From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>,
Lukas Wunner <lukas@wunner.de>,
Andreas Noever <andreas.noever@gmail.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 2/4] thunderbolt: Clean up ring interrupt register indexing
Date: Thu, 3 Sep 2026 14:34:52 +0200 [thread overview]
Message-ID: <20260903123455.2048076-3-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20260903123455.2048076-1-mika.westerberg@linux.intel.com>
nhi_mask_interrupt() and nhi_clear_interrupt() take "ring" as parameter
but in fact it is not an actual ring but a byte offset to the interrupt
register. Make this less confusing and name the paramers what it really
is and calculate the offset where it is actually needed.
In addition ring_interrupt_active() has two variables called "index"
with different meanings, and the second one shadows the first one
open-coding ring_interrupt_index() as well. Drop that and rename the
remaining what they actually hold.
While there, make the mask variable u32 and use BIT() to avoid signed
shifting.
No functional changes intended.
Assisted-by: LLM
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/thunderbolt/nhi.c | 44 +++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index 985b53399561..aaaf9e7966c8 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -41,6 +41,7 @@ static bool host_reset = true;
module_param(host_reset, bool, 0444);
MODULE_PARM_DESC(host_reset, "reset USB4 host router (default: true)");
+/* Returns absolute bit number of the ring in the interrupt registers */
static int ring_interrupt_index(const struct tb_ring *ring)
{
int bit = ring->hop;
@@ -49,24 +50,28 @@ static int ring_interrupt_index(const struct tb_ring *ring)
return bit;
}
-static void nhi_mask_interrupt(struct tb_nhi *nhi, int mask, int ring)
+static void nhi_mask_interrupt(struct tb_nhi *nhi, u32 mask, int reg_index)
{
+ int offset = reg_index * 4;
+
if (nhi->quirks & QUIRK_AUTO_CLEAR_INT) {
u32 val;
- val = ioread32(nhi->iobase + REG_RING_INTERRUPT_BASE + ring);
- iowrite32(val & ~mask, nhi->iobase + REG_RING_INTERRUPT_BASE + ring);
+ val = ioread32(nhi->iobase + REG_RING_INTERRUPT_BASE + offset);
+ iowrite32(val & ~mask, nhi->iobase + REG_RING_INTERRUPT_BASE + offset);
} else {
- iowrite32(mask, nhi->iobase + REG_RING_INTERRUPT_MASK_CLEAR_BASE + ring);
+ iowrite32(mask, nhi->iobase + REG_RING_INTERRUPT_MASK_CLEAR_BASE + offset);
}
}
-static void nhi_clear_interrupt(struct tb_nhi *nhi, int ring)
+static void nhi_clear_interrupt(struct tb_nhi *nhi, int reg_index)
{
+ int offset = reg_index * 4;
+
if (nhi->quirks & QUIRK_AUTO_CLEAR_INT)
- ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + ring);
+ ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + offset);
else
- iowrite32(~0, nhi->iobase + REG_RING_INT_CLEAR + ring);
+ iowrite32(~0, nhi->iobase + REG_RING_INT_CLEAR + offset);
}
/*
@@ -76,22 +81,17 @@ static void nhi_clear_interrupt(struct tb_nhi *nhi, int ring)
*/
static void ring_interrupt_active(struct tb_ring *ring, bool active)
{
- int index = ring_interrupt_index(ring) / 32 * 4;
- int reg = REG_RING_INTERRUPT_BASE + index;
- int interrupt_bit = ring_interrupt_index(ring) & 31;
- int mask = 1 << interrupt_bit;
+ int interrupt_index = ring_interrupt_index(ring);
+ int reg_index = interrupt_index / 32;
+ int reg = REG_RING_INTERRUPT_BASE + reg_index * 4;
+ int interrupt_bit = interrupt_index % 32;
+ u32 mask = BIT(interrupt_bit);
u32 old, new;
if (ring->irq > 0) {
u32 step, shift, ivr, misc, itr;
void __iomem *ivr_base;
int auto_clear_bit;
- int index;
-
- if (ring->is_tx)
- index = ring->hop;
- else
- index = ring->hop + ring->nhi->hop_count;
/*
* Intel routers support a bit that isn't part of
@@ -114,8 +114,8 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active)
ring->nhi->iobase + REG_DMA_MISC);
ivr_base = ring->nhi->iobase + REG_INT_VEC_ALLOC_BASE;
- step = index / REG_INT_VEC_ALLOC_REGS * REG_INT_VEC_ALLOC_BITS;
- shift = index % REG_INT_VEC_ALLOC_REGS * REG_INT_VEC_ALLOC_BITS;
+ step = interrupt_index / REG_INT_VEC_ALLOC_REGS * REG_INT_VEC_ALLOC_BITS;
+ shift = interrupt_index % REG_INT_VEC_ALLOC_REGS * REG_INT_VEC_ALLOC_BITS;
ivr = ioread32(ivr_base + step);
ivr &= ~(REG_INT_VEC_ALLOC_MASK << shift);
if (active)
@@ -156,7 +156,7 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active)
if (active)
iowrite32(new, ring->nhi->iobase + reg);
else
- nhi_mask_interrupt(ring->nhi, mask, index);
+ nhi_mask_interrupt(ring->nhi, mask, reg_index);
}
/*
@@ -169,11 +169,11 @@ void nhi_disable_interrupts(struct tb_nhi *nhi)
int i = 0;
/* disable interrupts */
for (i = 0; i < RING_INTERRUPT_REG_COUNT(nhi); i++)
- nhi_mask_interrupt(nhi, ~0, 4 * i);
+ nhi_mask_interrupt(nhi, ~0, i);
/* clear interrupt status bits */
for (i = 0; i < RING_NOTIFY_REG_COUNT(nhi); i++)
- nhi_clear_interrupt(nhi, 4 * i);
+ nhi_clear_interrupt(nhi, i);
}
/* ring helper methods */
--
2.50.1
next prev parent reply other threads:[~2026-09-03 12:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 12:34 [PATCH 0/4] thunderbolt: Couple of improvements for USB4STREAM Mika Westerberg
2026-09-03 12:34 ` [PATCH 1/4] thunderbolt: Do not WARN about already disabled interrupt on polled rings Mika Westerberg
2026-09-03 12:34 ` Mika Westerberg [this message]
2026-09-03 12:34 ` [PATCH 3/4] thunderbolt: Use shadow copy for ring interrupt mask Mika Westerberg
2026-09-03 12:34 ` [PATCH 4/4] thunderbolt: stream: Use polling with RX ring Mika Westerberg
2026-09-10 5:09 ` [PATCH 0/4] thunderbolt: Couple of improvements for USB4STREAM Mika Westerberg
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=20260903123455.2048076-3-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=linux-usb@vger.kernel.org \
--cc=lukas@wunner.de \
/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.