| 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 |
DR_ACTION_REFORMAT_TYP_INSERT_HDR, |
| 30 |
DR_ACTION_REFORMAT_TYP_REMOVE_HDR, |
| 31 |
}; |
| 32 |
|
| 33 |
struct mlx5dr_match_parameters { |
| 34 |
size_t match_sz; |
| 35 |
u64 *match_buf; /* Device spec format */ |
| 36 |
}; |
| 37 |
|
| 38 |
struct mlx5dr_action_dest { |
| 39 |
struct mlx5dr_action *dest; |
| 40 |
struct mlx5dr_action *reformat; |
| 41 |
}; |
| 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 |
void mlx5dr_domain_set_peer(struct mlx5dr_domain *dmn, |
| 49 |
struct mlx5dr_domain *peer_dmn, |
| 50 |
u16 peer_vhca_id); |
| 51 |
|
| 52 |
struct mlx5dr_table * |
| 53 |
mlx5dr_table_create(struct mlx5dr_domain *domain, u32 level, u32 flags, |
| 54 |
u16 uid); |
| 55 |
|
| 56 |
struct mlx5dr_table * |
| 57 |
mlx5dr_table_get_from_fs_ft(struct mlx5_flow_table *ft); |
| 58 |
|
| 59 |
int mlx5dr_table_destroy(struct mlx5dr_table *table); |
| 60 |
|
| 61 |
u32 mlx5dr_table_get_id(struct mlx5dr_table *table); |
| 62 |
|
| 63 |
struct mlx5dr_matcher * |
| 64 |
mlx5dr_matcher_create(struct mlx5dr_table *table, |
| 65 |
u32 priority, |
| 66 |
u8 match_criteria_enable, |
| 67 |
struct mlx5dr_match_parameters *mask); |
| 68 |
|
| 69 |
int mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher); |
| 70 |
|
| 71 |
struct mlx5dr_rule * |
| 72 |
mlx5dr_rule_create(struct mlx5dr_matcher *matcher, |
| 73 |
struct mlx5dr_match_parameters *value, |
| 74 |
size_t num_actions, |
| 75 |
struct mlx5dr_action *actions[], |
| 76 |
u32 flow_source); |
| 77 |
|
| 78 |
int mlx5dr_rule_destroy(struct mlx5dr_rule *rule); |
| 79 |
|
| 80 |
int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl, |
| 81 |
struct mlx5dr_action *action); |
| 82 |
|
| 83 |
struct mlx5dr_action * |
| 84 |
mlx5dr_action_create_dest_table_num(struct mlx5dr_domain *dmn, u32 table_num); |
| 85 |
|
| 86 |
struct mlx5dr_action * |
| 87 |
mlx5dr_action_create_dest_table(struct mlx5dr_table *table); |
| 88 |
|
| 89 |
struct mlx5dr_action * |
| 90 |
mlx5dr_action_create_dest_flow_fw_table(struct mlx5dr_domain *domain, |
| 91 |
struct mlx5_flow_table *ft); |
| 92 |
|
| 93 |
struct mlx5dr_action * |
| 94 |
mlx5dr_action_create_dest_vport(struct mlx5dr_domain *domain, |
| 95 |
u16 vport, u8 vhca_id_valid, |
| 96 |
u16 vhca_id); |
| 97 |
|
| 98 |
struct mlx5dr_action * |
| 99 |
mlx5dr_action_create_mult_dest_tbl(struct mlx5dr_domain *dmn, |
| 100 |
struct mlx5dr_action_dest *dests, |
| 101 |
u32 num_of_dests, |
| 102 |
bool ignore_flow_level, |
| 103 |
u32 flow_source); |
| 104 |
|
| 105 |
struct mlx5dr_action *mlx5dr_action_create_drop(void); |
| 106 |
|
| 107 |
struct mlx5dr_action *mlx5dr_action_create_tag(u32 tag_value); |
| 108 |
|
| 109 |
struct mlx5dr_action * |
| 110 |
mlx5dr_action_create_flow_sampler(struct mlx5dr_domain *dmn, u32 sampler_id); |
| 111 |
|
| 112 |
struct mlx5dr_action * |
| 113 |
mlx5dr_action_create_flow_counter(u32 counter_id); |
| 114 |
|
| 115 |
struct mlx5dr_action * |
| 116 |
mlx5dr_action_create_packet_reformat(struct mlx5dr_domain *dmn, |
| 117 |
enum mlx5dr_action_reformat_type reformat_type, |
| 118 |
u8 reformat_param_0, |
| 119 |
u8 reformat_param_1, |
| 120 |
size_t data_sz, |
| 121 |
void *data); |
| 122 |
|
| 123 |
struct mlx5dr_action * |
| 124 |
mlx5dr_action_create_modify_header(struct mlx5dr_domain *domain, |
| 125 |
u32 flags, |
| 126 |
size_t actions_sz, |
| 127 |
__be64 actions[]); |
| 128 |
|
| 129 |
struct mlx5dr_action *mlx5dr_action_create_pop_vlan(void); |
| 130 |
|
| 131 |
struct mlx5dr_action * |
| 132 |
mlx5dr_action_create_push_vlan(struct mlx5dr_domain *domain, __be32 vlan_hdr); |
| 133 |
|
| 134 |
struct mlx5dr_action * |
| 135 |
mlx5dr_action_create_aso(struct mlx5dr_domain *dmn, |
| 136 |
u32 obj_id, |
| 137 |
u8 return_reg_id, |
| 138 |
u8 aso_type, |
| 139 |
u8 init_color, |
| 140 |
u8 meter_id); |
| 141 |
|
| 142 |
struct mlx5dr_action * |
| 143 |
mlx5dr_action_create_dest_match_range(struct mlx5dr_domain *dmn, |
| 144 |
u32 field, |
| 145 |
struct mlx5_flow_table *hit_ft, |
| 146 |
struct mlx5_flow_table *miss_ft, |
| 147 |
u32 min, |
| 148 |
u32 max); |
| 149 |
|
| 150 |
int mlx5dr_action_destroy(struct mlx5dr_action *action); |
| 151 |
|
| 152 |
u32 mlx5dr_action_get_pkt_reformat_id(struct mlx5dr_action *action); |
| 153 |
|
| 154 |
static inline bool |
| 155 |
mlx5dr_is_supported(struct mlx5_core_dev *dev) |
| 156 |
{ |
| 157 |
return MLX5_CAP_GEN(dev, roce) && |
| 158 |
(MLX5_CAP_ESW_FLOWTABLE_FDB(dev, sw_owner) || |
| 159 |
(MLX5_CAP_ESW_FLOWTABLE_FDB(dev, sw_owner_v2) && |
| 160 |
(MLX5_CAP_GEN(dev, steering_format_version) <= |
| 161 |
MLX5_STEERING_FORMAT_CONNECTX_8))); |
| 162 |
} |
| 163 |
|
| 164 |
/* buddy functions & structure */ |
| 165 |
|
| 166 |
struct mlx5dr_icm_mr; |
| 167 |
|
| 168 |
struct mlx5dr_icm_buddy_mem { |
| 169 |
unsigned long **bitmap; |
| 170 |
unsigned int *num_free; |
| 171 |
u32 max_order; |
| 172 |
struct list_head list_node; |
| 173 |
struct mlx5dr_icm_mr *icm_mr; |
| 174 |
struct mlx5dr_icm_pool *pool; |
| 175 |
|
| 176 |
/* Amount of memory in used chunks - HW may be accessing this memory */ |
| 177 |
u64 used_memory; |
| 178 |
|
| 179 |
/* Memory optimisation */ |
| 180 |
struct mlx5dr_ste *ste_arr; |
| 181 |
struct list_head *miss_list; |
| 182 |
u8 *hw_ste_arr; |
| 183 |
}; |
| 184 |
|
| 185 |
int mlx5dr_buddy_init(struct mlx5dr_icm_buddy_mem *buddy, |
| 186 |
unsigned int max_order); |
| 187 |
void mlx5dr_buddy_cleanup(struct mlx5dr_icm_buddy_mem *buddy); |
| 188 |
int mlx5dr_buddy_alloc_mem(struct mlx5dr_icm_buddy_mem *buddy, |
| 189 |
unsigned int order, |
| 190 |
unsigned int *segment); |
| 191 |
void mlx5dr_buddy_free_mem(struct mlx5dr_icm_buddy_mem *buddy, |
| 192 |
unsigned int seg, unsigned int order); |
| 193 |
|
| 194 |
#endif /* _MLX5DR_H_ */ |