hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/ibm/emac/core.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * drivers/net/ethernet/ibm/emac/core.c
34 *
....@@ -16,12 +17,6 @@
1617 * (c) 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org>
1718 * Armin Kuster <akuster@mvista.com>
1819 * 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
- *
2520 */
2621
2722 #include <linux/module.h>
....@@ -423,7 +418,7 @@
423418 {
424419 const int regs = EMAC_XAHT_REGS(dev);
425420 u32 *gaht_base = emac_gaht_base(dev);
426
- u32 gaht_temp[regs];
421
+ u32 gaht_temp[EMAC_XAHT_MAX_REGS];
427422 struct netdev_hw_addr *ha;
428423 int i;
429424
....@@ -781,7 +776,7 @@
781776 mutex_unlock(&dev->link_lock);
782777 }
783778
784
-static void emac_tx_timeout(struct net_device *ndev)
779
+static void emac_tx_timeout(struct net_device *ndev, unsigned int txqueue)
785780 {
786781 struct emac_instance *dev = netdev_priv(ndev);
787782
....@@ -877,7 +872,7 @@
877872 {
878873 struct emac_regs __iomem *p = dev->emacp;
879874 u32 r = 0;
880
- int n, err = -ETIMEDOUT;
875
+ int n;
881876
882877 mutex_lock(&dev->mdio_lock);
883878
....@@ -924,7 +919,6 @@
924919 goto bail;
925920 }
926921 }
927
- err = 0;
928922 bail:
929923 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII))
930924 rgmii_put_mdio(dev->rgmii_dev, dev->rgmii_port);
....@@ -1071,7 +1065,9 @@
10711065
10721066 /* Second pass, allocate new skbs */
10731067 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);
10751071 if (!skb) {
10761072 ret = -ENOMEM;
10771073 goto oom;
....@@ -1080,10 +1076,10 @@
10801076 BUG_ON(!dev->rx_skb[i]);
10811077 dev_kfree_skb(dev->rx_skb[i]);
10821078
1083
- skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2);
10841079 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;
10871083 dev->rx_skb[i] = skb;
10881084 }
10891085 skip:
....@@ -1174,25 +1170,44 @@
11741170 }
11751171 }
11761172
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)
11791175 {
1180
- struct sk_buff *skb = alloc_skb(dev->rx_skb_size, flags);
11811176 if (unlikely(!skb))
11821177 return -ENOMEM;
11831178
11841179 dev->rx_skb[slot] = skb;
11851180 dev->rx_desc[slot].data_len = 0;
11861181
1187
- skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2);
11881182 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;
11911185 wmb();
11921186 dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY |
11931187 (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0);
11941188
11951189 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);
11961211 }
11971212
11981213 static void emac_print_link_status(struct emac_instance *dev)
....@@ -1225,7 +1240,7 @@
12251240
12261241 /* Allocate RX ring */
12271242 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)) {
12291244 printk(KERN_ERR "%s: failed to allocate RX ring\n",
12301245 ndev->name);
12311246 goto oom;
....@@ -1533,7 +1548,7 @@
15331548 ctrl);
15341549 /* skb fragments */
15351550 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];
15371552 len = skb_frag_size(frag);
15381553
15391554 if (unlikely(dev->tx_cnt + mal_tx_chunks(len) >= NUM_TX_BUFF))
....@@ -1660,8 +1675,9 @@
16601675 DBG2(dev, "recycle %d %d" NL, slot, len);
16611676
16621677 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);
16651681
16661682 dev->rx_desc[slot].data_len = 0;
16671683 wmb();
....@@ -1713,7 +1729,7 @@
17131729 int len = dev->rx_desc[slot].data_len;
17141730 int tot_len = dev->rx_sg_skb->len + len;
17151731
1716
- if (unlikely(tot_len + 2 > dev->rx_skb_size)) {
1732
+ if (unlikely(tot_len + NET_IP_ALIGN > dev->rx_skb_size)) {
17171733 ++dev->estats.rx_dropped_mtu;
17181734 dev_kfree_skb(dev->rx_sg_skb);
17191735 dev->rx_sg_skb = NULL;
....@@ -1769,16 +1785,18 @@
17691785 }
17701786
17711787 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);
17741791 if (unlikely(!copy_skb))
17751792 goto oom;
17761793
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);
17791797 emac_recycle_rx_skb(dev, slot, len);
17801798 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)))
17821800 goto oom;
17831801
17841802 skb_put(skb, len);
....@@ -1799,7 +1817,7 @@
17991817 sg:
18001818 if (ctrl & MAL_RX_CTRL_FIRST) {
18011819 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))) {
18031821 DBG(dev, "rx OOM %d" NL, slot);
18041822 ++dev->estats.rx_dropped_oom;
18051823 emac_recycle_rx_skb(dev, slot, 0);
....@@ -2301,7 +2319,7 @@
23012319 switch (cmd) {
23022320 case SIOCGMIIPHY:
23032321 data->phy_id = dev->phy.address;
2304
- /* Fall through */
2322
+ fallthrough;
23052323 case SIOCGMIIREG:
23062324 data->val_out = emac_mdio_read(ndev, dev->phy.address,
23072325 data->reg_num);
....@@ -2455,7 +2473,8 @@
24552473 dev->phy.duplex = phy->duplex;
24562474 dev->phy.pause = phy->pause;
24572475 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);
24592478 }
24602479
24612480 static int emac_mii_bus_read(struct mii_bus *bus, int addr, int regnum)
....@@ -2490,7 +2509,8 @@
24902509 phy_dev->autoneg = phy->autoneg;
24912510 phy_dev->speed = phy->speed;
24922511 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);
24942514 return phy_start_aneg(phy_dev);
24952515 }
24962516
....@@ -2624,7 +2644,8 @@
26242644 dev->phy.def->phy_id_mask = dev->phy_dev->drv->phy_id_mask;
26252645 dev->phy.def->name = dev->phy_dev->drv->name;
26262646 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);
26282649 dev->phy.address = dev->phy_dev->mdio.addr;
26292650 dev->phy.mode = dev->phy_dev->interface;
26302651 return 0;
....@@ -2827,6 +2848,7 @@
28272848 {
28282849 struct device_node *np = dev->ofdev->dev.of_node;
28292850 const void *p;
2851
+ int err;
28302852
28312853 /* Read config from device-tree */
28322854 if (emac_read_uint_prop(np, "mal-device", &dev->mal_ph, 1))
....@@ -2875,8 +2897,8 @@
28752897 dev->mal_burst_size = 256;
28762898
28772899 /* 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)
28802902 dev->phy_mode = PHY_INTERFACE_MODE_NA;
28812903
28822904 /* Check EMAC version */
....@@ -2970,6 +2992,10 @@
29702992 dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT;
29712993 }
29722994
2995
+ /* This should never happen */
2996
+ if (WARN_ON(EMAC_XAHT_REGS(dev) > EMAC_XAHT_MAX_REGS))
2997
+ return -ENXIO;
2998
+
29732999 DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE);
29743000 DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige);
29753001 DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige);