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)
99 struct qed_mcp_nvm_common {
106 struct qed_mcp_drv_version {
108 u8 name[MCP_DRV_VER_STR_SIZE - 4];
111 struct qed_mcp_lan_stats {
117 struct qed_mcp_fcoe_stats {
124 struct qed_mcp_iscsi_stats {
131 struct qed_mcp_rdma_stats {
138 enum qed_mcp_protocol_type {
145 union qed_mcp_protocol_stats {
146 struct qed_mcp_lan_stats lan_stats;
147 struct qed_mcp_fcoe_stats fcoe_stats;
148 struct qed_mcp_iscsi_stats iscsi_stats;
149 struct qed_mcp_rdma_stats rdma_stats;
152 enum qed_ov_eswitch {
161 QED_OV_CLIENT_VENDOR_SPEC
164 enum qed_ov_driver_state {
165 QED_OV_DRIVER_STATE_NOT_LOADED,
166 QED_OV_DRIVER_STATE_DISABLED,
167 QED_OV_DRIVER_STATE_ACTIVE
177 * @brief - returns the link params of the hw function
181 * @returns pointer to link params
183 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
186 * @brief - return the link state of the hw function
190 * @returns pointer to link state
192 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
195 * @brief - return the link capabilities of the hw function
199 * @returns pointer to link capabilities
201 struct qed_mcp_link_capabilities
202 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
205 * @brief Request the MFW to set the the link according to 'link_input'.
209 * @param b_up - raise link if `true'. Reset link if `false'.
213 int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
214 struct qed_ptt *p_ptt,
218 * @brief Get the management firmware version value
222 * @param p_mfw_ver - mfw version value
223 * @param p_running_bundle_id - image id in nvram; Optional.
225 * @return int - 0 - operation was successful.
227 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
228 struct qed_ptt *p_ptt,
229 u32 *p_mfw_ver, u32 *p_running_bundle_id);
232 * @brief Get media type value of the port.
234 * @param cdev - qed dev pointer
235 * @param mfw_ver - media type value
238 * 0 - Operation was successul.
239 * -EBUSY - Operation failed
241 int qed_mcp_get_media_type(struct qed_dev *cdev,
245 * @brief General function for sending commands to the MCP
246 * mailbox. It acquire mutex lock for the entire
247 * operation, from sending the request until the MCP
248 * response. Waiting for MCP response will be checked up
249 * to 5 seconds every 5ms.
251 * @param p_hwfn - hw function
252 * @param p_ptt - PTT required for register access
253 * @param cmd - command to be sent to the MCP.
254 * @param param - Optional param
255 * @param o_mcp_resp - The MCP response code (exclude sequence).
256 * @param o_mcp_param- Optional parameter provided by the MCP
258 * @return int - 0 - operation
261 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
262 struct qed_ptt *p_ptt,
269 * @brief - drains the nig, allowing completion to pass in case of pauses.
270 * (Should be called only from sleepable context)
275 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
276 struct qed_ptt *p_ptt);
279 * @brief Get the flash size value
283 * @param p_flash_size - flash size in bytes to be filled.
285 * @return int - 0 - operation was successul.
287 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
288 struct qed_ptt *p_ptt,
292 * @brief Send driver version to MFW
296 * @param version - Version value
297 * @param name - Protocol driver name
299 * @return int - 0 - operation was successul.
302 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
303 struct qed_ptt *p_ptt,
304 struct qed_mcp_drv_version *p_ver);
307 * @brief Notify MFW about the change in base device properties
311 * @param client - qed client type
313 * @return int - 0 - operation was successful.
315 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
316 struct qed_ptt *p_ptt,
317 enum qed_ov_client client);
320 * @brief Notify MFW about the driver state
324 * @param drv_state - Driver state
326 * @return int - 0 - operation was successful.
328 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
329 struct qed_ptt *p_ptt,
330 enum qed_ov_driver_state drv_state);
333 * @brief Send MTU size to MFW
337 * @param mtu - MTU size
339 * @return int - 0 - operation was successful.
341 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
342 struct qed_ptt *p_ptt, u16 mtu);
345 * @brief Send MAC address to MFW
349 * @param mac - MAC address
351 * @return int - 0 - operation was successful.
353 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
354 struct qed_ptt *p_ptt, u8 *mac);
357 * @brief Send WOL mode to MFW
361 * @param wol - WOL mode
363 * @return int - 0 - operation was successful.
365 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
366 struct qed_ptt *p_ptt,
367 enum qed_ov_wol wol);
370 * @brief Set LED status
374 * @param mode - LED mode
376 * @return int - 0 - operation was successful.
378 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
379 struct qed_ptt *p_ptt,
380 enum qed_led_mode mode);
383 * @brief Read from nvm
386 * @param addr - nvm offset
387 * @param p_buf - nvm read buffer
388 * @param len - buffer len
390 * @return int - 0 - operation was successful.
392 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
395 * @brief Bist register test
397 * @param p_hwfn - hw function
398 * @param p_ptt - PTT required for register access
400 * @return int - 0 - operation was successful.
402 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
403 struct qed_ptt *p_ptt);
406 * @brief Bist clock test
408 * @param p_hwfn - hw function
409 * @param p_ptt - PTT required for register access
411 * @return int - 0 - operation was successful.
413 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
414 struct qed_ptt *p_ptt);
417 * @brief Bist nvm test - get number of images
419 * @param p_hwfn - hw function
420 * @param p_ptt - PTT required for register access
421 * @param num_images - number of images if operation was
422 * successful. 0 if not.
424 * @return int - 0 - operation was successful.
426 int qed_mcp_bist_nvm_test_get_num_images(struct qed_hwfn *p_hwfn,
427 struct qed_ptt *p_ptt,
431 * @brief Bist nvm test - get image attributes by index
433 * @param p_hwfn - hw function
434 * @param p_ptt - PTT required for register access
435 * @param p_image_att - Attributes of image
436 * @param image_index - Index of image to get information for
438 * @return int - 0 - operation was successful.
440 int qed_mcp_bist_nvm_test_get_image_att(struct qed_hwfn *p_hwfn,
441 struct qed_ptt *p_ptt,
442 struct bist_nvm_image_att *p_image_att,
445 /* Using hwfn number (and not pf_num) is required since in CMT mode,
446 * same pf_num may be used by two different hwfn
447 * TODO - this shouldn't really be in .h file, but until all fields
448 * required during hw-init will be placed in their correct place in shmem
449 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
451 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
453 ((p_hwfn)->abs_pf_id & 1) << 3) : \
455 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
457 /* TODO - this is only correct as long as only BB is supported, and
458 * no port-swapping is implemented; Afterwards we'll need to fix it.
460 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
461 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
462 struct qed_mcp_info {
464 bool block_mb_sending;
471 struct qed_mcp_link_params link_input;
472 struct qed_mcp_link_state link_output;
473 struct qed_mcp_link_capabilities link_capabilities;
474 struct qed_mcp_function_info func_info;
481 struct qed_mcp_mb_params {
484 union drv_union_data *p_data_src;
485 union drv_union_data *p_data_dst;
491 * @brief Initialize the interface with the MCP
493 * @param p_hwfn - HW func
494 * @param p_ptt - PTT required for register access
498 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
499 struct qed_ptt *p_ptt);
502 * @brief Initialize the port interface with the MCP
506 * Can only be called after `num_ports_in_engines' is set
508 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
509 struct qed_ptt *p_ptt);
511 * @brief Releases resources allocated during the init process.
513 * @param p_hwfn - HW func
514 * @param p_ptt - PTT required for register access
519 int qed_mcp_free(struct qed_hwfn *p_hwfn);
522 * @brief This function is called from the DPC context. After
523 * pointing PTT to the mfw mb, check for events sent by the MCP
524 * to the driver and ack them. In case a critical event
525 * detected, it will be handled here, otherwise the work will be
526 * queued to a sleepable work-queue.
528 * @param p_hwfn - HW function
529 * @param p_ptt - PTT required for register access
530 * @return int - 0 - operation
533 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
534 struct qed_ptt *p_ptt);
537 * @brief Sends a LOAD_REQ to the MFW, and in case operation
538 * succeed, returns whether this PF is the first on the
539 * chip/engine/port or function. This function should be
540 * called when driver is ready to accept MFW events after
541 * Storms initializations are done.
543 * @param p_hwfn - hw function
544 * @param p_ptt - PTT required for register access
545 * @param p_load_code - The MCP response param containing one
547 * FW_MSG_CODE_DRV_LOAD_ENGINE
548 * FW_MSG_CODE_DRV_LOAD_PORT
549 * FW_MSG_CODE_DRV_LOAD_FUNCTION
551 * 0 - Operation was successul.
552 * -EBUSY - Operation failed
554 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
555 struct qed_ptt *p_ptt,
559 * @brief Read the MFW mailbox into Current buffer.
564 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
565 struct qed_ptt *p_ptt);
568 * @brief Ack to mfw that driver finished FLR process for VFs
572 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
574 * @param return int - 0 upon success.
576 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
577 struct qed_ptt *p_ptt, u32 *vfs_to_ack);
580 * @brief - calls during init to read shmem of all function-related info.
584 * @param return 0 upon success.
586 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
587 struct qed_ptt *p_ptt);
590 * @brief - Reset the MCP using mailbox command.
595 * @param return 0 upon success.
597 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
598 struct qed_ptt *p_ptt);
601 * @brief - Sends an NVM read command request to the MFW to get
606 * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
607 * DRV_MSG_CODE_NVM_READ_NVRAM commands
608 * @param param - [0:23] - Offset [24:31] - Size
609 * @param o_mcp_resp - MCP response
610 * @param o_mcp_param - MCP response param
611 * @param o_txn_size - Buffer size output
612 * @param o_buf - Pointer to the buffer returned by the MFW.
614 * @param return 0 upon success.
616 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
617 struct qed_ptt *p_ptt,
621 u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
624 * @brief indicates whether the MFW objects [under mcp_info] are accessible
628 * @return true iff MFW is running and mcp_info is initialized
630 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
633 * @brief request MFW to configure MSI-X for a VF
637 * @param vf_id - absolute inside engine
638 * @param num_sbs - number of entries to request
642 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
643 struct qed_ptt *p_ptt, u8 vf_id, u8 num);
646 * @brief - Halt the MCP.
651 * @param return 0 upon success.
653 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
656 * @brief - Wake up the MCP.
661 * @param return 0 upon success.
663 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
665 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
666 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
667 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
668 struct qed_ptt *p_ptt,
669 struct qed_mcp_link_state *p_link,
671 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
672 struct qed_ptt *p_ptt,
673 struct qed_mcp_link_state *p_link,
676 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
677 struct qed_ptt *p_ptt, u32 mask_parities);
680 * @brief Send eswitch mode to MFW
684 * @param eswitch - eswitch mode
686 * @return int - 0 - operation was successful.
688 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
689 struct qed_ptt *p_ptt,
690 enum qed_ov_eswitch eswitch);