-static const char * const valid_args[] = {
-#define IPN3KE_AFU_NAME "afu"
- IPN3KE_AFU_NAME,
-#define IPN3KE_FPGA_ACCELERATION_LIST "fpga_acc"
- IPN3KE_FPGA_ACCELERATION_LIST,
-#define IPN3KE_I40E_PF_LIST "i40e_pf"
- IPN3KE_I40E_PF_LIST,
- NULL
-};
-
-static int
-ipn3ke_cfg_parse_acc_list(const char *afu_name,
- const char *acc_list_name)
-{
- struct rte_afu_device *afu_dev;
- struct ipn3ke_hw *hw;
- const char *p_source;
- char *p_start;
- char name[RTE_ETH_NAME_MAX_LEN];
-
- afu_dev = rte_ifpga_find_afu_by_name(afu_name);
- if (!afu_dev)
- return -1;
- hw = afu_dev->shared.data;
- if (!hw)
- return -1;
-
- p_source = acc_list_name;
- while (*p_source) {
- while ((*p_source == '{') || (*p_source == '|'))
- p_source++;
- p_start = name;
- while ((*p_source != '|') && (*p_source != '}'))
- *p_start++ = *p_source++;
- *p_start = 0;
- if (!strcmp(name, "tm") && hw->tm_hw_enable)
- hw->acc_tm = 1;
-
- if (!strcmp(name, "flow") && hw->flow_hw_enable)
- hw->acc_flow = 1;
-
- if (*p_source == '}')
- return 0;
- }
-
- return 0;
-}
-
-static int
-ipn3ke_cfg_parse_i40e_pf_ethdev(const char *afu_name,
- const char *pf_name)
-{
- struct rte_eth_dev *i40e_eth, *rpst_eth;
- struct rte_afu_device *afu_dev;
- struct ipn3ke_rpst *rpst;
- struct ipn3ke_hw *hw;
- const char *p_source;
- char *p_start;
- char name[RTE_ETH_NAME_MAX_LEN];
- uint16_t port_id;
- int i;
- int ret = -1;
-
- afu_dev = rte_ifpga_find_afu_by_name(afu_name);
- if (!afu_dev)
- return -1;
- hw = afu_dev->shared.data;
- if (!hw)
- return -1;
-
- p_source = pf_name;
- for (i = 0; i < hw->port_num; i++) {
- snprintf(name, sizeof(name), "net_%s_representor_%d",
- afu_name, i);
- ret = rte_eth_dev_get_port_by_name(name, &port_id);
- if (ret)
- return -1;
- rpst_eth = &rte_eth_devices[port_id];
- rpst = IPN3KE_DEV_PRIVATE_TO_RPST(rpst_eth);
-
- while ((*p_source == '{') || (*p_source == '|'))
- p_source++;
- p_start = name;
- while ((*p_source != '|') && (*p_source != '}'))
- *p_start++ = *p_source++;
- *p_start = 0;
-
- ret = rte_eth_dev_get_port_by_name(name, &port_id);
- if (ret)
- return -1;
- i40e_eth = &rte_eth_devices[port_id];
-
- rpst->i40e_pf_eth = i40e_eth;
- rpst->i40e_pf_eth_port_id = port_id;
-
- if ((*p_source == '}') || !(*p_source))
- break;
- }
-
- return 0;
-}
-
-static int
-ipn3ke_cfg_probe(struct rte_vdev_device *dev)
-{
- struct rte_devargs *devargs;
- struct rte_kvargs *kvlist = NULL;
- char *afu_name = NULL;
- char *acc_name = NULL;
- char *pf_name = NULL;
- int afu_name_en = 0;
- int acc_list_en = 0;
- int pf_list_en = 0;
- int ret = -1;
-
- devargs = dev->device.devargs;
-
- kvlist = rte_kvargs_parse(devargs->args, valid_args);
- if (!kvlist) {
- IPN3KE_AFU_PMD_ERR("error when parsing param");
- goto end;
- }
-
- if (rte_kvargs_count(kvlist, IPN3KE_AFU_NAME) == 1) {
- if (rte_kvargs_process(kvlist, IPN3KE_AFU_NAME,
- &rte_ifpga_get_string_arg,
- &afu_name) < 0) {
- IPN3KE_AFU_PMD_ERR("error to parse %s",
- IPN3KE_AFU_NAME);
- goto end;
- } else {
- afu_name_en = 1;
- }
- }
-
- if (rte_kvargs_count(kvlist, IPN3KE_FPGA_ACCELERATION_LIST) == 1) {
- if (rte_kvargs_process(kvlist, IPN3KE_FPGA_ACCELERATION_LIST,
- &rte_ifpga_get_string_arg,
- &acc_name) < 0) {
- IPN3KE_AFU_PMD_ERR("error to parse %s",
- IPN3KE_FPGA_ACCELERATION_LIST);
- goto end;
- } else {
- acc_list_en = 1;
- }
- }
-
- if (rte_kvargs_count(kvlist, IPN3KE_I40E_PF_LIST) == 1) {
- if (rte_kvargs_process(kvlist, IPN3KE_I40E_PF_LIST,
- &rte_ifpga_get_string_arg,
- &pf_name) < 0) {
- IPN3KE_AFU_PMD_ERR("error to parse %s",
- IPN3KE_I40E_PF_LIST);
- goto end;
- } else {
- pf_list_en = 1;
- }
- }
-
- if (!afu_name_en) {
- IPN3KE_AFU_PMD_ERR("arg %s is mandatory for ipn3ke",
- IPN3KE_AFU_NAME);
- goto end;
- }
-
- if (!pf_list_en) {
- IPN3KE_AFU_PMD_ERR("arg %s is mandatory for ipn3ke",
- IPN3KE_I40E_PF_LIST);
- goto end;
- }
-
- if (acc_list_en) {
- ret = ipn3ke_cfg_parse_acc_list(afu_name, acc_name);
- if (ret) {
- IPN3KE_AFU_PMD_ERR("arg %s parse error for ipn3ke",
- IPN3KE_FPGA_ACCELERATION_LIST);
- goto end;
- }
- } else {
- IPN3KE_AFU_PMD_INFO("arg %s is optional for ipn3ke, using i40e acc",
- IPN3KE_FPGA_ACCELERATION_LIST);
- }
-
- ret = ipn3ke_cfg_parse_i40e_pf_ethdev(afu_name, pf_name);
-
-end:
- if (kvlist)
- rte_kvargs_free(kvlist);
- if (afu_name)
- free(afu_name);
- if (acc_name)
- free(acc_name);
-
- return ret;
-}
-
-static int
-ipn3ke_cfg_remove(struct rte_vdev_device *dev)
-{
- struct rte_devargs *devargs;
- struct rte_kvargs *kvlist = NULL;
- char *afu_name = NULL;
- struct rte_afu_device *afu_dev;
- int ret = -1;
-
- devargs = dev->device.devargs;
-
- kvlist = rte_kvargs_parse(devargs->args, valid_args);
- if (!kvlist) {
- IPN3KE_AFU_PMD_ERR("error when parsing param");
- goto end;
- }
-
- if (rte_kvargs_count(kvlist, IPN3KE_AFU_NAME) == 1) {
- if (rte_kvargs_process(kvlist, IPN3KE_AFU_NAME,
- &rte_ifpga_get_string_arg,
- &afu_name) < 0) {
- IPN3KE_AFU_PMD_ERR("error to parse %s",
- IPN3KE_AFU_NAME);
- } else {
- afu_dev = rte_ifpga_find_afu_by_name(afu_name);
- if (!afu_dev)
- goto end;
- ret = ipn3ke_vswitch_remove(afu_dev);
- }
- } else {
- IPN3KE_AFU_PMD_ERR("Remove ipn3ke_cfg %p error", dev);
- }
-
-end:
- if (kvlist)
- rte_kvargs_free(kvlist);
-
- return ret;
-}
-
-static struct rte_vdev_driver ipn3ke_cfg_driver = {
- .probe = ipn3ke_cfg_probe,
- .remove = ipn3ke_cfg_remove,
-};
-
-RTE_PMD_REGISTER_VDEV(ipn3ke_cfg, ipn3ke_cfg_driver);
-RTE_PMD_REGISTER_PARAM_STRING(ipn3ke_cfg,
- "afu=<string> "
- "fpga_acc=<string>"
- "i40e_pf=<string>");
-