bcc56b0a5434d4de3bfd11759a0174244003fb0f
[dpdk.git] / drivers / net / bnxt / tf_core / tfp.h
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] size, number specifying the request size of the data in bytes
61          */
62         uint32_t req_size;
63         /**
64          * [in] data, pointer to the data to be sent within the HWRM command
65          */
66         uint32_t *req_data;
67         /**
68          * [out] size, number specifying the response size of the data in bytes
69          */
70         uint32_t resp_size;
71         /**
72          * [out] data, pointer to the data to be sent within the HWRM command
73          */
74         uint32_t *resp_data;
75 };
76
77 /**
78  * calloc parameter definition
79  */
80 struct tfp_calloc_parms {
81         /**
82          * [in] nitems, number specifying number of items to allocate.
83          */
84         size_t nitems;
85         /**
86          * [in] size, number specifying the size of each memory item
87          *      requested. Size is in bytes.
88          */
89         size_t size;
90         /**
91          * [in] alignment, number indicates byte alignment required. 0
92          *      - don't care, 16 - 16 byte alignment, 4K - 4K alignment etc
93          */
94         size_t alignment;
95         /**
96          * [out] mem_va, pointer to the allocated memory.
97          */
98         void *mem_va;
99         /**
100          * [out] mem_pa, physical address of the allocated memory.
101          */
102         void *mem_pa;
103 };
104
105 /**
106  * @page Portability
107  *
108  * @ref tfp_send_direct
109  *
110  * @ref tfp_calloc
111  * @ref tfp_memcpy
112  * @ref tfp_free
113  *
114  * @ref tfp_spinlock_init
115  * @ref tfp_spinlock_lock
116  * @ref tfp_spinlock_unlock
117  *
118  */
119
120 /**
121  * Provides communication capability from the TrueFlow API layer to
122  * the TrueFlow firmware. The portability layer internally provides
123  * the transport to the firmware.
124  *
125  * [in] session, pointer to session handle
126  * [in] parms, parameter structure
127  *
128  * Returns:
129  *   0              - Success
130  *   -1             - Global error like not supported
131  *   -EINVAL        - Parameter Error
132  */
133 int tfp_send_msg_direct(struct tf *tfp,
134                         struct tfp_send_msg_parms *parms);
135
136 /**
137  * Sends OEM command message to Chimp
138  *
139  * [in] session, pointer to session handle
140  * [in] max_flows, max number of flows requested
141  *
142  * Returns:
143  *   0              - Success
144  *   -1             - Global error like not supported
145  *   -EINVAL        - Parameter Error
146  */
147 int
148 tfp_msg_hwrm_oem_cmd(struct tf *tfp,
149                      uint32_t max_flows);
150
151 /**
152  * Allocates zero'ed memory from the heap.
153  *
154  * NOTE: Also performs virt2phy address conversion by default thus is
155  * can be expensive to invoke.
156  *
157  * [in] parms, parameter structure
158  *
159  * Returns:
160  *   0              - Success
161  *   -ENOMEM        - No memory available
162  *   -EINVAL        - Parameter error
163  */
164 int tfp_calloc(struct tfp_calloc_parms *parms);
165 void tfp_memcpy(void *dest, void *src, size_t n);
166 void tfp_free(void *addr);
167
168 void tfp_spinlock_init(struct tfp_spinlock_parms *slock);
169 void tfp_spinlock_lock(struct tfp_spinlock_parms *slock);
170 void tfp_spinlock_unlock(struct tfp_spinlock_parms *slock);
171
172 /**
173  * Lookup of the FID in the platform specific structure.
174  *
175  * [in] session
176  *   Pointer to session handle
177  *
178  * [out] fw_fid
179  *   Pointer to the fw_fid
180  *
181  * Returns:
182  *   0       - Success
183  *   -EINVAL - Parameter error
184  */
185 int tfp_get_fid(struct tf *tfp, uint16_t *fw_fid);
186
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
235 #endif /* _TFP_H_ */