@@ -898,29 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
898
898
}
899
899
}
900
900
901
- static enum dsa_tag_protocol ksz8_get_tag_protocol (struct dsa_switch * ds ,
902
- int port ,
903
- enum dsa_tag_protocol mp )
904
- {
905
- struct ksz_device * dev = ds -> priv ;
906
-
907
- /* ksz88x3 uses the same tag schema as KSZ9893 */
908
- return ksz_is_ksz88x3 (dev ) ?
909
- DSA_TAG_PROTO_KSZ9893 : DSA_TAG_PROTO_KSZ8795 ;
910
- }
911
-
912
- static u32 ksz8_sw_get_phy_flags (struct dsa_switch * ds , int port )
913
- {
914
- /* Silicon Errata Sheet (DS80000830A):
915
- * Port 1 does not work with LinkMD Cable-Testing.
916
- * Port 1 does not respond to received PAUSE control frames.
917
- */
918
- if (!port )
919
- return MICREL_KSZ8_P1_ERRATA ;
920
-
921
- return 0 ;
922
- }
923
-
924
901
static void ksz8_cfg_port_member (struct ksz_device * dev , int port , u8 member )
925
902
{
926
903
u8 data ;
@@ -931,11 +908,6 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
931
908
ksz_pwrite8 (dev , port , P_MIRROR_CTRL , data );
932
909
}
933
910
934
- static void ksz8_port_stp_state_set (struct dsa_switch * ds , int port , u8 state )
935
- {
936
- ksz_port_stp_state_set (ds , port , state , P_STP_CTRL );
937
- }
938
-
939
911
static void ksz8_flush_dyn_mac_table (struct ksz_device * dev , int port )
940
912
{
941
913
u8 learn [DSA_MAX_PORTS ];
@@ -969,11 +941,111 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
969
941
}
970
942
}
971
943
972
- static int ksz8_port_vlan_filtering (struct dsa_switch * ds , int port , bool flag ,
973
- struct netlink_ext_ack * extack )
944
+ static int ksz8_fdb_dump (struct ksz_device * dev , int port ,
945
+ dsa_fdb_dump_cb_t * cb , void * data )
974
946
{
975
- struct ksz_device * dev = ds -> priv ;
947
+ int ret = 0 ;
948
+ u16 i = 0 ;
949
+ u16 entries = 0 ;
950
+ u8 timestamp = 0 ;
951
+ u8 fid ;
952
+ u8 member ;
953
+ struct alu_struct alu ;
954
+
955
+ do {
956
+ alu .is_static = false;
957
+ ret = ksz8_r_dyn_mac_table (dev , i , alu .mac , & fid , & member ,
958
+ & timestamp , & entries );
959
+ if (!ret && (member & BIT (port ))) {
960
+ ret = cb (alu .mac , alu .fid , alu .is_static , data );
961
+ if (ret )
962
+ break ;
963
+ }
964
+ i ++ ;
965
+ } while (i < entries );
966
+ if (i >= entries )
967
+ ret = 0 ;
968
+
969
+ return ret ;
970
+ }
971
+
972
+ static int ksz8_mdb_add (struct ksz_device * dev , int port ,
973
+ const struct switchdev_obj_port_mdb * mdb ,
974
+ struct dsa_db db )
975
+ {
976
+ struct alu_struct alu ;
977
+ int index ;
978
+ int empty = 0 ;
979
+
980
+ alu .port_forward = 0 ;
981
+ for (index = 0 ; index < dev -> info -> num_statics ; index ++ ) {
982
+ if (!ksz8_r_sta_mac_table (dev , index , & alu )) {
983
+ /* Found one already in static MAC table. */
984
+ if (!memcmp (alu .mac , mdb -> addr , ETH_ALEN ) &&
985
+ alu .fid == mdb -> vid )
986
+ break ;
987
+ /* Remember the first empty entry. */
988
+ } else if (!empty ) {
989
+ empty = index + 1 ;
990
+ }
991
+ }
992
+
993
+ /* no available entry */
994
+ if (index == dev -> info -> num_statics && !empty )
995
+ return - ENOSPC ;
996
+
997
+ /* add entry */
998
+ if (index == dev -> info -> num_statics ) {
999
+ index = empty - 1 ;
1000
+ memset (& alu , 0 , sizeof (alu ));
1001
+ memcpy (alu .mac , mdb -> addr , ETH_ALEN );
1002
+ alu .is_static = true;
1003
+ }
1004
+ alu .port_forward |= BIT (port );
1005
+ if (mdb -> vid ) {
1006
+ alu .is_use_fid = true;
1007
+
1008
+ /* Need a way to map VID to FID. */
1009
+ alu .fid = mdb -> vid ;
1010
+ }
1011
+ ksz8_w_sta_mac_table (dev , index , & alu );
1012
+
1013
+ return 0 ;
1014
+ }
1015
+
1016
+ static int ksz8_mdb_del (struct ksz_device * dev , int port ,
1017
+ const struct switchdev_obj_port_mdb * mdb ,
1018
+ struct dsa_db db )
1019
+ {
1020
+ struct alu_struct alu ;
1021
+ int index ;
1022
+
1023
+ for (index = 0 ; index < dev -> info -> num_statics ; index ++ ) {
1024
+ if (!ksz8_r_sta_mac_table (dev , index , & alu )) {
1025
+ /* Found one already in static MAC table. */
1026
+ if (!memcmp (alu .mac , mdb -> addr , ETH_ALEN ) &&
1027
+ alu .fid == mdb -> vid )
1028
+ break ;
1029
+ }
1030
+ }
1031
+
1032
+ /* no available entry */
1033
+ if (index == dev -> info -> num_statics )
1034
+ goto exit ;
1035
+
1036
+ /* clear port */
1037
+ alu .port_forward &= ~BIT (port );
1038
+ if (!alu .port_forward )
1039
+ alu .is_static = false;
1040
+ ksz8_w_sta_mac_table (dev , index , & alu );
976
1041
1042
+ exit :
1043
+ return 0 ;
1044
+ }
1045
+
1046
+ static int ksz8_port_vlan_filtering (struct ksz_device * dev , int port , bool flag ,
1047
+ struct netlink_ext_ack * extack )
1048
+ {
977
1049
if (ksz_is_ksz88x3 (dev ))
978
1050
return - ENOTSUPP ;
979
1051
@@ -998,12 +1070,11 @@ static void ksz8_port_enable_pvid(struct ksz_device *dev, int port, bool state)
998
1070
}
999
1071
}
1000
1072
1001
- static int ksz8_port_vlan_add (struct dsa_switch * ds , int port ,
1073
+ static int ksz8_port_vlan_add (struct ksz_device * dev , int port ,
1002
1074
const struct switchdev_obj_port_vlan * vlan ,
1003
1075
struct netlink_ext_ack * extack )
1004
1076
{
1005
1077
bool untagged = vlan -> flags & BRIDGE_VLAN_INFO_UNTAGGED ;
1006
- struct ksz_device * dev = ds -> priv ;
1007
1078
struct ksz_port * p = & dev -> ports [port ];
1008
1079
u16 data , new_pvid = 0 ;
1009
1080
u8 fid , member , valid ;
@@ -1071,10 +1142,9 @@ static int ksz8_port_vlan_add(struct dsa_switch *ds, int port,
1071
1142
return 0 ;
1072
1143
}
1073
1144
1074
- static int ksz8_port_vlan_del (struct dsa_switch * ds , int port ,
1145
+ static int ksz8_port_vlan_del (struct ksz_device * dev , int port ,
1075
1146
const struct switchdev_obj_port_vlan * vlan )
1076
1147
{
1077
- struct ksz_device * dev = ds -> priv ;
1078
1148
u16 data , pvid ;
1079
1149
u8 fid , member , valid ;
1080
1150
@@ -1104,12 +1174,10 @@ static int ksz8_port_vlan_del(struct dsa_switch *ds, int port,
1104
1174
return 0 ;
1105
1175
}
1106
1176
1107
- static int ksz8_port_mirror_add (struct dsa_switch * ds , int port ,
1177
+ static int ksz8_port_mirror_add (struct ksz_device * dev , int port ,
1108
1178
struct dsa_mall_mirror_tc_entry * mirror ,
1109
1179
bool ingress , struct netlink_ext_ack * extack )
1110
1180
{
1111
- struct ksz_device * dev = ds -> priv ;
1112
-
1113
1181
if (ingress ) {
1114
1182
ksz_port_cfg (dev , port , P_MIRROR_CTRL , PORT_MIRROR_RX , true);
1115
1183
dev -> mirror_rx |= BIT (port );
@@ -1128,10 +1196,9 @@ static int ksz8_port_mirror_add(struct dsa_switch *ds, int port,
1128
1196
return 0 ;
1129
1197
}
1130
1198
1131
- static void ksz8_port_mirror_del (struct dsa_switch * ds , int port ,
1199
+ static void ksz8_port_mirror_del (struct ksz_device * dev , int port ,
1132
1200
struct dsa_mall_mirror_tc_entry * mirror )
1133
1201
{
1134
- struct ksz_device * dev = ds -> priv ;
1135
1202
u8 data ;
1136
1203
1137
1204
if (mirror -> ingress ) {
@@ -1258,7 +1325,7 @@ static void ksz8_config_cpu_port(struct dsa_switch *ds)
1258
1325
for (i = 0 ; i < dev -> phy_port_cnt ; i ++ ) {
1259
1326
p = & dev -> ports [i ];
1260
1327
1261
- ksz8_port_stp_state_set (ds , i , BR_STATE_DISABLED );
1328
+ ksz_port_stp_state_set (ds , i , BR_STATE_DISABLED );
1262
1329
1263
1330
/* Last port may be disabled. */
1264
1331
if (i == dev -> phy_port_cnt )
@@ -1272,7 +1339,7 @@ static void ksz8_config_cpu_port(struct dsa_switch *ds)
1272
1339
continue ;
1273
1340
if (!ksz_is_ksz88x3 (dev )) {
1274
1341
ksz_pread8 (dev , i , regs [P_REMOTE_STATUS ], & remote );
1275
- if (remote & PORT_FIBER_MODE )
1342
+ if (remote & KSZ8_PORT_FIBER_MODE )
1276
1343
p -> fiber = 1 ;
1277
1344
}
1278
1345
if (p -> fiber )
@@ -1371,13 +1438,9 @@ static int ksz8_setup(struct dsa_switch *ds)
1371
1438
return ksz8_handle_global_errata (ds );
1372
1439
}
1373
1440
1374
- static void ksz8_get_caps (struct dsa_switch * ds , int port ,
1441
+ static void ksz8_get_caps (struct ksz_device * dev , int port ,
1375
1442
struct phylink_config * config )
1376
1443
{
1377
- struct ksz_device * dev = ds -> priv ;
1378
-
1379
- ksz_phylink_get_caps (ds , port , config );
1380
-
1381
1444
config -> mac_capabilities = MAC_10 | MAC_100 ;
1382
1445
1383
1446
/* Silicon Errata Sheet (DS80000830A):
@@ -1394,81 +1457,36 @@ static void ksz8_get_caps(struct dsa_switch *ds, int port,
1394
1457
}
1395
1458
1396
1459
static const struct dsa_switch_ops ksz8_switch_ops = {
1397
- .get_tag_protocol = ksz8_get_tag_protocol ,
1398
- .get_phy_flags = ksz8_sw_get_phy_flags ,
1460
+ .get_tag_protocol = ksz_get_tag_protocol ,
1461
+ .get_phy_flags = ksz_get_phy_flags ,
1399
1462
.setup = ksz8_setup ,
1400
1463
.phy_read = ksz_phy_read16 ,
1401
1464
.phy_write = ksz_phy_write16 ,
1402
- .phylink_get_caps = ksz8_get_caps ,
1465
+ .phylink_get_caps = ksz_phylink_get_caps ,
1403
1466
.phylink_mac_link_down = ksz_mac_link_down ,
1404
1467
.port_enable = ksz_enable_port ,
1405
1468
.get_strings = ksz_get_strings ,
1406
1469
.get_ethtool_stats = ksz_get_ethtool_stats ,
1407
1470
.get_sset_count = ksz_sset_count ,
1408
1471
.port_bridge_join = ksz_port_bridge_join ,
1409
1472
.port_bridge_leave = ksz_port_bridge_leave ,
1410
- .port_stp_state_set = ksz8_port_stp_state_set ,
1473
+ .port_stp_state_set = ksz_port_stp_state_set ,
1411
1474
.port_fast_age = ksz_port_fast_age ,
1412
- .port_vlan_filtering = ksz8_port_vlan_filtering ,
1413
- .port_vlan_add = ksz8_port_vlan_add ,
1414
- .port_vlan_del = ksz8_port_vlan_del ,
1475
+ .port_vlan_filtering = ksz_port_vlan_filtering ,
1476
+ .port_vlan_add = ksz_port_vlan_add ,
1477
+ .port_vlan_del = ksz_port_vlan_del ,
1415
1478
.port_fdb_dump = ksz_port_fdb_dump ,
1416
1479
.port_mdb_add = ksz_port_mdb_add ,
1417
1480
.port_mdb_del = ksz_port_mdb_del ,
1418
- .port_mirror_add = ksz8_port_mirror_add ,
1419
- .port_mirror_del = ksz8_port_mirror_del ,
1481
+ .port_mirror_add = ksz_port_mirror_add ,
1482
+ .port_mirror_del = ksz_port_mirror_del ,
1420
1483
};
1421
1484
1422
1485
static u32 ksz8_get_port_addr (int port , int offset )
1423
1486
{
1424
1487
return PORT_CTRL_ADDR (port , offset );
1425
1488
}
1426
1489
1427
- static int ksz8_switch_detect (struct ksz_device * dev )
1428
- {
1429
- u8 id1 , id2 ;
1430
- u16 id16 ;
1431
- int ret ;
1432
-
1433
- /* read chip id */
1434
- ret = ksz_read16 (dev , REG_CHIP_ID0 , & id16 );
1435
- if (ret )
1436
- return ret ;
1437
-
1438
- id1 = id16 >> 8 ;
1439
- id2 = id16 & SW_CHIP_ID_M ;
1440
-
1441
- switch (id1 ) {
1442
- case KSZ87_FAMILY_ID :
1443
- if ((id2 != CHIP_ID_94 && id2 != CHIP_ID_95 ))
1444
- return - ENODEV ;
1445
-
1446
- if (id2 == CHIP_ID_95 ) {
1447
- u8 val ;
1448
-
1449
- id2 = 0x95 ;
1450
- ksz_read8 (dev , REG_PORT_STATUS_0 , & val );
1451
- if (val & PORT_FIBER_MODE )
1452
- id2 = 0x65 ;
1453
- } else if (id2 == CHIP_ID_94 ) {
1454
- id2 = 0x94 ;
1455
- }
1456
- break ;
1457
- case KSZ88_FAMILY_ID :
1458
- if (id2 != CHIP_ID_63 )
1459
- return - ENODEV ;
1460
- break ;
1461
- default :
1462
- dev_err (dev -> dev , "invalid family id: %d\n" , id1 );
1463
- return - ENODEV ;
1464
- }
1465
- id16 &= ~0xff ;
1466
- id16 |= id2 ;
1467
- dev -> chip_id = id16 ;
1468
-
1469
- return 0 ;
1470
- }
1471
-
1472
1490
static int ksz8_switch_init (struct ksz_device * dev )
1473
1491
{
1474
1492
struct ksz8 * ksz8 = dev -> priv ;
@@ -1514,15 +1532,20 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
1514
1532
.port_setup = ksz8_port_setup ,
1515
1533
.r_phy = ksz8_r_phy ,
1516
1534
.w_phy = ksz8_w_phy ,
1517
- .r_dyn_mac_table = ksz8_r_dyn_mac_table ,
1518
- .r_sta_mac_table = ksz8_r_sta_mac_table ,
1519
- .w_sta_mac_table = ksz8_w_sta_mac_table ,
1520
1535
.r_mib_cnt = ksz8_r_mib_cnt ,
1521
1536
.r_mib_pkt = ksz8_r_mib_pkt ,
1522
1537
.freeze_mib = ksz8_freeze_mib ,
1523
1538
.port_init_cnt = ksz8_port_init_cnt ,
1539
+ .fdb_dump = ksz8_fdb_dump ,
1540
+ .mdb_add = ksz8_mdb_add ,
1541
+ .mdb_del = ksz8_mdb_del ,
1542
+ .vlan_filtering = ksz8_port_vlan_filtering ,
1543
+ .vlan_add = ksz8_port_vlan_add ,
1544
+ .vlan_del = ksz8_port_vlan_del ,
1545
+ .mirror_add = ksz8_port_mirror_add ,
1546
+ .mirror_del = ksz8_port_mirror_del ,
1547
+ .get_caps = ksz8_get_caps ,
1524
1548
.shutdown = ksz8_reset_switch ,
1525
- .detect = ksz8_switch_detect ,
1526
1549
.init = ksz8_switch_init ,
1527
1550
.exit = ksz8_switch_exit ,
1528
1551
};
0 commit comments