More endpoint descriptor data held by usb_storage

Makes usb_storage remember endpoint interval and other parameters, instead of endpoint number only.
This commit is contained in:
Wojciech Zajac 2014-06-23 12:32:44 +02:00 committed by Lionel Sambuc
parent d2cf1e60b4
commit e0f92bef05
4 changed files with 99 additions and 55 deletions

View file

@ -19,30 +19,30 @@
*===========================================================================*/ *===========================================================================*/
void void
init_urb(struct ddekit_usb_urb * urb, struct ddekit_usb_dev * dev, init_urb(struct ddekit_usb_urb * urb, struct ddekit_usb_dev * dev,
ddekit_int32_t urb_type, ddekit_int32_t urb_endpoint, urb_ep_config * conf)
ddekit_int32_t urb_direction)
{ {
MASS_DEBUG_DUMP; MASS_DEBUG_DUMP;
/* Sanity checks */ /* Sanity checks */
assert(NULL != urb); assert(NULL != urb);
assert(NULL != dev); assert(NULL != dev);
assert((DDEKIT_USB_TRANSFER_BLK == urb_type) || assert((DDEKIT_USB_TRANSFER_BLK == conf->type) ||
(DDEKIT_USB_TRANSFER_CTL == urb_type) || (DDEKIT_USB_TRANSFER_CTL == conf->type) ||
(DDEKIT_USB_TRANSFER_INT == urb_type) || (DDEKIT_USB_TRANSFER_INT == conf->type) ||
(DDEKIT_USB_TRANSFER_ISO == urb_type)); (DDEKIT_USB_TRANSFER_ISO == conf->type));
assert(urb_endpoint < 16); assert((conf->ep_num >= 0) && (conf->ep_num < 16));
assert((DDEKIT_USB_IN == urb_direction) || assert((DDEKIT_USB_IN == conf->direction) ||
(DDEKIT_USB_OUT == urb_direction)); (DDEKIT_USB_OUT == conf->direction));
/* Clear block first */ /* Clear block first */
memset(urb, 0, sizeof(*urb)); memset(urb, 0, sizeof(*urb));
/* Set supplied values */ /* Set supplied values */
urb->dev = dev; urb->dev = dev;
urb->type = urb_type; urb->type = conf->type;
urb->endpoint = urb_endpoint; urb->endpoint = conf->ep_num;
urb->direction = urb_direction; urb->direction = conf->direction;
urb->interval = conf->interval;
} }

View file

@ -19,11 +19,28 @@
#define URB_SUBMIT_CHECK_LEN 0 /* return error on length mismatch */ #define URB_SUBMIT_CHECK_LEN 0 /* return error on length mismatch */
#define URB_SUBMIT_ALLOW_MISMATCH 1 /* ignore length check */ #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 * * declared functions *
*---------------------------*/ *---------------------------*/
void init_urb(struct ddekit_usb_urb *, struct ddekit_usb_dev *, ddekit_int32_t, void init_urb(struct ddekit_usb_urb *, struct ddekit_usb_dev *,
ddekit_int32_t, ddekit_int32_t); urb_ep_config *);
void attach_urb_data(struct ddekit_usb_urb *, int, void *, ddekit_uint32_t); 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); int blocking_urb_submit(struct ddekit_usb_urb *, ddekit_sem_t *, int);

View file

