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"
17 /* Using hwfn number (and not pf_num) is required since in CMT mode,
18 * same pf_num may be used by two different hwfn
19 * TODO - this shouldn't really be in .h file, but until all fields
20 * required during hw-init will be placed in their correct place in shmem
21 * we need it in ecore_dev.c [for readin the nvram reflection in shmem].
23 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \
25 ((p_hwfn)->abs_pf_id & 1) << 3) : \
27 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
29 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
30 ((_p_hwfn)->p_dev->num_ports_in_engines * \
31 ecore_device_num_engines((_p_hwfn)->p_dev)))
33 struct ecore_mcp_info {
34 /* Spinlock used for protecting the access to the MFW mailbox */
36 /* Flag to indicate whether sending a MFW mailbox is forbidden */
37 bool block_mb_sending;
39 /* Address of the MCP public area */
41 /* Address of the driver mailbox */
43 /* Address of the MFW mailbox */
45 /* Address of the port configuration (link) */
48 /* Current driver mailbox sequence */
50 /* Current driver pulse sequence */
53 struct ecore_mcp_link_params link_input;
54 struct ecore_mcp_link_state link_output;
55 struct ecore_mcp_link_capabilities link_capabilities;
57 struct ecore_mcp_function_info func_info;
65 struct ecore_mcp_mb_params {
76 struct ecore_drv_tlv_hdr {
77 u8 tlv_type; /* According to the enum below */
78 u8 tlv_length; /* In dwords - not including this header */
80 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
85 * @brief Initialize the interface with the MCP
87 * @param p_hwfn - HW func
88 * @param p_ptt - PTT required for register access
90 * @return enum _ecore_status_t
92 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
93 struct ecore_ptt *p_ptt);
96 * @brief Initialize the port interface with the MCP
100 * Can only be called after `num_ports_in_engines' is set
102 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
103 struct ecore_ptt *p_ptt);
105 * @brief Releases resources allocated during the init process.
107 * @param p_hwfn - HW func
108 * @param p_ptt - PTT required for register access
110 * @return enum _ecore_status_t
113 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
116 * @brief This function is called from the DPC context. After
117 * pointing PTT to the mfw mb, check for events sent by the MCP
118 * to the driver and ack them. In case a critical event
119 * detected, it will be handled here, otherwise the work will be
120 * queued to a sleepable work-queue.
122 * @param p_hwfn - HW function
123 * @param p_ptt - PTT required for register access
124 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
127 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
128 struct ecore_ptt *p_ptt);
131 * @brief When MFW doesn't get driver pulse for couple of seconds, at some
132 * threshold before timeout expires, it will generate interrupt
133 * through a dedicated status block (DPSB - Driver Pulse Status
134 * Block), which the driver should respond immediately, by
135 * providing keepalive indication after setting the PTT to the
136 * driver-MFW mailbox. This function is called directly from the
137 * DPC upon receiving the DPSB attention.
139 * @param p_hwfn - hw function
140 * @param p_ptt - PTT required for register access
141 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
144 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
145 struct ecore_ptt *p_ptt);
147 enum ecore_drv_role {
149 ECORE_DRV_ROLE_KDUMP,
152 struct ecore_load_req_params {
153 enum ecore_drv_role drv_role;
154 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
155 bool avoid_eng_reset;
160 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
161 * returns whether this PF is the first on the engine/port or function.
167 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
169 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
170 struct ecore_ptt *p_ptt,
171 struct ecore_load_req_params *p_params);
174 * @brief Sends a UNLOAD_REQ message to the MFW
179 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
181 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
182 struct ecore_ptt *p_ptt);
185 * @brief Sends a UNLOAD_DONE message to the MFW
190 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
192 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
193 struct ecore_ptt *p_ptt);
196 * @brief Read the MFW mailbox into Current buffer.
201 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
202 struct ecore_ptt *p_ptt);
205 * @brief Ack to mfw that driver finished FLR process for VFs
209 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
211 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
213 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
214 struct ecore_ptt *p_ptt,
218 * @brief - calls during init to read shmem of all function-related info.
222 * @param return ECORE_SUCCESS upon success.
224 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
225 struct ecore_ptt *p_ptt);
228 * @brief - Reset the MCP using mailbox command.
233 * @param return ECORE_SUCCESS upon success.
235 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
236 struct ecore_ptt *p_ptt);
239 * @brief - Sends an NVM write command request to the MFW with
244 * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
245 * DRV_MSG_CODE_NVM_PUT_FILE_DATA
246 * @param param - [0:23] - Offset [24:31] - Size
247 * @param o_mcp_resp - MCP response
248 * @param o_mcp_param - MCP response param
249 * @param i_txn_size - Buffer size
250 * @param i_buf - Pointer to the buffer
252 * @param return ECORE_SUCCESS upon success.
254 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
255 struct ecore_ptt *p_ptt,
264 * @brief - Sends an NVM read command request to the MFW to get
269 * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
270 * DRV_MSG_CODE_NVM_READ_NVRAM commands
271 * @param param - [0:23] - Offset [24:31] - Size
272 * @param o_mcp_resp - MCP response
273 * @param o_mcp_param - MCP response param
274 * @param o_txn_size - Buffer size output
275 * @param o_buf - Pointer to the buffer returned by the MFW.
277 * @param return ECORE_SUCCESS upon success.
279 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
280 struct ecore_ptt *p_ptt,
289 * @brief indicates whether the MFW objects [under mcp_info] are accessible
293 * @return true iff MFW is running and mcp_info is initialized
295 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
298 * @brief request MFW to configure MSI-X for a VF
302 * @param vf_id - absolute inside engine
303 * @param num_sbs - number of entries to request
305 * @return enum _ecore_status_t
307 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
308 struct ecore_ptt *p_ptt,
312 * @brief - Halt the MCP.
317 * @param return ECORE_SUCCESS upon success.
319 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
320 struct ecore_ptt *p_ptt);
323 * @brief - Wake up the MCP.
328 * @param return ECORE_SUCCESS upon success.
330 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
331 struct ecore_ptt *p_ptt);
332 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
333 struct ecore_ptt *p_ptt,
334 struct ecore_mcp_link_state *p_link,
336 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
337 struct ecore_ptt *p_ptt,
338 struct ecore_mcp_link_state *p_link,
340 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
341 struct ecore_ptt *p_ptt,
344 * @brief - Sends crash mdump related info to the MFW.
349 * @param return ECORE_SUCCESS upon success.
351 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
352 struct ecore_ptt *p_ptt,
356 * @brief - Triggers a MFW crash dump procedure.
361 * @param return ECORE_SUCCESS upon success.
363 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
364 struct ecore_ptt *p_ptt);
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
421 struct ecore_resc_lock_params {
422 /* Resource number [valid values are 0..31] */
425 /* Lock timeout value in seconds [default, none or 1..254] */
427 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0
428 #define ECORE_MCP_RESC_LOCK_TO_NONE 255
430 /* Number of times to retry locking */
433 /* The interval in usec between retries */
436 /* Use sleep or delay between retries */
439 /* Will be set as true if the resource is free and granted */
442 /* Will be filled with the resource owner.
443 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
449 * @brief Acquires MFW generic resource lock
455 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
458 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
459 struct ecore_resc_lock_params *p_params);
461 struct ecore_resc_unlock_params {
462 /* Resource number [valid values are 0..31] */
465 /* Allow to release a resource even if belongs to another PF */
468 /* Will be set as true if the resource is released */
473 * @brief Releases MFW generic resource lock
479 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
482 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
483 struct ecore_resc_unlock_params *p_params);
485 #endif /* __ECORE_MCP_H__ */