e100_proc.c

来自「是关于linux2.5.1的完全源码」· C语言 代码 · 共 926 行 · 第 1/2 页

C
926
字号
/*******************************************************************************This software program is available to you under a choice of one of two licenses. You may choose to be licensed under either the GNU General Public License 2.0, June 1991, available at http://www.fsf.org/copyleft/gpl.html, or the Intel BSD + Patent License, the text of which follows:Recipient has requested a license and Intel Corporation ("Intel") is willingto grant a license for the software entitled Linux Base Driver for the Intel(R) PRO/100 Family of Adapters (e100) (the "Software") being provided by Intel Corporation. The following definitions apply to this license:"Licensed Patents" means patent claims licensable by Intel Corporation which are necessarily infringed by the use of sale of the Software alone or when combined with the operating system referred to below."Recipient" means the party to whom Intel delivers this Software."Licensee" means Recipient and those third parties that receive a license to any operating system available under the GNU General Public License 2.0 or later.Copyright (c) 1999 - 2002 Intel Corporation.All rights reserved.The license is provided to Recipient and Recipient's Licensees under the following terms.Redistribution and use in source and binary forms of the Software, with or without modification, are permitted provided that the following conditions are met:Redistributions of source code of the Software may retain the above copyright notice, this list of conditions and the following disclaimer.Redistributions in binary form of the Software may reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or materials provided with the distribution.Neither the name of Intel Corporation nor the names of its contributors shall be used to endorse or promote products derived from this Software without specific prior written permission.Intel hereby grants Recipient and Licensees a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Software, if any, in source code and object code form. This license shall include changes to the Software that are error corrections or other minor changes to the Software that do not add functionality or features when the Software is incorporated in any version of an operating system that has been distributed under the GNU General Public License 2.0 or later. This patent license shall apply to the combination of the Software and any operating system licensed under the GNU General Public License 2.0 or later if, at the time Intel provides the Software to Recipient, such addition of the Software to the then publicly available versions of such operating systems available under the GNU General Public License 2.0 or later (whether in gold, beta or alpha form) causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Software. NO hardware per se is licensed hereunder.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MECHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR IT CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ANY LOSS OF USE; DATA, OR PROFITS; OR BUSINESS INTERUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*******************************************************************************//***********************************************************************                                                                       ** INTEL CORPORATION                                                     **                                                                       ** This software is supplied under the terms of the license included     ** above.  All use of this driver must be in accordance with the terms   ** of that license.                                                      **                                                                       ** Module Name:  e100_proc.c                                             **                                                                       ** Abstract:     Functions to handle the proc file system.               **               Create the proc directories and files and run read and  **               write requests from the user                            **                                                                       ** Environment:  This file is intended to be specific to the Linux       **               operating system.                                       **                                                                       ***********************************************************************/#include <linux/config.h>#ifndef CONFIG_PROC_FS#undef E100_CONFIG_PROC_FS#endif#ifdef E100_CONFIG_PROC_FS#include "e100.h"/* MDI sleep time is at least 50 ms, in jiffies */#define MDI_SLEEP_TIME ((HZ / 20) + 1)/***************************************************************************//*       /proc File System Interaface Support Functions                    *//***************************************************************************/static struct proc_dir_entry *adapters_proc_dir = 0;/* externs from e100_main.c */extern const char *e100_short_driver_name;extern const char *e100_version;extern struct net_device_stats *e100_get_stats(struct net_device *dev);extern char *e100_get_brand_msg(struct e100_private *bdp);extern void e100_mdi_write(struct e100_private *, u32, u32, u16);static void e100_proc_cleanup(void);static unsigned char e100_init_proc_dir(void);#define E100_EOU#define ADAPTERS_PROC_DIR "PRO_LAN_Adapters"#define WRITE_BUF_MAX_LEN 20	#define READ_BUF_MAX_LEN  256#define E100_PE_LEN       25#define bdp_drv_off(off) (unsigned long)(offsetof(struct e100_private, drv_stats.off))#define bdp_prm_off(off) (unsigned long)(offsetof(struct e100_private, params.off))typedef struct _e100_proc_entry {	char *name;	read_proc_t *read_proc;	write_proc_t *write_proc;	unsigned long offset;	/* offset into bdp. ~0 means no value, pass NULL. */} e100_proc_entry;static intgeneric_read(char *page, char **start, off_t off, int count, int *eof, int len){	if (len <= off + count)		*eof = 1;	*start = page + off;	len -= off;	if (len > count)		len = count;	if (len < 0)		len = 0;	return len;}static intread_ulong(char *page, char **start, off_t off,	   int count, int *eof, unsigned long l){	int len;	len = sprintf(page, "%lu\n", l);	return generic_read(page, start, off, count, eof, len);}static intread_gen_ulong(char *page, char **start, off_t off,	       int count, int *eof, void *data){	unsigned long val = 0;	if (data)		val = *((unsigned long *) data);	return read_ulong(page, start, off, count, eof, val);}static intread_hwaddr(char *page, char **start, off_t off,	    int count, int *eof, unsigned char *hwaddr){	int len;	len = sprintf(page, "%02X:%02X:%02X:%02X:%02X:%02X\n",		      hwaddr[0], hwaddr[1], hwaddr[2],		      hwaddr[3], hwaddr[4], hwaddr[5]);	return generic_read(page, start, off, count, eof, len);}static intread_descr(char *page, char **start, off_t off, int count, int *eof, void *data){	struct e100_private *bdp = data;	int len;	len = sprintf(page, "%s\n", e100_get_brand_msg(bdp));	return generic_read(page, start, off, count, eof, len);}static intread_permanent_hwaddr(char *page, char **start, off_t off,		      int count, int *eof, void *data){	struct e100_private *bdp = data;	unsigned char *hwaddr = bdp->perm_node_address;	return read_hwaddr(page, start, off, count, eof, hwaddr);}static intread_part_number(char *page, char **start, off_t off,		 int count, int *eof, void *data){	struct e100_private *bdp = data;	int len;	len = sprintf(page, "%06lx-%03x\n",		      (unsigned long) (bdp->pwa_no >> 8),		      (unsigned int) (bdp->pwa_no & 0xFF));	return generic_read(page, start, off, count, eof, len);}static voidset_led(struct e100_private *bdp, u16 led_mdi_op){	spin_lock_bh(&bdp->mdi_access_lock);	e100_mdi_write(bdp, PHY_82555_LED_SWITCH_CONTROL,		       bdp->phy_addr, led_mdi_op);	spin_unlock_bh(&bdp->mdi_access_lock);	set_current_state(TASK_UNINTERRUPTIBLE);	schedule_timeout(MDI_SLEEP_TIME);	spin_lock_bh(&bdp->mdi_access_lock);	/* turn led ownership to the chip */	e100_mdi_write(bdp, PHY_82555_LED_SWITCH_CONTROL,		       bdp->phy_addr, PHY_82555_LED_NORMAL_CONTROL);	spin_unlock_bh(&bdp->mdi_access_lock);}static intwrite_blink_led_timer(struct file *file, const char *buffer,		      unsigned long count, void *data){	struct e100_private *bdp = data;	char s_blink_op[WRITE_BUF_MAX_LEN + 1];	char *res;	unsigned long i_blink_op;	if (!buffer)		return -EINVAL;	if (count > WRITE_BUF_MAX_LEN) {		count = WRITE_BUF_MAX_LEN;	}	copy_from_user(s_blink_op, buffer, count);	s_blink_op[count] = '\0';	i_blink_op = simple_strtoul(s_blink_op, &res, 0);	if (res == s_blink_op) {		return -EINVAL;	}	switch (i_blink_op) {	case LED_OFF:		set_led(bdp, PHY_82555_LED_OFF);		break;	case LED_ON:		if (bdp->rev_id >= D101MA_REV_ID)			set_led(bdp, PHY_82555_LED_ON_559);		else			set_led(bdp, PHY_82555_LED_ON_PRE_559);		break;	default:		return -EINVAL;	}	return count;}static e100_proc_entry e100_proc_list[] = {	{"Description",           read_descr,            0, 0},	{"Permanent_HWaddr",      read_permanent_hwaddr, 0, 0},	{"Part_Number",           read_part_number,      0, 0},	{"\n",},	{"Rx_TCP_Checksum_Good",  read_gen_ulong, 0, ~0},	{"Rx_TCP_Checksum_Bad",   read_gen_ulong, 0, ~0},	{"Tx_TCP_Checksum_Good",  read_gen_ulong, 0, ~0},	{"Tx_TCP_Checksum_Bad",   read_gen_ulong, 0, ~0},	{"\n",},	{"Tx_Abort_Late_Coll",    read_gen_ulong, 0, bdp_drv_off(tx_late_col)},	{"Tx_Deferred_Ok",        read_gen_ulong, 0, bdp_drv_off(tx_ok_defrd)},	{"Tx_Single_Coll_Ok",     read_gen_ulong, 0, bdp_drv_off(tx_one_retry)},	{"Tx_Multi_Coll_Ok",      read_gen_ulong, 0, bdp_drv_off(tx_mt_one_retry)},	{"Rx_Long_Length_Errors", read_gen_ulong, 0, ~0},	{"\n",},	{"Tx_Flow_Control_Pause", read_gen_ulong, 0, bdp_drv_off(xmt_fc_pkts)},	{"Rx_Flow_Control_Pause", read_gen_ulong, 0, bdp_drv_off(rcv_fc_pkts)},	{"Rx_Flow_Control_Unsup", read_gen_ulong, 0, bdp_drv_off(rcv_fc_unsupported)},	{"\n",},	{"Tx_TCO_Packets",        read_gen_ulong, 0, bdp_drv_off(xmt_tco_pkts)},	{"Rx_TCO_Packets",        read_gen_ulong, 0, bdp_drv_off(rcv_tco_pkts)},	{"\n",},	{"Rx_Interrupt_Packets",  read_gen_ulong, 0, bdp_drv_off(rx_intr_pkts)},	{"Rx_Polling_Packets",    read_gen_ulong, 0, bdp_drv_off(rx_tasklet_pkts)},	{"Polling_Interrupt_Switch", read_gen_ulong, 0, bdp_drv_off(poll_intr_switch)},	{"Identify_Adapter", 0, write_blink_led_timer, 0},	{"", 0, 0, 0}};static intread_info(char *page, char **start, off_t off, int count, int *eof, void *data){	struct e100_private *bdp = data;	e100_proc_entry *pe;	int tmp;	void *val;	int len = 0;	for (pe = e100_proc_list; pe->name[0]; pe++) {		if (pe->name[0] == '\n') {			len += sprintf(page + len, "\n");			continue;		}		if (pe->read_proc) {			if ((len + READ_BUF_MAX_LEN + E100_PE_LEN + 1) >=			    PAGE_SIZE)				break;			if (pe->offset != ~0)				val = ((char *) bdp) + pe->offset;			else				val = NULL;			len += sprintf(page + len, "%-"				       __MODULE_STRING(E100_PE_LEN)				       "s ", pe->name);			len += pe->read_proc(page + len, start, 0,					     READ_BUF_MAX_LEN + 1, &tmp, val);		}	}	return generic_read(page, start, off, count, eof, len);}#ifdef E100_EOU/********************** *  parameter entries **********************/static intread_int_param(char *page, char *name, char *desc, int def, int min, int max){	int len;	len = sprintf(page, "Name: %s\n", name);	len += sprintf(page + len, "Description: %s\n", desc);	len += sprintf(page + len, "Default_Value: %d\n", def);	len += sprintf(page + len, "Type: Range\n");	len += sprintf(page + len, "Min: %d\n", min);	len += sprintf(page + len, "Max: %d\n", max);	len += sprintf(page + len, "Step:1\n");	len += sprintf(page + len, "Radix: dec\n");	return len;}static intread_bool_param(char *page, char *name, char *desc, int def){	int len;	len = sprintf(page, "Name: %s\n", name);	len += sprintf(page + len, "Description: %s\n", desc);	len += sprintf(page + len, "Default_Value: %d\n", def);	len += sprintf(page + len, "Type: Enum\n");	len += sprintf(page + len, "0: Off\n");	len += sprintf(page + len, "1: On\n");	return len;}static intread_speed_duplex_def(char *page, char **start, off_t off,		      int count, int *eof, void *data){	int len;	len = sprintf(page, "Name: Speed and Duplex\n");	len += sprintf(page + len, "Description: Sets the adapter's "		       "speed and duplex mode\n");	len += sprintf(page + len, "Default_Value: 0\n");	len += sprintf(page + len, "Type: Enum\n");	len += sprintf(page + len, "0: Auto-Negotiate\n");	len += sprintf(page + len, "1: 10 Mbps / Half Duplex\n");	len += sprintf(page + len, "2: 10 Mbps / Full Duplex\n");	len += sprintf(page + len, "3: 100 Mbps / Half Duplex\n");	len += sprintf(page + len, "4: 100 Mbps / Full Duplex\n");	return generic_read(page, start, off, count, eof, len);}static intread_tx_desc_def(char *page, char **start, off_t off,		 int count, int *eof, void *data){	int len;	len = read_int_param(page, "Transmit Descriptors",			     "Sets the number of Tx descriptors "			     "available for the adapter",			     E100_DEFAULT_TCB, E100_MIN_TCB, E100_MAX_TCB);	return generic_read(page, start, off, count, eof, len);}static intread_rx_desc_def(char *page, char **start, off_t off,		 int count, int *eof, void *data){	int len;	len = read_int_param(page, "Receive Descriptors",			     "Sets the number of Rx descriptors "			     "available for the adapter",			     E100_DEFAULT_RFD, E100_MIN_RFD, E100_MAX_RFD);	return generic_read(page, start, off, count, eof, len);}static intread_ber_def(char *page, char **start, off_t off,	     int count, int *eof, void *data){	int len;	len = read_int_param(page, "Bit Error Rate",			     "Sets the value for the BER correction algorithm",			     E100_DEFAULT_BER, 0, ZLOCK_MAX_ERRORS);	return generic_read(page, start, off, count, eof, len);}static intread_xsum_rx_def(char *page, char **start, off_t off,		 int count, int *eof, void *data){	int len;	len = read_bool_param(page, "RX Checksum",			      "Setting this value to \"On\" enables "			      "receive checksum", E100_DEFAULT_XSUM);	return generic_read(page, start, off, count, eof, len);}static intread_ucode_def(char *page, char **start, off_t off,	       int count, int *eof, void *data){

⌨️ 快捷键说明

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