1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
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 dpaa2_setup_flow_dist(struct rte_eth_dev *eth_dev,
33 uint64_t req_dist_set)
35 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
36 struct fsl_mc_io *dpni = priv->hw;
37 struct dpni_rx_tc_dist_cfg tc_cfg;
38 struct dpkg_profile_cfg kg_cfg;
40 int ret, tc_index = 0;
42 p_params = rte_malloc(
43 NULL, DIST_PARAM_IOVA_SIZE, RTE_CACHE_LINE_SIZE);
45 DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
48 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
49 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
51 ret = dpaa2_distset_to_dpkg_profile_cfg(req_dist_set, &kg_cfg);
53 DPAA2_PMD_ERR("Given RSS Hash (%" PRIx64 ") not supported",
58 tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
59 tc_cfg.dist_size = eth_dev->data->nb_rx_queues;
60 tc_cfg.dist_mode = DPNI_DIST_MODE_HASH;
62 ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
64 DPAA2_PMD_ERR("Unable to prepare extract parameters");
69 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
74 "Setting distribution for Rx failed with err: %d",
82 int dpaa2_remove_flow_dist(
83 struct rte_eth_dev *eth_dev,
86 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
87 struct fsl_mc_io *dpni = priv->hw;
88 struct dpni_rx_tc_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");
99 memset(p_params, 0, DIST_PARAM_IOVA_SIZE);
100 memset(&tc_cfg, 0, sizeof(struct dpni_rx_tc_dist_cfg));
101 kg_cfg.num_extracts = 0;
102 tc_cfg.key_cfg_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(p_params));
103 tc_cfg.dist_size = 0;
104 tc_cfg.dist_mode = DPNI_DIST_MODE_NONE;
106 ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
108 DPAA2_PMD_ERR("Unable to prepare extract parameters");
113 ret = dpni_set_rx_tc_dist(dpni, CMD_PRI_LOW, priv->token, tc_index,
118 "Setting distribution for Rx failed with err: %d",
124 dpaa2_distset_to_dpkg_profile_cfg(
125 uint64_t req_dist_set,
126 struct dpkg_profile_cfg *kg_cfg)
128 uint32_t loop = 0, i = 0, dist_field = 0;
129 int l2_configured = 0, l3_configured = 0;
130 int l4_configured = 0, sctp_configured = 0;
132 memset(kg_cfg, 0, sizeof(struct dpkg_profile_cfg));
133 while (req_dist_set) {
134 if (req_dist_set % 2 != 0) {
135 dist_field = 1U << loop;
136 switch (dist_field) {
137 case ETH_RSS_L2_PAYLOAD:
143 kg_cfg->extracts[i].extract.from_hdr.prot =
145 kg_cfg->extracts[i].extract.from_hdr.field =
147 kg_cfg->extracts[i].type =
148 DPKG_EXTRACT_FROM_HDR;
149 kg_cfg->extracts[i].extract.from_hdr.type =
155 case ETH_RSS_FRAG_IPV4:
156 case ETH_RSS_NONFRAG_IPV4_OTHER:
158 case ETH_RSS_FRAG_IPV6:
159 case ETH_RSS_NONFRAG_IPV6_OTHER:
160 case ETH_RSS_IPV6_EX:
166 kg_cfg->extracts[i].extract.from_hdr.prot =
168 kg_cfg->extracts[i].extract.from_hdr.field =
170 kg_cfg->extracts[i].type =
171 DPKG_EXTRACT_FROM_HDR;
172 kg_cfg->extracts[i].extract.from_hdr.type =
176 kg_cfg->extracts[i].extract.from_hdr.prot =
178 kg_cfg->extracts[i].extract.from_hdr.field =
180 kg_cfg->extracts[i].type =
181 DPKG_EXTRACT_FROM_HDR;
182 kg_cfg->extracts[i].extract.from_hdr.type =
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 =
194 kg_cfg->num_extracts++;
198 case ETH_RSS_NONFRAG_IPV4_TCP:
199 case ETH_RSS_NONFRAG_IPV6_TCP:
200 case ETH_RSS_NONFRAG_IPV4_UDP:
201 case ETH_RSS_NONFRAG_IPV6_UDP:
202 case ETH_RSS_IPV6_TCP_EX:
203 case ETH_RSS_IPV6_UDP_EX:
209 kg_cfg->extracts[i].extract.from_hdr.prot =
211 kg_cfg->extracts[i].extract.from_hdr.field =
213 kg_cfg->extracts[i].type =
214 DPKG_EXTRACT_FROM_HDR;
215 kg_cfg->extracts[i].extract.from_hdr.type =
219 kg_cfg->extracts[i].extract.from_hdr.prot =
221 kg_cfg->extracts[i].extract.from_hdr.field =
223 kg_cfg->extracts[i].type =
224 DPKG_EXTRACT_FROM_HDR;
225 kg_cfg->extracts[i].extract.from_hdr.type =
230 case ETH_RSS_NONFRAG_IPV4_SCTP:
231 case ETH_RSS_NONFRAG_IPV6_SCTP:
237 kg_cfg->extracts[i].extract.from_hdr.prot =
239 kg_cfg->extracts[i].extract.from_hdr.field =
240 NH_FLD_SCTP_PORT_SRC;
241 kg_cfg->extracts[i].type =
242 DPKG_EXTRACT_FROM_HDR;
243 kg_cfg->extracts[i].extract.from_hdr.type =
247 kg_cfg->extracts[i].extract.from_hdr.prot =
249 kg_cfg->extracts[i].extract.from_hdr.field =
250 NH_FLD_SCTP_PORT_DST;
251 kg_cfg->extracts[i].type =
252 DPKG_EXTRACT_FROM_HDR;
253 kg_cfg->extracts[i].extract.from_hdr.type =
260 "Unsupported flow dist option %x",
265 req_dist_set = req_dist_set >> 1;
268 kg_cfg->num_extracts = i;
273 dpaa2_attach_bp_list(struct dpaa2_dev_priv *priv,
276 /* Function to attach a DPNI with a buffer pool list. Buffer pool list
277 * handle is passed in blist.
280 struct fsl_mc_io *dpni = priv->hw;
281 struct dpni_pools_cfg bpool_cfg;
282 struct dpaa2_bp_list *bp_list = (struct dpaa2_bp_list *)blist;
283 struct dpni_buffer_layout layout;
286 /* ... rx buffer layout .
287 * Check alignment for buffer layouts first
290 /* ... rx buffer layout ... */
291 tot_size = RTE_PKTMBUF_HEADROOM;
292 tot_size = RTE_ALIGN_CEIL(tot_size, DPAA2_PACKET_LAYOUT_ALIGN);
294 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
295 layout.options = DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM |
296 DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
297 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
298 DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
299 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
301 layout.pass_frame_status = 1;
302 layout.private_data_size = DPAA2_FD_PTA_SIZE;
303 layout.pass_parser_result = 1;
304 layout.data_align = DPAA2_PACKET_LAYOUT_ALIGN;
305 layout.data_head_room = tot_size - DPAA2_FD_PTA_SIZE -
306 DPAA2_MBUF_HW_ANNOTATION;
307 retcode = dpni_set_buffer_layout(dpni, CMD_PRI_LOW, priv->token,
308 DPNI_QUEUE_RX, &layout);
310 DPAA2_PMD_ERR("Error configuring buffer pool Rx layout (%d)",
315 /*Attach buffer pool to the network interface as described by the user*/
316 bpool_cfg.num_dpbp = 1;
317 bpool_cfg.pools[0].dpbp_id = bp_list->buf_pool.dpbp_node->dpbp_id;
318 bpool_cfg.pools[0].backup_pool = 0;
319 bpool_cfg.pools[0].buffer_size = RTE_ALIGN_CEIL(bp_list->buf_pool.size,
320 DPAA2_PACKET_LAYOUT_ALIGN);
321 bpool_cfg.pools[0].priority_mask = 0;
323 retcode = dpni_set_pools(dpni, CMD_PRI_LOW, priv->token, &bpool_cfg);
325 DPAA2_PMD_ERR("Error configuring buffer pool on interface."
326 " bpid = %d error code = %d",
327 bpool_cfg.pools[0].dpbp_id, retcode);
331 priv->bp_list = bp_list;