15
15
#include <linux/bitops.h>
16
16
#include <linux/etherdevice.h>
17
17
#include <linux/if_bridge.h>
18
+ #include <linux/if_vlan.h>
18
19
#include <linux/interrupt.h>
19
20
#include <linux/irqdomain.h>
20
21
#include <linux/irqchip/chained_irq.h>
117
118
RTL8366RB_STP_STATE((port), RTL8366RB_STP_MASK)
118
119
119
120
/* 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
122
123
/* 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
124
126
125
127
#define RTL8366RB_SMAR0 0x0070 /* bits 0..15 */
126
128
#define RTL8366RB_SMAR1 0x0071 /* bits 16..31 */
@@ -912,10 +914,10 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
912
914
913
915
/* Enable CPU port with custom DSA tag 8899.
914
916
*
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
916
918
* the custom tag is turned off.
917
919
*/
918
- ret = regmap_update_bits (priv -> map , RTL8368RB_CPU_CTRL_REG ,
920
+ ret = regmap_update_bits (priv -> map , RTL8366RB_CPU_CTRL_REG ,
919
921
0xFFFF ,
920
922
BIT (priv -> cpu_port ));
921
923
if (ret )
@@ -928,15 +930,19 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
928
930
if (ret )
929
931
return ret ;
930
932
931
- /* Set maximum packet length to 1536 bytes */
933
+ /* Set default maximum packet length to 1536 bytes */
932
934
ret = regmap_update_bits (priv -> map , RTL8366RB_SGCR ,
933
935
RTL8366RB_SGCR_MAX_LENGTH_MASK ,
934
936
RTL8366RB_SGCR_MAX_LENGTH_1536 );
935
937
if (ret )
936
938
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
+ }
940
946
941
947
/* Disable learning for all ports */
942
948
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)
1441
1447
/* Roof out the MTU for the entire switch to the greatest
1442
1448
* common denominator: the biggest set for any one port will
1443
1449
* 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.
1451
1450
*/
1452
- max_mtu = 1518 ;
1451
+ max_mtu = ETH_DATA_LEN ;
1453
1452
for (i = 0 ; i < RTL8366RB_NUM_PORTS ; i ++ ) {
1454
1453
if (rb -> max_mtu [i ] > max_mtu )
1455
1454
max_mtu = rb -> max_mtu [i ];
1456
1455
}
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 )
1458
1465
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
+ */
1460
1471
len = RTL8366RB_SGCR_MAX_LENGTH_1536 ;
1461
- else if (max_mtu > 1532 && max_mtu <= 1548 )
1472
+ else if (max_mtu > 1536 && max_mtu <= 1552 )
1462
1473
len = RTL8366RB_SGCR_MAX_LENGTH_1552 ;
1463
1474
else
1464
1475
len = RTL8366RB_SGCR_MAX_LENGTH_16000 ;
@@ -1470,10 +1481,12 @@ static int rtl8366rb_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
1470
1481
1471
1482
static int rtl8366rb_max_mtu (struct dsa_switch * ds , int port )
1472
1483
{
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.
1475
1488
*/
1476
- return 15996 ;
1489
+ return 16000 - VLAN_ETH_HLEN - ETH_FCS_LEN ;
1477
1490
}
1478
1491
1479
1492
static int rtl8366rb_get_vlan_4k (struct realtek_priv * priv , u32 vid ,
0 commit comments