2 * sgiseeq.c: Seeq8003 ethernet driver for SGI machines.
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
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/etherdevice.h>
20 #include <linux/skbuff.h>
22 #include <asm/sgi/hpc3.h>
23 #include <asm/sgi/ip22.h>
27 static char *sgiseeqstr
= "SGI Seeq8003";
30 * If you want speed, you do something silly, it always has worked for me. So,
31 * with that in mind, I've decided to make this driver look completely like a
32 * stupid Lance from a driver architecture perspective. Only difference is that
33 * here our "ring buffer" looks and acts like a real Lance one does but is
34 * layed out like how the HPC DMA and the Seeq want it to. You'd be surprised
35 * how a stupid idea like this can pay off in performance, not to mention
36 * making this driver 2,000 times easier to write. ;-)
39 /* Tune these if we tend to run out often etc. */
40 #define SEEQ_RX_BUFFERS 16
41 #define SEEQ_TX_BUFFERS 16
43 #define PKT_BUF_SZ 1584
45 #define NEXT_RX(i) (((i) + 1) & (SEEQ_RX_BUFFERS - 1))
46 #define NEXT_TX(i) (((i) + 1) & (SEEQ_TX_BUFFERS - 1))
47 #define PREV_RX(i) (((i) - 1) & (SEEQ_RX_BUFFERS - 1))
48 #define PREV_TX(i) (((i) - 1) & (SEEQ_TX_BUFFERS - 1))
50 #define TX_BUFFS_AVAIL(sp) ((sp->tx_old <= sp->tx_new) ? \
51 sp->tx_old + (SEEQ_TX_BUFFERS - 1) - sp->tx_new : \
52 sp->tx_old - sp->tx_new - 1)
54 struct sgiseeq_rx_desc
{
55 volatile struct hpc_dma_desc rdma
;
56 volatile signed int buf_vaddr
;
59 struct sgiseeq_tx_desc
{
60 volatile struct hpc_dma_desc tdma
;
61 volatile signed int buf_vaddr
;
65 * Warning: This structure is layed out in a certain way because HPC dma
66 * descriptors must be 8-byte aligned. So don't touch this without
69 struct sgiseeq_init_block
{ /* Note the name ;-) */
70 struct sgiseeq_rx_desc rxvector
[SEEQ_RX_BUFFERS
];
71 struct sgiseeq_tx_desc txvector
[SEEQ_TX_BUFFERS
];
74 struct sgiseeq_private
{
75 struct sgiseeq_init_block
*srings
;
77 /* Ptrs to the descriptors in uncached space. */
78 struct sgiseeq_rx_desc
*rx_desc
;
79 struct sgiseeq_tx_desc
*tx_desc
;
82 struct hpc3_ethregs
*hregs
;
83 struct sgiseeq_regs
*sregs
;
85 /* Ring entry counters. */
86 unsigned int rx_new
, tx_new
;
87 unsigned int rx_old
, tx_old
;
90 unsigned char control
;
93 struct net_device_stats stats
;
95 struct net_device
*next_module
;
99 /* A list of all installed seeq devices, for removing the driver module. */
100 static struct net_device
*root_sgiseeq_dev
;
102 static inline void hpc3_eth_reset(struct hpc3_ethregs
*hregs
)
104 hregs
->reset
= HPC3_ERST_CRESET
| HPC3_ERST_CLRIRQ
;
109 static inline void reset_hpc3_and_seeq(struct hpc3_ethregs
*hregs
,
110 struct sgiseeq_regs
*sregs
)
112 hregs
->rx_ctrl
= hregs
->tx_ctrl
= 0;
113 hpc3_eth_reset(hregs
);
116 #define RSTAT_GO_BITS (SEEQ_RCMD_IGOOD | SEEQ_RCMD_IEOF | SEEQ_RCMD_ISHORT | \
117 SEEQ_RCMD_IDRIB | SEEQ_RCMD_ICRC)
119 static inline void seeq_go(struct sgiseeq_private
*sp
,
120 struct hpc3_ethregs
*hregs
,
121 struct sgiseeq_regs
*sregs
)
123 sregs
->rstat
= sp
->mode
| RSTAT_GO_BITS
;
124 hregs
->rx_ctrl
= HPC3_ERXCTRL_ACTIVE
;
127 static inline void __sgiseeq_set_mac_address(struct net_device
*dev
)
129 struct sgiseeq_private
*sp
= netdev_priv(dev
);
130 struct sgiseeq_regs
*sregs
= sp
->sregs
;
133 sregs
->tstat
= SEEQ_TCMD_RB0
;
134 for (i
= 0; i
< 6; i
++)
135 sregs
->rw
.eth_addr
[i
] = dev
->dev_addr
[i
];
138 static int sgiseeq_set_mac_address(struct net_device
*dev
, void *addr
)
140 struct sgiseeq_private
*sp
= netdev_priv(dev
);
141 struct sockaddr
*sa
= addr
;
143 memcpy(dev
->dev_addr
, sa
->sa_data
, dev
->addr_len
);
145 spin_lock_irq(&sp
->tx_lock
);
146 __sgiseeq_set_mac_address(dev
);
147 spin_unlock_irq(&sp
->tx_lock
);
152 #define TCNTINFO_INIT (HPCDMA_EOX | HPCDMA_ETXD)
153 #define RCNTCFG_INIT (HPCDMA_OWN | HPCDMA_EORP | HPCDMA_XIE)
154 #define RCNTINFO_INIT (RCNTCFG_INIT | (PKT_BUF_SZ & HPCDMA_BCNT))
156 static int seeq_init_ring(struct net_device
*dev
)
158 struct sgiseeq_private
*sp
= netdev_priv(dev
);
161 netif_stop_queue(dev
);
162 sp
->rx_new
= sp
->tx_new
= 0;
163 sp
->rx_old
= sp
->tx_old
= 0;
165 __sgiseeq_set_mac_address(dev
);
168 for(i
= 0; i
< SEEQ_TX_BUFFERS
; i
++) {
169 if (!sp
->tx_desc
[i
].tdma
.pbuf
) {
170 unsigned long buffer
;
172 buffer
= (unsigned long) kmalloc(PKT_BUF_SZ
, GFP_KERNEL
);
175 sp
->tx_desc
[i
].buf_vaddr
= CKSEG1ADDR(buffer
);
176 sp
->tx_desc
[i
].tdma
.pbuf
= CPHYSADDR(buffer
);
178 sp
->tx_desc
[i
].tdma
.cntinfo
= TCNTINFO_INIT
;
181 /* And now the rx ring. */
182 for (i
= 0; i
< SEEQ_RX_BUFFERS
; i
++) {
183 if (!sp
->rx_desc
[i
].rdma
.pbuf
) {
184 unsigned long buffer
;
186 buffer
= (unsigned long) kmalloc(PKT_BUF_SZ
, GFP_KERNEL
);
189 sp
->rx_desc
[i
].buf_vaddr
= CKSEG1ADDR(buffer
);
190 sp
->rx_desc
[i
].rdma
.pbuf
= CPHYSADDR(buffer
);
192 sp
->rx_desc
[i
].rdma
.cntinfo
= RCNTINFO_INIT
;
194 sp
->rx_desc
[i
- 1].rdma
.cntinfo
|= HPCDMA_EOR
;
199 static struct sgiseeq_private
*gpriv
;
200 static struct net_device
*gdev
;
202 static void sgiseeq_dump_rings(void)
205 struct sgiseeq_rx_desc
*r
= gpriv
->rx_desc
;
206 struct sgiseeq_tx_desc
*t
= gpriv
->tx_desc
;
207 struct hpc3_ethregs
*hregs
= gpriv
->hregs
;
213 printk("RING DUMP:\n");
214 for (i
= 0; i
< SEEQ_RX_BUFFERS
; i
++) {
215 printk("RX [%d]: @(%p) [%08x,%08x,%08x] ",
216 i
, (&r
[i
]), r
[i
].rdma
.pbuf
, r
[i
].rdma
.cntinfo
,
219 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
220 i
, (&r
[i
]), r
[i
].rdma
.pbuf
, r
[i
].rdma
.cntinfo
,
223 for (i
= 0; i
< SEEQ_TX_BUFFERS
; i
++) {
224 printk("TX [%d]: @(%p) [%08x,%08x,%08x] ",
225 i
, (&t
[i
]), t
[i
].tdma
.pbuf
, t
[i
].tdma
.cntinfo
,
228 printk("-- [%d]: @(%p) [%08x,%08x,%08x]\n",
229 i
, (&t
[i
]), t
[i
].tdma
.pbuf
, t
[i
].tdma
.cntinfo
,
232 printk("INFO: [rx_new = %d rx_old=%d] [tx_new = %d tx_old = %d]\n",
233 gpriv
->rx_new
, gpriv
->rx_old
, gpriv
->tx_new
, gpriv
->tx_old
);
234 printk("RREGS: rx_cbptr[%08x] rx_ndptr[%08x] rx_ctrl[%08x]\n",
235 hregs
->rx_cbptr
, hregs
->rx_ndptr
, hregs
->rx_ctrl
);
236 printk("TREGS: tx_cbptr[%08x] tx_ndptr[%08x] tx_ctrl[%08x]\n",
237 hregs
->tx_cbptr
, hregs
->tx_ndptr
, hregs
->tx_ctrl
);
241 #define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
242 #define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
244 static int init_seeq(struct net_device
*dev
, struct sgiseeq_private
*sp
,
245 struct sgiseeq_regs
*sregs
)
247 struct hpc3_ethregs
*hregs
= sp
->hregs
;
250 reset_hpc3_and_seeq(hregs
, sregs
);
251 err
= seeq_init_ring(dev
);
255 /* Setup to field the proper interrupt types. */
257 sregs
->tstat
= TSTAT_INIT_EDLC
;
258 sregs
->rw
.wregs
.control
= sp
->control
;
259 sregs
->rw
.wregs
.frame_gap
= 0;
261 sregs
->tstat
= TSTAT_INIT_SEEQ
;
264 hregs
->rx_ndptr
= CPHYSADDR(sp
->rx_desc
);
265 hregs
->tx_ndptr
= CPHYSADDR(sp
->tx_desc
);
267 seeq_go(sp
, hregs
, sregs
);
271 static inline void record_rx_errors(struct sgiseeq_private
*sp
,
272 unsigned char status
)
274 if (status
& SEEQ_RSTAT_OVERF
||
275 status
& SEEQ_RSTAT_SFRAME
)
276 sp
->stats
.rx_over_errors
++;
277 if (status
& SEEQ_RSTAT_CERROR
)
278 sp
->stats
.rx_crc_errors
++;
279 if (status
& SEEQ_RSTAT_DERROR
)
280 sp
->stats
.rx_frame_errors
++;
281 if (status
& SEEQ_RSTAT_REOF
)
282 sp
->stats
.rx_errors
++;
285 static inline void rx_maybe_restart(struct sgiseeq_private
*sp
,
286 struct hpc3_ethregs
*hregs
,
287 struct sgiseeq_regs
*sregs
)
289 if (!(hregs
->rx_ctrl
& HPC3_ERXCTRL_ACTIVE
)) {
290 hregs
->rx_ndptr
= CPHYSADDR(sp
->rx_desc
+ sp
->rx_new
);
291 seeq_go(sp
, hregs
, sregs
);
295 #define for_each_rx(rd, sp) for((rd) = &(sp)->rx_desc[(sp)->rx_new]; \
296 !((rd)->rdma.cntinfo & HPCDMA_OWN); \
297 (rd) = &(sp)->rx_desc[(sp)->rx_new])
299 static inline void sgiseeq_rx(struct net_device
*dev
, struct sgiseeq_private
*sp
,
300 struct hpc3_ethregs
*hregs
,
301 struct sgiseeq_regs
*sregs
)
303 struct sgiseeq_rx_desc
*rd
;
304 struct sk_buff
*skb
= NULL
;
305 unsigned char pkt_status
;
306 unsigned char *pkt_pointer
= NULL
;
308 unsigned int orig_end
= PREV_RX(sp
->rx_new
);
310 /* Service every received packet. */
311 for_each_rx(rd
, sp
) {
312 len
= PKT_BUF_SZ
- (rd
->rdma
.cntinfo
& HPCDMA_BCNT
) - 3;
313 pkt_pointer
= (unsigned char *)(long)rd
->buf_vaddr
;
314 pkt_status
= pkt_pointer
[len
+ 2];
316 if (pkt_status
& SEEQ_RSTAT_FIG
) {
318 skb
= dev_alloc_skb(len
+ 2);
324 /* Copy out of kseg1 to avoid silly cache flush. */
325 eth_copy_and_sum(skb
, pkt_pointer
+ 2, len
, 0);
326 skb
->protocol
= eth_type_trans(skb
, dev
);
328 /* We don't want to receive our own packets */
329 if (memcmp(eth_hdr(skb
)->h_source
, dev
->dev_addr
, ETH_ALEN
)) {
331 dev
->last_rx
= jiffies
;
332 sp
->stats
.rx_packets
++;
333 sp
->stats
.rx_bytes
+= len
;
335 /* Silently drop my own packets */
336 dev_kfree_skb_irq(skb
);
339 printk (KERN_NOTICE
"%s: Memory squeeze, deferring packet.\n",
341 sp
->stats
.rx_dropped
++;
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
->rx_desc
[orig_end
].rdma
.cntinfo
&= ~(HPCDMA_EOR
);
352 sp
->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
)
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
374 while ((td
->tdma
.cntinfo
& (HPCDMA_XIU
| HPCDMA_ETXD
)) ==
375 (HPCDMA_XIU
| HPCDMA_ETXD
))
376 td
= (struct sgiseeq_tx_desc
*)(long) CKSEG1ADDR(td
->tdma
.pnext
);
377 if (td
->tdma
.cntinfo
& HPCDMA_XIU
) {
378 hregs
->tx_ndptr
= CPHYSADDR(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
;
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
++;
404 for (j
= sp
->tx_old
; j
!= sp
->tx_new
; j
= NEXT_TX(j
)) {
405 td
= &sp
->tx_desc
[j
];
407 if (!(td
->tdma
.cntinfo
& (HPCDMA_XIU
)))
409 if (!(td
->tdma
.cntinfo
& (HPCDMA_ETXD
))) {
410 if (!(status
& HPC3_ETXCTRL_ACTIVE
)) {
411 hregs
->tx_ndptr
= CPHYSADDR(td
);
412 hregs
->tx_ctrl
= HPC3_ETXCTRL_ACTIVE
;
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
)
425 struct net_device
*dev
= (struct net_device
*) dev_id
;
426 struct sgiseeq_private
*sp
= netdev_priv(dev
);
427 struct hpc3_ethregs
*hregs
= sp
->hregs
;
428 struct sgiseeq_regs
*sregs
= sp
->sregs
;
430 spin_lock(&sp
->tx_lock
);
432 /* Ack the IRQ and set software state. */
433 hregs
->reset
= HPC3_ERST_CLRIRQ
;
435 /* Always check for received packets. */
436 sgiseeq_rx(dev
, sp
, hregs
, sregs
);
438 /* Only check for tx acks if we have something queued. */
439 if (sp
->tx_old
!= sp
->tx_new
)
440 sgiseeq_tx(dev
, sp
, hregs
, sregs
);
442 if ((TX_BUFFS_AVAIL(sp
) > 0) && netif_queue_stopped(dev
)) {
443 netif_wake_queue(dev
);
445 spin_unlock(&sp
->tx_lock
);
450 static int sgiseeq_open(struct net_device
*dev
)
452 struct sgiseeq_private
*sp
= netdev_priv(dev
);
453 struct sgiseeq_regs
*sregs
= sp
->sregs
;
454 unsigned int irq
= dev
->irq
;
457 if (request_irq(irq
, sgiseeq_interrupt
, 0, sgiseeqstr
, dev
)) {
458 printk(KERN_ERR
"Seeq8003: Can't get irq %d\n", dev
->irq
);
462 err
= init_seeq(dev
, sp
, sregs
);
466 netif_start_queue(dev
);
476 static int sgiseeq_close(struct net_device
*dev
)
478 struct sgiseeq_private
*sp
= netdev_priv(dev
);
479 struct sgiseeq_regs
*sregs
= sp
->sregs
;
480 unsigned int irq
= dev
->irq
;
482 netif_stop_queue(dev
);
484 /* Shutdown the Seeq. */
485 reset_hpc3_and_seeq(sp
->hregs
, sregs
);
491 static inline int sgiseeq_reset(struct net_device
*dev
)
493 struct sgiseeq_private
*sp
= netdev_priv(dev
);
494 struct sgiseeq_regs
*sregs
= sp
->sregs
;
497 err
= init_seeq(dev
, sp
, sregs
);
501 dev
->trans_start
= jiffies
;
502 netif_wake_queue(dev
);
507 static int sgiseeq_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
509 struct sgiseeq_private
*sp
= netdev_priv(dev
);
510 struct hpc3_ethregs
*hregs
= sp
->hregs
;
512 struct sgiseeq_tx_desc
*td
;
513 int skblen
, len
, entry
;
515 spin_lock_irqsave(&sp
->tx_lock
, flags
);
519 len
= (skblen
<= ETH_ZLEN
) ? ETH_ZLEN
: skblen
;
520 sp
->stats
.tx_bytes
+= len
;
522 td
= &sp
->tx_desc
[entry
];
524 /* Create entry. There are so many races with adding a new
525 * descriptor to the chain:
526 * 1) Assume that the HPC is off processing a DMA chain while
527 * we are changing all of the following.
528 * 2) Do no allow the HPC to look at a new descriptor until
529 * we have completely set up it's state. This means, do
530 * not clear HPCDMA_EOX in the current last descritptor
531 * until the one we are adding looks consistent and could
532 * be processes right now.
533 * 3) The tx interrupt code must notice when we've added a new
534 * entry and the HPC got to the end of the chain before we
535 * added this new entry and restarted it.
537 skb_copy_from_linear_data(skb
, (char *)(long)td
->buf_vaddr
, skblen
);
539 memset((char *)(long)td
->buf_vaddr
+ skb
->len
, 0, len
-skblen
);
540 td
->tdma
.cntinfo
= (len
& HPCDMA_BCNT
) |
541 HPCDMA_XIU
| HPCDMA_EOXP
| HPCDMA_XIE
| HPCDMA_EOX
;
542 if (sp
->tx_old
!= sp
->tx_new
) {
543 struct sgiseeq_tx_desc
*backend
;
545 backend
= &sp
->tx_desc
[PREV_TX(sp
->tx_new
)];
546 backend
->tdma
.cntinfo
&= ~HPCDMA_EOX
;
548 sp
->tx_new
= NEXT_TX(sp
->tx_new
); /* Advance. */
550 /* Maybe kick the HPC back into motion. */
551 if (!(hregs
->tx_ctrl
& HPC3_ETXCTRL_ACTIVE
))
552 kick_tx(&sp
->tx_desc
[sp
->tx_old
], hregs
);
554 dev
->trans_start
= jiffies
;
557 if (!TX_BUFFS_AVAIL(sp
))
558 netif_stop_queue(dev
);
559 spin_unlock_irqrestore(&sp
->tx_lock
, flags
);
564 static void timeout(struct net_device
*dev
)
566 printk(KERN_NOTICE
"%s: transmit timed out, resetting\n", dev
->name
);
569 dev
->trans_start
= jiffies
;
570 netif_wake_queue(dev
);
573 static struct net_device_stats
*sgiseeq_get_stats(struct net_device
*dev
)
575 struct sgiseeq_private
*sp
= netdev_priv(dev
);
580 static void sgiseeq_set_multicast(struct net_device
*dev
)
582 struct sgiseeq_private
*sp
= (struct sgiseeq_private
*) dev
->priv
;
583 unsigned char oldmode
= sp
->mode
;
585 if(dev
->flags
& IFF_PROMISC
)
586 sp
->mode
= SEEQ_RCMD_RANY
;
587 else if ((dev
->flags
& IFF_ALLMULTI
) || dev
->mc_count
)
588 sp
->mode
= SEEQ_RCMD_RBMCAST
;
590 sp
->mode
= SEEQ_RCMD_RBCAST
;
592 /* XXX I know this sucks, but is there a better way to reprogram
593 * XXX the receiver? At least, this shouldn't happen too often.
596 if (oldmode
!= sp
->mode
)
600 static inline void setup_tx_ring(struct sgiseeq_tx_desc
*buf
, int nbufs
)
604 while (i
< (nbufs
- 1)) {
605 buf
[i
].tdma
.pnext
= CPHYSADDR(buf
+ i
+ 1);
606 buf
[i
].tdma
.pbuf
= 0;
609 buf
[i
].tdma
.pnext
= CPHYSADDR(buf
);
612 static inline void setup_rx_ring(struct sgiseeq_rx_desc
*buf
, int nbufs
)
616 while (i
< (nbufs
- 1)) {
617 buf
[i
].rdma
.pnext
= CPHYSADDR(buf
+ i
+ 1);
618 buf
[i
].rdma
.pbuf
= 0;
621 buf
[i
].rdma
.pbuf
= 0;
622 buf
[i
].rdma
.pnext
= CPHYSADDR(buf
);
625 #define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
627 static int sgiseeq_init(struct hpc3_regs
* hpcregs
, int irq
)
629 struct sgiseeq_init_block
*sr
;
630 struct sgiseeq_private
*sp
;
631 struct net_device
*dev
;
634 dev
= alloc_etherdev(sizeof (struct sgiseeq_private
));
636 printk(KERN_ERR
"Sgiseeq: Etherdev alloc failed, aborting.\n");
640 sp
= netdev_priv(dev
);
642 /* Make private data page aligned */
643 sr
= (struct sgiseeq_init_block
*) get_zeroed_page(GFP_KERNEL
);
645 printk(KERN_ERR
"Sgiseeq: Page alloc failed, aborting.\n");
647 goto err_out_free_dev
;
651 #define EADDR_NVOFS 250
652 for (i
= 0; i
< 3; i
++) {
653 unsigned short tmp
= ip22_nvram_read(EADDR_NVOFS
/ 2 + i
);
655 dev
->dev_addr
[2 * i
] = tmp
>> 8;
656 dev
->dev_addr
[2 * i
+ 1] = tmp
& 0xff;
663 sp
->sregs
= (struct sgiseeq_regs
*) &hpcregs
->eth_ext
[0];
664 sp
->hregs
= &hpcregs
->ethregs
;
665 sp
->name
= sgiseeqstr
;
666 sp
->mode
= SEEQ_RCMD_RBCAST
;
668 sp
->rx_desc
= (struct sgiseeq_rx_desc
*)
669 CKSEG1ADDR(ALIGNED(&sp
->srings
->rxvector
[0]));
670 dma_cache_wback_inv((unsigned long)&sp
->srings
->rxvector
,
671 sizeof(sp
->srings
->rxvector
));
672 sp
->tx_desc
= (struct sgiseeq_tx_desc
*)
673 CKSEG1ADDR(ALIGNED(&sp
->srings
->txvector
[0]));
674 dma_cache_wback_inv((unsigned long)&sp
->srings
->txvector
,
675 sizeof(sp
->srings
->txvector
));
677 /* A couple calculations now, saves many cycles later. */
678 setup_rx_ring(sp
->rx_desc
, SEEQ_RX_BUFFERS
);
679 setup_tx_ring(sp
->tx_desc
, SEEQ_TX_BUFFERS
);
681 /* Setup PIO and DMA transfer timing */
682 sp
->hregs
->pconfig
= 0x161;
683 sp
->hregs
->dconfig
= HPC3_EDCFG_FIRQ
| HPC3_EDCFG_FEOP
|
684 HPC3_EDCFG_FRXDC
| HPC3_EDCFG_PTO
| 0x026;
686 /* Reset the chip. */
687 hpc3_eth_reset(sp
->hregs
);
689 sp
->is_edlc
= !(sp
->sregs
->rw
.rregs
.collision_tx
[0] & 0xff);
691 sp
->control
= SEEQ_CTRL_XCNT
| SEEQ_CTRL_ACCNT
|
692 SEEQ_CTRL_SFLAG
| SEEQ_CTRL_ESHORT
|
695 dev
->open
= sgiseeq_open
;
696 dev
->stop
= sgiseeq_close
;
697 dev
->hard_start_xmit
= sgiseeq_start_xmit
;
698 dev
->tx_timeout
= timeout
;
699 dev
->watchdog_timeo
= (200 * HZ
) / 1000;
700 dev
->get_stats
= sgiseeq_get_stats
;
701 dev
->set_multicast_list
= sgiseeq_set_multicast
;
702 dev
->set_mac_address
= sgiseeq_set_mac_address
;
705 if (register_netdev(dev
)) {
706 printk(KERN_ERR
"Sgiseeq: Cannot register net device, "
709 goto err_out_free_page
;
712 printk(KERN_INFO
"%s: %s ", dev
->name
, sgiseeqstr
);
713 for (i
= 0; i
< 6; i
++)
714 printk("%2.2x%c", dev
->dev_addr
[i
], i
== 5 ? '\n' : ':');
716 sp
->next_module
= root_sgiseeq_dev
;
717 root_sgiseeq_dev
= dev
;
722 free_page((unsigned long) sp
->srings
);
730 static int __init
sgiseeq_probe(void)
732 /* On board adapter on 1st HPC is always present */
733 return sgiseeq_init(hpc3c0
, SGI_ENET_IRQ
);
736 static void __exit
sgiseeq_exit(void)
738 struct net_device
*next
, *dev
;
739 struct sgiseeq_private
*sp
;
741 for (dev
= root_sgiseeq_dev
; dev
; dev
= next
) {
742 sp
= (struct sgiseeq_private
*) netdev_priv(dev
);
743 next
= sp
->next_module
;
744 unregister_netdev(dev
);
745 free_page((unsigned long) sp
->srings
);
750 module_init(sgiseeq_probe
);
751 module_exit(sgiseeq_exit
);
753 MODULE_DESCRIPTION("SGI Seeq 8003 driver");
754 MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
755 MODULE_LICENSE("GPL");