1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2016-2019 NXP
12 #include <rte_ethdev_driver.h>
13 #include <rte_malloc.h>
14 #include <rte_memcpy.h>
15 #include <rte_string_fns.h>
16 #include <rte_cycles.h>
17 #include <rte_kvargs.h>
20 #include <dpaa2_pmd_logs.h>
21 #include <dpaa2_hw_pvt.h>
22 #include <dpaa2_hw_mempool.h>
24 #include "../dpaa2_ethdev.h"
27 dpaa2_distset_to_dpkg_profile_cfg(
28 uint64_t req_dist_set,
29 struct dpkg_profile_cfg *kg_cfg);
32 rte_pmd_dpaa2_set_custom_hash(uint16_t port_id,
36 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
37 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
38 struct fsl_mc_io *dpni = priv->hw;
39 struct dpni_rx_tc_dist_cfg tc_cfg;
40 struct dpkg_profile_cfg kg_cfg;
42 int ret, tc_index = 0;
44 p_params = rte_zmalloc(
45 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
47 DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
51 kg_cfg.extracts[0].type = DPKG_EXTRACT_FROM_DATA;
52 kg_cfg.extracts[0].extract.from_data.offset = offset;
53 kg_cfg.extracts[0].extract.from_data.size = size;
54 kg_cfg.extracts[0].num_of_byte_masks = 0;
55 kg_cfg.num_extracts = 1;
57 ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
59 DPAA2_PMD_ERR("Unable to prepare extract parameters");
64 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
65 tc_cfg.key_cfg_iova = (size_t)(DPAA2_VADDR_TO_IOVA(p_params));
66 tc_cfg.dist_size = eth_dev->data->nb_rx_queues;
67 tc_cfg.dist_mode = DPNI_DIST_MODE_HASH;
69 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
74 "Setting distribution for Rx failed with err: %d",
83 dpaa2_setup_flow_dist(struct rte_eth_dev *eth_dev,
84 uint64_t req_dist_set, int tc_index)
86 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
87 struct fsl_mc_io *dpni = priv->hw;
88 struct dpni_rx_dist_cfg tc_cfg;
89 struct dpkg_profile_cfg kg_cfg;
93 p_params = rte_malloc(
94 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
96 DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
100 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
101 memset(&tc_cfg, 0, sizeof(struct dpni_rx_dist_cfg));
103 ret = dpaa2_distset_to_dpkg_profile_cfg(req_dist_set, &kg_cfg);
105 DPAA2_PMD_ERR("Given RSS Hash (%" PRIx64 ") not supported",
111 tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
112 tc_cfg.dist_size = priv->dist_queues;
113 tc_cfg.enable = true;
114 tc_cfg.tc = tc_index;
116 ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
118 DPAA2_PMD_ERR("Unable to prepare extract parameters");
123 ret = dpni_set_rx_hash_dist(dpni, CMD_PRI_LOW, priv->token, &tc_cfg);
127 "Setting distribution for Rx failed with err: %d",
135 int dpaa2_remove_flow_dist(
136 struct rte_eth_dev *eth_dev,
139 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
140 struct fsl_mc_io *dpni = priv->hw;
141 struct dpni_rx_dist_cfg tc_cfg;
142 struct dpkg_profile_cfg kg_cfg;
146 p_params = rte_malloc(
147 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
149 DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
153 memset(&tc_cfg, 0, sizeof(struct dpni_rx_dist_cfg));
154 tc_cfg.dist_size = 0;
155 tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
156 tc_cfg.enable = true;
157 tc_cfg.tc = tc_index;
159 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
160 kg_cfg.num_extracts = 0;
161 ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
163 DPAA2_PMD_ERR("Unable to prepare extract parameters");
168 ret = dpni_set_rx_hash_dist(dpni, CMD_PRI_LOW, priv->token,
173 "Setting distribution for Rx failed with err: %d",
179 dpaa2_distset_to_dpkg_profile_cfg(
180 uint64_t req_dist_set,
181 struct dpkg_profile_cfg *kg_cfg)
183 uint32_t loop = 0, i = 0, dist_field = 0;
184 int l2_configured = 0, l3_configured = 0;
185 int l4_configured = 0, sctp_configured = 0;
187 memset(kg_cfg, 0, sizeof(struct dpkg_profile_cfg));
188 while (req_dist_set) {
189 if (req_dist_set % 2 != 0) {
190 dist_field = 1U << loop;
191 switch (dist_field) {
192 case ETH_RSS_L2_PAYLOAD:
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 =
210 case ETH_RSS_FRAG_IPV4:
211 case ETH_RSS_NONFRAG_IPV4_OTHER:
213 case ETH_RSS_FRAG_IPV6:
214 case ETH_RSS_NONFRAG_IPV6_OTHER:
215 case ETH_RSS_IPV6_EX:
221 kg_cfg->extracts[i].extract.from_hdr.prot =
223 kg_cfg->extracts[i].extract.from_hdr.field =
225 kg_cfg->extracts[i].type =
226 DPKG_EXTRACT_FROM_HDR;
227 kg_cfg->extracts[i].extract.from_hdr.type =
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 =
249 kg_cfg->num_extracts++;
253 case ETH_RSS_NONFRAG_IPV4_TCP:
254 case ETH_RSS_NONFRAG_IPV6_TCP:
255 case ETH_RSS_NONFRAG_IPV4_UDP:
256 case ETH_RSS_NONFRAG_IPV6_UDP:
257 case ETH_RSS_IPV6_TCP_EX:
258 case ETH_RSS_IPV6_UDP_EX:
264 kg_cfg->extracts[i].extract.from_hdr.prot =
266 kg_cfg->extracts[i].extract.from_hdr.field =
268 kg_cfg->extracts[i].type =
269 DPKG_EXTRACT_FROM_HDR;
270 kg_cfg->extracts[i].extract.from_hdr.type =
274 kg_cfg->extracts[i].extract.from_hdr.prot =
276 kg_cfg->extracts[i].extract.from_hdr.field =
278 kg_cfg->extracts[i].type =
279 DPKG_EXTRACT_FROM_HDR;
280 kg_cfg->extracts[i].extract.from_hdr.type =
285 case ETH_RSS_NONFRAG_IPV4_SCTP:
286 case ETH_RSS_NONFRAG_IPV6_SCTP:
292 kg_cfg->extracts[i].extract.from_hdr.prot =
294 kg_cfg->extracts[i].extract.from_hdr.field =
295 NH_FLD_SCTP_PORT_SRC;
296 kg_cfg->extracts[i].type =
297 DPKG_EXTRACT_FROM_HDR;
298 kg_cfg->extracts[i].extract.from_hdr.type =
302 kg_cfg->extracts[i].extract.from_hdr.prot =
304 kg_cfg->extracts[i].extract.from_hdr.field =
305 NH_FLD_SCTP_PORT_DST;
306 kg_cfg->extracts[i].type =
307 DPKG_EXTRACT_FROM_HDR;
308 kg_cfg->extracts[i].extract.from_hdr.type =
315 "Unsupported flow dist option %x",
320 req_dist_set = req_dist_set >> 1;
323 kg_cfg->num_extracts = i;
328 dpaa2_attach_bp_list(struct dpaa2_dev_priv *priv,
331 /* Function to attach a DPNI with a buffer pool list. Buffer pool list
332 * handle is passed in blist.
335 struct fsl_mc_io *dpni = priv->hw;
336 struct dpni_pools_cfg bpool_cfg;
337 struct dpaa2_bp_list *bp_list = (struct dpaa2_bp_list *)blist;
338 struct dpni_buffer_layout layout;
341 /* ... rx buffer layout .
342 * Check alignment for buffer layouts first
345 /* ... rx buffer layout ... */
346 tot_size = RTE_PKTMBUF_HEADROOM;
347 tot_size = RTE_ALIGN_CEIL(tot_size, DPAA2_PACKET_LAYOUT_ALIGN);
349 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
350 layout.options = DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM |
351 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
352 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
353 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
354 DPNI_BUF_LAYOUT_OPT_TIMESTAMP |
355 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
357 layout.pass_timestamp = true;
358 layout.pass_frame_status = 1;
359 layout.private_data_size = DPAA2_FD_PTA_SIZE;
360 layout.pass_parser_result = 1;
361 layout.data_align = DPAA2_PACKET_LAYOUT_ALIGN;
362 layout.data_head_room = tot_size - DPAA2_FD_PTA_SIZE -
363 DPAA2_MBUF_HW_ANNOTATION;
364 retcode = dpni_set_buffer_layout(dpni, CMD_PRI_LOW, priv->token,
365 DPNI_QUEUE_RX, &layout);
367 DPAA2_PMD_ERR("Error configuring buffer pool Rx layout (%d)",
372 /*Attach buffer pool to the network interface as described by the user*/
373 memset(&bpool_cfg, 0, sizeof(struct dpni_pools_cfg));
374 bpool_cfg.num_dpbp = 1;
375 bpool_cfg.pools[0].dpbp_id = bp_list->buf_pool.dpbp_node->dpbp_id;
376 bpool_cfg.pools[0].backup_pool = 0;
377 bpool_cfg.pools[0].buffer_size = RTE_ALIGN_CEIL(bp_list->buf_pool.size,
378 DPAA2_PACKET_LAYOUT_ALIGN);
379 bpool_cfg.pools[0].priority_mask = 0;
381 retcode = dpni_set_pools(dpni, CMD_PRI_LOW, priv->token, &bpool_cfg);
383 DPAA2_PMD_ERR("Error configuring buffer pool on interface."
384 " bpid = %d error code = %d",
385 bpool_cfg.pools[0].dpbp_id, retcode);
389 priv->bp_list = bp_list;