1515#include <linux/bitops.h>
1616#include <linux/etherdevice.h>
1717#include <linux/if_bridge.h>
18+ #include <linux/if_vlan.h>
1819#include <linux/interrupt.h>
1920#include <linux/irqdomain.h>
2021#include <linux/irqchip/chained_irq.h>
117118 RTL8366RB_STP_STATE((port), RTL8366RB_STP_MASK)
118119
119120/* CPU port control reg */
120- #define RTL8368RB_CPU_CTRL_REG 0x0061
121- #define RTL8368RB_CPU_PORTS_MSK 0x00FF
121+ #define RTL8366RB_CPU_CTRL_REG 0x0061
122+ #define RTL8366RB_CPU_PORTS_MSK 0x00FF
122123/* Disables inserting custom tag length/type 0x8899 */
123- #define RTL8368RB_CPU_NO_TAG BIT(15)
124+ #define RTL8366RB_CPU_NO_TAG BIT(15)
125+ #define RTL8366RB_CPU_TAG_SIZE 4
124126
125127#define RTL8366RB_SMAR0 0x0070 /* bits 0..15 */
126128#define RTL8366RB_SMAR1 0x0071 /* bits 16..31 */
@@ -912,10 +914,10 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
912914
913915 /* Enable CPU port with custom DSA tag 8899.
914916 *
915- * If you set RTL8368RB_CPU_NO_TAG (bit 15) in this registers
917+ * If you set RTL8366RB_CPU_NO_TAG (bit 15) in this register
916918 * the custom tag is turned off.
917919 */
918- ret = regmap_update_bits (priv -> map , RTL8368RB_CPU_CTRL_REG ,
920+ ret = regmap_update_bits (priv -> map , RTL8366RB_CPU_CTRL_REG ,
919921 0xFFFF ,
920922 BIT (priv -> cpu_port ));
921923 if (ret )
@@ -928,15 +930,19 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
928930 if (ret )
929931 return ret ;
930932
931- /* Set maximum packet length to 1536 bytes */
933+ /* Set default maximum packet length to 1536 bytes */
932934 ret = regmap_update_bits (priv -> map , RTL8366RB_SGCR ,
933935 RTL8366RB_SGCR_MAX_LENGTH_MASK ,
934936 RTL8366RB_SGCR_MAX_LENGTH_1536 );
935937 if (ret )
936938 return ret ;
937- for (i = 0 ; i < RTL8366RB_NUM_PORTS ; i ++ )
938- /* layer 2 size, see rtl8366rb_change_mtu() */
939- rb -> max_mtu [i ] = 1532 ;
939+ for (i = 0 ; i < RTL8366RB_NUM_PORTS ; i ++ ) {
940+ if (i == priv -> cpu_port )
941+ /* CPU port need to also accept the tag */
942+ rb -> max_mtu [i ] = ETH_DATA_LEN + RTL8366RB_CPU_TAG_SIZE ;
943+ else
944+ rb -> max_mtu [i ] = ETH_DATA_LEN ;
945+ }
940946
941947 /* Disable learning for all ports */
942948 ret = regmap_write (priv -> map , RTL8366RB_PORT_LEARNDIS_CTRL ,
@@ -1441,24 +1447,29 @@ static int rtl8366rb_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
14411447 /* Roof out the MTU for the entire switch to the greatest
14421448 * common denominator: the biggest set for any one port will
14431449 * be the biggest MTU for the switch.
1444- *
1445- * The first setting, 1522 bytes, is max IP packet 1500 bytes,
1446- * plus ethernet header, 1518 bytes, plus CPU tag, 4 bytes.
1447- * This function should consider the parameter an SDU, so the
1448- * MTU passed for this setting is 1518 bytes. The same logic
1449- * of subtracting the DSA tag of 4 bytes apply to the other
1450- * settings.
14511450 */
1452- max_mtu = 1518 ;
1451+ max_mtu = ETH_DATA_LEN ;
14531452 for (i = 0 ; i < RTL8366RB_NUM_PORTS ; i ++ ) {
14541453 if (rb -> max_mtu [i ] > max_mtu )
14551454 max_mtu = rb -> max_mtu [i ];
14561455 }
1457- if (max_mtu <= 1518 )
1456+
1457+ /* Translate to layer 2 size.
1458+ * Add ethernet and (possible) VLAN headers, and checksum to the size.
1459+ * For ETH_DATA_LEN (1500 bytes) this will add up to 1522 bytes.
1460+ */
1461+ max_mtu += VLAN_ETH_HLEN ;
1462+ max_mtu += ETH_FCS_LEN ;
1463+
1464+ if (max_mtu <= 1522 )
14581465 len = RTL8366RB_SGCR_MAX_LENGTH_1522 ;
1459- else if (max_mtu > 1518 && max_mtu <= 1532 )
1466+ else if (max_mtu > 1522 && max_mtu <= 1536 )
1467+ /* This will be the most common default if using VLAN and
1468+ * CPU tagging on a port as both VLAN and CPU tag will
1469+ * result in 1518 + 4 + 4 = 1526 bytes.
1470+ */
14601471 len = RTL8366RB_SGCR_MAX_LENGTH_1536 ;
1461- else if (max_mtu > 1532 && max_mtu <= 1548 )
1472+ else if (max_mtu > 1536 && max_mtu <= 1552 )
14621473 len = RTL8366RB_SGCR_MAX_LENGTH_1552 ;
14631474 else
14641475 len = RTL8366RB_SGCR_MAX_LENGTH_16000 ;
@@ -1470,10 +1481,12 @@ static int rtl8366rb_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
14701481
14711482static int rtl8366rb_max_mtu (struct dsa_switch * ds , int port )
14721483{
1473- /* The max MTU is 16000 bytes, so we subtract the CPU tag
1474- * and the max presented to the system is 15996 bytes.
1484+ /* The max MTU is 16000 bytes, so we subtract the ethernet
1485+ * headers with VLAN and checksum and arrive at
1486+ * 16000 - 18 - 4 = 15978. This does not include the CPU tag
1487+ * since that is added to the requested MTU by the DSA framework.
14751488 */
1476- return 15996 ;
1489+ return 16000 - VLAN_ETH_HLEN - ETH_FCS_LEN ;
14771490}
14781491
14791492static int rtl8366rb_get_vlan_4k (struct realtek_priv * priv , u32 vid ,
0 commit comments