1 /* SPDX-License-Identifier: BSD-3-Clause
13 #include <rte_ethdev.h>
15 #include <rte_eth_ctrl.h>
16 #include <rte_malloc.h>
17 #include <rte_flow_driver.h>
18 #include <rte_tailq.h>
20 #include <rte_fslmc.h>
21 #include <fsl_dpdmux.h>
24 #include <dpaa2_ethdev.h>
25 #include <dpaa2_pmd_logs.h>
27 struct dpaa2_dpdmux_dev {
28 TAILQ_ENTRY(dpaa2_dpdmux_dev) next;
29 /**< Pointer to Next device instance */
30 struct fsl_mc_io dpdmux; /** handle to DPDMUX portal object */
32 uint32_t dpdmux_id; /*HW ID for DPDMUX object */
33 uint8_t num_ifs; /* Number of interfaces in DPDMUX */
37 struct dpdmux_rule_cfg rule;
40 TAILQ_HEAD(dpdmux_dev_list, dpaa2_dpdmux_dev);
41 static struct dpdmux_dev_list dpdmux_dev_list =
42 TAILQ_HEAD_INITIALIZER(dpdmux_dev_list); /*!< DPDMUX device list */
44 static struct dpaa2_dpdmux_dev *get_dpdmux_from_id(uint32_t dpdmux_id)
46 struct dpaa2_dpdmux_dev *dpdmux_dev = NULL;
48 /* Get DPBP dev handle from list using index */
49 TAILQ_FOREACH(dpdmux_dev, &dpdmux_dev_list, next) {
50 if (dpdmux_dev->dpdmux_id == dpdmux_id)
58 rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id,
59 struct rte_flow_item *pattern[],
60 struct rte_flow_action *actions[])
62 struct dpaa2_dpdmux_dev *dpdmux_dev;
63 struct dpkg_profile_cfg kg_cfg;
64 const struct rte_flow_item_ipv4 *spec;
65 const struct rte_flow_action_vf *vf_conf;
66 struct dpdmux_cls_action dpdmux_action;
67 struct rte_flow *flow = NULL;
68 void *key_iova, *mask_iova, *key_cfg_iova = NULL;
71 if (pattern[0]->type != RTE_FLOW_ITEM_TYPE_IPV4) {
72 DPAA2_PMD_ERR("Not supported pattern type: %d",
77 /* Find the DPDMUX from dpdmux_id in our list */
78 dpdmux_dev = get_dpdmux_from_id(dpdmux_id);
80 DPAA2_PMD_ERR("Invalid dpdmux_id: %d", dpdmux_id);
84 key_cfg_iova = rte_zmalloc(NULL, DIST_PARAM_IOVA_SIZE,
87 DPAA2_PMD_ERR("Unable to allocate flow-dist parameters");
91 /* Currently taking only IP protocol as an extract type.
92 * This can be exended to other fields using pattern->type.
94 memset(&kg_cfg, 0, sizeof(struct dpkg_profile_cfg));
95 kg_cfg.extracts[0].extract.from_hdr.prot = NET_PROT_IP;
96 kg_cfg.extracts[0].extract.from_hdr.field = NH_FLD_IP_PROTO;
97 kg_cfg.extracts[0].type = DPKG_EXTRACT_FROM_HDR;
98 kg_cfg.extracts[0].extract.from_hdr.type = DPKG_FULL_FIELD;
99 kg_cfg.num_extracts = 1;
101 ret = dpkg_prepare_key_cfg(&kg_cfg, key_cfg_iova);
103 DPAA2_PMD_ERR("dpkg_prepare_key_cfg failed: err(%d)", ret);
107 ret = dpdmux_set_custom_key(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
109 (uint64_t)(DPAA2_VADDR_TO_IOVA(key_cfg_iova)));
111 DPAA2_PMD_ERR("dpdmux_set_custom_key failed: err(%d)", ret);
115 /* As now our key extract parameters are set, let us configure
118 flow = rte_zmalloc(NULL, sizeof(struct rte_flow) +
119 (2 * DIST_PARAM_IOVA_SIZE), RTE_CACHE_LINE_SIZE);
122 "Memory allocation failure for rule configration\n");
125 key_iova = (void *)((size_t)flow + sizeof(struct rte_flow));
126 mask_iova = (void *)((size_t)key_iova + DIST_PARAM_IOVA_SIZE);
128 spec = (const struct rte_flow_item_ipv4 *)pattern[0]->spec;
129 memcpy(key_iova, (const void *)&spec->hdr.next_proto_id,
131 memcpy(mask_iova, pattern[0]->mask, sizeof(uint8_t));
133 flow->rule.key_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(key_iova));
134 flow->rule.mask_iova = (uint64_t)(DPAA2_VADDR_TO_IOVA(mask_iova));
135 flow->rule.key_size = sizeof(uint8_t);
137 vf_conf = (const struct rte_flow_action_vf *)(actions[0]->conf);
138 if (vf_conf->id == 0 || vf_conf->id > dpdmux_dev->num_ifs) {
139 DPAA2_PMD_ERR("Invalid destination id\n");
142 dpdmux_action.dest_if = vf_conf->id;
144 ret = dpdmux_add_custom_cls_entry(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
145 dpdmux_dev->token, &flow->rule,
148 DPAA2_PMD_ERR("dpdmux_add_custom_cls_entry failed: err(%d)",
156 rte_free((void *)key_cfg_iova);
157 rte_free((void *)flow);
162 dpaa2_create_dpdmux_device(int vdev_fd __rte_unused,
163 struct vfio_device_info *obj_info __rte_unused,
166 struct dpaa2_dpdmux_dev *dpdmux_dev;
167 struct dpdmux_attr attr;
170 PMD_INIT_FUNC_TRACE();
172 /* Allocate DPAA2 dpdmux handle */
173 dpdmux_dev = rte_malloc(NULL, sizeof(struct dpaa2_dpdmux_dev), 0);
175 DPAA2_PMD_ERR("Memory allocation failed for DPDMUX Device");
179 /* Open the dpdmux object */
180 dpdmux_dev->dpdmux.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
181 ret = dpdmux_open(&dpdmux_dev->dpdmux, CMD_PRI_LOW, dpdmux_id,
184 DPAA2_PMD_ERR("Unable to open dpdmux object: err(%d)", ret);
188 ret = dpdmux_get_attributes(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
189 dpdmux_dev->token, &attr);
191 DPAA2_PMD_ERR("Unable to get dpdmux attr: err(%d)", ret);
195 ret = dpdmux_if_set_default(&dpdmux_dev->dpdmux, CMD_PRI_LOW,
196 dpdmux_dev->token, 1);
198 DPAA2_PMD_ERR("setting default interface failed in %s",
203 dpdmux_dev->dpdmux_id = dpdmux_id;
204 dpdmux_dev->num_ifs = attr.num_ifs;
206 TAILQ_INSERT_TAIL(&dpdmux_dev_list, dpdmux_dev, next);
212 rte_free(dpdmux_dev);
217 static struct rte_dpaa2_object rte_dpaa2_dpdmux_obj = {
218 .dev_type = DPAA2_MUX,
219 .create = dpaa2_create_dpdmux_device,
222 RTE_PMD_REGISTER_DPAA2_OBJECT(dpdmux, rte_dpaa2_dpdmux_obj);