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