now that we have generic map/unmap utilities, we can use them to drop some duplication from UDC drivers. Signed-off-by: Felipe Balbi <balbi@xxxxxx> --- drivers/usb/dwc3/ep0.c | 6 ++- drivers/usb/dwc3/gadget.c | 79 ++++------------------------------------ drivers/usb/dwc3/gadget.h | 2 - drivers/usb/musb/musb_gadget.c | 38 ++------------------ 4 files changed, 14 insertions(+), 111 deletions(-) diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 69a4e43..ed1f2f4 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -681,7 +681,8 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc, DWC3_TRBCTL_CONTROL_DATA); } else if ((req->request.length % dep->endpoint.maxpacket) && (event->endpoint_number == 0)) { - dwc3_map_buffer_to_dma(req); + usb_gadget_map_request(&dwc->gadget, &req->request, + req->direction); WARN_ON(req->request.length > dep->endpoint.maxpacket); @@ -696,7 +697,8 @@ static void dwc3_ep0_do_control_data(struct dwc3 *dwc, dwc->ep0_bounce_addr, dep->endpoint.maxpacket, DWC3_TRBCTL_CONTROL_DATA); } else { - dwc3_map_buffer_to_dma(req); + usb_gadget_map_request(&dwc->gadget, &req->request, + req->direction); ret = dwc3_ep0_start_trans(dwc, event->endpoint_number, req->request.dma, req->request.length, diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 9741026..3969d65 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -45,7 +45,6 @@ #include <linux/interrupt.h> #include <linux/io.h> #include <linux/list.h> -#include <linux/dma-mapping.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> @@ -54,70 +53,6 @@ #include "gadget.h" #include "io.h" -#define DMA_ADDR_INVALID (~(dma_addr_t)0) - -void dwc3_map_buffer_to_dma(struct dwc3_request *req) -{ - struct dwc3 *dwc = req->dep->dwc; - - if (req->request.length == 0) { - /* req->request.dma = dwc->setup_buf_addr; */ - return; - } - - if (req->request.num_sgs) { - int mapped; - - mapped = dma_map_sg(dwc->dev, req->request.sg, - req->request.num_sgs, - req->direction ? DMA_TO_DEVICE - : DMA_FROM_DEVICE); - if (mapped < 0) { - dev_err(dwc->dev, "failed to map SGs\n"); - return; - } - - req->request.num_mapped_sgs = mapped; - return; - } - - if (req->request.dma == DMA_ADDR_INVALID) { - req->request.dma = dma_map_single(dwc->dev, req->request.buf, - req->request.length, req->direction - ? DMA_TO_DEVICE : DMA_FROM_DEVICE); - req->mapped = true; - } -} - -void dwc3_unmap_buffer_from_dma(struct dwc3_request *req) -{ - struct dwc3 *dwc = req->dep->dwc; - - if (req->request.length == 0) { - req->request.dma = DMA_ADDR_INVALID; - return; - } - - if (req->request.num_mapped_sgs) { - req->request.dma = DMA_ADDR_INVALID; - dma_unmap_sg(dwc->dev, req->request.sg, - req->request.num_sgs, - req->direction ? DMA_TO_DEVICE - : DMA_FROM_DEVICE); - - req->request.num_mapped_sgs = 0; - return; - } - - if (req->mapped) { - dma_unmap_single(dwc->dev, req->request.dma, - req->request.length, req->direction - ? DMA_TO_DEVICE : DMA_FROM_DEVICE); - req->mapped = 0; - req->request.dma = DMA_ADDR_INVALID; - } -} - void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, int status) { @@ -144,7 +79,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, if (req->request.status == -EINPROGRESS) req->request.status = status; - dwc3_unmap_buffer_from_dma(req); + usb_gadget_unmap_request(&dwc->gadget, &req->request, req->direction); dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", req, dep->name, req->request.actual, @@ -817,7 +752,8 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param, * here and stop, unmap, free and del each of the linked * requests instead of we do now. */ - dwc3_unmap_buffer_from_dma(req); + usb_gadget_unmap_request(&dwc->gadget, &req->request, + req->direction); list_del(&req->list); return ret; } @@ -832,6 +768,8 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param, static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) { + struct dwc3 *dwc = dep->dwc; + req->request.actual = 0; req->request.status = -EINPROGRESS; req->direction = dep->direction; @@ -849,7 +787,7 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) * This will also avoid Host cancelling URBs due to too * many NACKs. */ - dwc3_map_buffer_to_dma(req); + usb_gadget_map_request(&dwc->gadget, &req->request, req->direction); list_add_tail(&req->list, &dep->request_list); /* @@ -874,12 +812,9 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) start_trans = 0; ret = __dwc3_gadget_kick_transfer(dep, 0, start_trans); - if (ret && ret != -EBUSY) { - struct dwc3 *dwc = dep->dwc; - + if (ret && ret != -EBUSY) dev_dbg(dwc->dev, "%s: failed to kick transfers\n", dep->name); - } }; return 0; diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index 71145a4..a2133eac 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -133,8 +133,6 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value); int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); -void dwc3_map_buffer_to_dma(struct dwc3_request *req); -void dwc3_unmap_buffer_from_dma(struct dwc3_request *req); /** * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 3148461..b3e4038 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -119,24 +119,7 @@ static inline void map_dma_buffer(struct musb_request *request, if (!compatible) return; - if (request->request.dma == DMA_ADDR_INVALID) { - request->request.dma = dma_map_single( - musb->controller, - request->request.buf, - request->request.length, - request->tx - ? DMA_TO_DEVICE - : DMA_FROM_DEVICE); - request->map_state = MUSB_MAPPED; - } else { - dma_sync_single_for_device(musb->controller, - request->request.dma, - request->request.length, - request->tx - ? DMA_TO_DEVICE - : DMA_FROM_DEVICE); - request->map_state = PRE_MAPPED; - } + usb_gadget_map_request(&musb->g, &request->request, request->tx); } /* Unmap the buffer from dma and maps it back to cpu */ @@ -151,23 +134,8 @@ static inline void unmap_dma_buffer(struct musb_request *request, "not unmapping a never mapped buffer\n"); return; } - if (request->map_state == MUSB_MAPPED) { - dma_unmap_single(musb->controller, - request->request.dma, - request->request.length, - request->tx - ? DMA_TO_DEVICE - : DMA_FROM_DEVICE); - request->request.dma = DMA_ADDR_INVALID; - } else { /* PRE_MAPPED */ - dma_sync_single_for_cpu(musb->controller, - request->request.dma, - request->request.length, - request->tx - ? DMA_TO_DEVICE - : DMA_FROM_DEVICE); - } - request->map_state = UN_MAPPED; + + usb_gadget_unmap_request(&musb->g, &request->request, request->tx); } /* -- 1.7.8.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html