8789eba1f340ddaa28a7536022080a7378aa30a3
[dpdk.git] / drivers / net / bnxt / tf_core / tfp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 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  * Allocates zero'ed memory from the heap.
175  *
176  * NOTE: Also performs virt2phy address conversion by default thus is
177  * can be expensive to invoke.
178  *
179  * [in] parms, parameter structure
180  *
181  * Returns:
182  *   0              - Success
183  *   -ENOMEM        - No memory available
184  *   -EINVAL        - Parameter error
185  */
186 int tfp_calloc(struct tfp_calloc_parms *parms);
187 void tfp_memcpy(void *dest, void *src, size_t n);
188 void tfp_free(void *addr);
189
190 void tfp_spinlock_init(struct tfp_spinlock_parms *slock);
191 void tfp_spinlock_lock(struct tfp_spinlock_parms *slock);
192 void tfp_spinlock_unlock(struct tfp_spinlock_parms *slock);
193
194 /**
195  * Lookup of the FID in the platform specific structure.
196  *
197  * [in] session
198  *   Pointer to session handle
199  *
200  * [out] fw_fid
201  *   Pointer to the fw_fid
202  *
203  * Returns:
204  *   0       - Success
205  *   -EINVAL - Parameter error
206  */
207 int tfp_get_fid(struct tf *tfp, uint16_t *fw_fid);
208
209
210 /*
211  * @ref tfp_cpu_to_le_16
212  * @ref tfp_le_to_cpu_16
213  * @ref tfp_cpu_to_le_32
214  * @ref tfp_le_to_cpu_32
215  * @ref tfp_cpu_to_le_64
216  * @ref tfp_le_to_cpu_64
217  * @ref tfp_cpu_to_be_16
218  * @ref tfp_be_to_cpu_16
219  * @ref tfp_cpu_to_be_32
220  * @ref tfp_be_to_cpu_32
221  * @ref tfp_cpu_to_be_64
222  * @ref tfp_be_to_cpu_64
223  */
224
225 #define tfp_cpu_to_le_16(val) rte_cpu_to_le_16(val)
226 #define tfp_le_to_cpu_16(val) rte_le_to_cpu_16(val)
227 #define tfp_cpu_to_le_32(val) rte_cpu_to_le_32(val)
228 #define tfp_le_to_cpu_32(val) rte_le_to_cpu_32(val)
229 #define tfp_cpu_to_le_64(val) rte_cpu_to_le_64(val)
230 #define tfp_le_to_cpu_64(val) rte_le_to_cpu_64(val)
231 #define tfp_cpu_to_be_16(val) rte_cpu_to_be_16(val)
232 #define tfp_be_to_cpu_16(val) rte_be_to_cpu_16(val)
233 #define tfp_cpu_to_be_32(val) rte_cpu_to_be_32(val)
234 #define tfp_be_to_cpu_32(val) rte_be_to_cpu_32(val)
235 #define tfp_cpu_to_be_64(val) rte_cpu_to_be_64(val)
236 #define tfp_be_to_cpu_64(val) rte_be_to_cpu_64(val)
237 #define tfp_bswap_16(val) rte_bswap16(val)
238 #define tfp_bswap_32(val) rte_bswap32(val)
239 #define tfp_bswap_64(val) rte_bswap64(val)
240
241 /**
242  * Lookup of the FID in the platform specific structure.
243  *
244  * [in] session
245  *   Pointer to session handle
246  *
247  * [out] fw_fid
248  *   Pointer to the fw_fid
249  *
250  * Returns:
251  *   0       - Success
252  *   -EINVAL - Parameter error
253  */
254 int tfp_get_fid(struct tf *tfp, uint16_t *fw_fid);
255
256 #endif /* _TFP_H_ */