Skip to content

Commit 6bdd39b

Browse files
Tomesmil
authored andcommitted
drivers/usb: Add dcache flush(VIC7100 ONLY)
drivers/usb/cdns3/ drivers/usb/core/ drivers/usb/host/ include/linux/usb.h Geert: Rebase to v5.13-rc1 Stafford: Don't flush NULL values Signed-off-by: Stafford Horne <shorne@gmail.com>
1 parent 7a144b2 commit 6bdd39b

File tree

17 files changed

+1209
-50
lines changed

17 files changed

+1209
-50
lines changed

drivers/usb/cdns3/cdns3-debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ static inline char *cdns3_dbg_ring(struct cdns3_endpoint *priv_ep,
152152
le32_to_cpu(trb->buffer),
153153
le32_to_cpu(trb->length),
154154
le32_to_cpu(trb->control));
155+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
156+
cdns_virt_flush_dcache(trb, sizeof(struct cdns3_trb));
157+
#endif
155158
addr += sizeof(*trb);
156159
}
157160

drivers/usb/cdns3/cdns3-ep0.c

Lines changed: 117 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ static void cdns3_ep0_run_transfer(struct cdns3_device *priv_dev,
5353
priv_ep->trb_pool[1].control = 0;
5454
}
5555

56+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
57+
cdns_flush_dcache(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma),
58+
2 * TRB_SIZE);
59+
#endif
60+
5661
trace_cdns3_prepare_trb(priv_ep, priv_ep->trb_pool);
5762

