From 2405a35ec0555d469a70d3207e1db08a2690dca2 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Wed, 9 Oct 2024 15:37:39 +0200 Subject: [PATCH] Introduce new extended port oper status notification Bring back compatybility with old structure --- inc/saiport.h | 55 ++++++++++++++++++++++++++++++++++++++++- inc/saiswitch.h | 14 +++++++++++ meta/saisanitycheck.c | 1 + meta/saiserializetest.c | 9 ++++++- meta/structs.pl | 11 +++++++-- 5 files changed, 86 insertions(+), 4 deletions(-) diff --git a/inc/saiport.h b/inc/saiport.h index 2eb6961c5..6afe8820a 100644 --- a/inc/saiport.h +++ b/inc/saiport.h @@ -141,9 +141,48 @@ typedef struct _sai_port_oper_status_notification_t /** Port operational status */ sai_port_oper_status_t port_state; +} sai_port_oper_status_notification_t; + +/** + * @brief Defines the extended operational status of the port + * + * Any additional data will must be passed on attributes list. Usually that + * will be port attributes that are READ_ONLY and the value will represent the + * state of given attribute for port_id object at the time that notification + * was generated. + * + * @count attr_list[attr_count] + */ +typedef struct _sai_extended_port_oper_status_notification_t +{ + /** + * @brief Port id. + * + * @objects SAI_OBJECT_TYPE_PORT, SAI_OBJECT_TYPE_BRIDGE_PORT, SAI_OBJECT_TYPE_LAG + */ + sai_object_id_t port_id; + + /** Port operational status */ + sai_port_oper_status_t port_state; + /** Bitmap of various port error or fault status */ sai_port_error_status_t port_error_status; -} sai_port_oper_status_notification_t; + + /** Attributes count */ + uint32_t attr_count; + + /** + * @brief Attributes + * + * Object type NULL specifies that attribute list is for object type + * specified in port_id field. For example if port_id field contains LAG + * object then list of attributes contains SAI_LAG_ATTR_* attributes. + * + * @objects SAI_OBJECT_TYPE_NULL + */ + sai_attribute_t *attr_list; + +} sai_extended_port_oper_status_notification_t; /** * @brief Attribute data for #SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL_MODE @@ -3502,6 +3541,20 @@ typedef void (*sai_port_state_change_notification_fn)( _In_ uint32_t count, _In_ const sai_port_oper_status_notification_t *data); +/** + * @brief Extended port state change notification + * + * Passed as a parameter into sai_initialize_switch() + * + * @count data[count] + * + * @param[in] count Number of notifications + * @param[in] data Array of port operational status + */ +typedef void (*sai_extended_port_state_change_notification_fn)( + _In_ uint32_t count, + _In_ const sai_extended_port_oper_status_notification_t *data); + /** * @brief Port host tx ready notification * diff --git a/inc/saiswitch.h b/inc/saiswitch.h index 1c13bc24c..bdb92e920 100644 --- a/inc/saiswitch.h +++ b/inc/saiswitch.h @@ -3070,6 +3070,20 @@ typedef enum _sai_switch_attr_t */ SAI_SWITCH_ATTR_SELECTIVE_COUNTER_LIST, + /** + * @brief Extended port state change notification callback function passed to the adapter. + * + * In case driver does not support this attribute, The Host adapter should poll + * port status by SAI_PORT_ATTR_OPER_STATUS. + * + * Use sai_extended_port_state_change_notification_fn as notification function. + * + * @type sai_pointer_t sai_extended_port_state_change_notification_fn + * @flags CREATE_AND_SET + * @default NULL + */ + SAI_SWITCH_ATTR_EXTENDED_PORT_STATE_CHANGE_NOTIFY, + /** * @brief End of attributes */ diff --git a/meta/saisanitycheck.c b/meta/saisanitycheck.c index fb76035a7..8fb8878f7 100644 --- a/meta/saisanitycheck.c +++ b/meta/saisanitycheck.c @@ -5983,6 +5983,7 @@ void check_struct_and_union_size() CHECK_STRUCT_SIZE(sai_port_snr_list_t, 16); CHECK_STRUCT_SIZE(sai_port_snr_values_t, 8); CHECK_STRUCT_SIZE(sai_port_oper_status_notification_t, 16); + CHECK_STRUCT_SIZE(sai_extended_port_oper_status_notification_t, 32); CHECK_STRUCT_SIZE(sai_prbs_rx_state_t, 8); CHECK_STRUCT_SIZE(sai_qos_map_list_t, 16); CHECK_STRUCT_SIZE(sai_qos_map_params_t, 16); diff --git a/meta/saiserializetest.c b/meta/saiserializetest.c index 87e25fd7a..eed04a579 100644 --- a/meta/saiserializetest.c +++ b/meta/saiserializetest.c @@ -1412,7 +1412,14 @@ void test_serialize_notifications() memset(&data1, 0, sizeof(data1)); res = sai_serialize_port_state_change_notification(buf, 1, &data1); - ret = "{\"count\":1,\"data\":[{\"port_id\":\"oid:0x0\",\"port_state\":\"SAI_PORT_OPER_STATUS_UNKNOWN\",\"port_error_status\":\"SAI_PORT_ERROR_STATUS_CLEAR\"}]}"; + ret = "{\"count\":1,\"data\":[{\"port_id\":\"oid:0x0\",\"port_state\":\"SAI_PORT_OPER_STATUS_UNKNOWN\"}]}"; + ASSERT_STR_EQ(buf, ret , res); + + sai_extended_port_oper_status_notification_t data1e; + memset(&data1e, 0, sizeof(data1e)); + + res = sai_serialize_extended_port_state_change_notification(buf, 1, &data1e); + ret = "{\"count\":1,\"data\":[{\"port_id\":\"oid:0x0\",\"port_state\":\"SAI_PORT_OPER_STATUS_UNKNOWN\",\"port_error_status\":\"SAI_PORT_ERROR_STATUS_CLEAR\",\"attr_count\":0,\"attr_list\":null}]}"; ASSERT_STR_EQ(buf, ret , res); sai_queue_deadlock_notification_data_t data2; diff --git a/meta/structs.pl b/meta/structs.pl index 8e6c6ba3d..d8e05bdb2 100755 --- a/meta/structs.pl +++ b/meta/structs.pl @@ -173,8 +173,15 @@ sub BuildCommitHistory if ($histCount > $currCount) { - LogError "FATAL: $structTypeName members were removed on commit $commit, NOT ALLOWED!"; - exit 1; + if ($structTypeName eq "sai_port_oper_status_notification_t") + { + # we allow this to change back backward compatibility + } + else + { + LogError "FATAL: $structTypeName members were removed on commit $commit, NOT ALLOWED!"; + exit 1; + } } my $minCount = ($histCount > $currCount) ? $currCount : $histCount;