mal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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(netif_rx_schedule_prep(&mal->poll_dev))) {
  180. MAL_DBG2(mal, "schedule_poll" NL);
  181. mal_disable_eob_irq(mal);
  182. __netif_rx_schedule(&mal->poll_dev);
  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. while (test_bit(__LINK_STATE_RX_SCHED, &mal->poll_dev.state))
  240. msleep(1);
  241. }
  242. void mal_poll_enable(struct mal_instance *mal, struct mal_commac *commac)
  243. {
  244. smp_wmb();
  245. clear_bit(MAL_COMMAC_POLL_DISABLED, &commac->flags);
  246. // XXX might want to kick a poll now...
  247. }
  248. static int mal_poll(struct net_device *ndev, int *budget)
  249. {
  250. struct mal_instance *mal = netdev_priv(ndev);
  251. struct list_head *l;
  252. int rx_work_limit = min(ndev->quota, *budget), received = 0, done;
  253. unsigned long flags;
  254. MAL_DBG2(mal, "poll(%d) %d ->" NL, *budget,
  255. rx_work_limit);
  256. again:
  257. /* Process TX skbs */
  258. list_for_each(l, &mal->poll_list) {
  259. struct mal_commac *mc =
  260. list_entry(l, struct mal_commac, poll_list);
  261. mc->ops->poll_tx(mc->dev);
  262. }
  263. /* Process RX skbs.
  264. *
  265. * We _might_ need something more smart here to enforce polling
  266. * fairness.
  267. */
  268. list_for_each(l, &mal->poll_list) {
  269. struct mal_commac *mc =
  270. list_entry(l, struct mal_commac, poll_list);
  271. int n;
  272. if (unlikely(test_bit(MAL_COMMAC_POLL_DISABLED, &mc->flags)))
  273. continue;
  274. n = mc->ops->poll_rx(mc->dev, rx_work_limit);
  275. if (n) {
  276. received += n;
  277. rx_work_limit -= n;
  278. if (rx_work_limit <= 0) {
  279. done = 0;
  280. // XXX What if this is the last one ?
  281. goto more_work;
  282. }
  283. }
  284. }
  285. /* We need to disable IRQs to protect from RXDE IRQ here */
  286. spin_lock_irqsave(&mal->lock, flags);
  287. __netif_rx_complete(ndev);
  288. mal_enable_eob_irq(mal);
  289. spin_unlock_irqrestore(&mal->lock, flags);
  290. done = 1;
  291. /* Check for "rotting" packet(s) */
  292. list_for_each(l, &mal->poll_list) {
  293. struct mal_commac *mc =
  294. list_entry(l, struct mal_commac, poll_list);
  295. if (unlikely(test_bit(MAL_COMMAC_POLL_DISABLED, &mc->flags)))
  296. continue;
  297. if (unlikely(mc->ops->peek_rx(mc->dev) ||
  298. test_bit(MAL_COMMAC_RX_STOPPED, &mc->flags))) {
  299. MAL_DBG2(mal, "rotting packet" NL);
  300. if (netif_rx_reschedule(ndev, received))
  301. mal_disable_eob_irq(mal);
  302. else
  303. MAL_DBG2(mal, "already in poll list" NL);
  304. if (rx_work_limit > 0)
  305. goto again;
  306. else
  307. goto more_work;
  308. }
  309. mc->ops->poll_tx(mc->dev);
  310. }
  311. more_work:
  312. ndev->quota -= received;
  313. *budget -= received;
  314. MAL_DBG2(mal, "poll() %d <- %d" NL, *budget,
  315. done ? 0 : 1);
  316. return done ? 0 : 1;
  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. const u32 *prop;
  369. u32 cfg;
  370. mal = kzalloc(sizeof(struct mal_instance), GFP_KERNEL);
  371. if (!mal) {
  372. printk(KERN_ERR
  373. "mal%d: out of memory allocating MAL structure!\n",
  374. index);
  375. return -ENOMEM;
  376. }
  377. mal->index = index;
  378. mal->ofdev = ofdev;
  379. mal->version = of_device_is_compatible(ofdev->node, "ibm,mcmal2") ? 2 : 1;
  380. MAL_DBG(mal, "probe" NL);
  381. prop = of_get_property(ofdev->node, "num-tx-chans", NULL);
  382. if (prop == NULL) {
  383. printk(KERN_ERR
  384. "mal%d: can't find MAL num-tx-chans property!\n",
  385. index);
  386. err = -ENODEV;
  387. goto fail;
  388. }
  389. mal->num_tx_chans = prop[0];
  390. prop = of_get_property(ofdev->node, "num-rx-chans", NULL);
  391. if (prop == NULL) {
  392. printk(KERN_ERR
  393. "mal%d: can't find MAL num-rx-chans property!\n",
  394. index);
  395. err = -ENODEV;
  396. goto fail;
  397. }
  398. mal->num_rx_chans = prop[0];
  399. mal->dcr_base = dcr_resource_start(ofdev->node, 0);
  400. if (mal->dcr_base == 0) {
  401. printk(KERN_ERR
  402. "mal%d: can't find DCR resource!\n", index);
  403. err = -ENODEV;
  404. goto fail;
  405. }
  406. mal->dcr_host = dcr_map(ofdev->node, mal->dcr_base, 0x100);
  407. if (!DCR_MAP_OK(mal->dcr_host)) {
  408. printk(KERN_ERR
  409. "mal%d: failed to map DCRs !\n", index);
  410. err = -ENODEV;
  411. goto fail;
  412. }
  413. mal->txeob_irq = irq_of_parse_and_map(ofdev->node, 0);
  414. mal->rxeob_irq = irq_of_parse_and_map(ofdev->node, 1);
  415. mal->serr_irq = irq_of_parse_and_map(ofdev->node, 2);
  416. mal->txde_irq = irq_of_parse_and_map(ofdev->node, 3);
  417. mal->rxde_irq = irq_of_parse_and_map(ofdev->node, 4);
  418. if (mal->txeob_irq == NO_IRQ || mal->rxeob_irq == NO_IRQ ||
  419. mal->serr_irq == NO_IRQ || mal->txde_irq == NO_IRQ ||
  420. mal->rxde_irq == NO_IRQ) {
  421. printk(KERN_ERR
  422. "mal%d: failed to map interrupts !\n", index);
  423. err = -ENODEV;
  424. goto fail_unmap;
  425. }
  426. INIT_LIST_HEAD(&mal->poll_list);
  427. set_bit(__LINK_STATE_START, &mal->poll_dev.state);
  428. mal->poll_dev.weight = CONFIG_IBM_NEW_EMAC_POLL_WEIGHT;
  429. mal->poll_dev.poll = mal_poll;
  430. mal->poll_dev.priv = mal;
  431. atomic_set(&mal->poll_dev.refcnt, 1);
  432. INIT_LIST_HEAD(&mal->list);
  433. spin_lock_init(&mal->lock);
  434. /* Load power-on reset defaults */
  435. mal_reset(mal);
  436. /* Set the MAL configuration register */
  437. cfg = (mal->version == 2) ? MAL2_CFG_DEFAULT : MAL1_CFG_DEFAULT;
  438. cfg |= MAL_CFG_PLBB | MAL_CFG_OPBBL | MAL_CFG_LEA;
  439. /* Current Axon is not happy with priority being non-0, it can
  440. * deadlock, fix it up here
  441. */
  442. if (of_device_is_compatible(ofdev->node, "ibm,mcmal-axon"))
  443. cfg &= ~(MAL2_CFG_RPP_10 | MAL2_CFG_WPP_10);
  444. /* Apply configuration */
  445. set_mal_dcrn(mal, MAL_CFG, cfg);
  446. /* Allocate space for BD rings */
  447. BUG_ON(mal->num_tx_chans <= 0 || mal->num_tx_chans > 32);
  448. BUG_ON(mal->num_rx_chans <= 0 || mal->num_rx_chans > 32);
  449. bd_size = sizeof(struct mal_descriptor) *
  450. (NUM_TX_BUFF * mal->num_tx_chans +
  451. NUM_RX_BUFF * mal->num_rx_chans);
  452. mal->bd_virt =
  453. dma_alloc_coherent(&ofdev->dev, bd_size, &mal->bd_dma,
  454. GFP_KERNEL);
  455. if (mal->bd_virt == NULL) {
  456. printk(KERN_ERR
  457. "mal%d: out of memory allocating RX/TX descriptors!\n",
  458. index);
  459. err = -ENOMEM;
  460. goto fail_unmap;
  461. }
  462. memset(mal->bd_virt, 0, bd_size);
  463. for (i = 0; i < mal->num_tx_chans; ++i)
  464. set_mal_dcrn(mal, MAL_TXCTPR(i), mal->bd_dma +
  465. sizeof(struct mal_descriptor) *
  466. mal_tx_bd_offset(mal, i));
  467. for (i = 0; i < mal->num_rx_chans; ++i)
  468. set_mal_dcrn(mal, MAL_RXCTPR(i), mal->bd_dma +
  469. sizeof(struct mal_descriptor) *
  470. mal_rx_bd_offset(mal, i));
  471. err = request_irq(mal->serr_irq, mal_serr, 0, "MAL SERR", mal);
  472. if (err)
  473. goto fail2;
  474. err = request_irq(mal->txde_irq, mal_txde, 0, "MAL TX DE", mal);
  475. if (err)
  476. goto fail3;
  477. err = request_irq(mal->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal);
  478. if (err)
  479. goto fail4;
  480. err = request_irq(mal->rxde_irq, mal_rxde, 0, "MAL RX DE", mal);
  481. if (err)
  482. goto fail5;
  483. err = request_irq(mal->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal);
  484. if (err)
  485. goto fail6;
  486. /* Enable all MAL SERR interrupt sources */
  487. if (mal->version == 2)
  488. set_mal_dcrn(mal, MAL_IER, MAL2_IER_EVENTS);
  489. else
  490. set_mal_dcrn(mal, MAL_IER, MAL1_IER_EVENTS);
  491. /* Enable EOB interrupt */
  492. mal_enable_eob_irq(mal);
  493. printk(KERN_INFO
  494. "MAL v%d %s, %d TX channels, %d RX channels\n",
  495. mal->version, ofdev->node->full_name,
  496. mal->num_tx_chans, mal->num_rx_chans);
  497. /* Advertise this instance to the rest of the world */
  498. wmb();
  499. dev_set_drvdata(&ofdev->dev, mal);
  500. mal_dbg_register(mal);
  501. return 0;
  502. fail6:
  503. free_irq(mal->rxde_irq, mal);
  504. fail5:
  505. free_irq(mal->txeob_irq, mal);
  506. fail4:
  507. free_irq(mal->txde_irq, mal);
  508. fail3:
  509. free_irq(mal->serr_irq, mal);
  510. fail2:
  511. dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma);
  512. fail_unmap:
  513. dcr_unmap(mal->dcr_host, mal->dcr_base, 0x100);
  514. fail:
  515. kfree(mal);
  516. return err;
  517. }
  518. static int __devexit mal_remove(struct of_device *ofdev)
  519. {
  520. struct mal_instance *mal = dev_get_drvdata(&ofdev->dev);
  521. MAL_DBG(mal, "remove" NL);
  522. /* Syncronize with scheduled polling,
  523. stolen from net/core/dev.c:dev_close()
  524. */
  525. clear_bit(__LINK_STATE_START, &mal->poll_dev.state);
  526. netif_poll_disable(&mal->poll_dev);
  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. }