macmace.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for the Macintosh 68K onboard MACE controller with PSC
  4. * driven DMA. The MACE driver code is derived from mace.c. The
  5. * Mac68k theory of operation is courtesy of the MacBSD wizards.
  6. *
  7. * Copyright (C) 1996 Paul Mackerras.
  8. * Copyright (C) 1998 Alan Cox <[email protected]>
  9. *
  10. * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
  11. *
  12. * Copyright (C) 2007 Finn Thain
  13. *
  14. * Converted to DMA API, converted to unified driver model,
  15. * sync'd some routines with mace.c and fixed various bugs.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/delay.h>
  22. #include <linux/string.h>
  23. #include <linux/crc32.h>
  24. #include <linux/bitrev.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/gfp.h>
  28. #include <linux/interrupt.h>
  29. #include <asm/io.h>
  30. #include <asm/macints.h>
  31. #include <asm/mac_psc.h>
  32. #include <asm/page.h>
  33. #include "mace.h"
  34. static char mac_mace_string[] = "macmace";
  35. #define N_TX_BUFF_ORDER 0
  36. #define N_TX_RING (1 << N_TX_BUFF_ORDER)
  37. #define N_RX_BUFF_ORDER 3
  38. #define N_RX_RING (1 << N_RX_BUFF_ORDER)
  39. #define TX_TIMEOUT HZ
  40. #define MACE_BUFF_SIZE 0x800
  41. /* Chip rev needs workaround on HW & multicast addr change */
  42. #define BROKEN_ADDRCHG_REV 0x0941
  43. /* The MACE is simply wired down on a Mac68K box */
  44. #define MACE_BASE (void *)(0x50F1C000)
  45. #define MACE_PROM (void *)(0x50F08001)
  46. struct mace_data {
  47. volatile struct mace *mace;
  48. unsigned char *tx_ring;
  49. dma_addr_t tx_ring_phys;
  50. unsigned char *rx_ring;
  51. dma_addr_t rx_ring_phys;
  52. int dma_intr;
  53. int rx_slot, rx_tail;
  54. int tx_slot, tx_sloti, tx_count;
  55. int chipid;
  56. struct device *device;
  57. };
  58. struct mace_frame {
  59. u8 rcvcnt;
  60. u8 pad1;
  61. u8 rcvsts;
  62. u8 pad2;
  63. u8 rntpc;
  64. u8 pad3;
  65. u8 rcvcc;
  66. u8 pad4;
  67. u32 pad5;
  68. u32 pad6;
  69. u8 data[1];
  70. /* And frame continues.. */
  71. };
  72. #define PRIV_BYTES sizeof(struct mace_data)
  73. static int mace_open(struct net_device *dev);
  74. static int mace_close(struct net_device *dev);
  75. static netdev_tx_t mace_xmit_start(struct sk_buff *skb, struct net_device *dev);
  76. static void mace_set_multicast(struct net_device *dev);
  77. static int mace_set_address(struct net_device *dev, void *addr);
  78. static void mace_reset(struct net_device *dev);
  79. static irqreturn_t mace_interrupt(int irq, void *dev_id);
  80. static irqreturn_t mace_dma_intr(int irq, void *dev_id);
  81. static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue);
  82. static void __mace_set_address(struct net_device *dev, const void *addr);
  83. /*
  84. * Load a receive DMA channel with a base address and ring length
  85. */
  86. static void mace_load_rxdma_base(struct net_device *dev, int set)
  87. {
  88. struct mace_data *mp = netdev_priv(dev);
  89. psc_write_word(PSC_ENETRD_CMD + set, 0x0100);
  90. psc_write_long(PSC_ENETRD_ADDR + set, (u32) mp->rx_ring_phys);
  91. psc_write_long(PSC_ENETRD_LEN + set, N_RX_RING);
  92. psc_write_word(PSC_ENETRD_CMD + set, 0x9800);
  93. mp->rx_tail = 0;
  94. }
  95. /*
  96. * Reset the receive DMA subsystem
  97. */
  98. static void mace_rxdma_reset(struct net_device *dev)
  99. {
  100. struct mace_data *mp = netdev_priv(dev);
  101. volatile struct mace *mace = mp->mace;
  102. u8 maccc = mace->maccc;
  103. mace->maccc = maccc & ~ENRCV;
  104. psc_write_word(PSC_ENETRD_CTL, 0x8800);
  105. mace_load_rxdma_base(dev, 0x00);
  106. psc_write_word(PSC_ENETRD_CTL, 0x0400);
  107. psc_write_word(PSC_ENETRD_CTL, 0x8800);
  108. mace_load_rxdma_base(dev, 0x10);
  109. psc_write_word(PSC_ENETRD_CTL, 0x0400);
  110. mace->maccc = maccc;
  111. mp->rx_slot = 0;
  112. psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x9800);
  113. psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x9800);
  114. }
  115. /*
  116. * Reset the transmit DMA subsystem
  117. */
  118. static void mace_txdma_reset(struct net_device *dev)
  119. {
  120. struct mace_data *mp = netdev_priv(dev);
  121. volatile struct mace *mace = mp->mace;
  122. u8 maccc;
  123. psc_write_word(PSC_ENETWR_CTL, 0x8800);
  124. maccc = mace->maccc;
  125. mace->maccc = maccc & ~ENXMT;
  126. mp->tx_slot = mp->tx_sloti = 0;
  127. mp->tx_count = N_TX_RING;
  128. psc_write_word(PSC_ENETWR_CTL, 0x0400);
  129. mace->maccc = maccc;
  130. }
  131. /*
  132. * Disable DMA
  133. */
  134. static void mace_dma_off(struct net_device *dev)
  135. {
  136. psc_write_word(PSC_ENETRD_CTL, 0x8800);
  137. psc_write_word(PSC_ENETRD_CTL, 0x1000);
  138. psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x1100);
  139. psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x1100);
  140. psc_write_word(PSC_ENETWR_CTL, 0x8800);
  141. psc_write_word(PSC_ENETWR_CTL, 0x1000);
  142. psc_write_word(PSC_ENETWR_CMD + PSC_SET0, 0x1100);
  143. psc_write_word(PSC_ENETWR_CMD + PSC_SET1, 0x1100);
  144. }
  145. static const struct net_device_ops mace_netdev_ops = {
  146. .ndo_open = mace_open,
  147. .ndo_stop = mace_close,
  148. .ndo_start_xmit = mace_xmit_start,
  149. .ndo_tx_timeout = mace_tx_timeout,
  150. .ndo_set_rx_mode = mace_set_multicast,
  151. .ndo_set_mac_address = mace_set_address,
  152. .ndo_validate_addr = eth_validate_addr,
  153. };
  154. /*
  155. * Not really much of a probe. The hardware table tells us if this
  156. * model of Macintrash has a MACE (AV macintoshes)
  157. */
  158. static int mace_probe(struct platform_device *pdev)
  159. {
  160. int j;
  161. struct mace_data *mp;
  162. unsigned char *addr;
  163. struct net_device *dev;
  164. unsigned char checksum = 0;
  165. u8 macaddr[ETH_ALEN];
  166. int err;
  167. dev = alloc_etherdev(PRIV_BYTES);
  168. if (!dev)
  169. return -ENOMEM;
  170. mp = netdev_priv(dev);
  171. mp->device = &pdev->dev;
  172. platform_set_drvdata(pdev, dev);
  173. SET_NETDEV_DEV(dev, &pdev->dev);
  174. dev->base_addr = (u32)MACE_BASE;
  175. mp->mace = MACE_BASE;
  176. dev->irq = IRQ_MAC_MACE;
  177. mp->dma_intr = IRQ_MAC_MACE_DMA;
  178. mp->chipid = mp->mace->chipid_hi << 8 | mp->mace->chipid_lo;
  179. /*
  180. * The PROM contains 8 bytes which total 0xFF when XOR'd
  181. * together. Due to the usual peculiar apple brain damage
  182. * the bytes are spaced out in a strange boundary and the
  183. * bits are reversed.
  184. */
  185. addr = MACE_PROM;
  186. for (j = 0; j < 6; ++j) {
  187. u8 v = bitrev8(addr[j<<4]);
  188. checksum ^= v;
  189. macaddr[j] = v;
  190. }
  191. eth_hw_addr_set(dev, macaddr);
  192. for (; j < 8; ++j) {
  193. checksum ^= bitrev8(addr[j<<4]);
  194. }
  195. if (checksum != 0xFF) {
  196. free_netdev(dev);
  197. return -ENODEV;
  198. }
  199. dev->netdev_ops = &mace_netdev_ops;
  200. dev->watchdog_timeo = TX_TIMEOUT;
  201. pr_info("Onboard MACE, hardware address %pM, chip revision 0x%04X\n",
  202. dev->dev_addr, mp->chipid);
  203. err = register_netdev(dev);
  204. if (!err)
  205. return 0;
  206. free_netdev(dev);
  207. return err;
  208. }
  209. /*
  210. * Reset the chip.
  211. */
  212. static void mace_reset(struct net_device *dev)
  213. {
  214. struct mace_data *mp = netdev_priv(dev);
  215. volatile struct mace *mb = mp->mace;
  216. int i;
  217. /* soft-reset the chip */
  218. i = 200;
  219. while (--i) {
  220. mb->biucc = SWRST;
  221. if (mb->biucc & SWRST) {
  222. udelay(10);
  223. continue;
  224. }
  225. break;
  226. }
  227. if (!i) {
  228. printk(KERN_ERR "macmace: cannot reset chip!\n");
  229. return;
  230. }
  231. mb->maccc = 0; /* turn off tx, rx */
  232. mb->imr = 0xFF; /* disable all intrs for now */
  233. i = mb->ir;
  234. mb->biucc = XMTSP_64;
  235. mb->utr = RTRD;
  236. mb->fifocc = XMTFW_8 | RCVFW_64 | XMTFWU | RCVFWU;
  237. mb->xmtfc = AUTO_PAD_XMIT; /* auto-pad short frames */
  238. mb->rcvfc = 0;
  239. /* load up the hardware address */
  240. __mace_set_address(dev, dev->dev_addr);
  241. /* clear the multicast filter */
  242. if (mp->chipid == BROKEN_ADDRCHG_REV)
  243. mb->iac = LOGADDR;
  244. else {
  245. mb->iac = ADDRCHG | LOGADDR;
  246. while ((mb->iac & ADDRCHG) != 0)
  247. ;
  248. }
  249. for (i = 0; i < 8; ++i)
  250. mb->ladrf = 0;
  251. /* done changing address */
  252. if (mp->chipid != BROKEN_ADDRCHG_REV)
  253. mb->iac = 0;
  254. mb->plscc = PORTSEL_AUI;
  255. }
  256. /*
  257. * Load the address on a mace controller.
  258. */
  259. static void __mace_set_address(struct net_device *dev, const void *addr)
  260. {
  261. struct mace_data *mp = netdev_priv(dev);
  262. volatile struct mace *mb = mp->mace;
  263. const unsigned char *p = addr;
  264. u8 macaddr[ETH_ALEN];
  265. int i;
  266. /* load up the hardware address */
  267. if (mp->chipid == BROKEN_ADDRCHG_REV)
  268. mb->iac = PHYADDR;
  269. else {
  270. mb->iac = ADDRCHG | PHYADDR;
  271. while ((mb->iac & ADDRCHG) != 0)
  272. ;
  273. }
  274. for (i = 0; i < 6; ++i)
  275. mb->padr = macaddr[i] = p[i];
  276. eth_hw_addr_set(dev, macaddr);
  277. if (mp->chipid != BROKEN_ADDRCHG_REV)
  278. mb->iac = 0;
  279. }
  280. static int mace_set_address(struct net_device *dev, void *addr)
  281. {
  282. struct mace_data *mp = netdev_priv(dev);
  283. volatile struct mace *mb = mp->mace;
  284. unsigned long flags;
  285. u8 maccc;
  286. local_irq_save(flags);
  287. maccc = mb->maccc;
  288. __mace_set_address(dev, addr);
  289. mb->maccc = maccc;
  290. local_irq_restore(flags);
  291. return 0;
  292. }
  293. /*
  294. * Open the Macintosh MACE. Most of this is playing with the DMA
  295. * engine. The ethernet chip is quite friendly.
  296. */
  297. static int mace_open(struct net_device *dev)
  298. {
  299. struct mace_data *mp = netdev_priv(dev);
  300. volatile struct mace *mb = mp->mace;
  301. /* reset the chip */
  302. mace_reset(dev);
  303. if (request_irq(dev->irq, mace_interrupt, 0, dev->name, dev)) {
  304. printk(KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq);
  305. return -EAGAIN;
  306. }
  307. if (request_irq(mp->dma_intr, mace_dma_intr, 0, dev->name, dev)) {
  308. printk(KERN_ERR "%s: can't get irq %d\n", dev->name, mp->dma_intr);
  309. free_irq(dev->irq, dev);
  310. return -EAGAIN;
  311. }
  312. /* Allocate the DMA ring buffers */
  313. mp->tx_ring = dma_alloc_coherent(mp->device,
  314. N_TX_RING * MACE_BUFF_SIZE,
  315. &mp->tx_ring_phys, GFP_KERNEL);
  316. if (mp->tx_ring == NULL)
  317. goto out1;
  318. mp->rx_ring = dma_alloc_coherent(mp->device,
  319. N_RX_RING * MACE_BUFF_SIZE,
  320. &mp->rx_ring_phys, GFP_KERNEL);
  321. if (mp->rx_ring == NULL)
  322. goto out2;
  323. mace_dma_off(dev);
  324. /* Not sure what these do */
  325. psc_write_word(PSC_ENETWR_CTL, 0x9000);
  326. psc_write_word(PSC_ENETRD_CTL, 0x9000);
  327. psc_write_word(PSC_ENETWR_CTL, 0x0400);
  328. psc_write_word(PSC_ENETRD_CTL, 0x0400);
  329. mace_rxdma_reset(dev);
  330. mace_txdma_reset(dev);
  331. /* turn it on! */
  332. mb->maccc = ENXMT | ENRCV;
  333. /* enable all interrupts except receive interrupts */
  334. mb->imr = RCVINT;
  335. return 0;
  336. out2:
  337. dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
  338. mp->tx_ring, mp->tx_ring_phys);
  339. out1:
  340. free_irq(dev->irq, dev);
  341. free_irq(mp->dma_intr, dev);
  342. return -ENOMEM;
  343. }
  344. /*
  345. * Shut down the mace and its interrupt channel
  346. */
  347. static int mace_close(struct net_device *dev)
  348. {
  349. struct mace_data *mp = netdev_priv(dev);
  350. volatile struct mace *mb = mp->mace;
  351. mb->maccc = 0; /* disable rx and tx */
  352. mb->imr = 0xFF; /* disable all irqs */
  353. mace_dma_off(dev); /* disable rx and tx dma */
  354. return 0;
  355. }
  356. /*
  357. * Transmit a frame
  358. */
  359. static netdev_tx_t mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
  360. {
  361. struct mace_data *mp = netdev_priv(dev);
  362. unsigned long flags;
  363. /* Stop the queue since there's only the one buffer */
  364. local_irq_save(flags);
  365. netif_stop_queue(dev);
  366. if (!mp->tx_count) {
  367. printk(KERN_ERR "macmace: tx queue running but no free buffers.\n");
  368. local_irq_restore(flags);
  369. return NETDEV_TX_BUSY;
  370. }
  371. mp->tx_count--;
  372. local_irq_restore(flags);
  373. dev->stats.tx_packets++;
  374. dev->stats.tx_bytes += skb->len;
  375. /* We need to copy into our xmit buffer to take care of alignment and caching issues */
  376. skb_copy_from_linear_data(skb, mp->tx_ring, skb->len);
  377. /* load the Tx DMA and fire it off */
  378. psc_write_long(PSC_ENETWR_ADDR + mp->tx_slot, (u32) mp->tx_ring_phys);
  379. psc_write_long(PSC_ENETWR_LEN + mp->tx_slot, skb->len);
  380. psc_write_word(PSC_ENETWR_CMD + mp->tx_slot, 0x9800);
  381. mp->tx_slot ^= 0x10;
  382. dev_kfree_skb(skb);
  383. return NETDEV_TX_OK;
  384. }
  385. static void mace_set_multicast(struct net_device *dev)
  386. {
  387. struct mace_data *mp = netdev_priv(dev);
  388. volatile struct mace *mb = mp->mace;
  389. int i;
  390. u32 crc;
  391. u8 maccc;
  392. unsigned long flags;
  393. local_irq_save(flags);
  394. maccc = mb->maccc;
  395. mb->maccc &= ~PROM;
  396. if (dev->flags & IFF_PROMISC) {
  397. mb->maccc |= PROM;
  398. } else {
  399. unsigned char multicast_filter[8];
  400. struct netdev_hw_addr *ha;
  401. if (dev->flags & IFF_ALLMULTI) {
  402. for (i = 0; i < 8; i++) {
  403. multicast_filter[i] = 0xFF;
  404. }
  405. } else {
  406. for (i = 0; i < 8; i++)
  407. multicast_filter[i] = 0;
  408. netdev_for_each_mc_addr(ha, dev) {
  409. crc = ether_crc_le(6, ha->addr);
  410. /* bit number in multicast_filter */
  411. i = crc >> 26;
  412. multicast_filter[i >> 3] |= 1 << (i & 7);
  413. }
  414. }
  415. if (mp->chipid == BROKEN_ADDRCHG_REV)
  416. mb->iac = LOGADDR;
  417. else {
  418. mb->iac = ADDRCHG | LOGADDR;
  419. while ((mb->iac & ADDRCHG) != 0)
  420. ;
  421. }
  422. for (i = 0; i < 8; ++i)
  423. mb->ladrf = multicast_filter[i];
  424. if (mp->chipid != BROKEN_ADDRCHG_REV)
  425. mb->iac = 0;
  426. }
  427. mb->maccc = maccc;
  428. local_irq_restore(flags);
  429. }
  430. static void mace_handle_misc_intrs(struct net_device *dev, int intr)
  431. {
  432. struct mace_data *mp = netdev_priv(dev);
  433. volatile struct mace *mb = mp->mace;
  434. static int mace_babbles, mace_jabbers;
  435. if (intr & MPCO)
  436. dev->stats.rx_missed_errors += 256;
  437. dev->stats.rx_missed_errors += mb->mpc; /* reading clears it */
  438. if (intr & RNTPCO)
  439. dev->stats.rx_length_errors += 256;
  440. dev->stats.rx_length_errors += mb->rntpc; /* reading clears it */
  441. if (intr & CERR)
  442. ++dev->stats.tx_heartbeat_errors;
  443. if (intr & BABBLE)
  444. if (mace_babbles++ < 4)
  445. printk(KERN_DEBUG "macmace: babbling transmitter\n");
  446. if (intr & JABBER)
  447. if (mace_jabbers++ < 4)
  448. printk(KERN_DEBUG "macmace: jabbering transceiver\n");
  449. }
  450. static irqreturn_t mace_interrupt(int irq, void *dev_id)
  451. {
  452. struct net_device *dev = (struct net_device *) dev_id;
  453. struct mace_data *mp = netdev_priv(dev);
  454. volatile struct mace *mb = mp->mace;
  455. int intr, fs;
  456. unsigned long flags;
  457. /* don't want the dma interrupt handler to fire */
  458. local_irq_save(flags);
  459. intr = mb->ir; /* read interrupt register */
  460. mace_handle_misc_intrs(dev, intr);
  461. if (intr & XMTINT) {
  462. fs = mb->xmtfs;
  463. if ((fs & XMTSV) == 0) {
  464. printk(KERN_ERR "macmace: xmtfs not valid! (fs=%x)\n", fs);
  465. mace_reset(dev);
  466. /*
  467. * XXX mace likes to hang the machine after a xmtfs error.
  468. * This is hard to reproduce, resetting *may* help
  469. */
  470. }
  471. /* dma should have finished */
  472. if (!mp->tx_count) {
  473. printk(KERN_DEBUG "macmace: tx ring ran out? (fs=%x)\n", fs);
  474. }
  475. /* Update stats */
  476. if (fs & (UFLO|LCOL|LCAR|RTRY)) {
  477. ++dev->stats.tx_errors;
  478. if (fs & LCAR)
  479. ++dev->stats.tx_carrier_errors;
  480. else if (fs & (UFLO|LCOL|RTRY)) {
  481. ++dev->stats.tx_aborted_errors;
  482. if (mb->xmtfs & UFLO) {
  483. dev->stats.tx_fifo_errors++;
  484. mace_txdma_reset(dev);
  485. }
  486. }
  487. }
  488. }
  489. if (mp->tx_count)
  490. netif_wake_queue(dev);
  491. local_irq_restore(flags);
  492. return IRQ_HANDLED;
  493. }
  494. static void mace_tx_timeout(struct net_device *dev, unsigned int txqueue)
  495. {
  496. struct mace_data *mp = netdev_priv(dev);
  497. volatile struct mace *mb = mp->mace;
  498. unsigned long flags;
  499. local_irq_save(flags);
  500. /* turn off both tx and rx and reset the chip */
  501. mb->maccc = 0;
  502. printk(KERN_ERR "macmace: transmit timeout - resetting\n");
  503. mace_txdma_reset(dev);
  504. mace_reset(dev);
  505. /* restart rx dma */
  506. mace_rxdma_reset(dev);
  507. mp->tx_count = N_TX_RING;
  508. netif_wake_queue(dev);
  509. /* turn it on! */
  510. mb->maccc = ENXMT | ENRCV;
  511. /* enable all interrupts except receive interrupts */
  512. mb->imr = RCVINT;
  513. local_irq_restore(flags);
  514. }
  515. /*
  516. * Handle a newly arrived frame
  517. */
  518. static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf)
  519. {
  520. struct sk_buff *skb;
  521. unsigned int frame_status = mf->rcvsts;
  522. if (frame_status & (RS_OFLO | RS_CLSN | RS_FRAMERR | RS_FCSERR)) {
  523. dev->stats.rx_errors++;
  524. if (frame_status & RS_OFLO)
  525. dev->stats.rx_fifo_errors++;
  526. if (frame_status & RS_CLSN)
  527. dev->stats.collisions++;
  528. if (frame_status & RS_FRAMERR)
  529. dev->stats.rx_frame_errors++;
  530. if (frame_status & RS_FCSERR)
  531. dev->stats.rx_crc_errors++;
  532. } else {
  533. unsigned int frame_length = mf->rcvcnt + ((frame_status & 0x0F) << 8 );
  534. skb = netdev_alloc_skb(dev, frame_length + 2);
  535. if (!skb) {
  536. dev->stats.rx_dropped++;
  537. return;
  538. }
  539. skb_reserve(skb, 2);
  540. skb_put_data(skb, mf->data, frame_length);
  541. skb->protocol = eth_type_trans(skb, dev);
  542. netif_rx(skb);
  543. dev->stats.rx_packets++;
  544. dev->stats.rx_bytes += frame_length;
  545. }
  546. }
  547. /*
  548. * The PSC has passed us a DMA interrupt event.
  549. */
  550. static irqreturn_t mace_dma_intr(int irq, void *dev_id)
  551. {
  552. struct net_device *dev = (struct net_device *) dev_id;
  553. struct mace_data *mp = netdev_priv(dev);
  554. int left, head;
  555. u16 status;
  556. u32 baka;
  557. /* Not sure what this does */
  558. while ((baka = psc_read_long(PSC_MYSTERY)) != psc_read_long(PSC_MYSTERY));
  559. if (!(baka & 0x60000000)) return IRQ_NONE;
  560. /*
  561. * Process the read queue
  562. */
  563. status = psc_read_word(PSC_ENETRD_CTL);
  564. if (status & 0x2000) {
  565. mace_rxdma_reset(dev);
  566. } else if (status & 0x0100) {
  567. psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x1100);
  568. left = psc_read_long(PSC_ENETRD_LEN + mp->rx_slot);
  569. head = N_RX_RING - left;
  570. /* Loop through the ring buffer and process new packages */
  571. while (mp->rx_tail < head) {
  572. mace_dma_rx_frame(dev, (struct mace_frame*) (mp->rx_ring
  573. + (mp->rx_tail * MACE_BUFF_SIZE)));
  574. mp->rx_tail++;
  575. }
  576. /* If we're out of buffers in this ring then switch to */
  577. /* the other set, otherwise just reactivate this one. */
  578. if (!left) {
  579. mace_load_rxdma_base(dev, mp->rx_slot);
  580. mp->rx_slot ^= 0x10;
  581. } else {
  582. psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x9800);
  583. }
  584. }
  585. /*
  586. * Process the write queue
  587. */
  588. status = psc_read_word(PSC_ENETWR_CTL);
  589. if (status & 0x2000) {
  590. mace_txdma_reset(dev);
  591. } else if (status & 0x0100) {
  592. psc_write_word(PSC_ENETWR_CMD + mp->tx_sloti, 0x0100);
  593. mp->tx_sloti ^= 0x10;
  594. mp->tx_count++;
  595. }
  596. return IRQ_HANDLED;
  597. }
  598. MODULE_LICENSE("GPL");
  599. MODULE_DESCRIPTION("Macintosh MACE ethernet driver");
  600. MODULE_ALIAS("platform:macmace");
  601. static int mac_mace_device_remove(struct platform_device *pdev)
  602. {
  603. struct net_device *dev = platform_get_drvdata(pdev);
  604. struct mace_data *mp = netdev_priv(dev);
  605. unregister_netdev(dev);
  606. free_irq(dev->irq, dev);
  607. free_irq(IRQ_MAC_MACE_DMA, dev);
  608. dma_free_coherent(mp->device, N_RX_RING * MACE_BUFF_SIZE,
  609. mp->rx_ring, mp->rx_ring_phys);
  610. dma_free_coherent(mp->device, N_TX_RING * MACE_BUFF_SIZE,
  611. mp->tx_ring, mp->tx_ring_phys);
  612. free_netdev(dev);
  613. return 0;
  614. }
  615. static struct platform_driver mac_mace_driver = {
  616. .probe = mace_probe,
  617. .remove = mac_mace_device_remove,
  618. .driver = {
  619. .name = mac_mace_string,
  620. },
  621. };
  622. module_platform_driver(mac_mace_driver);