Imported Upstream version 16.11
[deb_dpdk.git] / drivers / net / qede / base / ecore_mcp.h
1 /*
2  * Copyright (c) 2016 QLogic Corporation.
3  * All rights reserved.
4  * www.qlogic.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9 #ifndef __ECORE_MCP_H__
10 #define __ECORE_MCP_H__
11
12 #include "bcm_osal.h"
13 #include "mcp_public.h"
14 #include "ecore_mcp_api.h"
15
16 /* Using hwfn number (and not pf_num) is required since in CMT mode,
17  * same pf_num may be used by two different hwfn
18  * TODO - this shouldn't really be in .h file, but until all fields
19  * required during hw-init will be placed in their correct place in shmem
20  * we need it in ecore_dev.c [for readin the nvram reflection in shmem].
21  */
22 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \
23                                             ((rel_pfid) | \
24                                              ((p_hwfn)->abs_pf_id & 1) << 3) : \
25                                              rel_pfid)
26 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
27
28 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id % \
29                                  ((_p_hwfn)->p_dev->num_ports_in_engines * \
30                                   ecore_device_num_engines((_p_hwfn)->p_dev)))
31
32 struct ecore_mcp_info {
33         /* Spinlock used for protecting the access to the MFW mailbox */
34         osal_spinlock_t lock;
35         /* Flag to indicate whether sending a MFW mailbox is forbidden */
36         bool block_mb_sending;
37
38         /* Address of the MCP public area */
39         u32 public_base;
40         /* Address of the driver mailbox */
41         u32 drv_mb_addr;
42         /* Address of the MFW mailbox */
43         u32 mfw_mb_addr;
44         /* Address of the port configuration (link) */
45         u32 port_addr;
46
47         /* Current driver mailbox sequence */
48         u16 drv_mb_seq;
49         /* Current driver pulse sequence */
50         u16 drv_pulse_seq;
51
52         struct ecore_mcp_link_params       link_input;
53         struct ecore_mcp_link_state        link_output;
54         struct ecore_mcp_link_capabilities link_capabilities;
55
56         struct ecore_mcp_function_info     func_info;
57
58         u8 *mfw_mb_cur;
59         u8 *mfw_mb_shadow;
60         u16 mfw_mb_length;
61         u16 mcp_hist;
62 };
63
64 struct ecore_mcp_mb_params {
65         u32 cmd;
66         u32 param;
67         union drv_union_data *p_data_src;
68         union drv_union_data *p_data_dst;
69         u32 mcp_resp;
70         u32 mcp_param;
71 };
72
73 /**
74  * @brief Initialize the interface with the MCP
75  *
76  * @param p_hwfn - HW func
77  * @param p_ptt - PTT required for register access
78  *
79  * @return enum _ecore_status_t
80  */
81 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
82                                         struct ecore_ptt *p_ptt);
83
84 /**
85  * @brief Initialize the port interface with the MCP
86  *
87  * @param p_hwfn
88  * @param p_ptt
89  * Can only be called after `num_ports_in_engines' is set
90  */
91 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
92                              struct ecore_ptt *p_ptt);
93 /**
94  * @brief Releases resources allocated during the init process.
95  *
96  * @param p_hwfn - HW func
97  * @param p_ptt - PTT required for register access
98  *
99  * @return enum _ecore_status_t
100  */
101
102 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
103
104 /**
105  * @brief This function is called from the DPC context. After
106  * pointing PTT to the mfw mb, check for events sent by the MCP
107  * to the driver and ack them. In case a critical event
108  * detected, it will be handled here, otherwise the work will be
109  * queued to a sleepable work-queue.
110  *
111  * @param p_hwfn - HW function
112  * @param p_ptt - PTT required for register access
113  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
114  * was successul.
115  */
116 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
117                                              struct ecore_ptt *p_ptt);
118
119 /**
120  * @brief When MFW doesn't get driver pulse for couple of seconds, at some
121  * threshold before timeout expires, it will generate interrupt
122  * through a dedicated status block (DPSB - Driver Pulse Status
123  * Block), which the driver should respond immediately, by
124  * providing keepalive indication after setting the PTT to the
125  * driver-MFW mailbox. This function is called directly from the
126  * DPC upon receiving the DPSB attention.
127  *
128  * @param p_hwfn - hw function
129  * @param p_ptt - PTT required for register access
130  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
131  * was successul.
132  */
133 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
134                                        struct ecore_ptt *p_ptt);
135
136 /**
137  * @brief Sends a LOAD_REQ to the MFW, and in case operation
138  *        succeed, returns whether this PF is the first on the
139  *        chip/engine/port or function. This function should be
140  *        called when driver is ready to accept MFW events after
141  *        Storms initializations are done.
142  *
143  * @param p_hwfn       - hw function
144  * @param p_ptt        - PTT required for register access
145  * @param p_load_code  - The MCP response param containing one
146  *      of the following:
147  *      FW_MSG_CODE_DRV_LOAD_ENGINE
148  *      FW_MSG_CODE_DRV_LOAD_PORT
149  *      FW_MSG_CODE_DRV_LOAD_FUNCTION
150  * @return enum _ecore_status_t -
151  *      ECORE_SUCCESS - Operation was successul.
152  *      ECORE_BUSY - Operation failed
153  */
154 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
155                                         struct ecore_ptt *p_ptt,
156                                         u32 *p_load_code);
157
158 /**
159  * @brief Read the MFW mailbox into Current buffer.
160  *
161  * @param p_hwfn
162  * @param p_ptt
163  */
164 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
165                        struct ecore_ptt *p_ptt);
166
167 /**
168  * @brief Ack to mfw that driver finished FLR process for VFs
169  *
170  * @param p_hwfn
171  * @param p_ptt
172  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
173  *
174  * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
175  */
176 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
177                                           struct ecore_ptt *p_ptt,
178                                           u32 *vfs_to_ack);
179
180 /**
181  * @brief - calls during init to read shmem of all function-related info.
182  *
183  * @param p_hwfn
184  *
185  * @param return ECORE_SUCCESS upon success.
186  */
187 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
188                                                     struct ecore_ptt *p_ptt);
189
190 /**
191  * @brief - Reset the MCP using mailbox command.
192  *
193  * @param p_hwfn
194  * @param p_ptt
195  *
196  * @param return ECORE_SUCCESS upon success.
197  */
198 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
199                                      struct ecore_ptt *p_ptt);
200
201 /**
202  * @brief - Sends an NVM write command request to the MFW with
203  *          payload.
204  *
205  * @param p_hwfn
206  * @param p_ptt
207  * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
208  *            DRV_MSG_CODE_NVM_PUT_FILE_DATA
209  * @param param - [0:23] - Offset [24:31] - Size
210  * @param o_mcp_resp - MCP response
211  * @param o_mcp_param - MCP response param
212  * @param i_txn_size -  Buffer size
213  * @param i_buf - Pointer to the buffer
214  *
215  * @param return ECORE_SUCCESS upon success.
216  */
217 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
218                                           struct ecore_ptt *p_ptt,
219                                           u32 cmd,
220                                           u32 param,
221                                           u32 *o_mcp_resp,
222                                           u32 *o_mcp_param,
223                                           u32 i_txn_size,
224                                           u32 *i_buf);
225
226 /**
227  * @brief - Sends an NVM read command request to the MFW to get
228  *        a buffer.
229  *
230  * @param p_hwfn
231  * @param p_ptt
232  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
233  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
234  * @param param - [0:23] - Offset [24:31] - Size
235  * @param o_mcp_resp - MCP response
236  * @param o_mcp_param - MCP response param
237  * @param o_txn_size -  Buffer size output
238  * @param o_buf - Pointer to the buffer returned by the MFW.
239  *
240  * @param return ECORE_SUCCESS upon success.
241  */
242 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
243                                           struct ecore_ptt *p_ptt,
244                                           u32 cmd,
245                                           u32 param,
246                                           u32 *o_mcp_resp,
247                                           u32 *o_mcp_param,
248                                           u32 *o_txn_size,
249                                           u32 *o_buf);
250
251 /**
252  * @brief indicates whether the MFW objects [under mcp_info] are accessible
253  *
254  * @param p_hwfn
255  *
256  * @return true iff MFW is running and mcp_info is initialized
257  */
258 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
259
260 /**
261  * @brief request MFW to configure MSI-X for a VF
262  *
263  * @param p_hwfn
264  * @param p_ptt
265  * @param vf_id - absolute inside engine
266  * @param num_sbs - number of entries to request
267  *
268  * @return enum _ecore_status_t
269  */
270 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
271                                               struct ecore_ptt *p_ptt,
272                                               u8 vf_id, u8 num);
273
274 /**
275  * @brief - Halt the MCP.
276  *
277  * @param p_hwfn
278  * @param p_ptt
279  *
280  * @param return ECORE_SUCCESS upon success.
281  */
282 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
283                                     struct ecore_ptt *p_ptt);
284
285 /**
286  * @brief - Wake up the MCP.
287  *
288  * @param p_hwfn
289  * @param p_ptt
290  *
291  * @param return ECORE_SUCCESS upon success.
292  */
293 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
294                                       struct ecore_ptt *p_ptt);
295 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
296                                        struct ecore_ptt *p_ptt,
297                                        struct ecore_mcp_link_state *p_link,
298                                        u8 max_bw);
299 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
300                                        struct ecore_ptt *p_ptt,
301                                        struct ecore_mcp_link_state *p_link,
302                                        u8 min_bw);
303 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
304                                              struct ecore_ptt *p_ptt,
305                                              u32 mask_parities);
306 /**
307  * @brief - Sends crash mdump related info to the MFW.
308  *
309  * @param p_hwfn
310  * @param p_ptt
311  *
312  * @param return ECORE_SUCCESS upon success.
313  */
314 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
315                                                 struct ecore_ptt *p_ptt,
316                                                 u32 epoch);
317
318 /**
319  * @brief - Triggers a MFW crash dump procedure.
320  *
321  * @param p_hwfn
322  * @param p_ptt
323  *
324  * @param return ECORE_SUCCESS upon success.
325  */
326 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
327                                              struct ecore_ptt *p_ptt);
328
329 /**
330  * @brief - Clears the MFW crash dump logs.
331  *
332  * @param p_hwfn
333  * @param p_ptt
334  *
335  * @param return ECORE_SUCCESS upon success.
336  */
337 enum _ecore_status_t ecore_mcp_mdump_clear_logs(struct ecore_hwfn *p_hwfn,
338                                                 struct ecore_ptt *p_ptt);
339
340 /**
341  * @brief - Gets the MFW crash dump configuration and logs info.
342  *
343  * @param p_hwfn
344  * @param p_ptt
345  *
346  * @param return ECORE_SUCCESS upon success.
347  */
348 enum _ecore_status_t ecore_mcp_mdump_get_info(struct ecore_hwfn *p_hwfn,
349                                               struct ecore_ptt *p_ptt);
350
351 enum _ecore_status_t ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn,
352                                              struct ecore_ptt *p_ptt,
353                                              struct resource_info *p_resc_info,
354                                              u32 *p_mcp_resp, u32 *p_mcp_param);
355
356 /**
357  * @brief - Initiates PF FLR
358  *
359  * @param p_hwfn
360  * @param p_ptt
361  *
362  * @param return ECORE_SUCCESS upon success.
363  */
364 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
365                                                struct ecore_ptt *p_ptt);
366
367 #endif /* __ECORE_MCP_H__ */