Skip to content

Commit 9a2500a

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: airoha: Add airoha_qdma pointer in airoha_tx_irq_queue/airoha_queue structures
Move airoha_eth pointer in airoha_qdma structure from airoha_tx_irq_queue/airoha_queue ones. This is a preliminary patch to introduce support for multi-QDMA controllers available on EN7581. Signed-off-by: Lorenzo Bianconi <[email protected]> Link: https://patch.msgid.link/074565b82fd0ceefe66e186f21133d825dbd48eb.1722522582.git.lorenzo@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 19e47fc commit 9a2500a

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

drivers/net/ethernet/mediatek/airoha_eth.c

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ struct airoha_queue_entry {
728728
};
729729

730730
struct airoha_queue {
731-
struct airoha_eth *eth;
731+
struct airoha_qdma *qdma;
732732

733733
/* protect concurrent queue accesses */
734734
spinlock_t lock;
@@ -747,7 +747,7 @@ struct airoha_queue {
747747
};
748748

749749
struct airoha_tx_irq_queue {
750-
struct airoha_eth *eth;
750+
struct airoha_qdma *qdma;
751751

752752
struct napi_struct napi;
753753
u32 *q;
@@ -784,6 +784,7 @@ struct airoha_hw_stats {
784784
};
785785

786786
struct airoha_qdma {
787+
struct airoha_eth *eth;
787788
void __iomem *regs;
788789

789790
/* protect concurrent irqmask accesses */
@@ -1388,8 +1389,8 @@ static int airoha_fe_init(struct airoha_eth *eth)
13881389
static int airoha_qdma_fill_rx_queue(struct airoha_queue *q)
13891390
{
13901391
enum dma_data_direction dir = page_pool_get_dma_dir(q->page_pool);
1391-
struct airoha_qdma *qdma = &q->eth->qdma[0];
1392-
struct airoha_eth *eth = q->eth;
1392+
struct airoha_qdma *qdma = q->qdma;
1393+
struct airoha_eth *eth = qdma->eth;
13931394
int qid = q - &qdma->q_rx[0];
13941395
int nframes = 0;
13951396

@@ -1457,8 +1458,8 @@ static int airoha_qdma_get_gdm_port(struct airoha_eth *eth,
14571458
static int airoha_qdma_rx_process(struct airoha_queue *q, int budget)
14581459
{
14591460
enum dma_data_direction dir = page_pool_get_dma_dir(q->page_pool);
1460-
struct airoha_qdma *qdma = &q->eth->qdma[0];
1461-
struct airoha_eth *eth = q->eth;
1461+
struct airoha_qdma *qdma = q->qdma;
1462+
struct airoha_eth *eth = qdma->eth;
14621463
int qid = q - &qdma->q_rx[0];
14631464
int done = 0;
14641465

@@ -1521,7 +1522,6 @@ static int airoha_qdma_rx_process(struct airoha_queue *q, int budget)
15211522
static int airoha_qdma_rx_napi_poll(struct napi_struct *napi, int budget)
15221523
{
15231524
struct airoha_queue *q = container_of(napi, struct airoha_queue, napi);
1524-
struct airoha_qdma *qdma = &q->eth->qdma[0];
15251525
int cur, done = 0;
15261526

15271527
do {
@@ -1530,14 +1530,13 @@ static int airoha_qdma_rx_napi_poll(struct napi_struct *napi, int budget)
15301530
} while (cur && done < budget);
15311531

15321532
if (done < budget && napi_complete(napi))
1533-
airoha_qdma_irq_enable(qdma, QDMA_INT_REG_IDX1,
1533+
airoha_qdma_irq_enable(q->qdma, QDMA_INT_REG_IDX1,
15341534
RX_DONE_INT_MASK);
15351535

15361536
return done;
15371537
}
15381538

1539-
static int airoha_qdma_init_rx_queue(struct airoha_eth *eth,
1540-
struct airoha_queue *q,
1539+
static int airoha_qdma_init_rx_queue(struct airoha_queue *q,
15411540
struct airoha_qdma *qdma, int ndesc)
15421541
{
15431542
const struct page_pool_params pp_params = {
@@ -1547,15 +1546,16 @@ static int airoha_qdma_init_rx_queue(struct airoha_eth *eth,
15471546
.dma_dir = DMA_FROM_DEVICE,
15481547
.max_len = PAGE_SIZE,
15491548
.nid = NUMA_NO_NODE,
1550-
.dev = eth->dev,
1549+
.dev = qdma->eth->dev,
15511550
.napi = &q->napi,
15521551
};
1552+
struct airoha_eth *eth = qdma->eth;
15531553
int qid = q - &qdma->q_rx[0], thr;
15541554
dma_addr_t dma_addr;
15551555

15561556
q->buf_size = PAGE_SIZE / 2;
15571557
q->ndesc = ndesc;
1558-
q->eth = eth;
1558+
q->qdma = qdma;
15591559

15601560
q->entry = devm_kzalloc(eth->dev, q->ndesc * sizeof(*q->entry),
15611561
GFP_KERNEL);
@@ -1595,7 +1595,7 @@ static int airoha_qdma_init_rx_queue(struct airoha_eth *eth,
15951595

15961596
static void airoha_qdma_cleanup_rx_queue(struct airoha_queue *q)
15971597
{
1598-
struct airoha_eth *eth = q->eth;
1598+
struct airoha_eth *eth = q->qdma->eth;
15991599

16001600
while (q->queued) {
16011601
struct airoha_queue_entry *e = &q->entry[q->tail];
@@ -1609,8 +1609,7 @@ static void airoha_qdma_cleanup_rx_queue(struct airoha_queue *q)
16091609
}
16101610
}
16111611

1612-
static int airoha_qdma_init_rx(struct airoha_eth *eth,
1613-
struct airoha_qdma *qdma)
1612+
static int airoha_qdma_init_rx(struct airoha_qdma *qdma)
16141613
{
16151614
int i;
16161615

@@ -1622,8 +1621,8 @@ static int airoha_qdma_init_rx(struct airoha_eth *eth,
16221621
continue;
16231622
}
16241623

1625-
err = airoha_qdma_init_rx_queue(eth, &qdma->q_rx[i],
1626-
qdma, RX_DSCP_NUM(i));
1624+
err = airoha_qdma_init_rx_queue(&qdma->q_rx[i], qdma,
1625+
RX_DSCP_NUM(i));
16271626
if (err)
16281627
return err;
16291628
}
@@ -1639,9 +1638,9 @@ static int airoha_qdma_tx_napi_poll(struct napi_struct *napi, int budget)
16391638
int id, done = 0;
16401639

16411640
irq_q = container_of(napi, struct airoha_tx_irq_queue, napi);
1642-
eth = irq_q->eth;
1643-
qdma = &eth->qdma[0];
1641+
qdma = irq_q->qdma;
16441642
id = irq_q - &qdma->q_tx_irq[0];
1643+
eth = qdma->eth;
16451644

16461645
while (irq_q->queued > 0 && done < budget) {
16471646
u32 qid, last, val = irq_q->q[irq_q->head];
@@ -1723,16 +1722,16 @@ static int airoha_qdma_tx_napi_poll(struct napi_struct *napi, int budget)
17231722
return done;
17241723
}
17251724

1726-
static int airoha_qdma_init_tx_queue(struct airoha_eth *eth,
1727-
struct airoha_queue *q,
1725+
static int airoha_qdma_init_tx_queue(struct airoha_queue *q,
17281726
struct airoha_qdma *qdma, int size)
17291727
{
1728+
struct airoha_eth *eth = qdma->eth;
17301729
int i, qid = q - &qdma->q_tx[0];
17311730
dma_addr_t dma_addr;
17321731

17331732
spin_lock_init(&q->lock);
17341733
q->ndesc = size;
1735-
q->eth = eth;
1734+
q->qdma = qdma;
17361735
q->free_thr = 1 + MAX_SKB_FRAGS;
17371736

17381737
q->entry = devm_kzalloc(eth->dev, q->ndesc * sizeof(*q->entry),
@@ -1761,11 +1760,11 @@ static int airoha_qdma_init_tx_queue(struct airoha_eth *eth,
17611760
return 0;
17621761
}
17631762

1764-
static int airoha_qdma_tx_irq_init(struct airoha_eth *eth,
1765-
struct airoha_tx_irq_queue *irq_q,
1763+
static int airoha_qdma_tx_irq_init(struct airoha_tx_irq_queue *irq_q,
17661764
struct airoha_qdma *qdma, int size)
17671765
{
17681766
int id = irq_q - &qdma->q_tx_irq[0];
1767+
struct airoha_eth *eth = qdma->eth;
17691768
dma_addr_t dma_addr;
17701769

17711770
netif_napi_add_tx(eth->napi_dev, &irq_q->napi,
@@ -1777,7 +1776,7 @@ static int airoha_qdma_tx_irq_init(struct airoha_eth *eth,
17771776

17781777
memset(irq_q->q, 0xff, size * sizeof(u32));
17791778
irq_q->size = size;
1780-
irq_q->eth = eth;
1779+
irq_q->qdma = qdma;
17811780

17821781
airoha_qdma_wr(qdma, REG_TX_IRQ_BASE(id), dma_addr);
17831782
airoha_qdma_rmw(qdma, REG_TX_IRQ_CFG(id), TX_IRQ_DEPTH_MASK,
@@ -1788,21 +1787,20 @@ static int airoha_qdma_tx_irq_init(struct airoha_eth *eth,
17881787
return 0;
17891788
}
17901789

1791-
static int airoha_qdma_init_tx(struct airoha_eth *eth,
1792-
struct airoha_qdma *qdma)
1790+
static int airoha_qdma_init_tx(struct airoha_qdma *qdma)
17931791
{
17941792
int i, err;
17951793

17961794
for (i = 0; i < ARRAY_SIZE(qdma->q_tx_irq); i++) {
1797-
err = airoha_qdma_tx_irq_init(eth, &qdma->q_tx_irq[i],
1798-
qdma, IRQ_QUEUE_LEN(i));
1795+
err = airoha_qdma_tx_irq_init(&qdma->q_tx_irq[i], qdma,
1796+
IRQ_QUEUE_LEN(i));
17991797
if (err)
18001798
return err;
18011799
}
18021800

18031801
for (i = 0; i < ARRAY_SIZE(qdma->q_tx); i++) {
1804-
err = airoha_qdma_init_tx_queue(eth, &qdma->q_tx[i],
1805-
qdma, TX_DSCP_NUM);
1802+
err = airoha_qdma_init_tx_queue(&qdma->q_tx[i], qdma,
1803+
TX_DSCP_NUM);
18061804
if (err)
18071805
return err;
18081806
}
@@ -1812,7 +1810,7 @@ static int airoha_qdma_init_tx(struct airoha_eth *eth,
18121810

18131811
static void airoha_qdma_cleanup_tx_queue(struct airoha_queue *q)
18141812
{
1815-
struct airoha_eth *eth = q->eth;
1813+
struct airoha_eth *eth = q->qdma->eth;
18161814

18171815
spin_lock_bh(&q->lock);
18181816
while (q->queued) {
@@ -1829,9 +1827,9 @@ static void airoha_qdma_cleanup_tx_queue(struct airoha_queue *q)
18291827
spin_unlock_bh(&q->lock);
18301828
}
18311829

1832-
static int airoha_qdma_init_hfwd_queues(struct airoha_eth *eth,
1833-
struct airoha_qdma *qdma)
1830+
static int airoha_qdma_init_hfwd_queues(struct airoha_qdma *qdma)
18341831
{
1832+
struct airoha_eth *eth = qdma->eth;
18351833
dma_addr_t dma_addr;
18361834
u32 status;
18371835
int size;
@@ -1869,8 +1867,7 @@ static int airoha_qdma_init_hfwd_queues(struct airoha_eth *eth,
18691867
REG_LMGR_INIT_CFG);
18701868
}
18711869

1872-
static void airoha_qdma_init_qos(struct airoha_eth *eth,
1873-
struct airoha_qdma *qdma)
1870+
static void airoha_qdma_init_qos(struct airoha_qdma *qdma)
18741871
{
18751872
airoha_qdma_clear(qdma, REG_TXWRR_MODE_CFG, TWRR_WEIGHT_SCALE_MASK);
18761873
airoha_qdma_set(qdma, REG_TXWRR_MODE_CFG, TWRR_WEIGHT_BASE_MASK);
@@ -1920,8 +1917,7 @@ static void airoha_qdma_init_qos(struct airoha_eth *eth,
19201917
FIELD_PREP(SLA_SLOW_TICK_RATIO_MASK, 40));
19211918
}
19221919

1923-
static int airoha_qdma_hw_init(struct airoha_eth *eth,
1924-
struct airoha_qdma *qdma)
1920+
static int airoha_qdma_hw_init(struct airoha_qdma *qdma)
19251921
{
19261922
int i;
19271923

@@ -1958,7 +1954,7 @@ static int airoha_qdma_hw_init(struct airoha_eth *eth,
19581954
GLOBAL_CFG_TX_WB_DONE_MASK |
19591955
FIELD_PREP(GLOBAL_CFG_MAX_ISSUE_NUM_MASK, 2));
19601956

1961-
airoha_qdma_init_qos(eth, qdma);
1957+
airoha_qdma_init_qos(qdma);
19621958

19631959
/* disable qdma rx delay interrupt */
19641960
for (i = 0; i < ARRAY_SIZE(qdma->q_rx); i++) {
@@ -2034,6 +2030,8 @@ static int airoha_qdma_init(struct platform_device *pdev,
20342030
int err;
20352031

20362032
spin_lock_init(&qdma->irq_lock);
2033+
qdma->eth = eth;
2034+
20372035
qdma->irq = platform_get_irq(pdev, 0);
20382036
if (qdma->irq < 0)
20392037
return qdma->irq;
@@ -2043,19 +2041,19 @@ static int airoha_qdma_init(struct platform_device *pdev,
20432041
if (err)
20442042
return err;
20452043

2046-
err = airoha_qdma_init_rx(eth, qdma);
2044+
err = airoha_qdma_init_rx(qdma);
20472045
if (err)
20482046
return err;
20492047

2050-
err = airoha_qdma_init_tx(eth, qdma);
2048+
err = airoha_qdma_init_tx(qdma);
20512049
if (err)
20522050
return err;
20532051

2054-
err = airoha_qdma_init_hfwd_queues(eth, qdma);
2052+
err = airoha_qdma_init_hfwd_queues(qdma);
20552053
if (err)
20562054
return err;
20572055

2058-
err = airoha_qdma_hw_init(eth, qdma);
2056+
err = airoha_qdma_hw_init(qdma);
20592057
if (err)
20602058
return err;
20612059

0 commit comments

Comments
 (0)