Skip to content

Commit fca3dc8

Browse files
tlebkuba-moo
authored andcommitted
net: macb: remove illusion about TBQPH/RBQPH being per-queue
The MACB driver acts as if TBQPH/RBQPH are configurable on a per queue basis; this is a lie. A single register configures the upper 32 bits of each DMA descriptor buffers for all queues. Concrete actions: - Drop GEM_TBQPH/GEM_RBQPH macros which have a queue index argument. Only use MACB_TBQPH/MACB_RBQPH constants. - Drop struct macb_queue->TBQPH/RBQPH fields. - In macb_init_buffers(): do a single write to TBQPH and RBQPH for all queues instead of a write per queue. - In macb_tx_error_task(): drop the write to TBQPH. - In macb_alloc_consistent(): if allocations give different upper 32-bits, fail. Previously, it would have lead to silent memory corruption as queues would have used the upper 32 bits of the alloc from queue 0 and their own low 32 bits. - In macb_suspend(): if we use the tie off descriptor for suspend, do the write once for all queues instead of once per queue. Fixes: fff8019 ("net: macb: Add 64 bit addressing support for GEM") Fixes: ae1f2a5 ("net: macb: Added support for many RX queues") Reviewed-by: Sean Anderson <[email protected]> Acked-by: Nicolas Ferre <[email protected]> Signed-off-by: Théo Lebrun <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9665aa1 commit fca3dc8

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

drivers/net/ethernet/cadence/macb.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,8 @@
213213

214214
#define GEM_ISR(hw_q) (0x0400 + ((hw_q) << 2))
215215
#define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2))
216-
#define GEM_TBQPH(hw_q) (0x04C8)
217216
#define GEM_RBQP(hw_q) (0x0480 + ((hw_q) << 2))
218217
#define GEM_RBQS(hw_q) (0x04A0 + ((hw_q) << 2))
219-
#define GEM_RBQPH(hw_q) (0x04D4)
220218
#define GEM_IER(hw_q) (0x0600 + ((hw_q) << 2))
221219
#define GEM_IDR(hw_q) (0x0620 + ((hw_q) << 2))
222220
#define GEM_IMR(hw_q) (0x0640 + ((hw_q) << 2))
@@ -1214,10 +1212,8 @@ struct macb_queue {
12141212
unsigned int IDR;
12151213
unsigned int IMR;
12161214
unsigned int TBQP;
1217-
unsigned int TBQPH;
12181215
unsigned int RBQS;
12191216
unsigned int RBQP;
1220-
unsigned int RBQPH;
12211217

12221218
/* Lock to protect tx_head and tx_tail */
12231219
spinlock_t tx_ptr_lock;

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -495,19 +495,19 @@ static void macb_init_buffers(struct macb *bp)
495495
struct macb_queue *queue;
496496
unsigned int q;
497497

498-
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
499-
queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma));
500498
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
501-
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
502-
queue_writel(queue, RBQPH,
503-
upper_32_bits(queue->rx_ring_dma));
499+
/* Single register for all queues' high 32 bits. */
500+
if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
501+
macb_writel(bp, RBQPH,
502+
upper_32_bits(bp->queues[0].rx_ring_dma));
503+
macb_writel(bp, TBQPH,
504+
upper_32_bits(bp->queues[0].tx_ring_dma));
505+
}
504506
#endif
507+
508+
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
509+
queue_writel(queue, RBQP, lower_32_bits(queue->rx_ring_dma));
505510
queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma));
506-
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
507-
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
508-
queue_writel(queue, TBQPH,
509-
upper_32_bits(queue->tx_ring_dma));
510-
#endif
511511
}
512512
}
513513

@@ -1166,10 +1166,6 @@ static void macb_tx_error_task(struct work_struct *work)
11661166

