LCOV - code coverage report
Current view: top level - drivers/net/dpaa - dpaa_flow.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 469 0.0 %
Date: 2026-08-01 17:54:00 Functions: 0 18 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 222 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2017-2019,2021-2025 NXP
       3                 :            :  */
       4                 :            : 
       5                 :            : /* System headers */
       6                 :            : #include <stdio.h>
       7                 :            : #include <inttypes.h>
       8                 :            : #include <unistd.h>
       9                 :            : #include <sys/types.h>
      10                 :            : 
      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>
      16                 :            : #include <rte_pmd_dpaa.h>
      17                 :            : 
      18                 :            : #define DPAA_MAX_NUM_ETH_DEV    8
      19                 :            : 
      20                 :            : static inline
      21                 :            : ioc_fm_pcd_extract_entry_t *
      22                 :            : SCH_EXT_ARR(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
      23                 :            : {
      24                 :            : return &scheme_params->param.key_ext_and_hash.extract_array[hdr_idx];
      25                 :            : }
      26                 :            : 
      27                 :            : #define SCH_EXT_HDR(scheme_params, hdr_idx) \
      28                 :            :         SCH_EXT_ARR(scheme_params, hdr_idx)->extract_params.extract_by_hdr
      29                 :            : 
      30                 :            : #define SCH_EXT_FULL_FLD(scheme_params, hdr_idx) \
      31                 :            :         SCH_EXT_HDR(scheme_params, hdr_idx).extract_by_hdr_type.full_field
      32                 :            : 
      33                 :            : /* FMAN mac indexes mappings (0 is unused, first 8 are for 1G, next for 10G
      34                 :            :  * ports).
      35                 :            :  */
      36                 :            : const uint8_t mac_idx[] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1};
      37                 :            : 
      38                 :            : /* FM global info */
      39                 :            : struct dpaa_fm_info {
      40                 :            :         t_handle fman_handle;
      41                 :            :         t_handle pcd_handle;
      42                 :            : };
      43                 :            : 
      44                 :            : /*FM model to read and write from file */
      45                 :            : struct dpaa_fm_model {
      46                 :            :         uint32_t dev_count;
      47                 :            :         uint8_t device_order[DPAA_MAX_NUM_ETH_DEV];
      48                 :            :         t_fm_port_params fm_port_params[DPAA_MAX_NUM_ETH_DEV];
      49                 :            :         t_handle netenv_devid[DPAA_MAX_NUM_ETH_DEV];
      50                 :            :         t_handle scheme_devid[DPAA_MAX_NUM_ETH_DEV][2];
      51                 :            : };
      52                 :            : 
      53                 :            : static struct dpaa_fm_info fm_info;
      54                 :            : static struct dpaa_fm_model fm_model;
      55                 :            : static const char *fm_log = "/tmp/fmdpdk.bin";
      56                 :            : 
      57                 :          0 : static void fm_prev_cleanup(void)
      58                 :            : {
      59                 :            :         uint32_t fman_id = 0, i = 0, devid;
      60                 :          0 :         struct dpaa_if dpaa_intf = {0};
      61                 :          0 :         t_fm_pcd_params fm_pcd_params = {0};
      62                 :          0 :         PMD_INIT_FUNC_TRACE();
      63                 :            : 
      64                 :          0 :         fm_info.fman_handle = fm_open(fman_id);
      65         [ #  # ]:          0 :         if (!fm_info.fman_handle) {
      66                 :          0 :                 DPAA_PMD_ERR("unable to open FMAN");
      67                 :          0 :                 return;
      68                 :            :         }
      69                 :            : 
      70                 :          0 :         fm_pcd_params.h_fm = fm_info.fman_handle;
      71                 :          0 :         fm_pcd_params.prs_support = true;
      72                 :          0 :         fm_pcd_params.kg_support = true;
      73                 :            :         /* FM PCD Open */
      74                 :          0 :         fm_info.pcd_handle = fm_pcd_open(&fm_pcd_params);
      75         [ #  # ]:          0 :         if (!fm_info.pcd_handle) {
      76                 :          0 :                 DPAA_PMD_ERR("unable to open PCD");
      77                 :          0 :                 return;
      78                 :            :         }
      79                 :            : 
      80         [ #  # ]:          0 :         while (i < fm_model.dev_count) {
      81                 :          0 :                 devid = fm_model.device_order[i];
      82                 :            :                 /* FM Port Open */
      83                 :          0 :                 fm_model.fm_port_params[devid].h_fm = fm_info.fman_handle;
      84         [ #  # ]:          0 :                 if (dpaa_intf.port_handle) {
      85                 :          0 :                         fm_port_close(dpaa_intf.port_handle);
      86                 :          0 :                         dpaa_intf.port_handle = NULL;
      87                 :            :                 }
      88                 :          0 :                 dpaa_intf.port_handle =
      89                 :          0 :                                 fm_port_open(&fm_model.fm_port_params[devid]);
      90                 :          0 :                 dpaa_intf.scheme_handle[0] = create_device(fm_info.pcd_handle,
      91                 :            :                                         fm_model.scheme_devid[devid][0]);
      92                 :          0 :                 dpaa_intf.scheme_count = 1;
      93         [ #  # ]:          0 :                 if (fm_model.scheme_devid[devid][1]) {
      94                 :          0 :                         dpaa_intf.scheme_handle[1] =
      95                 :          0 :                                 create_device(fm_info.pcd_handle,
      96                 :            :                                         fm_model.scheme_devid[devid][1]);
      97         [ #  # ]:          0 :                         if (dpaa_intf.scheme_handle[1])
      98                 :          0 :                                 dpaa_intf.scheme_count++;
      99                 :            :                 }
     100                 :            : 
     101                 :          0 :                 dpaa_intf.netenv_handle = create_device(fm_info.pcd_handle,
     102                 :            :                                         fm_model.netenv_devid[devid]);
     103                 :          0 :                 i++;
     104         [ #  # ]:          0 :                 if (!dpaa_intf.netenv_handle ||
     105         [ #  # ]:          0 :                         !dpaa_intf.scheme_handle[0] ||
     106         [ #  # ]:          0 :                         !dpaa_intf.port_handle)
     107                 :          0 :                         continue;
     108                 :            : 
     109         [ #  # ]:          0 :                 if (dpaa_fm_deconfig(&dpaa_intf, NULL))
     110                 :          0 :                         DPAA_PMD_ERR("DPAA FM deconfig failed");
     111                 :            :         }
     112                 :            : 
     113         [ #  # ]:          0 :         if (dpaa_fm_term())
     114                 :          0 :                 DPAA_PMD_ERR("DPAA FM term failed");
     115                 :            : 
     116                 :            :         memset(&fm_model, 0, sizeof(struct dpaa_fm_model));
     117                 :            : }
     118                 :            : 
     119                 :          0 : void dpaa_write_fm_config_to_file(void)
     120                 :            : {
     121                 :            :         size_t bytes_write;
     122                 :          0 :         FILE *fp = fopen(fm_log, "wb");
     123                 :          0 :         PMD_INIT_FUNC_TRACE();
     124                 :            : 
     125         [ #  # ]:          0 :         if (!fp) {
     126                 :          0 :                 DPAA_PMD_ERR("File open failed");
     127                 :          0 :                 return;
     128                 :            :         }
     129                 :          0 :         bytes_write = fwrite(&fm_model, sizeof(struct dpaa_fm_model), 1, fp);
     130         [ #  # ]:          0 :         if (!bytes_write) {
     131                 :          0 :                 DPAA_PMD_WARN("No bytes write");
     132                 :          0 :                 fclose(fp);
     133                 :          0 :                 return;
     134                 :            :         }
     135                 :          0 :         fclose(fp);
     136                 :            : }
     137                 :            : 
     138                 :          0 : static void dpaa_read_fm_config_from_file(void)
     139                 :            : {
     140                 :            :         size_t bytes_read;
     141                 :          0 :         FILE *fp = fopen(fm_log, "rb");
     142                 :          0 :         PMD_INIT_FUNC_TRACE();
     143                 :            : 
     144         [ #  # ]:          0 :         if (!fp)
     145                 :            :                 return;
     146                 :          0 :         DPAA_PMD_INFO("Previous DPDK-FM config instance present, cleaning up.");
     147                 :            : 
     148                 :            :         bytes_read = fread(&fm_model, sizeof(struct dpaa_fm_model), 1, fp);
     149         [ #  # ]:          0 :         if (!bytes_read) {
     150                 :          0 :                 DPAA_PMD_WARN("No bytes read");
     151                 :          0 :                 fclose(fp);
     152                 :          0 :                 return;
     153                 :            :         }
     154                 :          0 :         fclose(fp);
     155                 :            : 
     156                 :            :         /*FM cleanup from previous configured app */
     157                 :          0 :         fm_prev_cleanup();
     158                 :            : }
     159                 :            : 
     160                 :            : static inline int
     161                 :            : set_hash_params_eth(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
     162                 :            : {
     163                 :            :         int k;
     164                 :            : 
     165         [ #  # ]:          0 :         for (k = 0; k < 2; k++) {
     166                 :          0 :                 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
     167                 :            :                                                 e_IOC_FM_PCD_EXTRACT_BY_HDR;
     168                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
     169                 :            :                                                 HEADER_TYPE_ETH;
     170                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
     171                 :            :                                                 e_IOC_FM_PCD_HDR_INDEX_NONE;
     172                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).type =
     173                 :            :                                                 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
     174         [ #  # ]:          0 :                 if (k == 0)
     175                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).eth =
     176                 :            :                                                 IOC_NET_HF_ETH_SA;
     177                 :            :                 else
     178                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).eth =
     179                 :            :                                                 IOC_NET_HF_ETH_DA;
     180                 :          0 :                 hdr_idx++;
     181                 :            :         }
     182                 :            :         return hdr_idx;
     183                 :            : }
     184                 :            : 
     185                 :            : static inline int
     186                 :            : set_hash_params_ipv4(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
     187                 :            : {
     188                 :            :         int k;
     189                 :            : 
     190         [ #  # ]:          0 :         for (k = 0; k < 2; k++) {
     191                 :          0 :                 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
     192                 :            :                                                 e_IOC_FM_PCD_EXTRACT_BY_HDR;
     193                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
     194                 :            :                                                 HEADER_TYPE_IPV4;
     195                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
     196                 :            :                                                 e_IOC_FM_PCD_HDR_INDEX_NONE;
     197                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).type =
     198                 :            :                                                 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
     199         [ #  # ]:          0 :                 if (k == 0)
     200                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv4 =
     201                 :            :                                         ioc_net_hf_ipv_4_src_ip;
     202                 :            :                 else
     203                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv4 =
     204                 :            :                                         ioc_net_hf_ipv_4_dst_ip;
     205                 :          0 :                 hdr_idx++;
     206                 :            :         }
     207                 :            :         return hdr_idx;
     208                 :            : }
     209                 :            : 
     210                 :            : static inline int
     211                 :            : set_hash_params_ipv6(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
     212                 :            : {
     213                 :            :         int k;
     214                 :            : 
     215         [ #  # ]:          0 :         for (k = 0; k < 2; k++) {
     216                 :          0 :                 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
     217                 :            :                                                 e_IOC_FM_PCD_EXTRACT_BY_HDR;
     218                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
     219                 :            :                                                         HEADER_TYPE_IPV6;
     220                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
     221                 :            :                                                 e_IOC_FM_PCD_HDR_INDEX_NONE;
     222                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).type =
     223                 :            :                                                 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
     224         [ #  # ]:          0 :                 if (k == 0)
     225                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv6 =
     226                 :            :                                         ioc_net_hf_ipv_6_src_ip;
     227                 :            :                 else
     228                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).ipv6 =
     229                 :            :                                         ioc_net_hf_ipv_6_dst_ip;
     230                 :          0 :                 hdr_idx++;
     231                 :            :         }
     232                 :            :         return hdr_idx;
     233                 :            : }
     234                 :            : 
     235                 :            : static inline int
     236                 :            : set_hash_params_udp(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
     237                 :            : {
     238                 :            :         int k;
     239                 :            : 
     240         [ #  # ]:          0 :         for (k = 0; k < 2; k++) {
     241                 :          0 :                 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
     242                 :            :                                                 e_IOC_FM_PCD_EXTRACT_BY_HDR;
     243                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
     244                 :            :                                                 HEADER_TYPE_UDP;
     245                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
     246                 :            :                                                 e_IOC_FM_PCD_HDR_INDEX_NONE;
     247                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).type =
     248                 :            :                                                 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
     249         [ #  # ]:          0 :                 if (k == 0)
     250                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).udp =
     251                 :            :                                         IOC_NET_HF_UDP_PORT_SRC;
     252                 :            :                 else
     253                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).udp =
     254                 :            :                                         IOC_NET_HF_UDP_PORT_DST;
     255                 :          0 :                 hdr_idx++;
     256                 :            :         }
     257                 :            :         return hdr_idx;
     258                 :            : }
     259                 :            : 
     260                 :            : static inline int
     261                 :            : set_hash_params_tcp(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
     262                 :            : {
     263                 :            :         int k;
     264                 :            : 
     265         [ #  # ]:          0 :         for (k = 0; k < 2; k++) {
     266                 :          0 :                 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
     267                 :            :                                                 e_IOC_FM_PCD_EXTRACT_BY_HDR;
     268                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
     269                 :            :                                                 HEADER_TYPE_TCP;
     270                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
     271                 :            :                                                 e_IOC_FM_PCD_HDR_INDEX_NONE;
     272                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).type =
     273                 :            :                                                 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
     274         [ #  # ]:          0 :                 if (k == 0)
     275                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).tcp =
     276                 :            :                                         IOC_NET_HF_TCP_PORT_SRC;
     277                 :            :                 else
     278                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).tcp =
     279                 :            :                                         IOC_NET_HF_TCP_PORT_DST;
     280                 :          0 :                 hdr_idx++;
     281                 :            :         }
     282                 :            :         return hdr_idx;
     283                 :            : }
     284                 :            : 
     285                 :            : static inline int
     286                 :            : set_hash_params_sctp(ioc_fm_pcd_kg_scheme_params_t *scheme_params, int hdr_idx)
     287                 :            : {
     288                 :            :         int k;
     289                 :            : 
     290         [ #  # ]:          0 :         for (k = 0; k < 2; k++) {
     291                 :          0 :                 SCH_EXT_ARR(scheme_params, hdr_idx)->type =
     292                 :            :                                                 e_IOC_FM_PCD_EXTRACT_BY_HDR;
     293                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr =
     294                 :            :                                                 HEADER_TYPE_SCTP;
     295                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).hdr_index =
     296                 :            :                                                 e_IOC_FM_PCD_HDR_INDEX_NONE;
     297                 :          0 :                 SCH_EXT_HDR(scheme_params, hdr_idx).type =
     298                 :            :                                                 e_IOC_FM_PCD_EXTRACT_FULL_FIELD;
     299         [ #  # ]:          0 :                 if (k == 0)
     300                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).sctp =
     301                 :            :                                         IOC_NET_HF_SCTP_PORT_SRC;
     302                 :            :                 else
     303                 :          0 :                         SCH_EXT_FULL_FLD(scheme_params, hdr_idx).sctp =
     304                 :            :                                         IOC_NET_HF_SCTP_PORT_DST;
     305                 :          0 :                 hdr_idx++;
     306                 :            :         }
     307                 :            :         return hdr_idx;
     308                 :            : }
     309                 :            : 
     310                 :            : /* Set scheme params for hash distribution */
     311                 :          0 : static int set_scheme_params(ioc_fm_pcd_kg_scheme_params_t *scheme_params,
     312                 :            :         ioc_fm_pcd_net_env_params_t *dist_units,
     313                 :            :         struct dpaa_if *dpaa_intf,
     314                 :            :         struct fman_if *fif)
     315                 :            : {
     316                 :            :         int dist_idx, hdr_idx = 0;
     317                 :          0 :         PMD_INIT_FUNC_TRACE();
     318                 :            : 
     319         [ #  # ]:          0 :         if (fif->num_profiles) {
     320                 :          0 :                 scheme_params->param.override_storage_profile = true;
     321                 :          0 :                 scheme_params->param.storage_profile.direct = true;
     322                 :            :                 scheme_params->param.storage_profile.profile_select
     323                 :          0 :                         .direct_relative_profile_id = fm_default_vsp_id(fif);
     324                 :            :         }
     325                 :            : 
     326                 :          0 :         scheme_params->param.use_hash = 1;
     327                 :          0 :         scheme_params->param.modify = false;
     328                 :          0 :         scheme_params->param.always_direct = false;
     329                 :          0 :         scheme_params->param.scheme_counter.update = 1;
     330                 :          0 :         scheme_params->param.scheme_counter.value = 0;
     331                 :          0 :         scheme_params->param.next_engine = e_IOC_FM_PCD_DONE;
     332                 :          0 :         scheme_params->param.base_fqid = dpaa_intf->rx_queues[0].fqid;
     333                 :          0 :         scheme_params->param.net_env_params.net_env_id =
     334                 :          0 :                 dpaa_intf->netenv_handle;
     335                 :          0 :         scheme_params->param.net_env_params.num_of_distinction_units =
     336                 :          0 :                 dist_units->param.num_of_distinction_units;
     337                 :            : 
     338                 :          0 :         scheme_params->param.key_ext_and_hash.hash_dist_num_of_fqids =
     339                 :          0 :                         dpaa_intf->nb_rx_queues;
     340                 :          0 :         scheme_params->param.key_ext_and_hash.num_of_used_extracts =
     341                 :            :                         2 * dist_units->param.num_of_distinction_units;
     342                 :            : 
     343                 :          0 :         for (dist_idx = 0; dist_idx <
     344         [ #  # ]:          0 :                 dist_units->param.num_of_distinction_units;
     345                 :          0 :                 dist_idx++) {
     346   [ #  #  #  #  :          0 :                 switch (dist_units->param.units[dist_idx].hdrs[0].hdr) {
                #  #  # ]
     347                 :            :                 case HEADER_TYPE_ETH:
     348                 :            :                         hdr_idx = set_hash_params_eth(scheme_params, hdr_idx);
     349                 :            :                         break;
     350                 :            : 
     351                 :            :                 case HEADER_TYPE_IPV4:
     352                 :            :                         hdr_idx = set_hash_params_ipv4(scheme_params, hdr_idx);
     353                 :            :                         break;
     354                 :            : 
     355                 :            :                 case HEADER_TYPE_IPV6:
     356                 :            :                         hdr_idx = set_hash_params_ipv6(scheme_params, hdr_idx);
     357                 :            :                         break;
     358                 :            : 
     359                 :            :                 case HEADER_TYPE_UDP:
     360                 :            :                         hdr_idx = set_hash_params_udp(scheme_params, hdr_idx);
     361                 :            :                         break;
     362                 :            : 
     363                 :            :                 case HEADER_TYPE_TCP:
     364                 :            :                         hdr_idx = set_hash_params_tcp(scheme_params, hdr_idx);
     365                 :            :                         break;
     366                 :            : 
     367                 :            :                 case HEADER_TYPE_SCTP:
     368                 :            :                         hdr_idx = set_hash_params_sctp(scheme_params, hdr_idx);
     369                 :            :                         break;
     370                 :            : 
     371                 :          0 :                 default:
     372                 :          0 :                         DPAA_PMD_ERR("Invalid Distinction Unit");
     373                 :          0 :                         return -1;
     374                 :            :                 }
     375                 :            :         }
     376                 :            : 
     377                 :            :         return 0;
     378                 :            : }
     379                 :            : 
     380                 :          0 : static void set_dist_units(ioc_fm_pcd_net_env_params_t *dist_units,
     381                 :            :                            uint64_t req_dist_set)
     382                 :            : {
     383                 :            :         uint32_t loop = 0, dist_idx = 0, dist_field = 0;
     384                 :            :         int l2_configured = 0, ipv4_configured = 0, ipv6_configured = 0;
     385                 :            :         int udp_configured = 0, tcp_configured = 0, sctp_configured = 0;
     386                 :          0 :         PMD_INIT_FUNC_TRACE();
     387                 :            : 
     388         [ #  # ]:          0 :         if (!req_dist_set)
     389                 :          0 :                 dist_units->param.units[dist_idx++].hdrs[0].hdr =
     390                 :            :                         HEADER_TYPE_ETH;
     391                 :            : 
     392         [ #  # ]:          0 :         while (req_dist_set) {
     393         [ #  # ]:          0 :                 if (req_dist_set % 2 != 0) {
     394                 :          0 :                         dist_field = 1U << loop;
     395   [ #  #  #  #  :          0 :                         switch (dist_field) {
                #  #  # ]
     396                 :          0 :                         case RTE_ETH_RSS_L2_PAYLOAD:
     397                 :            : 
     398         [ #  # ]:          0 :                                 if (l2_configured)
     399                 :            :                                         break;
     400                 :            :                                 l2_configured = 1;
     401                 :            : 
     402                 :          0 :                                 dist_units->param.units[dist_idx++].hdrs[0].hdr
     403                 :          0 :                                         = HEADER_TYPE_ETH;
     404                 :          0 :                                 break;
     405                 :            : 
     406                 :          0 :                         case RTE_ETH_RSS_IPV4:
     407                 :            :                         case RTE_ETH_RSS_FRAG_IPV4:
     408                 :            :                         case RTE_ETH_RSS_NONFRAG_IPV4_OTHER:
     409                 :            : 
     410         [ #  # ]:          0 :                                 if (ipv4_configured)
     411                 :            :                                         break;
     412                 :            :                                 ipv4_configured = 1;
     413                 :          0 :                                 dist_units->param.units[dist_idx++].hdrs[0].hdr
     414                 :          0 :                                         = HEADER_TYPE_IPV4;
     415                 :          0 :                                 break;
     416                 :            : 
     417                 :          0 :                         case RTE_ETH_RSS_IPV6:
     418                 :            :                         case RTE_ETH_RSS_FRAG_IPV6:
     419                 :            :                         case RTE_ETH_RSS_NONFRAG_IPV6_OTHER:
     420                 :            :                         case RTE_ETH_RSS_IPV6_EX:
     421                 :            : 
     422         [ #  # ]:          0 :                                 if (ipv6_configured)
     423                 :            :                                         break;
     424                 :            :                                 ipv6_configured = 1;
     425                 :          0 :                                 dist_units->param.units[dist_idx++].hdrs[0].hdr
     426                 :          0 :                                         = HEADER_TYPE_IPV6;
     427                 :          0 :                                 break;
     428                 :            : 
     429                 :          0 :                         case RTE_ETH_RSS_NONFRAG_IPV4_TCP:
     430                 :            :                         case RTE_ETH_RSS_NONFRAG_IPV6_TCP:
     431                 :            :                         case RTE_ETH_RSS_IPV6_TCP_EX:
     432                 :            : 
     433         [ #  # ]:          0 :                                 if (tcp_configured)
     434                 :            :                                         break;
     435                 :            :                                 tcp_configured = 1;
     436                 :          0 :                                 dist_units->param.units[dist_idx++].hdrs[0].hdr
     437                 :          0 :                                         = HEADER_TYPE_TCP;
     438                 :          0 :                                 break;
     439                 :            : 
     440                 :          0 :                         case RTE_ETH_RSS_NONFRAG_IPV4_UDP:
     441                 :            :                         case RTE_ETH_RSS_NONFRAG_IPV6_UDP:
     442                 :            :                         case RTE_ETH_RSS_IPV6_UDP_EX:
     443                 :            : 
     444         [ #  # ]:          0 :                                 if (udp_configured)
     445                 :            :                                         break;
     446                 :            :                                 udp_configured = 1;
     447                 :          0 :                                 dist_units->param.units[dist_idx++].hdrs[0].hdr
     448                 :          0 :                                         = HEADER_TYPE_UDP;
     449                 :          0 :                                 break;
     450                 :            : 
     451                 :          0 :                         case RTE_ETH_RSS_NONFRAG_IPV4_SCTP:
     452                 :            :                         case RTE_ETH_RSS_NONFRAG_IPV6_SCTP:
     453                 :            : 
     454         [ #  # ]:          0 :                                 if (sctp_configured)
     455                 :            :                                         break;
     456                 :            :                                 sctp_configured = 1;
     457                 :            : 
     458                 :          0 :                                 dist_units->param.units[dist_idx++].hdrs[0].hdr
     459                 :          0 :                                         = HEADER_TYPE_SCTP;
     460                 :          0 :                                 break;
     461                 :            : 
     462                 :          0 :                         default:
     463                 :          0 :                                 DPAA_PMD_ERR("Bad flow distribution option");
     464                 :            :                         }
     465                 :            :                 }
     466                 :          0 :                 req_dist_set = req_dist_set >> 1;
     467                 :          0 :                 loop++;
     468                 :            :         }
     469                 :            : 
     470                 :            :         /* Dist units is set to dist_idx */
     471                 :          0 :         dist_units->param.num_of_distinction_units = dist_idx;
     472                 :          0 : }
     473                 :            : 
     474                 :            : /* Apply PCD configuration on interface */
     475                 :          0 : static inline int set_port_pcd(struct dpaa_if *dpaa_intf)
     476                 :            : {
     477                 :            :         int ret = 0;
     478                 :            :         unsigned int idx;
     479                 :            :         ioc_fm_port_pcd_params_t pcd_param;
     480                 :            :         ioc_fm_port_pcd_prs_params_t prs_param;
     481                 :            :         ioc_fm_port_pcd_kg_params_t  kg_param;
     482                 :            : 
     483                 :          0 :         PMD_INIT_FUNC_TRACE();
     484                 :            : 
     485                 :            :         /* PCD support for hash distribution */
     486                 :            :         uint8_t pcd_support = e_FM_PORT_PCD_SUPPORT_PRS_AND_KG;
     487                 :            : 
     488                 :            :         memset(&pcd_param, 0, sizeof(pcd_param));
     489                 :            :         memset(&prs_param, 0, sizeof(prs_param));
     490                 :            :         memset(&kg_param, 0, sizeof(kg_param));
     491                 :            : 
     492                 :            :         /* Set parse params */
     493                 :          0 :         prs_param.first_prs_hdr = HEADER_TYPE_ETH;
     494                 :            : 
     495                 :            :         /* Set kg params */
     496         [ #  # ]:          0 :         for (idx = 0; idx < dpaa_intf->scheme_count; idx++)
     497                 :          0 :                 kg_param.scheme_ids[idx] = dpaa_intf->scheme_handle[idx];
     498                 :          0 :         kg_param.num_schemes = dpaa_intf->scheme_count;
     499                 :            : 
     500                 :            :         /* Set pcd params */
     501                 :          0 :         pcd_param.net_env_id = dpaa_intf->netenv_handle;
     502                 :          0 :         pcd_param.pcd_support = pcd_support;
     503                 :          0 :         pcd_param.p_kg_params = &kg_param;
     504                 :          0 :         pcd_param.p_prs_params = &prs_param;
     505                 :            : 
     506                 :            :         /* FM PORT Disable */
     507                 :          0 :         ret = fm_port_disable(dpaa_intf->port_handle);
     508         [ #  # ]:          0 :         if (ret != E_OK) {
     509                 :          0 :                 DPAA_PMD_ERR("fm_port_disable: Failed");
     510                 :          0 :                 return ret;
     511                 :            :         }
     512                 :            : 
     513                 :            :         /* FM PORT SetPCD */
     514                 :          0 :         ret = fm_port_set_pcd(dpaa_intf->port_handle, &pcd_param);
     515         [ #  # ]:          0 :         if (ret != E_OK) {
     516                 :          0 :                 DPAA_PMD_ERR("fm_port_set_pcd: Failed");
     517                 :          0 :                 return ret;
     518                 :            :         }
     519                 :            : 
     520                 :            :         /* FM PORT Enable */
     521                 :          0 :         ret = fm_port_enable(dpaa_intf->port_handle);
     522         [ #  # ]:          0 :         if (ret != E_OK) {
     523                 :          0 :                 DPAA_PMD_ERR("fm_port_enable: Failed");
     524                 :          0 :                 goto fm_port_delete_pcd;
     525                 :            :         }
     526                 :            : 
     527                 :            :         return 0;
     528                 :            : 
     529                 :            : fm_port_delete_pcd:
     530                 :            :         /* FM PORT DeletePCD */
     531                 :          0 :         ret = fm_port_delete_pcd(dpaa_intf->port_handle);
     532         [ #  # ]:          0 :         if (ret != E_OK) {
     533                 :          0 :                 DPAA_PMD_ERR("fm_port_delete_pcd: Failed");
     534                 :          0 :                 return ret;
     535                 :            :         }
     536                 :            :         return -1;
     537                 :            : }
     538                 :            : 
     539                 :            : /* Unset PCD NerEnv and scheme */
     540                 :          0 : static inline void unset_pcd_netenv_scheme(struct dpaa_if *dpaa_intf)
     541                 :            : {
     542                 :            :         int ret;
     543                 :          0 :         PMD_INIT_FUNC_TRACE();
     544                 :            : 
     545                 :            :         /* reduce scheme count */
     546         [ #  # ]:          0 :         if (dpaa_intf->scheme_count)
     547                 :          0 :                 dpaa_intf->scheme_count--;
     548                 :            : 
     549                 :          0 :         DPAA_PMD_DEBUG("KG SCHEME DEL %d handle =%p",
     550                 :            :                 dpaa_intf->scheme_count,
     551                 :            :                 dpaa_intf->scheme_handle[dpaa_intf->scheme_count]);
     552                 :            : 
     553                 :          0 :         ret = fm_pcd_kg_scheme_delete(dpaa_intf->scheme_handle
     554                 :          0 :                                         [dpaa_intf->scheme_count]);
     555         [ #  # ]:          0 :         if (ret != E_OK)
     556                 :          0 :                 DPAA_PMD_ERR("fm_pcd_kg_scheme_delete: Failed");
     557                 :            : 
     558                 :          0 :         dpaa_intf->scheme_handle[dpaa_intf->scheme_count] = NULL;
     559                 :          0 : }
     560                 :            : 
     561                 :            : /* Set PCD NetEnv and Scheme and default scheme */
     562                 :          0 : static inline int set_default_scheme(struct dpaa_if *dpaa_intf)
     563                 :            : {
     564                 :            :         ioc_fm_pcd_kg_scheme_params_t scheme_params;
     565                 :          0 :         int idx = dpaa_intf->scheme_count;
     566                 :          0 :         PMD_INIT_FUNC_TRACE();
     567                 :            : 
     568                 :            :         /* Set PCD NetEnvCharacteristics */
     569                 :            :         memset(&scheme_params, 0, sizeof(scheme_params));
     570                 :            : 
     571                 :            :         /* Adding 10 to default schemes as the number of interface would be
     572                 :            :          * lesser than 10 and the relative scheme ids should be unique for
     573                 :            :          * every scheme.
     574                 :            :          */
     575                 :          0 :         scheme_params.param.scm_id.relative_scheme_id =
     576                 :          0 :                 10 + dpaa_intf->ifid;
     577                 :            :         scheme_params.param.use_hash = 0;
     578                 :          0 :         scheme_params.param.next_engine = e_IOC_FM_PCD_DONE;
     579                 :            :         scheme_params.param.net_env_params.num_of_distinction_units = 0;
     580                 :          0 :         scheme_params.param.net_env_params.net_env_id =
     581                 :          0 :                 dpaa_intf->netenv_handle;
     582                 :          0 :         scheme_params.param.base_fqid = dpaa_intf->rx_queues[0].fqid;
     583                 :          0 :         scheme_params.param.key_ext_and_hash.hash_dist_num_of_fqids = 1;
     584                 :            :         scheme_params.param.key_ext_and_hash.num_of_used_extracts = 0;
     585                 :            :         scheme_params.param.modify = false;
     586                 :            :         scheme_params.param.always_direct = false;
     587                 :          0 :         scheme_params.param.scheme_counter.update = 1;
     588                 :            :         scheme_params.param.scheme_counter.value = 0;
     589                 :            : 
     590                 :            :         /* FM PCD KgSchemeSet */
     591                 :          0 :         dpaa_intf->scheme_handle[idx] =
     592                 :          0 :                 fm_pcd_kg_scheme_set(fm_info.pcd_handle, &scheme_params);
     593                 :          0 :         DPAA_PMD_DEBUG("KG SCHEME SET %d handle =%p",
     594                 :            :                 idx, dpaa_intf->scheme_handle[idx]);
     595         [ #  # ]:          0 :         if (!dpaa_intf->scheme_handle[idx]) {
     596                 :          0 :                 DPAA_PMD_ERR("fm_pcd_kg_scheme_set: Failed");
     597                 :          0 :                 return -1;
     598                 :            :         }
     599                 :            : 
     600                 :          0 :         fm_model.scheme_devid[dpaa_intf->ifid][idx] =
     601                 :          0 :                                 get_device_id(dpaa_intf->scheme_handle[idx]);
     602                 :          0 :         dpaa_intf->scheme_count++;
     603                 :          0 :         return 0;
     604                 :            : }
     605                 :            : 
     606                 :            : 
     607                 :            : /* Set PCD NetEnv and Scheme and default scheme */
     608                 :          0 : static inline int set_pcd_netenv_scheme(struct dpaa_if *dpaa_intf,
     609                 :            :                                         uint64_t req_dist_set,
     610                 :            :                                         struct fman_if *fif)
     611                 :            : {
     612                 :            :         int ret = -1;
     613                 :            :         ioc_fm_pcd_net_env_params_t dist_units;
     614                 :            :         ioc_fm_pcd_kg_scheme_params_t scheme_params;
     615                 :          0 :         int idx = dpaa_intf->scheme_count;
     616                 :          0 :         PMD_INIT_FUNC_TRACE();
     617                 :            : 
     618                 :            :         /* Set PCD NetEnvCharacteristics */
     619                 :            :         memset(&dist_units, 0, sizeof(dist_units));
     620                 :            :         memset(&scheme_params, 0, sizeof(scheme_params));
     621                 :            : 
     622                 :            :         /* Set dist unit header type */
     623                 :          0 :         set_dist_units(&dist_units, req_dist_set);
     624                 :            : 
     625                 :          0 :         scheme_params.param.scm_id.relative_scheme_id = dpaa_intf->ifid;
     626                 :            : 
     627                 :            :         /* Set PCD Scheme params */
     628                 :          0 :         ret = set_scheme_params(&scheme_params, &dist_units, dpaa_intf, fif);
     629         [ #  # ]:          0 :         if (ret) {
     630                 :          0 :                 DPAA_PMD_ERR("Set scheme params: Failed");
     631                 :          0 :                 return -1;
     632                 :            :         }
     633                 :            : 
     634                 :            :         /* FM PCD KgSchemeSet */
     635                 :          0 :         dpaa_intf->scheme_handle[idx] =
     636                 :          0 :                 fm_pcd_kg_scheme_set(fm_info.pcd_handle, &scheme_params);
     637                 :          0 :         DPAA_PMD_DEBUG("KG SCHEME SET %d handle =%p",
     638                 :            :                         idx, dpaa_intf->scheme_handle[idx]);
     639         [ #  # ]:          0 :         if (!dpaa_intf->scheme_handle[idx]) {
     640                 :          0 :                 DPAA_PMD_ERR("fm_pcd_kg_scheme_set: Failed");
     641                 :          0 :                 return -1;
     642                 :            :         }
     643                 :            : 
     644                 :          0 :         fm_model.scheme_devid[dpaa_intf->ifid][idx] =
     645                 :          0 :                                 get_device_id(dpaa_intf->scheme_handle[idx]);
     646                 :          0 :         dpaa_intf->scheme_count++;
     647                 :          0 :         return 0;
     648                 :            : }
     649                 :            : 
     650                 :            : 
     651                 :          0 : static inline int get_rx_port_type(struct fman_if *fif)
     652                 :            : {
     653                 :            :         /* For onic ports, configure the VSP as offline ports so that
     654                 :            :          * kernel can configure correct port.
     655                 :            :          */
     656         [ #  # ]:          0 :         if (fif->mac_type == fman_offline_internal ||
     657                 :            :             fif->mac_type == fman_onic)
     658                 :            :                 return e_FM_PORT_TYPE_OH_OFFLINE_PARSING;
     659                 :            :         /* For 1G fm-mac9 and fm-mac10 ports, configure the VSP as 10G
     660                 :            :          * ports so that kernel can configure correct port.
     661                 :            :          */
     662         [ #  # ]:          0 :         else if (fif->mac_type == fman_mac_1g &&
     663         [ #  # ]:          0 :                 fif->mac_idx >= DPAA_10G_MAC_START_IDX)
     664                 :            :                 return e_FM_PORT_TYPE_RX_10G;
     665         [ #  # ]:          0 :         else if (fif->mac_type == fman_mac_1g)
     666                 :            :                 return e_FM_PORT_TYPE_RX;
     667         [ #  # ]:          0 :         else if (fif->mac_type == fman_mac_2_5g)
     668                 :            :                 return e_FM_PORT_TYPE_RX_2_5G;
     669         [ #  # ]:          0 :         else if (fif->mac_type == fman_mac_10g)
     670                 :            :                 return e_FM_PORT_TYPE_RX_10G;
     671                 :            : 
     672                 :          0 :         DPAA_PMD_ERR("MAC type unsupported");
     673                 :          0 :         return e_FM_PORT_TYPE_DUMMY;
     674                 :            : }
     675                 :            : 
     676                 :          0 : static inline int set_fm_port_handle(struct dpaa_if *dpaa_intf,
     677                 :            :                                      uint64_t req_dist_set,
     678                 :            :                                      struct fman_if *fif)
     679                 :            : {
     680                 :            :         t_fm_port_params        fm_port_params;
     681                 :            :         ioc_fm_pcd_net_env_params_t dist_units;
     682                 :          0 :         PMD_INIT_FUNC_TRACE();
     683                 :            : 
     684                 :            :         /* Memset FM port params */
     685                 :            :         memset(&fm_port_params, 0, sizeof(fm_port_params));
     686                 :            : 
     687                 :            :         /* Set FM port params */
     688                 :          0 :         fm_port_params.h_fm = fm_info.fman_handle;
     689                 :          0 :         fm_port_params.port_type = get_rx_port_type(fif);
     690                 :          0 :         fm_port_params.port_id = mac_idx[fif->mac_idx];
     691                 :            : 
     692                 :            :         /* FM PORT Open */
     693                 :          0 :         dpaa_intf->port_handle = fm_port_open(&fm_port_params);
     694         [ #  # ]:          0 :         if (!dpaa_intf->port_handle) {
     695                 :          0 :                 DPAA_PMD_ERR("fm_port_open: Failed");
     696                 :          0 :                 return -1;
     697                 :            :         }
     698                 :            : 
     699                 :          0 :         fm_model.fm_port_params[dpaa_intf->ifid] = fm_port_params;
     700                 :            : 
     701                 :            :         /* Set PCD NetEnvCharacteristics */
     702                 :            :         memset(&dist_units, 0, sizeof(dist_units));
     703                 :            : 
     704                 :            :         /* Set dist unit header type */
     705                 :          0 :         set_dist_units(&dist_units, req_dist_set);
     706                 :            : 
     707                 :            :         /* FM PCD NetEnvCharacteristicsSet */
     708                 :          0 :         dpaa_intf->netenv_handle =
     709                 :          0 :                 fm_pcd_net_env_characteristics_set(fm_info.pcd_handle,
     710                 :            :                                                         &dist_units);
     711         [ #  # ]:          0 :         if (!dpaa_intf->netenv_handle) {
     712                 :          0 :                 DPAA_PMD_ERR("fm_pcd_net_env_characteristics_set: Failed");
     713                 :          0 :                 return -1;
     714                 :            :         }
     715                 :            : 
     716                 :          0 :         fm_model.netenv_devid[dpaa_intf->ifid] =
     717                 :          0 :                                 get_device_id(dpaa_intf->netenv_handle);
     718                 :            : 
     719                 :          0 :         return 0;
     720                 :            : }
     721                 :            : 
     722                 :            : /* De-Configure DPAA FM */
     723                 :          0 : int dpaa_fm_deconfig(struct dpaa_if *dpaa_intf,
     724                 :            :                         struct fman_if *fif __rte_unused)
     725                 :            : {
     726                 :            :         int ret;
     727                 :            :         unsigned int idx;
     728                 :            : 
     729                 :          0 :         PMD_INIT_FUNC_TRACE();
     730                 :            : 
     731                 :            :         /* FM PORT Disable */
     732                 :          0 :         ret = fm_port_disable(dpaa_intf->port_handle);
     733         [ #  # ]:          0 :         if (ret != E_OK) {
     734                 :          0 :                 DPAA_PMD_ERR("fm_port_disable: Failed");
     735                 :          0 :                 return ret;
     736                 :            :         }
     737                 :            : 
     738                 :            :         /* FM PORT DeletePCD */
     739                 :          0 :         ret = fm_port_delete_pcd(dpaa_intf->port_handle);
     740         [ #  # ]:          0 :         if (ret != E_OK) {
     741                 :          0 :                 DPAA_PMD_ERR("fm_port_delete_pcd: Failed");
     742                 :          0 :                 return ret;
     743                 :            :         }
     744                 :            : 
     745         [ #  # ]:          0 :         for (idx = 0; idx < dpaa_intf->scheme_count; idx++) {
     746                 :          0 :                 DPAA_PMD_DEBUG("KG SCHEME DEL %d, handle =%p",
     747                 :            :                         idx, dpaa_intf->scheme_handle[idx]);
     748                 :            :                 /* FM PCD KgSchemeDelete */
     749                 :          0 :                 ret = fm_pcd_kg_scheme_delete(dpaa_intf->scheme_handle[idx]);
     750         [ #  # ]:          0 :                 if (ret != E_OK) {
     751                 :          0 :                         DPAA_PMD_ERR("fm_pcd_kg_scheme_delete: Failed");
     752                 :          0 :                         return ret;
     753                 :            :                 }
     754                 :          0 :                 dpaa_intf->scheme_handle[idx] = NULL;
     755                 :            :         }
     756                 :            :         /* FM PCD NetEnvCharacteristicsDelete */
     757                 :          0 :         ret = fm_pcd_net_env_characteristics_delete(dpaa_intf->netenv_handle);
     758         [ #  # ]:          0 :         if (ret != E_OK) {
     759                 :          0 :                 DPAA_PMD_ERR("fm_pcd_net_env_characteristics_delete: Failed");
     760                 :          0 :                 return ret;
     761                 :            :         }
     762                 :          0 :         dpaa_intf->netenv_handle = NULL;
     763                 :            : 
     764   [ #  #  #  # ]:          0 :         if (fif && fif->is_shared_mac) {
     765                 :          0 :                 ret = fm_port_enable(dpaa_intf->port_handle);
     766         [ #  # ]:          0 :                 if (ret != E_OK) {
     767                 :          0 :                         DPAA_PMD_ERR("shared mac re-enable failed");
     768                 :          0 :                         return ret;
     769                 :            :                 }
     770                 :            :         }
     771                 :            : 
     772                 :            :         /* FM PORT Close */
     773                 :          0 :         fm_port_close(dpaa_intf->port_handle);
     774                 :          0 :         dpaa_intf->port_handle = NULL;
     775                 :            : 
     776                 :            :         /* Set scheme count to 0 */
     777                 :          0 :         dpaa_intf->scheme_count = 0;
     778                 :            : 
     779                 :          0 :         return 0;
     780                 :            : }
     781                 :            : 
     782                 :          0 : int dpaa_fm_config(struct rte_eth_dev *dev, uint64_t req_dist_set)
     783                 :            : {
     784                 :          0 :         struct dpaa_if *dpaa_intf = dev->data->dev_private;
     785                 :          0 :         struct fman_if *fif = dev->process_private;
     786                 :            :         int ret;
     787                 :            :         unsigned int i = 0;
     788                 :          0 :         PMD_INIT_FUNC_TRACE();
     789                 :            : 
     790         [ #  # ]:          0 :         if (dpaa_intf->port_handle) {
     791         [ #  # ]:          0 :                 if (dpaa_fm_deconfig(dpaa_intf, fif))
     792                 :          0 :                         DPAA_PMD_ERR("DPAA FM deconfig failed");
     793                 :            :         }
     794                 :            : 
     795         [ #  # ]:          0 :         if (!dev->data->nb_rx_queues)
     796                 :            :                 return 0;
     797                 :            : 
     798         [ #  # ]:          0 :         if (dev->data->nb_rx_queues & (dev->data->nb_rx_queues - 1)) {
     799                 :          0 :                 DPAA_PMD_ERR("No of queues should be power of 2");
     800                 :          0 :                 return -1;
     801                 :            :         }
     802                 :            : 
     803                 :            :         /* Open FM Port and set it in port info */
     804                 :          0 :         ret = set_fm_port_handle(dpaa_intf, req_dist_set, fif);
     805         [ #  # ]:          0 :         if (ret) {
     806                 :          0 :                 DPAA_PMD_ERR("Set FM Port handle: Failed");
     807                 :          0 :                 return -1;
     808                 :            :         }
     809                 :            : 
     810         [ #  # ]:          0 :         if (fif->num_profiles) {
     811         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++)
     812                 :          0 :                         dpaa_intf->rx_queues[i].vsp_id =
     813                 :          0 :                                 fm_default_vsp_id(fif);
     814                 :            : 
     815                 :            :                 i = 0;
     816                 :            :         }
     817                 :            : 
     818                 :            :         /* Set PCD netenv and scheme */
     819         [ #  # ]:          0 :         if (req_dist_set) {
     820                 :          0 :                 ret = set_pcd_netenv_scheme(dpaa_intf, req_dist_set, fif);
     821         [ #  # ]:          0 :                 if (ret) {
     822                 :          0 :                         DPAA_PMD_ERR("Set PCD NetEnv and Scheme dist: Failed");
     823                 :          0 :                         goto unset_fm_port_handle;
     824                 :            :                 }
     825                 :            :         }
     826                 :            :         /* Set default netenv and scheme */
     827         [ #  # ]:          0 :         if (!fif->is_shared_mac) {
     828                 :          0 :                 ret = set_default_scheme(dpaa_intf);
     829         [ #  # ]:          0 :                 if (ret) {
     830                 :          0 :                         DPAA_PMD_ERR("Set PCD NetEnv and Scheme: Failed");
     831                 :          0 :                         goto unset_pcd_netenv_scheme1;
     832                 :            :                 }
     833                 :            :         }
     834                 :            : 
     835                 :            :         /* Set Port PCD */
     836                 :          0 :         ret = set_port_pcd(dpaa_intf);
     837         [ #  # ]:          0 :         if (ret) {
     838                 :          0 :                 DPAA_PMD_ERR("Set Port PCD: Failed");
     839                 :          0 :                 goto unset_pcd_netenv_scheme;
     840                 :            :         }
     841                 :            : 
     842         [ #  # ]:          0 :         for (; i < fm_model.dev_count; i++)
     843         [ #  # ]:          0 :                 if (fm_model.device_order[i] == dpaa_intf->ifid)
     844                 :            :                         return 0;
     845                 :            : 
     846                 :          0 :         fm_model.device_order[fm_model.dev_count] = dpaa_intf->ifid;
     847                 :          0 :         fm_model.dev_count++;
     848                 :            : 
     849                 :          0 :         return 0;
     850                 :            : 
     851                 :            : unset_pcd_netenv_scheme:
     852                 :          0 :         unset_pcd_netenv_scheme(dpaa_intf);
     853                 :            : 
     854                 :          0 : unset_pcd_netenv_scheme1:
     855                 :          0 :         unset_pcd_netenv_scheme(dpaa_intf);
     856                 :            : 
     857                 :          0 : unset_fm_port_handle:
     858                 :            :         /* FM PORT Close */
     859                 :          0 :         fm_port_close(dpaa_intf->port_handle);
     860                 :          0 :         dpaa_intf->port_handle = NULL;
     861                 :          0 :         return -1;
     862                 :            : }
     863                 :            : 
     864                 :          0 : int dpaa_fm_init(void)
     865                 :            : {
     866                 :            :         t_handle fman_handle;
     867                 :            :         t_handle pcd_handle;
     868                 :          0 :         t_fm_pcd_params fm_pcd_params = {0};
     869                 :            :         /* Hard-coded : fman id 0 since one fman is present in LS104x */
     870                 :            :         int fman_id = 0, ret;
     871                 :          0 :         PMD_INIT_FUNC_TRACE();
     872                 :            : 
     873                 :          0 :         dpaa_read_fm_config_from_file();
     874                 :            : 
     875                 :            :         /* FM Open */
     876                 :          0 :         fman_handle = fm_open(fman_id);
     877         [ #  # ]:          0 :         if (!fman_handle) {
     878                 :          0 :                 DPAA_PMD_ERR("fm_open: Failed");
     879                 :          0 :                 return -1;
     880                 :            :         }
     881                 :            : 
     882                 :            :         /* FM PCD Open */
     883                 :          0 :         fm_pcd_params.h_fm = fman_handle;
     884                 :          0 :         fm_pcd_params.prs_support = true;
     885                 :          0 :         fm_pcd_params.kg_support = true;
     886                 :          0 :         pcd_handle = fm_pcd_open(&fm_pcd_params);
     887         [ #  # ]:          0 :         if (!pcd_handle) {
     888                 :          0 :                 fm_close(fman_handle);
     889                 :          0 :                 DPAA_PMD_ERR("fm_pcd_open: Failed");
     890                 :          0 :                 return -1;
     891                 :            :         }
     892                 :            : 
     893                 :            :         /* FM PCD Enable */
     894                 :          0 :         ret = fm_pcd_enable(pcd_handle);
     895         [ #  # ]:          0 :         if (ret) {
     896                 :          0 :                 DPAA_PMD_ERR("fm_pcd_enable: Failed");
     897                 :          0 :                 fm_pcd_close(pcd_handle);
     898                 :          0 :                 fm_close(fman_handle);
     899                 :          0 :                 return -1;
     900                 :            :         }
     901                 :            : 
     902                 :            :         /* Set fman and pcd handle in fm info */
     903                 :          0 :         fm_info.fman_handle = fman_handle;
     904                 :          0 :         fm_info.pcd_handle = pcd_handle;
     905                 :            : 
     906                 :          0 :         return 0;
     907                 :            : }
     908                 :            : 
     909                 :            : 
     910                 :            : /* De-initialization of FM */
     911                 :          0 : int dpaa_fm_term(void)
     912                 :            : {
     913                 :            :         int ret;
     914                 :            : 
     915                 :          0 :         PMD_INIT_FUNC_TRACE();
     916                 :            : 
     917   [ #  #  #  # ]:          0 :         if (fm_info.pcd_handle && fm_info.fman_handle) {
     918                 :            :                 /* FM PCD Disable */
     919                 :          0 :                 ret = fm_pcd_disable(fm_info.pcd_handle);
     920         [ #  # ]:          0 :                 if (ret) {
     921                 :          0 :                         DPAA_PMD_ERR("fm_pcd_disable: Failed");
     922                 :          0 :                         return -1;
     923                 :            :                 }
     924                 :            : 
     925                 :            :                 /* FM PCD Close */
     926                 :          0 :                 fm_pcd_close(fm_info.pcd_handle);
     927                 :          0 :                 fm_info.pcd_handle = NULL;
     928                 :            :         }
     929                 :            : 
     930         [ #  # ]:          0 :         if (fm_info.fman_handle) {
     931                 :            :                 /* FM Close */
     932                 :          0 :                 fm_close(fm_info.fman_handle);
     933                 :          0 :                 fm_info.fman_handle = NULL;
     934                 :            :         }
     935                 :            : 
     936         [ #  # ]:          0 :         if (access(fm_log, F_OK) != -1) {
     937                 :          0 :                 ret = remove(fm_log);
     938         [ #  # ]:          0 :                 if (ret)
     939                 :          0 :                         DPAA_PMD_ERR("File remove: Failed");
     940                 :            :         }
     941                 :            :         return 0;
     942                 :            : }
     943                 :            : 
     944                 :          0 : static int dpaa_port_vsp_configure(struct dpaa_if *dpaa_intf,
     945                 :            :                 uint8_t vsp_id, t_handle fman_handle,
     946                 :            :                 struct fman_if *fif, u32 mbuf_data_room_size)
     947                 :            : {
     948                 :            :         t_fm_vsp_params vsp_params;
     949                 :            :         t_fm_buffer_prefix_content buf_prefix_cont;
     950                 :          0 :         uint8_t idx = mac_idx[fif->mac_idx];
     951                 :            :         int ret;
     952                 :            : 
     953   [ #  #  #  # ]:          0 :         if (vsp_id == fif->base_profile_id && fif->is_shared_mac) {
     954                 :            :                 /* For shared interface, VSP of base
     955                 :            :                  * profile is default pool located in kernel.
     956                 :            :                  */
     957                 :          0 :                 dpaa_intf->vsp_bpid[vsp_id] = 0;
     958                 :          0 :                 return 0;
     959                 :            :         }
     960                 :            : 
     961         [ #  # ]:          0 :         if (vsp_id >= DPAA_VSP_PROFILE_MAX_NUM) {
     962                 :          0 :                 DPAA_PMD_ERR("VSP ID %d exceeds MAX number %d",
     963                 :            :                         vsp_id, DPAA_VSP_PROFILE_MAX_NUM);
     964                 :          0 :                 return -1;
     965                 :            :         }
     966                 :            : 
     967                 :            :         memset(&vsp_params, 0, sizeof(vsp_params));
     968                 :          0 :         vsp_params.h_fm = fman_handle;
     969                 :          0 :         vsp_params.relative_profile_id = vsp_id;
     970         [ #  # ]:          0 :         if (fif->mac_type == fman_offline_internal ||
     971                 :            :             fif->mac_type == fman_onic)
     972                 :          0 :                 vsp_params.port_params.port_id = fif->mac_idx;
     973                 :            :         else
     974                 :          0 :                 vsp_params.port_params.port_id = idx;
     975                 :            : 
     976                 :          0 :         vsp_params.port_params.port_type = get_rx_port_type(fif);
     977         [ #  # ]:          0 :         if (vsp_params.port_params.port_type == e_FM_PORT_TYPE_DUMMY) {
     978                 :          0 :                 DPAA_PMD_ERR("Mac type %d error", fif->mac_type);
     979                 :          0 :                 return -1;
     980                 :            :         }
     981                 :            : 
     982                 :          0 :         vsp_params.ext_buf_pools.num_of_pools_used = 1;
     983                 :          0 :         vsp_params.ext_buf_pools.ext_buf_pool[0].id = dpaa_intf->vsp_bpid[vsp_id];
     984                 :          0 :         vsp_params.ext_buf_pools.ext_buf_pool[0].size = mbuf_data_room_size;
     985                 :            : 
     986                 :          0 :         dpaa_intf->vsp_handle[vsp_id] = fm_vsp_config(&vsp_params);
     987         [ #  # ]:          0 :         if (!dpaa_intf->vsp_handle[vsp_id]) {
     988                 :          0 :                 DPAA_PMD_ERR("fm_vsp_config error for profile %d", vsp_id);
     989                 :          0 :                 return -EINVAL;
     990                 :            :         }
     991                 :            : 
     992                 :            :         /* configure the application buffer (structure, size and
     993                 :            :          * content)
     994                 :            :          */
     995                 :            : 
     996                 :            :         memset(&buf_prefix_cont, 0, sizeof(buf_prefix_cont));
     997                 :            : 
     998                 :          0 :         buf_prefix_cont.priv_data_size = 16;
     999                 :          0 :         buf_prefix_cont.data_align = 64;
    1000                 :          0 :         buf_prefix_cont.pass_prs_result = true;
    1001                 :          0 :         buf_prefix_cont.pass_time_stamp = true;
    1002                 :            :         buf_prefix_cont.pass_hash_result = false;
    1003                 :            :         buf_prefix_cont.pass_all_other_pcdinfo = false;
    1004                 :          0 :         buf_prefix_cont.manip_ext_space =
    1005                 :            :                 RTE_PKTMBUF_HEADROOM - DPAA_MBUF_HW_ANNOTATION;
    1006                 :            : 
    1007                 :          0 :         ret = fm_vsp_config_buffer_prefix_content(dpaa_intf->vsp_handle[vsp_id],
    1008                 :            :                                                &buf_prefix_cont);
    1009         [ #  # ]:          0 :         if (ret != E_OK) {
    1010                 :          0 :                 DPAA_PMD_ERR("fm_vsp_config_buffer_prefix_content error for profile %d err: %d",
    1011                 :            :                              vsp_id, ret);
    1012                 :          0 :                 return ret;
    1013                 :            :         }
    1014                 :            : 
    1015                 :            :         /* initialize the FM VSP module */
    1016                 :          0 :         ret = fm_vsp_init(dpaa_intf->vsp_handle[vsp_id]);
    1017         [ #  # ]:          0 :         if (ret != E_OK) {
    1018                 :          0 :                 DPAA_PMD_ERR("fm_vsp_init error for profile %d err:%d",
    1019                 :            :                          vsp_id, ret);
    1020                 :          0 :                 return ret;
    1021                 :            :         }
    1022                 :            : 
    1023                 :            :         return 0;
    1024                 :            : }
    1025                 :            : 
    1026                 :          0 : int dpaa_port_vsp_update(struct dpaa_if *dpaa_intf,
    1027                 :            :                 bool fmc_mode, uint8_t vsp_id, uint32_t bpid,
    1028                 :            :                 struct fman_if *fif, u32 mbuf_data_room_size)
    1029                 :            : {
    1030                 :            :         int ret = 0;
    1031                 :            :         t_handle fman_handle;
    1032                 :            : 
    1033         [ #  # ]:          0 :         if (!fif->num_profiles)
    1034                 :            :                 return 0;
    1035                 :            : 
    1036         [ #  # ]:          0 :         if (vsp_id >= fif->num_profiles)
    1037                 :            :                 return 0;
    1038                 :            : 
    1039         [ #  # ]:          0 :         if (dpaa_intf->vsp_bpid[vsp_id] == bpid)
    1040                 :            :                 return 0;
    1041                 :            : 
    1042         [ #  # ]:          0 :         if (dpaa_intf->vsp_handle[vsp_id]) {
    1043                 :          0 :                 ret = fm_vsp_free(dpaa_intf->vsp_handle[vsp_id]);
    1044         [ #  # ]:          0 :                 if (ret != E_OK) {
    1045                 :          0 :                         DPAA_PMD_ERR("Error fm_vsp_free: err %d vsp_handle[%d]",
    1046                 :            :                                      ret, vsp_id);
    1047                 :          0 :                         return ret;
    1048                 :            :                 }
    1049                 :          0 :                 dpaa_intf->vsp_handle[vsp_id] = 0;
    1050                 :            :         }
    1051                 :            : 
    1052         [ #  # ]:          0 :         if (fmc_mode)
    1053                 :          0 :                 fman_handle = fm_open(0);
    1054                 :            :         else
    1055                 :          0 :                 fman_handle = fm_info.fman_handle;
    1056                 :            : 
    1057                 :          0 :         dpaa_intf->vsp_bpid[vsp_id] = bpid;
    1058                 :            : 
    1059                 :          0 :         return dpaa_port_vsp_configure(dpaa_intf, vsp_id, fman_handle, fif,
    1060                 :            :                                        mbuf_data_room_size);
    1061                 :            : }
    1062                 :            : 
    1063                 :          0 : int dpaa_port_vsp_cleanup(struct dpaa_if *dpaa_intf, struct fman_if *fif)
    1064                 :            : {
    1065                 :            :         int idx, ret;
    1066                 :            : 
    1067         [ #  # ]:          0 :         for (idx = 0; idx < (uint8_t)fif->num_profiles; idx++) {
    1068         [ #  # ]:          0 :                 if (dpaa_intf->vsp_handle[idx]) {
    1069                 :          0 :                         ret = fm_vsp_free(dpaa_intf->vsp_handle[idx]);
    1070         [ #  # ]:          0 :                         if (ret != E_OK) {
    1071                 :          0 :                                 DPAA_PMD_ERR("Error fm_vsp_free: err %d"
    1072                 :            :                                              " vsp_handle[%d]", ret, idx);
    1073                 :          0 :                                 return ret;
    1074                 :            :                         }
    1075                 :            :                 }
    1076                 :            :         }
    1077                 :            : 
    1078                 :            :         return E_OK;
    1079                 :            : }

Generated by: LCOV version 1.14