diff mbox series

[V6,06/21] core/pldm: Encode GetPLDMTypes response

Message ID 20220913102705.65506-7-clombard@linux.vnet.ibm.com
State Superseded
Headers show
Series Implement MCTP and PLDM features | expand

Commit Message

Christophe Lombard Sept. 13, 2022, 10:26 a.m. UTC
The GetPLDMTypes command can be used to discover the PLDM type capabilities
supported by a PLDM terminus and to get a list of the PLDM types that are
supported.

Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
---
 core/pldm/pldm-responder.c | 52 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

Comments

Abhishek Singh Tomar Sept. 29, 2022, 2:27 p.m. UTC | #1
On Tue, Sep 13, 2022 at 12:26:50PM +0200, Christophe Lombard wrote:
> The GetPLDMTypes command can be used to discover the PLDM type capabilities
> supported by a PLDM terminus and to get a list of the PLDM types that are
> supported.
> 
Reviewed-by: Abhishek Singh Tomar <abhishek@linux.ibm.com>
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> ---
>  core/pldm/pldm-responder.c | 52 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
> index 6f11030d..6058af51 100644
> --- a/core/pldm/pldm-responder.c
> +++ b/core/pldm/pldm-responder.c
> @@ -154,6 +154,57 @@ static struct pldm_cmd pldm_base_get_tid = {
>  	.handler = base_get_tid_handler,
>  };
> 
> +/*
> + * GetPLDMTypes (0x04)
> + * The GetPLDMTypes command can be used to discover the PLDM type
> + * capabilities supported by a PLDM terminus and to get a list of the
> + * PLDM types that are supported.
> + */
> +static int base_get_types_handler(const struct pldm_rx_data *req)
> +{
> +	char response_msg[PKT_SIZE(struct pldm_get_types_resp)];
> +	bitmap_elem_t type_map[BITMAP_ELEMS(32)];
> +	struct pldm_type *iter;
> +	int rc;
> +
> +	/*
> +	 * build the supported type list from the registered type
> +	 * handlers
> +	 */
> +	memset(type_map, 0, sizeof(type_map));
> +	list_for_each(&pldm_type_list, iter, link)
> +		bitmap_set_bit(type_map, iter->pldm_type_id);
> +
> +	for (int i = 0; i < BITMAP_ELEMS(32); i++)
> +		type_map[i] = cpu_to_le64(type_map[i]);
> +
> +	memset(response_msg, 0, sizeof(response_msg));
> +	rc = encode_get_types_resp(req->hdrinf.instance,
> +				   PLDM_SUCCESS,
> +				   (bitfield8_t *)type_map,
> +				   (struct pldm_msg *)response_msg);
> +	if (rc != PLDM_SUCCESS) {
> +		prlog(PR_ERR, "Encode GetPLDMTypes Error, rc: %d\n", rc);
> +		cc_resp(req, req->hdrinf.pldm_type,
> +			req->hdrinf.command, PLDM_ERROR);
> +		return OPAL_PARAMETER;
> +	}
> +
> +	rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg));
> +	if (rc) {
> +		prlog(PR_ERR, "Failed to send GetPLDMTypes response, rc = %d\n", rc);
> +		return OPAL_HARDWARE;
> +	}
> +
> +	return OPAL_SUCCESS;
> +}
> +
> +static struct pldm_cmd pldm_base_get_types = {
> +	.name = "PLDM_GET_PLDM_TYPES",
> +	.pldm_cmd_id = PLDM_GET_PLDM_TYPES,
> +	.handler = base_get_types_handler,
> +};
> +
>  int pldm_responder_handle_request(struct pldm_rx_data *rx)
>  {
>  	const struct pldm_type *type;
> @@ -190,6 +241,7 @@ int pldm_responder_init(void)
>  	/* Register mandatory commands we'll respond to - DSP0240 */
>  	add_type(&pldm_base_type);
>  	add_cmd(&pldm_base_type, &pldm_base_get_tid);
> +	add_cmd(&pldm_base_type, &pldm_base_get_types);
> 
>  	return OPAL_SUCCESS;
>  }
> -- 
> 2.37.3
> 
> _______________________________________________
> Skiboot mailing list
> Skiboot@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot
Frederic Barrat April 12, 2023, 2:47 p.m. UTC | #2
On 13/09/2022 12:26, Christophe Lombard wrote:
> The GetPLDMTypes command can be used to discover the PLDM type capabilities
> supported by a PLDM terminus and to get a list of the PLDM types that are
> supported.
> 
> Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> ---
>   core/pldm/pldm-responder.c | 52 ++++++++++++++++++++++++++++++++++++++
>   1 file changed, 52 insertions(+)
> 
> diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
> index 6f11030d..6058af51 100644
> --- a/core/pldm/pldm-responder.c
> +++ b/core/pldm/pldm-responder.c
> @@ -154,6 +154,57 @@ static struct pldm_cmd pldm_base_get_tid = {
>   	.handler = base_get_tid_handler,
>   };
>   
> +/*
> + * GetPLDMTypes (0x04)
> + * The GetPLDMTypes command can be used to discover the PLDM type
> + * capabilities supported by a PLDM terminus and to get a list of the
> + * PLDM types that are supported.
> + */
> +static int base_get_types_handler(const struct pldm_rx_data *req)
> +{
> +	char response_msg[PKT_SIZE(struct pldm_get_types_resp)];
> +	bitmap_elem_t type_map[BITMAP_ELEMS(32)];


The spec says 64 and that's what libpldm is using.
We can use:
#define PLDM_MAX_TYPES 64

   Fred
Christophe Lombard April 12, 2023, 5:09 p.m. UTC | #3
Le 12/04/2023 à 16:47, Frederic Barrat a écrit :
>
>
> On 13/09/2022 12:26, Christophe Lombard wrote:
>> The GetPLDMTypes command can be used to discover the PLDM type 
>> capabilities
>> supported by a PLDM terminus and to get a list of the PLDM types that 
>> are
>> supported.
>>
>> Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
>> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
>> ---
>>   core/pldm/pldm-responder.c | 52 ++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 52 insertions(+)
>>
>> diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
>> index 6f11030d..6058af51 100644
>> --- a/core/pldm/pldm-responder.c
>> +++ b/core/pldm/pldm-responder.c
>> @@ -154,6 +154,57 @@ static struct pldm_cmd pldm_base_get_tid = {
>>       .handler = base_get_tid_handler,
>>   };
>>   +/*
>> + * GetPLDMTypes (0x04)
>> + * The GetPLDMTypes command can be used to discover the PLDM type
>> + * capabilities supported by a PLDM terminus and to get a list of the
>> + * PLDM types that are supported.
>> + */
>> +static int base_get_types_handler(const struct pldm_rx_data *req)
>> +{
>> +    char response_msg[PKT_SIZE(struct pldm_get_types_resp)];
>> +    bitmap_elem_t type_map[BITMAP_ELEMS(32)];
>
>
> The spec says 64 and that's what libpldm is using.
> We can use:
> #define PLDM_MAX_TYPES 64
>
>   Fred

Yep. Thanks
diff mbox series

Patch

diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c
index 6f11030d..6058af51 100644
--- a/core/pldm/pldm-responder.c
+++ b/core/pldm/pldm-responder.c
@@ -154,6 +154,57 @@  static struct pldm_cmd pldm_base_get_tid = {
 	.handler = base_get_tid_handler,
 };
 
+/*
+ * GetPLDMTypes (0x04)
+ * The GetPLDMTypes command can be used to discover the PLDM type
+ * capabilities supported by a PLDM terminus and to get a list of the
+ * PLDM types that are supported.
+ */
+static int base_get_types_handler(const struct pldm_rx_data *req)
+{
+	char response_msg[PKT_SIZE(struct pldm_get_types_resp)];
+	bitmap_elem_t type_map[BITMAP_ELEMS(32)];
+	struct pldm_type *iter;
+	int rc;
+
+	/*
+	 * build the supported type list from the registered type
+	 * handlers
+	 */
+	memset(type_map, 0, sizeof(type_map));
+	list_for_each(&pldm_type_list, iter, link)
+		bitmap_set_bit(type_map, iter->pldm_type_id);
+
+	for (int i = 0; i < BITMAP_ELEMS(32); i++)
+		type_map[i] = cpu_to_le64(type_map[i]);
+
+	memset(response_msg, 0, sizeof(response_msg));
+	rc = encode_get_types_resp(req->hdrinf.instance,
+				   PLDM_SUCCESS,
+				   (bitfield8_t *)type_map,
+				   (struct pldm_msg *)response_msg);
+	if (rc != PLDM_SUCCESS) {
+		prlog(PR_ERR, "Encode GetPLDMTypes Error, rc: %d\n", rc);
+		cc_resp(req, req->hdrinf.pldm_type,
+			req->hdrinf.command, PLDM_ERROR);
+		return OPAL_PARAMETER;
+	}
+
+	rc = pldm_mctp_message_tx(req->source_eid, response_msg, sizeof(response_msg));
+	if (rc) {
+		prlog(PR_ERR, "Failed to send GetPLDMTypes response, rc = %d\n", rc);
+		return OPAL_HARDWARE;
+	}
+
+	return OPAL_SUCCESS;
+}
+
+static struct pldm_cmd pldm_base_get_types = {
+	.name = "PLDM_GET_PLDM_TYPES",
+	.pldm_cmd_id = PLDM_GET_PLDM_TYPES,
+	.handler = base_get_types_handler,
+};
+
 int pldm_responder_handle_request(struct pldm_rx_data *rx)
 {
 	const struct pldm_type *type;
@@ -190,6 +241,7 @@  int pldm_responder_init(void)
 	/* Register mandatory commands we'll respond to - DSP0240 */
 	add_type(&pldm_base_type);
 	add_cmd(&pldm_base_type, &pldm_base_get_tid);
+	add_cmd(&pldm_base_type, &pldm_base_get_types);
 
 	return OPAL_SUCCESS;
 }