]> Zhao Yanbai Git Server - minix.git/commitdiff
More endpoint descriptor data held by usb_storage
authorWojciech Zajac <wzajac@jpembedded.eu>
Mon, 23 Jun 2014 10:32:44 +0000 (12:32 +0200)
committerLionel Sambuc <lionel@minix3.org>
Mon, 28 Jul 2014 15:05:54 +0000 (17:05 +0200)
Makes usb_storage remember endpoint interval and other parameters, instead of endpoint number only.

drivers/usb_storage/urb_helper.c
drivers/usb_storage/urb_helper.h
drivers/usb_storage/usb_storage.c
drivers/usb_storage/usb_storage.h

index 0756087e3df0bf6cccc9bc88960c3120ad9cf60f..80d40f89cecd0a9975a56e6680d17014ebad41b2 100755 (executable)
  *===========================================================================*/
 void
 init_urb(struct ddekit_usb_urb * urb, struct ddekit_usb_dev * dev,
-       ddekit_int32_t urb_type, ddekit_int32_t urb_endpoint,
-       ddekit_int32_t urb_direction)
+       urb_ep_config * conf)
 {
        MASS_DEBUG_DUMP;
 
        /* Sanity checks */
        assert(NULL != urb);
        assert(NULL != dev);
-       assert((DDEKIT_USB_TRANSFER_BLK == urb_type) ||
-               (DDEKIT_USB_TRANSFER_CTL == urb_type) ||
-               (DDEKIT_USB_TRANSFER_INT == urb_type) ||
-               (DDEKIT_USB_TRANSFER_ISO == urb_type));
-       assert(urb_endpoint < 16);
-       assert((DDEKIT_USB_IN == urb_direction) ||
-               (DDEKIT_USB_OUT == urb_direction));
+       assert((DDEKIT_USB_TRANSFER_BLK == conf->type) ||
+               (DDEKIT_USB_TRANSFER_CTL == conf->type) ||
+               (DDEKIT_USB_TRANSFER_INT == conf->type) ||
+               (DDEKIT_USB_TRANSFER_ISO == conf->type));
+       assert((conf->ep_num >= 0) && (conf->ep_num < 16));
+       assert((DDEKIT_USB_IN == conf->direction) ||
+               (DDEKIT_USB_OUT == conf->direction));
 
        /* Clear block first */
        memset(urb, 0, sizeof(*urb));
 
        /* Set supplied values */
        urb->dev = dev;
-       urb->type = urb_type;
-       urb->endpoint = urb_endpoint;
-       urb->direction = urb_direction;
+       urb->type = conf->type;
+       urb->endpoint = conf->ep_num;
+       urb->direction = conf->direction;
+       urb->interval = conf->interval;
 }
 
 
index 59680526fb5bb1605c3e072167591a6237e639bc..700323ae6ce9eeace82ac5e099bcf1ba998630cc 100755 (executable)
 #define URB_SUBMIT_CHECK_LEN 0         /* return error on length mismatch */
 #define URB_SUBMIT_ALLOW_MISMATCH 1    /* ignore length check */
 
+/* Endpoint configuration related */
+#define URB_INVALID_EP (-1)            /* default for unset endpoint */
+
+/*---------------------------*
+ *    declared types         *
+ *---------------------------*
+/* URB's endpoint configuration */
+typedef struct urb_ep_config {
+
+       ddekit_int32_t ep_num;
+       ddekit_int32_t direction;
+       ddekit_int32_t type;
+       ddekit_int32_t max_packet_size;
+       ddekit_int32_t interval;
+}
+urb_ep_config;
+
 /*---------------------------*
  *    declared functions     *
  *---------------------------*/
-void init_urb(struct ddekit_usb_urb *, struct ddekit_usb_dev *, ddekit_int32_t,
-               ddekit_int32_t, ddekit_int32_t);
+void init_urb(struct ddekit_usb_urb *, struct ddekit_usb_dev *,
+               urb_ep_config *);
 void attach_urb_data(struct ddekit_usb_urb *, int, void *, ddekit_uint32_t);
 int blocking_urb_submit(struct ddekit_usb_urb *, ddekit_sem_t *, int);
 
