Skip to content

Commit 8720bd9

Browse files
author
Paolo Abeni
committed
Merge branch 'net-dsa-microchip-common-spi-probe-for-the-ksz-series-switches-part-1'
Arun Ramadoss says: ==================== net: dsa: microchip: common spi probe for the ksz series switches - part 1 This patch series aims to refactor the ksz_switch_register routine to have the common flow for the ksz series switch. At present ksz8795.c & ksz9477.c have its own dsa_switch_ops and switch detect functionality. In ksz_switch_register, ksz_dev_ops is assigned based on the function parameter passed by the individual ksz8/ksz9477 switch register function. And then switch detect is performed based on the ksz_dev_ops.detect hook. This patch modifies the ksz_switch_register such a way that switch detect is performed first, based on the chip ksz_dev_ops is assigned to ksz_device structure. It ensures the common flow for the existing as well as LAN937x switches. In the next series of patch, it will move ksz_dsa_ops and dsa_switch_ops from ksz8795.c and ksz9477.c to ksz_common.c and have the common spi probe all the ksz based switches. Changes in v1 - Splitted the patch series into two. - Replaced all occurrence of REG_PORT_STATUS_0 and PORT_FIBER_MODE to KSZ8_PORT_STATUS_0 and KSZ8_PORT_FIBER_MODE. - Separated the tag protocol and phy read/write patch into two. - Assigned the DSA_TAG_PROTO_NONE as the default value for get_tag_protocol hook. - Reduced the indentation level by using the if(!dev->dev_ops->mirror_add). - Added the stp_ctrl_reg as a member in ksz_chip_data and removed the member in ksz_dev_ops. - Removed the r_dyn_mac_table, r_sta_mac_table and w_sta_mac_table from the ksz_dev_ops since it is used only in the ksz8795.c. Changes in RFC v2 - Fixed the compilation issue. - Reduced the patch set to 15. ==================== Reviewed-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 00bb292 + 1fe94f5 commit 8720bd9

File tree

6 files changed

+517
-336
lines changed

6 files changed

+517
-336
lines changed

drivers/net/dsa/microchip/ksz8795.c

Lines changed: 128 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -898,29 +898,6 @@ static void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
898898
}
899899
}
900900

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-
924901
static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
925902
{
926903
u8 data;
@@ -931,11 +908,6 @@ static void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
931908
ksz_pwrite8(dev, port, P_MIRROR_CTRL, data);
932909
}
933910

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-
939911
static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
940912
{
941913
u8 learn[DSA_MAX_PORTS];
@@ -969,11 +941,111 @@ static void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
969941
}
970942
}
971943

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)
974946
{
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);
9761041

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+
{
9771049
if (ksz_is_ksz88x3(dev))
9781050
return -ENOTSUPP;
9791051

@@ -998,12 +1070,11 @@ static void ksz8_port_enable_pvid(struct ksz_device *dev, int port, bool state)
9981070
}
9991071
}
10001072

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,
10021074
const struct switchdev_obj_port_vlan *vlan,
10031075
struct netlink_ext_ack *extack)
10041076
{
10051077
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
1006-
struct ksz_device *dev = ds->priv;
10071078
struct ksz_port *p = &dev->ports[port];
10081079
u16 data, new_pvid = 0;
10091080
u8 fid, member, valid;
@@ -1071,10 +1142,9 @@ static int ksz8_port_vlan_add(struct dsa_switch *ds, int port,
10711142
return 0;
10721143
}
10731144

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,
10751146
const struct switchdev_obj_port_vlan *vlan)
10761147
{
1077-
struct ksz_device *dev = ds->priv;
10781148
u16 data, pvid;
10791149
u8 fid, member, valid;
10801150

@@ -1104,12 +1174,10 @@ static int ksz8_port_vlan_del(struct dsa_switch *ds, int port,
11041174
return 0;
11051175
}
11061176

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,
11081178
struct dsa_mall_mirror_tc_entry *mirror,
11091179
bool ingress, struct netlink_ext_ack *extack)
11101180
{
1111-
struct ksz_device *dev = ds->priv;
1112-
11131181
if (ingress) {
11141182
ksz_port_cfg(dev, port, P_MIRROR_CTRL, PORT_MIRROR_RX, true);
11151183
dev->mirror_rx |= BIT(port);
@@ -1128,10 +1196,9 @@ static int ksz8_port_mirror_add(struct dsa_switch *ds, int port,
11281196
return 0;
11291197
}
11301198

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,
11321200
struct dsa_mall_mirror_tc_entry *mirror)
11331201
{
1134-
struct ksz_device *dev = ds->priv;
11351202
u8 data;
11361203

11371204
if (mirror->ingress) {
@@ -1258,7 +1325,7 @@ static void ksz8_config_cpu_port(struct dsa_switch *ds)
12581325
for (i = 0; i < dev->phy_port_cnt; i++) {
12591326
p = &dev->ports[i];
12601327

1261-
ksz8_port_stp_state_set(ds, i, BR_STATE_DISABLED);
1328+
ksz_port_stp_state_set(ds, i, BR_STATE_DISABLED);
12621329

12631330
/* Last port may be disabled. */
12641331
if (i == dev->phy_port_cnt)
@@ -1272,7 +1339,7 @@ static void ksz8_config_cpu_port(struct dsa_switch *ds)
12721339
continue;
12731340
if (!ksz_is_ksz88x3(dev)) {
12741341
ksz_pread8(dev, i, regs[P_REMOTE_STATUS], &remote);
1275-
if (remote & PORT_FIBER_MODE)
1342+
if (remote & KSZ8_PORT_FIBER_MODE)
12761343
p->fiber = 1;
12771344
}
12781345
if (p->fiber)
@@ -1371,13 +1438,9 @@ static int ksz8_setup(struct dsa_switch *ds)
13711438
return ksz8_handle_global_errata(ds);
13721439
}
13731440

1374-
static void ksz8_get_caps(struct dsa_switch *ds, int port,
1441+
static void ksz8_get_caps(struct ksz_device *dev, int port,
13751442
struct phylink_config *config)
13761443
{
1377-
struct ksz_device *dev = ds->priv;
1378-
1379-
ksz_phylink_get_caps(ds, port, config);
1380-
13811444
config->mac_capabilities = MAC_10 | MAC_100;
13821445

13831446
/* Silicon Errata Sheet (DS80000830A):
@@ -1394,81 +1457,36 @@ static void ksz8_get_caps(struct dsa_switch *ds, int port,
13941457
}
13951458

13961459
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,
13991462
.setup = ksz8_setup,
14001463
.phy_read = ksz_phy_read16,
14011464
.phy_write = ksz_phy_write16,
1402-
.phylink_get_caps = ksz8_get_caps,
1465+
.phylink_get_caps = ksz_phylink_get_caps,
14031466
.phylink_mac_link_down = ksz_mac_link_down,
14041467
.port_enable = ksz_enable_port,
14051468
.get_strings = ksz_get_strings,
14061469
.get_ethtool_stats = ksz_get_ethtool_stats,
14071470
.get_sset_count = ksz_sset_count,
14081471
.port_bridge_join = ksz_port_bridge_join,
14091472
.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,
14111474
.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,
14151478
.port_fdb_dump = ksz_port_fdb_dump,
14161479
.port_mdb_add = ksz_port_mdb_add,
14171480
.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,
14201483
};
14211484

14221485
static u32 ksz8_get_port_addr(int port, int offset)
14231486
{
14241487
return PORT_CTRL_ADDR(port, offset);
14251488
}
14261489

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-
14721490
static int ksz8_switch_init(struct ksz_device *dev)
14731491
{
14741492
struct ksz8 *ksz8 = dev->priv;
@@ -1514,15 +1532,20 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
15141532
.port_setup = ksz8_port_setup,
15151533
.r_phy = ksz8_r_phy,
15161534
.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,
15201535
.r_mib_cnt = ksz8_r_mib_cnt,
15211536
.r_mib_pkt = ksz8_r_mib_pkt,
15221537
.freeze_mib = ksz8_freeze_mib,
15231538
.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,
15241548
.shutdown = ksz8_reset_switch,
1525-
.detect = ksz8_switch_detect,
15261549
.init = ksz8_switch_init,
15271550
.exit = ksz8_switch_exit,
15281551
};

drivers/net/dsa/microchip/ksz8795_reg.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,10 @@
1414
#define KS_PRIO_M 0x3
1515
#define KS_PRIO_S 2
1616

17-
#define REG_CHIP_ID0 0x00
18-
19-
#define KSZ87_FAMILY_ID 0x87
20-
#define KSZ88_FAMILY_ID 0x88
21-
22-
#define REG_CHIP_ID1 0x01
23-
24-
#define SW_CHIP_ID_M 0xF0
25-
#define SW_CHIP_ID_S 4
2617
#define SW_REVISION_M 0x0E
2718
#define SW_REVISION_S 1
2819
#define SW_START 0x01
2920

30-
#define CHIP_ID_94 0x60
31-
#define CHIP_ID_95 0x90
32-
#define CHIP_ID_63 0x30
33-
3421
#define KSZ8863_REG_SW_RESET 0x43
3522

3623
#define KSZ8863_GLOBAL_SOFTWARE_RESET BIT(4)
@@ -217,8 +204,6 @@
217204
#define REG_PORT_4_STATUS_0 0x48
218205

219206
/* For KSZ8765. */
220-
#define PORT_FIBER_MODE BIT(7)
221-
222207
#define PORT_REMOTE_ASYM_PAUSE BIT(5)
223208
#define PORT_REMOTE_SYM_PAUSE BIT(4)
224209
#define PORT_REMOTE_100BTX_FD BIT(3)
@@ -322,7 +307,6 @@
322307

323308
#define REG_PORT_CTRL_5 0x05
324309

325-
#define REG_PORT_STATUS_0 0x08
326310
#define REG_PORT_STATUS_1 0x09
327311
#define REG_PORT_LINK_MD_CTRL 0x0A
328312
#define REG_PORT_LINK_MD_RESULT 0x0B

0 commit comments

Comments
 (0)