All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/27] xhci features for usb-next
@ 2020-07-23 14:45 Mathias Nyman
  2020-07-23 14:45 ` [PATCH 01/27] xhci: Make debug message consistent with bus and port number Mathias Nyman
                   ` (27 more replies)
  0 siblings, 28 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Hi Greg

This series for usb-next is almost completely about decoupling and
cleaning up relations between xhci, xhci debug capability (DbC),
and the DbC tty support.

Real motivation behind this is to later turn DbC into a proper device
allowing us to bind different drivers to it, like dbctty.

Thanks
-Mathias

Kai-Heng Feng (1):
  xhci: Make debug message consistent with bus and port number

Mathias Nyman (26):
  xhci: dbc: Don't use generic xhci inc_deq() function for dbc
  xhci: Don't pass struct xhci_hcd pointer to xhci_link_seg()
  xhci: dbc: Don't use generic xhci erst allocation and free functions
  xhci: dbc: Remove dbc_dma_alloc_coherent() wrapper
  xhci: dbc: Remove dbc_dma_free_coherent() wrapper
  xhci: dbc: Add device pointer to dbc structure
  xhci: dbc: Use dev_info() and similar instead of xhci_info()
  xhci: dbc: Don't use xhci_write_64() as it takes xhci as a parameter
  xhci: dbc: Don't pass the xhci pointer as a parameter to
    xhci_dbc_init_context()
  xhci: dbc: Get the device pointer from dbc structure in
    dbc_ep_do_queue()
  xhci: dbc: Pass dbc pointer to endpoint init and exit functions.
  xhci: dbc: Change to pass dbc pointer to xhci_do_dbc_stop()
  xhci: dbc: Pass dbc pointer to dbc_handle_xfer_event() instead of
    xhci_hcd pointer
  xhci: dbgtty: Pass dbc pointer when registering a dbctty device
  xhci: dbc: Pass dbc pointer to get_in/out_ep() helper functions to get
    endpoints
  xhci: dbc: Use dbc structure in the request completion instead of
    xhci_hcd
  xhci: dbc: Don't use generic xhci context allocation for dbc
  xhci: dbc: don't use generic xhci ring allocation functions for dbc.
  xhci: dbc: Pass dbc pointer to dbc memory init and cleanup functions
  xhci: dbc: Pass dbc pointer to dbc start and stop functions.
  xhci: dbc: simplify dbc requests allocation and queueing
  xhci: dbc: remove endpoint pointers from dbc_port structure
  xhci: dbctty: split dbc tty driver registration and unregistration
    functions.
  xhci: dbc: Add a operations structure to access driver functions
  xhci: dbgcap: remove dbc dependency on dbctty specific flag
  xhci: dbc: remove tty specific port structure from struct xhci_dbc

 drivers/usb/host/xhci-dbgcap.c | 391 +++++++++++++++++++++------------
 drivers/usb/host/xhci-dbgcap.h |  69 +++---
 drivers/usb/host/xhci-dbgtty.c | 219 +++++++++++-------
 drivers/usb/host/xhci-hub.c    |  41 ++--
 drivers/usb/host/xhci-mem.c    |  35 +--
 drivers/usb/host/xhci.h        |   2 +
 6 files changed, 462 insertions(+), 295 deletions(-)

-- 
2.17.1


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

* [PATCH 01/27] xhci: Make debug message consistent with bus and port number
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 02/27] xhci: dbc: Don't use generic xhci inc_deq() function for dbc Mathias Nyman
                   ` (26 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Kai-Heng Feng, Mathias Nyman

From: Kai-Heng Feng <kai.heng.feng@canonical.com>

Current xhci debug message doesn't always output bus number, so it's
hard to figure out it's from USB2 or USB3 root hub.

In addition to that, some port numbers are offset to 0 and others are
offset to 1. Use the latter to match the USB core.

So use "bus number - port index + 1" to make debug message consistent.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-hub.c | 41 +++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 073c54e42223..c3554e37e09f 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1241,7 +1241,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 			temp = readl(ports[wIndex]->addr);
 			/* Disable port */
 			if (link_state == USB_SS_PORT_LS_SS_DISABLED) {
-				xhci_dbg(xhci, "Disable port %d\n", wIndex);
+				xhci_dbg(xhci, "Disable port %d-%d\n",
+					 hcd->self.busnum, wIndex + 1);
 				temp = xhci_port_state_to_neutral(temp);
 				/*
 				 * Clear all change bits, so that we get a new
@@ -1257,7 +1258,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 
 			/* Put link in RxDetect (enable port) */
 			if (link_state == USB_SS_PORT_LS_RX_DETECT) {
-				xhci_dbg(xhci, "Enable port %d\n", wIndex);
+				xhci_dbg(xhci, "Enable port %d-%d\n",
+					 hcd->self.busnum, wIndex + 1);
 				xhci_set_link_state(xhci, ports[wIndex],
 							link_state);
 				temp = readl(ports[wIndex]->addr);
@@ -1289,8 +1291,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 					goto error;
 				}
 
-				xhci_dbg(xhci, "Enable compliance mode transition for port %d\n",
-						wIndex);
+				xhci_dbg(xhci, "Enable compliance mode transition for port %d-%d\n",
+					 hcd->self.busnum, wIndex + 1);
 				xhci_set_link_state(xhci, ports[wIndex],
 						link_state);
 
@@ -1304,8 +1306,9 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 			}
 			/* Can't set port link state above '3' (U3) */
 			if (link_state > USB_SS_PORT_LS_U3) {
-				xhci_warn(xhci, "Cannot set port %d link state %d\n",
-					 wIndex, link_state);
+				xhci_warn(xhci, "Cannot set port %d-%d link state %d\n",
+					  hcd->self.busnum, wIndex + 1,
+					  link_state);
 				goto error;
 			}
 
@@ -1340,8 +1343,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 				spin_unlock_irqrestore(&xhci->lock, flags);
 				if (!wait_for_completion_timeout(&bus_state->u3exit_done[wIndex],
 								 msecs_to_jiffies(100)))
-					xhci_dbg(xhci, "missing U0 port change event for port %d\n",
-						 wIndex);
+					xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n",
+						 hcd->self.busnum, wIndex + 1);
 				spin_lock_irqsave(&xhci->lock, flags);
 				temp = readl(ports[wIndex]->addr);
 				break;
@@ -1386,15 +1389,15 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 			writel(temp, ports[wIndex]->addr);
 
 			temp = readl(ports[wIndex]->addr);
-			xhci_dbg(xhci, "set port reset, actual port %d status  = 0x%x\n", wIndex, temp);
+			xhci_dbg(xhci, "set port reset, actual port %d-%d status  = 0x%x\n",
+				 hcd->self.busnum, wIndex + 1, temp);
 			break;
 		case USB_PORT_FEAT_REMOTE_WAKE_MASK:
 			xhci_set_remote_wake_mask(xhci, ports[wIndex],
 						  wake_mask);
 			temp = readl(ports[wIndex]->addr);
-			xhci_dbg(xhci, "set port remote wake mask, "
-					"actual port %d status  = 0x%x\n",
-					wIndex, temp);
+			xhci_dbg(xhci, "set port remote wake mask, actual port %d-%d status  = 0x%x\n",
+				 hcd->self.busnum, wIndex + 1, temp);
 			break;
 		case USB_PORT_FEAT_BH_PORT_RESET:
 			temp |= PORT_WR;
@@ -1635,8 +1638,8 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
 			spin_unlock_irqrestore(&xhci->lock, flags);
 			msleep(XHCI_PORT_POLLING_LFPS_TIME);
 			spin_lock_irqsave(&xhci->lock, flags);
-			xhci_dbg(xhci, "port %d polling in bus suspend, waiting\n",
-				 port_index);
+			xhci_dbg(xhci, "port %d-%d polling in bus suspend, waiting\n",
+				 hcd->self.busnum, port_index + 1);
 			goto retry;
 		}
 		/* bail out if port detected a over-current condition */
@@ -1654,7 +1657,8 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
 				xhci_dbg(xhci, "Bus suspend bailout, port connect change\n");
 				return -EBUSY;
 			}
-			xhci_dbg(xhci, "port %d not suspended\n", port_index);
+			xhci_dbg(xhci, "port %d-%d not suspended\n",
+				 hcd->self.busnum, port_index + 1);
 			t2 &= ~PORT_PLS_MASK;
 			t2 |= PORT_LINK_STROBE | XDEV_U3;
 			set_bit(port_index, &bus_state->bus_suspended);
@@ -1784,7 +1788,8 @@ int xhci_bus_resume(struct usb_hcd *hcd)
 		if ((xhci->quirks & XHCI_MISSING_CAS) &&
 		    (hcd->speed >= HCD_USB3) &&
 		    xhci_port_missing_cas_quirk(ports[port_index])) {
-			xhci_dbg(xhci, "reset stuck port %d\n", port_index);
+			xhci_dbg(xhci, "reset stuck port %d-%d\n",
+				 hcd->self.busnum, port_index + 1);
 			clear_bit(port_index, &bus_state->bus_suspended);
 			continue;
 		}
@@ -1831,8 +1836,8 @@ int xhci_bus_resume(struct usb_hcd *hcd)
 		sret = xhci_handshake(ports[port_index]->addr, PORT_PLC,
 				      PORT_PLC, 10 * 1000);
 		if (sret) {
-			xhci_warn(xhci, "port %d resume PLC timeout\n",
-				  port_index);
+			xhci_warn(xhci, "port %d-%d resume PLC timeout\n",
+				  hcd->self.busnum, port_index + 1);
 			continue;
 		}
 		xhci_test_and_clear_bit(xhci, ports[port_index], PORT_PLC);
-- 
2.17.1


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

* [PATCH 02/27] xhci: dbc: Don't use generic xhci inc_deq() function for dbc
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
  2020-07-23 14:45 ` [PATCH 01/27] xhci: Make debug message consistent with bus and port number Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 03/27] xhci: Don't pass struct xhci_hcd pointer to xhci_link_seg() Mathias Nyman
                   ` (25 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

The generic inc_deq() helper takes struct xhci_hcd pointer as a parameter,
and is a lot more complex than needed for the DbC usecase.

In order to decouple xhci and DbC we have to create our own small
inc_evt_deq() helper, not relying on xhci.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 987f893e941c..424b571d6ca9 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -644,6 +644,17 @@ static void dbc_handle_xfer_event(struct xhci_hcd *xhci, union xhci_trb *event)
 	xhci_dbc_giveback(req, status);
 }
 
+static void inc_evt_deq(struct xhci_ring *ring)
+{
+	/* If on the last TRB of the segment go back to the beginning */
+	if (ring->dequeue == &ring->deq_seg->trbs[TRBS_PER_SEGMENT - 1]) {
+		ring->cycle_state ^= 1;
+		ring->dequeue = ring->deq_seg->trbs;
+		return;
+	}
+	ring->dequeue++;
+}
+
 static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 {
 	dma_addr_t		deq;
@@ -765,7 +776,8 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 			break;
 		}
 
-		inc_deq(xhci, dbc->ring_evt);
+		inc_evt_deq(dbc->ring_evt);
+
 		evt = dbc->ring_evt->dequeue;
 		update_erdp = true;
 	}
-- 
2.17.1


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

* [PATCH 03/27] xhci: Don't pass struct xhci_hcd pointer to xhci_link_seg()
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
  2020-07-23 14:45 ` [PATCH 01/27] xhci: Make debug message consistent with bus and port number Mathias Nyman
  2020-07-23 14:45 ` [PATCH 02/27] xhci: dbc: Don't use generic xhci inc_deq() function for dbc Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 04/27] xhci: dbc: Don't use generic xhci erst allocation and free functions Mathias Nyman
                   ` (24 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

It's only used to dig out if we need to set a chain flag for specific
hosts. Pass the flag directly as a parameter instead.

No functional changes.

xhci_link_seg() is also used by DbC code, this change helps decoupling
xhci and DbC.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-mem.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index fb221c091478..d38779e2fc84 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -96,8 +96,9 @@ static void xhci_free_segments_for_ring(struct xhci_hcd *xhci,
  * DMA address of the next segment.  The caller needs to set any Link TRB
  * related flags, such as End TRB, Toggle Cycle, and no snoop.
  */
-static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev,
-		struct xhci_segment *next, enum xhci_ring_type type)
+static void xhci_link_segments(struct xhci_segment *prev,
+			       struct xhci_segment *next,
+			       enum xhci_ring_type type, bool chain_links)
 {
 	u32 val;
 
@@ -112,11 +113,7 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev,
 		val = le32_to_cpu(prev->trbs[TRBS_PER_SEGMENT-1].link.control);
 		val &= ~TRB_TYPE_BITMASK;
 		val |= TRB_TYPE(TRB_LINK);
-		/* Always set the chain bit with 0.95 hardware */
-		/* Set chain bit for isoc rings on AMD 0.96 host */
-		if (xhci_link_trb_quirk(xhci) ||
-				(type == TYPE_ISOC &&
-				 (xhci->quirks & XHCI_AMD_0x96_HOST)))
+		if (chain_links)
 			val |= TRB_CHAIN;
 		prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val);
 	}
@@ -131,13 +128,19 @@ static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
 		unsigned int num_segs)
 {
 	struct xhci_segment *next;
+	bool chain_links;
 
 	if (!ring || !first || !last)
 		return;
 
+	/* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */
+	chain_links = !!(xhci_link_trb_quirk(xhci) ||
+			 (ring->type == TYPE_ISOC &&
+			  (xhci->quirks & XHCI_AMD_0x96_HOST)));
+
 	next = ring->enq_seg->next;
-	xhci_link_segments(xhci, ring->enq_seg, first, ring->type);
-	xhci_link_segments(xhci, last, next, ring->type);
+	xhci_link_segments(ring->enq_seg, first, ring->type, chain_links);
+	xhci_link_segments(last, next, ring->type, chain_links);
 	ring->num_segs += num_segs;
 	ring->num_trbs_free += (TRBS_PER_SEGMENT - 1) * num_segs;
 
@@ -321,6 +324,12 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
 		enum xhci_ring_type type, unsigned int max_packet, gfp_t flags)
 {
 	struct xhci_segment *prev;
+	bool chain_links;
+
+	/* Set chain bit for 0.95 hosts, and for isoc rings on AMD 0.96 host */
+	chain_links = !!(xhci_link_trb_quirk(xhci) ||
+			 (type == TYPE_ISOC &&
+			  (xhci->quirks & XHCI_AMD_0x96_HOST)));
 
 	prev = xhci_segment_alloc(xhci, cycle_state, max_packet, flags);
 	if (!prev)
@@ -341,12 +350,12 @@ static int xhci_alloc_segments_for_ring(struct xhci_hcd *xhci,
 			}
 			return -ENOMEM;
 		}
-		xhci_link_segments(xhci, prev, next, type);
+		xhci_link_segments(prev, next, type, chain_links);
 
 		prev = next;
 		num_segs--;
 	}
-	xhci_link_segments(xhci, prev, *first, type);
+	xhci_link_segments(prev, *first, type, chain_links);
 	*last = prev;
 
 	return 0;
-- 
2.17.1


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

* [PATCH 04/27] xhci: dbc: Don't use generic xhci erst allocation and free functions
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (2 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 03/27] xhci: Don't pass struct xhci_hcd pointer to xhci_link_seg() Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 05/27] xhci: dbc: Remove dbc_dma_alloc_coherent() wrapper Mathias Nyman
                   ` (23 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

The generic erst allocation and free functions take struct xhci_hcd pointer
as a parameter. Create own erst helpers for DbC in order to decouple xhci
and DbC

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

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 424b571d6ca9..138b0c994ad2 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -370,12 +370,36 @@ static void xhci_dbc_eps_exit(struct xhci_hcd *xhci)
 	memset(dbc->eps, 0, sizeof(struct dbc_ep) * ARRAY_SIZE(dbc->eps));
 }
 
+static int dbc_erst_alloc(struct device *dev, struct xhci_ring *evt_ring,
+		    struct xhci_erst *erst, gfp_t flags)
+{
+	erst->entries = dma_alloc_coherent(dev, sizeof(struct xhci_erst_entry),
+					   &erst->erst_dma_addr, flags);
+	if (!erst->entries)
+		return -ENOMEM;
+
+	erst->num_entries = 1;
+	erst->entries[0].seg_addr = cpu_to_le64(evt_ring->first_seg->dma);
+	erst->entries[0].seg_size = cpu_to_le32(TRBS_PER_SEGMENT);
+	erst->entries[0].rsvd = 0;
+	return 0;
+}
+
+static void dbc_erst_free(struct device *dev, struct xhci_erst *erst)
+{
+	if (erst->entries)
+		dma_free_coherent(dev, sizeof(struct xhci_erst_entry),
+				  erst->entries, erst->erst_dma_addr);
+	erst->entries = NULL;
+}
+
 static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 {
 	int			ret;
 	dma_addr_t		deq;
 	u32			string_length;
 	struct xhci_dbc		*dbc = xhci->dbc;
+	struct device		*dev = xhci_to_hcd(xhci)->self.controller;
 
 	/* Allocate various rings for events and transfers: */
 	dbc->ring_evt = xhci_ring_alloc(xhci, 1, 1, TYPE_EVENT, 0, flags);
@@ -391,7 +415,7 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 		goto out_fail;
 
 	/* Allocate and populate ERST: */
-	ret = xhci_alloc_erst(xhci, dbc->ring_evt, &dbc->erst, flags);
+	ret = dbc_erst_alloc(dev, dbc->ring_evt, &dbc->erst, flags);
 	if (ret)
 		goto erst_fail;
 
@@ -429,7 +453,7 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	xhci_free_container_ctx(xhci, dbc->ctx);
 	dbc->ctx = NULL;
 ctx_fail:
-	xhci_free_erst(xhci, &dbc->erst);
+	dbc_erst_free(dev, &dbc->erst);
 erst_fail:
 	xhci_ring_free(xhci, dbc->ring_out);
 	dbc->ring_out = NULL;
@@ -446,6 +470,7 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
 {
 	struct xhci_dbc		*dbc = xhci->dbc;
+	struct device		*dev = xhci_to_hcd(xhci)->self.controller;
 
 	if (!dbc)
 		return;
@@ -462,7 +487,7 @@ static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
 	xhci_free_container_ctx(xhci, dbc->ctx);
 	dbc->ctx = NULL;
 
-	xhci_free_erst(xhci, &dbc->erst);
+	dbc_erst_free(dev, &dbc->erst);
 	xhci_ring_free(xhci, dbc->ring_out);
 	xhci_ring_free(xhci, dbc->ring_in);
 	xhci_ring_free(xhci, dbc->ring_evt);
-- 
2.17.1


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

* [PATCH 05/27] xhci: dbc: Remove dbc_dma_alloc_coherent() wrapper
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (3 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 04/27] xhci: dbc: Don't use generic xhci erst allocation and free functions Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 06/27] xhci: dbc: Remove dbc_dma_free_coherent() wrapper Mathias Nyman
                   ` (22 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

dbc_dma_alloc_coherent() takes struct xhci_hcd pointer as an parameter, but
does nothing more than calls dma_alloc_coherent().
Remove it and call dma_alloc_coherent() directly instead.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 138b0c994ad2..e8a2cbda135c 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -14,17 +14,6 @@
 #include "xhci-trace.h"
 #include "xhci-dbgcap.h"
 
-static inline void *
-dbc_dma_alloc_coherent(struct xhci_hcd *xhci, size_t size,
-		       dma_addr_t *dma_handle, gfp_t flags)
-{
-	void		*vaddr;
-
-	vaddr = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
-				   size, dma_handle, flags);
-	return vaddr;
-}
-
 static inline void
 dbc_dma_free_coherent(struct xhci_hcd *xhci, size_t size,
 		      void *cpu_addr, dma_addr_t dma_handle)
@@ -426,10 +415,8 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 
 	/* Allocate the string table: */
 	dbc->string_size = sizeof(struct dbc_str_descs);
-	dbc->string = dbc_dma_alloc_coherent(xhci,
-					     dbc->string_size,
-					     &dbc->string_dma,
-					     flags);
+	dbc->string = dma_alloc_coherent(dev, dbc->string_size,
+					 &dbc->string_dma, flags);
 	if (!dbc->string)
 		goto string_fail;
 
-- 
2.17.1


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

* [PATCH 06/27] xhci: dbc: Remove dbc_dma_free_coherent() wrapper
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (4 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 05/27] xhci: dbc: Remove dbc_dma_alloc_coherent() wrapper Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 07/27] xhci: dbc: Add device pointer to dbc structure Mathias Nyman
                   ` (21 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

dbc_dma_free_coherent() takes struct xhci_hcd pointer as a parameter, but
does nothing more than calls dma_free_coherent().
Remove it and call dma_free_coherent() directly instead.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index e8a2cbda135c..5bec36ed97c6 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -14,15 +14,6 @@
 #include "xhci-trace.h"
 #include "xhci-dbgcap.h"
 
-static inline void
-dbc_dma_free_coherent(struct xhci_hcd *xhci, size_t size,
-		      void *cpu_addr, dma_addr_t dma_handle)
-{
-	if (cpu_addr)
-		dma_free_coherent(xhci_to_hcd(xhci)->self.sysdev,
-				  size, cpu_addr, dma_handle);
-}
-
 static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
 {
 	struct usb_string_descriptor	*s_desc;
@@ -465,9 +456,8 @@ static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
 	xhci_dbc_eps_exit(xhci);
 
 	if (dbc->string) {
-		dbc_dma_free_coherent(xhci,
-				      dbc->string_size,
-				      dbc->string, dbc->string_dma);
+		dma_free_coherent(dbc->dev, dbc->string_size,
+				  dbc->string, dbc->string_dma);
 		dbc->string = NULL;
 	}
 
-- 
2.17.1


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

* [PATCH 07/27] xhci: dbc: Add device pointer to dbc structure
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (5 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 06/27] xhci: dbc: Remove dbc_dma_free_coherent() wrapper Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 08/27] xhci: dbc: Use dev_info() and similar instead of xhci_info() Mathias Nyman
                   ` (20 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Currently the dbc structure contains a pointer to struct xhci_hcd,
and dbc functions use that to dig up the underlying device pointer.

We are trying to decouple xhci and dbc code, and prepare for
code that use dbc such as dbctty into into real device drivers.
This is one step along the way.

Keep functionality the same and keep the xhci pointer, and
let the new device pointer point to the xhci device for now.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 1 +
 drivers/usb/host/xhci-dbgcap.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 5bec36ed97c6..ae584d6ae10c 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -878,6 +878,7 @@ static int xhci_do_dbc_init(struct xhci_hcd *xhci)
 	spin_unlock_irqrestore(&xhci->lock, flags);
 
 	dbc->xhci = xhci;
+	dbc->dev = xhci_to_hcd(xhci)->self.sysdev;
 	INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
 	spin_lock_init(&dbc->lock);
 
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index ce0c6072bd48..7ca2f4ccc537 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -133,6 +133,7 @@ struct dbc_port {
 
 struct xhci_dbc {
 	spinlock_t			lock;		/* device access */
+	struct device			*dev;
 	struct xhci_hcd			*xhci;
 	struct dbc_regs __iomem		*regs;
 	struct xhci_ring		*ring_evt;
-- 
2.17.1


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

* [PATCH 08/27] xhci: dbc: Use dev_info() and similar instead of xhci_info()
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (6 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 07/27] xhci: dbc: Add device pointer to dbc structure Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 09/27] xhci: dbc: Don't use xhci_write_64() as it takes xhci as a parameter Mathias Nyman
                   ` (19 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

To make this change possible we also need to change
dbc_handle_port_status() to take dbc pointer as parameter instead of
xhci_hcd pointer.

Note that xhci_info() used xhci_to_hcd(xhci)->self.controller as the
device while for dev_info we use xhci_to_hcd(xhci)->self.sysdev.

In many cases those are the same, but not for some device where
a dwc3 controller creates a xhci platform device. In th this case
self.controller may be the platform device while self.sysdev is
the actual device known to firmware (dwc3).

This change helps decoupling xhci and DbC

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

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index ae584d6ae10c..3375be7ea642 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -286,13 +286,13 @@ dbc_ep_do_queue(struct dbc_ep *dep, struct dbc_request *req)
 				  req->length,
 				  dbc_ep_dma_direction(dep));
 	if (dma_mapping_error(dev, req->dma)) {
-		xhci_err(xhci, "failed to map buffer\n");
+		dev_err(dbc->dev, "failed to map buffer\n");
 		return -EFAULT;
 	}
 
 	ret = xhci_dbc_queue_bulk_tx(dep, req);
 	if (ret) {
-		xhci_err(xhci, "failed to queue trbs\n");
+		dev_err(dbc->dev, "failed to queue trbs\n");
 		dma_unmap_single(dev,
 				 req->dma,
 				 req->length,
@@ -567,23 +567,22 @@ static void xhci_dbc_stop(struct xhci_hcd *xhci)
 }
 
 static void
-dbc_handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
+dbc_handle_port_status(struct xhci_dbc *dbc, union xhci_trb *event)
 {
 	u32			portsc;
-	struct xhci_dbc		*dbc = xhci->dbc;
 
 	portsc = readl(&dbc->regs->portsc);
 	if (portsc & DBC_PORTSC_CONN_CHANGE)
-		xhci_info(xhci, "DbC port connect change\n");
+		dev_info(dbc->dev, "DbC port connect change\n");
 
 	if (portsc & DBC_PORTSC_RESET_CHANGE)
-		xhci_info(xhci, "DbC port reset change\n");
+		dev_info(dbc->dev, "DbC port reset change\n");
 
 	if (portsc & DBC_PORTSC_LINK_CHANGE)
-		xhci_info(xhci, "DbC port link status change\n");
+		dev_info(dbc->dev, "DbC port link status change\n");
 
 	if (portsc & DBC_PORTSC_CONFIG_CHANGE)
-		xhci_info(xhci, "DbC config error change\n");
+		dev_info(dbc->dev, "DbC config error change\n");
 
 	/* Port reset change bit will be cleared in other place: */
 	writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc);
@@ -598,6 +597,7 @@ static void dbc_handle_xfer_event(struct xhci_hcd *xhci, union xhci_trb *event)
 	u32			comp_code;
 	size_t			remain_length;
 	struct dbc_request	*req = NULL, *r;
+	struct xhci_dbc		*dbc = xhci->dbc;
 
 	comp_code	= GET_COMP_CODE(le32_to_cpu(event->generic.field[2]));
 	remain_length	= EVENT_TRB_LEN(le32_to_cpu(event->generic.field[2]));
@@ -617,11 +617,11 @@ static void dbc_handle_xfer_event(struct xhci_hcd *xhci, union xhci_trb *event)
 	case COMP_BABBLE_DETECTED_ERROR:
 	case COMP_USB_TRANSACTION_ERROR:
 	case COMP_STALL_ERROR:
-		xhci_warn(xhci, "tx error %d detected\n", comp_code);
+		dev_warn(dbc->dev, "tx error %d detected\n", comp_code);
 		status = -comp_code;
 		break;
 	default:
-		xhci_err(xhci, "unknown tx error %d\n", comp_code);
+		dev_err(dbc->dev, "unknown tx error %d\n", comp_code);
 		status = -comp_code;
 		break;
 	}
@@ -635,7 +635,7 @@ static void dbc_handle_xfer_event(struct xhci_hcd *xhci, union xhci_trb *event)
 	}
 
 	if (!req) {
-		xhci_warn(xhci, "no matched request\n");
+		dev_warn(dbc->dev, "no matched request\n");
 		return;
 	}
 
@@ -676,7 +676,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 		portsc = readl(&dbc->regs->portsc);
 		if (portsc & DBC_PORTSC_CONN_STATUS) {
 			dbc->state = DS_CONNECTED;
-			xhci_info(xhci, "DbC connected\n");
+			dev_info(dbc->dev, "DbC connected\n");
 		}
 
 		return EVT_DONE;
@@ -684,7 +684,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 		ctrl = readl(&dbc->regs->control);
 		if (ctrl & DBC_CTRL_DBC_RUN) {
 			dbc->state = DS_CONFIGURED;
-			xhci_info(xhci, "DbC configured\n");
+			dev_info(dbc->dev, "DbC configured\n");
 			portsc = readl(&dbc->regs->portsc);
 			writel(portsc, &dbc->regs->portsc);
 			return EVT_GSER;
@@ -696,7 +696,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 		portsc = readl(&dbc->regs->portsc);
 		if (!(portsc & DBC_PORTSC_PORT_ENABLED) &&
 		    !(portsc & DBC_PORTSC_CONN_STATUS)) {
-			xhci_info(xhci, "DbC cable unplugged\n");
+			dev_info(dbc->dev, "DbC cable unplugged\n");
 			dbc->state = DS_ENABLED;
 			xhci_dbc_flush_requests(dbc);
 
@@ -705,7 +705,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 
 		/* Handle debug port reset event: */
 		if (portsc & DBC_PORTSC_RESET_CHANGE) {
-			xhci_info(xhci, "DbC port reset\n");
+			dev_info(dbc->dev, "DbC port reset\n");
 			writel(portsc, &dbc->regs->portsc);
 			dbc->state = DS_ENABLED;
 			xhci_dbc_flush_requests(dbc);
@@ -717,7 +717,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 		ctrl = readl(&dbc->regs->control);
 		if ((ctrl & DBC_CTRL_HALT_IN_TR) ||
 		    (ctrl & DBC_CTRL_HALT_OUT_TR)) {
-			xhci_info(xhci, "DbC Endpoint stall\n");
+			dev_info(dbc->dev, "DbC Endpoint stall\n");
 			dbc->state = DS_STALLED;
 
 			if (ctrl & DBC_CTRL_HALT_IN_TR) {
@@ -751,7 +751,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 
 		return EVT_DONE;
 	default:
-		xhci_err(xhci, "Unknown DbC state %d\n", dbc->state);
+		dev_err(dbc->dev, "Unknown DbC state %d\n", dbc->state);
 		break;
 	}
 
@@ -769,7 +769,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 
 		switch (le32_to_cpu(evt->event_cmd.flags) & TRB_TYPE_BITMASK) {
 		case TRB_TYPE(TRB_PORT_STATUS):
-			dbc_handle_port_status(xhci, evt);
+			dbc_handle_port_status(dbc, evt);
 			break;
 		case TRB_TYPE(TRB_TRANSFER):
 			dbc_handle_xfer_event(xhci, evt);
@@ -813,11 +813,11 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 	case EVT_GSER:
 		ret = xhci_dbc_tty_register_device(xhci);
 		if (ret) {
-			xhci_err(xhci, "failed to alloc tty device\n");
+			dev_err(dbc->dev, "failed to alloc tty device\n");
 			break;
 		}
 
-		xhci_info(xhci, "DbC now attached to /dev/ttyDBC0\n");
+		dev_info(dbc->dev, "DbC now attached to /dev/ttyDBC0\n");
 		break;
 	case EVT_DISC:
 		xhci_dbc_tty_unregister_device(xhci);
@@ -825,7 +825,7 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 	case EVT_DONE:
 		break;
 	default:
-		xhci_info(xhci, "stop handling dbc events\n");
+		dev_info(dbc->dev, "stop handling dbc events\n");
 		return;
 	}
 
-- 
2.17.1


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

* [PATCH 09/27] xhci: dbc: Don't use xhci_write_64() as it takes xhci as a parameter
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (7 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 08/27] xhci: dbc: Use dev_info() and similar instead of xhci_info() Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 10/27] xhci: dbc: Don't pass the xhci pointer as a parameter to xhci_dbc_init_context() Mathias Nyman
                   ` (18 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

xhci_write_64() is essentially a wrapper for lo_hi_writeq(), but it
requires struct xhci_hcd * as a parameter.
Use lo_hi_writeq() directly instead

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 3375be7ea642..3541fbbfc28b 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -101,7 +101,7 @@ static void xhci_dbc_init_contexts(struct xhci_hcd *xhci, u32 string_length)
 	ep_ctx->deq		= cpu_to_le64(deq | dbc->ring_in->cycle_state);
 
 	/* Set DbC context and info registers: */
-	xhci_write_64(xhci, dbc->ctx->dma, &dbc->regs->dccp);
+	lo_hi_writeq(dbc->ctx->dma, &dbc->regs->dccp);
 
 	dev_info = cpu_to_le32((DBC_VENDOR_ID << 16) | DBC_PROTOCOL);
 	writel(dev_info, &dbc->regs->devinfo1);
@@ -413,10 +413,11 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 
 	/* Setup ERST register: */
 	writel(dbc->erst.erst_size, &dbc->regs->ersts);
-	xhci_write_64(xhci, dbc->erst.erst_dma_addr, &dbc->regs->erstba);
+
+	lo_hi_writeq(dbc->erst.erst_dma_addr, &dbc->regs->erstba);
 	deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg,
 				   dbc->ring_evt->dequeue);
-	xhci_write_64(xhci, deq, &dbc->regs->erdp);
+	lo_hi_writeq(deq, &dbc->regs->erdp);
 
 	/* Setup strings and contexts: */
 	string_length = xhci_dbc_populate_strings(dbc->string);
@@ -788,7 +789,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 	if (update_erdp) {
 		deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg,
 					   dbc->ring_evt->dequeue);
-		xhci_write_64(xhci, deq, &dbc->regs->erdp);
+		lo_hi_writeq(deq, &dbc->regs->erdp);
 	}
 
 	return EVT_DONE;
-- 
2.17.1


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

* [PATCH 10/27] xhci: dbc: Don't pass the xhci pointer as a parameter to xhci_dbc_init_context()
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (8 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 09/27] xhci: dbc: Don't use xhci_write_64() as it takes xhci as a parameter Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 11/27] xhci: dbc: Get the device pointer from dbc structure in dbc_ep_do_queue() Mathias Nyman
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

xhci_dbc_init_context() no longer needs the struct xhci_hcd pointer.
Pass the dbc pointer directly instead.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 3541fbbfc28b..a5281f95fd72 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -63,16 +63,14 @@ static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
 	return string_length;
 }
 
-static void xhci_dbc_init_contexts(struct xhci_hcd *xhci, u32 string_length)
+static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
 {
-	struct xhci_dbc		*dbc;
 	struct dbc_info_context	*info;
 	struct xhci_ep_ctx	*ep_ctx;
 	u32			dev_info;
 	dma_addr_t		deq, dma;
 	unsigned int		max_burst;
 
-	dbc = xhci->dbc;
 	if (!dbc)
 		return;
 
@@ -421,7 +419,7 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 
 	/* Setup strings and contexts: */
 	string_length = xhci_dbc_populate_strings(dbc->string);
-	xhci_dbc_init_contexts(xhci, string_length);
+	xhci_dbc_init_contexts(dbc, string_length);
 
 	xhci_dbc_eps_init(xhci);
 	dbc->state = DS_INITIALIZED;
-- 
2.17.1


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

* [PATCH 11/27] xhci: dbc: Get the device pointer from dbc structure in dbc_ep_do_queue()
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (9 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 10/27] xhci: dbc: Don't pass the xhci pointer as a parameter to xhci_dbc_init_context() Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 12/27] xhci: dbc: Pass dbc pointer to endpoint init and exit functions Mathias Nyman
                   ` (16 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

dbc_ep_do_queue() can now get the device pointer directly from dbc
structure instead of going through the xhci_hcd structure.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index a5281f95fd72..44fe93632901 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -267,11 +267,8 @@ static int
 dbc_ep_do_queue(struct dbc_ep *dep, struct dbc_request *req)
 {
 	int			ret;
-	struct device		*dev;
 	struct xhci_dbc		*dbc = dep->dbc;
-	struct xhci_hcd		*xhci = dbc->xhci;
-
-	dev = xhci_to_hcd(xhci)->self.sysdev;
+	struct device		*dev = dbc->dev;
 
 	if (!req->length || !req->buf)
 		return -EINVAL;
-- 
2.17.1


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

* [PATCH 12/27] xhci: dbc: Pass dbc pointer to endpoint init and exit functions.
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (10 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 11/27] xhci: dbc: Get the device pointer from dbc structure in dbc_ep_do_queue() Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 13/27] xhci: dbc: Change to pass dbc pointer to xhci_do_dbc_stop() Mathias Nyman
                   ` (15 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

struct xhci_hcd pointer is not needed for dbc endpoint init and exit,
it was only used to get to the dbc structure.
Pass the dbc pointer as a parameter to these functions instead.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 44fe93632901..6114b334eb61 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -319,10 +319,9 @@ int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req,
 	return ret;
 }
 
-static inline void xhci_dbc_do_eps_init(struct xhci_hcd *xhci, bool direction)
+static inline void xhci_dbc_do_eps_init(struct xhci_dbc *dbc, bool direction)
 {
 	struct dbc_ep		*dep;
-	struct xhci_dbc		*dbc = xhci->dbc;
 
 	dep			= &dbc->eps[direction];
 	dep->dbc		= dbc;
@@ -332,16 +331,14 @@ static inline void xhci_dbc_do_eps_init(struct xhci_hcd *xhci, bool direction)
 	INIT_LIST_HEAD(&dep->list_pending);
 }
 
-static void xhci_dbc_eps_init(struct xhci_hcd *xhci)
+static void xhci_dbc_eps_init(struct xhci_dbc *dbc)
 {
-	xhci_dbc_do_eps_init(xhci, BULK_OUT);
-	xhci_dbc_do_eps_init(xhci, BULK_IN);
+	xhci_dbc_do_eps_init(dbc, BULK_OUT);
+	xhci_dbc_do_eps_init(dbc, BULK_IN);
 }
 
-static void xhci_dbc_eps_exit(struct xhci_hcd *xhci)
+static void xhci_dbc_eps_exit(struct xhci_dbc *dbc)
 {
-	struct xhci_dbc		*dbc = xhci->dbc;
-
 	memset(dbc->eps, 0, sizeof(struct dbc_ep) * ARRAY_SIZE(dbc->eps));
 }
 
@@ -418,7 +415,7 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	string_length = xhci_dbc_populate_strings(dbc->string);
 	xhci_dbc_init_contexts(dbc, string_length);
 
-	xhci_dbc_eps_init(xhci);
+	xhci_dbc_eps_init(dbc);
 	dbc->state = DS_INITIALIZED;
 
 	return 0;
@@ -449,7 +446,7 @@ static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
 	if (!dbc)
 		return;
 
-	xhci_dbc_eps_exit(xhci);
+	xhci_dbc_eps_exit(dbc);
 
 	if (dbc->string) {
 		dma_free_coherent(dbc->dev, dbc->string_size,
-- 
2.17.1


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

* [PATCH 13/27] xhci: dbc: Change to pass dbc pointer to xhci_do_dbc_stop()
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (11 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 12/27] xhci: dbc: Pass dbc pointer to endpoint init and exit functions Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 14/27] xhci: dbc: Pass dbc pointer to dbc_handle_xfer_event() instead of xhci_hcd pointer Mathias Nyman
                   ` (14 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Pass the dbc pointer instead of xhci_hcd pointer in order to
decouple xhci and dbc.

xhci_do_dbc_stop() only used xhci to get the dbc pointer.
Pass the dbc pointer instead as a parameter

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 6114b334eb61..7dce1e094364 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -500,10 +500,8 @@ static int xhci_do_dbc_start(struct xhci_hcd *xhci)
 	return 0;
 }
 
-static int xhci_do_dbc_stop(struct xhci_hcd *xhci)
+static int xhci_do_dbc_stop(struct xhci_dbc *dbc)
 {
-	struct xhci_dbc		*dbc = xhci->dbc;
-
 	if (dbc->state == DS_DISABLED)
 		return -1;
 
@@ -550,7 +548,7 @@ static void xhci_dbc_stop(struct xhci_hcd *xhci)
 		xhci_dbc_tty_unregister_device(xhci);
 
 	spin_lock_irqsave(&dbc->lock, flags);
-	ret = xhci_do_dbc_stop(xhci);
+	ret = xhci_do_dbc_stop(dbc);
 	spin_unlock_irqrestore(&dbc->lock, flags);
 
 	if (!ret) {
-- 
2.17.1


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

* [PATCH 14/27] xhci: dbc: Pass dbc pointer to dbc_handle_xfer_event() instead of xhci_hcd pointer
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (12 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 13/27] xhci: dbc: Change to pass dbc pointer to xhci_do_dbc_stop() Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 15/27] xhci: dbgtty: Pass dbc pointer when registering a dbctty device Mathias Nyman
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

The event handling function only used xhci pointer to get the dbc pointer.
Pass the dbc pointer instead as a parameter

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 7dce1e094364..1c53fdc791a4 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -579,7 +579,7 @@ dbc_handle_port_status(struct xhci_dbc *dbc, union xhci_trb *event)
 	writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc);
 }
 
-static void dbc_handle_xfer_event(struct xhci_hcd *xhci, union xhci_trb *event)
+static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event)
 {
 	struct dbc_ep		*dep;
 	struct xhci_ring	*ring;
@@ -588,7 +588,6 @@ static void dbc_handle_xfer_event(struct xhci_hcd *xhci, union xhci_trb *event)
 	u32			comp_code;
 	size_t			remain_length;
 	struct dbc_request	*req = NULL, *r;
-	struct xhci_dbc		*dbc = xhci->dbc;
 
 	comp_code	= GET_COMP_CODE(le32_to_cpu(event->generic.field[2]));
 	remain_length	= EVENT_TRB_LEN(le32_to_cpu(event->generic.field[2]));
@@ -654,7 +653,6 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 	struct dbc_ep		*dep;
 	union xhci_trb		*evt;
 	u32			ctrl, portsc;
-	struct xhci_hcd		*xhci = dbc->xhci;
 	bool			update_erdp = false;
 
 	/* DbC state machine: */
@@ -763,7 +761,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 			dbc_handle_port_status(dbc, evt);
 			break;
 		case TRB_TYPE(TRB_TRANSFER):
-			dbc_handle_xfer_event(xhci, evt);
+			dbc_handle_xfer_event(dbc, evt);
 			break;
 		default:
 			break;
-- 
2.17.1


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

* [PATCH 15/27] xhci: dbgtty: Pass dbc pointer when registering a dbctty device
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (13 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 14/27] xhci: dbc: Pass dbc pointer to dbc_handle_xfer_event() instead of xhci_hcd pointer Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 16/27] xhci: dbc: Pass dbc pointer to get_in/out_ep() helper functions to get endpoints Mathias Nyman
                   ` (12 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Pass dbc pointer to the xhci_dbc_tty_register_device() and
xhci_dbc_tty_unregister_device() functions instead of xhci_hcd pointer

These functions don't need a xhci_hcd pointer anymore, only use case was
the xhci_err() function, which is now changed to a dev_err() instead.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 8 +++-----
 drivers/usb/host/xhci-dbgcap.h | 4 ++--
 drivers/usb/host/xhci-dbgtty.c | 8 +++-----
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 1c53fdc791a4..dd8ac5918ad8 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -545,7 +545,7 @@ static void xhci_dbc_stop(struct xhci_hcd *xhci)
 	cancel_delayed_work_sync(&dbc->event_work);
 
 	if (port->registered)
-		xhci_dbc_tty_unregister_device(xhci);
+		xhci_dbc_tty_unregister_device(dbc);
 
 	spin_lock_irqsave(&dbc->lock, flags);
 	ret = xhci_do_dbc_stop(dbc);
@@ -789,10 +789,8 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 	enum evtreturn		evtr;
 	struct xhci_dbc		*dbc;
 	unsigned long		flags;
-	struct xhci_hcd		*xhci;
 
 	dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
-	xhci = dbc->xhci;
 
 	spin_lock_irqsave(&dbc->lock, flags);
 	evtr = xhci_dbc_do_handle_events(dbc);
@@ -800,7 +798,7 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 
 	switch (evtr) {
 	case EVT_GSER:
-		ret = xhci_dbc_tty_register_device(xhci);
+		ret = xhci_dbc_tty_register_device(dbc);
 		if (ret) {
 			dev_err(dbc->dev, "failed to alloc tty device\n");
 			break;
@@ -809,7 +807,7 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 		dev_info(dbc->dev, "DbC now attached to /dev/ttyDBC0\n");
 		break;
 	case EVT_DISC:
-		xhci_dbc_tty_unregister_device(xhci);
+		xhci_dbc_tty_unregister_device(dbc);
 		break;
 	case EVT_DONE:
 		break;
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 7ca2f4ccc537..628f85f97dfe 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -198,8 +198,8 @@ int xhci_dbc_init(struct xhci_hcd *xhci);
 void xhci_dbc_exit(struct xhci_hcd *xhci);
 int xhci_dbc_tty_register_driver(struct xhci_hcd *xhci);
 void xhci_dbc_tty_unregister_driver(void);
-int xhci_dbc_tty_register_device(struct xhci_hcd *xhci);
-void xhci_dbc_tty_unregister_device(struct xhci_hcd *xhci);
+int xhci_dbc_tty_register_device(struct xhci_dbc *dbc);
+void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc);
 struct dbc_request *dbc_alloc_request(struct dbc_ep *dep, gfp_t gfp_flags);
 void dbc_free_request(struct dbc_ep *dep, struct dbc_request *req);
 int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req, gfp_t gfp_flags);
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 9a1d38442578..545e8cb0221a 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -440,11 +440,10 @@ xhci_dbc_tty_exit_port(struct dbc_port *port)
 	tty_port_destroy(&port->port);
 }
 
-int xhci_dbc_tty_register_device(struct xhci_hcd *xhci)
+int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
 {
 	int			ret;
 	struct device		*tty_dev;
-	struct xhci_dbc		*dbc = xhci->dbc;
 	struct dbc_port		*port = &dbc->port;
 
 	xhci_dbc_tty_init_port(xhci, port);
@@ -484,14 +483,13 @@ int xhci_dbc_tty_register_device(struct xhci_hcd *xhci)
 register_fail:
 	xhci_dbc_tty_exit_port(port);
 
-	xhci_err(xhci, "can't register tty port, err %d\n", ret);
+	dev_err(dbc->dev, "can't register tty port, err %d\n", ret);
 
 	return ret;
 }
 
-void xhci_dbc_tty_unregister_device(struct xhci_hcd *xhci)
+void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 {
-	struct xhci_dbc		*dbc = xhci->dbc;
 	struct dbc_port		*port = &dbc->port;
 
 	tty_unregister_device(dbc_tty_driver, 0);
-- 
2.17.1


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

* [PATCH 16/27] xhci: dbc: Pass dbc pointer to get_in/out_ep() helper functions to get endpoints
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (14 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 15/27] xhci: dbgtty: Pass dbc pointer when registering a dbctty device Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 17/27] xhci: dbc: Use dbc structure in the request completion instead of xhci_hcd Mathias Nyman
                   ` (11 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Pass dbc pointer instead of struct xhci_hcd pointer to the get_in_ep() and
get_out_ep() helper functions.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c |  6 +++---
 drivers/usb/host/xhci-dbgcap.h |  8 ++------
 drivers/usb/host/xhci-dbgtty.c | 14 +++++++-------
 3 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index dd8ac5918ad8..26e693dd7414 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -593,7 +593,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event)
 	remain_length	= EVENT_TRB_LEN(le32_to_cpu(event->generic.field[2]));
 	ep_id		= TRB_TO_EP_ID(le32_to_cpu(event->generic.field[3]));
 	dep		= (ep_id == EPID_OUT) ?
-				get_out_ep(xhci) : get_in_ep(xhci);
+				get_out_ep(dbc) : get_in_ep(dbc);
 	ring		= dep->ring;
 
 	switch (comp_code) {
@@ -710,12 +710,12 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 			dbc->state = DS_STALLED;
 
 			if (ctrl & DBC_CTRL_HALT_IN_TR) {
-				dep = get_in_ep(xhci);
+				dep = get_in_ep(dbc);
 				xhci_dbc_flush_endpoint_requests(dep);
 			}
 
 			if (ctrl & DBC_CTRL_HALT_OUT_TR) {
-				dep = get_out_ep(xhci);
+				dep = get_out_ep(dbc);
 				xhci_dbc_flush_endpoint_requests(dep);
 			}
 
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 628f85f97dfe..dc7d2d157e7b 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -179,17 +179,13 @@ enum evtreturn {
 	EVT_DISC,
 };
 
-static inline struct dbc_ep *get_in_ep(struct xhci_hcd *xhci)
+static inline struct dbc_ep *get_in_ep(struct xhci_dbc *dbc)
 {
-	struct xhci_dbc		*dbc = xhci->dbc;
-
 	return &dbc->eps[BULK_IN];
 }
 
-static inline struct dbc_ep *get_out_ep(struct xhci_hcd *xhci)
+static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc)
 {
-	struct xhci_dbc		*dbc = xhci->dbc;
-
 	return &dbc->eps[BULK_OUT];
 }
 
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 545e8cb0221a..0ef48862f4a7 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -418,7 +418,7 @@ static const struct tty_port_operations dbc_port_ops = {
 };
 
 static void
-xhci_dbc_tty_init_port(struct xhci_hcd *xhci, struct dbc_port *port)
+xhci_dbc_tty_init_port(struct xhci_dbc *dbc, struct dbc_port *port)
 {
 	tty_port_init(&port->port);
 	spin_lock_init(&port->port_lock);
@@ -427,8 +427,8 @@ xhci_dbc_tty_init_port(struct xhci_hcd *xhci, struct dbc_port *port)
 	INIT_LIST_HEAD(&port->read_queue);
 	INIT_LIST_HEAD(&port->write_pool);
 
-	port->in =		get_in_ep(xhci);
-	port->out =		get_out_ep(xhci);
+	port->in =		get_in_ep(dbc);
+	port->out =		get_out_ep(dbc);
 	port->port.ops =	&dbc_port_ops;
 	port->n_read =		0;
 }
@@ -446,7 +446,7 @@ int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
 	struct device		*tty_dev;
 	struct dbc_port		*port = &dbc->port;
 
-	xhci_dbc_tty_init_port(xhci, port);
+	xhci_dbc_tty_init_port(dbc, port);
 	tty_dev = tty_port_register_device(&port->port,
 					   dbc_tty_driver, 0, NULL);
 	if (IS_ERR(tty_dev)) {
@@ -497,7 +497,7 @@ void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 	port->registered = false;
 
 	kfifo_free(&port->write_fifo);
-	xhci_dbc_free_requests(get_out_ep(xhci), &port->read_pool);
-	xhci_dbc_free_requests(get_out_ep(xhci), &port->read_queue);
-	xhci_dbc_free_requests(get_in_ep(xhci), &port->write_pool);
+	xhci_dbc_free_requests(get_out_ep(dbc), &port->read_pool);
+	xhci_dbc_free_requests(get_out_ep(dbc), &port->read_queue);
+	xhci_dbc_free_requests(get_in_ep(dbc), &port->write_pool);
 }
-- 
2.17.1


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

* [PATCH 17/27] xhci: dbc: Use dbc structure in the request completion instead of xhci_hcd
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (15 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 16/27] xhci: dbc: Pass dbc pointer to get_in/out_ep() helper functions to get endpoints Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 18/27] xhci: dbc: Don't use generic xhci context allocation for dbc Mathias Nyman
                   ` (10 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

The dbc request completion callback doesn't need a xhci_hcd pointer.
The only user of the xhci_hcd pointer in dbgtty request callback was
the xhci_warn() function. Change it to dev_warn() instead.

While changing the callback function parameter to dbc in struct
xhci_requeset, move the struct xhci_request declaraion down a bit in the
header file to avoid compiler warinings

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c |  5 ++---
 drivers/usb/host/xhci-dbgcap.h | 34 +++++++++++++++++-----------------
 drivers/usb/host/xhci-dbgtty.c | 10 ++++------
 3 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 26e693dd7414..2473100b955a 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -114,8 +114,7 @@ static void xhci_dbc_giveback(struct dbc_request *req, int status)
 {
 	struct dbc_ep		*dep = req->dep;
 	struct xhci_dbc		*dbc = dep->dbc;
-	struct xhci_hcd		*xhci = dbc->xhci;
-	struct device		*dev = xhci_to_hcd(dbc->xhci)->self.sysdev;
+	struct device		*dev = dbc->dev;
 
 	list_del_init(&req->list_pending);
 	req->trb_dma = 0;
@@ -133,7 +132,7 @@ static void xhci_dbc_giveback(struct dbc_request *req, int status)
 
 	/* Give back the transfer request: */
 	spin_unlock(&dbc->lock);
-	req->complete(xhci, req);
+	req->complete(dbc, req);
 	spin_lock(&dbc->lock);
 }
 
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index dc7d2d157e7b..9e3c5940f27b 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -84,23 +84,6 @@ enum dbc_state {
 	DS_STALLED,
 };
 
-struct dbc_request {
-	void				*buf;
-	unsigned int			length;
-	dma_addr_t			dma;
-	void				(*complete)(struct xhci_hcd *xhci,
-						    struct dbc_request *req);
-	struct list_head		list_pool;
-	int				status;
-	unsigned int			actual;
-
-	struct dbc_ep			*dep;
-	struct list_head		list_pending;
-	dma_addr_t			trb_dma;
-	union xhci_trb			*trb;
-	unsigned			direction:1;
-};
-
 struct dbc_ep {
 	struct xhci_dbc			*dbc;
 	struct list_head		list_pending;
@@ -154,6 +137,23 @@ struct xhci_dbc {
 	struct dbc_port			port;
 };
 
+struct dbc_request {
+	void				*buf;
+	unsigned int			length;
+	dma_addr_t			dma;
+	void				(*complete)(struct xhci_dbc *dbc,
+						    struct dbc_request *req);
+	struct list_head		list_pool;
+	int				status;
+	unsigned int			actual;
+
+	struct dbc_ep			*dep;
+	struct list_head		list_pending;
+	dma_addr_t			trb_dma;
+	union xhci_trb			*trb;
+	unsigned			direction:1;
+};
+
 #define dbc_bulkout_ctx(d)		\
 	((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE))
 #define dbc_bulkin_ctx(d)		\
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 0ef48862f4a7..967f0419dad7 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -91,10 +91,9 @@ static void dbc_start_rx(struct dbc_port *port)
 }
 
 static void
-dbc_read_complete(struct xhci_hcd *xhci, struct dbc_request *req)
+dbc_read_complete(struct xhci_dbc *dbc, struct dbc_request *req)
 {
 	unsigned long		flags;
-	struct xhci_dbc		*dbc = xhci->dbc;
 	struct dbc_port		*port = &dbc->port;
 
 	spin_lock_irqsave(&port->port_lock, flags);
@@ -103,10 +102,9 @@ dbc_read_complete(struct xhci_hcd *xhci, struct dbc_request *req)
 	spin_unlock_irqrestore(&port->port_lock, flags);
 }
 
-static void dbc_write_complete(struct xhci_hcd *xhci, struct dbc_request *req)
+static void dbc_write_complete(struct xhci_dbc *dbc, struct dbc_request *req)
 {
 	unsigned long		flags;
-	struct xhci_dbc		*dbc = xhci->dbc;
 	struct dbc_port		*port = &dbc->port;
 
 	spin_lock_irqsave(&port->port_lock, flags);
@@ -118,7 +116,7 @@ static void dbc_write_complete(struct xhci_hcd *xhci, struct dbc_request *req)
 	case -ESHUTDOWN:
 		break;
 	default:
-		xhci_warn(xhci, "unexpected write complete status %d\n",
+		dev_warn(dbc->dev, "unexpected write complete status %d\n",
 			  req->status);
 		break;
 	}
@@ -133,7 +131,7 @@ static void xhci_dbc_free_req(struct dbc_ep *dep, struct dbc_request *req)
 
 static int
 xhci_dbc_alloc_requests(struct dbc_ep *dep, struct list_head *head,
-			void (*fn)(struct xhci_hcd *, struct dbc_request *))
+			void (*fn)(struct xhci_dbc *, struct dbc_request *))
 {
 	int			i;
 	struct dbc_request	*req;
-- 
2.17.1


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

* [PATCH 18/27] xhci: dbc: Don't use generic xhci context allocation for dbc
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (16 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 17/27] xhci: dbc: Use dbc structure in the request completion instead of xhci_hcd Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 19/27] xhci: dbc: don't use generic xhci ring allocation functions " Mathias Nyman
                   ` (9 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

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 --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);
-- 
2.17.1


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

* [PATCH 19/27] xhci: dbc: don't use generic xhci ring allocation functions for dbc.
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (17 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 18/27] xhci: dbc: Don't use generic xhci context allocation for dbc Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 20/27] xhci: dbc: Pass dbc pointer to dbc memory init and cleanup functions Mathias Nyman
                   ` (8 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

The generic xhci ring allocations code needs struct xhci_hcd pointer, and
it allocates memory for the rings from dma pools created for the xhci
device.

In order to decouple xhci and DbC we have to create our own ring allocation
and free routines for DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 80 +++++++++++++++++++++++++++++-----
 drivers/usb/host/xhci-mem.c    |  4 +-
 drivers/usb/host/xhci.h        |  2 +
 3 files changed, 74 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index fb56198d3aff..b00cbff5e2ca 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -22,6 +22,21 @@ static void dbc_free_ctx(struct device *dev, struct xhci_container_ctx *ctx)
 	kfree(ctx);
 }
 
+/* we use only one segment for DbC rings */
+static void dbc_ring_free(struct device *dev, struct xhci_ring *ring)
+{
+	if (!ring)
+		return;
+
+	if (ring->first_seg && ring->first_seg->trbs) {
+		dma_free_coherent(dev, TRB_SEGMENT_SIZE,
+				  ring->first_seg->trbs,
+				  ring->first_seg->dma);
+		kfree(ring->first_seg);
+	}
+	kfree(ring);
+}
+
 static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
 {
 	struct usb_string_descriptor	*s_desc;
@@ -391,6 +406,51 @@ dbc_alloc_ctx(struct device *dev, gfp_t flags)
 	return ctx;
 }
 
+struct xhci_ring *
+xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
+{
+	struct xhci_ring *ring;
+	struct xhci_segment *seg;
+	dma_addr_t dma;
+
+	ring = kzalloc(sizeof(*ring), flags);
+	if (!ring)
+		return NULL;
+
+	ring->num_segs = 1;
+	ring->type = type;
+
+	seg = kzalloc(sizeof(*seg), flags);
+	if (!seg)
+		goto seg_fail;
+
+	ring->first_seg = seg;
+	ring->last_seg = seg;
+	seg->next = seg;
+
+	seg->trbs = dma_alloc_coherent(dev, TRB_SEGMENT_SIZE, &dma, flags);
+	if (!seg->trbs)
+		goto dma_fail;
+
+	seg->dma = dma;
+
+	/* Only event ring does not use link TRB */
+	if (type != TYPE_EVENT) {
+		union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1];
+
+		trb->link.segment_ptr = cpu_to_le64(dma);
+		trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK));
+	}
+	INIT_LIST_HEAD(&ring->td_list);
+	xhci_initialize_ring_info(ring, 1);
+	return ring;
+dma_fail:
+	kfree(seg);
+seg_fail:
+	kfree(ring);
+	return NULL;
+}
+
 static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 {
 	int			ret;
@@ -400,15 +460,15 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	struct device		*dev = xhci_to_hcd(xhci)->self.controller;
 
 	/* Allocate various rings for events and transfers: */
-	dbc->ring_evt = xhci_ring_alloc(xhci, 1, 1, TYPE_EVENT, 0, flags);
+	dbc->ring_evt = xhci_dbc_ring_alloc(dev, TYPE_EVENT, flags);
 	if (!dbc->ring_evt)
 		goto evt_fail;
 
-	dbc->ring_in = xhci_ring_alloc(xhci, 1, 1, TYPE_BULK, 0, flags);
+	dbc->ring_in = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags);
 	if (!dbc->ring_in)
 		goto in_fail;
 
