Skip to content

Commit 4dfb9ce

Browse files
committed
Merge tag 'fixes-for-v5.7-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-linus
Felipe writes: USB: fixes for v5.7-rc2 DWC3 learns how to properly set maxpacket limit and got a fix for a request completion bug. The raw gadget got a fix for copy_to/from_user() checks. Atmel got an improvement on vbus disconnect handling. We're also adding support for another SoC to the Renesas DRD driver. * tag 'fixes-for-v5.7-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb: usb: raw-gadget: Fix copy_to/from_user() checks usb: raw-gadget: fix raw_event_queue_fetch locking usb: gadget: udc: atmel: Fix vbus disconnect handling usb: dwc3: gadget: Fix request completion check usb: dwc3: gadget: Do link recovery for SS and SSP dt-bindings: usb: renesas,usb3-peri: add r8a77961 support dt-bindings: usb: renesas,usbhs: add r8a77961 support dt-bindings: usb: usb-xhci: add r8a77961 support docs: dt: qcom,dwc3.txt: fix cross-reference for a converted file usb: dwc3: gadget: Properly set maxpacket limit usb: dwc3: Fix GTXFIFOSIZ.TXFDEP macro name usb: gadget: udc: bdc: Remove unnecessary NULL checks in bdc_req_complete
2 parents be34a58 + a7b7783 commit 4dfb9ce

File tree

8 files changed

+62
-37
lines changed

8 files changed

+62
-37
lines changed

Documentation/devicetree/bindings/usb/qcom,dwc3.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ A child node must exist to represent the core DWC3 IP block. The name of
5252
the node is not important. The content of the node is defined in dwc3.txt.
5353

5454
Phy documentation is provided in the following places:
55-
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt - USB3 QMP PHY
56-
Documentation/devicetree/bindings/phy/qcom-qusb2-phy.txt - USB2 QUSB2 PHY
55+
Documentation/devicetree/bindings/phy/qcom-qmp-phy.txt - USB3 QMP PHY
56+
Documentation/devicetree/bindings/phy/qcom,qusb2-phy.yaml - USB2 QUSB2 PHY
5757

5858
Example device nodes:
5959

Documentation/devicetree/bindings/usb/renesas,usb3-peri.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ properties:
1818
- renesas,r8a774c0-usb3-peri # RZ/G2E
1919
- renesas,r8a7795-usb3-peri # R-Car H3
2020
- renesas,r8a7796-usb3-peri # R-Car M3-W
21+
- renesas,r8a77961-usb3-peri # R-Car M3-W+
2122
- renesas,r8a77965-usb3-peri # R-Car M3-N
2223
- renesas,r8a77990-usb3-peri # R-Car E3
2324
- const: renesas,rcar-gen3-usb3-peri

Documentation/devicetree/bindings/usb/renesas,usbhs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ properties:
4040
- renesas,usbhs-r8a774c0 # RZ/G2E
4141
- renesas,usbhs-r8a7795 # R-Car H3
4242
- renesas,usbhs-r8a7796 # R-Car M3-W
43+
- renesas,usbhs-r8a77961 # R-Car M3-W+
4344
- renesas,usbhs-r8a77965 # R-Car M3-N
4445
- renesas,usbhs-r8a77990 # R-Car E3
4546
- renesas,usbhs-r8a77995 # R-Car D3

Documentation/devicetree/bindings/usb/usb-xhci.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Required properties:
1616
- "renesas,xhci-r8a7791" for r8a7791 SoC
1717
- "renesas,xhci-r8a7793" for r8a7793 SoC
1818
- "renesas,xhci-r8a7795" for r8a7795 SoC
19-
- "renesas,xhci-r8a7796" for r8a7796 SoC
19+
- "renesas,xhci-r8a7796" for r8a77960 SoC
20+
- "renesas,xhci-r8a77961" for r8a77961 SoC
2021
- "renesas,xhci-r8a77965" for r8a77965 SoC
2122
- "renesas,xhci-r8a77990" for r8a77990 SoC
2223
- "renesas,rcar-gen2-xhci" for a generic R-Car Gen2 or RZ/G1 compatible

