1 /* 2 * Copyright 2015 Amazon.com, Inc. or its affiliates. 3 * 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 * BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 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. 22 * 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 30 * SOFTWARE. 31 */ 32 33 #ifndef ENA_COM 34 #define ENA_COM 35 36 #include <linux/compiler.h> 37 #include <linux/delay.h> 38 #include <linux/dma-mapping.h> 39 #include <linux/gfp.h> 40 #include <linux/io.h> 41 #include <linux/prefetch.h> 42 #include <linux/sched.h> 43 #include <linux/sizes.h> 44 #include <linux/spinlock.h> 45 #include <linux/types.h> 46 #include <linux/wait.h> 47 #include <linux/netdevice.h> 48 49 #include "ena_common_defs.h" 50 #include "ena_admin_defs.h" 51 #include "ena_eth_io_defs.h" 52 #include "ena_regs_defs.h" 53 54 #undef pr_fmt 55 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 56 57 #define ENA_MAX_NUM_IO_QUEUES 128U 58 /* We need to queues for each IO (on for Tx and one for Rx) */ 59 #define ENA_TOTAL_NUM_QUEUES (2 * (ENA_MAX_NUM_IO_QUEUES)) 60 61 #define ENA_MAX_HANDLERS 256 62 63 #define ENA_MAX_PHYS_ADDR_SIZE_BITS 48 64 65 /* Unit in usec */ 66 #define ENA_REG_READ_TIMEOUT 200000 67 68 #define ADMIN_SQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aq_entry)) 69 #define ADMIN_CQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_acq_entry)) 70 #define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry)) 71 72 /*****************************************************************************/ 73 /*****************************************************************************/ 74 /* ENA adaptive interrupt moderation settings */ 75 76 #define ENA_INTR_INITIAL_TX_INTERVAL_USECS 64 77 #define ENA_INTR_INITIAL_RX_INTERVAL_USECS 0 78 #define ENA_DEFAULT_INTR_DELAY_RESOLUTION 1 79 80 #define ENA_HASH_KEY_SIZE 40 81 82 #define ENA_HW_HINTS_NO_TIMEOUT 0xFFFF 83 84 #define ENA_FEATURE_MAX_QUEUE_EXT_VER 1 85 86 struct ena_llq_configurations { 87 enum ena_admin_llq_header_location llq_header_location; 88 enum ena_admin_llq_ring_entry_size llq_ring_entry_size; 89 enum ena_admin_llq_stride_ctrl llq_stride_ctrl; 90 enum ena_admin_llq_num_descs_before_header llq_num_decs_before_header; 91 u16 llq_ring_entry_size_value; 92 }; 93 94 enum queue_direction { 95 ENA_COM_IO_QUEUE_DIRECTION_TX, 96 ENA_COM_IO_QUEUE_DIRECTION_RX 97 }; 98 99 struct ena_com_buf { 100 dma_addr_t paddr; /**< Buffer physical address */ 101 u16 len; /**< Buffer length in bytes */ 102 }; 103 104 struct ena_com_rx_buf_info { 105 u16 len; 106 u16 req_id; 107 }; 108 109 struct ena_com_io_desc_addr { 110 u8 __iomem *pbuf_dev_addr; /* LLQ address */ 111 u8 *virt_addr; 112 dma_addr_t phys_addr; 113 }; 114 115 struct ena_com_tx_meta { 116 u16 mss; 117 u16 l3_hdr_len; 118 u16 l3_hdr_offset; 119 u16 l4_hdr_len; /* In words */ 120 }; 121 122 struct ena_com_llq_info { 123 u16 header_location_ctrl; 124 u16 desc_stride_ctrl; 125 u16 desc_list_entry_size_ctrl; 126 u16 desc_list_entry_size; 127 u16 descs_num_before_header; 128 u16 descs_per_entry; 129 u16 max_entries_in_tx_burst; 130 bool disable_meta_caching; 131 }; 132 133 struct ena_com_io_cq { 134 struct ena_com_io_desc_addr cdesc_addr; 135 136 /* Interrupt unmask register */ 137 u32 __iomem *unmask_reg; 138 139 /* The completion queue head doorbell register */ 140 u32 __iomem *cq_head_db_reg; 141 142 /* numa configuration register (for TPH) */ 143 u32 __iomem *numa_node_cfg_reg; 144 145 /* The value to write to the above register to unmask 146 * the interrupt of this queue 147 */ 148 u32 msix_vector; 149 150 enum queue_direction direction; 151 152 /* holds the number of cdesc of the current packet */ 153 u16 cur_rx_pkt_cdesc_count; 154 /* save the firt cdesc idx of the current packet */ 155 u16 cur_rx_pkt_cdesc_start_idx; 156 157 u16 q_depth; 158 /* Caller qid */ 159 u16 qid; 160 161 /* Device queue index */ 162 u16 idx; 163 u16 head; 164 u16 last_head_update; 165 u8 phase; 166 u8 cdesc_entry_size_in_bytes; 167 168 } ____cacheline_aligned; 169 170 struct ena_com_io_bounce_buffer_control { 171 u8 *base_buffer; 172 u16 next_to_use; 173 u16 buffer_size; 174 u16 buffers_num; /* Must be a power of 2 */ 175 }; 176 177 /* This struct is to keep tracking the current location of the next llq entry */ 178 struct ena_com_llq_pkt_ctrl { 179 u8 *curr_bounce_buf; 180 u16 idx; 181 u16 descs_left_in_line; 182 }; 183 184 struct ena_com_io_sq { 185 struct ena_com_io_desc_addr desc_addr; 186 187 u32 __iomem *db_addr; 188 u8 __iomem *header_addr; 189 190 enum queue_direction direction; 191 enum ena_admin_placement_policy_type mem_queue_type; 192 193 bool disable_meta_caching; 194 195 u32 msix_vector; 196 struct ena_com_tx_meta cached_tx_meta; 197 struct ena_com_llq_info llq_info; 198 struct ena_com_llq_pkt_ctrl llq_buf_ctrl; 199 struct ena_com_io_bounce_buffer_control bounce_buf_ctrl; 200 201 u16 q_depth; 202 u16 qid; 203 204 u16 idx; 205 u16 tail; 206 u16 next_to_comp; 207 u16 llq_last_copy_tail; 208 u32 tx_max_header_size; 209 u8 phase; 210 u8 desc_entry_size; 211 u8 dma_addr_bits; 212 u16 entries_in_tx_burst_left; 213 } ____cacheline_aligned; 214 215 struct ena_com_admin_cq { 216 struct ena_admin_acq_entry *entries; 217 dma_addr_t dma_addr; 218 219 u16 head; 220 u8 phase; 221 }; 222 223 struct ena_com_admin_sq { 224 struct ena_admin_aq_entry *entries; 225 dma_addr_t dma_addr; 226 227 u32 __iomem *db_addr; 228 229 u16 head; 230 u16 tail; 231 u8 phase; 232 233 }; 234 235 struct ena_com_stats_admin { 236 u64 aborted_cmd; 237 u64 submitted_cmd; 238 u64 completed_cmd; 239 u64 out_of_space; 240 u64 no_completion; 241 }; 242 243 struct ena_com_admin_queue { 244 void *q_dmadev; 245 struct ena_com_dev *ena_dev; 246 spinlock_t q_lock; /* spinlock for the admin queue */ 247 248 struct ena_comp_ctx *comp_ctx; 249 u32 completion_timeout; 250 u16 q_depth; 251 struct ena_com_admin_cq cq; 252 struct ena_com_admin_sq sq; 253 254 /* Indicate if the admin queue should poll for completion */ 255 bool polling; 256 257 /* Define if fallback to polling mode should occur */ 258 bool auto_polling; 259 260 u16 curr_cmd_id; 261 262 /* Indicate that the ena was initialized and can 263 * process new admin commands 264 */ 265 bool running_state; 266 267 /* Count the number of outstanding admin commands */ 268 atomic_t outstanding_cmds; 269 270 struct ena_com_stats_admin stats; 271 }; 272 273 struct ena_aenq_handlers; 274 275 struct ena_com_aenq { 276 u16 head; 277 u8 phase; 278 struct ena_admin_aenq_entry *entries; 279 dma_addr_t dma_addr; 280 u16 q_depth; 281 struct ena_aenq_handlers *aenq_handlers; 282 }; 283 284 struct ena_com_mmio_read { 285 struct ena_admin_ena_mmio_req_read_less_resp *read_resp; 286 dma_addr_t read_resp_dma_addr; 287 u32 reg_read_to; /* in us */ 288 u16 seq_num; 289 bool readless_supported; 290 /* spin lock to ensure a single outstanding read */ 291 spinlock_t lock; 292 }; 293 294 struct ena_rss { 295 /* Indirect table */ 296 u16 *host_rss_ind_tbl; 297 struct ena_admin_rss_ind_table_entry *rss_ind_tbl; 298 dma_addr_t rss_ind_tbl_dma_addr; 299 u16 tbl_log_size; 300 301 /* Hash key */ 302 enum ena_admin_hash_functions hash_func; 303 struct ena_admin_feature_rss_flow_hash_control *hash_key; 304 dma_addr_t hash_key_dma_addr; 305 u32 hash_init_val; 306 307 /* Flow Control */ 308 struct ena_admin_feature_rss_hash_control *hash_ctrl; 309 dma_addr_t hash_ctrl_dma_addr; 310 311 }; 312 313 struct ena_host_attribute { 314 /* Debug area */ 315 u8 *debug_area_virt_addr; 316 dma_addr_t debug_area_dma_addr; 317 u32 debug_area_size; 318 319 /* Host information */ 320 struct ena_admin_host_info *host_info; 321 dma_addr_t host_info_dma_addr; 322 }; 323 324 /* Each ena_dev is a PCI function. */ 325 struct ena_com_dev { 326 struct ena_com_admin_queue admin_queue; 327 struct ena_com_aenq aenq; 328 struct ena_com_io_cq io_cq_queues[ENA_TOTAL_NUM_QUEUES]; 329 struct ena_com_io_sq io_sq_queues[ENA_TOTAL_NUM_QUEUES]; 330 u8 __iomem *reg_bar; 331 void __iomem *mem_bar; 332 void *dmadev; 333 334 enum ena_admin_placement_policy_type tx_mem_queue_type; 335 u32 tx_max_header_size; 336 u16 stats_func; /* Selected function for extended statistic dump */ 337 u16 stats_queue; /* Selected queue for extended statistic dump */ 338 339 struct ena_com_mmio_read mmio_read; 340 341 struct ena_rss rss; 342 u32 supported_features; 343 u32 dma_addr_bits; 344 345 struct ena_host_attribute host_attr; 346 bool adaptive_coalescing; 347 u16 intr_delay_resolution; 348 349 /* interrupt moderation intervals are in usec divided by 350 * intr_delay_resolution, which is supplied by the device. 351 */ 352 u32 intr_moder_tx_interval; 353 u32 intr_moder_rx_interval; 354 355 struct ena_intr_moder_entry *intr_moder_tbl; 356 357 struct ena_com_llq_info llq_info; 358 359 u32 ena_min_poll_delay_us; 360 }; 361 362 struct ena_com_dev_get_features_ctx { 363 struct ena_admin_queue_feature_desc max_queues; 364 struct ena_admin_queue_ext_feature_desc max_queue_ext; 365 struct ena_admin_device_attr_feature_desc dev_attr; 366 struct ena_admin_feature_aenq_desc aenq; 367 struct ena_admin_feature_offload_desc offload; 368 struct ena_admin_ena_hw_hints hw_hints; 369 struct ena_admin_feature_llq_desc llq; 370 }; 371 372 struct ena_com_create_io_ctx { 373 enum ena_admin_placement_policy_type mem_queue_type; 374 enum queue_direction direction; 375 int numa_node; 376 u32 msix_vector; 377 u16 queue_size; 378 u16 qid; 379 }; 380 381 typedef void (*ena_aenq_handler)(void *data, 382 struct ena_admin_aenq_entry *aenq_e); 383 384 /* Holds aenq handlers. Indexed by AENQ event group */ 385 struct ena_aenq_handlers { 386 ena_aenq_handler handlers[ENA_MAX_HANDLERS]; 387 ena_aenq_handler unimplemented_handler; 388 }; 389 390 /*****************************************************************************/ 391 /*****************************************************************************/ 392 393 /* ena_com_mmio_reg_read_request_init - Init the mmio reg read mechanism 394 * @ena_dev: ENA communication layer struct 395 * 396 * Initialize the register read mechanism. 397 * 398 * @note: This method must be the first stage in the initialization sequence. 399 * 400 * @return - 0 on success, negative value on failure. 401 */ 402 int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev); 403 404 /* ena_com_set_mmio_read_mode - Enable/disable the indirect mmio reg read mechanism 405 * @ena_dev: ENA communication layer struct 406 * @readless_supported: readless mode (enable/disable) 407 */ 408 void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev, 409 bool readless_supported); 410 411 /* ena_com_mmio_reg_read_request_write_dev_addr - Write the mmio reg read return 412 * value physical address. 413 * @ena_dev: ENA communication layer struct 414 */ 415 void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev); 416 417 /* ena_com_mmio_reg_read_request_destroy - Destroy the mmio reg read mechanism 418 * @ena_dev: ENA communication layer struct 419 */ 420 void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev); 421 422 /* ena_com_admin_init - Init the admin and the async queues 423 * @ena_dev: ENA communication layer struct 424 * @aenq_handlers: Those handlers to be called upon event. 425 * 426 * Initialize the admin submission and completion queues. 427 * Initialize the asynchronous events notification queues. 428 * 429 * @return - 0 on success, negative value on failure. 430 */ 431 int ena_com_admin_init(struct ena_com_dev *ena_dev, 432 struct ena_aenq_handlers *aenq_handlers); 433 434 /* ena_com_admin_destroy - Destroy the admin and the async events queues. 435 * @ena_dev: ENA communication layer struct 436 * 437 * @note: Before calling this method, the caller must validate that the device 438 * won't send any additional admin completions/aenq. 439 * To achieve that, a FLR is recommended. 440 */ 441 void ena_com_admin_destroy(struct ena_com_dev *ena_dev); 442 443 /* ena_com_dev_reset - Perform device FLR to the device. 444 * @ena_dev: ENA communication layer struct 445 * @reset_reason: Specify what is the trigger for the reset in case of an error. 446 * 447 * @return - 0 on success, negative value on failure. 448 */ 449 int ena_com_dev_reset(struct ena_com_dev *ena_dev, 450 enum ena_regs_reset_reason_types reset_reason); 451 452 /* ena_com_create_io_queue - Create io queue. 453 * @ena_dev: ENA communication layer struct 454 * @ctx - create context structure 455 * 456 * Create the submission and the completion queues. 457 * 458 * @return - 0 on success, negative value on failure. 459 */ 460 int ena_com_create_io_queue(struct ena_com_dev *ena_dev, 461 struct ena_com_create_io_ctx *ctx); 462 463 /* ena_com_destroy_io_queue - Destroy IO queue with the queue id - qid. 464 * @ena_dev: ENA communication layer struct 465 * @qid - the caller virtual queue id. 466 */ 467 void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid); 468 469 /* ena_com_get_io_handlers - Return the io queue handlers 470 * @ena_dev: ENA communication layer struct 471 * @qid - the caller virtual queue id. 472 * @io_sq - IO submission queue handler 473 * @io_cq - IO completion queue handler. 474 * 475 * @return - 0 on success, negative value on failure. 476 */ 477 int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid, 478 struct ena_com_io_sq **io_sq, 479 struct ena_com_io_cq **io_cq); 480 481 /* ena_com_admin_aenq_enable - ENAble asynchronous event notifications 482 * @ena_dev: ENA communication layer struct 483 * 484 * After this method, aenq event can be received via AENQ. 485 */ 486 void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev); 487 488 /* ena_com_set_admin_running_state - Set the state of the admin queue 489 * @ena_dev: ENA communication layer struct 490 * 491 * Change the state of the admin queue (enable/disable) 492 */ 493 void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state); 494 495 /* ena_com_get_admin_running_state - Get the admin queue state 496 * @ena_dev: ENA communication layer struct 497 * 498 * Retrieve the state of the admin queue (enable/disable) 499 * 500 * @return - current polling mode (enable/disable) 501 */ 502 bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev); 503 504 /* ena_com_set_admin_polling_mode - Set the admin completion queue polling mode 505 * @ena_dev: ENA communication layer struct 506 * @polling: ENAble/Disable polling mode 507 * 508 * Set the admin completion mode. 509 */ 510 void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling); 511 512 /* ena_com_set_admin_auto_polling_mode - Enable autoswitch to polling mode 513 * @ena_dev: ENA communication layer struct 514 * @polling: Enable/Disable polling mode 515 * 516 * Set the autopolling mode. 517 * If autopolling is on: 518 * In case of missing interrupt when data is available switch to polling. 519 */ 520 void ena_com_set_admin_auto_polling_mode(struct ena_com_dev *ena_dev, 521 bool polling); 522 523 /* ena_com_admin_q_comp_intr_handler - admin queue interrupt handler 524 * @ena_dev: ENA communication layer struct 525 * 526 * This method goes over the admin completion queue and wakes up all the pending 527 * threads that wait on the commands wait event. 528 * 529 * @note: Should be called after MSI-X interrupt. 530 */ 531 void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev); 532 533 /* ena_com_aenq_intr_handler - AENQ interrupt handler 534 * @ena_dev: ENA communication layer struct 535 * 536 * This method goes over the async event notification queue and calls the proper 537 * aenq handler. 538 */ 539 void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data); 540 541 /* ena_com_abort_admin_commands - Abort all the outstanding admin commands. 542 * @ena_dev: ENA communication layer struct 543 * 544 * This method aborts all the outstanding admin commands. 545 * The caller should then call ena_com_wait_for_abort_completion to make sure 546 * all the commands were completed. 547 */ 548 void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev); 549 550 /* ena_com_wait_for_abort_completion - Wait for admin commands abort. 551 * @ena_dev: ENA communication layer struct 552 * 553 * This method waits until all the outstanding admin commands are completed. 554 */ 555 void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev); 556 557 /* ena_com_validate_version - Validate the device parameters 558 * @ena_dev: ENA communication layer struct 559 * 560 * This method verifies the device parameters are the same as the saved 561 * parameters in ena_dev. 562 * This method is useful after device reset, to validate the device mac address 563 * and the device offloads are the same as before the reset. 564 * 565 * @return - 0 on success negative value otherwise. 566 */ 567 int ena_com_validate_version(struct ena_com_dev *ena_dev); 568 569 /* ena_com_get_link_params - Retrieve physical link parameters. 570 * @ena_dev: ENA communication layer struct 571 * @resp: Link parameters 572 * 573 * Retrieve the physical link parameters, 574 * like speed, auto-negotiation and full duplex support. 575 * 576 * @return - 0 on Success negative value otherwise. 577 */ 578 int ena_com_get_link_params(struct ena_com_dev *ena_dev, 579 struct ena_admin_get_feat_resp *resp); 580 581 /* ena_com_get_dma_width - Retrieve physical dma address width the device 582 * supports. 583 * @ena_dev: ENA communication layer struct 584 * 585 * Retrieve the maximum physical address bits the device can handle. 586 * 587 * @return: > 0 on Success and negative value otherwise. 588 */ 589 int ena_com_get_dma_width(struct ena_com_dev *ena_dev); 590 591 /* ena_com_set_aenq_config - Set aenq groups configurations 592 * @ena_dev: ENA communication layer struct 593 * @groups flag: bit fields flags of enum ena_admin_aenq_group. 594 * 595 * Configure which aenq event group the driver would like to receive. 596 * 597 * @return: 0 on Success and negative value otherwise. 598 */ 599 int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag); 600 601 /* ena_com_get_dev_attr_feat - Get device features 602 * @ena_dev: ENA communication layer struct 603 * @get_feat_ctx: returned context that contain the get features. 604 * 605 * @return: 0 on Success and negative value otherwise. 606 */ 607 int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev, 608 struct ena_com_dev_get_features_ctx *get_feat_ctx); 609 610 /* ena_com_get_dev_basic_stats - Get device basic statistics 611 * @ena_dev: ENA communication layer struct 612 * @stats: stats return value 613 * 614 * @return: 0 on Success and negative value otherwise. 615 */ 616 int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev, 617 struct ena_admin_basic_stats *stats); 618 619 /* ena_com_get_eni_stats - Get extended network interface statistics 620 * @ena_dev: ENA communication layer struct 621 * @stats: stats return value 622 * 623 * @return: 0 on Success and negative value otherwise. 624 */ 625 int ena_com_get_eni_stats(struct ena_com_dev *ena_dev, 626 struct ena_admin_eni_stats *stats); 627 628 /* ena_com_set_dev_mtu - Configure the device mtu. 629 * @ena_dev: ENA communication layer struct 630 * @mtu: mtu value 631 * 632 * @return: 0 on Success and negative value otherwise. 633 */ 634 int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu); 635 636 /* ena_com_get_offload_settings - Retrieve the device offloads capabilities 637 * @ena_dev: ENA communication layer struct 638 * @offlad: offload return value 639 * 640 * @return: 0 on Success and negative value otherwise. 641 */ 642 int ena_com_get_offload_settings(struct ena_com_dev *ena_dev, 643 struct ena_admin_feature_offload_desc *offload); 644 645 /* ena_com_rss_init - Init RSS 646 * @ena_dev: ENA communication layer struct 647 * @log_size: indirection log size 648 * 649 * Allocate RSS/RFS resources. 650 * The caller then can configure rss using ena_com_set_hash_function, 651 * ena_com_set_hash_ctrl and ena_com_indirect_table_set. 652 * 653 * @return: 0 on Success and negative value otherwise. 654 */ 655 int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size); 656 657 /* ena_com_rss_destroy - Destroy rss 658 * @ena_dev: ENA communication layer struct 659 * 660 * Free all the RSS/RFS resources. 661 */ 662 void ena_com_rss_destroy(struct ena_com_dev *ena_dev); 663 664 /* ena_com_get_current_hash_function - Get RSS hash function 665 * @ena_dev: ENA communication layer struct 666 * 667 * Return the current hash function. 668 * @return: 0 or one of the ena_admin_hash_functions values. 669 */ 670 int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev); 671 672 /* ena_com_fill_hash_function - Fill RSS hash function 673 * @ena_dev: ENA communication layer struct 674 * @func: The hash function (Toeplitz or crc) 675 * @key: Hash key (for toeplitz hash) 676 * @key_len: key length (max length 10 DW) 677 * @init_val: initial value for the hash function 678 * 679 * Fill the ena_dev resources with the desire hash function, hash key, key_len 680 * and key initial value (if needed by the hash function). 681 * To flush the key into the device the caller should call 682 * ena_com_set_hash_function. 683 * 684 * @return: 0 on Success and negative value otherwise. 685 */ 686 int ena_com_fill_hash_function(struct ena_com_dev *ena_dev, 687 enum ena_admin_hash_functions func, 688 const u8 *key, u16 key_len, u32 init_val); 689 690 /* ena_com_set_hash_function - Flush the hash function and it dependencies to 691 * the device. 692 * @ena_dev: ENA communication layer struct 693 * 694 * Flush the hash function and it dependencies (key, key length and 695 * initial value) if needed. 696 * 697 * @note: Prior to this method the caller should call ena_com_fill_hash_function 698 * 699 * @return: 0 on Success and negative value otherwise. 700 */ 701 int ena_com_set_hash_function(struct ena_com_dev *ena_dev); 702 703 /* ena_com_get_hash_function - Retrieve the hash function from the device. 704 * @ena_dev: ENA communication layer struct 705 * @func: hash function 706 * 707 * Retrieve the hash function from the device. 708 * 709 * @note: If the caller called ena_com_fill_hash_function but didn't flush 710 * it to the device, the new configuration will be lost. 711 * 712 * @return: 0 on Success and negative value otherwise. 713 */ 714 int ena_com_get_hash_function(struct ena_com_dev *ena_dev, 715 enum ena_admin_hash_functions *func); 716 717 /* ena_com_get_hash_key - Retrieve the hash key 718 * @ena_dev: ENA communication layer struct 719 * @key: hash key 720 * 721 * Retrieve the hash key. 722 * 723 * @note: If the caller called ena_com_fill_hash_key but didn't flush 724 * it to the device, the new configuration will be lost. 725 * 726 * @return: 0 on Success and negative value otherwise. 727 */ 728 int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key); 729 /* ena_com_fill_hash_ctrl - Fill RSS hash control 730 * @ena_dev: ENA communication layer struct. 731 * @proto: The protocol to configure. 732 * @hash_fields: bit mask of ena_admin_flow_hash_fields 733 * 734 * Fill the ena_dev resources with the desire hash control (the ethernet 735 * fields that take part of the hash) for a specific protocol. 736 * To flush the hash control to the device, the caller should call 737 * ena_com_set_hash_ctrl. 738 * 739 * @return: 0 on Success and negative value otherwise. 740 */ 741 int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev, 742 enum ena_admin_flow_hash_proto proto, 743 u16 hash_fields); 744 745 /* ena_com_set_hash_ctrl - Flush the hash control resources to the device. 746 * @ena_dev: ENA communication layer struct 747 * 748 * Flush the hash control (the ethernet fields that take part of the hash) 749 * 750 * @note: Prior to this method the caller should call ena_com_fill_hash_ctrl. 751 * 752 * @return: 0 on Success and negative value otherwise. 753 */ 754 int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev); 755 756 /* ena_com_get_hash_ctrl - Retrieve the hash control from the device. 757 * @ena_dev: ENA communication layer struct 758 * @proto: The protocol to retrieve. 759 * @fields: bit mask of ena_admin_flow_hash_fields. 760 * 761 * Retrieve the hash control from the device. 762 * 763 * @note: If the caller called ena_com_fill_hash_ctrl but didn't flush 764 * it to the device, the new configuration will be lost. 765 * 766 * @return: 0 on Success and negative value otherwise. 767 */ 768 int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev, 769 enum ena_admin_flow_hash_proto proto, 770 u16 *fields); 771 772 /* ena_com_set_default_hash_ctrl - Set the hash control to a default 773 * configuration. 774 * @ena_dev: ENA communication layer struct 775 * 776 * Fill the ena_dev resources with the default hash control configuration. 777 * To flush the hash control to the device, the caller should call 778 * ena_com_set_hash_ctrl. 779 * 780 * @return: 0 on Success and negative value otherwise. 781 */ 782 int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev); 783 784 /* ena_com_indirect_table_fill_entry - Fill a single entry in the RSS 785 * indirection table 786 * @ena_dev: ENA communication layer struct. 787 * @entry_idx - indirection table entry. 788 * @entry_value - redirection value 789 * 790 * Fill a single entry of the RSS indirection table in the ena_dev resources. 791 * To flush the indirection table to the device, the called should call 792 * ena_com_indirect_table_set. 793 * 794 * @return: 0 on Success and negative value otherwise. 795 */ 796 int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev, 797 u16 entry_idx, u16 entry_value); 798 799 /* ena_com_indirect_table_set - Flush the indirection table to the device. 800 * @ena_dev: ENA communication layer struct 801 * 802 * Flush the indirection hash control to the device. 803 * Prior to this method the caller should call ena_com_indirect_table_fill_entry 804 * 805 * @return: 0 on Success and negative value otherwise. 806 */ 807 int ena_com_indirect_table_set(struct ena_com_dev *ena_dev); 808 809 /* ena_com_indirect_table_get - Retrieve the indirection table from the device. 810 * @ena_dev: ENA communication layer struct 811 * @ind_tbl: indirection table 812 * 813 * Retrieve the RSS indirection table from the device. 814 * 815 * @note: If the caller called ena_com_indirect_table_fill_entry but didn't flush 816 * it to the device, the new configuration will be lost. 817 * 818 * @return: 0 on Success and negative value otherwise. 819 */ 820 int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl); 821 822 /* ena_com_allocate_host_info - Allocate host info resources. 823 * @ena_dev: ENA communication layer struct 824 * 825 * @return: 0 on Success and negative value otherwise. 826 */ 827 int ena_com_allocate_host_info(struct ena_com_dev *ena_dev); 828 829 /* ena_com_allocate_debug_area - Allocate debug area. 830 * @ena_dev: ENA communication layer struct 831 * @debug_area_size - debug area size. 832 * 833 * @return: 0 on Success and negative value otherwise. 834 */ 835 int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev, 836 u32 debug_area_size); 837 838 /* ena_com_delete_debug_area - Free the debug area resources. 839 * @ena_dev: ENA communication layer struct 840 * 841 * Free the allocated debug area. 842 */ 843 void ena_com_delete_debug_area(struct ena_com_dev *ena_dev); 844 845 /* ena_com_delete_host_info - Free the host info resources. 846 * @ena_dev: ENA communication layer struct 847 * 848 * Free the allocated host info. 849 */ 850 void ena_com_delete_host_info(struct ena_com_dev *ena_dev); 851 852 /* ena_com_set_host_attributes - Update the device with the host 853 * attributes (debug area and host info) base address. 854 * @ena_dev: ENA communication layer struct 855 * 856 * @return: 0 on Success and negative value otherwise. 857 */ 858 int ena_com_set_host_attributes(struct ena_com_dev *ena_dev); 859 860 /* ena_com_create_io_cq - Create io completion queue. 861 * @ena_dev: ENA communication layer struct 862 * @io_cq - io completion queue handler 863 864 * Create IO completion queue. 865 * 866 * @return - 0 on success, negative value on failure. 867 */ 868 int ena_com_create_io_cq(struct ena_com_dev *ena_dev, 869 struct ena_com_io_cq *io_cq); 870 871 /* ena_com_destroy_io_cq - Destroy io completion queue. 872 * @ena_dev: ENA communication layer struct 873 * @io_cq - io completion queue handler 874 875 * Destroy IO completion queue. 876 * 877 * @return - 0 on success, negative value on failure. 878 */ 879 int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev, 880 struct ena_com_io_cq *io_cq); 881 882 /* ena_com_execute_admin_command - Execute admin command 883 * @admin_queue: admin queue. 884 * @cmd: the admin command to execute. 885 * @cmd_size: the command size. 886 * @cmd_completion: command completion return value. 887 * @cmd_comp_size: command completion size. 888 889 * Submit an admin command and then wait until the device returns a 890 * completion. 891 * The completion will be copied into cmd_comp. 892 * 893 * @return - 0 on success, negative value on failure. 894 */ 895 int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue, 896 struct ena_admin_aq_entry *cmd, 897 size_t cmd_size, 898 struct ena_admin_acq_entry *cmd_comp, 899 size_t cmd_comp_size); 900 901 /* ena_com_init_interrupt_moderation - Init interrupt moderation 902 * @ena_dev: ENA communication layer struct 903 * 904 * @return - 0 on success, negative value on failure. 905 */ 906 int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev); 907 908 /* ena_com_interrupt_moderation_supported - Return if interrupt moderation 909 * capability is supported by the device. 910 * 911 * @return - supported or not. 912 */ 913 bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev); 914 915 /* ena_com_update_nonadaptive_moderation_interval_tx - Update the 916 * non-adaptive interval in Tx direction. 917 * @ena_dev: ENA communication layer struct 918 * @tx_coalesce_usecs: Interval in usec. 919 * 920 * @return - 0 on success, negative value on failure. 921 */ 922 int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev, 923 u32 tx_coalesce_usecs); 924 925 /* ena_com_update_nonadaptive_moderation_interval_rx - Update the 926 * non-adaptive interval in Rx direction. 927 * @ena_dev: ENA communication layer struct 928 * @rx_coalesce_usecs: Interval in usec. 929 * 930 * @return - 0 on success, negative value on failure. 931 */ 932 int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev, 933 u32 rx_coalesce_usecs); 934 935 /* ena_com_get_nonadaptive_moderation_interval_tx - Retrieve the 936 * non-adaptive interval in Tx direction. 937 * @ena_dev: ENA communication layer struct 938 * 939 * @return - interval in usec 940 */ 941 unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev); 942 943 /* ena_com_get_nonadaptive_moderation_interval_rx - Retrieve the 944 * non-adaptive interval in Rx direction. 945 * @ena_dev: ENA communication layer struct 946 * 947 * @return - interval in usec 948 */ 949 unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev); 950 951 /* ena_com_config_dev_mode - Configure the placement policy of the device. 952 * @ena_dev: ENA communication layer struct 953 * @llq_features: LLQ feature descriptor, retrieve via 954 * ena_com_get_dev_attr_feat. 955 * @ena_llq_config: The default driver LLQ parameters configurations 956 */ 957 int ena_com_config_dev_mode(struct ena_com_dev *ena_dev, 958 struct ena_admin_feature_llq_desc *llq_features, 959 struct ena_llq_configurations *llq_default_config); 960 961 static inline bool ena_com_get_adaptive_moderation_enabled(struct ena_com_dev *ena_dev) 962 { 963 return ena_dev->adaptive_coalescing; 964 } 965 966 static inline void ena_com_enable_adaptive_moderation(struct ena_com_dev *ena_dev) 967 { 968 ena_dev->adaptive_coalescing = true; 969 } 970 971 static inline void ena_com_disable_adaptive_moderation(struct ena_com_dev *ena_dev) 972 { 973 ena_dev->adaptive_coalescing = false; 974 } 975 976 /* ena_com_update_intr_reg - Prepare interrupt register 977 * @intr_reg: interrupt register to update. 978 * @rx_delay_interval: Rx interval in usecs 979 * @tx_delay_interval: Tx interval in usecs 980 * @unmask: unmask enable/disable 981 * 982 * Prepare interrupt update register with the supplied parameters. 983 */ 984 static inline void ena_com_update_intr_reg(struct ena_eth_io_intr_reg *intr_reg, 985 u32 rx_delay_interval, 986 u32 tx_delay_interval, 987 bool unmask) 988 { 989 intr_reg->intr_control = 0; 990 intr_reg->intr_control |= rx_delay_interval & 991 ENA_ETH_IO_INTR_REG_RX_INTR_DELAY_MASK; 992 993 intr_reg->intr_control |= 994 (tx_delay_interval << ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_SHIFT) 995 & ENA_ETH_IO_INTR_REG_TX_INTR_DELAY_MASK; 996 997 if (unmask) 998 intr_reg->intr_control |= ENA_ETH_IO_INTR_REG_INTR_UNMASK_MASK; 999 } 1000 1001 static inline u8 *ena_com_get_next_bounce_buffer(struct ena_com_io_bounce_buffer_control *bounce_buf_ctrl) 1002 { 1003 u16 size, buffers_num; 1004 u8 *buf; 1005 1006 size = bounce_buf_ctrl->buffer_size; 1007 buffers_num = bounce_buf_ctrl->buffers_num; 1008 1009 buf = bounce_buf_ctrl->base_buffer + 1010 (bounce_buf_ctrl->next_to_use++ & (buffers_num - 1)) * size; 1011 1012 prefetchw(bounce_buf_ctrl->base_buffer + 1013 (bounce_buf_ctrl->next_to_use & (buffers_num - 1)) * size); 1014 1015 return buf; 1016 } 1017 1018 #endif /* !(ENA_COM) */ 1019