1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 /* Copyright (c) 2019, Mellanox Technologies */ 3 4 #ifndef _MLX5DR_H_ 5 #define _MLX5DR_H_ 6 7 struct mlx5dr_domain; 8 struct mlx5dr_table; 9 struct mlx5dr_matcher; 10 struct mlx5dr_rule; 11 struct mlx5dr_action; 12 13 enum mlx5dr_domain_type { 14 MLX5DR_DOMAIN_TYPE_NIC_RX, 15 MLX5DR_DOMAIN_TYPE_NIC_TX, 16 MLX5DR_DOMAIN_TYPE_FDB, 17 }; 18 19 enum mlx5dr_domain_sync_flags { 20 MLX5DR_DOMAIN_SYNC_FLAGS_SW = 1 << 0, 21 MLX5DR_DOMAIN_SYNC_FLAGS_HW = 1 << 1, 22 }; 23 24 enum mlx5dr_action_reformat_type { 25 DR_ACTION_REFORMAT_TYP_TNL_L2_TO_L2, 26 DR_ACTION_REFORMAT_TYP_L2_TO_TNL_L2, 27 DR_ACTION_REFORMAT_TYP_TNL_L3_TO_L2, 28 DR_ACTION_REFORMAT_TYP_L2_TO_TNL_L3, 29 }; 30 31 struct mlx5dr_match_parameters { 32 size_t match_sz; 33 u64 *match_buf; /* Device spec format */ 34 }; 35 36 struct mlx5dr_action_dest { 37 struct mlx5dr_action *dest; 38 struct mlx5dr_action *reformat; 39 }; 40 41 #ifdef CONFIG_MLX5_SW_STEERING 42 43 struct mlx5dr_domain * 44 mlx5dr_domain_create(struct mlx5_core_dev *mdev, enum mlx5dr_domain_type type); 45 46 int mlx5dr_domain_destroy(struct mlx5dr_domain *domain); 47 48 int mlx5dr_domain_sync(struct mlx5dr_domain *domain, u32 flags); 49 50 void mlx5dr_domain_set_peer(struct mlx5dr_domain *dmn, 51 struct mlx5dr_domain *peer_dmn); 52 53 struct mlx5dr_table * 54 mlx5dr_table_create(struct mlx5dr_domain *domain, u32 level, u32 flags); 55 56 int mlx5dr_table_destroy(struct mlx5dr_table *table); 57 58 u32 mlx5dr_table_get_id(struct mlx5dr_table *table); 59 60 struct mlx5dr_matcher * 61 mlx5dr_matcher_create(struct mlx5dr_table *table, 62 u16 priority, 63 u8 match_criteria_enable, 64 struct mlx5dr_match_parameters *mask); 65 66 int mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher); 67 68 struct mlx5dr_rule * 69 mlx5dr_rule_create(struct mlx5dr_matcher *matcher, 70 struct mlx5dr_match_parameters *value, 71 size_t num_actions, 72 struct mlx5dr_action *actions[]); 73 74 int mlx5dr_rule_destroy(struct mlx5dr_rule *rule); 75 76 int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl, 77 struct mlx5dr_action *action); 78 79 struct mlx5dr_action * 80 mlx5dr_action_create_dest_table(struct mlx5dr_table *table); 81 82 struct mlx5dr_action * 83 mlx5dr_action_create_dest_flow_fw_table(struct mlx5dr_domain *domain, 84 struct mlx5_flow_table *ft); 85 86 struct mlx5dr_action * 87 mlx5dr_action_create_dest_vport(struct mlx5dr_domain *domain, 88 u32 vport, u8 vhca_id_valid, 89 u16 vhca_id); 90 91 struct mlx5dr_action * 92 mlx5dr_action_create_mult_dest_tbl(struct mlx5dr_domain *dmn, 93 struct mlx5dr_action_dest *dests, 94 u32 num_of_dests); 95 96 struct mlx5dr_action *mlx5dr_action_create_drop(void); 97 98 struct mlx5dr_action *mlx5dr_action_create_tag(u32 tag_value); 99 100 struct mlx5dr_action * 101 mlx5dr_action_create_flow_counter(u32 counter_id); 102 103 struct mlx5dr_action * 104 mlx5dr_action_create_packet_reformat(struct mlx5dr_domain *dmn, 105 enum mlx5dr_action_reformat_type reformat_type, 106 size_t data_sz, 107 void *data); 108 109 struct mlx5dr_action * 110 mlx5dr_action_create_modify_header(struct mlx5dr_domain *domain, 111 u32 flags, 112 size_t actions_sz, 113 __be64 actions[]); 114 115 struct mlx5dr_action *mlx5dr_action_create_pop_vlan(void); 116 117 struct mlx5dr_action * 118 mlx5dr_action_create_push_vlan(struct mlx5dr_domain *domain, __be32 vlan_hdr); 119 120 int mlx5dr_action_destroy(struct mlx5dr_action *action); 121 122 static inline bool 123 mlx5dr_is_supported(struct mlx5_core_dev *dev) 124 { 125 return MLX5_CAP_ESW_FLOWTABLE_FDB(dev, sw_owner); 126 } 127 128 #else /* CONFIG_MLX5_SW_STEERING */ 129 130 static inline struct mlx5dr_domain * 131 mlx5dr_domain_create(struct mlx5_core_dev *mdev, enum mlx5dr_domain_type type) { return NULL; } 132 133 static inline int 134 mlx5dr_domain_destroy(struct mlx5dr_domain *domain) { return 0; } 135 136 static inline int 137 mlx5dr_domain_sync(struct mlx5dr_domain *domain, u32 flags) { return 0; } 138 139 static inline void 140 mlx5dr_domain_set_peer(struct mlx5dr_domain *dmn, 141 struct mlx5dr_domain *peer_dmn) { } 142 143 static inline struct mlx5dr_table * 144 mlx5dr_table_create(struct mlx5dr_domain *domain, u32 level, u32 flags) { return NULL; } 145 146 static inline int 147 mlx5dr_table_destroy(struct mlx5dr_table *table) { return 0; } 148 149 static inline u32 150 mlx5dr_table_get_id(struct mlx5dr_table *table) { return 0; } 151 152 static inline struct mlx5dr_matcher * 153 mlx5dr_matcher_create(struct mlx5dr_table *table, 154 u16 priority, 155 u8 match_criteria_enable, 156 struct mlx5dr_match_parameters *mask) { return NULL; } 157 158 static inline int 159 mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher) { return 0; } 160 161 static inline struct mlx5dr_rule * 162 mlx5dr_rule_create(struct mlx5dr_matcher *matcher, 163 struct mlx5dr_match_parameters *value, 164 size_t num_actions, 165 struct mlx5dr_action *actions[]) { return NULL; } 166 167 static inline int 168 mlx5dr_rule_destroy(struct mlx5dr_rule *rule) { return 0; } 169 170 static inline int 171 mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl, 172 struct mlx5dr_action *action) { return 0; } 173 174 static inline struct mlx5dr_action * 175 mlx5dr_action_create_dest_table(struct mlx5dr_table *table) { return NULL; } 176 177 static inline struct mlx5dr_action * 178 mlx5dr_action_create_dest_flow_fw_table(struct mlx5dr_domain *domain, 179 struct mlx5_flow_table *ft) { return NULL; } 180 181 static inline struct mlx5dr_action * 182 mlx5dr_action_create_dest_vport(struct mlx5dr_domain *domain, 183 u32 vport, u8 vhca_id_valid, 184 u16 vhca_id) { return NULL; } 185 186 static inline struct mlx5dr_action * 187 mlx5dr_action_create_mult_dest_tbl(struct mlx5dr_domain *dmn, 188 struct mlx5dr_action_dest *dests, 189 u32 num_of_dests) { return NULL; } 190 191 static inline struct mlx5dr_action * 192 mlx5dr_action_create_drop(void) { return NULL; } 193 194 static inline struct mlx5dr_action * 195 mlx5dr_action_create_tag(u32 tag_value) { return NULL; } 196 197 static inline struct mlx5dr_action * 198 mlx5dr_action_create_flow_counter(u32 counter_id) { return NULL; } 199 200 static inline struct mlx5dr_action * 201 mlx5dr_action_create_packet_reformat(struct mlx5dr_domain *dmn, 202 enum mlx5dr_action_reformat_type reformat_type, 203 size_t data_sz, 204 void *data) { return NULL; } 205 206 static inline struct mlx5dr_action * 207 mlx5dr_action_create_modify_header(struct mlx5dr_domain *domain, 208 u32 flags, 209 size_t actions_sz, 210 __be64 actions[]) { return NULL; } 211 212 static inline struct mlx5dr_action * 213 mlx5dr_action_create_pop_vlan(void) { return NULL; } 214 215 static inline struct mlx5dr_action * 216 mlx5dr_action_create_push_vlan(struct mlx5dr_domain *domain, 217 __be32 vlan_hdr) { return NULL; } 218 219 static inline int 220 mlx5dr_action_destroy(struct mlx5dr_action *action) { return 0; } 221 222 static inline bool 223 mlx5dr_is_supported(struct mlx5_core_dev *dev) { return false; } 224 225 #endif /* CONFIG_MLX5_SW_STEERING */ 226 227 #endif /* _MLX5DR_H_ */ 228