1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
9 #include "ecore_status.h"
11 #include "ecore_mcp.h"
12 #include "mcp_public.h"
15 #include "ecore_init_fw_funcs.h"
16 #include "ecore_sriov.h"
18 #include "ecore_iov_api.h"
19 #include "ecore_gtt_reg_addr.h"
20 #include "ecore_iro.h"
21 #include "ecore_dcbx.h"
22 #include "ecore_sp_commands.h"
23 #include "ecore_cxt.h"
25 #define GRCBASE_MCP 0xe00000
27 #define ECORE_MCP_RESP_ITER_US 10
28 #define ECORE_DRV_MB_MAX_RETRIES (500 * 1000) /* Account for 5 sec */
29 #define ECORE_MCP_RESET_RETRIES (50 * 1000) /* Account for 500 msec */
33 * The waiting interval is multiplied by 100 to reduce the impact of the
34 * built-in delay of 100usec in each ecore_rd().
35 * In addition, a factor of 4 comparing to ASIC is applied.
37 #define ECORE_EMUL_MCP_RESP_ITER_US (ECORE_MCP_RESP_ITER_US * 100)
38 #define ECORE_EMUL_DRV_MB_MAX_RETRIES ((ECORE_DRV_MB_MAX_RETRIES / 100) * 4)
39 #define ECORE_EMUL_MCP_RESET_RETRIES ((ECORE_MCP_RESET_RETRIES / 100) * 4)
42 #define DRV_INNER_WR(_p_hwfn, _p_ptt, _ptr, _offset, _val) \
43 ecore_wr(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset), \
46 #define DRV_INNER_RD(_p_hwfn, _p_ptt, _ptr, _offset) \
47 ecore_rd(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset))
49 #define DRV_MB_WR(_p_hwfn, _p_ptt, _field, _val) \
50 DRV_INNER_WR(p_hwfn, _p_ptt, drv_mb_addr, \
51 OFFSETOF(struct public_drv_mb, _field), _val)
53 #define DRV_MB_RD(_p_hwfn, _p_ptt, _field) \
54 DRV_INNER_RD(_p_hwfn, _p_ptt, drv_mb_addr, \
55 OFFSETOF(struct public_drv_mb, _field))
57 #define PDA_COMP (((FW_MAJOR_VERSION) + (FW_MINOR_VERSION << 8)) << \
58 DRV_ID_PDA_COMP_VER_OFFSET)
60 #define MCP_BYTES_PER_MBIT_OFFSET 17
64 static int loaded_port[MAX_NUM_PORTS] = { 0 };
67 bool ecore_mcp_is_init(struct ecore_hwfn *p_hwfn)
69 if (!p_hwfn->mcp_info || !p_hwfn->mcp_info->public_base)
74 void ecore_mcp_cmd_port_init(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
76 u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
78 u32 mfw_mb_offsize = ecore_rd(p_hwfn, p_ptt, addr);
80 p_hwfn->mcp_info->port_addr = SECTION_ADDR(mfw_mb_offsize,
82 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
83 "port_addr = 0x%x, port_id 0x%02x\n",
84 p_hwfn->mcp_info->port_addr, MFW_PORT(p_hwfn));
87 void ecore_mcp_read_mb(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
89 u32 length = MFW_DRV_MSG_MAX_DWORDS(p_hwfn->mcp_info->mfw_mb_length);
94 if (CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev))
98 if (!p_hwfn->mcp_info->public_base)
101 for (i = 0; i < length; i++) {
102 tmp = ecore_rd(p_hwfn, p_ptt,
103 p_hwfn->mcp_info->mfw_mb_addr +
104 (i << 2) + sizeof(u32));
106 ((u32 *)p_hwfn->mcp_info->mfw_mb_cur)[i] =
107 OSAL_BE32_TO_CPU(tmp);
111 struct ecore_mcp_cmd_elem {
112 osal_list_entry_t list;
113 struct ecore_mcp_mb_params *p_mb_params;
114 u16 expected_seq_num;
118 /* Must be called while cmd_lock is acquired */
119 static struct ecore_mcp_cmd_elem *
120 ecore_mcp_cmd_add_elem(struct ecore_hwfn *p_hwfn,
121 struct ecore_mcp_mb_params *p_mb_params,
122 u16 expected_seq_num)
124 struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL;
126 p_cmd_elem = OSAL_ZALLOC(p_hwfn->p_dev, GFP_ATOMIC,
127 sizeof(*p_cmd_elem));
129 DP_NOTICE(p_hwfn, false,
130 "Failed to allocate `struct ecore_mcp_cmd_elem'\n");
134 p_cmd_elem->p_mb_params = p_mb_params;
135 p_cmd_elem->expected_seq_num = expected_seq_num;
136 OSAL_LIST_PUSH_HEAD(&p_cmd_elem->list, &p_hwfn->mcp_info->cmd_list);
141 /* Must be called while cmd_lock is acquired */
142 static void ecore_mcp_cmd_del_elem(struct ecore_hwfn *p_hwfn,
143 struct ecore_mcp_cmd_elem *p_cmd_elem)
145 OSAL_LIST_REMOVE_ENTRY(&p_cmd_elem->list, &p_hwfn->mcp_info->cmd_list);
146 OSAL_FREE(p_hwfn->p_dev, p_cmd_elem);
149 /* Must be called while cmd_lock is acquired */
150 static struct ecore_mcp_cmd_elem *
151 ecore_mcp_cmd_get_elem(struct ecore_hwfn *p_hwfn, u16 seq_num)
153 struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL;
155 OSAL_LIST_FOR_EACH_ENTRY(p_cmd_elem, &p_hwfn->mcp_info->cmd_list, list,
156 struct ecore_mcp_cmd_elem) {
157 if (p_cmd_elem->expected_seq_num == seq_num)
164 enum _ecore_status_t ecore_mcp_free(struct ecore_hwfn *p_hwfn)
166 if (p_hwfn->mcp_info) {
167 struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL, *p_tmp;
169 OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info->mfw_mb_cur);
170 OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info->mfw_mb_shadow);
172 OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
173 OSAL_LIST_FOR_EACH_ENTRY_SAFE(p_cmd_elem, p_tmp,
174 &p_hwfn->mcp_info->cmd_list, list,
175 struct ecore_mcp_cmd_elem) {
176 ecore_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
178 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
180 #ifdef CONFIG_ECORE_LOCK_ALLOC
181 OSAL_SPIN_LOCK_DEALLOC(&p_hwfn->mcp_info->cmd_lock);
182 OSAL_SPIN_LOCK_DEALLOC(&p_hwfn->mcp_info->link_lock);
186 OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info);
188 return ECORE_SUCCESS;
191 /* Maximum of 1 sec to wait for the SHMEM ready indication */
192 #define ECORE_MCP_SHMEM_RDY_MAX_RETRIES 20
193 #define ECORE_MCP_SHMEM_RDY_ITER_MS 50
195 static enum _ecore_status_t ecore_load_mcp_offsets(struct ecore_hwfn *p_hwfn,
196 struct ecore_ptt *p_ptt)
198 struct ecore_mcp_info *p_info = p_hwfn->mcp_info;
199 u32 drv_mb_offsize, mfw_mb_offsize, val;
200 u8 cnt = ECORE_MCP_SHMEM_RDY_MAX_RETRIES;
201 u8 msec = ECORE_MCP_SHMEM_RDY_ITER_MS;
202 u32 mcp_pf_id = MCP_PF_ID(p_hwfn);
204 val = ecore_rd(p_hwfn, p_ptt, MCP_REG_CACHE_PAGING_ENABLE);
205 p_info->public_base = ecore_rd(p_hwfn, p_ptt, MISC_REG_SHARED_MEM_ADDR);
206 if (!p_info->public_base) {
207 DP_NOTICE(p_hwfn, false,
208 "The address of the MCP scratch-pad is not configured\n");
210 /* Zeroed "public_base" implies no MFW */
211 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
212 DP_INFO(p_hwfn, "Emulation: Assume no MFW\n");
217 p_info->public_base |= GRCBASE_MCP;
219 /* Get the MFW MB address and number of supported messages */
220 mfw_mb_offsize = ecore_rd(p_hwfn, p_ptt,
221 SECTION_OFFSIZE_ADDR(p_info->public_base,
223 p_info->mfw_mb_addr = SECTION_ADDR(mfw_mb_offsize, mcp_pf_id);
224 p_info->mfw_mb_length = (u16)ecore_rd(p_hwfn, p_ptt,
225 p_info->mfw_mb_addr);
228 * The driver can notify that there was an MCP reset, and read the SHMEM
229 * values before the MFW has completed initializing them.
230 * As a temporary solution, the "sup_msgs" field is used as a data ready
232 * This should be replaced with an actual indication when it is provided
235 while (!p_info->mfw_mb_length && cnt--) {
237 p_info->mfw_mb_length = (u16)ecore_rd(p_hwfn, p_ptt,
238 p_info->mfw_mb_addr);
242 DP_NOTICE(p_hwfn, false,
243 "Failed to get the SHMEM ready notification after %d msec\n",
244 ECORE_MCP_SHMEM_RDY_MAX_RETRIES * msec);
245 return ECORE_TIMEOUT;
248 /* Calculate the driver and MFW mailbox address */
249 drv_mb_offsize = ecore_rd(p_hwfn, p_ptt,
250 SECTION_OFFSIZE_ADDR(p_info->public_base,
252 p_info->drv_mb_addr = SECTION_ADDR(drv_mb_offsize, mcp_pf_id);
253 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
254 "drv_mb_offsiz = 0x%x, drv_mb_addr = 0x%x"
255 " mcp_pf_id = 0x%x\n",
256 drv_mb_offsize, p_info->drv_mb_addr, mcp_pf_id);
258 /* Get the current driver mailbox sequence before sending
261 p_info->drv_mb_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_mb_header) &
262 DRV_MSG_SEQ_NUMBER_MASK;
264 /* Get current FW pulse sequence */
265 p_info->drv_pulse_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_pulse_mb) &
268 p_info->mcp_hist = ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
270 return ECORE_SUCCESS;
273 enum _ecore_status_t ecore_mcp_cmd_init(struct ecore_hwfn *p_hwfn,
274 struct ecore_ptt *p_ptt)
276 struct ecore_mcp_info *p_info;
279 /* Allocate mcp_info structure */
280 p_hwfn->mcp_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
281 sizeof(*p_hwfn->mcp_info));
282 if (!p_hwfn->mcp_info) {
283 DP_NOTICE(p_hwfn, false, "Failed to allocate mcp_info\n");
286 p_info = p_hwfn->mcp_info;
288 /* Initialize the MFW spinlocks */
289 #ifdef CONFIG_ECORE_LOCK_ALLOC
290 if (OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_info->cmd_lock)) {
291 OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info);
294 if (OSAL_SPIN_LOCK_ALLOC(p_hwfn, &p_info->link_lock)) {
295 OSAL_SPIN_LOCK_DEALLOC(&p_info->cmd_lock);
296 OSAL_FREE(p_hwfn->p_dev, p_hwfn->mcp_info);
300 OSAL_SPIN_LOCK_INIT(&p_info->cmd_lock);
301 OSAL_SPIN_LOCK_INIT(&p_info->link_lock);
303 OSAL_LIST_INIT(&p_info->cmd_list);
305 if (ecore_load_mcp_offsets(p_hwfn, p_ptt) != ECORE_SUCCESS) {
306 DP_NOTICE(p_hwfn, false, "MCP is not initialized\n");
307 /* Do not free mcp_info here, since "public_base" indicates that
308 * the MCP is not initialized
310 return ECORE_SUCCESS;
313 size = MFW_DRV_MSG_MAX_DWORDS(p_info->mfw_mb_length) * sizeof(u32);
314 p_info->mfw_mb_cur = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, size);
315 p_info->mfw_mb_shadow = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL, size);
316 if (!p_info->mfw_mb_shadow || !p_info->mfw_mb_addr)
319 return ECORE_SUCCESS;
322 DP_NOTICE(p_hwfn, false, "Failed to allocate mcp memory\n");
323 ecore_mcp_free(p_hwfn);
327 static void ecore_mcp_reread_offsets(struct ecore_hwfn *p_hwfn,
328 struct ecore_ptt *p_ptt)
330 u32 generic_por_0 = ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
332 /* Use MCP history register to check if MCP reset occurred between init
335 if (p_hwfn->mcp_info->mcp_hist != generic_por_0) {
336 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
337 "Rereading MCP offsets [mcp_hist 0x%08x, generic_por_0 0x%08x]\n",
338 p_hwfn->mcp_info->mcp_hist, generic_por_0);
340 ecore_load_mcp_offsets(p_hwfn, p_ptt);
341 ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
345 enum _ecore_status_t ecore_mcp_reset(struct ecore_hwfn *p_hwfn,
346 struct ecore_ptt *p_ptt)
348 u32 prev_generic_por_0, seq, delay = ECORE_MCP_RESP_ITER_US, cnt = 0;
349 u32 retries = ECORE_MCP_RESET_RETRIES;
350 enum _ecore_status_t rc = ECORE_SUCCESS;
353 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
354 delay = ECORE_EMUL_MCP_RESP_ITER_US;
355 retries = ECORE_EMUL_MCP_RESET_RETRIES;
358 if (p_hwfn->mcp_info->b_block_cmd) {
359 DP_NOTICE(p_hwfn, false,
360 "The MFW is not responsive. Avoid sending MCP_RESET mailbox command.\n");
361 return ECORE_ABORTED;
364 /* Ensure that only a single thread is accessing the mailbox */
365 OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
367 prev_generic_por_0 = ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
369 /* Set drv command along with the updated sequence */
370 ecore_mcp_reread_offsets(p_hwfn, p_ptt);
371 seq = ++p_hwfn->mcp_info->drv_mb_seq;
372 DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (DRV_MSG_CODE_MCP_RESET | seq));
374 /* Give the MFW up to 500 second (50*1000*10usec) to resume */
378 if (ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0) !=
381 } while (cnt++ < retries);
383 if (ecore_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0) !=
384 prev_generic_por_0) {
385 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
386 "MCP was reset after %d usec\n", cnt * delay);
388 DP_ERR(p_hwfn, "Failed to reset MCP\n");
392 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
398 static void ecore_emul_mcp_load_req(struct ecore_hwfn *p_hwfn,
399 struct ecore_mcp_mb_params *p_mb_params)
401 if (GET_MFW_FIELD(p_mb_params->param, DRV_ID_MCP_HSI_VER) !=
402 1 /* ECORE_LOAD_REQ_HSI_VER_1 */) {
403 p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1;
408 p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_ENGINE;
409 else if (!loaded_port[p_hwfn->port_id])
410 p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_PORT;
412 p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_FUNCTION;
414 /* On CMT, always tell that it's engine */
415 if (ECORE_IS_CMT(p_hwfn->p_dev))
416 p_mb_params->mcp_resp = FW_MSG_CODE_DRV_LOAD_ENGINE;
419 loaded_port[p_hwfn->port_id]++;
421 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
422 "Load phase: 0x%08x load cnt: 0x%x port id=%d port_load=%d\n",
423 p_mb_params->mcp_resp, loaded, p_hwfn->port_id,
424 loaded_port[p_hwfn->port_id]);
427 static void ecore_emul_mcp_unload_req(struct ecore_hwfn *p_hwfn)
430 loaded_port[p_hwfn->port_id]--;
431 DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "Unload cnt: 0x%x\n", loaded);
434 static enum _ecore_status_t
435 ecore_emul_mcp_cmd(struct ecore_hwfn *p_hwfn,
436 struct ecore_mcp_mb_params *p_mb_params)
438 if (!CHIP_REV_IS_EMUL(p_hwfn->p_dev))
441 switch (p_mb_params->cmd) {
442 case DRV_MSG_CODE_LOAD_REQ:
443 ecore_emul_mcp_load_req(p_hwfn, p_mb_params);
445 case DRV_MSG_CODE_UNLOAD_REQ:
446 ecore_emul_mcp_unload_req(p_hwfn);
448 case DRV_MSG_CODE_GET_MFW_FEATURE_SUPPORT:
449 case DRV_MSG_CODE_RESOURCE_CMD:
450 case DRV_MSG_CODE_MDUMP_CMD:
451 case DRV_MSG_CODE_GET_ENGINE_CONFIG:
452 case DRV_MSG_CODE_GET_PPFID_BITMAP:
453 return ECORE_NOTIMPL;
458 return ECORE_SUCCESS;
462 /* Must be called while cmd_lock is acquired */
463 static bool ecore_mcp_has_pending_cmd(struct ecore_hwfn *p_hwfn)
465 struct ecore_mcp_cmd_elem *p_cmd_elem = OSAL_NULL;
467 /* There is at most one pending command at a certain time, and if it
468 * exists - it is placed at the HEAD of the list.
470 if (!OSAL_LIST_IS_EMPTY(&p_hwfn->mcp_info->cmd_list)) {
471 p_cmd_elem = OSAL_LIST_FIRST_ENTRY(&p_hwfn->mcp_info->cmd_list,
472 struct ecore_mcp_cmd_elem,
474 return !p_cmd_elem->b_is_completed;
480 /* Must be called while cmd_lock is acquired */
481 static enum _ecore_status_t
482 ecore_mcp_update_pending_cmd(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
484 struct ecore_mcp_mb_params *p_mb_params;
485 struct ecore_mcp_cmd_elem *p_cmd_elem;
489 mcp_resp = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_header);
490 seq_num = (u16)(mcp_resp & FW_MSG_SEQ_NUMBER_MASK);
492 /* Return if no new non-handled response has been received */
493 if (seq_num != p_hwfn->mcp_info->drv_mb_seq)
496 p_cmd_elem = ecore_mcp_cmd_get_elem(p_hwfn, seq_num);
499 "Failed to find a pending mailbox cmd that expects sequence number %d\n",
501 return ECORE_UNKNOWN_ERROR;
504 p_mb_params = p_cmd_elem->p_mb_params;
506 /* Get the MFW response along with the sequence number */
507 p_mb_params->mcp_resp = mcp_resp;
509 /* Get the MFW param */
510 p_mb_params->mcp_param = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_param);
512 /* Get the union data */
513 if (p_mb_params->p_data_dst != OSAL_NULL &&
514 p_mb_params->data_dst_size) {
515 u32 union_data_addr = p_hwfn->mcp_info->drv_mb_addr +
516 OFFSETOF(struct public_drv_mb,
518 ecore_memcpy_from(p_hwfn, p_ptt, p_mb_params->p_data_dst,
519 union_data_addr, p_mb_params->data_dst_size);
522 p_cmd_elem->b_is_completed = true;
524 return ECORE_SUCCESS;
527 /* Must be called while cmd_lock is acquired */
528 static void __ecore_mcp_cmd_and_union(struct ecore_hwfn *p_hwfn,
529 struct ecore_ptt *p_ptt,
530 struct ecore_mcp_mb_params *p_mb_params,
533 union drv_union_data union_data;
536 /* Set the union data */
537 union_data_addr = p_hwfn->mcp_info->drv_mb_addr +
538 OFFSETOF(struct public_drv_mb, union_data);
539 OSAL_MEM_ZERO(&union_data, sizeof(union_data));
540 if (p_mb_params->p_data_src != OSAL_NULL && p_mb_params->data_src_size)
541 OSAL_MEMCPY(&union_data, p_mb_params->p_data_src,
542 p_mb_params->data_src_size);
543 ecore_memcpy_to(p_hwfn, p_ptt, union_data_addr, &union_data,
546 /* Set the drv param */
547 DRV_MB_WR(p_hwfn, p_ptt, drv_mb_param, p_mb_params->param);
549 /* Set the drv command along with the sequence number */
550 DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (p_mb_params->cmd | seq_num));
552 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
553 "MFW mailbox: command 0x%08x param 0x%08x\n",
554 (p_mb_params->cmd | seq_num), p_mb_params->param);
557 static void ecore_mcp_cmd_set_blocking(struct ecore_hwfn *p_hwfn,
560 p_hwfn->mcp_info->b_block_cmd = block_cmd;
562 DP_INFO(p_hwfn, "%s sending of mailbox commands to the MFW\n",
563 block_cmd ? "Block" : "Unblock");
566 void ecore_mcp_print_cpu_info(struct ecore_hwfn *p_hwfn,
567 struct ecore_ptt *p_ptt)
569 u32 cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2;
570 u32 delay = ECORE_MCP_RESP_ITER_US;
573 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
574 delay = ECORE_EMUL_MCP_RESP_ITER_US;
576 cpu_mode = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
577 cpu_state = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
578 cpu_pc_0 = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
580 cpu_pc_1 = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
582 cpu_pc_2 = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
584 DP_NOTICE(p_hwfn, false,
585 "MCP CPU info: mode 0x%08x, state 0x%08x, pc {0x%08x, 0x%08x, 0x%08x}\n",
586 cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2);
589 static enum _ecore_status_t
590 _ecore_mcp_cmd_and_union(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
591 struct ecore_mcp_mb_params *p_mb_params,
592 u32 max_retries, u32 delay)
594 struct ecore_mcp_cmd_elem *p_cmd_elem;
597 enum _ecore_status_t rc = ECORE_SUCCESS;
599 /* Wait until the mailbox is non-occupied */
601 /* Exit the loop if there is no pending command, or if the
602 * pending command is completed during this iteration.
603 * The spinlock stays locked until the command is sent.
606 OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
608 if (!ecore_mcp_has_pending_cmd(p_hwfn))
611 rc = ecore_mcp_update_pending_cmd(p_hwfn, p_ptt);
612 if (rc == ECORE_SUCCESS)
614 else if (rc != ECORE_AGAIN)
617 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
619 OSAL_MFW_CMD_PREEMPT(p_hwfn);
620 } while (++cnt < max_retries);
622 if (cnt >= max_retries) {
623 DP_NOTICE(p_hwfn, false,
624 "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n",
625 p_mb_params->cmd, p_mb_params->param);
629 /* Send the mailbox command */
630 ecore_mcp_reread_offsets(p_hwfn, p_ptt);
631 seq_num = ++p_hwfn->mcp_info->drv_mb_seq;
632 p_cmd_elem = ecore_mcp_cmd_add_elem(p_hwfn, p_mb_params, seq_num);
638 __ecore_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, seq_num);
639 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
641 /* Wait for the MFW response */
643 /* Exit the loop if the command is already completed, or if the
644 * command is completed during this iteration.
645 * The spinlock stays locked until the list element is removed.
649 OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
651 if (p_cmd_elem->b_is_completed)
654 rc = ecore_mcp_update_pending_cmd(p_hwfn, p_ptt);
655 if (rc == ECORE_SUCCESS)
657 else if (rc != ECORE_AGAIN)
660 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
661 OSAL_MFW_CMD_PREEMPT(p_hwfn);
662 } while (++cnt < max_retries);
664 if (cnt >= max_retries) {
665 DP_NOTICE(p_hwfn, false,
666 "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
667 p_mb_params->cmd, p_mb_params->param);
668 ecore_mcp_print_cpu_info(p_hwfn, p_ptt);
670 OSAL_SPIN_LOCK(&p_hwfn->mcp_info->cmd_lock);
671 ecore_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
672 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
674 ecore_mcp_cmd_set_blocking(p_hwfn, true);
675 ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_MFW_RESP_FAIL);
679 ecore_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
680 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
682 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
683 "MFW mailbox: response 0x%08x param 0x%08x [after %d.%03d ms]\n",
684 p_mb_params->mcp_resp, p_mb_params->mcp_param,
685 (cnt * delay) / 1000, (cnt * delay) % 1000);
687 /* Clear the sequence number from the MFW response */
688 p_mb_params->mcp_resp &= FW_MSG_CODE_MASK;
690 return ECORE_SUCCESS;
693 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->cmd_lock);
697 static enum _ecore_status_t
698 ecore_mcp_cmd_and_union(struct ecore_hwfn *p_hwfn,
699 struct ecore_ptt *p_ptt,
700 struct ecore_mcp_mb_params *p_mb_params)
702 osal_size_t union_data_size = sizeof(union drv_union_data);
703 u32 max_retries = ECORE_DRV_MB_MAX_RETRIES;
704 u32 usecs = ECORE_MCP_RESP_ITER_US;
707 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn))
708 return ecore_emul_mcp_cmd(p_hwfn, p_mb_params);
710 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
711 max_retries = ECORE_EMUL_DRV_MB_MAX_RETRIES;
712 usecs = ECORE_EMUL_MCP_RESP_ITER_US;
715 if (ECORE_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP)) {
716 max_retries = DIV_ROUND_UP(max_retries, 1000);
720 /* MCP not initialized */
721 if (!ecore_mcp_is_init(p_hwfn)) {
722 DP_NOTICE(p_hwfn, true, "MFW is not initialized!\n");
726 if (p_mb_params->data_src_size > union_data_size ||
727 p_mb_params->data_dst_size > union_data_size) {
729 "The provided size is larger than the union data size [src_size %u, dst_size %u, union_data_size %zu]\n",
730 p_mb_params->data_src_size, p_mb_params->data_dst_size,
735 if (p_hwfn->mcp_info->b_block_cmd) {
736 DP_NOTICE(p_hwfn, false,
737 "The MFW is not responsive. Avoid sending mailbox command 0x%08x [param 0x%08x].\n",
738 p_mb_params->cmd, p_mb_params->param);
739 return ECORE_ABORTED;
742 return _ecore_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, max_retries,
746 enum _ecore_status_t ecore_mcp_cmd(struct ecore_hwfn *p_hwfn,
747 struct ecore_ptt *p_ptt, u32 cmd, u32 param,
748 u32 *o_mcp_resp, u32 *o_mcp_param)
750 struct ecore_mcp_mb_params mb_params;
751 enum _ecore_status_t rc;
753 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
755 mb_params.param = param;
756 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
757 if (rc != ECORE_SUCCESS)
760 *o_mcp_resp = mb_params.mcp_resp;
761 *o_mcp_param = mb_params.mcp_param;
763 return ECORE_SUCCESS;
766 enum _ecore_status_t ecore_mcp_nvm_wr_cmd(struct ecore_hwfn *p_hwfn,
767 struct ecore_ptt *p_ptt,
772 u32 i_txn_size, u32 *i_buf)
774 struct ecore_mcp_mb_params mb_params;
775 enum _ecore_status_t rc;
777 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
779 mb_params.param = param;
780 mb_params.p_data_src = i_buf;
781 mb_params.data_src_size = (u8)i_txn_size;
782 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
783 if (rc != ECORE_SUCCESS)
786 *o_mcp_resp = mb_params.mcp_resp;
787 *o_mcp_param = mb_params.mcp_param;
789 return ECORE_SUCCESS;
792 enum _ecore_status_t ecore_mcp_nvm_rd_cmd(struct ecore_hwfn *p_hwfn,
793 struct ecore_ptt *p_ptt,
798 u32 *o_txn_size, u32 *o_buf)
800 struct ecore_mcp_mb_params mb_params;
801 u8 raw_data[MCP_DRV_NVM_BUF_LEN];
802 enum _ecore_status_t rc;
804 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
806 mb_params.param = param;
807 mb_params.p_data_dst = raw_data;
809 /* Use the maximal value since the actual one is part of the response */
810 mb_params.data_dst_size = MCP_DRV_NVM_BUF_LEN;
812 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
813 if (rc != ECORE_SUCCESS)
816 *o_mcp_resp = mb_params.mcp_resp;
817 *o_mcp_param = mb_params.mcp_param;
819 *o_txn_size = *o_mcp_param;
821 OSAL_MEMCPY(o_buf, raw_data, RTE_MIN(*o_txn_size, MCP_DRV_NVM_BUF_LEN));
823 return ECORE_SUCCESS;
827 ecore_mcp_can_force_load(u8 drv_role, u8 exist_drv_role,
828 enum ecore_override_force_load override_force_load)
830 bool can_force_load = false;
832 switch (override_force_load) {
833 case ECORE_OVERRIDE_FORCE_LOAD_ALWAYS:
834 can_force_load = true;
836 case ECORE_OVERRIDE_FORCE_LOAD_NEVER:
837 can_force_load = false;
840 can_force_load = (drv_role == DRV_ROLE_OS &&
841 exist_drv_role == DRV_ROLE_PREBOOT) ||
842 (drv_role == DRV_ROLE_KDUMP &&
843 exist_drv_role == DRV_ROLE_OS);
847 return can_force_load;
850 static enum _ecore_status_t ecore_mcp_cancel_load_req(struct ecore_hwfn *p_hwfn,
851 struct ecore_ptt *p_ptt)
853 u32 resp = 0, param = 0;
854 enum _ecore_status_t rc;
856 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CANCEL_LOAD_REQ, 0,
858 if (rc != ECORE_SUCCESS)
859 DP_NOTICE(p_hwfn, false,
860 "Failed to send cancel load request, rc = %d\n", rc);
865 #define CONFIG_ECORE_L2_BITMAP_IDX (0x1 << 0)
866 #define CONFIG_ECORE_SRIOV_BITMAP_IDX (0x1 << 1)
867 #define CONFIG_ECORE_ROCE_BITMAP_IDX (0x1 << 2)
868 #define CONFIG_ECORE_IWARP_BITMAP_IDX (0x1 << 3)
869 #define CONFIG_ECORE_FCOE_BITMAP_IDX (0x1 << 4)
870 #define CONFIG_ECORE_ISCSI_BITMAP_IDX (0x1 << 5)
871 #define CONFIG_ECORE_LL2_BITMAP_IDX (0x1 << 6)
873 static u32 ecore_get_config_bitmap(void)
875 u32 config_bitmap = 0x0;
877 #ifdef CONFIG_ECORE_L2
878 config_bitmap |= CONFIG_ECORE_L2_BITMAP_IDX;
880 #ifdef CONFIG_ECORE_SRIOV
881 config_bitmap |= CONFIG_ECORE_SRIOV_BITMAP_IDX;
883 #ifdef CONFIG_ECORE_ROCE
884 config_bitmap |= CONFIG_ECORE_ROCE_BITMAP_IDX;
886 #ifdef CONFIG_ECORE_IWARP
887 config_bitmap |= CONFIG_ECORE_IWARP_BITMAP_IDX;
889 #ifdef CONFIG_ECORE_FCOE
890 config_bitmap |= CONFIG_ECORE_FCOE_BITMAP_IDX;
892 #ifdef CONFIG_ECORE_ISCSI
893 config_bitmap |= CONFIG_ECORE_ISCSI_BITMAP_IDX;
895 #ifdef CONFIG_ECORE_LL2
896 config_bitmap |= CONFIG_ECORE_LL2_BITMAP_IDX;
899 return config_bitmap;
902 struct ecore_load_req_in_params {
904 #define ECORE_LOAD_REQ_HSI_VER_DEFAULT 0
905 #define ECORE_LOAD_REQ_HSI_VER_1 1
912 bool avoid_eng_reset;
915 struct ecore_load_req_out_params {
925 static enum _ecore_status_t
926 __ecore_mcp_load_req(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
927 struct ecore_load_req_in_params *p_in_params,
928 struct ecore_load_req_out_params *p_out_params)
930 struct ecore_mcp_mb_params mb_params;
931 struct load_req_stc load_req;
932 struct load_rsp_stc load_rsp;
934 enum _ecore_status_t rc;
936 OSAL_MEM_ZERO(&load_req, sizeof(load_req));
937 load_req.drv_ver_0 = p_in_params->drv_ver_0;
938 load_req.drv_ver_1 = p_in_params->drv_ver_1;
939 load_req.fw_ver = p_in_params->fw_ver;
940 SET_MFW_FIELD(load_req.misc0, LOAD_REQ_ROLE, p_in_params->drv_role);
941 SET_MFW_FIELD(load_req.misc0, LOAD_REQ_LOCK_TO,
942 p_in_params->timeout_val);
943 SET_MFW_FIELD(load_req.misc0, LOAD_REQ_FORCE, p_in_params->force_cmd);
944 SET_MFW_FIELD(load_req.misc0, LOAD_REQ_FLAGS0,
945 p_in_params->avoid_eng_reset);
947 hsi_ver = (p_in_params->hsi_ver == ECORE_LOAD_REQ_HSI_VER_DEFAULT) ?
948 DRV_ID_MCP_HSI_VER_CURRENT :
949 (p_in_params->hsi_ver << DRV_ID_MCP_HSI_VER_OFFSET);
951 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
952 mb_params.cmd = DRV_MSG_CODE_LOAD_REQ;
953 mb_params.param = PDA_COMP | hsi_ver | p_hwfn->p_dev->drv_type;
954 mb_params.p_data_src = &load_req;
955 mb_params.data_src_size = sizeof(load_req);
956 mb_params.p_data_dst = &load_rsp;
957 mb_params.data_dst_size = sizeof(load_rsp);
959 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
960 "Load Request: param 0x%08x [init_hw %d, drv_type %d, hsi_ver %d, pda 0x%04x]\n",
962 GET_MFW_FIELD(mb_params.param, DRV_ID_DRV_INIT_HW),
963 GET_MFW_FIELD(mb_params.param, DRV_ID_DRV_TYPE),
964 GET_MFW_FIELD(mb_params.param, DRV_ID_MCP_HSI_VER),
965 GET_MFW_FIELD(mb_params.param, DRV_ID_PDA_COMP_VER));
967 if (p_in_params->hsi_ver != ECORE_LOAD_REQ_HSI_VER_1)
968 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
969 "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",
970 load_req.drv_ver_0, load_req.drv_ver_1,
971 load_req.fw_ver, load_req.misc0,
972 GET_MFW_FIELD(load_req.misc0, LOAD_REQ_ROLE),
973 GET_MFW_FIELD(load_req.misc0, LOAD_REQ_LOCK_TO),
974 GET_MFW_FIELD(load_req.misc0, LOAD_REQ_FORCE),
975 GET_MFW_FIELD(load_req.misc0, LOAD_REQ_FLAGS0));
977 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
978 if (rc != ECORE_SUCCESS) {
979 DP_NOTICE(p_hwfn, false,
980 "Failed to send load request, rc = %d\n", rc);
984 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
985 "Load Response: resp 0x%08x\n", mb_params.mcp_resp);
986 p_out_params->load_code = mb_params.mcp_resp;
988 if (p_in_params->hsi_ver != ECORE_LOAD_REQ_HSI_VER_1 &&
989 p_out_params->load_code != FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) {
990 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
991 "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",
992 load_rsp.drv_ver_0, load_rsp.drv_ver_1,
993 load_rsp.fw_ver, load_rsp.misc0,
994 GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_ROLE),
995 GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_HSI),
996 GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0));
998 p_out_params->exist_drv_ver_0 = load_rsp.drv_ver_0;
999 p_out_params->exist_drv_ver_1 = load_rsp.drv_ver_1;
1000 p_out_params->exist_fw_ver = load_rsp.fw_ver;
1001 p_out_params->exist_drv_role =
1002 GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_ROLE);
1003 p_out_params->mfw_hsi_ver =
1004 GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_HSI);
1005 p_out_params->drv_exists =
1006 GET_MFW_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0) &
1007 LOAD_RSP_FLAGS0_DRV_EXISTS;
1010 return ECORE_SUCCESS;
1013 static void ecore_get_mfw_drv_role(enum ecore_drv_role drv_role,
1017 case ECORE_DRV_ROLE_OS:
1018 *p_mfw_drv_role = DRV_ROLE_OS;
1020 case ECORE_DRV_ROLE_KDUMP:
1021 *p_mfw_drv_role = DRV_ROLE_KDUMP;
1026 enum ecore_load_req_force {
1027 ECORE_LOAD_REQ_FORCE_NONE,
1028 ECORE_LOAD_REQ_FORCE_PF,
1029 ECORE_LOAD_REQ_FORCE_ALL,
1032 static void ecore_get_mfw_force_cmd(enum ecore_load_req_force force_cmd,
1033 u8 *p_mfw_force_cmd)
1035 switch (force_cmd) {
1036 case ECORE_LOAD_REQ_FORCE_NONE:
1037 *p_mfw_force_cmd = LOAD_REQ_FORCE_NONE;
1039 case ECORE_LOAD_REQ_FORCE_PF:
1040 *p_mfw_force_cmd = LOAD_REQ_FORCE_PF;
1042 case ECORE_LOAD_REQ_FORCE_ALL:
1043 *p_mfw_force_cmd = LOAD_REQ_FORCE_ALL;
1048 enum _ecore_status_t ecore_mcp_load_req(struct ecore_hwfn *p_hwfn,
1049 struct ecore_ptt *p_ptt,
1050 struct ecore_load_req_params *p_params)
1052 struct ecore_load_req_out_params out_params;
1053 struct ecore_load_req_in_params in_params;
1054 u8 mfw_drv_role = 0, mfw_force_cmd;
1055 enum _ecore_status_t rc;
1057 OSAL_MEM_ZERO(&in_params, sizeof(in_params));
1058 in_params.hsi_ver = ECORE_LOAD_REQ_HSI_VER_DEFAULT;
1059 in_params.drv_ver_0 = ECORE_VERSION;
1060 in_params.drv_ver_1 = ecore_get_config_bitmap();
1061 in_params.fw_ver = STORM_FW_VERSION;
1062 ecore_get_mfw_drv_role(p_params->drv_role, &mfw_drv_role);
1063 in_params.drv_role = mfw_drv_role;
1064 in_params.timeout_val = p_params->timeout_val;
1065 ecore_get_mfw_force_cmd(ECORE_LOAD_REQ_FORCE_NONE, &mfw_force_cmd);
1066 in_params.force_cmd = mfw_force_cmd;
1067 in_params.avoid_eng_reset = p_params->avoid_eng_reset;
1069 OSAL_MEM_ZERO(&out_params, sizeof(out_params));
1070 rc = __ecore_mcp_load_req(p_hwfn, p_ptt, &in_params, &out_params);
1071 if (rc != ECORE_SUCCESS)
1074 /* First handle cases where another load request should/might be sent:
1075 * - MFW expects the old interface [HSI version = 1]
1076 * - MFW responds that a force load request is required
1078 if (out_params.load_code == FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) {
1080 "MFW refused a load request due to HSI > 1. Resending with HSI = 1.\n");
1082 in_params.hsi_ver = ECORE_LOAD_REQ_HSI_VER_1;
1083 OSAL_MEM_ZERO(&out_params, sizeof(out_params));
1084 rc = __ecore_mcp_load_req(p_hwfn, p_ptt, &in_params,
1086 if (rc != ECORE_SUCCESS)
1088 } else if (out_params.load_code ==
1089 FW_MSG_CODE_DRV_LOAD_REFUSED_REQUIRES_FORCE) {
1090 if (ecore_mcp_can_force_load(in_params.drv_role,
1091 out_params.exist_drv_role,
1092 p_params->override_force_load)) {
1094 "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",
1095 in_params.drv_role, in_params.fw_ver,
1096 in_params.drv_ver_0, in_params.drv_ver_1,
1097 out_params.exist_drv_role,
1098 out_params.exist_fw_ver,
1099 out_params.exist_drv_ver_0,
1100 out_params.exist_drv_ver_1);
1102 ecore_get_mfw_force_cmd(ECORE_LOAD_REQ_FORCE_ALL,
1105 in_params.force_cmd = mfw_force_cmd;
1106 OSAL_MEM_ZERO(&out_params, sizeof(out_params));
1107 rc = __ecore_mcp_load_req(p_hwfn, p_ptt, &in_params,
1109 if (rc != ECORE_SUCCESS)
1112 DP_NOTICE(p_hwfn, false,
1113 "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",
1114 in_params.drv_role, in_params.fw_ver,
1115 in_params.drv_ver_0, in_params.drv_ver_1,
1116 out_params.exist_drv_role,
1117 out_params.exist_fw_ver,
1118 out_params.exist_drv_ver_0,
1119 out_params.exist_drv_ver_1);
1121 ecore_mcp_cancel_load_req(p_hwfn, p_ptt);
1126 /* Now handle the other types of responses.
1127 * The "REFUSED_HSI_1" and "REFUSED_REQUIRES_FORCE" responses are not
1128 * expected here after the additional revised load requests were sent.
1130 switch (out_params.load_code) {
1131 case FW_MSG_CODE_DRV_LOAD_ENGINE:
1132 case FW_MSG_CODE_DRV_LOAD_PORT:
1133 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
1134 if (out_params.mfw_hsi_ver != ECORE_LOAD_REQ_HSI_VER_1 &&
1135 out_params.drv_exists) {
1136 /* The role and fw/driver version match, but the PF is
1137 * already loaded and has not been unloaded gracefully.
1138 * This is unexpected since a quasi-FLR request was
1139 * previously sent as part of ecore_hw_prepare().
1141 DP_NOTICE(p_hwfn, false,
1142 "PF is already loaded - shouldn't have got here since a quasi-FLR request was previously sent!\n");
1147 DP_NOTICE(p_hwfn, false,
1148 "Unexpected refusal to load request [resp 0x%08x]. Aborting.\n",
1149 out_params.load_code);
1153 p_params->load_code = out_params.load_code;
1155 return ECORE_SUCCESS;
1158 enum _ecore_status_t ecore_mcp_load_done(struct ecore_hwfn *p_hwfn,
1159 struct ecore_ptt *p_ptt)
1161 u32 resp = 0, param = 0;
1162 enum _ecore_status_t rc;
1164 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_LOAD_DONE, 0, &resp,
1166 if (rc != ECORE_SUCCESS) {
1167 DP_NOTICE(p_hwfn, false,
1168 "Failed to send a LOAD_DONE command, rc = %d\n", rc);
1172 /* Check if there is a DID mismatch between nvm-cfg/efuse */
1173 if (param & FW_MB_PARAM_LOAD_DONE_DID_EFUSE_ERROR)
1174 DP_NOTICE(p_hwfn, false,
1175 "warning: device configuration is not supported on this board type. The device may not function as expected.\n");
1177 return ECORE_SUCCESS;
1180 enum _ecore_status_t ecore_mcp_unload_req(struct ecore_hwfn *p_hwfn,
1181 struct ecore_ptt *p_ptt)
1183 u32 wol_param, mcp_resp, mcp_param;
1186 wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP;
1188 return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_UNLOAD_REQ, wol_param,
1189 &mcp_resp, &mcp_param);
1192 enum _ecore_status_t ecore_mcp_unload_done(struct ecore_hwfn *p_hwfn,
1193 struct ecore_ptt *p_ptt)
1195 struct ecore_mcp_mb_params mb_params;
1196 struct mcp_mac wol_mac;
1198 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1199 mb_params.cmd = DRV_MSG_CODE_UNLOAD_DONE;
1201 return ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1204 static void ecore_mcp_handle_vf_flr(struct ecore_hwfn *p_hwfn,
1205 struct ecore_ptt *p_ptt)
1207 u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1209 u32 mfw_path_offsize = ecore_rd(p_hwfn, p_ptt, addr);
1210 u32 path_addr = SECTION_ADDR(mfw_path_offsize,
1211 ECORE_PATH_ID(p_hwfn));
1212 u32 disabled_vfs[EXT_VF_BITMAP_SIZE_IN_DWORDS];
1215 OSAL_MEM_ZERO(disabled_vfs, EXT_VF_BITMAP_SIZE_IN_BYTES);
1217 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1218 "Reading Disabled VF information from [offset %08x],"
1219 " path_addr %08x\n",
1220 mfw_path_offsize, path_addr);
1222 for (i = 0; i < VF_BITMAP_SIZE_IN_DWORDS; i++) {
1223 disabled_vfs[i] = ecore_rd(p_hwfn, p_ptt,
1225 OFFSETOF(struct public_path,
1228 DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_IOV),
1229 "FLR-ed VFs [%08x,...,%08x] - %08x\n",
1230 i * 32, (i + 1) * 32 - 1, disabled_vfs[i]);
1233 if (ecore_iov_mark_vf_flr(p_hwfn, disabled_vfs))
1234 OSAL_VF_FLR_UPDATE(p_hwfn);
1237 enum _ecore_status_t ecore_mcp_ack_vf_flr(struct ecore_hwfn *p_hwfn,
1238 struct ecore_ptt *p_ptt,
1241 struct ecore_mcp_mb_params mb_params;
1242 enum _ecore_status_t rc;
1245 for (i = 0; i < VF_BITMAP_SIZE_IN_DWORDS; i++)
1246 DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_IOV),
1247 "Acking VFs [%08x,...,%08x] - %08x\n",
1248 i * 32, (i + 1) * 32 - 1, vfs_to_ack[i]);
1250 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1251 mb_params.cmd = DRV_MSG_CODE_VF_DISABLED_DONE;
1252 mb_params.p_data_src = vfs_to_ack;
1253 mb_params.data_src_size = (u8)VF_BITMAP_SIZE_IN_BYTES;
1254 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt,
1256 if (rc != ECORE_SUCCESS) {
1257 DP_NOTICE(p_hwfn, false,
1258 "Failed to pass ACK for VF flr to MFW\n");
1259 return ECORE_TIMEOUT;
1265 static void ecore_mcp_handle_transceiver_change(struct ecore_hwfn *p_hwfn,
1266 struct ecore_ptt *p_ptt)
1268 u32 transceiver_state;
1270 transceiver_state = ecore_rd(p_hwfn, p_ptt,
1271 p_hwfn->mcp_info->port_addr +
1272 OFFSETOF(struct public_port,
1275 DP_VERBOSE(p_hwfn, (ECORE_MSG_HW | ECORE_MSG_SP),
1276 "Received transceiver state update [0x%08x] from mfw"
1278 transceiver_state, (u32)(p_hwfn->mcp_info->port_addr +
1279 OFFSETOF(struct public_port,
1280 transceiver_data)));
1282 transceiver_state = GET_MFW_FIELD(transceiver_state,
1283 ETH_TRANSCEIVER_STATE);
1285 if (transceiver_state == ETH_TRANSCEIVER_STATE_PRESENT)
1286 DP_NOTICE(p_hwfn, false, "Transceiver is present.\n");
1288 DP_NOTICE(p_hwfn, false, "Transceiver is unplugged.\n");
1290 OSAL_TRANSCEIVER_UPDATE(p_hwfn);
1293 static void ecore_mcp_read_eee_config(struct ecore_hwfn *p_hwfn,
1294 struct ecore_ptt *p_ptt,
1295 struct ecore_mcp_link_state *p_link)
1297 u32 eee_status, val;
1299 p_link->eee_adv_caps = 0;
1300 p_link->eee_lp_adv_caps = 0;
1301 eee_status = ecore_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
1302 OFFSETOF(struct public_port, eee_status));
1303 p_link->eee_active = !!(eee_status & EEE_ACTIVE_BIT);
1304 val = (eee_status & EEE_LD_ADV_STATUS_MASK) >> EEE_LD_ADV_STATUS_OFFSET;
1305 if (val & EEE_1G_ADV)
1306 p_link->eee_adv_caps |= ECORE_EEE_1G_ADV;
1307 if (val & EEE_10G_ADV)
1308 p_link->eee_adv_caps |= ECORE_EEE_10G_ADV;
1309 val = (eee_status & EEE_LP_ADV_STATUS_MASK) >> EEE_LP_ADV_STATUS_OFFSET;
1310 if (val & EEE_1G_ADV)
1311 p_link->eee_lp_adv_caps |= ECORE_EEE_1G_ADV;
1312 if (val & EEE_10G_ADV)
1313 p_link->eee_lp_adv_caps |= ECORE_EEE_10G_ADV;
1316 static u32 ecore_mcp_get_shmem_func(struct ecore_hwfn *p_hwfn,
1317 struct ecore_ptt *p_ptt,
1318 struct public_func *p_data,
1321 u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1323 u32 mfw_path_offsize = ecore_rd(p_hwfn, p_ptt, addr);
1324 u32 func_addr = SECTION_ADDR(mfw_path_offsize, pfid);
1327 OSAL_MEM_ZERO(p_data, sizeof(*p_data));
1329 size = OSAL_MIN_T(u32, sizeof(*p_data),
1330 SECTION_SIZE(mfw_path_offsize));
1331 for (i = 0; i < size / sizeof(u32); i++)
1332 ((u32 *)p_data)[i] = ecore_rd(p_hwfn, p_ptt,
1333 func_addr + (i << 2));
1338 static void ecore_mcp_handle_link_change(struct ecore_hwfn *p_hwfn,
1339 struct ecore_ptt *p_ptt,
1342 struct ecore_mcp_link_state *p_link;
1346 /* Prevent SW/attentions from doing this at the same time */
1347 OSAL_SPIN_LOCK(&p_hwfn->mcp_info->link_lock);
1349 p_link = &p_hwfn->mcp_info->link_output;
1350 OSAL_MEMSET(p_link, 0, sizeof(*p_link));
1352 status = ecore_rd(p_hwfn, p_ptt,
1353 p_hwfn->mcp_info->port_addr +
1354 OFFSETOF(struct public_port, link_status));
1355 DP_VERBOSE(p_hwfn, (ECORE_MSG_LINK | ECORE_MSG_SP),
1356 "Received link update [0x%08x] from mfw"
1358 status, (u32)(p_hwfn->mcp_info->port_addr +
1359 OFFSETOF(struct public_port,
1362 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1363 "Resetting link indications\n");
1367 if (p_hwfn->b_drv_link_init) {
1368 /* Link indication with modern MFW arrives as per-PF
1371 if (p_hwfn->mcp_info->capabilities &
1372 FW_MB_PARAM_FEATURE_SUPPORT_VLINK) {
1373 struct public_func shmem_info;
1375 ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
1377 p_link->link_up = !!(shmem_info.status &
1378 FUNC_STATUS_VIRTUAL_LINK_UP);
1380 p_link->link_up = !!(status & LINK_STATUS_LINK_UP);
1383 p_link->link_up = false;
1386 p_link->full_duplex = true;
1387 switch ((status & LINK_STATUS_SPEED_AND_DUPLEX_MASK)) {
1388 case LINK_STATUS_SPEED_AND_DUPLEX_100G:
1389 p_link->speed = 100000;
1391 case LINK_STATUS_SPEED_AND_DUPLEX_50G:
1392 p_link->speed = 50000;
1394 case LINK_STATUS_SPEED_AND_DUPLEX_40G:
1395 p_link->speed = 40000;
1397 case LINK_STATUS_SPEED_AND_DUPLEX_25G:
1398 p_link->speed = 25000;
1400 case LINK_STATUS_SPEED_AND_DUPLEX_20G:
1401 p_link->speed = 20000;
1403 case LINK_STATUS_SPEED_AND_DUPLEX_10G:
1404 p_link->speed = 10000;
1406 case LINK_STATUS_SPEED_AND_DUPLEX_1000THD:
1407 p_link->full_duplex = false;
1409 case LINK_STATUS_SPEED_AND_DUPLEX_1000TFD:
1410 p_link->speed = 1000;
1416 /* We never store total line speed as p_link->speed is
1417 * again changes according to bandwidth allocation.
1419 if (p_link->link_up && p_link->speed)
1420 p_link->line_speed = p_link->speed;
1422 p_link->line_speed = 0;
1424 max_bw = p_hwfn->mcp_info->func_info.bandwidth_max;
1425 min_bw = p_hwfn->mcp_info->func_info.bandwidth_min;
1427 /* Max bandwidth configuration */
1428 __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
1431 /* Min bandwidth configuration */
1432 __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
1434 ecore_configure_vp_wfq_on_link_change(p_hwfn->p_dev, p_ptt,
1435 p_link->min_pf_rate);
1437 p_link->an = !!(status & LINK_STATUS_AUTO_NEGOTIATE_ENABLED);
1438 p_link->an_complete = !!(status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE);
1439 p_link->parallel_detection = !!(status &
1440 LINK_STATUS_PARALLEL_DETECTION_USED);
1441 p_link->pfc_enabled = !!(status & LINK_STATUS_PFC_ENABLED);
1443 p_link->partner_adv_speed |=
1444 (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE) ?
1445 ECORE_LINK_PARTNER_SPEED_1G_FD : 0;
1446 p_link->partner_adv_speed |=
1447 (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE) ?
1448 ECORE_LINK_PARTNER_SPEED_1G_HD : 0;
1449 p_link->partner_adv_speed |=
1450 (status & LINK_STATUS_LINK_PARTNER_10G_CAPABLE) ?
1451 ECORE_LINK_PARTNER_SPEED_10G : 0;
1452 p_link->partner_adv_speed |=
1453 (status & LINK_STATUS_LINK_PARTNER_20G_CAPABLE) ?
1454 ECORE_LINK_PARTNER_SPEED_20G : 0;
1455 p_link->partner_adv_speed |=
1456 (status & LINK_STATUS_LINK_PARTNER_25G_CAPABLE) ?
1457 ECORE_LINK_PARTNER_SPEED_25G : 0;
1458 p_link->partner_adv_speed |=
1459 (status & LINK_STATUS_LINK_PARTNER_40G_CAPABLE) ?
1460 ECORE_LINK_PARTNER_SPEED_40G : 0;
1461 p_link->partner_adv_speed |=
1462 (status & LINK_STATUS_LINK_PARTNER_50G_CAPABLE) ?
1463 ECORE_LINK_PARTNER_SPEED_50G : 0;
1464 p_link->partner_adv_speed |=
1465 (status & LINK_STATUS_LINK_PARTNER_100G_CAPABLE) ?
1466 ECORE_LINK_PARTNER_SPEED_100G : 0;
1468 p_link->partner_tx_flow_ctrl_en =
1469 !!(status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED);
1470 p_link->partner_rx_flow_ctrl_en =
1471 !!(status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED);
1473 switch (status & LINK_STATUS_LINK_PARTNER_FLOW_CONTROL_MASK) {
1474 case LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE:
1475 p_link->partner_adv_pause = ECORE_LINK_PARTNER_SYMMETRIC_PAUSE;
1477 case LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE:
1478 p_link->partner_adv_pause = ECORE_LINK_PARTNER_ASYMMETRIC_PAUSE;
1480 case LINK_STATUS_LINK_PARTNER_BOTH_PAUSE:
1481 p_link->partner_adv_pause = ECORE_LINK_PARTNER_BOTH_PAUSE;
1484 p_link->partner_adv_pause = 0;
1487 p_link->sfp_tx_fault = !!(status & LINK_STATUS_SFP_TX_FAULT);
1489 if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE)
1490 ecore_mcp_read_eee_config(p_hwfn, p_ptt, p_link);
1492 OSAL_LINK_UPDATE(p_hwfn);
1494 OSAL_SPIN_UNLOCK(&p_hwfn->mcp_info->link_lock);
1497 enum _ecore_status_t ecore_mcp_set_link(struct ecore_hwfn *p_hwfn,
1498 struct ecore_ptt *p_ptt, bool b_up)
1500 struct ecore_mcp_link_params *params = &p_hwfn->mcp_info->link_input;
1501 struct ecore_mcp_mb_params mb_params;
1502 struct eth_phy_cfg phy_cfg;
1503 enum _ecore_status_t rc = ECORE_SUCCESS;
1507 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
1509 OSAL_LINK_UPDATE(p_hwfn);
1510 return ECORE_SUCCESS;
1514 /* Set the shmem configuration according to params */
1515 OSAL_MEM_ZERO(&phy_cfg, sizeof(phy_cfg));
1516 cmd = b_up ? DRV_MSG_CODE_INIT_PHY : DRV_MSG_CODE_LINK_RESET;
1517 if (!params->speed.autoneg)
1518 phy_cfg.speed = params->speed.forced_speed;
1519 phy_cfg.pause |= (params->pause.autoneg) ? ETH_PAUSE_AUTONEG : 0;
1520 phy_cfg.pause |= (params->pause.forced_rx) ? ETH_PAUSE_RX : 0;
1521 phy_cfg.pause |= (params->pause.forced_tx) ? ETH_PAUSE_TX : 0;
1522 phy_cfg.adv_speed = params->speed.advertised_speeds;
1523 phy_cfg.loopback_mode = params->loopback_mode;
1525 /* There are MFWs that share this capability regardless of whether
1526 * this is feasible or not. And given that at the very least adv_caps
1527 * would be set internally by ecore, we want to make sure LFA would
1530 if ((p_hwfn->mcp_info->capabilities &
1531 FW_MB_PARAM_FEATURE_SUPPORT_EEE) &&
1532 params->eee.enable) {
1533 phy_cfg.eee_cfg |= EEE_CFG_EEE_ENABLED;
1534 if (params->eee.tx_lpi_enable)
1535 phy_cfg.eee_cfg |= EEE_CFG_TX_LPI;
1536 if (params->eee.adv_caps & ECORE_EEE_1G_ADV)
1537 phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_1G;
1538 if (params->eee.adv_caps & ECORE_EEE_10G_ADV)
1539 phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_10G;
1540 phy_cfg.eee_cfg |= (params->eee.tx_lpi_timer <<
1541 EEE_TX_TIMER_USEC_OFFSET) &
1542 EEE_TX_TIMER_USEC_MASK;
1545 p_hwfn->b_drv_link_init = b_up;
1548 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1549 "Configuring Link: Speed 0x%08x, Pause 0x%08x, adv_speed 0x%08x, loopback 0x%08x\n",
1550 phy_cfg.speed, phy_cfg.pause, phy_cfg.adv_speed,
1551 phy_cfg.loopback_mode);
1553 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK, "Resetting link\n");
1555 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1556 mb_params.cmd = cmd;
1557 mb_params.p_data_src = &phy_cfg;
1558 mb_params.data_src_size = sizeof(phy_cfg);
1559 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1561 /* if mcp fails to respond we must abort */
1562 if (rc != ECORE_SUCCESS) {
1563 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
1567 /* Mimic link-change attention, done for several reasons:
1568 * - On reset, there's no guarantee MFW would trigger
1570 * - On initialization, older MFWs might not indicate link change
1571 * during LFA, so we'll never get an UP indication.
1573 ecore_mcp_handle_link_change(p_hwfn, p_ptt, !b_up);
1575 return ECORE_SUCCESS;
1578 u32 ecore_get_process_kill_counter(struct ecore_hwfn *p_hwfn,
1579 struct ecore_ptt *p_ptt)
1581 u32 path_offsize_addr, path_offsize, path_addr, proc_kill_cnt;
1583 /* TODO - Add support for VFs */
1584 if (IS_VF(p_hwfn->p_dev))
1587 path_offsize_addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1589 path_offsize = ecore_rd(p_hwfn, p_ptt, path_offsize_addr);
1590 path_addr = SECTION_ADDR(path_offsize, ECORE_PATH_ID(p_hwfn));
1592 proc_kill_cnt = ecore_rd(p_hwfn, p_ptt,
1594 OFFSETOF(struct public_path, process_kill)) &
1595 PROCESS_KILL_COUNTER_MASK;
1597 return proc_kill_cnt;
1600 static void ecore_mcp_handle_process_kill(struct ecore_hwfn *p_hwfn,
1601 struct ecore_ptt *p_ptt)
1603 struct ecore_dev *p_dev = p_hwfn->p_dev;
1606 /* Prevent possible attentions/interrupts during the recovery handling
1607 * and till its load phase, during which they will be re-enabled.
1609 ecore_int_igu_disable_int(p_hwfn, p_ptt);
1611 DP_NOTICE(p_hwfn, false, "Received a process kill indication\n");
1613 /* The following operations should be done once, and thus in CMT mode
1614 * are carried out by only the first HW function.
1616 if (p_hwfn != ECORE_LEADING_HWFN(p_dev))
1619 if (p_dev->recov_in_prog) {
1620 DP_NOTICE(p_hwfn, false,
1621 "Ignoring the indication since a recovery"
1622 " process is already in progress\n");
1626 p_dev->recov_in_prog = true;
1628 proc_kill_cnt = ecore_get_process_kill_counter(p_hwfn, p_ptt);
1629 DP_NOTICE(p_hwfn, false, "Process kill counter: %d\n", proc_kill_cnt);
1631 OSAL_SCHEDULE_RECOVERY_HANDLER(p_hwfn);
1634 static void ecore_mcp_send_protocol_stats(struct ecore_hwfn *p_hwfn,
1635 struct ecore_ptt *p_ptt,
1636 enum MFW_DRV_MSG_TYPE type)
1638 enum ecore_mcp_protocol_type stats_type;
1639 union ecore_mcp_protocol_stats stats;
1640 struct ecore_mcp_mb_params mb_params;
1642 enum _ecore_status_t rc;
1645 case MFW_DRV_MSG_GET_LAN_STATS:
1646 stats_type = ECORE_MCP_LAN_STATS;
1647 hsi_param = DRV_MSG_CODE_STATS_TYPE_LAN;
1650 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1651 "Invalid protocol type %d\n", type);
1655 OSAL_GET_PROTOCOL_STATS(p_hwfn->p_dev, stats_type, &stats);
1657 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1658 mb_params.cmd = DRV_MSG_CODE_GET_STATS;
1659 mb_params.param = hsi_param;
1660 mb_params.p_data_src = &stats;
1661 mb_params.data_src_size = sizeof(stats);
1662 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1663 if (rc != ECORE_SUCCESS)
1664 DP_ERR(p_hwfn, "Failed to send protocol stats, rc = %d\n", rc);
1667 static void ecore_read_pf_bandwidth(struct ecore_hwfn *p_hwfn,
1668 struct public_func *p_shmem_info)
1670 struct ecore_mcp_function_info *p_info;
1672 p_info = &p_hwfn->mcp_info->func_info;
1674 /* TODO - bandwidth min/max should have valid values of 1-100,
1675 * as well as some indication that the feature is disabled.
1676 * Until MFW/qlediag enforce those limitations, Assume THERE IS ALWAYS
1677 * limit and correct value to min `1' and max `100' if limit isn't in
1680 p_info->bandwidth_min = (p_shmem_info->config &
1681 FUNC_MF_CFG_MIN_BW_MASK) >>
1682 FUNC_MF_CFG_MIN_BW_OFFSET;
1683 if (p_info->bandwidth_min < 1 || p_info->bandwidth_min > 100) {
1685 "bandwidth minimum out of bounds [%02x]. Set to 1\n",
1686 p_info->bandwidth_min);
1687 p_info->bandwidth_min = 1;
1690 p_info->bandwidth_max = (p_shmem_info->config &
1691 FUNC_MF_CFG_MAX_BW_MASK) >>
1692 FUNC_MF_CFG_MAX_BW_OFFSET;
1693 if (p_info->bandwidth_max < 1 || p_info->bandwidth_max > 100) {
1695 "bandwidth maximum out of bounds [%02x]. Set to 100\n",
1696 p_info->bandwidth_max);
1697 p_info->bandwidth_max = 100;
1702 ecore_mcp_update_bw(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
1704 struct ecore_mcp_function_info *p_info;
1705 struct public_func shmem_info;
1706 u32 resp = 0, param = 0;
1708 ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
1710 ecore_read_pf_bandwidth(p_hwfn, &shmem_info);
1712 p_info = &p_hwfn->mcp_info->func_info;
1714 ecore_configure_pf_min_bandwidth(p_hwfn->p_dev, p_info->bandwidth_min);
1716 ecore_configure_pf_max_bandwidth(p_hwfn->p_dev, p_info->bandwidth_max);
1718 /* Acknowledge the MFW */
1719 ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BW_UPDATE_ACK, 0, &resp,
1723 static void ecore_mcp_update_stag(struct ecore_hwfn *p_hwfn,
1724 struct ecore_ptt *p_ptt)
1726 struct public_func shmem_info;
1727 u32 resp = 0, param = 0;
1729 ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
1732 p_hwfn->mcp_info->func_info.ovlan = (u16)shmem_info.ovlan_stag &
1733 FUNC_MF_CFG_OV_STAG_MASK;
1734 p_hwfn->hw_info.ovlan = p_hwfn->mcp_info->func_info.ovlan;
1735 if (OSAL_GET_BIT(ECORE_MF_OVLAN_CLSS, &p_hwfn->p_dev->mf_bits)) {
1736 if (p_hwfn->hw_info.ovlan != ECORE_MCP_VLAN_UNSET) {
1737 ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_VALUE,
1738 p_hwfn->hw_info.ovlan);
1739 ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_EN, 1);
1741 /* Configure DB to add external vlan to EDPM packets */
1742 ecore_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 1);
1743 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_EXT_VID,
1744 p_hwfn->hw_info.ovlan);
1746 ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_EN, 0);
1747 ecore_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_VALUE, 0);
1749 /* Configure DB to add external vlan to EDPM packets */
1750 ecore_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 0);
1751 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_EXT_VID, 0);
1754 ecore_sp_pf_update_stag(p_hwfn);
1757 DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "ovlan = %d hw_mode = 0x%x\n",
1758 p_hwfn->mcp_info->func_info.ovlan, p_hwfn->hw_info.hw_mode);
1759 OSAL_HW_INFO_CHANGE(p_hwfn, ECORE_HW_INFO_CHANGE_OVLAN);
1761 /* Acknowledge the MFW */
1762 ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_S_TAG_UPDATE_ACK, 0,
1766 static void ecore_mcp_handle_fan_failure(struct ecore_hwfn *p_hwfn)
1768 /* A single notification should be sent to upper driver in CMT mode */
1769 if (p_hwfn != ECORE_LEADING_HWFN(p_hwfn->p_dev))
1772 DP_NOTICE(p_hwfn, false,
1773 "Fan failure was detected on the network interface card"
1774 " and it's going to be shut down.\n");
1776 ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_FAN_FAIL);
1779 struct ecore_mdump_cmd_params {
1788 static enum _ecore_status_t
1789 ecore_mcp_mdump_cmd(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1790 struct ecore_mdump_cmd_params *p_mdump_cmd_params)
1792 struct ecore_mcp_mb_params mb_params;
1793 enum _ecore_status_t rc;
1795 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
1796 mb_params.cmd = DRV_MSG_CODE_MDUMP_CMD;
1797 mb_params.param = p_mdump_cmd_params->cmd;
1798 mb_params.p_data_src = p_mdump_cmd_params->p_data_src;
1799 mb_params.data_src_size = p_mdump_cmd_params->data_src_size;
1800 mb_params.p_data_dst = p_mdump_cmd_params->p_data_dst;
1801 mb_params.data_dst_size = p_mdump_cmd_params->data_dst_size;
1802 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1803 if (rc != ECORE_SUCCESS)
1806 p_mdump_cmd_params->mcp_resp = mb_params.mcp_resp;
1808 if (p_mdump_cmd_params->mcp_resp == FW_MSG_CODE_MDUMP_INVALID_CMD) {
1810 "The mdump sub command is unsupported by the MFW [mdump_cmd 0x%x]\n",
1811 p_mdump_cmd_params->cmd);
1813 } else if (p_mdump_cmd_params->mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
1815 "The mdump command is not supported by the MFW\n");
1822 static enum _ecore_status_t ecore_mcp_mdump_ack(struct ecore_hwfn *p_hwfn,
1823 struct ecore_ptt *p_ptt)
1825 struct ecore_mdump_cmd_params mdump_cmd_params;
1827 OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1828 mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_ACK;
1830 return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1833 enum _ecore_status_t ecore_mcp_mdump_set_values(struct ecore_hwfn *p_hwfn,
1834 struct ecore_ptt *p_ptt,
1837 struct ecore_mdump_cmd_params mdump_cmd_params;
1839 OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1840 mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_SET_VALUES;
1841 mdump_cmd_params.p_data_src = &epoch;
1842 mdump_cmd_params.data_src_size = sizeof(epoch);
1844 return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1847 enum _ecore_status_t ecore_mcp_mdump_trigger(struct ecore_hwfn *p_hwfn,
1848 struct ecore_ptt *p_ptt)
1850 struct ecore_mdump_cmd_params mdump_cmd_params;
1852 OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1853 mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_TRIGGER;
1855 return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1858 static enum _ecore_status_t
1859 ecore_mcp_mdump_get_config(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1860 struct mdump_config_stc *p_mdump_config)
1862 struct ecore_mdump_cmd_params mdump_cmd_params;
1863 enum _ecore_status_t rc;
1865 OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1866 mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_GET_CONFIG;
1867 mdump_cmd_params.p_data_dst = p_mdump_config;
1868 mdump_cmd_params.data_dst_size = sizeof(*p_mdump_config);
1870 rc = ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1871 if (rc != ECORE_SUCCESS)
1874 if (mdump_cmd_params.mcp_resp != FW_MSG_CODE_OK) {
1876 "Failed to get the mdump configuration and logs info [mcp_resp 0x%x]\n",
1877 mdump_cmd_params.mcp_resp);
1878 rc = ECORE_UNKNOWN_ERROR;
1884 enum _ecore_status_t
1885 ecore_mcp_mdump_get_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1886 struct ecore_mdump_info *p_mdump_info)
1888 u32 addr, global_offsize, global_addr;
1889 struct mdump_config_stc mdump_config;
1890 enum _ecore_status_t rc;
1893 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
1894 DP_INFO(p_hwfn, "Emulation: Can't get mdump info\n");
1895 return ECORE_NOTIMPL;
1899 OSAL_MEMSET(p_mdump_info, 0, sizeof(*p_mdump_info));
1901 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1903 global_offsize = ecore_rd(p_hwfn, p_ptt, addr);
1904 global_addr = SECTION_ADDR(global_offsize, 0);
1905 p_mdump_info->reason = ecore_rd(p_hwfn, p_ptt,
1907 OFFSETOF(struct public_global,
1910 if (p_mdump_info->reason) {
1911 rc = ecore_mcp_mdump_get_config(p_hwfn, p_ptt, &mdump_config);
1912 if (rc != ECORE_SUCCESS)
1915 p_mdump_info->version = mdump_config.version;
1916 p_mdump_info->config = mdump_config.config;
1917 p_mdump_info->epoch = mdump_config.epoc;
1918 p_mdump_info->num_of_logs = mdump_config.num_of_logs;
1919 p_mdump_info->valid_logs = mdump_config.valid_logs;
1921 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1922 "MFW mdump info: reason %d, version 0x%x, config 0x%x, epoch 0x%x, num_of_logs 0x%x, valid_logs 0x%x\n",
1923 p_mdump_info->reason, p_mdump_info->version,
1924 p_mdump_info->config, p_mdump_info->epoch,
1925 p_mdump_info->num_of_logs, p_mdump_info->valid_logs);
1927 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1928 "MFW mdump info: reason %d\n", p_mdump_info->reason);
1931 return ECORE_SUCCESS;
1934 enum _ecore_status_t ecore_mcp_mdump_clear_logs(struct ecore_hwfn *p_hwfn,
1935 struct ecore_ptt *p_ptt)
1937 struct ecore_mdump_cmd_params mdump_cmd_params;
1939 OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1940 mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_CLEAR_LOGS;
1942 return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1945 enum _ecore_status_t
1946 ecore_mcp_mdump_get_retain(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
1947 struct ecore_mdump_retain_data *p_mdump_retain)
1949 struct ecore_mdump_cmd_params mdump_cmd_params;
1950 struct mdump_retain_data_stc mfw_mdump_retain;
1951 enum _ecore_status_t rc;
1953 OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1954 mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_GET_RETAIN;
1955 mdump_cmd_params.p_data_dst = &mfw_mdump_retain;
1956 mdump_cmd_params.data_dst_size = sizeof(mfw_mdump_retain);
1958 rc = ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1959 if (rc != ECORE_SUCCESS)
1962 if (mdump_cmd_params.mcp_resp != FW_MSG_CODE_OK) {
1964 "Failed to get the mdump retained data [mcp_resp 0x%x]\n",
1965 mdump_cmd_params.mcp_resp);
1966 return ECORE_UNKNOWN_ERROR;
1969 p_mdump_retain->valid = mfw_mdump_retain.valid;
1970 p_mdump_retain->epoch = mfw_mdump_retain.epoch;
1971 p_mdump_retain->pf = mfw_mdump_retain.pf;
1972 p_mdump_retain->status = mfw_mdump_retain.status;
1974 return ECORE_SUCCESS;
1977 enum _ecore_status_t ecore_mcp_mdump_clr_retain(struct ecore_hwfn *p_hwfn,
1978 struct ecore_ptt *p_ptt)
1980 struct ecore_mdump_cmd_params mdump_cmd_params;
1982 OSAL_MEM_ZERO(&mdump_cmd_params, sizeof(mdump_cmd_params));
1983 mdump_cmd_params.cmd = DRV_MSG_CODE_MDUMP_CLR_RETAIN;
1985 return ecore_mcp_mdump_cmd(p_hwfn, p_ptt, &mdump_cmd_params);
1988 static void ecore_mcp_handle_critical_error(struct ecore_hwfn *p_hwfn,
1989 struct ecore_ptt *p_ptt)
1991 struct ecore_mdump_retain_data mdump_retain;
1992 enum _ecore_status_t rc;
1994 /* In CMT mode - no need for more than a single acknowledgment to the
1995 * MFW, and no more than a single notification to the upper driver.
1997 if (p_hwfn != ECORE_LEADING_HWFN(p_hwfn->p_dev))
2000 rc = ecore_mcp_mdump_get_retain(p_hwfn, p_ptt, &mdump_retain);
2001 if (rc == ECORE_SUCCESS && mdump_retain.valid) {
2002 DP_NOTICE(p_hwfn, false,
2003 "The MFW notified that a critical error occurred in the device [epoch 0x%08x, pf 0x%x, status 0x%08x]\n",
2004 mdump_retain.epoch, mdump_retain.pf,
2005 mdump_retain.status);
2007 DP_NOTICE(p_hwfn, false,
2008 "The MFW notified that a critical error occurred in the device\n");
2011 if (p_hwfn->p_dev->allow_mdump) {
2012 DP_NOTICE(p_hwfn, false,
2013 "Not acknowledging the notification to allow the MFW crash dump\n");
2017 DP_NOTICE(p_hwfn, false,
2018 "Acknowledging the notification to not allow the MFW crash dump [driver debug data collection is preferable]\n");
2019 ecore_mcp_mdump_ack(p_hwfn, p_ptt);
2020 ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_HW_ATTN);
2024 ecore_mcp_read_ufp_config(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
2026 struct public_func shmem_info;
2029 if (!OSAL_GET_BIT(ECORE_MF_UFP_SPECIFIC, &p_hwfn->p_dev->mf_bits))
2032 OSAL_MEMSET(&p_hwfn->ufp_info, 0, sizeof(p_hwfn->ufp_info));
2033 port_cfg = ecore_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
2034 OFFSETOF(struct public_port, oem_cfg_port));
2035 val = GET_MFW_FIELD(port_cfg, OEM_CFG_CHANNEL_TYPE);
2036 if (val != OEM_CFG_CHANNEL_TYPE_STAGGED)
2037 DP_NOTICE(p_hwfn, false, "Incorrect UFP Channel type %d\n",
2040 val = GET_MFW_FIELD(port_cfg, OEM_CFG_SCHED_TYPE);
2041 if (val == OEM_CFG_SCHED_TYPE_ETS)
2042 p_hwfn->ufp_info.mode = ECORE_UFP_MODE_ETS;
2043 else if (val == OEM_CFG_SCHED_TYPE_VNIC_BW)
2044 p_hwfn->ufp_info.mode = ECORE_UFP_MODE_VNIC_BW;
2046 DP_NOTICE(p_hwfn, false, "Unknown UFP scheduling mode %d\n",
2049 ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
2051 val = GET_MFW_FIELD(shmem_info.oem_cfg_func, OEM_CFG_FUNC_TC);
2052 p_hwfn->ufp_info.tc = (u8)val;
2053 val = GET_MFW_FIELD(shmem_info.oem_cfg_func,
2054 OEM_CFG_FUNC_HOST_PRI_CTRL);
2055 if (val == OEM_CFG_FUNC_HOST_PRI_CTRL_VNIC)
2056 p_hwfn->ufp_info.pri_type = ECORE_UFP_PRI_VNIC;
2057 else if (val == OEM_CFG_FUNC_HOST_PRI_CTRL_OS)
2058 p_hwfn->ufp_info.pri_type = ECORE_UFP_PRI_OS;
2060 DP_NOTICE(p_hwfn, false, "Unknown Host priority control %d\n",
2063 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
2064 "UFP shmem config: mode = %d tc = %d pri_type = %d\n",
2065 p_hwfn->ufp_info.mode, p_hwfn->ufp_info.tc,
2066 p_hwfn->ufp_info.pri_type);
2069 static enum _ecore_status_t
2070 ecore_mcp_handle_ufp_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
2072 ecore_mcp_read_ufp_config(p_hwfn, p_ptt);
2074 if (p_hwfn->ufp_info.mode == ECORE_UFP_MODE_VNIC_BW) {
2075 p_hwfn->qm_info.ooo_tc = p_hwfn->ufp_info.tc;
2076 p_hwfn->hw_info.offload_tc = p_hwfn->ufp_info.tc;
2078 ecore_qm_reconf(p_hwfn, p_ptt);
2080 /* Merge UFP TC with the dcbx TC data */
2081 ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
2082 ECORE_DCBX_OPERATIONAL_MIB);
2085 /* update storm FW with negotiation results */
2086 ecore_sp_pf_update_ufp(p_hwfn);
2088 /* update stag pcp value */
2089 ecore_sp_pf_update_stag(p_hwfn);
2091 return ECORE_SUCCESS;
2094 enum _ecore_status_t ecore_mcp_handle_events(struct ecore_hwfn *p_hwfn,
2095 struct ecore_ptt *p_ptt)
2097 struct ecore_mcp_info *info = p_hwfn->mcp_info;
2098 enum _ecore_status_t rc = ECORE_SUCCESS;
2102 DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "Received message from MFW\n");
2104 /* Read Messages from MFW */
2105 ecore_mcp_read_mb(p_hwfn, p_ptt);
2107 /* Compare current messages to old ones */
2108 for (i = 0; i < info->mfw_mb_length; i++) {
2109 if (info->mfw_mb_cur[i] == info->mfw_mb_shadow[i])
2114 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
2115 "Msg [%d] - old CMD 0x%02x, new CMD 0x%02x\n",
2116 i, info->mfw_mb_shadow[i], info->mfw_mb_cur[i]);
2119 case MFW_DRV_MSG_LINK_CHANGE:
2120 ecore_mcp_handle_link_change(p_hwfn, p_ptt, false);
2122 case MFW_DRV_MSG_VF_DISABLED:
2123 ecore_mcp_handle_vf_flr(p_hwfn, p_ptt);
2125 case MFW_DRV_MSG_LLDP_DATA_UPDATED:
2126 ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
2127 ECORE_DCBX_REMOTE_LLDP_MIB);
2129 case MFW_DRV_MSG_DCBX_REMOTE_MIB_UPDATED:
2130 ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
2131 ECORE_DCBX_REMOTE_MIB);
2133 case MFW_DRV_MSG_DCBX_OPERATIONAL_MIB_UPDATED:
2134 ecore_dcbx_mib_update_event(p_hwfn, p_ptt,
2135 ECORE_DCBX_OPERATIONAL_MIB);
2136 /* clear the user-config cache */
2137 OSAL_MEMSET(&p_hwfn->p_dcbx_info->set, 0,
2138 sizeof(struct ecore_dcbx_set));
2140 case MFW_DRV_MSG_LLDP_RECEIVED_TLVS_UPDATED:
2141 ecore_lldp_mib_update_event(p_hwfn, p_ptt);
2143 case MFW_DRV_MSG_OEM_CFG_UPDATE:
2144 ecore_mcp_handle_ufp_event(p_hwfn, p_ptt);
2146 case MFW_DRV_MSG_TRANSCEIVER_STATE_CHANGE:
2147 ecore_mcp_handle_transceiver_change(p_hwfn, p_ptt);
2149 case MFW_DRV_MSG_ERROR_RECOVERY:
2150 ecore_mcp_handle_process_kill(p_hwfn, p_ptt);
2152 case MFW_DRV_MSG_GET_LAN_STATS:
2153 case MFW_DRV_MSG_GET_FCOE_STATS:
2154 case MFW_DRV_MSG_GET_ISCSI_STATS:
2155 case MFW_DRV_MSG_GET_RDMA_STATS:
2156 ecore_mcp_send_protocol_stats(p_hwfn, p_ptt, i);
2158 case MFW_DRV_MSG_BW_UPDATE:
2159 ecore_mcp_update_bw(p_hwfn, p_ptt);
2161 case MFW_DRV_MSG_S_TAG_UPDATE:
2162 ecore_mcp_update_stag(p_hwfn, p_ptt);
2164 case MFW_DRV_MSG_FAILURE_DETECTED:
2165 ecore_mcp_handle_fan_failure(p_hwfn);
2167 case MFW_DRV_MSG_CRITICAL_ERROR_OCCURRED:
2168 ecore_mcp_handle_critical_error(p_hwfn, p_ptt);
2171 DP_INFO(p_hwfn, "Unimplemented MFW message %d\n", i);
2176 /* ACK everything */
2177 for (i = 0; i < MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length); i++) {
2178 OSAL_BE32 val = OSAL_CPU_TO_BE32(((u32 *)info->mfw_mb_cur)[i]);
2180 /* MFW expect answer in BE, so we force write in that format */
2181 ecore_wr(p_hwfn, p_ptt,
2182 info->mfw_mb_addr + sizeof(u32) +
2183 MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length) *
2184 sizeof(u32) + i * sizeof(u32), val);
2188 DP_NOTICE(p_hwfn, false,
2189 "Received an MFW message indication but no"
2194 /* Copy the new mfw messages into the shadow */
2195 OSAL_MEMCPY(info->mfw_mb_shadow, info->mfw_mb_cur, info->mfw_mb_length);
2200 enum _ecore_status_t ecore_mcp_get_mfw_ver(struct ecore_hwfn *p_hwfn,
2201 struct ecore_ptt *p_ptt,
2203 u32 *p_running_bundle_id)
2208 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
2209 DP_INFO(p_hwfn, "Emulation: Can't get MFW version\n");
2210 return ECORE_NOTIMPL;
2214 if (IS_VF(p_hwfn->p_dev)) {
2215 if (p_hwfn->vf_iov_info) {
2216 struct pfvf_acquire_resp_tlv *p_resp;
2218 p_resp = &p_hwfn->vf_iov_info->acquire_resp;
2219 *p_mfw_ver = p_resp->pfdev_info.mfw_ver;
2220 return ECORE_SUCCESS;
2222 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2223 "VF requested MFW version prior to ACQUIRE\n");
2228 global_offsize = ecore_rd(p_hwfn, p_ptt,
2229 SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->
2233 ecore_rd(p_hwfn, p_ptt,
2234 SECTION_ADDR(global_offsize,
2235 0) + OFFSETOF(struct public_global, mfw_ver));
2237 if (p_running_bundle_id != OSAL_NULL) {
2238 *p_running_bundle_id = ecore_rd(p_hwfn, p_ptt,
2239 SECTION_ADDR(global_offsize,
2241 OFFSETOF(struct public_global,
2242 running_bundle_id));
2245 return ECORE_SUCCESS;
2248 int ecore_mcp_get_mbi_ver(struct ecore_hwfn *p_hwfn,
2249 struct ecore_ptt *p_ptt, u32 *p_mbi_ver)
2251 u32 nvm_cfg_addr, nvm_cfg1_offset, mbi_ver_addr;
2254 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
2255 DP_INFO(p_hwfn, "Emulation: Can't get MBI version\n");
2260 if (IS_VF(p_hwfn->p_dev))
2263 /* Read the address of the nvm_cfg */
2264 nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2265 if (!nvm_cfg_addr) {
2266 DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
2270 /* Read the offset of nvm_cfg1 */
2271 nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
2273 mbi_ver_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2274 offsetof(struct nvm_cfg1, glob) + offsetof(struct nvm_cfg1_glob,
2277 ecore_rd(p_hwfn, p_ptt,
2278 mbi_ver_addr) & (NVM_CFG1_GLOB_MBI_VERSION_0_MASK |
2279 NVM_CFG1_GLOB_MBI_VERSION_1_MASK |
2280 NVM_CFG1_GLOB_MBI_VERSION_2_MASK);
2285 enum _ecore_status_t ecore_mcp_get_media_type(struct ecore_hwfn *p_hwfn,
2286 struct ecore_ptt *p_ptt,
2289 *p_media_type = MEDIA_UNSPECIFIED;
2291 /* TODO - Add support for VFs */
2292 if (IS_VF(p_hwfn->p_dev))
2295 if (!ecore_mcp_is_init(p_hwfn)) {
2297 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
2298 DP_INFO(p_hwfn, "Emulation: Can't get media type\n");
2299 return ECORE_NOTIMPL;
2302 DP_NOTICE(p_hwfn, false, "MFW is not initialized!\n");
2309 *p_media_type = ecore_rd(p_hwfn, p_ptt,
2310 p_hwfn->mcp_info->port_addr +
2311 OFFSETOF(struct public_port, media_type));
2313 return ECORE_SUCCESS;
2316 enum _ecore_status_t ecore_mcp_get_transceiver_data(struct ecore_hwfn *p_hwfn,
2317 struct ecore_ptt *p_ptt,
2318 u32 *p_transceiver_state,
2319 u32 *p_transceiver_type)
2321 u32 transceiver_info;
2322 enum _ecore_status_t rc = ECORE_SUCCESS;
2324 /* TODO - Add support for VFs */
2325 if (IS_VF(p_hwfn->p_dev))
2328 if (!ecore_mcp_is_init(p_hwfn)) {
2329 DP_NOTICE(p_hwfn, false, "MFW is not initialized!\n");
2333 *p_transceiver_type = ETH_TRANSCEIVER_TYPE_NONE;
2334 *p_transceiver_state = ETH_TRANSCEIVER_STATE_UPDATING;
2336 transceiver_info = ecore_rd(p_hwfn, p_ptt,
2337 p_hwfn->mcp_info->port_addr +
2338 offsetof(struct public_port,
2341 *p_transceiver_state = GET_MFW_FIELD(transceiver_info,
2342 ETH_TRANSCEIVER_STATE);
2344 if (*p_transceiver_state == ETH_TRANSCEIVER_STATE_PRESENT) {
2345 *p_transceiver_type = GET_MFW_FIELD(transceiver_info,
2346 ETH_TRANSCEIVER_TYPE);
2348 *p_transceiver_type = ETH_TRANSCEIVER_TYPE_UNKNOWN;
2354 static int is_transceiver_ready(u32 transceiver_state, u32 transceiver_type)
2356 if ((transceiver_state & ETH_TRANSCEIVER_STATE_PRESENT) &&
2357 ((transceiver_state & ETH_TRANSCEIVER_STATE_UPDATING) == 0x0) &&
2358 (transceiver_type != ETH_TRANSCEIVER_TYPE_NONE))
2364 enum _ecore_status_t ecore_mcp_trans_speed_mask(struct ecore_hwfn *p_hwfn,
2365 struct ecore_ptt *p_ptt,
2368 u32 transceiver_type = ETH_TRANSCEIVER_TYPE_NONE, transceiver_state;
2370 ecore_mcp_get_transceiver_data(p_hwfn, p_ptt, &transceiver_state,
2374 if (is_transceiver_ready(transceiver_state, transceiver_type) == 0)
2377 switch (transceiver_type) {
2378 case ETH_TRANSCEIVER_TYPE_1G_LX:
2379 case ETH_TRANSCEIVER_TYPE_1G_SX:
2380 case ETH_TRANSCEIVER_TYPE_1G_PCC:
2381 case ETH_TRANSCEIVER_TYPE_1G_ACC:
2382 case ETH_TRANSCEIVER_TYPE_1000BASET:
2383 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2386 case ETH_TRANSCEIVER_TYPE_10G_SR:
2387 case ETH_TRANSCEIVER_TYPE_10G_LR:
2388 case ETH_TRANSCEIVER_TYPE_10G_LRM:
2389 case ETH_TRANSCEIVER_TYPE_10G_ER:
2390 case ETH_TRANSCEIVER_TYPE_10G_PCC:
2391 case ETH_TRANSCEIVER_TYPE_10G_ACC:
2392 case ETH_TRANSCEIVER_TYPE_4x10G:
2393 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
2396 case ETH_TRANSCEIVER_TYPE_40G_LR4:
2397 case ETH_TRANSCEIVER_TYPE_40G_SR4:
2398 case ETH_TRANSCEIVER_TYPE_MULTI_RATE_10G_40G_SR:
2399 case ETH_TRANSCEIVER_TYPE_MULTI_RATE_10G_40G_LR:
2400 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2401 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
2404 case ETH_TRANSCEIVER_TYPE_100G_AOC:
2405 case ETH_TRANSCEIVER_TYPE_100G_SR4:
2406 case ETH_TRANSCEIVER_TYPE_100G_LR4:
2407 case ETH_TRANSCEIVER_TYPE_100G_ER4:
2408 case ETH_TRANSCEIVER_TYPE_100G_ACC:
2410 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G |
2411 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
2414 case ETH_TRANSCEIVER_TYPE_25G_SR:
2415 case ETH_TRANSCEIVER_TYPE_25G_LR:
2416 case ETH_TRANSCEIVER_TYPE_25G_AOC:
2417 case ETH_TRANSCEIVER_TYPE_25G_ACC_S:
2418 case ETH_TRANSCEIVER_TYPE_25G_ACC_M:
2419 case ETH_TRANSCEIVER_TYPE_25G_ACC_L:
2420 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
2423 case ETH_TRANSCEIVER_TYPE_25G_CA_N:
2424 case ETH_TRANSCEIVER_TYPE_25G_CA_S:
2425 case ETH_TRANSCEIVER_TYPE_25G_CA_L:
2426 case ETH_TRANSCEIVER_TYPE_4x25G_CR:
2427 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G |
2428 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2429 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2432 case ETH_TRANSCEIVER_TYPE_40G_CR4:
2433 case ETH_TRANSCEIVER_TYPE_MULTI_RATE_10G_40G_CR:
2434 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2435 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2436 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2439 case ETH_TRANSCEIVER_TYPE_100G_CR4:
2440 case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_CR:
2442 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G |
2443 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G |
2444 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2445 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G |
2446 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_20G |
2447 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2448 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2451 case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_SR:
2452 case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_LR:
2453 case ETH_TRANSCEIVER_TYPE_MULTI_RATE_40G_100G_AOC:
2455 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G |
2456 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G |
2457 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G |
2458 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
2461 case ETH_TRANSCEIVER_TYPE_XLPPI:
2462 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
2465 case ETH_TRANSCEIVER_TYPE_10G_BASET:
2466 *p_speed_mask = NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G |
2467 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
2471 DP_INFO(p_hwfn, "Unknown transcevier type 0x%x\n",
2473 *p_speed_mask = 0xff;
2477 return ECORE_SUCCESS;
2480 enum _ecore_status_t ecore_mcp_get_board_config(struct ecore_hwfn *p_hwfn,
2481 struct ecore_ptt *p_ptt,
2482 u32 *p_board_config)
2484 u32 nvm_cfg_addr, nvm_cfg1_offset, port_cfg_addr;
2485 enum _ecore_status_t rc = ECORE_SUCCESS;
2487 /* TODO - Add support for VFs */
2488 if (IS_VF(p_hwfn->p_dev))
2491 if (!ecore_mcp_is_init(p_hwfn)) {
2492 DP_NOTICE(p_hwfn, false, "MFW is not initialized!\n");
2496 *p_board_config = NVM_CFG1_PORT_PORT_TYPE_UNDEFINED;
2499 nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt,
2500 MISC_REG_GEN_PURP_CR0);
2501 nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt,
2503 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2504 offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2505 *p_board_config = ecore_rd(p_hwfn, p_ptt,
2507 offsetof(struct nvm_cfg1_port,
2515 /* Old MFW has a global configuration for all PFs regarding RDMA support */
2517 ecore_mcp_get_shmem_proto_legacy(struct ecore_hwfn *p_hwfn,
2518 enum ecore_pci_personality *p_proto)
2520 *p_proto = ECORE_PCI_ETH;
2522 DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP,
2523 "According to Legacy capabilities, L2 personality is %08x\n",
2528 static enum _ecore_status_t
2529 ecore_mcp_get_shmem_proto_mfw(struct ecore_hwfn *p_hwfn,
2530 struct ecore_ptt *p_ptt,
2531 enum ecore_pci_personality *p_proto)
2533 u32 resp = 0, param = 0;
2534 enum _ecore_status_t rc;
2536 DP_VERBOSE(p_hwfn, ECORE_MSG_IFUP,
2537 "According to capabilities, L2 personality is %08x [resp %08x param %08x]\n",
2538 (u32)*p_proto, resp, param);
2539 return ECORE_SUCCESS;
2542 static enum _ecore_status_t
2543 ecore_mcp_get_shmem_proto(struct ecore_hwfn *p_hwfn,
2544 struct public_func *p_info,
2545 struct ecore_ptt *p_ptt,
2546 enum ecore_pci_personality *p_proto)
2548 enum _ecore_status_t rc = ECORE_SUCCESS;
2550 switch (p_info->config & FUNC_MF_CFG_PROTOCOL_MASK) {
2551 case FUNC_MF_CFG_PROTOCOL_ETHERNET:
2552 if (ecore_mcp_get_shmem_proto_mfw(p_hwfn, p_ptt, p_proto) !=
2554 ecore_mcp_get_shmem_proto_legacy(p_hwfn, p_proto);
2563 enum _ecore_status_t ecore_mcp_fill_shmem_func_info(struct ecore_hwfn *p_hwfn,
2564 struct ecore_ptt *p_ptt)
2566 struct ecore_mcp_function_info *info;
2567 struct public_func shmem_info;
2569 ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
2570 info = &p_hwfn->mcp_info->func_info;
2572 info->pause_on_host = (shmem_info.config &
2573 FUNC_MF_CFG_PAUSE_ON_HOST_RING) ? 1 : 0;
2575 if (ecore_mcp_get_shmem_proto(p_hwfn, &shmem_info, p_ptt,
2577 DP_ERR(p_hwfn, "Unknown personality %08x\n",
2578 (u32)(shmem_info.config & FUNC_MF_CFG_PROTOCOL_MASK));
2582 ecore_read_pf_bandwidth(p_hwfn, &shmem_info);
2584 if (shmem_info.mac_upper || shmem_info.mac_lower) {
2585 info->mac[0] = (u8)(shmem_info.mac_upper >> 8);
2586 info->mac[1] = (u8)(shmem_info.mac_upper);
2587 info->mac[2] = (u8)(shmem_info.mac_lower >> 24);
2588 info->mac[3] = (u8)(shmem_info.mac_lower >> 16);
2589 info->mac[4] = (u8)(shmem_info.mac_lower >> 8);
2590 info->mac[5] = (u8)(shmem_info.mac_lower);
2592 /* TODO - are there protocols for which there's no MAC? */
2593 DP_NOTICE(p_hwfn, false, "MAC is 0 in shmem\n");
2596 /* TODO - are these calculations true for BE machine? */
2597 info->wwn_port = (u64)shmem_info.fcoe_wwn_port_name_upper |
2598 (((u64)shmem_info.fcoe_wwn_port_name_lower) << 32);
2599 info->wwn_node = (u64)shmem_info.fcoe_wwn_node_name_upper |
2600 (((u64)shmem_info.fcoe_wwn_node_name_lower) << 32);
2602 info->ovlan = (u16)(shmem_info.ovlan_stag & FUNC_MF_CFG_OV_STAG_MASK);
2604 info->mtu = (u16)shmem_info.mtu_size;
2609 info->mtu = (u16)shmem_info.mtu_size;
2611 DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_IFUP),
2612 "Read configuration from shmem: pause_on_host %02x"
2613 " protocol %02x BW [%02x - %02x]"
2614 " MAC %02x:%02x:%02x:%02x:%02x:%02x wwn port %lx"
2615 " node %lx ovlan %04x\n",
2616 info->pause_on_host, info->protocol,
2617 info->bandwidth_min, info->bandwidth_max,
2618 info->mac[0], info->mac[1], info->mac[2],
2619 info->mac[3], info->mac[4], info->mac[5],
2620 (unsigned long)info->wwn_port,
2621 (unsigned long)info->wwn_node, info->ovlan);
2623 return ECORE_SUCCESS;
2626 struct ecore_mcp_link_params
2627 *ecore_mcp_get_link_params(struct ecore_hwfn *p_hwfn)
2629 if (!p_hwfn || !p_hwfn->mcp_info)
2631 return &p_hwfn->mcp_info->link_input;
2634 struct ecore_mcp_link_state
2635 *ecore_mcp_get_link_state(struct ecore_hwfn *p_hwfn)
2637 if (!p_hwfn || !p_hwfn->mcp_info)
2641 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2642 DP_INFO(p_hwfn, "Non-ASIC - always notify that link is up\n");
2643 p_hwfn->mcp_info->link_output.link_up = true;
2647 return &p_hwfn->mcp_info->link_output;
2650 struct ecore_mcp_link_capabilities
2651 *ecore_mcp_get_link_capabilities(struct ecore_hwfn *p_hwfn)
2653 if (!p_hwfn || !p_hwfn->mcp_info)
2655 return &p_hwfn->mcp_info->link_capabilities;
2658 enum _ecore_status_t ecore_mcp_drain(struct ecore_hwfn *p_hwfn,
2659 struct ecore_ptt *p_ptt)
2661 u32 resp = 0, param = 0;
2662 enum _ecore_status_t rc;
2664 rc = ecore_mcp_cmd(p_hwfn, p_ptt,
2665 DRV_MSG_CODE_NIG_DRAIN, 1000, &resp, ¶m);
2667 /* Wait for the drain to complete before returning */
2673 const struct ecore_mcp_function_info
2674 *ecore_mcp_get_function_info(struct ecore_hwfn *p_hwfn)
2676 if (!p_hwfn || !p_hwfn->mcp_info)
2678 return &p_hwfn->mcp_info->func_info;
2681 int ecore_mcp_get_personality_cnt(struct ecore_hwfn *p_hwfn,
2682 struct ecore_ptt *p_ptt, u32 personalities)
2684 enum ecore_pci_personality protocol = ECORE_PCI_DEFAULT;
2685 struct public_func shmem_info;
2686 int i, count = 0, num_pfs;
2688 num_pfs = NUM_OF_ENG_PFS(p_hwfn->p_dev);
2690 for (i = 0; i < num_pfs; i++) {
2691 ecore_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info,
2692 MCP_PF_ID_BY_REL(p_hwfn, i));
2693 if (shmem_info.config & FUNC_MF_CFG_FUNC_HIDE)
2696 if (ecore_mcp_get_shmem_proto(p_hwfn, &shmem_info, p_ptt,
2701 if ((1 << ((u32)protocol)) & personalities)
2708 enum _ecore_status_t ecore_mcp_get_flash_size(struct ecore_hwfn *p_hwfn,
2709 struct ecore_ptt *p_ptt,
2715 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
2716 DP_INFO(p_hwfn, "Emulation: Can't get flash size\n");
2717 return ECORE_NOTIMPL;
2721 if (IS_VF(p_hwfn->p_dev))
2724 flash_size = ecore_rd(p_hwfn, p_ptt, MCP_REG_NVM_CFG4);
2725 flash_size = (flash_size & MCP_REG_NVM_CFG4_FLASH_SIZE) >>
2726 MCP_REG_NVM_CFG4_FLASH_SIZE_SHIFT;
2727 flash_size = (1 << (flash_size + MCP_BYTES_PER_MBIT_OFFSET));
2729 *p_flash_size = flash_size;
2731 return ECORE_SUCCESS;
2734 enum _ecore_status_t ecore_start_recovery_process(struct ecore_hwfn *p_hwfn,
2735 struct ecore_ptt *p_ptt)
2737 struct ecore_dev *p_dev = p_hwfn->p_dev;
2739 if (p_dev->recov_in_prog) {
2740 DP_NOTICE(p_hwfn, false,
2741 "Avoid triggering a recovery since such a process"
2742 " is already in progress\n");
2746 DP_NOTICE(p_hwfn, false, "Triggering a recovery process\n");
2747 ecore_wr(p_hwfn, p_ptt, MISC_REG_AEU_GENERAL_ATTN_35, 0x1);
2749 return ECORE_SUCCESS;
2752 static enum _ecore_status_t
2753 ecore_mcp_config_vf_msix_bb(struct ecore_hwfn *p_hwfn,
2754 struct ecore_ptt *p_ptt,
2757 u32 resp = 0, param = 0, rc_param = 0;
2758 enum _ecore_status_t rc;
2760 /* Only Leader can configure MSIX, and need to take CMT into account */
2762 if (!IS_LEAD_HWFN(p_hwfn))
2763 return ECORE_SUCCESS;
2764 num *= p_hwfn->p_dev->num_hwfns;
2766 param |= (vf_id << DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_OFFSET) &
2767 DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_MASK;
2768 param |= (num << DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_OFFSET) &
2769 DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_MASK;
2771 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_VF_MSIX, param,
2774 if (resp != FW_MSG_CODE_DRV_CFG_VF_MSIX_DONE) {
2775 DP_NOTICE(p_hwfn, true, "VF[%d]: MFW failed to set MSI-X\n",
2779 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2780 "Requested 0x%02x MSI-x interrupts from VF 0x%02x\n",
2787 static enum _ecore_status_t
2788 ecore_mcp_config_vf_msix_ah(struct ecore_hwfn *p_hwfn,
2789 struct ecore_ptt *p_ptt,
2792 u32 resp = 0, param = num, rc_param = 0;
2793 enum _ecore_status_t rc;
2795 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_PF_VFS_MSIX,
2796 param, &resp, &rc_param);
2798 if (resp != FW_MSG_CODE_DRV_CFG_PF_VFS_MSIX_DONE) {
2799 DP_NOTICE(p_hwfn, true, "MFW failed to set MSI-X for VFs\n");
2802 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
2803 "Requested 0x%02x MSI-x interrupts for VFs\n",
2810 enum _ecore_status_t ecore_mcp_config_vf_msix(struct ecore_hwfn *p_hwfn,
2811 struct ecore_ptt *p_ptt,
2815 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && !ecore_mcp_is_init(p_hwfn)) {
2817 "Emulation: Avoid sending the %s mailbox command\n",
2818 ECORE_IS_BB(p_hwfn->p_dev) ? "CFG_VF_MSIX" :
2820 return ECORE_SUCCESS;
2824 if (ECORE_IS_BB(p_hwfn->p_dev))
2825 return ecore_mcp_config_vf_msix_bb(p_hwfn, p_ptt, vf_id, num);
2827 return ecore_mcp_config_vf_msix_ah(p_hwfn, p_ptt, num);
2830 enum _ecore_status_t
2831 ecore_mcp_send_drv_version(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
2832 struct ecore_mcp_drv_version *p_ver)
2834 struct ecore_mcp_mb_params mb_params;
2835 struct drv_version_stc drv_version;
2839 enum _ecore_status_t rc;
2842 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev))
2843 return ECORE_SUCCESS;
2846 OSAL_MEM_ZERO(&drv_version, sizeof(drv_version));
2847 drv_version.version = p_ver->version;
2848 num_words = (MCP_DRV_VER_STR_SIZE - 4) / 4;
2849 for (i = 0; i < num_words; i++) {
2850 /* The driver name is expected to be in a big-endian format */
2851 p_name = &p_ver->name[i * sizeof(u32)];
2852 val = OSAL_CPU_TO_BE32(*(u32 *)p_name);
2853 *(u32 *)&drv_version.name[i * sizeof(u32)] = val;
2856 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
2857 mb_params.cmd = DRV_MSG_CODE_SET_VERSION;
2858 mb_params.p_data_src = &drv_version;
2859 mb_params.data_src_size = sizeof(drv_version);
2860 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
2861 if (rc != ECORE_SUCCESS)
2862 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2867 /* A maximal 100 msec waiting time for the MCP to halt */
2868 #define ECORE_MCP_HALT_SLEEP_MS 10
2869 #define ECORE_MCP_HALT_MAX_RETRIES 10
2871 enum _ecore_status_t ecore_mcp_halt(struct ecore_hwfn *p_hwfn,
2872 struct ecore_ptt *p_ptt)
2874 u32 resp = 0, param = 0, cpu_state, cnt = 0;
2875 enum _ecore_status_t rc;
2877 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MCP_HALT, 0, &resp,
2879 if (rc != ECORE_SUCCESS) {
2880 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2885 OSAL_MSLEEP(ECORE_MCP_HALT_SLEEP_MS);
2886 cpu_state = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2887 if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED)
2889 } while (++cnt < ECORE_MCP_HALT_MAX_RETRIES);
2891 if (cnt == ECORE_MCP_HALT_MAX_RETRIES) {
2892 DP_NOTICE(p_hwfn, false,
2893 "Failed to halt the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2894 ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE), cpu_state);
2898 ecore_mcp_cmd_set_blocking(p_hwfn, true);
2900 return ECORE_SUCCESS;
2903 #define ECORE_MCP_RESUME_SLEEP_MS 10
2905 enum _ecore_status_t ecore_mcp_resume(struct ecore_hwfn *p_hwfn,
2906 struct ecore_ptt *p_ptt)
2908 u32 cpu_mode, cpu_state;
2910 ecore_wr(p_hwfn, p_ptt, MCP_REG_CPU_STATE, 0xffffffff);
2912 cpu_mode = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
2913 cpu_mode &= ~MCP_REG_CPU_MODE_SOFT_HALT;
2914 ecore_wr(p_hwfn, p_ptt, MCP_REG_CPU_MODE, cpu_mode);
2916 OSAL_MSLEEP(ECORE_MCP_RESUME_SLEEP_MS);
2917 cpu_state = ecore_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2919 if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED) {
2920 DP_NOTICE(p_hwfn, false,
2921 "Failed to resume the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2922 cpu_mode, cpu_state);
2926 ecore_mcp_cmd_set_blocking(p_hwfn, false);
2928 return ECORE_SUCCESS;
2931 enum _ecore_status_t
2932 ecore_mcp_ov_update_current_config(struct ecore_hwfn *p_hwfn,
2933 struct ecore_ptt *p_ptt,
2934 enum ecore_ov_client client)
2936 u32 resp = 0, param = 0;
2938 enum _ecore_status_t rc;
2941 case ECORE_OV_CLIENT_DRV:
2942 drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OS;
2944 case ECORE_OV_CLIENT_USER:
2945 drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OTHER;
2947 case ECORE_OV_CLIENT_VENDOR_SPEC:
2948 drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_VENDOR_SPEC;
2951 DP_NOTICE(p_hwfn, true, "Invalid client type %d\n", client);
2955 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_CURR_CFG,
2956 drv_mb_param, &resp, ¶m);
2957 if (rc != ECORE_SUCCESS)
2958 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2963 enum _ecore_status_t
2964 ecore_mcp_ov_update_driver_state(struct ecore_hwfn *p_hwfn,
2965 struct ecore_ptt *p_ptt,
2966 enum ecore_ov_driver_state drv_state)
2968 u32 resp = 0, param = 0;
2970 enum _ecore_status_t rc;
2972 switch (drv_state) {
2973 case ECORE_OV_DRIVER_STATE_NOT_LOADED:
2974 drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_NOT_LOADED;
2976 case ECORE_OV_DRIVER_STATE_DISABLED:
2977 drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_DISABLED;
2979 case ECORE_OV_DRIVER_STATE_ACTIVE:
2980 drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_ACTIVE;
2983 DP_NOTICE(p_hwfn, true, "Invalid driver state %d\n", drv_state);
2987 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE,
2988 drv_mb_param, &resp, ¶m);
2989 if (rc != ECORE_SUCCESS)
2990 DP_ERR(p_hwfn, "Failed to send driver state\n");
2995 enum _ecore_status_t
2996 ecore_mcp_ov_get_fc_npiv(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
2997 struct ecore_fc_npiv_tbl *p_table)
3002 enum _ecore_status_t
3003 ecore_mcp_ov_update_mtu(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3006 u32 resp = 0, param = 0, drv_mb_param = 0;
3007 enum _ecore_status_t rc;
3009 SET_MFW_FIELD(drv_mb_param, DRV_MB_PARAM_OV_MTU_SIZE, (u32)mtu);
3010 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_MTU,
3011 drv_mb_param, &resp, ¶m);
3012 if (rc != ECORE_SUCCESS)
3013 DP_ERR(p_hwfn, "Failed to send mtu value, rc = %d\n", rc);
3018 enum _ecore_status_t
3019 ecore_mcp_ov_update_mac(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3022 struct ecore_mcp_mb_params mb_params;
3023 union drv_union_data union_data;
3024 enum _ecore_status_t rc;
3026 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
3027 mb_params.cmd = DRV_MSG_CODE_SET_VMAC;
3028 SET_MFW_FIELD(mb_params.param, DRV_MSG_CODE_VMAC_TYPE,
3029 DRV_MSG_CODE_VMAC_TYPE_MAC);
3030 mb_params.param |= MCP_PF_ID(p_hwfn);
3031 OSAL_MEMCPY(&union_data.raw_data, mac, ETH_ALEN);
3032 mb_params.p_data_src = &union_data;
3033 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
3034 if (rc != ECORE_SUCCESS)
3035 DP_ERR(p_hwfn, "Failed to send mac address, rc = %d\n", rc);
3040 enum _ecore_status_t
3041 ecore_mcp_ov_update_eswitch(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3042 enum ecore_ov_eswitch eswitch)
3044 enum _ecore_status_t rc;
3045 u32 resp = 0, param = 0;
3049 case ECORE_OV_ESWITCH_NONE:
3050 drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_NONE;
3052 case ECORE_OV_ESWITCH_VEB:
3053 drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEB;
3055 case ECORE_OV_ESWITCH_VEPA:
3056 drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEPA;
3059 DP_ERR(p_hwfn, "Invalid eswitch mode %d\n", eswitch);
3063 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_ESWITCH_MODE,
3064 drv_mb_param, &resp, ¶m);
3065 if (rc != ECORE_SUCCESS)
3066 DP_ERR(p_hwfn, "Failed to send eswitch mode, rc = %d\n", rc);
3071 enum _ecore_status_t ecore_mcp_set_led(struct ecore_hwfn *p_hwfn,
3072 struct ecore_ptt *p_ptt,
3073 enum ecore_led_mode mode)
3075 u32 resp = 0, param = 0, drv_mb_param;
3076 enum _ecore_status_t rc;
3079 case ECORE_LED_MODE_ON:
3080 drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_ON;
3082 case ECORE_LED_MODE_OFF:
3083 drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OFF;
3085 case ECORE_LED_MODE_RESTORE:
3086 drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OPER;
3089 DP_NOTICE(p_hwfn, true, "Invalid LED mode %d\n", mode);
3093 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LED_MODE,
3094 drv_mb_param, &resp, ¶m);
3095 if (rc != ECORE_SUCCESS)
3096 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
3101 enum _ecore_status_t ecore_mcp_mask_parities(struct ecore_hwfn *p_hwfn,
3102 struct ecore_ptt *p_ptt,
3105 u32 resp = 0, param = 0;
3106 enum _ecore_status_t rc;
3108 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MASK_PARITIES,
3109 mask_parities, &resp, ¶m);
3111 if (rc != ECORE_SUCCESS) {
3113 "MCP response failure for mask parities, aborting\n");
3114 } else if (resp != FW_MSG_CODE_OK) {
3116 "MCP did not ack mask parity request. Old MFW?\n");
3123 enum _ecore_status_t ecore_mcp_nvm_read(struct ecore_dev *p_dev, u32 addr,
3126 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3127 u32 bytes_left, offset, bytes_to_copy, buf_size;
3128 u32 nvm_offset, resp, param;
3129 struct ecore_ptt *p_ptt;
3130 enum _ecore_status_t rc = ECORE_SUCCESS;
3132 p_ptt = ecore_ptt_acquire(p_hwfn);
3138 while (bytes_left > 0) {
3139 bytes_to_copy = OSAL_MIN_T(u32, bytes_left,
3140 MCP_DRV_NVM_BUF_LEN);
3141 nvm_offset = (addr + offset) | (bytes_to_copy <<
3142 DRV_MB_PARAM_NVM_LEN_OFFSET);
3143 rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
3144 DRV_MSG_CODE_NVM_READ_NVRAM,
3145 nvm_offset, &resp, ¶m, &buf_size,
3146 (u32 *)(p_buf + offset));
3147 if (rc != ECORE_SUCCESS) {
3148 DP_NOTICE(p_dev, false,
3149 "ecore_mcp_nvm_rd_cmd() failed, rc = %d\n",
3151 resp = FW_MSG_CODE_ERROR;
3155 if (resp != FW_MSG_CODE_NVM_OK) {
3156 DP_NOTICE(p_dev, false,
3157 "nvm read failed, resp = 0x%08x\n", resp);
3158 rc = ECORE_UNKNOWN_ERROR;
3162 /* This can be a lengthy process, and it's possible scheduler
3163 * isn't preemptible. Sleep a bit to prevent CPU hogging.
3165 if (bytes_left % 0x1000 <
3166 (bytes_left - buf_size) % 0x1000)
3170 bytes_left -= buf_size;
3173 p_dev->mcp_nvm_resp = resp;
3174 ecore_ptt_release(p_hwfn, p_ptt);
3179 enum _ecore_status_t ecore_mcp_phy_read(struct ecore_dev *p_dev, u32 cmd,
3180 u32 addr, u8 *p_buf, u32 *p_len)
3182 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3183 struct ecore_ptt *p_ptt;
3184 u32 resp = 0, param;
3185 enum _ecore_status_t rc;
3187 p_ptt = ecore_ptt_acquire(p_hwfn);
3191 rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
3192 (cmd == ECORE_PHY_CORE_READ) ?
3193 DRV_MSG_CODE_PHY_CORE_READ :
3194 DRV_MSG_CODE_PHY_RAW_READ,
3195 addr, &resp, ¶m, p_len, (u32 *)p_buf);
3196 if (rc != ECORE_SUCCESS)
3197 DP_NOTICE(p_dev, false, "MCP command rc = %d\n", rc);
3199 p_dev->mcp_nvm_resp = resp;
3200 ecore_ptt_release(p_hwfn, p_ptt);
3205 enum _ecore_status_t ecore_mcp_nvm_resp(struct ecore_dev *p_dev, u8 *p_buf)
3207 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3208 struct ecore_ptt *p_ptt;
3210 p_ptt = ecore_ptt_acquire(p_hwfn);
3214 OSAL_MEMCPY(p_buf, &p_dev->mcp_nvm_resp, sizeof(p_dev->mcp_nvm_resp));
3215 ecore_ptt_release(p_hwfn, p_ptt);
3217 return ECORE_SUCCESS;
3220 enum _ecore_status_t ecore_mcp_nvm_del_file(struct ecore_dev *p_dev, u32 addr)
3222 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3223 struct ecore_ptt *p_ptt;
3224 u32 resp = 0, param;
3225 enum _ecore_status_t rc;
3227 p_ptt = ecore_ptt_acquire(p_hwfn);
3230 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_NVM_DEL_FILE, addr,
3232 p_dev->mcp_nvm_resp = resp;
3233 ecore_ptt_release(p_hwfn, p_ptt);
3238 enum _ecore_status_t ecore_mcp_nvm_put_file_begin(struct ecore_dev *p_dev,
3241 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3242 struct ecore_ptt *p_ptt;
3243 u32 resp = 0, param;
3244 enum _ecore_status_t rc;
3246 p_ptt = ecore_ptt_acquire(p_hwfn);
3249 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_NVM_PUT_FILE_BEGIN, addr,
3251 p_dev->mcp_nvm_resp = resp;
3252 ecore_ptt_release(p_hwfn, p_ptt);
3257 /* rc receives ECORE_INVAL as default parameter because
3258 * it might not enter the while loop if the len is 0
3260 enum _ecore_status_t ecore_mcp_nvm_write(struct ecore_dev *p_dev, u32 cmd,
3261 u32 addr, u8 *p_buf, u32 len)
3263 u32 buf_idx, buf_size, nvm_cmd, nvm_offset;
3264 u32 resp = FW_MSG_CODE_ERROR, param;
3265 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3266 enum _ecore_status_t rc = ECORE_INVAL;
3267 struct ecore_ptt *p_ptt;
3269 p_ptt = ecore_ptt_acquire(p_hwfn);
3274 case ECORE_PUT_FILE_DATA:
3275 nvm_cmd = DRV_MSG_CODE_NVM_PUT_FILE_DATA;
3277 case ECORE_NVM_WRITE_NVRAM:
3278 nvm_cmd = DRV_MSG_CODE_NVM_WRITE_NVRAM;
3280 case ECORE_EXT_PHY_FW_UPGRADE:
3281 nvm_cmd = DRV_MSG_CODE_EXT_PHY_FW_UPGRADE;
3284 DP_NOTICE(p_hwfn, true, "Invalid nvm write command 0x%x\n",
3291 while (buf_idx < len) {
3292 buf_size = OSAL_MIN_T(u32, (len - buf_idx),
3293 MCP_DRV_NVM_BUF_LEN);
3294 nvm_offset = ((buf_size << DRV_MB_PARAM_NVM_LEN_OFFSET) |
3297 rc = ecore_mcp_nvm_wr_cmd(p_hwfn, p_ptt, nvm_cmd, nvm_offset,
3298 &resp, ¶m, buf_size,
3299 (u32 *)&p_buf[buf_idx]);
3300 if (rc != ECORE_SUCCESS) {
3301 DP_NOTICE(p_dev, false,
3302 "ecore_mcp_nvm_write() failed, rc = %d\n",
3304 resp = FW_MSG_CODE_ERROR;
3308 if (resp != FW_MSG_CODE_OK &&
3309 resp != FW_MSG_CODE_NVM_OK &&
3310 resp != FW_MSG_CODE_NVM_PUT_FILE_FINISH_OK) {
3311 DP_NOTICE(p_dev, false,
3312 "nvm write failed, resp = 0x%08x\n", resp);
3313 rc = ECORE_UNKNOWN_ERROR;
3317 /* This can be a lengthy process, and it's possible scheduler
3318 * isn't preemptible. Sleep a bit to prevent CPU hogging.
3320 if (buf_idx % 0x1000 >
3321 (buf_idx + buf_size) % 0x1000)
3324 buf_idx += buf_size;
3327 p_dev->mcp_nvm_resp = resp;
3329 ecore_ptt_release(p_hwfn, p_ptt);
3334 enum _ecore_status_t ecore_mcp_phy_write(struct ecore_dev *p_dev, u32 cmd,
3335 u32 addr, u8 *p_buf, u32 len)
3337 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3338 u32 resp = 0, param, nvm_cmd;
3339 struct ecore_ptt *p_ptt;
3340 enum _ecore_status_t rc;
3342 p_ptt = ecore_ptt_acquire(p_hwfn);
3346 nvm_cmd = (cmd == ECORE_PHY_CORE_WRITE) ? DRV_MSG_CODE_PHY_CORE_WRITE :
3347 DRV_MSG_CODE_PHY_RAW_WRITE;
3348 rc = ecore_mcp_nvm_wr_cmd(p_hwfn, p_ptt, nvm_cmd, addr,
3349 &resp, ¶m, len, (u32 *)p_buf);
3350 if (rc != ECORE_SUCCESS)
3351 DP_NOTICE(p_dev, false, "MCP command rc = %d\n", rc);
3352 p_dev->mcp_nvm_resp = resp;
3353 ecore_ptt_release(p_hwfn, p_ptt);
3358 enum _ecore_status_t ecore_mcp_nvm_set_secure_mode(struct ecore_dev *p_dev,
3361 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3362 struct ecore_ptt *p_ptt;
3363 u32 resp = 0, param;
3364 enum _ecore_status_t rc;
3366 p_ptt = ecore_ptt_acquire(p_hwfn);
3370 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_SECURE_MODE, addr,
3372 p_dev->mcp_nvm_resp = resp;
3373 ecore_ptt_release(p_hwfn, p_ptt);
3378 enum _ecore_status_t ecore_mcp_phy_sfp_read(struct ecore_hwfn *p_hwfn,
3379 struct ecore_ptt *p_ptt,
3380 u32 port, u32 addr, u32 offset,
3383 u32 bytes_left, bytes_to_copy, buf_size, nvm_offset;
3385 enum _ecore_status_t rc;
3387 nvm_offset = (port << DRV_MB_PARAM_TRANSCEIVER_PORT_OFFSET) |
3388 (addr << DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_OFFSET);
3392 while (bytes_left > 0) {
3393 bytes_to_copy = OSAL_MIN_T(u32, bytes_left,
3394 MAX_I2C_TRANSACTION_SIZE);
3395 nvm_offset &= (DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK |
3396 DRV_MB_PARAM_TRANSCEIVER_PORT_MASK);
3397 nvm_offset |= ((addr + offset) <<
3398 DRV_MB_PARAM_TRANSCEIVER_OFFSET_OFFSET);
3399 nvm_offset |= (bytes_to_copy <<
3400 DRV_MB_PARAM_TRANSCEIVER_SIZE_OFFSET);
3401 rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
3402 DRV_MSG_CODE_TRANSCEIVER_READ,
3403 nvm_offset, &resp, ¶m, &buf_size,
3404 (u32 *)(p_buf + offset));
3405 if (rc != ECORE_SUCCESS) {
3406 DP_NOTICE(p_hwfn, false,
3407 "Failed to send a transceiver read command to the MFW. rc = %d.\n",
3412 if (resp == FW_MSG_CODE_TRANSCEIVER_NOT_PRESENT)
3414 else if (resp != FW_MSG_CODE_TRANSCEIVER_DIAG_OK)
3415 return ECORE_UNKNOWN_ERROR;
3418 bytes_left -= buf_size;
3421 return ECORE_SUCCESS;
3424 enum _ecore_status_t ecore_mcp_phy_sfp_write(struct ecore_hwfn *p_hwfn,
3425 struct ecore_ptt *p_ptt,
3426 u32 port, u32 addr, u32 offset,
3429 u32 buf_idx, buf_size, nvm_offset, resp, param;
3430 enum _ecore_status_t rc;
3432 nvm_offset = (port << DRV_MB_PARAM_TRANSCEIVER_PORT_OFFSET) |
3433 (addr << DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_OFFSET);
3435 while (buf_idx < len) {
3436 buf_size = OSAL_MIN_T(u32, (len - buf_idx),
3437 MAX_I2C_TRANSACTION_SIZE);
3438 nvm_offset &= (DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK |
3439 DRV_MB_PARAM_TRANSCEIVER_PORT_MASK);
3440 nvm_offset |= ((offset + buf_idx) <<
3441 DRV_MB_PARAM_TRANSCEIVER_OFFSET_OFFSET);
3442 nvm_offset |= (buf_size <<
3443 DRV_MB_PARAM_TRANSCEIVER_SIZE_OFFSET);
3444 rc = ecore_mcp_nvm_wr_cmd(p_hwfn, p_ptt,
3445 DRV_MSG_CODE_TRANSCEIVER_WRITE,
3446 nvm_offset, &resp, ¶m, buf_size,
3447 (u32 *)&p_buf[buf_idx]);
3448 if (rc != ECORE_SUCCESS) {
3449 DP_NOTICE(p_hwfn, false,
3450 "Failed to send a transceiver write command to the MFW. rc = %d.\n",
3455 if (resp == FW_MSG_CODE_TRANSCEIVER_NOT_PRESENT)
3457 else if (resp != FW_MSG_CODE_TRANSCEIVER_DIAG_OK)
3458 return ECORE_UNKNOWN_ERROR;
3460 buf_idx += buf_size;
3463 return ECORE_SUCCESS;
3466 enum _ecore_status_t ecore_mcp_gpio_read(struct ecore_hwfn *p_hwfn,
3467 struct ecore_ptt *p_ptt,
3468 u16 gpio, u32 *gpio_val)
3470 enum _ecore_status_t rc = ECORE_SUCCESS;
3471 u32 drv_mb_param = 0, rsp = 0;
3473 drv_mb_param = (gpio << DRV_MB_PARAM_GPIO_NUMBER_OFFSET);
3475 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GPIO_READ,
3476 drv_mb_param, &rsp, gpio_val);
3478 if (rc != ECORE_SUCCESS)
3481 if ((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_GPIO_OK)
3482 return ECORE_UNKNOWN_ERROR;
3484 return ECORE_SUCCESS;
3487 enum _ecore_status_t ecore_mcp_gpio_write(struct ecore_hwfn *p_hwfn,
3488 struct ecore_ptt *p_ptt,
3489 u16 gpio, u16 gpio_val)
3491 enum _ecore_status_t rc = ECORE_SUCCESS;
3492 u32 drv_mb_param = 0, param, rsp = 0;
3494 drv_mb_param = (gpio << DRV_MB_PARAM_GPIO_NUMBER_OFFSET) |
3495 (gpio_val << DRV_MB_PARAM_GPIO_VALUE_OFFSET);
3497 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GPIO_WRITE,
3498 drv_mb_param, &rsp, ¶m);
3500 if (rc != ECORE_SUCCESS)
3503 if ((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_GPIO_OK)
3504 return ECORE_UNKNOWN_ERROR;
3506 return ECORE_SUCCESS;
3509 enum _ecore_status_t ecore_mcp_gpio_info(struct ecore_hwfn *p_hwfn,
3510 struct ecore_ptt *p_ptt,
3511 u16 gpio, u32 *gpio_direction,
3514 u32 drv_mb_param = 0, rsp, val = 0;
3515 enum _ecore_status_t rc = ECORE_SUCCESS;
3517 drv_mb_param = gpio << DRV_MB_PARAM_GPIO_NUMBER_OFFSET;
3519 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GPIO_INFO,
3520 drv_mb_param, &rsp, &val);
3521 if (rc != ECORE_SUCCESS)
3524 *gpio_direction = (val & DRV_MB_PARAM_GPIO_DIRECTION_MASK) >>
3525 DRV_MB_PARAM_GPIO_DIRECTION_OFFSET;
3526 *gpio_ctrl = (val & DRV_MB_PARAM_GPIO_CTRL_MASK) >>
3527 DRV_MB_PARAM_GPIO_CTRL_OFFSET;
3529 if ((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_GPIO_OK)
3530 return ECORE_UNKNOWN_ERROR;
3532 return ECORE_SUCCESS;
3535 enum _ecore_status_t ecore_mcp_bist_register_test(struct ecore_hwfn *p_hwfn,
3536 struct ecore_ptt *p_ptt)
3538 u32 drv_mb_param = 0, rsp, param;
3539 enum _ecore_status_t rc = ECORE_SUCCESS;
3541 drv_mb_param = (DRV_MB_PARAM_BIST_REGISTER_TEST <<
3542 DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
3544 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
3545 drv_mb_param, &rsp, ¶m);
3547 if (rc != ECORE_SUCCESS)
3550 if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
3551 (param != DRV_MB_PARAM_BIST_RC_PASSED))
3552 rc = ECORE_UNKNOWN_ERROR;
3557 enum _ecore_status_t ecore_mcp_bist_clock_test(struct ecore_hwfn *p_hwfn,
3558 struct ecore_ptt *p_ptt)
3560 u32 drv_mb_param, rsp, param;
3561 enum _ecore_status_t rc = ECORE_SUCCESS;
3563 drv_mb_param = (DRV_MB_PARAM_BIST_CLOCK_TEST <<
3564 DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
3566 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
3567 drv_mb_param, &rsp, ¶m);
3569 if (rc != ECORE_SUCCESS)
3572 if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
3573 (param != DRV_MB_PARAM_BIST_RC_PASSED))
3574 rc = ECORE_UNKNOWN_ERROR;
3579 enum _ecore_status_t ecore_mcp_bist_nvm_test_get_num_images(
3580 struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, u32 *num_images)
3582 u32 drv_mb_param = 0, rsp = 0;
3583 enum _ecore_status_t rc = ECORE_SUCCESS;
3585 drv_mb_param = (DRV_MB_PARAM_BIST_NVM_TEST_NUM_IMAGES <<
3586 DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
3588 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
3589 drv_mb_param, &rsp, num_images);
3591 if (rc != ECORE_SUCCESS)
3594 if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK))
3595 rc = ECORE_UNKNOWN_ERROR;
3600 enum _ecore_status_t ecore_mcp_bist_nvm_test_get_image_att(
3601 struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3602 struct bist_nvm_image_att *p_image_att, u32 image_index)
3604 u32 buf_size, nvm_offset, resp, param;
3605 enum _ecore_status_t rc;
3607 nvm_offset = (DRV_MB_PARAM_BIST_NVM_TEST_IMAGE_BY_INDEX <<
3608 DRV_MB_PARAM_BIST_TEST_INDEX_OFFSET);
3609 nvm_offset |= (image_index <<
3610 DRV_MB_PARAM_BIST_TEST_IMAGE_INDEX_OFFSET);
3611 rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
3612 nvm_offset, &resp, ¶m, &buf_size,
3613 (u32 *)p_image_att);
3614 if (rc != ECORE_SUCCESS)
3617 if (((resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
3618 (p_image_att->return_code != 1))
3619 rc = ECORE_UNKNOWN_ERROR;
3624 enum _ecore_status_t
3625 ecore_mcp_get_temperature_info(struct ecore_hwfn *p_hwfn,
3626 struct ecore_ptt *p_ptt,
3627 struct ecore_temperature_info *p_temp_info)
3629 struct ecore_temperature_sensor *p_temp_sensor;
3630 struct temperature_status_stc mfw_temp_info;
3631 struct ecore_mcp_mb_params mb_params;
3633 enum _ecore_status_t rc;
3636 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
3637 mb_params.cmd = DRV_MSG_CODE_GET_TEMPERATURE;
3638 mb_params.p_data_dst = &mfw_temp_info;
3639 mb_params.data_dst_size = sizeof(mfw_temp_info);
3640 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
3641 if (rc != ECORE_SUCCESS)
3644 OSAL_BUILD_BUG_ON(ECORE_MAX_NUM_OF_SENSORS != MAX_NUM_OF_SENSORS);
3645 p_temp_info->num_sensors = OSAL_MIN_T(u32, mfw_temp_info.num_of_sensors,
3646 ECORE_MAX_NUM_OF_SENSORS);
3647 for (i = 0; i < p_temp_info->num_sensors; i++) {
3648 val = mfw_temp_info.sensor[i];
3649 p_temp_sensor = &p_temp_info->sensors[i];
3650 p_temp_sensor->sensor_location = (val & SENSOR_LOCATION_MASK) >>
3651 SENSOR_LOCATION_OFFSET;
3652 p_temp_sensor->threshold_high = (val & THRESHOLD_HIGH_MASK) >>
3653 THRESHOLD_HIGH_OFFSET;
3654 p_temp_sensor->critical = (val & CRITICAL_TEMPERATURE_MASK) >>
3655 CRITICAL_TEMPERATURE_OFFSET;
3656 p_temp_sensor->current_temp = (val & CURRENT_TEMP_MASK) >>
3657 CURRENT_TEMP_OFFSET;
3660 return ECORE_SUCCESS;
3663 enum _ecore_status_t ecore_mcp_get_mba_versions(
3664 struct ecore_hwfn *p_hwfn,
3665 struct ecore_ptt *p_ptt,
3666 struct ecore_mba_vers *p_mba_vers)
3668 u32 buf_size, resp, param;
3669 enum _ecore_status_t rc;
3671 rc = ecore_mcp_nvm_rd_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GET_MBA_VERSION,
3672 0, &resp, ¶m, &buf_size,
3673 &p_mba_vers->mba_vers[0]);
3675 if (rc != ECORE_SUCCESS)
3678 if ((resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_NVM_OK)
3679 rc = ECORE_UNKNOWN_ERROR;
3681 if (buf_size != MCP_DRV_NVM_BUF_LEN)
3682 rc = ECORE_UNKNOWN_ERROR;
3687 enum _ecore_status_t ecore_mcp_mem_ecc_events(struct ecore_hwfn *p_hwfn,
3688 struct ecore_ptt *p_ptt,
3693 return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MEM_ECC_EVENTS,
3694 0, &rsp, (u32 *)num_events);
3697 static enum resource_id_enum
3698 ecore_mcp_get_mfw_res_id(enum ecore_resources res_id)
3700 enum resource_id_enum mfw_res_id = RESOURCE_NUM_INVALID;
3704 mfw_res_id = RESOURCE_NUM_SB_E;
3706 case ECORE_L2_QUEUE:
3707 mfw_res_id = RESOURCE_NUM_L2_QUEUE_E;
3710 mfw_res_id = RESOURCE_NUM_VPORT_E;
3713 mfw_res_id = RESOURCE_NUM_RSS_ENGINES_E;
3716 mfw_res_id = RESOURCE_NUM_PQ_E;
3719 mfw_res_id = RESOURCE_NUM_RL_E;
3723 /* Each VFC resource can accommodate both a MAC and a VLAN */
3724 mfw_res_id = RESOURCE_VFC_FILTER_E;
3727 mfw_res_id = RESOURCE_ILT_E;
3729 case ECORE_LL2_QUEUE:
3730 mfw_res_id = RESOURCE_LL2_QUEUE_E;
3732 case ECORE_RDMA_CNQ_RAM:
3733 case ECORE_CMDQS_CQS:
3734 /* CNQ/CMDQS are the same resource */
3735 mfw_res_id = RESOURCE_CQS_E;
3737 case ECORE_RDMA_STATS_QUEUE:
3738 mfw_res_id = RESOURCE_RDMA_STATS_QUEUE_E;
3741 mfw_res_id = RESOURCE_BDQ_E;
3750 #define ECORE_RESC_ALLOC_VERSION_MAJOR 2
3751 #define ECORE_RESC_ALLOC_VERSION_MINOR 0
3752 #define ECORE_RESC_ALLOC_VERSION \
3753 ((ECORE_RESC_ALLOC_VERSION_MAJOR << \
3754 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR_OFFSET) | \
3755 (ECORE_RESC_ALLOC_VERSION_MINOR << \
3756 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR_OFFSET))
3758 struct ecore_resc_alloc_in_params {
3760 enum ecore_resources res_id;
3764 struct ecore_resc_alloc_out_params {
3774 #define ECORE_RECOVERY_PROLOG_SLEEP_MS 100
3776 enum _ecore_status_t ecore_recovery_prolog(struct ecore_dev *p_dev)
3778 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3779 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
3780 enum _ecore_status_t rc;
3782 /* Allow ongoing PCIe transactions to complete */
3783 OSAL_MSLEEP(ECORE_RECOVERY_PROLOG_SLEEP_MS);
3785 /* Clear the PF's internal FID_enable in the PXP */
3786 rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_ptt, false);
3787 if (rc != ECORE_SUCCESS)
3788 DP_NOTICE(p_hwfn, false,
3789 "ecore_pglueb_set_pfid_enable() failed. rc = %d.\n",
3795 static enum _ecore_status_t
3796 ecore_mcp_resc_allocation_msg(struct ecore_hwfn *p_hwfn,
3797 struct ecore_ptt *p_ptt,
3798 struct ecore_resc_alloc_in_params *p_in_params,
3799 struct ecore_resc_alloc_out_params *p_out_params)
3801 struct ecore_mcp_mb_params mb_params;
3802 struct resource_info mfw_resc_info;
3803 enum _ecore_status_t rc;
3805 OSAL_MEM_ZERO(&mfw_resc_info, sizeof(mfw_resc_info));
3807 mfw_resc_info.res_id = ecore_mcp_get_mfw_res_id(p_in_params->res_id);
3808 if (mfw_resc_info.res_id == RESOURCE_NUM_INVALID) {
3810 "Failed to match resource %d [%s] with the MFW resources\n",
3811 p_in_params->res_id,
3812 ecore_hw_get_resc_name(p_in_params->res_id));
3816 switch (p_in_params->cmd) {
3817 case DRV_MSG_SET_RESOURCE_VALUE_MSG:
3818 mfw_resc_info.size = p_in_params->resc_max_val;
3820 case DRV_MSG_GET_RESOURCE_ALLOC_MSG:
3823 DP_ERR(p_hwfn, "Unexpected resource alloc command [0x%08x]\n",
3828 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
3829 mb_params.cmd = p_in_params->cmd;
3830 mb_params.param = ECORE_RESC_ALLOC_VERSION;
3831 mb_params.p_data_src = &mfw_resc_info;
3832 mb_params.data_src_size = sizeof(mfw_resc_info);
3833 mb_params.p_data_dst = mb_params.p_data_src;
3834 mb_params.data_dst_size = mb_params.data_src_size;
3836 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
3837 "Resource message request: cmd 0x%08x, res_id %d [%s], hsi_version %d.%d, val 0x%x\n",
3838 p_in_params->cmd, p_in_params->res_id,
3839 ecore_hw_get_resc_name(p_in_params->res_id),
3840 GET_MFW_FIELD(mb_params.param,
3841 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR),
3842 GET_MFW_FIELD(mb_params.param,
3843 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR),
3844 p_in_params->resc_max_val);
3846 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
3847 if (rc != ECORE_SUCCESS)
3850 p_out_params->mcp_resp = mb_params.mcp_resp;
3851 p_out_params->mcp_param = mb_params.mcp_param;
3852 p_out_params->resc_num = mfw_resc_info.size;
3853 p_out_params->resc_start = mfw_resc_info.offset;
3854 p_out_params->vf_resc_num = mfw_resc_info.vf_size;
3855 p_out_params->vf_resc_start = mfw_resc_info.vf_offset;
3856 p_out_params->flags = mfw_resc_info.flags;
3858 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
3859 "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",
3860 GET_MFW_FIELD(p_out_params->mcp_param,
3861 FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR),
3862 GET_MFW_FIELD(p_out_params->mcp_param,
3863 FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR),
3864 p_out_params->resc_num, p_out_params->resc_start,
3865 p_out_params->vf_resc_num, p_out_params->vf_resc_start,
3866 p_out_params->flags);
3868 return ECORE_SUCCESS;
3871 enum _ecore_status_t
3872 ecore_mcp_set_resc_max_val(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3873 enum ecore_resources res_id, u32 resc_max_val,
3876 struct ecore_resc_alloc_out_params out_params;
3877 struct ecore_resc_alloc_in_params in_params;
3878 enum _ecore_status_t rc;
3880 OSAL_MEM_ZERO(&in_params, sizeof(in_params));
3881 in_params.cmd = DRV_MSG_SET_RESOURCE_VALUE_MSG;
3882 in_params.res_id = res_id;
3883 in_params.resc_max_val = resc_max_val;
3884 OSAL_MEM_ZERO(&out_params, sizeof(out_params));
3885 rc = ecore_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params,
3887 if (rc != ECORE_SUCCESS)
3890 *p_mcp_resp = out_params.mcp_resp;
3892 return ECORE_SUCCESS;
3895 enum _ecore_status_t
3896 ecore_mcp_get_resc_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3897 enum ecore_resources res_id, u32 *p_mcp_resp,
3898 u32 *p_resc_num, u32 *p_resc_start)
3900 struct ecore_resc_alloc_out_params out_params;
3901 struct ecore_resc_alloc_in_params in_params;
3902 enum _ecore_status_t rc;
3904 OSAL_MEM_ZERO(&in_params, sizeof(in_params));
3905 in_params.cmd = DRV_MSG_GET_RESOURCE_ALLOC_MSG;
3906 in_params.res_id = res_id;
3907 OSAL_MEM_ZERO(&out_params, sizeof(out_params));
3908 rc = ecore_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params,
3910 if (rc != ECORE_SUCCESS)
3913 *p_mcp_resp = out_params.mcp_resp;
3915 if (*p_mcp_resp == FW_MSG_CODE_RESOURCE_ALLOC_OK) {
3916 *p_resc_num = out_params.resc_num;
3917 *p_resc_start = out_params.resc_start;
3920 return ECORE_SUCCESS;
3923 enum _ecore_status_t ecore_mcp_initiate_pf_flr(struct ecore_hwfn *p_hwfn,
3924 struct ecore_ptt *p_ptt)
3926 u32 mcp_resp, mcp_param;
3928 return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_INITIATE_PF_FLR, 0,
3929 &mcp_resp, &mcp_param);
3932 static enum _ecore_status_t ecore_mcp_resource_cmd(struct ecore_hwfn *p_hwfn,
3933 struct ecore_ptt *p_ptt,
3934 u32 param, u32 *p_mcp_resp,
3937 enum _ecore_status_t rc;
3939 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_RESOURCE_CMD, param,
3940 p_mcp_resp, p_mcp_param);
3941 if (rc != ECORE_SUCCESS)
3944 if (*p_mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
3946 "The resource command is unsupported by the MFW\n");
3947 return ECORE_NOTIMPL;
3950 if (*p_mcp_param == RESOURCE_OPCODE_UNKNOWN_CMD) {
3951 u8 opcode = GET_MFW_FIELD(param, RESOURCE_CMD_REQ_OPCODE);
3953 DP_NOTICE(p_hwfn, false,
3954 "The resource command is unknown to the MFW [param 0x%08x, opcode %d]\n",
3962 enum _ecore_status_t
3963 __ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3964 struct ecore_resc_lock_params *p_params)
3966 u32 param = 0, mcp_resp = 0, mcp_param = 0;
3968 enum _ecore_status_t rc;
3970 switch (p_params->timeout) {
3971 case ECORE_MCP_RESC_LOCK_TO_DEFAULT:
3972 opcode = RESOURCE_OPCODE_REQ;
3973 p_params->timeout = 0;
3975 case ECORE_MCP_RESC_LOCK_TO_NONE:
3976 opcode = RESOURCE_OPCODE_REQ_WO_AGING;
3977 p_params->timeout = 0;
3980 opcode = RESOURCE_OPCODE_REQ_W_AGING;
3984 SET_MFW_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource);
3985 SET_MFW_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode);
3986 SET_MFW_FIELD(param, RESOURCE_CMD_REQ_AGE, p_params->timeout);
3988 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
3989 "Resource lock request: param 0x%08x [age %d, opcode %d, resource %d]\n",
3990 param, p_params->timeout, opcode, p_params->resource);
3992 /* Attempt to acquire the resource */
3993 rc = ecore_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp,
3995 if (rc != ECORE_SUCCESS)
3998 /* Analyze the response */
3999 p_params->owner = GET_MFW_FIELD(mcp_param, RESOURCE_CMD_RSP_OWNER);
4000 opcode = GET_MFW_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE);
4002 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
4003 "Resource lock response: mcp_param 0x%08x [opcode %d, owner %d]\n",
4004 mcp_param, opcode, p_params->owner);
4007 case RESOURCE_OPCODE_GNT:
4008 p_params->b_granted = true;
4010 case RESOURCE_OPCODE_BUSY:
4011 p_params->b_granted = false;
4014 DP_NOTICE(p_hwfn, false,
4015 "Unexpected opcode in resource lock response [mcp_param 0x%08x, opcode %d]\n",
4020 return ECORE_SUCCESS;
4023 enum _ecore_status_t
4024 ecore_mcp_resc_lock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
4025 struct ecore_resc_lock_params *p_params)
4028 enum _ecore_status_t rc;
4031 /* No need for an interval before the first iteration */
4033 if (p_params->sleep_b4_retry) {
4034 u16 retry_interval_in_ms =
4035 DIV_ROUND_UP(p_params->retry_interval,
4038 OSAL_MSLEEP(retry_interval_in_ms);
4040 OSAL_UDELAY(p_params->retry_interval);
4044 rc = __ecore_mcp_resc_lock(p_hwfn, p_ptt, p_params);
4045 if (rc != ECORE_SUCCESS)
4048 if (p_params->b_granted)
4050 } while (retry_cnt++ < p_params->retry_num);
4052 return ECORE_SUCCESS;
4055 void ecore_mcp_resc_lock_default_init(struct ecore_resc_lock_params *p_lock,
4056 struct ecore_resc_unlock_params *p_unlock,
4057 enum ecore_resc_lock resource,
4058 bool b_is_permanent)
4060 if (p_lock != OSAL_NULL) {
4061 OSAL_MEM_ZERO(p_lock, sizeof(*p_lock));
4063 /* Permanent resources don't require aging, and there's no
4064 * point in trying to acquire them more than once since it's
4065 * unexpected another entity would release them.
4067 if (b_is_permanent) {
4068 p_lock->timeout = ECORE_MCP_RESC_LOCK_TO_NONE;
4070 p_lock->retry_num = ECORE_MCP_RESC_LOCK_RETRY_CNT_DFLT;
4071 p_lock->retry_interval =
4072 ECORE_MCP_RESC_LOCK_RETRY_VAL_DFLT;
4073 p_lock->sleep_b4_retry = true;
4076 p_lock->resource = resource;
4079 if (p_unlock != OSAL_NULL) {
4080 OSAL_MEM_ZERO(p_unlock, sizeof(*p_unlock));
4081 p_unlock->resource = resource;
4085 enum _ecore_status_t
4086 ecore_mcp_resc_unlock(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
4087 struct ecore_resc_unlock_params *p_params)
4089 u32 param = 0, mcp_resp, mcp_param;
4091 enum _ecore_status_t rc;
4093 opcode = p_params->b_force ? RESOURCE_OPCODE_FORCE_RELEASE
4094 : RESOURCE_OPCODE_RELEASE;
4095 SET_MFW_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource);
4096 SET_MFW_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode);
4098 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
4099 "Resource unlock request: param 0x%08x [opcode %d, resource %d]\n",
4100 param, opcode, p_params->resource);
4102 /* Attempt to release the resource */
4103 rc = ecore_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp,
4105 if (rc != ECORE_SUCCESS)
4108 /* Analyze the response */
4109 opcode = GET_MFW_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE);
4111 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
4112 "Resource unlock response: mcp_param 0x%08x [opcode %d]\n",
4116 case RESOURCE_OPCODE_RELEASED_PREVIOUS:
4118 "Resource unlock request for an already released resource [%d]\n",
4119 p_params->resource);
4121 case RESOURCE_OPCODE_RELEASED:
4122 p_params->b_released = true;
4124 case RESOURCE_OPCODE_WRONG_OWNER:
4125 p_params->b_released = false;
4128 DP_NOTICE(p_hwfn, false,
4129 "Unexpected opcode in resource unlock response [mcp_param 0x%08x, opcode %d]\n",
4134 return ECORE_SUCCESS;
4137 bool ecore_mcp_is_smart_an_supported(struct ecore_hwfn *p_hwfn)
4139 return !!(p_hwfn->mcp_info->capabilities &
4140 FW_MB_PARAM_FEATURE_SUPPORT_SMARTLINQ);
4143 enum _ecore_status_t ecore_mcp_get_capabilities(struct ecore_hwfn *p_hwfn,
4144 struct ecore_ptt *p_ptt)
4147 enum _ecore_status_t rc;
4149 rc = ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GET_MFW_FEATURE_SUPPORT,
4150 0, &mcp_resp, &p_hwfn->mcp_info->capabilities);
4151 if (rc == ECORE_SUCCESS)
4152 DP_VERBOSE(p_hwfn, (ECORE_MSG_SP | ECORE_MSG_PROBE),
4153 "MFW supported features: %08x\n",
4154 p_hwfn->mcp_info->capabilities);
4159 enum _ecore_status_t ecore_mcp_set_capabilities(struct ecore_hwfn *p_hwfn,
4160 struct ecore_ptt *p_ptt)
4162 u32 mcp_resp, mcp_param, features;
4164 features = DRV_MB_PARAM_FEATURE_SUPPORT_PORT_SMARTLINQ |
4165 DRV_MB_PARAM_FEATURE_SUPPORT_PORT_EEE |
4166 DRV_MB_PARAM_FEATURE_SUPPORT_FUNC_VLINK;
4168 return ecore_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_FEATURE_SUPPORT,
4169 features, &mcp_resp, &mcp_param);
4172 enum _ecore_status_t
4173 ecore_mcp_drv_attribute(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
4174 struct ecore_mcp_drv_attr *p_drv_attr)
4176 struct attribute_cmd_write_stc attr_cmd_write;
4177 enum _attribute_commands_e mfw_attr_cmd;
4178 struct ecore_mcp_mb_params mb_params;
4179 enum _ecore_status_t rc;
4181 switch (p_drv_attr->attr_cmd) {
4182 case ECORE_MCP_DRV_ATTR_CMD_READ:
4183 mfw_attr_cmd = ATTRIBUTE_CMD_READ;
4185 case ECORE_MCP_DRV_ATTR_CMD_WRITE:
4186 mfw_attr_cmd = ATTRIBUTE_CMD_WRITE;
4188 case ECORE_MCP_DRV_ATTR_CMD_READ_CLEAR:
4189 mfw_attr_cmd = ATTRIBUTE_CMD_READ_CLEAR;
4191 case ECORE_MCP_DRV_ATTR_CMD_CLEAR:
4192 mfw_attr_cmd = ATTRIBUTE_CMD_CLEAR;
4195 DP_NOTICE(p_hwfn, false, "Unknown attribute command %d\n",
4196 p_drv_attr->attr_cmd);
4200 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
4201 mb_params.cmd = DRV_MSG_CODE_ATTRIBUTE;
4202 SET_MFW_FIELD(mb_params.param, DRV_MB_PARAM_ATTRIBUTE_KEY,
4203 p_drv_attr->attr_num);
4204 SET_MFW_FIELD(mb_params.param, DRV_MB_PARAM_ATTRIBUTE_CMD,
4206 if (p_drv_attr->attr_cmd == ECORE_MCP_DRV_ATTR_CMD_WRITE) {
4207 OSAL_MEM_ZERO(&attr_cmd_write, sizeof(attr_cmd_write));
4208 attr_cmd_write.val = p_drv_attr->val;
4209 attr_cmd_write.mask = p_drv_attr->mask;
4210 attr_cmd_write.offset = p_drv_attr->offset;
4212 mb_params.p_data_src = &attr_cmd_write;
4213 mb_params.data_src_size = sizeof(attr_cmd_write);
4216 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
4217 if (rc != ECORE_SUCCESS)
4220 if (mb_params.mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
4222 "The attribute command is not supported by the MFW\n");
4223 return ECORE_NOTIMPL;
4224 } else if (mb_params.mcp_resp != FW_MSG_CODE_OK) {
4226 "Failed to send an attribute command [mcp_resp 0x%x, attr_cmd %d, attr_num %d]\n",
4227 mb_params.mcp_resp, p_drv_attr->attr_cmd,
4228 p_drv_attr->attr_num);
4232 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
4233 "Attribute Command: cmd %d [mfw_cmd %d], num %d, in={val 0x%08x, mask 0x%08x, offset 0x%08x}, out={val 0x%08x}\n",
4234 p_drv_attr->attr_cmd, mfw_attr_cmd, p_drv_attr->attr_num,
4235 p_drv_attr->val, p_drv_attr->mask, p_drv_attr->offset,
4236 mb_params.mcp_param);
4238 if (p_drv_attr->attr_cmd == ECORE_MCP_DRV_ATTR_CMD_READ ||
4239 p_drv_attr->attr_cmd == ECORE_MCP_DRV_ATTR_CMD_READ_CLEAR)
4240 p_drv_attr->val = mb_params.mcp_param;
4242 return ECORE_SUCCESS;
4245 enum _ecore_status_t ecore_mcp_get_engine_config(struct ecore_hwfn *p_hwfn,
4246 struct ecore_ptt *p_ptt)
4248 struct ecore_dev *p_dev = p_hwfn->p_dev;
4249 struct ecore_mcp_mb_params mb_params;
4250 u8 fir_valid, l2_valid;
4251 enum _ecore_status_t rc;
4253 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
4254 mb_params.cmd = DRV_MSG_CODE_GET_ENGINE_CONFIG;
4255 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
4256 if (rc != ECORE_SUCCESS)
4259 if (mb_params.mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
4261 "The get_engine_config command is unsupported by the MFW\n");
4262 return ECORE_NOTIMPL;
4265 fir_valid = GET_MFW_FIELD(mb_params.mcp_param,
4266 FW_MB_PARAM_ENG_CFG_FIR_AFFIN_VALID);
4269 GET_MFW_FIELD(mb_params.mcp_param,
4270 FW_MB_PARAM_ENG_CFG_FIR_AFFIN_VALUE);
4272 l2_valid = GET_MFW_FIELD(mb_params.mcp_param,
4273 FW_MB_PARAM_ENG_CFG_L2_AFFIN_VALID);
4275 p_dev->l2_affin_hint =
4276 GET_MFW_FIELD(mb_params.mcp_param,
4277 FW_MB_PARAM_ENG_CFG_L2_AFFIN_VALUE);
4280 "Engine affinity config: FIR={valid %hhd, value %hhd}, L2_hint={valid %hhd, value %hhd}\n",
4281 fir_valid, p_dev->fir_affin, l2_valid, p_dev->l2_affin_hint);
4283 return ECORE_SUCCESS;
4286 enum _ecore_status_t ecore_mcp_get_ppfid_bitmap(struct ecore_hwfn *p_hwfn,
4287 struct ecore_ptt *p_ptt)
4289 struct ecore_dev *p_dev = p_hwfn->p_dev;
4290 struct ecore_mcp_mb_params mb_params;
4291 enum _ecore_status_t rc;
4293 OSAL_MEM_ZERO(&mb_params, sizeof(mb_params));
4294 mb_params.cmd = DRV_MSG_CODE_GET_PPFID_BITMAP;
4295 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
4296 if (rc != ECORE_SUCCESS)
4299 if (mb_params.mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
4301 "The get_ppfid_bitmap command is unsupported by the MFW\n");
4302 return ECORE_NOTIMPL;
4305 p_dev->ppfid_bitmap = GET_MFW_FIELD(mb_params.mcp_param,
4306 FW_MB_PARAM_PPFID_BITMAP);
4308 DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "PPFID bitmap 0x%hhx\n",
4309 p_dev->ppfid_bitmap);
4311 return ECORE_SUCCESS;
4314 void ecore_mcp_wol_wr(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
4315 u32 offset, u32 val)
4317 enum _ecore_status_t rc = ECORE_SUCCESS;
4319 struct ecore_mcp_mb_params mb_params;
4321 OSAL_MEMSET(&mb_params, 0, sizeof(struct ecore_mcp_mb_params));
4322 mb_params.cmd = DRV_MSG_CODE_WRITE_WOL_REG;
4323 mb_params.param = offset;
4324 mb_params.p_data_src = &dword;
4325 mb_params.data_src_size = sizeof(dword);
4327 rc = ecore_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
4328 if (rc != ECORE_SUCCESS) {
4329 DP_NOTICE(p_hwfn, false,
4330 "Failed to wol write request, rc = %d\n", rc);
4333 if (mb_params.mcp_resp != FW_MSG_CODE_WOL_READ_WRITE_OK) {
4334 DP_NOTICE(p_hwfn, false,
4335 "Failed to write value 0x%x to offset 0x%x [mcp_resp 0x%x]\n",
4336 val, offset, mb_params.mcp_resp);
4337 rc = ECORE_UNKNOWN_ERROR;