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

[meta][sai] Move extensions SAI and API to 0x20000000 range #2028

Merged
merged 11 commits into from
Jul 14, 2024
2 changes: 1 addition & 1 deletion experimental/saiextensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*/
typedef enum _sai_api_extensions_t
{
SAI_API_EXTENSIONS_RANGE_START = SAI_API_MAX,
SAI_API_EXTENSIONS_RANGE_START = SAI_API_EXTENSIONS_RANGE_BASE,

SAI_API_BMTOR = SAI_API_EXTENSIONS_RANGE_START,

Expand Down
4 changes: 2 additions & 2 deletions experimental/saiportextensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
typedef enum _sai_port_attr_extensions_t
{
SAI_PORT_ATTR_EXTENSIONS_RANGE_START = SAI_PORT_ATTR_END,
SAI_PORT_ATTR_EXTENSIONS_RANGE_START = SAI_PORT_ATTR_EXTENSIONS_RANGE_BASE,

/* Add new experimental port attributes above this line */

Expand All @@ -50,7 +50,7 @@ typedef enum _sai_port_attr_extensions_t
*/
typedef enum _sai_port_stat_extensions_t
{
SAI_PORT_STAT_EXTENSIONS_RANGE_START = SAI_PORT_STAT_END,
SAI_PORT_STAT_EXTENSIONS_RANGE_START = SAI_PORT_STAT_EXTENSIONS_RANGE_BASE,

/** DASH port LB_FAST_PATH_ICMP_IN_BYTES stat count */
SAI_PORT_STAT_LB_FAST_PATH_ICMP_IN_BYTES = SAI_PORT_STAT_EXTENSIONS_RANGE_START,
Expand Down
2 changes: 1 addition & 1 deletion experimental/saiswitchextensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ typedef void (*sai_ha_scope_event_notification_fn)(
*/
typedef enum _sai_switch_attr_extensions_t
{
SAI_SWITCH_ATTR_EXTENSIONS_RANGE_START = SAI_SWITCH_ATTR_END,
SAI_SWITCH_ATTR_EXTENSIONS_RANGE_START = SAI_SWITCH_ATTR_EXTENSIONS_RANGE_BASE,

/**
* @brief Maximum number of meter buckets per ENI.
Expand Down
2 changes: 1 addition & 1 deletion experimental/saitypesextensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
typedef enum _sai_object_type_extensions_t
{
SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START = SAI_OBJECT_TYPE_MAX,
SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START = SAI_OBJECT_TYPE_EXTENSIONS_RANGE_BASE,

SAI_OBJECT_TYPE_TABLE_BITMAP_CLASSIFICATION_ENTRY = SAI_OBJECT_TYPE_EXTENSIONS_RANGE_START,

Expand Down
9 changes: 4 additions & 5 deletions inc/sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ typedef enum _sai_api_t
SAI_API_POE = 51, /**< sai_poe_api_t */
SAI_API_MAX, /**< total number of APIs */

/** Custom range base value */
SAI_API_CUSTOM_RANGE_START = 256,

/** End of custom range base */
SAI_API_CUSTOM_RANGE_END
/**
* @brief Extensions range base
*/
SAI_API_EXTENSIONS_RANGE_BASE = 0x20000000,
} sai_api_t;

/**
Expand Down
10 changes: 8 additions & 2 deletions inc/saiport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2529,7 +2529,10 @@ typedef enum _sai_port_attr_t
SAI_PORT_ATTR_CUSTOM_RANGE_START = 0x10000000,

/** End of custom range base */
SAI_PORT_ATTR_CUSTOM_RANGE_END
SAI_PORT_ATTR_CUSTOM_RANGE_END,

/** Extensions range base */
SAI_PORT_ATTR_EXTENSIONS_RANGE_BASE = 0x20000000

} sai_port_attr_t;

Expand Down Expand Up @@ -3256,7 +3259,10 @@ typedef enum _sai_port_stat_t
SAI_PORT_STAT_OUT_DROP_REASON_RANGE_END = 0x00002fff,

/** Port stat range end */
SAI_PORT_STAT_END
SAI_PORT_STAT_END,

/** Extensions range base */
SAI_PORT_STAT_EXTENSIONS_RANGE_BASE = 0x20000000

} sai_port_stat_t;

Expand Down
5 changes: 4 additions & 1 deletion inc/saiswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,10 @@ typedef enum _sai_switch_attr_t
SAI_SWITCH_ATTR_CUSTOM_RANGE_START = 0x10000000,

/** End of custom range base */
SAI_SWITCH_ATTR_CUSTOM_RANGE_END
SAI_SWITCH_ATTR_CUSTOM_RANGE_END,

/** Extensions range base */
SAI_SWITCH_ATTR_EXTENSIONS_RANGE_BASE = 0x20000000

} sai_switch_attr_t;

Expand Down
6 changes: 1 addition & 5 deletions inc/saitypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ typedef enum _sai_object_type_t
/** Must remain in last position */
SAI_OBJECT_TYPE_MAX,

/** Custom range base value */
SAI_OBJECT_TYPE_CUSTOM_RANGE_START = 256,
Copy link
Contributor

Choose a reason for hiding this comment

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

hi Kamil, just found that these attributes are removed. do we need to keep them but maybe with a different value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

currenty those are not needed, and they were added to fix gcc error, do a git blame and find commit for that change, if we want to add those back, then they need to start as custom range for other enums 0x10000000


/** End of custom range base */
SAI_OBJECT_TYPE_CUSTOM_RANGE_END
SAI_OBJECT_TYPE_EXTENSIONS_RANGE_BASE = 0x20000000,
} sai_object_type_t;

