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.
[RFC] UASP on target (was: [RFC/PATCH v4 1/3] uas: MS UAS Gadget driver - Infrastructure)
Quoted 3 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
hch said to use target framework and you haven't done so. This is what I have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.
Sebastian
Re: [RFC] UASP on target (was: [RFC/PATCH v4 1/3] uas: MS UAS Gadget driver - Infrastructure)
Quoted 5 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 3 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
Quoted 7 lines
hch said to use target framework and you haven't done so. This is what I have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.
drivers/target/Kconfig +1 -0
@@ -50,3 +50,4 @@ source "drivers/target/tcm_qla2xxx/Kconfig" source "drivers/target/tcm_vhost/Kconfig" endif +source "drivers/target/uasp/Kconfig"
drivers/target/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_TCM_FC) += tcm_fc/ obj-$(CONFIG_ISCSI_TARGET) += iscsi/ obj-$(CONFIG_TCM_QLA2XXX) += tcm_qla2xxx/ obj-$(CONFIG_TCM_VHOST) += tcm_vhost/ +obj-$(CONFIG_TARGET_UASP) += uasp/
drivers/target/target_core_configfs.c +7 -0
@@ -162,6 +162,13 @@ static struct config_group *target_core_register_fabric( " tcm_loop.ko: %d\n", ret);return ERR_PTR (-EINVAL ); } + }else if (!strncmp (name,"uasp" ,4 )) { + ret =request_module ("tcm_uasp" ); +if (ret <0 ) { +pr_err ("request_module() failed for" +" tcm_loop.ko: %d\n" , ret); +return ERR_PTR (-EINVAL ); + } } tf =target_core_get_fabric (name);
drivers/target/uasp/Kconfig new file +6 -0
@@ -0,0 +1,6 @@ +config TARGET_UASP + tristate "UASP fabric module" + depends on TARGET_CORE && CONFIGFS_FS + depends on USB_GADGET + ---help--- + Say Y here to enable the UASP fabric module
drivers/target/uasp/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +CFLAGS_gadget.o := -I$(srctree)/drivers/usb/gadget +tcm_uasp-objs := uasp_fabric.o \ + gadget.o \ + uasp_configfs.o +obj-$(CONFIG_TARGET_UASP) += tcm_uasp.o
drivers/target/uasp/gadget.c new file +541 -0
541 lines not on this page · raw message
drivers/target/uasp/gadget.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __GTARGET_UAS_H__ +#define __GTARGET_UAS_H__ + +struct usb_pipe_usage_descriptor { +__u8 bLength; +__u8 bDescriptorType; + +__u8 bPipeID; +/* Pipe ID defenitions: Table 9 from UAS spec*/ +#define PIPE_ID_CMD 0x01/* Command pipe */ +#define PIPE_ID_STS 0x02/* Status pipe */ +#define PIPE_ID_DATA_IN 0x03/* Data-in piep */ +#define PIPE_ID_DATA_OUT 0x04/* Data-out pipe */ +__u8 Reserved; +} __attribute__((__packed__ )); + +#endif
drivers/target/uasp/gadget_ops.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __GADGET_OPS_H__ +#define __GADGET_OPS_H__ + +int gadget_attach (void ); +void gadget_detach (void ); + +#endif
drivers/target/uasp/uasp_base.h new file +32 -0
@@ -0,0 +1,32 @@ +#define UASP_VERSION "v0.1" +#define UASP_NAMELEN 32 + +struct uasp_nacl { +/* Binary World Wide unique Port Name for SAS Initiator port */ +u64 iport_wwpn; +/* ASCII formatted WWPN for Sas Initiator port */ +char iport_name[UASP_NAMELEN ]; +/* Returned by uasp_make_nodeacl() */ +struct se_node_acl se_node_acl; +}; + +struct uasp_tpg { +/* SAS port target portal group tag for TCM */ +u16 tport_tpgt; +/* Pointer back to uasp_tport */ +struct uasp_tport *tport; +/* Returned by uasp_make_tpg() */ +struct se_portal_group se_tpg; +u32 gadget_connect; +}; + +struct uasp_tport { +/* SCSI protocol the tport is providing */ +u8 tport_proto_id; +/* Binary World Wide unique Port Name for SAS Target port */ +u64 tport_wwpn; +/* ASCII formatted WWPN for SAS Target port */ +char tport_name[UASP_NAMELEN ]; +/* Returned by uasp_make_tport() */ +struct se_wwn tport_wwn; +};
drivers/target/uasp/uasp_configfs.c new file +333 -0
333 lines not on this page · raw message
drivers/target/uasp/uasp_configfs.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __UASP_CONFIGFS_H_ +#define __UASP_CONFIGFS_H_ + +int uasp_register_configfs (void ); +void uasp_deregister_configfs (void ); + +#endif
drivers/target/uasp/uasp_fabric.c new file +287 -0
287 lines not on this page · raw message
drivers/target/uasp/uasp_fabric.h new file +37 -0
@@ -0,0 +1,37 @@ +int uasp_check_true (struct se_portal_group *); +int uasp_check_false (struct se_portal_group *); +char *uasp_get_fabric_name (void ); +u8 uasp_get_fabric_proto_ident (struct se_portal_group *); +char *uasp_get_fabric_wwn (struct se_portal_group *); +u16 uasp_get_tag (struct se_portal_group *); +u32 uasp_get_default_depth (struct se_portal_group *); +u32 uasp_get_pr_transport_id (struct se_portal_group *, +struct se_node_acl *,struct t10_pr_registration *, +int *,unsigned char *); +u32 uasp_get_pr_transport_id_len (struct se_portal_group *, +struct se_node_acl *,struct t10_pr_registration *, +int *); +char *uasp_parse_pr_out_transport_id (struct se_portal_group *, +const char *,u32 *,char **); +struct se_node_acl *uasp_alloc_fabric_acl (struct se_portal_group *); +void uasp_release_fabric_acl (struct se_portal_group *, +struct se_node_acl *); +u32 uasp_tpg_get_inst_index (struct se_portal_group *); +void uasp_release_cmd (struct se_cmd *); +int uasp_shutdown_session (struct se_session *); +void uasp_close_session (struct se_session *); +void uasp_stop_session (struct se_session *,int ,int ); +void uasp_reset_nexus (struct se_session *); +int uasp_sess_logged_in (struct se_session *); +u32 uasp_sess_get_index (struct se_session *); +int uasp_write_pending (struct se_cmd *); +int uasp_write_pending_status (struct se_cmd *); +void uasp_set_default_node_attrs (struct se_node_acl *); +u32 uasp_get_task_tag (struct se_cmd *); +int uasp_get_cmd_state (struct se_cmd *); +int uasp_queue_data_in (struct se_cmd *); +int uasp_queue_status (struct se_cmd *); +int uasp_queue_tm_rsp (struct se_cmd *); +u16 uasp_set_fabric_sense_len (struct se_cmd *,u32 ); +u16 uasp_get_fabric_sense_len (void ); +int uasp_is_state_remove (struct se_cmd *);
drivers/usb/gadget/Kconfig +3 -0
@@ -774,6 +774,9 @@ config USB_MASS_STORAGE Say "y" to link the driver statically, or "m" to build a dynamically linked module called "g_mass_storage". +comment "You need to go to the target framework for UASP support" + depends on TARGET_UASP=n + config USB_G_SERIAL tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" help
Sebastian
Re: [RFC] UASP on target (was: [RFC/PATCH v4 1/3] uas: MS UAS Gadget driver - Infrastructure)
Hi,
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 5 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 3 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
Quoted 7 lines
Quoted 7 lines
hch said to use target framework and you haven't done so. This is what I have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.
This is much better, indeed, but the way it is now, it's only usable by the gadget framework because you have put the function driver on the transport layer. I wonder if there wouldn't be a simple way to split the "SCSI Over USB" part in a more generic way which could be shared between gadget side UASP and host side UASP drivers ?!? Maybe ?!?
The drivers/target/uasp_*.c would really be just a transport layer and gadget/host drivers would make calls to that "library" ? Something like that ??
Signature · 1 line
balbi
Re: [RFC] UASP on target
Quoted 1 line · Felipe Balbi
Hi,
Hi,
Quoted 22 lines · Sebastian Andrzej Siewior
Quoted 7 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 6 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
Quoted 4 lines
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
Quoted 7 lines
Quoted 7 lines
hch said to use target framework and you haven't done so. This is what I have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.This is much better, indeed, but the way it is now, it's only usable by the gadget framework because you have put the function driver on the transport layer. I wonder if there wouldn't be a simple way to split the "SCSI Over USB" part in a more generic way which could be shared between gadget side UASP and host side UASP drivers ?!? Maybe ?!?
Quoted 3 lines
The
drivers/target/uasp_*.cwould really be just a transport layer and gadget/host drivers would make calls to that "library" ? Something like that ??
There is very little code that is not host specific. For instance uas_alloc_cmd_urb() is something that could be used on both side but the host is boxing the command and I need to unbox it. So I don't see how I could share things except for the defines.
Most of the things are usb specific. So UAS gets the commands from the scsi framework, puts the usb layer around it and sends them.
Sebastian
Re: [RFC] UASP on target
Quoted 30 lines · Sebastian Andrzej Siewior
Quoted 1 line · Felipe Balbi
Hi,
Hi,
Quoted 22 lines · Sebastian Andrzej Siewior
Quoted 7 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 6 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
Quoted 4 lines
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
Quoted 7 lines
Quoted 7 lines
hch said to use target framework and you haven't done so. This is what I have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.This is much better, indeed, but the way it is now, it's only usable by the gadget framework because you have put the function driver on the transport layer. I wonder if there wouldn't be a simple way to split the "SCSI Over USB" part in a more generic way which could be shared between gadget side UASP and host side UASP drivers ?!? Maybe ?!?
Quoted 3 lines
The
drivers/target/uasp_*.cwould really be just a transport layer and gadget/host drivers would make calls to that "library" ? Something like that ??
Quoted 6 lines
There is very little code that is not host specific. For instance
uas_alloc_cmd_urb()is something that could be used on both side but the host is boxing the command and I need to unbox it. So I don't see how I could share things except for the defines.
Most of the things are usb specific. So UAS gets the commands from the scsi framework, puts the usb layer around it and sends them.
k, fair enough ;-) Just thought there'd be a better way to share this code with host side implementation. Nevermind then
Signature · 1 line
balbi
Re: [RFC] UASP on target
Quoted 43 lines · Sebastian Andrzej Siewior
Quoted 34 lines · Felipe Balbi
Quoted 1 line
Hi,
Hi,
Quoted 1 line
On Mon, Dec 05, 2011 at 09:23:26AM +0100, Sebastian Andrzej Siewior
Quoted 8 lines · wrote:
Quoted 8 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 7 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
Quoted 4 lines
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
hch said to use target framework and you haven't done so. This is
what I
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.This is much better, indeed, but the way it is now, it's only usable by the gadget framework because you have put the function driver on the transport layer. I wonder if there wouldn't be a simple way to split
the
Quoted 1 line
"SCSI Over USB" part in a more generic way which could be shared
between
Quoted 5 lines
gadget side UASP and host side UASP drivers ?!? Maybe ?!?
The
drivers/target/uasp_*.cwould really be just a transport layer and gadget/host drivers would make calls to that "library" ? Something like that ??Quoted 6 lines
There is very little code that is not host specific. For instance
uas_alloc_cmd_urb()is something that could be used on both side but the host is boxing the command and I need to unbox it. So I don't see how I could share things except for the defines.
Most of the things are usb specific. So UAS gets the commands from the scsi framework, puts the usb layer around it and sends them.
Quoted 6 lines
k, fair enough ;-) Just thought there'd be a better way to share this code with host side implementation. Nevermind then
--
balbi
Hi guys,
Thanks for your quick response.
We are glad to see that our initial implementation is being used and gaining momentum.
We intend to learn and re-implement the UAS protocol using the target framework, and continue our work started few months ago.
We hope to get your corporation in the future as well.
Thanks,
Shimrit
Signature · 2 lines
Consultant for Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Re: [RFC] UASP on target
Quoted 50 lines · Shimrit Malichi
Quoted 43 lines · Sebastian Andrzej Siewior
Quoted 34 lines · Felipe Balbi
Quoted 1 line
Hi,
Hi,
Quoted 1 line
On Mon, Dec 05, 2011 at 09:23:26AM +0100, Sebastian Andrzej Siewior
Quoted 8 lines · wrote:
Quoted 8 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 7 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
Quoted 4 lines
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
hch said to use target framework and you haven't done so. This is
what I
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.This is much better, indeed, but the way it is now, it's only usable by the gadget framework because you have put the function driver on the transport layer. I wonder if there wouldn't be a simple way to split
the
Quoted 1 line
"SCSI Over USB" part in a more generic way which could be shared
between
Quoted 5 lines
gadget side UASP and host side UASP drivers ?!? Maybe ?!?
The
drivers/target/uasp_*.cwould really be just a transport layer and gadget/host drivers would make calls to that "library" ? Something like that ??Quoted 6 lines
There is very little code that is not host specific. For instance
uas_alloc_cmd_urb()is something that could be used on both side but the host is boxing the command and I need to unbox it. So I don't see how I could share things except for the defines.
Most of the things are usb specific. So UAS gets the commands from the scsi framework, puts the usb layer around it and sends them.Quoted 6 lines
k, fair enough ;-) Just thought there'd be a better way to share this code with host side implementation. Nevermind then
--
balbi
Quoted 8 lines
Hi guys,
Thanks for your quick response.
We are glad to see that our initial implementation is being used and gaining momentum.We intend to learn and re-implement the UAS protocol using the target framework, and continue our work started few months ago.
Sebastian has been doing for the last few days or so, you guys should join efforts to avoid duplicated work.
Quoted 1 line
We hope to get your corporation in the future as well.
sorry, but I'm not allowed to you my corporation. Hope my cooperation is enough :-)
Signature · 1 line
balbi
Re: [RFC] UASP on target (was: [RFC/PATCH v4 1/3] uas: MS UAS Gadget driver - Infrastructure)
In reply to Sebastian Andrzej SiewiorQuoted 7 lines · Sebastian Andrzej Siewior
Quoted 5 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 3 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
Quoted 7 lines
Quoted 7 lines
hch said to use target framework and you haven't done so. This is what I have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.
Evidently you were able to find enough information about the target framework to write a driver using it. Can you tell us where this information is? It hasn't been easy to locate.
Alan Stern
Re: [RFC] UASP on target
Quoted 3 lines · Alan Stern
Evidently you were able to find enough information about the target framework to write a driver using it. Can you tell us where this information is? It hasn't been easy to locate.
Hehe. Well, I've been told that the target framework has everything one
needs to get it done so I've been digging in the code. First I tried to
come up with an easy setup where I can use it. _This_ was already hard
to get done for someone who is not familiar with scsi. Once I had all
pieces together I wrote this [0].With this information I know more or
less how that thing works or should work.
So at this point I understood that I need to comeup with somethin liketcm_loop or tcm_vhost. Looking at the host side of the uas driver it is
using SAS as the protocol and nothing special if you ignore "struct iu"
for a moment.
Then I found the python script in Documentation/target which creates you a skeleton driver. So I used this and started hacking. First I took the usb descriptors and looked what happens after I connected thedummy_hcd driver/gadget. I received a usb command message. So now I try to wire it up in target. I look at the loopback/vhost_scsi for some inspiration. Other than that I have no additional information....
[0] http://article.gmane.org/gmane.linux.scsi.target.devel/654
Quoted 1 line
Alan Stern
Sebastian
Re: [RFC] UASP on target (was: [RFC/PATCH v4 1/3] uas: MS UAS Gadget driver - Infrastructure)
In reply to Sebastian Andrzej SiewiorQuoted 7 lines · Sebastian Andrzej Siewior
Quoted 5 lines · * Sebastian Andrzej Siewior | 2011-12-05 09:20:47 [+0100]:
Quoted 3 lines · * Shimrit Malichi | 2011-12-04 21:53:09 [+0200]:
This patch implements the infrastructure for the UAS gadget driver. The UAS gadget driver registers as a second configuration of the MS gadet driver.
Quoted 8 lines
Quoted 7 lines
hch said to use target framework and you haven't done so. This is what I have so far. It is not yet complete. What I need to do is:
- wire up command processing (currently here)
- wire up data processing
- check it works => post v1
- wire up command tagging => v2
- remove hard codings and fix whatever people complained about.
Hi Sebastian,
So this looks like a reasonable first step to get a control plane up for /sys/kernel/config/target/uasp/. I have not at the USB parts beyond the initial patch so I can't really comment there, but thanks for using tcm_mod_builder.py to generate your initial skeleton.
Just a minor few comments below on the target-related pieces below, and a few comments to keep in mind for he main I/O path with struct uasp_cmd->se_cmd descriptor usage.
Quoted 26 lines
drivers/target/Kconfig +1
-0@@ -50,3 +50,4 @@ source "drivers/target/tcm_qla2xxx/Kconfig" source "drivers/target/tcm_vhost/Kconfig" endif +source "drivers/target/uasp/Kconfig"drivers/target/Makefile +1
-0@@ -28,3 +28,4 @@ obj-$(CONFIG_TCM_FC) += tcm_fc/ obj-$(CONFIG_ISCSI_TARGET) += iscsi/ obj-$(CONFIG_TCM_QLA2XXX) += tcm_qla2xxx/ obj-$(CONFIG_TCM_VHOST) += tcm_vhost/ +obj-$(CONFIG_TARGET_UASP) += uasp/drivers/target/target_core_configfs.c +0
-0@@ -162,6 +162,13 @@ static struct config_group *target_core_register_fabric( " tcm_loop.ko: %d\n", ret);return ERR_PTR (-EINVAL ); }
drivers/target/target_core_configfs.c static struct config_group *target_core_register_fabric( · line 174
Quoted 10 lines
drivers/target/target_core_configfs.c +7
-0+ }else if (!strncmp (name,"uasp" ,4 )) { + ret =request_module ("tcm_uasp" ); +if (ret <0 ) { +pr_err ("request_module() failed for" +" tcm_loop.ko: %d\n" , ret); +return ERR_PTR (-EINVAL ); + } } tf =target_core_get_fabric (name);
So making the request_module() calls was an original feature of v3.x target core code, but this is not strictly required for normal usage after loading the module, or with rtslib /var/target/spec/uasp.spec usage.
As we are trying to avoid extra request_module() usage in target-core, please go ahead and drop this part for now..
Quoted 25 lines
drivers/target/uasp/Kconfig new file +6
-0@@ -0,0 +1,6 @@ +config TARGET_UASP + tristate "UASP fabric module" + depends on TARGET_CORE && CONFIGFS_FS + depends on USB_GADGET + ---help--- + Say Y here to enable the UASP fabric moduledrivers/target/uasp/Makefile new file +5
-0@@ -0,0 +1,5 @@ +CFLAGS_gadget.o := -I$(srctree)/drivers/usb/gadget +tcm_uasp-objs := uasp_fabric.o \ + gadget.o \ + uasp_configfs.o +obj-$(CONFIG_TARGET_UASP) += tcm_uasp.odrivers/target/uasp/gadget.c new file +0
-0
<SNIP>
Quoted 38 lines
drivers/target/uasp/uasp_configfs.c new file +32
-0@@ -0,0 +1,333 @@ +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/version.h> +#include <generated/utsrelease.h> +#include <linux/utsname.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/kthread.h> +#include <linux/types.h> +#include <linux/string.h> +#include <linux/configfs.h> +#include <linux/ctype.h> +#include <asm/unaligned.h> + +#include <target/target_core_base.h> +#include <target/target_core_fabric.h> +#include <target/target_core_fabric_configfs.h> +#include <target/target_core_configfs.h> +#include <target/configfs_macros.h> + +#include "uasp_base.h" +#include "uasp_fabric.h" +#include "gadget_ops.h" + +/* Local pointer to allocated TCM configfs fabric module */ +struct target_fabric_configfs *uasp_fabric_configfs; + +static const char *uasp_check_wwn (const char *name) +{ +const char *n; +unsigned int len; +
drivers/target/uasp/uasp_configfs.c line 42
Quoted 10 lines
drivers/target/uasp/uasp_configfs.c new file +10
-0+ n =strstr (name,"naa." ); +if (!n) +return NULL ; + n +=4 ; + len =strlen (n); +if (len ==0 || len >UASP_NAMELEN -1 ) +return NULL ; +return n; +} +
Note this is currently using naa. prefixed targetnames for UASP endpoints, as loopback does with SAS proto_id port emulation..
Quoted 6 lines
drivers/target/uasp/uasp_configfs.c new file +6
-0+int uasp_register_configfs (void ) +{ +struct target_fabric_configfs *fabric; +int ret; + + printk(KERN_INFO "UASP fabric module %s on %s/%s"
drivers/target/uasp/uasp_configfs.c line 291
Quoted 10 lines
drivers/target/uasp/uasp_configfs.c new file +10
-0+" on " UTS_RELEASE "\n" ,UASP_VERSION ,utsname ()->sysname, + utsname()->machine); +/* +* Register the top level struct config_item_type with TCM core +*/ + fabric =target_fabric_configfs_init (THIS_MODULE ,"uasp" ); +if (!(fabric)) { +printk (KERN_ERR "target_fabric_configfs_init() failed\n" ); +return -ENOMEM ; + }
This should be checking using IS_ERR() with fabric, which is a current bug in tcm_mod_builder.py
Quoted 213 lines
drivers/target/uasp/uasp_configfs.c new file +42
-0+/* +* Setup fabric->tf_ops from our local uasp_ops +*/ + fabric->tf_ops = uasp_ops; +/* +* Setup default attribute lists for various fabric->tf_cit_tmpl +*/ +TF_CIT_TMPL (fabric)->tfc_wwn_cit.ct_attrs = uasp_wwn_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_base_cit.ct_attrs = uasp_base_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_attrib_cit.ct_attrs =NULL ; +TF_CIT_TMPL (fabric)->tfc_tpg_param_cit.ct_attrs =NULL ; +TF_CIT_TMPL (fabric)->tfc_tpg_np_base_cit.ct_attrs =NULL ; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_base_cit.ct_attrs =NULL ; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs =NULL ; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_auth_cit.ct_attrs =NULL ; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_param_cit.ct_attrs =NULL ; +/* +* Register the fabric for use within TCM +*/ + ret =target_fabric_configfs_register (fabric); +if (ret <0 ) { +printk (KERN_ERR "target_fabric_configfs_register() failed" +" for UASP\n" ); +return ret; + } +/* +* Setup our local pointer to *fabric +*/ + uasp_fabric_configfs = fabric; +printk (KERN_INFO "UASP[0] - Set fabric -> uasp_fabric_configfs\n" ); +return 0 ; +}; + +void uasp_deregister_configfs (void ) +{ +if (!(uasp_fabric_configfs)) +return ; + +target_fabric_configfs_deregister (uasp_fabric_configfs); + uasp_fabric_configfs =NULL ; +printk (KERN_INFO "UASP[0] - Cleared uasp_fabric_configfs\n" ); +};drivers/target/uasp/uasp_fabric.c new file +164
-0@@ -0,0 +1,287 @@ +#include <linux/slab.h> +#include <linux/kthread.h> +#include <linux/types.h> +#include <linux/list.h> +#include <linux/types.h> +#include <linux/string.h> +#include <linux/ctype.h> +#include <asm/unaligned.h> +#include <scsi/scsi.h> +#include <scsi/scsi_host.h> +#include <scsi/scsi_device.h> +#include <scsi/scsi_cmnd.h> +#include <scsi/libfc.h> + +#include <target/target_core_base.h> +#include <target/target_core_fabric.h> +#include <target/target_core_configfs.h> + +#include "uasp_base.h" +#include "uasp_fabric.h" + +int uasp_check_true (struct se_portal_group *se_tpg) +{ +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return 1 ; +} + +int uasp_check_false (struct se_portal_group *se_tpg) +{ +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return 0 ; +} + +char *uasp_get_fabric_name (void ) +{ +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return "uasp" ; +} + +u8 uasp_get_fabric_proto_ident (struct se_portal_group *se_tpg) +{ +struct uasp_tpg *tpg =container_of (se_tpg, + struct uasp_tpg, se_tpg); +struct uasp_tport *tport = tpg->tport; +u8 proto_id; + +switch (tport->tport_proto_id) { +case SCSI_PROTOCOL_SAS : +default : + proto_id =sas_get_fabric_proto_ident (se_tpg); +break ; + } + +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return proto_id; +} + +char *uasp_get_fabric_wwn (struct se_portal_group *se_tpg) +{ +struct uasp_tpg *tpg =container_of (se_tpg, + struct uasp_tpg, se_tpg); +struct uasp_tport *tport = tpg->tport; + +printk (KERN_ERR "%s(%d) '%s'\n" , __func__, __LINE__, tport->tport_name); +return &tport->tport_name[0 ]; +} + +u16 uasp_get_tag (struct se_portal_group *se_tpg) +{ +struct uasp_tpg *tpg =container_of (se_tpg, + struct uasp_tpg, se_tpg); +printk (KERN_ERR "%s(%d) %d\n" , __func__, __LINE__, tpg->tport_tpgt); +return tpg->tport_tpgt; +} + +u32 uasp_get_default_depth (struct se_portal_group *se_tpg) +{ +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return 1 ; +} + +u32 uasp_get_pr_transport_id ( +struct se_portal_group *se_tpg, +struct se_node_acl *se_nacl, +struct t10_pr_registration *pr_reg, +int *format_code, +unsigned char *buf) +{ +struct uasp_tpg *tpg =container_of (se_tpg, + struct uasp_tpg, se_tpg); +struct uasp_tport *tport = tpg->tport; +int ret =0 ; + +switch (tport->tport_proto_id) { +case SCSI_PROTOCOL_SAS : +default : + ret =sas_get_pr_transport_id (se_tpg, se_nacl, pr_reg, + format_code, buf); +break ; + } + +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return ret; +} + +u32 uasp_get_pr_transport_id_len ( +struct se_portal_group *se_tpg, +struct se_node_acl *se_nacl, +struct t10_pr_registration *pr_reg, +int *format_code) +{ +struct uasp_tpg *tpg =container_of (se_tpg, + struct uasp_tpg, se_tpg); +struct uasp_tport *tport = tpg->tport; +int ret =0 ; + +switch (tport->tport_proto_id) { +case SCSI_PROTOCOL_SAS : +default : + ret =sas_get_pr_transport_id_len (se_tpg, se_nacl, pr_reg, + format_code); +break ; + } + +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return ret; +} + +char *uasp_parse_pr_out_transport_id ( +struct se_portal_group *se_tpg, +const char *buf, +u32 *out_tid_len, +char **port_nexus_ptr) +{ +struct uasp_tpg *tpg =container_of (se_tpg, + struct uasp_tpg, se_tpg); +struct uasp_tport *tport = tpg->tport; +char *tid =NULL ; + +switch (tport->tport_proto_id) { +case SCSI_PROTOCOL_SAS : +default : + tid =sas_parse_pr_out_transport_id (se_tpg, buf, out_tid_len, + port_nexus_ptr); + } + +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return tid; +} + +struct se_node_acl *uasp_alloc_fabric_acl (struct se_portal_group *se_tpg) +{ +struct uasp_nacl *nacl; + + nacl =kzalloc (sizeof (struct uasp_nacl ),GFP_KERNEL ); +if (!(nacl)) { +printk (KERN_ERR "Unable to alocate struct uasp_nacl\n" ); +return NULL ; + } + +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +return &nacl->se_node_acl; +} +
drivers/target/uasp/uasp_fabric.c line 174
Quoted 10 lines
drivers/target/uasp/uasp_fabric.c new file +10
-0+void uasp_release_fabric_acl ( +struct se_portal_group *se_tpg, +struct se_node_acl *se_nacl) +{ +struct uasp_nacl *nacl =container_of (se_nacl, + struct uasp_nacl, se_node_acl); +printk (KERN_ERR "%s(%d)\n" , __func__, __LINE__); +kfree (nacl); +} +
<SNIP>
So for the primary incoming I/O path, you'll want to be using the new target_submit_cmd() call that we've been working on in lio-core.git/qla_tgt-3.3 recently, as this will simplify incoming I/O + exception handling for struct uasp_cmd from processing context usage.
Also, do you expect this new driver to pass pre-populated scatterlists, or to leave se_cmd->t_data_sg allocation up to target-core..? Depending on the expected usage this will look slightly different from the current usage in tcm_loop/tcm_vhost that both pass pre-populated scatterlists from Linux/SCSI.
Aside from that, let me know if you have questions while filling in the write_pending and response (queue_data_in + queue_status) fabric callbacks.
Thanks!
--nab
Re: [RFC] UASP on target
Quoted 1 line · Nicholas A. Bellinger
Hi Sebastian,
Hi Nicholas,
Quoted 4 lines
So this looks like a reasonable first step to get a control plane up for
/sys/kernel/config/target/uasp/. I have not at the USB parts beyond the initial patch so I can't really comment there, but thanks for usingtcm_mod_builder.pyto generate your initial skeleton.
Thanks for providing the skeleton building script :)
I don't have more yet. Storage on USB should provide two
configurations: BOT and UASP. BOT is currently served by drivers/usb /gadget/mass_storage.c. The configuration (modprobe parameters) and protocol handling is done there. Since UASP brings its own configuration I think that it will be too complicated to merge both code basis (not to mention the way both handling things internally). So I decided first to integrate UASP with target and then worry about BOT.
Quoted 39 lines
Just a minor few comments below on the target-related pieces below, and a few comments to keep in mind for he main I/O path with struct
uasp_cmd->se_cmddescriptor usage.Quoted 35 lines
drivers/target/Kconfig +1
-0@@ -50,3 +50,4 @@ source "drivers/target/tcm_qla2xxx/Kconfig" source "drivers/target/tcm_vhost/Kconfig" endif +source "drivers/target/uasp/Kconfig"drivers/target/Makefile +1
-0@@ -28,3 +28,4 @@ obj-$(CONFIG_TCM_FC) += tcm_fc/ obj-$(CONFIG_ISCSI_TARGET) += iscsi/ obj-$(CONFIG_TCM_QLA2XXX) += tcm_qla2xxx/ obj-$(CONFIG_TCM_VHOST) += tcm_vhost/ +obj-$(CONFIG_TARGET_UASP) += uasp/drivers/target/target_core_configfs.c +7
-0@@ -162,6 +162,13 @@ static struct config_group *target_core_register_fabric( " tcm_loop.ko: %d\n", ret);return ERR_PTR (-EINVAL ); } + }else if (!strncmp (name,"uasp" ,4 )) { + ret =request_module ("tcm_uasp" ); +if (ret<0 ) { +pr_err ("request_module() failed for" +" tcm_loop.ko: %d\n" , ret); +return ERR_PTR (-EINVAL ); + } }
Quoted 6 lines
drivers/target/target_core_configfs.c static struct config_group *target_core_register_fabric( · line 174
Quoted 1 line
drivers/target/target_core_configfs.c +0
-0tf =target_core_get_fabric (name);So making the
request_module()calls was an original feature of v3.x target core code, but this is not strictly required for normal usage after loading the module, or with rtslib/var/target/spec/uasp.specusage.
I see.
Quoted 2 lines
As we are trying to avoid extra
request_module()usage in target-core, please go ahead and drop this part for now..
Okay.
Quoted 43 lines
Quoted 43 lines
drivers/target/uasp/uasp_configfs.c new file +37
-0@@ -0,0 +1,333 @@ +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/version.h> +#include <generated/utsrelease.h> +#include <linux/utsname.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/kthread.h> +#include <linux/types.h> +#include <linux/string.h> +#include <linux/configfs.h> +#include <linux/ctype.h> +#include <asm/unaligned.h> + +#include <target/target_core_base.h> +#include <target/target_core_fabric.h> +#include <target/target_core_fabric_configfs.h> +#include <target/target_core_configfs.h> +#include <target/configfs_macros.h> + +#include "uasp_base.h" +#include "uasp_fabric.h" +#include "gadget_ops.h" + +/* Local pointer to allocated TCM configfs fabric module */ +struct target_fabric_configfs *uasp_fabric_configfs; + +static const char *uasp_check_wwn (const char *name) +{ +const char *n; +unsigned int len; + + n =strstr (name,"naa." ); +if (!n) +return NULL ; + n +=4 ; + len =strlen (n);
Quoted 8 lines
drivers/target/uasp/uasp_configfs.c line 42
Quoted 5 lines
drivers/target/uasp/uasp_configfs.c new file +5
-0+if (len ==0 || len>UASP_NAMELEN -1 ) +return NULL ; +return n; +} +Note this is currently using naa. prefixed targetnames for UASP endpoints, as loopback does with SAS
proto_idport emulation..
Not sure if this is the right thing to do. I've seen it in loop and vhost that once "naa." has been found, the protocol was set to SAS. I think I have to use SAS so I am using the same prefix here.
Quoted 11 lines
Quoted 11 lines
drivers/target/uasp/uasp_configfs.c new file +11
-0+int uasp_register_configfs (void ) +{ +struct target_fabric_configfs *fabric; +int ret; + +printk (KERN_INFO "UASP fabric module %s on %s/%s" +" on " UTS_RELEASE "\n" ,UASP_VERSION ,utsname ()->sysname, +utsname ()->machine); +/* +* Register the top level struct config_item_type with TCM core +*/
Quoted 8 lines
drivers/target/uasp/uasp_configfs.c line 291
Quoted 5 lines
drivers/target/uasp/uasp_configfs.c new file +5
-0+ fabric =target_fabric_configfs_init (THIS_MODULE ,"uasp" ); +if (!(fabric)) { +printk (KERN_ERR "target_fabric_configfs_init() failed\n" ); +return -ENOMEM ; + }This should be checking using
IS_ERR()with fabric, which is a current bug intcm_mod_builder.py
Okay, will fix in both.
Quoted 6 lines
<SNIP>
So for the primary incoming I/O path, you'll want to be using the new
target_submit_cmd()call that we've been working on in lio-core.git/qla_tgt-3.3 recently, as this will simplify incoming I/O + exception handling for structuasp_cmdfrom processing context usage.
Okay, will look at that.
Quoted 5 lines
Also, do you expect this new driver to pass pre-populated scatterlists, or to leave
se_cmd->t_data_sgallocation up to target-core..? Depending on the expected usage this will look slightly different from the current usage in tcm_loop/tcm_vhost that both pass pre-populated scatterlists from Linux/SCSI.
USB has IN and OUT packets. OUT packets are sent by the HOST (received by the UDC or device and IN packets are received by the host and ..... OUT and IN is always seen / described from HOST's point of view. That means USB-OUT packet for the device is "receive-data". I have to queue an USB-OUT packet for the endpoint that receives the
command. For that I have to allocate memory. That means cdb + sense can
be part of that. For both I don't know the exact size. For cdb I
allocate maxpacket size (that is 512 bytes for high speed and 1024
bytes for super speed) memory and I receive the size, the host sent to
me.
For DATA-IN/OUT transfers I think it would be easier to let the core
allocate the memory. After all I don't know the exact size of the
transfer. We don't have scatterlist support on the gadget framework yet
but Felipe is looking into. So sgl is perfect, will provide a buffer
fallback and people may udpate their drivers if it is too slow :)
Quoted 3 lines
Aside from that, let me know if you have questions while filling in the
write_pendingand response (queue_data_in+queue_status) fabric callbacks.
Thanks for that. Once I have something I try to come up with a sane question :)
Quoted 3 lines
Thanks!
--nab
Sebastian