Merge with 2.3.99-pre1.
[linux-2.6/linux-mips.git] / drivers / net / sis900.c
blob2653270c35c0d9156010a64687e50b787107d0f0
1 /* sis900.c: A SiS 900/7016 PCI Fast Ethernet driver for Linux.
2 Copyright 1999 Silicon Integrated System Corporation
3 Revision: 1.06.04 Feb 11 2000
5 Modified from the driver which is originally written by Donald Becker.
7 This software may be used and distributed according to the terms
8 of the GNU Public License (GPL), incorporated herein by reference.
9 Drivers based on this skeleton fall under the GPL and must retain
10 the authorship (implicit copyright) notice.
12 References:
13 SiS 7016 Fast Ethernet PCI Bus 10/100 Mbps LAN Controller with OnNow Support,
14 preliminary Rev. 1.0 Jan. 14, 1998
15 SiS 900 Fast Ethernet PCI Bus 10/100 Mbps LAN Single Chip with OnNow Support,
16 preliminary Rev. 1.0 Nov. 10, 1998
17 SiS 7014 Single Chip 100BASE-TX/10BASE-T Physical Layer Solution,
18 preliminary Rev. 1.0 Jan. 18, 1998
19 http://www.sis.com.tw/support/databook.htm
21 Rev 1.06.04 Feb. 11 2000 Jeff Garzik <jgarzik@mandrakesoft.com> softnet and init for kernel 2.4
22 Rev 1.06.03 Dec. 23 1999 Ollie Lho Third release
23 Rev 1.06.02 Nov. 23 1999 Ollie Lho bug in mac probing fixed
24 Rev 1.06.01 Nov. 16 1999 Ollie Lho CRC calculation provide by Joseph Zbiciak (im14u2c@primenet.com)
25 Rev 1.06 Nov. 4 1999 Ollie Lho (ollie@sis.com.tw) Second release
26 Rev 1.05.05 Oct. 29 1999 Ollie Lho (ollie@sis.com.tw) Single buffer Tx/Rx
27 Chin-Shan Li (lcs@sis.com.tw) Added AMD Am79c901 HomePNA PHY support
28 Rev 1.05 Aug. 7 1999 Jim Huang (cmhuang@sis.com.tw) Initial release
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/string.h>
36 #include <linux/timer.h>
37 #include <linux/errno.h>
38 #include <linux/ioport.h>
39 #include <linux/malloc.h>
40 #include <linux/interrupt.h>
41 #include <linux/pci.h>
42 #include <linux/netdevice.h>
43 #include <linux/init.h>
45 #include <linux/etherdevice.h>
46 #include <linux/skbuff.h>
47 #include <asm/processor.h> /* Processor type for cache alignment. */
48 #include <asm/bitops.h>
49 #include <asm/io.h>
50 #include <linux/delay.h>
52 #include "sis900.h"
54 static const char *version =
55 "sis900.c: v1.06.04 02/11/2000\n";
57 static int max_interrupt_work = 20;
58 #define sis900_debug debug
59 static int sis900_debug = 0;
61 static int multicast_filter_limit = 128;
63 /* Time in jiffies before concluding the transmitter is hung. */
64 #define TX_TIMEOUT (4*HZ)
66 struct mac_chip_info {
67 const char *name;
68 u16 vendor_id, device_id, flags;
69 int io_size;
70 struct net_device *(*probe) (struct mac_chip_info *mac, struct pci_dev * pci_dev,
71 struct net_device * net_dev);
73 static struct net_device * sis900_mac_probe (struct mac_chip_info * mac, struct pci_dev * pci_dev,
74 struct net_device * net_dev);
76 static struct mac_chip_info mac_chip_table[] = {
77 { "SiS 900 PCI Fast Ethernet", PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_900,
78 PCI_COMMAND_IO|PCI_COMMAND_MASTER, SIS900_TOTAL_SIZE, sis900_mac_probe},
79 { "SiS 7016 PCI Fast Ethernet",PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7016,
80 PCI_COMMAND_IO|PCI_COMMAND_MASTER, SIS900_TOTAL_SIZE, sis900_mac_probe},
81 {0,}, /* 0 terminated list. */
84 static void sis900_read_mode(struct net_device *net_dev, int phy_addr, int *speed, int *duplex);
85 static void amd79c901_read_mode(struct net_device *net_dev, int phy_addr, int *speed, int *duplex);
87 static struct mii_chip_info {
88 const char * name;
89 u16 phy_id0;
90 u16 phy_id1;
91 void (*read_mode) (struct net_device *net_dev, int phy_addr, int *speed, int *duplex);
92 } mii_chip_table[] = {
93 {"SiS 900 Internal MII PHY", 0x001d, 0x8000, sis900_read_mode},
94 {"SiS 7014 Physical Layer Solution", 0x0016, 0xf830,sis900_read_mode},
95 {"AMD 79C901 10BASE-T PHY", 0x0000, 0x35b9, amd79c901_read_mode},
96 {"AMD 79C901 HomePNA PHY", 0x0000, 0x35c8, amd79c901_read_mode},
97 {0,},
100 struct mii_phy {
101 struct mii_phy * next;
102 struct mii_chip_info * chip_info;
103 int phy_addr;
104 u16 status;
107 typedef struct _BufferDesc {
108 u32 link;
109 u32 cmdsts;
110 u32 bufptr;
111 } BufferDesc;
113 struct sis900_private {
114 struct net_device *next_module;
115 struct net_device_stats stats;
116 struct pci_dev * pci_dev;
118 spinlock_t lock;
120 struct mac_chip_info * mac;
121 struct mii_phy * mii;
122 unsigned int cur_phy;
124 struct timer_list timer; /* Link status detection timer. */
125 unsigned int cur_rx, dirty_rx;
126 unsigned int cur_tx, dirty_tx;
128 /* The saved address of a sent/receive-in-place packet buffer */
129 struct sk_buff *tx_skbuff[NUM_TX_DESC];
130 struct sk_buff *rx_skbuff[NUM_RX_DESC];
131 BufferDesc tx_ring[NUM_TX_DESC];
132 BufferDesc rx_ring[NUM_RX_DESC];
133 unsigned int tx_full; /* The Tx queue is full. */
135 int LinkOn;
138 MODULE_AUTHOR("Jim Huang <cmhuang@sis.com.tw>, Ollie Lho <ollie@sis.com.tw>");
139 MODULE_DESCRIPTION("SiS 900 PCI Fast Ethernet driver");
140 MODULE_PARM(multicast_filter_limit, "i");
141 MODULE_PARM(max_interrupt_work, "i");
142 MODULE_PARM(debug, "i");
144 static int sis900_open(struct net_device *net_dev);
145 static int sis900_mii_probe (struct net_device * net_dev);
146 static void sis900_init_rxfilter (struct net_device * net_dev);
147 static u16 read_eeprom(long ioaddr, int location);
148 static u16 mdio_read(struct net_device *net_dev, int phy_id, int location);
149 static void mdio_write(struct net_device *net_dev, int phy_id, int location, int val);
150 static void sis900_timer(unsigned long data);
151 static void sis900_check_mode (struct net_device *net_dev, struct mii_phy *mii_phy);
152 static void sis900_tx_timeout(struct net_device *net_dev);
153 static void sis900_init_tx_ring(struct net_device *net_dev);
154 static void sis900_init_rx_ring(struct net_device *net_dev);
155 static int sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev);
156 static int sis900_rx(struct net_device *net_dev);
157 static void sis900_finish_xmit (struct net_device *net_dev);
158 static void sis900_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
159 static int sis900_close(struct net_device *net_dev);
160 static int mii_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd);
161 static struct enet_statistics *sis900_get_stats(struct net_device *net_dev);
162 static u16 sis900_compute_hashtable_index(u8 *addr);
163 static void set_rx_mode(struct net_device *net_dev);
164 static void sis900_reset(struct net_device *net_dev);
166 /* A list of all installed SiS900 devices, for removing the driver module. */
167 static struct net_device *root_sis900_dev = NULL;
169 /* walk through every ethernet PCI devices to see if some of them are matched with our card list*/
170 static int __init sis900_probe (void)
172 int found = 0;
173 struct pci_dev * pci_dev = NULL;
175 while ((pci_dev = pci_find_class (PCI_CLASS_NETWORK_ETHERNET << 8, pci_dev)) != NULL) {
176 /* pci_dev contains all ethernet devices */
177 u32 pci_io_base;
178 struct mac_chip_info * mac;
179 struct net_device *net_dev = NULL;
181 for (mac = mac_chip_table; mac->vendor_id; mac++) {
182 /* try to match our card list */
183 if (pci_dev->vendor == mac->vendor_id &&
184 pci_dev->device == mac->device_id)
185 break;
188 if (mac->vendor_id == 0)
189 /* pci_dev does not match any of our cards */
190 continue;
192 /* now, pci_dev should be either 900 or 7016 */
193 pci_io_base = pci_dev->resource[0].start;
194 if ((mac->flags & PCI_COMMAND_IO ) &&
195 check_region(pci_io_base, mac->io_size))
196 continue;
198 /* setup various bits in PCI command register */
199 pci_enable_device (pci_dev);
200 pci_set_master(pci_dev);
202 /* do the real low level jobs */
203 net_dev = mac->probe(mac, pci_dev, net_dev);
205 if (net_dev != NULL) {
206 found++;
208 net_dev = NULL;
210 return found ? 0 : -ENODEV;
213 static struct net_device * sis900_mac_probe (struct mac_chip_info * mac, struct pci_dev * pci_dev,
214 struct net_device * net_dev)
216 struct sis900_private *sis_priv;
217 long ioaddr = pci_dev->resource[0].start;
218 int irq = pci_dev->irq;
219 static int did_version = 0;
220 u16 signature;
221 int i;
223 if (did_version++ == 0)
224 printk(KERN_INFO "%s", version);
226 if ((net_dev = init_etherdev(net_dev, 0)) == NULL)
227 return NULL;
228 /* check to see if we have sane EEPROM */
229 signature = (u16) read_eeprom(ioaddr, EEPROMSignature);
230 if (signature == 0xffff || signature == 0x0000) {
231 printk (KERN_INFO "%s: Error EERPOM read %x\n",
232 net_dev->name, signature);
233 return NULL;
236 printk(KERN_INFO "%s: %s at %#lx, IRQ %d, ", net_dev->name, mac->name,
237 ioaddr, irq);
239 /* get MAC address from EEPROM */
240 for (i = 0; i < 3; i++)
241 ((u16 *)(net_dev->dev_addr))[i] = read_eeprom(ioaddr, i+EEPROMMACAddr);
242 for (i = 0; i < 5; i++)
243 printk("%2.2x:", (u8)net_dev->dev_addr[i]);
244 printk("%2.2x.\n", net_dev->dev_addr[i]);
246 if ((net_dev->priv = kmalloc(sizeof(struct sis900_private), GFP_KERNEL)) == NULL) {
247 unregister_netdevice(net_dev);
248 return NULL;
251 sis_priv = net_dev->priv;
252 memset(sis_priv, 0, sizeof(struct sis900_private));
254 /* We do a request_region() to register /proc/ioports info. */
255 request_region(ioaddr, mac->io_size, net_dev->name);
256 net_dev->base_addr = ioaddr;
257 net_dev->irq = irq;
258 sis_priv->pci_dev = pci_dev;
259 sis_priv->mac = mac;
260 spin_lock_init(&sis_priv->lock);
262 /* probe for mii transciver */
263 if (sis900_mii_probe(net_dev) == 0) {
264 unregister_netdev(net_dev);
265 kfree(sis_priv);
266 release_region(ioaddr, mac->io_size);
267 return NULL;
270 sis_priv->next_module = root_sis900_dev;
271 root_sis900_dev = net_dev;
273 /* The SiS900-specific entries in the device structure. */
274 net_dev->open = &sis900_open;
275 net_dev->hard_start_xmit = &sis900_start_xmit;
276 net_dev->stop = &sis900_close;
277 net_dev->get_stats = &sis900_get_stats;
278 net_dev->set_multicast_list = &set_rx_mode;
279 net_dev->do_ioctl = &mii_ioctl;
280 net_dev->tx_timeout = sis900_tx_timeout;
281 net_dev->watchdog_timeo = TX_TIMEOUT;
283 return net_dev;
286 static int sis900_mii_probe (struct net_device * net_dev)
288 struct sis900_private * sis_priv = (struct sis900_private *)net_dev->priv;
289 int phy_addr;
291 sis_priv->mii = NULL;
293 /* search for total of 32 possible mii phy addresses */
294 for (phy_addr = 0; phy_addr < 32; phy_addr++) {
295 u16 mii_status;
296 u16 phy_id0, phy_id1;
297 int i;
299 mii_status = mdio_read(net_dev, phy_addr, MII_STATUS);
300 if (mii_status == 0xffff || mii_status == 0x0000)
301 /* the mii is not accessable, try next one */
302 continue;
304 phy_id0 = mdio_read(net_dev, phy_addr, MII_PHY_ID0);
305 phy_id1 = mdio_read(net_dev, phy_addr, MII_PHY_ID1);
307 /* search our mii table for the current mii */
308 for (i = 0; mii_chip_table[i].phy_id1; i++)
309 if (phy_id0 == mii_chip_table[i].phy_id0) {
310 struct mii_phy * mii_phy;
312 printk(KERN_INFO
313 "%s: %s transceiver found at address %d.\n",
314 net_dev->name, mii_chip_table[i].name,
315 phy_addr);;
316 if ((mii_phy = kmalloc(sizeof(struct mii_phy), GFP_KERNEL)) != NULL) {
317 mii_phy->chip_info = mii_chip_table+i;
318 mii_phy->phy_addr = phy_addr;
319 mii_phy->status = mdio_read(net_dev, phy_addr,
320 MII_STATUS);
321 mii_phy->next = sis_priv->mii;
322 sis_priv->mii = mii_phy;
324 /* the current mii is on our mii_info_table,
325 try next address */
326 break;
330 if (sis_priv->mii == NULL) {
331 printk(KERN_INFO "%s: No MII transceivers found!\n",
332 net_dev->name);
333 return 0;
336 /* arbitrary choose that last PHY and current PHY */
337 sis_priv->cur_phy = sis_priv->mii->phy_addr;
338 printk(KERN_INFO "%s: Using %s as default\n", net_dev->name,
339 sis_priv->mii->chip_info->name);
341 if (sis_priv->mii->status & MII_STAT_LINK)
342 sis_priv->LinkOn = TRUE;
343 else
344 sis_priv->LinkOn = FALSE;
346 return 1;
349 /* Delay between EEPROM clock transitions. */
350 #define eeprom_delay() inl(ee_addr)
352 /* Read Serial EEPROM through EEPROM Access Register, Note that location is
353 in word (16 bits) unit */
354 static u16 read_eeprom(long ioaddr, int location)
356 int i;
357 u16 retval = 0;
358 long ee_addr = ioaddr + mear;
359 u32 read_cmd = location | EEread;
361 outl(0, ee_addr);
362 eeprom_delay();
363 outl(EECLK, ee_addr);
364 eeprom_delay();
366 /* Shift the read command (9) bits out. */
367 for (i = 8; i >= 0; i--) {
368 u32 dataval = (read_cmd & (1 << i)) ? EEDI | EECS : EECS;
369 outl(dataval, ee_addr);
370 eeprom_delay();
371 outl(dataval | EECLK, ee_addr);
372 eeprom_delay();
374 outb(EECS, ee_addr);
375 eeprom_delay();
377 /* read the 16-bits data in */
378 for (i = 16; i > 0; i--) {
379 outl(EECS, ee_addr);
380 eeprom_delay();
381 outl(EECS | EECLK, ee_addr);
382 eeprom_delay();
383 retval = (retval << 1) | ((inl(ee_addr) & EEDO) ? 1 : 0);
384 eeprom_delay();
387 /* Terminate the EEPROM access. */
388 outl(0, ee_addr);
389 eeprom_delay();
390 outl(EECLK, ee_addr);
392 return (retval);
395 /* Read and write the MII management registers using software-generated
396 serial MDIO protocol. Note that the command bits and data bits are
397 send out seperately */
398 #define mdio_delay() inl(mdio_addr)
400 static void mdio_idle(long mdio_addr)
402 outl(MDIO | MDDIR, mdio_addr);
403 mdio_delay();
404 outl(MDIO | MDDIR | MDC, mdio_addr);
407 /* Syncronize the MII management interface by shifting 32 one bits out. */
408 static void mdio_reset(long mdio_addr)
410 int i;
412 for (i = 31; i >= 0; i--) {
413 outl(MDDIR | MDIO, mdio_addr);
414 mdio_delay();
415 outl(MDDIR | MDIO | MDC, mdio_addr);
416 mdio_delay();
418 return;
421 static u16 mdio_read(struct net_device *net_dev, int phy_id, int location)
423 long mdio_addr = net_dev->base_addr + mear;
424 int mii_cmd = MIIread|(phy_id<<MIIpmdShift)|(location<<MIIregShift);
425 u16 retval = 0;
426 int i;
428 mdio_reset(mdio_addr);
429 mdio_idle(mdio_addr);
431 for (i = 15; i >= 0; i--) {
432 int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR;
433 outl(dataval, mdio_addr);
434 mdio_delay();
435 outl(dataval | MDC, mdio_addr);
436 mdio_delay();
439 /* Read the 16 data bits. */
440 for (i = 16; i > 0; i--) {
441 outl(0, mdio_addr);
442 mdio_delay();
443 retval = (retval << 1) | ((inl(mdio_addr) & MDIO) ? 1 : 0);
444 outl(MDC, mdio_addr);
445 mdio_delay();
447 return retval;
450 static void mdio_write(struct net_device *net_dev, int phy_id, int location, int value)
452 long mdio_addr = net_dev->base_addr + mear;
453 int mii_cmd = MIIwrite|(phy_id<<MIIpmdShift)|(location<<MIIregShift);
454 int i;
456 mdio_reset(mdio_addr);
457 mdio_idle(mdio_addr);
459 /* Shift the command bits out. */
460 for (i = 15; i >= 0; i--) {
461 int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR;
462 outb(dataval, mdio_addr);
463 mdio_delay();
464 outb(dataval | MDC, mdio_addr);
465 mdio_delay();
467 mdio_delay();
469 /* Shift the value bits out. */
470 for (i = 15; i >= 0; i--) {
471 int dataval = (value & (1 << i)) ? MDDIR | MDIO : MDDIR;
472 outl(dataval, mdio_addr);
473 mdio_delay();
474 outl(dataval | MDC, mdio_addr);
475 mdio_delay();
477 mdio_delay();
479 /* Clear out extra bits. */
480 for (i = 2; i > 0; i--) {
481 outb(0, mdio_addr);
482 mdio_delay();
483 outb(MDC, mdio_addr);
484 mdio_delay();
486 return;
489 static int
490 sis900_open(struct net_device *net_dev)
492 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
493 long ioaddr = net_dev->base_addr;
495 /* Soft reset the chip. */
496 sis900_reset(net_dev);
498 if (request_irq(net_dev->irq, &sis900_interrupt, SA_SHIRQ, net_dev->name, net_dev)) {
499 return -EAGAIN;
502 MOD_INC_USE_COUNT;
504 sis900_init_rxfilter(net_dev);
506 sis900_init_tx_ring(net_dev);
507 sis900_init_rx_ring(net_dev);
509 set_rx_mode(net_dev);
511 netif_start_queue(net_dev);
513 /* Enable all known interrupts by setting the interrupt mask. */
514 outl((RxSOVR|RxORN|RxERR|RxOK|TxURN|TxERR|TxIDLE), ioaddr + imr);
515 outl(RxENA, ioaddr + cr);
516 outl(IE, ioaddr + ier);
518 sis900_check_mode(net_dev, sis_priv->mii);
520 /* Set the timer to switch to check for link beat and perhaps switch
521 to an alternate media type. */
522 init_timer(&sis_priv->timer);
523 sis_priv->timer.expires = jiffies + HZ;
524 sis_priv->timer.data = (unsigned long)net_dev;
525 sis_priv->timer.function = &sis900_timer;
526 add_timer(&sis_priv->timer);
528 return 0;
531 /* set receive filter address to our MAC address */
532 static void
533 sis900_init_rxfilter (struct net_device * net_dev)
535 long ioaddr = net_dev->base_addr;
536 u32 rfcrSave;
537 u32 i;
539 rfcrSave = inl(rfcr + ioaddr);
541 /* disable packet filtering before setting filter */
542 outl(rfcrSave & ~RFEN, rfcr);
544 /* load MAC addr to filter data register */
545 for (i = 0 ; i < 3 ; i++) {
546 u32 w;
548 w = (u32) *((u16 *)(net_dev->dev_addr)+i);
549 outl((i << RFADDR_shift), ioaddr + rfcr);
550 outl(w, ioaddr + rfdr);
552 if (sis900_debug > 2) {
553 printk(KERN_INFO "%s: Receive Filter Addrss[%d]=%x\n",
554 net_dev->name, i, inl(ioaddr + rfdr));
558 /* enable packet filitering */
559 outl(rfcrSave | RFEN, rfcr + ioaddr);
562 /* Initialize the Tx ring. */
563 static void
564 sis900_init_tx_ring(struct net_device *net_dev)
566 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
567 long ioaddr = net_dev->base_addr;
568 int i;
570 sis_priv->tx_full = 0;
571 sis_priv->dirty_tx = sis_priv->cur_tx = 0;
573 for (i = 0; i < NUM_TX_DESC; i++) {
574 sis_priv->tx_skbuff[i] = NULL;
576 sis_priv->tx_ring[i].link = (u32) virt_to_bus(&sis_priv->tx_ring[i+1]);
577 sis_priv->tx_ring[i].cmdsts = 0;
578 sis_priv->tx_ring[i].bufptr = 0;
580 sis_priv->tx_ring[i-1].link = (u32) virt_to_bus(&sis_priv->tx_ring[0]);
582 /* load Transmit Descriptor Register */
583 outl(virt_to_bus(&sis_priv->tx_ring[0]), ioaddr + txdp);
584 if (sis900_debug > 2)
585 printk(KERN_INFO "%s: TX descriptor register loaded with: %8.8x\n",
586 net_dev->name, inl(ioaddr + txdp));
589 /* Initialize the Rx descriptor ring, pre-allocate recevie buffers */
590 static void
591 sis900_init_rx_ring(struct net_device *net_dev)
593 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
594 long ioaddr = net_dev->base_addr;
595 int i;
597 sis_priv->cur_rx = 0;
598 sis_priv->dirty_rx = 0;
600 /* init RX descriptor */
601 for (i = 0; i < NUM_RX_DESC; i++) {
602 sis_priv->rx_skbuff[i] = NULL;
604 sis_priv->rx_ring[i].link = (u32) virt_to_bus(&sis_priv->rx_ring[i+1]);
605 sis_priv->rx_ring[i].cmdsts = 0;
606 sis_priv->rx_ring[i].bufptr = 0;
608 sis_priv->rx_ring[i-1].link = (u32) virt_to_bus(&sis_priv->rx_ring[0]);
610 /* allocate sock buffers */
611 for (i = 0; i < NUM_RX_DESC; i++) {
612 struct sk_buff *skb;
614 if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
615 /* not enough memory for skbuff, this makes a "hole"
616 on the buffer ring, it is not clear how the
617 hardware will react to this kind of degenerated
618 buffer */
619 break;
621 skb->dev = net_dev;
622 sis_priv->rx_skbuff[i] = skb;
623 sis_priv->rx_ring[i].cmdsts = RX_BUF_SIZE;
624 sis_priv->rx_ring[i].bufptr = virt_to_bus(skb->tail);
626 sis_priv->dirty_rx = (unsigned int) (i - NUM_RX_DESC);
628 /* load Receive Descriptor Register */
629 outl(virt_to_bus(&sis_priv->rx_ring[0]), ioaddr + rxdp);
630 if (sis900_debug > 2)
631 printk(KERN_INFO "%s: RX descriptor register loaded with: %8.8x\n",
632 net_dev->name, inl(ioaddr + rxdp));
634 /* on each timer ticks we check two things, Link Status (ON/OFF) and
635 Link Mode (10/100/Full/Half)
637 static void sis900_timer(unsigned long data)
639 struct net_device *net_dev = (struct net_device *)data;
640 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
641 struct mii_phy *mii_phy = sis_priv->mii;
642 static int next_tick = 5*HZ;
643 u16 status;
645 status = mdio_read(net_dev, sis_priv->cur_phy, MII_STATUS);
647 /* current mii phy is failed to link, try another one */
648 while (!(status & MII_STAT_LINK)) {
649 if (mii_phy->next == NULL) {
650 if (sis_priv->LinkOn) {
651 /* link stat change from ON to OFF */
652 next_tick = HZ;
653 sis_priv->LinkOn = FALSE;
654 printk(KERN_INFO "%s: Media Link Off\n",
655 net_dev->name);
657 sis_priv->timer.expires = jiffies + next_tick;
658 add_timer(&sis_priv->timer);
659 return;
661 mii_phy = mii_phy->next;
662 status = mdio_read(net_dev, mii_phy->phy_addr, MII_STATUS);
665 if (!sis_priv->LinkOn) {
666 /* link stat change forn OFF to ON, read and report link mode */
667 sis_priv->LinkOn = TRUE;
668 next_tick = 5*HZ;
669 /* change what cur_phy means */
670 if (mii_phy->phy_addr != sis_priv->cur_phy) {
671 printk(KERN_INFO "%s: Changing transceiver to %s\n",
672 net_dev->name, mii_phy->chip_info->name);
673 status = mdio_read(net_dev, sis_priv->cur_phy, MII_CONTROL);
674 mdio_write(net_dev, sis_priv->cur_phy,
675 MII_CONTROL, status | MII_CNTL_ISOLATE);
676 status = mdio_read(net_dev, mii_phy->phy_addr, MII_CONTROL);
677 mdio_write(net_dev, mii_phy->phy_addr,
678 MII_CONTROL, status & ~MII_CNTL_ISOLATE);
679 sis_priv->cur_phy = mii_phy->phy_addr;
681 sis900_check_mode(net_dev, mii_phy);
684 sis_priv->timer.expires = jiffies + next_tick;
685 add_timer(&sis_priv->timer);
687 static void sis900_check_mode (struct net_device *net_dev, struct mii_phy *mii_phy)
689 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
690 long ioaddr = net_dev->base_addr;
691 int speed, duplex;
692 u32 tx_flags = 0, rx_flags = 0;
694 mii_phy->chip_info->read_mode(net_dev, sis_priv->cur_phy, &speed, &duplex);
696 tx_flags = TxATP | (TX_DMA_BURST << TxMXDMA_shift) | (TX_FILL_THRESH << TxFILLT_shift);
697 rx_flags = RX_DMA_BURST << RxMXDMA_shift;
699 if (speed == HW_SPEED_HOME || speed == HW_SPEED_10_MBPS ) {
700 rx_flags |= (RxDRNT_10 << RxDRNT_shift);
701 tx_flags |= (TxDRNT_10 << TxDRNT_shift);
703 else {
704 rx_flags |= (RxDRNT_100 << RxDRNT_shift);
705 tx_flags |= (TxDRNT_100 << TxDRNT_shift);
708 if (duplex == FDX_CAPABLE_FULL_SELECTED) {
709 tx_flags |= (TxCSI | TxHBI);
710 rx_flags |= RxATX;
713 outl (tx_flags, ioaddr + txcfg);
714 outl (rx_flags, ioaddr + rxcfg);
716 static void sis900_read_mode(struct net_device *net_dev, int phy_addr, int *speed, int *duplex)
718 int i = 0;
719 u32 status;
721 /* STSOUT register is Latched on Transition, read operation updates it */
722 while (i++ < 2)
723 status = mdio_read(net_dev, phy_addr, MII_STSOUT);
725 if (status & MII_STSOUT_SPD)
726 *speed = HW_SPEED_100_MBPS;
727 else
728 *speed = HW_SPEED_10_MBPS;
730 if (status & MII_STSOUT_DPLX)
731 *duplex = FDX_CAPABLE_FULL_SELECTED;
732 else
733 *duplex = FDX_CAPABLE_HALF_SELECTED;
735 if (status & MII_STSOUT_LINK_FAIL)
736 printk(KERN_INFO "%s: Media Link Off\n", net_dev->name);
737 else
738 printk(KERN_INFO "%s: Media Link On %s %s-duplex \n",
739 net_dev->name,
740 *speed == HW_SPEED_100_MBPS ?
741 "100mbps" : "10mbps",
742 *duplex == FDX_CAPABLE_FULL_SELECTED ?
743 "full" : "half");
745 static void amd79c901_read_mode(struct net_device *net_dev, int phy_addr, int *speed, int *duplex)
747 int i;
748 u16 status;
750 for (i = 0; i < 2; i++)
751 status = mdio_read(net_dev, phy_addr, MII_STATUS);
753 if (status & MII_STAT_CAN_AUTO) {
754 /* 10BASE-T PHY */
755 for (i = 0; i < 2; i++)
756 status = mdio_read(net_dev, phy_addr, MII_STATUS_SUMMARY);
757 if (status & MII_STSSUM_SPD)
758 *speed = HW_SPEED_100_MBPS;
759 else
760 *speed = HW_SPEED_10_MBPS;
761 if (status & MII_STSSUM_DPLX)
762 *duplex = FDX_CAPABLE_FULL_SELECTED;
763 else
764 *duplex = FDX_CAPABLE_HALF_SELECTED;
766 if (status & MII_STSSUM_LINK)
767 printk(KERN_INFO "%s: Media Link On %s %s-duplex \n",
768 net_dev->name,
769 *speed == HW_SPEED_100_MBPS ?
770 "100mbps" : "10mbps",
771 *duplex == FDX_CAPABLE_FULL_SELECTED ?
772 "full" : "half");
773 else
774 printk(KERN_INFO "%s: Media Link Off\n", net_dev->name);
777 else {
778 /* HomePNA */
779 *speed = HW_SPEED_HOME;
780 *duplex = FDX_CAPABLE_HALF_SELECTED;
781 if (status & MII_STAT_LINK)
782 printk(KERN_INFO "%s: Media Link On 1mbps half-duplex \n",
783 net_dev->name);
784 else
785 printk(KERN_INFO "%s: Media Link Off\n", net_dev->name);
788 static void sis900_tx_timeout(struct net_device *net_dev)
790 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
791 long ioaddr = net_dev->base_addr;
792 unsigned long flags;
793 int i;
795 printk(KERN_INFO "%s: Transmit timeout, status %8.8x %8.8x \n",
796 net_dev->name, inl(ioaddr + cr), inl(ioaddr + isr));
798 /* Disable interrupts by clearing the interrupt mask. */
799 outl(0x0000, ioaddr + imr);
801 /* use spinlock to prevent interrupt handler accessing buffer ring */
802 spin_lock_irqsave(&sis_priv->lock, flags);
804 /* discard unsent packets */
805 sis_priv->dirty_tx = sis_priv->cur_tx = 0;
806 for (i = 0; i < NUM_TX_DESC; i++) {
807 if (sis_priv->tx_skbuff[i] != NULL) {
808 dev_kfree_skb(sis_priv->tx_skbuff[i]);
809 sis_priv->tx_skbuff[i] = 0;
810 sis_priv->tx_ring[i].cmdsts = 0;
811 sis_priv->tx_ring[i].bufptr = 0;
812 sis_priv->stats.tx_dropped++;
815 sis_priv->tx_full = 0;
816 netif_wake_queue(net_dev);
818 spin_unlock_irqrestore(&sis_priv->lock, flags);
820 net_dev->trans_start = jiffies;
822 /* FIXME: Should we restart the transmission thread here ?? */
823 outl(TxENA, ioaddr + cr);
825 /* Enable all known interrupts by setting the interrupt mask. */
826 outl((RxSOVR|RxORN|RxERR|RxOK|TxURN|TxERR|TxIDLE), ioaddr + imr);
827 return;
830 static int
831 sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
833 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
834 long ioaddr = net_dev->base_addr;
835 unsigned int entry;
836 unsigned long flags;
838 spin_lock_irqsave(&sis_priv->lock, flags);
840 /* Calculate the next Tx descriptor entry. */
841 entry = sis_priv->cur_tx % NUM_TX_DESC;
842 sis_priv->tx_skbuff[entry] = skb;
844 /* set the transmit buffer descriptor and enable Transmit State Machine */
845 sis_priv->tx_ring[entry].bufptr = virt_to_bus(skb->data);
846 sis_priv->tx_ring[entry].cmdsts = (OWN | skb->len);
847 outl(TxENA, ioaddr + cr);
849 if (++sis_priv->cur_tx - sis_priv->dirty_tx < NUM_TX_DESC) {
850 /* Typical path, tell upper layer that more transmission is possible */
851 netif_start_queue(net_dev);
852 } else {
853 /* buffer full, tell upper layer no more transmission */
854 sis_priv->tx_full = 1;
855 netif_stop_queue(net_dev);
858 spin_unlock_irqrestore(&sis_priv->lock, flags);
860 net_dev->trans_start = jiffies;
862 if (sis900_debug > 3)
863 printk(KERN_INFO "%s: Queued Tx packet at %p size %d "
864 "to slot %d.\n",
865 net_dev->name, skb->data, (int)skb->len, entry);
867 return 0;
870 /* The interrupt handler does all of the Rx thread work and cleans up
871 after the Tx thread. */
872 static void sis900_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
874 struct net_device *net_dev = (struct net_device *)dev_instance;
875 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
876 int boguscnt = max_interrupt_work;
877 long ioaddr = net_dev->base_addr;
878 u32 status;
880 spin_lock (&sis_priv->lock);
882 do {
883 status = inl(ioaddr + isr);
885 if ((status & (HIBERR|TxURN|TxERR|TxIDLE|RxORN|RxERR|RxOK)) == 0)
886 /* nothing intresting happened */
887 break;
889 /* why dow't we break after Tx/Rx case ?? keyword: full-duplex */
890 if (status & (RxORN | RxERR | RxOK))
891 /* Rx interrupt */
892 sis900_rx(net_dev);
894 if (status & (TxURN | TxERR | TxIDLE))
895 /* Tx interrupt */
896 sis900_finish_xmit(net_dev);
898 /* something strange happened !!! */
899 if (status & HIBERR) {
900 printk(KERN_INFO "%s: Abnormal interrupt,"
901 "status %#8.8x.\n", net_dev->name, status);
902 break;
904 if (--boguscnt < 0) {
905 printk(KERN_INFO "%s: Too much work at interrupt, "
906 "interrupt status = %#8.8x.\n",
907 net_dev->name, status);
908 break;
910 } while (1);
912 if (sis900_debug > 3)
913 printk(KERN_INFO "%s: exiting interrupt, "
914 "interrupt status = 0x%#8.8x.\n",
915 net_dev->name, inl(ioaddr + isr));
917 spin_unlock (&sis_priv->lock);
918 return;
921 /* Process receive interrupt events, put buffer to higher layer and refill buffer pool
922 Note: This fucntion is called by interrupt handler, don't do "too much" work here */
923 static int sis900_rx(struct net_device *net_dev)
925 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
926 long ioaddr = net_dev->base_addr;
927 unsigned int entry = sis_priv->cur_rx % NUM_RX_DESC;
928 u32 rx_status = sis_priv->rx_ring[entry].cmdsts;
930 if (sis900_debug > 3)
931 printk(KERN_INFO "sis900_rx, cur_rx:%4.4d, dirty_rx:%4.4d "
932 "status:0x%8.8x\n",
933 sis_priv->cur_rx, sis_priv->dirty_rx, rx_status);
935 while (rx_status & OWN) {
936 unsigned int rx_size;
938 rx_size = (rx_status & DSIZE) - CRC_SIZE;
940 if (rx_status & (ABORT|OVERRUN|TOOLONG|RUNT|RXISERR|CRCERR|FAERR)) {
941 /* corrupted packet received */
942 if (sis900_debug > 3)
943 printk(KERN_INFO "%s: Corrupted packet "
944 "received, buffer status = 0x%8.8x.\n",
945 net_dev->name, rx_status);
946 sis_priv->stats.rx_errors++;
947 if (rx_status & OVERRUN)
948 sis_priv->stats.rx_over_errors++;
949 if (rx_status & (TOOLONG|RUNT))
950 sis_priv->stats.rx_length_errors++;
951 if (rx_status & (RXISERR | FAERR))
952 sis_priv->stats.rx_frame_errors++;
953 if (rx_status & CRCERR)
954 sis_priv->stats.rx_crc_errors++;
955 /* reset buffer descriptor state */
956 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
957 } else {
958 struct sk_buff * skb;
960 /* This situation should never happen, but due to
961 some unknow bugs, it is possible that
962 we are working on NULL sk_buff :-( */
963 if (sis_priv->rx_skbuff[entry] == NULL) {
964 printk(KERN_INFO "%s: NULL pointer "
965 "encountered in Rx ring, skipping\n",
966 net_dev->name);
967 break;
969 skb = sis_priv->rx_skbuff[entry];
970 sis_priv->rx_skbuff[entry] = NULL;
971 /* reset buffer descriptor state */
972 sis_priv->rx_ring[entry].cmdsts = 0;
973 sis_priv->rx_ring[entry].bufptr = 0;
975 skb_put(skb, rx_size);
976 skb->protocol = eth_type_trans(skb, net_dev);
977 netif_rx(skb);
979 if ((rx_status & BCAST) == MCAST)
980 sis_priv->stats.multicast++;
981 net_dev->last_rx = jiffies;
982 sis_priv->stats.rx_bytes += rx_size;
983 sis_priv->stats.rx_packets++;
985 sis_priv->cur_rx++;
986 entry = sis_priv->cur_rx % NUM_RX_DESC;
987 rx_status = sis_priv->rx_ring[entry].cmdsts;
988 } // while
990 /* refill the Rx buffer, what if the rate of refilling is slower than
991 consuming ?? */
992 for (;sis_priv->cur_rx - sis_priv->dirty_rx > 0; sis_priv->dirty_rx++) {
993 struct sk_buff *skb;
995 entry = sis_priv->dirty_rx % NUM_RX_DESC;
997 if (sis_priv->rx_skbuff[entry] == NULL) {
998 if ((skb = dev_alloc_skb(RX_BUF_SIZE)) == NULL) {
999 /* not enough memory for skbuff, this makes a "hole"
1000 on the buffer ring, it is not clear how the
1001 hardware will react to this kind of degenerated
1002 buffer */
1003 printk(KERN_INFO "%s: Memory squeeze,"
1004 "deferring packet.\n",
1005 net_dev->name);
1006 sis_priv->stats.rx_dropped++;
1007 break;
1009 skb->dev = net_dev;
1010 sis_priv->rx_skbuff[entry] = skb;
1011 sis_priv->rx_ring[entry].cmdsts = RX_BUF_SIZE;
1012 sis_priv->rx_ring[entry].bufptr = virt_to_bus(skb->tail);
1015 /* re-enable the potentially idle receive state matchine */
1016 outl(RxENA , ioaddr + cr );
1018 return 0;
1021 /* finish up transmission of packets, check for error condition and free skbuff etc.
1022 Note: This fucntion is called by interrupt handler, don't do "too much" work here */
1023 static void sis900_finish_xmit (struct net_device *net_dev)
1025 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
1027 for (; sis_priv->dirty_tx < sis_priv->cur_tx; sis_priv->dirty_tx++) {
1028 unsigned int entry;
1029 u32 tx_status;
1031 entry = sis_priv->dirty_tx % NUM_TX_DESC;
1032 tx_status = sis_priv->tx_ring[entry].cmdsts;
1034 if (tx_status & OWN) {
1035 /* The packet is not transmited yet (owned by hardware) !
1036 Note: the interrupt is generated only when Tx Machine
1037 is idle, so this is an almost impossible case */
1038 break;
1041 if (tx_status & (ABORT | UNDERRUN | OWCOLL)) {
1042 /* packet unsuccessfully transmited */
1043 if (sis900_debug > 3)
1044 printk(KERN_INFO "%s: Transmit "
1045 "error, Tx status %8.8x.\n",
1046 net_dev->name, tx_status);
1047 sis_priv->stats.tx_errors++;
1048 if (tx_status & UNDERRUN)
1049 sis_priv->stats.tx_fifo_errors++;
1050 if (tx_status & ABORT)
1051 sis_priv->stats.tx_aborted_errors++;
1052 if (tx_status & NOCARRIER)
1053 sis_priv->stats.tx_carrier_errors++;
1054 if (tx_status & OWCOLL)
1055 sis_priv->stats.tx_window_errors++;
1056 } else {
1057 /* packet successfully transmited */
1058 sis_priv->stats.collisions += (tx_status & COLCNT) >> 16;
1059 sis_priv->stats.tx_bytes += tx_status & DSIZE;
1060 sis_priv->stats.tx_packets++;
1062 /* Free the original skb. */
1063 dev_kfree_skb_irq(sis_priv->tx_skbuff[entry]);
1064 sis_priv->tx_skbuff[entry] = NULL;
1065 sis_priv->tx_ring[entry].bufptr = 0;
1066 sis_priv->tx_ring[entry].cmdsts = 0;
1069 if (sis_priv->tx_full && netif_queue_stopped(net_dev) &&
1070 sis_priv->cur_tx - sis_priv->dirty_tx < NUM_TX_DESC - 4) {
1071 /* The ring is no longer full, clear tx_full and schedule more transmission
1072 by netif_wake_queue(net_dev) */
1073 sis_priv->tx_full = 0;
1074 netif_wake_queue (net_dev);
1078 static int
1079 sis900_close(struct net_device *net_dev)
1081 long ioaddr = net_dev->base_addr;
1082 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
1083 int i;
1085 netif_stop_queue(net_dev);
1087 /* Disable interrupts by clearing the interrupt mask. */
1088 outl(0x0000, ioaddr + imr);
1089 outl(0x0000, ioaddr + ier);
1091 /* Stop the chip's Tx and Rx Status Machine */
1092 outl(RxDIS | TxDIS, ioaddr + cr);
1094 del_timer(&sis_priv->timer);
1096 free_irq(net_dev->irq, net_dev);
1098 /* Free Tx and RX skbuff */
1099 for (i = 0; i < NUM_RX_DESC; i++) {
1100 if (sis_priv->rx_skbuff[i] != NULL)
1101 dev_kfree_skb(sis_priv->rx_skbuff[i]);
1102 sis_priv->rx_skbuff[i] = 0;
1104 for (i = 0; i < NUM_TX_DESC; i++) {
1105 if (sis_priv->tx_skbuff[i] != NULL)
1106 dev_kfree_skb(sis_priv->tx_skbuff[i]);
1107 sis_priv->tx_skbuff[i] = 0;
1110 /* Green! Put the chip in low-power mode. */
1112 MOD_DEC_USE_COUNT;
1114 return 0;
1117 static int mii_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd)
1119 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
1120 u16 *data = (u16 *)&rq->ifr_data;
1122 switch(cmd) {
1123 case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
1124 data[0] = sis_priv->mii->phy_addr;
1125 /* Fall Through */
1126 case SIOCDEVPRIVATE+1: /* Read the specified MII register. */
1127 data[3] = mdio_read(net_dev, data[0] & 0x1f, data[1] & 0x1f);
1128 return 0;
1129 case SIOCDEVPRIVATE+2: /* Write the specified MII register */
1130 if (!capable(CAP_NET_ADMIN))
1131 return -EPERM;
1132 mdio_write(net_dev, data[0] & 0x1f, data[1] & 0x1f, data[2]);
1133 return 0;
1134 default:
1135 return -EOPNOTSUPP;
1139 static struct enet_statistics *
1140 sis900_get_stats(struct net_device *net_dev)
1142 struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
1144 return &sis_priv->stats;
1147 /* SiS 900 uses the most sigificant 7 bits to index a 128 bits multicast hash table, which makes
1148 this function a little bit different from other drivers */
1149 static u16 sis900_compute_hashtable_index(u8 *addr)
1152 /* what is the correct value of the POLYNOMIAL ??
1153 Donald Becker use 0x04C11DB7U
1154 Joseph Zbiciak im14u2c@primenet.com gives me the
1155 correct answer, thank you Joe !! */
1156 #define POLYNOMIAL 0x04C11DB7L
1157 u32 crc = 0xffffffff, msb;
1158 int i, j;
1159 u32 byte;
1161 for (i = 0; i < 6; i++) {
1162 byte = *addr++;
1163 for (j = 0; j < 8; j++) {
1164 msb = crc >> 31;
1165 crc <<= 1;
1166 if (msb ^ (byte & 1)) {
1167 crc ^= POLYNOMIAL;
1169 byte >>= 1;
1172 /* leave 7 most siginifant bits */
1173 return ((int)(crc >> 25));
1176 static void set_rx_mode(struct net_device *net_dev)
1178 long ioaddr = net_dev->base_addr;
1179 u16 mc_filter[8]; /* 128 bits multicast hash table */
1180 int i;
1181 u32 rx_mode;
1183 if (net_dev->flags & IFF_PROMISC) {
1184 /* Accept any kinds of packets */
1185 rx_mode = RFPromiscuous;
1186 for (i = 0; i < 8; i++)
1187 mc_filter[i] = 0xffff;
1188 } else if ((net_dev->mc_count > multicast_filter_limit) ||
1189 (net_dev->flags & IFF_ALLMULTI)) {
1190 /* too many multicast addresses or accept all multicast packet */
1191 rx_mode = RFAAB | RFAAM;
1192 for (i = 0; i < 8; i++)
1193 mc_filter[i] = 0xffff;
1194 } else {
1195 /* Accept Broadcast packet, destination address matchs our MAC address,
1196 use Receive Filter to reject unwanted MCAST packet */
1197 struct dev_mc_list *mclist;
1198 rx_mode = RFAAB;
1199 for (i = 0; i < 8; i++)
1200 mc_filter[i]=0;
1201 for (i = 0, mclist = net_dev->mc_list; mclist && i < net_dev->mc_count;
1202 i++, mclist = mclist->next)
1203 set_bit(sis900_compute_hashtable_index(mclist->dmi_addr),
1204 mc_filter);
1207 /* update Multicast Hash Table in Receive Filter */
1208 for (i = 0; i < 8; i++) {
1209 /* why plus 0x04 ??, That makes the correct value for hash table. */
1210 outl((u32)(0x00000004+i) << RFADDR_shift, ioaddr + rfcr);
1211 outl(mc_filter[i], ioaddr + rfdr);
1214 outl(RFEN | rx_mode, ioaddr + rfcr);
1216 /* sis900 is capatable of looping back packet at MAC level for debugging purpose */
1217 if (net_dev->flags & IFF_LOOPBACK) {
1218 u32 cr_saved;
1219 /* We must disable Tx/Rx before setting loopback mode */
1220 cr_saved = inl(ioaddr + cr);
1221 outl(cr_saved | TxDIS | RxDIS, ioaddr + cr);
1222 /* enable loopback */
1223 outl(inl(ioaddr + txcfg) | TxMLB, ioaddr + txcfg);
1224 outl(inl(ioaddr + rxcfg) | RxATX, ioaddr + rxcfg);
1225 /* restore cr */
1226 outl(cr_saved, ioaddr + cr);
1229 return;
1232 static void sis900_reset(struct net_device *net_dev)
1234 long ioaddr = net_dev->base_addr;
1235 int i = 0;
1236 u32 status = TxRCMP | RxRCMP;
1238 outl(0, ioaddr + ier);
1239 outl(0, ioaddr + imr);
1240 outl(0, ioaddr + rfcr);
1242 outl(RxRESET | TxRESET | RESET, ioaddr + cr);
1244 /* Check that the chip has finished the reset. */
1245 while (status && (i++ < 1000)) {
1246 status ^= (inl(isr + ioaddr) & status);
1249 outl(PESEL, ioaddr + cfg);
1252 static void __exit sis900_cleanup_module(void)
1254 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1255 while (root_sis900_dev) {
1256 struct sis900_private *sis_priv =
1257 (struct sis900_private *)root_sis900_dev->priv;
1258 struct net_device *next_dev = sis_priv->next_module;
1260 unregister_netdev(root_sis900_dev);
1261 release_region(root_sis900_dev->base_addr,
1262 sis_priv->mac->io_size);
1263 kfree(sis_priv);
1264 kfree(root_sis900_dev);
1266 root_sis900_dev = next_dev;
1270 module_init(sis900_probe);
1271 module_exit(sis900_cleanup_module);