1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/types.h>
34 #include <asm/byteorder.h>
35 #include <linux/delay.h>
36 #include <linux/errno.h>
37 #include <linux/kernel.h>
38 #include <linux/slab.h>
39 #include <linux/spinlock.h>
40 #include <linux/string.h>
41 #include <linux/etherdevice.h>
48 #include "qed_reg_addr.h"
49 #include "qed_sriov.h"
51 #define QED_MCP_RESP_ITER_US 10
53 #define QED_DRV_MB_MAX_RETRIES (500 * 1000) /* Account for 5 sec */
54 #define QED_MCP_RESET_RETRIES (50 * 1000) /* Account for 500 msec */
56 #define DRV_INNER_WR(_p_hwfn, _p_ptt, _ptr, _offset, _val) \
57 qed_wr(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset), \
60 #define DRV_INNER_RD(_p_hwfn, _p_ptt, _ptr, _offset) \
61 qed_rd(_p_hwfn, _p_ptt, (_p_hwfn->mcp_info->_ptr + _offset))
63 #define DRV_MB_WR(_p_hwfn, _p_ptt, _field, _val) \
64 DRV_INNER_WR(p_hwfn, _p_ptt, drv_mb_addr, \
65 offsetof(struct public_drv_mb, _field), _val)
67 #define DRV_MB_RD(_p_hwfn, _p_ptt, _field) \
68 DRV_INNER_RD(_p_hwfn, _p_ptt, drv_mb_addr, \
69 offsetof(struct public_drv_mb, _field))
71 #define PDA_COMP (((FW_MAJOR_VERSION) + (FW_MINOR_VERSION << 8)) << \
72 DRV_ID_PDA_COMP_VER_SHIFT)
74 #define MCP_BYTES_PER_MBIT_SHIFT 17
76 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn)
78 if (!p_hwfn->mcp_info || !p_hwfn->mcp_info->public_base)
83 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
85 u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
87 u32 mfw_mb_offsize = qed_rd(p_hwfn, p_ptt, addr);
89 p_hwfn->mcp_info->port_addr = SECTION_ADDR(mfw_mb_offsize,
91 DP_VERBOSE(p_hwfn, QED_MSG_SP,
92 "port_addr = 0x%x, port_id 0x%02x\n",
93 p_hwfn->mcp_info->port_addr, MFW_PORT(p_hwfn));
96 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
98 u32 length = MFW_DRV_MSG_MAX_DWORDS(p_hwfn->mcp_info->mfw_mb_length);
101 if (!p_hwfn->mcp_info->public_base)
104 for (i = 0; i < length; i++) {
105 tmp = qed_rd(p_hwfn, p_ptt,
106 p_hwfn->mcp_info->mfw_mb_addr +
107 (i << 2) + sizeof(u32));
109 /* The MB data is actually BE; Need to force it to cpu */
110 ((u32 *)p_hwfn->mcp_info->mfw_mb_cur)[i] =
111 be32_to_cpu((__force __be32)tmp);
115 struct qed_mcp_cmd_elem {
116 struct list_head list;
117 struct qed_mcp_mb_params *p_mb_params;
118 u16 expected_seq_num;
122 /* Must be called while cmd_lock is acquired */
123 static struct qed_mcp_cmd_elem *
124 qed_mcp_cmd_add_elem(struct qed_hwfn *p_hwfn,
125 struct qed_mcp_mb_params *p_mb_params,
126 u16 expected_seq_num)
128 struct qed_mcp_cmd_elem *p_cmd_elem = NULL;
130 p_cmd_elem = kzalloc(sizeof(*p_cmd_elem), GFP_ATOMIC);
134 p_cmd_elem->p_mb_params = p_mb_params;
135 p_cmd_elem->expected_seq_num = expected_seq_num;
136 list_add(&p_cmd_elem->list, &p_hwfn->mcp_info->cmd_list);
141 /* Must be called while cmd_lock is acquired */
142 static void qed_mcp_cmd_del_elem(struct qed_hwfn *p_hwfn,
143 struct qed_mcp_cmd_elem *p_cmd_elem)
145 list_del(&p_cmd_elem->list);
149 /* Must be called while cmd_lock is acquired */
150 static struct qed_mcp_cmd_elem *qed_mcp_cmd_get_elem(struct qed_hwfn *p_hwfn,
153 struct qed_mcp_cmd_elem *p_cmd_elem = NULL;
155 list_for_each_entry(p_cmd_elem, &p_hwfn->mcp_info->cmd_list, list) {
156 if (p_cmd_elem->expected_seq_num == seq_num)
163 int qed_mcp_free(struct qed_hwfn *p_hwfn)
165 if (p_hwfn->mcp_info) {
166 struct qed_mcp_cmd_elem *p_cmd_elem, *p_tmp;
168 kfree(p_hwfn->mcp_info->mfw_mb_cur);
169 kfree(p_hwfn->mcp_info->mfw_mb_shadow);
171 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
172 list_for_each_entry_safe(p_cmd_elem,
174 &p_hwfn->mcp_info->cmd_list, list) {
175 qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
177 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
180 kfree(p_hwfn->mcp_info);
181 p_hwfn->mcp_info = NULL;
186 /* Maximum of 1 sec to wait for the SHMEM ready indication */
187 #define QED_MCP_SHMEM_RDY_MAX_RETRIES 20
188 #define QED_MCP_SHMEM_RDY_ITER_MS 50
190 static int qed_load_mcp_offsets(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
192 struct qed_mcp_info *p_info = p_hwfn->mcp_info;
193 u8 cnt = QED_MCP_SHMEM_RDY_MAX_RETRIES;
194 u8 msec = QED_MCP_SHMEM_RDY_ITER_MS;
195 u32 drv_mb_offsize, mfw_mb_offsize;
196 u32 mcp_pf_id = MCP_PF_ID(p_hwfn);
198 p_info->public_base = qed_rd(p_hwfn, p_ptt, MISC_REG_SHARED_MEM_ADDR);
199 if (!p_info->public_base) {
201 "The address of the MCP scratch-pad is not configured\n");
205 p_info->public_base |= GRCBASE_MCP;
207 /* Get the MFW MB address and number of supported messages */
208 mfw_mb_offsize = qed_rd(p_hwfn, p_ptt,
209 SECTION_OFFSIZE_ADDR(p_info->public_base,
211 p_info->mfw_mb_addr = SECTION_ADDR(mfw_mb_offsize, mcp_pf_id);
212 p_info->mfw_mb_length = (u16)qed_rd(p_hwfn, p_ptt,
213 p_info->mfw_mb_addr +
214 offsetof(struct public_mfw_mb,
217 /* The driver can notify that there was an MCP reset, and might read the
218 * SHMEM values before the MFW has completed initializing them.
219 * To avoid this, the "sup_msgs" field in the MFW mailbox is used as a
220 * data ready indication.
222 while (!p_info->mfw_mb_length && --cnt) {
224 p_info->mfw_mb_length =
225 (u16)qed_rd(p_hwfn, p_ptt,
226 p_info->mfw_mb_addr +
227 offsetof(struct public_mfw_mb, sup_msgs));
232 "Failed to get the SHMEM ready notification after %d msec\n",
233 QED_MCP_SHMEM_RDY_MAX_RETRIES * msec);
237 /* Calculate the driver and MFW mailbox address */
238 drv_mb_offsize = qed_rd(p_hwfn, p_ptt,
239 SECTION_OFFSIZE_ADDR(p_info->public_base,
241 p_info->drv_mb_addr = SECTION_ADDR(drv_mb_offsize, mcp_pf_id);
242 DP_VERBOSE(p_hwfn, QED_MSG_SP,
243 "drv_mb_offsiz = 0x%x, drv_mb_addr = 0x%x mcp_pf_id = 0x%x\n",
244 drv_mb_offsize, p_info->drv_mb_addr, mcp_pf_id);
246 /* Get the current driver mailbox sequence before sending
249 p_info->drv_mb_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_mb_header) &
250 DRV_MSG_SEQ_NUMBER_MASK;
252 /* Get current FW pulse sequence */
253 p_info->drv_pulse_seq = DRV_MB_RD(p_hwfn, p_ptt, drv_pulse_mb) &
256 p_info->mcp_hist = qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
261 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
263 struct qed_mcp_info *p_info;
266 /* Allocate mcp_info structure */
267 p_hwfn->mcp_info = kzalloc(sizeof(*p_hwfn->mcp_info), GFP_KERNEL);
268 if (!p_hwfn->mcp_info)
270 p_info = p_hwfn->mcp_info;
272 /* Initialize the MFW spinlock */
273 spin_lock_init(&p_info->cmd_lock);
274 spin_lock_init(&p_info->link_lock);
276 INIT_LIST_HEAD(&p_info->cmd_list);
278 if (qed_load_mcp_offsets(p_hwfn, p_ptt) != 0) {
279 DP_NOTICE(p_hwfn, "MCP is not initialized\n");
280 /* Do not free mcp_info here, since public_base indicate that
281 * the MCP is not initialized
286 size = MFW_DRV_MSG_MAX_DWORDS(p_info->mfw_mb_length) * sizeof(u32);
287 p_info->mfw_mb_cur = kzalloc(size, GFP_KERNEL);
288 p_info->mfw_mb_shadow = kzalloc(size, GFP_KERNEL);
289 if (!p_info->mfw_mb_cur || !p_info->mfw_mb_shadow)
295 qed_mcp_free(p_hwfn);
299 static void qed_mcp_reread_offsets(struct qed_hwfn *p_hwfn,
300 struct qed_ptt *p_ptt)
302 u32 generic_por_0 = qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
304 /* Use MCP history register to check if MCP reset occurred between init
307 if (p_hwfn->mcp_info->mcp_hist != generic_por_0) {
310 "Rereading MCP offsets [mcp_hist 0x%08x, generic_por_0 0x%08x]\n",
311 p_hwfn->mcp_info->mcp_hist, generic_por_0);
313 qed_load_mcp_offsets(p_hwfn, p_ptt);
314 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
318 int qed_mcp_reset(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
320 u32 org_mcp_reset_seq, seq, delay = QED_MCP_RESP_ITER_US, cnt = 0;
323 if (p_hwfn->mcp_info->b_block_cmd) {
325 "The MFW is not responsive. Avoid sending MCP_RESET mailbox command.\n");
329 /* Ensure that only a single thread is accessing the mailbox */
330 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
332 org_mcp_reset_seq = qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0);
334 /* Set drv command along with the updated sequence */
335 qed_mcp_reread_offsets(p_hwfn, p_ptt);
336 seq = ++p_hwfn->mcp_info->drv_mb_seq;
337 DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (DRV_MSG_CODE_MCP_RESET | seq));
340 /* Wait for MFW response */
342 /* Give the FW up to 500 second (50*1000*10usec) */
343 } while ((org_mcp_reset_seq == qed_rd(p_hwfn, p_ptt,
344 MISCS_REG_GENERIC_POR_0)) &&
345 (cnt++ < QED_MCP_RESET_RETRIES));
347 if (org_mcp_reset_seq !=
348 qed_rd(p_hwfn, p_ptt, MISCS_REG_GENERIC_POR_0)) {
349 DP_VERBOSE(p_hwfn, QED_MSG_SP,
350 "MCP was reset after %d usec\n", cnt * delay);
352 DP_ERR(p_hwfn, "Failed to reset MCP\n");
356 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
361 /* Must be called while cmd_lock is acquired */
362 static bool qed_mcp_has_pending_cmd(struct qed_hwfn *p_hwfn)
364 struct qed_mcp_cmd_elem *p_cmd_elem;
366 /* There is at most one pending command at a certain time, and if it
367 * exists - it is placed at the HEAD of the list.
369 if (!list_empty(&p_hwfn->mcp_info->cmd_list)) {
370 p_cmd_elem = list_first_entry(&p_hwfn->mcp_info->cmd_list,
371 struct qed_mcp_cmd_elem, list);
372 return !p_cmd_elem->b_is_completed;
378 /* Must be called while cmd_lock is acquired */
380 qed_mcp_update_pending_cmd(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
382 struct qed_mcp_mb_params *p_mb_params;
383 struct qed_mcp_cmd_elem *p_cmd_elem;
387 mcp_resp = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_header);
388 seq_num = (u16)(mcp_resp & FW_MSG_SEQ_NUMBER_MASK);
390 /* Return if no new non-handled response has been received */
391 if (seq_num != p_hwfn->mcp_info->drv_mb_seq)
394 p_cmd_elem = qed_mcp_cmd_get_elem(p_hwfn, seq_num);
397 "Failed to find a pending mailbox cmd that expects sequence number %d\n",
402 p_mb_params = p_cmd_elem->p_mb_params;
404 /* Get the MFW response along with the sequence number */
405 p_mb_params->mcp_resp = mcp_resp;
407 /* Get the MFW param */
408 p_mb_params->mcp_param = DRV_MB_RD(p_hwfn, p_ptt, fw_mb_param);
410 /* Get the union data */
411 if (p_mb_params->p_data_dst != NULL && p_mb_params->data_dst_size) {
412 u32 union_data_addr = p_hwfn->mcp_info->drv_mb_addr +
413 offsetof(struct public_drv_mb,
415 qed_memcpy_from(p_hwfn, p_ptt, p_mb_params->p_data_dst,
416 union_data_addr, p_mb_params->data_dst_size);
419 p_cmd_elem->b_is_completed = true;
424 /* Must be called while cmd_lock is acquired */
425 static void __qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
426 struct qed_ptt *p_ptt,
427 struct qed_mcp_mb_params *p_mb_params,
430 union drv_union_data union_data;
433 /* Set the union data */
434 union_data_addr = p_hwfn->mcp_info->drv_mb_addr +
435 offsetof(struct public_drv_mb, union_data);
436 memset(&union_data, 0, sizeof(union_data));
437 if (p_mb_params->p_data_src != NULL && p_mb_params->data_src_size)
438 memcpy(&union_data, p_mb_params->p_data_src,
439 p_mb_params->data_src_size);
440 qed_memcpy_to(p_hwfn, p_ptt, union_data_addr, &union_data,
443 /* Set the drv param */
444 DRV_MB_WR(p_hwfn, p_ptt, drv_mb_param, p_mb_params->param);
446 /* Set the drv command along with the sequence number */
447 DRV_MB_WR(p_hwfn, p_ptt, drv_mb_header, (p_mb_params->cmd | seq_num));
449 DP_VERBOSE(p_hwfn, QED_MSG_SP,
450 "MFW mailbox: command 0x%08x param 0x%08x\n",
451 (p_mb_params->cmd | seq_num), p_mb_params->param);
454 static void qed_mcp_cmd_set_blocking(struct qed_hwfn *p_hwfn, bool block_cmd)
456 p_hwfn->mcp_info->b_block_cmd = block_cmd;
458 DP_INFO(p_hwfn, "%s sending of mailbox commands to the MFW\n",
459 block_cmd ? "Block" : "Unblock");
462 static void qed_mcp_print_cpu_info(struct qed_hwfn *p_hwfn,
463 struct qed_ptt *p_ptt)
465 u32 cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2;
466 u32 delay = QED_MCP_RESP_ITER_US;
468 cpu_mode = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
469 cpu_state = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
470 cpu_pc_0 = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
472 cpu_pc_1 = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
474 cpu_pc_2 = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_PROGRAM_COUNTER);
477 "MCP CPU info: mode 0x%08x, state 0x%08x, pc {0x%08x, 0x%08x, 0x%08x}\n",
478 cpu_mode, cpu_state, cpu_pc_0, cpu_pc_1, cpu_pc_2);
482 _qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
483 struct qed_ptt *p_ptt,
484 struct qed_mcp_mb_params *p_mb_params,
485 u32 max_retries, u32 usecs)
487 u32 cnt = 0, msecs = DIV_ROUND_UP(usecs, 1000);
488 struct qed_mcp_cmd_elem *p_cmd_elem;
492 /* Wait until the mailbox is non-occupied */
494 /* Exit the loop if there is no pending command, or if the
495 * pending command is completed during this iteration.
496 * The spinlock stays locked until the command is sent.
499 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
501 if (!qed_mcp_has_pending_cmd(p_hwfn)) {
502 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
506 rc = qed_mcp_update_pending_cmd(p_hwfn, p_ptt);
508 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
510 } else if (rc != -EAGAIN) {
514 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
516 if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP))
520 } while (++cnt < max_retries);
522 if (cnt >= max_retries) {
524 "The MFW mailbox is occupied by an uncompleted command. Failed to send command 0x%08x [param 0x%08x].\n",
525 p_mb_params->cmd, p_mb_params->param);
529 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
531 /* Send the mailbox command */
532 qed_mcp_reread_offsets(p_hwfn, p_ptt);
533 seq_num = ++p_hwfn->mcp_info->drv_mb_seq;
534 p_cmd_elem = qed_mcp_cmd_add_elem(p_hwfn, p_mb_params, seq_num);
540 __qed_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, seq_num);
541 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
543 /* Wait for the MFW response */
545 /* Exit the loop if the command is already completed, or if the
546 * command is completed during this iteration.
547 * The spinlock stays locked until the list element is removed.
550 if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP))
555 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
557 if (p_cmd_elem->b_is_completed) {
558 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
562 rc = qed_mcp_update_pending_cmd(p_hwfn, p_ptt);
564 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
566 } else if (rc != -EAGAIN) {
570 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
571 } while (++cnt < max_retries);
573 if (cnt >= max_retries) {
575 "The MFW failed to respond to command 0x%08x [param 0x%08x].\n",
576 p_mb_params->cmd, p_mb_params->param);
577 qed_mcp_print_cpu_info(p_hwfn, p_ptt);
579 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
580 qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
581 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
583 if (!QED_MB_FLAGS_IS_SET(p_mb_params, AVOID_BLOCK))
584 qed_mcp_cmd_set_blocking(p_hwfn, true);
589 spin_lock_bh(&p_hwfn->mcp_info->cmd_lock);
590 qed_mcp_cmd_del_elem(p_hwfn, p_cmd_elem);
591 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
595 "MFW mailbox: response 0x%08x param 0x%08x [after %d.%03d ms]\n",
596 p_mb_params->mcp_resp,
597 p_mb_params->mcp_param,
598 (cnt * usecs) / 1000, (cnt * usecs) % 1000);
600 /* Clear the sequence number from the MFW response */
601 p_mb_params->mcp_resp &= FW_MSG_CODE_MASK;
606 spin_unlock_bh(&p_hwfn->mcp_info->cmd_lock);
610 static int qed_mcp_cmd_and_union(struct qed_hwfn *p_hwfn,
611 struct qed_ptt *p_ptt,
612 struct qed_mcp_mb_params *p_mb_params)
614 size_t union_data_size = sizeof(union drv_union_data);
615 u32 max_retries = QED_DRV_MB_MAX_RETRIES;
616 u32 usecs = QED_MCP_RESP_ITER_US;
618 /* MCP not initialized */
619 if (!qed_mcp_is_init(p_hwfn)) {
620 DP_NOTICE(p_hwfn, "MFW is not initialized!\n");
624 if (p_hwfn->mcp_info->b_block_cmd) {
626 "The MFW is not responsive. Avoid sending mailbox command 0x%08x [param 0x%08x].\n",
627 p_mb_params->cmd, p_mb_params->param);
631 if (p_mb_params->data_src_size > union_data_size ||
632 p_mb_params->data_dst_size > union_data_size) {
634 "The provided size is larger than the union data size [src_size %u, dst_size %u, union_data_size %zu]\n",
635 p_mb_params->data_src_size,
636 p_mb_params->data_dst_size, union_data_size);
640 if (QED_MB_FLAGS_IS_SET(p_mb_params, CAN_SLEEP)) {
641 max_retries = DIV_ROUND_UP(max_retries, 1000);
645 return _qed_mcp_cmd_and_union(p_hwfn, p_ptt, p_mb_params, max_retries,
649 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
650 struct qed_ptt *p_ptt,
656 struct qed_mcp_mb_params mb_params;
659 memset(&mb_params, 0, sizeof(mb_params));
661 mb_params.param = param;
663 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
667 *o_mcp_resp = mb_params.mcp_resp;
668 *o_mcp_param = mb_params.mcp_param;
674 qed_mcp_nvm_wr_cmd(struct qed_hwfn *p_hwfn,
675 struct qed_ptt *p_ptt,
679 u32 *o_mcp_param, u32 i_txn_size, u32 *i_buf)
681 struct qed_mcp_mb_params mb_params;
684 memset(&mb_params, 0, sizeof(mb_params));
686 mb_params.param = param;
687 mb_params.p_data_src = i_buf;
688 mb_params.data_src_size = (u8)i_txn_size;
689 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
693 *o_mcp_resp = mb_params.mcp_resp;
694 *o_mcp_param = mb_params.mcp_param;
696 /* nvm_info needs to be updated */
697 p_hwfn->nvm_info.valid = false;
702 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
703 struct qed_ptt *p_ptt,
707 u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf)
709 struct qed_mcp_mb_params mb_params;
710 u8 raw_data[MCP_DRV_NVM_BUF_LEN];
713 memset(&mb_params, 0, sizeof(mb_params));
715 mb_params.param = param;
716 mb_params.p_data_dst = raw_data;
718 /* Use the maximal value since the actual one is part of the response */
719 mb_params.data_dst_size = MCP_DRV_NVM_BUF_LEN;
721 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
725 *o_mcp_resp = mb_params.mcp_resp;
726 *o_mcp_param = mb_params.mcp_param;
728 *o_txn_size = *o_mcp_param;
729 memcpy(o_buf, raw_data, *o_txn_size);
735 qed_mcp_can_force_load(u8 drv_role,
737 enum qed_override_force_load override_force_load)
739 bool can_force_load = false;
741 switch (override_force_load) {
742 case QED_OVERRIDE_FORCE_LOAD_ALWAYS:
743 can_force_load = true;
745 case QED_OVERRIDE_FORCE_LOAD_NEVER:
746 can_force_load = false;
749 can_force_load = (drv_role == DRV_ROLE_OS &&
750 exist_drv_role == DRV_ROLE_PREBOOT) ||
751 (drv_role == DRV_ROLE_KDUMP &&
752 exist_drv_role == DRV_ROLE_OS);
756 return can_force_load;
759 static int qed_mcp_cancel_load_req(struct qed_hwfn *p_hwfn,
760 struct qed_ptt *p_ptt)
762 u32 resp = 0, param = 0;
765 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CANCEL_LOAD_REQ, 0,
769 "Failed to send cancel load request, rc = %d\n", rc);
774 #define CONFIG_QEDE_BITMAP_IDX BIT(0)
775 #define CONFIG_QED_SRIOV_BITMAP_IDX BIT(1)
776 #define CONFIG_QEDR_BITMAP_IDX BIT(2)
777 #define CONFIG_QEDF_BITMAP_IDX BIT(4)
778 #define CONFIG_QEDI_BITMAP_IDX BIT(5)
779 #define CONFIG_QED_LL2_BITMAP_IDX BIT(6)
781 static u32 qed_get_config_bitmap(void)
783 u32 config_bitmap = 0x0;
785 if (IS_ENABLED(CONFIG_QEDE))
786 config_bitmap |= CONFIG_QEDE_BITMAP_IDX;
788 if (IS_ENABLED(CONFIG_QED_SRIOV))
789 config_bitmap |= CONFIG_QED_SRIOV_BITMAP_IDX;
791 if (IS_ENABLED(CONFIG_QED_RDMA))
792 config_bitmap |= CONFIG_QEDR_BITMAP_IDX;
794 if (IS_ENABLED(CONFIG_QED_FCOE))
795 config_bitmap |= CONFIG_QEDF_BITMAP_IDX;
797 if (IS_ENABLED(CONFIG_QED_ISCSI))
798 config_bitmap |= CONFIG_QEDI_BITMAP_IDX;
800 if (IS_ENABLED(CONFIG_QED_LL2))
801 config_bitmap |= CONFIG_QED_LL2_BITMAP_IDX;
803 return config_bitmap;
806 struct qed_load_req_in_params {
808 #define QED_LOAD_REQ_HSI_VER_DEFAULT 0
809 #define QED_LOAD_REQ_HSI_VER_1 1
816 bool avoid_eng_reset;
819 struct qed_load_req_out_params {
830 __qed_mcp_load_req(struct qed_hwfn *p_hwfn,
831 struct qed_ptt *p_ptt,
832 struct qed_load_req_in_params *p_in_params,
833 struct qed_load_req_out_params *p_out_params)
835 struct qed_mcp_mb_params mb_params;
836 struct load_req_stc load_req;
837 struct load_rsp_stc load_rsp;
841 memset(&load_req, 0, sizeof(load_req));
842 load_req.drv_ver_0 = p_in_params->drv_ver_0;
843 load_req.drv_ver_1 = p_in_params->drv_ver_1;
844 load_req.fw_ver = p_in_params->fw_ver;
845 QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_ROLE, p_in_params->drv_role);
846 QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_LOCK_TO,
847 p_in_params->timeout_val);
848 QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_FORCE,
849 p_in_params->force_cmd);
850 QED_MFW_SET_FIELD(load_req.misc0, LOAD_REQ_FLAGS0,
851 p_in_params->avoid_eng_reset);
853 hsi_ver = (p_in_params->hsi_ver == QED_LOAD_REQ_HSI_VER_DEFAULT) ?
854 DRV_ID_MCP_HSI_VER_CURRENT :
855 (p_in_params->hsi_ver << DRV_ID_MCP_HSI_VER_SHIFT);
857 memset(&mb_params, 0, sizeof(mb_params));
858 mb_params.cmd = DRV_MSG_CODE_LOAD_REQ;
859 mb_params.param = PDA_COMP | hsi_ver | p_hwfn->cdev->drv_type;
860 mb_params.p_data_src = &load_req;
861 mb_params.data_src_size = sizeof(load_req);
862 mb_params.p_data_dst = &load_rsp;
863 mb_params.data_dst_size = sizeof(load_rsp);
864 mb_params.flags = QED_MB_FLAG_CAN_SLEEP | QED_MB_FLAG_AVOID_BLOCK;
866 DP_VERBOSE(p_hwfn, QED_MSG_SP,
867 "Load Request: param 0x%08x [init_hw %d, drv_type %d, hsi_ver %d, pda 0x%04x]\n",
869 QED_MFW_GET_FIELD(mb_params.param, DRV_ID_DRV_INIT_HW),
870 QED_MFW_GET_FIELD(mb_params.param, DRV_ID_DRV_TYPE),
871 QED_MFW_GET_FIELD(mb_params.param, DRV_ID_MCP_HSI_VER),
872 QED_MFW_GET_FIELD(mb_params.param, DRV_ID_PDA_COMP_VER));
874 if (p_in_params->hsi_ver != QED_LOAD_REQ_HSI_VER_1) {
875 DP_VERBOSE(p_hwfn, QED_MSG_SP,
876 "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",
881 QED_MFW_GET_FIELD(load_req.misc0, LOAD_REQ_ROLE),
882 QED_MFW_GET_FIELD(load_req.misc0,
884 QED_MFW_GET_FIELD(load_req.misc0, LOAD_REQ_FORCE),
885 QED_MFW_GET_FIELD(load_req.misc0, LOAD_REQ_FLAGS0));
888 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
890 DP_NOTICE(p_hwfn, "Failed to send load request, rc = %d\n", rc);
894 DP_VERBOSE(p_hwfn, QED_MSG_SP,
895 "Load Response: resp 0x%08x\n", mb_params.mcp_resp);
896 p_out_params->load_code = mb_params.mcp_resp;
898 if (p_in_params->hsi_ver != QED_LOAD_REQ_HSI_VER_1 &&
899 p_out_params->load_code != FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) {
902 "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",
907 QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_ROLE),
908 QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_HSI),
909 QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0));
911 p_out_params->exist_drv_ver_0 = load_rsp.drv_ver_0;
912 p_out_params->exist_drv_ver_1 = load_rsp.drv_ver_1;
913 p_out_params->exist_fw_ver = load_rsp.fw_ver;
914 p_out_params->exist_drv_role =
915 QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_ROLE);
916 p_out_params->mfw_hsi_ver =
917 QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_HSI);
918 p_out_params->drv_exists =
919 QED_MFW_GET_FIELD(load_rsp.misc0, LOAD_RSP_FLAGS0) &
920 LOAD_RSP_FLAGS0_DRV_EXISTS;
926 static int eocre_get_mfw_drv_role(struct qed_hwfn *p_hwfn,
927 enum qed_drv_role drv_role,
931 case QED_DRV_ROLE_OS:
932 *p_mfw_drv_role = DRV_ROLE_OS;
934 case QED_DRV_ROLE_KDUMP:
935 *p_mfw_drv_role = DRV_ROLE_KDUMP;
938 DP_ERR(p_hwfn, "Unexpected driver role %d\n", drv_role);
945 enum qed_load_req_force {
946 QED_LOAD_REQ_FORCE_NONE,
947 QED_LOAD_REQ_FORCE_PF,
948 QED_LOAD_REQ_FORCE_ALL,
951 static void qed_get_mfw_force_cmd(struct qed_hwfn *p_hwfn,
953 enum qed_load_req_force force_cmd,
957 case QED_LOAD_REQ_FORCE_NONE:
958 *p_mfw_force_cmd = LOAD_REQ_FORCE_NONE;
960 case QED_LOAD_REQ_FORCE_PF:
961 *p_mfw_force_cmd = LOAD_REQ_FORCE_PF;
963 case QED_LOAD_REQ_FORCE_ALL:
964 *p_mfw_force_cmd = LOAD_REQ_FORCE_ALL;
969 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
970 struct qed_ptt *p_ptt,
971 struct qed_load_req_params *p_params)
973 struct qed_load_req_out_params out_params;
974 struct qed_load_req_in_params in_params;
975 u8 mfw_drv_role, mfw_force_cmd;
978 memset(&in_params, 0, sizeof(in_params));
979 in_params.hsi_ver = QED_LOAD_REQ_HSI_VER_DEFAULT;
980 in_params.drv_ver_0 = QED_VERSION;
981 in_params.drv_ver_1 = qed_get_config_bitmap();
982 in_params.fw_ver = STORM_FW_VERSION;
983 rc = eocre_get_mfw_drv_role(p_hwfn, p_params->drv_role, &mfw_drv_role);
987 in_params.drv_role = mfw_drv_role;
988 in_params.timeout_val = p_params->timeout_val;
989 qed_get_mfw_force_cmd(p_hwfn,
990 QED_LOAD_REQ_FORCE_NONE, &mfw_force_cmd);
992 in_params.force_cmd = mfw_force_cmd;
993 in_params.avoid_eng_reset = p_params->avoid_eng_reset;
995 memset(&out_params, 0, sizeof(out_params));
996 rc = __qed_mcp_load_req(p_hwfn, p_ptt, &in_params, &out_params);
1000 /* First handle cases where another load request should/might be sent:
1001 * - MFW expects the old interface [HSI version = 1]
1002 * - MFW responds that a force load request is required
1004 if (out_params.load_code == FW_MSG_CODE_DRV_LOAD_REFUSED_HSI_1) {
1006 "MFW refused a load request due to HSI > 1. Resending with HSI = 1\n");
1008 in_params.hsi_ver = QED_LOAD_REQ_HSI_VER_1;
1009 memset(&out_params, 0, sizeof(out_params));
1010 rc = __qed_mcp_load_req(p_hwfn, p_ptt, &in_params, &out_params);
1013 } else if (out_params.load_code ==
1014 FW_MSG_CODE_DRV_LOAD_REFUSED_REQUIRES_FORCE) {
1015 if (qed_mcp_can_force_load(in_params.drv_role,
1016 out_params.exist_drv_role,
1017 p_params->override_force_load)) {
1019 "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}]\n",
1020 in_params.drv_role, in_params.fw_ver,
1021 in_params.drv_ver_0, in_params.drv_ver_1,
1022 out_params.exist_drv_role,
1023 out_params.exist_fw_ver,
1024 out_params.exist_drv_ver_0,
1025 out_params.exist_drv_ver_1);
1027 qed_get_mfw_force_cmd(p_hwfn,
1028 QED_LOAD_REQ_FORCE_ALL,
1031 in_params.force_cmd = mfw_force_cmd;
1032 memset(&out_params, 0, sizeof(out_params));
1033 rc = __qed_mcp_load_req(p_hwfn, p_ptt, &in_params,
1039 "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",
1040 in_params.drv_role, in_params.fw_ver,
1041 in_params.drv_ver_0, in_params.drv_ver_1,
1042 out_params.exist_drv_role,
1043 out_params.exist_fw_ver,
1044 out_params.exist_drv_ver_0,
1045 out_params.exist_drv_ver_1);
1047 "Avoid sending a force load request to prevent disruption of active PFs\n");
1049 qed_mcp_cancel_load_req(p_hwfn, p_ptt);
1054 /* Now handle the other types of responses.
1055 * The "REFUSED_HSI_1" and "REFUSED_REQUIRES_FORCE" responses are not
1056 * expected here after the additional revised load requests were sent.
1058 switch (out_params.load_code) {
1059 case FW_MSG_CODE_DRV_LOAD_ENGINE:
1060 case FW_MSG_CODE_DRV_LOAD_PORT:
1061 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
1062 if (out_params.mfw_hsi_ver != QED_LOAD_REQ_HSI_VER_1 &&
1063 out_params.drv_exists) {
1064 /* The role and fw/driver version match, but the PF is
1065 * already loaded and has not been unloaded gracefully.
1068 "PF is already loaded\n");
1074 "Unexpected refusal to load request [resp 0x%08x]. Aborting.\n",
1075 out_params.load_code);
1079 p_params->load_code = out_params.load_code;
1084 int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1086 struct qed_mcp_mb_params mb_params;
1089 switch (p_hwfn->cdev->wol_config) {
1090 case QED_OV_WOL_DISABLED:
1091 wol_param = DRV_MB_PARAM_UNLOAD_WOL_DISABLED;
1093 case QED_OV_WOL_ENABLED:
1094 wol_param = DRV_MB_PARAM_UNLOAD_WOL_ENABLED;
1098 "Unknown WoL configuration %02x\n",
1099 p_hwfn->cdev->wol_config);
1101 case QED_OV_WOL_DEFAULT:
1102 wol_param = DRV_MB_PARAM_UNLOAD_WOL_MCP;
1105 memset(&mb_params, 0, sizeof(mb_params));
1106 mb_params.cmd = DRV_MSG_CODE_UNLOAD_REQ;
1107 mb_params.param = wol_param;
1108 mb_params.flags = QED_MB_FLAG_CAN_SLEEP | QED_MB_FLAG_AVOID_BLOCK;
1110 return qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1113 int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1115 struct qed_mcp_mb_params mb_params;
1116 struct mcp_mac wol_mac;
1118 memset(&mb_params, 0, sizeof(mb_params));
1119 mb_params.cmd = DRV_MSG_CODE_UNLOAD_DONE;
1121 /* Set the primary MAC if WoL is enabled */
1122 if (p_hwfn->cdev->wol_config == QED_OV_WOL_ENABLED) {
1123 u8 *p_mac = p_hwfn->cdev->wol_mac;
1125 memset(&wol_mac, 0, sizeof(wol_mac));
1126 wol_mac.mac_upper = p_mac[0] << 8 | p_mac[1];
1127 wol_mac.mac_lower = p_mac[2] << 24 | p_mac[3] << 16 |
1128 p_mac[4] << 8 | p_mac[5];
1131 (QED_MSG_SP | NETIF_MSG_IFDOWN),
1132 "Setting WoL MAC: %pM --> [%08x,%08x]\n",
1133 p_mac, wol_mac.mac_upper, wol_mac.mac_lower);
1135 mb_params.p_data_src = &wol_mac;
1136 mb_params.data_src_size = sizeof(wol_mac);
1139 return qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1142 static void qed_mcp_handle_vf_flr(struct qed_hwfn *p_hwfn,
1143 struct qed_ptt *p_ptt)
1145 u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1147 u32 mfw_path_offsize = qed_rd(p_hwfn, p_ptt, addr);
1148 u32 path_addr = SECTION_ADDR(mfw_path_offsize,
1149 QED_PATH_ID(p_hwfn));
1150 u32 disabled_vfs[VF_MAX_STATIC / 32];
1155 "Reading Disabled VF information from [offset %08x], path_addr %08x\n",
1156 mfw_path_offsize, path_addr);
1158 for (i = 0; i < (VF_MAX_STATIC / 32); i++) {
1159 disabled_vfs[i] = qed_rd(p_hwfn, p_ptt,
1161 offsetof(struct public_path,
1164 DP_VERBOSE(p_hwfn, (QED_MSG_SP | QED_MSG_IOV),
1165 "FLR-ed VFs [%08x,...,%08x] - %08x\n",
1166 i * 32, (i + 1) * 32 - 1, disabled_vfs[i]);
1169 if (qed_iov_mark_vf_flr(p_hwfn, disabled_vfs))
1170 qed_schedule_iov(p_hwfn, QED_IOV_WQ_FLR_FLAG);
1173 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
1174 struct qed_ptt *p_ptt, u32 *vfs_to_ack)
1176 u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1178 u32 mfw_func_offsize = qed_rd(p_hwfn, p_ptt, addr);
1179 u32 func_addr = SECTION_ADDR(mfw_func_offsize,
1181 struct qed_mcp_mb_params mb_params;
1185 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
1186 DP_VERBOSE(p_hwfn, (QED_MSG_SP | QED_MSG_IOV),
1187 "Acking VFs [%08x,...,%08x] - %08x\n",
1188 i * 32, (i + 1) * 32 - 1, vfs_to_ack[i]);
1190 memset(&mb_params, 0, sizeof(mb_params));
1191 mb_params.cmd = DRV_MSG_CODE_VF_DISABLED_DONE;
1192 mb_params.p_data_src = vfs_to_ack;
1193 mb_params.data_src_size = VF_MAX_STATIC / 8;
1194 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1196 DP_NOTICE(p_hwfn, "Failed to pass ACK for VF flr to MFW\n");
1200 /* Clear the ACK bits */
1201 for (i = 0; i < (VF_MAX_STATIC / 32); i++)
1202 qed_wr(p_hwfn, p_ptt,
1204 offsetof(struct public_func, drv_ack_vf_disabled) +
1205 i * sizeof(u32), 0);
1210 static void qed_mcp_handle_transceiver_change(struct qed_hwfn *p_hwfn,
1211 struct qed_ptt *p_ptt)
1213 u32 transceiver_state;
1215 transceiver_state = qed_rd(p_hwfn, p_ptt,
1216 p_hwfn->mcp_info->port_addr +
1217 offsetof(struct public_port,
1221 (NETIF_MSG_HW | QED_MSG_SP),
1222 "Received transceiver state update [0x%08x] from mfw [Addr 0x%x]\n",
1224 (u32)(p_hwfn->mcp_info->port_addr +
1225 offsetof(struct public_port, transceiver_data)));
1227 transceiver_state = GET_FIELD(transceiver_state,
1228 ETH_TRANSCEIVER_STATE);
1230 if (transceiver_state == ETH_TRANSCEIVER_STATE_PRESENT)
1231 DP_NOTICE(p_hwfn, "Transceiver is present.\n");
1233 DP_NOTICE(p_hwfn, "Transceiver is unplugged.\n");
1236 static void qed_mcp_read_eee_config(struct qed_hwfn *p_hwfn,
1237 struct qed_ptt *p_ptt,
1238 struct qed_mcp_link_state *p_link)
1240 u32 eee_status, val;
1242 p_link->eee_adv_caps = 0;
1243 p_link->eee_lp_adv_caps = 0;
1244 eee_status = qed_rd(p_hwfn,
1246 p_hwfn->mcp_info->port_addr +
1247 offsetof(struct public_port, eee_status));
1248 p_link->eee_active = !!(eee_status & EEE_ACTIVE_BIT);
1249 val = (eee_status & EEE_LD_ADV_STATUS_MASK) >> EEE_LD_ADV_STATUS_OFFSET;
1250 if (val & EEE_1G_ADV)
1251 p_link->eee_adv_caps |= QED_EEE_1G_ADV;
1252 if (val & EEE_10G_ADV)
1253 p_link->eee_adv_caps |= QED_EEE_10G_ADV;
1254 val = (eee_status & EEE_LP_ADV_STATUS_MASK) >> EEE_LP_ADV_STATUS_OFFSET;
1255 if (val & EEE_1G_ADV)
1256 p_link->eee_lp_adv_caps |= QED_EEE_1G_ADV;
1257 if (val & EEE_10G_ADV)
1258 p_link->eee_lp_adv_caps |= QED_EEE_10G_ADV;
1261 static void qed_mcp_handle_link_change(struct qed_hwfn *p_hwfn,
1262 struct qed_ptt *p_ptt, bool b_reset)
1264 struct qed_mcp_link_state *p_link;
1268 /* Prevent SW/attentions from doing this at the same time */
1269 spin_lock_bh(&p_hwfn->mcp_info->link_lock);
1271 p_link = &p_hwfn->mcp_info->link_output;
1272 memset(p_link, 0, sizeof(*p_link));
1274 status = qed_rd(p_hwfn, p_ptt,
1275 p_hwfn->mcp_info->port_addr +
1276 offsetof(struct public_port, link_status));
1277 DP_VERBOSE(p_hwfn, (NETIF_MSG_LINK | QED_MSG_SP),
1278 "Received link update [0x%08x] from mfw [Addr 0x%x]\n",
1280 (u32)(p_hwfn->mcp_info->port_addr +
1281 offsetof(struct public_port, link_status)));
1283 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1284 "Resetting link indications\n");
1288 if (p_hwfn->b_drv_link_init)
1289 p_link->link_up = !!(status & LINK_STATUS_LINK_UP);
1291 p_link->link_up = false;
1293 p_link->full_duplex = true;
1294 switch ((status & LINK_STATUS_SPEED_AND_DUPLEX_MASK)) {
1295 case LINK_STATUS_SPEED_AND_DUPLEX_100G:
1296 p_link->speed = 100000;
1298 case LINK_STATUS_SPEED_AND_DUPLEX_50G:
1299 p_link->speed = 50000;
1301 case LINK_STATUS_SPEED_AND_DUPLEX_40G:
1302 p_link->speed = 40000;
1304 case LINK_STATUS_SPEED_AND_DUPLEX_25G:
1305 p_link->speed = 25000;
1307 case LINK_STATUS_SPEED_AND_DUPLEX_20G:
1308 p_link->speed = 20000;
1310 case LINK_STATUS_SPEED_AND_DUPLEX_10G:
1311 p_link->speed = 10000;
1313 case LINK_STATUS_SPEED_AND_DUPLEX_1000THD:
1314 p_link->full_duplex = false;
1316 case LINK_STATUS_SPEED_AND_DUPLEX_1000TFD:
1317 p_link->speed = 1000;
1321 p_link->link_up = 0;
1324 if (p_link->link_up && p_link->speed)
1325 p_link->line_speed = p_link->speed;
1327 p_link->line_speed = 0;
1329 max_bw = p_hwfn->mcp_info->func_info.bandwidth_max;
1330 min_bw = p_hwfn->mcp_info->func_info.bandwidth_min;
1332 /* Max bandwidth configuration */
1333 __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt, p_link, max_bw);
1335 /* Min bandwidth configuration */
1336 __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt, p_link, min_bw);
1337 qed_configure_vp_wfq_on_link_change(p_hwfn->cdev, p_ptt,
1338 p_link->min_pf_rate);
1340 p_link->an = !!(status & LINK_STATUS_AUTO_NEGOTIATE_ENABLED);
1341 p_link->an_complete = !!(status &
1342 LINK_STATUS_AUTO_NEGOTIATE_COMPLETE);
1343 p_link->parallel_detection = !!(status &
1344 LINK_STATUS_PARALLEL_DETECTION_USED);
1345 p_link->pfc_enabled = !!(status & LINK_STATUS_PFC_ENABLED);
1347 p_link->partner_adv_speed |=
1348 (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE) ?
1349 QED_LINK_PARTNER_SPEED_1G_FD : 0;
1350 p_link->partner_adv_speed |=
1351 (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE) ?
1352 QED_LINK_PARTNER_SPEED_1G_HD : 0;
1353 p_link->partner_adv_speed |=
1354 (status & LINK_STATUS_LINK_PARTNER_10G_CAPABLE) ?
1355 QED_LINK_PARTNER_SPEED_10G : 0;
1356 p_link->partner_adv_speed |=
1357 (status & LINK_STATUS_LINK_PARTNER_20G_CAPABLE) ?
1358 QED_LINK_PARTNER_SPEED_20G : 0;
1359 p_link->partner_adv_speed |=
1360 (status & LINK_STATUS_LINK_PARTNER_25G_CAPABLE) ?
1361 QED_LINK_PARTNER_SPEED_25G : 0;
1362 p_link->partner_adv_speed |=
1363 (status & LINK_STATUS_LINK_PARTNER_40G_CAPABLE) ?
1364 QED_LINK_PARTNER_SPEED_40G : 0;
1365 p_link->partner_adv_speed |=
1366 (status & LINK_STATUS_LINK_PARTNER_50G_CAPABLE) ?
1367 QED_LINK_PARTNER_SPEED_50G : 0;
1368 p_link->partner_adv_speed |=
1369 (status & LINK_STATUS_LINK_PARTNER_100G_CAPABLE) ?
1370 QED_LINK_PARTNER_SPEED_100G : 0;
1372 p_link->partner_tx_flow_ctrl_en =
1373 !!(status & LINK_STATUS_TX_FLOW_CONTROL_ENABLED);
1374 p_link->partner_rx_flow_ctrl_en =
1375 !!(status & LINK_STATUS_RX_FLOW_CONTROL_ENABLED);
1377 switch (status & LINK_STATUS_LINK_PARTNER_FLOW_CONTROL_MASK) {
1378 case LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE:
1379 p_link->partner_adv_pause = QED_LINK_PARTNER_SYMMETRIC_PAUSE;
1381 case LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE:
1382 p_link->partner_adv_pause = QED_LINK_PARTNER_ASYMMETRIC_PAUSE;
1384 case LINK_STATUS_LINK_PARTNER_BOTH_PAUSE:
1385 p_link->partner_adv_pause = QED_LINK_PARTNER_BOTH_PAUSE;
1388 p_link->partner_adv_pause = 0;
1391 p_link->sfp_tx_fault = !!(status & LINK_STATUS_SFP_TX_FAULT);
1393 if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE)
1394 qed_mcp_read_eee_config(p_hwfn, p_ptt, p_link);
1396 qed_link_update(p_hwfn, p_ptt);
1398 spin_unlock_bh(&p_hwfn->mcp_info->link_lock);
1401 int qed_mcp_set_link(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, bool b_up)
1403 struct qed_mcp_link_params *params = &p_hwfn->mcp_info->link_input;
1404 struct qed_mcp_mb_params mb_params;
1405 struct eth_phy_cfg phy_cfg;
1409 /* Set the shmem configuration according to params */
1410 memset(&phy_cfg, 0, sizeof(phy_cfg));
1411 cmd = b_up ? DRV_MSG_CODE_INIT_PHY : DRV_MSG_CODE_LINK_RESET;
1412 if (!params->speed.autoneg)
1413 phy_cfg.speed = params->speed.forced_speed;
1414 phy_cfg.pause |= (params->pause.autoneg) ? ETH_PAUSE_AUTONEG : 0;
1415 phy_cfg.pause |= (params->pause.forced_rx) ? ETH_PAUSE_RX : 0;
1416 phy_cfg.pause |= (params->pause.forced_tx) ? ETH_PAUSE_TX : 0;
1417 phy_cfg.adv_speed = params->speed.advertised_speeds;
1418 phy_cfg.loopback_mode = params->loopback_mode;
1420 /* There are MFWs that share this capability regardless of whether
1421 * this is feasible or not. And given that at the very least adv_caps
1422 * would be set internally by qed, we want to make sure LFA would
1425 if ((p_hwfn->mcp_info->capabilities &
1426 FW_MB_PARAM_FEATURE_SUPPORT_EEE) && params->eee.enable) {
1427 phy_cfg.eee_cfg |= EEE_CFG_EEE_ENABLED;
1428 if (params->eee.tx_lpi_enable)
1429 phy_cfg.eee_cfg |= EEE_CFG_TX_LPI;
1430 if (params->eee.adv_caps & QED_EEE_1G_ADV)
1431 phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_1G;
1432 if (params->eee.adv_caps & QED_EEE_10G_ADV)
1433 phy_cfg.eee_cfg |= EEE_CFG_ADV_SPEED_10G;
1434 phy_cfg.eee_cfg |= (params->eee.tx_lpi_timer <<
1435 EEE_TX_TIMER_USEC_OFFSET) &
1436 EEE_TX_TIMER_USEC_MASK;
1439 p_hwfn->b_drv_link_init = b_up;
1442 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1443 "Configuring Link: Speed 0x%08x, Pause 0x%08x, adv_speed 0x%08x, loopback 0x%08x, features 0x%08x\n",
1447 phy_cfg.loopback_mode,
1448 phy_cfg.feature_config_flags);
1450 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1451 "Resetting link\n");
1454 memset(&mb_params, 0, sizeof(mb_params));
1455 mb_params.cmd = cmd;
1456 mb_params.p_data_src = &phy_cfg;
1457 mb_params.data_src_size = sizeof(phy_cfg);
1458 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1460 /* if mcp fails to respond we must abort */
1462 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
1466 /* Mimic link-change attention, done for several reasons:
1467 * - On reset, there's no guarantee MFW would trigger
1469 * - On initialization, older MFWs might not indicate link change
1470 * during LFA, so we'll never get an UP indication.
1472 qed_mcp_handle_link_change(p_hwfn, p_ptt, !b_up);
1477 static void qed_mcp_send_protocol_stats(struct qed_hwfn *p_hwfn,
1478 struct qed_ptt *p_ptt,
1479 enum MFW_DRV_MSG_TYPE type)
1481 enum qed_mcp_protocol_type stats_type;
1482 union qed_mcp_protocol_stats stats;
1483 struct qed_mcp_mb_params mb_params;
1487 case MFW_DRV_MSG_GET_LAN_STATS:
1488 stats_type = QED_MCP_LAN_STATS;
1489 hsi_param = DRV_MSG_CODE_STATS_TYPE_LAN;
1491 case MFW_DRV_MSG_GET_FCOE_STATS:
1492 stats_type = QED_MCP_FCOE_STATS;
1493 hsi_param = DRV_MSG_CODE_STATS_TYPE_FCOE;
1495 case MFW_DRV_MSG_GET_ISCSI_STATS:
1496 stats_type = QED_MCP_ISCSI_STATS;
1497 hsi_param = DRV_MSG_CODE_STATS_TYPE_ISCSI;
1499 case MFW_DRV_MSG_GET_RDMA_STATS:
1500 stats_type = QED_MCP_RDMA_STATS;
1501 hsi_param = DRV_MSG_CODE_STATS_TYPE_RDMA;
1504 DP_NOTICE(p_hwfn, "Invalid protocol type %d\n", type);
1508 qed_get_protocol_stats(p_hwfn->cdev, stats_type, &stats);
1510 memset(&mb_params, 0, sizeof(mb_params));
1511 mb_params.cmd = DRV_MSG_CODE_GET_STATS;
1512 mb_params.param = hsi_param;
1513 mb_params.p_data_src = &stats;
1514 mb_params.data_src_size = sizeof(stats);
1515 qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1518 static void qed_read_pf_bandwidth(struct qed_hwfn *p_hwfn,
1519 struct public_func *p_shmem_info)
1521 struct qed_mcp_function_info *p_info;
1523 p_info = &p_hwfn->mcp_info->func_info;
1525 p_info->bandwidth_min = (p_shmem_info->config &
1526 FUNC_MF_CFG_MIN_BW_MASK) >>
1527 FUNC_MF_CFG_MIN_BW_SHIFT;
1528 if (p_info->bandwidth_min < 1 || p_info->bandwidth_min > 100) {
1530 "bandwidth minimum out of bounds [%02x]. Set to 1\n",
1531 p_info->bandwidth_min);
1532 p_info->bandwidth_min = 1;
1535 p_info->bandwidth_max = (p_shmem_info->config &
1536 FUNC_MF_CFG_MAX_BW_MASK) >>
1537 FUNC_MF_CFG_MAX_BW_SHIFT;
1538 if (p_info->bandwidth_max < 1 || p_info->bandwidth_max > 100) {
1540 "bandwidth maximum out of bounds [%02x]. Set to 100\n",
1541 p_info->bandwidth_max);
1542 p_info->bandwidth_max = 100;
1546 static u32 qed_mcp_get_shmem_func(struct qed_hwfn *p_hwfn,
1547 struct qed_ptt *p_ptt,
1548 struct public_func *p_data, int pfid)
1550 u32 addr = SECTION_OFFSIZE_ADDR(p_hwfn->mcp_info->public_base,
1552 u32 mfw_path_offsize = qed_rd(p_hwfn, p_ptt, addr);
1553 u32 func_addr = SECTION_ADDR(mfw_path_offsize, pfid);
1556 memset(p_data, 0, sizeof(*p_data));
1558 size = min_t(u32, sizeof(*p_data), QED_SECTION_SIZE(mfw_path_offsize));
1559 for (i = 0; i < size / sizeof(u32); i++)
1560 ((u32 *)p_data)[i] = qed_rd(p_hwfn, p_ptt,
1561 func_addr + (i << 2));
1565 static void qed_mcp_update_bw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1567 struct qed_mcp_function_info *p_info;
1568 struct public_func shmem_info;
1569 u32 resp = 0, param = 0;
1571 qed_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
1573 qed_read_pf_bandwidth(p_hwfn, &shmem_info);
1575 p_info = &p_hwfn->mcp_info->func_info;
1577 qed_configure_pf_min_bandwidth(p_hwfn->cdev, p_info->bandwidth_min);
1578 qed_configure_pf_max_bandwidth(p_hwfn->cdev, p_info->bandwidth_max);
1580 /* Acknowledge the MFW */
1581 qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BW_UPDATE_ACK, 0, &resp,
1585 static void qed_mcp_update_stag(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1587 struct public_func shmem_info;
1588 u32 resp = 0, param = 0;
1590 qed_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
1592 p_hwfn->mcp_info->func_info.ovlan = (u16)shmem_info.ovlan_stag &
1593 FUNC_MF_CFG_OV_STAG_MASK;
1594 p_hwfn->hw_info.ovlan = p_hwfn->mcp_info->func_info.ovlan;
1595 if (test_bit(QED_MF_OVLAN_CLSS, &p_hwfn->cdev->mf_bits)) {
1596 if (p_hwfn->hw_info.ovlan != QED_MCP_VLAN_UNSET) {
1597 qed_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_VALUE,
1598 p_hwfn->hw_info.ovlan);
1599 qed_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_EN, 1);
1601 /* Configure DB to add external vlan to EDPM packets */
1602 qed_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 1);
1603 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_EXT_VID_BB_K2,
1604 p_hwfn->hw_info.ovlan);
1606 qed_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_EN, 0);
1607 qed_wr(p_hwfn, p_ptt, NIG_REG_LLH_FUNC_TAG_VALUE, 0);
1608 qed_wr(p_hwfn, p_ptt, DORQ_REG_TAG1_OVRD_MODE, 0);
1609 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_EXT_VID_BB_K2, 0);
1612 qed_sp_pf_update_stag(p_hwfn);
1615 DP_VERBOSE(p_hwfn, QED_MSG_SP, "ovlan = %d hw_mode = 0x%x\n",
1616 p_hwfn->mcp_info->func_info.ovlan, p_hwfn->hw_info.hw_mode);
1618 /* Acknowledge the MFW */
1619 qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_S_TAG_UPDATE_ACK, 0,
1623 void qed_mcp_read_ufp_config(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1625 struct public_func shmem_info;
1628 if (!test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits))
1631 memset(&p_hwfn->ufp_info, 0, sizeof(p_hwfn->ufp_info));
1632 port_cfg = qed_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
1633 offsetof(struct public_port, oem_cfg_port));
1634 val = (port_cfg & OEM_CFG_CHANNEL_TYPE_MASK) >>
1635 OEM_CFG_CHANNEL_TYPE_OFFSET;
1636 if (val != OEM_CFG_CHANNEL_TYPE_STAGGED)
1637 DP_NOTICE(p_hwfn, "Incorrect UFP Channel type %d\n", val);
1639 val = (port_cfg & OEM_CFG_SCHED_TYPE_MASK) >> OEM_CFG_SCHED_TYPE_OFFSET;
1640 if (val == OEM_CFG_SCHED_TYPE_ETS) {
1641 p_hwfn->ufp_info.mode = QED_UFP_MODE_ETS;
1642 } else if (val == OEM_CFG_SCHED_TYPE_VNIC_BW) {
1643 p_hwfn->ufp_info.mode = QED_UFP_MODE_VNIC_BW;
1645 p_hwfn->ufp_info.mode = QED_UFP_MODE_UNKNOWN;
1646 DP_NOTICE(p_hwfn, "Unknown UFP scheduling mode %d\n", val);
1649 qed_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
1650 val = (shmem_info.oem_cfg_func & OEM_CFG_FUNC_TC_MASK) >>
1651 OEM_CFG_FUNC_TC_OFFSET;
1652 p_hwfn->ufp_info.tc = (u8)val;
1653 val = (shmem_info.oem_cfg_func & OEM_CFG_FUNC_HOST_PRI_CTRL_MASK) >>
1654 OEM_CFG_FUNC_HOST_PRI_CTRL_OFFSET;
1655 if (val == OEM_CFG_FUNC_HOST_PRI_CTRL_VNIC) {
1656 p_hwfn->ufp_info.pri_type = QED_UFP_PRI_VNIC;
1657 } else if (val == OEM_CFG_FUNC_HOST_PRI_CTRL_OS) {
1658 p_hwfn->ufp_info.pri_type = QED_UFP_PRI_OS;
1660 p_hwfn->ufp_info.pri_type = QED_UFP_PRI_UNKNOWN;
1661 DP_NOTICE(p_hwfn, "Unknown Host priority control %d\n", val);
1665 "UFP shmem config: mode = %d tc = %d pri_type = %d\n",
1666 p_hwfn->ufp_info.mode,
1667 p_hwfn->ufp_info.tc, p_hwfn->ufp_info.pri_type);
1671 qed_mcp_handle_ufp_event(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1673 qed_mcp_read_ufp_config(p_hwfn, p_ptt);
1675 if (p_hwfn->ufp_info.mode == QED_UFP_MODE_VNIC_BW) {
1676 p_hwfn->qm_info.ooo_tc = p_hwfn->ufp_info.tc;
1677 qed_hw_info_set_offload_tc(&p_hwfn->hw_info,
1678 p_hwfn->ufp_info.tc);
1680 qed_qm_reconf(p_hwfn, p_ptt);
1681 } else if (p_hwfn->ufp_info.mode == QED_UFP_MODE_ETS) {
1682 /* Merge UFP TC with the dcbx TC data */
1683 qed_dcbx_mib_update_event(p_hwfn, p_ptt,
1684 QED_DCBX_OPERATIONAL_MIB);
1686 DP_ERR(p_hwfn, "Invalid sched type, discard the UFP config\n");
1690 /* update storm FW with negotiation results */
1691 qed_sp_pf_update_ufp(p_hwfn);
1693 /* update stag pcp value */
1694 qed_sp_pf_update_stag(p_hwfn);
1699 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
1700 struct qed_ptt *p_ptt)
1702 struct qed_mcp_info *info = p_hwfn->mcp_info;
1707 DP_VERBOSE(p_hwfn, QED_MSG_SP, "Received message from MFW\n");
1709 /* Read Messages from MFW */
1710 qed_mcp_read_mb(p_hwfn, p_ptt);
1712 /* Compare current messages to old ones */
1713 for (i = 0; i < info->mfw_mb_length; i++) {
1714 if (info->mfw_mb_cur[i] == info->mfw_mb_shadow[i])
1719 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1720 "Msg [%d] - old CMD 0x%02x, new CMD 0x%02x\n",
1721 i, info->mfw_mb_shadow[i], info->mfw_mb_cur[i]);
1724 case MFW_DRV_MSG_LINK_CHANGE:
1725 qed_mcp_handle_link_change(p_hwfn, p_ptt, false);
1727 case MFW_DRV_MSG_VF_DISABLED:
1728 qed_mcp_handle_vf_flr(p_hwfn, p_ptt);
1730 case MFW_DRV_MSG_LLDP_DATA_UPDATED:
1731 qed_dcbx_mib_update_event(p_hwfn, p_ptt,
1732 QED_DCBX_REMOTE_LLDP_MIB);
1734 case MFW_DRV_MSG_DCBX_REMOTE_MIB_UPDATED:
1735 qed_dcbx_mib_update_event(p_hwfn, p_ptt,
1736 QED_DCBX_REMOTE_MIB);
1738 case MFW_DRV_MSG_DCBX_OPERATIONAL_MIB_UPDATED:
1739 qed_dcbx_mib_update_event(p_hwfn, p_ptt,
1740 QED_DCBX_OPERATIONAL_MIB);
1742 case MFW_DRV_MSG_OEM_CFG_UPDATE:
1743 qed_mcp_handle_ufp_event(p_hwfn, p_ptt);
1745 case MFW_DRV_MSG_TRANSCEIVER_STATE_CHANGE:
1746 qed_mcp_handle_transceiver_change(p_hwfn, p_ptt);
1748 case MFW_DRV_MSG_GET_LAN_STATS:
1749 case MFW_DRV_MSG_GET_FCOE_STATS:
1750 case MFW_DRV_MSG_GET_ISCSI_STATS:
1751 case MFW_DRV_MSG_GET_RDMA_STATS:
1752 qed_mcp_send_protocol_stats(p_hwfn, p_ptt, i);
1754 case MFW_DRV_MSG_BW_UPDATE:
1755 qed_mcp_update_bw(p_hwfn, p_ptt);
1757 case MFW_DRV_MSG_S_TAG_UPDATE:
1758 qed_mcp_update_stag(p_hwfn, p_ptt);
1760 case MFW_DRV_MSG_GET_TLV_REQ:
1761 qed_mfw_tlv_req(p_hwfn);
1764 DP_INFO(p_hwfn, "Unimplemented MFW message %d\n", i);
1769 /* ACK everything */
1770 for (i = 0; i < MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length); i++) {
1771 __be32 val = cpu_to_be32(((u32 *)info->mfw_mb_cur)[i]);
1773 /* MFW expect answer in BE, so we force write in that format */
1774 qed_wr(p_hwfn, p_ptt,
1775 info->mfw_mb_addr + sizeof(u32) +
1776 MFW_DRV_MSG_MAX_DWORDS(info->mfw_mb_length) *
1777 sizeof(u32) + i * sizeof(u32),
1783 "Received an MFW message indication but no new message!\n");
1787 /* Copy the new mfw messages into the shadow */
1788 memcpy(info->mfw_mb_shadow, info->mfw_mb_cur, info->mfw_mb_length);
1793 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
1794 struct qed_ptt *p_ptt,
1795 u32 *p_mfw_ver, u32 *p_running_bundle_id)
1799 if (IS_VF(p_hwfn->cdev)) {
1800 if (p_hwfn->vf_iov_info) {
1801 struct pfvf_acquire_resp_tlv *p_resp;
1803 p_resp = &p_hwfn->vf_iov_info->acquire_resp;
1804 *p_mfw_ver = p_resp->pfdev_info.mfw_ver;
1809 "VF requested MFW version prior to ACQUIRE\n");
1814 global_offsize = qed_rd(p_hwfn, p_ptt,
1815 SECTION_OFFSIZE_ADDR(p_hwfn->
1816 mcp_info->public_base,
1819 qed_rd(p_hwfn, p_ptt,
1820 SECTION_ADDR(global_offsize,
1821 0) + offsetof(struct public_global, mfw_ver));
1823 if (p_running_bundle_id != NULL) {
1824 *p_running_bundle_id = qed_rd(p_hwfn, p_ptt,
1825 SECTION_ADDR(global_offsize, 0) +
1826 offsetof(struct public_global,
1827 running_bundle_id));
1833 int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
1834 struct qed_ptt *p_ptt, u32 *p_mbi_ver)
1836 u32 nvm_cfg_addr, nvm_cfg1_offset, mbi_ver_addr;
1838 if (IS_VF(p_hwfn->cdev))
1841 /* Read the address of the nvm_cfg */
1842 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
1843 if (!nvm_cfg_addr) {
1844 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
1848 /* Read the offset of nvm_cfg1 */
1849 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
1851 mbi_ver_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1852 offsetof(struct nvm_cfg1, glob) +
1853 offsetof(struct nvm_cfg1_glob, mbi_version);
1854 *p_mbi_ver = qed_rd(p_hwfn, p_ptt,
1856 (NVM_CFG1_GLOB_MBI_VERSION_0_MASK |
1857 NVM_CFG1_GLOB_MBI_VERSION_1_MASK |
1858 NVM_CFG1_GLOB_MBI_VERSION_2_MASK);
1863 int qed_mcp_get_media_type(struct qed_hwfn *p_hwfn,
1864 struct qed_ptt *p_ptt, u32 *p_media_type)
1866 if (IS_VF(p_hwfn->cdev))
1869 if (!qed_mcp_is_init(p_hwfn)) {
1870 DP_NOTICE(p_hwfn, "MFW is not initialized!\n");
1875 *p_media_type = MEDIA_UNSPECIFIED;
1879 *p_media_type = qed_rd(p_hwfn, p_ptt,
1880 p_hwfn->mcp_info->port_addr +
1881 offsetof(struct public_port,
1887 /* Old MFW has a global configuration for all PFs regarding RDMA support */
1889 qed_mcp_get_shmem_proto_legacy(struct qed_hwfn *p_hwfn,
1890 enum qed_pci_personality *p_proto)
1892 /* There wasn't ever a legacy MFW that published iwarp.
1893 * So at this point, this is either plain l2 or RoCE.
1895 if (test_bit(QED_DEV_CAP_ROCE, &p_hwfn->hw_info.device_capabilities))
1896 *p_proto = QED_PCI_ETH_ROCE;
1898 *p_proto = QED_PCI_ETH;
1900 DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
1901 "According to Legacy capabilities, L2 personality is %08x\n",
1906 qed_mcp_get_shmem_proto_mfw(struct qed_hwfn *p_hwfn,
1907 struct qed_ptt *p_ptt,
1908 enum qed_pci_personality *p_proto)
1910 u32 resp = 0, param = 0;
1913 rc = qed_mcp_cmd(p_hwfn, p_ptt,
1914 DRV_MSG_CODE_GET_PF_RDMA_PROTOCOL, 0, &resp, ¶m);
1917 if (resp != FW_MSG_CODE_OK) {
1918 DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
1919 "MFW lacks support for command; Returns %08x\n",
1925 case FW_MB_PARAM_GET_PF_RDMA_NONE:
1926 *p_proto = QED_PCI_ETH;
1928 case FW_MB_PARAM_GET_PF_RDMA_ROCE:
1929 *p_proto = QED_PCI_ETH_ROCE;
1931 case FW_MB_PARAM_GET_PF_RDMA_IWARP:
1932 *p_proto = QED_PCI_ETH_IWARP;
1934 case FW_MB_PARAM_GET_PF_RDMA_BOTH:
1935 *p_proto = QED_PCI_ETH_RDMA;
1939 "MFW answers GET_PF_RDMA_PROTOCOL but param is %08x\n",
1946 "According to capabilities, L2 personality is %08x [resp %08x param %08x]\n",
1947 (u32) *p_proto, resp, param);
1952 qed_mcp_get_shmem_proto(struct qed_hwfn *p_hwfn,
1953 struct public_func *p_info,
1954 struct qed_ptt *p_ptt,
1955 enum qed_pci_personality *p_proto)
1959 switch (p_info->config & FUNC_MF_CFG_PROTOCOL_MASK) {
1960 case FUNC_MF_CFG_PROTOCOL_ETHERNET:
1961 if (!IS_ENABLED(CONFIG_QED_RDMA))
1962 *p_proto = QED_PCI_ETH;
1963 else if (qed_mcp_get_shmem_proto_mfw(p_hwfn, p_ptt, p_proto))
1964 qed_mcp_get_shmem_proto_legacy(p_hwfn, p_proto);
1966 case FUNC_MF_CFG_PROTOCOL_ISCSI:
1967 *p_proto = QED_PCI_ISCSI;
1969 case FUNC_MF_CFG_PROTOCOL_FCOE:
1970 *p_proto = QED_PCI_FCOE;
1972 case FUNC_MF_CFG_PROTOCOL_ROCE:
1973 DP_NOTICE(p_hwfn, "RoCE personality is not a valid value!\n");
1982 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
1983 struct qed_ptt *p_ptt)
1985 struct qed_mcp_function_info *info;
1986 struct public_func shmem_info;
1988 qed_mcp_get_shmem_func(p_hwfn, p_ptt, &shmem_info, MCP_PF_ID(p_hwfn));
1989 info = &p_hwfn->mcp_info->func_info;
1991 info->pause_on_host = (shmem_info.config &
1992 FUNC_MF_CFG_PAUSE_ON_HOST_RING) ? 1 : 0;
1994 if (qed_mcp_get_shmem_proto(p_hwfn, &shmem_info, p_ptt,
1996 DP_ERR(p_hwfn, "Unknown personality %08x\n",
1997 (u32)(shmem_info.config & FUNC_MF_CFG_PROTOCOL_MASK));
2001 qed_read_pf_bandwidth(p_hwfn, &shmem_info);
2003 if (shmem_info.mac_upper || shmem_info.mac_lower) {
2004 info->mac[0] = (u8)(shmem_info.mac_upper >> 8);
2005 info->mac[1] = (u8)(shmem_info.mac_upper);
2006 info->mac[2] = (u8)(shmem_info.mac_lower >> 24);
2007 info->mac[3] = (u8)(shmem_info.mac_lower >> 16);
2008 info->mac[4] = (u8)(shmem_info.mac_lower >> 8);
2009 info->mac[5] = (u8)(shmem_info.mac_lower);
2011 /* Store primary MAC for later possible WoL */
2012 memcpy(&p_hwfn->cdev->wol_mac, info->mac, ETH_ALEN);
2014 DP_NOTICE(p_hwfn, "MAC is 0 in shmem\n");
2017 info->wwn_port = (u64)shmem_info.fcoe_wwn_port_name_lower |
2018 (((u64)shmem_info.fcoe_wwn_port_name_upper) << 32);
2019 info->wwn_node = (u64)shmem_info.fcoe_wwn_node_name_lower |
2020 (((u64)shmem_info.fcoe_wwn_node_name_upper) << 32);
2022 info->ovlan = (u16)(shmem_info.ovlan_stag & FUNC_MF_CFG_OV_STAG_MASK);
2024 info->mtu = (u16)shmem_info.mtu_size;
2026 p_hwfn->hw_info.b_wol_support = QED_WOL_SUPPORT_NONE;
2027 p_hwfn->cdev->wol_config = (u8)QED_OV_WOL_DEFAULT;
2028 if (qed_mcp_is_init(p_hwfn)) {
2029 u32 resp = 0, param = 0;
2032 rc = qed_mcp_cmd(p_hwfn, p_ptt,
2033 DRV_MSG_CODE_OS_WOL, 0, &resp, ¶m);
2036 if (resp == FW_MSG_CODE_OS_WOL_SUPPORTED)
2037 p_hwfn->hw_info.b_wol_support = QED_WOL_SUPPORT_PME;
2040 DP_VERBOSE(p_hwfn, (QED_MSG_SP | NETIF_MSG_IFUP),
2041 "Read configuration from shmem: pause_on_host %02x protocol %02x BW [%02x - %02x] MAC %02x:%02x:%02x:%02x:%02x:%02x wwn port %llx node %llx ovlan %04x wol %02x\n",
2042 info->pause_on_host, info->protocol,
2043 info->bandwidth_min, info->bandwidth_max,
2044 info->mac[0], info->mac[1], info->mac[2],
2045 info->mac[3], info->mac[4], info->mac[5],
2046 info->wwn_port, info->wwn_node,
2047 info->ovlan, (u8)p_hwfn->hw_info.b_wol_support);
2052 struct qed_mcp_link_params
2053 *qed_mcp_get_link_params(struct qed_hwfn *p_hwfn)
2055 if (!p_hwfn || !p_hwfn->mcp_info)
2057 return &p_hwfn->mcp_info->link_input;
2060 struct qed_mcp_link_state
2061 *qed_mcp_get_link_state(struct qed_hwfn *p_hwfn)
2063 if (!p_hwfn || !p_hwfn->mcp_info)
2065 return &p_hwfn->mcp_info->link_output;
2068 struct qed_mcp_link_capabilities
2069 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn)
2071 if (!p_hwfn || !p_hwfn->mcp_info)
2073 return &p_hwfn->mcp_info->link_capabilities;
2076 int qed_mcp_drain(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2078 u32 resp = 0, param = 0;
2081 rc = qed_mcp_cmd(p_hwfn, p_ptt,
2082 DRV_MSG_CODE_NIG_DRAIN, 1000, &resp, ¶m);
2084 /* Wait for the drain to complete before returning */
2090 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
2091 struct qed_ptt *p_ptt, u32 *p_flash_size)
2095 if (IS_VF(p_hwfn->cdev))
2098 flash_size = qed_rd(p_hwfn, p_ptt, MCP_REG_NVM_CFG4);
2099 flash_size = (flash_size & MCP_REG_NVM_CFG4_FLASH_SIZE) >>
2100 MCP_REG_NVM_CFG4_FLASH_SIZE_SHIFT;
2101 flash_size = (1 << (flash_size + MCP_BYTES_PER_MBIT_SHIFT));
2103 *p_flash_size = flash_size;
2109 qed_mcp_config_vf_msix_bb(struct qed_hwfn *p_hwfn,
2110 struct qed_ptt *p_ptt, u8 vf_id, u8 num)
2112 u32 resp = 0, param = 0, rc_param = 0;
2115 /* Only Leader can configure MSIX, and need to take CMT into account */
2116 if (!IS_LEAD_HWFN(p_hwfn))
2118 num *= p_hwfn->cdev->num_hwfns;
2120 param |= (vf_id << DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_SHIFT) &
2121 DRV_MB_PARAM_CFG_VF_MSIX_VF_ID_MASK;
2122 param |= (num << DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_SHIFT) &
2123 DRV_MB_PARAM_CFG_VF_MSIX_SB_NUM_MASK;
2125 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_VF_MSIX, param,
2128 if (resp != FW_MSG_CODE_DRV_CFG_VF_MSIX_DONE) {
2129 DP_NOTICE(p_hwfn, "VF[%d]: MFW failed to set MSI-X\n", vf_id);
2132 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2133 "Requested 0x%02x MSI-x interrupts from VF 0x%02x\n",
2141 qed_mcp_config_vf_msix_ah(struct qed_hwfn *p_hwfn,
2142 struct qed_ptt *p_ptt, u8 num)
2144 u32 resp = 0, param = num, rc_param = 0;
2147 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_CFG_PF_VFS_MSIX,
2148 param, &resp, &rc_param);
2150 if (resp != FW_MSG_CODE_DRV_CFG_PF_VFS_MSIX_DONE) {
2151 DP_NOTICE(p_hwfn, "MFW failed to set MSI-X for VFs\n");
2154 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
2155 "Requested 0x%02x MSI-x interrupts for VFs\n", num);
2161 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
2162 struct qed_ptt *p_ptt, u8 vf_id, u8 num)
2164 if (QED_IS_BB(p_hwfn->cdev))
2165 return qed_mcp_config_vf_msix_bb(p_hwfn, p_ptt, vf_id, num);
2167 return qed_mcp_config_vf_msix_ah(p_hwfn, p_ptt, num);
2171 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
2172 struct qed_ptt *p_ptt,
2173 struct qed_mcp_drv_version *p_ver)
2175 struct qed_mcp_mb_params mb_params;
2176 struct drv_version_stc drv_version;
2181 memset(&drv_version, 0, sizeof(drv_version));
2182 drv_version.version = p_ver->version;
2183 for (i = 0; i < (MCP_DRV_VER_STR_SIZE - 4) / sizeof(u32); i++) {
2184 val = cpu_to_be32(*((u32 *)&p_ver->name[i * sizeof(u32)]));
2185 *(__be32 *)&drv_version.name[i * sizeof(u32)] = val;
2188 memset(&mb_params, 0, sizeof(mb_params));
2189 mb_params.cmd = DRV_MSG_CODE_SET_VERSION;
2190 mb_params.p_data_src = &drv_version;
2191 mb_params.data_src_size = sizeof(drv_version);
2192 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
2194 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2199 /* A maximal 100 msec waiting time for the MCP to halt */
2200 #define QED_MCP_HALT_SLEEP_MS 10
2201 #define QED_MCP_HALT_MAX_RETRIES 10
2203 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2205 u32 resp = 0, param = 0, cpu_state, cnt = 0;
2208 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MCP_HALT, 0, &resp,
2211 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2216 msleep(QED_MCP_HALT_SLEEP_MS);
2217 cpu_state = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2218 if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED)
2220 } while (++cnt < QED_MCP_HALT_MAX_RETRIES);
2222 if (cnt == QED_MCP_HALT_MAX_RETRIES) {
2224 "Failed to halt the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2225 qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE), cpu_state);
2229 qed_mcp_cmd_set_blocking(p_hwfn, true);
2234 #define QED_MCP_RESUME_SLEEP_MS 10
2236 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2238 u32 cpu_mode, cpu_state;
2240 qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_STATE, 0xffffffff);
2242 cpu_mode = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_MODE);
2243 cpu_mode &= ~MCP_REG_CPU_MODE_SOFT_HALT;
2244 qed_wr(p_hwfn, p_ptt, MCP_REG_CPU_MODE, cpu_mode);
2245 msleep(QED_MCP_RESUME_SLEEP_MS);
2246 cpu_state = qed_rd(p_hwfn, p_ptt, MCP_REG_CPU_STATE);
2248 if (cpu_state & MCP_REG_CPU_STATE_SOFT_HALTED) {
2250 "Failed to resume the MCP [CPU_MODE = 0x%08x, CPU_STATE = 0x%08x]\n",
2251 cpu_mode, cpu_state);
2255 qed_mcp_cmd_set_blocking(p_hwfn, false);
2260 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
2261 struct qed_ptt *p_ptt,
2262 enum qed_ov_client client)
2264 u32 resp = 0, param = 0;
2269 case QED_OV_CLIENT_DRV:
2270 drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OS;
2272 case QED_OV_CLIENT_USER:
2273 drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_OTHER;
2275 case QED_OV_CLIENT_VENDOR_SPEC:
2276 drv_mb_param = DRV_MB_PARAM_OV_CURR_CFG_VENDOR_SPEC;
2279 DP_NOTICE(p_hwfn, "Invalid client type %d\n", client);
2283 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_CURR_CFG,
2284 drv_mb_param, &resp, ¶m);
2286 DP_ERR(p_hwfn, "MCP response failure, aborting\n");
2291 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
2292 struct qed_ptt *p_ptt,
2293 enum qed_ov_driver_state drv_state)
2295 u32 resp = 0, param = 0;
2299 switch (drv_state) {
2300 case QED_OV_DRIVER_STATE_NOT_LOADED:
2301 drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_NOT_LOADED;
2303 case QED_OV_DRIVER_STATE_DISABLED:
2304 drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_DISABLED;
2306 case QED_OV_DRIVER_STATE_ACTIVE:
2307 drv_mb_param = DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE_ACTIVE;
2310 DP_NOTICE(p_hwfn, "Invalid driver state %d\n", drv_state);
2314 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_DRIVER_STATE,
2315 drv_mb_param, &resp, ¶m);
2317 DP_ERR(p_hwfn, "Failed to send driver state\n");
2322 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
2323 struct qed_ptt *p_ptt, u16 mtu)
2325 u32 resp = 0, param = 0;
2329 drv_mb_param = (u32)mtu << DRV_MB_PARAM_OV_MTU_SIZE_SHIFT;
2330 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_MTU,
2331 drv_mb_param, &resp, ¶m);
2333 DP_ERR(p_hwfn, "Failed to send mtu value, rc = %d\n", rc);
2338 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
2339 struct qed_ptt *p_ptt, u8 *mac)
2341 struct qed_mcp_mb_params mb_params;
2345 memset(&mb_params, 0, sizeof(mb_params));
2346 mb_params.cmd = DRV_MSG_CODE_SET_VMAC;
2347 mb_params.param = DRV_MSG_CODE_VMAC_TYPE_MAC <<
2348 DRV_MSG_CODE_VMAC_TYPE_SHIFT;
2349 mb_params.param |= MCP_PF_ID(p_hwfn);
2351 /* MCP is BE, and on LE platforms PCI would swap access to SHMEM
2352 * in 32-bit granularity.
2353 * So the MAC has to be set in native order [and not byte order],
2354 * otherwise it would be read incorrectly by MFW after swap.
2356 mfw_mac[0] = mac[0] << 24 | mac[1] << 16 | mac[2] << 8 | mac[3];
2357 mfw_mac[1] = mac[4] << 24 | mac[5] << 16;
2359 mb_params.p_data_src = (u8 *)mfw_mac;
2360 mb_params.data_src_size = 8;
2361 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
2363 DP_ERR(p_hwfn, "Failed to send mac address, rc = %d\n", rc);
2365 /* Store primary MAC for later possible WoL */
2366 memcpy(p_hwfn->cdev->wol_mac, mac, ETH_ALEN);
2371 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
2372 struct qed_ptt *p_ptt, enum qed_ov_wol wol)
2374 u32 resp = 0, param = 0;
2378 if (p_hwfn->hw_info.b_wol_support == QED_WOL_SUPPORT_NONE) {
2379 DP_VERBOSE(p_hwfn, QED_MSG_SP,
2380 "Can't change WoL configuration when WoL isn't supported\n");
2385 case QED_OV_WOL_DEFAULT:
2386 drv_mb_param = DRV_MB_PARAM_WOL_DEFAULT;
2388 case QED_OV_WOL_DISABLED:
2389 drv_mb_param = DRV_MB_PARAM_WOL_DISABLED;
2391 case QED_OV_WOL_ENABLED:
2392 drv_mb_param = DRV_MB_PARAM_WOL_ENABLED;
2395 DP_ERR(p_hwfn, "Invalid wol state %d\n", wol);
2399 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_WOL,
2400 drv_mb_param, &resp, ¶m);
2402 DP_ERR(p_hwfn, "Failed to send wol mode, rc = %d\n", rc);
2404 /* Store the WoL update for a future unload */
2405 p_hwfn->cdev->wol_config = (u8)wol;
2410 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
2411 struct qed_ptt *p_ptt,
2412 enum qed_ov_eswitch eswitch)
2414 u32 resp = 0, param = 0;
2419 case QED_OV_ESWITCH_NONE:
2420 drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_NONE;
2422 case QED_OV_ESWITCH_VEB:
2423 drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEB;
2425 case QED_OV_ESWITCH_VEPA:
2426 drv_mb_param = DRV_MB_PARAM_ESWITCH_MODE_VEPA;
2429 DP_ERR(p_hwfn, "Invalid eswitch mode %d\n", eswitch);
2433 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_OV_UPDATE_ESWITCH_MODE,
2434 drv_mb_param, &resp, ¶m);
2436 DP_ERR(p_hwfn, "Failed to send eswitch mode, rc = %d\n", rc);
2441 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
2442 struct qed_ptt *p_ptt, enum qed_led_mode mode)
2444 u32 resp = 0, param = 0, drv_mb_param;
2448 case QED_LED_MODE_ON:
2449 drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_ON;
2451 case QED_LED_MODE_OFF:
2452 drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OFF;
2454 case QED_LED_MODE_RESTORE:
2455 drv_mb_param = DRV_MB_PARAM_SET_LED_MODE_OPER;
2458 DP_NOTICE(p_hwfn, "Invalid LED mode %d\n", mode);
2462 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_LED_MODE,
2463 drv_mb_param, &resp, ¶m);
2468 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
2469 struct qed_ptt *p_ptt, u32 mask_parities)
2471 u32 resp = 0, param = 0;
2474 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_MASK_PARITIES,
2475 mask_parities, &resp, ¶m);
2479 "MCP response failure for mask parities, aborting\n");
2480 } else if (resp != FW_MSG_CODE_OK) {
2482 "MCP did not acknowledge mask parity request. Old MFW?\n");
2489 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len)
2491 u32 bytes_left = len, offset = 0, bytes_to_copy, read_len = 0;
2492 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2493 u32 resp = 0, resp_param = 0;
2494 struct qed_ptt *p_ptt;
2497 p_ptt = qed_ptt_acquire(p_hwfn);
2501 while (bytes_left > 0) {
2502 bytes_to_copy = min_t(u32, bytes_left, MCP_DRV_NVM_BUF_LEN);
2504 rc = qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
2505 DRV_MSG_CODE_NVM_READ_NVRAM,
2508 DRV_MB_PARAM_NVM_LEN_OFFSET),
2511 (u32 *)(p_buf + offset));
2513 if (rc || (resp != FW_MSG_CODE_NVM_OK)) {
2514 DP_NOTICE(cdev, "MCP command rc = %d\n", rc);
2518 /* This can be a lengthy process, and it's possible scheduler
2519 * isn't preemptable. Sleep a bit to prevent CPU hogging.
2521 if (bytes_left % 0x1000 <
2522 (bytes_left - read_len) % 0x1000)
2523 usleep_range(1000, 2000);
2526 bytes_left -= read_len;
2529 cdev->mcp_nvm_resp = resp;
2530 qed_ptt_release(p_hwfn, p_ptt);
2535 int qed_mcp_nvm_resp(struct qed_dev *cdev, u8 *p_buf)
2537 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2538 struct qed_ptt *p_ptt;
2540 p_ptt = qed_ptt_acquire(p_hwfn);
2544 memcpy(p_buf, &cdev->mcp_nvm_resp, sizeof(cdev->mcp_nvm_resp));
2545 qed_ptt_release(p_hwfn, p_ptt);
2550 int qed_mcp_nvm_put_file_begin(struct qed_dev *cdev, u32 addr)
2552 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2553 struct qed_ptt *p_ptt;
2557 p_ptt = qed_ptt_acquire(p_hwfn);
2560 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_NVM_PUT_FILE_BEGIN, addr,
2562 cdev->mcp_nvm_resp = resp;
2563 qed_ptt_release(p_hwfn, p_ptt);
2568 int qed_mcp_nvm_write(struct qed_dev *cdev,
2569 u32 cmd, u32 addr, u8 *p_buf, u32 len)
2571 u32 buf_idx = 0, buf_size, nvm_cmd, nvm_offset, resp = 0, param;
2572 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2573 struct qed_ptt *p_ptt;
2576 p_ptt = qed_ptt_acquire(p_hwfn);
2581 case QED_PUT_FILE_DATA:
2582 nvm_cmd = DRV_MSG_CODE_NVM_PUT_FILE_DATA;
2584 case QED_NVM_WRITE_NVRAM:
2585 nvm_cmd = DRV_MSG_CODE_NVM_WRITE_NVRAM;
2588 DP_NOTICE(p_hwfn, "Invalid nvm write command 0x%x\n", cmd);
2593 while (buf_idx < len) {
2594 buf_size = min_t(u32, (len - buf_idx), MCP_DRV_NVM_BUF_LEN);
2595 nvm_offset = ((buf_size << DRV_MB_PARAM_NVM_LEN_OFFSET) |
2597 rc = qed_mcp_nvm_wr_cmd(p_hwfn, p_ptt, nvm_cmd, nvm_offset,
2598 &resp, ¶m, buf_size,
2599 (u32 *)&p_buf[buf_idx]);
2601 DP_NOTICE(cdev, "nvm write failed, rc = %d\n", rc);
2602 resp = FW_MSG_CODE_ERROR;
2606 if (resp != FW_MSG_CODE_OK &&
2607 resp != FW_MSG_CODE_NVM_OK &&
2608 resp != FW_MSG_CODE_NVM_PUT_FILE_FINISH_OK) {
2610 "nvm write failed, resp = 0x%08x\n", resp);
2615 /* This can be a lengthy process, and it's possible scheduler
2616 * isn't pre-emptable. Sleep a bit to prevent CPU hogging.
2618 if (buf_idx % 0x1000 > (buf_idx + buf_size) % 0x1000)
2619 usleep_range(1000, 2000);
2621 buf_idx += buf_size;
2624 cdev->mcp_nvm_resp = resp;
2626 qed_ptt_release(p_hwfn, p_ptt);
2631 int qed_mcp_phy_sfp_read(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
2632 u32 port, u32 addr, u32 offset, u32 len, u8 *p_buf)
2634 u32 bytes_left, bytes_to_copy, buf_size, nvm_offset = 0;
2638 nvm_offset |= (port << DRV_MB_PARAM_TRANSCEIVER_PORT_OFFSET) &
2639 DRV_MB_PARAM_TRANSCEIVER_PORT_MASK;
2640 nvm_offset |= (addr << DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_OFFSET) &
2641 DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK;
2646 while (bytes_left > 0) {
2647 bytes_to_copy = min_t(u32, bytes_left,
2648 MAX_I2C_TRANSACTION_SIZE);
2649 nvm_offset &= (DRV_MB_PARAM_TRANSCEIVER_I2C_ADDRESS_MASK |
2650 DRV_MB_PARAM_TRANSCEIVER_PORT_MASK);
2651 nvm_offset |= ((addr + offset) <<
2652 DRV_MB_PARAM_TRANSCEIVER_OFFSET_OFFSET) &
2653 DRV_MB_PARAM_TRANSCEIVER_OFFSET_MASK;
2654 nvm_offset |= (bytes_to_copy <<
2655 DRV_MB_PARAM_TRANSCEIVER_SIZE_OFFSET) &
2656 DRV_MB_PARAM_TRANSCEIVER_SIZE_MASK;
2657 rc = qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
2658 DRV_MSG_CODE_TRANSCEIVER_READ,
2659 nvm_offset, &resp, ¶m, &buf_size,
2660 (u32 *)(p_buf + offset));
2663 "Failed to send a transceiver read command to the MFW. rc = %d.\n",
2668 if (resp == FW_MSG_CODE_TRANSCEIVER_NOT_PRESENT)
2670 else if (resp != FW_MSG_CODE_TRANSCEIVER_DIAG_OK)
2674 bytes_left -= buf_size;
2680 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2682 u32 drv_mb_param = 0, rsp, param;
2685 drv_mb_param = (DRV_MB_PARAM_BIST_REGISTER_TEST <<
2686 DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT);
2688 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
2689 drv_mb_param, &rsp, ¶m);
2694 if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
2695 (param != DRV_MB_PARAM_BIST_RC_PASSED))
2701 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2703 u32 drv_mb_param, rsp, param;
2706 drv_mb_param = (DRV_MB_PARAM_BIST_CLOCK_TEST <<
2707 DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT);
2709 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
2710 drv_mb_param, &rsp, ¶m);
2715 if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
2716 (param != DRV_MB_PARAM_BIST_RC_PASSED))
2722 int qed_mcp_bist_nvm_get_num_images(struct qed_hwfn *p_hwfn,
2723 struct qed_ptt *p_ptt,
2726 u32 drv_mb_param = 0, rsp;
2729 drv_mb_param = (DRV_MB_PARAM_BIST_NVM_TEST_NUM_IMAGES <<
2730 DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT);
2732 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_BIST_TEST,
2733 drv_mb_param, &rsp, num_images);
2737 if (((rsp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK))
2743 int qed_mcp_bist_nvm_get_image_att(struct qed_hwfn *p_hwfn,
2744 struct qed_ptt *p_ptt,
2745 struct bist_nvm_image_att *p_image_att,
2748 u32 buf_size = 0, param, resp = 0, resp_param = 0;
2751 param = DRV_MB_PARAM_BIST_NVM_TEST_IMAGE_BY_INDEX <<
2752 DRV_MB_PARAM_BIST_TEST_INDEX_SHIFT;
2753 param |= image_index << DRV_MB_PARAM_BIST_TEST_IMAGE_INDEX_SHIFT;
2755 rc = qed_mcp_nvm_rd_cmd(p_hwfn, p_ptt,
2756 DRV_MSG_CODE_BIST_TEST, param,
2759 (u32 *)p_image_att);
2763 if (((resp & FW_MSG_CODE_MASK) != FW_MSG_CODE_OK) ||
2764 (p_image_att->return_code != 1))
2770 int qed_mcp_nvm_info_populate(struct qed_hwfn *p_hwfn)
2772 struct qed_nvm_image_info nvm_info;
2773 struct qed_ptt *p_ptt;
2777 if (p_hwfn->nvm_info.valid)
2780 p_ptt = qed_ptt_acquire(p_hwfn);
2782 DP_ERR(p_hwfn, "failed to acquire ptt\n");
2786 /* Acquire from MFW the amount of available images */
2787 nvm_info.num_images = 0;
2788 rc = qed_mcp_bist_nvm_get_num_images(p_hwfn,
2789 p_ptt, &nvm_info.num_images);
2790 if (rc == -EOPNOTSUPP) {
2791 DP_INFO(p_hwfn, "DRV_MSG_CODE_BIST_TEST is not supported\n");
2793 } else if (rc || !nvm_info.num_images) {
2794 DP_ERR(p_hwfn, "Failed getting number of images\n");
2798 nvm_info.image_att = kmalloc_array(nvm_info.num_images,
2799 sizeof(struct bist_nvm_image_att),
2801 if (!nvm_info.image_att) {
2806 /* Iterate over images and get their attributes */
2807 for (i = 0; i < nvm_info.num_images; i++) {
2808 rc = qed_mcp_bist_nvm_get_image_att(p_hwfn, p_ptt,
2809 &nvm_info.image_att[i], i);
2812 "Failed getting image index %d attributes\n", i);
2816 DP_VERBOSE(p_hwfn, QED_MSG_SP, "image index %d, size %x\n", i,
2817 nvm_info.image_att[i].len);
2820 /* Update hwfn's nvm_info */
2821 if (nvm_info.num_images) {
2822 p_hwfn->nvm_info.num_images = nvm_info.num_images;
2823 kfree(p_hwfn->nvm_info.image_att);
2824 p_hwfn->nvm_info.image_att = nvm_info.image_att;
2825 p_hwfn->nvm_info.valid = true;
2828 qed_ptt_release(p_hwfn, p_ptt);
2832 kfree(nvm_info.image_att);
2834 qed_ptt_release(p_hwfn, p_ptt);
2839 qed_mcp_get_nvm_image_att(struct qed_hwfn *p_hwfn,
2840 enum qed_nvm_images image_id,
2841 struct qed_nvm_image_att *p_image_att)
2843 enum nvm_image_type type;
2847 /* Translate image_id into MFW definitions */
2849 case QED_NVM_IMAGE_ISCSI_CFG:
2850 type = NVM_TYPE_ISCSI_CFG;
2852 case QED_NVM_IMAGE_FCOE_CFG:
2853 type = NVM_TYPE_FCOE_CFG;
2855 case QED_NVM_IMAGE_NVM_CFG1:
2856 type = NVM_TYPE_NVM_CFG1;
2858 case QED_NVM_IMAGE_DEFAULT_CFG:
2859 type = NVM_TYPE_DEFAULT_CFG;
2861 case QED_NVM_IMAGE_NVM_META:
2862 type = NVM_TYPE_META;
2865 DP_NOTICE(p_hwfn, "Unknown request of image_id %08x\n",
2870 rc = qed_mcp_nvm_info_populate(p_hwfn);
2874 for (i = 0; i < p_hwfn->nvm_info.num_images; i++)
2875 if (type == p_hwfn->nvm_info.image_att[i].image_type)
2877 if (i == p_hwfn->nvm_info.num_images) {
2878 DP_VERBOSE(p_hwfn, QED_MSG_STORAGE,
2879 "Failed to find nvram image of type %08x\n",
2884 p_image_att->start_addr = p_hwfn->nvm_info.image_att[i].nvm_start_addr;
2885 p_image_att->length = p_hwfn->nvm_info.image_att[i].len;
2890 int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn,
2891 enum qed_nvm_images image_id,
2892 u8 *p_buffer, u32 buffer_len)
2894 struct qed_nvm_image_att image_att;
2897 memset(p_buffer, 0, buffer_len);
2899 rc = qed_mcp_get_nvm_image_att(p_hwfn, image_id, &image_att);
2903 /* Validate sizes - both the image's and the supplied buffer's */
2904 if (image_att.length <= 4) {
2905 DP_VERBOSE(p_hwfn, QED_MSG_STORAGE,
2906 "Image [%d] is too small - only %d bytes\n",
2907 image_id, image_att.length);
2911 if (image_att.length > buffer_len) {
2914 "Image [%d] is too big - %08x bytes where only %08x are available\n",
2915 image_id, image_att.length, buffer_len);
2919 return qed_mcp_nvm_read(p_hwfn->cdev, image_att.start_addr,
2920 p_buffer, image_att.length);
2923 static enum resource_id_enum qed_mcp_get_mfw_res_id(enum qed_resources res_id)
2925 enum resource_id_enum mfw_res_id = RESOURCE_NUM_INVALID;
2929 mfw_res_id = RESOURCE_NUM_SB_E;
2932 mfw_res_id = RESOURCE_NUM_L2_QUEUE_E;
2935 mfw_res_id = RESOURCE_NUM_VPORT_E;
2938 mfw_res_id = RESOURCE_NUM_RSS_ENGINES_E;
2941 mfw_res_id = RESOURCE_NUM_PQ_E;
2944 mfw_res_id = RESOURCE_NUM_RL_E;
2948 /* Each VFC resource can accommodate both a MAC and a VLAN */
2949 mfw_res_id = RESOURCE_VFC_FILTER_E;
2952 mfw_res_id = RESOURCE_ILT_E;
2955 mfw_res_id = RESOURCE_LL2_QUEUE_E;
2957 case QED_RDMA_CNQ_RAM:
2959 /* CNQ/CMDQS are the same resource */
2960 mfw_res_id = RESOURCE_CQS_E;
2962 case QED_RDMA_STATS_QUEUE:
2963 mfw_res_id = RESOURCE_RDMA_STATS_QUEUE_E;
2966 mfw_res_id = RESOURCE_BDQ_E;
2975 #define QED_RESC_ALLOC_VERSION_MAJOR 2
2976 #define QED_RESC_ALLOC_VERSION_MINOR 0
2977 #define QED_RESC_ALLOC_VERSION \
2978 ((QED_RESC_ALLOC_VERSION_MAJOR << \
2979 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR_SHIFT) | \
2980 (QED_RESC_ALLOC_VERSION_MINOR << \
2981 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR_SHIFT))
2983 struct qed_resc_alloc_in_params {
2985 enum qed_resources res_id;
2989 struct qed_resc_alloc_out_params {
3000 qed_mcp_resc_allocation_msg(struct qed_hwfn *p_hwfn,
3001 struct qed_ptt *p_ptt,
3002 struct qed_resc_alloc_in_params *p_in_params,
3003 struct qed_resc_alloc_out_params *p_out_params)
3005 struct qed_mcp_mb_params mb_params;
3006 struct resource_info mfw_resc_info;
3009 memset(&mfw_resc_info, 0, sizeof(mfw_resc_info));
3011 mfw_resc_info.res_id = qed_mcp_get_mfw_res_id(p_in_params->res_id);
3012 if (mfw_resc_info.res_id == RESOURCE_NUM_INVALID) {
3014 "Failed to match resource %d [%s] with the MFW resources\n",
3015 p_in_params->res_id,
3016 qed_hw_get_resc_name(p_in_params->res_id));
3020 switch (p_in_params->cmd) {
3021 case DRV_MSG_SET_RESOURCE_VALUE_MSG:
3022 mfw_resc_info.size = p_in_params->resc_max_val;
3024 case DRV_MSG_GET_RESOURCE_ALLOC_MSG:
3027 DP_ERR(p_hwfn, "Unexpected resource alloc command [0x%08x]\n",
3032 memset(&mb_params, 0, sizeof(mb_params));
3033 mb_params.cmd = p_in_params->cmd;
3034 mb_params.param = QED_RESC_ALLOC_VERSION;
3035 mb_params.p_data_src = &mfw_resc_info;
3036 mb_params.data_src_size = sizeof(mfw_resc_info);
3037 mb_params.p_data_dst = mb_params.p_data_src;
3038 mb_params.data_dst_size = mb_params.data_src_size;
3042 "Resource message request: cmd 0x%08x, res_id %d [%s], hsi_version %d.%d, val 0x%x\n",
3044 p_in_params->res_id,
3045 qed_hw_get_resc_name(p_in_params->res_id),
3046 QED_MFW_GET_FIELD(mb_params.param,
3047 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR),
3048 QED_MFW_GET_FIELD(mb_params.param,
3049 DRV_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR),
3050 p_in_params->resc_max_val);
3052 rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
3056 p_out_params->mcp_resp = mb_params.mcp_resp;
3057 p_out_params->mcp_param = mb_params.mcp_param;
3058 p_out_params->resc_num = mfw_resc_info.size;
3059 p_out_params->resc_start = mfw_resc_info.offset;
3060 p_out_params->vf_resc_num = mfw_resc_info.vf_size;
3061 p_out_params->vf_resc_start = mfw_resc_info.vf_offset;
3062 p_out_params->flags = mfw_resc_info.flags;
3066 "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",
3067 QED_MFW_GET_FIELD(p_out_params->mcp_param,
3068 FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MAJOR),
3069 QED_MFW_GET_FIELD(p_out_params->mcp_param,
3070 FW_MB_PARAM_RESOURCE_ALLOC_VERSION_MINOR),
3071 p_out_params->resc_num,
3072 p_out_params->resc_start,
3073 p_out_params->vf_resc_num,
3074 p_out_params->vf_resc_start, p_out_params->flags);
3080 qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn,
3081 struct qed_ptt *p_ptt,
3082 enum qed_resources res_id,
3083 u32 resc_max_val, u32 *p_mcp_resp)
3085 struct qed_resc_alloc_out_params out_params;
3086 struct qed_resc_alloc_in_params in_params;
3089 memset(&in_params, 0, sizeof(in_params));
3090 in_params.cmd = DRV_MSG_SET_RESOURCE_VALUE_MSG;
3091 in_params.res_id = res_id;
3092 in_params.resc_max_val = resc_max_val;
3093 memset(&out_params, 0, sizeof(out_params));
3094 rc = qed_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params,
3099 *p_mcp_resp = out_params.mcp_resp;
3105 qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
3106 struct qed_ptt *p_ptt,
3107 enum qed_resources res_id,
3108 u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start)
3110 struct qed_resc_alloc_out_params out_params;
3111 struct qed_resc_alloc_in_params in_params;
3114 memset(&in_params, 0, sizeof(in_params));
3115 in_params.cmd = DRV_MSG_GET_RESOURCE_ALLOC_MSG;
3116 in_params.res_id = res_id;
3117 memset(&out_params, 0, sizeof(out_params));
3118 rc = qed_mcp_resc_allocation_msg(p_hwfn, p_ptt, &in_params,
3123 *p_mcp_resp = out_params.mcp_resp;
3125 if (*p_mcp_resp == FW_MSG_CODE_RESOURCE_ALLOC_OK) {
3126 *p_resc_num = out_params.resc_num;
3127 *p_resc_start = out_params.resc_start;
3133 int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
3135 u32 mcp_resp, mcp_param;
3137 return qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_INITIATE_PF_FLR, 0,
3138 &mcp_resp, &mcp_param);
3141 static int qed_mcp_resource_cmd(struct qed_hwfn *p_hwfn,
3142 struct qed_ptt *p_ptt,
3143 u32 param, u32 *p_mcp_resp, u32 *p_mcp_param)
3147 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_RESOURCE_CMD, param,
3148 p_mcp_resp, p_mcp_param);
3152 if (*p_mcp_resp == FW_MSG_CODE_UNSUPPORTED) {
3154 "The resource command is unsupported by the MFW\n");
3158 if (*p_mcp_param == RESOURCE_OPCODE_UNKNOWN_CMD) {
3159 u8 opcode = QED_MFW_GET_FIELD(param, RESOURCE_CMD_REQ_OPCODE);
3162 "The resource command is unknown to the MFW [param 0x%08x, opcode %d]\n",
3171 __qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
3172 struct qed_ptt *p_ptt,
3173 struct qed_resc_lock_params *p_params)
3175 u32 param = 0, mcp_resp, mcp_param;
3179 switch (p_params->timeout) {
3180 case QED_MCP_RESC_LOCK_TO_DEFAULT:
3181 opcode = RESOURCE_OPCODE_REQ;
3182 p_params->timeout = 0;
3184 case QED_MCP_RESC_LOCK_TO_NONE:
3185 opcode = RESOURCE_OPCODE_REQ_WO_AGING;
3186 p_params->timeout = 0;
3189 opcode = RESOURCE_OPCODE_REQ_W_AGING;
3193 QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource);
3194 QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode);
3195 QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_AGE, p_params->timeout);
3199 "Resource lock request: param 0x%08x [age %d, opcode %d, resource %d]\n",
3200 param, p_params->timeout, opcode, p_params->resource);
3202 /* Attempt to acquire the resource */
3203 rc = qed_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp, &mcp_param);
3207 /* Analyze the response */
3208 p_params->owner = QED_MFW_GET_FIELD(mcp_param, RESOURCE_CMD_RSP_OWNER);
3209 opcode = QED_MFW_GET_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE);
3213 "Resource lock response: mcp_param 0x%08x [opcode %d, owner %d]\n",
3214 mcp_param, opcode, p_params->owner);
3217 case RESOURCE_OPCODE_GNT:
3218 p_params->b_granted = true;
3220 case RESOURCE_OPCODE_BUSY:
3221 p_params->b_granted = false;
3225 "Unexpected opcode in resource lock response [mcp_param 0x%08x, opcode %d]\n",
3234 qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
3235 struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params)
3241 /* No need for an interval before the first iteration */
3243 if (p_params->sleep_b4_retry) {
3244 u16 retry_interval_in_ms =
3245 DIV_ROUND_UP(p_params->retry_interval,
3248 msleep(retry_interval_in_ms);
3250 udelay(p_params->retry_interval);
3254 rc = __qed_mcp_resc_lock(p_hwfn, p_ptt, p_params);
3258 if (p_params->b_granted)
3260 } while (retry_cnt++ < p_params->retry_num);
3266 qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn,
3267 struct qed_ptt *p_ptt,
3268 struct qed_resc_unlock_params *p_params)
3270 u32 param = 0, mcp_resp, mcp_param;
3274 opcode = p_params->b_force ? RESOURCE_OPCODE_FORCE_RELEASE
3275 : RESOURCE_OPCODE_RELEASE;
3276 QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_RESC, p_params->resource);
3277 QED_MFW_SET_FIELD(param, RESOURCE_CMD_REQ_OPCODE, opcode);
3279 DP_VERBOSE(p_hwfn, QED_MSG_SP,
3280 "Resource unlock request: param 0x%08x [opcode %d, resource %d]\n",
3281 param, opcode, p_params->resource);
3283 /* Attempt to release the resource */
3284 rc = qed_mcp_resource_cmd(p_hwfn, p_ptt, param, &mcp_resp, &mcp_param);
3288 /* Analyze the response */
3289 opcode = QED_MFW_GET_FIELD(mcp_param, RESOURCE_CMD_RSP_OPCODE);
3291 DP_VERBOSE(p_hwfn, QED_MSG_SP,
3292 "Resource unlock response: mcp_param 0x%08x [opcode %d]\n",
3296 case RESOURCE_OPCODE_RELEASED_PREVIOUS:
3298 "Resource unlock request for an already released resource [%d]\n",
3299 p_params->resource);
3301 case RESOURCE_OPCODE_RELEASED:
3302 p_params->b_released = true;
3304 case RESOURCE_OPCODE_WRONG_OWNER:
3305 p_params->b_released = false;
3309 "Unexpected opcode in resource unlock response [mcp_param 0x%08x, opcode %d]\n",
3317 void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock,
3318 struct qed_resc_unlock_params *p_unlock,
3320 resource, bool b_is_permanent)
3323 memset(p_lock, 0, sizeof(*p_lock));
3325 /* Permanent resources don't require aging, and there's no
3326 * point in trying to acquire them more than once since it's
3327 * unexpected another entity would release them.
3329 if (b_is_permanent) {
3330 p_lock->timeout = QED_MCP_RESC_LOCK_TO_NONE;
3332 p_lock->retry_num = QED_MCP_RESC_LOCK_RETRY_CNT_DFLT;
3333 p_lock->retry_interval =
3334 QED_MCP_RESC_LOCK_RETRY_VAL_DFLT;
3335 p_lock->sleep_b4_retry = true;
3338 p_lock->resource = resource;
3342 memset(p_unlock, 0, sizeof(*p_unlock));
3343 p_unlock->resource = resource;
3347 int qed_mcp_get_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
3352 rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_GET_MFW_FEATURE_SUPPORT,
3353 0, &mcp_resp, &p_hwfn->mcp_info->capabilities);
3355 DP_VERBOSE(p_hwfn, (QED_MSG_SP | NETIF_MSG_PROBE),
3356 "MFW supported features: %08x\n",
3357 p_hwfn->mcp_info->capabilities);
3362 int qed_mcp_set_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
3364 u32 mcp_resp, mcp_param, features;
3366 features = DRV_MB_PARAM_FEATURE_SUPPORT_PORT_EEE;
3368 return qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_FEATURE_SUPPORT,
3369 features, &mcp_resp, &mcp_param);