5863
cdns3_select_ep(priv_dev, priv_dev->ep0_data_dir);
@@ -88,6 +93,9 @@ static int cdns3_ep0_delegate_req(struct cdns3_device *priv_dev,
8893
spin_unlock(&priv_dev->lock);
8994
priv_dev->setup_pending = 1;
9095
ret = priv_dev->gadget_driver->setup(&priv_dev->gadget, ctrl_req);
96+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
97+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
98+
#endif
9199
priv_dev->setup_pending = 0;
92100
spin_lock(&priv_dev->lock);
93101
return ret;
@@ -97,6 +105,12 @@ static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev)
97105
{
98106
priv_dev->ep0_data_dir = 0;
99107
priv_dev->ep0_stage = CDNS3_SETUP_STAGE;
108+
109+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
110+
gadget_flush_dcache(priv_dev->setup_dma,
111+
sizeof(struct usb_ctrlrequest));
112+
#endif
113+
100114
cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma,
101115
sizeof(struct usb_ctrlrequest), 0, 0);
102116
}
@@ -140,6 +154,9 @@ static int cdns3_req_ep0_set_configuration(struct cdns3_device *priv_dev,
140154
u32 config = le16_to_cpu(ctrl_req->wValue);
141155
int result = 0;
142156

157+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
158+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
159+
#endif
143160
switch (device_state) {
144161
case USB_STATE_ADDRESS:
145162
result = cdns3_ep0_delegate_req(priv_dev, ctrl_req);
@@ -185,7 +202,9 @@ static int cdns3_req_ep0_set_address(struct cdns3_device *priv_dev,
185202
u32 addr;
186203

187204
addr = le16_to_cpu(ctrl_req->wValue);
188-
205+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
206+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
207+
#endif
189208
if (addr > USB_DEVICE_MAX_ADDRESS) {
190209
dev_err(priv_dev->dev,
191210
"Device address (%d) cannot be greater than %d\n",
@@ -225,9 +244,14 @@ static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev,
225244
u16 usb_status = 0;
226245
u32 recip;
227246
u8 index;
247+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
248+
u32 tmp_ind;
249+
#endif
228250

229251
recip = ctrl->bRequestType & USB_RECIP_MASK;
230-
252+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
253+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
254+
#endif
231255
switch (recip) {
232256
case USB_RECIP_DEVICE:
233257
/* self powered */
@@ -253,8 +277,17 @@ static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev,
253277
index = cdns3_ep_addr_to_index(le16_to_cpu(ctrl->wIndex));
254278
priv_ep = priv_dev->eps[index];
255279

280+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
281+
tmp_ind = ctrl->wIndex;
282+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
283+
284+
/* check if endpoint is stalled or stall is pending */
285+
cdns3_select_ep(priv_dev, tmp_ind);
286+
#else
287+
256288
/* check if endpoint is stalled or stall is pending */
257289
cdns3_select_ep(priv_dev, le16_to_cpu(ctrl->wIndex));
290+
#endif
258291
if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts)) ||
259292
(priv_ep->flags & EP_STALL_PENDING))
260293
usb_status = BIT(USB_ENDPOINT_HALT);
@@ -266,6 +299,10 @@ static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev,
266299
response_pkt = (__le16 *)priv_dev->setup_buf;
267300
*response_pkt = cpu_to_le16(usb_status);
268301

302+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
303+
cdns_flush_dcache(priv_dev->setup_dma, sizeof(*response_pkt));
304+
#endif
305+
269306
cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma,
270307
sizeof(*response_pkt), 1, 0);
271308
return 0;
@@ -282,6 +319,9 @@ static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev,
282319
u16 tmode;
283320

284321
wValue = le16_to_cpu(ctrl->wValue);
322+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
323+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
324+
#endif
285325
state = priv_dev->gadget.state;
286326
speed = priv_dev->gadget.speed;
287327

@@ -309,7 +349,9 @@ static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev,
309349
return -EINVAL;
310350

311351
tmode = le16_to_cpu(ctrl->wIndex);
312-
352+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
353+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
354+
#endif
313355
if (!set || (tmode & 0xff) != 0)
314356
return -EINVAL;
315357

@@ -342,7 +384,9 @@ static int cdns3_ep0_feature_handle_intf(struct cdns3_device *priv_dev,
342384
int ret = 0;
343385

344386
wValue = le16_to_cpu(ctrl->wValue);
345-
387+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
388+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
389+
#endif
346390
switch (wValue) {
347391
case USB_INTRF_FUNC_SUSPEND:
348392
break;
@@ -360,17 +404,38 @@ static int cdns3_ep0_feature_handle_endpoint(struct cdns3_device *priv_dev,
360404
struct cdns3_endpoint *priv_ep;
361405
int ret = 0;
362406
u8 index;
363-
364-
if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT)
407+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
408+
u32 tmp_ind;
409+
#endif
410+
411+
if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) {
412+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
413+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
414+
#endif
365415
return -EINVAL;
416+
}
366417

367-
if (!(le16_to_cpu(ctrl->wIndex) & ~USB_DIR_IN))
418+
if (!(le16_to_cpu(ctrl->wIndex) & ~USB_DIR_IN)) {
419+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
420+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
421+
#endif
368422
return 0;
423+
}
424+
425+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
426+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
427+
#endif
369428

370429
index = cdns3_ep_addr_to_index(le16_to_cpu(ctrl->wIndex));
371430
priv_ep = priv_dev->eps[index];
372431

432+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
433+
tmp_ind = ctrl->wIndex;
434+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
435+
cdns3_select_ep(priv_dev, tmp_ind);
436+
#else
373437
cdns3_select_ep(priv_dev, le16_to_cpu(ctrl->wIndex));
438+
#endif
374439

375440
if (set)
376441
__cdns3_gadget_ep_set_halt(priv_ep);
@@ -400,7 +465,9 @@ static int cdns3_req_ep0_handle_feature(struct cdns3_device *priv_dev,
400465
u32 recip;
401466

402467
recip = ctrl->bRequestType & USB_RECIP_MASK;
403-
468+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
469+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
470+
#endif
404471
switch (recip) {
405472
case USB_RECIP_DEVICE:
406473
ret = cdns3_ep0_feature_handle_device(priv_dev, ctrl, set);
@@ -434,9 +501,17 @@ static int cdns3_req_ep0_set_sel(struct cdns3_device *priv_dev,
434501
if (le16_to_cpu(ctrl_req->wLength) != 6) {
435502
dev_err(priv_dev->dev, "Set SEL should be 6 bytes, got %d\n",
436503
ctrl_req->wLength);
504+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
505+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
506+
#endif
437507
return -EINVAL;
438508
}
439509

510+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
511+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
512+
cdns_flush_dcache(priv_dev->setup_dma, 6);
513+
#endif
514+
440515
cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 6, 1, 0);
441516
return 0;
442517
}
@@ -452,11 +527,19 @@ static int cdns3_req_ep0_set_sel(struct cdns3_device *priv_dev,
452527
static int cdns3_req_ep0_set_isoch_delay(struct cdns3_device *priv_dev,
453528
struct usb_ctrlrequest *ctrl_req)
454529
{
455-
if (ctrl_req->wIndex || ctrl_req->wLength)
530+
if (ctrl_req->wIndex || ctrl_req->wLength) {
531+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
532+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
533+
#endif
456534
return -EINVAL;
535+
}
457536

458537
priv_dev->isoch_delay = le16_to_cpu(ctrl_req->wValue);
459538

539+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
540+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
541+
#endif
542+
460543
return 0;
461544
}
462545

@@ -472,7 +555,13 @@ static int cdns3_ep0_standard_request(struct cdns3_device *priv_dev,
472555
{
473556
int ret;
474557

558+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
559+
u8 bReq = ctrl_req->bRequest;
560+
cdns_virt_flush_dcache(ctrl_req, sizeof(struct usb_ctrlrequest));
561+
switch (bReq) {
562+
#else
475563
switch (ctrl_req->bRequest) {
564+
#endif
476565
case USB_REQ_SET_ADDRESS:
477566
ret = cdns3_req_ep0_set_address(priv_dev, ctrl_req);
478567
break;
@@ -535,7 +624,9 @@ static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev)
535624
int result;
536625

537626
priv_dev->ep0_data_dir = ctrl->bRequestType & USB_DIR_IN;
538-
627+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
628+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
629+
#endif
539630
trace_cdns3_ctrl_req(ctrl);
540631

541632
if (!list_empty(&priv_ep->pending_req_list)) {
@@ -552,10 +643,17 @@ static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev)
552643
else
553644
priv_dev->ep0_stage = CDNS3_STATUS_STAGE;
554645

555-
if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD)
646+
if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
647+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
648+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
649+
#endif
556650
result = cdns3_ep0_standard_request(priv_dev, ctrl);
557-
else
651+
} else {
652+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
653+
cdns_virt_flush_dcache(ctrl, sizeof(struct usb_ctrlrequest));
654+
#endif
558655
result = cdns3_ep0_delegate_req(priv_dev, ctrl);
656+
}
559657

560658
if (result == USB_GADGET_DELAYED_STATUS)
561659
return;
@@ -579,6 +677,10 @@ static void cdns3_transfer_completed(struct cdns3_device *priv_dev)
579677
request->actual =
580678
TRB_LEN(le32_to_cpu(priv_ep->trb_pool->length));
581679

680+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
681+
cdns_flush_dcache(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma),
682+
sizeof(struct cdns3_trb));
683+
#endif
582684
priv_ep->dir = priv_dev->ep0_data_dir;
583685
cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), 0);
584686
}
@@ -764,6 +866,9 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
764866
(request->length % ep->maxpacket == 0))
765867
zlp = 1;
766868

869+
#ifdef CONFIG_USB_CDNS3_HOST_FLUSH_DMA
870+
gadget_flush_dcache(request->dma, request->length);
871+
#endif
767872
cdns3_ep0_run_transfer(priv_dev, request->dma, request->length, 1, zlp);
768873

769874
spin_unlock_irqrestore(&priv_dev->lock, flags);

0 commit comments

Comments
 (0)