Skip to content

Commit fff8019

Browse files
harini-katakamdavem330
authored andcommitted
net: macb: Add 64 bit addressing support for GEM
This patch adds support for 64 bit addressing and BDs. -> Enable 64 bit addressing in DMACFG register. -> Set DMA mask when design config register shows support for 64 bit addr. -> Add new BD words for higher address when 64 bit DMA support is present. -> Add and update TBQPH and RBQPH for MSB of BD pointers. -> Change extraction and updation of buffer addresses to use 64 bit address. -> In gem_rx extract address in one place insted of two and use a separate flag for RXUSED. Signed-off-by: Harini Katakam <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 054c67d commit fff8019

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

drivers/net/ethernet/cadence/macb.c

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,14 @@ static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb)
541541
}
542542
}
543543

544+
static inline void macb_set_addr(struct macb_dma_desc *desc, dma_addr_t addr)
545+
{
546+
desc->addr = (u32)addr;
547+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
548+
desc->addrh = (u32)(addr >> 32);
549+
#endif
550+
}
551+
544552
static void macb_tx_error_task(struct work_struct *work)
545553
{
546554
struct macb_queue *queue = container_of(work, struct macb_queue,
@@ -621,14 +629,17 @@ static void macb_tx_error_task(struct work_struct *work)
621629

622630
/* Set end of TX queue */
623631
desc = macb_tx_desc(queue, 0);
624-
desc->addr = 0;
632+
macb_set_addr(desc, 0);
625633
desc->ctrl = MACB_BIT(TX_USED);
626634

627635
/* Make descriptor updates visible to hardware */
628636
wmb();
629637

630638
/* Reinitialize the TX desc queue */
631-
queue_writel(queue, TBQP, queue->tx_ring_dma);
639+
queue_writel(queue, TBQP, (u32)(queue->tx_ring_dma));
640+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
641+
queue_writel(queue, TBQPH, (u32)(queue->tx_ring_dma >> 32));
642+
#endif
632643
/* Make TX ring reflect state of hardware */
633644
queue->tx_head = 0;
634645
queue->tx_tail = 0;
@@ -750,7 +761,7 @@ static void gem_rx_refill(struct macb *bp)
750761

751762
if (entry == RX_RING_SIZE - 1)
752763
paddr |= MACB_BIT(RX_WRAP);
753-
bp->rx_ring[entry].addr = paddr;
764+
macb_set_addr(&(bp->rx_ring[entry]), paddr);
754765
bp->rx_ring[entry].ctrl = 0;
755766

756767
/* properly align Ethernet header */
@@ -798,18 +809,24 @@ static int gem_rx(struct macb *bp, int budget)
798809
int count = 0;
799810

800811
while (count < budget) {
801-
u32 addr, ctrl;
812+
u32 ctrl;
813+
dma_addr_t addr;
814+
bool rxused;
802815

803816
entry = macb_rx_ring_wrap(bp->rx_tail);
804817
desc = &bp->rx_ring[entry];
805818

806819
/* Make hw descriptor updates visible to CPU */
807820
rmb();
808821

809-
addr = desc->addr;
822+
rxused = (desc->addr & MACB_BIT(RX_USED)) ? true : false;
823+
addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, desc->addr));
824+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
825+
addr |= ((u64)(desc->addrh) << 32);
826+
#endif
810827
ctrl = desc->ctrl;
811828

812-
if (!(addr & MACB_BIT(RX_USED)))
829+
if (!rxused)
813830
break;
814831

815832
bp->rx_tail++;
@@ -835,7 +852,6 @@ static int gem_rx(struct macb *bp, int budget)
835852
netdev_vdbg(bp->dev, "gem_rx %u (len %u)\n", entry, len);
836853

837854
skb_put(skb, len);
838-
addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, addr));
839855
dma_unmap_single(&bp->pdev->dev, addr,
840856
bp->rx_buffer_size, DMA_FROM_DEVICE);
841857

@@ -1299,7 +1315,7 @@ static unsigned int macb_tx_map(struct macb *bp,
12991315
ctrl |= MACB_BIT(TX_WRAP);
13001316

13011317
/* Set TX buffer descriptor */
1302-
desc->addr = tx_skb->mapping;
1318+
macb_set_addr(desc, tx_skb->mapping);
13031319
/* desc->addr must be visible to hardware before clearing
13041320
* 'TX_USED' bit in desc->ctrl.
13051321
*/
@@ -1422,6 +1438,9 @@ static void gem_free_rx_buffers(struct macb *bp)
14221438

14231439
desc = &bp->rx_ring[i];
14241440
addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, desc->addr));
1441+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
1442+
addr |= ((u64)(desc->addrh) << 32);
1443+
#endif
14251444
dma_unmap_single(&bp->pdev->dev, addr, bp->rx_buffer_size,
14261445
DMA_FROM_DEVICE);
14271446
dev_kfree_skb_any(skb);
@@ -1547,7 +1566,7 @@ static void gem_init_rings(struct macb *bp)
15471566

