Skip to content

Commit dbc4ec5

Browse files
ikhorndavem330
authored andcommitted
net: ethernet: ti: cpsw: move napi struct to cpsw_common
The napi structs are common for both net devices in dual_emac mode, In order to not hold duplicate links to them, move to cpsw_common. Signed-off-by: Ivan Khoronzhuk <[email protected]> Reviewed-by: Mugunthan V N <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 606f399 commit dbc4ec5

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

drivers/net/ethernet/ti/cpsw.c

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ static inline void slave_write(struct cpsw_slave *slave, u32 val, u32 offset)
367367
struct cpsw_common {
368368
struct device *dev;
369369
struct cpsw_platform_data data;
370+
struct napi_struct napi_rx;
371+
struct napi_struct napi_tx;
370372
struct cpsw_ss_regs __iomem *regs;
371373
struct cpsw_wr_regs __iomem *wr_regs;
372374
u8 __iomem *hw_stats;
@@ -382,8 +384,6 @@ struct cpsw_common {
382384

383385
struct cpsw_priv {
384386
struct net_device *ndev;
385-
struct napi_struct napi_rx;
386-
struct napi_struct napi_tx;
387387
struct device *dev;
388388
u32 msg_enable;
389389
u32 version;
@@ -488,7 +488,7 @@ static const struct cpsw_stats cpsw_gstrings_stats[] = {
488488
#define CPSW_STATS_LEN ARRAY_SIZE(cpsw_gstrings_stats)
489489

490490
#define ndev_to_cpsw(ndev) (((struct cpsw_priv *)netdev_priv(ndev))->cpsw)
491-
#define napi_to_priv(napi) container_of(napi, struct cpsw_priv, napi)
491+
#define napi_to_cpsw(napi) container_of(napi, struct cpsw_common, napi)
492492
#define for_each_slave(priv, func, arg...) \
493493
do { \
494494
struct cpsw_slave *slave; \
@@ -752,8 +752,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
752752

753753
static irqreturn_t cpsw_tx_interrupt(int irq, void *dev_id)
754754
{
755-
struct cpsw_priv *priv = dev_id;
756-
struct cpsw_common *cpsw = priv->cpsw;
755+
struct cpsw_common *cpsw = dev_id;
757756

758757
writel(0, &cpsw->wr_regs->tx_en);
759758
cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_TX);
@@ -763,14 +762,13 @@ static irqreturn_t cpsw_tx_interrupt(int irq, void *dev_id)
763762
cpsw->tx_irq_disabled = true;
764763
}
765764

766-
napi_schedule(&priv->napi_tx);
765+
napi_schedule(&cpsw->napi_tx);
767766
return IRQ_HANDLED;
768767
}
769768

770769
static irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id)
771770
{
772-
struct cpsw_priv *priv = dev_id;
773-
struct cpsw_common *cpsw = priv->cpsw;
771+
struct cpsw_common *cpsw = dev_id;
774772

775773
cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_RX);
776774
writel(0, &cpsw->wr_regs->rx_en);
@@ -780,15 +778,14 @@ static irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id)
780778
cpsw->rx_irq_disabled = true;
781779
}
782780

783-
napi_schedule(&priv->napi_rx);
781+
napi_schedule(&cpsw->napi_rx);
784782
return IRQ_HANDLED;
785783
}
786784

