Skip to content

Commit 9045995

Browse files
[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 <aaronp@arista.com> * Address review comments * Address review comments, fix hwinfo Co-authored-by: Aaron Payment <aaronp@arista.com>
1 parent 9d3a5c5 commit 9045995

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

orchagent/saihelper.cpp

+20-26
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,6 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)
359359
sai_status_t status;
360360
char fwPath[PATH_MAX];
361361
char hwinfo[HWINFO_MAX_SIZE + 1];
362-
char hwinfoIntf[IFNAMSIZ + 1];
363-
unsigned int hwinfoPhyid;
364-
int ret;
365362

366363
SWSS_LOG_ENTER();
367364

@@ -377,22 +374,15 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)
377374
attr.value.u32 = 0;
378375
attrs.push_back(attr);
379376

380-
ret = sscanf(phy->hwinfo.c_str(), "%" STR(IFNAMSIZ) "[^/]/%u", hwinfoIntf, &hwinfoPhyid);
381-
if (ret != 2) {
382-
SWSS_LOG_ERROR("BOX: hardware info doesn't match the 'interface_name/phyid' "
383-
"format");
384-
return SAI_STATUS_FAILURE;
377+
if( phy->hwinfo.length() > HWINFO_MAX_SIZE ) {
378+
SWSS_LOG_ERROR( "hwinfo string attribute is too long." );
379+
return SAI_STATUS_FAILURE;
385380
}
386-
387-
if (hwinfoPhyid > std::numeric_limits<uint16_t>::max()) {
388-
SWSS_LOG_ERROR("BOX: phyid is bigger than maximum limit");
389-
return SAI_STATUS_FAILURE;
390-
}
391-
392-
strcpy(hwinfo, phy->hwinfo.c_str());
381+
memset(hwinfo, 0, HWINFO_MAX_SIZE + 1);
382+
strncpy(hwinfo, phy->hwinfo.c_str(), phy->hwinfo.length());
393383

394384
attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO;
395-
attr.value.s8list.count = (uint32_t) phy->hwinfo.length();
385+
attr.value.s8list.count = (uint32_t) phy->hwinfo.length() + 1;
396386
attr.value.s8list.list = (int8_t *) hwinfo;
397387
attrs.push_back(attr);
398388

@@ -452,17 +442,21 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)
452442

453443
phy->phy_oid = sai_serialize_object_id(phyOid);
454444

455-
attr.id = SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION;
456-
status = sai_switch_api->get_switch_attribute(phyOid, 1, &attr);
457-
if (status != SAI_STATUS_SUCCESS)
458-
{
459-
SWSS_LOG_ERROR("BOX: Failed to get firmware major version:%d rtn:%d", phy->phy_id, status);
460-
return status;
461-
}
462-
else
445+
if (phy->firmware.length() != 0)
463446
{
464-
phy->firmware_major_version = string(attr.value.chardata);
447+
attr.id = SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION;
448+
status = sai_switch_api->get_switch_attribute(phyOid, 1, &attr);
449+
if (status != SAI_STATUS_SUCCESS)
450+
{
451+
SWSS_LOG_ERROR("BOX: Failed to get firmware major version for hwinfo:%s, phy:%d, rtn:%d",
452+
phy->hwinfo.c_str(), phy->phy_id, status);
453+
return status;
454+
}
455+
else
456+
{
457+
phy->firmware_major_version = string(attr.value.chardata);
458+
}
465459
}
466-
467460
return status;
468461
}
462+

0 commit comments

Comments
 (0)