typedef struct _sai_u8_list_t
Expand Down
13 changes: 3 additions & 10 deletions meta/parse.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ sub ProcessSingleObjectType
WriteSource ".isresourcetype = $isresourcetype,";
WriteSource ".isdeprecated = $isdeprecated,";
WriteSource ".isconditionrelaxed = $isrelaxed,";
WriteSource ".iscustom = $attr >= 0x10000000";
WriteSource ".iscustom = ($attr >= 0x10000000) && ($attr < 0x20000000)";

WriteSource "};";

Expand Down Expand Up @@ -2542,7 +2542,8 @@ sub CreateMetadataForAttributes
WriteSource "};";
}

WriteHeader "extern const sai_attr_metadata_t* const* const sai_metadata_attr_by_object_type[];";
# This is disabled since it's object type can't be used as index any more
# WriteHeader "extern const sai_attr_metadata_t* const* const sai_metadata_attr_by_object_type[];";
WriteSource "const sai_attr_metadata_t* const* const sai_metadata_attr_by_object_type[] = {";

for my $ot (@objects)
Expand All @@ -2565,10 +2566,6 @@ sub CreateMetadataForAttributes

WriteHeader "extern const size_t sai_metadata_attr_by_object_type_count;";
WriteSource "const size_t sai_metadata_attr_by_object_type_count = $count;";

WriteSectionComment "Define SAI_OBJECT_TYPE_EXTENSIONS_MAX";

WriteHeader "#define SAI_OBJECT_TYPE_EXTENSIONS_MAX ((sai_object_type_t)$count)";
}

sub CreateEnumHelperMethod
Expand Down Expand Up @@ -3246,10 +3243,6 @@ sub CreateApisStruct
WriteHeader "} sai_apis_t;";

my $count = scalar @apis;

WriteSectionComment "Define SAI_API_EXTENSIONS_MAX";

WriteHeader "#define SAI_API_EXTENSIONS_MAX ((sai_api_t)$count)";
}

sub CreateGlobalApis
Expand Down
38 changes: 17 additions & 21 deletions meta/saidepgraphgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {
}

// node name
#define NN(x) (sai_metadata_enum_sai_object_type_t.valuesshortnames[(x)])
#define NN(x) (sai_metadata_get_enum_value_short_name(&sai_metadata_enum_sai_object_type_t,(x)))

