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 ecore_device_num_ports((_p_hwfn)->p_dev))
33 struct ecore_mcp_info {
34 /* List for mailbox commands which were sent and wait for a response */
37 /* Spinlock used for protecting the access to the mailbox commands list
38 * and the sending of the commands.
40 osal_spinlock_t cmd_lock;
42 /* Flag to indicate whether sending a MFW mailbox command is blocked */
45 /* Spinlock used for syncing SW link-changes and link-changes
46 * originating from attention context.
48 osal_spinlock_t link_lock;
50 /* Address of the MCP public area */
52 /* Address of the driver mailbox */
54 /* Address of the MFW mailbox */
56 /* Address of the port configuration (link) */
59 /* Current driver mailbox sequence */
61 /* Current driver pulse sequence */
64 struct ecore_mcp_link_params link_input;
65 struct ecore_mcp_link_state link_output;
66 struct ecore_mcp_link_capabilities link_capabilities;
68 struct ecore_mcp_function_info func_info;
75 /* Capabilties negotiated with the MFW */
79 struct ecore_mcp_mb_params {
90 struct ecore_drv_tlv_hdr {
91 u8 tlv_type; /* According to the enum below */
92 u8 tlv_length; /* In dwords - not including this header */
94 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
99 * @brief Initialize the interface with the MCP
101 * @param p_hwfn - HW func
102 * @param p_ptt - PTT required for register access
104 * @return enum _ecore_status_t
106 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
107 struct ecore_ptt *p_ptt);
110 * @brief Initialize the port interface with the MCP
114 * Can only be called after `num_ports_in_engine' is set
116 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
117 struct ecore_ptt *p_ptt);
119 * @brief Releases resources allocated during the init process.
121 * @param p_hwfn - HW func
122 * @param p_ptt - PTT required for register access
124 * @return enum _ecore_status_t
127 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
130 * @brief This function is called from the DPC context. After
131 * pointing PTT to the mfw mb, check for events sent by the MCP
132 * to the driver and ack them. In case a critical event
133 * detected, it will be handled here, otherwise the work will be
134 * queued to a sleepable work-queue.
136 * @param p_hwfn - HW function
137 * @param p_ptt - PTT required for register access
138 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
141 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
142 struct ecore_ptt *p_ptt);
145 * @brief When MFW doesn't get driver pulse for couple of seconds, at some
146 * threshold before timeout expires, it will generate interrupt
147 * through a dedicated status block (DPSB - Driver Pulse Status
148 * Block), which the driver should respond immediately, by
149 * providing keepalive indication after setting the PTT to the
150 * driver-MFW mailbox. This function is called directly from the
151 * DPC upon receiving the DPSB attention.
153 * @param p_hwfn - hw function
154 * @param p_ptt - PTT required for register access
155 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
158 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
159 struct ecore_ptt *p_ptt);
161 enum ecore_drv_role {
163 ECORE_DRV_ROLE_KDUMP,
166 struct ecore_load_req_params {
168 enum ecore_drv_role drv_role;
169 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
170 bool avoid_eng_reset;
171 enum ecore_override_force_load override_force_load;
178 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
179 * returns whether this PF is the first on the engine/port or function.
185 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
187 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
188 struct ecore_ptt *p_ptt,
189 struct ecore_load_req_params *p_params);
192 * @brief Sends a LOAD_DONE message to the MFW
197 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
199 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
200 struct ecore_ptt *p_ptt);
203 * @brief Sends a UNLOAD_REQ message to the MFW
208 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
210 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
211 struct ecore_ptt *p_ptt);
214 * @brief Sends a UNLOAD_DONE message to the MFW
219 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
221 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
222 struct ecore_ptt *p_ptt);
225 * @brief Read the MFW mailbox into Current buffer.
230 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
231 struct ecore_ptt *p_ptt);
234 * @brief Ack to mfw that driver finished FLR process for VFs
238 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
240 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
242 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
243 struct ecore_ptt *p_ptt,
247 * @brief - calls during init to read shmem of all function-related info.
251 * @param return ECORE_SUCCESS upon success.
253 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
254 struct ecore_ptt *p_ptt);
257 * @brief - Reset the MCP using mailbox command.
262 * @param return ECORE_SUCCESS upon success.
264 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
265 struct ecore_ptt *p_ptt);
268 * @brief indicates whether the MFW objects [under mcp_info] are accessible
272 * @return true iff MFW is running and mcp_info is initialized
274 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
277 * @brief request MFW to configure MSI-X for a VF
281 * @param vf_id - absolute inside engine
282 * @param num_sbs - number of entries to request
284 * @return enum _ecore_status_t
286 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
287 struct ecore_ptt *p_ptt,
291 * @brief - Halt the MCP.
296 * @param return ECORE_SUCCESS upon success.
298 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
299 struct ecore_ptt *p_ptt);
302 * @brief - Wake up the MCP.
307 * @param return ECORE_SUCCESS upon success.
309 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
310 struct ecore_ptt *p_ptt);
311 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
312 struct ecore_ptt *p_ptt,
313 struct ecore_mcp_link_state *p_link,
315 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
316 struct ecore_ptt *p_ptt,
317 struct ecore_mcp_link_state *p_link,
319 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
320 struct ecore_ptt *p_ptt,
323 * @brief - Sends crash mdump related info to the MFW.
328 * @param return ECORE_SUCCESS upon success.
330 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
331 struct ecore_ptt *p_ptt,
335 * @brief - Triggers a MFW crash dump procedure.
341 * @param return ECORE_SUCCESS upon success.
343 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
344 struct ecore_ptt *p_ptt);
346 struct ecore_mdump_retain_data {
354 * @brief - Gets the mdump retained data from the MFW.
358 * @param p_mdump_retain
360 * @param return ECORE_SUCCESS upon success.
363 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
364 struct ecore_mdump_retain_data *p_mdump_retain);
367 * @brief - Sets the MFW's max value for the given resource
372 * @param resc_max_val
375 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
378 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
379 enum ecore_resources res_id, u32 resc_max_val,
383 * @brief - Gets the MFW allocation info for the given resource
390 * @param p_resc_start
392 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
395 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
396 enum ecore_resources res_id, u32 *p_mcp_resp,
397 u32 *p_resc_num, u32 *p_resc_start);
400 * @brief - Initiates PF FLR
405 * @param return ECORE_SUCCESS upon success.
407 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
408 struct ecore_ptt *p_ptt);
410 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */
411 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31
413 enum ecore_resc_lock {
414 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
415 /* Locks that the MFW is aware of should be added here downwards */
417 /* Ecore only locks should be added here upwards */
418 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL,
420 /* A dummy value to be used for auxiliary functions in need of
421 * returning an 'error' value.
423 ECORE_RESC_LOCK_RESC_INVALID,
426 struct ecore_resc_lock_params {
427 /* Resource number [valid values are 0..31] */
430 /* Lock timeout value in seconds [default, none or 1..254] */
432 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0
433 #define ECORE_MCP_RESC_LOCK_TO_NONE 255
435 /* Number of times to retry locking */
437 #define ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT 10
439 /* The interval in usec between retries */
441 #define ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000
443 /* Use sleep or delay between retries */
446 /* Will be set as true if the resource is free and granted */
449 /* Will be filled with the resource owner.
450 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
456 * @brief Acquires MFW generic resource lock
462 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
465 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
466 struct ecore_resc_lock_params *p_params);
468 struct ecore_resc_unlock_params {
469 /* Resource number [valid values are 0..31] */
472 /* Allow to release a resource even if belongs to another PF */
475 /* Will be set as true if the resource is released */
480 * @brief Releases MFW generic resource lock
486 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
489 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
490 struct ecore_resc_unlock_params *p_params);
493 * @brief - default initialization for lock/unlock resource structs
495 * @param p_lock - lock params struct to be initialized; Can be OSAL_NULL
496 * @param p_unlock - unlock params struct to be initialized; Can be OSAL_NULL
497 * @param resource - the requested resource
498 * @paral b_is_permanent - disable retries & aging when set
500 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
501 struct ecore_resc_unlock_params *p_unlock,
502 enum ecore_resc_lock resource,
503 bool b_is_permanent);
506 * @brief Learn of supported MFW features; To be done during early init
511 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
512 struct ecore_ptt *p_ptt);
515 * @brief Inform MFW of set of features supported by driver. Should be done
516 * inside the contet of the LOAD_REQ.
521 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
522 struct ecore_ptt *p_ptt);
524 #endif /* __ECORE_MCP_H__ */