New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / qede / base / ecore_hw.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2016 - 2018 Cavium Inc.
3  * All rights reserved.
4  * www.cavium.com
5  */
6
7 #ifndef __ECORE_HW_H__
8 #define __ECORE_HW_H__
9
10 #include "ecore.h"
11 #include "ecore_dev_api.h"
12
13 /* Forward decleration */
14 struct ecore_ptt;
15
16 enum reserved_ptts {
17         RESERVED_PTT_EDIAG,
18         RESERVED_PTT_USER_SPACE,
19         RESERVED_PTT_MAIN,
20         RESERVED_PTT_DPC,
21         RESERVED_PTT_MAX
22 };
23
24 /* @@@TMP - in earlier versions of the emulation, the HW lock started from 1
25  * instead of 0, this should be fixed in later HW versions.
26  */
27 #ifndef MISC_REG_DRIVER_CONTROL_0
28 #define MISC_REG_DRIVER_CONTROL_0       MISC_REG_DRIVER_CONTROL_1
29 #endif
30 #ifndef MISC_REG_DRIVER_CONTROL_0_SIZE
31 #define MISC_REG_DRIVER_CONTROL_0_SIZE  MISC_REG_DRIVER_CONTROL_1_SIZE
32 #endif
33
34 enum _dmae_cmd_dst_mask {
35         DMAE_CMD_DST_MASK_NONE = 0,
36         DMAE_CMD_DST_MASK_PCIE = 1,
37         DMAE_CMD_DST_MASK_GRC = 2
38 };
39
40 enum _dmae_cmd_src_mask {
41         DMAE_CMD_SRC_MASK_PCIE = 0,
42         DMAE_CMD_SRC_MASK_GRC = 1
43 };
44
45 enum _dmae_cmd_crc_mask {
46         DMAE_CMD_COMP_CRC_EN_MASK_NONE = 0,
47         DMAE_CMD_COMP_CRC_EN_MASK_SET = 1
48 };
49
50 /* definitions for DMA constants */
51 #define DMAE_GO_VALUE   0x1
52
53 #ifdef __BIG_ENDIAN
54 #define DMAE_COMPLETION_VAL     0xAED10000
55 #define DMAE_CMD_ENDIANITY      0x3
56 #else
57 #define DMAE_COMPLETION_VAL     0xD1AE
58 #define DMAE_CMD_ENDIANITY      0x2
59 #endif
60
61 #define DMAE_CMD_SIZE   14
62 /* size of DMAE command structure to fill.. DMAE_CMD_SIZE-5 */
63 #define DMAE_CMD_SIZE_TO_FILL   (DMAE_CMD_SIZE - 5)
64 /* Minimum wait for dmae opertaion to complete 2 milliseconds */
65 #define DMAE_MIN_WAIT_TIME      0x2
66 #define DMAE_MAX_CLIENTS        32
67
68 /**
69 * @brief ecore_gtt_init - Initialize GTT windows
70 *
71 * @param p_hwfn
72 * @param p_ptt
73 */
74 void ecore_gtt_init(struct ecore_hwfn *p_hwfn,
75                     struct ecore_ptt *p_ptt);
76
77 /**
78  * @brief ecore_ptt_invalidate - Forces all ptt entries to be re-configured
79  *
80  * @param p_hwfn
81  */
82 void ecore_ptt_invalidate(struct ecore_hwfn *p_hwfn);
83
84 /**
85  * @brief ecore_ptt_pool_alloc - Allocate and initialize PTT pool
86  *
87  * @param p_hwfn
88  *
89  * @return _ecore_status_t - success (0), negative - error.
90  */
91 enum _ecore_status_t ecore_ptt_pool_alloc(struct ecore_hwfn *p_hwfn);
92
93 /**
94  * @brief ecore_ptt_pool_free -
95  *
96  * @param p_hwfn
97  */
98 void ecore_ptt_pool_free(struct ecore_hwfn *p_hwfn);
99
100 /**
101  * @brief ecore_ptt_get_bar_addr - Get PPT's external BAR address
102  *
103  * @param p_hwfn
104  * @param p_ptt
105  *
106  * @return u32
107  */
108 u32 ecore_ptt_get_bar_addr(struct ecore_ptt     *p_ptt);
109
110 /**
111  * @brief ecore_ptt_set_win - Set PTT Window's GRC BAR address
112  *
113  * @param p_hwfn
114  * @param new_hw_addr
115  * @param p_ptt
116  */
117 void ecore_ptt_set_win(struct ecore_hwfn        *p_hwfn,
118                        struct ecore_ptt         *p_ptt,
119                        u32                      new_hw_addr);
120
121 /**
122  * @brief ecore_get_reserved_ptt - Get a specific reserved PTT
123  *
124  * @param p_hwfn
125  * @param ptt_idx
126  *
127  * @return struct ecore_ptt *
128  */
129 struct ecore_ptt *ecore_get_reserved_ptt(struct ecore_hwfn      *p_hwfn,
130                                          enum reserved_ptts     ptt_idx);
131
132 /**
133  * @brief ecore_wr - Write value to BAR using the given ptt
134  *
135  * @param p_hwfn
136  * @param p_ptt
137  * @param hw_addr
138  * @param val
139  */
140 void ecore_wr(struct ecore_hwfn *p_hwfn,
141               struct ecore_ptt  *p_ptt,
142               u32               hw_addr,
143               u32               val);
144
145 /**
146  * @brief ecore_rd - Read value from BAR using the given ptt
147  *
148  * @param p_hwfn
149  * @param p_ptt
150  * @param hw_addr
151  */
152 u32 ecore_rd(struct ecore_hwfn  *p_hwfn,
153              struct ecore_ptt   *p_ptt,
154              u32                hw_addr);
155
156 /**
157  * @brief ecore_memcpy_from - copy n bytes from BAR using the given
158  *        ptt
159  *
160  * @param p_hwfn
161  * @param p_ptt
162  * @param dest
163  * @param hw_addr
164  * @param n
165  */
166 void ecore_memcpy_from(struct ecore_hwfn        *p_hwfn,
167                        struct ecore_ptt         *p_ptt,
168                        void                     *dest,
169                        u32                      hw_addr,
170                        osal_size_t              n);
171
172 /**
173  * @brief ecore_memcpy_to - copy n bytes to BAR using the given
174  *        ptt
175  *
176  * @param p_hwfn
177  * @param p_ptt
178  * @param hw_addr
179  * @param src
180  * @param n
181  */
182 void ecore_memcpy_to(struct ecore_hwfn  *p_hwfn,
183                      struct ecore_ptt   *p_ptt,
184                      u32                hw_addr,
185                      void               *src,
186                      osal_size_t        n);
187 /**
188  * @brief ecore_fid_pretend - pretend to another function when
189  *        accessing the ptt window. There is no way to unpretend
190  *        a function. The only way to cancel a pretend is to
191  *        pretend back to the original function.
192  *
193  * @param p_hwfn
194  * @param p_ptt
195  * @param fid - fid field of pxp_pretend structure. Can contain
196  *            either pf / vf, port/path fields are don't care.
197  */
198 void ecore_fid_pretend(struct ecore_hwfn        *p_hwfn,
199                        struct ecore_ptt         *p_ptt,
200                        u16                      fid);
201
202 /**
203  * @brief ecore_port_pretend - pretend to another port when
204  *        accessing the ptt window
205  *
206  * @param p_hwfn
207  * @param p_ptt
208  * @param port_id - the port to pretend to
209  */
210 void ecore_port_pretend(struct ecore_hwfn       *p_hwfn,
211                         struct ecore_ptt        *p_ptt,
212                         u8                      port_id);
213
214 /**
215  * @brief ecore_port_unpretend - cancel any previously set port
216  *        pretend
217  *
218  * @param p_hwfn
219  * @param p_ptt
220  */
221 void ecore_port_unpretend(struct ecore_hwfn     *p_hwfn,
222                           struct ecore_ptt      *p_ptt);
223
224 /**
225  * @brief ecore_port_fid_pretend - pretend to another port and another function
226  *        when accessing the ptt window
227  *
228  * @param p_hwfn
229  * @param p_ptt
230  * @param port_id - the port to pretend to
231  * @param fid - fid field of pxp_pretend structure. Can contain either pf / vf.
232  */
233 void ecore_port_fid_pretend(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
234                             u8 port_id, u16 fid);
235
236 /**
237  * @brief ecore_vfid_to_concrete - build a concrete FID for a
238  *        given VF ID
239  *
240  * @param p_hwfn
241  * @param p_ptt
242  * @param vfid
243  */
244 u32 ecore_vfid_to_concrete(struct ecore_hwfn *p_hwfn, u8 vfid);
245
246 /**
247 * @brief ecore_dmae_info_alloc - Init the dmae_info structure
248 * which is part of p_hwfn.
249 * @param p_hwfn
250 */
251 enum _ecore_status_t ecore_dmae_info_alloc(struct ecore_hwfn    *p_hwfn);
252
253 /**
254 * @brief ecore_dmae_info_free - Free the dmae_info structure
255 * which is part of p_hwfn
256 *
257 * @param p_hwfn
258 */
259 void ecore_dmae_info_free(struct ecore_hwfn     *p_hwfn);
260
261 enum _ecore_status_t ecore_init_fw_data(struct ecore_dev *p_dev,
262                                         const u8 *fw_data);
263
264 void ecore_hw_err_notify(struct ecore_hwfn *p_hwfn,
265                          enum ecore_hw_err_type err_type);
266
267 enum _ecore_status_t ecore_dmae_sanity(struct ecore_hwfn *p_hwfn,
268                                        struct ecore_ptt *p_ptt,
269                                        const char *phase);
270
271 /**
272  * @brief ecore_ppfid_wr - Write value to BAR using the given ptt while
273  *      pretending to a PF to which the given PPFID pertains.
274  *
275  * @param p_hwfn
276  * @param p_ptt
277  * @param abs_ppfid
278  * @param hw_addr
279  * @param val
280  */
281 void ecore_ppfid_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
282                     u8 abs_ppfid, u32 hw_addr, u32 val);
283
284 /**
285  * @brief ecore_ppfid_rd - Read value from BAR using the given ptt while
286  *       pretending to a PF to which the given PPFID pertains.
287  *
288  * @param p_hwfn
289  * @param p_ptt
290  * @param abs_ppfid
291  * @param hw_addr
292  */
293 u32 ecore_ppfid_rd(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
294                    u8 abs_ppfid, u32 hw_addr);
295
296 #endif /* __ECORE_HW_H__ */