bmips: bcm6368-enetsw: Bump max MTU
[openwrt/staging/nbd.git] / target / linux / bmips / files / drivers / net / ethernet / broadcom / bcm6368-enetsw.c
index 124baee9b412778c07de35c0c744f2600fc3f03f..b72a788378fa717d13ba988dd2d9e20c0551f3aa 100644 (file)
 #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))))
 
@@ -908,6 +918,7 @@ static int bcm6368_enetsw_probe(struct platform_device *pdev)
        struct bcm6368_enetsw *priv;
        struct net_device *ndev;
        struct resource *res;
+       unsigned char dev_addr[ETH_ALEN];
        unsigned i;
        int num_resets;
        int ret;
@@ -995,15 +1006,16 @@ static int bcm6368_enetsw_probe(struct platform_device *pdev)
        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);
@@ -1063,9 +1075,13 @@ static int bcm6368_enetsw_probe(struct platform_device *pdev)
        /* 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) {
@@ -1130,3 +1146,8 @@ static struct platform_driver bcm6368_enetsw_driver = {
        .remove = bcm6368_enetsw_remove,
 };
 module_platform_driver(bcm6368_enetsw_driver);
+
+MODULE_AUTHOR("Álvaro Fernández Rojas <noltari@gmail.com>");
+MODULE_DESCRIPTION("BCM6368 Ethernet Switch Controller Driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:bcm6368-enetsw");