More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / sgiseeq.c
blob216b9b6a319d743db2fd655d5e08dc3549bef40d
1 /*
2 * sgiseeq.c: Seeq8003 ethernet driver for SGI machines.
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/errno.h>
9 #include <linux/init.h>
10 #include <linux/types.h>
11 #include <linux/interrupt.h>
12 #include <linux/ioport.h>
13 #include <linux/socket.h>
14 #include <linux/in.h>
15 #include <linux/route.h>
16 #include <linux/slab.h>
17 #include <linux/string.h>
18 #include <linux/delay.h>
19 #include <linux/netdevice.h>
20 #include <linux/etherdevice.h>
21 #include <linux/skbuff.h>
23 #include <asm/byteorder.h>
24 #include <asm/io.h>
25 #include <asm/system.h>
26 #include <asm/bitops.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>
33 #include "sgiseeq.h"
35 static char *version = "sgiseeq.c: David S. Miller (dm@engr.sgi.com)\n";
37 static char *sgiseeqstr = "SGI Seeq8003";
40 * If you want speed, you do something silly, it always has worked for me. So,
41 * with that in mind, I've decided to make this driver look completely like a
42 * stupid Lance from a driver architecture perspective. Only difference is that
43 * here our "ring buffer" looks and acts like a real Lance one does but is
44 * layed out like how the HPC DMA and the Seeq want it to. You'd be surprised
45 * how a stupid idea like this can pay off in performance, not to mention
46 * making this driver 2,000 times easier to write. ;-)
49 /* Tune these if we tend to run out often etc. */
50 #define SEEQ_RX_BUFFERS 16
51 #define SEEQ_TX_BUFFERS 16
53 #define PKT_BUF_SZ 1584
55 #define NEXT_RX(i) (((i) + 1) & (SEEQ_RX_BUFFERS - 1))
56 #define NEXT_TX(i) (((i) + 1) & (SEEQ_TX_BUFFERS - 1))
57 #define PREV_RX(i) (((i) - 1) & (SEEQ_RX_BUFFERS - 1))
58 #define PREV_TX(i) (((i) - 1) & (SEEQ_TX_BUFFERS - 1))
60 #define TX_BUFFS_AVAIL(sp) ((sp->tx_old <= sp->tx_new) ? \
61 sp->tx_old + (SEEQ_TX_BUFFERS - 1) - sp->tx_new : \
62 sp->tx_old - sp->tx_new - 1)
64 #define DEBUG
66 struct sgiseeq_rx_desc {
67 struct hpc_dma_desc rdma;
68 signed int buf_vaddr;
71 struct sgiseeq_tx_desc {
72 struct hpc_dma_desc tdma;
73 signed int buf_vaddr;
77 * Warning: This structure is layed out in a certain way because HPC dma
78 * descriptors must be 8-byte aligned. So don't touch this without
79 * some care.
81 struct sgiseeq_init_block { /* Note the name ;-) */
82 /* Ptrs to the descriptors in KSEG1 uncached space. */
83 struct sgiseeq_rx_desc *rx_desc;
84 struct sgiseeq_tx_desc *tx_desc;
85 unsigned int _padding[30]; /* Pad out to largest cache line size. */
87 struct sgiseeq_rx_desc rxvector[SEEQ_RX_BUFFERS];
88 struct sgiseeq_tx_desc txvector[SEEQ_TX_BUFFERS];
91 struct sgiseeq_private {
92 volatile struct sgiseeq_init_block srings;
93 char *name;
94 struct hpc3_ethregs *hregs;
95 struct sgiseeq_regs *sregs;
97 /* Ring entry counters. */
98 unsigned int rx_new, tx_new;
99 unsigned int rx_old, tx_old;
101 int is_edlc;
102 unsigned char control;
103 unsigned char mode;
105 struct net_device_stats stats;
107 struct net_device *next_module;
108 spinlock_t tx_lock;
111 /* A list of all installed seeq devices, for removing the driver module. */
112 static struct net_device *root_sgiseeq_dev;
114 static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
116 hregs->rx_reset = (HPC3_ERXRST_CRESET | HPC3_ERXRST_CLRIRQ);
117 udelay(20);
118 hregs->rx_reset = 0;
121 static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
122 struct sgiseeq_regs *sregs)
124 hregs->rx_ctrl = hregs->tx_ctrl = 0;
125 hpc3_eth_reset(hregs);
128 #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
129 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
131 static inline void seeq_go(struct sgiseeq_private *sp,
132 struct hpc3_ethregs *hregs,
133 struct sgiseeq_regs *sregs)
135 sregs->rstat = sp->mode | RSTAT_GO_BITS;
136 hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE;
139 static inline void seeq_load_eaddr(struct net_device *dev,
140 struct sgiseeq_regs *sregs)
142 int i;
144 sregs->tstat = SEEQ_TCMD_RB0;
145 for (i = 0; i < 6; i++)
146 sregs->rw.eth_addr[i] = dev->dev_addr[i];
149 #define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD)
150 #define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE)
151 #define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT))
153 static int seeq_init_ring(struct net_device *dev)
155 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
156 volatile struct sgiseeq_init_block *ib = &sp->srings;
157 int i;
159 netif_stop_queue(dev);
160 sp->rx_new = sp->tx_new = 0;
161 sp->rx_old = sp->tx_old = 0;
163 seeq_load_eaddr(dev, sp->sregs);
165 /* XXX for now just accept packets directly to us
166 * XXX and ether-broadcast. Will do multicast and
167 * XXX promiscuous mode later. -davem
169 sp->mode = SEEQ_RCMD_RBCAST;
171 /* Setup tx ring. */
172 for(i = 0; i < SEEQ_TX_BUFFERS; i++) {
173 if (!ib->tx_desc[i].tdma.pbuf) {
174 unsigned long buffer;
176 buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
177 if (!buffer)
178 return -ENOMEM;
179 ib->tx_desc[i].buf_vaddr = KSEG1ADDR(buffer);
180 ib->tx_desc[i].tdma.pbuf = PHYSADDR(buffer);
182 ib->tx_desc[i].tdma.cntinfo = (TCNTINFO_INIT);
185 /* And now the rx ring. */
186 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
187 if (!ib->rx_desc[i].rdma.pbuf) {
188 unsigned long buffer;
190 buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
191 if (!buffer)
192 return -ENOMEM;
193 ib->rx_desc[i].buf_vaddr = KSEG1ADDR(buffer);
194 ib->rx_desc[i].rdma.pbuf = PHYSADDR(buffer);
196 ib->rx_desc[i].rdma.cntinfo = (RCNTINFO_INIT);
198 ib->rx_desc[i - 1].rdma.cntinfo |= (HPCDMA_EOR);
199 return 0;
202 #ifdef DEBUG
203 static struct sgiseeq_private *gpriv;
204 static struct net_device *gdev;
206 void sgiseeq_dump_rings(void)
208 static int once;
209 struct sgiseeq_rx_desc *r = gpriv->srings.rx_desc;
210 struct sgiseeq_tx_desc *t = gpriv->srings.tx_desc;
211 struct hpc3_ethregs *hregs = gpriv->hregs;
212 int i;
214 if (once)
215 return;
216 once++;
217 printk("RING DUMP:\n");
218 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
219 printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
220 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
221 r[i].rdma.pnext);
222 i += 1;
223 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
224 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
225 r[i].rdma.pnext);
227 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
228 printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
229 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
230 t[i].tdma.pnext);
231 i += 1;
232 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
233 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
234 t[i].tdma.pnext);
236 printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
237 gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old);
238 printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
239 hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl);
240 printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
241 hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl);
243 #endif
245 #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
246 #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
247 #define RDMACFG_INIT (HPC3_ERXDCFG_FRXDC | HPC3_ERXDCFG_FEOP | HPC3_ERXDCFG_FIRQ)
249 static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
250 struct sgiseeq_regs *sregs)
252 struct hpc3_ethregs *hregs = sp->hregs;
253 int err;
255 reset_hpc3_and_seeq(hregs, sregs);
256 err = seeq_init_ring(dev);
257 if (err)
258 return err;
260 /* Setup to field the proper interrupt types. */
261 if (sp->is_edlc) {
262 sregs->tstat = (TSTAT_INIT_EDLC);
263 sregs->rw.wregs.control = sp->control;
264 sregs->rw.wregs.frame_gap = 0;
265 } else {
266 sregs->tstat = (TSTAT_INIT_SEEQ);
269 hregs->rx_dconfig |= RDMACFG_INIT;
271 hregs->rx_ndptr = PHYSADDR(&sp->srings.rx_desc[0]);
272 hregs->tx_ndptr = PHYSADDR(&sp->srings.tx_desc[0]);
274 seeq_go(sp, hregs, sregs);
275 return 0;
278 static inline void record_rx_errors(struct sgiseeq_private *sp,
279 unsigned char status)
281 if (status & SEEQ_RSTAT_OVERF ||
282 status & SEEQ_RSTAT_SFRAME)
283 sp->stats.rx_over_errors++;
284 if (status & SEEQ_RSTAT_CERROR)
285 sp->stats.rx_crc_errors++;
286 if (status & SEEQ_RSTAT_DERROR)
287 sp->stats.rx_frame_errors++;
288 if (status & SEEQ_RSTAT_REOF)
289 sp->stats.rx_errors++;
292 static inline void rx_maybe_restart(struct sgiseeq_private *sp,
293 struct hpc3_ethregs *hregs,
294 struct sgiseeq_regs *sregs)
296 if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) {
297 hregs->rx_ndptr = PHYSADDR(&sp->srings.rx_desc[sp->rx_new]);
298 seeq_go(sp, hregs, sregs);
302 #define for_each_rx(rd, sp) for((rd) = &(sp)->srings.rx_desc[(sp)->rx_new]; \
303 !((rd)->rdma.cntinfo & HPCDMA_OWN); \
304 (rd) = &(sp)->srings.rx_desc[(sp)->rx_new])
306 static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp,
307 struct hpc3_ethregs *hregs,
308 struct sgiseeq_regs *sregs)
310 struct sgiseeq_rx_desc *rd;
311 struct sk_buff *skb = 0;
312 unsigned char pkt_status;
313 unsigned char *pkt_pointer = 0;
314 int len = 0;
315 unsigned int orig_end = PREV_RX(sp->rx_new);
317 /* Service every received packet. */
318 for_each_rx(rd, sp) {
319 len = (PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3);
320 pkt_pointer = (unsigned char *)(long)rd->buf_vaddr;
321 pkt_status = pkt_pointer[len + 2];
323 if (pkt_status & SEEQ_RSTAT_FIG) {
324 /* Packet is OK. */
325 skb = dev_alloc_skb(len + 2);
327 if (skb) {
328 skb->dev = dev;
329 skb_reserve(skb, 2);
330 skb_put(skb, len);
332 /* Copy out of kseg1 to avoid silly cache flush. */
333 eth_copy_and_sum(skb, pkt_pointer + 2, len, 0);
334 skb->protocol = eth_type_trans(skb, dev);
335 netif_rx(skb);
336 dev->last_rx = jiffies;
337 sp->stats.rx_packets++;
338 sp->stats.rx_bytes += len;
339 } else {
340 printk (KERN_NOTICE "%s: Memory squeeze, deferring packet.\n",
341 dev->name);
342 sp->stats.rx_dropped++;
344 } else {
345 record_rx_errors(sp, pkt_status);
348 /* Return the entry to the ring pool. */
349 rd->rdma.cntinfo = (RCNTINFO_INIT);
350 sp->rx_new = NEXT_RX(sp->rx_new);
352 sp->srings.rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
353 sp->srings.rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
354 rx_maybe_restart(sp, hregs, sregs);
357 static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
358 struct sgiseeq_regs *sregs)
360 if (sp->is_edlc) {
361 sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
362 sregs->rw.wregs.control = sp->control;
366 static inline void kick_tx(struct sgiseeq_tx_desc *td,
367 struct hpc3_ethregs *hregs)
369 /* If the HPC aint doin nothin, and there are more packets
370 * with ETXD cleared and XIU set we must make very certain
371 * that we restart the HPC else we risk locking up the
372 * adapter. The following code is only safe iff the HPCDMA
373 * is not active!
375 while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
376 (HPCDMA_XIU | HPCDMA_ETXD))
377 td = (struct sgiseeq_tx_desc *)(long) KSEG1ADDR(td->tdma.pnext);
378 if (td->tdma.cntinfo & HPCDMA_XIU) {
379 hregs->tx_ndptr = PHYSADDR(td);
380 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
384 static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
385 struct hpc3_ethregs *hregs,
386 struct sgiseeq_regs *sregs)
388 struct sgiseeq_tx_desc *td;
389 unsigned long status = hregs->tx_ctrl;
390 int j;
392 tx_maybe_reset_collisions(sp, sregs);
394 if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
395 /* Oops, HPC detected some sort of error. */
396 if (status & SEEQ_TSTAT_R16)
397 sp->stats.tx_aborted_errors++;
398 if (status & SEEQ_TSTAT_UFLOW)
399 sp->stats.tx_fifo_errors++;
400 if (status & SEEQ_TSTAT_LCLS)
401 sp->stats.collisions++;
404 /* Ack 'em... */
405 for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
406 td = &sp->srings.tx_desc[j];
408 if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
409 break;
410 if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
411 if (!(status & HPC3_ETXCTRL_ACTIVE)) {
412 hregs->tx_ndptr = PHYSADDR(td);
413 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
415 break;
417 sp->stats.tx_packets++;
418 sp->tx_old = NEXT_TX(sp->tx_old);
419 td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
420 td->tdma.cntinfo |= HPCDMA_EOX;
424 static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id, struct pt_regs *regs)
426 struct net_device *dev = (struct net_device *) dev_id;
427 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
428 struct hpc3_ethregs *hregs = sp->hregs;
429 struct sgiseeq_regs *sregs = sp->sregs;
431 spin_lock(&sp->tx_lock);
433 /* Ack the IRQ and set software state. */
434 hregs->rx_reset = HPC3_ERXRST_CLRIRQ;
436 /* Always check for received packets. */
437 sgiseeq_rx(dev, sp, hregs, sregs);
439 /* Only check for tx acks if we have something queued. */
440 if (sp->tx_old != sp->tx_new)
441 sgiseeq_tx(dev, sp, hregs, sregs);
443 if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
444 netif_wake_queue(dev);
446 spin_unlock(&sp->tx_lock);
448 return IRQ_HANDLED;
451 static int sgiseeq_open(struct net_device *dev)
453 struct sgiseeq_private *sp = (struct sgiseeq_private *)dev->priv;
454 struct sgiseeq_regs *sregs = sp->sregs;
456 int err = init_seeq(dev, sp, sregs);
457 if (err)
458 return err;
460 netif_start_queue(dev);
462 return 0;
465 static int sgiseeq_close(struct net_device *dev)
467 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
468 struct sgiseeq_regs *sregs = sp->sregs;
470 netif_stop_queue(dev);
472 /* Shutdown the Seeq. */
473 reset_hpc3_and_seeq(sp->hregs, sregs);
475 return 0;
478 static inline int sgiseeq_reset(struct net_device *dev)
480 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
481 struct sgiseeq_regs *sregs = sp->sregs;
482 int err;
484 err = init_seeq(dev, sp, sregs);
485 if (err)
486 return err;
488 dev->trans_start = jiffies;
489 netif_wake_queue(dev);
491 return 0;
494 void sgiseeq_my_reset(void)
496 printk("RESET!\n");
497 sgiseeq_reset(gdev);
500 static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
502 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
503 struct hpc3_ethregs *hregs = sp->hregs;
504 unsigned long flags;
505 struct sgiseeq_tx_desc *td;
506 int skblen, len, entry;
508 spin_lock_irqsave(&sp->tx_lock, flags);
510 /* Setup... */
511 skblen = skb->len;
512 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
513 sp->stats.tx_bytes += len;
514 entry = sp->tx_new;
515 td = &sp->srings.tx_desc[entry];
517 /* Create entry. There are so many races with adding a new
518 * descriptor to the chain:
519 * 1) Assume that the HPC is off processing a DMA chain while
520 * we are changing all of the following.
521 * 2) Do no allow the HPC to look at a new descriptor until
522 * we have completely set up it's state. This means, do
523 * not clear HPCDMA_EOX in the current last descritptor
524 * until the one we are adding looks consistent and could
525 * be processes right now.
526 * 3) The tx interrupt code must notice when we've added a new
527 * entry and the HPC got to the end of the chain before we
528 * added this new entry and restarted it.
530 memcpy((char *)(long)td->buf_vaddr, skb->data, skblen);
531 if (len != skblen)
532 memset((char *)(long)td->buf_vaddr + skb->len, 0, len-skblen);
533 td->tdma.cntinfo = (len & HPCDMA_BCNT) |
534 (HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX);
535 if (sp->tx_old != sp->tx_new) {
536 struct sgiseeq_tx_desc *backend;
538 backend = &sp->srings.tx_desc[PREV_TX(sp->tx_new)];
539 backend->tdma.cntinfo &= ~(HPCDMA_EOX);
541 sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
543 /* Maybe kick the HPC back into motion. */
544 if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
545 kick_tx(&sp->srings.tx_desc[sp->tx_old], hregs);
547 dev->trans_start = jiffies;
548 dev_kfree_skb(skb);
550 if (!TX_BUFFS_AVAIL(sp))
551 netif_stop_queue(dev);
552 spin_unlock_irqrestore(&sp->tx_lock, flags);
554 return 0;
557 static void timeout(struct net_device *dev)
559 printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
560 sgiseeq_reset(dev);
562 dev->trans_start = jiffies;
563 netif_wake_queue(dev);
566 static struct net_device_stats *sgiseeq_get_stats(struct net_device *dev)
568 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
570 return &sp->stats;
573 static void sgiseeq_set_multicast(struct net_device *dev)
577 static inline void setup_tx_ring(struct sgiseeq_tx_desc *buf, int nbufs)
579 int i = 0;
581 while (i < (nbufs - 1)) {
582 buf[i].tdma.pnext = PHYSADDR(&buf[i + 1]);
583 buf[i].tdma.pbuf = 0;
584 i++;
586 buf[i].tdma.pnext = PHYSADDR(&buf[0]);
589 static inline void setup_rx_ring(struct sgiseeq_rx_desc *buf, int nbufs)
591 int i = 0;
593 while (i < (nbufs - 1)) {
594 buf[i].rdma.pnext = PHYSADDR(&buf[i + 1]);
595 buf[i].rdma.pbuf = 0;
596 i++;
598 buf[i].rdma.pbuf = 0;
599 buf[i].rdma.pnext = PHYSADDR(&buf[0]);
602 #define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
604 int sgiseeq_init(struct hpc3_regs* regs, int irq)
606 struct net_device *dev;
607 struct sgiseeq_private *sp;
608 int err, i;
610 dev = alloc_etherdev(sizeof(struct sgiseeq_private));
611 if (!dev) {
612 printk(KERN_ERR "Sgiseeq: Etherdev alloc failed, aborting.\n");
613 err = -ENOMEM;
614 goto err_out;
617 sp = dev->priv;
619 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
620 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
621 err = -EAGAIN;
622 goto err_out_free_dev;
625 printk(KERN_INFO "%s: SGI Seeq8003 ", dev->name);
627 #define EADDR_NVOFS 250
628 for (i = 0; i < 3; i++) {
629 unsigned short tmp = ip22_nvram_read(EADDR_NVOFS / 2 + i);
631 printk("%2.2x:%2.2x%c",
632 dev->dev_addr[2 * i] = tmp >> 8,
633 dev->dev_addr[2 * i + 1] = tmp & 0xff,
634 i == 2 ? ' ' : ':');
636 printk("\n");
638 #ifdef DEBUG
639 gpriv = sp;
640 gdev = dev;
641 #endif
642 sp->sregs = (struct sgiseeq_regs *) &hpc3c0->eth_ext[0];
643 sp->hregs = &hpc3c0->ethregs;
644 sp->name = sgiseeqstr;
646 sp->srings.rx_desc = (struct sgiseeq_rx_desc *)
647 (KSEG1ADDR(ALIGNED(&sp->srings.rxvector[0])));
648 dma_cache_wback_inv((unsigned long)&sp->srings.rxvector,
649 sizeof(sp->srings.rxvector));
650 sp->srings.tx_desc = (struct sgiseeq_tx_desc *)
651 (KSEG1ADDR(ALIGNED(&sp->srings.txvector[0])));
652 dma_cache_wback_inv((unsigned long)&sp->srings.txvector,
653 sizeof(sp->srings.txvector));
655 /* A couple calculations now, saves many cycles later. */
656 setup_rx_ring(sp->srings.rx_desc, SEEQ_RX_BUFFERS);
657 setup_tx_ring(sp->srings.tx_desc, SEEQ_TX_BUFFERS);
659 /* Reset the chip. */
660 hpc3_eth_reset(sp->hregs);
662 sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
663 if (sp->is_edlc)
664 sp->control = (SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
665 SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
666 SEEQ_CTRL_ENCARR);
668 dev->open = sgiseeq_open;
669 dev->stop = sgiseeq_close;
670 dev->hard_start_xmit = sgiseeq_start_xmit;
671 dev->tx_timeout = timeout;
672 dev->watchdog_timeo = (200 * HZ) / 1000;
673 dev->get_stats = sgiseeq_get_stats;
674 dev->set_multicast_list = sgiseeq_set_multicast;
675 dev->irq = irq;
676 dev->dma = 0;
678 if (register_netdev(dev)) {
679 printk(KERN_ERR "Sgiseeq: Cannot register net device, "
680 "aborting.\n");
681 err = -ENODEV;
682 goto err_out_free_irq;
685 sp->next_module = root_sgiseeq_dev;
686 root_sgiseeq_dev = dev;
688 return 0;
690 err_out_free_irq:
691 free_irq(irq, dev);
693 err_out_free_dev:
694 kfree(dev);
696 err_out:
697 return err;
700 static int __init sgiseeq_probe(void)
702 printk(version);
704 /* On board adapter on 1st HPC is always present */
705 return sgiseeq_init(hpc3c0, SGI_ENET_IRQ);
708 static void __exit sgiseeq_exit(void)
710 struct net_device *next, *dev;
711 struct sgiseeq_private *sp;
712 int irq;
714 for (dev = root_sgiseeq_dev; dev; dev = next) {
715 sp = (struct sgiseeq_private *) dev->priv;
716 next = sp->next_module;
717 irq = dev->irq;
718 unregister_netdev(dev);
719 free_irq(irq, dev);
720 kfree(dev);
724 module_init(sgiseeq_probe);
725 module_exit(sgiseeq_exit);
727 MODULE_LICENSE("GPL");