15481567
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
15491568
for (i = 0; i < TX_RING_SIZE; i++) {
1550-
queue->tx_ring[i].addr = 0;
1569+
macb_set_addr(&(queue->tx_ring[i]), 0);
15511570
queue->tx_ring[i].ctrl = MACB_BIT(TX_USED);
15521571
}
15531572
queue->tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
@@ -1694,6 +1713,10 @@ static void macb_configure_dma(struct macb *bp)
16941713
dmacfg |= GEM_BIT(TXCOEN);
16951714
else
16961715
dmacfg &= ~GEM_BIT(TXCOEN);
1716+
1717+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
1718+
dmacfg |= GEM_BIT(ADDR64);
1719+
#endif
16971720
netdev_dbg(bp->dev, "Cadence configure DMA with 0x%08x\n",
16981721
dmacfg);
16991722
gem_writel(bp, DMACFG, dmacfg);
@@ -1739,9 +1762,15 @@ static void macb_init_hw(struct macb *bp)
17391762
macb_configure_dma(bp);
17401763

17411764
/* Initialize TX and RX buffers */
1742-
macb_writel(bp, RBQP, bp->rx_ring_dma);
1765+
macb_writel(bp, RBQP, (u32)(bp->rx_ring_dma));
1766+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
1767+
macb_writel(bp, RBQPH, (u32)(bp->rx_ring_dma >> 32));
1768+
#endif
17431769
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
1744-
queue_writel(queue, TBQP, queue->tx_ring_dma);
1770+
queue_writel(queue, TBQP, (u32)(queue->tx_ring_dma));
1771+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
1772+
queue_writel(queue, TBQPH, (u32)(queue->tx_ring_dma >> 32));
1773+
#endif
17451774

17461775
/* Enable interrupts */
17471776
queue_writel(queue, IER,
@@ -2379,13 +2408,19 @@ static int macb_init(struct platform_device *pdev)
23792408
queue->IDR = GEM_IDR(hw_q - 1);
23802409
queue->IMR = GEM_IMR(hw_q - 1);
23812410
queue->TBQP = GEM_TBQP(hw_q - 1);
2411+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
2412+
queue->TBQPH = GEM_TBQPH(hw_q -1);
2413+
#endif
23822414
} else {
23832415
/* queue0 uses legacy registers */
23842416
queue->ISR = MACB_ISR;
23852417
queue->IER = MACB_IER;
23862418
queue->IDR = MACB_IDR;
23872419
queue->IMR = MACB_IMR;
23882420
queue->TBQP = MACB_TBQP;
2421+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
2422+
queue->TBQPH = MACB_TBQPH;
2423+
#endif
23892424
}
23902425

23912426
/* get irq: here we use the linux queue index, not the hardware
@@ -2935,6 +2970,11 @@ static int macb_probe(struct platform_device *pdev)
29352970
bp->wol |= MACB_WOL_HAS_MAGIC_PACKET;
29362971
device_init_wakeup(&pdev->dev, bp->wol & MACB_WOL_HAS_MAGIC_PACKET);
29372972

2973+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
2974+
if (GEM_BFEXT(DBWDEF, gem_readl(bp, DCFG1)) > GEM_DBW32)
2975+
dma_set_mask(&pdev->dev, DMA_BIT_MASK(44));
2976+
#endif
2977+
29382978
spin_lock_init(&bp->lock);
29392979

29402980
/* setup capabilities */

drivers/net/ethernet/cadence/macb.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
#define MACB_USRIO 0x00c0
6767
#define MACB_WOL 0x00c4
6868
#define MACB_MID 0x00fc
69+
#define MACB_TBQPH 0x04C8
70+
#define MACB_RBQPH 0x04D4
6971

7072
/* GEM register offsets. */
7173
#define GEM_NCFGR 0x0004 /* Network Config */
@@ -139,6 +141,7 @@
139141

140142
#define GEM_ISR(hw_q) (0x0400 + ((hw_q) << 2))
141143
#define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2))
144+
#define GEM_TBQPH(hw_q) (0x04C8)
142145
#define GEM_RBQP(hw_q) (0x0480 + ((hw_q) << 2))
143146
#define GEM_IER(hw_q) (0x0600 + ((hw_q) << 2))
144147
#define GEM_IDR(hw_q) (0x0620 + ((hw_q) << 2))
@@ -249,6 +252,8 @@
249252
#define GEM_RXBS_SIZE 8
250253
#define GEM_DDRP_OFFSET 24 /* disc_when_no_ahb */
251254
#define GEM_DDRP_SIZE 1
255+
#define GEM_ADDR64_OFFSET 30 /* Address bus width - 64b or 32b */
256+
#define GEM_ADDR64_SIZE 1
252257

253258

254259
/* Bitfields in NSR */
@@ -474,6 +479,10 @@
474479
struct macb_dma_desc {
475480
u32 addr;
476481
u32 ctrl;
482+
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
483+
u32 addrh;
484+
u32 resvd;
485+
#endif
477486
};
478487

479488
/* DMA descriptor bitfields */
@@ -777,6 +786,7 @@ struct macb_queue {
777786
unsigned int IDR;
778787
unsigned int IMR;
779788
unsigned int TBQP;
789+
unsigned int TBQPH;
780790

781791
unsigned int tx_head, tx_tail;
782792
struct macb_dma_desc *tx_ring;

0 commit comments

Comments
 (0)