drivers/usb/dwc3/core.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,14 @@
307307

308308
/* Global TX Fifo Size Register */
309309
#define DWC31_GTXFIFOSIZ_TXFRAMNUM BIT(15) /* DWC_usb31 only */
310-
#define DWC31_GTXFIFOSIZ_TXFDEF(n) ((n) & 0x7fff) /* DWC_usb31 only */
311-
#define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff)
310+
#define DWC31_GTXFIFOSIZ_TXFDEP(n) ((n) & 0x7fff) /* DWC_usb31 only */
311+
#define DWC3_GTXFIFOSIZ_TXFDEP(n) ((n) & 0xffff)
312312
#define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000)
313313

314+
/* Global RX Fifo Size Register */
315+
#define DWC31_GRXFIFOSIZ_RXFDEP(n) ((n) & 0x7fff) /* DWC_usb31 only */
316+
#define DWC3_GRXFIFOSIZ_RXFDEP(n) ((n) & 0xffff)
317+
314318
/* Global Event Size Registers */
315319
#define DWC3_GEVNTSIZ_INTMASK BIT(31)
316320
#define DWC3_GEVNTSIZ_SIZE(n) ((n) & 0xffff)

drivers/usb/dwc3/gadget.c

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,6 @@ static int __dwc3_gadget_wakeup(struct dwc3 *dwc)
17281728
u32 reg;
17291729

17301730
u8 link_state;
1731-
u8 speed;
17321731

17331732
/*
17341733
* According to the Databook Remote wakeup request should
@@ -1738,16 +1737,13 @@ static int __dwc3_gadget_wakeup(struct dwc3 *dwc)
17381737
*/
17391738
reg = dwc3_readl(dwc->regs, DWC3_DSTS);
17401739

1741-
speed = reg & DWC3_DSTS_CONNECTSPD;
1742-
if ((speed == DWC3_DSTS_SUPERSPEED) ||
1743-
(speed == DWC3_DSTS_SUPERSPEED_PLUS))
1744-
return 0;
1745-
17461740
link_state = DWC3_DSTS_USBLNKST(reg);
17471741

17481742
switch (link_state) {
1743+
case DWC3_LINK_STATE_RESET:
17491744
case DWC3_LINK_STATE_RX_DET: /* in HS, means Early Suspend */
17501745
case DWC3_LINK_STATE_U3: /* in HS, means SUSPEND */
1746+
case DWC3_LINK_STATE_RESUME:
17511747
break;
17521748
default:
17531749
return -EINVAL;
@@ -2227,7 +2223,6 @@ static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
22272223
{
22282224
struct dwc3 *dwc = dep->dwc;
22292225
int mdwidth;
2230-
int kbytes;
22312226
int size;
22322227

22332228
mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
@@ -2236,24 +2231,24 @@ static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
22362231

22372232
size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1));
22382233
if (dwc3_is_usb31(dwc))
2239-
size = DWC31_GTXFIFOSIZ_TXFDEF(size);
2234+
size = DWC31_GTXFIFOSIZ_TXFDEP(size);
22402235
else
2241-
size = DWC3_GTXFIFOSIZ_TXFDEF(size);
2236+
size = DWC3_GTXFIFOSIZ_TXFDEP(size);
22422237

22432238
/* FIFO Depth is in MDWDITH bytes. Multiply */
22442239
size *= mdwidth;
22452240

2246-
kbytes = size / 1024;
2247-
if (kbytes == 0)
2248-
kbytes = 1;
2249-
22502241
/*
2251-
* FIFO sizes account an extra MDWIDTH * (kbytes + 1) bytes for
2252-
* internal overhead. We don't really know how these are used,
2253-
* but documentation say it exists.
2242+
* To meet performance requirement, a minimum TxFIFO size of 3x
2243+
* MaxPacketSize is recommended for endpoints that support burst and a
2244+
* minimum TxFIFO size of 2x MaxPacketSize for endpoints that don't
2245+
* support burst. Use those numbers and we can calculate the max packet
2246+
* limit as below.
22542247
*/
2255-
size -= mdwidth * (kbytes + 1);
2256-
size /= kbytes;
2248+
if (dwc->maximum_speed >= USB_SPEED_SUPER)
2249+
size /= 3;
2250+
else
2251+
size /= 2;
22572252

