macmace.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Driver for the Macintosh 68K onboard MACE controller with PSC
  3. * driven DMA. The MACE driver code is derived from mace.c. The
  4. * Mac68k theory of operation is courtesy of the MacBSD wizards.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Copyright (C) 1996 Paul Mackerras.
  12. * Copyright (C) 1998 Alan Cox <alan@redhat.com>
  13. *
  14. * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/delay.h>
  21. #include <linux/string.h>
  22. #include <linux/crc32.h>
  23. #include <asm/io.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/irq.h>
  26. #include <asm/macintosh.h>
  27. #include <asm/macints.h>
  28. #include <asm/mac_psc.h>
  29. #include <asm/page.h>
  30. #include "mace.h"
  31. #define N_TX_RING 1
  32. #define N_RX_RING 8
  33. #define N_RX_PAGES ((N_RX_RING * 0x0800 + PAGE_SIZE - 1) / PAGE_SIZE)
  34. #define TX_TIMEOUT HZ
  35. /* Bits in transmit DMA status */
  36. #define TX_DMA_ERR 0x80
  37. /* The MACE is simply wired down on a Mac68K box */
  38. #define MACE_BASE (void *)(0x50F1C000)
  39. #define MACE_PROM (void *)(0x50F08001)
  40. struct mace_data {
  41. volatile struct mace *mace;
  42. volatile unsigned char *tx_ring;
  43. volatile unsigned char *tx_ring_phys;
  44. volatile unsigned char *rx_ring;
  45. volatile unsigned char *rx_ring_phys;
  46. int dma_intr;
  47. struct net_device_stats stats;
  48. int rx_slot, rx_tail;
  49. int tx_slot, tx_sloti, tx_count;
  50. };
  51. struct mace_frame {
  52. u16 len;
  53. u16 status;
  54. u16 rntpc;
  55. u16 rcvcc;
  56. u32 pad1;
  57. u32 pad2;
  58. u8 data[1];
  59. /* And frame continues.. */
  60. };
  61. #define PRIV_BYTES sizeof(struct mace_data)
  62. extern void psc_debug_dump(void);
  63. static int mace_open(struct net_device *dev);
  64. static int mace_close(struct net_device *dev);
  65. static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev);
  66. static struct net_device_stats *mace_stats(struct net_device *dev);
  67. static void mace_set_multicast(struct net_device *dev);
  68. static int mace_set_address(struct net_device *dev, void *addr);
  69. static irqreturn_t mace_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  70. static irqreturn_t mace_dma_intr(int irq, void *dev_id, struct pt_regs *regs);
  71. static void mace_tx_timeout(struct net_device *dev);
  72. /* Bit-reverse one byte of an ethernet hardware address. */
  73. static int bitrev(int b)
  74. {
  75. int d = 0, i;
  76. for (i = 0; i < 8; ++i, b >>= 1) {
  77. d = (d << 1) | (b & 1);
  78. }
  79. return d;
  80. }
  81. /*
  82. * Load a receive DMA channel with a base address and ring length
  83. */
  84. static void mace_load_rxdma_base(struct net_device *dev, int set)
  85. {
  86. struct mace_data *mp = (struct mace_data *) dev->priv;
  87. psc_write_word(PSC_ENETRD_CMD + set, 0x0100);
  88. psc_write_long(PSC_ENETRD_ADDR + set, (u32) mp->rx_ring_phys);
  89. psc_write_long(PSC_ENETRD_LEN + set, N_RX_RING);
  90. psc_write_word(PSC_ENETRD_CMD + set, 0x9800);
  91. mp->rx_tail = 0;
  92. }
  93. /*
  94. * Reset the receive DMA subsystem
  95. */
  96. static void mace_rxdma_reset(struct net_device *dev)
  97. {
  98. struct mace_data *mp = (struct mace_data *) dev->priv;
  99. volatile struct mace *mace = mp->mace;
  100. u8 maccc = mace->maccc;
  101. mace->maccc = maccc & ~ENRCV;
  102. psc_write_word(PSC_ENETRD_CTL, 0x8800);
  103. mace_load_rxdma_base(dev, 0x00);
  104. psc_write_word(PSC_ENETRD_CTL, 0x0400);
  105. psc_write_word(PSC_ENETRD_CTL, 0x8800);
  106. mace_load_rxdma_base(dev, 0x10);
  107. psc_write_word(PSC_ENETRD_CTL, 0x0400);
  108. mace->maccc = maccc;
  109. mp->rx_slot = 0;
  110. psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x9800);
  111. psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x9800);
  112. }
  113. /*
  114. * Reset the transmit DMA subsystem
  115. */
  116. static void mace_txdma_reset(struct net_device *dev)
  117. {
  118. struct mace_data *mp = (struct mace_data *) dev->priv;
  119. volatile struct mace *mace = mp->mace;
  120. u8 maccc;
  121. psc_write_word(PSC_ENETWR_CTL, 0x8800);
  122. maccc = mace->maccc;
  123. mace->maccc = maccc & ~ENXMT;
  124. mp->tx_slot = mp->tx_sloti = 0;
  125. mp->tx_count = N_TX_RING;
  126. psc_write_word(PSC_ENETWR_CTL, 0x0400);
  127. mace->maccc = maccc;
  128. }
  129. /*
  130. * Disable DMA
  131. */
  132. static void mace_dma_off(struct net_device *dev)
  133. {
  134. psc_write_word(PSC_ENETRD_CTL, 0x8800);
  135. psc_write_word(PSC_ENETRD_CTL, 0x1000);
  136. psc_write_word(PSC_ENETRD_CMD + PSC_SET0, 0x1100);
  137. psc_write_word(PSC_ENETRD_CMD + PSC_SET1, 0x1100);
  138. psc_write_word(PSC_ENETWR_CTL, 0x8800);
  139. psc_write_word(PSC_ENETWR_CTL, 0x1000);
  140. psc_write_word(PSC_ENETWR_CMD + PSC_SET0, 0x1100);
  141. psc_write_word(PSC_ENETWR_CMD + PSC_SET1, 0x1100);
  142. }
  143. /*
  144. * Not really much of a probe. The hardware table tells us if this
  145. * model of Macintrash has a MACE (AV macintoshes)
  146. */
  147. struct net_device *mace_probe(int unit)
  148. {
  149. int j;
  150. struct mace_data *mp;
  151. unsigned char *addr;
  152. struct net_device *dev;
  153. unsigned char checksum = 0;
  154. static int found = 0;
  155. int err;
  156. if (found || macintosh_config->ether_type != MAC_ETHER_MACE)
  157. return ERR_PTR(-ENODEV);
  158. found = 1; /* prevent 'finding' one on every device probe */
  159. dev = alloc_etherdev(PRIV_BYTES);
  160. if (!dev)
  161. return ERR_PTR(-ENOMEM);
  162. if (unit >= 0)
  163. sprintf(dev->name, "eth%d", unit);
  164. mp = (struct mace_data *) dev->priv;
  165. dev->base_addr = (u32)MACE_BASE;
  166. mp->mace = (volatile struct mace *) MACE_BASE;
  167. dev->irq = IRQ_MAC_MACE;
  168. mp->dma_intr = IRQ_MAC_MACE_DMA;
  169. /*
  170. * The PROM contains 8 bytes which total 0xFF when XOR'd
  171. * together. Due to the usual peculiar apple brain damage
  172. * the bytes are spaced out in a strange boundary and the
  173. * bits are reversed.
  174. */
  175. addr = (void *)MACE_PROM;
  176. for (j = 0; j < 6; ++j) {
  177. u8 v=bitrev(addr[j<<4]);
  178. checksum ^= v;
  179. dev->dev_addr[j] = v;
  180. }
  181. for (; j < 8; ++j) {
  182. checksum ^= bitrev(addr[j<<4]);
  183. }
  184. if (checksum != 0xFF) {
  185. free_netdev(dev);
  186. return ERR_PTR(-ENODEV);
  187. }
  188. memset(&mp->stats, 0, sizeof(mp->stats));
  189. dev->open = mace_open;
  190. dev->stop = mace_close;
  191. dev->hard_start_xmit = mace_xmit_start;
  192. dev->tx_timeout = mace_tx_timeout;
  193. dev->watchdog_timeo = TX_TIMEOUT;
  194. dev->get_stats = mace_stats;
  195. dev->set_multicast_list = mace_set_multicast;
  196. dev->set_mac_address = mace_set_address;
  197. printk(KERN_INFO "%s: 68K MACE, hardware address %.2X", dev->name, dev->dev_addr[0]);
  198. for (j = 1 ; j < 6 ; j++) printk(":%.2X", dev->dev_addr[j]);
  199. printk("\n");
  200. err = register_netdev(dev);
  201. if (!err)
  202. return dev;
  203. free_netdev(dev);
  204. return ERR_PTR(err);
  205. }
  206. /*
  207. * Load the address on a mace controller.
  208. */
  209. static int mace_set_address(struct net_device *dev, void *addr)
  210. {
  211. unsigned char *p = addr;
  212. struct mace_data *mp = (struct mace_data *) dev->priv;
  213. volatile struct mace *mb = mp->mace;
  214. int i;
  215. unsigned long flags;
  216. u8 maccc;
  217. local_irq_save(flags);
  218. maccc = mb->maccc;
  219. /* load up the hardware address */
  220. mb->iac = ADDRCHG | PHYADDR;
  221. while ((mb->iac & ADDRCHG) != 0);
  222. for (i = 0; i < 6; ++i) {
  223. mb->padr = dev->dev_addr[i] = p[i];
  224. }
  225. mb->maccc = maccc;
  226. local_irq_restore(flags);
  227. return 0;
  228. }
  229. /*
  230. * Open the Macintosh MACE. Most of this is playing with the DMA
  231. * engine. The ethernet chip is quite friendly.
  232. */
  233. static int mace_open(struct net_device *dev)
  234. {
  235. struct mace_data *mp = (struct mace_data *) dev->priv;
  236. volatile struct mace *mb = mp->mace;
  237. #if 0
  238. int i;
  239. i = 200;
  240. while (--i) {
  241. mb->biucc = SWRST;
  242. if (mb->biucc & SWRST) {
  243. udelay(10);
  244. continue;
  245. }
  246. break;
  247. }
  248. if (!i) {
  249. printk(KERN_ERR "%s: software reset failed!!\n", dev->name);
  250. return -EAGAIN;
  251. }
  252. #endif
  253. mb->biucc = XMTSP_64;
  254. mb->fifocc = XMTFW_16 | RCVFW_64 | XMTFWU | RCVFWU | XMTBRST | RCVBRST;
  255. mb->xmtfc = AUTO_PAD_XMIT;
  256. mb->plscc = PORTSEL_AUI;
  257. /* mb->utr = RTRD; */
  258. if (request_irq(dev->irq, mace_interrupt, 0, dev->name, dev)) {
  259. printk(KERN_ERR "%s: can't get irq %d\n", dev->name, dev->irq);
  260. return -EAGAIN;
  261. }
  262. if (request_irq(mp->dma_intr, mace_dma_intr, 0, dev->name, dev)) {
  263. printk(KERN_ERR "%s: can't get irq %d\n", dev->name, mp->dma_intr);
  264. free_irq(dev->irq, dev);
  265. return -EAGAIN;
  266. }
  267. /* Allocate the DMA ring buffers */
  268. mp->rx_ring = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, N_RX_PAGES);
  269. mp->tx_ring = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, 0);
  270. if (mp->tx_ring==NULL || mp->rx_ring==NULL) {
  271. if (mp->rx_ring) free_pages((u32) mp->rx_ring, N_RX_PAGES);
  272. if (mp->tx_ring) free_pages((u32) mp->tx_ring, 0);
  273. free_irq(dev->irq, dev);
  274. free_irq(mp->dma_intr, dev);
  275. printk(KERN_ERR "%s: unable to allocate DMA buffers\n", dev->name);
  276. return -ENOMEM;
  277. }
  278. mp->rx_ring_phys = (unsigned char *) virt_to_bus((void *)mp->rx_ring);
  279. mp->tx_ring_phys = (unsigned char *) virt_to_bus((void *)mp->tx_ring);
  280. /* We want the Rx buffer to be uncached and the Tx buffer to be writethrough */
  281. kernel_set_cachemode((void *)mp->rx_ring, N_RX_PAGES * PAGE_SIZE, IOMAP_NOCACHE_NONSER);
  282. kernel_set_cachemode((void *)mp->tx_ring, PAGE_SIZE, IOMAP_WRITETHROUGH);
  283. mace_dma_off(dev);
  284. /* Not sure what these do */
  285. psc_write_word(PSC_ENETWR_CTL, 0x9000);
  286. psc_write_word(PSC_ENETRD_CTL, 0x9000);
  287. psc_write_word(PSC_ENETWR_CTL, 0x0400);
  288. psc_write_word(PSC_ENETRD_CTL, 0x0400);
  289. #if 0
  290. /* load up the hardware address */
  291. mb->iac = ADDRCHG | PHYADDR;
  292. while ((mb->iac & ADDRCHG) != 0);
  293. for (i = 0; i < 6; ++i)
  294. mb->padr = dev->dev_addr[i];
  295. /* clear the multicast filter */
  296. mb->iac = ADDRCHG | LOGADDR;
  297. while ((mb->iac & ADDRCHG) != 0);
  298. for (i = 0; i < 8; ++i)
  299. mb->ladrf = 0;
  300. mb->plscc = PORTSEL_GPSI + ENPLSIO;
  301. mb->maccc = ENXMT | ENRCV;
  302. mb->imr = RCVINT;
  303. #endif
  304. mace_rxdma_reset(dev);
  305. mace_txdma_reset(dev);
  306. return 0;
  307. }
  308. /*
  309. * Shut down the mace and its interrupt channel
  310. */
  311. static int mace_close(struct net_device *dev)
  312. {
  313. struct mace_data *mp = (struct mace_data *) dev->priv;
  314. volatile struct mace *mb = mp->mace;
  315. mb->maccc = 0; /* disable rx and tx */
  316. mb->imr = 0xFF; /* disable all irqs */
  317. mace_dma_off(dev); /* disable rx and tx dma */
  318. free_irq(dev->irq, dev);
  319. free_irq(IRQ_MAC_MACE_DMA, dev);
  320. free_pages((u32) mp->rx_ring, N_RX_PAGES);
  321. free_pages((u32) mp->tx_ring, 0);
  322. return 0;
  323. }
  324. /*
  325. * Transmit a frame
  326. */
  327. static int mace_xmit_start(struct sk_buff *skb, struct net_device *dev)
  328. {
  329. struct mace_data *mp = (struct mace_data *) dev->priv;
  330. /* Stop the queue if the buffer is full */
  331. if (!mp->tx_count) {
  332. netif_stop_queue(dev);
  333. return 1;
  334. }
  335. mp->tx_count--;
  336. mp->stats.tx_packets++;
  337. mp->stats.tx_bytes += skb->len;
  338. /* We need to copy into our xmit buffer to take care of alignment and caching issues */
  339. memcpy((void *) mp->tx_ring, skb->data, skb->len);
  340. /* load the Tx DMA and fire it off */
  341. psc_write_long(PSC_ENETWR_ADDR + mp->tx_slot, (u32) mp->tx_ring_phys);
  342. psc_write_long(PSC_ENETWR_LEN + mp->tx_slot, skb->len);
  343. psc_write_word(PSC_ENETWR_CMD + mp->tx_slot, 0x9800);
  344. mp->tx_slot ^= 0x10;
  345. dev_kfree_skb(skb);
  346. return 0;
  347. }
  348. static struct net_device_stats *mace_stats(struct net_device *dev)
  349. {
  350. struct mace_data *p = (struct mace_data *) dev->priv;
  351. return &p->stats;
  352. }
  353. static void mace_set_multicast(struct net_device *dev)
  354. {
  355. struct mace_data *mp = (struct mace_data *) dev->priv;
  356. volatile struct mace *mb = mp->mace;
  357. int i, j;
  358. u32 crc;
  359. u8 maccc;
  360. maccc = mb->maccc;
  361. mb->maccc &= ~PROM;
  362. if (dev->flags & IFF_PROMISC) {
  363. mb->maccc |= PROM;
  364. } else {
  365. unsigned char multicast_filter[8];
  366. struct dev_mc_list *dmi = dev->mc_list;
  367. if (dev->flags & IFF_ALLMULTI) {
  368. for (i = 0; i < 8; i++) {
  369. multicast_filter[i] = 0xFF;
  370. }
  371. } else {
  372. for (i = 0; i < 8; i++)
  373. multicast_filter[i] = 0;
  374. for (i = 0; i < dev->mc_count; i++) {
  375. crc = ether_crc_le(6, dmi->dmi_addr);
  376. j = crc >> 26; /* bit number in multicast_filter */
  377. multicast_filter[j >> 3] |= 1 << (j & 7);
  378. dmi = dmi->next;
  379. }
  380. }
  381. mb->iac = ADDRCHG | LOGADDR;
  382. while (mb->iac & ADDRCHG);
  383. for (i = 0; i < 8; ++i) {
  384. mb->ladrf = multicast_filter[i];
  385. }
  386. }
  387. mb->maccc = maccc;
  388. }
  389. /*
  390. * Miscellaneous interrupts are handled here. We may end up
  391. * having to bash the chip on the head for bad errors
  392. */
  393. static void mace_handle_misc_intrs(struct mace_data *mp, int intr)
  394. {
  395. volatile struct mace *mb = mp->mace;
  396. static int mace_babbles, mace_jabbers;
  397. if (intr & MPCO) {
  398. mp->stats.rx_missed_errors += 256;
  399. }
  400. mp->stats.rx_missed_errors += mb->mpc; /* reading clears it */
  401. if (intr & RNTPCO) {
  402. mp->stats.rx_length_errors += 256;
  403. }
  404. mp->stats.rx_length_errors += mb->rntpc; /* reading clears it */
  405. if (intr & CERR) {
  406. ++mp->stats.tx_heartbeat_errors;
  407. }
  408. if (intr & BABBLE) {
  409. if (mace_babbles++ < 4) {
  410. printk(KERN_DEBUG "mace: babbling transmitter\n");
  411. }
  412. }
  413. if (intr & JABBER) {
  414. if (mace_jabbers++ < 4) {
  415. printk(KERN_DEBUG "mace: jabbering transceiver\n");
  416. }
  417. }
  418. }
  419. /*
  420. * A transmit error has occurred. (We kick the transmit side from
  421. * the DMA completion)
  422. */
  423. static void mace_xmit_error(struct net_device *dev)
  424. {
  425. struct mace_data *mp = (struct mace_data *) dev->priv;
  426. volatile struct mace *mb = mp->mace;
  427. u8 xmtfs, xmtrc;
  428. xmtfs = mb->xmtfs;
  429. xmtrc = mb->xmtrc;
  430. if (xmtfs & XMTSV) {
  431. if (xmtfs & UFLO) {
  432. printk("%s: DMA underrun.\n", dev->name);
  433. mp->stats.tx_errors++;
  434. mp->stats.tx_fifo_errors++;
  435. mace_txdma_reset(dev);
  436. }
  437. if (xmtfs & RTRY) {
  438. mp->stats.collisions++;
  439. }
  440. }
  441. }
  442. /*
  443. * A receive interrupt occurred.
  444. */
  445. static void mace_recv_interrupt(struct net_device *dev)
  446. {
  447. /* struct mace_data *mp = (struct mace_data *) dev->priv; */
  448. // volatile struct mace *mb = mp->mace;
  449. }
  450. /*
  451. * Process the chip interrupt
  452. */
  453. static irqreturn_t mace_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  454. {
  455. struct net_device *dev = (struct net_device *) dev_id;
  456. struct mace_data *mp = (struct mace_data *) dev->priv;
  457. volatile struct mace *mb = mp->mace;
  458. u8 ir;
  459. ir = mb->ir;
  460. mace_handle_misc_intrs(mp, ir);
  461. if (ir & XMTINT) {
  462. mace_xmit_error(dev);
  463. }
  464. if (ir & RCVINT) {
  465. mace_recv_interrupt(dev);
  466. }
  467. return IRQ_HANDLED;
  468. }
  469. static void mace_tx_timeout(struct net_device *dev)
  470. {
  471. /* struct mace_data *mp = (struct mace_data *) dev->priv; */
  472. // volatile struct mace *mb = mp->mace;
  473. }
  474. /*
  475. * Handle a newly arrived frame
  476. */
  477. static void mace_dma_rx_frame(struct net_device *dev, struct mace_frame *mf)
  478. {
  479. struct mace_data *mp = (struct mace_data *) dev->priv;
  480. struct sk_buff *skb;
  481. if (mf->status & RS_OFLO) {
  482. printk("%s: fifo overflow.\n", dev->name);
  483. mp->stats.rx_errors++;
  484. mp->stats.rx_fifo_errors++;
  485. }
  486. if (mf->status&(RS_CLSN|RS_FRAMERR|RS_FCSERR))
  487. mp->stats.rx_errors++;
  488. if (mf->status&RS_CLSN) {
  489. mp->stats.collisions++;
  490. }
  491. if (mf->status&RS_FRAMERR) {
  492. mp->stats.rx_frame_errors++;
  493. }
  494. if (mf->status&RS_FCSERR) {
  495. mp->stats.rx_crc_errors++;
  496. }
  497. skb = dev_alloc_skb(mf->len+2);
  498. if (!skb) {
  499. mp->stats.rx_dropped++;
  500. return;
  501. }
  502. skb_reserve(skb,2);
  503. memcpy(skb_put(skb, mf->len), mf->data, mf->len);
  504. skb->dev = dev;
  505. skb->protocol = eth_type_trans(skb, dev);
  506. netif_rx(skb);
  507. dev->last_rx = jiffies;
  508. mp->stats.rx_packets++;
  509. mp->stats.rx_bytes += mf->len;
  510. }
  511. /*
  512. * The PSC has passed us a DMA interrupt event.
  513. */
  514. static irqreturn_t mace_dma_intr(int irq, void *dev_id, struct pt_regs *regs)
  515. {
  516. struct net_device *dev = (struct net_device *) dev_id;
  517. struct mace_data *mp = (struct mace_data *) dev->priv;
  518. int left, head;
  519. u16 status;
  520. u32 baka;
  521. /* Not sure what this does */
  522. while ((baka = psc_read_long(PSC_MYSTERY)) != psc_read_long(PSC_MYSTERY));
  523. if (!(baka & 0x60000000)) return IRQ_NONE;
  524. /*
  525. * Process the read queue
  526. */
  527. status = psc_read_word(PSC_ENETRD_CTL);
  528. if (status & 0x2000) {
  529. mace_rxdma_reset(dev);
  530. } else if (status & 0x0100) {
  531. psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x1100);
  532. left = psc_read_long(PSC_ENETRD_LEN + mp->rx_slot);
  533. head = N_RX_RING - left;
  534. /* Loop through the ring buffer and process new packages */
  535. while (mp->rx_tail < head) {
  536. mace_dma_rx_frame(dev, (struct mace_frame *) (mp->rx_ring + (mp->rx_tail * 0x0800)));
  537. mp->rx_tail++;
  538. }
  539. /* If we're out of buffers in this ring then switch to */
  540. /* the other set, otherwise just reactivate this one. */
  541. if (!left) {
  542. mace_load_rxdma_base(dev, mp->rx_slot);
  543. mp->rx_slot ^= 0x10;
  544. } else {
  545. psc_write_word(PSC_ENETRD_CMD + mp->rx_slot, 0x9800);
  546. }
  547. }
  548. /*
  549. * Process the write queue
  550. */
  551. status = psc_read_word(PSC_ENETWR_CTL);
  552. if (status & 0x2000) {
  553. mace_txdma_reset(dev);
  554. } else if (status & 0x0100) {
  555. psc_write_word(PSC_ENETWR_CMD + mp->tx_sloti, 0x0100);
  556. mp->tx_sloti ^= 0x10;
  557. mp->tx_count++;
  558. netif_wake_queue(dev);
  559. }
  560. return IRQ_HANDLED;
  561. }
  562. MODULE_LICENSE("GPL");