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_link_speed_params {
20 u32 advertised_speeds; /* bitmask of DRV_SPEED_CAPABILITY */
21 u32 forced_speed; /* In Mb/s */
24 struct qed_mcp_link_pause_params {
30 struct qed_mcp_link_params {
31 struct qed_mcp_link_speed_params speed;
32 struct qed_mcp_link_pause_params pause;
36 struct qed_mcp_link_capabilities {
37 u32 speed_capabilities;
40 struct qed_mcp_link_state {
43 u32 speed; /* In Mb/s */
48 bool parallel_detection;
51 #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
52 #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
53 #define QED_LINK_PARTNER_SPEED_10G BIT(2)
54 #define QED_LINK_PARTNER_SPEED_20G BIT(3)
55 #define QED_LINK_PARTNER_SPEED_40G BIT(4)
56 #define QED_LINK_PARTNER_SPEED_50G BIT(5)
57 #define QED_LINK_PARTNER_SPEED_100G BIT(6)
58 u32 partner_adv_speed;
60 bool partner_tx_flow_ctrl_en;
61 bool partner_rx_flow_ctrl_en;
63 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
64 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
65 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
71 struct qed_mcp_function_info {
74 enum qed_pci_personality protocol;
84 #define QED_MCP_VLAN_UNSET (0xffff)
88 struct qed_mcp_nvm_common {
95 struct qed_mcp_drv_version {
97 u8 name[MCP_DRV_VER_STR_SIZE - 4];
101 * @brief - returns the link params of the hw function
105 * @returns pointer to link params
107 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
110 * @brief - return the link state of the hw function
114 * @returns pointer to link state
116 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
119 * @brief - return the link capabilities of the hw function
123 * @returns pointer to link capabilities
125 struct qed_mcp_link_capabilities
126 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
129 * @brief Request the MFW to set the the link according to 'link_input'.
133 * @param b_up - raise link if `true'. Reset link if `false'.
137 int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
138 struct qed_ptt *p_ptt,
142 * @brief Get the management firmware version value
144 * @param cdev - qed dev pointer
145 * @param mfw_ver - mfw version value
147 * @return int - 0 - operation was successul.
149 int qed_mcp_get_mfw_ver(struct qed_dev *cdev,
153 * @brief Get media type value of the port.
155 * @param cdev - qed dev pointer
156 * @param mfw_ver - media type value
159 * 0 - Operation was successul.
160 * -EBUSY - Operation failed
162 int qed_mcp_get_media_type(struct qed_dev *cdev,
166 * @brief General function for sending commands to the MCP
167 * mailbox. It acquire mutex lock for the entire
168 * operation, from sending the request until the MCP
169 * response. Waiting for MCP response will be checked up
170 * to 5 seconds every 5ms.
172 * @param p_hwfn - hw function
173 * @param p_ptt - PTT required for register access
174 * @param cmd - command to be sent to the MCP.
175 * @param param - Optional param
176 * @param o_mcp_resp - The MCP response code (exclude sequence).
177 * @param o_mcp_param- Optional parameter provided by the MCP
179 * @return int - 0 - operation
182 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
183 struct qed_ptt *p_ptt,
190 * @brief - drains the nig, allowing completion to pass in case of pauses.
191 * (Should be called only from sleepable context)
196 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
197 struct qed_ptt *p_ptt);
200 * @brief Get the flash size value
204 * @param p_flash_size - flash size in bytes to be filled.
206 * @return int - 0 - operation was successul.
208 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
209 struct qed_ptt *p_ptt,
213 * @brief Send driver version to MFW
217 * @param version - Version value
218 * @param name - Protocol driver name
220 * @return int - 0 - operation was successul.
223 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
224 struct qed_ptt *p_ptt,
225 struct qed_mcp_drv_version *p_ver);
227 /* Using hwfn number (and not pf_num) is required since in CMT mode,
228 * same pf_num may be used by two different hwfn
229 * TODO - this shouldn't really be in .h file, but until all fields
230 * required during hw-init will be placed in their correct place in shmem
231 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
233 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
235 ((p_hwfn)->abs_pf_id & 1) << 3) : \
237 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
239 /* TODO - this is only correct as long as only BB is supported, and
240 * no port-swapping is implemented; Afterwards we'll need to fix it.
242 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
243 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
244 struct qed_mcp_info {
245 struct mutex mutex; /* MCP access lock */
252 struct qed_mcp_link_params link_input;
253 struct qed_mcp_link_state link_output;
254 struct qed_mcp_link_capabilities link_capabilities;
255 struct qed_mcp_function_info func_info;
263 * @brief Initialize the interface with the MCP
265 * @param p_hwfn - HW func
266 * @param p_ptt - PTT required for register access
270 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
271 struct qed_ptt *p_ptt);
274 * @brief Initialize the port interface with the MCP
278 * Can only be called after `num_ports_in_engines' is set
280 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
281 struct qed_ptt *p_ptt);
283 * @brief Releases resources allocated during the init process.
285 * @param p_hwfn - HW func
286 * @param p_ptt - PTT required for register access
291 int qed_mcp_free(struct qed_hwfn *p_hwfn);
294 * @brief This function is called from the DPC context. After
295 * pointing PTT to the mfw mb, check for events sent by the MCP
296 * to the driver and ack them. In case a critical event
297 * detected, it will be handled here, otherwise the work will be
298 * queued to a sleepable work-queue.
300 * @param p_hwfn - HW function
301 * @param p_ptt - PTT required for register access
302 * @return int - 0 - operation
305 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
306 struct qed_ptt *p_ptt);
309 * @brief Sends a LOAD_REQ to the MFW, and in case operation
310 * succeed, returns whether this PF is the first on the
311 * chip/engine/port or function. This function should be
312 * called when driver is ready to accept MFW events after
313 * Storms initializations are done.
315 * @param p_hwfn - hw function
316 * @param p_ptt - PTT required for register access
317 * @param p_load_code - The MCP response param containing one
319 * FW_MSG_CODE_DRV_LOAD_ENGINE
320 * FW_MSG_CODE_DRV_LOAD_PORT
321 * FW_MSG_CODE_DRV_LOAD_FUNCTION
323 * 0 - Operation was successul.
324 * -EBUSY - Operation failed
326 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
327 struct qed_ptt *p_ptt,
331 * @brief Read the MFW mailbox into Current buffer.
336 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
337 struct qed_ptt *p_ptt);
340 * @brief - calls during init to read shmem of all function-related info.
344 * @param return 0 upon success.
346 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
347 struct qed_ptt *p_ptt);
350 * @brief - Reset the MCP using mailbox command.
355 * @param return 0 upon success.
357 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
358 struct qed_ptt *p_ptt);
361 * @brief indicates whether the MFW objects [under mcp_info] are accessible
365 * @return true iff MFW is running and mcp_info is initialized
367 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);