2 * Copyright (C) 2017 Netronome Systems, Inc.
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.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
34 #ifndef __NFP_FLOWER_H__
35 #define __NFP_FLOWER_H__ 1
37 #include <linux/circ_buf.h>
38 #include <linux/hashtable.h>
39 #include <linux/time64.h>
40 #include <linux/types.h>
41 #include <net/pkt_cls.h>
42 #include <linux/workqueue.h>
47 #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)
50 #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
55 #define NFP_FL_META_FLAG_MANAGE_MASK BIT(7)
57 #define NFP_FL_MASK_REUSE_TIME_NS 40000
58 #define NFP_FL_MASK_ID_LOCATION 1
60 struct nfp_fl_mask_id {
61 struct circ_buf mask_id_free_list;
62 struct timespec64 *last_used;
66 struct nfp_fl_stats_id {
67 struct circ_buf free_list;
73 * struct nfp_flower_priv - Flower APP per-vNIC priv data
74 * @app: Back pointer to app
75 * @nn: Pointer to vNIC
76 * @mask_id_seed: Seed used for mask hash table
77 * @flower_version: HW version of flower
78 * @stats_ids: List of free stats ids
79 * @mask_ids: List of free mask ids
80 * @mask_table: Hash table used to store masks
81 * @flow_table: Hash table used to store flower rules
82 * @cmsg_work: Workqueue for control messages processing
83 * @cmsg_skbs: List of skbs for control message processing
85 struct nfp_flower_priv {
90 struct nfp_fl_stats_id stats_ids;
91 struct nfp_fl_mask_id mask_ids;
92 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
93 DECLARE_HASHTABLE(flow_table, NFP_FLOWER_HASH_BITS);
94 struct work_struct cmsg_work;
95 struct sk_buff_head cmsg_skbs;
98 struct nfp_fl_key_ls {
104 struct nfp_fl_rule_metadata {
110 __be64 host_cookie __packed;
111 __be64 flow_version __packed;
115 struct nfp_fl_stats {
121 struct nfp_fl_payload {
122 struct nfp_fl_rule_metadata meta;
123 unsigned long tc_flower_cookie;
124 struct hlist_node link;
126 spinlock_t lock; /* lock stats */
127 struct nfp_fl_stats stats;
133 struct nfp_fl_stats_frame {
140 int nfp_flower_metadata_init(struct nfp_app *app);
141 void nfp_flower_metadata_cleanup(struct nfp_app *app);
143 int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
144 enum tc_setup_type type, void *type_data);
145 int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
146 struct nfp_fl_key_ls *key_ls,
147 struct net_device *netdev,
148 struct nfp_fl_payload *nfp_flow);
149 int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
150 struct net_device *netdev,
151 struct nfp_fl_payload *nfp_flow);
152 int nfp_compile_flow_metadata(struct nfp_app *app,
153 struct tc_cls_flower_offload *flow,
154 struct nfp_fl_payload *nfp_flow);
155 int nfp_modify_flow_metadata(struct nfp_app *app,
156 struct nfp_fl_payload *nfp_flow);
158 struct nfp_fl_payload *
159 nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
160 struct nfp_fl_payload *
161 nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
163 void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);