/* sis900.c: A SiS 900/7016 PCI Fast Ethernet driver for Linux. Copyright 1999 Silicon Integrated System Corporation Revision: 1.08.10 Apr. 2 2006 Modified from the driver which is originally written by Donald Becker. This software may be used and distributed according to the terms of the GNU General Public License (GPL), incorporated herein by reference. Drivers based on this skeleton fall under the GPL and must retain the authorship (implicit copyright) notice. 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 Rev 1.08.10 Apr. 2 2006 Daniele Venzano add vlan (jumbo packets) support Rev 1.08.09 Sep. 19 2005 Daniele Venzano add Wake on LAN support Rev 1.08.08 Jan. 22 2005 Daniele Venzano use netif_msg for debugging messages Rev 1.08.07 Nov. 2 2003 Daniele Venzano <[email protected]> add suspend/resume support Rev 1.08.06 Sep. 24 2002 Mufasa Yang bug fix for Tx timeout & add SiS963 support Rev 1.08.05 Jun. 6 2002 Mufasa Yang bug fix for read_eeprom & Tx descriptor over-boundary Rev 1.08.04 Apr. 25 2002 Mufasa Yang <[email protected]> added SiS962 support Rev 1.08.03 Feb. 1 2002 Matt Domsch <[email protected]> update to use library crc32 function Rev 1.08.02 Nov. 30 2001 Hui-Fen Hsu workaround for EDB & bug fix for dhcp problem Rev 1.08.01 Aug. 25 2001 Hui-Fen Hsu update for 630ET & workaround for ICS1893 PHY Rev 1.08.00 Jun. 11 2001 Hui-Fen Hsu workaround for RTL8201 PHY and some bug fix Rev 1.07.11 Apr. 2 2001 Hui-Fen Hsu updates PCI drivers to use the new pci_set_dma_mask for kernel 2.4.3 Rev 1.07.10 Mar. 1 2001 Hui-Fen Hsu <[email protected]> some bug fix & 635M/B support Rev 1.07.09 Feb. 9 2001 Dave Jones <[email protected]> PCI enable cleanup Rev 1.07.08 Jan. 8 2001 Lei-Chun Chang added RTL8201 PHY support Rev 1.07.07 Nov. 29 2000 Lei-Chun Chang added kernel-doc extractable documentation and 630 workaround fix Rev 1.07.06 Nov. 7 2000 Jeff Garzik <[email protected]> some bug fix and cleaning Rev 1.07.05 Nov. 6 2000 metapirat<[email protected]> contribute media type select by ifconfig Rev 1.07.04 Sep. 6 2000 Lei-Chun Chang added ICS1893 PHY support Rev 1.07.03 Aug. 24 2000 Lei-Chun Chang ([email protected]) modified 630E equalizer workaround rule Rev 1.07.01 Aug. 08 2000 Ollie Lho minor update for SiS 630E and SiS 630E A1 Rev 1.07 Mar. 07 2000 Ollie Lho bug fix in Rx buffer ring Rev 1.06.04 Feb. 11 2000 Jeff Garzik <[email protected]> softnet and init for kernel 2.4 Rev 1.06.03 Dec. 23 1999 Ollie Lho Third release Rev 1.06.02 Nov. 23 1999 Ollie Lho bug in mac probing fixed Rev 1.06.01 Nov. 16 1999 Ollie Lho CRC calculation provide by Joseph Zbiciak ([email protected]) Rev 1.06 Nov. 4 1999 Ollie Lho ([email protected]) Second release Rev 1.05.05 Oct. 29 1999 Ollie Lho ([email protected]) Single buffer Tx/Rx Chin-Shan Li ([email protected]) Added AMD Am79c901 HomePNA PHY support Rev 1.05 Aug. 7 1999 Jim Huang ([email protected]) Initial release */ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/string.h> #include <linux/timer.h> #include <linux/errno.h> #include <linux/ioport.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/netdevice.h> #include <linux/init.h> #include <linux/mii.h> #include <linux/etherdevice.h> #include <linux/skbuff.h> #include <linux/delay.h> #include <linux/ethtool.h> #include <linux/crc32.h> #include <linux/bitops.h> #include <linux/dma-mapping.h> #include <asm/processor.h> /* Processor type for cache alignment. */ #include <asm/io.h> #include <asm/irq.h> #include <linux/uaccess.h> /* User space memory access functions */ #include "sis900.h" #define SIS900_MODULE_NAME … #define SIS900_DRV_VERSION … static const char version[] = …; static int max_interrupt_work = …; static int multicast_filter_limit = …; static int sis900_debug = …; /* Use SIS900_DEF_MSG as value */ #define SIS900_DEF_MSG … /* Time in jiffies before concluding the transmitter is hung. */ #define TX_TIMEOUT … enum { … }; static const char * card_names[] = …; static const struct pci_device_id sis900_pci_tbl[] = …; MODULE_DEVICE_TABLE (pci, sis900_pci_tbl); static void sis900_read_mode(struct net_device *net_dev, int *speed, int *duplex); static const struct mii_chip_info { … } mii_chip_table[] = …; struct mii_phy { … }; BufferDesc; struct sis900_private { … }; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; module_param(multicast_filter_limit, int, 0444); module_param(max_interrupt_work, int, 0444); module_param(sis900_debug, int, 0444); MODULE_PARM_DESC(…) …; MODULE_PARM_DESC(…) …; MODULE_PARM_DESC(…) …; #define sw32(reg, val) … #define sw8(reg, val) … #define sr32(reg) … #define sr16(reg) … #ifdef CONFIG_NET_POLL_CONTROLLER static void sis900_poll(struct net_device *dev); #endif static int sis900_open(struct net_device *net_dev); static int sis900_mii_probe (struct net_device * net_dev); static void sis900_init_rxfilter (struct net_device * net_dev); static u16 read_eeprom(void __iomem *ioaddr, int location); static int mdio_read(struct net_device *net_dev, int phy_id, int location); static void mdio_write(struct net_device *net_dev, int phy_id, int location, int val); static void sis900_timer(struct timer_list *t); static void sis900_check_mode (struct net_device *net_dev, struct mii_phy *mii_phy); static void sis900_tx_timeout(struct net_device *net_dev, unsigned int txqueue); static void sis900_init_tx_ring(struct net_device *net_dev); static void sis900_init_rx_ring(struct net_device *net_dev); static netdev_tx_t sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev); static int sis900_rx(struct net_device *net_dev); static void sis900_finish_xmit (struct net_device *net_dev); static irqreturn_t sis900_interrupt(int irq, void *dev_instance); static int sis900_close(struct net_device *net_dev); static int mii_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd); static u16 sis900_mcast_bitnr(u8 *addr, u8 revision); static void set_rx_mode(struct net_device *net_dev); static void sis900_reset(struct net_device *net_dev); static void sis630_set_eq(struct net_device *net_dev, u8 revision); static int sis900_set_config(struct net_device *dev, struct ifmap *map); static u16 sis900_default_phy(struct net_device * net_dev); static void sis900_set_capability( struct net_device *net_dev ,struct mii_phy *phy); static u16 sis900_reset_phy(struct net_device *net_dev, int phy_addr); static void sis900_auto_negotiate(struct net_device *net_dev, int phy_addr); static void sis900_set_mode(struct sis900_private *, int speed, int duplex); static const struct ethtool_ops sis900_ethtool_ops; /** * 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_dev *pci_dev, struct net_device *net_dev) { … } /** * 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_dev *pci_dev, struct net_device *net_dev) { … } /** * sis635_get_mac_addr - Get MAC address for SIS635 model * @pci_dev: the sis900 pci device * @net_dev: the net device to get address for * * SiS635 model, set MAC Reload Bit to load Mac address from APC * to rfdr. rfdr is accessed through rfcr. MAC address is read into * @net_dev->dev_addr. */ static int sis635_get_mac_addr(struct pci_dev *pci_dev, struct net_device *net_dev) { … } /** * 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 accessing EEPROM, send EEREQ signal to hardware first * and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be accessed * by LAN, otherwise it 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_dev *pci_dev, struct net_device *net_dev) { … } static const struct net_device_ops sis900_netdev_ops = …; /** * sis900_probe - Probe for sis900 device * @pci_dev: the sis900 pci device * @pci_id: the pci device ID * * Check and probe sis900 net device for @pci_dev. * Get mac address according to the chip revision, * and assign SiS900-specific entries in the device structure. * ie: sis900_open(), sis900_start_xmit(), sis900_close(), etc. */ static int sis900_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id) { … } /** * sis900_mii_probe - Probe MII PHY for sis900 * @net_dev: the net device to probe for * * Search for total of 32 possible mii phy addresses. * Identify and set current phy if found one, * return error if it failed to found. */ static int sis900_mii_probe(struct net_device *net_dev) { … } /** * sis900_default_phy - Select default PHY for sis900 mac. * @net_dev: the net device to probe for * * Select first detected PHY with link as default. * If no one is link on, select PHY whose types is HOME as default. * If HOME doesn't exist, select LAN. */ static u16 sis900_default_phy(struct net_device * net_dev) { … } /** * sis900_set_capability - set the media capability of network adapter. * @net_dev : the net device to probe for * @phy : default PHY * * Set the media capability of network adapter according to * mii status register. It's necessary before auto-negotiate. */ static void sis900_set_capability(struct net_device *net_dev, struct mii_phy *phy) { … } /* Delay between EEPROM clock transitions. */ #define eeprom_delay() … /** * read_eeprom - Read Serial EEPROM * @ioaddr: base i/o address * @location: the EEPROM location to read * * Read Serial EEPROM through EEPROM Access Register. * Note that location is in word (16 bits) unit */ static u16 read_eeprom(void __iomem *ioaddr, int location) { … } /* Read and write the MII management registers using software-generated serial MDIO protocol. Note that the command bits and data bits are send out separately */ #define mdio_delay() … static void mdio_idle(struct sis900_private *sp) { … } /* Synchronize the MII management interface by shifting 32 one bits out. */ static void mdio_reset(struct sis900_private *sp) { … } /** * mdio_read - read MII PHY register * @net_dev: the net device to read * @phy_id: the phy address to read * @location: the phy register id to read * * Read MII registers through MDIO and MDC * using MDIO management frame structure and protocol(defined by ISO/IEC). * Please see SiS7014 or ICS spec */ static int mdio_read(struct net_device *net_dev, int phy_id, int location) { … } /** * mdio_write - write MII PHY register * @net_dev: the net device to write * @phy_id: the phy address to write * @location: the phy register id to write * @value: the register value to write with * * Write MII registers with @value through MDIO and MDC * using MDIO management frame structure and protocol(defined by ISO/IEC) * please see SiS7014 or ICS spec */ static void mdio_write(struct net_device *net_dev, int phy_id, int location, int value) { … } /** * sis900_reset_phy - reset sis900 mii phy. * @net_dev: the net device to write * @phy_addr: default phy address * * Some specific phy can't work properly without reset. * This function will be called during initialization and * link status change from ON to DOWN. */ static u16 sis900_reset_phy(struct net_device *net_dev, int phy_addr) { … } #ifdef CONFIG_NET_POLL_CONTROLLER /* * Polling 'interrupt' - used by things like netconsole to send skbs * without having to re-enable interrupts. It's not called while * the interrupt routine is executing. */ static void sis900_poll(struct net_device *dev) { … } #endif /** * sis900_open - open sis900 device * @net_dev: the net device to open * * Do some initialization and start net interface. * enable interrupts and set sis900 timer. */ static int sis900_open(struct net_device *net_dev) { … } /** * sis900_init_rxfilter - Initialize the Rx filter * @net_dev: the net device to initialize for * * Set receive filter address to our MAC address * and enable packet filtering. */ static void sis900_init_rxfilter (struct net_device * net_dev) { … } /** * sis900_init_tx_ring - Initialize the Tx descriptor ring * @net_dev: the net device to initialize for * * Initialize the Tx descriptor ring, */ static void sis900_init_tx_ring(struct net_device *net_dev) { … } /** * sis900_init_rx_ring - Initialize the Rx descriptor ring * @net_dev: the net device to initialize for * * Initialize the Rx descriptor ring, * and pre-allocate receive buffers (socket buffer) */ static void sis900_init_rx_ring(struct net_device *net_dev) { … } /** * sis630_set_eq - set phy equalizer value for 630 LAN * @net_dev: the net device to set equalizer value * @revision: 630 LAN revision number * * 630E equalizer workaround rule(Cyrus Huang 08/15) * PHY register 14h(Test) * Bit 14: 0 -- Automatically detect (default) * 1 -- Manually set Equalizer filter * Bit 13: 0 -- (Default) * 1 -- Speed up convergence of equalizer setting * Bit 9 : 0 -- (Default) * 1 -- Disable Baseline Wander * Bit 3~7 -- Equalizer filter setting * Link ON: Set Bit 9, 13 to 1, Bit 14 to 0 * Then calculate equalizer value * Then set equalizer value, and set Bit 14 to 1, Bit 9 to 0 * Link Off:Set Bit 13 to 1, Bit 14 to 0 * Calculate Equalizer value: * When Link is ON and Bit 14 is 0, SIS900PHY will auto-detect proper equalizer value. * When the equalizer is stable, this value is not a fixed value. It will be within * a small range(eg. 7~9). Then we get a minimum and a maximum value(eg. min=7, max=9) * 0 <= max <= 4 --> set equalizer to max * 5 <= max <= 14 --> set equalizer to max+1 or set equalizer to max+2 if max == min * max >= 15 --> set equalizer to max+5 or set equalizer to max+6 if max == min */ static void sis630_set_eq(struct net_device *net_dev, u8 revision) { … } /** * sis900_timer - sis900 timer routine * @t: timer list containing a pointer to sis900 net device * * On each timer ticks we check two things, * link status (ON/OFF) and link mode (10/100/Full/Half) */ static void sis900_timer(struct timer_list *t) { … } /** * sis900_check_mode - check the media mode for sis900 * @net_dev: the net device to be checked * @mii_phy: the mii phy * * Older driver gets the media mode from mii status output * register. Now we set our media capability and auto-negotiate * to get the upper bound of speed and duplex between two ends. * If the types of mii phy is HOME, it doesn't need to auto-negotiate * and autong_complete should be set to 1. */ static void sis900_check_mode(struct net_device *net_dev, struct mii_phy *mii_phy) { … } /** * sis900_set_mode - Set the media mode of mac register. * @sp: the device private data * @speed : the transmit speed to be determined * @duplex: the duplex mode to be determined * * Set the media mode of mac register txcfg/rxcfg according to * speed and duplex of phy. Bit EDB_MASTER_EN indicates the EDB * bus is used instead of PCI bus. When this bit is set 1, the * Max DMA Burst Size for TX/RX DMA should be no larger than 16 * double words. */ static void sis900_set_mode(struct sis900_private *sp, int speed, int duplex) { … } /** * sis900_auto_negotiate - Set the Auto-Negotiation Enable/Reset bit. * @net_dev: the net device to read mode for * @phy_addr: mii phy address * * If the adapter is link-on, set the auto-negotiate enable/reset bit. * autong_complete should be set to 0 when starting auto-negotiation. * autong_complete should be set to 1 if we didn't start auto-negotiation. * sis900_timer will wait for link on again if autong_complete = 0. */ static void sis900_auto_negotiate(struct net_device *net_dev, int phy_addr) { … } /** * sis900_read_mode - read media mode for sis900 internal phy * @net_dev: the net device to read mode for * @speed : the transmit speed to be determined * @duplex : the duplex mode to be determined * * The capability of remote end will be put in mii register autorec * after auto-negotiation. Use AND operation to get the upper bound * of speed and duplex between two ends. */ static void sis900_read_mode(struct net_device *net_dev, int *speed, int *duplex) { … } /** * sis900_tx_timeout - sis900 transmit timeout routine * @net_dev: the net device to transmit * @txqueue: index of hanging queue * * print transmit timeout status * disable interrupts and do some tasks */ static void sis900_tx_timeout(struct net_device *net_dev, unsigned int txqueue) { … } /** * sis900_start_xmit - sis900 start transmit routine * @skb: socket buffer pointer to put the data being transmitted * @net_dev: the net device to transmit with * * Set the transmit buffer descriptor, * and write TxENA to enable transmit state machine. * tell upper layer if the buffer is full */ static netdev_tx_t sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev) { … } /** * sis900_interrupt - sis900 interrupt handler * @irq: the irq number * @dev_instance: the client data object * * The interrupt handler does all of the Rx thread work, * and cleans up after the Tx thread */ static irqreturn_t sis900_interrupt(int irq, void *dev_instance) { … } /** * sis900_rx - sis900 receive routine * @net_dev: the net device which receives data * * Process receive interrupt events, * put buffer to higher layer and refill buffer pool * Note: This function is called by interrupt handler, * don't do "too much" work here */ static int sis900_rx(struct net_device *net_dev) { … } /** * sis900_finish_xmit - finish up transmission of packets * @net_dev: the net device to be transmitted on * * Check for error condition and free socket buffer etc * schedule for more transmission as needed * Note: This function is called by interrupt handler, * don't do "too much" work here */ static void sis900_finish_xmit (struct net_device *net_dev) { … } /** * sis900_close - close sis900 device * @net_dev: the net device to be closed * * Disable interrupts, stop the Tx and Rx Status Machine * free Tx and RX socket buffer */ static int sis900_close(struct net_device *net_dev) { … } /** * sis900_get_drvinfo - Return information about driver * @net_dev: the net device to probe * @info: container for info returned * * Process ethtool command such as "ehtool -i" to show information */ static void sis900_get_drvinfo(struct net_device *net_dev, struct ethtool_drvinfo *info) { … } static u32 sis900_get_msglevel(struct net_device *net_dev) { … } static void sis900_set_msglevel(struct net_device *net_dev, u32 value) { … } static u32 sis900_get_link(struct net_device *net_dev) { … } static int sis900_get_link_ksettings(struct net_device *net_dev, struct ethtool_link_ksettings *cmd) { … } static int sis900_set_link_ksettings(struct net_device *net_dev, const struct ethtool_link_ksettings *cmd) { … } static int sis900_nway_reset(struct net_device *net_dev) { … } /** * sis900_set_wol - Set up Wake on Lan registers * @net_dev: the net device to probe * @wol: container for info passed to the driver * * Process ethtool command "wol" to setup wake on lan features. * SiS900 supports sending WoL events if a correct packet is received, * but there is no simple way to filter them to only a subset (broadcast, * multicast, unicast or arp). */ static int sis900_set_wol(struct net_device *net_dev, struct ethtool_wolinfo *wol) { … } static void sis900_get_wol(struct net_device *net_dev, struct ethtool_wolinfo *wol) { … } static int sis900_get_eeprom_len(struct net_device *dev) { … } static int sis900_read_eeprom(struct net_device *net_dev, u8 *buf) { … } #define SIS900_EEPROM_MAGIC … static int sis900_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) { … } static const struct ethtool_ops sis900_ethtool_ops = …; /** * mii_ioctl - process MII i/o control command * @net_dev: the net device to command for * @rq: parameter for command * @cmd: the i/o command * * Process MII command like read/write MII register */ static int mii_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd) { … } /** * sis900_set_config - Set media type by net_device.set_config * @dev: the net device for media type change * @map: ifmap passed by ifconfig * * Set media type to 10baseT, 100baseT or 0(for auto) by ifconfig * we support only port changes. All other runtime configuration * changes will be ignored */ static int sis900_set_config(struct net_device *dev, struct ifmap *map) { … } /** * sis900_mcast_bitnr - compute hashtable index * @addr: multicast address * @revision: revision id of chip * * SiS 900 uses the most sigificant 7 bits to index a 128 bits multicast * hash table, which makes this function a little bit different from other drivers * SiS 900 B0 & 635 M/B uses the most significat 8 bits to index 256 bits * multicast hash table. */ static inline u16 sis900_mcast_bitnr(u8 *addr, u8 revision) { … } /** * set_rx_mode - Set SiS900 receive mode * @net_dev: the net device to be set * * Set SiS900 receive mode for promiscuous, multicast, or broadcast mode. * And set the appropriate multicast filter. * Multicast hash table changes from 128 to 256 bits for 635M/B & 900B0. */ static void set_rx_mode(struct net_device *net_dev) { … } /** * sis900_reset - Reset sis900 MAC * @net_dev: the net device to reset * * reset sis900 MAC and wait until finished * reset through command register * change backoff algorithm for 900B0 & 635 M/B */ static void sis900_reset(struct net_device *net_dev) { … } /** * sis900_remove - Remove sis900 device * @pci_dev: the pci device to be removed * * remove and release SiS900 net device */ static void sis900_remove(struct pci_dev *pci_dev) { … } static int __maybe_unused sis900_suspend(struct device *dev) { … } static int __maybe_unused sis900_resume(struct device *dev) { … } static SIMPLE_DEV_PM_OPS(sis900_pm_ops, sis900_suspend, sis900_resume); static struct pci_driver sis900_pci_driver = …; static int __init sis900_init_module(void) { … } static void __exit sis900_cleanup_module(void) { … } module_init(…) …; module_exit(sis900_cleanup_module);