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_engine * \
55 ecore_device_num_engines((_p_hwfn)->p_dev)))
57 struct ecore_mcp_info {
58 /* List for mailbox commands which were sent and wait for a response */
61 /* Spinlock used for protecting the access to the mailbox commands list
62 * and the sending of the commands.
64 osal_spinlock_t cmd_lock;
66 /* Flag to indicate whether sending a MFW mailbox command is blocked */
69 /* Spinlock used for syncing SW link-changes and link-changes
70 * originating from attention context.
72 osal_spinlock_t link_lock;
74 /* Address of the MCP public area */
76 /* Address of the driver mailbox */
78 /* Address of the MFW mailbox */
80 /* Address of the port configuration (link) */
83 /* Current driver mailbox sequence */
85 /* Current driver pulse sequence */
88 struct ecore_mcp_link_params link_input;
89 struct ecore_mcp_link_state link_output;
90 struct ecore_mcp_link_capabilities link_capabilities;
92 struct ecore_mcp_function_info func_info;
99 /* Capabilties negotiated with the MFW */
103 struct ecore_mcp_mb_params {
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 Intialize 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 UNLOAD_REQ message to the MFW
227 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
229 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
230 struct ecore_ptt *p_ptt);
233 * @brief Sends a UNLOAD_DONE message to the MFW
238 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
240 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
241 struct ecore_ptt *p_ptt);
244 * @brief Read the MFW mailbox into Current buffer.
249 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
250 struct ecore_ptt *p_ptt);
253 * @brief Ack to mfw that driver finished FLR process for VFs
257 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
259 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
261 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
262 struct ecore_ptt *p_ptt,
266 * @brief - calls during init to read shmem of all function-related info.
270 * @param return ECORE_SUCCESS upon success.
272 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
273 struct ecore_ptt *p_ptt);
276 * @brief - Reset the MCP using mailbox command.
281 * @param return ECORE_SUCCESS upon success.
283 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
284 struct ecore_ptt *p_ptt);
287 * @brief indicates whether the MFW objects [under mcp_info] are accessible
291 * @return true iff MFW is running and mcp_info is initialized
293 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
296 * @brief request MFW to configure MSI-X for a VF
300 * @param vf_id - absolute inside engine
301 * @param num_sbs - number of entries to request
303 * @return enum _ecore_status_t
305 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
306 struct ecore_ptt *p_ptt,
310 * @brief - Halt the MCP.
315 * @param return ECORE_SUCCESS upon success.
317 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
318 struct ecore_ptt *p_ptt);
321 * @brief - Wake up the MCP.
326 * @param return ECORE_SUCCESS upon success.
328 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
329 struct ecore_ptt *p_ptt);
330 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
331 struct ecore_ptt *p_ptt,
332 struct ecore_mcp_link_state *p_link,
334 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
335 struct ecore_ptt *p_ptt,
336 struct ecore_mcp_link_state *p_link,
338 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
339 struct ecore_ptt *p_ptt,
342 enum _ecore_status_t ecore_hw_init_first_eth(struct ecore_hwfn *p_hwfn,
343 struct ecore_ptt *p_ptt,
348 * @brief - Sends crash mdump related info to the MFW.
354 * @param return ECORE_SUCCESS upon success.
356 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
357 struct ecore_ptt *p_ptt,
361 * @brief - Triggers a MFW crash dump procedure.
366 * @param return ECORE_SUCCESS upon success.
368 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
369 struct ecore_ptt *p_ptt);
371 struct ecore_mdump_retain_data {
379 * @brief - Gets the mdump retained data from the MFW.
383 * @param p_mdump_retain
385 * @param return ECORE_SUCCESS upon success.
388 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
389 struct ecore_mdump_retain_data *p_mdump_retain);
392 * @brief - Sets the MFW's max value for the given resource
397 * @param resc_max_val
400 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
403 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
404 enum ecore_resources res_id, u32 resc_max_val,
408 * @brief - Gets the MFW allocation info for the given resource
415 * @param p_resc_start
417 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
420 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
421 enum ecore_resources res_id, u32 *p_mcp_resp,
422 u32 *p_resc_num, u32 *p_resc_start);
425 * @brief - Initiates PF FLR
430 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
432 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
433 struct ecore_ptt *p_ptt);
436 * @brief Send eswitch mode to MFW
440 * @param eswitch - eswitch mode
442 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
445 ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
446 enum ecore_ov_eswitch eswitch);
448 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */
449 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31
451 enum ecore_resc_lock {
452 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
453 /* Locks that the MFW is aware of should be added here downwards */
455 /* Ecore only locks should be added here upwards */
456 ECORE_RESC_LOCK_PTP_PORT0,
457 ECORE_RESC_LOCK_PTP_PORT1,
458 ECORE_RESC_LOCK_PTP_PORT2,
459 ECORE_RESC_LOCK_PTP_PORT3,
460 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL,
462 /* A dummy value to be used for auxillary functions in need of
463 * returning an 'error' value.
465 ECORE_RESC_LOCK_RESC_INVALID,
468 struct ecore_resc_lock_params {
469 /* Resource number [valid values are 0..31] */
472 /* Lock timeout value in seconds [default, none or 1..254] */
474 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0
475 #define ECORE_MCP_RESC_LOCK_TO_NONE 255
477 /* Number of times to retry locking */
479 #define ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT 10
481 /* The interval in usec between retries */
483 #define ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000
485 /* Use sleep or delay between retries */
488 /* Will be set as true if the resource is free and granted */
491 /* Will be filled with the resource owner.
492 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
498 * @brief Acquires MFW generic resource lock
504 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
507 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
508 struct ecore_resc_lock_params *p_params);
510 struct ecore_resc_unlock_params {
511 /* Resource number [valid values are 0..31] */
514 /* Allow to release a resource even if belongs to another PF */
517 /* Will be set as true if the resource is released */
522 * @brief Releases MFW generic resource lock
528 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
531 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
532 struct ecore_resc_unlock_params *p_params);
535 * @brief - default initialization for lock/unlock resource structs
537 * @param p_lock - lock params struct to be initialized; Can be OSAL_NULL
538 * @param p_unlock - unlock params struct to be initialized; Can be OSAL_NULL
539 * @param resource - the requested resource
540 * @paral b_is_permanent - disable retries & aging when set
542 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
543 struct ecore_resc_unlock_params *p_unlock,
544 enum ecore_resc_lock resource,
545 bool b_is_permanent);
547 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
548 u32 offset, u32 val);
551 * @brief Learn of supported MFW features; To be done during early init
556 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
557 struct ecore_ptt *p_ptt);
560 * @brief Inform MFW of set of features supported by driver. Should be done
561 * inside the contet of the LOAD_REQ.
566 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
567 struct ecore_ptt *p_ptt);
570 * @brief Initialize MFW mailbox and sequence values for driver interaction.
575 enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn,
576 struct ecore_ptt *p_ptt);
578 #endif /* __ECORE_MCP_H__ */