index 0297082def360b316808ac2bc7a93527a78f389f..ca7b0cf793ccf8fda3ed9aa72bfd5a26bf108960 100755 (executable)
@@ -81,9 +81,11 @@ static void usb_driver_connect(struct ddekit_usb_dev *, unsigned int);
 static void usb_driver_disconnect(struct ddekit_usb_dev *);
 
 /* Simplified enumeration method for endpoint resolution */
-static int mass_storage_get_endpoints(int *, int *);
-static int mass_storage_parse_endpoint(usb_descriptor_t *, int *, int *);
-static int mass_storage_parse_descriptors(char *, unsigned int, int *, int *);
+static int mass_storage_get_endpoints(urb_ep_config *, urb_ep_config *);
+static int mass_storage_parse_endpoint(usb_descriptor_t *, urb_ep_config *,
+                                       urb_ep_config *);
+static int mass_storage_parse_descriptors(char *, unsigned int, urb_ep_config *,
+                                       urb_ep_config *);
 
 
 /*---------------------------*
@@ -220,8 +222,8 @@ mass_storage_send_scsi_cbw_out(int scsi_cmd, scsi_transfer * info)
        MASS_DEBUG_DUMP;
 
        /* Reset URB and assign given values */
-       init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK,
-               driver_state.cur_periph->ep_out, DDEKIT_USB_OUT);
+       init_urb(&urb, driver_state.cur_periph->dev,
+               &(driver_state.cur_periph->ep_out));
 
        /* Reset CBW and assign default values */
        init_cbw(&cbw, last_cbw_tag = current_cbw_tag++);
@@ -253,8 +255,8 @@ mass_storage_send_scsi_data_in(void * buf, unsigned int in_len)
        MASS_DEBUG_DUMP;
 
        /* Reset URB and assign given values */
-       init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK,
-               driver_state.cur_periph->ep_in, DDEKIT_USB_IN);
+       init_urb(&urb, driver_state.cur_periph->dev,
+               &(driver_state.cur_periph->ep_in));
 
        /* Attach buffer to URB */
        attach_urb_data(&urb, URB_BUF_TYPE_DATA, buf, in_len);
@@ -279,8 +281,8 @@ mass_storage_send_scsi_data_out(void * buf, unsigned int out_len)
        MASS_DEBUG_DUMP;
 
        /* Reset URB and assign given values */
-       init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK,
-               driver_state.cur_periph->ep_out, DDEKIT_USB_OUT);
+       init_urb(&urb, driver_state.cur_periph->dev,
+               &(driver_state.cur_periph->ep_out));
 
        /* Attach buffer to URB */
        attach_urb_data(&urb, URB_BUF_TYPE_DATA, buf, out_len);
@@ -308,8 +310,8 @@ mass_storage_send_scsi_csw_in(void)
        MASS_DEBUG_DUMP;
 
        /* Reset URB and assign given values */
-       init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK,
-               driver_state.cur_periph->ep_in, DDEKIT_USB_IN);
+       init_urb(&urb, driver_state.cur_periph->dev,
+               &(driver_state.cur_periph->ep_in));
 
        /* Clear CSW for receiving */
        init_csw(&csw);
@@ -340,11 +342,18 @@ mass_storage_send_bulk_reset(void)
        /* Setup buffer to be send */
        struct usb_ctrlrequest bulk_setup;
 
+       /* Control EP configuration */
+       urb_ep_config ep_conf;
+
        MASS_DEBUG_DUMP;
 
+       /* Initialize EP configuration */
+       ep_conf.ep_num = 0;
+       ep_conf.direction = DDEKIT_USB_OUT;
+       ep_conf.type = DDEKIT_USB_TRANSFER_CTL;
+
        /* Reset URB and assign given values */
-       init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_CTL, 0,
-               DDEKIT_USB_OUT);
+       init_urb(&urb, driver_state.cur_periph->dev, &ep_conf);
 
        /* Clear setup data */
        memset(&bulk_setup, 0, sizeof(bulk_setup));
