Merge tag 'cramfs_fixes' of git://git.linaro.org/people/nicolas.pitre/linux
[linux-2.6-microblaze.git] / drivers / net / ethernet / netronome / nfp / flower / main.h
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
3
4 #ifndef __NFP_FLOWER_H__
5 #define __NFP_FLOWER_H__ 1
6
7 #include "cmsg.h"
8
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>
15 #include <net/tcp.h>
16 #include <linux/workqueue.h>
17 #include <linux/idr.h>
18
19 struct nfp_fl_pre_lag;
20 struct net_device;
21 struct nfp_app;
22
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, \
25                                                      init_unalloc)
26 #define NFP_FLOWER_MASK_ENTRY_RS        256
27 #define NFP_FLOWER_MASK_ELEMENT_RS      1
28 #define NFP_FLOWER_MASK_HASH_BITS       10
29
30 #define NFP_FL_META_FLAG_MANAGE_MASK    BIT(7)
31
32 #define NFP_FL_MASK_REUSE_TIME_NS       40000
33 #define NFP_FL_MASK_ID_LOCATION         1
34
35 #define NFP_FL_VXLAN_PORT               4789
36 #define NFP_FL_GENEVE_PORT              6081
37
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)
44
45 struct nfp_fl_mask_id {
46         struct circ_buf mask_id_free_list;
47         ktime_t *last_used;
48         u8 init_unallocated;
49 };
50
51 struct nfp_fl_stats_id {
52         struct circ_buf free_list;
53         u32 init_unalloc;
54         u8 repeated_em_count;
55 };
56
57 /**
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
64  */
65 struct nfp_mtu_conf {
66         u32 portnum;
67         unsigned int requested_val;
68         bool ack;
69         wait_queue_head_t wait_q;
70         spinlock_t lock;
71 };
72
73 /**
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
85  *                      retransmission
86  */
87 struct nfp_fl_lag {
88         struct notifier_block lag_nb;
89         struct delayed_work work;
90         struct mutex lock;
91         struct list_head group_list;
92         struct ida ida_handle;
93         unsigned int pkt_num;
94         unsigned int batch_ver;
95         u8 global_inst;
96         bool rst_cfg;
97         struct sk_buff_head retrans_skbs;
98 };
99
100 /**
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
116  *                      processing
117  * @cmsg_skbs_low:      List of lower priority skbs for control message
118  *                      processing
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
136  */
137 struct nfp_flower_priv {
138         struct nfp_app *app;
139         struct nfp_net *nn;
140         u32 mask_id_seed;
141         u64 flower_version;
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);
146         u32 stats_ring_size;
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;
169 };
170
171 /**
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
174  */
175 struct nfp_flower_repr_priv {
176         unsigned long lag_port_flags;
177 };
178
179 struct nfp_fl_key_ls {
180         u32 key_layer_two;
181         u8 key_layer;
182         int key_size;
183 };
184
185 struct nfp_fl_rule_metadata {
186         u8 key_len;
187         u8 mask_len;
188         u8 act_len;
189         u8 flags;
190         __be32 host_ctx_id;
191         __be64 host_cookie __packed;
192         __be64 flow_version __packed;
193         __be32 shortcut;
194 };
195
196 struct nfp_fl_stats {
197         u64 pkts;
198         u64 bytes;
199         u64 used;
200 };
201
202 struct nfp_fl_payload {
203         struct nfp_fl_rule_metadata meta;
204         unsigned long tc_flower_cookie;
205         struct rhash_head fl_node;
206         struct rcu_head rcu;
207         __be32 nfp_tun_ipv4_addr;
208         struct net_device *ingress_dev;
209         char *unmasked_data;
210         char *mask_data;
211         char *action_data;
212         bool ingress_offload;
213 };
214
215 extern const struct rhashtable_params nfp_flower_table_params;
216
217 struct nfp_fl_stats_frame {
218         __be32 stats_con_id;
219         __be32 pkt_count;
220         __be64 byte_count;
221         __be64 stats_cookie;
222 };
223
224 int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count);
225 void nfp_flower_metadata_cleanup(struct nfp_app *app);
226
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);
244
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);
250
251 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
252
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,
261                                   void *cb_priv);
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);
271
272 #endif