1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT) 2 * Google virtual Ethernet (gve) driver 3 * 4 * Copyright (C) 2015-2024 Google LLC 5 */ 6 7 #ifndef _GVE_H_ 8 #define _GVE_H_ 9 10 #include <linux/dma-mapping.h> 11 #include <linux/dmapool.h> 12 #include <linux/ethtool_netlink.h> 13 #include <linux/netdevice.h> 14 #include <linux/net_tstamp.h> 15 #include <linux/pci.h> 16 #include <linux/ptp_clock_kernel.h> 17 #include <linux/u64_stats_sync.h> 18 #include <net/page_pool/helpers.h> 19 #include <net/xdp.h> 20 21 #include "gve_desc.h" 22 #include "gve_desc_dqo.h" 23 24 #ifndef PCI_VENDOR_ID_GOOGLE 25 #define PCI_VENDOR_ID_GOOGLE 0x1ae0 26 #endif 27 28 #define PCI_DEV_ID_GVNIC 0x0042 29 30 #define GVE_REGISTER_BAR 0 31 #define GVE_DOORBELL_BAR 2 32 33 /* Driver can alloc up to 2 segments for the header and 2 for the payload. */ 34 #define GVE_TX_MAX_IOVEC 4 35 /* 1 for management, 1 for rx, 1 for tx */ 36 #define GVE_MIN_MSIX 3 37 38 /* Numbers of gve tx/rx stats in stats report. */ 39 #define GVE_TX_STATS_REPORT_NUM 6 40 #define GVE_RX_STATS_REPORT_NUM 2 41 42 /* Interval to schedule a stats report update, 20000ms. */ 43 #define GVE_STATS_REPORT_TIMER_PERIOD 20000 44 45 /* Numbers of NIC tx/rx stats in stats report. */ 46 #define NIC_TX_STATS_REPORT_NUM 0 47 #define NIC_RX_STATS_REPORT_NUM 4 48 49 #define GVE_ADMINQ_BUFFER_SIZE 4096 50 51 #define GVE_DATA_SLOT_ADDR_PAGE_MASK (~(PAGE_SIZE - 1)) 52 53 /* PTYPEs are always 10 bits. */ 54 #define GVE_NUM_PTYPES 1024 55 56 /* Default minimum ring size */ 57 #define GVE_DEFAULT_MIN_TX_RING_SIZE 256 58 #define GVE_DEFAULT_MIN_RX_RING_SIZE 512 59 60 #define GVE_DEFAULT_RX_BUFFER_SIZE 2048 61 62 #define GVE_XDP_RX_BUFFER_SIZE_DQO 4096 63 64 #define GVE_DEFAULT_RX_BUFFER_OFFSET 2048 65 66 #define GVE_PAGE_POOL_SIZE_MULTIPLIER 4 67 68 #define GVE_FLOW_RULES_CACHE_SIZE \ 69 (GVE_ADMINQ_BUFFER_SIZE / sizeof(struct gve_adminq_queried_flow_rule)) 70 #define GVE_FLOW_RULE_IDS_CACHE_SIZE \ 71 (GVE_ADMINQ_BUFFER_SIZE / sizeof(((struct gve_adminq_queried_flow_rule *)0)->location)) 72 73 #define GVE_RSS_KEY_SIZE 40 74 #define GVE_RSS_INDIR_SIZE 128 75 76 #define GVE_XDP_ACTIONS 5 77 78 #define GVE_GQ_TX_MIN_PKT_DESC_BYTES 182 79 80 #define GVE_DEFAULT_HEADER_BUFFER_SIZE 128 81 82 /* Maximum TSO size supported on DQO */ 83 #define GVE_DQO_TX_MAX 0x3FFFF 84 85 #define GVE_TX_BUF_SHIFT_DQO 11 86 87 /* 2K buffers for DQO-QPL */ 88 #define GVE_TX_BUF_SIZE_DQO BIT(GVE_TX_BUF_SHIFT_DQO) 89 #define GVE_TX_BUFS_PER_PAGE_DQO (PAGE_SIZE >> GVE_TX_BUF_SHIFT_DQO) 90 #define GVE_MAX_TX_BUFS_PER_PKT (DIV_ROUND_UP(GVE_DQO_TX_MAX, GVE_TX_BUF_SIZE_DQO)) 91 92 /* If number of free/recyclable buffers are less than this threshold; driver 93 * allocs and uses a non-qpl page on the receive path of DQO QPL to free 94 * up buffers. 95 * Value is set big enough to post at least 3 64K LRO packet via 2K buffer to NIC. 96 */ 97 #define GVE_DQO_QPL_ONDEMAND_ALLOC_THRESHOLD 96 98 99 #define GVE_DQO_RX_HWTSTAMP_VALID 0x1 100 101 /* Each slot in the desc ring has a 1:1 mapping to a slot in the data ring */ 102 struct gve_rx_desc_queue { 103 struct gve_rx_desc *desc_ring; /* the descriptor ring */ 104 dma_addr_t bus; /* the bus for the desc_ring */ 105 u8 seqno; /* the next expected seqno for this desc*/ 106 }; 107 108 /* The page info for a single slot in the RX data queue */ 109 struct gve_rx_slot_page_info { 110 /* netmem is used for DQO RDA mode 111 * page is used in all other modes 112 */ 113 union { 114 struct page *page; 115 netmem_ref netmem; 116 }; 117 void *page_address; 118 u32 page_offset; /* offset to write to in page */ 119 unsigned int buf_size; 120 int pagecnt_bias; /* expected pagecnt if only the driver has a ref */ 121 u16 pad; /* adjustment for rx padding */ 122 u8 can_flip; /* tracks if the networking stack is using the page */ 123 }; 124 125 /* A list of pages registered with the device during setup and used by a queue 126 * as buffers 127 */ 128 struct gve_queue_page_list { 129 u32 id; /* unique id */ 130 u32 num_entries; 131 struct page **pages; /* list of num_entries pages */ 132 dma_addr_t *page_buses; /* the dma addrs of the pages */ 133 }; 134 135 /* Each slot in the data ring has a 1:1 mapping to a slot in the desc ring */ 136 struct gve_rx_data_queue { 137 union gve_rx_data_slot *data_ring; /* read by NIC */ 138 dma_addr_t data_bus; /* dma mapping of the slots */ 139 struct gve_rx_slot_page_info *page_info; /* page info of the buffers */ 140 struct gve_queue_page_list *qpl; /* qpl assigned to this queue */ 141 u8 raw_addressing; /* use raw_addressing? */ 142 }; 143 144 struct gve_priv; 145 146 /* RX buffer queue for posting buffers to HW. 147 * Each RX (completion) queue has a corresponding buffer queue. 148 */ 149 struct gve_rx_buf_queue_dqo { 150 struct gve_rx_desc_dqo *desc_ring; 151 dma_addr_t bus; 152 u32 head; /* Pointer to start cleaning buffers at. */ 153 u32 tail; /* Last posted buffer index + 1 */ 154 u32 mask; /* Mask for indices to the size of the ring */ 155 }; 156 157 /* RX completion queue to receive packets from HW. */ 158 struct gve_rx_compl_queue_dqo { 159 struct gve_rx_compl_desc_dqo *desc_ring; 160 dma_addr_t bus; 161 162 /* Number of slots which did not have a buffer posted yet. We should not 163 * post more buffers than the queue size to avoid HW overrunning the 164 * queue. 165 */ 166 int num_free_slots; 167 168 /* HW uses a "generation bit" to notify SW of new descriptors. When a 169 * descriptor's generation bit is different from the current generation, 170 * that descriptor is ready to be consumed by SW. 171 */ 172 u8 cur_gen_bit; 173 174 /* Pointer into desc_ring where the next completion descriptor will be 175 * received. 176 */ 177 u32 head; 178 u32 mask; /* Mask for indices to the size of the ring */ 179 }; 180 181 struct gve_header_buf { 182 u8 *data; 183 dma_addr_t addr; 184 }; 185 186 /* Stores state for tracking buffers posted to HW */ 187 struct gve_rx_buf_state_dqo { 188 /* The page posted to HW. */ 189 struct gve_rx_slot_page_info page_info; 190 191 /* XSK buffer */ 192 struct xdp_buff *xsk_buff; 193 194 /* The DMA address corresponding to `page_info`. */ 195 dma_addr_t addr; 196 197 /* Last offset into the page when it only had a single reference, at 198 * which point every other offset is free to be reused. 199 */ 200 u32 last_single_ref_offset; 201 202 /* Linked list index to next element in the list, or -1 if none */ 203 s16 next; 204 }; 205 206 /* Wrapper for XDP Rx metadata */ 207 struct gve_xdp_buff { 208 struct xdp_buff xdp; 209 struct gve_priv *gve; 210 const struct gve_rx_compl_desc_dqo *compl_desc; 211 }; 212 213 /* `head` and `tail` are indices into an array, or -1 if empty. */ 214 struct gve_index_list { 215 s16 head; 216 s16 tail; 217 }; 218 219 /* A single received packet split across multiple buffers may be 220 * reconstructed using the information in this structure. 221 */ 222 struct gve_rx_ctx { 223 /* head and tail of skb chain for the current packet or NULL if none */ 224 struct sk_buff *skb_head; 225 struct sk_buff *skb_tail; 226 u32 total_size; 227 u8 frag_cnt; 228 bool drop_pkt; 229 }; 230 231 struct gve_rx_cnts { 232 u32 ok_pkt_bytes; 233 u16 ok_pkt_cnt; 234 u16 total_pkt_cnt; 235 u16 cont_pkt_cnt; 236 u16 desc_err_pkt_cnt; 237 }; 238 239 /* Contains datapath state used to represent an RX queue. */ 240 struct gve_rx_ring { 241 struct gve_priv *gve; 242 243 u16 packet_buffer_size; /* Size of buffer posted to NIC */ 244 u16 packet_buffer_truesize; /* Total size of RX buffer */ 245 u16 rx_headroom; 246 247 union { 248 /* GQI fields */ 249 struct { 250 struct gve_rx_desc_queue desc; 251 struct gve_rx_data_queue data; 252 253 /* threshold for posting new buffs and descs */ 254 u32 db_threshold; 255 256 u32 qpl_copy_pool_mask; 257 u32 qpl_copy_pool_head; 258 struct gve_rx_slot_page_info *qpl_copy_pool; 259 }; 260 261 /* DQO fields. */ 262 struct { 263 struct gve_rx_buf_queue_dqo bufq; 264 struct gve_rx_compl_queue_dqo complq; 265 266 struct gve_rx_buf_state_dqo *buf_states; 267 u16 num_buf_states; 268 269 /* Linked list of gve_rx_buf_state_dqo. Index into 270 * buf_states, or -1 if empty. 271 */ 272 s16 free_buf_states; 273 274 /* Linked list of gve_rx_buf_state_dqo. Indexes into 275 * buf_states, or -1 if empty. 276 * 277 * This list contains buf_states which are pointing to 278 * valid buffers. 279 * 280 * We use a FIFO here in order to increase the 281 * probability that buffers can be reused by increasing 282 * the time between usages. 283 */ 284 struct gve_index_list recycled_buf_states; 285 286 /* Linked list of gve_rx_buf_state_dqo. Indexes into 287 * buf_states, or -1 if empty. 288 * 289 * This list contains buf_states which have buffers 290 * which cannot be reused yet. 291 */ 292 struct gve_index_list used_buf_states; 293 294 /* qpl assigned to this queue */ 295 struct gve_queue_page_list *qpl; 296 297 /* index into queue page list */ 298 u32 next_qpl_page_idx; 299 300 /* track number of used buffers */ 301 u16 used_buf_states_cnt; 302 303 /* Address info of the buffers for header-split */ 304 struct gve_header_buf hdr_bufs; 305 306 struct page_pool *page_pool; 307 } dqo; 308 }; 309 310 u64 rbytes; /* free-running bytes received */ 311 u64 rx_hsplit_bytes; /* free-running header bytes received */ 312 u64 rpackets; /* free-running packets received */ 313 u32 cnt; /* free-running total number of completed packets */ 314 u32 fill_cnt; /* free-running total number of descs and buffs posted */ 315 u32 mask; /* masks the cnt and fill_cnt to the size of the ring */ 316 u64 rx_hsplit_pkt; /* free-running packets with headers split */ 317 u64 rx_copybreak_pkt; /* free-running count of copybreak packets */ 318 u64 rx_copied_pkt; /* free-running total number of copied packets */ 319 u64 rx_skb_alloc_fail; /* free-running count of skb alloc fails */ 320 u64 rx_buf_alloc_fail; /* free-running count of buffer alloc fails */ 321 u64 rx_desc_err_dropped_pkt; /* free-running count of packets dropped by descriptor error */ 322 /* free-running count of unsplit packets due to header buffer overflow or hdr_len is 0 */ 323 u64 rx_hsplit_unsplit_pkt; 324 u64 rx_cont_packet_cnt; /* free-running multi-fragment packets received */ 325 u64 rx_frag_flip_cnt; /* free-running count of rx segments where page_flip was used */ 326 u64 rx_frag_copy_cnt; /* free-running count of rx segments copied */ 327 u64 rx_frag_alloc_cnt; /* free-running count of rx page allocations */ 328 u64 xdp_tx_errors; 329 u64 xdp_redirect_errors; 330 u64 xdp_alloc_fails; 331 u64 xdp_actions[GVE_XDP_ACTIONS]; 332 u32 q_num; /* queue index */ 333 u32 ntfy_id; /* notification block index */ 334 struct gve_queue_resources *q_resources; /* head and tail pointer idx */ 335 dma_addr_t q_resources_bus; /* dma address for the queue resources */ 336 struct u64_stats_sync statss; /* sync stats for 32bit archs */ 337 338 struct gve_rx_ctx ctx; /* Info for packet currently being processed in this ring. */ 339 340 /* XDP stuff */ 341 struct xdp_rxq_info xdp_rxq; 342 struct xsk_buff_pool *xsk_pool; 343 struct page_frag_cache page_cache; /* Page cache to allocate XDP frames */ 344 }; 345 346 /* A TX desc ring entry */ 347 union gve_tx_desc { 348 struct gve_tx_pkt_desc pkt; /* first desc for a packet */ 349 struct gve_tx_mtd_desc mtd; /* optional metadata descriptor */ 350 struct gve_tx_seg_desc seg; /* subsequent descs for a packet */ 351 }; 352 353 /* Tracks the memory in the fifo occupied by a segment of a packet */ 354 struct gve_tx_iovec { 355 u32 iov_offset; /* offset into this segment */ 356 u32 iov_len; /* length */ 357 u32 iov_padding; /* padding associated with this segment */ 358 }; 359 360 /* Tracks the memory in the fifo occupied by the skb. Mapped 1:1 to a desc 361 * ring entry but only used for a pkt_desc not a seg_desc 362 */ 363 struct gve_tx_buffer_state { 364 union { 365 struct sk_buff *skb; /* skb for this pkt */ 366 struct xdp_frame *xdp_frame; /* xdp_frame */ 367 }; 368 struct { 369 u16 size; /* size of xmitted xdp pkt */ 370 u8 is_xsk; /* xsk buff */ 371 } xdp; 372 union { 373 struct gve_tx_iovec iov[GVE_TX_MAX_IOVEC]; /* segments of this pkt */ 374 struct { 375 DEFINE_DMA_UNMAP_ADDR(dma); 376 DEFINE_DMA_UNMAP_LEN(len); 377 }; 378 }; 379 }; 380 381 /* A TX buffer - each queue has one */ 382 struct gve_tx_fifo { 383 void *base; /* address of base of FIFO */ 384 u32 size; /* total size */ 385 atomic_t available; /* how much space is still available */ 386 u32 head; /* offset to write at */ 387 struct gve_queue_page_list *qpl; /* QPL mapped into this FIFO */ 388 }; 389 390 /* TX descriptor for DQO format */ 391 union gve_tx_desc_dqo { 392 struct gve_tx_pkt_desc_dqo pkt; 393 struct gve_tx_tso_context_desc_dqo tso_ctx; 394 struct gve_tx_general_context_desc_dqo general_ctx; 395 }; 396 397 enum gve_packet_state { 398 /* Packet is in free list, available to be allocated. 399 * This should always be zero since state is not explicitly initialized. 400 */ 401 GVE_PACKET_STATE_UNALLOCATED, 402 /* Packet is expecting a regular data completion or miss completion */ 403 GVE_PACKET_STATE_PENDING_DATA_COMPL, 404 /* Packet has received a miss completion and is expecting a 405 * re-injection completion. 406 */ 407 GVE_PACKET_STATE_PENDING_REINJECT_COMPL, 408 /* No valid completion received within the specified timeout. */ 409 GVE_PACKET_STATE_TIMED_OUT_COMPL, 410 /* XSK pending packet has received a packet/reinjection completion, or 411 * has timed out. At this point, the pending packet can be counted by 412 * xsk_tx_complete and freed. 413 */ 414 GVE_PACKET_STATE_XSK_COMPLETE, 415 }; 416 417 enum gve_tx_pending_packet_dqo_type { 418 GVE_TX_PENDING_PACKET_DQO_SKB, 419 GVE_TX_PENDING_PACKET_DQO_XDP_FRAME, 420 GVE_TX_PENDING_PACKET_DQO_XSK, 421 }; 422 423 struct gve_tx_pending_packet_dqo { 424 union { 425 struct sk_buff *skb; 426 struct xdp_frame *xdpf; 427 }; 428 429 /* 0th element corresponds to the linear portion of `skb`, should be 430 * unmapped with `dma_unmap_single`. 431 * 432 * All others correspond to `skb`'s frags and should be unmapped with 433 * `dma_unmap_page`. 434 */ 435 union { 436 struct { 437 DEFINE_DMA_UNMAP_ADDR(dma[MAX_SKB_FRAGS + 1]); 438 DEFINE_DMA_UNMAP_LEN(len[MAX_SKB_FRAGS + 1]); 439 }; 440 s16 tx_qpl_buf_ids[GVE_MAX_TX_BUFS_PER_PKT]; 441 }; 442 443 u16 num_bufs; 444 445 /* Linked list index to next element in the list, or -1 if none */ 446 s16 next; 447 448 /* Linked list index to prev element in the list, or -1 if none. 449 * Used for tracking either outstanding miss completions or prematurely 450 * freed packets. 451 */ 452 s16 prev; 453 454 /* Identifies the current state of the packet as defined in 455 * `enum gve_packet_state`. 456 */ 457 u8 state : 3; 458 459 /* gve_tx_pending_packet_dqo_type */ 460 u8 type : 2; 461 462 /* If packet is an outstanding miss completion, then the packet is 463 * freed if the corresponding re-injection completion is not received 464 * before kernel jiffies exceeds timeout_jiffies. 465 */ 466 unsigned long timeout_jiffies; 467 }; 468 469 /* Contains datapath state used to represent a TX queue. */ 470 struct gve_tx_ring { 471 /* Cacheline 0 -- Accessed & dirtied during transmit */ 472 union { 473 /* GQI fields */ 474 struct { 475 struct gve_tx_fifo tx_fifo; 476 u32 req; /* driver tracked head pointer */ 477 u32 done; /* driver tracked tail pointer */ 478 }; 479 480 /* DQO fields. */ 481 struct { 482 /* Spinlock for XDP tx traffic */ 483 spinlock_t xdp_lock; 484 485 /* Linked list of gve_tx_pending_packet_dqo. Index into 486 * pending_packets, or -1 if empty. 487 * 488 * This is a consumer list owned by the TX path. When it 489 * runs out, the producer list is stolen from the 490 * completion handling path 491 * (dqo_compl.free_pending_packets). 492 */ 493 s16 free_pending_packets; 494 495 /* Cached value of `dqo_compl.hw_tx_head` */ 496 u32 head; 497 u32 tail; /* Last posted buffer index + 1 */ 498 499 /* Index of the last descriptor with "report event" bit 500 * set. 501 */ 502 u32 last_re_idx; 503 504 /* free running number of packet buf descriptors posted */ 505 u16 posted_packet_desc_cnt; 506 /* free running number of packet buf descriptors completed */ 507 u16 completed_packet_desc_cnt; 508 509 /* QPL fields */ 510 struct { 511 /* Linked list of gve_tx_buf_dqo. Index into 512 * tx_qpl_buf_next, or -1 if empty. 513 * 514 * This is a consumer list owned by the TX path. When it 515 * runs out, the producer list is stolen from the 516 * completion handling path 517 * (dqo_compl.free_tx_qpl_buf_head). 518 */ 519 s16 free_tx_qpl_buf_head; 520 521 /* Free running count of the number of QPL tx buffers 522 * allocated 523 */ 524 u32 alloc_tx_qpl_buf_cnt; 525 526 /* Cached value of `dqo_compl.free_tx_qpl_buf_cnt` */ 527 u32 free_tx_qpl_buf_cnt; 528 }; 529 530 atomic_t xsk_reorder_queue_tail; 531 } dqo_tx; 532 }; 533 534 /* Cacheline 1 -- Accessed & dirtied during gve_clean_tx_done */ 535 union { 536 /* GQI fields */ 537 struct { 538 /* Spinlock for when cleanup in progress */ 539 spinlock_t clean_lock; 540 /* Spinlock for XDP tx traffic */ 541 spinlock_t xdp_lock; 542 }; 543 544 /* DQO fields. */ 545 struct { 546 u32 head; /* Last read on compl_desc */ 547 548 /* Tracks the current gen bit of compl_q */ 549 u8 cur_gen_bit; 550 551 /* Linked list of gve_tx_pending_packet_dqo. Index into 552 * pending_packets, or -1 if empty. 553 * 554 * This is the producer list, owned by the completion 555 * handling path. When the consumer list 556 * (dqo_tx.free_pending_packets) is runs out, this list 557 * will be stolen. 558 */ 559 atomic_t free_pending_packets; 560 561 /* Last TX ring index fetched by HW */ 562 atomic_t hw_tx_head; 563 564 u16 xsk_reorder_queue_head; 565 u16 xsk_reorder_queue_tail; 566 567 /* List to track pending packets which received a miss 568 * completion but not a corresponding reinjection. 569 */ 570 struct gve_index_list miss_completions; 571 572 /* List to track pending packets that were completed 573 * before receiving a valid completion because they 574 * reached a specified timeout. 575 */ 576 struct gve_index_list timed_out_completions; 577 578 /* QPL fields */ 579 struct { 580 /* Linked list of gve_tx_buf_dqo. Index into 581 * tx_qpl_buf_next, or -1 if empty. 582 * 583 * This is the producer list, owned by the completion 584 * handling path. When the consumer list 585 * (dqo_tx.free_tx_qpl_buf_head) is runs out, this list 586 * will be stolen. 587 */ 588 atomic_t free_tx_qpl_buf_head; 589 590 /* Free running count of the number of tx buffers 591 * freed 592 */ 593 atomic_t free_tx_qpl_buf_cnt; 594 }; 595 } dqo_compl; 596 } ____cacheline_aligned; 597 u64 pkt_done; /* free-running - total packets completed */ 598 u64 bytes_done; /* free-running - total bytes completed */ 599 u64 dropped_pkt; /* free-running - total packets dropped */ 600 u64 dma_mapping_error; /* count of dma mapping errors */ 601 602 /* Cacheline 2 -- Read-mostly fields */ 603 union { 604 /* GQI fields */ 605 struct { 606 union gve_tx_desc *desc; 607 608 /* Maps 1:1 to a desc */ 609 struct gve_tx_buffer_state *info; 610 }; 611 612 /* DQO fields. */ 613 struct { 614 union gve_tx_desc_dqo *tx_ring; 615 struct gve_tx_compl_desc *compl_ring; 616 617 struct gve_tx_pending_packet_dqo *pending_packets; 618 s16 num_pending_packets; 619 620 u16 *xsk_reorder_queue; 621 622 u32 complq_mask; /* complq size is complq_mask + 1 */ 623 624 /* QPL fields */ 625 struct { 626 /* qpl assigned to this queue */ 627 struct gve_queue_page_list *qpl; 628 629 /* Each QPL page is divided into TX bounce buffers 630 * of size GVE_TX_BUF_SIZE_DQO. tx_qpl_buf_next is 631 * an array to manage linked lists of TX buffers. 632 * An entry j at index i implies that j'th buffer 633 * is next on the list after i 634 */ 635 s16 *tx_qpl_buf_next; 636 u32 num_tx_qpl_bufs; 637 }; 638 } dqo; 639 } ____cacheline_aligned; 640 struct netdev_queue *netdev_txq; 641 struct gve_queue_resources *q_resources; /* head and tail pointer idx */ 642 struct device *dev; 643 u32 mask; /* masks req and done down to queue size */ 644 u8 raw_addressing; /* use raw_addressing? */ 645 646 /* Slow-path fields */ 647 u32 q_num ____cacheline_aligned; /* queue idx */ 648 u32 stop_queue; /* count of queue stops */ 649 u32 wake_queue; /* count of queue wakes */ 650 u32 queue_timeout; /* count of queue timeouts */ 651 u32 ntfy_id; /* notification block index */ 652 u32 last_kick_msec; /* Last time the queue was kicked */ 653 dma_addr_t bus; /* dma address of the descr ring */ 654 dma_addr_t q_resources_bus; /* dma address of the queue resources */ 655 dma_addr_t complq_bus_dqo; /* dma address of the dqo.compl_ring */ 656 struct u64_stats_sync statss; /* sync stats for 32bit archs */ 657 struct xsk_buff_pool *xsk_pool; 658 u64 xdp_xsk_sent; 659 u64 xdp_xmit; 660 u64 xdp_xmit_errors; 661 } ____cacheline_aligned; 662 663 /* Wraps the info for one irq including the napi struct and the queues 664 * associated with that irq. 665 */ 666 struct gve_notify_block { 667 __be32 *irq_db_index; /* pointer to idx into Bar2 */ 668 char name[IFNAMSIZ + 16]; /* name registered with the kernel */ 669 struct napi_struct napi; /* kernel napi struct for this block */ 670 struct gve_priv *priv; 671 struct gve_tx_ring *tx; /* tx rings on this block */ 672 struct gve_rx_ring *rx; /* rx rings on this block */ 673 u32 irq; 674 }; 675 676 /* Tracks allowed and current rx queue settings */ 677 struct gve_rx_queue_config { 678 u16 max_queues; 679 u16 num_queues; 680 u16 packet_buffer_size; 681 }; 682 683 /* Tracks allowed and current tx queue settings */ 684 struct gve_tx_queue_config { 685 u16 max_queues; 686 u16 num_queues; /* number of TX queues, excluding XDP queues */ 687 u16 num_xdp_queues; 688 }; 689 690 /* Tracks the available and used qpl IDs */ 691 struct gve_qpl_config { 692 u32 qpl_map_size; /* map memory size */ 693 unsigned long *qpl_id_map; /* bitmap of used qpl ids */ 694 }; 695 696 struct gve_irq_db { 697 __be32 index; 698 } ____cacheline_aligned; 699 700 struct gve_ptype { 701 u8 l3_type; /* `gve_l3_type` in gve_adminq.h */ 702 u8 l4_type; /* `gve_l4_type` in gve_adminq.h */ 703 }; 704 705 struct gve_ptype_lut { 706 struct gve_ptype ptypes[GVE_NUM_PTYPES]; 707 }; 708 709 /* Parameters for allocating resources for tx queues */ 710 struct gve_tx_alloc_rings_cfg { 711 struct gve_tx_queue_config *qcfg; 712 u16 pages_per_qpl; 713 714 u16 num_xdp_rings; 715 716 u16 ring_size; 717 bool raw_addressing; 718 719 /* Allocated resources are returned here */ 720 struct gve_tx_ring *tx; 721 }; 722 723 /* Parameters for allocating resources for rx queues */ 724 struct gve_rx_alloc_rings_cfg { 725 /* tx config is also needed to determine QPL ids */ 726 struct gve_rx_queue_config *qcfg_rx; 727 struct gve_tx_queue_config *qcfg_tx; 728 u16 pages_per_qpl; 729 730 u16 ring_size; 731 u16 packet_buffer_size; 732 bool raw_addressing; 733 bool enable_header_split; 734 bool reset_rss; 735 bool xdp; 736 737 /* Allocated resources are returned here */ 738 struct gve_rx_ring *rx; 739 }; 740 741 /* GVE_QUEUE_FORMAT_UNSPECIFIED must be zero since 0 is the default value 742 * when the entire configure_device_resources command is zeroed out and the 743 * queue_format is not specified. 744 */ 745 enum gve_queue_format { 746 GVE_QUEUE_FORMAT_UNSPECIFIED = 0x0, 747 GVE_GQI_RDA_FORMAT = 0x1, 748 GVE_GQI_QPL_FORMAT = 0x2, 749 GVE_DQO_RDA_FORMAT = 0x3, 750 GVE_DQO_QPL_FORMAT = 0x4, 751 }; 752 753 struct gve_flow_spec { 754 __be32 src_ip[4]; 755 __be32 dst_ip[4]; 756 union { 757 struct { 758 __be16 src_port; 759 __be16 dst_port; 760 }; 761 __be32 spi; 762 }; 763 union { 764 u8 tos; 765 u8 tclass; 766 }; 767 }; 768 769 struct gve_flow_rule { 770 u32 location; 771 u16 flow_type; 772 u16 action; 773 struct gve_flow_spec key; 774 struct gve_flow_spec mask; 775 }; 776 777 struct gve_flow_rules_cache { 778 bool rules_cache_synced; /* False if the driver's rules_cache is outdated */ 779 struct gve_adminq_queried_flow_rule *rules_cache; 780 __be32 *rule_ids_cache; 781 /* The total number of queried rules that stored in the caches */ 782 u32 rules_cache_num; 783 u32 rule_ids_cache_num; 784 }; 785 786 struct gve_rss_config { 787 u8 *hash_key; 788 u32 *hash_lut; 789 }; 790 791 struct gve_ptp { 792 struct ptp_clock_info info; 793 struct ptp_clock *clock; 794 struct gve_priv *priv; 795 }; 796 797 struct gve_priv { 798 struct net_device *dev; 799 struct gve_tx_ring *tx; /* array of tx_cfg.num_queues */ 800 struct gve_rx_ring *rx; /* array of rx_cfg.num_queues */ 801 struct gve_notify_block *ntfy_blocks; /* array of num_ntfy_blks */ 802 struct gve_irq_db *irq_db_indices; /* array of num_ntfy_blks */ 803 dma_addr_t irq_db_indices_bus; 804 struct msix_entry *msix_vectors; /* array of num_ntfy_blks + 1 */ 805 char mgmt_msix_name[IFNAMSIZ + 16]; 806 u32 mgmt_msix_idx; 807 __be32 *counter_array; /* array of num_event_counters */ 808 dma_addr_t counter_array_bus; 809 810 u16 num_event_counters; 811 u16 tx_desc_cnt; /* num desc per ring */ 812 u16 rx_desc_cnt; /* num desc per ring */ 813 u16 max_tx_desc_cnt; 814 u16 max_rx_desc_cnt; 815 u16 min_tx_desc_cnt; 816 u16 min_rx_desc_cnt; 817 bool modify_ring_size_enabled; 818 bool default_min_ring_size; 819 u16 tx_pages_per_qpl; 820 u16 rx_pages_per_qpl; 821 u64 max_registered_pages; 822 u64 num_registered_pages; /* num pages registered with NIC */ 823 struct bpf_prog *xdp_prog; /* XDP BPF program */ 824 u32 rx_copybreak; /* copy packets smaller than this */ 825 u16 default_num_queues; /* default num queues to set up */ 826 827 struct gve_tx_queue_config tx_cfg; 828 struct gve_rx_queue_config rx_cfg; 829 unsigned long *xsk_pools; /* bitmap of RX queues with XSK pools */ 830 u32 num_ntfy_blks; /* split between TX and RX so must be even */ 831 int numa_node; 832 833 struct gve_registers __iomem *reg_bar0; /* see gve_register.h */ 834 __be32 __iomem *db_bar2; /* "array" of doorbells */ 835 u32 msg_enable; /* level for netif* netdev print macros */ 836 struct pci_dev *pdev; 837 838 /* metrics */ 839 u32 tx_timeo_cnt; 840 841 /* Admin queue - see gve_adminq.h*/ 842 union gve_adminq_command *adminq; 843 dma_addr_t adminq_bus_addr; 844 struct dma_pool *adminq_pool; 845 struct mutex adminq_lock; /* Protects adminq command execution */ 846 u32 adminq_mask; /* masks prod_cnt to adminq size */ 847 u32 adminq_prod_cnt; /* free-running count of AQ cmds executed */ 848 u32 adminq_cmd_fail; /* free-running count of AQ cmds failed */ 849 u32 adminq_timeouts; /* free-running count of AQ cmds timeouts */ 850 /* free-running count of per AQ cmd executed */ 851 u32 adminq_describe_device_cnt; 852 u32 adminq_cfg_device_resources_cnt; 853 u32 adminq_register_page_list_cnt; 854 u32 adminq_unregister_page_list_cnt; 855 u32 adminq_create_tx_queue_cnt; 856 u32 adminq_create_rx_queue_cnt; 857 u32 adminq_destroy_tx_queue_cnt; 858 u32 adminq_destroy_rx_queue_cnt; 859 u32 adminq_dcfg_device_resources_cnt; 860 u32 adminq_set_driver_parameter_cnt; 861 u32 adminq_report_stats_cnt; 862 u32 adminq_report_link_speed_cnt; 863 u32 adminq_report_nic_timestamp_cnt; 864 u32 adminq_get_ptype_map_cnt; 865 u32 adminq_verify_driver_compatibility_cnt; 866 u32 adminq_query_flow_rules_cnt; 867 u32 adminq_cfg_flow_rule_cnt; 868 u32 adminq_cfg_rss_cnt; 869 u32 adminq_query_rss_cnt; 870 871 /* Global stats */ 872 u32 interface_up_cnt; /* count of times interface turned up since last reset */ 873 u32 interface_down_cnt; /* count of times interface turned down since last reset */ 874 u32 reset_cnt; /* count of reset */ 875 u32 page_alloc_fail; /* count of page alloc fails */ 876 u32 dma_mapping_error; /* count of dma mapping errors */ 877 u32 stats_report_trigger_cnt; /* count of device-requested stats-reports since last reset */ 878 u32 suspend_cnt; /* count of times suspended */ 879 u32 resume_cnt; /* count of times resumed */ 880 struct workqueue_struct *gve_wq; 881 struct work_struct service_task; 882 struct work_struct stats_report_task; 883 unsigned long service_task_flags; 884 unsigned long state_flags; 885 886 struct gve_stats_report *stats_report; 887 u64 stats_report_len; 888 dma_addr_t stats_report_bus; /* dma address for the stats report */ 889 unsigned long ethtool_flags; 890 891 unsigned long stats_report_timer_period; 892 struct timer_list stats_report_timer; 893 894 /* Gvnic device link speed from hypervisor. */ 895 u64 link_speed; 896 bool up_before_suspend; /* True if dev was up before suspend */ 897 898 struct gve_ptype_lut *ptype_lut_dqo; 899 900 /* Must be a power of two. */ 901 u16 max_rx_buffer_size; /* device limit */ 902 903 enum gve_queue_format queue_format; 904 905 /* Interrupt coalescing settings */ 906 u32 tx_coalesce_usecs; 907 u32 rx_coalesce_usecs; 908 909 u16 header_buf_size; /* device configured, header-split supported if non-zero */ 910 bool header_split_enabled; /* True if the header split is enabled by the user */ 911 912 u32 max_flow_rules; 913 u32 num_flow_rules; 914 915 struct gve_flow_rules_cache flow_rules_cache; 916 917 u16 rss_key_size; 918 u16 rss_lut_size; 919 bool cache_rss_config; 920 struct gve_rss_config rss_config; 921 922 /* True if the device supports reading the nic clock */ 923 bool nic_timestamp_supported; 924 struct gve_ptp *ptp; 925 struct kernel_hwtstamp_config ts_config; 926 struct gve_nic_ts_report *nic_ts_report; 927 dma_addr_t nic_ts_report_bus; 928 u64 last_sync_nic_counter; /* Clock counter from last NIC TS report */ 929 }; 930 931 enum gve_service_task_flags_bit { 932 GVE_PRIV_FLAGS_DO_RESET = 1, 933 GVE_PRIV_FLAGS_RESET_IN_PROGRESS = 2, 934 GVE_PRIV_FLAGS_PROBE_IN_PROGRESS = 3, 935 GVE_PRIV_FLAGS_DO_REPORT_STATS = 4, 936 }; 937 938 enum gve_state_flags_bit { 939 GVE_PRIV_FLAGS_ADMIN_QUEUE_OK = 1, 940 GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK = 2, 941 GVE_PRIV_FLAGS_DEVICE_RINGS_OK = 3, 942 GVE_PRIV_FLAGS_NAPI_ENABLED = 4, 943 }; 944 945 enum gve_ethtool_flags_bit { 946 GVE_PRIV_FLAGS_REPORT_STATS = 0, 947 }; 948 949 static inline bool gve_get_do_reset(struct gve_priv *priv) 950 { 951 return test_bit(GVE_PRIV_FLAGS_DO_RESET, &priv->service_task_flags); 952 } 953 954 static inline void gve_set_do_reset(struct gve_priv *priv) 955 { 956 set_bit(GVE_PRIV_FLAGS_DO_RESET, &priv->service_task_flags); 957 } 958 959 static inline void gve_clear_do_reset(struct gve_priv *priv) 960 { 961 clear_bit(GVE_PRIV_FLAGS_DO_RESET, &priv->service_task_flags); 962 } 963 964 static inline bool gve_get_reset_in_progress(struct gve_priv *priv) 965 { 966 return test_bit(GVE_PRIV_FLAGS_RESET_IN_PROGRESS, 967 &priv->service_task_flags); 968 } 969 970 static inline void gve_set_reset_in_progress(struct gve_priv *priv) 971 { 972 set_bit(GVE_PRIV_FLAGS_RESET_IN_PROGRESS, &priv->service_task_flags); 973 } 974 975 static inline void gve_clear_reset_in_progress(struct gve_priv *priv) 976 { 977 clear_bit(GVE_PRIV_FLAGS_RESET_IN_PROGRESS, &priv->service_task_flags); 978 } 979 980 static inline bool gve_get_probe_in_progress(struct gve_priv *priv) 981 { 982 return test_bit(GVE_PRIV_FLAGS_PROBE_IN_PROGRESS, 983 &priv->service_task_flags); 984 } 985 986 static inline void gve_set_probe_in_progress(struct gve_priv *priv) 987 { 988 set_bit(GVE_PRIV_FLAGS_PROBE_IN_PROGRESS, &priv->service_task_flags); 989 } 990 991 static inline void gve_clear_probe_in_progress(struct gve_priv *priv) 992 { 993 clear_bit(GVE_PRIV_FLAGS_PROBE_IN_PROGRESS, &priv->service_task_flags); 994 } 995 996 static inline bool gve_get_do_report_stats(struct gve_priv *priv) 997 { 998 return test_bit(GVE_PRIV_FLAGS_DO_REPORT_STATS, 999 &priv->service_task_flags); 1000 } 1001 1002 static inline void gve_set_do_report_stats(struct gve_priv *priv) 1003 { 1004 set_bit(GVE_PRIV_FLAGS_DO_REPORT_STATS, &priv->service_task_flags); 1005 } 1006 1007 static inline void gve_clear_do_report_stats(struct gve_priv *priv) 1008 { 1009 clear_bit(GVE_PRIV_FLAGS_DO_REPORT_STATS, &priv->service_task_flags); 1010 } 1011 1012 static inline bool gve_get_admin_queue_ok(struct gve_priv *priv) 1013 { 1014 return test_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags); 1015 } 1016 1017 static inline void gve_set_admin_queue_ok(struct gve_priv *priv) 1018 { 1019 set_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags); 1020 } 1021 1022 static inline void gve_clear_admin_queue_ok(struct gve_priv *priv) 1023 { 1024 clear_bit(GVE_PRIV_FLAGS_ADMIN_QUEUE_OK, &priv->state_flags); 1025 } 1026 1027 static inline bool gve_get_device_resources_ok(struct gve_priv *priv) 1028 { 1029 return test_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags); 1030 } 1031 1032 static inline void gve_set_device_resources_ok(struct gve_priv *priv) 1033 { 1034 set_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags); 1035 } 1036 1037 static inline void gve_clear_device_resources_ok(struct gve_priv *priv) 1038 { 1039 clear_bit(GVE_PRIV_FLAGS_DEVICE_RESOURCES_OK, &priv->state_flags); 1040 } 1041 1042 static inline bool gve_get_device_rings_ok(struct gve_priv *priv) 1043 { 1044 return test_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags); 1045 } 1046 1047 static inline void gve_set_device_rings_ok(struct gve_priv *priv) 1048 { 1049 set_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags); 1050 } 1051 1052 static inline void gve_clear_device_rings_ok(struct gve_priv *priv) 1053 { 1054 clear_bit(GVE_PRIV_FLAGS_DEVICE_RINGS_OK, &priv->state_flags); 1055 } 1056 1057 static inline bool gve_get_napi_enabled(struct gve_priv *priv) 1058 { 1059 return test_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags); 1060 } 1061 1062 static inline void gve_set_napi_enabled(struct gve_priv *priv) 1063 { 1064 set_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags); 1065 } 1066 1067 static inline void gve_clear_napi_enabled(struct gve_priv *priv) 1068 { 1069 clear_bit(GVE_PRIV_FLAGS_NAPI_ENABLED, &priv->state_flags); 1070 } 1071 1072 static inline bool gve_get_report_stats(struct gve_priv *priv) 1073 { 1074 return test_bit(GVE_PRIV_FLAGS_REPORT_STATS, &priv->ethtool_flags); 1075 } 1076 1077 static inline void gve_clear_report_stats(struct gve_priv *priv) 1078 { 1079 clear_bit(GVE_PRIV_FLAGS_REPORT_STATS, &priv->ethtool_flags); 1080 } 1081 1082 /* Returns the address of the ntfy_blocks irq doorbell 1083 */ 1084 static inline __be32 __iomem *gve_irq_doorbell(struct gve_priv *priv, 1085 struct gve_notify_block *block) 1086 { 1087 return &priv->db_bar2[be32_to_cpu(*block->irq_db_index)]; 1088 } 1089 1090 /* Returns the index into ntfy_blocks of the given tx ring's block 1091 */ 1092 static inline u32 gve_tx_idx_to_ntfy(struct gve_priv *priv, u32 queue_idx) 1093 { 1094 return queue_idx; 1095 } 1096 1097 /* Returns the index into ntfy_blocks of the given rx ring's block 1098 */ 1099 static inline u32 gve_rx_idx_to_ntfy(struct gve_priv *priv, u32 queue_idx) 1100 { 1101 return (priv->num_ntfy_blks / 2) + queue_idx; 1102 } 1103 1104 static inline bool gve_is_qpl(struct gve_priv *priv) 1105 { 1106 return priv->queue_format == GVE_GQI_QPL_FORMAT || 1107 priv->queue_format == GVE_DQO_QPL_FORMAT; 1108 } 1109 1110 /* Returns the number of tx queue page lists */ 1111 static inline u32 gve_num_tx_qpls(const struct gve_tx_queue_config *tx_cfg, 1112 bool is_qpl) 1113 { 1114 if (!is_qpl) 1115 return 0; 1116 return tx_cfg->num_queues + tx_cfg->num_xdp_queues; 1117 } 1118 1119 /* Returns the number of rx queue page lists */ 1120 static inline u32 gve_num_rx_qpls(const struct gve_rx_queue_config *rx_cfg, 1121 bool is_qpl) 1122 { 1123 if (!is_qpl) 1124 return 0; 1125 return rx_cfg->num_queues; 1126 } 1127 1128 static inline u32 gve_tx_qpl_id(struct gve_priv *priv, int tx_qid) 1129 { 1130 return tx_qid; 1131 } 1132 1133 static inline u32 gve_rx_qpl_id(struct gve_priv *priv, int rx_qid) 1134 { 1135 return priv->tx_cfg.max_queues + rx_qid; 1136 } 1137 1138 static inline u32 gve_get_rx_qpl_id(const struct gve_tx_queue_config *tx_cfg, 1139 int rx_qid) 1140 { 1141 return tx_cfg->max_queues + rx_qid; 1142 } 1143 1144 static inline u32 gve_tx_start_qpl_id(struct gve_priv *priv) 1145 { 1146 return gve_tx_qpl_id(priv, 0); 1147 } 1148 1149 static inline u32 gve_rx_start_qpl_id(const struct gve_tx_queue_config *tx_cfg) 1150 { 1151 return gve_get_rx_qpl_id(tx_cfg, 0); 1152 } 1153 1154 /* Returns the correct dma direction for tx and rx qpls */ 1155 static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv, 1156 int id) 1157 { 1158 if (id < gve_rx_start_qpl_id(&priv->tx_cfg)) 1159 return DMA_TO_DEVICE; 1160 else 1161 return DMA_FROM_DEVICE; 1162 } 1163 1164 static inline bool gve_is_gqi(struct gve_priv *priv) 1165 { 1166 return priv->queue_format == GVE_GQI_RDA_FORMAT || 1167 priv->queue_format == GVE_GQI_QPL_FORMAT; 1168 } 1169 1170 static inline bool gve_is_dqo(struct gve_priv *priv) 1171 { 1172 return priv->queue_format == GVE_DQO_RDA_FORMAT || 1173 priv->queue_format == GVE_DQO_QPL_FORMAT; 1174 } 1175 1176 static inline u32 gve_num_tx_queues(struct gve_priv *priv) 1177 { 1178 return priv->tx_cfg.num_queues + priv->tx_cfg.num_xdp_queues; 1179 } 1180 1181 static inline u32 gve_xdp_tx_queue_id(struct gve_priv *priv, u32 queue_id) 1182 { 1183 return priv->tx_cfg.num_queues + queue_id; 1184 } 1185 1186 static inline u32 gve_xdp_tx_start_queue_id(struct gve_priv *priv) 1187 { 1188 return gve_xdp_tx_queue_id(priv, 0); 1189 } 1190 1191 static inline bool gve_supports_xdp_xmit(struct gve_priv *priv) 1192 { 1193 switch (priv->queue_format) { 1194 case GVE_GQI_QPL_FORMAT: 1195 case GVE_DQO_RDA_FORMAT: 1196 return true; 1197 default: 1198 return false; 1199 } 1200 } 1201 1202 static inline bool gve_is_clock_enabled(struct gve_priv *priv) 1203 { 1204 return priv->nic_ts_report; 1205 } 1206 1207 /* gqi napi handler defined in gve_main.c */ 1208 int gve_napi_poll(struct napi_struct *napi, int budget); 1209 1210 /* buffers */ 1211 int gve_alloc_page(struct gve_priv *priv, struct device *dev, 1212 struct page **page, dma_addr_t *dma, 1213 enum dma_data_direction, gfp_t gfp_flags); 1214 void gve_free_page(struct device *dev, struct page *page, dma_addr_t dma, 1215 enum dma_data_direction); 1216 /* qpls */ 1217 struct gve_queue_page_list *gve_alloc_queue_page_list(struct gve_priv *priv, 1218 u32 id, int pages); 1219 void gve_free_queue_page_list(struct gve_priv *priv, 1220 struct gve_queue_page_list *qpl, 1221 u32 id); 1222 /* tx handling */ 1223 netdev_tx_t gve_tx(struct sk_buff *skb, struct net_device *dev); 1224 int gve_xdp_xmit_gqi(struct net_device *dev, int n, struct xdp_frame **frames, 1225 u32 flags); 1226 int gve_xdp_xmit_dqo(struct net_device *dev, int n, struct xdp_frame **frames, 1227 u32 flags); 1228 int gve_xdp_xmit_one(struct gve_priv *priv, struct gve_tx_ring *tx, 1229 void *data, int len, void *frame_p); 1230 void gve_xdp_tx_flush(struct gve_priv *priv, u32 xdp_qid); 1231 int gve_xdp_xmit_one_dqo(struct gve_priv *priv, struct gve_tx_ring *tx, 1232 struct xdp_frame *xdpf); 1233 bool gve_tx_poll(struct gve_notify_block *block, int budget); 1234 bool gve_xdp_poll(struct gve_notify_block *block, int budget); 1235 int gve_xsk_tx_poll(struct gve_notify_block *block, int budget); 1236 int gve_tx_alloc_rings_gqi(struct gve_priv *priv, 1237 struct gve_tx_alloc_rings_cfg *cfg); 1238 void gve_tx_free_rings_gqi(struct gve_priv *priv, 1239 struct gve_tx_alloc_rings_cfg *cfg); 1240 void gve_tx_start_ring_gqi(struct gve_priv *priv, int idx); 1241 void gve_tx_stop_ring_gqi(struct gve_priv *priv, int idx); 1242 u32 gve_tx_load_event_counter(struct gve_priv *priv, 1243 struct gve_tx_ring *tx); 1244 bool gve_tx_clean_pending(struct gve_priv *priv, struct gve_tx_ring *tx); 1245 /* rx handling */ 1246 void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx); 1247 int gve_rx_poll(struct gve_notify_block *block, int budget); 1248 bool gve_rx_work_pending(struct gve_rx_ring *rx); 1249 int gve_rx_alloc_ring_gqi(struct gve_priv *priv, 1250 struct gve_rx_alloc_rings_cfg *cfg, 1251 struct gve_rx_ring *rx, 1252 int idx); 1253 void gve_rx_free_ring_gqi(struct gve_priv *priv, struct gve_rx_ring *rx, 1254 struct gve_rx_alloc_rings_cfg *cfg); 1255 int gve_rx_alloc_rings_gqi(struct gve_priv *priv, 1256 struct gve_rx_alloc_rings_cfg *cfg); 1257 void gve_rx_free_rings_gqi(struct gve_priv *priv, 1258 struct gve_rx_alloc_rings_cfg *cfg); 1259 void gve_rx_start_ring_gqi(struct gve_priv *priv, int idx); 1260 void gve_rx_stop_ring_gqi(struct gve_priv *priv, int idx); 1261 bool gve_header_split_supported(const struct gve_priv *priv); 1262 int gve_set_rx_buf_len_config(struct gve_priv *priv, u32 rx_buf_len, 1263 struct netlink_ext_ack *extack, 1264 struct gve_rx_alloc_rings_cfg *rx_alloc_cfg); 1265 int gve_set_hsplit_config(struct gve_priv *priv, u8 tcp_data_split, 1266 struct gve_rx_alloc_rings_cfg *rx_alloc_cfg); 1267 /* rx buffer handling */ 1268 int gve_buf_ref_cnt(struct gve_rx_buf_state_dqo *bs); 1269 void gve_free_page_dqo(struct gve_priv *priv, struct gve_rx_buf_state_dqo *bs, 1270 bool free_page); 1271 struct gve_rx_buf_state_dqo *gve_alloc_buf_state(struct gve_rx_ring *rx); 1272 bool gve_buf_state_is_allocated(struct gve_rx_ring *rx, 1273 struct gve_rx_buf_state_dqo *buf_state); 1274 void gve_free_buf_state(struct gve_rx_ring *rx, 1275 struct gve_rx_buf_state_dqo *buf_state); 1276 struct gve_rx_buf_state_dqo *gve_dequeue_buf_state(struct gve_rx_ring *rx, 1277 struct gve_index_list *list); 1278 void gve_enqueue_buf_state(struct gve_rx_ring *rx, struct gve_index_list *list, 1279 struct gve_rx_buf_state_dqo *buf_state); 1280 struct gve_rx_buf_state_dqo *gve_get_recycled_buf_state(struct gve_rx_ring *rx); 1281 void gve_try_recycle_buf(struct gve_priv *priv, struct gve_rx_ring *rx, 1282 struct gve_rx_buf_state_dqo *buf_state); 1283 void gve_free_to_page_pool(struct gve_rx_ring *rx, 1284 struct gve_rx_buf_state_dqo *buf_state, 1285 bool allow_direct); 1286 int gve_alloc_qpl_page_dqo(struct gve_rx_ring *rx, 1287 struct gve_rx_buf_state_dqo *buf_state); 1288 void gve_free_qpl_page_dqo(struct gve_rx_buf_state_dqo *buf_state); 1289 void gve_reuse_buffer(struct gve_rx_ring *rx, 1290 struct gve_rx_buf_state_dqo *buf_state); 1291 void gve_free_buffer(struct gve_rx_ring *rx, 1292 struct gve_rx_buf_state_dqo *buf_state); 1293 int gve_alloc_buffer(struct gve_rx_ring *rx, struct gve_rx_desc_dqo *desc); 1294 struct page_pool *gve_rx_create_page_pool(struct gve_priv *priv, 1295 struct gve_rx_ring *rx, 1296 bool xdp); 1297 1298 /* Reset */ 1299 void gve_schedule_reset(struct gve_priv *priv); 1300 int gve_reset(struct gve_priv *priv, bool attempt_teardown); 1301 void gve_get_curr_alloc_cfgs(struct gve_priv *priv, 1302 struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, 1303 struct gve_rx_alloc_rings_cfg *rx_alloc_cfg); 1304 void gve_update_num_qpl_pages(struct gve_priv *priv, 1305 struct gve_rx_alloc_rings_cfg *rx_alloc_cfg, 1306 struct gve_tx_alloc_rings_cfg *tx_alloc_cfg); 1307 int gve_adjust_config(struct gve_priv *priv, 1308 struct gve_tx_alloc_rings_cfg *tx_alloc_cfg, 1309 struct gve_rx_alloc_rings_cfg *rx_alloc_cfg); 1310 int gve_adjust_queues(struct gve_priv *priv, 1311 struct gve_rx_queue_config new_rx_config, 1312 struct gve_tx_queue_config new_tx_config, 1313 bool reset_rss); 1314 /* flow steering rule */ 1315 int gve_get_flow_rule_entry(struct gve_priv *priv, struct ethtool_rxnfc *cmd); 1316 int gve_get_flow_rule_ids(struct gve_priv *priv, struct ethtool_rxnfc *cmd, u32 *rule_locs); 1317 int gve_add_flow_rule(struct gve_priv *priv, struct ethtool_rxnfc *cmd); 1318 int gve_del_flow_rule(struct gve_priv *priv, struct ethtool_rxnfc *cmd); 1319 int gve_flow_rules_reset(struct gve_priv *priv); 1320 /* RSS config */ 1321 int gve_init_rss_config(struct gve_priv *priv, u16 num_queues); 1322 /* PTP and timestamping */ 1323 #if IS_ENABLED(CONFIG_PTP_1588_CLOCK) 1324 int gve_clock_nic_ts_read(struct gve_priv *priv); 1325 int gve_init_clock(struct gve_priv *priv); 1326 void gve_teardown_clock(struct gve_priv *priv); 1327 #else /* CONFIG_PTP_1588_CLOCK */ 1328 static inline int gve_clock_nic_ts_read(struct gve_priv *priv) 1329 { 1330 return -EOPNOTSUPP; 1331 } 1332 1333 static inline int gve_init_clock(struct gve_priv *priv) 1334 { 1335 return 0; 1336 } 1337 1338 static inline void gve_teardown_clock(struct gve_priv *priv) { } 1339 #endif /* CONFIG_PTP_1588_CLOCK */ 1340 /* report stats handling */ 1341 void gve_handle_report_stats(struct gve_priv *priv); 1342 /* exported by ethtool.c */ 1343 extern const struct ethtool_ops gve_ethtool_ops; 1344 /* needed by ethtool */ 1345 extern char gve_driver_name[]; 1346 extern const char gve_version_str[]; 1347 #endif /* _GVE_H_ */ 1348