1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019-2021 Broadcom 3 * All rights reserved. 4 */ 5 6 /* 7 * This header file defines the Portability structures and APIs for 8 * TruFlow. 9 */ 10 11 #ifndef _TFP_H_ 12 #define _TFP_H_ 13 14 #include <rte_config.h> 15 #include <rte_spinlock.h> 16 #include <rte_log.h> 17 #include <rte_byteorder.h> 18 19 /** 20 * DPDK/Driver specific log level for the BNXT Eth driver. 21 */ 22 extern int bnxt_logtype_driver; 23 24 /** Spinlock 25 */ 26 struct tfp_spinlock_parms { 27 rte_spinlock_t slock; 28 }; 29 30 #define TFP_DRV_LOG_RAW(level, fmt, args...) \ 31 rte_log(RTE_LOG_ ## level, bnxt_logtype_driver, "%s(): " fmt, \ 32 __func__, ## args) 33 34 #define TFP_DRV_LOG(level, fmt, args...) \ 35 TFP_DRV_LOG_RAW(level, fmt, ## args) 36 37 /** 38 * @file 39 * 40 * TrueFlow Portability API Header File 41 */ 42 43 /** 44 * send message parameter definition 45 */ 46 struct tfp_send_msg_parms { 47 /** 48 * [in] mailbox, specifying the Mailbox to send the command on. 49 */ 50 uint32_t mailbox; 51 /** 52 * [in] tlv_subtype, specifies the tlv_type. 53 */ 54 uint16_t tf_type; 55 /** 56 * [in] tlv_subtype, specifies the tlv_subtype. 57 */ 58 uint16_t tf_subtype; 59 /** 60 * [out] tf_resp_code, response code from the internal tlv 61 * message. Only supported on tunneled messages. 62 */ 63 uint32_t tf_resp_code; 64 /** 65 * [out] size, number specifying the request size of the data in bytes 66 */ 67 uint32_t req_size; 68 /** 69 * [in] data, pointer to the data to be sent within the HWRM command 70 */ 71 uint32_t *req_data; 72 /** 73 * [out] size, number specifying the response size of the data in bytes 74 */ 75 uint32_t resp_size; 76 /** 77 * [out] data, pointer to the data to be sent within the HWRM command 78 */ 79 uint32_t *resp_data; 80 }; 81 82 /** 83 * calloc parameter definition 84 */ 85 struct tfp_calloc_parms { 86 /** 87 * [in] nitems, number specifying number of items to allocate. 88 */ 89 size_t nitems; 90 /** 91 * [in] size, number specifying the size of each memory item 92 * requested. Size is in bytes. 93 */ 94 size_t size; 95 /** 96 * [in] alignment, number indicates byte alignment required. 0 97 * - don't care, 16 - 16 byte alignment, 4K - 4K alignment etc 98 */ 99 size_t alignment; 100 /** 101 * [out] mem_va, pointer to the allocated memory. 102 */ 103 void *mem_va; 104 /** 105 * [out] mem_pa, physical address of the allocated memory. 106 */ 107 void *mem_pa; 108 }; 109 110 /** 111 * @page Portability 112 * 113 * @ref tfp_send_direct 114 * @ref tfp_send_msg_tunneled 115 * 116 * @ref tfp_calloc 117 * @ref tfp_memcpy 118 * @ref tfp_free 119 * 120 * @ref tfp_spinlock_init 121 * @ref tfp_spinlock_lock 122 * @ref tfp_spinlock_unlock 123 * 124 */ 125 126 /** 127 * Provides communication capability from the TrueFlow API layer to 128 * the TrueFlow firmware. The portability layer internally provides 129 * the transport to the firmware. 130 * 131 * [in] session, pointer to session handle 132 * [in] parms, parameter structure 133 * 134 * Returns: 135 * 0 - Success 136 * -1 - Global error like not supported 137 * -EINVAL - Parameter Error 138 */ 139 int tfp_send_msg_direct(struct tf *tfp, 140 struct tfp_send_msg_parms *parms); 141 142 /** 143 * Provides communication capability from the TrueFlow API layer to 144 * the TrueFlow firmware. The portability layer internally provides 145 * the transport to the firmware. 146 * 147 * [in] session, pointer to session handle 148 * [in] parms, parameter structure 149 * 150 * Returns: 151 * 0 - Success 152 * -1 - Global error like not supported 153 * -EINVAL - Parameter Error 154 */ 155 int tfp_send_msg_tunneled(struct tf *tfp, 156 struct tfp_send_msg_parms *parms); 157 158 /** 159 * Sends OEM command message to Chimp 160 * 161 * [in] session, pointer to session handle 162 * [in] max_flows, max number of flows requested 163 * 164 * Returns: 165 * 0 - Success 166 * -1 - Global error like not supported 167 * -EINVAL - Parameter Error 168 */ 169 int 170 tfp_msg_hwrm_oem_cmd(struct tf *tfp, 171 uint32_t max_flows); 172 173 /** 174 * Sends OEM command message to Chimp 175 * 176 * [in] session, pointer to session handle 177 * [in] max_flows, max number of flows requested 178 * 179 * Returns: 180 * 0 - Success 181 * -1 - Global error like not supported 182 * -EINVAL - Parameter Error 183 */ 184 int 185 tfp_msg_hwrm_oem_cmd(struct tf *tfp, 186 uint32_t max_flows); 187 188 /** 189 * Allocates zero'ed memory from the heap. 190 * 191 * NOTE: Also performs virt2phy address conversion by default thus is 192 * can be expensive to invoke. 193 * 194 * [in] parms, parameter structure 195 * 196 * Returns: 197 * 0 - Success 198 * -ENOMEM - No memory available 199 * -EINVAL - Parameter error 200 */ 201 int tfp_calloc(struct tfp_calloc_parms *parms); 202 void tfp_memcpy(void *dest, void *src, size_t n); 203 void tfp_free(void *addr); 204 205 void tfp_spinlock_init(struct tfp_spinlock_parms *slock); 206 void tfp_spinlock_lock(struct tfp_spinlock_parms *slock); 207 void tfp_spinlock_unlock(struct tfp_spinlock_parms *slock); 208 209 /** 210 * Lookup of the FID in the platform specific structure. 211 * 212 * [in] session 213 * Pointer to session handle 214 * 215 * [out] fw_fid 216 * Pointer to the fw_fid 217 * 218 * Returns: 219 * 0 - Success 220 * -EINVAL - Parameter error 221 */ 222 int tfp_get_fid(struct tf *tfp, uint16_t *fw_fid); 223 224 225 /* 226 * @ref tfp_cpu_to_le_16 227 * @ref tfp_le_to_cpu_16 228 * @ref tfp_cpu_to_le_32 229 * @ref tfp_le_to_cpu_32 230 * @ref tfp_cpu_to_le_64 231 * @ref tfp_le_to_cpu_64 232 * @ref tfp_cpu_to_be_16 233 * @ref tfp_be_to_cpu_16 234 * @ref tfp_cpu_to_be_32 235 * @ref tfp_be_to_cpu_32 236 * @ref tfp_cpu_to_be_64 237 * @ref tfp_be_to_cpu_64 238 */ 239 240 #define tfp_cpu_to_le_16(val) rte_cpu_to_le_16(val) 241 #define tfp_le_to_cpu_16(val) rte_le_to_cpu_16(val) 242 #define tfp_cpu_to_le_32(val) rte_cpu_to_le_32(val) 243 #define tfp_le_to_cpu_32(val) rte_le_to_cpu_32(val) 244 #define tfp_cpu_to_le_64(val) rte_cpu_to_le_64(val) 245 #define tfp_le_to_cpu_64(val) rte_le_to_cpu_64(val) 246 #define tfp_cpu_to_be_16(val) rte_cpu_to_be_16(val) 247 #define tfp_be_to_cpu_16(val) rte_be_to_cpu_16(val) 248 #define tfp_cpu_to_be_32(val) rte_cpu_to_be_32(val) 249 #define tfp_be_to_cpu_32(val) rte_be_to_cpu_32(val) 250 #define tfp_cpu_to_be_64(val) rte_cpu_to_be_64(val) 251 #define tfp_be_to_cpu_64(val) rte_be_to_cpu_64(val) 252 #define tfp_bswap_16(val) rte_bswap16(val) 253 #define tfp_bswap_32(val) rte_bswap32(val) 254 #define tfp_bswap_64(val) rte_bswap64(val) 255 256 /** 257 * Lookup of the FID in the platform specific structure. 258 * 259 * [in] session 260 * Pointer to session handle 261 * 262 * [out] fw_fid 263 * Pointer to the fw_fid 264 * 265 * Returns: 266 * 0 - Success 267 * -EINVAL - Parameter error 268 */ 269 int tfp_get_fid(struct tf *tfp, uint16_t *fw_fid); 270 271 /** 272 * Get the PF associated with the fw communications channel. 273 * 274 * [in] session 275 * Pointer to session handle 276 * 277 * [out] pf 278 * Pointer to the pf id 279 * 280 * Returns: 281 * 0 - Success 282 * -EINVAL - Failure 283 * 284 */ 285 int tfp_get_pf(struct tf *tfp, uint16_t *pf); 286 287 #endif /* _TFP_H_ */ 288