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