Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb: device_next: new USB Mass Storage implementation #54776

Merged
merged 1 commit into from
Feb 24, 2023

Conversation

tmon-nordic
Copy link
Contributor

Introduce new USB Mass Storage Bulk-Only Transport implementation written from scratch. Main goal behind new implementation was to separate USB and SCSI parts as clearly as possible.

Limited set of SCSI disk commands is implemented in separate source code file that is internal to USB device stack. While it should be possible to use the SCSI implementation by other components there is currently no other user besides USB MSC and therefore SCSI header is kept private.

Signed-off-by: Tomasz Moń tomasz.mon@nordicsemi.no

include/zephyr/usb/class/usbd_msc.h Outdated Show resolved Hide resolved
subsys/usb/device_next/class/Kconfig.msc Outdated Show resolved Hide resolved
subsys/usb/device_next/class/Kconfig.msc Show resolved Hide resolved
subsys/usb/device_next/class/usbd_msc.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/usbd_msc.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/usbd_msc.c Outdated Show resolved Hide resolved
* to allow generating boilerplate handling code.
*/
#define SCSI_CMD_STRUCT(opcode) struct scsi_##opcode##_cmd
#define SCSI_CMD_HANDLER(opcode) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not obscure it for about 10 definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree. This macro enforces common calling scheme for all commands.

#define SCSI_CMD_HANDLER(opcode) \
static int scsi_##opcode(struct scsi_ctx *ctx, \
struct scsi_##opcode##_cmd *cmd, \
uint8_t data_in_buf[CONFIG_USBD_MSC_SCSI_BUFFER_SIZE])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is not data_out_buf, I suggest to name just data, or buf.

Suggested change
uint8_t data_in_buf[CONFIG_USBD_MSC_SCSI_BUFFER_SIZE])
uint8_t *const data)

or one that generates a warning

Suggested change
uint8_t data_in_buf[CONFIG_USBD_MSC_SCSI_BUFFER_SIZE])
uint8_t data[static CONFIG_USBD_MSC_SCSI_BUFFER_SIZE])

Copy link
Contributor Author

@tmon-nordic tmon-nordic Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no data_out_buf passed to handler directly because the data out is not available at this time. If the command is not supported (or command wants to process more data than indicated in CBW, or wants to send data instead of receive), we want to STALL OUT endpoint immediately to not waste time receiving any Data Out. Besides that, having both data_in_buf and data_out_buf would require allocating two buffers but considering how USB Bulk-Only Transport SCSI transport works it is perfectly fine to have common shared buffer.

"Data-In Buffer" and "Data-Out Buffer" are the terms used in SAM-6 (5.4.2.2 Send SCSI Command SCSI transport protocol service request) so I refuse to change the name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Data-In Buffer" and "Data-Out Buffer" are the terms used in SAM-6 (5.4.2.2 Send SCSI Command SCSI transport protocol service request) so I refuse to change the name.

okay, but why not uint8_t data_in_buf[static CONFIG_USBD_MSC_SCSI_BUFFER_SIZE]), otherwise I do not see a reason to use sized array parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to look it up what static means in this context and it means what I really want. Added static to all declarations.

subsys/usb/device_next/class/usbd_msc_scsi.c Outdated Show resolved Hide resolved
subsys/usb/device_next/class/usbd_msc_scsi.c Show resolved Hide resolved
@tmon-nordic tmon-nordic force-pushed the usbd-msc branch 3 times, most recently from 0072307 to 780a709 Compare February 24, 2023 10:45
Introduce new USB Mass Storage Bulk-Only Transport implementation
written from scratch. Main goal behind new implementation was to
separate USB and SCSI parts as clearly as possible.

Limited set of SCSI disk commands is implemented in separate source code
file that is internal to USB device stack. While it should be possible
to use the SCSI implementation by other components there is currently no
other user besides USB MSC and therefore SCSI header is kept private.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
@carlescufi carlescufi merged commit 509c033 into zephyrproject-rtos:main Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants