Skip to content

Commit c2aee37

Browse files
committed
Merge tag 'usb-4.18-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB fixes from Greg KH: "Here is a number of USB gadget and other driver fixes for 4.18-rc3. There's a bunch of them here, most of them being gadget driver and xhci host controller fixes for reported issues (as normal), but there are also some new device ids, and some fixes for the typec code. There is an acpi core patch in here that was acked by the acpi maintainer as it is needed for the typec fixes in order to properly solve a problem in that driver. All of these have been in linux-next this week with no reported issues" * tag 'usb-4.18-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (33 commits) usb: chipidea: host: fix disconnection detect issue usb: typec: tcpm: fix logbuffer index is wrong if _tcpm_log is re-entered typec: tcpm: Fix a msecs vs jiffies bug NFC: pn533: Fix wrong GFP flag usage usb: cdc_acm: Add quirk for Uniden UBC125 scanner staging/typec: fix tcpci_rt1711h build errors usb: typec: ucsi: Fix for incorrect status data issue usb: typec: ucsi: acpi: Workaround for cache mode issue acpi: Add helper for deactivating memory region usb: xhci: increase CRS timeout value usb: xhci: tegra: fix runtime PM error handling usb: xhci: remove the code build warning xhci: Fix kernel oops in trace_xhci_free_virt_device xhci: Fix perceived dead host due to runtime suspend race with event handler dwc2: gadget: Fix ISOC IN DDMA PID bitfield value calculation usb: gadget: dwc2: fix memory leak in gadget_init() usb: gadget: composite: fix delayed_status race condition when set_interface usb: dwc2: fix isoc split in transfer with no data usb: dwc2: alloc dma aligned buffer for isoc split in usb: dwc2: fix the incorrect bitmaps for the ports of multi_tt hub ...
2 parents c350d6d + 226e2d2 commit c2aee37

File tree

28 files changed

+373
-66
lines changed

28 files changed

+373
-66
lines changed

Documentation/usb/gadget_configfs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ $ rm configs/<config name>.<number>/<function>
226226
where <config name>.<number> specify the configuration and <function> is
227227
a symlink to a function being removed from the configuration, e.g.:
228228

229-
$ rm configfs/c.1/ncm.usb0
229+
$ rm configs/c.1/ncm.usb0
230230

231231
...
232232
...

drivers/acpi/osl.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#include <linux/uaccess.h>
4646
#include <linux/io-64-nonatomic-lo-hi.h>
4747

48+
#include "acpica/accommon.h"
49+
#include "acpica/acnamesp.h"
4850
#include "internal.h"
4951

5052
#define _COMPONENT ACPI_OS_SERVICES
@@ -1490,6 +1492,76 @@ int acpi_check_region(resource_size_t start, resource_size_t n,
14901492
}
14911493
EXPORT_SYMBOL(acpi_check_region);
14921494

1495+
static acpi_status acpi_deactivate_mem_region(acpi_handle handle, u32 level,
1496+
void *_res, void **return_value)
1497+
{
1498+
struct acpi_mem_space_context **mem_ctx;
1499+
union acpi_operand_object *handler_obj;
1500+
union acpi_operand_object *region_obj2;
1501+
union acpi_operand_object *region_obj;
1502+
struct resource *res = _res;
1503+
acpi_status status;
1504+
1505+
region_obj = acpi_ns_get_attached_object(handle);
1506+
if (!region_obj)
1507+
return AE_OK;
1508+
1509+
handler_obj = region_obj->region.handler;
1510+
if (!handler_obj)
1511+
return AE_OK;
1512+
1513+
if (region_obj->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
1514+
return AE_OK;
1515+
1516+
if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE))
1517+
return AE_OK;
1518+
1519+
region_obj2 = acpi_ns_get_secondary_object(region_obj);
1520+
if (!region_obj2)
1521+
return AE_OK;
1522+
1523+
mem_ctx = (void *)&region_obj2->extra.region_context;
1524+
1525+
if (!(mem_ctx[0]->address >= res->start &&
1526+
mem_ctx[0]->address < res->end))
1527+
return AE_OK;
1528+
1529+
status = handler_obj->address_space.setup(region_obj,
1530+
ACPI_REGION_DEACTIVATE,
1531+
NULL, (void **)mem_ctx);
1532+
if (ACPI_SUCCESS(status))
1533+
region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE);
1534+
1535+
return status;
1536+
}
1537+
1538+
/**
1539+
* acpi_release_memory - Release any mappings done to a memory region
1540+
* @handle: Handle to namespace node
1541+
* @res: Memory resource
1542+
* @level: A level that terminates the search
1543+
*
1544+
* Walks through @handle and unmaps all SystemMemory Operation Regions that
1545+
* overlap with @res and that have already been activated (mapped).
1546+
*
1547+
* This is a helper that allows drivers to place special requirements on memory
1548+
* region that may overlap with operation regions, primarily allowing them to
1549+
* safely map the region as non-cached memory.
1550+
*
1551+
* The unmapped Operation Regions will be automatically remapped next time they
1552+
* are called, so the drivers do not need to do anything else.
1553+
*/
1554+
acpi_status acpi_release_memory(acpi_handle handle, struct resource *res,
1555+
u32 level)
1556+
{
1557+
if (!(res->flags & IORESOURCE_MEM))
1558+
return AE_TYPE;
1559+
1560+
return acpi_walk_namespace(ACPI_TYPE_REGION, handle, level,
1561+
acpi_deactivate_mem_region, NULL, res, NULL);
1562+
}
1563+
EXPORT_SYMBOL_GPL(acpi_release_memory);
1564+
14931565
/*
14941566
* Let drivers know whether the resource checks are effective
14951567
*/

drivers/nfc/pn533/usb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void pn533_recv_response(struct urb *urb)
7474
struct sk_buff *skb = NULL;
7575

7676
if (!urb->status) {
77-
skb = alloc_skb(urb->actual_length, GFP_KERNEL);
77+
skb = alloc_skb(urb->actual_length, GFP_ATOMIC);
7878
if (!skb) {
7979
nfc_err(&phy->udev->dev, "failed to alloc memory\n");
8080
} else {
@@ -186,7 +186,7 @@ static int pn533_usb_send_frame(struct pn533 *dev,
186186

187187
if (dev->protocol_type == PN533_PROTO_REQ_RESP) {
188188
/* request for response for sent packet directly */
189-
rc = pn533_submit_urb_for_response(phy, GFP_ATOMIC);
189+
rc = pn533_submit_urb_for_response(phy, GFP_KERNEL);
190190
if (rc)
191191
goto error;
192192
} else if (dev->protocol_type == PN533_PROTO_REQ_ACK_RESP) {

drivers/staging/typec/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ config TYPEC_TCPCI
1111

1212
config TYPEC_RT1711H
1313
tristate "Richtek RT1711H Type-C chip driver"
14+
depends on I2C
1415
select TYPEC_TCPCI
1516
help
1617
Richtek RT1711H Type-C chip driver that works with

drivers/usb/chipidea/host.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ static int host_start(struct ci_hdrc *ci)
124124

125125
hcd->power_budget = ci->platdata->power_budget;
126126
hcd->tpl_support = ci->platdata->tpl_support;
127-
if (ci->phy || ci->usb_phy)
127+
if (ci->phy || ci->usb_phy) {
128128
hcd->skip_phy_initialization = 1;
129+
if (ci->usb_phy)
130+
hcd->usb_phy = ci->usb_phy;
131+
}
129132

130133
ehci = hcd_to_ehci(hcd);
131134
ehci->caps = ci->hw_bank.cap;

drivers/usb/class/cdc-acm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,9 @@ static const struct usb_device_id acm_ids[] = {
17581758
{ USB_DEVICE(0x11ca, 0x0201), /* VeriFone Mx870 Gadget Serial */
17591759
.driver_info = SINGLE_RX_URB,
17601760
},
1761+
{ USB_DEVICE(0x1965, 0x0018), /* Uniden UBC125XLT */
1762+
.driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1763+
},
17611764
{ USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
17621765
.driver_info = NO_UNION_NORMAL, /* has no union descriptor */
17631766
},

drivers/usb/dwc2/core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ struct dwc2_hregs_backup {
10041004
* @frame_list_sz: Frame list size
10051005
* @desc_gen_cache: Kmem cache for generic descriptors
10061006
* @desc_hsisoc_cache: Kmem cache for hs isochronous descriptors
1007+
* @unaligned_cache: Kmem cache for DMA mode to handle non-aligned buf
10071008
*
10081009
* These are for peripheral mode:
10091010
*
@@ -1177,6 +1178,8 @@ struct dwc2_hsotg {
11771178
u32 frame_list_sz;
11781179
struct kmem_cache *desc_gen_cache;
11791180
struct kmem_cache *desc_hsisoc_cache;
1181+
struct kmem_cache *unaligned_cache;
1182+
#define DWC2_KMEM_UNALIGNED_BUF_SIZE 1024
11801183

11811184
#endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */
11821185

drivers/usb/dwc2/gadget.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ static int dwc2_gadget_fill_isoc_desc(struct dwc2_hsotg_ep *hs_ep,
812812
u32 index;
813813
u32 maxsize = 0;
814814
u32 mask = 0;
815+
u8 pid = 0;
815816

816817
maxsize = dwc2_gadget_get_desc_params(hs_ep, &mask);
817818

@@ -840,7 +841,11 @@ static int dwc2_gadget_fill_isoc_desc(struct dwc2_hsotg_ep *hs_ep,
840841
((len << DEV_DMA_NBYTES_SHIFT) & mask));
841842

842843
if (hs_ep->dir_in) {
843-
desc->status |= ((hs_ep->mc << DEV_DMA_ISOC_PID_SHIFT) &
844+
if (len)
845+
pid = DIV_ROUND_UP(len, hs_ep->ep.maxpacket);
846+
else
847+
pid = 1;
848+
desc->status |= ((pid << DEV_DMA_ISOC_PID_SHIFT) &
844849
DEV_DMA_ISOC_PID_MASK) |
845850
((len % hs_ep->ep.maxpacket) ?
846851
DEV_DMA_SHORT : 0) |
@@ -884,6 +889,7 @@ static void dwc2_gadget_start_isoc_ddma(struct dwc2_hsotg_ep *hs_ep)
884889
struct dwc2_dma_desc *desc;
885890

886891
if (list_empty(&hs_ep->queue)) {
892+
hs_ep->target_frame = TARGET_FRAME_INITIAL;
887893
dev_dbg(hsotg->dev, "%s: No requests in queue\n", __func__);
888894
return;
889895
}
@@ -2755,8 +2761,6 @@ static void dwc2_gadget_handle_out_token_ep_disabled(struct dwc2_hsotg_ep *ep)
27552761
*/
27562762
tmp = dwc2_hsotg_read_frameno(hsotg);
27572763

2758-
dwc2_hsotg_complete_request(hsotg, ep, get_ep_head(ep), 0);
2759-
27602764
if (using_desc_dma(hsotg)) {
27612765
if (ep->target_frame == TARGET_FRAME_INITIAL) {
27622766
/* Start first ISO Out */
@@ -2817,9 +2821,6 @@ static void dwc2_gadget_handle_nak(struct dwc2_hsotg_ep *hs_ep)
28172821

28182822
tmp = dwc2_hsotg_read_frameno(hsotg);
28192823
if (using_desc_dma(hsotg)) {
2820-
dwc2_hsotg_complete_request(hsotg, hs_ep,
2821-
get_ep_head(hs_ep), 0);
2822-
28232824
hs_ep->target_frame = tmp;
28242825
dwc2_gadget_incr_frame_num(hs_ep);
28252826
dwc2_gadget_start_isoc_ddma(hs_ep);
@@ -4739,9 +4740,11 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
47394740
}
47404741

47414742
ret = usb_add_gadget_udc(dev, &hsotg->gadget);
4742-
if (ret)
4743+
if (ret) {
4744+
dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep,
4745+
hsotg->ctrl_req);
47434746
return ret;
4744-
4747+
}
47454748
dwc2_hsotg_dump(hsotg);
47464749

47474750
return 0;
@@ -4755,6 +4758,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
47554758
int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg)
47564759
{
47574760
usb_del_gadget_udc(&hsotg->gadget);
4761+
dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req);
47584762

47594763
return 0;
47604764
}

drivers/usb/dwc2/hcd.c

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,11 +1567,20 @@ static void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
15671567
}
15681568

15691569
if (hsotg->params.host_dma) {
1570-
dwc2_writel((u32)chan->xfer_dma,
1571-
hsotg->regs + HCDMA(chan->hc_num));
1570+
dma_addr_t dma_addr;
1571+
1572+
if (chan->align_buf) {
1573+
if (dbg_hc(chan))
1574+
dev_vdbg(hsotg->dev, "align_buf\n");
1575+
dma_addr = chan->align_buf;
1576+
} else {
1577+
dma_addr = chan->xfer_dma;
1578+
}
1579+
dwc2_writel((u32)dma_addr, hsotg->regs + HCDMA(chan->hc_num));
1580+
15721581
if (dbg_hc(chan))
15731582
dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n",
1574-
(unsigned long)chan->xfer_dma, chan->hc_num);
1583+
(unsigned long)dma_addr, chan->hc_num);
15751584
}
15761585

15771586
/* Start the split */
@@ -2625,6 +2634,35 @@ static void dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg,
26252634
}
26262635
}
26272636

2637+
static int dwc2_alloc_split_dma_aligned_buf(struct dwc2_hsotg *hsotg,
2638+
struct dwc2_qh *qh,
2639+
struct dwc2_host_chan *chan)
2640+
{
2641+
if (!hsotg->unaligned_cache ||
2642+
chan->max_packet > DWC2_KMEM_UNALIGNED_BUF_SIZE)
2643+
return -ENOMEM;
2644+
2645+
if (!qh->dw_align_buf) {
2646+
qh->dw_align_buf = kmem_cache_alloc(hsotg->unaligned_cache,
2647+
GFP_ATOMIC | GFP_DMA);
2648+
if (!qh->dw_align_buf)
2649+
return -ENOMEM;
2650+
}
2651+
2652+
qh->dw_align_buf_dma = dma_map_single(hsotg->dev, qh->dw_align_buf,
2653+
DWC2_KMEM_UNALIGNED_BUF_SIZE,
2654+
DMA_FROM_DEVICE);
2655+
2656+
if (dma_mapping_error(hsotg->dev, qh->dw_align_buf_dma)) {
2657+
dev_err(hsotg->dev, "can't map align_buf\n");
2658+
chan->align_buf = 0;
2659+
return -EINVAL;
2660+
}
2661+
2662+
chan->align_buf = qh->dw_align_buf_dma;
2663+
return 0;
2664+
}
2665+
26282666
#define DWC2_USB_DMA_ALIGN 4
26292667

26302668
struct dma_aligned_buffer {
@@ -2802,6 +2840,32 @@ static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
28022840
/* Set the transfer attributes */
28032841
dwc2_hc_init_xfer(hsotg, chan, qtd);
28042842

2843+
/* For non-dword aligned buffers */
2844+
if (hsotg->params.host_dma && qh->do_split &&
2845+
chan->ep_is_in && (chan->xfer_dma & 0x3)) {
2846+
dev_vdbg(hsotg->dev, "Non-aligned buffer\n");
2847+
if (dwc2_alloc_split_dma_aligned_buf(hsotg, qh, chan)) {
2848+
dev_err(hsotg->dev,
2849+
"Failed to allocate memory to handle non-aligned buffer\n");
2850+
/* Add channel back to free list */
2851+
chan->align_buf = 0;
2852+
chan->multi_count = 0;
2853+
list_add_tail(&chan->hc_list_entry,
2854+
&hsotg->free_hc_list);
2855+
qtd->in_process = 0;
2856+
qh->channel = NULL;
2857+
return -ENOMEM;
2858+
}
2859+
} else {
2860+
/*
2861+
* We assume that DMA is always aligned in non-split
2862+
* case or split out case. Warn if not.
2863+
*/
2864+
WARN_ON_ONCE(hsotg->params.host_dma &&
2865+
(chan->xfer_dma & 0x3));
2866+
chan->align_buf = 0;
2867+
}
2868+
28052869
if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
28062870
chan->ep_type == USB_ENDPOINT_XFER_ISOC)
28072871
/*
@@ -5246,6 +5310,19 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
52465310
}
52475311
}
52485312

5313+
if (hsotg->params.host_dma) {
5314+
/*
5315+
* Create kmem caches to handle non-aligned buffer
5316+
* in Buffer DMA mode.
5317+
*/
5318+
hsotg->unaligned_cache = kmem_cache_create("dwc2-unaligned-dma",
5319+
DWC2_KMEM_UNALIGNED_BUF_SIZE, 4,
5320+
SLAB_CACHE_DMA, NULL);
5321+
if (!hsotg->unaligned_cache)
5322+
dev_err(hsotg->dev,
5323+
"unable to create dwc2 unaligned cache\n");
5324+
}
5325+
52495326
hsotg->otg_port = 1;
52505327
hsotg->frame_list = NULL;
52515328
hsotg->frame_list_dma = 0;
@@ -5280,8 +5357,9 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg)
52805357
return 0;
52815358

52825359
error4:
5283-
kmem_cache_destroy(hsotg->desc_gen_cache);
5360+
kmem_cache_destroy(hsotg->unaligned_cache);
52845361
kmem_cache_destroy(hsotg->desc_hsisoc_cache);
5362+
kmem_cache_destroy(hsotg->desc_gen_cache);
52855363
error3:
52865364
dwc2_hcd_release(hsotg);
52875365
error2:
@@ -5322,8 +5400,9 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
53225400
usb_remove_hcd(hcd);
53235401
hsotg->priv = NULL;
53245402

5325-
kmem_cache_destroy(hsotg->desc_gen_cache);
5403+
kmem_cache_destroy(hsotg->unaligned_cache);
53265404
kmem_cache_destroy(hsotg->desc_hsisoc_cache);
5405+
kmem_cache_destroy(hsotg->desc_gen_cache);
53275406

53285407
dwc2_hcd_release(hsotg);
53295408
usb_put_hcd(hcd);
@@ -5435,7 +5514,7 @@ int dwc2_host_enter_hibernation(struct dwc2_hsotg *hsotg)
54355514
dwc2_writel(hprt0, hsotg->regs + HPRT0);
54365515

54375516
/* Wait for the HPRT0.PrtSusp register field to be set */
5438-
if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 300))
5517+
if (dwc2_hsotg_wait_bit_set(hsotg, HPRT0, HPRT0_SUSP, 3000))
54395518
dev_warn(hsotg->dev, "Suspend wasn't generated\n");
54405519

54415520
/*
@@ -5616,6 +5695,8 @@ int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup,
56165695
return ret;
56175696
}
56185697

5698+
dwc2_hcd_rem_wakeup(hsotg);
5699+
56195700
hsotg->hibernated = 0;
56205701
hsotg->bus_suspended = 0;
56215702
hsotg->lx_state = DWC2_L0;

0 commit comments

Comments
 (0)