7a8151617c3c0c24a3929f75cfd77f95cc7b3991
[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 successul.
140  */
141 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
142                                        struct ecore_ptt *p_ptt);
143
144 /**
145  * @brief Sends a LOAD_REQ to the MFW, and in case operation
146  *        succeed, returns whether this PF is the first on the
147  *        chip/engine/port or function. This function should be
148  *        called when driver is ready to accept MFW events after
149  *        Storms initializations are done.
150  *
151  * @param p_hwfn       - hw function
152  * @param p_ptt        - PTT required for register access
153  * @param p_load_code  - The MCP response param containing one
154  *      of the following:
155  *      FW_MSG_CODE_DRV_LOAD_ENGINE
156  *      FW_MSG_CODE_DRV_LOAD_PORT
157  *      FW_MSG_CODE_DRV_LOAD_FUNCTION
158  * @return enum _ecore_status_t -
159  *      ECORE_SUCCESS - Operation was successul.
160  *      ECORE_BUSY - Operation failed
161  */
162 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
163                                         struct ecore_ptt *p_ptt,
164                                         u32 *p_load_code);
165
166 /**
167  * @brief Read the MFW mailbox into Current buffer.
168  *
169  * @param p_hwfn
170  * @param p_ptt
171  */
172 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
173                        struct ecore_ptt *p_ptt);
174
175 /**
176  * @brief Ack to mfw that driver finished FLR process for VFs
177  *
178  * @param p_hwfn
179  * @param p_ptt
180  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
181  *
182  * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
183  */
184 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
185                                           struct ecore_ptt *p_ptt,
186                                           u32 *vfs_to_ack);
187
188 /**
189  * @brief - calls during init to read shmem of all function-related info.
190  *
191  * @param p_hwfn
192  *
193  * @param return ECORE_SUCCESS upon success.
194  */
195 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
196                                                     struct ecore_ptt *p_ptt);
197
198 /**
199  * @brief - Reset the MCP using mailbox command.
200  *
201  * @param p_hwfn
202  * @param p_ptt
203  *
204  * @param return ECORE_SUCCESS upon success.
205  */
206 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
207                                      struct ecore_ptt *p_ptt);
208
209 /**
210  * @brief - Sends an NVM write command request to the MFW with
211  *          payload.
212  *
213  * @param p_hwfn
214  * @param p_ptt
215  * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
216  *            DRV_MSG_CODE_NVM_PUT_FILE_DATA
217  * @param param - [0:23] - Offset [24:31] - Size
218  * @param o_mcp_resp - MCP response
219  * @param o_mcp_param - MCP response param
220  * @param i_txn_size -  Buffer size
221  * @param i_buf - Pointer to the buffer
222  *
223  * @param return ECORE_SUCCESS upon success.
224  */
225 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
226                                           struct ecore_ptt *p_ptt,
227                                           u32 cmd,
228                                           u32 param,
229                                           u32 *o_mcp_resp,
230                                           u32 *o_mcp_param,
231                                           u32 i_txn_size,
232                                           u32 *i_buf);
233
234 /**
235  * @brief - Sends an NVM read command request to the MFW to get
236  *        a buffer.
237  *
238  * @param p_hwfn
239  * @param p_ptt
240  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
241  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
242  * @param param - [0:23] - Offset [24:31] - Size
243  * @param o_mcp_resp - MCP response
244  * @param o_mcp_param - MCP response param
245  * @param o_txn_size -  Buffer size output
246  * @param o_buf - Pointer to the buffer returned by the MFW.
247  *
248  * @param return ECORE_SUCCESS upon success.
249  */
250 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
251                                           struct ecore_ptt *p_ptt,
252                                           u32 cmd,
253                                           u32 param,
254                                           u32 *o_mcp_resp,
255                                           u32 *o_mcp_param,
256                                           u32 *o_txn_size,
257                                           u32 *o_buf);
258
259 /**
260  * @brief indicates whether the MFW objects [under mcp_info] are accessible
261  *
262  * @param p_hwfn
263  *
264  * @return true iff MFW is running and mcp_info is initialized
265  */
266 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
267
268 /**
269  * @brief request MFW to configure MSI-X for a VF
270  *
271  * @param p_hwfn
272  * @param p_ptt
273  * @param vf_id - absolute inside engine
274  * @param num_sbs - number of entries to request
275  *
276  * @return enum _ecore_status_t
277  */
278 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
279                                               struct ecore_ptt *p_ptt,
280                                               u8 vf_id, u8 num);
281
282 /**
283  * @brief - Halt the MCP.
284  *
285  * @param p_hwfn
286  * @param p_ptt
287  *
288  * @param return ECORE_SUCCESS upon success.
289  */
290 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
291                                     struct ecore_ptt *p_ptt);
292
293 /**
294  * @brief - Wake up the MCP.
295  *
296  * @param p_hwfn
297  * @param p_ptt
298  *
299  * @param return ECORE_SUCCESS upon success.
300  */
301 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
302                                       struct ecore_ptt *p_ptt);
303 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
304                                        struct ecore_ptt *p_ptt,
305                                        struct ecore_mcp_link_state *p_link,
306                                        u8 max_bw);
307 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
308                                        struct ecore_ptt *p_ptt,
309                                        struct ecore_mcp_link_state *p_link,
310                                        u8 min_bw);
311 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
312                                              struct ecore_ptt *p_ptt,
313                                              u32 mask_parities);
314 /**
315  * @brief - Sends crash mdump related info to the MFW.
316  *
317  * @param p_hwfn
318  * @param p_ptt
319  *
320  * @param return ECORE_SUCCESS upon success.
321  */
322 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
323                                                 struct ecore_ptt *p_ptt,
324                                                 u32 epoch);
325
326 /**
327  * @brief - Triggers a MFW crash dump procedure.
328  *
329  * @param p_hwfn
330  * @param p_ptt
331  *
332  * @param return ECORE_SUCCESS upon success.
333  */
334 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
335                                              struct ecore_ptt *p_ptt);
336
337 /**
338  * @brief - Gets the MFW allocation info for the given resource
339  *
340  *  @param p_hwfn
341  *  @param p_ptt
342  *  @param p_resc_info
343  *  @param p_mcp_resp
344  *  @param p_mcp_param
345  *
346  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
347  */
348 enum _ecore_status_t ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn,
349                                              struct ecore_ptt *p_ptt,
350                                              struct resource_info *p_resc_info,
351                                              u32 *p_mcp_resp, u32 *p_mcp_param);
352
353 /**
354  * @brief - Initiates PF FLR
355  *
356  * @param p_hwfn
357  * @param p_ptt
358  *
359  * @param return ECORE_SUCCESS upon success.
360  */
361 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
362                                                struct ecore_ptt *p_ptt);
363
364 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT  0
365 #define ECORE_MCP_RESC_LOCK_TO_NONE     255
366
367 /**
368  * @brief Acquires MFW generic resource lock
369  *
370  *  @param p_hwfn
371  *  @param p_ptt
372  *  @param resource_num - valid values are 0..31
373  *  @param timeout - lock timeout value in seconds
374  *                   (1..254, '0' - default value, '255' - no timeout).
375  *  @param p_granted - will be filled as true if the resource is free and
376  *                     granted, or false if it is busy.
377  *  @param p_owner - A pointer to a variable to be filled with the resource
378  *                   owner (0..15 = PF0-15, 16 = MFW, 17 = diag over serial).
379  *
380  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
381  */
382 enum _ecore_status_t ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn,
383                                          struct ecore_ptt *p_ptt,
384                                          u8 resource_num, u8 timeout,
385                                          bool *p_granted, u8 *p_owner);
386
387 /**
388  * @brief Releases MFW generic resource lock
389  *
390  *  @param p_hwfn
391  *  @param p_ptt
392  *  @param resource_num
393  *  @param force -  allows to release a reeource even if belongs to another PF
394  *  @param p_released - will be filled as true if the resource is released (or
395  *                      has been already released), and false if the resource is
396  *                      acquired by another PF and the `force' flag was not set.
397  *
398  * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
399  */
400 enum _ecore_status_t ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn,
401                                            struct ecore_ptt *p_ptt,
402                                            u8 resource_num, bool force,
403                                            bool *p_released);
404
405 #endif /* __ECORE_MCP_H__ */