@@ -908,8 +917,8 @@ mass_storage_open(devminor_t minor, int UNUSED(access))
 
        /* In case of missing endpoint information, do simple
         * enumeration and hold it for future use */
-       if ((-1 == driver_state.cur_periph->ep_in) ||
-               (-1 == driver_state.cur_periph->ep_out)) {
+       if ((URB_INVALID_EP == driver_state.cur_periph->ep_in.ep_num) ||
+               (URB_INVALID_EP == driver_state.cur_periph->ep_out.ep_num)) {
 
                if (mass_storage_get_endpoints(&driver_state.cur_periph->ep_in,
                                        &driver_state.cur_periph->ep_out))
@@ -1279,8 +1288,8 @@ usb_driver_connect(struct ddekit_usb_dev * dev,
        /* Hold host information for future use */
        driver_state.cur_periph->dev = dev;
        driver_state.cur_periph->interfaces = interfaces;
-       driver_state.cur_periph->ep_in = -1;
-       driver_state.cur_periph->ep_out = -1;
+       driver_state.cur_periph->ep_in.ep_num = URB_INVALID_EP;
+       driver_state.cur_periph->ep_out.ep_num = URB_INVALID_EP;
 }
 
 
@@ -1301,8 +1310,8 @@ usb_driver_disconnect(struct ddekit_usb_dev * UNUSED(dev))
        /* Clear */
        driver_state.cur_periph->dev = NULL;
        driver_state.cur_periph->interfaces = 0;
-       driver_state.cur_periph->ep_in = -1;
-       driver_state.cur_periph->ep_out = -1;
+       driver_state.cur_periph->ep_in.ep_num = URB_INVALID_EP;
+       driver_state.cur_periph->ep_out.ep_num = URB_INVALID_EP;
 }
 
 
@@ -1310,7 +1319,7 @@ usb_driver_disconnect(struct ddekit_usb_dev * UNUSED(dev))
  *    mass_storage_get_endpoints                                             *
  *===========================================================================*/
 static int
-mass_storage_get_endpoints(int * ep_in, int * ep_out)
+mass_storage_get_endpoints(urb_ep_config * ep_in, urb_ep_config * ep_out)
 {
        /* URB to be send */
        struct ddekit_usb_urb urb;
@@ -1318,14 +1327,21 @@ mass_storage_get_endpoints(int * ep_in, int * ep_out)
        /* Setup buffer to be attached */
        struct usb_ctrlrequest setup_buf;
 
+       /* Control EP configuration */
+       urb_ep_config ep_conf;
+
        /* Descriptors' buffer */
        unsigned char descriptors[MAX_DESCRIPTORS_LEN];
 
        MASS_DEBUG_DUMP;
 
+       /* Initialize EP configuration */
+       ep_conf.ep_num = 0;
+       ep_conf.direction = DDEKIT_USB_IN;
+       ep_conf.type = DDEKIT_USB_TRANSFER_CTL;
+
        /* Reset URB and assign given values */
-       init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_CTL, 0,
-               DDEKIT_USB_IN);
+       init_urb(&urb, driver_state.cur_periph->dev, &ep_conf);
 
        /* Clear setup data */
        memset(&setup_buf, 0, sizeof(setup_buf));
@@ -1364,10 +1380,12 @@ mass_storage_get_endpoints(int * ep_in, int * ep_out)
  *===========================================================================*/
 static int
 mass_storage_parse_endpoint(usb_descriptor_t * cur_desc,
-                       int * ep_in, int * ep_out)
+                       urb_ep_config * ep_in, urb_ep_config * ep_out)
 {
        usb_endpoint_descriptor_t * ep_desc;
 
+       urb_ep_config * this_ep;
+
        MASS_DEBUG_DUMP;
 
        ep_desc = (usb_endpoint_descriptor_t *)cur_desc;
@@ -1378,24 +1396,30 @@ mass_storage_parse_endpoint(usb_descriptor_t * cur_desc,
                /* Check for direction */
                if (UE_DIR_IN == UE_GET_DIR(ep_desc->bEndpointAddress)) {
 
-                       if (-1 != *ep_in) {
-                               MASS_MSG("BULK IN already set");
-                               return EXIT_FAILURE;
-                       }
-
-                       *ep_in = UE_GET_ADDR(ep_desc->bEndpointAddress);
+                       this_ep = ep_in;
+                       this_ep->direction = DDEKIT_USB_IN;
 
                } else {
 
-                       if (-1 != *ep_out) {
-                               MASS_MSG("BULK OUT already set");
-                               return EXIT_FAILURE;
-                       }
+                       this_ep = ep_out;
+                       this_ep->direction = DDEKIT_USB_OUT;
+               }
 
-                       *ep_out = UE_GET_ADDR(ep_desc->bEndpointAddress);
+               /* Check if it was set before */
+               if (URB_INVALID_EP != this_ep->ep_num) {
+                       MASS_MSG("BULK EP already set");
+                       return EXIT_FAILURE;
                }
+
+               /* Assign rest */
+               this_ep->ep_num = UE_GET_ADDR(ep_desc->bEndpointAddress);
+               this_ep->type = DDEKIT_USB_TRANSFER_BLK;
+               this_ep->max_packet_size = UGETW(ep_desc->wMaxPacketSize);
+               this_ep->interval = ep_desc->bInterval;
        }
 
+       /* EP type other than bulk, is also correct,
+        * just no parsing is performed */
        return EXIT_SUCCESS;
 }
 
