main.h 7.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*
 * Copyright (C) 2017 Netronome Systems, Inc.
 *
 * This software is dual licensed under the GNU General License Version 2,
 * June 1991 as shown in the file COPYING in the top-level directory of this
 * source tree or the BSD 2-Clause License provided below.  You have the
 * option to license this software under the complete terms of either license.
 *
 * The BSD 2-Clause License:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      1. Redistributions of source code must retain the above
 *         copyright notice, this list of conditions and the following
 *         disclaimer.
 *
 *      2. Redistributions in binary form must reproduce the above
 *         copyright notice, this list of conditions and the following
 *         disclaimer in the documentation and/or other materials
 *         provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __NFP_FLOWER_H__
#define __NFP_FLOWER_H__ 1

37 38
#include "cmsg.h"

39 40 41
#include <linux/circ_buf.h>
#include <linux/hashtable.h>
#include <linux/time64.h>
42
#include <linux/types.h>
43
#include <net/pkt_cls.h>
44
#include <net/tcp.h>
45
#include <linux/workqueue.h>
46 47 48 49

struct net_device;
struct nfp_app;

50 51 52
#define NFP_FL_STATS_ENTRY_RS		BIT(20)
#define NFP_FL_STATS_ELEM_RS		4
#define NFP_FL_REPEATED_HASH_MAX	BIT(17)
53 54 55 56 57
#define NFP_FLOWER_HASH_BITS		19
#define NFP_FLOWER_MASK_ENTRY_RS	256
#define NFP_FLOWER_MASK_ELEMENT_RS	1
#define NFP_FLOWER_MASK_HASH_BITS	10

58
#define NFP_FL_META_FLAG_MANAGE_MASK	BIT(7)
59 60 61 62

#define NFP_FL_MASK_REUSE_TIME_NS	40000
#define NFP_FL_MASK_ID_LOCATION		1

63
#define NFP_FL_VXLAN_PORT		4789
64 65 66 67
#define NFP_FL_GENEVE_PORT		6081

/* Extra features bitmap. */
#define NFP_FL_FEATS_GENEVE		BIT(0)
68
#define NFP_FL_NBI_MTU_SETTING		BIT(1)
69

70 71 72 73 74 75
struct nfp_fl_mask_id {
	struct circ_buf mask_id_free_list;
	struct timespec64 *last_used;
	u8 init_unallocated;
};

76 77 78 79 80 81
struct nfp_fl_stats_id {
	struct circ_buf free_list;
	u32 init_unalloc;
	u8 repeated_em_count;
};

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/**
 * struct nfp_mtu_conf - manage MTU setting
 * @portnum:		NFP port number of repr with requested MTU change
 * @requested_val:	MTU value requested for repr
 * @ack:		Received ack that MTU has been correctly set
 * @wait_q:		Wait queue for MTU acknowledgements
 * @lock:		Lock for setting/reading MTU variables
 */
struct nfp_mtu_conf {
	u32 portnum;
	unsigned int requested_val;
	bool ack;
	wait_queue_head_t wait_q;
	spinlock_t lock;
};

98 99
/**
 * struct nfp_flower_priv - Flower APP per-vNIC priv data
100
 * @app:		Back pointer to app
101 102 103
 * @nn:			Pointer to vNIC
 * @mask_id_seed:	Seed used for mask hash table
 * @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 107 108
 * @mask_ids:		List of free mask ids
 * @mask_table:		Hash table used to store masks
 * @flow_table:		Hash table used to store flower rules
109
 * @cmsg_work:		Workqueue for control messages processing
110 111 112 113
 * @cmsg_skbs_high:	List of higher priority skbs for control message
 *			processing
 * @cmsg_skbs_low:	List of lower priority skbs for control message
 *			processing
114 115
 * @nfp_mac_off_list:	List of MAC addresses to offload
 * @nfp_mac_index_list:	List of unique 8-bit indexes for non NFP netdevs
116
 * @nfp_ipv4_off_list:	List of IPv4 addresses to offload
117
 * @nfp_neigh_off_list:	List of neighbour offloads
118 119
 * @nfp_mac_off_lock:	Lock for the MAC address list
 * @nfp_mac_index_lock:	Lock for the MAC index list
120
 * @nfp_ipv4_off_lock:	Lock for the IPv4 address list
121
 * @nfp_neigh_off_lock:	Lock for the neighbour address list
122 123 124
 * @nfp_mac_off_ids:	IDA to manage id assignment for offloaded macs
 * @nfp_mac_off_count:	Number of MACs in address list
 * @nfp_tun_mac_nb:	Notifier to monitor link state
125
 * @nfp_tun_neigh_nb:	Notifier to monitor neighbour state
126 127 128
 * @reify_replies:	atomically stores the number of replies received
 *			from firmware for repr reify
 * @reify_wait_queue:	wait queue for repr reify response counting
129
 * @mtu_conf:		Configuration of repr MTU value
130 131
 */
