1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** NetX shaper */ 16 /** */ 17 /**************************************************************************/ 18 /**************************************************************************/ 19 20 21 /**************************************************************************/ 22 /* */ 23 /* COMPONENT DEFINITION RELEASE */ 24 /* */ 25 /* nx_shaper.h Generic */ 26 /* 6.4.0 */ 27 /* AUTHOR */ 28 /* */ 29 /* Yajun Xia, Microsoft Corporation */ 30 /* */ 31 /* DESCRIPTION */ 32 /* */ 33 /* This file defines the NetX shaper component. */ 34 /* */ 35 /* RELEASE HISTORY */ 36 /* */ 37 /* DATE NAME DESCRIPTION */ 38 /* */ 39 /* 12-31-2023 Yajun Xia Initial Version 6.4.0 */ 40 /* */ 41 /**************************************************************************/ 42 43 #ifndef NX_SHAPER_H 44 #define NX_SHAPER_H 45 46 /* Determine if a C++ compiler is being used. If so, ensure that standard 47 C is used to process the API information. */ 48 #ifdef __cplusplus 49 50 /* Yes, C++ compiler is present. Use standard C. */ 51 extern "C" { 52 53 #endif 54 55 #include "nx_api.h" 56 57 /* Define shaper constants. */ 58 #define NX_SHAPER_CLASS_A_PCP (3) 59 #define NX_SHAPER_CLASS_B_PCP (2) 60 #define NX_SHAPER_PCP_MAX (7) 61 62 #define NX_SHAPER_MAPPING_LIST_SIZE (8) 63 64 #define NX_SHAPER_HW_QUEUE_NONE (0) 65 #define NX_SHAPER_HW_QUEUE_NORMAL (1u << 0) 66 #define NX_SHAPER_HW_QUEUE_CBS (1u << 1) 67 68 #define NX_SHAPER_TYPE_CBS (0) 69 #define NX_SHAPER_TYPE_TAS (1) 70 #define NX_SHAPER_TYPE_FP (2) 71 #define NX_SHAPER_TYPE_MAX (3) 72 73 #define NX_SHAPER_NUMBERS (3) 74 75 #define NX_SHAPER_INVALID_INDEX (0xFF) 76 77 #define NX_SHAPER_CAPABILITY_CBS_SUPPORTED (1U << 1) 78 #define NX_SHAPER_CAPABILITY_TAS_SUPPORTED (1U << 2) 79 #define NX_SHAPER_CAPABILITY_PREEMPTION_SUPPORTED (1U << 3) 80 81 #define NX_SHAPER_COMMAND_INIT (0x01) 82 #define NX_SHAPER_COMMAND_CONFIG (0x02) 83 #define NX_SHAPER_COMMAND_PARAMETER_SET (0x03) 84 85 #define NX_SHAPER_MAX_SPA_QUEUE_NUM (8) 86 87 #define NX_SHAPER_GATE_OPERATION_SET (0) 88 #define NX_SHAPER_GATE_OPERATION_HOLD (1) 89 #define NX_SHAPER_GATE_OPERATION_RELEASE (2) 90 91 #define NX_SHAPER_GCL_LENGTH_MAX (32) 92 93 #define NX_SHAPER_TRAFFIC_OPEN (1) 94 #define NX_SHAPER_TRAFFIC_CLOSE (0) 95 96 #define NX_SHAPER_TAS_IDLE_CYCLE_AUTO_FILL_DISABLED (0) 97 #define NX_SHAPER_TAS_IDLE_CYCLE_AUTO_FILL_WITH_OPEN (1) 98 #define NX_SHAPER_TAS_IDLE_CYCLE_AUTO_FILL_WITH_CLOSE (2) 99 100 #define NX_SHAPER_GCL_AUTO_FILL_FLAG (0x80000000) 101 102 #define NX_SHAPER_DEFAULT_MIN_FRAGMENTABLE_SDU_SIZE (123) 103 #define NX_SHAPER_DEFAULT_MIN_SDU_SIZE (64) 104 105 #define NX_SHAPER_FP_DEFAULT_HA (0) 106 #define NX_SHAPER_FP_DEFAULT_RA (0xFFFFFFFF) 107 108 /* Shaper structure. */ 109 struct NX_SHAPER_DRIVER_PARAMETER_STRUCT; 110 typedef UINT (*NX_SHAPER_DRIVER)(struct NX_SHAPER_DRIVER_PARAMETER_STRUCT *parameter); 111 typedef UINT (*NX_SHAPER_DEFAULT_MAPPING_GET)(NX_INTERFACE *interface_ptr, UCHAR *pcp_list, UCHAR *queue_id_list, UCHAR list_size); 112 113 typedef struct NX_SHAPER_HW_QUEUE_STRUCT 114 { 115 UCHAR hw_queue_id; 116 UCHAR priority; 117 UCHAR type; 118 UCHAR reserved; 119 } NX_SHAPER_HW_QUEUE; 120 121 typedef struct NX_SHAPER_STRUCT 122 { 123 UCHAR shaper_type; 124 UCHAR reserved[3]; 125 NX_SHAPER_DRIVER shaper_driver; 126 void *cfg_pointer; 127 } NX_SHAPER; 128 129 typedef struct NX_SHAPER_CONTAINER_STRUCT 130 { 131 UINT port_rate; /* Mbps */ 132 UCHAR shaper_capability; /* cbs/tas/preemption control */ 133 UCHAR hw_queue_number; /* total number of hardware queues */ 134 UCHAR shaper_number; /* total number of shapers */ 135 UCHAR reserved; 136 NX_SHAPER_HW_QUEUE hw_queue[NX_SHAPER_MAX_SPA_QUEUE_NUM]; 137 UCHAR queue_map[NX_SHAPER_MAX_SPA_QUEUE_NUM]; 138 NX_SHAPER *shaper[NX_SHAPER_NUMBERS]; 139 } NX_SHAPER_CONTAINER; 140 141 typedef struct NX_SHAPER_CBS_PARAMETER_STRUCT 142 { 143 INT idle_slope; /* Mbps */ 144 INT send_slope; /* Mbps */ 145 INT hi_credit; 146 INT low_credit; 147 UCHAR hw_queue_id; 148 UCHAR reserved[3]; 149 } NX_SHAPER_CBS_PARAMETER; 150 151 typedef struct NX_SHAPER_DRIVER_PARAMETER_STRUCT 152 { 153 UINT nx_shaper_driver_command; 154 UCHAR shaper_type; 155 UCHAR reserved[3]; 156 void *shaper_parameter; 157 NX_INTERFACE *nx_ip_driver_interface; 158 } NX_SHAPER_DRIVER_PARAMETER; 159 160 typedef struct NX_SHAPER_TAS_GCL_STRUCT 161 { 162 UINT gate_control; /* max 8 queues */ 163 UINT duration; 164 UCHAR operation; 165 UCHAR reserved[3]; 166 } NX_SHAPER_TAS_GCL; 167 168 typedef struct NX_SHAPER_TAS_PARAMETER_STRUCT 169 { 170 ULONG64 base_time; 171 UINT cycle_time; 172 UINT cycle_time_extension; 173 UINT gcl_length; 174 NX_SHAPER_TAS_GCL gcl[NX_SHAPER_GCL_LENGTH_MAX]; 175 void *fp_parameter; /* Configured by shaper */ 176 } NX_SHAPER_TAS_PARAMETER; 177 178 typedef struct NX_SHAPER_TAS_TRAFFIC_CONFIG_STRUCT 179 { 180 UCHAR pcp; 181 UCHAR traffic_control; 182 UCHAR reserved[2]; 183 UINT time_offset; /* slot start offset of each cycle */ 184 UINT duration; 185 } NX_SHAPER_TAS_TRAFFIC_CONFIG; 186 187 typedef struct NX_SHAPER_TAS_CONFIG_STRUCT 188 { 189 ULONG64 base_time; /* (nano seconds) 0 means current cycle finish time */ 190 UINT cycle_time; /* (nano seconds) */ 191 UINT auto_fill_status; 192 UINT traffic_count; 193 NX_SHAPER_TAS_TRAFFIC_CONFIG traffic[NX_SHAPER_GCL_LENGTH_MAX]; 194 } NX_SHAPER_TAS_CONFIG; 195 196 typedef struct NX_SHAPER_FP_PARAMETER_STRUCT 197 { 198 UCHAR verification_enable; /* Enable/Disable fp verification (Application/Driver) */ 199 UCHAR express_queue_bitmap; /* Bitmap of express queues */ 200 UCHAR express_guardband_enable; /* Enable/Disable guard band on express queue */ 201 UCHAR reserved; 202 UINT ha; /* Hold advance time */ 203 UINT ra; /* Release advance time */ 204 } NX_SHAPER_FP_PARAMETER; 205 206 /* APIs for network driver. */ 207 UINT nx_shaper_config(NX_INTERFACE *interface_ptr, UINT port_rate, UCHAR shaper_capability, 208 UCHAR hw_queue_number, NX_SHAPER_HW_QUEUE *hw_queue); 209 UINT nx_shaper_hw_queue_set(NX_INTERFACE *interface_ptr, UCHAR hw_queue_id, UCHAR priority, UCHAR type); 210 UINT nx_shaper_hw_queue_id_get(NX_INTERFACE *interface_ptr, NX_PACKET *packet_ptr, UCHAR *hw_queue_id); 211 212 /* Define APIs for application. */ 213 UINT nx_shaper_create(NX_INTERFACE *interface_ptr, NX_SHAPER_CONTAINER *shaper_container, NX_SHAPER *shaper, UCHAR shaper_type, NX_SHAPER_DRIVER shaper_driver); 214 UINT nx_shaper_delete(NX_INTERFACE *interface_ptr, NX_SHAPER *shaper); 215 UINT nx_shaper_current_mapping_get(NX_INTERFACE *interface_ptr, UCHAR *pcp_list, UCHAR *queue_id_list, UCHAR list_size); 216 UINT nx_shaper_default_mapping_get(NX_INTERFACE *interface_ptr, UCHAR *pcp_list, UCHAR *queue_id_list, UCHAR list_size); 217 UINT nx_shaper_mapping_set(NX_INTERFACE *interface_ptr, UCHAR *pcp_list, UCHAR *queue_id_list, UCHAR list_size); 218 UINT nx_shaper_cbs_parameter_set(NX_INTERFACE *interface_ptr, NX_SHAPER_CBS_PARAMETER *cbs_parameter, UCHAR pcp); 219 UINT nx_shaper_fp_parameter_set(NX_INTERFACE *interface_ptr, NX_SHAPER_FP_PARAMETER *fp_parameter); 220 UINT nx_shaper_tas_parameter_set(NX_INTERFACE *interface_ptr, NX_SHAPER_TAS_CONFIG *tas_config); 221 222 /* Internal functions. */ 223 UINT nx_shaper_hw_queue_number_get(NX_INTERFACE *interface_ptr, UCHAR *hw_queue_number); 224 UINT nx_shaper_hw_cbs_queue_number_get(NX_INTERFACE *interface_ptr, UCHAR *hw_cbs_queue_number); 225 UINT nx_shaper_port_rate_get(NX_INTERFACE *interface_ptr, UINT *port_rate); 226 UINT nx_shaper_sdu_tx_time_get(NX_INTERFACE *interface_ptr, UINT sdu_size, UINT *tx_time); 227 UINT nx_shaper_express_queue_set(NX_INTERFACE *interface_ptr, UCHAR *express_queue_bitmap, UCHAR pcp); 228 229 #ifdef __cplusplus 230 } 231 #endif 232 233 #endif /* NX_SHAPER_H */ 234 235