-	dbc->ring_out = xhci_ring_alloc(xhci, 1, 1, TYPE_BULK, 0, flags);
+	dbc->ring_out = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags);
 	if (!dbc->ring_out)
 		goto out_fail;
 
@@ -452,13 +512,13 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 ctx_fail:
 	dbc_erst_free(dev, &dbc->erst);
 erst_fail:
-	xhci_ring_free(xhci, dbc->ring_out);
+	dbc_ring_free(dev, dbc->ring_out);
 	dbc->ring_out = NULL;
 out_fail:
-	xhci_ring_free(xhci, dbc->ring_in);
+	dbc_ring_free(dev, dbc->ring_in);
 	dbc->ring_in = NULL;
 in_fail:
-	xhci_ring_free(xhci, dbc->ring_evt);
+	dbc_ring_free(dev, dbc->ring_evt);
 	dbc->ring_evt = NULL;
 evt_fail:
 	return -ENOMEM;
@@ -483,10 +543,10 @@ static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
 	dbc_free_ctx(dbc->dev, dbc->ctx);
 	dbc->ctx = NULL;
 
-	dbc_erst_free(dev, &dbc->erst);
-	xhci_ring_free(xhci, dbc->ring_out);
-	xhci_ring_free(xhci, dbc->ring_in);
-	xhci_ring_free(xhci, dbc->ring_evt);
+	dbc_erst_free(dbc->dev, &dbc->erst);
+	dbc_ring_free(dbc->dev, dbc->ring_out);
+	dbc_ring_free(dbc->dev, dbc->ring_in);
+	dbc_ring_free(dbc->dev, dbc->ring_evt);
 	dbc->ring_in = NULL;
 	dbc->ring_out = NULL;
 	dbc->ring_evt = NULL;
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d38779e2fc84..696fad50b478 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -293,8 +293,8 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
 	kfree(ring);
 }
 
