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 * @lag_nb: Notifier to track master/slave events
76 * @work: Work queue for writing configs to the HW
77 * @lock: Lock to protect lag_group_list
78 * @group_list: List of all master/slave groups offloaded
79 * @ida_handle: IDA to handle group ids
80 * @pkt_num: Incremented for each config packet sent
81 * @batch_ver: Incremented for each batch of config packets
82 * @global_inst: Instance allocator for groups
83 * @rst_cfg: Marker to reset HW LAG config
84 * @retrans_skbs: Cmsgs that could not be processed by HW and require
88 struct notifier_block lag_nb;
89 struct delayed_work work;
91 struct list_head group_list;
92 struct ida ida_handle;
94 unsigned int batch_ver;
97 struct sk_buff_head retrans_skbs;
101 * struct nfp_flower_priv - Flower APP per-vNIC priv data
102 * @app: Back pointer to app
103 * @nn: Pointer to vNIC
104 * @mask_id_seed: Seed used for mask hash table
105 * @flower_version: HW version of flower
106 * @flower_ext_feats: Bitmap of extra features the HW supports
107 * @stats_ids: List of free stats ids
108 * @mask_ids: List of free mask ids
109 * @mask_table: Hash table used to store masks
110 * @stats_ring_size: Maximum number of allowed stats ids
111 * @flow_table: Hash table used to store flower rules
112 * @stats: Stored stats updates for flower rules
113 * @stats_lock: Lock for flower rule stats updates
114 * @cmsg_work: Workqueue for control messages processing
115 * @cmsg_skbs_high: List of higher priority skbs for control message
117 * @cmsg_skbs_low: List of lower priority skbs for control message
119 * @nfp_mac_off_list: List of MAC addresses to offload
120 * @nfp_mac_index_list: List of unique 8-bit indexes for non NFP netdevs
121 * @nfp_ipv4_off_list: List of IPv4 addresses to offload
122 * @nfp_neigh_off_list: List of neighbour offloads
123 * @nfp_mac_off_lock: Lock for the MAC address list
124 * @nfp_mac_index_lock: Lock for the MAC index list
125 * @nfp_ipv4_off_lock: Lock for the IPv4 address list
126 * @nfp_neigh_off_lock: Lock for the neighbour address list
127 * @nfp_mac_off_ids: IDA to manage id assignment for offloaded macs
128 * @nfp_mac_off_count: Number of MACs in address list
129 * @nfp_tun_mac_nb: Notifier to monitor link state
130 * @nfp_tun_neigh_nb: Notifier to monitor neighbour state
131 * @reify_replies: atomically stores the number of replies received
132 * from firmware for repr reify
133 * @reify_wait_queue: wait queue for repr reify response counting
134 * @mtu_conf: Configuration of repr MTU value
135 * @nfp_lag: Link aggregation data block
137 struct nfp_flower_priv {
142 u64 flower_ext_feats;
143 struct nfp_fl_stats_id stats_ids;
144 struct nfp_fl_mask_id mask_ids;
145 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
147 struct rhashtable flow_table;
148 struct nfp_fl_stats *stats;
149 spinlock_t stats_lock; /* lock stats */
150 struct work_struct cmsg_work;
151 struct sk_buff_head cmsg_skbs_high;
152 struct sk_buff_head cmsg_skbs_low;
153 struct list_head nfp_mac_off_list;
154 struct list_head nfp_mac_index_list;
155 struct list_head nfp_ipv4_off_list;
156 struct list_head nfp_neigh_off_list;
157 struct mutex nfp_mac_off_lock;
158 struct mutex nfp_mac_index_lock;
159 struct mutex nfp_ipv4_off_lock;
160 spinlock_t nfp_neigh_off_lock;
161 struct ida nfp_mac_off_ids;
162 int nfp_mac_off_count;
163 struct notifier_block nfp_tun_mac_nb;
164 struct notifier_block nfp_tun_neigh_nb;
165 atomic_t reify_replies;
166 wait_queue_head_t reify_wait_queue;
167 struct nfp_mtu_conf mtu_conf;
168 struct nfp_fl_lag nfp_lag;
172 * struct nfp_flower_repr_priv - Flower APP per-repr priv data
173 * @lag_port_flags: Extended port flags to record lag state of repr
175 struct nfp_flower_repr_priv {
176 unsigned long lag_port_flags;
179 struct nfp_fl_key_ls {
185 struct nfp_fl_rule_metadata {
191 __be64 host_cookie __packed;
192 __be64 flow_version __packed;
196 struct nfp_fl_stats {
202 struct nfp_fl_payload {
203 struct nfp_fl_rule_metadata meta;
204 unsigned long tc_flower_cookie;
205 struct rhash_head fl_node;
207 __be32 nfp_tun_ipv4_addr;
208 struct net_device *ingress_dev;
212 bool ingress_offload;
215 extern const struct rhashtable_params nfp_flower_table_params;
217 struct nfp_fl_stats_frame {
224 int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count);
225 void nfp_flower_metadata_cleanup(struct nfp_app *app);
227 int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
228 enum tc_setup_type type, void *type_data);
229 int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
230 struct nfp_fl_key_ls *key_ls,
231 struct net_device *netdev,
232 struct nfp_fl_payload *nfp_flow,
233 enum nfp_flower_tun_type tun_type);
234 int nfp_flower_compile_action(struct nfp_app *app,
235 struct tc_cls_flower_offload *flow,
236 struct net_device *netdev,
237 struct nfp_fl_payload *nfp_flow);
238 int nfp_compile_flow_metadata(struct nfp_app *app,
239 struct tc_cls_flower_offload *flow,
240 struct nfp_fl_payload *nfp_flow,
241 struct net_device *netdev);
242 int nfp_modify_flow_metadata(struct nfp_app *app,
243 struct nfp_fl_payload *nfp_flow);
245 struct nfp_fl_payload *
246 nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
247 struct net_device *netdev, __be32 host_ctx);
248 struct nfp_fl_payload *
249 nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
251 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
253 int nfp_tunnel_config_start(struct nfp_app *app);
254 void nfp_tunnel_config_stop(struct nfp_app *app);
255 void nfp_tunnel_write_macs(struct nfp_app *app);
256 void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
257 void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
258 void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
259 void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
260 int nfp_flower_setup_tc_egress_cb(enum tc_setup_type type, void *type_data,
262 void nfp_flower_lag_init(struct nfp_fl_lag *lag);
263 void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
264 int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
265 bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
266 int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
267 struct net_device *master,
268 struct nfp_fl_pre_lag *pre_act);
269 int nfp_flower_lag_get_output_id(struct nfp_app *app,
270 struct net_device *master);