pvrdma_verbs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * Copyright (c) 2012-2016 VMware, Inc. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of EITHER the GNU General Public License
  6. * version 2 as published by the Free Software Foundation or the BSD
  7. * 2-Clause License. This program is distributed in the hope that it
  8. * will be useful, but WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED
  9. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License version 2 for more details at
  11. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program available in the file COPYING in the main
  15. * directory of this source tree.
  16. *
  17. * The BSD 2-Clause License
  18. *
  19. * Redistribution and use in source and binary forms, with or
  20. * without modification, are permitted provided that the following
  21. * conditions are met:
  22. *
  23. * - Redistributions of source code must retain the above
  24. * copyright notice, this list of conditions and the following
  25. * disclaimer.
  26. *
  27. * - Redistributions in binary form must reproduce the above
  28. * copyright notice, this list of conditions and the following
  29. * disclaimer in the documentation and/or other materials
  30. * provided with the distribution.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  35. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  36. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  37. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  38. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  39. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  40. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  41. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  43. * OF THE POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. #ifndef __PVRDMA_VERBS_H__
  46. #define __PVRDMA_VERBS_H__
  47. #include <linux/types.h>
  48. union pvrdma_gid {
  49. u8 raw[16];
  50. struct {
  51. __be64 subnet_prefix;
  52. __be64 interface_id;
  53. } global;
  54. };
  55. enum pvrdma_link_layer {
  56. PVRDMA_LINK_LAYER_UNSPECIFIED,
  57. PVRDMA_LINK_LAYER_INFINIBAND,
  58. PVRDMA_LINK_LAYER_ETHERNET,
  59. };
  60. enum pvrdma_mtu {
  61. PVRDMA_MTU_256 = 1,
  62. PVRDMA_MTU_512 = 2,
  63. PVRDMA_MTU_1024 = 3,
  64. PVRDMA_MTU_2048 = 4,
  65. PVRDMA_MTU_4096 = 5,
  66. };
  67. static inline int pvrdma_mtu_enum_to_int(enum pvrdma_mtu mtu)
  68. {
  69. switch (mtu) {
  70. case PVRDMA_MTU_256: return 256;
  71. case PVRDMA_MTU_512: return 512;
  72. case PVRDMA_MTU_1024: return 1024;
  73. case PVRDMA_MTU_2048: return 2048;
  74. case PVRDMA_MTU_4096: return 4096;
  75. default: return -1;
  76. }
  77. }
  78. static inline enum pvrdma_mtu pvrdma_mtu_int_to_enum(int mtu)
  79. {
  80. switch (mtu) {
  81. case 256: return PVRDMA_MTU_256;
  82. case 512: return PVRDMA_MTU_512;
  83. case 1024: return PVRDMA_MTU_1024;
  84. case 2048: return PVRDMA_MTU_2048;
  85. case 4096:
  86. default: return PVRDMA_MTU_4096;
  87. }
  88. }
  89. enum pvrdma_port_state {
  90. PVRDMA_PORT_NOP = 0,
  91. PVRDMA_PORT_DOWN = 1,
  92. PVRDMA_PORT_INIT = 2,
  93. PVRDMA_PORT_ARMED = 3,
  94. PVRDMA_PORT_ACTIVE = 4,
  95. PVRDMA_PORT_ACTIVE_DEFER = 5,
  96. };
  97. enum pvrdma_port_cap_flags {
  98. PVRDMA_PORT_SM = 1 << 1,
  99. PVRDMA_PORT_NOTICE_SUP = 1 << 2,
  100. PVRDMA_PORT_TRAP_SUP = 1 << 3,
  101. PVRDMA_PORT_OPT_IPD_SUP = 1 << 4,
  102. PVRDMA_PORT_AUTO_MIGR_SUP = 1 << 5,
  103. PVRDMA_PORT_SL_MAP_SUP = 1 << 6,
  104. PVRDMA_PORT_MKEY_NVRAM = 1 << 7,
  105. PVRDMA_PORT_PKEY_NVRAM = 1 << 8,
  106. PVRDMA_PORT_LED_INFO_SUP = 1 << 9,
  107. PVRDMA_PORT_SM_DISABLED = 1 << 10,
  108. PVRDMA_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  109. PVRDMA_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  110. PVRDMA_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
  111. PVRDMA_PORT_CM_SUP = 1 << 16,
  112. PVRDMA_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  113. PVRDMA_PORT_REINIT_SUP = 1 << 18,
  114. PVRDMA_PORT_DEVICE_MGMT_SUP = 1 << 19,
  115. PVRDMA_PORT_VENDOR_CLASS_SUP = 1 << 20,
  116. PVRDMA_PORT_DR_NOTICE_SUP = 1 << 21,
  117. PVRDMA_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  118. PVRDMA_PORT_BOOT_MGMT_SUP = 1 << 23,
  119. PVRDMA_PORT_LINK_LATENCY_SUP = 1 << 24,
  120. PVRDMA_PORT_CLIENT_REG_SUP = 1 << 25,
  121. PVRDMA_PORT_IP_BASED_GIDS = 1 << 26,
  122. PVRDMA_PORT_CAP_FLAGS_MAX = PVRDMA_PORT_IP_BASED_GIDS,
  123. };
  124. enum pvrdma_port_width {
  125. PVRDMA_WIDTH_1X = 1,
  126. PVRDMA_WIDTH_4X = 2,
  127. PVRDMA_WIDTH_8X = 4,
  128. PVRDMA_WIDTH_12X = 8,
  129. };
  130. static inline int pvrdma_width_enum_to_int(enum pvrdma_port_width width)
  131. {
  132. switch (width) {
  133. case PVRDMA_WIDTH_1X: return 1;
  134. case PVRDMA_WIDTH_4X: return 4;
  135. case PVRDMA_WIDTH_8X: return 8;
  136. case PVRDMA_WIDTH_12X: return 12;
  137. default: return -1;
  138. }
  139. }
  140. enum pvrdma_port_speed {
  141. PVRDMA_SPEED_SDR = 1,
  142. PVRDMA_SPEED_DDR = 2,
  143. PVRDMA_SPEED_QDR = 4,
  144. PVRDMA_SPEED_FDR10 = 8,
  145. PVRDMA_SPEED_FDR = 16,
  146. PVRDMA_SPEED_EDR = 32,
  147. };
  148. struct pvrdma_port_attr {
  149. enum pvrdma_port_state state;
  150. enum pvrdma_mtu max_mtu;
  151. enum pvrdma_mtu active_mtu;
  152. u32 gid_tbl_len;
  153. u32 port_cap_flags;
  154. u32 max_msg_sz;
  155. u32 bad_pkey_cntr;
  156. u32 qkey_viol_cntr;
  157. u16 pkey_tbl_len;
  158. u16 lid;
  159. u16 sm_lid;
  160. u8 lmc;
  161. u8 max_vl_num;
  162. u8 sm_sl;
  163. u8 subnet_timeout;
  164. u8 init_type_reply;
  165. u8 active_width;
  166. u8 active_speed;
  167. u8 phys_state;
  168. u8 reserved[2];
  169. };
  170. struct pvrdma_global_route {
  171. union pvrdma_gid dgid;
  172. u32 flow_label;
  173. u8 sgid_index;
  174. u8 hop_limit;
  175. u8 traffic_class;
  176. u8 reserved;
  177. };
  178. struct pvrdma_grh {
  179. __be32 version_tclass_flow;
  180. __be16 paylen;
  181. u8 next_hdr;
  182. u8 hop_limit;
  183. union pvrdma_gid sgid;
  184. union pvrdma_gid dgid;
  185. };
  186. enum pvrdma_ah_flags {
  187. PVRDMA_AH_GRH = 1,
  188. };
  189. enum pvrdma_rate {
  190. PVRDMA_RATE_PORT_CURRENT = 0,
  191. PVRDMA_RATE_2_5_GBPS = 2,
  192. PVRDMA_RATE_5_GBPS = 5,
  193. PVRDMA_RATE_10_GBPS = 3,
  194. PVRDMA_RATE_20_GBPS = 6,
  195. PVRDMA_RATE_30_GBPS = 4,
  196. PVRDMA_RATE_40_GBPS = 7,
  197. PVRDMA_RATE_60_GBPS = 8,
  198. PVRDMA_RATE_80_GBPS = 9,
  199. PVRDMA_RATE_120_GBPS = 10,
  200. PVRDMA_RATE_14_GBPS = 11,
  201. PVRDMA_RATE_56_GBPS = 12,
  202. PVRDMA_RATE_112_GBPS = 13,
  203. PVRDMA_RATE_168_GBPS = 14,
  204. PVRDMA_RATE_25_GBPS = 15,
  205. PVRDMA_RATE_100_GBPS = 16,
  206. PVRDMA_RATE_200_GBPS = 17,
  207. PVRDMA_RATE_300_GBPS = 18,
  208. };
  209. struct pvrdma_ah_attr {
  210. struct pvrdma_global_route grh;
  211. u16 dlid;
  212. u16 vlan_id;
  213. u8 sl;
  214. u8 src_path_bits;
  215. u8 static_rate;
  216. u8 ah_flags;
  217. u8 port_num;
  218. u8 dmac[6];
  219. u8 reserved;
  220. };
  221. enum pvrdma_cq_notify_flags {
  222. PVRDMA_CQ_SOLICITED = 1 << 0,
  223. PVRDMA_CQ_NEXT_COMP = 1 << 1,
  224. PVRDMA_CQ_SOLICITED_MASK = PVRDMA_CQ_SOLICITED |
  225. PVRDMA_CQ_NEXT_COMP,
  226. PVRDMA_CQ_REPORT_MISSED_EVENTS = 1 << 2,
  227. };
  228. struct pvrdma_qp_cap {
  229. u32 max_send_wr;
  230. u32 max_recv_wr;
  231. u32 max_send_sge;
  232. u32 max_recv_sge;
  233. u32 max_inline_data;
  234. u32 reserved;
  235. };
  236. enum pvrdma_sig_type {
  237. PVRDMA_SIGNAL_ALL_WR,
  238. PVRDMA_SIGNAL_REQ_WR,
  239. };
  240. enum pvrdma_qp_type {
  241. PVRDMA_QPT_SMI,
  242. PVRDMA_QPT_GSI,
  243. PVRDMA_QPT_RC,
  244. PVRDMA_QPT_UC,
  245. PVRDMA_QPT_UD,
  246. PVRDMA_QPT_RAW_IPV6,
  247. PVRDMA_QPT_RAW_ETHERTYPE,
  248. PVRDMA_QPT_RAW_PACKET = 8,
  249. PVRDMA_QPT_XRC_INI = 9,
  250. PVRDMA_QPT_XRC_TGT,
  251. PVRDMA_QPT_MAX,
  252. };
  253. enum pvrdma_qp_create_flags {
  254. PVRDMA_QP_CREATE_IPOPVRDMA_UD_LSO = 1 << 0,
  255. PVRDMA_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
  256. };
  257. enum pvrdma_qp_attr_mask {
  258. PVRDMA_QP_STATE = 1 << 0,
  259. PVRDMA_QP_CUR_STATE = 1 << 1,
  260. PVRDMA_QP_EN_SQD_ASYNC_NOTIFY = 1 << 2,
  261. PVRDMA_QP_ACCESS_FLAGS = 1 << 3,
  262. PVRDMA_QP_PKEY_INDEX = 1 << 4,
  263. PVRDMA_QP_PORT = 1 << 5,
  264. PVRDMA_QP_QKEY = 1 << 6,
  265. PVRDMA_QP_AV = 1 << 7,
  266. PVRDMA_QP_PATH_MTU = 1 << 8,
  267. PVRDMA_QP_TIMEOUT = 1 << 9,
  268. PVRDMA_QP_RETRY_CNT = 1 << 10,
  269. PVRDMA_QP_RNR_RETRY = 1 << 11,
  270. PVRDMA_QP_RQ_PSN = 1 << 12,
  271. PVRDMA_QP_MAX_QP_RD_ATOMIC = 1 << 13,
  272. PVRDMA_QP_ALT_PATH = 1 << 14,
  273. PVRDMA_QP_MIN_RNR_TIMER = 1 << 15,
  274. PVRDMA_QP_SQ_PSN = 1 << 16,
  275. PVRDMA_QP_MAX_DEST_RD_ATOMIC = 1 << 17,
  276. PVRDMA_QP_PATH_MIG_STATE = 1 << 18,
  277. PVRDMA_QP_CAP = 1 << 19,
  278. PVRDMA_QP_DEST_QPN = 1 << 20,
  279. PVRDMA_QP_ATTR_MASK_MAX = PVRDMA_QP_DEST_QPN,
  280. };
  281. enum pvrdma_qp_state {
  282. PVRDMA_QPS_RESET,
  283. PVRDMA_QPS_INIT,
  284. PVRDMA_QPS_RTR,
  285. PVRDMA_QPS_RTS,
  286. PVRDMA_QPS_SQD,
  287. PVRDMA_QPS_SQE,
  288. PVRDMA_QPS_ERR,
  289. };
  290. enum pvrdma_mig_state {
  291. PVRDMA_MIG_MIGRATED,
  292. PVRDMA_MIG_REARM,
  293. PVRDMA_MIG_ARMED,
  294. };
  295. enum pvrdma_mw_type {
  296. PVRDMA_MW_TYPE_1 = 1,
  297. PVRDMA_MW_TYPE_2 = 2,
  298. };
  299. struct pvrdma_srq_attr {
  300. u32 max_wr;
  301. u32 max_sge;
  302. u32 srq_limit;
  303. u32 reserved;
  304. };
  305. struct pvrdma_qp_attr {
  306. enum pvrdma_qp_state qp_state;
  307. enum pvrdma_qp_state cur_qp_state;
  308. enum pvrdma_mtu path_mtu;
  309. enum pvrdma_mig_state path_mig_state;
  310. u32 qkey;
  311. u32 rq_psn;
  312. u32 sq_psn;
  313. u32 dest_qp_num;
  314. u32 qp_access_flags;
  315. u16 pkey_index;
  316. u16 alt_pkey_index;
  317. u8 en_sqd_async_notify;
  318. u8 sq_draining;
  319. u8 max_rd_atomic;
  320. u8 max_dest_rd_atomic;
  321. u8 min_rnr_timer;
  322. u8 port_num;
  323. u8 timeout;
  324. u8 retry_cnt;
  325. u8 rnr_retry;
  326. u8 alt_port_num;
  327. u8 alt_timeout;
  328. u8 reserved[5];
  329. struct pvrdma_qp_cap cap;
  330. struct pvrdma_ah_attr ah_attr;
  331. struct pvrdma_ah_attr alt_ah_attr;
  332. };
  333. enum pvrdma_send_flags {
  334. PVRDMA_SEND_FENCE = 1 << 0,
  335. PVRDMA_SEND_SIGNALED = 1 << 1,
  336. PVRDMA_SEND_SOLICITED = 1 << 2,
  337. PVRDMA_SEND_INLINE = 1 << 3,
  338. PVRDMA_SEND_IP_CSUM = 1 << 4,
  339. PVRDMA_SEND_FLAGS_MAX = PVRDMA_SEND_IP_CSUM,
  340. };
  341. enum pvrdma_access_flags {
  342. PVRDMA_ACCESS_LOCAL_WRITE = 1 << 0,
  343. PVRDMA_ACCESS_REMOTE_WRITE = 1 << 1,
  344. PVRDMA_ACCESS_REMOTE_READ = 1 << 2,
  345. PVRDMA_ACCESS_REMOTE_ATOMIC = 1 << 3,
  346. PVRDMA_ACCESS_MW_BIND = 1 << 4,
  347. PVRDMA_ZERO_BASED = 1 << 5,
  348. PVRDMA_ACCESS_ON_DEMAND = 1 << 6,
  349. PVRDMA_ACCESS_FLAGS_MAX = PVRDMA_ACCESS_ON_DEMAND,
  350. };
  351. int pvrdma_query_device(struct ib_device *ibdev,
  352. struct ib_device_attr *props,
  353. struct ib_udata *udata);
  354. int pvrdma_query_port(struct ib_device *ibdev, u8 port,
  355. struct ib_port_attr *props);
  356. int pvrdma_query_gid(struct ib_device *ibdev, u8 port,
  357. int index, union ib_gid *gid);
  358. int pvrdma_query_pkey(struct ib_device *ibdev, u8 port,
  359. u16 index, u16 *pkey);
  360. enum rdma_link_layer pvrdma_port_link_layer(struct ib_device *ibdev,
  361. u8 port);
  362. int pvrdma_modify_device(struct ib_device *ibdev, int mask,
  363. struct ib_device_modify *props);
  364. int pvrdma_modify_port(struct ib_device *ibdev, u8 port,
  365. int mask, struct ib_port_modify *props);
  366. int pvrdma_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
  367. struct ib_ucontext *pvrdma_alloc_ucontext(struct ib_device *ibdev,
  368. struct ib_udata *udata);
  369. int pvrdma_dealloc_ucontext(struct ib_ucontext *context);
  370. struct ib_pd *pvrdma_alloc_pd(struct ib_device *ibdev,
  371. struct ib_ucontext *context,
  372. struct ib_udata *udata);
  373. int pvrdma_dealloc_pd(struct ib_pd *ibpd);
  374. struct ib_mr *pvrdma_get_dma_mr(struct ib_pd *pd, int acc);
  375. struct ib_mr *pvrdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
  376. u64 virt_addr, int access_flags,
  377. struct ib_udata *udata);
  378. int pvrdma_dereg_mr(struct ib_mr *mr);
  379. struct ib_mr *pvrdma_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
  380. u32 max_num_sg);
  381. int pvrdma_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg,
  382. int sg_nents, unsigned int *sg_offset);
  383. struct ib_cq *pvrdma_create_cq(struct ib_device *ibdev,
  384. const struct ib_cq_init_attr *attr,
  385. struct ib_ucontext *context,
  386. struct ib_udata *udata);
  387. int pvrdma_destroy_cq(struct ib_cq *cq);
  388. int pvrdma_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  389. int pvrdma_req_notify_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
  390. struct ib_ah *pvrdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
  391. struct ib_udata *udata);
  392. int pvrdma_destroy_ah(struct ib_ah *ah);
  393. struct ib_srq *pvrdma_create_srq(struct ib_pd *pd,
  394. struct ib_srq_init_attr *init_attr,
  395. struct ib_udata *udata);
  396. int pvrdma_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  397. enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
  398. int pvrdma_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
  399. int pvrdma_destroy_srq(struct ib_srq *srq);
  400. struct ib_qp *pvrdma_create_qp(struct ib_pd *pd,
  401. struct ib_qp_init_attr *init_attr,
  402. struct ib_udata *udata);
  403. int pvrdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  404. int attr_mask, struct ib_udata *udata);
  405. int pvrdma_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
  406. int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
  407. int pvrdma_destroy_qp(struct ib_qp *qp);
  408. int pvrdma_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
  409. const struct ib_send_wr **bad_wr);
  410. int pvrdma_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
  411. const struct ib_recv_wr **bad_wr);
  412. #endif /* __PVRDMA_VERBS_H__ */