Skip to content

Commit

Permalink
[orchagent]: Enhance initSaiPhyApi (sonic-net#2367)
Browse files Browse the repository at this point in the history
* 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 <aaronp@arista.com>

* Address review comments
* Address review comments, fix hwinfo

Co-authored-by: Aaron Payment <aaronp@arista.com>
  • Loading branch information
andywongarista and aaronpayment authored Jul 18, 2022
1 parent 9d3a5c5 commit 9045995
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions orchagent/saihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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<uint16_t>::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);

Expand Down Expand Up @@ -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;
}

0 comments on commit 9045995

Please sign in to comment.