📄 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 *//* 07 Dec 2003 timlegge - Enabled Multicast Support 06 Dec 2003 timlegge - Fixed relocation issue in 5.2 04 Jan 2002 Chien-Yu Chen, Doug Ambrisko, Marty Connor Patch to Etherboot 5.0.5 Added support for the SiS 630ET plus various bug fixes from linux kernel source 2.4.17. 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 "timer.h"#include "sis900.h"/* Globals */static int sis900_debug = 0;static unsigned short vendor, dev_id;static unsigned long ioaddr;static u8 pci_revision;static unsigned int cur_phy;static unsigned int cur_rx;static BufferDesc txd;static BufferDesc rxd[NUM_RX_DESC];static unsigned char txb[TX_BUF_SIZE];static unsigned char rxb[NUM_RX_DESC * RX_BUF_SIZE];static 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 void vt6103_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}, {"VIA 6103 10/100Mbps Phyceiver", 0x0101, 0x8f20,vt6103_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_id pci_isa_bridge_list[] = { { 0x1039, 0x0008, "SIS 85C503/5513 PCI to ISA bridge"},};static struct pci_driver sis_bridge_driver __pci_driver = { .type = BRIDGE_DRIVER, .name = "", .probe = 0, .ids = pci_isa_bridge_list, .id_count = sizeof(pci_isa_bridge_list)/sizeof(pci_isa_bridge_list[0]), .class = 0,};/* Function Prototypes */static int sis900_probe(struct dev *dev, 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 dev *dev);/** * 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 __unused, 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;}/** * sis96x_get_mac_addr: - Get MAC address for SiS962 or SiS963 model * @pci_dev: the sis900 pci device * @net_dev: the net device to get address for * * SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM * is shared by * LAN and 1394. When access EEPROM, send EEREQ signal to hardware first * and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access * by LAN, otherwise is not. After MAC address is read from EEPROM, send * EEDONE signal to refuse EEPROM access by LAN. * The EEPROM map of SiS962 or SiS963 is different to SiS900. * The signature field in SiS962 or SiS963 spec is meaningless. * MAC address is read into @net_dev->dev_addr. */static int sis96x_get_mac_addr(struct pci_device * pci_dev, struct nic *nic){/* long ioaddr = net_dev->base_addr; */ long ee_addr = ioaddr + mear; u32 waittime = 0; int i; printf("Alternate function\n"); outl(EEREQ, ee_addr); while(waittime < 2000) { if(inl(ee_addr) & EEGNT) { /* get MAC address from EEPROM */ for (i = 0; i < 3; i++) ((u16 *)(nic->node_addr))[i] = sis900_read_eeprom(i+EEPROMMACAddr); outl(EEDONE, ee_addr); return 1; } else { udelay(1); waittime ++; } } outl(EEDONE, ee_addr); return 0;}/** * 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 __unused, struct nic *nic){ u8 reg; int i; struct pci_device p[1]; /* find PCI to ISA bridge */ memset(p, 0, sizeof(p)); do { find_pci(BRIDGE_DRIVER, p); } while(p->driver && p->driver != &sis_bridge_driver); /* error on failure */ if (!p->driver) return 0; 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;}/** * 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 sis635_get_mac_addr(struct pci_device * pci_dev __unused, struct nic *nic){ u32 rfcrSave; u32 i; rfcrSave = inl(rfcr + ioaddr); outl(rfcrSave | RELOAD, ioaddr + cr); outl(0, ioaddr + cr); /* disable packet filtering before setting filter */ outl(rfcrSave & ~RFEN, rfcr + ioaddr); /* load MAC addr to filter data register */ for (i = 0 ; i < 3 ; i++) { outl((i << RFADDR_shift), ioaddr + rfcr); *( ((u16 *)nic->node_addr) + i) = inw(ioaddr + rfdr); } /* enable packet filitering */ outl(rfcrSave | RFEN, rfcr + ioaddr); 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 */static int sis900_probe(struct dev *dev, struct pci_device *pci){ struct nic *nic = (struct nic *)dev; int i; int found=0; int phy_addr; u8 revision; int ret; if (pci->ioaddr == 0) return 0; ioaddr = pci->ioaddr & ~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); /* save for use later in sis900_reset() */ pci_revision = revision; if (revision == SIS630E_900_REV) ret = sis630e_get_mac_addr(pci, nic); else if ((revision > 0x81) && (revision <= 0x90)) ret = sis635_get_mac_addr(pci, nic); else if (revision == SIS96x_900_REV) ret = sis96x_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 0; } /* 630ET : set the mii access mode as software-mode */ if (revision == SIS630ET_900_REV) outl(ACCESSMODE | inl(ioaddr + cr), ioaddr + cr); 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 0; } /* 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); dev->disable = sis900_disable; nic->poll = sis900_poll;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -