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>
43 struct qed_mcp_link_speed_params {
45 u32 advertised_speeds; /* bitmask of DRV_SPEED_CAPABILITY */
46 u32 forced_speed; /* In Mb/s */
49 struct qed_mcp_link_pause_params {
55 struct qed_mcp_link_params {
56 struct qed_mcp_link_speed_params speed;
57 struct qed_mcp_link_pause_params pause;
61 struct qed_mcp_link_capabilities {
62 u32 speed_capabilities;
65 struct qed_mcp_link_state {
70 /* Actual link speed in Mb/s */
73 /* PF max speed in Mb/s, deduced from line_speed
74 * according to PF max bandwidth configuration.
81 bool parallel_detection;
84 #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
85 #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
86 #define QED_LINK_PARTNER_SPEED_10G BIT(2)
87 #define QED_LINK_PARTNER_SPEED_20G BIT(3)
88 #define QED_LINK_PARTNER_SPEED_25G BIT(4)
89 #define QED_LINK_PARTNER_SPEED_40G BIT(5)
90 #define QED_LINK_PARTNER_SPEED_50G BIT(6)
91 #define QED_LINK_PARTNER_SPEED_100G BIT(7)
92 u32 partner_adv_speed;
94 bool partner_tx_flow_ctrl_en;
95 bool partner_rx_flow_ctrl_en;
97 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
98 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
99 #define QED_LINK_PARTNER_BOTH_PAUSE (3)
100 u8 partner_adv_pause;
105 struct qed_mcp_function_info {
108 enum qed_pci_personality protocol;
118 #define QED_MCP_VLAN_UNSET (0xffff)
124 struct qed_mcp_nvm_common {
131 struct qed_mcp_drv_version {
133 u8 name[MCP_DRV_VER_STR_SIZE - 4];
136 struct qed_mcp_lan_stats {
142 struct qed_mcp_fcoe_stats {
149 struct qed_mcp_iscsi_stats {
156 struct qed_mcp_rdma_stats {
163 enum qed_mcp_protocol_type {
170 union qed_mcp_protocol_stats {
171 struct qed_mcp_lan_stats lan_stats;
172 struct qed_mcp_fcoe_stats fcoe_stats;
173 struct qed_mcp_iscsi_stats iscsi_stats;
174 struct qed_mcp_rdma_stats rdma_stats;
177 enum qed_ov_eswitch {
186 QED_OV_CLIENT_VENDOR_SPEC
189 enum qed_ov_driver_state {
190 QED_OV_DRIVER_STATE_NOT_LOADED,
191 QED_OV_DRIVER_STATE_DISABLED,
192 QED_OV_DRIVER_STATE_ACTIVE
202 * @brief - returns the link params of the hw function
206 * @returns pointer to link params
208 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
211 * @brief - return the link state of the hw function
215 * @returns pointer to link state
217 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
220 * @brief - return the link capabilities of the hw function
224 * @returns pointer to link capabilities
226 struct qed_mcp_link_capabilities
227 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
230 * @brief Request the MFW to set the the link according to 'link_input'.
234 * @param b_up - raise link if `true'. Reset link if `false'.
238 int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
239 struct qed_ptt *p_ptt,
243 * @brief Get the management firmware version value
247 * @param p_mfw_ver - mfw version value
248 * @param p_running_bundle_id - image id in nvram; Optional.
250 * @return int - 0 - operation was successful.
252 int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
253 struct qed_ptt *p_ptt,
254 u32 *p_mfw_ver, u32 *p_running_bundle_id);
257 * @brief Get media type value of the port.
259 * @param cdev - qed dev pointer
260 * @param mfw_ver - media type value
263 * 0 - Operation was successul.
264 * -EBUSY - Operation failed
266 int qed_mcp_get_media_type(struct qed_dev *cdev,
270 * @brief General function for sending commands to the MCP
271 * mailbox. It acquire mutex lock for the entire
272 * operation, from sending the request until the MCP
273 * response. Waiting for MCP response will be checked up
274 * to 5 seconds every 5ms.
276 * @param p_hwfn - hw function
277 * @param p_ptt - PTT required for register access
278 * @param cmd - command to be sent to the MCP.
279 * @param param - Optional param
280 * @param o_mcp_resp - The MCP response code (exclude sequence).
281 * @param o_mcp_param- Optional parameter provided by the MCP
283 * @return int - 0 - operation
286 int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
287 struct qed_ptt *p_ptt,
294 * @brief - drains the nig, allowing completion to pass in case of pauses.
295 * (Should be called only from sleepable context)
300 int qed_mcp_drain(struct qed_hwfn *p_hwfn,
301 struct qed_ptt *p_ptt);
304 * @brief Get the flash size value
308 * @param p_flash_size - flash size in bytes to be filled.
310 * @return int - 0 - operation was successul.
312 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
313 struct qed_ptt *p_ptt,
317 * @brief Send driver version to MFW
321 * @param version - Version value
322 * @param name - Protocol driver name
324 * @return int - 0 - operation was successul.
327 qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
328 struct qed_ptt *p_ptt,
329 struct qed_mcp_drv_version *p_ver);
332 * @brief Notify MFW about the change in base device properties
336 * @param client - qed client type
338 * @return int - 0 - operation was successful.
340 int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
341 struct qed_ptt *p_ptt,
342 enum qed_ov_client client);
345 * @brief Notify MFW about the driver state
349 * @param drv_state - Driver state
351 * @return int - 0 - operation was successful.
353 int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
354 struct qed_ptt *p_ptt,
355 enum qed_ov_driver_state drv_state);
358 * @brief Send MTU size to MFW
362 * @param mtu - MTU size
364 * @return int - 0 - operation was successful.
366 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
367 struct qed_ptt *p_ptt, u16 mtu);
370 * @brief Send MAC address to MFW
374 * @param mac - MAC address
376 * @return int - 0 - operation was successful.
378 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
379 struct qed_ptt *p_ptt, u8 *mac);
382 * @brief Send WOL mode to MFW
386 * @param wol - WOL mode
388 * @return int - 0 - operation was successful.
390 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
391 struct qed_ptt *p_ptt,
392 enum qed_ov_wol wol);
395 * @brief Set LED status
399 * @param mode - LED mode
401 * @return int - 0 - operation was successful.
403 int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
404 struct qed_ptt *p_ptt,
405 enum qed_led_mode mode);
408 * @brief Read from nvm
411 * @param addr - nvm offset
412 * @param p_buf - nvm read buffer
413 * @param len - buffer len
415 * @return int - 0 - operation was successful.
417 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
420 * @brief Bist register test
422 * @param p_hwfn - hw function
423 * @param p_ptt - PTT required for register access
425 * @return int - 0 - operation was successful.
427 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
428 struct qed_ptt *p_ptt);
431 * @brief Bist clock test
433 * @param p_hwfn - hw function
434 * @param p_ptt - PTT required for register access
436 * @return int - 0 - operation was successful.
438 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
439 struct qed_ptt *p_ptt);
442 * @brief Bist nvm test - get number of images
444 * @param p_hwfn - hw function
445 * @param p_ptt - PTT required for register access
446 * @param num_images - number of images if operation was
447 * successful. 0 if not.
449 * @return int - 0 - operation was successful.
451 int qed_mcp_bist_nvm_test_get_num_images(struct qed_hwfn *p_hwfn,
452 struct qed_ptt *p_ptt,
456 * @brief Bist nvm test - get image attributes by index
458 * @param p_hwfn - hw function
459 * @param p_ptt - PTT required for register access
460 * @param p_image_att - Attributes of image
461 * @param image_index - Index of image to get information for
463 * @return int - 0 - operation was successful.
465 int qed_mcp_bist_nvm_test_get_image_att(struct qed_hwfn *p_hwfn,
466 struct qed_ptt *p_ptt,
467 struct bist_nvm_image_att *p_image_att,
470 /* Using hwfn number (and not pf_num) is required since in CMT mode,
471 * same pf_num may be used by two different hwfn
472 * TODO - this shouldn't really be in .h file, but until all fields
473 * required during hw-init will be placed in their correct place in shmem
474 * we need it in qed_dev.c [for readin the nvram reflection in shmem].
476 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
478 ((p_hwfn)->abs_pf_id & 1) << 3) : \
480 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
482 /* TODO - this is only correct as long as only BB is supported, and
483 * no port-swapping is implemented; Afterwards we'll need to fix it.
485 #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
486 ((_p_hwfn)->cdev->num_ports_in_engines * 2))
487 struct qed_mcp_info {
488 /* Spinlock used for protecting the access to the MFW mailbox */
491 /* Spinlock used for syncing SW link-changes and link-changes
492 * originating from attention context.
494 spinlock_t link_lock;
495 bool block_mb_sending;
502 struct qed_mcp_link_params link_input;
503 struct qed_mcp_link_state link_output;
504 struct qed_mcp_link_capabilities link_capabilities;
505 struct qed_mcp_function_info func_info;
512 struct qed_mcp_mb_params {
515 union drv_union_data *p_data_src;
516 union drv_union_data *p_data_dst;
522 * @brief Initialize the interface with the MCP
524 * @param p_hwfn - HW func
525 * @param p_ptt - PTT required for register access
529 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
530 struct qed_ptt *p_ptt);
533 * @brief Initialize the port interface with the MCP
537 * Can only be called after `num_ports_in_engines' is set
539 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
540 struct qed_ptt *p_ptt);
542 * @brief Releases resources allocated during the init process.
544 * @param p_hwfn - HW func
545 * @param p_ptt - PTT required for register access
550 int qed_mcp_free(struct qed_hwfn *p_hwfn);
553 * @brief This function is called from the DPC context. After
554 * pointing PTT to the mfw mb, check for events sent by the MCP
555 * to the driver and ack them. In case a critical event
556 * detected, it will be handled here, otherwise the work will be
557 * queued to a sleepable work-queue.
559 * @param p_hwfn - HW function
560 * @param p_ptt - PTT required for register access
561 * @return int - 0 - operation
564 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
565 struct qed_ptt *p_ptt);
568 * @brief Sends a LOAD_REQ to the MFW, and in case operation
569 * succeed, returns whether this PF is the first on the
570 * chip/engine/port or function. This function should be
571 * called when driver is ready to accept MFW events after
572 * Storms initializations are done.
574 * @param p_hwfn - hw function
575 * @param p_ptt - PTT required for register access
576 * @param p_load_code - The MCP response param containing one
578 * FW_MSG_CODE_DRV_LOAD_ENGINE
579 * FW_MSG_CODE_DRV_LOAD_PORT
580 * FW_MSG_CODE_DRV_LOAD_FUNCTION
582 * 0 - Operation was successul.
583 * -EBUSY - Operation failed
585 int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
586 struct qed_ptt *p_ptt,
590 * @brief Read the MFW mailbox into Current buffer.
595 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
596 struct qed_ptt *p_ptt);
599 * @brief Ack to mfw that driver finished FLR process for VFs
603 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
605 * @param return int - 0 upon success.
607 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
608 struct qed_ptt *p_ptt, u32 *vfs_to_ack);
611 * @brief - calls during init to read shmem of all function-related info.
615 * @param return 0 upon success.
617 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
618 struct qed_ptt *p_ptt);
621 * @brief - Reset the MCP using mailbox command.
626 * @param return 0 upon success.
628 int qed_mcp_reset(struct qed_hwfn *p_hwfn,
629 struct qed_ptt *p_ptt);
632 * @brief - Sends an NVM read command request to the MFW to get
637 * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
638 * DRV_MSG_CODE_NVM_READ_NVRAM commands
639 * @param param - [0:23] - Offset [24:31] - Size
640 * @param o_mcp_resp - MCP response
641 * @param o_mcp_param - MCP response param
642 * @param o_txn_size - Buffer size output
643 * @param o_buf - Pointer to the buffer returned by the MFW.
645 * @param return 0 upon success.
647 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
648 struct qed_ptt *p_ptt,
652 u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
655 * @brief indicates whether the MFW objects [under mcp_info] are accessible
659 * @return true iff MFW is running and mcp_info is initialized
661 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
664 * @brief request MFW to configure MSI-X for a VF
668 * @param vf_id - absolute inside engine
669 * @param num_sbs - number of entries to request
673 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
674 struct qed_ptt *p_ptt, u8 vf_id, u8 num);
677 * @brief - Halt the MCP.
682 * @param return 0 upon success.
684 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
687 * @brief - Wake up the MCP.
692 * @param return 0 upon success.
694 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
696 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
697 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
698 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
699 struct qed_ptt *p_ptt,
700 struct qed_mcp_link_state *p_link,
702 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
703 struct qed_ptt *p_ptt,
704 struct qed_mcp_link_state *p_link,
707 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
708 struct qed_ptt *p_ptt, u32 mask_parities);
711 * @brief Send eswitch mode to MFW
715 * @param eswitch - eswitch mode
717 * @return int - 0 - operation was successful.
719 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
720 struct qed_ptt *p_ptt,
721 enum qed_ov_eswitch eswitch);
724 * @brief - Gets the MFW allocation info for the given resource
728 * @param p_resc_info - descriptor of requested resource
732 * @return int - 0 - operation was successful.
734 int qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
735 struct qed_ptt *p_ptt,
736 struct resource_info *p_resc_info,
737 u32 *p_mcp_resp, u32 *p_mcp_param);