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