linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] add xhci hooks for USB offload
@ 2021-01-19 10:10 Howard Yen
  2021-01-19 10:10 ` [PATCH 1/4] usb: host: " Howard Yen
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Howard Yen @ 2021-01-19 10:10 UTC (permalink / raw)
  To: gregkh, robh+dt, mathias.nyman
  Cc: linux-usb, devicetree, linux-kernel, Howard Yen

To let the xhci driver support USB offload, add hooks for vendor to have
customized behavior for the initialization, memory allocation, irq work, and 
device context synchronization. Detail is in each patch commit message.

Howard Yen (4):
  usb: host: add xhci hooks for USB offload
  usb: host: export symbols for xhci hooks usage
  usb: xhci-plat: add xhci_plat_priv_overwrite
  dt-bindings: usb: usb-xhci: add USB offload support

 .../devicetree/bindings/usb/usb-xhci.txt      |  1 +
 drivers/usb/host/xhci-hub.c                   |  5 +
 drivers/usb/host/xhci-mem.c                   | 99 ++++++++++++++++---
 drivers/usb/host/xhci-plat.c                  | 45 ++++++++-
 drivers/usb/host/xhci-plat.h                  |  9 ++
 drivers/usb/host/xhci-ring.c                  | 19 +++-
 drivers/usb/host/xhci.c                       | 89 +++++++++++++++++
 drivers/usb/host/xhci.h                       | 38 +++++++
 8 files changed, 289 insertions(+), 16 deletions(-)

-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/4] usb: host: add xhci hooks for USB offload
  2021-01-19 10:10 [PATCH 0/4] add xhci hooks for USB offload Howard Yen
@ 2021-01-19 10:10 ` Howard Yen
  2021-01-19 10:27   ` Greg KH
  2021-01-19 10:10 ` [PATCH 2/4] usb: host: export symbols for xhci hooks usage Howard Yen
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Howard Yen @ 2021-01-19 10:10 UTC (permalink / raw)
  To: gregkh, robh+dt, mathias.nyman
  Cc: linux-usb, devicetree, linux-kernel, Howard Yen

To enable supporting for USB offload, define "offload" in usb controller
node of device tree. "offload" value can be used to determine which type
of offload was been enabled in the SoC.

For example:

&usbdrd_dwc3 {
	...
	/* support usb offloading, 0: disabled, 1: audio */
	offload = <1>;
	...
};

There are several vendor_ops introduced by this patch:

struct xhci_vendor_ops - function callbacks for vendor specific operations
{
	@vendor_init:
		- called for vendor init process during xhci-plat-hcd
		  probe.
	@vendor_cleanup:
		- called for vendor cleanup process during xhci-plat-hcd
		  remove.
	@is_usb_offload_enabled:
		- called to check if usb offload enabled.
	@queue_irq_work:
		- called to queue vendor specific irq work.
	@alloc_dcbaa:
		- called when allocating vendor specific dcbaa during
		  memory initializtion.
	@free_dcbaa:
		- called to free vendor specific dcbaa when cleanup the
		  memory.
	@alloc_transfer_ring:
		- called when vendor specific transfer ring allocation is required
	@free_transfer_ring:
		- called to free vendor specific transfer ring
	@sync_dev_ctx:
		- called when synchronization for device context is required
}

The xhci hooks with prefix "xhci_vendor_" on the ops in xhci_vendor_ops.
For example, vendor_init ops will be invoked by xhci_vendor_init() hook,
is_usb_offload_enabled ops will be invoked by
xhci_vendor_is_usb_offload_enabled(), and so on.

Signed-off-by: Howard Yen <howardyen@google.com>
---
 drivers/usb/host/xhci-hub.c  |  5 ++
 drivers/usb/host/xhci-mem.c  | 96 +++++++++++++++++++++++++++++++-----
 drivers/usb/host/xhci-plat.c | 25 +++++++++-
 drivers/usb/host/xhci-plat.h |  2 +
 drivers/usb/host/xhci-ring.c | 13 +++++
 drivers/usb/host/xhci.c      | 89 +++++++++++++++++++++++++++++++++
 drivers/usb/host/xhci.h      | 38 ++++++++++++++
 7 files changed, 254 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index f37316d2c8fa..0eda5bb23ed8 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -448,8 +448,13 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
 	    cmd->status == COMP_COMMAND_RING_STOPPED) {
 		xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n");
 		ret = -ETIME;
+		goto cmd_cleanup;
 	}
 
+	ret = xhci_vendor_sync_dev_ctx(xhci, slot_id);
+	if (ret)
+		xhci_warn(xhci, "Sync device context failed, ret=%d\n", ret);
+
 cmd_cleanup:
 	xhci_free_command(xhci, cmd);
 	return ret;
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 9764122c9cdf..f3dbc5956290 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -352,6 +352,37 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
 	return 0;
 }
 
+static struct xhci_ring *xhci_vendor_alloc_transfer_ring(struct xhci_hcd *xhci,
+		u32 endpoint_type, enum xhci_ring_type ring_type,
+		gfp_t mem_flags)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->alloc_transfer_ring)
+		return ops->alloc_transfer_ring(xhci, endpoint_type, ring_type,
+						mem_flags);
+	return 0;
+}
+
+static void xhci_vendor_free_transfer_ring(struct xhci_hcd *xhci,
+		struct xhci_virt_device *virt_dev, unsigned int ep_index)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->free_transfer_ring)
+		ops->free_transfer_ring(xhci, virt_dev, ep_index);
+}
+
+static bool xhci_vendor_is_usb_offload_enabled(struct xhci_hcd *xhci,
+		struct xhci_virt_device *virt_dev, unsigned int ep_index)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->is_usb_offload_enabled)
+		return ops->is_usb_offload_enabled(xhci, virt_dev, ep_index);
+	return false;
+}
+
 /**
  * Create a new ring with zero or more segments.
  *
@@ -403,7 +434,11 @@ void xhci_free_endpoint_ring(struct xhci_hcd *xhci,
 		struct xhci_virt_device *virt_dev,
 		unsigned int ep_index)
 {
-	xhci_ring_free(xhci, virt_dev->eps[ep_index].ring);
+	if (xhci_vendor_is_usb_offload_enabled(xhci, virt_dev, ep_index))
+		xhci_vendor_free_transfer_ring(xhci, virt_dev, ep_index);
+	else
+		xhci_ring_free(xhci, virt_dev->eps[ep_index].ring);
+
 	virt_dev->eps[ep_index].ring = NULL;
 }
 
@@ -897,7 +932,7 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
 
 	for (i = 0; i < 31; i++) {
 		if (dev->eps[i].ring)
-			xhci_ring_free(xhci, dev->eps[i].ring);
+			xhci_free_endpoint_ring(xhci, dev, i);
 		if (dev->eps[i].stream_info)
 			xhci_free_stream_info(xhci,
 					dev->eps[i].stream_info);
@@ -1492,8 +1527,15 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
 		mult = 0;
 
 	/* Set up the endpoint ring */
-	virt_dev->eps[ep_index].new_ring =
-		xhci_ring_alloc(xhci, 2, 1, ring_type, max_packet, mem_flags);
+	if (xhci_vendor_is_usb_offload_enabled(xhci, virt_dev, ep_index) &&
+	    usb_endpoint_xfer_isoc(&ep->desc)) {
+		virt_dev->eps[ep_index].new_ring =
+			xhci_vendor_alloc_transfer_ring(xhci, endpoint_type, ring_type, mem_flags);
+	} else {
+		virt_dev->eps[ep_index].new_ring =
+			xhci_ring_alloc(xhci, 2, 1, ring_type, max_packet, mem_flags);
+	}
+
 	if (!virt_dev->eps[ep_index].new_ring)
 		return -ENOMEM;
 
@@ -1837,6 +1879,24 @@ void xhci_free_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
 	erst->entries = NULL;
 }
 
+static struct xhci_device_context_array *xhci_vendor_alloc_dcbaa(
+		struct xhci_hcd *xhci, gfp_t flags)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->alloc_dcbaa)
+		return ops->alloc_dcbaa(xhci, flags);
+	return 0;
+}
+
+static void xhci_vendor_free_dcbaa(struct xhci_hcd *xhci)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->free_dcbaa)
+		ops->free_dcbaa(xhci);
+}
+
 void xhci_mem_cleanup(struct xhci_hcd *xhci)
 {
 	struct device	*dev = xhci_to_hcd(xhci)->self.sysdev;
@@ -1891,9 +1951,13 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
 			"Freed medium stream array pool");
 
-	if (xhci->dcbaa)
-		dma_free_coherent(dev, sizeof(*xhci->dcbaa),
-				xhci->dcbaa, xhci->dcbaa->dma);
+	if (xhci_vendor_is_usb_offload_enabled(xhci, NULL, 0)) {
+		xhci_vendor_free_dcbaa(xhci);
+	} else {
+		if (xhci->dcbaa)
+			dma_free_coherent(dev, sizeof(*xhci->dcbaa),
+					xhci->dcbaa, xhci->dcbaa->dma);
+	}
 	xhci->dcbaa = NULL;
 
 	scratchpad_free(xhci);
@@ -2420,15 +2484,21 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	 * xHCI section 5.4.6 - doorbell array must be
 	 * "physically contiguous and 64-byte (cache line) aligned".
 	 */
-	xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma,
-			flags);
-	if (!xhci->dcbaa)
-		goto fail;
-	xhci->dcbaa->dma = dma;
+	if (xhci_vendor_is_usb_offload_enabled(xhci, NULL, 0)) {
+		xhci->dcbaa = xhci_vendor_alloc_dcbaa(xhci, flags);
+		if (!xhci->dcbaa)
+			goto fail;
+	} else {
+		xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma,
+				flags);
+		if (!xhci->dcbaa)
+			goto fail;
+		xhci->dcbaa->dma = dma;
+	}
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init,
 			"// Device context base array address = 0x%llx (DMA), %p (virt)",
 			(unsigned long long)xhci->dcbaa->dma, xhci->dcbaa);
-	xhci_write_64(xhci, dma, &xhci->op_regs->dcbaa_ptr);
+	xhci_write_64(xhci, xhci->dcbaa->dma, &xhci->op_regs->dcbaa_ptr);
 
 	/*
 	 * Initialize the ring segment pool.  The ring must be a contiguous
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index f6b4089bfc4a..5f8e69089654 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -163,6 +163,23 @@ static const struct of_device_id usb_xhci_of_match[] = {
 MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
 #endif
 
+static int xhci_vendor_init(struct xhci_hcd *xhci)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->vendor_init)
+		return ops->vendor_init(xhci);
+	return 0;
+}
+
+static void xhci_vendor_cleanup(struct xhci_hcd *xhci)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->vendor_cleanup)
+		ops->vendor_cleanup(xhci);
+}
+
 static int xhci_plat_probe(struct platform_device *pdev)
 {
 	const struct xhci_plat_priv *priv_match;
@@ -314,6 +331,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
 			goto put_usb3_hcd;
 	}
 
+	ret = xhci_vendor_init(xhci);
+	if (ret)
+		goto disable_usb_phy;
+
 	hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node);
 	xhci->shared_hcd->tpl_support = hcd->tpl_support;
 	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
@@ -380,8 +401,10 @@ static int xhci_plat_remove(struct platform_device *dev)
 	usb_phy_shutdown(hcd->usb_phy);
 
 	usb_remove_hcd(hcd);
-	usb_put_hcd(shared_hcd);
 
+	xhci_vendor_cleanup(xhci);
+
+	usb_put_hcd(shared_hcd);
 	clk_disable_unprepare(clk);
 	clk_disable_unprepare(reg_clk);
 	usb_put_hcd(hcd);
diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h
index b49f6447bd3a..2b2d090c4c01 100644
--- a/drivers/usb/host/xhci-plat.h
+++ b/drivers/usb/host/xhci-plat.h
@@ -13,6 +13,8 @@
 struct xhci_plat_priv {
 	const char *firmware_name;
 	unsigned long long quirks;
+	struct xhci_vendor_ops *vendor_ops;
+	struct xhci_vendor_data *vendor_data;
 	void (*plat_start)(struct usb_hcd *);
 	int (*init_quirk)(struct usb_hcd *);
 	int (*resume_quirk)(struct usb_hcd *);
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 2c255d0620b0..bfd653a1e5f6 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2823,6 +2823,15 @@ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
 	xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue);
 }
 
+static irqreturn_t xhci_vendor_queue_irq_work(struct xhci_hcd *xhci)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->queue_irq_work)
+		return ops->queue_irq_work(xhci);
+	return IRQ_NONE;
+}
+
 /*
  * xHCI spec says we can get an interrupt, and if the HC has an error condition,
  * we might get bad data out of the event ring.  Section 4.10.2.7 has a list of
@@ -2857,6 +2866,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
 		goto out;
 	}
 
+	ret = xhci_vendor_queue_irq_work(xhci);
+	if (ret == IRQ_HANDLED)
+		goto out;
+
 	/*
 	 * Clear the op reg interrupt status first,
 	 * so we can receive interrupts from other MSI-X interrupters.
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index bee5deccc83d..59e1b8813ca4 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -23,6 +23,7 @@
 #include "xhci-mtk.h"
 #include "xhci-debugfs.h"
 #include "xhci-dbgcap.h"
+#include "xhci-plat.h"
 
 #define DRIVER_AUTHOR "Sarah Sharp"
 #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
@@ -1482,6 +1483,11 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag
 		return -ENODEV;
 	}
 
+	if (xhci_vendor_usb_offload_skip_urb(xhci, urb)) {
+		xhci_dbg(xhci, "skip urb for usb offload\n");
+		return -EOPNOTSUPP;
+	}
+
 	if (usb_endpoint_xfer_isoc(&urb->ep->desc))
 		num_tds = urb->number_of_packets;
 	else if (usb_endpoint_is_bulk_out(&urb->ep->desc) &&
@@ -2832,6 +2838,14 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
 			xhci_finish_resource_reservation(xhci, ctrl_ctx);
 		spin_unlock_irqrestore(&xhci->lock, flags);
 	}
+	if (ret)
+		goto failed;
+
+	ret = xhci_vendor_sync_dev_ctx(xhci, udev->slot_id);
+	if (ret)
+		xhci_warn(xhci, "sync device context failed, ret=%d", ret);
+
+failed:
 	return ret;
 }
 
@@ -3212,6 +3226,13 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
 
 	wait_for_completion(stop_cmd->completion);
 
+	err = xhci_vendor_sync_dev_ctx(xhci, udev->slot_id);
+	if (err) {
+		xhci_warn(xhci, "%s: Failed to sync device context failed, err=%d",
+			  __func__, err);
+		goto cleanup;
+	}
+
 	spin_lock_irqsave(&xhci->lock, flags);
 
 	/* config ep command clears toggle if add and drop ep flags are set */
@@ -3235,6 +3256,11 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd,
 
 	wait_for_completion(cfg_cmd->completion);
 
+	err = xhci_vendor_sync_dev_ctx(xhci, udev->slot_id);
+	if (err)
+		xhci_warn(xhci, "%s: Failed to sync device context failed, err=%d",
+			  __func__, err);
+
 	ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE;
 	xhci_free_command(xhci, cfg_cmd);
 cleanup:
@@ -3773,6 +3799,13 @@ static int xhci_discover_or_reset_device(struct usb_hcd *hcd,
 	/* Wait for the Reset Device command to finish */
 	wait_for_completion(reset_device_cmd->completion);
 
+	ret = xhci_vendor_sync_dev_ctx(xhci, slot_id);
+	if (ret) {
+		xhci_warn(xhci, "%s: Failed to sync device context failed, err=%d",
+			  __func__, ret);
+		goto command_cleanup;
+	}
+
 	/* The Reset Device command can't fail, according to the 0.95/0.96 spec,
 	 * unless we tried to reset a slot ID that wasn't enabled,
 	 * or the device wasn't in the addressed or configured state.
@@ -4012,6 +4045,14 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
 		xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n");
 		goto disable_slot;
 	}
+
+	ret = xhci_vendor_sync_dev_ctx(xhci, slot_id);
+	if (ret) {
+		xhci_warn(xhci, "%s: Failed to sync device context failed, err=%d",
+			  __func__, ret);
+		goto disable_slot;
+	}
+
 	vdev = xhci->devs[slot_id];
 	slot_ctx = xhci_get_slot_ctx(xhci, vdev->out_ctx);
 	trace_xhci_alloc_dev(slot_ctx);
@@ -4145,6 +4186,13 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
 	/* ctrl tx can take up to 5 sec; XXX: need more time for xHC? */
 	wait_for_completion(command->completion);
 
+	ret = xhci_vendor_sync_dev_ctx(xhci, udev->slot_id);
+	if (ret) {
+		xhci_warn(xhci, "%s: Failed to sync device context failed, err=%d",
+			  __func__, ret);
+		goto out;
+	}
+
 	/* FIXME: From section 4.3.4: "Software shall be responsible for timing
 	 * the SetAddress() "recovery interval" required by USB and aborting the
 	 * command on a timeout.
@@ -4291,6 +4339,14 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci,
 		return -ENOMEM;
 	}
 
+	ret = xhci_vendor_sync_dev_ctx(xhci, udev->slot_id);
+	if (ret) {
+		spin_unlock_irqrestore(&xhci->lock, flags);
+		xhci_warn(xhci, "%s: Failed to sync device context failed, err=%d",
+			  __func__, ret);
+		return ret;
+	}
+
 	xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx);
 	spin_unlock_irqrestore(&xhci->lock, flags);
 
@@ -4315,6 +4371,30 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci,
 	return ret;
 }
 
+struct xhci_vendor_ops *xhci_vendor_get_ops(struct xhci_hcd *xhci)
+{
+	return xhci_to_priv(xhci)->vendor_ops;
+}
+EXPORT_SYMBOL_GPL(xhci_vendor_get_ops);
+
+int xhci_vendor_sync_dev_ctx(struct xhci_hcd *xhci, unsigned int slot_id)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->sync_dev_ctx)
+		return ops->sync_dev_ctx(xhci, slot_id);
+	return 0;
+}
+
+bool xhci_vendor_usb_offload_skip_urb(struct xhci_hcd *xhci, struct urb *urb)
+{
+	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+
+	if (ops && ops->usb_offload_skip_urb)
+		return ops->usb_offload_skip_urb(xhci, urb);
+	return false;
+}
+
 #ifdef CONFIG_PM
 
 /* BESL to HIRD Encoding array for USB2 LPM */
@@ -5048,6 +5128,15 @@ static int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
 		return -ENOMEM;
 	}
 
+	ret = xhci_vendor_sync_dev_ctx(xhci, hdev->slot_id);
+	if (ret) {
+		xhci_warn(xhci, "%s: Failed to sync device context failed, err=%d",
+			  __func__, ret);
+		xhci_free_command(xhci, config_cmd);
+		spin_unlock_irqrestore(&xhci->lock, flags);
+		return ret;
+	}
+
 	xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx);
 	ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
 	slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 2c6c4f8d1ee1..4b110590561b 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2177,6 +2177,44 @@ static inline struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
 					urb->stream_id);
 }
 
+/**
+ * struct xhci_vendor_ops - function callbacks for vendor specific operations
+ * @vendor_init: called for vendor init process
+ * @vendor_cleanup: called for vendor cleanup process
+ * @is_usb_offload_enabled: called to check if usb offload enabled
+ * @queue_irq_work: called to queue vendor specific irq work
+ * @alloc_dcbaa: called when allocating vendor specific dcbaa
+ * @free_dcbaa: called to free vendor specific dcbaa
+ * @alloc_transfer_ring: called when remote transfer ring allocation is required
+ * @free_transfer_ring: called to free vendor specific transfer ring
+ * @sync_dev_ctx: called when synchronization for device context is required
+ */
+struct xhci_vendor_ops {
+	int (*vendor_init)(struct xhci_hcd *xhci);
+	void (*vendor_cleanup)(struct xhci_hcd *xhci);
+	bool (*is_usb_offload_enabled)(struct xhci_hcd *xhci,
+				       struct xhci_virt_device *vdev,
+				       unsigned int ep_index);
+	irqreturn_t (*queue_irq_work)(struct xhci_hcd *xhci);
+
+	struct xhci_device_context_array *(*alloc_dcbaa)(struct xhci_hcd *xhci,
+							 gfp_t flags);
+	void (*free_dcbaa)(struct xhci_hcd *xhci);
+
+	struct xhci_ring *(*alloc_transfer_ring)(struct xhci_hcd *xhci,
+			u32 endpoint_type, enum xhci_ring_type ring_type,
+			gfp_t mem_flags);
+	void (*free_transfer_ring)(struct xhci_hcd *xhci,
+			struct xhci_virt_device *virt_dev, unsigned int ep_index);
+	int (*sync_dev_ctx)(struct xhci_hcd *xhci, unsigned int slot_id);
+	bool (*usb_offload_skip_urb)(struct xhci_hcd *xhci, struct urb *urb);
+};
+
+struct xhci_vendor_ops *xhci_vendor_get_ops(struct xhci_hcd *xhci);
+
+int xhci_vendor_sync_dev_ctx(struct xhci_hcd *xhci, unsigned int slot_id);
+bool xhci_vendor_usb_offload_skip_urb(struct xhci_hcd *xhci, struct urb *urb);
+
 /*
  * TODO: As per spec Isochronous IDT transmissions are supported. We bypass
  * them anyways as we where unable to find a device that matches the
-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/4] usb: host: export symbols for xhci hooks usage
  2021-01-19 10:10 [PATCH 0/4] add xhci hooks for USB offload Howard Yen
  2021-01-19 10:10 ` [PATCH 1/4] usb: host: " Howard Yen
@ 2021-01-19 10:10 ` Howard Yen
  2021-01-19 10:10 ` [PATCH 3/4] usb: xhci-plat: add xhci_plat_priv_overwrite Howard Yen
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Howard Yen @ 2021-01-19 10:10 UTC (permalink / raw)
  To: gregkh, robh+dt, mathias.nyman
  Cc: linux-usb, devicetree, linux-kernel, Howard Yen

Export symbols for xhci hooks usage:
    xhci_ring_free
        - Allow xhci hook to free xhci_ring.
    xhci_get_slot_ctx
        - Allow xhci hook to get slot_ctx from the xhci_container_ctx
	  for getting the slot_ctx information to know which slot is
	  offloading and compare the context in remote subsystem memory
	  if needed.
    xhci_get_ep_ctx
        - Allow xhci hook to get ep_ctx from the xhci_container_ctx for
	  getting the ep_ctx information to know which ep is offloading and
	  comparing the context in remote subsystem memory if needed.
    xhci_handle_event
        - Allow xhci hook to handle the xhci events from the USB
	  controller.
    xhci_update_erst_dequeue
        - If xhci events was handle by xhci hook, it needs to update
	  the erst dequeue pointer to let the USB controller know the
	  events was handled.

Signed-off-by: Howard Yen <howardyen@google.com>
---
 drivers/usb/host/xhci-mem.c  | 3 +++
 drivers/usb/host/xhci-ring.c | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index f3dbc5956290..69f19774b914 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -289,6 +289,7 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
 
 	kfree(ring);
 }
+EXPORT_SYMBOL_GPL(xhci_ring_free);
 
 static void xhci_initialize_ring_info(struct xhci_ring *ring,
 					unsigned int cycle_state)
@@ -545,6 +546,7 @@ struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci,
 	return (struct xhci_slot_ctx *)
 		(ctx->bytes + CTX_SIZE(xhci->hcc_params));
 }
+EXPORT_SYMBOL_GPL(xhci_get_slot_ctx);
 
 struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
 				    struct xhci_container_ctx *ctx,
@@ -558,6 +560,7 @@ struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
 	return (struct xhci_ep_ctx *)
 		(ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params)));
 }
+EXPORT_SYMBOL_GPL(xhci_get_ep_ctx);
 
 
 /***************** Streams structures manipulation *************************/
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index bfd653a1e5f6..f3b387e2fcb3 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2717,7 +2717,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
  * Returns >0 for "possibly more events to process" (caller should call again),
  * otherwise 0 if done.  In future, <0 returns should indicate error code.
  */
-static int xhci_handle_event(struct xhci_hcd *xhci)
+int xhci_handle_event(struct xhci_hcd *xhci)
 {
 	union xhci_trb *event;
 	int update_ptrs = 1;
@@ -2786,13 +2786,14 @@ static int xhci_handle_event(struct xhci_hcd *xhci)
 	 */
 	return 1;
 }
+EXPORT_SYMBOL_GPL(xhci_handle_event);
 
 /*
  * Update Event Ring Dequeue Pointer:
  * - When all events have finished
  * - To avoid "Event Ring Full Error" condition
  */
-static void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
+void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
 		union xhci_trb *event_ring_deq)
 {
 	u64 temp_64;
@@ -2822,6 +2823,7 @@ static void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
 	temp_64 |= ERST_EHB;
 	xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue);
 }
+EXPORT_SYMBOL_GPL(xhci_update_erst_dequeue);
 
 static irqreturn_t xhci_vendor_queue_irq_work(struct xhci_hcd *xhci)
 {
-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/4] usb: xhci-plat: add xhci_plat_priv_overwrite
  2021-01-19 10:10 [PATCH 0/4] add xhci hooks for USB offload Howard Yen
  2021-01-19 10:10 ` [PATCH 1/4] usb: host: " Howard Yen
  2021-01-19 10:10 ` [PATCH 2/4] usb: host: export symbols for xhci hooks usage Howard Yen
@ 2021-01-19 10:10 ` Howard Yen
  2021-01-19 10:10 ` [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support Howard Yen
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Howard Yen @ 2021-01-19 10:10 UTC (permalink / raw)
  To: gregkh, robh+dt, mathias.nyman
  Cc: linux-usb, devicetree, linux-kernel, Howard Yen

Add an overwrite to platform specific callback for setting up the
xhci_vendor_ops, allow vendor to store the xhci_vendor_ops and
overwrite them when xhci_plat_probe invoked.

This change is depend on Commit in this patch series
("usb: host: add xhci hooks for USB offload"), vendor needs
to invoke xhci_plat_register_vendor_ops() to register the vendor specific
vendor_ops. And the vendor_ops will overwrite the vendor_ops inside
xhci_plat_priv in xhci_vendor_init() during xhci-plat-hcd probe.

Signed-off-by: Howard Yen <howardyen@google.com>
---
 drivers/usb/host/xhci-plat.c | 20 ++++++++++++++++++++
 drivers/usb/host/xhci-plat.h |  7 +++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 5f8e69089654..a8e217494831 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -163,9 +163,26 @@ static const struct of_device_id usb_xhci_of_match[] = {
 MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
 #endif
 
+static struct xhci_plat_priv_overwrite xhci_plat_vendor_overwrite;
+
+int xhci_plat_register_vendor_ops(struct xhci_vendor_ops *vendor_ops)
+{
+	if (vendor_ops == NULL)
+		return -EINVAL;
+
+	xhci_plat_vendor_overwrite.vendor_ops = vendor_ops;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(xhci_plat_register_vendor_ops);
+
 static int xhci_vendor_init(struct xhci_hcd *xhci)
 {
 	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+	struct xhci_plat_priv *priv = xhci_to_priv(xhci);
+
+	if (xhci_plat_vendor_overwrite.vendor_ops)
+		ops = priv->vendor_ops = xhci_plat_vendor_overwrite.vendor_ops;
 
 	if (ops && ops->vendor_init)
 		return ops->vendor_init(xhci);
@@ -175,9 +192,12 @@ static int xhci_vendor_init(struct xhci_hcd *xhci)
 static void xhci_vendor_cleanup(struct xhci_hcd *xhci)
 {
 	struct xhci_vendor_ops *ops = xhci_vendor_get_ops(xhci);
+	struct xhci_plat_priv *priv = xhci_to_priv(xhci);
 
 	if (ops && ops->vendor_cleanup)
 		ops->vendor_cleanup(xhci);
+
+	priv->vendor_ops = NULL;
 }
 
 static int xhci_plat_probe(struct platform_device *pdev)
diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h
index 2b2d090c4c01..d85802725208 100644
--- a/drivers/usb/host/xhci-plat.h
+++ b/drivers/usb/host/xhci-plat.h
@@ -22,4 +22,11 @@ struct xhci_plat_priv {
 
 #define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv)
 #define xhci_to_priv(x) ((struct xhci_plat_priv *)(x)->priv)
+
+struct xhci_plat_priv_overwrite {
+	struct xhci_vendor_ops *vendor_ops;
+};
+
+int xhci_plat_register_vendor_ops(struct xhci_vendor_ops *vendor_ops);
+
 #endif	/* _XHCI_PLAT_H */
-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support
  2021-01-19 10:10 [PATCH 0/4] add xhci hooks for USB offload Howard Yen
                   ` (2 preceding siblings ...)
  2021-01-19 10:10 ` [PATCH 3/4] usb: xhci-plat: add xhci_plat_priv_overwrite Howard Yen
@ 2021-01-19 10:10 ` Howard Yen
  2021-01-19 10:22   ` Greg KH
  2021-02-09  2:30   ` Rob Herring
  2021-01-19 10:25 ` [PATCH 0/4] add xhci hooks for USB offload Greg KH
  2021-01-19 12:49 ` Mathias Nyman
  5 siblings, 2 replies; 16+ messages in thread
From: Howard Yen @ 2021-01-19 10:10 UTC (permalink / raw)
  To: gregkh, robh+dt, mathias.nyman
  Cc: linux-usb, devicetree, linux-kernel, Howard Yen

Document USB offload support for usb-xhci.

For example:

&usbdrd_dwc3 {
	...
	/* support usb offloading, 0: disabled, 1: audio */
	offload = <1>;
	...
};

Signed-off-by: Howard Yen <howardyen@google.com>
---
 Documentation/devicetree/bindings/usb/usb-xhci.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
index b120dd6612a2..aab1fd499f15 100644
--- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
@@ -46,6 +46,7 @@ Optional properties:
   - quirk-broken-port-ped: set if the controller has broken port disable mechanism
   - imod-interval-ns: default interrupt moderation interval is 5000ns
   - phys : see usb-hcd.yaml in the current directory
+  - offload: supporting USB offload feature, 0: disabled, 1: audio
 
 additionally the properties from usb-hcd.yaml (in the current directory) are
 supported.
-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support
  2021-01-19 10:10 ` [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support Howard Yen
@ 2021-01-19 10:22   ` Greg KH
  2021-02-09  2:30   ` Rob Herring
  1 sibling, 0 replies; 16+ messages in thread
From: Greg KH @ 2021-01-19 10:22 UTC (permalink / raw)
  To: Howard Yen; +Cc: robh+dt, mathias.nyman, linux-usb, devicetree, linux-kernel

On Tue, Jan 19, 2021 at 06:10:44PM +0800, Howard Yen wrote:
> Document USB offload support for usb-xhci.
> 
> For example:
> 
> &usbdrd_dwc3 {
> 	...
> 	/* support usb offloading, 0: disabled, 1: audio */
> 	offload = <1>;
> 	...
> };
> 
> Signed-off-by: Howard Yen <howardyen@google.com>
> ---
>  Documentation/devicetree/bindings/usb/usb-xhci.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> index b120dd6612a2..aab1fd499f15 100644
> --- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> @@ -46,6 +46,7 @@ Optional properties:
>    - quirk-broken-port-ped: set if the controller has broken port disable mechanism
>    - imod-interval-ns: default interrupt moderation interval is 5000ns
>    - phys : see usb-hcd.yaml in the current directory
> +  - offload: supporting USB offload feature, 0: disabled, 1: audio

Why does the "type" of offload matter, shouldn't it just be:
	0: disabled, 1: enabled
?

And in thinking about it some more, why does this need to be a binding
at all, shouldn't this just be an issue if the platform-specific ops are
available or not, meaning no DT change should be needed at all?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-19 10:10 [PATCH 0/4] add xhci hooks for USB offload Howard Yen
                   ` (3 preceding siblings ...)
  2021-01-19 10:10 ` [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support Howard Yen
@ 2021-01-19 10:25 ` Greg KH
  2021-01-19 12:49 ` Mathias Nyman
  5 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2021-01-19 10:25 UTC (permalink / raw)
  To: Howard Yen; +Cc: robh+dt, mathias.nyman, linux-usb, devicetree, linux-kernel

On Tue, Jan 19, 2021 at 06:10:40PM +0800, Howard Yen wrote:
> To let the xhci driver support USB offload, add hooks for vendor to have
> customized behavior for the initialization, memory allocation, irq work, and 
> device context synchronization. Detail is in each patch commit message.
> 
> Howard Yen (4):
>   usb: host: add xhci hooks for USB offload
>   usb: host: export symbols for xhci hooks usage
>   usb: xhci-plat: add xhci_plat_priv_overwrite
>   dt-bindings: usb: usb-xhci: add USB offload support
> 
>  .../devicetree/bindings/usb/usb-xhci.txt      |  1 +
>  drivers/usb/host/xhci-hub.c                   |  5 +
>  drivers/usb/host/xhci-mem.c                   | 99 ++++++++++++++++---
>  drivers/usb/host/xhci-plat.c                  | 45 ++++++++-
>  drivers/usb/host/xhci-plat.h                  |  9 ++
>  drivers/usb/host/xhci-ring.c                  | 19 +++-
>  drivers/usb/host/xhci.c                       | 89 +++++++++++++++++
>  drivers/usb/host/xhci.h                       | 38 +++++++
>  8 files changed, 289 insertions(+), 16 deletions(-)

Thanks so much for posting this.

A bit of background for the lists.  I helped review previous versions of
this patchset from Howard as he worked to convert the hacks from a
previous vendor into something that would be semi-sane.  It would be
great if we can take the previously-submitted Samsung usb-audio hooks
(as published in their kernel sources for their last-year phones) and
get it into something mergable with this scheme as well, as this is the
"correct" way to do what they were wanting to do.

Although I know that is outside of the work you probably have time for,
maybe I will work on that over the next few weeks...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] usb: host: add xhci hooks for USB offload
  2021-01-19 10:10 ` [PATCH 1/4] usb: host: " Howard Yen
@ 2021-01-19 10:27   ` Greg KH
  0 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2021-01-19 10:27 UTC (permalink / raw)
  To: Howard Yen; +Cc: robh+dt, mathias.nyman, linux-usb, devicetree, linux-kernel

On Tue, Jan 19, 2021 at 06:10:41PM +0800, Howard Yen wrote:
> To enable supporting for USB offload, define "offload" in usb controller
> node of device tree. "offload" value can be used to determine which type
> of offload was been enabled in the SoC.
> 
> For example:
> 
> &usbdrd_dwc3 {
> 	...
> 	/* support usb offloading, 0: disabled, 1: audio */
> 	offload = <1>;
> 	...
> };

This patch doesn't require this change, right?  That's only necessary
for your DT change later on, from what I can tell, so maybe it's not
needed to list this here, as the xhci core changes do not seem to
require dt at all.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-19 10:10 [PATCH 0/4] add xhci hooks for USB offload Howard Yen
                   ` (4 preceding siblings ...)
  2021-01-19 10:25 ` [PATCH 0/4] add xhci hooks for USB offload Greg KH
@ 2021-01-19 12:49 ` Mathias Nyman
  2021-01-20 10:04   ` Howard Yen
  5 siblings, 1 reply; 16+ messages in thread
From: Mathias Nyman @ 2021-01-19 12:49 UTC (permalink / raw)
  To: Howard Yen, gregkh, robh+dt; +Cc: linux-usb, devicetree, linux-kernel

On 19.1.2021 12.10, Howard Yen wrote:
> To let the xhci driver support USB offload, add hooks for vendor to have
> customized behavior for the initialization, memory allocation, irq work, and 
> device context synchronization. Detail is in each patch commit message.

Is this related to the usb audio sideband capability that was added to the xHCI specification?
If yes, then we should probably implement the generic parts first, and then add
the vendor specific hooks.

-Mathias
 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-19 12:49 ` Mathias Nyman
@ 2021-01-20 10:04   ` Howard Yen
  2021-01-22 15:32     ` Mathias Nyman
  0 siblings, 1 reply; 16+ messages in thread
From: Howard Yen @ 2021-01-20 10:04 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: gregkh, robh+dt, linux-usb, devicetree, linux-kernel

On Tue, Jan 19, 2021 at 8:47 PM Mathias Nyman <mathias.nyman@intel.com> wrote:
>
> On 19.1.2021 12.10, Howard Yen wrote:
> > To let the xhci driver support USB offload, add hooks for vendor to have
> > customized behavior for the initialization, memory allocation, irq work, and
> > device context synchronization. Detail is in each patch commit message.
>
> Is this related to the usb audio sideband capability that was added to the xHCI specification?
> If yes, then we should probably implement the generic parts first, and then add
> the vendor specific hooks.
>
> -Mathias
>
>

This is for offloading, no matter what type of offloading.
I made the hooks generically and can be used for usb audio on the xhci
which is not including the usb audio sideband capability.


- Howard

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-20 10:04   ` Howard Yen
@ 2021-01-22 15:32     ` Mathias Nyman
  2021-01-26 14:19       ` Greg KH
  0 siblings, 1 reply; 16+ messages in thread
From: Mathias Nyman @ 2021-01-22 15:32 UTC (permalink / raw)
  To: Howard Yen, Mathias Nyman
  Cc: gregkh, robh+dt, linux-usb, devicetree, linux-kernel

On 20.1.2021 12.04, Howard Yen wrote:
> On Tue, Jan 19, 2021 at 8:47 PM Mathias Nyman <mathias.nyman@intel.com> wrote:
>>
>> On 19.1.2021 12.10, Howard Yen wrote:
>>> To let the xhci driver support USB offload, add hooks for vendor to have
>>> customized behavior for the initialization, memory allocation, irq work, and
>>> device context synchronization. Detail is in each patch commit message.
>>
>> Is this related to the usb audio sideband capability that was added to the xHCI specification?
>> If yes, then we should probably implement the generic parts first, and then add
>> the vendor specific hooks.
>>
>> -Mathias
>>
>>
> 
> This is for offloading, no matter what type of offloading.
> I made the hooks generically and can be used for usb audio on the xhci
> which is not including the usb audio sideband capability.
> 

Ok, before adding hooks like this I think we need to see how they are used.
Do you have the rest of the patches that go on top of this series?

Maybe it could make sense to use overrides for the functions in struct hc_driver
instead in some cases? There is support for that already.

Thanks
-Mathias  


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-22 15:32     ` Mathias Nyman
@ 2021-01-26 14:19       ` Greg KH
  2021-01-28  3:38         ` Howard Yen
  0 siblings, 1 reply; 16+ messages in thread
From: Greg KH @ 2021-01-26 14:19 UTC (permalink / raw)
  To: Mathias Nyman
  Cc: Howard Yen, Mathias Nyman, robh+dt, linux-usb, devicetree, linux-kernel

On Fri, Jan 22, 2021 at 05:32:58PM +0200, Mathias Nyman wrote:
> On 20.1.2021 12.04, Howard Yen wrote:
> > On Tue, Jan 19, 2021 at 8:47 PM Mathias Nyman <mathias.nyman@intel.com> wrote:
> >>
> >> On 19.1.2021 12.10, Howard Yen wrote:
> >>> To let the xhci driver support USB offload, add hooks for vendor to have
> >>> customized behavior for the initialization, memory allocation, irq work, and
> >>> device context synchronization. Detail is in each patch commit message.
> >>
> >> Is this related to the usb audio sideband capability that was added to the xHCI specification?
> >> If yes, then we should probably implement the generic parts first, and then add
> >> the vendor specific hooks.
> >>
> >> -Mathias
> >>
> >>
> > 
> > This is for offloading, no matter what type of offloading.
> > I made the hooks generically and can be used for usb audio on the xhci
> > which is not including the usb audio sideband capability.
> > 
> 
> Ok, before adding hooks like this I think we need to see how they are used.
> Do you have the rest of the patches that go on top of this series?
> 
> Maybe it could make sense to use overrides for the functions in struct hc_driver
> instead in some cases? There is support for that already.

What overrides could be done for these changes?  At first glance that
would seem to require a lot of duplicated code in whatever override
happens to be needed.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-26 14:19       ` Greg KH
@ 2021-01-28  3:38         ` Howard Yen
  2021-01-28  6:31           ` Mathias Nyman
  0 siblings, 1 reply; 16+ messages in thread
From: Howard Yen @ 2021-01-28  3:38 UTC (permalink / raw)
  To: Greg KH
  Cc: Mathias Nyman, Mathias Nyman, robh+dt, linux-usb, devicetree,
	linux-kernel

On Tue, Jan 26, 2021 at 10:19 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Fri, Jan 22, 2021 at 05:32:58PM +0200, Mathias Nyman wrote:
> > On 20.1.2021 12.04, Howard Yen wrote:
> > > On Tue, Jan 19, 2021 at 8:47 PM Mathias Nyman <mathias.nyman@intel.com> wrote:
> > >>
> > >> On 19.1.2021 12.10, Howard Yen wrote:
> > >>> To let the xhci driver support USB offload, add hooks for vendor to have
> > >>> customized behavior for the initialization, memory allocation, irq work, and
> > >>> device context synchronization. Detail is in each patch commit message.
> > >>
> > >> Is this related to the usb audio sideband capability that was added to the xHCI specification?
> > >> If yes, then we should probably implement the generic parts first, and then add
> > >> the vendor specific hooks.
> > >>
> > >> -Mathias
> > >>
> > >>
> > >
> > > This is for offloading, no matter what type of offloading.
> > > I made the hooks generically and can be used for usb audio on the xhci
> > > which is not including the usb audio sideband capability.
> > >
> >
> > Ok, before adding hooks like this I think we need to see how they are used.
> > Do you have the rest of the patches that go on top of this series?
> >
> > Maybe it could make sense to use overrides for the functions in struct hc_driver
> > instead in some cases? There is support for that already.
>
> What overrides could be done for these changes?  At first glance that
> would seem to require a lot of duplicated code in whatever override
> happens to be needed.
>
> thanks,
>
> greg k-h

This patch series is all the changes for the offload hooks currently.

I thought about this, but if I tried to override the functions in
struct hc_driver, that'll need to
copy many code to the override function, and it won't follow the
latest change in the core
xhci driver.


- Howard

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-28  3:38         ` Howard Yen
@ 2021-01-28  6:31           ` Mathias Nyman
  2021-01-28  7:41             ` Greg KH
  0 siblings, 1 reply; 16+ messages in thread
From: Mathias Nyman @ 2021-01-28  6:31 UTC (permalink / raw)
  To: Howard Yen, Greg KH
  Cc: Mathias Nyman, robh+dt, linux-usb, devicetree, linux-kernel

On 28.1.2021 5.38, Howard Yen wrote:
> On Tue, Jan 26, 2021 at 10:19 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>>
>> On Fri, Jan 22, 2021 at 05:32:58PM +0200, Mathias Nyman wrote:
>>>
>>> Ok, before adding hooks like this I think we need to see how they are used.
>>> Do you have the rest of the patches that go on top of this series?
>>>
>>> Maybe it could make sense to use overrides for the functions in struct hc_driver
>>> instead in some cases? There is support for that already.
>>
>> What overrides could be done for these changes?  At first glance that
>> would seem to require a lot of duplicated code in whatever override
>> happens to be needed.
>>
>> thanks,
>>
>> greg k-h
> 
> This patch series is all the changes for the offload hooks currently.
> 
> I thought about this, but if I tried to override the functions in
> struct hc_driver, that'll need to
> copy many code to the override function, and it won't follow the
> latest change in the core
> xhci driver.
> 
> 
> - Howard

Ok, I see. 

The point I'm trying to make is that there is no way for me to know if
these hooks are the right solution before I see any code using them.

Is the offloading code ready and public somewhere?

Thanks
-Mathias 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 0/4] add xhci hooks for USB offload
  2021-01-28  6:31           ` Mathias Nyman
@ 2021-01-28  7:41             ` Greg KH
  0 siblings, 0 replies; 16+ messages in thread
From: Greg KH @ 2021-01-28  7:41 UTC (permalink / raw)
  To: Mathias Nyman
  Cc: Howard Yen, Mathias Nyman, robh+dt, linux-usb, devicetree, linux-kernel

On Thu, Jan 28, 2021 at 08:31:14AM +0200, Mathias Nyman wrote:
> On 28.1.2021 5.38, Howard Yen wrote:
> > On Tue, Jan 26, 2021 at 10:19 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> >>
> >> On Fri, Jan 22, 2021 at 05:32:58PM +0200, Mathias Nyman wrote:
> >>>
> >>> Ok, before adding hooks like this I think we need to see how they are used.
> >>> Do you have the rest of the patches that go on top of this series?
> >>>
> >>> Maybe it could make sense to use overrides for the functions in struct hc_driver
> >>> instead in some cases? There is support for that already.
> >>
> >> What overrides could be done for these changes?  At first glance that
> >> would seem to require a lot of duplicated code in whatever override
> >> happens to be needed.
> >>
> >> thanks,
> >>
> >> greg k-h
> > 
> > This patch series is all the changes for the offload hooks currently.
> > 
> > I thought about this, but if I tried to override the functions in
> > struct hc_driver, that'll need to
> > copy many code to the override function, and it won't follow the
> > latest change in the core
> > xhci driver.
> > 
> > 
> > - Howard
> 
> Ok, I see. 
> 
> The point I'm trying to make is that there is no way for me to know if
> these hooks are the right solution before I see any code using them.
> 
> Is the offloading code ready and public somewhere?

There is offload code published in the last few Samsung phone kernels, I
want to get that ported to these hooks to see if that works properly.

Give me a few days and I'll see if I can get it working, I had a
half-finished port around here somewhere...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support
  2021-01-19 10:10 ` [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support Howard Yen
  2021-01-19 10:22   ` Greg KH
@ 2021-02-09  2:30   ` Rob Herring
  1 sibling, 0 replies; 16+ messages in thread
From: Rob Herring @ 2021-02-09  2:30 UTC (permalink / raw)
  To: Howard Yen; +Cc: gregkh, mathias.nyman, linux-usb, devicetree, linux-kernel

On Tue, Jan 19, 2021 at 06:10:44PM +0800, Howard Yen wrote:
> Document USB offload support for usb-xhci.

Is this a standard XHCI capability or specific to certain 
implementations? Do all versions of DWC3 support it?

> 
> For example:
> 
> &usbdrd_dwc3 {
> 	...
> 	/* support usb offloading, 0: disabled, 1: audio */
> 	offload = <1>;
> 	...
> };
> 
> Signed-off-by: Howard Yen <howardyen@google.com>
> ---
>  Documentation/devicetree/bindings/usb/usb-xhci.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> index b120dd6612a2..aab1fd499f15 100644
> --- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> @@ -46,6 +46,7 @@ Optional properties:
>    - quirk-broken-port-ped: set if the controller has broken port disable mechanism
>    - imod-interval-ns: default interrupt moderation interval is 5000ns
>    - phys : see usb-hcd.yaml in the current directory
> +  - offload: supporting USB offload feature, 0: disabled, 1: audio

What does not present mean? Unless you need 'keep the h/w default', then 
this can be boolean instead.

>  
>  additionally the properties from usb-hcd.yaml (in the current directory) are
>  supported.
> -- 
> 2.30.0.284.gd98b1dd5eaa7-goog
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-02-09  2:31 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-19 10:10 [PATCH 0/4] add xhci hooks for USB offload Howard Yen
2021-01-19 10:10 ` [PATCH 1/4] usb: host: " Howard Yen
2021-01-19 10:27   ` Greg KH
2021-01-19 10:10 ` [PATCH 2/4] usb: host: export symbols for xhci hooks usage Howard Yen
2021-01-19 10:10 ` [PATCH 3/4] usb: xhci-plat: add xhci_plat_priv_overwrite Howard Yen
2021-01-19 10:10 ` [PATCH 4/4] dt-bindings: usb: usb-xhci: add USB offload support Howard Yen
2021-01-19 10:22   ` Greg KH
2021-02-09  2:30   ` Rob Herring
2021-01-19 10:25 ` [PATCH 0/4] add xhci hooks for USB offload Greg KH
2021-01-19 12:49 ` Mathias Nyman
2021-01-20 10:04   ` Howard Yen
2021-01-22 15:32     ` Mathias Nyman
2021-01-26 14:19       ` Greg KH
2021-01-28  3:38         ` Howard Yen
2021-01-28  6:31           ` Mathias Nyman
2021-01-28  7:41             ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).