1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2020 Mellanox Technologies, Ltd 3 */ 4 5 #ifndef RTE_PMD_MLX5_FLOW_OS_H_ 6 #define RTE_PMD_MLX5_FLOW_OS_H_ 7 8 #include "mlx5_flow.h" 9 #include "mlx5_malloc.h" 10 11 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 12 extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops; 13 #endif 14 15 /** 16 * Get OS enforced flow type. MLX5_FLOW_TYPE_MAX means "non enforced type". 17 * 18 * @return 19 * Flow type (MLX5_FLOW_TYPE_MAX) 20 */ 21 static inline enum mlx5_flow_drv_type 22 mlx5_flow_os_get_type(void) 23 { 24 return MLX5_FLOW_TYPE_DV; 25 } 26 27 /** 28 * Check if item type is supported. 29 * 30 * @param item 31 * Item type to check. 32 * 33 * @return 34 * True is this item type is supported, false if not supported. 35 */ 36 static inline bool 37 mlx5_flow_os_item_supported(int item) 38 { 39 switch (item) { 40 case RTE_FLOW_ITEM_TYPE_END: 41 case RTE_FLOW_ITEM_TYPE_VOID: 42 case RTE_FLOW_ITEM_TYPE_ETH: 43 case RTE_FLOW_ITEM_TYPE_IPV4: 44 case RTE_FLOW_ITEM_TYPE_UDP: 45 case RTE_FLOW_ITEM_TYPE_TCP: 46 case RTE_FLOW_ITEM_TYPE_IPV6: 47 case RTE_FLOW_ITEM_TYPE_VLAN: 48 return true; 49 default: 50 return false; 51 } 52 } 53 54 /** 55 * Check if action type is supported. 56 * 57 * @param action 58 * Action type to check. 59 * 60 * @return 61 * True is this action type is supported, false if not supported. 62 */ 63 static inline bool 64 mlx5_flow_os_action_supported(int action) 65 { 66 switch (action) { 67 case RTE_FLOW_ACTION_TYPE_END: 68 case RTE_FLOW_ACTION_TYPE_VOID: 69 case RTE_FLOW_ACTION_TYPE_QUEUE: 70 case RTE_FLOW_ACTION_TYPE_RSS: 71 return true; 72 default: 73 return false; 74 } 75 } 76 77 /** 78 * Create flow table. 79 * 80 * @param[in] domain 81 * Pointer to relevant domain. 82 * @param[in] table_id 83 * Table ID. 84 * @param[out] table 85 * NULL (no table object required) 86 * 87 * @return 88 * 0 if table_id is 0, negative value otherwise and errno is set. 89 */ 90 static inline int 91 mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table) 92 { 93 RTE_SET_USED(domain); 94 *table = NULL; 95 if (table_id) { 96 rte_errno = ENOTSUP; 97 return -rte_errno; 98 } 99 return 0; 100 } 101 102 /** 103 * Destroy flow table. 104 * 105 * @param table 106 * Pointer to table to destroy. 107 * 108 * @return 109 * 0 on success (silently ignored). 110 */ 111 static inline int 112 mlx5_flow_os_destroy_flow_tbl(void *table) 113 { 114 RTE_SET_USED(table); 115 /* Silently ignore */ 116 return 0; 117 } 118 119 /** 120 * Create flow action: packet reformat. 121 * 122 * @param[in] ctx 123 * Pointer to relevant device context. 124 * @param[in] domain 125 * Pointer to domain handler. 126 * @param[in] resource 127 * Pointer to action data resource. 128 * @param[out] action 129 * Pointer to a valid action on success, NULL otherwise. 130 * 131 * 132 * @return 133 * 0 on success, or negative value on failure and errno is set. 134 */ 135 static inline int 136 mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain, 137 void *resource, void **action) 138 { 139 RTE_SET_USED(ctx); 140 RTE_SET_USED(domain); 141 RTE_SET_USED(resource); 142 RTE_SET_USED(action); 143 rte_errno = ENOTSUP; 144 return -rte_errno; 145 } 146 147 /** 148 * Create flow action: modify header. 149 * 150 * @param[in] ctx 151 * Pointer to relevant device context. 152 * @param[in] domain 153 * Pointer to domain handler. 154 * @param[in] resource 155 * Pointer to action data resource. 156 * @param[in] actions_len 157 * Total length of actions data in resource. 158 * @param[out] action 159 * Pointer to a valid action on success, NULL otherwise. 160 * 161 * 162 * @return 163 * 0 on success, or -1 on failure and errno is set. 164 */ 165 static inline int 166 mlx5_flow_os_create_flow_action_modify_header(void *ctx, 167 void *domain, 168 void *resource, 169 uint32_t actions_len, 170 void **action) 171 { 172 RTE_SET_USED(ctx); 173 RTE_SET_USED(domain); 174 RTE_SET_USED(resource); 175 RTE_SET_USED(actions_len); 176 RTE_SET_USED(action); 177 rte_errno = ENOTSUP; 178 return -rte_errno; 179 } 180 181 /** 182 * Create flow action: destination flow table. 183 * 184 * @param[in] tbl_obj 185 * Pointer to destination table object. 186 * @param[out] action 187 * Pointer to a valid action on success, NULL otherwise. 188 * 189 * @return 190 * 0 on success, or negative value on failure and errno is set. 191 */ 192 static inline int 193 mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action) 194 { 195 RTE_SET_USED(tbl_obj); 196 RTE_SET_USED(action); 197 rte_errno = ENOTSUP; 198 return -rte_errno; 199 } 200 201 /** 202 * Create flow action: destination port. 203 * 204 * @param[in] domain 205 * Pointer to domain handler. 206 * @param[in] port_id 207 * Destination port ID. 208 * @param[out] action 209 * Pointer to a valid action on success, NULL otherwise. 210 * 211 * @return 212 * 0 on success, or negative value on failure and errno is set. 213 */ 214 static inline int 215 mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id, 216 void **action) 217 { 218 RTE_SET_USED(domain); 219 RTE_SET_USED(port_id); 220 *action = NULL; 221 rte_errno = ENOTSUP; 222 return -rte_errno; 223 } 224 225 /** 226 * Create flow action: push vlan. 227 * 228 * @param[in] domain 229 * Pointer to domain handler. 230 * @param[in] vlan_tag 231 * VLAN tag value. 232 * @param[out] action 233 * Pointer to a valid action on success, NULL otherwise. 234 * 235 * @return 236 * 0 on success, or negative value on failure and errno is set. 237 */ 238 static inline int 239 mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag, 240 void **action) 241 { 242 RTE_SET_USED(domain); 243 RTE_SET_USED(vlan_tag); 244 *action = NULL; 245 rte_errno = ENOTSUP; 246 return -rte_errno; 247 } 248 249 /** 250 * Create flow action: count. 251 * 252 * @param[in] cnt_obj 253 * Pointer to DevX counter object. 254 * @param[in] offset 255 * Offset of counter in array. 256 * @param[out] action 257 * Pointer to a valid action on success, NULL otherwise. 258 * 259 * @return 260 * 0 on success, or negative value on failure and errno is set. 261 */ 262 static inline int 263 mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset, 264 void **action) 265 { 266 RTE_SET_USED(cnt_obj); 267 RTE_SET_USED(offset); 268 *action = NULL; 269 rte_errno = ENOTSUP; 270 return -rte_errno; 271 } 272 273 /** 274 * Create flow action: tag. 275 * 276 * @param[in] tag 277 * Tag value. 278 * @param[out] action 279 * Pointer to a valid action on success, NULL otherwise. 280 * 281 * @return 282 * 0 on success, or negative value on failure and errno is set. 283 */ 284 static inline int 285 mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action) 286 { 287 RTE_SET_USED(tag); 288 *action = NULL; 289 rte_errno = ENOTSUP; 290 return -rte_errno; 291 } 292 293 /** 294 * Create flow action: drop. 295 * 296 * @param[out] action 297 * Pointer to a valid action on success, NULL otherwise. 298 * 299 * @return 300 * 0 on success, or negative value on failure and errno is set. 301 */ 302 static inline int 303 mlx5_flow_os_create_flow_action_drop(void **action) 304 { 305 *action = NULL; 306 rte_errno = ENOTSUP; 307 return -rte_errno; 308 } 309 310 /** 311 * Create flow action: default miss. 312 * 313 * @param[out] action 314 * NULL action pointer. 315 * 316 * @return 317 * 0 as success. 318 */ 319 static inline int 320 mlx5_flow_os_create_flow_action_default_miss(void **action) 321 { 322 *action = 0; 323 /* Silently ignore */ 324 return 0; 325 } 326 327 /** 328 * Create flow action: sampler 329 * 330 * @param[in] attr 331 * Pointer to sampler attribute 332 * @param[out] action 333 * Pointer to a valid action on success, NULL otherwise. 334 * 335 * @return 336 * 0 on success, or -1 on failure and errno is set. 337 */ 338 static inline int 339 mlx5_os_flow_dr_create_flow_action_sampler 340 (struct mlx5dv_dr_flow_sampler_attr *attr, 341 void **action) 342 { 343 RTE_SET_USED(attr); 344 *action = NULL; 345 rte_errno = ENOTSUP; 346 return -rte_errno; 347 } 348 349 /** 350 * Create flow action: dest_array 351 * 352 * @param[in] domain 353 * Pointer to relevant domain. 354 * @param[in] num_dest 355 * Number of destinations array. 356 * @param[in] dests 357 * Array of destination attributes. 358 * @param[out] action 359 * Pointer to a valid action on success, NULL otherwise. 360 * 361 * @return 362 * 0 on success, or -1 on failure and errno is set. 363 */ 364 static inline int 365 mlx5_os_flow_dr_create_flow_action_dest_array 366 (void *domain, 367 size_t num_dest, 368 struct mlx5dv_dr_action_dest_attr *dests[], 369 void **action) 370 { 371 RTE_SET_USED(domain); 372 RTE_SET_USED(num_dest); 373 RTE_SET_USED(dests); 374 *action = NULL; 375 rte_errno = ENOTSUP; 376 return -rte_errno; 377 } 378 379 /** 380 * OS stub for mlx5_flow_adjust_priority() API. 381 * Windows only supports flow priority 0 that cannot be adjusted. 382 * 383 * @param[in] dev 384 * Pointer to the Ethernet device structure. 385 * @param[in] priority 386 * The rule base priority. 387 * @param[in] subpriority 388 * The priority based on the items. 389 * 390 * @return 391 * 0 392 */ 393 static inline uint32_t 394 mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority, 395 uint32_t subpriority) 396 { 397 RTE_SET_USED(dev); 398 RTE_SET_USED(priority); 399 RTE_SET_USED(subpriority); 400 return 0; 401 } 402 403 static inline int 404 mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags) 405 { 406 RTE_SET_USED(domain); 407 RTE_SET_USED(flags); 408 errno = ENOTSUP; 409 return errno; 410 } 411 412 int mlx5_flow_os_validate_flow_attributes(struct rte_eth_dev *dev, 413 const struct rte_flow_attr *attributes, 414 bool external, 415 struct rte_flow_error *error); 416 int mlx5_flow_os_create_flow_matcher(void *ctx, 417 void *attr, 418 void *table, 419 void **matcher); 420 int mlx5_flow_os_destroy_flow_matcher(void *matcher); 421 int mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir, 422 void **action); 423 int mlx5_flow_os_destroy_flow_action(void *action); 424 int mlx5_flow_os_create_flow(void *matcher, void *match_value, 425 size_t num_actions, 426 void *actions[], void **flow); 427 int mlx5_flow_os_destroy_flow(void *drv_flow_ptr); 428 #endif /* RTE_PMD_MLX5_FLOW_OS_H_ */ 429