@@ -1404,7 +1428,7 @@ mass_storage_parse_endpoint(usb_descriptor_t * cur_desc,
  *===========================================================================*/
 static int
 mass_storage_parse_descriptors(char * desc_buf, unsigned int buf_len,
-                               int * ep_in, int * ep_out)
+                               urb_ep_config * ep_in, urb_ep_config * ep_out)
 {
        /* Currently parsed, descriptors */
        usb_descriptor_t * cur_desc;
@@ -1419,8 +1443,8 @@ mass_storage_parse_descriptors(char * desc_buf, unsigned int buf_len,
        MASS_DEBUG_DUMP;
 
        /* Parse descriptors to get endpoints */
-       *ep_in = -1;
-       *ep_out = -1;
+       ep_in->ep_num = URB_INVALID_EP;
+       ep_out->ep_num = URB_INVALID_EP;
        valid_interface = 0;
        cur_byte = 0;
 
@@ -1514,7 +1538,8 @@ mass_storage_parse_descriptors(char * desc_buf, unsigned int buf_len,
                return EXIT_FAILURE;
 
        /* ...and descriptors should be valid */
-       if ((-1 == *ep_in) || (-1 == *ep_out)) {
+       if ((URB_INVALID_EP == ep_in->ep_num) ||
+               (URB_INVALID_EP == ep_out->ep_num)) {
                MASS_MSG("Valid bulk endpoints not found");
                return EXIT_FAILURE;
        }
index 1734498c0b3b1d2770126201f2e95caf38bf8dc3..436d01138c5d080345adf7026cbe3504d7f20d3a 100755 (executable)
@@ -9,6 +9,8 @@
 #include <minix/type.h>                        /* vir_bytes */
 /* TODO: no header for ddekit_usb_dev */
 
+#include "urb_helper.h"
+
 /* Number of handled peripherals (USB devices) */
 #define MAX_PERIPHS                    (1)
 /* Number of handled disks per driver */
@@ -40,8 +42,8 @@ typedef struct mass_storage_periph {
        mass_storage_drive drives[MAX_DRIVES];  /* Possible drive info */
        struct ddekit_usb_dev * dev;            /* DDEKit device handler */
        unsigned int interfaces;                /* Interfaces bitmap */
-       int ep_in;                              /* Bulk IN endpoint*/
-       int ep_out;                             /* Bulk OUT endpoint*/
+       urb_ep_config ep_in;                    /* Bulk IN endpoint */
+       urb_ep_config ep_out;                   /* Bulk OUT endpoint */
 }
 mass_storage_periph;