📄 velocity_proc.c
字号:
/* * 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. * * * File: velocity_proc.c * * Purpose: proc entry process routines * * Author: Chuang Liang-Shing, AJ Jiang * * Date: Jan 24, 2003 * */#include "velocity.h"#include "velocity_proc.h"static const char* VELOCITY_PROC_DIR_NAME = "Velocity_Gigabit_Adapters";static struct proc_dir_entry *velocity_dir = NULL;static int FunVerRead(char *page, char **start, off_t off, int count, int *eof, void *data);static int FunStatRead(PVELOCITY_PROC_ENTRY pInfo,char* buf);static int FunConfRead(PVELOCITY_PROC_ENTRY pInfo,char* buf);static int FunConfWrite(PVELOCITY_PROC_ENTRY pInfo,const char* buf,unsigned long len);static int FunRMONRead(PVELOCITY_PROC_ENTRY pInfo,char* buf);typedefenum _proc_conf_type { CONF_RX_DESC = 0, // 0 CONF_TX_DESC, // 1 CONF_RX_THRESH, // 2 CONF_DMA_LEN, // 3 CONF_SPD_DPX, // 4 CONF_FLOW_CTRL, // 5 CONF_WOL_OPTS, // 6 CONF_ENABLE_TAG, // 7 CONF_VID_SETTING, // 8 CONF_VAL_PKT, // 9 CONF_ENABLE_MRDPL // 10} PROC_CONF_TYPE, *PPROC_CONF_TYPE;static const VELOCITY_PROC_ENTRY velocity_proc_tab_conf[] = {{"RxDescriptors", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_RX_DESC, NULL, 0},{"TxDescriptors", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_TX_DESC, NULL, 0},{"rx_thresh", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_RX_THRESH, NULL, 0},{"speed_duplex", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_SPD_DPX, NULL, 0},{"flow_control", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_FLOW_CTRL, NULL, 0},{"DMA_length", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_DMA_LEN, NULL, 0},{"ValPktLen", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_VAL_PKT, NULL, 0},{"wol_opts", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_WOL_OPTS, NULL, 0},{"EnableMRDPL", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_ENABLE_MRDPL, NULL, 0},{"enable_tagging", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_ENABLE_TAG, NULL, 0},{"VID_setting", VELOCITY_PROC_FILE, FunConfRead, FunConfWrite, CONF_VID_SETTING, NULL, 0},{"", VELOCITY_PROC_EOT, NULL, NULL, 0, NULL}};static const VELOCITY_PROC_ENTRY velocity_proc_tab_rmon[]={{"etherStatsDropEvents", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_DropEvents, NULL},{"etherStatsOctets", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Octets, NULL},{"etherStatsPkts", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Pkts, NULL},{"etherStatsBroadcastPkts", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_BroadcastPkts, NULL},{"etherStatsMulticastPkts", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_MulticastPkts, NULL},{"etherStatsCRCAlignErrors", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_CRCAlignErrors, NULL},{"etherStatsUndersizePkts", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_UndersizePkts,NULL},{"etherStatsOversizePkts", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_OversizePkts,NULL},{"etherStatsFragments", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Fragments,NULL},{"etherStatsJabbers", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Jabbers,NULL},{"etherStatsCollisions", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Collisions, NULL},{"etherStatsPkts64Octets", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Pkts64Octets, NULL},{"etherStatsPkts65to127Octets", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Pkts65to127Octets, NULL},{"etherStatsPkts128to255Octets", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Pkts128to255Octets, NULL},{"etherStatsPkts256to511Octets", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Pkts256to511Octets, NULL},{"etherStatsPkts512to1023Octets", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Pkts512to1023Octets, NULL},{"etherStatsPkts1024to1518Octets", VELOCITY_PROC_READ, FunRMONRead, NULL, RMON_Pkts1024to1518Octets, NULL},{"", VELOCITY_PROC_EOT, NULL, NULL, 0, NULL}};static const VELOCITY_PROC_ENTRY velocity_proc_tab[]={{"conf", VELOCITY_PROC_DIR, NULL, NULL, 0, velocity_proc_tab_conf},{"rmon", VELOCITY_PROC_DIR, NULL, NULL, 0, velocity_proc_tab_rmon},{"statics", VELOCITY_PROC_READ, FunStatRead,NULL, 0, NULL},{"", VELOCITY_PROC_EOT, NULL, NULL, 0, NULL}};static int velocity_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data) { PVELOCITY_PROC_ENTRY pEntry=(PVELOCITY_PROC_ENTRY) data; int len; len=pEntry->read_proc(pEntry, page); page[len++]='\n'; if (len <= off + count) *eof = 1; *start = page + off; len -= off; if (len > count) len = count; if (len < 0) len = 0; return len;}static int velocity_proc_write(struct file *filp, const char* buffer, unsigned long count, void *data){ int res=0; PVELOCITY_PROC_ENTRY pEntry=(PVELOCITY_PROC_ENTRY) data; res=pEntry->write_proc(pEntry,buffer,count); return res;}static void velocity_create_proc_tab(PVELOCITY_INFO pInfo, PVELOCITY_PROC_ENTRY pParent, const VELOCITY_PROC_ENTRY pTab[]) { int i; struct proc_dir_entry* ptr; PVELOCITY_PROC_ENTRY pEntry=NULL; PVELOCITY_PROC_ENTRY pRoot=NULL; if (pTab==NULL) return; for (i=0;pTab[i].type!=VELOCITY_PROC_EOT;i++) { //Skip some entries if ((pTab[i].byRevId!=0) && (pInfo->hw.byRevId<pTab[i].byRevId)) { continue; } pEntry=kmalloc(sizeof(VELOCITY_PROC_ENTRY),GFP_KERNEL); memcpy(pEntry,&pTab[i],sizeof(VELOCITY_PROC_ENTRY)); pEntry->siblings=pRoot; pRoot=pEntry; if (pEntry->type & VELOCITY_PROC_DIR) { ptr=create_proc_entry(pEntry->name,S_IFDIR, pParent->pOsEntry); pEntry->pOsParent=pParent->pOsEntry; pEntry->pOsEntry=ptr; velocity_create_proc_tab(pInfo,pEntry,pTab[i].childs); } else { int flag=S_IFREG; if (pEntry->type & VELOCITY_PROC_READ) flag|=S_IRUGO; if (pEntry->type & VELOCITY_PROC_WRITE) flag|=S_IWUSR; ptr=create_proc_entry(pEntry->name,flag, pParent->pOsEntry); if (pEntry->type & VELOCITY_PROC_READ) ptr->read_proc=velocity_proc_read; if (pEntry->type & VELOCITY_PROC_WRITE) ptr->write_proc=velocity_proc_write; ptr->data=pEntry; pEntry->pOsEntry=ptr; pEntry->pInfo=pInfo; pEntry->pOsParent=pParent->pOsEntry; } } pParent->childs=pRoot;}static void velocity_delete_proc_tab(PVELOCITY_INFO pInfo, const PVELOCITY_PROC_ENTRY pEntry) { if (pEntry==NULL) return; if (pEntry->type & VELOCITY_PROC_DIR) velocity_delete_proc_tab(pInfo,(PVELOCITY_PROC_ENTRY) pEntry->childs); else velocity_delete_proc_tab(pInfo,(PVELOCITY_PROC_ENTRY) pEntry->siblings); remove_proc_entry(pEntry->name,pEntry->pOsParent); kfree(pEntry);}BOOL velocity_create_proc_entry(PVELOCITY_INFO pInfo) { struct net_device *dev = pInfo->dev; //Create ethX directory as root directory pInfo->pProcDir=kmalloc(sizeof(VELOCITY_PROC_ENTRY),GFP_KERNEL); memset(pInfo->pProcDir,0,sizeof(VELOCITY_PROC_ENTRY)); pInfo->pProcDir->pOsEntry= create_proc_entry(dev->name, S_IFDIR, velocity_dir); pInfo->pProcDir->pOsParent = velocity_dir; //Create all other directoires according the defined entries on table velocity_create_proc_tab(pInfo, pInfo->pProcDir, velocity_proc_tab); return TRUE;}void velocity_free_proc_entry(PVELOCITY_INFO pInfo) { struct net_device *dev = pInfo->dev; velocity_delete_proc_tab(pInfo, (PVELOCITY_PROC_ENTRY) pInfo->pProcDir->childs); remove_proc_entry(dev->name, velocity_dir); kfree(pInfo->pProcDir);}BOOL velocity_init_proc_fs(PVELOCITY_INFO pInfo) { struct proc_dir_entry* ptr; int len=strlen(VELOCITY_PROC_DIR_NAME); if (velocity_dir==NULL) { for (velocity_dir = proc_net->subdir; velocity_dir;velocity_dir = velocity_dir->next) { if ((velocity_dir->namelen == len) && (!memcmp(velocity_dir->name, VELOCITY_PROC_DIR_NAME, len))) break; } if (velocity_dir==NULL) { velocity_dir=create_proc_entry(VELOCITY_PROC_DIR_NAME,S_IFDIR,proc_net); ptr=create_proc_entry("version",S_IFREG|S_IRUGO,velocity_dir); ptr->data=NULL; ptr->write_proc=NULL; ptr->read_proc=FunVerRead; } } if (velocity_dir==NULL) return FALSE; return TRUE;}void velocity_free_proc_fs(PVELOCITY_INFO pInfo) { struct proc_dir_entry* ptr;// remove_proc_entry(pInfo->pProcDir, velocity_dir); if (velocity_dir==NULL) return; //Check if other adapters's entry still exist for (ptr = velocity_dir->subdir; ptr; ptr = ptr->next) { if ((*(ptr->name) != '.') && (strcmp(ptr->name,"version"))) break; } if (ptr) return; remove_proc_entry("version",velocity_dir); remove_proc_entry(VELOCITY_PROC_DIR_NAME,proc_net); velocity_dir=NULL;}static long atol(const char* ptr,int len) { unsigned long l=0; while (*ptr!=0 && *ptr!='\n' && len-->0 ) { if (*ptr< '0' || *ptr >'9') return -1; l*=10; l+=(*ptr++-'0'); } return l;}//----------------------------------//static int FunVerRead(char *page, char **start, off_t off, int count, int *eof, void *data) { int len; len=sprintf(page,"%s",VELOCITY_VERSION); page[len++]='\n';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -