DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev v1] crypto/ipsec_mb: multi-process IPC request handler
@ 2022-10-20 23:51 Kai Ji
  2022-10-24 23:38 ` [dpdk-dev v2] " Kai Ji
  0 siblings, 1 reply; 14+ messages in thread
From: Kai Ji @ 2022-10-20 23:51 UTC (permalink / raw)
  To: dev; +Cc: Kai Ji, Pablo de Lara, Anatoly Burakov

As the secondary process needs queue-pair to be configured by
the primary process before use. This patch adds an IPC register function
to allow secondary process to setup cryptodev queue-pair via IPC messages
during the runtime. A new "qp_in_used_pid" param stores the PID to provide
the ownership of the queue-pair so that only the PID matched queue-pair
can be free'd in the request.

Signed-off-by: Kai Ji <kai.ji@intel.com>
---
 drivers/crypto/ipsec_mb/ipsec_mb_ops.c     | 69 ++++++++++++++++++++++
 drivers/crypto/ipsec_mb/ipsec_mb_private.c | 22 ++++++-
 drivers/crypto/ipsec_mb/ipsec_mb_private.h | 33 +++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
index cedcaa2742..abeef364d1 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
@@ -296,6 +296,75 @@ ipsec_mb_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
 	return ret;
 }
 
+int
+ipsec_mb_ipc_request(const struct rte_mp_msg *mp_msg, const void *peer)
+{
+	struct rte_mp_msg mp_res;
+	struct ipsec_mb_mp_param *resp_param =
+		(struct ipsec_mb_mp_param *)mp_res.param;
+	const struct ipsec_mb_mp_param *req_param =
+		(const struct ipsec_mb_mp_param *)mp_msg->param;
+
+	int ret;
+	struct rte_cryptodev *dev;
+	struct ipsec_mb_qp *qp;
+	int dev_id = req_param->dev_id;
+	int qp_id = req_param->qp_id;
+	struct rte_cryptodev_qp_conf *queue_conf =
+		(struct rte_cryptodev_qp_conf *)req_param->queue_conf;
+
+	resp_param->result = -EINVAL;
+	if (!rte_cryptodev_is_valid_dev(dev_id)) {
+		CDEV_LOG_ERR("Invalid dev_id=%d", dev_id);
+		goto out;
+	}
+
+	dev = rte_cryptodev_pmd_get_dev(dev_id);
+	switch (req_param->type) {
+	case RTE_IPSEC_MB_MP_REQ_QP_SET:
+		qp = dev->data->queue_pairs[qp_id];
+		if (qp)	{
+			CDEV_LOG_DEBUG("qp %d on dev %d is initialised", qp_id, dev_id);
+			goto out;
+		}
+
+		ret = ipsec_mb_qp_setup(dev, qp_id,	queue_conf, req_param->socket_id);
+		if (!ret) {
+			qp = dev->data->queue_pairs[qp_id];
+			if (!qp) {
+				CDEV_LOG_DEBUG("qp %d on dev %d is not initialised",
+					qp_id, dev_id);
+				goto out;
+			}
+			qp->qp_in_used_by_pid = req_param->process_id;
+		}
+		resp_param->result = ret;
+		break;
+	case RTE_IPSEC_MB_MP_REQ_QP_FREE:
+		qp = dev->data->queue_pairs[qp_id];
+		if (!qp) {
+			CDEV_LOG_DEBUG("qp %d on dev %d is not initialised",
+				qp_id, dev_id);
+			goto out;
+		}
+
+		if (qp->qp_in_used_by_pid != req_param->process_id) {
+			CDEV_LOG_ERR("Unable to release qp_id=%d", qp_id);
+			goto out;
+		}
+
+		qp->qp_in_used_by_pid = 0;
+		resp_param->result = ipsec_mb_qp_release(dev, qp_id);
+		break;
+	default:
+		CDEV_LOG_ERR("invalid mp request type\n");
+	}
+
+out:
+	ret = rte_mp_reply(&mp_res, peer);
+	return ret;
+}
+
 /** Return the size of the specific pmd session structure */
 unsigned
 ipsec_mb_sym_session_get_size(struct rte_cryptodev *dev)
diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_private.c b/drivers/crypto/ipsec_mb/ipsec_mb_private.c
index e56579596f..3c5cf50673 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_private.c
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_private.c
@@ -42,6 +42,22 @@ ipsec_mb_enqueue_burst(void *__qp, struct rte_crypto_op **ops,
 	return nb_enqueued;
 }
 
+static int
+ipsec_mb_mp_request_register(void)
+{
+	RTE_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
+	IPSEC_MB_LOG(INFO, "Starting register MP IPC request\n");
+	return rte_mp_action_register(IPSEC_MB_MP_REQ,
+				ipsec_mb_ipc_request);
+}
+
+static void
+ipsec_mb_mp_request_unregister(void)
+{
+	RTE_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
+	rte_mp_action_unregister(IPSEC_MB_MP_REQ);
+}
+
 int
 ipsec_mb_create(struct rte_vdev_device *vdev,
 	enum ipsec_mb_pmd_types pmd_type)
@@ -152,7 +168,9 @@ ipsec_mb_create(struct rte_vdev_device *vdev,
 	IPSEC_MB_LOG(INFO, "IPSec Multi-buffer library version used: %s\n",
 		     imb_get_version_str());
 
-	return 0;
+	retval = ipsec_mb_mp_request_register();
+
+	return retval;
 }
 
 int
@@ -187,5 +205,7 @@ ipsec_mb_remove(struct rte_vdev_device *vdev)
 	for (qp_id = 0; qp_id < cryptodev->data->nb_queue_pairs; qp_id++)
 		ipsec_mb_qp_release(cryptodev, qp_id);
 
+	ipsec_mb_mp_request_unregister();
+
 	return rte_cryptodev_pmd_destroy(cryptodev);
 }
diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_private.h b/drivers/crypto/ipsec_mb/ipsec_mb_private.h
index b56eaf061e..4c894e6688 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_private.h
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_private.h
@@ -10,6 +10,7 @@
 #else
 #include <intel-ipsec-mb.h>
 #endif
+#include <rte_cryptodev.h>
 #include <cryptodev_pmd.h>
 #include <bus_vdev_driver.h>
 
@@ -25,6 +26,9 @@
 /* Maximum length for memzone name */
 #define IPSEC_MB_MAX_MZ_NAME 32
 
+/* ipsec mbmulti-process queue pair config */
+#define IPSEC_MB_MP_REQ "ipsec_mb_mp_request"
+
 enum ipsec_mb_vector_mode {
 	IPSEC_MB_NOT_SUPPORTED = 0,
 	IPSEC_MB_SSE,
@@ -149,11 +153,40 @@ struct ipsec_mb_qp {
 	IMB_MGR *mb_mgr;
 	/* Multi buffer manager */
 	const struct rte_memzone *mb_mgr_mz;
+	/** Array of process id used for queue pairs **/
+	uint16_t qp_in_used_by_pid;
 	/* Shared memzone for storing mb_mgr */
 	__extension__ uint8_t additional_data[];
 	/**< Storing PMD specific additional data */
 };
 
+/** Request types for IPC. */
+enum ipsec_mb_mp_req_type {
+	RTE_IPSEC_MB_MP_REQ_NONE, /**< unknown event type */
+	RTE_IPSEC_MB_MP_REQ_QP_SET, /**< Queue pair setup request */
+	RTE_IPSEC_MB_MP_REQ_QP_FREE /**< Queue pair free request */
+};
+
+/** Parameters for IPC. */
+struct ipsec_mb_mp_param {
+	enum ipsec_mb_mp_req_type type; /**< IPC request type */
+	int dev_id;
+	/**< The identifier of the device */
+	int qp_id;
+	/**< The index of the queue pair to be configured */
+	int socket_id;
+	/**< Socket to allocate resources on */
+	uint16_t process_id;
+	/**< The pid who send out the requested */
+	void *queue_conf;
+	/**< A pointer of Crypto device queue pair configuration structure */
+	int result;
+	/**< The request result for response message */
+};
+
+int
+ipsec_mb_ipc_request(const struct rte_mp_msg *mp_msg, const void *peer);
+
 static __rte_always_inline void *
 ipsec_mb_get_qp_private_data(struct ipsec_mb_qp *qp)
 {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-10-27 17:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-20 23:51 [dpdk-dev v1] crypto/ipsec_mb: multi-process IPC request handler Kai Ji
2022-10-24 23:38 ` [dpdk-dev v2] " Kai Ji
2022-10-25 21:48   ` [dpdk-dev v3] " Kai Ji
2022-10-26  8:17     ` De Lara Guarch, Pablo
2022-10-26 10:01     ` [dpdk-dev v4] " Kai Ji
2022-10-26 10:22       ` Kai Ji
2022-10-26 10:27         ` Kai Ji
2022-10-26 11:07           ` Kusztal, ArkadiuszX
2022-10-26 12:32           ` De Lara Guarch, Pablo
2022-10-26 12:48           ` Kai Ji
2022-10-26 13:04             ` De Lara Guarch, Pablo
2022-10-26 13:19             ` [dpdk-dev v5] " Kai Ji
2022-10-27  9:54               ` [EXT] " Akhil Goyal
2022-10-27 17:57               ` Konstantin Ananyev

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).