static std::set<sai_object_type_t> source;
static std::set<sai_object_type_t> target;
Expand Down Expand Up @@ -132,19 +132,19 @@ static void process_object_type_attributes(

static void process_object_types()
{
for (int i = 0; sai_metadata_attr_by_object_type[i] != NULL; ++i)
for (int idx = 1; sai_metadata_all_object_type_infos[idx]; ++idx)
{
const sai_attr_metadata_t* const* const meta = sai_metadata_attr_by_object_type[i];
const sai_attr_metadata_t* const* const meta = sai_metadata_all_object_type_infos[idx]->attrmetadata;

process_object_type_attributes(meta, (sai_object_type_t)i);
process_object_type_attributes(meta, sai_metadata_all_object_type_infos[idx]->objecttype);
}
}

static void process_colors()
{
for (int i = 0; sai_metadata_attr_by_object_type[i] != NULL; ++i)
for (int idx = 1; sai_metadata_all_object_type_infos[idx]; ++idx)
{
sai_object_type_t ot = (sai_object_type_t)i;
sai_object_type_t ot = sai_metadata_all_object_type_infos[idx]->objecttype;

bool is_source = source.find(ot) != source.end();
bool is_target = target.find(ot) != target.end();
Expand Down Expand Up @@ -176,23 +176,21 @@ static void process_colors()
}
}

size_t max = show_extensions ? SAI_OBJECT_TYPE_EXTENSIONS_MAX : SAI_OBJECT_TYPE_MAX;

for (size_t i = SAI_OBJECT_TYPE_NULL; i < max; ++i)
for (size_t idx = 1 ; sai_metadata_all_object_type_infos[idx]; ++idx)
{
const sai_object_type_info_t* oi = sai_metadata_all_object_type_infos[i];
const sai_object_type_info_t* oi = sai_metadata_all_object_type_infos[idx];

if (oi == NULL)
if (!oi->isnonobjectid)
{
continue;
}

if (!oi->isnonobjectid)
if (oi->objecttype >= SAI_OBJECT_TYPE_MAX && !show_extensions)
{
continue;
}

std::cout << NN(i) << " [color=plum, shape = rect];\n";
std::cout << NN(oi->objecttype) << " [color=plum, shape = rect];\n";
}
}

Expand All @@ -203,18 +201,16 @@ static void process_nonobjectid_connections()
{
const char* c = " [color=\"0.650 0.700 0.700\", style = dashed, penwidth=2];\n";

size_t max = show_extensions ? SAI_OBJECT_TYPE_EXTENSIONS_MAX : SAI_OBJECT_TYPE_MAX;

for (size_t i = SAI_OBJECT_TYPE_NULL; i < max; ++i)
for (size_t idx = 1 ; sai_metadata_all_object_type_infos[idx]; ++idx)
{
const sai_object_type_info_t* oi = sai_metadata_all_object_type_infos[i];
const sai_object_type_info_t* oi = sai_metadata_all_object_type_infos[idx];

if (oi == NULL)
if (!oi->isnonobjectid)
{
continue;
}

if (!oi->isnonobjectid)
if (oi->objecttype >= SAI_OBJECT_TYPE_MAX && !show_extensions)
{
continue;
}
Expand All @@ -236,12 +232,12 @@ static void process_nonobjectid_connections()
continue;
}

std::cout << NN(ot) << " -> " << NN((sai_object_type_t)i) << c;
std::cout << NN(ot) << " -> " << NN(oi->objecttype) << c;
}
}
else if (sm->isvlan)
{
std::cout << NN(SAI_OBJECT_TYPE_VLAN) << " -> " << NN((sai_object_type_t)i) << c;
std::cout << NN(SAI_OBJECT_TYPE_VLAN) << " -> " << NN(oi->objecttype) << c;
}
}
}
Expand Down
85 changes: 57 additions & 28 deletions meta/saimetadatautils.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,34 @@ const sai_attr_metadata_t* sai_metadata_get_attr_metadata(
_In_ sai_object_type_t objecttype,
_In_ sai_attr_id_t attrid)
{
if (sai_metadata_is_object_type_valid(objecttype))
const sai_object_type_info_t* oi = sai_metadata_get_object_type_info(objecttype);

if (oi == NULL)
{
const sai_attr_metadata_t* const* const md = sai_metadata_attr_by_object_type[objecttype];
return NULL;
}

/*
* Most object attributes are not flags, so we can use direct index to
* find attribute metadata, this should speed up search.
*/
const sai_attr_metadata_t* const* const md = oi->attrmetadata;

const sai_object_type_info_t* oi = sai_metadata_all_object_type_infos[objecttype];
/*
* Most object attributes are not flags, so we can use direct index to
* find attribute metadata, this should speed up search.
*/

if (!oi->enummetadata->containsflags && attrid < oi->attridend)
{
return md[attrid];
}
if (!oi->enummetadata->containsflags && attrid < oi->attridend)
{
return md[attrid];
}

/* otherwise search one by one */
/* otherwise search one by one */

size_t index = 0;
size_t index = 0;

for (; md[index] != NULL; index++)
for (; md[index] != NULL; index++)
{
if (md[index]->attrid == attrid)
{
if (md[index]->attrid == attrid)
{
return md[index];
}
return md[index];
}
}

Expand Down Expand Up @@ -227,21 +229,16 @@ const sai_attr_metadata_t* sai_metadata_get_ignored_attr_metadata_by_attr_id_nam
return NULL;
}

