#include <linux/pm_domain.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
+#include <linux/version.h>
-/* MTU */
-#define ENETSW_TAG_SIZE (6 + VLAN_HLEN)
-#define ENETSW_MTU_OVERHEAD (VLAN_ETH_HLEN + VLAN_HLEN + \
- ENETSW_TAG_SIZE)
+/* TODO: Bigger frames may work but we do not trust that they are safe on all
+ * platforms so more research is needed, a max frame size of 2048 has been
+ * tested. We use the safe frame size 1542 which is 1532 plus DSA and VLAN
+ * overhead.
+ */
+#define ENETSW_MAX_FRAME 1542
+#define ENETSW_DSA_TAG_SIZE 6
+/* The MTU in Linux does not include ethernet or VLAN headers, but it DOES
+ * include the DSA overhead (the framework will increase the MTU to fit
+ * any DSA header).
+ */
+#define ENETSW_MAX_MTU (ENETSW_MAX_FRAME - VLAN_ETH_HLEN - \
+ VLAN_HLEN)
#define ENETSW_FRAG_SIZE(x) (SKB_DATA_ALIGN(NET_SKB_PAD + x + \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))))
struct bcm6368_enetsw *priv;
struct net_device *ndev;
struct resource *res;
+ unsigned char dev_addr[ETH_ALEN];
unsigned i;
int num_resets;
int ret;
priv->tx_ring_size = ENETSW_DEF_TX_DESC;
priv->copybreak = ENETSW_DEF_CPY_BREAK;
- of_get_mac_address(node, ndev->dev_addr);
- if (is_valid_ether_addr(ndev->dev_addr)) {
- dev_info(dev, "mtd mac %pM\n", ndev->dev_addr);
+ of_get_mac_address(node, dev_addr);
+ if (is_valid_ether_addr(dev_addr)) {
+ dev_addr_set(ndev, dev_addr);
+ dev_info(dev, "mtd mac %pM\n", dev_addr);
} else {
- random_ether_addr(ndev->dev_addr);
- dev_info(dev, "random mac %pM\n", ndev->dev_addr);
+ eth_hw_addr_random(ndev);
+ dev_info(dev, "random mac\n");
}
- priv->rx_buf_size = ALIGN(ndev->mtu + ENETSW_MTU_OVERHEAD,
+ priv->rx_buf_size = ALIGN(ENETSW_MAX_FRAME,
ENETSW_DMA_MAXBURST * 4);
priv->rx_frag_size = ENETSW_FRAG_SIZE(priv->rx_buf_size);
/* register netdevice */
ndev->netdev_ops = &bcm6368_enetsw_ops;
ndev->min_mtu = ETH_ZLEN;
- ndev->mtu = ETH_DATA_LEN + ENETSW_TAG_SIZE;
- ndev->max_mtu = ETH_DATA_LEN + ENETSW_TAG_SIZE;
+ ndev->mtu = ETH_DATA_LEN;
+ ndev->max_mtu = ENETSW_MAX_MTU;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0)
+ netif_napi_add(ndev, &priv->napi, bcm6368_enetsw_poll);
+#else
netif_napi_add(ndev, &priv->napi, bcm6368_enetsw_poll, 16);
+#endif
ret = devm_register_netdev(dev, ndev);
if (ret) {