]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c
staging: ft1000: Remove unused variable.
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / ft1000 / ft1000-usb / ft1000_chdev.c
index 87a6487531c2262e95357fac2987bc62a5d18e96..4e5c8a3bc8887071c5f5e079a598b40f3a372bbe 100644 (file)
@@ -37,7 +37,7 @@
 #include <linux/kmod.h>
 #include <linux/ioctl.h>
 #include <linux/unistd.h>
-
+#include <linux/debugfs.h>
 #include "ft1000_usb.h"
 //#include "ft1000_ioctl.h"
 
@@ -51,10 +51,6 @@ static long ft1000_ChIoctl(struct file *File, unsigned int Command,
                            unsigned long Argument);
 static int ft1000_ChRelease (struct inode *Inode, struct file *File);
 
-// Global pointer to device object
-static struct ft1000_device *pdevobj[MAX_NUM_CARDS + 2];
-//static devfs_handle_t ft1000Handle[MAX_NUM_CARDS];
-
 // List to free receive command buffer pool
 struct list_head freercvpool;
 
@@ -64,7 +60,7 @@ spinlock_t free_buff_lock;
 int numofmsgbuf = 0;
 
 // Global variable to indicate that all provisioning data is sent to DSP
-//BOOLEAN fProvComplete;
+//bool fProvComplete;
 
 //
 // Table of entry-point routines for char device
@@ -78,88 +74,6 @@ static struct file_operations ft1000fops =
        .llseek         = no_llseek,
 };
 
-
-
-
-//---------------------------------------------------------------------------
-// Function:    exec_mknod
-//
-// Parameters:
-//
-// Returns:
-//
-// Description:
-//
-// Notes:
-//
-//---------------------------------------------------------------------------
-static int exec_mknod (void *pdata)
-{
-       struct ft1000_info *info;
-    char mjnum[4];
-    char minornum[4];
-    char temp[32];
-    int retcode;
-//    int i;                                   //aelias [-] reason : unused variable
-    char *envp[] = { "HOME=/", "PATH=/usr/bin:/bin", NULL };
-    char *argv[]={"-m 666",temp,"c",mjnum,minornum,NULL};
-
-    info = pdata;
-    DEBUG("ft1000_chdev:exec_mknod is called with major number = %d\n", info->DeviceMajor);
-    sprintf(temp, "%s%s", "/dev/", info->DeviceName) ;
-    sprintf(mjnum, "%d", info->DeviceMajor);
-    sprintf(minornum, "%d", info->CardNumber);
-
-    //char *argv[]={"mknod","-m 666",temp,"c",mjnum,minornum,NULL};
-//    char *argv[]={"-m 666",temp,"c",mjnum,minornum,NULL};
-
-    //for (i=0; i<7;i++)
-    //    DEBUG("argv[%d]=%s\n", i, argv[i]);
-
-
-    retcode = call_usermodehelper ("/bin/mknod", argv, envp, 1);
-    if (retcode) {
-        DEBUG("ft1000_chdev:exec_mknod failed to make the node: retcode = %d\n", retcode);
-    }
-
-
-
-    return retcode;
-
-}
-
-//---------------------------------------------------------------------------
-// Function:    rm_mknod
-//
-// Description: This module removes the FT1000 device file
-//
-//---------------------------------------------------------------------------
-static int rm_mknod (void *pdata)
-{
-
-       struct ft1000_info *info;
-    //char *argv[4]={"rm", "-f", "/dev/FT1000", NULL};
-    int retcode;
-    char temp[32];
-    char *argv[]={"rm", "-f", temp, NULL};
-
-       info = (struct ft1000_info *)pdata;
-    DEBUG("ft1000_chdev:rm_mknod is called for device %s\n", info->DeviceName);
-    sprintf(temp, "%s%s", "/dev/", info->DeviceName) ;
-
-//    char *argv[]={"rm", "-f", temp, NULL};
-
-    retcode = call_usermodehelper ("/bin/rm", argv, NULL, 1);
-    if (retcode) {
-        DEBUG("ft1000_chdev:rm_mknod failed to remove the node: retcode = %d\n", retcode);
-    }
-    else
-        DEBUG("ft1000_chdev:rm_mknod done!\n");
-
-
-    return retcode;
-
-}
 //---------------------------------------------------------------------------
 // Function:    ft1000_get_buffer
 //
@@ -238,23 +152,15 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
        struct ft1000_info *info = netdev_priv(dev->net);
     int result;
     int i;
