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 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)(DPAA2_VADDR_TO_IOVA(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,
94 "Setting distribution for Rx failed with err: %d\n",
102 int dpaa2_remove_flow_dist(
103 struct rte_eth_dev *eth_dev,
106 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
107 struct fsl_mc_io *dpni = priv->hw;
108 struct dpni_rx_tc_dist_cfg tc_cfg;
109 struct dpkg_profile_cfg kg_cfg;
113 p_params = rte_malloc(
114 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
116 RTE_LOG(ERR, PMD, "Memory unavaialble\n");
119 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
120 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
122 tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
123 tc_cfg.dist_size = 0;
124 tc_cfg.dist_mode = DPNI_DIST_MODE_NONE;
126 ret = dpni_prepare_key_cfg(&kg_cfg, p_params);
128 RTE_LOG(ERR, PMD, "Unable to prepare extract parameters\n");
133 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
138 "Setting distribution for Rx failed with err: %d\n",
146 dpaa2_distset_to_dpkg_profile_cfg(
147 uint32_t req_dist_set,
148 struct dpkg_profile_cfg *kg_cfg)
150 uint32_t loop = 0, i = 0, dist_field = 0;
151 int l2_configured = 0, l3_configured = 0;
152 int l4_configured = 0, sctp_configured = 0;
154 memset(kg_cfg, 0, sizeof(struct dpkg_profile_cfg));
155 while (req_dist_set) {
156 if (req_dist_set % 2 != 0) {
157 dist_field = 1U << loop;
158 switch (dist_field) {
159 case ETH_RSS_L2_PAYLOAD:
165 kg_cfg->extracts[i].extract.from_hdr.prot =
167 kg_cfg->extracts[i].extract.from_hdr.field =
169 kg_cfg->extracts[i].type =
170 DPKG_EXTRACT_FROM_HDR;
171 kg_cfg->extracts[i].extract.from_hdr.type =
177 case ETH_RSS_FRAG_IPV4:
178 case ETH_RSS_NONFRAG_IPV4_OTHER:
180 case ETH_RSS_FRAG_IPV6:
181 case ETH_RSS_NONFRAG_IPV6_OTHER:
182 case ETH_RSS_IPV6_EX:
188 kg_cfg->extracts[i].extract.from_hdr.prot =
190 kg_cfg->extracts[i].extract.from_hdr.field =
192 kg_cfg->extracts[i].type =
193 DPKG_EXTRACT_FROM_HDR;
194 kg_cfg->extracts[i].extract.from_hdr.type =
198 kg_cfg->extracts[i].extract.from_hdr.prot =
200 kg_cfg->extracts[i].extract.from_hdr.field =
202 kg_cfg->extracts[i].type =
203 DPKG_EXTRACT_FROM_HDR;
204 kg_cfg->extracts[i].extract.from_hdr.type =
208 kg_cfg->extracts[i].extract.from_hdr.prot =
210 kg_cfg->extracts[i].extract.from_hdr.field =
212 kg_cfg->extracts[i].type =
213 DPKG_EXTRACT_FROM_HDR;
214 kg_cfg->extracts[i].extract.from_hdr.type =
216 kg_cfg->num_extracts++;
220 case ETH_RSS_NONFRAG_IPV4_TCP:
221 case ETH_RSS_NONFRAG_IPV6_TCP:
222 case ETH_RSS_NONFRAG_IPV4_UDP:
223 case ETH_RSS_NONFRAG_IPV6_UDP:
224 case ETH_RSS_IPV6_TCP_EX:
225 case ETH_RSS_IPV6_UDP_EX:
231 kg_cfg->extracts[i].extract.from_hdr.prot =
233 kg_cfg->extracts[i].extract.from_hdr.field =
235 kg_cfg->extracts[i].type =
236 DPKG_EXTRACT_FROM_HDR;
237 kg_cfg->extracts[i].extract.from_hdr.type =
241 kg_cfg->extracts[i].extract.from_hdr.prot =
243 kg_cfg->extracts[i].extract.from_hdr.field =
245 kg_cfg->extracts[i].type =
246 DPKG_EXTRACT_FROM_HDR;
247 kg_cfg->extracts[i].extract.from_hdr.type =
252 case ETH_RSS_NONFRAG_IPV4_SCTP:
253 case ETH_RSS_NONFRAG_IPV6_SCTP:
259 kg_cfg->extracts[i].extract.from_hdr.prot =
261 kg_cfg->extracts[i].extract.from_hdr.field =
262 NH_FLD_SCTP_PORT_SRC;
263 kg_cfg->extracts[i].type =
264 DPKG_EXTRACT_FROM_HDR;
265 kg_cfg->extracts[i].extract.from_hdr.type =
269 kg_cfg->extracts[i].extract.from_hdr.prot =
271 kg_cfg->extracts[i].extract.from_hdr.field =
272 NH_FLD_SCTP_PORT_DST;
273 kg_cfg->extracts[i].type =
274 DPKG_EXTRACT_FROM_HDR;
275 kg_cfg->extracts[i].extract.from_hdr.type =
281 PMD_DRV_LOG(WARNING, "Bad flow distribution"
282 " option %x\n", dist_field);
285 req_dist_set = req_dist_set >> 1;
288 kg_cfg->num_extracts = i;
292 dpaa2_attach_bp_list(struct dpaa2_dev_priv *priv,
295 /* Function to attach a DPNI with a buffer pool list. Buffer pool list
296 * handle is passed in blist.
299 struct fsl_mc_io *dpni = priv->hw;
300 struct dpni_pools_cfg bpool_cfg;
301 struct dpaa2_bp_list *bp_list = (struct dpaa2_bp_list *)blist;
302 struct dpni_buffer_layout layout;
305 /* ... rx buffer layout .
306 * Check alignment for buffer layouts first
309 /* ... rx buffer layout ... */
310 tot_size = RTE_PKTMBUF_HEADROOM;
311 tot_size = RTE_ALIGN_CEIL(tot_size, DPAA2_PACKET_LAYOUT_ALIGN);
313 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
314 layout.options = DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM |
315 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
316 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
317 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
318 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
320 layout.pass_frame_status = 1;
321 layout.private_data_size = DPAA2_FD_PTA_SIZE;
322 layout.pass_parser_result = 1;
323 layout.data_align = DPAA2_PACKET_LAYOUT_ALIGN;
324 layout.data_head_room = tot_size - DPAA2_FD_PTA_SIZE -
325 DPAA2_MBUF_HW_ANNOTATION;
326 retcode = dpni_set_buffer_layout(dpni, CMD_PRI_LOW, priv->token,
327 DPNI_QUEUE_RX, &layout);
329 PMD_INIT_LOG(ERR, "Err(%d) in setting rx buffer layout\n",
334 /*Attach buffer pool to the network interface as described by the user*/
335 bpool_cfg.num_dpbp = 1;
336 bpool_cfg.pools[0].dpbp_id = bp_list->buf_pool.dpbp_node->dpbp_id;
337 bpool_cfg.pools[0].backup_pool = 0;
338 bpool_cfg.pools[0].buffer_size = RTE_ALIGN_CEIL(bp_list->buf_pool.size,
339 DPAA2_PACKET_LAYOUT_ALIGN);
341 retcode = dpni_set_pools(dpni, CMD_PRI_LOW, priv->token, &bpool_cfg);
343 PMD_INIT_LOG(ERR, "Error in attaching the buffer pool list"
344 " bpid = %d Error code = %d\n",
345 bpool_cfg.pools[0].dpbp_id, retcode);
349 priv->bp_list = bp_list;