Commit 9119dee1 authored by Marek Belisko's avatar Marek Belisko Committed by Greg Kroah-Hartman

staging: ft1000: Convert char device to debugfs.

Character device was used only for debugging purposes.
Convert it to debugfs functionality. For every plugged device
create new directory with one file.
Signed-off-by: default avatarMarek Belisko <marek.belisko@open-nandra.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 372058f1
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <linux/kmod.h> #include <linux/kmod.h>
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <linux/unistd.h> #include <linux/unistd.h>
#include <linux/debugfs.h>
#include "ft1000_usb.h" #include "ft1000_usb.h"
//#include "ft1000_ioctl.h" //#include "ft1000_ioctl.h"
...@@ -156,9 +156,11 @@ int ft1000_CreateDevice(struct ft1000_device *dev) ...@@ -156,9 +156,11 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
struct ft1000_info *info = netdev_priv(dev->net); struct ft1000_info *info = netdev_priv(dev->net);
int result; int result;
int i; int i;
struct dentry *dir, *file;
struct ft1000_debug_dirs *tmp;
// make a new device name // make a new device name
sprintf(info->DeviceName, "%s%d", "FT100", info->CardNumber); sprintf(info->DeviceName, "%s%d", "FT1000_", info->CardNumber);
DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt); DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt);
DEBUG("DeviceCreated = %x\n", info->DeviceCreated); DEBUG("DeviceCreated = %x\n", info->DeviceCreated);
...@@ -179,21 +181,31 @@ int ft1000_CreateDevice(struct ft1000_device *dev) ...@@ -179,21 +181,31 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName); DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName);
info->DeviceMajor = 0; info->DeviceMajor = 0;
result = register_chrdev(info->DeviceMajor, info->DeviceName, &ft1000fops); tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL);
if (result < 0) if (tmp == NULL) {
{ result = -1;
DEBUG("ft1000_CreateDevice: unable to get major %d\n", info->DeviceMajor); goto fail;
return result; }
}
DEBUG("ft1000_CreateDevice: registered char device \"%s\"\n", info->DeviceName); dir = debugfs_create_dir(info->DeviceName, 0);
if (IS_ERR(dir)) {
result = PTR_ERR(dir);
goto debug_dir_fail;
}
// save a dynamic device major number file = debugfs_create_file("device", S_IRUGO | S_IWUGO, dir,
if (info->DeviceMajor == 0) NULL, &ft1000fops);
{ if (IS_ERR(file)) {
info->DeviceMajor = result; result = PTR_ERR(file);
DEBUG("ft1000_PcdCreateDevice: device major = %d\n", info->DeviceMajor); goto debug_file_fail;
} }
tmp->dent = dir;
tmp->file = file;
tmp->int_number = info->CardNumber;
list_add(&(tmp->list), &(info->nodes.list));
DEBUG("ft1000_CreateDevice: registered char device \"%s\"\n", info->DeviceName);
// initialize application information // initialize application information
...@@ -243,7 +255,14 @@ int ft1000_CreateDevice(struct ft1000_device *dev) ...@@ -243,7 +255,14 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
info->DeviceCreated = TRUE; info->DeviceCreated = TRUE;
ft1000_flarion_cnt++; ft1000_flarion_cnt++;
return result; return 0;
debug_file_fail:
debugfs_remove(dir);
debug_dir_fail:
kfree(tmp);
fail:
return result;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -259,10 +278,11 @@ int ft1000_CreateDevice(struct ft1000_device *dev) ...@@ -259,10 +278,11 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
void ft1000_DestroyDevice(struct net_device *dev) void ft1000_DestroyDevice(struct net_device *dev)
{ {
struct ft1000_info *info = netdev_priv(dev); struct ft1000_info *info = netdev_priv(dev);
int result = 0;
int i; int i;
struct dpram_blk *pdpram_blk; struct dpram_blk *pdpram_blk;
struct dpram_blk *ptr; struct dpram_blk *ptr;
struct list_head *pos, *q;
struct ft1000_debug_dirs *dir;
DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n"); DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n");
...@@ -271,9 +291,17 @@ void ft1000_DestroyDevice(struct net_device *dev) ...@@ -271,9 +291,17 @@ void ft1000_DestroyDevice(struct net_device *dev)
if (info->DeviceCreated) if (info->DeviceCreated)
{ {
ft1000_flarion_cnt--; ft1000_flarion_cnt--;
unregister_chrdev(info->DeviceMajor, info->DeviceName); list_for_each_safe(pos, q, &info->nodes.list) {
DEBUG("ft1000_DestroyDevice: unregistered device \"%s\", result = %d\n", dir = list_entry(pos, struct ft1000_debug_dirs, list);
info->DeviceName, result); if (dir->int_number == info->CardNumber) {
debugfs_remove(dir->file);
debugfs_remove(dir->dent);
list_del(pos);
kfree(dir);
}
}
DEBUG("ft1000_DestroyDevice: unregistered device \"%s\"\n",
info->DeviceName);
// Make sure we free any memory reserve for slow Queue // Make sure we free any memory reserve for slow Queue
for (i=0; i<MAX_NUM_APP; i++) { for (i=0; i<MAX_NUM_APP; i++) {
......
...@@ -851,6 +851,7 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev) ...@@ -851,6 +851,7 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
INIT_LIST_HEAD(&pInfo->prov_list); INIT_LIST_HEAD(&pInfo->prov_list);
INIT_LIST_HEAD(&pInfo->nodes.list);
//mbelian //mbelian
#ifdef HAVE_NET_DEVICE_OPS #ifdef HAVE_NET_DEVICE_OPS
netdev->netdev_ops = &ftnet_ops; netdev->netdev_ops = &ftnet_ops;
......
...@@ -473,6 +473,13 @@ struct ft1000_device ...@@ -473,6 +473,13 @@ struct ft1000_device
// struct net_device_stats stats; //mbelian // struct net_device_stats stats; //mbelian
} __attribute__ ((packed)); } __attribute__ ((packed));
struct ft1000_debug_dirs {
struct list_head list;
struct dentry *dent;
struct dentry *file;
int int_number;
};
struct ft1000_info { struct ft1000_info {
struct ft1000_device *pFt1000Dev; struct ft1000_device *pFt1000Dev;
struct net_device_stats stats; struct net_device_stats stats;
...@@ -508,6 +515,7 @@ struct ft1000_info { ...@@ -508,6 +515,7 @@ struct ft1000_info {
u8 CardNumber; u8 CardNumber;
u8 DeviceName[15]; u8 DeviceName[15];
int DeviceMajor; int DeviceMajor;
struct ft1000_debug_dirs nodes;
int registered; int registered;
int mediastate; int mediastate;
int dhcpflg; int dhcpflg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment