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