mana.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /* Copyright (c) 2021, Microsoft Corporation. */
  3. #ifndef _MANA_H
  4. #define _MANA_H
  5. #include "gdma.h"
  6. #include "hw_channel.h"
  7. /* Microsoft Azure Network Adapter (MANA)'s definitions
  8. *
  9. * Structures labeled with "HW DATA" are exchanged with the hardware. All of
  10. * them are naturally aligned and hence don't need __packed.
  11. */
  12. /* MANA protocol version */
  13. #define MANA_MAJOR_VERSION 0
  14. #define MANA_MINOR_VERSION 1
  15. #define MANA_MICRO_VERSION 1
  16. typedef u64 mana_handle_t;
  17. #define INVALID_MANA_HANDLE ((mana_handle_t)-1)
  18. enum TRI_STATE {
  19. TRI_STATE_UNKNOWN = -1,
  20. TRI_STATE_FALSE = 0,
  21. TRI_STATE_TRUE = 1
  22. };
  23. /* Number of entries for hardware indirection table must be in power of 2 */
  24. #define MANA_INDIRECT_TABLE_SIZE 64
  25. #define MANA_INDIRECT_TABLE_MASK (MANA_INDIRECT_TABLE_SIZE - 1)
  26. /* The Toeplitz hash key's length in bytes: should be multiple of 8 */
  27. #define MANA_HASH_KEY_SIZE 40
  28. #define COMP_ENTRY_SIZE 64
  29. #define ADAPTER_MTU_SIZE 1500
  30. #define MAX_FRAME_SIZE (ADAPTER_MTU_SIZE + 14)
  31. #define RX_BUFFERS_PER_QUEUE 512
  32. #define MAX_SEND_BUFFERS_PER_QUEUE 256
  33. #define EQ_SIZE (8 * PAGE_SIZE)
  34. #define LOG2_EQ_THROTTLE 3
  35. #define MAX_PORTS_IN_MANA_DEV 256
  36. struct mana_stats_rx {
  37. u64 packets;
  38. u64 bytes;
  39. u64 xdp_drop;
  40. u64 xdp_tx;
  41. u64 xdp_redirect;
  42. struct u64_stats_sync syncp;
  43. };
  44. struct mana_stats_tx {
  45. u64 packets;
  46. u64 bytes;
  47. u64 xdp_xmit;
  48. struct u64_stats_sync syncp;
  49. };
  50. struct mana_txq {
  51. struct gdma_queue *gdma_sq;
  52. union {
  53. u32 gdma_txq_id;
  54. struct {
  55. u32 reserved1 : 10;
  56. u32 vsq_frame : 14;
  57. u32 reserved2 : 8;
  58. };
  59. };
  60. u16 vp_offset;
  61. struct net_device *ndev;
  62. /* The SKBs are sent to the HW and we are waiting for the CQEs. */
  63. struct sk_buff_head pending_skbs;
  64. struct netdev_queue *net_txq;
  65. atomic_t pending_sends;
  66. struct mana_stats_tx stats;
  67. };
  68. /* skb data and frags dma mappings */
  69. struct mana_skb_head {
  70. dma_addr_t dma_handle[MAX_SKB_FRAGS + 1];
  71. u32 size[MAX_SKB_FRAGS + 1];
  72. };
  73. #define MANA_HEADROOM sizeof(struct mana_skb_head)
  74. enum mana_tx_pkt_format {
  75. MANA_SHORT_PKT_FMT = 0,
  76. MANA_LONG_PKT_FMT = 1,
  77. };
  78. struct mana_tx_short_oob {
  79. u32 pkt_fmt : 2;
  80. u32 is_outer_ipv4 : 1;
  81. u32 is_outer_ipv6 : 1;
  82. u32 comp_iphdr_csum : 1;
  83. u32 comp_tcp_csum : 1;
  84. u32 comp_udp_csum : 1;
  85. u32 supress_txcqe_gen : 1;
  86. u32 vcq_num : 24;
  87. u32 trans_off : 10; /* Transport header offset */
  88. u32 vsq_frame : 14;
  89. u32 short_vp_offset : 8;
  90. }; /* HW DATA */
  91. struct mana_tx_long_oob {
  92. u32 is_encap : 1;
  93. u32 inner_is_ipv6 : 1;
  94. u32 inner_tcp_opt : 1;
  95. u32 inject_vlan_pri_tag : 1;
  96. u32 reserved1 : 12;
  97. u32 pcp : 3; /* 802.1Q */
  98. u32 dei : 1; /* 802.1Q */
  99. u32 vlan_id : 12; /* 802.1Q */
  100. u32 inner_frame_offset : 10;
  101. u32 inner_ip_rel_offset : 6;
  102. u32 long_vp_offset : 12;
  103. u32 reserved2 : 4;
  104. u32 reserved3;
  105. u32 reserved4;
  106. }; /* HW DATA */
  107. struct mana_tx_oob {
  108. struct mana_tx_short_oob s_oob;
  109. struct mana_tx_long_oob l_oob;
  110. }; /* HW DATA */
  111. enum mana_cq_type {
  112. MANA_CQ_TYPE_RX,
  113. MANA_CQ_TYPE_TX,
  114. };
  115. enum mana_cqe_type {
  116. CQE_INVALID = 0,
  117. CQE_RX_OKAY = 1,
  118. CQE_RX_COALESCED_4 = 2,
  119. CQE_RX_OBJECT_FENCE = 3,
  120. CQE_RX_TRUNCATED = 4,
  121. CQE_TX_OKAY = 32,
  122. CQE_TX_SA_DROP = 33,
  123. CQE_TX_MTU_DROP = 34,
  124. CQE_TX_INVALID_OOB = 35,
  125. CQE_TX_INVALID_ETH_TYPE = 36,
  126. CQE_TX_HDR_PROCESSING_ERROR = 37,
  127. CQE_TX_VF_DISABLED = 38,
  128. CQE_TX_VPORT_IDX_OUT_OF_RANGE = 39,
  129. CQE_TX_VPORT_DISABLED = 40,
  130. CQE_TX_VLAN_TAGGING_VIOLATION = 41,
  131. };
  132. #define MANA_CQE_COMPLETION 1
  133. struct mana_cqe_header {
  134. u32 cqe_type : 6;
  135. u32 client_type : 2;
  136. u32 vendor_err : 24;
  137. }; /* HW DATA */
  138. /* NDIS HASH Types */
  139. #define NDIS_HASH_IPV4 BIT(0)
  140. #define NDIS_HASH_TCP_IPV4 BIT(1)
  141. #define NDIS_HASH_UDP_IPV4 BIT(2)
  142. #define NDIS_HASH_IPV6 BIT(3)
  143. #define NDIS_HASH_TCP_IPV6 BIT(4)
  144. #define NDIS_HASH_UDP_IPV6 BIT(5)
  145. #define NDIS_HASH_IPV6_EX BIT(6)
  146. #define NDIS_HASH_TCP_IPV6_EX BIT(7)
  147. #define NDIS_HASH_UDP_IPV6_EX BIT(8)
  148. #define MANA_HASH_L3 (NDIS_HASH_IPV4 | NDIS_HASH_IPV6 | NDIS_HASH_IPV6_EX)
  149. #define MANA_HASH_L4 \
  150. (NDIS_HASH_TCP_IPV4 | NDIS_HASH_UDP_IPV4 | NDIS_HASH_TCP_IPV6 | \
  151. NDIS_HASH_UDP_IPV6 | NDIS_HASH_TCP_IPV6_EX | NDIS_HASH_UDP_IPV6_EX)
  152. struct mana_rxcomp_perpkt_info {
  153. u32 pkt_len : 16;
  154. u32 reserved1 : 16;
  155. u32 reserved2;
  156. u32 pkt_hash;
  157. }; /* HW DATA */
  158. #define MANA_RXCOMP_OOB_NUM_PPI 4
  159. /* Receive completion OOB */
  160. struct mana_rxcomp_oob {
  161. struct mana_cqe_header cqe_hdr;
  162. u32 rx_vlan_id : 12;
  163. u32 rx_vlantag_present : 1;
  164. u32 rx_outer_iphdr_csum_succeed : 1;
  165. u32 rx_outer_iphdr_csum_fail : 1;
  166. u32 reserved1 : 1;
  167. u32 rx_hashtype : 9;
  168. u32 rx_iphdr_csum_succeed : 1;
  169. u32 rx_iphdr_csum_fail : 1;
  170. u32 rx_tcp_csum_succeed : 1;
  171. u32 rx_tcp_csum_fail : 1;
  172. u32 rx_udp_csum_succeed : 1;
  173. u32 rx_udp_csum_fail : 1;
  174. u32 reserved2 : 1;
  175. struct mana_rxcomp_perpkt_info ppi[MANA_RXCOMP_OOB_NUM_PPI];
  176. u32 rx_wqe_offset;
  177. }; /* HW DATA */
  178. struct mana_tx_comp_oob {
  179. struct mana_cqe_header cqe_hdr;
  180. u32 tx_data_offset;
  181. u32 tx_sgl_offset : 5;
  182. u32 tx_wqe_offset : 27;
  183. u32 reserved[12];
  184. }; /* HW DATA */
  185. struct mana_rxq;
  186. #define CQE_POLLING_BUFFER 512
  187. struct mana_cq {
  188. struct gdma_queue *gdma_cq;
  189. /* Cache the CQ id (used to verify if each CQE comes to the right CQ. */
  190. u32 gdma_id;
  191. /* Type of the CQ: TX or RX */
  192. enum mana_cq_type type;
  193. /* Pointer to the mana_rxq that is pushing RX CQEs to the queue.
  194. * Only and must be non-NULL if type is MANA_CQ_TYPE_RX.
  195. */
  196. struct mana_rxq *rxq;
  197. /* Pointer to the mana_txq that is pushing TX CQEs to the queue.
  198. * Only and must be non-NULL if type is MANA_CQ_TYPE_TX.
  199. */
  200. struct mana_txq *txq;
  201. /* Buffer which the CQ handler can copy the CQE's into. */
  202. struct gdma_comp gdma_comp_buf[CQE_POLLING_BUFFER];
  203. /* NAPI data */
  204. struct napi_struct napi;
  205. int work_done;
  206. int budget;
  207. };
  208. #define GDMA_MAX_RQE_SGES 15
  209. struct mana_recv_buf_oob {
  210. /* A valid GDMA work request representing the data buffer. */
  211. struct gdma_wqe_request wqe_req;
  212. void *buf_va;
  213. dma_addr_t buf_dma_addr;
  214. /* SGL of the buffer going to be sent has part of the work request. */
  215. u32 num_sge;
  216. struct gdma_sge sgl[GDMA_MAX_RQE_SGES];
  217. /* Required to store the result of mana_gd_post_work_request.
  218. * gdma_posted_wqe_info.wqe_size_in_bu is required for progressing the
  219. * work queue when the WQE is consumed.
  220. */
  221. struct gdma_posted_wqe_info wqe_inf;
  222. };
  223. struct mana_rxq {
  224. struct gdma_queue *gdma_rq;
  225. /* Cache the gdma receive queue id */
  226. u32 gdma_id;
  227. /* Index of RQ in the vPort, not gdma receive queue id */
  228. u32 rxq_idx;
  229. u32 datasize;
  230. mana_handle_t rxobj;
  231. struct mana_cq rx_cq;
  232. struct completion fence_event;
  233. struct net_device *ndev;
  234. /* Total number of receive buffers to be allocated */
  235. u32 num_rx_buf;
  236. u32 buf_index;
  237. struct mana_stats_rx stats;
  238. struct bpf_prog __rcu *bpf_prog;
  239. struct xdp_rxq_info xdp_rxq;
  240. struct page *xdp_save_page;
  241. bool xdp_flush;
  242. int xdp_rc; /* XDP redirect return code */
  243. /* MUST BE THE LAST MEMBER:
  244. * Each receive buffer has an associated mana_recv_buf_oob.
  245. */
  246. struct mana_recv_buf_oob rx_oobs[];
  247. };
  248. struct mana_tx_qp {
  249. struct mana_txq txq;
  250. struct mana_cq tx_cq;
  251. mana_handle_t tx_object;
  252. };
  253. struct mana_ethtool_stats {
  254. u64 stop_queue;
  255. u64 wake_queue;
  256. };
  257. struct mana_context {
  258. struct gdma_dev *gdma_dev;
  259. u16 num_ports;
  260. struct mana_eq *eqs;
  261. struct net_device *ports[MAX_PORTS_IN_MANA_DEV];
  262. };
  263. struct mana_port_context {
  264. struct mana_context *ac;
  265. struct net_device *ndev;
  266. u8 mac_addr[ETH_ALEN];
  267. enum TRI_STATE rss_state;
  268. mana_handle_t default_rxobj;
  269. bool tx_shortform_allowed;
  270. u16 tx_vp_offset;
  271. struct mana_tx_qp *tx_qp;
  272. /* Indirection Table for RX & TX. The values are queue indexes */
  273. u32 indir_table[MANA_INDIRECT_TABLE_SIZE];
  274. /* Indirection table containing RxObject Handles */
  275. mana_handle_t rxobj_table[MANA_INDIRECT_TABLE_SIZE];
  276. /* Hash key used by the NIC */
  277. u8 hashkey[MANA_HASH_KEY_SIZE];
  278. /* This points to an array of num_queues of RQ pointers. */
  279. struct mana_rxq **rxqs;
  280. struct bpf_prog *bpf_prog;
  281. /* Create num_queues EQs, SQs, SQ-CQs, RQs and RQ-CQs, respectively. */
  282. unsigned int max_queues;
  283. unsigned int num_queues;
  284. mana_handle_t port_handle;
  285. mana_handle_t pf_filter_handle;
  286. u16 port_idx;
  287. bool port_is_up;
  288. bool port_st_save; /* Saved port state */
  289. struct mana_ethtool_stats eth_stats;
  290. };
  291. int mana_start_xmit(struct sk_buff *skb, struct net_device *ndev);
  292. int mana_config_rss(struct mana_port_context *ac, enum TRI_STATE rx,
  293. bool update_hash, bool update_tab);
  294. int mana_alloc_queues(struct net_device *ndev);
  295. int mana_attach(struct net_device *ndev);
  296. int mana_detach(struct net_device *ndev, bool from_close);
  297. int mana_probe(struct gdma_dev *gd, bool resuming);
  298. void mana_remove(struct gdma_dev *gd, bool suspending);
  299. void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev);
  300. int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames,
  301. u32 flags);
  302. u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq,
  303. struct xdp_buff *xdp, void *buf_va, uint pkt_len);
  304. struct bpf_prog *mana_xdp_get(struct mana_port_context *apc);
  305. void mana_chn_setxdp(struct mana_port_context *apc, struct bpf_prog *prog);
  306. int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf);
  307. extern const struct ethtool_ops mana_ethtool_ops;
  308. struct mana_obj_spec {
  309. u32 queue_index;
  310. u64 gdma_region;
  311. u32 queue_size;
  312. u32 attached_eq;
  313. u32 modr_ctx_id;
  314. };
  315. enum mana_command_code {
  316. MANA_QUERY_DEV_CONFIG = 0x20001,
  317. MANA_QUERY_GF_STAT = 0x20002,
  318. MANA_CONFIG_VPORT_TX = 0x20003,
  319. MANA_CREATE_WQ_OBJ = 0x20004,
  320. MANA_DESTROY_WQ_OBJ = 0x20005,
  321. MANA_FENCE_RQ = 0x20006,
  322. MANA_CONFIG_VPORT_RX = 0x20007,
  323. MANA_QUERY_VPORT_CONFIG = 0x20008,
  324. /* Privileged commands for the PF mode */
  325. MANA_REGISTER_FILTER = 0x28000,
  326. MANA_DEREGISTER_FILTER = 0x28001,
  327. MANA_REGISTER_HW_PORT = 0x28003,
  328. MANA_DEREGISTER_HW_PORT = 0x28004,
  329. };
  330. /* Query Device Configuration */
  331. struct mana_query_device_cfg_req {
  332. struct gdma_req_hdr hdr;
  333. /* MANA Nic Driver Capability flags */
  334. u64 mn_drv_cap_flags1;
  335. u64 mn_drv_cap_flags2;
  336. u64 mn_drv_cap_flags3;
  337. u64 mn_drv_cap_flags4;
  338. u32 proto_major_ver;
  339. u32 proto_minor_ver;
  340. u32 proto_micro_ver;
  341. u32 reserved;
  342. }; /* HW DATA */
  343. struct mana_query_device_cfg_resp {
  344. struct gdma_resp_hdr hdr;
  345. u64 pf_cap_flags1;
  346. u64 pf_cap_flags2;
  347. u64 pf_cap_flags3;
  348. u64 pf_cap_flags4;
  349. u16 max_num_vports;
  350. u16 reserved;
  351. u32 max_num_eqs;
  352. }; /* HW DATA */
  353. /* Query vPort Configuration */
  354. struct mana_query_vport_cfg_req {
  355. struct gdma_req_hdr hdr;
  356. u32 vport_index;
  357. }; /* HW DATA */
  358. struct mana_query_vport_cfg_resp {
  359. struct gdma_resp_hdr hdr;
  360. u32 max_num_sq;
  361. u32 max_num_rq;
  362. u32 num_indirection_ent;
  363. u32 reserved1;
  364. u8 mac_addr[6];
  365. u8 reserved2[2];
  366. mana_handle_t vport;
  367. }; /* HW DATA */
  368. /* Configure vPort */
  369. struct mana_config_vport_req {
  370. struct gdma_req_hdr hdr;
  371. mana_handle_t vport;
  372. u32 pdid;
  373. u32 doorbell_pageid;
  374. }; /* HW DATA */
  375. struct mana_config_vport_resp {
  376. struct gdma_resp_hdr hdr;
  377. u16 tx_vport_offset;
  378. u8 short_form_allowed;
  379. u8 reserved;
  380. }; /* HW DATA */
  381. /* Create WQ Object */
  382. struct mana_create_wqobj_req {
  383. struct gdma_req_hdr hdr;
  384. mana_handle_t vport;
  385. u32 wq_type;
  386. u32 reserved;
  387. u64 wq_gdma_region;
  388. u64 cq_gdma_region;
  389. u32 wq_size;
  390. u32 cq_size;
  391. u32 cq_moderation_ctx_id;
  392. u32 cq_parent_qid;
  393. }; /* HW DATA */
  394. struct mana_create_wqobj_resp {
  395. struct gdma_resp_hdr hdr;
  396. u32 wq_id;
  397. u32 cq_id;
  398. mana_handle_t wq_obj;
  399. }; /* HW DATA */
  400. /* Destroy WQ Object */
  401. struct mana_destroy_wqobj_req {
  402. struct gdma_req_hdr hdr;
  403. u32 wq_type;
  404. u32 reserved;
  405. mana_handle_t wq_obj_handle;
  406. }; /* HW DATA */
  407. struct mana_destroy_wqobj_resp {
  408. struct gdma_resp_hdr hdr;
  409. }; /* HW DATA */
  410. /* Fence RQ */
  411. struct mana_fence_rq_req {
  412. struct gdma_req_hdr hdr;
  413. mana_handle_t wq_obj_handle;
  414. }; /* HW DATA */
  415. struct mana_fence_rq_resp {
  416. struct gdma_resp_hdr hdr;
  417. }; /* HW DATA */
  418. /* Configure vPort Rx Steering */
  419. struct mana_cfg_rx_steer_req {
  420. struct gdma_req_hdr hdr;
  421. mana_handle_t vport;
  422. u16 num_indir_entries;
  423. u16 indir_tab_offset;
  424. u32 rx_enable;
  425. u32 rss_enable;
  426. u8 update_default_rxobj;
  427. u8 update_hashkey;
  428. u8 update_indir_tab;
  429. u8 reserved;
  430. mana_handle_t default_rxobj;
  431. u8 hashkey[MANA_HASH_KEY_SIZE];
  432. }; /* HW DATA */
  433. struct mana_cfg_rx_steer_resp {
  434. struct gdma_resp_hdr hdr;
  435. }; /* HW DATA */
  436. /* Register HW vPort */
  437. struct mana_register_hw_vport_req {
  438. struct gdma_req_hdr hdr;
  439. u16 attached_gfid;
  440. u8 is_pf_default_vport;
  441. u8 reserved1;
  442. u8 allow_all_ether_types;
  443. u8 reserved2;
  444. u8 reserved3;
  445. u8 reserved4;
  446. }; /* HW DATA */
  447. struct mana_register_hw_vport_resp {
  448. struct gdma_resp_hdr hdr;
  449. mana_handle_t hw_vport_handle;
  450. }; /* HW DATA */
  451. /* Deregister HW vPort */
  452. struct mana_deregister_hw_vport_req {
  453. struct gdma_req_hdr hdr;
  454. mana_handle_t hw_vport_handle;
  455. }; /* HW DATA */
  456. struct mana_deregister_hw_vport_resp {
  457. struct gdma_resp_hdr hdr;
  458. }; /* HW DATA */
  459. /* Register filter */
  460. struct mana_register_filter_req {
  461. struct gdma_req_hdr hdr;
  462. mana_handle_t vport;
  463. u8 mac_addr[6];
  464. u8 reserved1;
  465. u8 reserved2;
  466. u8 reserved3;
  467. u8 reserved4;
  468. u16 reserved5;
  469. u32 reserved6;
  470. u32 reserved7;
  471. u32 reserved8;
  472. }; /* HW DATA */
  473. struct mana_register_filter_resp {
  474. struct gdma_resp_hdr hdr;
  475. mana_handle_t filter_handle;
  476. }; /* HW DATA */
  477. /* Deregister filter */
  478. struct mana_deregister_filter_req {
  479. struct gdma_req_hdr hdr;
  480. mana_handle_t filter_handle;
  481. }; /* HW DATA */
  482. struct mana_deregister_filter_resp {
  483. struct gdma_resp_hdr hdr;
  484. }; /* HW DATA */
  485. #define MANA_MAX_NUM_QUEUES 64
  486. #define MANA_SHORT_VPORT_OFFSET_MAX ((1U << 8) - 1)
  487. struct mana_tx_package {
  488. struct gdma_wqe_request wqe_req;
  489. struct gdma_sge sgl_array[5];
  490. struct gdma_sge *sgl_ptr;
  491. struct mana_tx_oob tx_oob;
  492. struct gdma_posted_wqe_info wqe_info;
  493. };
  494. #endif /* _MANA_H */