* [dpdk-dev] [PATCH v1] crypto/ccp: moving vdev to PCI driver
@ 2021-07-16 8:47 asomalap
2021-07-16 10:41 ` [dpdk-dev] [PATCH v2] " asomalap
0 siblings, 1 reply; 3+ messages in thread
From: asomalap @ 2021-07-16 8:47 UTC (permalink / raw)
To: dev
From: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
drop all the code duplicating the PCI bus driver
develped for Enable IOMMU in vdev.
Signed-off-by: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
---
drivers/crypto/ccp/ccp_dev.c | 67 ++-----------
drivers/crypto/ccp/ccp_dev.h | 3 +-
drivers/crypto/ccp/rte_ccp_pmd.c | 156 +++++++------------------------
3 files changed, 41 insertions(+), 185 deletions(-)
diff --git a/drivers/crypto/ccp/ccp_dev.c b/drivers/crypto/ccp/ccp_dev.c
index ee6882b8a4..be2cefbec9 100644
--- a/drivers/crypto/ccp/ccp_dev.c
+++ b/drivers/crypto/ccp/ccp_dev.c
@@ -604,6 +604,7 @@ ccp_add_device(struct ccp_device *dev, int type)
}
TAILQ_INSERT_TAIL(&ccp_list, dev, next);
+
return 0;
}
@@ -650,73 +651,17 @@ is_ccp_device(const char *dirname,
}
static int
-ccp_probe_device(const char *dirname, uint16_t domain,
- uint8_t bus, uint8_t devid,
- uint8_t function, int ccp_type)
+ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev)
{
struct ccp_device *ccp_dev = NULL;
- struct rte_pci_device *pci;
- char filename[PATH_MAX];
- unsigned long tmp;
int uio_fd = -1;
ccp_dev = rte_zmalloc("ccp_device", sizeof(*ccp_dev),
RTE_CACHE_LINE_SIZE);
if (ccp_dev == NULL)
goto fail;
- pci = &(ccp_dev->pci);
-
- pci->addr.domain = domain;
- pci->addr.bus = bus;
- pci->addr.devid = devid;
- pci->addr.function = function;
-
- /* get vendor id */
- snprintf(filename, sizeof(filename), "%s/vendor", dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.vendor_id = (uint16_t)tmp;
-
- /* get device id */
- snprintf(filename, sizeof(filename), "%s/device", dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.device_id = (uint16_t)tmp;
-
- /* get subsystem_vendor id */
- snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.subsystem_vendor_id = (uint16_t)tmp;
-
- /* get subsystem_device id */
- snprintf(filename, sizeof(filename), "%s/subsystem_device",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.subsystem_device_id = (uint16_t)tmp;
-
- /* get class_id */
- snprintf(filename, sizeof(filename), "%s/class",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- /* the least 24 bits are valid: class, subclass, program interface */
- pci->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID;
-
- /* parse resources */
- snprintf(filename, sizeof(filename), "%s/resource", dirname);
- if (ccp_pci_parse_sysfs_resource(filename, pci) < 0)
- goto fail;
- if (iommu_mode == 2)
- pci->kdrv = RTE_PCI_KDRV_VFIO;
- else if (iommu_mode == 0)
- pci->kdrv = RTE_PCI_KDRV_IGB_UIO;
- else if (iommu_mode == 1)
- pci->kdrv = RTE_PCI_KDRV_UIO_GENERIC;
- rte_pci_map_device(pci);
+ ccp_dev->pci = *pci_dev;
/* device is valid, add in list */
if (ccp_add_device(ccp_dev, ccp_type)) {
@@ -735,7 +680,8 @@ ccp_probe_device(const char *dirname, uint16_t domain,
}
int
-ccp_probe_devices(const struct rte_pci_id *ccp_id)
+ccp_probe_devices(struct rte_pci_device *pci_dev,
+ const struct rte_pci_id *ccp_id)
{
int dev_cnt = 0;
int ccp_type = 0;
@@ -767,8 +713,7 @@ ccp_probe_devices(const struct rte_pci_id *ccp_id)
if (is_ccp_device(dirname, ccp_id, &ccp_type)) {
printf("CCP : Detected CCP device with ID = 0x%x\n",
ccp_id[ccp_type].device_id);
- ret = ccp_probe_device(dirname, domain, bus, devid,
- function, ccp_type);
+ ret = ccp_probe_device(ccp_type, pci_dev);
if (ret == 0)
dev_cnt++;
}
diff --git a/drivers/crypto/ccp/ccp_dev.h b/drivers/crypto/ccp/ccp_dev.h
index 37e04218ce..ca5145c278 100644
--- a/drivers/crypto/ccp/ccp_dev.h
+++ b/drivers/crypto/ccp/ccp_dev.h
@@ -473,7 +473,8 @@ int ccp_dev_start(struct rte_cryptodev *dev);
* @param ccp_id rte_pci_id list for supported CCP devices
* @return no. of successfully initialized CCP devices
*/
-int ccp_probe_devices(const struct rte_pci_id *ccp_id);
+int ccp_probe_devices(struct rte_pci_device *pci_dev,
+ const struct rte_pci_id *ccp_id);
/**
* allocate a ccp command queue
diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c
index ba379a19f3..7fc87892fb 100644
--- a/drivers/crypto/ccp/rte_ccp_pmd.c
+++ b/drivers/crypto/ccp/rte_ccp_pmd.c
@@ -47,111 +47,6 @@ enum ccp_pmd_auth_opt {
CCP_PMD_AUTH_OPT_CPU,
};
-/** parse integer from integer argument */
-static int
-parse_integer_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- int *i = (int *) extra_args;
-
- *i = atoi(value);
- if (*i < 0) {
- CCP_LOG_ERR("Argument has to be positive.\n");
- return -EINVAL;
- }
-
- return 0;
-}
-
-/** parse name argument */
-static int
-parse_name_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- struct rte_cryptodev_pmd_init_params *params = extra_args;
-
- if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
- CCP_LOG_ERR("Invalid name %s, should be less than "
- "%u bytes.\n", value,
- RTE_CRYPTODEV_NAME_MAX_LEN - 1);
- return -EINVAL;
- }
-
- strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
-
- return 0;
-}
-
-/** parse authentication operation option */
-static int
-parse_auth_opt_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- struct ccp_pmd_init_params *params = extra_args;
- int i;
-
- i = atoi(value);
- if (i < CCP_PMD_AUTH_OPT_CCP || i > CCP_PMD_AUTH_OPT_CPU) {
- CCP_LOG_ERR("Invalid ccp pmd auth option. "
- "0->auth on CCP(default), "
- "1->auth on CPU\n");
- return -EINVAL;
- }
- params->auth_opt = i;
- return 0;
-}
-
-static int
-ccp_pmd_parse_input_args(struct ccp_pmd_init_params *params,
- const char *input_args)
-{
- struct rte_kvargs *kvlist = NULL;
- int ret = 0;
-
- if (params == NULL)
- return -EINVAL;
-
- if (input_args) {
- kvlist = rte_kvargs_parse(input_args,
- ccp_pmd_valid_params);
- if (kvlist == NULL)
- return -1;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_MAX_NB_QP,
- &parse_integer_arg,
- ¶ms->def_p.max_nb_queue_pairs);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_SOCKET_ID,
- &parse_integer_arg,
- ¶ms->def_p.socket_id);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_NAME,
- &parse_name_arg,
- ¶ms->def_p);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_AUTH_OPT,
- &parse_auth_opt_arg,
- params);
- if (ret < 0)
- goto free_kvlist;
-
- }
-
-free_kvlist:
- rte_kvargs_free(kvlist);
- return ret;
-}
-
static struct ccp_session *
get_ccp_session(struct ccp_qp *qp, struct rte_crypto_op *op)
{
@@ -300,12 +195,21 @@ static struct rte_pci_id ccp_pci_id[] = {
/** Remove ccp pmd */
static int
-cryptodev_ccp_remove(struct rte_vdev_device *dev)
+cryptodev_ccp_remove(struct rte_pci_device *pci_dev)
{
- const char *name;
+ char name[RTE_CRYPTODEV_NAME_MAX_LEN];
+ struct rte_cryptodev *dev;
+
+ if (pci_dev == NULL)
+ return -EINVAL;
+
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+
+ dev = rte_cryptodev_pmd_get_named_dev(name);
+ if (dev == NULL)
+ return -ENODEV;
ccp_pmd_init_done = 0;
- name = rte_vdev_device_name(dev);
rte_free(sha_ctx);
if (name == NULL)
return -EINVAL;
@@ -313,14 +217,15 @@ cryptodev_ccp_remove(struct rte_vdev_device *dev)
RTE_LOG(INFO, PMD, "Closing ccp device %s on numa socket %u\n",
name, rte_socket_id());
- return 0;
+ return rte_cryptodev_pmd_destroy(dev);
}
/** Create crypto device */
static int
cryptodev_ccp_create(const char *name,
- struct rte_vdev_device *vdev,
- struct ccp_pmd_init_params *init_params)
+ struct rte_pci_device *pci_dev,
+ struct ccp_pmd_init_params *init_params,
+ struct rte_pci_driver *pci_drv)
{
struct rte_cryptodev *dev;
struct ccp_private *internals;
@@ -330,14 +235,14 @@ cryptodev_ccp_create(const char *name,
sizeof(init_params->def_p.name));
dev = rte_cryptodev_pmd_create(init_params->def_p.name,
- &vdev->device,
+ &pci_dev->device,
&init_params->def_p);
if (dev == NULL) {
CCP_LOG_ERR("failed to create cryptodev vdev");
goto init_error;
}
- cryptodev_cnt = ccp_probe_devices(ccp_pci_id);
+ cryptodev_cnt = ccp_probe_devices(pci_dev, ccp_pci_id);
if (cryptodev_cnt == 0) {
CCP_LOG_ERR("failed to detect CCP crypto device");
@@ -345,6 +250,8 @@ cryptodev_ccp_create(const char *name,
}
printf("CCP : Crypto device count = %d\n", cryptodev_cnt);
+ dev->device = &pci_dev->device;
+ dev->device->driver = &pci_drv->driver;
dev->driver_id = ccp_cryptodev_driver_id;
/* register rx/tx burst functions for data path */
@@ -368,17 +275,18 @@ cryptodev_ccp_create(const char *name,
init_error:
CCP_LOG_ERR("driver %s: %s() failed",
init_params->def_p.name, __func__);
- cryptodev_ccp_remove(vdev);
+ cryptodev_ccp_remove(pci_dev);
return -EFAULT;
}
/** Probe ccp pmd */
static int
-cryptodev_ccp_probe(struct rte_vdev_device *vdev)
+cryptodev_ccp_probe(struct rte_pci_driver *pci_drv __rte_unused,
+ struct rte_pci_device *pci_dev)
{
int rc = 0;
- const char *name;
+ char name[RTE_CRYPTODEV_NAME_MAX_LEN];
struct ccp_pmd_init_params init_params = {
.def_p = {
"",
@@ -388,19 +296,16 @@ cryptodev_ccp_probe(struct rte_vdev_device *vdev)
},
.auth_opt = CCP_PMD_AUTH_OPT_CCP,
};
- const char *input_args;
sha_ctx = (void *)rte_malloc(NULL, SHA512_DIGEST_SIZE, 64);
if (ccp_pmd_init_done) {
RTE_LOG(INFO, PMD, "CCP PMD already initialized\n");
return -EFAULT;
}
- name = rte_vdev_device_name(vdev);
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
if (name == NULL)
return -EINVAL;
- input_args = rte_vdev_device_args(vdev);
- ccp_pmd_parse_input_args(&init_params, input_args);
init_params.def_p.max_nb_queue_pairs = CCP_PMD_MAX_QUEUE_PAIRS;
RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
@@ -410,21 +315,26 @@ cryptodev_ccp_probe(struct rte_vdev_device *vdev)
RTE_LOG(INFO, PMD, "Authentication offload to %s\n",
((init_params.auth_opt == 0) ? "CCP" : "CPU"));
- rc = cryptodev_ccp_create(name, vdev, &init_params);
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+
+ rc = cryptodev_ccp_create(name, pci_dev, &init_params, pci_drv);
if (rc)
return rc;
ccp_pmd_init_done = 1;
return 0;
}
-static struct rte_vdev_driver cryptodev_ccp_pmd_drv = {
+static struct rte_pci_driver cryptodev_ccp_pmd_drv = {
+ .id_table = ccp_pci_id,
+ .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
.probe = cryptodev_ccp_probe,
.remove = cryptodev_ccp_remove
};
static struct cryptodev_driver ccp_crypto_drv;
-RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_CCP_PMD, cryptodev_ccp_pmd_drv);
+RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_CCP_PMD, cryptodev_ccp_pmd_drv);
+RTE_PMD_REGISTER_KMOD_DEP(CRYPTODEV_NAME_CCP_PMD, "* igb_uio | uio_pci_generic | vfio-pci");
RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_CCP_PMD,
"max_nb_queue_pairs=<int> "
"socket_id=<int> "
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [dpdk-dev] [PATCH v2] crypto/ccp: moving vdev to PCI driver
2021-07-16 8:47 [dpdk-dev] [PATCH v1] crypto/ccp: moving vdev to PCI driver asomalap
@ 2021-07-16 10:41 ` asomalap
2021-07-16 10:49 ` [dpdk-dev] [PATCH v3] " asomalap
0 siblings, 1 reply; 3+ messages in thread
From: asomalap @ 2021-07-16 10:41 UTC (permalink / raw)
To: dev
From: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
drop all the code duplicating the PCI bus driver
develped for Enable IOMMU in vdev.
Signed-off-by: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
---
drivers/crypto/ccp/ccp_dev.c | 66 +------------
drivers/crypto/ccp/ccp_dev.h | 3 +-
drivers/crypto/ccp/rte_ccp_pmd.c | 158 +++++++------------------------
3 files changed, 41 insertions(+), 186 deletions(-)
diff --git a/drivers/crypto/ccp/ccp_dev.c b/drivers/crypto/ccp/ccp_dev.c
index ee6882b8a4..0eb1b0328e 100644
--- a/drivers/crypto/ccp/ccp_dev.c
+++ b/drivers/crypto/ccp/ccp_dev.c
@@ -650,73 +650,17 @@ is_ccp_device(const char *dirname,
}
static int
-ccp_probe_device(const char *dirname, uint16_t domain,
- uint8_t bus, uint8_t devid,
- uint8_t function, int ccp_type)
+ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev)
{
struct ccp_device *ccp_dev = NULL;
- struct rte_pci_device *pci;
- char filename[PATH_MAX];
- unsigned long tmp;
int uio_fd = -1;
ccp_dev = rte_zmalloc("ccp_device", sizeof(*ccp_dev),
RTE_CACHE_LINE_SIZE);
if (ccp_dev == NULL)
goto fail;
- pci = &(ccp_dev->pci);
-
- pci->addr.domain = domain;
- pci->addr.bus = bus;
- pci->addr.devid = devid;
- pci->addr.function = function;
-
- /* get vendor id */
- snprintf(filename, sizeof(filename), "%s/vendor", dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.vendor_id = (uint16_t)tmp;
-
- /* get device id */
- snprintf(filename, sizeof(filename), "%s/device", dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.device_id = (uint16_t)tmp;
-
- /* get subsystem_vendor id */
- snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.subsystem_vendor_id = (uint16_t)tmp;
-
- /* get subsystem_device id */
- snprintf(filename, sizeof(filename), "%s/subsystem_device",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.subsystem_device_id = (uint16_t)tmp;
-
- /* get class_id */
- snprintf(filename, sizeof(filename), "%s/class",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- /* the least 24 bits are valid: class, subclass, program interface */
- pci->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID;
-
- /* parse resources */
- snprintf(filename, sizeof(filename), "%s/resource", dirname);
- if (ccp_pci_parse_sysfs_resource(filename, pci) < 0)
- goto fail;
- if (iommu_mode == 2)
- pci->kdrv = RTE_PCI_KDRV_VFIO;
- else if (iommu_mode == 0)
- pci->kdrv = RTE_PCI_KDRV_IGB_UIO;
- else if (iommu_mode == 1)
- pci->kdrv = RTE_PCI_KDRV_UIO_GENERIC;
- rte_pci_map_device(pci);
+ ccp_dev->pci = *pci_dev;
/* device is valid, add in list */
if (ccp_add_device(ccp_dev, ccp_type)) {
@@ -735,7 +679,8 @@ ccp_probe_device(const char *dirname, uint16_t domain,
}
int
-ccp_probe_devices(const struct rte_pci_id *ccp_id)
+ccp_probe_devices(struct rte_pci_device *pci_dev,
+ const struct rte_pci_id *ccp_id)
{
int dev_cnt = 0;
int ccp_type = 0;
@@ -767,8 +712,7 @@ ccp_probe_devices(const struct rte_pci_id *ccp_id)
if (is_ccp_device(dirname, ccp_id, &ccp_type)) {
printf("CCP : Detected CCP device with ID = 0x%x\n",
ccp_id[ccp_type].device_id);
- ret = ccp_probe_device(dirname, domain, bus, devid,
- function, ccp_type);
+ ret = ccp_probe_device(ccp_type, pci_dev);
if (ret == 0)
dev_cnt++;
}
diff --git a/drivers/crypto/ccp/ccp_dev.h b/drivers/crypto/ccp/ccp_dev.h
index 37e04218ce..ca5145c278 100644
--- a/drivers/crypto/ccp/ccp_dev.h
+++ b/drivers/crypto/ccp/ccp_dev.h
@@ -473,7 +473,8 @@ int ccp_dev_start(struct rte_cryptodev *dev);
* @param ccp_id rte_pci_id list for supported CCP devices
* @return no. of successfully initialized CCP devices
*/
-int ccp_probe_devices(const struct rte_pci_id *ccp_id);
+int ccp_probe_devices(struct rte_pci_device *pci_dev,
+ const struct rte_pci_id *ccp_id);
/**
* allocate a ccp command queue
diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c
index ba379a19f3..ad0bbde1f3 100644
--- a/drivers/crypto/ccp/rte_ccp_pmd.c
+++ b/drivers/crypto/ccp/rte_ccp_pmd.c
@@ -47,111 +47,6 @@ enum ccp_pmd_auth_opt {
CCP_PMD_AUTH_OPT_CPU,
};
-/** parse integer from integer argument */
-static int
-parse_integer_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- int *i = (int *) extra_args;
-
- *i = atoi(value);
- if (*i < 0) {
- CCP_LOG_ERR("Argument has to be positive.\n");
- return -EINVAL;
- }
-
- return 0;
-}
-
-/** parse name argument */
-static int
-parse_name_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- struct rte_cryptodev_pmd_init_params *params = extra_args;
-
- if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
- CCP_LOG_ERR("Invalid name %s, should be less than "
- "%u bytes.\n", value,
- RTE_CRYPTODEV_NAME_MAX_LEN - 1);
- return -EINVAL;
- }
-
- strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
-
- return 0;
-}
-
-/** parse authentication operation option */
-static int
-parse_auth_opt_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- struct ccp_pmd_init_params *params = extra_args;
- int i;
-
- i = atoi(value);
- if (i < CCP_PMD_AUTH_OPT_CCP || i > CCP_PMD_AUTH_OPT_CPU) {
- CCP_LOG_ERR("Invalid ccp pmd auth option. "
- "0->auth on CCP(default), "
- "1->auth on CPU\n");
- return -EINVAL;
- }
- params->auth_opt = i;
- return 0;
-}
-
-static int
-ccp_pmd_parse_input_args(struct ccp_pmd_init_params *params,
- const char *input_args)
-{
- struct rte_kvargs *kvlist = NULL;
- int ret = 0;
-
- if (params == NULL)
- return -EINVAL;
-
- if (input_args) {
- kvlist = rte_kvargs_parse(input_args,
- ccp_pmd_valid_params);
- if (kvlist == NULL)
- return -1;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_MAX_NB_QP,
- &parse_integer_arg,
- ¶ms->def_p.max_nb_queue_pairs);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_SOCKET_ID,
- &parse_integer_arg,
- ¶ms->def_p.socket_id);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_NAME,
- &parse_name_arg,
- ¶ms->def_p);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_AUTH_OPT,
- &parse_auth_opt_arg,
- params);
- if (ret < 0)
- goto free_kvlist;
-
- }
-
-free_kvlist:
- rte_kvargs_free(kvlist);
- return ret;
-}
-
static struct ccp_session *
get_ccp_session(struct ccp_qp *qp, struct rte_crypto_op *op)
{
@@ -300,12 +195,21 @@ static struct rte_pci_id ccp_pci_id[] = {
/** Remove ccp pmd */
static int
-cryptodev_ccp_remove(struct rte_vdev_device *dev)
+cryptodev_ccp_remove(struct rte_pci_device *pci_dev)
{
- const char *name;
+ char name[RTE_CRYPTODEV_NAME_MAX_LEN];
+ struct rte_cryptodev *dev;
+
+ if (pci_dev == NULL)
+ return -EINVAL;
+
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+
+ dev = rte_cryptodev_pmd_get_named_dev(name);
+ if (dev == NULL)
+ return -ENODEV;
ccp_pmd_init_done = 0;
- name = rte_vdev_device_name(dev);
rte_free(sha_ctx);
if (name == NULL)
return -EINVAL;
@@ -313,14 +217,15 @@ cryptodev_ccp_remove(struct rte_vdev_device *dev)
RTE_LOG(INFO, PMD, "Closing ccp device %s on numa socket %u\n",
name, rte_socket_id());
- return 0;
+ return rte_cryptodev_pmd_destroy(dev);
}
/** Create crypto device */
static int
cryptodev_ccp_create(const char *name,
- struct rte_vdev_device *vdev,
- struct ccp_pmd_init_params *init_params)
+ struct rte_pci_device *pci_dev,
+ struct ccp_pmd_init_params *init_params,
+ struct rte_pci_driver *pci_drv)
{
struct rte_cryptodev *dev;
struct ccp_private *internals;
@@ -330,14 +235,14 @@ cryptodev_ccp_create(const char *name,
sizeof(init_params->def_p.name));
dev = rte_cryptodev_pmd_create(init_params->def_p.name,
- &vdev->device,
+ &pci_dev->device,
&init_params->def_p);
if (dev == NULL) {
CCP_LOG_ERR("failed to create cryptodev vdev");
goto init_error;
}
- cryptodev_cnt = ccp_probe_devices(ccp_pci_id);
+ cryptodev_cnt = ccp_probe_devices(pci_dev, ccp_pci_id);
if (cryptodev_cnt == 0) {
CCP_LOG_ERR("failed to detect CCP crypto device");
@@ -345,6 +250,8 @@ cryptodev_ccp_create(const char *name,
}
printf("CCP : Crypto device count = %d\n", cryptodev_cnt);
+ dev->device = &pci_dev->device;
+ dev->device->driver = &pci_drv->driver;
dev->driver_id = ccp_cryptodev_driver_id;
/* register rx/tx burst functions for data path */
@@ -368,17 +275,18 @@ cryptodev_ccp_create(const char *name,
init_error:
CCP_LOG_ERR("driver %s: %s() failed",
init_params->def_p.name, __func__);
- cryptodev_ccp_remove(vdev);
+ cryptodev_ccp_remove(pci_dev);
return -EFAULT;
}
/** Probe ccp pmd */
static int
-cryptodev_ccp_probe(struct rte_vdev_device *vdev)
+cryptodev_ccp_probe(struct rte_pci_driver *pci_drv __rte_unused,
+ struct rte_pci_device *pci_dev)
{
int rc = 0;
- const char *name;
+ char name[RTE_CRYPTODEV_NAME_MAX_LEN];
struct ccp_pmd_init_params init_params = {
.def_p = {
"",
@@ -388,19 +296,16 @@ cryptodev_ccp_probe(struct rte_vdev_device *vdev)
},
.auth_opt = CCP_PMD_AUTH_OPT_CCP,
};
- const char *input_args;
sha_ctx = (void *)rte_malloc(NULL, SHA512_DIGEST_SIZE, 64);
if (ccp_pmd_init_done) {
RTE_LOG(INFO, PMD, "CCP PMD already initialized\n");
return -EFAULT;
}
- name = rte_vdev_device_name(vdev);
- if (name == NULL)
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+ if (name == '\0')
return -EINVAL;
- input_args = rte_vdev_device_args(vdev);
- ccp_pmd_parse_input_args(&init_params, input_args);
init_params.def_p.max_nb_queue_pairs = CCP_PMD_MAX_QUEUE_PAIRS;
RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
@@ -410,21 +315,26 @@ cryptodev_ccp_probe(struct rte_vdev_device *vdev)
RTE_LOG(INFO, PMD, "Authentication offload to %s\n",
((init_params.auth_opt == 0) ? "CCP" : "CPU"));
- rc = cryptodev_ccp_create(name, vdev, &init_params);
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+
+ rc = cryptodev_ccp_create(name, pci_dev, &init_params, pci_drv);
if (rc)
return rc;
ccp_pmd_init_done = 1;
return 0;
}
-static struct rte_vdev_driver cryptodev_ccp_pmd_drv = {
+static struct rte_pci_driver cryptodev_ccp_pmd_drv = {
+ .id_table = ccp_pci_id,
+ .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
.probe = cryptodev_ccp_probe,
.remove = cryptodev_ccp_remove
};
static struct cryptodev_driver ccp_crypto_drv;
-RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_CCP_PMD, cryptodev_ccp_pmd_drv);
+RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_CCP_PMD, cryptodev_ccp_pmd_drv);
+RTE_PMD_REGISTER_KMOD_DEP(CRYPTODEV_NAME_CCP_PMD, "* igb_uio | uio_pci_generic | vfio-pci");
RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_CCP_PMD,
"max_nb_queue_pairs=<int> "
"socket_id=<int> "
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [dpdk-dev] [PATCH v3] crypto/ccp: moving vdev to PCI driver
2021-07-16 10:41 ` [dpdk-dev] [PATCH v2] " asomalap
@ 2021-07-16 10:49 ` asomalap
0 siblings, 0 replies; 3+ messages in thread
From: asomalap @ 2021-07-16 10:49 UTC (permalink / raw)
To: dev
From: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
drop all the code duplicating the PCI bus driver
develped for Enable IOMMU in vdev.
Signed-off-by: Amaranath Somalapuram <Amaranath.Somalapuram@amd.com>
---
drivers/crypto/ccp/ccp_dev.c | 66 +------------
drivers/crypto/ccp/ccp_dev.h | 3 +-
drivers/crypto/ccp/rte_ccp_pmd.c | 158 +++++++------------------------
3 files changed, 41 insertions(+), 186 deletions(-)
diff --git a/drivers/crypto/ccp/ccp_dev.c b/drivers/crypto/ccp/ccp_dev.c
index ee6882b8a4..0eb1b0328e 100644
--- a/drivers/crypto/ccp/ccp_dev.c
+++ b/drivers/crypto/ccp/ccp_dev.c
@@ -650,73 +650,17 @@ is_ccp_device(const char *dirname,
}
static int
-ccp_probe_device(const char *dirname, uint16_t domain,
- uint8_t bus, uint8_t devid,
- uint8_t function, int ccp_type)
+ccp_probe_device(int ccp_type, struct rte_pci_device *pci_dev)
{
struct ccp_device *ccp_dev = NULL;
- struct rte_pci_device *pci;
- char filename[PATH_MAX];
- unsigned long tmp;
int uio_fd = -1;
ccp_dev = rte_zmalloc("ccp_device", sizeof(*ccp_dev),
RTE_CACHE_LINE_SIZE);
if (ccp_dev == NULL)
goto fail;
- pci = &(ccp_dev->pci);
-
- pci->addr.domain = domain;
- pci->addr.bus = bus;
- pci->addr.devid = devid;
- pci->addr.function = function;
-
- /* get vendor id */
- snprintf(filename, sizeof(filename), "%s/vendor", dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.vendor_id = (uint16_t)tmp;
-
- /* get device id */
- snprintf(filename, sizeof(filename), "%s/device", dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.device_id = (uint16_t)tmp;
-
- /* get subsystem_vendor id */
- snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.subsystem_vendor_id = (uint16_t)tmp;
-
- /* get subsystem_device id */
- snprintf(filename, sizeof(filename), "%s/subsystem_device",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- pci->id.subsystem_device_id = (uint16_t)tmp;
-
- /* get class_id */
- snprintf(filename, sizeof(filename), "%s/class",
- dirname);
- if (ccp_pci_parse_sysfs_value(filename, &tmp) < 0)
- goto fail;
- /* the least 24 bits are valid: class, subclass, program interface */
- pci->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID;
-
- /* parse resources */
- snprintf(filename, sizeof(filename), "%s/resource", dirname);
- if (ccp_pci_parse_sysfs_resource(filename, pci) < 0)
- goto fail;
- if (iommu_mode == 2)
- pci->kdrv = RTE_PCI_KDRV_VFIO;
- else if (iommu_mode == 0)
- pci->kdrv = RTE_PCI_KDRV_IGB_UIO;
- else if (iommu_mode == 1)
- pci->kdrv = RTE_PCI_KDRV_UIO_GENERIC;
- rte_pci_map_device(pci);
+ ccp_dev->pci = *pci_dev;
/* device is valid, add in list */
if (ccp_add_device(ccp_dev, ccp_type)) {
@@ -735,7 +679,8 @@ ccp_probe_device(const char *dirname, uint16_t domain,
}
int
-ccp_probe_devices(const struct rte_pci_id *ccp_id)
+ccp_probe_devices(struct rte_pci_device *pci_dev,
+ const struct rte_pci_id *ccp_id)
{
int dev_cnt = 0;
int ccp_type = 0;
@@ -767,8 +712,7 @@ ccp_probe_devices(const struct rte_pci_id *ccp_id)
if (is_ccp_device(dirname, ccp_id, &ccp_type)) {
printf("CCP : Detected CCP device with ID = 0x%x\n",
ccp_id[ccp_type].device_id);
- ret = ccp_probe_device(dirname, domain, bus, devid,
- function, ccp_type);
+ ret = ccp_probe_device(ccp_type, pci_dev);
if (ret == 0)
dev_cnt++;
}
diff --git a/drivers/crypto/ccp/ccp_dev.h b/drivers/crypto/ccp/ccp_dev.h
index 37e04218ce..ca5145c278 100644
--- a/drivers/crypto/ccp/ccp_dev.h
+++ b/drivers/crypto/ccp/ccp_dev.h
@@ -473,7 +473,8 @@ int ccp_dev_start(struct rte_cryptodev *dev);
* @param ccp_id rte_pci_id list for supported CCP devices
* @return no. of successfully initialized CCP devices
*/
-int ccp_probe_devices(const struct rte_pci_id *ccp_id);
+int ccp_probe_devices(struct rte_pci_device *pci_dev,
+ const struct rte_pci_id *ccp_id);
/**
* allocate a ccp command queue
diff --git a/drivers/crypto/ccp/rte_ccp_pmd.c b/drivers/crypto/ccp/rte_ccp_pmd.c
index ba379a19f3..84a650d9f5 100644
--- a/drivers/crypto/ccp/rte_ccp_pmd.c
+++ b/drivers/crypto/ccp/rte_ccp_pmd.c
@@ -47,111 +47,6 @@ enum ccp_pmd_auth_opt {
CCP_PMD_AUTH_OPT_CPU,
};
-/** parse integer from integer argument */
-static int
-parse_integer_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- int *i = (int *) extra_args;
-
- *i = atoi(value);
- if (*i < 0) {
- CCP_LOG_ERR("Argument has to be positive.\n");
- return -EINVAL;
- }
-
- return 0;
-}
-
-/** parse name argument */
-static int
-parse_name_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- struct rte_cryptodev_pmd_init_params *params = extra_args;
-
- if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
- CCP_LOG_ERR("Invalid name %s, should be less than "
- "%u bytes.\n", value,
- RTE_CRYPTODEV_NAME_MAX_LEN - 1);
- return -EINVAL;
- }
-
- strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
-
- return 0;
-}
-
-/** parse authentication operation option */
-static int
-parse_auth_opt_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- struct ccp_pmd_init_params *params = extra_args;
- int i;
-
- i = atoi(value);
- if (i < CCP_PMD_AUTH_OPT_CCP || i > CCP_PMD_AUTH_OPT_CPU) {
- CCP_LOG_ERR("Invalid ccp pmd auth option. "
- "0->auth on CCP(default), "
- "1->auth on CPU\n");
- return -EINVAL;
- }
- params->auth_opt = i;
- return 0;
-}
-
-static int
-ccp_pmd_parse_input_args(struct ccp_pmd_init_params *params,
- const char *input_args)
-{
- struct rte_kvargs *kvlist = NULL;
- int ret = 0;
-
- if (params == NULL)
- return -EINVAL;
-
- if (input_args) {
- kvlist = rte_kvargs_parse(input_args,
- ccp_pmd_valid_params);
- if (kvlist == NULL)
- return -1;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_MAX_NB_QP,
- &parse_integer_arg,
- ¶ms->def_p.max_nb_queue_pairs);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_SOCKET_ID,
- &parse_integer_arg,
- ¶ms->def_p.socket_id);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_NAME,
- &parse_name_arg,
- ¶ms->def_p);
- if (ret < 0)
- goto free_kvlist;
-
- ret = rte_kvargs_process(kvlist,
- CCP_CRYPTODEV_PARAM_AUTH_OPT,
- &parse_auth_opt_arg,
- params);
- if (ret < 0)
- goto free_kvlist;
-
- }
-
-free_kvlist:
- rte_kvargs_free(kvlist);
- return ret;
-}
-
static struct ccp_session *
get_ccp_session(struct ccp_qp *qp, struct rte_crypto_op *op)
{
@@ -300,12 +195,21 @@ static struct rte_pci_id ccp_pci_id[] = {
/** Remove ccp pmd */
static int
-cryptodev_ccp_remove(struct rte_vdev_device *dev)
+cryptodev_ccp_remove(struct rte_pci_device *pci_dev)
{
- const char *name;
+ char name[RTE_CRYPTODEV_NAME_MAX_LEN];
+ struct rte_cryptodev *dev;
+
+ if (pci_dev == NULL)
+ return -EINVAL;
+
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+
+ dev = rte_cryptodev_pmd_get_named_dev(name);
+ if (dev == NULL)
+ return -ENODEV;
ccp_pmd_init_done = 0;
- name = rte_vdev_device_name(dev);
rte_free(sha_ctx);
if (name == NULL)
return -EINVAL;
@@ -313,14 +217,15 @@ cryptodev_ccp_remove(struct rte_vdev_device *dev)
RTE_LOG(INFO, PMD, "Closing ccp device %s on numa socket %u\n",
name, rte_socket_id());
- return 0;
+ return rte_cryptodev_pmd_destroy(dev);
}
/** Create crypto device */
static int
cryptodev_ccp_create(const char *name,
- struct rte_vdev_device *vdev,
- struct ccp_pmd_init_params *init_params)
+ struct rte_pci_device *pci_dev,
+ struct ccp_pmd_init_params *init_params,
+ struct rte_pci_driver *pci_drv)
{
struct rte_cryptodev *dev;
struct ccp_private *internals;
@@ -330,14 +235,14 @@ cryptodev_ccp_create(const char *name,
sizeof(init_params->def_p.name));
dev = rte_cryptodev_pmd_create(init_params->def_p.name,
- &vdev->device,
+ &pci_dev->device,
&init_params->def_p);
if (dev == NULL) {
CCP_LOG_ERR("failed to create cryptodev vdev");
goto init_error;
}
- cryptodev_cnt = ccp_probe_devices(ccp_pci_id);
+ cryptodev_cnt = ccp_probe_devices(pci_dev, ccp_pci_id);
if (cryptodev_cnt == 0) {
CCP_LOG_ERR("failed to detect CCP crypto device");
@@ -345,6 +250,8 @@ cryptodev_ccp_create(const char *name,
}
printf("CCP : Crypto device count = %d\n", cryptodev_cnt);
+ dev->device = &pci_dev->device;
+ dev->device->driver = &pci_drv->driver;
dev->driver_id = ccp_cryptodev_driver_id;
/* register rx/tx burst functions for data path */
@@ -368,17 +275,18 @@ cryptodev_ccp_create(const char *name,
init_error:
CCP_LOG_ERR("driver %s: %s() failed",
init_params->def_p.name, __func__);
- cryptodev_ccp_remove(vdev);
+ cryptodev_ccp_remove(pci_dev);
return -EFAULT;
}
/** Probe ccp pmd */
static int
-cryptodev_ccp_probe(struct rte_vdev_device *vdev)
+cryptodev_ccp_probe(struct rte_pci_driver *pci_drv __rte_unused,
+ struct rte_pci_device *pci_dev)
{
int rc = 0;
- const char *name;
+ char name[RTE_CRYPTODEV_NAME_MAX_LEN];
struct ccp_pmd_init_params init_params = {
.def_p = {
"",
@@ -388,19 +296,16 @@ cryptodev_ccp_probe(struct rte_vdev_device *vdev)
},
.auth_opt = CCP_PMD_AUTH_OPT_CCP,
};
- const char *input_args;
sha_ctx = (void *)rte_malloc(NULL, SHA512_DIGEST_SIZE, 64);
if (ccp_pmd_init_done) {
RTE_LOG(INFO, PMD, "CCP PMD already initialized\n");
return -EFAULT;
}
- name = rte_vdev_device_name(vdev);
- if (name == NULL)
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+ if (name[0] == '\0')
return -EINVAL;
- input_args = rte_vdev_device_args(vdev);
- ccp_pmd_parse_input_args(&init_params, input_args);
init_params.def_p.max_nb_queue_pairs = CCP_PMD_MAX_QUEUE_PAIRS;
RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
@@ -410,21 +315,26 @@ cryptodev_ccp_probe(struct rte_vdev_device *vdev)
RTE_LOG(INFO, PMD, "Authentication offload to %s\n",
((init_params.auth_opt == 0) ? "CCP" : "CPU"));
- rc = cryptodev_ccp_create(name, vdev, &init_params);
+ rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
+
+ rc = cryptodev_ccp_create(name, pci_dev, &init_params, pci_drv);
if (rc)
return rc;
ccp_pmd_init_done = 1;
return 0;
}
-static struct rte_vdev_driver cryptodev_ccp_pmd_drv = {
+static struct rte_pci_driver cryptodev_ccp_pmd_drv = {
+ .id_table = ccp_pci_id,
+ .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
.probe = cryptodev_ccp_probe,
.remove = cryptodev_ccp_remove
};
static struct cryptodev_driver ccp_crypto_drv;
-RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_CCP_PMD, cryptodev_ccp_pmd_drv);
+RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_CCP_PMD, cryptodev_ccp_pmd_drv);
+RTE_PMD_REGISTER_KMOD_DEP(CRYPTODEV_NAME_CCP_PMD, "* igb_uio | uio_pci_generic | vfio-pci");
RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_CCP_PMD,
"max_nb_queue_pairs=<int> "
"socket_id=<int> "
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-16 10:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-16 8:47 [dpdk-dev] [PATCH v1] crypto/ccp: moving vdev to PCI driver asomalap
2021-07-16 10:41 ` [dpdk-dev] [PATCH v2] " asomalap
2021-07-16 10:49 ` [dpdk-dev] [PATCH v3] " asomalap
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).