gdma.h 22 KB

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