Merge branch 'hns3-next'
[linux-block.git] / drivers / net / ethernet / netronome / nfp / flower / main.h
CommitLineData
96de2506
JK
1/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
8a276873
PJV
3
4#ifndef __NFP_FLOWER_H__
5#define __NFP_FLOWER_H__ 1
6
bedeca15
JH
7#include "cmsg.h"
8
43f84b72
PJV
9#include <linux/circ_buf.h>
10#include <linux/hashtable.h>
c01d0efa 11#include <linux/rhashtable.h>
43f84b72 12#include <linux/time64.h>
8a276873 13#include <linux/types.h>
de4784ca 14#include <net/pkt_cls.h>
ffa61202 15#include <net/tcp.h>
b985f870 16#include <linux/workqueue.h>
bb9a8d03 17#include <linux/idr.h>
8a276873 18
7e24a593 19struct nfp_fl_pre_lag;
8a276873
PJV
20struct net_device;
21struct nfp_app;
22
467322e2
PJV
23#define NFP_FL_STAT_ID_MU_NUM GENMASK(31, 22)
24#define NFP_FL_STAT_ID_STAT GENMASK(21, 0)
25
12ecf615
PJV
26#define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \
27 init_unalloc)
43f84b72
PJV
28#define NFP_FLOWER_MASK_ENTRY_RS 256
29#define NFP_FLOWER_MASK_ELEMENT_RS 1
30#define NFP_FLOWER_MASK_HASH_BITS 10
31
6c3ab204 32#define NFP_FL_META_FLAG_MANAGE_MASK BIT(7)
43f84b72
PJV
33
34#define NFP_FL_MASK_REUSE_TIME_NS 40000
35#define NFP_FL_MASK_ID_LOCATION 1
36
bedeca15
JH
37/* Extra features bitmap. */
38#define NFP_FL_FEATS_GENEVE BIT(0)
29a5dcae 39#define NFP_FL_NBI_MTU_SETTING BIT(1)
9e7c32fe 40#define NFP_FL_FEATS_GENEVE_OPT BIT(2)
db191db8 41#define NFP_FL_FEATS_VLAN_PCP BIT(3)
898bc7d6 42#define NFP_FL_FEATS_LAG BIT(31)
611aec10 43
43f84b72
PJV
44struct nfp_fl_mask_id {
45 struct circ_buf mask_id_free_list;
51bef926 46 ktime_t *last_used;
43f84b72
PJV
47 u8 init_unallocated;
48};
49
abfcdc1d
PJV
50struct nfp_fl_stats_id {
51 struct circ_buf free_list;
52 u32 init_unalloc;
53 u8 repeated_em_count;
54};
55
f3b97577
JH
56/**
57 * struct nfp_fl_tunnel_offloads - priv data for tunnel offloads
20cce886 58 * @offloaded_macs: Hashtable of the offloaded MAC addresses
f3b97577
JH
59 * @ipv4_off_list: List of IPv4 addresses to offload
60 * @neigh_off_list: List of neighbour offloads
f3b97577
JH
61 * @ipv4_off_lock: Lock for the IPv4 address list
62 * @neigh_off_lock: Lock for the neighbour address list
63 * @mac_off_ids: IDA to manage id assignment for offloaded MACs
f3b97577
JH
64 * @neigh_nb: Notifier to monitor neighbour state
65 */
66struct nfp_fl_tunnel_offloads {
20cce886 67 struct rhashtable offloaded_macs;
f3b97577
JH
68 struct list_head ipv4_off_list;
69 struct list_head neigh_off_list;
f3b97577
JH
70 struct mutex ipv4_off_lock;
71 spinlock_t neigh_off_lock;
72 struct ida mac_off_ids;
f3b97577
JH
73 struct notifier_block neigh_nb;
74};
75
29a5dcae
JH
76/**
77 * struct nfp_mtu_conf - manage MTU setting
78 * @portnum: NFP port number of repr with requested MTU change
79 * @requested_val: MTU value requested for repr
80 * @ack: Received ack that MTU has been correctly set
81 * @wait_q: Wait queue for MTU acknowledgements
82 * @lock: Lock for setting/reading MTU variables
83 */
84struct nfp_mtu_conf {
85 u32 portnum;
86 unsigned int requested_val;
87 bool ack;
88 wait_queue_head_t wait_q;
89 spinlock_t lock;
90};
91
bb9a8d03
JH
92/**
93 * struct nfp_fl_lag - Flower APP priv data for link aggregation
bb9a8d03
JH
94 * @work: Work queue for writing configs to the HW
95 * @lock: Lock to protect lag_group_list
96 * @group_list: List of all master/slave groups offloaded
97 * @ida_handle: IDA to handle group ids
98 * @pkt_num: Incremented for each config packet sent
99 * @batch_ver: Incremented for each batch of config packets
100 * @global_inst: Instance allocator for groups
101 * @rst_cfg: Marker to reset HW LAG config
2e1cc522
JH
102 * @retrans_skbs: Cmsgs that could not be processed by HW and require
103 * retransmission
bb9a8d03
JH
104 */
105struct nfp_fl_lag {
bb9a8d03
JH
106 struct delayed_work work;
107 struct mutex lock;
108 struct list_head group_list;
109 struct ida ida_handle;
110 unsigned int pkt_num;
111 unsigned int batch_ver;
112 u8 global_inst;
113 bool rst_cfg;
2e1cc522 114 struct sk_buff_head retrans_skbs;
bb9a8d03
JH
115};
116
43f84b72
PJV
117/**
118 * struct nfp_flower_priv - Flower APP per-vNIC priv data
c496291c 119 * @app: Back pointer to app
43f84b72
PJV
120 * @nn: Pointer to vNIC
121 * @mask_id_seed: Seed used for mask hash table
122 * @flower_version: HW version of flower
73997348 123 * @flower_ext_feats: Bitmap of extra features the HW supports
abfcdc1d 124 * @stats_ids: List of free stats ids
43f84b72
PJV
125 * @mask_ids: List of free mask ids
126 * @mask_table: Hash table used to store masks
12ecf615 127 * @stats_ring_size: Maximum number of allowed stats ids
43f84b72 128 * @flow_table: Hash table used to store flower rules
7fade107
PJV
129 * @stats: Stored stats updates for flower rules
130 * @stats_lock: Lock for flower rule stats updates
b985f870 131 * @cmsg_work: Workqueue for control messages processing
cf2cbadc
PJV
132 * @cmsg_skbs_high: List of higher priority skbs for control message
133 * processing
134 * @cmsg_skbs_low: List of lower priority skbs for control message
135 * processing
f3b97577 136 * @tun: Tunnel offload data
d2c2928d
DM
137 * @reify_replies: atomically stores the number of replies received
138 * from firmware for repr reify
139 * @reify_wait_queue: wait queue for repr reify response counting
29a5dcae 140 * @mtu_conf: Configuration of repr MTU value
bb9a8d03 141 * @nfp_lag: Link aggregation data block
3166dd07 142 * @indr_block_cb_priv: List of priv data passed to indirect block cbs
05d2bee6 143 * @non_repr_priv: List of offloaded non-repr ports and their priv data
467322e2
PJV
144 * @active_mem_unit: Current active memory unit for flower rules
145 * @total_mem_units: Total number of available memory units for flower rules
43f84b72
PJV
146 */
147struct nfp_flower_priv {
c496291c 148 struct nfp_app *app;
43f84b72
PJV
149 struct nfp_net *nn;
150 u32 mask_id_seed;
151 u64 flower_version;
73997348 152 u64 flower_ext_feats;
abfcdc1d 153 struct nfp_fl_stats_id stats_ids;
43f84b72
PJV
154 struct nfp_fl_mask_id mask_ids;
155 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
12ecf615 156 u32 stats_ring_size;
c01d0efa 157 struct rhashtable flow_table;
7fade107
PJV
158 struct nfp_fl_stats *stats;
159 spinlock_t stats_lock; /* lock stats */
b985f870 160 struct work_struct cmsg_work;
cf2cbadc
PJV
161 struct sk_buff_head cmsg_skbs_high;
162 struct sk_buff_head cmsg_skbs_low;
f3b97577 163 struct nfp_fl_tunnel_offloads tun;
d2c2928d
DM
164 atomic_t reify_replies;
165 wait_queue_head_t reify_wait_queue;
29a5dcae 166 struct nfp_mtu_conf mtu_conf;
bb9a8d03 167 struct nfp_fl_lag nfp_lag;
3166dd07 168 struct list_head indr_block_cb_priv;
05d2bee6 169 struct list_head non_repr_priv;
467322e2
PJV
170 unsigned int active_mem_unit;
171 unsigned int total_mem_units;
43f84b72
PJV
172};
173
b9452452
JH
174/**
175 * struct nfp_flower_repr_priv - Flower APP per-repr priv data
20cce886 176 * @nfp_repr: Back pointer to nfp_repr
b9452452 177 * @lag_port_flags: Extended port flags to record lag state of repr
13cf7103
JH
178 * @mac_offloaded: Flag indicating a MAC address is offloaded for repr
179 * @offloaded_mac_addr: MAC address that has been offloaded for repr
20cce886 180 * @mac_list: List entry of reprs that share the same offloaded MAC
b9452452
JH
181 */
182struct nfp_flower_repr_priv {
20cce886 183 struct nfp_repr *nfp_repr;
b9452452 184 unsigned long lag_port_flags;
13cf7103
JH
185 bool mac_offloaded;
186 u8 offloaded_mac_addr[ETH_ALEN];
20cce886 187 struct list_head mac_list;
b9452452
JH
188};
189
05d2bee6
JH
190/**
191 * struct nfp_flower_non_repr_priv - Priv data for non-repr offloaded ports
192 * @list: List entry of offloaded reprs
193 * @netdev: Pointer to non-repr net_device
194 * @ref_count: Number of references held for this priv data
13cf7103
JH
195 * @mac_offloaded: Flag indicating a MAC address is offloaded for device
196 * @offloaded_mac_addr: MAC address that has been offloaded for dev
05d2bee6
JH
197 */
198struct nfp_flower_non_repr_priv {
199 struct list_head list;
200 struct net_device *netdev;
201 int ref_count;
13cf7103
JH
202 bool mac_offloaded;
203 u8 offloaded_mac_addr[ETH_ALEN];
05d2bee6
JH
204};
205
af9d842c
PJV
206struct nfp_fl_key_ls {
207 u32 key_layer_two;
208 u8 key_layer;
209 int key_size;
210};
211
212struct nfp_fl_rule_metadata {
213 u8 key_len;
214 u8 mask_len;
215 u8 act_len;
216 u8 flags;
217 __be32 host_ctx_id;
218 __be64 host_cookie __packed;
219 __be64 flow_version __packed;
220 __be32 shortcut;
221};
222
abfcdc1d
PJV
223struct nfp_fl_stats {
224 u64 pkts;
225 u64 bytes;
226 u64 used;
227};
228
af9d842c
PJV
229struct nfp_fl_payload {
230 struct nfp_fl_rule_metadata meta;
43f84b72 231 unsigned long tc_flower_cookie;
c01d0efa 232 struct rhash_head fl_node;
43f84b72 233 struct rcu_head rcu;
2d9ad71a 234 __be32 nfp_tun_ipv4_addr;
54a4a034 235 struct net_device *ingress_dev;
af9d842c
PJV
236 char *unmasked_data;
237 char *mask_data;
238 char *action_data;
239};
240
c01d0efa
PJV
241extern const struct rhashtable_params nfp_flower_table_params;
242
abfcdc1d
PJV
243struct nfp_fl_stats_frame {
244 __be32 stats_con_id;
245 __be32 pkt_count;
246 __be64 byte_count;
247 __be64 stats_cookie;
248};
249
467322e2
PJV
250int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count,
251 unsigned int host_ctx_split);
43f84b72
PJV
252void nfp_flower_metadata_cleanup(struct nfp_app *app);
253
8a276873 254int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
de4784ca 255 enum tc_setup_type type, void *type_data);
7885b4fc
JH
256int nfp_flower_compile_flow_match(struct nfp_app *app,
257 struct tc_cls_flower_offload *flow,
5571e8c9
PJV
258 struct nfp_fl_key_ls *key_ls,
259 struct net_device *netdev,
bedeca15
JH
260 struct nfp_fl_payload *nfp_flow,
261 enum nfp_flower_tun_type tun_type);
7e24a593
JH
262int nfp_flower_compile_action(struct nfp_app *app,
263 struct tc_cls_flower_offload *flow,
1a1e586f
PJV
264 struct net_device *netdev,
265 struct nfp_fl_payload *nfp_flow);
43f84b72
PJV
266int nfp_compile_flow_metadata(struct nfp_app *app,
267 struct tc_cls_flower_offload *flow,
54a4a034
JH
268 struct nfp_fl_payload *nfp_flow,
269 struct net_device *netdev);
43f84b72
PJV
270int nfp_modify_flow_metadata(struct nfp_app *app,
271 struct nfp_fl_payload *nfp_flow);
272
273struct nfp_fl_payload *
54a4a034 274nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
d4b69bad 275 struct net_device *netdev);
43f84b72
PJV
276struct nfp_fl_payload *
277nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
5571e8c9 278
abfcdc1d
PJV
279void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
280
fd0dd1ab
JH
281int nfp_tunnel_config_start(struct nfp_app *app);
282void nfp_tunnel_config_stop(struct nfp_app *app);
0c665e2b
JK
283int nfp_tunnel_mac_event_handler(struct nfp_app *app,
284 struct net_device *netdev,
285 unsigned long event, void *ptr);
2d9ad71a
JH
286void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
287void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
8e6a9046 288void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
856f5b13 289void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
bb9a8d03
JH
290void nfp_flower_lag_init(struct nfp_fl_lag *lag);
291void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
292int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
0c665e2b
JK
293int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv,
294 struct net_device *netdev,
295 unsigned long event, void *ptr);
2e1cc522 296bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
7e24a593
JH
297int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
298 struct net_device *master,
299 struct nfp_fl_pre_lag *pre_act);
300int nfp_flower_lag_get_output_id(struct nfp_app *app,
301 struct net_device *master);
3166dd07
JH
302int nfp_flower_reg_indir_block_handler(struct nfp_app *app,
303 struct net_device *netdev,
304 unsigned long event);
fd0dd1ab 305
05d2bee6
JH
306void
307__nfp_flower_non_repr_priv_get(struct nfp_flower_non_repr_priv *non_repr_priv);
308struct nfp_flower_non_repr_priv *
309nfp_flower_non_repr_priv_get(struct nfp_app *app, struct net_device *netdev);
310void
311__nfp_flower_non_repr_priv_put(struct nfp_flower_non_repr_priv *non_repr_priv);
312void
313nfp_flower_non_repr_priv_put(struct nfp_app *app, struct net_device *netdev);
8a276873 314#endif