@@ -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,
@@ -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);
@@ -89,14 +88,19 @@ queue_dma_zone_reserve(const char *queue_name, uint32_t queue_size,
memzone_flags, 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)) {
PMD_DRV_LOG(ERR, "Can't create qp for %u descriptors",
@@ -104,8 +108,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?).");
@@ -132,14 +134,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);
@@ -152,7 +154,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)
@@ -174,13 +176,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:
@@ -188,10 +192,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();
@@ -200,6 +203,9 @@ int qat_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
return 0;
}
+ PMD_DRV_LOG(DEBUG, "Free qp %u on device %d",
+ qp->queue_pair_id, 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));
@@ -218,13 +224,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;
@@ -234,6 +238,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. */
@@ -249,13 +256,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);
@@ -270,15 +277,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);
@@ -308,12 +313,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");
@@ -336,6 +335,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:
@@ -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_ */
@@ -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++) {
@@ -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;