* [PATCH] usb: gadget: Support transfers from device memory
@ 2023-10-31 3:54 Manan Aurora
2023-10-31 6:00 ` Greg Kroah-Hartman
2023-10-31 14:27 ` Alan Stern
0 siblings, 2 replies; 3+ messages in thread
From: Manan Aurora @ 2023-10-31 3:54 UTC (permalink / raw)
To: Greg Kroah-Hartman, Alan Stern, Badhri Jagan Sridharan,
Francesco Dolcini
Cc: linux-usb, linux-kernel, manugautam, Manan Aurora
USB gadget stack only supports usb_request objects that point to buffers
located in memory. Support use cases where data is transferred from
physical addresses in device mmio regions
Added a bit "pre_mapped" to usb_request to bypass dma_map_single and
dma_map_sg for such requests
The caller must determine the dma address for the request before queuing
it
Signed-off-by: Manan Aurora <maurora@google.com>
---
drivers/usb/gadget/udc/core.c | 4 ++--
include/linux/usb/gadget.h | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index ded9531f141b..236165ba08f4 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -900,7 +900,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_activate);
int usb_gadget_map_request_by_dev(struct device *dev,
struct usb_request *req, int is_in)
{
- if (req->length == 0)
+ if (req->pre_mapped || req->length == 0)
return 0;
if (req->num_sgs) {
@@ -948,7 +948,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request);
void usb_gadget_unmap_request_by_dev(struct device *dev,
struct usb_request *req, int is_in)
{
- if (req->length == 0)
+ if (req->pre_mapped || req->length == 0)
return;
if (req->num_mapped_sgs) {
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a771ccc038ac..6bc035439098 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -111,6 +111,7 @@ struct usb_request {
unsigned zero:1;
unsigned short_not_ok:1;
unsigned dma_mapped:1;
+ unsigned pre_mapped:1;
void (*complete)(struct usb_ep *ep,
struct usb_request *req);
--
2.42.0.820.g83a721a137-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: gadget: Support transfers from device memory
2023-10-31 3:54 [PATCH] usb: gadget: Support transfers from device memory Manan Aurora
@ 2023-10-31 6:00 ` Greg Kroah-Hartman
2023-10-31 14:27 ` Alan Stern
1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-31 6:00 UTC (permalink / raw)
To: Manan Aurora
Cc: Alan Stern, Badhri Jagan Sridharan, Francesco Dolcini, linux-usb,
linux-kernel, manugautam
On Tue, Oct 31, 2023 at 03:54:02AM +0000, Manan Aurora wrote:
> USB gadget stack only supports usb_request objects that point to buffers
> located in memory. Support use cases where data is transferred from
> physical addresses in device mmio regions
>
> Added a bit "pre_mapped" to usb_request to bypass dma_map_single and
> dma_map_sg for such requests
>
> The caller must determine the dma address for the request before queuing
> it
>
> Signed-off-by: Manan Aurora <maurora@google.com>
> ---
> drivers/usb/gadget/udc/core.c | 4 ++--
> include/linux/usb/gadget.h | 1 +
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
> index ded9531f141b..236165ba08f4 100644
> --- a/drivers/usb/gadget/udc/core.c
> +++ b/drivers/usb/gadget/udc/core.c
> @@ -900,7 +900,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_activate);
> int usb_gadget_map_request_by_dev(struct device *dev,
> struct usb_request *req, int is_in)
> {
> - if (req->length == 0)
> + if (req->pre_mapped || req->length == 0)
> return 0;
>
> if (req->num_sgs) {
> @@ -948,7 +948,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request);
> void usb_gadget_unmap_request_by_dev(struct device *dev,
> struct usb_request *req, int is_in)
> {
> - if (req->length == 0)
> + if (req->pre_mapped || req->length == 0)
> return;
>
> if (req->num_mapped_sgs) {
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index a771ccc038ac..6bc035439098 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -111,6 +111,7 @@ struct usb_request {
> unsigned zero:1;
> unsigned short_not_ok:1;
> unsigned dma_mapped:1;
> + unsigned pre_mapped:1;
>
> void (*complete)(struct usb_ep *ep,
> struct usb_request *req);
> --
> 2.42.0.820.g83a721a137-goog
>
>
You can not add features/functionality that no in-kernel driver uses, so
this can not be accepted as-is, sorry. Please submit it as part of a
patch series where it is actually used, otherwise we have no idea if
this is even something that we should do or not.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: gadget: Support transfers from device memory
2023-10-31 3:54 [PATCH] usb: gadget: Support transfers from device memory Manan Aurora
2023-10-31 6:00 ` Greg Kroah-Hartman
@ 2023-10-31 14:27 ` Alan Stern
1 sibling, 0 replies; 3+ messages in thread
From: Alan Stern @ 2023-10-31 14:27 UTC (permalink / raw)
To: Manan Aurora
Cc: Greg Kroah-Hartman, Badhri Jagan Sridharan, Francesco Dolcini,
linux-usb, linux-kernel, manugautam
On Tue, Oct 31, 2023 at 03:54:02AM +0000, Manan Aurora wrote:
> USB gadget stack only supports usb_request objects that point to buffers
> located in memory. Support use cases where data is transferred from
> physical addresses in device mmio regions
>
> Added a bit "pre_mapped" to usb_request to bypass dma_map_single and
> dma_map_sg for such requests
>
> The caller must determine the dma address for the request before queuing
> it
>
> Signed-off-by: Manan Aurora <maurora@google.com>
> ---
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index a771ccc038ac..6bc035439098 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -111,6 +111,7 @@ struct usb_request {
> unsigned zero:1;
> unsigned short_not_ok:1;
> unsigned dma_mapped:1;
> + unsigned pre_mapped:1;
>
> void (*complete)(struct usb_ep *ep,
> struct usb_request *req);
You forgot to update the kerneldoc for struct usb_request.
Alan Stern
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-31 14:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-31 3:54 [PATCH] usb: gadget: Support transfers from device memory Manan Aurora
2023-10-31 6:00 ` Greg Kroah-Hartman
2023-10-31 14:27 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox