]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/include/usbcan.h
USB LinCAN support reworked to use lists instead of arrays.
[lincan.git] / lincan / include / usbcan.h
index b01a6275d0d6a953a9b3f7049462f55efa4d135b..f29f9b8062bfcf14a47b15ca10e4134f98aff3c2 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/uaccess.h>
 #include <linux/usb.h>
 #include <linux/mutex.h>
+#include <linux/wait.h>
 
 #include "../include/kthread.h"
 
@@ -27,8 +28,8 @@
 /* arbitrarily chosen */
 
 /* Define these values to match your devices */
-#define USBCAN_VENDOR_ID       0xDEAD
-#define USBCAN_PRODUCT_ID      0x1001
+#define USBCAN_VENDOR_ID       0x1669
+#define USBCAN_PRODUCT_ID      0x1011
 
 #define RESET_ADDR 0x0
 
@@ -66,7 +67,7 @@ int usbcan_irq_handler(int irq, struct canchip_t *chip);
 int usbcan_init(void);
 void usbcan_exit(void);
 
-int usbcan_read_kthread(void *data);
+int usbcan_kthread(void *data);
 int usbcan_chip_queue_status(struct canchip_t *chip);
 
 #ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS
@@ -115,57 +116,64 @@ int usbcan_chip_queue_status(struct canchip_t *chip);
 
 #endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/
 
+struct usbcan_usb;
+
+#define USBCAN_TOT_RX_URBS 8
+#define USBCAN_TOT_TX_URBS 8
+
+#define USBCAN_TRANSFER_SIZE 16
+
 struct usbcan_message {
        struct urb      *u;
-       u8      msg[16];
-       spinlock_t              acc;            /* access lock */
-       long    flags;
+       struct usbcan_usb *dev;
+       u8      msg[USBCAN_TRANSFER_SIZE];
+       struct canque_edge_t *qedge;
+       struct canque_slot_t *slot;
+       struct list_head list_node;
+       volatile long   flags;
 };
 
-#define USBCAN_MESSAGE_FREE (1)
-#define USBCAN_MESSAGE_READY_TO_SEND (2)
-#define USBCAN_MESSAGE_SENDING                 (3)
-#define USBCAN_MESSAGE_TERMINATE               (4)
-#define USBCAN_MESSAGE_ERROR                           (5)
-#define USBCAN_MESSAGE_DATA_READ               (6)
-
-#define USBCAN_TOT_RX_URBS 8
-#define USBCAN_TOT_TX_URBS 8
+#define USBCAN_MESSAGE_FREE                            (1)
+#define USBCAN_MESSAGE_URB_PENDING                     (2)
+#define USBCAN_MESSAGE_TERMINATE                       (3)
+#define USBCAN_MESSAGE_ERROR                           (4)
+#define USBCAN_MESSAGE_DATA_OK                         (5)
+#define USBCAN_MESSAGE_TYPE_RX                         (6)
+#define USBCAN_MESSAGE_TYPE_TX                         (7)
 
 /* Structure to hold all of our device specific stuff */
 struct usbcan_usb {
        struct usb_device       *udev;                  /* the usb device for this device */
        struct usb_interface    *interface;             /* the interface for this device */
-       struct semaphore        limit_sem;              /* limiting the number of writes in progress */
-       struct usb_anchor       submitted;              /* in case we need to retract our submissions */
        unsigned char           *bulk_in_buffer;        /* the buffer to receive data */
-       unsigned char           *ctl_in_buffer; /* the buffer to receive data */
        size_t                  bulk_in_size;           /* the size of the receive buffer */
-       size_t                  ctl_in_size;            /* the size of the receive buffer */
-       u8                      ctl_in_endpointAddr;    /* the address of the bulk in endpoint */
-       u8                      ctl_out_endpointAddr;   /* the address of the bulk in endpoint */
        u8                      bulk_in_endpointAddr;   /* the address of the bulk in endpoint */
        u8                      bulk_out_endpointAddr;  /* the address of the bulk out endpoint */
-       int                     errors;                 /* the last request tanked */
-       int                     open_count;             /* count the number of openers */
-       spinlock_t              err_lock;               /* lock for errors */
        struct mutex            io_mutex;               /* synchronize I/O with disconnect */
-       struct urb              *rx;
-       struct urb              *tx;
-       u8      rx_msg[16];
-       u8      tx_msg[16];
 
-       struct task_struct *comthread;                      /* usb communication kernel thread  */
+       struct list_head        rx_pend_list;           /* URBs waiting for data receive */
+       struct list_head        rx_ready_list;          /* URBs with valid received data */
+       struct list_head        tx_idle_list;           /* URBs prepared to hold Tx messages */
+       struct list_head        tx_pend_list;           /* URBs holding Tx messages in progress */
+       struct list_head        tx_ready_list;          /* URBs with yet confirmed Tx messages */
 
+       spinlock_t              list_lock;                      /* list lock */
 
-       struct candevice_t *candev;
-       long flags;
+       struct task_struct *comthread;                  /* usb communication kernel thread  */
+       wait_queue_head_t queue;
+
+       struct canchip_t *chip;
+       volatile long flags;
 };
 
-#define USBCAN_DATA_READ               (1)
-#define USBCAN_TERMINATE               (2)
-#define USBCAN_ERROR                           (3)
-#define USBCAN_TX_PENDING              (4)
+#define USBCAN_DATA_OK                         (1)
+#define USBCAN_DATA_RX                         (2)
+#define USBCAN_DATA_TX                         (3)
+#define USBCAN_TERMINATE                       (4)
+#define USBCAN_ERROR                                   (5)
+#define USBCAN_TX_PENDING                      (6)
+#define USBCAN_THREAD_RUNNING  (7)
+#define USBCAN_FREE_TX_URB             (8)
 
 #define USBCAN_VENDOR_BAUD_RATE_SET    (1)
 #define USBCAN_VENDOR_BAUD_RATE_STATUS (2)
@@ -176,5 +184,11 @@ struct usbcan_usb {
 #define USBCAN_VENDOR_EXT_MASK_SET     (7)
 #define USBCAN_VENDOR_EXT_MASK_STATUS  (8)
 
+struct usbcan_devs {
+       struct usbcan_usb **devs;
+       int     count;
+       struct candevice_t *candev;
+};
+
 
 #endif /*USBCAN_H*/