@ -81,9 +81,11 @@ static void usb_driver_connect(struct ddekit_usb_dev *, unsigned int);
static void usb_driver_disconnect(struct ddekit_usb_dev *); static void usb_driver_disconnect(struct ddekit_usb_dev *);
/* Simplified enumeration method for endpoint resolution */ /* Simplified enumeration method for endpoint resolution */
static int mass_storage_get_endpoints(int *, int *); static int mass_storage_get_endpoints(urb_ep_config *, urb_ep_config *);
static int mass_storage_parse_endpoint(usb_descriptor_t *, int *, int *); static int mass_storage_parse_endpoint(usb_descriptor_t *, urb_ep_config *,
static int mass_storage_parse_descriptors(char *, unsigned int, int *, int *); 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; MASS_DEBUG_DUMP;
/* Reset URB and assign given values */ /* Reset URB and assign given values */
init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK, init_urb(&urb, driver_state.cur_periph->dev,
driver_state.cur_periph->ep_out, DDEKIT_USB_OUT); &(driver_state.cur_periph->ep_out));
/* Reset CBW and assign default values */ /* Reset CBW and assign default values */
init_cbw(&cbw, last_cbw_tag = current_cbw_tag++); 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; MASS_DEBUG_DUMP;
/* Reset URB and assign given values */ /* Reset URB and assign given values */
init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK, init_urb(&urb, driver_state.cur_periph->dev,
driver_state.cur_periph->ep_in, DDEKIT_USB_IN); &(driver_state.cur_periph->ep_in));
/* Attach buffer to URB */ /* Attach buffer to URB */
attach_urb_data(&urb, URB_BUF_TYPE_DATA, buf, in_len); 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; MASS_DEBUG_DUMP;
/* Reset URB and assign given values */ /* Reset URB and assign given values */
init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK, init_urb(&urb, driver_state.cur_periph->dev,
driver_state.cur_periph->ep_out, DDEKIT_USB_OUT); &(driver_state.cur_periph->ep_out));
/* Attach buffer to URB */ /* Attach buffer to URB */
attach_urb_data(&urb, URB_BUF_TYPE_DATA, buf, out_len); 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; MASS_DEBUG_DUMP;
/* Reset URB and assign given values */ /* Reset URB and assign given values */
init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_BLK, init_urb(&urb, driver_state.cur_periph->dev,
driver_state.cur_periph->ep_in, DDEKIT_USB_IN); &(driver_state.cur_periph->ep_in));
/* Clear CSW for receiving */ /* Clear CSW for receiving */
init_csw(&csw); init_csw(&csw);
@ -340,11 +342,18 @@ mass_storage_send_bulk_reset(void)
/* Setup buffer to be send */ /* Setup buffer to be send */
struct usb_ctrlrequest bulk_setup; struct usb_ctrlrequest bulk_setup;
/* Control EP configuration */
urb_ep_config ep_conf;
MASS_DEBUG_DUMP; 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 */ /* Reset URB and assign given values */
init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_CTL, 0, init_urb(&urb, driver_state.cur_periph->dev, &ep_conf);
DDEKIT_USB_OUT);
/* Clear setup data */ /* Clear setup data */
memset(&bulk_setup, 0, sizeof(bulk_setup)); 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 /* In case of missing endpoint information, do simple
* enumeration and hold it for future use */ * enumeration and hold it for future use */
if ((-1 == driver_state.cur_periph->ep_in) || if ((URB_INVALID_EP == driver_state.cur_periph->ep_in.ep_num) ||
(-1 == driver_state.cur_periph->ep_out)) { (URB_INVALID_EP == driver_state.cur_periph->ep_out.ep_num)) {
if (mass_storage_get_endpoints(&driver_state.cur_periph->ep_in, if (mass_storage_get_endpoints(&driver_state.cur_periph->ep_in,
&driver_state.cur_periph->ep_out)) &driver_state.cur_periph->ep_out))
@ -1279,8 +1288,8 @@ usb_driver_connect(struct ddekit_usb_dev * dev,
/* Hold host information for future use */ /* Hold host information for future use */
driver_state.cur_periph->dev = dev; driver_state.cur_periph->dev = dev;
driver_state.cur_periph->interfaces = interfaces; driver_state.cur_periph->interfaces = interfaces;
driver_state.cur_periph->ep_in = -1; driver_state.cur_periph->ep_in.ep_num = URB_INVALID_EP;
driver_state.cur_periph->ep_out = -1; 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 */ /* Clear */
driver_state.cur_periph->dev = NULL; driver_state.cur_periph->dev = NULL;
driver_state.cur_periph->interfaces = 0; driver_state.cur_periph->interfaces = 0;
driver_state.cur_periph->ep_in = -1; driver_state.cur_periph->ep_in.ep_num = URB_INVALID_EP;
driver_state.cur_periph->ep_out = -1; 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 * * mass_storage_get_endpoints *
*===========================================================================*/ *===========================================================================*/
static int 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 */ /* URB to be send */
struct ddekit_usb_urb urb; struct ddekit_usb_urb urb;
@ -1318,14 +1327,21 @@ mass_storage_get_endpoints(int * ep_in, int * ep_out)
/* Setup buffer to be attached */ /* Setup buffer to be attached */
struct usb_ctrlrequest setup_buf; struct usb_ctrlrequest setup_buf;
/* Control EP configuration */
urb_ep_config ep_conf;
/* Descriptors' buffer */ /* Descriptors' buffer */
unsigned char descriptors[MAX_DESCRIPTORS_LEN]; unsigned char descriptors[MAX_DESCRIPTORS_LEN];
MASS_DEBUG_DUMP; 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 */ /* Reset URB and assign given values */
init_urb(&urb, driver_state.cur_periph->dev, DDEKIT_USB_TRANSFER_CTL, 0, init_urb(&urb, driver_state.cur_periph->dev, &ep_conf);
DDEKIT_USB_IN);
/* Clear setup data */ /* Clear setup data */
memset(&setup_buf, 0, sizeof(setup_buf)); memset(&setup_buf, 0, sizeof(setup_buf));
@ -1364,10 +1380,12 @@ mass_storage_get_endpoints(int * ep_in, int * ep_out)
*===========================================================================*/ *===========================================================================*/
static int static int
mass_storage_parse_endpoint(usb_descriptor_t * cur_desc, 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; usb_endpoint_descriptor_t * ep_desc;
urb_ep_config * this_ep;
MASS_DEBUG_DUMP; MASS_DEBUG_DUMP;
ep_desc = (usb_endpoint_descriptor_t *)cur_desc; ep_desc = (usb_endpoint_descriptor_t *)cur_desc;
@ -1378,24 +1396,30 @@ mass_storage_parse_endpoint(usb_descriptor_t * cur_desc,
/* Check for direction */ /* Check for direction */
if (UE_DIR_IN == UE_GET_DIR(ep_desc->bEndpointAddress)) { if (UE_DIR_IN == UE_GET_DIR(ep_desc->bEndpointAddress)) {
if (-1 != *ep_in) { this_ep = ep_in;
MASS_MSG("BULK IN already set"); this_ep->direction = DDEKIT_USB_IN;
return EXIT_FAILURE;
}
*ep_in = UE_GET_ADDR(ep_desc->bEndpointAddress);
} else { } else {
if (-1 != *ep_out) { this_ep = ep_out;
MASS_MSG("BULK OUT already set"); this_ep->direction = DDEKIT_USB_OUT;
}
/* Check if it was set before */
if (URB_INVALID_EP != this_ep->ep_num) {
MASS_MSG("BULK EP already set");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
*ep_out = UE_GET_ADDR(ep_desc->bEndpointAddress); /* 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; return EXIT_SUCCESS;
} }
@ -1404,7 +1428,7 @@ mass_storage_parse_endpoint(usb_descriptor_t * cur_desc,
*===========================================================================*/ *===========================================================================*/
static int static int
mass_storage_parse_descriptors(char * desc_buf, unsigned int buf_len, 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 */ /* Currently parsed, descriptors */
usb_descriptor_t * cur_desc; usb_descriptor_t * cur_desc;
@ -1419,8 +1443,8 @@ mass_storage_parse_descriptors(char * desc_buf, unsigned int buf_len,
MASS_DEBUG_DUMP; MASS_DEBUG_DUMP;
/* Parse descriptors to get endpoints */ /* Parse descriptors to get endpoints */
*ep_in = -1; ep_in->ep_num = URB_INVALID_EP;
*ep_out = -1; ep_out->ep_num = URB_INVALID_EP;
valid_interface = 0; valid_interface = 0;
cur_byte = 0; cur_byte = 0;
@ -1514,7 +1538,8 @@ mass_storage_parse_descriptors(char * desc_buf, unsigned int buf_len,
return EXIT_FAILURE; return EXIT_FAILURE;
/* ...and descriptors should be valid */ /* ...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"); MASS_MSG("Valid bulk endpoints not found");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View file

@ -9,6 +9,8 @@
#include <minix/type.h> /* vir_bytes */ #include <minix/type.h> /* vir_bytes */
/* TODO: no header for ddekit_usb_dev */ /* TODO: no header for ddekit_usb_dev */
#include "urb_helper.h"
/* Number of handled peripherals (USB devices) */ /* Number of handled peripherals (USB devices) */
#define MAX_PERIPHS (1) #define MAX_PERIPHS (1)
/* Number of handled disks per driver */ /* Number of handled disks per driver */
@ -40,8 +42,8 @@ typedef struct mass_storage_periph {
mass_storage_drive drives[MAX_DRIVES]; /* Possible drive info */ mass_storage_drive drives[MAX_DRIVES]; /* Possible drive info */
struct ddekit_usb_dev * dev; /* DDEKit device handler */ struct ddekit_usb_dev * dev; /* DDEKit device handler */
unsigned int interfaces; /* Interfaces bitmap */ unsigned int interfaces; /* Interfaces bitmap */
int ep_in; /* Bulk IN endpoint*/ urb_ep_config ep_in; /* Bulk IN endpoint */
int ep_out; /* Bulk OUT endpoint*/ urb_ep_config ep_out; /* Bulk OUT endpoint */
} }
mass_storage_periph; mass_storage_periph;