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