Skip to content

Commit 1a3fc3e

Browse files
pcercueinunojsa
authored andcommitted
usb: gadget: Support already-mapped DMA SGs
Add a new 'sg_was_mapped' field to the struct usb_request. This field can be used to indicate that the scatterlist associated to the USB transfer has already been mapped into the DMA space, and it does not have to be done internally. Signed-off-by: Paul Cercueil <paul@crapouillou.net> Link: https://lore.kernel.org/r/20240130122340.54813-2-paul@crapouillou.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aded153 commit 1a3fc3e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

drivers/usb/gadget/udc/core.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,11 @@ int usb_gadget_map_request_by_dev(struct device *dev,
905905
if (req->length == 0)
906906
return 0;
907907

908+
if (req->sg_was_mapped) {
909+
req->num_mapped_sgs = req->num_sgs;
910+
return 0;
911+
}
912+
908913
if (req->num_sgs) {
909914
int mapped;
910915

@@ -950,7 +955,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request);
950955
void usb_gadget_unmap_request_by_dev(struct device *dev,
951956
struct usb_request *req, int is_in)
952957
{
953-
if (req->length == 0)
958+
if (req->length == 0 || req->sg_was_mapped)
954959
return;
955960

956961
if (req->num_mapped_sgs) {

include/linux/usb/gadget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct usb_ep;
5252
* @short_not_ok: When reading data, makes short packets be
5353
* treated as errors (queue stops advancing till cleanup).
5454
* @dma_mapped: Indicates if request has been mapped to DMA (internal)
55+
* @sg_was_mapped: Set if the scatterlist has been mapped before the request
5556
* @complete: Function called when request completes, so this request and
5657
* its buffer may be re-used. The function will always be called with
5758
* interrupts disabled, and it must not sleep.
@@ -111,6 +112,7 @@ struct usb_request {
111112
unsigned zero:1;
112113
unsigned short_not_ok:1;
113114
unsigned dma_mapped:1;
115+
unsigned sg_was_mapped:1;
114116

115117
void (*complete)(struct usb_ep *ep,
116118
struct usb_request *req);

0 commit comments

Comments
 (0)