[Skiboot] [PATCH V6 21/21] core/pldm: Get file handle and file length

Christophe Lombard clombard at linux.vnet.ibm.com
Wed Apr 19 00:58:49 AEST 2023



Le 12/04/2023 à 18:39, Frederic Barrat a écrit :
>
>
> On 13/09/2022 12:27, Christophe Lombard wrote:
>> Retrieve the file handle and file length based on attribute name.
>>
>> Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
>> Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
>> ---
>>   core/pldm/pldm-file-io-requests.c | 78 ++++++++++++++++++++++++++++++-
>>   core/pldm/pldm.h                  |  3 ++
>>   2 files changed, 80 insertions(+), 1 deletion(-)
>>
>> diff --git a/core/pldm/pldm-file-io-requests.c 
>> b/core/pldm/pldm-file-io-requests.c
>> index 0665a679..a1191b89 100644
>> --- a/core/pldm/pldm-file-io-requests.c
>> +++ b/core/pldm/pldm-file-io-requests.c
>> @@ -34,6 +34,82 @@ static void file_io_init_complete(bool success)
>>       file_io_ready = true;
>>   }
>>   +#define CHKSUM_PADDING 8
>> +
>> +/*
>> + * Retrieve the file handle and file length from the file attribute
>> + * table.
>> + */
>> +static int find_file_handle_by_lid_id(const char *lid_id,
>> +                      uint32_t *file_handle,
>> +                      uint32_t *file_length)
>> +{
>> +    const struct pldm_file_attr_table_entry *file_entry;
>> +    char *startptr, *endptr;
>> +    uint16_t file_name_length;
>> +
>> +    if ((file_attr_table == NULL) || (file_attr_length == 0))
>> +        return OPAL_PARAMETER;
>> +
>> +    startptr = (char *)file_attr_table;
>> +    endptr = startptr + file_attr_length - CHKSUM_PADDING;
>> +    *file_handle = 0;
>> +    *file_length = 0;
>> +
>> +    while (startptr < endptr) {
>> +        /* file entry:
>> +         *   4 Bytes: file handle
>> +         *   2 Bytes: file name length
>> +         *   <file name length> Bytes: file name
>> +         *   4 Bytes: file length
>> +         */
>> +        file_entry = (struct pldm_file_attr_table_entry *)startptr;
>> +
>> +        *file_handle = le32_to_cpu(file_entry->file_handle);
>> +        startptr += sizeof(uint32_t);
>> +
>> +        file_name_length = le16_to_cpu(file_entry->file_name_length);
>> +        startptr += sizeof(file_name_length);
>> +
>> +        if (!strncmp(startptr, lid_id, strlen(lid_id))) {
>> +            startptr += file_name_length;
>> +            *file_length = le32_to_cpu(*(uint32_t *)startptr);
>> +            break;
>> +        }
>> +        startptr += file_name_length;
>> +        startptr += sizeof(uint32_t);
>> +        startptr += sizeof(bitfield32_t);
>
>
> Could you update the content of the file entry comment to add the 
> bitfield32_t (what is it?)
>

ok, will do.

> Fred
>
>
>> +    }
>> +
>> +    if (*file_length == 0) {
>> +        prlog(PR_ERR, "%s - No file handle found, lid_id: %s\n",
>> +                  __func__, lid_id);
>> +        *file_handle = 0xff;
>> +        *file_length = 0;
>> +        return OPAL_PARAMETER;
>> +    }
>> +
>> +    prlog(PR_DEBUG, "%s - lid_id: %s, file_handle: %d, file_length: 
>> %d\n",
>> +            __func__, lid_id, *file_handle, *file_length);
>> +
>> +    return OPAL_SUCCESS;
>> +}
>> +
>> +/*
>> + * Retrieve the file handle and file length based on lid id.
>> + */
>> +int pldm_find_file_handle_by_lid_id(const char *lid_id,
>> +                    uint32_t *file_handle,
>> +                    uint32_t *file_length)
>> +{
>> +    if (!file_io_ready)
>> +        return OPAL_PARAMETER;
>> +
>> +    return find_file_handle_by_lid_id(lid_id,
>> +                      file_handle,
>> +                      file_length);
>> +}
>> +
>>   /* maximum currently transfer size for PLDM */
>>   #define KILOBYTE 1024ul
>>   #define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE + 1)
>> @@ -191,7 +267,7 @@ static int write_file_req(uint32_t file_handle, 
>> const void *buf,
>>       request_length = sizeof(struct pldm_msg_hdr) +
>>                sizeof(struct pldm_write_file_req) +
>>                size;
>> -    request_msg = malloc(request_length);
>> +    request_msg = zalloc(request_length);
>
>
> That hunk should be merged in the previous patch
>

correct. Thanks


> Fred
>
>
>
>>         payload_data = ((struct pldm_msg *)request_msg)->payload
>>               + sizeof(file_req.file_handle)
>> diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h
>> index 688c7996..35b0dd66 100644
>> --- a/core/pldm/pldm.h
>> +++ b/core/pldm/pldm.h
>> @@ -47,6 +47,9 @@ int pldm_responder_handle_request(struct 
>> pldm_rx_data *rx);
>>   int pldm_responder_init(void);
>>     /* Requester support */
>> +int pldm_find_file_handle_by_lid_id(const char *lid_id,
>> +                    uint32_t *file_handle,
>> +                    uint32_t *file_length);
>>   int pldm_file_io_read_file(uint32_t file_handle, uint32_t file_length,
>>                  void *buf, uint32_t offset, uint64_t size);
>>   int pldm_file_io_write_file(uint32_t file_handle, const void *buf,



More information about the Skiboot mailing list