📄 sis900.c
字号:
/* -*- Mode:C; c-basic-offset:4; -*- *//* sis900.c: An SiS 900/7016 PCI Fast Ethernet driver for Etherboot Copyright (C) 2001 Entity Cyber, Inc. Revision: 1.0 March 1, 2001 Author: Marty Connor (mdc@thinguin.org) Adapted from a Linux driver which was written by Donald Becker and modified by Ollie Lho and Chin-Shan Li of SiS Corporation. Rewritten for Etherboot by Marty Connor. This software may be used and distributed according to the terms of the GNU Public License (GPL), incorporated herein by reference. References: SiS 7016 Fast Ethernet PCI Bus 10/100 Mbps LAN Controller with OnNow Support, preliminary Rev. 1.0 Jan. 14, 1998 SiS 900 Fast Ethernet PCI Bus 10/100 Mbps LAN Single Chip with OnNow Support, preliminary Rev. 1.0 Nov. 10, 1998 SiS 7014 Single Chip 100BASE-TX/10BASE-T Physical Layer Solution, preliminary Rev. 1.0 Jan. 18, 1998 http://www.sis.com.tw/support/databook.htm *//* Revision History *//* 01 March 2001 mdc 1.0 Initial Release. Tested with PCI based sis900 card and ThinkNIC computer. 20 March 2001 P.Koegel added support for sis630e and PHY ICS1893 and RTL8201 Testet with SIS730S chipset + ICS1893*//* Includes */#include "etherboot.h"#include "nic.h"#include "pci.h"#include "cards.h"#include "sis900.h"/* Globals */static int sis900_debug = 0;static unsigned short vendor, dev_id;static unsigned long ioaddr;static unsigned int cur_phy;static unsigned int cur_rx;static BufferDesc txd;static BufferDesc rxd[NUM_RX_DESC];#ifdef USE_LOWMEM_BUFFER#define txb ((char *)0x10000 - TX_BUF_SIZE)#define rxb ((char *)0x10000 - NUM_RX_DESC*RX_BUF_SIZE - TX_BUF_SIZE)#elsestatic unsigned char txb[TX_BUF_SIZE];static unsigned char rxb[NUM_RX_DESC * RX_BUF_SIZE];#endifstatic struct mac_chip_info { const char *name; u16 vendor_id, device_id, flags; int io_size;} mac_chip_table[] = { { "SiS 900 PCI Fast Ethernet", PCI_VENDOR_ID_SIS, PCI_DEVICE_ID_SIS900, PCI_COMMAND_IO|PCI_COMMAND_MASTER, SIS900_TOTAL_SIZE}, { "SiS 7016 PCI Fast Ethernet",PCI_VENDOR_ID_SIS, PCI_DEVICE_ID_SIS7016, PCI_COMMAND_IO|PCI_COMMAND_MASTER, SIS900_TOTAL_SIZE}, {0,0,0,0,0} /* 0 terminated list. */};static void sis900_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);static void amd79c901_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);static void ics1893_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);static void rtl8201_read_mode(struct nic *nic, int phy_addr, int *speed, int *duplex);static struct mii_chip_info { const char * name; u16 phy_id0; u16 phy_id1; void (*read_mode) (struct nic *nic, int phy_addr, int *speed, int *duplex);} mii_chip_table[] = { {"SiS 900 Internal MII PHY", 0x001d, 0x8000, sis900_read_mode}, {"SiS 7014 Physical Layer Solution", 0x0016, 0xf830,sis900_read_mode}, {"AMD 79C901 10BASE-T PHY", 0x0000, 0x35b9, amd79c901_read_mode}, {"AMD 79C901 HomePNA PHY", 0x0000, 0x35c8, amd79c901_read_mode}, {"ICS 1893 Integrated PHYceiver" , 0x0015, 0xf441,ics1893_read_mode}, {"RTL 8201 10/100Mbps Phyceiver" , 0x0000, 0x8201,rtl8201_read_mode}, {0,0,0,0}};static struct mii_phy { struct mii_phy * next; struct mii_chip_info * chip_info; int phy_addr; u16 status;} mii;// PCI to ISA bridge for SIS640E accessstatic struct pci_device pci_isa_bridge_list[] = { { 0x1039, 0x0008, "SIS 85C503/5513 PCI to ISA bridge", 0, 0, 0, 0}, {0, 0, NULL, 0, 0, 0, 0}};/* Function Prototypes */struct nic *sis900_probe(struct nic *nic, unsigned short *io_addrs, struct pci_device *pci);static u16 sis900_read_eeprom(int location);static void sis900_mdio_reset(long mdio_addr);static void sis900_mdio_idle(long mdio_addr);static u16 sis900_mdio_read(int phy_id, int location);static void sis900_mdio_write(int phy_id, int location, int val);static void sis900_init(struct nic *nic);static void sis900_reset(struct nic *nic);static void sis900_init_rxfilter(struct nic *nic);static void sis900_init_txd(struct nic *nic);static void sis900_init_rxd(struct nic *nic);static void sis900_set_rx_mode(struct nic *nic);static void sis900_check_mode(struct nic *nic);static void sis900_transmit(struct nic *nic, const char *d, unsigned int t, unsigned int s, const char *p);static int sis900_poll(struct nic *nic);static void sis900_disable(struct nic *nic);/** * sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model * @pci_dev: the sis900 pci device * @net_dev: the net device to get address for * * Older SiS900 and friends, use EEPROM to store MAC address. * MAC address is read from read_eeprom() into @net_dev->dev_addr. */static int sis900_get_mac_addr(struct pci_device * pci_dev , struct nic *nic){ u16 signature; int i; /* check to see if we have sane EEPROM */ signature = (u16) sis900_read_eeprom( EEPROMSignature); if (signature == 0xffff || signature == 0x0000) { printf ("sis900_probe: Error EERPOM read %hX\n", signature); return 0; } /* get MAC address from EEPROM */ for (i = 0; i < 3; i++) ((u16 *)(nic->node_addr))[i] = sis900_read_eeprom(i+EEPROMMACAddr); return 1;}/** * sis630e_get_mac_addr: - Get MAC address for SiS630E model * @pci_dev: the sis900 pci device * @net_dev: the net device to get address for * * SiS630E model, use APC CMOS RAM to store MAC address. * APC CMOS RAM is accessed through ISA bridge. * MAC address is read into @net_dev->dev_addr. */static int sis630e_get_mac_addr(struct pci_device * pci_dev, struct nic *nic){ u8 reg; int i; struct pci_device *p; // find PCI to ISA bridge eth_pci_init(pci_isa_bridge_list); /* the firts entry in this list should contain bus/devfn */ p = pci_isa_bridge_list; pcibios_read_config_byte(p->bus,p->devfn, 0x48, ®); pcibios_write_config_byte(p->bus,p->devfn, 0x48, reg | 0x40); for (i = 0; i < ETH_ALEN; i++) { outb(0x09 + i, 0x70); ((u8 *)(nic->node_addr))[i] = inb(0x71); } pcibios_write_config_byte(p->bus,p->devfn, 0x48, reg & ~0x40); return 1;}/* * Function: sis900_probe * * Description: initializes initializes the NIC, retrieves the * MAC address of the card, and sets up some globals required by * other routines. * * Side effects: * leaves the ioaddress of the sis900 chip in the variable ioaddr. * leaves the sis900 initialized, and ready to recieve packets. * * Returns: struct nic *: pointer to NIC data structure */struct nic *sis900_probe(struct nic *nic, unsigned short *io_addrs, struct pci_device *pci){ int i; int found=0; int phy_addr; u16 signature; u8 revision; int ret; if (io_addrs == 0 || *io_addrs == 0) return NULL; ioaddr = *io_addrs & ~3; vendor = pci->vendor; dev_id = pci->dev_id; /* wakeup chip */ pcibios_write_config_dword(pci->bus, pci->devfn, 0x40, 0x00000000); adjust_pci_device(pci); /* get MAC address */ ret = 0; pcibios_read_config_byte(pci->bus,pci->devfn, PCI_REVISION, &revision); if (revision == SIS630E_900_REV || revision == SIS630EA1_900_REV) ret = sis630e_get_mac_addr(pci, nic); else if (revision == SIS630S_900_REV) ret = sis630e_get_mac_addr(pci, nic); else ret = sis900_get_mac_addr(pci, nic); if (ret == 0) { printf ("sis900_probe: Error MAC address not found\n"); return NULL; } printf("\nsis900_probe: MAC addr %! at ioaddr %#hX\n", nic->node_addr, ioaddr); printf("sis900_probe: Vendor:%#hX Device:%#hX\n", vendor, dev_id); /* probe for mii transceiver */ /* search for total of 32 possible mii phy addresses */ found = 0; for (phy_addr = 0; phy_addr < 32; phy_addr++) { u16 mii_status; u16 phy_id0, phy_id1; mii_status = sis900_mdio_read(phy_addr, MII_STATUS); if (mii_status == 0xffff || mii_status == 0x0000) /* the mii is not accessable, try next one */ continue; phy_id0 = sis900_mdio_read(phy_addr, MII_PHY_ID0); phy_id1 = sis900_mdio_read(phy_addr, MII_PHY_ID1); /* search our mii table for the current mii */ for (i = 0; mii_chip_table[i].phy_id1; i++) { if (phy_id0 == mii_chip_table[i].phy_id0) { printf("sis900_probe: %s transceiver found at address %d.\n", mii_chip_table[i].name, phy_addr); mii.chip_info = &mii_chip_table[i]; mii.phy_addr = phy_addr; mii.status = sis900_mdio_read(phy_addr, MII_STATUS); mii.next = NULL; found=1; break; } } } if (found == 0) { printf("sis900_probe: No MII transceivers found!\n"); return NULL; } /* Arbitrarily select the last PHY found as current PHY */ cur_phy = mii.phy_addr; printf("sis900_probe: Using %s as default\n", mii.chip_info->name); /* initialize device */ sis900_init(nic); nic->reset = sis900_init; nic->poll = sis900_poll; nic->transmit = sis900_transmit; nic->disable = sis900_disable; return nic;}/* * EEPROM Routines: These functions read and write to EEPROM for * retrieving the MAC address and other configuration information about * the card. *//* Delay between EEPROM clock transitions. */#define eeprom_delay() inl(ee_addr)/* Function: sis900_read_eeprom * * Description: reads and returns a given location from EEPROM * * Arguments: int location: requested EEPROM location * * Returns: u16: contents of requested EEPROM location * *//* Read Serial EEPROM through EEPROM Access Register, Note that location is in word (16 bits) unit */static u16 sis900_read_eeprom(int location){ int i; u16 retval = 0; long ee_addr = ioaddr + mear; u32 read_cmd = location | EEread; outl(0, ee_addr); eeprom_delay(); outl(EECLK, ee_addr); eeprom_delay(); /* Shift the read command (9) bits out. */ for (i = 8; i >= 0; i--) { u32 dataval = (read_cmd & (1 << i)) ? EEDI | EECS : EECS; outl(dataval, ee_addr); eeprom_delay(); outl(dataval | EECLK, ee_addr); eeprom_delay(); } outb(EECS, ee_addr); eeprom_delay(); /* read the 16-bits data in */ for (i = 16; i > 0; i--) { outl(EECS, ee_addr); eeprom_delay(); outl(EECS | EECLK, ee_addr); eeprom_delay(); retval = (retval << 1) | ((inl(ee_addr) & EEDO) ? 1 : 0); eeprom_delay(); } /* Terminate the EEPROM access. */ outl(0, ee_addr); eeprom_delay(); outl(EECLK, ee_addr); return (retval);}#define sis900_mdio_delay() inl(mdio_addr)/* Read and write the MII management registers using software-generated serial MDIO protocol. Note that the command bits and data bits are send out seperately */static void sis900_mdio_idle(long mdio_addr){ outl(MDIO | MDDIR, mdio_addr); sis900_mdio_delay(); outl(MDIO | MDDIR | MDC, mdio_addr);}/* Syncronize the MII management interface by shifting 32 one bits out. */static void sis900_mdio_reset(long mdio_addr){ int i; for (i = 31; i >= 0; i--) { outl(MDDIR | MDIO, mdio_addr); sis900_mdio_delay(); outl(MDDIR | MDIO | MDC, mdio_addr); sis900_mdio_delay(); } return;}static u16 sis900_mdio_read(int phy_id, int location){ long mdio_addr = ioaddr + mear; int mii_cmd = MIIread|(phy_id<<MIIpmdShift)|(location<<MIIregShift); u16 retval = 0; int i; sis900_mdio_reset(mdio_addr); sis900_mdio_idle(mdio_addr); for (i = 15; i >= 0; i--) { int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR; outl(dataval, mdio_addr); sis900_mdio_delay(); outl(dataval | MDC, mdio_addr); sis900_mdio_delay(); } /* Read the 16 data bits. */ for (i = 16; i > 0; i--) { outl(0, mdio_addr); sis900_mdio_delay(); retval = (retval << 1) | ((inl(mdio_addr) & MDIO) ? 1 : 0); outl(MDC, mdio_addr); sis900_mdio_delay(); } return retval;}static void sis900_mdio_write(int phy_id, int location, int value){ long mdio_addr = ioaddr + mear; int mii_cmd = MIIwrite|(phy_id<<MIIpmdShift)|(location<<MIIregShift); int i; sis900_mdio_reset(mdio_addr); sis900_mdio_idle(mdio_addr); /* Shift the command bits out. */ for (i = 15; i >= 0; i--) { int dataval = (mii_cmd & (1 << i)) ? MDDIR | MDIO : MDDIR; outb(dataval, mdio_addr); sis900_mdio_delay(); outb(dataval | MDC, mdio_addr); sis900_mdio_delay(); } sis900_mdio_delay(); /* Shift the value bits out. */ for (i = 15; i >= 0; i--) { int dataval = (value & (1 << i)) ? MDDIR | MDIO : MDDIR; outl(dataval, mdio_addr); sis900_mdio_delay(); outl(dataval | MDC, mdio_addr); sis900_mdio_delay(); } sis900_mdio_delay(); /* Clear out extra bits. */ for (i = 2; i > 0; i--) { outb(0, mdio_addr); sis900_mdio_delay(); outb(MDC, mdio_addr); sis900_mdio_delay(); } return;}/* Function: sis900_init * * Description: resets the ethernet controller chip and various * data structures required for sending and receiving packets. * * Arguments: struct nic *nic: NIC data structure * * returns: void. */static voidsis900_init(struct nic *nic){ /* Soft reset the chip. */ sis900_reset(nic); sis900_init_rxfilter(nic); sis900_init_txd(nic); sis900_init_rxd(nic); sis900_set_rx_mode(nic); sis900_check_mode(nic); outl(RxENA, ioaddr + cr);}/* * Function: sis900_reset * * Description: disables interrupts and soft resets the controller chip * * Arguments: struct nic *nic: NIC data structure * * Returns: void. */static void sis900_reset(struct nic *nic)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -