| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * drivers/net/ethernet/ibm/emac/core.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 16 | 17 | * (c) 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org> |
|---|
| 17 | 18 | * Armin Kuster <akuster@mvista.com> |
|---|
| 18 | 19 | * Johnnie Peters <jpeters@mvista.com> |
|---|
| 19 | | - * |
|---|
| 20 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 21 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 22 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 23 | | - * option) any later version. |
|---|
| 24 | | - * |
|---|
| 25 | 20 | */ |
|---|
| 26 | 21 | |
|---|
| 27 | 22 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 423 | 418 | { |
|---|
| 424 | 419 | const int regs = EMAC_XAHT_REGS(dev); |
|---|
| 425 | 420 | u32 *gaht_base = emac_gaht_base(dev); |
|---|
| 426 | | - u32 gaht_temp[regs]; |
|---|
| 421 | + u32 gaht_temp[EMAC_XAHT_MAX_REGS]; |
|---|
| 427 | 422 | struct netdev_hw_addr *ha; |
|---|
| 428 | 423 | int i; |
|---|
| 429 | 424 | |
|---|
| .. | .. |
|---|
| 781 | 776 | mutex_unlock(&dev->link_lock); |
|---|
| 782 | 777 | } |
|---|
| 783 | 778 | |
|---|
| 784 | | -static void emac_tx_timeout(struct net_device *ndev) |
|---|
| 779 | +static void emac_tx_timeout(struct net_device *ndev, unsigned int txqueue) |
|---|
| 785 | 780 | { |
|---|
| 786 | 781 | struct emac_instance *dev = netdev_priv(ndev); |
|---|
| 787 | 782 | |
|---|
| .. | .. |
|---|
| 877 | 872 | { |
|---|
| 878 | 873 | struct emac_regs __iomem *p = dev->emacp; |
|---|
| 879 | 874 | u32 r = 0; |
|---|
| 880 | | - int n, err = -ETIMEDOUT; |
|---|
| 875 | + int n; |
|---|
| 881 | 876 | |
|---|
| 882 | 877 | mutex_lock(&dev->mdio_lock); |
|---|
| 883 | 878 | |
|---|
| .. | .. |
|---|
| 924 | 919 | goto bail; |
|---|
| 925 | 920 | } |
|---|
| 926 | 921 | } |
|---|
| 927 | | - err = 0; |
|---|
| 928 | 922 | bail: |
|---|
| 929 | 923 | if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) |
|---|
| 930 | 924 | rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port); |
|---|
| .. | .. |
|---|
| 1071 | 1065 | |
|---|
| 1072 | 1066 | /* Second pass, allocate new skbs */ |
|---|
| 1073 | 1067 | for (i = 0; i < NUM_RX_BUFF; ++i) { |
|---|
| 1074 | | - struct sk_buff *skb = alloc_skb(rx_skb_size, GFP_ATOMIC); |
|---|
| 1068 | + struct sk_buff *skb; |
|---|
| 1069 | + |
|---|
| 1070 | + skb = netdev_alloc_skb_ip_align(dev->ndev, rx_skb_size); |
|---|
| 1075 | 1071 | if (!skb) { |
|---|
| 1076 | 1072 | ret = -ENOMEM; |
|---|
| 1077 | 1073 | goto oom; |
|---|
| .. | .. |
|---|
| 1080 | 1076 | BUG_ON(!dev->rx_skb[i]); |
|---|
| 1081 | 1077 | dev_kfree_skb(dev->rx_skb[i]); |
|---|
| 1082 | 1078 | |
|---|
| 1083 | | - skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2); |
|---|
| 1084 | 1079 | dev->rx_desc[i].data_ptr = |
|---|
| 1085 | | - dma_map_single(&dev->ofdev->dev, skb->data - 2, rx_sync_size, |
|---|
| 1086 | | - DMA_FROM_DEVICE) + 2; |
|---|
| 1080 | + dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, |
|---|
| 1081 | + rx_sync_size, DMA_FROM_DEVICE) |
|---|
| 1082 | + + NET_IP_ALIGN; |
|---|
| 1087 | 1083 | dev->rx_skb[i] = skb; |
|---|
| 1088 | 1084 | } |
|---|
| 1089 | 1085 | skip: |
|---|
| .. | .. |
|---|
| 1174 | 1170 | } |
|---|
| 1175 | 1171 | } |
|---|
| 1176 | 1172 | |
|---|
| 1177 | | -static inline int emac_alloc_rx_skb(struct emac_instance *dev, int slot, |
|---|
| 1178 | | - gfp_t flags) |
|---|
| 1173 | +static int |
|---|
| 1174 | +__emac_prepare_rx_skb(struct sk_buff *skb, struct emac_instance *dev, int slot) |
|---|
| 1179 | 1175 | { |
|---|
| 1180 | | - struct sk_buff *skb = alloc_skb(dev->rx_skb_size, flags); |
|---|
| 1181 | 1176 | if (unlikely(!skb)) |
|---|
| 1182 | 1177 | return -ENOMEM; |
|---|
| 1183 | 1178 | |
|---|
| 1184 | 1179 | dev->rx_skb[slot] = skb; |
|---|
| 1185 | 1180 | dev->rx_desc[slot].data_len = 0; |
|---|
| 1186 | 1181 | |
|---|
| 1187 | | - skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2); |
|---|
| 1188 | 1182 | dev->rx_desc[slot].data_ptr = |
|---|
| 1189 | | - dma_map_single(&dev->ofdev->dev, skb->data - 2, dev->rx_sync_size, |
|---|
| 1190 | | - DMA_FROM_DEVICE) + 2; |
|---|
| 1183 | + dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, |
|---|
| 1184 | + dev->rx_sync_size, DMA_FROM_DEVICE) + NET_IP_ALIGN; |
|---|
| 1191 | 1185 | wmb(); |
|---|
| 1192 | 1186 | dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY | |
|---|
| 1193 | 1187 | (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0); |
|---|
| 1194 | 1188 | |
|---|
| 1195 | 1189 | return 0; |
|---|
| 1190 | +} |
|---|
| 1191 | + |
|---|
| 1192 | +static int |
|---|
| 1193 | +emac_alloc_rx_skb(struct emac_instance *dev, int slot) |
|---|
| 1194 | +{ |
|---|
| 1195 | + struct sk_buff *skb; |
|---|
| 1196 | + |
|---|
| 1197 | + skb = __netdev_alloc_skb_ip_align(dev->ndev, dev->rx_skb_size, |
|---|
| 1198 | + GFP_KERNEL); |
|---|
| 1199 | + |
|---|
| 1200 | + return __emac_prepare_rx_skb(skb, dev, slot); |
|---|
| 1201 | +} |
|---|
| 1202 | + |
|---|
| 1203 | +static int |
|---|
| 1204 | +emac_alloc_rx_skb_napi(struct emac_instance *dev, int slot) |
|---|
| 1205 | +{ |
|---|
| 1206 | + struct sk_buff *skb; |
|---|
| 1207 | + |
|---|
| 1208 | + skb = napi_alloc_skb(&dev->mal->napi, dev->rx_skb_size); |
|---|
| 1209 | + |
|---|
| 1210 | + return __emac_prepare_rx_skb(skb, dev, slot); |
|---|
| 1196 | 1211 | } |
|---|
| 1197 | 1212 | |
|---|
| 1198 | 1213 | static void emac_print_link_status(struct emac_instance *dev) |
|---|
| .. | .. |
|---|
| 1225 | 1240 | |
|---|
| 1226 | 1241 | /* Allocate RX ring */ |
|---|
| 1227 | 1242 | for (i = 0; i < NUM_RX_BUFF; ++i) |
|---|
| 1228 | | - if (emac_alloc_rx_skb(dev, i, GFP_KERNEL)) { |
|---|
| 1243 | + if (emac_alloc_rx_skb(dev, i)) { |
|---|
| 1229 | 1244 | printk(KERN_ERR "%s: failed to allocate RX ring\n", |
|---|
| 1230 | 1245 | ndev->name); |
|---|
| 1231 | 1246 | goto oom; |
|---|
| .. | .. |
|---|
| 1533 | 1548 | ctrl); |
|---|
| 1534 | 1549 | /* skb fragments */ |
|---|
| 1535 | 1550 | for (i = 0; i < nr_frags; ++i) { |
|---|
| 1536 | | - struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i]; |
|---|
| 1551 | + skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
|---|
| 1537 | 1552 | len = skb_frag_size(frag); |
|---|
| 1538 | 1553 | |
|---|
| 1539 | 1554 | if (unlikely(dev->tx_cnt + mal_tx_chunks(len) >= NUM_TX_BUFF)) |
|---|
| .. | .. |
|---|
| 1660 | 1675 | DBG2(dev, "recycle %d %d" NL, slot, len); |
|---|
| 1661 | 1676 | |
|---|
| 1662 | 1677 | if (len) |
|---|
| 1663 | | - dma_map_single(&dev->ofdev->dev, skb->data - 2, |
|---|
| 1664 | | - EMAC_DMA_ALIGN(len + 2), DMA_FROM_DEVICE); |
|---|
| 1678 | + dma_map_single(&dev->ofdev->dev, skb->data - NET_IP_ALIGN, |
|---|
| 1679 | + SKB_DATA_ALIGN(len + NET_IP_ALIGN), |
|---|
| 1680 | + DMA_FROM_DEVICE); |
|---|
| 1665 | 1681 | |
|---|
| 1666 | 1682 | dev->rx_desc[slot].data_len = 0; |
|---|
| 1667 | 1683 | wmb(); |
|---|
| .. | .. |
|---|
| 1713 | 1729 | int len = dev->rx_desc[slot].data_len; |
|---|
| 1714 | 1730 | int tot_len = dev->rx_sg_skb->len + len; |
|---|
| 1715 | 1731 | |
|---|
| 1716 | | - if (unlikely(tot_len + 2 > dev->rx_skb_size)) { |
|---|
| 1732 | + if (unlikely(tot_len + NET_IP_ALIGN > dev->rx_skb_size)) { |
|---|
| 1717 | 1733 | ++dev->estats.rx_dropped_mtu; |
|---|
| 1718 | 1734 | dev_kfree_skb(dev->rx_sg_skb); |
|---|
| 1719 | 1735 | dev->rx_sg_skb = NULL; |
|---|
| .. | .. |
|---|
| 1769 | 1785 | } |
|---|
| 1770 | 1786 | |
|---|
| 1771 | 1787 | if (len && len < EMAC_RX_COPY_THRESH) { |
|---|
| 1772 | | - struct sk_buff *copy_skb = |
|---|
| 1773 | | - alloc_skb(len + EMAC_RX_SKB_HEADROOM + 2, GFP_ATOMIC); |
|---|
| 1788 | + struct sk_buff *copy_skb; |
|---|
| 1789 | + |
|---|
| 1790 | + copy_skb = napi_alloc_skb(&dev->mal->napi, len); |
|---|
| 1774 | 1791 | if (unlikely(!copy_skb)) |
|---|
| 1775 | 1792 | goto oom; |
|---|
| 1776 | 1793 | |
|---|
| 1777 | | - skb_reserve(copy_skb, EMAC_RX_SKB_HEADROOM + 2); |
|---|
| 1778 | | - memcpy(copy_skb->data - 2, skb->data - 2, len + 2); |
|---|
| 1794 | + memcpy(copy_skb->data - NET_IP_ALIGN, |
|---|
| 1795 | + skb->data - NET_IP_ALIGN, |
|---|
| 1796 | + len + NET_IP_ALIGN); |
|---|
| 1779 | 1797 | emac_recycle_rx_skb(dev, slot, len); |
|---|
| 1780 | 1798 | skb = copy_skb; |
|---|
| 1781 | | - } else if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC))) |
|---|
| 1799 | + } else if (unlikely(emac_alloc_rx_skb_napi(dev, slot))) |
|---|
| 1782 | 1800 | goto oom; |
|---|
| 1783 | 1801 | |
|---|
| 1784 | 1802 | skb_put(skb, len); |
|---|
| .. | .. |
|---|
| 1799 | 1817 | sg: |
|---|
| 1800 | 1818 | if (ctrl & MAL_RX_CTRL_FIRST) { |
|---|
| 1801 | 1819 | BUG_ON(dev->rx_sg_skb); |
|---|
| 1802 | | - if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC))) { |
|---|
| 1820 | + if (unlikely(emac_alloc_rx_skb_napi(dev, slot))) { |
|---|
| 1803 | 1821 | DBG(dev, "rx OOM %d" NL, slot); |
|---|
| 1804 | 1822 | ++dev->estats.rx_dropped_oom; |
|---|
| 1805 | 1823 | emac_recycle_rx_skb(dev, slot, 0); |
|---|
| .. | .. |
|---|
| 2301 | 2319 | switch (cmd) { |
|---|
| 2302 | 2320 | case SIOCGMIIPHY: |
|---|
| 2303 | 2321 | data->phy_id = dev->phy.address; |
|---|
| 2304 | | - /* Fall through */ |
|---|
| 2322 | + fallthrough; |
|---|
| 2305 | 2323 | case SIOCGMIIREG: |
|---|
| 2306 | 2324 | data->val_out = emac_mdio_read(ndev, dev->phy.address, |
|---|
| 2307 | 2325 | data->reg_num); |
|---|
| .. | .. |
|---|
| 2455 | 2473 | dev->phy.duplex = phy->duplex; |
|---|
| 2456 | 2474 | dev->phy.pause = phy->pause; |
|---|
| 2457 | 2475 | dev->phy.asym_pause = phy->asym_pause; |
|---|
| 2458 | | - dev->phy.advertising = phy->advertising; |
|---|
| 2476 | + ethtool_convert_link_mode_to_legacy_u32(&dev->phy.advertising, |
|---|
| 2477 | + phy->advertising); |
|---|
| 2459 | 2478 | } |
|---|
| 2460 | 2479 | |
|---|
| 2461 | 2480 | static int emac_mii_bus_read(struct mii_bus *bus, int addr, int regnum) |
|---|
| .. | .. |
|---|
| 2490 | 2509 | phy_dev->autoneg = phy->autoneg; |
|---|
| 2491 | 2510 | phy_dev->speed = phy->speed; |
|---|
| 2492 | 2511 | phy_dev->duplex = phy->duplex; |
|---|
| 2493 | | - phy_dev->advertising = phy->advertising; |
|---|
| 2512 | + ethtool_convert_legacy_u32_to_link_mode(phy_dev->advertising, |
|---|
| 2513 | + phy->advertising); |
|---|
| 2494 | 2514 | return phy_start_aneg(phy_dev); |
|---|
| 2495 | 2515 | } |
|---|
| 2496 | 2516 | |
|---|
| .. | .. |
|---|
| 2624 | 2644 | dev->phy.def->phy_id_mask = dev->phy_dev->drv->phy_id_mask; |
|---|
| 2625 | 2645 | dev->phy.def->name = dev->phy_dev->drv->name; |
|---|
| 2626 | 2646 | dev->phy.def->ops = &emac_dt_mdio_phy_ops; |
|---|
| 2627 | | - dev->phy.features = dev->phy_dev->supported; |
|---|
| 2647 | + ethtool_convert_link_mode_to_legacy_u32(&dev->phy.features, |
|---|
| 2648 | + dev->phy_dev->supported); |
|---|
| 2628 | 2649 | dev->phy.address = dev->phy_dev->mdio.addr; |
|---|
| 2629 | 2650 | dev->phy.mode = dev->phy_dev->interface; |
|---|
| 2630 | 2651 | return 0; |
|---|
| .. | .. |
|---|
| 2827 | 2848 | { |
|---|
| 2828 | 2849 | struct device_node *np = dev->ofdev->dev.of_node; |
|---|
| 2829 | 2850 | const void *p; |
|---|
| 2851 | + int err; |
|---|
| 2830 | 2852 | |
|---|
| 2831 | 2853 | /* Read config from device-tree */ |
|---|
| 2832 | 2854 | if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1)) |
|---|
| .. | .. |
|---|
| 2875 | 2897 | dev->mal_burst_size = 256; |
|---|
| 2876 | 2898 | |
|---|
| 2877 | 2899 | /* PHY mode needs some decoding */ |
|---|
| 2878 | | - dev->phy_mode = of_get_phy_mode(np); |
|---|
| 2879 | | - if (dev->phy_mode < 0) |
|---|
| 2900 | + err = of_get_phy_mode(np, &dev->phy_mode); |
|---|
| 2901 | + if (err) |
|---|
| 2880 | 2902 | dev->phy_mode = PHY_INTERFACE_MODE_NA; |
|---|
| 2881 | 2903 | |
|---|
| 2882 | 2904 | /* Check EMAC version */ |
|---|
| .. | .. |
|---|
| 2970 | 2992 | dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT; |
|---|
| 2971 | 2993 | } |
|---|
| 2972 | 2994 | |
|---|
| 2995 | + /* This should never happen */ |
|---|
| 2996 | + if (WARN_ON(EMAC_XAHT_REGS(dev) > EMAC_XAHT_MAX_REGS)) |
|---|
| 2997 | + return -ENXIO; |
|---|
| 2998 | + |
|---|
| 2973 | 2999 | DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE); |
|---|
| 2974 | 3000 | DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige); |
|---|
| 2975 | 3001 | DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige); |
|---|