1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 2 /* Copyright (c) 2021, Microsoft Corporation. */ 3 4 #ifndef _MANA_H 5 #define _MANA_H 6 7 #include <linux/dim.h> 8 #include <net/xdp.h> 9 #include <net/net_shaper.h> 10 11 #include "gdma.h" 12 #include "hw_channel.h" 13 14 /* Microsoft Azure Network Adapter (MANA)'s definitions 15 * 16 * Structures labeled with "HW DATA" are exchanged with the hardware. All of 17 * them are naturally aligned and hence don't need __packed. 18 */ 19 20 /* MANA protocol version */ 21 #define MANA_MAJOR_VERSION 0 22 #define MANA_MINOR_VERSION 1 23 #define MANA_MICRO_VERSION 1 24 25 typedef u64 mana_handle_t; 26 #define INVALID_MANA_HANDLE ((mana_handle_t)-1) 27 28 enum TRI_STATE { 29 TRI_STATE_UNKNOWN = -1, 30 TRI_STATE_FALSE = 0, 31 TRI_STATE_TRUE = 1 32 }; 33 34 /* MANA ethtool private flag bit positions */ 35 enum mana_priv_flag_bits { 36 MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF = 0, 37 MANA_PRIV_FLAG_MAX, 38 }; 39 40 /* Number of entries for hardware indirection table must be in power of 2 */ 41 #define MANA_INDIRECT_TABLE_MAX_SIZE 512 42 #define MANA_INDIRECT_TABLE_DEF_SIZE 64 43 44 /* The Toeplitz hash key's length in bytes: should be multiple of 8 */ 45 #define MANA_HASH_KEY_SIZE 40 46 47 #define COMP_ENTRY_SIZE 64 48 49 /* This Max value for RX buffers is derived from __alloc_page()'s max page 50 * allocation calculation. It allows maximum 2^MAX_PAGE_ORDER pages. RX 51 * buffer size beyond this value gets rejected by __alloc_page() call. 52 */ 53 #define MAX_RX_BUFFERS_PER_QUEUE 8192 54 #define DEF_RX_BUFFERS_PER_QUEUE 1024 55 #define MIN_RX_BUFFERS_PER_QUEUE 128 56 57 /* This max value for TX buffers is derived as the maximum allocatable 58 * pages supported on host per guest through testing. TX buffer size beyond 59 * this value is rejected by the hardware. 60 */ 61 #define MAX_TX_BUFFERS_PER_QUEUE 16384 62 #define DEF_TX_BUFFERS_PER_QUEUE 256 63 #define MIN_TX_BUFFERS_PER_QUEUE 128 64 65 #define EQ_SIZE (8 * MANA_PAGE_SIZE) 66 67 #define LOG2_EQ_THROTTLE 3 68 69 #define MAX_PORTS_IN_MANA_DEV 256 70 71 /* Maximum number of PPIs per coalesced CQE */ 72 #define MANA_RXCOMP_OOB_NUM_PPI 4 73 74 /* 8-pkt mode packs up to 2 packets per PPI entry */ 75 #define MANA_CQE_COAL_PKTS_8 8 76 77 /* Default/min interrupt moderation settings */ 78 #define MANA_INTR_MODR_USEC_DEF 1 79 #define MANA_INTR_MODR_COMP_DEF 1 80 81 #define MANA_INTR_MODR_USEC_MIN 1 82 #define MANA_INTR_MODR_COMP_MIN 1 83 84 #define MANA_ADAPTIVE_RX_DEF true 85 #define MANA_ADAPTIVE_TX_DEF true 86 87 /* DIM doorbell value field layout */ 88 #define MANA_INTR_MODR_USEC_MAX GENMASK(9, 0) 89 #define MANA_INTR_MODR_USEC_VLD BIT(15) 90 #define MANA_INTR_MODR_COMP_MAX GENMASK(7, 0) 91 #define MANA_INTR_MODR_COMP_MASK GENMASK(23, 16) 92 93 /* Update this count whenever the respective structures are changed */ 94 #define MANA_STATS_RX_COUNT (6 + MANA_CQE_COAL_PKTS_8 - 1) 95 #define MANA_STATS_TX_COUNT 11 96 #define MANA_STATS_EQ_COUNT 1 97 98 #define MANA_RX_FRAG_ALIGNMENT 64 99 100 struct mana_stats_rx { 101 u64 packets; 102 u64 bytes; 103 u64 xdp_drop; 104 u64 xdp_tx; 105 u64 xdp_redirect; 106 u64 pkt_len0_err; 107 u64 coalesced_cqe[MANA_CQE_COAL_PKTS_8 - 1]; 108 struct u64_stats_sync syncp; 109 }; 110 111 struct mana_stats_tx { 112 u64 packets; 113 u64 bytes; 114 u64 xdp_xmit; 115 u64 tso_packets; 116 u64 tso_bytes; 117 u64 tso_inner_packets; 118 u64 tso_inner_bytes; 119 u64 short_pkt_fmt; 120 u64 long_pkt_fmt; 121 u64 csum_partial; 122 u64 mana_map_err; 123 struct u64_stats_sync syncp; 124 }; 125 126 struct mana_txq { 127 struct gdma_queue *gdma_sq; 128 129 union { 130 u32 gdma_txq_id; 131 struct { 132 u32 reserved1 : 10; 133 u32 vsq_frame : 14; 134 u32 reserved2 : 8; 135 }; 136 }; 137 138 u16 vp_offset; 139 140 struct net_device *ndev; 141 142 /* The SKBs are sent to the HW and we are waiting for the CQEs. */ 143 struct sk_buff_head pending_skbs; 144 struct netdev_queue *net_txq; 145 146 atomic_t pending_sends; 147 148 bool napi_initialized; 149 150 struct mana_stats_tx stats; 151 }; 152 153 /* skb data and frags dma mappings */ 154 struct mana_skb_head { 155 /* GSO pkts may have 2 SGEs for the linear part*/ 156 dma_addr_t dma_handle[MAX_SKB_FRAGS + 2]; 157 158 u32 size[MAX_SKB_FRAGS + 2]; 159 }; 160 161 #define MANA_HEADROOM sizeof(struct mana_skb_head) 162 163 enum mana_tx_pkt_format { 164 MANA_SHORT_PKT_FMT = 0, 165 MANA_LONG_PKT_FMT = 1, 166 }; 167 168 struct mana_tx_short_oob { 169 u32 pkt_fmt : 2; 170 u32 is_outer_ipv4 : 1; 171 u32 is_outer_ipv6 : 1; 172 u32 comp_iphdr_csum : 1; 173 u32 comp_tcp_csum : 1; 174 u32 comp_udp_csum : 1; 175 u32 supress_txcqe_gen : 1; 176 u32 vcq_num : 24; 177 178 u32 trans_off : 10; /* Transport header offset */ 179 u32 vsq_frame : 14; 180 u32 short_vp_offset : 8; 181 }; /* HW DATA */ 182 183 struct mana_tx_long_oob { 184 u32 is_encap : 1; 185 u32 inner_is_ipv6 : 1; 186 u32 inner_tcp_opt : 1; 187 u32 inject_vlan_pri_tag : 1; 188 u32 reserved1 : 12; 189 u32 pcp : 3; /* 802.1Q */ 190 u32 dei : 1; /* 802.1Q */ 191 u32 vlan_id : 12; /* 802.1Q */ 192 193 u32 inner_frame_offset : 10; 194 u32 inner_ip_rel_offset : 6; 195 u32 long_vp_offset : 12; 196 u32 reserved2 : 4; 197 198 u32 reserved3; 199 u32 reserved4; 200 }; /* HW DATA */ 201 202 struct mana_tx_oob { 203 struct mana_tx_short_oob s_oob; 204 struct mana_tx_long_oob l_oob; 205 }; /* HW DATA */ 206 207 enum mana_cq_type { 208 MANA_CQ_TYPE_RX, 209 MANA_CQ_TYPE_TX, 210 }; 211 212 enum mana_cqe_type { 213 CQE_INVALID = 0, 214 CQE_RX_OKAY = 1, 215 CQE_RX_COALESCED_4 = 2, 216 CQE_RX_OBJECT_FENCE = 3, 217 CQE_RX_TRUNCATED = 4, 218 CQE_RX_COALESCED_8 = 7, 219 220 CQE_TX_OKAY = 32, 221 CQE_TX_SA_DROP = 33, 222 CQE_TX_MTU_DROP = 34, 223 CQE_TX_INVALID_OOB = 35, 224 CQE_TX_INVALID_ETH_TYPE = 36, 225 CQE_TX_HDR_PROCESSING_ERROR = 37, 226 CQE_TX_VF_DISABLED = 38, 227 CQE_TX_VPORT_IDX_OUT_OF_RANGE = 39, 228 CQE_TX_VPORT_DISABLED = 40, 229 CQE_TX_VLAN_TAGGING_VIOLATION = 41, 230 }; 231 232 #define MANA_CQE_COMPLETION 1 233 234 struct mana_cqe_header { 235 u32 cqe_type : 6; 236 u32 client_type : 2; 237 u32 vendor_err : 24; 238 }; /* HW DATA */ 239 240 /* NDIS HASH Types */ 241 #define NDIS_HASH_IPV4 BIT(0) 242 #define NDIS_HASH_TCP_IPV4 BIT(1) 243 #define NDIS_HASH_UDP_IPV4 BIT(2) 244 #define NDIS_HASH_IPV6 BIT(3) 245 #define NDIS_HASH_TCP_IPV6 BIT(4) 246 #define NDIS_HASH_UDP_IPV6 BIT(5) 247 #define NDIS_HASH_IPV6_EX BIT(6) 248 #define NDIS_HASH_TCP_IPV6_EX BIT(7) 249 #define NDIS_HASH_UDP_IPV6_EX BIT(8) 250 251 #define MANA_HASH_L3 (NDIS_HASH_IPV4 | NDIS_HASH_IPV6 | NDIS_HASH_IPV6_EX) 252 #define MANA_HASH_L4 \ 253 (NDIS_HASH_TCP_IPV4 | NDIS_HASH_UDP_IPV4 | NDIS_HASH_TCP_IPV6 | \ 254 NDIS_HASH_UDP_IPV6 | NDIS_HASH_TCP_IPV6_EX | NDIS_HASH_UDP_IPV6_EX) 255 #define MANA_HASH_ENABLE_SUPPORTED \ 256 (NDIS_HASH_IPV4 | NDIS_HASH_TCP_IPV4 | NDIS_HASH_UDP_IPV4 | \ 257 NDIS_HASH_IPV6 | NDIS_HASH_TCP_IPV6 | NDIS_HASH_UDP_IPV6) 258 259 /* Read PPI in two different layouts based on cqe_type */ 260 union mana_rxcomp_perpkt_info { 261 struct { 262 u32 pkt_len : 16; 263 u32 reserved1 : 16; 264 u32 reserved2; 265 u32 pkt_hash; 266 }; 267 268 /* Up to two pkts per PPI entry */ 269 struct { 270 u32 pkt_hash0; 271 u16 pkt_len0; 272 u16 pkt_len1; 273 u32 pkt_hash1; 274 }; 275 }; /* HW DATA */ 276 277 /* Receive completion OOB */ 278 struct mana_rxcomp_oob { 279 struct mana_cqe_header cqe_hdr; 280 281 u32 rx_vlan_id : 12; 282 u32 rx_vlantag_present : 1; 283 u32 rx_outer_iphdr_csum_succeed : 1; 284 u32 rx_outer_iphdr_csum_fail : 1; 285 u32 reserved1 : 1; 286 u32 rx_hashtype : 9; 287 u32 rx_iphdr_csum_succeed : 1; 288 u32 rx_iphdr_csum_fail : 1; 289 u32 rx_tcp_csum_succeed : 1; 290 u32 rx_tcp_csum_fail : 1; 291 u32 rx_udp_csum_succeed : 1; 292 u32 rx_udp_csum_fail : 1; 293 u32 reserved2 : 1; 294 295 union mana_rxcomp_perpkt_info ppi[MANA_RXCOMP_OOB_NUM_PPI]; 296 297 u32 rx_wqe_offset; 298 }; /* HW DATA */ 299 300 struct mana_tx_comp_oob { 301 struct mana_cqe_header cqe_hdr; 302 303 u32 tx_data_offset; 304 305 u32 tx_sgl_offset : 5; 306 u32 tx_wqe_offset : 27; 307 308 u32 reserved[12]; 309 }; /* HW DATA */ 310 311 struct mana_rxq; 312 313 #define CQE_POLLING_BUFFER 512 314 315 struct mana_cq { 316 struct gdma_queue *gdma_cq; 317 318 /* Cache the CQ id (used to verify if each CQE comes to the right CQ. */ 319 u32 gdma_id; 320 321 /* Type of the CQ: TX or RX */ 322 enum mana_cq_type type; 323 324 /* Pointer to the mana_rxq that is pushing RX CQEs to the queue. 325 * Only and must be non-NULL if type is MANA_CQ_TYPE_RX. 326 */ 327 struct mana_rxq *rxq; 328 329 /* Pointer to the mana_txq that is pushing TX CQEs to the queue. 330 * Only and must be non-NULL if type is MANA_CQ_TYPE_TX. 331 */ 332 struct mana_txq *txq; 333 334 /* Buffer which the CQ handler can copy the CQE's into. */ 335 struct gdma_comp gdma_comp_buf[CQE_POLLING_BUFFER]; 336 337 /* NAPI data */ 338 struct napi_struct napi; 339 int work_done; 340 int work_done_since_doorbell; 341 int budget; 342 343 /* DIM - Dynamic Interrupt Moderation */ 344 struct dim dim; 345 u16 dim_event_ctr; 346 347 /* Cumulative TX completions fed to DIM. Updated and read only in 348 * NAPI context (mana_poll_tx_cq() / mana_update_tx_dim()), so they 349 * measure the hardware completion rate and need no u64_stats_sync. 350 */ 351 u64 tx_dim_pkts; 352 u64 tx_dim_bytes; 353 }; 354 355 struct mana_recv_buf_oob { 356 /* A valid GDMA work request representing the data buffer. */ 357 struct gdma_wqe_request wqe_req; 358 359 void *buf_va; 360 bool from_pool; /* allocated from a page pool */ 361 /* head page of the page_pool fragment; valid only when 362 * from_pool && frag_count > 1. 363 */ 364 struct page *pp_page; 365 /* Fragment offset plus rxq->headroom, passed to 366 * page_pool_dma_sync_for_cpu(). 367 */ 368 u32 dma_sync_offset; 369 370 /* SGL of the buffer going to be sent as part of the work request. */ 371 u32 num_sge; 372 struct gdma_sge sgl[MAX_RX_WQE_SGL_ENTRIES]; 373 374 /* Required to store the result of mana_gd_post_work_request. 375 * gdma_posted_wqe_info.wqe_size_in_bu is required for progressing the 376 * work queue when the WQE is consumed. 377 */ 378 struct gdma_posted_wqe_info wqe_inf; 379 }; 380 381 #define MANA_RXBUF_PAD (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) \ 382 + ETH_HLEN) 383 384 /* Headroom an RX buffer has to reserve while XDP is attached: the XDP program 385 * needs XDP_PACKET_HEADROOM, and the TX path needs LL_RESERVED_SPACE() (see 386 * mana_get_rxbuf_headroom()). LL_RESERVED_SPACE() grows with MAX_SKB_FRAGS and 387 * exceeds XDP_PACKET_HEADROOM once CONFIG_MAX_SKB_FRAGS is 19 or more. 388 */ 389 static inline u32 mana_xdp_headroom(struct net_device *ndev) 390 { 391 return max_t(u32, LL_RESERVED_SPACE(ndev), XDP_PACKET_HEADROOM); 392 } 393 394 #define MANA_XDP_MTU_MAX(ndev) \ 395 (PAGE_SIZE - MANA_RXBUF_PAD - mana_xdp_headroom(ndev)) 396 397 struct mana_rxq { 398 struct gdma_queue *gdma_rq; 399 /* Cache the gdma receive queue id */ 400 u32 gdma_id; 401 402 /* Index of RQ in the vPort, not gdma receive queue id */ 403 u32 rxq_idx; 404 405 u32 datasize; 406 u32 alloc_size; 407 u32 headroom; 408 u32 frag_count; 409 410 mana_handle_t rxobj; 411 412 struct mana_cq rx_cq; 413 414 struct completion fence_event; 415 416 struct net_device *ndev; 417 418 /* Total number of receive buffers to be allocated */ 419 u32 num_rx_buf; 420 421 u32 buf_index; 422 423 struct mana_stats_rx stats; 424 425 struct bpf_prog __rcu *bpf_prog; 426 struct xdp_rxq_info xdp_rxq; 427 /* For buffers not from the page pool (from_pool == false) */ 428 struct xdp_rxq_info xdp_rxq_shared; 429 void *xdp_save_va; /* for reusing */ 430 bool xdp_flush; 431 int xdp_rc; /* XDP redirect return code */ 432 433 struct page_pool *page_pool; 434 struct dentry *mana_rx_debugfs; 435 436 /* MUST BE THE LAST MEMBER: 437 * Each receive buffer has an associated mana_recv_buf_oob. 438 */ 439 struct mana_recv_buf_oob rx_oobs[] __counted_by(num_rx_buf); 440 }; 441 442 struct mana_tx_qp { 443 struct mana_txq txq; 444 445 struct mana_cq tx_cq; 446 447 mana_handle_t tx_object; 448 449 struct dentry *mana_tx_debugfs; 450 }; 451 452 struct mana_ethtool_stats { 453 u64 stop_queue; 454 u64 wake_queue; 455 u64 tx_cqe_err; 456 u64 tx_cqe_unknown_type; 457 u64 tx_linear_pkt_cnt; 458 u64 rx_cqe_unknown_type; 459 }; 460 461 struct mana_ethtool_hc_stats { 462 u64 hc_rx_discards_no_wqe; 463 u64 hc_rx_err_vport_disabled; 464 u64 hc_rx_bytes; 465 u64 hc_rx_ucast_pkts; 466 u64 hc_rx_ucast_bytes; 467 u64 hc_rx_bcast_pkts; 468 u64 hc_rx_bcast_bytes; 469 u64 hc_rx_mcast_pkts; 470 u64 hc_rx_mcast_bytes; 471 u64 hc_tx_err_gf_disabled; 472 u64 hc_tx_err_vport_disabled; 473 u64 hc_tx_err_inval_vportoffset_pkt; 474 u64 hc_tx_err_vlan_enforcement; 475 u64 hc_tx_err_eth_type_enforcement; 476 u64 hc_tx_err_sa_enforcement; 477 u64 hc_tx_err_sqpdid_enforcement; 478 u64 hc_tx_err_cqpdid_enforcement; 479 u64 hc_tx_err_mtu_violation; 480 u64 hc_tx_err_inval_oob; 481 u64 hc_tx_bytes; 482 u64 hc_tx_ucast_pkts; 483 u64 hc_tx_ucast_bytes; 484 u64 hc_tx_bcast_pkts; 485 u64 hc_tx_bcast_bytes; 486 u64 hc_tx_mcast_pkts; 487 u64 hc_tx_mcast_bytes; 488 u64 hc_tx_err_gdma; 489 }; 490 491 struct mana_ethtool_phy_stats { 492 /* Drop Counters */ 493 u64 rx_pkt_drop_phy; 494 u64 tx_pkt_drop_phy; 495 496 /* Per TC traffic Counters */ 497 u64 rx_pkt_tc0_phy; 498 u64 tx_pkt_tc0_phy; 499 u64 rx_pkt_tc1_phy; 500 u64 tx_pkt_tc1_phy; 501 u64 rx_pkt_tc2_phy; 502 u64 tx_pkt_tc2_phy; 503 u64 rx_pkt_tc3_phy; 504 u64 tx_pkt_tc3_phy; 505 u64 rx_pkt_tc4_phy; 506 u64 tx_pkt_tc4_phy; 507 u64 rx_pkt_tc5_phy; 508 u64 tx_pkt_tc5_phy; 509 u64 rx_pkt_tc6_phy; 510 u64 tx_pkt_tc6_phy; 511 u64 rx_pkt_tc7_phy; 512 u64 tx_pkt_tc7_phy; 513 514 u64 rx_byte_tc0_phy; 515 u64 tx_byte_tc0_phy; 516 u64 rx_byte_tc1_phy; 517 u64 tx_byte_tc1_phy; 518 u64 rx_byte_tc2_phy; 519 u64 tx_byte_tc2_phy; 520 u64 rx_byte_tc3_phy; 521 u64 tx_byte_tc3_phy; 522 u64 rx_byte_tc4_phy; 523 u64 tx_byte_tc4_phy; 524 u64 rx_byte_tc5_phy; 525 u64 tx_byte_tc5_phy; 526 u64 rx_byte_tc6_phy; 527 u64 tx_byte_tc6_phy; 528 u64 rx_byte_tc7_phy; 529 u64 tx_byte_tc7_phy; 530 531 /* Per TC pause Counters */ 532 u64 rx_pause_tc0_phy; 533 u64 tx_pause_tc0_phy; 534 u64 rx_pause_tc1_phy; 535 u64 tx_pause_tc1_phy; 536 u64 rx_pause_tc2_phy; 537 u64 tx_pause_tc2_phy; 538 u64 rx_pause_tc3_phy; 539 u64 tx_pause_tc3_phy; 540 u64 rx_pause_tc4_phy; 541 u64 tx_pause_tc4_phy; 542 u64 rx_pause_tc5_phy; 543 u64 tx_pause_tc5_phy; 544 u64 rx_pause_tc6_phy; 545 u64 tx_pause_tc6_phy; 546 u64 rx_pause_tc7_phy; 547 u64 tx_pause_tc7_phy; 548 }; 549 550 struct mana_context { 551 struct gdma_dev *gdma_dev; 552 553 u16 num_ports; 554 u8 bm_hostmode; 555 556 struct mana_ethtool_hc_stats hc_stats; 557 struct workqueue_struct *per_port_queue_reset_wq; 558 /* Workqueue for querying hardware stats */ 559 struct delayed_work gf_stats_work; 560 bool hwc_timeout_occurred; 561 562 struct net_device *ports[MAX_PORTS_IN_MANA_DEV]; 563 564 /* Link state change work */ 565 struct work_struct link_change_work; 566 u32 link_event; 567 }; 568 569 struct mana_port_context { 570 struct mana_context *ac; 571 struct net_device *ndev; 572 struct work_struct queue_reset_work; 573 574 /* Debug knob to log TX timeout but skip recovery reset */ 575 bool tx_timeout_skip_reset; 576 577 u8 mac_addr[ETH_ALEN]; 578 579 struct mana_eq *eqs; 580 struct dentry *mana_eqs_debugfs; 581 582 enum TRI_STATE rss_state; 583 584 mana_handle_t default_rxobj; 585 bool tx_shortform_allowed; 586 u16 tx_vp_offset; 587 588 struct mana_tx_qp **tx_qp; 589 590 /* Indirection Table for RX & TX. The values are queue indexes */ 591 u32 *indir_table; 592 u32 indir_table_sz; 593 594 /* Indirection table containing RxObject Handles */ 595 mana_handle_t *rxobj_table; 596 597 /* Hash key used by the NIC */ 598 u8 hashkey[MANA_HASH_KEY_SIZE]; 599 600 /* This points to an array of num_queues of RQ pointers. */ 601 struct mana_rxq **rxqs; 602 603 /* pre-allocated rx buffer array */ 604 void **rxbufs_pre; 605 dma_addr_t *das_pre; 606 int rxbpre_total; 607 u32 rxbpre_datasize; 608 u32 rxbpre_alloc_size; 609 u32 rxbpre_headroom; 610 u32 rxbpre_frag_count; 611 612 u32 priv_flags; 613 614 struct bpf_prog *bpf_prog; 615 616 /* Create num_queues EQs, SQs, SQ-CQs, RQs and RQ-CQs, respectively. */ 617 unsigned int max_queues; 618 unsigned int num_queues; 619 620 unsigned int rx_queue_size; 621 unsigned int tx_queue_size; 622 623 mana_handle_t port_handle; 624 mana_handle_t pf_filter_handle; 625 626 /* Mutex for sharing access to vport_use_count */ 627 struct mutex vport_mutex; 628 int vport_use_count; 629 630 /* Set by mana_set_channels() under vport_mutex to block RDMA 631 * from grabbing the vport during the detach/attach window. 632 * Checked by mana_cfg_vport() when called from the RDMA path. 633 */ 634 bool channel_changing; 635 636 /* Net shaper handle*/ 637 struct net_shaper_handle handle; 638 639 u16 port_idx; 640 /* Currently configured speed (mbps) */ 641 u32 speed; 642 /* Maximum speed supported by the SKU (mbps) */ 643 u32 max_speed; 644 /* 1 = not queried, 0 = cached success, negative = permanent error. 645 * Protected by the netdev instance lock. 646 */ 647 int link_cfg_error; 648 649 bool port_is_up; 650 bool port_st_save; /* Saved port state */ 651 652 u8 cqe_coalescing_enable; 653 u8 cqe8_coalescing_enable; 654 u32 cqe_coalescing_timeout_ns; 655 656 /* Interrupt moderation settings */ 657 u16 intr_modr_rx_usec; 658 u16 intr_modr_rx_comp; 659 u16 intr_modr_tx_usec; 660 u16 intr_modr_tx_comp; 661 662 bool rx_dim_enabled; 663 bool tx_dim_enabled; 664 665 struct mana_ethtool_stats eth_stats; 666 667 struct mana_ethtool_phy_stats phy_stats; 668 669 /* Debugfs */ 670 struct dentry *mana_port_debugfs; 671 672 /* Cached vport/steering config for debugfs */ 673 u32 vport_max_sq; 674 u32 vport_max_rq; 675 u32 steer_rx; 676 u32 steer_rss; 677 bool steer_update_tab; 678 u32 steer_cqe_coalescing; 679 }; 680 681 netdev_tx_t __mana_start_xmit(struct sk_buff *skb, struct net_device *ndev, 682 bool xdp); 683 netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev); 684 int mana_config_rss(struct mana_port_context *ac, enum TRI_STATE rx, 685 bool update_hash, bool update_tab); 686 int mana_disable_vport_rx(struct mana_port_context *apc); 687 688 int mana_alloc_queues(struct net_device *ndev); 689 int mana_attach(struct net_device *ndev); 690 int mana_detach(struct net_device *ndev, bool from_close); 691 692 void mana_dim_change(struct mana_cq *cq, bool enable); 693 694 int mana_probe(struct gdma_dev *gd, bool resuming); 695 void mana_remove(struct gdma_dev *gd, bool suspending); 696 697 int mana_rdma_probe(struct gdma_dev *gd); 698 void mana_rdma_remove(struct gdma_dev *gd); 699 700 void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev); 701 int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames, 702 u32 flags); 703 u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq, 704 struct xdp_buff *xdp, void *buf_va, bool from_pool, 705 uint pkt_len); 706 struct bpf_prog *mana_xdp_get(struct mana_port_context *apc); 707 void mana_chn_setxdp(struct mana_port_context *apc, struct bpf_prog *prog); 708 int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf); 709 int mana_query_gf_stats(struct mana_context *ac); 710 int mana_query_link_cfg(struct mana_port_context *apc); 711 int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed, 712 int enable_clamping); 713 void mana_query_phy_stats(struct mana_port_context *apc); 714 bool mana_single_rxbuf_per_page_forced(struct mana_port_context *apc, u32 mtu); 715 int mana_pre_alloc_rxbufs(struct mana_port_context *apc, int mtu, int num_queues); 716 void mana_pre_dealloc_rxbufs(struct mana_port_context *apc); 717 void mana_unmap_skb(struct sk_buff *skb, struct mana_port_context *apc); 718 719 extern const struct ethtool_ops mana_ethtool_ops; 720 extern struct dentry *mana_debugfs_root; 721 722 /* A CQ can be created not associated with any EQ */ 723 #define GDMA_CQ_NO_EQ 0xffff 724 725 struct mana_obj_spec { 726 u32 queue_index; 727 u64 gdma_region; 728 u32 queue_size; 729 u32 attached_eq; 730 u32 modr_ctx_id; 731 u8 req_cq_moderation; 732 u16 cq_moderation_comp; 733 u16 cq_moderation_usec; 734 }; 735 736 enum mana_command_code { 737 MANA_QUERY_DEV_CONFIG = 0x20001, 738 MANA_QUERY_GF_STAT = 0x20002, 739 MANA_CONFIG_VPORT_TX = 0x20003, 740 MANA_CREATE_WQ_OBJ = 0x20004, 741 MANA_DESTROY_WQ_OBJ = 0x20005, 742 MANA_FENCE_RQ = 0x20006, 743 MANA_CONFIG_VPORT_RX = 0x20007, 744 MANA_QUERY_VPORT_CONFIG = 0x20008, 745 MANA_QUERY_LINK_CONFIG = 0x2000A, 746 MANA_SET_BW_CLAMP = 0x2000B, 747 MANA_QUERY_PHY_STAT = 0x2000c, 748 749 /* Privileged commands for the PF mode */ 750 MANA_REGISTER_FILTER = 0x28000, 751 MANA_DEREGISTER_FILTER = 0x28001, 752 MANA_REGISTER_HW_PORT = 0x28003, 753 MANA_DEREGISTER_HW_PORT = 0x28004, 754 }; 755 756 /* Query Link Configuration*/ 757 struct mana_query_link_config_req { 758 struct gdma_req_hdr hdr; 759 mana_handle_t vport; 760 }; /* HW DATA */ 761 762 struct mana_query_link_config_resp { 763 struct gdma_resp_hdr hdr; 764 u32 qos_speed_mbps; 765 u8 qos_unconfigured; 766 u8 reserved1[3]; 767 u32 link_speed_mbps; 768 u8 reserved2[4]; 769 }; /* HW DATA */ 770 771 /* Set Bandwidth Clamp*/ 772 struct mana_set_bw_clamp_req { 773 struct gdma_req_hdr hdr; 774 mana_handle_t vport; 775 enum TRI_STATE enable_clamping; 776 u32 link_speed_mbps; 777 }; /* HW DATA */ 778 779 struct mana_set_bw_clamp_resp { 780 struct gdma_resp_hdr hdr; 781 u8 qos_unconfigured; 782 u8 reserved[7]; 783 }; /* HW DATA */ 784 785 /* Query Device Configuration */ 786 struct mana_query_device_cfg_req { 787 struct gdma_req_hdr hdr; 788 789 /* MANA Nic Driver Capability flags */ 790 u64 mn_drv_cap_flags1; 791 u64 mn_drv_cap_flags2; 792 u64 mn_drv_cap_flags3; 793 u64 mn_drv_cap_flags4; 794 795 u32 proto_major_ver; 796 u32 proto_minor_ver; 797 u32 proto_micro_ver; 798 799 u32 reserved; 800 }; /* HW DATA */ 801 802 #define MANA_PF_FLAG_1_CQE_8_COALESCING_SUPPORTED BIT(5) 803 804 struct mana_query_device_cfg_resp { 805 struct gdma_resp_hdr hdr; 806 807 u64 pf_cap_flags1; 808 u64 pf_cap_flags2; 809 u64 pf_cap_flags3; 810 u64 pf_cap_flags4; 811 812 u16 max_num_vports; 813 u8 bm_hostmode; /* response v3: Bare Metal Host Mode */ 814 u8 reserved; 815 u32 max_num_eqs; 816 817 /* response v2: */ 818 u16 adapter_mtu; 819 u16 reserved2; 820 u32 reserved3; 821 }; /* HW DATA */ 822 823 /* Query vPort Configuration */ 824 struct mana_query_vport_cfg_req { 825 struct gdma_req_hdr hdr; 826 u32 vport_index; 827 }; /* HW DATA */ 828 829 struct mana_query_vport_cfg_resp { 830 struct gdma_resp_hdr hdr; 831 u32 max_num_sq; 832 u32 max_num_rq; 833 u32 num_indirection_ent; 834 u32 reserved1; 835 u8 mac_addr[6]; 836 u8 reserved2[2]; 837 mana_handle_t vport; 838 }; /* HW DATA */ 839 840 /* Configure vPort */ 841 struct mana_config_vport_req { 842 struct gdma_req_hdr hdr; 843 mana_handle_t vport; 844 u32 pdid; 845 u32 doorbell_pageid; 846 }; /* HW DATA */ 847 848 struct mana_config_vport_resp { 849 struct gdma_resp_hdr hdr; 850 u16 tx_vport_offset; 851 u8 short_form_allowed; 852 u8 reserved; 853 }; /* HW DATA */ 854 855 /* Create WQ Object */ 856 struct mana_create_wqobj_req { 857 struct gdma_req_hdr hdr; 858 mana_handle_t vport; 859 u32 wq_type; 860 u32 reserved; 861 u64 wq_gdma_region; 862 u64 cq_gdma_region; 863 u32 wq_size; 864 u32 cq_size; 865 u32 cq_moderation_ctx_id; 866 u32 cq_parent_qid; 867 868 /* V2 */ 869 u8 allow_rqwqe_chain; 870 871 /* V3 */ 872 u8 req_cq_moderation; 873 u16 cq_moderation_comp; 874 u16 cq_moderation_usec; 875 u8 reserved2[2]; 876 }; /* HW DATA */ 877 878 struct mana_create_wqobj_resp { 879 struct gdma_resp_hdr hdr; 880 u32 wq_id; 881 u32 cq_id; 882 mana_handle_t wq_obj; 883 884 /* V2 */ 885 u16 cq_moderation_comp; 886 u16 cq_moderation_usec; 887 u8 cq_moderation_enabled; 888 u8 reserved1[3]; 889 }; /* HW DATA */ 890 891 /* Destroy WQ Object */ 892 struct mana_destroy_wqobj_req { 893 struct gdma_req_hdr hdr; 894 u32 wq_type; 895 u32 reserved; 896 mana_handle_t wq_obj_handle; 897 }; /* HW DATA */ 898 899 struct mana_destroy_wqobj_resp { 900 struct gdma_resp_hdr hdr; 901 }; /* HW DATA */ 902 903 /* Fence RQ */ 904 struct mana_fence_rq_req { 905 struct gdma_req_hdr hdr; 906 mana_handle_t wq_obj_handle; 907 }; /* HW DATA */ 908 909 struct mana_fence_rq_resp { 910 struct gdma_resp_hdr hdr; 911 }; /* HW DATA */ 912 913 /* Query stats RQ */ 914 struct mana_query_gf_stat_req { 915 struct gdma_req_hdr hdr; 916 u64 req_stats; 917 }; /* HW DATA */ 918 919 struct mana_query_gf_stat_resp { 920 struct gdma_resp_hdr hdr; 921 u64 reported_stats; 922 /* rx errors/discards */ 923 u64 rx_discards_nowqe; 924 u64 rx_err_vport_disabled; 925 /* rx bytes/packets */ 926 u64 hc_rx_bytes; 927 u64 hc_rx_ucast_pkts; 928 u64 hc_rx_ucast_bytes; 929 u64 hc_rx_bcast_pkts; 930 u64 hc_rx_bcast_bytes; 931 u64 hc_rx_mcast_pkts; 932 u64 hc_rx_mcast_bytes; 933 /* tx errors */ 934 u64 tx_err_gf_disabled; 935 u64 tx_err_vport_disabled; 936 u64 tx_err_inval_vport_offset_pkt; 937 u64 tx_err_vlan_enforcement; 938 u64 tx_err_ethtype_enforcement; 939 u64 tx_err_SA_enforcement; 940 u64 tx_err_SQPDID_enforcement; 941 u64 tx_err_CQPDID_enforcement; 942 u64 tx_err_mtu_violation; 943 u64 tx_err_inval_oob; 944 /* tx bytes/packets */ 945 u64 hc_tx_bytes; 946 u64 hc_tx_ucast_pkts; 947 u64 hc_tx_ucast_bytes; 948 u64 hc_tx_bcast_pkts; 949 u64 hc_tx_bcast_bytes; 950 u64 hc_tx_mcast_pkts; 951 u64 hc_tx_mcast_bytes; 952 /* tx error */ 953 u64 tx_err_gdma; 954 }; /* HW DATA */ 955 956 /* Query phy stats */ 957 struct mana_query_phy_stat_req { 958 struct gdma_req_hdr hdr; 959 u64 req_stats; 960 }; /* HW DATA */ 961 962 struct mana_query_phy_stat_resp { 963 struct gdma_resp_hdr hdr; 964 u64 reported_stats; 965 966 /* Aggregate Drop Counters */ 967 u64 rx_pkt_drop_phy; 968 u64 tx_pkt_drop_phy; 969 970 /* Per TC(Traffic class) traffic Counters */ 971 u64 rx_pkt_tc0_phy; 972 u64 tx_pkt_tc0_phy; 973 u64 rx_pkt_tc1_phy; 974 u64 tx_pkt_tc1_phy; 975 u64 rx_pkt_tc2_phy; 976 u64 tx_pkt_tc2_phy; 977 u64 rx_pkt_tc3_phy; 978 u64 tx_pkt_tc3_phy; 979 u64 rx_pkt_tc4_phy; 980 u64 tx_pkt_tc4_phy; 981 u64 rx_pkt_tc5_phy; 982 u64 tx_pkt_tc5_phy; 983 u64 rx_pkt_tc6_phy; 984 u64 tx_pkt_tc6_phy; 985 u64 rx_pkt_tc7_phy; 986 u64 tx_pkt_tc7_phy; 987 988 u64 rx_byte_tc0_phy; 989 u64 tx_byte_tc0_phy; 990 u64 rx_byte_tc1_phy; 991 u64 tx_byte_tc1_phy; 992 u64 rx_byte_tc2_phy; 993 u64 tx_byte_tc2_phy; 994 u64 rx_byte_tc3_phy; 995 u64 tx_byte_tc3_phy; 996 u64 rx_byte_tc4_phy; 997 u64 tx_byte_tc4_phy; 998 u64 rx_byte_tc5_phy; 999 u64 tx_byte_tc5_phy; 1000 u64 rx_byte_tc6_phy; 1001 u64 tx_byte_tc6_phy; 1002 u64 rx_byte_tc7_phy; 1003 u64 tx_byte_tc7_phy; 1004 1005 /* Per TC(Traffic Class) pause Counters */ 1006 u64 rx_pause_tc0_phy; 1007 u64 tx_pause_tc0_phy; 1008 u64 rx_pause_tc1_phy; 1009 u64 tx_pause_tc1_phy; 1010 u64 rx_pause_tc2_phy; 1011 u64 tx_pause_tc2_phy; 1012 u64 rx_pause_tc3_phy; 1013 u64 tx_pause_tc3_phy; 1014 u64 rx_pause_tc4_phy; 1015 u64 tx_pause_tc4_phy; 1016 u64 rx_pause_tc5_phy; 1017 u64 tx_pause_tc5_phy; 1018 u64 rx_pause_tc6_phy; 1019 u64 tx_pause_tc6_phy; 1020 u64 rx_pause_tc7_phy; 1021 u64 tx_pause_tc7_phy; 1022 }; /* HW DATA */ 1023 1024 /* Configure vPort Rx Steering */ 1025 struct mana_cfg_rx_steer_req_v2 { 1026 struct gdma_req_hdr hdr; 1027 mana_handle_t vport; 1028 u16 num_indir_entries; 1029 u16 indir_tab_offset; 1030 u32 rx_enable; 1031 u32 rss_enable; 1032 u8 update_default_rxobj; 1033 u8 update_hashkey; 1034 u8 update_indir_tab; 1035 u8 reserved; 1036 mana_handle_t default_rxobj; 1037 u8 hashkey[MANA_HASH_KEY_SIZE]; 1038 u8 cqe_coalescing_enable; 1039 u8 reserved2[3]; 1040 u16 rss_hash_types; 1041 u8 cqe8_coalescing_enable; /* v5 message */ 1042 u8 reserved3; 1043 mana_handle_t indir_tab[] __counted_by(num_indir_entries); 1044 }; /* HW DATA */ 1045 1046 struct mana_cfg_rx_steer_resp { 1047 struct gdma_resp_hdr hdr; 1048 1049 /* V2 */ 1050 u32 cqe_coalescing_timeout_ns; 1051 u32 reserved1; 1052 }; /* HW DATA */ 1053 1054 /* Register HW vPort */ 1055 struct mana_register_hw_vport_req { 1056 struct gdma_req_hdr hdr; 1057 u16 attached_gfid; 1058 u8 is_pf_default_vport; 1059 u8 reserved1; 1060 u8 allow_all_ether_types; 1061 u8 reserved2; 1062 u8 reserved3; 1063 u8 reserved4; 1064 }; /* HW DATA */ 1065 1066 struct mana_register_hw_vport_resp { 1067 struct gdma_resp_hdr hdr; 1068 mana_handle_t hw_vport_handle; 1069 }; /* HW DATA */ 1070 1071 /* Deregister HW vPort */ 1072 struct mana_deregister_hw_vport_req { 1073 struct gdma_req_hdr hdr; 1074 mana_handle_t hw_vport_handle; 1075 }; /* HW DATA */ 1076 1077 struct mana_deregister_hw_vport_resp { 1078 struct gdma_resp_hdr hdr; 1079 }; /* HW DATA */ 1080 1081 /* Register filter */ 1082 struct mana_register_filter_req { 1083 struct gdma_req_hdr hdr; 1084 mana_handle_t vport; 1085 u8 mac_addr[6]; 1086 u8 reserved1; 1087 u8 reserved2; 1088 u8 reserved3; 1089 u8 reserved4; 1090 u16 reserved5; 1091 u32 reserved6; 1092 u32 reserved7; 1093 u32 reserved8; 1094 }; /* HW DATA */ 1095 1096 struct mana_register_filter_resp { 1097 struct gdma_resp_hdr hdr; 1098 mana_handle_t filter_handle; 1099 }; /* HW DATA */ 1100 1101 /* Deregister filter */ 1102 struct mana_deregister_filter_req { 1103 struct gdma_req_hdr hdr; 1104 mana_handle_t filter_handle; 1105 }; /* HW DATA */ 1106 1107 struct mana_deregister_filter_resp { 1108 struct gdma_resp_hdr hdr; 1109 }; /* HW DATA */ 1110 1111 /* Requested GF stats Flags */ 1112 /* Rx discards/Errors */ 1113 #define STATISTICS_FLAGS_RX_DISCARDS_NO_WQE 0x0000000000000001 1114 #define STATISTICS_FLAGS_RX_ERRORS_VPORT_DISABLED 0x0000000000000002 1115 /* Rx bytes/pkts */ 1116 #define STATISTICS_FLAGS_HC_RX_BYTES 0x0000000000000004 1117 #define STATISTICS_FLAGS_HC_RX_UCAST_PACKETS 0x0000000000000008 1118 #define STATISTICS_FLAGS_HC_RX_UCAST_BYTES 0x0000000000000010 1119 #define STATISTICS_FLAGS_HC_RX_MCAST_PACKETS 0x0000000000000020 1120 #define STATISTICS_FLAGS_HC_RX_MCAST_BYTES 0x0000000000000040 1121 #define STATISTICS_FLAGS_HC_RX_BCAST_PACKETS 0x0000000000000080 1122 #define STATISTICS_FLAGS_HC_RX_BCAST_BYTES 0x0000000000000100 1123 /* Tx errors */ 1124 #define STATISTICS_FLAGS_TX_ERRORS_GF_DISABLED 0x0000000000000200 1125 #define STATISTICS_FLAGS_TX_ERRORS_VPORT_DISABLED 0x0000000000000400 1126 #define STATISTICS_FLAGS_TX_ERRORS_INVAL_VPORT_OFFSET_PACKETS \ 1127 0x0000000000000800 1128 #define STATISTICS_FLAGS_TX_ERRORS_VLAN_ENFORCEMENT 0x0000000000001000 1129 #define STATISTICS_FLAGS_TX_ERRORS_ETH_TYPE_ENFORCEMENT \ 1130 0x0000000000002000 1131 #define STATISTICS_FLAGS_TX_ERRORS_SA_ENFORCEMENT 0x0000000000004000 1132 #define STATISTICS_FLAGS_TX_ERRORS_SQPDID_ENFORCEMENT 0x0000000000008000 1133 #define STATISTICS_FLAGS_TX_ERRORS_CQPDID_ENFORCEMENT 0x0000000000010000 1134 #define STATISTICS_FLAGS_TX_ERRORS_MTU_VIOLATION 0x0000000000020000 1135 #define STATISTICS_FLAGS_TX_ERRORS_INVALID_OOB 0x0000000000040000 1136 /* Tx bytes/pkts */ 1137 #define STATISTICS_FLAGS_HC_TX_BYTES 0x0000000000080000 1138 #define STATISTICS_FLAGS_HC_TX_UCAST_PACKETS 0x0000000000100000 1139 #define STATISTICS_FLAGS_HC_TX_UCAST_BYTES 0x0000000000200000 1140 #define STATISTICS_FLAGS_HC_TX_MCAST_PACKETS 0x0000000000400000 1141 #define STATISTICS_FLAGS_HC_TX_MCAST_BYTES 0x0000000000800000 1142 #define STATISTICS_FLAGS_HC_TX_BCAST_PACKETS 0x0000000001000000 1143 #define STATISTICS_FLAGS_HC_TX_BCAST_BYTES 0x0000000002000000 1144 /* Tx error */ 1145 #define STATISTICS_FLAGS_TX_ERRORS_GDMA_ERROR 0x0000000004000000 1146 1147 #define MANA_MAX_NUM_QUEUES 64 1148 #define MANA_DEF_NUM_QUEUES 16 1149 1150 #define MANA_SHORT_VPORT_OFFSET_MAX ((1U << 8) - 1) 1151 1152 struct mana_tx_package { 1153 struct gdma_wqe_request wqe_req; 1154 struct gdma_sge sgl_array[5]; 1155 struct gdma_sge *sgl_ptr; 1156 1157 struct mana_tx_oob tx_oob; 1158 1159 struct gdma_posted_wqe_info wqe_info; 1160 }; 1161 1162 int mana_create_wq_obj(struct mana_port_context *apc, 1163 mana_handle_t vport, 1164 u32 wq_type, struct mana_obj_spec *wq_spec, 1165 struct mana_obj_spec *cq_spec, 1166 mana_handle_t *wq_obj); 1167 1168 void mana_destroy_wq_obj(struct mana_port_context *apc, u32 wq_type, 1169 mana_handle_t wq_obj); 1170 1171 int mana_cfg_vport(struct mana_port_context *apc, u32 protection_dom_id, 1172 u32 doorbell_pg_id, bool check_channel_changing); 1173 void mana_uncfg_vport(struct mana_port_context *apc); 1174 int mana_create_eq(struct mana_port_context *apc); 1175 void mana_destroy_eq(struct mana_port_context *apc); 1176 1177 struct net_device *mana_get_primary_netdev(struct mana_context *ac, 1178 u32 port_index, 1179 netdevice_tracker *tracker); 1180 #endif /* _MANA_H */ 1181