From 1b3c4cb1e392bf9365ac633d305c6a1aac9b94e1 Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Wed, 2 Sep 2020 13:06:06 +0200 Subject: dfu: Fix handling of UBI partitions in MTD backend For UBI partitions ("partubi" in dfu_alt_info), dfu_fill_entity_mtd sets the mtd.ubi flag; however other functions incorrectly check for nand.ubi instead. Fix this by checking for the correct flag. Signed-off-by: Guillermo Rodriguez Cc: Lukasz Majewski Reviewed-by: Patrick Delaunay --- drivers/dfu/dfu_mtd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c index b34975d..ca67585 100644 --- a/drivers/dfu/dfu_mtd.c +++ b/drivers/dfu/dfu_mtd.c @@ -204,7 +204,7 @@ static int dfu_flush_medium_mtd(struct dfu_entity *dfu) int ret; /* in case of ubi partition, erase rest of the partition */ - if (dfu->data.nand.ubi) { + if (dfu->data.mtd.ubi) { struct erase_info erase_op = {}; erase_op.mtd = dfu->data.mtd.info; @@ -242,7 +242,7 @@ static unsigned int dfu_polltimeout_mtd(struct dfu_entity *dfu) * ubi partition, as sectors which are not used need * to be erased */ - if (dfu->data.nand.ubi) + if (dfu->data.mtd.ubi) return DFU_MANIFEST_POLL_TIMEOUT; return DFU_DEFAULT_POLL_TIMEOUT; -- cgit v1.1 From 8b387f112bc96688d40281fc22531863eb812511 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 16 Oct 2020 16:29:02 +0900 Subject: gadget: f_thor: fix wrong file size cast Casting 32bit int value directly into 64bit unsigned type causes wrong value for file size equal or larger than 2GB. Fix the wrong file size by casting uint32_t first. Fixes: commit 1fe9ae76b113 ("gadget: f_thor: update to support more than 4GB file as thor 5.0") Reported-by: Junghoon Kim Signed-off-by: Seung-Woo Kim Reviewed-by: Jaehoon Chung --- drivers/usb/gadget/f_thor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index 88fc87f..559ffb7 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -266,8 +266,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt) switch (rqt->rqt_data) { case RQT_DL_INIT: - thor_file_size = (unsigned long long int)rqt->int_data[0] + - (((unsigned long long int)rqt->int_data[1]) + thor_file_size = (uint64_t)(uint32_t)rqt->int_data[0] + + (((uint64_t)(uint32_t)rqt->int_data[1]) << 32); debug("INIT: total %llu bytes\n", thor_file_size); break; @@ -280,8 +280,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt) break; } - thor_file_size = (unsigned long long int)rqt->int_data[1] + - (((unsigned long long int)rqt->int_data[2]) + thor_file_size = (uint64_t)(uint32_t)rqt->int_data[1] + + (((uint64_t)(uint32_t)rqt->int_data[2]) << 32); memcpy(f_name, rqt->str_data[0], F_NAME_BUF_SIZE); f_name[F_NAME_BUF_SIZE] = '\0'; -- cgit v1.1 From 0234609d9631652e2faf77e23f332be29570d7d2 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 3 Dec 2020 17:32:03 +0200 Subject: f_rockusb: Use NULL instead of 0 for pointers get_rkusb() mistakenly uses integers without cast. Convert them to proper type. Signed-off-by: Andy Shevchenko --- drivers/usb/gadget/f_rockusb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_rockusb.c b/drivers/usb/gadget/f_rockusb.c index 9ae02ae..9dd10f9 100644 --- a/drivers/usb/gadget/f_rockusb.c +++ b/drivers/usb/gadget/f_rockusb.c @@ -110,7 +110,7 @@ struct f_rockusb *get_rkusb(void) if (!f_rkusb) { f_rkusb = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*f_rkusb)); if (!f_rkusb) - return 0; + return NULL; rockusb_func = f_rkusb; memset(f_rkusb, 0, sizeof(*f_rkusb)); @@ -120,7 +120,7 @@ struct f_rockusb *get_rkusb(void) f_rkusb->buf_head = memalign(CONFIG_SYS_CACHELINE_SIZE, RKUSB_BUF_SIZE); if (!f_rkusb->buf_head) - return 0; + return NULL; f_rkusb->buf = f_rkusb->buf_head; memset(f_rkusb->buf_head, 0, RKUSB_BUF_SIZE); -- cgit v1.1 From ff52577c1b5188a5f25bd7d7d41730bb5de4b688 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 3 Dec 2020 17:32:04 +0200 Subject: f_rockusb: Avoid use-after-free in the global pointer variable In case of usb_add_function() failure the error path has two issues: - the potentially allocated structure isn't getting freed - the global pointer variable is assigned to garbage Fix the above mentioned issues by freeing memory and assigning NULL. Signed-off-by: Andy Shevchenko --- drivers/usb/gadget/f_rockusb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_rockusb.c b/drivers/usb/gadget/f_rockusb.c index 9dd10f9..bd846ce 100644 --- a/drivers/usb/gadget/f_rockusb.c +++ b/drivers/usb/gadget/f_rockusb.c @@ -309,8 +309,9 @@ static int rockusb_add(struct usb_configuration *c) status = usb_add_function(c, &f_rkusb->usb_function); if (status) { + free(f_rkusb->buf_head); free(f_rkusb); - rockusb_func = f_rkusb; + rockusb_func = NULL; } return status; } -- cgit v1.1 From 6ffc8e29934391e1569066ca1a1638d261839fa7 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 3 Dec 2020 17:32:05 +0200 Subject: f_fastboot: Avoid use-after-free in the global pointer variable In case of usb_add_function() failure the error path has an issue, i.e the global pointer variable is assigned to garbage Fix the above mentioned issue by assigning pointer to NULL. Signed-off-by: Andy Shevchenko --- drivers/usb/gadget/f_fastboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index d1d087e..d0d865c 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -315,7 +315,7 @@ static int fastboot_add(struct usb_configuration *c) status = usb_add_function(c, &f_fb->usb_function); if (status) { free(f_fb); - fastboot_func = f_fb; + fastboot_func = NULL; } return status; -- cgit v1.1 From f21358ad6cb5d39fff432fa0af0c4fd24288b2b7 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 22 Dec 2020 11:32:20 +0100 Subject: dfu: mmc: use the default MMC device if entity specifies it as -1 Use the default MMC device set in the command line if entity specifies it as -1. This allows to use the same dfu_alt_info string for different MMC devices (like embedded eMMC and external SD card if data layout is the same on both devices). Signed-off-by: Marek Szyprowski --- drivers/dfu/dfu_mmc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 691d01c..784d0ec 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -316,7 +316,7 @@ void dfu_free_entity_mmc(struct dfu_entity *dfu) int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) { const char *entity_type; - size_t second_arg; + ssize_t second_arg; size_t third_arg; struct mmc *mmc; @@ -339,7 +339,7 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) * Base 0 means we'll accept (prefixed with 0x or 0) base 16, 8, * with default 10. */ - second_arg = simple_strtoul(argv[1], NULL, 0); + second_arg = simple_strtol(argv[1], NULL, 0); third_arg = simple_strtoul(argv[2], NULL, 0); mmc = find_mmc_device(dfu->data.mmc.dev_num); @@ -406,7 +406,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) /* if it's NOT a raw write */ if (strcmp(entity_type, "raw")) { - dfu->data.mmc.dev = second_arg; + dfu->data.mmc.dev = (second_arg != -1) ? second_arg : + dfu->data.mmc.dev_num; dfu->data.mmc.part = third_arg; } -- cgit v1.1 From b5f3405b9d8666bd0ab627c298cea1c927da081a Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Tue, 22 Dec 2020 11:32:21 +0100 Subject: dfu: add 'SKIP' entity Define a new 'SKIP' type for the DFU entities. The flashed data for that entity is simply ignored without returning any error values. This allows to have one flashing procedure and images for the different board types or variants, where each board uses only the images relevant to it and skips the rest. This is especially usefull for the THOR protocol, which usually transfers more than one file in a single session. Signed-off-by: Jaehoon Chung Reviewed-by: Minkyu Kang [mszyprow: rephrased commit message and docs for easier reading, changed subject to "dfu: add 'SKIP' entity"] Signed-off-by: Marek Szyprowski --- drivers/dfu/dfu.c | 2 +- drivers/dfu/dfu_mmc.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index 501a60b..fc32a53 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -614,7 +614,7 @@ const char *dfu_get_dev_type(enum dfu_device_type t) const char *dfu_get_layout(enum dfu_layout l) { const char *const dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2", - "EXT3", "EXT4", "RAM_ADDR" }; + "EXT3", "EXT4", "RAM_ADDR", "SKIP" }; return dfu_layout[l]; } diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 784d0ec..d1af11d 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -108,6 +108,8 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu, case DFU_FS_EXT4: fstype = FS_TYPE_EXT; break; + case DFU_SKIP: + return 0; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, dfu_get_layout(dfu->layout)); @@ -204,6 +206,9 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu, case DFU_FS_EXT4: ret = mmc_file_buf_write(dfu, offset, buf, len); break; + case DFU_SKIP: + ret = 0; + break; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, dfu_get_layout(dfu->layout)); @@ -238,6 +243,8 @@ int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size) if (ret < 0) return ret; return 0; + case DFU_SKIP: + return 0; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, dfu_get_layout(dfu->layout)); @@ -399,6 +406,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_FS_FAT; } else if (!strcmp(entity_type, "ext4")) { dfu->layout = DFU_FS_EXT4; + } else if (!strcmp(entity_type, "skip")) { + dfu->layout = DFU_SKIP; } else { pr_err("Memory layout (%s) not supported!\n", entity_type); return -ENODEV; -- cgit v1.1 From c533f94c102127b94abda206dbe41fe026bcde76 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 22 Dec 2020 11:32:22 +0100 Subject: dfu: add 'SCRIPT' entity Define a new 'SCRIPT' type for DFU entities. The downloaded data are treated as simple u-boot's scripts and executed with run_command_list() function. Flashing the 'SCRIPT' entity might result in changing the 'dfu_alt_info' environment variable from the flashed script, so add a global variable for tracking the potential need to reinitialize the dfu_alt_info related structures. Signed-off-by: Marek Szyprowski --- drivers/dfu/dfu.c | 7 ++++++- drivers/dfu/dfu_mmc.c | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index fc32a53..213a20e 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -26,6 +26,8 @@ static struct hash_algo *dfu_hash_algo; static unsigned long dfu_timeout = 0; #endif +bool dfu_reinit_needed = false; + /* * The purpose of the dfu_flush_callback() function is to * provide callback for dfu user @@ -139,6 +141,8 @@ int dfu_init_env_entities(char *interface, char *devstr) char *env_bkp; int ret = 0; + dfu_reinit_needed = false; + #ifdef CONFIG_SET_DFU_ALT_INFO set_dfu_alt_info(interface, devstr); #endif @@ -614,7 +618,8 @@ const char *dfu_get_dev_type(enum dfu_device_type t) const char *dfu_get_layout(enum dfu_layout l) { const char *const dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2", - "EXT3", "EXT4", "RAM_ADDR", "SKIP" }; + "EXT3", "EXT4", "RAM_ADDR", "SKIP", + "SCRIPT" }; return dfu_layout[l]; } diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index d1af11d..e63fa84 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -16,6 +16,7 @@ #include #include #include +#include static unsigned char *dfu_file_buf; static u64 dfu_file_buf_len; @@ -206,6 +207,9 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu, case DFU_FS_EXT4: ret = mmc_file_buf_write(dfu, offset, buf, len); break; + case DFU_SCRIPT: + ret = run_command_list(buf, *len, 0); + break; case DFU_SKIP: ret = 0; break; @@ -221,9 +225,21 @@ int dfu_flush_medium_mmc(struct dfu_entity *dfu) { int ret = 0; - if (dfu->layout != DFU_RAW_ADDR) { - /* Do stuff here. */ + switch (dfu->layout) { + case DFU_FS_FAT: + case DFU_FS_EXT4: ret = mmc_file_buf_write_finish(dfu); + break; + case DFU_SCRIPT: + /* script may have changed the dfu_alt_info */ + dfu_reinit_needed = true; + break; + case DFU_RAW_ADDR: + case DFU_SKIP: + break; + default: + printf("%s: Layout (%s) not (yet) supported!\n", __func__, + dfu_get_layout(dfu->layout)); } return ret; @@ -243,6 +259,7 @@ int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size) if (ret < 0) return ret; return 0; + case DFU_SCRIPT: case DFU_SKIP: return 0; default: @@ -408,6 +425,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) dfu->layout = DFU_FS_EXT4; } else if (!strcmp(entity_type, "skip")) { dfu->layout = DFU_SKIP; + } else if (!strcmp(entity_type, "script")) { + dfu->layout = DFU_SCRIPT; } else { pr_err("Memory layout (%s) not supported!\n", entity_type); return -ENODEV; -- cgit v1.1 From e47431aa5cf0fe5e113ee9e33624084c93d4ec58 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Tue, 22 Dec 2020 11:32:24 +0100 Subject: thor: add support for the dfu_alt_info reintialization from the flashed script Reinitialize dfu_env_entities after flashing the 'SCRIPT' entity to ensure that the potential changes to the 'dfu_alt_info' environment variable are applied. Signed-off-by: Marek Szyprowski --- drivers/usb/gadget/f_thor.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c index 559ffb7..47ef55b 100644 --- a/drivers/usb/gadget/f_thor.c +++ b/drivers/usb/gadget/f_thor.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "f_thor.h" @@ -735,6 +736,8 @@ int thor_handle(void) printf("%s: No data received!\n", __func__); break; } + if (dfu_reinit_needed) + return THOR_DFU_REINIT_NEEDED; } return 0; -- cgit v1.1 From f2fa49988301965c4f8e7bfdf83145e677b1fbcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Sat, 26 Dec 2020 19:12:11 +0100 Subject: usb: gadget: Do not export usbd_device_* arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each array is used only in one file (core.c or ep0.c). Move their content to correct file, mark them as static and do not export out of current file. This change allows to decrease size of u-boot.bin as more of those strings are not used. Signed-off-by: Pali Rohár --- drivers/usb/gadget/core.c | 45 ++++----------------------------------------- drivers/usb/gadget/ep0.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 41 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/core.c b/drivers/usb/gadget/core.c index 3781d25..888f0cf 100644 --- a/drivers/usb/gadget/core.c +++ b/drivers/usb/gadget/core.c @@ -36,7 +36,7 @@ extern struct usb_function_driver ep0_driver; int registered_functions; int registered_devices; -char *usbd_device_events[] = { +__maybe_unused static char *usbd_device_events[] = { "DEVICE_UNKNOWN", "DEVICE_INIT", "DEVICE_CREATE", @@ -56,52 +56,15 @@ char *usbd_device_events[] = { "DEVICE_FUNCTION_PRIVATE", }; -char *usbd_device_states[] = { - "STATE_INIT", - "STATE_CREATED", - "STATE_ATTACHED", - "STATE_POWERED", - "STATE_DEFAULT", - "STATE_ADDRESSED", - "STATE_CONFIGURED", - "STATE_UNKNOWN", -}; - -char *usbd_device_requests[] = { - "GET STATUS", /* 0 */ - "CLEAR FEATURE", /* 1 */ - "RESERVED", /* 2 */ - "SET FEATURE", /* 3 */ - "RESERVED", /* 4 */ - "SET ADDRESS", /* 5 */ - "GET DESCRIPTOR", /* 6 */ - "SET DESCRIPTOR", /* 7 */ - "GET CONFIGURATION", /* 8 */ - "SET CONFIGURATION", /* 9 */ - "GET INTERFACE", /* 10 */ - "SET INTERFACE", /* 11 */ - "SYNC FRAME", /* 12 */ -}; - -char *usbd_device_descriptors[] = { - "UNKNOWN", /* 0 */ - "DEVICE", /* 1 */ - "CONFIG", /* 2 */ - "STRING", /* 3 */ - "INTERFACE", /* 4 */ - "ENDPOINT", /* 5 */ - "DEVICE QUALIFIER", /* 6 */ - "OTHER SPEED", /* 7 */ - "INTERFACE POWER", /* 8 */ -}; - -char *usbd_device_status[] = { +__maybe_unused static char *usbd_device_status[] = { "USBD_OPENING", "USBD_OK", "USBD_SUSPENDED", "USBD_CLOSING", }; +#define USBD_DEVICE_STATUS(x) (((unsigned int)x <= USBD_CLOSING) ? usbd_device_status[x] : "UNKNOWN") + /* Descriptor support functions ************************************************************** */ diff --git a/drivers/usb/gadget/ep0.c b/drivers/usb/gadget/ep0.c index 6fabee2..457679f 100644 --- a/drivers/usb/gadget/ep0.c +++ b/drivers/usb/gadget/ep0.c @@ -46,6 +46,52 @@ #define dbg_ep0(lvl,fmt,args...) #endif +__maybe_unused static char *usbd_device_descriptors[] = { + "UNKNOWN", /* 0 */ + "DEVICE", /* 1 */ + "CONFIG", /* 2 */ + "STRING", /* 3 */ + "INTERFACE", /* 4 */ + "ENDPOINT", /* 5 */ + "DEVICE QUALIFIER", /* 6 */ + "OTHER SPEED", /* 7 */ + "INTERFACE POWER", /* 8 */ +}; + +#define USBD_DEVICE_DESCRIPTORS(x) (((unsigned int)x <= USB_DESCRIPTOR_TYPE_INTERFACE_POWER) ? \ + usbd_device_descriptors[x] : "UNKNOWN") + +__maybe_unused static char *usbd_device_states[] = { + "STATE_INIT", + "STATE_CREATED", + "STATE_ATTACHED", + "STATE_POWERED", + "STATE_DEFAULT", + "STATE_ADDRESSED", + "STATE_CONFIGURED", + "STATE_UNKNOWN", +}; + +#define USBD_DEVICE_STATE(x) (((unsigned int)x <= STATE_UNKNOWN) ? usbd_device_states[x] : "UNKNOWN") + +__maybe_unused static char *usbd_device_requests[] = { + "GET STATUS", /* 0 */ + "CLEAR FEATURE", /* 1 */ + "RESERVED", /* 2 */ + "SET FEATURE", /* 3 */ + "RESERVED", /* 4 */ + "SET ADDRESS", /* 5 */ + "GET DESCRIPTOR", /* 6 */ + "SET DESCRIPTOR", /* 7 */ + "GET CONFIGURATION", /* 8 */ + "SET CONFIGURATION", /* 9 */ + "GET INTERFACE", /* 10 */ + "SET INTERFACE", /* 11 */ + "SYNC FRAME", /* 12 */ +}; + +#define USBD_DEVICE_REQUESTS(x) (((unsigned int)x <= USB_REQ_SYNCH_FRAME) ? usbd_device_requests[x] : "UNKNOWN") + /* EP0 Configuration Set ********************************************************************* */ -- cgit v1.1 From 71a5732b43b9798d4c288f4dd118247ebdf88e9b Mon Sep 17 00:00:00 2001 From: Ye Li Date: Mon, 25 Jan 2021 21:43:44 +0800 Subject: usb: gadget: Add ep_config call back to usb_gadget_ops Since some new fields in usb_ep structure been moved to usb_ss_ep. The CDNS3 gadget driver should replies on this operation to bind the usb_ss_ep with the endpoint descriptor when function layer uses usb_ep_autoconfig to add endpoint descriptors to gadget. So that CDNS3 driver can know the EP information and configure the EP once the set configuration request is received. Signed-off-by: Sherry Sun Signed-off-by: Ye Li Signed-off-by: Peng Fan --- drivers/usb/gadget/epautoconf.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index e61fe5d..3f88429 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c @@ -167,6 +167,10 @@ static int ep_matches( size = 64; put_unaligned(cpu_to_le16(size), &desc->wMaxPacketSize); } + + if (gadget->ops->ep_conf) + return gadget->ops->ep_conf(gadget, ep, desc); + return 1; } -- cgit v1.1 From c93edbf5385ecd3fd57179acdda813f7ab8cf201 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:45 +0800 Subject: usb: gadget: don't change ep name for dwc3 while ep autoconfig As the SDP protocol use the predefined ep num for communication, we can't change its name hence reset its ep num while do ep autoconfig, this is only apply for SPL. Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/epautoconf.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 3f88429..7da334f 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c @@ -262,6 +262,7 @@ struct usb_ep *usb_ep_autoconfig( ep = find_ep(gadget, "ep1-bulk"); if (ep && ep_matches(gadget, ep, desc)) return ep; +#ifndef CONFIG_SPL_BUILD } else if (gadget_is_dwc3(gadget)) { const char *name = NULL; /* @@ -284,6 +285,7 @@ struct usb_ep *usb_ep_autoconfig( ep = find_ep(gadget, name); if (ep && ep_matches(gadget, ep, desc)) return ep; +#endif } if (gadget->ops->match_ep) -- cgit v1.1 From 1c7aacb9a88844858b4af45522685819c826d0d2 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:46 +0800 Subject: usb: gadget: OS String support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a porting patch from linux kernel: 19824d5eeece ("usb: gadget: OS String support"), original commit log see below: "There is a custom (non-USB IF) extension to the USB standard: http://msdn.microsoft.com/library/windows/hardware/gg463182 They grant permission to use the specification - there is "Microsoft OS Descriptor Specification License Agreement" under the link mentioned above, and its Section 2 "Grant of License", letter (b) reads: "Patent license. Microsoft hereby grants to You a nonexclusive, royalty-free, nontransferable, worldwide license under Microsoft鈥檚 patents embodied solely within the Specification and that are owned or licensable by Microsoft to make, use, import, offer to sell, sell and distribute directly or indirectly to Your Licensees Your Implementation. You may sublicense this patent license to Your Licensees under the same terms and conditions." The said extension is maintained by Microsoft for Microsoft. Yet it is fairly common for various devices to use it, and a popular proprietary operating system expects devices to provide "OS descriptors", so Linux-based USB gadgets whishing to be able to talk to a variety of operating systems should be able to provide the "OS descriptors". This patch adds optional support for gadgets whishing to expose the so called "OS String" under index 0xEE of language 0. The contents of the string is generated based on the qw_sign array and b_vendor_code. Interested gadgets need to set the cdev->use_os_string flag, fill cdev->qw_sign with appropriate values and fill cdev->b_vendor_code with a value of their choice. This patch does not however implement responding to any vendor-specific USB requests." Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 91ed7fc..63855af 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -26,6 +26,22 @@ static inline void le16_add_cpu_packed(__le16_packed *var, u16 val) } /** + * struct usb_os_string - represents OS String to be reported by a gadget + * @bLength: total length of the entire descritor, always 0x12 + * @bDescriptorType: USB_DT_STRING + * @qwSignature: the OS String proper + * @bMS_VendorCode: code used by the host for subsequent requests + * @bPad: not used, must be zero + */ +struct usb_os_string { + __u8 bLength; + __u8 bDescriptorType; + __u8 qwSignature[OS_STRING_QW_SIGN_LEN]; + __u8 bMS_VendorCode; + __u8 bPad; +} __packed; + +/** * usb_add_function() - add a function to a configuration * @config: the configuration * @function: the function being added @@ -577,6 +593,16 @@ static int get_string(struct usb_composite_dev *cdev, return s->bLength; } + if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) { + struct usb_os_string *b = buf; + b->bLength = sizeof(*b); + b->bDescriptorType = USB_DT_STRING; + memcpy(&b->qwSignature, cdev->qw_sign, sizeof(b->qwSignature)); + b->bMS_VendorCode = cdev->b_vendor_code; + b->bPad = 0; + return sizeof(*b); + } + /* * Otherwise, look up and return a specified string. String IDs * are device-scoped, so we look up each string table we're told -- cgit v1.1 From 6777483f5d1e9907a571aca55ec7d86bbce3040b Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:47 +0800 Subject: usb: gadget: move utf8_to_utf16le to header file As other users may use utf8_to_utf16le() to convert the utf8 to utf16 for usb, so move it to head file. Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/usbstring.c | 74 +----------------------------------------- 1 file changed, 1 insertion(+), 73 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c index 83cdd8a..e2464ad 100644 --- a/drivers/usb/gadget/usbstring.c +++ b/drivers/usb/gadget/usbstring.c @@ -10,79 +10,7 @@ #include #include #include - -#include - - -static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len) -{ - int count = 0; - u8 c; - u16 uchar; - - /* - * this insists on correct encodings, though not minimal ones. - * BUT it currently rejects legit 4-byte UTF-8 code points, - * which need surrogate pairs. (Unicode 3.1 can use them.) - */ - while (len != 0 && (c = (u8) *s++) != 0) { - if ((c & 0x80)) { - /* - * 2-byte sequence: - * 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx - */ - if ((c & 0xe0) == 0xc0) { - uchar = (c & 0x1f) << 6; - - c = (u8) *s++; - if ((c & 0xc0) != 0x80) - goto fail; - c &= 0x3f; - uchar |= c; - - /* - * 3-byte sequence (most CJKV characters): - * zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx - */ - } else if ((c & 0xf0) == 0xe0) { - uchar = (c & 0x0f) << 12; - - c = (u8) *s++; - if ((c & 0xc0) != 0x80) - goto fail; - c &= 0x3f; - uchar |= c << 6; - - c = (u8) *s++; - if ((c & 0xc0) != 0x80) - goto fail; - c &= 0x3f; - uchar |= c; - - /* no bogus surrogates */ - if (0xd800 <= uchar && uchar <= 0xdfff) - goto fail; - - /* - * 4-byte sequence (surrogate pairs, currently rare): - * 11101110wwwwzzzzyy + 110111yyyyxxxxxx - * = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx - * (uuuuu = wwww + 1) - * FIXME accept the surrogate code points (only) - */ - } else - goto fail; - } else - uchar = c; - put_unaligned_le16(uchar, cp++); - count++; - len--; - } - return count; -fail: - return -1; -} - +#include /** * usb_gadget_get_string - fill out a string descriptor -- cgit v1.1 From 16fd832e0e2d06c1a76d9bef1f62e9d94c3fed98 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Mon, 25 Jan 2021 21:43:48 +0800 Subject: usb: gadget: add Kconfig for OS descriptors Add Kconfig for OS descriptors Signed-off-by: Peng Fan --- drivers/usb/gadget/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 7c0df5c..4a3b22e 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -98,6 +98,15 @@ config USB_GADGET_DWC2_OTG_PHY_BUS_WIDTH_8 endif # USB_GADGET_DWC2_OTG +config USB_GADGET_OS_DESCRIPTORS + bool "USB OS Feature Descriptors support" + help + This is a porting patch from linux kernel: 37a3a533429e + ("usb: gadget: OS Feature Descriptors support"), the original commit + log see below: + There is a custom (non-USB IF) extension to the USB standard: + http://msdn.microsoft.com/library/windows/hardware/gg463182 + config CI_UDC bool "ChipIdea device controller" select USB_GADGET_DUALSPEED -- cgit v1.1 From a764c941289c404ae3a2605a204fc0375b566bb2 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:49 +0800 Subject: usb: gadget: OS Feature Descriptors support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a proting patch from linux kernel: 37a3a533429e ("usb: gadget: OS Feature Descriptors support"), the original commit log see below: There is a custom (non-USB IF) extension to the USB standard: http://msdn.microsoft.com/library/windows/hardware/gg463182 They grant permission to use the specification - there is "Microsoft OS Descriptor Specification License Agreement" under the link mentioned above, and its Section 2 "Grant of License", letter (b) reads: "Patent license. Microsoft hereby grants to You a nonexclusive, royalty-free, nontransferable, worldwide license under Microsoft鈥檚 patents embodied solely within the Specification and that are owned or licensable by Microsoft to make, use, import, offer to sell, sell and distribute directly or indirectly to Your Licensees Your Implementation. You may sublicense this patent license to Your Licensees under the same terms and conditions." The said extension is maintained by Microsoft for Microsoft. Yet it is fairly common for various devices to use it, and a popular proprietary operating system expects devices to provide "OS descriptors", so Linux-based USB gadgets whishing to be able to talk to a variety of operating systems should be able to provide the "OS descriptors". This patch adds optional support for gadgets whishing to expose the so called "OS Feature Descriptors", that is "Extended Compatibility ID" and "Extended Properties". Hosts which do request "OS descriptors" from gadgets do so during the enumeration phase and before the configuration is set with SET_CONFIGURATION. What is more, those hosts never ask for configurations at indices other than 0. Therefore, gadgets whishing to provide "OS descriptors" must designate one configuration to be used with this kind of hosts - this is what os_desc_config is added for in struct usb_composite_dev. There is an additional advantage to it: if a gadget provides "OS descriptors" and designates one configuration to be used with such non-USB-compliant hosts it can invoke "usb_add_config" in any order because the designated configuration will be reported to be at index 0 anyway. This patch also adds handling vendor-specific requests addressed at device or interface and related to handling "OS descriptors"." Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 252 ++++++++++++++++++++++++++++++++++++++++- drivers/usb/gadget/u_os_desc.h | 123 ++++++++++++++++++++ 2 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/gadget/u_os_desc.h (limited to 'drivers') diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 63855af..a0c28db 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -12,6 +12,7 @@ #include #include #include +#include "u_os_desc.h" #define USB_BUFSIZ 4096 @@ -244,6 +245,7 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) u8 type = w_value >> 8; int hs = 0; struct usb_configuration *c; + struct list_head *pos; if (gadget_is_dualspeed(gadget)) { if (gadget->speed == USB_SPEED_HIGH) @@ -255,7 +257,20 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) } w_value &= 0xff; - list_for_each_entry(c, &cdev->configs, list) { + + pos = &cdev->configs; + c = cdev->os_desc_config; + if (c) + goto check_config; + + while ((pos = pos->next) != &cdev->configs) { + c = list_entry(pos, typeof(*c), list); + + /* skip OS Descriptors config which is handled separately */ + if (c == cdev->os_desc_config) + continue; + +check_config: if (speed == USB_SPEED_HIGH) { if (!c->highspeed) continue; @@ -779,6 +794,156 @@ static int bos_desc(struct usb_composite_dev *cdev) return le16_to_cpu(bos->wTotalLength); } +static int count_ext_compat(struct usb_configuration *c) +{ + int i, res; + + res = 0; + for (i = 0; i < c->next_interface_id; ++i) { + struct usb_function *f; + int j; + + f = c->interface[i]; + for (j = 0; j < f->os_desc_n; ++j) { + struct usb_os_desc *d; + + if (i != f->os_desc_table[j].if_id) + continue; + d = f->os_desc_table[j].os_desc; + if (d && d->ext_compat_id) + ++res; + } + } + BUG_ON(res > 255); + return res; +} + +static void fill_ext_compat(struct usb_configuration *c, u8 *buf) +{ + int i, count; + + count = 16; + for (i = 0; i < c->next_interface_id; ++i) { + struct usb_function *f; + int j; + + f = c->interface[i]; + for (j = 0; j < f->os_desc_n; ++j) { + struct usb_os_desc *d; + + if (i != f->os_desc_table[j].if_id) + continue; + d = f->os_desc_table[j].os_desc; + if (d && d->ext_compat_id) { + *buf++ = i; + *buf++ = 0x01; + memcpy(buf, d->ext_compat_id, 16); + buf += 22; + } else { + ++buf; + *buf = 0x01; + buf += 23; + } + count += 24; + if (count >= 4096) + return; + } + } +} + +static int count_ext_prop(struct usb_configuration *c, int interface) +{ + struct usb_function *f; + int j; + + f = c->interface[interface]; + for (j = 0; j < f->os_desc_n; ++j) { + struct usb_os_desc *d; + + if (interface != f->os_desc_table[j].if_id) + continue; + d = f->os_desc_table[j].os_desc; + if (d && d->ext_compat_id) + return d->ext_prop_count; + } + return 0; +} + +static int len_ext_prop(struct usb_configuration *c, int interface) +{ + struct usb_function *f; + struct usb_os_desc *d; + int j, res; + + res = 10; /* header length */ + f = c->interface[interface]; + for (j = 0; j < f->os_desc_n; ++j) { + if (interface != f->os_desc_table[j].if_id) + continue; + d = f->os_desc_table[j].os_desc; + if (d) + return min(res + d->ext_prop_len, 4096); + } + return res; +} + +static int fill_ext_prop(struct usb_configuration *c, int interface, u8 *buf) +{ + struct usb_function *f; + struct usb_os_desc *d; + struct usb_os_desc_ext_prop *ext_prop; + int j, count, n, ret; + u8 *start = buf; + + f = c->interface[interface]; + for (j = 0; j < f->os_desc_n; ++j) { + if (interface != f->os_desc_table[j].if_id) + continue; + d = f->os_desc_table[j].os_desc; + if (d) + list_for_each_entry(ext_prop, &d->ext_prop, entry) { + /* 4kB minus header length */ + n = buf - start; + if (n >= 4086) + return 0; + + count = ext_prop->data_len + + ext_prop->name_len + 14; + if (count > 4086 - n) + return -EINVAL; + usb_ext_prop_put_size(buf, count); + usb_ext_prop_put_type(buf, ext_prop->type); + ret = usb_ext_prop_put_name(buf, ext_prop->name, + ext_prop->name_len); + if (ret < 0) + return ret; + switch (ext_prop->type) { + case USB_EXT_PROP_UNICODE: + case USB_EXT_PROP_UNICODE_ENV: + case USB_EXT_PROP_UNICODE_LINK: + usb_ext_prop_put_unicode(buf, ret, + ext_prop->data, + ext_prop->data_len); + break; + case USB_EXT_PROP_BINARY: + usb_ext_prop_put_binary(buf, ret, + ext_prop->data, + ext_prop->data_len); + break; + case USB_EXT_PROP_LE32: + /* not implemented */ + case USB_EXT_PROP_BE32: + /* not implemented */ + default: + return -EINVAL; + } + buf += count; + } + } + + return 0; +} + /* * The setup() callback implements all the ep0 functionality that's * not handled lower down, in hardware or the hardware driver(like @@ -935,6 +1100,91 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) break; default: unknown: + /* + * OS descriptors handling + */ + if (CONFIG_IS_ENABLED(USB_GADGET_OS_DESCRIPTORS) && cdev->use_os_string && + cdev->os_desc_config && (ctrl->bRequestType & USB_TYPE_VENDOR) && + ctrl->bRequest == cdev->b_vendor_code) { + struct usb_configuration *os_desc_cfg; + u8 *buf; + int interface; + int count = 0; + + buf = req->buf; + os_desc_cfg = cdev->os_desc_config; + memset(buf, 0, w_length); + buf[5] = 0x01; + switch (ctrl->bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + if (w_index != 0x4 || (w_value >> 8)) + break; + buf[6] = w_index; + if (w_length == 0x10) { + /* Number of ext compat interfaces */ + count = count_ext_compat(os_desc_cfg); + buf[8] = count; + count *= 24; /* 24 B/ext compat desc */ + count += 16; /* header */ + put_unaligned_le32(count, buf); + value = w_length; + } else { + /* "extended compatibility ID"s */ + count = count_ext_compat(os_desc_cfg); + buf[8] = count; + count *= 24; /* 24 B/ext compat desc */ + count += 16; /* header */ + put_unaligned_le32(count, buf); + buf += 16; + fill_ext_compat(os_desc_cfg, buf); + value = w_length; + } + break; + case USB_RECIP_INTERFACE: + if (w_index != 0x5 || (w_value >> 8)) + break; + interface = w_value & 0xFF; + buf[6] = w_index; + if (w_length == 0x0A) { + count = count_ext_prop(os_desc_cfg, + interface); + put_unaligned_le16(count, buf + 8); + count = len_ext_prop(os_desc_cfg, + interface); + put_unaligned_le32(count, buf); + + value = w_length; + } else { + count = count_ext_prop(os_desc_cfg, + interface); + put_unaligned_le16(count, buf + 8); + count = len_ext_prop(os_desc_cfg, + interface); + put_unaligned_le32(count, buf); + buf += 10; + value = fill_ext_prop(os_desc_cfg, + interface, buf); + if (value < 0) + return value; + + value = w_length; + } + break; + } + + if (value >= 0) { + req->length = value; + req->zero = value < w_length; + value = usb_ep_queue(gadget->ep0, req, GFP_KERNEL); + if (value < 0) { + debug("ep_queue --> %d\n", value); + req->status = 0; + composite_setup_complete(gadget->ep0, req); + } + } + return value; + } + debug("non-core control req%02x.%02x v%04x i%04x l%d\n", ctrl->bRequestType, ctrl->bRequest, w_value, w_index, w_length); diff --git a/drivers/usb/gadget/u_os_desc.h b/drivers/usb/gadget/u_os_desc.h new file mode 100644 index 0000000..4dab481 --- /dev/null +++ b/drivers/usb/gadget/u_os_desc.h @@ -0,0 +1,123 @@ +/* + * u_os_desc.h + * + * Utility definitions for "OS Descriptors" support + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * Author: Andrzej Pietrasiewicz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __U_OS_DESC_H__ +#define __U_OS_DESC_H__ + +#include + +#define USB_EXT_PROP_DW_SIZE 0 +#define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4 +#define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8 +#define USB_EXT_PROP_B_PROPERTY_NAME 10 +#define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10 +#define USB_EXT_PROP_B_PROPERTY_DATA 14 + +#define USB_EXT_PROP_RESERVED 0 +#define USB_EXT_PROP_UNICODE 1 +#define USB_EXT_PROP_UNICODE_ENV 2 +#define USB_EXT_PROP_BINARY 3 +#define USB_EXT_PROP_LE32 4 +#define USB_EXT_PROP_BE32 5 +#define USB_EXT_PROP_UNICODE_LINK 6 +#define USB_EXT_PROP_UNICODE_MULTI 7 + +static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset) +{ + return buf + offset; +} + +static inline u8 *usb_ext_prop_size_ptr(u8 *buf) +{ + return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE); +} + +static inline u8 *usb_ext_prop_type_ptr(u8 *buf) +{ + return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE); +} + +static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf) +{ + return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH); +} + +static inline u8 *usb_ext_prop_name_ptr(u8 *buf) +{ + return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME); +} + +static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off) +{ + return __usb_ext_prop_ptr(buf, + USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off); +} + +static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off) +{ + return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off); +} + +static inline void usb_ext_prop_put_size(u8 *buf, int dw_size) +{ + put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf)); +} + +static inline void usb_ext_prop_put_type(u8 *buf, int type) +{ + put_unaligned_le32(type, usb_ext_prop_type_ptr(buf)); +} + +static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) +{ + int result; + + put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf)); + memset(usb_ext_prop_name_ptr(buf), 0, 2 * strlen(name)); + result = utf8_to_utf16le(name, (__le16 *)usb_ext_prop_name_ptr(buf), + strlen(name)); + if (result < 0) + return result; + + put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]); + + return pnl; +} + +static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const char *data, + int data_len) +{ + put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl)); + memcpy(usb_ext_prop_data_ptr(buf, pnl), data, data_len); +} + +static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, + int data_len) +{ + int result; + put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl)); + memset(usb_ext_prop_data_ptr(buf, pnl), 0, 2 * (data_len >> 1)); + result = utf8_to_utf16le(string, (__le16 *) usb_ext_prop_data_ptr(buf, pnl), + data_len >> 1); + if (result < 0) + return result; + + put_unaligned_le16(0, + &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]); + + return data_len; +} + +#endif /* __U_OS_DESC_H__ */ -- cgit v1.1 From 37e4fc3354dab8b4cbf835f83ed439753234ce12 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:50 +0800 Subject: usb: gadget: add WCID support for mfgtool Enable WCID(Microsoft Compatible ID Feature Descriptor) for mfgtool. Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index a0c28db..cd61bfe 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -20,6 +20,10 @@ typedef struct { __le16 val; } __packed __le16_packed; static struct usb_composite_driver *composite; +static struct usb_configuration *os_desc_config; + +/* Microsoft OS String Descriptor */ +static char qw_sign_buf[OS_STRING_QW_SIGN_LEN / 2] = {'M', 'S', 'F', 'T', '1', '0', '0'}; static inline void le16_add_cpu_packed(__le16_packed *var, u16 val) { @@ -395,6 +399,10 @@ static int set_config(struct usb_composite_dev *cdev, goto done; cdev->config = c; + if (cdev->use_os_string) { + cdev->os_desc_config = c; + os_desc_config = c; + } /* Initialize all interfaces by setting them to altsetting zero. */ for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) { @@ -1358,6 +1366,18 @@ static int composite_bind(struct usb_gadget *gadget) sizeof(struct usb_device_descriptor)); cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; + if (cdev->use_os_string) { + /* TODO: Do we want to pass this via platform? */ + cdev->b_vendor_code = 0x40; + + /* Microsoft OS String Descriptor */ + utf8_to_utf16le(qw_sign_buf, (__le16 *)cdev->qw_sign, + OS_STRING_QW_SIGN_LEN / 2); + + if (os_desc_config) + cdev->os_desc_config = os_desc_config; + } + debug("%s: ready\n", composite->name); return 0; -- cgit v1.1 From 8043cf8fbd93dfceeec14a8c00eda292deaca938 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:51 +0800 Subject: usb: gadget: fastboot: add ext properties for WCID Add device interface GUID for Microsoft Extended Properties Feature Descriptor. Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/f_fastboot.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index d0d865c..f5ac223 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -46,6 +46,25 @@ struct f_fastboot { struct usb_request *in_req, *out_req; }; +static char fb_ext_prop_name[] = "DeviceInterfaceGUID"; +static char fb_ext_prop_data[] = "{4866319A-F4D6-4374-93B9-DC2DEB361BA9}"; + +static struct usb_os_desc_ext_prop fb_ext_prop = { + .type = 1, /* NUL-terminated Unicode String (REG_SZ) */ + .name = fb_ext_prop_name, + .data = fb_ext_prop_data, +}; + +/* 16 bytes of "Compatible ID" and "Subcompatible ID" */ +static char fb_cid[16] = {'W', 'I', 'N', 'U', 'S', 'B'}; +static struct usb_os_desc fb_os_desc = { + .ext_compat_id = fb_cid, +}; + +static struct usb_os_desc_table fb_os_desc_table = { + .os_desc = &fb_os_desc, +}; + static inline struct f_fastboot *func_to_fastboot(struct usb_function *f) { return container_of(f, struct f_fastboot, usb_function); @@ -161,6 +180,19 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) return id; interface_desc.bInterfaceNumber = id; + /* Enable OS and Extended Properties Feature Descriptor */ + c->cdev->use_os_string = 1; + f->os_desc_table = &fb_os_desc_table; + f->os_desc_n = 1; + f->os_desc_table->if_id = id; + INIT_LIST_HEAD(&fb_os_desc.ext_prop); + fb_ext_prop.name_len = strlen(fb_ext_prop.name) * 2 + 2; + fb_os_desc.ext_prop_len = 10 + fb_ext_prop.name_len; + fb_os_desc.ext_prop_count = 1; + fb_ext_prop.data_len = strlen(fb_ext_prop.data) * 2 + 2; + fb_os_desc.ext_prop_len += fb_ext_prop.data_len + 4; + list_add_tail(&fb_ext_prop.entry, &fb_os_desc.ext_prop); + id = usb_string_id(c->cdev); if (id < 0) return id; @@ -196,6 +228,8 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) static void fastboot_unbind(struct usb_configuration *c, struct usb_function *f) { + f->os_desc_table = NULL; + list_del(&fb_os_desc.ext_prop); memset(fastboot_func, 0, sizeof(*fastboot_func)); } -- cgit v1.1 From 4e643671f53173bf0f95f11e3b5a1872ffe029d3 Mon Sep 17 00:00:00 2001 From: Jun Li Date: Mon, 25 Jan 2021 21:43:52 +0800 Subject: usb: gadget: set correct usb_configuration for os_desc_config The current way to set cdev->os_desc_config is wrong if user restart fastboot, as the old config is not used anymore and new allocated usb_configuration will be used, so set the os_desc_config while usb_add_config. Reviewed-by: Ye Li Signed-off-by: Li Jun Signed-off-by: Peter Chen Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index cd61bfe..e6fdefd 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -399,10 +399,6 @@ static int set_config(struct usb_composite_dev *cdev, goto done; cdev->config = c; - if (cdev->use_os_string) { - cdev->os_desc_config = c; - os_desc_config = c; - } /* Initialize all interfaces by setting them to altsetting zero. */ for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) { @@ -516,6 +512,9 @@ int usb_add_config(struct usb_composite_dev *cdev, usb_ep_autoconfig_reset(cdev->gadget); + if (os_desc_config) + cdev->os_desc_config = os_desc_config; + done: if (status) debug("added config '%s'/%u --> %d\n", config->label, @@ -1373,9 +1372,6 @@ static int composite_bind(struct usb_gadget *gadget) /* Microsoft OS String Descriptor */ utf8_to_utf16le(qw_sign_buf, (__le16 *)cdev->qw_sign, OS_STRING_QW_SIGN_LEN / 2); - - if (os_desc_config) - cdev->os_desc_config = os_desc_config; } debug("%s: ready\n", composite->name); -- cgit v1.1 From 42a594de14637f809050cd2e2ea8b4a7f51bb31a Mon Sep 17 00:00:00 2001 From: Jun Li Date: Mon, 25 Jan 2021 21:43:53 +0800 Subject: usb: gadget: update os_desc_config when add config Always use the new added config for os_desc_config to fix cdev-> os_desc_config may miss set in case we restart usb gadget driver. Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index e6fdefd..404da12 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -512,8 +512,8 @@ int usb_add_config(struct usb_composite_dev *cdev, usb_ep_autoconfig_reset(cdev->gadget); - if (os_desc_config) - cdev->os_desc_config = os_desc_config; + os_desc_config = config; + cdev->os_desc_config = os_desc_config; done: if (status) -- cgit v1.1 From 8745b9ebccae599856045c5d6354463178604f72 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:54 +0800 Subject: usb: gadget: add super speed support This patch is to add usb gadget super speed support in common driver, including BOS descriptor and select the super speed descriptor from function driver. Reviewed-by: Ye Li Reviewed-by: Peter Chen Tested-by: faqiang.zhu Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 85 +++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 25 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 404da12..1063c57 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -88,6 +88,8 @@ int usb_add_function(struct usb_configuration *config, config->fullspeed = 1; if (!config->highspeed && function->hs_descriptors) config->highspeed = 1; + if (!config->superspeed && function->ss_descriptors) + config->superspeed = 1; done: if (value) @@ -223,7 +225,9 @@ static int config_buf(struct usb_configuration *config, /* add each function's descriptors */ list_for_each_entry(f, &config->functions, list) { - if (speed == USB_SPEED_HIGH) + if (speed == USB_SPEED_SUPER) + descriptors = f->ss_descriptors; + else if (speed == USB_SPEED_HIGH) descriptors = f->hs_descriptors; else descriptors = f->descriptors; @@ -251,7 +255,9 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) struct usb_configuration *c; struct list_head *pos; - if (gadget_is_dualspeed(gadget)) { + if (gadget_is_superspeed(gadget)) { + speed = gadget->speed; + } else if (gadget_is_dualspeed(gadget)) { if (gadget->speed == USB_SPEED_HIGH) hs = 1; if (type == USB_DT_OTHER_SPEED_CONFIG) @@ -275,7 +281,10 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) continue; check_config: - if (speed == USB_SPEED_HIGH) { + if (speed == USB_SPEED_SUPER) { + if (!c->superspeed) + continue; + } else if (speed == USB_SPEED_HIGH) { if (!c->highspeed) continue; } else { @@ -294,8 +303,12 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type) struct usb_gadget *gadget = cdev->gadget; unsigned count = 0; int hs = 0; + int ss = 0; struct usb_configuration *c; + if (gadget->speed == USB_SPEED_SUPER) + ss = 1; + if (gadget_is_dualspeed(gadget)) { if (gadget->speed == USB_SPEED_HIGH) hs = 1; @@ -304,7 +317,10 @@ static int count_configs(struct usb_composite_dev *cdev, unsigned type) } list_for_each_entry(c, &cdev->configs, list) { /* ignore configs that won't work at this speed */ - if (hs) { + if (ss) { + if (!c->superspeed) + continue; + } else if (hs) { if (!c->highspeed) continue; } else { @@ -388,6 +404,9 @@ static int set_config(struct usb_composite_dev *cdev, case USB_SPEED_HIGH: speed = "high"; break; + case USB_SPEED_SUPER: + speed = "super"; + break; default: speed = "?"; break; @@ -412,7 +431,9 @@ static int set_config(struct usb_composite_dev *cdev, * function's setup callback instead of the current * configuration's setup callback. */ - if (gadget->speed == USB_SPEED_HIGH) + if (gadget->speed == USB_SPEED_SUPER) + descriptors = f->ss_descriptors; + else if (gadget->speed == USB_SPEED_HIGH) descriptors = f->hs_descriptors; else descriptors = f->descriptors; @@ -492,8 +513,9 @@ int usb_add_config(struct usb_composite_dev *cdev, list_del(&config->list); config->cdev = NULL; } else { - debug("cfg %d/%p speeds:%s%s\n", + debug("cfg %d/%p speeds:%s%s%s\n", config->bConfigurationValue, config, + config->superspeed ? " super" : "", config->highspeed ? " high" : "", config->fullspeed ? (gadget_is_dualspeed(cdev->gadget) @@ -751,6 +773,7 @@ static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) static int bos_desc(struct usb_composite_dev *cdev) { struct usb_ext_cap_descriptor *usb_ext; + struct usb_dcd_config_params dcd_config_params; struct usb_bos_descriptor *bos = cdev->req->buf; bos->bLength = USB_DT_BOS_SIZE; @@ -794,9 +817,19 @@ static int bos_desc(struct usb_composite_dev *cdev) USB_HIGH_SPEED_OPERATION | USB_5GBPS_OPERATION); ss_cap->bFunctionalitySupport = USB_LOW_SPEED_OPERATION; - ss_cap->bU1devExitLat = USB_DEFAULT_U1_DEV_EXIT_LAT; - ss_cap->bU2DevExitLat = - cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT); + + /* Get Controller configuration */ + if (cdev->gadget->ops->get_config_params) { + cdev->gadget->ops->get_config_params( + &dcd_config_params); + } else { + dcd_config_params.bU1devExitLat = + USB_DEFAULT_U1_DEV_EXIT_LAT; + dcd_config_params.bU2DevExitLat = + cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT); + } + ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat; + ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat; } return le16_to_cpu(bos->wTotalLength); } @@ -999,32 +1032,28 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) cdev->desc.bNumConfigurations = count_configs(cdev, USB_DT_DEVICE); - /* - * If the speed is Super speed, then the supported - * max packet size is 512 and it should be sent as - * exponent of 2. So, 9(2^9=512) should be filled in - * bMaxPacketSize0. Also fill USB version as 3.0 - * if speed is Super speed. - */ - if (cdev->gadget->speed == USB_SPEED_SUPER) { + cdev->desc.bMaxPacketSize0 = + cdev->gadget->ep0->maxpacket; + if (gadget->speed >= USB_SPEED_SUPER) { + cdev->desc.bcdUSB = cpu_to_le16(0x0310); cdev->desc.bMaxPacketSize0 = 9; - cdev->desc.bcdUSB = cpu_to_le16(0x0300); } else { - cdev->desc.bMaxPacketSize0 = - cdev->gadget->ep0->maxpacket; + cdev->desc.bcdUSB = cpu_to_le16(0x0200); } value = min(w_length, (u16) sizeof cdev->desc); memcpy(req->buf, &cdev->desc, value); break; case USB_DT_DEVICE_QUALIFIER: - if (!gadget_is_dualspeed(gadget)) + if (!gadget_is_dualspeed(gadget) || + gadget->speed >= USB_SPEED_SUPER) break; device_qual(cdev); value = min_t(int, w_length, sizeof(struct usb_qualifier_descriptor)); break; case USB_DT_OTHER_SPEED_CONFIG: - if (!gadget_is_dualspeed(gadget)) + if (!gadget_is_dualspeed(gadget) || + gadget->speed >= USB_SPEED_SUPER) break; case USB_DT_CONFIG: @@ -1039,10 +1068,16 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) value = min(w_length, (u16) value); break; case USB_DT_BOS: - if (gadget_is_superspeed(cdev->gadget)) + /* + * Super speed connection should support BOS, and + * USB compliance test (USB 2.0 Command Verifier) + * also issues this request, return for now for + * USB 2.0 connection. + */ + if (gadget->speed >= USB_SPEED_SUPER) { value = bos_desc(cdev); - if (value >= 0) value = min(w_length, (u16)value); + } break; default: goto unknown; @@ -1421,7 +1456,7 @@ composite_resume(struct usb_gadget *gadget) } static struct usb_gadget_driver composite_driver = { - .speed = USB_SPEED_HIGH, + .speed = USB_SPEED_SUPER, .bind = composite_bind, .unbind = composite_unbind, -- cgit v1.1 From 761dfe0fb2ba82704d1212021b4623da34800de4 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:55 +0800 Subject: usb: fastboot: add super speed support Add super speed EP config. Reviewed-by: Ye Li Reviewed-by: Peter Chen Tested-by: faqiang.zhu Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/f_fastboot.c | 47 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index f5ac223..f3ce47a 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -128,10 +128,45 @@ static struct usb_descriptor_header *fb_hs_function[] = { NULL, }; +/* Super speed */ +static struct usb_endpoint_descriptor ss_ep_in = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(1024), +}; + +static struct usb_endpoint_descriptor ss_ep_out = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(1024), +}; + +static struct usb_ss_ep_comp_descriptor fb_ss_bulk_comp_desc = { + .bLength = sizeof(fb_ss_bulk_comp_desc), + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, +}; + +static struct usb_descriptor_header *fb_ss_function[] = { + (struct usb_descriptor_header *)&interface_desc, + (struct usb_descriptor_header *)&ss_ep_in, + (struct usb_descriptor_header *)&fb_ss_bulk_comp_desc, + (struct usb_descriptor_header *)&ss_ep_out, + (struct usb_descriptor_header *)&fb_ss_bulk_comp_desc, + NULL, +}; + static struct usb_endpoint_descriptor * fb_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, - struct usb_endpoint_descriptor *hs) + struct usb_endpoint_descriptor *hs, + struct usb_endpoint_descriptor *ss) { + if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER) + return ss; + if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) return hs; return fs; @@ -219,6 +254,12 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f) f->hs_descriptors = fb_hs_function; } + if (gadget_is_superspeed(gadget)) { + ss_ep_in.bEndpointAddress = fs_ep_in.bEndpointAddress; + ss_ep_out.bEndpointAddress = fs_ep_out.bEndpointAddress; + f->ss_descriptors = fb_ss_function; + } + s = env_get("serial#"); if (s) g_dnl_set_serialnumber((char *)s); @@ -283,7 +324,7 @@ static int fastboot_set_alt(struct usb_function *f, debug("%s: func: %s intf: %d alt: %d\n", __func__, f->name, interface, alt); - d = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out); + d = fb_ep_desc(gadget, &fs_ep_out, &hs_ep_out, &ss_ep_out); ret = usb_ep_enable(f_fb->out_ep, d); if (ret) { puts("failed to enable out ep\n"); @@ -298,7 +339,7 @@ static int fastboot_set_alt(struct usb_function *f, } f_fb->out_req->complete = rx_handler_command; - d = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in); + d = fb_ep_desc(gadget, &fs_ep_in, &hs_ep_in, &ss_ep_in); ret = usb_ep_enable(f_fb->in_ep, d); if (ret) { puts("failed to enable in ep\n"); -- cgit v1.1 From 429e2f299f3a978cf248c3597f60308c5d636ad8 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:56 +0800 Subject: usb: gadget: dnl: set dnl to be super speed Set its max_speed to be super speed. Reviewed-by: Ye Li Reviewed-by: Peter Chen Tested-by: faqiang.zhu Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/g_dnl.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c index 86fdd16..afb7b74 100644 --- a/drivers/usb/gadget/g_dnl.c +++ b/drivers/usb/gadget/g_dnl.c @@ -286,6 +286,7 @@ static struct usb_composite_driver g_dnl_driver = { .name = NULL, .dev = &device_desc, .strings = g_dnl_composite_strings, + .max_speed = USB_SPEED_SUPER, .bind = g_dnl_bind, .unbind = g_dnl_unbind, -- cgit v1.1 From 4df50f89f5769732c6cce67f956371140680ff5d Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:57 +0800 Subject: usb: composite: force gadget to be USB2 for HS only function If one of functions is not super speed capable, we need force the udc to be high speed, this is an equivalent implementation of usb_gadget_udc_set_speed() in kernel but simple, which set the gadget max_speed to be high speed, so afterwards when start gadget duc can set the HW to be USB 2.0 mode. Reviewed-by: Ye Li Reviewed-by: Peter Chen Tested-by: faqiang.zhu Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/composite.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 1063c57..2a309e6 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -532,6 +532,19 @@ int usb_add_config(struct usb_composite_dev *cdev, } } + /* + * If one function of config is not super speed capable, + * force the gadget to be high speed so controller driver + * can init HW to be USB 2.0 + */ + if (gadget_is_superspeed(cdev->gadget)) { + list_for_each_entry(f, &config->functions, list) { + if (!f->ss_descriptors) + cdev->gadget->max_speed = + USB_SPEED_HIGH; + } + } + usb_ep_autoconfig_reset(cdev->gadget); os_desc_config = config; -- cgit v1.1 From 54b22f409cdaaeb3f312a3afcfaddf2fd184209b Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:58 +0800 Subject: usb: udc: ci: update speed handling Remove the gadget driver speed check, and set its max_speed to be USB_SPEED_HIGH. Reviewed-by: Ye Li Reviewed-by: Peter Chen Tested-by: faqiang.zhu Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/ci_udc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index cdb8f6f..b64e4bb 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -145,6 +145,7 @@ static struct ci_drv controller = { .name = "ci_udc", .ops = &ci_udc_ops, .is_dualspeed = 1, + .max_speed = USB_SPEED_HIGH, }, }; @@ -1015,8 +1016,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) return -EINVAL; if (!driver->bind || !driver->setup || !driver->disconnect) return -EINVAL; - if (driver->speed != USB_SPEED_FULL && driver->speed != USB_SPEED_HIGH) - return -EINVAL; #if CONFIG_IS_ENABLED(DM_USB) ret = usb_setup_ehci_gadget(&controller.ctrl); -- cgit v1.1 From 27c9141b1114fd5721437abbb1c694e45e765f19 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:43:59 +0800 Subject: usb: gadget: fastboot: use correct max packet size Change to use wMaxPacketSize of current speed EP desc for request length wrap up. Reviewed-by: Peter Chen Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/f_fastboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index f3ce47a..950cc11 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -427,7 +427,7 @@ static unsigned int rx_bytes_expected(struct usb_ep *ep) { int rx_remain = fastboot_data_remaining(); unsigned int rem; - unsigned int maxpacket = ep->maxpacket; + unsigned int maxpacket = usb_endpoint_maxp(ep->desc); if (rx_remain <= 0) return 0; -- cgit v1.1 From 723fd5668ff2c8dd19e808778b5670d0fa6bdc4b Mon Sep 17 00:00:00 2001 From: Li Jun Date: Mon, 25 Jan 2021 21:44:00 +0800 Subject: usb: gaget: ci: set ep's desc when enable ep As we need standard usb_ep's desc, so set it when enable ep. Reviewed-by: Peter Chen Signed-off-by: Li Jun Signed-off-by: Peng Fan --- drivers/usb/gadget/ci_udc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c index b64e4bb..226a9e6 100644 --- a/drivers/usb/gadget/ci_udc.c +++ b/drivers/usb/gadget/ci_udc.c @@ -336,6 +336,7 @@ static int ci_ep_enable(struct usb_ep *ep, num = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; in = (desc->bEndpointAddress & USB_DIR_IN) != 0; ci_ep->desc = desc; + ep->desc = desc; if (num) { int max = get_unaligned_le16(&desc->wMaxPacketSize); @@ -358,6 +359,7 @@ static int ci_ep_disable(struct usb_ep *ep) struct ci_ep *ci_ep = container_of(ep, struct ci_ep, ep); ci_ep->desc = NULL; + ep->desc = NULL; return 0; } -- cgit v1.1