1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017-2020 NXP
11 #include <dpaa_ethdev.h>
12 #include <dpaa_flow.h>
13 #include <rte_dpaa_logs.h>
14 #include <fmlib/fm_port_ext.h>
15 #include <fmlib/fm_vsp_ext.h>
17 #define FMC_OUTPUT_FORMAT_VER 0x106
19 #define FMC_NAME_LEN 64
20 #define FMC_FMAN_NUM 2
21 #define FMC_PORTS_PER_FMAN 16
22 #define FMC_SCHEMES_NUM 32
23 #define FMC_SCHEME_PROTOCOLS_NUM 16
24 #define FMC_CC_NODES_NUM 512
25 #define FMC_REPLICATORS_NUM 16
26 #define FMC_PLC_NUM 64
27 #define MAX_SP_CODE_SIZE 0x7C0
28 #define FMC_MANIP_MAX 64
29 #define FMC_HMANIP_MAX 512
30 #define FMC_INSERT_MAX 56
31 #define FM_PCD_MAX_REPS 64
33 typedef struct fmc_port_t {
36 struct fm_pcd_net_env_params_t distinction_units;
37 struct ioc_fm_port_pcd_params_t pcd_param;
38 struct ioc_fm_port_pcd_prs_params_t prs_param;
39 struct ioc_fm_port_pcd_kg_params_t kg_param;
40 struct ioc_fm_port_pcd_cc_params_t cc_param;
41 char name[FMC_NAME_LEN];
42 char cctree_name[FMC_NAME_LEN];
44 t_handle env_id_handle;
45 t_handle env_id_dev_id;
46 t_handle cctree_handle;
47 t_handle cctree_dev_id;
49 unsigned int schemes_count;
50 unsigned int schemes[FMC_SCHEMES_NUM];
51 unsigned int ccnodes_count;
52 unsigned int ccnodes[FMC_CC_NODES_NUM];
53 unsigned int htnodes_count;
54 unsigned int htnodes[FMC_CC_NODES_NUM];
56 unsigned int replicators_count;
57 unsigned int replicators[FMC_REPLICATORS_NUM];
58 ioc_fm_port_vsp_alloc_params_t vsp_param;
60 unsigned int ccroot_count;
61 unsigned int ccroot[FMC_CC_NODES_NUM];
62 enum ioc_fm_pcd_engine ccroot_type[FMC_CC_NODES_NUM];
63 unsigned int ccroot_manip[FMC_CC_NODES_NUM];
65 unsigned int reasm_index;
68 typedef struct fmc_fman_t {
70 unsigned int port_count;
71 unsigned int ports[FMC_PORTS_PER_FMAN];
72 char name[FMC_NAME_LEN];
74 char pcd_name[FMC_NAME_LEN];
76 unsigned int kg_payload_offset;
78 unsigned int offload_support;
80 unsigned int reasm_count;
81 struct fm_pcd_manip_params_t reasm[FMC_MANIP_MAX];
82 char reasm_name[FMC_MANIP_MAX][FMC_NAME_LEN];
83 t_handle reasm_handle[FMC_MANIP_MAX];
84 t_handle reasm_dev_id[FMC_MANIP_MAX];
86 unsigned int frag_count;
87 struct fm_pcd_manip_params_t frag[FMC_MANIP_MAX];
88 char frag_name[FMC_MANIP_MAX][FMC_NAME_LEN];
89 t_handle frag_handle[FMC_MANIP_MAX];
90 t_handle frag_dev_id[FMC_MANIP_MAX];
92 unsigned int hdr_count;
93 struct fm_pcd_manip_params_t hdr[FMC_HMANIP_MAX];
94 uint8_t insert_data[FMC_HMANIP_MAX][FMC_INSERT_MAX];
95 char hdr_name[FMC_HMANIP_MAX][FMC_NAME_LEN];
96 t_handle hdr_handle[FMC_HMANIP_MAX];
97 t_handle hdr_dev_id[FMC_HMANIP_MAX];
98 unsigned int hdr_has_next[FMC_HMANIP_MAX];
99 unsigned int hdr_next[FMC_HMANIP_MAX];
102 typedef enum fmc_apply_order_e {
116 typedef struct fmc_apply_order_t {
117 fmc_apply_order_e type;
122 unsigned int format_version;
123 unsigned int sp_enable;
124 t_fm_pcd_prs_sw_params sp;
125 uint8_t spcode[MAX_SP_CODE_SIZE];
127 unsigned int fman_count;
128 fmc_fman fman[FMC_FMAN_NUM];
130 unsigned int port_count;
131 fmc_port port[FMC_FMAN_NUM * FMC_PORTS_PER_FMAN];
133 unsigned int scheme_count;
134 char scheme_name[FMC_SCHEMES_NUM][FMC_NAME_LEN];
135 t_handle scheme_handle[FMC_SCHEMES_NUM];
136 t_handle scheme_dev_id[FMC_SCHEMES_NUM];
137 struct fm_pcd_kg_scheme_params_t scheme[FMC_SCHEMES_NUM];
139 unsigned int ccnode_count;
140 char ccnode_name[FMC_CC_NODES_NUM][FMC_NAME_LEN];
141 t_handle ccnode_handle[FMC_CC_NODES_NUM];
142 t_handle ccnode_dev_id[FMC_CC_NODES_NUM];
143 struct fm_pcd_cc_node_params_t ccnode[FMC_CC_NODES_NUM];
144 uint8_t cckeydata[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS]
145 [FM_PCD_MAX_SIZE_OF_KEY];
146 unsigned char ccmask[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS]
147 [FM_PCD_MAX_SIZE_OF_KEY];
149 ccentry_action_index[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
150 enum ioc_fm_pcd_engine
151 ccentry_action_type[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
152 unsigned char ccentry_frag[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
153 unsigned int ccentry_manip[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
154 unsigned int ccmiss_action_index[FMC_CC_NODES_NUM];
155 enum ioc_fm_pcd_engine ccmiss_action_type[FMC_CC_NODES_NUM];
156 unsigned char ccmiss_frag[FMC_CC_NODES_NUM];
157 unsigned int ccmiss_manip[FMC_CC_NODES_NUM];
159 unsigned int htnode_count;
160 char htnode_name[FMC_CC_NODES_NUM][FMC_NAME_LEN];
161 t_handle htnode_handle[FMC_CC_NODES_NUM];
162 t_handle htnode_dev_id[FMC_CC_NODES_NUM];
163 struct fm_pcd_hash_table_params_t htnode[FMC_CC_NODES_NUM];
165 unsigned int htentry_count[FMC_CC_NODES_NUM];
166 struct ioc_fm_pcd_cc_key_params_t
167 htentry[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
168 uint8_t htkeydata[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS]
169 [FM_PCD_MAX_SIZE_OF_KEY];
171 htentry_action_index[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
172 enum ioc_fm_pcd_engine
173 htentry_action_type[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
174 unsigned char htentry_frag[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
175 unsigned int htentry_manip[FMC_CC_NODES_NUM][FM_PCD_MAX_NUM_OF_KEYS];
177 unsigned int htmiss_action_index[FMC_CC_NODES_NUM];
178 enum ioc_fm_pcd_engine htmiss_action_type[FMC_CC_NODES_NUM];
179 unsigned char htmiss_frag[FMC_CC_NODES_NUM];
180 unsigned int htmiss_manip[FMC_CC_NODES_NUM];
182 unsigned int replicator_count;
183 char replicator_name[FMC_REPLICATORS_NUM][FMC_NAME_LEN];
184 t_handle replicator_handle[FMC_REPLICATORS_NUM];
185 t_handle replicator_dev_id[FMC_REPLICATORS_NUM];
186 struct fm_pcd_frm_replic_group_params_t replicator[FMC_REPLICATORS_NUM];
188 repentry_action_index[FMC_REPLICATORS_NUM][FM_PCD_MAX_REPS];
189 unsigned char repentry_frag[FMC_REPLICATORS_NUM][FM_PCD_MAX_REPS];
190 unsigned int repentry_manip[FMC_REPLICATORS_NUM][FM_PCD_MAX_REPS];
192 unsigned int policer_count;
193 char policer_name[FMC_PLC_NUM][FMC_NAME_LEN];
194 struct fm_pcd_plcr_profile_params_t policer[FMC_PLC_NUM];
195 t_handle policer_handle[FMC_PLC_NUM];
196 t_handle policer_dev_id[FMC_PLC_NUM];
197 unsigned int policer_action_index[FMC_PLC_NUM][3];
199 unsigned int apply_order_count;
200 fmc_apply_order apply_order[FMC_FMAN_NUM *
202 (FMC_SCHEMES_NUM + FMC_CC_NODES_NUM)];
205 struct fmc_model_t *g_fmc_model;
207 static int dpaa_port_fmc_port_parse(struct fman_if *fif,
208 const struct fmc_model_t *fmc_model,
211 int current_port = fmc_model->apply_order[apply_idx].index;
212 const fmc_port *pport = &fmc_model->port[current_port];
213 const uint8_t mac_idx[] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1};
214 const uint8_t mac_type[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
216 if (mac_idx[fif->mac_idx] != pport->number ||
217 mac_type[fif->mac_idx] != pport->type)
223 static int dpaa_port_fmc_scheme_parse(struct fman_if *fif,
224 const struct fmc_model_t *fmc,
226 uint16_t *rxq_idx, int max_nb_rxq,
227 uint32_t *fqids, int8_t *vspids)
229 int idx = fmc->apply_order[apply_idx].index;
232 if (!fmc->scheme[idx].override_storage_profile &&
233 fif->is_shared_mac) {
234 DPAA_PMD_WARN("No VSP assigned to scheme %d for sharemac %d!",
236 DPAA_PMD_WARN("Risk to receive pkts from skb pool to CRASH!");
239 if (e_IOC_FM_PCD_DONE ==
240 fmc->scheme[idx].next_engine) {
241 for (i = 0; i < fmc->scheme[idx]
242 .key_ext_and_hash.hash_dist_num_of_fqids; i++) {
243 uint32_t fqid = fmc->scheme[idx].base_fqid + i;
246 if (fqid == fif->fqid_rx_def) {
247 if (fif->is_shared_mac &&
248 fmc->scheme[idx].override_storage_profile &&
249 fmc->scheme[idx].storage_profile.direct &&
250 fmc->scheme[idx].storage_profile
251 .profile_select.direct_relative_profile_id !=
252 fif->base_profile_id) {
253 DPAA_PMD_ERR("Def RXQ must be associated with def VSP on sharemac!");
260 if (fif->is_shared_mac &&
261 !fmc->scheme[idx].override_storage_profile) {
262 DPAA_PMD_ERR("RXQ to DPDK must be associated with VSP on sharemac!");
266 if (fif->is_shared_mac &&
267 fmc->scheme[idx].override_storage_profile &&
268 fmc->scheme[idx].storage_profile.direct &&
269 fmc->scheme[idx].storage_profile
270 .profile_select.direct_relative_profile_id ==
271 fif->base_profile_id) {
272 DPAA_PMD_ERR("RXQ can't be associated with default VSP on sharemac!");
277 if ((*rxq_idx) >= max_nb_rxq) {
278 DPAA_PMD_DEBUG("Too many queues in FMC policy"
280 (*rxq_idx), max_nb_rxq);
285 for (k = 0; k < (*rxq_idx); k++) {
286 if (fqids[k] == fqid) {
294 fqids[(*rxq_idx)] = fqid;
295 if (fmc->scheme[idx].override_storage_profile) {
296 if (fmc->scheme[idx].storage_profile.direct) {
298 fmc->scheme[idx].storage_profile
300 .direct_relative_profile_id;
302 vspids[(*rxq_idx)] = -1;
305 vspids[(*rxq_idx)] = -1;
314 static int dpaa_port_fmc_ccnode_parse(struct fman_if *fif,
315 const struct fmc_model_t *fmc_model,
317 uint16_t *rxq_idx, int max_nb_rxq,
318 uint32_t *fqids, int8_t *vspids)
320 uint16_t j, k, found = 0;
321 const struct ioc_keys_params_t *keys_params;
322 uint32_t fqid, cc_idx = fmc_model->apply_order[apply_idx].index;
324 keys_params = &fmc_model->ccnode[cc_idx].keys_params;
326 if ((*rxq_idx) >= max_nb_rxq) {
327 DPAA_PMD_WARN("Too many queues in FMC policy %d overflow %d",
328 (*rxq_idx), max_nb_rxq);
333 for (j = 0; j < keys_params->num_of_keys; ++j) {
335 fqid = keys_params->key_params[j].cc_next_engine_params
336 .params.enqueue_params.new_fqid;
338 if (keys_params->key_params[j].cc_next_engine_params
339 .next_engine != e_IOC_FM_PCD_DONE) {
340 DPAA_PMD_WARN("FMC CC next engine not support");
343 if (keys_params->key_params[j].cc_next_engine_params
344 .params.enqueue_params.action !=
345 e_IOC_FM_PCD_ENQ_FRAME)
347 for (k = 0; k < (*rxq_idx); k++) {
348 if (fqids[k] == fqid) {
356 if ((*rxq_idx) >= max_nb_rxq) {
357 DPAA_PMD_WARN("Too many queues in FMC policy %d overflow %d",
358 (*rxq_idx), max_nb_rxq);
363 fqids[(*rxq_idx)] = fqid;
365 keys_params->key_params[j].cc_next_engine_params
366 .params.enqueue_params
367 .new_relative_storage_profile_id;
369 if (vspids[(*rxq_idx)] == fif->base_profile_id &&
370 fif->is_shared_mac) {
371 DPAA_PMD_ERR("VSP %d can NOT be used on DPDK.",
373 DPAA_PMD_ERR("It is associated to skb pool of shared interface.");
382 int dpaa_port_fmc_init(struct fman_if *fif,
383 uint32_t *fqids, int8_t *vspids, int max_nb_rxq)
385 int current_port = -1, ret;
386 uint16_t rxq_idx = 0;
387 const struct fmc_model_t *fmc_model;
392 FILE *fp = fopen(FMC_FILE, "rb");
395 DPAA_PMD_ERR("%s not exists", FMC_FILE);
399 g_fmc_model = rte_malloc(NULL, sizeof(struct fmc_model_t), 64);
401 DPAA_PMD_ERR("FMC memory alloc failed");
406 bytes_read = fread(g_fmc_model,
407 sizeof(struct fmc_model_t), 1, fp);
409 DPAA_PMD_ERR("No bytes read");
411 rte_free(g_fmc_model);
418 fmc_model = g_fmc_model;
420 if (fmc_model->format_version != FMC_OUTPUT_FORMAT_VER)
423 for (i = 0; i < fmc_model->apply_order_count; i++) {
424 switch (fmc_model->apply_order[i].type) {
425 case fmcengine_start:
430 current_port = dpaa_port_fmc_port_parse(fif,
436 if (current_port < 0)
439 ret = dpaa_port_fmc_scheme_parse(fif, fmc_model,
448 if (current_port < 0)
451 ret = dpaa_port_fmc_ccnode_parse(fif, fmc_model,
467 case fmcmanipulation: