blob: a69ea62e9c9c3a8f198409ad52eefdea3a730db1 [file] [log] [blame]
Pieter Jansen van Vuuren8a276872017-06-29 22:08:13 +02001/*
2 * Copyright (C) 2017 Netronome Systems, Inc.
3 *
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
8 *
9 * The BSD 2-Clause License:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#ifndef __NFP_FLOWER_H__
35#define __NFP_FLOWER_H__ 1
36
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020037#include <linux/circ_buf.h>
38#include <linux/hashtable.h>
39#include <linux/time64.h>
Pieter Jansen van Vuuren8a276872017-06-29 22:08:13 +020040#include <linux/types.h>
Jiri Pirkode4784c2017-08-07 10:15:32 +020041#include <net/pkt_cls.h>
Simon Hormanb985f872017-08-16 09:37:43 +020042#include <linux/workqueue.h>
Pieter Jansen van Vuuren8a276872017-06-29 22:08:13 +020043
Pieter Jansen van Vuuren8a276872017-06-29 22:08:13 +020044struct net_device;
45struct nfp_app;
46
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +020047#define NFP_FL_STATS_ENTRY_RS BIT(20)
48#define NFP_FL_STATS_ELEM_RS 4
49#define NFP_FL_REPEATED_HASH_MAX BIT(17)
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020050#define NFP_FLOWER_HASH_BITS 19
51#define NFP_FLOWER_MASK_ENTRY_RS 256
52#define NFP_FLOWER_MASK_ELEMENT_RS 1
53#define NFP_FLOWER_MASK_HASH_BITS 10
54
Pieter Jansen van Vuuren6c3ab202017-11-16 17:06:39 -080055#define NFP_FL_META_FLAG_MANAGE_MASK BIT(7)
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020056
57#define NFP_FL_MASK_REUSE_TIME_NS 40000
58#define NFP_FL_MASK_ID_LOCATION 1
59
John Hurley611aec12017-09-25 12:23:36 +020060#define NFP_FL_VXLAN_PORT 4789
61
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020062struct nfp_fl_mask_id {
63 struct circ_buf mask_id_free_list;
64 struct timespec64 *last_used;
65 u8 init_unallocated;
66};
67
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +020068struct nfp_fl_stats_id {
69 struct circ_buf free_list;
70 u32 init_unalloc;
71 u8 repeated_em_count;
72};
73
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020074/**
75 * struct nfp_flower_priv - Flower APP per-vNIC priv data
Jakub Kicinskic4962912017-09-02 18:26:00 -070076 * @app: Back pointer to app
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020077 * @nn: Pointer to vNIC
78 * @mask_id_seed: Seed used for mask hash table
79 * @flower_version: HW version of flower
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +020080 * @stats_ids: List of free stats ids
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020081 * @mask_ids: List of free mask ids
82 * @mask_table: Hash table used to store masks
83 * @flow_table: Hash table used to store flower rules
Simon Hormanb985f872017-08-16 09:37:43 +020084 * @cmsg_work: Workqueue for control messages processing
85 * @cmsg_skbs: List of skbs for control message processing
John Hurleyfd0dd1a2017-09-25 12:23:38 +020086 * @nfp_mac_off_list: List of MAC addresses to offload
87 * @nfp_mac_index_list: List of unique 8-bit indexes for non NFP netdevs
John Hurley2d9ad712017-09-25 12:23:39 +020088 * @nfp_ipv4_off_list: List of IPv4 addresses to offload
John Hurley8e6a9042017-09-25 12:23:40 +020089 * @nfp_neigh_off_list: List of neighbour offloads
John Hurleyfd0dd1a2017-09-25 12:23:38 +020090 * @nfp_mac_off_lock: Lock for the MAC address list
91 * @nfp_mac_index_lock: Lock for the MAC index list
John Hurley2d9ad712017-09-25 12:23:39 +020092 * @nfp_ipv4_off_lock: Lock for the IPv4 address list
John Hurley8e6a9042017-09-25 12:23:40 +020093 * @nfp_neigh_off_lock: Lock for the neighbour address list
John Hurleyfd0dd1a2017-09-25 12:23:38 +020094 * @nfp_mac_off_ids: IDA to manage id assignment for offloaded macs
95 * @nfp_mac_off_count: Number of MACs in address list
96 * @nfp_tun_mac_nb: Notifier to monitor link state
John Hurley8e6a9042017-09-25 12:23:40 +020097 * @nfp_tun_neigh_nb: Notifier to monitor neighbour state
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +020098 */
99struct nfp_flower_priv {
Jakub Kicinskic4962912017-09-02 18:26:00 -0700100 struct nfp_app *app;
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +0200101 struct nfp_net *nn;
102 u32 mask_id_seed;
103 u64 flower_version;
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +0200104 struct nfp_fl_stats_id stats_ids;
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +0200105 struct nfp_fl_mask_id mask_ids;
106 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
107 DECLARE_HASHTABLE(flow_table, NFP_FLOWER_HASH_BITS);
Simon Hormanb985f872017-08-16 09:37:43 +0200108 struct work_struct cmsg_work;
109 struct sk_buff_head cmsg_skbs;
John Hurleyfd0dd1a2017-09-25 12:23:38 +0200110 struct list_head nfp_mac_off_list;
111 struct list_head nfp_mac_index_list;
John Hurley2d9ad712017-09-25 12:23:39 +0200112 struct list_head nfp_ipv4_off_list;
John Hurley8e6a9042017-09-25 12:23:40 +0200113 struct list_head nfp_neigh_off_list;
John Hurleyfd0dd1a2017-09-25 12:23:38 +0200114 struct mutex nfp_mac_off_lock;
115 struct mutex nfp_mac_index_lock;
John Hurley2d9ad712017-09-25 12:23:39 +0200116 struct mutex nfp_ipv4_off_lock;
John Hurleydc4646a2017-11-02 01:31:30 -0700117 spinlock_t nfp_neigh_off_lock;
John Hurleyfd0dd1a2017-09-25 12:23:38 +0200118 struct ida nfp_mac_off_ids;
119 int nfp_mac_off_count;
120 struct notifier_block nfp_tun_mac_nb;
John Hurley8e6a9042017-09-25 12:23:40 +0200121 struct notifier_block nfp_tun_neigh_nb;
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +0200122};
123
Pieter Jansen van Vuurenaf9d8422017-06-29 22:08:14 +0200124struct nfp_fl_key_ls {
125 u32 key_layer_two;
126 u8 key_layer;
127 int key_size;
128};
129
130struct nfp_fl_rule_metadata {
131 u8 key_len;
132 u8 mask_len;
133 u8 act_len;
134 u8 flags;
135 __be32 host_ctx_id;
136 __be64 host_cookie __packed;
137 __be64 flow_version __packed;
138 __be32 shortcut;
139};
140
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +0200141struct nfp_fl_stats {
142 u64 pkts;
143 u64 bytes;
144 u64 used;
145};
146
Pieter Jansen van Vuurenaf9d8422017-06-29 22:08:14 +0200147struct nfp_fl_payload {
148 struct nfp_fl_rule_metadata meta;
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +0200149 unsigned long tc_flower_cookie;
150 struct hlist_node link;
151 struct rcu_head rcu;
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +0200152 spinlock_t lock; /* lock stats */
153 struct nfp_fl_stats stats;
John Hurley2d9ad712017-09-25 12:23:39 +0200154 __be32 nfp_tun_ipv4_addr;
Pieter Jansen van Vuurenaf9d8422017-06-29 22:08:14 +0200155 char *unmasked_data;
156 char *mask_data;
157 char *action_data;
158};
159
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +0200160struct nfp_fl_stats_frame {
161 __be32 stats_con_id;
162 __be32 pkt_count;
163 __be64 byte_count;
164 __be64 stats_cookie;
165};
166
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +0200167int nfp_flower_metadata_init(struct nfp_app *app);
168void nfp_flower_metadata_cleanup(struct nfp_app *app);
169
Pieter Jansen van Vuuren8a276872017-06-29 22:08:13 +0200170int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
Jiri Pirkode4784c2017-08-07 10:15:32 +0200171 enum tc_setup_type type, void *type_data);
Pieter Jansen van Vuuren5571e8c2017-06-29 22:08:15 +0200172int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
173 struct nfp_fl_key_ls *key_ls,
174 struct net_device *netdev,
175 struct nfp_fl_payload *nfp_flow);
Pieter Jansen van Vuuren1a1e5862017-06-29 22:08:16 +0200176int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
177 struct net_device *netdev,
178 struct nfp_fl_payload *nfp_flow);
Pieter Jansen van Vuuren43f84b72017-06-29 22:08:17 +0200179int nfp_compile_flow_metadata(struct nfp_app *app,
180 struct tc_cls_flower_offload *flow,
181 struct nfp_fl_payload *nfp_flow);
182int nfp_modify_flow_metadata(struct nfp_app *app,
183 struct nfp_fl_payload *nfp_flow);
184
185struct nfp_fl_payload *
186nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
187struct nfp_fl_payload *
188nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
Pieter Jansen van Vuuren5571e8c2017-06-29 22:08:15 +0200189
Pieter Jansen van Vuurenabfcdc12017-06-29 22:08:18 +0200190void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
191
John Hurleyfd0dd1a2017-09-25 12:23:38 +0200192int nfp_tunnel_config_start(struct nfp_app *app);
193void nfp_tunnel_config_stop(struct nfp_app *app);
194void nfp_tunnel_write_macs(struct nfp_app *app);
John Hurley2d9ad712017-09-25 12:23:39 +0200195void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
196void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
John Hurley8e6a9042017-09-25 12:23:40 +0200197void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
John Hurley856f5b12017-09-25 12:23:41 +0200198void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
John Hurleyfd0dd1a2017-09-25 12:23:38 +0200199
Pieter Jansen van Vuuren8a276872017-06-29 22:08:13 +0200200#endif