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

Abhishek SIngh Tomar abhishek at linux.ibm.com
Wed Mar 16 20:40:44 AEDT 2022


On Fri, Mar 04, 2022 at 02:11:54PM +0100, Christophe Lombard wrote:
> Retrieve the file handle and file length based on attribute name.
> 
> Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
Reviewed-by: Abhishek Singh Tomar <abhishek at linux.ibm.com>
> ---
>  core/pldm/pldm-file-io-requests.c | 83 +++++++++++++++++++++++++++++--
>  core/pldm/pldm.h                  |  8 +--
>  2 files changed, 84 insertions(+), 7 deletions(-)
> 
> diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c
> index a86527c0..7f2d4c49 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);
> +	}
> +
> +	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)
> @@ -167,7 +243,7 @@ int pldm_file_io_read_file(uint32_t file_handle,
>   * Send/receive a PLDM WriteFile request message.
>   */
>  static int write_file_req(uint32_t file_handle, uint32_t file_length,
> -			  void *buf, uint32_t offset, uint64_t size)
> +			  const void *buf, uint32_t offset, uint64_t size)
>  {
>  	void *response_msg, *current_ptr, *payload_data;
>  	uint32_t total_write, resp_length, request_length;
> @@ -281,9 +357,8 @@ static int write_file_req(uint32_t file_handle, uint32_t file_length,
>  	return OPAL_SUCCESS;
>  }
>  
> -int pldm_file_io_write_file(uint32_t file_handle,
> -			    uint32_t file_length,
> -			    void *buf, uint32_t offset,
> +int pldm_file_io_write_file(uint32_t file_handle, uint32_t file_length,
> +			    const void *buf, uint32_t offset,
>  			    uint64_t size)
>  {
>  	if (!file_io_ready)
> diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h
> index e7a175f5..f3f698b1 100644
> --- a/core/pldm/pldm.h
> +++ b/core/pldm/pldm.h
> @@ -51,13 +51,15 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx);
>  int pldm_mctp_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,
> -			    uint32_t file_length,
> -			    void *buf, uint32_t offset,
> +int pldm_file_io_write_file(uint32_t file_handle, uint32_t file_length,
> +			    const void *buf, uint32_t offset,
>  			    uint64_t size);
>  int pldm_file_io_init(void);
>  
> -- 
> 2.35.1
> 
> _______________________________________________
> Skiboot mailing list
> Skiboot at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/skiboot


More information about the Skiboot mailing list