Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ftmac100: allow increasing MTU to make most use of single-segment buffers

If the FTMAC100 is used as a DSA master, then it is expected that frames
which are MTU sized on the wire facing the external switch port (1500
octets in L2 payload, plus L2 header) also get a DSA tag when seen by
the host port.

This extra tag increases the length of the packet as the host port sees
it, and the FTMAC100 is not prepared to handle frames whose length
exceeds 1518 octets (including FCS) at all.

Only a minimal rework is needed to support this configuration. Since
MTU-sized DSA-tagged frames still fit within a single buffer (RX_BUF_SIZE),
we just need to optimize the resource management rather than implement
multi buffer RX.

In ndo_change_mtu(), we toggle the FTMAC100_MACCR_RX_FTL bit to tell the
hardware to drop (or not) frames with an L2 payload length larger than
1500. We need to replicate the MACCR configuration in ftmac100_start_hw()
as well, since there is a hardware reset there which clears previous
settings.

The advantage of dynamically changing FTMAC100_MACCR_RX_FTL is that when
dev->mtu is at the default value of 1500, large frames are automatically
dropped in hardware and we do not spend CPU cycles dropping them.

Suggested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Sergei Antonov <saproj@gmail.com>
Link: https://lore.kernel.org/r/20221028183220.155948-3-saproj@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Sergei Antonov and committed by
Jakub Kicinski
37c84890 30f837b7

+31 -2
+31 -2
drivers/net/ethernet/faraday/ftmac100.c
··· 11 11 #include <linux/dma-mapping.h> 12 12 #include <linux/etherdevice.h> 13 13 #include <linux/ethtool.h> 14 + #include <linux/if_ether.h> 14 15 #include <linux/if_vlan.h> 15 16 #include <linux/init.h> 16 17 #include <linux/interrupt.h> ··· 29 28 #define RX_QUEUE_ENTRIES 128 /* must be power of 2 */ 30 29 #define TX_QUEUE_ENTRIES 16 /* must be power of 2 */ 31 30 32 - #define MAX_PKT_SIZE 1518 33 31 #define RX_BUF_SIZE 2044 /* must be smaller than 0x7ff */ 32 + #define MAX_PKT_SIZE RX_BUF_SIZE /* multi-segment not supported */ 34 33 35 34 #if MAX_PKT_SIZE > 0x7ff 36 35 #error invalid MAX_PKT_SIZE ··· 161 160 static int ftmac100_start_hw(struct ftmac100 *priv) 162 161 { 163 162 struct net_device *netdev = priv->netdev; 163 + unsigned int maccr = MACCR_ENABLE_ALL; 164 164 165 165 if (ftmac100_reset(priv)) 166 166 return -EIO; ··· 178 176 179 177 ftmac100_set_mac(priv, netdev->dev_addr); 180 178 181 - iowrite32(MACCR_ENABLE_ALL, priv->base + FTMAC100_OFFSET_MACCR); 179 + /* See ftmac100_change_mtu() */ 180 + if (netdev->mtu > ETH_DATA_LEN) 181 + maccr |= FTMAC100_MACCR_RX_FTL; 182 + 183 + iowrite32(maccr, priv->base + FTMAC100_OFFSET_MACCR); 182 184 return 0; 183 185 } 184 186 ··· 1039 1033 return generic_mii_ioctl(&priv->mii, data, cmd, NULL); 1040 1034 } 1041 1035 1036 + static int ftmac100_change_mtu(struct net_device *netdev, int mtu) 1037 + { 1038 + struct ftmac100 *priv = netdev_priv(netdev); 1039 + unsigned int maccr; 1040 + 1041 + maccr = ioread32(priv->base + FTMAC100_OFFSET_MACCR); 1042 + if (mtu > ETH_DATA_LEN) { 1043 + /* process long packets in the driver */ 1044 + maccr |= FTMAC100_MACCR_RX_FTL; 1045 + } else { 1046 + /* Let the controller drop incoming packets greater 1047 + * than 1518 (that is 1500 + 14 Ethernet + 4 FCS). 1048 + */ 1049 + maccr &= ~FTMAC100_MACCR_RX_FTL; 1050 + } 1051 + iowrite32(maccr, priv->base + FTMAC100_OFFSET_MACCR); 1052 + 1053 + netdev->mtu = mtu; 1054 + 1055 + return 0; 1056 + } 1057 + 1042 1058 static const struct net_device_ops ftmac100_netdev_ops = { 1043 1059 .ndo_open = ftmac100_open, 1044 1060 .ndo_stop = ftmac100_stop, ··· 1068 1040 .ndo_set_mac_address = eth_mac_addr, 1069 1041 .ndo_validate_addr = eth_validate_addr, 1070 1042 .ndo_eth_ioctl = ftmac100_do_ioctl, 1043 + .ndo_change_mtu = ftmac100_change_mtu, 1071 1044 }; 1072 1045 1073 1046 /******************************************************************************