3 #include <linux/module.h>
4 #include <linux/moduleparam.h>
5 #include <linux/kernel.h>
6 #include <linux/sched.h>
7 #include <linux/string.h>
8 #include <linux/timer.h>
9 #include <linux/errno.h>
10 #include <linux/ioport.h>
11 #include <linux/slab.h>
12 #include <linux/interrupt.h>
13 #include <linux/pci.h>
14 #include <linux/netdevice.h>
15 #include <linux/init.h>
16 #include <linux/mii.h>
17 #include <linux/etherdevice.h>
18 #include <linux/skbuff.h>
19 #include <linux/delay.h>
20 #include <linux/ethtool.h>
21 #include <linux/crc32.h>
22 #include <linux/bitops.h>
23 #include <linux/dma-mapping.h>
25 #include <asm/processor.h> /* Processor type for cache alignment. */
28 #include <asm/uaccess.h> /* User space memory access functions */
32 #define SIS900_MODULE_NAME "sis900"
33 #define SIS900_DRV_VERSION "v1.08.10 Apr. 2 2006"
35 static const char version
[] __devinitconst
=
36 KERN_INFO
"sis900.c: " SIS900_DRV_VERSION
"\n";
38 static int max_interrupt_work
= 40;
39 static int multicast_filter_limit
= 128;
41 static int sis900_debug
= -1; /* Use SIS900_DEF_MSG as value */
43 #define SIS900_DEF_MSG \
49 /* Time in jiffies before concluding the transmitter is hung. */
50 #define TX_TIMEOUT (4*HZ)
56 static const char * card_names
[] = {
57 "SiS 900 PCI Fast Ethernet",
58 "SiS 7016 PCI Fast Ethernet"
60 static DEFINE_PCI_DEVICE_TABLE(sis900_pci_tbl
) = {
61 {PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_900
,
62 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, SIS_900
},
63 {PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_7016
,
64 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, SIS_7016
},
67 MODULE_DEVICE_TABLE (pci
, sis900_pci_tbl
);
69 static void sis900_read_mode(struct net_device
*net_dev
, int *speed
, int *duplex
);
71 static const struct mii_chip_info
{
80 } mii_chip_table
[] = {
81 { "SiS 900 Internal MII PHY", 0x001d, 0x8000, LAN
},
82 { "SiS 7014 Physical Layer Solution", 0x0016, 0xf830, LAN
},
83 { "SiS 900 on Foxconn 661 7MI", 0x0143, 0xBC70, LAN
},
84 { "Altimata AC101LF PHY", 0x0022, 0x5520, LAN
},
85 { "ADM 7001 LAN PHY", 0x002e, 0xcc60, LAN
},
86 { "AMD 79C901 10BASE-T PHY", 0x0000, 0x6B70, LAN
},
87 { "AMD 79C901 HomePNA PHY", 0x0000, 0x6B90, HOME
},
88 { "ICS LAN PHY", 0x0015, 0xF440, LAN
},
89 { "ICS LAN PHY", 0x0143, 0xBC70, LAN
},
90 { "NS 83851 PHY", 0x2000, 0x5C20, MIX
},
91 { "NS 83847 PHY", 0x2000, 0x5C30, MIX
},
92 { "Realtek RTL8201 PHY", 0x0000, 0x8200, LAN
},
93 { "VIA 6103 PHY", 0x0101, 0x8f20, LAN
},
98 struct mii_phy
* next
;
106 typedef struct _BufferDesc
{
112 struct sis900_private
{
113 struct pci_dev
* pci_dev
;
117 struct mii_phy
* mii
;
118 struct mii_phy
* first_mii
; /* record the first mii structure */
119 unsigned int cur_phy
;
120 struct mii_if_info mii_info
;
122 struct timer_list timer
; /* Link status detection timer. */
123 u8 autong_complete
; /* 1: auto-negotiate complete */
127 unsigned int cur_rx
, dirty_rx
; /* producer/comsumer pointers for Tx/Rx ring */
128 unsigned int cur_tx
, dirty_tx
;
130 /* The saved address of a sent/receive-in-place packet buffer */
131 struct sk_buff
*tx_skbuff
[NUM_TX_DESC
];
132 struct sk_buff
*rx_skbuff
[NUM_RX_DESC
];
136 dma_addr_t tx_ring_dma
;
137 dma_addr_t rx_ring_dma
;
139 unsigned int tx_full
; /* The Tx queue is full. */
144 MODULE_AUTHOR("Jim Huang <cmhuang@sis.com.tw>, Ollie Lho <ollie@sis.com.tw>");
145 MODULE_DESCRIPTION("SiS 900 PCI Fast Ethernet driver");
146 MODULE_LICENSE("GPL");
148 module_param(multicast_filter_limit
, int, 0444);
149 module_param(max_interrupt_work
, int, 0444);
150 module_param(sis900_debug
, int, 0444);
151 MODULE_PARM_DESC(multicast_filter_limit
, "SiS 900/7016 maximum number of filtered multicast addresses");
152 MODULE_PARM_DESC(max_interrupt_work
, "SiS 900/7016 maximum events handled per interrupt");
153 MODULE_PARM_DESC(sis900_debug
, "SiS 900/7016 bitmapped debugging message level");
155 #ifdef CONFIG_NET_POLL_CONTROLLER
156 static void sis900_poll(struct net_device
*dev
);
158 static int sis900_open(struct net_device
*net_dev
);
159 static int sis900_mii_probe (struct net_device
* net_dev
);
160 static void sis900_init_rxfilter (struct net_device
* net_dev
);
161 static u16
read_eeprom(long ioaddr
, int location
);
162 static int mdio_read(struct net_device
*net_dev
, int phy_id
, int location
);
163 static void mdio_write(struct net_device
*net_dev
, int phy_id
, int location
, int val
);
164 static void sis900_timer(unsigned long data
);
165 static void sis900_check_mode (struct net_device
*net_dev
, struct mii_phy
*mii_phy
);
166 static void sis900_tx_timeout(struct net_device
*net_dev
);
167 static void sis900_init_tx_ring(struct net_device
*net_dev
);
168 static void sis900_init_rx_ring(struct net_device
*net_dev
);
169 static netdev_tx_t
sis900_start_xmit(struct sk_buff
*skb
,
170 struct net_device
*net_dev
);
171 static int sis900_rx(struct net_device
*net_dev
);
172 static void sis900_finish_xmit (struct net_device
*net_dev
);
173 static irqreturn_t
sis900_interrupt(int irq
, void *dev_instance
);
174 static int sis900_close(struct net_device
*net_dev
);
175 static int mii_ioctl(struct net_device
*net_dev
, struct ifreq
*rq
, int cmd
);
176 static u16
sis900_mcast_bitnr(u8
*addr
, u8 revision
);
177 static void set_rx_mode(struct net_device
*net_dev
);
178 static void sis900_reset(struct net_device
*net_dev
);
179 static void sis630_set_eq(struct net_device
*net_dev
, u8 revision
);
180 static int sis900_set_config(struct net_device
*dev
, struct ifmap
*map
);
181 static u16
sis900_default_phy(struct net_device
* net_dev
);
182 static void sis900_set_capability( struct net_device
*net_dev
,struct mii_phy
*phy
);
183 static u16
sis900_reset_phy(struct net_device
*net_dev
, int phy_addr
);
184 static void sis900_auto_negotiate(struct net_device
*net_dev
, int phy_addr
);
185 static void sis900_set_mode (long ioaddr
, int speed
, int duplex
);
186 static const struct ethtool_ops sis900_ethtool_ops
;
189 * sis900_get_mac_addr - Get MAC address for stand alone SiS900 model
190 * @pci_dev: the sis900 pci device
191 * @net_dev: the net device to get address for
193 * Older SiS900 and friends, use EEPROM to store MAC address.
194 * MAC address is read from read_eeprom() into @net_dev->dev_addr.
197 static int __devinit
sis900_get_mac_addr(struct pci_dev
* pci_dev
, struct net_device
*net_dev
)
199 long ioaddr
= pci_resource_start(pci_dev
, 0);
203 /* check to see if we have sane EEPROM */
204 signature
= (u16
) read_eeprom(ioaddr
, EEPROMSignature
);
205 if (signature
== 0xffff || signature
== 0x0000) {
206 printk (KERN_WARNING
"%s: Error EERPOM read %x\n",
207 pci_name(pci_dev
), signature
);
211 /* get MAC address from EEPROM */
212 for (i
= 0; i
< 3; i
++)
213 ((u16
*)(net_dev
->dev_addr
))[i
] = read_eeprom(ioaddr
, i
+EEPROMMACAddr
);
219 * sis630e_get_mac_addr - Get MAC address for SiS630E model
220 * @pci_dev: the sis900 pci device
221 * @net_dev: the net device to get address for
223 * SiS630E model, use APC CMOS RAM to store MAC address.
224 * APC CMOS RAM is accessed through ISA bridge.
225 * MAC address is read into @net_dev->dev_addr.
228 static int __devinit
sis630e_get_mac_addr(struct pci_dev
* pci_dev
,
229 struct net_device
*net_dev
)
231 struct pci_dev
*isa_bridge
= NULL
;
235 isa_bridge
= pci_get_device(PCI_VENDOR_ID_SI
, 0x0008, isa_bridge
);
237 isa_bridge
= pci_get_device(PCI_VENDOR_ID_SI
, 0x0018, isa_bridge
);
239 printk(KERN_WARNING
"%s: Can not find ISA bridge\n",
243 pci_read_config_byte(isa_bridge
, 0x48, ®
);
244 pci_write_config_byte(isa_bridge
, 0x48, reg
| 0x40);
246 for (i
= 0; i
< 6; i
++) {
247 outb(0x09 + i
, 0x70);
248 ((u8
*)(net_dev
->dev_addr
))[i
] = inb(0x71);
250 pci_write_config_byte(isa_bridge
, 0x48, reg
& ~0x40);
251 pci_dev_put(isa_bridge
);
258 * sis635_get_mac_addr - Get MAC address for SIS635 model
259 * @pci_dev: the sis900 pci device
260 * @net_dev: the net device to get address for
262 * SiS635 model, set MAC Reload Bit to load Mac address from APC
263 * to rfdr. rfdr is accessed through rfcr. MAC address is read into
264 * @net_dev->dev_addr.
267 static int __devinit
sis635_get_mac_addr(struct pci_dev
* pci_dev
,
268 struct net_device
*net_dev
)
270 long ioaddr
= net_dev
->base_addr
;
274 rfcrSave
= inl(rfcr
+ ioaddr
);
276 outl(rfcrSave
| RELOAD
, ioaddr
+ cr
);
277 outl(0, ioaddr
+ cr
);
279 /* disable packet filtering before setting filter */
280 outl(rfcrSave
& ~RFEN
, rfcr
+ ioaddr
);
282 /* load MAC addr to filter data register */
283 for (i
= 0 ; i
< 3 ; i
++) {
284 outl((i
<< RFADDR_shift
), ioaddr
+ rfcr
);
285 *( ((u16
*)net_dev
->dev_addr
) + i
) = inw(ioaddr
+ rfdr
);
288 /* enable packet filtering */
289 outl(rfcrSave
| RFEN
, rfcr
+ ioaddr
);
295 * sis96x_get_mac_addr - Get MAC address for SiS962 or SiS963 model
296 * @pci_dev: the sis900 pci device
297 * @net_dev: the net device to get address for
299 * SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM
301 * LAN and 1394. When access EEPROM, send EEREQ signal to hardware first
302 * and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access
303 * by LAN, otherwise is not. After MAC address is read from EEPROM, send
304 * EEDONE signal to refuse EEPROM access by LAN.
305 * The EEPROM map of SiS962 or SiS963 is different to SiS900.
306 * The signature field in SiS962 or SiS963 spec is meaningless.
307 * MAC address is read into @net_dev->dev_addr.
310 static int __devinit
sis96x_get_mac_addr(struct pci_dev
* pci_dev
,
311 struct net_device
*net_dev
)
313 long ioaddr
= net_dev
->base_addr
;
314 long ee_addr
= ioaddr
+ mear
;
318 outl(EEREQ
, ee_addr
);
319 while(waittime
< 2000) {
320 if(inl(ee_addr
) & EEGNT
) {
322 /* get MAC address from EEPROM */
323 for (i
= 0; i
< 3; i
++)
324 ((u16
*)(net_dev
->dev_addr
))[i
] = read_eeprom(ioaddr
, i
+EEPROMMACAddr
);
326 outl(EEDONE
, ee_addr
);
333 outl(EEDONE
, ee_addr
);
337 static const struct net_device_ops sis900_netdev_ops
= {
338 .ndo_open
= sis900_open
,
339 .ndo_stop
= sis900_close
,
340 .ndo_start_xmit
= sis900_start_xmit
,
341 .ndo_set_config
= sis900_set_config
,
342 .ndo_set_multicast_list
= set_rx_mode
,
343 .ndo_change_mtu
= eth_change_mtu
,
344 .ndo_validate_addr
= eth_validate_addr
,
345 .ndo_set_mac_address
= eth_mac_addr
,
346 .ndo_do_ioctl
= mii_ioctl
,
347 .ndo_tx_timeout
= sis900_tx_timeout
,
348 #ifdef CONFIG_NET_POLL_CONTROLLER
349 .ndo_poll_controller
= sis900_poll
,
354 * sis900_probe - Probe for sis900 device
355 * @pci_dev: the sis900 pci device
356 * @pci_id: the pci device ID
358 * Check and probe sis900 net device for @pci_dev.
359 * Get mac address according to the chip revision,
360 * and assign SiS900-specific entries in the device structure.
361 * ie: sis900_open(), sis900_start_xmit(), sis900_close(), etc.
364 static int __devinit
sis900_probe(struct pci_dev
*pci_dev
,
365 const struct pci_device_id
*pci_id
)
367 struct sis900_private
*sis_priv
;
368 struct net_device
*net_dev
;
374 const char *card_name
= card_names
[pci_id
->driver_data
];
375 const char *dev_name
= pci_name(pci_dev
);
377 /* when built into the kernel, we only print version if device is found */
379 static int printed_version
;
380 if (!printed_version
++)
384 /* setup various bits in PCI command register */
385 ret
= pci_enable_device(pci_dev
);
388 i
= pci_set_dma_mask(pci_dev
, DMA_BIT_MASK(32));
390 printk(KERN_ERR
"sis900.c: architecture does not support "
391 "32bit PCI busmaster DMA\n");
395 pci_set_master(pci_dev
);
397 net_dev
= alloc_etherdev(sizeof(struct sis900_private
));
400 SET_NETDEV_DEV(net_dev
, &pci_dev
->dev
);
402 /* We do a request_region() to register /proc/ioports info. */
403 ioaddr
= pci_resource_start(pci_dev
, 0);
404 ret
= pci_request_regions(pci_dev
, "sis900");
408 sis_priv
= netdev_priv(net_dev
);
409 net_dev
->base_addr
= ioaddr
;
410 net_dev
->irq
= pci_dev
->irq
;
411 sis_priv
->pci_dev
= pci_dev
;
412 spin_lock_init(&sis_priv
->lock
);
414 pci_set_drvdata(pci_dev
, net_dev
);
416 ring_space
= pci_alloc_consistent(pci_dev
, TX_TOTAL_SIZE
, &ring_dma
);
419 goto err_out_cleardev
;
421 sis_priv
->tx_ring
= (BufferDesc
*)ring_space
;
422 sis_priv
->tx_ring_dma
= ring_dma
;
424 ring_space
= pci_alloc_consistent(pci_dev
, RX_TOTAL_SIZE
, &ring_dma
);
429 sis_priv
->rx_ring
= (BufferDesc
*)ring_space
;
430 sis_priv
->rx_ring_dma
= ring_dma
;
432 /* The SiS900-specific entries in the device structure. */
433 net_dev
->netdev_ops
= &sis900_netdev_ops
;
434 net_dev
->watchdog_timeo
= TX_TIMEOUT
;
435 net_dev
->ethtool_ops
= &sis900_ethtool_ops
;
437 if (sis900_debug
> 0)
438 sis_priv
->msg_enable
= sis900_debug
;
440 sis_priv
->msg_enable
= SIS900_DEF_MSG
;
442 sis_priv
->mii_info
.dev
= net_dev
;
443 sis_priv
->mii_info
.mdio_read
= mdio_read
;
444 sis_priv
->mii_info
.mdio_write
= mdio_write
;
445 sis_priv
->mii_info
.phy_id_mask
= 0x1f;
446 sis_priv
->mii_info
.reg_num_mask
= 0x1f;
448 /* Get Mac address according to the chip revision */
449 pci_read_config_byte(pci_dev
, PCI_CLASS_REVISION
, &(sis_priv
->chipset_rev
));
450 if(netif_msg_probe(sis_priv
))
451 printk(KERN_DEBUG
"%s: detected revision %2.2x, "
452 "trying to get MAC address...\n",
453 dev_name
, sis_priv
->chipset_rev
);
456 if (sis_priv
->chipset_rev
== SIS630E_900_REV
)
457 ret
= sis630e_get_mac_addr(pci_dev
, net_dev
);
458 else if ((sis_priv
->chipset_rev
> 0x81) && (sis_priv
->chipset_rev
<= 0x90) )
459 ret
= sis635_get_mac_addr(pci_dev
, net_dev
);
460 else if (sis_priv
->chipset_rev
== SIS96x_900_REV
)
461 ret
= sis96x_get_mac_addr(pci_dev
, net_dev
);
463 ret
= sis900_get_mac_addr(pci_dev
, net_dev
);
465 if (!ret
|| !is_valid_ether_addr(net_dev
->dev_addr
)) {
466 random_ether_addr(net_dev
->dev_addr
);
467 printk(KERN_WARNING
"%s: Unreadable or invalid MAC address,"
468 "using random generated one\n", dev_name
);
471 /* 630ET : set the mii access mode as software-mode */
472 if (sis_priv
->chipset_rev
== SIS630ET_900_REV
)
473 outl(ACCESSMODE
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
475 /* probe for mii transceiver */
476 if (sis900_mii_probe(net_dev
) == 0) {
477 printk(KERN_WARNING
"%s: Error probing MII device.\n",
483 /* save our host bridge revision */
484 dev
= pci_get_device(PCI_VENDOR_ID_SI
, PCI_DEVICE_ID_SI_630
, NULL
);
486 pci_read_config_byte(dev
, PCI_CLASS_REVISION
, &sis_priv
->host_bridge_rev
);
490 ret
= register_netdev(net_dev
);
494 /* print some information about our NIC */
495 printk(KERN_INFO
"%s: %s at %#lx, IRQ %d, %pM\n",
496 net_dev
->name
, card_name
, ioaddr
, net_dev
->irq
,
499 /* Detect Wake on Lan support */
500 ret
= (inl(net_dev
->base_addr
+ CFGPMC
) & PMESP
) >> 27;
501 if (netif_msg_probe(sis_priv
) && (ret
& PME_D3C
) == 0)
502 printk(KERN_INFO
"%s: Wake on LAN only available from suspend to RAM.", net_dev
->name
);
507 pci_free_consistent(pci_dev
, RX_TOTAL_SIZE
, sis_priv
->rx_ring
,
508 sis_priv
->rx_ring_dma
);
510 pci_free_consistent(pci_dev
, TX_TOTAL_SIZE
, sis_priv
->tx_ring
,
511 sis_priv
->tx_ring_dma
);
513 pci_set_drvdata(pci_dev
, NULL
);
514 pci_release_regions(pci_dev
);
516 free_netdev(net_dev
);
521 * sis900_mii_probe - Probe MII PHY for sis900
522 * @net_dev: the net device to probe for
524 * Search for total of 32 possible mii phy addresses.
525 * Identify and set current phy if found one,
526 * return error if it failed to found.
529 static int __devinit
sis900_mii_probe(struct net_device
* net_dev
)
531 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
532 const char *dev_name
= pci_name(sis_priv
->pci_dev
);
533 u16 poll_bit
= MII_STAT_LINK
, status
= 0;
534 unsigned long timeout
= jiffies
+ 5 * HZ
;
537 sis_priv
->mii
= NULL
;
539 /* search for total of 32 possible mii phy addresses */
540 for (phy_addr
= 0; phy_addr
< 32; phy_addr
++) {
541 struct mii_phy
* mii_phy
= NULL
;
546 for(i
= 0; i
< 2; i
++)
547 mii_status
= mdio_read(net_dev
, phy_addr
, MII_STATUS
);
549 if (mii_status
== 0xffff || mii_status
== 0x0000) {
550 if (netif_msg_probe(sis_priv
))
551 printk(KERN_DEBUG
"%s: MII at address %d"
557 if ((mii_phy
= kmalloc(sizeof(struct mii_phy
), GFP_KERNEL
)) == NULL
) {
558 printk(KERN_WARNING
"Cannot allocate mem for struct mii_phy\n");
559 mii_phy
= sis_priv
->first_mii
;
563 mii_phy
= mii_phy
->next
;
569 mii_phy
->phy_id0
= mdio_read(net_dev
, phy_addr
, MII_PHY_ID0
);
570 mii_phy
->phy_id1
= mdio_read(net_dev
, phy_addr
, MII_PHY_ID1
);
571 mii_phy
->phy_addr
= phy_addr
;
572 mii_phy
->status
= mii_status
;
573 mii_phy
->next
= sis_priv
->mii
;
574 sis_priv
->mii
= mii_phy
;
575 sis_priv
->first_mii
= mii_phy
;
577 for (i
= 0; mii_chip_table
[i
].phy_id1
; i
++)
578 if ((mii_phy
->phy_id0
== mii_chip_table
[i
].phy_id0
) &&
579 ((mii_phy
->phy_id1
& 0xFFF0) == mii_chip_table
[i
].phy_id1
)){
580 mii_phy
->phy_types
= mii_chip_table
[i
].phy_types
;
581 if (mii_chip_table
[i
].phy_types
== MIX
)
583 (mii_status
& (MII_STAT_CAN_TX_FDX
| MII_STAT_CAN_TX
)) ? LAN
: HOME
;
584 printk(KERN_INFO
"%s: %s transceiver found "
587 mii_chip_table
[i
].name
,
592 if( !mii_chip_table
[i
].phy_id1
) {
593 printk(KERN_INFO
"%s: Unknown PHY transceiver found at address %d.\n",
595 mii_phy
->phy_types
= UNKNOWN
;
599 if (sis_priv
->mii
== NULL
) {
600 printk(KERN_INFO
"%s: No MII transceivers found!\n", dev_name
);
604 /* select default PHY for mac */
605 sis_priv
->mii
= NULL
;
606 sis900_default_phy( net_dev
);
608 /* Reset phy if default phy is internal sis900 */
609 if ((sis_priv
->mii
->phy_id0
== 0x001D) &&
610 ((sis_priv
->mii
->phy_id1
&0xFFF0) == 0x8000))
611 status
= sis900_reset_phy(net_dev
, sis_priv
->cur_phy
);
613 if ((sis_priv
->mii
->phy_id0
== 0x0015) &&
614 ((sis_priv
->mii
->phy_id1
&0xFFF0) == 0xF440))
615 mdio_write(net_dev
, sis_priv
->cur_phy
, 0x0018, 0xD200);
617 if(status
& MII_STAT_LINK
){
621 poll_bit
^= (mdio_read(net_dev
, sis_priv
->cur_phy
, MII_STATUS
) & poll_bit
);
622 if (time_after_eq(jiffies
, timeout
)) {
623 printk(KERN_WARNING
"%s: reset phy and link down now\n",
630 if (sis_priv
->chipset_rev
== SIS630E_900_REV
) {
631 /* SiS 630E has some bugs on default value of PHY registers */
632 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_ANADV
, 0x05e1);
633 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_CONFIG1
, 0x22);
634 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_CONFIG2
, 0xff00);
635 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_MASK
, 0xffc0);
636 //mdio_write(net_dev, sis_priv->cur_phy, MII_CONTROL, 0x1000);
639 if (sis_priv
->mii
->status
& MII_STAT_LINK
)
640 netif_carrier_on(net_dev
);
642 netif_carrier_off(net_dev
);
648 * sis900_default_phy - Select default PHY for sis900 mac.
649 * @net_dev: the net device to probe for
651 * Select first detected PHY with link as default.
652 * If no one is link on, select PHY whose types is HOME as default.
653 * If HOME doesn't exist, select LAN.
656 static u16
sis900_default_phy(struct net_device
* net_dev
)
658 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
659 struct mii_phy
*phy
= NULL
, *phy_home
= NULL
,
660 *default_phy
= NULL
, *phy_lan
= NULL
;
663 for (phy
=sis_priv
->first_mii
; phy
; phy
=phy
->next
) {
664 status
= mdio_read(net_dev
, phy
->phy_addr
, MII_STATUS
);
665 status
= mdio_read(net_dev
, phy
->phy_addr
, MII_STATUS
);
667 /* Link ON & Not select default PHY & not ghost PHY */
668 if ((status
& MII_STAT_LINK
) && !default_phy
&&
669 (phy
->phy_types
!= UNKNOWN
))
672 status
= mdio_read(net_dev
, phy
->phy_addr
, MII_CONTROL
);
673 mdio_write(net_dev
, phy
->phy_addr
, MII_CONTROL
,
674 status
| MII_CNTL_AUTO
| MII_CNTL_ISOLATE
);
675 if (phy
->phy_types
== HOME
)
677 else if(phy
->phy_types
== LAN
)
682 if (!default_phy
&& phy_home
)
683 default_phy
= phy_home
;
684 else if (!default_phy
&& phy_lan
)
685 default_phy
= phy_lan
;
686 else if (!default_phy
)
687 default_phy
= sis_priv
->first_mii
;
689 if (sis_priv
->mii
!= default_phy
) {
690 sis_priv
->mii
= default_phy
;
691 sis_priv
->cur_phy
= default_phy
->phy_addr
;
692 printk(KERN_INFO
"%s: Using transceiver found at address %d as default\n",
693 pci_name(sis_priv
->pci_dev
), sis_priv
->cur_phy
);
696 sis_priv
->mii_info
.phy_id
= sis_priv
->cur_phy
;
698 status
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_CONTROL
);
699 status
&= (~MII_CNTL_ISOLATE
);
701 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_CONTROL
, status
);
702 status
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_STATUS
);
703 status
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_STATUS
);
710 * sis900_set_capability - set the media capability of network adapter.
711 * @net_dev : the net device to probe for
714 * Set the media capability of network adapter according to
715 * mii status register. It's necessary before auto-negotiate.
718 static void sis900_set_capability(struct net_device
*net_dev
, struct mii_phy
*phy
)
723 status
= mdio_read(net_dev
, phy
->phy_addr
, MII_STATUS
);
724 status
= mdio_read(net_dev
, phy
->phy_addr
, MII_STATUS
);
726 cap
= MII_NWAY_CSMA_CD
|
727 ((phy
->status
& MII_STAT_CAN_TX_FDX
)? MII_NWAY_TX_FDX
:0) |
728 ((phy
->status
& MII_STAT_CAN_TX
) ? MII_NWAY_TX
:0) |
729 ((phy
->status
& MII_STAT_CAN_T_FDX
) ? MII_NWAY_T_FDX
:0)|
730 ((phy
->status
& MII_STAT_CAN_T
) ? MII_NWAY_T
:0);
732 mdio_write(net_dev
, phy
->phy_addr
, MII_ANADV
, cap
);
736 /* Delay between EEPROM clock transitions. */
737 #define eeprom_delay() inl(ee_addr)
740 * read_eeprom - Read Serial EEPROM
741 * @ioaddr: base i/o address
742 * @location: the EEPROM location to read
744 * Read Serial EEPROM through EEPROM Access Register.
745 * Note that location is in word (16 bits) unit
748 static u16 __devinit
read_eeprom(long ioaddr
, int location
)
752 long ee_addr
= ioaddr
+ mear
;
753 u32 read_cmd
= location
| EEread
;
760 /* Shift the read command (9) bits out. */
761 for (i
= 8; i
>= 0; i
--) {
762 u32 dataval
= (read_cmd
& (1 << i
)) ? EEDI
| EECS
: EECS
;
763 outl(dataval
, ee_addr
);
765 outl(dataval
| EECLK
, ee_addr
);
771 /* read the 16-bits data in */
772 for (i
= 16; i
> 0; i
--) {
775 outl(EECS
| EECLK
, ee_addr
);
777 retval
= (retval
<< 1) | ((inl(ee_addr
) & EEDO
) ? 1 : 0);
781 /* Terminate the EEPROM access. */
788 /* Read and write the MII management registers using software-generated
789 serial MDIO protocol. Note that the command bits and data bits are
790 send out separately */
791 #define mdio_delay() inl(mdio_addr)
793 static void mdio_idle(long mdio_addr
)
795 outl(MDIO
| MDDIR
, mdio_addr
);
797 outl(MDIO
| MDDIR
| MDC
, mdio_addr
);
800 /* Syncronize the MII management interface by shifting 32 one bits out. */
801 static void mdio_reset(long mdio_addr
)
805 for (i
= 31; i
>= 0; i
--) {
806 outl(MDDIR
| MDIO
, mdio_addr
);
808 outl(MDDIR
| MDIO
| MDC
, mdio_addr
);
814 * mdio_read - read MII PHY register
815 * @net_dev: the net device to read
816 * @phy_id: the phy address to read
817 * @location: the phy regiester id to read
819 * Read MII registers through MDIO and MDC
820 * using MDIO management frame structure and protocol(defined by ISO/IEC).
821 * Please see SiS7014 or ICS spec
824 static int mdio_read(struct net_device
*net_dev
, int phy_id
, int location
)
826 long mdio_addr
= net_dev
->base_addr
+ mear
;
827 int mii_cmd
= MIIread
|(phy_id
<<MIIpmdShift
)|(location
<<MIIregShift
);
831 mdio_reset(mdio_addr
);
832 mdio_idle(mdio_addr
);
834 for (i
= 15; i
>= 0; i
--) {
835 int dataval
= (mii_cmd
& (1 << i
)) ? MDDIR
| MDIO
: MDDIR
;
836 outl(dataval
, mdio_addr
);
838 outl(dataval
| MDC
, mdio_addr
);
842 /* Read the 16 data bits. */
843 for (i
= 16; i
> 0; i
--) {
846 retval
= (retval
<< 1) | ((inl(mdio_addr
) & MDIO
) ? 1 : 0);
847 outl(MDC
, mdio_addr
);
850 outl(0x00, mdio_addr
);
856 * mdio_write - write MII PHY register
857 * @net_dev: the net device to write
858 * @phy_id: the phy address to write
859 * @location: the phy regiester id to write
860 * @value: the register value to write with
862 * Write MII registers with @value through MDIO and MDC
863 * using MDIO management frame structure and protocol(defined by ISO/IEC)
864 * please see SiS7014 or ICS spec
867 static void mdio_write(struct net_device
*net_dev
, int phy_id
, int location
,
870 long mdio_addr
= net_dev
->base_addr
+ mear
;
871 int mii_cmd
= MIIwrite
|(phy_id
<<MIIpmdShift
)|(location
<<MIIregShift
);
874 mdio_reset(mdio_addr
);
875 mdio_idle(mdio_addr
);
877 /* Shift the command bits out. */
878 for (i
= 15; i
>= 0; i
--) {
879 int dataval
= (mii_cmd
& (1 << i
)) ? MDDIR
| MDIO
: MDDIR
;
880 outb(dataval
, mdio_addr
);
882 outb(dataval
| MDC
, mdio_addr
);
887 /* Shift the value bits out. */
888 for (i
= 15; i
>= 0; i
--) {
889 int dataval
= (value
& (1 << i
)) ? MDDIR
| MDIO
: MDDIR
;
890 outl(dataval
, mdio_addr
);
892 outl(dataval
| MDC
, mdio_addr
);
897 /* Clear out extra bits. */
898 for (i
= 2; i
> 0; i
--) {
901 outb(MDC
, mdio_addr
);
904 outl(0x00, mdio_addr
);
909 * sis900_reset_phy - reset sis900 mii phy.
910 * @net_dev: the net device to write
911 * @phy_addr: default phy address
913 * Some specific phy can't work properly without reset.
914 * This function will be called during initialization and
915 * link status change from ON to DOWN.
918 static u16
sis900_reset_phy(struct net_device
*net_dev
, int phy_addr
)
923 for (i
= 0; i
< 2; i
++)
924 status
= mdio_read(net_dev
, phy_addr
, MII_STATUS
);
926 mdio_write( net_dev
, phy_addr
, MII_CONTROL
, MII_CNTL_RESET
);
931 #ifdef CONFIG_NET_POLL_CONTROLLER
933 * Polling 'interrupt' - used by things like netconsole to send skbs
934 * without having to re-enable interrupts. It's not called while
935 * the interrupt routine is executing.
937 static void sis900_poll(struct net_device
*dev
)
939 disable_irq(dev
->irq
);
940 sis900_interrupt(dev
->irq
, dev
);
941 enable_irq(dev
->irq
);
946 * sis900_open - open sis900 device
947 * @net_dev: the net device to open
949 * Do some initialization and start net interface.
950 * enable interrupts and set sis900 timer.
954 sis900_open(struct net_device
*net_dev
)
956 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
957 long ioaddr
= net_dev
->base_addr
;
960 /* Soft reset the chip. */
961 sis900_reset(net_dev
);
963 sis630_set_eq(net_dev
, sis_priv
->chipset_rev
);
965 ret
= request_irq(net_dev
->irq
, sis900_interrupt
, IRQF_SHARED
,
966 net_dev
->name
, net_dev
);
970 sis900_init_rxfilter(net_dev
);
972 sis900_init_tx_ring(net_dev
);
973 sis900_init_rx_ring(net_dev
);
975 set_rx_mode(net_dev
);
977 netif_start_queue(net_dev
);
979 sis900_set_mode(ioaddr
, HW_SPEED_10_MBPS
, FDX_CAPABLE_HALF_SELECTED
);
981 /* Enable all known interrupts by setting the interrupt mask. */
982 outl((RxSOVR
|RxORN
|RxERR
|RxOK
|TxURN
|TxERR
|TxIDLE
), ioaddr
+ imr
);
983 outl(RxENA
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
984 outl(IE
, ioaddr
+ ier
);
986 sis900_check_mode(net_dev
, sis_priv
->mii
);
988 /* Set the timer to switch to check for link beat and perhaps switch
989 to an alternate media type. */
990 init_timer(&sis_priv
->timer
);
991 sis_priv
->timer
.expires
= jiffies
+ HZ
;
992 sis_priv
->timer
.data
= (unsigned long)net_dev
;
993 sis_priv
->timer
.function
= &sis900_timer
;
994 add_timer(&sis_priv
->timer
);
1000 * sis900_init_rxfilter - Initialize the Rx filter
1001 * @net_dev: the net device to initialize for
1003 * Set receive filter address to our MAC address
1004 * and enable packet filtering.
1008 sis900_init_rxfilter (struct net_device
* net_dev
)
1010 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1011 long ioaddr
= net_dev
->base_addr
;
1015 rfcrSave
= inl(rfcr
+ ioaddr
);
1017 /* disable packet filtering before setting filter */
1018 outl(rfcrSave
& ~RFEN
, rfcr
+ ioaddr
);
1020 /* load MAC addr to filter data register */
1021 for (i
= 0 ; i
< 3 ; i
++) {
1024 w
= (u32
) *((u16
*)(net_dev
->dev_addr
)+i
);
1025 outl((i
<< RFADDR_shift
), ioaddr
+ rfcr
);
1026 outl(w
, ioaddr
+ rfdr
);
1028 if (netif_msg_hw(sis_priv
)) {
1029 printk(KERN_DEBUG
"%s: Receive Filter Addrss[%d]=%x\n",
1030 net_dev
->name
, i
, inl(ioaddr
+ rfdr
));
1034 /* enable packet filtering */
1035 outl(rfcrSave
| RFEN
, rfcr
+ ioaddr
);
1039 * sis900_init_tx_ring - Initialize the Tx descriptor ring
1040 * @net_dev: the net device to initialize for
1042 * Initialize the Tx descriptor ring,
1046 sis900_init_tx_ring(struct net_device
*net_dev
)
1048 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1049 long ioaddr
= net_dev
->base_addr
;
1052 sis_priv
->tx_full
= 0;
1053 sis_priv
->dirty_tx
= sis_priv
->cur_tx
= 0;
1055 for (i
= 0; i
< NUM_TX_DESC
; i
++) {
1056 sis_priv
->tx_skbuff
[i
] = NULL
;
1058 sis_priv
->tx_ring
[i
].link
= sis_priv
->tx_ring_dma
+
1059 ((i
+1)%NUM_TX_DESC
)*sizeof(BufferDesc
);
1060 sis_priv
->tx_ring
[i
].cmdsts
= 0;
1061 sis_priv
->tx_ring
[i
].bufptr
= 0;
1064 /* load Transmit Descriptor Register */
1065 outl(sis_priv
->tx_ring_dma
, ioaddr
+ txdp
);
1066 if (netif_msg_hw(sis_priv
))
1067 printk(KERN_DEBUG
"%s: TX descriptor register loaded with: %8.8x\n",
1068 net_dev
->name
, inl(ioaddr
+ txdp
));
1072 * sis900_init_rx_ring - Initialize the Rx descriptor ring
1073 * @net_dev: the net device to initialize for
1075 * Initialize the Rx descriptor ring,
1076 * and pre-allocate recevie buffers (socket buffer)
1080 sis900_init_rx_ring(struct net_device
*net_dev
)
1082 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1083 long ioaddr
= net_dev
->base_addr
;
1086 sis_priv
->cur_rx
= 0;
1087 sis_priv
->dirty_rx
= 0;
1089 /* init RX descriptor */
1090 for (i
= 0; i
< NUM_RX_DESC
; i
++) {
1091 sis_priv
->rx_skbuff
[i
] = NULL
;
1093 sis_priv
->rx_ring
[i
].link
= sis_priv
->rx_ring_dma
+
1094 ((i
+1)%NUM_RX_DESC
)*sizeof(BufferDesc
);
1095 sis_priv
->rx_ring
[i
].cmdsts
= 0;
1096 sis_priv
->rx_ring
[i
].bufptr
= 0;
1099 /* allocate sock buffers */
1100 for (i
= 0; i
< NUM_RX_DESC
; i
++) {
1101 struct sk_buff
*skb
;
1103 if ((skb
= dev_alloc_skb(RX_BUF_SIZE
)) == NULL
) {
1104 /* not enough memory for skbuff, this makes a "hole"
1105 on the buffer ring, it is not clear how the
1106 hardware will react to this kind of degenerated
1110 sis_priv
->rx_skbuff
[i
] = skb
;
1111 sis_priv
->rx_ring
[i
].cmdsts
= RX_BUF_SIZE
;
1112 sis_priv
->rx_ring
[i
].bufptr
= pci_map_single(sis_priv
->pci_dev
,
1113 skb
->data
, RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
1115 sis_priv
->dirty_rx
= (unsigned int) (i
- NUM_RX_DESC
);
1117 /* load Receive Descriptor Register */
1118 outl(sis_priv
->rx_ring_dma
, ioaddr
+ rxdp
);
1119 if (netif_msg_hw(sis_priv
))
1120 printk(KERN_DEBUG
"%s: RX descriptor register loaded with: %8.8x\n",
1121 net_dev
->name
, inl(ioaddr
+ rxdp
));
1125 static void sis630_set_eq(struct net_device
*net_dev
, u8 revision
)
1127 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1128 u16 reg14h
, eq_value
=0, max_value
=0, min_value
=0;
1131 if ( !(revision
== SIS630E_900_REV
|| revision
== SIS630EA1_900_REV
||
1132 revision
== SIS630A_900_REV
|| revision
== SIS630ET_900_REV
) )
1135 if (netif_carrier_ok(net_dev
)) {
1136 reg14h
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_RESV
);
1137 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_RESV
,
1138 (0x2200 | reg14h
) & 0xBFFF);
1139 for (i
=0; i
< maxcount
; i
++) {
1140 eq_value
= (0x00F8 & mdio_read(net_dev
,
1141 sis_priv
->cur_phy
, MII_RESV
)) >> 3;
1143 max_value
=min_value
=eq_value
;
1144 max_value
= (eq_value
> max_value
) ?
1145 eq_value
: max_value
;
1146 min_value
= (eq_value
< min_value
) ?
1147 eq_value
: min_value
;
1149 /* 630E rule to determine the equalizer value */
1150 if (revision
== SIS630E_900_REV
|| revision
== SIS630EA1_900_REV
||
1151 revision
== SIS630ET_900_REV
) {
1153 eq_value
= max_value
;
1154 else if (max_value
>= 5 && max_value
< 15)
1155 eq_value
= (max_value
== min_value
) ?
1156 max_value
+2 : max_value
+1;
1157 else if (max_value
>= 15)
1158 eq_value
=(max_value
== min_value
) ?
1159 max_value
+6 : max_value
+5;
1161 /* 630B0&B1 rule to determine the equalizer value */
1162 if (revision
== SIS630A_900_REV
&&
1163 (sis_priv
->host_bridge_rev
== SIS630B0
||
1164 sis_priv
->host_bridge_rev
== SIS630B1
)) {
1168 eq_value
= (max_value
+ min_value
+ 1)/2;
1170 /* write equalizer value and setting */
1171 reg14h
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_RESV
);
1172 reg14h
= (reg14h
& 0xFF07) | ((eq_value
<< 3) & 0x00F8);
1173 reg14h
= (reg14h
| 0x6000) & 0xFDFF;
1174 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_RESV
, reg14h
);
1176 reg14h
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_RESV
);
1177 if (revision
== SIS630A_900_REV
&&
1178 (sis_priv
->host_bridge_rev
== SIS630B0
||
1179 sis_priv
->host_bridge_rev
== SIS630B1
))
1180 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_RESV
,
1181 (reg14h
| 0x2200) & 0xBFFF);
1183 mdio_write(net_dev
, sis_priv
->cur_phy
, MII_RESV
,
1184 (reg14h
| 0x2000) & 0xBFFF);
1189 * sis900_timer - sis900 timer routine
1190 * @data: pointer to sis900 net device
1192 * On each timer ticks we check two things,
1193 * link status (ON/OFF) and link mode (10/100/Full/Half)
1196 static void sis900_timer(unsigned long data
)
1198 struct net_device
*net_dev
= (struct net_device
*)data
;
1199 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1200 struct mii_phy
*mii_phy
= sis_priv
->mii
;
1201 static const int next_tick
= 5*HZ
;
1204 if (!sis_priv
->autong_complete
){
1205 int uninitialized_var(speed
), duplex
= 0;
1207 sis900_read_mode(net_dev
, &speed
, &duplex
);
1209 sis900_set_mode(net_dev
->base_addr
, speed
, duplex
);
1210 sis630_set_eq(net_dev
, sis_priv
->chipset_rev
);
1211 netif_start_queue(net_dev
);
1214 sis_priv
->timer
.expires
= jiffies
+ HZ
;
1215 add_timer(&sis_priv
->timer
);
1219 status
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_STATUS
);
1220 status
= mdio_read(net_dev
, sis_priv
->cur_phy
, MII_STATUS
);
1222 /* Link OFF -> ON */
1223 if (!netif_carrier_ok(net_dev
)) {
1225 /* Search for new PHY */
1226 status
= sis900_default_phy(net_dev
);
1227 mii_phy
= sis_priv
->mii
;
1229 if (status
& MII_STAT_LINK
){
1230 sis900_check_mode(net_dev
, mii_phy
);
1231 netif_carrier_on(net_dev
);
1234 /* Link ON -> OFF */
1235 if (!(status
& MII_STAT_LINK
)){
1236 netif_carrier_off(net_dev
);
1237 if(netif_msg_link(sis_priv
))
1238 printk(KERN_INFO
"%s: Media Link Off\n", net_dev
->name
);
1240 /* Change mode issue */
1241 if ((mii_phy
->phy_id0
== 0x001D) &&
1242 ((mii_phy
->phy_id1
& 0xFFF0) == 0x8000))
1243 sis900_reset_phy(net_dev
, sis_priv
->cur_phy
);
1245 sis630_set_eq(net_dev
, sis_priv
->chipset_rev
);
1251 sis_priv
->timer
.expires
= jiffies
+ next_tick
;
1252 add_timer(&sis_priv
->timer
);
1256 * sis900_check_mode - check the media mode for sis900
1257 * @net_dev: the net device to be checked
1258 * @mii_phy: the mii phy
1260 * Older driver gets the media mode from mii status output
1261 * register. Now we set our media capability and auto-negotiate
1262 * to get the upper bound of speed and duplex between two ends.
1263 * If the types of mii phy is HOME, it doesn't need to auto-negotiate
1264 * and autong_complete should be set to 1.
1267 static void sis900_check_mode(struct net_device
*net_dev
, struct mii_phy
*mii_phy
)
1269 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1270 long ioaddr
= net_dev
->base_addr
;
1273 if (mii_phy
->phy_types
== LAN
) {
1274 outl(~EXD
& inl(ioaddr
+ cfg
), ioaddr
+ cfg
);
1275 sis900_set_capability(net_dev
, mii_phy
);
1276 sis900_auto_negotiate(net_dev
, sis_priv
->cur_phy
);
1278 outl(EXD
| inl(ioaddr
+ cfg
), ioaddr
+ cfg
);
1279 speed
= HW_SPEED_HOME
;
1280 duplex
= FDX_CAPABLE_HALF_SELECTED
;
1281 sis900_set_mode(ioaddr
, speed
, duplex
);
1282 sis_priv
->autong_complete
= 1;
1287 * sis900_set_mode - Set the media mode of mac register.
1288 * @ioaddr: the address of the device
1289 * @speed : the transmit speed to be determined
1290 * @duplex: the duplex mode to be determined
1292 * Set the media mode of mac register txcfg/rxcfg according to
1293 * speed and duplex of phy. Bit EDB_MASTER_EN indicates the EDB
1294 * bus is used instead of PCI bus. When this bit is set 1, the
1295 * Max DMA Burst Size for TX/RX DMA should be no larger than 16
1299 static void sis900_set_mode (long ioaddr
, int speed
, int duplex
)
1301 u32 tx_flags
= 0, rx_flags
= 0;
1303 if (inl(ioaddr
+ cfg
) & EDB_MASTER_EN
) {
1304 tx_flags
= TxATP
| (DMA_BURST_64
<< TxMXDMA_shift
) |
1305 (TX_FILL_THRESH
<< TxFILLT_shift
);
1306 rx_flags
= DMA_BURST_64
<< RxMXDMA_shift
;
1308 tx_flags
= TxATP
| (DMA_BURST_512
<< TxMXDMA_shift
) |
1309 (TX_FILL_THRESH
<< TxFILLT_shift
);
1310 rx_flags
= DMA_BURST_512
<< RxMXDMA_shift
;
1313 if (speed
== HW_SPEED_HOME
|| speed
== HW_SPEED_10_MBPS
) {
1314 rx_flags
|= (RxDRNT_10
<< RxDRNT_shift
);
1315 tx_flags
|= (TxDRNT_10
<< TxDRNT_shift
);
1317 rx_flags
|= (RxDRNT_100
<< RxDRNT_shift
);
1318 tx_flags
|= (TxDRNT_100
<< TxDRNT_shift
);
1321 if (duplex
== FDX_CAPABLE_FULL_SELECTED
) {
1322 tx_flags
|= (TxCSI
| TxHBI
);
1326 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1327 /* Can accept Jumbo packet */
1331 outl (tx_flags
, ioaddr
+ txcfg
);
1332 outl (rx_flags
, ioaddr
+ rxcfg
);
1336 * sis900_auto_negotiate - Set the Auto-Negotiation Enable/Reset bit.
1337 * @net_dev: the net device to read mode for
1338 * @phy_addr: mii phy address
1340 * If the adapter is link-on, set the auto-negotiate enable/reset bit.
1341 * autong_complete should be set to 0 when starting auto-negotiation.
1342 * autong_complete should be set to 1 if we didn't start auto-negotiation.
1343 * sis900_timer will wait for link on again if autong_complete = 0.
1346 static void sis900_auto_negotiate(struct net_device
*net_dev
, int phy_addr
)
1348 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1352 for (i
= 0; i
< 2; i
++)
1353 status
= mdio_read(net_dev
, phy_addr
, MII_STATUS
);
1355 if (!(status
& MII_STAT_LINK
)){
1356 if(netif_msg_link(sis_priv
))
1357 printk(KERN_INFO
"%s: Media Link Off\n", net_dev
->name
);
1358 sis_priv
->autong_complete
= 1;
1359 netif_carrier_off(net_dev
);
1363 /* (Re)start AutoNegotiate */
1364 mdio_write(net_dev
, phy_addr
, MII_CONTROL
,
1365 MII_CNTL_AUTO
| MII_CNTL_RST_AUTO
);
1366 sis_priv
->autong_complete
= 0;
1371 * sis900_read_mode - read media mode for sis900 internal phy
1372 * @net_dev: the net device to read mode for
1373 * @speed : the transmit speed to be determined
1374 * @duplex : the duplex mode to be determined
1376 * The capability of remote end will be put in mii register autorec
1377 * after auto-negotiation. Use AND operation to get the upper bound
1378 * of speed and duplex between two ends.
1381 static void sis900_read_mode(struct net_device
*net_dev
, int *speed
, int *duplex
)
1383 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1384 struct mii_phy
*phy
= sis_priv
->mii
;
1385 int phy_addr
= sis_priv
->cur_phy
;
1387 u16 autoadv
, autorec
;
1390 for (i
= 0; i
< 2; i
++)
1391 status
= mdio_read(net_dev
, phy_addr
, MII_STATUS
);
1393 if (!(status
& MII_STAT_LINK
))
1396 /* AutoNegotiate completed */
1397 autoadv
= mdio_read(net_dev
, phy_addr
, MII_ANADV
);
1398 autorec
= mdio_read(net_dev
, phy_addr
, MII_ANLPAR
);
1399 status
= autoadv
& autorec
;
1401 *speed
= HW_SPEED_10_MBPS
;
1402 *duplex
= FDX_CAPABLE_HALF_SELECTED
;
1404 if (status
& (MII_NWAY_TX
| MII_NWAY_TX_FDX
))
1405 *speed
= HW_SPEED_100_MBPS
;
1406 if (status
& ( MII_NWAY_TX_FDX
| MII_NWAY_T_FDX
))
1407 *duplex
= FDX_CAPABLE_FULL_SELECTED
;
1409 sis_priv
->autong_complete
= 1;
1411 if ((phy
->phy_id0
== 0x0000) && ((phy
->phy_id1
& 0xFFF0) == 0x8200)) {
1412 if (mdio_read(net_dev
, phy_addr
, MII_CONTROL
) & MII_CNTL_FDX
)
1413 *duplex
= FDX_CAPABLE_FULL_SELECTED
;
1414 if (mdio_read(net_dev
, phy_addr
, 0x0019) & 0x01)
1415 *speed
= HW_SPEED_100_MBPS
;
1418 if(netif_msg_link(sis_priv
))
1419 printk(KERN_INFO
"%s: Media Link On %s %s-duplex\n",
1421 *speed
== HW_SPEED_100_MBPS
?
1422 "100mbps" : "10mbps",
1423 *duplex
== FDX_CAPABLE_FULL_SELECTED
?
1428 * sis900_tx_timeout - sis900 transmit timeout routine
1429 * @net_dev: the net device to transmit
1431 * print transmit timeout status
1432 * disable interrupts and do some tasks
1435 static void sis900_tx_timeout(struct net_device
*net_dev
)
1437 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1438 long ioaddr
= net_dev
->base_addr
;
1439 unsigned long flags
;
1442 if(netif_msg_tx_err(sis_priv
))
1443 printk(KERN_INFO
"%s: Transmit timeout, status %8.8x %8.8x\n",
1444 net_dev
->name
, inl(ioaddr
+ cr
), inl(ioaddr
+ isr
));
1446 /* Disable interrupts by clearing the interrupt mask. */
1447 outl(0x0000, ioaddr
+ imr
);
1449 /* use spinlock to prevent interrupt handler accessing buffer ring */
1450 spin_lock_irqsave(&sis_priv
->lock
, flags
);
1452 /* discard unsent packets */
1453 sis_priv
->dirty_tx
= sis_priv
->cur_tx
= 0;
1454 for (i
= 0; i
< NUM_TX_DESC
; i
++) {
1455 struct sk_buff
*skb
= sis_priv
->tx_skbuff
[i
];
1458 pci_unmap_single(sis_priv
->pci_dev
,
1459 sis_priv
->tx_ring
[i
].bufptr
, skb
->len
,
1461 dev_kfree_skb_irq(skb
);
1462 sis_priv
->tx_skbuff
[i
] = NULL
;
1463 sis_priv
->tx_ring
[i
].cmdsts
= 0;
1464 sis_priv
->tx_ring
[i
].bufptr
= 0;
1465 net_dev
->stats
.tx_dropped
++;
1468 sis_priv
->tx_full
= 0;
1469 netif_wake_queue(net_dev
);
1471 spin_unlock_irqrestore(&sis_priv
->lock
, flags
);
1473 net_dev
->trans_start
= jiffies
; /* prevent tx timeout */
1475 /* load Transmit Descriptor Register */
1476 outl(sis_priv
->tx_ring_dma
, ioaddr
+ txdp
);
1478 /* Enable all known interrupts by setting the interrupt mask. */
1479 outl((RxSOVR
|RxORN
|RxERR
|RxOK
|TxURN
|TxERR
|TxIDLE
), ioaddr
+ imr
);
1483 * sis900_start_xmit - sis900 start transmit routine
1484 * @skb: socket buffer pointer to put the data being transmitted
1485 * @net_dev: the net device to transmit with
1487 * Set the transmit buffer descriptor,
1488 * and write TxENA to enable transmit state machine.
1489 * tell upper layer if the buffer is full
1493 sis900_start_xmit(struct sk_buff
*skb
, struct net_device
*net_dev
)
1495 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1496 long ioaddr
= net_dev
->base_addr
;
1498 unsigned long flags
;
1499 unsigned int index_cur_tx
, index_dirty_tx
;
1500 unsigned int count_dirty_tx
;
1502 /* Don't transmit data before the complete of auto-negotiation */
1503 if(!sis_priv
->autong_complete
){
1504 netif_stop_queue(net_dev
);
1505 return NETDEV_TX_BUSY
;
1508 spin_lock_irqsave(&sis_priv
->lock
, flags
);
1510 /* Calculate the next Tx descriptor entry. */
1511 entry
= sis_priv
->cur_tx
% NUM_TX_DESC
;
1512 sis_priv
->tx_skbuff
[entry
] = skb
;
1514 /* set the transmit buffer descriptor and enable Transmit State Machine */
1515 sis_priv
->tx_ring
[entry
].bufptr
= pci_map_single(sis_priv
->pci_dev
,
1516 skb
->data
, skb
->len
, PCI_DMA_TODEVICE
);
1517 sis_priv
->tx_ring
[entry
].cmdsts
= (OWN
| skb
->len
);
1518 outl(TxENA
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
1520 sis_priv
->cur_tx
++;
1521 index_cur_tx
= sis_priv
->cur_tx
;
1522 index_dirty_tx
= sis_priv
->dirty_tx
;
1524 for (count_dirty_tx
= 0; index_cur_tx
!= index_dirty_tx
; index_dirty_tx
++)
1527 if (index_cur_tx
== index_dirty_tx
) {
1528 /* dirty_tx is met in the cycle of cur_tx, buffer full */
1529 sis_priv
->tx_full
= 1;
1530 netif_stop_queue(net_dev
);
1531 } else if (count_dirty_tx
< NUM_TX_DESC
) {
1532 /* Typical path, tell upper layer that more transmission is possible */
1533 netif_start_queue(net_dev
);
1535 /* buffer full, tell upper layer no more transmission */
1536 sis_priv
->tx_full
= 1;
1537 netif_stop_queue(net_dev
);
1540 spin_unlock_irqrestore(&sis_priv
->lock
, flags
);
1542 if (netif_msg_tx_queued(sis_priv
))
1543 printk(KERN_DEBUG
"%s: Queued Tx packet at %p size %d "
1545 net_dev
->name
, skb
->data
, (int)skb
->len
, entry
);
1547 return NETDEV_TX_OK
;
1551 * sis900_interrupt - sis900 interrupt handler
1552 * @irq: the irq number
1553 * @dev_instance: the client data object
1555 * The interrupt handler does all of the Rx thread work,
1556 * and cleans up after the Tx thread
1559 static irqreturn_t
sis900_interrupt(int irq
, void *dev_instance
)
1561 struct net_device
*net_dev
= dev_instance
;
1562 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1563 int boguscnt
= max_interrupt_work
;
1564 long ioaddr
= net_dev
->base_addr
;
1566 unsigned int handled
= 0;
1568 spin_lock (&sis_priv
->lock
);
1571 status
= inl(ioaddr
+ isr
);
1573 if ((status
& (HIBERR
|TxURN
|TxERR
|TxIDLE
|RxORN
|RxERR
|RxOK
)) == 0)
1574 /* nothing intresting happened */
1578 /* why dow't we break after Tx/Rx case ?? keyword: full-duplex */
1579 if (status
& (RxORN
| RxERR
| RxOK
))
1583 if (status
& (TxURN
| TxERR
| TxIDLE
))
1585 sis900_finish_xmit(net_dev
);
1587 /* something strange happened !!! */
1588 if (status
& HIBERR
) {
1589 if(netif_msg_intr(sis_priv
))
1590 printk(KERN_INFO
"%s: Abnormal interrupt, "
1591 "status %#8.8x.\n", net_dev
->name
, status
);
1594 if (--boguscnt
< 0) {
1595 if(netif_msg_intr(sis_priv
))
1596 printk(KERN_INFO
"%s: Too much work at interrupt, "
1597 "interrupt status = %#8.8x.\n",
1598 net_dev
->name
, status
);
1603 if(netif_msg_intr(sis_priv
))
1604 printk(KERN_DEBUG
"%s: exiting interrupt, "
1605 "interrupt status = 0x%#8.8x.\n",
1606 net_dev
->name
, inl(ioaddr
+ isr
));
1608 spin_unlock (&sis_priv
->lock
);
1609 return IRQ_RETVAL(handled
);
1613 * sis900_rx - sis900 receive routine
1614 * @net_dev: the net device which receives data
1616 * Process receive interrupt events,
1617 * put buffer to higher layer and refill buffer pool
1618 * Note: This function is called by interrupt handler,
1619 * don't do "too much" work here
1622 static int sis900_rx(struct net_device
*net_dev
)
1624 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1625 long ioaddr
= net_dev
->base_addr
;
1626 unsigned int entry
= sis_priv
->cur_rx
% NUM_RX_DESC
;
1627 u32 rx_status
= sis_priv
->rx_ring
[entry
].cmdsts
;
1630 if (netif_msg_rx_status(sis_priv
))
1631 printk(KERN_DEBUG
"sis900_rx, cur_rx:%4.4d, dirty_rx:%4.4d "
1633 sis_priv
->cur_rx
, sis_priv
->dirty_rx
, rx_status
);
1634 rx_work_limit
= sis_priv
->dirty_rx
+ NUM_RX_DESC
- sis_priv
->cur_rx
;
1636 while (rx_status
& OWN
) {
1637 unsigned int rx_size
;
1638 unsigned int data_size
;
1640 if (--rx_work_limit
< 0)
1643 data_size
= rx_status
& DSIZE
;
1644 rx_size
= data_size
- CRC_SIZE
;
1646 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1647 /* ``TOOLONG'' flag means jumbo packet recived. */
1648 if ((rx_status
& TOOLONG
) && data_size
<= MAX_FRAME_SIZE
)
1649 rx_status
&= (~ ((unsigned int)TOOLONG
));
1652 if (rx_status
& (ABORT
|OVERRUN
|TOOLONG
|RUNT
|RXISERR
|CRCERR
|FAERR
)) {
1653 /* corrupted packet received */
1654 if (netif_msg_rx_err(sis_priv
))
1655 printk(KERN_DEBUG
"%s: Corrupted packet "
1656 "received, buffer status = 0x%8.8x/%d.\n",
1657 net_dev
->name
, rx_status
, data_size
);
1658 net_dev
->stats
.rx_errors
++;
1659 if (rx_status
& OVERRUN
)
1660 net_dev
->stats
.rx_over_errors
++;
1661 if (rx_status
& (TOOLONG
|RUNT
))
1662 net_dev
->stats
.rx_length_errors
++;
1663 if (rx_status
& (RXISERR
| FAERR
))
1664 net_dev
->stats
.rx_frame_errors
++;
1665 if (rx_status
& CRCERR
)
1666 net_dev
->stats
.rx_crc_errors
++;
1667 /* reset buffer descriptor state */
1668 sis_priv
->rx_ring
[entry
].cmdsts
= RX_BUF_SIZE
;
1670 struct sk_buff
* skb
;
1671 struct sk_buff
* rx_skb
;
1673 pci_unmap_single(sis_priv
->pci_dev
,
1674 sis_priv
->rx_ring
[entry
].bufptr
, RX_BUF_SIZE
,
1675 PCI_DMA_FROMDEVICE
);
1677 /* refill the Rx buffer, what if there is not enough
1678 * memory for new socket buffer ?? */
1679 if ((skb
= dev_alloc_skb(RX_BUF_SIZE
)) == NULL
) {
1681 * Not enough memory to refill the buffer
1682 * so we need to recycle the old one so
1683 * as to avoid creating a memory hole
1686 skb
= sis_priv
->rx_skbuff
[entry
];
1687 net_dev
->stats
.rx_dropped
++;
1688 goto refill_rx_ring
;
1691 /* This situation should never happen, but due to
1692 some unknown bugs, it is possible that
1693 we are working on NULL sk_buff :-( */
1694 if (sis_priv
->rx_skbuff
[entry
] == NULL
) {
1695 if (netif_msg_rx_err(sis_priv
))
1696 printk(KERN_WARNING
"%s: NULL pointer "
1697 "encountered in Rx ring\n"
1698 "cur_rx:%4.4d, dirty_rx:%4.4d\n",
1699 net_dev
->name
, sis_priv
->cur_rx
,
1700 sis_priv
->dirty_rx
);
1704 /* give the socket buffer to upper layers */
1705 rx_skb
= sis_priv
->rx_skbuff
[entry
];
1706 skb_put(rx_skb
, rx_size
);
1707 rx_skb
->protocol
= eth_type_trans(rx_skb
, net_dev
);
1710 /* some network statistics */
1711 if ((rx_status
& BCAST
) == MCAST
)
1712 net_dev
->stats
.multicast
++;
1713 net_dev
->stats
.rx_bytes
+= rx_size
;
1714 net_dev
->stats
.rx_packets
++;
1715 sis_priv
->dirty_rx
++;
1717 sis_priv
->rx_skbuff
[entry
] = skb
;
1718 sis_priv
->rx_ring
[entry
].cmdsts
= RX_BUF_SIZE
;
1719 sis_priv
->rx_ring
[entry
].bufptr
=
1720 pci_map_single(sis_priv
->pci_dev
, skb
->data
,
1721 RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
1724 entry
= sis_priv
->cur_rx
% NUM_RX_DESC
;
1725 rx_status
= sis_priv
->rx_ring
[entry
].cmdsts
;
1728 /* refill the Rx buffer, what if the rate of refilling is slower
1729 * than consuming ?? */
1730 for (; sis_priv
->cur_rx
!= sis_priv
->dirty_rx
; sis_priv
->dirty_rx
++) {
1731 struct sk_buff
*skb
;
1733 entry
= sis_priv
->dirty_rx
% NUM_RX_DESC
;
1735 if (sis_priv
->rx_skbuff
[entry
] == NULL
) {
1736 if ((skb
= dev_alloc_skb(RX_BUF_SIZE
)) == NULL
) {
1737 /* not enough memory for skbuff, this makes a
1738 * "hole" on the buffer ring, it is not clear
1739 * how the hardware will react to this kind
1740 * of degenerated buffer */
1741 if (netif_msg_rx_err(sis_priv
))
1742 printk(KERN_INFO
"%s: Memory squeeze, "
1743 "deferring packet.\n",
1745 net_dev
->stats
.rx_dropped
++;
1748 sis_priv
->rx_skbuff
[entry
] = skb
;
1749 sis_priv
->rx_ring
[entry
].cmdsts
= RX_BUF_SIZE
;
1750 sis_priv
->rx_ring
[entry
].bufptr
=
1751 pci_map_single(sis_priv
->pci_dev
, skb
->data
,
1752 RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
1755 /* re-enable the potentially idle receive state matchine */
1756 outl(RxENA
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
1762 * sis900_finish_xmit - finish up transmission of packets
1763 * @net_dev: the net device to be transmitted on
1765 * Check for error condition and free socket buffer etc
1766 * schedule for more transmission as needed
1767 * Note: This function is called by interrupt handler,
1768 * don't do "too much" work here
1771 static void sis900_finish_xmit (struct net_device
*net_dev
)
1773 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1775 for (; sis_priv
->dirty_tx
!= sis_priv
->cur_tx
; sis_priv
->dirty_tx
++) {
1776 struct sk_buff
*skb
;
1780 entry
= sis_priv
->dirty_tx
% NUM_TX_DESC
;
1781 tx_status
= sis_priv
->tx_ring
[entry
].cmdsts
;
1783 if (tx_status
& OWN
) {
1784 /* The packet is not transmitted yet (owned by hardware) !
1785 * Note: the interrupt is generated only when Tx Machine
1786 * is idle, so this is an almost impossible case */
1790 if (tx_status
& (ABORT
| UNDERRUN
| OWCOLL
)) {
1791 /* packet unsuccessfully transmitted */
1792 if (netif_msg_tx_err(sis_priv
))
1793 printk(KERN_DEBUG
"%s: Transmit "
1794 "error, Tx status %8.8x.\n",
1795 net_dev
->name
, tx_status
);
1796 net_dev
->stats
.tx_errors
++;
1797 if (tx_status
& UNDERRUN
)
1798 net_dev
->stats
.tx_fifo_errors
++;
1799 if (tx_status
& ABORT
)
1800 net_dev
->stats
.tx_aborted_errors
++;
1801 if (tx_status
& NOCARRIER
)
1802 net_dev
->stats
.tx_carrier_errors
++;
1803 if (tx_status
& OWCOLL
)
1804 net_dev
->stats
.tx_window_errors
++;
1806 /* packet successfully transmitted */
1807 net_dev
->stats
.collisions
+= (tx_status
& COLCNT
) >> 16;
1808 net_dev
->stats
.tx_bytes
+= tx_status
& DSIZE
;
1809 net_dev
->stats
.tx_packets
++;
1811 /* Free the original skb. */
1812 skb
= sis_priv
->tx_skbuff
[entry
];
1813 pci_unmap_single(sis_priv
->pci_dev
,
1814 sis_priv
->tx_ring
[entry
].bufptr
, skb
->len
,
1816 dev_kfree_skb_irq(skb
);
1817 sis_priv
->tx_skbuff
[entry
] = NULL
;
1818 sis_priv
->tx_ring
[entry
].bufptr
= 0;
1819 sis_priv
->tx_ring
[entry
].cmdsts
= 0;
1822 if (sis_priv
->tx_full
&& netif_queue_stopped(net_dev
) &&
1823 sis_priv
->cur_tx
- sis_priv
->dirty_tx
< NUM_TX_DESC
- 4) {
1824 /* The ring is no longer full, clear tx_full and schedule
1825 * more transmission by netif_wake_queue(net_dev) */
1826 sis_priv
->tx_full
= 0;
1827 netif_wake_queue (net_dev
);
1832 * sis900_close - close sis900 device
1833 * @net_dev: the net device to be closed
1835 * Disable interrupts, stop the Tx and Rx Status Machine
1836 * free Tx and RX socket buffer
1839 static int sis900_close(struct net_device
*net_dev
)
1841 long ioaddr
= net_dev
->base_addr
;
1842 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1843 struct sk_buff
*skb
;
1846 netif_stop_queue(net_dev
);
1848 /* Disable interrupts by clearing the interrupt mask. */
1849 outl(0x0000, ioaddr
+ imr
);
1850 outl(0x0000, ioaddr
+ ier
);
1852 /* Stop the chip's Tx and Rx Status Machine */
1853 outl(RxDIS
| TxDIS
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
1855 del_timer(&sis_priv
->timer
);
1857 free_irq(net_dev
->irq
, net_dev
);
1859 /* Free Tx and RX skbuff */
1860 for (i
= 0; i
< NUM_RX_DESC
; i
++) {
1861 skb
= sis_priv
->rx_skbuff
[i
];
1863 pci_unmap_single(sis_priv
->pci_dev
,
1864 sis_priv
->rx_ring
[i
].bufptr
,
1865 RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
1867 sis_priv
->rx_skbuff
[i
] = NULL
;
1870 for (i
= 0; i
< NUM_TX_DESC
; i
++) {
1871 skb
= sis_priv
->tx_skbuff
[i
];
1873 pci_unmap_single(sis_priv
->pci_dev
,
1874 sis_priv
->tx_ring
[i
].bufptr
, skb
->len
,
1877 sis_priv
->tx_skbuff
[i
] = NULL
;
1881 /* Green! Put the chip in low-power mode. */
1887 * sis900_get_drvinfo - Return information about driver
1888 * @net_dev: the net device to probe
1889 * @info: container for info returned
1891 * Process ethtool command such as "ehtool -i" to show information
1894 static void sis900_get_drvinfo(struct net_device
*net_dev
,
1895 struct ethtool_drvinfo
*info
)
1897 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1899 strcpy (info
->driver
, SIS900_MODULE_NAME
);
1900 strcpy (info
->version
, SIS900_DRV_VERSION
);
1901 strcpy (info
->bus_info
, pci_name(sis_priv
->pci_dev
));
1904 static u32
sis900_get_msglevel(struct net_device
*net_dev
)
1906 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1907 return sis_priv
->msg_enable
;
1910 static void sis900_set_msglevel(struct net_device
*net_dev
, u32 value
)
1912 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1913 sis_priv
->msg_enable
= value
;
1916 static u32
sis900_get_link(struct net_device
*net_dev
)
1918 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1919 return mii_link_ok(&sis_priv
->mii_info
);
1922 static int sis900_get_settings(struct net_device
*net_dev
,
1923 struct ethtool_cmd
*cmd
)
1925 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1926 spin_lock_irq(&sis_priv
->lock
);
1927 mii_ethtool_gset(&sis_priv
->mii_info
, cmd
);
1928 spin_unlock_irq(&sis_priv
->lock
);
1932 static int sis900_set_settings(struct net_device
*net_dev
,
1933 struct ethtool_cmd
*cmd
)
1935 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1937 spin_lock_irq(&sis_priv
->lock
);
1938 rt
= mii_ethtool_sset(&sis_priv
->mii_info
, cmd
);
1939 spin_unlock_irq(&sis_priv
->lock
);
1943 static int sis900_nway_reset(struct net_device
*net_dev
)
1945 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1946 return mii_nway_restart(&sis_priv
->mii_info
);
1950 * sis900_set_wol - Set up Wake on Lan registers
1951 * @net_dev: the net device to probe
1952 * @wol: container for info passed to the driver
1954 * Process ethtool command "wol" to setup wake on lan features.
1955 * SiS900 supports sending WoL events if a correct packet is received,
1956 * but there is no simple way to filter them to only a subset (broadcast,
1957 * multicast, unicast or arp).
1960 static int sis900_set_wol(struct net_device
*net_dev
, struct ethtool_wolinfo
*wol
)
1962 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
1963 long pmctrl_addr
= net_dev
->base_addr
+ pmctrl
;
1964 u32 cfgpmcsr
= 0, pmctrl_bits
= 0;
1966 if (wol
->wolopts
== 0) {
1967 pci_read_config_dword(sis_priv
->pci_dev
, CFGPMCSR
, &cfgpmcsr
);
1968 cfgpmcsr
&= ~PME_EN
;
1969 pci_write_config_dword(sis_priv
->pci_dev
, CFGPMCSR
, cfgpmcsr
);
1970 outl(pmctrl_bits
, pmctrl_addr
);
1971 if (netif_msg_wol(sis_priv
))
1972 printk(KERN_DEBUG
"%s: Wake on LAN disabled\n", net_dev
->name
);
1976 if (wol
->wolopts
& (WAKE_MAGICSECURE
| WAKE_UCAST
| WAKE_MCAST
1977 | WAKE_BCAST
| WAKE_ARP
))
1980 if (wol
->wolopts
& WAKE_MAGIC
)
1981 pmctrl_bits
|= MAGICPKT
;
1982 if (wol
->wolopts
& WAKE_PHY
)
1983 pmctrl_bits
|= LINKON
;
1985 outl(pmctrl_bits
, pmctrl_addr
);
1987 pci_read_config_dword(sis_priv
->pci_dev
, CFGPMCSR
, &cfgpmcsr
);
1989 pci_write_config_dword(sis_priv
->pci_dev
, CFGPMCSR
, cfgpmcsr
);
1990 if (netif_msg_wol(sis_priv
))
1991 printk(KERN_DEBUG
"%s: Wake on LAN enabled\n", net_dev
->name
);
1996 static void sis900_get_wol(struct net_device
*net_dev
, struct ethtool_wolinfo
*wol
)
1998 long pmctrl_addr
= net_dev
->base_addr
+ pmctrl
;
2001 pmctrl_bits
= inl(pmctrl_addr
);
2002 if (pmctrl_bits
& MAGICPKT
)
2003 wol
->wolopts
|= WAKE_MAGIC
;
2004 if (pmctrl_bits
& LINKON
)
2005 wol
->wolopts
|= WAKE_PHY
;
2007 wol
->supported
= (WAKE_PHY
| WAKE_MAGIC
);
2010 static const struct ethtool_ops sis900_ethtool_ops
= {
2011 .get_drvinfo
= sis900_get_drvinfo
,
2012 .get_msglevel
= sis900_get_msglevel
,
2013 .set_msglevel
= sis900_set_msglevel
,
2014 .get_link
= sis900_get_link
,
2015 .get_settings
= sis900_get_settings
,
2016 .set_settings
= sis900_set_settings
,
2017 .nway_reset
= sis900_nway_reset
,
2018 .get_wol
= sis900_get_wol
,
2019 .set_wol
= sis900_set_wol
2023 * mii_ioctl - process MII i/o control command
2024 * @net_dev: the net device to command for
2025 * @rq: parameter for command
2026 * @cmd: the i/o command
2028 * Process MII command like read/write MII register
2031 static int mii_ioctl(struct net_device
*net_dev
, struct ifreq
*rq
, int cmd
)
2033 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
2034 struct mii_ioctl_data
*data
= if_mii(rq
);
2037 case SIOCGMIIPHY
: /* Get address of MII PHY in use. */
2038 data
->phy_id
= sis_priv
->mii
->phy_addr
;
2041 case SIOCGMIIREG
: /* Read MII PHY register. */
2042 data
->val_out
= mdio_read(net_dev
, data
->phy_id
& 0x1f, data
->reg_num
& 0x1f);
2045 case SIOCSMIIREG
: /* Write MII PHY register. */
2046 mdio_write(net_dev
, data
->phy_id
& 0x1f, data
->reg_num
& 0x1f, data
->val_in
);
2054 * sis900_set_config - Set media type by net_device.set_config
2055 * @dev: the net device for media type change
2056 * @map: ifmap passed by ifconfig
2058 * Set media type to 10baseT, 100baseT or 0(for auto) by ifconfig
2059 * we support only port changes. All other runtime configuration
2060 * changes will be ignored
2063 static int sis900_set_config(struct net_device
*dev
, struct ifmap
*map
)
2065 struct sis900_private
*sis_priv
= netdev_priv(dev
);
2066 struct mii_phy
*mii_phy
= sis_priv
->mii
;
2070 if ((map
->port
!= (u_char
)(-1)) && (map
->port
!= dev
->if_port
)) {
2071 /* we switch on the ifmap->port field. I couldn't find anything
2072 * like a definition or standard for the values of that field.
2073 * I think the meaning of those values is device specific. But
2074 * since I would like to change the media type via the ifconfig
2075 * command I use the definition from linux/netdevice.h
2076 * (which seems to be different from the ifport(pcmcia) definition) */
2078 case IF_PORT_UNKNOWN
: /* use auto here */
2079 dev
->if_port
= map
->port
;
2080 /* we are going to change the media type, so the Link
2081 * will be temporary down and we need to reflect that
2082 * here. When the Link comes up again, it will be
2083 * sensed by the sis_timer procedure, which also does
2084 * all the rest for us */
2085 netif_carrier_off(dev
);
2087 /* read current state */
2088 status
= mdio_read(dev
, mii_phy
->phy_addr
, MII_CONTROL
);
2090 /* enable auto negotiation and reset the negotioation
2091 * (I don't really know what the auto negatiotiation
2092 * reset really means, but it sounds for me right to
2094 mdio_write(dev
, mii_phy
->phy_addr
,
2095 MII_CONTROL
, status
| MII_CNTL_AUTO
| MII_CNTL_RST_AUTO
);
2099 case IF_PORT_10BASET
: /* 10BaseT */
2100 dev
->if_port
= map
->port
;
2102 /* we are going to change the media type, so the Link
2103 * will be temporary down and we need to reflect that
2104 * here. When the Link comes up again, it will be
2105 * sensed by the sis_timer procedure, which also does
2106 * all the rest for us */
2107 netif_carrier_off(dev
);
2109 /* set Speed to 10Mbps */
2110 /* read current state */
2111 status
= mdio_read(dev
, mii_phy
->phy_addr
, MII_CONTROL
);
2113 /* disable auto negotiation and force 10MBit mode*/
2114 mdio_write(dev
, mii_phy
->phy_addr
,
2115 MII_CONTROL
, status
& ~(MII_CNTL_SPEED
|
2119 case IF_PORT_100BASET
: /* 100BaseT */
2120 case IF_PORT_100BASETX
: /* 100BaseTx */
2121 dev
->if_port
= map
->port
;
2123 /* we are going to change the media type, so the Link
2124 * will be temporary down and we need to reflect that
2125 * here. When the Link comes up again, it will be
2126 * sensed by the sis_timer procedure, which also does
2127 * all the rest for us */
2128 netif_carrier_off(dev
);
2130 /* set Speed to 100Mbps */
2131 /* disable auto negotiation and enable 100MBit Mode */
2132 status
= mdio_read(dev
, mii_phy
->phy_addr
, MII_CONTROL
);
2133 mdio_write(dev
, mii_phy
->phy_addr
,
2134 MII_CONTROL
, (status
& ~MII_CNTL_SPEED
) |
2139 case IF_PORT_10BASE2
: /* 10Base2 */
2140 case IF_PORT_AUI
: /* AUI */
2141 case IF_PORT_100BASEFX
: /* 100BaseFx */
2142 /* These Modes are not supported (are they?)*/
2154 * sis900_mcast_bitnr - compute hashtable index
2155 * @addr: multicast address
2156 * @revision: revision id of chip
2158 * SiS 900 uses the most sigificant 7 bits to index a 128 bits multicast
2159 * hash table, which makes this function a little bit different from other drivers
2160 * SiS 900 B0 & 635 M/B uses the most significat 8 bits to index 256 bits
2161 * multicast hash table.
2164 static inline u16
sis900_mcast_bitnr(u8
*addr
, u8 revision
)
2167 u32 crc
= ether_crc(6, addr
);
2169 /* leave 8 or 7 most siginifant bits */
2170 if ((revision
>= SIS635A_900_REV
) || (revision
== SIS900B_900_REV
))
2171 return ((int)(crc
>> 24));
2173 return ((int)(crc
>> 25));
2177 * set_rx_mode - Set SiS900 receive mode
2178 * @net_dev: the net device to be set
2180 * Set SiS900 receive mode for promiscuous, multicast, or broadcast mode.
2181 * And set the appropriate multicast filter.
2182 * Multicast hash table changes from 128 to 256 bits for 635M/B & 900B0.
2185 static void set_rx_mode(struct net_device
*net_dev
)
2187 long ioaddr
= net_dev
->base_addr
;
2188 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
2189 u16 mc_filter
[16] = {0}; /* 256/128 bits multicast hash table */
2190 int i
, table_entries
;
2193 /* 635 Hash Table entries = 256(2^16) */
2194 if((sis_priv
->chipset_rev
>= SIS635A_900_REV
) ||
2195 (sis_priv
->chipset_rev
== SIS900B_900_REV
))
2200 if (net_dev
->flags
& IFF_PROMISC
) {
2201 /* Accept any kinds of packets */
2202 rx_mode
= RFPromiscuous
;
2203 for (i
= 0; i
< table_entries
; i
++)
2204 mc_filter
[i
] = 0xffff;
2205 } else if ((netdev_mc_count(net_dev
) > multicast_filter_limit
) ||
2206 (net_dev
->flags
& IFF_ALLMULTI
)) {
2207 /* too many multicast addresses or accept all multicast packet */
2208 rx_mode
= RFAAB
| RFAAM
;
2209 for (i
= 0; i
< table_entries
; i
++)
2210 mc_filter
[i
] = 0xffff;
2212 /* Accept Broadcast packet, destination address matchs our
2213 * MAC address, use Receive Filter to reject unwanted MCAST
2215 struct netdev_hw_addr
*ha
;
2218 netdev_for_each_mc_addr(ha
, net_dev
) {
2219 unsigned int bit_nr
;
2221 bit_nr
= sis900_mcast_bitnr(ha
->addr
,
2222 sis_priv
->chipset_rev
);
2223 mc_filter
[bit_nr
>> 4] |= (1 << (bit_nr
& 0xf));
2227 /* update Multicast Hash Table in Receive Filter */
2228 for (i
= 0; i
< table_entries
; i
++) {
2229 /* why plus 0x04 ??, That makes the correct value for hash table. */
2230 outl((u32
)(0x00000004+i
) << RFADDR_shift
, ioaddr
+ rfcr
);
2231 outl(mc_filter
[i
], ioaddr
+ rfdr
);
2234 outl(RFEN
| rx_mode
, ioaddr
+ rfcr
);
2236 /* sis900 is capable of looping back packets at MAC level for
2237 * debugging purpose */
2238 if (net_dev
->flags
& IFF_LOOPBACK
) {
2240 /* We must disable Tx/Rx before setting loopback mode */
2241 cr_saved
= inl(ioaddr
+ cr
);
2242 outl(cr_saved
| TxDIS
| RxDIS
, ioaddr
+ cr
);
2243 /* enable loopback */
2244 outl(inl(ioaddr
+ txcfg
) | TxMLB
, ioaddr
+ txcfg
);
2245 outl(inl(ioaddr
+ rxcfg
) | RxATX
, ioaddr
+ rxcfg
);
2247 outl(cr_saved
, ioaddr
+ cr
);
2252 * sis900_reset - Reset sis900 MAC
2253 * @net_dev: the net device to reset
2255 * reset sis900 MAC and wait until finished
2256 * reset through command register
2257 * change backoff algorithm for 900B0 & 635 M/B
2260 static void sis900_reset(struct net_device
*net_dev
)
2262 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
2263 long ioaddr
= net_dev
->base_addr
;
2265 u32 status
= TxRCMP
| RxRCMP
;
2267 outl(0, ioaddr
+ ier
);
2268 outl(0, ioaddr
+ imr
);
2269 outl(0, ioaddr
+ rfcr
);
2271 outl(RxRESET
| TxRESET
| RESET
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
2273 /* Check that the chip has finished the reset. */
2274 while (status
&& (i
++ < 1000)) {
2275 status
^= (inl(isr
+ ioaddr
) & status
);
2278 if( (sis_priv
->chipset_rev
>= SIS635A_900_REV
) ||
2279 (sis_priv
->chipset_rev
== SIS900B_900_REV
) )
2280 outl(PESEL
| RND_CNT
, ioaddr
+ cfg
);
2282 outl(PESEL
, ioaddr
+ cfg
);
2286 * sis900_remove - Remove sis900 device
2287 * @pci_dev: the pci device to be removed
2289 * remove and release SiS900 net device
2292 static void __devexit
sis900_remove(struct pci_dev
*pci_dev
)
2294 struct net_device
*net_dev
= pci_get_drvdata(pci_dev
);
2295 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
2296 struct mii_phy
*phy
= NULL
;
2298 while (sis_priv
->first_mii
) {
2299 phy
= sis_priv
->first_mii
;
2300 sis_priv
->first_mii
= phy
->next
;
2304 pci_free_consistent(pci_dev
, RX_TOTAL_SIZE
, sis_priv
->rx_ring
,
2305 sis_priv
->rx_ring_dma
);
2306 pci_free_consistent(pci_dev
, TX_TOTAL_SIZE
, sis_priv
->tx_ring
,
2307 sis_priv
->tx_ring_dma
);
2308 unregister_netdev(net_dev
);
2309 free_netdev(net_dev
);
2310 pci_release_regions(pci_dev
);
2311 pci_set_drvdata(pci_dev
, NULL
);
2316 static int sis900_suspend(struct pci_dev
*pci_dev
, pm_message_t state
)
2318 struct net_device
*net_dev
= pci_get_drvdata(pci_dev
);
2319 long ioaddr
= net_dev
->base_addr
;
2321 if(!netif_running(net_dev
))
2324 netif_stop_queue(net_dev
);
2325 netif_device_detach(net_dev
);
2327 /* Stop the chip's Tx and Rx Status Machine */
2328 outl(RxDIS
| TxDIS
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
2330 pci_set_power_state(pci_dev
, PCI_D3hot
);
2331 pci_save_state(pci_dev
);
2336 static int sis900_resume(struct pci_dev
*pci_dev
)
2338 struct net_device
*net_dev
= pci_get_drvdata(pci_dev
);
2339 struct sis900_private
*sis_priv
= netdev_priv(net_dev
);
2340 long ioaddr
= net_dev
->base_addr
;
2342 if(!netif_running(net_dev
))
2344 pci_restore_state(pci_dev
);
2345 pci_set_power_state(pci_dev
, PCI_D0
);
2347 sis900_init_rxfilter(net_dev
);
2349 sis900_init_tx_ring(net_dev
);
2350 sis900_init_rx_ring(net_dev
);
2352 set_rx_mode(net_dev
);
2354 netif_device_attach(net_dev
);
2355 netif_start_queue(net_dev
);
2357 sis900_set_mode(ioaddr
, HW_SPEED_10_MBPS
, FDX_CAPABLE_HALF_SELECTED
);
2359 /* Enable all known interrupts by setting the interrupt mask. */
2360 outl((RxSOVR
|RxORN
|RxERR
|RxOK
|TxURN
|TxERR
|TxIDLE
), ioaddr
+ imr
);
2361 outl(RxENA
| inl(ioaddr
+ cr
), ioaddr
+ cr
);
2362 outl(IE
, ioaddr
+ ier
);
2364 sis900_check_mode(net_dev
, sis_priv
->mii
);
2368 #endif /* CONFIG_PM */
2370 static struct pci_driver sis900_pci_driver
= {
2371 .name
= SIS900_MODULE_NAME
,
2372 .id_table
= sis900_pci_tbl
,
2373 .probe
= sis900_probe
,
2374 .remove
= __devexit_p(sis900_remove
),
2376 .suspend
= sis900_suspend
,
2377 .resume
= sis900_resume
,
2378 #endif /* CONFIG_PM */
2381 static int __init
sis900_init_module(void)
2383 /* when a module, this is printed whether or not devices are found in probe */
2388 return pci_register_driver(&sis900_pci_driver
);
2391 static void __exit
sis900_cleanup_module(void)
2393 pci_unregister_driver(&sis900_pci_driver
);
2396 module_init(sis900_init_module
);
2397 module_exit(sis900_cleanup_module
);