aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-04-12 22:41:33 -0400
committerDavid S. Miller <davem@davemloft.net>2016-04-12 22:41:33 -0400
commitb30d27f5bba2c65fb571ad7448b18dfee2fd63ae (patch)
treec0cfab410e63d281f560adfdb318dd4d714a7a15
parentda0caadf0a05945bf2ef017d43e4eae1e2859b92 (diff)
parent369f04531f80c5e5d194a193a2b9e7676a77328d (diff)
Merge branch 'mediatek-stress-test-fixes'
John Crispin says: ==================== net: mediatek: make the driver pass stress tests While testing the driver we managed to get the TX path to stall and fail to recover. When dual MAC support was added to the driver, the whole queue stop/wake code was not properly adapted. There was also a regression in the locking of the xmit function. The fact that watchdog_timeo was not set and that the tx_timeout code failed to properly reset the dma, irq and queue just made the mess complete. This series make the driver pass stress testing. With this series applied the testbed has been running for several days and still has not locked up. We have a second setup that has a small hack patch applied to randomly stop irqs and/or one of the queues and successfully manages to recover from these simulated tx stalls. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/mediatek/mtk_eth_soc.c106
-rw-r--r--drivers/net/ethernet/mediatek/mtk_eth_soc.h4
2 files changed, 66 insertions, 44 deletions
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index e0b68afea56e..c984462fad2a 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -536,7 +536,6 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
536 struct mtk_eth *eth = mac->hw; 536 struct mtk_eth *eth = mac->hw;
537 struct mtk_tx_dma *itxd, *txd; 537 struct mtk_tx_dma *itxd, *txd;
538 struct mtk_tx_buf *tx_buf; 538 struct mtk_tx_buf *tx_buf;
539 unsigned long flags;
540 dma_addr_t mapped_addr; 539 dma_addr_t mapped_addr;
541 unsigned int nr_frags; 540 unsigned int nr_frags;
542 int i, n_desc = 1; 541 int i, n_desc = 1;
@@ -568,11 +567,6 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
568 if (unlikely(dma_mapping_error(&dev->dev, mapped_addr))) 567 if (unlikely(dma_mapping_error(&dev->dev, mapped_addr)))
569 return -ENOMEM; 568 return -ENOMEM;
570 569
571 /* normally we can rely on the stack not calling this more than once,
572 * however we have 2 queues running ont he same ring so we need to lock
573 * the ring access
574 */
575 spin_lock_irqsave(&eth->page_lock, flags);
576 WRITE_ONCE(itxd->txd1, mapped_addr); 570 WRITE_ONCE(itxd->txd1, mapped_addr);
577 tx_buf->flags |= MTK_TX_FLAGS_SINGLE0; 571 tx_buf->flags |= MTK_TX_FLAGS_SINGLE0;
578 dma_unmap_addr_set(tx_buf, dma_addr0, mapped_addr); 572 dma_unmap_addr_set(tx_buf, dma_addr0, mapped_addr);
@@ -609,8 +603,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
609 WRITE_ONCE(txd->txd1, mapped_addr); 603 WRITE_ONCE(txd->txd1, mapped_addr);
610 WRITE_ONCE(txd->txd3, (TX_DMA_SWC | 604 WRITE_ONCE(txd->txd3, (TX_DMA_SWC |
611 TX_DMA_PLEN0(frag_map_size) | 605 TX_DMA_PLEN0(frag_map_size) |
612 last_frag * TX_DMA_LS0) | 606 last_frag * TX_DMA_LS0));
613 mac->id);
614 WRITE_ONCE(txd->txd4, 0); 607 WRITE_ONCE(txd->txd4, 0);
615 608
616 tx_buf->skb = (struct sk_buff *)MTK_DMA_DUMMY_DESC; 609 tx_buf->skb = (struct sk_buff *)MTK_DMA_DUMMY_DESC;
@@ -632,8 +625,6 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
632 WRITE_ONCE(itxd->txd3, (TX_DMA_SWC | TX_DMA_PLEN0(skb_headlen(skb)) | 625 WRITE_ONCE(itxd->txd3, (TX_DMA_SWC | TX_DMA_PLEN0(skb_headlen(skb)) |
633 (!nr_frags * TX_DMA_LS0))); 626 (!nr_frags * TX_DMA_LS0)));
634 627
635 spin_unlock_irqrestore(&eth->page_lock, flags);
636
637 netdev_sent_queue(dev, skb->len); 628 netdev_sent_queue(dev, skb->len);
638 skb_tx_timestamp(skb); 629 skb_tx_timestamp(skb);
639 630
@@ -661,8 +652,6 @@ err_dma:
661 itxd = mtk_qdma_phys_to_virt(ring, itxd->txd2); 652 itxd = mtk_qdma_phys_to_virt(ring, itxd->txd2);
662 } while (itxd != txd); 653 } while (itxd != txd);
663 654
664 spin_unlock_irqrestore(&eth->page_lock, flags);
665
666 return -ENOMEM; 655 return -ENOMEM;
667} 656}
668 657
@@ -681,7 +670,29 @@ static inline int mtk_cal_txd_req(struct sk_buff *skb)
681 nfrags += skb_shinfo(skb)->nr_frags; 670 nfrags += skb_shinfo(skb)->nr_frags;
682 } 671 }
683 672
684 return DIV_ROUND_UP(nfrags, 2); 673 return nfrags;
674}
675
676static void mtk_wake_queue(struct mtk_eth *eth)
677{
678 int i;
679
680 for (i = 0; i < MTK_MAC_COUNT; i++) {
681 if (!eth->netdev[i])
682 continue;
683 netif_wake_queue(eth->netdev[i]);
684 }
685}
686
687static void mtk_stop_queue(struct mtk_eth *eth)
688{
689 int i;
690
691 for (i = 0; i < MTK_MAC_COUNT; i++) {
692 if (!eth->netdev[i])
693 continue;
694 netif_stop_queue(eth->netdev[i]);
695 }
685} 696}
686 697
687static int mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) 698static int mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)
@@ -690,14 +701,22 @@ static int mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)
690 struct mtk_eth *eth = mac->hw; 701 struct mtk_eth *eth = mac->hw;
691 struct mtk_tx_ring *ring = &eth->tx_ring; 702 struct mtk_tx_ring *ring = &eth->tx_ring;
692 struct net_device_stats *stats = &dev->stats; 703 struct net_device_stats *stats = &dev->stats;
704 unsigned long flags;
693 bool gso = false; 705 bool gso = false;
694 int tx_num; 706 int tx_num;
695 707
708 /* normally we can rely on the stack not calling this more than once,
709 * however we have 2 queues running on the same ring so we need to lock
710 * the ring access
711 */
712 spin_lock_irqsave(&eth->page_lock, flags);
713
696 tx_num = mtk_cal_txd_req(skb); 714 tx_num = mtk_cal_txd_req(skb);
697 if (unlikely(atomic_read(&ring->free_count) <= tx_num)) { 715 if (unlikely(atomic_read(&ring->free_count) <= tx_num)) {
698 netif_stop_queue(dev); 716 mtk_stop_queue(eth);
699 netif_err(eth, tx_queued, dev, 717 netif_err(eth, tx_queued, dev,
700 "Tx Ring full when queue awake!\n"); 718 "Tx Ring full when queue awake!\n");
719 spin_unlock_irqrestore(&eth->page_lock, flags);
701 return NETDEV_TX_BUSY; 720 return NETDEV_TX_BUSY;
702 } 721 }
703 722
@@ -720,15 +739,17 @@ static int mtk_start_xmit(struct sk_buff *skb, struct net_device *dev)
720 goto drop; 739 goto drop;
721 740
722 if (unlikely(atomic_read(&ring->free_count) <= ring->thresh)) { 741 if (unlikely(atomic_read(&ring->free_count) <= ring->thresh)) {
723 netif_stop_queue(dev); 742 mtk_stop_queue(eth);
724 if (unlikely(atomic_read(&ring->free_count) > 743 if (unlikely(atomic_read(&ring->free_count) >
725 ring->thresh)) 744 ring->thresh))
726 netif_wake_queue(dev); 745 mtk_wake_queue(eth);
727 } 746 }
747 spin_unlock_irqrestore(&eth->page_lock, flags);
728 748
729 return NETDEV_TX_OK; 749 return NETDEV_TX_OK;
730 750
731drop: 751drop:
752 spin_unlock_irqrestore(&eth->page_lock, flags);
732 stats->tx_dropped++; 753 stats->tx_dropped++;
733 dev_kfree_skb(skb); 754 dev_kfree_skb(skb);
734 return NETDEV_TX_OK; 755 return NETDEV_TX_OK;
@@ -897,13 +918,8 @@ static int mtk_poll_tx(struct mtk_eth *eth, int budget, bool *tx_again)
897 if (!total) 918 if (!total)
898 return 0; 919 return 0;
899 920
900 for (i = 0; i < MTK_MAC_COUNT; i++) { 921 if (atomic_read(&ring->free_count) > ring->thresh)
901 if (!eth->netdev[i] || 922 mtk_wake_queue(eth);
902 unlikely(!netif_queue_stopped(eth->netdev[i])))
903 continue;
904 if (atomic_read(&ring->free_count) > ring->thresh)
905 netif_wake_queue(eth->netdev[i]);
906 }
907 923
908 return total; 924 return total;
909} 925}
@@ -1176,7 +1192,7 @@ static void mtk_tx_timeout(struct net_device *dev)
1176 eth->netdev[mac->id]->stats.tx_errors++; 1192 eth->netdev[mac->id]->stats.tx_errors++;
1177 netif_err(eth, tx_err, dev, 1193 netif_err(eth, tx_err, dev,
1178 "transmit timed out\n"); 1194 "transmit timed out\n");
1179 schedule_work(&mac->pending_work); 1195 schedule_work(&eth->pending_work);
1180} 1196}
1181 1197
1182static irqreturn_t mtk_handle_irq(int irq, void *_eth) 1198static irqreturn_t mtk_handle_irq(int irq, void *_eth)
@@ -1413,19 +1429,30 @@ static int mtk_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1413 1429
1414static void mtk_pending_work(struct work_struct *work) 1430static void mtk_pending_work(struct work_struct *work)
1415{ 1431{
1416 struct mtk_mac *mac = container_of(work, struct mtk_mac, pending_work); 1432 struct mtk_eth *eth = container_of(work, struct mtk_eth, pending_work);
1417 struct mtk_eth *eth = mac->hw; 1433 int err, i;
1418 struct net_device *dev = eth->netdev[mac->id]; 1434 unsigned long restart = 0;
1419 int err;
1420 1435
1421 rtnl_lock(); 1436 rtnl_lock();
1422 mtk_stop(dev);
1423 1437
1424 err = mtk_open(dev); 1438 /* stop all devices to make sure that dma is properly shut down */
1425 if (err) { 1439 for (i = 0; i < MTK_MAC_COUNT; i++) {
1426 netif_alert(eth, ifup, dev, 1440 if (!eth->netdev[i])
1427 "Driver up/down cycle failed, closing device.\n"); 1441 continue;
1428 dev_close(dev); 1442 mtk_stop(eth->netdev[i]);
1443 __set_bit(i, &restart);
1444 }
1445
1446 /* restart DMA and enable IRQs */
1447 for (i = 0; i < MTK_MAC_COUNT; i++) {
1448 if (!test_bit(i, &restart))
1449 continue;
1450 err = mtk_open(eth->netdev[i]);
1451 if (err) {
1452 netif_alert(eth, ifup, eth->netdev[i],
1453 "Driver up/down cycle failed, closing device.\n");
1454 dev_close(eth->netdev[i]);
1455 }
1429 } 1456 }
1430 rtnl_unlock(); 1457 rtnl_unlock();
1431} 1458}
@@ -1435,15 +1462,13 @@ static int mtk_cleanup(struct mtk_eth *eth)
1435 int i; 1462 int i;
1436 1463
1437 for (i = 0; i < MTK_MAC_COUNT; i++) { 1464 for (i = 0; i < MTK_MAC_COUNT; i++) {
1438 struct mtk_mac *mac = netdev_priv(eth->netdev[i]);
1439
1440 if (!eth->netdev[i]) 1465 if (!eth->netdev[i])
1441 continue; 1466 continue;
1442 1467
1443 unregister_netdev(eth->netdev[i]); 1468 unregister_netdev(eth->netdev[i]);
1444 free_netdev(eth->netdev[i]); 1469 free_netdev(eth->netdev[i]);
1445 cancel_work_sync(&mac->pending_work);
1446 } 1470 }
1471 cancel_work_sync(&eth->pending_work);
1447 1472
1448 return 0; 1473 return 0;
1449} 1474}
@@ -1631,7 +1656,6 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
1631 mac->id = id; 1656 mac->id = id;
1632 mac->hw = eth; 1657 mac->hw = eth;
1633 mac->of_node = np; 1658 mac->of_node = np;
1634 INIT_WORK(&mac->pending_work, mtk_pending_work);
1635 1659
1636 mac->hw_stats = devm_kzalloc(eth->dev, 1660 mac->hw_stats = devm_kzalloc(eth->dev,
1637 sizeof(*mac->hw_stats), 1661 sizeof(*mac->hw_stats),
@@ -1645,6 +1669,7 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
1645 mac->hw_stats->reg_offset = id * MTK_STAT_OFFSET; 1669 mac->hw_stats->reg_offset = id * MTK_STAT_OFFSET;
1646 1670
1647 SET_NETDEV_DEV(eth->netdev[id], eth->dev); 1671 SET_NETDEV_DEV(eth->netdev[id], eth->dev);
1672 eth->netdev[id]->watchdog_timeo = HZ;
1648 eth->netdev[id]->netdev_ops = &mtk_netdev_ops; 1673 eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
1649 eth->netdev[id]->base_addr = (unsigned long)eth->base; 1674 eth->netdev[id]->base_addr = (unsigned long)eth->base;
1650 eth->netdev[id]->vlan_features = MTK_HW_FEATURES & 1675 eth->netdev[id]->vlan_features = MTK_HW_FEATURES &
@@ -1678,10 +1703,6 @@ static int mtk_probe(struct platform_device *pdev)
1678 struct mtk_eth *eth; 1703 struct mtk_eth *eth;
1679 int err; 1704 int err;
1680 1705
1681 err = device_reset(&pdev->dev);
1682 if (err)
1683 return err;
1684
1685 match = of_match_device(of_mtk_match, &pdev->dev); 1706 match = of_match_device(of_mtk_match, &pdev->dev);
1686 soc = (struct mtk_soc_data *)match->data; 1707 soc = (struct mtk_soc_data *)match->data;
1687 1708
@@ -1736,6 +1757,7 @@ static int mtk_probe(struct platform_device *pdev)
1736 1757
1737 eth->dev = &pdev->dev; 1758 eth->dev = &pdev->dev;
1738 eth->msg_enable = netif_msg_init(mtk_msg_level, MTK_DEFAULT_MSG_ENABLE); 1759 eth->msg_enable = netif_msg_init(mtk_msg_level, MTK_DEFAULT_MSG_ENABLE);
1760 INIT_WORK(&eth->pending_work, mtk_pending_work);
1739 1761
1740 err = mtk_hw_init(eth); 1762 err = mtk_hw_init(eth);
1741 if (err) 1763 if (err)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
index 48a5292c8ed8..eed626d56ea4 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -363,6 +363,7 @@ struct mtk_rx_ring {
363 * @clk_gp1: The gmac1 clock 363 * @clk_gp1: The gmac1 clock
364 * @clk_gp2: The gmac2 clock 364 * @clk_gp2: The gmac2 clock
365 * @mii_bus: If there is a bus we need to create an instance for it 365 * @mii_bus: If there is a bus we need to create an instance for it
366 * @pending_work: The workqueue used to reset the dma ring
366 */ 367 */
367 368
368struct mtk_eth { 369struct mtk_eth {
@@ -389,6 +390,7 @@ struct mtk_eth {
389 struct clk *clk_gp1; 390 struct clk *clk_gp1;
390 struct clk *clk_gp2; 391 struct clk *clk_gp2;
391 struct mii_bus *mii_bus; 392 struct mii_bus *mii_bus;
393 struct work_struct pending_work;
392}; 394};
393 395
394/* struct mtk_mac - the structure that holds the info about the MACs of the 396/* struct mtk_mac - the structure that holds the info about the MACs of the
@@ -398,7 +400,6 @@ struct mtk_eth {
398 * @hw: Backpointer to our main datastruture 400 * @hw: Backpointer to our main datastruture
399 * @hw_stats: Packet statistics counter 401 * @hw_stats: Packet statistics counter
400 * @phy_dev: The attached PHY if available 402 * @phy_dev: The attached PHY if available
401 * @pending_work: The workqueue used to reset the dma ring
402 */ 403 */
403struct mtk_mac { 404struct mtk_mac {
404 int id; 405 int id;
@@ -406,7 +407,6 @@ struct mtk_mac {
406 struct mtk_eth *hw; 407 struct mtk_eth *hw;
407 struct mtk_hw_stats *hw_stats; 408 struct mtk_hw_stats *hw_stats;
408 struct phy_device *phy_dev; 409 struct phy_device *phy_dev;
409 struct work_struct pending_work;
410}; 410};
411 411
412/* the struct describing the SoC. these are declared in the soc_xyz.c files */ 412/* the struct describing the SoC. these are declared in the soc_xyz.c files */