1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/types.h>
37 #include <linux/delay.h>
38 #include <linux/slab.h>
39 #include <linux/spinlock.h>
40 #include <linux/qed/qed_fcoe_if.h>
42 #include "qed_dev_api.h"
44 struct qed_mcp_link_speed_params {
46 u32 advertised_speeds; /* bitmask of DRV_SPEED_CAPABILITY */
47 u32 forced_speed; /* In Mb/s */
50 struct qed_mcp_link_pause_params {
56 struct qed_mcp_link_params {
57 struct qed_mcp_link_speed_params speed;
58 struct qed_mcp_link_pause_params pause;
62 struct qed_mcp_link_capabilities {
63 u32 speed_capabilities;
64 bool default_speed_autoneg;
67 struct qed_mcp_link_state {
72 /* Actual link speed in Mb/s */
75 /* PF max speed in Mb/s, deduced from line_speed
76 * according to PF max bandwidth configuration.
83 bool parallel_detection;
86 #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
87 #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
88 #define QED_LINK_PARTNER_SPEED_10G BIT(2)
89 #define QED_LINK_PARTNER_SPEED_20G BIT(3)
90 #define QED_LINK_PARTNER_SPEED_25G BIT(4)
91 #define QED_LINK_PARTNER_SPEED_40G BIT(5)
92 #define QED_LINK_PARTNER_SPEED_50G BIT(6)
93 #define QED_LINK_PARTNER_SPEED_100G BIT(7)
94 u32 partner_adv_speed;
96 bool partner_tx_flow_ctrl_en;
97 bool partner_rx_flow_ctrl_en;
99 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
100 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
101 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
102 u8 partner_adv_pause;
107 struct qed_mcp_function_info {
110 enum qed_pci_personality protocol;
120 #define QED_MCP_VLAN_UNSET (0xffff)
126 struct qed_mcp_nvm_common {
133 struct qed_mcp_drv_version {
135 u8 name[MCP_DRV_VER_STR_SIZE - 4];
138 struct qed_mcp_lan_stats {
144 struct qed_mcp_fcoe_stats {
151 struct qed_mcp_iscsi_stats {
158 struct qed_mcp_rdma_stats {
165 enum qed_mcp_protocol_type {
172 union qed_mcp_protocol_stats {
173 struct qed_mcp_lan_stats lan_stats;
174 struct qed_mcp_fcoe_stats fcoe_stats;
175 struct qed_mcp_iscsi_stats iscsi_stats;
176 struct qed_mcp_rdma_stats rdma_stats;
179 enum qed_ov_eswitch {
188 QED_OV_CLIENT_VENDOR_SPEC
191 enum qed_ov_driver_state {
192 QED_OV_DRIVER_STATE_NOT_LOADED,
193 QED_OV_DRIVER_STATE_DISABLED,
194 QED_OV_DRIVER_STATE_ACTIVE
204 * @brief - returns the link params of the hw function
208 * @returns pointer to link params
210 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
213 * @brief - return the link state of the hw function
217 * @returns pointer to link state
219 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
222 * @brief - return the link capabilities of the hw function
226 * @returns pointer to link capabilities
228 struct qed_mcp_link_capabilities
229 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
232 * @brief Request the MFW to set the the link according to 'link_input'.
236 * @param b_up - raise link if `true'. Reset link if `false'.
240 int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
241 struct qed_ptt *p_ptt,
245 * @brief Get the management firmware version value
249 * @param p_mfw_ver - mfw version value
250 * @param p_running_bundle_id - image id in nvram; Optional.
252 * @return int - 0 - operation was successful.
254 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
255 struct qed_ptt *p_ptt,
256 u32 *p_mfw_ver, u32 *p_running_bundle_id);
259 * @brief Get the MBI version value
263 * @param p_mbi_ver - A pointer to a variable to be filled with the MBI version.
265 * @return int - 0 - operation was successful.
267 int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
268 struct qed_ptt *p_ptt, u32 *p_mbi_ver);
271 * @brief Get media type value of the port.
273 * @param cdev - qed dev pointer
274 * @param mfw_ver - media type value
277 * 0 - Operation was successul.
278 * -EBUSY - Operation failed
280 int qed_mcp_get_media_type(struct qed_dev *cdev,
284 * @brief General function for sending commands to the MCP
285 * mailbox. It acquire mutex lock for the entire
286 * operation, from sending the request until the MCP
287 * response. Waiting for MCP response will be checked up
288 * to 5 seconds every 5ms.
290 * @param p_hwfn - hw function
291 * @param p_ptt - PTT required for register access
292 * @param cmd - command to be sent to the MCP.
293 * @param param - Optional param
294 * @param o_mcp_resp - The MCP response code (exclude sequence).
295 * @param o_mcp_param- Optional parameter provided by the MCP
297 * @return int - 0 - operation
300 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
301 struct qed_ptt *p_ptt,
308 * @brief - drains the nig, allowing completion to pass in case of pauses.
309 * (Should be called only from sleepable context)
314 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
315 struct qed_ptt *p_ptt);
318 * @brief Get the flash size value
322 * @param p_flash_size - flash size in bytes to be filled.
324 * @return int - 0 - operation was successul.
326 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
327 struct qed_ptt *p_ptt,
331 * @brief Send driver version to MFW
335 * @param version - Version value
336 * @param name - Protocol driver name
338 * @return int - 0 - operation was successul.
341 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
342 struct qed_ptt *p_ptt,
343 struct qed_mcp_drv_version *p_ver);
346 * @brief Notify MFW about the change in base device properties
350 * @param client - qed client type
352 * @return int - 0 - operation was successful.
354 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
355 struct qed_ptt *p_ptt,
356 enum qed_ov_client client);
359 * @brief Notify MFW about the driver state
363 * @param drv_state - Driver state
365 * @return int - 0 - operation was successful.
367 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
368 struct qed_ptt *p_ptt,
369 enum qed_ov_driver_state drv_state);
372 * @brief Send MTU size to MFW
376 * @param mtu - MTU size
378 * @return int - 0 - operation was successful.
380 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
381 struct qed_ptt *p_ptt, u16 mtu);
384 * @brief Send MAC address to MFW
388 * @param mac - MAC address
390 * @return int - 0 - operation was successful.
392 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
393 struct qed_ptt *p_ptt, u8 *mac);
396 * @brief Send WOL mode to MFW
400 * @param wol - WOL mode
402 * @return int - 0 - operation was successful.
404 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
405 struct qed_ptt *p_ptt,
406 enum qed_ov_wol wol);
409 * @brief Set LED status
413 * @param mode - LED mode
415 * @return int - 0 - operation was successful.
417 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
418 struct qed_ptt *p_ptt,
419 enum qed_led_mode mode);
422 * @brief Read from nvm
425 * @param addr - nvm offset
426 * @param p_buf - nvm read buffer
427 * @param len - buffer len
429 * @return int - 0 - operation was successful.
431 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
433 struct qed_nvm_image_att {
439 * @brief Allows reading a whole nvram image
443 * @param image_id - image requested for reading
444 * @param p_buffer - allocated buffer into which to fill data
445 * @param buffer_len - length of the allocated buffer.
447 * @return 0 iff p_buffer now contains the nvram image.
449 int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn,
450 struct qed_ptt *p_ptt,
451 enum qed_nvm_images image_id,
452 u8 *p_buffer, u32 buffer_len);
455 * @brief Bist register test
457 * @param p_hwfn - hw function
458 * @param p_ptt - PTT required for register access
460 * @return int - 0 - operation was successful.
462 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
463 struct qed_ptt *p_ptt);
466 * @brief Bist clock test
468 * @param p_hwfn - hw function
469 * @param p_ptt - PTT required for register access
471 * @return int - 0 - operation was successful.
473 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
474 struct qed_ptt *p_ptt);
477 * @brief Bist nvm test - get number of images
479 * @param p_hwfn - hw function
480 * @param p_ptt - PTT required for register access
481 * @param num_images - number of images if operation was
482 * successful. 0 if not.
484 * @return int - 0 - operation was successful.
486 int qed_mcp_bist_nvm_test_get_num_images(struct qed_hwfn *p_hwfn,
487 struct qed_ptt *p_ptt,
491 * @brief Bist nvm test - get image attributes by index
493 * @param p_hwfn - hw function
494 * @param p_ptt - PTT required for register access
495 * @param p_image_att - Attributes of image
496 * @param image_index - Index of image to get information for
498 * @return int - 0 - operation was successful.
500 int qed_mcp_bist_nvm_test_get_image_att(struct qed_hwfn *p_hwfn,
501 struct qed_ptt *p_ptt,
502 struct bist_nvm_image_att *p_image_att,
505 /* Using hwfn number (and not pf_num) is required since in CMT mode,
506 * same pf_num may be used by two different hwfn
507 * TODO - this shouldn't really be in .h file, but until all fields
508 * required during hw-init will be placed in their correct place in shmem
509 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
511 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
513 ((p_hwfn)->abs_pf_id & 1) << 3) : \
515 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
517 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
518 ((_p_hwfn)->cdev->num_ports_in_engine * \
519 qed_device_num_engines((_p_hwfn)->cdev)))
521 struct qed_mcp_info {
522 /* List for mailbox commands which were sent and wait for a response */
523 struct list_head cmd_list;
525 /* Spinlock used for protecting the access to the mailbox commands list
526 * and the sending of the commands.
530 /* Spinlock used for syncing SW link-changes and link-changes
531 * originating from attention context.
533 spinlock_t link_lock;
534 bool block_mb_sending;
541 struct qed_mcp_link_params link_input;
542 struct qed_mcp_link_state link_output;
543 struct qed_mcp_link_capabilities link_capabilities;
544 struct qed_mcp_function_info func_info;
551 struct qed_mcp_mb_params {
563 * @brief Initialize the interface with the MCP
565 * @param p_hwfn - HW func
566 * @param p_ptt - PTT required for register access
570 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
571 struct qed_ptt *p_ptt);
574 * @brief Initialize the port interface with the MCP
578 * Can only be called after `num_ports_in_engines' is set
580 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
581 struct qed_ptt *p_ptt);
583 * @brief Releases resources allocated during the init process.
585 * @param p_hwfn - HW func
586 * @param p_ptt - PTT required for register access
591 int qed_mcp_free(struct qed_hwfn *p_hwfn);
594 * @brief This function is called from the DPC context. After
595 * pointing PTT to the mfw mb, check for events sent by the MCP
596 * to the driver and ack them. In case a critical event
597 * detected, it will be handled here, otherwise the work will be
598 * queued to a sleepable work-queue.
600 * @param p_hwfn - HW function
601 * @param p_ptt - PTT required for register access
602 * @return int - 0 - operation
605 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
606 struct qed_ptt *p_ptt);
613 struct qed_load_req_params {
615 enum qed_drv_role drv_role;
617 bool avoid_eng_reset;
618 enum qed_override_force_load override_force_load;
625 * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
626 * returns whether this PF is the first on the engine/port or function.
632 * @return int - 0 - Operation was successful.
634 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
635 struct qed_ptt *p_ptt,
636 struct qed_load_req_params *p_params);
639 * @brief Sends a UNLOAD_REQ message to the MFW
644 * @return int - 0 - Operation was successful.
646 int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
649 * @brief Sends a UNLOAD_DONE message to the MFW
654 * @return int - 0 - Operation was successful.
656 int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
659 * @brief Read the MFW mailbox into Current buffer.
664 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
665 struct qed_ptt *p_ptt);
668 * @brief Ack to mfw that driver finished FLR process for VFs
672 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
674 * @param return int - 0 upon success.
676 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
677 struct qed_ptt *p_ptt, u32 *vfs_to_ack);
680 * @brief - calls during init to read shmem of all function-related info.
684 * @param return 0 upon success.
686 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
687 struct qed_ptt *p_ptt);
690 * @brief - Reset the MCP using mailbox command.
695 * @param return 0 upon success.
697 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
698 struct qed_ptt *p_ptt);
701 * @brief - Sends an NVM read command request to the MFW to get
706 * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
707 * DRV_MSG_CODE_NVM_READ_NVRAM commands
708 * @param param - [0:23] - Offset [24:31] - Size
709 * @param o_mcp_resp - MCP response
710 * @param o_mcp_param - MCP response param
711 * @param o_txn_size - Buffer size output
712 * @param o_buf - Pointer to the buffer returned by the MFW.
714 * @param return 0 upon success.
716 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
717 struct qed_ptt *p_ptt,
721 u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
724 * @brief indicates whether the MFW objects [under mcp_info] are accessible
728 * @return true iff MFW is running and mcp_info is initialized
730 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
733 * @brief request MFW to configure MSI-X for a VF
737 * @param vf_id - absolute inside engine
738 * @param num_sbs - number of entries to request
742 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
743 struct qed_ptt *p_ptt, u8 vf_id, u8 num);
746 * @brief - Halt the MCP.
751 * @param return 0 upon success.
753 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
756 * @brief - Wake up the MCP.
761 * @param return 0 upon success.
763 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
765 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
766 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
767 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
768 struct qed_ptt *p_ptt,
769 struct qed_mcp_link_state *p_link,
771 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
772 struct qed_ptt *p_ptt,
773 struct qed_mcp_link_state *p_link,
776 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
777 struct qed_ptt *p_ptt, u32 mask_parities);
780 * @brief - Sets the MFW's max value for the given resource
785 * @param resc_max_val
788 * @return int - 0 - operation was successful.
791 qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn,
792 struct qed_ptt *p_ptt,
793 enum qed_resources res_id,
794 u32 resc_max_val, u32 *p_mcp_resp);
797 * @brief - Gets the MFW allocation info for the given resource
804 * @param p_resc_start
806 * @return int - 0 - operation was successful.
809 qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
810 struct qed_ptt *p_ptt,
811 enum qed_resources res_id,
812 u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start);
815 * @brief Send eswitch mode to MFW
819 * @param eswitch - eswitch mode
821 * @return int - 0 - operation was successful.
823 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
824 struct qed_ptt *p_ptt,
825 enum qed_ov_eswitch eswitch);
827 #define QED_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP
828 #define QED_MCP_RESC_LOCK_MAX_VAL 31
831 QED_RESC_LOCK_DBG_DUMP = QED_MCP_RESC_LOCK_MIN_VAL,
832 QED_RESC_LOCK_PTP_PORT0,
833 QED_RESC_LOCK_PTP_PORT1,
834 QED_RESC_LOCK_PTP_PORT2,
835 QED_RESC_LOCK_PTP_PORT3,
836 QED_RESC_LOCK_RESC_ALLOC = QED_MCP_RESC_LOCK_MAX_VAL,
837 QED_RESC_LOCK_RESC_INVALID
841 * @brief - Initiates PF FLR
846 * @return int - 0 - operation was successful.
848 int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
849 struct qed_resc_lock_params {
850 /* Resource number [valid values are 0..31] */
853 /* Lock timeout value in seconds [default, none or 1..254] */
855 #define QED_MCP_RESC_LOCK_TO_DEFAULT 0
856 #define QED_MCP_RESC_LOCK_TO_NONE 255
858 /* Number of times to retry locking */
860 #define QED_MCP_RESC_LOCK_RETRY_CNT_DFLT 10
862 /* The interval in usec between retries */
864 #define QED_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000
866 /* Use sleep or delay between retries */
869 /* Will be set as true if the resource is free and granted */
872 /* Will be filled with the resource owner.
873 * [0..15 = PF0-15, 16 = MFW]
879 * @brief Acquires MFW generic resource lock
885 * @return int - 0 - operation was successful.
888 qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
889 struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params);
891 struct qed_resc_unlock_params {
892 /* Resource number [valid values are 0..31] */
895 /* Allow to release a resource even if belongs to another PF */
898 /* Will be set as true if the resource is released */
903 * @brief Releases MFW generic resource lock
909 * @return int - 0 - operation was successful.
912 qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn,
913 struct qed_ptt *p_ptt,
914 struct qed_resc_unlock_params *p_params);
917 * @brief - default initialization for lock/unlock resource structs
919 * @param p_lock - lock params struct to be initialized; Can be NULL
920 * @param p_unlock - unlock params struct to be initialized; Can be NULL
921 * @param resource - the requested resource
922 * @paral b_is_permanent - disable retries & aging when set
924 void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock,
925 struct qed_resc_unlock_params *p_unlock,
927 resource, bool b_is_permanent);