1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
4 #ifndef __NFP_FLOWER_H__
5 #define __NFP_FLOWER_H__ 1
9 #include <linux/circ_buf.h>
10 #include <linux/hashtable.h>
11 #include <linux/rhashtable.h>
12 #include <linux/time64.h>
13 #include <linux/types.h>
14 #include <net/pkt_cls.h>
16 #include <linux/workqueue.h>
17 #include <linux/idr.h>
19 struct nfp_fl_pre_lag;
23 #define NFP_FL_STAT_ID_MU_NUM GENMASK(31, 22)
24 #define NFP_FL_STAT_ID_STAT GENMASK(21, 0)
26 #define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \
28 #define NFP_FLOWER_MASK_ENTRY_RS 256
29 #define NFP_FLOWER_MASK_ELEMENT_RS 1
30 #define NFP_FLOWER_MASK_HASH_BITS 10
32 #define NFP_FL_META_FLAG_MANAGE_MASK BIT(7)
34 #define NFP_FL_MASK_REUSE_TIME_NS 40000
35 #define NFP_FL_MASK_ID_LOCATION 1
37 #define NFP_FL_VXLAN_PORT 4789
38 #define NFP_FL_GENEVE_PORT 6081
40 /* Extra features bitmap. */
41 #define NFP_FL_FEATS_GENEVE BIT(0)
42 #define NFP_FL_NBI_MTU_SETTING BIT(1)
43 #define NFP_FL_FEATS_GENEVE_OPT BIT(2)
44 #define NFP_FL_FEATS_VLAN_PCP BIT(3)
45 #define NFP_FL_FEATS_LAG BIT(31)
47 struct nfp_fl_mask_id {
48 struct circ_buf mask_id_free_list;
53 struct nfp_fl_stats_id {
54 struct circ_buf free_list;
60 * struct nfp_fl_tunnel_offloads - priv data for tunnel offloads
61 * @offloaded_macs: Hashtable of the offloaded MAC addresses
62 * @ipv4_off_list: List of IPv4 addresses to offload
63 * @neigh_off_list: List of neighbour offloads
64 * @ipv4_off_lock: Lock for the IPv4 address list
65 * @neigh_off_lock: Lock for the neighbour address list
66 * @mac_off_ids: IDA to manage id assignment for offloaded MACs
67 * @neigh_nb: Notifier to monitor neighbour state
69 struct nfp_fl_tunnel_offloads {
70 struct rhashtable offloaded_macs;
71 struct list_head ipv4_off_list;
72 struct list_head neigh_off_list;
73 struct mutex ipv4_off_lock;
74 spinlock_t neigh_off_lock;
75 struct ida mac_off_ids;
76 struct notifier_block neigh_nb;
80 * struct nfp_mtu_conf - manage MTU setting
81 * @portnum: NFP port number of repr with requested MTU change
82 * @requested_val: MTU value requested for repr
83 * @ack: Received ack that MTU has been correctly set
84 * @wait_q: Wait queue for MTU acknowledgements
85 * @lock: Lock for setting/reading MTU variables
89 unsigned int requested_val;
91 wait_queue_head_t wait_q;
96 * struct nfp_fl_lag - Flower APP priv data for link aggregation
97 * @work: Work queue for writing configs to the HW
98 * @lock: Lock to protect lag_group_list
99 * @group_list: List of all master/slave groups offloaded
100 * @ida_handle: IDA to handle group ids
101 * @pkt_num: Incremented for each config packet sent
102 * @batch_ver: Incremented for each batch of config packets
103 * @global_inst: Instance allocator for groups
104 * @rst_cfg: Marker to reset HW LAG config
105 * @retrans_skbs: Cmsgs that could not be processed by HW and require
109 struct delayed_work work;
111 struct list_head group_list;
112 struct ida ida_handle;
113 unsigned int pkt_num;
114 unsigned int batch_ver;
117 struct sk_buff_head retrans_skbs;
121 * struct nfp_flower_priv - Flower APP per-vNIC priv data
122 * @app: Back pointer to app
123 * @nn: Pointer to vNIC
124 * @mask_id_seed: Seed used for mask hash table
125 * @flower_version: HW version of flower
126 * @flower_ext_feats: Bitmap of extra features the HW supports
127 * @stats_ids: List of free stats ids
128 * @mask_ids: List of free mask ids
129 * @mask_table: Hash table used to store masks
130 * @stats_ring_size: Maximum number of allowed stats ids
131 * @flow_table: Hash table used to store flower rules
132 * @stats: Stored stats updates for flower rules
133 * @stats_lock: Lock for flower rule stats updates
134 * @cmsg_work: Workqueue for control messages processing
135 * @cmsg_skbs_high: List of higher priority skbs for control message
137 * @cmsg_skbs_low: List of lower priority skbs for control message
139 * @tun: Tunnel offload data
140 * @reify_replies: atomically stores the number of replies received
141 * from firmware for repr reify
142 * @reify_wait_queue: wait queue for repr reify response counting
143 * @mtu_conf: Configuration of repr MTU value
144 * @nfp_lag: Link aggregation data block
145 * @indr_block_cb_priv: List of priv data passed to indirect block cbs
146 * @non_repr_priv: List of offloaded non-repr ports and their priv data
147 * @active_mem_unit: Current active memory unit for flower rules
148 * @total_mem_units: Total number of available memory units for flower rules
150 struct nfp_flower_priv {
155 u64 flower_ext_feats;
156 struct nfp_fl_stats_id stats_ids;
157 struct nfp_fl_mask_id mask_ids;
158 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
160 struct rhashtable flow_table;
161 struct nfp_fl_stats *stats;
162 spinlock_t stats_lock; /* lock stats */
163 struct work_struct cmsg_work;
164 struct sk_buff_head cmsg_skbs_high;
165 struct sk_buff_head cmsg_skbs_low;
166 struct nfp_fl_tunnel_offloads tun;
167 atomic_t reify_replies;
168 wait_queue_head_t reify_wait_queue;
169 struct nfp_mtu_conf mtu_conf;
170 struct nfp_fl_lag nfp_lag;
171 struct list_head indr_block_cb_priv;
172 struct list_head non_repr_priv;
173 unsigned int active_mem_unit;
174 unsigned int total_mem_units;
178 * struct nfp_flower_repr_priv - Flower APP per-repr priv data
179 * @nfp_repr: Back pointer to nfp_repr
180 * @lag_port_flags: Extended port flags to record lag state of repr
181 * @mac_offloaded: Flag indicating a MAC address is offloaded for repr
182 * @offloaded_mac_addr: MAC address that has been offloaded for repr
183 * @mac_list: List entry of reprs that share the same offloaded MAC
185 struct nfp_flower_repr_priv {
186 struct nfp_repr *nfp_repr;
187 unsigned long lag_port_flags;
189 u8 offloaded_mac_addr[ETH_ALEN];
190 struct list_head mac_list;
194 * struct nfp_flower_non_repr_priv - Priv data for non-repr offloaded ports
195 * @list: List entry of offloaded reprs
196 * @netdev: Pointer to non-repr net_device
197 * @ref_count: Number of references held for this priv data
198 * @mac_offloaded: Flag indicating a MAC address is offloaded for device
199 * @offloaded_mac_addr: MAC address that has been offloaded for dev
201 struct nfp_flower_non_repr_priv {
202 struct list_head list;
203 struct net_device *netdev;
206 u8 offloaded_mac_addr[ETH_ALEN];
209 struct nfp_fl_key_ls {
215 struct nfp_fl_rule_metadata {
221 __be64 host_cookie __packed;
222 __be64 flow_version __packed;
226 struct nfp_fl_stats {
232 struct nfp_fl_payload {
233 struct nfp_fl_rule_metadata meta;
234 unsigned long tc_flower_cookie;
235 struct rhash_head fl_node;
237 __be32 nfp_tun_ipv4_addr;
238 struct net_device *ingress_dev;
244 extern const struct rhashtable_params nfp_flower_table_params;
246 struct nfp_fl_stats_frame {
253 int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count,
254 unsigned int host_ctx_split);
255 void nfp_flower_metadata_cleanup(struct nfp_app *app);
257 int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
258 enum tc_setup_type type, void *type_data);
259 int nfp_flower_compile_flow_match(struct nfp_app *app,
260 struct tc_cls_flower_offload *flow,
261 struct nfp_fl_key_ls *key_ls,
262 struct net_device *netdev,
263 struct nfp_fl_payload *nfp_flow,
264 enum nfp_flower_tun_type tun_type);
265 int nfp_flower_compile_action(struct nfp_app *app,
266 struct tc_cls_flower_offload *flow,
267 struct net_device *netdev,
268 struct nfp_fl_payload *nfp_flow);
269 int nfp_compile_flow_metadata(struct nfp_app *app,
270 struct tc_cls_flower_offload *flow,
271 struct nfp_fl_payload *nfp_flow,
272 struct net_device *netdev);
273 int nfp_modify_flow_metadata(struct nfp_app *app,
274 struct nfp_fl_payload *nfp_flow);
276 struct nfp_fl_payload *
277 nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
278 struct net_device *netdev);
279 struct nfp_fl_payload *
280 nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
282 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
284 int nfp_tunnel_config_start(struct nfp_app *app);
285 void nfp_tunnel_config_stop(struct nfp_app *app);
286 int nfp_tunnel_mac_event_handler(struct nfp_app *app,
287 struct net_device *netdev,
288 unsigned long event, void *ptr);
289 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
290 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
291 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
292 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
293 void nfp_flower_lag_init(struct nfp_fl_lag *lag);
294 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
295 int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
296 int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv,
297 struct net_device *netdev,
298 unsigned long event, void *ptr);
299 bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
300 int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
301 struct net_device *master,
302 struct nfp_fl_pre_lag *pre_act);
303 int nfp_flower_lag_get_output_id(struct nfp_app *app,
304 struct net_device *master);
305 int nfp_flower_reg_indir_block_handler(struct nfp_app *app,
306 struct net_device *netdev,
307 unsigned long event);
310 __nfp_flower_non_repr_priv_get(struct nfp_flower_non_repr_priv *non_repr_priv);
311 struct nfp_flower_non_repr_priv *
312 nfp_flower_non_repr_priv_get(struct nfp_app *app, struct net_device *netdev);
314 __nfp_flower_non_repr_priv_put(struct nfp_flower_non_repr_priv *non_repr_priv);
316 nfp_flower_non_repr_priv_put(struct nfp_app *app, struct net_device *netdev);