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