22/*
33 * Microchip switch driver main logic
44 *
5- * Copyright (C) 2017-2019 Microchip Technology Inc.
5+ * Copyright (C) 2017-2024 Microchip Technology Inc.
66 */
77
88#include <linux/delay.h>
@@ -277,7 +277,7 @@ static const struct phylink_mac_ops ksz8_phylink_mac_ops = {
277277 .mac_link_up = ksz8_phylink_mac_link_up ,
278278};
279279
280- static const struct ksz_dev_ops ksz88x3_dev_ops = {
280+ static const struct ksz_dev_ops ksz88xx_dev_ops = {
281281 .setup = ksz8_setup ,
282282 .get_port_addr = ksz8_get_port_addr ,
283283 .cfg_port_member = ksz8_cfg_port_member ,
@@ -572,6 +572,61 @@ static u8 ksz8863_shifts[] = {
572572 [DYNAMIC_MAC_SRC_PORT ] = 20 ,
573573};
574574
575+ static const u16 ksz8895_regs [] = {
576+ [REG_SW_MAC_ADDR ] = 0x68 ,
577+ [REG_IND_CTRL_0 ] = 0x6E ,
578+ [REG_IND_DATA_8 ] = 0x70 ,
579+ [REG_IND_DATA_CHECK ] = 0x72 ,
580+ [REG_IND_DATA_HI ] = 0x71 ,
581+ [REG_IND_DATA_LO ] = 0x75 ,
582+ [REG_IND_MIB_CHECK ] = 0x75 ,
583+ [P_FORCE_CTRL ] = 0x0C ,
584+ [P_LINK_STATUS ] = 0x0E ,
585+ [P_LOCAL_CTRL ] = 0x0C ,
586+ [P_NEG_RESTART_CTRL ] = 0x0D ,
587+ [P_REMOTE_STATUS ] = 0x0E ,
588+ [P_SPEED_STATUS ] = 0x09 ,
589+ [S_TAIL_TAG_CTRL ] = 0x0C ,
590+ [P_STP_CTRL ] = 0x02 ,
591+ [S_START_CTRL ] = 0x01 ,
592+ [S_BROADCAST_CTRL ] = 0x06 ,
593+ [S_MULTICAST_CTRL ] = 0x04 ,
594+ };
595+
596+ static const u32 ksz8895_masks [] = {
597+ [PORT_802_1P_REMAPPING ] = BIT (7 ),
598+ [SW_TAIL_TAG_ENABLE ] = BIT (1 ),
599+ [MIB_COUNTER_OVERFLOW ] = BIT (7 ),
600+ [MIB_COUNTER_VALID ] = BIT (6 ),
601+ [VLAN_TABLE_FID ] = GENMASK (6 , 0 ),
602+ [VLAN_TABLE_MEMBERSHIP ] = GENMASK (11 , 7 ),
603+ [VLAN_TABLE_VALID ] = BIT (12 ),
604+ [STATIC_MAC_TABLE_VALID ] = BIT (21 ),
605+ [STATIC_MAC_TABLE_USE_FID ] = BIT (23 ),
606+ [STATIC_MAC_TABLE_FID ] = GENMASK (30 , 24 ),
607+ [STATIC_MAC_TABLE_OVERRIDE ] = BIT (22 ),
608+ [STATIC_MAC_TABLE_FWD_PORTS ] = GENMASK (20 , 16 ),
609+ [DYNAMIC_MAC_TABLE_ENTRIES_H ] = GENMASK (6 , 0 ),
610+ [DYNAMIC_MAC_TABLE_MAC_EMPTY ] = BIT (7 ),
611+ [DYNAMIC_MAC_TABLE_NOT_READY ] = BIT (7 ),
612+ [DYNAMIC_MAC_TABLE_ENTRIES ] = GENMASK (31 , 29 ),
613+ [DYNAMIC_MAC_TABLE_FID ] = GENMASK (22 , 16 ),
614+ [DYNAMIC_MAC_TABLE_SRC_PORT ] = GENMASK (26 , 24 ),
615+ [DYNAMIC_MAC_TABLE_TIMESTAMP ] = GENMASK (28 , 27 ),
616+ };
617+
618+ static const u8 ksz8895_shifts [] = {
619+ [VLAN_TABLE_MEMBERSHIP_S ] = 7 ,
620+ [VLAN_TABLE ] = 13 ,
621+ [STATIC_MAC_FWD_PORTS ] = 16 ,
622+ [STATIC_MAC_FID ] = 24 ,
623+ [DYNAMIC_MAC_ENTRIES_H ] = 3 ,
624+ [DYNAMIC_MAC_ENTRIES ] = 29 ,
625+ [DYNAMIC_MAC_FID ] = 16 ,
626+ [DYNAMIC_MAC_TIMESTAMP ] = 27 ,
627+ [DYNAMIC_MAC_SRC_PORT ] = 24 ,
628+ };
629+
575630static const u16 ksz9477_regs [] = {
576631 [REG_SW_MAC_ADDR ] = 0x0302 ,
577632 [P_STP_CTRL ] = 0x0B04 ,
@@ -1397,7 +1452,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
13971452 .port_cnt = 3 ,
13981453 .num_tx_queues = 4 ,
13991454 .num_ipms = 4 ,
1400- .ops = & ksz88x3_dev_ops ,
1455+ .ops = & ksz88xx_dev_ops ,
14011456 .phylink_mac_ops = & ksz8830_phylink_mac_ops ,
14021457 .mib_names = ksz88xx_mib_names ,
14031458 .mib_cnt = ARRAY_SIZE (ksz88xx_mib_names ),
@@ -1412,6 +1467,61 @@ const struct ksz_chip_data ksz_switch_chips[] = {
14121467 .rd_table = & ksz8873_register_set ,
14131468 },
14141469
1470+ [KSZ8864 ] = {
1471+ /* WARNING
1472+ * =======
1473+ * KSZ8864 is similar to KSZ8895, except the first port
1474+ * does not exist.
1475+ * external cpu
1476+ * KSZ8864 1,2,3 4
1477+ * KSZ8895 0,1,2,3 4
1478+ * port_cnt is configured as 5, even though it is 4
1479+ */
1480+ .chip_id = KSZ8864_CHIP_ID ,
1481+ .dev_name = "KSZ8864" ,
1482+ .num_vlans = 4096 ,
1483+ .num_alus = 0 ,
1484+ .num_statics = 32 ,
1485+ .cpu_ports = 0x10 , /* can be configured as cpu port */
1486+ .port_cnt = 5 , /* total cpu and user ports */
1487+ .num_tx_queues = 4 ,
1488+ .num_ipms = 4 ,
1489+ .ops = & ksz88xx_dev_ops ,
1490+ .phylink_mac_ops = & ksz8830_phylink_mac_ops ,
1491+ .mib_names = ksz88xx_mib_names ,
1492+ .mib_cnt = ARRAY_SIZE (ksz88xx_mib_names ),
1493+ .reg_mib_cnt = MIB_COUNTER_NUM ,
1494+ .regs = ksz8895_regs ,
1495+ .masks = ksz8895_masks ,
1496+ .shifts = ksz8895_shifts ,
1497+ .supports_mii = {false, false, false, false, true},
1498+ .supports_rmii = {false, false, false, false, true},
1499+ .internal_phy = {false, true, true, true, false},
1500+ },
1501+
1502+ [KSZ8895 ] = {
1503+ .chip_id = KSZ8895_CHIP_ID ,
1504+ .dev_name = "KSZ8895" ,
1505+ .num_vlans = 4096 ,
1506+ .num_alus = 0 ,
1507+ .num_statics = 32 ,
1508+ .cpu_ports = 0x10 , /* can be configured as cpu port */
1509+ .port_cnt = 5 , /* total cpu and user ports */
1510+ .num_tx_queues = 4 ,
1511+ .num_ipms = 4 ,
1512+ .ops = & ksz88xx_dev_ops ,
1513+ .phylink_mac_ops = & ksz8830_phylink_mac_ops ,
1514+ .mib_names = ksz88xx_mib_names ,
1515+ .mib_cnt = ARRAY_SIZE (ksz88xx_mib_names ),
1516+ .reg_mib_cnt = MIB_COUNTER_NUM ,
1517+ .regs = ksz8895_regs ,
1518+ .masks = ksz8895_masks ,
1519+ .shifts = ksz8895_shifts ,
1520+ .supports_mii = {false, false, false, false, true},
1521+ .supports_rmii = {false, false, false, false, true},
1522+ .internal_phy = {true, true, true, true, false},
1523+ },
1524+
14151525 [KSZ9477 ] = {
14161526 .chip_id = KSZ9477_CHIP_ID ,
14171527 .dev_name = "KSZ9477" ,
@@ -2937,9 +3047,7 @@ static enum dsa_tag_protocol ksz_get_tag_protocol(struct dsa_switch *ds,
29373047 struct ksz_device * dev = ds -> priv ;
29383048 enum dsa_tag_protocol proto = DSA_TAG_PROTO_NONE ;
29393049
2940- if (dev -> chip_id == KSZ8795_CHIP_ID ||
2941- dev -> chip_id == KSZ8794_CHIP_ID ||
2942- dev -> chip_id == KSZ8765_CHIP_ID )
3050+ if (ksz_is_ksz87xx (dev ) || ksz_is_8895_family (dev ))
29433051 proto = DSA_TAG_PROTO_KSZ8795 ;
29443052
29453053 if (dev -> chip_id == KSZ8830_CHIP_ID ||
@@ -3055,6 +3163,8 @@ static int ksz_max_mtu(struct dsa_switch *ds, int port)
30553163 case KSZ8765_CHIP_ID :
30563164 return KSZ8795_HUGE_PACKET_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN ;
30573165 case KSZ8830_CHIP_ID :
3166+ case KSZ8864_CHIP_ID :
3167+ case KSZ8895_CHIP_ID :
30583168 return KSZ8863_HUGE_PACKET_SIZE - VLAN_ETH_HLEN - ETH_FCS_LEN ;
30593169 case KSZ8563_CHIP_ID :
30603170 case KSZ8567_CHIP_ID :
@@ -3412,6 +3522,18 @@ static int ksz_switch_detect(struct ksz_device *dev)
34123522 else
34133523 return - ENODEV ;
34143524 break ;
3525+ case KSZ8895_FAMILY_ID :
3526+ if (id2 == KSZ8895_CHIP_ID_95 ||
3527+ id2 == KSZ8895_CHIP_ID_95R )
3528+ dev -> chip_id = KSZ8895_CHIP_ID ;
3529+ else
3530+ return - ENODEV ;
3531+ ret = ksz_read8 (dev , REG_KSZ8864_CHIP_ID , & id4 );
3532+ if (ret )
3533+ return ret ;
3534+ if (id4 & SW_KSZ8864 )
3535+ dev -> chip_id = KSZ8864_CHIP_ID ;
3536+ break ;
34153537 default :
34163538 ret = ksz_read32 (dev , REG_CHIP_ID0 , & id32 );
34173539 if (ret )
0 commit comments