2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
9 #ifndef __ECORE_MCP_H__
10 #define __ECORE_MCP_H__
13 #include "mcp_public.h"
15 #include "ecore_mcp_api.h"
16 #include "ecore_dev_api.h"
18 /* Using hwfn number (and not pf_num) is required since in CMT mode,
19 * same pf_num may be used by two different hwfn
20 * TODO - this shouldn't really be in .h file, but until all fields
21 * required during hw-init will be placed in their correct place in shmem
22 * we need it in ecore_dev.c [for readin the nvram reflection in shmem].
24 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \
26 ((p_hwfn)->abs_pf_id & 1) << 3) : \
28 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
30 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
31 ((_p_hwfn)->p_dev->num_ports_in_engines * \
32 ecore_device_num_engines((_p_hwfn)->p_dev)))
34 struct ecore_mcp_info {
35 /* List for mailbox commands which were sent and wait for a response */
38 /* Spinlock used for protecting the access to the mailbox commands list
39 * and the sending of the commands.
41 osal_spinlock_t cmd_lock;
43 /* Flag to indicate whether sending a MFW mailbox command is blocked */
46 /* Spinlock used for syncing SW link-changes and link-changes
47 * originating from attention context.
49 osal_spinlock_t link_lock;
51 /* Address of the MCP public area */
53 /* Address of the driver mailbox */
55 /* Address of the MFW mailbox */
57 /* Address of the port configuration (link) */
60 /* Current driver mailbox sequence */
62 /* Current driver pulse sequence */
65 struct ecore_mcp_link_params link_input;
66 struct ecore_mcp_link_state link_output;
67 struct ecore_mcp_link_capabilities link_capabilities;
69 struct ecore_mcp_function_info func_info;
76 /* Capabilties negotiated with the MFW */
80 struct ecore_mcp_mb_params {
91 struct ecore_drv_tlv_hdr {
92 u8 tlv_type; /* According to the enum below */
93 u8 tlv_length; /* In dwords - not including this header */
95 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
100 * @brief Initialize the interface with the MCP
102 * @param p_hwfn - HW func
103 * @param p_ptt - PTT required for register access
105 * @return enum _ecore_status_t
107 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
108 struct ecore_ptt *p_ptt);
111 * @brief Initialize the port interface with the MCP
115 * Can only be called after `num_ports_in_engines' is set
117 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
118 struct ecore_ptt *p_ptt);
120 * @brief Releases resources allocated during the init process.
122 * @param p_hwfn - HW func
123 * @param p_ptt - PTT required for register access
125 * @return enum _ecore_status_t
128 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
131 * @brief This function is called from the DPC context. After
132 * pointing PTT to the mfw mb, check for events sent by the MCP
133 * to the driver and ack them. In case a critical event
134 * detected, it will be handled here, otherwise the work will be
135 * queued to a sleepable work-queue.
137 * @param p_hwfn - HW function
138 * @param p_ptt - PTT required for register access
139 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
142 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
143 struct ecore_ptt *p_ptt);
146 * @brief When MFW doesn't get driver pulse for couple of seconds, at some
147 * threshold before timeout expires, it will generate interrupt
148 * through a dedicated status block (DPSB - Driver Pulse Status
149 * Block), which the driver should respond immediately, by
150 * providing keepalive indication after setting the PTT to the
151 * driver-MFW mailbox. This function is called directly from the
152 * DPC upon receiving the DPSB attention.
154 * @param p_hwfn - hw function
155 * @param p_ptt - PTT required for register access
156 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
159 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
160 struct ecore_ptt *p_ptt);
162 enum ecore_drv_role {
164 ECORE_DRV_ROLE_KDUMP,
167 struct ecore_load_req_params {
169 enum ecore_drv_role drv_role;
170 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
171 bool avoid_eng_reset;
172 enum ecore_override_force_load override_force_load;
179 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
180 * returns whether this PF is the first on the engine/port or function.
186 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
188 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
189 struct ecore_ptt *p_ptt,
190 struct ecore_load_req_params *p_params);
193 * @brief Sends a LOAD_DONE message to the MFW
198 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
200 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
201 struct ecore_ptt *p_ptt);
204 * @brief Sends a UNLOAD_REQ message to the MFW
209 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
211 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
212 struct ecore_ptt *p_ptt);
215 * @brief Sends a UNLOAD_DONE message to the MFW
220 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
222 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
223 struct ecore_ptt *p_ptt);
226 * @brief Read the MFW mailbox into Current buffer.
231 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
232 struct ecore_ptt *p_ptt);
235 * @brief Ack to mfw that driver finished FLR process for VFs
239 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
241 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
243 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
244 struct ecore_ptt *p_ptt,
248 * @brief - calls during init to read shmem of all function-related info.
252 * @param return ECORE_SUCCESS upon success.
254 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
255 struct ecore_ptt *p_ptt);
258 * @brief - Reset the MCP using mailbox command.
263 * @param return ECORE_SUCCESS upon success.
265 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
266 struct ecore_ptt *p_ptt);
269 * @brief indicates whether the MFW objects [under mcp_info] are accessible
273 * @return true iff MFW is running and mcp_info is initialized
275 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
278 * @brief request MFW to configure MSI-X for a VF
282 * @param vf_id - absolute inside engine
283 * @param num_sbs - number of entries to request
285 * @return enum _ecore_status_t
287 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
288 struct ecore_ptt *p_ptt,
292 * @brief - Halt the MCP.
297 * @param return ECORE_SUCCESS upon success.
299 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
300 struct ecore_ptt *p_ptt);
303 * @brief - Wake up the MCP.
308 * @param return ECORE_SUCCESS upon success.
310 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
311 struct ecore_ptt *p_ptt);
312 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
313 struct ecore_ptt *p_ptt,
314 struct ecore_mcp_link_state *p_link,
316 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
317 struct ecore_ptt *p_ptt,
318 struct ecore_mcp_link_state *p_link,
320 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
321 struct ecore_ptt *p_ptt,
324 * @brief - Sends crash mdump related info to the MFW.
329 * @param return ECORE_SUCCESS upon success.
331 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
332 struct ecore_ptt *p_ptt,
336 * @brief - Triggers a MFW crash dump procedure.
342 * @param return ECORE_SUCCESS upon success.
344 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
345 struct ecore_ptt *p_ptt);
347 struct ecore_mdump_retain_data {
355 * @brief - Gets the mdump retained data from the MFW.
359 * @param p_mdump_retain
361 * @param return ECORE_SUCCESS upon success.
364 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
365 struct ecore_mdump_retain_data *p_mdump_retain);
368 * @brief - Sets the MFW's max value for the given resource
373 * @param resc_max_val
376 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
379 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
380 enum ecore_resources res_id, u32 resc_max_val,
384 * @brief - Gets the MFW allocation info for the given resource
391 * @param p_resc_start
393 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
396 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
397 enum ecore_resources res_id, u32 *p_mcp_resp,
398 u32 *p_resc_num, u32 *p_resc_start);
401 * @brief - Initiates PF FLR
406 * @param return ECORE_SUCCESS upon success.
408 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
409 struct ecore_ptt *p_ptt);
411 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */
412 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31
414 enum ecore_resc_lock {
415 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
416 /* Locks that the MFW is aware of should be added here downwards */
418 /* Ecore only locks should be added here upwards */
419 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL,
421 /* A dummy value to be used for auxiliary functions in need of
422 * returning an 'error' value.
424 ECORE_RESC_LOCK_RESC_INVALID,
427 struct ecore_resc_lock_params {
428 /* Resource number [valid values are 0..31] */
431 /* Lock timeout value in seconds [default, none or 1..254] */
433 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0
434 #define ECORE_MCP_RESC_LOCK_TO_NONE 255
436 /* Number of times to retry locking */
438 #define ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT 10
440 /* The interval in usec between retries */
442 #define ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000
444 /* Use sleep or delay between retries */
447 /* Will be set as true if the resource is free and granted */
450 /* Will be filled with the resource owner.
451 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
457 * @brief Acquires MFW generic resource lock
463 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
466 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
467 struct ecore_resc_lock_params *p_params);
469 struct ecore_resc_unlock_params {
470 /* Resource number [valid values are 0..31] */
473 /* Allow to release a resource even if belongs to another PF */
476 /* Will be set as true if the resource is released */
481 * @brief Releases MFW generic resource lock
487 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
490 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
491 struct ecore_resc_unlock_params *p_params);
494 * @brief - default initialization for lock/unlock resource structs
496 * @param p_lock - lock params struct to be initialized; Can be OSAL_NULL
497 * @param p_unlock - unlock params struct to be initialized; Can be OSAL_NULL
498 * @param resource - the requested resource
499 * @paral b_is_permanent - disable retries & aging when set
501 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
502 struct ecore_resc_unlock_params *p_unlock,
503 enum ecore_resc_lock resource,
504 bool b_is_permanent);
507 * @brief Learn of supported MFW features; To be done during early init
512 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
513 struct ecore_ptt *p_ptt);
516 * @brief Inform MFW of set of features supported by driver. Should be done
517 * inside the contet of the LOAD_REQ.
522 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
523 struct ecore_ptt *p_ptt);
525 #endif /* __ECORE_MCP_H__ */