aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/ti
diff options
context:
space:
mode:
authorIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>2016-08-09 19:22:40 -0400
committerDavid S. Miller <davem@davemloft.net>2016-08-10 20:27:40 -0400
commit2c836bd9a247132ff478857ec7b41a740df5ab64 (patch)
tree8ed306111884c22c6f5853f87ec199f56f5d049b /drivers/net/ethernet/ti
parent5d8d0d4d46ed7bc0cf3e3ccb6c8b6ad7676335bc (diff)
net: ethernet: ti: cpsw: move cpdma resources to cpsw_common
Every net device private struct holds links to shared cpdma resources. No need to save and every time synchronize these resources per net dev. So, move it to common driver struct. Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> Reviewed-by: Mugunthan V N <mugunthanvnm@ti.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/ti')
-rw-r--r--drivers/net/ethernet/ti/cpsw.c97
1 files changed, 48 insertions, 49 deletions
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 5db2a554fc2c..6d99d1e614f5 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -369,6 +369,8 @@ struct cpsw_common {
369 struct cpsw_wr_regs __iomem *wr_regs; 369 struct cpsw_wr_regs __iomem *wr_regs;
370 u8 __iomem *hw_stats; 370 u8 __iomem *hw_stats;
371 struct cpsw_host_regs __iomem *host_port_regs; 371 struct cpsw_host_regs __iomem *host_port_regs;
372 struct cpdma_ctlr *dma;
373 struct cpdma_chan *txch, *rxch;
372}; 374};
373 375
374struct cpsw_priv { 376struct cpsw_priv {
@@ -384,8 +386,6 @@ struct cpsw_priv {
384 int rx_packet_max; 386 int rx_packet_max;
385 u8 mac_addr[ETH_ALEN]; 387 u8 mac_addr[ETH_ALEN];
386 struct cpsw_slave *slaves; 388 struct cpsw_slave *slaves;
387 struct cpdma_ctlr *dma;
388 struct cpdma_chan *txch, *rxch;
389 struct cpsw_ale *ale; 389 struct cpsw_ale *ale;
390 bool rx_pause; 390 bool rx_pause;
391 bool tx_pause; 391 bool tx_pause;
@@ -654,25 +654,21 @@ static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
654 } 654 }
655} 655}
656 656
657static void cpsw_intr_enable(struct cpsw_priv *priv) 657static void cpsw_intr_enable(struct cpsw_common *cpsw)
658{ 658{
659 struct cpsw_common *cpsw = priv->cpsw;
660
661 __raw_writel(0xFF, &cpsw->wr_regs->tx_en); 659 __raw_writel(0xFF, &cpsw->wr_regs->tx_en);
662 __raw_writel(0xFF, &cpsw->wr_regs->rx_en); 660 __raw_writel(0xFF, &cpsw->wr_regs->rx_en);
663 661
664 cpdma_ctlr_int_ctrl(priv->dma, true); 662 cpdma_ctlr_int_ctrl(cpsw->dma, true);
665 return; 663 return;
666} 664}
667 665
668static void cpsw_intr_disable(struct cpsw_priv *priv) 666static void cpsw_intr_disable(struct cpsw_common *cpsw)
669{ 667{
670 struct cpsw_common *cpsw = priv->cpsw;
671
672 __raw_writel(0, &cpsw->wr_regs->tx_en); 668 __raw_writel(0, &cpsw->wr_regs->tx_en);
673 __raw_writel(0, &cpsw->wr_regs->rx_en); 669 __raw_writel(0, &cpsw->wr_regs->rx_en);
674 670
675 cpdma_ctlr_int_ctrl(priv->dma, false); 671 cpdma_ctlr_int_ctrl(cpsw->dma, false);
676 return; 672 return;
677} 673}
678 674
@@ -700,6 +696,7 @@ static void cpsw_rx_handler(void *token, int len, int status)
700 struct net_device *ndev = skb->dev; 696 struct net_device *ndev = skb->dev;
701 struct cpsw_priv *priv = netdev_priv(ndev); 697 struct cpsw_priv *priv = netdev_priv(ndev);
702 int ret = 0; 698 int ret = 0;
699 struct cpsw_common *cpsw = priv->cpsw;
703 700
704 cpsw_dual_emac_src_port_detect(status, priv, ndev, skb); 701 cpsw_dual_emac_src_port_detect(status, priv, ndev, skb);
705 702
@@ -745,8 +742,8 @@ static void cpsw_rx_handler(void *token, int len, int status)
745 } 742 }
746 743
747requeue: 744requeue:
748 ret = cpdma_chan_submit(priv->rxch, new_skb, new_skb->data, 745 ret = cpdma_chan_submit(cpsw->rxch, new_skb, new_skb->data,
749 skb_tailroom(new_skb), 0); 746 skb_tailroom(new_skb), 0);
750 if (WARN_ON(ret < 0)) 747 if (WARN_ON(ret < 0))
751 dev_kfree_skb_any(new_skb); 748 dev_kfree_skb_any(new_skb);
752} 749}
@@ -757,7 +754,7 @@ static irqreturn_t cpsw_tx_interrupt(int irq, void *dev_id)
757 struct cpsw_common *cpsw = priv->cpsw; 754 struct cpsw_common *cpsw = priv->cpsw;
758 755
759 writel(0, &cpsw->wr_regs->tx_en); 756 writel(0, &cpsw->wr_regs->tx_en);
760 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX); 757 cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_TX);
761 758
762 if (priv->quirk_irq) { 759 if (priv->quirk_irq) {
763 disable_irq_nosync(priv->irqs_table[1]); 760 disable_irq_nosync(priv->irqs_table[1]);
@@ -773,7 +770,7 @@ static irqreturn_t cpsw_rx_interrupt(int irq, void *dev_id)
773 struct cpsw_priv *priv = dev_id; 770 struct cpsw_priv *priv = dev_id;
774 struct cpsw_common *cpsw = priv->cpsw; 771 struct cpsw_common *cpsw = priv->cpsw;
775 772
776 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX); 773 cpdma_ctlr_eoi(cpsw->dma, CPDMA_EOI_RX);
777 writel(0, &cpsw->wr_regs->rx_en); 774 writel(0, &cpsw->wr_regs->rx_en);
778 775
779 if (priv->quirk_irq) { 776 if (priv->quirk_irq) {
@@ -791,7 +788,7 @@ static int cpsw_tx_poll(struct napi_struct *napi_tx, int budget)
791 int num_tx; 788 int num_tx;
792 struct cpsw_common *cpsw = priv->cpsw; 789 struct cpsw_common *cpsw = priv->cpsw;
793 790
794 num_tx = cpdma_chan_process(priv->txch, budget); 791 num_tx = cpdma_chan_process(cpsw->txch, budget);
795 if (num_tx < budget) { 792 if (num_tx < budget) {
796 napi_complete(napi_tx); 793 napi_complete(napi_tx);
797 writel(0xff, &cpsw->wr_regs->tx_en); 794 writel(0xff, &cpsw->wr_regs->tx_en);
@@ -810,7 +807,7 @@ static int cpsw_rx_poll(struct napi_struct *napi_rx, int budget)
810 int num_rx; 807 int num_rx;
811 struct cpsw_common *cpsw = priv->cpsw; 808 struct cpsw_common *cpsw = priv->cpsw;
812 809
813 num_rx = cpdma_chan_process(priv->rxch, budget); 810 num_rx = cpdma_chan_process(cpsw->rxch, budget);
814 if (num_rx < budget) { 811 if (num_rx < budget) {
815 napi_complete(napi_rx); 812 napi_complete(napi_rx);
816 writel(0xff, &cpsw->wr_regs->rx_en); 813 writel(0xff, &cpsw->wr_regs->rx_en);
@@ -1020,17 +1017,16 @@ static void cpsw_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
1020static void cpsw_get_ethtool_stats(struct net_device *ndev, 1017static void cpsw_get_ethtool_stats(struct net_device *ndev,
1021 struct ethtool_stats *stats, u64 *data) 1018 struct ethtool_stats *stats, u64 *data)
1022{ 1019{
1023 struct cpsw_priv *priv = netdev_priv(ndev);
1024 struct cpdma_chan_stats rx_stats; 1020 struct cpdma_chan_stats rx_stats;
1025 struct cpdma_chan_stats tx_stats; 1021 struct cpdma_chan_stats tx_stats;
1026 u32 val; 1022 u32 val;
1027 u8 *p; 1023 u8 *p;
1028 int i; 1024 int i;
1029 struct cpsw_common *cpsw = priv->cpsw; 1025 struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
1030 1026
1031 /* Collect Davinci CPDMA stats for Rx and Tx Channel */ 1027 /* Collect Davinci CPDMA stats for Rx and Tx Channel */
1032 cpdma_chan_get_stats(priv->rxch, &rx_stats); 1028 cpdma_chan_get_stats(cpsw->rxch, &rx_stats);
1033 cpdma_chan_get_stats(priv->txch, &tx_stats); 1029 cpdma_chan_get_stats(cpsw->txch, &tx_stats);
1034 1030
1035 for (i = 0; i < CPSW_STATS_LEN; i++) { 1031 for (i = 0; i < CPSW_STATS_LEN; i++) {
1036 switch (cpsw_gstrings_stats[i].type) { 1032 switch (cpsw_gstrings_stats[i].type) {
@@ -1073,7 +1069,9 @@ static int cpsw_common_res_usage_state(struct cpsw_priv *priv)
1073static inline int cpsw_tx_packet_submit(struct cpsw_priv *priv, 1069static inline int cpsw_tx_packet_submit(struct cpsw_priv *priv,
1074 struct sk_buff *skb) 1070 struct sk_buff *skb)
1075{ 1071{
1076 return cpdma_chan_submit(priv->txch, skb, skb->data, skb->len, 1072 struct cpsw_common *cpsw = priv->cpsw;
1073
1074 return cpdma_chan_submit(cpsw->txch, skb, skb->data, skb->len,
1077 priv->emac_port + priv->data.dual_emac); 1075 priv->emac_port + priv->data.dual_emac);
1078} 1076}
1079 1077
@@ -1260,7 +1258,7 @@ static int cpsw_ndo_open(struct net_device *ndev)
1260 } 1258 }
1261 1259
1262 if (!cpsw_common_res_usage_state(priv)) 1260 if (!cpsw_common_res_usage_state(priv))
1263 cpsw_intr_disable(priv); 1261 cpsw_intr_disable(cpsw);
1264 netif_carrier_off(ndev); 1262 netif_carrier_off(ndev);
1265 1263
1266 reg = priv->version; 1264 reg = priv->version;
@@ -1286,8 +1284,8 @@ static int cpsw_ndo_open(struct net_device *ndev)
1286 int buf_num; 1284 int buf_num;
1287 1285
1288 /* setup tx dma to fixed prio and zero offset */ 1286 /* setup tx dma to fixed prio and zero offset */
1289 cpdma_control_set(priv->dma, CPDMA_TX_PRIO_FIXED, 1); 1287 cpdma_control_set(cpsw->dma, CPDMA_TX_PRIO_FIXED, 1);
1290 cpdma_control_set(priv->dma, CPDMA_RX_BUFFER_OFFSET, 0); 1288 cpdma_control_set(cpsw->dma, CPDMA_RX_BUFFER_OFFSET, 0);
1291 1289
1292 /* disable priority elevation */ 1290 /* disable priority elevation */
1293 __raw_writel(0, &cpsw->regs->ptype); 1291 __raw_writel(0, &cpsw->regs->ptype);
@@ -1311,7 +1309,7 @@ static int cpsw_ndo_open(struct net_device *ndev)
1311 enable_irq(priv->irqs_table[0]); 1309 enable_irq(priv->irqs_table[0]);
1312 } 1310 }
1313 1311
1314 buf_num = cpdma_chan_get_rx_buf_num(priv->dma); 1312 buf_num = cpdma_chan_get_rx_buf_num(cpsw->dma);
1315 for (i = 0; i < buf_num; i++) { 1313 for (i = 0; i < buf_num; i++) {
1316 struct sk_buff *skb; 1314 struct sk_buff *skb;
1317 1315
@@ -1320,8 +1318,8 @@ static int cpsw_ndo_open(struct net_device *ndev)
1320 priv->rx_packet_max, GFP_KERNEL); 1318 priv->rx_packet_max, GFP_KERNEL);
1321 if (!skb) 1319 if (!skb)
1322 goto err_cleanup; 1320 goto err_cleanup;
1323 ret = cpdma_chan_submit(priv->rxch, skb, skb->data, 1321 ret = cpdma_chan_submit(cpsw->rxch, skb, skb->data,
1324 skb_tailroom(skb), 0); 1322 skb_tailroom(skb), 0);
1325 if (ret < 0) { 1323 if (ret < 0) {
1326 kfree_skb(skb); 1324 kfree_skb(skb);
1327 goto err_cleanup; 1325 goto err_cleanup;
@@ -1347,15 +1345,15 @@ static int cpsw_ndo_open(struct net_device *ndev)
1347 cpsw_set_coalesce(ndev, &coal); 1345 cpsw_set_coalesce(ndev, &coal);
1348 } 1346 }
1349 1347
1350 cpdma_ctlr_start(priv->dma); 1348 cpdma_ctlr_start(cpsw->dma);
1351 cpsw_intr_enable(priv); 1349 cpsw_intr_enable(cpsw);
1352 1350
1353 if (priv->data.dual_emac) 1351 if (priv->data.dual_emac)
1354 priv->slaves[priv->emac_port].open_stat = true; 1352 priv->slaves[priv->emac_port].open_stat = true;
1355 return 0; 1353 return 0;
1356 1354
1357err_cleanup: 1355err_cleanup:
1358 cpdma_ctlr_stop(priv->dma); 1356 cpdma_ctlr_stop(cpsw->dma);
1359 for_each_slave(priv, cpsw_slave_stop, priv); 1357 for_each_slave(priv, cpsw_slave_stop, priv);
1360 pm_runtime_put_sync(cpsw->dev); 1358 pm_runtime_put_sync(cpsw->dev);
1361 netif_carrier_off(priv->ndev); 1359 netif_carrier_off(priv->ndev);
@@ -1377,8 +1375,8 @@ static int cpsw_ndo_stop(struct net_device *ndev)
1377 napi_disable(&priv_sl0->napi_rx); 1375 napi_disable(&priv_sl0->napi_rx);
1378 napi_disable(&priv_sl0->napi_tx); 1376 napi_disable(&priv_sl0->napi_tx);
1379 cpts_unregister(priv->cpts); 1377 cpts_unregister(priv->cpts);
1380 cpsw_intr_disable(priv); 1378 cpsw_intr_disable(cpsw);
1381 cpdma_ctlr_stop(priv->dma); 1379 cpdma_ctlr_stop(cpsw->dma);
1382 cpsw_ale_stop(priv->ale); 1380 cpsw_ale_stop(priv->ale);
1383 } 1381 }
1384 for_each_slave(priv, cpsw_slave_stop, priv); 1382 for_each_slave(priv, cpsw_slave_stop, priv);
@@ -1393,6 +1391,7 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
1393{ 1391{
1394 struct cpsw_priv *priv = netdev_priv(ndev); 1392 struct cpsw_priv *priv = netdev_priv(ndev);
1395 int ret; 1393 int ret;
1394 struct cpsw_common *cpsw = priv->cpsw;
1396 1395
1397 netif_trans_update(ndev); 1396 netif_trans_update(ndev);
1398 1397
@@ -1417,7 +1416,7 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
1417 /* If there is no more tx desc left free then we need to 1416 /* If there is no more tx desc left free then we need to
1418 * tell the kernel to stop sending us tx frames. 1417 * tell the kernel to stop sending us tx frames.
1419 */ 1418 */
1420 if (unlikely(!cpdma_check_free_tx_desc(priv->txch))) 1419 if (unlikely(!cpdma_check_free_tx_desc(cpsw->txch)))
1421 netif_stop_queue(ndev); 1420 netif_stop_queue(ndev);
1422 1421
1423 return NETDEV_TX_OK; 1422 return NETDEV_TX_OK;
@@ -1602,13 +1601,14 @@ static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
1602static void cpsw_ndo_tx_timeout(struct net_device *ndev) 1601static void cpsw_ndo_tx_timeout(struct net_device *ndev)
1603{ 1602{
1604 struct cpsw_priv *priv = netdev_priv(ndev); 1603 struct cpsw_priv *priv = netdev_priv(ndev);
1604 struct cpsw_common *cpsw = priv->cpsw;
1605 1605
1606 cpsw_err(priv, tx_err, "transmit timeout, restarting dma\n"); 1606 cpsw_err(priv, tx_err, "transmit timeout, restarting dma\n");
1607 ndev->stats.tx_errors++; 1607 ndev->stats.tx_errors++;
1608 cpsw_intr_disable(priv); 1608 cpsw_intr_disable(cpsw);
1609 cpdma_chan_stop(priv->txch); 1609 cpdma_chan_stop(cpsw->txch);
1610 cpdma_chan_start(priv->txch); 1610 cpdma_chan_start(cpsw->txch);
1611 cpsw_intr_enable(priv); 1611 cpsw_intr_enable(cpsw);
1612} 1612}
1613 1613
1614static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p) 1614static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
@@ -1652,11 +1652,12 @@ static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
1652static void cpsw_ndo_poll_controller(struct net_device *ndev) 1652static void cpsw_ndo_poll_controller(struct net_device *ndev)
1653{ 1653{
1654 struct cpsw_priv *priv = netdev_priv(ndev); 1654 struct cpsw_priv *priv = netdev_priv(ndev);
1655 struct cpsw_common *cpsw = priv->cpsw;
1655 1656
1656 cpsw_intr_disable(priv); 1657 cpsw_intr_disable(priv->cpsw);
1657 cpsw_rx_interrupt(priv->irqs_table[0], priv); 1658 cpsw_rx_interrupt(priv->irqs_table[0], priv);
1658 cpsw_tx_interrupt(priv->irqs_table[1], priv); 1659 cpsw_tx_interrupt(priv->irqs_table[1], priv);
1659 cpsw_intr_enable(priv); 1660 cpsw_intr_enable(priv->cpsw);
1660} 1661}
1661#endif 1662#endif
1662 1663
@@ -2204,9 +2205,6 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
2204 priv_sl2->slaves = priv->slaves; 2205 priv_sl2->slaves = priv->slaves;
2205 priv_sl2->coal_intvl = 0; 2206 priv_sl2->coal_intvl = 0;
2206 priv_sl2->bus_freq_mhz = priv->bus_freq_mhz; 2207 priv_sl2->bus_freq_mhz = priv->bus_freq_mhz;
2207 priv_sl2->dma = priv->dma;
2208 priv_sl2->txch = priv->txch;
2209 priv_sl2->rxch = priv->rxch;
2210 priv_sl2->ale = priv->ale; 2208 priv_sl2->ale = priv->ale;
2211 priv_sl2->emac_port = 1; 2209 priv_sl2->emac_port = 1;
2212 priv->slaves[1].ndev = ndev; 2210 priv->slaves[1].ndev = ndev;
@@ -2450,19 +2448,19 @@ static int cpsw_probe(struct platform_device *pdev)
2450 dma_params.has_ext_regs = true; 2448 dma_params.has_ext_regs = true;
2451 dma_params.desc_hw_addr = dma_params.desc_mem_phys; 2449 dma_params.desc_hw_addr = dma_params.desc_mem_phys;
2452 2450
2453 priv->dma = cpdma_ctlr_create(&dma_params); 2451 cpsw->dma = cpdma_ctlr_create(&dma_params);
2454 if (!priv->dma) { 2452 if (!cpsw->dma) {
2455 dev_err(priv->dev, "error initializing dma\n"); 2453 dev_err(priv->dev, "error initializing dma\n");
2456 ret = -ENOMEM; 2454 ret = -ENOMEM;
2457 goto clean_runtime_disable_ret; 2455 goto clean_runtime_disable_ret;
2458 } 2456 }
2459 2457
2460 priv->txch = cpdma_chan_create(priv->dma, tx_chan_num(0), 2458 cpsw->txch = cpdma_chan_create(cpsw->dma, tx_chan_num(0),
2461 cpsw_tx_handler); 2459 cpsw_tx_handler);
2462 priv->rxch = cpdma_chan_create(priv->dma, rx_chan_num(0), 2460 cpsw->rxch = cpdma_chan_create(cpsw->dma, rx_chan_num(0),
2463 cpsw_rx_handler); 2461 cpsw_rx_handler);
2464 2462
2465 if (WARN_ON(!priv->txch || !priv->rxch)) { 2463 if (WARN_ON(!cpsw->txch || !cpsw->rxch)) {
2466 dev_err(priv->dev, "error initializing dma channels\n"); 2464 dev_err(priv->dev, "error initializing dma channels\n");
2467 ret = -ENOMEM; 2465 ret = -ENOMEM;
2468 goto clean_dma_ret; 2466 goto clean_dma_ret;
@@ -2565,7 +2563,7 @@ static int cpsw_probe(struct platform_device *pdev)
2565clean_ale_ret: 2563clean_ale_ret:
2566 cpsw_ale_destroy(priv->ale); 2564 cpsw_ale_destroy(priv->ale);
2567clean_dma_ret: 2565clean_dma_ret:
2568 cpdma_ctlr_destroy(priv->dma); 2566 cpdma_ctlr_destroy(cpsw->dma);
2569clean_runtime_disable_ret: 2567clean_runtime_disable_ret:
2570 pm_runtime_disable(&pdev->dev); 2568 pm_runtime_disable(&pdev->dev);
2571clean_ndev_ret: 2569clean_ndev_ret:
@@ -2577,6 +2575,7 @@ static int cpsw_remove(struct platform_device *pdev)
2577{ 2575{
2578 struct net_device *ndev = platform_get_drvdata(pdev); 2576 struct net_device *ndev = platform_get_drvdata(pdev);
2579 struct cpsw_priv *priv = netdev_priv(ndev); 2577 struct cpsw_priv *priv = netdev_priv(ndev);
2578 struct cpsw_common *cpsw = priv->cpsw;
2580 int ret; 2579 int ret;
2581 2580
2582 ret = pm_runtime_get_sync(&pdev->dev); 2581 ret = pm_runtime_get_sync(&pdev->dev);
@@ -2590,7 +2589,7 @@ static int cpsw_remove(struct platform_device *pdev)
2590 unregister_netdev(ndev); 2589 unregister_netdev(ndev);
2591 2590
2592 cpsw_ale_destroy(priv->ale); 2591 cpsw_ale_destroy(priv->ale);
2593 cpdma_ctlr_destroy(priv->dma); 2592 cpdma_ctlr_destroy(cpsw->dma);
2594 of_platform_depopulate(&pdev->dev); 2593 of_platform_depopulate(&pdev->dev);
2595 pm_runtime_put_sync(&pdev->dev); 2594 pm_runtime_put_sync(&pdev->dev);
2596 pm_runtime_disable(&pdev->dev); 2595 pm_runtime_disable(&pdev->dev);