xref: /dpdk/drivers/net/bnxt/tf_core/tfp.h (revision fd51012de5369679e807be1d6a81d63ef15015ce)
18430a8b8SMichael Wildt /* SPDX-License-Identifier: BSD-3-Clause
2e6e8f03eSRandy Schacher  * Copyright(c) 2019-2023 Broadcom
38430a8b8SMichael Wildt  * All rights reserved.
48430a8b8SMichael Wildt  */
58430a8b8SMichael Wildt 
6ae2ebb98SPeter Spreadborough /*
7ae2ebb98SPeter Spreadborough  * This header file defines the Portability structures and APIs for
88430a8b8SMichael Wildt  * TruFlow.
98430a8b8SMichael Wildt  */
108430a8b8SMichael Wildt 
118430a8b8SMichael Wildt #ifndef _TFP_H_
128430a8b8SMichael Wildt #define _TFP_H_
138430a8b8SMichael Wildt 
14ae2ebb98SPeter Spreadborough #include <rte_config.h>
158430a8b8SMichael Wildt #include <rte_spinlock.h>
16ae2ebb98SPeter Spreadborough #include <rte_log.h>
17ae2ebb98SPeter Spreadborough #include <rte_byteorder.h>
18873661aaSJay Ding #include <bnxt.h>
19ae2ebb98SPeter Spreadborough 
20ae2ebb98SPeter Spreadborough /**
21ae2ebb98SPeter Spreadborough  * DPDK/Driver specific log level for the BNXT Eth driver.
22ae2ebb98SPeter Spreadborough  */
23ae2ebb98SPeter Spreadborough extern int bnxt_logtype_driver;
248430a8b8SMichael Wildt 
258430a8b8SMichael Wildt /** Spinlock
268430a8b8SMichael Wildt  */
278430a8b8SMichael Wildt struct tfp_spinlock_parms {
288430a8b8SMichael Wildt 	rte_spinlock_t slock;
298430a8b8SMichael Wildt };
308430a8b8SMichael Wildt 
31*fd51012dSAndre Muezerie #define TFP_DRV_LOG_RAW(level, fmt, ...) \
32ae2ebb98SPeter Spreadborough 	rte_log(RTE_LOG_ ## level, bnxt_logtype_driver, "%s(): " fmt, \
33*fd51012dSAndre Muezerie 		__func__, ## __VA_ARGS__)
34ae2ebb98SPeter Spreadborough 
35*fd51012dSAndre Muezerie #define TFP_DRV_LOG(level, fmt, ...) \
36*fd51012dSAndre Muezerie 	TFP_DRV_LOG_RAW(level, fmt, ## __VA_ARGS__)
37ae2ebb98SPeter Spreadborough 
388430a8b8SMichael Wildt /**
398430a8b8SMichael Wildt  * @file
408430a8b8SMichael Wildt  *
411993b267SShahaji Bhosle  * TruFlow Portability API Header File
428430a8b8SMichael Wildt  */
438430a8b8SMichael Wildt 
44ae2ebb98SPeter Spreadborough /**
45ae2ebb98SPeter Spreadborough  * send message parameter definition
468430a8b8SMichael Wildt  */
478430a8b8SMichael Wildt struct tfp_send_msg_parms {
488430a8b8SMichael Wildt 	/**
498430a8b8SMichael Wildt 	 * [in] mailbox, specifying the Mailbox to send the command on.
508430a8b8SMichael Wildt 	 */
518430a8b8SMichael Wildt 	uint32_t  mailbox;
528430a8b8SMichael Wildt 	/**
538430a8b8SMichael Wildt 	 * [in] tlv_subtype, specifies the tlv_type.
548430a8b8SMichael Wildt 	 */
558430a8b8SMichael Wildt 	uint16_t  tf_type;
568430a8b8SMichael Wildt 	/**
578430a8b8SMichael Wildt 	 * [in] tlv_subtype, specifies the tlv_subtype.
588430a8b8SMichael Wildt 	 */
598430a8b8SMichael Wildt 	uint16_t  tf_subtype;
608430a8b8SMichael Wildt 	/**
618430a8b8SMichael Wildt 	 * [out] size, number specifying the request size of the data in bytes
628430a8b8SMichael Wildt 	 */
638430a8b8SMichael Wildt 	uint32_t req_size;
648430a8b8SMichael Wildt 	/**
658430a8b8SMichael Wildt 	 * [in] data, pointer to the data to be sent within the HWRM command
668430a8b8SMichael Wildt 	 */
678430a8b8SMichael Wildt 	uint32_t *req_data;
688430a8b8SMichael Wildt 	/**
698430a8b8SMichael Wildt 	 * [out] size, number specifying the response size of the data in bytes
708430a8b8SMichael Wildt 	 */
718430a8b8SMichael Wildt 	uint32_t resp_size;
728430a8b8SMichael Wildt 	/**
738430a8b8SMichael Wildt 	 * [out] data, pointer to the data to be sent within the HWRM command
748430a8b8SMichael Wildt 	 */
758430a8b8SMichael Wildt 	uint32_t *resp_data;
768430a8b8SMichael Wildt };
778430a8b8SMichael Wildt 
78ae2ebb98SPeter Spreadborough /**
79ae2ebb98SPeter Spreadborough  * calloc parameter definition
808430a8b8SMichael Wildt  */
818430a8b8SMichael Wildt struct tfp_calloc_parms {
828430a8b8SMichael Wildt 	/**
838430a8b8SMichael Wildt 	 * [in] nitems, number specifying number of items to allocate.
848430a8b8SMichael Wildt 	 */
858430a8b8SMichael Wildt 	size_t nitems;
868430a8b8SMichael Wildt 	/**
878430a8b8SMichael Wildt 	 * [in] size, number specifying the size of each memory item
888430a8b8SMichael Wildt 	 *      requested. Size is in bytes.
898430a8b8SMichael Wildt 	 */
908430a8b8SMichael Wildt 	size_t size;
918430a8b8SMichael Wildt 	/**
928430a8b8SMichael Wildt 	 * [in] alignment, number indicates byte alignment required. 0
938430a8b8SMichael Wildt 	 *      - don't care, 16 - 16 byte alignment, 4K - 4K alignment etc
948430a8b8SMichael Wildt 	 */
958430a8b8SMichael Wildt 	size_t alignment;
968430a8b8SMichael Wildt 	/**
978430a8b8SMichael Wildt 	 * [out] mem_va, pointer to the allocated memory.
988430a8b8SMichael Wildt 	 */
998430a8b8SMichael Wildt 	void *mem_va;
1008430a8b8SMichael Wildt 	/**
1018430a8b8SMichael Wildt 	 * [out] mem_pa, physical address of the allocated memory.
1028430a8b8SMichael Wildt 	 */
1038430a8b8SMichael Wildt 	void *mem_pa;
1048430a8b8SMichael Wildt };
1058430a8b8SMichael Wildt 
1068430a8b8SMichael Wildt /**
1078430a8b8SMichael Wildt  * @page Portability
1088430a8b8SMichael Wildt  *
1098430a8b8SMichael Wildt  * @ref tfp_send_direct
1108430a8b8SMichael Wildt  *
1118430a8b8SMichael Wildt  * @ref tfp_calloc
1128430a8b8SMichael Wildt  * @ref tfp_memcpy
113ae2ebb98SPeter Spreadborough  * @ref tfp_free
1148430a8b8SMichael Wildt  *
1158430a8b8SMichael Wildt  * @ref tfp_spinlock_init
1168430a8b8SMichael Wildt  * @ref tfp_spinlock_lock
1178430a8b8SMichael Wildt  * @ref tfp_spinlock_unlock
1188430a8b8SMichael Wildt  *
1198430a8b8SMichael Wildt  */
1208430a8b8SMichael Wildt 
1218430a8b8SMichael Wildt /**
1221993b267SShahaji Bhosle  * Provides communication capability from the TruFlow API layer to
1231993b267SShahaji Bhosle  * the TruFlow firmware. The portability layer internally provides
1248430a8b8SMichael Wildt  * the transport to the firmware.
1258430a8b8SMichael Wildt  *
1268430a8b8SMichael Wildt  * [in] session, pointer to session handle
1278430a8b8SMichael Wildt  * [in] parms, parameter structure
1288430a8b8SMichael Wildt  *
1298430a8b8SMichael Wildt  * Returns:
1308430a8b8SMichael Wildt  *   0              - Success
1318430a8b8SMichael Wildt  *   -1             - Global error like not supported
1328430a8b8SMichael Wildt  *   -EINVAL        - Parameter Error
1338430a8b8SMichael Wildt  */
134873661aaSJay Ding int tfp_send_msg_direct(struct bnxt *bp,
1358430a8b8SMichael Wildt 			struct tfp_send_msg_parms *parms);
1368430a8b8SMichael Wildt 
1378430a8b8SMichael Wildt /**
138b2da0248SPeter Spreadborough  * Sends OEM command message to Chimp
139b2da0248SPeter Spreadborough  *
140b2da0248SPeter Spreadborough  * [in] session, pointer to session handle
141b2da0248SPeter Spreadborough  * [in] max_flows, max number of flows requested
142b2da0248SPeter Spreadborough  *
143b2da0248SPeter Spreadborough  * Returns:
144b2da0248SPeter Spreadborough  *   0              - Success
145b2da0248SPeter Spreadborough  *   -1             - Global error like not supported
146b2da0248SPeter Spreadborough  *   -EINVAL        - Parameter Error
147b2da0248SPeter Spreadborough  */
148b2da0248SPeter Spreadborough int
149b2da0248SPeter Spreadborough tfp_msg_hwrm_oem_cmd(struct tf *tfp,
150b2da0248SPeter Spreadborough 		     uint32_t max_flows);
151b2da0248SPeter Spreadborough 
152b2da0248SPeter Spreadborough /**
1537be78d02SJosh Soref  * Allocates zeroed memory from the heap.
1548430a8b8SMichael Wildt  *
1558430a8b8SMichael Wildt  * NOTE: Also performs virt2phy address conversion by default thus is
1568430a8b8SMichael Wildt  * can be expensive to invoke.
1578430a8b8SMichael Wildt  *
1588430a8b8SMichael Wildt  * [in] parms, parameter structure
1598430a8b8SMichael Wildt  *
1608430a8b8SMichael Wildt  * Returns:
1618430a8b8SMichael Wildt  *   0              - Success
1628430a8b8SMichael Wildt  *   -ENOMEM        - No memory available
1638430a8b8SMichael Wildt  *   -EINVAL        - Parameter error
1648430a8b8SMichael Wildt  */
1658430a8b8SMichael Wildt int tfp_calloc(struct tfp_calloc_parms *parms);
1668430a8b8SMichael Wildt void tfp_memcpy(void *dest, void *src, size_t n);
167ae2ebb98SPeter Spreadborough void tfp_free(void *addr);
168ae2ebb98SPeter Spreadborough 
1698430a8b8SMichael Wildt void tfp_spinlock_init(struct tfp_spinlock_parms *slock);
1708430a8b8SMichael Wildt void tfp_spinlock_lock(struct tfp_spinlock_parms *slock);
1718430a8b8SMichael Wildt void tfp_spinlock_unlock(struct tfp_spinlock_parms *slock);
172ae2ebb98SPeter Spreadborough 
173ae2ebb98SPeter Spreadborough /**
174ae2ebb98SPeter Spreadborough  * Lookup of the FID in the platform specific structure.
175ae2ebb98SPeter Spreadborough  *
176ae2ebb98SPeter Spreadborough  * [in] session
177ae2ebb98SPeter Spreadborough  *   Pointer to session handle
178ae2ebb98SPeter Spreadborough  *
179ae2ebb98SPeter Spreadborough  * [out] fw_fid
180ae2ebb98SPeter Spreadborough  *   Pointer to the fw_fid
181ae2ebb98SPeter Spreadborough  *
182ae2ebb98SPeter Spreadborough  * Returns:
183ae2ebb98SPeter Spreadborough  *   0       - Success
184ae2ebb98SPeter Spreadborough  *   -EINVAL - Parameter error
185ae2ebb98SPeter Spreadborough  */
186ae2ebb98SPeter Spreadborough int tfp_get_fid(struct tf *tfp, uint16_t *fw_fid);
187ae2ebb98SPeter Spreadborough 
188ae2ebb98SPeter Spreadborough /*
189ae2ebb98SPeter Spreadborough  * @ref tfp_cpu_to_le_16
190ae2ebb98SPeter Spreadborough  * @ref tfp_le_to_cpu_16
191ae2ebb98SPeter Spreadborough  * @ref tfp_cpu_to_le_32
192ae2ebb98SPeter Spreadborough  * @ref tfp_le_to_cpu_32
193ae2ebb98SPeter Spreadborough  * @ref tfp_cpu_to_le_64
194ae2ebb98SPeter Spreadborough  * @ref tfp_le_to_cpu_64
195ae2ebb98SPeter Spreadborough  * @ref tfp_cpu_to_be_16
196ae2ebb98SPeter Spreadborough  * @ref tfp_be_to_cpu_16
197ae2ebb98SPeter Spreadborough  * @ref tfp_cpu_to_be_32
198ae2ebb98SPeter Spreadborough  * @ref tfp_be_to_cpu_32
199ae2ebb98SPeter Spreadborough  * @ref tfp_cpu_to_be_64
200ae2ebb98SPeter Spreadborough  * @ref tfp_be_to_cpu_64
201ae2ebb98SPeter Spreadborough  */
202ae2ebb98SPeter Spreadborough 
203ae2ebb98SPeter Spreadborough #define tfp_cpu_to_le_16(val) rte_cpu_to_le_16(val)
204ae2ebb98SPeter Spreadborough #define tfp_le_to_cpu_16(val) rte_le_to_cpu_16(val)
205ae2ebb98SPeter Spreadborough #define tfp_cpu_to_le_32(val) rte_cpu_to_le_32(val)
206ae2ebb98SPeter Spreadborough #define tfp_le_to_cpu_32(val) rte_le_to_cpu_32(val)
207ae2ebb98SPeter Spreadborough #define tfp_cpu_to_le_64(val) rte_cpu_to_le_64(val)
208ae2ebb98SPeter Spreadborough #define tfp_le_to_cpu_64(val) rte_le_to_cpu_64(val)
209ae2ebb98SPeter Spreadborough #define tfp_cpu_to_be_16(val) rte_cpu_to_be_16(val)
210ae2ebb98SPeter Spreadborough #define tfp_be_to_cpu_16(val) rte_be_to_cpu_16(val)
211ae2ebb98SPeter Spreadborough #define tfp_cpu_to_be_32(val) rte_cpu_to_be_32(val)
212ae2ebb98SPeter Spreadborough #define tfp_be_to_cpu_32(val) rte_be_to_cpu_32(val)
213ae2ebb98SPeter Spreadborough #define tfp_cpu_to_be_64(val) rte_cpu_to_be_64(val)
214ae2ebb98SPeter Spreadborough #define tfp_be_to_cpu_64(val) rte_be_to_cpu_64(val)
215ae2ebb98SPeter Spreadborough #define tfp_bswap_16(val) rte_bswap16(val)
216ae2ebb98SPeter Spreadborough #define tfp_bswap_32(val) rte_bswap32(val)
217ae2ebb98SPeter Spreadborough #define tfp_bswap_64(val) rte_bswap64(val)
218ae2ebb98SPeter Spreadborough 
219aa2be509SMichael Wildt /**
2200ea250f8SFarah Smith  * Get the PF associated with the fw communications channel.
2210ea250f8SFarah Smith  *
2220ea250f8SFarah Smith  * [in] session
2230ea250f8SFarah Smith  *   Pointer to session handle
2240ea250f8SFarah Smith  *
2250ea250f8SFarah Smith  * [out] pf
2260ea250f8SFarah Smith  *   Pointer to the pf id
2270ea250f8SFarah Smith  *
2280ea250f8SFarah Smith  * Returns:
2290ea250f8SFarah Smith  *   0       - Success
2300ea250f8SFarah Smith  *   -EINVAL - Failure
2310ea250f8SFarah Smith  *
2320ea250f8SFarah Smith  */
2330ea250f8SFarah Smith int tfp_get_pf(struct tf *tfp, uint16_t *pf);
2348430a8b8SMichael Wildt #endif /* _TFP_H_ */
235