mal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * drivers/net/ibm_newemac/mal.c
  3. *
  4. * Memory Access Layer (MAL) support
  5. *
  6. * Copyright (c) 2004, 2005 Zultys Technologies.
  7. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  8. *
  9. * Based on original work by
  10. * Benjamin Herrenschmidt <benh@kernel.crashing.org>,
  11. * David Gibson <hermes@gibson.dropbear.id.au>,
  12. *
  13. * Armin Kuster <akuster@mvista.com>
  14. * Copyright 2002 MontaVista Softare Inc.
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the
  18. * Free Software Foundation; either version 2 of the License, or (at your
  19. * option) any later version.
  20. *
  21. */
  22. #include <linux/delay.h>
  23. #include "core.h"
  24. static int mal_count;
  25. int __devinit mal_register_commac(struct mal_instance *mal,
  26. struct mal_commac *commac)
  27. {
  28. unsigned long flags;
  29. spin_lock_irqsave(&mal->lock, flags);
  30. MAL_DBG(mal, "reg(%08x, %08x)" NL,
  31. commac->tx_chan_mask, commac->rx_chan_mask);
  32. /* Don't let multiple commacs claim the same channel(s) */
  33. if ((mal->tx_chan_mask & commac->tx_chan_mask) ||
  34. (mal->rx_chan_mask & commac->rx_chan_mask)) {
  35. spin_unlock_irqrestore(&mal->lock, flags);
  36. printk(KERN_WARNING "mal%d: COMMAC channels conflict!\n",
  37. mal->index);
  38. return -EBUSY;
  39. }
  40. if (list_empty(&mal->list))
  41. napi_enable(&mal->napi);
  42. mal->tx_chan_mask |= commac->tx_chan_mask;
  43. mal->rx_chan_mask |= commac->rx_chan_mask;
  44. list_add(&commac->list, &mal->list);
  45. spin_unlock_irqrestore(&mal->lock, flags);
  46. return 0;
  47. }
  48. void __devexit mal_unregister_commac(struct mal_instance *mal,
  49. struct mal_commac *commac)
  50. {
  51. unsigned long flags;
  52. spin_lock_irqsave(&mal->lock, flags);
  53. MAL_DBG(mal, "unreg(%08x, %08x)" NL,
  54. commac->tx_chan_mask, commac->rx_chan_mask);
  55. mal->tx_chan_mask &= ~commac->tx_chan_mask;
  56. mal->rx_chan_mask &= ~commac->rx_chan_mask;
  57. list_del_init(&commac->list);
  58. if (list_empty(&mal->list))
  59. napi_disable(&mal->napi);
  60. spin_unlock_irqrestore(&mal->lock, flags);
  61. }
  62. int mal_set_rcbs(struct mal_instance *mal, int channel, unsigned long size)
  63. {
  64. BUG_ON(channel < 0 || channel >= mal->num_rx_chans ||
  65. size > MAL_MAX_RX_SIZE);
  66. MAL_DBG(mal, "set_rbcs(%d, %lu)" NL, channel, size);
  67. if (size & 0xf) {
  68. printk(KERN_WARNING
  69. "mal%d: incorrect RX size %lu for the channel %d\n",
  70. mal->index, size, channel);
  71. return -EINVAL;
  72. }
  73. set_mal_dcrn(mal, MAL_RCBS(channel), size >> 4);
  74. return 0;
  75. }
  76. int mal_tx_bd_offset(struct mal_instance *mal, int channel)
  77. {
  78. BUG_ON(channel < 0 || channel >= mal->num_tx_chans);
  79. return channel * NUM_TX_BUFF;
  80. }
  81. int mal_rx_bd_offset(struct mal_instance *mal, int channel)
  82. {
  83. BUG_ON(channel < 0 || channel >= mal->num_rx_chans);
  84. return mal->num_tx_chans * NUM_TX_BUFF + channel * NUM_RX_BUFF;
  85. }
  86. void mal_enable_tx_channel(struct mal_instance *mal, int channel)
  87. {
  88. unsigned long flags;
  89. spin_lock_irqsave(&mal->lock, flags);
  90. MAL_DBG(mal, "enable_tx(%d)" NL, channel);
  91. set_mal_dcrn(mal, MAL_TXCASR,
  92. get_mal_dcrn(mal, MAL_TXCASR) | MAL_CHAN_MASK(channel));
  93. spin_unlock_irqrestore(&mal->lock, flags);
  94. }
  95. void mal_disable_tx_channel(struct mal_instance *mal, int channel)
  96. {
  97. set_mal_dcrn(mal, MAL_TXCARR, MAL_CHAN_MASK(channel));
  98. MAL_DBG(mal, "disable_tx(%d)" NL, channel);
  99. }
  100. void mal_enable_rx_channel(struct mal_instance *mal, int channel)
  101. {
  102. unsigned long flags;
  103. spin_lock_irqsave(&mal->lock, flags);
  104. MAL_DBG(mal, "enable_rx(%d)" NL, channel);
  105. set_mal_dcrn(mal, MAL_RXCASR,
  106. get_mal_dcrn(mal, MAL_RXCASR) | MAL_CHAN_MASK(channel));
  107. spin_unlock_irqrestore(&mal->lock, flags);
  108. }
  109. void mal_disable_rx_channel(struct mal_instance *mal, int channel)
  110. {
  111. set_mal_dcrn(mal, MAL_RXCARR, MAL_CHAN_MASK(channel));
  112. MAL_DBG(mal, "disable_rx(%d)" NL, channel);
  113. }
  114. void mal_poll_add(struct mal_instance *mal, struct mal_commac *commac)
  115. {
  116. unsigned long flags;
  117. spin_lock_irqsave(&mal->lock, flags);
  118. MAL_DBG(mal, "poll_add(%p)" NL, commac);
  119. /* starts disabled */
  120. set_bit(MAL_COMMAC_POLL_DISABLED, &commac->flags);
  121. list_add_tail(&commac->poll_list, &mal->poll_list);
  122. spin_unlock_irqrestore(&mal->lock, flags);
  123. }
  124. void mal_poll_del(struct mal_instance *mal, struct mal_commac *commac)
  125. {
  126. unsigned long flags;
  127. spin_lock_irqsave(&mal->lock, flags);
  128. MAL_DBG(mal, "poll_del(%p)" NL, commac);
  129. list_del(&commac->poll_list);
  130. spin_unlock_irqrestore(&mal->lock, flags);
  131. }
  132. /* synchronized by mal_poll() */
  133. static inline void mal_enable_eob_irq(struct mal_instance *mal)
  134. {
  135. MAL_DBG2(mal, "enable_irq" NL);
  136. // XXX might want to cache MAL_CFG as the DCR read can be slooooow
  137. set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) | MAL_CFG_EOPIE);
  138. }
  139. /* synchronized by NAPI state */
  140. static inline void mal_disable_eob_irq(struct mal_instance *mal)
  141. {
  142. // XXX might want to cache MAL_CFG as the DCR read can be slooooow
  143. set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) & ~MAL_CFG_EOPIE);
  144. MAL_DBG2(mal, "disable_irq" NL);
  145. }
  146. static irqreturn_t mal_serr(int irq, void *dev_instance)
  147. {
  148. struct mal_instance *mal = dev_instance;
  149. u32 esr = get_mal_dcrn(mal, MAL_ESR);
  150. /* Clear the error status register */
  151. set_mal_dcrn(mal, MAL_ESR, esr);
  152. MAL_DBG(mal, "SERR %08x" NL, esr);
  153. if (esr & MAL_ESR_EVB) {
  154. if (esr & MAL_ESR_DE) {
  155. /* We ignore Descriptor error,
  156. * TXDE or RXDE interrupt will be generated anyway.
  157. */
  158. return IRQ_HANDLED;
  159. }
  160. if (esr & MAL_ESR_PEIN) {
  161. /* PLB error, it's probably buggy hardware or
  162. * incorrect physical address in BD (i.e. bug)
  163. */
  164. if (net_ratelimit())
  165. printk(KERN_ERR
  166. "mal%d: system error, "
  167. "PLB (ESR = 0x%08x)\n",
  168. mal->index, esr);
  169. return IRQ_HANDLED;
  170. }
  171. /* OPB error, it's probably buggy hardware or incorrect
  172. * EBC setup
  173. */
  174. if (net_ratelimit())
  175. printk(KERN_ERR
  176. "mal%d: system error, OPB (ESR = 0x%08x)\n",
  177. mal->index, esr);
  178. }
  179. return IRQ_HANDLED;
  180. }
  181. static inline void mal_schedule_poll(struct mal_instance *mal)
  182. {
  183. if (likely(napi_schedule_prep(&mal->napi))) {
  184. MAL_DBG2(mal, "schedule_poll" NL);
  185. mal_disable_eob_irq(mal);
  186. __napi_schedule(&mal->napi);
  187. } else
  188. MAL_DBG2(mal, "already in poll" NL);
  189. }
  190. static irqreturn_t mal_txeob(int irq, void *dev_instance)
  191. {
  192. struct mal_instance *mal = dev_instance;
  193. u32 r = get_mal_dcrn(mal, MAL_TXEOBISR);
  194. MAL_DBG2(mal, "txeob %08x" NL, r);
  195. mal_schedule_poll(mal);
  196. set_mal_dcrn(mal, MAL_TXEOBISR, r);
  197. return IRQ_HANDLED;
  198. }
  199. static irqreturn_t mal_rxeob(int irq, void *dev_instance)
  200. {
  201. struct mal_instance *mal = dev_instance;
  202. u32 r = get_mal_dcrn(mal, MAL_RXEOBISR);
  203. MAL_DBG2(mal, "rxeob %08x" NL, r);
  204. mal_schedule_poll(mal);
  205. set_mal_dcrn(mal, MAL_RXEOBISR, r);
  206. return IRQ_HANDLED;
  207. }
  208. static irqreturn_t mal_txde(int irq, void *dev_instance)
  209. {
  210. struct mal_instance *mal = dev_instance;
  211. u32 deir = get_mal_dcrn(mal, MAL_TXDEIR);
  212. set_mal_dcrn(mal, MAL_TXDEIR, deir);
  213. MAL_DBG(mal, "txde %08x" NL, deir);
  214. if (net_ratelimit())
  215. printk(KERN_ERR
  216. "mal%d: TX descriptor error (TXDEIR = 0x%08x)\n",
  217. mal->index, deir);
  218. return IRQ_HANDLED;
  219. }
  220. static irqreturn_t mal_rxde(int irq, void *dev_instance)
  221. {
  222. struct mal_instance *mal = dev_instance;
  223. struct list_head *l;
  224. u32 deir = get_mal_dcrn(mal, MAL_RXDEIR);
  225. MAL_DBG(mal, "rxde %08x" NL, deir);
  226. list_for_each(l, &mal->list) {
  227. struct mal_commac *mc = list_entry(l, struct mal_commac, list);
  228. if (deir & mc->rx_chan_mask) {
  229. set_bit(MAL_COMMAC_RX_STOPPED, &mc->flags);
  230. mc->ops->rxde(mc->dev);
  231. }
  232. }
  233. mal_schedule_poll(mal);
  234. set_mal_dcrn(mal, MAL_RXDEIR, deir);
  235. return IRQ_HANDLED;
  236. }
  237. void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac)
  238. {
  239. /* Spinlock-type semantics: only one caller disable poll at a time */
  240. while (test_and_set_bit(MAL_COMMAC_POLL_DISABLED, &commac->flags))
  241. msleep(1);
  242. /* Synchronize with the MAL NAPI poller */
  243. napi_synchronize(&mal->napi);
  244. }
  245. void mal_poll_enable(struct mal_instance *mal, struct mal_commac *commac)
  246. {
  247. smp_wmb();
  248. clear_bit(MAL_COMMAC_POLL_DISABLED, &commac->flags);
  249. /* Feels better to trigger a poll here to catch up with events that
  250. * may have happened on this channel while disabled. It will most
  251. * probably be delayed until the next interrupt but that's mostly a
  252. * non-issue in the context where this is called.
  253. */
  254. napi_schedule(&mal->napi);
  255. }
  256. static int mal_poll(struct napi_struct *napi, int budget)
  257. {
  258. struct mal_instance *mal = container_of(napi, struct mal_instance, napi);
  259. struct list_head *l;
  260. int received = 0;
  261. unsigned long flags;
  262. MAL_DBG2(mal, "poll(%d)" NL, budget);
  263. again:
  264. /* Process TX skbs */
  265. list_for_each(l, &mal->poll_list) {
  266. struct mal_commac *mc =
  267. list_entry(l, struct mal_commac, poll_list);
  268. mc->ops->poll_tx(mc->dev);
  269. }
  270. /* Process RX skbs.
  271. *
  272. * We _might_ need something more smart here to enforce polling
  273. * fairness.
  274. */
  275. list_for_each(l, &mal->poll_list) {
  276. struct mal_commac *mc =
  277. list_entry(l, struct mal_commac, poll_list);
  278. int n;
  279. if (unlikely(test_bit(MAL_COMMAC_POLL_DISABLED, &mc->flags)))
  280. continue;
  281. n = mc->ops->poll_rx(mc->dev, budget);
  282. if (n) {
  283. received += n;
  284. budget -= n;
  285. if (budget <= 0)
  286. goto more_work; // XXX What if this is the last one ?
  287. }
  288. }
  289. /* We need to disable IRQs to protect from RXDE IRQ here */
  290. spin_lock_irqsave(&mal->lock, flags);
  291. __napi_complete(napi);
  292. mal_enable_eob_irq(mal);
  293. spin_unlock_irqrestore(&mal->lock, flags);
  294. /* Check for "rotting" packet(s) */
  295. list_for_each(l, &mal->poll_list) {
  296. struct mal_commac *mc =
  297. list_entry(l, struct mal_commac, poll_list);
  298. if (unlikely(test_bit(MAL_COMMAC_POLL_DISABLED, &mc->flags)))
  299. continue;
  300. if (unlikely(mc->ops->peek_rx(mc->dev) ||
  301. test_bit(MAL_COMMAC_RX_STOPPED, &mc->flags))) {
  302. MAL_DBG2(mal, "rotting packet" NL);
  303. if (napi_reschedule(napi))
  304. mal_disable_eob_irq(mal);
  305. else
  306. MAL_DBG2(mal, "already in poll list" NL);
  307. if (budget > 0)
  308. goto again;
  309. else
  310. goto more_work;
  311. }
  312. mc->ops->poll_tx(mc->dev);
  313. }
  314. more_work:
  315. MAL_DBG2(mal, "poll() %d <- %d" NL, budget, received);
  316. return received;
  317. }
  318. static void mal_reset(struct mal_instance *mal)
  319. {
  320. int n = 10;
  321. MAL_DBG(mal, "reset" NL);
  322. set_mal_dcrn(mal, MAL_CFG, MAL_CFG_SR);
  323. /* Wait for reset to complete (1 system clock) */
  324. while ((get_mal_dcrn(mal, MAL_CFG) & MAL_CFG_SR) && n)
  325. --n;
  326. if (unlikely(!n))
  327. printk(KERN_ERR "mal%d: reset timeout\n", mal->index);
  328. }
  329. int mal_get_regs_len(struct mal_instance *mal)
  330. {
  331. return sizeof(struct emac_ethtool_regs_subhdr) +
  332. sizeof(struct mal_regs);
  333. }
  334. void *mal_dump_regs(struct mal_instance *mal, void *buf)
  335. {
  336. struct emac_ethtool_regs_subhdr *hdr = buf;
  337. struct mal_regs *regs = (struct mal_regs *)(hdr + 1);
  338. int i;
  339. hdr->version = mal->version;
  340. hdr->index = mal->index;
  341. regs->tx_count = mal->num_tx_chans;
  342. regs->rx_count = mal->num_rx_chans;
  343. regs->cfg = get_mal_dcrn(mal, MAL_CFG);
  344. regs->esr = get_mal_dcrn(mal, MAL_ESR);
  345. regs->ier = get_mal_dcrn(mal, MAL_IER);
  346. regs->tx_casr = get_mal_dcrn(mal, MAL_TXCASR);
  347. regs->tx_carr = get_mal_dcrn(mal, MAL_TXCARR);
  348. regs->tx_eobisr = get_mal_dcrn(mal, MAL_TXEOBISR);
  349. regs->tx_deir = get_mal_dcrn(mal, MAL_TXDEIR);
  350. regs->rx_casr = get_mal_dcrn(mal, MAL_RXCASR);
  351. regs->rx_carr = get_mal_dcrn(mal, MAL_RXCARR);
  352. regs->rx_eobisr = get_mal_dcrn(mal, MAL_RXEOBISR);
  353. regs->rx_deir = get_mal_dcrn(mal, MAL_RXDEIR);
  354. for (i = 0; i < regs->tx_count; ++i)
  355. regs->tx_ctpr[i] = get_mal_dcrn(mal, MAL_TXCTPR(i));
  356. for (i = 0; i < regs->rx_count; ++i) {
  357. regs->rx_ctpr[i] = get_mal_dcrn(mal, MAL_RXCTPR(i));
  358. regs->rcbs[i] = get_mal_dcrn(mal, MAL_RCBS(i));
  359. }
  360. return regs + 1;
  361. }
  362. static int __devinit mal_probe(struct of_device *ofdev,
  363. const struct of_device_id *match)
  364. {
  365. struct mal_instance *mal;
  366. int err = 0, i, bd_size;
  367. int index = mal_count++;
  368. unsigned int dcr_base;
  369. const u32 *prop;
  370. u32 cfg;
  371. mal = kzalloc(sizeof(struct mal_instance), GFP_KERNEL);
  372. if (!mal) {
  373. printk(KERN_ERR
  374. "mal%d: out of memory allocating MAL structure!\n",
  375. index);
  376. return -ENOMEM;
  377. }
  378. mal->index = index;
  379. mal->ofdev = ofdev;
  380. mal->version = of_device_is_compatible(ofdev->node, "ibm,mcmal2") ? 2 : 1;
  381. MAL_DBG(mal, "probe" NL);
  382. prop = of_get_property(ofdev->node, "num-tx-chans", NULL);
  383. if (prop == NULL) {
  384. printk(KERN_ERR
  385. "mal%d: can't find MAL num-tx-chans property!\n",
  386. index);
  387. err = -ENODEV;
  388. goto fail;
  389. }
  390. mal->num_tx_chans = prop[0];
  391. prop = of_get_property(ofdev->node, "num-rx-chans", NULL);
  392. if (prop == NULL) {
  393. printk(KERN_ERR
  394. "mal%d: can't find MAL num-rx-chans property!\n",
  395. index);
  396. err = -ENODEV;
  397. goto fail;
  398. }
  399. mal->num_rx_chans = prop[0];
  400. dcr_base = dcr_resource_start(ofdev->node, 0);
  401. if (dcr_base == 0) {
  402. printk(KERN_ERR
  403. "mal%d: can't find DCR resource!\n", index);
  404. err = -ENODEV;
  405. goto fail;
  406. }
  407. mal->dcr_host = dcr_map(ofdev->node, dcr_base, 0x100);
  408. if (!DCR_MAP_OK(mal->dcr_host)) {
  409. printk(KERN_ERR
  410. "mal%d: failed to map DCRs !\n", index);
  411. err = -ENODEV;
  412. goto fail;
  413. }
  414. mal->txeob_irq = irq_of_parse_and_map(ofdev->node, 0);
  415. mal->rxeob_irq = irq_of_parse_and_map(ofdev->node, 1);
  416. mal->serr_irq = irq_of_parse_and_map(ofdev->node, 2);
  417. mal->txde_irq = irq_of_parse_and_map(ofdev->node, 3);
  418. mal->rxde_irq = irq_of_parse_and_map(ofdev->node, 4);
  419. if (mal->txeob_irq == NO_IRQ || mal->rxeob_irq == NO_IRQ ||
  420. mal->serr_irq == NO_IRQ || mal->txde_irq == NO_IRQ ||
  421. mal->rxde_irq == NO_IRQ) {
  422. printk(KERN_ERR
  423. "mal%d: failed to map interrupts !\n", index);
  424. err = -ENODEV;
  425. goto fail_unmap;
  426. }
  427. INIT_LIST_HEAD(&mal->poll_list);
  428. INIT_LIST_HEAD(&mal->list);
  429. spin_lock_init(&mal->lock);
  430. netif_napi_add(NULL, &mal->napi, mal_poll,
  431. CONFIG_IBM_NEW_EMAC_POLL_WEIGHT);
  432. /* Load power-on reset defaults */
  433. mal_reset(mal);
  434. /* Set the MAL configuration register */
  435. cfg = (mal->version == 2) ? MAL2_CFG_DEFAULT : MAL1_CFG_DEFAULT;
  436. cfg |= MAL_CFG_PLBB | MAL_CFG_OPBBL | MAL_CFG_LEA;
  437. /* Current Axon is not happy with priority being non-0, it can
  438. * deadlock, fix it up here
  439. */
  440. if (of_device_is_compatible(ofdev->node, "ibm,mcmal-axon"))
  441. cfg &= ~(MAL2_CFG_RPP_10 | MAL2_CFG_WPP_10);
  442. /* Apply configuration */
  443. set_mal_dcrn(mal, MAL_CFG, cfg);
  444. /* Allocate space for BD rings */
  445. BUG_ON(mal->num_tx_chans <= 0 || mal->num_tx_chans > 32);
  446. BUG_ON(mal->num_rx_chans <= 0 || mal->num_rx_chans > 32);
  447. bd_size = sizeof(struct mal_descriptor) *
  448. (NUM_TX_BUFF * mal->num_tx_chans +
  449. NUM_RX_BUFF * mal->num_rx_chans);
  450. mal->bd_virt =
  451. dma_alloc_coherent(&ofdev->dev, bd_size, &mal->bd_dma,
  452. GFP_KERNEL);
  453. if (mal->bd_virt == NULL) {
  454. printk(KERN_ERR
  455. "mal%d: out of memory allocating RX/TX descriptors!\n",
  456. index);
  457. err = -ENOMEM;
  458. goto fail_unmap;
  459. }
  460. memset(mal->bd_virt, 0, bd_size);
  461. for (i = 0; i < mal->num_tx_chans; ++i)
  462. set_mal_dcrn(mal, MAL_TXCTPR(i), mal->bd_dma +
  463. sizeof(struct mal_descriptor) *
  464. mal_tx_bd_offset(mal, i));
  465. for (i = 0; i < mal->num_rx_chans; ++i)
  466. set_mal_dcrn(mal, MAL_RXCTPR(i), mal->bd_dma +
  467. sizeof(struct mal_descriptor) *
  468. mal_rx_bd_offset(mal, i));
  469. err = request_irq(mal->serr_irq, mal_serr, 0, "MAL SERR", mal);
  470. if (err)
  471. goto fail2;
  472. err = request_irq(mal->txde_irq, mal_txde, 0, "MAL TX DE", mal);
  473. if (err)
  474. goto fail3;
  475. err = request_irq(mal->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal);
  476. if (err)
  477. goto fail4;
  478. err = request_irq(mal->rxde_irq, mal_rxde, 0, "MAL RX DE", mal);
  479. if (err)
  480. goto fail5;
  481. err = request_irq(mal->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal);
  482. if (err)
  483. goto fail6;
  484. /* Enable all MAL SERR interrupt sources */
  485. if (mal->version == 2)
  486. set_mal_dcrn(mal, MAL_IER, MAL2_IER_EVENTS);
  487. else
  488. set_mal_dcrn(mal, MAL_IER, MAL1_IER_EVENTS);
  489. /* Enable EOB interrupt */
  490. mal_enable_eob_irq(mal);
  491. printk(KERN_INFO
  492. "MAL v%d %s, %d TX channels, %d RX channels\n",
  493. mal->version, ofdev->node->full_name,
  494. mal->num_tx_chans, mal->num_rx_chans);
  495. /* Advertise this instance to the rest of the world */
  496. wmb();
  497. dev_set_drvdata(&ofdev->dev, mal);
  498. mal_dbg_register(mal);
  499. return 0;
  500. fail6:
  501. free_irq(mal->rxde_irq, mal);
  502. fail5:
  503. free_irq(mal->txeob_irq, mal);
  504. fail4:
  505. free_irq(mal->txde_irq, mal);
  506. fail3:
  507. free_irq(mal->serr_irq, mal);
  508. fail2:
  509. dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma);
  510. fail_unmap:
  511. dcr_unmap(mal->dcr_host, 0x100);
  512. fail:
  513. kfree(mal);
  514. return err;
  515. }
  516. static int __devexit mal_remove(struct of_device *ofdev)
  517. {
  518. struct mal_instance *mal = dev_get_drvdata(&ofdev->dev);
  519. MAL_DBG(mal, "remove" NL);
  520. /* Synchronize with scheduled polling */
  521. napi_disable(&mal->napi);
  522. if (!list_empty(&mal->list)) {
  523. /* This is *very* bad */
  524. printk(KERN_EMERG
  525. "mal%d: commac list is not empty on remove!\n",
  526. mal->index);
  527. WARN_ON(1);
  528. }
  529. dev_set_drvdata(&ofdev->dev, NULL);
  530. free_irq(mal->serr_irq, mal);
  531. free_irq(mal->txde_irq, mal);
  532. free_irq(mal->txeob_irq, mal);
  533. free_irq(mal->rxde_irq, mal);
  534. free_irq(mal->rxeob_irq, mal);
  535. mal_reset(mal);
  536. mal_dbg_unregister(mal);
  537. dma_free_coherent(&ofdev->dev,
  538. sizeof(struct mal_descriptor) *
  539. (NUM_TX_BUFF * mal->num_tx_chans +
  540. NUM_RX_BUFF * mal->num_rx_chans), mal->bd_virt,
  541. mal->bd_dma);
  542. kfree(mal);
  543. return 0;
  544. }
  545. static struct of_device_id mal_platform_match[] =
  546. {
  547. {
  548. .compatible = "ibm,mcmal",
  549. },
  550. {
  551. .compatible = "ibm,mcmal2",
  552. },
  553. /* Backward compat */
  554. {
  555. .type = "mcmal-dma",
  556. .compatible = "ibm,mcmal",
  557. },
  558. {
  559. .type = "mcmal-dma",
  560. .compatible = "ibm,mcmal2",
  561. },
  562. {},
  563. };
  564. static struct of_platform_driver mal_of_driver = {
  565. .name = "mcmal",
  566. .match_table = mal_platform_match,
  567. .probe = mal_probe,
  568. .remove = mal_remove,
  569. };
  570. int __init mal_init(void)
  571. {
  572. return of_register_platform_driver(&mal_of_driver);
  573. }
  574. void mal_exit(void)
  575. {
  576. of_unregister_platform_driver(&mal_of_driver);
  577. }