Skip to content

Commit fa12bb9

Browse files
ahunter6alexandrebelloni
authored andcommitted
i3c: mipi-i3c-hci: Consolidate spinlocks
The MIPI I3C HCI driver currently uses separate spinlocks for different contexts (PIO vs. DMA rings). This split is unnecessary and complicates upcoming fixes. The driver does not support concurrent PIO and DMA operation, and it only supports a single DMA ring, so a single lock is sufficient for all paths. Introduce a unified spinlock in struct i3c_hci, switch both PIO and DMA code to use it, and remove the per-context locks. No functional change is intended in this patch. Fixes: 9ad9a52 ("i3c/master: introduce the mipi-i3c-hci driver") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260306072451.11131-5-adrian.hunter@intel.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent f3bcbfe commit fa12bb9

4 files changed

Lines changed: 16 additions & 17 deletions

File tree

drivers/i3c/master/mipi-i3c-hci/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,8 @@ static int i3c_hci_probe(struct platform_device *pdev)
926926
if (!hci)
927927
return -ENOMEM;
928928

929+
spin_lock_init(&hci->lock);
930+
929931
/*
930932
* Multi-bus instances share the same MMIO address range, but not
931933
* necessarily in separate contiguous sub-ranges. To avoid overlapping

drivers/i3c/master/mipi-i3c-hci/dma.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ struct hci_rh_data {
131131
unsigned int xfer_struct_sz, resp_struct_sz, ibi_status_sz, ibi_chunk_sz;
132132
unsigned int done_ptr, ibi_chunk_ptr;
133133
struct hci_xfer **src_xfers;
134-
spinlock_t lock;
135134
struct completion op_done;
136135
};
137136

@@ -344,7 +343,6 @@ static int hci_dma_init(struct i3c_hci *hci)
344343
goto err_out;
345344
rh = &rings->headers[i];
346345
rh->regs = hci->base_regs + offset;
347-
spin_lock_init(&rh->lock);
348346
init_completion(&rh->op_done);
349347

350348
rh->xfer_entries = XFER_RING_ENTRIES;
@@ -534,12 +532,12 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci,
534532
}
535533

536534
/* take care to update the hardware enqueue pointer atomically */
537-
spin_lock_irq(&rh->lock);
535+
spin_lock_irq(&hci->lock);
538536
op1_val = rh_reg_read(RING_OPERATION1);
539537
op1_val &= ~RING_OP1_CR_ENQ_PTR;
540538
op1_val |= FIELD_PREP(RING_OP1_CR_ENQ_PTR, enqueue_ptr);
541539
rh_reg_write(RING_OPERATION1, op1_val);
542-
spin_unlock_irq(&rh->lock);
540+
spin_unlock_irq(&hci->lock);
543541

544542
return 0;
545543
}
@@ -637,12 +635,12 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, struct hci_rh_data *rh)
637635
}
638636

639637
/* take care to update the software dequeue pointer atomically */
640-
spin_lock(&rh->lock);
638+
spin_lock(&hci->lock);
641639
op1_val = rh_reg_read(RING_OPERATION1);
642640
op1_val &= ~RING_OP1_CR_SW_DEQ_PTR;
643641
op1_val |= FIELD_PREP(RING_OP1_CR_SW_DEQ_PTR, done_ptr);
644642
rh_reg_write(RING_OPERATION1, op1_val);
645-
spin_unlock(&rh->lock);
643+
spin_unlock(&hci->lock);
646644
}
647645

648646
static int hci_dma_request_ibi(struct i3c_hci *hci, struct i3c_dev_desc *dev,
@@ -823,12 +821,12 @@ static void hci_dma_process_ibi(struct i3c_hci *hci, struct hci_rh_data *rh)
823821

824822
done:
825823
/* take care to update the ibi dequeue pointer atomically */
826-
spin_lock(&rh->lock);
824+
spin_lock(&hci->lock);
827825
op1_val = rh_reg_read(RING_OPERATION1);
828826
op1_val &= ~RING_OP1_IBI_DEQ_PTR;
829827
op1_val |= FIELD_PREP(RING_OP1_IBI_DEQ_PTR, deq_ptr);
830828
rh_reg_write(RING_OPERATION1, op1_val);
831-
spin_unlock(&rh->lock);
829+
spin_unlock(&hci->lock);
832830

833831
/* update the chunk pointer */
834832
rh->ibi_chunk_ptr += ibi_chunks;

drivers/i3c/master/mipi-i3c-hci/hci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct i3c_hci {
5050
const struct hci_io_ops *io;
5151
void *io_data;
5252
const struct hci_cmd_ops *cmd;
53+
spinlock_t lock;
5354
atomic_t next_cmd_tid;
5455
bool irq_inactive;
5556
u32 caps;

drivers/i3c/master/mipi-i3c-hci/pio.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ struct hci_pio_ibi_data {
123123
};
124124

125125
struct hci_pio_data {
126-
spinlock_t lock;
127126
struct hci_xfer *curr_xfer, *xfer_queue;
128127
struct hci_xfer *curr_rx, *rx_queue;
129128
struct hci_xfer *curr_tx, *tx_queue;
@@ -212,7 +211,6 @@ static int hci_pio_init(struct i3c_hci *hci)
212211
return -ENOMEM;
213212

214213
hci->io_data = pio;
215-
spin_lock_init(&pio->lock);
216214

217215
__hci_pio_init(hci, &size_val);
218216

@@ -631,7 +629,7 @@ static int hci_pio_queue_xfer(struct i3c_hci *hci, struct hci_xfer *xfer, int n)
631629
xfer[i].data_left = xfer[i].data_len;
632630
}
633631

634-
spin_lock_irq(&pio->lock);
632+
spin_lock_irq(&hci->lock);
635633
prev_queue_tail = pio->xfer_queue;
636634
pio->xfer_queue = &xfer[n - 1];
637635
if (pio->curr_xfer) {
@@ -645,7 +643,7 @@ static int hci_pio_queue_xfer(struct i3c_hci *hci, struct hci_xfer *xfer, int n)
645643
pio_reg_read(INTR_STATUS),
646644
pio_reg_read(INTR_SIGNAL_ENABLE));
647645
}
648-
spin_unlock_irq(&pio->lock);
646+
spin_unlock_irq(&hci->lock);
649647
return 0;
650648
}
651649

@@ -716,14 +714,14 @@ static bool hci_pio_dequeue_xfer(struct i3c_hci *hci, struct hci_xfer *xfer, int
716714
struct hci_pio_data *pio = hci->io_data;
717715
int ret;
718716

719-
spin_lock_irq(&pio->lock);
717+
spin_lock_irq(&hci->lock);
720718
dev_dbg(&hci->master.dev, "n=%d status=%#x/%#x", n,
721719
pio_reg_read(INTR_STATUS), pio_reg_read(INTR_SIGNAL_ENABLE));
722720
dev_dbg(&hci->master.dev, "main_status = %#x/%#x",
723721
readl(hci->base_regs + 0x20), readl(hci->base_regs + 0x28));
724722

725723
ret = hci_pio_dequeue_xfer_common(hci, pio, xfer, n);
726-
spin_unlock_irq(&pio->lock);
724+
spin_unlock_irq(&hci->lock);
727725
return ret;
728726
}
729727

@@ -1016,13 +1014,13 @@ static bool hci_pio_irq_handler(struct i3c_hci *hci)
10161014
struct hci_pio_data *pio = hci->io_data;
10171015
u32 status;
10181016

1019-
spin_lock(&pio->lock);
1017+
spin_lock(&hci->lock);
10201018
status = pio_reg_read(INTR_STATUS);
10211019
dev_dbg(&hci->master.dev, "PIO_INTR_STATUS %#x/%#x",
10221020
status, pio->enabled_irqs);
10231021
status &= pio->enabled_irqs | STAT_LATENCY_WARNINGS;
10241022
if (!status) {
1025-
spin_unlock(&pio->lock);
1023+
spin_unlock(&hci->lock);
10261024
return false;
10271025
}
10281026

@@ -1058,7 +1056,7 @@ static bool hci_pio_irq_handler(struct i3c_hci *hci)
10581056
pio_reg_write(INTR_SIGNAL_ENABLE, pio->enabled_irqs);
10591057
dev_dbg(&hci->master.dev, "PIO_INTR_STATUS %#x/%#x",
10601058
pio_reg_read(INTR_STATUS), pio_reg_read(INTR_SIGNAL_ENABLE));
1061-
spin_unlock(&pio->lock);
1059+
spin_unlock(&hci->lock);
10621060
return true;
10631061
}
10641062

0 commit comments

Comments
 (0)