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

📄 via-velocity.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 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/config.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/version.h>#include <linux/string.h>#include <linux/wait.h>#include <asm/io.h>#include <linux/if.h>#include <linux/config.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/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;static int velocity_mii_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);static 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 const int N[MAX_UNITS]=OPTION_DEFAULT;\        MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UNITS) "i");\        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 VLAN_ID_MIN     0#define VLAN_ID_MAX     4095#define VLAN_ID_DEF     0/* VID_setting[] is used for setting the VID of NIC.   0: default VID.   1-4094: other VIDs.*/VELOCITY_PARAM(VID_setting, "802.1Q VLAN ID");#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 TAGGING_DEF     0/* enable_tagging[] is used for enabling 802.1Q VID tagging.   0: disable VID seeting(default).   1: enable VID setting.*/VELOCITY_PARAM(enable_tagging, "Enable 802.1Q tagging");#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_PARM(rx_copybreak, "i");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, 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, struct pt_regs *regs);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_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 * 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 * regs);static int velocity_mii_read(struct mac_regs *, u8 byIdx, u16 * pdata);static int velocity_mii_write(struct mac_regs *, u8 byMiiAddr, u16 data);static u32 mii_check_media_mode(struct mac_regs * regs);static u32 check_connection_type(struct mac_regs * regs);static int velocity_set_media_mode(struct velocity_info *vptr, u32 mii_status);#ifdef CONFIG_PMstatic int velocity_suspend(struct pci_dev *pdev, u32 state);static int velocity_resume(struct pci_dev *pdev);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 spinlock_t velocity_dev_list_lock = SPIN_LOCK_UNLOCKED;static LIST_HEAD(velocity_dev_list);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				/* CONFIG_PM */#define velocity_register_notifier()	do {} while (0)#define velocity_unregister_notifier()	do {} while (0)#endif				/* !CONFIG_PM *//* *	Internal board variants. At the moment we have only one */static struct velocity_info_tbl chip_info_table[] = {	{CHIP_TYPE_VT6110, "VIA Networking Velocity Family Gigabit Ethernet Adapter", 256, 1, 0x00FFFFFFUL},	{0, NULL}};/* *	Describe the PCI device identifiers that we support in this *	device driver. Used for hotplug autoloading. */static struct pci_device_id velocity_id_table[] __devinitdata = {	{PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_612X,	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long) chip_info_table},	{0, }};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 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 = dev->priv;#ifdef CONFIG_PM	unsigned long flags;	spin_lock_irqsave(&velocity_dev_list_lock, flags);	if (!list_empty(&velocity_dev_list))		list_del(&vptr->list);	spin_unlock_irqrestore(&velocity_dev_list_lock, flags);#endif	unregister_netdev(dev);	iounmap(vptr->mac_regs);	pci_release_regions(pdev);	pci_disable_device(pdev);	pci_set_drvdata(pdev, NULL);	free_netdev(dev);	velocity_nics--;}/** *	velocity_set_int_opt	-	parser for integer options *	@opt: pointer to option value *	@val: value the user requested (or -1 for default) *	@min: lowest value allowed *	@max: highest value allowed *	@def: default value *	@name: property name *	@dev: device name * *	Set an integer property in the module options. This function does *	all the verification and checking as well as reporting so that *	we don't duplicate code for each option. */static void __devinit velocity_set_int_opt(int *opt, int val, int min, int max, int def, char *name, char *devname){	if (val == -1)		*opt = def;	else if (val < min || val > max) {		VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n",					devname, name, min, max);		*opt = def;	} else {		VELOCITY_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",					devname, name, val);		*opt = val;	}}/** *	velocity_set_bool_opt	-	parser for boolean options *	@opt: pointer to option value *	@val: value the user requested (or -1 for default) *	@def: default value (yes/no) *	@flag: numeric value to set for true. *	@name: property name *	@dev: device name * *	Set a boolean property in the module options. This function does *	all the verification and checking as well as reporting so that *	we don't duplicate code for each option. */static void __devinit velocity_set_bool_opt(u32 * opt, int val, int def, u32 flag, char *name, char *devname){	(*opt) &= (~flag);	if (val == -1)		*opt |= (def ? flag : 0);	else if (val < 0 || val > 1) {		printk(KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (0-1)\n", 			devname, name);		*opt |= (def ? flag : 0);	} else {		printk(KERN_INFO "%s: set parameter %s to %s\n", 			devname, name, val ? "TRUE" : "FALSE");		*opt |= (val ? flag : 0);	}}/** *	velocity_get_options	-	set options on device *	@opts: option structure for the device *	@index: index of option to use in module options array *	@devname: device name * *	Turn the module and command options into a single structure *	for the current device */static void __devinit velocity_get_options(struct velocity_opt *opts, int index, char *devname){	velocity_set_int_opt(&opts->rx_thresh, rx_thresh[index], RX_THRESH_MIN, RX_THRESH_MAX, RX_THRESH_DEF, "rx_thresh", devname);	velocity_set_int_opt(&opts->DMA_length, DMA_length[index], DMA_LENGTH_MIN, DMA_LENGTH_MAX, DMA_LENGTH_DEF, "DMA_length", devname);	velocity_set_int_opt(&opts->numrx, RxDescriptors[index], RX_DESC_MIN, RX_DESC_MAX, RX_DESC_DEF, "RxDescriptors", devname);	velocity_set_int_opt(&opts->numtx, TxDescriptors[index], TX_DESC_MIN, TX_DESC_MAX, TX_DESC_DEF, "TxDescriptors", devname);	velocity_set_int_opt(&opts->vid, VID_setting[index], VLAN_ID_MIN, VLAN_ID_MAX, VLAN_ID_DEF, "VID_setting", devname);	velocity_set_bool_opt(&opts->flags, enable_tagging[index], TAGGING_DEF, VELOCITY_FLAGS_TAGGING, "enable_tagging", devname);	velocity_set_bool_opt(&opts->flags, txcsum_offload[index], TX_CSUM_DEF, VELOCITY_FLAGS_TX_CSUM, "txcsum_offload", devname);	velocity_set_int_opt(&opts->flow_cntl, flow_control[index], FLOW_CNTL_MIN, FLOW_CNTL_MAX, FLOW_CNTL_DEF, "flow_control", devname);	velocity_set_bool_opt(&opts->flags, IP_byte_align[index], IP_ALIG_DEF, VELOCITY_FLAGS_IP_ALIGN, "IP_byte_align", devname);	velocity_set_bool_opt(&opts->flags, ValPktLen[index], VAL_PKT_LEN_DEF, VELOCITY_FLAGS_VAL_PKT_LEN, "ValPktLen", devname);	velocity_set_int_opt((int *) &opts->spd_dpx, speed_duplex[index], MED_LNK_MIN, MED_LNK_MAX, MED_LNK_DEF, "Media link mode", devname);	velocity_set_int_opt((int *) &opts->wol_opts, wol_opts[index], WOL_OPT_MIN, WOL_OPT_MAX, WOL_OPT_DEF, "Wake On Lan options", devname);	velocity_set_int_opt((int *) &opts->int_works, int_works[index], INT_WORKS_MIN, INT_WORKS_MAX, INT_WORKS_DEF, "Interrupt service works", devname);	opts->numrx = (opts->numrx & ~3);}/** *	velocity_init_cam_filter	-	initialise CAM *	@vptr: velocity to program * *	Initialize the content addressable memory used for filters. Load *	appropriately according to the presence of VLAN */static void velocity_init_cam_filter(struct velocity_info *vptr){	struct mac_regs * regs = vptr->mac_regs;	/* Turn on MCFG_PQEN, turn off MCFG_RTGOPT */	WORD_REG_BITS_SET(MCFG_PQEN, MCFG_RTGOPT, &regs->MCFG);	WORD_REG_BITS_ON(MCFG_VIDFR, &regs->MCFG);	/* Disable all CAMs */	memset(vptr->vCAMmask, 0, sizeof(u8) * 8);	memset(vptr->mCAMmask, 0, sizeof(u8) * 8);	mac_set_cam_mask(regs, vptr->vCAMmask, VELOCITY_VLAN_ID_CAM);	mac_set_cam_mask(regs, vptr->mCAMmask, VELOCITY_MULTICAST_CAM);	/* Enable first VCAM */	if (vptr->flags & VELOCITY_FLAGS_TAGGING) {		/* If Tagging option is enabled and VLAN ID is not zero, then		   turn on MCFG_RTGOPT also */		if (vptr->options.vid != 0)			WORD_REG_BITS_ON(MCFG_RTGOPT, &regs->MCFG);		mac_set_cam(regs, 0, (u8 *) & (vptr->options.vid), VELOCITY_VLAN_ID_CAM);		vptr->vCAMmask[0] |= 1;		mac_set_cam_mask(regs, vptr->vCAMmask, VELOCITY_VLAN_ID_CAM);	} else {		u16 temp = 0;		mac_set_cam(regs, 0, (u8 *) &temp, VELOCITY_VLAN_ID_CAM);		temp = 1;		mac_set_cam_mask(regs, (u8 *) &temp, VELOCITY_VLAN_ID_CAM);	}}

⌨️ 快捷键说明

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