787785
static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget)
788786
{
789-
struct cpsw_priv *priv = napi_to_priv(napi_tx);
787+
struct cpsw_common *cpsw = napi_to_cpsw(napi_tx);
790788
int num_tx;
791-
struct cpsw_common *cpsw = priv->cpsw;
792789

793790
num_tx = cpdma_chan_process(cpsw->txch, budget);
794791
if (num_tx < budget) {
@@ -805,9 +802,8 @@ static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget)
805802

806803
static int cpsw_rx_poll(struct napi_struct *napi_rx, int budget)
807804
{
808-
struct cpsw_priv *priv = napi_to_priv(napi_rx);
805+
struct cpsw_common *cpsw = napi_to_cpsw(napi_rx);
809806
int num_rx;
810-
struct cpsw_common *cpsw = priv->cpsw;
811807

812808
num_rx = cpdma_chan_process(cpsw->rxch, budget);
813809
if (num_rx < budget) {
@@ -1283,7 +1279,6 @@ static int cpsw_ndo_open(struct net_device *ndev)
12831279
ALE_ALL_PORTS, ALE_ALL_PORTS, 0, 0);
12841280

12851281
if (!cpsw_common_res_usage_state(cpsw)) {
1286-
struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(cpsw, 0);
12871282
int buf_num;
12881283

12891284
/* setup tx dma to fixed prio and zero offset */
@@ -1299,8 +1294,8 @@ static int cpsw_ndo_open(struct net_device *ndev)
12991294
/* Enable internal fifo flow control */
13001295
writel(0x7, &cpsw->regs->flow_control);
13011296

1302-
napi_enable(&priv_sl0->napi_rx);
1303-
napi_enable(&priv_sl0->napi_tx);
1297+
napi_enable(&cpsw->napi_rx);
1298+
napi_enable(&cpsw->napi_tx);
13041299

13051300
if (cpsw->tx_irq_disabled) {
13061301
cpsw->tx_irq_disabled = false;
@@ -1373,10 +1368,8 @@ static int cpsw_ndo_stop(struct net_device *ndev)
13731368
netif_carrier_off(priv->ndev);
13741369

13751370
if (cpsw_common_res_usage_state(cpsw) <= 1) {
1376-
struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(cpsw, 0);
1377-
1378-
napi_disable(&priv_sl0->napi_rx);
1379-
napi_disable(&priv_sl0->napi_tx);
1371+
napi_disable(&cpsw->napi_rx);
1372+
napi_disable(&cpsw->napi_tx);
13801373
cpts_unregister(priv->cpts);
13811374
cpsw_intr_disable(cpsw);
13821375
cpdma_ctlr_stop(cpsw->dma);
@@ -1656,13 +1649,12 @@ static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
16561649
#ifdef CONFIG_NET_POLL_CONTROLLER
16571650
static void cpsw_ndo_poll_controller(struct net_device *ndev)
16581651
{
1659-
struct cpsw_priv *priv = netdev_priv(ndev);
1660-
struct cpsw_common *cpsw = priv->cpsw;
1652+
struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
16611653

1662-
cpsw_intr_disable(priv->cpsw);
1663-
cpsw_rx_interrupt(cpsw->irqs_table[0], priv);
1664-
cpsw_tx_interrupt(cpsw->irqs_table[1], priv);
1665-
cpsw_intr_enable(priv->cpsw);
1654+
cpsw_intr_disable(cpsw);
1655+
cpsw_rx_interrupt(cpsw->irqs_table[0], cpsw);
1656+
cpsw_tx_interrupt(cpsw->irqs_table[1], cpsw);
1657+
cpsw_intr_enable(cpsw);
16661658
}
16671659
#endif
16681660

@@ -2512,7 +2504,7 @@ static int cpsw_probe(struct platform_device *pdev)
25122504

25132505
cpsw->irqs_table[0] = irq;
25142506
ret = devm_request_irq(&pdev->dev, irq, cpsw_rx_interrupt,
2515-
0, dev_name(&pdev->dev), priv);
2507+
0, dev_name(&pdev->dev), cpsw);
25162508
if (ret < 0) {
25172509
dev_err(priv->dev, "error attaching irq (%d)\n", ret);
25182510
goto clean_ale_ret;
@@ -2527,7 +2519,7 @@ static int cpsw_probe(struct platform_device *pdev)
25272519

25282520
cpsw->irqs_table[1] = irq;
25292521
ret = devm_request_irq(&pdev->dev, irq, cpsw_tx_interrupt,
2530-
0, dev_name(&pdev->dev), priv);
2522+
0, dev_name(&pdev->dev), cpsw);
25312523
if (ret < 0) {
25322524
dev_err(priv->dev, "error attaching irq (%d)\n", ret);
25332525
goto clean_ale_ret;
@@ -2537,8 +2529,8 @@ static int cpsw_probe(struct platform_device *pdev)
25372529

25382530
ndev->netdev_ops = &cpsw_netdev_ops;
25392531
ndev->ethtool_ops = &cpsw_ethtool_ops;
2540-
netif_napi_add(ndev, &priv->napi_rx, cpsw_rx_poll, CPSW_POLL_WEIGHT);
2541-
netif_tx_napi_add(ndev, &priv->napi_tx, cpsw_tx_poll, CPSW_POLL_WEIGHT);
2532+
netif_napi_add(ndev, &cpsw->napi_rx, cpsw_rx_poll, CPSW_POLL_WEIGHT);
2533+
netif_tx_napi_add(ndev, &cpsw->napi_tx, cpsw_tx_poll, CPSW_POLL_WEIGHT);
25422534

25432535
/* register the network device */
25442536
SET_NETDEV_DEV(ndev, &pdev->dev);

0 commit comments

Comments
 (0)