All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 16/19] xhci: split free interrupter into separate remove and free parts
Date: Thu, 19 Oct 2023 13:29:21 +0300	[thread overview]
Message-ID: <20231019102924.2797346-17-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20231019102924.2797346-1-mathias.nyman@linux.intel.com>

The current function that both removes and frees an interrupter isn't
optimal when using several interrupters. The array of interrupters need
to be protected with a lock while removing interrupters, but the default
xhci spin lock can't be used while freeing the interrupters event ring
segment table as dma_free_coherent() should be called with IRQs enabled.

There is no need to free the interrupter under the lock, so split this
code into separate unlocked free part, and a lock protected remove part.

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

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 4d0b1c0e61a8..62116586848b 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1807,22 +1807,13 @@ static int xhci_alloc_erst(struct xhci_hcd *xhci,
 }
 
 static void
-xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
+xhci_remove_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
 {
-	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
-	size_t erst_size;
 	u32 tmp;
 
 	if (!ir)
 		return;
 
-	erst_size = sizeof(struct xhci_erst_entry) * ir->erst.num_entries;
-	if (ir->erst.entries)
-		dma_free_coherent(dev, erst_size,
-				  ir->erst.entries,
-				  ir->erst.erst_dma_addr);
-	ir->erst.entries = NULL;
-
 	/*
 	 * Clean out interrupter registers except ERSTBA. Clearing either the
 	 * low or high 32 bits of ERSTBA immediately causes the controller to
@@ -1835,10 +1826,28 @@ xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
 
 		xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue);
 	}
+}
+
+static void
+xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
+{
+	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
+	size_t erst_size;
+
+	if (!ir)
+		return;
+
+	erst_size = sizeof(struct xhci_erst_entry) * ir->erst.num_entries;
+	if (ir->erst.entries)
+		dma_free_coherent(dev, erst_size,
+				  ir->erst.entries,
+				  ir->erst.erst_dma_addr);
+	ir->erst.entries = NULL;
 
-	/* free interrrupter event ring */
+	/* free interrupter event ring */
 	if (ir->event_ring)
 		xhci_ring_free(xhci, ir->event_ring);
+
 	ir->event_ring = NULL;
 
 	kfree(ir);
@@ -1851,6 +1860,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
 
 	cancel_delayed_work_sync(&xhci->cmd_timer);
 
+	xhci_remove_interrupter(xhci, xhci->interrupter);
 	xhci_free_interrupter(xhci, xhci->interrupter);
 	xhci->interrupter = NULL;
 	xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed primary event ring");
-- 
2.25.1


  parent reply	other threads:[~2023-10-19 10:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19 10:29 [PATCH 00/19] xhci features for usb-next Mathias Nyman
2023-10-19 10:29 ` [PATCH 01/19] xhci: pass port structure to tracing instead of port number Mathias Nyman
2023-10-19 10:29 ` [PATCH 02/19] xhci: Add busnumber to port tracing Mathias Nyman
2023-10-19 10:29 ` [PATCH 03/19] xhci: expand next_trb() helper to support more ring types Mathias Nyman
2023-10-19 10:29 ` [PATCH 04/19] xhci: Set DESI bits in ERDP register correctly Mathias Nyman
2023-10-19 10:29 ` [PATCH 05/19] xhci: Use more than one Event Ring segment Mathias Nyman
2023-10-19 10:29 ` [PATCH 06/19] xhci: Adjust segment numbers after ring expansion Mathias Nyman
2023-10-19 10:29 ` [PATCH 07/19] xhci: Update last segment pointer after Event Ring expansion Mathias Nyman
2023-10-19 10:29 ` [PATCH 08/19] xhci: Expose segment numbers in debugfs Mathias Nyman
2023-10-19 10:29 ` [PATCH 09/19] xhci: Clean up ERST_PTR_MASK inversion Mathias Nyman
2023-10-19 10:29 ` [PATCH 10/19] xhci: Clean up stale comment on ERST_SIZE macro Mathias Nyman
2023-10-19 10:29 ` [PATCH 11/19] xhci: Clean up xhci_{alloc,free}_erst() declarations Mathias Nyman
2023-10-19 10:29 ` [PATCH 12/19] xhci: simplify event ring dequeue tracking for transfer events Mathias Nyman
2023-10-19 10:29 ` [PATCH 13/19] xhci: Simplify event ring dequeue pointer update for port change events Mathias Nyman
2023-10-19 10:29 ` [PATCH 14/19] xhci: Loosen RPM as default policy to cover for AMD xHC 1.1 Mathias Nyman
2023-10-19 10:29 ` [PATCH 15/19] xhci: Enable RPM on controllers that support low-power states Mathias Nyman
2023-10-19 10:29 ` Mathias Nyman [this message]
2023-10-19 10:29 ` [PATCH 17/19] usb: xhci: Implement xhci_handshake_check_state() helper Mathias Nyman
2023-10-19 10:29 ` [PATCH 18/19] usb: host: xhci-plat: fix possible kernel oops while resuming Mathias Nyman
2023-10-19 10:29 ` [PATCH 19/19] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present Mathias Nyman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231019102924.2797346-17-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.