-
Notifications
You must be signed in to change notification settings - Fork 694
[portsorch]: Implement port PFC asym capability check #2942
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // includes ----------------------------------------------------------------------------------------------------------- | ||
|
|
||
| extern "C" { | ||
| #include <saistatus.h> | ||
| } | ||
|
|
||
| #include <string> | ||
|
|
||
| #include <sai_serialize.h> | ||
| #include <logger.h> | ||
|
|
||
| #include "portcap.h" | ||
|
|
||
| using namespace swss; | ||
|
|
||
| // variables ---------------------------------------------------------------------------------------------------------- | ||
|
|
||
| extern sai_object_id_t gSwitchId; | ||
|
|
||
| // functions ---------------------------------------------------------------------------------------------------------- | ||
|
|
||
| static std::string toStr(sai_object_type_t objType, sai_attr_id_t attrId) noexcept | ||
| { | ||
| const auto *meta = sai_metadata_get_attr_metadata(objType, attrId); | ||
|
|
||
| return meta != nullptr ? meta->attridname : "UNKNOWN"; | ||
| } | ||
|
|
||
| // Port capabilities -------------------------------------------------------------------------------------------------- | ||
|
|
||
| PortCapabilities::PortCapabilities() | ||
| { | ||
| queryPortAttrCapabilities(portCapabilities.pfc, SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL); | ||
| queryPortAttrCapabilities(portCapabilities.pfcTx, SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX); | ||
| queryPortAttrCapabilities(portCapabilities.pfcRx, SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX); | ||
| queryPortAttrCapabilities(portCapabilities.pfcMode, SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE); | ||
| } | ||
|
|
||
| bool PortCapabilities::isPortPfcAsymSupported() const | ||
| { | ||
| auto supported = portCapabilities.pfcMode.attrCap.set_implemented; | ||
| supported = supported && portCapabilities.pfc.attrCap.set_implemented; | ||
| supported = supported && portCapabilities.pfcTx.attrCap.set_implemented; | ||
| supported = supported && portCapabilities.pfcRx.attrCap.set_implemented; | ||
|
|
||
| return supported; | ||
| } | ||
|
|
||
| sai_status_t PortCapabilities::queryAttrCapabilitiesSai(sai_attr_capability_t &attrCap, sai_object_type_t objType, sai_attr_id_t attrId) const | ||
| { | ||
| return sai_query_attribute_capability(gSwitchId, objType, attrId, &attrCap); | ||
| } | ||
|
|
||
| template<typename T> | ||
| void PortCapabilities::queryPortAttrCapabilities(T &obj, sai_port_attr_t attrId) | ||
| { | ||
| SWSS_LOG_ENTER(); | ||
|
|
||
| auto status = queryAttrCapabilitiesSai( | ||
| obj.attrCap, SAI_OBJECT_TYPE_PORT, attrId | ||
| ); | ||
| if (status != SAI_STATUS_SUCCESS) | ||
| { | ||
| SWSS_LOG_ERROR( | ||
| "Failed to get attribute(%s) capabilities", | ||
| toStr(SAI_OBJECT_TYPE_PORT, attrId).c_str() | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| if (!obj.attrCap.set_implemented) | ||
| { | ||
| SWSS_LOG_WARN( | ||
| "Attribute(%s) SET is not implemented in SAI", | ||
| toStr(SAI_OBJECT_TYPE_PORT, attrId).c_str() | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #pragma once | ||
|
|
||
| extern "C" { | ||
| #include <saiobject.h> | ||
| #include <saitypes.h> | ||
| #include <saiport.h> | ||
| } | ||
|
|
||
| class PortCapabilities final | ||
| { | ||
| public: | ||
| PortCapabilities(); | ||
| ~PortCapabilities() = default; | ||
|
|
||
| bool isPortPfcAsymSupported() const; | ||
|
|
||
| private: | ||
| sai_status_t queryAttrCapabilitiesSai(sai_attr_capability_t &attrCap, sai_object_type_t objType, sai_attr_id_t attrId) const; | ||
|
|
||
| template<typename T> | ||
| void queryPortAttrCapabilities(T &obj, sai_port_attr_t attrId); | ||
|
|
||
| // Port SAI capabilities | ||
| struct { | ||
| struct { | ||
| sai_attr_capability_t attrCap = { false, false, false }; | ||
| } pfcRx; // SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX | ||
|
|
||
| struct { | ||
| sai_attr_capability_t attrCap = { false, false, false }; | ||
| } pfcTx; // SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX | ||
|
|
||
| struct { | ||
| sai_attr_capability_t attrCap = { false, false, false }; | ||
| } pfc; // SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL | ||
|
|
||
| struct { | ||
| sai_attr_capability_t attrCap = { false, false, false }; | ||
| } pfcMode; // SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE | ||
| } portCapabilities; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.