net/qede/base: support previous driver unload
[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_mcp_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                                  ((_p_hwfn)->p_dev->num_ports_in_engines * \
30                                   ecore_device_num_engines((_p_hwfn)->p_dev)))
31
32 struct ecore_mcp_info {
33         /* Spinlock used for protecting the access to the MFW mailbox */
34         osal_spinlock_t lock;
35         /* Flag to indicate whether sending a MFW mailbox is forbidden */
36         bool block_mb_sending;
37
38         /* Address of the MCP public area */
39         u32 public_base;
40         /* Address of the driver mailbox */
41         u32 drv_mb_addr;
42         /* Address of the MFW mailbox */
43         u32 mfw_mb_addr;
44         /* Address of the port configuration (link) */
45         u32 port_addr;
46
47         /* Current driver mailbox sequence */
48         u16 drv_mb_seq;
49         /* Current driver pulse sequence */
50         u16 drv_pulse_seq;
51
52         struct ecore_mcp_link_params       link_input;
53         struct ecore_mcp_link_state        link_output;
54         struct ecore_mcp_link_capabilities link_capabilities;
55
56         struct ecore_mcp_function_info     func_info;
57
58         u8 *mfw_mb_cur;
59         u8 *mfw_mb_shadow;
60         u16 mfw_mb_length;
61         u16 mcp_hist;
62 };
63
64 struct ecore_mcp_mb_params {
65         u32 cmd;
66         u32 param;
67         union drv_union_data *p_data_src;
68         union drv_union_data *p_data_dst;
69         u32 mcp_resp;
70         u32 mcp_param;
71 };
72
73 struct ecore_drv_tlv_hdr {
74         u8 tlv_type;    /* According to the enum below */
75         u8 tlv_length;  /* In dwords - not including this header */
76         u8 tlv_reserved;
77 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
78         u8 tlv_flags;
79 };
80
81 /**
82  * @brief Initialize the interface with the MCP
83  *
84  * @param p_hwfn - HW func
85  * @param p_ptt - PTT required for register access
86  *
87  * @return enum _ecore_status_t
88  */
89 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
90                                         struct ecore_ptt *p_ptt);
91
92 /**
93  * @brief Initialize the port interface with the MCP
94  *
95  * @param p_hwfn
96  * @param p_ptt
97  * Can only be called after `num_ports_in_engines' is set
98  */
99 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
100                              struct ecore_ptt *p_ptt);
101 /**
102  * @brief Releases resources allocated during the init process.
103  *
104  * @param p_hwfn - HW func
105  * @param p_ptt - PTT required for register access
106  *
107  * @return enum _ecore_status_t
108  */
109
110 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
111
112 /**
113  * @brief This function is called from the DPC context. After
114  * pointing PTT to the mfw mb, check for events sent by the MCP
115  * to the driver and ack them. In case a critical event
116  * detected, it will be handled here, otherwise the work will be
117  * queued to a sleepable work-queue.
118  *
119  * @param p_hwfn - HW function
120  * @param p_ptt - PTT required for register access
121  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
122  * was successul.
123  */
124 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
125                                              struct ecore_ptt *p_ptt);
126
127 /**
128  * @brief When MFW doesn't get driver pulse for couple of seconds, at some
129  * threshold before timeout expires, it will generate interrupt
130  * through a dedicated status block (DPSB - Driver Pulse Status
131  * Block), which the driver should respond immediately, by
132  * providing keepalive indication after setting the PTT to the
133  * driver-MFW mailbox. This function is called directly from the
134  * DPC upon receiving the DPSB attention.
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 successful.
140  */
141 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
142                                        struct ecore_ptt *p_ptt);
143
144 enum ecore_drv_role {
145         ECORE_DRV_ROLE_OS,
146         ECORE_DRV_ROLE_KDUMP,
147 };
148
149 struct ecore_load_req_params {
150         enum ecore_drv_role drv_role;
151         u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
152         bool avoid_eng_reset;
153         u32 load_code;
154 };
155
156 /**
157  * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
158  *        returns whether this PF is the first on the engine/port or function.
159  *
160  * @param p_hwfn
161  * @param p_pt
162  * @param p_params
163  *
164  * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
165  */
166 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
167                                         struct ecore_ptt *p_ptt,
168                                         struct ecore_load_req_params *p_params);
169
170 /**
171  * @brief Read the MFW mailbox into Current buffer.
172  *
173  * @param p_hwfn
174  * @param p_ptt
175  */
176 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
177                        struct ecore_ptt *p_ptt);
178
179 /**
180  * @brief Ack to mfw that driver finished FLR process for VFs
181  *
182  * @param p_hwfn
183  * @param p_ptt
184  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
185  *
186  * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
187  */
188 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
189                                           struct ecore_ptt *p_ptt,
190                                           u32 *vfs_to_ack);
191
192 /**
193  * @brief - calls during init to read shmem of all function-related info.
194  *
195  * @param p_hwfn
196  *
197  * @param return ECORE_SUCCESS upon success.
198  */
199 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
200                                                     struct ecore_ptt *p_ptt);
201
202 /**
203  * @brief - Reset the MCP using mailbox command.
204  *
205  * @param p_hwfn
206  * @param p_ptt
207  *
208  * @param return ECORE_SUCCESS upon success.
209  */
210 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
211                                      struct ecore_ptt *p_ptt);
212
213 /**
214  * @brief - Sends an NVM write command request to the MFW with
215  *          payload.
216  *
217  * @param p_hwfn
218  * @param p_ptt
219  * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
220  *            DRV_MSG_CODE_NVM_PUT_FILE_DATA
221  * @param param - [0:23] - Offset [24:31] - Size
222  * @param o_mcp_resp - MCP response
223  * @param o_mcp_param - MCP response param
224  * @param i_txn_size -  Buffer size
225  * @param i_buf - Pointer to the buffer
226  *
227  * @param return ECORE_SUCCESS upon success.
228  */
229 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
230                                           struct ecore_ptt *p_ptt,
231                                           u32 cmd,
232                                           u32 param,
233                                           u32 *o_mcp_resp,
234                                           u32 *o_mcp_param,
235                                           u32 i_txn_size,
236                                           u32 *i_buf);
237
238 /**
239  * @brief - Sends an NVM read command request to the MFW to get
240  *        a buffer.
241  *
242  * @param p_hwfn
243  * @param p_ptt
244  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
245  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
246  * @param param - [0:23] - Offset [24:31] - Size
247  * @param o_mcp_resp - MCP response
248  * @param o_mcp_param - MCP response param
249  * @param o_txn_size -  Buffer size output
250  * @param o_buf - Pointer to the buffer returned by the MFW.
251  *
252  * @param return ECORE_SUCCESS upon success.
253  */
254 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
255                                           struct ecore_ptt *p_ptt,
256                                           u32 cmd,
257                                           u32 param,
258                                           u32 *o_mcp_resp,
259                                           u32 *o_mcp_param,
260                                           u32 *o_txn_size,
261                                           u32 *o_buf);
262
263 /**
264  * @brief indicates whether the MFW objects [under mcp_info] are accessible
265  *
266  * @param p_hwfn
267  *
268  * @return true iff MFW is running and mcp_info is initialized
269  */
270 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
271
272 /**
273  * @brief request MFW to configure MSI-X for a VF
274  *
275  * @param p_hwfn
276  * @param p_ptt
277  * @param vf_id - absolute inside engine
278  * @param num_sbs - number of entries to request
279  *
280  * @return enum _ecore_status_t
281  */
282 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
283                                               struct ecore_ptt *p_ptt,
284                                               u8 vf_id, u8 num);
285
286 /**
287  * @brief - Halt the MCP.
288  *
289  * @param p_hwfn
290  * @param p_ptt
291  *
292  * @param return ECORE_SUCCESS upon success.
293  */
294 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
295                                     struct ecore_ptt *p_ptt);
296
297 /**
298  * @brief - Wake up the MCP.
299  *
300  * @param p_hwfn
301  * @param p_ptt
302  *
303  * @param return ECORE_SUCCESS upon success.
304  */
305 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
306                                       struct ecore_ptt *p_ptt);
307 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
308                                        struct ecore_ptt *p_ptt,
309                                        struct ecore_mcp_link_state *p_link,
310                                        u8 max_bw);
311 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
312                                        struct ecore_ptt *p_ptt,
313                                        struct ecore_mcp_link_state *p_link,
314                                        u8 min_bw);
315 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
316                                              struct ecore_ptt *p_ptt,
317                                              u32 mask_parities);
318 /**
319  * @brief - Sends crash mdump related info to the MFW.
320  *
321  * @param p_hwfn
322  * @param p_ptt
323  *
324  * @param return ECORE_SUCCESS upon success.
325  */
326 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
327                                                 struct ecore_ptt *p_ptt,
328                                                 u32 epoch);
329
330 /**
331  * @brief - Triggers a MFW crash dump procedure.
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_mdump_trigger(struct ecore_hwfn *p_hwfn,
339                                              struct ecore_ptt *p_ptt);
340
341 /**
342  * @brief - Gets the MFW allocation info for the given resource
343  *
344  *  @param p_hwfn
345  *  @param p_ptt
346  *  @param p_resc_info
347  *  @param p_mcp_resp
348  *  @param p_mcp_param
349  *
350  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
351  */
352 enum _ecore_status_t ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn,
353                                              struct ecore_ptt *p_ptt,
354                                              struct resource_info *p_resc_info,
355                                              u32 *p_mcp_resp, u32 *p_mcp_param);
356
357 /**
358  * @brief - Initiates PF FLR
359  *
360  * @param p_hwfn
361  * @param p_ptt
362  *
363  * @param return ECORE_SUCCESS upon success.
364  */
365 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
366                                                struct ecore_ptt *p_ptt);
367
368 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT  0
369 #define ECORE_MCP_RESC_LOCK_TO_NONE     255
370
371 /**
372  * @brief Acquires MFW generic resource lock
373  *
374  *  @param p_hwfn
375  *  @param p_ptt
376  *  @param resource_num - valid values are 0..31
377  *  @param timeout - lock timeout value in seconds
378  *                   (1..254, '0' - default value, '255' - no timeout).
379  *  @param p_granted - will be filled as true if the resource is free and
380  *                     granted, or false if it is busy.
381  *  @param p_owner - A pointer to a variable to be filled with the resource
382  *                   owner (0..15 = PF0-15, 16 = MFW, 17 = diag over serial).
383  *
384  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
385  */
386 enum _ecore_status_t ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn,
387                                          struct ecore_ptt *p_ptt,
388                                          u8 resource_num, u8 timeout,
389                                          bool *p_granted, u8 *p_owner);
390
391 /**
392  * @brief Releases MFW generic resource lock
393  *
394  *  @param p_hwfn
395  *  @param p_ptt
396  *  @param resource_num
397  *  @param force -  allows to release a reeource even if belongs to another PF
398  *  @param p_released - will be filled as true if the resource is released (or
399  *                      has been already released), and false if the resource is
400  *                      acquired by another PF and the `force' flag was not set.
401  *
402  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
403  */
404 enum _ecore_status_t ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn,
405                                            struct ecore_ptt *p_ptt,
406                                            u8 resource_num, bool force,
407                                            bool *p_released);
408
409 #endif /* __ECORE_MCP_H__ */