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_25G BIT(4)
64 #define QED_LINK_PARTNER_SPEED_40G BIT(5)
65 #define QED_LINK_PARTNER_SPEED_50G BIT(6)
66 #define QED_LINK_PARTNER_SPEED_100G BIT(7)
67 u32 partner_adv_speed;
69 bool partner_tx_flow_ctrl_en;
70 bool partner_rx_flow_ctrl_en;
72 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
73 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
74 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
80 struct qed_mcp_function_info {
83 enum qed_pci_personality protocol;
93 #define QED_MCP_VLAN_UNSET (0xffff)
97 struct qed_mcp_nvm_common {
104 struct qed_mcp_drv_version {
106 u8 name[MCP_DRV_VER_STR_SIZE - 4];
109 struct qed_mcp_lan_stats {
115 struct qed_mcp_fcoe_stats {
122 struct qed_mcp_iscsi_stats {
129 struct qed_mcp_rdma_stats {
136 enum qed_mcp_protocol_type {
143 union qed_mcp_protocol_stats {
144 struct qed_mcp_lan_stats lan_stats;
145 struct qed_mcp_fcoe_stats fcoe_stats;
146 struct qed_mcp_iscsi_stats iscsi_stats;
147 struct qed_mcp_rdma_stats rdma_stats;
151 * @brief - returns the link params of the hw function
155 * @returns pointer to link params
157 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
160 * @brief - return the link state of the hw function
164 * @returns pointer to link state
166 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
169 * @brief - return the link capabilities of the hw function
173 * @returns pointer to link capabilities
175 struct qed_mcp_link_capabilities
176 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
179 * @brief Request the MFW to set the the link according to 'link_input'.
183 * @param b_up - raise link if `true'. Reset link if `false'.
187 int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
188 struct qed_ptt *p_ptt,
192 * @brief Get the management firmware version value
196 * @param p_mfw_ver - mfw version value
197 * @param p_running_bundle_id - image id in nvram; Optional.
199 * @return int - 0 - operation was successful.
201 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
202 struct qed_ptt *p_ptt,
203 u32 *p_mfw_ver, u32 *p_running_bundle_id);
206 * @brief Get media type value of the port.
208 * @param cdev - qed dev pointer
209 * @param mfw_ver - media type value
212 * 0 - Operation was successul.
213 * -EBUSY - Operation failed
215 int qed_mcp_get_media_type(struct qed_dev *cdev,
219 * @brief General function for sending commands to the MCP
220 * mailbox. It acquire mutex lock for the entire
221 * operation, from sending the request until the MCP
222 * response. Waiting for MCP response will be checked up
223 * to 5 seconds every 5ms.
225 * @param p_hwfn - hw function
226 * @param p_ptt - PTT required for register access
227 * @param cmd - command to be sent to the MCP.
228 * @param param - Optional param
229 * @param o_mcp_resp - The MCP response code (exclude sequence).
230 * @param o_mcp_param- Optional parameter provided by the MCP
232 * @return int - 0 - operation
235 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
236 struct qed_ptt *p_ptt,
243 * @brief - drains the nig, allowing completion to pass in case of pauses.
244 * (Should be called only from sleepable context)
249 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
250 struct qed_ptt *p_ptt);
253 * @brief Get the flash size value
257 * @param p_flash_size - flash size in bytes to be filled.
259 * @return int - 0 - operation was successul.
261 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
262 struct qed_ptt *p_ptt,
266 * @brief Send driver version to MFW
270 * @param version - Version value
271 * @param name - Protocol driver name
273 * @return int - 0 - operation was successul.
276 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
277 struct qed_ptt *p_ptt,
278 struct qed_mcp_drv_version *p_ver);
281 * @brief Set LED status
285 * @param mode - LED mode
287 * @return int - 0 - operation was successful.
289 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
290 struct qed_ptt *p_ptt,
291 enum qed_led_mode mode);
294 * @brief Bist register test
296 * @param p_hwfn - hw function
297 * @param p_ptt - PTT required for register access
299 * @return int - 0 - operation was successful.
301 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
302 struct qed_ptt *p_ptt);
305 * @brief Bist clock test
307 * @param p_hwfn - hw function
308 * @param p_ptt - PTT required for register access
310 * @return int - 0 - operation was successful.
312 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
313 struct qed_ptt *p_ptt);
315 /* Using hwfn number (and not pf_num) is required since in CMT mode,
316 * same pf_num may be used by two different hwfn
317 * TODO - this shouldn't really be in .h file, but until all fields
318 * required during hw-init will be placed in their correct place in shmem
319 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
321 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
323 ((p_hwfn)->abs_pf_id & 1) << 3) : \
325 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
327 /* TODO - this is only correct as long as only BB is supported, and
328 * no port-swapping is implemented; Afterwards we'll need to fix it.
330 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
331 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
332 struct qed_mcp_info {
334 bool block_mb_sending;
341 struct qed_mcp_link_params link_input;
342 struct qed_mcp_link_state link_output;
343 struct qed_mcp_link_capabilities link_capabilities;
344 struct qed_mcp_function_info func_info;
351 struct qed_mcp_mb_params {
354 union drv_union_data *p_data_src;
355 union drv_union_data *p_data_dst;
361 * @brief Initialize the interface with the MCP
363 * @param p_hwfn - HW func
364 * @param p_ptt - PTT required for register access
368 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
369 struct qed_ptt *p_ptt);
372 * @brief Initialize the port interface with the MCP
376 * Can only be called after `num_ports_in_engines' is set
378 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
379 struct qed_ptt *p_ptt);
381 * @brief Releases resources allocated during the init process.
383 * @param p_hwfn - HW func
384 * @param p_ptt - PTT required for register access
389 int qed_mcp_free(struct qed_hwfn *p_hwfn);
392 * @brief This function is called from the DPC context. After
393 * pointing PTT to the mfw mb, check for events sent by the MCP
394 * to the driver and ack them. In case a critical event
395 * detected, it will be handled here, otherwise the work will be
396 * queued to a sleepable work-queue.
398 * @param p_hwfn - HW function
399 * @param p_ptt - PTT required for register access
400 * @return int - 0 - operation
403 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
404 struct qed_ptt *p_ptt);
407 * @brief Sends a LOAD_REQ to the MFW, and in case operation
408 * succeed, returns whether this PF is the first on the
409 * chip/engine/port or function. This function should be
410 * called when driver is ready to accept MFW events after
411 * Storms initializations are done.
413 * @param p_hwfn - hw function
414 * @param p_ptt - PTT required for register access
415 * @param p_load_code - The MCP response param containing one
417 * FW_MSG_CODE_DRV_LOAD_ENGINE
418 * FW_MSG_CODE_DRV_LOAD_PORT
419 * FW_MSG_CODE_DRV_LOAD_FUNCTION
421 * 0 - Operation was successul.
422 * -EBUSY - Operation failed
424 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
425 struct qed_ptt *p_ptt,
429 * @brief Read the MFW mailbox into Current buffer.
434 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
435 struct qed_ptt *p_ptt);
438 * @brief Ack to mfw that driver finished FLR process for VFs
442 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
444 * @param return int - 0 upon success.
446 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
447 struct qed_ptt *p_ptt, u32 *vfs_to_ack);
450 * @brief - calls during init to read shmem of all function-related info.
454 * @param return 0 upon success.
456 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
457 struct qed_ptt *p_ptt);
460 * @brief - Reset the MCP using mailbox command.
465 * @param return 0 upon success.
467 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
468 struct qed_ptt *p_ptt);
471 * @brief - Sends an NVM read command request to the MFW to get
476 * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
477 * DRV_MSG_CODE_NVM_READ_NVRAM commands
478 * @param param - [0:23] - Offset [24:31] - Size
479 * @param o_mcp_resp - MCP response
480 * @param o_mcp_param - MCP response param
481 * @param o_txn_size - Buffer size output
482 * @param o_buf - Pointer to the buffer returned by the MFW.
484 * @param return 0 upon success.
486 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
487 struct qed_ptt *p_ptt,
491 u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
494 * @brief indicates whether the MFW objects [under mcp_info] are accessible
498 * @return true iff MFW is running and mcp_info is initialized
500 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
503 * @brief request MFW to configure MSI-X for a VF
507 * @param vf_id - absolute inside engine
508 * @param num_sbs - number of entries to request
512 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
513 struct qed_ptt *p_ptt, u8 vf_id, u8 num);
516 * @brief - Halt the MCP.
521 * @param return 0 upon success.
523 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
526 * @brief - Wake up the MCP.
531 * @param return 0 upon success.
533 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
535 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
536 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
537 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
538 struct qed_ptt *p_ptt,
539 struct qed_mcp_link_state *p_link,
541 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
542 struct qed_ptt *p_ptt,
543 struct qed_mcp_link_state *p_link,
546 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
547 struct qed_ptt *p_ptt, u32 mask_parities);