diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-01 17:51:54 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-01 17:51:54 -0700 |
commit | 20b4fb485227404329e41ad15588afad3df23050 (patch) | |
tree | f3e099f0ab3da8a93b447203e294d2bb22f6dc05 /drivers/staging/silicom | |
parent | b9394d8a657cd3c064fa432aa0905c1b58b38fe9 (diff) | |
parent | ac3e3c5b1164397656df81b9e9ab4991184d3236 (diff) | |
download | blackbird-op-linux-20b4fb485227404329e41ad15588afad3df23050.tar.gz blackbird-op-linux-20b4fb485227404329e41ad15588afad3df23050.zip |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull VFS updates from Al Viro,
Misc cleanups all over the place, mainly wrt /proc interfaces (switch
create_proc_entry to proc_create(), get rid of the deprecated
create_proc_read_entry() in favor of using proc_create_data() and
seq_file etc).
7kloc removed.
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (204 commits)
don't bother with deferred freeing of fdtables
proc: Move non-public stuff from linux/proc_fs.h to fs/proc/internal.h
proc: Make the PROC_I() and PDE() macros internal to procfs
proc: Supply a function to remove a proc entry by PDE
take cgroup_open() and cpuset_open() to fs/proc/base.c
ppc: Clean up scanlog
ppc: Clean up rtas_flash driver somewhat
hostap: proc: Use remove_proc_subtree()
drm: proc: Use remove_proc_subtree()
drm: proc: Use minor->index to label things, not PDE->name
drm: Constify drm_proc_list[]
zoran: Don't print proc_dir_entry data in debug
reiserfs: Don't access the proc_dir_entry in r_open(), r_start() r_show()
proc: Supply an accessor for getting the data from a PDE's parent
airo: Use remove_proc_subtree()
rtl8192u: Don't need to save device proc dir PDE
rtl8187se: Use a dir under /proc/net/r8180/
proc: Add proc_mkdir_data()
proc: Move some bits from linux/proc_fs.h to linux/{of.h,signal.h,tty.h}
proc: Move PDE_NET() to fs/proc/proc_net.c
...
Diffstat (limited to 'drivers/staging/silicom')
-rw-r--r-- | drivers/staging/silicom/Makefile | 3 | ||||
-rw-r--r-- | drivers/staging/silicom/bp_proc.c | 1327 | ||||
-rw-r--r-- | drivers/staging/silicom/bpctl_mod.c (renamed from drivers/staging/silicom/bp_mod.c) | 1925 |
3 files changed, 556 insertions, 2699 deletions
diff --git a/drivers/staging/silicom/Makefile b/drivers/staging/silicom/Makefile index 80e6d12d156b..ca8359481c48 100644 --- a/drivers/staging/silicom/Makefile +++ b/drivers/staging/silicom/Makefile @@ -4,6 +4,3 @@ obj-$(CONFIG_BPCTL) += bpctl_mod.o obj-$(CONFIG_SBYPASS) += bypasslib/ - - -bpctl_mod-objs := bp_mod.o bp_proc.o diff --git a/drivers/staging/silicom/bp_proc.c b/drivers/staging/silicom/bp_proc.c deleted file mode 100644 index a01ca97b7665..000000000000 --- a/drivers/staging/silicom/bp_proc.c +++ /dev/null @@ -1,1327 +0,0 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2004-2006 Silicom, Ltd */ -/* All rights reserved. */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, located in the file LICENSE. */ -/* */ -/* */ -/******************************************************************************/ - -#if defined(CONFIG_SMP) && !defined(__SMP__) -#define __SMP__ -#endif - -#include <linux/proc_fs.h> -#include <linux/netdevice.h> -#include <asm/uaccess.h> -/* #include <linux/smp_lock.h> */ -#include "bp_mod.h" - -#define BP_PROC_DIR "bypass" -/* #define BYPASS_SUPPORT "bypass" */ - -#ifdef BYPASS_SUPPORT - -#define GPIO6_SET_ENTRY_SD "gpio6_set" -#define GPIO6_CLEAR_ENTRY_SD "gpio6_clear" - -#define GPIO7_SET_ENTRY_SD "gpio7_set" -#define GPIO7_CLEAR_ENTRY_SD "gpio7_clear" - -#define PULSE_SET_ENTRY_SD "pulse_set" -#define ZERO_SET_ENTRY_SD "zero_set" -#define PULSE_GET1_ENTRY_SD "pulse_get1" -#define PULSE_GET2_ENTRY_SD "pulse_get2" - -#define CMND_ON_ENTRY_SD "cmnd_on" -#define CMND_OFF_ENTRY_SD "cmnd_off" -#define RESET_CONT_ENTRY_SD "reset_cont" - - /*COMMANDS*/ -#define BYPASS_INFO_ENTRY_SD "bypass_info" -#define BYPASS_SLAVE_ENTRY_SD "bypass_slave" -#define BYPASS_CAPS_ENTRY_SD "bypass_caps" -#define WD_SET_CAPS_ENTRY_SD "wd_set_caps" -#define BYPASS_ENTRY_SD "bypass" -#define BYPASS_CHANGE_ENTRY_SD "bypass_change" -#define BYPASS_WD_ENTRY_SD "bypass_wd" -#define WD_EXPIRE_TIME_ENTRY_SD "wd_expire_time" -#define RESET_BYPASS_WD_ENTRY_SD "reset_bypass_wd" -#define DIS_BYPASS_ENTRY_SD "dis_bypass" -#define BYPASS_PWUP_ENTRY_SD "bypass_pwup" -#define BYPASS_PWOFF_ENTRY_SD "bypass_pwoff" -#define STD_NIC_ENTRY_SD "std_nic" -#define STD_NIC_ENTRY_SD "std_nic" -#define TAP_ENTRY_SD "tap" -#define TAP_CHANGE_ENTRY_SD "tap_change" -#define DIS_TAP_ENTRY_SD "dis_tap" -#define TAP_PWUP_ENTRY_SD "tap_pwup" -#define TWO_PORT_LINK_ENTRY_SD "two_port_link" -#define WD_EXP_MODE_ENTRY_SD "wd_exp_mode" -#define WD_AUTORESET_ENTRY_SD "wd_autoreset" -#define TPL_ENTRY_SD "tpl" -#define WAIT_AT_PWUP_ENTRY_SD "wait_at_pwup" -#define HW_RESET_ENTRY_SD "hw_reset" -#define DISC_ENTRY_SD "disc" -#define DISC_CHANGE_ENTRY_SD "disc_change" -#define DIS_DISC_ENTRY_SD "dis_disc" -#define DISC_PWUP_ENTRY_SD "disc_pwup" - -static struct proc_dir_entry *bp_procfs_dir; - -static struct proc_dir_entry *proc_getdir(char *name, - struct proc_dir_entry *proc_dir) -{ - struct proc_dir_entry *pde = proc_dir; - for (pde = pde->subdir; pde; pde = pde->next) { - if (pde->namelen && (strcmp(name, pde->name) == 0)) { - /* directory exists */ - break; - } - } - if (pde == (struct proc_dir_entry *)0) { - /* create the directory */ - pde = create_proc_entry(name, S_IFDIR, proc_dir); - if (pde == (struct proc_dir_entry *)0) - return pde; - } - return pde; -} - -int -bypass_proc_create_entry_sd(struct pfs_unit *pfs_unit_curr, - char *proc_name, - write_proc_t *write_proc, - read_proc_t *read_proc, - struct proc_dir_entry *parent_pfs, void *data) -{ - strcpy(pfs_unit_curr->proc_name, proc_name); - pfs_unit_curr->proc_entry = create_proc_entry(pfs_unit_curr->proc_name, - S_IFREG | S_IRUSR | - S_IWUSR | S_IRGRP | - S_IROTH, parent_pfs); - if (pfs_unit_curr->proc_entry == 0) - return -1; - - pfs_unit_curr->proc_entry->read_proc = read_proc; - pfs_unit_curr->proc_entry->write_proc = write_proc; - pfs_unit_curr->proc_entry->data = data; - - return 0; - -} - -int -get_bypass_info_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - int len = 0; - - len += sprintf(page, "Name\t\t\t%s\n", pbp_device_block->bp_name); - len += - sprintf(page + len, "Firmware version\t0x%x\n", - pbp_device_block->bp_fw_ver); - - *eof = 1; - return len; -} - -int -get_bypass_slave_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - struct pci_dev *pci_slave_dev = pbp_device_block->bp_slave; - struct net_device *net_slave_dev; - int len = 0; - - if (is_bypass_fn(pbp_device_block)) { - net_slave_dev = pci_get_drvdata(pci_slave_dev); - if (net_slave_dev) - len = sprintf(page, "%s\n", net_slave_dev->name); - else - len = sprintf(page, "fail\n"); - } else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; -} - -int -get_bypass_caps_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_caps_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "-1\n"); - else - len = sprintf(page, "0x%x\n", ret); - *eof = 1; - return len; - -} - -int -get_wd_set_caps_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_wd_set_caps_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "-1\n"); - else - len = sprintf(page, "0x%x\n", ret); - *eof = 1; - return len; -} - -int -set_bypass_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_bypass_fn(pbp_device_block, bypass_param); - - return count; -} - -int -set_tap_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_tap_fn(pbp_device_block, tap_param); - - return count; -} - -int -set_disc_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_disc_fn(pbp_device_block, tap_param); - - return count; -} - -int -get_bypass_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; -} - -int -get_tap_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_tap_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; -} - -int -get_disc_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_disc_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; -} - -int -get_bypass_change_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_change_fn(pbp_device_block); - if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; -} - -int -get_tap_change_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_tap_change_fn(pbp_device_block); - if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; -} - -int -get_disc_change_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_disc_change_fn(pbp_device_block); - if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; -} - -int -set_bypass_wd_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - unsigned int timeout = 0; - char *timeout_ptr = kbuf; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - timeout_ptr = kbuf; - timeout = atoi(&timeout_ptr); - - set_bypass_wd_fn(pbp_device_block, timeout); - - return count; -} - -int -get_bypass_wd_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0, timeout = 0; - - ret = get_bypass_wd_fn(pbp_device_block, &timeout); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (timeout == -1) - len = sprintf(page, "unknown\n"); - else if (timeout == 0) - len = sprintf(page, "disable\n"); - else - len = sprintf(page, "%d\n", timeout); - - *eof = 1; - return len; -} - -int -get_wd_expire_time_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0, timeout = 0; - - ret = get_wd_expire_time_fn(pbp_device_block, &timeout); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (timeout == -1) - len = sprintf(page, "expire\n"); - else if (timeout == 0) - len = sprintf(page, "disable\n"); - - else - len = sprintf(page, "%d\n", timeout); - *eof = 1; - return len; -} - -int -get_tpl_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_tpl_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; -} - -#ifdef PMC_FIX_FLAG -int -get_wait_at_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bp_wait_at_pwup_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; -} - -int -get_hw_reset_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bp_hw_reset_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; -} - -#endif /*PMC_WAIT_FLAG */ - -int -reset_bypass_wd_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = reset_bypass_wd_timer_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "disable\n"); - else if (ret == 1) - len = sprintf(page, "success\n"); - - *eof = 1; - return len; -} - -int -set_dis_bypass_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_dis_bypass_fn(pbp_device_block, bypass_param); - - return count; -} - -int -set_dis_tap_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_dis_tap_fn(pbp_device_block, tap_param); - - return count; -} - -int -set_dis_disc_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_dis_disc_fn(pbp_device_block, tap_param); - - return count; -} - -int -get_dis_bypass_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_dis_bypass_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -get_dis_tap_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_dis_tap_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -get_dis_disc_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_dis_disc_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -set_bypass_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_bypass_pwup_fn(pbp_device_block, bypass_param); - - return count; -} - -int -set_bypass_pwoff_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_bypass_pwoff_fn(pbp_device_block, bypass_param); - - return count; -} - -int -set_tap_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_tap_pwup_fn(pbp_device_block, tap_param); - - return count; -} - -int -set_disc_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_disc_pwup_fn(pbp_device_block, tap_param); - - return count; -} - -int -get_bypass_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_pwup_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -get_bypass_pwoff_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_pwoff_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -get_tap_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_tap_pwup_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -get_disc_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_disc_pwup_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -set_std_nic_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_std_nic_fn(pbp_device_block, bypass_param); - - return count; -} - -int -get_std_nic_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_std_nic_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -get_wd_exp_mode_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_wd_exp_mode_fn(pbp_device_block); - if (ret == 1) - len = sprintf(page, "tap\n"); - else if (ret == 0) - len = sprintf(page, "bypass\n"); - else if (ret == 2) - len = sprintf(page, "disc\n"); - - else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; -} - -int -set_wd_exp_mode_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "tap") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "bypass") == 0) - bypass_param = 0; - else if (strcmp(kbuf, "disc") == 0) - bypass_param = 2; - - set_wd_exp_mode_fn(pbp_device_block, bypass_param); - - return count; -} - -int -get_wd_autoreset_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_wd_autoreset_fn(pbp_device_block); - if (ret >= 0) - len = sprintf(page, "%d\n", ret); - else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; -} - -int -set_wd_autoreset_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - u32 timeout = 0; - char *timeout_ptr = kbuf; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - timeout_ptr = kbuf; - timeout = atoi(&timeout_ptr); - - set_wd_autoreset_fn(pbp_device_block, timeout); - - return count; -} - -int -set_tpl_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tpl_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tpl_param = 1; - else if (strcmp(kbuf, "off") == 0) - tpl_param = 0; - - set_tpl_fn(pbp_device_block, tpl_param); - - return count; -} - -#ifdef PMC_FIX_FLAG -int -set_wait_at_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tpl_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tpl_param = 1; - else if (strcmp(kbuf, "off") == 0) - tpl_param = 0; - - set_bp_wait_at_pwup_fn(pbp_device_block, tpl_param); - - return count; -} - -int -set_hw_reset_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tpl_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) - return -1; - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tpl_param = 1; - else if (strcmp(kbuf, "off") == 0) - tpl_param = 0; - - set_bp_hw_reset_fn(pbp_device_block, tpl_param); - - return count; -} - -#endif /*PMC_FIX_FLAG */ - -int bypass_proc_create_dev_sd(bpctl_dev_t *pbp_device_block) -{ - struct bypass_pfs_sd *current_pfs = &(pbp_device_block->bypass_pfs_set); - static struct proc_dir_entry *procfs_dir; - int ret = 0; - - sprintf(current_pfs->dir_name, "bypass_%s", dev->name); - - if (!bp_procfs_dir) - return -1; - - /* create device proc dir */ - procfs_dir = proc_getdir(current_pfs->dir_name, bp_procfs_dir); - if (procfs_dir == 0) { - printk(KERN_DEBUG "Could not create procfs directory %s\n", - current_pfs->dir_name); - return -1; - } - current_pfs->bypass_entry = procfs_dir; - - if (bypass_proc_create_entry(&(current_pfs->bypass_info), BYPASS_INFO_ENTRY_SD, NULL, /* write */ - get_bypass_info_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (pbp_device_block->bp_caps & SW_CTL_CAP) { - - /* Create set param proc's */ - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_slave), BYPASS_SLAVE_ENTRY_SD, NULL, /* write */ - get_bypass_slave_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_caps), BYPASS_CAPS_ENTRY_SD, NULL, /* write */ - get_bypass_caps_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->wd_set_caps), WD_SET_CAPS_ENTRY_SD, NULL, /* write */ - get_wd_set_caps_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_wd), BYPASS_WD_ENTRY_SD, set_bypass_wd_pfs, /* write */ - get_bypass_wd_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->wd_expire_time), WD_EXPIRE_TIME_ENTRY_SD, NULL, /* write */ - get_wd_expire_time_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->reset_bypass_wd), RESET_BYPASS_WD_ENTRY_SD, NULL, /* write */ - reset_bypass_wd_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->std_nic), STD_NIC_ENTRY_SD, set_std_nic_pfs, /* write */ - get_std_nic_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (pbp_device_block->bp_caps & BP_CAP) { - if (bypass_proc_create_entry_sd(&(current_pfs->bypass), BYPASS_ENTRY_SD, set_bypass_pfs, /* write */ - get_bypass_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->dis_bypass), DIS_BYPASS_ENTRY_SD, set_dis_bypass_pfs, /* write */ - get_dis_bypass_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_pwup), BYPASS_PWUP_ENTRY_SD, set_bypass_pwup_pfs, /* write */ - get_bypass_pwup_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_pwoff), BYPASS_PWOFF_ENTRY_SD, set_bypass_pwoff_pfs, /* write */ - get_bypass_pwoff_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_change), BYPASS_CHANGE_ENTRY_SD, NULL, /* write */ - get_bypass_change_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - } - - if (pbp_device_block->bp_caps & TAP_CAP) { - - if (bypass_proc_create_entry_sd(&(current_pfs->tap), TAP_ENTRY_SD, set_tap_pfs, /* write */ - get_tap_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->dis_tap), DIS_TAP_ENTRY_SD, set_dis_tap_pfs, /* write */ - get_dis_tap_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_pwup), TAP_PWUP_ENTRY_SD, set_tap_pwup_pfs, /* write */ - get_tap_pwup_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_change), TAP_CHANGE_ENTRY_SD, NULL, /* write */ - get_tap_change_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - } - if (pbp_device_block->bp_caps & DISC_CAP) { - - if (bypass_proc_create_entry_sd(&(current_pfs->tap), DISC_ENTRY_SD, set_disc_pfs, /* write */ - get_disc_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; -#if 1 - - if (bypass_proc_create_entry_sd(&(current_pfs->dis_tap), DIS_DISC_ENTRY_SD, set_dis_disc_pfs, /* write */ - get_dis_disc_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; -#endif - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_pwup), DISC_PWUP_ENTRY_SD, set_disc_pwup_pfs, /* write */ - get_disc_pwup_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_change), DISC_CHANGE_ENTRY_SD, NULL, /* write */ - get_disc_change_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - } - - if (bypass_proc_create_entry_sd(&(current_pfs->wd_exp_mode), WD_EXP_MODE_ENTRY_SD, set_wd_exp_mode_pfs, /* write */ - get_wd_exp_mode_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->wd_autoreset), WD_AUTORESET_ENTRY_SD, set_wd_autoreset_pfs, /* write */ - get_wd_autoreset_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->tpl), TPL_ENTRY_SD, set_tpl_pfs, /* write */ - get_tpl_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; -#ifdef PMC_FIX_FLAG - if (bypass_proc_create_entry_sd(&(current_pfs->tpl), WAIT_AT_PWUP_ENTRY_SD, set_wait_at_pwup_pfs, /* write */ - get_wait_at_pwup_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->tpl), HW_RESET_ENTRY_SD, set_hw_reset_pfs, /* write */ - get_hw_reset_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - -#endif - - } - if (ret < 0) - printk(KERN_DEBUG "Create proc entry failed\n"); - - return ret; -} - -int bypass_proc_remove_dev_sd(bpctl_dev_t *pbp_device_block) -{ - - struct bypass_pfs_sd *current_pfs = &pbp_device_block->bypass_pfs_set; - struct proc_dir_entry *pde = current_pfs->bypass_entry, *pde_curr = - NULL; - char name[256]; - - for (pde = pde->subdir; pde;) { - strcpy(name, pde->name); - pde_curr = pde; - pde = pde->next; - remove_proc_entry(name, current_pfs->bypass_entry); - } - if (!pde) - remove_proc_entry(current_pfs->dir_name, bp_procfs_dir); - - return 0; -} - -#endif /* BYPASS_SUPPORT */ diff --git a/drivers/staging/silicom/bp_mod.c b/drivers/staging/silicom/bpctl_mod.c index 45a222723207..b7e570ccb759 100644 --- a/drivers/staging/silicom/bp_mod.c +++ b/drivers/staging/silicom/bpctl_mod.c @@ -35,7 +35,6 @@ #define BP_MOD_DESCR "Silicom Bypass-SD Control driver" #define BP_SYNC_FLAG 1 -static int Device_Open = 0; static int major_num = 0; MODULE_AUTHOR("Anna Lukin, annal@silicom.co.il"); @@ -60,35 +59,9 @@ typedef enum { bp_none, } bp_media_type; -struct pfs_unit_sd { - struct proc_dir_entry *proc_entry; - char proc_name[32]; -}; - struct bypass_pfs_sd { char dir_name[32]; struct proc_dir_entry *bypass_entry; - struct pfs_unit_sd bypass_info; - struct pfs_unit_sd bypass_slave; - struct pfs_unit_sd bypass_caps; - struct pfs_unit_sd wd_set_caps; - struct pfs_unit_sd bypass; - struct pfs_unit_sd bypass_change; - struct pfs_unit_sd bypass_wd; - struct pfs_unit_sd wd_expire_time; - struct pfs_unit_sd reset_bypass_wd; - struct pfs_unit_sd dis_bypass; - struct pfs_unit_sd bypass_pwup; - struct pfs_unit_sd bypass_pwoff; - struct pfs_unit_sd std_nic; - struct pfs_unit_sd tap; - struct pfs_unit_sd dis_tap; - struct pfs_unit_sd tap_pwup; - struct pfs_unit_sd tap_change; - struct pfs_unit_sd wd_exp_mode; - struct pfs_unit_sd wd_autoreset; - struct pfs_unit_sd tpl; - }; typedef struct _bpctl_dev { @@ -315,27 +288,6 @@ static struct notifier_block bp_notifier_block = { .notifier_call = bp_device_event, }; -static int device_open(struct inode *inode, struct file *file) -{ -#ifdef DEBUG - printk("device_open(%p)\n", file); -#endif - Device_Open++; -/* -* Initialize the message -*/ - return SUCCESS; -} - -static int device_release(struct inode *inode, struct file *file) -{ -#ifdef DEBUG - printk("device_release(%p,%p)\n", inode, file); -#endif - Device_Open--; - return SUCCESS; -} - int is_bypass_fn(bpctl_dev_t *pbpctl_dev); int wdt_time_left(bpctl_dev_t *pbpctl_dev); @@ -1728,62 +1680,33 @@ int gpio6_clear_fn(bpctl_dev_t *pbpctl_dev) } #endif /*BYPASS_DEBUG */ -static bpctl_dev_t *get_status_port_fn(bpctl_dev_t *pbpctl_dev) +static bpctl_dev_t *lookup_port(bpctl_dev_t *dev) { - int idx_dev = 0; - - if (pbpctl_dev == NULL) - return NULL; - - if ((pbpctl_dev->func == 0) || (pbpctl_dev->func == 2)) { - for (idx_dev = 0; - ((bpctl_dev_arr[idx_dev].pdev != NULL) - && (idx_dev < device_num)); idx_dev++) { - if ((bpctl_dev_arr[idx_dev].bus == pbpctl_dev->bus) - && (bpctl_dev_arr[idx_dev].slot == pbpctl_dev->slot) - && ((bpctl_dev_arr[idx_dev].func == 1) - && (pbpctl_dev->func == 0))) { - - return &(bpctl_dev_arr[idx_dev]); - } - if ((bpctl_dev_arr[idx_dev].bus == pbpctl_dev->bus) && - (bpctl_dev_arr[idx_dev].slot == pbpctl_dev->slot) && - ((bpctl_dev_arr[idx_dev].func == 3) - && (pbpctl_dev->func == 2))) { + bpctl_dev_t *p; + int n; + for (n = 0, p = bpctl_dev_arr; n < device_num && p->pdev; n++) { + if (p->bus == dev->bus + && p->slot == dev->slot + && p->func == (dev->func ^ 1)) + return p; + } + return NULL; +} - return &(bpctl_dev_arr[idx_dev]); - } - } +static bpctl_dev_t *get_status_port_fn(bpctl_dev_t *pbpctl_dev) +{ + if (pbpctl_dev) { + if (pbpctl_dev->func == 0 || pbpctl_dev->func == 2) + return lookup_port(pbpctl_dev); } return NULL; } static bpctl_dev_t *get_master_port_fn(bpctl_dev_t *pbpctl_dev) { - int idx_dev = 0; - - if (pbpctl_dev == NULL) - return NULL; - - if ((pbpctl_dev->func == 1) || (pbpctl_dev->func == 3)) { - for (idx_dev = 0; - ((bpctl_dev_arr[idx_dev].pdev != NULL) - && (idx_dev < device_num)); idx_dev++) { - if ((bpctl_dev_arr[idx_dev].bus == pbpctl_dev->bus) - && (bpctl_dev_arr[idx_dev].slot == pbpctl_dev->slot) - && ((bpctl_dev_arr[idx_dev].func == 0) - && (pbpctl_dev->func == 1))) { - - return &(bpctl_dev_arr[idx_dev]); - } - if ((bpctl_dev_arr[idx_dev].bus == pbpctl_dev->bus) && - (bpctl_dev_arr[idx_dev].slot == pbpctl_dev->slot) && - ((bpctl_dev_arr[idx_dev].func == 2) - && (pbpctl_dev->func == 3))) { - - return &(bpctl_dev_arr[idx_dev]); - } - } + if (pbpctl_dev) { + if (pbpctl_dev->func == 1 || pbpctl_dev->func == 3) + return lookup_port(pbpctl_dev); } return NULL; } @@ -5858,11 +5781,9 @@ static long device_ioctl(struct file *file, /* see include/linux/fs.h */ return ret; } -struct file_operations Fops = { +static const struct file_operations Fops = { .owner = THIS_MODULE, .unlocked_ioctl = device_ioctl, - .open = device_open, - .release = device_release, /* a.k.a. close */ }; #ifndef PCI_DEVICE @@ -6686,6 +6607,118 @@ static bpmod_info_t tx_ctl_pci_tbl[] = { {0,} }; +static void find_fw(bpctl_dev_t *dev) +{ + unsigned long mmio_start, mmio_len; + struct pci_dev *pdev1 = dev->pdev; + + if ((OLD_IF_SERIES(dev->subdevice)) || + (INTEL_IF_SERIES(dev->subdevice))) + dev->bp_fw_ver = 0xff; + else + dev->bp_fw_ver = bypass_fw_ver(dev); + + if (dev->bp_10gb == 1 && dev->bp_fw_ver == 0xff) { + int cnt = 100; + while (cnt--) { + iounmap((void *)dev->mem_map); + mmio_start = pci_resource_start(pdev1, 0); + mmio_len = pci_resource_len(pdev1, 0); + + dev->mem_map = (unsigned long) + ioremap(mmio_start, mmio_len); + + dev->bp_fw_ver = bypass_fw_ver(dev); + if (dev-> bp_fw_ver == 0xa8) + break; + } + } + /* dev->bp_fw_ver=0xa8; */ + printk("firmware version: 0x%x\n", dev->bp_fw_ver); +} + +static int init_one(bpctl_dev_t *dev, bpmod_info_t *info, struct pci_dev *pdev1) +{ + unsigned long mmio_start, mmio_len; + + dev->pdev = pdev1; + mmio_start = pci_resource_start(pdev1, 0); + mmio_len = pci_resource_len(pdev1, 0); + + dev->desc = dev_desc[info->index].name; + dev->name = info->bp_name; + dev->device = info->device; + dev->vendor = info->vendor; + dev->subdevice = info->subdevice; + dev->subvendor = info->subvendor; + dev->func = PCI_FUNC(pdev1->devfn); + dev->slot = PCI_SLOT(pdev1->devfn); + dev->bus = pdev1->bus->number; + dev->mem_map = (unsigned long)ioremap(mmio_start, mmio_len); +#ifdef BP_SYNC_FLAG + spin_lock_init(&dev->bypass_wr_lock); +#endif + if (BP10G9_IF_SERIES(dev->subdevice)) + dev->bp_10g9 = 1; + if (BP10G_IF_SERIES(dev->subdevice)) + dev->bp_10g = 1; + if (PEG540_IF_SERIES(dev->subdevice)) + dev->bp_540 = 1; + if (PEGF5_IF_SERIES(dev->subdevice)) + dev->bp_fiber5 = 1; + if (PEG80_IF_SERIES(dev->subdevice)) + dev->bp_i80 = 1; + if (PEGF80_IF_SERIES(dev->subdevice)) + dev->bp_i80 = 1; + if ((dev->subdevice & 0xa00) == 0xa00) + dev->bp_i80 = 1; + if (BP10GB_IF_SERIES(dev->subdevice)) { + if (dev->ifindex == 0) { + unregister_chrdev(major_num, DEVICE_NAME); + printk("Please load network driver for %s adapter!\n", + dev->name); + return -1; + } + + if (dev->ndev && !(dev->ndev->flags & IFF_UP)) { + unregister_chrdev(major_num, DEVICE_NAME); + printk("Please bring up network interfaces for %s adapter!\n", + dev->name); + return -1; + } + dev->bp_10gb = 1; + } + + if (!dev->bp_10g9) { + if (is_bypass_fn(dev)) { + printk(KERN_INFO "%s found, ", + dev->name); + find_fw(dev); + } + dev->wdt_status = WDT_STATUS_UNKNOWN; + dev->reset_time = 0; + atomic_set(&dev->wdt_busy, 0); + dev->bp_status_un = 1; + + bypass_caps_init(dev); + + init_bypass_wd_auto(dev); + init_bypass_tpl_auto(dev); + if (NOKIA_SERIES(dev->subdevice)) + reset_cont(dev); + } +#ifdef BP_SELF_TEST + if ((dev->bp_tx_data = kzalloc(BPTEST_DATA_LEN, GFP_KERNEL))) { + memset(dev->bp_tx_data, 0xff, 6); + memset(dev->bp_tx_data + 6, 0x0, 1); + memset(dev->bp_tx_data + 7, 0xaa, 5); + *(__be16 *)(dev->bp_tx_data + 12) = htons(ETH_P_BPTEST); + } else + printk("bp_ctl: Memory allocation error!\n"); +#endif + return 0; +} + /* * Initialize the module - Register the character device */ @@ -6694,7 +6727,7 @@ static int __init bypass_init_module(void) { int ret_val, idx, idx_dev = 0; struct pci_dev *pdev1 = NULL; - unsigned long mmio_start, mmio_len; + bpctl_dev_t *dev; printk(BP_MOD_DESCR " v" BP_MOD_VER "\n"); ret_val = register_chrdev(major_num, DEVICE_NAME, &Fops); @@ -6729,181 +6762,16 @@ static int __init bypass_init_module(void) memset(bpctl_dev_arr, 0, ((device_num) * sizeof(bpctl_dev_t))); pdev1 = NULL; + dev = bpctl_dev_arr; for (idx = 0; tx_ctl_pci_tbl[idx].vendor; idx++) { while ((pdev1 = pci_get_subsys(tx_ctl_pci_tbl[idx].vendor, tx_ctl_pci_tbl[idx].device, tx_ctl_pci_tbl[idx].subvendor, tx_ctl_pci_tbl[idx].subdevice, pdev1))) { - bpctl_dev_arr[idx_dev].pdev = pdev1; - - mmio_start = pci_resource_start(pdev1, 0); - mmio_len = pci_resource_len(pdev1, 0); - - bpctl_dev_arr[idx_dev].desc = - dev_desc[tx_ctl_pci_tbl[idx].index].name; - bpctl_dev_arr[idx_dev].name = - tx_ctl_pci_tbl[idx].bp_name; - bpctl_dev_arr[idx_dev].device = - tx_ctl_pci_tbl[idx].device; - bpctl_dev_arr[idx_dev].vendor = - tx_ctl_pci_tbl[idx].vendor; - bpctl_dev_arr[idx_dev].subdevice = - tx_ctl_pci_tbl[idx].subdevice; - bpctl_dev_arr[idx_dev].subvendor = - tx_ctl_pci_tbl[idx].subvendor; - /* bpctl_dev_arr[idx_dev].pdev=pdev1; */ - bpctl_dev_arr[idx_dev].func = PCI_FUNC(pdev1->devfn); - bpctl_dev_arr[idx_dev].slot = PCI_SLOT(pdev1->devfn); - bpctl_dev_arr[idx_dev].bus = pdev1->bus->number; - bpctl_dev_arr[idx_dev].mem_map = - (unsigned long)ioremap(mmio_start, mmio_len); -#ifdef BP_SYNC_FLAG - spin_lock_init(&bpctl_dev_arr[idx_dev].bypass_wr_lock); -#endif - if (BP10G9_IF_SERIES(bpctl_dev_arr[idx_dev].subdevice)) - bpctl_dev_arr[idx_dev].bp_10g9 = 1; - if (BP10G_IF_SERIES(bpctl_dev_arr[idx_dev].subdevice)) - bpctl_dev_arr[idx_dev].bp_10g = 1; - if (PEG540_IF_SERIES(bpctl_dev_arr[idx_dev].subdevice)) { - - bpctl_dev_arr[idx_dev].bp_540 = 1; - } - if (PEGF5_IF_SERIES(bpctl_dev_arr[idx_dev].subdevice)) - bpctl_dev_arr[idx_dev].bp_fiber5 = 1; - if (PEG80_IF_SERIES(bpctl_dev_arr[idx_dev].subdevice)) - bpctl_dev_arr[idx_dev].bp_i80 = 1; - if (PEGF80_IF_SERIES(bpctl_dev_arr[idx_dev].subdevice)) - bpctl_dev_arr[idx_dev].bp_i80 = 1; - if ((bpctl_dev_arr[idx_dev].subdevice & 0xa00) == 0xa00) - bpctl_dev_arr[idx_dev].bp_i80 = 1; - if (BP10GB_IF_SERIES(bpctl_dev_arr[idx_dev].subdevice)) { - if (bpctl_dev_arr[idx_dev].ifindex == 0) { - unregister_chrdev(major_num, - DEVICE_NAME); - printk - ("Please load network driver for %s adapter!\n", - bpctl_dev_arr[idx_dev].name); - return -1; - } - - if (bpctl_dev_arr[idx_dev].ndev) { - if (! - (bpctl_dev_arr[idx_dev].ndev-> - flags & IFF_UP)) { - if (! - (bpctl_dev_arr[idx_dev]. - ndev->flags & IFF_UP)) { - unregister_chrdev - (major_num, - DEVICE_NAME); - printk - ("Please bring up network interfaces for %s adapter!\n", - bpctl_dev_arr - [idx_dev].name); - return -1; - } - - } - } - bpctl_dev_arr[idx_dev].bp_10gb = 1; - } - - if (!bpctl_dev_arr[idx_dev].bp_10g9) { - - if (is_bypass_fn(&bpctl_dev_arr[idx_dev])) { - printk(KERN_INFO "%s found, ", - bpctl_dev_arr[idx_dev].name); - if ((OLD_IF_SERIES - (bpctl_dev_arr[idx_dev].subdevice)) - || - (INTEL_IF_SERIES - (bpctl_dev_arr[idx_dev]. - subdevice))) - bpctl_dev_arr[idx_dev]. - bp_fw_ver = 0xff; - else - bpctl_dev_arr[idx_dev]. - bp_fw_ver = - bypass_fw_ver(&bpctl_dev_arr - [idx_dev]); - if ((bpctl_dev_arr[idx_dev].bp_10gb == - 1) - && (bpctl_dev_arr[idx_dev]. - bp_fw_ver == 0xff)) { - int cnt = 100; - while (cnt--) { - iounmap((void - *) - (bpctl_dev_arr - [idx_dev]. - mem_map)); - mmio_start = - pci_resource_start - (pdev1, 0); - mmio_len = - pci_resource_len - (pdev1, 0); - - bpctl_dev_arr[idx_dev]. - mem_map = - (unsigned long) - ioremap(mmio_start, - mmio_len); - - bpctl_dev_arr[idx_dev]. - bp_fw_ver = - bypass_fw_ver - (&bpctl_dev_arr - [idx_dev]); - if (bpctl_dev_arr - [idx_dev]. - bp_fw_ver == 0xa8) - break; - - } - } - /* bpctl_dev_arr[idx_dev].bp_fw_ver=0xa8; */ - printk("firmware version: 0x%x\n", - bpctl_dev_arr[idx_dev]. - bp_fw_ver); - } - bpctl_dev_arr[idx_dev].wdt_status = - WDT_STATUS_UNKNOWN; - bpctl_dev_arr[idx_dev].reset_time = 0; - atomic_set(&bpctl_dev_arr[idx_dev].wdt_busy, 0); - bpctl_dev_arr[idx_dev].bp_status_un = 1; - - bypass_caps_init(&bpctl_dev_arr[idx_dev]); - - init_bypass_wd_auto(&bpctl_dev_arr[idx_dev]); - init_bypass_tpl_auto(&bpctl_dev_arr[idx_dev]); - if (NOKIA_SERIES - (bpctl_dev_arr[idx_dev].subdevice)) - reset_cont(&bpctl_dev_arr[idx_dev]); - } -#ifdef BP_SELF_TEST - if ((bpctl_dev_arr[idx_dev].bp_tx_data = - kmalloc(BPTEST_DATA_LEN, GFP_KERNEL))) { - - memset(bpctl_dev_arr[idx_dev].bp_tx_data, 0x0, - BPTEST_DATA_LEN); - - memset(bpctl_dev_arr[idx_dev].bp_tx_data, 0xff, - 6); - memset(bpctl_dev_arr[idx_dev].bp_tx_data + 6, - 0x0, 1); - memset(bpctl_dev_arr[idx_dev].bp_tx_data + 7, - 0xaa, 5); - - *(__be16 *) (bpctl_dev_arr[idx_dev].bp_tx_data + - 12) = htons(ETH_P_BPTEST); - - } else - printk("bp_ctl: Memory allocation error!\n"); -#endif - idx_dev++; - + if (init_one(dev, &tx_ctl_pci_tbl[idx], pdev1) < 0) + return -1; + dev++; } } if_scan_init(); @@ -6913,33 +6781,27 @@ static int __init bypass_init_module(void) { bpctl_dev_t *pbpctl_dev_c = NULL; - for (idx_dev = 0; - ((bpctl_dev_arr[idx_dev].pdev != NULL) - && (idx_dev < device_num)); idx_dev++) { - if (bpctl_dev_arr[idx_dev].bp_10g9) { - pbpctl_dev_c = - get_status_port_fn(&bpctl_dev_arr[idx_dev]); - if (is_bypass_fn(&bpctl_dev_arr[idx_dev])) { + for (idx_dev = 0, dev = bpctl_dev_arr; + idx_dev < device_num && dev->pdev; + idx_dev++, dev++) { + if (dev->bp_10g9) { + pbpctl_dev_c = get_status_port_fn(dev); + if (is_bypass_fn(dev)) { printk(KERN_INFO "%s found, ", - bpctl_dev_arr[idx_dev].name); - bpctl_dev_arr[idx_dev].bp_fw_ver = - bypass_fw_ver(&bpctl_dev_arr - [idx_dev]); + dev->name); + dev->bp_fw_ver = bypass_fw_ver(dev); printk("firmware version: 0x%x\n", - bpctl_dev_arr[idx_dev]. - bp_fw_ver); - + dev->bp_fw_ver); } - bpctl_dev_arr[idx_dev].wdt_status = - WDT_STATUS_UNKNOWN; - bpctl_dev_arr[idx_dev].reset_time = 0; - atomic_set(&bpctl_dev_arr[idx_dev].wdt_busy, 0); - bpctl_dev_arr[idx_dev].bp_status_un = 1; + dev->wdt_status = WDT_STATUS_UNKNOWN; + dev->reset_time = 0; + atomic_set(&dev->wdt_busy, 0); + dev->bp_status_un = 1; - bypass_caps_init(&bpctl_dev_arr[idx_dev]); + bypass_caps_init(dev); - init_bypass_wd_auto(&bpctl_dev_arr[idx_dev]); - init_bypass_tpl_auto(&bpctl_dev_arr[idx_dev]); + init_bypass_wd_auto(dev); + init_bypass_tpl_auto(dev); } @@ -7336,78 +7198,11 @@ EXPORT_SYMBOL_NOVERS(bp_if_scan_sd); #define BP_PROC_DIR "bypass" -#define GPIO6_SET_ENTRY_SD "gpio6_set" -#define GPIO6_CLEAR_ENTRY_SD "gpio6_clear" - -#define GPIO7_SET_ENTRY_SD "gpio7_set" -#define GPIO7_CLEAR_ENTRY_SD "gpio7_clear" - -#define PULSE_SET_ENTRY_SD "pulse_set" -#define ZERO_SET_ENTRY_SD "zero_set" -#define PULSE_GET1_ENTRY_SD "pulse_get1" -#define PULSE_GET2_ENTRY_SD "pulse_get2" - -#define CMND_ON_ENTRY_SD "cmnd_on" -#define CMND_OFF_ENTRY_SD "cmnd_off" -#define RESET_CONT_ENTRY_SD "reset_cont" - - /*COMMANDS*/ -#define BYPASS_INFO_ENTRY_SD "bypass_info" -#define BYPASS_SLAVE_ENTRY_SD "bypass_slave" -#define BYPASS_CAPS_ENTRY_SD "bypass_caps" -#define WD_SET_CAPS_ENTRY_SD "wd_set_caps" -#define BYPASS_ENTRY_SD "bypass" -#define BYPASS_CHANGE_ENTRY_SD "bypass_change" -#define BYPASS_WD_ENTRY_SD "bypass_wd" -#define WD_EXPIRE_TIME_ENTRY_SD "wd_expire_time" -#define RESET_BYPASS_WD_ENTRY_SD "reset_bypass_wd" -#define DIS_BYPASS_ENTRY_SD "dis_bypass" -#define BYPASS_PWUP_ENTRY_SD "bypass_pwup" -#define BYPASS_PWOFF_ENTRY_SD "bypass_pwoff" -#define STD_NIC_ENTRY_SD "std_nic" -#define STD_NIC_ENTRY_SD "std_nic" -#define TAP_ENTRY_SD "tap" -#define TAP_CHANGE_ENTRY_SD "tap_change" -#define DIS_TAP_ENTRY_SD "dis_tap" -#define TAP_PWUP_ENTRY_SD "tap_pwup" -#define TWO_PORT_LINK_ENTRY_SD "two_port_link" -#define WD_EXP_MODE_ENTRY_SD "wd_exp_mode" -#define WD_AUTORESET_ENTRY_SD "wd_autoreset" -#define TPL_ENTRY_SD "tpl" -#define WAIT_AT_PWUP_ENTRY_SD "wait_at_pwup" -#define HW_RESET_ENTRY_SD "hw_reset" -#define DISC_ENTRY_SD "disc" -#define DISC_CHANGE_ENTRY_SD "disc_change" -#define DIS_DISC_ENTRY_SD "dis_disc" -#define DISC_PWUP_ENTRY_SD "disc_pwup" static struct proc_dir_entry *bp_procfs_dir; -static struct proc_dir_entry *proc_getdir(char *name, - struct proc_dir_entry *proc_dir) -{ - struct proc_dir_entry *pde = proc_dir; - - for (pde = pde->subdir; pde; pde = pde->next) { - if (pde->namelen && (strcmp(name, pde->name) == 0)) { - /* directory exists */ - break; - } - } - if (pde == (struct proc_dir_entry *)0) { - /* create the directory */ - pde = proc_mkdir(name, proc_dir); - if (pde == (struct proc_dir_entry *)0) { - - return pde; - } - } - - return pde; -} - int bp_proc_create(void) { - bp_procfs_dir = proc_getdir(BP_PROC_DIR, init_net.proc_net); + bp_procfs_dir = proc_mkdir(BP_PROC_DIR, init_net.proc_net); if (bp_procfs_dir == (struct proc_dir_entry *)0) { printk(KERN_DEBUG "Could not create procfs nicinfo directory %s\n", @@ -7417,144 +7212,99 @@ int bp_proc_create(void) return 0; } -int -bypass_proc_create_entry_sd(struct pfs_unit_sd *pfs_unit_curr, - char *proc_name, - write_proc_t *write_proc, - read_proc_t *read_proc, - struct proc_dir_entry *parent_pfs, void *data) +static int procfs_add(char *proc_name, const struct file_operations *fops, + bpctl_dev_t *dev) { - strcpy(pfs_unit_curr->proc_name, proc_name); - pfs_unit_curr->proc_entry = create_proc_entry(pfs_unit_curr->proc_name, - S_IFREG | S_IRUSR | - S_IWUSR | S_IRGRP | - S_IROTH, parent_pfs); - if (pfs_unit_curr->proc_entry == NULL) + struct bypass_pfs_sd *pfs = &dev->bypass_pfs_set; + if (!proc_create_data(proc_name, 0644, pfs->bypass_entry, fops, dev)) return -1; - - pfs_unit_curr->proc_entry->read_proc = read_proc; - pfs_unit_curr->proc_entry->write_proc = write_proc; - pfs_unit_curr->proc_entry->data = data; - return 0; - } -int -get_bypass_info_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - int len = 0; - - len += sprintf(page, "Name\t\t\t%s\n", pbp_device_block->name); - len += - sprintf(page + len, "Firmware version\t0x%x\n", - pbp_device_block->bp_fw_ver); +#define RO_FOPS(name) \ +static int name##_open(struct inode *inode, struct file *file) \ +{ \ + return single_open(file, show_##name, PDE_DATA(inode));\ +} \ +static const struct file_operations name##_ops = { \ + .open = name##_open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ +}; - *eof = 1; - return len; -} +#define RW_FOPS(name) \ +static int name##_open(struct inode *inode, struct file *file) \ +{ \ + return single_open(file, show_##name, PDE_DATA(inode));\ +} \ +static const struct file_operations name##_ops = { \ + .open = name##_open, \ + .read = seq_read, \ + .write = name##_write, \ + .llseek = seq_lseek, \ + .release = single_release, \ +}; -int -get_bypass_slave_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_bypass_info(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; + bpctl_dev_t *dev = m->private; - int len = 0; - bpctl_dev_t *pbp_device_block_slave = NULL; - int idx_dev = 0; - struct net_device *net_slave_dev = NULL; - - if ((pbp_device_block->func == 0) || (pbp_device_block->func == 2)) { - for (idx_dev = 0; - ((bpctl_dev_arr[idx_dev].pdev != NULL) - && (idx_dev < device_num)); idx_dev++) { - if ((bpctl_dev_arr[idx_dev].bus == - pbp_device_block->bus) - && (bpctl_dev_arr[idx_dev].slot == - pbp_device_block->slot)) { - if ((pbp_device_block->func == 0) - && (bpctl_dev_arr[idx_dev].func == 1)) { - pbp_device_block_slave = - &bpctl_dev_arr[idx_dev]; - break; - } - if ((pbp_device_block->func == 2) && - (bpctl_dev_arr[idx_dev].func == 3)) { - pbp_device_block_slave = - &bpctl_dev_arr[idx_dev]; - break; - } - } - } - } else - pbp_device_block_slave = pbp_device_block; - if (!pbp_device_block_slave) { - len = sprintf(page, "fail\n"); - *eof = 1; - return len; - } - net_slave_dev = pbp_device_block_slave->ndev; - if (net_slave_dev) - len = sprintf(page, "%s\n", net_slave_dev->name); - - *eof = 1; - return len; + seq_printf(m, "Name\t\t\t%s\n", dev->name); + seq_printf(m, "Firmware version\t0x%x\n", dev->bp_fw_ver); + return 0; } +RO_FOPS(bypass_info) -int -get_bypass_caps_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_bypass_slave(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; + bpctl_dev_t *dev = m->private; + bpctl_dev_t *slave = get_status_port_fn(dev); + if (!slave) + slave = dev; + if (!slave) + seq_printf(m, "fail\n"); + else if (slave->ndev) + seq_printf(m, "%s\n", slave->ndev->name); + return 0; +} +RO_FOPS(bypass_slave) - ret = get_bypass_caps_fn(pbp_device_block); +static int show_bypass_caps(struct seq_file *m, void *v) +{ + bpctl_dev_t *dev = m->private; + int ret = get_bypass_caps_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "-1\n"); + seq_printf(m, "-1\n"); else - len = sprintf(page, "0x%x\n", ret); - *eof = 1; - return len; - + seq_printf(m, "0x%x\n", ret); + return 0; } +RO_FOPS(bypass_caps) -int -get_wd_set_caps_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_wd_set_caps(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_wd_set_caps_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_wd_set_caps_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "-1\n"); + seq_printf(m, "-1\n"); else - len = sprintf(page, "0x%x\n", ret); - *eof = 1; - return len; + seq_printf(m, "0x%x\n", ret); + return 0; } +RO_FOPS(wd_set_caps) -int -set_bypass_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static int user_on_off(const void __user *buffer, size_t count) { char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; + int length = 0; if (count > (sizeof(kbuf) - 1)) return -1; - if (copy_from_user(&kbuf, buffer, count)) { + if (copy_from_user(&kbuf, buffer, count)) return -1; - } kbuf[count] = '\0'; length = strlen(kbuf); @@ -7562,806 +7312,467 @@ set_bypass_pfs(struct file *file, const char *buffer, kbuf[--length] = '\0'; if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_bypass_fn(pbp_device_block, bypass_param); - - return count; + return 1; + if (strcmp(kbuf, "off") == 0) + return 0; + return 0; } -int -set_tap_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t bypass_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) + int bypass_param = user_on_off(buffer, count); + if (bypass_param < 0) return -1; - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_tap_fn(pbp_device_block, tap_param); - + set_bypass_fn(PDE_DATA(file_inode(file)), bypass_param); return count; } - -int -set_disc_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static int show_bypass(struct seq_file *m, void *v) { + bpctl_dev_t *dev = m->private; + int ret = get_bypass_fn(dev); + if (ret == BP_NOT_CAP) + seq_printf(m, "fail\n"); + else if (ret == 1) + seq_printf(m, "on\n"); + else if (ret == 0) + seq_printf(m, "off\n"); + return 0; +} +RW_FOPS(bypass) - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) { +static ssize_t tap_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) +{ + int tap_param = user_on_off(buffer, count); + if (tap_param < 0) return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_disc_fn(pbp_device_block, tap_param); + set_tap_fn(PDE_DATA(file_inode(file)), tap_param); return count; } - -int -get_bypass_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_tap(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_tap_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; + seq_printf(m, "off\n"); + return 0; } +RW_FOPS(tap) -int -get_tap_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static ssize_t disc_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_tap_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 1) - len = sprintf(page, "on\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); + int tap_param = user_on_off(buffer, count); + if (tap_param < 0) + return -1; - *eof = 1; - return len; + set_disc_fn(PDE_DATA(file_inode(file)), tap_param); + return count; } - -int -get_disc_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_disc(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_disc_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_disc_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; + seq_printf(m, "off\n"); + return 0; } +RW_FOPS(disc) -int -get_bypass_change_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_bypass_change(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_change_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_bypass_change_fn(dev); if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; + seq_printf(m, "fail\n"); + return 0; } +RO_FOPS(bypass_change) -int -get_tap_change_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_tap_change(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_tap_change_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_tap_change_fn(dev); if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; + seq_printf(m, "fail\n"); + return 0; } +RO_FOPS(tap_change) -int -get_disc_change_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_disc_change(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_disc_change_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_disc_change_fn(dev); if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; -} - -#define isdigit(c) (c >= '0' && c <= '9') -__inline static int atoi(char **s) -{ - int i = 0; - while (isdigit(**s)) - i = i * 10 + *((*s)++) - '0'; - return i; + seq_printf(m, "fail\n"); + return 0; } +RO_FOPS(disc_change) -int -set_bypass_wd_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t bypass_wd_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; + bpctl_dev_t *dev = PDE_DATA(file_inode(file)); int timeout; - int ret; - - ret = kstrtoint_from_user(buffer, count, 10, &timeout); + int ret = kstrtoint_from_user(buffer, count, 10, &timeout); if (ret) return ret; - set_bypass_wd_fn(pbp_device_block, timeout); - + set_bypass_wd_fn(dev, timeout); return count; } - -int -get_bypass_wd_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_bypass_wd(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; + bpctl_dev_t *dev = m->private; + int ret = 0, timeout = 0; - int len = 0, ret = 0, timeout = 0; - - ret = get_bypass_wd_fn(pbp_device_block, &timeout); + ret = get_bypass_wd_fn(dev, &timeout); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (timeout == -1) - len = sprintf(page, "unknown\n"); + seq_printf(m, "unknown\n"); else if (timeout == 0) - len = sprintf(page, "disable\n"); + seq_printf(m, "disable\n"); else - len = sprintf(page, "%d\n", timeout); - - *eof = 1; - return len; + seq_printf(m, "%d\n", timeout); + return 0; } +RW_FOPS(bypass_wd) -int -get_wd_expire_time_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_wd_expire_time(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0, timeout = 0; - - ret = get_wd_expire_time_fn(pbp_device_block, &timeout); + bpctl_dev_t *dev = m->private; + int ret = 0, timeout = 0; + ret = get_wd_expire_time_fn(dev, &timeout); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (timeout == -1) - len = sprintf(page, "expire\n"); + seq_printf(m, "expire\n"); else if (timeout == 0) - len = sprintf(page, "disable\n"); - + seq_printf(m, "disable\n"); else - len = sprintf(page, "%d\n", timeout); - *eof = 1; - return len; + seq_printf(m, "%d\n", timeout); + return 0; } +RO_FOPS(wd_expire_time) -int -get_tpl_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static ssize_t tpl_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; + bpctl_dev_t *dev = PDE_DATA(file_inode(file)); + int tpl_param = user_on_off(buffer, count); + if (tpl_param < 0) + return -1; - ret = get_tpl_fn(pbp_device_block); + set_tpl_fn(dev, tpl_param); + return count; +} +static int show_tpl(struct seq_file *m, void *v) +{ + bpctl_dev_t *dev = m->private; + int ret = get_tpl_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; + seq_printf(m, "off\n"); + return 0; } +RW_FOPS(tpl) #ifdef PMC_FIX_FLAG -int -get_wait_at_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static ssize_t wait_at_pwup_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; + bpctl_dev_t *dev = PDE_DATA(file_inode(file)); + int tpl_param = user_on_off(buffer, count); + if (tpl_param < 0) + return -1; - ret = get_bp_wait_at_pwup_fn(pbp_device_block); + set_bp_wait_at_pwup_fn(dev, tpl_param); + return count; +} +static int show_wait_at_pwup(struct seq_file *m, void *v) +{ + bpctl_dev_t *dev = m->private; + int ret = get_bp_wait_at_pwup_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; + seq_printf(m, "off\n"); + return 0; } +RW_FOPS(wait_at_pwup) -int -get_hw_reset_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static ssize_t hw_reset_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; + bpctl_dev_t *dev = PDE_DATA(file_inode(file)); + int tpl_param = user_on_off(buffer, count); + if (tpl_param < 0) + return -1; - ret = get_bp_hw_reset_fn(pbp_device_block); + set_bp_hw_reset_fn(dev, tpl_param); + return count; +} +static int show_hw_reset(struct seq_file *m, void *v) +{ + bpctl_dev_t *dev = m->private; + int ret = get_bp_hw_reset_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 1) - len = sprintf(page, "on\n"); + seq_printf(m, "on\n"); else if (ret == 0) - len = sprintf(page, "off\n"); - - *eof = 1; - return len; + seq_printf(m, "off\n"); + return 0; } +RW_FOPS(hw_reset) #endif /*PMC_WAIT_FLAG */ -int -reset_bypass_wd_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_reset_bypass_wd(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = reset_bypass_wd_timer_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = reset_bypass_wd_timer_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 0) - len = sprintf(page, "disable\n"); + seq_printf(m, "disable\n"); else if (ret == 1) - len = sprintf(page, "success\n"); - - *eof = 1; - return len; + seq_printf(m, "success\n"); + return 0; } +RO_FOPS(reset_bypass_wd) -int -set_dis_bypass_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t dis_bypass_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (count >= sizeof(kbuf)) + int bypass_param = user_on_off(buffer, count); + if (bypass_param < 0) return -EINVAL; - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_dis_bypass_fn(pbp_device_block, bypass_param); - + set_dis_bypass_fn(PDE_DATA(file_inode(file)), bypass_param); return count; } - -int -set_dis_tap_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static int show_dis_bypass(struct seq_file *m, void *v) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count >= sizeof(kbuf)) - return -EINVAL; - - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_dis_tap_fn(pbp_device_block, tap_param); - - return count; + bpctl_dev_t *dev = m->private; + int ret = get_dis_bypass_fn(dev); + if (ret == BP_NOT_CAP) + seq_printf(m, "fail\n"); + else if (ret == 0) + seq_printf(m, "off\n"); + else + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(dis_bypass) -int -set_dis_disc_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t dis_tap_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count >= sizeof(kbuf)) + int tap_param = user_on_off(buffer, count); + if (tap_param < 0) return -EINVAL; - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_dis_disc_fn(pbp_device_block, tap_param); - + set_dis_tap_fn(PDE_DATA(file_inode(file)), tap_param); return count; } - -int -get_dis_bypass_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_dis_tap(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_dis_bypass_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_dis_tap_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(dis_tap) -int -get_dis_tap_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static ssize_t dis_disc_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_dis_tap_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); + int tap_param = user_on_off(buffer, count); + if (tap_param < 0) + return -EINVAL; - *eof = 1; - return len; + set_dis_disc_fn(PDE_DATA(file_inode(file)), tap_param); + return count; } - -int -get_dis_disc_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_dis_disc(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_dis_disc_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_dis_disc_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -set_bypass_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (count >= sizeof(kbuf)) - return -EINVAL; - - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_bypass_pwup_fn(pbp_device_block, bypass_param); - - return count; + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(dis_disc) -int -set_bypass_pwoff_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t bypass_pwup_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (count >= sizeof(kbuf)) + int bypass_param = user_on_off(buffer, count); + if (bypass_param < 0) return -EINVAL; - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_bypass_pwoff_fn(pbp_device_block, bypass_param); - + set_bypass_pwup_fn(PDE_DATA(file_inode(file)), bypass_param); return count; } - -int -set_tap_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static int show_bypass_pwup(struct seq_file *m, void *v) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count >= sizeof(kbuf)) - return -EINVAL; - - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_tap_pwup_fn(pbp_device_block, tap_param); - - return count; + bpctl_dev_t *dev = m->private; + int ret = get_bypass_pwup_fn(dev); + if (ret == BP_NOT_CAP) + seq_printf(m, "fail\n"); + else if (ret == 0) + seq_printf(m, "off\n"); + else + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(bypass_pwup) -int -set_disc_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t bypass_pwoff_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tap_param = 0, length = 0; - - if (count >= sizeof(kbuf)) + int bypass_param = user_on_off(buffer, count); + if (bypass_param < 0) return -EINVAL; - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tap_param = 1; - else if (strcmp(kbuf, "off") == 0) - tap_param = 0; - - set_disc_pwup_fn(pbp_device_block, tap_param); - + set_bypass_pwoff_fn(PDE_DATA(file_inode(file)), bypass_param); return count; } - -int -get_bypass_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_bypass_pwoff(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_pwup_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_bypass_pwoff_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(bypass_pwoff) -int -get_bypass_pwoff_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static ssize_t tap_pwup_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_bypass_pwoff_fn(pbp_device_block); - if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); - else if (ret == 0) - len = sprintf(page, "off\n"); - else - len = sprintf(page, "on\n"); + int tap_param = user_on_off(buffer, count); + if (tap_param < 0) + return -EINVAL; - *eof = 1; - return len; + set_tap_pwup_fn(PDE_DATA(file_inode(file)), tap_param); + return count; } - -int -get_tap_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_tap_pwup(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_tap_pwup_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_tap_pwup_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(tap_pwup) -int -get_disc_pwup_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static ssize_t disc_pwup_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; + int tap_param = user_on_off(buffer, count); + if (tap_param < 0) + return -EINVAL; - ret = get_disc_pwup_fn(pbp_device_block); + set_disc_pwup_fn(PDE_DATA(file_inode(file)), tap_param); + return count; +} +static int show_disc_pwup(struct seq_file *m, void *v) +{ + bpctl_dev_t *dev = m->private; + int ret = get_disc_pwup_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(disc_pwup) -int -set_std_nic_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t std_nic_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int bypass_param = 0, length = 0; - - if (count >= sizeof(kbuf)) + int bypass_param = user_on_off(buffer, count); + if (bypass_param < 0) return -EINVAL; - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - bypass_param = 1; - else if (strcmp(kbuf, "off") == 0) - bypass_param = 0; - - set_std_nic_fn(pbp_device_block, bypass_param); - + set_std_nic_fn(PDE_DATA(file_inode(file)), bypass_param); return count; } - -int -get_std_nic_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_std_nic(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_std_nic_fn(pbp_device_block); + bpctl_dev_t *dev = m->private; + int ret = get_std_nic_fn(dev); if (ret == BP_NOT_CAP) - len = sprintf(page, "fail\n"); + seq_printf(m, "fail\n"); else if (ret == 0) - len = sprintf(page, "off\n"); + seq_printf(m, "off\n"); else - len = sprintf(page, "on\n"); - - *eof = 1; - return len; -} - -int -get_wd_exp_mode_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) -{ - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_wd_exp_mode_fn(pbp_device_block); - if (ret == 1) - len = sprintf(page, "tap\n"); - else if (ret == 0) - len = sprintf(page, "bypass\n"); - else if (ret == 2) - len = sprintf(page, "disc\n"); - - else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; + seq_printf(m, "on\n"); + return 0; } +RW_FOPS(std_nic) -int -set_wd_exp_mode_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t wd_exp_mode_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - int bypass_param = 0, length = 0; if (count > (sizeof(kbuf) - 1)) return -1; - if (copy_from_user(&kbuf, buffer, count)) { + if (copy_from_user(&kbuf, buffer, count)) return -1; - } kbuf[count] = '\0'; length = strlen(kbuf); @@ -8375,143 +7786,47 @@ set_wd_exp_mode_pfs(struct file *file, const char *buffer, else if (strcmp(kbuf, "disc") == 0) bypass_param = 2; - set_wd_exp_mode_fn(pbp_device_block, bypass_param); + set_wd_exp_mode_fn(PDE_DATA(file_inode(file)), bypass_param); return count; } - -int -get_wd_autoreset_pfs(char *page, char **start, off_t off, int count, - int *eof, void *data) +static int show_wd_exp_mode(struct seq_file *m, void *v) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int len = 0, ret = 0; - - ret = get_wd_autoreset_fn(pbp_device_block); - if (ret >= 0) - len = sprintf(page, "%d\n", ret); + bpctl_dev_t *dev = m->private; + int ret = get_wd_exp_mode_fn(dev); + if (ret == 1) + seq_printf(m, "tap\n"); + else if (ret == 0) + seq_printf(m, "bypass\n"); + else if (ret == 2) + seq_printf(m, "disc\n"); else - len = sprintf(page, "fail\n"); - - *eof = 1; - return len; + seq_printf(m, "fail\n"); + return 0; } +RW_FOPS(wd_exp_mode) -int -set_wd_autoreset_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t wd_autoreset_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; int timeout; - int ret; - - ret = kstrtoint_from_user(buffer, count, 10, &timeout); + int ret = kstrtoint_from_user(buffer, count, 10, &timeout); if (ret) return ret; - set_wd_autoreset_fn(pbp_device_block, timeout); - - return count; -} - -int -set_tpl_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tpl_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tpl_param = 1; - else if (strcmp(kbuf, "off") == 0) - tpl_param = 0; - - set_tpl_fn(pbp_device_block, tpl_param); - + set_wd_autoreset_fn(PDE_DATA(file_inode(file)), timeout); return count; } - -#ifdef PMC_FIX_FLAG -int -set_wait_at_pwup_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) -{ - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tpl_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tpl_param = 1; - else if (strcmp(kbuf, "off") == 0) - tpl_param = 0; - - set_bp_wait_at_pwup_fn(pbp_device_block, tpl_param); - - return count; -} - -int -set_hw_reset_pfs(struct file *file, const char *buffer, - unsigned long count, void *data) +static int show_wd_autoreset(struct seq_file *m, void *v) { - - char kbuf[256]; - bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data; - - int tpl_param = 0, length = 0; - - if (count > (sizeof(kbuf) - 1)) - return -1; - - if (copy_from_user(&kbuf, buffer, count)) { - return -1; - } - - kbuf[count] = '\0'; - length = strlen(kbuf); - if (kbuf[length - 1] == '\n') - kbuf[--length] = '\0'; - - if (strcmp(kbuf, "on") == 0) - tpl_param = 1; - else if (strcmp(kbuf, "off") == 0) - tpl_param = 0; - - set_bp_hw_reset_fn(pbp_device_block, tpl_param); - - return count; + bpctl_dev_t *dev = m->private; + int ret = get_wd_autoreset_fn(dev); + if (ret >= 0) + seq_printf(m, "%d\n", ret); + else + seq_printf(m, "fail\n"); + return 0; } - -#endif /*PMC_FIX_FLAG */ +RW_FOPS(wd_autoreset) int bypass_proc_create_dev_sd(bpctl_dev_t *pbp_device_block) { @@ -8528,168 +7843,54 @@ int bypass_proc_create_dev_sd(bpctl_dev_t *pbp_device_block) return -1; /* create device proc dir */ - procfs_dir = proc_getdir(current_pfs->dir_name, bp_procfs_dir); - if (procfs_dir == 0) { + procfs_dir = proc_mkdir(current_pfs->dir_name, bp_procfs_dir); + if (!procfs_dir) { printk(KERN_DEBUG "Could not create procfs directory %s\n", current_pfs->dir_name); return -1; } current_pfs->bypass_entry = procfs_dir; - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_info), BYPASS_INFO_ENTRY_SD, NULL, /* write */ - get_bypass_info_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - +#define ENTRY(x) ret |= procfs_add(#x, &x##_ops, pbp_device_block) + ENTRY(bypass_info); if (pbp_device_block->bp_caps & SW_CTL_CAP) { - /* Create set param proc's */ - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_slave), BYPASS_SLAVE_ENTRY_SD, NULL, /* write */ - get_bypass_slave_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_caps), BYPASS_CAPS_ENTRY_SD, NULL, /* write */ - get_bypass_caps_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->wd_set_caps), WD_SET_CAPS_ENTRY_SD, NULL, /* write */ - get_wd_set_caps_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_wd), BYPASS_WD_ENTRY_SD, set_bypass_wd_pfs, /* write */ - get_bypass_wd_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->wd_expire_time), WD_EXPIRE_TIME_ENTRY_SD, NULL, /* write */ - get_wd_expire_time_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->reset_bypass_wd), RESET_BYPASS_WD_ENTRY_SD, NULL, /* write */ - reset_bypass_wd_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->std_nic), STD_NIC_ENTRY_SD, set_std_nic_pfs, /* write */ - get_std_nic_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - + ENTRY(bypass_slave); + ENTRY(bypass_caps); + ENTRY(wd_set_caps); + ENTRY(bypass_wd); + ENTRY(wd_expire_time); + ENTRY(reset_bypass_wd); + ENTRY(std_nic); if (pbp_device_block->bp_caps & BP_CAP) { - if (bypass_proc_create_entry_sd(&(current_pfs->bypass), BYPASS_ENTRY_SD, set_bypass_pfs, /* write */ - get_bypass_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->dis_bypass), DIS_BYPASS_ENTRY_SD, set_dis_bypass_pfs, /* write */ - get_dis_bypass_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_pwup), BYPASS_PWUP_ENTRY_SD, set_bypass_pwup_pfs, /* write */ - get_bypass_pwup_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_pwoff), BYPASS_PWOFF_ENTRY_SD, set_bypass_pwoff_pfs, /* write */ - get_bypass_pwoff_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->bypass_change), BYPASS_CHANGE_ENTRY_SD, NULL, /* write */ - get_bypass_change_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; + ENTRY(bypass); + ENTRY(dis_bypass); + ENTRY(bypass_pwup); + ENTRY(bypass_pwoff); + ENTRY(bypass_change); } - if (pbp_device_block->bp_caps & TAP_CAP) { - - if (bypass_proc_create_entry_sd(&(current_pfs->tap), TAP_ENTRY_SD, set_tap_pfs, /* write */ - get_tap_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->dis_tap), DIS_TAP_ENTRY_SD, set_dis_tap_pfs, /* write */ - get_dis_tap_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_pwup), TAP_PWUP_ENTRY_SD, set_tap_pwup_pfs, /* write */ - get_tap_pwup_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_change), TAP_CHANGE_ENTRY_SD, NULL, /* write */ - get_tap_change_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; + ENTRY(tap); + ENTRY(dis_tap); + ENTRY(tap_pwup); + ENTRY(tap_change); } if (pbp_device_block->bp_caps & DISC_CAP) { - - if (bypass_proc_create_entry_sd(&(current_pfs->tap), DISC_ENTRY_SD, set_disc_pfs, /* write */ - get_disc_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; -#if 1 - - if (bypass_proc_create_entry_sd(&(current_pfs->dis_tap), DIS_DISC_ENTRY_SD, set_dis_disc_pfs, /* write */ - get_dis_disc_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; -#endif - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_pwup), DISC_PWUP_ENTRY_SD, set_disc_pwup_pfs, /* write */ - get_disc_pwup_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->tap_change), DISC_CHANGE_ENTRY_SD, NULL, /* write */ - get_disc_change_pfs, /* read */ - procfs_dir, - pbp_device_block)) - ret = -1; + ENTRY(disc); + ENTRY(dis_disc); + ENTRY(disc_pwup); + ENTRY(disc_change); } - if (bypass_proc_create_entry_sd(&(current_pfs->wd_exp_mode), WD_EXP_MODE_ENTRY_SD, set_wd_exp_mode_pfs, /* write */ - get_wd_exp_mode_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - - if (bypass_proc_create_entry_sd(&(current_pfs->wd_autoreset), WD_AUTORESET_ENTRY_SD, set_wd_autoreset_pfs, /* write */ - get_wd_autoreset_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->tpl), TPL_ENTRY_SD, set_tpl_pfs, /* write */ - get_tpl_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; + ENTRY(wd_exp_mode); + ENTRY(wd_autoreset); + ENTRY(tpl); #ifdef PMC_FIX_FLAG - if (bypass_proc_create_entry_sd(&(current_pfs->tpl), WAIT_AT_PWUP_ENTRY_SD, set_wait_at_pwup_pfs, /* write */ - get_wait_at_pwup_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - if (bypass_proc_create_entry_sd(&(current_pfs->tpl), HW_RESET_ENTRY_SD, set_hw_reset_pfs, /* write */ - get_hw_reset_pfs, /* read */ - procfs_dir, pbp_device_block)) - ret = -1; - + ENTRY(wait_at_pwup); + ENTRY(hw_reset); #endif - } +#undef ENTRY if (ret < 0) printk(KERN_DEBUG "Create proc entry failed\n"); @@ -8700,21 +7901,7 @@ int bypass_proc_remove_dev_sd(bpctl_dev_t *pbp_device_block) { struct bypass_pfs_sd *current_pfs = &pbp_device_block->bypass_pfs_set; - struct proc_dir_entry *pde = current_pfs->bypass_entry, *pde_curr = - NULL; - char name[256]; - - if (!pde) - return 0; - for (pde = pde->subdir; pde;) { - strcpy(name, pde->name); - pde_curr = pde; - pde = pde->next; - remove_proc_entry(name, current_pfs->bypass_entry); - } - if (!pde) - remove_proc_entry(current_pfs->dir_name, bp_procfs_dir); + remove_proc_subtree(current_pfs->dir_name, bp_procfs_dir); current_pfs->bypass_entry = NULL; - return 0; } |