13126df22SRasesh Mody /* SPDX-License-Identifier: BSD-3-Clause
29adde217SRasesh Mody * Copyright (c) 2016 - 2018 Cavium Inc.
3ec94dbc5SRasesh Mody * All rights reserved.
49adde217SRasesh Mody * www.cavium.com
5ec94dbc5SRasesh Mody */
6ec94dbc5SRasesh Mody
7ec94dbc5SRasesh Mody #include "bcm_osal.h"
8ec94dbc5SRasesh Mody #include "ecore.h"
9ec94dbc5SRasesh Mody #include "ecore_status.h"
10bdc40630SRasesh Mody #include "nvm_cfg.h"
11ec94dbc5SRasesh Mody #include "ecore_mcp.h"
12ec94dbc5SRasesh Mody #include "mcp_public.h"
13ec94dbc5SRasesh Mody #include "reg_addr.h"
14ec94dbc5SRasesh Mody #include "ecore_hw.h"
15ec94dbc5SRasesh Mody #include "ecore_init_fw_funcs.h"
1686a2265eSRasesh Mody #include "ecore_sriov.h"
1722d07d93SRasesh Mody #include "ecore_vf.h"
1886a2265eSRasesh Mody #include "ecore_iov_api.h"
19ec94dbc5SRasesh Mody #include "ecore_gtt_reg_addr.h"
20ec94dbc5SRasesh Mody #include "ecore_iro.h"
2126ae839dSRasesh Mody #include "ecore_dcbx.h"
222a0c610bSRasesh Mody #include "ecore_sp_commands.h"
2347af7019SRasesh Mody #include "ecore_cxt.h"
24ec94dbc5SRasesh Mody
257ed1cd53SRasesh Mody #define GRCBASE_MCP 0xe00000
26ec94dbc5SRasesh Mody
273b307c55SRasesh Mody #define ECORE_MCP_RESP_ITER_US 10
28ec94dbc5SRasesh Mody #define ECORE_DRV_MB_MAX_RETRIES (500 * 1000) /* Account for 5 sec */
29ec94dbc5SRasesh Mody #define ECORE_MCP_RESET_RETRIES (50 * 1000) /* Account for 500 msec */
30ec94dbc5SRasesh Mody
313b307c55SRasesh Mody #ifndef ASIC_ONLY
323b307c55SRasesh Mody /* Non-ASIC:
333b307c55SRasesh Mody * The waiting interval is multiplied by 100 to reduce the impact of the
343b307c55SRasesh Mody * built-in delay of 100usec in each ecore_rd().
353b307c55SRasesh Mody * In addition, a factor of 4 comparing to ASIC is applied.
363b307c55SRasesh Mody */
373b307c55SRasesh Mody #define ECORE_EMUL_MCP_RESP_ITER_US (ECORE_MCP_RESP_ITER_US * 100)
383b307c55SRasesh Mody #define ECORE_EMUL_DRV_MB_MAX_RETRIES ((ECORE_DRV_MB_MAX_RETRIES / 100) * 4)
393b307c55SRasesh Mody #define ECORE_EMUL_MCP_RESET_RETRIES ((ECORE_MCP_RESET_RETRIES / 100) * 4)
403b307c55SRasesh Mody #endif
413b307c55SRasesh Mody
42ec94dbc5SRasesh Mody #define DRV_INNER_WR(_p_hwfn, _p_ptt, _ptr, _offset, _val) \
43ec94dbc5SRasesh Mody ecore_wr(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset), \
44ec94dbc5SRasesh Mody _val)
45ec94dbc5SRasesh Mody
46ec94dbc5SRasesh Mody #define DRV_INNER_RD(_p_hwfn, _p_ptt, _ptr, _offset) \
47ec94dbc5SRasesh Mody ecore_rd(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset))
48ec94dbc5SRasesh Mody
49ec94dbc5SRasesh Mody #define DRV_MB_WR(_p_hwfn, _p_ptt, _field, _val) \
50ec94dbc5SRasesh Mody DRV_INNER_WR(p_hwfn, _p_ptt, drv_mb_addr, \
51ec94dbc5SRasesh Mody OFFSETOF(struct public_drv_mb, _field), _val)
52ec94dbc5SRasesh Mody
53ec94dbc5SRasesh Mody #define DRV_MB_RD(_p_hwfn, _p_ptt, _field) \
54ec94dbc5SRasesh Mody DRV_INNER_RD(_p_hwfn, _p_ptt, drv_mb_addr, \
55ec94dbc5SRasesh Mody OFFSETOF(struct public_drv_mb, _field))
56ec94dbc5SRasesh Mody
57ec94dbc5SRasesh Mody #define PDA_COMP (((FW_MAJOR_VERSION) + (FW_MINOR_VERSION << 8)) << \
5804b00049SRasesh Mody DRV_ID_PDA_COMP_VER_OFFSET)
59ec94dbc5SRasesh Mody
6004b00049SRasesh Mody #define MCP_BYTES_PER_MBIT_OFFSET 17
61ec94dbc5SRasesh Mody
62ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
63ec94dbc5SRasesh Mody static int loaded;
64ec94dbc5SRasesh Mody static int loaded_port[MAX_NUM_PORTS] = { 0 };
65ec94dbc5SRasesh Mody #endif
66ec94dbc5SRasesh Mody
ecore_mcp_is_init(struct ecore_hwfn * p_hwfn)67ec94dbc5SRasesh Mody bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn)
68ec94dbc5SRasesh Mody {
69ec94dbc5SRasesh Mody if (!p_hwfn->mcp_info || !p_hwfn->mcp_info->public_base)
70ec94dbc5SRasesh Mody return false;
71ec94dbc5SRasesh Mody return true;
72ec94dbc5SRasesh Mody }
73ec94dbc5SRasesh Mody
ecore_mcp_cmd_port_init(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)74ec94dbc5SRasesh Mody void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
75ec94dbc5SRasesh Mody {
76ec94dbc5SRasesh Mody u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
77ec94dbc5SRasesh Mody PUBLIC_PORT);
78ec94dbc5SRasesh Mody u32 mfw_mb_offsize = ecore_rd(p_hwfn, p_ptt, addr);
79ec94dbc5SRasesh Mody
80ec94dbc5SRasesh Mody p_hwfn->mcp_info->port_addr = SECTION_ADDR(mfw_mb_offsize,
81ec94dbc5SRasesh Mody MFW_PORT(p_hwfn));
82ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
83ec94dbc5SRasesh Mody "port_addr = 0x%x, port_id 0x%02x\n",
84ec94dbc5SRasesh Mody p_hwfn->mcp_info->port_addr, MFW_PORT(p_hwfn));
85ec94dbc5SRasesh Mody }
86ec94dbc5SRasesh Mody
ecore_mcp_read_mb(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)87ec94dbc5SRasesh Mody void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
88ec94dbc5SRasesh Mody {
89ec94dbc5SRasesh Mody u32 length = MFW_DRV_MSG_MAX_DWORDS(p_hwfn->mcp_info->mfw_mb_length);
90ec94dbc5SRasesh Mody OSAL_BE32 tmp;
91ec94dbc5SRasesh Mody u32 i;
92ec94dbc5SRasesh Mody
93ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
94ec94dbc5SRasesh Mody if (CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev))
95ec94dbc5SRasesh Mody return;
96ec94dbc5SRasesh Mody #endif
97ec94dbc5SRasesh Mody
98ec94dbc5SRasesh Mody if (!p_hwfn->mcp_info->public_base)
99ec94dbc5SRasesh Mody return;
100ec94dbc5SRasesh Mody
101ec94dbc5SRasesh Mody for (i = 0; i < length; i++) {
102ec94dbc5SRasesh Mody tmp = ecore_rd(p_hwfn, p_ptt,
103ec94dbc5SRasesh Mody p_hwfn->mcp_info->mfw_mb_addr +
104ec94dbc5SRasesh Mody (i << 2) + sizeof(u32));
105ec94dbc5SRasesh Mody
106ec94dbc5SRasesh Mody ((u32 *)p_hwfn->mcp_info->mfw_mb_cur)[i] =
107ec94dbc5SRasesh Mody OSAL_BE32_TO_CPU(tmp);
108ec94dbc5SRasesh Mody }
109ec94dbc5SRasesh Mody }
110ec94dbc5SRasesh Mody
11122c99696SRasesh Mody struct ecore_mcp_cmd_elem {
11222c99696SRasesh Mody osal_list_entry_t list;
11322c99696SRasesh Mody struct ecore_mcp_mb_params *p_mb_params;
11422c99696SRasesh Mody u16 expected_seq_num;
11522c99696SRasesh Mody bool b_is_completed;
11622c99696SRasesh Mody };
11722c99696SRasesh Mody
11822c99696SRasesh Mody /* Must be called while cmd_lock is acquired */
11922c99696SRasesh Mody static struct ecore_mcp_cmd_elem *
ecore_mcp_cmd_add_elem(struct ecore_hwfn * p_hwfn,struct ecore_mcp_mb_params * p_mb_params,u16 expected_seq_num)12022c99696SRasesh Mody ecore_mcp_cmd_add_elem(struct ecore_hwfn *p_hwfn,
12122c99696SRasesh Mody struct ecore_mcp_mb_params *p_mb_params,
12222c99696SRasesh Mody u16 expected_seq_num)
12322c99696SRasesh Mody {
12422c99696SRasesh Mody struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL;
12522c99696SRasesh Mody
12622c99696SRasesh Mody p_cmd_elem = OSAL_ZALLOC(p_hwfn->p_dev, GFP_ATOMIC,
12722c99696SRasesh Mody sizeof(*p_cmd_elem));
12822c99696SRasesh Mody if (!p_cmd_elem) {
12922c99696SRasesh Mody DP_NOTICE(p_hwfn, false,
13022c99696SRasesh Mody "Failed to allocate `struct ecore_mcp_cmd_elem'\n");
13122c99696SRasesh Mody goto out;
13222c99696SRasesh Mody }
13322c99696SRasesh Mody
13422c99696SRasesh Mody p_cmd_elem->p_mb_params = p_mb_params;
13522c99696SRasesh Mody p_cmd_elem->expected_seq_num = expected_seq_num;
13622c99696SRasesh Mody OSAL_LIST_PUSH_HEAD(&p_cmd_elem->list, &p_hwfn->mcp_info->cmd_list);
13722c99696SRasesh Mody out:
13822c99696SRasesh Mody return p_cmd_elem;
13922c99696SRasesh Mody }
14022c99696SRasesh Mody
14122c99696SRasesh Mody /* Must be called while cmd_lock is acquired */
ecore_mcp_cmd_del_elem(struct ecore_hwfn * p_hwfn,struct ecore_mcp_cmd_elem * p_cmd_elem)14222c99696SRasesh Mody static void ecore_mcp_cmd_del_elem(struct ecore_hwfn *p_hwfn,
14322c99696SRasesh Mody struct ecore_mcp_cmd_elem *p_cmd_elem)
14422c99696SRasesh Mody {
14522c99696SRasesh Mody OSAL_LIST_REMOVE_ENTRY(&p_cmd_elem->list, &p_hwfn->mcp_info->cmd_list);
14622c99696SRasesh Mody OSAL_FREE(p_hwfn->p_dev, p_cmd_elem);
14722c99696SRasesh Mody }
14822c99696SRasesh Mody
14922c99696SRasesh Mody /* Must be called while cmd_lock is acquired */
15022c99696SRasesh Mody static struct ecore_mcp_cmd_elem *
ecore_mcp_cmd_get_elem(struct ecore_hwfn * p_hwfn,u16 seq_num)15122c99696SRasesh Mody ecore_mcp_cmd_get_elem(struct ecore_hwfn *p_hwfn, u16 seq_num)
15222c99696SRasesh Mody {
15322c99696SRasesh Mody struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL;
15422c99696SRasesh Mody
15522c99696SRasesh Mody OSAL_LIST_FOR_EACH_ENTRY(p_cmd_elem, &p_hwfn->mcp_info->cmd_list, list,
15622c99696SRasesh Mody struct ecore_mcp_cmd_elem) {
15722c99696SRasesh Mody if (p_cmd_elem->expected_seq_num == seq_num)
15822c99696SRasesh Mody return p_cmd_elem;
15922c99696SRasesh Mody }
16022c99696SRasesh Mody
16122c99696SRasesh Mody return OSAL_NULL;
16222c99696SRasesh Mody }
16322c99696SRasesh Mody
ecore_mcp_free(struct ecore_hwfn * p_hwfn)164ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn)
165ec94dbc5SRasesh Mody {
166ec94dbc5SRasesh Mody if (p_hwfn->mcp_info) {
16722c99696SRasesh Mody struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL, *p_tmp;
16822c99696SRasesh Mody
1698335b809SRasesh Mody OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info->mfw_mb_cur);
1708335b809SRasesh Mody OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info->mfw_mb_shadow);
1718335b809SRasesh Mody
17222c99696SRasesh Mody OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
17322c99696SRasesh Mody OSAL_LIST_FOR_EACH_ENTRY_SAFE(p_cmd_elem, p_tmp,
17422c99696SRasesh Mody &p_hwfn->mcp_info->cmd_list, list,
17522c99696SRasesh Mody struct ecore_mcp_cmd_elem) {
17622c99696SRasesh Mody ecore_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
17722c99696SRasesh Mody }
17822c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
17922c99696SRasesh Mody
18022c99696SRasesh Mody #ifdef CONFIG_ECORE_LOCK_ALLOC
18122c99696SRasesh Mody OSAL_SPIN_LOCK_DEALLOC(&p_hwfn->mcp_info->cmd_lock);
18222c99696SRasesh Mody OSAL_SPIN_LOCK_DEALLOC(&p_hwfn->mcp_info->link_lock);
18322c99696SRasesh Mody #endif
184ec94dbc5SRasesh Mody }
18522c99696SRasesh Mody
186ec94dbc5SRasesh Mody OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info);
187ec94dbc5SRasesh Mody
188ec94dbc5SRasesh Mody return ECORE_SUCCESS;
189ec94dbc5SRasesh Mody }
190ec94dbc5SRasesh Mody
19123c5600aSRasesh Mody /* Maximum of 1 sec to wait for the SHMEM ready indication */
19223c5600aSRasesh Mody #define ECORE_MCP_SHMEM_RDY_MAX_RETRIES 20
19323c5600aSRasesh Mody #define ECORE_MCP_SHMEM_RDY_ITER_MS 50
19423c5600aSRasesh Mody
ecore_load_mcp_offsets(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)195ec94dbc5SRasesh Mody static enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn,
196ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
197ec94dbc5SRasesh Mody {
198ec94dbc5SRasesh Mody struct ecore_mcp_info *p_info = p_hwfn->mcp_info;
1993b307c55SRasesh Mody u32 drv_mb_offsize, mfw_mb_offsize, val;
20023c5600aSRasesh Mody u8 cnt = ECORE_MCP_SHMEM_RDY_MAX_RETRIES;
20123c5600aSRasesh Mody u8 msec = ECORE_MCP_SHMEM_RDY_ITER_MS;
202ec94dbc5SRasesh Mody u32 mcp_pf_id = MCP_PF_ID(p_hwfn);
203ec94dbc5SRasesh Mody
2043b307c55SRasesh Mody val = ecore_rd(p_hwfn, p_ptt, MCP_REG_CACHE_PAGING_ENABLE);
2053b307c55SRasesh Mody p_info->public_base = ecore_rd(p_hwfn, p_ptt, MISC_REG_SHARED_MEM_ADDR);
2063b307c55SRasesh Mody if (!p_info->public_base) {
2073b307c55SRasesh Mody DP_NOTICE(p_hwfn, false,
2083b307c55SRasesh Mody "The address of the MCP scratch-pad is not configured\n");
209ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
2103b307c55SRasesh Mody /* Zeroed "public_base" implies no MFW */
2113b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
2123b307c55SRasesh Mody DP_INFO(p_hwfn, "Emulation: Assume no MFW\n");
2133b307c55SRasesh Mody #endif
214ec94dbc5SRasesh Mody return ECORE_INVAL;
215ec94dbc5SRasesh Mody }
216ec94dbc5SRasesh Mody
217ec94dbc5SRasesh Mody p_info->public_base |= GRCBASE_MCP;
218ec94dbc5SRasesh Mody
21923c5600aSRasesh Mody /* Get the MFW MB address and number of supported messages */
22023c5600aSRasesh Mody mfw_mb_offsize = ecore_rd(p_hwfn, p_ptt,
22123c5600aSRasesh Mody SECTION_OFFSIZE_ADDR(p_info->public_base,
22223c5600aSRasesh Mody PUBLIC_MFW_MB));
22323c5600aSRasesh Mody p_info->mfw_mb_addr = SECTION_ADDR(mfw_mb_offsize, mcp_pf_id);
22423c5600aSRasesh Mody p_info->mfw_mb_length = (u16)ecore_rd(p_hwfn, p_ptt,
22523c5600aSRasesh Mody p_info->mfw_mb_addr);
22623c5600aSRasesh Mody
22723c5600aSRasesh Mody /* @@@TBD:
22823c5600aSRasesh Mody * The driver can notify that there was an MCP reset, and read the SHMEM
22923c5600aSRasesh Mody * values before the MFW has completed initializing them.
23023c5600aSRasesh Mody * As a temporary solution, the "sup_msgs" field is used as a data ready
23123c5600aSRasesh Mody * indication.
23223c5600aSRasesh Mody * This should be replaced with an actual indication when it is provided
23323c5600aSRasesh Mody * by the MFW.
23423c5600aSRasesh Mody */
23523c5600aSRasesh Mody while (!p_info->mfw_mb_length && cnt--) {
23623c5600aSRasesh Mody OSAL_MSLEEP(msec);
23723c5600aSRasesh Mody p_info->mfw_mb_length = (u16)ecore_rd(p_hwfn, p_ptt,
23823c5600aSRasesh Mody p_info->mfw_mb_addr);
23923c5600aSRasesh Mody }
24023c5600aSRasesh Mody
24123c5600aSRasesh Mody if (!cnt) {
24223c5600aSRasesh Mody DP_NOTICE(p_hwfn, false,
24323c5600aSRasesh Mody "Failed to get the SHMEM ready notification after %d msec\n",
24423c5600aSRasesh Mody ECORE_MCP_SHMEM_RDY_MAX_RETRIES * msec);
24523c5600aSRasesh Mody return ECORE_TIMEOUT;
24623c5600aSRasesh Mody }
24723c5600aSRasesh Mody
248ec94dbc5SRasesh Mody /* Calculate the driver and MFW mailbox address */
249ec94dbc5SRasesh Mody drv_mb_offsize = ecore_rd(p_hwfn, p_ptt,
250ec94dbc5SRasesh Mody SECTION_OFFSIZE_ADDR(p_info->public_base,
251ec94dbc5SRasesh Mody PUBLIC_DRV_MB));
252ec94dbc5SRasesh Mody p_info->drv_mb_addr = SECTION_ADDR(drv_mb_offsize, mcp_pf_id);
253ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
2549455b556SRasesh Mody "drv_mb_offsiz = 0x%x, drv_mb_addr = 0x%x"
2559455b556SRasesh Mody " mcp_pf_id = 0x%x\n",
256ec94dbc5SRasesh Mody drv_mb_offsize, p_info->drv_mb_addr, mcp_pf_id);
257ec94dbc5SRasesh Mody
258ec94dbc5SRasesh Mody /* Get the current driver mailbox sequence before sending
259ec94dbc5SRasesh Mody * the first command
260ec94dbc5SRasesh Mody */
261ec94dbc5SRasesh Mody p_info->drv_mb_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_mb_header) &
262ec94dbc5SRasesh Mody DRV_MSG_SEQ_NUMBER_MASK;
263ec94dbc5SRasesh Mody
264ec94dbc5SRasesh Mody /* Get current FW pulse sequence */
265ec94dbc5SRasesh Mody p_info->drv_pulse_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_pulse_mb) &
266ec94dbc5SRasesh Mody DRV_PULSE_SEQ_MASK;
267ec94dbc5SRasesh Mody
26822c99696SRasesh Mody p_info->mcp_hist = ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
269ec94dbc5SRasesh Mody
270ec94dbc5SRasesh Mody return ECORE_SUCCESS;
271ec94dbc5SRasesh Mody }
272ec94dbc5SRasesh Mody
ecore_mcp_cmd_init(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)273ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
274ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
275ec94dbc5SRasesh Mody {
276ec94dbc5SRasesh Mody struct ecore_mcp_info *p_info;
277ec94dbc5SRasesh Mody u32 size;
278ec94dbc5SRasesh Mody
279ec94dbc5SRasesh Mody /* Allocate mcp_info structure */
280ec94dbc5SRasesh Mody p_hwfn->mcp_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
281ec94dbc5SRasesh Mody sizeof(*p_hwfn->mcp_info));
28298abf84eSRasesh Mody if (!p_hwfn->mcp_info) {
28398abf84eSRasesh Mody DP_NOTICE(p_hwfn, false, "Failed to allocate mcp_info\n");
28498abf84eSRasesh Mody return ECORE_NOMEM;
28598abf84eSRasesh Mody }
286ec94dbc5SRasesh Mody p_info = p_hwfn->mcp_info;
287ec94dbc5SRasesh Mody
2888335b809SRasesh Mody /* Initialize the MFW spinlocks */
2898335b809SRasesh Mody #ifdef CONFIG_ECORE_LOCK_ALLOC
29098abf84eSRasesh Mody if (OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_info->cmd_lock)) {
29198abf84eSRasesh Mody OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info);
29298abf84eSRasesh Mody return ECORE_NOMEM;
29398abf84eSRasesh Mody }
29498abf84eSRasesh Mody if (OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_info->link_lock)) {
29598abf84eSRasesh Mody OSAL_SPIN_LOCK_DEALLOC(&p_info->cmd_lock);
29698abf84eSRasesh Mody OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info);
29798abf84eSRasesh Mody return ECORE_NOMEM;
29898abf84eSRasesh Mody }
2998335b809SRasesh Mody #endif
3008335b809SRasesh Mody OSAL_SPIN_LOCK_INIT(&p_info->cmd_lock);
3018335b809SRasesh Mody OSAL_SPIN_LOCK_INIT(&p_info->link_lock);
3028335b809SRasesh Mody
3038335b809SRasesh Mody OSAL_LIST_INIT(&p_info->cmd_list);
3048335b809SRasesh Mody
305ec94dbc5SRasesh Mody if (ecore_load_mcp_offsets(p_hwfn, p_ptt) != ECORE_SUCCESS) {
306ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false, "MCP is not initialized\n");
3073b307c55SRasesh Mody /* Do not free mcp_info here, since "public_base" indicates that
308ec94dbc5SRasesh Mody * the MCP is not initialized
309ec94dbc5SRasesh Mody */
310ec94dbc5SRasesh Mody return ECORE_SUCCESS;
311ec94dbc5SRasesh Mody }
312ec94dbc5SRasesh Mody
313ec94dbc5SRasesh Mody size = MFW_DRV_MSG_MAX_DWORDS(p_info->mfw_mb_length) * sizeof(u32);
314ec94dbc5SRasesh Mody p_info->mfw_mb_cur = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, size);
315ec94dbc5SRasesh Mody p_info->mfw_mb_shadow = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, size);
316ec94dbc5SRasesh Mody if (!p_info->mfw_mb_shadow || !p_info->mfw_mb_addr)
317ec94dbc5SRasesh Mody goto err;
318ec94dbc5SRasesh Mody
319ec94dbc5SRasesh Mody return ECORE_SUCCESS;
320ec94dbc5SRasesh Mody
321ec94dbc5SRasesh Mody err:
32298abf84eSRasesh Mody DP_NOTICE(p_hwfn, false, "Failed to allocate mcp memory\n");
323ec94dbc5SRasesh Mody ecore_mcp_free(p_hwfn);
324ec94dbc5SRasesh Mody return ECORE_NOMEM;
325ec94dbc5SRasesh Mody }
326ec94dbc5SRasesh Mody
ecore_mcp_reread_offsets(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)32722c99696SRasesh Mody static void ecore_mcp_reread_offsets(struct ecore_hwfn *p_hwfn,
32822c99696SRasesh Mody struct ecore_ptt *p_ptt)
3291db31dcdSHarish Patil {
33022c99696SRasesh Mody u32 generic_por_0 = ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
3311db31dcdSHarish Patil
33222c99696SRasesh Mody /* Use MCP history register to check if MCP reset occurred between init
33322c99696SRasesh Mody * time and now.
3341db31dcdSHarish Patil */
33522c99696SRasesh Mody if (p_hwfn->mcp_info->mcp_hist != generic_por_0) {
33622c99696SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
33722c99696SRasesh Mody "Rereading MCP offsets [mcp_hist 0x%08x, generic_por_0 0x%08x]\n",
33822c99696SRasesh Mody p_hwfn->mcp_info->mcp_hist, generic_por_0);
3391db31dcdSHarish Patil
34022c99696SRasesh Mody ecore_load_mcp_offsets(p_hwfn, p_ptt);
34122c99696SRasesh Mody ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
3421db31dcdSHarish Patil }
3431db31dcdSHarish Patil }
3441db31dcdSHarish Patil
ecore_mcp_reset(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)345ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
346ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
347ec94dbc5SRasesh Mody {
3483b307c55SRasesh Mody u32 prev_generic_por_0, seq, delay = ECORE_MCP_RESP_ITER_US, cnt = 0;
3493b307c55SRasesh Mody u32 retries = ECORE_MCP_RESET_RETRIES;
350ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
351ec94dbc5SRasesh Mody
352ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
3533b307c55SRasesh Mody if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
3543b307c55SRasesh Mody delay = ECORE_EMUL_MCP_RESP_ITER_US;
3553b307c55SRasesh Mody retries = ECORE_EMUL_MCP_RESET_RETRIES;
3563b307c55SRasesh Mody }
357ec94dbc5SRasesh Mody #endif
358a474d1c1SRasesh Mody if (p_hwfn->mcp_info->b_block_cmd) {
359a474d1c1SRasesh Mody DP_NOTICE(p_hwfn, false,
360a474d1c1SRasesh Mody "The MFW is not responsive. Avoid sending MCP_RESET mailbox command.\n");
361a474d1c1SRasesh Mody return ECORE_ABORTED;
362a474d1c1SRasesh Mody }
363a474d1c1SRasesh Mody
36422c99696SRasesh Mody /* Ensure that only a single thread is accessing the mailbox */
36522c99696SRasesh Mody OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
36622c99696SRasesh Mody
3673b307c55SRasesh Mody prev_generic_por_0 = ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
368ec94dbc5SRasesh Mody
369ec94dbc5SRasesh Mody /* Set drv command along with the updated sequence */
37022c99696SRasesh Mody ecore_mcp_reread_offsets(p_hwfn, p_ptt);
37122c99696SRasesh Mody seq = ++p_hwfn->mcp_info->drv_mb_seq;
372ec94dbc5SRasesh Mody DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (DRV_MSG_CODE_MCP_RESET | seq));
373ec94dbc5SRasesh Mody
3743b307c55SRasesh Mody /* Give the MFW up to 500 second (50*1000*10usec) to resume */
375ec94dbc5SRasesh Mody do {
376ec94dbc5SRasesh Mody OSAL_UDELAY(delay);
377ec94dbc5SRasesh Mody
3783b307c55SRasesh Mody if (ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0) !=
3793b307c55SRasesh Mody prev_generic_por_0)
3803b307c55SRasesh Mody break;
3813b307c55SRasesh Mody } while (cnt++ < retries);
3823b307c55SRasesh Mody
3833b307c55SRasesh Mody if (ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0) !=
3843b307c55SRasesh Mody prev_generic_por_0) {
385ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
386ec94dbc5SRasesh Mody "MCP was reset after %d usec\n", cnt * delay);
387ec94dbc5SRasesh Mody } else {
388ec94dbc5SRasesh Mody DP_ERR(p_hwfn, "Failed to reset MCP\n");
389ec94dbc5SRasesh Mody rc = ECORE_AGAIN;
390ec94dbc5SRasesh Mody }
391ec94dbc5SRasesh Mody
39222c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
393ec94dbc5SRasesh Mody
394ec94dbc5SRasesh Mody return rc;
395ec94dbc5SRasesh Mody }
396ec94dbc5SRasesh Mody
3973b307c55SRasesh Mody #ifndef ASIC_ONLY
ecore_emul_mcp_load_req(struct ecore_hwfn * p_hwfn,struct ecore_mcp_mb_params * p_mb_params)3983b307c55SRasesh Mody static void ecore_emul_mcp_load_req(struct ecore_hwfn *p_hwfn,
3993b307c55SRasesh Mody struct ecore_mcp_mb_params *p_mb_params)
4003b307c55SRasesh Mody {
4013b307c55SRasesh Mody if (GET_MFW_FIELD(p_mb_params->param, DRV_ID_MCP_HSI_VER) !=
4023b307c55SRasesh Mody 1 /* ECORE_LOAD_REQ_HSI_VER_1 */) {
4033b307c55SRasesh Mody p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1;
4043b307c55SRasesh Mody return;
4053b307c55SRasesh Mody }
4063b307c55SRasesh Mody
4073b307c55SRasesh Mody if (!loaded)
4083b307c55SRasesh Mody p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_ENGINE;
4093b307c55SRasesh Mody else if (!loaded_port[p_hwfn->port_id])
4103b307c55SRasesh Mody p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_PORT;
4113b307c55SRasesh Mody else
4123b307c55SRasesh Mody p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_FUNCTION;
4133b307c55SRasesh Mody
4143b307c55SRasesh Mody /* On CMT, always tell that it's engine */
4153b307c55SRasesh Mody if (ECORE_IS_CMT(p_hwfn->p_dev))
4163b307c55SRasesh Mody p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_ENGINE;
4173b307c55SRasesh Mody
4183b307c55SRasesh Mody loaded++;
4193b307c55SRasesh Mody loaded_port[p_hwfn->port_id]++;
4203b307c55SRasesh Mody
4213b307c55SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
4223b307c55SRasesh Mody "Load phase: 0x%08x load cnt: 0x%x port id=%d port_load=%d\n",
4233b307c55SRasesh Mody p_mb_params->mcp_resp, loaded, p_hwfn->port_id,
4243b307c55SRasesh Mody loaded_port[p_hwfn->port_id]);
4253b307c55SRasesh Mody }
4263b307c55SRasesh Mody
ecore_emul_mcp_unload_req(struct ecore_hwfn * p_hwfn)4273b307c55SRasesh Mody static void ecore_emul_mcp_unload_req(struct ecore_hwfn *p_hwfn)
4283b307c55SRasesh Mody {
4293b307c55SRasesh Mody loaded--;
4303b307c55SRasesh Mody loaded_port[p_hwfn->port_id]--;
4313b307c55SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "Unload cnt: 0x%x\n", loaded);
4323b307c55SRasesh Mody }
4333b307c55SRasesh Mody
4343b307c55SRasesh Mody static enum _ecore_status_t
ecore_emul_mcp_cmd(struct ecore_hwfn * p_hwfn,struct ecore_mcp_mb_params * p_mb_params)4353b307c55SRasesh Mody ecore_emul_mcp_cmd(struct ecore_hwfn *p_hwfn,
4363b307c55SRasesh Mody struct ecore_mcp_mb_params *p_mb_params)
4373b307c55SRasesh Mody {
4383b307c55SRasesh Mody if (!CHIP_REV_IS_EMUL(p_hwfn->p_dev))
4393b307c55SRasesh Mody return ECORE_INVAL;
4403b307c55SRasesh Mody
4413b307c55SRasesh Mody switch (p_mb_params->cmd) {
4423b307c55SRasesh Mody case DRV_MSG_CODE_LOAD_REQ:
4433b307c55SRasesh Mody ecore_emul_mcp_load_req(p_hwfn, p_mb_params);
4443b307c55SRasesh Mody break;
4453b307c55SRasesh Mody case DRV_MSG_CODE_UNLOAD_REQ:
4463b307c55SRasesh Mody ecore_emul_mcp_unload_req(p_hwfn);
4473b307c55SRasesh Mody break;
4483b307c55SRasesh Mody case DRV_MSG_CODE_GET_MFW_FEATURE_SUPPORT:
4493b307c55SRasesh Mody case DRV_MSG_CODE_RESOURCE_CMD:
4503b307c55SRasesh Mody case DRV_MSG_CODE_MDUMP_CMD:
4513b307c55SRasesh Mody case DRV_MSG_CODE_GET_ENGINE_CONFIG:
4523b307c55SRasesh Mody case DRV_MSG_CODE_GET_PPFID_BITMAP:
4533b307c55SRasesh Mody return ECORE_NOTIMPL;
4543b307c55SRasesh Mody default:
4553b307c55SRasesh Mody break;
4563b307c55SRasesh Mody }
4573b307c55SRasesh Mody
4583b307c55SRasesh Mody return ECORE_SUCCESS;
4593b307c55SRasesh Mody }
4603b307c55SRasesh Mody #endif
4613b307c55SRasesh Mody
46222c99696SRasesh Mody /* Must be called while cmd_lock is acquired */
ecore_mcp_has_pending_cmd(struct ecore_hwfn * p_hwfn)46322c99696SRasesh Mody static bool ecore_mcp_has_pending_cmd(struct ecore_hwfn *p_hwfn)
464ec94dbc5SRasesh Mody {
46522c99696SRasesh Mody struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL;
46622c99696SRasesh Mody
46722c99696SRasesh Mody /* There is at most one pending command at a certain time, and if it
46822c99696SRasesh Mody * exists - it is placed at the HEAD of the list.
46922c99696SRasesh Mody */
47022c99696SRasesh Mody if (!OSAL_LIST_IS_EMPTY(&p_hwfn->mcp_info->cmd_list)) {
47122c99696SRasesh Mody p_cmd_elem = OSAL_LIST_FIRST_ENTRY(&p_hwfn->mcp_info->cmd_list,
47222c99696SRasesh Mody struct ecore_mcp_cmd_elem,
47322c99696SRasesh Mody list);
47422c99696SRasesh Mody return !p_cmd_elem->b_is_completed;
47522c99696SRasesh Mody }
47622c99696SRasesh Mody
47722c99696SRasesh Mody return false;
47822c99696SRasesh Mody }
47922c99696SRasesh Mody
48022c99696SRasesh Mody /* Must be called while cmd_lock is acquired */
48122c99696SRasesh Mody static enum _ecore_status_t
ecore_mcp_update_pending_cmd(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)48222c99696SRasesh Mody ecore_mcp_update_pending_cmd(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
48322c99696SRasesh Mody {
48422c99696SRasesh Mody struct ecore_mcp_mb_params *p_mb_params;
48522c99696SRasesh Mody struct ecore_mcp_cmd_elem *p_cmd_elem;
48622c99696SRasesh Mody u32 mcp_resp;
48722c99696SRasesh Mody u16 seq_num;
48822c99696SRasesh Mody
48922c99696SRasesh Mody mcp_resp = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_header);
49022c99696SRasesh Mody seq_num = (u16)(mcp_resp & FW_MSG_SEQ_NUMBER_MASK);
49122c99696SRasesh Mody
49222c99696SRasesh Mody /* Return if no new non-handled response has been received */
49322c99696SRasesh Mody if (seq_num != p_hwfn->mcp_info->drv_mb_seq)
49422c99696SRasesh Mody return ECORE_AGAIN;
49522c99696SRasesh Mody
49622c99696SRasesh Mody p_cmd_elem = ecore_mcp_cmd_get_elem(p_hwfn, seq_num);
49722c99696SRasesh Mody if (!p_cmd_elem) {
49822c99696SRasesh Mody DP_ERR(p_hwfn,
49922c99696SRasesh Mody "Failed to find a pending mailbox cmd that expects sequence number %d\n",
50022c99696SRasesh Mody seq_num);
50122c99696SRasesh Mody return ECORE_UNKNOWN_ERROR;
50222c99696SRasesh Mody }
50322c99696SRasesh Mody
50422c99696SRasesh Mody p_mb_params = p_cmd_elem->p_mb_params;
50522c99696SRasesh Mody
50622c99696SRasesh Mody /* Get the MFW response along with the sequence number */
50722c99696SRasesh Mody p_mb_params->mcp_resp = mcp_resp;
50822c99696SRasesh Mody
50922c99696SRasesh Mody /* Get the MFW param */
51022c99696SRasesh Mody p_mb_params->mcp_param = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_param);
51122c99696SRasesh Mody
51222c99696SRasesh Mody /* Get the union data */
51322c99696SRasesh Mody if (p_mb_params->p_data_dst != OSAL_NULL &&
51422c99696SRasesh Mody p_mb_params->data_dst_size) {
51522c99696SRasesh Mody u32 union_data_addr = p_hwfn->mcp_info->drv_mb_addr +
51622c99696SRasesh Mody OFFSETOF(struct public_drv_mb,
51722c99696SRasesh Mody union_data);
51822c99696SRasesh Mody ecore_memcpy_from(p_hwfn, p_ptt, p_mb_params->p_data_dst,
51922c99696SRasesh Mody union_data_addr, p_mb_params->data_dst_size);
52022c99696SRasesh Mody }
52122c99696SRasesh Mody
52222c99696SRasesh Mody p_cmd_elem->b_is_completed = true;
52322c99696SRasesh Mody
52422c99696SRasesh Mody return ECORE_SUCCESS;
52522c99696SRasesh Mody }
52622c99696SRasesh Mody
52722c99696SRasesh Mody /* Must be called while cmd_lock is acquired */
__ecore_mcp_cmd_and_union(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_mb_params * p_mb_params,u16 seq_num)52822c99696SRasesh Mody static void __ecore_mcp_cmd_and_union(struct ecore_hwfn *p_hwfn,
52922c99696SRasesh Mody struct ecore_ptt *p_ptt,
53022c99696SRasesh Mody struct ecore_mcp_mb_params *p_mb_params,
53122c99696SRasesh Mody u16 seq_num)
53222c99696SRasesh Mody {
53322c99696SRasesh Mody union drv_union_data union_data;
53422c99696SRasesh Mody u32 union_data_addr;
53522c99696SRasesh Mody
53622c99696SRasesh Mody /* Set the union data */
53722c99696SRasesh Mody union_data_addr = p_hwfn->mcp_info->drv_mb_addr +
53822c99696SRasesh Mody OFFSETOF(struct public_drv_mb, union_data);
53922c99696SRasesh Mody OSAL_MEM_ZERO(&union_data, sizeof(union_data));
54022c99696SRasesh Mody if (p_mb_params->p_data_src != OSAL_NULL && p_mb_params->data_src_size)
54122c99696SRasesh Mody OSAL_MEMCPY(&union_data, p_mb_params->p_data_src,
54222c99696SRasesh Mody p_mb_params->data_src_size);
54322c99696SRasesh Mody ecore_memcpy_to(p_hwfn, p_ptt, union_data_addr, &union_data,
54422c99696SRasesh Mody sizeof(union_data));
54522c99696SRasesh Mody
54622c99696SRasesh Mody /* Set the drv param */
54722c99696SRasesh Mody DRV_MB_WR(p_hwfn, p_ptt, drv_mb_param, p_mb_params->param);
54822c99696SRasesh Mody
54922c99696SRasesh Mody /* Set the drv command along with the sequence number */
55022c99696SRasesh Mody DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (p_mb_params->cmd | seq_num));
55122c99696SRasesh Mody
5526fa40355SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
55322c99696SRasesh Mody "MFW mailbox: command 0x%08x param 0x%08x\n",
55422c99696SRasesh Mody (p_mb_params->cmd | seq_num), p_mb_params->param);
55522c99696SRasesh Mody }
55622c99696SRasesh Mody
ecore_mcp_cmd_set_blocking(struct ecore_hwfn * p_hwfn,bool block_cmd)557a474d1c1SRasesh Mody static void ecore_mcp_cmd_set_blocking(struct ecore_hwfn *p_hwfn,
558a474d1c1SRasesh Mody bool block_cmd)
559a474d1c1SRasesh Mody {
560a474d1c1SRasesh Mody p_hwfn->mcp_info->b_block_cmd = block_cmd;
561a474d1c1SRasesh Mody
562a474d1c1SRasesh Mody DP_INFO(p_hwfn, "%s sending of mailbox commands to the MFW\n",
563a474d1c1SRasesh Mody block_cmd ? "Block" : "Unblock");
564a474d1c1SRasesh Mody }
565a474d1c1SRasesh Mody
ecore_mcp_print_cpu_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)56649f4b9dcSRasesh Mody void ecore_mcp_print_cpu_info(struct ecore_hwfn *p_hwfn,
56749f4b9dcSRasesh Mody struct ecore_ptt *p_ptt)
56849f4b9dcSRasesh Mody {
56949f4b9dcSRasesh Mody u32 cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2;
5703b307c55SRasesh Mody u32 delay = ECORE_MCP_RESP_ITER_US;
57149f4b9dcSRasesh Mody
5723b307c55SRasesh Mody #ifndef ASIC_ONLY
5733b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
5743b307c55SRasesh Mody delay = ECORE_EMUL_MCP_RESP_ITER_US;
5753b307c55SRasesh Mody #endif
57649f4b9dcSRasesh Mody cpu_mode = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
57749f4b9dcSRasesh Mody cpu_state = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
57849f4b9dcSRasesh Mody cpu_pc_0 = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
5793b307c55SRasesh Mody OSAL_UDELAY(delay);
58049f4b9dcSRasesh Mody cpu_pc_1 = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
5813b307c55SRasesh Mody OSAL_UDELAY(delay);
58249f4b9dcSRasesh Mody cpu_pc_2 = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
58349f4b9dcSRasesh Mody
58449f4b9dcSRasesh Mody DP_NOTICE(p_hwfn, false,
58549f4b9dcSRasesh Mody "MCP CPU info: mode 0x%08x, state 0x%08x, pc {0x%08x, 0x%08x, 0x%08x}\n",
58649f4b9dcSRasesh Mody cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2);
58749f4b9dcSRasesh Mody }
58849f4b9dcSRasesh Mody
58922c99696SRasesh Mody static enum _ecore_status_t
_ecore_mcp_cmd_and_union(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_mb_params * p_mb_params,u32 max_retries,u32 delay)59022c99696SRasesh Mody _ecore_mcp_cmd_and_union(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
59122c99696SRasesh Mody struct ecore_mcp_mb_params *p_mb_params,
59222c99696SRasesh Mody u32 max_retries, u32 delay)
59322c99696SRasesh Mody {
59422c99696SRasesh Mody struct ecore_mcp_cmd_elem *p_cmd_elem;
59522c99696SRasesh Mody u32 cnt = 0;
59622c99696SRasesh Mody u16 seq_num;
597ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
598ec94dbc5SRasesh Mody
59922c99696SRasesh Mody /* Wait until the mailbox is non-occupied */
60022c99696SRasesh Mody do {
60122c99696SRasesh Mody /* Exit the loop if there is no pending command, or if the
60222c99696SRasesh Mody * pending command is completed during this iteration.
60322c99696SRasesh Mody * The spinlock stays locked until the command is sent.
60422c99696SRasesh Mody */
60522c99696SRasesh Mody
60622c99696SRasesh Mody OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
60722c99696SRasesh Mody
60822c99696SRasesh Mody if (!ecore_mcp_has_pending_cmd(p_hwfn))
60922c99696SRasesh Mody break;
61022c99696SRasesh Mody
61122c99696SRasesh Mody rc = ecore_mcp_update_pending_cmd(p_hwfn, p_ptt);
61222c99696SRasesh Mody if (rc == ECORE_SUCCESS)
61322c99696SRasesh Mody break;
61422c99696SRasesh Mody else if (rc != ECORE_AGAIN)
61522c99696SRasesh Mody goto err;
61622c99696SRasesh Mody
61722c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
61822c99696SRasesh Mody OSAL_UDELAY(delay);
61970f1a93dSRasesh Mody OSAL_MFW_CMD_PREEMPT(p_hwfn);
62022c99696SRasesh Mody } while (++cnt < max_retries);
62122c99696SRasesh Mody
62222c99696SRasesh Mody if (cnt >= max_retries) {
62322c99696SRasesh Mody DP_NOTICE(p_hwfn, false,
62422c99696SRasesh Mody "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n",
62522c99696SRasesh Mody p_mb_params->cmd, p_mb_params->param);
62622c99696SRasesh Mody return ECORE_AGAIN;
62722c99696SRasesh Mody }
62822c99696SRasesh Mody
62922c99696SRasesh Mody /* Send the mailbox command */
63022c99696SRasesh Mody ecore_mcp_reread_offsets(p_hwfn, p_ptt);
63122c99696SRasesh Mody seq_num = ++p_hwfn->mcp_info->drv_mb_seq;
63222c99696SRasesh Mody p_cmd_elem = ecore_mcp_cmd_add_elem(p_hwfn, p_mb_params, seq_num);
63322c99696SRasesh Mody if (!p_cmd_elem) {
63422c99696SRasesh Mody rc = ECORE_NOMEM;
63522c99696SRasesh Mody goto err;
63622c99696SRasesh Mody }
63722c99696SRasesh Mody
63822c99696SRasesh Mody __ecore_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, seq_num);
63922c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
64022c99696SRasesh Mody
64122c99696SRasesh Mody /* Wait for the MFW response */
64222c99696SRasesh Mody do {
64322c99696SRasesh Mody /* Exit the loop if the command is already completed, or if the
64422c99696SRasesh Mody * command is completed during this iteration.
64522c99696SRasesh Mody * The spinlock stays locked until the list element is removed.
64622c99696SRasesh Mody */
64722c99696SRasesh Mody
64822c99696SRasesh Mody OSAL_UDELAY(delay);
64922c99696SRasesh Mody OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
65022c99696SRasesh Mody
65122c99696SRasesh Mody if (p_cmd_elem->b_is_completed)
65222c99696SRasesh Mody break;
65322c99696SRasesh Mody
65422c99696SRasesh Mody rc = ecore_mcp_update_pending_cmd(p_hwfn, p_ptt);
65522c99696SRasesh Mody if (rc == ECORE_SUCCESS)
65622c99696SRasesh Mody break;
65722c99696SRasesh Mody else if (rc != ECORE_AGAIN)
65822c99696SRasesh Mody goto err;
65922c99696SRasesh Mody
66022c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
66170f1a93dSRasesh Mody OSAL_MFW_CMD_PREEMPT(p_hwfn);
66222c99696SRasesh Mody } while (++cnt < max_retries);
66322c99696SRasesh Mody
66422c99696SRasesh Mody if (cnt >= max_retries) {
66522c99696SRasesh Mody DP_NOTICE(p_hwfn, false,
66622c99696SRasesh Mody "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
66722c99696SRasesh Mody p_mb_params->cmd, p_mb_params->param);
66849f4b9dcSRasesh Mody ecore_mcp_print_cpu_info(p_hwfn, p_ptt);
66922c99696SRasesh Mody
67022c99696SRasesh Mody OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
67122c99696SRasesh Mody ecore_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
67222c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
67322c99696SRasesh Mody
674a474d1c1SRasesh Mody ecore_mcp_cmd_set_blocking(p_hwfn, true);
67522c99696SRasesh Mody ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_MFW_RESP_FAIL);
67622c99696SRasesh Mody return ECORE_AGAIN;
67722c99696SRasesh Mody }
67822c99696SRasesh Mody
67922c99696SRasesh Mody ecore_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
68022c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
68122c99696SRasesh Mody
6826fa40355SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
68322c99696SRasesh Mody "MFW mailbox: response 0x%08x param 0x%08x [after %d.%03d ms]\n",
68422c99696SRasesh Mody p_mb_params->mcp_resp, p_mb_params->mcp_param,
68522c99696SRasesh Mody (cnt * delay) / 1000, (cnt * delay) % 1000);
68622c99696SRasesh Mody
68722c99696SRasesh Mody /* Clear the sequence number from the MFW response */
68822c99696SRasesh Mody p_mb_params->mcp_resp &= FW_MSG_CODE_MASK;
68922c99696SRasesh Mody
69022c99696SRasesh Mody return ECORE_SUCCESS;
69122c99696SRasesh Mody
69222c99696SRasesh Mody err:
69322c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
69422c99696SRasesh Mody return rc;
69522c99696SRasesh Mody }
69622c99696SRasesh Mody
69722c99696SRasesh Mody static enum _ecore_status_t
ecore_mcp_cmd_and_union(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_mb_params * p_mb_params)69822c99696SRasesh Mody ecore_mcp_cmd_and_union(struct ecore_hwfn *p_hwfn,
69922c99696SRasesh Mody struct ecore_ptt *p_ptt,
70022c99696SRasesh Mody struct ecore_mcp_mb_params *p_mb_params)
70122c99696SRasesh Mody {
70222c99696SRasesh Mody osal_size_t union_data_size = sizeof(union drv_union_data);
70322c99696SRasesh Mody u32 max_retries = ECORE_DRV_MB_MAX_RETRIES;
7043b307c55SRasesh Mody u32 usecs = ECORE_MCP_RESP_ITER_US;
70522c99696SRasesh Mody
706ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
7073b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn))
7083b307c55SRasesh Mody return ecore_emul_mcp_cmd(p_hwfn, p_mb_params);
7093b307c55SRasesh Mody
7103b307c55SRasesh Mody if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
7113b307c55SRasesh Mody max_retries = ECORE_EMUL_DRV_MB_MAX_RETRIES;
7123b307c55SRasesh Mody usecs = ECORE_EMUL_MCP_RESP_ITER_US;
7133b307c55SRasesh Mody }
714ec94dbc5SRasesh Mody #endif
7153b307c55SRasesh Mody if (ECORE_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP)) {
7163b307c55SRasesh Mody max_retries = DIV_ROUND_UP(max_retries, 1000);
7173b307c55SRasesh Mody usecs *= 1000;
7183b307c55SRasesh Mody }
719ec94dbc5SRasesh Mody
720ec94dbc5SRasesh Mody /* MCP not initialized */
721ec94dbc5SRasesh Mody if (!ecore_mcp_is_init(p_hwfn)) {
722ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, true, "MFW is not initialized!\n");
723ec94dbc5SRasesh Mody return ECORE_BUSY;
724ec94dbc5SRasesh Mody }
725ec94dbc5SRasesh Mody
72622c99696SRasesh Mody if (p_mb_params->data_src_size > union_data_size ||
72722c99696SRasesh Mody p_mb_params->data_dst_size > union_data_size) {
728e32dc0f7SRasesh Mody DP_ERR(p_hwfn,
729e32dc0f7SRasesh Mody "The provided size is larger than the union data size [src_size %u, dst_size %u, union_data_size %zu]\n",
730e32dc0f7SRasesh Mody p_mb_params->data_src_size, p_mb_params->data_dst_size,
73122c99696SRasesh Mody union_data_size);
732e32dc0f7SRasesh Mody return ECORE_INVAL;
733e32dc0f7SRasesh Mody }
734e32dc0f7SRasesh Mody
735a474d1c1SRasesh Mody if (p_hwfn->mcp_info->b_block_cmd) {
736a474d1c1SRasesh Mody DP_NOTICE(p_hwfn, false,
737a474d1c1SRasesh Mody "The MFW is not responsive. Avoid sending mailbox command 0x%08x [param 0x%08x].\n",
738a474d1c1SRasesh Mody p_mb_params->cmd, p_mb_params->param);
739a474d1c1SRasesh Mody return ECORE_ABORTED;
740a474d1c1SRasesh Mody }
741a474d1c1SRasesh Mody
74222c99696SRasesh Mody return _ecore_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, max_retries,
7433b307c55SRasesh Mody usecs);
744ec94dbc5SRasesh Mody }
745ec94dbc5SRasesh Mody
ecore_mcp_cmd(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 cmd,u32 param,u32 * o_mcp_resp,u32 * o_mcp_param)746ffdd0599SHarish Patil enum _ecore_status_t ecore_mcp_cmd(struct ecore_hwfn *p_hwfn,
747ffdd0599SHarish Patil struct ecore_ptt *p_ptt, u32 cmd, u32 param,
748ffdd0599SHarish Patil u32 *o_mcp_resp, u32 *o_mcp_param)
749ffdd0599SHarish Patil {
750ffdd0599SHarish Patil struct ecore_mcp_mb_params mb_params;
751ffdd0599SHarish Patil enum _ecore_status_t rc;
752ec94dbc5SRasesh Mody
753ffdd0599SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
754ffdd0599SHarish Patil mb_params.cmd = cmd;
755ffdd0599SHarish Patil mb_params.param = param;
756ffdd0599SHarish Patil rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
757ffdd0599SHarish Patil if (rc != ECORE_SUCCESS)
758ec94dbc5SRasesh Mody return rc;
759ffdd0599SHarish Patil
760ffdd0599SHarish Patil *o_mcp_resp = mb_params.mcp_resp;
761ffdd0599SHarish Patil *o_mcp_param = mb_params.mcp_param;
762ffdd0599SHarish Patil
763ffdd0599SHarish Patil return ECORE_SUCCESS;
764ec94dbc5SRasesh Mody }
765ec94dbc5SRasesh Mody
ecore_mcp_nvm_wr_cmd(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 cmd,u32 param,u32 * o_mcp_resp,u32 * o_mcp_param,u32 i_txn_size,u32 * i_buf)766ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
767ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
768ec94dbc5SRasesh Mody u32 cmd,
769ec94dbc5SRasesh Mody u32 param,
770ec94dbc5SRasesh Mody u32 *o_mcp_resp,
771ec94dbc5SRasesh Mody u32 *o_mcp_param,
772ec94dbc5SRasesh Mody u32 i_txn_size, u32 *i_buf)
773ec94dbc5SRasesh Mody {
774ffdd0599SHarish Patil struct ecore_mcp_mb_params mb_params;
775ffdd0599SHarish Patil enum _ecore_status_t rc;
776ec94dbc5SRasesh Mody
777ffdd0599SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
778ffdd0599SHarish Patil mb_params.cmd = cmd;
779ffdd0599SHarish Patil mb_params.param = param;
780e32dc0f7SRasesh Mody mb_params.p_data_src = i_buf;
781e32dc0f7SRasesh Mody mb_params.data_src_size = (u8)i_txn_size;
782ffdd0599SHarish Patil rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
783ffdd0599SHarish Patil if (rc != ECORE_SUCCESS)
784ffdd0599SHarish Patil return rc;
785ec94dbc5SRasesh Mody
786ffdd0599SHarish Patil *o_mcp_resp = mb_params.mcp_resp;
787ffdd0599SHarish Patil *o_mcp_param = mb_params.mcp_param;
788ffdd0599SHarish Patil
789ffdd0599SHarish Patil return ECORE_SUCCESS;
790ec94dbc5SRasesh Mody }
791ec94dbc5SRasesh Mody
ecore_mcp_nvm_rd_cmd(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 cmd,u32 param,u32 * o_mcp_resp,u32 * o_mcp_param,u32 * o_txn_size,u32 * o_buf)792ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
793ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
794ec94dbc5SRasesh Mody u32 cmd,
795ec94dbc5SRasesh Mody u32 param,
796ec94dbc5SRasesh Mody u32 *o_mcp_resp,
797ec94dbc5SRasesh Mody u32 *o_mcp_param,
798ec94dbc5SRasesh Mody u32 *o_txn_size, u32 *o_buf)
799ec94dbc5SRasesh Mody {
80022d07d93SRasesh Mody struct ecore_mcp_mb_params mb_params;
801e32dc0f7SRasesh Mody u8 raw_data[MCP_DRV_NVM_BUF_LEN];
802ec94dbc5SRasesh Mody enum _ecore_status_t rc;
803ec94dbc5SRasesh Mody
80422d07d93SRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
80522d07d93SRasesh Mody mb_params.cmd = cmd;
80622d07d93SRasesh Mody mb_params.param = param;
807e32dc0f7SRasesh Mody mb_params.p_data_dst = raw_data;
808e32dc0f7SRasesh Mody
809e32dc0f7SRasesh Mody /* Use the maximal value since the actual one is part of the response */
810e32dc0f7SRasesh Mody mb_params.data_dst_size = MCP_DRV_NVM_BUF_LEN;
811e32dc0f7SRasesh Mody
81222d07d93SRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
813ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS)
814ec94dbc5SRasesh Mody return rc;
81522d07d93SRasesh Mody
81622d07d93SRasesh Mody *o_mcp_resp = mb_params.mcp_resp;
81722d07d93SRasesh Mody *o_mcp_param = mb_params.mcp_param;
81822d07d93SRasesh Mody
81922d07d93SRasesh Mody *o_txn_size = *o_mcp_param;
820e32dc0f7SRasesh Mody /* @DPDK */
821e32dc0f7SRasesh Mody OSAL_MEMCPY(o_buf, raw_data, RTE_MIN(*o_txn_size, MCP_DRV_NVM_BUF_LEN));
82222d07d93SRasesh Mody
82322d07d93SRasesh Mody return ECORE_SUCCESS;
824ec94dbc5SRasesh Mody }
825ec94dbc5SRasesh Mody
826c5e11089SRasesh Mody static bool
ecore_mcp_can_force_load(u8 drv_role,u8 exist_drv_role,enum ecore_override_force_load override_force_load)827c5e11089SRasesh Mody ecore_mcp_can_force_load(u8 drv_role, u8 exist_drv_role,
828c5e11089SRasesh Mody enum ecore_override_force_load override_force_load)
8290b6bf70dSRasesh Mody {
830c5e11089SRasesh Mody bool can_force_load = false;
831c5e11089SRasesh Mody
832c5e11089SRasesh Mody switch (override_force_load) {
833c5e11089SRasesh Mody case ECORE_OVERRIDE_FORCE_LOAD_ALWAYS:
834c5e11089SRasesh Mody can_force_load = true;
835c5e11089SRasesh Mody break;
836c5e11089SRasesh Mody case ECORE_OVERRIDE_FORCE_LOAD_NEVER:
837c5e11089SRasesh Mody can_force_load = false;
838c5e11089SRasesh Mody break;
839c5e11089SRasesh Mody default:
840c5e11089SRasesh Mody can_force_load = (drv_role == DRV_ROLE_OS &&
8410b6bf70dSRasesh Mody exist_drv_role == DRV_ROLE_PREBOOT) ||
842c5e11089SRasesh Mody (drv_role == DRV_ROLE_KDUMP &&
843c5e11089SRasesh Mody exist_drv_role == DRV_ROLE_OS);
844c5e11089SRasesh Mody break;
845c5e11089SRasesh Mody }
846c5e11089SRasesh Mody
847c5e11089SRasesh Mody return can_force_load;
8480b6bf70dSRasesh Mody }
8490b6bf70dSRasesh Mody
ecore_mcp_cancel_load_req(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)8500b6bf70dSRasesh Mody static enum _ecore_status_t ecore_mcp_cancel_load_req(struct ecore_hwfn *p_hwfn,
8510b6bf70dSRasesh Mody struct ecore_ptt *p_ptt)
8520b6bf70dSRasesh Mody {
8530b6bf70dSRasesh Mody u32 resp = 0, param = 0;
8540b6bf70dSRasesh Mody enum _ecore_status_t rc;
8550b6bf70dSRasesh Mody
8560b6bf70dSRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CANCEL_LOAD_REQ, 0,
8570b6bf70dSRasesh Mody &resp, ¶m);
8580b6bf70dSRasesh Mody if (rc != ECORE_SUCCESS)
8590b6bf70dSRasesh Mody DP_NOTICE(p_hwfn, false,
8600b6bf70dSRasesh Mody "Failed to send cancel load request, rc = %d\n", rc);
8610b6bf70dSRasesh Mody
8620b6bf70dSRasesh Mody return rc;
8630b6bf70dSRasesh Mody }
8640b6bf70dSRasesh Mody
8650b6bf70dSRasesh Mody #define CONFIG_ECORE_L2_BITMAP_IDX (0x1 << 0)
8660b6bf70dSRasesh Mody #define CONFIG_ECORE_SRIOV_BITMAP_IDX (0x1 << 1)
8670b6bf70dSRasesh Mody #define CONFIG_ECORE_ROCE_BITMAP_IDX (0x1 << 2)
8680b6bf70dSRasesh Mody #define CONFIG_ECORE_IWARP_BITMAP_IDX (0x1 << 3)
8690b6bf70dSRasesh Mody #define CONFIG_ECORE_FCOE_BITMAP_IDX (0x1 << 4)
8700b6bf70dSRasesh Mody #define CONFIG_ECORE_ISCSI_BITMAP_IDX (0x1 << 5)
8710b6bf70dSRasesh Mody #define CONFIG_ECORE_LL2_BITMAP_IDX (0x1 << 6)
8720b6bf70dSRasesh Mody
ecore_get_config_bitmap(void)8730b6bf70dSRasesh Mody static u32 ecore_get_config_bitmap(void)
8740b6bf70dSRasesh Mody {
8750b6bf70dSRasesh Mody u32 config_bitmap = 0x0;
8760b6bf70dSRasesh Mody
8770b6bf70dSRasesh Mody #ifdef CONFIG_ECORE_L2
8780b6bf70dSRasesh Mody config_bitmap |= CONFIG_ECORE_L2_BITMAP_IDX;
8790b6bf70dSRasesh Mody #endif
8800b6bf70dSRasesh Mody #ifdef CONFIG_ECORE_SRIOV
8810b6bf70dSRasesh Mody config_bitmap |= CONFIG_ECORE_SRIOV_BITMAP_IDX;
8820b6bf70dSRasesh Mody #endif
8830b6bf70dSRasesh Mody #ifdef CONFIG_ECORE_ROCE
8840b6bf70dSRasesh Mody config_bitmap |= CONFIG_ECORE_ROCE_BITMAP_IDX;
8850b6bf70dSRasesh Mody #endif
8860b6bf70dSRasesh Mody #ifdef CONFIG_ECORE_IWARP
8870b6bf70dSRasesh Mody config_bitmap |= CONFIG_ECORE_IWARP_BITMAP_IDX;
8880b6bf70dSRasesh Mody #endif
8890b6bf70dSRasesh Mody #ifdef CONFIG_ECORE_FCOE
8900b6bf70dSRasesh Mody config_bitmap |= CONFIG_ECORE_FCOE_BITMAP_IDX;
8910b6bf70dSRasesh Mody #endif
8920b6bf70dSRasesh Mody #ifdef CONFIG_ECORE_ISCSI
8930b6bf70dSRasesh Mody config_bitmap |= CONFIG_ECORE_ISCSI_BITMAP_IDX;
8940b6bf70dSRasesh Mody #endif
8950b6bf70dSRasesh Mody #ifdef CONFIG_ECORE_LL2
8960b6bf70dSRasesh Mody config_bitmap |= CONFIG_ECORE_LL2_BITMAP_IDX;
8970b6bf70dSRasesh Mody #endif
8980b6bf70dSRasesh Mody
8990b6bf70dSRasesh Mody return config_bitmap;
9000b6bf70dSRasesh Mody }
9010b6bf70dSRasesh Mody
9020b6bf70dSRasesh Mody struct ecore_load_req_in_params {
9030b6bf70dSRasesh Mody u8 hsi_ver;
9040b6bf70dSRasesh Mody #define ECORE_LOAD_REQ_HSI_VER_DEFAULT 0
9050b6bf70dSRasesh Mody #define ECORE_LOAD_REQ_HSI_VER_1 1
9060b6bf70dSRasesh Mody u32 drv_ver_0;
9070b6bf70dSRasesh Mody u32 drv_ver_1;
9080b6bf70dSRasesh Mody u32 fw_ver;
9090b6bf70dSRasesh Mody u8 drv_role;
9100b6bf70dSRasesh Mody u8 timeout_val;
9110b6bf70dSRasesh Mody u8 force_cmd;
9120b6bf70dSRasesh Mody bool avoid_eng_reset;
9130b6bf70dSRasesh Mody };
9140b6bf70dSRasesh Mody
9150b6bf70dSRasesh Mody struct ecore_load_req_out_params {
9160b6bf70dSRasesh Mody u32 load_code;
9170b6bf70dSRasesh Mody u32 exist_drv_ver_0;
9180b6bf70dSRasesh Mody u32 exist_drv_ver_1;
9190b6bf70dSRasesh Mody u32 exist_fw_ver;
9200b6bf70dSRasesh Mody u8 exist_drv_role;
9210b6bf70dSRasesh Mody u8 mfw_hsi_ver;
9220b6bf70dSRasesh Mody bool drv_exists;
9230b6bf70dSRasesh Mody };
9240b6bf70dSRasesh Mody
9250b6bf70dSRasesh Mody static enum _ecore_status_t
__ecore_mcp_load_req(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_load_req_in_params * p_in_params,struct ecore_load_req_out_params * p_out_params)9260b6bf70dSRasesh Mody __ecore_mcp_load_req(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
9270b6bf70dSRasesh Mody struct ecore_load_req_in_params *p_in_params,
9280b6bf70dSRasesh Mody struct ecore_load_req_out_params *p_out_params)
9290b6bf70dSRasesh Mody {
9300b6bf70dSRasesh Mody struct ecore_mcp_mb_params mb_params;
931e32dc0f7SRasesh Mody struct load_req_stc load_req;
932e32dc0f7SRasesh Mody struct load_rsp_stc load_rsp;
9330b6bf70dSRasesh Mody u32 hsi_ver;
9340b6bf70dSRasesh Mody enum _ecore_status_t rc;
9350b6bf70dSRasesh Mody
936e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&load_req, sizeof(load_req));
937e32dc0f7SRasesh Mody load_req.drv_ver_0 = p_in_params->drv_ver_0;
938e32dc0f7SRasesh Mody load_req.drv_ver_1 = p_in_params->drv_ver_1;
939e32dc0f7SRasesh Mody load_req.fw_ver = p_in_params->fw_ver;
94004b00049SRasesh Mody SET_MFW_FIELD(load_req.misc0, LOAD_REQ_ROLE, p_in_params->drv_role);
94104b00049SRasesh Mody SET_MFW_FIELD(load_req.misc0, LOAD_REQ_LOCK_TO,
9420b6bf70dSRasesh Mody p_in_params->timeout_val);
94304b00049SRasesh Mody SET_MFW_FIELD(load_req.misc0, LOAD_REQ_FORCE, p_in_params->force_cmd);
94404b00049SRasesh Mody SET_MFW_FIELD(load_req.misc0, LOAD_REQ_FLAGS0,
9450b6bf70dSRasesh Mody p_in_params->avoid_eng_reset);
9460b6bf70dSRasesh Mody
9470b6bf70dSRasesh Mody hsi_ver = (p_in_params->hsi_ver == ECORE_LOAD_REQ_HSI_VER_DEFAULT) ?
9480b6bf70dSRasesh Mody DRV_ID_MCP_HSI_VER_CURRENT :
94904b00049SRasesh Mody (p_in_params->hsi_ver << DRV_ID_MCP_HSI_VER_OFFSET);
9500b6bf70dSRasesh Mody
9510b6bf70dSRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
9520b6bf70dSRasesh Mody mb_params.cmd = DRV_MSG_CODE_LOAD_REQ;
9530b6bf70dSRasesh Mody mb_params.param = PDA_COMP | hsi_ver | p_hwfn->p_dev->drv_type;
954e32dc0f7SRasesh Mody mb_params.p_data_src = &load_req;
955e32dc0f7SRasesh Mody mb_params.data_src_size = sizeof(load_req);
956e32dc0f7SRasesh Mody mb_params.p_data_dst = &load_rsp;
957e32dc0f7SRasesh Mody mb_params.data_dst_size = sizeof(load_rsp);
9580b6bf70dSRasesh Mody
9590b6bf70dSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
9600b6bf70dSRasesh Mody "Load Request: param 0x%08x [init_hw %d, drv_type %d, hsi_ver %d, pda 0x%04x]\n",
9610b6bf70dSRasesh Mody mb_params.param,
96204b00049SRasesh Mody GET_MFW_FIELD(mb_params.param, DRV_ID_DRV_INIT_HW),
96304b00049SRasesh Mody GET_MFW_FIELD(mb_params.param, DRV_ID_DRV_TYPE),
96404b00049SRasesh Mody GET_MFW_FIELD(mb_params.param, DRV_ID_MCP_HSI_VER),
96504b00049SRasesh Mody GET_MFW_FIELD(mb_params.param, DRV_ID_PDA_COMP_VER));
9660b6bf70dSRasesh Mody
9670b6bf70dSRasesh Mody if (p_in_params->hsi_ver != ECORE_LOAD_REQ_HSI_VER_1)
9680b6bf70dSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
9690b6bf70dSRasesh Mody "Load Request: drv_ver 0x%08x_0x%08x, fw_ver 0x%08x, misc0 0x%08x [role %d, timeout %d, force %d, flags0 0x%x]\n",
970e32dc0f7SRasesh Mody load_req.drv_ver_0, load_req.drv_ver_1,
971e32dc0f7SRasesh Mody load_req.fw_ver, load_req.misc0,
97204b00049SRasesh Mody GET_MFW_FIELD(load_req.misc0, LOAD_REQ_ROLE),
97304b00049SRasesh Mody GET_MFW_FIELD(load_req.misc0, LOAD_REQ_LOCK_TO),
97404b00049SRasesh Mody GET_MFW_FIELD(load_req.misc0, LOAD_REQ_FORCE),
97504b00049SRasesh Mody GET_MFW_FIELD(load_req.misc0, LOAD_REQ_FLAGS0));
9760b6bf70dSRasesh Mody
9770b6bf70dSRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
9780b6bf70dSRasesh Mody if (rc != ECORE_SUCCESS) {
9790b6bf70dSRasesh Mody DP_NOTICE(p_hwfn, false,
9800b6bf70dSRasesh Mody "Failed to send load request, rc = %d\n", rc);
9810b6bf70dSRasesh Mody return rc;
9820b6bf70dSRasesh Mody }
9830b6bf70dSRasesh Mody
9840b6bf70dSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
9850b6bf70dSRasesh Mody "Load Response: resp 0x%08x\n", mb_params.mcp_resp);
9860b6bf70dSRasesh Mody p_out_params->load_code = mb_params.mcp_resp;
9870b6bf70dSRasesh Mody
9880b6bf70dSRasesh Mody if (p_in_params->hsi_ver != ECORE_LOAD_REQ_HSI_VER_1 &&
9890b6bf70dSRasesh Mody p_out_params->load_code != FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) {
9900b6bf70dSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
9910b6bf70dSRasesh Mody "Load Response: exist_drv_ver 0x%08x_0x%08x, exist_fw_ver 0x%08x, misc0 0x%08x [exist_role %d, mfw_hsi %d, flags0 0x%x]\n",
992e32dc0f7SRasesh Mody load_rsp.drv_ver_0, load_rsp.drv_ver_1,
993e32dc0f7SRasesh Mody load_rsp.fw_ver, load_rsp.misc0,
99404b00049SRasesh Mody GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_ROLE),
99504b00049SRasesh Mody GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_HSI),
99604b00049SRasesh Mody GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0));
9970b6bf70dSRasesh Mody
998e32dc0f7SRasesh Mody p_out_params->exist_drv_ver_0 = load_rsp.drv_ver_0;
999e32dc0f7SRasesh Mody p_out_params->exist_drv_ver_1 = load_rsp.drv_ver_1;
1000e32dc0f7SRasesh Mody p_out_params->exist_fw_ver = load_rsp.fw_ver;
10010b6bf70dSRasesh Mody p_out_params->exist_drv_role =
100204b00049SRasesh Mody GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_ROLE);
10030b6bf70dSRasesh Mody p_out_params->mfw_hsi_ver =
100404b00049SRasesh Mody GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_HSI);
10050b6bf70dSRasesh Mody p_out_params->drv_exists =
100604b00049SRasesh Mody GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0) &
10070b6bf70dSRasesh Mody LOAD_RSP_FLAGS0_DRV_EXISTS;
10080b6bf70dSRasesh Mody }
10090b6bf70dSRasesh Mody
10100b6bf70dSRasesh Mody return ECORE_SUCCESS;
10110b6bf70dSRasesh Mody }
10120b6bf70dSRasesh Mody
ecore_get_mfw_drv_role(enum ecore_drv_role drv_role,u8 * p_mfw_drv_role)101330ecf673SRasesh Mody static void ecore_get_mfw_drv_role(enum ecore_drv_role drv_role,
10140b6bf70dSRasesh Mody u8 *p_mfw_drv_role)
10150b6bf70dSRasesh Mody {
10160b6bf70dSRasesh Mody switch (drv_role) {
10170b6bf70dSRasesh Mody case ECORE_DRV_ROLE_OS:
10180b6bf70dSRasesh Mody *p_mfw_drv_role = DRV_ROLE_OS;
10190b6bf70dSRasesh Mody break;
10200b6bf70dSRasesh Mody case ECORE_DRV_ROLE_KDUMP:
10210b6bf70dSRasesh Mody *p_mfw_drv_role = DRV_ROLE_KDUMP;
10220b6bf70dSRasesh Mody break;
10230b6bf70dSRasesh Mody }
10240b6bf70dSRasesh Mody }
10250b6bf70dSRasesh Mody
10260b6bf70dSRasesh Mody enum ecore_load_req_force {
10270b6bf70dSRasesh Mody ECORE_LOAD_REQ_FORCE_NONE,
10280b6bf70dSRasesh Mody ECORE_LOAD_REQ_FORCE_PF,
10290b6bf70dSRasesh Mody ECORE_LOAD_REQ_FORCE_ALL,
10300b6bf70dSRasesh Mody };
10310b6bf70dSRasesh Mody
ecore_get_mfw_force_cmd(enum ecore_load_req_force force_cmd,u8 * p_mfw_force_cmd)103230ecf673SRasesh Mody static void ecore_get_mfw_force_cmd(enum ecore_load_req_force force_cmd,
10330b6bf70dSRasesh Mody u8 *p_mfw_force_cmd)
10340b6bf70dSRasesh Mody {
10350b6bf70dSRasesh Mody switch (force_cmd) {
10360b6bf70dSRasesh Mody case ECORE_LOAD_REQ_FORCE_NONE:
10370b6bf70dSRasesh Mody *p_mfw_force_cmd = LOAD_REQ_FORCE_NONE;
10380b6bf70dSRasesh Mody break;
10390b6bf70dSRasesh Mody case ECORE_LOAD_REQ_FORCE_PF:
10400b6bf70dSRasesh Mody *p_mfw_force_cmd = LOAD_REQ_FORCE_PF;
10410b6bf70dSRasesh Mody break;
10420b6bf70dSRasesh Mody case ECORE_LOAD_REQ_FORCE_ALL:
10430b6bf70dSRasesh Mody *p_mfw_force_cmd = LOAD_REQ_FORCE_ALL;
10440b6bf70dSRasesh Mody break;
10450b6bf70dSRasesh Mody }
10460b6bf70dSRasesh Mody }
10470b6bf70dSRasesh Mody
ecore_mcp_load_req(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_load_req_params * p_params)1048ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
1049ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
10500b6bf70dSRasesh Mody struct ecore_load_req_params *p_params)
1051ec94dbc5SRasesh Mody {
10520b6bf70dSRasesh Mody struct ecore_load_req_out_params out_params;
10530b6bf70dSRasesh Mody struct ecore_load_req_in_params in_params;
1054c5e11089SRasesh Mody u8 mfw_drv_role = 0, mfw_force_cmd;
1055ec94dbc5SRasesh Mody enum _ecore_status_t rc;
1056ec94dbc5SRasesh Mody
10570b6bf70dSRasesh Mody OSAL_MEM_ZERO(&in_params, sizeof(in_params));
10580b6bf70dSRasesh Mody in_params.hsi_ver = ECORE_LOAD_REQ_HSI_VER_DEFAULT;
10590b6bf70dSRasesh Mody in_params.drv_ver_0 = ECORE_VERSION;
10600b6bf70dSRasesh Mody in_params.drv_ver_1 = ecore_get_config_bitmap();
10610b6bf70dSRasesh Mody in_params.fw_ver = STORM_FW_VERSION;
106230ecf673SRasesh Mody ecore_get_mfw_drv_role(p_params->drv_role, &mfw_drv_role);
10630b6bf70dSRasesh Mody in_params.drv_role = mfw_drv_role;
10640b6bf70dSRasesh Mody in_params.timeout_val = p_params->timeout_val;
106530ecf673SRasesh Mody ecore_get_mfw_force_cmd(ECORE_LOAD_REQ_FORCE_NONE, &mfw_force_cmd);
10660b6bf70dSRasesh Mody in_params.force_cmd = mfw_force_cmd;
10670b6bf70dSRasesh Mody in_params.avoid_eng_reset = p_params->avoid_eng_reset;
10680b6bf70dSRasesh Mody
10690b6bf70dSRasesh Mody OSAL_MEM_ZERO(&out_params, sizeof(out_params));
10700b6bf70dSRasesh Mody rc = __ecore_mcp_load_req(p_hwfn, p_ptt, &in_params, &out_params);
10710b6bf70dSRasesh Mody if (rc != ECORE_SUCCESS)
10720b6bf70dSRasesh Mody return rc;
10730b6bf70dSRasesh Mody
10740b6bf70dSRasesh Mody /* First handle cases where another load request should/might be sent:
10750b6bf70dSRasesh Mody * - MFW expects the old interface [HSI version = 1]
10760b6bf70dSRasesh Mody * - MFW responds that a force load request is required
1077ec94dbc5SRasesh Mody */
10780b6bf70dSRasesh Mody if (out_params.load_code == FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) {
10790b6bf70dSRasesh Mody DP_INFO(p_hwfn,
10800b6bf70dSRasesh Mody "MFW refused a load request due to HSI > 1. Resending with HSI = 1.\n");
10810b6bf70dSRasesh Mody
10820b6bf70dSRasesh Mody in_params.hsi_ver = ECORE_LOAD_REQ_HSI_VER_1;
10830b6bf70dSRasesh Mody OSAL_MEM_ZERO(&out_params, sizeof(out_params));
10840b6bf70dSRasesh Mody rc = __ecore_mcp_load_req(p_hwfn, p_ptt, &in_params,
10850b6bf70dSRasesh Mody &out_params);
10860b6bf70dSRasesh Mody if (rc != ECORE_SUCCESS)
10870b6bf70dSRasesh Mody return rc;
10880b6bf70dSRasesh Mody } else if (out_params.load_code ==
10890b6bf70dSRasesh Mody FW_MSG_CODE_DRV_LOAD_REFUSED_REQUIRES_FORCE) {
10900b6bf70dSRasesh Mody if (ecore_mcp_can_force_load(in_params.drv_role,
1091c5e11089SRasesh Mody out_params.exist_drv_role,
1092c5e11089SRasesh Mody p_params->override_force_load)) {
10930b6bf70dSRasesh Mody DP_INFO(p_hwfn,
1094c5e11089SRasesh Mody "A force load is required [{role, fw_ver, drv_ver}: loading={%d, 0x%08x, 0x%08x_%08x}, existing={%d, 0x%08x, 0x%08x_%08x}]\n",
1095c5e11089SRasesh Mody in_params.drv_role, in_params.fw_ver,
1096c5e11089SRasesh Mody in_params.drv_ver_0, in_params.drv_ver_1,
10970b6bf70dSRasesh Mody out_params.exist_drv_role,
10980b6bf70dSRasesh Mody out_params.exist_fw_ver,
10990b6bf70dSRasesh Mody out_params.exist_drv_ver_0,
11000b6bf70dSRasesh Mody out_params.exist_drv_ver_1);
11010b6bf70dSRasesh Mody
110230ecf673SRasesh Mody ecore_get_mfw_force_cmd(ECORE_LOAD_REQ_FORCE_ALL,
11030b6bf70dSRasesh Mody &mfw_force_cmd);
11040b6bf70dSRasesh Mody
11050b6bf70dSRasesh Mody in_params.force_cmd = mfw_force_cmd;
11060b6bf70dSRasesh Mody OSAL_MEM_ZERO(&out_params, sizeof(out_params));
11070b6bf70dSRasesh Mody rc = __ecore_mcp_load_req(p_hwfn, p_ptt, &in_params,
11080b6bf70dSRasesh Mody &out_params);
11090b6bf70dSRasesh Mody if (rc != ECORE_SUCCESS)
11100b6bf70dSRasesh Mody return rc;
11110b6bf70dSRasesh Mody } else {
11120b6bf70dSRasesh Mody DP_NOTICE(p_hwfn, false,
1113c5e11089SRasesh Mody "A force load is required [{role, fw_ver, drv_ver}: loading={%d, 0x%08x, x%08x_0x%08x}, existing={%d, 0x%08x, 0x%08x_0x%08x}] - Avoid\n",
1114c5e11089SRasesh Mody in_params.drv_role, in_params.fw_ver,
1115c5e11089SRasesh Mody in_params.drv_ver_0, in_params.drv_ver_1,
11160b6bf70dSRasesh Mody out_params.exist_drv_role,
11170b6bf70dSRasesh Mody out_params.exist_fw_ver,
11180b6bf70dSRasesh Mody out_params.exist_drv_ver_0,
11190b6bf70dSRasesh Mody out_params.exist_drv_ver_1);
11200b6bf70dSRasesh Mody
11210b6bf70dSRasesh Mody ecore_mcp_cancel_load_req(p_hwfn, p_ptt);
1122ec94dbc5SRasesh Mody return ECORE_BUSY;
1123ec94dbc5SRasesh Mody }
11240b6bf70dSRasesh Mody }
11250b6bf70dSRasesh Mody
11260b6bf70dSRasesh Mody /* Now handle the other types of responses.
11270b6bf70dSRasesh Mody * The "REFUSED_HSI_1" and "REFUSED_REQUIRES_FORCE" responses are not
11280b6bf70dSRasesh Mody * expected here after the additional revised load requests were sent.
11290b6bf70dSRasesh Mody */
11300b6bf70dSRasesh Mody switch (out_params.load_code) {
11310b6bf70dSRasesh Mody case FW_MSG_CODE_DRV_LOAD_ENGINE:
11320b6bf70dSRasesh Mody case FW_MSG_CODE_DRV_LOAD_PORT:
11330b6bf70dSRasesh Mody case FW_MSG_CODE_DRV_LOAD_FUNCTION:
11340b6bf70dSRasesh Mody if (out_params.mfw_hsi_ver != ECORE_LOAD_REQ_HSI_VER_1 &&
11350b6bf70dSRasesh Mody out_params.drv_exists) {
11360b6bf70dSRasesh Mody /* The role and fw/driver version match, but the PF is
11370b6bf70dSRasesh Mody * already loaded and has not been unloaded gracefully.
11380b6bf70dSRasesh Mody * This is unexpected since a quasi-FLR request was
11390b6bf70dSRasesh Mody * previously sent as part of ecore_hw_prepare().
11400b6bf70dSRasesh Mody */
11410b6bf70dSRasesh Mody DP_NOTICE(p_hwfn, false,
11420b6bf70dSRasesh Mody "PF is already loaded - shouldn't have got here since a quasi-FLR request was previously sent!\n");
11430b6bf70dSRasesh Mody return ECORE_INVAL;
11440b6bf70dSRasesh Mody }
11450b6bf70dSRasesh Mody break;
11460b6bf70dSRasesh Mody default:
11470b6bf70dSRasesh Mody DP_NOTICE(p_hwfn, false,
1148c5e11089SRasesh Mody "Unexpected refusal to load request [resp 0x%08x]. Aborting.\n",
11490b6bf70dSRasesh Mody out_params.load_code);
1150c5e11089SRasesh Mody return ECORE_BUSY;
11510b6bf70dSRasesh Mody }
11520b6bf70dSRasesh Mody
11530b6bf70dSRasesh Mody p_params->load_code = out_params.load_code;
1154ec94dbc5SRasesh Mody
1155ec94dbc5SRasesh Mody return ECORE_SUCCESS;
1156ec94dbc5SRasesh Mody }
1157ec94dbc5SRasesh Mody
ecore_mcp_load_done(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)115860c78a5eSRasesh Mody enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
115960c78a5eSRasesh Mody struct ecore_ptt *p_ptt)
116060c78a5eSRasesh Mody {
116160c78a5eSRasesh Mody u32 resp = 0, param = 0;
116260c78a5eSRasesh Mody enum _ecore_status_t rc;
116360c78a5eSRasesh Mody
116460c78a5eSRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_LOAD_DONE, 0, &resp,
116560c78a5eSRasesh Mody ¶m);
116660c78a5eSRasesh Mody if (rc != ECORE_SUCCESS) {
116760c78a5eSRasesh Mody DP_NOTICE(p_hwfn, false,
116860c78a5eSRasesh Mody "Failed to send a LOAD_DONE command, rc = %d\n", rc);
116960c78a5eSRasesh Mody return rc;
117060c78a5eSRasesh Mody }
117160c78a5eSRasesh Mody
117260c78a5eSRasesh Mody /* Check if there is a DID mismatch between nvm-cfg/efuse */
117360c78a5eSRasesh Mody if (param & FW_MB_PARAM_LOAD_DONE_DID_EFUSE_ERROR)
117460c78a5eSRasesh Mody DP_NOTICE(p_hwfn, false,
117560c78a5eSRasesh Mody "warning: device configuration is not supported on this board type. The device may not function as expected.\n");
117660c78a5eSRasesh Mody
117760c78a5eSRasesh Mody return ECORE_SUCCESS;
117860c78a5eSRasesh Mody }
117960c78a5eSRasesh Mody
ecore_mcp_unload_req(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)118039f0eb3bSRasesh Mody enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
118139f0eb3bSRasesh Mody struct ecore_ptt *p_ptt)
118239f0eb3bSRasesh Mody {
118339f0eb3bSRasesh Mody u32 wol_param, mcp_resp, mcp_param;
118439f0eb3bSRasesh Mody
118539f0eb3bSRasesh Mody /* @DPDK */
118639f0eb3bSRasesh Mody wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP;
118739f0eb3bSRasesh Mody
118839f0eb3bSRasesh Mody return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_UNLOAD_REQ, wol_param,
118939f0eb3bSRasesh Mody &mcp_resp, &mcp_param);
119039f0eb3bSRasesh Mody }
119139f0eb3bSRasesh Mody
ecore_mcp_unload_done(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1192e32dc0f7SRasesh Mody enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
1193e32dc0f7SRasesh Mody struct ecore_ptt *p_ptt)
1194e32dc0f7SRasesh Mody {
1195e32dc0f7SRasesh Mody struct ecore_mcp_mb_params mb_params;
1196e32dc0f7SRasesh Mody struct mcp_mac wol_mac;
1197e32dc0f7SRasesh Mody
1198e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1199e32dc0f7SRasesh Mody mb_params.cmd = DRV_MSG_CODE_UNLOAD_DONE;
1200e32dc0f7SRasesh Mody
1201e32dc0f7SRasesh Mody return ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1202e32dc0f7SRasesh Mody }
1203e32dc0f7SRasesh Mody
ecore_mcp_handle_vf_flr(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1204ec94dbc5SRasesh Mody static void ecore_mcp_handle_vf_flr(struct ecore_hwfn *p_hwfn,
1205ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
1206ec94dbc5SRasesh Mody {
1207ec94dbc5SRasesh Mody u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1208ec94dbc5SRasesh Mody PUBLIC_PATH);
1209ec94dbc5SRasesh Mody u32 mfw_path_offsize = ecore_rd(p_hwfn, p_ptt, addr);
1210ec94dbc5SRasesh Mody u32 path_addr = SECTION_ADDR(mfw_path_offsize,
1211ec94dbc5SRasesh Mody ECORE_PATH_ID(p_hwfn));
12123b307c55SRasesh Mody u32 disabled_vfs[EXT_VF_BITMAP_SIZE_IN_DWORDS];
1213ec94dbc5SRasesh Mody int i;
1214ec94dbc5SRasesh Mody
12153b307c55SRasesh Mody OSAL_MEM_ZERO(disabled_vfs, EXT_VF_BITMAP_SIZE_IN_BYTES);
12163b307c55SRasesh Mody
1217ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1218ec94dbc5SRasesh Mody "Reading Disabled VF information from [offset %08x],"
1219ec94dbc5SRasesh Mody " path_addr %08x\n",
1220ec94dbc5SRasesh Mody mfw_path_offsize, path_addr);
1221ec94dbc5SRasesh Mody
12223b307c55SRasesh Mody for (i = 0; i < VF_BITMAP_SIZE_IN_DWORDS; i++) {
1223ec94dbc5SRasesh Mody disabled_vfs[i] = ecore_rd(p_hwfn, p_ptt,
1224ec94dbc5SRasesh Mody path_addr +
1225ec94dbc5SRasesh Mody OFFSETOF(struct public_path,
1226ec94dbc5SRasesh Mody mcp_vf_disabled) +
1227ec94dbc5SRasesh Mody sizeof(u32) * i);
1228ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_IOV),
1229ec94dbc5SRasesh Mody "FLR-ed VFs [%08x,...,%08x] - %08x\n",
1230ec94dbc5SRasesh Mody i * 32, (i + 1) * 32 - 1, disabled_vfs[i]);
1231ec94dbc5SRasesh Mody }
123286a2265eSRasesh Mody
123386a2265eSRasesh Mody if (ecore_iov_mark_vf_flr(p_hwfn, disabled_vfs))
123486a2265eSRasesh Mody OSAL_VF_FLR_UPDATE(p_hwfn);
1235ec94dbc5SRasesh Mody }
1236ec94dbc5SRasesh Mody
ecore_mcp_ack_vf_flr(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * vfs_to_ack)1237ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
1238ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
1239ec94dbc5SRasesh Mody u32 *vfs_to_ack)
1240ec94dbc5SRasesh Mody {
1241ffdd0599SHarish Patil struct ecore_mcp_mb_params mb_params;
1242ec94dbc5SRasesh Mody enum _ecore_status_t rc;
12433b307c55SRasesh Mody u16 i;
1244ec94dbc5SRasesh Mody
12453b307c55SRasesh Mody for (i = 0; i < VF_BITMAP_SIZE_IN_DWORDS; i++)
1246ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_IOV),
1247ec94dbc5SRasesh Mody "Acking VFs [%08x,...,%08x] - %08x\n",
1248ec94dbc5SRasesh Mody i * 32, (i + 1) * 32 - 1, vfs_to_ack[i]);
1249ec94dbc5SRasesh Mody
1250ffdd0599SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1251ffdd0599SHarish Patil mb_params.cmd = DRV_MSG_CODE_VF_DISABLED_DONE;
1252e32dc0f7SRasesh Mody mb_params.p_data_src = vfs_to_ack;
12533b307c55SRasesh Mody mb_params.data_src_size = (u8)VF_BITMAP_SIZE_IN_BYTES;
125422d07d93SRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt,
125522d07d93SRasesh Mody &mb_params);
1256ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS) {
125722d07d93SRasesh Mody DP_NOTICE(p_hwfn, false,
1258ec94dbc5SRasesh Mody "Failed to pass ACK for VF flr to MFW\n");
1259ec94dbc5SRasesh Mody return ECORE_TIMEOUT;
1260ec94dbc5SRasesh Mody }
1261ec94dbc5SRasesh Mody
1262ec94dbc5SRasesh Mody return rc;
1263ec94dbc5SRasesh Mody }
1264ec94dbc5SRasesh Mody
ecore_mcp_handle_transceiver_change(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1265ec94dbc5SRasesh Mody static void ecore_mcp_handle_transceiver_change(struct ecore_hwfn *p_hwfn,
1266ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
1267ec94dbc5SRasesh Mody {
1268ec94dbc5SRasesh Mody u32 transceiver_state;
1269ec94dbc5SRasesh Mody
1270ec94dbc5SRasesh Mody transceiver_state = ecore_rd(p_hwfn, p_ptt,
1271ec94dbc5SRasesh Mody p_hwfn->mcp_info->port_addr +
1272ec94dbc5SRasesh Mody OFFSETOF(struct public_port,
1273ec94dbc5SRasesh Mody transceiver_data));
1274ec94dbc5SRasesh Mody
1275ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, (ECORE_MSG_HW | ECORE_MSG_SP),
1276ec94dbc5SRasesh Mody "Received transceiver state update [0x%08x] from mfw"
1277ec94dbc5SRasesh Mody " [Addr 0x%x]\n",
1278ec94dbc5SRasesh Mody transceiver_state, (u32)(p_hwfn->mcp_info->port_addr +
1279ec94dbc5SRasesh Mody OFFSETOF(struct public_port,
1280ec94dbc5SRasesh Mody transceiver_data)));
1281ec94dbc5SRasesh Mody
128204b00049SRasesh Mody transceiver_state = GET_MFW_FIELD(transceiver_state,
128304b00049SRasesh Mody ETH_TRANSCEIVER_STATE);
1284ec94dbc5SRasesh Mody
128557a304efSRasesh Mody if (transceiver_state == ETH_TRANSCEIVER_STATE_PRESENT)
1286ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false, "Transceiver is present.\n");
1287ec94dbc5SRasesh Mody else
1288ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false, "Transceiver is unplugged.\n");
128970f1a93dSRasesh Mody
129070f1a93dSRasesh Mody OSAL_TRANSCEIVER_UPDATE(p_hwfn);
1291ec94dbc5SRasesh Mody }
1292ec94dbc5SRasesh Mody
ecore_mcp_read_eee_config(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_link_state * p_link)12933c6a3cf6SRasesh Mody static void ecore_mcp_read_eee_config(struct ecore_hwfn *p_hwfn,
12943c6a3cf6SRasesh Mody struct ecore_ptt *p_ptt,
12953c6a3cf6SRasesh Mody struct ecore_mcp_link_state *p_link)
12963c6a3cf6SRasesh Mody {
12973c6a3cf6SRasesh Mody u32 eee_status, val;
12983c6a3cf6SRasesh Mody
12993c6a3cf6SRasesh Mody p_link->eee_adv_caps = 0;
13003c6a3cf6SRasesh Mody p_link->eee_lp_adv_caps = 0;
13013c6a3cf6SRasesh Mody eee_status = ecore_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
13023c6a3cf6SRasesh Mody OFFSETOF(struct public_port, eee_status));
13033c6a3cf6SRasesh Mody p_link->eee_active = !!(eee_status & EEE_ACTIVE_BIT);
130404b00049SRasesh Mody val = (eee_status & EEE_LD_ADV_STATUS_MASK) >> EEE_LD_ADV_STATUS_OFFSET;
13053c6a3cf6SRasesh Mody if (val & EEE_1G_ADV)
13063c6a3cf6SRasesh Mody p_link->eee_adv_caps |= ECORE_EEE_1G_ADV;
13073c6a3cf6SRasesh Mody if (val & EEE_10G_ADV)
13083c6a3cf6SRasesh Mody p_link->eee_adv_caps |= ECORE_EEE_10G_ADV;
130904b00049SRasesh Mody val = (eee_status & EEE_LP_ADV_STATUS_MASK) >> EEE_LP_ADV_STATUS_OFFSET;
13103c6a3cf6SRasesh Mody if (val & EEE_1G_ADV)
13113c6a3cf6SRasesh Mody p_link->eee_lp_adv_caps |= ECORE_EEE_1G_ADV;
13123c6a3cf6SRasesh Mody if (val & EEE_10G_ADV)
13133c6a3cf6SRasesh Mody p_link->eee_lp_adv_caps |= ECORE_EEE_10G_ADV;
13143c6a3cf6SRasesh Mody }
13153c6a3cf6SRasesh Mody
ecore_mcp_get_shmem_func(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct public_func * p_data,int pfid)1316fe0deb21SRasesh Mody static u32 ecore_mcp_get_shmem_func(struct ecore_hwfn *p_hwfn,
1317fe0deb21SRasesh Mody struct ecore_ptt *p_ptt,
1318fe0deb21SRasesh Mody struct public_func *p_data,
1319fe0deb21SRasesh Mody int pfid)
1320fe0deb21SRasesh Mody {
1321fe0deb21SRasesh Mody u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1322fe0deb21SRasesh Mody PUBLIC_FUNC);
1323fe0deb21SRasesh Mody u32 mfw_path_offsize = ecore_rd(p_hwfn, p_ptt, addr);
1324fe0deb21SRasesh Mody u32 func_addr = SECTION_ADDR(mfw_path_offsize, pfid);
1325fe0deb21SRasesh Mody u32 i, size;
1326fe0deb21SRasesh Mody
1327fe0deb21SRasesh Mody OSAL_MEM_ZERO(p_data, sizeof(*p_data));
1328fe0deb21SRasesh Mody
1329fe0deb21SRasesh Mody size = OSAL_MIN_T(u32, sizeof(*p_data),
1330fe0deb21SRasesh Mody SECTION_SIZE(mfw_path_offsize));
1331fe0deb21SRasesh Mody for (i = 0; i < size / sizeof(u32); i++)
1332fe0deb21SRasesh Mody ((u32 *)p_data)[i] = ecore_rd(p_hwfn, p_ptt,
1333fe0deb21SRasesh Mody func_addr + (i << 2));
1334fe0deb21SRasesh Mody
1335fe0deb21SRasesh Mody return size;
1336fe0deb21SRasesh Mody }
1337fe0deb21SRasesh Mody
ecore_mcp_handle_link_change(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,bool b_reset)1338ec94dbc5SRasesh Mody static void ecore_mcp_handle_link_change(struct ecore_hwfn *p_hwfn,
133922d07d93SRasesh Mody struct ecore_ptt *p_ptt,
134022d07d93SRasesh Mody bool b_reset)
1341ec94dbc5SRasesh Mody {
1342ec94dbc5SRasesh Mody struct ecore_mcp_link_state *p_link;
134322d07d93SRasesh Mody u8 max_bw, min_bw;
1344ec94dbc5SRasesh Mody u32 status = 0;
1345ec94dbc5SRasesh Mody
134622c99696SRasesh Mody /* Prevent SW/attentions from doing this at the same time */
134722c99696SRasesh Mody OSAL_SPIN_LOCK(&p_hwfn->mcp_info->link_lock);
134822c99696SRasesh Mody
1349ec94dbc5SRasesh Mody p_link = &p_hwfn->mcp_info->link_output;
1350ec94dbc5SRasesh Mody OSAL_MEMSET(p_link, 0, sizeof(*p_link));
1351ec94dbc5SRasesh Mody if (!b_reset) {
1352ec94dbc5SRasesh Mody status = ecore_rd(p_hwfn, p_ptt,
1353ec94dbc5SRasesh Mody p_hwfn->mcp_info->port_addr +
1354ec94dbc5SRasesh Mody OFFSETOF(struct public_port, link_status));
1355ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, (ECORE_MSG_LINK | ECORE_MSG_SP),
1356ec94dbc5SRasesh Mody "Received link update [0x%08x] from mfw"
1357ec94dbc5SRasesh Mody " [Addr 0x%x]\n",
1358ec94dbc5SRasesh Mody status, (u32)(p_hwfn->mcp_info->port_addr +
1359ec94dbc5SRasesh Mody OFFSETOF(struct public_port,
1360ec94dbc5SRasesh Mody link_status)));
1361ec94dbc5SRasesh Mody } else {
1362ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1363ec94dbc5SRasesh Mody "Resetting link indications\n");
136422c99696SRasesh Mody goto out;
1365ec94dbc5SRasesh Mody }
1366ec94dbc5SRasesh Mody
1367fe0deb21SRasesh Mody if (p_hwfn->b_drv_link_init) {
1368fe0deb21SRasesh Mody /* Link indication with modern MFW arrives as per-PF
1369fe0deb21SRasesh Mody * indication.
1370fe0deb21SRasesh Mody */
1371fe0deb21SRasesh Mody if (p_hwfn->mcp_info->capabilities &
1372fe0deb21SRasesh Mody FW_MB_PARAM_FEATURE_SUPPORT_VLINK) {
1373fe0deb21SRasesh Mody struct public_func shmem_info;
1374fe0deb21SRasesh Mody
1375fe0deb21SRasesh Mody ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
1376fe0deb21SRasesh Mody MCP_PF_ID(p_hwfn));
1377fe0deb21SRasesh Mody p_link->link_up = !!(shmem_info.status &
1378fe0deb21SRasesh Mody FUNC_STATUS_VIRTUAL_LINK_UP);
1379fe0deb21SRasesh Mody } else {
1380ec94dbc5SRasesh Mody p_link->link_up = !!(status & LINK_STATUS_LINK_UP);
1381fe0deb21SRasesh Mody }
1382fe0deb21SRasesh Mody } else {
1383ec94dbc5SRasesh Mody p_link->link_up = false;
1384fe0deb21SRasesh Mody }
1385ec94dbc5SRasesh Mody
1386ec94dbc5SRasesh Mody p_link->full_duplex = true;
1387ec94dbc5SRasesh Mody switch ((status & LINK_STATUS_SPEED_AND_DUPLEX_MASK)) {
1388ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_100G:
1389ec94dbc5SRasesh Mody p_link->speed = 100000;
1390ec94dbc5SRasesh Mody break;
1391ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_50G:
1392ec94dbc5SRasesh Mody p_link->speed = 50000;
1393ec94dbc5SRasesh Mody break;
1394ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_40G:
1395ec94dbc5SRasesh Mody p_link->speed = 40000;
1396ec94dbc5SRasesh Mody break;
1397ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_25G:
1398ec94dbc5SRasesh Mody p_link->speed = 25000;
1399ec94dbc5SRasesh Mody break;
1400ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_20G:
1401ec94dbc5SRasesh Mody p_link->speed = 20000;
1402ec94dbc5SRasesh Mody break;
1403ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_10G:
1404ec94dbc5SRasesh Mody p_link->speed = 10000;
1405ec94dbc5SRasesh Mody break;
1406ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_1000THD:
1407ec94dbc5SRasesh Mody p_link->full_duplex = false;
1408ec94dbc5SRasesh Mody /* Fall-through */
1409ec94dbc5SRasesh Mody case LINK_STATUS_SPEED_AND_DUPLEX_1000TFD:
1410ec94dbc5SRasesh Mody p_link->speed = 1000;
1411ec94dbc5SRasesh Mody break;
1412ec94dbc5SRasesh Mody default:
1413ec94dbc5SRasesh Mody p_link->speed = 0;
1414ec94dbc5SRasesh Mody }
1415ec94dbc5SRasesh Mody
1416ec94dbc5SRasesh Mody /* We never store total line speed as p_link->speed is
1417ec94dbc5SRasesh Mody * again changes according to bandwidth allocation.
1418ec94dbc5SRasesh Mody */
1419ec94dbc5SRasesh Mody if (p_link->link_up && p_link->speed)
1420ec94dbc5SRasesh Mody p_link->line_speed = p_link->speed;
1421ec94dbc5SRasesh Mody else
1422ec94dbc5SRasesh Mody p_link->line_speed = 0;
1423ec94dbc5SRasesh Mody
142422d07d93SRasesh Mody max_bw = p_hwfn->mcp_info->func_info.bandwidth_max;
142522d07d93SRasesh Mody min_bw = p_hwfn->mcp_info->func_info.bandwidth_min;
1426ec94dbc5SRasesh Mody
142722d07d93SRasesh Mody /* Max bandwidth configuration */
1428ec94dbc5SRasesh Mody __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
1429ec94dbc5SRasesh Mody p_link, max_bw);
1430ec94dbc5SRasesh Mody
1431aa96bcbdSRasesh Mody /* Min bandwidth configuration */
1432ec94dbc5SRasesh Mody __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
1433ec94dbc5SRasesh Mody p_link, min_bw);
1434544927f9SRasesh Mody ecore_configure_vp_wfq_on_link_change(p_hwfn->p_dev, p_ptt,
1435ec94dbc5SRasesh Mody p_link->min_pf_rate);
1436ec94dbc5SRasesh Mody
1437ec94dbc5SRasesh Mody p_link->an = !!(status & LINK_STATUS_AUTO_NEGOTIATE_ENABLED);
1438ec94dbc5SRasesh Mody p_link->an_complete = !!(status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE);
1439ec94dbc5SRasesh Mody p_link->parallel_detection = !!(status &
1440ec94dbc5SRasesh Mody LINK_STATUS_PARALLEL_DETECTION_USED);
1441ec94dbc5SRasesh Mody p_link->pfc_enabled = !!(status & LINK_STATUS_PFC_ENABLED);
1442ec94dbc5SRasesh Mody
1443ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1444ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE) ?
1445ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_1G_FD : 0;
1446ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1447ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE) ?
1448ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_1G_HD : 0;
1449ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1450ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_10G_CAPABLE) ?
1451ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_10G : 0;
1452ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1453ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_20G_CAPABLE) ?
1454ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_20G : 0;
1455ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1456ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_25G_CAPABLE) ?
1457ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_25G : 0;
1458ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1459ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_40G_CAPABLE) ?
1460ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_40G : 0;
1461ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1462ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_50G_CAPABLE) ?
1463ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_50G : 0;
1464ec94dbc5SRasesh Mody p_link->partner_adv_speed |=
1465ec94dbc5SRasesh Mody (status & LINK_STATUS_LINK_PARTNER_100G_CAPABLE) ?
1466ec94dbc5SRasesh Mody ECORE_LINK_PARTNER_SPEED_100G : 0;
1467ec94dbc5SRasesh Mody
1468ec94dbc5SRasesh Mody p_link->partner_tx_flow_ctrl_en =
1469ec94dbc5SRasesh Mody !!(status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED);
1470ec94dbc5SRasesh Mody p_link->partner_rx_flow_ctrl_en =
1471ec94dbc5SRasesh Mody !!(status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED);
1472ec94dbc5SRasesh Mody
1473ec94dbc5SRasesh Mody switch (status & LINK_STATUS_LINK_PARTNER_FLOW_CONTROL_MASK) {
1474ec94dbc5SRasesh Mody case LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE:
1475ec94dbc5SRasesh Mody p_link->partner_adv_pause = ECORE_LINK_PARTNER_SYMMETRIC_PAUSE;
1476ec94dbc5SRasesh Mody break;
1477ec94dbc5SRasesh Mody case LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE:
1478ec94dbc5SRasesh Mody p_link->partner_adv_pause = ECORE_LINK_PARTNER_ASYMMETRIC_PAUSE;
1479ec94dbc5SRasesh Mody break;
1480ec94dbc5SRasesh Mody case LINK_STATUS_LINK_PARTNER_BOTH_PAUSE:
1481ec94dbc5SRasesh Mody p_link->partner_adv_pause = ECORE_LINK_PARTNER_BOTH_PAUSE;
1482ec94dbc5SRasesh Mody break;
1483ec94dbc5SRasesh Mody default:
1484ec94dbc5SRasesh Mody p_link->partner_adv_pause = 0;
1485ec94dbc5SRasesh Mody }
1486ec94dbc5SRasesh Mody
1487ec94dbc5SRasesh Mody p_link->sfp_tx_fault = !!(status & LINK_STATUS_SFP_TX_FAULT);
1488ec94dbc5SRasesh Mody
14893c6a3cf6SRasesh Mody if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE)
14903c6a3cf6SRasesh Mody ecore_mcp_read_eee_config(p_hwfn, p_ptt, p_link);
14913c6a3cf6SRasesh Mody
14928aab5d6fSRasesh Mody OSAL_LINK_UPDATE(p_hwfn);
149322c99696SRasesh Mody out:
149422c99696SRasesh Mody OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->link_lock);
1495ec94dbc5SRasesh Mody }
1496ec94dbc5SRasesh Mody
ecore_mcp_set_link(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,bool b_up)1497ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_set_link(struct ecore_hwfn *p_hwfn,
1498ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt, bool b_up)
1499ec94dbc5SRasesh Mody {
1500ec94dbc5SRasesh Mody struct ecore_mcp_link_params *params = &p_hwfn->mcp_info->link_input;
1501ffdd0599SHarish Patil struct ecore_mcp_mb_params mb_params;
1502e32dc0f7SRasesh Mody struct eth_phy_cfg phy_cfg;
1503ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
150422d07d93SRasesh Mody u32 cmd;
1505ec94dbc5SRasesh Mody
1506ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
15073b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
15083b307c55SRasesh Mody if (b_up)
15093b307c55SRasesh Mody OSAL_LINK_UPDATE(p_hwfn);
1510ec94dbc5SRasesh Mody return ECORE_SUCCESS;
15113b307c55SRasesh Mody }
1512ec94dbc5SRasesh Mody #endif
1513ec94dbc5SRasesh Mody
1514ec94dbc5SRasesh Mody /* Set the shmem configuration according to params */
1515e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&phy_cfg, sizeof(phy_cfg));
1516ec94dbc5SRasesh Mody cmd = b_up ? DRV_MSG_CODE_INIT_PHY : DRV_MSG_CODE_LINK_RESET;
1517ec94dbc5SRasesh Mody if (!params->speed.autoneg)
1518e32dc0f7SRasesh Mody phy_cfg.speed = params->speed.forced_speed;
1519e32dc0f7SRasesh Mody phy_cfg.pause |= (params->pause.autoneg) ? ETH_PAUSE_AUTONEG : 0;
1520e32dc0f7SRasesh Mody phy_cfg.pause |= (params->pause.forced_rx) ? ETH_PAUSE_RX : 0;
1521e32dc0f7SRasesh Mody phy_cfg.pause |= (params->pause.forced_tx) ? ETH_PAUSE_TX : 0;
1522e32dc0f7SRasesh Mody phy_cfg.adv_speed = params->speed.advertised_speeds;
1523e32dc0f7SRasesh Mody phy_cfg.loopback_mode = params->loopback_mode;
15243c6a3cf6SRasesh Mody
15253c6a3cf6SRasesh Mody /* There are MFWs that share this capability regardless of whether
15263c6a3cf6SRasesh Mody * this is feasible or not. And given that at the very least adv_caps
15273c6a3cf6SRasesh Mody * would be set internally by ecore, we want to make sure LFA would
15283c6a3cf6SRasesh Mody * still work.
15293c6a3cf6SRasesh Mody */
15303c6a3cf6SRasesh Mody if ((p_hwfn->mcp_info->capabilities &
15313c6a3cf6SRasesh Mody FW_MB_PARAM_FEATURE_SUPPORT_EEE) &&
15323c6a3cf6SRasesh Mody params->eee.enable) {
15333c6a3cf6SRasesh Mody phy_cfg.eee_cfg |= EEE_CFG_EEE_ENABLED;
15343c6a3cf6SRasesh Mody if (params->eee.tx_lpi_enable)
15353c6a3cf6SRasesh Mody phy_cfg.eee_cfg |= EEE_CFG_TX_LPI;
15363c6a3cf6SRasesh Mody if (params->eee.adv_caps & ECORE_EEE_1G_ADV)
15373c6a3cf6SRasesh Mody phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_1G;
15383c6a3cf6SRasesh Mody if (params->eee.adv_caps & ECORE_EEE_10G_ADV)
15393c6a3cf6SRasesh Mody phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_10G;
15403c6a3cf6SRasesh Mody phy_cfg.eee_cfg |= (params->eee.tx_lpi_timer <<
154104b00049SRasesh Mody EEE_TX_TIMER_USEC_OFFSET) &
15423c6a3cf6SRasesh Mody EEE_TX_TIMER_USEC_MASK;
15433c6a3cf6SRasesh Mody }
15443c6a3cf6SRasesh Mody
1545ec94dbc5SRasesh Mody p_hwfn->b_drv_link_init = b_up;
1546ec94dbc5SRasesh Mody
1547ec94dbc5SRasesh Mody if (b_up)
1548ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1549652ee28aSRasesh Mody "Configuring Link: Speed 0x%08x, Pause 0x%08x, adv_speed 0x%08x, loopback 0x%08x\n",
1550e32dc0f7SRasesh Mody phy_cfg.speed, phy_cfg.pause, phy_cfg.adv_speed,
1551e32dc0f7SRasesh Mody phy_cfg.loopback_mode);
1552ec94dbc5SRasesh Mody else
1553ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_LINK, "Resetting link\n");
1554ec94dbc5SRasesh Mody
1555ffdd0599SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1556ffdd0599SHarish Patil mb_params.cmd = cmd;
1557e32dc0f7SRasesh Mody mb_params.p_data_src = &phy_cfg;
1558e32dc0f7SRasesh Mody mb_params.data_src_size = sizeof(phy_cfg);
1559ffdd0599SHarish Patil rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1560ec94dbc5SRasesh Mody
1561ec94dbc5SRasesh Mody /* if mcp fails to respond we must abort */
1562ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS) {
1563ec94dbc5SRasesh Mody DP_ERR(p_hwfn, "MCP response failure, aborting\n");
1564ec94dbc5SRasesh Mody return rc;
1565ec94dbc5SRasesh Mody }
1566ec94dbc5SRasesh Mody
156722c99696SRasesh Mody /* Mimic link-change attention, done for several reasons:
156822c99696SRasesh Mody * - On reset, there's no guarantee MFW would trigger
156922c99696SRasesh Mody * an attention.
157022c99696SRasesh Mody * - On initialization, older MFWs might not indicate link change
157122c99696SRasesh Mody * during LFA, so we'll never get an UP indication.
157222c99696SRasesh Mody */
157322c99696SRasesh Mody ecore_mcp_handle_link_change(p_hwfn, p_ptt, !b_up);
1574ec94dbc5SRasesh Mody
1575eafbc6fcSRasesh Mody return ECORE_SUCCESS;
1576ec94dbc5SRasesh Mody }
1577ec94dbc5SRasesh Mody
ecore_get_process_kill_counter(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1578ec94dbc5SRasesh Mody u32 ecore_get_process_kill_counter(struct ecore_hwfn *p_hwfn,
1579ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
1580ec94dbc5SRasesh Mody {
1581ec94dbc5SRasesh Mody u32 path_offsize_addr, path_offsize, path_addr, proc_kill_cnt;
1582ec94dbc5SRasesh Mody
158386a2265eSRasesh Mody /* TODO - Add support for VFs */
158486a2265eSRasesh Mody if (IS_VF(p_hwfn->p_dev))
158586a2265eSRasesh Mody return ECORE_INVAL;
158686a2265eSRasesh Mody
1587ec94dbc5SRasesh Mody path_offsize_addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1588ec94dbc5SRasesh Mody PUBLIC_PATH);
1589ec94dbc5SRasesh Mody path_offsize = ecore_rd(p_hwfn, p_ptt, path_offsize_addr);
1590ec94dbc5SRasesh Mody path_addr = SECTION_ADDR(path_offsize, ECORE_PATH_ID(p_hwfn));
1591ec94dbc5SRasesh Mody
1592ec94dbc5SRasesh Mody proc_kill_cnt = ecore_rd(p_hwfn, p_ptt,
1593ec94dbc5SRasesh Mody path_addr +
1594ec94dbc5SRasesh Mody OFFSETOF(struct public_path, process_kill)) &
1595ec94dbc5SRasesh Mody PROCESS_KILL_COUNTER_MASK;
1596ec94dbc5SRasesh Mody
1597ec94dbc5SRasesh Mody return proc_kill_cnt;
1598ec94dbc5SRasesh Mody }
1599ec94dbc5SRasesh Mody
ecore_mcp_handle_process_kill(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1600ec94dbc5SRasesh Mody static void ecore_mcp_handle_process_kill(struct ecore_hwfn *p_hwfn,
1601ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
1602ec94dbc5SRasesh Mody {
1603ec94dbc5SRasesh Mody struct ecore_dev *p_dev = p_hwfn->p_dev;
1604ec94dbc5SRasesh Mody u32 proc_kill_cnt;
1605ec94dbc5SRasesh Mody
1606ec94dbc5SRasesh Mody /* Prevent possible attentions/interrupts during the recovery handling
1607ec94dbc5SRasesh Mody * and till its load phase, during which they will be re-enabled.
1608ec94dbc5SRasesh Mody */
1609ec94dbc5SRasesh Mody ecore_int_igu_disable_int(p_hwfn, p_ptt);
1610ec94dbc5SRasesh Mody
1611ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false, "Received a process kill indication\n");
1612ec94dbc5SRasesh Mody
1613ec94dbc5SRasesh Mody /* The following operations should be done once, and thus in CMT mode
1614ec94dbc5SRasesh Mody * are carried out by only the first HW function.
1615ec94dbc5SRasesh Mody */
1616ec94dbc5SRasesh Mody if (p_hwfn != ECORE_LEADING_HWFN(p_dev))
1617ec94dbc5SRasesh Mody return;
1618ec94dbc5SRasesh Mody
1619ec94dbc5SRasesh Mody if (p_dev->recov_in_prog) {
1620ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false,
1621ec94dbc5SRasesh Mody "Ignoring the indication since a recovery"
1622ec94dbc5SRasesh Mody " process is already in progress\n");
1623ec94dbc5SRasesh Mody return;
1624ec94dbc5SRasesh Mody }
1625ec94dbc5SRasesh Mody
1626ec94dbc5SRasesh Mody p_dev->recov_in_prog = true;
1627ec94dbc5SRasesh Mody
1628ec94dbc5SRasesh Mody proc_kill_cnt = ecore_get_process_kill_counter(p_hwfn, p_ptt);
1629ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false, "Process kill counter: %d\n", proc_kill_cnt);
1630ec94dbc5SRasesh Mody
1631ec94dbc5SRasesh Mody OSAL_SCHEDULE_RECOVERY_HANDLER(p_hwfn);
1632ec94dbc5SRasesh Mody }
1633ec94dbc5SRasesh Mody
ecore_mcp_send_protocol_stats(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum MFW_DRV_MSG_TYPE type)1634ec94dbc5SRasesh Mody static void ecore_mcp_send_protocol_stats(struct ecore_hwfn *p_hwfn,
1635ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
1636ec94dbc5SRasesh Mody enum MFW_DRV_MSG_TYPE type)
1637ec94dbc5SRasesh Mody {
1638ec94dbc5SRasesh Mody enum ecore_mcp_protocol_type stats_type;
1639ec94dbc5SRasesh Mody union ecore_mcp_protocol_stats stats;
1640ffdd0599SHarish Patil struct ecore_mcp_mb_params mb_params;
164122d07d93SRasesh Mody u32 hsi_param;
16422c3945f6SRasesh Mody enum _ecore_status_t rc;
1643ec94dbc5SRasesh Mody
1644ec94dbc5SRasesh Mody switch (type) {
1645ec94dbc5SRasesh Mody case MFW_DRV_MSG_GET_LAN_STATS:
1646ec94dbc5SRasesh Mody stats_type = ECORE_MCP_LAN_STATS;
1647ec94dbc5SRasesh Mody hsi_param = DRV_MSG_CODE_STATS_TYPE_LAN;
1648ec94dbc5SRasesh Mody break;
1649ec94dbc5SRasesh Mody default:
1650fe0deb21SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1651fe0deb21SRasesh Mody "Invalid protocol type %d\n", type);
1652ec94dbc5SRasesh Mody return;
1653ec94dbc5SRasesh Mody }
1654ec94dbc5SRasesh Mody
1655ec94dbc5SRasesh Mody OSAL_GET_PROTOCOL_STATS(p_hwfn->p_dev, stats_type, &stats);
1656ec94dbc5SRasesh Mody
1657ffdd0599SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1658ffdd0599SHarish Patil mb_params.cmd = DRV_MSG_CODE_GET_STATS;
1659ffdd0599SHarish Patil mb_params.param = hsi_param;
1660e32dc0f7SRasesh Mody mb_params.p_data_src = &stats;
1661e32dc0f7SRasesh Mody mb_params.data_src_size = sizeof(stats);
16622c3945f6SRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
16632c3945f6SRasesh Mody if (rc != ECORE_SUCCESS)
16642c3945f6SRasesh Mody DP_ERR(p_hwfn, "Failed to send protocol stats, rc = %d\n", rc);
1665ec94dbc5SRasesh Mody }
1666ec94dbc5SRasesh Mody
ecore_read_pf_bandwidth(struct ecore_hwfn * p_hwfn,struct public_func * p_shmem_info)1667ababb520SRasesh Mody static void ecore_read_pf_bandwidth(struct ecore_hwfn *p_hwfn,
1668ec94dbc5SRasesh Mody struct public_func *p_shmem_info)
1669ec94dbc5SRasesh Mody {
1670ec94dbc5SRasesh Mody struct ecore_mcp_function_info *p_info;
1671ec94dbc5SRasesh Mody
1672ec94dbc5SRasesh Mody p_info = &p_hwfn->mcp_info->func_info;
1673ec94dbc5SRasesh Mody
1674ec94dbc5SRasesh Mody /* TODO - bandwidth min/max should have valid values of 1-100,
1675ec94dbc5SRasesh Mody * as well as some indication that the feature is disabled.
1676ec94dbc5SRasesh Mody * Until MFW/qlediag enforce those limitations, Assume THERE IS ALWAYS
1677ec94dbc5SRasesh Mody * limit and correct value to min `1' and max `100' if limit isn't in
1678ec94dbc5SRasesh Mody * range.
1679ec94dbc5SRasesh Mody */
1680ec94dbc5SRasesh Mody p_info->bandwidth_min = (p_shmem_info->config &
1681ec94dbc5SRasesh Mody FUNC_MF_CFG_MIN_BW_MASK) >>
168204b00049SRasesh Mody FUNC_MF_CFG_MIN_BW_OFFSET;
1683ec94dbc5SRasesh Mody if (p_info->bandwidth_min < 1 || p_info->bandwidth_min > 100) {
1684ec94dbc5SRasesh Mody DP_INFO(p_hwfn,
1685ec94dbc5SRasesh Mody "bandwidth minimum out of bounds [%02x]. Set to 1\n",
1686ec94dbc5SRasesh Mody p_info->bandwidth_min);
1687ec94dbc5SRasesh Mody p_info->bandwidth_min = 1;
1688ec94dbc5SRasesh Mody }
1689ec94dbc5SRasesh Mody
1690ec94dbc5SRasesh Mody p_info->bandwidth_max = (p_shmem_info->config &
1691ec94dbc5SRasesh Mody FUNC_MF_CFG_MAX_BW_MASK) >>
169204b00049SRasesh Mody FUNC_MF_CFG_MAX_BW_OFFSET;
1693ec94dbc5SRasesh Mody if (p_info->bandwidth_max < 1 || p_info->bandwidth_max > 100) {
1694ec94dbc5SRasesh Mody DP_INFO(p_hwfn,
1695ec94dbc5SRasesh Mody "bandwidth maximum out of bounds [%02x]. Set to 100\n",
1696ec94dbc5SRasesh Mody p_info->bandwidth_max);
1697ec94dbc5SRasesh Mody p_info->bandwidth_max = 100;
1698ec94dbc5SRasesh Mody }
1699ec94dbc5SRasesh Mody }
1700ec94dbc5SRasesh Mody
1701ec94dbc5SRasesh Mody static void
ecore_mcp_update_bw(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1702ec94dbc5SRasesh Mody ecore_mcp_update_bw(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1703ec94dbc5SRasesh Mody {
1704ec94dbc5SRasesh Mody struct ecore_mcp_function_info *p_info;
1705ec94dbc5SRasesh Mody struct public_func shmem_info;
1706ec94dbc5SRasesh Mody u32 resp = 0, param = 0;
1707ec94dbc5SRasesh Mody
1708ec94dbc5SRasesh Mody ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
1709ec94dbc5SRasesh Mody
1710ec94dbc5SRasesh Mody ecore_read_pf_bandwidth(p_hwfn, &shmem_info);
1711ec94dbc5SRasesh Mody
1712ec94dbc5SRasesh Mody p_info = &p_hwfn->mcp_info->func_info;
1713ec94dbc5SRasesh Mody
1714ec94dbc5SRasesh Mody ecore_configure_pf_min_bandwidth(p_hwfn->p_dev, p_info->bandwidth_min);
1715ec94dbc5SRasesh Mody
1716ec94dbc5SRasesh Mody ecore_configure_pf_max_bandwidth(p_hwfn->p_dev, p_info->bandwidth_max);
1717ec94dbc5SRasesh Mody
1718ec94dbc5SRasesh Mody /* Acknowledge the MFW */
1719ec94dbc5SRasesh Mody ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BW_UPDATE_ACK, 0, &resp,
1720ec94dbc5SRasesh Mody ¶m);
1721ec94dbc5SRasesh Mody }
1722ec94dbc5SRasesh Mody
ecore_mcp_update_stag(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1723cb719927SRasesh Mody static void ecore_mcp_update_stag(struct ecore_hwfn *p_hwfn,
1724cb719927SRasesh Mody struct ecore_ptt *p_ptt)
1725cb719927SRasesh Mody {
1726cb719927SRasesh Mody struct public_func shmem_info;
1727cb719927SRasesh Mody u32 resp = 0, param = 0;
1728cb719927SRasesh Mody
1729cb719927SRasesh Mody ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
1730cb719927SRasesh Mody MCP_PF_ID(p_hwfn));
1731cb719927SRasesh Mody
1732cb719927SRasesh Mody p_hwfn->mcp_info->func_info.ovlan = (u16)shmem_info.ovlan_stag &
1733cb719927SRasesh Mody FUNC_MF_CFG_OV_STAG_MASK;
1734cb719927SRasesh Mody p_hwfn->hw_info.ovlan = p_hwfn->mcp_info->func_info.ovlan;
17355018f1fcSJoyce Kong if (OSAL_GET_BIT(ECORE_MF_OVLAN_CLSS, &p_hwfn->p_dev->mf_bits)) {
1736cb719927SRasesh Mody if (p_hwfn->hw_info.ovlan != ECORE_MCP_VLAN_UNSET) {
1737cb719927SRasesh Mody ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_VALUE,
1738cb719927SRasesh Mody p_hwfn->hw_info.ovlan);
1739cb719927SRasesh Mody ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_EN, 1);
1740cb719927SRasesh Mody
1741cb719927SRasesh Mody /* Configure DB to add external vlan to EDPM packets */
1742cb719927SRasesh Mody ecore_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 1);
174352fa735cSRasesh Mody ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_EXT_VID,
1744cb719927SRasesh Mody p_hwfn->hw_info.ovlan);
1745cb719927SRasesh Mody } else {
1746cb719927SRasesh Mody ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_EN, 0);
1747cb719927SRasesh Mody ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_VALUE, 0);
1748cb719927SRasesh Mody
1749cb719927SRasesh Mody /* Configure DB to add external vlan to EDPM packets */
1750cb719927SRasesh Mody ecore_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 0);
175152fa735cSRasesh Mody ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_EXT_VID, 0);
1752cb719927SRasesh Mody }
1753cb719927SRasesh Mody
1754cb719927SRasesh Mody ecore_sp_pf_update_stag(p_hwfn);
1755cb719927SRasesh Mody }
1756cb719927SRasesh Mody
1757cb719927SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "ovlan = %d hw_mode = 0x%x\n",
1758cb719927SRasesh Mody p_hwfn->mcp_info->func_info.ovlan, p_hwfn->hw_info.hw_mode);
1759cb719927SRasesh Mody OSAL_HW_INFO_CHANGE(p_hwfn, ECORE_HW_INFO_CHANGE_OVLAN);
1760cb719927SRasesh Mody
1761cb719927SRasesh Mody /* Acknowledge the MFW */
1762cb719927SRasesh Mody ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_S_TAG_UPDATE_ACK, 0,
1763cb719927SRasesh Mody &resp, ¶m);
1764cb719927SRasesh Mody }
1765cb719927SRasesh Mody
ecore_mcp_handle_fan_failure(struct ecore_hwfn * p_hwfn)176630ecf673SRasesh Mody static void ecore_mcp_handle_fan_failure(struct ecore_hwfn *p_hwfn)
1767ec94dbc5SRasesh Mody {
1768ec94dbc5SRasesh Mody /* A single notification should be sent to upper driver in CMT mode */
1769ec94dbc5SRasesh Mody if (p_hwfn != ECORE_LEADING_HWFN(p_hwfn->p_dev))
1770ec94dbc5SRasesh Mody return;
1771ec94dbc5SRasesh Mody
1772ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false,
1773ec94dbc5SRasesh Mody "Fan failure was detected on the network interface card"
1774ec94dbc5SRasesh Mody " and it's going to be shut down.\n");
1775ec94dbc5SRasesh Mody
1776ec94dbc5SRasesh Mody ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_FAN_FAIL);
1777ec94dbc5SRasesh Mody }
1778ec94dbc5SRasesh Mody
1779e32dc0f7SRasesh Mody struct ecore_mdump_cmd_params {
1780e32dc0f7SRasesh Mody u32 cmd;
1781e32dc0f7SRasesh Mody void *p_data_src;
1782e32dc0f7SRasesh Mody u8 data_src_size;
1783e32dc0f7SRasesh Mody void *p_data_dst;
1784e32dc0f7SRasesh Mody u8 data_dst_size;
1785e32dc0f7SRasesh Mody u32 mcp_resp;
1786e32dc0f7SRasesh Mody };
1787e32dc0f7SRasesh Mody
1788301ea2d7SRasesh Mody static enum _ecore_status_t
ecore_mcp_mdump_cmd(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mdump_cmd_params * p_mdump_cmd_params)1789301ea2d7SRasesh Mody ecore_mcp_mdump_cmd(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1790e32dc0f7SRasesh Mody struct ecore_mdump_cmd_params *p_mdump_cmd_params)
1791301ea2d7SRasesh Mody {
1792301ea2d7SRasesh Mody struct ecore_mcp_mb_params mb_params;
1793301ea2d7SRasesh Mody enum _ecore_status_t rc;
1794301ea2d7SRasesh Mody
1795301ea2d7SRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1796301ea2d7SRasesh Mody mb_params.cmd = DRV_MSG_CODE_MDUMP_CMD;
1797e32dc0f7SRasesh Mody mb_params.param = p_mdump_cmd_params->cmd;
1798e32dc0f7SRasesh Mody mb_params.p_data_src = p_mdump_cmd_params->p_data_src;
1799e32dc0f7SRasesh Mody mb_params.data_src_size = p_mdump_cmd_params->data_src_size;
1800e32dc0f7SRasesh Mody mb_params.p_data_dst = p_mdump_cmd_params->p_data_dst;
1801e32dc0f7SRasesh Mody mb_params.data_dst_size = p_mdump_cmd_params->data_dst_size;
1802301ea2d7SRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1803301ea2d7SRasesh Mody if (rc != ECORE_SUCCESS)
1804301ea2d7SRasesh Mody return rc;
1805301ea2d7SRasesh Mody
1806e32dc0f7SRasesh Mody p_mdump_cmd_params->mcp_resp = mb_params.mcp_resp;
1807a064d7d2SRasesh Mody
1808e32dc0f7SRasesh Mody if (p_mdump_cmd_params->mcp_resp == FW_MSG_CODE_MDUMP_INVALID_CMD) {
1809a064d7d2SRasesh Mody DP_INFO(p_hwfn,
1810a064d7d2SRasesh Mody "The mdump sub command is unsupported by the MFW [mdump_cmd 0x%x]\n",
1811e32dc0f7SRasesh Mody p_mdump_cmd_params->cmd);
1812a064d7d2SRasesh Mody rc = ECORE_NOTIMPL;
1813a064d7d2SRasesh Mody } else if (p_mdump_cmd_params->mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
1814a064d7d2SRasesh Mody DP_INFO(p_hwfn,
1815a064d7d2SRasesh Mody "The mdump command is not supported by the MFW\n");
1816a064d7d2SRasesh Mody rc = ECORE_NOTIMPL;
1817301ea2d7SRasesh Mody }
1818301ea2d7SRasesh Mody
1819301ea2d7SRasesh Mody return rc;
1820301ea2d7SRasesh Mody }
1821301ea2d7SRasesh Mody
ecore_mcp_mdump_ack(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1822301ea2d7SRasesh Mody static enum _ecore_status_t ecore_mcp_mdump_ack(struct ecore_hwfn *p_hwfn,
1823301ea2d7SRasesh Mody struct ecore_ptt *p_ptt)
1824301ea2d7SRasesh Mody {
1825e32dc0f7SRasesh Mody struct ecore_mdump_cmd_params mdump_cmd_params;
1826301ea2d7SRasesh Mody
1827e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1828e32dc0f7SRasesh Mody mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_ACK;
1829e32dc0f7SRasesh Mody
1830e32dc0f7SRasesh Mody return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1831301ea2d7SRasesh Mody }
1832301ea2d7SRasesh Mody
ecore_mcp_mdump_set_values(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 epoch)1833301ea2d7SRasesh Mody enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
1834301ea2d7SRasesh Mody struct ecore_ptt *p_ptt,
1835301ea2d7SRasesh Mody u32 epoch)
1836301ea2d7SRasesh Mody {
1837e32dc0f7SRasesh Mody struct ecore_mdump_cmd_params mdump_cmd_params;
1838301ea2d7SRasesh Mody
1839e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1840e32dc0f7SRasesh Mody mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_SET_VALUES;
1841e32dc0f7SRasesh Mody mdump_cmd_params.p_data_src = &epoch;
1842e32dc0f7SRasesh Mody mdump_cmd_params.data_src_size = sizeof(epoch);
1843301ea2d7SRasesh Mody
1844e32dc0f7SRasesh Mody return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1845301ea2d7SRasesh Mody }
1846301ea2d7SRasesh Mody
ecore_mcp_mdump_trigger(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1847301ea2d7SRasesh Mody enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
1848301ea2d7SRasesh Mody struct ecore_ptt *p_ptt)
1849301ea2d7SRasesh Mody {
1850e32dc0f7SRasesh Mody struct ecore_mdump_cmd_params mdump_cmd_params;
1851301ea2d7SRasesh Mody
1852e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1853e32dc0f7SRasesh Mody mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_TRIGGER;
1854f8da0cd6SRasesh Mody
1855e32dc0f7SRasesh Mody return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1856301ea2d7SRasesh Mody }
1857301ea2d7SRasesh Mody
1858301ea2d7SRasesh Mody static enum _ecore_status_t
ecore_mcp_mdump_get_config(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct mdump_config_stc * p_mdump_config)1859301ea2d7SRasesh Mody ecore_mcp_mdump_get_config(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1860301ea2d7SRasesh Mody struct mdump_config_stc *p_mdump_config)
1861301ea2d7SRasesh Mody {
1862e32dc0f7SRasesh Mody struct ecore_mdump_cmd_params mdump_cmd_params;
1863301ea2d7SRasesh Mody enum _ecore_status_t rc;
1864301ea2d7SRasesh Mody
1865e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1866e32dc0f7SRasesh Mody mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_GET_CONFIG;
1867e32dc0f7SRasesh Mody mdump_cmd_params.p_data_dst = p_mdump_config;
1868e32dc0f7SRasesh Mody mdump_cmd_params.data_dst_size = sizeof(*p_mdump_config);
1869e32dc0f7SRasesh Mody
1870e32dc0f7SRasesh Mody rc = ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1871301ea2d7SRasesh Mody if (rc != ECORE_SUCCESS)
1872301ea2d7SRasesh Mody return rc;
1873301ea2d7SRasesh Mody
1874e32dc0f7SRasesh Mody if (mdump_cmd_params.mcp_resp != FW_MSG_CODE_OK) {
1875a064d7d2SRasesh Mody DP_INFO(p_hwfn,
1876e32dc0f7SRasesh Mody "Failed to get the mdump configuration and logs info [mcp_resp 0x%x]\n",
1877e32dc0f7SRasesh Mody mdump_cmd_params.mcp_resp);
1878e32dc0f7SRasesh Mody rc = ECORE_UNKNOWN_ERROR;
1879e32dc0f7SRasesh Mody }
1880301ea2d7SRasesh Mody
1881301ea2d7SRasesh Mody return rc;
1882301ea2d7SRasesh Mody }
1883301ea2d7SRasesh Mody
1884f8da0cd6SRasesh Mody enum _ecore_status_t
ecore_mcp_mdump_get_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mdump_info * p_mdump_info)1885f8da0cd6SRasesh Mody ecore_mcp_mdump_get_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1886f8da0cd6SRasesh Mody struct ecore_mdump_info *p_mdump_info)
1887301ea2d7SRasesh Mody {
1888f8da0cd6SRasesh Mody u32 addr, global_offsize, global_addr;
1889301ea2d7SRasesh Mody struct mdump_config_stc mdump_config;
1890301ea2d7SRasesh Mody enum _ecore_status_t rc;
1891301ea2d7SRasesh Mody
18923b307c55SRasesh Mody #ifndef ASIC_ONLY
18933b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
18943b307c55SRasesh Mody DP_INFO(p_hwfn, "Emulation: Can't get mdump info\n");
18953b307c55SRasesh Mody return ECORE_NOTIMPL;
18963b307c55SRasesh Mody }
18973b307c55SRasesh Mody #endif
18983b307c55SRasesh Mody
1899f8da0cd6SRasesh Mody OSAL_MEMSET(p_mdump_info, 0, sizeof(*p_mdump_info));
1900f8da0cd6SRasesh Mody
1901f8da0cd6SRasesh Mody addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1902f8da0cd6SRasesh Mody PUBLIC_GLOBAL);
1903f8da0cd6SRasesh Mody global_offsize = ecore_rd(p_hwfn, p_ptt, addr);
1904f8da0cd6SRasesh Mody global_addr = SECTION_ADDR(global_offsize, 0);
1905f8da0cd6SRasesh Mody p_mdump_info->reason = ecore_rd(p_hwfn, p_ptt,
1906f8da0cd6SRasesh Mody global_addr +
1907f8da0cd6SRasesh Mody OFFSETOF(struct public_global,
1908f8da0cd6SRasesh Mody mdump_reason));
1909f8da0cd6SRasesh Mody
1910f8da0cd6SRasesh Mody if (p_mdump_info->reason) {
1911301ea2d7SRasesh Mody rc = ecore_mcp_mdump_get_config(p_hwfn, p_ptt, &mdump_config);
1912301ea2d7SRasesh Mody if (rc != ECORE_SUCCESS)
1913301ea2d7SRasesh Mody return rc;
1914301ea2d7SRasesh Mody
1915f8da0cd6SRasesh Mody p_mdump_info->version = mdump_config.version;
1916f8da0cd6SRasesh Mody p_mdump_info->config = mdump_config.config;
1917f8da0cd6SRasesh Mody p_mdump_info->epoch = mdump_config.epoc;
1918f8da0cd6SRasesh Mody p_mdump_info->num_of_logs = mdump_config.num_of_logs;
1919f8da0cd6SRasesh Mody p_mdump_info->valid_logs = mdump_config.valid_logs;
1920f8da0cd6SRasesh Mody
1921301ea2d7SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1922f8da0cd6SRasesh Mody "MFW mdump info: reason %d, version 0x%x, config 0x%x, epoch 0x%x, num_of_logs 0x%x, valid_logs 0x%x\n",
1923f8da0cd6SRasesh Mody p_mdump_info->reason, p_mdump_info->version,
1924f8da0cd6SRasesh Mody p_mdump_info->config, p_mdump_info->epoch,
1925f8da0cd6SRasesh Mody p_mdump_info->num_of_logs, p_mdump_info->valid_logs);
1926f8da0cd6SRasesh Mody } else {
1927f8da0cd6SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1928f8da0cd6SRasesh Mody "MFW mdump info: reason %d\n", p_mdump_info->reason);
1929301ea2d7SRasesh Mody }
1930301ea2d7SRasesh Mody
1931f8da0cd6SRasesh Mody return ECORE_SUCCESS;
1932301ea2d7SRasesh Mody }
1933301ea2d7SRasesh Mody
ecore_mcp_mdump_clear_logs(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1934f8da0cd6SRasesh Mody enum _ecore_status_t ecore_mcp_mdump_clear_logs(struct ecore_hwfn *p_hwfn,
1935f8da0cd6SRasesh Mody struct ecore_ptt *p_ptt)
1936301ea2d7SRasesh Mody {
1937e32dc0f7SRasesh Mody struct ecore_mdump_cmd_params mdump_cmd_params;
1938f8da0cd6SRasesh Mody
1939e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1940e32dc0f7SRasesh Mody mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_CLEAR_LOGS;
1941e32dc0f7SRasesh Mody
1942e32dc0f7SRasesh Mody return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1943301ea2d7SRasesh Mody }
1944301ea2d7SRasesh Mody
1945a064d7d2SRasesh Mody enum _ecore_status_t
ecore_mcp_mdump_get_retain(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mdump_retain_data * p_mdump_retain)1946a064d7d2SRasesh Mody ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1947a064d7d2SRasesh Mody struct ecore_mdump_retain_data *p_mdump_retain)
1948a064d7d2SRasesh Mody {
1949a064d7d2SRasesh Mody struct ecore_mdump_cmd_params mdump_cmd_params;
1950a064d7d2SRasesh Mody struct mdump_retain_data_stc mfw_mdump_retain;
1951a064d7d2SRasesh Mody enum _ecore_status_t rc;
1952a064d7d2SRasesh Mody
1953a064d7d2SRasesh Mody OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1954a064d7d2SRasesh Mody mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_GET_RETAIN;
1955a064d7d2SRasesh Mody mdump_cmd_params.p_data_dst = &mfw_mdump_retain;
1956a064d7d2SRasesh Mody mdump_cmd_params.data_dst_size = sizeof(mfw_mdump_retain);
1957a064d7d2SRasesh Mody
1958a064d7d2SRasesh Mody rc = ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1959a064d7d2SRasesh Mody if (rc != ECORE_SUCCESS)
1960a064d7d2SRasesh Mody return rc;
1961a064d7d2SRasesh Mody
1962a064d7d2SRasesh Mody if (mdump_cmd_params.mcp_resp != FW_MSG_CODE_OK) {
1963a064d7d2SRasesh Mody DP_INFO(p_hwfn,
1964a064d7d2SRasesh Mody "Failed to get the mdump retained data [mcp_resp 0x%x]\n",
1965a064d7d2SRasesh Mody mdump_cmd_params.mcp_resp);
1966a064d7d2SRasesh Mody return ECORE_UNKNOWN_ERROR;
1967a064d7d2SRasesh Mody }
1968a064d7d2SRasesh Mody
1969a064d7d2SRasesh Mody p_mdump_retain->valid = mfw_mdump_retain.valid;
1970a064d7d2SRasesh Mody p_mdump_retain->epoch = mfw_mdump_retain.epoch;
1971a064d7d2SRasesh Mody p_mdump_retain->pf = mfw_mdump_retain.pf;
1972a064d7d2SRasesh Mody p_mdump_retain->status = mfw_mdump_retain.status;
1973a064d7d2SRasesh Mody
1974a064d7d2SRasesh Mody return ECORE_SUCCESS;
1975a064d7d2SRasesh Mody }
1976a064d7d2SRasesh Mody
ecore_mcp_mdump_clr_retain(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1977a064d7d2SRasesh Mody enum _ecore_status_t ecore_mcp_mdump_clr_retain(struct ecore_hwfn *p_hwfn,
1978a064d7d2SRasesh Mody struct ecore_ptt *p_ptt)
1979a064d7d2SRasesh Mody {
1980a064d7d2SRasesh Mody struct ecore_mdump_cmd_params mdump_cmd_params;
1981a064d7d2SRasesh Mody
1982a064d7d2SRasesh Mody OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1983a064d7d2SRasesh Mody mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_CLR_RETAIN;
1984a064d7d2SRasesh Mody
1985a064d7d2SRasesh Mody return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1986a064d7d2SRasesh Mody }
1987a064d7d2SRasesh Mody
ecore_mcp_handle_critical_error(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)1988301ea2d7SRasesh Mody static void ecore_mcp_handle_critical_error(struct ecore_hwfn *p_hwfn,
1989301ea2d7SRasesh Mody struct ecore_ptt *p_ptt)
1990301ea2d7SRasesh Mody {
1991a064d7d2SRasesh Mody struct ecore_mdump_retain_data mdump_retain;
1992a064d7d2SRasesh Mody enum _ecore_status_t rc;
1993a064d7d2SRasesh Mody
1994301ea2d7SRasesh Mody /* In CMT mode - no need for more than a single acknowledgment to the
1995301ea2d7SRasesh Mody * MFW, and no more than a single notification to the upper driver.
1996301ea2d7SRasesh Mody */
1997301ea2d7SRasesh Mody if (p_hwfn != ECORE_LEADING_HWFN(p_hwfn->p_dev))
1998301ea2d7SRasesh Mody return;
1999301ea2d7SRasesh Mody
2000a064d7d2SRasesh Mody rc = ecore_mcp_mdump_get_retain(p_hwfn, p_ptt, &mdump_retain);
2001a064d7d2SRasesh Mody if (rc == ECORE_SUCCESS && mdump_retain.valid) {
2002301ea2d7SRasesh Mody DP_NOTICE(p_hwfn, false,
2003a064d7d2SRasesh Mody "The MFW notified that a critical error occurred in the device [epoch 0x%08x, pf 0x%x, status 0x%08x]\n",
2004a064d7d2SRasesh Mody mdump_retain.epoch, mdump_retain.pf,
2005a064d7d2SRasesh Mody mdump_retain.status);
2006a064d7d2SRasesh Mody } else {
2007a064d7d2SRasesh Mody DP_NOTICE(p_hwfn, false,
2008a064d7d2SRasesh Mody "The MFW notified that a critical error occurred in the device\n");
2009a064d7d2SRasesh Mody }
2010301ea2d7SRasesh Mody
20113d5083f2SRasesh Mody if (p_hwfn->p_dev->allow_mdump) {
2012301ea2d7SRasesh Mody DP_NOTICE(p_hwfn, false,
2013301ea2d7SRasesh Mody "Not acknowledging the notification to allow the MFW crash dump\n");
2014301ea2d7SRasesh Mody return;
2015301ea2d7SRasesh Mody }
2016301ea2d7SRasesh Mody
2017a064d7d2SRasesh Mody DP_NOTICE(p_hwfn, false,
2018a064d7d2SRasesh Mody "Acknowledging the notification to not allow the MFW crash dump [driver debug data collection is preferable]\n");
2019301ea2d7SRasesh Mody ecore_mcp_mdump_ack(p_hwfn, p_ptt);
2020301ea2d7SRasesh Mody ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_HW_ATTN);
2021301ea2d7SRasesh Mody }
2022301ea2d7SRasesh Mody
202347af7019SRasesh Mody void
ecore_mcp_read_ufp_config(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)202447af7019SRasesh Mody ecore_mcp_read_ufp_config(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
202547af7019SRasesh Mody {
202647af7019SRasesh Mody struct public_func shmem_info;
202747af7019SRasesh Mody u32 port_cfg, val;
202847af7019SRasesh Mody
20295018f1fcSJoyce Kong if (!OSAL_GET_BIT(ECORE_MF_UFP_SPECIFIC, &p_hwfn->p_dev->mf_bits))
203047af7019SRasesh Mody return;
203147af7019SRasesh Mody
203247af7019SRasesh Mody OSAL_MEMSET(&p_hwfn->ufp_info, 0, sizeof(p_hwfn->ufp_info));
203347af7019SRasesh Mody port_cfg = ecore_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
203447af7019SRasesh Mody OFFSETOF(struct public_port, oem_cfg_port));
203547af7019SRasesh Mody val = GET_MFW_FIELD(port_cfg, OEM_CFG_CHANNEL_TYPE);
203647af7019SRasesh Mody if (val != OEM_CFG_CHANNEL_TYPE_STAGGED)
203747af7019SRasesh Mody DP_NOTICE(p_hwfn, false, "Incorrect UFP Channel type %d\n",
203847af7019SRasesh Mody val);
203947af7019SRasesh Mody
204047af7019SRasesh Mody val = GET_MFW_FIELD(port_cfg, OEM_CFG_SCHED_TYPE);
204147af7019SRasesh Mody if (val == OEM_CFG_SCHED_TYPE_ETS)
204247af7019SRasesh Mody p_hwfn->ufp_info.mode = ECORE_UFP_MODE_ETS;
204347af7019SRasesh Mody else if (val == OEM_CFG_SCHED_TYPE_VNIC_BW)
204447af7019SRasesh Mody p_hwfn->ufp_info.mode = ECORE_UFP_MODE_VNIC_BW;
204547af7019SRasesh Mody else
204647af7019SRasesh Mody DP_NOTICE(p_hwfn, false, "Unknown UFP scheduling mode %d\n",
204747af7019SRasesh Mody val);
204847af7019SRasesh Mody
204947af7019SRasesh Mody ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
205047af7019SRasesh Mody MCP_PF_ID(p_hwfn));
205147af7019SRasesh Mody val = GET_MFW_FIELD(shmem_info.oem_cfg_func, OEM_CFG_FUNC_TC);
205247af7019SRasesh Mody p_hwfn->ufp_info.tc = (u8)val;
205347af7019SRasesh Mody val = GET_MFW_FIELD(shmem_info.oem_cfg_func,
205447af7019SRasesh Mody OEM_CFG_FUNC_HOST_PRI_CTRL);
205547af7019SRasesh Mody if (val == OEM_CFG_FUNC_HOST_PRI_CTRL_VNIC)
205647af7019SRasesh Mody p_hwfn->ufp_info.pri_type = ECORE_UFP_PRI_VNIC;
205747af7019SRasesh Mody else if (val == OEM_CFG_FUNC_HOST_PRI_CTRL_OS)
205847af7019SRasesh Mody p_hwfn->ufp_info.pri_type = ECORE_UFP_PRI_OS;
205947af7019SRasesh Mody else
206047af7019SRasesh Mody DP_NOTICE(p_hwfn, false, "Unknown Host priority control %d\n",
206147af7019SRasesh Mody val);
206247af7019SRasesh Mody
2063657b762aSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
206447af7019SRasesh Mody "UFP shmem config: mode = %d tc = %d pri_type = %d\n",
206547af7019SRasesh Mody p_hwfn->ufp_info.mode, p_hwfn->ufp_info.tc,
206647af7019SRasesh Mody p_hwfn->ufp_info.pri_type);
206747af7019SRasesh Mody }
206847af7019SRasesh Mody
206947af7019SRasesh Mody static enum _ecore_status_t
ecore_mcp_handle_ufp_event(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)207047af7019SRasesh Mody ecore_mcp_handle_ufp_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
207147af7019SRasesh Mody {
207247af7019SRasesh Mody ecore_mcp_read_ufp_config(p_hwfn, p_ptt);
207347af7019SRasesh Mody
207447af7019SRasesh Mody if (p_hwfn->ufp_info.mode == ECORE_UFP_MODE_VNIC_BW) {
207547af7019SRasesh Mody p_hwfn->qm_info.ooo_tc = p_hwfn->ufp_info.tc;
207647af7019SRasesh Mody p_hwfn->hw_info.offload_tc = p_hwfn->ufp_info.tc;
207747af7019SRasesh Mody
207847af7019SRasesh Mody ecore_qm_reconf(p_hwfn, p_ptt);
207947af7019SRasesh Mody } else {
208047af7019SRasesh Mody /* Merge UFP TC with the dcbx TC data */
208147af7019SRasesh Mody ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
208247af7019SRasesh Mody ECORE_DCBX_OPERATIONAL_MIB);
208347af7019SRasesh Mody }
208447af7019SRasesh Mody
208547af7019SRasesh Mody /* update storm FW with negotiation results */
208647af7019SRasesh Mody ecore_sp_pf_update_ufp(p_hwfn);
208747af7019SRasesh Mody
20883b307c55SRasesh Mody /* update stag pcp value */
20893b307c55SRasesh Mody ecore_sp_pf_update_stag(p_hwfn);
20903b307c55SRasesh Mody
209147af7019SRasesh Mody return ECORE_SUCCESS;
209247af7019SRasesh Mody }
209347af7019SRasesh Mody
ecore_mcp_handle_events(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)2094ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
2095ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
2096ec94dbc5SRasesh Mody {
2097ec94dbc5SRasesh Mody struct ecore_mcp_info *info = p_hwfn->mcp_info;
2098ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
2099ec94dbc5SRasesh Mody bool found = false;
2100ec94dbc5SRasesh Mody u16 i;
2101ec94dbc5SRasesh Mody
2102ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "Received message from MFW\n");
2103ec94dbc5SRasesh Mody
2104ec94dbc5SRasesh Mody /* Read Messages from MFW */
2105ec94dbc5SRasesh Mody ecore_mcp_read_mb(p_hwfn, p_ptt);
2106ec94dbc5SRasesh Mody
2107ec94dbc5SRasesh Mody /* Compare current messages to old ones */
2108ec94dbc5SRasesh Mody for (i = 0; i < info->mfw_mb_length; i++) {
2109ec94dbc5SRasesh Mody if (info->mfw_mb_cur[i] == info->mfw_mb_shadow[i])
2110ec94dbc5SRasesh Mody continue;
2111ec94dbc5SRasesh Mody
2112ec94dbc5SRasesh Mody found = true;
2113ec94dbc5SRasesh Mody
2114ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
2115ec94dbc5SRasesh Mody "Msg [%d] - old CMD 0x%02x, new CMD 0x%02x\n",
2116ec94dbc5SRasesh Mody i, info->mfw_mb_shadow[i], info->mfw_mb_cur[i]);
2117ec94dbc5SRasesh Mody
2118ec94dbc5SRasesh Mody switch (i) {
2119ec94dbc5SRasesh Mody case MFW_DRV_MSG_LINK_CHANGE:
2120ec94dbc5SRasesh Mody ecore_mcp_handle_link_change(p_hwfn, p_ptt, false);
2121ec94dbc5SRasesh Mody break;
2122ec94dbc5SRasesh Mody case MFW_DRV_MSG_VF_DISABLED:
2123ec94dbc5SRasesh Mody ecore_mcp_handle_vf_flr(p_hwfn, p_ptt);
2124ec94dbc5SRasesh Mody break;
212526ae839dSRasesh Mody case MFW_DRV_MSG_LLDP_DATA_UPDATED:
212626ae839dSRasesh Mody ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
212726ae839dSRasesh Mody ECORE_DCBX_REMOTE_LLDP_MIB);
212826ae839dSRasesh Mody break;
212926ae839dSRasesh Mody case MFW_DRV_MSG_DCBX_REMOTE_MIB_UPDATED:
213026ae839dSRasesh Mody ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
213126ae839dSRasesh Mody ECORE_DCBX_REMOTE_MIB);
213226ae839dSRasesh Mody break;
213326ae839dSRasesh Mody case MFW_DRV_MSG_DCBX_OPERATIONAL_MIB_UPDATED:
213426ae839dSRasesh Mody ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
213526ae839dSRasesh Mody ECORE_DCBX_OPERATIONAL_MIB);
213636341ac6SRasesh Mody /* clear the user-config cache */
213736341ac6SRasesh Mody OSAL_MEMSET(&p_hwfn->p_dcbx_info->set, 0,
213836341ac6SRasesh Mody sizeof(struct ecore_dcbx_set));
213926ae839dSRasesh Mody break;
214081dba2b2SRasesh Mody case MFW_DRV_MSG_LLDP_RECEIVED_TLVS_UPDATED:
214181dba2b2SRasesh Mody ecore_lldp_mib_update_event(p_hwfn, p_ptt);
214281dba2b2SRasesh Mody break;
214347af7019SRasesh Mody case MFW_DRV_MSG_OEM_CFG_UPDATE:
214447af7019SRasesh Mody ecore_mcp_handle_ufp_event(p_hwfn, p_ptt);
214547af7019SRasesh Mody break;
214622d07d93SRasesh Mody case MFW_DRV_MSG_TRANSCEIVER_STATE_CHANGE:
214722d07d93SRasesh Mody ecore_mcp_handle_transceiver_change(p_hwfn, p_ptt);
214822d07d93SRasesh Mody break;
2149ec94dbc5SRasesh Mody case MFW_DRV_MSG_ERROR_RECOVERY:
2150ec94dbc5SRasesh Mody ecore_mcp_handle_process_kill(p_hwfn, p_ptt);
2151ec94dbc5SRasesh Mody break;
2152ec94dbc5SRasesh Mody case MFW_DRV_MSG_GET_LAN_STATS:
2153ec94dbc5SRasesh Mody case MFW_DRV_MSG_GET_FCOE_STATS:
2154ec94dbc5SRasesh Mody case MFW_DRV_MSG_GET_ISCSI_STATS:
2155ec94dbc5SRasesh Mody case MFW_DRV_MSG_GET_RDMA_STATS:
2156ec94dbc5SRasesh Mody ecore_mcp_send_protocol_stats(p_hwfn, p_ptt, i);
2157ec94dbc5SRasesh Mody break;
2158ec94dbc5SRasesh Mody case MFW_DRV_MSG_BW_UPDATE:
2159ec94dbc5SRasesh Mody ecore_mcp_update_bw(p_hwfn, p_ptt);
2160ec94dbc5SRasesh Mody break;
2161cb719927SRasesh Mody case MFW_DRV_MSG_S_TAG_UPDATE:
2162cb719927SRasesh Mody ecore_mcp_update_stag(p_hwfn, p_ptt);
2163cb719927SRasesh Mody break;
2164ec94dbc5SRasesh Mody case MFW_DRV_MSG_FAILURE_DETECTED:
216530ecf673SRasesh Mody ecore_mcp_handle_fan_failure(p_hwfn);
2166ec94dbc5SRasesh Mody break;
2167301ea2d7SRasesh Mody case MFW_DRV_MSG_CRITICAL_ERROR_OCCURRED:
2168301ea2d7SRasesh Mody ecore_mcp_handle_critical_error(p_hwfn, p_ptt);
2169301ea2d7SRasesh Mody break;
2170ec94dbc5SRasesh Mody default:
21716bd042a0SRasesh Mody DP_INFO(p_hwfn, "Unimplemented MFW message %d\n", i);
2172ec94dbc5SRasesh Mody rc = ECORE_INVAL;
2173ec94dbc5SRasesh Mody }
2174ec94dbc5SRasesh Mody }
2175ec94dbc5SRasesh Mody
2176ec94dbc5SRasesh Mody /* ACK everything */
2177ec94dbc5SRasesh Mody for (i = 0; i < MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length); i++) {
2178ec94dbc5SRasesh Mody OSAL_BE32 val = OSAL_CPU_TO_BE32(((u32 *)info->mfw_mb_cur)[i]);
2179ec94dbc5SRasesh Mody
2180ec94dbc5SRasesh Mody /* MFW expect answer in BE, so we force write in that format */
2181ec94dbc5SRasesh Mody ecore_wr(p_hwfn, p_ptt,
2182ec94dbc5SRasesh Mody info->mfw_mb_addr + sizeof(u32) +
2183ec94dbc5SRasesh Mody MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length) *
2184ec94dbc5SRasesh Mody sizeof(u32) + i * sizeof(u32), val);
2185ec94dbc5SRasesh Mody }
2186ec94dbc5SRasesh Mody
2187ec94dbc5SRasesh Mody if (!found) {
2188ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false,
2189ec94dbc5SRasesh Mody "Received an MFW message indication but no"
2190ec94dbc5SRasesh Mody " new message!\n");
2191ec94dbc5SRasesh Mody rc = ECORE_INVAL;
2192ec94dbc5SRasesh Mody }
2193ec94dbc5SRasesh Mody
2194ec94dbc5SRasesh Mody /* Copy the new mfw messages into the shadow */
2195ec94dbc5SRasesh Mody OSAL_MEMCPY(info->mfw_mb_shadow, info->mfw_mb_cur, info->mfw_mb_length);
2196ec94dbc5SRasesh Mody
2197ec94dbc5SRasesh Mody return rc;
2198ec94dbc5SRasesh Mody }
2199ec94dbc5SRasesh Mody
ecore_mcp_get_mfw_ver(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * p_mfw_ver,u32 * p_running_bundle_id)220022d07d93SRasesh Mody enum _ecore_status_t ecore_mcp_get_mfw_ver(struct ecore_hwfn *p_hwfn,
2201ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
2202ec94dbc5SRasesh Mody u32 *p_mfw_ver,
2203ec94dbc5SRasesh Mody u32 *p_running_bundle_id)
2204ec94dbc5SRasesh Mody {
2205ec94dbc5SRasesh Mody u32 global_offsize;
2206ec94dbc5SRasesh Mody
2207ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
22083b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
22093b307c55SRasesh Mody DP_INFO(p_hwfn, "Emulation: Can't get MFW version\n");
22103b307c55SRasesh Mody return ECORE_NOTIMPL;
2211ec94dbc5SRasesh Mody }
2212ec94dbc5SRasesh Mody #endif
2213ec94dbc5SRasesh Mody
221422d07d93SRasesh Mody if (IS_VF(p_hwfn->p_dev)) {
221586a2265eSRasesh Mody if (p_hwfn->vf_iov_info) {
221686a2265eSRasesh Mody struct pfvf_acquire_resp_tlv *p_resp;
221786a2265eSRasesh Mody
221886a2265eSRasesh Mody p_resp = &p_hwfn->vf_iov_info->acquire_resp;
221986a2265eSRasesh Mody *p_mfw_ver = p_resp->pfdev_info.mfw_ver;
222086a2265eSRasesh Mody return ECORE_SUCCESS;
222122d07d93SRasesh Mody } else {
222222d07d93SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
222322d07d93SRasesh Mody "VF requested MFW version prior to ACQUIRE\n");
222486a2265eSRasesh Mody return ECORE_INVAL;
222586a2265eSRasesh Mody }
222622d07d93SRasesh Mody }
222786a2265eSRasesh Mody
2228ec94dbc5SRasesh Mody global_offsize = ecore_rd(p_hwfn, p_ptt,
2229ec94dbc5SRasesh Mody SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->
2230ec94dbc5SRasesh Mody public_base,
2231ec94dbc5SRasesh Mody PUBLIC_GLOBAL));
2232ec94dbc5SRasesh Mody *p_mfw_ver =
2233ec94dbc5SRasesh Mody ecore_rd(p_hwfn, p_ptt,
2234ec94dbc5SRasesh Mody SECTION_ADDR(global_offsize,
2235ec94dbc5SRasesh Mody 0) + OFFSETOF(struct public_global, mfw_ver));
2236ec94dbc5SRasesh Mody
2237ec94dbc5SRasesh Mody if (p_running_bundle_id != OSAL_NULL) {
2238ec94dbc5SRasesh Mody *p_running_bundle_id = ecore_rd(p_hwfn, p_ptt,
2239ec94dbc5SRasesh Mody SECTION_ADDR(global_offsize,
2240ec94dbc5SRasesh Mody 0) +
2241ec94dbc5SRasesh Mody OFFSETOF(struct public_global,
2242ec94dbc5SRasesh Mody running_bundle_id));
2243ec94dbc5SRasesh Mody }
2244ec94dbc5SRasesh Mody
2245ec94dbc5SRasesh Mody return ECORE_SUCCESS;
2246ec94dbc5SRasesh Mody }
2247ec94dbc5SRasesh Mody
ecore_mcp_get_mbi_ver(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * p_mbi_ver)2248f97b56f9SRasesh Mody int ecore_mcp_get_mbi_ver(struct ecore_hwfn *p_hwfn,
2249f97b56f9SRasesh Mody struct ecore_ptt *p_ptt, u32 *p_mbi_ver)
2250f97b56f9SRasesh Mody {
2251f97b56f9SRasesh Mody u32 nvm_cfg_addr, nvm_cfg1_offset, mbi_ver_addr;
2252f97b56f9SRasesh Mody
2253f97b56f9SRasesh Mody #ifndef ASIC_ONLY
2254f97b56f9SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
2255f97b56f9SRasesh Mody DP_INFO(p_hwfn, "Emulation: Can't get MBI version\n");
2256f97b56f9SRasesh Mody return -EOPNOTSUPP;
2257f97b56f9SRasesh Mody }
2258f97b56f9SRasesh Mody #endif
2259f97b56f9SRasesh Mody
2260f97b56f9SRasesh Mody if (IS_VF(p_hwfn->p_dev))
2261f97b56f9SRasesh Mody return -EINVAL;
2262f97b56f9SRasesh Mody
2263f97b56f9SRasesh Mody /* Read the address of the nvm_cfg */
2264f97b56f9SRasesh Mody nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2265f97b56f9SRasesh Mody if (!nvm_cfg_addr) {
2266f97b56f9SRasesh Mody DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
2267f97b56f9SRasesh Mody return -EINVAL;
2268f97b56f9SRasesh Mody }
2269f97b56f9SRasesh Mody
2270f97b56f9SRasesh Mody /* Read the offset of nvm_cfg1 */
2271f97b56f9SRasesh Mody nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
2272f97b56f9SRasesh Mody
2273f97b56f9SRasesh Mody mbi_ver_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2274f97b56f9SRasesh Mody offsetof(struct nvm_cfg1, glob) + offsetof(struct nvm_cfg1_glob,
2275f97b56f9SRasesh Mody mbi_version);
2276f97b56f9SRasesh Mody *p_mbi_ver =
2277f97b56f9SRasesh Mody ecore_rd(p_hwfn, p_ptt,
2278f97b56f9SRasesh Mody mbi_ver_addr) & (NVM_CFG1_GLOB_MBI_VERSION_0_MASK |
2279f97b56f9SRasesh Mody NVM_CFG1_GLOB_MBI_VERSION_1_MASK |
2280f97b56f9SRasesh Mody NVM_CFG1_GLOB_MBI_VERSION_2_MASK);
2281f97b56f9SRasesh Mody
2282f97b56f9SRasesh Mody return 0;
2283f97b56f9SRasesh Mody }
2284f97b56f9SRasesh Mody
ecore_mcp_get_media_type(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * p_media_type)2285739a5b2fSRasesh Mody enum _ecore_status_t ecore_mcp_get_media_type(struct ecore_hwfn *p_hwfn,
2286739a5b2fSRasesh Mody struct ecore_ptt *p_ptt,
2287ec94dbc5SRasesh Mody u32 *p_media_type)
2288ec94dbc5SRasesh Mody {
22893b307c55SRasesh Mody *p_media_type = MEDIA_UNSPECIFIED;
2290ec94dbc5SRasesh Mody
229186a2265eSRasesh Mody /* TODO - Add support for VFs */
2292739a5b2fSRasesh Mody if (IS_VF(p_hwfn->p_dev))
229386a2265eSRasesh Mody return ECORE_INVAL;
229486a2265eSRasesh Mody
2295ec94dbc5SRasesh Mody if (!ecore_mcp_is_init(p_hwfn)) {
22963b307c55SRasesh Mody #ifndef ASIC_ONLY
22973b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
22983b307c55SRasesh Mody DP_INFO(p_hwfn, "Emulation: Can't get media type\n");
22993b307c55SRasesh Mody return ECORE_NOTIMPL;
23003b307c55SRasesh Mody }
23013b307c55SRasesh Mody #endif
2302bdc40630SRasesh Mody DP_NOTICE(p_hwfn, false, "MFW is not initialized!\n");
2303ec94dbc5SRasesh Mody return ECORE_BUSY;
2304ec94dbc5SRasesh Mody }
2305ec94dbc5SRasesh Mody
23063b307c55SRasesh Mody if (!p_ptt)
23073b307c55SRasesh Mody return ECORE_INVAL;
23083b307c55SRasesh Mody
2309739a5b2fSRasesh Mody *p_media_type = ecore_rd(p_hwfn, p_ptt,
2310739a5b2fSRasesh Mody p_hwfn->mcp_info->port_addr +
23113b307c55SRasesh Mody OFFSETOF(struct public_port, media_type));
2312ec94dbc5SRasesh Mody
2313ec94dbc5SRasesh Mody return ECORE_SUCCESS;
2314ec94dbc5SRasesh Mody }
2315ec94dbc5SRasesh Mody
ecore_mcp_get_transceiver_data(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * p_transceiver_state,u32 * p_transceiver_type)2316bdc40630SRasesh Mody enum _ecore_status_t ecore_mcp_get_transceiver_data(struct ecore_hwfn *p_hwfn,
2317bdc40630SRasesh Mody struct ecore_ptt *p_ptt,
23186d1be6d6SRasesh Mody u32 *p_transceiver_state,
23196d1be6d6SRasesh Mody u32 *p_transceiver_type)
2320bdc40630SRasesh Mody {
23216d1be6d6SRasesh Mody u32 transceiver_info;
2322bdc40630SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
2323bdc40630SRasesh Mody
2324bdc40630SRasesh Mody /* TODO - Add support for VFs */
2325bdc40630SRasesh Mody if (IS_VF(p_hwfn->p_dev))
2326bdc40630SRasesh Mody return ECORE_INVAL;
2327bdc40630SRasesh Mody
2328bdc40630SRasesh Mody if (!ecore_mcp_is_init(p_hwfn)) {
2329bdc40630SRasesh Mody DP_NOTICE(p_hwfn, false, "MFW is not initialized!\n");
2330bdc40630SRasesh Mody return ECORE_BUSY;
2331bdc40630SRasesh Mody }
23326d1be6d6SRasesh Mody
23336d1be6d6SRasesh Mody *p_transceiver_type = ETH_TRANSCEIVER_TYPE_NONE;
23346d1be6d6SRasesh Mody *p_transceiver_state = ETH_TRANSCEIVER_STATE_UPDATING;
23356d1be6d6SRasesh Mody
23366d1be6d6SRasesh Mody transceiver_info = ecore_rd(p_hwfn, p_ptt,
2337bdc40630SRasesh Mody p_hwfn->mcp_info->port_addr +
2338bdc40630SRasesh Mody offsetof(struct public_port,
2339bdc40630SRasesh Mody transceiver_data));
23406d1be6d6SRasesh Mody
23416d1be6d6SRasesh Mody *p_transceiver_state = GET_MFW_FIELD(transceiver_info,
23426d1be6d6SRasesh Mody ETH_TRANSCEIVER_STATE);
23436d1be6d6SRasesh Mody
23446d1be6d6SRasesh Mody if (*p_transceiver_state == ETH_TRANSCEIVER_STATE_PRESENT) {
23456d1be6d6SRasesh Mody *p_transceiver_type = GET_MFW_FIELD(transceiver_info,
23466d1be6d6SRasesh Mody ETH_TRANSCEIVER_TYPE);
23476d1be6d6SRasesh Mody } else {
23486d1be6d6SRasesh Mody *p_transceiver_type = ETH_TRANSCEIVER_TYPE_UNKNOWN;
2349bdc40630SRasesh Mody }
2350bdc40630SRasesh Mody
2351bdc40630SRasesh Mody return rc;
2352bdc40630SRasesh Mody }
2353bdc40630SRasesh Mody
is_transceiver_ready(u32 transceiver_state,u32 transceiver_type)2354bdc40630SRasesh Mody static int is_transceiver_ready(u32 transceiver_state, u32 transceiver_type)
2355bdc40630SRasesh Mody {
2356bdc40630SRasesh Mody if ((transceiver_state & ETH_TRANSCEIVER_STATE_PRESENT) &&
2357bdc40630SRasesh Mody ((transceiver_state & ETH_TRANSCEIVER_STATE_UPDATING) == 0x0) &&
2358bdc40630SRasesh Mody (transceiver_type != ETH_TRANSCEIVER_TYPE_NONE))
2359bdc40630SRasesh Mody return 1;
2360bdc40630SRasesh Mody
2361bdc40630SRasesh Mody return 0;
2362bdc40630SRasesh Mody }
2363bdc40630SRasesh Mody
ecore_mcp_trans_speed_mask(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * p_speed_mask)2364bdc40630SRasesh Mody enum _ecore_status_t ecore_mcp_trans_speed_mask(struct ecore_hwfn *p_hwfn,
2365bdc40630SRasesh Mody struct ecore_ptt *p_ptt,
2366bdc40630SRasesh Mody u32 *p_speed_mask)
2367bdc40630SRasesh Mody {
2368db8af647SAndrzej Ostruszka u32 transceiver_type = ETH_TRANSCEIVER_TYPE_NONE, transceiver_state;
2369bdc40630SRasesh Mody
23706d1be6d6SRasesh Mody ecore_mcp_get_transceiver_data(p_hwfn, p_ptt, &transceiver_state,
23716d1be6d6SRasesh Mody &transceiver_type);
2372bdc40630SRasesh Mody
2373bdc40630SRasesh Mody
2374bdc40630SRasesh Mody if (is_transceiver_ready(transceiver_state, transceiver_type) == 0)
2375bdc40630SRasesh Mody return ECORE_INVAL;
2376bdc40630SRasesh Mody
2377bdc40630SRasesh Mody switch (transceiver_type) {
2378bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_1G_LX:
2379bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_1G_SX:
2380bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_1G_PCC:
2381bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_1G_ACC:
2382bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_1000BASET:
2383bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2384bdc40630SRasesh Mody break;
2385bdc40630SRasesh Mody
2386bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_10G_SR:
2387bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_10G_LR:
2388bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_10G_LRM:
2389bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_10G_ER:
2390bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_10G_PCC:
2391bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_10G_ACC:
2392bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_4x10G:
2393bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
2394bdc40630SRasesh Mody break;
2395bdc40630SRasesh Mody
2396bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_40G_LR4:
2397bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_40G_SR4:
2398bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_MULTI_RATE_10G_40G_SR:
2399bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_MULTI_RATE_10G_40G_LR:
2400bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2401bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
2402bdc40630SRasesh Mody break;
2403bdc40630SRasesh Mody
2404bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_100G_AOC:
2405bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_100G_SR4:
2406bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_100G_LR4:
2407bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_100G_ER4:
2408bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_100G_ACC:
2409bdc40630SRasesh Mody *p_speed_mask =
2410bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G |
2411bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
2412bdc40630SRasesh Mody break;
2413bdc40630SRasesh Mody
2414bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_SR:
2415bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_LR:
2416bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_AOC:
2417bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_ACC_S:
2418bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_ACC_M:
2419bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_ACC_L:
2420bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
2421bdc40630SRasesh Mody break;
2422bdc40630SRasesh Mody
2423bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_CA_N:
2424bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_CA_S:
2425bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_25G_CA_L:
2426bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_4x25G_CR:
2427bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G |
2428bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2429bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2430bdc40630SRasesh Mody break;
2431bdc40630SRasesh Mody
2432bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_40G_CR4:
2433bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_MULTI_RATE_10G_40G_CR:
2434bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2435bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2436bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2437bdc40630SRasesh Mody break;
2438bdc40630SRasesh Mody
2439bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_100G_CR4:
2440bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_CR:
2441bdc40630SRasesh Mody *p_speed_mask =
2442bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G |
2443bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G |
2444bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2445bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G |
2446bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_20G |
2447bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2448bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2449bdc40630SRasesh Mody break;
2450bdc40630SRasesh Mody
2451bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_SR:
2452bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_LR:
2453bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_AOC:
2454bdc40630SRasesh Mody *p_speed_mask =
2455bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G |
2456bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2457bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G |
2458bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
2459bdc40630SRasesh Mody break;
2460bdc40630SRasesh Mody
2461bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_XLPPI:
2462bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
2463bdc40630SRasesh Mody break;
2464bdc40630SRasesh Mody
2465bdc40630SRasesh Mody case ETH_TRANSCEIVER_TYPE_10G_BASET:
2466bdc40630SRasesh Mody *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2467bdc40630SRasesh Mody NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2468bdc40630SRasesh Mody break;
2469bdc40630SRasesh Mody
2470bdc40630SRasesh Mody default:
2471bdc40630SRasesh Mody DP_INFO(p_hwfn, "Unknown transcevier type 0x%x\n",
2472bdc40630SRasesh Mody transceiver_type);
2473bdc40630SRasesh Mody *p_speed_mask = 0xff;
2474bdc40630SRasesh Mody break;
2475bdc40630SRasesh Mody }
2476bdc40630SRasesh Mody
2477bdc40630SRasesh Mody return ECORE_SUCCESS;
2478bdc40630SRasesh Mody }
2479bdc40630SRasesh Mody
ecore_mcp_get_board_config(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * p_board_config)2480bdc40630SRasesh Mody enum _ecore_status_t ecore_mcp_get_board_config(struct ecore_hwfn *p_hwfn,
2481bdc40630SRasesh Mody struct ecore_ptt *p_ptt,
2482bdc40630SRasesh Mody u32 *p_board_config)
2483bdc40630SRasesh Mody {
2484bdc40630SRasesh Mody u32 nvm_cfg_addr, nvm_cfg1_offset, port_cfg_addr;
2485bdc40630SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
2486bdc40630SRasesh Mody
2487bdc40630SRasesh Mody /* TODO - Add support for VFs */
2488bdc40630SRasesh Mody if (IS_VF(p_hwfn->p_dev))
2489bdc40630SRasesh Mody return ECORE_INVAL;
2490bdc40630SRasesh Mody
2491bdc40630SRasesh Mody if (!ecore_mcp_is_init(p_hwfn)) {
2492bdc40630SRasesh Mody DP_NOTICE(p_hwfn, false, "MFW is not initialized!\n");
2493bdc40630SRasesh Mody return ECORE_BUSY;
2494bdc40630SRasesh Mody }
2495bdc40630SRasesh Mody if (!p_ptt) {
2496bdc40630SRasesh Mody *p_board_config = NVM_CFG1_PORT_PORT_TYPE_UNDEFINED;
2497bdc40630SRasesh Mody rc = ECORE_INVAL;
2498bdc40630SRasesh Mody } else {
2499bdc40630SRasesh Mody nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt,
2500bdc40630SRasesh Mody MISC_REG_GEN_PURP_CR0);
2501bdc40630SRasesh Mody nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt,
2502bdc40630SRasesh Mody nvm_cfg_addr + 4);
2503bdc40630SRasesh Mody port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2504bdc40630SRasesh Mody offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2505bdc40630SRasesh Mody *p_board_config = ecore_rd(p_hwfn, p_ptt,
2506bdc40630SRasesh Mody port_cfg_addr +
2507bdc40630SRasesh Mody offsetof(struct nvm_cfg1_port,
2508bdc40630SRasesh Mody board_cfg));
2509bdc40630SRasesh Mody }
2510bdc40630SRasesh Mody
2511bdc40630SRasesh Mody return rc;
2512bdc40630SRasesh Mody }
2513bdc40630SRasesh Mody
2514bdf4267dSRasesh Mody /* @DPDK */
2515bdf4267dSRasesh Mody /* Old MFW has a global configuration for all PFs regarding RDMA support */
2516bdf4267dSRasesh Mody static void
ecore_mcp_get_shmem_proto_legacy(struct ecore_hwfn * p_hwfn,enum ecore_pci_personality * p_proto)2517bdf4267dSRasesh Mody ecore_mcp_get_shmem_proto_legacy(struct ecore_hwfn *p_hwfn,
2518bdf4267dSRasesh Mody enum ecore_pci_personality *p_proto)
2519bdf4267dSRasesh Mody {
2520bdf4267dSRasesh Mody *p_proto = ECORE_PCI_ETH;
2521bdf4267dSRasesh Mody
2522bdf4267dSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP,
2523bdf4267dSRasesh Mody "According to Legacy capabilities, L2 personality is %08x\n",
2524bdf4267dSRasesh Mody (u32)*p_proto);
2525bdf4267dSRasesh Mody }
2526bdf4267dSRasesh Mody
2527bdf4267dSRasesh Mody /* @DPDK */
2528bdf4267dSRasesh Mody static enum _ecore_status_t
ecore_mcp_get_shmem_proto_mfw(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_pci_personality * p_proto)2529bdf4267dSRasesh Mody ecore_mcp_get_shmem_proto_mfw(struct ecore_hwfn *p_hwfn,
2530bdf4267dSRasesh Mody struct ecore_ptt *p_ptt,
2531bdf4267dSRasesh Mody enum ecore_pci_personality *p_proto)
2532bdf4267dSRasesh Mody {
2533bdf4267dSRasesh Mody u32 resp = 0, param = 0;
2534bdf4267dSRasesh Mody enum _ecore_status_t rc;
2535bdf4267dSRasesh Mody
2536bdf4267dSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP,
2537bdf4267dSRasesh Mody "According to capabilities, L2 personality is %08x [resp %08x param %08x]\n",
2538bdf4267dSRasesh Mody (u32)*p_proto, resp, param);
2539bdf4267dSRasesh Mody return ECORE_SUCCESS;
2540bdf4267dSRasesh Mody }
2541bdf4267dSRasesh Mody
2542ec94dbc5SRasesh Mody static enum _ecore_status_t
ecore_mcp_get_shmem_proto(struct ecore_hwfn * p_hwfn,struct public_func * p_info,struct ecore_ptt * p_ptt,enum ecore_pci_personality * p_proto)2543ec94dbc5SRasesh Mody ecore_mcp_get_shmem_proto(struct ecore_hwfn *p_hwfn,
2544ec94dbc5SRasesh Mody struct public_func *p_info,
2545bdf4267dSRasesh Mody struct ecore_ptt *p_ptt,
2546ec94dbc5SRasesh Mody enum ecore_pci_personality *p_proto)
2547ec94dbc5SRasesh Mody {
2548ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
2549ec94dbc5SRasesh Mody
2550ec94dbc5SRasesh Mody switch (p_info->config & FUNC_MF_CFG_PROTOCOL_MASK) {
2551ec94dbc5SRasesh Mody case FUNC_MF_CFG_PROTOCOL_ETHERNET:
2552bdf4267dSRasesh Mody if (ecore_mcp_get_shmem_proto_mfw(p_hwfn, p_ptt, p_proto) !=
2553bdf4267dSRasesh Mody ECORE_SUCCESS)
2554bdf4267dSRasesh Mody ecore_mcp_get_shmem_proto_legacy(p_hwfn, p_proto);
2555ec94dbc5SRasesh Mody break;
2556ec94dbc5SRasesh Mody default:
2557ec94dbc5SRasesh Mody rc = ECORE_INVAL;
2558ec94dbc5SRasesh Mody }
2559ec94dbc5SRasesh Mody
2560ec94dbc5SRasesh Mody return rc;
2561ec94dbc5SRasesh Mody }
2562ec94dbc5SRasesh Mody
ecore_mcp_fill_shmem_func_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)2563ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
2564ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
2565ec94dbc5SRasesh Mody {
2566ec94dbc5SRasesh Mody struct ecore_mcp_function_info *info;
2567ec94dbc5SRasesh Mody struct public_func shmem_info;
2568ec94dbc5SRasesh Mody
2569ec94dbc5SRasesh Mody ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
2570ec94dbc5SRasesh Mody info = &p_hwfn->mcp_info->func_info;
2571ec94dbc5SRasesh Mody
2572ec94dbc5SRasesh Mody info->pause_on_host = (shmem_info.config &
2573ec94dbc5SRasesh Mody FUNC_MF_CFG_PAUSE_ON_HOST_RING) ? 1 : 0;
2574ec94dbc5SRasesh Mody
2575bdf4267dSRasesh Mody if (ecore_mcp_get_shmem_proto(p_hwfn, &shmem_info, p_ptt,
2576bdf4267dSRasesh Mody &info->protocol)) {
2577ec94dbc5SRasesh Mody DP_ERR(p_hwfn, "Unknown personality %08x\n",
2578ec94dbc5SRasesh Mody (u32)(shmem_info.config & FUNC_MF_CFG_PROTOCOL_MASK));
2579ec94dbc5SRasesh Mody return ECORE_INVAL;
2580ec94dbc5SRasesh Mody }
2581ec94dbc5SRasesh Mody
2582ec94dbc5SRasesh Mody ecore_read_pf_bandwidth(p_hwfn, &shmem_info);
2583ec94dbc5SRasesh Mody
2584ec94dbc5SRasesh Mody if (shmem_info.mac_upper || shmem_info.mac_lower) {
2585ec94dbc5SRasesh Mody info->mac[0] = (u8)(shmem_info.mac_upper >> 8);
2586ec94dbc5SRasesh Mody info->mac[1] = (u8)(shmem_info.mac_upper);
2587ec94dbc5SRasesh Mody info->mac[2] = (u8)(shmem_info.mac_lower >> 24);
2588ec94dbc5SRasesh Mody info->mac[3] = (u8)(shmem_info.mac_lower >> 16);
2589ec94dbc5SRasesh Mody info->mac[4] = (u8)(shmem_info.mac_lower >> 8);
2590ec94dbc5SRasesh Mody info->mac[5] = (u8)(shmem_info.mac_lower);
2591ec94dbc5SRasesh Mody } else {
2592ec94dbc5SRasesh Mody /* TODO - are there protocols for which there's no MAC? */
2593ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false, "MAC is 0 in shmem\n");
2594ec94dbc5SRasesh Mody }
2595ec94dbc5SRasesh Mody
259622d07d93SRasesh Mody /* TODO - are these calculations true for BE machine? */
259722d07d93SRasesh Mody info->wwn_port = (u64)shmem_info.fcoe_wwn_port_name_upper |
259822d07d93SRasesh Mody (((u64)shmem_info.fcoe_wwn_port_name_lower) << 32);
259922d07d93SRasesh Mody info->wwn_node = (u64)shmem_info.fcoe_wwn_node_name_upper |
260022d07d93SRasesh Mody (((u64)shmem_info.fcoe_wwn_node_name_lower) << 32);
260122d07d93SRasesh Mody
2602ec94dbc5SRasesh Mody info->ovlan = (u16)(shmem_info.ovlan_stag & FUNC_MF_CFG_OV_STAG_MASK);
2603ec94dbc5SRasesh Mody
26045c11b706SRasesh Mody info->mtu = (u16)shmem_info.mtu_size;
26055c11b706SRasesh Mody
26065c11b706SRasesh Mody if (info->mtu == 0)
26075c11b706SRasesh Mody info->mtu = 1500;
26085c11b706SRasesh Mody
26095c11b706SRasesh Mody info->mtu = (u16)shmem_info.mtu_size;
26105c11b706SRasesh Mody
2611ec94dbc5SRasesh Mody DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_IFUP),
2612ec94dbc5SRasesh Mody "Read configuration from shmem: pause_on_host %02x"
2613ec94dbc5SRasesh Mody " protocol %02x BW [%02x - %02x]"
2614*c2c4f87bSAman Deep Singh " MAC " RTE_ETHER_ADDR_PRT_FMT " wwn port %lx"
261522d07d93SRasesh Mody " node %lx ovlan %04x\n",
2616ec94dbc5SRasesh Mody info->pause_on_host, info->protocol,
2617ec94dbc5SRasesh Mody info->bandwidth_min, info->bandwidth_max,
2618ec94dbc5SRasesh Mody info->mac[0], info->mac[1], info->mac[2],
2619ec94dbc5SRasesh Mody info->mac[3], info->mac[4], info->mac[5],
262022d07d93SRasesh Mody (unsigned long)info->wwn_port,
262122d07d93SRasesh Mody (unsigned long)info->wwn_node, info->ovlan);
2622ec94dbc5SRasesh Mody
2623ec94dbc5SRasesh Mody return ECORE_SUCCESS;
2624ec94dbc5SRasesh Mody }
2625ec94dbc5SRasesh Mody
2626ec94dbc5SRasesh Mody struct ecore_mcp_link_params
ecore_mcp_get_link_params(struct ecore_hwfn * p_hwfn)2627ec94dbc5SRasesh Mody *ecore_mcp_get_link_params(struct ecore_hwfn *p_hwfn)
2628ec94dbc5SRasesh Mody {
2629ec94dbc5SRasesh Mody if (!p_hwfn || !p_hwfn->mcp_info)
2630ec94dbc5SRasesh Mody return OSAL_NULL;
2631ec94dbc5SRasesh Mody return &p_hwfn->mcp_info->link_input;
2632ec94dbc5SRasesh Mody }
2633ec94dbc5SRasesh Mody
2634ec94dbc5SRasesh Mody struct ecore_mcp_link_state
ecore_mcp_get_link_state(struct ecore_hwfn * p_hwfn)2635ec94dbc5SRasesh Mody *ecore_mcp_get_link_state(struct ecore_hwfn *p_hwfn)
2636ec94dbc5SRasesh Mody {
2637ec94dbc5SRasesh Mody if (!p_hwfn || !p_hwfn->mcp_info)
2638ec94dbc5SRasesh Mody return OSAL_NULL;
2639ec94dbc5SRasesh Mody
2640ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
2641ec94dbc5SRasesh Mody if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2642ec94dbc5SRasesh Mody DP_INFO(p_hwfn, "Non-ASIC - always notify that link is up\n");
2643ec94dbc5SRasesh Mody p_hwfn->mcp_info->link_output.link_up = true;
2644ec94dbc5SRasesh Mody }
2645ec94dbc5SRasesh Mody #endif
2646ec94dbc5SRasesh Mody
2647ec94dbc5SRasesh Mody return &p_hwfn->mcp_info->link_output;
2648ec94dbc5SRasesh Mody }
2649ec94dbc5SRasesh Mody
2650ec94dbc5SRasesh Mody struct ecore_mcp_link_capabilities
ecore_mcp_get_link_capabilities(struct ecore_hwfn * p_hwfn)2651ec94dbc5SRasesh Mody *ecore_mcp_get_link_capabilities(struct ecore_hwfn *p_hwfn)
2652ec94dbc5SRasesh Mody {
2653ec94dbc5SRasesh Mody if (!p_hwfn || !p_hwfn->mcp_info)
2654ec94dbc5SRasesh Mody return OSAL_NULL;
2655ec94dbc5SRasesh Mody return &p_hwfn->mcp_info->link_capabilities;
2656ec94dbc5SRasesh Mody }
2657ec94dbc5SRasesh Mody
ecore_mcp_drain(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)2658ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_drain(struct ecore_hwfn *p_hwfn,
2659ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
2660ec94dbc5SRasesh Mody {
2661ec94dbc5SRasesh Mody u32 resp = 0, param = 0;
266222d07d93SRasesh Mody enum _ecore_status_t rc;
2663ec94dbc5SRasesh Mody
2664ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt,
266522d07d93SRasesh Mody DRV_MSG_CODE_NIG_DRAIN, 1000, &resp, ¶m);
2666ec94dbc5SRasesh Mody
2667ec94dbc5SRasesh Mody /* Wait for the drain to complete before returning */
266822d07d93SRasesh Mody OSAL_MSLEEP(1020);
2669ec94dbc5SRasesh Mody
2670ec94dbc5SRasesh Mody return rc;
2671ec94dbc5SRasesh Mody }
2672ec94dbc5SRasesh Mody
2673ec94dbc5SRasesh Mody const struct ecore_mcp_function_info
ecore_mcp_get_function_info(struct ecore_hwfn * p_hwfn)2674ec94dbc5SRasesh Mody *ecore_mcp_get_function_info(struct ecore_hwfn *p_hwfn)
2675ec94dbc5SRasesh Mody {
2676ec94dbc5SRasesh Mody if (!p_hwfn || !p_hwfn->mcp_info)
2677ec94dbc5SRasesh Mody return OSAL_NULL;
2678ec94dbc5SRasesh Mody return &p_hwfn->mcp_info->func_info;
2679ec94dbc5SRasesh Mody }
2680ec94dbc5SRasesh Mody
ecore_mcp_get_personality_cnt(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 personalities)2681ec94dbc5SRasesh Mody int ecore_mcp_get_personality_cnt(struct ecore_hwfn *p_hwfn,
2682ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt, u32 personalities)
2683ec94dbc5SRasesh Mody {
2684ec94dbc5SRasesh Mody enum ecore_pci_personality protocol = ECORE_PCI_DEFAULT;
2685ec94dbc5SRasesh Mody struct public_func shmem_info;
2686ec94dbc5SRasesh Mody int i, count = 0, num_pfs;
2687ec94dbc5SRasesh Mody
2688ec94dbc5SRasesh Mody num_pfs = NUM_OF_ENG_PFS(p_hwfn->p_dev);
2689ec94dbc5SRasesh Mody
2690ec94dbc5SRasesh Mody for (i = 0; i < num_pfs; i++) {
2691ec94dbc5SRasesh Mody ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
2692ec94dbc5SRasesh Mody MCP_PF_ID_BY_REL(p_hwfn, i));
2693ec94dbc5SRasesh Mody if (shmem_info.config & FUNC_MF_CFG_FUNC_HIDE)
2694ec94dbc5SRasesh Mody continue;
2695ec94dbc5SRasesh Mody
2696bdf4267dSRasesh Mody if (ecore_mcp_get_shmem_proto(p_hwfn, &shmem_info, p_ptt,
2697bdf4267dSRasesh Mody &protocol) !=
2698bdf4267dSRasesh Mody ECORE_SUCCESS)
2699ec94dbc5SRasesh Mody continue;
2700ec94dbc5SRasesh Mody
2701ec94dbc5SRasesh Mody if ((1 << ((u32)protocol)) & personalities)
2702ec94dbc5SRasesh Mody count++;
2703ec94dbc5SRasesh Mody }
2704ec94dbc5SRasesh Mody
2705ec94dbc5SRasesh Mody return count;
2706ec94dbc5SRasesh Mody }
2707ec94dbc5SRasesh Mody
ecore_mcp_get_flash_size(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * p_flash_size)2708ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_get_flash_size(struct ecore_hwfn *p_hwfn,
2709ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
2710ec94dbc5SRasesh Mody u32 *p_flash_size)
2711ec94dbc5SRasesh Mody {
2712ec94dbc5SRasesh Mody u32 flash_size;
2713ec94dbc5SRasesh Mody
2714ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
27153b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
27163b307c55SRasesh Mody DP_INFO(p_hwfn, "Emulation: Can't get flash size\n");
27173b307c55SRasesh Mody return ECORE_NOTIMPL;
2718ec94dbc5SRasesh Mody }
2719ec94dbc5SRasesh Mody #endif
2720ec94dbc5SRasesh Mody
272186a2265eSRasesh Mody if (IS_VF(p_hwfn->p_dev))
272286a2265eSRasesh Mody return ECORE_INVAL;
272386a2265eSRasesh Mody
2724ec94dbc5SRasesh Mody flash_size = ecore_rd(p_hwfn, p_ptt, MCP_REG_NVM_CFG4);
2725ec94dbc5SRasesh Mody flash_size = (flash_size & MCP_REG_NVM_CFG4_FLASH_SIZE) >>
2726ec94dbc5SRasesh Mody MCP_REG_NVM_CFG4_FLASH_SIZE_SHIFT;
272704b00049SRasesh Mody flash_size = (1 << (flash_size + MCP_BYTES_PER_MBIT_OFFSET));
2728ec94dbc5SRasesh Mody
2729ec94dbc5SRasesh Mody *p_flash_size = flash_size;
2730ec94dbc5SRasesh Mody
2731ec94dbc5SRasesh Mody return ECORE_SUCCESS;
2732ec94dbc5SRasesh Mody }
2733ec94dbc5SRasesh Mody
ecore_start_recovery_process(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)2734ec94dbc5SRasesh Mody enum _ecore_status_t ecore_start_recovery_process(struct ecore_hwfn *p_hwfn,
2735ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
2736ec94dbc5SRasesh Mody {
2737ec94dbc5SRasesh Mody struct ecore_dev *p_dev = p_hwfn->p_dev;
2738ec94dbc5SRasesh Mody
2739ec94dbc5SRasesh Mody if (p_dev->recov_in_prog) {
2740ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false,
2741ec94dbc5SRasesh Mody "Avoid triggering a recovery since such a process"
2742ec94dbc5SRasesh Mody " is already in progress\n");
2743ec94dbc5SRasesh Mody return ECORE_AGAIN;
2744ec94dbc5SRasesh Mody }
2745ec94dbc5SRasesh Mody
2746ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, false, "Triggering a recovery process\n");
2747ec94dbc5SRasesh Mody ecore_wr(p_hwfn, p_ptt, MISC_REG_AEU_GENERAL_ATTN_35, 0x1);
2748ec94dbc5SRasesh Mody
2749ec94dbc5SRasesh Mody return ECORE_SUCCESS;
2750ec94dbc5SRasesh Mody }
2751ec94dbc5SRasesh Mody
2752cb051eb2SRasesh Mody static enum _ecore_status_t
ecore_mcp_config_vf_msix_bb(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 vf_id,u8 num)2753cb051eb2SRasesh Mody ecore_mcp_config_vf_msix_bb(struct ecore_hwfn *p_hwfn,
2754ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
2755ec94dbc5SRasesh Mody u8 vf_id, u8 num)
2756ec94dbc5SRasesh Mody {
2757ec94dbc5SRasesh Mody u32 resp = 0, param = 0, rc_param = 0;
2758ec94dbc5SRasesh Mody enum _ecore_status_t rc;
2759ec94dbc5SRasesh Mody
276022d07d93SRasesh Mody /* Only Leader can configure MSIX, and need to take CMT into account */
276122d07d93SRasesh Mody
276222d07d93SRasesh Mody if (!IS_LEAD_HWFN(p_hwfn))
276322d07d93SRasesh Mody return ECORE_SUCCESS;
276422d07d93SRasesh Mody num *= p_hwfn->p_dev->num_hwfns;
276522d07d93SRasesh Mody
276604b00049SRasesh Mody param |= (vf_id << DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_OFFSET) &
2767ec94dbc5SRasesh Mody DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_MASK;
276804b00049SRasesh Mody param |= (num << DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_OFFSET) &
2769ec94dbc5SRasesh Mody DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_MASK;
2770ec94dbc5SRasesh Mody
2771ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_VF_MSIX, param,
2772ec94dbc5SRasesh Mody &resp, &rc_param);
2773ec94dbc5SRasesh Mody
2774ec94dbc5SRasesh Mody if (resp != FW_MSG_CODE_DRV_CFG_VF_MSIX_DONE) {
2775ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, true, "VF[%d]: MFW failed to set MSI-X\n",
2776ec94dbc5SRasesh Mody vf_id);
2777ec94dbc5SRasesh Mody rc = ECORE_INVAL;
277822d07d93SRasesh Mody } else {
277922d07d93SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
278022d07d93SRasesh Mody "Requested 0x%02x MSI-x interrupts from VF 0x%02x\n",
278122d07d93SRasesh Mody num, vf_id);
2782ec94dbc5SRasesh Mody }
2783ec94dbc5SRasesh Mody
2784ec94dbc5SRasesh Mody return rc;
2785ec94dbc5SRasesh Mody }
2786ec94dbc5SRasesh Mody
2787cb051eb2SRasesh Mody static enum _ecore_status_t
ecore_mcp_config_vf_msix_ah(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 num)2788cb051eb2SRasesh Mody ecore_mcp_config_vf_msix_ah(struct ecore_hwfn *p_hwfn,
2789cb051eb2SRasesh Mody struct ecore_ptt *p_ptt,
2790cb051eb2SRasesh Mody u8 num)
2791cb051eb2SRasesh Mody {
2792cb051eb2SRasesh Mody u32 resp = 0, param = num, rc_param = 0;
2793cb051eb2SRasesh Mody enum _ecore_status_t rc;
2794cb051eb2SRasesh Mody
2795cb051eb2SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_PF_VFS_MSIX,
2796cb051eb2SRasesh Mody param, &resp, &rc_param);
2797cb051eb2SRasesh Mody
2798cb051eb2SRasesh Mody if (resp != FW_MSG_CODE_DRV_CFG_PF_VFS_MSIX_DONE) {
2799cb051eb2SRasesh Mody DP_NOTICE(p_hwfn, true, "MFW failed to set MSI-X for VFs\n");
2800cb051eb2SRasesh Mody rc = ECORE_INVAL;
2801cb051eb2SRasesh Mody } else {
2802cb051eb2SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2803cb051eb2SRasesh Mody "Requested 0x%02x MSI-x interrupts for VFs\n",
2804cb051eb2SRasesh Mody num);
2805cb051eb2SRasesh Mody }
2806cb051eb2SRasesh Mody
2807cb051eb2SRasesh Mody return rc;
2808cb051eb2SRasesh Mody }
2809cb051eb2SRasesh Mody
ecore_mcp_config_vf_msix(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 vf_id,u8 num)2810cb051eb2SRasesh Mody enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
2811cb051eb2SRasesh Mody struct ecore_ptt *p_ptt,
2812cb051eb2SRasesh Mody u8 vf_id, u8 num)
2813cb051eb2SRasesh Mody {
28143b307c55SRasesh Mody #ifndef ASIC_ONLY
28153b307c55SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
28163b307c55SRasesh Mody DP_INFO(p_hwfn,
28173b307c55SRasesh Mody "Emulation: Avoid sending the %s mailbox command\n",
28183b307c55SRasesh Mody ECORE_IS_BB(p_hwfn->p_dev) ? "CFG_VF_MSIX" :
28193b307c55SRasesh Mody "CFG_PF_VFS_MSIX");
28203b307c55SRasesh Mody return ECORE_SUCCESS;
28213b307c55SRasesh Mody }
28223b307c55SRasesh Mody #endif
28233b307c55SRasesh Mody
2824cb051eb2SRasesh Mody if (ECORE_IS_BB(p_hwfn->p_dev))
2825cb051eb2SRasesh Mody return ecore_mcp_config_vf_msix_bb(p_hwfn, p_ptt, vf_id, num);
2826cb051eb2SRasesh Mody else
2827cb051eb2SRasesh Mody return ecore_mcp_config_vf_msix_ah(p_hwfn, p_ptt, num);
2828cb051eb2SRasesh Mody }
2829cb051eb2SRasesh Mody
2830ec94dbc5SRasesh Mody enum _ecore_status_t
ecore_mcp_send_drv_version(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_drv_version * p_ver)2831ec94dbc5SRasesh Mody ecore_mcp_send_drv_version(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
2832ec94dbc5SRasesh Mody struct ecore_mcp_drv_version *p_ver)
2833ec94dbc5SRasesh Mody {
2834ffdd0599SHarish Patil struct ecore_mcp_mb_params mb_params;
2835e32dc0f7SRasesh Mody struct drv_version_stc drv_version;
283622d07d93SRasesh Mody u32 num_words, i;
2837ec94dbc5SRasesh Mody void *p_name;
2838ec94dbc5SRasesh Mody OSAL_BE32 val;
2839ec94dbc5SRasesh Mody enum _ecore_status_t rc;
2840ec94dbc5SRasesh Mody
2841ec94dbc5SRasesh Mody #ifndef ASIC_ONLY
2842ec94dbc5SRasesh Mody if (CHIP_REV_IS_SLOW(p_hwfn->p_dev))
2843ec94dbc5SRasesh Mody return ECORE_SUCCESS;
2844ec94dbc5SRasesh Mody #endif
2845ec94dbc5SRasesh Mody
2846e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&drv_version, sizeof(drv_version));
2847e32dc0f7SRasesh Mody drv_version.version = p_ver->version;
2848ec94dbc5SRasesh Mody num_words = (MCP_DRV_VER_STR_SIZE - 4) / 4;
2849ec94dbc5SRasesh Mody for (i = 0; i < num_words; i++) {
28505c66fd85SRasesh Mody /* The driver name is expected to be in a big-endian format */
2851ec94dbc5SRasesh Mody p_name = &p_ver->name[i * sizeof(u32)];
2852ec94dbc5SRasesh Mody val = OSAL_CPU_TO_BE32(*(u32 *)p_name);
2853e32dc0f7SRasesh Mody *(u32 *)&drv_version.name[i * sizeof(u32)] = val;
2854ec94dbc5SRasesh Mody }
2855ec94dbc5SRasesh Mody
2856ffdd0599SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
2857ffdd0599SHarish Patil mb_params.cmd = DRV_MSG_CODE_SET_VERSION;
2858e32dc0f7SRasesh Mody mb_params.p_data_src = &drv_version;
2859e32dc0f7SRasesh Mody mb_params.data_src_size = sizeof(drv_version);
2860ffdd0599SHarish Patil rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
2861ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS)
2862ec94dbc5SRasesh Mody DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2863ec94dbc5SRasesh Mody
2864ec94dbc5SRasesh Mody return rc;
2865ec94dbc5SRasesh Mody }
2866ec94dbc5SRasesh Mody
2867a474d1c1SRasesh Mody /* A maximal 100 msec waiting time for the MCP to halt */
2868a474d1c1SRasesh Mody #define ECORE_MCP_HALT_SLEEP_MS 10
2869a474d1c1SRasesh Mody #define ECORE_MCP_HALT_MAX_RETRIES 10
2870a474d1c1SRasesh Mody
ecore_mcp_halt(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)2871ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
2872ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
2873ec94dbc5SRasesh Mody {
2874a474d1c1SRasesh Mody u32 resp = 0, param = 0, cpu_state, cnt = 0;
2875ec94dbc5SRasesh Mody enum _ecore_status_t rc;
2876ec94dbc5SRasesh Mody
2877ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MCP_HALT, 0, &resp,
2878ec94dbc5SRasesh Mody ¶m);
2879a474d1c1SRasesh Mody if (rc != ECORE_SUCCESS) {
2880ec94dbc5SRasesh Mody DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2881ec94dbc5SRasesh Mody return rc;
2882ec94dbc5SRasesh Mody }
2883ec94dbc5SRasesh Mody
2884a474d1c1SRasesh Mody do {
2885a474d1c1SRasesh Mody OSAL_MSLEEP(ECORE_MCP_HALT_SLEEP_MS);
2886a474d1c1SRasesh Mody cpu_state = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2887a474d1c1SRasesh Mody if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED)
2888a474d1c1SRasesh Mody break;
2889a474d1c1SRasesh Mody } while (++cnt < ECORE_MCP_HALT_MAX_RETRIES);
2890a474d1c1SRasesh Mody
2891a474d1c1SRasesh Mody if (cnt == ECORE_MCP_HALT_MAX_RETRIES) {
2892a474d1c1SRasesh Mody DP_NOTICE(p_hwfn, false,
2893a474d1c1SRasesh Mody "Failed to halt the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2894a474d1c1SRasesh Mody ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE), cpu_state);
2895a474d1c1SRasesh Mody return ECORE_BUSY;
2896a474d1c1SRasesh Mody }
2897a474d1c1SRasesh Mody
2898a474d1c1SRasesh Mody ecore_mcp_cmd_set_blocking(p_hwfn, true);
2899a474d1c1SRasesh Mody
2900a474d1c1SRasesh Mody return ECORE_SUCCESS;
2901a474d1c1SRasesh Mody }
2902a474d1c1SRasesh Mody
2903a474d1c1SRasesh Mody #define ECORE_MCP_RESUME_SLEEP_MS 10
2904a474d1c1SRasesh Mody
ecore_mcp_resume(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)2905ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
2906ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt)
2907ec94dbc5SRasesh Mody {
2908a474d1c1SRasesh Mody u32 cpu_mode, cpu_state;
2909ec94dbc5SRasesh Mody
2910ec94dbc5SRasesh Mody ecore_wr(p_hwfn, p_ptt, MCP_REG_CPU_STATE, 0xffffffff);
2911ec94dbc5SRasesh Mody
2912ec94dbc5SRasesh Mody cpu_mode = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
2913a474d1c1SRasesh Mody cpu_mode &= ~MCP_REG_CPU_MODE_SOFT_HALT;
2914a474d1c1SRasesh Mody ecore_wr(p_hwfn, p_ptt, MCP_REG_CPU_MODE, cpu_mode);
2915ec94dbc5SRasesh Mody
2916a474d1c1SRasesh Mody OSAL_MSLEEP(ECORE_MCP_RESUME_SLEEP_MS);
2917a474d1c1SRasesh Mody cpu_state = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2918a474d1c1SRasesh Mody
2919a474d1c1SRasesh Mody if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED) {
2920a474d1c1SRasesh Mody DP_NOTICE(p_hwfn, false,
2921a474d1c1SRasesh Mody "Failed to resume the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2922a474d1c1SRasesh Mody cpu_mode, cpu_state);
2923a474d1c1SRasesh Mody return ECORE_BUSY;
2924a474d1c1SRasesh Mody }
2925a474d1c1SRasesh Mody
2926a474d1c1SRasesh Mody ecore_mcp_cmd_set_blocking(p_hwfn, false);
2927a474d1c1SRasesh Mody
2928a474d1c1SRasesh Mody return ECORE_SUCCESS;
2929ec94dbc5SRasesh Mody }
2930ec94dbc5SRasesh Mody
2931ec94dbc5SRasesh Mody enum _ecore_status_t
ecore_mcp_ov_update_current_config(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_ov_client client)2932ec94dbc5SRasesh Mody ecore_mcp_ov_update_current_config(struct ecore_hwfn *p_hwfn,
2933ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
2934ec94dbc5SRasesh Mody enum ecore_ov_client client)
2935ec94dbc5SRasesh Mody {
2936ec94dbc5SRasesh Mody u32 resp = 0, param = 0;
2937ec94dbc5SRasesh Mody u32 drv_mb_param;
2938c68f27a2SRasesh Mody enum _ecore_status_t rc;
2939ec94dbc5SRasesh Mody
2940bb42c23bSRasesh Mody switch (client) {
2941ec94dbc5SRasesh Mody case ECORE_OV_CLIENT_DRV:
2942ec94dbc5SRasesh Mody drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OS;
2943ec94dbc5SRasesh Mody break;
2944ec94dbc5SRasesh Mody case ECORE_OV_CLIENT_USER:
2945ec94dbc5SRasesh Mody drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OTHER;
2946ec94dbc5SRasesh Mody break;
29473ca097bbSRasesh Mody case ECORE_OV_CLIENT_VENDOR_SPEC:
29483ca097bbSRasesh Mody drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_VENDOR_SPEC;
29493ca097bbSRasesh Mody break;
2950ec94dbc5SRasesh Mody default:
2951bb42c23bSRasesh Mody DP_NOTICE(p_hwfn, true, "Invalid client type %d\n", client);
2952ec94dbc5SRasesh Mody return ECORE_INVAL;
2953ec94dbc5SRasesh Mody }
2954ec94dbc5SRasesh Mody
2955ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_CURR_CFG,
2956ec94dbc5SRasesh Mody drv_mb_param, &resp, ¶m);
2957ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS)
2958ec94dbc5SRasesh Mody DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2959ec94dbc5SRasesh Mody
2960ec94dbc5SRasesh Mody return rc;
2961ec94dbc5SRasesh Mody }
2962ec94dbc5SRasesh Mody
2963ec94dbc5SRasesh Mody enum _ecore_status_t
ecore_mcp_ov_update_driver_state(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_ov_driver_state drv_state)2964ec94dbc5SRasesh Mody ecore_mcp_ov_update_driver_state(struct ecore_hwfn *p_hwfn,
2965ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
2966ec94dbc5SRasesh Mody enum ecore_ov_driver_state drv_state)
2967ec94dbc5SRasesh Mody {
2968ec94dbc5SRasesh Mody u32 resp = 0, param = 0;
2969ec94dbc5SRasesh Mody u32 drv_mb_param;
2970c68f27a2SRasesh Mody enum _ecore_status_t rc;
2971ec94dbc5SRasesh Mody
2972ec94dbc5SRasesh Mody switch (drv_state) {
2973ec94dbc5SRasesh Mody case ECORE_OV_DRIVER_STATE_NOT_LOADED:
2974ec94dbc5SRasesh Mody drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_NOT_LOADED;
2975ec94dbc5SRasesh Mody break;
2976ec94dbc5SRasesh Mody case ECORE_OV_DRIVER_STATE_DISABLED:
2977ec94dbc5SRasesh Mody drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_DISABLED;
2978ec94dbc5SRasesh Mody break;
2979ec94dbc5SRasesh Mody case ECORE_OV_DRIVER_STATE_ACTIVE:
2980ec94dbc5SRasesh Mody drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_ACTIVE;
2981ec94dbc5SRasesh Mody break;
2982ec94dbc5SRasesh Mody default:
2983ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, true, "Invalid driver state %d\n", drv_state);
2984ec94dbc5SRasesh Mody return ECORE_INVAL;
2985ec94dbc5SRasesh Mody }
2986ec94dbc5SRasesh Mody
2987ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE,
29883ca097bbSRasesh Mody drv_mb_param, &resp, ¶m);
2989ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS)
29903ca097bbSRasesh Mody DP_ERR(p_hwfn, "Failed to send driver state\n");
2991ec94dbc5SRasesh Mody
2992ec94dbc5SRasesh Mody return rc;
2993ec94dbc5SRasesh Mody }
2994ec94dbc5SRasesh Mody
2995ec94dbc5SRasesh Mody enum _ecore_status_t
ecore_mcp_ov_get_fc_npiv(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_fc_npiv_tbl * p_table)2996ec94dbc5SRasesh Mody ecore_mcp_ov_get_fc_npiv(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
2997ec94dbc5SRasesh Mody struct ecore_fc_npiv_tbl *p_table)
2998ec94dbc5SRasesh Mody {
2999ec94dbc5SRasesh Mody return 0;
3000ec94dbc5SRasesh Mody }
3001ec94dbc5SRasesh Mody
3002ec94dbc5SRasesh Mody enum _ecore_status_t
ecore_mcp_ov_update_mtu(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 mtu)3003ebbc55b8SRasesh Mody ecore_mcp_ov_update_mtu(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3004ebbc55b8SRasesh Mody u16 mtu)
3005ec94dbc5SRasesh Mody {
3006ebbc55b8SRasesh Mody u32 resp = 0, param = 0, drv_mb_param = 0;
3007ebbc55b8SRasesh Mody enum _ecore_status_t rc;
3008ebbc55b8SRasesh Mody
3009ebbc55b8SRasesh Mody SET_MFW_FIELD(drv_mb_param, DRV_MB_PARAM_OV_MTU_SIZE, (u32)mtu);
3010ebbc55b8SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_MTU,
3011ebbc55b8SRasesh Mody drv_mb_param, &resp, ¶m);
3012ebbc55b8SRasesh Mody if (rc != ECORE_SUCCESS)
3013ebbc55b8SRasesh Mody DP_ERR(p_hwfn, "Failed to send mtu value, rc = %d\n", rc);
3014ebbc55b8SRasesh Mody
3015ebbc55b8SRasesh Mody return rc;
3016ebbc55b8SRasesh Mody }
3017ebbc55b8SRasesh Mody
3018ebbc55b8SRasesh Mody enum _ecore_status_t
ecore_mcp_ov_update_mac(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u8 * mac)3019ebbc55b8SRasesh Mody ecore_mcp_ov_update_mac(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3020ebbc55b8SRasesh Mody u8 *mac)
3021ebbc55b8SRasesh Mody {
3022ebbc55b8SRasesh Mody struct ecore_mcp_mb_params mb_params;
3023ebbc55b8SRasesh Mody union drv_union_data union_data;
3024ebbc55b8SRasesh Mody enum _ecore_status_t rc;
3025ebbc55b8SRasesh Mody
3026ebbc55b8SRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
3027ebbc55b8SRasesh Mody mb_params.cmd = DRV_MSG_CODE_SET_VMAC;
3028ebbc55b8SRasesh Mody SET_MFW_FIELD(mb_params.param, DRV_MSG_CODE_VMAC_TYPE,
3029ebbc55b8SRasesh Mody DRV_MSG_CODE_VMAC_TYPE_MAC);
3030ebbc55b8SRasesh Mody mb_params.param |= MCP_PF_ID(p_hwfn);
3031ebbc55b8SRasesh Mody OSAL_MEMCPY(&union_data.raw_data, mac, ETH_ALEN);
3032ebbc55b8SRasesh Mody mb_params.p_data_src = &union_data;
3033ebbc55b8SRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
3034ebbc55b8SRasesh Mody if (rc != ECORE_SUCCESS)
3035ebbc55b8SRasesh Mody DP_ERR(p_hwfn, "Failed to send mac address, rc = %d\n", rc);
3036ebbc55b8SRasesh Mody
3037ebbc55b8SRasesh Mody return rc;
3038ebbc55b8SRasesh Mody }
3039ebbc55b8SRasesh Mody
3040ebbc55b8SRasesh Mody enum _ecore_status_t
ecore_mcp_ov_update_eswitch(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_ov_eswitch eswitch)3041ebbc55b8SRasesh Mody ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3042ebbc55b8SRasesh Mody enum ecore_ov_eswitch eswitch)
3043ebbc55b8SRasesh Mody {
3044ebbc55b8SRasesh Mody enum _ecore_status_t rc;
3045ebbc55b8SRasesh Mody u32 resp = 0, param = 0;
3046ebbc55b8SRasesh Mody u32 drv_mb_param;
3047ebbc55b8SRasesh Mody
3048ebbc55b8SRasesh Mody switch (eswitch) {
3049ebbc55b8SRasesh Mody case ECORE_OV_ESWITCH_NONE:
3050ebbc55b8SRasesh Mody drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_NONE;
3051ebbc55b8SRasesh Mody break;
3052ebbc55b8SRasesh Mody case ECORE_OV_ESWITCH_VEB:
3053ebbc55b8SRasesh Mody drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEB;
3054ebbc55b8SRasesh Mody break;
3055ebbc55b8SRasesh Mody case ECORE_OV_ESWITCH_VEPA:
3056ebbc55b8SRasesh Mody drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEPA;
3057ebbc55b8SRasesh Mody break;
3058ebbc55b8SRasesh Mody default:
3059ebbc55b8SRasesh Mody DP_ERR(p_hwfn, "Invalid eswitch mode %d\n", eswitch);
3060ebbc55b8SRasesh Mody return ECORE_INVAL;
3061ebbc55b8SRasesh Mody }
3062ebbc55b8SRasesh Mody
3063ebbc55b8SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_ESWITCH_MODE,
3064ebbc55b8SRasesh Mody drv_mb_param, &resp, ¶m);
3065ebbc55b8SRasesh Mody if (rc != ECORE_SUCCESS)
3066ebbc55b8SRasesh Mody DP_ERR(p_hwfn, "Failed to send eswitch mode, rc = %d\n", rc);
3067ebbc55b8SRasesh Mody
3068ebbc55b8SRasesh Mody return rc;
3069ec94dbc5SRasesh Mody }
3070ec94dbc5SRasesh Mody
ecore_mcp_set_led(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_led_mode mode)3071ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_set_led(struct ecore_hwfn *p_hwfn,
3072ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
3073ec94dbc5SRasesh Mody enum ecore_led_mode mode)
3074ec94dbc5SRasesh Mody {
3075ec94dbc5SRasesh Mody u32 resp = 0, param = 0, drv_mb_param;
3076ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3077ec94dbc5SRasesh Mody
3078ec94dbc5SRasesh Mody switch (mode) {
3079ec94dbc5SRasesh Mody case ECORE_LED_MODE_ON:
3080ec94dbc5SRasesh Mody drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_ON;
3081ec94dbc5SRasesh Mody break;
3082ec94dbc5SRasesh Mody case ECORE_LED_MODE_OFF:
3083ec94dbc5SRasesh Mody drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OFF;
3084ec94dbc5SRasesh Mody break;
3085ec94dbc5SRasesh Mody case ECORE_LED_MODE_RESTORE:
3086ec94dbc5SRasesh Mody drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OPER;
3087ec94dbc5SRasesh Mody break;
3088ec94dbc5SRasesh Mody default:
3089ec94dbc5SRasesh Mody DP_NOTICE(p_hwfn, true, "Invalid LED mode %d\n", mode);
3090ec94dbc5SRasesh Mody return ECORE_INVAL;
3091ec94dbc5SRasesh Mody }
3092ec94dbc5SRasesh Mody
3093ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LED_MODE,
3094ec94dbc5SRasesh Mody drv_mb_param, &resp, ¶m);
3095ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS)
3096ec94dbc5SRasesh Mody DP_ERR(p_hwfn, "MCP response failure, aborting\n");
3097ec94dbc5SRasesh Mody
3098ec94dbc5SRasesh Mody return rc;
3099ec94dbc5SRasesh Mody }
3100ec94dbc5SRasesh Mody
ecore_mcp_mask_parities(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 mask_parities)3101ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
3102ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
3103ec94dbc5SRasesh Mody u32 mask_parities)
3104ec94dbc5SRasesh Mody {
3105ec94dbc5SRasesh Mody u32 resp = 0, param = 0;
3106a064d7d2SRasesh Mody enum _ecore_status_t rc;
3107ec94dbc5SRasesh Mody
3108ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MASK_PARITIES,
3109ec94dbc5SRasesh Mody mask_parities, &resp, ¶m);
3110ec94dbc5SRasesh Mody
3111ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS) {
3112ec94dbc5SRasesh Mody DP_ERR(p_hwfn,
3113ec94dbc5SRasesh Mody "MCP response failure for mask parities, aborting\n");
3114ec94dbc5SRasesh Mody } else if (resp != FW_MSG_CODE_OK) {
3115ec94dbc5SRasesh Mody DP_ERR(p_hwfn,
3116ec94dbc5SRasesh Mody "MCP did not ack mask parity request. Old MFW?\n");
3117ec94dbc5SRasesh Mody rc = ECORE_INVAL;
3118ec94dbc5SRasesh Mody }
3119ec94dbc5SRasesh Mody
3120ec94dbc5SRasesh Mody return rc;
3121ec94dbc5SRasesh Mody }
3122ec94dbc5SRasesh Mody
ecore_mcp_nvm_read(struct ecore_dev * p_dev,u32 addr,u8 * p_buf,u32 len)3123ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_read(struct ecore_dev *p_dev, u32 addr,
3124ec94dbc5SRasesh Mody u8 *p_buf, u32 len)
3125ec94dbc5SRasesh Mody {
3126ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3127ec94dbc5SRasesh Mody u32 bytes_left, offset, bytes_to_copy, buf_size;
31282292589aSRasesh Mody u32 nvm_offset, resp, param;
3129ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
3130ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
3131ec94dbc5SRasesh Mody
3132ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3133ec94dbc5SRasesh Mody if (!p_ptt)
3134ec94dbc5SRasesh Mody return ECORE_BUSY;
3135ec94dbc5SRasesh Mody
3136ec94dbc5SRasesh Mody bytes_left = len;
3137ec94dbc5SRasesh Mody offset = 0;
3138ec94dbc5SRasesh Mody while (bytes_left > 0) {
3139ec94dbc5SRasesh Mody bytes_to_copy = OSAL_MIN_T(u32, bytes_left,
3140ec94dbc5SRasesh Mody MCP_DRV_NVM_BUF_LEN);
31412292589aSRasesh Mody nvm_offset = (addr + offset) | (bytes_to_copy <<
314204b00049SRasesh Mody DRV_MB_PARAM_NVM_LEN_OFFSET);
31432292589aSRasesh Mody rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
31442292589aSRasesh Mody DRV_MSG_CODE_NVM_READ_NVRAM,
31452292589aSRasesh Mody nvm_offset, &resp, ¶m, &buf_size,
31462292589aSRasesh Mody (u32 *)(p_buf + offset));
31472292589aSRasesh Mody if (rc != ECORE_SUCCESS) {
31482292589aSRasesh Mody DP_NOTICE(p_dev, false,
31492292589aSRasesh Mody "ecore_mcp_nvm_rd_cmd() failed, rc = %d\n",
31502292589aSRasesh Mody rc);
31512292589aSRasesh Mody resp = FW_MSG_CODE_ERROR;
31522292589aSRasesh Mody break;
31532292589aSRasesh Mody }
31542292589aSRasesh Mody
31552292589aSRasesh Mody if (resp != FW_MSG_CODE_NVM_OK) {
31562292589aSRasesh Mody DP_NOTICE(p_dev, false,
31572292589aSRasesh Mody "nvm read failed, resp = 0x%08x\n", resp);
31582292589aSRasesh Mody rc = ECORE_UNKNOWN_ERROR;
3159ec94dbc5SRasesh Mody break;
3160ec94dbc5SRasesh Mody }
316122d07d93SRasesh Mody
316222d07d93SRasesh Mody /* This can be a lengthy process, and it's possible scheduler
316322d07d93SRasesh Mody * isn't preemptible. Sleep a bit to prevent CPU hogging.
316422d07d93SRasesh Mody */
316522d07d93SRasesh Mody if (bytes_left % 0x1000 <
31662292589aSRasesh Mody (bytes_left - buf_size) % 0x1000)
316722d07d93SRasesh Mody OSAL_MSLEEP(1);
316822d07d93SRasesh Mody
31692292589aSRasesh Mody offset += buf_size;
31702292589aSRasesh Mody bytes_left -= buf_size;
3171ec94dbc5SRasesh Mody }
3172ec94dbc5SRasesh Mody
31732292589aSRasesh Mody p_dev->mcp_nvm_resp = resp;
3174ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3175ec94dbc5SRasesh Mody
3176ec94dbc5SRasesh Mody return rc;
3177ec94dbc5SRasesh Mody }
3178ec94dbc5SRasesh Mody
ecore_mcp_phy_read(struct ecore_dev * p_dev,u32 cmd,u32 addr,u8 * p_buf,u32 * p_len)3179ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_phy_read(struct ecore_dev *p_dev, u32 cmd,
3180979582a1SRasesh Mody u32 addr, u8 *p_buf, u32 *p_len)
3181ec94dbc5SRasesh Mody {
3182ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3183ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
31849ed26bc7SRasesh Mody u32 resp = 0, param;
3185ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3186ec94dbc5SRasesh Mody
3187ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3188ec94dbc5SRasesh Mody if (!p_ptt)
3189ec94dbc5SRasesh Mody return ECORE_BUSY;
3190ec94dbc5SRasesh Mody
31912292589aSRasesh Mody rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
31922292589aSRasesh Mody (cmd == ECORE_PHY_CORE_READ) ?
31932292589aSRasesh Mody DRV_MSG_CODE_PHY_CORE_READ :
31942292589aSRasesh Mody DRV_MSG_CODE_PHY_RAW_READ,
3195979582a1SRasesh Mody addr, &resp, ¶m, p_len, (u32 *)p_buf);
3196ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS)
3197ec94dbc5SRasesh Mody DP_NOTICE(p_dev, false, "MCP command rc = %d\n", rc);
3198ec94dbc5SRasesh Mody
31992292589aSRasesh Mody p_dev->mcp_nvm_resp = resp;
3200ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3201ec94dbc5SRasesh Mody
3202ec94dbc5SRasesh Mody return rc;
3203ec94dbc5SRasesh Mody }
3204ec94dbc5SRasesh Mody
ecore_mcp_nvm_resp(struct ecore_dev * p_dev,u8 * p_buf)3205ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_resp(struct ecore_dev *p_dev, u8 *p_buf)
3206ec94dbc5SRasesh Mody {
3207ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3208ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
3209ec94dbc5SRasesh Mody
3210ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3211ec94dbc5SRasesh Mody if (!p_ptt)
3212ec94dbc5SRasesh Mody return ECORE_BUSY;
3213ec94dbc5SRasesh Mody
3214ec94dbc5SRasesh Mody OSAL_MEMCPY(p_buf, &p_dev->mcp_nvm_resp, sizeof(p_dev->mcp_nvm_resp));
3215ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3216ec94dbc5SRasesh Mody
3217ec94dbc5SRasesh Mody return ECORE_SUCCESS;
3218ec94dbc5SRasesh Mody }
3219ec94dbc5SRasesh Mody
ecore_mcp_nvm_del_file(struct ecore_dev * p_dev,u32 addr)3220ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_del_file(struct ecore_dev *p_dev, u32 addr)
3221ec94dbc5SRasesh Mody {
3222ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3223ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
32249ed26bc7SRasesh Mody u32 resp = 0, param;
3225ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3226ec94dbc5SRasesh Mody
3227ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3228ec94dbc5SRasesh Mody if (!p_ptt)
3229ec94dbc5SRasesh Mody return ECORE_BUSY;
32302292589aSRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_NVM_DEL_FILE, addr,
32312292589aSRasesh Mody &resp, ¶m);
32322292589aSRasesh Mody p_dev->mcp_nvm_resp = resp;
3233ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3234ec94dbc5SRasesh Mody
3235ec94dbc5SRasesh Mody return rc;
3236ec94dbc5SRasesh Mody }
3237ec94dbc5SRasesh Mody
ecore_mcp_nvm_put_file_begin(struct ecore_dev * p_dev,u32 addr)3238ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_put_file_begin(struct ecore_dev *p_dev,
3239ec94dbc5SRasesh Mody u32 addr)
3240ec94dbc5SRasesh Mody {
3241ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3242ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
32439ed26bc7SRasesh Mody u32 resp = 0, param;
3244ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3245ec94dbc5SRasesh Mody
3246ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3247ec94dbc5SRasesh Mody if (!p_ptt)
3248ec94dbc5SRasesh Mody return ECORE_BUSY;
32492292589aSRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_NVM_PUT_FILE_BEGIN, addr,
32502292589aSRasesh Mody &resp, ¶m);
32512292589aSRasesh Mody p_dev->mcp_nvm_resp = resp;
3252ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3253ec94dbc5SRasesh Mody
3254ec94dbc5SRasesh Mody return rc;
3255ec94dbc5SRasesh Mody }
3256ec94dbc5SRasesh Mody
3257ec94dbc5SRasesh Mody /* rc receives ECORE_INVAL as default parameter because
3258ec94dbc5SRasesh Mody * it might not enter the while loop if the len is 0
3259ec94dbc5SRasesh Mody */
ecore_mcp_nvm_write(struct ecore_dev * p_dev,u32 cmd,u32 addr,u8 * p_buf,u32 len)3260ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_write(struct ecore_dev *p_dev, u32 cmd,
3261ec94dbc5SRasesh Mody u32 addr, u8 *p_buf, u32 len)
3262ec94dbc5SRasesh Mody {
3263db8af647SAndrzej Ostruszka u32 buf_idx, buf_size, nvm_cmd, nvm_offset;
3264db8af647SAndrzej Ostruszka u32 resp = FW_MSG_CODE_ERROR, param;
3265ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3266ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_INVAL;
3267ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
3268ec94dbc5SRasesh Mody
3269ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3270ec94dbc5SRasesh Mody if (!p_ptt)
3271ec94dbc5SRasesh Mody return ECORE_BUSY;
3272ec94dbc5SRasesh Mody
32732292589aSRasesh Mody switch (cmd) {
32742292589aSRasesh Mody case ECORE_PUT_FILE_DATA:
32752292589aSRasesh Mody nvm_cmd = DRV_MSG_CODE_NVM_PUT_FILE_DATA;
32762292589aSRasesh Mody break;
32772292589aSRasesh Mody case ECORE_NVM_WRITE_NVRAM:
32782292589aSRasesh Mody nvm_cmd = DRV_MSG_CODE_NVM_WRITE_NVRAM;
32792292589aSRasesh Mody break;
32802292589aSRasesh Mody case ECORE_EXT_PHY_FW_UPGRADE:
32812292589aSRasesh Mody nvm_cmd = DRV_MSG_CODE_EXT_PHY_FW_UPGRADE;
32822292589aSRasesh Mody break;
32832292589aSRasesh Mody default:
32842292589aSRasesh Mody DP_NOTICE(p_hwfn, true, "Invalid nvm write command 0x%x\n",
32852292589aSRasesh Mody cmd);
32862292589aSRasesh Mody rc = ECORE_INVAL;
32872292589aSRasesh Mody goto out;
32882292589aSRasesh Mody }
32892292589aSRasesh Mody
3290ec94dbc5SRasesh Mody buf_idx = 0;
3291ec94dbc5SRasesh Mody while (buf_idx < len) {
3292ec94dbc5SRasesh Mody buf_size = OSAL_MIN_T(u32, (len - buf_idx),
3293ec94dbc5SRasesh Mody MCP_DRV_NVM_BUF_LEN);
329404b00049SRasesh Mody nvm_offset = ((buf_size << DRV_MB_PARAM_NVM_LEN_OFFSET) |
329504b00049SRasesh Mody addr) +
32962292589aSRasesh Mody buf_idx;
32972292589aSRasesh Mody rc = ecore_mcp_nvm_wr_cmd(p_hwfn, p_ptt, nvm_cmd, nvm_offset,
32982292589aSRasesh Mody &resp, ¶m, buf_size,
32992292589aSRasesh Mody (u32 *)&p_buf[buf_idx]);
33002292589aSRasesh Mody if (rc != ECORE_SUCCESS) {
33012292589aSRasesh Mody DP_NOTICE(p_dev, false,
33022292589aSRasesh Mody "ecore_mcp_nvm_write() failed, rc = %d\n",
33032292589aSRasesh Mody rc);
33042292589aSRasesh Mody resp = FW_MSG_CODE_ERROR;
33052292589aSRasesh Mody break;
33062292589aSRasesh Mody }
33072292589aSRasesh Mody
33082292589aSRasesh Mody if (resp != FW_MSG_CODE_OK &&
33092292589aSRasesh Mody resp != FW_MSG_CODE_NVM_OK &&
33102292589aSRasesh Mody resp != FW_MSG_CODE_NVM_PUT_FILE_FINISH_OK) {
33112292589aSRasesh Mody DP_NOTICE(p_dev, false,
33122292589aSRasesh Mody "nvm write failed, resp = 0x%08x\n", resp);
33132292589aSRasesh Mody rc = ECORE_UNKNOWN_ERROR;
33142292589aSRasesh Mody break;
33152292589aSRasesh Mody }
3316ec94dbc5SRasesh Mody
331722d07d93SRasesh Mody /* This can be a lengthy process, and it's possible scheduler
331822d07d93SRasesh Mody * isn't preemptible. Sleep a bit to prevent CPU hogging.
331922d07d93SRasesh Mody */
332022d07d93SRasesh Mody if (buf_idx % 0x1000 >
332122d07d93SRasesh Mody (buf_idx + buf_size) % 0x1000)
332222d07d93SRasesh Mody OSAL_MSLEEP(1);
332322d07d93SRasesh Mody
3324ec94dbc5SRasesh Mody buf_idx += buf_size;
3325ec94dbc5SRasesh Mody }
3326ec94dbc5SRasesh Mody
33272292589aSRasesh Mody p_dev->mcp_nvm_resp = resp;
33282292589aSRasesh Mody out:
3329ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3330ec94dbc5SRasesh Mody
3331ec94dbc5SRasesh Mody return rc;
3332ec94dbc5SRasesh Mody }
3333ec94dbc5SRasesh Mody
ecore_mcp_phy_write(struct ecore_dev * p_dev,u32 cmd,u32 addr,u8 * p_buf,u32 len)3334ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_phy_write(struct ecore_dev *p_dev, u32 cmd,
3335ec94dbc5SRasesh Mody u32 addr, u8 *p_buf, u32 len)
3336ec94dbc5SRasesh Mody {
3337ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
33389ed26bc7SRasesh Mody u32 resp = 0, param, nvm_cmd;
3339ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
3340ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3341ec94dbc5SRasesh Mody
3342ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3343ec94dbc5SRasesh Mody if (!p_ptt)
3344ec94dbc5SRasesh Mody return ECORE_BUSY;
3345ec94dbc5SRasesh Mody
33462292589aSRasesh Mody nvm_cmd = (cmd == ECORE_PHY_CORE_WRITE) ? DRV_MSG_CODE_PHY_CORE_WRITE :
33472292589aSRasesh Mody DRV_MSG_CODE_PHY_RAW_WRITE;
33482292589aSRasesh Mody rc = ecore_mcp_nvm_wr_cmd(p_hwfn, p_ptt, nvm_cmd, addr,
33492292589aSRasesh Mody &resp, ¶m, len, (u32 *)p_buf);
3350ec94dbc5SRasesh Mody if (rc != ECORE_SUCCESS)
3351ec94dbc5SRasesh Mody DP_NOTICE(p_dev, false, "MCP command rc = %d\n", rc);
33522292589aSRasesh Mody p_dev->mcp_nvm_resp = resp;
3353ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3354ec94dbc5SRasesh Mody
3355ec94dbc5SRasesh Mody return rc;
3356ec94dbc5SRasesh Mody }
3357ec94dbc5SRasesh Mody
ecore_mcp_nvm_set_secure_mode(struct ecore_dev * p_dev,u32 addr)3358ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_set_secure_mode(struct ecore_dev *p_dev,
3359ec94dbc5SRasesh Mody u32 addr)
3360ec94dbc5SRasesh Mody {
3361ec94dbc5SRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3362ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt;
3363db8af647SAndrzej Ostruszka u32 resp = 0, param;
3364ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3365ec94dbc5SRasesh Mody
3366ec94dbc5SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
3367ec94dbc5SRasesh Mody if (!p_ptt)
3368ec94dbc5SRasesh Mody return ECORE_BUSY;
3369ec94dbc5SRasesh Mody
33702292589aSRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_SECURE_MODE, addr,
33712292589aSRasesh Mody &resp, ¶m);
33722292589aSRasesh Mody p_dev->mcp_nvm_resp = resp;
3373ec94dbc5SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
3374ec94dbc5SRasesh Mody
3375ec94dbc5SRasesh Mody return rc;
3376ec94dbc5SRasesh Mody }
3377ec94dbc5SRasesh Mody
ecore_mcp_phy_sfp_read(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 port,u32 addr,u32 offset,u32 len,u8 * p_buf)3378ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_phy_sfp_read(struct ecore_hwfn *p_hwfn,
3379ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
3380ec94dbc5SRasesh Mody u32 port, u32 addr, u32 offset,
3381ec94dbc5SRasesh Mody u32 len, u8 *p_buf)
3382ec94dbc5SRasesh Mody {
33832292589aSRasesh Mody u32 bytes_left, bytes_to_copy, buf_size, nvm_offset;
33842292589aSRasesh Mody u32 resp, param;
3385ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3386ec94dbc5SRasesh Mody
338704b00049SRasesh Mody nvm_offset = (port << DRV_MB_PARAM_TRANSCEIVER_PORT_OFFSET) |
338804b00049SRasesh Mody (addr << DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_OFFSET);
3389ec94dbc5SRasesh Mody addr = offset;
3390ec94dbc5SRasesh Mody offset = 0;
3391ec94dbc5SRasesh Mody bytes_left = len;
3392ec94dbc5SRasesh Mody while (bytes_left > 0) {
3393ec94dbc5SRasesh Mody bytes_to_copy = OSAL_MIN_T(u32, bytes_left,
3394ec94dbc5SRasesh Mody MAX_I2C_TRANSACTION_SIZE);
33952292589aSRasesh Mody nvm_offset &= (DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK |
339622d07d93SRasesh Mody DRV_MB_PARAM_TRANSCEIVER_PORT_MASK);
33972292589aSRasesh Mody nvm_offset |= ((addr + offset) <<
339804b00049SRasesh Mody DRV_MB_PARAM_TRANSCEIVER_OFFSET_OFFSET);
33992292589aSRasesh Mody nvm_offset |= (bytes_to_copy <<
340004b00049SRasesh Mody DRV_MB_PARAM_TRANSCEIVER_SIZE_OFFSET);
34012292589aSRasesh Mody rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
34022292589aSRasesh Mody DRV_MSG_CODE_TRANSCEIVER_READ,
34032292589aSRasesh Mody nvm_offset, &resp, ¶m, &buf_size,
34042292589aSRasesh Mody (u32 *)(p_buf + offset));
3405b9ebba32SRasesh Mody if (rc != ECORE_SUCCESS) {
3406b9ebba32SRasesh Mody DP_NOTICE(p_hwfn, false,
3407b9ebba32SRasesh Mody "Failed to send a transceiver read command to the MFW. rc = %d.\n",
3408b9ebba32SRasesh Mody rc);
3409b9ebba32SRasesh Mody return rc;
3410b9ebba32SRasesh Mody }
3411b9ebba32SRasesh Mody
3412b9ebba32SRasesh Mody if (resp == FW_MSG_CODE_TRANSCEIVER_NOT_PRESENT)
3413ec94dbc5SRasesh Mody return ECORE_NODEV;
3414b9ebba32SRasesh Mody else if (resp != FW_MSG_CODE_TRANSCEIVER_DIAG_OK)
3415ec94dbc5SRasesh Mody return ECORE_UNKNOWN_ERROR;
3416ec94dbc5SRasesh Mody
34172292589aSRasesh Mody offset += buf_size;
34182292589aSRasesh Mody bytes_left -= buf_size;
3419ec94dbc5SRasesh Mody }
3420ec94dbc5SRasesh Mody
3421ec94dbc5SRasesh Mody return ECORE_SUCCESS;
3422ec94dbc5SRasesh Mody }
3423ec94dbc5SRasesh Mody
ecore_mcp_phy_sfp_write(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 port,u32 addr,u32 offset,u32 len,u8 * p_buf)3424ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_phy_sfp_write(struct ecore_hwfn *p_hwfn,
3425ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
3426ec94dbc5SRasesh Mody u32 port, u32 addr, u32 offset,
3427ec94dbc5SRasesh Mody u32 len, u8 *p_buf)
3428ec94dbc5SRasesh Mody {
34292292589aSRasesh Mody u32 buf_idx, buf_size, nvm_offset, resp, param;
3430ec94dbc5SRasesh Mody enum _ecore_status_t rc;
3431ec94dbc5SRasesh Mody
343204b00049SRasesh Mody nvm_offset = (port << DRV_MB_PARAM_TRANSCEIVER_PORT_OFFSET) |
343304b00049SRasesh Mody (addr << DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_OFFSET);
3434ec94dbc5SRasesh Mody buf_idx = 0;
3435ec94dbc5SRasesh Mody while (buf_idx < len) {
3436ec94dbc5SRasesh Mody buf_size = OSAL_MIN_T(u32, (len - buf_idx),
3437ec94dbc5SRasesh Mody MAX_I2C_TRANSACTION_SIZE);
34382292589aSRasesh Mody nvm_offset &= (DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK |
343922d07d93SRasesh Mody DRV_MB_PARAM_TRANSCEIVER_PORT_MASK);
34402292589aSRasesh Mody nvm_offset |= ((offset + buf_idx) <<
344104b00049SRasesh Mody DRV_MB_PARAM_TRANSCEIVER_OFFSET_OFFSET);
344204b00049SRasesh Mody nvm_offset |= (buf_size <<
344304b00049SRasesh Mody DRV_MB_PARAM_TRANSCEIVER_SIZE_OFFSET);
34442292589aSRasesh Mody rc = ecore_mcp_nvm_wr_cmd(p_hwfn, p_ptt,
34452292589aSRasesh Mody DRV_MSG_CODE_TRANSCEIVER_WRITE,
34462292589aSRasesh Mody nvm_offset, &resp, ¶m, buf_size,
34472292589aSRasesh Mody (u32 *)&p_buf[buf_idx]);
3448b9ebba32SRasesh Mody if (rc != ECORE_SUCCESS) {
3449b9ebba32SRasesh Mody DP_NOTICE(p_hwfn, false,
3450b9ebba32SRasesh Mody "Failed to send a transceiver write command to the MFW. rc = %d.\n",
3451b9ebba32SRasesh Mody rc);
3452b9ebba32SRasesh Mody return rc;
3453b9ebba32SRasesh Mody }
3454b9ebba32SRasesh Mody
3455b9ebba32SRasesh Mody if (resp == FW_MSG_CODE_TRANSCEIVER_NOT_PRESENT)
3456ec94dbc5SRasesh Mody return ECORE_NODEV;
3457b9ebba32SRasesh Mody else if (resp != FW_MSG_CODE_TRANSCEIVER_DIAG_OK)
3458ec94dbc5SRasesh Mody return ECORE_UNKNOWN_ERROR;
3459ec94dbc5SRasesh Mody
3460ec94dbc5SRasesh Mody buf_idx += buf_size;
3461ec94dbc5SRasesh Mody }
3462ec94dbc5SRasesh Mody
3463ec94dbc5SRasesh Mody return ECORE_SUCCESS;
3464ec94dbc5SRasesh Mody }
3465ec94dbc5SRasesh Mody
ecore_mcp_gpio_read(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 gpio,u32 * gpio_val)3466ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_gpio_read(struct ecore_hwfn *p_hwfn,
3467ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
3468ec94dbc5SRasesh Mody u16 gpio, u32 *gpio_val)
3469ec94dbc5SRasesh Mody {
3470ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
3471db8af647SAndrzej Ostruszka u32 drv_mb_param = 0, rsp = 0;
3472ec94dbc5SRasesh Mody
347304b00049SRasesh Mody drv_mb_param = (gpio << DRV_MB_PARAM_GPIO_NUMBER_OFFSET);
3474ec94dbc5SRasesh Mody
3475ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GPIO_READ,
3476ec94dbc5SRasesh Mody drv_mb_param, &rsp, gpio_val);
3477ec94dbc5SRasesh Mody
347822d07d93SRasesh Mody if (rc != ECORE_SUCCESS)
347922d07d93SRasesh Mody return rc;
348022d07d93SRasesh Mody
3481ec94dbc5SRasesh Mody if ((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_GPIO_OK)
3482ec94dbc5SRasesh Mody return ECORE_UNKNOWN_ERROR;
3483ec94dbc5SRasesh Mody
3484ec94dbc5SRasesh Mody return ECORE_SUCCESS;
3485ec94dbc5SRasesh Mody }
3486ec94dbc5SRasesh Mody
ecore_mcp_gpio_write(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 gpio,u16 gpio_val)3487ec94dbc5SRasesh Mody enum _ecore_status_t ecore_mcp_gpio_write(struct ecore_hwfn *p_hwfn,
3488ec94dbc5SRasesh Mody struct ecore_ptt *p_ptt,
3489ec94dbc5SRasesh Mody u16 gpio, u16 gpio_val)
3490ec94dbc5SRasesh Mody {
3491ec94dbc5SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
3492db8af647SAndrzej Ostruszka u32 drv_mb_param = 0, param, rsp = 0;
3493ec94dbc5SRasesh Mody
349404b00049SRasesh Mody drv_mb_param = (gpio << DRV_MB_PARAM_GPIO_NUMBER_OFFSET) |
349504b00049SRasesh Mody (gpio_val << DRV_MB_PARAM_GPIO_VALUE_OFFSET);
3496ec94dbc5SRasesh Mody
3497ec94dbc5SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GPIO_WRITE,
3498ec94dbc5SRasesh Mody drv_mb_param, &rsp, ¶m);
3499ec94dbc5SRasesh Mody
350022d07d93SRasesh Mody if (rc != ECORE_SUCCESS)
350122d07d93SRasesh Mody return rc;
350222d07d93SRasesh Mody
3503ec94dbc5SRasesh Mody if ((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_GPIO_OK)
3504ec94dbc5SRasesh Mody return ECORE_UNKNOWN_ERROR;
3505ec94dbc5SRasesh Mody
3506ec94dbc5SRasesh Mody return ECORE_SUCCESS;
3507ec94dbc5SRasesh Mody }
3508252b88b5SHarish Patil
ecore_mcp_gpio_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u16 gpio,u32 * gpio_direction,u32 * gpio_ctrl)3509252b88b5SHarish Patil enum _ecore_status_t ecore_mcp_gpio_info(struct ecore_hwfn *p_hwfn,
3510252b88b5SHarish Patil struct ecore_ptt *p_ptt,
3511252b88b5SHarish Patil u16 gpio, u32 *gpio_direction,
3512252b88b5SHarish Patil u32 *gpio_ctrl)
3513252b88b5SHarish Patil {
3514252b88b5SHarish Patil u32 drv_mb_param = 0, rsp, val = 0;
3515252b88b5SHarish Patil enum _ecore_status_t rc = ECORE_SUCCESS;
3516252b88b5SHarish Patil
351704b00049SRasesh Mody drv_mb_param = gpio << DRV_MB_PARAM_GPIO_NUMBER_OFFSET;
3518252b88b5SHarish Patil
3519252b88b5SHarish Patil rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GPIO_INFO,
3520252b88b5SHarish Patil drv_mb_param, &rsp, &val);
3521252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
3522252b88b5SHarish Patil return rc;
3523252b88b5SHarish Patil
3524252b88b5SHarish Patil *gpio_direction = (val & DRV_MB_PARAM_GPIO_DIRECTION_MASK) >>
352504b00049SRasesh Mody DRV_MB_PARAM_GPIO_DIRECTION_OFFSET;
3526252b88b5SHarish Patil *gpio_ctrl = (val & DRV_MB_PARAM_GPIO_CTRL_MASK) >>
352704b00049SRasesh Mody DRV_MB_PARAM_GPIO_CTRL_OFFSET;
3528252b88b5SHarish Patil
3529252b88b5SHarish Patil if ((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_GPIO_OK)
3530252b88b5SHarish Patil return ECORE_UNKNOWN_ERROR;
3531252b88b5SHarish Patil
3532252b88b5SHarish Patil return ECORE_SUCCESS;
3533252b88b5SHarish Patil }
3534252b88b5SHarish Patil
ecore_mcp_bist_register_test(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)3535252b88b5SHarish Patil enum _ecore_status_t ecore_mcp_bist_register_test(struct ecore_hwfn *p_hwfn,
3536252b88b5SHarish Patil struct ecore_ptt *p_ptt)
3537252b88b5SHarish Patil {
3538252b88b5SHarish Patil u32 drv_mb_param = 0, rsp, param;
3539252b88b5SHarish Patil enum _ecore_status_t rc = ECORE_SUCCESS;
3540252b88b5SHarish Patil
3541252b88b5SHarish Patil drv_mb_param = (DRV_MB_PARAM_BIST_REGISTER_TEST <<
354204b00049SRasesh Mody DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
3543252b88b5SHarish Patil
3544252b88b5SHarish Patil rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
3545252b88b5SHarish Patil drv_mb_param, &rsp, ¶m);
3546252b88b5SHarish Patil
3547252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
3548252b88b5SHarish Patil return rc;
3549252b88b5SHarish Patil
3550252b88b5SHarish Patil if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
3551252b88b5SHarish Patil (param != DRV_MB_PARAM_BIST_RC_PASSED))
3552252b88b5SHarish Patil rc = ECORE_UNKNOWN_ERROR;
3553252b88b5SHarish Patil
3554252b88b5SHarish Patil return rc;
3555252b88b5SHarish Patil }
3556252b88b5SHarish Patil
ecore_mcp_bist_clock_test(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)3557252b88b5SHarish Patil enum _ecore_status_t ecore_mcp_bist_clock_test(struct ecore_hwfn *p_hwfn,
3558252b88b5SHarish Patil struct ecore_ptt *p_ptt)
3559252b88b5SHarish Patil {
3560869c47d0SRasesh Mody u32 drv_mb_param, rsp, param;
3561252b88b5SHarish Patil enum _ecore_status_t rc = ECORE_SUCCESS;
3562252b88b5SHarish Patil
3563252b88b5SHarish Patil drv_mb_param = (DRV_MB_PARAM_BIST_CLOCK_TEST <<
356404b00049SRasesh Mody DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
3565252b88b5SHarish Patil
3566252b88b5SHarish Patil rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
3567252b88b5SHarish Patil drv_mb_param, &rsp, ¶m);
3568252b88b5SHarish Patil
3569252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
3570252b88b5SHarish Patil return rc;
3571252b88b5SHarish Patil
3572252b88b5SHarish Patil if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
3573252b88b5SHarish Patil (param != DRV_MB_PARAM_BIST_RC_PASSED))
3574252b88b5SHarish Patil rc = ECORE_UNKNOWN_ERROR;
3575252b88b5SHarish Patil
3576252b88b5SHarish Patil return rc;
3577252b88b5SHarish Patil }
3578252b88b5SHarish Patil
ecore_mcp_bist_nvm_test_get_num_images(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * num_images)3579252b88b5SHarish Patil enum _ecore_status_t ecore_mcp_bist_nvm_test_get_num_images(
3580252b88b5SHarish Patil struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, u32 *num_images)
3581252b88b5SHarish Patil {
3582db8af647SAndrzej Ostruszka u32 drv_mb_param = 0, rsp = 0;
3583252b88b5SHarish Patil enum _ecore_status_t rc = ECORE_SUCCESS;
3584252b88b5SHarish Patil
3585252b88b5SHarish Patil drv_mb_param = (DRV_MB_PARAM_BIST_NVM_TEST_NUM_IMAGES <<
358604b00049SRasesh Mody DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
3587252b88b5SHarish Patil
3588252b88b5SHarish Patil rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
3589252b88b5SHarish Patil drv_mb_param, &rsp, num_images);
3590252b88b5SHarish Patil
3591252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
3592252b88b5SHarish Patil return rc;
3593252b88b5SHarish Patil
3594252b88b5SHarish Patil if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK))
3595252b88b5SHarish Patil rc = ECORE_UNKNOWN_ERROR;
3596252b88b5SHarish Patil
3597252b88b5SHarish Patil return rc;
3598252b88b5SHarish Patil }
3599252b88b5SHarish Patil
ecore_mcp_bist_nvm_test_get_image_att(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct bist_nvm_image_att * p_image_att,u32 image_index)3600252b88b5SHarish Patil enum _ecore_status_t ecore_mcp_bist_nvm_test_get_image_att(
3601252b88b5SHarish Patil struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3602252b88b5SHarish Patil struct bist_nvm_image_att *p_image_att, u32 image_index)
3603252b88b5SHarish Patil {
36042292589aSRasesh Mody u32 buf_size, nvm_offset, resp, param;
3605252b88b5SHarish Patil enum _ecore_status_t rc;
3606252b88b5SHarish Patil
36072292589aSRasesh Mody nvm_offset = (DRV_MB_PARAM_BIST_NVM_TEST_IMAGE_BY_INDEX <<
360804b00049SRasesh Mody DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
360904b00049SRasesh Mody nvm_offset |= (image_index <<
361004b00049SRasesh Mody DRV_MB_PARAM_BIST_TEST_IMAGE_INDEX_OFFSET);
36112292589aSRasesh Mody rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
36122292589aSRasesh Mody nvm_offset, &resp, ¶m, &buf_size,
36132292589aSRasesh Mody (u32 *)p_image_att);
3614252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
3615252b88b5SHarish Patil return rc;
3616252b88b5SHarish Patil
36172292589aSRasesh Mody if (((resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
3618252b88b5SHarish Patil (p_image_att->return_code != 1))
3619252b88b5SHarish Patil rc = ECORE_UNKNOWN_ERROR;
3620252b88b5SHarish Patil
3621252b88b5SHarish Patil return rc;
3622252b88b5SHarish Patil }
3623252b88b5SHarish Patil
3624252b88b5SHarish Patil enum _ecore_status_t
ecore_mcp_bist_nvm_get_num_images(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 * num_images)36252352f348SRasesh Mody ecore_mcp_bist_nvm_get_num_images(struct ecore_hwfn *p_hwfn,
36262352f348SRasesh Mody struct ecore_ptt *p_ptt, u32 *num_images)
36272352f348SRasesh Mody {
36282352f348SRasesh Mody u32 drv_mb_param = 0, rsp;
36292352f348SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
36302352f348SRasesh Mody
36312352f348SRasesh Mody SET_MFW_FIELD(drv_mb_param, DRV_MB_PARAM_BIST_TEST_INDEX,
36322352f348SRasesh Mody DRV_MB_PARAM_BIST_NVM_TEST_NUM_IMAGES);
36332352f348SRasesh Mody
36342352f348SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
36352352f348SRasesh Mody drv_mb_param, &rsp, num_images);
36362352f348SRasesh Mody if (rc != ECORE_SUCCESS)
36372352f348SRasesh Mody return rc;
36382352f348SRasesh Mody
36392352f348SRasesh Mody if (rsp == FW_MSG_CODE_UNSUPPORTED)
36402352f348SRasesh Mody rc = ECORE_NOTIMPL;
36412352f348SRasesh Mody else if (rsp != FW_MSG_CODE_OK)
36422352f348SRasesh Mody rc = ECORE_UNKNOWN_ERROR;
36432352f348SRasesh Mody
36442352f348SRasesh Mody return rc;
36452352f348SRasesh Mody }
36462352f348SRasesh Mody
36472352f348SRasesh Mody enum _ecore_status_t
ecore_mcp_bist_nvm_get_image_att(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct bist_nvm_image_att * p_image_att,u32 image_index)36482352f348SRasesh Mody ecore_mcp_bist_nvm_get_image_att(struct ecore_hwfn *p_hwfn,
36492352f348SRasesh Mody struct ecore_ptt *p_ptt,
36502352f348SRasesh Mody struct bist_nvm_image_att *p_image_att,
36512352f348SRasesh Mody u32 image_index)
36522352f348SRasesh Mody {
36532352f348SRasesh Mody u32 buf_size, nvm_offset = 0, resp, param;
36542352f348SRasesh Mody enum _ecore_status_t rc;
36552352f348SRasesh Mody
36562352f348SRasesh Mody SET_MFW_FIELD(nvm_offset, DRV_MB_PARAM_BIST_TEST_INDEX,
36572352f348SRasesh Mody DRV_MB_PARAM_BIST_NVM_TEST_IMAGE_BY_INDEX);
36582352f348SRasesh Mody SET_MFW_FIELD(nvm_offset, DRV_MB_PARAM_BIST_TEST_IMAGE_INDEX,
36592352f348SRasesh Mody image_index);
36602352f348SRasesh Mody rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
36612352f348SRasesh Mody nvm_offset, &resp, ¶m, &buf_size,
36622352f348SRasesh Mody (u32 *)p_image_att);
36632352f348SRasesh Mody if (rc != ECORE_SUCCESS)
36642352f348SRasesh Mody return rc;
36652352f348SRasesh Mody
36662352f348SRasesh Mody if (resp == FW_MSG_CODE_UNSUPPORTED)
36672352f348SRasesh Mody rc = ECORE_NOTIMPL;
36682352f348SRasesh Mody else if ((resp != FW_MSG_CODE_OK) || (p_image_att->return_code != 1))
36692352f348SRasesh Mody rc = ECORE_UNKNOWN_ERROR;
36702352f348SRasesh Mody
36712352f348SRasesh Mody return rc;
36722352f348SRasesh Mody }
36732352f348SRasesh Mody
ecore_mcp_nvm_info_populate(struct ecore_hwfn * p_hwfn)36742352f348SRasesh Mody enum _ecore_status_t ecore_mcp_nvm_info_populate(struct ecore_hwfn *p_hwfn)
36752352f348SRasesh Mody {
36762352f348SRasesh Mody struct ecore_nvm_image_info nvm_info;
36772352f348SRasesh Mody struct ecore_ptt *p_ptt;
36782352f348SRasesh Mody enum _ecore_status_t rc;
36792352f348SRasesh Mody u32 i;
36802352f348SRasesh Mody
36812352f348SRasesh Mody if (p_hwfn->nvm_info.valid)
36822352f348SRasesh Mody return ECORE_SUCCESS;
36832352f348SRasesh Mody
36842352f348SRasesh Mody #ifndef ASIC_ONLY
36852352f348SRasesh Mody if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) ||
36862352f348SRasesh Mody CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev))
36872352f348SRasesh Mody return ECORE_SUCCESS;
36882352f348SRasesh Mody #endif
36892352f348SRasesh Mody
36902352f348SRasesh Mody p_ptt = ecore_ptt_acquire(p_hwfn);
36912352f348SRasesh Mody if (!p_ptt) {
36922352f348SRasesh Mody DP_ERR(p_hwfn, "failed to acquire ptt\n");
36932352f348SRasesh Mody return ECORE_BUSY;
36942352f348SRasesh Mody }
36952352f348SRasesh Mody
36962352f348SRasesh Mody /* Acquire from MFW the amount of available images */
36972352f348SRasesh Mody OSAL_MEM_ZERO(&nvm_info, sizeof(nvm_info));
36982352f348SRasesh Mody rc = ecore_mcp_bist_nvm_get_num_images(p_hwfn, p_ptt,
36992352f348SRasesh Mody &nvm_info.num_images);
37002352f348SRasesh Mody if (rc == ECORE_NOTIMPL) {
37012352f348SRasesh Mody DP_INFO(p_hwfn, "DRV_MSG_CODE_BIST_TEST is not supported\n");
37022352f348SRasesh Mody goto out;
37032352f348SRasesh Mody } else if ((rc != ECORE_SUCCESS) || (nvm_info.num_images == 0)) {
37042352f348SRasesh Mody DP_ERR(p_hwfn, "Failed getting number of images\n");
37052352f348SRasesh Mody goto err0;
37062352f348SRasesh Mody }
37072352f348SRasesh Mody
37082352f348SRasesh Mody nvm_info.image_att = OSAL_ALLOC(p_hwfn->p_dev, GFP_KERNEL,
37092352f348SRasesh Mody nvm_info.num_images *
37102352f348SRasesh Mody sizeof(struct bist_nvm_image_att));
37112352f348SRasesh Mody if (!nvm_info.image_att) {
37122352f348SRasesh Mody rc = ECORE_NOMEM;
37132352f348SRasesh Mody goto err0;
37142352f348SRasesh Mody }
37152352f348SRasesh Mody
37162352f348SRasesh Mody /* Iterate over images and get their attributes */
37172352f348SRasesh Mody for (i = 0; i < nvm_info.num_images; i++) {
37182352f348SRasesh Mody rc = ecore_mcp_bist_nvm_get_image_att(p_hwfn, p_ptt,
37192352f348SRasesh Mody &nvm_info.image_att[i],
37202352f348SRasesh Mody i);
37212352f348SRasesh Mody if (rc != ECORE_SUCCESS) {
37222352f348SRasesh Mody DP_ERR(p_hwfn,
37232352f348SRasesh Mody "Failed getting image index %d attributes\n",
37242352f348SRasesh Mody i);
37252352f348SRasesh Mody goto err1;
37262352f348SRasesh Mody }
37272352f348SRasesh Mody
37282352f348SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "image index %d, size %x\n", i,
37292352f348SRasesh Mody nvm_info.image_att[i].len);
37302352f348SRasesh Mody }
37312352f348SRasesh Mody out:
37322352f348SRasesh Mody /* Update hwfn's nvm_info */
37332352f348SRasesh Mody if (nvm_info.num_images) {
37342352f348SRasesh Mody p_hwfn->nvm_info.num_images = nvm_info.num_images;
37352352f348SRasesh Mody if (p_hwfn->nvm_info.image_att)
37362352f348SRasesh Mody OSAL_FREE(p_hwfn->p_dev, p_hwfn->nvm_info.image_att);
37372352f348SRasesh Mody p_hwfn->nvm_info.image_att = nvm_info.image_att;
37382352f348SRasesh Mody p_hwfn->nvm_info.valid = true;
37392352f348SRasesh Mody }
37402352f348SRasesh Mody
37412352f348SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
37422352f348SRasesh Mody return ECORE_SUCCESS;
37432352f348SRasesh Mody
37442352f348SRasesh Mody err1:
37452352f348SRasesh Mody OSAL_FREE(p_hwfn->p_dev, nvm_info.image_att);
37462352f348SRasesh Mody err0:
37472352f348SRasesh Mody ecore_ptt_release(p_hwfn, p_ptt);
37482352f348SRasesh Mody return rc;
37492352f348SRasesh Mody }
37502352f348SRasesh Mody
37512352f348SRasesh Mody enum _ecore_status_t
ecore_mcp_get_nvm_image_att(struct ecore_hwfn * p_hwfn,enum ecore_nvm_images image_id,struct ecore_nvm_image_att * p_image_att)37522352f348SRasesh Mody ecore_mcp_get_nvm_image_att(struct ecore_hwfn *p_hwfn,
37532352f348SRasesh Mody enum ecore_nvm_images image_id,
37542352f348SRasesh Mody struct ecore_nvm_image_att *p_image_att)
37552352f348SRasesh Mody {
37562352f348SRasesh Mody enum nvm_image_type type;
37572352f348SRasesh Mody u32 i;
37582352f348SRasesh Mody
37592352f348SRasesh Mody /* Translate image_id into MFW definitions */
37602352f348SRasesh Mody switch (image_id) {
37612352f348SRasesh Mody case ECORE_NVM_IMAGE_ISCSI_CFG:
37622352f348SRasesh Mody type = NVM_TYPE_ISCSI_CFG;
37632352f348SRasesh Mody break;
37642352f348SRasesh Mody case ECORE_NVM_IMAGE_FCOE_CFG:
37652352f348SRasesh Mody type = NVM_TYPE_FCOE_CFG;
37662352f348SRasesh Mody break;
37672352f348SRasesh Mody case ECORE_NVM_IMAGE_MDUMP:
37682352f348SRasesh Mody type = NVM_TYPE_MDUMP;
37692352f348SRasesh Mody break;
37702352f348SRasesh Mody case ECORE_NVM_IMAGE_NVM_CFG1:
37712352f348SRasesh Mody type = NVM_TYPE_NVM_CFG1;
37722352f348SRasesh Mody break;
37732352f348SRasesh Mody case ECORE_NVM_IMAGE_DEFAULT_CFG:
37742352f348SRasesh Mody type = NVM_TYPE_DEFAULT_CFG;
37752352f348SRasesh Mody break;
37762352f348SRasesh Mody case ECORE_NVM_IMAGE_NVM_META:
37772352f348SRasesh Mody type = NVM_TYPE_META;
37782352f348SRasesh Mody break;
37792352f348SRasesh Mody default:
37802352f348SRasesh Mody DP_NOTICE(p_hwfn, false, "Unknown request of image_id %08x\n",
37812352f348SRasesh Mody image_id);
37822352f348SRasesh Mody return ECORE_INVAL;
37832352f348SRasesh Mody }
37842352f348SRasesh Mody
37852352f348SRasesh Mody ecore_mcp_nvm_info_populate(p_hwfn);
37862352f348SRasesh Mody for (i = 0; i < p_hwfn->nvm_info.num_images; i++) {
37872352f348SRasesh Mody if (type == p_hwfn->nvm_info.image_att[i].image_type)
37882352f348SRasesh Mody break;
37892352f348SRasesh Mody }
37902352f348SRasesh Mody if (i == p_hwfn->nvm_info.num_images) {
37912352f348SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
37922352f348SRasesh Mody "Failed to find nvram image of type %08x\n",
37932352f348SRasesh Mody image_id);
37942352f348SRasesh Mody return ECORE_NOENT;
37952352f348SRasesh Mody }
37962352f348SRasesh Mody
37972352f348SRasesh Mody p_image_att->start_addr = p_hwfn->nvm_info.image_att[i].nvm_start_addr;
37982352f348SRasesh Mody p_image_att->length = p_hwfn->nvm_info.image_att[i].len;
37992352f348SRasesh Mody
38002352f348SRasesh Mody return ECORE_SUCCESS;
38012352f348SRasesh Mody }
38022352f348SRasesh Mody
ecore_mcp_get_nvm_image(struct ecore_hwfn * p_hwfn,enum ecore_nvm_images image_id,u8 * p_buffer,u32 buffer_len)38032352f348SRasesh Mody enum _ecore_status_t ecore_mcp_get_nvm_image(struct ecore_hwfn *p_hwfn,
38042352f348SRasesh Mody enum ecore_nvm_images image_id,
38052352f348SRasesh Mody u8 *p_buffer, u32 buffer_len)
38062352f348SRasesh Mody {
38072352f348SRasesh Mody struct ecore_nvm_image_att image_att;
38082352f348SRasesh Mody enum _ecore_status_t rc;
38092352f348SRasesh Mody
38102352f348SRasesh Mody OSAL_MEM_ZERO(p_buffer, buffer_len);
38112352f348SRasesh Mody
38122352f348SRasesh Mody rc = ecore_mcp_get_nvm_image_att(p_hwfn, image_id, &image_att);
38132352f348SRasesh Mody if (rc != ECORE_SUCCESS)
38142352f348SRasesh Mody return rc;
38152352f348SRasesh Mody
38162352f348SRasesh Mody /* Validate sizes - both the image's and the supplied buffer's */
38172352f348SRasesh Mody if (image_att.length <= 4) {
38182352f348SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
38192352f348SRasesh Mody "Image [%d] is too small - only %d bytes\n",
38202352f348SRasesh Mody image_id, image_att.length);
38212352f348SRasesh Mody return ECORE_INVAL;
38222352f348SRasesh Mody }
38232352f348SRasesh Mody
38242352f348SRasesh Mody if (image_att.length > buffer_len) {
38252352f348SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
38262352f348SRasesh Mody "Image [%d] is too big - %08x bytes where only %08x are available\n",
38272352f348SRasesh Mody image_id, image_att.length, buffer_len);
38282352f348SRasesh Mody return ECORE_NOMEM;
38292352f348SRasesh Mody }
38302352f348SRasesh Mody
38312352f348SRasesh Mody return ecore_mcp_nvm_read(p_hwfn->p_dev, image_att.start_addr,
38322352f348SRasesh Mody (u8 *)p_buffer, image_att.length);
38332352f348SRasesh Mody }
38342352f348SRasesh Mody
38352352f348SRasesh Mody enum _ecore_status_t
ecore_mcp_get_temperature_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_temperature_info * p_temp_info)3836252b88b5SHarish Patil ecore_mcp_get_temperature_info(struct ecore_hwfn *p_hwfn,
3837252b88b5SHarish Patil struct ecore_ptt *p_ptt,
3838252b88b5SHarish Patil struct ecore_temperature_info *p_temp_info)
3839252b88b5SHarish Patil {
3840252b88b5SHarish Patil struct ecore_temperature_sensor *p_temp_sensor;
3841e32dc0f7SRasesh Mody struct temperature_status_stc mfw_temp_info;
3842252b88b5SHarish Patil struct ecore_mcp_mb_params mb_params;
3843252b88b5SHarish Patil u32 val;
3844252b88b5SHarish Patil enum _ecore_status_t rc;
3845252b88b5SHarish Patil u8 i;
3846252b88b5SHarish Patil
3847252b88b5SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
3848252b88b5SHarish Patil mb_params.cmd = DRV_MSG_CODE_GET_TEMPERATURE;
3849e32dc0f7SRasesh Mody mb_params.p_data_dst = &mfw_temp_info;
3850e32dc0f7SRasesh Mody mb_params.data_dst_size = sizeof(mfw_temp_info);
3851252b88b5SHarish Patil rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
3852252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
3853252b88b5SHarish Patil return rc;
3854252b88b5SHarish Patil
3855252b88b5SHarish Patil OSAL_BUILD_BUG_ON(ECORE_MAX_NUM_OF_SENSORS != MAX_NUM_OF_SENSORS);
3856e32dc0f7SRasesh Mody p_temp_info->num_sensors = OSAL_MIN_T(u32, mfw_temp_info.num_of_sensors,
3857252b88b5SHarish Patil ECORE_MAX_NUM_OF_SENSORS);
3858252b88b5SHarish Patil for (i = 0; i < p_temp_info->num_sensors; i++) {
3859e32dc0f7SRasesh Mody val = mfw_temp_info.sensor[i];
3860252b88b5SHarish Patil p_temp_sensor = &p_temp_info->sensors[i];
3861252b88b5SHarish Patil p_temp_sensor->sensor_location = (val & SENSOR_LOCATION_MASK) >>
386204b00049SRasesh Mody SENSOR_LOCATION_OFFSET;
3863252b88b5SHarish Patil p_temp_sensor->threshold_high = (val & THRESHOLD_HIGH_MASK) >>
386404b00049SRasesh Mody THRESHOLD_HIGH_OFFSET;
3865252b88b5SHarish Patil p_temp_sensor->critical = (val & CRITICAL_TEMPERATURE_MASK) >>
386604b00049SRasesh Mody CRITICAL_TEMPERATURE_OFFSET;
3867252b88b5SHarish Patil p_temp_sensor->current_temp = (val & CURRENT_TEMP_MASK) >>
386804b00049SRasesh Mody CURRENT_TEMP_OFFSET;
3869252b88b5SHarish Patil }
3870252b88b5SHarish Patil
3871252b88b5SHarish Patil return ECORE_SUCCESS;
3872252b88b5SHarish Patil }
3873252b88b5SHarish Patil
ecore_mcp_get_mba_versions(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mba_vers * p_mba_vers)3874252b88b5SHarish Patil enum _ecore_status_t ecore_mcp_get_mba_versions(
3875252b88b5SHarish Patil struct ecore_hwfn *p_hwfn,
3876252b88b5SHarish Patil struct ecore_ptt *p_ptt,
3877252b88b5SHarish Patil struct ecore_mba_vers *p_mba_vers)
3878252b88b5SHarish Patil {
38792292589aSRasesh Mody u32 buf_size, resp, param;
3880252b88b5SHarish Patil enum _ecore_status_t rc;
3881252b88b5SHarish Patil
38822292589aSRasesh Mody rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GET_MBA_VERSION,
38832292589aSRasesh Mody 0, &resp, ¶m, &buf_size,
38842292589aSRasesh Mody &p_mba_vers->mba_vers[0]);
3885252b88b5SHarish Patil
3886252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
3887252b88b5SHarish Patil return rc;
3888252b88b5SHarish Patil
38892292589aSRasesh Mody if ((resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_NVM_OK)
3890252b88b5SHarish Patil rc = ECORE_UNKNOWN_ERROR;
3891252b88b5SHarish Patil
3892252b88b5SHarish Patil if (buf_size != MCP_DRV_NVM_BUF_LEN)
3893252b88b5SHarish Patil rc = ECORE_UNKNOWN_ERROR;
3894252b88b5SHarish Patil
3895252b88b5SHarish Patil return rc;
3896252b88b5SHarish Patil }
3897252b88b5SHarish Patil
ecore_mcp_mem_ecc_events(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u64 * num_events)3898252b88b5SHarish Patil enum _ecore_status_t ecore_mcp_mem_ecc_events(struct ecore_hwfn *p_hwfn,
3899252b88b5SHarish Patil struct ecore_ptt *p_ptt,
3900252b88b5SHarish Patil u64 *num_events)
3901252b88b5SHarish Patil {
3902252b88b5SHarish Patil u32 rsp;
3903252b88b5SHarish Patil
3904252b88b5SHarish Patil return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MEM_ECC_EVENTS,
3905252b88b5SHarish Patil 0, &rsp, (u32 *)num_events);
3906252b88b5SHarish Patil }
3907252b88b5SHarish Patil
390849ca6a7bSRasesh Mody static enum resource_id_enum
ecore_mcp_get_mfw_res_id(enum ecore_resources res_id)390949ca6a7bSRasesh Mody ecore_mcp_get_mfw_res_id(enum ecore_resources res_id)
391049ca6a7bSRasesh Mody {
391149ca6a7bSRasesh Mody enum resource_id_enum mfw_res_id = RESOURCE_NUM_INVALID;
391249ca6a7bSRasesh Mody
391349ca6a7bSRasesh Mody switch (res_id) {
391449ca6a7bSRasesh Mody case ECORE_SB:
391549ca6a7bSRasesh Mody mfw_res_id = RESOURCE_NUM_SB_E;
391649ca6a7bSRasesh Mody break;
391749ca6a7bSRasesh Mody case ECORE_L2_QUEUE:
391849ca6a7bSRasesh Mody mfw_res_id = RESOURCE_NUM_L2_QUEUE_E;
391949ca6a7bSRasesh Mody break;
392049ca6a7bSRasesh Mody case ECORE_VPORT:
392149ca6a7bSRasesh Mody mfw_res_id = RESOURCE_NUM_VPORT_E;
392249ca6a7bSRasesh Mody break;
392349ca6a7bSRasesh Mody case ECORE_RSS_ENG:
392449ca6a7bSRasesh Mody mfw_res_id = RESOURCE_NUM_RSS_ENGINES_E;
392549ca6a7bSRasesh Mody break;
392649ca6a7bSRasesh Mody case ECORE_PQ:
392749ca6a7bSRasesh Mody mfw_res_id = RESOURCE_NUM_PQ_E;
392849ca6a7bSRasesh Mody break;
392949ca6a7bSRasesh Mody case ECORE_RL:
393049ca6a7bSRasesh Mody mfw_res_id = RESOURCE_NUM_RL_E;
393149ca6a7bSRasesh Mody break;
393249ca6a7bSRasesh Mody case ECORE_MAC:
393349ca6a7bSRasesh Mody case ECORE_VLAN:
393449ca6a7bSRasesh Mody /* Each VFC resource can accommodate both a MAC and a VLAN */
393549ca6a7bSRasesh Mody mfw_res_id = RESOURCE_VFC_FILTER_E;
393649ca6a7bSRasesh Mody break;
393749ca6a7bSRasesh Mody case ECORE_ILT:
393849ca6a7bSRasesh Mody mfw_res_id = RESOURCE_ILT_E;
393949ca6a7bSRasesh Mody break;
394049ca6a7bSRasesh Mody case ECORE_LL2_QUEUE:
394149ca6a7bSRasesh Mody mfw_res_id = RESOURCE_LL2_QUEUE_E;
394249ca6a7bSRasesh Mody break;
394349ca6a7bSRasesh Mody case ECORE_RDMA_CNQ_RAM:
394449ca6a7bSRasesh Mody case ECORE_CMDQS_CQS:
394549ca6a7bSRasesh Mody /* CNQ/CMDQS are the same resource */
394649ca6a7bSRasesh Mody mfw_res_id = RESOURCE_CQS_E;
394749ca6a7bSRasesh Mody break;
394849ca6a7bSRasesh Mody case ECORE_RDMA_STATS_QUEUE:
394949ca6a7bSRasesh Mody mfw_res_id = RESOURCE_RDMA_STATS_QUEUE_E;
395049ca6a7bSRasesh Mody break;
395149ca6a7bSRasesh Mody case ECORE_BDQ:
395249ca6a7bSRasesh Mody mfw_res_id = RESOURCE_BDQ_E;
395349ca6a7bSRasesh Mody break;
395449ca6a7bSRasesh Mody default:
395549ca6a7bSRasesh Mody break;
395649ca6a7bSRasesh Mody }
395749ca6a7bSRasesh Mody
395849ca6a7bSRasesh Mody return mfw_res_id;
395949ca6a7bSRasesh Mody }
396049ca6a7bSRasesh Mody
396149ca6a7bSRasesh Mody #define ECORE_RESC_ALLOC_VERSION_MAJOR 2
3962252b88b5SHarish Patil #define ECORE_RESC_ALLOC_VERSION_MINOR 0
3963252b88b5SHarish Patil #define ECORE_RESC_ALLOC_VERSION \
3964252b88b5SHarish Patil ((ECORE_RESC_ALLOC_VERSION_MAJOR << \
396504b00049SRasesh Mody DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR_OFFSET) | \
3966252b88b5SHarish Patil (ECORE_RESC_ALLOC_VERSION_MINOR << \
396704b00049SRasesh Mody DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR_OFFSET))
3968252b88b5SHarish Patil
396949ca6a7bSRasesh Mody struct ecore_resc_alloc_in_params {
397049ca6a7bSRasesh Mody u32 cmd;
397149ca6a7bSRasesh Mody enum ecore_resources res_id;
397249ca6a7bSRasesh Mody u32 resc_max_val;
397349ca6a7bSRasesh Mody };
397449ca6a7bSRasesh Mody
397549ca6a7bSRasesh Mody struct ecore_resc_alloc_out_params {
397649ca6a7bSRasesh Mody u32 mcp_resp;
397749ca6a7bSRasesh Mody u32 mcp_param;
397849ca6a7bSRasesh Mody u32 resc_num;
397949ca6a7bSRasesh Mody u32 resc_start;
398049ca6a7bSRasesh Mody u32 vf_resc_num;
398149ca6a7bSRasesh Mody u32 vf_resc_start;
398249ca6a7bSRasesh Mody u32 flags;
398349ca6a7bSRasesh Mody };
398449ca6a7bSRasesh Mody
398560c78a5eSRasesh Mody #define ECORE_RECOVERY_PROLOG_SLEEP_MS 100
398660c78a5eSRasesh Mody
ecore_recovery_prolog(struct ecore_dev * p_dev)398760c78a5eSRasesh Mody enum _ecore_status_t ecore_recovery_prolog(struct ecore_dev *p_dev)
398860c78a5eSRasesh Mody {
398960c78a5eSRasesh Mody struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
399060c78a5eSRasesh Mody struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
399160c78a5eSRasesh Mody enum _ecore_status_t rc;
399260c78a5eSRasesh Mody
399360c78a5eSRasesh Mody /* Allow ongoing PCIe transactions to complete */
399460c78a5eSRasesh Mody OSAL_MSLEEP(ECORE_RECOVERY_PROLOG_SLEEP_MS);
399560c78a5eSRasesh Mody
399660c78a5eSRasesh Mody /* Clear the PF's internal FID_enable in the PXP */
399760c78a5eSRasesh Mody rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_ptt, false);
399860c78a5eSRasesh Mody if (rc != ECORE_SUCCESS)
399960c78a5eSRasesh Mody DP_NOTICE(p_hwfn, false,
400060c78a5eSRasesh Mody "ecore_pglueb_set_pfid_enable() failed. rc = %d.\n",
400160c78a5eSRasesh Mody rc);
400260c78a5eSRasesh Mody
400360c78a5eSRasesh Mody return rc;
400460c78a5eSRasesh Mody }
400560c78a5eSRasesh Mody
400649ca6a7bSRasesh Mody static enum _ecore_status_t
ecore_mcp_resc_allocation_msg(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_resc_alloc_in_params * p_in_params,struct ecore_resc_alloc_out_params * p_out_params)400749ca6a7bSRasesh Mody ecore_mcp_resc_allocation_msg(struct ecore_hwfn *p_hwfn,
4008252b88b5SHarish Patil struct ecore_ptt *p_ptt,
400949ca6a7bSRasesh Mody struct ecore_resc_alloc_in_params *p_in_params,
401049ca6a7bSRasesh Mody struct ecore_resc_alloc_out_params *p_out_params)
4011252b88b5SHarish Patil {
4012252b88b5SHarish Patil struct ecore_mcp_mb_params mb_params;
4013e32dc0f7SRasesh Mody struct resource_info mfw_resc_info;
4014252b88b5SHarish Patil enum _ecore_status_t rc;
4015252b88b5SHarish Patil
4016e32dc0f7SRasesh Mody OSAL_MEM_ZERO(&mfw_resc_info, sizeof(mfw_resc_info));
401749ca6a7bSRasesh Mody
4018e32dc0f7SRasesh Mody mfw_resc_info.res_id = ecore_mcp_get_mfw_res_id(p_in_params->res_id);
4019e32dc0f7SRasesh Mody if (mfw_resc_info.res_id == RESOURCE_NUM_INVALID) {
402049ca6a7bSRasesh Mody DP_ERR(p_hwfn,
402149ca6a7bSRasesh Mody "Failed to match resource %d [%s] with the MFW resources\n",
402249ca6a7bSRasesh Mody p_in_params->res_id,
402349ca6a7bSRasesh Mody ecore_hw_get_resc_name(p_in_params->res_id));
402449ca6a7bSRasesh Mody return ECORE_INVAL;
402549ca6a7bSRasesh Mody }
402649ca6a7bSRasesh Mody
402749ca6a7bSRasesh Mody switch (p_in_params->cmd) {
402849ca6a7bSRasesh Mody case DRV_MSG_SET_RESOURCE_VALUE_MSG:
4029e32dc0f7SRasesh Mody mfw_resc_info.size = p_in_params->resc_max_val;
403049ca6a7bSRasesh Mody /* Fallthrough */
403149ca6a7bSRasesh Mody case DRV_MSG_GET_RESOURCE_ALLOC_MSG:
403249ca6a7bSRasesh Mody break;
403349ca6a7bSRasesh Mody default:
403449ca6a7bSRasesh Mody DP_ERR(p_hwfn, "Unexpected resource alloc command [0x%08x]\n",
403549ca6a7bSRasesh Mody p_in_params->cmd);
403649ca6a7bSRasesh Mody return ECORE_INVAL;
403749ca6a7bSRasesh Mody }
403849ca6a7bSRasesh Mody
4039252b88b5SHarish Patil OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
404049ca6a7bSRasesh Mody mb_params.cmd = p_in_params->cmd;
4041252b88b5SHarish Patil mb_params.param = ECORE_RESC_ALLOC_VERSION;
4042e32dc0f7SRasesh Mody mb_params.p_data_src = &mfw_resc_info;
4043e32dc0f7SRasesh Mody mb_params.data_src_size = sizeof(mfw_resc_info);
4044e32dc0f7SRasesh Mody mb_params.p_data_dst = mb_params.p_data_src;
4045e32dc0f7SRasesh Mody mb_params.data_dst_size = mb_params.data_src_size;
404649ca6a7bSRasesh Mody
404749ca6a7bSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
404849ca6a7bSRasesh Mody "Resource message request: cmd 0x%08x, res_id %d [%s], hsi_version %d.%d, val 0x%x\n",
404949ca6a7bSRasesh Mody p_in_params->cmd, p_in_params->res_id,
405049ca6a7bSRasesh Mody ecore_hw_get_resc_name(p_in_params->res_id),
405104b00049SRasesh Mody GET_MFW_FIELD(mb_params.param,
405249ca6a7bSRasesh Mody DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR),
405304b00049SRasesh Mody GET_MFW_FIELD(mb_params.param,
405449ca6a7bSRasesh Mody DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR),
405549ca6a7bSRasesh Mody p_in_params->resc_max_val);
405649ca6a7bSRasesh Mody
4057252b88b5SHarish Patil rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
4058252b88b5SHarish Patil if (rc != ECORE_SUCCESS)
4059252b88b5SHarish Patil return rc;
4060252b88b5SHarish Patil
406149ca6a7bSRasesh Mody p_out_params->mcp_resp = mb_params.mcp_resp;
406249ca6a7bSRasesh Mody p_out_params->mcp_param = mb_params.mcp_param;
4063e32dc0f7SRasesh Mody p_out_params->resc_num = mfw_resc_info.size;
4064e32dc0f7SRasesh Mody p_out_params->resc_start = mfw_resc_info.offset;
4065e32dc0f7SRasesh Mody p_out_params->vf_resc_num = mfw_resc_info.vf_size;
4066e32dc0f7SRasesh Mody p_out_params->vf_resc_start = mfw_resc_info.vf_offset;
4067e32dc0f7SRasesh Mody p_out_params->flags = mfw_resc_info.flags;
406868cd48d0SRasesh Mody
4069252b88b5SHarish Patil DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
407049ca6a7bSRasesh Mody "Resource message response: mfw_hsi_version %d.%d, num 0x%x, start 0x%x, vf_num 0x%x, vf_start 0x%x, flags 0x%08x\n",
407104b00049SRasesh Mody GET_MFW_FIELD(p_out_params->mcp_param,
407249ca6a7bSRasesh Mody FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR),
407304b00049SRasesh Mody GET_MFW_FIELD(p_out_params->mcp_param,
407449ca6a7bSRasesh Mody FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR),
407549ca6a7bSRasesh Mody p_out_params->resc_num, p_out_params->resc_start,
407649ca6a7bSRasesh Mody p_out_params->vf_resc_num, p_out_params->vf_resc_start,
407749ca6a7bSRasesh Mody p_out_params->flags);
407849ca6a7bSRasesh Mody
407949ca6a7bSRasesh Mody return ECORE_SUCCESS;
408049ca6a7bSRasesh Mody }
408149ca6a7bSRasesh Mody
408249ca6a7bSRasesh Mody enum _ecore_status_t
ecore_mcp_set_resc_max_val(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_resources res_id,u32 resc_max_val,u32 * p_mcp_resp)408349ca6a7bSRasesh Mody ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
408449ca6a7bSRasesh Mody enum ecore_resources res_id, u32 resc_max_val,
408549ca6a7bSRasesh Mody u32 *p_mcp_resp)
408649ca6a7bSRasesh Mody {
408749ca6a7bSRasesh Mody struct ecore_resc_alloc_out_params out_params;
408849ca6a7bSRasesh Mody struct ecore_resc_alloc_in_params in_params;
408949ca6a7bSRasesh Mody enum _ecore_status_t rc;
409049ca6a7bSRasesh Mody
409149ca6a7bSRasesh Mody OSAL_MEM_ZERO(&in_params, sizeof(in_params));
409249ca6a7bSRasesh Mody in_params.cmd = DRV_MSG_SET_RESOURCE_VALUE_MSG;
409349ca6a7bSRasesh Mody in_params.res_id = res_id;
409449ca6a7bSRasesh Mody in_params.resc_max_val = resc_max_val;
409549ca6a7bSRasesh Mody OSAL_MEM_ZERO(&out_params, sizeof(out_params));
409649ca6a7bSRasesh Mody rc = ecore_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params,
409749ca6a7bSRasesh Mody &out_params);
409849ca6a7bSRasesh Mody if (rc != ECORE_SUCCESS)
409949ca6a7bSRasesh Mody return rc;
410049ca6a7bSRasesh Mody
410149ca6a7bSRasesh Mody *p_mcp_resp = out_params.mcp_resp;
410249ca6a7bSRasesh Mody
410349ca6a7bSRasesh Mody return ECORE_SUCCESS;
410449ca6a7bSRasesh Mody }
410549ca6a7bSRasesh Mody
410649ca6a7bSRasesh Mody enum _ecore_status_t
ecore_mcp_get_resc_info(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,enum ecore_resources res_id,u32 * p_mcp_resp,u32 * p_resc_num,u32 * p_resc_start)410749ca6a7bSRasesh Mody ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
410849ca6a7bSRasesh Mody enum ecore_resources res_id, u32 *p_mcp_resp,
410949ca6a7bSRasesh Mody u32 *p_resc_num, u32 *p_resc_start)
411049ca6a7bSRasesh Mody {
411149ca6a7bSRasesh Mody struct ecore_resc_alloc_out_params out_params;
411249ca6a7bSRasesh Mody struct ecore_resc_alloc_in_params in_params;
411349ca6a7bSRasesh Mody enum _ecore_status_t rc;
411449ca6a7bSRasesh Mody
411549ca6a7bSRasesh Mody OSAL_MEM_ZERO(&in_params, sizeof(in_params));
411649ca6a7bSRasesh Mody in_params.cmd = DRV_MSG_GET_RESOURCE_ALLOC_MSG;
411749ca6a7bSRasesh Mody in_params.res_id = res_id;
411849ca6a7bSRasesh Mody OSAL_MEM_ZERO(&out_params, sizeof(out_params));
411949ca6a7bSRasesh Mody rc = ecore_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params,
412049ca6a7bSRasesh Mody &out_params);
412149ca6a7bSRasesh Mody if (rc != ECORE_SUCCESS)
412249ca6a7bSRasesh Mody return rc;
412349ca6a7bSRasesh Mody
412449ca6a7bSRasesh Mody *p_mcp_resp = out_params.mcp_resp;
412549ca6a7bSRasesh Mody
412649ca6a7bSRasesh Mody if (*p_mcp_resp == FW_MSG_CODE_RESOURCE_ALLOC_OK) {
412749ca6a7bSRasesh Mody *p_resc_num = out_params.resc_num;
412849ca6a7bSRasesh Mody *p_resc_start = out_params.resc_start;
412949ca6a7bSRasesh Mody }
4130252b88b5SHarish Patil
4131252b88b5SHarish Patil return ECORE_SUCCESS;
4132252b88b5SHarish Patil }
413340c926baSHarish Patil
ecore_mcp_initiate_pf_flr(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)413440c926baSHarish Patil enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
413540c926baSHarish Patil struct ecore_ptt *p_ptt)
413640c926baSHarish Patil {
413740c926baSHarish Patil u32 mcp_resp, mcp_param;
413840c926baSHarish Patil
41399e2f08a4SRasesh Mody return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_INITIATE_PF_FLR, 0,
41409e2f08a4SRasesh Mody &mcp_resp, &mcp_param);
414140c926baSHarish Patil }
41428a20e270SRasesh Mody
ecore_mcp_resource_cmd(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 param,u32 * p_mcp_resp,u32 * p_mcp_param)41438a20e270SRasesh Mody static enum _ecore_status_t ecore_mcp_resource_cmd(struct ecore_hwfn *p_hwfn,
41448a20e270SRasesh Mody struct ecore_ptt *p_ptt,
41458a20e270SRasesh Mody u32 param, u32 *p_mcp_resp,
41468a20e270SRasesh Mody u32 *p_mcp_param)
41478a20e270SRasesh Mody {
41488a20e270SRasesh Mody enum _ecore_status_t rc;
41498a20e270SRasesh Mody
41508a20e270SRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_RESOURCE_CMD, param,
41518a20e270SRasesh Mody p_mcp_resp, p_mcp_param);
41528a20e270SRasesh Mody if (rc != ECORE_SUCCESS)
41538a20e270SRasesh Mody return rc;
41548a20e270SRasesh Mody
415549ca6a7bSRasesh Mody if (*p_mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
415649ca6a7bSRasesh Mody DP_INFO(p_hwfn,
415749ca6a7bSRasesh Mody "The resource command is unsupported by the MFW\n");
41588a20e270SRasesh Mody return ECORE_NOTIMPL;
415949ca6a7bSRasesh Mody }
41608a20e270SRasesh Mody
41618a20e270SRasesh Mody if (*p_mcp_param == RESOURCE_OPCODE_UNKNOWN_CMD) {
416204b00049SRasesh Mody u8 opcode = GET_MFW_FIELD(param, RESOURCE_CMD_REQ_OPCODE);
41638a20e270SRasesh Mody
41648a20e270SRasesh Mody DP_NOTICE(p_hwfn, false,
41658a20e270SRasesh Mody "The resource command is unknown to the MFW [param 0x%08x, opcode %d]\n",
41668a20e270SRasesh Mody param, opcode);
41678a20e270SRasesh Mody return ECORE_INVAL;
41688a20e270SRasesh Mody }
41698a20e270SRasesh Mody
41708a20e270SRasesh Mody return rc;
41718a20e270SRasesh Mody }
41728a20e270SRasesh Mody
417349ca6a7bSRasesh Mody enum _ecore_status_t
__ecore_mcp_resc_lock(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_resc_lock_params * p_params)417449ca6a7bSRasesh Mody __ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
417549ca6a7bSRasesh Mody struct ecore_resc_lock_params *p_params)
41768a20e270SRasesh Mody {
4177db8af647SAndrzej Ostruszka u32 param = 0, mcp_resp = 0, mcp_param = 0;
41788a20e270SRasesh Mody u8 opcode;
41798a20e270SRasesh Mody enum _ecore_status_t rc;
41808a20e270SRasesh Mody
418149ca6a7bSRasesh Mody switch (p_params->timeout) {
41828a20e270SRasesh Mody case ECORE_MCP_RESC_LOCK_TO_DEFAULT:
41838a20e270SRasesh Mody opcode = RESOURCE_OPCODE_REQ;
418449ca6a7bSRasesh Mody p_params->timeout = 0;
41858a20e270SRasesh Mody break;
41868a20e270SRasesh Mody case ECORE_MCP_RESC_LOCK_TO_NONE:
41878a20e270SRasesh Mody opcode = RESOURCE_OPCODE_REQ_WO_AGING;
418849ca6a7bSRasesh Mody p_params->timeout = 0;
41898a20e270SRasesh Mody break;
41908a20e270SRasesh Mody default:
41918a20e270SRasesh Mody opcode = RESOURCE_OPCODE_REQ_W_AGING;
41928a20e270SRasesh Mody break;
41938a20e270SRasesh Mody }
41948a20e270SRasesh Mody
419504b00049SRasesh Mody SET_MFW_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource);
419604b00049SRasesh Mody SET_MFW_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode);
419704b00049SRasesh Mody SET_MFW_FIELD(param, RESOURCE_CMD_REQ_AGE, p_params->timeout);
41988a20e270SRasesh Mody
41998a20e270SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
420049ca6a7bSRasesh Mody "Resource lock request: param 0x%08x [age %d, opcode %d, resource %d]\n",
420149ca6a7bSRasesh Mody param, p_params->timeout, opcode, p_params->resource);
42028a20e270SRasesh Mody
42038a20e270SRasesh Mody /* Attempt to acquire the resource */
42048a20e270SRasesh Mody rc = ecore_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp,
42058a20e270SRasesh Mody &mcp_param);
42068a20e270SRasesh Mody if (rc != ECORE_SUCCESS)
42078a20e270SRasesh Mody return rc;
42088a20e270SRasesh Mody
42098a20e270SRasesh Mody /* Analyze the response */
421004b00049SRasesh Mody p_params->owner = GET_MFW_FIELD(mcp_param, RESOURCE_CMD_RSP_OWNER);
421104b00049SRasesh Mody opcode = GET_MFW_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE);
42128a20e270SRasesh Mody
42138a20e270SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
42148a20e270SRasesh Mody "Resource lock response: mcp_param 0x%08x [opcode %d, owner %d]\n",
421549ca6a7bSRasesh Mody mcp_param, opcode, p_params->owner);
42168a20e270SRasesh Mody
42178a20e270SRasesh Mody switch (opcode) {
42188a20e270SRasesh Mody case RESOURCE_OPCODE_GNT:
421949ca6a7bSRasesh Mody p_params->b_granted = true;
42208a20e270SRasesh Mody break;
42218a20e270SRasesh Mody case RESOURCE_OPCODE_BUSY:
422249ca6a7bSRasesh Mody p_params->b_granted = false;
42238a20e270SRasesh Mody break;
42248a20e270SRasesh Mody default:
42258a20e270SRasesh Mody DP_NOTICE(p_hwfn, false,
42268a20e270SRasesh Mody "Unexpected opcode in resource lock response [mcp_param 0x%08x, opcode %d]\n",
42278a20e270SRasesh Mody mcp_param, opcode);
42288a20e270SRasesh Mody return ECORE_INVAL;
42298a20e270SRasesh Mody }
42308a20e270SRasesh Mody
42318a20e270SRasesh Mody return ECORE_SUCCESS;
42328a20e270SRasesh Mody }
42338a20e270SRasesh Mody
423449ca6a7bSRasesh Mody enum _ecore_status_t
ecore_mcp_resc_lock(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_resc_lock_params * p_params)423549ca6a7bSRasesh Mody ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
423649ca6a7bSRasesh Mody struct ecore_resc_lock_params *p_params)
423749ca6a7bSRasesh Mody {
423849ca6a7bSRasesh Mody u32 retry_cnt = 0;
423949ca6a7bSRasesh Mody enum _ecore_status_t rc;
424049ca6a7bSRasesh Mody
424149ca6a7bSRasesh Mody do {
424249ca6a7bSRasesh Mody /* No need for an interval before the first iteration */
424349ca6a7bSRasesh Mody if (retry_cnt) {
424449ca6a7bSRasesh Mody if (p_params->sleep_b4_retry) {
424549ca6a7bSRasesh Mody u16 retry_interval_in_ms =
424649ca6a7bSRasesh Mody DIV_ROUND_UP(p_params->retry_interval,
424749ca6a7bSRasesh Mody 1000);
424849ca6a7bSRasesh Mody
424949ca6a7bSRasesh Mody OSAL_MSLEEP(retry_interval_in_ms);
425049ca6a7bSRasesh Mody } else {
425149ca6a7bSRasesh Mody OSAL_UDELAY(p_params->retry_interval);
425249ca6a7bSRasesh Mody }
425349ca6a7bSRasesh Mody }
425449ca6a7bSRasesh Mody
425549ca6a7bSRasesh Mody rc = __ecore_mcp_resc_lock(p_hwfn, p_ptt, p_params);
425649ca6a7bSRasesh Mody if (rc != ECORE_SUCCESS)
425749ca6a7bSRasesh Mody return rc;
425849ca6a7bSRasesh Mody
425949ca6a7bSRasesh Mody if (p_params->b_granted)
426049ca6a7bSRasesh Mody break;
426149ca6a7bSRasesh Mody } while (retry_cnt++ < p_params->retry_num);
426249ca6a7bSRasesh Mody
426349ca6a7bSRasesh Mody return ECORE_SUCCESS;
426449ca6a7bSRasesh Mody }
426549ca6a7bSRasesh Mody
ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params * p_lock,struct ecore_resc_unlock_params * p_unlock,enum ecore_resc_lock resource,bool b_is_permanent)426630ecf673SRasesh Mody void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
426740a373fcSRasesh Mody struct ecore_resc_unlock_params *p_unlock,
426840a373fcSRasesh Mody enum ecore_resc_lock resource,
426940a373fcSRasesh Mody bool b_is_permanent)
427040a373fcSRasesh Mody {
427140a373fcSRasesh Mody if (p_lock != OSAL_NULL) {
427240a373fcSRasesh Mody OSAL_MEM_ZERO(p_lock, sizeof(*p_lock));
427340a373fcSRasesh Mody
427440a373fcSRasesh Mody /* Permanent resources don't require aging, and there's no
427540a373fcSRasesh Mody * point in trying to acquire them more than once since it's
427640a373fcSRasesh Mody * unexpected another entity would release them.
427740a373fcSRasesh Mody */
427840a373fcSRasesh Mody if (b_is_permanent) {
427940a373fcSRasesh Mody p_lock->timeout = ECORE_MCP_RESC_LOCK_TO_NONE;
428040a373fcSRasesh Mody } else {
428140a373fcSRasesh Mody p_lock->retry_num = ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT;
428240a373fcSRasesh Mody p_lock->retry_interval =
428340a373fcSRasesh Mody ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT;
428440a373fcSRasesh Mody p_lock->sleep_b4_retry = true;
428540a373fcSRasesh Mody }
428640a373fcSRasesh Mody
428740a373fcSRasesh Mody p_lock->resource = resource;
428840a373fcSRasesh Mody }
428940a373fcSRasesh Mody
429040a373fcSRasesh Mody if (p_unlock != OSAL_NULL) {
429140a373fcSRasesh Mody OSAL_MEM_ZERO(p_unlock, sizeof(*p_unlock));
429240a373fcSRasesh Mody p_unlock->resource = resource;
429340a373fcSRasesh Mody }
429440a373fcSRasesh Mody }
429540a373fcSRasesh Mody
429649ca6a7bSRasesh Mody enum _ecore_status_t
ecore_mcp_resc_unlock(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_resc_unlock_params * p_params)429749ca6a7bSRasesh Mody ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
429849ca6a7bSRasesh Mody struct ecore_resc_unlock_params *p_params)
42998a20e270SRasesh Mody {
43008a20e270SRasesh Mody u32 param = 0, mcp_resp, mcp_param;
43018a20e270SRasesh Mody u8 opcode;
43028a20e270SRasesh Mody enum _ecore_status_t rc;
43038a20e270SRasesh Mody
430449ca6a7bSRasesh Mody opcode = p_params->b_force ? RESOURCE_OPCODE_FORCE_RELEASE
43058a20e270SRasesh Mody : RESOURCE_OPCODE_RELEASE;
430604b00049SRasesh Mody SET_MFW_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource);
430704b00049SRasesh Mody SET_MFW_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode);
43088a20e270SRasesh Mody
43098a20e270SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
431049ca6a7bSRasesh Mody "Resource unlock request: param 0x%08x [opcode %d, resource %d]\n",
431149ca6a7bSRasesh Mody param, opcode, p_params->resource);
43128a20e270SRasesh Mody
43138a20e270SRasesh Mody /* Attempt to release the resource */
43148a20e270SRasesh Mody rc = ecore_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp,
43158a20e270SRasesh Mody &mcp_param);
43168a20e270SRasesh Mody if (rc != ECORE_SUCCESS)
43178a20e270SRasesh Mody return rc;
43188a20e270SRasesh Mody
43198a20e270SRasesh Mody /* Analyze the response */
432004b00049SRasesh Mody opcode = GET_MFW_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE);
43218a20e270SRasesh Mody
43228a20e270SRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
43238a20e270SRasesh Mody "Resource unlock response: mcp_param 0x%08x [opcode %d]\n",
43248a20e270SRasesh Mody mcp_param, opcode);
43258a20e270SRasesh Mody
43268a20e270SRasesh Mody switch (opcode) {
43278a20e270SRasesh Mody case RESOURCE_OPCODE_RELEASED_PREVIOUS:
43288a20e270SRasesh Mody DP_INFO(p_hwfn,
432949ca6a7bSRasesh Mody "Resource unlock request for an already released resource [%d]\n",
433049ca6a7bSRasesh Mody p_params->resource);
43318a20e270SRasesh Mody /* Fallthrough */
43328a20e270SRasesh Mody case RESOURCE_OPCODE_RELEASED:
433349ca6a7bSRasesh Mody p_params->b_released = true;
43348a20e270SRasesh Mody break;
43358a20e270SRasesh Mody case RESOURCE_OPCODE_WRONG_OWNER:
433649ca6a7bSRasesh Mody p_params->b_released = false;
43378a20e270SRasesh Mody break;
43388a20e270SRasesh Mody default:
43398a20e270SRasesh Mody DP_NOTICE(p_hwfn, false,
43408a20e270SRasesh Mody "Unexpected opcode in resource unlock response [mcp_param 0x%08x, opcode %d]\n",
43418a20e270SRasesh Mody mcp_param, opcode);
43428a20e270SRasesh Mody return ECORE_INVAL;
43438a20e270SRasesh Mody }
43448a20e270SRasesh Mody
43458a20e270SRasesh Mody return ECORE_SUCCESS;
43468a20e270SRasesh Mody }
4347652ee28aSRasesh Mody
ecore_mcp_is_smart_an_supported(struct ecore_hwfn * p_hwfn)4348652ee28aSRasesh Mody bool ecore_mcp_is_smart_an_supported(struct ecore_hwfn *p_hwfn)
4349652ee28aSRasesh Mody {
4350652ee28aSRasesh Mody return !!(p_hwfn->mcp_info->capabilities &
4351652ee28aSRasesh Mody FW_MB_PARAM_FEATURE_SUPPORT_SMARTLINQ);
4352652ee28aSRasesh Mody }
4353652ee28aSRasesh Mody
ecore_mcp_get_capabilities(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)4354652ee28aSRasesh Mody enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
4355652ee28aSRasesh Mody struct ecore_ptt *p_ptt)
4356652ee28aSRasesh Mody {
4357652ee28aSRasesh Mody u32 mcp_resp;
4358652ee28aSRasesh Mody enum _ecore_status_t rc;
4359652ee28aSRasesh Mody
4360652ee28aSRasesh Mody rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GET_MFW_FEATURE_SUPPORT,
4361652ee28aSRasesh Mody 0, &mcp_resp, &p_hwfn->mcp_info->capabilities);
4362652ee28aSRasesh Mody if (rc == ECORE_SUCCESS)
4363652ee28aSRasesh Mody DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_PROBE),
4364652ee28aSRasesh Mody "MFW supported features: %08x\n",
4365652ee28aSRasesh Mody p_hwfn->mcp_info->capabilities);
4366652ee28aSRasesh Mody
4367652ee28aSRasesh Mody return rc;
4368652ee28aSRasesh Mody }
4369652ee28aSRasesh Mody
ecore_mcp_set_capabilities(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)4370652ee28aSRasesh Mody enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
4371652ee28aSRasesh Mody struct ecore_ptt *p_ptt)
4372652ee28aSRasesh Mody {
4373652ee28aSRasesh Mody u32 mcp_resp, mcp_param, features;
4374652ee28aSRasesh Mody
43753c6a3cf6SRasesh Mody features = DRV_MB_PARAM_FEATURE_SUPPORT_PORT_SMARTLINQ |
4376fe0deb21SRasesh Mody DRV_MB_PARAM_FEATURE_SUPPORT_PORT_EEE |
4377fe0deb21SRasesh Mody DRV_MB_PARAM_FEATURE_SUPPORT_FUNC_VLINK;
4378652ee28aSRasesh Mody
4379652ee28aSRasesh Mody return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_FEATURE_SUPPORT,
4380652ee28aSRasesh Mody features, &mcp_resp, &mcp_param);
4381652ee28aSRasesh Mody }
4382f5940e7dSRasesh Mody
4383f5940e7dSRasesh Mody enum _ecore_status_t
ecore_mcp_drv_attribute(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,struct ecore_mcp_drv_attr * p_drv_attr)4384f5940e7dSRasesh Mody ecore_mcp_drv_attribute(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
4385f5940e7dSRasesh Mody struct ecore_mcp_drv_attr *p_drv_attr)
4386f5940e7dSRasesh Mody {
4387f5940e7dSRasesh Mody struct attribute_cmd_write_stc attr_cmd_write;
4388f5940e7dSRasesh Mody enum _attribute_commands_e mfw_attr_cmd;
4389f5940e7dSRasesh Mody struct ecore_mcp_mb_params mb_params;
4390f5940e7dSRasesh Mody enum _ecore_status_t rc;
4391f5940e7dSRasesh Mody
4392f5940e7dSRasesh Mody switch (p_drv_attr->attr_cmd) {
4393f5940e7dSRasesh Mody case ECORE_MCP_DRV_ATTR_CMD_READ:
4394f5940e7dSRasesh Mody mfw_attr_cmd = ATTRIBUTE_CMD_READ;
4395f5940e7dSRasesh Mody break;
4396f5940e7dSRasesh Mody case ECORE_MCP_DRV_ATTR_CMD_WRITE:
4397f5940e7dSRasesh Mody mfw_attr_cmd = ATTRIBUTE_CMD_WRITE;
4398f5940e7dSRasesh Mody break;
4399f5940e7dSRasesh Mody case ECORE_MCP_DRV_ATTR_CMD_READ_CLEAR:
4400f5940e7dSRasesh Mody mfw_attr_cmd = ATTRIBUTE_CMD_READ_CLEAR;
4401f5940e7dSRasesh Mody break;
4402f5940e7dSRasesh Mody case ECORE_MCP_DRV_ATTR_CMD_CLEAR:
4403f5940e7dSRasesh Mody mfw_attr_cmd = ATTRIBUTE_CMD_CLEAR;
4404f5940e7dSRasesh Mody break;
4405f5940e7dSRasesh Mody default:
4406f5940e7dSRasesh Mody DP_NOTICE(p_hwfn, false, "Unknown attribute command %d\n",
4407f5940e7dSRasesh Mody p_drv_attr->attr_cmd);
4408f5940e7dSRasesh Mody return ECORE_INVAL;
4409f5940e7dSRasesh Mody }
4410f5940e7dSRasesh Mody
4411f5940e7dSRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
4412f5940e7dSRasesh Mody mb_params.cmd = DRV_MSG_CODE_ATTRIBUTE;
4413f5940e7dSRasesh Mody SET_MFW_FIELD(mb_params.param, DRV_MB_PARAM_ATTRIBUTE_KEY,
4414f5940e7dSRasesh Mody p_drv_attr->attr_num);
4415f5940e7dSRasesh Mody SET_MFW_FIELD(mb_params.param, DRV_MB_PARAM_ATTRIBUTE_CMD,
4416f5940e7dSRasesh Mody mfw_attr_cmd);
4417f5940e7dSRasesh Mody if (p_drv_attr->attr_cmd == ECORE_MCP_DRV_ATTR_CMD_WRITE) {
4418f5940e7dSRasesh Mody OSAL_MEM_ZERO(&attr_cmd_write, sizeof(attr_cmd_write));
4419f5940e7dSRasesh Mody attr_cmd_write.val = p_drv_attr->val;
4420f5940e7dSRasesh Mody attr_cmd_write.mask = p_drv_attr->mask;
4421f5940e7dSRasesh Mody attr_cmd_write.offset = p_drv_attr->offset;
4422f5940e7dSRasesh Mody
4423f5940e7dSRasesh Mody mb_params.p_data_src = &attr_cmd_write;
4424f5940e7dSRasesh Mody mb_params.data_src_size = sizeof(attr_cmd_write);
4425f5940e7dSRasesh Mody }
4426f5940e7dSRasesh Mody
4427f5940e7dSRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
4428f5940e7dSRasesh Mody if (rc != ECORE_SUCCESS)
4429f5940e7dSRasesh Mody return rc;
4430f5940e7dSRasesh Mody
4431f5940e7dSRasesh Mody if (mb_params.mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
4432f5940e7dSRasesh Mody DP_INFO(p_hwfn,
4433f5940e7dSRasesh Mody "The attribute command is not supported by the MFW\n");
4434f5940e7dSRasesh Mody return ECORE_NOTIMPL;
4435f5940e7dSRasesh Mody } else if (mb_params.mcp_resp != FW_MSG_CODE_OK) {
4436f5940e7dSRasesh Mody DP_INFO(p_hwfn,
4437f5940e7dSRasesh Mody "Failed to send an attribute command [mcp_resp 0x%x, attr_cmd %d, attr_num %d]\n",
4438f5940e7dSRasesh Mody mb_params.mcp_resp, p_drv_attr->attr_cmd,
4439f5940e7dSRasesh Mody p_drv_attr->attr_num);
4440f5940e7dSRasesh Mody return ECORE_INVAL;
4441f5940e7dSRasesh Mody }
4442f5940e7dSRasesh Mody
4443f5940e7dSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
4444f5940e7dSRasesh Mody "Attribute Command: cmd %d [mfw_cmd %d], num %d, in={val 0x%08x, mask 0x%08x, offset 0x%08x}, out={val 0x%08x}\n",
4445f5940e7dSRasesh Mody p_drv_attr->attr_cmd, mfw_attr_cmd, p_drv_attr->attr_num,
4446f5940e7dSRasesh Mody p_drv_attr->val, p_drv_attr->mask, p_drv_attr->offset,
4447f5940e7dSRasesh Mody mb_params.mcp_param);
4448f5940e7dSRasesh Mody
4449f5940e7dSRasesh Mody if (p_drv_attr->attr_cmd == ECORE_MCP_DRV_ATTR_CMD_READ ||
4450f5940e7dSRasesh Mody p_drv_attr->attr_cmd == ECORE_MCP_DRV_ATTR_CMD_READ_CLEAR)
4451f5940e7dSRasesh Mody p_drv_attr->val = mb_params.mcp_param;
4452f5940e7dSRasesh Mody
4453f5940e7dSRasesh Mody return ECORE_SUCCESS;
4454f5940e7dSRasesh Mody }
44552fdeb693SRasesh Mody
ecore_mcp_get_engine_config(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)44563eed444aSRasesh Mody enum _ecore_status_t ecore_mcp_get_engine_config(struct ecore_hwfn *p_hwfn,
44573eed444aSRasesh Mody struct ecore_ptt *p_ptt)
44583eed444aSRasesh Mody {
44593eed444aSRasesh Mody struct ecore_dev *p_dev = p_hwfn->p_dev;
44603eed444aSRasesh Mody struct ecore_mcp_mb_params mb_params;
44613eed444aSRasesh Mody u8 fir_valid, l2_valid;
44623eed444aSRasesh Mody enum _ecore_status_t rc;
44633eed444aSRasesh Mody
44643eed444aSRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
44653eed444aSRasesh Mody mb_params.cmd = DRV_MSG_CODE_GET_ENGINE_CONFIG;
44663eed444aSRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
44673eed444aSRasesh Mody if (rc != ECORE_SUCCESS)
44683eed444aSRasesh Mody return rc;
44693eed444aSRasesh Mody
44703eed444aSRasesh Mody if (mb_params.mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
44713eed444aSRasesh Mody DP_INFO(p_hwfn,
44723eed444aSRasesh Mody "The get_engine_config command is unsupported by the MFW\n");
44733eed444aSRasesh Mody return ECORE_NOTIMPL;
44743eed444aSRasesh Mody }
44753eed444aSRasesh Mody
44763eed444aSRasesh Mody fir_valid = GET_MFW_FIELD(mb_params.mcp_param,
44773eed444aSRasesh Mody FW_MB_PARAM_ENG_CFG_FIR_AFFIN_VALID);
44783eed444aSRasesh Mody if (fir_valid)
44793eed444aSRasesh Mody p_dev->fir_affin =
44803eed444aSRasesh Mody GET_MFW_FIELD(mb_params.mcp_param,
44813eed444aSRasesh Mody FW_MB_PARAM_ENG_CFG_FIR_AFFIN_VALUE);
44823eed444aSRasesh Mody
44833eed444aSRasesh Mody l2_valid = GET_MFW_FIELD(mb_params.mcp_param,
44843eed444aSRasesh Mody FW_MB_PARAM_ENG_CFG_L2_AFFIN_VALID);
44853eed444aSRasesh Mody if (l2_valid)
44863eed444aSRasesh Mody p_dev->l2_affin_hint =
44873eed444aSRasesh Mody GET_MFW_FIELD(mb_params.mcp_param,
44883eed444aSRasesh Mody FW_MB_PARAM_ENG_CFG_L2_AFFIN_VALUE);
44893eed444aSRasesh Mody
44903eed444aSRasesh Mody DP_INFO(p_hwfn,
44913eed444aSRasesh Mody "Engine affinity config: FIR={valid %hhd, value %hhd}, L2_hint={valid %hhd, value %hhd}\n",
44923eed444aSRasesh Mody fir_valid, p_dev->fir_affin, l2_valid, p_dev->l2_affin_hint);
44933eed444aSRasesh Mody
44943eed444aSRasesh Mody return ECORE_SUCCESS;
44953eed444aSRasesh Mody }
44963eed444aSRasesh Mody
ecore_mcp_get_ppfid_bitmap(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt)44973eed444aSRasesh Mody enum _ecore_status_t ecore_mcp_get_ppfid_bitmap(struct ecore_hwfn *p_hwfn,
44983eed444aSRasesh Mody struct ecore_ptt *p_ptt)
44993eed444aSRasesh Mody {
45003eed444aSRasesh Mody struct ecore_dev *p_dev = p_hwfn->p_dev;
45013eed444aSRasesh Mody struct ecore_mcp_mb_params mb_params;
45023eed444aSRasesh Mody enum _ecore_status_t rc;
45033eed444aSRasesh Mody
45043eed444aSRasesh Mody OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
45053eed444aSRasesh Mody mb_params.cmd = DRV_MSG_CODE_GET_PPFID_BITMAP;
45063eed444aSRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
45073eed444aSRasesh Mody if (rc != ECORE_SUCCESS)
45083eed444aSRasesh Mody return rc;
45093eed444aSRasesh Mody
45103eed444aSRasesh Mody if (mb_params.mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
45113eed444aSRasesh Mody DP_INFO(p_hwfn,
45123eed444aSRasesh Mody "The get_ppfid_bitmap command is unsupported by the MFW\n");
45133eed444aSRasesh Mody return ECORE_NOTIMPL;
45143eed444aSRasesh Mody }
45153eed444aSRasesh Mody
45163eed444aSRasesh Mody p_dev->ppfid_bitmap = GET_MFW_FIELD(mb_params.mcp_param,
45173eed444aSRasesh Mody FW_MB_PARAM_PPFID_BITMAP);
45183eed444aSRasesh Mody
45193eed444aSRasesh Mody DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "PPFID bitmap 0x%hhx\n",
45203eed444aSRasesh Mody p_dev->ppfid_bitmap);
45213eed444aSRasesh Mody
45223eed444aSRasesh Mody return ECORE_SUCCESS;
45233eed444aSRasesh Mody }
45243eed444aSRasesh Mody
ecore_mcp_wol_wr(struct ecore_hwfn * p_hwfn,struct ecore_ptt * p_ptt,u32 offset,u32 val)45252fdeb693SRasesh Mody void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
45262fdeb693SRasesh Mody u32 offset, u32 val)
45272fdeb693SRasesh Mody {
45282fdeb693SRasesh Mody enum _ecore_status_t rc = ECORE_SUCCESS;
45292fdeb693SRasesh Mody u32 dword = val;
45309ed26bc7SRasesh Mody struct ecore_mcp_mb_params mb_params;
45312fdeb693SRasesh Mody
45329ed26bc7SRasesh Mody OSAL_MEMSET(&mb_params, 0, sizeof(struct ecore_mcp_mb_params));
45332fdeb693SRasesh Mody mb_params.cmd = DRV_MSG_CODE_WRITE_WOL_REG;
45342fdeb693SRasesh Mody mb_params.param = offset;
45352fdeb693SRasesh Mody mb_params.p_data_src = &dword;
45362fdeb693SRasesh Mody mb_params.data_src_size = sizeof(dword);
45372fdeb693SRasesh Mody
45382fdeb693SRasesh Mody rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
45392fdeb693SRasesh Mody if (rc != ECORE_SUCCESS) {
45402fdeb693SRasesh Mody DP_NOTICE(p_hwfn, false,
45412fdeb693SRasesh Mody "Failed to wol write request, rc = %d\n", rc);
45422fdeb693SRasesh Mody }
45432fdeb693SRasesh Mody
45442fdeb693SRasesh Mody if (mb_params.mcp_resp != FW_MSG_CODE_WOL_READ_WRITE_OK) {
45452fdeb693SRasesh Mody DP_NOTICE(p_hwfn, false,
45462fdeb693SRasesh Mody "Failed to write value 0x%x to offset 0x%x [mcp_resp 0x%x]\n",
45472fdeb693SRasesh Mody val, offset, mb_params.mcp_resp);
45482fdeb693SRasesh Mody rc = ECORE_UNKNOWN_ERROR;
45492fdeb693SRasesh Mody }
45502fdeb693SRasesh Mody }
4551