1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017-2019,2021 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 DPAA_MAX_NUM_ETH_DEV 8
20 ioc_fm_pcd_extract_entry_t *
21 SCH_EXT_ARR(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
23 return &scheme_params->param.key_ext_and_hash.extract_array[hdr_idx];
26 #define SCH_EXT_HDR(scheme_params, hdr_idx) \
27 SCH_EXT_ARR(scheme_params, hdr_idx)->extract_params.extract_by_hdr
29 #define SCH_EXT_FULL_FLD(scheme_params, hdr_idx) \
30 SCH_EXT_HDR(scheme_params, hdr_idx).extract_by_hdr_type.full_field
38 /*FM model to read and write from file */
39 struct dpaa_fm_model {
41 uint8_t device_order[DPAA_MAX_NUM_ETH_DEV];
42 t_fm_port_params fm_port_params[DPAA_MAX_NUM_ETH_DEV];
43 t_handle netenv_devid[DPAA_MAX_NUM_ETH_DEV];
44 t_handle scheme_devid[DPAA_MAX_NUM_ETH_DEV][2];
47 static struct dpaa_fm_info fm_info;
48 static struct dpaa_fm_model fm_model;
49 static const char *fm_log = "/tmp/fmdpdk.bin";
51 static inline uint8_t fm_default_vsp_id(struct fman_if *fif)
53 /* Avoid being same as base profile which could be used
54 * for kernel interface of shared mac.
56 if (fif->base_profile_id)
59 return DPAA_DEFAULT_RXQ_VSP_ID;
62 static void fm_prev_cleanup(void)
64 uint32_t fman_id = 0, i = 0, devid;
65 struct dpaa_if dpaa_intf = {0};
66 t_fm_pcd_params fm_pcd_params = {0};
67 PMD_INIT_FUNC_TRACE();
69 fm_info.fman_handle = fm_open(fman_id);
70 if (!fm_info.fman_handle) {
71 printf("\n%s- unable to open FMAN", __func__);
75 fm_pcd_params.h_fm = fm_info.fman_handle;
76 fm_pcd_params.prs_support = true;
77 fm_pcd_params.kg_support = true;
79 fm_info.pcd_handle = fm_pcd_open(&fm_pcd_params);
80 if (!fm_info.pcd_handle) {
81 printf("\n%s- unable to open PCD", __func__);
85 while (i < fm_model.dev_count) {
86 devid = fm_model.device_order[i];
88 fm_model.fm_port_params[devid].h_fm = fm_info.fman_handle;
89 dpaa_intf.port_handle =
90 fm_port_open(&fm_model.fm_port_params[devid]);
91 dpaa_intf.scheme_handle[0] = create_device(fm_info.pcd_handle,
92 fm_model.scheme_devid[devid][0]);
93 dpaa_intf.scheme_count = 1;
94 if (fm_model.scheme_devid[devid][1]) {
95 dpaa_intf.scheme_handle[1] =
96 create_device(fm_info.pcd_handle,
97 fm_model.scheme_devid[devid][1]);
98 if (dpaa_intf.scheme_handle[1])
99 dpaa_intf.scheme_count++;
102 dpaa_intf.netenv_handle = create_device(fm_info.pcd_handle,
103 fm_model.netenv_devid[devid]);
105 if (!dpaa_intf.netenv_handle ||
106 !dpaa_intf.scheme_handle[0] ||
107 !dpaa_intf.port_handle)
110 if (dpaa_fm_deconfig(&dpaa_intf, NULL))
111 printf("\nDPAA FM deconfig failed\n");
115 printf("\nDPAA FM term failed\n");
117 memset(&fm_model, 0, sizeof(struct dpaa_fm_model));
120 void dpaa_write_fm_config_to_file(void)
123 FILE *fp = fopen(fm_log, "wb");
124 PMD_INIT_FUNC_TRACE();
127 DPAA_PMD_ERR("File open failed");
130 bytes_write = fwrite(&fm_model, sizeof(struct dpaa_fm_model), 1, fp);
132 DPAA_PMD_WARN("No bytes write");
139 static void dpaa_read_fm_config_from_file(void)
142 FILE *fp = fopen(fm_log, "rb");
143 PMD_INIT_FUNC_TRACE();
147 DPAA_PMD_INFO("Previous DPDK-FM config instance present, cleaning up.");
149 bytes_read = fread(&fm_model, sizeof(struct dpaa_fm_model), 1, fp);
151 DPAA_PMD_WARN("No bytes read");
157 /*FM cleanup from previous configured app */
162 set_hash_params_eth(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
166 for (k = 0; k < 2; k++) {
167 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
168 e_IOC_FM_PCD_EXTRACT_BY_HDR;
169 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
171 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
172 e_IOC_FM_PCD_HDR_INDEX_NONE;
173 SCH_EXT_HDR(scheme_params, hdr_idx).type =
174 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
176 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).eth =
179 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).eth =
187 set_hash_params_ipv4(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
191 for (k = 0; k < 2; k++) {
192 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
193 e_IOC_FM_PCD_EXTRACT_BY_HDR;
194 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
196 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
197 e_IOC_FM_PCD_HDR_INDEX_NONE;
198 SCH_EXT_HDR(scheme_params, hdr_idx).type =
199 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
201 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv4 =
202 ioc_net_hf_ipv_4_src_ip;
204 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv4 =
205 ioc_net_hf_ipv_4_dst_ip;
212 set_hash_params_ipv6(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
216 for (k = 0; k < 2; k++) {
217 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
218 e_IOC_FM_PCD_EXTRACT_BY_HDR;
219 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
221 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
222 e_IOC_FM_PCD_HDR_INDEX_NONE;
223 SCH_EXT_HDR(scheme_params, hdr_idx).type =
224 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
226 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv6 =
227 ioc_net_hf_ipv_6_src_ip;
229 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv6 =
230 ioc_net_hf_ipv_6_dst_ip;
237 set_hash_params_udp(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
241 for (k = 0; k < 2; k++) {
242 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
243 e_IOC_FM_PCD_EXTRACT_BY_HDR;
244 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
246 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
247 e_IOC_FM_PCD_HDR_INDEX_NONE;
248 SCH_EXT_HDR(scheme_params, hdr_idx).type =
249 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
251 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).udp =
252 IOC_NET_HF_UDP_PORT_SRC;
254 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).udp =
255 IOC_NET_HF_UDP_PORT_DST;
262 set_hash_params_tcp(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
266 for (k = 0; k < 2; k++) {
267 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
268 e_IOC_FM_PCD_EXTRACT_BY_HDR;
269 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
271 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
272 e_IOC_FM_PCD_HDR_INDEX_NONE;
273 SCH_EXT_HDR(scheme_params, hdr_idx).type =
274 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
276 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).tcp =
277 IOC_NET_HF_TCP_PORT_SRC;
279 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).tcp =
280 IOC_NET_HF_TCP_PORT_DST;
287 set_hash_params_sctp(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
291 for (k = 0; k < 2; k++) {
292 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
293 e_IOC_FM_PCD_EXTRACT_BY_HDR;
294 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
296 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
297 e_IOC_FM_PCD_HDR_INDEX_NONE;
298 SCH_EXT_HDR(scheme_params, hdr_idx).type =
299 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
301 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).sctp =
302 IOC_NET_HF_SCTP_PORT_SRC;
304 SCH_EXT_FULL_FLD(scheme_params, hdr_idx).sctp =
305 IOC_NET_HF_SCTP_PORT_DST;
311 /* Set scheme params for hash distribution */
312 static int set_scheme_params(ioc_fm_pcd_kg_scheme_params_t *scheme_params,
313 ioc_fm_pcd_net_env_params_t *dist_units,
314 struct dpaa_if *dpaa_intf,
317 int dist_idx, hdr_idx = 0;
318 PMD_INIT_FUNC_TRACE();
320 if (fif->num_profiles) {
321 scheme_params->param.override_storage_profile = true;
322 scheme_params->param.storage_profile.direct = true;
323 scheme_params->param.storage_profile.profile_select
324 .direct_relative_profile_id = fm_default_vsp_id(fif);
327 scheme_params->param.use_hash = 1;
328 scheme_params->param.modify = false;
329 scheme_params->param.always_direct = false;
330 scheme_params->param.scheme_counter.update = 1;
331 scheme_params->param.scheme_counter.value = 0;
332 scheme_params->param.next_engine = e_IOC_FM_PCD_DONE;
333 scheme_params->param.base_fqid = dpaa_intf->rx_queues[0].fqid;
334 scheme_params->param.net_env_params.net_env_id =
335 dpaa_intf->netenv_handle;
336 scheme_params->param.net_env_params.num_of_distinction_units =
337 dist_units->param.num_of_distinction_units;
339 scheme_params->param.key_ext_and_hash.hash_dist_num_of_fqids =
340 dpaa_intf->nb_rx_queues;
341 scheme_params->param.key_ext_and_hash.num_of_used_extracts =
342 2 * dist_units->param.num_of_distinction_units;
344 for (dist_idx = 0; dist_idx <
345 dist_units->param.num_of_distinction_units;
347 switch (dist_units->param.units[dist_idx].hdrs[0].hdr) {
348 case HEADER_TYPE_ETH:
349 hdr_idx = set_hash_params_eth(scheme_params, hdr_idx);
352 case HEADER_TYPE_IPV4:
353 hdr_idx = set_hash_params_ipv4(scheme_params, hdr_idx);
356 case HEADER_TYPE_IPV6:
357 hdr_idx = set_hash_params_ipv6(scheme_params, hdr_idx);
360 case HEADER_TYPE_UDP:
361 hdr_idx = set_hash_params_udp(scheme_params, hdr_idx);
364 case HEADER_TYPE_TCP:
365 hdr_idx = set_hash_params_tcp(scheme_params, hdr_idx);
368 case HEADER_TYPE_SCTP:
369 hdr_idx = set_hash_params_sctp(scheme_params, hdr_idx);
373 DPAA_PMD_ERR("Invalid Distinction Unit");
381 static void set_dist_units(ioc_fm_pcd_net_env_params_t *dist_units,
382 uint64_t req_dist_set)
384 uint32_t loop = 0, dist_idx = 0, dist_field = 0;
385 int l2_configured = 0, ipv4_configured = 0, ipv6_configured = 0;
386 int udp_configured = 0, tcp_configured = 0, sctp_configured = 0;
387 PMD_INIT_FUNC_TRACE();
390 dist_units->param.units[dist_idx++].hdrs[0].hdr =
393 while (req_dist_set) {
394 if (req_dist_set % 2 != 0) {
395 dist_field = 1U << loop;
396 switch (dist_field) {
397 case ETH_RSS_L2_PAYLOAD:
403 dist_units->param.units[dist_idx++].hdrs[0].hdr
408 case ETH_RSS_FRAG_IPV4:
409 case ETH_RSS_NONFRAG_IPV4_OTHER:
414 dist_units->param.units[dist_idx++].hdrs[0].hdr
419 case ETH_RSS_FRAG_IPV6:
420 case ETH_RSS_NONFRAG_IPV6_OTHER:
421 case ETH_RSS_IPV6_EX:
426 dist_units->param.units[dist_idx++].hdrs[0].hdr
430 case ETH_RSS_NONFRAG_IPV4_TCP:
431 case ETH_RSS_NONFRAG_IPV6_TCP:
432 case ETH_RSS_IPV6_TCP_EX:
437 dist_units->param.units[dist_idx++].hdrs[0].hdr
441 case ETH_RSS_NONFRAG_IPV4_UDP:
442 case ETH_RSS_NONFRAG_IPV6_UDP:
443 case ETH_RSS_IPV6_UDP_EX:
448 dist_units->param.units[dist_idx++].hdrs[0].hdr
452 case ETH_RSS_NONFRAG_IPV4_SCTP:
453 case ETH_RSS_NONFRAG_IPV6_SCTP:
459 dist_units->param.units[dist_idx++].hdrs[0].hdr
464 DPAA_PMD_ERR("Bad flow distribution option");
467 req_dist_set = req_dist_set >> 1;
471 /* Dist units is set to dist_idx */
472 dist_units->param.num_of_distinction_units = dist_idx;
475 /* Apply PCD configuration on interface */
476 static inline int set_port_pcd(struct dpaa_if *dpaa_intf)
480 ioc_fm_port_pcd_params_t pcd_param;
481 ioc_fm_port_pcd_prs_params_t prs_param;
482 ioc_fm_port_pcd_kg_params_t kg_param;
484 PMD_INIT_FUNC_TRACE();
486 /* PCD support for hash distribution */
487 uint8_t pcd_support = e_FM_PORT_PCD_SUPPORT_PRS_AND_KG;
489 memset(&pcd_param, 0, sizeof(pcd_param));
490 memset(&prs_param, 0, sizeof(prs_param));
491 memset(&kg_param, 0, sizeof(kg_param));
493 /* Set parse params */
494 prs_param.first_prs_hdr = HEADER_TYPE_ETH;
497 for (idx = 0; idx < dpaa_intf->scheme_count; idx++)
498 kg_param.scheme_ids[idx] = dpaa_intf->scheme_handle[idx];
499 kg_param.num_schemes = dpaa_intf->scheme_count;
502 pcd_param.net_env_id = dpaa_intf->netenv_handle;
503 pcd_param.pcd_support = pcd_support;
504 pcd_param.p_kg_params = &kg_param;
505 pcd_param.p_prs_params = &prs_param;
507 /* FM PORT Disable */
508 ret = fm_port_disable(dpaa_intf->port_handle);
510 DPAA_PMD_ERR("fm_port_disable: Failed");
515 ret = fm_port_set_pcd(dpaa_intf->port_handle, &pcd_param);
517 DPAA_PMD_ERR("fm_port_set_pcd: Failed");
522 ret = fm_port_enable(dpaa_intf->port_handle);
524 DPAA_PMD_ERR("fm_port_enable: Failed");
525 goto fm_port_delete_pcd;
531 /* FM PORT DeletePCD */
532 ret = fm_port_delete_pcd(dpaa_intf->port_handle);
534 DPAA_PMD_ERR("fm_port_delete_pcd: Failed\n");
540 /* Unset PCD NerEnv and scheme */
541 static inline void unset_pcd_netenv_scheme(struct dpaa_if *dpaa_intf)
544 PMD_INIT_FUNC_TRACE();
546 /* reduce scheme count */
547 if (dpaa_intf->scheme_count)
548 dpaa_intf->scheme_count--;
550 DPAA_PMD_DEBUG("KG SCHEME DEL %d handle =%p",
551 dpaa_intf->scheme_count,
552 dpaa_intf->scheme_handle[dpaa_intf->scheme_count]);
554 ret = fm_pcd_kg_scheme_delete(dpaa_intf->scheme_handle
555 [dpaa_intf->scheme_count]);
557 DPAA_PMD_ERR("fm_pcd_kg_scheme_delete: Failed");
559 dpaa_intf->scheme_handle[dpaa_intf->scheme_count] = NULL;
562 /* Set PCD NetEnv and Scheme and default scheme */
563 static inline int set_default_scheme(struct dpaa_if *dpaa_intf)
565 ioc_fm_pcd_kg_scheme_params_t scheme_params;
566 int idx = dpaa_intf->scheme_count;
567 PMD_INIT_FUNC_TRACE();
569 /* Set PCD NetEnvCharacteristics */
570 memset(&scheme_params, 0, sizeof(scheme_params));
572 /* Adding 10 to default schemes as the number of interface would be
573 * lesser than 10 and the relative scheme ids should be unique for
576 scheme_params.param.scm_id.relative_scheme_id =
577 10 + dpaa_intf->ifid;
578 scheme_params.param.use_hash = 0;
579 scheme_params.param.next_engine = e_IOC_FM_PCD_DONE;
580 scheme_params.param.net_env_params.num_of_distinction_units = 0;
581 scheme_params.param.net_env_params.net_env_id =
582 dpaa_intf->netenv_handle;
583 scheme_params.param.base_fqid = dpaa_intf->rx_queues[0].fqid;
584 scheme_params.param.key_ext_and_hash.hash_dist_num_of_fqids = 1;
585 scheme_params.param.key_ext_and_hash.num_of_used_extracts = 0;
586 scheme_params.param.modify = false;
587 scheme_params.param.always_direct = false;
588 scheme_params.param.scheme_counter.update = 1;
589 scheme_params.param.scheme_counter.value = 0;
591 /* FM PCD KgSchemeSet */
592 dpaa_intf->scheme_handle[idx] =
593 fm_pcd_kg_scheme_set(fm_info.pcd_handle, &scheme_params);
594 DPAA_PMD_DEBUG("KG SCHEME SET %d handle =%p",
595 idx, dpaa_intf->scheme_handle[idx]);
596 if (!dpaa_intf->scheme_handle[idx]) {
597 DPAA_PMD_ERR("fm_pcd_kg_scheme_set: Failed");
601 fm_model.scheme_devid[dpaa_intf->ifid][idx] =
602 get_device_id(dpaa_intf->scheme_handle[idx]);
603 dpaa_intf->scheme_count++;
608 /* Set PCD NetEnv and Scheme and default scheme */
609 static inline int set_pcd_netenv_scheme(struct dpaa_if *dpaa_intf,
610 uint64_t req_dist_set,
614 ioc_fm_pcd_net_env_params_t dist_units;
615 ioc_fm_pcd_kg_scheme_params_t scheme_params;
616 int idx = dpaa_intf->scheme_count;
617 PMD_INIT_FUNC_TRACE();
619 /* Set PCD NetEnvCharacteristics */
620 memset(&dist_units, 0, sizeof(dist_units));
621 memset(&scheme_params, 0, sizeof(scheme_params));
623 /* Set dist unit header type */
624 set_dist_units(&dist_units, req_dist_set);
626 scheme_params.param.scm_id.relative_scheme_id = dpaa_intf->ifid;
628 /* Set PCD Scheme params */
629 ret = set_scheme_params(&scheme_params, &dist_units, dpaa_intf, fif);
631 DPAA_PMD_ERR("Set scheme params: Failed");
635 /* FM PCD KgSchemeSet */
636 dpaa_intf->scheme_handle[idx] =
637 fm_pcd_kg_scheme_set(fm_info.pcd_handle, &scheme_params);
638 DPAA_PMD_DEBUG("KG SCHEME SET %d handle =%p",
639 idx, dpaa_intf->scheme_handle[idx]);
640 if (!dpaa_intf->scheme_handle[idx]) {
641 DPAA_PMD_ERR("fm_pcd_kg_scheme_set: Failed");
645 fm_model.scheme_devid[dpaa_intf->ifid][idx] =
646 get_device_id(dpaa_intf->scheme_handle[idx]);
647 dpaa_intf->scheme_count++;
652 static inline int get_port_type(struct fman_if *fif)
654 if (fif->mac_type == fman_mac_1g)
655 return e_FM_PORT_TYPE_RX;
656 else if (fif->mac_type == fman_mac_2_5g)
657 return e_FM_PORT_TYPE_RX_2_5G;
658 else if (fif->mac_type == fman_mac_10g)
659 return e_FM_PORT_TYPE_RX_10G;
661 DPAA_PMD_ERR("MAC type unsupported");
665 static inline int set_fm_port_handle(struct dpaa_if *dpaa_intf,
666 uint64_t req_dist_set,
669 t_fm_port_params fm_port_params;
670 ioc_fm_pcd_net_env_params_t dist_units;
671 PMD_INIT_FUNC_TRACE();
673 /* FMAN mac indexes mappings (0 is unused,
674 * first 8 are for 1G, next for 10G ports
676 uint8_t mac_idx[] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1};
678 /* Memset FM port params */
679 memset(&fm_port_params, 0, sizeof(fm_port_params));
681 /* Set FM port params */
682 fm_port_params.h_fm = fm_info.fman_handle;
683 fm_port_params.port_type = get_port_type(fif);
684 fm_port_params.port_id = mac_idx[fif->mac_idx];
687 dpaa_intf->port_handle = fm_port_open(&fm_port_params);
688 if (!dpaa_intf->port_handle) {
689 DPAA_PMD_ERR("fm_port_open: Failed\n");
693 fm_model.fm_port_params[dpaa_intf->ifid] = fm_port_params;
695 /* Set PCD NetEnvCharacteristics */
696 memset(&dist_units, 0, sizeof(dist_units));
698 /* Set dist unit header type */
699 set_dist_units(&dist_units, req_dist_set);
701 /* FM PCD NetEnvCharacteristicsSet */
702 dpaa_intf->netenv_handle =
703 fm_pcd_net_env_characteristics_set(fm_info.pcd_handle,
705 if (!dpaa_intf->netenv_handle) {
706 DPAA_PMD_ERR("fm_pcd_net_env_characteristics_set: Failed");
710 fm_model.netenv_devid[dpaa_intf->ifid] =
711 get_device_id(dpaa_intf->netenv_handle);
716 /* De-Configure DPAA FM */
717 int dpaa_fm_deconfig(struct dpaa_if *dpaa_intf,
718 struct fman_if *fif __rte_unused)
723 PMD_INIT_FUNC_TRACE();
725 /* FM PORT Disable */
726 ret = fm_port_disable(dpaa_intf->port_handle);
728 DPAA_PMD_ERR("fm_port_disable: Failed");
732 /* FM PORT DeletePCD */
733 ret = fm_port_delete_pcd(dpaa_intf->port_handle);
735 DPAA_PMD_ERR("fm_port_delete_pcd: Failed");
739 for (idx = 0; idx < dpaa_intf->scheme_count; idx++) {
740 DPAA_PMD_DEBUG("KG SCHEME DEL %d, handle =%p",
741 idx, dpaa_intf->scheme_handle[idx]);
742 /* FM PCD KgSchemeDelete */
743 ret = fm_pcd_kg_scheme_delete(dpaa_intf->scheme_handle[idx]);
745 DPAA_PMD_ERR("fm_pcd_kg_scheme_delete: Failed");
748 dpaa_intf->scheme_handle[idx] = NULL;
750 /* FM PCD NetEnvCharacteristicsDelete */
751 ret = fm_pcd_net_env_characteristics_delete(dpaa_intf->netenv_handle);
753 DPAA_PMD_ERR("fm_pcd_net_env_characteristics_delete: Failed");
756 dpaa_intf->netenv_handle = NULL;
758 if (fif && fif->is_shared_mac) {
759 ret = fm_port_enable(dpaa_intf->port_handle);
761 DPAA_PMD_ERR("shared mac re-enable failed");
767 fm_port_close(dpaa_intf->port_handle);
768 dpaa_intf->port_handle = NULL;
770 /* Set scheme count to 0 */
771 dpaa_intf->scheme_count = 0;
776 int dpaa_fm_config(struct rte_eth_dev *dev, uint64_t req_dist_set)
778 struct dpaa_if *dpaa_intf = dev->data->dev_private;
779 struct fman_if *fif = dev->process_private;
782 PMD_INIT_FUNC_TRACE();
784 if (dpaa_intf->port_handle) {
785 if (dpaa_fm_deconfig(dpaa_intf, fif))
786 DPAA_PMD_ERR("DPAA FM deconfig failed");
789 if (!dev->data->nb_rx_queues)
792 if (dev->data->nb_rx_queues & (dev->data->nb_rx_queues - 1)) {
793 DPAA_PMD_ERR("No of queues should be power of 2");
797 dpaa_intf->nb_rx_queues = dev->data->nb_rx_queues;
799 /* Open FM Port and set it in port info */
800 ret = set_fm_port_handle(dpaa_intf, req_dist_set, fif);
802 DPAA_PMD_ERR("Set FM Port handle: Failed");
806 if (fif->num_profiles) {
807 for (i = 0; i < dpaa_intf->nb_rx_queues; i++)
808 dpaa_intf->rx_queues[i].vsp_id =
809 fm_default_vsp_id(fif);
814 /* Set PCD netenv and scheme */
816 ret = set_pcd_netenv_scheme(dpaa_intf, req_dist_set, fif);
818 DPAA_PMD_ERR("Set PCD NetEnv and Scheme dist: Failed");
819 goto unset_fm_port_handle;
822 /* Set default netenv and scheme */
823 if (!fif->is_shared_mac) {
824 ret = set_default_scheme(dpaa_intf);
826 DPAA_PMD_ERR("Set PCD NetEnv and Scheme: Failed");
827 goto unset_pcd_netenv_scheme1;
832 ret = set_port_pcd(dpaa_intf);
834 DPAA_PMD_ERR("Set Port PCD: Failed");
835 goto unset_pcd_netenv_scheme;
838 for (; i < fm_model.dev_count; i++)
839 if (fm_model.device_order[i] == dpaa_intf->ifid)
842 fm_model.device_order[fm_model.dev_count] = dpaa_intf->ifid;
843 fm_model.dev_count++;
847 unset_pcd_netenv_scheme:
848 unset_pcd_netenv_scheme(dpaa_intf);
850 unset_pcd_netenv_scheme1:
851 unset_pcd_netenv_scheme(dpaa_intf);
853 unset_fm_port_handle:
855 fm_port_close(dpaa_intf->port_handle);
856 dpaa_intf->port_handle = NULL;
860 int dpaa_fm_init(void)
862 t_handle fman_handle;
864 t_fm_pcd_params fm_pcd_params = {0};
865 /* Hard-coded : fman id 0 since one fman is present in LS104x */
866 int fman_id = 0, ret;
867 PMD_INIT_FUNC_TRACE();
869 dpaa_read_fm_config_from_file();
872 fman_handle = fm_open(fman_id);
874 DPAA_PMD_ERR("fm_open: Failed");
879 fm_pcd_params.h_fm = fman_handle;
880 fm_pcd_params.prs_support = true;
881 fm_pcd_params.kg_support = true;
882 pcd_handle = fm_pcd_open(&fm_pcd_params);
884 fm_close(fman_handle);
885 DPAA_PMD_ERR("fm_pcd_open: Failed");
890 ret = fm_pcd_enable(pcd_handle);
892 fm_close(fman_handle);
893 fm_pcd_close(pcd_handle);
894 DPAA_PMD_ERR("fm_pcd_enable: Failed");
898 /* Set fman and pcd handle in fm info */
899 fm_info.fman_handle = fman_handle;
900 fm_info.pcd_handle = pcd_handle;
906 /* De-initialization of FM */
907 int dpaa_fm_term(void)
911 PMD_INIT_FUNC_TRACE();
913 if (fm_info.pcd_handle && fm_info.fman_handle) {
915 ret = fm_pcd_disable(fm_info.pcd_handle);
917 DPAA_PMD_ERR("fm_pcd_disable: Failed");
922 fm_pcd_close(fm_info.pcd_handle);
923 fm_info.pcd_handle = NULL;
926 if (fm_info.fman_handle) {
928 fm_close(fm_info.fman_handle);
929 fm_info.fman_handle = NULL;
932 if (access(fm_log, F_OK) != -1) {
933 ret = remove(fm_log);
935 DPAA_PMD_ERR("File remove: Failed");
940 static int dpaa_port_vsp_configure(struct dpaa_if *dpaa_intf,
941 uint8_t vsp_id, t_handle fman_handle,
944 t_fm_vsp_params vsp_params;
945 t_fm_buffer_prefix_content buf_prefix_cont;
946 uint8_t mac_idx[] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1};
947 uint8_t idx = mac_idx[fif->mac_idx];
950 if (vsp_id == fif->base_profile_id && fif->is_shared_mac) {
951 /* For shared interface, VSP of base
952 * profile is default pool located in kernel.
954 dpaa_intf->vsp_bpid[vsp_id] = 0;
958 if (vsp_id >= DPAA_VSP_PROFILE_MAX_NUM) {
959 DPAA_PMD_ERR("VSP ID %d exceeds MAX number %d",
960 vsp_id, DPAA_VSP_PROFILE_MAX_NUM);
964 memset(&vsp_params, 0, sizeof(vsp_params));
965 vsp_params.h_fm = fman_handle;
966 vsp_params.relative_profile_id = vsp_id;
967 vsp_params.port_params.port_id = idx;
968 if (fif->mac_type == fman_mac_1g) {
969 vsp_params.port_params.port_type = e_FM_PORT_TYPE_RX;
970 } else if (fif->mac_type == fman_mac_2_5g) {
971 vsp_params.port_params.port_type = e_FM_PORT_TYPE_RX_2_5G;
972 } else if (fif->mac_type == fman_mac_10g) {
973 vsp_params.port_params.port_type = e_FM_PORT_TYPE_RX_10G;
975 DPAA_PMD_ERR("Mac type %d error", fif->mac_type);
978 vsp_params.ext_buf_pools.num_of_pools_used = 1;
979 vsp_params.ext_buf_pools.ext_buf_pool[0].id =
980 dpaa_intf->vsp_bpid[vsp_id];
981 vsp_params.ext_buf_pools.ext_buf_pool[0].size =
982 RTE_MBUF_DEFAULT_BUF_SIZE;
984 dpaa_intf->vsp_handle[vsp_id] = fm_vsp_config(&vsp_params);
985 if (!dpaa_intf->vsp_handle[vsp_id]) {
986 DPAA_PMD_ERR("fm_vsp_config error for profile %d", vsp_id);
990 /* configure the application buffer (structure, size and
994 memset(&buf_prefix_cont, 0, sizeof(buf_prefix_cont));
996 buf_prefix_cont.priv_data_size = 16;
997 buf_prefix_cont.data_align = 64;
998 buf_prefix_cont.pass_prs_result = true;
999 buf_prefix_cont.pass_time_stamp = true;
1000 buf_prefix_cont.pass_hash_result = false;
1001 buf_prefix_cont.pass_all_other_pcdinfo = false;
1002 buf_prefix_cont.manip_ext_space =
1003 RTE_PKTMBUF_HEADROOM - DPAA_MBUF_HW_ANNOTATION;
1005 ret = fm_vsp_config_buffer_prefix_content(dpaa_intf->vsp_handle[vsp_id],
1008 DPAA_PMD_ERR("fm_vsp_config_buffer_prefix_content error for profile %d err: %d",
1013 /* initialize the FM VSP module */
1014 ret = fm_vsp_init(dpaa_intf->vsp_handle[vsp_id]);
1016 DPAA_PMD_ERR("fm_vsp_init error for profile %d err:%d",
1024 int dpaa_port_vsp_update(struct dpaa_if *dpaa_intf,
1025 bool fmc_mode, uint8_t vsp_id, uint32_t bpid,
1026 struct fman_if *fif)
1029 t_handle fman_handle;
1031 if (!fif->num_profiles)
1034 if (vsp_id >= fif->num_profiles)
1037 if (dpaa_intf->vsp_bpid[vsp_id] == bpid)
1040 if (dpaa_intf->vsp_handle[vsp_id]) {
1041 ret = fm_vsp_free(dpaa_intf->vsp_handle[vsp_id]);
1043 DPAA_PMD_ERR("Error fm_vsp_free: err %d vsp_handle[%d]",
1047 dpaa_intf->vsp_handle[vsp_id] = 0;
1051 fman_handle = fm_open(0);
1053 fman_handle = fm_info.fman_handle;
1055 dpaa_intf->vsp_bpid[vsp_id] = bpid;
1057 return dpaa_port_vsp_configure(dpaa_intf, vsp_id, fman_handle, fif);
1060 int dpaa_port_vsp_cleanup(struct dpaa_if *dpaa_intf, struct fman_if *fif)
1064 for (idx = 0; idx < (uint8_t)fif->num_profiles; idx++) {
1065 if (dpaa_intf->vsp_handle[idx]) {
1066 ret = fm_vsp_free(dpaa_intf->vsp_handle[idx]);
1068 DPAA_PMD_ERR("Error fm_vsp_free: err %d"
1069 " vsp_handle[%d]", ret, idx);