diff --git a/gearsyncd/gearboxparser.cpp b/gearsyncd/gearboxparser.cpp index 65e0b4f05dee..863ee57dabf1 100644 --- a/gearsyncd/gearboxparser.cpp +++ b/gearsyncd/gearboxparser.cpp @@ -143,6 +143,14 @@ bool GearboxParser::parse() val = phy["bus_id"]; attr = std::make_pair("bus_id", std::to_string(val.get())); attrs.push_back(attr); + if (phy.find("hwinfo") == phy.end()) + { + SWSS_LOG_ERROR("missing 'hwinfo' field in 'phys' item %d in gearbox configuration", iter); + return false; + } + val = phy["hwinfo"]; + attr = std::make_pair("hwinfo", std::string(val.get())); + attrs.push_back(attr); std::string key; key = "phy:" + std::to_string(phyId); if (getWriteToDb() == true) diff --git a/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_line_lanes.json b/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_line_lanes.json index 16a790b5193d..763d716113ad 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_line_lanes.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_line_lanes.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_system_lanes.json b/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_system_lanes.json index 86bedc7c1dc8..5852ae204b8a 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_system_lanes.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_empty_ethernet_system_lanes.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_invalid_array.json b/gearsyncd/tests/configs/negative/gearbox_config_invalid_array.json index 3533c0e54bc3..d346f0242ae8 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_invalid_array.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_invalid_array.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_invalid_json.json b/gearsyncd/tests/configs/negative/gearbox_config_invalid_json.json index eae5bc7aa239..64d8272bee30 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_invalid_json.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_invalid_json.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_invalid_phy_config_file.json b/gearsyncd/tests/configs/negative/gearbox_config_invalid_phy_config_file.json index c567489538a6..944eeb22998a 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_invalid_phy_config_file.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_invalid_phy_config_file.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy_config_does_not_exist.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_index.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_index.json index b863410e641e..b54100671195 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_index.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_index.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lane_speed.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lane_speed.json index b3dea2095554..db0e700e8578 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lane_speed.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lane_speed.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lanes.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lanes.json index f245b8adf7ac..d8b79f54959e 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lanes.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_line_lanes.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_phy_id.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_phy_id.json index b76e613a4479..dd9a4ca11323 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_phy_id.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_phy_id.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lane_speed.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lane_speed.json index b3dea2095554..2bcafd59eef2 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lane_speed.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lane_speed.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/3" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lanes.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lanes.json index 1a6a60dc0d86..f5f80b24dc47 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lanes.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_ethernet_system_lanes.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_interfaces.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_interfaces.json index 84b2056780c0..9bc632bbe9bd 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_interfaces.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_interfaces.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ] } diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_address.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_address.json index 5989dd0856da..5d6e4060280f 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_address.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_address.json @@ -7,7 +7,8 @@ "firmware_path": "/tmp/phy-example1.bin", "config_file": "tests/configs/positive/phy1_config_1.json", "phy_access": "MDIO(NPU)", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -17,7 +18,8 @@ "firmware_path": "/tmp/phy-example2.bin", "config_file": "tests/configs/positive/phy2_config_1.json", "phy_access": "I2C", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_bus_id.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_bus_id.json index 1b37dfbec2e3..928dca874924 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_bus_id.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_bus_id.json @@ -7,7 +7,8 @@ "lib_name": "libsai_phy_example1.so", "firmware_path": "/tmp/phy-example1.bin", "config_file": "tests/configs/positive/phy1_config_1.json", - "phy_access": "MDIO(NPU)" + "phy_access": "MDIO(NPU)", + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -17,7 +18,8 @@ "firmware_path": "/tmp/phy-example2.bin", "config_file": "tests/configs/positive/phy2_config_1.json", "phy_access": "I2C", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_config_file.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_config_file.json index e9589d4daa2f..ca96aefe411b 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_config_file.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_config_file.json @@ -7,7 +7,8 @@ "lib_name": "libsai_phy_example1.so", "firmware_path": "/tmp/phy-example1.bin", "phy_access": "MDIO(NPU)", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -17,7 +18,8 @@ "firmware_path": "/tmp/phy-example2.bin", "config_file": "tests/configs/positive/phy2_config_1.json", "phy_access": "I2C", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_firmware_path.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_firmware_path.json index 33cbfc176c7e..8fac85842b57 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_firmware_path.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_firmware_path.json @@ -7,7 +7,8 @@ "lib_name": "libsai_phy_example1.so", "config_file": "tests/configs/positive/phy1_config_1.json", "phy_access": "MDIO(NPU)", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -17,7 +18,8 @@ "firmware_path": "/tmp/phy-example2.bin", "config_file": "tests/configs/positive/phy2_config_1.json", "phy_access": "I2C", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_hwinfo.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_hwinfo.json new file mode 100644 index 000000000000..e06cb5904854 --- /dev/null +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_hwinfo.json @@ -0,0 +1,46 @@ +{ + "phys": [ + { + "phy_id": 0, + "name": "example-1", + "address": "0x1000", + "lib_name": "libsai_phy_example1.so", + "firmware_path": "/tmp/phy-example1.bin", + "config_file": "tests/configs/positive/phy1_config_1.json", + "phy_access": "mdio", + "bus_id": 0 + }, + { + "phy_id": 1, + "name": "example-2", + "address": "0x2000", + "lib_name": "libsai_phy_example2.so", + "firmware_path": "/tmp/phy-example2.bin", + "config_file": "tests/configs/positive/phy2_config_1.json", + "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", + "phy_access": "i2c", + "bus_id": 1, + "hwinfo": "" + } + ], + "interfaces": [ + { + "index": 1, + "phy_id" : 0, + "system_lanes": [38,39], + "line_lanes": [30,31,32,33] + }, + { + "index": 1, + "phy_id" : 0, + "system_lanes": [40,41], + "line_lanes": [34,35,36,37] + }, + { + "index": 1, + "phy_id" : 1, + "system_lanes": [4,5], + "line_lanes": [0,1,2,3] + } + ] +} diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_id.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_id.json index 39b4a0e57a67..97fb90a99f74 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_id.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_id.json @@ -8,7 +8,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -19,7 +20,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_lib_name.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_lib_name.json index 3a204e07d748..f33ac8dfddff 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_lib_name.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_lib_name.json @@ -7,7 +7,8 @@ "firmware_path": "/tmp/phy-example1.bin", "config_file": "tests/configs/positive/phy1_config_1.json", "phy_access": "MDIO(NPU)", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -17,7 +18,8 @@ "firmware_path": "/tmp/phy-example2.bin", "config_file": "tests/configs/positive/phy2_config_1.json", "phy_access": "I2C", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_name.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_name.json index f74dfb154a29..d6eb57df9785 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_name.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_name.json @@ -7,7 +7,8 @@ "firmware_path": "/tmp/phy-example1.bin", "config_file": "tests/configs/positive/phy1_config_1.json", "phy_access": "MDIO(NPU)", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -17,7 +18,8 @@ "firmware_path": "/tmp/phy-example2.bin", "config_file": "tests/configs/positive/phy2_config_1.json", "phy_access": "I2C", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_phy_access.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_phy_access.json index 33fd9f368f47..f6d97f7e9069 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_phy_access.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_phy_access.json @@ -7,7 +7,8 @@ "lib_name": "libsai_phy_example1.so", "firmware_path": "/tmp/phy-example1.bin", "config_file": "tests/configs/positive/phy1_config_1.json", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -17,7 +18,8 @@ "firmware_path": "/tmp/phy-example2.bin", "config_file": "tests/configs/positive/phy2_config_1.json", "phy_access": "I2C", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_sai_init_config_file.json b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_sai_init_config_file.json index fd28a59ef17d..048240e824ad 100644 --- a/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_sai_init_config_file.json +++ b/gearsyncd/tests/configs/negative/gearbox_config_missing_phy_sai_init_config_file.json @@ -8,7 +8,8 @@ "firmware_path": "/tmp/phy-example1.bin", "config_file": "tests/configs/positive/phy1_config_1.json", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/0" }, { "phy_id": 1, @@ -19,7 +20,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/configs/positive/gearbox_config_1.json b/gearsyncd/tests/configs/positive/gearbox_config_1.json index b3dea2095554..190eefedf844 100644 --- a/gearsyncd/tests/configs/positive/gearbox_config_1.json +++ b/gearsyncd/tests/configs/positive/gearbox_config_1.json @@ -9,7 +9,8 @@ "config_file": "tests/configs/positive/phy1_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-1.bcm", "phy_access": "mdio", - "bus_id": 0 + "bus_id": 0, + "hwinfo": "mdio0/1" }, { "phy_id": 1, @@ -20,7 +21,8 @@ "config_file": "tests/configs/positive/phy2_config_1.json", "sai_init_config_file": "/usr/share/sonic/hwsku/example-2.bcm", "phy_access": "i2c", - "bus_id": 1 + "bus_id": 1, + "hwinfo": "" } ], "interfaces": [ diff --git a/gearsyncd/tests/testgearparser.cpp b/gearsyncd/tests/testgearparser.cpp index 26422589990d..baf97f4780b8 100644 --- a/gearsyncd/tests/testgearparser.cpp +++ b/gearsyncd/tests/testgearparser.cpp @@ -63,6 +63,8 @@ void negativeConfigTest() CU_ASSERT_EQUAL(ret, false); ret = handleGearboxConfigFile("tests/configs/negative/gearbox_config_missing_phy_bus_id.json", false); CU_ASSERT_EQUAL(ret, false); + ret = handleGearboxConfigFile("tests/configs/negative/gearbox_config_missing_phy_hwinfo.json", false); + CU_ASSERT_EQUAL(ret, false); ret = handleGearboxConfigFile("tests/configs/negative/gearbox_config_invalid_phy_config_file.json", false); CU_ASSERT_EQUAL(ret, false); diff --git a/lib/gearboxutils.cpp b/lib/gearboxutils.cpp index d17ed3a02fb7..989de4d22f7c 100644 --- a/lib/gearboxutils.cpp +++ b/lib/gearboxutils.cpp @@ -173,6 +173,10 @@ std::map GearboxUtils::loadPhyMap(Table *gearboxTable) { phy.access = val.second; } + else if (val.first == "hwinfo") + { + phy.hwinfo = val.second; + } else if (val.first == "address") { phy.address = std::stoi(val.second); diff --git a/lib/gearboxutils.h b/lib/gearboxutils.h index 95e362d20e94..0a70c62d77f2 100644 --- a/lib/gearboxutils.h +++ b/lib/gearboxutils.h @@ -41,6 +41,7 @@ typedef struct std::string sai_init_config_file; std::string config_file; std::string access; + std::string hwinfo; uint32_t address; uint32_t bus_id; } gearbox_phy_t; diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index e5a59979ee89..d047852488fe 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -15,6 +15,7 @@ extern "C" { #include #include #include +#include #include "timestamp.h" #include "sai_serialize.h" #include "saihelper.h" @@ -22,8 +23,14 @@ extern "C" { using namespace std; using namespace swss; +#define _STR(s) #s +#define STR(s) _STR(s) + #define CONTEXT_CFG_FILE "/usr/share/sonic/hwsku/context_config.json" +// hwinfo = "INTERFACE_NAME/PHY ID", mii_ioctl_data->phy_id is a __u16 +#define HWINFO_MAX_SIZE IFNAMSIZ + 1 + 5 + /* Initialize all global api pointers */ sai_switch_api_t* sai_switch_api; sai_bridge_api_t* sai_bridge_api; @@ -271,6 +278,10 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy) vector attrs; sai_status_t status; char fwPath[PATH_MAX]; + char hwinfo[HWINFO_MAX_SIZE + 1]; + char hwinfoIntf[IFNAMSIZ + 1]; + unsigned int hwinfoPhyid; + int ret; SWSS_LOG_ENTER(); @@ -286,9 +297,23 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy) attr.value.u32 = 0; attrs.push_back(attr); + ret = sscanf(phy->hwinfo.c_str(), "%" STR(IFNAMSIZ) "[^/]/%u", hwinfoIntf, &hwinfoPhyid); + if (ret != 2) { + SWSS_LOG_ERROR("BOX: hardware info doesn't match the 'interface_name/phyid' " + "format"); + return SAI_STATUS_FAILURE; + } + + if (hwinfoPhyid > std::numeric_limits::max()) { + SWSS_LOG_ERROR("BOX: phyid is bigger than maximum limit"); + return SAI_STATUS_FAILURE; + } + + strcpy(hwinfo, phy->hwinfo.c_str()); + attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO; - attr.value.s8list.count = 0; - attr.value.s8list.list = 0; + attr.value.s8list.count = (uint32_t) phy->hwinfo.length(); + attr.value.s8list.list = (int8_t *) hwinfo; attrs.push_back(attr); if (phy->firmware.length() == 0)