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