2 * Copyright (c) 2017-2018 Cavium, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
32 #ifndef __ECORE_MCP_H__
33 #define __ECORE_MCP_H__
36 #include "mcp_public.h"
38 #include "ecore_mcp_api.h"
39 #include "ecore_dev_api.h"
41 /* Using hwfn number (and not pf_num) is required since in CMT mode,
42 * same pf_num may be used by two different hwfn
43 * TODO - this shouldn't really be in .h file, but until all fields
44 * required during hw-init will be placed in their correct place in shmem
45 * we need it in ecore_dev.c [for readin the nvram reflection in shmem].
47 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \
49 ((p_hwfn)->abs_pf_id & 1) << 3) : \
51 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
53 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
54 ((_p_hwfn)->p_dev->num_ports_in_engines * \
55 ecore_device_num_engines((_p_hwfn)->p_dev)))
57 struct ecore_mcp_info {
58 /* Spinlock used for protecting the access to the MFW mailbox */
61 /* Spinglock used for syncing SW link-changes and link-changes
62 * originating from attention context.
64 osal_spinlock_t link_lock;
66 /* Flag to indicate whether sending a MFW mailbox is forbidden */
67 bool block_mb_sending;
69 /* Address of the MCP public area */
71 /* Address of the driver mailbox */
73 /* Address of the MFW mailbox */
75 /* Address of the port configuration (link) */
78 /* Current driver mailbox sequence */
80 /* Current driver pulse sequence */
83 struct ecore_mcp_link_params link_input;
84 struct ecore_mcp_link_state link_output;
85 struct ecore_mcp_link_capabilities link_capabilities;
87 struct ecore_mcp_function_info func_info;
94 /* Capabilties negotiated with the MFW */
98 struct ecore_mcp_mb_params {
109 enum ecore_ov_eswitch {
110 ECORE_OV_ESWITCH_NONE,
111 ECORE_OV_ESWITCH_VEB,
112 ECORE_OV_ESWITCH_VEPA
115 struct ecore_drv_tlv_hdr {
116 u8 tlv_type; /* According to the enum below */
117 u8 tlv_length; /* In dwords - not including this header */
119 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
124 * @brief Initialize the interface with the MCP
126 * @param p_hwfn - HW func
127 * @param p_ptt - PTT required for register access
129 * @return enum _ecore_status_t
131 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
132 struct ecore_ptt *p_ptt);
135 * @brief Intialize the port interface with the MCP
139 * Can only be called after `num_ports_in_engines' is set
141 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
142 struct ecore_ptt *p_ptt);
144 * @brief Releases resources allocated during the init process.
146 * @param p_hwfn - HW func
147 * @param p_ptt - PTT required for register access
149 * @return enum _ecore_status_t
152 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
155 * @brief This function is called from the DPC context. After
156 * pointing PTT to the mfw mb, check for events sent by the MCP
157 * to the driver and ack them. In case a critical event
158 * detected, it will be handled here, otherwise the work will be
159 * queued to a sleepable work-queue.
161 * @param p_hwfn - HW function
162 * @param p_ptt - PTT required for register access
163 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
166 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
167 struct ecore_ptt *p_ptt);
170 * @brief When MFW doesn't get driver pulse for couple of seconds, at some
171 * threshold before timeout expires, it will generate interrupt
172 * through a dedicated status block (DPSB - Driver Pulse Status
173 * Block), which the driver should respond immediately, by
174 * providing keepalive indication after setting the PTT to the
175 * driver-MFW mailbox. This function is called directly from the
176 * DPC upon receiving the DPSB attention.
178 * @param p_hwfn - hw function
179 * @param p_ptt - PTT required for register access
180 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
183 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
184 struct ecore_ptt *p_ptt);
186 enum ecore_drv_role {
188 ECORE_DRV_ROLE_KDUMP,
191 struct ecore_load_req_params {
193 enum ecore_drv_role drv_role;
194 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
195 bool avoid_eng_reset;
196 enum ecore_override_force_load override_force_load;
203 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
204 * returns whether this PF is the first on the engine/port or function.
210 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
212 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
213 struct ecore_ptt *p_ptt,
214 struct ecore_load_req_params *p_params);
217 * @brief Sends a UNLOAD_REQ message to the MFW
222 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
224 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
225 struct ecore_ptt *p_ptt);
228 * @brief Sends a UNLOAD_DONE message to the MFW
233 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
235 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
236 struct ecore_ptt *p_ptt);
239 * @brief Read the MFW mailbox into Current buffer.
244 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
245 struct ecore_ptt *p_ptt);
248 * @brief Ack to mfw that driver finished FLR process for VFs
252 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
254 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
256 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
257 struct ecore_ptt *p_ptt,
261 * @brief - calls during init to read shmem of all function-related info.
265 * @param return ECORE_SUCCESS upon success.
267 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
268 struct ecore_ptt *p_ptt);
271 * @brief - Reset the MCP using mailbox command.
276 * @param return ECORE_SUCCESS upon success.
278 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
279 struct ecore_ptt *p_ptt);
282 * @brief - Sends an NVM write command request to the MFW with
287 * @param cmd - Command: Either DRV_MSG_CODE_NVM_WRITE_NVRAM or
288 * DRV_MSG_CODE_NVM_PUT_FILE_DATA
289 * @param param - [0:23] - Offset [24:31] - Size
290 * @param o_mcp_resp - MCP response
291 * @param o_mcp_param - MCP response param
292 * @param i_txn_size - Buffer size
293 * @param i_buf - Pointer to the buffer
295 * @param return ECORE_SUCCESS upon success.
297 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
298 struct ecore_ptt *p_ptt,
307 * @brief - Sends an NVM read command request to the MFW to get
312 * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
313 * DRV_MSG_CODE_NVM_READ_NVRAM commands
314 * @param param - [0:23] - Offset [24:31] - Size
315 * @param o_mcp_resp - MCP response
316 * @param o_mcp_param - MCP response param
317 * @param o_txn_size - Buffer size output
318 * @param o_buf - Pointer to the buffer returned by the MFW.
320 * @param return ECORE_SUCCESS upon success.
322 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
323 struct ecore_ptt *p_ptt,
332 * @brief indicates whether the MFW objects [under mcp_info] are accessible
336 * @return true iff MFW is running and mcp_info is initialized
338 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
341 * @brief request MFW to configure MSI-X for a VF
345 * @param vf_id - absolute inside engine
346 * @param num_sbs - number of entries to request
348 * @return enum _ecore_status_t
350 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
351 struct ecore_ptt *p_ptt,
355 * @brief - Halt the MCP.
360 * @param return ECORE_SUCCESS upon success.
362 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
363 struct ecore_ptt *p_ptt);
366 * @brief - Wake up the MCP.
371 * @param return ECORE_SUCCESS upon success.
373 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
374 struct ecore_ptt *p_ptt);
375 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
376 struct ecore_ptt *p_ptt,
377 struct ecore_mcp_link_state *p_link,
379 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
380 struct ecore_ptt *p_ptt,
381 struct ecore_mcp_link_state *p_link,
383 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
384 struct ecore_ptt *p_ptt,
387 enum _ecore_status_t ecore_hw_init_first_eth(struct ecore_hwfn *p_hwfn,
388 struct ecore_ptt *p_ptt,
393 * @brief - Sends crash mdump related info to the MFW.
399 * @param return ECORE_SUCCESS upon success.
401 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
402 struct ecore_ptt *p_ptt,
406 * @brief - Triggers a MFW crash dump procedure.
411 * @param return ECORE_SUCCESS upon success.
413 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
414 struct ecore_ptt *p_ptt);
416 struct ecore_mdump_retain_data {
424 * @brief - Gets the mdump retained data from the MFW.
428 * @param p_mdump_retain
430 * @param return ECORE_SUCCESS upon success.
433 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
434 struct ecore_mdump_retain_data *p_mdump_retain);
437 * @brief - Clear the mdump retained data.
442 * @param return ECORE_SUCCESS upon success.
444 enum _ecore_status_t ecore_mcp_mdump_clr_retain(struct ecore_hwfn *p_hwfn,
445 struct ecore_ptt *p_ptt);
448 * @brief - Sets the MFW's max value for the given resource
453 * @param resc_max_val
456 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
459 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
460 enum ecore_resources res_id, u32 resc_max_val,
464 * @brief - Gets the MFW allocation info for the given resource
471 * @param p_resc_start
473 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
476 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
477 enum ecore_resources res_id, u32 *p_mcp_resp,
478 u32 *p_resc_num, u32 *p_resc_start);
481 * @brief - Initiates PF FLR
486 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
488 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
489 struct ecore_ptt *p_ptt);
492 * @brief Send eswitch mode to MFW
496 * @param eswitch - eswitch mode
498 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
501 ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
502 enum ecore_ov_eswitch eswitch);
504 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */
505 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31
507 enum ecore_resc_lock {
508 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
509 /* Locks that the MFW is aware of should be added here downwards */
511 /* Ecore only locks should be added here upwards */
512 ECORE_RESC_LOCK_PTP_PORT0,
513 ECORE_RESC_LOCK_PTP_PORT1,
514 ECORE_RESC_LOCK_PTP_PORT2,
515 ECORE_RESC_LOCK_PTP_PORT3,
516 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL
519 struct ecore_resc_lock_params {
520 /* Resource number [valid values are 0..31] */
523 /* Lock timeout value in seconds [default, none or 1..254] */
525 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0
526 #define ECORE_MCP_RESC_LOCK_TO_NONE 255
528 /* Number of times to retry locking */
531 /* The interval in usec between retries */
534 /* Use sleep or delay between retries */
537 /* Will be set as true if the resource is free and granted */
540 /* Will be filled with the resource owner.
541 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
547 * @brief Acquires MFW generic resource lock
553 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
556 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
557 struct ecore_resc_lock_params *p_params);
559 struct ecore_resc_unlock_params {
560 /* Resource number [valid values are 0..31] */
563 /* Allow to release a resource even if belongs to another PF */
566 /* Will be set as true if the resource is released */
571 * @brief Releases MFW generic resource lock
577 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
580 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
581 struct ecore_resc_unlock_params *p_params);
583 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
584 u32 offset, u32 val);
587 * @brief Learn of supported MFW features; To be done during early init
592 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
593 struct ecore_ptt *p_ptt);
596 * @brief Inform MFW of set of features supported by driver. Should be done
597 * inside the contet of the LOAD_REQ.
602 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
603 struct ecore_ptt *p_ptt);
606 * @brief Initialize MFW mailbox and sequence values for driver interaction.
611 enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn,
612 struct ecore_ptt *p_ptt);
614 #endif /* __ECORE_MCP_H__ */