Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'fixes-for-v3.17-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-linus

Felipe writes:

usb: fixes for v3.17-rc3

A new set of fixes which have been pending for a while. All patches
have been randconfig build-tested and boot tested where applicable.

The most important fixes are MUSB on AM335x learned how to transfer
ZLPs, and net2280 got a fix for reset IRQ handling.

Signed-of-by: Felipe Balbi <balbi@ti.com>

+172 -24
+1
Documentation/devicetree/bindings/usb/mxs-phy.txt
··· 5 5 * "fsl,imx23-usbphy" for imx23 and imx28 6 6 * "fsl,imx6q-usbphy" for imx6dq and imx6dl 7 7 * "fsl,imx6sl-usbphy" for imx6sl 8 + * "fsl,imx6sx-usbphy" for imx6sx 8 9 "fsl,imx23-usbphy" is still a fallback for other strings 9 10 - reg: Should contain registers location and length 10 11 - interrupts: Should contain phy interrupt
+55 -11
drivers/usb/gadget/function/f_fs.c
··· 155 155 struct usb_request *req; 156 156 }; 157 157 158 + struct ffs_desc_helper { 159 + struct ffs_data *ffs; 160 + unsigned interfaces_count; 161 + unsigned eps_count; 162 + }; 163 + 158 164 static int __must_check ffs_epfiles_create(struct ffs_data *ffs); 159 165 static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count); 160 166 ··· 1836 1830 u8 *valuep, struct usb_descriptor_header *desc, 1837 1831 void *priv) 1838 1832 { 1839 - struct ffs_data *ffs = priv; 1833 + struct ffs_desc_helper *helper = priv; 1834 + struct usb_endpoint_descriptor *d; 1840 1835 1841 1836 ENTER(); 1842 1837 ··· 1851 1844 * encountered interface "n" then there are at least 1852 1845 * "n+1" interfaces. 1853 1846 */ 1854 - if (*valuep >= ffs->interfaces_count) 1855 - ffs->interfaces_count = *valuep + 1; 1847 + if (*valuep >= helper->interfaces_count) 1848 + helper->interfaces_count = *valuep + 1; 1856 1849 break; 1857 1850 1858 1851 case FFS_STRING: ··· 1860 1853 * Strings are indexed from 1 (0 is magic ;) reserved 1861 1854 * for languages list or some such) 1862 1855 */ 1863 - if (*valuep > ffs->strings_count) 1864 - ffs->strings_count = *valuep; 1856 + if (*valuep > helper->ffs->strings_count) 1857 + helper->ffs->strings_count = *valuep; 1865 1858 break; 1866 1859 1867 1860 case FFS_ENDPOINT: 1868 - /* Endpoints are indexed from 1 as well. */ 1869 - if ((*valuep & USB_ENDPOINT_NUMBER_MASK) > ffs->eps_count) 1870 - ffs->eps_count = (*valuep & USB_ENDPOINT_NUMBER_MASK); 1861 + d = (void *)desc; 1862 + helper->eps_count++; 1863 + if (helper->eps_count >= 15) 1864 + return -EINVAL; 1865 + /* Check if descriptors for any speed were already parsed */ 1866 + if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) 1867 + helper->ffs->eps_addrmap[helper->eps_count] = 1868 + d->bEndpointAddress; 1869 + else if (helper->ffs->eps_addrmap[helper->eps_count] != 1870 + d->bEndpointAddress) 1871 + return -EINVAL; 1871 1872 break; 1872 1873 } 1873 1874 ··· 2068 2053 char *data = _data, *raw_descs; 2069 2054 unsigned os_descs_count = 0, counts[3], flags; 2070 2055 int ret = -EINVAL, i; 2056 + struct ffs_desc_helper helper; 2071 2057 2072 2058 ENTER(); 2073 2059 ··· 2117 2101 2118 2102 /* Read descriptors */ 2119 2103 raw_descs = data; 2104 + helper.ffs = ffs; 2120 2105 for (i = 0; i < 3; ++i) { 2121 2106 if (!counts[i]) 2122 2107 continue; 2108 + helper.interfaces_count = 0; 2109 + helper.eps_count = 0; 2123 2110 ret = ffs_do_descs(counts[i], data, len, 2124 - __ffs_data_do_entity, ffs); 2111 + __ffs_data_do_entity, &helper); 2125 2112 if (ret < 0) 2126 2113 goto error; 2114 + if (!ffs->eps_count && !ffs->interfaces_count) { 2115 + ffs->eps_count = helper.eps_count; 2116 + ffs->interfaces_count = helper.interfaces_count; 2117 + } else { 2118 + if (ffs->eps_count != helper.eps_count) { 2119 + ret = -EINVAL; 2120 + goto error; 2121 + } 2122 + if (ffs->interfaces_count != helper.interfaces_count) { 2123 + ret = -EINVAL; 2124 + goto error; 2125 + } 2126 + } 2127 2127 data += ret; 2128 2128 len -= ret; 2129 2129 } ··· 2374 2342 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); 2375 2343 } 2376 2344 2377 - 2378 2345 /* Bind/unbind USB function hooks *******************************************/ 2346 + 2347 + static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) 2348 + { 2349 + int i; 2350 + 2351 + for (i = 1; i < ARRAY_SIZE(ffs->eps_addrmap); ++i) 2352 + if (ffs->eps_addrmap[i] == endpoint_address) 2353 + return i; 2354 + return -ENOENT; 2355 + } 2379 2356 2380 2357 static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, 2381 2358 struct usb_descriptor_header *desc, ··· 2419 2378 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) 2420 2379 return 0; 2421 2380 2422 - idx = (ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) - 1; 2381 + idx = ffs_ep_addr2idx(func->ffs, ds->bEndpointAddress) - 1; 2382 + if (idx < 0) 2383 + return idx; 2384 + 2423 2385 ffs_ep = func->eps + idx; 2424 2386 2425 2387 if (unlikely(ffs_ep->descs[ep_desc_id])) {
+2
drivers/usb/gadget/function/u_fs.h
··· 224 224 void *ms_os_descs_ext_prop_name_avail; 225 225 void *ms_os_descs_ext_prop_data_avail; 226 226 227 + u8 eps_addrmap[15]; 228 + 227 229 unsigned short strings_count; 228 230 unsigned short interfaces_count; 229 231 unsigned short eps_count;
+1 -1
drivers/usb/gadget/udc/fusb300_udc.h
··· 12 12 13 13 14 14 #ifndef __FUSB300_UDC_H__ 15 - #define __FUSB300_UDC_H_ 15 + #define __FUSB300_UDC_H__ 16 16 17 17 #include <linux/kernel.h> 18 18
+1 -1
drivers/usb/gadget/udc/net2280.c
··· 3320 3320 if (stat & tmp) { 3321 3321 writel(tmp, &dev->regs->irqstat1); 3322 3322 if ((((stat & BIT(ROOT_PORT_RESET_INTERRUPT)) && 3323 - (readl(&dev->usb->usbstat) & mask)) || 3323 + ((readl(&dev->usb->usbstat) & mask) == 0)) || 3324 3324 ((readl(&dev->usb->usbctl) & 3325 3325 BIT(VBUS_PIN)) == 0)) && 3326 3326 (dev->gadget.speed != USB_SPEED_UNKNOWN)) {
+15 -2
drivers/usb/musb/musb_cppi41.c
··· 39 39 u32 transferred; 40 40 u32 packet_sz; 41 41 struct list_head tx_check; 42 + int tx_zlp; 42 43 }; 43 44 44 45 #define MUSB_DMA_NUM_CHANNELS 15 ··· 123 122 { 124 123 struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; 125 124 struct musb *musb = hw_ep->musb; 125 + void __iomem *epio = hw_ep->regs; 126 + u16 csr; 126 127 127 128 if (!cppi41_channel->prog_len || 128 129 (cppi41_channel->channel.status == MUSB_DMA_STATUS_FREE)) { ··· 134 131 cppi41_channel->transferred; 135 132 cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE; 136 133 cppi41_channel->channel.rx_packet_done = true; 134 + 135 + /* 136 + * transmit ZLP using PIO mode for transfers which size is 137 + * multiple of EP packet size. 138 + */ 139 + if (cppi41_channel->tx_zlp && (cppi41_channel->transferred % 140 + cppi41_channel->packet_sz) == 0) { 141 + musb_ep_select(musb->mregs, hw_ep->epnum); 142 + csr = MUSB_TXCSR_MODE | MUSB_TXCSR_TXPKTRDY; 143 + musb_writew(epio, MUSB_TXCSR, csr); 144 + } 137 145 musb_dma_completion(musb, hw_ep->epnum, cppi41_channel->is_tx); 138 146 } else { 139 147 /* next iteration, reload */ 140 148 struct dma_chan *dc = cppi41_channel->dc; 141 149 struct dma_async_tx_descriptor *dma_desc; 142 150 enum dma_transfer_direction direction; 143 - u16 csr; 144 151 u32 remain_bytes; 145 - void __iomem *epio = cppi41_channel->hw_ep->regs; 146 152 147 153 cppi41_channel->buf_addr += cppi41_channel->packet_sz; 148 154 ··· 375 363 cppi41_channel->total_len = len; 376 364 cppi41_channel->transferred = 0; 377 365 cppi41_channel->packet_sz = packet_sz; 366 + cppi41_channel->tx_zlp = (cppi41_channel->is_tx && mode) ? 1 : 0; 378 367 379 368 /* 380 369 * Due to AM335x' Advisory 1.0.13 we are not allowed to transfer more
+7 -1
drivers/usb/phy/phy-mxs-usb.c
··· 1 1 /* 2 - * Copyright 2012-2013 Freescale Semiconductor, Inc. 2 + * Copyright 2012-2014 Freescale Semiconductor, Inc. 3 3 * Copyright (C) 2012 Marek Vasut <marex@denx.de> 4 4 * on behalf of DENX Software Engineering GmbH 5 5 * ··· 125 125 MXS_PHY_NEED_IP_FIX, 126 126 }; 127 127 128 + static const struct mxs_phy_data imx6sx_phy_data = { 129 + .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | 130 + MXS_PHY_NEED_IP_FIX, 131 + }; 132 + 128 133 static const struct of_device_id mxs_phy_dt_ids[] = { 134 + { .compatible = "fsl,imx6sx-usbphy", .data = &imx6sx_phy_data, }, 129 135 { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, }, 130 136 { .compatible = "fsl,imx6q-usbphy", .data = &imx6q_phy_data, }, 131 137 { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, },
+2 -2
drivers/usb/phy/phy-tegra-usb.c
··· 878 878 return -ENOMEM; 879 879 } 880 880 881 - tegra_phy->config = devm_kzalloc(&pdev->dev, 882 - sizeof(*tegra_phy->config), GFP_KERNEL); 881 + tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config), 882 + GFP_KERNEL); 883 883 if (!tegra_phy->config) { 884 884 dev_err(&pdev->dev, 885 885 "unable to allocate memory for USB UTMIP config\n");
+66 -6
drivers/usb/renesas_usbhs/fifo.c
··· 108 108 return list_first_entry(&pipe->list, struct usbhs_pkt, node); 109 109 } 110 110 111 + static void usbhsf_fifo_clear(struct usbhs_pipe *pipe, 112 + struct usbhs_fifo *fifo); 113 + static void usbhsf_fifo_unselect(struct usbhs_pipe *pipe, 114 + struct usbhs_fifo *fifo); 115 + static struct dma_chan *usbhsf_dma_chan_get(struct usbhs_fifo *fifo, 116 + struct usbhs_pkt *pkt); 117 + #define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1) 118 + #define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0) 119 + static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map); 111 120 struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt) 112 121 { 113 122 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 123 + struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe); 114 124 unsigned long flags; 115 125 116 126 /******************** spin lock ********************/ 117 127 usbhs_lock(priv, flags); 118 128 129 + usbhs_pipe_disable(pipe); 130 + 119 131 if (!pkt) 120 132 pkt = __usbhsf_pkt_get(pipe); 121 133 122 - if (pkt) 134 + if (pkt) { 135 + struct dma_chan *chan = NULL; 136 + 137 + if (fifo) 138 + chan = usbhsf_dma_chan_get(fifo, pkt); 139 + if (chan) { 140 + dmaengine_terminate_all(chan); 141 + usbhsf_fifo_clear(pipe, fifo); 142 + usbhsf_dma_unmap(pkt); 143 + } 144 + 123 145 __usbhsf_pkt_del(pkt); 146 + } 147 + 148 + if (fifo) 149 + usbhsf_fifo_unselect(pipe, fifo); 124 150 125 151 usbhs_unlock(priv, flags); 126 152 /******************** spin unlock ******************/ ··· 570 544 usbhsf_send_terminator(pipe, fifo); 571 545 572 546 usbhsf_tx_irq_ctrl(pipe, !*is_done); 547 + usbhs_pipe_running(pipe, !*is_done); 573 548 usbhs_pipe_enable(pipe); 574 549 575 550 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n", ··· 597 570 * retry in interrupt 598 571 */ 599 572 usbhsf_tx_irq_ctrl(pipe, 1); 573 + usbhs_pipe_running(pipe, 1); 600 574 601 575 return ret; 602 576 } 603 577 578 + static int usbhsf_pio_prepare_push(struct usbhs_pkt *pkt, int *is_done) 579 + { 580 + if (usbhs_pipe_is_running(pkt->pipe)) 581 + return 0; 582 + 583 + return usbhsf_pio_try_push(pkt, is_done); 584 + } 585 + 604 586 struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = { 605 - .prepare = usbhsf_pio_try_push, 587 + .prepare = usbhsf_pio_prepare_push, 606 588 .try_run = usbhsf_pio_try_push, 607 589 }; 608 590 ··· 625 589 if (usbhs_pipe_is_busy(pipe)) 626 590 return 0; 627 591 592 + if (usbhs_pipe_is_running(pipe)) 593 + return 0; 594 + 628 595 /* 629 596 * pipe enable to prepare packet receive 630 597 */ ··· 636 597 637 598 usbhs_pipe_set_trans_count_if_bulk(pipe, pkt->length); 638 599 usbhs_pipe_enable(pipe); 600 + usbhs_pipe_running(pipe, 1); 639 601 usbhsf_rx_irq_ctrl(pipe, 1); 640 602 641 603 return 0; ··· 682 642 (total_len < maxp)) { /* short packet */ 683 643 *is_done = 1; 684 644 usbhsf_rx_irq_ctrl(pipe, 0); 645 + usbhs_pipe_running(pipe, 0); 685 646 usbhs_pipe_disable(pipe); /* disable pipe first */ 686 647 } 687 648 ··· 804 763 usbhs_bset(priv, fifo->sel, DREQE, dreqe); 805 764 } 806 765 807 - #define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1) 808 - #define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0) 809 766 static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map) 810 767 { 811 768 struct usbhs_pipe *pipe = pkt->pipe; ··· 844 805 dev_dbg(dev, " %s %d (%d/ %d)\n", 845 806 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero); 846 807 808 + usbhs_pipe_running(pipe, 1); 847 809 usbhs_pipe_set_trans_count_if_bulk(pipe, pkt->trans); 848 810 usbhs_pipe_enable(pipe); 849 811 usbhsf_dma_start(pipe, fifo); ··· 875 835 876 836 if ((uintptr_t)(pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */ 877 837 goto usbhsf_pio_prepare_push; 838 + 839 + /* return at this time if the pipe is running */ 840 + if (usbhs_pipe_is_running(pipe)) 841 + return 0; 878 842 879 843 /* get enable DMA fifo */ 880 844 fifo = usbhsf_get_dma_fifo(priv, pkt); ··· 913 869 static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done) 914 870 { 915 871 struct usbhs_pipe *pipe = pkt->pipe; 872 + int is_short = pkt->trans % usbhs_pipe_get_maxpacket(pipe); 916 873 917 - pkt->actual = pkt->trans; 874 + pkt->actual += pkt->trans; 918 875 919 - *is_done = !pkt->zero; /* send zero packet ? */ 876 + if (pkt->actual < pkt->length) 877 + *is_done = 0; /* there are remainder data */ 878 + else if (is_short) 879 + *is_done = 1; /* short packet */ 880 + else 881 + *is_done = !pkt->zero; /* send zero packet? */ 882 + 883 + usbhs_pipe_running(pipe, !*is_done); 920 884 921 885 usbhsf_dma_stop(pipe, pipe->fifo); 922 886 usbhsf_dma_unmap(pkt); 923 887 usbhsf_fifo_unselect(pipe, pipe->fifo); 888 + 889 + if (!*is_done) { 890 + /* change handler to PIO */ 891 + pkt->handler = &usbhs_fifo_pio_push_handler; 892 + return pkt->handler->try_run(pkt, is_done); 893 + } 924 894 925 895 return 0; 926 896 } ··· 1030 972 if ((pkt->actual == pkt->length) || /* receive all data */ 1031 973 (pkt->trans < maxp)) { /* short packet */ 1032 974 *is_done = 1; 975 + usbhs_pipe_running(pipe, 0); 1033 976 } else { 1034 977 /* re-enable */ 978 + usbhs_pipe_running(pipe, 0); 1035 979 usbhsf_prepare_pop(pkt, is_done); 1036 980 } 1037 981
+5
drivers/usb/renesas_usbhs/mod.c
··· 213 213 { 214 214 struct usbhs_mod *mod = usbhs_mod_get_current(priv); 215 215 u16 intenb0, intenb1; 216 + unsigned long flags; 216 217 218 + /******************** spin lock ********************/ 219 + usbhs_lock(priv, flags); 217 220 state->intsts0 = usbhs_read(priv, INTSTS0); 218 221 state->intsts1 = usbhs_read(priv, INTSTS1); 219 222 ··· 232 229 state->bempsts &= mod->irq_bempsts; 233 230 state->brdysts &= mod->irq_brdysts; 234 231 } 232 + usbhs_unlock(priv, flags); 233 + /******************** spin unlock ******************/ 235 234 236 235 /* 237 236 * Check whether the irq enable registers and the irq status are set
+13
drivers/usb/renesas_usbhs/pipe.c
··· 578 578 return usbhsp_flags_has(pipe, IS_DIR_HOST); 579 579 } 580 580 581 + int usbhs_pipe_is_running(struct usbhs_pipe *pipe) 582 + { 583 + return usbhsp_flags_has(pipe, IS_RUNNING); 584 + } 585 + 586 + void usbhs_pipe_running(struct usbhs_pipe *pipe, int running) 587 + { 588 + if (running) 589 + usbhsp_flags_set(pipe, IS_RUNNING); 590 + else 591 + usbhsp_flags_clr(pipe, IS_RUNNING); 592 + } 593 + 581 594 void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int sequence) 582 595 { 583 596 u16 mask = (SQCLR | SQSET);
+4
drivers/usb/renesas_usbhs/pipe.h
··· 36 36 #define USBHS_PIPE_FLAGS_IS_USED (1 << 0) 37 37 #define USBHS_PIPE_FLAGS_IS_DIR_IN (1 << 1) 38 38 #define USBHS_PIPE_FLAGS_IS_DIR_HOST (1 << 2) 39 + #define USBHS_PIPE_FLAGS_IS_RUNNING (1 << 3) 39 40 40 41 struct usbhs_pkt_handle *handler; 41 42 ··· 81 80 void usbhs_pipe_remove(struct usbhs_priv *priv); 82 81 int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe); 83 82 int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe); 83 + int usbhs_pipe_is_running(struct usbhs_pipe *pipe); 84 + void usbhs_pipe_running(struct usbhs_pipe *pipe, int running); 85 + 84 86 void usbhs_pipe_init(struct usbhs_priv *priv, 85 87 int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map)); 86 88 int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);