Merge remote-tracking branch 'torvalds/master' into perf/core
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / steering / mlx5dr.h
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 struct mlx5dr_domain *
42 mlx5dr_domain_create(struct mlx5_core_dev *mdev, enum mlx5dr_domain_type type);
43
44 int mlx5dr_domain_destroy(struct mlx5dr_domain *domain);
45
46 int mlx5dr_domain_sync(struct mlx5dr_domain *domain, u32 flags);
47
48 void mlx5dr_domain_set_peer(struct mlx5dr_domain *dmn,
49                             struct mlx5dr_domain *peer_dmn);
50
51 struct mlx5dr_table *
52 mlx5dr_table_create(struct mlx5dr_domain *domain, u32 level, u32 flags);
53
54 int mlx5dr_table_destroy(struct mlx5dr_table *table);
55
56 u32 mlx5dr_table_get_id(struct mlx5dr_table *table);
57
58 struct mlx5dr_matcher *
59 mlx5dr_matcher_create(struct mlx5dr_table *table,
60                       u32 priority,
61                       u8 match_criteria_enable,
62                       struct mlx5dr_match_parameters *mask);
63
64 int mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher);
65
66 struct mlx5dr_rule *
67 mlx5dr_rule_create(struct mlx5dr_matcher *matcher,
68                    struct mlx5dr_match_parameters *value,
69                    size_t num_actions,
70                    struct mlx5dr_action *actions[],
71                    u32 flow_source);
72
73 int mlx5dr_rule_destroy(struct mlx5dr_rule *rule);
74
75 int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
76                                  struct mlx5dr_action *action);
77
78 struct mlx5dr_action *
79 mlx5dr_action_create_dest_table_num(struct mlx5dr_domain *dmn, u32 table_num);
80
81 struct mlx5dr_action *
82 mlx5dr_action_create_dest_table(struct mlx5dr_table *table);
83
84 struct mlx5dr_action *
85 mlx5dr_action_create_dest_flow_fw_table(struct mlx5dr_domain *domain,
86                                         struct mlx5_flow_table *ft);
87
88 struct mlx5dr_action *
89 mlx5dr_action_create_dest_vport(struct mlx5dr_domain *domain,
90                                 u32 vport, u8 vhca_id_valid,
91                                 u16 vhca_id);
92
93 struct mlx5dr_action *
94 mlx5dr_action_create_mult_dest_tbl(struct mlx5dr_domain *dmn,
95                                    struct mlx5dr_action_dest *dests,
96                                    u32 num_of_dests);
97
98 struct mlx5dr_action *mlx5dr_action_create_drop(void);
99
100 struct mlx5dr_action *mlx5dr_action_create_tag(u32 tag_value);
101
102 struct mlx5dr_action *
103 mlx5dr_action_create_flow_counter(u32 counter_id);
104
105 struct mlx5dr_action *
106 mlx5dr_action_create_packet_reformat(struct mlx5dr_domain *dmn,
107                                      enum mlx5dr_action_reformat_type reformat_type,
108                                      size_t data_sz,
109                                      void *data);
110
111 struct mlx5dr_action *
112 mlx5dr_action_create_modify_header(struct mlx5dr_domain *domain,
113                                    u32 flags,
114                                    size_t actions_sz,
115                                    __be64 actions[]);
116
117 struct mlx5dr_action *mlx5dr_action_create_pop_vlan(void);
118
119 struct mlx5dr_action *
120 mlx5dr_action_create_push_vlan(struct mlx5dr_domain *domain, __be32 vlan_hdr);
121
122 int mlx5dr_action_destroy(struct mlx5dr_action *action);
123
124 static inline bool
125 mlx5dr_is_supported(struct mlx5_core_dev *dev)
126 {
127         return MLX5_CAP_GEN(dev, roce) &&
128                (MLX5_CAP_ESW_FLOWTABLE_FDB(dev, sw_owner) ||
129                 (MLX5_CAP_ESW_FLOWTABLE_FDB(dev, sw_owner_v2) &&
130                  (MLX5_CAP_GEN(dev, steering_format_version) <=
131                   MLX5_STEERING_FORMAT_CONNECTX_6DX)));
132 }
133
134 /* buddy functions & structure */
135
136 struct mlx5dr_icm_mr;
137
138 struct mlx5dr_icm_buddy_mem {
139         unsigned long           **bitmap;
140         unsigned int            *num_free;
141         u32                     max_order;
142         struct list_head        list_node;
143         struct mlx5dr_icm_mr    *icm_mr;
144         struct mlx5dr_icm_pool  *pool;
145
146         /* This is the list of used chunks. HW may be accessing this memory */
147         struct list_head        used_list;
148         u64                     used_memory;
149
150         /* Hardware may be accessing this memory but at some future,
151          * undetermined time, it might cease to do so.
152          * sync_ste command sets them free.
153          */
154         struct list_head        hot_list;
155 };
156
157 int mlx5dr_buddy_init(struct mlx5dr_icm_buddy_mem *buddy,
158                       unsigned int max_order);
159 void mlx5dr_buddy_cleanup(struct mlx5dr_icm_buddy_mem *buddy);
160 int mlx5dr_buddy_alloc_mem(struct mlx5dr_icm_buddy_mem *buddy,
161                            unsigned int order,
162                            unsigned int *segment);
163 void mlx5dr_buddy_free_mem(struct mlx5dr_icm_buddy_mem *buddy,
164                            unsigned int seg, unsigned int order);
165
166 #endif /* _MLX5DR_H_ */