-static void xhci_initialize_ring_info(struct xhci_ring *ring,
-					unsigned int cycle_state)
+void xhci_initialize_ring_info(struct xhci_ring *ring,
+			       unsigned int cycle_state)
 {
 	/* The ring is empty, so the enqueue pointer == dequeue pointer */
 	ring->enqueue = ring->first_seg->trbs;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index c295e8a7f5ae..ea1754f185a2 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2015,6 +2015,8 @@ int xhci_alloc_erst(struct xhci_hcd *xhci,
 		struct xhci_ring *evt_ring,
 		struct xhci_erst *erst,
 		gfp_t flags);
+void xhci_initialize_ring_info(struct xhci_ring *ring,
+			unsigned int cycle_state);
 void xhci_free_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
 void xhci_free_endpoint_ring(struct xhci_hcd *xhci,
 		struct xhci_virt_device *virt_dev,
-- 
2.17.1


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

* [PATCH 20/27] xhci: dbc: Pass dbc pointer to dbc memory init and cleanup functions
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (18 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 19/27] xhci: dbc: don't use generic xhci ring allocation functions " Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 21/27] xhci: dbc: Pass dbc pointer to dbc start and stop functions Mathias Nyman
                   ` (7 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Dbc mem_init and mem_cleanup functions used xhci_hcd to get to the device
pointer. The device pointer can be accessed directly from dbc structure,
so pass a pointer to dbc as a parameter instead.

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index b00cbff5e2ca..626635f26658 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -451,13 +451,12 @@ xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
 	return NULL;
 }
 
-static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
+static int xhci_dbc_mem_init(struct xhci_dbc *dbc, gfp_t flags)
 {
 	int			ret;
 	dma_addr_t		deq;
 	u32			string_length;
-	struct xhci_dbc		*dbc = xhci->dbc;
-	struct device		*dev = xhci_to_hcd(xhci)->self.controller;
+	struct device		*dev = dbc->dev;
 
 	/* Allocate various rings for events and transfers: */
 	dbc->ring_evt = xhci_dbc_ring_alloc(dev, TYPE_EVENT, flags);
@@ -524,11 +523,8 @@ static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	return -ENOMEM;
 }
 
-static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
+static void xhci_dbc_mem_cleanup(struct xhci_dbc *dbc)
 {
-	struct xhci_dbc		*dbc = xhci->dbc;
-	struct device		*dev = xhci_to_hcd(xhci)->self.controller;
-
 	if (!dbc)
 		return;
 
@@ -568,7 +564,7 @@ static int xhci_do_dbc_start(struct xhci_hcd *xhci)
 	if (ret)
 		return ret;
 
-	ret = xhci_dbc_mem_init(xhci, GFP_ATOMIC);
+	ret = xhci_dbc_mem_init(dbc, GFP_ATOMIC);
 	if (ret)
 		return ret;
 
@@ -638,7 +634,7 @@ static void xhci_dbc_stop(struct xhci_hcd *xhci)
 	spin_unlock_irqrestore(&dbc->lock, flags);
 
 	if (!ret) {
-		xhci_dbc_mem_cleanup(xhci);
+		xhci_dbc_mem_cleanup(dbc);
 		pm_runtime_put_sync(xhci_to_hcd(xhci)->self.controller);
 	}
 }
-- 
2.17.1


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

* [PATCH 21/27] xhci: dbc: Pass dbc pointer to dbc start and stop functions.
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (19 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 20/27] xhci: dbc: Pass dbc pointer to dbc memory init and cleanup functions Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 22/27] xhci: dbc: simplify dbc requests allocation and queueing Mathias Nyman
                   ` (6 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

xhci_dbc_start() and xhci_dbc_stop() functions only used xhci_hcd pointer
to get the dbc pointer.
Pass the dbc pointer instead of the xhci_hcd pointer as a parameter

No functional changes
This change helps decoupling xhci and DbC

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 626635f26658..af6e3622e53a 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -548,11 +548,10 @@ static void xhci_dbc_mem_cleanup(struct xhci_dbc *dbc)
 	dbc->ring_evt = NULL;
 }
 
-static int xhci_do_dbc_start(struct xhci_hcd *xhci)
+static int xhci_do_dbc_start(struct xhci_dbc *dbc)
 {
 	int			ret;
 	u32			ctrl;
-	struct xhci_dbc		*dbc = xhci->dbc;
 
 	if (dbc->state != DS_DISABLED)
 		return -EINVAL;
@@ -593,33 +592,31 @@ static int xhci_do_dbc_stop(struct xhci_dbc *dbc)
 	return 0;
 }
 
-static int xhci_dbc_start(struct xhci_hcd *xhci)
+static int xhci_dbc_start(struct xhci_dbc *dbc)
 {
 	int			ret;
 	unsigned long		flags;
-	struct xhci_dbc		*dbc = xhci->dbc;
 
 	WARN_ON(!dbc);
 
-	pm_runtime_get_sync(xhci_to_hcd(xhci)->self.controller);
+	pm_runtime_get_sync(dbc->dev); /* note this was self.controller */
 
 	spin_lock_irqsave(&dbc->lock, flags);
-	ret = xhci_do_dbc_start(xhci);
+	ret = xhci_do_dbc_start(dbc);
 	spin_unlock_irqrestore(&dbc->lock, flags);
 
 	if (ret) {
-		pm_runtime_put(xhci_to_hcd(xhci)->self.controller);
+		pm_runtime_put(dbc->dev); /* note this was self.controller */
 		return ret;
 	}
 
 	return mod_delayed_work(system_wq, &dbc->event_work, 1);
 }
 
-static void xhci_dbc_stop(struct xhci_hcd *xhci)
+static void xhci_dbc_stop(struct xhci_dbc *dbc)
 {
 	int ret;
 	unsigned long		flags;
-	struct xhci_dbc		*dbc = xhci->dbc;
 	struct dbc_port		*port = &dbc->port;
 
 	WARN_ON(!dbc);
@@ -635,7 +632,7 @@ static void xhci_dbc_stop(struct xhci_hcd *xhci)
 
 	if (!ret) {
 		xhci_dbc_mem_cleanup(dbc);
-		pm_runtime_put_sync(xhci_to_hcd(xhci)->self.controller);
+		pm_runtime_put_sync(dbc->dev); /* note, was self.controller */
 	}
 }
 
@@ -996,13 +993,15 @@ static ssize_t dbc_store(struct device *dev,
 			 const char *buf, size_t count)
 {
 	struct xhci_hcd		*xhci;
+	struct xhci_dbc		*dbc;
 
 	xhci = hcd_to_xhci(dev_get_drvdata(dev));
+	dbc = xhci->dbc;
 
 	if (!strncmp(buf, "enable", 6))
-		xhci_dbc_start(xhci);
+		xhci_dbc_start(dbc);
 	else if (!strncmp(buf, "disable", 7))
-		xhci_dbc_stop(xhci);
+		xhci_dbc_stop(dbc);
 	else
 		return -EINVAL;
 
@@ -1047,7 +1046,7 @@ void xhci_dbc_exit(struct xhci_hcd *xhci)
 
 	device_remove_file(dev, &dev_attr_dbc);
 	xhci_dbc_tty_unregister_driver();
-	xhci_dbc_stop(xhci);
+	xhci_dbc_stop(xhci->dbc);
 	xhci_do_dbc_exit(xhci);
 }
 
@@ -1062,7 +1061,7 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci)
 	if (dbc->state == DS_CONFIGURED)
 		dbc->resume_required = 1;
 
-	xhci_dbc_stop(xhci);
+	xhci_dbc_stop(dbc);
 
 	return 0;
 }
@@ -1077,7 +1076,7 @@ int xhci_dbc_resume(struct xhci_hcd *xhci)
 
 	if (dbc->resume_required) {
 		dbc->resume_required = 0;
-		xhci_dbc_start(xhci);
+		xhci_dbc_start(dbc);
 	}
 
 	return ret;
-- 
2.17.1


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

