From patchwork Mon Jun 29 02:32:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 243060 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Mon, 29 Jun 2020 10:32:52 +0800 Subject: [PATCH 1/7] sdp: call board_usb_init at spl_sdp_load_image Message-ID: <20200629023258.25452-1-peng.fan@nxp.com> From: Frank Li Need initialize UDC before run sdp download Signed-off-by: Frank Li Signed-off-by: Peng Fan --- common/spl/spl_sdp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c index e7f7b68411..ae9c09883a 100644 --- a/common/spl/spl_sdp.c +++ b/common/spl/spl_sdp.c @@ -19,6 +19,8 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image, usb_gadget_initialize(controller_index); + board_usb_init(0, USB_INIT_DEVICE); + g_dnl_clear_detach(); ret = g_dnl_register("usb_dnl_sdp"); if (ret) { From patchwork Mon Jun 29 02:32:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 243064 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Mon, 29 Jun 2020 10:32:53 +0800 Subject: [PATCH 2/7] f_sdp: Add high speed endpoint descriptor In-Reply-To: <20200629023258.25452-1-peng.fan@nxp.com> References: <20200629023258.25452-1-peng.fan@nxp.com> Message-ID: <20200629023258.25452-2-peng.fan@nxp.com> From: Ye Li Add HS endpoint descriptor for SDP. So that we can use high speed endpoint, and the SDP device can send packet with 512 byte size. Signed-off-by: Ye Li Signed-off-by: Peng Fan --- drivers/usb/gadget/f_sdp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index f2fe89d2a6..f971ccdeca 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -159,6 +159,16 @@ static struct usb_endpoint_descriptor in_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor in_hs_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress = 1 | USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = 512, + .bInterval = 1, +}; + static struct usb_descriptor_header *sdp_runtime_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc, @@ -166,6 +176,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = { NULL, }; +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = { + (struct usb_descriptor_header *)&sdp_intf_runtime, + (struct usb_descriptor_header *)&sdp_hid_desc, + (struct usb_descriptor_header *)&in_hs_desc, + NULL, +}; + /* This is synchronized with what the SoC implementation reports */ static struct hid_report sdp_hid_report = { .usage_page = { @@ -489,6 +506,11 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f) goto error; } + if (gadget_is_dualspeed(gadget)) { + /* Assume endpoint addresses are the same for both speeds */ + in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress; + } + sdp->in_ep = ep; /* Store IN EP for enabling @ setup */ cdev->req->context = sdp; @@ -541,11 +563,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_sdp *sdp = func_to_sdp(f); struct usb_composite_dev *cdev = f->config->cdev; + struct usb_gadget *gadget = cdev->gadget; int result; debug("%s: intf: %d alt: %d\n", __func__, intf, alt); - result = usb_ep_enable(sdp->in_ep, &in_desc); + if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) + result = usb_ep_enable(sdp->in_ep, &in_hs_desc); + else + result = usb_ep_enable(sdp->in_ep, &in_desc); if (result) return result; sdp->in_req = sdp_start_ep(sdp->in_ep); @@ -591,7 +617,7 @@ static int sdp_bind_config(struct usb_configuration *c) memset(sdp_func, 0, sizeof(*sdp_func)); sdp_func->usb_function.name = "sdp"; - sdp_func->usb_function.hs_descriptors = sdp_runtime_descs; + sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs; sdp_func->usb_function.descriptors = sdp_runtime_descs; sdp_func->usb_function.bind = sdp_bind; sdp_func->usb_function.unbind = sdp_unbind; From patchwork Mon Jun 29 02:32:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 243061 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Mon, 29 Jun 2020 10:32:54 +0800 Subject: [PATCH 3/7] f_sdp: Fix wrong usb request size In-Reply-To: <20200629023258.25452-1-peng.fan@nxp.com> References: <20200629023258.25452-1-peng.fan@nxp.com> Message-ID: <20200629023258.25452-3-peng.fan@nxp.com> From: Ye Li Because the buffer length of sdp usb request is 65, we have to allocate 65 bytes not 64 bytes. Otherwise there is potential buffer overflow. Signed-off-by: Ye Li Signed-off-by: Peng Fan --- drivers/usb/gadget/f_sdp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index f971ccdeca..eec7560fc2 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -548,7 +548,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep) { struct usb_request *req; - req = alloc_ep_req(ep, 64); + req = alloc_ep_req(ep, 65); debug("%s: ep:%p req:%p\n", __func__, ep, req); if (!req) From patchwork Mon Jun 29 02:32:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 243062 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Mon, 29 Jun 2020 10:32:55 +0800 Subject: [PATCH 4/7] f_sdp: Support searching and loading FIT or container image In-Reply-To: <20200629023258.25452-1-peng.fan@nxp.com> References: <20200629023258.25452-1-peng.fan@nxp.com> Message-ID: <20200629023258.25452-4-peng.fan@nxp.com> Add support to f_sdp to search and load iMX8 container image or iMX8M FIT image by new UUU command SDPV. When using the SDPV, the uuu will continue to send out data after first level boot loader used by ROM. This means uuu won't skip to the offset of the second boot loader, and the padding data before second boot loader will be sent out. So we have to search the FIT header or container header in the buffer that SDP received. Also change to more common method to exit f_sdp handler not depending on SPL_FIT_FOUND flag because container loader won't set this. Signed-off-by: Peng Fan --- drivers/usb/gadget/f_sdp.c | 72 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index eec7560fc2..9f5dab23d7 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -71,6 +71,8 @@ struct hid_report { #define SDP_COMMAND_LEN 16 +#define SDP_EXIT 1 + struct sdp_command { u16 cmd; u32 addr; @@ -667,19 +669,42 @@ static u32 sdp_jump_imxheader(void *address) } #ifdef CONFIG_SPL_BUILD -#ifdef CONFIG_SPL_LOAD_FIT -static ulong sdp_fit_read(struct spl_load_info *load, ulong sector, - ulong count, void *buf) +static ulong sdp_load_read(struct spl_load_info *load, ulong sector, + ulong count, void *buf) { debug("%s: sector %lx, count %lx, buf %lx\n", __func__, sector, count, (ulong)buf); memcpy(buf, (void *)(load->dev + sector), count); return count; } -#endif -#endif -static void sdp_handle_in_ep(struct spl_image_info *spl_image) +static ulong search_fit_header(ulong p, int size) +{ + int i; + + for (i = 0; i < size; i += 4) { + if (genimg_get_format((const void *)(p + i)) == IMAGE_FORMAT_FIT) + return p + i; + } + + return 0; +} + +static ulong search_container_header(ulong p, int size) +{ + int i; + u8 *hdr; + + for (i = 0; i < size; i += 4) { + hdr = (u8 *)(p + i); + if (*(hdr + 3) == 0x87 && *hdr == 0) + if (*(hdr + 1) != 0 || *(hdr + 2) != 0) + return p + i; + } + return 0; +} + +static int sdp_handle_in_ep(struct spl_image_info *spl_image) { u8 *data = sdp_func->in_req->buf; u32 status; @@ -731,6 +756,16 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) /* If imx header fails, try some U-Boot specific headers */ if (status) { #ifdef CONFIG_SPL_BUILD + if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) + sdp_func->jmp_address = (u32)search_container_header((ulong)sdp_func->jmp_address, sdp_func->dnl_bytes); + else if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) + sdp_func->jmp_address = (u32)search_fit_header((ulong)sdp_func->jmp_address, sdp_func->dnl_bytes); +#endif + if (sdp_func->jmp_address == 0) + panic("Error in search header, failed to jump\n"); + + printf("Found header at 0x%08x\n", sdp_func->jmp_address); + image_header_t *header = sdp_ptr(sdp_func->jmp_address); #ifdef CONFIG_SPL_LOAD_FIT @@ -740,13 +775,23 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) debug("Found FIT\n"); load.dev = header; load.bl_len = 1; - load.read = sdp_fit_read; + load.read = sdp_load_read; spl_load_simple_fit(spl_image, &load, 0, header); - return; + return SDP_EXIT; } #endif + if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { + struct spl_load_info load; + + load.dev = header; + load.bl_len = 1; + load.read = sdp_load_read; + spl_load_imx_container(spl_image, &load, 0); + return SDP_EXIT; + } + /* In SPL, allow jumps to U-Boot images */ struct spl_image_info spl_image = {}; spl_parse_image_header(&spl_image, header); @@ -769,6 +814,8 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) default: break; }; + + return 0; } #ifndef CONFIG_SPL_BUILD @@ -777,6 +824,7 @@ int sdp_handle(int controller_index) int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) #endif { + int flag = 0; printf("SDP: handle requests...\n"); while (1) { if (ctrlc()) { @@ -784,18 +832,16 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) return -EINVAL; } -#ifdef CONFIG_SPL_BUILD - if (spl_image->flags & SPL_FIT_FOUND) + if (flag == SDP_EXIT) return 0; -#endif WATCHDOG_RESET(); usb_gadget_handle_interrupts(controller_index); #ifdef CONFIG_SPL_BUILD - sdp_handle_in_ep(spl_image); + flag = sdp_handle_in_ep(spl_image); #else - sdp_handle_in_ep(NULL); + flag = sdp_handle_in_ep(NULL); #endif } } From patchwork Mon Jun 29 02:32:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 243063 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Mon, 29 Jun 2020 10:32:56 +0800 Subject: [PATCH 5/7] spl: add g_dnl_get_board_bcd_device_number In-Reply-To: <20200629023258.25452-1-peng.fan@nxp.com> References: <20200629023258.25452-1-peng.fan@nxp.com> Message-ID: <20200629023258.25452-5-peng.fan@nxp.com> Add g_dnl_get_board_bcd_device_number, the new BCD value is used by uuu to distinguish if the SPL supports the SDPV. Signed-off-by: Peng Fan --- arch/arm/mach-imx/spl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c index 1a231c67f5..8c0596d1e1 100644 --- a/arch/arm/mach-imx/spl.c +++ b/arch/arm/mach-imx/spl.c @@ -187,6 +187,12 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) return 0; } + +#define SDPV_BCD_DEVICE 0x500 +int g_dnl_get_board_bcd_device_number(int gcnum) +{ + return SDPV_BCD_DEVICE; +} #endif #if defined(CONFIG_SPL_MMC_SUPPORT) From patchwork Mon Jun 29 02:32:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 243066 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Mon, 29 Jun 2020 10:32:57 +0800 Subject: [PATCH 6/7] f_sdp: Add EP1_OUT as default data receive pipe in sdp In-Reply-To: <20200629023258.25452-1-peng.fan@nxp.com> References: <20200629023258.25452-1-peng.fan@nxp.com> Message-ID: <20200629023258.25452-6-peng.fan@nxp.com> From: Sherry Sun EP0 has been used to transfer file data in sdp before, but the max packetsize of ep0 is 64 bytes. So in order to improve the file transfer speed, here add the EP1_OUT interrupt endpoint which max packetsize is set to 1024 byte. After testing, it turns out that using ep1out is twice as fast as using ep0 while receiving data in sdp. Signed-off-by: Sherry Sun Reviewed-by: Ye Li Signed-off-by: Peng Fan --- drivers/usb/gadget/f_sdp.c | 123 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 16 deletions(-) diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index 9f5dab23d7..4e33be6ada 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -71,6 +71,8 @@ struct hid_report { #define SDP_COMMAND_LEN 16 +#define SDP_HID_PACKET_SIZE_EP1 1024 + #define SDP_EXIT 1 struct sdp_command { @@ -84,8 +86,10 @@ struct sdp_command { enum sdp_state { SDP_STATE_IDLE, + SDP_STATE_RX_CMD, SDP_STATE_RX_DCD_DATA, SDP_STATE_RX_FILE_DATA, + SDP_STATE_RX_FILE_DATA_BUSY, SDP_STATE_TX_SEC_CONF, SDP_STATE_TX_SEC_CONF_BUSY, SDP_STATE_TX_REGISTER, @@ -116,8 +120,12 @@ struct f_sdp { /* EP1 IN */ struct usb_ep *in_ep; struct usb_request *in_req; + /* EP1 OUT */ + struct usb_ep *out_ep; + struct usb_request *out_req; bool configuration_done; + bool ep_int_enable; }; static struct f_sdp *sdp_func; @@ -131,7 +139,7 @@ static struct usb_interface_descriptor sdp_intf_runtime = { .bLength = sizeof(sdp_intf_runtime), .bDescriptorType = USB_DT_INTERFACE, .bAlternateSetting = 0, - .bNumEndpoints = 1, + .bNumEndpoints = 2, .bInterfaceClass = USB_CLASS_HID, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, @@ -161,6 +169,16 @@ static struct usb_endpoint_descriptor in_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress = 1 | USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = 64, + .bInterval = 1, +}; + static struct usb_endpoint_descriptor in_hs_desc = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ @@ -171,10 +189,21 @@ static struct usb_endpoint_descriptor in_hs_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor out_hs_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress = 1 | USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = SDP_HID_PACKET_SIZE_EP1, + .bInterval = 1, +}; + static struct usb_descriptor_header *sdp_runtime_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc, (struct usb_descriptor_header *)&in_desc, + (struct usb_descriptor_header *)&out_desc, NULL, }; @@ -182,6 +211,7 @@ static struct usb_descriptor_header *sdp_runtime_hs_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc, (struct usb_descriptor_header *)&in_hs_desc, + (struct usb_descriptor_header *)&out_hs_desc, NULL, }; @@ -347,7 +377,7 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) int status = req->status; u8 *data = req->buf; u8 report = data[0]; - int datalen = req->length - 1; + int datalen = req->actual - 1; if (status != 0) { pr_err("Status: %d\n", status); @@ -370,13 +400,15 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) sdp->dnl_bytes_remaining -= datalen; } - if (sdp->state == SDP_STATE_RX_FILE_DATA) { + if (sdp->state == SDP_STATE_RX_FILE_DATA_BUSY) { memcpy(sdp_ptr(sdp->dnl_address), req->buf + 1, datalen); sdp->dnl_address += datalen; } - if (sdp->dnl_bytes_remaining) + if (sdp->dnl_bytes_remaining) { + sdp->state = SDP_STATE_RX_FILE_DATA; return; + } #ifndef CONFIG_SPL_BUILD env_set_hex("filesize", sdp->dnl_bytes); @@ -384,7 +416,7 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) printf("done\n"); switch (sdp->state) { - case SDP_STATE_RX_FILE_DATA: + case SDP_STATE_RX_FILE_DATA_BUSY: sdp->state = SDP_STATE_TX_SEC_CONF; break; case SDP_STATE_RX_DCD_DATA: @@ -465,10 +497,12 @@ static int sdp_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) case 1: value = SDP_COMMAND_LEN + 1; req->complete = sdp_rx_command_complete; + sdp_func->ep_int_enable = false; break; case 2: value = len; req->complete = sdp_rx_data_complete; + sdp_func->state = SDP_STATE_RX_FILE_DATA_BUSY; break; } } @@ -499,11 +533,17 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f) return id; sdp_intf_runtime.bInterfaceNumber = id; - struct usb_ep *ep; + struct usb_ep *ep_in, *ep_out; /* allocate instance-specific endpoints */ - ep = usb_ep_autoconfig(gadget, &in_desc); - if (!ep) { + ep_in = usb_ep_autoconfig(gadget, &in_desc); + if (!ep_in) { + rv = -ENODEV; + goto error; + } + + ep_out = usb_ep_autoconfig(gadget, &out_desc); + if (!ep_out) { rv = -ENODEV; goto error; } @@ -511,9 +551,11 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f) if (gadget_is_dualspeed(gadget)) { /* Assume endpoint addresses are the same for both speeds */ in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress; + out_hs_desc.bEndpointAddress = out_desc.bEndpointAddress; } - sdp->in_ep = ep; /* Store IN EP for enabling @ setup */ + sdp->in_ep = ep_in; /* Store IN EP for enabling @ setup */ + sdp->out_ep = ep_out; cdev->req->context = sdp; @@ -546,18 +588,29 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) } -static struct usb_request *sdp_start_ep(struct usb_ep *ep) +static struct usb_request *sdp_start_ep(struct usb_ep *ep, bool in) { struct usb_request *req; - req = alloc_ep_req(ep, 65); + if (in) + req = alloc_ep_req(ep, 65); + else + req = alloc_ep_req(ep, 2048); +/* + * OUT endpoint request length should be an integral multiple of + * maxpacket size 1024, else we break on certain controllers like + * DWC3 that expect bulk OUT requests to be divisible by maxpacket size. + */ debug("%s: ep:%p req:%p\n", __func__, ep, req); if (!req) return NULL; memset(req->buf, 0, req->length); - req->complete = sdp_tx_complete; + if (in) + req->complete = sdp_tx_complete; + else + req->complete = sdp_rx_command_complete; return req; } @@ -570,19 +623,27 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt) debug("%s: intf: %d alt: %d\n", __func__, intf, alt); - if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) + if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) { result = usb_ep_enable(sdp->in_ep, &in_hs_desc); - else + result |= usb_ep_enable(sdp->out_ep, &out_hs_desc); + } else { result = usb_ep_enable(sdp->in_ep, &in_desc); + result |= usb_ep_enable(sdp->out_ep, &out_desc); + } if (result) return result; - sdp->in_req = sdp_start_ep(sdp->in_ep); + + sdp->in_req = sdp_start_ep(sdp->in_ep, true); sdp->in_req->context = sdp; + sdp->out_req = sdp_start_ep(sdp->out_ep, false); + sdp->out_req->context = sdp; sdp->in_ep->driver_data = cdev; /* claim */ + sdp->out_ep->driver_data = cdev; /* claim */ sdp->altsetting = alt; sdp->state = SDP_STATE_IDLE; + sdp->ep_int_enable = true; return 0; } @@ -599,11 +660,18 @@ static void sdp_disable(struct usb_function *f) struct f_sdp *sdp = func_to_sdp(f); usb_ep_disable(sdp->in_ep); + usb_ep_disable(sdp->out_ep); if (sdp->in_req) { - free(sdp->in_req); + free(sdp->in_req->buf); + usb_ep_free_request(sdp->in_ep, sdp->in_req); sdp->in_req = NULL; } + if (sdp->out_req) { + free(sdp->out_req->buf); + usb_ep_free_request(sdp->out_ep, sdp->out_req); + sdp->out_req = NULL; + } } static int sdp_bind_config(struct usb_configuration *c) @@ -818,6 +886,27 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image) return 0; } +static void sdp_handle_out_ep(void) +{ + int rc; + + if (sdp_func->state == SDP_STATE_IDLE) { + sdp_func->out_req->complete = sdp_rx_command_complete; + rc = usb_ep_queue(sdp_func->out_ep, sdp_func->out_req, 0); + if (rc) + printf("error in submission: %s\n", + sdp_func->out_ep->name); + sdp_func->state = SDP_STATE_RX_CMD; + } else if (sdp_func->state == SDP_STATE_RX_FILE_DATA) { + sdp_func->out_req->complete = sdp_rx_data_complete; + rc = usb_ep_queue(sdp_func->out_ep, sdp_func->out_req, 0); + if (rc) + printf("error in submission: %s\n", + sdp_func->out_ep->name); + sdp_func->state = SDP_STATE_RX_FILE_DATA_BUSY; + } +} + #ifndef CONFIG_SPL_BUILD int sdp_handle(int controller_index) #else @@ -843,6 +932,8 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) #else flag = sdp_handle_in_ep(NULL); #endif + if (sdp_func->ep_int_enable) + sdp_handle_out_ep(); } } From patchwork Mon Jun 29 02:32:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 243065 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Mon, 29 Jun 2020 10:32:58 +0800 Subject: [PATCH 7/7] f_sdp: Change bInterval of interrupt endpoint to 3 In-Reply-To: <20200629023258.25452-1-peng.fan@nxp.com> References: <20200629023258.25452-1-peng.fan@nxp.com> Message-ID: <20200629023258.25452-7-peng.fan@nxp.com> From: Sherry Sun Since the USB HID limits the maximum bandwidth(3072) for interrupt endpoint transfers, when the bInterval set to 1, we can only support 3 boards to run sdp at the same time. In order to support more boards, change the bInterval of interrupt endpoint to 3, which will not affect the transmission speed. Reviewed-by: Ye Li Signed-off-by: Sherry Sun Signed-off-by: Peng Fan --- drivers/usb/gadget/f_sdp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index 4e33be6ada..5bde08f707 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -186,7 +186,7 @@ static struct usb_endpoint_descriptor in_hs_desc = { .bEndpointAddress = 1 | USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_INT, .wMaxPacketSize = 512, - .bInterval = 1, + .bInterval = 3, }; static struct usb_endpoint_descriptor out_hs_desc = { @@ -196,7 +196,7 @@ static struct usb_endpoint_descriptor out_hs_desc = { .bEndpointAddress = 1 | USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_INT, .wMaxPacketSize = SDP_HID_PACKET_SIZE_EP1, - .bInterval = 1, + .bInterval = 3, }; static struct usb_descriptor_header *sdp_runtime_descs[] = {