kernel: remove obsolete kernel version switches
[openwrt/openwrt.git] / target / linux / ath79 / files / drivers / net / ethernet / atheros / ag71xx / ag71xx_main.c
index 463083628fbeeefe05d45bd0cf2c29ff21021212..06ebbd8ea3893fe3018eb35780148e348cc41f57 100644 (file)
@@ -34,7 +34,7 @@ MODULE_PARM_DESC(msg_level, "Message level (-1=defaults,0=none,...,16=all)");
 
 #define ETH_SWITCH_HEADER_LEN  2
 
-static int ag71xx_tx_packets(struct ag71xx *ag, bool flush);
+static int ag71xx_tx_packets(struct ag71xx *ag, bool flush, int budget);
 
 static inline unsigned int ag71xx_max_frame_len(unsigned int mtu)
 {
@@ -478,7 +478,7 @@ static void ag71xx_fast_reset(struct ag71xx *ag)
        mii_reg = ag71xx_rr(ag, AG71XX_REG_MII_CFG);
        rx_ds = ag71xx_rr(ag, AG71XX_REG_RX_DESC);
 
-       ag71xx_tx_packets(ag, true);
+       ag71xx_tx_packets(ag, true, 0);
 
        reset_control_assert(ag->mac_reset);
        udelay(10);
@@ -1198,11 +1198,7 @@ static void ag71xx_oom_timer_handler(struct timer_list *t)
        napi_schedule(&ag->napi);
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
 static void ag71xx_tx_timeout(struct net_device *dev, unsigned int txqueue)
-#else
-static void ag71xx_tx_timeout(struct net_device *dev)
-#endif
 {
        struct ag71xx *ag = netdev_priv(dev);
 
@@ -1249,7 +1245,7 @@ static bool ag71xx_check_dma_stuck(struct ag71xx *ag)
        return false;
 }
 
-static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
+static int ag71xx_tx_packets(struct ag71xx *ag, bool flush, int budget)
 {
        struct ag71xx_ring *ring = &ag->tx_ring;
        bool dma_stuck = false;
@@ -1282,7 +1278,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag, bool flush)
                if (!skb)
                        continue;
 
-               dev_kfree_skb_any(skb);
+               napi_consume_skb(skb, budget);
                ring->buf[i].skb = NULL;
 
                bytes_compl += ring->buf[i].len;
@@ -1356,7 +1352,7 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit)
                dev->stats.rx_packets++;
                dev->stats.rx_bytes += pktlen;
 
-               skb = build_skb(ring->buf[i].rx_buf, ag71xx_buffer_size(ag));
+               skb = napi_build_skb(ring->buf[i].rx_buf, ag71xx_buffer_size(ag));
                if (!skb) {
                        skb_free_frag(ring->buf[i].rx_buf);
                        goto next;
@@ -1404,7 +1400,7 @@ static int ag71xx_poll(struct napi_struct *napi, int limit)
        int tx_done;
        int rx_done;
 
-       tx_done = ag71xx_tx_packets(ag, false);
+       tx_done = ag71xx_tx_packets(ag, false, limit);
 
        DBG("%s: processing RX ring\n", dev->name);
        rx_done = ag71xx_rx_packets(ag, limit);
@@ -1519,7 +1515,6 @@ static int ag71xx_probe(struct platform_device *pdev)
        struct net_device *dev;
        struct resource *res;
        struct ag71xx *ag;
-       const void *mac_addr;
        u32 max_frame_len;
        int tx_size, err;
 
@@ -1601,6 +1596,12 @@ static int ag71xx_probe(struct platform_device *pdev)
                        return -ENOMEM;
        }
 
+       /* ensure that HW is in manual polling mode before interrupts are
+        * activated. Otherwise ag71xx_interrupt might call napi_schedule
+        * before it is initialized by netif_napi_add.
+        */
+       ag71xx_int_disable(ag, AG71XX_INT_POLL);
+
        dev->irq = platform_get_irq(pdev, 0);
        err = devm_request_irq(&pdev->dev, dev->irq, ag71xx_interrupt,
                               0x0, dev_name(&pdev->dev), dev);
@@ -1668,21 +1669,14 @@ static int ag71xx_probe(struct platform_device *pdev)
        ag->stop_desc->ctrl = 0;
        ag->stop_desc->next = (u32) ag->stop_desc_dma;
 
-       mac_addr = of_get_mac_address(np);
-       if (IS_ERR_OR_NULL(mac_addr) || !is_valid_ether_addr(mac_addr)) {
+       of_get_mac_address(np, dev->dev_addr);
+       if (!is_valid_ether_addr(dev->dev_addr)) {
                dev_err(&pdev->dev, "invalid MAC address, using random address\n");
                eth_random_addr(dev->dev_addr);
-       } else {
-               memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
        }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0)
        err = of_get_phy_mode(np, &ag->phy_if_mode);
        if (err < 0) {
-#else
-       ag->phy_if_mode = of_get_phy_mode(np);
-       if (ag->phy_if_mode < 0) {
-#endif
                dev_err(&pdev->dev, "missing phy-mode property in DT\n");
                return ag->phy_if_mode;
        }