1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
12 #include <linux/types.h>
13 #include <linux/delay.h>
14 #include <linux/mutex.h>
15 #include <linux/slab.h>
18 struct qed_mcp_function_info {
21 enum qed_pci_personality protocol;
31 #define QED_MCP_VLAN_UNSET (0xffff)
35 struct qed_mcp_nvm_common {
42 struct qed_mcp_drv_version {
44 u8 name[MCP_DRV_VER_STR_SIZE - 4];
48 * @brief Get the management firmware version value
50 * @param cdev - qed dev pointer
51 * @param mfw_ver - mfw version value
53 * @return int - 0 - operation was successul.
55 int qed_mcp_get_mfw_ver(struct qed_dev *cdev,
59 * @brief General function for sending commands to the MCP
60 * mailbox. It acquire mutex lock for the entire
61 * operation, from sending the request until the MCP
62 * response. Waiting for MCP response will be checked up
63 * to 5 seconds every 5ms.
65 * @param p_hwfn - hw function
66 * @param p_ptt - PTT required for register access
67 * @param cmd - command to be sent to the MCP.
68 * @param param - Optional param
69 * @param o_mcp_resp - The MCP response code (exclude sequence).
70 * @param o_mcp_param- Optional parameter provided by the MCP
72 * @return int - 0 - operation
75 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
76 struct qed_ptt *p_ptt,
83 * @brief - drains the nig, allowing completion to pass in case of pauses.
84 * (Should be called only from sleepable context)
89 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
90 struct qed_ptt *p_ptt);
93 * @brief Send driver version to MFW
97 * @param version - Version value
98 * @param name - Protocol driver name
100 * @return int - 0 - operation was successul.
103 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
104 struct qed_ptt *p_ptt,
105 struct qed_mcp_drv_version *p_ver);
107 /* Using hwfn number (and not pf_num) is required since in CMT mode,
108 * same pf_num may be used by two different hwfn
109 * TODO - this shouldn't really be in .h file, but until all fields
110 * required during hw-init will be placed in their correct place in shmem
111 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
113 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
115 ((p_hwfn)->abs_pf_id & 1) << 3) : \
117 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
119 /* TODO - this is only correct as long as only BB is supported, and
120 * no port-swapping is implemented; Afterwards we'll need to fix it.
122 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
123 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
124 struct qed_mcp_info {
125 struct mutex mutex; /* MCP access lock */
132 struct qed_mcp_function_info func_info;
141 * @brief Initialize the interface with the MCP
143 * @param p_hwfn - HW func
144 * @param p_ptt - PTT required for register access
148 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
149 struct qed_ptt *p_ptt);
152 * @brief Initialize the port interface with the MCP
156 * Can only be called after `num_ports_in_engines' is set
158 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
159 struct qed_ptt *p_ptt);
161 * @brief Releases resources allocated during the init process.
163 * @param p_hwfn - HW func
164 * @param p_ptt - PTT required for register access
169 int qed_mcp_free(struct qed_hwfn *p_hwfn);
172 * @brief Sends a LOAD_REQ to the MFW, and in case operation
173 * succeed, returns whether this PF is the first on the
174 * chip/engine/port or function. This function should be
175 * called when driver is ready to accept MFW events after
176 * Storms initializations are done.
178 * @param p_hwfn - hw function
179 * @param p_ptt - PTT required for register access
180 * @param p_load_code - The MCP response param containing one
182 * FW_MSG_CODE_DRV_LOAD_ENGINE
183 * FW_MSG_CODE_DRV_LOAD_PORT
184 * FW_MSG_CODE_DRV_LOAD_FUNCTION
186 * 0 - Operation was successul.
187 * -EBUSY - Operation failed
189 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
190 struct qed_ptt *p_ptt,
194 * @brief Read the MFW mailbox into Current buffer.
199 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
200 struct qed_ptt *p_ptt);
203 * @brief - calls during init to read shmem of all function-related info.
207 * @param return 0 upon success.
209 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
210 struct qed_ptt *p_ptt);
213 * @brief - Reset the MCP using mailbox command.
218 * @param return 0 upon success.
220 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
221 struct qed_ptt *p_ptt);
224 * @brief indicates whether the MFW objects [under mcp_info] are accessible
228 * @return true iff MFW is running and mcp_info is initialized
230 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);