-    pid_t pid;
+       struct dentry *dir, *file;
+       struct ft1000_debug_dirs *tmp;
 
     // make a new device name
-    sprintf(info->DeviceName, "%s%d", "FT100", info->CardNumber);
-
-    // Delete any existing FT1000 node
-    pid = kernel_thread (rm_mknod,(void *)info, 0);
-    msleep(1000);
+    sprintf(info->DeviceName, "%s%d", "FT1000_", info->CardNumber);
 
     DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt);
     DEBUG("DeviceCreated = %x\n", info->DeviceCreated);
 
-    //save the device info to global array
-    pdevobj[info->CardNumber] = dev;
-
-    DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%p\n", info->CardNumber, pdevobj[info->CardNumber]);   //aelias [+] reason:up
-
     if (info->DeviceCreated)
     {
        DEBUG("ft1000_CreateDevice: \"%s\" already registered\n", info->DeviceName);
@@ -264,29 +170,34 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
 
     // register the device
     DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName);
-    info->DeviceMajor = 0;
 
-    result = register_chrdev(info->DeviceMajor, info->DeviceName, &ft1000fops);
-    if (result < 0)
-    {
-       DEBUG("ft1000_CreateDevice: unable to get major %d\n", info->DeviceMajor);
-       return result;
-    }
+       tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL);
+       if (tmp == NULL) {
+               result = -1;
+               goto fail;
+       }
 
-    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
-    if (info->DeviceMajor == 0)
-    {
-       info->DeviceMajor = result;
-       DEBUG("ft1000_PcdCreateDevice: device major = %d\n", info->DeviceMajor);
-    }
+       file = debugfs_create_file("device", S_IRUGO | S_IWUGO, dir,
+                                       NULL, &ft1000fops);
+       if (IS_ERR(file)) {
+               result = PTR_ERR(file);
+               goto debug_file_fail;
+       }
 
-    // Create a thread to call user mode app to mknod
-    pid = kernel_thread (exec_mknod, (void *)info, 0);
+       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
-    info->appcnt = 0;
 
 //    if (ft1000_flarion_cnt == 0) {
 //
@@ -334,7 +245,14 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
     info->DeviceCreated = TRUE;
     ft1000_flarion_cnt++;
 
-    return result;
+       return 0;
+
+debug_file_fail:
+       debugfs_remove(dir);
+debug_dir_fail:
+       kfree(tmp);
+fail:
+       return result;
 }
 
 //---------------------------------------------------------------------------
