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