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