1 /* QLogic qed NIC Driver 2 * Copyright (c) 2015 QLogic Corporation 3 * 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 6 * this source tree. 7 */ 8 9 #ifndef _QED_MCP_H 10 #define _QED_MCP_H 11 12 #include <linux/types.h> 13 #include <linux/delay.h> 14 #include <linux/slab.h> 15 #include <linux/spinlock.h> 16 #include "qed_hsi.h" 17 18 struct qed_mcp_link_speed_params { 19 bool autoneg; 20 u32 advertised_speeds; /* bitmask of DRV_SPEED_CAPABILITY */ 21 u32 forced_speed; /* In Mb/s */ 22 }; 23 24 struct qed_mcp_link_pause_params { 25 bool autoneg; 26 bool forced_rx; 27 bool forced_tx; 28 }; 29 30 struct qed_mcp_link_params { 31 struct qed_mcp_link_speed_params speed; 32 struct qed_mcp_link_pause_params pause; 33 u32 loopback_mode; 34 }; 35 36 struct qed_mcp_link_capabilities { 37 u32 speed_capabilities; 38 }; 39 40 struct qed_mcp_link_state { 41 bool link_up; 42 43 u32 min_pf_rate; 44 45 /* Actual link speed in Mb/s */ 46 u32 line_speed; 47 48 /* PF max speed in Mb/s, deduced from line_speed 49 * according to PF max bandwidth configuration. 50 */ 51 u32 speed; 52 bool full_duplex; 53 54 bool an; 55 bool an_complete; 56 bool parallel_detection; 57 bool pfc_enabled; 58 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; 68 69 bool partner_tx_flow_ctrl_en; 70 bool partner_rx_flow_ctrl_en; 71 72 #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1) 73 #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2) 74 #define QED_LINK_PARTNER_BOTH_PAUSE (3) 75 u8 partner_adv_pause; 76 77 bool sfp_tx_fault; 78 }; 79 80 struct qed_mcp_function_info { 81 u8 pause_on_host; 82 83 enum qed_pci_personality protocol; 84 85 u8 bandwidth_min; 86 u8 bandwidth_max; 87 88 u8 mac[ETH_ALEN]; 89 90 u64 wwn_port; 91 u64 wwn_node; 92 93 #define QED_MCP_VLAN_UNSET (0xffff) 94 u16 ovlan; 95 96 u16 mtu; 97 }; 98 99 struct qed_mcp_nvm_common { 100 u32 offset; 101 u32 param; 102 u32 resp; 103 u32 cmd; 104 }; 105 106 struct qed_mcp_drv_version { 107 u32 version; 108 u8 name[MCP_DRV_VER_STR_SIZE - 4]; 109 }; 110 111 struct qed_mcp_lan_stats { 112 u64 ucast_rx_pkts; 113 u64 ucast_tx_pkts; 114 u32 fcs_err; 115 }; 116 117 struct qed_mcp_fcoe_stats { 118 u64 rx_pkts; 119 u64 tx_pkts; 120 u32 fcs_err; 121 u32 login_failure; 122 }; 123 124 struct qed_mcp_iscsi_stats { 125 u64 rx_pdus; 126 u64 tx_pdus; 127 u64 rx_bytes; 128 u64 tx_bytes; 129 }; 130 131 struct qed_mcp_rdma_stats { 132 u64 rx_pkts; 133 u64 tx_pkts; 134 u64 rx_bytes; 135 u64 tx_byts; 136 }; 137 138 enum qed_mcp_protocol_type { 139 QED_MCP_LAN_STATS, 140 QED_MCP_FCOE_STATS, 141 QED_MCP_ISCSI_STATS, 142 QED_MCP_RDMA_STATS 143 }; 144 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; 150 }; 151 152 enum qed_ov_eswitch { 153 QED_OV_ESWITCH_NONE, 154 QED_OV_ESWITCH_VEB, 155 QED_OV_ESWITCH_VEPA 156 }; 157 158 enum qed_ov_client { 159 QED_OV_CLIENT_DRV, 160 QED_OV_CLIENT_USER, 161 QED_OV_CLIENT_VENDOR_SPEC 162 }; 163 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 168 }; 169 170 enum qed_ov_wol { 171 QED_OV_WOL_DEFAULT, 172 QED_OV_WOL_DISABLED, 173 QED_OV_WOL_ENABLED 174 }; 175 176 /** 177 * @brief - returns the link params of the hw function 178 * 179 * @param p_hwfn 180 * 181 * @returns pointer to link params 182 */ 183 struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *); 184 185 /** 186 * @brief - return the link state of the hw function 187 * 188 * @param p_hwfn 189 * 190 * @returns pointer to link state 191 */ 192 struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *); 193 194 /** 195 * @brief - return the link capabilities of the hw function 196 * 197 * @param p_hwfn 198 * 199 * @returns pointer to link capabilities 200 */ 201 struct qed_mcp_link_capabilities 202 *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn); 203 204 /** 205 * @brief Request the MFW to set the the link according to 'link_input'. 206 * 207 * @param p_hwfn 208 * @param p_ptt 209 * @param b_up - raise link if `true'. Reset link if `false'. 210 * 211 * @return int 212 */ 213 int qed_mcp_set_link(struct qed_hwfn *p_hwfn, 214 struct qed_ptt *p_ptt, 215 bool b_up); 216 217 /** 218 * @brief Get the management firmware version value 219 * 220 * @param p_hwfn 221 * @param p_ptt 222 * @param p_mfw_ver - mfw version value 223 * @param p_running_bundle_id - image id in nvram; Optional. 224 * 225 * @return int - 0 - operation was successful. 226 */ 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); 230 231 /** 232 * @brief Get media type value of the port. 233 * 234 * @param cdev - qed dev pointer 235 * @param mfw_ver - media type value 236 * 237 * @return int - 238 * 0 - Operation was successul. 239 * -EBUSY - Operation failed 240 */ 241 int qed_mcp_get_media_type(struct qed_dev *cdev, 242 u32 *media_type); 243 244 /** 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. 250 * 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 257 * response 258 * @return int - 0 - operation 259 * was successul. 260 */ 261 int qed_mcp_cmd(struct qed_hwfn *p_hwfn, 262 struct qed_ptt *p_ptt, 263 u32 cmd, 264 u32 param, 265 u32 *o_mcp_resp, 266 u32 *o_mcp_param); 267 268 /** 269 * @brief - drains the nig, allowing completion to pass in case of pauses. 270 * (Should be called only from sleepable context) 271 * 272 * @param p_hwfn 273 * @param p_ptt 274 */ 275 int qed_mcp_drain(struct qed_hwfn *p_hwfn, 276 struct qed_ptt *p_ptt); 277 278 /** 279 * @brief Get the flash size value 280 * 281 * @param p_hwfn 282 * @param p_ptt 283 * @param p_flash_size - flash size in bytes to be filled. 284 * 285 * @return int - 0 - operation was successul. 286 */ 287 int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn, 288 struct qed_ptt *p_ptt, 289 u32 *p_flash_size); 290 291 /** 292 * @brief Send driver version to MFW 293 * 294 * @param p_hwfn 295 * @param p_ptt 296 * @param version - Version value 297 * @param name - Protocol driver name 298 * 299 * @return int - 0 - operation was successul. 300 */ 301 int 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); 305 306 /** 307 * @brief Notify MFW about the change in base device properties 308 * 309 * @param p_hwfn 310 * @param p_ptt 311 * @param client - qed client type 312 * 313 * @return int - 0 - operation was successful. 314 */ 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); 318 319 /** 320 * @brief Notify MFW about the driver state 321 * 322 * @param p_hwfn 323 * @param p_ptt 324 * @param drv_state - Driver state 325 * 326 * @return int - 0 - operation was successful. 327 */ 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); 331 332 /** 333 * @brief Send MTU size to MFW 334 * 335 * @param p_hwfn 336 * @param p_ptt 337 * @param mtu - MTU size 338 * 339 * @return int - 0 - operation was successful. 340 */ 341 int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn, 342 struct qed_ptt *p_ptt, u16 mtu); 343 344 /** 345 * @brief Send MAC address to MFW 346 * 347 * @param p_hwfn 348 * @param p_ptt 349 * @param mac - MAC address 350 * 351 * @return int - 0 - operation was successful. 352 */ 353 int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn, 354 struct qed_ptt *p_ptt, u8 *mac); 355 356 /** 357 * @brief Send WOL mode to MFW 358 * 359 * @param p_hwfn 360 * @param p_ptt 361 * @param wol - WOL mode 362 * 363 * @return int - 0 - operation was successful. 364 */ 365 int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn, 366 struct qed_ptt *p_ptt, 367 enum qed_ov_wol wol); 368 369 /** 370 * @brief Set LED status 371 * 372 * @param p_hwfn 373 * @param p_ptt 374 * @param mode - LED mode 375 * 376 * @return int - 0 - operation was successful. 377 */ 378 int qed_mcp_set_led(struct qed_hwfn *p_hwfn, 379 struct qed_ptt *p_ptt, 380 enum qed_led_mode mode); 381 382 /** 383 * @brief Read from nvm 384 * 385 * @param cdev 386 * @param addr - nvm offset 387 * @param p_buf - nvm read buffer 388 * @param len - buffer len 389 * 390 * @return int - 0 - operation was successful. 391 */ 392 int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len); 393 394 /** 395 * @brief Bist register test 396 * 397 * @param p_hwfn - hw function 398 * @param p_ptt - PTT required for register access 399 * 400 * @return int - 0 - operation was successful. 401 */ 402 int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn, 403 struct qed_ptt *p_ptt); 404 405 /** 406 * @brief Bist clock test 407 * 408 * @param p_hwfn - hw function 409 * @param p_ptt - PTT required for register access 410 * 411 * @return int - 0 - operation was successful. 412 */ 413 int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn, 414 struct qed_ptt *p_ptt); 415 416 /** 417 * @brief Bist nvm test - get number of images 418 * 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. 423 * 424 * @return int - 0 - operation was successful. 425 */ 426 int qed_mcp_bist_nvm_test_get_num_images(struct qed_hwfn *p_hwfn, 427 struct qed_ptt *p_ptt, 428 u32 *num_images); 429 430 /** 431 * @brief Bist nvm test - get image attributes by index 432 * 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 437 * 438 * @return int - 0 - operation was successful. 439 */ 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, 443 u32 image_index); 444 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]. 450 */ 451 #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \ 452 ((rel_pfid) | \ 453 ((p_hwfn)->abs_pf_id & 1) << 3) : \ 454 rel_pfid) 455 #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id) 456 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. 459 */ 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 { 463 spinlock_t lock; 464 bool block_mb_sending; 465 u32 public_base; 466 u32 drv_mb_addr; 467 u32 mfw_mb_addr; 468 u32 port_addr; 469 u16 drv_mb_seq; 470 u16 drv_pulse_seq; 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; 475 u8 *mfw_mb_cur; 476 u8 *mfw_mb_shadow; 477 u16 mfw_mb_length; 478 u16 mcp_hist; 479 }; 480 481 struct qed_mcp_mb_params { 482 u32 cmd; 483 u32 param; 484 union drv_union_data *p_data_src; 485 union drv_union_data *p_data_dst; 486 u32 mcp_resp; 487 u32 mcp_param; 488 }; 489 490 /** 491 * @brief Initialize the interface with the MCP 492 * 493 * @param p_hwfn - HW func 494 * @param p_ptt - PTT required for register access 495 * 496 * @return int 497 */ 498 int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn, 499 struct qed_ptt *p_ptt); 500 501 /** 502 * @brief Initialize the port interface with the MCP 503 * 504 * @param p_hwfn 505 * @param p_ptt 506 * Can only be called after `num_ports_in_engines' is set 507 */ 508 void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn, 509 struct qed_ptt *p_ptt); 510 /** 511 * @brief Releases resources allocated during the init process. 512 * 513 * @param p_hwfn - HW func 514 * @param p_ptt - PTT required for register access 515 * 516 * @return int 517 */ 518 519 int qed_mcp_free(struct qed_hwfn *p_hwfn); 520 521 /** 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. 527 * 528 * @param p_hwfn - HW function 529 * @param p_ptt - PTT required for register access 530 * @return int - 0 - operation 531 * was successul. 532 */ 533 int qed_mcp_handle_events(struct qed_hwfn *p_hwfn, 534 struct qed_ptt *p_ptt); 535 536 /** 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. 542 * 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 546 * of the following: 547 * FW_MSG_CODE_DRV_LOAD_ENGINE 548 * FW_MSG_CODE_DRV_LOAD_PORT 549 * FW_MSG_CODE_DRV_LOAD_FUNCTION 550 * @return int - 551 * 0 - Operation was successul. 552 * -EBUSY - Operation failed 553 */ 554 int qed_mcp_load_req(struct qed_hwfn *p_hwfn, 555 struct qed_ptt *p_ptt, 556 u32 *p_load_code); 557 558 /** 559 * @brief Read the MFW mailbox into Current buffer. 560 * 561 * @param p_hwfn 562 * @param p_ptt 563 */ 564 void qed_mcp_read_mb(struct qed_hwfn *p_hwfn, 565 struct qed_ptt *p_ptt); 566 567 /** 568 * @brief Ack to mfw that driver finished FLR process for VFs 569 * 570 * @param p_hwfn 571 * @param p_ptt 572 * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks. 573 * 574 * @param return int - 0 upon success. 575 */ 576 int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn, 577 struct qed_ptt *p_ptt, u32 *vfs_to_ack); 578 579 /** 580 * @brief - calls during init to read shmem of all function-related info. 581 * 582 * @param p_hwfn 583 * 584 * @param return 0 upon success. 585 */ 586 int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn, 587 struct qed_ptt *p_ptt); 588 589 /** 590 * @brief - Reset the MCP using mailbox command. 591 * 592 * @param p_hwfn 593 * @param p_ptt 594 * 595 * @param return 0 upon success. 596 */ 597 int qed_mcp_reset(struct qed_hwfn *p_hwfn, 598 struct qed_ptt *p_ptt); 599 600 /** 601 * @brief - Sends an NVM read command request to the MFW to get 602 * a buffer. 603 * 604 * @param p_hwfn 605 * @param p_ptt 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. 613 * 614 * @param return 0 upon success. 615 */ 616 int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn, 617 struct qed_ptt *p_ptt, 618 u32 cmd, 619 u32 param, 620 u32 *o_mcp_resp, 621 u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf); 622 623 /** 624 * @brief indicates whether the MFW objects [under mcp_info] are accessible 625 * 626 * @param p_hwfn 627 * 628 * @return true iff MFW is running and mcp_info is initialized 629 */ 630 bool qed_mcp_is_init(struct qed_hwfn *p_hwfn); 631 632 /** 633 * @brief request MFW to configure MSI-X for a VF 634 * 635 * @param p_hwfn 636 * @param p_ptt 637 * @param vf_id - absolute inside engine 638 * @param num_sbs - number of entries to request 639 * 640 * @return int 641 */ 642 int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn, 643 struct qed_ptt *p_ptt, u8 vf_id, u8 num); 644 645 /** 646 * @brief - Halt the MCP. 647 * 648 * @param p_hwfn 649 * @param p_ptt 650 * 651 * @param return 0 upon success. 652 */ 653 int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt); 654 655 /** 656 * @brief - Wake up the MCP. 657 * 658 * @param p_hwfn 659 * @param p_ptt 660 * 661 * @param return 0 upon success. 662 */ 663 int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt); 664 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, 670 u8 max_bw); 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, 674 u8 min_bw); 675 676 int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn, 677 struct qed_ptt *p_ptt, u32 mask_parities); 678 679 /** 680 * @brief Send eswitch mode to MFW 681 * 682 * @param p_hwfn 683 * @param p_ptt 684 * @param eswitch - eswitch mode 685 * 686 * @return int - 0 - operation was successful. 687 */ 688 int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn, 689 struct qed_ptt *p_ptt, 690 enum qed_ov_eswitch eswitch); 691 692 /** 693 * @brief - Gets the MFW allocation info for the given resource 694 * 695 * @param p_hwfn 696 * @param p_ptt 697 * @param p_resc_info - descriptor of requested resource 698 * @param p_mcp_resp 699 * @param p_mcp_param 700 * 701 * @return int - 0 - operation was successful. 702 */ 703 int qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn, 704 struct qed_ptt *p_ptt, 705 struct resource_info *p_resc_info, 706 u32 *p_mcp_resp, u32 *p_mcp_param); 707 #endif 708