]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
Merge: Separated normal read and RTR assisted read transfer.
authorppisa <pisa@cmp.felk.cvut.cz>
Thu, 25 Nov 2004 20:45:00 +0000 (21:45 +0100)
committerppisa <pisa@cmp.felk.cvut.cz>
Thu, 25 Nov 2004 20:45:00 +0000 (21:45 +0100)
Merge commit 'remotes/sf-ocera-lincan/master'

lincan/include/can.h
lincan/include/ioctl.h
lincan/src/Makefile.omk
lincan/src/Makefile.std
lincan/src/ioctl.c
lincan/src/ioctl_remote.c [new file with mode: 0644]
lincan/src/read.c
lincan/src/write.c

index 8a9368443a2c1dc404578dd98dfb3e28d4304681..b3b265ce141c7eb96e47a4e56cafe06c73346ccc 100644 (file)
@@ -77,6 +77,7 @@ struct can_baudparams_t {
 #define CANQUE_FILTER _IOW(CAN_IOC_MAGIC, 10, struct canfilt_t)
 #define CANQUE_FLUSH  _IO(CAN_IOC_MAGIC, 11)
 #define CONF_BAUDPARAMS  _IOW(CAN_IOC_MAGIC, 11, struct can_baudparams_t)
+#define CANRTR_READ  _IOWR(CAN_IOC_MAGIC, 12, struct canmsg_t)
 
 #ifdef __cplusplus
 } /* extern "C"*/
index e1e3acf9d1ae75c9309495a0d493b06c193e233e..e780c289477cdc1727aa401d3601d71aa448804e 100644 (file)
@@ -9,3 +9,5 @@
 
 int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
 int can_ioctl_query(struct canuser_t *canuser, unsigned long what);
+int can_ioctl_remote_read(struct canuser_t *canuser, struct canmsg_t *rtr_msg,
+                          unsigned long rtr_id, int options);
index 863cfdc81936bebaac35c335e59ee2ba5cd3493b..fe1bfa97b3da86598bdc6739c641e41752d2b4a1 100644 (file)
@@ -43,6 +43,7 @@ lincan_SOURCES = can_queue.c can_quekern.c main.c modparms.c \
                devcommon.c setup.c finish.c irq.c boardlist.c \
                sja1000p.c sja1000.c i82527.c  \
                open.c close.c read.c write.c ioctl.c select.c fasync.c \
-               proc.c ioctl_query.c $(lincan_cards_SOURCES) $(lincan_rtl_SOURCES)
+               proc.c ioctl_query.c ioctl_remote.c \
+               $(lincan_cards_SOURCES) $(lincan_rtl_SOURCES)
                
 endif #CONFIG_OC_LINCAN
index 7d04da305a8cebd042930a711ad06e54c9a6d344..c70ce4c6bdaac244030e7c97689baf8a14d0feea 100644 (file)
@@ -142,7 +142,7 @@ O_OBJS       += can_queue.o can_quekern.o devcommon.o main.o modparms.o \
                setup.o finish.o irq.o boardlist.o \
                sja1000p.o sja1000.o i82527.o  \
                open.o proc.o close.o write.o read.o \
-               ioctl.o ioctl_query.o select.o fasync.o
+               ioctl.o ioctl_query.o ioctl_remote.o select.o fasync.o
 # Objects with exported symbols (-DEXPORT_SYMTAB)
 OX_OBJS      = 
 # Module objects 
index 6edca99e5ea2c1e65ca4269770ee31dd09eb95cd..63aaea10188e1495f1024a8787c60d916d82b38a 100644 (file)
@@ -84,6 +84,16 @@ int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned
                        }
                        break;
                }