struct nfp_flower_priv {
132
	struct nfp_app *app;
133 134 135
	struct nfp_net *nn;
	u32 mask_id_seed;
	u64 flower_version;
136
	u64 flower_ext_feats;
137
	struct nfp_fl_stats_id stats_ids;
138 139 140
	struct nfp_fl_mask_id mask_ids;
	DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
	DECLARE_HASHTABLE(flow_table, NFP_FLOWER_HASH_BITS);
141
	struct work_struct cmsg_work;
142 143
	struct sk_buff_head cmsg_skbs_high;
	struct sk_buff_head cmsg_skbs_low;
144 145
	struct list_head nfp_mac_off_list;
	struct list_head nfp_mac_index_list;
146
	struct list_head nfp_ipv4_off_list;
147
	struct list_head nfp_neigh_off_list;
148 149
	struct mutex nfp_mac_off_lock;
	struct mutex nfp_mac_index_lock;
150
	struct mutex nfp_ipv4_off_lock;
151
	spinlock_t nfp_neigh_off_lock;
152 153 154
	struct ida nfp_mac_off_ids;
	int nfp_mac_off_count;
	struct notifier_block nfp_tun_mac_nb;
155
	struct notifier_block nfp_tun_neigh_nb;
156 157
	atomic_t reify_replies;
	wait_queue_head_t reify_wait_queue;
158
	struct nfp_mtu_conf mtu_conf;
159 160
};

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
struct nfp_fl_key_ls {
	u32 key_layer_two;
	u8 key_layer;
	int key_size;
};

struct nfp_fl_rule_metadata {
	u8 key_len;
	u8 mask_len;
	u8 act_len;
	u8 flags;
	__be32 host_ctx_id;
	__be64 host_cookie __packed;
	__be64 flow_version __packed;
	__be32 shortcut;
};

178 179 180 181 182 183
struct nfp_fl_stats {
	u64 pkts;
	u64 bytes;
	u64 used;
};

184 185
struct nfp_fl_payload {
	struct nfp_fl_rule_metadata meta;
186 187 188
	unsigned long tc_flower_cookie;
	struct hlist_node link;
	struct rcu_head rcu;
189 190
	spinlock_t lock; /* lock stats */
	struct nfp_fl_stats stats;
191
	__be32 nfp_tun_ipv4_addr;
192 193 194 195 196
	char *unmasked_data;
	char *mask_data;
	char *action_data;
};

197 198 199 200 201 202 203
struct nfp_fl_stats_frame {
	__be32 stats_con_id;
	__be32 pkt_count;
	__be64 byte_count;
	__be64 stats_cookie;
};

204 205 206
int nfp_flower_metadata_init(struct nfp_app *app);
void nfp_flower_metadata_cleanup(struct nfp_app *app);

207
int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
208
			enum tc_setup_type type, void *type_data);
209 210 211
int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
				  struct nfp_fl_key_ls *key_ls,
				  struct net_device *netdev,
212 213
				  struct nfp_fl_payload *nfp_flow,
				  enum nfp_flower_tun_type tun_type);
214 215 216
int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
			      struct net_device *netdev,
			      struct nfp_fl_payload *nfp_flow);
217 218 219 220 221 222 223 224 225 226
int nfp_compile_flow_metadata(struct nfp_app *app,
			      struct tc_cls_flower_offload *flow,
			      struct nfp_fl_payload *nfp_flow);
int nfp_modify_flow_metadata(struct nfp_app *app,
			     struct nfp_fl_payload *nfp_flow);

struct nfp_fl_payload *
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
struct nfp_fl_payload *
nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
227

228 229
void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);

230 231 232
int nfp_tunnel_config_start(struct nfp_app *app);
void nfp_tunnel_config_stop(struct nfp_app *app);
void nfp_tunnel_write_macs(struct nfp_app *app);
233 234
void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
235
void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
236
void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
237 238
int nfp_flower_setup_tc_egress_cb(enum tc_setup_type type, void *type_data,
				  void *cb_priv);
239

240
#endif