]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/proc.c
CAN driver infrastructure redesign to LinCAN-0.2 version
[lincan.git] / lincan / src / proc.c
index 79309e0e35affbe900df17959b6da583c85438fe..fb573be8cdfb99fdddeeda94810a9f5d376b8911 100644 (file)
@@ -1,25 +1,20 @@
 /* proc.c
  * Linux CAN-bus device driver.
  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
+ * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
+ * email:pisa@cmp.felk.cvut.cz
  * This software is released under the GPL-License.
- * Version 0.7  6 Aug 2001
+ * Version lincan-0.2  9 Jul 2003
  */ 
 
 #define __NO_VERSION__
 #include <linux/module.h>
 
 #include <linux/autoconf.h>
-#if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)
-#define MODVERSIONS
-#endif
-
-#if defined (MODVERSIONS)
-#include <linux/modversions.h>
-#endif
 
 #include <linux/version.h>
 #include <linux/kernel.h>
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
 #include <linux/malloc.h>
 #else
 #include <linux/slab.h>
 #include "../include/proc.h"
 #include "../include/setup.h"
 
-int add_channel_to_procdir(void);
+int add_channel_to_procdir(struct candevice_t *candev);
 int remove_channel_from_procdir(void);
-int add_object_to_procdir(void);
+int add_object_to_procdir(int chip_nr);
 int remove_object_from_procdir(void);
 
 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
 static int candev_readlink(struct proc_dir_entry *de, char *page);
 #endif
 
-static int bc=0; /* static counter for each hardware board */
 static int cc=0; /* static counter for each CAN chip */
-static int oc=0; /* static counter for each message object */
 
 struct canproc_t can_proc_base;
 struct canproc_t *base=&can_proc_base;
