New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / qede / base / ecore_mcp.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_MCP_H__
8 #define __ECORE_MCP_H__
9
10 #include "bcm_osal.h"
11 #include "mcp_public.h"
12 #include "ecore.h"
13 #include "ecore_mcp_api.h"
14 #include "ecore_dev_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 struct ecore_mcp_info {
29         /* List for mailbox commands which were sent and wait for a response */
30         osal_list_t cmd_list;
31
32         /* Spinlock used for protecting the access to the mailbox commands list
33          * and the sending of the commands.
34          */
35         osal_spinlock_t cmd_lock;
36
37         /* Flag to indicate whether sending a MFW mailbox command is blocked */
38         bool b_block_cmd;
39
40         /* Spinlock used for syncing SW link-changes and link-changes
41          * originating from attention context.
42          */
43         osal_spinlock_t link_lock;
44
45         /* Address of the MCP public area */
46         u32 public_base;
47         /* Address of the driver mailbox */
48         u32 drv_mb_addr;
49         /* Address of the MFW mailbox */
50         u32 mfw_mb_addr;
51         /* Address of the port configuration (link) */
52         u32 port_addr;
53
54         /* Current driver mailbox sequence */
55         u16 drv_mb_seq;
56         /* Current driver pulse sequence */
57         u16 drv_pulse_seq;
58
59         struct ecore_mcp_link_params       link_input;
60         struct ecore_mcp_link_state        link_output;
61         struct ecore_mcp_link_capabilities link_capabilities;
62
63         struct ecore_mcp_function_info     func_info;
64
65         u8 *mfw_mb_cur;
66         u8 *mfw_mb_shadow;
67         u16 mfw_mb_length;
68         u32 mcp_hist;
69
70         /* Capabilties negotiated with the MFW */
71         u32 capabilities;
72 };
73
74 struct ecore_mcp_mb_params {
75         u32 cmd;
76         u32 param;
77         void *p_data_src;
78         u8 data_src_size;
79         void *p_data_dst;
80         u8 data_dst_size;
81         u32 mcp_resp;
82         u32 mcp_param;
83 };
84
85 struct ecore_drv_tlv_hdr {
86         u8 tlv_type;    /* According to the enum below */
87         u8 tlv_length;  /* In dwords - not including this header */
88         u8 tlv_reserved;
89 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
90         u8 tlv_flags;
91 };
92
93 /**
94  * @brief Initialize the interface with the MCP
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 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
102                                         struct ecore_ptt *p_ptt);
103
104 /**
105  * @brief Initialize the port interface with the MCP
106  *
107  * @param p_hwfn
108  * @param p_ptt
109  * Can only be called after `num_ports_in_engine' is set
110  */
111 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
112                              struct ecore_ptt *p_ptt);
113 /**
114  * @brief Releases resources allocated during the init process.
115  *
116  * @param p_hwfn - HW func
117  * @param p_ptt - PTT required for register access
118  *
119  * @return enum _ecore_status_t
120  */
121
122 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
123
124 /**
125  * @brief This function is called from the DPC context. After
126  * pointing PTT to the mfw mb, check for events sent by the MCP
127  * to the driver and ack them. In case a critical event
128  * detected, it will be handled here, otherwise the work will be
129  * queued to a sleepable work-queue.
130  *
131  * @param p_hwfn - HW function
132  * @param p_ptt - PTT required for register access
133  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
134  * was successul.
135  */
136 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
137                                              struct ecore_ptt *p_ptt);
138
139 /**
140  * @brief When MFW doesn't get driver pulse for couple of seconds, at some
141  * threshold before timeout expires, it will generate interrupt
142  * through a dedicated status block (DPSB - Driver Pulse Status
143  * Block), which the driver should respond immediately, by
144  * providing keepalive indication after setting the PTT to the
145  * driver-MFW mailbox. This function is called directly from the
146  * DPC upon receiving the DPSB attention.
147  *
148  * @param p_hwfn - hw function
149  * @param p_ptt - PTT required for register access
150  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
151  * was successful.
152  */
153 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
154                                        struct ecore_ptt *p_ptt);
155
156 enum ecore_drv_role {
157         ECORE_DRV_ROLE_OS,
158         ECORE_DRV_ROLE_KDUMP,
159 };
160
161 struct ecore_load_req_params {
162         /* Input params */
163         enum ecore_drv_role drv_role;
164         u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
165         bool avoid_eng_reset;
166         enum ecore_override_force_load override_force_load;
167
168         /* Output params */
169         u32 load_code;
170 };
171
172 /**
173  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
174  *        returns whether this PF is the first on the engine/port or function.
175  *
176  * @param p_hwfn
177  * @param p_ptt
178  * @param p_params
179  *
180  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
181  */
182 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
183                                         struct ecore_ptt *p_ptt,
184                                         struct ecore_load_req_params *p_params);
185
186 /**
187  * @brief Sends a LOAD_DONE message to the MFW
188  *
189  * @param p_hwfn
190  * @param p_ptt
191  *
192  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
193  */
194 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
195                                          struct ecore_ptt *p_ptt);
196
197 /**
198  * @brief Sends a UNLOAD_REQ message to the MFW
199  *
200  * @param p_hwfn
201  * @param p_ptt
202  *
203  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
204  */
205 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
206                                           struct ecore_ptt *p_ptt);
207
208 /**
209  * @brief Sends a UNLOAD_DONE message to the MFW
210  *
211  * @param p_hwfn
212  * @param p_ptt
213  *
214  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
215  */
216 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
217                                            struct ecore_ptt *p_ptt);
218
219 /**
220  * @brief Read the MFW mailbox into Current buffer.
221  *
222  * @param p_hwfn
223  * @param p_ptt
224  */
225 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
226                        struct ecore_ptt *p_ptt);
227
228 /**
229  * @brief Ack to mfw that driver finished FLR process for VFs
230  *
231  * @param p_hwfn
232  * @param p_ptt
233  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
234  *
235  * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
236  */
237 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
238                                           struct ecore_ptt *p_ptt,
239                                           u32 *vfs_to_ack);
240
241 /**
242  * @brief - calls during init to read shmem of all function-related info.
243  *
244  * @param p_hwfn
245  *
246  * @param return ECORE_SUCCESS upon success.
247  */
248 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
249                                                     struct ecore_ptt *p_ptt);
250
251 /**
252  * @brief - Reset the MCP using mailbox command.
253  *
254  * @param p_hwfn
255  * @param p_ptt
256  *
257  * @param return ECORE_SUCCESS upon success.
258  */
259 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
260                                      struct ecore_ptt *p_ptt);
261
262 /**
263  * @brief indicates whether the MFW objects [under mcp_info] are accessible
264  *
265  * @param p_hwfn
266  *
267  * @return true iff MFW is running and mcp_info is initialized
268  */
269 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
270
271 /**
272  * @brief request MFW to configure MSI-X for a VF
273  *
274  * @param p_hwfn
275  * @param p_ptt
276  * @param vf_id - absolute inside engine
277  * @param num_sbs - number of entries to request
278  *
279  * @return enum _ecore_status_t
280  */
281 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
282                                               struct ecore_ptt *p_ptt,
283                                               u8 vf_id, u8 num);
284
285 /**
286  * @brief - Halt 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_halt(struct ecore_hwfn *p_hwfn,
294                                     struct ecore_ptt *p_ptt);
295
296 /**
297  * @brief - Wake up the MCP.
298  *
299  * @param p_hwfn
300  * @param p_ptt
301  *
302  * @param return ECORE_SUCCESS upon success.
303  */
304 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
305                                       struct ecore_ptt *p_ptt);
306 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
307                                        struct ecore_ptt *p_ptt,
308                                        struct ecore_mcp_link_state *p_link,
309                                        u8 max_bw);
310 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
311                                        struct ecore_ptt *p_ptt,
312                                        struct ecore_mcp_link_state *p_link,
313                                        u8 min_bw);
314 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
315                                              struct ecore_ptt *p_ptt,
316                                              u32 mask_parities);
317 /**
318  * @brief - Sends crash mdump related info to the MFW.
319  *
320  * @param p_hwfn
321  * @param p_ptt
322  *
323  * @param return ECORE_SUCCESS upon success.
324  */
325 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
326                                                 struct ecore_ptt *p_ptt,
327                                                 u32 epoch);
328
329 /**
330  * @brief - Triggers a MFW crash dump procedure.
331  *
332  * @param p_hwfn
333  * @param p_ptt
334  * @param epoch
335  *
336  * @param return ECORE_SUCCESS upon success.
337  */
338 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
339                                              struct ecore_ptt *p_ptt);
340
341 struct ecore_mdump_retain_data {
342         u32 valid;
343         u32 epoch;
344         u32 pf;
345         u32 status;
346 };
347
348 /**
349  * @brief - Gets the mdump retained data from the MFW.
350  *
351  * @param p_hwfn
352  * @param p_ptt
353  * @param p_mdump_retain
354  *
355  * @param return ECORE_SUCCESS upon success.
356  */
357 enum _ecore_status_t
358 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
359                            struct ecore_mdump_retain_data *p_mdump_retain);
360
361 /**
362  * @brief - Sets the MFW's max value for the given resource
363  *
364  *  @param p_hwfn
365  *  @param p_ptt
366  *  @param res_id
367  *  @param resc_max_val
368  *  @param p_mcp_resp
369  *
370  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
371  */
372 enum _ecore_status_t
373 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
374                            enum ecore_resources res_id, u32 resc_max_val,
375                            u32 *p_mcp_resp);
376
377 /**
378  * @brief - Gets the MFW allocation info for the given resource
379  *
380  *  @param p_hwfn
381  *  @param p_ptt
382  *  @param res_id
383  *  @param p_mcp_resp
384  *  @param p_resc_num
385  *  @param p_resc_start
386  *
387  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
388  */
389 enum _ecore_status_t
390 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
391                         enum ecore_resources res_id, u32 *p_mcp_resp,
392                         u32 *p_resc_num, u32 *p_resc_start);
393
394 /**
395  * @brief - Initiates PF FLR
396  *
397  * @param p_hwfn
398  * @param p_ptt
399  *
400  * @param return ECORE_SUCCESS upon success.
401  */
402 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
403                                                struct ecore_ptt *p_ptt);
404
405 #define ECORE_MCP_RESC_LOCK_MIN_VAL     RESOURCE_DUMP /* 0 */
406 #define ECORE_MCP_RESC_LOCK_MAX_VAL     31
407
408 enum ecore_resc_lock {
409         ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
410         /* Locks that the MFW is aware of should be added here downwards */
411
412         /* Ecore only locks should be added here upwards */
413         ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL,
414
415         /* A dummy value to be used for auxiliary functions in need of
416          * returning an 'error' value.
417          */
418         ECORE_RESC_LOCK_RESC_INVALID,
419 };
420
421 struct ecore_resc_lock_params {
422         /* Resource number [valid values are 0..31] */
423         u8 resource;
424
425         /* Lock timeout value in seconds [default, none or 1..254] */
426         u8 timeout;
427 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT  0
428 #define ECORE_MCP_RESC_LOCK_TO_NONE     255
429
430         /* Number of times to retry locking */
431         u8 retry_num;
432 #define ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT      10
433
434         /* The interval in usec between retries */
435         u16 retry_interval;
436 #define ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT      10000
437
438         /* Use sleep or delay between retries */
439         bool sleep_b4_retry;
440
441         /* Will be set as true if the resource is free and granted */
442         bool b_granted;
443
444         /* Will be filled with the resource owner.
445          * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
446          */
447         u8 owner;
448 };
449
450 /**
451  * @brief Acquires MFW generic resource lock
452  *
453  *  @param p_hwfn
454  *  @param p_ptt
455  *  @param p_params
456  *
457  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
458  */
459 enum _ecore_status_t
460 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
461                     struct ecore_resc_lock_params *p_params);
462
463 struct ecore_resc_unlock_params {
464         /* Resource number [valid values are 0..31] */
465         u8 resource;
466
467         /* Allow to release a resource even if belongs to another PF */
468         bool b_force;
469
470         /* Will be set as true if the resource is released */
471         bool b_released;
472 };
473
474 /**
475  * @brief Releases MFW generic resource lock
476  *
477  *  @param p_hwfn
478  *  @param p_ptt
479  *  @param p_params
480  *
481  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
482  */
483 enum _ecore_status_t
484 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
485                       struct ecore_resc_unlock_params *p_params);
486
487 /**
488  * @brief - default initialization for lock/unlock resource structs
489  *
490  * @param p_lock - lock params struct to be initialized; Can be OSAL_NULL
491  * @param p_unlock - unlock params struct to be initialized; Can be OSAL_NULL
492  * @param resource - the requested resource
493  * @paral b_is_permanent - disable retries & aging when set
494  */
495 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
496                                       struct ecore_resc_unlock_params *p_unlock,
497                                       enum ecore_resc_lock resource,
498                                       bool b_is_permanent);
499
500 /**
501  * @brief Learn of supported MFW features; To be done during early init
502  *
503  * @param p_hwfn
504  * @param p_ptt
505  */
506 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
507                                                 struct ecore_ptt *p_ptt);
508
509 /**
510  * @brief Inform MFW of set of features supported by driver. Should be done
511  * inside the contet of the LOAD_REQ.
512  *
513  * @param p_hwfn
514  * @param p_ptt
515  */
516 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
517                                                 struct ecore_ptt *p_ptt);
518
519 enum ecore_mcp_drv_attr_cmd {
520         ECORE_MCP_DRV_ATTR_CMD_READ,
521         ECORE_MCP_DRV_ATTR_CMD_WRITE,
522         ECORE_MCP_DRV_ATTR_CMD_READ_CLEAR,
523         ECORE_MCP_DRV_ATTR_CMD_CLEAR,
524 };
525
526 struct ecore_mcp_drv_attr {
527         enum ecore_mcp_drv_attr_cmd attr_cmd;
528         u32 attr_num;
529
530         /* R/RC - will be set with the read value
531          * W - should hold the required value to be written
532          * C - DC
533          */
534         u32 val;
535
536         /* W - mask/offset to be applied on the given value
537          * R/RC/C - DC
538          */
539         u32 mask;
540         u32 offset;
541 };
542
543 /**
544  * @brief Handle the drivers' attributes that are kept by the MFW.
545  *
546  * @param p_hwfn
547  * @param p_ptt
548  * @param p_drv_attr
549  */
550 enum _ecore_status_t
551 ecore_mcp_drv_attribute(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
552                         struct ecore_mcp_drv_attr *p_drv_attr);
553
554 /**
555  * @brief Read ufp config from the shared memory.
556  *
557  * @param p_hwfn
558  * @param p_ptt
559  */
560 void
561 ecore_mcp_read_ufp_config(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
562
563 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
564                       u32 offset, u32 val);
565
566 /**
567  * @brief Get the engine affinity configuration.
568  *
569  * @param p_hwfn
570  * @param p_ptt
571  */
572 enum _ecore_status_t ecore_mcp_get_engine_config(struct ecore_hwfn *p_hwfn,
573                                                  struct ecore_ptt *p_ptt);
574
575 /**
576  * @brief Get the PPFID bitmap.
577  *
578  * @param p_hwfn
579  * @param p_ptt
580  */
581 enum _ecore_status_t ecore_mcp_get_ppfid_bitmap(struct ecore_hwfn *p_hwfn,
582                                                 struct ecore_ptt *p_ptt);
583
584 #endif /* __ECORE_MCP_H__ */