mal.c 17 KB

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