Commit | Line | Data |
---|---|---|
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 | ||
42 | struct tc_to_netdev; | |
43 | struct net_device; | |
44 | struct nfp_app; | |
45 | ||
43f84b72 PJV |
46 | #define NFP_FLOWER_HASH_BITS 19 |
47 | #define NFP_FLOWER_MASK_ENTRY_RS 256 | |
48 | #define NFP_FLOWER_MASK_ELEMENT_RS 1 | |
49 | #define NFP_FLOWER_MASK_HASH_BITS 10 | |
50 | ||
51 | #define NFP_FL_META_FLAG_NEW_MASK 128 | |
52 | #define NFP_FL_META_FLAG_LAST_MASK 1 | |
53 | ||
54 | #define NFP_FL_MASK_REUSE_TIME_NS 40000 | |
55 | #define NFP_FL_MASK_ID_LOCATION 1 | |
56 | ||
57 | struct nfp_fl_mask_id { | |
58 | struct circ_buf mask_id_free_list; | |
59 | struct timespec64 *last_used; | |
60 | u8 init_unallocated; | |
61 | }; | |
62 | ||
63 | /** | |
64 | * struct nfp_flower_priv - Flower APP per-vNIC priv data | |
65 | * @nn: Pointer to vNIC | |
66 | * @mask_id_seed: Seed used for mask hash table | |
67 | * @flower_version: HW version of flower | |
68 | * @mask_ids: List of free mask ids | |
69 | * @mask_table: Hash table used to store masks | |
70 | * @flow_table: Hash table used to store flower rules | |
71 | */ | |
72 | struct nfp_flower_priv { | |
73 | struct nfp_net *nn; | |
74 | u32 mask_id_seed; | |
75 | u64 flower_version; | |
76 | struct nfp_fl_mask_id mask_ids; | |
77 | DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS); | |
78 | DECLARE_HASHTABLE(flow_table, NFP_FLOWER_HASH_BITS); | |
79 | }; | |
80 | ||
af9d842c PJV |
81 | struct nfp_fl_key_ls { |
82 | u32 key_layer_two; | |
83 | u8 key_layer; | |
84 | int key_size; | |
85 | }; | |
86 | ||
87 | struct nfp_fl_rule_metadata { | |
88 | u8 key_len; | |
89 | u8 mask_len; | |
90 | u8 act_len; | |
91 | u8 flags; | |
92 | __be32 host_ctx_id; | |
93 | __be64 host_cookie __packed; | |
94 | __be64 flow_version __packed; | |
95 | __be32 shortcut; | |
96 | }; | |
97 | ||
98 | struct nfp_fl_payload { | |
99 | struct nfp_fl_rule_metadata meta; | |
43f84b72 PJV |
100 | unsigned long tc_flower_cookie; |
101 | struct hlist_node link; | |
102 | struct rcu_head rcu; | |
af9d842c PJV |
103 | char *unmasked_data; |
104 | char *mask_data; | |
105 | char *action_data; | |
106 | }; | |
107 | ||
43f84b72 PJV |
108 | int nfp_flower_metadata_init(struct nfp_app *app); |
109 | void nfp_flower_metadata_cleanup(struct nfp_app *app); | |
110 | ||
8a276873 PJV |
111 | int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev, |
112 | u32 handle, __be16 proto, struct tc_to_netdev *tc); | |
5571e8c9 PJV |
113 | int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow, |
114 | struct nfp_fl_key_ls *key_ls, | |
115 | struct net_device *netdev, | |
116 | struct nfp_fl_payload *nfp_flow); | |
1a1e586f PJV |
117 | int nfp_flower_compile_action(struct tc_cls_flower_offload *flow, |
118 | struct net_device *netdev, | |
119 | struct nfp_fl_payload *nfp_flow); | |
43f84b72 PJV |
120 | int nfp_compile_flow_metadata(struct nfp_app *app, |
121 | struct tc_cls_flower_offload *flow, | |
122 | struct nfp_fl_payload *nfp_flow); | |
123 | int nfp_modify_flow_metadata(struct nfp_app *app, | |
124 | struct nfp_fl_payload *nfp_flow); | |
125 | ||
126 | struct nfp_fl_payload * | |
127 | nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie); | |
128 | struct nfp_fl_payload * | |
129 | nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie); | |
5571e8c9 | 130 | |
8a276873 | 131 | #endif |