⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 via-velocity.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * This code is derived from the VIA reference driver (copyright message * below) provided to Red Hat by VIA Networking Technologies, Inc. for * addition to the Linux kernel. * * The code has been merged into one source file, cleaned up to follow * Linux coding style,  ported to the Linux 2.6 kernel tree and cleaned * for 64bit hardware platforms. * * TODO *	Big-endian support *	rx_copybreak/alignment *	Scatter gather *	More testing * * The changes are (c) Copyright 2004, Red Hat Inc. <alan@redhat.com> * Additional fixes and clean up: Francois Romieu * * This source has not been verified for use in safety critical systems. * * Please direct queries about the revamped driver to the linux-kernel * list not VIA. * * Original code: * * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. * All rights reserved. * * This software may be redistributed and/or modified under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * Author: Chuang Liang-Shing, AJ Jiang * * Date: Jan 24, 2003 * * MODULE_LICENSE("GPL"); * */#include <linux/module.h>#include <linux/types.h>#include <linux/init.h>#include <linux/mm.h>#include <linux/errno.h>#include <linux/ioport.h>#include <linux/pci.h>#include <linux/kernel.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/delay.h>#include <linux/timer.h>#include <linux/slab.h>#include <linux/interrupt.h>#include <linux/string.h>#include <linux/wait.h>#include <asm/io.h>#include <linux/if.h>#include <asm/uaccess.h>#include <linux/proc_fs.h>#include <linux/inetdevice.h>#include <linux/reboot.h>#include <linux/ethtool.h>#include <linux/mii.h>#include <linux/in.h>#include <linux/if_arp.h>#include <linux/if_vlan.h>#include <linux/ip.h>#include <linux/tcp.h>#include <linux/udp.h>#include <linux/crc-ccitt.h>#include <linux/crc32.h>#include "via-velocity.h"static int velocity_nics = 0;static int msglevel = MSG_LEVEL_INFO;/** *	mac_get_cam_mask	-	Read a CAM mask *	@regs: register block for this velocity *	@mask: buffer to store mask * *	Fetch the mask bits of the selected CAM and store them into the *	provided mask buffer. */static void mac_get_cam_mask(struct mac_regs __iomem * regs, u8 * mask){	int i;	/* Select CAM mask */	BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);	writeb(0, &regs->CAMADDR);	/* read mask */	for (i = 0; i < 8; i++)		*mask++ = readb(&(regs->MARCAM[i]));	/* disable CAMEN */	writeb(0, &regs->CAMADDR);	/* Select mar */	BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);}/** *	mac_set_cam_mask	-	Set a CAM mask *	@regs: register block for this velocity *	@mask: CAM mask to load * *	Store a new mask into a CAM */static void mac_set_cam_mask(struct mac_regs __iomem * regs, u8 * mask){	int i;	/* Select CAM mask */	BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);	writeb(CAMADDR_CAMEN, &regs->CAMADDR);	for (i = 0; i < 8; i++) {		writeb(*mask++, &(regs->MARCAM[i]));	}	/* disable CAMEN */	writeb(0, &regs->CAMADDR);	/* Select mar */	BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);}static void mac_set_vlan_cam_mask(struct mac_regs __iomem * regs, u8 * mask){	int i;	/* Select CAM mask */	BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);	writeb(CAMADDR_CAMEN | CAMADDR_VCAMSL, &regs->CAMADDR);	for (i = 0; i < 8; i++) {		writeb(*mask++, &(regs->MARCAM[i]));	}	/* disable CAMEN */	writeb(0, &regs->CAMADDR);	/* Select mar */	BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);}/** *	mac_set_cam	-	set CAM data *	@regs: register block of this velocity *	@idx: Cam index *	@addr: 2 or 6 bytes of CAM data * *	Load an address or vlan tag into a CAM */static void mac_set_cam(struct mac_regs __iomem * regs, int idx, const u8 *addr){	int i;	/* Select CAM mask */	BYTE_REG_BITS_SET(CAMCR_PS_CAM_DATA, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);	idx &= (64 - 1);	writeb(CAMADDR_CAMEN | idx, &regs->CAMADDR);	for (i = 0; i < 6; i++) {		writeb(*addr++, &(regs->MARCAM[i]));	}	BYTE_REG_BITS_ON(CAMCR_CAMWR, &regs->CAMCR);	udelay(10);	writeb(0, &regs->CAMADDR);	/* Select mar */	BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);}static void mac_set_vlan_cam(struct mac_regs __iomem * regs, int idx,			     const u8 *addr){	/* Select CAM mask */	BYTE_REG_BITS_SET(CAMCR_PS_CAM_DATA, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);	idx &= (64 - 1);	writeb(CAMADDR_CAMEN | CAMADDR_VCAMSL | idx, &regs->CAMADDR);	writew(*((u16 *) addr), &regs->MARCAM[0]);	BYTE_REG_BITS_ON(CAMCR_CAMWR, &regs->CAMCR);	udelay(10);	writeb(0, &regs->CAMADDR);	/* Select mar */	BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, &regs->CAMCR);}/** *	mac_wol_reset	-	reset WOL after exiting low power *	@regs: register block of this velocity * *	Called after we drop out of wake on lan mode in order to *	reset the Wake on lan features. This function doesn't restore *	the rest of the logic from the result of sleep/wakeup */static void mac_wol_reset(struct mac_regs __iomem * regs){	/* Turn off SWPTAG right after leaving power mode */	BYTE_REG_BITS_OFF(STICKHW_SWPTAG, &regs->STICKHW);	/* clear sticky bits */	BYTE_REG_BITS_OFF((STICKHW_DS1 | STICKHW_DS0), &regs->STICKHW);	BYTE_REG_BITS_OFF(CHIPGCR_FCGMII, &regs->CHIPGCR);	BYTE_REG_BITS_OFF(CHIPGCR_FCMODE, &regs->CHIPGCR);	/* disable force PME-enable */	writeb(WOLCFG_PMEOVR, &regs->WOLCFGClr);	/* disable power-event config bit */	writew(0xFFFF, &regs->WOLCRClr);	/* clear power status */	writew(0xFFFF, &regs->WOLSRClr);}static int velocity_mii_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);static const struct ethtool_ops velocity_ethtool_ops;/*    Define module options*/MODULE_AUTHOR("VIA Networking Technologies, Inc.");MODULE_LICENSE("GPL");MODULE_DESCRIPTION("VIA Networking Velocity Family Gigabit Ethernet Adapter Driver");#define VELOCITY_PARAM(N,D) \        static int N[MAX_UNITS]=OPTION_DEFAULT;\	module_param_array(N, int, NULL, 0); \        MODULE_PARM_DESC(N, D);#define RX_DESC_MIN     64#define RX_DESC_MAX     255#define RX_DESC_DEF     64VELOCITY_PARAM(RxDescriptors, "Number of receive descriptors");#define TX_DESC_MIN     16#define TX_DESC_MAX     256#define TX_DESC_DEF     64VELOCITY_PARAM(TxDescriptors, "Number of transmit descriptors");#define RX_THRESH_MIN   0#define RX_THRESH_MAX   3#define RX_THRESH_DEF   0/* rx_thresh[] is used for controlling the receive fifo threshold.   0: indicate the rxfifo threshold is 128 bytes.   1: indicate the rxfifo threshold is 512 bytes.   2: indicate the rxfifo threshold is 1024 bytes.   3: indicate the rxfifo threshold is store & forward.*/VELOCITY_PARAM(rx_thresh, "Receive fifo threshold");#define DMA_LENGTH_MIN  0#define DMA_LENGTH_MAX  7#define DMA_LENGTH_DEF  0/* DMA_length[] is used for controlling the DMA length   0: 8 DWORDs   1: 16 DWORDs   2: 32 DWORDs   3: 64 DWORDs   4: 128 DWORDs   5: 256 DWORDs   6: SF(flush till emply)   7: SF(flush till emply)*/VELOCITY_PARAM(DMA_length, "DMA length");#define IP_ALIG_DEF     0/* IP_byte_align[] is used for IP header DWORD byte aligned   0: indicate the IP header won't be DWORD byte aligned.(Default) .   1: indicate the IP header will be DWORD byte aligned.      In some enviroment, the IP header should be DWORD byte aligned,      or the packet will be droped when we receive it. (eg: IPVS)*/VELOCITY_PARAM(IP_byte_align, "Enable IP header dword aligned");#define TX_CSUM_DEF     1/* txcsum_offload[] is used for setting the checksum offload ability of NIC.   (We only support RX checksum offload now)   0: disable csum_offload[checksum offload   1: enable checksum offload. (Default)*/VELOCITY_PARAM(txcsum_offload, "Enable transmit packet checksum offload");#define FLOW_CNTL_DEF   1#define FLOW_CNTL_MIN   1#define FLOW_CNTL_MAX   5/* flow_control[] is used for setting the flow control ability of NIC.   1: hardware deafult - AUTO (default). Use Hardware default value in ANAR.   2: enable TX flow control.   3: enable RX flow control.   4: enable RX/TX flow control.   5: disable*/VELOCITY_PARAM(flow_control, "Enable flow control ability");#define MED_LNK_DEF 0#define MED_LNK_MIN 0#define MED_LNK_MAX 4/* speed_duplex[] is used for setting the speed and duplex mode of NIC.   0: indicate autonegotiation for both speed and duplex mode   1: indicate 100Mbps half duplex mode   2: indicate 100Mbps full duplex mode   3: indicate 10Mbps half duplex mode   4: indicate 10Mbps full duplex mode   Note:        if EEPROM have been set to the force mode, this option is ignored            by driver.*/VELOCITY_PARAM(speed_duplex, "Setting the speed and duplex mode");#define VAL_PKT_LEN_DEF     0/* ValPktLen[] is used for setting the checksum offload ability of NIC.   0: Receive frame with invalid layer 2 length (Default)   1: Drop frame with invalid layer 2 length*/VELOCITY_PARAM(ValPktLen, "Receiving or Drop invalid 802.3 frame");#define WOL_OPT_DEF     0#define WOL_OPT_MIN     0#define WOL_OPT_MAX     7/* wol_opts[] is used for controlling wake on lan behavior.   0: Wake up if recevied a magic packet. (Default)   1: Wake up if link status is on/off.   2: Wake up if recevied an arp packet.   4: Wake up if recevied any unicast packet.   Those value can be sumed up to support more than one option.*/VELOCITY_PARAM(wol_opts, "Wake On Lan options");#define INT_WORKS_DEF   20#define INT_WORKS_MIN   10#define INT_WORKS_MAX   64VELOCITY_PARAM(int_works, "Number of packets per interrupt services");static int rx_copybreak = 200;module_param(rx_copybreak, int, 0644);MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");static void velocity_init_info(struct pci_dev *pdev, struct velocity_info *vptr,			       const struct velocity_info_tbl *info);static int velocity_get_pci_info(struct velocity_info *, struct pci_dev *pdev);static void velocity_print_info(struct velocity_info *vptr);static int velocity_open(struct net_device *dev);static int velocity_change_mtu(struct net_device *dev, int mtu);static int velocity_xmit(struct sk_buff *skb, struct net_device *dev);static int velocity_intr(int irq, void *dev_instance);static void velocity_set_multi(struct net_device *dev);static struct net_device_stats *velocity_get_stats(struct net_device *dev);static int velocity_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);static int velocity_close(struct net_device *dev);static int velocity_receive_frame(struct velocity_info *, int idx);static int velocity_alloc_rx_buf(struct velocity_info *, int idx);static void velocity_free_rd_ring(struct velocity_info *vptr);static void velocity_free_tx_buf(struct velocity_info *vptr, struct velocity_td_info *);static int velocity_soft_reset(struct velocity_info *vptr);static void mii_init(struct velocity_info *vptr, u32 mii_status);static u32 velocity_get_link(struct net_device *dev);static u32 velocity_get_opt_media_mode(struct velocity_info *vptr);static void velocity_print_link_status(struct velocity_info *vptr);static void safe_disable_mii_autopoll(struct mac_regs __iomem * regs);static void velocity_shutdown(struct velocity_info *vptr);static void enable_flow_control_ability(struct velocity_info *vptr);static void enable_mii_autopoll(struct mac_regs __iomem * regs);static int velocity_mii_read(struct mac_regs __iomem *, u8 byIdx, u16 * pdata);static int velocity_mii_write(struct mac_regs __iomem *, u8 byMiiAddr, u16 data);static u32 mii_check_media_mode(struct mac_regs __iomem * regs);static u32 check_connection_type(struct mac_regs __iomem * regs);static int velocity_set_media_mode(struct velocity_info *vptr, u32 mii_status);#ifdef CONFIG_PMstatic int velocity_suspend(struct pci_dev *pdev, pm_message_t state);static int velocity_resume(struct pci_dev *pdev);static DEFINE_SPINLOCK(velocity_dev_list_lock);static LIST_HEAD(velocity_dev_list);#endif#if defined(CONFIG_PM) && defined(CONFIG_INET)static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr);static struct notifier_block velocity_inetaddr_notifier = {      .notifier_call	= velocity_netdev_event,};static void velocity_register_notifier(void){	register_inetaddr_notifier(&velocity_inetaddr_notifier);}static void velocity_unregister_notifier(void){	unregister_inetaddr_notifier(&velocity_inetaddr_notifier);}#else#define velocity_register_notifier()	do {} while (0)#define velocity_unregister_notifier()	do {} while (0)#endif/* *	Internal board variants. At the moment we have only one */static const struct velocity_info_tbl chip_info_table[] __devinitdata = {	{CHIP_TYPE_VT6110, "VIA Networking Velocity Family Gigabit Ethernet Adapter", 1, 0x00FFFFFFUL},	{ }};/* *	Describe the PCI device identifiers that we support in this *	device driver. Used for hotplug autoloading. */static const struct pci_device_id velocity_id_table[] __devinitdata = {	{ PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_612X) },	{ }};MODULE_DEVICE_TABLE(pci, velocity_id_table);/** *	get_chip_name	- 	identifier to name *	@id: chip identifier * *	Given a chip identifier return a suitable description. Returns *	a pointer a static string valid while the driver is loaded. */static const char __devinit *get_chip_name(enum chip_type chip_id){	int i;	for (i = 0; chip_info_table[i].name != NULL; i++)		if (chip_info_table[i].chip_id == chip_id)			break;	return chip_info_table[i].name;}/** *	velocity_remove1	-	device unplug *	@pdev: PCI device being removed * *	Device unload callback. Called on an unplug or on module *	unload for each active device that is present. Disconnects *	the device from the network layer and frees all the resources */static void __devexit velocity_remove1(struct pci_dev *pdev){	struct net_device *dev = pci_get_drvdata(pdev);	struct velocity_info *vptr = netdev_priv(dev);#ifdef CONFIG_PM	unsigned long flags;	spin_lock_irqsave(&velocity_dev_list_lock, flags);	if (!list_empty(&velocity_dev_list))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -