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 struct ecore_mcp_info {
54 /* List for mailbox commands which were sent and wait for a response */
57 /* Spinlock used for protecting the access to the mailbox commands list
58 * and the sending of the commands.
60 osal_spinlock_t cmd_lock;
62 /* Flag to indicate whether sending a MFW mailbox command is blocked */
65 /* Spinlock used for syncing SW link-changes and link-changes
66 * originating from attention context.
68 osal_spinlock_t link_lock;
70 /* Address of the MCP public area */
72 /* Address of the driver mailbox */
74 /* Address of the MFW mailbox */
76 /* Address of the port configuration (link) */
79 /* Current driver mailbox sequence */
81 /* Current driver pulse sequence */
84 struct ecore_mcp_link_params link_input;
85 struct ecore_mcp_link_state link_output;
86 struct ecore_mcp_link_capabilities link_capabilities;
88 struct ecore_mcp_function_info func_info;
95 /* Capabilties negotiated with the MFW */
99 struct ecore_mcp_mb_params {
109 #define ECORE_MB_FLAG_CAN_SLEEP (0x1 << 0)
110 #define ECORE_MB_FLAG_AVOID_BLOCK (0x1 << 1)
111 #define ECORE_MB_FLAGS_IS_SET(params, flag) \
112 ((params) != OSAL_NULL && ((params)->flags & ECORE_MB_FLAG_##flag))
115 enum ecore_ov_eswitch {
116 ECORE_OV_ESWITCH_NONE,
117 ECORE_OV_ESWITCH_VEB,
118 ECORE_OV_ESWITCH_VEPA
121 struct ecore_drv_tlv_hdr {
122 u8 tlv_type; /* According to the enum below */
123 u8 tlv_length; /* In dwords - not including this header */
125 #define ECORE_DRV_TLV_FLAGS_CHANGED 0x01
130 * @brief Initialize the interface with the MCP
132 * @param p_hwfn - HW func
133 * @param p_ptt - PTT required for register access
135 * @return enum _ecore_status_t
137 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
138 struct ecore_ptt *p_ptt);
141 * @brief Initialize the port interface with the MCP
145 * Can only be called after `num_ports_in_engine' is set
147 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn,
148 struct ecore_ptt *p_ptt);
150 * @brief Releases resources allocated during the init process.
152 * @param p_hwfn - HW func
153 * @param p_ptt - PTT required for register access
155 * @return enum _ecore_status_t
158 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn);
161 * @brief This function is called from the DPC context. After
162 * pointing PTT to the mfw mb, check for events sent by the MCP
163 * to the driver and ack them. In case a critical event
164 * detected, it will be handled here, otherwise the work will be
165 * queued to a sleepable work-queue.
167 * @param p_hwfn - HW function
168 * @param p_ptt - PTT required for register access
169 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
172 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
173 struct ecore_ptt *p_ptt);
176 * @brief When MFW doesn't get driver pulse for couple of seconds, at some
177 * threshold before timeout expires, it will generate interrupt
178 * through a dedicated status block (DPSB - Driver Pulse Status
179 * Block), which the driver should respond immediately, by
180 * providing keepalive indication after setting the PTT to the
181 * driver-MFW mailbox. This function is called directly from the
182 * DPC upon receiving the DPSB attention.
184 * @param p_hwfn - hw function
185 * @param p_ptt - PTT required for register access
186 * @return enum _ecore_status_t - ECORE_SUCCESS - operation
189 enum _ecore_status_t ecore_issue_pulse(struct ecore_hwfn *p_hwfn,
190 struct ecore_ptt *p_ptt);
192 enum ecore_drv_role {
194 ECORE_DRV_ROLE_KDUMP,
197 struct ecore_load_req_params {
199 enum ecore_drv_role drv_role;
200 u8 timeout_val; /* 1..254, '0' - default value, '255' - no timeout */
201 bool avoid_eng_reset;
202 enum ecore_override_force_load override_force_load;
209 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
210 * returns whether this PF is the first on the engine/port or function.
216 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
218 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
219 struct ecore_ptt *p_ptt,
220 struct ecore_load_req_params *p_params);
223 * @brief Sends a LOAD_DONE message to the MFW
228 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
230 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
231 struct ecore_ptt *p_ptt);
234 * @brief Sends a CANCEL_LOAD_REQ message to the MFW
239 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
241 enum _ecore_status_t ecore_mcp_cancel_load_req(struct ecore_hwfn *p_hwfn,
242 struct ecore_ptt *p_ptt);
245 * @brief Sends a UNLOAD_REQ message to the MFW
250 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
252 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
253 struct ecore_ptt *p_ptt);
256 * @brief Sends a UNLOAD_DONE message to the MFW
261 * @return enum _ecore_status_t - ECORE_SUCCESS - Operation was successful.
263 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
264 struct ecore_ptt *p_ptt);
267 * @brief Read the MFW mailbox into Current buffer.
272 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn,
273 struct ecore_ptt *p_ptt);
276 * @brief Ack to mfw that driver finished FLR process for VFs
280 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
282 * @param return enum _ecore_status_t - ECORE_SUCCESS upon success.
284 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
285 struct ecore_ptt *p_ptt,
289 * @brief - calls during init to read shmem of all function-related info.
293 * @param return ECORE_SUCCESS upon success.
295 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
296 struct ecore_ptt *p_ptt);
299 * @brief - Reset the MCP using mailbox command.
304 * @param return ECORE_SUCCESS upon success.
306 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
307 struct ecore_ptt *p_ptt);
310 * @brief indicates whether the MFW objects [under mcp_info] are accessible
314 * @return true iff MFW is running and mcp_info is initialized
316 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn);
319 * @brief request MFW to configure MSI-X for a VF
323 * @param vf_id - absolute inside engine
324 * @param num_sbs - number of entries to request
326 * @return enum _ecore_status_t
328 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
329 struct ecore_ptt *p_ptt,
333 * @brief - Halt the MCP.
338 * @param return ECORE_SUCCESS upon success.
340 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
341 struct ecore_ptt *p_ptt);
344 * @brief - Wake up the MCP.
349 * @param return ECORE_SUCCESS upon success.
351 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
352 struct ecore_ptt *p_ptt);
353 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
354 struct ecore_ptt *p_ptt,
355 struct ecore_mcp_link_state *p_link,
357 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
358 struct ecore_ptt *p_ptt,
359 struct ecore_mcp_link_state *p_link,
361 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
362 struct ecore_ptt *p_ptt,
365 enum _ecore_status_t ecore_hw_init_first_eth(struct ecore_hwfn *p_hwfn,
366 struct ecore_ptt *p_ptt,
371 * @brief - Sends crash mdump related info to the MFW.
377 * @param return ECORE_SUCCESS upon success.
379 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
380 struct ecore_ptt *p_ptt,
384 * @brief - Triggers a MFW crash dump procedure.
389 * @param return ECORE_SUCCESS upon success.
391 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
392 struct ecore_ptt *p_ptt);
394 struct ecore_mdump_retain_data {
402 * @brief - Gets the mdump retained data from the MFW.
406 * @param p_mdump_retain
408 * @param return ECORE_SUCCESS upon success.
411 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
412 struct ecore_mdump_retain_data *p_mdump_retain);
415 * @brief - Sets the MFW's max value for the given resource
420 * @param resc_max_val
423 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
426 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
427 enum ecore_resources res_id, u32 resc_max_val,
431 * @brief - Gets the MFW allocation info for the given resource
438 * @param p_resc_start
440 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
443 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
444 enum ecore_resources res_id, u32 *p_mcp_resp,
445 u32 *p_resc_num, u32 *p_resc_start);
448 * @brief - Initiates PF FLR
453 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
455 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
456 struct ecore_ptt *p_ptt);
459 * @brief Send eswitch mode to MFW
463 * @param eswitch - eswitch mode
465 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
468 ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
469 enum ecore_ov_eswitch eswitch);
471 #define ECORE_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP /* 0 */
472 #define ECORE_MCP_RESC_LOCK_MAX_VAL 31
474 enum ecore_resc_lock {
475 ECORE_RESC_LOCK_DBG_DUMP = ECORE_MCP_RESC_LOCK_MIN_VAL,
476 /* Locks that the MFW is aware of should be added here downwards */
478 /* Ecore only locks should be added here upwards */
479 ECORE_RESC_LOCK_IND_TABLE = 26,
480 ECORE_RESC_LOCK_PTP_PORT0 = 27,
481 ECORE_RESC_LOCK_PTP_PORT1 = 28,
482 ECORE_RESC_LOCK_PTP_PORT2 = 29,
483 ECORE_RESC_LOCK_PTP_PORT3 = 30,
484 ECORE_RESC_LOCK_RESC_ALLOC = ECORE_MCP_RESC_LOCK_MAX_VAL,
486 /* A dummy value to be used for auxillary functions in need of
487 * returning an 'error' value.
489 ECORE_RESC_LOCK_RESC_INVALID,
492 struct ecore_resc_lock_params {
493 /* Resource number [valid values are 0..31] */
496 /* Lock timeout value in seconds [default, none or 1..254] */
498 #define ECORE_MCP_RESC_LOCK_TO_DEFAULT 0
499 #define ECORE_MCP_RESC_LOCK_TO_NONE 255
501 /* Number of times to retry locking */
503 #define ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT 10
505 /* The interval in usec between retries */
507 #define ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000
509 /* Use sleep or delay between retries */
512 /* Will be set as true if the resource is free and granted */
515 /* Will be filled with the resource owner.
516 * [0..15 = PF0-15, 16 = MFW, 17 = diag over serial]
522 * @brief Acquires MFW generic resource lock
528 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
531 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
532 struct ecore_resc_lock_params *p_params);
534 struct ecore_resc_unlock_params {
535 /* Resource number [valid values are 0..31] */
538 /* Allow to release a resource even if belongs to another PF */
541 /* Will be set as true if the resource is released */
546 * @brief Releases MFW generic resource lock
552 * @return enum _ecore_status_t - ECORE_SUCCESS - operation was successful.
555 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
556 struct ecore_resc_unlock_params *p_params);
559 * @brief - default initialization for lock/unlock resource structs
561 * @param p_lock - lock params struct to be initialized; Can be OSAL_NULL
562 * @param p_unlock - unlock params struct to be initialized; Can be OSAL_NULL
563 * @param resource - the requested resource
564 * @paral b_is_permanent - disable retries & aging when set
566 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
567 struct ecore_resc_unlock_params *p_unlock,
568 enum ecore_resc_lock resource,
569 bool b_is_permanent);
571 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
572 u32 offset, u32 val);
575 * @brief Learn of supported MFW features; To be done during early init
580 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
581 struct ecore_ptt *p_ptt);
584 * @brief Inform MFW of set of features supported by driver. Should be done
585 * inside the contet of the LOAD_REQ.
590 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
591 struct ecore_ptt *p_ptt);
594 * @brief Initialize MFW mailbox and sequence values for driver interaction.
599 enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn,
600 struct ecore_ptt *p_ptt);
602 enum ecore_mcp_drv_attr_cmd {
603 ECORE_MCP_DRV_ATTR_CMD_READ,
604 ECORE_MCP_DRV_ATTR_CMD_WRITE,
605 ECORE_MCP_DRV_ATTR_CMD_READ_CLEAR,
606 ECORE_MCP_DRV_ATTR_CMD_CLEAR,
609 struct ecore_mcp_drv_attr {
610 enum ecore_mcp_drv_attr_cmd attr_cmd;
613 /* R/RC - will be set with the read value
614 * W - should hold the required value to be written
619 /* W - mask/offset to be applied on the given value
627 * @brief Handle the drivers' attributes that are kept by the MFW.
634 ecore_mcp_drv_attribute(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
635 struct ecore_mcp_drv_attr *p_drv_attr);
638 * @brief Read ufp config from the shared memory.
644 ecore_mcp_read_ufp_config(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
647 * @brief Get the engine affinity configuration.
652 enum _ecore_status_t ecore_mcp_get_engine_config(struct ecore_hwfn *p_hwfn,
653 struct ecore_ptt *p_ptt);
656 * @brief Get the PPFID bitmap.
661 enum _ecore_status_t ecore_mcp_get_ppfid_bitmap(struct ecore_hwfn *p_hwfn,
662 struct ecore_ptt *p_ptt);
665 * @brief Acquire MCP lock to access to HW indirection table entries
670 * @param retry_interval
673 ecore_mcp_ind_table_lock(struct ecore_hwfn *p_hwfn,
674 struct ecore_ptt *p_ptt,
679 * @brief Release MCP lock of access to HW indirection table entries
685 ecore_mcp_ind_table_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
687 #endif /* __ECORE_MCP_H__ */