Skip to content

Commit 19e47fc

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: airoha: Move irq_mask in airoha_qdma structure
QDMA controllers have independent irq lines, so move irqmask in airoha_qdma structure. This is a preliminary patch to support multiple QDMA controllers. Signed-off-by: Lorenzo Bianconi <[email protected]> Link: https://patch.msgid.link/1c8a06e8be605278a7b2f3cd8ac06e74bf5ebf2b.1722522582.git.lorenzo@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 245c7bc commit 19e47fc

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

drivers/net/ethernet/mediatek/airoha_eth.c

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,11 @@ struct airoha_hw_stats {
786786
struct airoha_qdma {
787787
void __iomem *regs;
788788

789+
/* protect concurrent irqmask accesses */
790+
spinlock_t irq_lock;
791+
u32 irqmask[QDMA_INT_REG_MAX];
792+
int irq;
793+
789794
struct airoha_tx_irq_queue q_tx_irq[AIROHA_NUM_TX_IRQ];
790795

791796
struct airoha_queue q_tx[AIROHA_NUM_TX_RING];
@@ -812,11 +817,6 @@ struct airoha_eth {
812817
unsigned long state;
813818
void __iomem *fe_regs;
814819

815-
/* protect concurrent irqmask accesses */
816-
spinlock_t irq_lock;
817-
u32 irqmask[QDMA_INT_REG_MAX];
818-
int irq;
819-
820820
struct reset_control_bulk_data rsts[AIROHA_MAX_NUM_RSTS];
821821
struct reset_control_bulk_data xsi_rsts[AIROHA_MAX_NUM_XSI_RSTS];
822822

@@ -866,38 +866,37 @@ static u32 airoha_rmw(void __iomem *base, u32 offset, u32 mask, u32 val)
866866
#define airoha_qdma_clear(qdma, offset, val) \
867867
airoha_rmw((qdma)->regs, (offset), (val), 0)
868868

869-
static void airoha_qdma_set_irqmask(struct airoha_eth *eth, int index,
869+
static void airoha_qdma_set_irqmask(struct airoha_qdma *qdma, int index,
870870
u32 clear, u32 set)
871871
{
872872
unsigned long flags;
873873

874-
if (WARN_ON_ONCE(index >= ARRAY_SIZE(eth->irqmask)))
874+
if (WARN_ON_ONCE(index >= ARRAY_SIZE(qdma->irqmask)))
875875
return;
876876

877-
spin_lock_irqsave(&eth->irq_lock, flags);
877+
spin_lock_irqsave(&qdma->irq_lock, flags);
878878

879-
eth->irqmask[index] &= ~clear;
880-
eth->irqmask[index] |= set;
881-
airoha_qdma_wr(&eth->qdma[0], REG_INT_ENABLE(index),
882-
eth->irqmask[index]);
879+
qdma->irqmask[index] &= ~clear;
880+
qdma->irqmask[index] |= set;
881+
airoha_qdma_wr(qdma, REG_INT_ENABLE(index), qdma->irqmask[index]);
883882
/* Read irq_enable register in order to guarantee the update above
884883
* completes in the spinlock critical section.
885884
*/
886-
airoha_qdma_rr(&eth->qdma[0], REG_INT_ENABLE(index));
885+
airoha_qdma_rr(qdma, REG_INT_ENABLE(index));
887886

888-
spin_unlock_irqrestore(&eth->irq_lock, flags);
887+
spin_unlock_irqrestore(&qdma->irq_lock, flags);
889888
}
890889

891-
static void airoha_qdma_irq_enable(struct airoha_eth *eth, int index,
890+
static void airoha_qdma_irq_enable(struct airoha_qdma *qdma, int index,
892891
u32 mask)
893892
{
894-
airoha_qdma_set_irqmask(eth, index, 0, mask);
893+
airoha_qdma_set_irqmask(qdma, index, 0, mask);
895894
}
896895

897-
static void airoha_qdma_irq_disable(struct airoha_eth *eth, int index,
896+
static void airoha_qdma_irq_disable(struct airoha_qdma *qdma, int index,
898897
u32 mask)
899898
{
900-
airoha_qdma_set_irqmask(eth, index, mask, 0);
899+
airoha_qdma_set_irqmask(qdma, index, mask, 0);
901900
}
902901

903902
static void airoha_set_macaddr(struct airoha_eth *eth, const u8 *addr)
@@ -1522,7 +1521,7 @@ static int airoha_qdma_rx_process(struct airoha_queue *q, int budget)
15221521
static int airoha_qdma_rx_napi_poll(struct napi_struct *napi, int budget)
15231522
{
15241523
struct airoha_queue *q = container_of(napi, struct airoha_queue, napi);
1525-
struct airoha_eth *eth = q->eth;
1524+
struct airoha_qdma *qdma = &q->eth->qdma[0];
15261525
int cur, done = 0;
15271526

15281527
do {
@@ -1531,7 +1530,7 @@ static int airoha_qdma_rx_napi_poll(struct napi_struct *napi, int budget)
15311530
} while (cur && done < budget);
15321531

15331532
if (done < budget && napi_complete(napi))
1534-
airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX1,
1533+
airoha_qdma_irq_enable(qdma, QDMA_INT_REG_IDX1,
15351534
RX_DONE_INT_MASK);
15361535

15371536
return done;
@@ -1718,7 +1717,7 @@ static int airoha_qdma_tx_napi_poll(struct napi_struct *napi, int budget)
17181717
}
17191718

17201719
if (done < budget && napi_complete(napi))
1721-
airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX0,
1720+
airoha_qdma_irq_enable(qdma, QDMA_INT_REG_IDX0,
17221721
TX_DONE_INT_MASK(id));
17231722

17241723
return done;
@@ -1927,13 +1926,13 @@ static int airoha_qdma_hw_init(struct airoha_eth *eth,
19271926
int i;
19281927

19291928
/* clear pending irqs */
1930-
for (i = 0; i < ARRAY_SIZE(eth->irqmask); i++)
1929+
for (i = 0; i < ARRAY_SIZE(qdma->irqmask); i++)
19311930
airoha_qdma_wr(qdma, REG_INT_STATUS(i), 0xffffffff);
19321931

19331932
/* setup irqs */
1934-
airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX0, INT_IDX0_MASK);
1935-
airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX1, INT_IDX1_MASK);
1936-
airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX4, INT_IDX4_MASK);
1933+
airoha_qdma_irq_enable(qdma, QDMA_INT_REG_IDX0, INT_IDX0_MASK);
1934+
airoha_qdma_irq_enable(qdma, QDMA_INT_REG_IDX1, INT_IDX1_MASK);
1935+
airoha_qdma_irq_enable(qdma, QDMA_INT_REG_IDX4, INT_IDX4_MASK);
19371936

19381937
/* setup irq binding */
19391938
for (i = 0; i < ARRAY_SIZE(qdma->q_tx); i++) {
@@ -1979,22 +1978,21 @@ static int airoha_qdma_hw_init(struct airoha_eth *eth,
19791978
static irqreturn_t airoha_irq_handler(int irq, void *dev_instance)
19801979
{
19811980
struct airoha_eth *eth = dev_instance;
1982-
u32 intr[ARRAY_SIZE(eth->irqmask)];
1983-
struct airoha_qdma *qdma;
1981+
struct airoha_qdma *qdma = &eth->qdma[0];
1982+
u32 intr[ARRAY_SIZE(qdma->irqmask)];
19841983
int i;
19851984

1986-
qdma = &eth->qdma[0];
1987-
for (i = 0; i < ARRAY_SIZE(eth->irqmask); i++) {
1985+
for (i = 0; i < ARRAY_SIZE(qdma->irqmask); i++) {
19881986
intr[i] = airoha_qdma_rr(qdma, REG_INT_STATUS(i));
1989-
intr[i] &= eth->irqmask[i];
1987+
intr[i] &= qdma->irqmask[i];
19901988
airoha_qdma_wr(qdma, REG_INT_STATUS(i), intr[i]);
19911989
}
19921990

19931991
if (!test_bit(DEV_STATE_INITIALIZED, &eth->state))
19941992
return IRQ_NONE;
19951993

19961994
if (intr[1] & RX_DONE_INT_MASK) {
1997-
airoha_qdma_irq_disable(eth, QDMA_INT_REG_IDX1,
1995+
airoha_qdma_irq_disable(qdma, QDMA_INT_REG_IDX1,
19981996
RX_DONE_INT_MASK);
19991997

20001998
for (i = 0; i < ARRAY_SIZE(qdma->q_rx); i++) {
@@ -2014,7 +2012,7 @@ static irqreturn_t airoha_irq_handler(int irq, void *dev_instance)
20142012
if (!(intr[0] & TX_DONE_INT_MASK(i)))
20152013
continue;
20162014

2017-
airoha_qdma_irq_disable(eth, QDMA_INT_REG_IDX0,
2015+
airoha_qdma_irq_disable(qdma, QDMA_INT_REG_IDX0,
20182016
TX_DONE_INT_MASK(i));
20192017

20202018
status = airoha_qdma_rr(qdma, REG_IRQ_STATUS(i));
@@ -2029,12 +2027,18 @@ static irqreturn_t airoha_irq_handler(int irq, void *dev_instance)
20292027
return IRQ_HANDLED;
20302028
}
20312029

2032-
static int airoha_qdma_init(struct airoha_eth *eth)
2030+
static int airoha_qdma_init(struct platform_device *pdev,
2031+
struct airoha_eth *eth)
20332032
{
20342033
struct airoha_qdma *qdma = &eth->qdma[0];
20352034
int err;
20362035

2037-
err = devm_request_irq(eth->dev, eth->irq, airoha_irq_handler,
2036+
spin_lock_init(&qdma->irq_lock);
2037+
qdma->irq = platform_get_irq(pdev, 0);
2038+
if (qdma->irq < 0)
2039+
return qdma->irq;
2040+
2041+
err = devm_request_irq(eth->dev, qdma->irq, airoha_irq_handler,
20382042
IRQF_SHARED, KBUILD_MODNAME, eth);
20392043
if (err)
20402044
return err;
@@ -2060,7 +2064,8 @@ static int airoha_qdma_init(struct airoha_eth *eth)
20602064
return 0;
20612065
}
20622066

2063-
static int airoha_hw_init(struct airoha_eth *eth)
2067+
static int airoha_hw_init(struct platform_device *pdev,
2068+
struct airoha_eth *eth)
20642069
{
20652070
int err;
20662071

@@ -2076,7 +2081,7 @@ static int airoha_hw_init(struct airoha_eth *eth)
20762081
if (err)
20772082
return err;
20782083

2079-
return airoha_qdma_init(eth);
2084+
return airoha_qdma_init(pdev, eth);
20802085
}
20812086

20822087
static void airoha_hw_cleanup(struct airoha_eth *eth)
@@ -2673,11 +2678,6 @@ static int airoha_probe(struct platform_device *pdev)
26732678
return err;
26742679
}
26752680

2676-
spin_lock_init(&eth->irq_lock);
2677-
eth->irq = platform_get_irq(pdev, 0);
2678-
if (eth->irq < 0)
2679-
return eth->irq;
2680-
26812681
eth->napi_dev = alloc_netdev_dummy(0);
26822682
if (!eth->napi_dev)
26832683
return -ENOMEM;
@@ -2687,7 +2687,7 @@ static int airoha_probe(struct platform_device *pdev)
26872687
strscpy(eth->napi_dev->name, "qdma_eth", sizeof(eth->napi_dev->name));
26882688
platform_set_drvdata(pdev, eth);
26892689

2690-
err = airoha_hw_init(eth);
2690+
err = airoha_hw_init(pdev, eth);
26912691
if (err)
26922692
goto error;
26932693

0 commit comments

Comments
 (0)