sai_object_type_t ot;
int idx = 1;

/*
* Since we don't have list of ignored attributes, enumerate all objects
* and attribute enums to find ignored values.
*/

for (ot = SAI_OBJECT_TYPE_NULL; ot < SAI_OBJECT_TYPE_EXTENSIONS_MAX; ot++)
for (; sai_metadata_all_object_type_infos[idx]; idx++)
{
const sai_object_type_info_t* oti = sai_metadata_get_object_type_info(ot);

if (oti == NULL)
continue;

const sai_enum_metadata_t* em = oti->enummetadata;
const sai_enum_metadata_t* em = sai_metadata_all_object_type_infos[idx]->enummetadata;

if (em->ignorevaluesnames)
{
Expand Down Expand Up @@ -284,6 +281,28 @@ const char* sai_metadata_get_enum_value_name(
return NULL;
}

const char* sai_metadata_get_enum_value_short_name(
_In_ const sai_enum_metadata_t* metadata,
_In_ int value)
{
if (metadata == NULL)
{
return NULL;
}

size_t i = 0;

for (; i < metadata->valuescount; ++i)
{
if (metadata->values[i] == value)
{
return metadata->valuesshortnames[i];
}
}

return NULL;
}

const sai_attribute_t* sai_metadata_get_attr_by_id(
_In_ sai_attr_id_t id,
_In_ uint32_t attr_count,
Expand All @@ -310,11 +329,21 @@ const sai_attribute_t* sai_metadata_get_attr_by_id(
const sai_object_type_info_t* sai_metadata_get_object_type_info(
_In_ sai_object_type_t object_type)
{
if (sai_metadata_is_object_type_valid(object_type))
if (object_type >= SAI_OBJECT_TYPE_NULL && object_type < SAI_OBJECT_TYPE_MAX)
{
return sai_metadata_all_object_type_infos[object_type];
}

int idx = 1;

for (; sai_metadata_all_object_type_infos[idx]; idx++)
{
if (sai_metadata_all_object_type_infos[idx]->objecttype == object_type)
{
return sai_metadata_all_object_type_infos[idx];
}
}

return NULL;
}

Expand All @@ -334,7 +363,7 @@ bool sai_metadata_is_object_type_oid(
bool sai_metadata_is_object_type_valid(
_In_ sai_object_type_t object_type)
{
return object_type > SAI_OBJECT_TYPE_NULL && object_type < SAI_OBJECT_TYPE_EXTENSIONS_MAX;
return sai_metadata_get_object_type_info(object_type) != NULL;
}

static bool sai_metadata_is_condition_value_eq(
Expand Down
Loading
Loading