4 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5 * Copyright (c) 2016 NXP. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_ethdev.h>
39 #include <rte_malloc.h>
40 #include <rte_memcpy.h>
41 #include <rte_string_fns.h>
42 #include <rte_cycles.h>
43 #include <rte_kvargs.h>
45 #include <rte_ethdev.h>
47 #include <fslmc_logs.h>
48 #include <dpaa2_hw_pvt.h>
50 #include "../dpaa2_ethdev.h"
53 dpaa2_distset_to_dpkg_profile_cfg(
54 uint32_t req_dist_set,
55 struct dpkg_profile_cfg *kg_cfg);
58 dpaa2_setup_flow_dist(struct rte_eth_dev *eth_dev,
59 uint32_t req_dist_set)
61 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
62 struct fsl_mc_io *dpni = priv->hw;
63 struct dpni_rx_tc_dist_cfg tc_cfg;
64 struct dpkg_profile_cfg kg_cfg;
66 int ret, tc_index = 0;
68 p_params = rte_malloc(
69 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
71 RTE_LOG(ERR, PMD, "Memory unavaialble\n");
74 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
75 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
77 dpaa2_distset_to_dpkg_profile_cfg(req_dist_set, &kg_cfg);
78 tc_cfg.key_cfg_iova = (uint64_t)(p_params);
79 tc_cfg.dist_size = eth_dev->data->nb_rx_queues;
80 tc_cfg.dist_mode = DPNI_DIST_MODE_HASH;
82 ret = dpni_prepare_key_cfg(&kg_cfg, p_params);
84 RTE_LOG(ERR, PMD, "Unable to prepare extract parameters\n");
89 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
93 RTE_LOG(ERR, PMD, "Setting distribution for Rx failed with"
94 " err code: %d\n", ret);
101 int dpaa2_remove_flow_dist(
102 struct rte_eth_dev *eth_dev,
105 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
106 struct fsl_mc_io *dpni = priv->hw;
107 struct dpni_rx_tc_dist_cfg tc_cfg;
108 struct dpkg_profile_cfg kg_cfg;
112 p_params = rte_malloc(
113 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
115 RTE_LOG(ERR, PMD, "Memory unavaialble\n");
118 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
119 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
121 tc_cfg.key_cfg_iova = (uint64_t)(p_params);
122 tc_cfg.dist_size = 0;
123 tc_cfg.dist_mode = DPNI_DIST_MODE_NONE;
125 ret = dpni_prepare_key_cfg(&kg_cfg, p_params);
127 RTE_LOG(ERR, PMD, "Unable to prepare extract parameters\n");
132 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
136 RTE_LOG(ERR, PMD, "Setting distribution for Rx failed with"
137 " err code: %d\n", ret);
144 dpaa2_distset_to_dpkg_profile_cfg(
145 uint32_t req_dist_set,
146 struct dpkg_profile_cfg *kg_cfg)
148 uint32_t loop = 0, i = 0, dist_field = 0;
149 int l2_configured = 0, l3_configured = 0;
150 int l4_configured = 0, sctp_configured = 0;
152 memset(kg_cfg, 0, sizeof(struct dpkg_profile_cfg));
153 while (req_dist_set) {
154 if (req_dist_set % 2 != 0) {
155 dist_field = 1U << loop;
156 switch (dist_field) {
157 case ETH_RSS_L2_PAYLOAD:
163 kg_cfg->extracts[i].extract.from_hdr.prot =
165 kg_cfg->extracts[i].extract.from_hdr.field =
167 kg_cfg->extracts[i].type =
168 DPKG_EXTRACT_FROM_HDR;
169 kg_cfg->extracts[i].extract.from_hdr.type =
175 case ETH_RSS_FRAG_IPV4:
176 case ETH_RSS_NONFRAG_IPV4_OTHER:
178 case ETH_RSS_FRAG_IPV6:
179 case ETH_RSS_NONFRAG_IPV6_OTHER:
180 case ETH_RSS_IPV6_EX:
186 kg_cfg->extracts[i].extract.from_hdr.prot =
188 kg_cfg->extracts[i].extract.from_hdr.field =
190 kg_cfg->extracts[i].type =
191 DPKG_EXTRACT_FROM_HDR;
192 kg_cfg->extracts[i].extract.from_hdr.type =
196 kg_cfg->extracts[i].extract.from_hdr.prot =
198 kg_cfg->extracts[i].extract.from_hdr.field =
200 kg_cfg->extracts[i].type =
201 DPKG_EXTRACT_FROM_HDR;
202 kg_cfg->extracts[i].extract.from_hdr.type =
206 kg_cfg->extracts[i].extract.from_hdr.prot =
208 kg_cfg->extracts[i].extract.from_hdr.field =
210 kg_cfg->extracts[i].type =
211 DPKG_EXTRACT_FROM_HDR;
212 kg_cfg->extracts[i].extract.from_hdr.type =
214 kg_cfg->num_extracts++;
218 case ETH_RSS_NONFRAG_IPV4_TCP:
219 case ETH_RSS_NONFRAG_IPV6_TCP:
220 case ETH_RSS_NONFRAG_IPV4_UDP:
221 case ETH_RSS_NONFRAG_IPV6_UDP:
222 case ETH_RSS_IPV6_TCP_EX:
223 case ETH_RSS_IPV6_UDP_EX:
229 kg_cfg->extracts[i].extract.from_hdr.prot =
231 kg_cfg->extracts[i].extract.from_hdr.field =
233 kg_cfg->extracts[i].type =
234 DPKG_EXTRACT_FROM_HDR;
235 kg_cfg->extracts[i].extract.from_hdr.type =
239 kg_cfg->extracts[i].extract.from_hdr.prot =
241 kg_cfg->extracts[i].extract.from_hdr.field =
243 kg_cfg->extracts[i].type =
244 DPKG_EXTRACT_FROM_HDR;
245 kg_cfg->extracts[i].extract.from_hdr.type =
250 case ETH_RSS_NONFRAG_IPV4_SCTP:
251 case ETH_RSS_NONFRAG_IPV6_SCTP:
257 kg_cfg->extracts[i].extract.from_hdr.prot =
259 kg_cfg->extracts[i].extract.from_hdr.field =
260 NH_FLD_SCTP_PORT_SRC;
261 kg_cfg->extracts[i].type =
262 DPKG_EXTRACT_FROM_HDR;
263 kg_cfg->extracts[i].extract.from_hdr.type =
267 kg_cfg->extracts[i].extract.from_hdr.prot =
269 kg_cfg->extracts[i].extract.from_hdr.field =
270 NH_FLD_SCTP_PORT_DST;
271 kg_cfg->extracts[i].type =
272 DPKG_EXTRACT_FROM_HDR;
273 kg_cfg->extracts[i].extract.from_hdr.type =
279 PMD_DRV_LOG(WARNING, "Bad flow distribution"
280 " option %x\n", dist_field);
283 req_dist_set = req_dist_set >> 1;
286 kg_cfg->num_extracts = i;