net/qede/base: serialize access to MFW mbox
[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 /* TODO - this is only correct as long as only BB is supported, and
29  * no port-swapping is implemented; Afterwards we'll need to fix it.
30  */
31 #define MFW_PORT(_p_hwfn)       ((_p_hwfn)->abs_pf_id % \
32                                  ((_p_hwfn)->p_dev->num_ports_in_engines * 2))
33 struct ecore_mcp_info {
34         osal_spinlock_t lock;   /* Spinlock used for accessing MCP mailbox */
35
36         /* Flag to indicate whether sending a MFW mailbox is forbidden */
37         bool block_mb_sending;
38
39         u32 public_base;        /* Address of the MCP public area */
40         u32 drv_mb_addr;        /* Address of the driver mailbox */
41         u32 mfw_mb_addr;        /* Address of the MFW mailbox */
42         u32 port_addr;          /* Address of the port configuration (link) */
43         u16 drv_mb_seq;         /* Current driver mailbox sequence */
44         u16 drv_pulse_seq;      /* Current driver pulse sequence */
45         struct ecore_mcp_link_params       link_input;
46         struct ecore_mcp_link_state        link_output;
47         struct ecore_mcp_link_capabilities link_capabilities;
48         struct ecore_mcp_function_info     func_info;
49
50         u8 *mfw_mb_cur;
51         u8 *mfw_mb_shadow;
52         u16 mfw_mb_length;
53         u16 mcp_hist;
54 };
55
56 struct ecore_mcp_mb_params {
57         u32 cmd;
58         u32 param;
59         union drv_union_data *p_data_src;
60         union drv_union_data *p_data_dst;
61         u32 mcp_resp;
62         u32 mcp_param;
63 };
64
65 /**
66  * @brief Initialize the interface with the MCP
67  *
68  * @param p_hwfn - HW func
69  * @param p_ptt - PTT required for register access
70  *
71  * @return enum _ecore_status_t
72  */
73 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
74                                         struct ecore_ptt *p_ptt);
75
76 /**
77  * @brief Initialize the port interface with the MCP
78  *
79  * @param p_hwfn
80  * @param p_ptt
81  * Can only be called after `num_ports_in_engines' is set
82  */
83 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
84                              struct ecore_ptt *p_ptt);
85 /**
86  * @brief Releases resources allocated during the init process.
87  *
88  * @param p_hwfn - HW func
89  * @param p_ptt - PTT required for register access
90  *
91  * @return enum _ecore_status_t
92  */
93
94 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
95
96 /**
97  * @brief This function is called from the DPC context. After
98  * pointing PTT to the mfw mb, check for events sent by the MCP
99  * to the driver and ack them. In case a critical event
100  * detected, it will be handled here, otherwise the work will be
101  * queued to a sleepable work-queue.
102  *
103  * @param p_hwfn - HW function
104  * @param p_ptt - PTT required for register access
105  * @return enum _ecore_status_t - ECORE_SUCCESS - operation
106  * was successul.
107  */
108 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
109                                              struct ecore_ptt *p_ptt);
110
111 /**
112  * @brief When MFW doesn't get driver pulse for couple of seconds, at some
113  * threshold before timeout expires, it will generate interrupt
114  * through a dedicated status block (DPSB - Driver Pulse Status
115  * Block), which the driver should respond immediately, by
116  * providing keepalive indication after setting the PTT to the
117  * driver-MFW mailbox. This function is called directly from the
118  * DPC upon receiving the DPSB attention.
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_issue_pulse(struct ecore_hwfn *p_hwfn,
126                                        struct ecore_ptt *p_ptt);
127
128 /**
129  * @brief Sends a LOAD_REQ to the MFW, and in case operation
130  *        succeed, returns whether this PF is the first on the
131  *        chip/engine/port or function. This function should be
132  *        called when driver is ready to accept MFW events after
133  *        Storms initializations are done.
134  *
135  * @param p_hwfn       - hw function
136  * @param p_ptt        - PTT required for register access
137  * @param p_load_code  - The MCP response param containing one
138  *      of the following:
139  *      FW_MSG_CODE_DRV_LOAD_ENGINE
140  *      FW_MSG_CODE_DRV_LOAD_PORT
141  *      FW_MSG_CODE_DRV_LOAD_FUNCTION
142  * @return enum _ecore_status_t -
143  *      ECORE_SUCCESS - Operation was successul.
144  *      ECORE_BUSY - Operation failed
145  */
146 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
147                                         struct ecore_ptt *p_ptt,
148                                         u32 *p_load_code);
149
150 /**
151  * @brief Read the MFW mailbox into Current buffer.
152  *
153  * @param p_hwfn
154  * @param p_ptt
155  */
156 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
157
158 /**
159  * @brief Ack to mfw that driver finished FLR process for VFs
160  *
161  * @param p_hwfn
162  * @param p_ptt
163  * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
164  *
165  * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
166  */
167 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
168                                           struct ecore_ptt *p_ptt,
169                                           u32 *vfs_to_ack);
170
171 /**
172  * @brief - calls during init to read shmem of all function-related info.
173  *
174  * @param p_hwfn
175  *
176  * @param return ECORE_SUCCESS upon success.
177  */
178 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
179                                                     struct ecore_ptt *p_ptt);
180
181 /**
182  * @brief - Reset the MCP using mailbox command.
183  *
184  * @param p_hwfn
185  * @param p_ptt
186  *
187  * @param return ECORE_SUCCESS upon success.
188  */
189 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
190                                      struct ecore_ptt *p_ptt);
191
192 /**
193  * @brief - Sends an NVM write command request to the MFW with
194  *          payload.
195  *
196  * @param p_hwfn
197  * @param p_ptt
198  * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
199  *            DRV_MSG_CODE_NVM_PUT_FILE_DATA
200  * @param param - [0:23] - Offset [24:31] - Size
201  * @param o_mcp_resp - MCP response
202  * @param o_mcp_param - MCP response param
203  * @param i_txn_size -  Buffer size
204  * @param i_buf - Pointer to the buffer
205  *
206  * @param return ECORE_SUCCESS upon success.
207  */
208 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
209                                           struct ecore_ptt *p_ptt,
210                                           u32 cmd,
211                                           u32 param,
212                                           u32 *o_mcp_resp,
213                                           u32 *o_mcp_param,
214                                           u32 i_txn_size, u32 *i_buf);
215
216 /**
217  * @brief - Sends an NVM read command request to the MFW to get
218  *        a buffer.
219  *
220  * @param p_hwfn
221  * @param p_ptt
222  * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
223  *            DRV_MSG_CODE_NVM_READ_NVRAM commands
224  * @param param - [0:23] - Offset [24:31] - Size
225  * @param o_mcp_resp - MCP response
226  * @param o_mcp_param - MCP response param
227  * @param o_txn_size -  Buffer size output
228  * @param o_buf - Pointer to the buffer returned by the MFW.
229  *
230  * @param return ECORE_SUCCESS upon success.
231  */
232 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
233                                           struct ecore_ptt *p_ptt,
234                                           u32 cmd,
235                                           u32 param,
236                                           u32 *o_mcp_resp,
237                                           u32 *o_mcp_param,
238                                           u32 *o_txn_size, u32 *o_buf);
239
240 /**
241  * @brief indicates whether the MFW objects [under mcp_info] are accessible
242  *
243  * @param p_hwfn
244  *
245  * @return true iff MFW is running and mcp_info is initialized
246  */
247 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
248
249 /**
250  * @brief request MFW to configure MSI-X for a VF
251  *
252  * @param p_hwfn
253  * @param p_ptt
254  * @param vf_id - absolute inside engine
255  * @param num_sbs - number of entries to request
256  *
257  * @return enum _ecore_status_t
258  */
259 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
260                                               struct ecore_ptt *p_ptt,
261                                               u8 vf_id, u8 num);
262
263 /**
264  * @brief - Halt the MCP.
265  *
266  * @param p_hwfn
267  * @param p_ptt
268  *
269  * @param return ECORE_SUCCESS upon success.
270  */
271 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
272                                     struct ecore_ptt *p_ptt);
273
274 /**
275  * @brief - Wake up the MCP.
276  *
277  * @param p_hwfn
278  * @param p_ptt
279  *
280  * @param return ECORE_SUCCESS upon success.
281  */
282 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
283                                       struct ecore_ptt *p_ptt);
284 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
285                                        struct ecore_ptt *p_ptt,
286                                        struct ecore_mcp_link_state *p_link,
287                                        u8 max_bw);
288 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
289                                        struct ecore_ptt *p_ptt,
290                                        struct ecore_mcp_link_state *p_link,
291                                        u8 min_bw);
292 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
293                                              struct ecore_ptt *p_ptt,
294                                              u32 mask_parities);
295 #endif /* __ECORE_MCP_H__ */