From 81db79e24a3744239e546a5afc7aa6f7a335dc99 Mon Sep 17 00:00:00 2001 From: Rahul Pathak Date: Sun, 22 Sep 2024 13:17:48 +0530 Subject: [PATCH 1/2] Rename the queue size parameter to mention request queue Make it explicit that the queue size parameters are for a2p request and p2a request queues. Though its mentioned in the header doc but rename the parameters for clarity Signed-off-by: Rahul Pathak --- include/librpmi.h | 8 ++++---- lib/rpmi_transport_shmem.c | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/librpmi.h b/include/librpmi.h index 80833bd..c828ca8 100644 --- a/include/librpmi.h +++ b/include/librpmi.h @@ -505,15 +505,15 @@ enum rpmi_error rpmi_transport_dequeue(struct rpmi_transport *trans, * * @param[in] name name of the shared memory transport instance * @param[in] slot_size size of message slot for queues in shared memory - * @param[in] a2p_queue_size size of A2P request and P2A acknowledgement queues - * @param[in] p2a_queue_size size of P2A request and A2P acknowledgement queues + * @param[in] a2p_req_queue_size size of A2P request and P2A acknowledgement queues + * @param[in] p2a_req_queue_size size of P2A request and A2P acknowledgement queues * @param[in] shmem pointer to a RPMI shared memory instance * @return pointer to RPMI transport upon success and NULL upon failure */ struct rpmi_transport *rpmi_transport_shmem_create(const char *name, rpmi_uint32_t slot_size, - rpmi_uint32_t a2p_queue_size, - rpmi_uint32_t p2a_queue_size, + rpmi_uint32_t a2p_req_queue_size, + rpmi_uint32_t p2a_req_queue_size, struct rpmi_shmem *shmem); /** diff --git a/lib/rpmi_transport_shmem.c b/lib/rpmi_transport_shmem.c index 59b73ca..6cdbae0 100644 --- a/lib/rpmi_transport_shmem.c +++ b/lib/rpmi_transport_shmem.c @@ -167,8 +167,8 @@ static enum rpmi_error shmem_dequeue(struct rpmi_transport *trans, struct rpmi_transport *rpmi_transport_shmem_create(const char *name, rpmi_uint32_t slot_size, - rpmi_uint32_t a2p_queue_size, - rpmi_uint32_t p2a_queue_size, + rpmi_uint32_t a2p_req_queue_size, + rpmi_uint32_t p2a_req_queue_size, struct rpmi_shmem *shmem) { struct rpmi_transport_shmem_queue *shqueue; @@ -185,17 +185,17 @@ struct rpmi_transport *rpmi_transport_shmem_create(const char *name, return NULL; /* Make sure queue sizes are multiples of slot size */ - if ((a2p_queue_size & (slot_size - 1)) || - (p2a_queue_size & (slot_size - 1))) + if ((a2p_req_queue_size & (slot_size - 1)) || + (p2a_req_queue_size & (slot_size - 1))) return NULL; /* Make sure queue sizes are not less than minimum required size */ - if (a2p_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size) || - p2a_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size)) + if (a2p_req_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size) || + p2a_req_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size)) return NULL; /* Shared memory size MUST be enough to accommodate all queues */ - if (rpmi_shmem_size(shmem) < (2 * (a2p_queue_size + p2a_queue_size))) + if (rpmi_shmem_size(shmem) < (2 * (a2p_req_queue_size + p2a_req_queue_size))) return NULL; /* Fill the shared memory with zeros */ @@ -212,9 +212,9 @@ struct rpmi_transport *rpmi_transport_shmem_create(const char *name, shqueue = &shtrans->queues[i]; shqueue->queue_type = i; if (i == RPMI_QUEUE_A2P_REQ || i == RPMI_QUEUE_P2A_ACK) - shqueue->queue_size = a2p_queue_size; + shqueue->queue_size = a2p_req_queue_size; else - shqueue->queue_size = p2a_queue_size; + shqueue->queue_size = p2a_req_queue_size; if (i) shqueue->queue_base = shtrans->queues[i - 1].queue_base + shtrans->queues[i - 1].queue_size; From be6971710511cfa8368d32ddb32f47428d498908 Mon Sep 17 00:00:00 2001 From: Rahul Pathak Date: Sun, 22 Sep 2024 19:33:22 +0530 Subject: [PATCH 2/2] Make P2A channel queues optional As per RPMI spec the P2A channel queues (p2a req and a2p ack) are optional. Change the shmem transport to support optional queues Signed-off-by: Rahul Pathak --- include/librpmi.h | 6 ++++ lib/rpmi_transport.c | 12 ++++++++ lib/rpmi_transport_shmem.c | 61 ++++++++++++++++++++++++++++---------- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/include/librpmi.h b/include/librpmi.h index c828ca8..6dca610 100644 --- a/include/librpmi.h +++ b/include/librpmi.h @@ -411,6 +411,12 @@ struct rpmi_transport { /** Endianness of the messages transferred through this transport */ rpmi_bool_t is_be; + + /** + * Is P2A channel available (in case of shmem based transport + * is p2a req and a2p ack queues) + */ + rpmi_bool_t is_p2a_channel; /** Slot (or max message) size in transport queues */ rpmi_size_t slot_size; diff --git a/lib/rpmi_transport.c b/lib/rpmi_transport.c index 2728ef5..c064f32 100644 --- a/lib/rpmi_transport.c +++ b/lib/rpmi_transport.c @@ -87,6 +87,12 @@ enum rpmi_error rpmi_transport_enqueue(struct rpmi_transport *trans, return RPMI_ERR_INVAL; } + if (!trans->is_p2a_channel && qtype >= RPMI_QUEUE_P2A_REQ) { + DPRINTF("%s: %s: p2a channel not available, invalid qtype %d\n", + __func__, trans->name, qtype); + return RPMI_ERR_INVAL; + } + if (!trans->enqueue) { DPRINTF("%s: %s: enqueue operation not supported for qtype %d\n", __func__, trans->name, qtype); @@ -134,6 +140,12 @@ enum rpmi_error rpmi_transport_dequeue(struct rpmi_transport *trans, return RPMI_ERR_INVAL; } + if (!trans->is_p2a_channel && qtype >= RPMI_QUEUE_P2A_REQ) { + DPRINTF("%s: %s: p2a channel not available, invalid qtype %d\n", + __func__, trans->name, qtype); + return RPMI_ERR_INVAL; + } + if (!trans->dequeue) { DPRINTF("%s: %s: dequeue operation not supported for qtype %d\n", __func__, trans->name, qtype); diff --git a/lib/rpmi_transport_shmem.c b/lib/rpmi_transport_shmem.c index 6cdbae0..542c545 100644 --- a/lib/rpmi_transport_shmem.c +++ b/lib/rpmi_transport_shmem.c @@ -23,7 +23,8 @@ struct rpmi_transport_shmem_queue { struct rpmi_transport_shmem { struct rpmi_shmem *shmem; - struct rpmi_transport_shmem_queue queues[RPMI_QUEUE_MAX]; + rpmi_uint32_t queue_count; + struct rpmi_transport_shmem_queue *queues; struct rpmi_transport trans; }; @@ -184,19 +185,35 @@ struct rpmi_transport *rpmi_transport_shmem_create(const char *name, if ((slot_size & (slot_size - 1)) || slot_size < RPMI_SLOT_SIZE_MIN) return NULL; - /* Make sure queue sizes are multiples of slot size */ - if ((a2p_req_queue_size & (slot_size - 1)) || - (p2a_req_queue_size & (slot_size - 1))) - return NULL; - - /* Make sure queue sizes are not less than minimum required size */ - if (a2p_req_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size) || - p2a_req_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size)) - return NULL; - - /* Shared memory size MUST be enough to accommodate all queues */ - if (rpmi_shmem_size(shmem) < (2 * (a2p_req_queue_size + p2a_req_queue_size))) - return NULL; + /* all four queue are present */ + if (p2a_req_queue_size) { + /* Make sure queue sizes are multiples of slot size */ + if ((a2p_req_queue_size & (slot_size - 1)) || + (p2a_req_queue_size & (slot_size - 1))) + return NULL; + + /* Make sure queue sizes are not less than minimum required size */ + if (a2p_req_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size) || + p2a_req_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size)) + return NULL; + + /* Shared memory size MUST be enough to accommodate all queues */ + if (rpmi_shmem_size(shmem) < (2 * (a2p_req_queue_size + p2a_req_queue_size))) + return NULL; + } + else { /* only a2p req and p2a ack queue */ + /* Make sure queue sizes are multiples of slot size */ + if (a2p_req_queue_size & (slot_size - 1)) + return NULL; + + /* Make sure queue sizes are not less than minimum required size */ + if (a2p_req_queue_size < LIBRPMI_TRANSPORT_SHMEM_QUEUE_MIN_SIZE(slot_size)) + return NULL; + + /* Shared memory size MUST be enough to accommodate all queues */ + if (rpmi_shmem_size(shmem) < (2 * a2p_req_queue_size)) + return NULL; + } /* Fill the shared memory with zeros */ if (rpmi_shmem_fill(shmem, 0, 0, rpmi_shmem_size(shmem))) @@ -208,12 +225,18 @@ struct rpmi_transport *rpmi_transport_shmem_create(const char *name, return NULL; shtrans->shmem = shmem; - for (i = 0; i < RPMI_QUEUE_MAX; i++) { + shtrans->queue_count = p2a_req_queue_size? RPMI_QUEUE_MAX : 2; + + shtrans->queues = rpmi_env_zalloc(sizeof(*shtrans->queues) * shtrans->queue_count); + if (!shtrans->queues) + return NULL; + + for (i = 0; i < shtrans->queue_count; i++) { shqueue = &shtrans->queues[i]; shqueue->queue_type = i; if (i == RPMI_QUEUE_A2P_REQ || i == RPMI_QUEUE_P2A_ACK) shqueue->queue_size = a2p_req_queue_size; - else + else if (p2a_req_queue_size) shqueue->queue_size = p2a_req_queue_size; if (i) shqueue->queue_base = shtrans->queues[i - 1].queue_base + @@ -227,6 +250,7 @@ struct rpmi_transport *rpmi_transport_shmem_create(const char *name, trans->name = name; trans->is_be = false; trans->slot_size = slot_size; + trans->is_p2a_channel = p2a_req_queue_size ? true : false; trans->is_empty = shmem_is_empty; trans->is_full = shmem_is_full; trans->enqueue = shmem_enqueue; @@ -239,9 +263,14 @@ struct rpmi_transport *rpmi_transport_shmem_create(const char *name, void rpmi_transport_shmem_destroy(struct rpmi_transport *trans) { + struct rpmi_transport_shmem *shtrans; + if (!trans) return; + shtrans = trans->priv; + rpmi_env_free_lock(trans->lock); + rpmi_env_free(shtrans->queues); rpmi_env_free(trans->priv); }