22582253
usb_ep_set_maxpacket_limit(&dep->endpoint, size);
22592254

@@ -2271,8 +2266,39 @@ static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
22712266
static int dwc3_gadget_init_out_endpoint(struct dwc3_ep *dep)
22722267
{
22732268
struct dwc3 *dwc = dep->dwc;
2269+
int mdwidth;
2270+
int size;
2271+
2272+
mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
22742273

2275-
usb_ep_set_maxpacket_limit(&dep->endpoint, 1024);
2274+
/* MDWIDTH is represented in bits, convert to bytes */
2275+
mdwidth /= 8;
2276+
2277+
/* All OUT endpoints share a single RxFIFO space */
2278+
size = dwc3_readl(dwc->regs, DWC3_GRXFIFOSIZ(0));
2279+
if (dwc3_is_usb31(dwc))
2280+
size = DWC31_GRXFIFOSIZ_RXFDEP(size);
2281+
else
2282+
size = DWC3_GRXFIFOSIZ_RXFDEP(size);
2283+
2284+
/* FIFO depth is in MDWDITH bytes */
2285+
size *= mdwidth;
2286+
2287+
/*
2288+
* To meet performance requirement, a minimum recommended RxFIFO size
2289+
* is defined as follow:
2290+
* RxFIFO size >= (3 x MaxPacketSize) +
2291+
* (3 x 8 bytes setup packets size) + (16 bytes clock crossing margin)
2292+
*
2293+
* Then calculate the max packet limit as below.
2294+
*/
2295+
size -= (3 * 8) + 16;
2296+
if (size < 0)
2297+
size = 0;
2298+
else
2299+
size /= 3;
2300+
2301+
usb_ep_set_maxpacket_limit(&dep->endpoint, size);
22762302
dep->endpoint.max_streams = 15;
22772303
dep->endpoint.ops = &dwc3_gadget_ep_ops;
22782304
list_add_tail(&dep->endpoint.ep_list,
@@ -2484,14 +2510,7 @@ static int dwc3_gadget_ep_reclaim_trb_linear(struct dwc3_ep *dep,
24842510

24852511
static bool dwc3_gadget_ep_request_completed(struct dwc3_request *req)
24862512
{
2487-
/*
2488-
* For OUT direction, host may send less than the setup
2489-
* length. Return true for all OUT requests.
2490-
*/
2491-
if (!req->direction)
2492-
return true;
2493-
2494-
return req->request.actual == req->request.length;
2513+
return req->num_pending_sgs == 0;
24952514
}
24962515

24972516
static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
@@ -2515,8 +2534,7 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
25152534

25162535
req->request.actual = req->request.length - req->remaining;
25172536

2518-
if (!dwc3_gadget_ep_request_completed(req) ||
2519-
req->num_pending_sgs) {
2537+
if (!dwc3_gadget_ep_request_completed(req)) {
25202538
__dwc3_gadget_kick_transfer(dep);
25212539
goto out;
25222540
}

drivers/usb/gadget/udc/atmel_usba_udc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,10 +1951,10 @@ static irqreturn_t usba_vbus_irq_thread(int irq, void *devid)
19511951
usba_start(udc);
19521952
} else {
19531953
udc->suspended = false;
1954-
usba_stop(udc);
1955-
19561954
if (udc->driver->disconnect)
19571955
udc->driver->disconnect(&udc->gadget);
1956+
1957+
usba_stop(udc);
19581958
}
19591959
udc->vbus_prev = vbus;
19601960
}

drivers/usb/gadget/udc/bdc/bdc_ep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req,
540540
{
541541
struct bdc *bdc = ep->bdc;
542542

543-
if (req == NULL || &req->queue == NULL || &req->usb_req == NULL)
543+
if (req == NULL)
544544
return;
545545

546546
dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status);

0 commit comments

Comments
 (0)