@@ -101,6 +94,8 @@ int can_remove_proc_entry(struct proc_dir_entry *del, struct proc_dir_entry *par
  */
 int can_init_procdir(void)
 {
+       int board;
+       struct candevice_t *candev;
 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
        base->can_proc_entry = new_can_proc_entry(0, "can", S_IFDIR | S_IRUGO | 
                                        S_IXUGO, 0, &proc_root);
@@ -111,8 +106,9 @@ int can_init_procdir(void)
        if (base->can_proc_entry == NULL)
                return -ENODEV;
 
-       for (bc=0; bc<hardware_p->nr_boards; bc++) {
-               add_channel_to_procdir();
+       for (board=0; board<hardware_p->nr_boards; board++) {
+               candev=hardware_p->candevice[board];
+               if(candev) add_channel_to_procdir(candev);
        } 
 
        return 0;
@@ -133,12 +129,11 @@ int can_delete_procdir(void)
        return 0;
 }
 
-int add_channel_to_procdir(void)
+int add_channel_to_procdir(struct candevice_t *candev)
 {
        int i=0;
 
-       for (i=0; i < candevices_p[bc]->nr_82527_chips + 
-                       candevices_p[bc]->nr_sja1000_chips; i++) {
+       for (i=0; i < candev->nr_all_chips; i++) {
 
                base->channel[cc] = (struct channelproc_t *)
                        kmalloc(sizeof(struct channelproc_t), GFP_KERNEL);
@@ -163,7 +158,7 @@ int add_channel_to_procdir(void)
                if (base->channel[cc]->ch_entry == NULL)
                        return -ENODEV;
 
-               add_object_to_procdir();
+               add_object_to_procdir(cc);
 
                cc++;
        } 
@@ -192,60 +187,56 @@ int remove_channel_from_procdir(void)
 }
 
 
-int add_object_to_procdir(void)
+int add_object_to_procdir(int chip_nr)
 {
-       int i=0, obj=0;
+       int i, max_objects;
 
-       if (!strcmp(chips_p[cc]->chip_type,"i82527"))
-               obj=15;
-       if (!strcmp(chips_p[cc]->chip_type,"sja1000"))
-               obj=1;
+       max_objects=chips_p[chip_nr]->max_objects;
 
-       for (i=0; i<obj; i++) {
-               oc=i;
-               base->channel[cc]->object[i] = (struct objectproc_t *)
+       for (i=0; i<max_objects; i++) {
+               base->channel[chip_nr]->object[i] = (struct objectproc_t *)
                        kmalloc(sizeof(struct objectproc_t),GFP_KERNEL);
                                
                                
-               if (base->channel[cc]->object[i] == NULL)
+               if (base->channel[chip_nr]->object[i] == NULL)
                        return -ENOMEM;
-               else if (add_mem_to_list( base->channel[cc]->object[i]))
+               else if (add_mem_to_list( base->channel[chip_nr]->object[i]))
                        return -ENOMEM;
 
-               sprintf(base->channel[cc]->object[i]->obj_name,"object%d",i);
-               sprintf(base->channel[cc]->object[i]->lnk_name,"dev");
+               sprintf(base->channel[chip_nr]->object[i]->obj_name,"object%d",i);
+               sprintf(base->channel[chip_nr]->object[i]->lnk_name,"dev");
                                                                
 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))
-               base->channel[cc]->object[i]->obj_entry=new_can_proc_entry(
-                               0, base->channel[cc]->object[i]->obj_name,
+               base->channel[chip_nr]->object[i]->obj_entry=new_can_proc_entry(
+                               0, base->channel[chip_nr]->object[i]->obj_name,
                                S_IFDIR | S_IRUGO | S_IXUGO, 0, 
-                               base->channel[cc]->ch_entry);
-               if (base->channel[cc]->object[i]->obj_entry == NULL)
+                               base->channel[chip_nr]->ch_entry);
+               if (base->channel[chip_nr]->object[i]->obj_entry == NULL)
                        return -ENODEV;
-               base->channel[cc]->object[i]->lnk = new_can_proc_entry(
-                               0, base->channel[cc]->object[i]->lnk_name, 
+               base->channel[chip_nr]->object[i]->lnk = new_can_proc_entry(
+                               0, base->channel[chip_nr]->object[i]->lnk_name, 
                                S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO,
-                               0, base->channel[cc]->object[i]->obj_entry);
-               if (base->channel[cc]->object[i]->lnk == NULL)
+                               0, base->channel[chip_nr]->object[i]->obj_entry);
+               if (base->channel[chip_nr]->object[i]->lnk == NULL)
                        return -ENODEV;
-               sprintf(base->channel[cc]->object[i]->lnk_dev,"/dev/can");
-               base->channel[cc]->object[i]->lnk->readlink_proc =
+               sprintf(base->channel[chip_nr]->object[i]->lnk_dev,"/dev/can");
+               base->channel[chip_nr]->object[i]->lnk->readlink_proc =
                                                                candev_readlink;
 
 #else
-               base->channel[cc]->object[i]->obj_entry = create_proc_entry(
-                               base->channel[cc]->object[i]->obj_name,
+               base->channel[chip_nr]->object[i]->obj_entry = create_proc_entry(
+                               base->channel[chip_nr]->object[i]->obj_name,
                                S_IFDIR | S_IRUGO | S_IXUGO,
-                               base->channel[cc]->ch_entry);
-               if (base->channel[cc]->object[i]->obj_entry == NULL)
+                               base->channel[chip_nr]->ch_entry);
+               if (base->channel[chip_nr]->object[i]->obj_entry == NULL)
                        return -ENODEV;
-               sprintf(base->channel[cc]->object[i]->lnk_dev,"/dev/can%d",
-                       chips_p[cc]->msgobj[i]->minor);
-               base->channel[cc]->object[i]->lnk = proc_symlink(
-                               base->channel[cc]->object[i]->lnk_name,
-                               base->channel[cc]->object[i]->obj_entry,
-                               base->channel[cc]->object[i]->lnk_dev);
-               if (base->channel[cc]->object[i]->lnk == NULL)
+               sprintf(base->channel[chip_nr]->object[i]->lnk_dev,"/dev/can%d",
+                       chips_p[chip_nr]->msgobj[i]->minor);
+               base->channel[chip_nr]->object[i]->lnk = proc_symlink(
+                               base->channel[chip_nr]->object[i]->lnk_name,
+                               base->channel[chip_nr]->object[i]->obj_entry,
+                               base->channel[chip_nr]->object[i]->lnk_dev);
+               if (base->channel[chip_nr]->object[i]->lnk == NULL)
                        return -ENODEV;
 #endif
 
@@ -257,10 +248,7 @@ int remove_object_from_procdir(void)
 {
        int i=0, obj=0;
 
-       if (!strcmp(chips_p[cc]->chip_type,"i82527"))
-               obj=15;
-       if (!strcmp(chips_p[cc]->chip_type,"sja1000"))
-               obj=1;
+       obj=chips_p[cc]->max_objects;
 
        for (i=0; i<obj; i++) {
 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0))