4 * Copyright (c) 2016 Freescale Semiconductor, Inc. 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>
46 #include <fslmc_logs.h>
47 #include <dpaa2_hw_pvt.h>
48 #include <dpaa2_hw_mempool.h>
50 #include "../dpaa2_ethdev.h"
53 dpaa2_distset_to_dpkg_profile_cfg(
54 uint64_t req_dist_set,
55 struct dpkg_profile_cfg *kg_cfg);
58 dpaa2_setup_flow_dist(struct rte_eth_dev *eth_dev,
59 uint64_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 PMD_INIT_LOG(ERR, "Memory unavailable");
74 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
75 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
77 ret = dpaa2_distset_to_dpkg_profile_cfg(req_dist_set, &kg_cfg);
79 PMD_INIT_LOG(ERR, "given rss_hf (%lx) not supported",
84 tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
85 tc_cfg.dist_size = eth_dev->data->nb_rx_queues;
86 tc_cfg.dist_mode = DPNI_DIST_MODE_HASH;
88 ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
90 PMD_INIT_LOG(ERR, "Unable to prepare extract parameters");
95 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
100 "Setting distribution for Rx failed with err: %d",
108 int dpaa2_remove_flow_dist(
109 struct rte_eth_dev *eth_dev,
112 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
113 struct fsl_mc_io *dpni = priv->hw;
114 struct dpni_rx_tc_dist_cfg tc_cfg;
115 struct dpkg_profile_cfg kg_cfg;
119 p_params = rte_malloc(
120 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
122 PMD_INIT_LOG(ERR, "Memory unavailable");
125 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
126 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
127 kg_cfg.num_extracts = 0;
128 tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
129 tc_cfg.dist_size = 0;
130 tc_cfg.dist_mode = DPNI_DIST_MODE_NONE;
132 ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
134 PMD_INIT_LOG(ERR, "Unable to prepare extract parameters");
139 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
144 "Setting distribution for Rx failed with err:%d",
150 dpaa2_distset_to_dpkg_profile_cfg(
151 uint64_t req_dist_set,
152 struct dpkg_profile_cfg *kg_cfg)
154 uint32_t loop = 0, i = 0, dist_field = 0;
155 int l2_configured = 0, l3_configured = 0;
156 int l4_configured = 0, sctp_configured = 0;
158 memset(kg_cfg, 0, sizeof(struct dpkg_profile_cfg));
159 while (req_dist_set) {
160 if (req_dist_set % 2 != 0) {
161 dist_field = 1U << loop;
162 switch (dist_field) {
163 case ETH_RSS_L2_PAYLOAD:
169 kg_cfg->extracts[i].extract.from_hdr.prot =
171 kg_cfg->extracts[i].extract.from_hdr.field =
173 kg_cfg->extracts[i].type =
174 DPKG_EXTRACT_FROM_HDR;
175 kg_cfg->extracts[i].extract.from_hdr.type =
181 case ETH_RSS_FRAG_IPV4:
182 case ETH_RSS_NONFRAG_IPV4_OTHER:
184 case ETH_RSS_FRAG_IPV6:
185 case ETH_RSS_NONFRAG_IPV6_OTHER:
186 case ETH_RSS_IPV6_EX:
192 kg_cfg->extracts[i].extract.from_hdr.prot =
194 kg_cfg->extracts[i].extract.from_hdr.field =
196 kg_cfg->extracts[i].type =
197 DPKG_EXTRACT_FROM_HDR;
198 kg_cfg->extracts[i].extract.from_hdr.type =
202 kg_cfg->extracts[i].extract.from_hdr.prot =
204 kg_cfg->extracts[i].extract.from_hdr.field =
206 kg_cfg->extracts[i].type =
207 DPKG_EXTRACT_FROM_HDR;
208 kg_cfg->extracts[i].extract.from_hdr.type =
212 kg_cfg->extracts[i].extract.from_hdr.prot =
214 kg_cfg->extracts[i].extract.from_hdr.field =
216 kg_cfg->extracts[i].type =
217 DPKG_EXTRACT_FROM_HDR;
218 kg_cfg->extracts[i].extract.from_hdr.type =
220 kg_cfg->num_extracts++;
224 case ETH_RSS_NONFRAG_IPV4_TCP:
225 case ETH_RSS_NONFRAG_IPV6_TCP:
226 case ETH_RSS_NONFRAG_IPV4_UDP:
227 case ETH_RSS_NONFRAG_IPV6_UDP:
228 case ETH_RSS_IPV6_TCP_EX:
229 case ETH_RSS_IPV6_UDP_EX:
235 kg_cfg->extracts[i].extract.from_hdr.prot =
237 kg_cfg->extracts[i].extract.from_hdr.field =
239 kg_cfg->extracts[i].type =
240 DPKG_EXTRACT_FROM_HDR;
241 kg_cfg->extracts[i].extract.from_hdr.type =
245 kg_cfg->extracts[i].extract.from_hdr.prot =
247 kg_cfg->extracts[i].extract.from_hdr.field =
249 kg_cfg->extracts[i].type =
250 DPKG_EXTRACT_FROM_HDR;
251 kg_cfg->extracts[i].extract.from_hdr.type =
256 case ETH_RSS_NONFRAG_IPV4_SCTP:
257 case ETH_RSS_NONFRAG_IPV6_SCTP:
263 kg_cfg->extracts[i].extract.from_hdr.prot =
265 kg_cfg->extracts[i].extract.from_hdr.field =
266 NH_FLD_SCTP_PORT_SRC;
267 kg_cfg->extracts[i].type =
268 DPKG_EXTRACT_FROM_HDR;
269 kg_cfg->extracts[i].extract.from_hdr.type =
273 kg_cfg->extracts[i].extract.from_hdr.prot =
275 kg_cfg->extracts[i].extract.from_hdr.field =
276 NH_FLD_SCTP_PORT_DST;
277 kg_cfg->extracts[i].type =
278 DPKG_EXTRACT_FROM_HDR;
279 kg_cfg->extracts[i].extract.from_hdr.type =
285 PMD_INIT_LOG(WARNING,
286 "Unsupported flow dist option %x",
291 req_dist_set = req_dist_set >> 1;
294 kg_cfg->num_extracts = i;
299 dpaa2_attach_bp_list(struct dpaa2_dev_priv *priv,
302 /* Function to attach a DPNI with a buffer pool list. Buffer pool list
303 * handle is passed in blist.
306 struct fsl_mc_io *dpni = priv->hw;
307 struct dpni_pools_cfg bpool_cfg;
308 struct dpaa2_bp_list *bp_list = (struct dpaa2_bp_list *)blist;
309 struct dpni_buffer_layout layout;
312 /* ... rx buffer layout .
313 * Check alignment for buffer layouts first
316 /* ... rx buffer layout ... */
317 tot_size = RTE_PKTMBUF_HEADROOM;
318 tot_size = RTE_ALIGN_CEIL(tot_size, DPAA2_PACKET_LAYOUT_ALIGN);
320 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
321 layout.options = DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM |
322 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
323 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
324 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
325 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
327 layout.pass_frame_status = 1;
328 layout.private_data_size = DPAA2_FD_PTA_SIZE;
329 layout.pass_parser_result = 1;
330 layout.data_align = DPAA2_PACKET_LAYOUT_ALIGN;
331 layout.data_head_room = tot_size - DPAA2_FD_PTA_SIZE -
332 DPAA2_MBUF_HW_ANNOTATION;
333 retcode = dpni_set_buffer_layout(dpni, CMD_PRI_LOW, priv->token,
334 DPNI_QUEUE_RX, &layout);
336 PMD_INIT_LOG(ERR, "Err(%d) in setting rx buffer layout\n",
341 /*Attach buffer pool to the network interface as described by the user*/
342 bpool_cfg.num_dpbp = 1;
343 bpool_cfg.pools[0].dpbp_id = bp_list->buf_pool.dpbp_node->dpbp_id;
344 bpool_cfg.pools[0].backup_pool = 0;
345 bpool_cfg.pools[0].buffer_size = RTE_ALIGN_CEIL(bp_list->buf_pool.size,
346 DPAA2_PACKET_LAYOUT_ALIGN);
347 bpool_cfg.pools[0].priority_mask = 0;
349 retcode = dpni_set_pools(dpni, CMD_PRI_LOW, priv->token, &bpool_cfg);
351 PMD_INIT_LOG(ERR, "Error in attaching the buffer pool list"
352 " bpid = %d Error code = %d\n",
353 bpool_cfg.pools[0].dpbp_id, retcode);
357 priv->bp_list = bp_list;