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