diff mbox series

[18/27] xhci: dbc: Don't use generic xhci context allocation for dbc

Message ID 20200723144530.9992-19-mathias.nyman@linux.intel.com (mailing list archive)
State Superseded
Commit cb66434e67cc30e2971879fe36e03c8ca7208101
Headers show
Series xhci features for usb-next | expand

Commit Message

Mathias Nyman July 23, 2020, 2:45 p.m. UTC
The DbC context is different from the xhci device context.
It's a lot smaller as it only contains three 64 bytes sub-contexts;
the info, endpoint-out, and endpoint-in contexts. In total 192 bytes.
The context size (CSZ) field in HCCPARAMS1 xhci register does not alter
DbC context size like it does for xhci device contexts.

So don't use the geneic xhci context memory allocation, or the
dma pool that is intended for xhci device contexts.

In addition to saving memory this also helps decoupleing xhci and dbc code.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 2473100b955a..fb56198d3aff 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -14,6 +14,14 @@ 
 #include "xhci-trace.h"
 #include "xhci-dbgcap.h"
 
+static void dbc_free_ctx(struct device *dev, struct xhci_container_ctx *ctx)
+{
+	if (!ctx)
+		return;
+	dma_free_coherent(dev, ctx->size, ctx->bytes, ctx->dma);
+	kfree(ctx);
+}
+
 static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
 {
 	struct usb_string_descriptor	*s_desc;
@@ -364,6 +372,25 @@  static void dbc_erst_free(struct device *dev, struct xhci_erst *erst)
 	erst->entries = NULL;
 }
 
+static struct xhci_container_ctx *
+dbc_alloc_ctx(struct device *dev, gfp_t flags)
+{
+	struct xhci_container_ctx *ctx;
+
+	ctx = kzalloc(sizeof(*ctx), flags);
+	if (!ctx)
+		return NULL;
+
+	/* xhci 7.6.9, all three contexts; info, ep-out and ep-in. Each 64 bytes*/
+	ctx->size = 3 * DBC_CONTEXT_SIZE;
+	ctx->bytes = dma_alloc_coherent(dev, ctx->size, &ctx->dma, flags);
+	if (!ctx->bytes) {
+		kfree(ctx);
+		return NULL;
+	}
+	return ctx;
+}
+
 static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 {
 	int			ret;
@@ -391,7 +418,7 @@  static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 		goto erst_fail;
 
 	/* Allocate context data structure: */
-	dbc->ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags);
+	dbc->ctx = dbc_alloc_ctx(dev, flags); /* was sysdev, and is still */
 	if (!dbc->ctx)
 		goto ctx_fail;
 
@@ -420,7 +447,7 @@  static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	return 0;
 
 string_fail:
-	xhci_free_container_ctx(xhci, dbc->ctx);
+	dbc_free_ctx(dev, dbc->ctx);
 	dbc->ctx = NULL;
 ctx_fail:
 	dbc_erst_free(dev, &dbc->erst);
@@ -453,7 +480,7 @@  static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
 		dbc->string = NULL;
 	}
 
-	xhci_free_container_ctx(xhci, dbc->ctx);
+	dbc_free_ctx(dbc->dev, dbc->ctx);
 	dbc->ctx = NULL;
 
 	dbc_erst_free(dev, &dbc->erst);