* [PATCH 22/27] xhci: dbc: simplify dbc requests allocation and queueing
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (20 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 21/27] xhci: dbc: Pass dbc pointer to dbc start and stop functions Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 23/27] xhci: dbc: remove endpoint pointers from dbc_port structure Mathias Nyman
                   ` (5 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Don't pass endpoint pointer, dbctty should not be aware of
struct dbc_ep, knowing the direction is enough.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 43 ++++++++++++++++++++++------------
 drivers/usb/host/xhci-dbgcap.h | 12 ++++++----
 drivers/usb/host/xhci-dbgtty.c | 33 +++++++++++++-------------
 3 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index af6e3622e53a..e3eec628edb5 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -135,8 +135,7 @@ static void xhci_dbc_giveback(struct dbc_request *req, int status)
 	__releases(&dbc->lock)
 	__acquires(&dbc->lock)
 {
-	struct dbc_ep		*dep = req->dep;
-	struct xhci_dbc		*dbc = dep->dbc;
+	struct xhci_dbc		*dbc = req->dbc;
 	struct device		*dev = dbc->dev;
 
 	list_del_init(&req->list_pending);
@@ -151,7 +150,7 @@ static void xhci_dbc_giveback(struct dbc_request *req, int status)
 	dma_unmap_single(dev,
 			 req->dma,
 			 req->length,
-			 dbc_ep_dma_direction(dep));
+			 dbc_ep_dma_direction(req));
 
 	/* Give back the transfer request: */
 	spin_unlock(&dbc->lock);
@@ -187,18 +186,25 @@ static void xhci_dbc_flush_requests(struct xhci_dbc *dbc)
 }
 
 struct dbc_request *
-dbc_alloc_request(struct dbc_ep *dep, gfp_t gfp_flags)
+dbc_alloc_request(struct xhci_dbc *dbc, unsigned int direction, gfp_t flags)
 {
 	struct dbc_request	*req;
 
-	req = kzalloc(sizeof(*req), gfp_flags);
+	if (direction != BULK_IN &&
+	    direction != BULK_OUT)
+		return NULL;
+
+	if (!dbc)
+		return NULL;
+
+	req = kzalloc(sizeof(*req), flags);
 	if (!req)
 		return NULL;
 
-	req->dep = dep;
+	req->dbc = dbc;
 	INIT_LIST_HEAD(&req->list_pending);
 	INIT_LIST_HEAD(&req->list_pool);
-	req->direction = dep->direction;
+	req->direction = direction;
 
 	trace_xhci_dbc_alloc_request(req);
 
@@ -206,7 +212,7 @@ dbc_alloc_request(struct dbc_ep *dep, gfp_t gfp_flags)
 }
 
 void
-dbc_free_request(struct dbc_ep *dep, struct dbc_request *req)
+dbc_free_request(struct dbc_request *req)
 {
 	trace_xhci_dbc_free_request(req);
 
@@ -242,7 +248,7 @@ static int xhci_dbc_queue_bulk_tx(struct dbc_ep *dep,
 	u64			addr;
 	union xhci_trb		*trb;
 	unsigned int		num_trbs;
-	struct xhci_dbc		*dbc = dep->dbc;
+	struct xhci_dbc		*dbc = req->dbc;
 	struct xhci_ring	*ring = dep->ring;
 	u32			length, control, cycle;
 
@@ -286,11 +292,12 @@ static int xhci_dbc_queue_bulk_tx(struct dbc_ep *dep,
 }
 
 static int
-dbc_ep_do_queue(struct dbc_ep *dep, struct dbc_request *req)
+dbc_ep_do_queue(struct dbc_request *req)
 {
 	int			ret;
-	struct xhci_dbc		*dbc = dep->dbc;
+	struct xhci_dbc		*dbc = req->dbc;
 	struct device		*dev = dbc->dev;
+	struct dbc_ep		*dep = &dbc->eps[req->direction];
 
 	if (!req->length || !req->buf)
 		return -EINVAL;
@@ -322,16 +329,22 @@ dbc_ep_do_queue(struct dbc_ep *dep, struct dbc_request *req)
 	return 0;
 }
 
-int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req,
-		 gfp_t gfp_flags)
+int dbc_ep_queue(struct dbc_request *req)
 {
 	unsigned long		flags;
-	struct xhci_dbc		*dbc = dep->dbc;
+	struct xhci_dbc		*dbc = req->dbc;
 	int			ret = -ESHUTDOWN;
 
+	if (!dbc)
+		return -ENODEV;
+
+	if (req->direction != BULK_IN &&
+	    req->direction != BULK_OUT)
+		return -EINVAL;
+
 	spin_lock_irqsave(&dbc->lock, flags);
 	if (dbc->state == DS_CONFIGURED)
-		ret = dbc_ep_do_queue(dep, req);
+		ret = dbc_ep_do_queue(req);
 	spin_unlock_irqrestore(&dbc->lock, flags);
 
 	mod_delayed_work(system_wq, &dbc->event_work, 0);
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 9e3c5940f27b..fe360cf712c1 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -88,7 +88,7 @@ struct dbc_ep {
 	struct xhci_dbc			*dbc;
 	struct list_head		list_pending;
 	struct xhci_ring		*ring;
-	unsigned			direction:1;
+	unsigned int			direction:1;
 };
 
 #define DBC_QUEUE_SIZE			16
@@ -147,7 +147,7 @@ struct dbc_request {
 	int				status;
 	unsigned int			actual;
 
-	struct dbc_ep			*dep;
+	struct xhci_dbc			*dbc;
 	struct list_head		list_pending;
 	dma_addr_t			trb_dma;
 	union xhci_trb			*trb;
@@ -196,9 +196,11 @@ int xhci_dbc_tty_register_driver(struct xhci_hcd *xhci);
 void xhci_dbc_tty_unregister_driver(void);
 int xhci_dbc_tty_register_device(struct xhci_dbc *dbc);
 void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc);
-struct dbc_request *dbc_alloc_request(struct dbc_ep *dep, gfp_t gfp_flags);
-void dbc_free_request(struct dbc_ep *dep, struct dbc_request *req);
-int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req, gfp_t gfp_flags);
+struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
+				      unsigned int direction,
+				      gfp_t flags);
+void dbc_free_request(struct dbc_request *req);
+int dbc_ep_queue(struct dbc_request *req);
 #ifdef CONFIG_PM
 int xhci_dbc_suspend(struct xhci_hcd *xhci);
 int xhci_dbc_resume(struct xhci_hcd *xhci);
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 967f0419dad7..9886d42e1ff2 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -48,7 +48,7 @@ static int dbc_start_tx(struct dbc_port *port)
 		list_del(&req->list_pool);
 
 		spin_unlock(&port->port_lock);
-		status = dbc_ep_queue(port->out, req, GFP_ATOMIC);
+		status = dbc_ep_queue(req);
 		spin_lock(&port->port_lock);
 
 		if (status) {
@@ -80,7 +80,7 @@ static void dbc_start_rx(struct dbc_port *port)
 		req->length = DBC_MAX_PACKET;
 
 		spin_unlock(&port->port_lock);
-		status = dbc_ep_queue(port->in, req, GFP_ATOMIC);
+		status = dbc_ep_queue(req);
 		spin_lock(&port->port_lock);
 
 		if (status) {
@@ -123,28 +123,29 @@ static void dbc_write_complete(struct xhci_dbc *dbc, struct dbc_request *req)
 	spin_unlock_irqrestore(&port->port_lock, flags);
 }
 
-static void xhci_dbc_free_req(struct dbc_ep *dep, struct dbc_request *req)
+static void xhci_dbc_free_req(struct dbc_request *req)
 {
 	kfree(req->buf);
-	dbc_free_request(dep, req);
+	dbc_free_request(req);
 }
 
 static int
-xhci_dbc_alloc_requests(struct dbc_ep *dep, struct list_head *head,
+xhci_dbc_alloc_requests(struct xhci_dbc *dbc, unsigned int direction,
+			struct list_head *head,
 			void (*fn)(struct xhci_dbc *, struct dbc_request *))
 {
 	int			i;
 	struct dbc_request	*req;
 
 	for (i = 0; i < DBC_QUEUE_SIZE; i++) {
-		req = dbc_alloc_request(dep, GFP_KERNEL);
+		req = dbc_alloc_request(dbc, direction, GFP_KERNEL);
 		if (!req)
 			break;
 
 		req->length = DBC_MAX_PACKET;
 		req->buf = kmalloc(req->length, GFP_KERNEL);
 		if (!req->buf) {
-			dbc_free_request(dep, req);
+			dbc_free_request(req);
 			break;
 		}
 
@@ -156,14 +157,14 @@ xhci_dbc_alloc_requests(struct dbc_ep *dep, struct list_head *head,
 }
 
 static void
-xhci_dbc_free_requests(struct dbc_ep *dep, struct list_head *head)
+xhci_dbc_free_requests(struct list_head *head)
 {
 	struct dbc_request	*req;
 
 	while (!list_empty(head)) {
 		req = list_entry(head->next, struct dbc_request, list_pool);
 		list_del(&req->list_pool);
-		xhci_dbc_free_req(dep, req);
+		xhci_dbc_free_req(req);
 	}
 }
 
@@ -456,12 +457,12 @@ int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
 	if (ret)
 		goto buf_alloc_fail;
 
-	ret = xhci_dbc_alloc_requests(port->in, &port->read_pool,
+	ret = xhci_dbc_alloc_requests(dbc, BULK_IN, &port->read_pool,
 				      dbc_read_complete);
 	if (ret)
 		goto request_fail;
 
-	ret = xhci_dbc_alloc_requests(port->out, &port->write_pool,
+	ret = xhci_dbc_alloc_requests(dbc, BULK_OUT, &port->write_pool,
 				      dbc_write_complete);
 	if (ret)
 		goto request_fail;
@@ -471,8 +472,8 @@ int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
 	return 0;
 
 request_fail:
-	xhci_dbc_free_requests(port->in, &port->read_pool);
-	xhci_dbc_free_requests(port->out, &port->write_pool);
+	xhci_dbc_free_requests(&port->read_pool);
+	xhci_dbc_free_requests(&port->write_pool);
 	kfifo_free(&port->write_fifo);
 
 buf_alloc_fail:
@@ -495,7 +496,7 @@ void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 	port->registered = false;
 
 	kfifo_free(&port->write_fifo);
-	xhci_dbc_free_requests(get_out_ep(dbc), &port->read_pool);
-	xhci_dbc_free_requests(get_out_ep(dbc), &port->read_queue);
-	xhci_dbc_free_requests(get_in_ep(dbc), &port->write_pool);
+	xhci_dbc_free_requests(&port->read_pool);
+	xhci_dbc_free_requests(&port->read_queue);
+	xhci_dbc_free_requests(&port->write_pool);
 }
-- 
2.17.1


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

* [PATCH 23/27] xhci: dbc: remove endpoint pointers from dbc_port structure
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (21 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 22/27] xhci: dbc: simplify dbc requests allocation and queueing Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 24/27] xhci: dbctty: split dbc tty driver registration and unregistration functions Mathias Nyman
                   ` (4 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

dbctty no longer needs references directly to dbc endpoints,
so remove them

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.h | 2 --
 drivers/usb/host/xhci-dbgtty.c | 2 --
 2 files changed, 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index fe360cf712c1..796cf2808be8 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -110,8 +110,6 @@ struct dbc_port {
 	struct kfifo			write_fifo;
 
 	bool				registered;
-	struct dbc_ep			*in;
-	struct dbc_ep			*out;
 };
 
 struct xhci_dbc {
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 9886d42e1ff2..ab2b82aa04be 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -426,8 +426,6 @@ xhci_dbc_tty_init_port(struct xhci_dbc *dbc, struct dbc_port *port)
 	INIT_LIST_HEAD(&port->read_queue);
 	INIT_LIST_HEAD(&port->write_pool);
 
-	port->in =		get_in_ep(dbc);
-	port->out =		get_out_ep(dbc);
 	port->port.ops =	&dbc_port_ops;
 	port->n_read =		0;
 }
-- 
2.17.1


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

* [PATCH 24/27] xhci: dbctty: split dbc tty driver registration and unregistration functions.
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (22 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 23/27] xhci: dbc: remove endpoint pointers from dbc_port structure Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 25/27] xhci: dbc: Add a operations structure to access driver functions Mathias Nyman
                   ` (3 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Split the dbc tty driver registrations function into separate
init and probe parts.

The init part will register the tty driver, and should in the future be
called from module_init().
The probe part will become the normal probe function, but for now it is
called from the init part.

The unregister function is s likewise split into remove and exit parts.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c |   6 +-
 drivers/usb/host/xhci-dbgcap.h |   4 +-
 drivers/usb/host/xhci-dbgtty.c | 125 ++++++++++++++++++++-------------
 3 files changed, 81 insertions(+), 54 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index e3eec628edb5..99f0b425274a 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -1032,7 +1032,7 @@ int xhci_dbc_init(struct xhci_hcd *xhci)
 	if (ret)
 		goto init_err3;
 
-	ret = xhci_dbc_tty_register_driver(xhci);
+	ret = xhci_dbc_tty_probe(xhci);
 	if (ret)
 		goto init_err2;
 
@@ -1043,7 +1043,7 @@ int xhci_dbc_init(struct xhci_hcd *xhci)
 	return 0;
 
 init_err1:
-	xhci_dbc_tty_unregister_driver();
+	xhci_dbc_tty_remove(xhci->dbc);
 init_err2:
 	xhci_do_dbc_exit(xhci);
 init_err3:
@@ -1058,7 +1058,7 @@ void xhci_dbc_exit(struct xhci_hcd *xhci)
 		return;
 
 	device_remove_file(dev, &dev_attr_dbc);
-	xhci_dbc_tty_unregister_driver();
+	xhci_dbc_tty_remove(xhci->dbc);
 	xhci_dbc_stop(xhci->dbc);
 	xhci_do_dbc_exit(xhci);
 }
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 796cf2808be8..e4c7c9279ea8 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -190,8 +190,8 @@ static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc)
 #ifdef CONFIG_USB_XHCI_DBGCAP
 int xhci_dbc_init(struct xhci_hcd *xhci);
 void xhci_dbc_exit(struct xhci_hcd *xhci);
-int xhci_dbc_tty_register_driver(struct xhci_hcd *xhci);
-void xhci_dbc_tty_unregister_driver(void);
+int xhci_dbc_tty_probe(struct xhci_hcd *xhci);
+void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
 int xhci_dbc_tty_register_device(struct xhci_dbc *dbc);
 void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc);
 struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index ab2b82aa04be..9acf1efba36c 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -14,6 +14,11 @@
 #include "xhci.h"
 #include "xhci-dbgcap.h"
 
+static int dbc_tty_init(void);
+static void dbc_tty_exit(void);
+
+static struct tty_driver *dbc_tty_driver;
+
 static unsigned int
 dbc_send_packet(struct dbc_port *port, char *packet, unsigned int size)
 {
@@ -278,55 +283,6 @@ static const struct tty_operations dbc_tty_ops = {
 	.unthrottle		= dbc_tty_unthrottle,
 };
 
-static struct tty_driver *dbc_tty_driver;
-
-int xhci_dbc_tty_register_driver(struct xhci_hcd *xhci)
-{
-	int			status;
-	struct xhci_dbc		*dbc = xhci->dbc;
-
-	dbc_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW |
-					  TTY_DRIVER_DYNAMIC_DEV);
-	if (IS_ERR(dbc_tty_driver)) {
-		status = PTR_ERR(dbc_tty_driver);
-		dbc_tty_driver = NULL;
-		return status;
-	}
-
-	dbc_tty_driver->driver_name = "dbc_serial";
-	dbc_tty_driver->name = "ttyDBC";
-
-	dbc_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
-	dbc_tty_driver->subtype = SERIAL_TYPE_NORMAL;
-	dbc_tty_driver->init_termios = tty_std_termios;
-	dbc_tty_driver->init_termios.c_cflag =
-			B9600 | CS8 | CREAD | HUPCL | CLOCAL;
-	dbc_tty_driver->init_termios.c_ispeed = 9600;
-	dbc_tty_driver->init_termios.c_ospeed = 9600;
-	dbc_tty_driver->driver_state = &dbc->port;
-
-	tty_set_operations(dbc_tty_driver, &dbc_tty_ops);
-
-	status = tty_register_driver(dbc_tty_driver);
-	if (status) {
-		xhci_err(xhci,
-			 "can't register dbc tty driver, err %d\n", status);
-		put_tty_driver(dbc_tty_driver);
-		dbc_tty_driver = NULL;
-	}
-
-	return status;
-}
-
-void xhci_dbc_tty_unregister_driver(void)
-{
-	if (dbc_tty_driver) {
-		tty_unregister_driver(dbc_tty_driver);
-		put_tty_driver(dbc_tty_driver);
-		dbc_tty_driver = NULL;
-	}
-}
-
 static void dbc_rx_push(unsigned long _port)
 {
 	struct dbc_request	*req;
@@ -498,3 +454,74 @@ void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 	xhci_dbc_free_requests(&port->read_queue);
 	xhci_dbc_free_requests(&port->write_pool);
 }
+
+int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
+{
+	struct xhci_dbc		*dbc = xhci->dbc;
+	int			status;
+
+	/* dbc_tty_init will be called by module init() in the future */
+	status = dbc_tty_init();
+	if (status)
+		return status;
+
+	dbc_tty_driver->driver_state = &dbc->port;
+
+	return 0;
+out:
+
+	/* dbc_tty_exit will be called by module_exit() in the future */
+	dbc_tty_exit();
+	return status;
+}
+
+/*
+ * undo what probe did, assume dbc is stopped already.
+ * we also assume tty_unregister_device() is called before this
+ */
+void xhci_dbc_tty_remove(struct xhci_dbc *dbc)
+{
+	/* dbc_tty_exit will be called by  module_exit() in the future */
+	dbc_tty_exit();
+}
+
+static int dbc_tty_init(void)
+{
+	int		ret;
+
+	dbc_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW |
+					  TTY_DRIVER_DYNAMIC_DEV);
+	if (IS_ERR(dbc_tty_driver))
+		return PTR_ERR(dbc_tty_driver);
+
+	dbc_tty_driver->driver_name = "dbc_serial";
+	dbc_tty_driver->name = "ttyDBC";
+
+	dbc_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
+	dbc_tty_driver->subtype = SERIAL_TYPE_NORMAL;
+	dbc_tty_driver->init_termios = tty_std_termios;
+	dbc_tty_driver->init_termios.c_cflag =
+			B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+	dbc_tty_driver->init_termios.c_ispeed = 9600;
+	dbc_tty_driver->init_termios.c_ospeed = 9600;
+
+	tty_set_operations(dbc_tty_driver, &dbc_tty_ops);
+
+	ret = tty_register_driver(dbc_tty_driver);
+	if (ret) {
+		pr_err("Can't register dbc tty driver\n");
+		put_tty_driver(dbc_tty_driver);
+	}
+	return ret;
+}
+
+static void dbc_tty_exit(void)
+{
+	if (dbc_tty_driver) {
+		tty_unregister_driver(dbc_tty_driver);
+		put_tty_driver(dbc_tty_driver);
+		dbc_tty_driver = NULL;
+	}
+}
+
+
-- 
2.17.1


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

* [PATCH 25/27] xhci: dbc: Add a operations structure to access driver functions
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (23 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 24/27] xhci: dbctty: split dbc tty driver registration and unregistration functions Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 26/27] xhci: dbgcap: remove dbc dependency on dbctty specific flag Mathias Nyman
                   ` (2 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Don't call dbctty driver functions directly from dbc core code.
Introduce a new dbc_driver structure that contains function pointers
for disconnect and configure operations.

The driver (ttydbc) must provide these opeations when creating a dbc.

Name the structure dbc_driver instead of dbc_ops as we plan to
add more driver configureable values here, such as vid and pid.

Decouples dbc and dbctty.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 17 ++++++-----------
 drivers/usb/host/xhci-dbgcap.h |  8 ++++++--
 drivers/usb/host/xhci-dbgtty.c | 11 +++++++++--
 3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 99f0b425274a..47090bceae21 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -636,8 +636,8 @@ static void xhci_dbc_stop(struct xhci_dbc *dbc)
 
 	cancel_delayed_work_sync(&dbc->event_work);
 
-	if (port->registered)
-		xhci_dbc_tty_unregister_device(dbc);
+	if (port->registered && dbc->driver->disconnect)
+		dbc->driver->disconnect(dbc);
 
 	spin_lock_irqsave(&dbc->lock, flags);
 	ret = xhci_do_dbc_stop(dbc);
@@ -877,7 +877,6 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 
 static void xhci_dbc_handle_events(struct work_struct *work)
 {
-	int			ret;
 	enum evtreturn		evtr;
 	struct xhci_dbc		*dbc;
 	unsigned long		flags;
@@ -890,16 +889,12 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 
 	switch (evtr) {
 	case EVT_GSER:
-		ret = xhci_dbc_tty_register_device(dbc);
-		if (ret) {
-			dev_err(dbc->dev, "failed to alloc tty device\n");
-			break;
-		}
-
-		dev_info(dbc->dev, "DbC now attached to /dev/ttyDBC0\n");
+		if (dbc->driver->configure)
+			dbc->driver->configure(dbc);
 		break;
 	case EVT_DISC:
-		xhci_dbc_tty_unregister_device(dbc);
+		if (dbc->driver->disconnect)
+			dbc->driver->disconnect(dbc);
 		break;
 	case EVT_DONE:
 		break;
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index e4c7c9279ea8..5018b32fc742 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -112,6 +112,11 @@ struct dbc_port {
 	bool				registered;
 };
 
+struct dbc_driver {
+	int (*configure)(struct xhci_dbc *dbc);
+	void (*disconnect)(struct xhci_dbc *dbc);
+};
+
 struct xhci_dbc {
 	spinlock_t			lock;		/* device access */
 	struct device			*dev;
@@ -133,6 +138,7 @@ struct xhci_dbc {
 	struct dbc_ep			eps[2];
 
 	struct dbc_port			port;
+	const struct dbc_driver		*driver;
 };
 
 struct dbc_request {
@@ -192,8 +198,6 @@ int xhci_dbc_init(struct xhci_hcd *xhci);
 void xhci_dbc_exit(struct xhci_hcd *xhci);
 int xhci_dbc_tty_probe(struct xhci_hcd *xhci);
 void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
-int xhci_dbc_tty_register_device(struct xhci_dbc *dbc);
-void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc);
 struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
 				      unsigned int direction,
 				      gfp_t flags);
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 9acf1efba36c..3231cec74a7a 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -455,6 +455,11 @@ void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 	xhci_dbc_free_requests(&port->write_pool);
 }
 
+static const struct dbc_driver dbc_driver = {
+	.configure		= xhci_dbc_tty_register_device,
+	.disconnect		= xhci_dbc_tty_unregister_device,
+};
+
 int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
 {
 	struct xhci_dbc		*dbc = xhci->dbc;
@@ -465,6 +470,8 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
 	if (status)
 		return status;
 
+	dbc->driver = &dbc_driver;
+
 	dbc_tty_driver->driver_state = &dbc->port;
 
 	return 0;
@@ -481,6 +488,8 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
  */
 void xhci_dbc_tty_remove(struct xhci_dbc *dbc)
 {
+	dbc->driver = NULL;
+
 	/* dbc_tty_exit will be called by  module_exit() in the future */
 	dbc_tty_exit();
 }
@@ -523,5 +532,3 @@ static void dbc_tty_exit(void)
 		dbc_tty_driver = NULL;
 	}
 }
-
-
-- 
2.17.1


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

* [PATCH 26/27] xhci: dbgcap: remove dbc dependency on dbctty specific flag
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (24 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 25/27] xhci: dbc: Add a operations structure to access driver functions Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 14:45 ` [PATCH 27/27] xhci: dbc: remove tty specific port structure from struct xhci_dbc Mathias Nyman
  2020-07-23 15:04 ` [PATCH 00/27] xhci features for usb-next Greg KH
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

dbc should not be aware of, or use any dbctty specific variables.
currenly dbc driver reads the port->registered flag to see if the
callbacks should be called.

Only makes these decisions based on dbc internal state instead.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 16 ++++++++++++----
 drivers/usb/host/xhci-dbgtty.c |  5 +++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 47090bceae21..c57178db7994 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -630,14 +630,22 @@ static void xhci_dbc_stop(struct xhci_dbc *dbc)
 {
 	int ret;
 	unsigned long		flags;
-	struct dbc_port		*port = &dbc->port;
 
 	WARN_ON(!dbc);
 
-	cancel_delayed_work_sync(&dbc->event_work);
+	switch (dbc->state) {
+	case DS_DISABLED:
+		return;
+	case DS_CONFIGURED:
+	case DS_STALLED:
+		if (dbc->driver->disconnect)
+			dbc->driver->disconnect(dbc);
+		break;
+	default:
+		break;
+	}
 
-	if (port->registered && dbc->driver->disconnect)
-		dbc->driver->disconnect(dbc);
+	cancel_delayed_work_sync(&dbc->event_work);
 
 	spin_lock_irqsave(&dbc->lock, flags);
 	ret = xhci_do_dbc_stop(dbc);
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 3231cec74a7a..3b306a22da47 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -399,6 +399,9 @@ int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
 	struct device		*tty_dev;
 	struct dbc_port		*port = &dbc->port;
 
+	if (port->registered)
+		return -EBUSY;
+
 	xhci_dbc_tty_init_port(dbc, port);
 	tty_dev = tty_port_register_device(&port->port,
 					   dbc_tty_driver, 0, NULL);
@@ -445,6 +448,8 @@ void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 {
 	struct dbc_port		*port = &dbc->port;
 
+	if (!port->registered)
+		return;
 	tty_unregister_device(dbc_tty_driver, 0);
 	xhci_dbc_tty_exit_port(port);
 	port->registered = false;
-- 
2.17.1


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

* [PATCH 27/27] xhci: dbc: remove tty specific port structure from struct xhci_dbc
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (25 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 26/27] xhci: dbgcap: remove dbc dependency on dbctty specific flag Mathias Nyman
@ 2020-07-23 14:45 ` Mathias Nyman
  2020-07-23 15:04 ` [PATCH 00/27] xhci features for usb-next Greg KH
  27 siblings, 0 replies; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 14:45 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, Mathias Nyman

Use a void pointer that any function driver can use instead.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.h |  2 +-
 drivers/usb/host/xhci-dbgtty.c | 29 +++++++++++++++++++++++------
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 5018b32fc742..c70b78d504eb 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -137,8 +137,8 @@ struct xhci_dbc {
 	unsigned			resume_required:1;
 	struct dbc_ep			eps[2];
 
-	struct dbc_port			port;
 	const struct dbc_driver		*driver;
+	void				*priv;
 };
 
 struct dbc_request {
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 3b306a22da47..0b942112b6f8 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -19,6 +19,11 @@ static void dbc_tty_exit(void);
 
 static struct tty_driver *dbc_tty_driver;
 
+static inline struct dbc_port *dbc_to_port(struct xhci_dbc *dbc)
+{
+	return dbc->priv;
+}
+
 static unsigned int
 dbc_send_packet(struct dbc_port *port, char *packet, unsigned int size)
 {
@@ -99,7 +104,7 @@ static void
 dbc_read_complete(struct xhci_dbc *dbc, struct dbc_request *req)
 {
 	unsigned long		flags;
-	struct dbc_port		*port = &dbc->port;
+	struct dbc_port		*port = dbc_to_port(dbc);
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	list_add_tail(&req->list_pool, &port->read_queue);
@@ -110,7 +115,7 @@ dbc_read_complete(struct xhci_dbc *dbc, struct dbc_request *req)
 static void dbc_write_complete(struct xhci_dbc *dbc, struct dbc_request *req)
 {
 	unsigned long		flags;
-	struct dbc_port		*port = &dbc->port;
+	struct dbc_port		*port = dbc_to_port(dbc);
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	list_add(&req->list_pool, &port->write_pool);
@@ -397,7 +402,7 @@ int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
 {
 	int			ret;
 	struct device		*tty_dev;
-	struct dbc_port		*port = &dbc->port;
+	struct dbc_port		*port = dbc_to_port(dbc);
 
 	if (port->registered)
 		return -EBUSY;
@@ -446,7 +451,7 @@ int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
 
 void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 {
-	struct dbc_port		*port = &dbc->port;
+	struct dbc_port		*port = dbc_to_port(dbc);
 
 	if (!port->registered)
 		return;
@@ -468,6 +473,7 @@ static const struct dbc_driver dbc_driver = {
 int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
 {
 	struct xhci_dbc		*dbc = xhci->dbc;
+	struct dbc_port		*port;
 	int			status;
 
 	/* dbc_tty_init will be called by module init() in the future */
@@ -475,13 +481,20 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
 	if (status)
 		return status;
 
+	port = kzalloc(sizeof(*port), GFP_KERNEL);
+	if (!port) {
+		status = -ENOMEM;
+		goto out;
+	}
+
 	dbc->driver = &dbc_driver;
+	dbc->priv = port;
+
 
-	dbc_tty_driver->driver_state = &dbc->port;
+	dbc_tty_driver->driver_state = port;
 
 	return 0;
 out:
-
 	/* dbc_tty_exit will be called by module_exit() in the future */
 	dbc_tty_exit();
 	return status;
@@ -493,7 +506,11 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
  */
 void xhci_dbc_tty_remove(struct xhci_dbc *dbc)
 {
+	struct dbc_port         *port = dbc_to_port(dbc);
+
 	dbc->driver = NULL;
+	dbc->priv = NULL;
+	kfree(port);
 
 	/* dbc_tty_exit will be called by  module_exit() in the future */
 	dbc_tty_exit();
-- 
2.17.1


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

* Re: [PATCH 00/27] xhci features for usb-next
  2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
                   ` (26 preceding siblings ...)
  2020-07-23 14:45 ` [PATCH 27/27] xhci: dbc: remove tty specific port structure from struct xhci_dbc Mathias Nyman
@ 2020-07-23 15:04 ` Greg KH
  2020-07-23 18:47   ` Mathias Nyman
  27 siblings, 1 reply; 33+ messages in thread
From: Greg KH @ 2020-07-23 15:04 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: linux-usb

On Thu, Jul 23, 2020 at 05:45:03PM +0300, Mathias Nyman wrote:
> Hi Greg
> 
> This series for usb-next is almost completely about decoupling and
> cleaning up relations between xhci, xhci debug capability (DbC),
> and the DbC tty support.
> 
> Real motivation behind this is to later turn DbC into a proper device
> allowing us to bind different drivers to it, like dbctty.

I don't really understand why you want to do that, but ok :)

What is that going to help with?

thanks,

greg k-h

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

* Re: [PATCH 00/27] xhci features for usb-next
  2020-07-23 15:04 ` [PATCH 00/27] xhci features for usb-next Greg KH
@ 2020-07-23 18:47   ` Mathias Nyman
  2020-07-24  7:06     ` Greg KH
  0 siblings, 1 reply; 33+ messages in thread
From: Mathias Nyman @ 2020-07-23 18:47 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb

On 23.7.2020 18.04, Greg KH wrote:
> On Thu, Jul 23, 2020 at 05:45:03PM +0300, Mathias Nyman wrote:
>> Hi Greg
>>
>> This series for usb-next is almost completely about decoupling and
>> cleaning up relations between xhci, xhci debug capability (DbC),
>> and the DbC tty support.
>>
>> Real motivation behind this is to later turn DbC into a proper device
>> allowing us to bind different drivers to it, like dbctty.
> 
> I don't really understand why you want to do that, but ok :)

Well to be fair loading different drivers for DbC isn't the only motivation.

Just using the Linux device model solves issues we are currently seeing 
when using DbC on systems with several xHCI controllers. The original DbC 
implementation didn't take this into account. 

And as a bigger picture DbC is just one extended capability. 
xHC controller provides a list of support extended capabilities, each one
with an ID and often a mmio region (inside xhci mmio range).
We don't handle these consistently in the xhci driver, for example
the role switch capability is currently turned into a platform device
while the DbC capability support is squashed all into the xhci driver.

Long term idea here would be to create a extended capability bus where each
capability is a device, (child of xhci device) and drivers for these match
based on the capability ID.

> 
> What is that going to help with?

The option to load other drivers for the DbC capability will help other
developers to write "standard" Linux drivers that provide different interfaces
than TTY to send data over DbC.

I don't fully understand these TTY limitations myself, but there is a strong push
to implement this, and the task to provide the infrastructure for this landed
on my table.

Thanks
-Mathias

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

* Re: [PATCH 00/27] xhci features for usb-next
  2020-07-23 18:47   ` Mathias Nyman
@ 2020-07-24  7:06     ` Greg KH
  2020-07-24 11:11       ` Mathias Nyman
  0 siblings, 1 reply; 33+ messages in thread
From: Greg KH @ 2020-07-24  7:06 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: linux-usb

On Thu, Jul 23, 2020 at 09:47:14PM +0300, Mathias Nyman wrote:
> On 23.7.2020 18.04, Greg KH wrote:
> > On Thu, Jul 23, 2020 at 05:45:03PM +0300, Mathias Nyman wrote:
> >> Hi Greg
> >>
> >> This series for usb-next is almost completely about decoupling and
> >> cleaning up relations between xhci, xhci debug capability (DbC),
> >> and the DbC tty support.
> >>
> >> Real motivation behind this is to later turn DbC into a proper device
> >> allowing us to bind different drivers to it, like dbctty.
> > 
> > I don't really understand why you want to do that, but ok :)
> 
> Well to be fair loading different drivers for DbC isn't the only motivation.
> 
> Just using the Linux device model solves issues we are currently seeing 
> when using DbC on systems with several xHCI controllers. The original DbC 
> implementation didn't take this into account. 

I thought when that was first merged no one cared :)

Nice to see that fixed here.

> And as a bigger picture DbC is just one extended capability. 
> xHC controller provides a list of support extended capabilities, each one
> with an ID and often a mmio region (inside xhci mmio range).
> We don't handle these consistently in the xhci driver, for example
> the role switch capability is currently turned into a platform device
> while the DbC capability support is squashed all into the xhci driver.
> 
> Long term idea here would be to create a extended capability bus where each
> capability is a device, (child of xhci device) and drivers for these match
> based on the capability ID.

Odd, but ok.

> > What is that going to help with?
> 
> The option to load other drivers for the DbC capability will help other
> developers to write "standard" Linux drivers that provide different interfaces
> than TTY to send data over DbC.
> 
> I don't fully understand these TTY limitations myself, but there is a strong push
> to implement this, and the task to provide the infrastructure for this landed
> on my table.

What other interface is asked for?  And yes, I would push back, what is
wrong with TTY here?  It should be the most "low overhead" interface
that works with common userspace tools that we have.

thanks,

greg k-h

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

* Re: [PATCH 00/27] xhci features for usb-next
  2020-07-24  7:06     ` Greg KH
@ 2020-07-24 11:11       ` Mathias Nyman
  2020-07-24 16:32         ` Greg KH
  0 siblings, 1 reply; 33+ messages in thread
From: Mathias Nyman @ 2020-07-24 11:11 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb

On 24.7.2020 10.06, Greg KH wrote:
> On Thu, Jul 23, 2020 at 09:47:14PM +0300, Mathias Nyman wrote:
>> On 23.7.2020 18.04, Greg KH wrote:
>>> On Thu, Jul 23, 2020 at 05:45:03PM +0300, Mathias Nyman wrote:
>>>> Hi Greg
>>>>
>>>> This series for usb-next is almost completely about decoupling and
>>>> cleaning up relations between xhci, xhci debug capability (DbC),
>>>> and the DbC tty support.
>>>>
>>>> Real motivation behind this is to later turn DbC into a proper device
>>>> allowing us to bind different drivers to it, like dbctty.
>>>
>>> I don't really understand why you want to do that, but ok :)
>>
>> Well to be fair loading different drivers for DbC isn't the only motivation.
>>
>> Just using the Linux device model solves issues we are currently seeing 
>> when using DbC on systems with several xHCI controllers. The original DbC 
>> implementation didn't take this into account. 
> 
> I thought when that was first merged no one cared :)
> 
> Nice to see that fixed here.
> 
>> And as a bigger picture DbC is just one extended capability. 
>> xHC controller provides a list of support extended capabilities, each one
>> with an ID and often a mmio region (inside xhci mmio range).
>> We don't handle these consistently in the xhci driver, for example
>> the role switch capability is currently turned into a platform device
>> while the DbC capability support is squashed all into the xhci driver.
>>
>> Long term idea here would be to create a extended capability bus where each
>> capability is a device, (child of xhci device) and drivers for these match
>> based on the capability ID.
> 
> Odd, but ok.

Suggestions and other approaches are welcome.

> 
>>> What is that going to help with?
>>
>> The option to load other drivers for the DbC capability will help other
>> developers to write "standard" Linux drivers that provide different interfaces
>> than TTY to send data over DbC.
>>
>> I don't fully understand these TTY limitations myself, but there is a strong push
>> to implement this, and the task to provide the infrastructure for this landed
>> on my table.
> 
> What other interface is asked for?  And yes, I would push back, what is
> wrong with TTY here?  It should be the most "low overhead" interface
> that works with common userspace tools that we have.

I've been asking the same questions about the TTY limitations.

Currently there's a driver providing a character device in development.
The developers are aware that they need to clarify and justify the need for a
new interface to get the driver upstream. My concerns and suggestions are noted.

As I don't understand these TTY limitations I'll have to let people publishing the
driver do this part. I expect that the driver will clarify things.

Anyway, I rather support them and work on providing the infrastructure needed 
to write such a driver, and give them the opportunity to implement whatever is needed.

Thanks
Mathias

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

* Re: [PATCH 00/27] xhci features for usb-next
  2020-07-24 11:11       ` Mathias Nyman
@ 2020-07-24 16:32         ` Greg KH
  0 siblings, 0 replies; 33+ messages in thread
From: Greg KH @ 2020-07-24 16:32 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: linux-usb

On Fri, Jul 24, 2020 at 02:11:44PM +0300, Mathias Nyman wrote:
> > What other interface is asked for?  And yes, I would push back, what is
> > wrong with TTY here?  It should be the most "low overhead" interface
> > that works with common userspace tools that we have.
> 
> I've been asking the same questions about the TTY limitations.
> 
> Currently there's a driver providing a character device in development.
> The developers are aware that they need to clarify and justify the need for a
> new interface to get the driver upstream. My concerns and suggestions are noted.
> 
> As I don't understand these TTY limitations I'll have to let people publishing the
> driver do this part. I expect that the driver will clarify things.
> 
> Anyway, I rather support them and work on providing the infrastructure needed 
> to write such a driver, and give them the opportunity to implement whatever is needed.

Don't add frameworks for no users.

Making this a char driver is not going to fly with me, I think I
remember seeing old patches that tried to do this in the past that were
submitted to some random Android kernel, and they just did not make any
sense.

It is easier to hide custom ioctls (i.e. custom syscalls) in a char
driver than it is in a tty driver, so don't fall into that trap :)

good luck!

greg k-h

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

end of thread, other threads:[~2020-07-24 16:32 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
2020-07-23 14:45 ` [PATCH 01/27] xhci: Make debug message consistent with bus and port number Mathias Nyman
2020-07-23 14:45 ` [PATCH 02/27] xhci: dbc: Don't use generic xhci inc_deq() function for dbc Mathias Nyman
2020-07-23 14:45 ` [PATCH 03/27] xhci: Don't pass struct xhci_hcd pointer to xhci_link_seg() Mathias Nyman
2020-07-23 14:45 ` [PATCH 04/27] xhci: dbc: Don't use generic xhci erst allocation and free functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 05/27] xhci: dbc: Remove dbc_dma_alloc_coherent() wrapper Mathias Nyman
2020-07-23 14:45 ` [PATCH 06/27] xhci: dbc: Remove dbc_dma_free_coherent() wrapper Mathias Nyman
2020-07-23 14:45 ` [PATCH 07/27] xhci: dbc: Add device pointer to dbc structure Mathias Nyman
2020-07-23 14:45 ` [PATCH 08/27] xhci: dbc: Use dev_info() and similar instead of xhci_info() Mathias Nyman
2020-07-23 14:45 ` [PATCH 09/27] xhci: dbc: Don't use xhci_write_64() as it takes xhci as a parameter Mathias Nyman
2020-07-23 14:45 ` [PATCH 10/27] xhci: dbc: Don't pass the xhci pointer as a parameter to xhci_dbc_init_context() Mathias Nyman
2020-07-23 14:45 ` [PATCH 11/27] xhci: dbc: Get the device pointer from dbc structure in dbc_ep_do_queue() Mathias Nyman
2020-07-23 14:45 ` [PATCH 12/27] xhci: dbc: Pass dbc pointer to endpoint init and exit functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 13/27] xhci: dbc: Change to pass dbc pointer to xhci_do_dbc_stop() Mathias Nyman
2020-07-23 14:45 ` [PATCH 14/27] xhci: dbc: Pass dbc pointer to dbc_handle_xfer_event() instead of xhci_hcd pointer Mathias Nyman
2020-07-23 14:45 ` [PATCH 15/27] xhci: dbgtty: Pass dbc pointer when registering a dbctty device Mathias Nyman
2020-07-23 14:45 ` [PATCH 16/27] xhci: dbc: Pass dbc pointer to get_in/out_ep() helper functions to get endpoints Mathias Nyman
2020-07-23 14:45 ` [PATCH 17/27] xhci: dbc: Use dbc structure in the request completion instead of xhci_hcd Mathias Nyman
2020-07-23 14:45 ` [PATCH 18/27] xhci: dbc: Don't use generic xhci context allocation for dbc Mathias Nyman
2020-07-23 14:45 ` [PATCH 19/27] xhci: dbc: don't use generic xhci ring allocation functions " Mathias Nyman
2020-07-23 14:45 ` [PATCH 20/27] xhci: dbc: Pass dbc pointer to dbc memory init and cleanup functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 21/27] xhci: dbc: Pass dbc pointer to dbc start and stop functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 22/27] xhci: dbc: simplify dbc requests allocation and queueing Mathias Nyman
2020-07-23 14:45 ` [PATCH 23/27] xhci: dbc: remove endpoint pointers from dbc_port structure Mathias Nyman
2020-07-23 14:45 ` [PATCH 24/27] xhci: dbctty: split dbc tty driver registration and unregistration functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 25/27] xhci: dbc: Add a operations structure to access driver functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 26/27] xhci: dbgcap: remove dbc dependency on dbctty specific flag Mathias Nyman
2020-07-23 14:45 ` [PATCH 27/27] xhci: dbc: remove tty specific port structure from struct xhci_dbc Mathias Nyman
2020-07-23 15:04 ` [PATCH 00/27] xhci features for usb-next Greg KH
2020-07-23 18:47   ` Mathias Nyman
2020-07-24  7:06     ` Greg KH
2020-07-24 11:11       ` Mathias Nyman
2020-07-24 16:32         ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.