net: sched: change return value of ndo_setup_tc for driver supporting mqprio only
[linux-block.git] / drivers / net / ethernet / netronome / nfp / flower / main.h
CommitLineData
8a276873
PJV
1/*
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
43f84b72
PJV
37#include <linux/circ_buf.h>
38#include <linux/hashtable.h>
39#include <linux/time64.h>
8a276873
PJV
40#include <linux/types.h>
41
42struct tc_to_netdev;
43struct net_device;
44struct nfp_app;
45
abfcdc1d
PJV
46#define NFP_FL_STATS_ENTRY_RS BIT(20)
47#define NFP_FL_STATS_ELEM_RS 4
48#define NFP_FL_REPEATED_HASH_MAX BIT(17)
43f84b72
PJV
49#define NFP_FLOWER_HASH_BITS 19
50#define NFP_FLOWER_MASK_ENTRY_RS 256
51#define NFP_FLOWER_MASK_ELEMENT_RS 1
52#define NFP_FLOWER_MASK_HASH_BITS 10
53
54#define NFP_FL_META_FLAG_NEW_MASK 128
55#define NFP_FL_META_FLAG_LAST_MASK 1
56
57#define NFP_FL_MASK_REUSE_TIME_NS 40000
58#define NFP_FL_MASK_ID_LOCATION 1
59
60struct nfp_fl_mask_id {
61 struct circ_buf mask_id_free_list;
62 struct timespec64 *last_used;
63 u8 init_unallocated;
64};
65
abfcdc1d
PJV
66struct nfp_fl_stats_id {
67 struct circ_buf free_list;
68 u32 init_unalloc;
69 u8 repeated_em_count;
70};
71
43f84b72
PJV
72/**
73 * struct nfp_flower_priv - Flower APP per-vNIC priv data
74 * @nn: Pointer to vNIC
75 * @mask_id_seed: Seed used for mask hash table
76 * @flower_version: HW version of flower
abfcdc1d 77 * @stats_ids: List of free stats ids
43f84b72
PJV
78 * @mask_ids: List of free mask ids
79 * @mask_table: Hash table used to store masks
80 * @flow_table: Hash table used to store flower rules
81 */
82struct nfp_flower_priv {
83 struct nfp_net *nn;
84 u32 mask_id_seed;
85 u64 flower_version;
abfcdc1d 86 struct nfp_fl_stats_id stats_ids;
43f84b72
PJV
87 struct nfp_fl_mask_id mask_ids;
88 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
89 DECLARE_HASHTABLE(flow_table, NFP_FLOWER_HASH_BITS);
90};
91
af9d842c
PJV
92struct nfp_fl_key_ls {
93 u32 key_layer_two;
94 u8 key_layer;
95 int key_size;
96};
97
98struct nfp_fl_rule_metadata {
99 u8 key_len;
100 u8 mask_len;
101 u8 act_len;
102 u8 flags;
103 __be32 host_ctx_id;
104 __be64 host_cookie __packed;
105 __be64 flow_version __packed;
106 __be32 shortcut;
107};
108
abfcdc1d
PJV
109struct nfp_fl_stats {
110 u64 pkts;
111 u64 bytes;
112 u64 used;
113};
114
af9d842c
PJV
115struct nfp_fl_payload {
116 struct nfp_fl_rule_metadata meta;
43f84b72
PJV
117 unsigned long tc_flower_cookie;
118 struct hlist_node link;
119 struct rcu_head rcu;
abfcdc1d
PJV
120 spinlock_t lock; /* lock stats */
121 struct nfp_fl_stats stats;
af9d842c
PJV
122 char *unmasked_data;
123 char *mask_data;
124 char *action_data;
125};
126
abfcdc1d
PJV
127struct nfp_fl_stats_frame {
128 __be32 stats_con_id;
129 __be32 pkt_count;
130 __be64 byte_count;
131 __be64 stats_cookie;
132};
133
43f84b72
PJV
134int nfp_flower_metadata_init(struct nfp_app *app);
135void nfp_flower_metadata_cleanup(struct nfp_app *app);
136
8a276873 137int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
5fd9fc4e 138 enum tc_setup_type type, struct tc_to_netdev *tc);
5571e8c9
PJV
139int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
140 struct nfp_fl_key_ls *key_ls,
141 struct net_device *netdev,
142 struct nfp_fl_payload *nfp_flow);
1a1e586f
PJV
143int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
144 struct net_device *netdev,
145 struct nfp_fl_payload *nfp_flow);
43f84b72
PJV
146int nfp_compile_flow_metadata(struct nfp_app *app,
147 struct tc_cls_flower_offload *flow,
148 struct nfp_fl_payload *nfp_flow);
149int nfp_modify_flow_metadata(struct nfp_app *app,
150 struct nfp_fl_payload *nfp_flow);
151
152struct nfp_fl_payload *
153nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
154struct nfp_fl_payload *
155nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
5571e8c9 156
abfcdc1d
PJV
157void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
158
8a276873 159#endif