forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/net/usb/lan78xx.c
....@@ -1,18 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Copyright (C) 2015 Microchip Technology
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version 2
7
- * of the License, or (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
164 */
175 #include <linux/version.h>
186 #include <linux/module.h>
....@@ -25,6 +13,7 @@
2513 #include <linux/slab.h>
2614 #include <linux/if_vlan.h>
2715 #include <linux/uaccess.h>
16
+#include <linux/linkmode.h>
2817 #include <linux/list.h>
2918 #include <linux/ip.h>
3019 #include <linux/ipv6.h>
....@@ -1024,7 +1013,7 @@
10241013 static void lan78xx_set_addr_filter(struct lan78xx_priv *pdata,
10251014 int index, u8 addr[ETH_ALEN])
10261015 {
1027
- u32 temp;
1016
+ u32 temp;
10281017
10291018 if ((pdata) && (index > 0) && (index < NUM_OF_MAF)) {
10301019 temp = addr[3];
....@@ -1271,8 +1260,7 @@
12711260 return;
12721261 }
12731262
1274
- memcpy(&intdata, urb->transfer_buffer, 4);
1275
- le32_to_cpus(&intdata);
1263
+ intdata = get_unaligned_le32(urb->transfer_buffer);
12761264
12771265 if (intdata & INT_ENP_PHY_INT) {
12781266 netif_dbg(dev, link, dev->net, "PHY INTR: 0x%08x\n", intdata);
....@@ -1608,18 +1596,17 @@
16081596 dev->fc_request_control |= FLOW_CTRL_TX;
16091597
16101598 if (ecmd.base.autoneg) {
1599
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(fc) = { 0, };
16111600 u32 mii_adv;
1612
- u32 advertising;
16131601
1614
- ethtool_convert_link_mode_to_legacy_u32(
1615
- &advertising, ecmd.link_modes.advertising);
1616
-
1617
- advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
1602
+ linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT,
1603
+ ecmd.link_modes.advertising);
1604
+ linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
1605
+ ecmd.link_modes.advertising);
16181606 mii_adv = (u32)mii_advertise_flowctrl(dev->fc_request_control);
1619
- advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
1620
-
1621
- ethtool_convert_legacy_u32_to_link_mode(
1622
- ecmd.link_modes.advertising, advertising);
1607
+ mii_adv_to_linkmode_adv_t(fc, mii_adv);
1608
+ linkmode_or(ecmd.link_modes.advertising, fc,
1609
+ ecmd.link_modes.advertising);
16231610
16241611 phy_ethtool_ksettings_set(phydev, &ecmd);
16251612 }
....@@ -1682,14 +1669,6 @@
16821669 .get_regs_len = lan78xx_get_regs_len,
16831670 .get_regs = lan78xx_get_regs,
16841671 };
1685
-
1686
-static int lan78xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
1687
-{
1688
- if (!netif_running(netdev))
1689
- return -EINVAL;
1690
-
1691
- return phy_mii_ioctl(netdev->phydev, rq, cmd);
1692
-}
16931672
16941673 static void lan78xx_init_mac_address(struct lan78xx_net *dev)
16951674 {
....@@ -1847,8 +1826,7 @@
18471826
18481827 node = of_get_child_by_name(dev->udev->dev.of_node, "mdio");
18491828 ret = of_mdiobus_register(dev->mdiobus, node);
1850
- if (node)
1851
- of_node_put(node);
1829
+ of_node_put(node);
18521830 if (ret) {
18531831 netdev_err(dev->net, "can't register MDIO bus\n");
18541832 goto exit1;
....@@ -2075,8 +2053,7 @@
20752053 phydev = phy_find_first(dev->mdiobus);
20762054 if (!phydev) {
20772055 netdev_dbg(dev->net, "PHY Not Found!! Registering Fixed PHY\n");
2078
- phydev = fixed_phy_register(PHY_POLL, &fphy_status, -1,
2079
- NULL);
2056
+ phydev = fixed_phy_register(PHY_POLL, &fphy_status, NULL);
20802057 if (IS_ERR(phydev)) {
20812058 netdev_err(dev->net, "No PHY/fixed_PHY found\n");
20822059 return NULL;
....@@ -2119,6 +2096,7 @@
21192096
21202097 static int lan78xx_phy_init(struct lan78xx_net *dev)
21212098 {
2099
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(fc) = { 0, };
21222100 int ret;
21232101 u32 mii_adv;
21242102 struct phy_device *phydev;
....@@ -2178,13 +2156,17 @@
21782156 }
21792157
21802158 /* MAC doesn't support 1000T Half */
2181
- phydev->supported &= ~SUPPORTED_1000baseT_Half;
2159
+ phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
21822160
21832161 /* support both flow controls */
21842162 dev->fc_request_control = (FLOW_CTRL_RX | FLOW_CTRL_TX);
2185
- phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
2163
+ linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT,
2164
+ phydev->advertising);
2165
+ linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
2166
+ phydev->advertising);
21862167 mii_adv = (u32)mii_advertise_flowctrl(dev->fc_request_control);
2187
- phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
2168
+ mii_adv_to_linkmode_adv_t(fc, mii_adv);
2169
+ linkmode_or(phydev->advertising, fc, phydev->advertising);
21882170
21892171 if (phydev->mdio.dev.of_node) {
21902172 u32 reg;
....@@ -2706,7 +2688,7 @@
27062688
27072689 static int lan78xx_stop(struct net_device *net)
27082690 {
2709
- struct lan78xx_net *dev = netdev_priv(net);
2691
+ struct lan78xx_net *dev = netdev_priv(net);
27102692
27112693 if (timer_pending(&dev->stat_monitor))
27122694 del_timer_sync(&dev->stat_monitor);
....@@ -2745,6 +2727,7 @@
27452727 struct sk_buff *skb, gfp_t flags)
27462728 {
27472729 u32 tx_cmd_a, tx_cmd_b;
2730
+ void *ptr;
27482731
27492732 if (skb_cow_head(skb, TX_OVERHEAD)) {
27502733 dev_kfree_skb_any(skb);
....@@ -2775,13 +2758,9 @@
27752758 tx_cmd_b |= skb_vlan_tag_get(skb) & TX_CMD_B_VTAG_MASK_;
27762759 }
27772760
2778
- skb_push(skb, 4);
2779
- cpu_to_le32s(&tx_cmd_b);
2780
- memcpy(skb->data, &tx_cmd_b, 4);
2781
-
2782
- skb_push(skb, 4);
2783
- cpu_to_le32s(&tx_cmd_a);
2784
- memcpy(skb->data, &tx_cmd_a, 4);
2761
+ ptr = skb_push(skb, 8);
2762
+ put_unaligned_le32(tx_cmd_a, ptr);
2763
+ put_unaligned_le32(tx_cmd_b, ptr + 4);
27852764
27862765 return skb;
27872766 }
....@@ -3020,7 +2999,7 @@
30202999
30213000 static void lan78xx_skb_return(struct lan78xx_net *dev, struct sk_buff *skb)
30223001 {
3023
- int status;
3002
+ int status;
30243003
30253004 if (test_bit(EVENT_RX_PAUSED, &dev->flags)) {
30263005 skb_queue_tail(&dev->rxq_pause, skb);
....@@ -3056,16 +3035,13 @@
30563035 struct sk_buff *skb2;
30573036 unsigned char *packet;
30583037
3059
- memcpy(&rx_cmd_a, skb->data, sizeof(rx_cmd_a));
3060
- le32_to_cpus(&rx_cmd_a);
3038
+ rx_cmd_a = get_unaligned_le32(skb->data);
30613039 skb_pull(skb, sizeof(rx_cmd_a));
30623040
3063
- memcpy(&rx_cmd_b, skb->data, sizeof(rx_cmd_b));
3064
- le32_to_cpus(&rx_cmd_b);
3041
+ rx_cmd_b = get_unaligned_le32(skb->data);
30653042 skb_pull(skb, sizeof(rx_cmd_b));
30663043
3067
- memcpy(&rx_cmd_c, skb->data, sizeof(rx_cmd_c));
3068
- le16_to_cpus(&rx_cmd_c);
3044
+ rx_cmd_c = get_unaligned_le16(skb->data);
30693045 skb_pull(skb, sizeof(rx_cmd_c));
30703046
30713047 packet = skb->data;
....@@ -3226,7 +3202,7 @@
32263202 case -EPIPE:
32273203 dev->net->stats.rx_errors++;
32283204 lan78xx_defer_kevent(dev, EVENT_RX_HALT);
3229
- /* FALLTHROUGH */
3205
+ fallthrough;
32303206 case -ECONNRESET: /* async unlink */
32313207 case -ESHUTDOWN: /* hardware gone */
32323208 netif_dbg(dev, ifdown, dev->net,
....@@ -3247,7 +3223,7 @@
32473223 /* data overrun ... flush fifo? */
32483224 case -EOVERFLOW:
32493225 dev->net->stats.rx_over_errors++;
3250
- /* FALLTHROUGH */
3226
+ fallthrough;
32513227
32523228 default:
32533229 state = rx_cleanup;
....@@ -3287,9 +3263,9 @@
32873263 count = 0;
32883264 length = 0;
32893265 spin_lock_irqsave(&tqp->lock, flags);
3290
- for (skb = tqp->next; pkt_cnt < tqp->qlen; skb = skb->next) {
3266
+ skb_queue_walk(tqp, skb) {
32913267 if (skb_is_gso(skb)) {
3292
- if (pkt_cnt) {
3268
+ if (!skb_queue_is_first(tqp, skb)) {
32933269 /* handle previous packets first */
32943270 break;
32953271 }
....@@ -3580,10 +3556,10 @@
35803556
35813557 static void lan78xx_disconnect(struct usb_interface *intf)
35823558 {
3583
- struct lan78xx_net *dev;
3584
- struct usb_device *udev;
3585
- struct net_device *net;
3586
- struct phy_device *phydev;
3559
+ struct lan78xx_net *dev;
3560
+ struct usb_device *udev;
3561
+ struct net_device *net;
3562
+ struct phy_device *phydev;
35873563
35883564 dev = usb_get_intfdata(intf);
35893565 usb_set_intfdata(intf, NULL);
....@@ -3617,7 +3593,7 @@
36173593 usb_put_dev(udev);
36183594 }
36193595
3620
-static void lan78xx_tx_timeout(struct net_device *net)
3596
+static void lan78xx_tx_timeout(struct net_device *net, unsigned int txqueue)
36213597 {
36223598 struct lan78xx_net *dev = netdev_priv(net);
36233599
....@@ -3646,7 +3622,7 @@
36463622 .ndo_change_mtu = lan78xx_change_mtu,
36473623 .ndo_set_mac_address = lan78xx_set_mac_addr,
36483624 .ndo_validate_addr = eth_validate_addr,
3649
- .ndo_do_ioctl = lan78xx_ioctl,
3625
+ .ndo_do_ioctl = phy_do_ioctl_running,
36503626 .ndo_set_rx_mode = lan78xx_set_multicast,
36513627 .ndo_set_features = lan78xx_set_features,
36523628 .ndo_vlan_rx_add_vid = lan78xx_vlan_rx_add_vid,
....@@ -3744,7 +3720,6 @@
37443720 ret = lan78xx_bind(dev, intf);
37453721 if (ret < 0)
37463722 goto out2;
3747
- strcpy(netdev->name, "eth%d");
37483723
37493724 if (netdev->mtu > (dev->hard_mtu - netdev->hard_header_len))
37503725 netdev->mtu = dev->hard_mtu - netdev->hard_header_len;
....@@ -3991,9 +3966,6 @@
39913966 struct lan78xx_priv *pdata = (struct lan78xx_priv *)(dev->data[0]);
39923967 u32 buf;
39933968 int ret;
3994
- int event;
3995
-
3996
- event = message.event;
39973969
39983970 if (!dev->suspend_count++) {
39993971 spin_lock_irq(&dev->txq.lock);