1
2
3
4
5#ifndef _ROC_NPC_H_
6#define _ROC_NPC_H_
7
8#include <sys/queue.h>
9
10enum roc_npc_item_type {
11 ROC_NPC_ITEM_TYPE_VOID,
12 ROC_NPC_ITEM_TYPE_ANY,
13 ROC_NPC_ITEM_TYPE_ETH,
14 ROC_NPC_ITEM_TYPE_VLAN,
15 ROC_NPC_ITEM_TYPE_E_TAG,
16 ROC_NPC_ITEM_TYPE_IPV4,
17 ROC_NPC_ITEM_TYPE_IPV6,
18 ROC_NPC_ITEM_TYPE_ARP_ETH_IPV4,
19 ROC_NPC_ITEM_TYPE_MPLS,
20 ROC_NPC_ITEM_TYPE_ICMP,
21 ROC_NPC_ITEM_TYPE_IGMP,
22 ROC_NPC_ITEM_TYPE_UDP,
23 ROC_NPC_ITEM_TYPE_TCP,
24 ROC_NPC_ITEM_TYPE_SCTP,
25 ROC_NPC_ITEM_TYPE_ESP,
26 ROC_NPC_ITEM_TYPE_GRE,
27 ROC_NPC_ITEM_TYPE_NVGRE,
28 ROC_NPC_ITEM_TYPE_VXLAN,
29 ROC_NPC_ITEM_TYPE_GTPC,
30 ROC_NPC_ITEM_TYPE_GTPU,
31 ROC_NPC_ITEM_TYPE_GENEVE,
32 ROC_NPC_ITEM_TYPE_VXLAN_GPE,
33 ROC_NPC_ITEM_TYPE_IPV6_EXT,
34 ROC_NPC_ITEM_TYPE_GRE_KEY,
35 ROC_NPC_ITEM_TYPE_HIGIG2,
36 ROC_NPC_ITEM_TYPE_CPT_HDR,
37 ROC_NPC_ITEM_TYPE_L3_CUSTOM,
38 ROC_NPC_ITEM_TYPE_QINQ,
39 ROC_NPC_ITEM_TYPE_RAW,
40 ROC_NPC_ITEM_TYPE_END,
41};
42
43struct roc_npc_item_info {
44 enum roc_npc_item_type type;
45 uint32_t size;
46 const void *spec;
47 const void *mask;
48 const void *last;
49};
50
51struct roc_npc_flow_item_raw {
52 uint32_t relative : 1;
53 uint32_t search : 1;
54 uint32_t reserved : 30;
55 int32_t offset;
56 uint16_t limit;
57 uint16_t length;
58 const uint8_t *pattern;
59};
60
61#define ROC_NPC_MAX_ACTION_COUNT 19
62
63enum roc_npc_action_type {
64 ROC_NPC_ACTION_TYPE_END = (1 << 0),
65 ROC_NPC_ACTION_TYPE_VOID = (1 << 1),
66 ROC_NPC_ACTION_TYPE_MARK = (1 << 2),
67 ROC_NPC_ACTION_TYPE_FLAG = (1 << 3),
68 ROC_NPC_ACTION_TYPE_DROP = (1 << 4),
69 ROC_NPC_ACTION_TYPE_QUEUE = (1 << 5),
70 ROC_NPC_ACTION_TYPE_RSS = (1 << 6),
71 ROC_NPC_ACTION_TYPE_DUP = (1 << 7),
72 ROC_NPC_ACTION_TYPE_SEC = (1 << 8),
73 ROC_NPC_ACTION_TYPE_COUNT = (1 << 9),
74 ROC_NPC_ACTION_TYPE_PF = (1 << 10),
75 ROC_NPC_ACTION_TYPE_VF = (1 << 11),
76 ROC_NPC_ACTION_TYPE_VLAN_STRIP = (1 << 12),
77 ROC_NPC_ACTION_TYPE_VLAN_INSERT = (1 << 13),
78 ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT = (1 << 14),
79 ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT = (1 << 15),
80 ROC_NPC_ACTION_TYPE_PORT_ID = (1 << 16),
81 ROC_NPC_ACTION_TYPE_METER = (1 << 17),
82};
83
84struct roc_npc_action {
85 enum roc_npc_action_type type;
86 const void *conf;
87};
88
89struct roc_npc_action_mark {
90 uint32_t id;
91};
92
93struct roc_npc_action_vf {
94 uint32_t original : 1;
95 uint32_t reserved : 31;
96 uint32_t id;
97};
98
99struct roc_npc_action_port_id {
100 uint32_t original : 1;
101 uint32_t reserved : 31;
102 uint32_t id;
103};
104
105struct roc_npc_action_queue {
106 uint16_t index;
107};
108
109struct roc_npc_action_of_push_vlan {
110 uint16_t ethertype;
111};
112
113struct roc_npc_action_of_set_vlan_vid {
114 uint16_t vlan_vid;
115};
116
117struct roc_npc_action_of_set_vlan_pcp {
118 uint8_t vlan_pcp;
119};
120
121struct roc_npc_action_meter {
122 uint32_t mtr_id;
123};
124
125struct roc_npc_attr {
126 uint32_t priority;
127 uint32_t ingress : 1;
128 uint32_t egress : 1;
129 uint32_t reserved : 30;
130};
131
132struct roc_npc_flow_dump_data {
133 uint8_t lid;
134 uint16_t ltype;
135};
136
137struct roc_npc_flow {
138 uint8_t nix_intf;
139 uint8_t enable;
140 uint32_t mcam_id;
141 int32_t ctr_id;
142 uint32_t priority;
143 uint32_t mtr_id;
144#define ROC_NPC_MAX_MCAM_WIDTH_DWORDS 7
145
146 uint64_t mcam_data[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
147 uint64_t mcam_mask[ROC_NPC_MAX_MCAM_WIDTH_DWORDS];
148 uint64_t npc_action;
149 uint64_t vtag_action;
150 bool vtag_insert_enabled;
151 uint8_t vtag_insert_count;
152#define ROC_NPC_MAX_FLOW_PATTERNS 32
153 struct roc_npc_flow_dump_data dump_data[ROC_NPC_MAX_FLOW_PATTERNS];
154 uint16_t num_patterns;
155
156 TAILQ_ENTRY(roc_npc_flow) next;
157};
158
159enum roc_npc_rss_hash_function {
160 ROC_NPC_RSS_HASH_FUNCTION_DEFAULT = 0,
161 ROC_NPC_RSS_HASH_FUNCTION_TOEPLITZ,
162 ROC_NPC_RSS_HASH_FUNCTION_SIMPLE_XOR,
163 ROC_NPC_RSS_HASH_FUNCTION_SYMMETRIC_TOEPLITZ,
164 ROC_NPC_RSS_HASH_FUNCTION_MAX,
165};
166
167struct roc_npc_action_rss {
168 enum roc_npc_rss_hash_function func;
169 uint32_t level;
170 uint64_t types;
171 uint32_t key_len;
172 uint32_t queue_num;
173 const uint8_t *key;
174 const uint16_t *queue;
175};
176
177enum roc_npc_intf {
178 ROC_NPC_INTF_RX = 0,
179 ROC_NPC_INTF_TX = 1,
180 ROC_NPC_INTF_MAX = 2,
181};
182
183enum flow_vtag_cfg_dir { VTAG_TX, VTAG_RX };
184#define ROC_ETHER_TYPE_VLAN 0x8100
185#define ROC_ETHER_TYPE_QINQ 0x88A8
186
187struct roc_npc {
188 struct roc_nix *roc_nix;
189 uint8_t switch_header_type;
190 uint16_t flow_prealloc_size;
191 uint16_t flow_max_priority;
192 uint16_t channel;
193 uint16_t pf_func;
194 uint64_t kex_capability;
195 uint64_t rx_parse_nibble;
196
197 uint32_t flowkey_cfg_state;
198
199#define ROC_NPC_MEM_SZ (5 * 1024)
200 uint8_t reserved[ROC_NPC_MEM_SZ];
201} __plt_cache_aligned;
202
203int __roc_api roc_npc_init(struct roc_npc *roc_npc);
204int __roc_api roc_npc_fini(struct roc_npc *roc_npc);
205const char *__roc_api roc_npc_profile_name_get(struct roc_npc *roc_npc);
206
207struct roc_npc_flow *__roc_api
208roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
209 const struct roc_npc_item_info pattern[],
210 const struct roc_npc_action actions[], int *errcode);
211int __roc_api roc_npc_flow_destroy(struct roc_npc *roc_npc,
212 struct roc_npc_flow *flow);
213int __roc_api roc_npc_mcam_free_entry(struct roc_npc *roc_npc, uint32_t entry);
214int __roc_api roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc,
215 struct roc_npc_flow *mcam,
216 struct roc_npc_flow *ref_mcam, int prio,
217 int *resp_count);
218int __roc_api roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
219 int *alloc_entry, int req_count,
220 int priority, int *resp_count);
221int __roc_api roc_npc_mcam_ena_dis_entry(struct roc_npc *roc_npc,
222 struct roc_npc_flow *mcam,
223 bool enable);
224int __roc_api roc_npc_mcam_write_entry(struct roc_npc *roc_npc,
225 struct roc_npc_flow *mcam);
226int __roc_api roc_npc_flow_parse(struct roc_npc *roc_npc,
227 const struct roc_npc_attr *attr,
228 const struct roc_npc_item_info pattern[],
229 const struct roc_npc_action actions[],
230 struct roc_npc_flow *flow);
231int __roc_api roc_npc_get_low_priority_mcam(struct roc_npc *roc_npc);
232int __roc_api roc_npc_mcam_free_counter(struct roc_npc *roc_npc,
233 uint16_t ctr_id);
234int __roc_api roc_npc_mcam_read_counter(struct roc_npc *roc_npc,
235 uint32_t ctr_id, uint64_t *count);
236int __roc_api roc_npc_mcam_clear_counter(struct roc_npc *roc_npc,
237 uint32_t ctr_id);
238int __roc_api roc_npc_mcam_free_all_resources(struct roc_npc *roc_npc);
239void __roc_api roc_npc_flow_dump(FILE *file, struct roc_npc *roc_npc);
240void __roc_api roc_npc_flow_mcam_dump(FILE *file, struct roc_npc *roc_npc,
241 struct roc_npc_flow *mcam);
242int __roc_api roc_npc_mark_actions_get(struct roc_npc *roc_npc);
243int __roc_api roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc,
244 uint32_t count);
245int __roc_api roc_npc_vtag_actions_get(struct roc_npc *roc_npc);
246int __roc_api roc_npc_vtag_actions_sub_return(struct roc_npc *roc_npc,
247 uint32_t count);
248int __roc_api roc_npc_mcam_merge_base_steering_rule(struct roc_npc *roc_npc,
249 struct roc_npc_flow *flow);
250int __roc_api roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
251 struct roc_npc *roc_npc_dst);
252#endif
253