sgiseeq.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. * sgiseeq.c: Seeq8003 ethernet driver for SGI machines.
  3. *
  4. * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
  5. */
  6. #undef DEBUG
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/errno.h>
  10. #include <linux/init.h>
  11. #include <linux/types.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/slab.h>
  14. #include <linux/string.h>
  15. #include <linux/delay.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/skbuff.h>
  20. #include <asm/sgi/hpc3.h>
  21. #include <asm/sgi/ip22.h>
  22. #include <asm/sgi/seeq.h>
  23. #include "sgiseeq.h"
  24. static char *sgiseeqstr = "SGI Seeq8003";
  25. /*
  26. * If you want speed, you do something silly, it always has worked for me. So,
  27. * with that in mind, I've decided to make this driver look completely like a
  28. * stupid Lance from a driver architecture perspective. Only difference is that
  29. * here our "ring buffer" looks and acts like a real Lance one does but is
  30. * layed out like how the HPC DMA and the Seeq want it to. You'd be surprised
  31. * how a stupid idea like this can pay off in performance, not to mention
  32. * making this driver 2,000 times easier to write. ;-)
  33. */
  34. /* Tune these if we tend to run out often etc. */
  35. #define SEEQ_RX_BUFFERS 16
  36. #define SEEQ_TX_BUFFERS 16
  37. #define PKT_BUF_SZ 1584
  38. #define NEXT_RX(i) (((i) + 1) & (SEEQ_RX_BUFFERS - 1))
  39. #define NEXT_TX(i) (((i) + 1) & (SEEQ_TX_BUFFERS - 1))
  40. #define PREV_RX(i) (((i) - 1) & (SEEQ_RX_BUFFERS - 1))
  41. #define PREV_TX(i) (((i) - 1) & (SEEQ_TX_BUFFERS - 1))
  42. #define TX_BUFFS_AVAIL(sp) ((sp->tx_old <= sp->tx_new) ? \
  43. sp->tx_old + (SEEQ_TX_BUFFERS - 1) - sp->tx_new : \
  44. sp->tx_old - sp->tx_new - 1)
  45. struct sgiseeq_rx_desc {
  46. volatile struct hpc_dma_desc rdma;
  47. volatile signed int buf_vaddr;
  48. };
  49. struct sgiseeq_tx_desc {
  50. volatile struct hpc_dma_desc tdma;
  51. volatile signed int buf_vaddr;
  52. };
  53. /*
  54. * Warning: This structure is layed out in a certain way because HPC dma
  55. * descriptors must be 8-byte aligned. So don't touch this without
  56. * some care.
  57. */
  58. struct sgiseeq_init_block { /* Note the name ;-) */
  59. struct sgiseeq_rx_desc rxvector[SEEQ_RX_BUFFERS];
  60. struct sgiseeq_tx_desc txvector[SEEQ_TX_BUFFERS];
  61. };
  62. struct sgiseeq_private {
  63. struct sgiseeq_init_block *srings;
  64. dma_addr_t srings_dma;
  65. /* Ptrs to the descriptors in uncached space. */
  66. struct sgiseeq_rx_desc *rx_desc;
  67. struct sgiseeq_tx_desc *tx_desc;
  68. char *name;
  69. struct hpc3_ethregs *hregs;
  70. struct sgiseeq_regs *sregs;
  71. /* Ring entry counters. */
  72. unsigned int rx_new, tx_new;
  73. unsigned int rx_old, tx_old;
  74. int is_edlc;
  75. unsigned char control;
  76. unsigned char mode;
  77. spinlock_t tx_lock;
  78. };
  79. static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
  80. {
  81. hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ;
  82. udelay(20);
  83. hregs->reset = 0;
  84. }
  85. static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
  86. struct sgiseeq_regs *sregs)
  87. {
  88. hregs->rx_ctrl = hregs->tx_ctrl = 0;
  89. hpc3_eth_reset(hregs);
  90. }
  91. #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
  92. SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
  93. static inline void seeq_go(struct sgiseeq_private *sp,
  94. struct hpc3_ethregs *hregs,
  95. struct sgiseeq_regs *sregs)
  96. {
  97. sregs->rstat = sp->mode | RSTAT_GO_BITS;
  98. hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE;
  99. }
  100. static inline void __sgiseeq_set_mac_address(struct net_device *dev)
  101. {
  102. struct sgiseeq_private *sp = netdev_priv(dev);
  103. struct sgiseeq_regs *sregs = sp->sregs;
  104. int i;
  105. sregs->tstat = SEEQ_TCMD_RB0;
  106. for (i = 0; i < 6; i++)
  107. sregs->rw.eth_addr[i] = dev->dev_addr[i];
  108. }
  109. static int sgiseeq_set_mac_address(struct net_device *dev, void *addr)
  110. {
  111. struct sgiseeq_private *sp = netdev_priv(dev);
  112. struct sockaddr *sa = addr;
  113. memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
  114. spin_lock_irq(&sp->tx_lock);
  115. __sgiseeq_set_mac_address(dev);
  116. spin_unlock_irq(&sp->tx_lock);
  117. return 0;
  118. }
  119. #define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD)
  120. #define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE)
  121. #define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT))
  122. static int seeq_init_ring(struct net_device *dev)
  123. {
  124. struct sgiseeq_private *sp = netdev_priv(dev);
  125. int i;
  126. netif_stop_queue(dev);
  127. sp->rx_new = sp->tx_new = 0;
  128. sp->rx_old = sp->tx_old = 0;
  129. __sgiseeq_set_mac_address(dev);
  130. /* Setup tx ring. */
  131. for(i = 0; i < SEEQ_TX_BUFFERS; i++) {
  132. if (!sp->tx_desc[i].tdma.pbuf) {
  133. unsigned long buffer;
  134. buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
  135. if (!buffer)
  136. return -ENOMEM;
  137. sp->tx_desc[i].buf_vaddr = CKSEG1ADDR(buffer);
  138. sp->tx_desc[i].tdma.pbuf = CPHYSADDR(buffer);
  139. }
  140. sp->tx_desc[i].tdma.cntinfo = TCNTINFO_INIT;
  141. }
  142. /* And now the rx ring. */
  143. for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
  144. if (!sp->rx_desc[i].rdma.pbuf) {
  145. unsigned long buffer;
  146. buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
  147. if (!buffer)
  148. return -ENOMEM;
  149. sp->rx_desc[i].buf_vaddr = CKSEG1ADDR(buffer);
  150. sp->rx_desc[i].rdma.pbuf = CPHYSADDR(buffer);
  151. }
  152. sp->rx_desc[i].rdma.cntinfo = RCNTINFO_INIT;
  153. }
  154. sp->rx_desc[i - 1].rdma.cntinfo |= HPCDMA_EOR;
  155. return 0;
  156. }
  157. #ifdef DEBUG
  158. static struct sgiseeq_private *gpriv;
  159. static struct net_device *gdev;
  160. static void sgiseeq_dump_rings(void)
  161. {
  162. static int once;
  163. struct sgiseeq_rx_desc *r = gpriv->rx_desc;
  164. struct sgiseeq_tx_desc *t = gpriv->tx_desc;
  165. struct hpc3_ethregs *hregs = gpriv->hregs;
  166. int i;
  167. if (once)
  168. return;
  169. once++;
  170. printk("RING DUMP:\n");
  171. for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
  172. printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
  173. i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
  174. r[i].rdma.pnext);
  175. i += 1;
  176. printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
  177. i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
  178. r[i].rdma.pnext);
  179. }
  180. for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
  181. printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
  182. i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
  183. t[i].tdma.pnext);
  184. i += 1;
  185. printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
  186. i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
  187. t[i].tdma.pnext);
  188. }
  189. printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
  190. gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old);
  191. printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
  192. hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl);
  193. printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
  194. hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl);
  195. }
  196. #endif
  197. #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
  198. #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
  199. static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
  200. struct sgiseeq_regs *sregs)
  201. {
  202. struct hpc3_ethregs *hregs = sp->hregs;
  203. int err;
  204. reset_hpc3_and_seeq(hregs, sregs);
  205. err = seeq_init_ring(dev);
  206. if (err)
  207. return err;
  208. /* Setup to field the proper interrupt types. */
  209. if (sp->is_edlc) {
  210. sregs->tstat = TSTAT_INIT_EDLC;
  211. sregs->rw.wregs.control = sp->control;
  212. sregs->rw.wregs.frame_gap = 0;
  213. } else {
  214. sregs->tstat = TSTAT_INIT_SEEQ;
  215. }
  216. hregs->rx_ndptr = CPHYSADDR(sp->rx_desc);
  217. hregs->tx_ndptr = CPHYSADDR(sp->tx_desc);
  218. seeq_go(sp, hregs, sregs);
  219. return 0;
  220. }
  221. static void record_rx_errors(struct net_device *dev, unsigned char status)
  222. {
  223. if (status & SEEQ_RSTAT_OVERF ||
  224. status & SEEQ_RSTAT_SFRAME)
  225. dev->stats.rx_over_errors++;
  226. if (status & SEEQ_RSTAT_CERROR)
  227. dev->stats.rx_crc_errors++;
  228. if (status & SEEQ_RSTAT_DERROR)
  229. dev->stats.rx_frame_errors++;
  230. if (status & SEEQ_RSTAT_REOF)
  231. dev->stats.rx_errors++;
  232. }
  233. static inline void rx_maybe_restart(struct sgiseeq_private *sp,
  234. struct hpc3_ethregs *hregs,
  235. struct sgiseeq_regs *sregs)
  236. {
  237. if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) {
  238. hregs->rx_ndptr = CPHYSADDR(sp->rx_desc + sp->rx_new);
  239. seeq_go(sp, hregs, sregs);
  240. }
  241. }
  242. #define for_each_rx(rd, sp) for((rd) = &(sp)->rx_desc[(sp)->rx_new]; \
  243. !((rd)->rdma.cntinfo & HPCDMA_OWN); \
  244. (rd) = &(sp)->rx_desc[(sp)->rx_new])
  245. static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp,
  246. struct hpc3_ethregs *hregs,
  247. struct sgiseeq_regs *sregs)
  248. {
  249. struct sgiseeq_rx_desc *rd;
  250. struct sk_buff *skb = NULL;
  251. unsigned char pkt_status;
  252. unsigned char *pkt_pointer = NULL;
  253. int len = 0;
  254. unsigned int orig_end = PREV_RX(sp->rx_new);
  255. /* Service every received packet. */
  256. for_each_rx(rd, sp) {
  257. len = PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3;
  258. pkt_pointer = (unsigned char *)(long)rd->buf_vaddr;
  259. pkt_status = pkt_pointer[len + 2];
  260. if (pkt_status & SEEQ_RSTAT_FIG) {
  261. /* Packet is OK. */
  262. skb = dev_alloc_skb(len + 2);
  263. if (skb) {
  264. skb_reserve(skb, 2);
  265. skb_put(skb, len);
  266. /* Copy out of kseg1 to avoid silly cache flush. */
  267. skb_copy_to_linear_data(skb, pkt_pointer + 2, len);
  268. skb->protocol = eth_type_trans(skb, dev);
  269. /* We don't want to receive our own packets */
  270. if (memcmp(eth_hdr(skb)->h_source, dev->dev_addr, ETH_ALEN)) {
  271. netif_rx(skb);
  272. dev->last_rx = jiffies;
  273. dev->stats.rx_packets++;
  274. dev->stats.rx_bytes += len;
  275. } else {
  276. /* Silently drop my own packets */
  277. dev_kfree_skb_irq(skb);
  278. }
  279. } else {
  280. printk (KERN_NOTICE "%s: Memory squeeze, deferring packet.\n",
  281. dev->name);
  282. dev->stats.rx_dropped++;
  283. }
  284. } else {
  285. record_rx_errors(dev, pkt_status);
  286. }
  287. /* Return the entry to the ring pool. */
  288. rd->rdma.cntinfo = RCNTINFO_INIT;
  289. sp->rx_new = NEXT_RX(sp->rx_new);
  290. }
  291. sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
  292. sp->rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
  293. rx_maybe_restart(sp, hregs, sregs);
  294. }
  295. static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
  296. struct sgiseeq_regs *sregs)
  297. {
  298. if (sp->is_edlc) {
  299. sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
  300. sregs->rw.wregs.control = sp->control;
  301. }
  302. }
  303. static inline void kick_tx(struct sgiseeq_tx_desc *td,
  304. struct hpc3_ethregs *hregs)
  305. {
  306. /* If the HPC aint doin nothin, and there are more packets
  307. * with ETXD cleared and XIU set we must make very certain
  308. * that we restart the HPC else we risk locking up the
  309. * adapter. The following code is only safe iff the HPCDMA
  310. * is not active!
  311. */
  312. while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
  313. (HPCDMA_XIU | HPCDMA_ETXD))
  314. td = (struct sgiseeq_tx_desc *)(long) CKSEG1ADDR(td->tdma.pnext);
  315. if (td->tdma.cntinfo & HPCDMA_XIU) {
  316. hregs->tx_ndptr = CPHYSADDR(td);
  317. hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
  318. }
  319. }
  320. static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
  321. struct hpc3_ethregs *hregs,
  322. struct sgiseeq_regs *sregs)
  323. {
  324. struct sgiseeq_tx_desc *td;
  325. unsigned long status = hregs->tx_ctrl;
  326. int j;
  327. tx_maybe_reset_collisions(sp, sregs);
  328. if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
  329. /* Oops, HPC detected some sort of error. */
  330. if (status & SEEQ_TSTAT_R16)
  331. dev->stats.tx_aborted_errors++;
  332. if (status & SEEQ_TSTAT_UFLOW)
  333. dev->stats.tx_fifo_errors++;
  334. if (status & SEEQ_TSTAT_LCLS)
  335. dev->stats.collisions++;
  336. }
  337. /* Ack 'em... */
  338. for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
  339. td = &sp->tx_desc[j];
  340. if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
  341. break;
  342. if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
  343. if (!(status & HPC3_ETXCTRL_ACTIVE)) {
  344. hregs->tx_ndptr = CPHYSADDR(td);
  345. hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
  346. }
  347. break;
  348. }
  349. dev->stats.tx_packets++;
  350. sp->tx_old = NEXT_TX(sp->tx_old);
  351. td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
  352. td->tdma.cntinfo |= HPCDMA_EOX;
  353. }
  354. }
  355. static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id)
  356. {
  357. struct net_device *dev = (struct net_device *) dev_id;
  358. struct sgiseeq_private *sp = netdev_priv(dev);
  359. struct hpc3_ethregs *hregs = sp->hregs;
  360. struct sgiseeq_regs *sregs = sp->sregs;
  361. spin_lock(&sp->tx_lock);
  362. /* Ack the IRQ and set software state. */
  363. hregs->reset = HPC3_ERST_CLRIRQ;
  364. /* Always check for received packets. */
  365. sgiseeq_rx(dev, sp, hregs, sregs);
  366. /* Only check for tx acks if we have something queued. */
  367. if (sp->tx_old != sp->tx_new)
  368. sgiseeq_tx(dev, sp, hregs, sregs);
  369. if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
  370. netif_wake_queue(dev);
  371. }
  372. spin_unlock(&sp->tx_lock);
  373. return IRQ_HANDLED;
  374. }
  375. static int sgiseeq_open(struct net_device *dev)
  376. {
  377. struct sgiseeq_private *sp = netdev_priv(dev);
  378. struct sgiseeq_regs *sregs = sp->sregs;
  379. unsigned int irq = dev->irq;
  380. int err;
  381. if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
  382. printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
  383. err = -EAGAIN;
  384. }
  385. err = init_seeq(dev, sp, sregs);
  386. if (err)
  387. goto out_free_irq;
  388. netif_start_queue(dev);
  389. return 0;
  390. out_free_irq:
  391. free_irq(irq, dev);
  392. return err;
  393. }
  394. static int sgiseeq_close(struct net_device *dev)
  395. {
  396. struct sgiseeq_private *sp = netdev_priv(dev);
  397. struct sgiseeq_regs *sregs = sp->sregs;
  398. unsigned int irq = dev->irq;
  399. netif_stop_queue(dev);
  400. /* Shutdown the Seeq. */
  401. reset_hpc3_and_seeq(sp->hregs, sregs);
  402. free_irq(irq, dev);
  403. return 0;
  404. }
  405. static inline int sgiseeq_reset(struct net_device *dev)
  406. {
  407. struct sgiseeq_private *sp = netdev_priv(dev);
  408. struct sgiseeq_regs *sregs = sp->sregs;
  409. int err;
  410. err = init_seeq(dev, sp, sregs);
  411. if (err)
  412. return err;
  413. dev->trans_start = jiffies;
  414. netif_wake_queue(dev);
  415. return 0;
  416. }
  417. static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
  418. {
  419. struct sgiseeq_private *sp = netdev_priv(dev);
  420. struct hpc3_ethregs *hregs = sp->hregs;
  421. unsigned long flags;
  422. struct sgiseeq_tx_desc *td;
  423. int skblen, len, entry;
  424. spin_lock_irqsave(&sp->tx_lock, flags);
  425. /* Setup... */
  426. skblen = skb->len;
  427. len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
  428. dev->stats.tx_bytes += len;
  429. entry = sp->tx_new;
  430. td = &sp->tx_desc[entry];
  431. /* Create entry. There are so many races with adding a new
  432. * descriptor to the chain:
  433. * 1) Assume that the HPC is off processing a DMA chain while
  434. * we are changing all of the following.
  435. * 2) Do no allow the HPC to look at a new descriptor until
  436. * we have completely set up it's state. This means, do
  437. * not clear HPCDMA_EOX in the current last descritptor
  438. * until the one we are adding looks consistent and could
  439. * be processes right now.
  440. * 3) The tx interrupt code must notice when we've added a new
  441. * entry and the HPC got to the end of the chain before we
  442. * added this new entry and restarted it.
  443. */
  444. skb_copy_from_linear_data(skb, (char *)(long)td->buf_vaddr, skblen);
  445. if (len != skblen)
  446. memset((char *)(long)td->buf_vaddr + skb->len, 0, len-skblen);
  447. td->tdma.cntinfo = (len & HPCDMA_BCNT) |
  448. HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX;
  449. if (sp->tx_old != sp->tx_new) {
  450. struct sgiseeq_tx_desc *backend;
  451. backend = &sp->tx_desc[PREV_TX(sp->tx_new)];
  452. backend->tdma.cntinfo &= ~HPCDMA_EOX;
  453. }
  454. sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
  455. /* Maybe kick the HPC back into motion. */
  456. if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
  457. kick_tx(&sp->tx_desc[sp->tx_old], hregs);
  458. dev->trans_start = jiffies;
  459. dev_kfree_skb(skb);
  460. if (!TX_BUFFS_AVAIL(sp))
  461. netif_stop_queue(dev);
  462. spin_unlock_irqrestore(&sp->tx_lock, flags);
  463. return 0;
  464. }
  465. static void timeout(struct net_device *dev)
  466. {
  467. printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
  468. sgiseeq_reset(dev);
  469. dev->trans_start = jiffies;
  470. netif_wake_queue(dev);
  471. }
  472. static void sgiseeq_set_multicast(struct net_device *dev)
  473. {
  474. struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
  475. unsigned char oldmode = sp->mode;
  476. if(dev->flags & IFF_PROMISC)
  477. sp->mode = SEEQ_RCMD_RANY;
  478. else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count)
  479. sp->mode = SEEQ_RCMD_RBMCAST;
  480. else
  481. sp->mode = SEEQ_RCMD_RBCAST;
  482. /* XXX I know this sucks, but is there a better way to reprogram
  483. * XXX the receiver? At least, this shouldn't happen too often.
  484. */
  485. if (oldmode != sp->mode)
  486. sgiseeq_reset(dev);
  487. }
  488. static inline void setup_tx_ring(struct sgiseeq_tx_desc *buf, int nbufs)
  489. {
  490. int i = 0;
  491. while (i < (nbufs - 1)) {
  492. buf[i].tdma.pnext = CPHYSADDR(buf + i + 1);
  493. buf[i].tdma.pbuf = 0;
  494. i++;
  495. }
  496. buf[i].tdma.pnext = CPHYSADDR(buf);
  497. }
  498. static inline void setup_rx_ring(struct sgiseeq_rx_desc *buf, int nbufs)
  499. {
  500. int i = 0;
  501. while (i < (nbufs - 1)) {
  502. buf[i].rdma.pnext = CPHYSADDR(buf + i + 1);
  503. buf[i].rdma.pbuf = 0;
  504. i++;
  505. }
  506. buf[i].rdma.pbuf = 0;
  507. buf[i].rdma.pnext = CPHYSADDR(buf);
  508. }
  509. #define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
  510. static int __init sgiseeq_probe(struct platform_device *pdev)
  511. {
  512. struct sgiseeq_platform_data *pd = pdev->dev.platform_data;
  513. struct hpc3_regs *hpcregs = pd->hpc;
  514. struct sgiseeq_init_block *sr;
  515. unsigned int irq = pd->irq;
  516. struct sgiseeq_private *sp;
  517. struct net_device *dev;
  518. int err, i;
  519. DECLARE_MAC_BUF(mac);
  520. dev = alloc_etherdev(sizeof (struct sgiseeq_private));
  521. if (!dev) {
  522. printk(KERN_ERR "Sgiseeq: Etherdev alloc failed, aborting.\n");
  523. err = -ENOMEM;
  524. goto err_out;
  525. }
  526. platform_set_drvdata(pdev, dev);
  527. sp = netdev_priv(dev);
  528. /* Make private data page aligned */
  529. sr = dma_alloc_coherent(&pdev->dev, sizeof(*sp->srings),
  530. &sp->srings_dma, GFP_KERNEL);
  531. if (!sr) {
  532. printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n");
  533. err = -ENOMEM;
  534. goto err_out_free_dev;
  535. }
  536. sp->srings = sr;
  537. sp->rx_desc = sp->srings->rxvector;
  538. sp->tx_desc = sp->srings->txvector;
  539. /* A couple calculations now, saves many cycles later. */
  540. setup_rx_ring(sp->rx_desc, SEEQ_RX_BUFFERS);
  541. setup_tx_ring(sp->tx_desc, SEEQ_TX_BUFFERS);
  542. memcpy(dev->dev_addr, pd->mac, ETH_ALEN);
  543. #ifdef DEBUG
  544. gpriv = sp;
  545. gdev = dev;
  546. #endif
  547. sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0];
  548. sp->hregs = &hpcregs->ethregs;
  549. sp->name = sgiseeqstr;
  550. sp->mode = SEEQ_RCMD_RBCAST;
  551. /* Setup PIO and DMA transfer timing */
  552. sp->hregs->pconfig = 0x161;
  553. sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
  554. HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
  555. /* Setup PIO and DMA transfer timing */
  556. sp->hregs->pconfig = 0x161;
  557. sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
  558. HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
  559. /* Reset the chip. */
  560. hpc3_eth_reset(sp->hregs);
  561. sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
  562. if (sp->is_edlc)
  563. sp->control = SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
  564. SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
  565. SEEQ_CTRL_ENCARR;
  566. dev->open = sgiseeq_open;
  567. dev->stop = sgiseeq_close;
  568. dev->hard_start_xmit = sgiseeq_start_xmit;
  569. dev->tx_timeout = timeout;
  570. dev->watchdog_timeo = (200 * HZ) / 1000;
  571. dev->set_multicast_list = sgiseeq_set_multicast;
  572. dev->set_mac_address = sgiseeq_set_mac_address;
  573. dev->irq = irq;
  574. if (register_netdev(dev)) {
  575. printk(KERN_ERR "Sgiseeq: Cannot register net device, "
  576. "aborting.\n");
  577. err = -ENODEV;
  578. goto err_out_free_page;
  579. }
  580. printk(KERN_INFO "%s: %s %s\n",
  581. dev->name, sgiseeqstr, print_mac(mac, dev->dev_addr));
  582. return 0;
  583. err_out_free_page:
  584. free_page((unsigned long) sp->srings);
  585. err_out_free_dev:
  586. kfree(dev);
  587. err_out:
  588. return err;
  589. }
  590. static int __exit sgiseeq_remove(struct platform_device *pdev)
  591. {
  592. struct net_device *dev = platform_get_drvdata(pdev);
  593. struct sgiseeq_private *sp = netdev_priv(dev);
  594. unregister_netdev(dev);
  595. dma_free_coherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
  596. sp->srings_dma);
  597. free_netdev(dev);
  598. platform_set_drvdata(pdev, NULL);
  599. return 0;
  600. }
  601. static struct platform_driver sgiseeq_driver = {
  602. .probe = sgiseeq_probe,
  603. .remove = __devexit_p(sgiseeq_remove),
  604. .driver = {
  605. .name = "sgiseeq"
  606. }
  607. };
  608. static int __init sgiseeq_module_init(void)
  609. {
  610. if (platform_driver_register(&sgiseeq_driver)) {
  611. printk(KERN_ERR "Driver registration failed\n");
  612. return -ENODEV;
  613. }
  614. return 0;
  615. }
  616. static void __exit sgiseeq_module_exit(void)
  617. {
  618. platform_driver_unregister(&sgiseeq_driver);
  619. }
  620. module_init(sgiseeq_module_init);
  621. module_exit(sgiseeq_module_exit);
  622. MODULE_DESCRIPTION("SGI Seeq 8003 driver");
  623. MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
  624. MODULE_LICENSE("GPL");