forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/net/ethernet/marvell/mv643xx_eth.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for Marvell Discovery (MV643XX) and Marvell Orion ethernet ports
34 * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com>
....@@ -21,19 +22,6 @@
2122 * Lennert Buytenhek <buytenh@marvell.com>
2223 *
2324 * Copyright (C) 2013 Michael Stapelberg <michael@stapelberg.de>
24
- *
25
- * This program is free software; you can redistribute it and/or
26
- * modify it under the terms of the GNU General Public License
27
- * as published by the Free Software Foundation; either version 2
28
- * of the License, or (at your option) any later version.
29
- *
30
- * This program is distributed in the hope that it will be useful,
31
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
- * GNU General Public License for more details.
34
- *
35
- * You should have received a copy of the GNU General Public License
36
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
3725 */
3826
3927 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -671,16 +659,11 @@
671659 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
672660 const skb_frag_t *fragp = &skb_shinfo(skb)->frags[frag];
673661
674
- if (skb_frag_size(fragp) <= 8 && fragp->page_offset & 7)
662
+ if (skb_frag_size(fragp) <= 8 && skb_frag_off(fragp) & 7)
675663 return 1;
676664 }
677665
678666 return 0;
679
-}
680
-
681
-static inline __be16 sum16_as_be(__sum16 sum)
682
-{
683
- return (__force __be16)sum;
684667 }
685668
686669 static int skb_tx_csum(struct mv643xx_eth_private *mp, struct sk_buff *skb,
....@@ -833,10 +816,9 @@
833816 struct net_device *dev)
834817 {
835818 struct mv643xx_eth_private *mp = txq_to_mp(txq);
836
- int total_len, data_left, ret;
819
+ int hdr_len, total_len, data_left, ret;
837820 int desc_count = 0;
838821 struct tso_t tso;
839
- int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
840822 struct tx_desc *first_tx_desc;
841823 u32 first_cmd_sts = 0;
842824
....@@ -849,7 +831,7 @@
849831 first_tx_desc = &txq->tx_desc_area[txq->tx_curr_desc];
850832
851833 /* Initialize the TSO handler, and prepare the first payload */
852
- tso_start(skb, &tso);
834
+ hdr_len = tso_start(skb, &tso);
853835
854836 total_len = skb->len - hdr_len;
855837 while (total_len > 0) {
....@@ -1444,11 +1426,11 @@
14441426 };
14451427
14461428 #define SSTAT(m) \
1447
- { #m, FIELD_SIZEOF(struct net_device_stats, m), \
1429
+ { #m, sizeof_field(struct net_device_stats, m), \
14481430 offsetof(struct net_device, stats.m), -1 }
14491431
14501432 #define MIBSTAT(m) \
1451
- { #m, FIELD_SIZEOF(struct mib_counters, m), \
1433
+ { #m, sizeof_field(struct mib_counters, m), \
14521434 -1, offsetof(struct mv643xx_eth_private, mib_counters.m) }
14531435
14541436 static const struct mv643xx_eth_stats mv643xx_eth_stats[] = {
....@@ -1499,23 +1481,16 @@
14991481 struct ethtool_link_ksettings *cmd)
15001482 {
15011483 struct net_device *dev = mp->dev;
1502
- u32 supported, advertising;
15031484
15041485 phy_ethtool_ksettings_get(dev->phydev, cmd);
15051486
15061487 /*
15071488 * The MAC does not support 1000baseT_Half.
15081489 */
1509
- ethtool_convert_link_mode_to_legacy_u32(&supported,
1510
- cmd->link_modes.supported);
1511
- ethtool_convert_link_mode_to_legacy_u32(&advertising,
1512
- cmd->link_modes.advertising);
1513
- supported &= ~SUPPORTED_1000baseT_Half;
1514
- advertising &= ~ADVERTISED_1000baseT_Half;
1515
- ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
1516
- supported);
1517
- ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
1518
- advertising);
1490
+ linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
1491
+ cmd->link_modes.supported);
1492
+ linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
1493
+ cmd->link_modes.advertising);
15191494
15201495 return 0;
15211496 }
....@@ -1756,6 +1731,7 @@
17561731 }
17571732
17581733 static const struct ethtool_ops mv643xx_eth_ethtool_ops = {
1734
+ .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
17591735 .get_drvinfo = mv643xx_eth_get_drvinfo,
17601736 .nway_reset = phy_ethtool_nway_reset,
17611737 .get_link = ethtool_op_get_link,
....@@ -2495,6 +2471,7 @@
24952471 for (i = 0; i < mp->rxq_count; i++)
24962472 rxq_deinit(mp->rxq + i);
24972473 out:
2474
+ napi_disable(&mp->napi);
24982475 free_irq(dev->irq, dev);
24992476
25002477 return err;
....@@ -2609,7 +2586,7 @@
26092586 }
26102587 }
26112588
2612
-static void mv643xx_eth_tx_timeout(struct net_device *dev)
2589
+static void mv643xx_eth_tx_timeout(struct net_device *dev, unsigned int txqueue)
26132590 {
26142591 struct mv643xx_eth_private *mp = netdev_priv(dev);
26152592
....@@ -2733,17 +2710,17 @@
27332710
27342711 memset(&res, 0, sizeof(res));
27352712 if (of_irq_to_resource(pnp, 0, &res) <= 0) {
2736
- dev_err(&pdev->dev, "missing interrupt on %s\n", pnp->name);
2713
+ dev_err(&pdev->dev, "missing interrupt on %pOFn\n", pnp);
27372714 return -EINVAL;
27382715 }
27392716
27402717 if (of_property_read_u32(pnp, "reg", &ppd.port_number)) {
2741
- dev_err(&pdev->dev, "missing reg property on %s\n", pnp->name);
2718
+ dev_err(&pdev->dev, "missing reg property on %pOFn\n", pnp);
27422719 return -EINVAL;
27432720 }
27442721
27452722 if (ppd.port_number >= 3) {
2746
- dev_err(&pdev->dev, "invalid reg property on %s\n", pnp->name);
2723
+ dev_err(&pdev->dev, "invalid reg property on %pOFn\n", pnp);
27472724 return -EINVAL;
27482725 }
27492726
....@@ -2756,8 +2733,8 @@
27562733 }
27572734
27582735 mac_addr = of_get_mac_address(pnp);
2759
- if (mac_addr)
2760
- memcpy(ppd.mac_addr, mac_addr, ETH_ALEN);
2736
+ if (!IS_ERR(mac_addr))
2737
+ ether_addr_copy(ppd.mac_addr, mac_addr);
27612738
27622739 mv643xx_eth_property(pnp, "tx-queue-size", ppd.tx_queue_size);
27632740 mv643xx_eth_property(pnp, "tx-sram-addr", ppd.tx_sram_addr);
....@@ -2978,15 +2955,16 @@
29782955 static int get_phy_mode(struct mv643xx_eth_private *mp)
29792956 {
29802957 struct device *dev = mp->dev->dev.parent;
2981
- int iface = -1;
2958
+ phy_interface_t iface;
2959
+ int err;
29822960
29832961 if (dev->of_node)
2984
- iface = of_get_phy_mode(dev->of_node);
2962
+ err = of_get_phy_mode(dev->of_node, &iface);
29852963
29862964 /* Historical default if unspecified. We could also read/write
29872965 * the interface state in the PSC1
29882966 */
2989
- if (iface < 0)
2967
+ if (!dev->of_node || err)
29902968 iface = PHY_INTERFACE_MODE_GMII;
29912969 return iface;
29922970 }
....@@ -3036,10 +3014,12 @@
30363014 phy->autoneg = AUTONEG_ENABLE;
30373015 phy->speed = 0;
30383016 phy->duplex = 0;
3039
- phy->advertising = phy->supported | ADVERTISED_Autoneg;
3017
+ linkmode_copy(phy->advertising, phy->supported);
3018
+ linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
3019
+ phy->advertising);
30403020 } else {
30413021 phy->autoneg = AUTONEG_DISABLE;
3042
- phy->advertising = 0;
3022
+ linkmode_zero(phy->advertising);
30433023 phy->speed = speed;
30443024 phy->duplex = duplex;
30453025 }