@@ -350,11 +268,11 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
 void ft1000_DestroyDevice(struct net_device *dev)
 {
        struct ft1000_info *info = netdev_priv(dev);
-    int result = 0;
-    pid_t pid;
                int i;
        struct dpram_blk *pdpram_blk;
        struct dpram_blk *ptr;
+       struct list_head *pos, *q;
+       struct ft1000_debug_dirs *dir;
 
     DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n");
 
@@ -363,11 +281,17 @@ void ft1000_DestroyDevice(struct net_device *dev)
     if (info->DeviceCreated)
        {
         ft1000_flarion_cnt--;
-               unregister_chrdev(info->DeviceMajor, info->DeviceName);
-               DEBUG("ft1000_DestroyDevice: unregistered device \"%s\", result = %d\n",
-                                          info->DeviceName, result);
-
-       pid = kernel_thread (rm_mknod, (void *)info, 0);
+               list_for_each_safe(pos, q, &info->nodes.list) {
+                       dir = list_entry(pos, struct ft1000_debug_dirs, list);
+                       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
         for (i=0; i<MAX_NUM_APP; i++) {
@@ -393,8 +317,6 @@ void ft1000_DestroyDevice(struct net_device *dev)
 //        devfs_unregister(ft1000Handle[info->CardNumber]);
 
                info->DeviceCreated = FALSE;
-
-               pdevobj[info->CardNumber] = NULL;
        }
 
 
@@ -413,23 +335,14 @@ void ft1000_DestroyDevice(struct net_device *dev)
 static int ft1000_ChOpen (struct inode *Inode, struct file *File)
 {
        struct ft1000_info *info;
+       struct ft1000_device *dev = (struct ft1000_device *)Inode->i_private;
     int i,num;
 
     DEBUG("ft1000_ChOpen called\n");
     num = (MINOR(Inode->i_rdev) & 0xf);
     DEBUG("ft1000_ChOpen: minor number=%d\n", num);
 
-    for (i=0; i<5; i++)
-        DEBUG("pdevobj[%d]=%p\n", i, pdevobj[i]); //aelias [+] reason: down
-
-    if ( pdevobj[num] != NULL )
-        //info = (struct ft1000_info *)(pdevobj[num]->net->priv);
-               info = (struct ft1000_info *)netdev_priv(pdevobj[num]->net);
-    else
-    {
-        DEBUG("ft1000_ChOpen: can not find device object %d\n", num);
-        return -1;
-    }
+       info = File->private_data = netdev_priv(dev->net);
 
     DEBUG("f_owner = %p number of application = %d\n", (&File->f_owner), info->appcnt );
 
@@ -459,8 +372,6 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
     info->app_info[i].nTxMsgReject = 0;
     info->app_info[i].nRxMsgMiss = 0;
 
-    File->private_data = pdevobj[num]->net;
-
        nonseekable_open(Inode, File);
     return 0;
 }
@@ -489,7 +400,7 @@ static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
         return (-EBADF);
     }
 
-       info = (struct ft1000_info *) netdev_priv(dev);
+       info = netdev_priv(dev);
 
     // Search for matching file object
     for (i=0; i<MAX_NUM_APP; i++) {
@@ -561,7 +472,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
     //DEBUG("FT1000:ft1000_ChIoctl:Command = 0x%x Argument = 0x%8x\n", Command, (u32)Argument);
 
     dev = File->private_data;
-       info = (struct ft1000_info *) netdev_priv(dev);
+       info = netdev_priv(dev);
     ft1000dev = info->pFt1000Dev;
     cmd = _IOC_NR(Command);
     //DEBUG("FT1000:ft1000_ChIoctl:cmd = 0x%x\n", cmd);
@@ -623,10 +534,10 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
         memcpy(get_stat_data.eui64, info->eui64, EUISZ);
 
             if (info->ProgConStat != 0xFF) {
-                ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (PUCHAR)&ledStat, FT1000_MAG_DSP_LED_INDX);
+                ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
                 get_stat_data.LedStat = ntohs(ledStat);
                 DEBUG("FT1000:ft1000_ChIoctl: LedStat = 0x%x\n", get_stat_data.LedStat);
-                ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (PUCHAR)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
+                ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
                 get_stat_data.ConStat = ntohs(conStat);
                 DEBUG("FT1000:ft1000_ChIoctl: ConStat = 0x%x\n", get_stat_data.ConStat);
             }
@@ -651,14 +562,14 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
         break;
     case IOCTL_SET_DPRAM_CMD:
         {
-            IOCTL_DPRAM_BLK *dpram_data;
+            IOCTL_DPRAM_BLK *dpram_data = NULL;
             //IOCTL_DPRAM_COMMAND dpram_command;
-            USHORT qtype;
-            USHORT msgsz;
+            u16 qtype;
+            u16 msgsz;
                struct pseudo_hdr *ppseudo_hdr;
-            PUSHORT pmsg;
-            USHORT total_len;
-            USHORT app_index;
+            u16 *pmsg;
+            u16 total_len;
+            u16 app_index;
             u16 status;
 
             //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_SET_DPRAM called\n");
@@ -699,7 +610,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                        break;
 
                 //if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
-                if ( copy_from_user(&dpram_data, argp, msgsz+2) ) {
+                if ( copy_from_user(dpram_data, argp, msgsz+2) ) {
                     DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
                     result = -EFAULT;
                 }
@@ -766,8 +677,8 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
                         // Make sure we are within the limits of the slow queue memory limitation
                         if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) {
                             // Need to put sequence number plus new checksum for message
-                            //pmsg = (PUSHORT)&dpram_command.dpram_blk.pseudohdr;
-                            pmsg = (PUSHORT)&dpram_data->pseudohdr;
+                            //pmsg = (u16 *)&dpram_command.dpram_blk.pseudohdr;
+                            pmsg = (u16 *)&dpram_data->pseudohdr;
                                ppseudo_hdr = (struct pseudo_hdr *)pmsg;
                             total_len = msgsz+2;
                             if (total_len & 0x1) {
@@ -901,7 +812,7 @@ static int ft1000_ChRelease (struct inode *Inode, struct file *File)
     DEBUG("ft1000_ChRelease called\n");
 
     dev = File->private_data;
-       info = (struct ft1000_info *) netdev_priv(dev);
+       info = netdev_priv(dev);
 
     if (ft1000_flarion_cnt == 0) {
         info->appcnt--;