mana.h 24 KB

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