[v3,13/38] crypto/qat: remove dependencies on cryptodev from common
diff mbox series

Message ID 1528892062-4997-14-git-send-email-tomaszx.jozwiak@intel.com
State Accepted, archived
Delegated to: Pablo de Lara Guarch
Headers show
Series
  • crypto/qat: refactor to support multiple services
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Tomasz Jozwiak June 13, 2018, 12:13 p.m. UTC
From: Fiona Trahe <fiona.trahe@intel.com>

Remove dependence on rte_cryptodev from common qp code
to facilitate being used by other device types in future.
Transferred required data into qat-specific structures.

Signed-off-by: Fiona Trahe <fiona.trahe@intel.com>
---
 drivers/crypto/qat/qat_device.h        | 11 ++++-
 drivers/crypto/qat/qat_qp.c            | 67 ++++++++++++++------------
 drivers/crypto/qat/qat_qp.h            |  8 ++-
 drivers/crypto/qat/qat_sym.c           | 15 ++++--
 drivers/crypto/qat/rte_qat_cryptodev.c |  4 +-
 5 files changed, 66 insertions(+), 39 deletions(-)

Patch
diff mbox series

diff --git a/drivers/crypto/qat/qat_device.h b/drivers/crypto/qat/qat_device.h
index 2cb8e7612..64706abae 100644
--- a/drivers/crypto/qat/qat_device.h
+++ b/drivers/crypto/qat/qat_device.h
@@ -14,7 +14,11 @@  extern uint8_t cryptodev_qat_driver_id;
 extern int qat_sym_qp_release(struct rte_cryptodev *dev,
 	uint16_t queue_pair_id);
 
-/** private data structure for each QAT device */
+/** private data structure for each QAT device.
+ * In this context a QAT device is a device offering only one service,
+ * so there can be more than 1 device on a pci_dev (VF),
+ * one for symmetric crypto, one for compression
+ */
 struct qat_pmd_private {
 	unsigned int max_nb_queue_pairs;
 	/**< Max number of queue pairs supported by device */
@@ -23,6 +27,11 @@  struct qat_pmd_private {
 	enum qat_device_gen qat_dev_gen;
 	/**< QAT device generation */
 	const struct rte_cryptodev_capabilities *qat_dev_capabilities;
+	/* QAT device capabilities */
+	struct rte_pci_device *pci_dev;
+	/**< PCI information. */
+	uint8_t dev_id;
+	/**< Device ID for this instance */
 };
 
 int qat_dev_config(struct rte_cryptodev *dev,
diff --git a/drivers/crypto/qat/qat_qp.c b/drivers/crypto/qat/qat_qp.c
index d1d2be34f..b831ab420 100644
--- a/drivers/crypto/qat/qat_qp.c
+++ b/drivers/crypto/qat/qat_qp.c
@@ -6,7 +6,6 @@ 
 #include <rte_dev.h>
 #include <rte_malloc.h>
 #include <rte_memzone.h>
-#include <rte_cryptodev_pmd.h>
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
 #include <rte_atomic.h>
@@ -31,7 +30,7 @@ 
 static int qat_qp_check_queue_alignment(uint64_t phys_addr,
 	uint32_t queue_size_bytes);
 static void qat_queue_delete(struct qat_queue *queue);
-static int qat_queue_create(struct rte_cryptodev *dev,
+static int qat_queue_create(struct qat_pmd_private *qat_dev,
 	struct qat_queue *queue, struct qat_qp_config *, uint8_t dir);
 static int adf_verify_queue_size(uint32_t msg_size, uint32_t msg_num,
 	uint32_t *queue_size_for_csr);
@@ -70,14 +69,19 @@  queue_dma_zone_reserve(const char *queue_name, uint32_t queue_size,
 		socket_id, RTE_MEMZONE_IOVA_CONTIG, queue_size);
 }
 
-int qat_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+int qat_qp_setup(struct qat_pmd_private *qat_dev,
+		struct qat_qp **qp_addr,
+		uint16_t queue_pair_id,
 		struct qat_qp_config *qat_qp_conf)
+
 {
 	struct qat_qp *qp;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = qat_dev->pci_dev;
 	char op_cookie_pool_name[RTE_RING_NAMESIZE];
 	uint32_t i;
 
+	PMD_DRV_LOG(DEBUG, "Setup qp %u on device %d gen %d",
+			queue_pair_id, qat_dev->dev_id, qat_dev->qat_dev_gen);
 
 	if ((qat_qp_conf->nb_descriptors > ADF_MAX_DESC) ||
 		(qat_qp_conf->nb_descriptors < ADF_MIN_DESC)) {
@@ -86,8 +90,6 @@  int qat_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
 		return -EINVAL;
 	}
 
-	pci_dev = RTE_DEV_TO_PCI(dev->device);
-
 	if (pci_dev->mem_resource[0].addr == NULL) {
 		PMD_DRV_LOG(ERR, "Could not find VF config space "
 				"(UIO driver attached?).");
@@ -114,14 +116,14 @@  int qat_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
 	qp->mmap_bar_addr = pci_dev->mem_resource[0].addr;
 	qp->inflights16 = 0;
 
-	if (qat_queue_create(dev, &(qp->tx_q), qat_qp_conf,
+	if (qat_queue_create(qat_dev, &(qp->tx_q), qat_qp_conf,
 					ADF_RING_DIR_TX) != 0) {
 		PMD_INIT_LOG(ERR, "Tx queue create failed "
 				"queue_pair_id=%u", queue_pair_id);
 		goto create_err;
 	}
 
-	if (qat_queue_create(dev, &(qp->rx_q), qat_qp_conf,
+	if (qat_queue_create(qat_dev, &(qp->rx_q), qat_qp_conf,
 					ADF_RING_DIR_RX) != 0) {
 		PMD_DRV_LOG(ERR, "Rx queue create failed "
 				"queue_pair_id=%hu", queue_pair_id);
@@ -134,7 +136,7 @@  int qat_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
 
 	snprintf(op_cookie_pool_name, RTE_RING_NAMESIZE, "%s_%s_qp_op_%d_%hu",
 		pci_dev->driver->driver.name, qat_qp_conf->service_str,
-		dev->data->dev_id, queue_pair_id);
+		qat_dev->dev_id, queue_pair_id);
 
 	qp->op_cookie_pool = rte_mempool_lookup(op_cookie_pool_name);
 	if (qp->op_cookie_pool == NULL)
@@ -156,13 +158,15 @@  int qat_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
 		}
 	}
 
-	struct qat_pmd_private *internals
-		= dev->data->dev_private;
-	qp->qat_dev_gen = internals->qat_dev_gen;
+	qp->qat_dev_gen = qat_dev->qat_dev_gen;
 	qp->build_request = qat_qp_conf->build_request;
 	qp->process_response = qat_qp_conf->process_response;
+	qp->qat_dev = qat_dev;
+
+	PMD_DRV_LOG(DEBUG, "QP setup complete: id: %d, cookiepool: %s",
+			queue_pair_id, op_cookie_pool_name);
 
-	dev->data->queue_pairs[queue_pair_id] = qp;
+	*qp_addr = qp;
 	return 0;
 
 create_err:
@@ -170,10 +174,9 @@  int qat_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
 	return -EFAULT;
 }
 
-int qat_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
+int qat_qp_release(struct qat_qp **qp_addr)
 {
-	struct qat_qp *qp =
-			(struct qat_qp *)dev->data->queue_pairs[queue_pair_id];
+	struct qat_qp *qp = *qp_addr;
 	uint32_t i;
 
 	PMD_INIT_FUNC_TRACE();
@@ -182,6 +185,9 @@  int qat_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
 		return 0;
 	}
 
+	PMD_DRV_LOG(DEBUG, "Free qp on qat_pci device %d",
+			qp->qat_dev->dev_id);
+
 	/* Don't free memory if there are still responses to be processed */
 	if (qp->inflights16 == 0) {
 		qat_queue_delete(&(qp->tx_q));
@@ -200,13 +206,11 @@  int qat_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
 
 	rte_free(qp->op_cookies);
 	rte_free(qp);
-	dev->data->queue_pairs[queue_pair_id] = NULL;
+	*qp_addr = NULL;
 	return 0;
 }
 
 
-
-
 static void qat_queue_delete(struct qat_queue *queue)
 {
 	const struct rte_memzone *mz;
@@ -216,6 +220,9 @@  static void qat_queue_delete(struct qat_queue *queue)
 		PMD_DRV_LOG(DEBUG, "Invalid queue");
 		return;
 	}
+	PMD_DRV_LOG(DEBUG, "Free ring %d, memzone: %s",
+			queue->hw_queue_number, queue->memz_name);
+
 	mz = rte_memzone_lookup(queue->memz_name);
 	if (mz != NULL)	{
 		/* Write an unused pattern to the queue memory. */
@@ -231,13 +238,13 @@  static void qat_queue_delete(struct qat_queue *queue)
 }
 
 static int
-qat_queue_create(struct rte_cryptodev *dev, struct qat_queue *queue,
+qat_queue_create(struct qat_pmd_private *qat_dev, struct qat_queue *queue,
 		struct qat_qp_config *qp_conf, uint8_t dir)
 {
 	uint64_t queue_base;
 	void *io_addr;
 	const struct rte_memzone *qp_mz;
-	struct rte_pci_device *pci_dev;
+	struct rte_pci_device *pci_dev = qat_dev->pci_dev;
 	int ret = 0;
 	uint16_t desc_size = (dir == ADF_RING_DIR_TX ?
 				qp_conf->tx_msg_size : qp_conf->rx_msg_size);
@@ -252,15 +259,13 @@  qat_queue_create(struct rte_cryptodev *dev, struct qat_queue *queue,
 		return -EINVAL;
 	}
 
-	pci_dev = RTE_DEV_TO_PCI(dev->device);
-
 	/*
 	 * Allocate a memzone for the queue - create a unique name.
 	 */
 	snprintf(queue->memz_name, sizeof(queue->memz_name),
 		"%s_%s_%s_%d_%d_%d",
 		pci_dev->driver->driver.name, qp_conf->service_str,
-		"qp_mem", dev->data->dev_id,
+		"qp_mem", qat_dev->dev_id,
 		queue->hw_bundle_number, queue->hw_queue_number);
 	qp_mz = queue_dma_zone_reserve(queue->memz_name, queue_size_bytes,
 			qp_conf->socket_id);
@@ -290,12 +295,6 @@  qat_queue_create(struct rte_cryptodev *dev, struct qat_queue *queue,
 	queue->max_inflights = ADF_MAX_INFLIGHTS(queue->queue_size,
 					ADF_BYTES_TO_MSG_SIZE(desc_size));
 	queue->modulo = ADF_RING_SIZE_MODULO(queue->queue_size);
-	PMD_DRV_LOG(DEBUG, "RING: Name:%s, size in CSR: %u, in bytes %u,"
-			" nb msgs %u, msg_size %u, max_inflights %u modulo %u",
-			queue->memz_name,
-			queue->queue_size, queue_size_bytes,
-			qp_conf->nb_descriptors, desc_size,
-			queue->max_inflights, queue->modulo);
 
 	if (queue->max_inflights < 2) {
 		PMD_DRV_LOG(ERR, "Invalid num inflights");
@@ -318,6 +317,14 @@  qat_queue_create(struct rte_cryptodev *dev, struct qat_queue *queue,
 
 	WRITE_CSR_RING_BASE(io_addr, queue->hw_bundle_number,
 			queue->hw_queue_number, queue_base);
+
+	PMD_DRV_LOG(DEBUG, "RING: Name:%s, size in CSR: %u, in bytes %u,"
+			" nb msgs %u, msg_size %u, max_inflights %u modulo %u",
+			queue->memz_name,
+			queue->queue_size, queue_size_bytes,
+			qp_conf->nb_descriptors, desc_size,
+			queue->max_inflights, queue->modulo);
+
 	return 0;
 
 queue_create_err:
diff --git a/drivers/crypto/qat/qat_qp.h b/drivers/crypto/qat/qat_qp.h
index 0cdf37f61..7bd8fdcec 100644
--- a/drivers/crypto/qat/qat_qp.h
+++ b/drivers/crypto/qat/qat_qp.h
@@ -5,6 +5,7 @@ 
 #define _QAT_QP_H_
 
 #include "qat_common.h"
+#include "qat_device.h"
 
 typedef int (*build_request_t)(void *op,
 		uint8_t *req, void *op_cookie,
@@ -69,6 +70,8 @@  struct qat_qp {
 	enum qat_device_gen qat_dev_gen;
 	build_request_t build_request;
 	process_response_t process_response;
+	struct qat_pmd_private *qat_dev;
+	/**< qat device this qp is on */
 } __rte_cache_aligned;
 
 uint16_t
@@ -78,9 +81,10 @@  uint16_t
 qat_dequeue_op_burst(void *qp, void **ops, uint16_t nb_ops);
 
 int
-qat_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id);
+qat_qp_release(struct qat_qp **qp_addr);
 
 int
-qat_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
+qat_qp_setup(struct qat_pmd_private *qat_dev,
+		struct qat_qp **qp_addr, uint16_t queue_pair_id,
 		struct qat_qp_config *qat_qp_conf);
 #endif /* _QAT_QP_H_ */
diff --git a/drivers/crypto/qat/qat_sym.c b/drivers/crypto/qat/qat_sym.c
index 4f86f2258..8ab95ac43 100644
--- a/drivers/crypto/qat/qat_sym.c
+++ b/drivers/crypto/qat/qat_sym.c
@@ -809,7 +809,10 @@  void qat_sym_stats_reset(struct rte_cryptodev *dev)
 
 int qat_sym_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
 {
-	return qat_qp_release(dev, queue_pair_id);
+	PMD_DRV_LOG(DEBUG, "Release sym qp %u on device %d",
+				queue_pair_id, dev->data->dev_id);
+	return qat_qp_release((struct qat_qp **)
+			&(dev->data->queue_pairs[queue_pair_id]));
 }
 
 int qat_sym_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
@@ -820,9 +823,12 @@  int qat_sym_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 	int ret = 0;
 	uint32_t i;
 	struct qat_qp_config qat_qp_conf;
+	struct qat_qp **qp_addr =
+			(struct qat_qp **)&(dev->data->queue_pairs[qp_id]);
+	struct qat_pmd_private *qat_private = dev->data->dev_private;
 
 	/* If qp is already in use free ring memory and qp metadata. */
-	if (dev->data->queue_pairs[qp_id] != NULL) {
+	if (*qp_addr != NULL) {
 		ret = qat_sym_qp_release(dev, qp_id);
 		if (ret < 0)
 			return ret;
@@ -833,7 +839,6 @@  int qat_sym_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 		return -EINVAL;
 	}
 
-
 	qat_qp_conf.hw_bundle_num = (qp_id/ADF_NUM_SYM_QPS_PER_BUNDLE);
 	qat_qp_conf.tx_ring_num = (qp_id%ADF_NUM_SYM_QPS_PER_BUNDLE) +
 			ADF_SYM_TX_QUEUE_STARTOFF;
@@ -848,11 +853,11 @@  int qat_sym_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 	qat_qp_conf.socket_id = socket_id;
 	qat_qp_conf.service_str = "sym";
 
-	ret = qat_qp_setup(dev, qp_id, &qat_qp_conf);
+	ret = qat_qp_setup(qat_private, qp_addr, qp_id, &qat_qp_conf);
 	if (ret != 0)
 		return ret;
 
-	qp = (struct qat_qp *)dev->data->queue_pairs[qp_id];
+	qp = (struct qat_qp *)*qp_addr;
 
 	for (i = 0; i < qp->nb_descriptors; i++) {
 
diff --git a/drivers/crypto/qat/rte_qat_cryptodev.c b/drivers/crypto/qat/rte_qat_cryptodev.c
index 05cb5ef40..fe19b18b6 100644
--- a/drivers/crypto/qat/rte_qat_cryptodev.c
+++ b/drivers/crypto/qat/rte_qat_cryptodev.c
@@ -96,7 +96,9 @@  crypto_qat_create(const char *name, struct rte_pci_device *pci_dev,
 
 	internals = cryptodev->data->dev_private;
 	internals->max_nb_sessions = init_params->max_nb_sessions;
-	switch (pci_dev->id.device_id) {
+	internals->pci_dev = RTE_DEV_TO_PCI(cryptodev->device);
+	internals->dev_id = cryptodev->data->dev_id;
+	switch (internals->pci_dev->id.device_id) {
 	case 0x0443:
 		internals->qat_dev_gen = QAT_GEN1;
 		internals->qat_dev_capabilities = qat_gen1_sym_capabilities;