Skip to contentSkip to conversation

xhci features for usb-next

PATCH In review Mathias Nyman 2 participants 33 messages Jul 23, 2020 – Jul 24, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover xhci features for usb-next

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(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/27 xhci: Make debug message consistent with bus and port number

From: Kai-Heng Feng <[email protected]>

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.

---
 drivers/usb/host/xhci-hub.c | 41 +++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 18 deletions(-)
drivers/usb/host/xhci-hub.c +23 -18
index 073c54e42223..c3554e37e09f 100644
@@ -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);
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/27 xhci: dbc: Don't use generic xhci inc_deq() function for dbc

In reply to 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.

---
 drivers/usb/host/xhci-dbgcap.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/usb/host/xhci-dbgcap.c +13 -1
index 987f893e941c..424b571d6ca9 100644
@@ -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;
 	}
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/27 xhci: Don't pass struct xhci_hcd pointer to xhci_link_seg()

In reply to 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.

---
 drivers/usb/host/xhci-mem.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/usb/host/xhci-mem.c +20 -11
index fb221c091478..d38779e2fc84 100644
@@ -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;
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/27 xhci: dbc: Don't use generic xhci erst allocation and free functions

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/usb/host/xhci-dbgcap.c +28 -3
index 424b571d6ca9..138b0c994ad2 100644
@@ -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);
Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/27 xhci: dbc: Remove dbc_dma_alloc_coherent() wrapper

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/usb/host/xhci-dbgcap.c +2 -15
index 138b0c994ad2..e8a2cbda135c 100644
@@ -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;
 
Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/27 xhci: dbc: Remove dbc_dma_free_coherent() wrapper

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/usb/host/xhci-dbgcap.c +2 -12
index e8a2cbda135c..5bec36ed97c6 100644
@@ -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;
 	}
 
Signature · 1 line
2.17.1
#7 lore raw

PATCH 7/27 xhci: dbc: Add device pointer to dbc structure

In reply to 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.

---
 drivers/usb/host/xhci-dbgcap.c | 1 +
 drivers/usb/host/xhci-dbgcap.h | 1 +
 2 files changed, 2 insertions(+)
drivers/usb/host/xhci-dbgcap.c +1 -0
index 5bec36ed97c6..ae584d6ae10c 100644
@@ -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);
 
drivers/usb/host/xhci-dbgcap.h +1 -0
index ce0c6072bd48..7ca2f4ccc537 100644
@@ -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;
Signature · 1 line
2.17.1
#8 lore raw

PATCH 8/27 xhci: dbc: Use dev_info() and similar instead of xhci_info()

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 42 +++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 21 deletions(-)
drivers/usb/host/xhci-dbgcap.c +21 -21
index ae584d6ae10c..3375be7ea642 100644
@@ -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;
 	}
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH 9/27 xhci: dbc: Don't use xhci_write_64() as it takes xhci as a parameter

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-dbgcap.c +5 -4
index 3375be7ea642..3541fbbfc28b 100644
@@ -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;
Signature · 1 line
2.17.1
#10 lore raw

PATCH 10/27 xhci: dbc: Don't pass the xhci pointer as a parameter to xhci_dbc_init_context()

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-dbgcap.c +2 -4
index 3541fbbfc28b..a5281f95fd72 100644
@@ -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;
Signature · 1 line
2.17.1
#11 lore raw

PATCH 11/27 xhci: dbc: Get the device pointer from dbc structure in dbc_ep_do_queue()

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/usb/host/xhci-dbgcap.c +1 -4
index a5281f95fd72..44fe93632901 100644
@@ -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;
Signature · 1 line
2.17.1
#12 lore raw

PATCH 12/27 xhci: dbc: Pass dbc pointer to endpoint init and exit functions.

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/usb/host/xhci-dbgcap.c +7 -10
index 44fe93632901..6114b334eb61 100644
@@ -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,
Signature · 1 line
2.17.1
#13 lore raw

