gdma.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /* Copyright (c) 2021, Microsoft Corporation. */
  3. #ifndef _GDMA_H
  4. #define _GDMA_H
  5. #include <linux/dma-mapping.h>
  6. #include <linux/netdevice.h>
  7. #include "shm_channel.h"
  8. #define GDMA_STATUS_MORE_ENTRIES 0x00000105
  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. enum gdma_request_type {
  13. GDMA_VERIFY_VF_DRIVER_VERSION = 1,
  14. GDMA_QUERY_MAX_RESOURCES = 2,
  15. GDMA_LIST_DEVICES = 3,
  16. GDMA_REGISTER_DEVICE = 4,
  17. GDMA_DEREGISTER_DEVICE = 5,
  18. GDMA_GENERATE_TEST_EQE = 10,
  19. GDMA_CREATE_QUEUE = 12,
  20. GDMA_DISABLE_QUEUE = 13,
  21. GDMA_ALLOCATE_RESOURCE_RANGE = 22,
  22. GDMA_DESTROY_RESOURCE_RANGE = 24,
  23. GDMA_CREATE_DMA_REGION = 25,
  24. GDMA_DMA_REGION_ADD_PAGES = 26,
  25. GDMA_DESTROY_DMA_REGION = 27,
  26. GDMA_CREATE_PD = 29,
  27. GDMA_DESTROY_PD = 30,
  28. GDMA_CREATE_MR = 31,
  29. GDMA_DESTROY_MR = 32,
  30. GDMA_QUERY_HWC_TIMEOUT = 84, /* 0x54 */
  31. };
  32. #define GDMA_RESOURCE_DOORBELL_PAGE 27
  33. enum gdma_queue_type {
  34. GDMA_INVALID_QUEUE,
  35. GDMA_SQ,
  36. GDMA_RQ,
  37. GDMA_CQ,
  38. GDMA_EQ,
  39. };
  40. enum gdma_work_request_flags {
  41. GDMA_WR_NONE = 0,
  42. GDMA_WR_OOB_IN_SGL = BIT(0),
  43. GDMA_WR_PAD_BY_SGE0 = BIT(1),
  44. };
  45. enum gdma_eqe_type {
  46. GDMA_EQE_COMPLETION = 3,
  47. GDMA_EQE_TEST_EVENT = 64,
  48. GDMA_EQE_HWC_INIT_EQ_ID_DB = 129,
  49. GDMA_EQE_HWC_INIT_DATA = 130,
  50. GDMA_EQE_HWC_INIT_DONE = 131,
  51. GDMA_EQE_HWC_SOC_RECONFIG = 132,
  52. GDMA_EQE_HWC_SOC_RECONFIG_DATA = 133,
  53. GDMA_EQE_RNIC_QP_FATAL = 176,
  54. };
  55. enum {
  56. GDMA_DEVICE_NONE = 0,
  57. GDMA_DEVICE_HWC = 1,
  58. GDMA_DEVICE_MANA = 2,
  59. GDMA_DEVICE_MANA_IB = 3,
  60. };
  61. struct gdma_resource {
  62. /* Protect the bitmap */
  63. spinlock_t lock;
  64. /* The bitmap size in bits. */
  65. u32 size;
  66. /* The bitmap tracks the resources. */
  67. unsigned long *map;
  68. };
  69. union gdma_doorbell_entry {
  70. u64 as_uint64;
  71. struct {
  72. u64 id : 24;
  73. u64 reserved : 8;
  74. u64 tail_ptr : 31;
  75. u64 arm : 1;
  76. } cq;
  77. struct {
  78. u64 id : 24;
  79. u64 wqe_cnt : 8;
  80. u64 tail_ptr : 32;
  81. } rq;
  82. struct {
  83. u64 id : 24;
  84. u64 reserved : 8;
  85. u64 tail_ptr : 32;
  86. } sq;
  87. struct {
  88. u64 id : 16;
  89. u64 reserved : 16;
  90. u64 tail_ptr : 31;
  91. u64 arm : 1;
  92. } eq;
  93. }; /* HW DATA */
  94. struct gdma_msg_hdr {
  95. u32 hdr_type;
  96. u32 msg_type;
  97. u16 msg_version;
  98. u16 hwc_msg_id;
  99. u32 msg_size;
  100. }; /* HW DATA */
  101. struct gdma_dev_id {
  102. union {
  103. struct {
  104. u16 type;
  105. u16 instance;
  106. };
  107. u32 as_uint32;
  108. };
  109. }; /* HW DATA */
  110. struct gdma_req_hdr {
  111. struct gdma_msg_hdr req;
  112. struct gdma_msg_hdr resp; /* The expected response */
  113. struct gdma_dev_id dev_id;
  114. u32 activity_id;
  115. }; /* HW DATA */
  116. struct gdma_resp_hdr {
  117. struct gdma_msg_hdr response;
  118. struct gdma_dev_id dev_id;
  119. u32 activity_id;
  120. u32 status;
  121. u32 reserved;
  122. }; /* HW DATA */
  123. struct gdma_general_req {
  124. struct gdma_req_hdr hdr;
  125. }; /* HW DATA */
  126. #define GDMA_MESSAGE_V1 1
  127. #define GDMA_MESSAGE_V2 2
  128. #define GDMA_MESSAGE_V3 3
  129. struct gdma_general_resp {
  130. struct gdma_resp_hdr hdr;
  131. }; /* HW DATA */
  132. #define GDMA_STANDARD_HEADER_TYPE 0
  133. static inline void mana_gd_init_req_hdr(struct gdma_req_hdr *hdr, u32 code,
  134. u32 req_size, u32 resp_size)
  135. {
  136. hdr->req.hdr_type = GDMA_STANDARD_HEADER_TYPE;
  137. hdr->req.msg_type = code;
  138. hdr->req.msg_version = GDMA_MESSAGE_V1;
  139. hdr->req.msg_size = req_size;
  140. hdr->resp.hdr_type = GDMA_STANDARD_HEADER_TYPE;
  141. hdr->resp.msg_type = code;
  142. hdr->resp.msg_version = GDMA_MESSAGE_V1;
  143. hdr->resp.msg_size = resp_size;
  144. }
  145. /* The 16-byte struct is part of the GDMA work queue entry (WQE). */
  146. struct gdma_sge {
  147. u64 address;
  148. u32 mem_key;
  149. u32 size;
  150. }; /* HW DATA */
  151. struct gdma_wqe_request {
  152. struct gdma_sge *sgl;
  153. u32 num_sge;
  154. u32 inline_oob_size;
  155. const void *inline_oob_data;
  156. u32 flags;
  157. u32 client_data_unit;
  158. };
  159. enum gdma_page_type {
  160. GDMA_PAGE_TYPE_4K,
  161. };
  162. #define GDMA_INVALID_DMA_REGION 0
  163. struct gdma_mem_info {
  164. struct device *dev;
  165. dma_addr_t dma_handle;
  166. void *virt_addr;
  167. u64 length;
  168. /* Allocated by the PF driver */
  169. u64 dma_region_handle;
  170. };
  171. #define REGISTER_ATB_MST_MKEY_LOWER_SIZE 8
  172. struct gdma_dev {
  173. struct gdma_context *gdma_context;
  174. struct gdma_dev_id dev_id;
  175. u32 pdid;
  176. u32 doorbell;
  177. u32 gpa_mkey;
  178. /* GDMA driver specific pointer */
  179. void *driver_data;
  180. struct auxiliary_device *adev;
  181. };
  182. /* MANA_PAGE_SIZE is the DMA unit */
  183. #define MANA_PAGE_SHIFT 12
  184. #define MANA_PAGE_SIZE BIT(MANA_PAGE_SHIFT)
  185. #define MANA_PAGE_ALIGN(x) ALIGN((x), MANA_PAGE_SIZE)
  186. #define MANA_PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), MANA_PAGE_SIZE)
  187. #define MANA_PFN(a) ((a) >> MANA_PAGE_SHIFT)
  188. /* Required by HW */
  189. #define MANA_MIN_QSIZE MANA_PAGE_SIZE
  190. #define GDMA_CQE_SIZE 64
  191. #define GDMA_EQE_SIZE 16
  192. #define GDMA_MAX_SQE_SIZE 512
  193. #define GDMA_MAX_RQE_SIZE 256
  194. #define GDMA_COMP_DATA_SIZE 0x3C
  195. #define GDMA_EVENT_DATA_SIZE 0xC
  196. /* The WQE size must be a multiple of the Basic Unit, which is 32 bytes. */
  197. #define GDMA_WQE_BU_SIZE 32
  198. #define INVALID_PDID UINT_MAX
  199. #define INVALID_DOORBELL UINT_MAX
  200. #define INVALID_MEM_KEY UINT_MAX
  201. #define INVALID_QUEUE_ID UINT_MAX
  202. #define INVALID_PCI_MSIX_INDEX UINT_MAX
  203. struct gdma_comp {
  204. u32 cqe_data[GDMA_COMP_DATA_SIZE / 4];
  205. u32 wq_num;
  206. bool is_sq;
  207. };
  208. struct gdma_event {
  209. u32 details[GDMA_EVENT_DATA_SIZE / 4];
  210. u8 type;
  211. };
  212. struct gdma_queue;
  213. struct mana_eq {
  214. struct gdma_queue *eq;
  215. };
  216. typedef void gdma_eq_callback(void *context, struct gdma_queue *q,
  217. struct gdma_event *e);
  218. typedef void gdma_cq_callback(void *context, struct gdma_queue *q);
  219. /* The 'head' is the producer index. For SQ/RQ, when the driver posts a WQE
  220. * (Note: the WQE size must be a multiple of the 32-byte Basic Unit), the
  221. * driver increases the 'head' in BUs rather than in bytes, and notifies
  222. * the HW of the updated head. For EQ/CQ, the driver uses the 'head' to track
  223. * the HW head, and increases the 'head' by 1 for every processed EQE/CQE.
  224. *
  225. * The 'tail' is the consumer index for SQ/RQ. After the CQE of the SQ/RQ is
  226. * processed, the driver increases the 'tail' to indicate that WQEs have
  227. * been consumed by the HW, so the driver can post new WQEs into the SQ/RQ.
  228. *
  229. * The driver doesn't use the 'tail' for EQ/CQ, because the driver ensures
  230. * that the EQ/CQ is big enough so they can't overflow, and the driver uses
  231. * the owner bits mechanism to detect if the queue has become empty.
  232. */
  233. struct gdma_queue {
  234. struct gdma_dev *gdma_dev;
  235. enum gdma_queue_type type;
  236. u32 id;
  237. struct gdma_mem_info mem_info;
  238. void *queue_mem_ptr;
  239. u32 queue_size;
  240. bool monitor_avl_buf;
  241. u32 head;
  242. u32 tail;
  243. struct list_head entry;
  244. /* Extra fields specific to EQ/CQ. */
  245. union {
  246. struct {
  247. bool disable_needed;
  248. gdma_eq_callback *callback;
  249. void *context;
  250. unsigned int msix_index;
  251. u32 log2_throttle_limit;
  252. } eq;
  253. struct {
  254. gdma_cq_callback *callback;
  255. void *context;
  256. struct gdma_queue *parent; /* For CQ/EQ relationship */
  257. } cq;
  258. };
  259. };
  260. struct gdma_queue_spec {
  261. enum gdma_queue_type type;
  262. bool monitor_avl_buf;
  263. unsigned int queue_size;
  264. /* Extra fields specific to EQ/CQ. */
  265. union {
  266. struct {
  267. gdma_eq_callback *callback;
  268. void *context;
  269. unsigned long log2_throttle_limit;
  270. unsigned int msix_index;
  271. } eq;
  272. struct {
  273. gdma_cq_callback *callback;
  274. void *context;
  275. struct gdma_queue *parent_eq;
  276. } cq;
  277. };
  278. };
  279. #define MANA_IRQ_NAME_SZ 32
  280. struct gdma_irq_context {
  281. void (*handler)(void *arg);
  282. /* Protect the eq_list */
  283. spinlock_t lock;
  284. struct list_head eq_list;
  285. char name[MANA_IRQ_NAME_SZ];
  286. };
  287. struct gdma_context {
  288. struct device *dev;
  289. /* Per-vPort max number of queues */
  290. unsigned int max_num_queues;
  291. unsigned int max_num_msix;
  292. unsigned int num_msix_usable;
  293. struct gdma_irq_context *irq_contexts;
  294. /* L2 MTU */
  295. u16 adapter_mtu;
  296. /* This maps a CQ index to the queue structure. */
  297. unsigned int max_num_cqs;
  298. struct gdma_queue **cq_table;
  299. /* Protect eq_test_event and test_event_eq_id */
  300. struct mutex eq_test_event_mutex;
  301. struct completion eq_test_event;
  302. u32 test_event_eq_id;
  303. bool is_pf;
  304. phys_addr_t bar0_pa;
  305. void __iomem *bar0_va;
  306. void __iomem *shm_base;
  307. void __iomem *db_page_base;
  308. phys_addr_t phys_db_page_base;
  309. u32 db_page_size;
  310. int numa_node;
  311. /* Shared memory chanenl (used to bootstrap HWC) */
  312. struct shm_channel shm_channel;
  313. /* Hardware communication channel (HWC) */
  314. struct gdma_dev hwc;
  315. /* Azure network adapter */
  316. struct gdma_dev mana;
  317. /* Azure RDMA adapter */
  318. struct gdma_dev mana_ib;
  319. };
  320. static inline bool mana_gd_is_mana(struct gdma_dev *gd)
  321. {
  322. return gd->dev_id.type == GDMA_DEVICE_MANA;
  323. }
  324. static inline bool mana_gd_is_hwc(struct gdma_dev *gd)
  325. {
  326. return gd->dev_id.type == GDMA_DEVICE_HWC;
  327. }
  328. u8 *mana_gd_get_wqe_ptr(const struct gdma_queue *wq, u32 wqe_offset);
  329. u32 mana_gd_wq_avail_space(struct gdma_queue *wq);
  330. int mana_gd_test_eq(struct gdma_context *gc, struct gdma_queue *eq);
  331. int mana_gd_create_hwc_queue(struct gdma_dev *gd,
  332. const struct gdma_queue_spec *spec,
  333. struct gdma_queue **queue_ptr);
  334. int mana_gd_create_mana_eq(struct gdma_dev *gd,
  335. const struct gdma_queue_spec *spec,
  336. struct gdma_queue **queue_ptr);
  337. int mana_gd_create_mana_wq_cq(struct gdma_dev *gd,
  338. const struct gdma_queue_spec *spec,
  339. struct gdma_queue **queue_ptr);
  340. void mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue);
  341. int mana_gd_poll_cq(struct gdma_queue *cq, struct gdma_comp *comp, int num_cqe);
  342. void mana_gd_ring_cq(struct gdma_queue *cq, u8 arm_bit);
  343. struct gdma_wqe {
  344. u32 reserved :24;
  345. u32 last_vbytes :8;
  346. union {
  347. u32 flags;
  348. struct {
  349. u32 num_sge :8;
  350. u32 inline_oob_size_div4:3;
  351. u32 client_oob_in_sgl :1;
  352. u32 reserved1 :4;
  353. u32 client_data_unit :14;
  354. u32 reserved2 :2;
  355. };
  356. };
  357. }; /* HW DATA */
  358. #define INLINE_OOB_SMALL_SIZE 8
  359. #define INLINE_OOB_LARGE_SIZE 24
  360. #define MAX_TX_WQE_SIZE 512
  361. #define MAX_RX_WQE_SIZE 256
  362. #define MAX_TX_WQE_SGL_ENTRIES ((GDMA_MAX_SQE_SIZE - \
  363. sizeof(struct gdma_sge) - INLINE_OOB_SMALL_SIZE) / \
  364. sizeof(struct gdma_sge))
  365. #define MAX_RX_WQE_SGL_ENTRIES ((GDMA_MAX_RQE_SIZE - \
  366. sizeof(struct gdma_sge)) / sizeof(struct gdma_sge))
  367. struct gdma_cqe {
  368. u32 cqe_data[GDMA_COMP_DATA_SIZE / 4];
  369. union {
  370. u32 as_uint32;
  371. struct {
  372. u32 wq_num : 24;
  373. u32 is_sq : 1;
  374. u32 reserved : 4;
  375. u32 owner_bits : 3;
  376. };
  377. } cqe_info;
  378. }; /* HW DATA */
  379. #define GDMA_CQE_OWNER_BITS 3
  380. #define GDMA_CQE_OWNER_MASK ((1 << GDMA_CQE_OWNER_BITS) - 1)
  381. #define SET_ARM_BIT 1
  382. #define GDMA_EQE_OWNER_BITS 3
  383. union gdma_eqe_info {
  384. u32 as_uint32;
  385. struct {
  386. u32 type : 8;
  387. u32 reserved1 : 8;
  388. u32 client_id : 2;
  389. u32 reserved2 : 11;
  390. u32 owner_bits : 3;
  391. };
  392. }; /* HW DATA */
  393. #define GDMA_EQE_OWNER_MASK ((1 << GDMA_EQE_OWNER_BITS) - 1)
  394. #define INITIALIZED_OWNER_BIT(log2_num_entries) (1UL << (log2_num_entries))
  395. struct gdma_eqe {
  396. u32 details[GDMA_EVENT_DATA_SIZE / 4];
  397. u32 eqe_info;
  398. }; /* HW DATA */
  399. #define GDMA_REG_DB_PAGE_OFFSET 8
  400. #define GDMA_REG_DB_PAGE_SIZE 0x10
  401. #define GDMA_REG_SHM_OFFSET 0x18
  402. #define GDMA_PF_REG_DB_PAGE_SIZE 0xD0
  403. #define GDMA_PF_REG_DB_PAGE_OFF 0xC8
  404. #define GDMA_PF_REG_SHM_OFF 0x70
  405. #define GDMA_SRIOV_REG_CFG_BASE_OFF 0x108
  406. #define MANA_PF_DEVICE_ID 0x00B9
  407. #define MANA_VF_DEVICE_ID 0x00BA
  408. struct gdma_posted_wqe_info {
  409. u32 wqe_size_in_bu;
  410. };
  411. /* GDMA_GENERATE_TEST_EQE */
  412. struct gdma_generate_test_event_req {
  413. struct gdma_req_hdr hdr;
  414. u32 queue_index;
  415. }; /* HW DATA */
  416. /* GDMA_VERIFY_VF_DRIVER_VERSION */
  417. enum {
  418. GDMA_PROTOCOL_V1 = 1,
  419. GDMA_PROTOCOL_FIRST = GDMA_PROTOCOL_V1,
  420. GDMA_PROTOCOL_LAST = GDMA_PROTOCOL_V1,
  421. };
  422. #define GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT BIT(0)
  423. /* Advertise to the NIC firmware: the NAPI work_done variable race is fixed,
  424. * so the driver is able to reliably support features like busy_poll.
  425. */
  426. #define GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX BIT(2)
  427. #define GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG BIT(3)
  428. #define GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT BIT(5)
  429. /* Driver can handle holes (zeros) in the device list */
  430. #define GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP BIT(11)
  431. #define GDMA_DRV_CAP_FLAGS1 \
  432. (GDMA_DRV_CAP_FLAG_1_EQ_SHARING_MULTI_VPORT | \
  433. GDMA_DRV_CAP_FLAG_1_NAPI_WKDONE_FIX | \
  434. GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG | \
  435. GDMA_DRV_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT | \
  436. GDMA_DRV_CAP_FLAG_1_DEV_LIST_HOLES_SUP)
  437. #define GDMA_DRV_CAP_FLAGS2 0
  438. #define GDMA_DRV_CAP_FLAGS3 0
  439. #define GDMA_DRV_CAP_FLAGS4 0
  440. struct gdma_verify_ver_req {
  441. struct gdma_req_hdr hdr;
  442. /* Mandatory fields required for protocol establishment */
  443. u64 protocol_ver_min;
  444. u64 protocol_ver_max;
  445. /* Gdma Driver Capability Flags */
  446. u64 gd_drv_cap_flags1;
  447. u64 gd_drv_cap_flags2;
  448. u64 gd_drv_cap_flags3;
  449. u64 gd_drv_cap_flags4;
  450. /* Advisory fields */
  451. u64 drv_ver;
  452. u32 os_type; /* Linux = 0x10; Windows = 0x20; Other = 0x30 */
  453. u32 reserved;
  454. u32 os_ver_major;
  455. u32 os_ver_minor;
  456. u32 os_ver_build;
  457. u32 os_ver_platform;
  458. u64 reserved_2;
  459. u8 os_ver_str1[128];
  460. u8 os_ver_str2[128];
  461. u8 os_ver_str3[128];
  462. u8 os_ver_str4[128];
  463. }; /* HW DATA */
  464. struct gdma_verify_ver_resp {
  465. struct gdma_resp_hdr hdr;
  466. u64 gdma_protocol_ver;
  467. u64 pf_cap_flags1;
  468. u64 pf_cap_flags2;
  469. u64 pf_cap_flags3;
  470. u64 pf_cap_flags4;
  471. }; /* HW DATA */
  472. /* GDMA_QUERY_MAX_RESOURCES */
  473. struct gdma_query_max_resources_resp {
  474. struct gdma_resp_hdr hdr;
  475. u32 status;
  476. u32 max_sq;
  477. u32 max_rq;
  478. u32 max_cq;
  479. u32 max_eq;
  480. u32 max_db;
  481. u32 max_mst;
  482. u32 max_cq_mod_ctx;
  483. u32 max_mod_cq;
  484. u32 max_msix;
  485. }; /* HW DATA */
  486. /* GDMA_LIST_DEVICES */
  487. #define GDMA_DEV_LIST_SIZE 64
  488. struct gdma_list_devices_resp {
  489. struct gdma_resp_hdr hdr;
  490. u32 num_of_devs;
  491. u32 reserved;
  492. struct gdma_dev_id devs[GDMA_DEV_LIST_SIZE];
  493. }; /* HW DATA */
  494. /* GDMA_REGISTER_DEVICE */
  495. struct gdma_register_device_resp {
  496. struct gdma_resp_hdr hdr;
  497. u32 pdid;
  498. u32 gpa_mkey;
  499. u32 db_id;
  500. }; /* HW DATA */
  501. struct gdma_allocate_resource_range_req {
  502. struct gdma_req_hdr hdr;
  503. u32 resource_type;
  504. u32 num_resources;
  505. u32 alignment;
  506. u32 allocated_resources;
  507. };
  508. struct gdma_allocate_resource_range_resp {
  509. struct gdma_resp_hdr hdr;
  510. u32 allocated_resources;
  511. };
  512. struct gdma_destroy_resource_range_req {
  513. struct gdma_req_hdr hdr;
  514. u32 resource_type;
  515. u32 num_resources;
  516. u32 allocated_resources;
  517. };
  518. /* GDMA_CREATE_QUEUE */
  519. struct gdma_create_queue_req {
  520. struct gdma_req_hdr hdr;
  521. u32 type;
  522. u32 reserved1;
  523. u32 pdid;
  524. u32 doolbell_id;
  525. u64 gdma_region;
  526. u32 reserved2;
  527. u32 queue_size;
  528. u32 log2_throttle_limit;
  529. u32 eq_pci_msix_index;
  530. u32 cq_mod_ctx_id;
  531. u32 cq_parent_eq_id;
  532. u8 rq_drop_on_overrun;
  533. u8 rq_err_on_wqe_overflow;
  534. u8 rq_chain_rec_wqes;
  535. u8 sq_hw_db;
  536. u32 reserved3;
  537. }; /* HW DATA */
  538. struct gdma_create_queue_resp {
  539. struct gdma_resp_hdr hdr;
  540. u32 queue_index;
  541. }; /* HW DATA */
  542. /* GDMA_DISABLE_QUEUE */
  543. struct gdma_disable_queue_req {
  544. struct gdma_req_hdr hdr;
  545. u32 type;
  546. u32 queue_index;
  547. u32 alloc_res_id_on_creation;
  548. }; /* HW DATA */
  549. /* GDMA_QUERY_HWC_TIMEOUT */
  550. struct gdma_query_hwc_timeout_req {
  551. struct gdma_req_hdr hdr;
  552. u32 timeout_ms;
  553. u32 reserved;
  554. };
  555. struct gdma_query_hwc_timeout_resp {
  556. struct gdma_resp_hdr hdr;
  557. u32 timeout_ms;
  558. u32 reserved;
  559. };
  560. enum atb_page_size {
  561. ATB_PAGE_SIZE_4K,
  562. ATB_PAGE_SIZE_8K,
  563. ATB_PAGE_SIZE_16K,
  564. ATB_PAGE_SIZE_32K,
  565. ATB_PAGE_SIZE_64K,
  566. ATB_PAGE_SIZE_128K,
  567. ATB_PAGE_SIZE_256K,
  568. ATB_PAGE_SIZE_512K,
  569. ATB_PAGE_SIZE_1M,
  570. ATB_PAGE_SIZE_2M,
  571. ATB_PAGE_SIZE_MAX,
  572. };
  573. enum gdma_mr_access_flags {
  574. GDMA_ACCESS_FLAG_LOCAL_READ = BIT_ULL(0),
  575. GDMA_ACCESS_FLAG_LOCAL_WRITE = BIT_ULL(1),
  576. GDMA_ACCESS_FLAG_REMOTE_READ = BIT_ULL(2),
  577. GDMA_ACCESS_FLAG_REMOTE_WRITE = BIT_ULL(3),
  578. GDMA_ACCESS_FLAG_REMOTE_ATOMIC = BIT_ULL(4),
  579. };
  580. /* GDMA_CREATE_DMA_REGION */
  581. struct gdma_create_dma_region_req {
  582. struct gdma_req_hdr hdr;
  583. /* The total size of the DMA region */
  584. u64 length;
  585. /* The offset in the first page */
  586. u32 offset_in_page;
  587. /* enum gdma_page_type */
  588. u32 gdma_page_type;
  589. /* The total number of pages */
  590. u32 page_count;
  591. /* If page_addr_list_len is smaller than page_count,
  592. * the remaining page addresses will be added via the
  593. * message GDMA_DMA_REGION_ADD_PAGES.
  594. */
  595. u32 page_addr_list_len;
  596. u64 page_addr_list[];
  597. }; /* HW DATA */
  598. struct gdma_create_dma_region_resp {
  599. struct gdma_resp_hdr hdr;
  600. u64 dma_region_handle;
  601. }; /* HW DATA */
  602. /* GDMA_DMA_REGION_ADD_PAGES */
  603. struct gdma_dma_region_add_pages_req {
  604. struct gdma_req_hdr hdr;
  605. u64 dma_region_handle;
  606. u32 page_addr_list_len;
  607. u32 reserved3;
  608. u64 page_addr_list[];
  609. }; /* HW DATA */
  610. /* GDMA_DESTROY_DMA_REGION */
  611. struct gdma_destroy_dma_region_req {
  612. struct gdma_req_hdr hdr;
  613. u64 dma_region_handle;
  614. }; /* HW DATA */
  615. enum gdma_pd_flags {
  616. GDMA_PD_FLAG_INVALID = 0,
  617. };
  618. struct gdma_create_pd_req {
  619. struct gdma_req_hdr hdr;
  620. enum gdma_pd_flags flags;
  621. u32 reserved;
  622. };/* HW DATA */
  623. struct gdma_create_pd_resp {
  624. struct gdma_resp_hdr hdr;
  625. u64 pd_handle;
  626. u32 pd_id;
  627. u32 reserved;
  628. };/* HW DATA */
  629. struct gdma_destroy_pd_req {
  630. struct gdma_req_hdr hdr;
  631. u64 pd_handle;
  632. };/* HW DATA */
  633. struct gdma_destory_pd_resp {
  634. struct gdma_resp_hdr hdr;
  635. };/* HW DATA */
  636. enum gdma_mr_type {
  637. /* Guest Virtual Address - MRs of this type allow access
  638. * to memory mapped by PTEs associated with this MR using a virtual
  639. * address that is set up in the MST
  640. */
  641. GDMA_MR_TYPE_GVA = 2,
  642. };
  643. struct gdma_create_mr_params {
  644. u64 pd_handle;
  645. enum gdma_mr_type mr_type;
  646. union {
  647. struct {
  648. u64 dma_region_handle;
  649. u64 virtual_address;
  650. enum gdma_mr_access_flags access_flags;
  651. } gva;
  652. };
  653. };
  654. struct gdma_create_mr_request {
  655. struct gdma_req_hdr hdr;
  656. u64 pd_handle;
  657. enum gdma_mr_type mr_type;
  658. u32 reserved_1;
  659. union {
  660. struct {
  661. u64 dma_region_handle;
  662. u64 virtual_address;
  663. enum gdma_mr_access_flags access_flags;
  664. } gva;
  665. };
  666. u32 reserved_2;
  667. };/* HW DATA */
  668. struct gdma_create_mr_response {
  669. struct gdma_resp_hdr hdr;
  670. u64 mr_handle;
  671. u32 lkey;
  672. u32 rkey;
  673. };/* HW DATA */
  674. struct gdma_destroy_mr_request {
  675. struct gdma_req_hdr hdr;
  676. u64 mr_handle;
  677. };/* HW DATA */
  678. struct gdma_destroy_mr_response {
  679. struct gdma_resp_hdr hdr;
  680. };/* HW DATA */
  681. int mana_gd_verify_vf_version(struct pci_dev *pdev);
  682. int mana_gd_register_device(struct gdma_dev *gd);
  683. int mana_gd_deregister_device(struct gdma_dev *gd);
  684. int mana_gd_post_work_request(struct gdma_queue *wq,
  685. const struct gdma_wqe_request *wqe_req,
  686. struct gdma_posted_wqe_info *wqe_info);
  687. int mana_gd_post_and_ring(struct gdma_queue *queue,
  688. const struct gdma_wqe_request *wqe,
  689. struct gdma_posted_wqe_info *wqe_info);
  690. int mana_gd_alloc_res_map(u32 res_avail, struct gdma_resource *r);
  691. void mana_gd_free_res_map(struct gdma_resource *r);
  692. void mana_gd_wq_ring_doorbell(struct gdma_context *gc,
  693. struct gdma_queue *queue);
  694. int mana_gd_alloc_memory(struct gdma_context *gc, unsigned int length,
  695. struct gdma_mem_info *gmi);
  696. void mana_gd_free_memory(struct gdma_mem_info *gmi);
  697. int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req,
  698. u32 resp_len, void *resp);
  699. int mana_gd_destroy_dma_region(struct gdma_context *gc, u64 dma_region_handle);
  700. #endif /* _GDMA_H */