+               
+               case CANRTR_READ: {
+                       int ret;
+                       struct canmsg_t rtr_msg;
+                       
+                       copy_from_user(&rtr_msg, (void*)arg, sizeof(struct canmsg_t));
+                       ret = can_ioctl_remote_read(canuser, &rtr_msg, rtr_msg.id, 0);
+                       if(ret<0) return ret;
+                       copy_to_user((void*)arg, &rtr_msg, sizeof(struct canmsg_t));
+               }
 
                case CONF_BAUD: {
                        channel = arg & 0xff;
diff --git a/lincan/src/ioctl_remote.c b/lincan/src/ioctl_remote.c
new file mode 100644 (file)
index 0000000..68f3670
--- /dev/null
@@ -0,0 +1,93 @@
+/* ioctl_remote.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 lincan-0.3  17 Nov 2004
+ */
+
+#include "../include/can.h"
+#include "../include/can_sysdep.h"
+#include "../include/main.h"
+#include "../include/read.h"
+#include "../include/ioctl.h"
+
+/* This is the 'RTR' read handler for remote transmission request messages */
+int can_ioctl_remote_read(struct canuser_t *canuser, struct canmsg_t *rtr_msg,
+                          unsigned long rtr_id, int options)
+{
+       can_spin_irqflags_t flags;
+       struct rtr_id *rtr_current, *new_rtr_entry;
+       struct msgobj_t *obj;
+       struct canchip_t *chip;
+       /*struct canque_ends_t *qends;*/
+       
+       DEBUGMSG("Remote transmission request\n");
+
+       /*qends = canuser->qends;*/
+
+       /* Initialize hardware pointers */
+       obj = canuser->msgobj;
+       if (obj == NULL) {
+               CANMSG("Could not assign buffer structure\n");
+               return -ENODEV;
+       }
+
+       if ( (chip = obj->hostchip) == NULL) {
+               CANMSG("Device is not correctly configured,\n");
+               CANMSG("please reload the driver.\n");
+               return -ENODEV;
+       }
+
+       can_spin_lock_irqsave(&hardware_p->rtr_lock, flags);
+       if (hardware_p->rtr_queue == NULL) { //No remote messages pending
+               new_rtr_entry=(struct rtr_id *)kmalloc(sizeof(struct rtr_id),GFP_ATOMIC);
+               if (new_rtr_entry == NULL) {
+                       can_spin_unlock_irqrestore(&hardware_p->rtr_lock, 
+                                                               flags);
+                       return -ENOMEM;
+               }
+               hardware_p->rtr_queue=new_rtr_entry;
+       }
+       else {
+               rtr_current=hardware_p->rtr_queue;
+               while (rtr_current->next != NULL)
+                       rtr_current=rtr_current->next;
+               new_rtr_entry=(struct rtr_id *)kmalloc(sizeof(struct rtr_id),GFP_ATOMIC);
+               rtr_current->next=new_rtr_entry;
+       }
+       init_waitqueue_head(&new_rtr_entry->rtr_wq);
+       new_rtr_entry->id = rtr_id;
+       new_rtr_entry->rtr_message = rtr_msg;
+       new_rtr_entry->next=NULL;
+
+       can_spin_unlock_irqrestore(&hardware_p->rtr_lock, flags);
+
+       /* Send remote transmission request */
+       chip->chipspecops->remote_request(chip,obj);
+       obj->ret = 0;
+       interruptible_sleep_on(&new_rtr_entry->rtr_wq);
+
+       can_spin_lock_irqsave(&hardware_p->rtr_lock, flags);
+       if (hardware_p->rtr_queue == new_rtr_entry) {
+               if (new_rtr_entry->next != NULL) 
+                       hardware_p->rtr_queue=new_rtr_entry->next;
+               else
+                       hardware_p->rtr_queue=NULL;
+       }
+       else {
+               rtr_current=hardware_p->rtr_queue;
+               while (rtr_current->next != new_rtr_entry)
+                       rtr_current=rtr_current->next;
+               if (new_rtr_entry->next != NULL)
+                       rtr_current->next=new_rtr_entry->next;
+               else
+                       rtr_current->next=NULL;
+       }
+       can_spin_unlock_irqrestore(&hardware_p->rtr_lock, flags);
+       kfree(new_rtr_entry);
+
+       return obj->ret;
+}
+
index 384bf1b27295adfc8a323f4f1529993e55ef752b..c16c76b5a723a1870f7fdf85c77b47b74fbf697f 100644 (file)
 #include "../include/can_sysdep.h"
 #include "../include/main.h"
 #include "../include/read.h"
-#include "../include/ioctl.h"
 
 /* This is the 'Normal' read handler for normal transmission messages */
-inline ssize_t can_std_read(struct file *file, struct canque_ends_t *qends, 
-                       struct msgobj_t *obj, char *buffer, size_t length)
+ssize_t can_read(struct file *file, char *buffer, size_t length, loff_t *offset)
 {
-       int ret;
+       struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
+       struct canque_ends_t *qends;
        int bytes_to_copy;
        struct canque_edge_t *qedge;
        struct canque_slot_t *slot;
-       
+       int ret;
+
+       if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
+               CANMSG("can_read: bad canuser magic\n");
+               return -ENODEV;
+       }
+
+       if (length < sizeof(struct canmsg_t)) {
+               DEBUGMSG("Trying to read less bytes than a CAN message, \n");
+               DEBUGMSG("this will always return zero.\n");
+               return 0;
+       }
+
+       qends = canuser->qends;
+
        ret=canque_test_outslot(qends, &qedge, &slot);
        if(ret<0){
                if (file->f_flags & O_NONBLOCK) {
@@ -59,111 +72,3 @@ inline ssize_t can_std_read(struct file *file, struct canque_ends_t *qends,
        return length-bytes_to_copy;
 }
 
-/* This is the 'RTR' read handler for remote transmission request messages */
-inline ssize_t can_rtr_read(struct canchip_t *chip, struct msgobj_t *obj, 
-                                                               char *buffer)
-{
-       can_spin_irqflags_t flags;
-       struct rtr_id *rtr_current, *new_rtr_entry;
-       struct canmsg_t read_msg;
-       
-       DEBUGMSG("Remote transmission request\n");
-
-       copy_from_user(&read_msg, buffer, sizeof(struct canmsg_t));
-
-       can_spin_lock_irqsave(&hardware_p->rtr_lock, flags);
-       if (hardware_p->rtr_queue == NULL) { //No remote messages pending
-               new_rtr_entry=(struct rtr_id *)kmalloc(sizeof(struct rtr_id),GFP_ATOMIC);
-               if (new_rtr_entry == NULL) {
-                       can_spin_unlock_irqrestore(&hardware_p->rtr_lock, 
-                                                               flags);
-                       return -ENOMEM;
-               }
-               hardware_p->rtr_queue=new_rtr_entry;
-       }
-       else {
-               rtr_current=hardware_p->rtr_queue;
-               while (rtr_current->next != NULL)
-                       rtr_current=rtr_current->next;
-               new_rtr_entry=(struct rtr_id *)kmalloc(sizeof(struct rtr_id),GFP_ATOMIC);
-               rtr_current->next=new_rtr_entry;
-       }
-       init_waitqueue_head(&new_rtr_entry->rtr_wq);
-       new_rtr_entry->id = read_msg.id;
-       new_rtr_entry->rtr_message = &read_msg;
-       new_rtr_entry->next=NULL;
-
-       can_spin_unlock_irqrestore(&hardware_p->rtr_lock, flags);
-
-       /* Send remote transmission request */
-       chip->chipspecops->remote_request(chip,obj);
-       obj->ret = 0;
-       interruptible_sleep_on(&new_rtr_entry->rtr_wq);
-
-       can_spin_lock_irqsave(&hardware_p->rtr_lock, flags);
-       if (hardware_p->rtr_queue == new_rtr_entry) {
-               if (new_rtr_entry->next != NULL) 
-                       hardware_p->rtr_queue=new_rtr_entry->next;
-               else
-                       hardware_p->rtr_queue=NULL;
-       }
-       else {
-               rtr_current=hardware_p->rtr_queue;
-               while (rtr_current->next != new_rtr_entry)
-                       rtr_current=rtr_current->next;
-               if (new_rtr_entry->next != NULL)
-                       rtr_current->next=new_rtr_entry->next;
-               else
-                       rtr_current->next=NULL;
-       }
-       can_spin_unlock_irqrestore(&hardware_p->rtr_lock, flags);
-       kfree(new_rtr_entry);
-
-       copy_to_user(buffer, &read_msg, sizeof(struct canmsg_t));
-
-       return obj->ret;
-}
-
-ssize_t can_read(struct file *file, char *buffer, size_t length, loff_t *offset)
-{
-       struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
-       struct msgobj_t *obj;
-       struct canchip_t *chip;
-       struct canmsg_t read_msg;
-       struct canque_ends_t *qends;
-       int ret=0;
-
-       if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
-               CANMSG("can_read: bad canuser magic\n");
-               return -ENODEV;
-       }
-
-       if (length < sizeof(struct canmsg_t)) {
-               DEBUGMSG("Trying to read less bytes than a CAN message, \n");
-               DEBUGMSG("this will always return zero.\n");
-               return 0;
-       }
-       /* Initialize hardware pointers */
-       obj = canuser->msgobj;
-       if (obj == NULL) {
-               CANMSG("Could not assign buffer structure\n");
-               return -1;
-       }
-       qends = canuser->qends;
-       if ( (chip = obj->hostchip) == NULL) {
-               CANMSG("Device is not correctly configured,\n");
-               CANMSG("please reload the driver.\n");
-               return -1;
-       }
-
-       copy_from_user(&read_msg, buffer, sizeof(struct canmsg_t));
-       if (read_msg.flags & MSG_RTR)
-               /* FIXME: RTR processing should go to its own IOCTLs */
-               ret = can_rtr_read(chip, obj, buffer);
-       else
-               ret = can_std_read(file, qends, obj, buffer, length);
-
-       return ret;
-}
-
-
index 6ef80ee1a960bf560c7c63218646037044871b79..dccade1edbfc1a0e5eb88ebadb8d668752669d0d 100644 (file)
@@ -10,6 +10,7 @@
 #include "../include/can.h"
 #include "../include/can_sysdep.h"
 #include "../include/main.h"
+#include "../include/write.h"
 
 ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *offset)
 {