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/slab.h>
15 #include <linux/spinlock.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 {
45 /* Actual link speed in Mb/s */
48 /* PF max speed in Mb/s, deduced from line_speed
49 * according to PF max bandwidth configuration.
56 bool parallel_detection;
59 #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
60 #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
61 #define QED_LINK_PARTNER_SPEED_10G BIT(2)
62 #define QED_LINK_PARTNER_SPEED_20G BIT(3)
63 #define QED_LINK_PARTNER_SPEED_40G BIT(4)
64 #define QED_LINK_PARTNER_SPEED_50G BIT(5)
65 #define QED_LINK_PARTNER_SPEED_100G BIT(6)
66 u32 partner_adv_speed;
68 bool partner_tx_flow_ctrl_en;
69 bool partner_rx_flow_ctrl_en;
71 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
72 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
73 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
79 struct qed_mcp_function_info {
82 enum qed_pci_personality protocol;
92 #define QED_MCP_VLAN_UNSET (0xffff)
96 struct qed_mcp_nvm_common {
103 struct qed_mcp_drv_version {
105 u8 name[MCP_DRV_VER_STR_SIZE - 4];
109 * @brief - returns the link params of the hw function
113 * @returns pointer to link params
115 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
118 * @brief - return the link state of the hw function
122 * @returns pointer to link state
124 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
127 * @brief - return the link capabilities of the hw function
131 * @returns pointer to link capabilities
133 struct qed_mcp_link_capabilities
134 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
137 * @brief Request the MFW to set the the link according to 'link_input'.
141 * @param b_up - raise link if `true'. Reset link if `false'.
145 int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
146 struct qed_ptt *p_ptt,
150 * @brief Get the management firmware version value
154 * @param p_mfw_ver - mfw version value
155 * @param p_running_bundle_id - image id in nvram; Optional.
157 * @return int - 0 - operation was successful.
159 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
160 struct qed_ptt *p_ptt,
161 u32 *p_mfw_ver, u32 *p_running_bundle_id);
164 * @brief Get media type value of the port.
166 * @param cdev - qed dev pointer
167 * @param mfw_ver - media type value
170 * 0 - Operation was successul.
171 * -EBUSY - Operation failed
173 int qed_mcp_get_media_type(struct qed_dev *cdev,
177 * @brief General function for sending commands to the MCP
178 * mailbox. It acquire mutex lock for the entire
179 * operation, from sending the request until the MCP
180 * response. Waiting for MCP response will be checked up
181 * to 5 seconds every 5ms.
183 * @param p_hwfn - hw function
184 * @param p_ptt - PTT required for register access
185 * @param cmd - command to be sent to the MCP.
186 * @param param - Optional param
187 * @param o_mcp_resp - The MCP response code (exclude sequence).
188 * @param o_mcp_param- Optional parameter provided by the MCP
190 * @return int - 0 - operation
193 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
194 struct qed_ptt *p_ptt,
201 * @brief - drains the nig, allowing completion to pass in case of pauses.
202 * (Should be called only from sleepable context)
207 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
208 struct qed_ptt *p_ptt);
211 * @brief Get the flash size value
215 * @param p_flash_size - flash size in bytes to be filled.
217 * @return int - 0 - operation was successul.
219 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
220 struct qed_ptt *p_ptt,
224 * @brief Send driver version to MFW
228 * @param version - Version value
229 * @param name - Protocol driver name
231 * @return int - 0 - operation was successul.
234 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
235 struct qed_ptt *p_ptt,
236 struct qed_mcp_drv_version *p_ver);
239 * @brief Set LED status
243 * @param mode - LED mode
245 * @return int - 0 - operation was successful.
247 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
248 struct qed_ptt *p_ptt,
249 enum qed_led_mode mode);
252 * @brief Bist register test
254 * @param p_hwfn - hw function
255 * @param p_ptt - PTT required for register access
257 * @return int - 0 - operation was successful.
259 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
260 struct qed_ptt *p_ptt);
263 * @brief Bist clock test
265 * @param p_hwfn - hw function
266 * @param p_ptt - PTT required for register access
268 * @return int - 0 - operation was successful.
270 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
271 struct qed_ptt *p_ptt);
273 /* Using hwfn number (and not pf_num) is required since in CMT mode,
274 * same pf_num may be used by two different hwfn
275 * TODO - this shouldn't really be in .h file, but until all fields
276 * required during hw-init will be placed in their correct place in shmem
277 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
279 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
281 ((p_hwfn)->abs_pf_id & 1) << 3) : \
283 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
285 /* TODO - this is only correct as long as only BB is supported, and
286 * no port-swapping is implemented; Afterwards we'll need to fix it.
288 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
289 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
290 struct qed_mcp_info {
292 bool block_mb_sending;
299 struct qed_mcp_link_params link_input;
300 struct qed_mcp_link_state link_output;
301 struct qed_mcp_link_capabilities link_capabilities;
302 struct qed_mcp_function_info func_info;
309 struct qed_mcp_mb_params {
312 union drv_union_data *p_data_src;
313 union drv_union_data *p_data_dst;
319 * @brief Initialize the interface with the MCP
321 * @param p_hwfn - HW func
322 * @param p_ptt - PTT required for register access
326 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
327 struct qed_ptt *p_ptt);
330 * @brief Initialize the port interface with the MCP
334 * Can only be called after `num_ports_in_engines' is set
336 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
337 struct qed_ptt *p_ptt);
339 * @brief Releases resources allocated during the init process.
341 * @param p_hwfn - HW func
342 * @param p_ptt - PTT required for register access
347 int qed_mcp_free(struct qed_hwfn *p_hwfn);
350 * @brief This function is called from the DPC context. After
351 * pointing PTT to the mfw mb, check for events sent by the MCP
352 * to the driver and ack them. In case a critical event
353 * detected, it will be handled here, otherwise the work will be
354 * queued to a sleepable work-queue.
356 * @param p_hwfn - HW function
357 * @param p_ptt - PTT required for register access
358 * @return int - 0 - operation
361 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
362 struct qed_ptt *p_ptt);
365 * @brief Sends a LOAD_REQ to the MFW, and in case operation
366 * succeed, returns whether this PF is the first on the
367 * chip/engine/port or function. This function should be
368 * called when driver is ready to accept MFW events after
369 * Storms initializations are done.
371 * @param p_hwfn - hw function
372 * @param p_ptt - PTT required for register access
373 * @param p_load_code - The MCP response param containing one
375 * FW_MSG_CODE_DRV_LOAD_ENGINE
376 * FW_MSG_CODE_DRV_LOAD_PORT
377 * FW_MSG_CODE_DRV_LOAD_FUNCTION
379 * 0 - Operation was successul.
380 * -EBUSY - Operation failed
382 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
383 struct qed_ptt *p_ptt,
387 * @brief Read the MFW mailbox into Current buffer.
392 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
393 struct qed_ptt *p_ptt);
396 * @brief - calls during init to read shmem of all function-related info.
400 * @param return 0 upon success.
402 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
403 struct qed_ptt *p_ptt);
406 * @brief - Reset the MCP using mailbox command.
411 * @param return 0 upon success.
413 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
414 struct qed_ptt *p_ptt);
417 * @brief indicates whether the MFW objects [under mcp_info] are accessible
421 * @return true iff MFW is running and mcp_info is initialized
423 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
426 * @brief request MFW to configure MSI-X for a VF
430 * @param vf_id - absolute inside engine
431 * @param num_sbs - number of entries to request
435 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
436 struct qed_ptt *p_ptt, u8 vf_id, u8 num);
438 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
439 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
440 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
441 struct qed_ptt *p_ptt,
442 struct qed_mcp_link_state *p_link,
444 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
445 struct qed_ptt *p_ptt,
446 struct qed_mcp_link_state *p_link,