PATCH 13/27 xhci: dbc: Change to pass dbc pointer to xhci_do_dbc_stop()

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-dbgcap.c +2 -4
index 6114b334eb61..7dce1e094364 100644
@@ -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) {
Signature · 1 line
2.17.1
#14 lore raw

PATCH 14/27 xhci: dbc: Pass dbc pointer to dbc_handle_xfer_event() instead of xhci_hcd pointer

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-dbgcap.c +2 -4
index 7dce1e094364..1c53fdc791a4 100644
@@ -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;
Signature · 1 line
2.17.1
#15 lore raw

PATCH 15/27 xhci: dbgtty: Pass dbc pointer when registering a dbctty device

In reply to 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

---
 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(-)
drivers/usb/host/xhci-dbgcap.c +3 -5
index 1c53fdc791a4..dd8ac5918ad8 100644
@@ -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;
drivers/usb/host/xhci-dbgcap.h +2 -2
index 7ca2f4ccc537..628f85f97dfe 100644
@@ -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);
drivers/usb/host/xhci-dbgtty.c +3 -5
index 9a1d38442578..545e8cb0221a 100644
@@ -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);
Signature · 1 line
2.17.1
#16 lore raw

PATCH 16/27 xhci: dbc: Pass dbc pointer to get_in/out_ep() helper functions to get endpoints

In reply to 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

---
 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(-)
drivers/usb/host/xhci-dbgcap.c +3 -3
index dd8ac5918ad8..26e693dd7414 100644
@@ -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);
 			}
 
drivers/usb/host/xhci-dbgcap.h +2 -6
index 628f85f97dfe..dc7d2d157e7b 100644
@@ -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];
 }
 
drivers/usb/host/xhci-dbgtty.c +7 -7
index 545e8cb0221a..0ef48862f4a7 100644
@@ -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);
 }
Signature · 1 line
2.17.1
#17 lore raw

PATCH 17/27 xhci: dbc: Use dbc structure in the request completion instead of xhci_hcd

In reply to 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

---
 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(-)
drivers/usb/host/xhci-dbgcap.c +2 -3
index 26e693dd7414..2473100b955a 100644
@@ -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);
 }
 
drivers/usb/host/xhci-dbgcap.h +17 -17
index dc7d2d157e7b..9e3c5940f27b 100644
@@ -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)		\
drivers/usb/host/xhci-dbgtty.c +4 -6
index 0ef48862f4a7..967f0419dad7 100644
@@ -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;
Signature · 1 line
2.17.1
#18 lore raw

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

In reply to 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.

---
 drivers/usb/host/xhci-dbgcap.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
drivers/usb/host/xhci-dbgcap.c +30 -3
index 2473100b955a..fb56198d3aff 100644
@@ -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);
Signature · 1 line
2.17.1
#19 lore raw

PATCH 19/27 xhci: dbc: don't use generic xhci ring allocation functions for dbc.

In reply to 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

---
 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(-)
drivers/usb/host/xhci-dbgcap.c +70 -10
index fb56198d3aff..b00cbff5e2ca 100644
@@ -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;
drivers/usb/host/xhci-mem.c +2 -2
index d38779e2fc84..696fad50b478 100644
@@ -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;
drivers/usb/host/xhci.h +2 -0
index c295e8a7f5ae..ea1754f185a2 100644
@@ -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,
Signature · 1 line
2.17.1
#20 lore raw

PATCH 20/27 xhci: dbc: Pass dbc pointer to dbc memory init and cleanup functions

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/usb/host/xhci-dbgcap.c +5 -9
index b00cbff5e2ca..626635f26658 100644
@@ -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);
 	}
 }
Signature · 1 line
2.17.1
#21 lore raw

PATCH 21/27 xhci: dbc: Pass dbc pointer to dbc start and stop functions.

In reply to 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

---
 drivers/usb/host/xhci-dbgcap.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/usb/host/xhci-dbgcap.c +14 -15
index 626635f26658..af6e3622e53a 100644
@@ -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;
Signature · 1 line
2.17.1
#22 lore raw

PATCH 22/27 xhci: dbc: simplify dbc requests allocation and queueing

In reply to Mathias Nyman

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

---
 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(-)
drivers/usb/host/xhci-dbgcap.c +28 -15
index af6e3622e53a..e3eec628edb5 100644
@@ -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);
drivers/usb/host/xhci-dbgcap.h +7 -5
index 9e3c5940f27b..fe360cf712c1 100644
@@ -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);
drivers/usb/host/xhci-dbgtty.c +17 -16
index 967f0419dad7..9886d42e1ff2 100644
@@ -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);
 }
Signature · 1 line
2.17.1
#23 lore raw

PATCH 23/27 xhci: dbc: remove endpoint pointers from dbc_port structure

