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_STATS_CTX_DONT_CARE cpu_to_be32(0xffffffff)
24 #define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \
26 #define NFP_FLOWER_MASK_ENTRY_RS 256
27 #define NFP_FLOWER_MASK_ELEMENT_RS 1
28 #define NFP_FLOWER_MASK_HASH_BITS 10
30 #define NFP_FL_META_FLAG_MANAGE_MASK BIT(7)
32 #define NFP_FL_MASK_REUSE_TIME_NS 40000
33 #define NFP_FL_MASK_ID_LOCATION 1
35 #define NFP_FL_VXLAN_PORT 4789
36 #define NFP_FL_GENEVE_PORT 6081
38 /* Extra features bitmap. */
39 #define NFP_FL_FEATS_GENEVE BIT(0)
40 #define NFP_FL_NBI_MTU_SETTING BIT(1)
41 #define NFP_FL_FEATS_GENEVE_OPT BIT(2)
42 #define NFP_FL_FEATS_VLAN_PCP BIT(3)
43 #define NFP_FL_FEATS_LAG BIT(31)
45 struct nfp_fl_mask_id {
46 struct circ_buf mask_id_free_list;
51 struct nfp_fl_stats_id {
52 struct circ_buf free_list;
58 * struct nfp_mtu_conf - manage MTU setting
59 * @portnum: NFP port number of repr with requested MTU change
60 * @requested_val: MTU value requested for repr
61 * @ack: Received ack that MTU has been correctly set
62 * @wait_q: Wait queue for MTU acknowledgements
63 * @lock: Lock for setting/reading MTU variables
67 unsigned int requested_val;
69 wait_queue_head_t wait_q;
74 * struct nfp_fl_lag - Flower APP priv data for link aggregation
75 * @work: Work queue for writing configs to the HW
76 * @lock: Lock to protect lag_group_list
77 * @group_list: List of all master/slave groups offloaded
78 * @ida_handle: IDA to handle group ids
79 * @pkt_num: Incremented for each config packet sent
80 * @batch_ver: Incremented for each batch of config packets
81 * @global_inst: Instance allocator for groups
82 * @rst_cfg: Marker to reset HW LAG config
83 * @retrans_skbs: Cmsgs that could not be processed by HW and require
87 struct delayed_work work;
89 struct list_head group_list;
90 struct ida ida_handle;
92 unsigned int batch_ver;
95 struct sk_buff_head retrans_skbs;
99 * struct nfp_flower_priv - Flower APP per-vNIC priv data
100 * @app: Back pointer to app
101 * @nn: Pointer to vNIC
102 * @mask_id_seed: Seed used for mask hash table
103 * @flower_version: HW version of flower
104 * @flower_ext_feats: Bitmap of extra features the HW supports
105 * @stats_ids: List of free stats ids
106 * @mask_ids: List of free mask ids
107 * @mask_table: Hash table used to store masks
108 * @stats_ring_size: Maximum number of allowed stats ids
109 * @flow_table: Hash table used to store flower rules
110 * @stats: Stored stats updates for flower rules
111 * @stats_lock: Lock for flower rule stats updates
112 * @cmsg_work: Workqueue for control messages processing
113 * @cmsg_skbs_high: List of higher priority skbs for control message
115 * @cmsg_skbs_low: List of lower priority skbs for control message
117 * @nfp_mac_off_list: List of MAC addresses to offload
118 * @nfp_mac_index_list: List of unique 8-bit indexes for non NFP netdevs
119 * @nfp_ipv4_off_list: List of IPv4 addresses to offload
120 * @nfp_neigh_off_list: List of neighbour offloads
121 * @nfp_mac_off_lock: Lock for the MAC address list
122 * @nfp_mac_index_lock: Lock for the MAC index list
123 * @nfp_ipv4_off_lock: Lock for the IPv4 address list
124 * @nfp_neigh_off_lock: Lock for the neighbour address list
125 * @nfp_mac_off_ids: IDA to manage id assignment for offloaded macs
126 * @nfp_mac_off_count: Number of MACs in address list
127 * @nfp_tun_neigh_nb: Notifier to monitor neighbour state
128 * @reify_replies: atomically stores the number of replies received
129 * from firmware for repr reify
130 * @reify_wait_queue: wait queue for repr reify response counting
131 * @mtu_conf: Configuration of repr MTU value
132 * @nfp_lag: Link aggregation data block
133 * @indr_block_cb_priv: List of priv data passed to indirect block cbs
135 struct nfp_flower_priv {
140 u64 flower_ext_feats;
141 struct nfp_fl_stats_id stats_ids;
142 struct nfp_fl_mask_id mask_ids;
143 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
145 struct rhashtable flow_table;
146 struct nfp_fl_stats *stats;
147 spinlock_t stats_lock; /* lock stats */
148 struct work_struct cmsg_work;
149 struct sk_buff_head cmsg_skbs_high;
150 struct sk_buff_head cmsg_skbs_low;
151 struct list_head nfp_mac_off_list;
152 struct list_head nfp_mac_index_list;
153 struct list_head nfp_ipv4_off_list;
154 struct list_head nfp_neigh_off_list;
155 struct mutex nfp_mac_off_lock;
156 struct mutex nfp_mac_index_lock;
157 struct mutex nfp_ipv4_off_lock;
158 spinlock_t nfp_neigh_off_lock;
159 struct ida nfp_mac_off_ids;
160 int nfp_mac_off_count;
161 struct notifier_block nfp_tun_neigh_nb;
162 atomic_t reify_replies;
163 wait_queue_head_t reify_wait_queue;
164 struct nfp_mtu_conf mtu_conf;
165 struct nfp_fl_lag nfp_lag;
166 struct list_head indr_block_cb_priv;
170 * struct nfp_flower_repr_priv - Flower APP per-repr priv data
171 * @lag_port_flags: Extended port flags to record lag state of repr
173 struct nfp_flower_repr_priv {
174 unsigned long lag_port_flags;
177 struct nfp_fl_key_ls {
183 struct nfp_fl_rule_metadata {
189 __be64 host_cookie __packed;
190 __be64 flow_version __packed;
194 struct nfp_fl_stats {
200 struct nfp_fl_payload {
201 struct nfp_fl_rule_metadata meta;
202 unsigned long tc_flower_cookie;
203 struct rhash_head fl_node;
205 __be32 nfp_tun_ipv4_addr;
206 struct net_device *ingress_dev;
210 bool ingress_offload;
213 extern const struct rhashtable_params nfp_flower_table_params;
215 struct nfp_fl_stats_frame {
222 int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count);
223 void nfp_flower_metadata_cleanup(struct nfp_app *app);
225 int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
226 enum tc_setup_type type, void *type_data);
227 int nfp_flower_compile_flow_match(struct nfp_app *app,
228 struct tc_cls_flower_offload *flow,
229 struct nfp_fl_key_ls *key_ls,
230 struct net_device *netdev,
231 struct nfp_fl_payload *nfp_flow,
232 enum nfp_flower_tun_type tun_type);
233 int nfp_flower_compile_action(struct nfp_app *app,
234 struct tc_cls_flower_offload *flow,
235 struct net_device *netdev,
236 struct nfp_fl_payload *nfp_flow);
237 int nfp_compile_flow_metadata(struct nfp_app *app,
238 struct tc_cls_flower_offload *flow,
239 struct nfp_fl_payload *nfp_flow,
240 struct net_device *netdev);
241 int nfp_modify_flow_metadata(struct nfp_app *app,
242 struct nfp_fl_payload *nfp_flow);
244 struct nfp_fl_payload *
245 nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
246 struct net_device *netdev, __be32 host_ctx);
247 struct nfp_fl_payload *
248 nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
250 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
252 int nfp_tunnel_config_start(struct nfp_app *app);
253 void nfp_tunnel_config_stop(struct nfp_app *app);
254 int nfp_tunnel_mac_event_handler(struct nfp_app *app,
255 struct net_device *netdev,
256 unsigned long event, void *ptr);
257 void nfp_tunnel_write_macs(struct nfp_app *app);
258 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
259 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
260 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
261 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
262 int nfp_flower_setup_tc_egress_cb(enum tc_setup_type type, void *type_data,
264 void nfp_flower_lag_init(struct nfp_fl_lag *lag);
265 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
266 int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
267 int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv,
268 struct net_device *netdev,
269 unsigned long event, void *ptr);
270 bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
271 int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
272 struct net_device *master,
273 struct nfp_fl_pre_lag *pre_act);
274 int nfp_flower_lag_get_output_id(struct nfp_app *app,
275 struct net_device *master);
276 int nfp_flower_reg_indir_block_handler(struct nfp_app *app,
277 struct net_device *netdev,
278 unsigned long event);