| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 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/>. |
|---|
| 16 | 4 | */ |
|---|
| 17 | 5 | #include <linux/version.h> |
|---|
| 18 | 6 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 25 | 13 | #include <linux/slab.h> |
|---|
| 26 | 14 | #include <linux/if_vlan.h> |
|---|
| 27 | 15 | #include <linux/uaccess.h> |
|---|
| 16 | +#include <linux/linkmode.h> |
|---|
| 28 | 17 | #include <linux/list.h> |
|---|
| 29 | 18 | #include <linux/ip.h> |
|---|
| 30 | 19 | #include <linux/ipv6.h> |
|---|
| .. | .. |
|---|
| 1024 | 1013 | static void lan78xx_set_addr_filter(struct lan78xx_priv *pdata, |
|---|
| 1025 | 1014 | int index, u8 addr[ETH_ALEN]) |
|---|
| 1026 | 1015 | { |
|---|
| 1027 | | - u32 temp; |
|---|
| 1016 | + u32 temp; |
|---|
| 1028 | 1017 | |
|---|
| 1029 | 1018 | if ((pdata) && (index > 0) && (index < NUM_OF_MAF)) { |
|---|
| 1030 | 1019 | temp = addr[3]; |
|---|
| .. | .. |
|---|
| 1271 | 1260 | return; |
|---|
| 1272 | 1261 | } |
|---|
| 1273 | 1262 | |
|---|
| 1274 | | - memcpy(&intdata, urb->transfer_buffer, 4); |
|---|
| 1275 | | - le32_to_cpus(&intdata); |
|---|
| 1263 | + intdata = get_unaligned_le32(urb->transfer_buffer); |
|---|
| 1276 | 1264 | |
|---|
| 1277 | 1265 | if (intdata & INT_ENP_PHY_INT) { |
|---|
| 1278 | 1266 | netif_dbg(dev, link, dev->net, "PHY INTR: 0x%08x\n", intdata); |
|---|
| .. | .. |
|---|
| 1608 | 1596 | dev->fc_request_control |= FLOW_CTRL_TX; |
|---|
| 1609 | 1597 | |
|---|
| 1610 | 1598 | if (ecmd.base.autoneg) { |
|---|
| 1599 | + __ETHTOOL_DECLARE_LINK_MODE_MASK(fc) = { 0, }; |
|---|
| 1611 | 1600 | u32 mii_adv; |
|---|
| 1612 | | - u32 advertising; |
|---|
| 1613 | 1601 | |
|---|
| 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); |
|---|
| 1618 | 1606 | 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); |
|---|
| 1623 | 1610 | |
|---|
| 1624 | 1611 | phy_ethtool_ksettings_set(phydev, &ecmd); |
|---|
| 1625 | 1612 | } |
|---|
| .. | .. |
|---|
| 1682 | 1669 | .get_regs_len = lan78xx_get_regs_len, |
|---|
| 1683 | 1670 | .get_regs = lan78xx_get_regs, |
|---|
| 1684 | 1671 | }; |
|---|
| 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 | | -} |
|---|
| 1693 | 1672 | |
|---|
| 1694 | 1673 | static void lan78xx_init_mac_address(struct lan78xx_net *dev) |
|---|
| 1695 | 1674 | { |
|---|
| .. | .. |
|---|
| 1847 | 1826 | |
|---|
| 1848 | 1827 | node = of_get_child_by_name(dev->udev->dev.of_node, "mdio"); |
|---|
| 1849 | 1828 | ret = of_mdiobus_register(dev->mdiobus, node); |
|---|
| 1850 | | - if (node) |
|---|
| 1851 | | - of_node_put(node); |
|---|
| 1829 | + of_node_put(node); |
|---|
| 1852 | 1830 | if (ret) { |
|---|
| 1853 | 1831 | netdev_err(dev->net, "can't register MDIO bus\n"); |
|---|
| 1854 | 1832 | goto exit1; |
|---|
| .. | .. |
|---|
| 2075 | 2053 | phydev = phy_find_first(dev->mdiobus); |
|---|
| 2076 | 2054 | if (!phydev) { |
|---|
| 2077 | 2055 | 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); |
|---|
| 2080 | 2057 | if (IS_ERR(phydev)) { |
|---|
| 2081 | 2058 | netdev_err(dev->net, "No PHY/fixed_PHY found\n"); |
|---|
| 2082 | 2059 | return NULL; |
|---|
| .. | .. |
|---|
| 2119 | 2096 | |
|---|
| 2120 | 2097 | static int lan78xx_phy_init(struct lan78xx_net *dev) |
|---|
| 2121 | 2098 | { |
|---|
| 2099 | + __ETHTOOL_DECLARE_LINK_MODE_MASK(fc) = { 0, }; |
|---|
| 2122 | 2100 | int ret; |
|---|
| 2123 | 2101 | u32 mii_adv; |
|---|
| 2124 | 2102 | struct phy_device *phydev; |
|---|
| .. | .. |
|---|
| 2178 | 2156 | } |
|---|
| 2179 | 2157 | |
|---|
| 2180 | 2158 | /* MAC doesn't support 1000T Half */ |
|---|
| 2181 | | - phydev->supported &= ~SUPPORTED_1000baseT_Half; |
|---|
| 2159 | + phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT); |
|---|
| 2182 | 2160 | |
|---|
| 2183 | 2161 | /* support both flow controls */ |
|---|
| 2184 | 2162 | 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); |
|---|
| 2186 | 2167 | 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); |
|---|
| 2188 | 2170 | |
|---|
| 2189 | 2171 | if (phydev->mdio.dev.of_node) { |
|---|
| 2190 | 2172 | u32 reg; |
|---|
| .. | .. |
|---|
| 2706 | 2688 | |
|---|
| 2707 | 2689 | static int lan78xx_stop(struct net_device *net) |
|---|
| 2708 | 2690 | { |
|---|
| 2709 | | - struct lan78xx_net *dev = netdev_priv(net); |
|---|
| 2691 | + struct lan78xx_net *dev = netdev_priv(net); |
|---|
| 2710 | 2692 | |
|---|
| 2711 | 2693 | if (timer_pending(&dev->stat_monitor)) |
|---|
| 2712 | 2694 | del_timer_sync(&dev->stat_monitor); |
|---|
| .. | .. |
|---|
| 2745 | 2727 | struct sk_buff *skb, gfp_t flags) |
|---|
| 2746 | 2728 | { |
|---|
| 2747 | 2729 | u32 tx_cmd_a, tx_cmd_b; |
|---|
| 2730 | + void *ptr; |
|---|
| 2748 | 2731 | |
|---|
| 2749 | 2732 | if (skb_cow_head(skb, TX_OVERHEAD)) { |
|---|
| 2750 | 2733 | dev_kfree_skb_any(skb); |
|---|
| .. | .. |
|---|
| 2775 | 2758 | tx_cmd_b |= skb_vlan_tag_get(skb) & TX_CMD_B_VTAG_MASK_; |
|---|
| 2776 | 2759 | } |
|---|
| 2777 | 2760 | |
|---|
| 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); |
|---|
| 2785 | 2764 | |
|---|
| 2786 | 2765 | return skb; |
|---|
| 2787 | 2766 | } |
|---|
| .. | .. |
|---|
| 3020 | 2999 | |
|---|
| 3021 | 3000 | static void lan78xx_skb_return(struct lan78xx_net *dev, struct sk_buff *skb) |
|---|
| 3022 | 3001 | { |
|---|
| 3023 | | - int status; |
|---|
| 3002 | + int status; |
|---|
| 3024 | 3003 | |
|---|
| 3025 | 3004 | if (test_bit(EVENT_RX_PAUSED, &dev->flags)) { |
|---|
| 3026 | 3005 | skb_queue_tail(&dev->rxq_pause, skb); |
|---|
| .. | .. |
|---|
| 3056 | 3035 | struct sk_buff *skb2; |
|---|
| 3057 | 3036 | unsigned char *packet; |
|---|
| 3058 | 3037 | |
|---|
| 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); |
|---|
| 3061 | 3039 | skb_pull(skb, sizeof(rx_cmd_a)); |
|---|
| 3062 | 3040 | |
|---|
| 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); |
|---|
| 3065 | 3042 | skb_pull(skb, sizeof(rx_cmd_b)); |
|---|
| 3066 | 3043 | |
|---|
| 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); |
|---|
| 3069 | 3045 | skb_pull(skb, sizeof(rx_cmd_c)); |
|---|
| 3070 | 3046 | |
|---|
| 3071 | 3047 | packet = skb->data; |
|---|
| .. | .. |
|---|
| 3226 | 3202 | case -EPIPE: |
|---|
| 3227 | 3203 | dev->net->stats.rx_errors++; |
|---|
| 3228 | 3204 | lan78xx_defer_kevent(dev, EVENT_RX_HALT); |
|---|
| 3229 | | - /* FALLTHROUGH */ |
|---|
| 3205 | + fallthrough; |
|---|
| 3230 | 3206 | case -ECONNRESET: /* async unlink */ |
|---|
| 3231 | 3207 | case -ESHUTDOWN: /* hardware gone */ |
|---|
| 3232 | 3208 | netif_dbg(dev, ifdown, dev->net, |
|---|
| .. | .. |
|---|
| 3247 | 3223 | /* data overrun ... flush fifo? */ |
|---|
| 3248 | 3224 | case -EOVERFLOW: |
|---|
| 3249 | 3225 | dev->net->stats.rx_over_errors++; |
|---|
| 3250 | | - /* FALLTHROUGH */ |
|---|
| 3226 | + fallthrough; |
|---|
| 3251 | 3227 | |
|---|
| 3252 | 3228 | default: |
|---|
| 3253 | 3229 | state = rx_cleanup; |
|---|
| .. | .. |
|---|
| 3287 | 3263 | count = 0; |
|---|
| 3288 | 3264 | length = 0; |
|---|
| 3289 | 3265 | spin_lock_irqsave(&tqp->lock, flags); |
|---|
| 3290 | | - for (skb = tqp->next; pkt_cnt < tqp->qlen; skb = skb->next) { |
|---|
| 3266 | + skb_queue_walk(tqp, skb) { |
|---|
| 3291 | 3267 | if (skb_is_gso(skb)) { |
|---|
| 3292 | | - if (pkt_cnt) { |
|---|
| 3268 | + if (!skb_queue_is_first(tqp, skb)) { |
|---|
| 3293 | 3269 | /* handle previous packets first */ |
|---|
| 3294 | 3270 | break; |
|---|
| 3295 | 3271 | } |
|---|
| .. | .. |
|---|
| 3580 | 3556 | |
|---|
| 3581 | 3557 | static void lan78xx_disconnect(struct usb_interface *intf) |
|---|
| 3582 | 3558 | { |
|---|
| 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; |
|---|
| 3587 | 3563 | |
|---|
| 3588 | 3564 | dev = usb_get_intfdata(intf); |
|---|
| 3589 | 3565 | usb_set_intfdata(intf, NULL); |
|---|
| .. | .. |
|---|
| 3617 | 3593 | usb_put_dev(udev); |
|---|
| 3618 | 3594 | } |
|---|
| 3619 | 3595 | |
|---|
| 3620 | | -static void lan78xx_tx_timeout(struct net_device *net) |
|---|
| 3596 | +static void lan78xx_tx_timeout(struct net_device *net, unsigned int txqueue) |
|---|
| 3621 | 3597 | { |
|---|
| 3622 | 3598 | struct lan78xx_net *dev = netdev_priv(net); |
|---|
| 3623 | 3599 | |
|---|
| .. | .. |
|---|
| 3646 | 3622 | .ndo_change_mtu = lan78xx_change_mtu, |
|---|
| 3647 | 3623 | .ndo_set_mac_address = lan78xx_set_mac_addr, |
|---|
| 3648 | 3624 | .ndo_validate_addr = eth_validate_addr, |
|---|
| 3649 | | - .ndo_do_ioctl = lan78xx_ioctl, |
|---|
| 3625 | + .ndo_do_ioctl = phy_do_ioctl_running, |
|---|
| 3650 | 3626 | .ndo_set_rx_mode = lan78xx_set_multicast, |
|---|
| 3651 | 3627 | .ndo_set_features = lan78xx_set_features, |
|---|
| 3652 | 3628 | .ndo_vlan_rx_add_vid = lan78xx_vlan_rx_add_vid, |
|---|
| .. | .. |
|---|
| 3744 | 3720 | ret = lan78xx_bind(dev, intf); |
|---|
| 3745 | 3721 | if (ret < 0) |
|---|
| 3746 | 3722 | goto out2; |
|---|
| 3747 | | - strcpy(netdev->name, "eth%d"); |
|---|
| 3748 | 3723 | |
|---|
| 3749 | 3724 | if (netdev->mtu > (dev->hard_mtu - netdev->hard_header_len)) |
|---|
| 3750 | 3725 | netdev->mtu = dev->hard_mtu - netdev->hard_header_len; |
|---|
| .. | .. |
|---|
| 3991 | 3966 | struct lan78xx_priv *pdata = (struct lan78xx_priv *)(dev->data[0]); |
|---|
| 3992 | 3967 | u32 buf; |
|---|
| 3993 | 3968 | int ret; |
|---|
| 3994 | | - int event; |
|---|
| 3995 | | - |
|---|
| 3996 | | - event = message.event; |
|---|
| 3997 | 3969 | |
|---|
| 3998 | 3970 | if (!dev->suspend_count++) { |
|---|
| 3999 | 3971 | spin_lock_irq(&dev->txq.lock); |
|---|