More meth updates.
[linux-2.6/linux-mips.git] / drivers / net / meth.c
blob96cc8629493b85681db8baf45acd947c6bb219aa
1 /*
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>
23 #include <linux/in.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>
35 #include "meth.h"
37 #include <linux/in6.h>
38 #include <asm/checksum.h>
40 #ifndef MFE_DEBUG
41 #define MFE_DEBUG 0
42 #endif
44 #if MFE_DEBUG>=1
45 #define DPRINTK(str,args...) printk (KERN_DEBUG "meth(%ld): %s: " str, jiffies, __FUNCTION__ , ## args)
46 #define MFE_RX_DEBUG 2
47 #else
48 #define DPRINTK(str,args...)
49 #define MFE_RX_DEBUG 0
50 #endif
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");
64 #endif
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*/
76 tx_packet *tx_ring;
77 dma_addr_t tx_ring_dma;
78 int free_space;
79 struct sk_buff *tx_skbs[TX_RING_ENTRIES];
80 dma_addr_t tx_skb_dmas[TX_RING_ENTRIES];
81 int tx_read,tx_write;
82 int tx_count;
84 rx_packet *rx_ring[RX_RING_ENTRIES];
85 dma_addr_t rx_ring_dmas[RX_RING_ENTRIES];
86 int rx_write;
88 spinlock_t meth_lock;
89 } meth_private;
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)
100 int i;
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);
104 for (i=0; i<6; i++)
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){ \
114 udelay(25); \
116 /*read phy register, return value read */
117 static int mdio_read(meth_private *priv,int phyreg)
119 volatile meth_regs* regs=priv->regs;
120 volatile u32 rval;
121 WAIT_FOR_PHY(regs,rval);
122 regs->phy_registers=(priv->phy_addr<<5)|(phyreg&0x1f);
123 udelay(25);
124 regs->phy_trans_go=1;
125 udelay(25);
126 WAIT_FOR_PHY(regs,rval);
127 return rval&MDIO_DATA_MASK;
130 static int mdio_probe(meth_private *priv)
132 int i, p2, p3;
133 DPRINTK("Detecting PHY kind\n");
134 /* check if phy is detected already */
135 if(priv->phy_addr>=0&&priv->phy_addr<32)
136 return 0;
137 spin_lock(&priv->meth_lock);
138 for (i=0;i<32;++i){
139 priv->phy_addr=(char)i;
140 p2=mdio_read(priv,2);
141 #ifdef MFE_DEBUG
142 p3=mdio_read(priv,3);
143 switch ((p2<<12)|(p3>>4)){
144 case PHY_QS6612X:
145 DPRINTK("PHY is QS6612X\n");
146 break;
147 case PHY_ICS1889:
148 DPRINTK("PHY is ICS1889\n");
149 break;
150 case PHY_ICS1890:
151 DPRINTK("PHY is ICS1890\n");
152 break;
153 case PHY_DP83840:
154 DPRINTK("PHY is DP83840\n");
155 break;
157 #endif
158 if(p2!=0xffff&&p2!=0x0000){
159 DPRINTK("PHY code: %x\n",(p2<<12)|(p3>>4));
160 break;
163 spin_unlock(&priv->meth_lock);
164 if(priv->phy_addr<32) {
165 return 0;
167 DPRINTK("Oopsie! PHY is not known!\n");
168 priv->phy_addr=-1;
169 return -ENODEV;
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;
178 int duplex, speed;
180 if (mii_partner == 0xffff)
181 return;
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");
189 if (duplex)
190 priv->mode |= METH_PHY_FDX;
191 else
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);
199 if (duplex)
200 priv->mode |= METH_100MBIT;
201 else
202 priv->mode &= ~METH_100MBIT;
203 priv->regs->mac_ctrl = priv->mode;
208 static int meth_init_tx_ring(meth_private *priv)
210 /* Init TX ring */
211 DPRINTK("Initializing TX ring\n");
212 priv->tx_ring = (tx_packet *) pci_alloc_consistent(NULL,TX_RING_BUFFER_SIZE,&(priv->tx_ring_dma));
213 if(!priv->tx_ring)
214 return -ENOMEM;
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");
223 return 0;
226 static int meth_init_rx_ring(meth_private *priv)
228 int i;
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];
234 priv->rx_write = 0;
235 DPRINTK("Done with RX ring\n");
236 return 0;
238 static void meth_free_tx_ring(meth_private *priv)
240 int i;
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,
249 TX_RING_BUFFER_SIZE,
250 priv->tx_ring,
251 priv->tx_ring_dma);
253 static void meth_free_rx_ring(meth_private *priv)
255 int i;
257 for(i=0;i<RX_RING_ENTRIES;i++)
258 pci_free_consistent(NULL,
259 METH_RX_BUFF_SIZE,
260 priv->rx_ring[i],
261 priv->rx_ring_dmas[i]);
264 int meth_reset(struct net_device *dev)
266 struct meth_private *priv = (struct meth_private *) dev->priv;
268 /* Reset card */
269 priv->regs->mac_ctrl = SGI_MAC_RESET;
270 priv->regs->mac_ctrl = 0;
271 udelay(25);
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");
280 return -ENODEV;
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);
296 return(0);
299 /*============End Helper Routines=====================*/
302 * Open and close
305 int meth_open(struct net_device *dev)
307 meth_private *priv=dev->priv;
308 volatile meth_regs *regs=priv->regs;
309 int ret;
311 /* Initialize the hardware */
312 if((ret=meth_reset(dev)) < 0)
313 return ret;
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);
319 return ret;
322 DPRINTK("Will set dma_ctl now\n");
323 /* Start DMA */
324 regs->dma_ctrl|=
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);
330 return -EAGAIN;
332 DPRINTK("About to start queue\n");
333 netif_start_queue(dev);
334 DPRINTK("Opened... DMA control=0x%08lx\n", regs->dma_ctrl);
335 return 0;
338 int meth_release(struct net_device *dev)
340 meth_private *priv=dev->priv;
341 netif_stop_queue(dev); /* can't transmit any more */
342 /* shut down dma */
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);
349 return 0;
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 */
358 return -EBUSY;
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");
363 return -EOPNOTSUPP;
366 /* Don't allow changing the IRQ */
367 if (map->irq != dev->irq) {
368 printk(KERN_WARNING "meth: Can't change IRQ\n");
369 return -EOPNOTSUPP;
371 DPRINTK("Configured\n");
373 /* ignore other fields */
374 return 0;
378 * Receive a packet: retrieve, encapsulate and pass over to upper levels
380 void meth_rx(struct net_device* dev)
382 struct sk_buff *skb;
383 struct meth_private *priv = (struct meth_private *) dev->priv;
384 rx_packet *rxb;
385 int twptr=priv->rx_write;
386 u64 status;
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 */
400 if(!skb){
401 /* Ouch! No memory! Drop packet on the floor */
402 priv->stats.rx_dropped++;
403 } else {
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 */
407 skb->dev = dev;
408 skb->protocol = eth_type_trans(skb, dev);
410 dev->last_rx = jiffies;
411 priv->stats.rx_packets++;
412 priv->stats.rx_bytes+=len;
413 netif_rx(skb);
415 } else {
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");
430 rxb->status.raw=0;
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;
450 tx_packet* status;
451 struct sk_buff *skb;
453 spin_lock(&priv->meth_lock);
455 /* Stop DMA */
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)
462 break;
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);
471 priv->tx_count --;
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;
488 u32 status;
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 */
504 meth_rx(dev);
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| \
525 METH_INT_TX_ABORT| \
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 */
533 return IRQ_HANDLED;
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);
546 if(skb->len < 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;
557 dma_addr_t catbuf;
559 desc->header.raw=METH_TX_CMD_INT_EN|TX_CATBUF1|(skb->len-1);
561 /* unaligned part */
562 if(unaligned_len){
563 memcpy(desc->data.dt+(120-unaligned_len),
564 skb->data, unaligned_len);
565 desc->header.raw |= (128-unaligned_len) << 16;
568 /* first page */
569 catbuf = pci_map_single(NULL,
570 buffer_data,
571 buffer_len,
572 PCI_DMA_TODEVICE);
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);
588 /* unaligned part */
589 if(unaligned_len){
590 memcpy(desc->data.dt+(120-unaligned_len),
591 skb->data, unaligned_len);
592 desc->header.raw |= (128-unaligned_len) << 16;
595 /* first page */
596 catbuf1 = pci_map_single(NULL,
597 buffer1_data,
598 buffer1_len,
599 PCI_DMA_TODEVICE);
600 desc->data.cat_buf[0].form.start_addr = catbuf1 >> 3;
601 desc->data.cat_buf[0].form.len = buffer1_len-1;
602 /* second page */
603 catbuf2 = pci_map_single(NULL,
604 buffer2_data,
605 buffer2_len,
606 PCI_DMA_TODEVICE);
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);
620 } else {
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;
629 priv->tx_count ++;
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);
654 return 0;
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. */
671 meth_reset(dev);
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);
681 /* Restart dma */
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);
690 return;
694 * Ioctl commands
696 int meth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
699 DPRINTK("ioctl\n");
700 return 0;
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;
709 return &priv->stats;
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
721 * hand assignments
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;
734 #endif
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);
750 return 0;
754 * The devices
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));
768 meth_init(meth_dev);
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);
781 kfree(meth_dev);
782 return;
785 module_init(meth_init_module);
786 module_exit(meth_cleanup);