Pull bugzilla-9429 into release branch
[pv_ops_mirror.git] / drivers / net / sgiseeq.c
blobff4056310356a8e04b2b33634d1098e474347b2c
1 /*
2 * sgiseeq.c: Seeq8003 ethernet driver for SGI machines.
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
5 */
7 #undef DEBUG
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/errno.h>
12 #include <linux/init.h>
13 #include <linux/types.h>
14 #include <linux/interrupt.h>
15 #include <linux/slab.h>
16 #include <linux/string.h>
17 #include <linux/delay.h>
18 #include <linux/netdevice.h>
19 #include <linux/platform_device.h>
20 #include <linux/etherdevice.h>
21 #include <linux/skbuff.h>
23 #include <asm/sgi/hpc3.h>
24 #include <asm/sgi/ip22.h>
25 #include <asm/sgi/seeq.h>
27 #include "sgiseeq.h"
29 static char *sgiseeqstr = "SGI Seeq8003";
32 * If you want speed, you do something silly, it always has worked for me. So,
33 * with that in mind, I've decided to make this driver look completely like a
34 * stupid Lance from a driver architecture perspective. Only difference is that
35 * here our "ring buffer" looks and acts like a real Lance one does but is
36 * layed out like how the HPC DMA and the Seeq want it to. You'd be surprised
37 * how a stupid idea like this can pay off in performance, not to mention
38 * making this driver 2,000 times easier to write. ;-)
41 /* Tune these if we tend to run out often etc. */
42 #define SEEQ_RX_BUFFERS 16
43 #define SEEQ_TX_BUFFERS 16
45 #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))
52 #define TX_BUFFS_AVAIL(sp) ((sp->tx_old <= sp->tx_new) ? \
53 sp->tx_old + (SEEQ_TX_BUFFERS - 1) - sp->tx_new : \
54 sp->tx_old - sp->tx_new - 1)
56 struct sgiseeq_rx_desc {
57 volatile struct hpc_dma_desc rdma;
58 volatile signed int buf_vaddr;
61 struct sgiseeq_tx_desc {
62 volatile struct hpc_dma_desc tdma;
63 volatile signed int buf_vaddr;
67 * Warning: This structure is layed out in a certain way because HPC dma
68 * descriptors must be 8-byte aligned. So don't touch this without
69 * some care.
71 struct sgiseeq_init_block { /* Note the name ;-) */
72 struct sgiseeq_rx_desc rxvector[SEEQ_RX_BUFFERS];
73 struct sgiseeq_tx_desc txvector[SEEQ_TX_BUFFERS];
76 struct sgiseeq_private {
77 struct sgiseeq_init_block *srings;
78 dma_addr_t srings_dma;
80 /* Ptrs to the descriptors in uncached space. */
81 struct sgiseeq_rx_desc *rx_desc;
82 struct sgiseeq_tx_desc *tx_desc;
84 char *name;
85 struct hpc3_ethregs *hregs;
86 struct sgiseeq_regs *sregs;
88 /* Ring entry counters. */
89 unsigned int rx_new, tx_new;
90 unsigned int rx_old, tx_old;
92 int is_edlc;
93 unsigned char control;
94 unsigned char mode;
96 spinlock_t tx_lock;
99 static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
101 hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ;
102 udelay(20);
103 hregs->reset = 0;
106 static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
107 struct sgiseeq_regs *sregs)
109 hregs->rx_ctrl = hregs->tx_ctrl = 0;
110 hpc3_eth_reset(hregs);
113 #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
114 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
116 static inline void seeq_go(struct sgiseeq_private *sp,
117 struct hpc3_ethregs *hregs,
118 struct sgiseeq_regs *sregs)
120 sregs->rstat = sp->mode | RSTAT_GO_BITS;
121 hregs->rx_ctrl = HPC3_ERXCTRL_ACTIVE;
124 static inline void __sgiseeq_set_mac_address(struct net_device *dev)
126 struct sgiseeq_private *sp = netdev_priv(dev);
127 struct sgiseeq_regs *sregs = sp->sregs;
128 int i;
130 sregs->tstat = SEEQ_TCMD_RB0;
131 for (i = 0; i < 6; i++)
132 sregs->rw.eth_addr[i] = dev->dev_addr[i];
135 static int sgiseeq_set_mac_address(struct net_device *dev, void *addr)
137 struct sgiseeq_private *sp = netdev_priv(dev);
138 struct sockaddr *sa = addr;
140 memcpy(dev->dev_addr, sa->sa_data, dev->addr_len);
142 spin_lock_irq(&sp->tx_lock);
143 __sgiseeq_set_mac_address(dev);
144 spin_unlock_irq(&sp->tx_lock);
146 return 0;
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 = netdev_priv(dev);
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 __sgiseeq_set_mac_address(dev);
164 /* Setup tx ring. */
165 for(i = 0; i < SEEQ_TX_BUFFERS; i++) {
166 if (!sp->tx_desc[i].tdma.pbuf) {
167 unsigned long buffer;
169 buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
170 if (!buffer)
171 return -ENOMEM;
172 sp->tx_desc[i].buf_vaddr = CKSEG1ADDR(buffer);
173 sp->tx_desc[i].tdma.pbuf = CPHYSADDR(buffer);
175 sp->tx_desc[i].tdma.cntinfo = TCNTINFO_INIT;
178 /* And now the rx ring. */
179 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
180 if (!sp->rx_desc[i].rdma.pbuf) {
181 unsigned long buffer;
183 buffer = (unsigned long) kmalloc(PKT_BUF_SZ, GFP_KERNEL);
184 if (!buffer)
185 return -ENOMEM;
186 sp->rx_desc[i].buf_vaddr = CKSEG1ADDR(buffer);
187 sp->rx_desc[i].rdma.pbuf = CPHYSADDR(buffer);
189 sp->rx_desc[i].rdma.cntinfo = RCNTINFO_INIT;
191 sp->rx_desc[i - 1].rdma.cntinfo |= HPCDMA_EOR;
192 return 0;
195 #ifdef DEBUG
196 static struct sgiseeq_private *gpriv;
197 static struct net_device *gdev;
199 static void sgiseeq_dump_rings(void)
201 static int once;
202 struct sgiseeq_rx_desc *r = gpriv->rx_desc;
203 struct sgiseeq_tx_desc *t = gpriv->tx_desc;
204 struct hpc3_ethregs *hregs = gpriv->hregs;
205 int i;
207 if (once)
208 return;
209 once++;
210 printk("RING DUMP:\n");
211 for (i = 0; i < SEEQ_RX_BUFFERS; i++) {
212 printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
213 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
214 r[i].rdma.pnext);
215 i += 1;
216 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
217 i, (&r[i]), r[i].rdma.pbuf, r[i].rdma.cntinfo,
218 r[i].rdma.pnext);
220 for (i = 0; i < SEEQ_TX_BUFFERS; i++) {
221 printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
222 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
223 t[i].tdma.pnext);
224 i += 1;
225 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
226 i, (&t[i]), t[i].tdma.pbuf, t[i].tdma.cntinfo,
227 t[i].tdma.pnext);
229 printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
230 gpriv->rx_new, gpriv->rx_old, gpriv->tx_new, gpriv->tx_old);
231 printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
232 hregs->rx_cbptr, hregs->rx_ndptr, hregs->rx_ctrl);
233 printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
234 hregs->tx_cbptr, hregs->tx_ndptr, hregs->tx_ctrl);
236 #endif
238 #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
239 #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
241 static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
242 struct sgiseeq_regs *sregs)
244 struct hpc3_ethregs *hregs = sp->hregs;
245 int err;
247 reset_hpc3_and_seeq(hregs, sregs);
248 err = seeq_init_ring(dev);
249 if (err)
250 return err;
252 /* Setup to field the proper interrupt types. */
253 if (sp->is_edlc) {
254 sregs->tstat = TSTAT_INIT_EDLC;
255 sregs->rw.wregs.control = sp->control;
256 sregs->rw.wregs.frame_gap = 0;
257 } else {
258 sregs->tstat = TSTAT_INIT_SEEQ;
261 hregs->rx_ndptr = CPHYSADDR(sp->rx_desc);
262 hregs->tx_ndptr = CPHYSADDR(sp->tx_desc);
264 seeq_go(sp, hregs, sregs);
265 return 0;
268 static void record_rx_errors(struct net_device *dev, unsigned char status)
270 if (status & SEEQ_RSTAT_OVERF ||
271 status & SEEQ_RSTAT_SFRAME)
272 dev->stats.rx_over_errors++;
273 if (status & SEEQ_RSTAT_CERROR)
274 dev->stats.rx_crc_errors++;
275 if (status & SEEQ_RSTAT_DERROR)
276 dev->stats.rx_frame_errors++;
277 if (status & SEEQ_RSTAT_REOF)
278 dev->stats.rx_errors++;
281 static inline void rx_maybe_restart(struct sgiseeq_private *sp,
282 struct hpc3_ethregs *hregs,
283 struct sgiseeq_regs *sregs)
285 if (!(hregs->rx_ctrl & HPC3_ERXCTRL_ACTIVE)) {
286 hregs->rx_ndptr = CPHYSADDR(sp->rx_desc + sp->rx_new);
287 seeq_go(sp, hregs, sregs);
291 #define for_each_rx(rd, sp) for((rd) = &(sp)->rx_desc[(sp)->rx_new]; \
292 !((rd)->rdma.cntinfo & HPCDMA_OWN); \
293 (rd) = &(sp)->rx_desc[(sp)->rx_new])
295 static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp,
296 struct hpc3_ethregs *hregs,
297 struct sgiseeq_regs *sregs)
299 struct sgiseeq_rx_desc *rd;
300 struct sk_buff *skb = NULL;
301 unsigned char pkt_status;
302 unsigned char *pkt_pointer = NULL;
303 int len = 0;
304 unsigned int orig_end = PREV_RX(sp->rx_new);
306 /* Service every received packet. */
307 for_each_rx(rd, sp) {
308 len = PKT_BUF_SZ - (rd->rdma.cntinfo & HPCDMA_BCNT) - 3;
309 pkt_pointer = (unsigned char *)(long)rd->buf_vaddr;
310 pkt_status = pkt_pointer[len + 2];
312 if (pkt_status & SEEQ_RSTAT_FIG) {
313 /* Packet is OK. */
314 skb = dev_alloc_skb(len + 2);
316 if (skb) {
317 skb_reserve(skb, 2);
318 skb_put(skb, len);
320 /* Copy out of kseg1 to avoid silly cache flush. */
321 skb_copy_to_linear_data(skb, pkt_pointer + 2, len);
322 skb->protocol = eth_type_trans(skb, dev);
324 /* We don't want to receive our own packets */
325 if (memcmp(eth_hdr(skb)->h_source, dev->dev_addr, ETH_ALEN)) {
326 netif_rx(skb);
327 dev->last_rx = jiffies;
328 dev->stats.rx_packets++;
329 dev->stats.rx_bytes += len;
330 } else {
331 /* Silently drop my own packets */
332 dev_kfree_skb_irq(skb);
334 } else {
335 printk (KERN_NOTICE "%s: Memory squeeze, deferring packet.\n",
336 dev->name);
337 dev->stats.rx_dropped++;
339 } else {
340 record_rx_errors(dev, pkt_status);
343 /* Return the entry to the ring pool. */
344 rd->rdma.cntinfo = RCNTINFO_INIT;
345 sp->rx_new = NEXT_RX(sp->rx_new);
347 sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
348 sp->rx_desc[PREV_RX(sp->rx_new)].rdma.cntinfo |= HPCDMA_EOR;
349 rx_maybe_restart(sp, hregs, sregs);
352 static inline void tx_maybe_reset_collisions(struct sgiseeq_private *sp,
353 struct sgiseeq_regs *sregs)
355 if (sp->is_edlc) {
356 sregs->rw.wregs.control = sp->control & ~(SEEQ_CTRL_XCNT);
357 sregs->rw.wregs.control = sp->control;
361 static inline void kick_tx(struct sgiseeq_tx_desc *td,
362 struct hpc3_ethregs *hregs)
364 /* If the HPC aint doin nothin, and there are more packets
365 * with ETXD cleared and XIU set we must make very certain
366 * that we restart the HPC else we risk locking up the
367 * adapter. The following code is only safe iff the HPCDMA
368 * is not active!
370 while ((td->tdma.cntinfo & (HPCDMA_XIU | HPCDMA_ETXD)) ==
371 (HPCDMA_XIU | HPCDMA_ETXD))
372 td = (struct sgiseeq_tx_desc *)(long) CKSEG1ADDR(td->tdma.pnext);
373 if (td->tdma.cntinfo & HPCDMA_XIU) {
374 hregs->tx_ndptr = CPHYSADDR(td);
375 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
379 static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp,
380 struct hpc3_ethregs *hregs,
381 struct sgiseeq_regs *sregs)
383 struct sgiseeq_tx_desc *td;
384 unsigned long status = hregs->tx_ctrl;
385 int j;
387 tx_maybe_reset_collisions(sp, sregs);
389 if (!(status & (HPC3_ETXCTRL_ACTIVE | SEEQ_TSTAT_PTRANS))) {
390 /* Oops, HPC detected some sort of error. */
391 if (status & SEEQ_TSTAT_R16)
392 dev->stats.tx_aborted_errors++;
393 if (status & SEEQ_TSTAT_UFLOW)
394 dev->stats.tx_fifo_errors++;
395 if (status & SEEQ_TSTAT_LCLS)
396 dev->stats.collisions++;
399 /* Ack 'em... */
400 for (j = sp->tx_old; j != sp->tx_new; j = NEXT_TX(j)) {
401 td = &sp->tx_desc[j];
403 if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
404 break;
405 if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
406 if (!(status & HPC3_ETXCTRL_ACTIVE)) {
407 hregs->tx_ndptr = CPHYSADDR(td);
408 hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
410 break;
412 dev->stats.tx_packets++;
413 sp->tx_old = NEXT_TX(sp->tx_old);
414 td->tdma.cntinfo &= ~(HPCDMA_XIU | HPCDMA_XIE);
415 td->tdma.cntinfo |= HPCDMA_EOX;
419 static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id)
421 struct net_device *dev = (struct net_device *) dev_id;
422 struct sgiseeq_private *sp = netdev_priv(dev);
423 struct hpc3_ethregs *hregs = sp->hregs;
424 struct sgiseeq_regs *sregs = sp->sregs;
426 spin_lock(&sp->tx_lock);
428 /* Ack the IRQ and set software state. */
429 hregs->reset = HPC3_ERST_CLRIRQ;
431 /* Always check for received packets. */
432 sgiseeq_rx(dev, sp, hregs, sregs);
434 /* Only check for tx acks if we have something queued. */
435 if (sp->tx_old != sp->tx_new)
436 sgiseeq_tx(dev, sp, hregs, sregs);
438 if ((TX_BUFFS_AVAIL(sp) > 0) && netif_queue_stopped(dev)) {
439 netif_wake_queue(dev);
441 spin_unlock(&sp->tx_lock);
443 return IRQ_HANDLED;
446 static int sgiseeq_open(struct net_device *dev)
448 struct sgiseeq_private *sp = netdev_priv(dev);
449 struct sgiseeq_regs *sregs = sp->sregs;
450 unsigned int irq = dev->irq;
451 int err;
453 if (request_irq(irq, sgiseeq_interrupt, 0, sgiseeqstr, dev)) {
454 printk(KERN_ERR "Seeq8003: Can't get irq %d\n", dev->irq);
455 err = -EAGAIN;
458 err = init_seeq(dev, sp, sregs);
459 if (err)
460 goto out_free_irq;
462 netif_start_queue(dev);
464 return 0;
466 out_free_irq:
467 free_irq(irq, dev);
469 return err;
472 static int sgiseeq_close(struct net_device *dev)
474 struct sgiseeq_private *sp = netdev_priv(dev);
475 struct sgiseeq_regs *sregs = sp->sregs;
476 unsigned int irq = dev->irq;
478 netif_stop_queue(dev);
480 /* Shutdown the Seeq. */
481 reset_hpc3_and_seeq(sp->hregs, sregs);
482 free_irq(irq, dev);
484 return 0;
487 static inline int sgiseeq_reset(struct net_device *dev)
489 struct sgiseeq_private *sp = netdev_priv(dev);
490 struct sgiseeq_regs *sregs = sp->sregs;
491 int err;
493 err = init_seeq(dev, sp, sregs);
494 if (err)
495 return err;
497 dev->trans_start = jiffies;
498 netif_wake_queue(dev);
500 return 0;
503 static int sgiseeq_start_xmit(struct sk_buff *skb, struct net_device *dev)
505 struct sgiseeq_private *sp = netdev_priv(dev);
506 struct hpc3_ethregs *hregs = sp->hregs;
507 unsigned long flags;
508 struct sgiseeq_tx_desc *td;
509 int skblen, len, entry;
511 spin_lock_irqsave(&sp->tx_lock, flags);
513 /* Setup... */
514 skblen = skb->len;
515 len = (skblen <= ETH_ZLEN) ? ETH_ZLEN : skblen;
516 dev->stats.tx_bytes += len;
517 entry = sp->tx_new;
518 td = &sp->tx_desc[entry];
520 /* Create entry. There are so many races with adding a new
521 * descriptor to the chain:
522 * 1) Assume that the HPC is off processing a DMA chain while
523 * we are changing all of the following.
524 * 2) Do no allow the HPC to look at a new descriptor until
525 * we have completely set up it's state. This means, do
526 * not clear HPCDMA_EOX in the current last descritptor
527 * until the one we are adding looks consistent and could
528 * be processes right now.
529 * 3) The tx interrupt code must notice when we've added a new
530 * entry and the HPC got to the end of the chain before we
531 * added this new entry and restarted it.
533 skb_copy_from_linear_data(skb, (char *)(long)td->buf_vaddr, skblen);
534 if (len != skblen)
535 memset((char *)(long)td->buf_vaddr + skb->len, 0, len-skblen);
536 td->tdma.cntinfo = (len & HPCDMA_BCNT) |
537 HPCDMA_XIU | HPCDMA_EOXP | HPCDMA_XIE | HPCDMA_EOX;
538 if (sp->tx_old != sp->tx_new) {
539 struct sgiseeq_tx_desc *backend;
541 backend = &sp->tx_desc[PREV_TX(sp->tx_new)];
542 backend->tdma.cntinfo &= ~HPCDMA_EOX;
544 sp->tx_new = NEXT_TX(sp->tx_new); /* Advance. */
546 /* Maybe kick the HPC back into motion. */
547 if (!(hregs->tx_ctrl & HPC3_ETXCTRL_ACTIVE))
548 kick_tx(&sp->tx_desc[sp->tx_old], hregs);
550 dev->trans_start = jiffies;
551 dev_kfree_skb(skb);
553 if (!TX_BUFFS_AVAIL(sp))
554 netif_stop_queue(dev);
555 spin_unlock_irqrestore(&sp->tx_lock, flags);
557 return 0;
560 static void timeout(struct net_device *dev)
562 printk(KERN_NOTICE "%s: transmit timed out, resetting\n", dev->name);
563 sgiseeq_reset(dev);
565 dev->trans_start = jiffies;
566 netif_wake_queue(dev);
569 static void sgiseeq_set_multicast(struct net_device *dev)
571 struct sgiseeq_private *sp = (struct sgiseeq_private *) dev->priv;
572 unsigned char oldmode = sp->mode;
574 if(dev->flags & IFF_PROMISC)
575 sp->mode = SEEQ_RCMD_RANY;
576 else if ((dev->flags & IFF_ALLMULTI) || dev->mc_count)
577 sp->mode = SEEQ_RCMD_RBMCAST;
578 else
579 sp->mode = SEEQ_RCMD_RBCAST;
581 /* XXX I know this sucks, but is there a better way to reprogram
582 * XXX the receiver? At least, this shouldn't happen too often.
585 if (oldmode != sp->mode)
586 sgiseeq_reset(dev);
589 static inline void setup_tx_ring(struct sgiseeq_tx_desc *buf, int nbufs)
591 int i = 0;
593 while (i < (nbufs - 1)) {
594 buf[i].tdma.pnext = CPHYSADDR(buf + i + 1);
595 buf[i].tdma.pbuf = 0;
596 i++;
598 buf[i].tdma.pnext = CPHYSADDR(buf);
601 static inline void setup_rx_ring(struct sgiseeq_rx_desc *buf, int nbufs)
603 int i = 0;
605 while (i < (nbufs - 1)) {
606 buf[i].rdma.pnext = CPHYSADDR(buf + i + 1);
607 buf[i].rdma.pbuf = 0;
608 i++;
610 buf[i].rdma.pbuf = 0;
611 buf[i].rdma.pnext = CPHYSADDR(buf);
614 #define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
616 static int __init sgiseeq_probe(struct platform_device *pdev)
618 struct sgiseeq_platform_data *pd = pdev->dev.platform_data;
619 struct hpc3_regs *hpcregs = pd->hpc;
620 struct sgiseeq_init_block *sr;
621 unsigned int irq = pd->irq;
622 struct sgiseeq_private *sp;
623 struct net_device *dev;
624 int err, i;
625 DECLARE_MAC_BUF(mac);
627 dev = alloc_etherdev(sizeof (struct sgiseeq_private));
628 if (!dev) {
629 printk(KERN_ERR "Sgiseeq: Etherdev alloc failed, aborting.\n");
630 err = -ENOMEM;
631 goto err_out;
634 platform_set_drvdata(pdev, dev);
635 sp = netdev_priv(dev);
637 /* Make private data page aligned */
638 sr = dma_alloc_coherent(&pdev->dev, sizeof(*sp->srings),
639 &sp->srings_dma, GFP_KERNEL);
640 if (!sr) {
641 printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n");
642 err = -ENOMEM;
643 goto err_out_free_dev;
645 sp->srings = sr;
646 sp->rx_desc = sp->srings->rxvector;
647 sp->tx_desc = sp->srings->txvector;
649 /* A couple calculations now, saves many cycles later. */
650 setup_rx_ring(sp->rx_desc, SEEQ_RX_BUFFERS);
651 setup_tx_ring(sp->tx_desc, SEEQ_TX_BUFFERS);
653 memcpy(dev->dev_addr, pd->mac, ETH_ALEN);
655 #ifdef DEBUG
656 gpriv = sp;
657 gdev = dev;
658 #endif
659 sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0];
660 sp->hregs = &hpcregs->ethregs;
661 sp->name = sgiseeqstr;
662 sp->mode = SEEQ_RCMD_RBCAST;
664 /* Setup PIO and DMA transfer timing */
665 sp->hregs->pconfig = 0x161;
666 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
667 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
669 /* Setup PIO and DMA transfer timing */
670 sp->hregs->pconfig = 0x161;
671 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
672 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
674 /* Reset the chip. */
675 hpc3_eth_reset(sp->hregs);
677 sp->is_edlc = !(sp->sregs->rw.rregs.collision_tx[0] & 0xff);
678 if (sp->is_edlc)
679 sp->control = SEEQ_CTRL_XCNT | SEEQ_CTRL_ACCNT |
680 SEEQ_CTRL_SFLAG | SEEQ_CTRL_ESHORT |
681 SEEQ_CTRL_ENCARR;
683 dev->open = sgiseeq_open;
684 dev->stop = sgiseeq_close;
685 dev->hard_start_xmit = sgiseeq_start_xmit;
686 dev->tx_timeout = timeout;
687 dev->watchdog_timeo = (200 * HZ) / 1000;
688 dev->set_multicast_list = sgiseeq_set_multicast;
689 dev->set_mac_address = sgiseeq_set_mac_address;
690 dev->irq = irq;
692 if (register_netdev(dev)) {
693 printk(KERN_ERR "Sgiseeq: Cannot register net device, "
694 "aborting.\n");
695 err = -ENODEV;
696 goto err_out_free_page;
699 printk(KERN_INFO "%s: %s %s\n",
700 dev->name, sgiseeqstr, print_mac(mac, dev->dev_addr));
702 return 0;
704 err_out_free_page:
705 free_page((unsigned long) sp->srings);
706 err_out_free_dev:
707 kfree(dev);
709 err_out:
710 return err;
713 static int __exit sgiseeq_remove(struct platform_device *pdev)
715 struct net_device *dev = platform_get_drvdata(pdev);
716 struct sgiseeq_private *sp = netdev_priv(dev);
718 unregister_netdev(dev);
719 dma_free_coherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
720 sp->srings_dma);
721 free_netdev(dev);
722 platform_set_drvdata(pdev, NULL);
724 return 0;
727 static struct platform_driver sgiseeq_driver = {
728 .probe = sgiseeq_probe,
729 .remove = __devexit_p(sgiseeq_remove),
730 .driver = {
731 .name = "sgiseeq"
735 static int __init sgiseeq_module_init(void)
737 if (platform_driver_register(&sgiseeq_driver)) {
738 printk(KERN_ERR "Driver registration failed\n");
739 return -ENODEV;
742 return 0;
745 static void __exit sgiseeq_module_exit(void)
747 platform_driver_unregister(&sgiseeq_driver);
750 module_init(sgiseeq_module_init);
751 module_exit(sgiseeq_module_exit);
753 MODULE_DESCRIPTION("SGI Seeq 8003 driver");
754 MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
755 MODULE_LICENSE("GPL");