sgiseeq.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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->dev = dev;
  267. skb_reserve(skb, 2);
  268. skb_put(skb, len);
  269. /* Copy out of kseg1 to avoid silly cache flush. */
  270. eth_copy_and_sum(skb, pkt_pointer + 2, len, 0);
  271. skb->protocol = eth_type_trans(skb, dev);
  272. /* We don't want to receive our own packets */
  273. if (memcmp(eth_hdr(skb)->h_source, dev->dev_addr, ETH_ALEN)) {
  274. netif_rx(skb);
  275. dev->last_rx = jiffies;
  276. sp->stats.rx_packets++;
  277. sp->stats.rx_bytes += len;
  278. } else {
  279. /* Silently drop my own packets */
  280. dev_kfree_skb_irq(skb);
  281. }
  282. } else {
  283. printk (KERN_NOTICE "%s: Memory squeeze, deferring packet.\n",
  284. dev->name);
  285. sp->stats.rx_dropped++;
  286. }
  287. } else {
  288. record_rx_errors(sp, pkt_status);
  289. }
  290. /* Return the entry to the ring pool. */
  291. rd->rdma.cntinfo = RCNTINFO_INIT;
  292. sp->rx_new = NEXT_RX(sp->rx_new);
  293. }
  294. sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
  295. sp->rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
  296. rx_maybe_restart(sp, hregs, sregs);
  297. }
  298. static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
  299. struct sgiseeq_regs *sregs)
  300. {
  301. if (sp->is_edlc) {
  302. sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
  303. sregs->rw.wregs.control = sp->control;
  304. }
  305. }
  306. static inline void kick_tx(struct sgiseeq_tx_desc *td,
  307. struct hpc3_ethregs *hregs)
  308. {
  309. /* If the HPC aint doin nothin, and there are more packets
  310. * with ETXD cleared and XIU set we must make very certain
  311. * that we restart the HPC else we risk locking up the
  312. * adapter. The following code is only safe iff the HPCDMA
  313. * is not active!
  314. */
  315. while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
  316. (HPCDMA_XIU | HPCDMA_ETXD))
  317. td = (struct sgiseeq_tx_desc *)(long) CKSEG1ADDR(td->tdma.pnext);
  318. if (td->tdma.cntinfo & HPCDMA_XIU) {
  319. hregs->tx_ndptr = CPHYSADDR(td);
  320. hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
  321. }
  322. }
  323. static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
  324. struct hpc3_ethregs *hregs,
  325. struct sgiseeq_regs *sregs)
  326. {
  327. struct sgiseeq_tx_desc *td;
  328. unsigned long status = hregs->tx_ctrl;
  329. int j;
  330. tx_maybe_reset_collisions(sp, sregs);
  331. if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
  332. /* Oops, HPC detected some sort of error. */
  333. if (status & SEEQ_TSTAT_R16)
  334. sp->stats.tx_aborted_errors++;
  335. if (status & SEEQ_TSTAT_UFLOW)
  336. sp->stats.tx_fifo_errors++;
  337. if (status & SEEQ_TSTAT_LCLS)
  338. sp->stats.collisions++;
  339. }
  340. /* Ack 'em... */
  341. for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
  342. td = &sp->tx_desc[j];
  343. if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
  344. break;
  345. if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
  346. if (!(status & HPC3_ETXCTRL_ACTIVE)) {
  347. hregs->tx_ndptr = CPHYSADDR(td);
  348. hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
  349. }
  350. break;
  351. }
  352. sp->stats.tx_packets++;
  353. sp->tx_old = NEXT_TX(sp->tx_old);
  354. td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
  355. td->tdma.cntinfo |= HPCDMA_EOX;
  356. }
  357. }
  358. static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id)
  359. {
  360. struct net_device *dev = (struct net_device *) dev_id;
  361. struct sgiseeq_private *sp = netdev_priv(dev);
  362. struct hpc3_ethregs *hregs = sp->hregs;
  363. struct sgiseeq_regs *sregs = sp->sregs;
  364. spin_lock(&sp->tx_lock);
  365. /* Ack the IRQ and set software state. */
  366. hregs->reset = HPC3_ERST_CLRIRQ;
  367. /* Always check for received packets. */
  368. sgiseeq_rx(dev, sp, hregs, sregs);
  369. /* Only check for tx acks if we have something queued. */
  370. if (sp->tx_old != sp->tx_new)
  371. sgiseeq_tx(dev, sp, hregs, sregs);
  372. if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
  373. netif_wake_queue(dev);
  374. }
  375. spin_unlock(&sp->tx_lock);
  376. return IRQ_HANDLED;
  377. }
  378. static int sgiseeq_open(struct net_device *dev)
  379. {
  380. struct sgiseeq_private *sp = netdev_priv(dev);
  381. struct sgiseeq_regs *sregs = sp->sregs;
  382. unsigned int irq = dev->irq;
  383. int err;
  384. if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
  385. printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
  386. err = -EAGAIN;
  387. }
  388. err = init_seeq(dev, sp, sregs);
  389. if (err)
  390. goto out_free_irq;
  391. netif_start_queue(dev);
  392. return 0;
  393. out_free_irq:
  394. free_irq(irq, dev);
  395. return err;
  396. }
  397. static int sgiseeq_close(struct net_device *dev)
  398. {
  399. struct sgiseeq_private *sp = netdev_priv(dev);
  400. struct sgiseeq_regs *sregs = sp->sregs;
  401. unsigned int irq = dev->irq;
  402. netif_stop_queue(dev);
  403. /* Shutdown the Seeq. */
  404. reset_hpc3_and_seeq(sp->hregs, sregs);
  405. free_irq(irq, dev);
  406. return 0;
  407. }
  408. static inline int sgiseeq_reset(struct net_device *dev)
  409. {
  410. struct sgiseeq_private *sp = netdev_priv(dev);
  411. struct sgiseeq_regs *sregs = sp->sregs;
  412. int err;
  413. err = init_seeq(dev, sp, sregs);
  414. if (err)
  415. return err;
  416. dev->trans_start = jiffies;
  417. netif_wake_queue(dev);
  418. return 0;
  419. }
  420. static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
  421. {
  422. struct sgiseeq_private *sp = netdev_priv(dev);
  423. struct hpc3_ethregs *hregs = sp->hregs;
  424. unsigned long flags;
  425. struct sgiseeq_tx_desc *td;
  426. int skblen, len, entry;
  427. spin_lock_irqsave(&sp->tx_lock, flags);
  428. /* Setup... */
  429. skblen = skb->len;
  430. len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
  431. sp->stats.tx_bytes += len;
  432. entry = sp->tx_new;
  433. td = &sp->tx_desc[entry];
  434. /* Create entry. There are so many races with adding a new
  435. * descriptor to the chain:
  436. * 1) Assume that the HPC is off processing a DMA chain while
  437. * we are changing all of the following.
  438. * 2) Do no allow the HPC to look at a new descriptor until
  439. * we have completely set up it's state. This means, do
  440. * not clear HPCDMA_EOX in the current last descritptor
  441. * until the one we are adding looks consistent and could
  442. * be processes right now.
  443. * 3) The tx interrupt code must notice when we've added a new
  444. * entry and the HPC got to the end of the chain before we
  445. * added this new entry and restarted it.
  446. */
  447. memcpy((char *)(long)td->buf_vaddr, skb->data, skblen);
  448. if (len != skblen)
  449. memset((char *)(long)td->buf_vaddr + skb->len, 0, len-skblen);
  450. td->tdma.cntinfo = (len & HPCDMA_BCNT) |
  451. HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX;
  452. if (sp->tx_old != sp->tx_new) {
  453. struct sgiseeq_tx_desc *backend;
  454. backend = &sp->tx_desc[PREV_TX(sp->tx_new)];
  455. backend->tdma.cntinfo &= ~HPCDMA_EOX;
  456. }
  457. sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
  458. /* Maybe kick the HPC back into motion. */
  459. if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
  460. kick_tx(&sp->tx_desc[sp->tx_old], hregs);
  461. dev->trans_start = jiffies;
  462. dev_kfree_skb(skb);
  463. if (!TX_BUFFS_AVAIL(sp))
  464. netif_stop_queue(dev);
  465. spin_unlock_irqrestore(&sp->tx_lock, flags);
  466. return 0;
  467. }
  468. static void timeout(struct net_device *dev)
  469. {
  470. printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
  471. sgiseeq_reset(dev);
  472. dev->trans_start = jiffies;
  473. netif_wake_queue(dev);
  474. }
  475. static struct net_device_stats *sgiseeq_get_stats(struct net_device *dev)
  476. {
  477. struct sgiseeq_private *sp = netdev_priv(dev);
  478. return &sp->stats;
  479. }
  480. static void sgiseeq_set_multicast(struct net_device *dev)
  481. {
  482. struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
  483. unsigned char oldmode = sp->mode;
  484. if(dev->flags & IFF_PROMISC)
  485. sp->mode = SEEQ_RCMD_RANY;
  486. else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count)
  487. sp->mode = SEEQ_RCMD_RBMCAST;
  488. else
  489. sp->mode = SEEQ_RCMD_RBCAST;
  490. /* XXX I know this sucks, but is there a better way to reprogram
  491. * XXX the receiver? At least, this shouldn't happen too often.
  492. */
  493. if (oldmode != sp->mode)
  494. sgiseeq_reset(dev);
  495. }
  496. static inline void setup_tx_ring(struct sgiseeq_tx_desc *buf, int nbufs)
  497. {
  498. int i = 0;
  499. while (i < (nbufs - 1)) {
  500. buf[i].tdma.pnext = CPHYSADDR(buf + i + 1);
  501. buf[i].tdma.pbuf = 0;
  502. i++;
  503. }
  504. buf[i].tdma.pnext = CPHYSADDR(buf);
  505. }
  506. static inline void setup_rx_ring(struct sgiseeq_rx_desc *buf, int nbufs)
  507. {
  508. int i = 0;
  509. while (i < (nbufs - 1)) {
  510. buf[i].rdma.pnext = CPHYSADDR(buf + i + 1);
  511. buf[i].rdma.pbuf = 0;
  512. i++;
  513. }
  514. buf[i].rdma.pbuf = 0;
  515. buf[i].rdma.pnext = CPHYSADDR(buf);
  516. }
  517. #define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
  518. static int sgiseeq_init(struct hpc3_regs* hpcregs, int irq)
  519. {
  520. struct sgiseeq_init_block *sr;
  521. struct sgiseeq_private *sp;
  522. struct net_device *dev;
  523. int err, i;
  524. dev = alloc_etherdev(sizeof (struct sgiseeq_private));
  525. if (!dev) {
  526. printk(KERN_ERR "Sgiseeq: Etherdev alloc failed, aborting.\n");
  527. err = -ENOMEM;
  528. goto err_out;
  529. }
  530. sp = netdev_priv(dev);
  531. /* Make private data page aligned */
  532. sr = (struct sgiseeq_init_block *) get_zeroed_page(GFP_KERNEL);
  533. if (!sr) {
  534. printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n");
  535. err = -ENOMEM;
  536. goto err_out_free_dev;
  537. }
  538. sp->srings = sr;
  539. #define EADDR_NVOFS 250
  540. for (i = 0; i < 3; i++) {
  541. unsigned short tmp = ip22_nvram_read(EADDR_NVOFS / 2 + i);
  542. dev->dev_addr[2 * i] = tmp >> 8;
  543. dev->dev_addr[2 * i + 1] = tmp & 0xff;
  544. }
  545. #ifdef DEBUG
  546. gpriv = sp;
  547. gdev = dev;
  548. #endif
  549. sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0];
  550. sp->hregs = &hpcregs->ethregs;
  551. sp->name = sgiseeqstr;
  552. sp->mode = SEEQ_RCMD_RBCAST;
  553. sp->rx_desc = (struct sgiseeq_rx_desc *)
  554. CKSEG1ADDR(ALIGNED(&sp->srings->rxvector[0]));
  555. dma_cache_wback_inv((unsigned long)&sp->srings->rxvector,
  556. sizeof(sp->srings->rxvector));
  557. sp->tx_desc = (struct sgiseeq_tx_desc *)
  558. CKSEG1ADDR(ALIGNED(&sp->srings->txvector[0]));
  559. dma_cache_wback_inv((unsigned long)&sp->srings->txvector,
  560. sizeof(sp->srings->txvector));
  561. /* A couple calculations now, saves many cycles later. */
  562. setup_rx_ring(sp->rx_desc, SEEQ_RX_BUFFERS);
  563. setup_tx_ring(sp->tx_desc, SEEQ_TX_BUFFERS);
  564. /* Setup PIO and DMA transfer timing */
  565. sp->hregs->pconfig = 0x161;
  566. sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
  567. HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
  568. /* Reset the chip. */
  569. hpc3_eth_reset(sp->hregs);
  570. sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
  571. if (sp->is_edlc)
  572. sp->control = SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
  573. SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
  574. SEEQ_CTRL_ENCARR;
  575. dev->open = sgiseeq_open;
  576. dev->stop = sgiseeq_close;
  577. dev->hard_start_xmit = sgiseeq_start_xmit;
  578. dev->tx_timeout = timeout;
  579. dev->watchdog_timeo = (200 * HZ) / 1000;
  580. dev->get_stats = sgiseeq_get_stats;
  581. dev->set_multicast_list = sgiseeq_set_multicast;
  582. dev->set_mac_address = sgiseeq_set_mac_address;
  583. dev->irq = irq;
  584. if (register_netdev(dev)) {
  585. printk(KERN_ERR "Sgiseeq: Cannot register net device, "
  586. "aborting.\n");
  587. err = -ENODEV;
  588. goto err_out_free_page;
  589. }
  590. printk(KERN_INFO "%s: %s ", dev->name, sgiseeqstr);
  591. for (i = 0; i < 6; i++)
  592. printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':');
  593. sp->next_module = root_sgiseeq_dev;
  594. root_sgiseeq_dev = dev;
  595. return 0;
  596. err_out_free_page:
  597. free_page((unsigned long) sp->srings);
  598. err_out_free_dev:
  599. kfree(dev);
  600. err_out:
  601. return err;
  602. }
  603. static int __init sgiseeq_probe(void)
  604. {
  605. /* On board adapter on 1st HPC is always present */
  606. return sgiseeq_init(hpc3c0, SGI_ENET_IRQ);
  607. }
  608. static void __exit sgiseeq_exit(void)
  609. {
  610. struct net_device *next, *dev;
  611. struct sgiseeq_private *sp;
  612. for (dev = root_sgiseeq_dev; dev; dev = next) {
  613. sp = (struct sgiseeq_private *) netdev_priv(dev);
  614. next = sp->next_module;
  615. unregister_netdev(dev);
  616. free_page((unsigned long) sp->srings);
  617. free_netdev(dev);
  618. }
  619. }
  620. module_init(sgiseeq_probe);
  621. module_exit(sgiseeq_exit);
  622. MODULE_DESCRIPTION("SGI Seeq 8003 driver");
  623. MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
  624. MODULE_LICENSE("GPL");