77fb5a3c2810ecf820955ef6085d48c89ad6325b
[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.h"
15 #include "ecore_mcp_api.h"
16
17 /* Using hwfn number (and not pf_num) is required since in CMT mode,
18  * same pf_num may be used by two different hwfn
19  * TODO - this shouldn't really be in .h file, but until all fields
20  * required during hw-init will be placed in their correct place in shmem
21  * we need it in ecore_dev.c [for readin the nvram reflection in shmem].
22  */
23 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \
24                                             ((rel_pfid) | \
25                                              ((p_hwfn)->abs_pf_id & 1) << 3) : \
26                                              rel_pfid)
27 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
28
29 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id % \
30                                  ((_p_hwfn)->p_dev->num_ports_in_engines * \
31                                   ecore_device_num_engines((_p_hwfn)->p_dev)))
32
33 struct ecore_mcp_info {
34         /* Spinlock used for protecting the access to the MFW mailbox */
35         osal_spinlock_t lock;
36         /* Flag to indicate whether sending a MFW mailbox is forbidden */
37         bool block_mb_sending;
38
39         /* Address of the MCP public area */
40         u32 public_base;
41         /* Address of the driver mailbox */
42         u32 drv_mb_addr;
43         /* Address of the MFW mailbox */
44         u32 mfw_mb_addr;
45         /* Address of the port configuration (link) */
46         u32 port_addr;
47
48         /* Current driver mailbox sequence */
49         u16 drv_mb_seq;
50         /* Current driver pulse sequence */
51         u16 drv_pulse_seq;
52
53         struct ecore_mcp_link_params       link_input;
54         struct ecore_mcp_link_state        link_output;
55         struct ecore_mcp_link_capabilities link_capabilities;
56
57         struct ecore_mcp_function_info     func_info;
58
59         u8 *mfw_mb_cur;
60         u8 *mfw_mb_shadow;
61         u16 mfw_mb_length;
62         u16 mcp_hist;
63 };
64
65 struct ecore_mcp_mb_params {
66         u32 cmd;
67         u32 param;
68         void *p_data_src;
69         u8 data_src_size;
70         void *p_data_dst;
71         u8 data_dst_size;
72         u32 mcp_resp;
73         u32 mcp_param;
74 };
75
76 struct ecore_drv_tlv_hdr {
77         u8 tlv_type;    /* According to the enum below */
78         u8 tlv_length;  /* In dwords - not including this header */
79         u8 tlv_reserved;
80 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
81         u8 tlv_flags;
82 };
83
84 /**
85  * @brief Initialize the interface with the MCP
86  *
87  * @param p_hwfn - HW func
88  * @param p_ptt - PTT required for register access
89  *
90  * @return enum _ecore_status_t
91  */
92 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
93                                         struct ecore_ptt *p_ptt);
94
95 /**
96  * @brief Initialize the port interface with the MCP
97  *
98  * @param p_hwfn
99  * @param p_ptt
100  * Can only be called after `num_ports_in_engines' is set
101  */
102 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
103                              struct ecore_ptt *p_ptt);
104 /**
105  * @brief Releases resources allocated during the init process.
106  *
107  * @param p_hwfn - HW func
108  * @param p_ptt - PTT required for register access
109  *
110  * @return enum _ecore_status_t
111  */
112
113 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
114
115 /**
116  * @brief This function is called from the DPC context. After
117  * pointing PTT to the mfw mb, check for events sent by the MCP
118  * to the driver and ack them. In case a critical event
119  * detected, it will be handled here, otherwise the work will be
120  * queued to a sleepable work-queue.
121  *
122  * @param p_hwfn - HW function
123  * @param p_ptt - PTT required for register access
124  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
125  * was successul.
126  */
127 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
128                                              struct ecore_ptt *p_ptt);
129
130 /**
131  * @brief When MFW doesn't get driver pulse for couple of seconds, at some
132  * threshold before timeout expires, it will generate interrupt
133  * through a dedicated status block (DPSB - Driver Pulse Status
134  * Block), which the driver should respond immediately, by
135  * providing keepalive indication after setting the PTT to the
136  * driver-MFW mailbox. This function is called directly from the
137  * DPC upon receiving the DPSB attention.
138  *
139  * @param p_hwfn - hw function
140  * @param p_ptt - PTT required for register access
141  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
142  * was successful.
143  */
144 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
145                                        struct ecore_ptt *p_ptt);
146
147 enum ecore_drv_role {
148         ECORE_DRV_ROLE_OS,
149         ECORE_DRV_ROLE_KDUMP,
150 };
151
152 struct ecore_load_req_params {
153         enum ecore_drv_role drv_role;
154         u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
155         bool avoid_eng_reset;
156         u32 load_code;
157 };
158
159 /**
160  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
161  *        returns whether this PF is the first on the engine/port or function.
162  *
163  * @param p_hwfn
164  * @param p_ptt
165  * @param p_params
166  *
167  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
168  */
169 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
170                                         struct ecore_ptt *p_ptt,
171                                         struct ecore_load_req_params *p_params);
172
173 /**
174  * @brief Sends a LOAD_DONE message to the MFW
175  *
176  * @param p_hwfn
177  * @param p_ptt
178  *
179  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
180  */
181 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
182                                          struct ecore_ptt *p_ptt);
183
184 /**
185  * @brief Sends a UNLOAD_REQ message to the MFW
186  *
187  * @param p_hwfn
188  * @param p_ptt
189  *
190  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
191  */
192 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
193                                           struct ecore_ptt *p_ptt);
194
195 /**
196  * @brief Sends a UNLOAD_DONE message to the MFW
197  *
198  * @param p_hwfn
199  * @param p_ptt
200  *
201  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
202  */
203 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
204                                            struct ecore_ptt *p_ptt);
205
206 /**
207  * @brief Read the MFW mailbox into Current buffer.
208  *
209  * @param p_hwfn
210  * @param p_ptt
211  */
212 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
213                        struct ecore_ptt *p_ptt);
214
215 /**
216  * @brief Ack to mfw that driver finished FLR process for VFs
217  *
218  * @param p_hwfn
219  * @param p_ptt
220  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
221  *
222  * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
223  */
224 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
225                                           struct ecore_ptt *p_ptt,
226                                           u32 *vfs_to_ack);
227
228 /**
229  * @brief - calls during init to read shmem of all function-related info.
230  *
231  * @param p_hwfn
232  *
233  * @param return ECORE_SUCCESS upon success.
234  */
235 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
236                                                     struct ecore_ptt *p_ptt);
237
238 /**
239  * @brief - Reset the MCP using mailbox command.
240  *
241  * @param p_hwfn
242  * @param p_ptt
243  *
244  * @param return ECORE_SUCCESS upon success.
245  */
246 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
247                                      struct ecore_ptt *p_ptt);
248
249 /**
250  * @brief - Sends an NVM write command request to the MFW with
251  *          payload.
252  *
253  * @param p_hwfn
254  * @param p_ptt
255  * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
256  *            DRV_MSG_CODE_NVM_PUT_FILE_DATA
257  * @param param - [0:23] - Offset [24:31] - Size
258  * @param o_mcp_resp - MCP response
259  * @param o_mcp_param - MCP response param
260  * @param i_txn_size -  Buffer size
261  * @param i_buf - Pointer to the buffer
262  *
263  * @param return ECORE_SUCCESS upon success.
264  */
265 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
266                                           struct ecore_ptt *p_ptt,
267                                           u32 cmd,
268                                           u32 param,
269                                           u32 *o_mcp_resp,
270                                           u32 *o_mcp_param,
271                                           u32 i_txn_size,
272                                           u32 *i_buf);
273
274 /**
275  * @brief - Sends an NVM read command request to the MFW to get
276  *        a buffer.
277  *
278  * @param p_hwfn
279  * @param p_ptt
280  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
281  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
282  * @param param - [0:23] - Offset [24:31] - Size
283  * @param o_mcp_resp - MCP response
284  * @param o_mcp_param - MCP response param
285  * @param o_txn_size -  Buffer size output
286  * @param o_buf - Pointer to the buffer returned by the MFW.
287  *
288  * @param return ECORE_SUCCESS upon success.
289  */
290 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
291                                           struct ecore_ptt *p_ptt,
292                                           u32 cmd,
293                                           u32 param,
294                                           u32 *o_mcp_resp,
295                                           u32 *o_mcp_param,
296                                           u32 *o_txn_size,
297                                           u32 *o_buf);
298
299 /**
300  * @brief indicates whether the MFW objects [under mcp_info] are accessible
301  *
302  * @param p_hwfn
303  *
304  * @return true iff MFW is running and mcp_info is initialized
305  */
306 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
307
308 /**
309  * @brief request MFW to configure MSI-X for a VF
310  *
311  * @param p_hwfn
312  * @param p_ptt
313  * @param vf_id - absolute inside engine
314  * @param num_sbs - number of entries to request
315  *
316  * @return enum _ecore_status_t
317  */
318 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
319                                               struct ecore_ptt *p_ptt,
320                                               u8 vf_id, u8 num);
321
322 /**
323  * @brief - Halt the MCP.
324  *
325  * @param p_hwfn
326  * @param p_ptt
327  *
328  * @param return ECORE_SUCCESS upon success.
329  */
330 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
331                                     struct ecore_ptt *p_ptt);
332
333 /**
334  * @brief - Wake up the MCP.
335  *
336  * @param p_hwfn
337  * @param p_ptt
338  *
339  * @param return ECORE_SUCCESS upon success.
340  */
341 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
342                                       struct ecore_ptt *p_ptt);
343 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
344                                        struct ecore_ptt *p_ptt,
345                                        struct ecore_mcp_link_state *p_link,
346                                        u8 max_bw);
347 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
348                                        struct ecore_ptt *p_ptt,
349                                        struct ecore_mcp_link_state *p_link,
350                                        u8 min_bw);
351 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
352                                              struct ecore_ptt *p_ptt,
353                                              u32 mask_parities);
354 /**
355  * @brief - Sends crash mdump related info to the MFW.
356  *
357  * @param p_hwfn
358  * @param p_ptt
359  *
360  * @param return ECORE_SUCCESS upon success.
361  */
362 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
363                                                 struct ecore_ptt *p_ptt,
364                                                 u32 epoch);
365
366 /**
367  * @brief - Triggers a MFW crash dump procedure.
368  *
369  * @param p_hwfn
370  * @param p_ptt
371  *
372  * @param return ECORE_SUCCESS upon success.
373  */
374 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
375                                              struct ecore_ptt *p_ptt);
376
377 /**
378  * @brief - Sets the MFW's max value for the given resource
379  *
380  *  @param p_hwfn
381  *  @param p_ptt
382  *  @param res_id
383  *  @param resc_max_val
384  *  @param p_mcp_resp
385  *
386  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
387  */
388 enum _ecore_status_t
389 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
390                            enum ecore_resources res_id, u32 resc_max_val,
391                            u32 *p_mcp_resp);
392
393 /**
394  * @brief - Gets the MFW allocation info for the given resource
395  *
396  *  @param p_hwfn
397  *  @param p_ptt
398  *  @param res_id
399  *  @param p_mcp_resp
400  *  @param p_resc_num
401  *  @param p_resc_start
402  *
403  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
404  */
405 enum _ecore_status_t
406 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
407                         enum ecore_resources res_id, u32 *p_mcp_resp,
408                         u32 *p_resc_num, u32 *p_resc_start);
409
410 /**
411  * @brief - Initiates PF FLR
412  *
413  * @param p_hwfn
414  * @param p_ptt
415  *
416  * @param return ECORE_SUCCESS upon success.
417  */
418 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
419                                                struct ecore_ptt *p_ptt);
420
421 #define ECORE_MCP_RESC_LOCK_MIN_VAL     RESOURCE_DUMP /* 0 */
422 #define ECORE_MCP_RESC_LOCK_MAX_VAL     31
423
424 enum ecore_resc_lock {
425         ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
426         /* Locks that the MFW is aware of should be added here downwards */
427
428         /* Ecore only locks should be added here upwards */
429         ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL
430 };
431
432 struct ecore_resc_lock_params {
433         /* Resource number [valid values are 0..31] */
434         u8 resource;
435
436         /* Lock timeout value in seconds [default, none or 1..254] */
437         u8 timeout;
438 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT  0
439 #define ECORE_MCP_RESC_LOCK_TO_NONE     255
440
441         /* Number of times to retry locking */
442         u8 retry_num;
443
444         /* The interval in usec between retries */
445         u16 retry_interval;
446
447         /* Use sleep or delay between retries */
448         bool sleep_b4_retry;
449
450         /* Will be set as true if the resource is free and granted */
451         bool b_granted;
452
453         /* Will be filled with the resource owner.
454          * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
455          */
456         u8 owner;
457 };
458
459 /**
460  * @brief Acquires MFW generic resource lock
461  *
462  *  @param p_hwfn
463  *  @param p_ptt
464  *  @param p_params
465  *
466  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
467  */
468 enum _ecore_status_t
469 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
470                     struct ecore_resc_lock_params *p_params);
471
472 struct ecore_resc_unlock_params {
473         /* Resource number [valid values are 0..31] */
474         u8 resource;
475
476         /* Allow to release a resource even if belongs to another PF */
477         bool b_force;
478
479         /* Will be set as true if the resource is released */
480         bool b_released;
481 };
482
483 /**
484  * @brief Releases MFW generic resource lock
485  *
486  *  @param p_hwfn
487  *  @param p_ptt
488  *  @param p_params
489  *
490  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
491  */
492 enum _ecore_status_t
493 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
494                       struct ecore_resc_unlock_params *p_params);
495
496 #endif /* __ECORE_MCP_H__ */