Message ID | 20220429094744.72855-12-clombard@linux.vnet.ibm.com |
---|---|
State | Superseded |
Headers | show |
Series | Complete PLDM responder and enable PLDM support | expand |
On 29/04/2022 11:47, Christophe Lombard wrote: > The GetFRURecordTable command is used to get the FRU Record Table data. > This command is defined to allow the FRU Record Table data to be > transferred using a sequence of one or more command/response messages. > > Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com> > --- > core/pldm/pldm-fru-requests.c | 12 ++++++ > core/pldm/pldm-responder.c | 78 +++++++++++++++++++++++++++++++++++ > core/pldm/pldm.h | 2 + > 3 files changed, 92 insertions(+) > > diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c > index 6da1fb55..863d94f9 100644 > --- a/core/pldm/pldm-fru-requests.c > +++ b/core/pldm/pldm-fru-requests.c > @@ -199,3 +199,15 @@ void pldm_fru_add_record(uint32_t *table_length, > > fru_table_length = *table_length; > } > + > +int pldm_fru_get_table(void **fru_record_table_bytes, > + uint32_t *fru_record_table_size) > +{ > + if (!fru_table) > + return OPAL_PARAMETER; > + > + *fru_record_table_bytes = fru_table; > + *fru_record_table_size = fru_table_length; > + > + return OPAL_SUCCESS; > +} > diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c > index f11317c5..626f8970 100644 > --- a/core/pldm/pldm-responder.c > +++ b/core/pldm/pldm-responder.c > @@ -983,6 +983,83 @@ static struct pldm_cmd pldm_fru_get_record_table_metadata = { > .handler = fru_get_record_table_metadata_handler, > }; > > +/* > + * GetFRURecordTable (0X02) > + * The GetFRURecordTable command is used to get the FRU Record Table > + * data. This command is defined to allow the FRU Record Table data to > + * be transferred using a sequence of one or more command/response > + * messages. > + */ > +static int fru_get_record_table_handler(const struct pldm_rx_data *req) > +{ > + struct pldm_get_fru_record_table_resp *resp; > + void *fru_record_table_bytes; > + uint32_t fru_record_table_size; > + size_t response_length; > + struct pldm_msg *msg; > + char *response_msg; > + int rc; > + > + /* The getFruRecordTable requests do have request data, but it's > + * only related to multi-part transfers which we don't support > + * and which the BMC will not send us. > + */ > + > + /* get fru record table */ > + rc = pldm_fru_get_table(&fru_record_table_bytes, &fru_record_table_size); > + if (rc) { > + prlog(PR_ERR, "Failed to get Fru Record Table\n"); > + pldm_cc_resp(req, req->hdrinf.pldm_type, > + req->hdrinf.command, PLDM_ERROR); > + return OPAL_PARAMETER; > + } > + > + /* create a PLDM response message for GetFRURecordTable */ > + response_length = sizeof(struct pldm_msg_hdr) + > + sizeof(struct pldm_get_fru_record_table_resp) + > + fru_record_table_size; > + response_msg = malloc(response_length); > + memset(response_msg, 0, response_length); Same as previous patch: a new version of the patch reads: response_msg = zalloc(response_length); memset(response_msg, 0, response_length); so the memset is now useless > + > + rc = encode_get_fru_record_table_resp( > + req->hdrinf.instance, > + PLDM_SUCCESS, > + 0, // No next transfer handle > + PLDM_START_AND_END, > + (struct pldm_msg *)response_msg); > + if (rc != PLDM_SUCCESS) { > + prlog(PR_ERR, "Encode GetFruRecordTable Error, rc: %d\n", rc); > + pldm_cc_resp(req, req->hdrinf.pldm_type, > + req->hdrinf.command, PLDM_ERROR); > + free(response_msg); > + return OPAL_PARAMETER; > + } > + > + msg = (struct pldm_msg *)response_msg; > + resp = (struct pldm_get_fru_record_table_resp *)(msg->payload); > + memcpy(resp->fru_record_table_data, > + fru_record_table_bytes, > + fru_record_table_size); > + > + /* send PLDM message over MCTP */ > + rc = pldm_send(req->source_eid, response_msg, response_length - 1); Same comment as before about the "-1" Fred > + if (rc) { > + prlog(PR_ERR, "Failed to send GetFruRecordTable response, rc = %d\n", rc); > + free(response_msg); > + return OPAL_HARDWARE; > + } > + > + free(response_msg); > + > + return OPAL_SUCCESS; > +} > + > +static struct pldm_cmd pldm_fru_get_record_table = { > + .name = "PLDM_GET_FRU_RECORD_TABLE", > + .pldm_cmd_id = PLDM_GET_FRU_RECORD_TABLE, > + .handler = fru_get_record_table_handler, > +}; > + > int pldm_rx_handle_request(struct pldm_rx_data *rx) > { > const struct pldm_type *t; > @@ -1034,6 +1111,7 @@ int pldm_mctp_responder_init(void) > /* Register platform commands we'll respond to - DSP0257 */ > pldm_add_type(&pldm_fru_type); > pldm_add_cmd(&pldm_fru_type, &pldm_fru_get_record_table_metadata); > + pldm_add_cmd(&pldm_fru_type, &pldm_fru_get_record_table); > > return OPAL_SUCCESS; > } > diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h > index d0ceb546..ef884995 100644 > --- a/core/pldm/pldm.h > +++ b/core/pldm/pldm.h > @@ -91,6 +91,8 @@ int pldm_fru_get_record_by_option(uint16_t fru_table_handle, > void pldm_fru_add_record(uint32_t *fru_table_length, > uint16_t *total_record_set_identifiers, > uint16_t *total_table_records); > +int pldm_fru_get_table(void **fru_record_table_bytes, > + uint32_t *fru_record_table_size); > > int pldm_bios_find_lid_by_attr_name(const char *name, char **lid); > int pldm_bios_get_lids_id(char **lid_ids_string);
diff --git a/core/pldm/pldm-fru-requests.c b/core/pldm/pldm-fru-requests.c index 6da1fb55..863d94f9 100644 --- a/core/pldm/pldm-fru-requests.c +++ b/core/pldm/pldm-fru-requests.c @@ -199,3 +199,15 @@ void pldm_fru_add_record(uint32_t *table_length, fru_table_length = *table_length; } + +int pldm_fru_get_table(void **fru_record_table_bytes, + uint32_t *fru_record_table_size) +{ + if (!fru_table) + return OPAL_PARAMETER; + + *fru_record_table_bytes = fru_table; + *fru_record_table_size = fru_table_length; + + return OPAL_SUCCESS; +} diff --git a/core/pldm/pldm-responder.c b/core/pldm/pldm-responder.c index f11317c5..626f8970 100644 --- a/core/pldm/pldm-responder.c +++ b/core/pldm/pldm-responder.c @@ -983,6 +983,83 @@ static struct pldm_cmd pldm_fru_get_record_table_metadata = { .handler = fru_get_record_table_metadata_handler, }; +/* + * GetFRURecordTable (0X02) + * The GetFRURecordTable command is used to get the FRU Record Table + * data. This command is defined to allow the FRU Record Table data to + * be transferred using a sequence of one or more command/response + * messages. + */ +static int fru_get_record_table_handler(const struct pldm_rx_data *req) +{ + struct pldm_get_fru_record_table_resp *resp; + void *fru_record_table_bytes; + uint32_t fru_record_table_size; + size_t response_length; + struct pldm_msg *msg; + char *response_msg; + int rc; + + /* The getFruRecordTable requests do have request data, but it's + * only related to multi-part transfers which we don't support + * and which the BMC will not send us. + */ + + /* get fru record table */ + rc = pldm_fru_get_table(&fru_record_table_bytes, &fru_record_table_size); + if (rc) { + prlog(PR_ERR, "Failed to get Fru Record Table\n"); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + return OPAL_PARAMETER; + } + + /* create a PLDM response message for GetFRURecordTable */ + response_length = sizeof(struct pldm_msg_hdr) + + sizeof(struct pldm_get_fru_record_table_resp) + + fru_record_table_size; + response_msg = malloc(response_length); + memset(response_msg, 0, response_length); + + rc = encode_get_fru_record_table_resp( + req->hdrinf.instance, + PLDM_SUCCESS, + 0, // No next transfer handle + PLDM_START_AND_END, + (struct pldm_msg *)response_msg); + if (rc != PLDM_SUCCESS) { + prlog(PR_ERR, "Encode GetFruRecordTable Error, rc: %d\n", rc); + pldm_cc_resp(req, req->hdrinf.pldm_type, + req->hdrinf.command, PLDM_ERROR); + free(response_msg); + return OPAL_PARAMETER; + } + + msg = (struct pldm_msg *)response_msg; + resp = (struct pldm_get_fru_record_table_resp *)(msg->payload); + memcpy(resp->fru_record_table_data, + fru_record_table_bytes, + fru_record_table_size); + + /* send PLDM message over MCTP */ + rc = pldm_send(req->source_eid, response_msg, response_length - 1); + if (rc) { + prlog(PR_ERR, "Failed to send GetFruRecordTable response, rc = %d\n", rc); + free(response_msg); + return OPAL_HARDWARE; + } + + free(response_msg); + + return OPAL_SUCCESS; +} + +static struct pldm_cmd pldm_fru_get_record_table = { + .name = "PLDM_GET_FRU_RECORD_TABLE", + .pldm_cmd_id = PLDM_GET_FRU_RECORD_TABLE, + .handler = fru_get_record_table_handler, +}; + int pldm_rx_handle_request(struct pldm_rx_data *rx) { const struct pldm_type *t; @@ -1034,6 +1111,7 @@ int pldm_mctp_responder_init(void) /* Register platform commands we'll respond to - DSP0257 */ pldm_add_type(&pldm_fru_type); pldm_add_cmd(&pldm_fru_type, &pldm_fru_get_record_table_metadata); + pldm_add_cmd(&pldm_fru_type, &pldm_fru_get_record_table); return OPAL_SUCCESS; } diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h index d0ceb546..ef884995 100644 --- a/core/pldm/pldm.h +++ b/core/pldm/pldm.h @@ -91,6 +91,8 @@ int pldm_fru_get_record_by_option(uint16_t fru_table_handle, void pldm_fru_add_record(uint32_t *fru_table_length, uint16_t *total_record_set_identifiers, uint16_t *total_table_records); +int pldm_fru_get_table(void **fru_record_table_bytes, + uint32_t *fru_record_table_size); int pldm_bios_find_lid_by_attr_name(const char *name, char **lid); int pldm_bios_get_lids_id(char **lid_ids_string);
The GetFRURecordTable command is used to get the FRU Record Table data. This command is defined to allow the FRU Record Table data to be transferred using a sequence of one or more command/response messages. Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com> --- core/pldm/pldm-fru-requests.c | 12 ++++++ core/pldm/pldm-responder.c | 78 +++++++++++++++++++++++++++++++++++ core/pldm/pldm.h | 2 + 3 files changed, 92 insertions(+)