Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[orchagent]: Enhance initSaiPhyApi #2367

Merged
merged 4 commits into from
Jul 18, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 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,19 +374,11 @@ 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());
strncpy(hwinfo, phy->hwinfo.c_str(), HWINFO_MAX_SIZE);

attr.id = SAI_SWITCH_ATTR_SWITCH_HARDWARE_INFO;
attr.value.s8list.count = (uint32_t) phy->hwinfo.length();
Expand Down Expand Up @@ -454,15 +443,14 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)

attr.id = SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION;
status = sai_switch_api->get_switch_attribute(phyOid, 1, &attr);
if (status != SAI_STATUS_SUCCESS)
{
if (status == SAI_STATUS_SUCCESS) {
phy->firmware_major_version = string(attr.value.chardata);
} else if( status == SAI_STATUS_NOT_SUPPORTED ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be handled in vendor SAI instead of swss?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vendor SAI will handle returning the appropriate status and setting the attr variable appropriately, and swss will update the local phy object appropriately. I'm not sure I understand why the responsibilities would need to change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do this change in swss, it would change the behavior for all platforms. However, BCM54182(or a few limited platforms) is the only platform that requires this change. That is why I thought it should be vendor SAI's responsibility to do so.
Anyway, if this change has no harm to other platforms, I can live with it. I don't have strong opinion here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should not affect other platforms if they are still returning SAI_STATUS_FAILURE. But I think the change here is appropriate to allow initSaiPhyApi to return with success on platforms that don't support firmware.

phy->firmware_major_version = "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the empty string is good enough here. Should it be "N/A" or "Not Supported"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with changing it to N/A. I don't think there are any strict requirements here.

status = SAI_STATUS_SUCCESS;
} else {
SWSS_LOG_ERROR("BOX: Failed to get firmware major version:%d rtn:%d", phy->phy_id, status);
return status;
}
else
{
phy->firmware_major_version = string(attr.value.chardata);
}

return status;
}