Don't free the private area now that we've converted to alloc_etherdev.
[linux-2.6/linux-mips.git] / drivers / net / sgiseeq.c
blob089303b1e265f93cd82be0703ec1103e742ebe1a
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/init.h>
9 #include <linux/types.h>
10 #include <linux/interrupt.h>
11 #include <linux/ioport.h>
12 #include <linux/in.h>
13 #include <linux/route.h>
14 #include <linux/slab.h>
15 #include <linux/socket.h>
16 #include <linux/string.h>
17 #include <linux/delay.h>
18 #include <linux/errno.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 =
36 "sgiseeq.c: David S. Miller (dm@engr.sgi.com)\n";
38 static char *sgiseeqstr = "SGI Seeq8003";
40 /* If you want speed, you do something silly, it always has worked
41 * for me. So, with that in mind, I've decided to make this driver
42 * look completely like a stupid Lance from a driver architecture
43 * perspective. Only difference is that here our "ring buffer" looks
44 * and acts like a real Lance one does but is layed out like how the
45 * HPC DMA and the Seeq want it to. You'd be surprised how a stupid
46 * idea like this can pay off in performance, not to mention making
47 * this driver 2,000 times easier to write. ;-)
50 /* Tune these if we tend to run out often etc. */
51 #define SEEQ_RX_BUFFERS 16
52 #define SEEQ_TX_BUFFERS 16
54 #define PKT_BUF_SZ 1584
56 #define NEXT_RX(i) (((i) + 1) & (SEEQ_RX_BUFFERS - 1))
57 #define NEXT_TX(i) (((i) + 1) & (SEEQ_TX_BUFFERS - 1))
58 #define PREV_RX(i) (((i) - 1) & (SEEQ_RX_BUFFERS - 1))
59 #define PREV_TX(i) (((i) - 1) & (SEEQ_TX_BUFFERS - 1))
61 #define TX_BUFFS_AVAIL(sp) ((sp->tx_old <= sp->tx_new) ? \
62 sp->tx_old + (SEEQ_TX_BUFFERS - 1) - sp->tx_new : \
63 sp->tx_old - sp->tx_new - 1)
65 #define DEBUG
67 struct sgiseeq_rx_desc {
68 struct hpc_dma_desc rdma;
69 signed int buf_vaddr;
72 struct sgiseeq_tx_desc {
73 struct hpc_dma_desc tdma;
74 signed int buf_vaddr;
77 /* Warning: This structure is layed out in a certain way because
78 * HPC dma descriptors must be 8-byte aligned. So don't
79 * touch this without 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;
110 /* A list of all installed seeq devices, for removing the driver module. */
111 static struct net_device *root_sgiseeq_dev;
113 static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
115 hregs->rx_reset = (HPC3_ERXRST_CRESET | HPC3_ERXRST_CLRIRQ);
116 udelay(20);
117 hregs->rx_reset = 0;
120 static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
121 struct sgiseeq_regs *sregs)
123 hregs->rx_ctrl = hregs->tx_ctrl = 0;
124 hpc3_eth_reset(hregs);
127 #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
128 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
130 static inline void seeq_go(struct sgiseeq_private *sp,
131 struct hpc3_ethregs *hregs,
132 struct sgiseeq_regs *sregs)
134 sregs->rstat = sp->mode | RSTAT_GO_BITS;
135 hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE;
138 static inline void seeq_load_eaddr(struct net_device *dev,
139 struct sgiseeq_regs *sregs)
141 int i;
143 sregs->tstat = SEEQ_TCMD_RB0;
144 for (i = 0; i < 6; i++)
145 sregs->rw.eth_addr[i] = dev->dev_addr[i];
148 #define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD)
149 #define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE)
150 #define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT))
152 static int seeq_init_ring(struct net_device *dev)
154 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
155 volatile struct sgiseeq_init_block *ib = &sp->srings;
156 int i;
158 netif_stop_queue(dev);
159 sp->rx_new = sp->tx_new = 0;
160 sp->rx_old = sp->tx_old = 0;
162 seeq_load_eaddr(dev, sp->sregs);
164 /* XXX for now just accept packets directly to us
165 * XXX and ether-broadcast. Will do multicast and
166 * XXX promiscuous mode later. -davem
168 sp->mode = SEEQ_RCMD_RBCAST;
170 /* Setup tx ring. */
171 for(i = 0; i < SEEQ_TX_BUFFERS; i++) {
172 if(!ib->tx_desc[i].tdma.pbuf) {
173 unsigned long buffer;
175 buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
176 if (!buffer)
177 return -ENOMEM;
178 ib->tx_desc[i].buf_vaddr = KSEG1ADDR(buffer);
179 ib->tx_desc[i].tdma.pbuf = PHYSADDR(buffer);
181 ib->tx_desc[i].tdma.cntinfo = (TCNTINFO_INIT);
184 /* And now the rx ring. */
185 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
186 if (!ib->rx_desc[i].rdma.pbuf) {
187 unsigned long buffer;
189 buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
190 if (!buffer)
191 return -ENOMEM;
192 ib->rx_desc[i].buf_vaddr = KSEG1ADDR(buffer);
193 ib->rx_desc[i].rdma.pbuf = PHYSADDR(buffer);
195 ib->rx_desc[i].rdma.cntinfo = (RCNTINFO_INIT);
197 ib->rx_desc[i - 1].rdma.cntinfo |= (HPCDMA_EOR);
198 return 0;
201 #ifdef DEBUG
202 static struct sgiseeq_private *gpriv;
203 static struct net_device *gdev;
205 void sgiseeq_dump_rings(void)
207 static int once;
208 struct sgiseeq_rx_desc *r = gpriv->srings.rx_desc;
209 struct sgiseeq_tx_desc *t = gpriv->srings.tx_desc;
210 struct hpc3_ethregs *hregs = gpriv->hregs;
211 int i;
213 if(once)
214 return;
215 once++;
216 printk("RING DUMP:\n");
217 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
218 printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
219 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
220 r[i].rdma.pnext);
221 i += 1;
222 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
223 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
224 r[i].rdma.pnext);
226 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
227 printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
228 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
229 t[i].tdma.pnext);
230 i += 1;
231 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
232 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
233 t[i].tdma.pnext);
235 printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
236 gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old);
237 printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
238 hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl);
239 printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
240 hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl);
242 #endif
244 #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
245 #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
246 #define RDMACFG_INIT (HPC3_ERXDCFG_FRXDC | HPC3_ERXDCFG_FEOP | HPC3_ERXDCFG_FIRQ)
248 static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
249 struct sgiseeq_regs *sregs)
251 struct hpc3_ethregs *hregs = sp->hregs;
252 int err;
254 reset_hpc3_and_seeq(hregs, sregs);
255 err = seeq_init_ring(dev);
256 if (err)
257 return err;
259 /* Setup to field the proper interrupt types. */
260 if (sp->is_edlc) {
261 sregs->tstat = (TSTAT_INIT_EDLC);
262 sregs->rw.wregs.control = sp->control;
263 sregs->rw.wregs.frame_gap = 0;
264 } else {
265 sregs->tstat = (TSTAT_INIT_SEEQ);
268 hregs->rx_dconfig |= RDMACFG_INIT;
270 hregs->rx_ndptr = PHYSADDR(&sp->srings.rx_desc[0]);
271 hregs->tx_ndptr = PHYSADDR(&sp->srings.tx_desc[0]);
273 seeq_go(sp, hregs, sregs);
274 return 0;
277 static inline void record_rx_errors(struct sgiseeq_private *sp,
278 unsigned char status)
280 if (status & SEEQ_RSTAT_OVERF ||
281 status & SEEQ_RSTAT_SFRAME)
282 sp->stats.rx_over_errors++;
283 if (status & SEEQ_RSTAT_CERROR)
284 sp->stats.rx_crc_errors++;
285 if (status & SEEQ_RSTAT_DERROR)
286 sp->stats.rx_frame_errors++;
287 if (status & SEEQ_RSTAT_REOF)
288 sp->stats.rx_errors++;
291 static inline void rx_maybe_restart(struct sgiseeq_private *sp,
292 struct hpc3_ethregs *hregs,
293 struct sgiseeq_regs *sregs)
295 if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) {
296 hregs->rx_ndptr = PHYSADDR(&sp->srings.rx_desc[sp->rx_new]);
297 seeq_go(sp, hregs, sregs);
301 #define for_each_rx(rd, sp) for((rd) = &(sp)->srings.rx_desc[(sp)->rx_new]; \
302 !((rd)->rdma.cntinfo & HPCDMA_OWN); \
303 (rd) = &(sp)->srings.rx_desc[(sp)->rx_new])
305 static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp,
306 struct hpc3_ethregs *hregs,
307 struct sgiseeq_regs *sregs)
309 struct sgiseeq_rx_desc *rd;
310 struct sk_buff *skb = 0;
311 unsigned char pkt_status;
312 unsigned char *pkt_pointer = 0;
313 int len = 0;
314 unsigned int orig_end = PREV_RX(sp->rx_new);
316 /* Service every received packet. */
317 for_each_rx(rd, sp) {
318 len = (PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3);
319 pkt_pointer = (unsigned char *)(long)rd->buf_vaddr;
320 pkt_status = pkt_pointer[len + 2];
322 if (pkt_status & SEEQ_RSTAT_FIG) {
323 /* Packet is OK. */
324 skb = dev_alloc_skb(len + 2);
326 if (skb) {
327 skb->dev = dev;
328 skb_reserve(skb, 2);
329 skb_put(skb, len);
331 /* Copy out of kseg1 to avoid silly cache flush. */
332 eth_copy_and_sum(skb, pkt_pointer + 2, len, 0);
333 skb->protocol = eth_type_trans(skb, dev);
334 netif_rx(skb);
335 dev->last_rx = jiffies;
336 sp->stats.rx_packets++;
337 sp->stats.rx_bytes += len;
338 } else {
339 printk (KERN_NOTICE "%s: Memory squeeze, deferring packet.\n",
340 dev->name);
341 sp->stats.rx_dropped++;
343 } else {
344 record_rx_errors(sp, pkt_status);
347 /* Return the entry to the ring pool. */
348 rd->rdma.cntinfo = (RCNTINFO_INIT);
349 sp->rx_new = NEXT_RX(sp->rx_new);
351 sp->srings.rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
352 sp->srings.rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
353 rx_maybe_restart(sp, hregs, sregs);
356 static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
357 struct sgiseeq_regs *sregs)
359 if (sp->is_edlc) {
360 sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
361 sregs->rw.wregs.control = sp->control;
365 static inline void kick_tx(struct sgiseeq_tx_desc *td,
366 struct hpc3_ethregs *hregs)
368 /* If the HPC aint doin nothin, and there are more packets
369 * with ETXD cleared and XIU set we must make very certain
370 * that we restart the HPC else we risk locking up the
371 * adapter. The following code is only safe iff the HPCDMA
372 * is not active!
374 while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
375 (HPCDMA_XIU | HPCDMA_ETXD))
376 td = (struct sgiseeq_tx_desc *)(long) KSEG1ADDR(td->tdma.pnext);
377 if (td->tdma.cntinfo & HPCDMA_XIU) {
378 hregs->tx_ndptr = PHYSADDR(td);
379 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
383 static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
384 struct hpc3_ethregs *hregs,
385 struct sgiseeq_regs *sregs)
387 struct sgiseeq_tx_desc *td;
388 unsigned long status = hregs->tx_ctrl;
389 int j;
391 tx_maybe_reset_collisions(sp, sregs);
393 if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
394 /* Oops, HPC detected some sort of error. */
395 if (status & SEEQ_TSTAT_R16)
396 sp->stats.tx_aborted_errors++;
397 if (status & SEEQ_TSTAT_UFLOW)
398 sp->stats.tx_fifo_errors++;
399 if (status & SEEQ_TSTAT_LCLS)
400 sp->stats.collisions++;
403 /* Ack 'em... */
404 for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
405 td = &sp->srings.tx_desc[j];
407 if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
408 break;
409 if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
410 if(!(status & HPC3_ETXCTRL_ACTIVE)) {
411 hregs->tx_ndptr = PHYSADDR(td);
412 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
414 break;
416 sp->stats.tx_packets++;
417 sp->tx_old = NEXT_TX(sp->tx_old);
418 td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
419 td->tdma.cntinfo |= HPCDMA_EOX;
423 static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id, struct pt_regs *regs)
425 struct net_device *dev = (struct net_device *) dev_id;
426 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
427 struct hpc3_ethregs *hregs = sp->hregs;
428 struct sgiseeq_regs *sregs = sp->sregs;
430 /* Ack the IRQ and set software state. */
431 hregs->rx_reset = HPC3_ERXRST_CLRIRQ;
433 /* Always check for received packets. */
434 sgiseeq_rx(dev, sp, hregs, sregs);
436 /* Only check for tx acks if we have something queued. */
437 if (sp->tx_old != sp->tx_new)
438 sgiseeq_tx(dev, sp, hregs, sregs);
440 if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
441 netif_wake_queue(dev);
443 return IRQ_HANDLED;
446 static int sgiseeq_open(struct net_device *dev)
448 struct sgiseeq_private *sp = (struct sgiseeq_private *)dev->priv;
449 struct sgiseeq_regs *sregs = sp->sregs;
451 int err = init_seeq(dev, sp, sregs);
452 if (err)
453 return err;
455 netif_start_queue(dev);
457 return 0;
460 static int sgiseeq_close(struct net_device *dev)
462 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
463 struct sgiseeq_regs *sregs = sp->sregs;
465 netif_stop_queue(dev);
467 /* Shutdown the Seeq. */
468 reset_hpc3_and_seeq(sp->hregs, sregs);
470 return 0;
473 static inline int sgiseeq_reset(struct net_device *dev)
475 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
476 struct sgiseeq_regs *sregs = sp->sregs;
477 int err;
479 err = init_seeq(dev, sp, sregs);
480 if (err)
481 return err;
483 dev->trans_start = jiffies;
484 netif_wake_queue(dev);
486 return 0;
489 void sgiseeq_my_reset(void)
491 printk("RESET!\n");
492 sgiseeq_reset(gdev);
495 static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
497 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
498 struct hpc3_ethregs *hregs = sp->hregs;
499 unsigned long flags;
500 struct sgiseeq_tx_desc *td;
501 int skblen, len, entry;
503 local_irq_save(flags);
505 /* Setup... */
506 skblen = skb->len;
507 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
508 sp->stats.tx_bytes += len;
509 entry = sp->tx_new;
510 td = &sp->srings.tx_desc[entry];
512 /* Create entry. There are so many races with adding a new
513 * descriptor to the chain:
514 * 1) Assume that the HPC is off processing a DMA chain while
515 * we are changing all of the following.
516 * 2) Do no allow the HPC to look at a new descriptor until
517 * we have completely set up it's state. This means, do
518 * not clear HPCDMA_EOX in the current last descritptor
519 * until the one we are adding looks consistent and could
520 * be processes right now.
521 * 3) The tx interrupt code must notice when we've added a new
522 * entry and the HPC got to the end of the chain before we
523 * added this new entry and restarted it.
525 memcpy((char *)(long)td->buf_vaddr, skb->data, skblen);
526 if (len != skblen)
527 memset((char *)(long)td->buf_vaddr + skb->len, 0, len-skblen);
528 td->tdma.cntinfo = (len & HPCDMA_BCNT) |
529 (HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX);
530 if (sp->tx_old != sp->tx_new) {
531 struct sgiseeq_tx_desc *backend;
533 backend = &sp->srings.tx_desc[PREV_TX(sp->tx_new)];
534 backend->tdma.cntinfo &= ~(HPCDMA_EOX);
536 sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
538 /* Maybe kick the HPC back into motion. */
539 if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
540 kick_tx(&sp->srings.tx_desc[sp->tx_old], hregs);
542 dev->trans_start = jiffies;
543 dev_kfree_skb(skb);
545 if (!TX_BUFFS_AVAIL(sp))
546 netif_stop_queue(dev);
547 local_irq_restore(flags);
549 return 0;
552 static void timeout(struct net_device *dev)
554 printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
555 sgiseeq_reset(dev);
557 dev->trans_start = jiffies;
558 netif_wake_queue(dev);
561 static struct net_device_stats *sgiseeq_get_stats(struct net_device *dev)
563 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
565 return &sp->stats;
568 static void sgiseeq_set_multicast(struct net_device *dev)
572 static inline void setup_tx_ring(struct sgiseeq_tx_desc *buf, int nbufs)
574 int i = 0;
576 while (i < (nbufs - 1)) {
577 buf[i].tdma.pnext = PHYSADDR(&buf[i + 1]);
578 buf[i].tdma.pbuf = 0;
579 i++;
581 buf[i].tdma.pnext = PHYSADDR(&buf[0]);
584 static inline void setup_rx_ring(struct sgiseeq_rx_desc *buf, int nbufs)
586 int i = 0;
588 while (i < (nbufs - 1)) {
589 buf[i].rdma.pnext = PHYSADDR(&buf[i + 1]);
590 buf[i].rdma.pbuf = 0;
591 i++;
593 buf[i].rdma.pbuf = 0;
594 buf[i].rdma.pnext = PHYSADDR(&buf[0]);
597 #define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
599 int sgiseeq_init(struct hpc3_regs* regs, int irq)
601 struct net_device *dev;
602 struct sgiseeq_private *sp;
603 int err, i;
605 dev = alloc_etherdev(sizeof(struct sgiseeq_private));
606 if (!dev) {
607 printk(KERN_ERR "Sgiseeq: Etherdev alloc failed, aborting.\n");
608 err = -ENOMEM;
609 goto err_out;
612 sp = dev->priv;
614 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
615 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
616 free_page((unsigned long) sp);
617 unregister_netdev(dev);
618 return -EAGAIN;
621 printk(KERN_INFO "%s: SGI Seeq8003 ", dev->name);
623 #define EADDR_NVOFS 250
624 for (i = 0; i < 3; i++) {
625 unsigned short tmp = ip22_nvram_read(EADDR_NVOFS / 2 + i);
627 printk("%2.2x:%2.2x%c",
628 dev->dev_addr[2 * i] = tmp >> 8,
629 dev->dev_addr[2 * i + 1] = tmp & 0xff,
630 i == 2 ? ' ' : ':');
632 printk("\n");
634 #ifdef DEBUG
635 gpriv = sp;
636 gdev = dev;
637 #endif
638 sp->sregs = (struct sgiseeq_regs *) &hpc3c0->eth_ext[0];
639 sp->hregs = &hpc3c0->ethregs;
640 sp->name = sgiseeqstr;
642 sp->srings.rx_desc = (struct sgiseeq_rx_desc *)
643 (KSEG1ADDR(ALIGNED(&sp->srings.rxvector[0])));
644 dma_cache_wback_inv((unsigned long)&sp->srings.rxvector,
645 sizeof(sp->srings.rxvector));
646 sp->srings.tx_desc = (struct sgiseeq_tx_desc *)
647 (KSEG1ADDR(ALIGNED(&sp->srings.txvector[0])));
648 dma_cache_wback_inv((unsigned long)&sp->srings.txvector,
649 sizeof(sp->srings.txvector));
651 /* A couple calculations now, saves many cycles later. */
652 setup_rx_ring(sp->srings.rx_desc, SEEQ_RX_BUFFERS);
653 setup_tx_ring(sp->srings.tx_desc, SEEQ_TX_BUFFERS);
655 /* Reset the chip. */
656 hpc3_eth_reset(sp->hregs);
658 sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
659 if (sp->is_edlc)
660 sp->control = (SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
661 SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
662 SEEQ_CTRL_ENCARR);
664 dev->open = sgiseeq_open;
665 dev->stop = sgiseeq_close;
666 dev->hard_start_xmit = sgiseeq_start_xmit;
667 dev->tx_timeout = timeout;
668 dev->watchdog_timeo = (200 * HZ) / 1000;
669 dev->get_stats = sgiseeq_get_stats;
670 dev->set_multicast_list = sgiseeq_set_multicast;
671 dev->irq = irq;
672 dev->dma = 0;
674 if (register_netdev(dev)) {
675 printk(KERN_ERR "Sgiseeq: Cannot register net device, "
676 "aborting.\n");
677 err = -ENODEV;
678 goto err_out_free_irq;
681 sp->next_module = root_sgiseeq_dev;
682 root_sgiseeq_dev = dev;
684 return 0;
686 err_out_free_irq:
687 free_irq(irq, dev);
689 err_out:
690 return err;
693 static int __init sgiseeq_probe(void)
695 printk(version);
697 /* On board adapter on 1st HPC is always present */
698 return sgiseeq_init(hpc3c0, SGI_ENET_IRQ);
701 static void __exit sgiseeq_exit(void)
703 struct net_device *next, *dev;
704 struct sgiseeq_private *sp;
705 int irq;
707 for (dev = root_sgiseeq_dev; dev; dev = next) {
708 sp = (struct sgiseeq_private *) dev->priv;
709 next = sp->next_module;
710 irq = dev->irq;
711 unregister_netdev(dev);
712 free_irq(irq, dev);
713 kfree(dev);
717 module_init(sgiseeq_probe);
718 module_exit(sgiseeq_exit);
720 MODULE_LICENSE("GPL");