1 /*
2  * Copyright 2023, Cypress Semiconductor Corporation (an Infineon company)
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /** @file whd_resource_api.h
19  *  Prototypes of functions for providing external resources to the radio driver
20  *
21  *  This file provides prototypes for functions which allow
22  *  WHD to download firmware, NVRAM and CLM BLOB on a particular hardware platform.
23  *
24  */
25 #include "whd.h"
26 
27 #ifndef INCLUDED_WHD_RESOURCE_API_H_
28 #define INCLUDED_WHD_RESOURCE_API_H_
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 #define BLOCK_SIZE 1024 /**< Size of the block */
36 
37 #ifndef NVM_IMAGE_SIZE_ALIGNMENT
38 #define NVM_IMAGE_SIZE_ALIGNMENT 4 /**< The alignment size of NVRAM image */
39 #endif
40 
41 /**
42  * Type of resources
43  */
44 typedef enum
45 {
46     WHD_RESOURCE_WLAN_FIRMWARE, /**< Resource type: WLAN Firmware */
47     WHD_RESOURCE_WLAN_NVRAM,    /**< Resource type: NVRAM file */
48     WHD_RESOURCE_WLAN_CLM,      /**< Resource type: CLM_BLOB file */
49 } whd_resource_type_t;
50 
51 /******************************************************
52 *                 Global Variables
53 ******************************************************/
54 
55 /** @addtogroup res WHD Resource API
56  *  @brief Functions that enable WHD to download WLAN firmware, NVRAM and CLM BLOB on a particular hardware platform.
57  *  @{
58  */
59 
60 /**
61  * Interface to a data source that provides external resources to the radio driver
62  */
63 
64 /** This data structure defines a source for data generally intended to be downloaded to the radio device.
65  *
66  * The data is assumed to be available as a set of blocks that are all the same size with the exception
67  * of the last block. The whd_get_resource_block_size function returns this block size. The whd_get_resource_block call
68  * returns a pointer to a block of data. The actual storage for the data block is owned by the data source, so only a pointer
69  * to the block is returned. There are two predominate use cases. If the data is stored in the internal
70  * flash memory, then whd_get_resource_no_of_blocks will return 1 and a call to whd_get_resource_block will return a pointer to
71  * the data image with the size being the size of the data image. If the data is stored in an external flash of some
72  * type, each block of data can be read from the external flash one at a time.  whd_get_resource_no_of_blocks will return
73  * the physical number of blocks in the data and each call to whd_get_resource_block will read data from the external memory
74  * and make it available via an internal buffer.
75  */
76 struct whd_resource_source
77 {
78     /** Gets the size of the resource for respective resource type
79      *
80      *
81      *  @param whd_drv     Pointer to handle instance of the driver
82      *  @param resource    Type of resource - WHD_RESOURCE_WLAN_FIRMWARE, WHD_RESOURCE_WLAN_NVRAM, WHD_RESOURCE_WLAN_CLM
83      *  @param size_out    Size of the resource
84      *
85      *  @return            WHD_SUCCESS or error code
86      *
87      */
88     uint32_t (*whd_resource_size)(whd_driver_t whd_drv, whd_resource_type_t resource, uint32_t *size_out);
89 
90     /** Gets the resource block for specified resource type
91      *
92      *  @param whd_drv     Pointer to handle instance of the driver
93      *  @param type        Type of resource - WHD_RESOURCE_WLAN_FIRMWARE, WHD_RESOURCE_WLAN_NVRAM, WHD_RESOURCE_WLAN_CLM
94      *  @param blockno     The number of block
95      *  @param data        Pointer to a block of data
96      *  @param size_out    Size of the resource
97      *
98      *  @return            WHD_SUCCESS or error code
99      *
100      */
101     uint32_t (*whd_get_resource_block)(whd_driver_t whd_drv, whd_resource_type_t type,
102                                        uint32_t blockno, const uint8_t **data, uint32_t *size_out);
103 
104     /** Gets block count for the specified resource_type
105      *
106      *  @param whd_drv      Pointer to handle instance of the driver
107      *  @param type         Type of resource - WHD_RESOURCE_WLAN_FIRMWARE, WHD_RESOURCE_WLAN_NVRAM, WHD_RESOURCE_WLAN_CLM
108      *  @param block_count  Pointer to store block count for the resource
109      *
110      *  @return             WHD_SUCCESS or error code
111      *
112      */
113     uint32_t (*whd_get_resource_no_of_blocks)(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *block_count);
114 
115     /** Gets block size for the specified resource_type
116      *
117      *  @param whd_drv      Pointer to handle instance of the driver
118      *  @param type         Type of resources - WHD_RESOURCE_WLAN_FIRMWARE, WHD_RESOURCE_WLAN_NVRAM, WHD_RESOURCE_WLAN_CLM
119      *  @param size_out     Pointer to store size of the block
120      *
121      *  @return             WHD_SUCCESS or error code
122      *
123      */
124     uint32_t (*whd_get_resource_block_size)(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *size_out);
125 
126     /** Gets the resource for specified resource type
127      *
128      *  @param whd_drv     Pointer to handle instance of the driver
129      *  @param type        Type of resource - WHD_RESOURCE_WLAN_FIRMWARE, WHD_RESOURCE_WLAN_NVRAM, WHD_RESOURCE_WLAN_CLM
130      *  @param offset      offset address to store buffer
131      *  @param size        Pointer to a size of buffer
132      *  @param size_out    Pointer to store size of buffer
133      *  @param buffer      Pointer to a buffer
134      *
135      *  @return            WHD_SUCCESS or error code
136      *
137      */
138     uint32_t (*whd_resource_read)(whd_driver_t whd_drv, whd_resource_type_t type,
139                                   uint32_t offset, uint32_t size, uint32_t *size_out, void *buffer);
140 };
141 
142 /** @} */
143 
144 #ifdef __cplusplus
145 } /* extern "C" */
146 #endif
147 #endif /* ifndef INCLUDED_WHD_RESOURCE_API_H_ */
148 
149