1 /* 2 * Copyright (c) 2016 QLogic Corporation. 3 * All rights reserved. 4 * www.qlogic.com 5 * 6 * See LICENSE.qede_pmd for copyright and licensing details. 7 */ 8 9 #ifndef __ECORE_DEV_API_H__ 10 #define __ECORE_DEV_API_H__ 11 12 #include "ecore_status.h" 13 #include "ecore_chain.h" 14 #include "ecore_int_api.h" 15 16 /** 17 * @brief ecore_init_dp - initialize the debug level 18 * 19 * @param p_dev 20 * @param dp_module 21 * @param dp_level 22 * @param dp_ctx 23 */ 24 void ecore_init_dp(struct ecore_dev *p_dev, 25 u32 dp_module, 26 u8 dp_level, 27 void *dp_ctx); 28 29 /** 30 * @brief ecore_init_struct - initialize the device structure to 31 * its defaults 32 * 33 * @param p_dev 34 */ 35 void ecore_init_struct(struct ecore_dev *p_dev); 36 37 /** 38 * @brief ecore_resc_free - 39 * 40 * @param p_dev 41 */ 42 void ecore_resc_free(struct ecore_dev *p_dev); 43 44 /** 45 * @brief ecore_resc_alloc - 46 * 47 * @param p_dev 48 * 49 * @return enum _ecore_status_t 50 */ 51 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev); 52 53 /** 54 * @brief ecore_resc_setup - 55 * 56 * @param p_dev 57 */ 58 void ecore_resc_setup(struct ecore_dev *p_dev); 59 60 enum ecore_override_force_load { 61 ECORE_OVERRIDE_FORCE_LOAD_NONE, 62 ECORE_OVERRIDE_FORCE_LOAD_ALWAYS, 63 ECORE_OVERRIDE_FORCE_LOAD_NEVER, 64 }; 65 66 struct ecore_drv_load_params { 67 /* Indicates whether the driver is running over a crash kernel. 68 * As part of the load request, this will be used for providing the 69 * driver role to the MFW. 70 * In case of a crash kernel over PDA - this should be set to false. 71 */ 72 bool is_crash_kernel; 73 74 /* The timeout value that the MFW should use when locking the engine for 75 * the driver load process. 76 * A value of '0' means the default value, and '255' means no timeout. 77 */ 78 u8 mfw_timeout_val; 79 #define ECORE_LOAD_REQ_LOCK_TO_DEFAULT 0 80 #define ECORE_LOAD_REQ_LOCK_TO_NONE 255 81 82 /* Avoid engine reset when first PF loads on it */ 83 bool avoid_eng_reset; 84 85 /* Allow overriding the default force load behavior */ 86 enum ecore_override_force_load override_force_load; 87 }; 88 89 struct ecore_hw_init_params { 90 /* Tunneling parameters */ 91 struct ecore_tunnel_info *p_tunn; 92 93 bool b_hw_start; 94 95 /* Interrupt mode [msix, inta, etc.] to use */ 96 enum ecore_int_mode int_mode; 97 98 /* NPAR tx switching to be used for vports configured for tx-switching 99 */ 100 bool allow_npar_tx_switch; 101 102 /* Binary fw data pointer in binary fw file */ 103 const u8 *bin_fw_data; 104 105 /* Driver load parameters */ 106 struct ecore_drv_load_params *p_drv_load_params; 107 }; 108 109 /** 110 * @brief ecore_hw_init - 111 * 112 * @param p_dev 113 * @param p_params 114 * 115 * @return enum _ecore_status_t 116 */ 117 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev, 118 struct ecore_hw_init_params *p_params); 119 120 /** 121 * @brief ecore_hw_timers_stop_all - 122 * 123 * @param p_dev 124 * 125 * @return void 126 */ 127 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev); 128 129 /** 130 * @brief ecore_hw_stop - 131 * 132 * @param p_dev 133 * 134 * @return enum _ecore_status_t 135 */ 136 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev); 137 138 /** 139 * @brief ecore_hw_stop_fastpath -should be called incase 140 * slowpath is still required for the device, 141 * but fastpath is not. 142 * 143 * @param p_dev 144 * 145 * @return enum _ecore_status_t 146 */ 147 enum _ecore_status_t ecore_hw_stop_fastpath(struct ecore_dev *p_dev); 148 149 #ifndef LINUX_REMOVE 150 /** 151 * @brief ecore_prepare_hibernate -should be called when 152 * the system is going into the hibernate state 153 * 154 * @param p_dev 155 * 156 */ 157 void ecore_prepare_hibernate(struct ecore_dev *p_dev); 158 159 enum ecore_db_rec_width { 160 DB_REC_WIDTH_32B, 161 DB_REC_WIDTH_64B, 162 }; 163 164 enum ecore_db_rec_space { 165 DB_REC_KERNEL, 166 DB_REC_USER, 167 }; 168 169 /** 170 * @brief db_recovery_add - add doorbell information to the doorbell 171 * recovery mechanism. 172 * 173 * @param p_dev 174 * @param db_addr - doorbell address 175 * @param db_data - address of where db_data is stored 176 * @param db_width - doorbell is 32b pr 64b 177 * @param db_space - doorbell recovery addresses are user or kernel space 178 */ 179 enum _ecore_status_t ecore_db_recovery_add(struct ecore_dev *p_dev, 180 void OSAL_IOMEM *db_addr, 181 void *db_data, 182 enum ecore_db_rec_width db_width, 183 enum ecore_db_rec_space db_space); 184 185 /** 186 * @brief db_recovery_del - remove doorbell information from the doorbell 187 * recovery mechanism. db_data serves as key (db_addr is not unique). 188 * 189 * @param cdev 190 * @param db_addr - doorbell address 191 * @param db_data - address where db_data is stored. Serves as key for the 192 * entry to delete. 193 */ 194 enum _ecore_status_t ecore_db_recovery_del(struct ecore_dev *p_dev, 195 void OSAL_IOMEM *db_addr, 196 void *db_data); 197 198 static OSAL_INLINE bool ecore_is_mf_ufp(struct ecore_hwfn *p_hwfn) 199 { 200 return !!OSAL_TEST_BIT(ECORE_MF_UFP_SPECIFIC, &p_hwfn->p_dev->mf_bits); 201 } 202 203 #endif 204 205 /** 206 * @brief ecore_hw_start_fastpath -restart fastpath traffic, 207 * only if hw_stop_fastpath was called 208 209 * @param p_hwfn 210 * 211 * @return enum _ecore_status_t 212 */ 213 enum _ecore_status_t ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn); 214 215 enum ecore_hw_prepare_result { 216 ECORE_HW_PREPARE_SUCCESS, 217 218 /* FAILED results indicate probe has failed & cleaned up */ 219 ECORE_HW_PREPARE_FAILED_ENG2, 220 ECORE_HW_PREPARE_FAILED_ME, 221 ECORE_HW_PREPARE_FAILED_MEM, 222 ECORE_HW_PREPARE_FAILED_DEV, 223 ECORE_HW_PREPARE_FAILED_NVM, 224 225 /* BAD results indicate probe is passed even though some wrongness 226 * has occurred; Trying to actually use [I.e., hw_init()] might have 227 * dire reprecautions. 228 */ 229 ECORE_HW_PREPARE_BAD_IOV, 230 ECORE_HW_PREPARE_BAD_MCP, 231 ECORE_HW_PREPARE_BAD_IGU, 232 }; 233 234 struct ecore_hw_prepare_params { 235 /* Personality to initialize */ 236 int personality; 237 238 /* Force the driver's default resource allocation */ 239 bool drv_resc_alloc; 240 241 /* Check the reg_fifo after any register access */ 242 bool chk_reg_fifo; 243 244 /* Request the MFW to initiate PF FLR */ 245 bool initiate_pf_flr; 246 247 /* The OS Epoch time in seconds */ 248 u32 epoch; 249 250 /* Allow the MFW to collect a crash dump */ 251 bool allow_mdump; 252 253 /* Allow prepare to pass even if some initializations are failing. 254 * If set, the `p_prepare_res' field would be set with the return, 255 * and might allow probe to pass even if there are certain issues. 256 */ 257 bool b_relaxed_probe; 258 enum ecore_hw_prepare_result p_relaxed_res; 259 }; 260 261 /** 262 * @brief ecore_hw_prepare - 263 * 264 * @param p_dev 265 * @param p_params 266 * 267 * @return enum _ecore_status_t 268 */ 269 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev, 270 struct ecore_hw_prepare_params *p_params); 271 272 /** 273 * @brief ecore_hw_remove - 274 * 275 * @param p_dev 276 */ 277 void ecore_hw_remove(struct ecore_dev *p_dev); 278 279 /** 280 * @brief ecore_ptt_acquire - Allocate a PTT window 281 * 282 * Should be called at the entry point to the driver (at the beginning of an 283 * exported function) 284 * 285 * @param p_hwfn 286 * 287 * @return struct ecore_ptt 288 */ 289 struct ecore_ptt *ecore_ptt_acquire(struct ecore_hwfn *p_hwfn); 290 291 /** 292 * @brief ecore_ptt_release - Release PTT Window 293 * 294 * Should be called at the end of a flow - at the end of the function that 295 * acquired the PTT. 296 * 297 * 298 * @param p_hwfn 299 * @param p_ptt 300 */ 301 void ecore_ptt_release(struct ecore_hwfn *p_hwfn, 302 struct ecore_ptt *p_ptt); 303 304 struct ecore_eth_stats_common { 305 u64 no_buff_discards; 306 u64 packet_too_big_discard; 307 u64 ttl0_discard; 308 u64 rx_ucast_bytes; 309 u64 rx_mcast_bytes; 310 u64 rx_bcast_bytes; 311 u64 rx_ucast_pkts; 312 u64 rx_mcast_pkts; 313 u64 rx_bcast_pkts; 314 u64 mftag_filter_discards; 315 u64 mac_filter_discards; 316 u64 tx_ucast_bytes; 317 u64 tx_mcast_bytes; 318 u64 tx_bcast_bytes; 319 u64 tx_ucast_pkts; 320 u64 tx_mcast_pkts; 321 u64 tx_bcast_pkts; 322 u64 tx_err_drop_pkts; 323 u64 tpa_coalesced_pkts; 324 u64 tpa_coalesced_events; 325 u64 tpa_aborts_num; 326 u64 tpa_not_coalesced_pkts; 327 u64 tpa_coalesced_bytes; 328 329 /* port */ 330 u64 rx_64_byte_packets; 331 u64 rx_65_to_127_byte_packets; 332 u64 rx_128_to_255_byte_packets; 333 u64 rx_256_to_511_byte_packets; 334 u64 rx_512_to_1023_byte_packets; 335 u64 rx_1024_to_1518_byte_packets; 336 u64 rx_crc_errors; 337 u64 rx_mac_crtl_frames; 338 u64 rx_pause_frames; 339 u64 rx_pfc_frames; 340 u64 rx_align_errors; 341 u64 rx_carrier_errors; 342 u64 rx_oversize_packets; 343 u64 rx_jabbers; 344 u64 rx_undersize_packets; 345 u64 rx_fragments; 346 u64 tx_64_byte_packets; 347 u64 tx_65_to_127_byte_packets; 348 u64 tx_128_to_255_byte_packets; 349 u64 tx_256_to_511_byte_packets; 350 u64 tx_512_to_1023_byte_packets; 351 u64 tx_1024_to_1518_byte_packets; 352 u64 tx_pause_frames; 353 u64 tx_pfc_frames; 354 u64 brb_truncates; 355 u64 brb_discards; 356 u64 rx_mac_bytes; 357 u64 rx_mac_uc_packets; 358 u64 rx_mac_mc_packets; 359 u64 rx_mac_bc_packets; 360 u64 rx_mac_frames_ok; 361 u64 tx_mac_bytes; 362 u64 tx_mac_uc_packets; 363 u64 tx_mac_mc_packets; 364 u64 tx_mac_bc_packets; 365 u64 tx_mac_ctrl_frames; 366 }; 367 368 struct ecore_eth_stats_bb { 369 u64 rx_1519_to_1522_byte_packets; 370 u64 rx_1519_to_2047_byte_packets; 371 u64 rx_2048_to_4095_byte_packets; 372 u64 rx_4096_to_9216_byte_packets; 373 u64 rx_9217_to_16383_byte_packets; 374 u64 tx_1519_to_2047_byte_packets; 375 u64 tx_2048_to_4095_byte_packets; 376 u64 tx_4096_to_9216_byte_packets; 377 u64 tx_9217_to_16383_byte_packets; 378 u64 tx_lpi_entry_count; 379 u64 tx_total_collisions; 380 }; 381 382 struct ecore_eth_stats_ah { 383 u64 rx_1519_to_max_byte_packets; 384 u64 tx_1519_to_max_byte_packets; 385 }; 386 387 struct ecore_eth_stats { 388 struct ecore_eth_stats_common common; 389 union { 390 struct ecore_eth_stats_bb bb; 391 struct ecore_eth_stats_ah ah; 392 }; 393 }; 394 395 enum ecore_dmae_address_type_t { 396 ECORE_DMAE_ADDRESS_HOST_VIRT, 397 ECORE_DMAE_ADDRESS_HOST_PHYS, 398 ECORE_DMAE_ADDRESS_GRC 399 }; 400 401 /* value of flags If ECORE_DMAE_FLAG_RW_REPL_SRC flag is set and the 402 * source is a block of length DMAE_MAX_RW_SIZE and the 403 * destination is larger, the source block will be duplicated as 404 * many times as required to fill the destination block. This is 405 * used mostly to write a zeroed buffer to destination address 406 * using DMA 407 */ 408 #define ECORE_DMAE_FLAG_RW_REPL_SRC 0x00000001 409 #define ECORE_DMAE_FLAG_VF_SRC 0x00000002 410 #define ECORE_DMAE_FLAG_VF_DST 0x00000004 411 #define ECORE_DMAE_FLAG_COMPLETION_DST 0x00000008 412 413 struct ecore_dmae_params { 414 u32 flags; /* consists of ECORE_DMAE_FLAG_* values */ 415 u8 src_vfid; 416 u8 dst_vfid; 417 }; 418 419 /** 420 * @brief ecore_dmae_host2grc - copy data from source addr to 421 * dmae registers using the given ptt 422 * 423 * @param p_hwfn 424 * @param p_ptt 425 * @param source_addr 426 * @param grc_addr (dmae_data_offset) 427 * @param size_in_dwords 428 * @param flags (one of the flags defined above) 429 */ 430 enum _ecore_status_t 431 ecore_dmae_host2grc(struct ecore_hwfn *p_hwfn, 432 struct ecore_ptt *p_ptt, 433 u64 source_addr, 434 u32 grc_addr, 435 u32 size_in_dwords, 436 u32 flags); 437 438 /** 439 * @brief ecore_dmae_grc2host - Read data from dmae data offset 440 * to source address using the given ptt 441 * 442 * @param p_ptt 443 * @param grc_addr (dmae_data_offset) 444 * @param dest_addr 445 * @param size_in_dwords 446 * @param flags - one of the flags defined above 447 */ 448 enum _ecore_status_t 449 ecore_dmae_grc2host(struct ecore_hwfn *p_hwfn, 450 struct ecore_ptt *p_ptt, 451 u32 grc_addr, 452 dma_addr_t dest_addr, 453 u32 size_in_dwords, 454 u32 flags); 455 456 /** 457 * @brief ecore_dmae_host2host - copy data from to source address 458 * to a destination address (for SRIOV) using the given ptt 459 * 460 * @param p_hwfn 461 * @param p_ptt 462 * @param source_addr 463 * @param dest_addr 464 * @param size_in_dwords 465 * @param params 466 */ 467 enum _ecore_status_t 468 ecore_dmae_host2host(struct ecore_hwfn *p_hwfn, 469 struct ecore_ptt *p_ptt, 470 dma_addr_t source_addr, 471 dma_addr_t dest_addr, 472 u32 size_in_dwords, 473 struct ecore_dmae_params *p_params); 474 475 /** 476 * @brief ecore_chain_alloc - Allocate and initialize a chain 477 * 478 * @param p_hwfn 479 * @param intended_use 480 * @param mode 481 * @param num_elems 482 * @param elem_size 483 * @param p_chain 484 * 485 * @return enum _ecore_status_t 486 */ 487 enum _ecore_status_t 488 ecore_chain_alloc(struct ecore_dev *p_dev, 489 enum ecore_chain_use_mode intended_use, 490 enum ecore_chain_mode mode, 491 enum ecore_chain_cnt_type cnt_type, 492 u32 num_elems, 493 osal_size_t elem_size, 494 struct ecore_chain *p_chain, 495 struct ecore_chain_ext_pbl *ext_pbl); 496 497 /** 498 * @brief ecore_chain_free - Free chain DMA memory 499 * 500 * @param p_hwfn 501 * @param p_chain 502 */ 503 void ecore_chain_free(struct ecore_dev *p_dev, 504 struct ecore_chain *p_chain); 505 506 /** 507 * @@brief ecore_fw_l2_queue - Get absolute L2 queue ID 508 * 509 * @param p_hwfn 510 * @param src_id - relative to p_hwfn 511 * @param dst_id - absolute per engine 512 * 513 * @return enum _ecore_status_t 514 */ 515 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn, 516 u16 src_id, 517 u16 *dst_id); 518 519 /** 520 * @@brief ecore_fw_vport - Get absolute vport ID 521 * 522 * @param p_hwfn 523 * @param src_id - relative to p_hwfn 524 * @param dst_id - absolute per engine 525 * 526 * @return enum _ecore_status_t 527 */ 528 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn, 529 u8 src_id, 530 u8 *dst_id); 531 532 /** 533 * @@brief ecore_fw_rss_eng - Get absolute RSS engine ID 534 * 535 * @param p_hwfn 536 * @param src_id - relative to p_hwfn 537 * @param dst_id - absolute per engine 538 * 539 * @return enum _ecore_status_t 540 */ 541 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn, 542 u8 src_id, 543 u8 *dst_id); 544 545 /** 546 * @brief ecore_llh_add_mac_filter - configures a MAC filter in llh 547 * 548 * @param p_hwfn 549 * @param p_ptt 550 * @param p_filter - MAC to add 551 */ 552 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn, 553 struct ecore_ptt *p_ptt, 554 u8 *p_filter); 555 556 /** 557 * @brief ecore_llh_remove_mac_filter - removes a MAC filtre from llh 558 * 559 * @param p_hwfn 560 * @param p_ptt 561 * @param p_filter - MAC to remove 562 */ 563 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn, 564 struct ecore_ptt *p_ptt, 565 u8 *p_filter); 566 567 enum ecore_llh_port_filter_type_t { 568 ECORE_LLH_FILTER_ETHERTYPE, 569 ECORE_LLH_FILTER_TCP_SRC_PORT, 570 ECORE_LLH_FILTER_TCP_DEST_PORT, 571 ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT, 572 ECORE_LLH_FILTER_UDP_SRC_PORT, 573 ECORE_LLH_FILTER_UDP_DEST_PORT, 574 ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT 575 }; 576 577 /** 578 * @brief ecore_llh_add_protocol_filter - configures a protocol filter in llh 579 * 580 * @param p_hwfn 581 * @param p_ptt 582 * @param source_port_or_eth_type - source port or ethertype to add 583 * @param dest_port - destination port to add 584 * @param type - type of filters and comparing 585 */ 586 enum _ecore_status_t 587 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn, 588 struct ecore_ptt *p_ptt, 589 u16 source_port_or_eth_type, 590 u16 dest_port, 591 enum ecore_llh_port_filter_type_t type); 592 593 /** 594 * @brief ecore_llh_remove_protocol_filter - remove a protocol filter in llh 595 * 596 * @param p_hwfn 597 * @param p_ptt 598 * @param source_port_or_eth_type - source port or ethertype to add 599 * @param dest_port - destination port to add 600 * @param type - type of filters and comparing 601 */ 602 void 603 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn, 604 struct ecore_ptt *p_ptt, 605 u16 source_port_or_eth_type, 606 u16 dest_port, 607 enum ecore_llh_port_filter_type_t type); 608 609 /** 610 * @brief ecore_llh_clear_all_filters - removes all MAC filters from llh 611 * 612 * @param p_hwfn 613 * @param p_ptt 614 */ 615 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn, 616 struct ecore_ptt *p_ptt); 617 618 /** 619 * @brief ecore_llh_set_function_as_default - set function as default per port 620 * 621 * @param p_hwfn 622 * @param p_ptt 623 */ 624 enum _ecore_status_t 625 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn, 626 struct ecore_ptt *p_ptt); 627 628 /** 629 *@brief Cleanup of previous driver remains prior to load 630 * 631 * @param p_hwfn 632 * @param p_ptt 633 * @param id - For PF, engine-relative. For VF, PF-relative. 634 * @param is_vf - true iff cleanup is made for a VF. 635 * 636 * @return enum _ecore_status_t 637 */ 638 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn, 639 struct ecore_ptt *p_ptt, 640 u16 id, 641 bool is_vf); 642 643 /** 644 * @brief ecore_get_queue_coalesce - Retrieve coalesce value for a given queue. 645 * 646 * @param p_hwfn 647 * @param p_coal - store coalesce value read from the hardware. 648 * @param p_handle 649 * 650 * @return enum _ecore_status_t 651 **/ 652 enum _ecore_status_t 653 ecore_get_queue_coalesce(struct ecore_hwfn *p_hwfn, u16 *coal, 654 void *handle); 655 656 /** 657 * @brief ecore_set_queue_coalesce - Configure coalesce parameters for Rx and 658 * Tx queue. The fact that we can configure coalescing to up to 511, but on 659 * varying accuracy [the bigger the value the less accurate] up to a mistake 660 * of 3usec for the highest values. 661 * While the API allows setting coalescing per-qid, all queues sharing a SB 662 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff] 663 * otherwise configuration would break. 664 * 665 * @param p_hwfn 666 * @param rx_coal - Rx Coalesce value in micro seconds. 667 * @param tx_coal - TX Coalesce value in micro seconds. 668 * @param p_handle 669 * 670 * @return enum _ecore_status_t 671 **/ 672 enum _ecore_status_t 673 ecore_set_queue_coalesce(struct ecore_hwfn *p_hwfn, u16 rx_coal, 674 u16 tx_coal, void *p_handle); 675 676 /** 677 * @brief ecore_pglueb_set_pfid_enable - Enable or disable PCI BUS MASTER 678 * 679 * @param p_hwfn 680 * @param p_ptt 681 * @param b_enable - true/false 682 * 683 * @return enum _ecore_status_t 684 */ 685 enum _ecore_status_t ecore_pglueb_set_pfid_enable(struct ecore_hwfn *p_hwfn, 686 struct ecore_ptt *p_ptt, 687 bool b_enable); 688 #endif 689