11671167
/* Reinitialize the TX desc queue */
11681168
queue_writel(queue, TBQP, lower_32_bits(queue->tx_ring_dma));
1169-
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
1170-
if (bp->hw_dma_cap & HW_DMA_CAP_64B)
1171-
queue_writel(queue, TBQPH, upper_32_bits(queue->tx_ring_dma));
1172-
#endif
11731169
/* Make TX ring reflect state of hardware */
11741170
queue->tx_head = 0;
11751171
queue->tx_tail = 0;
@@ -2546,14 +2542,17 @@ static int macb_alloc_consistent(struct macb *bp)
25462542
{
25472543
struct macb_queue *queue;
25482544
unsigned int q;
2545+
u32 upper;
25492546
int size;
25502547

25512548
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
25522549
size = TX_RING_BYTES(bp) + bp->tx_bd_rd_prefetch;
25532550
queue->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
25542551
&queue->tx_ring_dma,
25552552
GFP_KERNEL);
2556-
if (!queue->tx_ring)
2553+
upper = upper_32_bits(queue->tx_ring_dma);
2554+
if (!queue->tx_ring ||
2555+
upper != upper_32_bits(bp->queues[0].tx_ring_dma))
25572556
goto out_err;
25582557
netdev_dbg(bp->dev,
25592558
"Allocated TX ring for queue %u of %d bytes at %08lx (mapped %p)\n",
@@ -2567,8 +2566,11 @@ static int macb_alloc_consistent(struct macb *bp)
25672566

25682567
size = RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch;
25692568
queue->rx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
2570-
&queue->rx_ring_dma, GFP_KERNEL);
2571-
if (!queue->rx_ring)
2569+
&queue->rx_ring_dma,
2570+
GFP_KERNEL);
2571+
upper = upper_32_bits(queue->rx_ring_dma);
2572+
if (!queue->rx_ring ||
2573+
upper != upper_32_bits(bp->queues[0].rx_ring_dma))
25722574
goto out_err;
25732575
netdev_dbg(bp->dev,
25742576
"Allocated RX ring of %d bytes at %08lx (mapped %p)\n",
@@ -4309,12 +4311,6 @@ static int macb_init(struct platform_device *pdev)
43094311
queue->TBQP = GEM_TBQP(hw_q - 1);
43104312
queue->RBQP = GEM_RBQP(hw_q - 1);
43114313
queue->RBQS = GEM_RBQS(hw_q - 1);
4312-
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
4313-
if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
4314-
queue->TBQPH = GEM_TBQPH(hw_q - 1);
4315-
queue->RBQPH = GEM_RBQPH(hw_q - 1);
4316-
}
4317-
#endif
43184314
} else {
43194315
/* queue0 uses legacy registers */
43204316
queue->ISR = MACB_ISR;
@@ -4323,12 +4319,6 @@ static int macb_init(struct platform_device *pdev)
43234319
queue->IMR = MACB_IMR;
43244320
queue->TBQP = MACB_TBQP;
43254321
queue->RBQP = MACB_RBQP;
4326-
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
4327-
if (bp->hw_dma_cap & HW_DMA_CAP_64B) {
4328-
queue->TBQPH = MACB_TBQPH;
4329-
queue->RBQPH = MACB_RBQPH;
4330-
}
4331-
#endif
43324322
}
43334323

43344324
/* get irq: here we use the linux queue index, not the hardware
@@ -5452,6 +5442,11 @@ static int __maybe_unused macb_suspend(struct device *dev)
54525442
*/
54535443
tmp = macb_readl(bp, NCR);
54545444
macb_writel(bp, NCR, tmp & ~(MACB_BIT(TE) | MACB_BIT(RE)));
5445+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
5446+
if (!(bp->caps & MACB_CAPS_QUEUE_DISABLE))
5447+
macb_writel(bp, RBQPH,
5448+
upper_32_bits(bp->rx_ring_tieoff_dma));
5449+
#endif
54555450
for (q = 0, queue = bp->queues; q < bp->num_queues;
54565451
++q, ++queue) {
54575452
/* Disable RX queues */
@@ -5461,10 +5456,6 @@ static int __maybe_unused macb_suspend(struct device *dev)
54615456
/* Tie off RX queues */
54625457
queue_writel(queue, RBQP,
54635458
lower_32_bits(bp->rx_ring_tieoff_dma));
5464-
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
5465-
queue_writel(queue, RBQPH,
5466-
upper_32_bits(bp->rx_ring_tieoff_dma));
5467-
#endif
54685459
}
54695460
/* Disable all interrupts */
54705461
queue_writel(queue, IDR, -1);

0 commit comments

Comments
 (0)