uas: MS UAS Gadget driver - Infrastructure
Subsystems (2)
PATCH v4 1/3 uas: MS UAS Gadget driver - Infrastructure
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
A new module parameter was added to the mass_storage module:
bool use_uasp. (default = 0)
If this parameter is set to true, the mass_storage module will register with the UAS configuration as the devices first configuration and operate according to the UAS protocol.
The number of buffers used by the mass_storage device was increased according to the number of supported streams.
It defines the API for COMMAND/TASK MANAGEMENT IU implementation.
--- drivers/usb/gadget/f_mass_storage.c | 26 +- drivers/usb/gadget/f_uasp.c | 2393 +++++++++++++++++++++++++++++++++++ drivers/usb/gadget/f_uasp.h | 430 +++++++ drivers/usb/gadget/mass_storage.c | 67 +- drivers/usb/gadget/storage_common.c | 24 +- drivers/usb/gadget/uasp_cmdiu.c | 514 ++++++++ drivers/usb/gadget/uasp_tmiu.c | 277 ++++ 7 files changed, 3708 insertions(+), 23 deletions(-) create mode 100644 drivers/usb/gadget/f_uasp.c create mode 100644 drivers/usb/gadget/f_uasp.h create mode 100644 drivers/usb/gadget/uasp_cmdiu.c create mode 100644 drivers/usb/gadget/uasp_tmiu.c
drivers/usb/gadget/f_mass_storage.c +15 -11
@@ -2703,7 +2703,8 @@ static inline void fsg_common_put(struct fsg_common *common)static struct fsg_common *fsg_common_init (struct fsg_common *common,struct usb_composite_dev *cdev, -struct fsg_config *cfg) +struct fsg_config *cfg, +int start_thread) {struct usb_gadget *gadget = cdev->gadget;struct fsg_buffhd *bh;
@@ -2866,12 +2867,14 @@ buffhds_first_it:kref_init (&common->ref);/* Tell the thread to start working */ - common->thread_task = -kthread_create (fsg_main_thread, common, +if (start_thread) { + common->thread_task = +kthread_create (fsg_main_thread, common, cfg->thread_name ?:"file-storage" ); -if (IS_ERR (common->thread_task)) { - rc =PTR_ERR (common->thread_task); - goto error_release; +if (IS_ERR (common->thread_task)) { + rc =PTR_ERR (common->thread_task); + goto error_release; + } }init_completion (&common->thread_notifier);init_waitqueue_head (&common->fsg_wait);
@@ -2902,10 +2905,11 @@ buffhds_first_it: }kfree (pathbuf); -DBG (common,"I/O thread pid: %d\n" ,task_pid_nr (common->thread_task)); - -wake_up_process (common->thread_task); - +if (start_thread) { +DBG (common,"I/O thread pid: %d\n" , +task_pid_nr (common->thread_task)); +wake_up_process (common->thread_task); + }return common; error_luns:
@@ -3196,6 +3200,6 @@ fsg_common_from_params(struct fsg_common *common, {struct fsg_config cfg;fsg_config_from_params (&cfg, params); -return fsg_common_init (common, cdev, &cfg); +return fsg_common_init (common, cdev, &cfg,1 ); }
drivers/usb/gadget/f_uasp.c new file +2393 -0
2,393 lines not on this page · raw message
drivers/usb/gadget/f_uasp.h new file +430 -0
430 lines not on this page · raw message
drivers/usb/gadget/mass_storage.c +61 -6
100 lines not on this page · raw message
drivers/usb/gadget/storage_common.c +18 -6
@@ -217,6 +217,7 @@ struct interrupt_data {#define SS_UNRECOVERED_READ_ERROR 0x031100#define SS_WRITE_ERROR 0x030c02#define SS_WRITE_PROTECTED 0x072700 +#define SS_OVERLAPPED_COMMANDS_ATTEMPTED 0x0b4e00#define SK (x) ((u8) ((x) >> 16))/* Sense Key byte, etc. */ #define ASC (x) ((u8) ((x) >> 8))
@@ -261,9 +262,16 @@ static struct fsg_lun *fsg_lun_from_dev(struct device *dev)#define EP0_BUFSIZE 256#define DELAYED_STATUS (EP0_BUFSIZE + 999)/* An impossibly large value */ +/* +* We limit the number of UASP streams to 256 due to memory requirements. +* 4 buffer will be allocated for each supported stream. +*/ +#define UASP_SS_EP_COMP_NUM_STREAMS 4 +#ifdef CONFIG_USB_GADGET_DEBUG_FILES -static unsigned int fsg_num_buffers =CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS ; +static unsigned int fsg_num_buffers = (4 * + CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS^UASP_SS_EP_COMP_NUM_STREAMS));module_param_named (num_buffers, fsg_num_buffers, uint,S_IRUGO );MODULE_PARM_DESC (num_buffers,"Number of pipeline buffers" );
@@ -273,17 +281,18 @@ MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers");* Number of buffers we will use. * 2 is usually enough for good buffering pipeline */
Lines of this file are not shown. View the raw message.
drivers/usb/gadget/uasp_cmdiu.c new file +514 -0
514 lines not on this page · raw message
drivers/usb/gadget/uasp_tmiu.c new file +277 -0
277 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 5 lines
1.7.6 -- Sent by a Consultant for Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Part of the diff is not shown here. View the raw message.
PATCH v4 2/3 uas: MS UAS Gadget driver - Implementation
Implementation of different SCSI commands received in a COMMAND IU packets, as well as most of the TASK MANAGEMENT IUs defined in table 20 of the UAS specifications, for UASP over a HS USB bus connection.
--- drivers/usb/gadget/f_uasp.c | 25 +- drivers/usb/gadget/f_uasp.h | 28 +- drivers/usb/gadget/uasp_cmdiu.c | 1408 ++++++++++++++++++++++++++++++++++++++- drivers/usb/gadget/uasp_tmiu.c | 273 ++++++++- 4 files changed, 1700 insertions(+), 34 deletions(-)
drivers/usb/gadget/f_uasp.c +17 -8
@@ -922,6 +922,8 @@ reset_uasp: fcommon->fsg = new_fsg; fsgd = fcommon->fsg; + uaspd->op_mode = (fcommon->gadget->speed ==USB_SPEED_SUPER ? +SS_UASP_MODE :HS_UASP_MODE );/* Enable the endpoints */ config_ep_by_speed (fcommon->gadget, &fsgd->function, fsgd->bulk_in);
@@ -990,9 +992,9 @@ reset_uasp: goto reset_uasp; } -DBG (uaspd->ucommon->common,"%s() allocated command request = %p, " -"udev=%p\n" , __func__, - uaspd->cmd_buff.outreq, uaspd); +DBG (uaspd->ucommon->common,"%s() Enebled endpoints. " +"Opperation mode = %d\n" , __func__, + uaspd->op_mode); uaspd->cmd_buff.outreq->buf = &(uaspd->cmd_buff.buf); uaspd->cmd_buff.inreq =NULL ; uaspd->cmd_buff.state =BUF_STATE_EMPTY ;
@@ -1196,6 +1198,7 @@ static int uasp_command_check(struct uasp_dev *udev, void **command)list_for_each_entry (tmp_cmdiu, &curlun->cmd_queue, node) {if (tmp_cmdiu->state !=COMMAND_STATE_IDLE && tmp_cmdiu->state !=COMMAND_STATE_DATA && + tmp_cmdiu->state !=COMMAND_STATE_RR_WR && tmp_cmdiu->state !=COMMAND_STATE_STATUS ) {continue ; }
@@ -1222,6 +1225,7 @@ static int uasp_command_check(struct uasp_dev *udev, void **command)list_for_each_entry (tmp_cmdiu, &udev->cmd_queue, node) {if (tmp_cmdiu->state !=COMMAND_STATE_IDLE && tmp_cmdiu->state !=COMMAND_STATE_DATA && + tmp_cmdiu->state !=COMMAND_STATE_RR_WR && tmp_cmdiu->state !=COMMAND_STATE_STATUS )continue ;
@@ -1300,7 +1304,8 @@ overlapped_tag:fill_usb_request (tmiu->bh->inreq, tmiu->bh->buf,UASP_SIZEOF_RESPONSE_IU ,0 , (void *)tmiu,0 , -be16_to_cpup (&tmiu->tag), status_complete); +be16_to_cpup (&tmiu->tag), status_complete, + udev->op_mode); tmiu->ep = udev->status; tmiu->bh->inreq_busy =1 ;
@@ -1329,7 +1334,8 @@ overlapped_tag:fill_usb_request (cmdiu->bh->inreq, cmdiu->bh->buf,UASP_SIZEOF_SENSE_IU ,0 , (void *)cmdiu,0 , -be16_to_cpup (&cmdiu->tag), status_complete); +be16_to_cpup (&cmdiu->tag), status_complete, + udev->op_mode); cmdiu->ep = udev->status; cmdiu->bh->inreq_busy =1 ;if (usb_ep_queue (cmdiu->ep, cmdiu->bh->inreq,0 ))
@@ -1668,7 +1674,8 @@ void abort_commands(struct uasp_dev *udev,spin_lock_irqsave (lock, flags);list_for_each_entry_safe (cmdiu, tmp_cmdiu, cmd_queue, node) { -if (cmdiu->state ==COMMAND_STATE_DATA ) { +if (cmdiu->state ==COMMAND_STATE_DATA || + cmdiu->state ==COMMAND_STATE_RR_WR ) {if (cmdiu->req_sts ==CMD_REQ_IN_PROGRESS ) {spin_unlock_irqrestore (lock, flags);if (cmdiu->bh->inreq_busy)
@@ -2371,6 +2378,7 @@ uasp_add_err:* @short_not_ok: short_not_ok field of the request. * @stream_id: stream_id field of the request. * @complete: complete function to be called on request completion +* @op_mode: operation mode (HS_UASP_MODE/SS_UASP_MODE) * */ void fill_usb_request(struct usb_request *req,
@@ -2380,14 +2388,15 @@ void fill_usb_request(struct usb_request *req,void *context, unsigned short_not_ok, unsigned stream_id, - usb_request_complete_t complete) + usb_request_complete_t complete, + uint8_t op_mode) { req->buf = buf; req->length = length; req->zero = zero; req->context = context; req->short_not_ok = short_not_ok; - req->stream_id = stream_id; + req->stream_id = (op_mode ==SS_UASP_MODE ? stream_id :0 ); req->complete = complete; }
drivers/usb/gadget/f_uasp.h +27 -1
@@ -124,6 +124,10 @@ struct uasp_dev {struct usb_ep *command;struct fsg_buffhd cmd_buff; +#define HS_UASP_MODE 0 +#define SS_UASP_MODE 1 +uint8_t op_mode; +unsigned int cmd_enabled;unsigned int status_enabled;
@@ -337,6 +341,27 @@ struct response_iu { } __attribute__((__packed__));#define UASP_SIZEOF_RESPONSE_IU 8 +/* READ/WRITE READY IU - see table 14/15 of the UAS Spec */ +struct rw_ready_iu { +__u8 iu_id; +__u8 reserved; +__be16 tag;/* section 4.2 of the UAS spec */ +} __attribute__((__packed__ )); +#define UASP_SIZEOF_RW_READY_IU 4 + +/** +* fill_usb_request() - fills the usb_request structure with the given values. +* @req: pointer to usb_request structure to be filled. +* @buf: the buffer to send/receive +* @length: length field of the request. +* @zero: zero field of the request. +* @context: context field of the request. +* @short_not_ok: short_not_ok field of the request. +* @stream_id: stream_id field of the request. +* @complete: complete function to be called on request completion +* @op_mode: operation mode (HS_UASP_MODE/SS_UASP_MODE) +* +*/ void fill_usb_request(struct usb_request *req, void *buf, unsigned length,
@@ -344,7 +369,8 @@ void fill_usb_request(struct usb_request *req,void *context, unsigned short_not_ok, unsigned stream_id, - usb_request_complete_t complete); + usb_request_complete_t complete, + uint8_t op_mode);/** * uasp_bulk_in_complete() - Callback function for the bulk IN endpoint
drivers/usb/gadget/uasp_cmdiu.c +1394 -14
1,503 lines not on this page · raw message
drivers/usb/gadget/uasp_tmiu.c +262 -11
334 lines not on this page · raw message
Signature · 5 lines
1.7.6 -- Sent by a Consultant for Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH v4 3/3 uas: Supporting UAS and BOT configuration.
In reply to Shimrit MalichiTwo configuration were added to the mass storage gadget: BOT (the first one), and UAS. The linux host can switch between the configurations by changing the value of bConfigValue in /sys/bus/usb/devices/<your_usb_device>/
Also, a fallback to HS in case SS configuration fails was added.
--- drivers/usb/gadget/f_mass_storage.c | 92 +--- drivers/usb/gadget/f_uasp.c | 1063 ++++++++++++++++++++--------------- drivers/usb/gadget/f_uasp.h | 106 +++- drivers/usb/gadget/mass_storage.c | 88 ++-- drivers/usb/gadget/storage_common.c | 66 +++- drivers/usb/gadget/uasp_cmdiu.c | 176 +++--- drivers/usb/gadget/uasp_tmiu.c | 60 +- 7 files changed, 955 insertions(+), 696 deletions(-)
drivers/usb/gadget/f_mass_storage.c +23 -69
@@ -317,39 +317,16 @@ static const char fsg_string_interface[] = "Mass Storage";struct fsg_dev ;struct fsg_common ; -/* FSF callback functions */ -struct fsg_operations { -/* -* Callback function to call when thread exits. If no -* callback is set or it returns value lower then zero MSF -* will force eject all LUNs it operates on (including those -* marked as non-removable or with prevent_medium_removal flag -* set). -*/ -int (*thread_exits)(struct fsg_common *common); - -/* -* Called prior to ejection. Negative return means error, -* zero means to continue with ejection, positive means not to -* eject. -*/ -int (*pre_eject)(struct fsg_common *common, -struct fsg_lun *lun,int num); -/* -* Called after ejection. Negative return means error, zero -* or positive is just a success. -*/ -int (*post_eject)(struct fsg_common *common, -struct fsg_lun *lun,int num); -}; -/* Data shared by all the FSG instances. */ struct fsg_common {struct usb_gadget *gadget;struct usb_composite_dev *cdev; +struct msg_common_data *msg_common;struct fsg_dev *fsg, *new_fsg;wait_queue_head_t fsg_wait; +struct mutex *config_mutex; +/* filesem protects: backing files in use */ struct rw_semaphore filesem;
@@ -408,31 +385,6 @@ struct fsg_common {struct kref ref; }; -struct fsg_config { -unsigned nluns; -struct fsg_lun_config { -const char *filename; -char ro; -char removable; -char cdrom; -char nofua; - } luns[FSG_MAX_LUNS ]; - -const char *lun_name_format; -const char *thread_name; - -/* Callback functions. */ -const struct fsg_operations *ops; -/* Gadget's private data. */ -void *private_data; - -const char *vendor_name;/* 8 characters or less */ -const char *product_name;/* 16 characters or less */ -u16 release; - -char can_stall; -}; -struct fsg_dev {struct usb_function function;struct usb_gadget *gadget;/* Copy of cdev->gadget */
@@ -2364,7 +2316,10 @@ reset:usb_ep_disable (fsg->bulk_out); fsg->bulk_out_enabled =0 ; } - +DBG (common, +"%s()- disabled endpoints, releasing config mutex\n" , + __func__); +mutex_unlock (common->config_mutex); common->fsg =NULL ;wake_up (&common->fsg_wait); }
@@ -2373,6 +2328,9 @@ reset:if (!new_fsg || rc)return rc; +DBG (common,"%s()- Enabling endpoints, taking config mutex\n" , + __func__); +mutex_lock (common->config_mutex); common->fsg = new_fsg; fsg = common->fsg;
@@ -2703,8 +2661,7 @@ static inline void fsg_common_put(struct fsg_common *common)static struct fsg_common *fsg_common_init (struct fsg_common *common,struct usb_composite_dev *cdev, -struct fsg_config *cfg, -int start_thread) +struct fsg_config *cfg) {struct usb_gadget *gadget = cdev->gadget;struct fsg_buffhd *bh;
@@ -2750,6 +2707,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, common->ep0 = gadget->ep0; common->ep0req = cdev->req; common->cdev = cdev; + common->config_mutex = &(cfg->config_mutex);/* Maybe allocate device-global string IDs, and patch descriptors */ if (fsg_strings[FSG_STRING_INTERFACE ].id ==0 ) {
@@ -2866,15 +2824,12 @@ buffhds_first_it:spin_lock_init (&common->lock);kref_init (&common->ref); -/* Tell the thread to start working */ -if (start_thread) { - common->thread_task = -kthread_create (fsg_main_thread, common, - cfg->thread_name ?:"file-storage" ); -if (IS_ERR (common->thread_task)) { - rc =PTR_ERR (common->thread_task); - goto error_release; - } + common->thread_task = +kthread_create (fsg_main_thread, common, + cfg->thread_name ?:"file-storage" ); +if (IS_ERR (common->thread_task)) { + rc =PTR_ERR (common->thread_task); + goto error_release; }init_completion (&common->thread_notifier);init_waitqueue_head (&common->fsg_wait);
@@ -2905,11 +2860,10 @@ buffhds_first_it: }kfree (pathbuf); -if (start_thread) { -DBG (common,"I/O thread pid: %d\n" , -task_pid_nr (common->thread_task)); -wake_up_process (common->thread_task); - } +DBG (common,"I/O thread pid: %d\n" ,task_pid_nr (common->thread_task)); + +wake_up_process (common->thread_task); +return common; error_luns:
@@ -3200,6 +3154,6 @@ fsg_common_from_params(struct fsg_common *common, {struct fsg_config cfg;fsg_config_from_params (&cfg, params); -return fsg_common_init (common, cdev, &cfg,1 ); +return fsg_common_init (common, cdev, &cfg); }
drivers/usb/gadget/f_uasp.c +622 -441
1,941 lines not on this page · raw message
drivers/usb/gadget/f_uasp.h +87 -19
146 lines not on this page · raw message
drivers/usb/gadget/mass_storage.c +38 -50
149 lines not on this page · raw message
drivers/usb/gadget/storage_common.c +65 -1
78 lines not on this page · raw message
drivers/usb/gadget/uasp_cmdiu.c +90 -86
534 lines not on this page · raw message
drivers/usb/gadget/uasp_tmiu.c +30 -30
60 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 5 lines
1.7.6 -- Sent by a Consultant for Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Part of the diff is not shown here. View the raw message.
Hi,
Quoted 17 lines · Shimrit Malichi
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
A new module parameter was added to the
mass_storagemodule:
booluse_uasp. (default = 0)
If this parameter is set to true, themass_storagemodule will register with the UAS configuration as the devices first configuration and operate according to the UAS protocol.The number of buffers used by the
mass_storagedevice was increased according to the number of supported streams.It defines the API for COMMAND/TASK MANAGEMENT IU implementation.
Change-Id I86ec7f23b15e602b0f46934adbf5824472e59a1fSigned-off-by Tatyana Brokhman <[email protected]>
Quoted 13 lines
--- drivers/usb/gadget/f_mass_storage.c | 26 +- drivers/usb/gadget/f_uasp.c | 2393 +++++++++++++++++++++++++++++++++++ drivers/usb/gadget/f_uasp.h | 430 +++++++ drivers/usb/gadget/mass_storage.c | 67 +- drivers/usb/gadget/storage_common.c | 24 +- drivers/usb/gadget/uasp_cmdiu.c | 514 ++++++++ drivers/usb/gadget/uasp_tmiu.c | 277 ++++ 7 files changed, 3708 insertions(+), 23 deletions(-) create mode 100644 drivers/usb/gadget/f_uasp.c create mode 100644 drivers/usb/gadget/f_uasp.h create mode 100644 drivers/usb/gadget/uasp_cmdiu.c create mode 100644 drivers/usb/gadget/uasp_tmiu.c
I wonder how many times we will have to ask for this to be done on TARGET FRAMEWORK!!! It's like talking to the walls.
Signature · 1 line
balbi