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.
31 #ifndef __ECORE_MCP_H__
32 #define __ECORE_MCP_H__
35 #include "mcp_public.h"
37 #include "ecore_mcp_api.h"
38 #include "ecore_dev_api.h"
40 /* Using hwfn number (and not pf_num) is required since in CMT mode,
41 * same pf_num may be used by two different hwfn
42 * TODO - this shouldn't really be in .h file, but until all fields
43 * required during hw-init will be placed in their correct place in shmem
44 * we need it in ecore_dev.c [for readin the nvram reflection in shmem].
46 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (ECORE_IS_BB((p_hwfn)->p_dev) ? \
48 ((p_hwfn)->abs_pf_id & 1) << 3) : \
50 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
52 struct ecore_mcp_info {
53 /* List for mailbox commands which were sent and wait for a response */
56 /* Spinlock used for protecting the access to the mailbox commands list
57 * and the sending of the commands.
59 osal_spinlock_t cmd_lock;
61 /* Flag to indicate whether sending a MFW mailbox command is blocked */
64 /* Spinlock used for syncing SW link-changes and link-changes
65 * originating from attention context.
67 osal_spinlock_t link_lock;
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 {
108 #define ECORE_MB_FLAG_CAN_SLEEP (0x1 << 0)
109 #define ECORE_MB_FLAG_AVOID_BLOCK (0x1 << 1)
110 #define ECORE_MB_FLAGS_IS_SET(params, flag) \
111 ((params) != OSAL_NULL && ((params)->flags & ECORE_MB_FLAG_##flag))
114 enum ecore_ov_eswitch {
115 ECORE_OV_ESWITCH_NONE,
116 ECORE_OV_ESWITCH_VEB,
117 ECORE_OV_ESWITCH_VEPA
120 struct ecore_drv_tlv_hdr {
121 u8 tlv_type; /* According to the enum below */
122 u8 tlv_length; /* In dwords - not including this header */
124 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
129 * @brief Initialize the interface with the MCP
131 * @param p_hwfn - HW func
132 * @param p_ptt - PTT required for register access
134 * @return enum _ecore_status_t
136 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
137 struct ecore_ptt *p_ptt);
140 * @brief Initialize the port interface with the MCP
144 * Can only be called after `num_ports_in_engine' is set
146 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
147 struct ecore_ptt *p_ptt);
149 * @brief Releases resources allocated during the init process.
151 * @param p_hwfn - HW func
152 * @param p_ptt - PTT required for register access
154 * @return enum _ecore_status_t
157 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
160 * @brief This function is called from the DPC context. After
161 * pointing PTT to the mfw mb, check for events sent by the MCP
162 * to the driver and ack them. In case a critical event
163 * detected, it will be handled here, otherwise the work will be
164 * queued to a sleepable work-queue.
166 * @param p_hwfn - HW function
167 * @param p_ptt - PTT required for register access
168 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
171 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
172 struct ecore_ptt *p_ptt);
175 * @brief When MFW doesn't get driver pulse for couple of seconds, at some
176 * threshold before timeout expires, it will generate interrupt
177 * through a dedicated status block (DPSB - Driver Pulse Status
178 * Block), which the driver should respond immediately, by
179 * providing keepalive indication after setting the PTT to the
180 * driver-MFW mailbox. This function is called directly from the
181 * DPC upon receiving the DPSB attention.
183 * @param p_hwfn - hw function
184 * @param p_ptt - PTT required for register access
185 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
188 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
189 struct ecore_ptt *p_ptt);
191 enum ecore_drv_role {
193 ECORE_DRV_ROLE_KDUMP,
196 struct ecore_load_req_params {
198 enum ecore_drv_role drv_role;
199 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
200 bool avoid_eng_reset;
201 enum ecore_override_force_load override_force_load;
208 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
209 * returns whether this PF is the first on the engine/port or function.
215 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
217 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
218 struct ecore_ptt *p_ptt,
219 struct ecore_load_req_params *p_params);
222 * @brief Sends a LOAD_DONE message to the MFW
227 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
229 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
230 struct ecore_ptt *p_ptt);
233 * @brief Sends a CANCEL_LOAD_REQ message to the MFW
238 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
240 enum _ecore_status_t ecore_mcp_cancel_load_req(struct ecore_hwfn *p_hwfn,
241 struct ecore_ptt *p_ptt);
244 * @brief Sends a UNLOAD_REQ message to the MFW
249 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
251 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
252 struct ecore_ptt *p_ptt);
255 * @brief Sends a UNLOAD_DONE message to the MFW
260 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
262 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
263 struct ecore_ptt *p_ptt);
266 * @brief Read the MFW mailbox into Current buffer.
271 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
272 struct ecore_ptt *p_ptt);
275 * @brief Ack to mfw that driver finished FLR process for VFs
279 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
281 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
283 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
284 struct ecore_ptt *p_ptt,
288 * @brief - calls during init to read shmem of all function-related info.
292 * @param return ECORE_SUCCESS upon success.
294 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
295 struct ecore_ptt *p_ptt);
298 * @brief - Reset the MCP using mailbox command.
303 * @param return ECORE_SUCCESS upon success.
305 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
306 struct ecore_ptt *p_ptt);
309 * @brief indicates whether the MFW objects [under mcp_info] are accessible
313 * @return true iff MFW is running and mcp_info is initialized
315 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
318 * @brief request MFW to configure MSI-X for a VF
322 * @param vf_id - absolute inside engine
323 * @param num_sbs - number of entries to request
325 * @return enum _ecore_status_t
327 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
328 struct ecore_ptt *p_ptt,
332 * @brief - Halt the MCP.
337 * @param return ECORE_SUCCESS upon success.
339 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
340 struct ecore_ptt *p_ptt);
343 * @brief - Wake up the MCP.
348 * @param return ECORE_SUCCESS upon success.
350 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
351 struct ecore_ptt *p_ptt);
352 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
353 struct ecore_ptt *p_ptt,
354 struct ecore_mcp_link_state *p_link,
356 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
357 struct ecore_ptt *p_ptt,
358 struct ecore_mcp_link_state *p_link,
360 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
361 struct ecore_ptt *p_ptt,
364 enum _ecore_status_t ecore_hw_init_first_eth(struct ecore_hwfn *p_hwfn,
365 struct ecore_ptt *p_ptt,
370 * @brief - Sends crash mdump related info to the MFW.
376 * @param return ECORE_SUCCESS upon success.
378 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
379 struct ecore_ptt *p_ptt,
383 * @brief - Triggers a MFW crash dump procedure.
388 * @param return ECORE_SUCCESS upon success.
390 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
391 struct ecore_ptt *p_ptt);
393 struct ecore_mdump_retain_data {
401 * @brief - Gets the mdump retained data from the MFW.
405 * @param p_mdump_retain
407 * @param return ECORE_SUCCESS upon success.
410 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
411 struct ecore_mdump_retain_data *p_mdump_retain);
414 * @brief - Sets the MFW's max value for the given resource
419 * @param resc_max_val
422 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
425 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
426 enum ecore_resources res_id, u32 resc_max_val,
430 * @brief - Gets the MFW allocation info for the given resource
437 * @param p_resc_start
439 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
442 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
443 enum ecore_resources res_id, u32 *p_mcp_resp,
444 u32 *p_resc_num, u32 *p_resc_start);
447 * @brief - Initiates PF FLR
452 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
454 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
455 struct ecore_ptt *p_ptt);
458 * @brief Send eswitch mode to MFW
462 * @param eswitch - eswitch mode
464 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
467 ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
468 enum ecore_ov_eswitch eswitch);
470 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */
471 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31
473 enum ecore_resc_lock {
474 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
475 /* Locks that the MFW is aware of should be added here downwards */
477 /* Ecore only locks should be added here upwards */
478 ECORE_RESC_LOCK_IND_TABLE = 26,
479 ECORE_RESC_LOCK_PTP_PORT0 = 27,
480 ECORE_RESC_LOCK_PTP_PORT1 = 28,
481 ECORE_RESC_LOCK_PTP_PORT2 = 29,
482 ECORE_RESC_LOCK_PTP_PORT3 = 30,
483 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL,
485 /* A dummy value to be used for auxillary functions in need of
486 * returning an 'error' value.
488 ECORE_RESC_LOCK_RESC_INVALID,
491 struct ecore_resc_lock_params {
492 /* Resource number [valid values are 0..31] */
495 /* Lock timeout value in seconds [default, none or 1..254] */
497 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0
498 #define ECORE_MCP_RESC_LOCK_TO_NONE 255
500 /* Number of times to retry locking */
502 #define ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT 10
504 /* The interval in usec between retries */
506 #define ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000
508 /* Use sleep or delay between retries */
511 /* Will be set as true if the resource is free and granted */
514 /* Will be filled with the resource owner.
515 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
521 * @brief Acquires MFW generic resource lock
527 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
530 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
531 struct ecore_resc_lock_params *p_params);
533 struct ecore_resc_unlock_params {
534 /* Resource number [valid values are 0..31] */
537 /* Allow to release a resource even if belongs to another PF */
540 /* Will be set as true if the resource is released */
545 * @brief Releases MFW generic resource lock
551 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
554 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
555 struct ecore_resc_unlock_params *p_params);
558 * @brief - default initialization for lock/unlock resource structs
560 * @param p_lock - lock params struct to be initialized; Can be OSAL_NULL
561 * @param p_unlock - unlock params struct to be initialized; Can be OSAL_NULL
562 * @param resource - the requested resource
563 * @paral b_is_permanent - disable retries & aging when set
565 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
566 struct ecore_resc_unlock_params *p_unlock,
567 enum ecore_resc_lock resource,
568 bool b_is_permanent);
570 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
571 u32 offset, u32 val);
574 * @brief Learn of supported MFW features; To be done during early init
579 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
580 struct ecore_ptt *p_ptt);
583 * @brief Inform MFW of set of features supported by driver. Should be done
584 * inside the contet of the LOAD_REQ.
589 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
590 struct ecore_ptt *p_ptt);
593 * @brief Initialize MFW mailbox and sequence values for driver interaction.
598 enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn,
599 struct ecore_ptt *p_ptt);
601 enum ecore_mcp_drv_attr_cmd {
602 ECORE_MCP_DRV_ATTR_CMD_READ,
603 ECORE_MCP_DRV_ATTR_CMD_WRITE,
604 ECORE_MCP_DRV_ATTR_CMD_READ_CLEAR,
605 ECORE_MCP_DRV_ATTR_CMD_CLEAR,
608 struct ecore_mcp_drv_attr {
609 enum ecore_mcp_drv_attr_cmd attr_cmd;
612 /* R/RC - will be set with the read value
613 * W - should hold the required value to be written
618 /* W - mask/offset to be applied on the given value
626 * @brief Handle the drivers' attributes that are kept by the MFW.
633 ecore_mcp_drv_attribute(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
634 struct ecore_mcp_drv_attr *p_drv_attr);
637 * @brief Read ufp config from the shared memory.
643 ecore_mcp_read_ufp_config(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
646 * @brief Get the engine affinity configuration.
651 enum _ecore_status_t ecore_mcp_get_engine_config(struct ecore_hwfn *p_hwfn,
652 struct ecore_ptt *p_ptt);
655 * @brief Get the PPFID bitmap.
660 enum _ecore_status_t ecore_mcp_get_ppfid_bitmap(struct ecore_hwfn *p_hwfn,
661 struct ecore_ptt *p_ptt);
664 * @brief Acquire MCP lock to access to HW indirection table entries
669 * @param retry_interval
672 ecore_mcp_ind_table_lock(struct ecore_hwfn *p_hwfn,
673 struct ecore_ptt *p_ptt,
678 * @brief Release MCP lock of access to HW indirection table entries
684 ecore_mcp_ind_table_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
686 #endif /* __ECORE_MCP_H__ */