]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/finish.c
changed usb vendor and product id.
[lincan.git] / lincan / src / finish.c
index a5cd8d176413cf85b38595d07211a7a66cdc06e1..5e789ae4e56bb36881f5772727389ae9edd85c25 100644 (file)
@@ -1,3 +1,12 @@
+/* finish.c - finalization of the driver operation
+ * 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 Jun 2004
+ */
+
 #include "../include/can.h"
 #include "../include/can_sysdep.h"
 #include "../include/main.h"
 #include "../include/finish.h"
 #include "../include/setup.h"
 
-
-
+extern int next_minor;
+/**
+ * msgobj_done - destroys one CAN message object
+ * @obj: pointer to CAN message object structure
+ */
 void msgobj_done(struct msgobj_t *obj)
 {
+       int delayed=0;
        if(obj->qends) {
-               if(canqueue_ends_done_chip(obj->qends) < 0)
+               delayed=canqueue_ends_done_chip(obj->qends);
+               if(delayed < 0)
                        CANMSG("msgobj_done: problem with chip queue ends\n");
        }
 
@@ -18,32 +32,48 @@ void msgobj_done(struct msgobj_t *obj)
                if(obj->hostchip->msgobj[obj->object-1] == obj)
                        obj->hostchip->msgobj[obj->object-1]=NULL;
                else
-                       CANMSG("msgobj_done: not registered in the chip_t\n");
+                       CANMSG("msgobj_done: not registered in the canchip_t\n");
                obj->hostchip=NULL;
        }
-       
+
        if((obj->minor>=0)) {
-               if(objects_p[obj->minor] == obj)
+               if(objects_p[obj->minor] == obj){
                        objects_p[obj->minor] = NULL;
+                       if (--next_minor<0)
+                               next_minor=0;
+               }
                else
                        CANMSG("msgobj_done: not registered as minor\n");
        }
-       
+
        del_timer_sync(&obj->tx_timeout);
 
        if(obj->qends) {
-               can_checked_free(obj->qends);
+               /*delayed free could be required there in the future,
+                 actual use patter cannot generate such situation*/
+               if(!delayed) {
+                       can_checked_free(obj->qends);
+               }
        }
        obj->qends=NULL;
 }
 
 
-void canchip_done(struct chip_t *chip)
+/**
+ * canchip_done - destroys one CAN chip representation
+ * @chip: pointer to CAN chip structure
+ */
+void canchip_done(struct canchip_t *chip)
 {
 
        int i;
        struct msgobj_t *obj;
 
+       if(chip->flags & CHIP_ATTACHED){
+               chip->chipspecops->release_chip(chip);
+               chip->flags &= ~CHIP_ATTACHED;
+       }
+
        if((chip->hostdevice) && (chip->chip_idx>=0)) {
                if(chip->hostdevice->chip[chip->chip_idx] == chip)
                        chip->hostdevice->chip[chip->chip_idx] = NULL;
@@ -51,36 +81,37 @@ void canchip_done(struct chip_t *chip)
                        CANMSG("canchip_done: not registered in hostdevice\n");
        }
 
-       if((chip->flags & CHIP_IRQ_SETUP) && (chip->chip_irq>=0)) {
-               free_irq(chip->chip_irq, chip);
-               chip->flags &= ~CHIP_IRQ_SETUP;
-       }
-               
+       can_chip_free_irq(chip);
+
        can_synchronize_irq(chip->chip_irq);
-       
+
        for(i=0; i<chip->max_objects; i++){
                if((obj=chip->msgobj[i])==NULL)
                        continue;
                msgobj_done(obj);
                can_checked_free(obj);
        }
-       
+
        can_checked_free(chip->chipspecops);
        chip->chipspecops=NULL;
 
 }
 
+/**
+ * candevice_done - destroys representation of one CAN device/board
+ * @candev: pointer to CAN device/board structure
+ */
 void candevice_done(struct candevice_t *candev)
 {
        int i;
-       struct chip_t *chip;
-       
+       struct canchip_t *chip;
+
        for(i=0; i<candev->nr_all_chips; i++){
                if((chip=candev->chip[i])==NULL)
                        continue;
                canchip_done(chip);
                can_checked_free(chip);
-       
+
        }
        if(candev->flags & CANDEV_IO_RESERVED) {
                candev->hwspecops->release_io(candev);
@@ -90,12 +121,16 @@ void candevice_done(struct candevice_t *candev)
        candev->hwspecops=NULL;
 }
 
+/**
+ * candevice_done - destroys representation of all CAN devices/boards
+ * @canhw: pointer to the root of all CAN hardware representation
+ */
 void canhardware_done(struct canhardware_t *canhw)
 {
        int i;
        struct candevice_t *candev;
-       
-       for(i=0; i<canhw->nr_boards; i++){
+
+       for(i=0; i<MAX_HW_CARDS; i++){
                if((candev=canhw->candevice[i])==NULL)
                        continue;
                candevice_done(candev);