sgiseeq.c 20 KB

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