1 /* -*- Mode:C; c-basic-offset:4; -*- */
4 sis900.c: An SiS 900/7016 PCI Fast Ethernet driver for Etherboot
5 Copyright (C) 2001 Entity Cyber, Inc.
7 Revision: 1.0 March 1, 2001
9 Author: Marty Connor (mdc@etherboot.org)
11 Adapted from a Linux driver which was written by Donald Becker
12 and modified by Ollie Lho and Chin-Shan Li of SiS Corporation.
13 Rewritten for Etherboot by Marty Connor.
15 This software may be used and distributed according to the terms
16 of the GNU Public License (GPL), incorporated herein by reference.
19 SiS 7016 Fast Ethernet PCI Bus 10/100 Mbps LAN Controller with OnNow Support,
20 preliminary Rev. 1.0 Jan. 14, 1998
21 SiS 900 Fast Ethernet PCI Bus 10/100 Mbps LAN Single Chip with OnNow Support,
22 preliminary Rev. 1.0 Nov. 10, 1998
23 SiS 7014 Single Chip 100BASE-TX/10BASE-T Physical Layer Solution,
24 preliminary Rev. 1.0 Jan. 18, 1998
25 http://www.sis.com.tw/support/databook.htm */
27 /* Revision History */
30 07 Dec 2003 timlegge - Enabled Multicast Support
31 06 Dec 2003 timlegge - Fixed relocation issue in 5.2
32 04 Jan 2002 Chien-Yu Chen, Doug Ambrisko, Marty Connor Patch to Etherboot 5.0.5
33 Added support for the SiS 630ET plus various bug fixes from linux kernel
36 Initial Release. Tested with PCI based sis900 card and ThinkNIC
38 20 March 2001 P.Koegel
39 added support for sis630e and PHY ICS1893 and RTL8201
40 Testet with SIS730S chipset + ICS1893
46 #include "etherboot.h"
56 static struct nic_operations sis900_operations;
58 static int sis900_debug = 0;
60 static unsigned short vendor, dev_id;
61 static unsigned long ioaddr;
62 static u8 pci_revision;
64 static unsigned int cur_phy;
66 static unsigned int cur_rx;
70 BufferDesc rxd[NUM_RX_DESC];
71 unsigned char txb[TX_BUF_SIZE];
72 unsigned char rxb[NUM_RX_DESC * RX_BUF_SIZE];
73 } sis900_bufs __shared;
74 #define txd sis900_bufs.txd
75 #define rxd sis900_bufs.rxd
76 #define txb sis900_bufs.txb
77 #define rxb sis900_bufs.rxb
80 static struct mac_chip_info {
82 u16 vendor_id, device_id, flags;
84 } mac_chip_table[] = {
85 { "SiS 900 PCI Fast Ethernet", PCI_VENDOR_ID_SIS, PCI_DEVICE_ID_SIS900,
86 PCI_COMMAND_IO|PCI_COMMAND_MASTER, SIS900_TOTAL_SIZE},
87 { "SiS 7016 PCI Fast Ethernet",PCI_VENDOR_ID_SIS, PCI_DEVICE_ID_SIS7016,
88 PCI_COMMAND_IO|PCI_COMMAND_MASTER, SIS900_TOTAL_SIZE},
89 {0,0,0,0,0} /* 0 terminated list. */
93 static void sis900_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);
94 static void amd79c901_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);
95 static void ics1893_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);
96 static void rtl8201_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);
97 static void vt6103_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);
99 static struct mii_chip_info {
103 void (*read_mode) (struct nic *nic, int phy_addr, int *speed, int *duplex);
104 } mii_chip_table[] = {
105 {"SiS 900 Internal MII PHY", 0x001d, 0x8000, sis900_read_mode},
106 {"SiS 7014 Physical Layer Solution", 0x0016, 0xf830,sis900_read_mode},
107 {"AMD 79C901 10BASE-T PHY", 0x0000, 0x6B70, amd79c901_read_mode},
108 {"AMD 79C901 HomePNA PHY", 0x0000, 0x6B90, amd79c901_read_mode},
109 {"ICS 1893 Integrated PHYceiver" , 0x0015, 0xf440,ics1893_read_mode},
110 // {"NS 83851 PHY",0x2000, 0x5C20, MIX },
111 {"RTL 8201 10/100Mbps Phyceiver" , 0x0000, 0x8200,rtl8201_read_mode},
112 {"VIA 6103 10/100Mbps Phyceiver", 0x0101, 0x8f20,vt6103_read_mode},
116 static struct mii_phy {
117 struct mii_phy * next;
118 struct mii_chip_info * chip_info;
126 // PCI to ISA bridge for SIS640E access
127 static struct pci_device_id pci_isa_bridge_list[] = {
128 { .vendor = 0x1039, .device = 0x0008,
129 .name = "SIS 85C503/5513 PCI to ISA bridge"},
132 PCI_DRIVER( sis_bridge_pci_driver, pci_isa_bridge_list, PCI_NO_CLASS );
134 static struct device_driver sis_bridge_driver = {
135 .name = "SIS ISA bridge",
136 .bus_driver = &pci_driver,
137 .bus_driver_info = ( struct bus_driver_info * ) &sis_bridge_pci_driver,
141 /* Function Prototypes */
143 static int sis900_probe(struct nic *nic,struct pci_device *pci);
145 static u16 sis900_read_eeprom(int location);
146 static void sis900_mdio_reset(long mdio_addr);
147 static void sis900_mdio_idle(long mdio_addr);
148 static u16 sis900_mdio_read(int phy_id, int location);
150 static void sis900_mdio_write(int phy_id, int location, int val);
152 static void sis900_init(struct nic *nic);
154 static void sis900_reset(struct nic *nic);
156 static void sis900_init_rxfilter(struct nic *nic);
157 static void sis900_init_txd(struct nic *nic);
158 static void sis900_init_rxd(struct nic *nic);
159 static void sis900_set_rx_mode(struct nic *nic);
160 static void sis900_check_mode(struct nic *nic);
162 static void sis900_transmit(struct nic *nic, const char *d,
163 unsigned int t, unsigned int s, const char *p);
164 static int sis900_poll(struct nic *nic, int retrieve);
166 static void sis900_disable(struct nic *nic);
168 static void sis900_irq(struct nic *nic, irq_action_t action);
171 * sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model
172 * @pci_dev: the sis900 pci device
173 * @net_dev: the net device to get address for
175 * Older SiS900 and friends, use EEPROM to store MAC address.
176 * MAC address is read from read_eeprom() into @net_dev->dev_addr.
179 static int sis900_get_mac_addr(struct pci_device * pci_dev __unused, struct nic *nic)
184 /* check to see if we have sane EEPROM */
185 signature = (u16) sis900_read_eeprom( EEPROMSignature);
186 if (signature == 0xffff || signature == 0x0000) {
187 printf ("sis900_probe: Error EERPOM read %hX\n", signature);
191 /* get MAC address from EEPROM */
192 for (i = 0; i < 3; i++)
193 ((u16 *)(nic->node_addr))[i] = sis900_read_eeprom(i+EEPROMMACAddr);
198 * sis96x_get_mac_addr: - Get MAC address for SiS962 or SiS963 model
199 * @pci_dev: the sis900 pci device
200 * @net_dev: the net device to get address for
202 * SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM
204 * LAN and 1394. When access EEPROM, send EEREQ signal to hardware first
205 * and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access
206 * by LAN, otherwise is not. After MAC address is read from EEPROM, send
207 * EEDONE signal to refuse EEPROM access by LAN.
208 * The EEPROM map of SiS962 or SiS963 is different to SiS900.
209 * The signature field in SiS962 or SiS963 spec is meaningless.
210 * MAC address is read into @net_dev->dev_addr.
213 static int sis96x_get_mac_addr(struct pci_device * pci_dev __unused, struct nic *nic)
215 /* long ioaddr = net_dev->base_addr; */
216 long ee_addr = ioaddr + mear;
220 printf("Alternate function\n");
222 outl(EEREQ, ee_addr);
223 while(waittime < 2000) {
224 if(inl(ee_addr) & EEGNT) {
226 /* get MAC address from EEPROM */
227 for (i = 0; i < 3; i++)
228 ((u16 *)(nic->node_addr))[i] = sis900_read_eeprom(i+EEPROMMACAddr);
230 outl(EEDONE, ee_addr);
237 outl(EEDONE, ee_addr);
242 * sis630e_get_mac_addr: - Get MAC address for SiS630E model
243 * @pci_dev: the sis900 pci device
244 * @net_dev: the net device to get address for
246 * SiS630E model, use APC CMOS RAM to store MAC address.
247 * APC CMOS RAM is accessed through ISA bridge.
248 * MAC address is read into @net_dev->dev_addr.
251 static int sis630e_get_mac_addr(struct pci_device * pci_dev __unused, struct nic *nic)
256 struct bus_loc bus_loc;
259 struct bus_dev bus_dev;
260 struct pci_device isa_bridge;
264 /* find PCI to ISA bridge */
265 memset(&bus_loc, 0, sizeof(bus_loc));
266 if ( ! find_by_driver ( &bus_loc, &u.bus_dev, &sis_bridge_driver, 0 ) )
270 pci_read_config_byte(&u.isa_bridge, 0x48, ®);
271 pci_write_config_byte(&u.isa_bridge, 0x48, reg | 0x40);
273 for (i = 0; i < ETH_ALEN; i++)
275 outb(0x09 + i, 0x70);
276 ((u8 *)(nic->node_addr))[i] = inb(0x71);
278 pci_write_config_byte(&u.isa_bridge, 0x48, reg & ~0x40);
284 * sis630e_get_mac_addr: - Get MAC address for SiS630E model
285 * @pci_dev: the sis900 pci device
286 * @net_dev: the net device to get address for
288 * SiS630E model, use APC CMOS RAM to store MAC address.
289 * APC CMOS RAM is accessed through ISA bridge.
290 * MAC address is read into @net_dev->dev_addr.
293 static int sis635_get_mac_addr(struct pci_device * pci_dev __unused, struct nic *nic)
299 rfcrSave = inl(rfcr + ioaddr);
301 outl(rfcrSave | RELOAD, ioaddr + cr);
302 outl(0, ioaddr + cr);
304 /* disable packet filtering before setting filter */
305 outl(rfcrSave & ~RFEN, rfcr + ioaddr);
307 /* load MAC addr to filter data register */
308 for (i = 0 ; i < 3 ; i++) {
309 outl((i << RFADDR_shift), ioaddr + rfcr);
310 *( ((u16 *)nic->node_addr) + i) = inw(ioaddr + rfdr);
313 /* enable packet filitering */
314 outl(rfcrSave | RFEN, rfcr + ioaddr);
320 * Function: sis900_probe
322 * Description: initializes initializes the NIC, retrieves the
323 * MAC address of the card, and sets up some globals required by
327 * leaves the ioaddress of the sis900 chip in the variable ioaddr.
328 * leaves the sis900 initialized, and ready to recieve packets.
330 * Returns: struct nic *: pointer to NIC data structure
333 static int sis900_probe ( struct nic *nic, struct pci_device *pci ) {
341 if (pci->ioaddr == 0)
345 pci_fill_nic ( nic, pci );
346 nic->ioaddr = pci->ioaddr;
347 ioaddr = pci->ioaddr;
348 vendor = pci->vendor;
349 dev_id = pci->device;
352 pci_write_config_dword(pci, 0x40, 0x00000000);
354 adjust_pci_device(pci);
356 /* get MAC address */
358 pci_read_config_byte(pci, PCI_REVISION, &revision);
360 /* save for use later in sis900_reset() */
361 pci_revision = revision;
363 if (revision == SIS630E_900_REV)
364 ret = sis630e_get_mac_addr(pci, nic);
365 else if ((revision > 0x81) && (revision <= 0x90))
366 ret = sis635_get_mac_addr(pci, nic);
367 else if (revision == SIS96x_900_REV)
368 ret = sis96x_get_mac_addr(pci, nic);
370 ret = sis900_get_mac_addr(pci, nic);
374 printf ("sis900_probe: Error MAC address not found\n");
378 /* 630ET : set the mii access mode as software-mode */
379 if (revision == SIS630ET_900_REV)
380 outl(ACCESSMODE | inl(ioaddr + cr), ioaddr + cr);
382 DBG( "sis900_probe: Vendor:%#hX Device:%#hX\n", vendor, dev_id );
384 /* probe for mii transceiver */
385 /* search for total of 32 possible mii phy addresses */
388 for (phy_addr = 0; phy_addr < 32; phy_addr++) {
390 u16 phy_id0, phy_id1;
392 mii_status = sis900_mdio_read(phy_addr, MII_STATUS);
393 if (mii_status == 0xffff || mii_status == 0x0000)
394 /* the mii is not accessable, try next one */
397 phy_id0 = sis900_mdio_read(phy_addr, MII_PHY_ID0);
398 phy_id1 = sis900_mdio_read(phy_addr, MII_PHY_ID1);
400 /* search our mii table for the current mii */
401 for (i = 0; mii_chip_table[i].phy_id1; i++) {
403 if ((phy_id0 == mii_chip_table[i].phy_id0) &&
404 ((phy_id1 & 0xFFF0) == mii_chip_table[i].phy_id1)){
406 printf("sis900_probe: %s transceiver found at address %d.\n",
407 mii_chip_table[i].name, phy_addr);
409 mii.chip_info = &mii_chip_table[i];
410 mii.phy_addr = phy_addr;
411 mii.status = sis900_mdio_read(phy_addr, MII_STATUS);
421 printf("sis900_probe: No MII transceivers found!\n");
425 /* Arbitrarily select the last PHY found as current PHY */
426 cur_phy = mii.phy_addr;
427 printf("sis900_probe: Using %s as default\n", mii.chip_info->name);
429 /* initialize device */
431 nic->nic_op = &sis900_operations;
440 * EEPROM Routines: These functions read and write to EEPROM for
441 * retrieving the MAC address and other configuration information about
445 /* Delay between EEPROM clock transitions. */
446 #define eeprom_delay() inl(ee_addr)
449 /* Function: sis900_read_eeprom
451 * Description: reads and returns a given location from EEPROM
453 * Arguments: int location: requested EEPROM location
455 * Returns: u16: contents of requested EEPROM location
459 /* Read Serial EEPROM through EEPROM Access Register, Note that location is
460 in word (16 bits) unit */
461 static u16 sis900_read_eeprom(int location)
465 long ee_addr = ioaddr + mear;
466 u32 read_cmd = location | EEread;
473 /* Shift the read command (9) bits out. */
474 for (i = 8; i >= 0; i--) {
475 u32 dataval = (read_cmd & (1 << i)) ? EEDI | EECS : EECS;
476 outl(dataval, ee_addr);
478 outl(dataval | EECLK, ee_addr);
484 /* read the 16-bits data in */
485 for (i = 16; i > 0; i--) {
488 outl(EECS | EECLK, ee_addr);
490 retval = (retval << 1) | ((inl(ee_addr) & EEDO) ? 1 : 0);
494 /* Terminate the EEPROM access. */
497 // outl(EECLK, ee_addr);
502 #define sis900_mdio_delay() inl(mdio_addr)
506 Read and write the MII management registers using software-generated
507 serial MDIO protocol. Note that the command bits and data bits are
511 static void sis900_mdio_idle(long mdio_addr)
513 outl(MDIO | MDDIR, mdio_addr);
515 outl(MDIO | MDDIR | MDC, mdio_addr);
518 /* Syncronize the MII management interface by shifting 32 one bits out. */
519 static void sis900_mdio_reset(long mdio_addr)
523 for (i = 31; i >= 0; i--) {
524 outl(MDDIR | MDIO, mdio_addr);
526 outl(MDDIR | MDIO | MDC, mdio_addr);
532 static u16 sis900_mdio_read(int phy_id, int location)
534 long mdio_addr = ioaddr + mear;
535 int mii_cmd = MIIread|(phy_id<<MIIpmdShift)|(location<<MIIregShift);
539 sis900_mdio_reset(mdio_addr);
540 sis900_mdio_idle(mdio_addr);
542 for (i = 15; i >= 0; i--) {
543 int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR;
544 outl(dataval, mdio_addr);
546 outl(dataval | MDC, mdio_addr);
550 /* Read the 16 data bits. */
551 for (i = 16; i > 0; i--) {
554 retval = (retval << 1) | ((inl(mdio_addr) & MDIO) ? 1 : 0);
555 outl(MDC, mdio_addr);
558 outl(0x00, mdio_addr);
563 static void sis900_mdio_write(int phy_id, int location, int value)
565 long mdio_addr = ioaddr + mear;
566 int mii_cmd = MIIwrite|(phy_id<<MIIpmdShift)|(location<<MIIregShift);
569 sis900_mdio_reset(mdio_addr);
570 sis900_mdio_idle(mdio_addr);
572 /* Shift the command bits out. */
573 for (i = 15; i >= 0; i--) {
574 int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR;
575 outb(dataval, mdio_addr);
577 outb(dataval | MDC, mdio_addr);
582 /* Shift the value bits out. */
583 for (i = 15; i >= 0; i--) {
584 int dataval = (value & (1 << i)) ? MDDIR | MDIO : MDDIR;
585 outl(dataval, mdio_addr);
587 outl(dataval | MDC, mdio_addr);
592 /* Clear out extra bits. */
593 for (i = 2; i > 0; i--) {
596 outb(MDC, mdio_addr);
599 outl(0x00, mdio_addr);
605 /* Function: sis900_init
607 * Description: resets the ethernet controller chip and various
608 * data structures required for sending and receiving packets.
610 * Arguments: struct nic *nic: NIC data structure
616 sis900_init(struct nic *nic)
618 /* Soft reset the chip. */
621 sis900_init_rxfilter(nic);
623 sis900_init_txd(nic);
624 sis900_init_rxd(nic);
626 sis900_set_rx_mode(nic);
628 sis900_check_mode(nic);
630 outl(RxENA| inl(ioaddr + cr), ioaddr + cr);
635 * Function: sis900_reset
637 * Description: disables interrupts and soft resets the controller chip
639 * Arguments: struct nic *nic: NIC data structure
645 sis900_reset(struct nic *nic __unused)
648 u32 status = TxRCMP | RxRCMP;
650 outl(0, ioaddr + ier);
651 outl(0, ioaddr + imr);
652 outl(0, ioaddr + rfcr);
654 outl(RxRESET | TxRESET | RESET | inl(ioaddr + cr), ioaddr + cr);
656 /* Check that the chip has finished the reset. */
657 while (status && (i++ < 1000)) {
658 status ^= (inl(isr + ioaddr) & status);
661 if( (pci_revision >= SIS635A_900_REV) || (pci_revision == SIS900B_900_REV) )
662 outl(PESEL | RND_CNT, ioaddr + cfg);
664 outl(PESEL, ioaddr + cfg);
668 /* Function: sis_init_rxfilter
670 * Description: sets receive filter address to our MAC address
672 * Arguments: struct nic *nic: NIC data structure
678 sis900_init_rxfilter(struct nic *nic)
683 rfcrSave = inl(rfcr + ioaddr);
685 /* disable packet filtering before setting filter */
686 outl(rfcrSave & ~RFEN, rfcr + ioaddr);
688 /* load MAC addr to filter data register */
689 for (i = 0 ; i < 3 ; i++) {
692 w = (u32) *((u16 *)(nic->node_addr)+i);
693 outl((i << RFADDR_shift), ioaddr + rfcr);
694 outl(w, ioaddr + rfdr);
696 if (sis900_debug > 0)
697 printf("sis900_init_rxfilter: Receive Filter Addrss[%d]=%lX\n",
698 i, inl(ioaddr + rfdr));
701 /* enable packet filitering */
702 outl(rfcrSave | RFEN, rfcr + ioaddr);
707 * Function: sis_init_txd
709 * Description: initializes the Tx descriptor
711 * Arguments: struct nic *nic: NIC data structure
717 sis900_init_txd(struct nic *nic __unused)
720 txd.cmdsts = (u32) 0;
721 txd.bufptr = virt_to_bus(&txb[0]);
723 /* load Transmit Descriptor Register */
724 outl(virt_to_bus(&txd), ioaddr + txdp);
725 if (sis900_debug > 0)
726 printf("sis900_init_txd: TX descriptor register loaded with: %lX\n",
731 /* Function: sis_init_rxd
733 * Description: initializes the Rx descriptor ring
735 * Arguments: struct nic *nic: NIC data structure
741 sis900_init_rxd(struct nic *nic __unused)
747 /* init RX descriptor */
748 for (i = 0; i < NUM_RX_DESC; i++) {
749 rxd[i].link = virt_to_bus((i+1 < NUM_RX_DESC) ? &rxd[i+1] : &rxd[0]);
750 rxd[i].cmdsts = (u32) RX_BUF_SIZE;
751 rxd[i].bufptr = virt_to_bus(&rxb[i*RX_BUF_SIZE]);
752 if (sis900_debug > 0)
753 printf("sis900_init_rxd: rxd[%d]=%p link=%X cmdsts=%X bufptr=%X\n",
754 i, &rxd[i], rxd[i].link, rxd[i].cmdsts, rxd[i].bufptr);
757 /* load Receive Descriptor Register */
758 outl(virt_to_bus(&rxd[0]), ioaddr + rxdp);
760 if (sis900_debug > 0)
761 printf("sis900_init_rxd: RX descriptor register loaded with: %lX\n",
767 /* Function: sis_init_rxd
770 * sets the receive mode to accept all broadcast packets and packets
771 * with our MAC address, and reject all multicast packets.
773 * Arguments: struct nic *nic: NIC data structure
778 static void sis900_set_rx_mode(struct nic *nic __unused)
780 int i, table_entries;
782 u16 mc_filter[16] = {0}; /* 256/128 bits multicast hash table */
784 if((pci_revision == SIS635A_900_REV) || (pci_revision == SIS900B_900_REV))
789 /* accept all multicast packet */
790 rx_mode = RFAAB | RFAAM;
791 for (i = 0; i < table_entries; i++)
792 mc_filter[i] = 0xffff;
794 /* update Multicast Hash Table in Receive Filter */
795 for (i = 0; i < table_entries; i++) {
796 /* why plus 0x04? That makes the correct value for hash table. */
797 outl((u32)(0x00000004+i) << RFADDR_shift, ioaddr + rfcr);
798 outl(mc_filter[i], ioaddr + rfdr);
801 /* Accept Broadcast and multicast packets, destination addresses that match
803 outl(RFEN | rx_mode, ioaddr + rfcr);
809 /* Function: sis900_check_mode
811 * Description: checks the state of transmit and receive
812 * parameters on the NIC, and updates NIC registers to match
814 * Arguments: struct nic *nic: NIC data structure
820 sis900_check_mode(struct nic *nic)
823 u32 tx_flags = 0, rx_flags = 0;
825 mii.chip_info->read_mode(nic, cur_phy, &speed, &duplex);
827 if( inl(ioaddr + cfg) & EDB_MASTER_EN ) {
828 tx_flags = TxATP | (DMA_BURST_64 << TxMXDMA_shift) | (TX_FILL_THRESH << TxFILLT_shift);
829 rx_flags = DMA_BURST_64 << RxMXDMA_shift;
832 tx_flags = TxATP | (DMA_BURST_512 << TxMXDMA_shift) | (TX_FILL_THRESH << TxFILLT_shift);
833 rx_flags = DMA_BURST_512 << RxMXDMA_shift;
836 if (speed == HW_SPEED_HOME || speed == HW_SPEED_10_MBPS) {
837 rx_flags |= (RxDRNT_10 << RxDRNT_shift);
838 tx_flags |= (TxDRNT_10 << TxDRNT_shift);
841 rx_flags |= (RxDRNT_100 << RxDRNT_shift);
842 tx_flags |= (TxDRNT_100 << TxDRNT_shift);
845 if (duplex == FDX_CAPABLE_FULL_SELECTED) {
846 tx_flags |= (TxCSI | TxHBI);
850 outl (tx_flags, ioaddr + txcfg);
851 outl (rx_flags, ioaddr + rxcfg);
855 /* Function: sis900_read_mode
857 * Description: retrieves and displays speed and duplex
858 * parameters from the NIC
860 * Arguments: struct nic *nic: NIC data structure
866 sis900_read_mode(struct nic *nic __unused, int phy_addr, int *speed, int *duplex)
870 u16 phy_id0, phy_id1;
872 /* STSOUT register is Latched on Transition, read operation updates it */
874 status = sis900_mdio_read(phy_addr, MII_STSOUT);
876 *speed = HW_SPEED_10_MBPS;
877 *duplex = FDX_CAPABLE_HALF_SELECTED;
879 if (status & (MII_NWAY_TX | MII_NWAY_TX_FDX))
880 *speed = HW_SPEED_100_MBPS;
881 if (status & ( MII_NWAY_TX_FDX | MII_NWAY_T_FDX))
882 *duplex = FDX_CAPABLE_FULL_SELECTED;
884 /* Workaround for Realtek RTL8201 PHY issue */
885 phy_id0 = sis900_mdio_read(phy_addr, MII_PHY_ID0);
886 phy_id1 = sis900_mdio_read(phy_addr, MII_PHY_ID1);
887 if((phy_id0 == 0x0000) && ((phy_id1 & 0xFFF0) == 0x8200)){
888 if(sis900_mdio_read(phy_addr, MII_CONTROL) & MII_CNTL_FDX)
889 *duplex = FDX_CAPABLE_FULL_SELECTED;
890 if(sis900_mdio_read(phy_addr, 0x0019) & 0x01)
891 *speed = HW_SPEED_100_MBPS;
894 if (status & MII_STSOUT_LINK_FAIL)
895 printf("sis900_read_mode: Media Link Off\n");
897 printf("sis900_read_mode: Media Link On %s %s-duplex \n",
898 *speed == HW_SPEED_100_MBPS ?
899 "100mbps" : "10mbps",
900 *duplex == FDX_CAPABLE_FULL_SELECTED ?
905 /* Function: amd79c901_read_mode
907 * Description: retrieves and displays speed and duplex
908 * parameters from the NIC
910 * Arguments: struct nic *nic: NIC data structure
916 amd79c901_read_mode(struct nic *nic __unused, int phy_addr, int *speed, int *duplex)
921 for (i = 0; i < 2; i++)
922 status = sis900_mdio_read(phy_addr, MII_STATUS);
924 if (status & MII_STAT_CAN_AUTO) {
926 for (i = 0; i < 2; i++)
927 status = sis900_mdio_read(phy_addr, MII_STATUS_SUMMARY);
928 if (status & MII_STSSUM_SPD)
929 *speed = HW_SPEED_100_MBPS;
931 *speed = HW_SPEED_10_MBPS;
932 if (status & MII_STSSUM_DPLX)
933 *duplex = FDX_CAPABLE_FULL_SELECTED;
935 *duplex = FDX_CAPABLE_HALF_SELECTED;
937 if (status & MII_STSSUM_LINK)
938 printf("amd79c901_read_mode: Media Link On %s %s-duplex \n",
939 *speed == HW_SPEED_100_MBPS ?
940 "100mbps" : "10mbps",
941 *duplex == FDX_CAPABLE_FULL_SELECTED ?
944 printf("amd79c901_read_mode: Media Link Off\n");
948 *speed = HW_SPEED_HOME;
949 *duplex = FDX_CAPABLE_HALF_SELECTED;
950 if (status & MII_STAT_LINK)
951 printf("amd79c901_read_mode:Media Link On 1mbps half-duplex \n");
953 printf("amd79c901_read_mode: Media Link Off\n");
959 * ics1893_read_mode: - read media mode for ICS1893 PHY
960 * @net_dev: the net device to read mode for
961 * @phy_addr: mii phy address
962 * @speed: the transmit speed to be determined
963 * @duplex: the duplex mode to be determined
965 * ICS1893 PHY use Quick Poll Detailed Status register
966 * to determine the speed and duplex mode for sis900
969 static void ics1893_read_mode(struct nic *nic __unused, int phy_addr, int *speed, int *duplex)
974 /* MII_QPDSTS is Latched, read twice in succession will reflect the current state */
975 for (i = 0; i < 2; i++)
976 status = sis900_mdio_read(phy_addr, MII_QPDSTS);
978 if (status & MII_STSICS_SPD)
979 *speed = HW_SPEED_100_MBPS;
981 *speed = HW_SPEED_10_MBPS;
983 if (status & MII_STSICS_DPLX)
984 *duplex = FDX_CAPABLE_FULL_SELECTED;
986 *duplex = FDX_CAPABLE_HALF_SELECTED;
988 if (status & MII_STSICS_LINKSTS)
989 printf("ics1893_read_mode: Media Link On %s %s-duplex \n",
990 *speed == HW_SPEED_100_MBPS ?
991 "100mbps" : "10mbps",
992 *duplex == FDX_CAPABLE_FULL_SELECTED ?
995 printf("ics1893_read_mode: Media Link Off\n");
999 * rtl8201_read_mode: - read media mode for rtl8201 phy
1000 * @nic: the net device to read mode for
1001 * @phy_addr: mii phy address
1002 * @speed: the transmit speed to be determined
1003 * @duplex: the duplex mode to be determined
1005 * read MII_STATUS register from rtl8201 phy
1006 * to determine the speed and duplex mode for sis900
1009 static void rtl8201_read_mode(struct nic *nic __unused, int phy_addr, int *speed, int *duplex)
1013 status = sis900_mdio_read(phy_addr, MII_STATUS);
1015 if (status & MII_STAT_CAN_TX_FDX) {
1016 *speed = HW_SPEED_100_MBPS;
1017 *duplex = FDX_CAPABLE_FULL_SELECTED;
1019 else if (status & MII_STAT_CAN_TX) {
1020 *speed = HW_SPEED_100_MBPS;
1021 *duplex = FDX_CAPABLE_HALF_SELECTED;
1023 else if (status & MII_STAT_CAN_T_FDX) {
1024 *speed = HW_SPEED_10_MBPS;
1025 *duplex = FDX_CAPABLE_FULL_SELECTED;
1027 else if (status & MII_STAT_CAN_T) {
1028 *speed = HW_SPEED_10_MBPS;
1029 *duplex = FDX_CAPABLE_HALF_SELECTED;
1032 if (status & MII_STAT_LINK)
1033 printf("rtl8201_read_mode: Media Link On %s %s-duplex \n",
1034 *speed == HW_SPEED_100_MBPS ?
1035 "100mbps" : "10mbps",
1036 *duplex == FDX_CAPABLE_FULL_SELECTED ?
1039 printf("rtl8201_read_config_mode: Media Link Off\n");
1043 * vt6103_read_mode: - read media mode for vt6103 phy
1044 * @nic: the net device to read mode for
1045 * @phy_addr: mii phy address
1046 * @speed: the transmit speed to be determined
1047 * @duplex: the duplex mode to be determined
1049 * read MII_STATUS register from rtl8201 phy
1050 * to determine the speed and duplex mode for sis900
1053 static void vt6103_read_mode(struct nic *nic __unused, int phy_addr, int *speed, int *duplex)
1057 status = sis900_mdio_read(phy_addr, MII_STATUS);
1059 if (status & MII_STAT_CAN_TX_FDX) {
1060 *speed = HW_SPEED_100_MBPS;
1061 *duplex = FDX_CAPABLE_FULL_SELECTED;
1063 else if (status & MII_STAT_CAN_TX) {
1064 *speed = HW_SPEED_100_MBPS;
1065 *duplex = FDX_CAPABLE_HALF_SELECTED;
1067 else if (status & MII_STAT_CAN_T_FDX) {
1068 *speed = HW_SPEED_10_MBPS;
1069 *duplex = FDX_CAPABLE_FULL_SELECTED;
1071 else if (status & MII_STAT_CAN_T) {
1072 *speed = HW_SPEED_10_MBPS;
1073 *duplex = FDX_CAPABLE_HALF_SELECTED;
1076 if (status & MII_STAT_LINK)
1077 printf("vt6103_read_mode: Media Link On %s %s-duplex \n",
1078 *speed == HW_SPEED_100_MBPS ?
1079 "100mbps" : "10mbps",
1080 *duplex == FDX_CAPABLE_FULL_SELECTED ?
1083 printf("vt6103_read_config_mode: Media Link Off\n");
1086 /* Function: sis900_transmit
1088 * Description: transmits a packet and waits for completion or timeout.
1090 * Arguments: char d[6]: destination ethernet address.
1091 * unsigned short t: ethernet protocol type.
1092 * unsigned short s: size of the data-part of the packet.
1093 * char *p: the data for the packet.
1099 sis900_transmit(struct nic *nic,
1100 const char *d, /* Destination */
1101 unsigned int t, /* Type */
1102 unsigned int s, /* size */
1103 const char *p) /* Packet */
1106 volatile u32 tx_status;
1108 /* Stop the transmitter */
1109 outl(TxDIS | inl(ioaddr + cr), ioaddr + cr);
1111 /* load Transmit Descriptor Register */
1112 outl(virt_to_bus(&txd), ioaddr + txdp);
1113 if (sis900_debug > 1)
1114 printf("sis900_transmit: TX descriptor register loaded with: %lX\n",
1115 inl(ioaddr + txdp));
1117 memcpy(txb, d, ETH_ALEN);
1118 memcpy(txb + ETH_ALEN, nic->node_addr, ETH_ALEN);
1120 memcpy(txb + 2 * ETH_ALEN, (char*)&nstype, 2);
1121 memcpy(txb + ETH_HLEN, p, s);
1126 if (sis900_debug > 1)
1127 printf("sis900_transmit: sending %d bytes ethtype %hX\n", (int) s, t);
1129 /* pad to minimum packet size */
1130 while (s < ETH_ZLEN)
1133 /* set the transmit buffer descriptor and enable Transmit State Machine */
1134 txd.bufptr = virt_to_bus(&txb[0]);
1135 txd.cmdsts = (u32) OWN | s;
1137 /* restart the transmitter */
1138 outl(TxENA | inl(ioaddr + cr), ioaddr + cr);
1140 if (sis900_debug > 1)
1141 printf("sis900_transmit: Queued Tx packet size %d.\n", (int) s);
1143 to = currticks() + TX_TIMEOUT;
1145 while (((tx_status=txd.cmdsts) & OWN) && (currticks() < to))
1148 if (currticks() >= to) {
1149 printf("sis900_transmit: TX Timeout! Tx status %X.\n", tx_status);
1152 if (tx_status & (ABORT | UNDERRUN | OWCOLL)) {
1153 /* packet unsuccessfully transmited */
1154 printf("sis900_transmit: Transmit error, Tx status %X.\n", tx_status);
1156 /* Disable interrupts by clearing the interrupt mask. */
1157 outl(0, ioaddr + imr);
1161 /* Function: sis900_poll
1163 * Description: checks for a received packet and returns it if found.
1165 * Arguments: struct nic *nic: NIC data structure
1167 * Returns: 1 if a packet was recieved.
1168 * 0 if no pacet was recieved.
1171 * Returns (copies) the packet to the array nic->packet.
1172 * Returns the length of the packet in nic->packetlen.
1176 sis900_poll(struct nic *nic, int retrieve)
1178 u32 rx_status = rxd[cur_rx].cmdsts;
1181 if (sis900_debug > 2)
1182 printf("sis900_poll: cur_rx:%d, status:%X\n", cur_rx, rx_status);
1184 if (!(rx_status & OWN))
1187 if (sis900_debug > 1)
1188 printf("sis900_poll: got a packet: cur_rx:%d, status:%X\n",
1191 if ( ! retrieve ) return 1;
1193 nic->packetlen = (rx_status & DSIZE) - CRC_SIZE;
1195 if (rx_status & (ABORT|OVERRUN|TOOLONG|RUNT|RXISERR|CRCERR|FAERR)) {
1196 /* corrupted packet received */
1197 printf("sis900_poll: Corrupted packet received, buffer status = %X\n",
1201 /* give packet to higher level routine */
1202 memcpy(nic->packet, (rxb + cur_rx*RX_BUF_SIZE), nic->packetlen);
1206 /* return the descriptor and buffer to receive ring */
1207 rxd[cur_rx].cmdsts = RX_BUF_SIZE;
1208 rxd[cur_rx].bufptr = virt_to_bus(&rxb[cur_rx*RX_BUF_SIZE]);
1210 if (++cur_rx == NUM_RX_DESC)
1213 /* re-enable the potentially idle receive state machine */
1214 outl(RxENA | inl(ioaddr + cr), ioaddr + cr);
1221 /* Function: sis900_disable
1223 * Description: Turns off interrupts and stops Tx and Rx engines
1225 * Arguments: struct nic *nic: NIC data structure
1231 sis900_disable ( struct nic *nic ) {
1235 /* Disable interrupts by clearing the interrupt mask. */
1236 outl(0, ioaddr + imr);
1237 outl(0, ioaddr + ier);
1239 /* Stop the chip's Tx and Rx Status Machine */
1240 outl(RxDIS | TxDIS | inl(ioaddr + cr), ioaddr + cr);
1244 /* Function: sis900_irq
1246 * Description: Enable, Disable, or Force, interrupts
1248 * Arguments: struct nic *nic: NIC data structure
1249 * irq_action_t action: Requested action
1255 sis900_irq(struct nic *nic __unused, irq_action_t action __unused)
1267 static struct nic_operations sis900_operations = {
1268 .connect = dummy_connect,
1269 .poll = sis900_poll,
1270 .transmit = sis900_transmit,
1274 static struct pci_device_id sis900_nics[] = {
1275 PCI_ROM(0x1039, 0x0900, "sis900", "SIS900"),
1276 PCI_ROM(0x1039, 0x7016, "sis7016", "SIS7016"),
1279 PCI_DRIVER ( sis900_driver, sis900_nics, PCI_NO_CLASS );
1281 DRIVER ( "SIS900", nic_driver, pci_driver, sis900_driver,
1282 sis900_probe, sis900_disable );