2 * meth.c -- O2 Builtin 10/100 Ethernet driver
4 * Copyright (C) 2001 Ilya Volynets
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 #include <linux/module.h>
12 #include <linux/init.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h> /* printk() */
16 #include <linux/delay.h>
17 #include <linux/slab.h>
18 #include <linux/errno.h> /* error codes */
19 #include <linux/types.h> /* size_t */
20 #include <linux/interrupt.h> /* mark_bh */
21 #include <linux/pci.h>
24 #include <linux/netdevice.h> /* struct device, and other headers */
25 #include <linux/etherdevice.h> /* eth_type_trans */
26 #include <linux/ip.h> /* struct iphdr */
27 #include <linux/tcp.h> /* struct tcphdr */
28 #include <linux/skbuff.h>
29 #include <linux/mii.h> /*MII definitions */
31 #include <asm/ip32/crime.h>
32 #include <asm/ip32/mace.h>
33 #include <asm/ip32/ip32_ints.h>
37 #include <linux/in6.h>
38 #include <asm/checksum.h>
45 #define DPRINTK(str,args...) printk (KERN_DEBUG "meth(%ld): %s: " str, jiffies, __FUNCTION__ , ## args)
46 #define MFE_RX_DEBUG 2
48 #define DPRINTK(str,args...)
49 #define MFE_RX_DEBUG 0
53 static const char *meth_str
="SGI O2 Fast Ethernet";
54 MODULE_AUTHOR("Ilya Volynets <ilya@theIlya.com>");
55 MODULE_DESCRIPTION("SGI O2 Builtin Fast Ethernet driver");
57 #define HAVE_TX_TIMEOUT
58 /* The maximum time waited (in jiffies) before assuming a Tx failed. (400ms) */
59 #define TX_TIMEOUT (400*HZ/1000)
61 #ifdef HAVE_TX_TIMEOUT
62 static int timeout
= TX_TIMEOUT
;
63 MODULE_PARM(timeout
, "i");
67 * This structure is private to each device. It is used to pass
68 * packets in and out, so there is place for a packet
71 typedef struct meth_private
{
72 struct net_device_stats stats
;
73 volatile struct meth_regs
*regs
;
74 u64 mode
; /* in-memory copy of MAC control register */
75 int phy_addr
; /* address of phy, used by mdio_* functions, initialized in mdio_probe*/
77 dma_addr_t tx_ring_dma
;
79 struct sk_buff
*tx_skbs
[TX_RING_ENTRIES
];
80 dma_addr_t tx_skb_dmas
[TX_RING_ENTRIES
];
84 rx_packet
*rx_ring
[RX_RING_ENTRIES
];
85 dma_addr_t rx_ring_dmas
[RX_RING_ENTRIES
];
91 void meth_tx_timeout (struct net_device
*dev
);
92 irqreturn_t
meth_interrupt(int irq
, void *dev_id
, struct pt_regs
*pregs
);
94 /* global, initialized in ip32-setup.c */
95 char o2meth_eaddr
[8]={0,0,0,0,0,0,0,0};
97 static inline void load_eaddr(struct net_device
*dev
,
98 volatile struct meth_regs
*regs
)
101 DPRINTK("Loading MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
102 (int)o2meth_eaddr
[0]&0xFF,(int)o2meth_eaddr
[1]&0xFF,(int)o2meth_eaddr
[2]&0xFF,
103 (int)o2meth_eaddr
[3]&0xFF,(int)o2meth_eaddr
[4]&0xFF,(int)o2meth_eaddr
[5]&0xFF);
105 dev
->dev_addr
[i
]=o2meth_eaddr
[i
];
106 regs
->mac_addr
=(*(u64
*)o2meth_eaddr
)>>16;
110 *Waits for BUSY status of mdio bus to clear
112 #define WAIT_FOR_PHY(___regs, ___rval) \
113 while((___rval=___regs->phy_data)&MDIO_BUSY){ \
116 /*read phy register, return value read */
117 static int mdio_read(meth_private
*priv
,int phyreg
)
119 volatile meth_regs
* regs
=priv
->regs
;
121 WAIT_FOR_PHY(regs
,rval
);
122 regs
->phy_registers
=(priv
->phy_addr
<<5)|(phyreg
&0x1f);
124 regs
->phy_trans_go
=1;
126 WAIT_FOR_PHY(regs
,rval
);
127 return rval
&MDIO_DATA_MASK
;
130 static int mdio_probe(meth_private
*priv
)
133 DPRINTK("Detecting PHY kind\n");
134 /* check if phy is detected already */
135 if(priv
->phy_addr
>=0&&priv
->phy_addr
<32)
137 spin_lock(&priv
->meth_lock
);
139 priv
->phy_addr
=(char)i
;
140 p2
=mdio_read(priv
,2);
142 p3
=mdio_read(priv
,3);
143 switch ((p2
<<12)|(p3
>>4)){
145 DPRINTK("PHY is QS6612X\n");
148 DPRINTK("PHY is ICS1889\n");
151 DPRINTK("PHY is ICS1890\n");
154 DPRINTK("PHY is DP83840\n");
158 if(p2
!=0xffff&&p2
!=0x0000){
159 DPRINTK("PHY code: %x\n",(p2
<<12)|(p3
>>4));
163 spin_unlock(&priv
->meth_lock
);
164 if(priv
->phy_addr
<32) {
167 DPRINTK("Oopsie! PHY is not known!\n");
172 static void meth_check_link(struct net_device
*dev
)
174 struct meth_private
*priv
= (struct meth_private
*) dev
->priv
;
175 int mii_partner
= mdio_read(priv
, 5);
176 int mii_advertising
= mdio_read(priv
, 4);
177 int negotiated
= mii_advertising
& mii_partner
;
180 if (mii_partner
== 0xffff)
183 duplex
= ((negotiated
& 0x0100) || (negotiated
& 0x01C0) == 0x0040)?METH_PHY_FDX
:0;
184 speed
= (negotiated
& 0x0380)?METH_100MBIT
:0;
186 if ((priv
->mode
& METH_PHY_FDX
) ^ duplex
)
188 DPRINTK("Setting %s-duplex\n", duplex
? "full" : "half");
190 priv
->mode
|= METH_PHY_FDX
;
192 priv
->mode
&= ~METH_PHY_FDX
;
193 priv
->regs
->mac_ctrl
= priv
->mode
;
196 if ((priv
->mode
& METH_100MBIT
) ^ speed
)
198 DPRINTK("Setting %dMbs mode\n", speed
? 100 : 10);
200 priv
->mode
|= METH_100MBIT
;
202 priv
->mode
&= ~METH_100MBIT
;
203 priv
->regs
->mac_ctrl
= priv
->mode
;
208 static int meth_init_tx_ring(meth_private
*priv
)
211 DPRINTK("Initializing TX ring\n");
212 priv
->tx_ring
= (tx_packet
*) pci_alloc_consistent(NULL
,TX_RING_BUFFER_SIZE
,&(priv
->tx_ring_dma
));
215 memset(priv
->tx_ring
, 0, TX_RING_BUFFER_SIZE
);
216 priv
->tx_count
= priv
->tx_read
= priv
->tx_write
= 0;
217 priv
->regs
->tx_ring_base
= priv
->tx_ring_dma
;
218 priv
->free_space
= TX_RING_ENTRIES
;
219 /* Now init skb save area */
220 memset(priv
->tx_skbs
,0,sizeof(priv
->tx_skbs
));
221 memset(priv
->tx_skb_dmas
,0,sizeof(priv
->tx_skb_dmas
));
222 DPRINTK("Done with TX ring init\n");
226 static int meth_init_rx_ring(meth_private
*priv
)
229 for(i
=0;i
<RX_RING_ENTRIES
;i
++){
230 priv
->rx_ring
[i
]=(rx_packet
*)pci_alloc_consistent(NULL
,METH_RX_BUFF_SIZE
,&(priv
->rx_ring_dmas
[i
]));
231 /* I'll need to re-sync it after each RX */
232 priv
->regs
->rx_fifo
=priv
->rx_ring_dmas
[i
];
235 DPRINTK("Done with RX ring\n");
238 static void meth_free_tx_ring(meth_private
*priv
)
242 /* Remove any pending skb */
243 for (i
= 0; i
< TX_RING_ENTRIES
; i
++) {
244 if (priv
->tx_skbs
[i
])
245 dev_kfree_skb(priv
->tx_skbs
[i
]);
246 priv
->tx_skbs
[i
] = NULL
;
248 pci_free_consistent(NULL
,
253 static void meth_free_rx_ring(meth_private
*priv
)
257 for(i
=0;i
<RX_RING_ENTRIES
;i
++)
258 pci_free_consistent(NULL
,
261 priv
->rx_ring_dmas
[i
]);
264 int meth_reset(struct net_device
*dev
)
266 struct meth_private
*priv
= (struct meth_private
*) dev
->priv
;
269 priv
->regs
->mac_ctrl
= SGI_MAC_RESET
;
270 priv
->regs
->mac_ctrl
= 0;
273 /* Load ethernet address */
274 load_eaddr(dev
, priv
->regs
);
275 /* Should load some "errata", but later */
277 /* Check for device */
278 if(mdio_probe(priv
) < 0) {
279 DPRINTK("Unable to find PHY\n");
283 /* Initial mode -- 10|Half-duplex|Accept normal packets */
284 priv
->mode
=METH_ACCEPT_MCAST
|METH_DEFAULT_IPG
;
285 if(dev
->flags
| IFF_PROMISC
)
286 priv
->mode
|= METH_PROMISC
;
287 priv
->regs
->mac_ctrl
= priv
->mode
;
289 /* Autonegociate speed and duplex mode */
290 meth_check_link(dev
);
292 /* Now set dma control, but don't enable DMA, yet */
293 priv
->regs
->dma_ctrl
= (4 << METH_RX_OFFSET_SHIFT
) |
294 (RX_RING_ENTRIES
<< METH_RX_DEPTH_SHIFT
);
299 /*============End Helper Routines=====================*/
305 int meth_open(struct net_device
*dev
)
307 meth_private
*priv
=dev
->priv
;
308 volatile meth_regs
*regs
=priv
->regs
;
311 /* Initialize the hardware */
312 if((ret
=meth_reset(dev
)) < 0)
315 /* Allocate the ring buffers */
316 if((ret
=meth_init_tx_ring(priv
))<0||(ret
=meth_init_rx_ring(priv
))<0){
317 meth_free_tx_ring(priv
);
318 meth_free_rx_ring(priv
);
322 DPRINTK("Will set dma_ctl now\n");
325 METH_DMA_TX_EN
|/*METH_DMA_TX_INT_EN|*/
326 METH_DMA_RX_EN
|METH_DMA_RX_INT_EN
;
328 if(request_irq(dev
->irq
,meth_interrupt
,SA_SHIRQ
,meth_str
,dev
)){
329 printk(KERN_ERR
"%s: Can't get irq %d\n", dev
->name
, dev
->irq
);
332 DPRINTK("About to start queue\n");
333 netif_start_queue(dev
);
334 DPRINTK("Opened... DMA control=0x%08lx\n", regs
->dma_ctrl
);
338 int meth_release(struct net_device
*dev
)
340 meth_private
*priv
=dev
->priv
;
341 netif_stop_queue(dev
); /* can't transmit any more */
343 ((meth_private
*)(dev
->priv
))->regs
->dma_ctrl
&=
344 ~(METH_DMA_TX_EN
|METH_DMA_TX_INT_EN
|
345 METH_DMA_RX_EN
|METH_DMA_RX_INT_EN
);
346 free_irq(dev
->irq
, dev
);
347 meth_free_tx_ring(priv
);
348 meth_free_rx_ring(priv
);
353 * Configuration changes (passed on by ifconfig)
355 int meth_config(struct net_device
*dev
, struct ifmap
*map
)
357 if (dev
->flags
& IFF_UP
) /* can't act on a running interface */
360 /* Don't allow changing the I/O address */
361 if (map
->base_addr
!= dev
->base_addr
) {
362 printk(KERN_WARNING
"meth: Can't change I/O address\n");
366 /* Don't allow changing the IRQ */
367 if (map
->irq
!= dev
->irq
) {
368 printk(KERN_WARNING
"meth: Can't change IRQ\n");
371 DPRINTK("Configured\n");
373 /* ignore other fields */
378 * Receive a packet: retrieve, encapsulate and pass over to upper levels
380 void meth_rx(struct net_device
* dev
)
383 struct meth_private
*priv
= (struct meth_private
*) dev
->priv
;
385 int twptr
=priv
->rx_write
;
387 spin_lock(&(priv
->meth_lock
));
388 while ((status
=(rxb
=priv
->rx_ring
[priv
->rx_write
])->status
.raw
)&0x8000000000000000)
390 int len
=(status
&0xFFFF) - 4; /* omit CRC */
391 /* length sanity check */
392 if(len
< 60 || len
> 1518) {
393 printk(KERN_DEBUG
"%s: bogus packet size: %d, status=%#2lx.\n",
394 dev
->name
, priv
->rx_write
, rxb
->status
.raw
);
395 priv
->stats
.rx_errors
++;
396 priv
->stats
.rx_length_errors
++;
398 if(!(status
&METH_RX_STATUS_ERRORS
)){
399 skb
=alloc_skb(len
+2,GFP_ATOMIC
);/* Should be atomic -- we are in interrupt */
401 /* Ouch! No memory! Drop packet on the floor */
402 priv
->stats
.rx_dropped
++;
404 skb_reserve(skb
, 2); /* align IP on 16B boundary */
405 memcpy(skb_put(skb
, len
), rxb
->buf
, len
);
406 /* Write metadata, and then pass to the receive level */
408 skb
->protocol
= eth_type_trans(skb
, dev
);
410 dev
->last_rx
= jiffies
;
411 priv
->stats
.rx_packets
++;
412 priv
->stats
.rx_bytes
+=len
;
416 printk(KERN_WARNING
"meth: RX error: status=0x%016lx\n",status
);
417 if(status
&METH_RX_ST_RCV_CODE_VIOLATION
)
418 printk(KERN_WARNING
"Receive Code Violation\n");
419 if(status
&METH_RX_ST_CRC_ERR
)
420 printk(KERN_WARNING
"CRC error\n");
421 if(status
&METH_RX_ST_INV_PREAMBLE_CTX
)
422 printk(KERN_WARNING
"Invalid Preamble Context\n");
423 if(status
&METH_RX_ST_LONG_EVT_SEEN
)
424 printk(KERN_WARNING
"Long Event Seen...\n");
425 if(status
&METH_RX_ST_BAD_PACKET
)
426 printk(KERN_WARNING
"Bad Packet\n");
427 if(status
&METH_RX_ST_CARRIER_EVT_SEEN
)
428 printk(KERN_WARNING
"Carrier Event Seen\n");
431 priv
->regs
->rx_fifo
=priv
->rx_ring_dmas
[priv
->rx_write
];
432 priv
->rx_write
=(priv
->rx_write
+1)&(RX_RING_ENTRIES
-1);
433 if(priv
->rx_write
==twptr
) {
434 DPRINTK("going rounds\n");
437 spin_unlock(&(priv
->meth_lock
));
440 static int meth_tx_full(struct net_device
*dev
)
442 struct meth_private
*priv
= (struct meth_private
*) dev
->priv
;
444 return(priv
->tx_count
>= TX_RING_ENTRIES
-1);
447 void meth_tx_cleanup(struct net_device
* dev
, int rptr
)
449 meth_private
*priv
=dev
->priv
;
453 spin_lock(&priv
->meth_lock
);
456 priv
->regs
->dma_ctrl
&= ~(METH_DMA_TX_INT_EN
);
458 while(priv
->tx_read
!= rptr
){
459 skb
= priv
->tx_skbs
[priv
->tx_read
];
460 status
= &priv
->tx_ring
[priv
->tx_read
];
461 if(!status
->header
.res
.sent
)
463 if(status
->header
.raw
& METH_TX_STATUS_DONE
) {
464 priv
->stats
.tx_packets
++;
465 priv
->stats
.tx_bytes
+= skb
->len
;
467 dev_kfree_skb_irq(skb
);
468 priv
->tx_skbs
[priv
->tx_read
] = NULL
;
469 status
->header
.raw
= 0;
470 priv
->tx_read
= (priv
->tx_read
+1)&(TX_RING_ENTRIES
-1);
474 /* wake up queue if it was stopped */
475 if (netif_queue_stopped(dev
) && ! meth_tx_full(dev
)) {
476 netif_wake_queue(dev
);
479 spin_unlock(priv
->meth_lock
);
483 * The typical interrupt entry point
485 irqreturn_t
meth_interrupt(int irq
, void *dev_id
, struct pt_regs
*pregs
)
487 struct meth_private
*priv
;
490 * As usual, check the "device" pointer for shared handlers.
491 * Then assign "struct device *dev"
493 struct net_device
*dev
= (struct net_device
*)dev_id
;
494 /* ... and check with hw if it's really ours */
496 if (!dev
/*paranoid*/ ) return IRQ_HANDLED
;
498 priv
= (struct meth_private
*) dev
->priv
;
500 status
= priv
->regs
->int_flags
;
502 if (status
& (METH_INT_RX_THRESHOLD
|METH_INT_RX_UNDERFLOW
)) {
503 /* send it to meth_rx for handling */
507 if (status
& (METH_INT_TX_EMPTY
|METH_INT_TX_PKT
)) {
508 /* a transmission is over: free the skb */
509 meth_tx_cleanup(dev
, (priv
->regs
->tx_info
&TX_INFO_RPTR
)>>16);
511 /* check for errors too... */
512 if (status
& (METH_INT_TX_LINK_FAIL
))
513 printk(KERN_WARNING
"meth: link failure\n");
514 if (status
& (METH_INT_MEM_ERROR
))
515 printk(KERN_WARNING
"meth: memory error\n");
516 if (status
& (METH_INT_TX_ABORT
))
517 printk(KERN_WARNING
"meth: aborted\n");
518 if (status
& (METH_INT_RX_OVERFLOW
))
519 printk(KERN_WARNING
"meth: RX overflow\n");
520 if (status
& (METH_INT_RX_UNDERFLOW
))
521 printk(KERN_WARNING
"meth: RX underflow\n");
523 #define METH_INT_ERROR (METH_INT_TX_LINK_FAIL| \
524 METH_INT_MEM_ERROR| \
526 METH_INT_RX_OVERFLOW| \
527 METH_INT_RX_UNDERFLOW)
528 if( status
& METH_INT_ERROR
) {
529 printk(KERN_WARNING
"meth: error status: 0x%08x\n",status
);
530 netif_wake_queue(dev
);
532 priv
->regs
->int_flags
=status
&0xff; /* clear interrupts */
537 * Transmits packets that fit into TX descriptor (are <=120B)
539 static void meth_tx_short_prepare(meth_private
* priv
, struct sk_buff
* skb
)
541 tx_packet
*desc
=&priv
->tx_ring
[priv
->tx_write
];
542 int len
= (skb
->len
<ETH_ZLEN
)?ETH_ZLEN
:skb
->len
;
544 /* maybe I should set whole thing to 0 first... */
545 memcpy(desc
->data
.dt
+(120-len
),skb
->data
,skb
->len
);
547 memset(desc
->data
.dt
+120-len
+skb
->len
,0,len
-skb
->len
);
548 desc
->header
.raw
=METH_TX_CMD_INT_EN
|(len
-1)|((128-len
)<<16);
550 #define TX_CATBUF1 BIT(25)
551 static void meth_tx_1page_prepare(meth_private
* priv
, struct sk_buff
* skb
)
553 tx_packet
*desc
=&priv
->tx_ring
[priv
->tx_write
];
554 void *buffer_data
= (void *)(((u64
)skb
->data
+ 7ULL) & (~7ULL));
555 int unaligned_len
= (int)((u64
)buffer_data
- (u64
)skb
->data
);
556 int buffer_len
= skb
->len
- unaligned_len
;
559 desc
->header
.raw
=METH_TX_CMD_INT_EN
|TX_CATBUF1
|(skb
->len
-1);
563 memcpy(desc
->data
.dt
+(120-unaligned_len
),
564 skb
->data
, unaligned_len
);
565 desc
->header
.raw
|= (128-unaligned_len
) << 16;
569 catbuf
= pci_map_single(NULL
,
573 desc
->data
.cat_buf
[0].form
.start_addr
= catbuf
>> 3;
574 desc
->data
.cat_buf
[0].form
.len
= buffer_len
-1;
576 #define TX_CATBUF2 BIT(26)
577 static void meth_tx_2page_prepare(meth_private
* priv
, struct sk_buff
* skb
)
579 tx_packet
*desc
=&priv
->tx_ring
[priv
->tx_write
];
580 void *buffer1_data
= (void *)(((u64
)skb
->data
+ 7ULL) & (~7ULL));
581 void *buffer2_data
= (void *)PAGE_ALIGN((u64
)skb
->data
);
582 int unaligned_len
= (int)((u64
)buffer1_data
- (u64
)skb
->data
);
583 int buffer1_len
= (int)((u64
)buffer2_data
- (u64
)buffer1_data
);
584 int buffer2_len
= skb
->len
- buffer1_len
- unaligned_len
;
585 dma_addr_t catbuf1
, catbuf2
;
587 desc
->header
.raw
=METH_TX_CMD_INT_EN
|TX_CATBUF1
|TX_CATBUF2
|(skb
->len
-1);
590 memcpy(desc
->data
.dt
+(120-unaligned_len
),
591 skb
->data
, unaligned_len
);
592 desc
->header
.raw
|= (128-unaligned_len
) << 16;
596 catbuf1
= pci_map_single(NULL
,
600 desc
->data
.cat_buf
[0].form
.start_addr
= catbuf1
>> 3;
601 desc
->data
.cat_buf
[0].form
.len
= buffer1_len
-1;
603 catbuf2
= pci_map_single(NULL
,
607 desc
->data
.cat_buf
[1].form
.start_addr
= catbuf2
>> 3;
608 desc
->data
.cat_buf
[1].form
.len
= buffer2_len
-1;
611 void meth_add_to_tx_ring(meth_private
*priv
, struct sk_buff
* skb
)
613 if(skb
->len
<= 120) {
614 /* Whole packet fits into descriptor */
615 meth_tx_short_prepare(priv
,skb
);
616 } else if(PAGE_ALIGN((u64
)skb
->data
) !=
617 PAGE_ALIGN((u64
)skb
->data
+skb
->len
-1)) {
618 /* Packet crosses page boundary */
619 meth_tx_2page_prepare(priv
,skb
);
621 /* Packet is in one page */
622 meth_tx_1page_prepare(priv
,skb
);
625 /* Remember the skb, so we can free it at interrupt time */
626 priv
->tx_skbs
[priv
->tx_write
] = skb
;
627 priv
->tx_write
= (priv
->tx_write
+1) & (TX_RING_ENTRIES
-1);
628 priv
->regs
->tx_info
= priv
->tx_write
;
630 /* Enable DMA transfer */
631 priv
->regs
->dma_ctrl
|= METH_DMA_TX_INT_EN
;
635 * Transmit a packet (called by the kernel)
637 int meth_tx(struct sk_buff
*skb
, struct net_device
*dev
)
639 struct meth_private
*priv
= (struct meth_private
*) dev
->priv
;
641 spin_lock(&priv
->meth_lock
);
643 meth_add_to_tx_ring(priv
, skb
);
644 dev
->trans_start
= jiffies
; /* save the timestamp */
646 /* If TX ring is full, tell the upper layer to stop sending packets */
647 if (meth_tx_full(dev
)) {
648 printk("TX full: stopping\n");
649 netif_stop_queue(dev
);
652 spin_unlock(&priv
->meth_lock
);
658 * Deal with a transmit timeout.
661 void meth_tx_timeout (struct net_device
*dev
)
663 struct meth_private
*priv
= (struct meth_private
*) dev
->priv
;
665 printk(KERN_WARNING
"%s: transmit timed out\n", dev
->name
);
667 /* Protect against concurrent rx interrupts */
668 spin_lock(&priv
->meth_lock
);
670 /* Try to reset the interface. */
673 priv
->stats
.tx_errors
++;
675 /* Clear all rings */
676 meth_free_tx_ring(priv
);
677 meth_free_rx_ring(priv
);
678 meth_init_tx_ring(priv
);
679 meth_init_rx_ring(priv
);
682 priv
->regs
->dma_ctrl
|=METH_DMA_TX_EN
|METH_DMA_RX_EN
|METH_DMA_RX_INT_EN
;
684 /* Enable interrupt */
685 spin_unlock(&priv
->meth_lock
);
687 dev
->trans_start
= jiffies
;
688 netif_wake_queue(dev
);
696 int meth_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
704 * Return statistics to the caller
706 struct net_device_stats
*meth_stats(struct net_device
*dev
)
708 struct meth_private
*priv
= (struct meth_private
*) dev
->priv
;
713 * The init function (sometimes called probe).
714 * It is invoked by register_netdev()
716 int meth_init(struct net_device
*dev
)
718 meth_private
*priv
=(meth_private
*)dev
->priv
;
720 * Then, assign other fields in dev, using ether_setup() and some
723 ether_setup(dev
); /* assign some of the fields */
725 dev
->open
= meth_open
;
726 dev
->stop
= meth_release
;
727 dev
->set_config
= meth_config
;
728 dev
->hard_start_xmit
= meth_tx
;
729 dev
->do_ioctl
= meth_ioctl
;
730 dev
->get_stats
= meth_stats
;
731 #ifdef HAVE_TX_TIMEOUT
732 dev
->tx_timeout
= meth_tx_timeout
;
733 dev
->watchdog_timeo
= timeout
;
735 dev
->irq
= MACE_ETHERNET_IRQ
;
736 SET_MODULE_OWNER(dev
);
738 spin_lock_init(&((struct meth_private
*) dev
->priv
)->meth_lock
);
740 * Make the usual checks: check_region(), probe irq, ... -ENODEV
741 * should be returned if no device found. No resource should be
742 * grabbed: this is done on open().
744 priv
->regs
=(meth_regs
*)SGI_MFE
;
745 dev
->base_addr
=SGI_MFE
;
746 priv
->phy_addr
= -1; /* No phy is known yet... */
748 printk("SGI O2 Fast Ethernet rev. %ld\n", priv
->regs
->mac_ctrl
>> 29);
757 struct net_device
*meth_dev
;
760 * Finally, the module stuff
763 int meth_init_module(void)
765 int result
, device_present
= 0;
767 meth_dev
=alloc_etherdev(sizeof(meth_private
));
770 if ( (result
= register_netdev(meth_dev
)) )
771 printk("meth: error %i registering device \"%s\"\n",
772 result
, meth_dev
->name
);
773 else device_present
++;
775 return device_present
? 0 : -ENODEV
;
778 void meth_cleanup(void)
780 unregister_netdev(meth_dev
);
785 module_init(meth_init_module
);
786 module_exit(meth_cleanup
);