In reply to Mathias Nyman

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

---
 drivers/usb/host/xhci-dbgcap.h | 2 --
 drivers/usb/host/xhci-dbgtty.c | 2 --
 2 files changed, 4 deletions(-)
drivers/usb/host/xhci-dbgcap.h +0 -2
index fe360cf712c1..796cf2808be8 100644
@@ -110,8 +110,6 @@ struct dbc_port {
 	struct kfifo			write_fifo;
 
 	bool				registered;
-	struct dbc_ep			*in;
-	struct dbc_ep			*out;
 };
 
 struct xhci_dbc {
drivers/usb/host/xhci-dbgtty.c +0 -2
index 9886d42e1ff2..ab2b82aa04be 100644
@@ -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;
 }
Signature · 1 line
2.17.1
#24 lore raw

PATCH 24/27 xhci: dbctty: split dbc tty driver registration and unregistration functions.

In reply to 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.

---
 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(-)
drivers/usb/host/xhci-dbgcap.c +3 -3
index e3eec628edb5..99f0b425274a 100644
@@ -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);
 }
drivers/usb/host/xhci-dbgcap.h +2 -2
index 796cf2808be8..e4c7c9279ea8 100644
@@ -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,
drivers/usb/host/xhci-dbgtty.c +76 -49

140 lines not on this page · raw message

Signature · 1 line
2.17.1
#25 lore raw

PATCH 25/27 xhci: dbc: Add a operations structure to access driver functions

In reply to 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.

---
 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(-)
drivers/usb/host/xhci-dbgcap.c +6 -11
index 99f0b425274a..47090bceae21 100644
@@ -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;
drivers/usb/host/xhci-dbgcap.h +6 -2
index e4c7c9279ea8..5018b32fc742 100644
@@ -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);
drivers/usb/host/xhci-dbgtty.c +9 -2
index 9acf1efba36c..3231cec74a7a 100644
@@ -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;
 	}
 }
-
-
Signature · 1 line
2.17.1
#26 lore raw

PATCH 26/27 xhci: dbgcap: remove dbc dependency on dbctty specific flag

In reply to 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.

---
 drivers/usb/host/xhci-dbgcap.c | 16 ++++++++++++----
 drivers/usb/host/xhci-dbgtty.c |  5 +++++
 2 files changed, 17 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-dbgcap.c +12 -4
index 47090bceae21..c57178db7994 100644
@@ -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);
drivers/usb/host/xhci-dbgtty.c +5 -0
index 3231cec74a7a..3b306a22da47 100644
@@ -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;
Signature · 1 line
2.17.1
#27 lore raw

PATCH 27/27 xhci: dbc: remove tty specific port structure from struct xhci_dbc

In reply to Mathias Nyman

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

---
 drivers/usb/host/xhci-dbgcap.h |  2 +-
 drivers/usb/host/xhci-dbgtty.c | 29 +++++++++++++++++++++++------
 2 files changed, 24 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-dbgcap.h +1 -1
index 5018b32fc742..c70b78d504eb 100644
@@ -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 {
drivers/usb/host/xhci-dbgtty.c +23 -6
index 3b306a22da47..0b942112b6f8 100644
@@ -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();
Signature · 1 line
2.17.1
maintainer
#28 lore raw
In reply to Mathias Nyman
Quoted 8 lines · 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.

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

What is that going to help with?

thanks,

greg k-h

#29 lore raw
Quoted 11 lines · Greg KH
Quoted 8 lines · 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.

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.

Quoted 2 lines

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

maintainer
#30 lore raw
Quoted 11 lines · Mathias Nyman
Quoted 10 lines · Greg KH
Quoted 8 lines · 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.

Quoted 7 lines
Quoted 1 line

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.

Quoted 10 lines

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.

Quoted 9 lines
Quoted 1 line

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

#31 lore raw
Quoted 31 lines · Greg KH
Quoted 11 lines · Mathias Nyman
Quoted 10 lines · Greg KH
Quoted 8 lines · 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.

Quoted 7 lines
Quoted 1 line

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.

Quoted 7 lines

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.

Quoted 5 lines
Quoted 3 lines

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.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

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.

Quoted 7 lines
Quoted 3 lines

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

maintainer
#32 lore raw
Quoted 10 lines · Mathias Nyman
Quoted 3 lines

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.

Quoted 5 lines

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