From 90459953c8206381d4b6ebf137e6bbd74eb212f8 Mon Sep 17 00:00:00 2001 From: andywongarista <78833093+andywongarista@users.noreply.github.com> Date: Sun, 17 Jul 2022 19:58:48 -0700 Subject: [PATCH] [orchagent]: Enhance initSaiPhyApi (#2367) * Add support for generic hwinfo string in gearbox_config.json The SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO formatting is vendor specific. * Remove the formating check that assumes its of the mdio sysfs format * Note the the count remains without including the NULL termintor, which is not compliant with the SAI header definintion that indicates a NULL terminated string. Signed-off-by: aaronp@arista.com * Add support to allow Firmware Major Version to return unsupported" Some external phys do not support Firmware upgrades and therefore do not have a firmware version. The SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION may return SAI_STATUS_ATTR_NOT_SUPPORTED which needs to be gracefully supported and allow the phy to be created. * Allow SAI_STATUS_NOT_SUPPORTED return value and set version to empty string. Signed-off-by: Aaron Payment * Address review comments * Address review comments, fix hwinfo Co-authored-by: Aaron Payment --- orchagent/saihelper.cpp | 46 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index 3b409f7217f0..ee6ce2b8021d 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -359,9 +359,6 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy) 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(); @@ -377,22 +374,15 @@ 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( phy->hwinfo.length() > HWINFO_MAX_SIZE ) { + SWSS_LOG_ERROR( "hwinfo string attribute is too long." ); + 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()); + memset(hwinfo, 0, HWINFO_MAX_SIZE + 1); + strncpy(hwinfo, phy->hwinfo.c_str(), phy->hwinfo.length()); attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO; - attr.value.s8list.count = (uint32_t) phy->hwinfo.length(); + attr.value.s8list.count = (uint32_t) phy->hwinfo.length() + 1; attr.value.s8list.list = (int8_t *) hwinfo; attrs.push_back(attr); @@ -452,17 +442,21 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy) phy->phy_oid = sai_serialize_object_id(phyOid); - attr.id = SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION; - status = sai_switch_api->get_switch_attribute(phyOid, 1, &attr); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("BOX: Failed to get firmware major version:%d rtn:%d", phy->phy_id, status); - return status; - } - else + if (phy->firmware.length() != 0) { - phy->firmware_major_version = string(attr.value.chardata); + attr.id = SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION; + status = sai_switch_api->get_switch_attribute(phyOid, 1, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("BOX: Failed to get firmware major version for hwinfo:%s, phy:%d, rtn:%d", + phy->hwinfo.c_str(), phy->phy_id, status); + return status; + } + else + { + phy->firmware_major_version = string(attr.value.chardata); + } } - return status; } +