sgiseeq.c 20 KB

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