mal.c 18 KB

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