Linux Audio

Check our new training course

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