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