ib_verbs.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. /*
  2. * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
  4. * Copyright (c) 2004 Intel Corporation. All rights reserved.
  5. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  6. * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
  7. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  8. * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
  9. *
  10. * This software is available to you under a choice of one of two
  11. * licenses. You may choose to be licensed under the terms of the GNU
  12. * General Public License (GPL) Version 2, available from the file
  13. * COPYING in the main directory of this source tree, or the
  14. * OpenIB.org BSD license below:
  15. *
  16. * Redistribution and use in source and binary forms, with or
  17. * without modification, are permitted provided that the following
  18. * conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer.
  23. *
  24. * - Redistributions in binary form must reproduce the above
  25. * copyright notice, this list of conditions and the following
  26. * disclaimer in the documentation and/or other materials
  27. * provided with the distribution.
  28. *
  29. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  33. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  34. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  36. * SOFTWARE.
  37. *
  38. * $Id: ib_verbs.h 1349 2004-12-16 21:09:43Z roland $
  39. */
  40. #if !defined(IB_VERBS_H)
  41. #define IB_VERBS_H
  42. #include <linux/types.h>
  43. #include <linux/device.h>
  44. #include <asm/atomic.h>
  45. #include <asm/scatterlist.h>
  46. #include <asm/uaccess.h>
  47. union ib_gid {
  48. u8 raw[16];
  49. struct {
  50. __be64 subnet_prefix;
  51. __be64 interface_id;
  52. } global;
  53. };
  54. enum ib_node_type {
  55. IB_NODE_CA = 1,
  56. IB_NODE_SWITCH,
  57. IB_NODE_ROUTER
  58. };
  59. enum ib_device_cap_flags {
  60. IB_DEVICE_RESIZE_MAX_WR = 1,
  61. IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
  62. IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
  63. IB_DEVICE_RAW_MULTI = (1<<3),
  64. IB_DEVICE_AUTO_PATH_MIG = (1<<4),
  65. IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
  66. IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
  67. IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
  68. IB_DEVICE_SHUTDOWN_PORT = (1<<8),
  69. IB_DEVICE_INIT_TYPE = (1<<9),
  70. IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
  71. IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
  72. IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
  73. IB_DEVICE_SRQ_RESIZE = (1<<13),
  74. IB_DEVICE_N_NOTIFY_CQ = (1<<14),
  75. };
  76. enum ib_atomic_cap {
  77. IB_ATOMIC_NONE,
  78. IB_ATOMIC_HCA,
  79. IB_ATOMIC_GLOB
  80. };
  81. struct ib_device_attr {
  82. u64 fw_ver;
  83. __be64 sys_image_guid;
  84. u64 max_mr_size;
  85. u64 page_size_cap;
  86. u32 vendor_id;
  87. u32 vendor_part_id;
  88. u32 hw_ver;
  89. int max_qp;
  90. int max_qp_wr;
  91. int device_cap_flags;
  92. int max_sge;
  93. int max_sge_rd;
  94. int max_cq;
  95. int max_cqe;
  96. int max_mr;
  97. int max_pd;
  98. int max_qp_rd_atom;
  99. int max_ee_rd_atom;
  100. int max_res_rd_atom;
  101. int max_qp_init_rd_atom;
  102. int max_ee_init_rd_atom;
  103. enum ib_atomic_cap atomic_cap;
  104. int max_ee;
  105. int max_rdd;
  106. int max_mw;
  107. int max_raw_ipv6_qp;
  108. int max_raw_ethy_qp;
  109. int max_mcast_grp;
  110. int max_mcast_qp_attach;
  111. int max_total_mcast_qp_attach;
  112. int max_ah;
  113. int max_fmr;
  114. int max_map_per_fmr;
  115. int max_srq;
  116. int max_srq_wr;
  117. int max_srq_sge;
  118. u16 max_pkeys;
  119. u8 local_ca_ack_delay;
  120. };
  121. enum ib_mtu {
  122. IB_MTU_256 = 1,
  123. IB_MTU_512 = 2,
  124. IB_MTU_1024 = 3,
  125. IB_MTU_2048 = 4,
  126. IB_MTU_4096 = 5
  127. };
  128. static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
  129. {
  130. switch (mtu) {
  131. case IB_MTU_256: return 256;
  132. case IB_MTU_512: return 512;
  133. case IB_MTU_1024: return 1024;
  134. case IB_MTU_2048: return 2048;
  135. case IB_MTU_4096: return 4096;
  136. default: return -1;
  137. }
  138. }
  139. enum ib_port_state {
  140. IB_PORT_NOP = 0,
  141. IB_PORT_DOWN = 1,
  142. IB_PORT_INIT = 2,
  143. IB_PORT_ARMED = 3,
  144. IB_PORT_ACTIVE = 4,
  145. IB_PORT_ACTIVE_DEFER = 5
  146. };
  147. enum ib_port_cap_flags {
  148. IB_PORT_SM = 1 << 1,
  149. IB_PORT_NOTICE_SUP = 1 << 2,
  150. IB_PORT_TRAP_SUP = 1 << 3,
  151. IB_PORT_OPT_IPD_SUP = 1 << 4,
  152. IB_PORT_AUTO_MIGR_SUP = 1 << 5,
  153. IB_PORT_SL_MAP_SUP = 1 << 6,
  154. IB_PORT_MKEY_NVRAM = 1 << 7,
  155. IB_PORT_PKEY_NVRAM = 1 << 8,
  156. IB_PORT_LED_INFO_SUP = 1 << 9,
  157. IB_PORT_SM_DISABLED = 1 << 10,
  158. IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  159. IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  160. IB_PORT_CM_SUP = 1 << 16,
  161. IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  162. IB_PORT_REINIT_SUP = 1 << 18,
  163. IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
  164. IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
  165. IB_PORT_DR_NOTICE_SUP = 1 << 21,
  166. IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  167. IB_PORT_BOOT_MGMT_SUP = 1 << 23,
  168. IB_PORT_LINK_LATENCY_SUP = 1 << 24,
  169. IB_PORT_CLIENT_REG_SUP = 1 << 25
  170. };
  171. enum ib_port_width {
  172. IB_WIDTH_1X = 1,
  173. IB_WIDTH_4X = 2,
  174. IB_WIDTH_8X = 4,
  175. IB_WIDTH_12X = 8
  176. };
  177. static inline int ib_width_enum_to_int(enum ib_port_width width)
  178. {
  179. switch (width) {
  180. case IB_WIDTH_1X: return 1;
  181. case IB_WIDTH_4X: return 4;
  182. case IB_WIDTH_8X: return 8;
  183. case IB_WIDTH_12X: return 12;
  184. default: return -1;
  185. }
  186. }
  187. struct ib_port_attr {
  188. enum ib_port_state state;
  189. enum ib_mtu max_mtu;
  190. enum ib_mtu active_mtu;
  191. int gid_tbl_len;
  192. u32 port_cap_flags;
  193. u32 max_msg_sz;
  194. u32 bad_pkey_cntr;
  195. u32 qkey_viol_cntr;
  196. u16 pkey_tbl_len;
  197. u16 lid;
  198. u16 sm_lid;
  199. u8 lmc;
  200. u8 max_vl_num;
  201. u8 sm_sl;
  202. u8 subnet_timeout;
  203. u8 init_type_reply;
  204. u8 active_width;
  205. u8 active_speed;
  206. u8 phys_state;
  207. };
  208. enum ib_device_modify_flags {
  209. IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
  210. IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
  211. };
  212. struct ib_device_modify {
  213. u64 sys_image_guid;
  214. char node_desc[64];
  215. };
  216. enum ib_port_modify_flags {
  217. IB_PORT_SHUTDOWN = 1,
  218. IB_PORT_INIT_TYPE = (1<<2),
  219. IB_PORT_RESET_QKEY_CNTR = (1<<3)
  220. };
  221. struct ib_port_modify {
  222. u32 set_port_cap_mask;
  223. u32 clr_port_cap_mask;
  224. u8 init_type;
  225. };
  226. enum ib_event_type {
  227. IB_EVENT_CQ_ERR,
  228. IB_EVENT_QP_FATAL,
  229. IB_EVENT_QP_REQ_ERR,
  230. IB_EVENT_QP_ACCESS_ERR,
  231. IB_EVENT_COMM_EST,
  232. IB_EVENT_SQ_DRAINED,
  233. IB_EVENT_PATH_MIG,
  234. IB_EVENT_PATH_MIG_ERR,
  235. IB_EVENT_DEVICE_FATAL,
  236. IB_EVENT_PORT_ACTIVE,
  237. IB_EVENT_PORT_ERR,
  238. IB_EVENT_LID_CHANGE,
  239. IB_EVENT_PKEY_CHANGE,
  240. IB_EVENT_SM_CHANGE,
  241. IB_EVENT_SRQ_ERR,
  242. IB_EVENT_SRQ_LIMIT_REACHED,
  243. IB_EVENT_QP_LAST_WQE_REACHED
  244. };
  245. struct ib_event {
  246. struct ib_device *device;
  247. union {
  248. struct ib_cq *cq;
  249. struct ib_qp *qp;
  250. struct ib_srq *srq;
  251. u8 port_num;
  252. } element;
  253. enum ib_event_type event;
  254. };
  255. struct ib_event_handler {
  256. struct ib_device *device;
  257. void (*handler)(struct ib_event_handler *, struct ib_event *);
  258. struct list_head list;
  259. };
  260. #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
  261. do { \
  262. (_ptr)->device = _device; \
  263. (_ptr)->handler = _handler; \
  264. INIT_LIST_HEAD(&(_ptr)->list); \
  265. } while (0)
  266. struct ib_global_route {
  267. union ib_gid dgid;
  268. u32 flow_label;
  269. u8 sgid_index;
  270. u8 hop_limit;
  271. u8 traffic_class;
  272. };
  273. struct ib_grh {
  274. __be32 version_tclass_flow;
  275. __be16 paylen;
  276. u8 next_hdr;
  277. u8 hop_limit;
  278. union ib_gid sgid;
  279. union ib_gid dgid;
  280. };
  281. enum {
  282. IB_MULTICAST_QPN = 0xffffff
  283. };
  284. #define IB_LID_PERMISSIVE __constant_htons(0xFFFF)
  285. enum ib_ah_flags {
  286. IB_AH_GRH = 1
  287. };
  288. struct ib_ah_attr {
  289. struct ib_global_route grh;
  290. u16 dlid;
  291. u8 sl;
  292. u8 src_path_bits;
  293. u8 static_rate;
  294. u8 ah_flags;
  295. u8 port_num;
  296. };
  297. enum ib_wc_status {
  298. IB_WC_SUCCESS,
  299. IB_WC_LOC_LEN_ERR,
  300. IB_WC_LOC_QP_OP_ERR,
  301. IB_WC_LOC_EEC_OP_ERR,
  302. IB_WC_LOC_PROT_ERR,
  303. IB_WC_WR_FLUSH_ERR,
  304. IB_WC_MW_BIND_ERR,
  305. IB_WC_BAD_RESP_ERR,
  306. IB_WC_LOC_ACCESS_ERR,
  307. IB_WC_REM_INV_REQ_ERR,
  308. IB_WC_REM_ACCESS_ERR,
  309. IB_WC_REM_OP_ERR,
  310. IB_WC_RETRY_EXC_ERR,
  311. IB_WC_RNR_RETRY_EXC_ERR,
  312. IB_WC_LOC_RDD_VIOL_ERR,
  313. IB_WC_REM_INV_RD_REQ_ERR,
  314. IB_WC_REM_ABORT_ERR,
  315. IB_WC_INV_EECN_ERR,
  316. IB_WC_INV_EEC_STATE_ERR,
  317. IB_WC_FATAL_ERR,
  318. IB_WC_RESP_TIMEOUT_ERR,
  319. IB_WC_GENERAL_ERR
  320. };
  321. enum ib_wc_opcode {
  322. IB_WC_SEND,
  323. IB_WC_RDMA_WRITE,
  324. IB_WC_RDMA_READ,
  325. IB_WC_COMP_SWAP,
  326. IB_WC_FETCH_ADD,
  327. IB_WC_BIND_MW,
  328. /*
  329. * Set value of IB_WC_RECV so consumers can test if a completion is a
  330. * receive by testing (opcode & IB_WC_RECV).
  331. */
  332. IB_WC_RECV = 1 << 7,
  333. IB_WC_RECV_RDMA_WITH_IMM
  334. };
  335. enum ib_wc_flags {
  336. IB_WC_GRH = 1,
  337. IB_WC_WITH_IMM = (1<<1)
  338. };
  339. struct ib_wc {
  340. u64 wr_id;
  341. enum ib_wc_status status;
  342. enum ib_wc_opcode opcode;
  343. u32 vendor_err;
  344. u32 byte_len;
  345. __be32 imm_data;
  346. u32 qp_num;
  347. u32 src_qp;
  348. int wc_flags;
  349. u16 pkey_index;
  350. u16 slid;
  351. u8 sl;
  352. u8 dlid_path_bits;
  353. u8 port_num; /* valid only for DR SMPs on switches */
  354. };
  355. enum ib_cq_notify {
  356. IB_CQ_SOLICITED,
  357. IB_CQ_NEXT_COMP
  358. };
  359. enum ib_srq_attr_mask {
  360. IB_SRQ_MAX_WR = 1 << 0,
  361. IB_SRQ_LIMIT = 1 << 1,
  362. };
  363. struct ib_srq_attr {
  364. u32 max_wr;
  365. u32 max_sge;
  366. u32 srq_limit;
  367. };
  368. struct ib_srq_init_attr {
  369. void (*event_handler)(struct ib_event *, void *);
  370. void *srq_context;
  371. struct ib_srq_attr attr;
  372. };
  373. struct ib_qp_cap {
  374. u32 max_send_wr;
  375. u32 max_recv_wr;
  376. u32 max_send_sge;
  377. u32 max_recv_sge;
  378. u32 max_inline_data;
  379. };
  380. enum ib_sig_type {
  381. IB_SIGNAL_ALL_WR,
  382. IB_SIGNAL_REQ_WR
  383. };
  384. enum ib_qp_type {
  385. /*
  386. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  387. * here (and in that order) since the MAD layer uses them as
  388. * indices into a 2-entry table.
  389. */
  390. IB_QPT_SMI,
  391. IB_QPT_GSI,
  392. IB_QPT_RC,
  393. IB_QPT_UC,
  394. IB_QPT_UD,
  395. IB_QPT_RAW_IPV6,
  396. IB_QPT_RAW_ETY
  397. };
  398. struct ib_qp_init_attr {
  399. void (*event_handler)(struct ib_event *, void *);
  400. void *qp_context;
  401. struct ib_cq *send_cq;
  402. struct ib_cq *recv_cq;
  403. struct ib_srq *srq;
  404. struct ib_qp_cap cap;
  405. enum ib_sig_type sq_sig_type;
  406. enum ib_qp_type qp_type;
  407. u8 port_num; /* special QP types only */
  408. };
  409. enum ib_rnr_timeout {
  410. IB_RNR_TIMER_655_36 = 0,
  411. IB_RNR_TIMER_000_01 = 1,
  412. IB_RNR_TIMER_000_02 = 2,
  413. IB_RNR_TIMER_000_03 = 3,
  414. IB_RNR_TIMER_000_04 = 4,
  415. IB_RNR_TIMER_000_06 = 5,
  416. IB_RNR_TIMER_000_08 = 6,
  417. IB_RNR_TIMER_000_12 = 7,
  418. IB_RNR_TIMER_000_16 = 8,
  419. IB_RNR_TIMER_000_24 = 9,
  420. IB_RNR_TIMER_000_32 = 10,
  421. IB_RNR_TIMER_000_48 = 11,
  422. IB_RNR_TIMER_000_64 = 12,
  423. IB_RNR_TIMER_000_96 = 13,
  424. IB_RNR_TIMER_001_28 = 14,
  425. IB_RNR_TIMER_001_92 = 15,
  426. IB_RNR_TIMER_002_56 = 16,
  427. IB_RNR_TIMER_003_84 = 17,
  428. IB_RNR_TIMER_005_12 = 18,
  429. IB_RNR_TIMER_007_68 = 19,
  430. IB_RNR_TIMER_010_24 = 20,
  431. IB_RNR_TIMER_015_36 = 21,
  432. IB_RNR_TIMER_020_48 = 22,
  433. IB_RNR_TIMER_030_72 = 23,
  434. IB_RNR_TIMER_040_96 = 24,
  435. IB_RNR_TIMER_061_44 = 25,
  436. IB_RNR_TIMER_081_92 = 26,
  437. IB_RNR_TIMER_122_88 = 27,
  438. IB_RNR_TIMER_163_84 = 28,
  439. IB_RNR_TIMER_245_76 = 29,
  440. IB_RNR_TIMER_327_68 = 30,
  441. IB_RNR_TIMER_491_52 = 31
  442. };
  443. enum ib_qp_attr_mask {
  444. IB_QP_STATE = 1,
  445. IB_QP_CUR_STATE = (1<<1),
  446. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  447. IB_QP_ACCESS_FLAGS = (1<<3),
  448. IB_QP_PKEY_INDEX = (1<<4),
  449. IB_QP_PORT = (1<<5),
  450. IB_QP_QKEY = (1<<6),
  451. IB_QP_AV = (1<<7),
  452. IB_QP_PATH_MTU = (1<<8),
  453. IB_QP_TIMEOUT = (1<<9),
  454. IB_QP_RETRY_CNT = (1<<10),
  455. IB_QP_RNR_RETRY = (1<<11),
  456. IB_QP_RQ_PSN = (1<<12),
  457. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  458. IB_QP_ALT_PATH = (1<<14),
  459. IB_QP_MIN_RNR_TIMER = (1<<15),
  460. IB_QP_SQ_PSN = (1<<16),
  461. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  462. IB_QP_PATH_MIG_STATE = (1<<18),
  463. IB_QP_CAP = (1<<19),
  464. IB_QP_DEST_QPN = (1<<20)
  465. };
  466. enum ib_qp_state {
  467. IB_QPS_RESET,
  468. IB_QPS_INIT,
  469. IB_QPS_RTR,
  470. IB_QPS_RTS,
  471. IB_QPS_SQD,
  472. IB_QPS_SQE,
  473. IB_QPS_ERR
  474. };
  475. enum ib_mig_state {
  476. IB_MIG_MIGRATED,
  477. IB_MIG_REARM,
  478. IB_MIG_ARMED
  479. };
  480. struct ib_qp_attr {
  481. enum ib_qp_state qp_state;
  482. enum ib_qp_state cur_qp_state;
  483. enum ib_mtu path_mtu;
  484. enum ib_mig_state path_mig_state;
  485. u32 qkey;
  486. u32 rq_psn;
  487. u32 sq_psn;
  488. u32 dest_qp_num;
  489. int qp_access_flags;
  490. struct ib_qp_cap cap;
  491. struct ib_ah_attr ah_attr;
  492. struct ib_ah_attr alt_ah_attr;
  493. u16 pkey_index;
  494. u16 alt_pkey_index;
  495. u8 en_sqd_async_notify;
  496. u8 sq_draining;
  497. u8 max_rd_atomic;
  498. u8 max_dest_rd_atomic;
  499. u8 min_rnr_timer;
  500. u8 port_num;
  501. u8 timeout;
  502. u8 retry_cnt;
  503. u8 rnr_retry;
  504. u8 alt_port_num;
  505. u8 alt_timeout;
  506. };
  507. enum ib_wr_opcode {
  508. IB_WR_RDMA_WRITE,
  509. IB_WR_RDMA_WRITE_WITH_IMM,
  510. IB_WR_SEND,
  511. IB_WR_SEND_WITH_IMM,
  512. IB_WR_RDMA_READ,
  513. IB_WR_ATOMIC_CMP_AND_SWP,
  514. IB_WR_ATOMIC_FETCH_AND_ADD
  515. };
  516. enum ib_send_flags {
  517. IB_SEND_FENCE = 1,
  518. IB_SEND_SIGNALED = (1<<1),
  519. IB_SEND_SOLICITED = (1<<2),
  520. IB_SEND_INLINE = (1<<3)
  521. };
  522. struct ib_sge {
  523. u64 addr;
  524. u32 length;
  525. u32 lkey;
  526. };
  527. struct ib_send_wr {
  528. struct ib_send_wr *next;
  529. u64 wr_id;
  530. struct ib_sge *sg_list;
  531. int num_sge;
  532. enum ib_wr_opcode opcode;
  533. int send_flags;
  534. __be32 imm_data;
  535. union {
  536. struct {
  537. u64 remote_addr;
  538. u32 rkey;
  539. } rdma;
  540. struct {
  541. u64 remote_addr;
  542. u64 compare_add;
  543. u64 swap;
  544. u32 rkey;
  545. } atomic;
  546. struct {
  547. struct ib_ah *ah;
  548. u32 remote_qpn;
  549. u32 remote_qkey;
  550. u16 pkey_index; /* valid for GSI only */
  551. u8 port_num; /* valid for DR SMPs on switch only */
  552. } ud;
  553. } wr;
  554. };
  555. struct ib_recv_wr {
  556. struct ib_recv_wr *next;
  557. u64 wr_id;
  558. struct ib_sge *sg_list;
  559. int num_sge;
  560. };
  561. enum ib_access_flags {
  562. IB_ACCESS_LOCAL_WRITE = 1,
  563. IB_ACCESS_REMOTE_WRITE = (1<<1),
  564. IB_ACCESS_REMOTE_READ = (1<<2),
  565. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  566. IB_ACCESS_MW_BIND = (1<<4)
  567. };
  568. struct ib_phys_buf {
  569. u64 addr;
  570. u64 size;
  571. };
  572. struct ib_mr_attr {
  573. struct ib_pd *pd;
  574. u64 device_virt_addr;
  575. u64 size;
  576. int mr_access_flags;
  577. u32 lkey;
  578. u32 rkey;
  579. };
  580. enum ib_mr_rereg_flags {
  581. IB_MR_REREG_TRANS = 1,
  582. IB_MR_REREG_PD = (1<<1),
  583. IB_MR_REREG_ACCESS = (1<<2)
  584. };
  585. struct ib_mw_bind {
  586. struct ib_mr *mr;
  587. u64 wr_id;
  588. u64 addr;
  589. u32 length;
  590. int send_flags;
  591. int mw_access_flags;
  592. };
  593. struct ib_fmr_attr {
  594. int max_pages;
  595. int max_maps;
  596. u8 page_shift;
  597. };
  598. struct ib_ucontext {
  599. struct ib_device *device;
  600. struct list_head pd_list;
  601. struct list_head mr_list;
  602. struct list_head mw_list;
  603. struct list_head cq_list;
  604. struct list_head qp_list;
  605. struct list_head srq_list;
  606. struct list_head ah_list;
  607. };
  608. struct ib_uobject {
  609. u64 user_handle; /* handle given to us by userspace */
  610. struct ib_ucontext *context; /* associated user context */
  611. struct list_head list; /* link to context's list */
  612. u32 id; /* index into kernel idr */
  613. };
  614. struct ib_umem {
  615. unsigned long user_base;
  616. unsigned long virt_base;
  617. size_t length;
  618. int offset;
  619. int page_size;
  620. int writable;
  621. struct list_head chunk_list;
  622. };
  623. struct ib_umem_chunk {
  624. struct list_head list;
  625. int nents;
  626. int nmap;
  627. struct scatterlist page_list[0];
  628. };
  629. struct ib_udata {
  630. void __user *inbuf;
  631. void __user *outbuf;
  632. size_t inlen;
  633. size_t outlen;
  634. };
  635. #define IB_UMEM_MAX_PAGE_CHUNK \
  636. ((PAGE_SIZE - offsetof(struct ib_umem_chunk, page_list)) / \
  637. ((void *) &((struct ib_umem_chunk *) 0)->page_list[1] - \
  638. (void *) &((struct ib_umem_chunk *) 0)->page_list[0]))
  639. struct ib_umem_object {
  640. struct ib_uobject uobject;
  641. struct ib_umem umem;
  642. };
  643. struct ib_pd {
  644. struct ib_device *device;
  645. struct ib_uobject *uobject;
  646. atomic_t usecnt; /* count all resources */
  647. };
  648. struct ib_ah {
  649. struct ib_device *device;
  650. struct ib_pd *pd;
  651. struct ib_uobject *uobject;
  652. };
  653. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  654. struct ib_cq {
  655. struct ib_device *device;
  656. struct ib_uobject *uobject;
  657. ib_comp_handler comp_handler;
  658. void (*event_handler)(struct ib_event *, void *);
  659. void * cq_context;
  660. int cqe;
  661. atomic_t usecnt; /* count number of work queues */
  662. };
  663. struct ib_srq {
  664. struct ib_device *device;
  665. struct ib_pd *pd;
  666. struct ib_uobject *uobject;
  667. void (*event_handler)(struct ib_event *, void *);
  668. void *srq_context;
  669. atomic_t usecnt;
  670. };
  671. struct ib_qp {
  672. struct ib_device *device;
  673. struct ib_pd *pd;
  674. struct ib_cq *send_cq;
  675. struct ib_cq *recv_cq;
  676. struct ib_srq *srq;
  677. struct ib_uobject *uobject;
  678. void (*event_handler)(struct ib_event *, void *);
  679. void *qp_context;
  680. u32 qp_num;
  681. enum ib_qp_type qp_type;
  682. };
  683. struct ib_mr {
  684. struct ib_device *device;
  685. struct ib_pd *pd;
  686. struct ib_uobject *uobject;
  687. u32 lkey;
  688. u32 rkey;
  689. atomic_t usecnt; /* count number of MWs */
  690. };
  691. struct ib_mw {
  692. struct ib_device *device;
  693. struct ib_pd *pd;
  694. struct ib_uobject *uobject;
  695. u32 rkey;
  696. };
  697. struct ib_fmr {
  698. struct ib_device *device;
  699. struct ib_pd *pd;
  700. struct list_head list;
  701. u32 lkey;
  702. u32 rkey;
  703. };
  704. struct ib_mad;
  705. struct ib_grh;
  706. enum ib_process_mad_flags {
  707. IB_MAD_IGNORE_MKEY = 1,
  708. IB_MAD_IGNORE_BKEY = 2,
  709. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  710. };
  711. enum ib_mad_result {
  712. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  713. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  714. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  715. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  716. };
  717. #define IB_DEVICE_NAME_MAX 64
  718. struct ib_cache {
  719. rwlock_t lock;
  720. struct ib_event_handler event_handler;
  721. struct ib_pkey_cache **pkey_cache;
  722. struct ib_gid_cache **gid_cache;
  723. };
  724. struct ib_device {
  725. struct device *dma_device;
  726. char name[IB_DEVICE_NAME_MAX];
  727. struct list_head event_handler_list;
  728. spinlock_t event_handler_lock;
  729. struct list_head core_list;
  730. struct list_head client_data_list;
  731. spinlock_t client_data_lock;
  732. struct ib_cache cache;
  733. u32 flags;
  734. int (*query_device)(struct ib_device *device,
  735. struct ib_device_attr *device_attr);
  736. int (*query_port)(struct ib_device *device,
  737. u8 port_num,
  738. struct ib_port_attr *port_attr);
  739. int (*query_gid)(struct ib_device *device,
  740. u8 port_num, int index,
  741. union ib_gid *gid);
  742. int (*query_pkey)(struct ib_device *device,
  743. u8 port_num, u16 index, u16 *pkey);
  744. int (*modify_device)(struct ib_device *device,
  745. int device_modify_mask,
  746. struct ib_device_modify *device_modify);
  747. int (*modify_port)(struct ib_device *device,
  748. u8 port_num, int port_modify_mask,
  749. struct ib_port_modify *port_modify);
  750. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  751. struct ib_udata *udata);
  752. int (*dealloc_ucontext)(struct ib_ucontext *context);
  753. int (*mmap)(struct ib_ucontext *context,
  754. struct vm_area_struct *vma);
  755. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  756. struct ib_ucontext *context,
  757. struct ib_udata *udata);
  758. int (*dealloc_pd)(struct ib_pd *pd);
  759. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  760. struct ib_ah_attr *ah_attr);
  761. int (*modify_ah)(struct ib_ah *ah,
  762. struct ib_ah_attr *ah_attr);
  763. int (*query_ah)(struct ib_ah *ah,
  764. struct ib_ah_attr *ah_attr);
  765. int (*destroy_ah)(struct ib_ah *ah);
  766. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  767. struct ib_srq_init_attr *srq_init_attr,
  768. struct ib_udata *udata);
  769. int (*modify_srq)(struct ib_srq *srq,
  770. struct ib_srq_attr *srq_attr,
  771. enum ib_srq_attr_mask srq_attr_mask);
  772. int (*query_srq)(struct ib_srq *srq,
  773. struct ib_srq_attr *srq_attr);
  774. int (*destroy_srq)(struct ib_srq *srq);
  775. int (*post_srq_recv)(struct ib_srq *srq,
  776. struct ib_recv_wr *recv_wr,
  777. struct ib_recv_wr **bad_recv_wr);
  778. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  779. struct ib_qp_init_attr *qp_init_attr,
  780. struct ib_udata *udata);
  781. int (*modify_qp)(struct ib_qp *qp,
  782. struct ib_qp_attr *qp_attr,
  783. int qp_attr_mask);
  784. int (*query_qp)(struct ib_qp *qp,
  785. struct ib_qp_attr *qp_attr,
  786. int qp_attr_mask,
  787. struct ib_qp_init_attr *qp_init_attr);
  788. int (*destroy_qp)(struct ib_qp *qp);
  789. int (*post_send)(struct ib_qp *qp,
  790. struct ib_send_wr *send_wr,
  791. struct ib_send_wr **bad_send_wr);
  792. int (*post_recv)(struct ib_qp *qp,
  793. struct ib_recv_wr *recv_wr,
  794. struct ib_recv_wr **bad_recv_wr);
  795. struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
  796. struct ib_ucontext *context,
  797. struct ib_udata *udata);
  798. int (*destroy_cq)(struct ib_cq *cq);
  799. int (*resize_cq)(struct ib_cq *cq, int cqe,
  800. struct ib_udata *udata);
  801. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  802. struct ib_wc *wc);
  803. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  804. int (*req_notify_cq)(struct ib_cq *cq,
  805. enum ib_cq_notify cq_notify);
  806. int (*req_ncomp_notif)(struct ib_cq *cq,
  807. int wc_cnt);
  808. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  809. int mr_access_flags);
  810. struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
  811. struct ib_phys_buf *phys_buf_array,
  812. int num_phys_buf,
  813. int mr_access_flags,
  814. u64 *iova_start);
  815. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  816. struct ib_umem *region,
  817. int mr_access_flags,
  818. struct ib_udata *udata);
  819. int (*query_mr)(struct ib_mr *mr,
  820. struct ib_mr_attr *mr_attr);
  821. int (*dereg_mr)(struct ib_mr *mr);
  822. int (*rereg_phys_mr)(struct ib_mr *mr,
  823. int mr_rereg_mask,
  824. struct ib_pd *pd,
  825. struct ib_phys_buf *phys_buf_array,
  826. int num_phys_buf,
  827. int mr_access_flags,
  828. u64 *iova_start);
  829. struct ib_mw * (*alloc_mw)(struct ib_pd *pd);
  830. int (*bind_mw)(struct ib_qp *qp,
  831. struct ib_mw *mw,
  832. struct ib_mw_bind *mw_bind);
  833. int (*dealloc_mw)(struct ib_mw *mw);
  834. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  835. int mr_access_flags,
  836. struct ib_fmr_attr *fmr_attr);
  837. int (*map_phys_fmr)(struct ib_fmr *fmr,
  838. u64 *page_list, int list_len,
  839. u64 iova);
  840. int (*unmap_fmr)(struct list_head *fmr_list);
  841. int (*dealloc_fmr)(struct ib_fmr *fmr);
  842. int (*attach_mcast)(struct ib_qp *qp,
  843. union ib_gid *gid,
  844. u16 lid);
  845. int (*detach_mcast)(struct ib_qp *qp,
  846. union ib_gid *gid,
  847. u16 lid);
  848. int (*process_mad)(struct ib_device *device,
  849. int process_mad_flags,
  850. u8 port_num,
  851. struct ib_wc *in_wc,
  852. struct ib_grh *in_grh,
  853. struct ib_mad *in_mad,
  854. struct ib_mad *out_mad);
  855. struct module *owner;
  856. struct class_device class_dev;
  857. struct kobject ports_parent;
  858. struct list_head port_list;
  859. enum {
  860. IB_DEV_UNINITIALIZED,
  861. IB_DEV_REGISTERED,
  862. IB_DEV_UNREGISTERED
  863. } reg_state;
  864. u64 uverbs_cmd_mask;
  865. int uverbs_abi_ver;
  866. char node_desc[64];
  867. __be64 node_guid;
  868. u8 node_type;
  869. u8 phys_port_cnt;
  870. };
  871. struct ib_client {
  872. char *name;
  873. void (*add) (struct ib_device *);
  874. void (*remove)(struct ib_device *);
  875. struct list_head list;
  876. };
  877. struct ib_device *ib_alloc_device(size_t size);
  878. void ib_dealloc_device(struct ib_device *device);
  879. int ib_register_device (struct ib_device *device);
  880. void ib_unregister_device(struct ib_device *device);
  881. int ib_register_client (struct ib_client *client);
  882. void ib_unregister_client(struct ib_client *client);
  883. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  884. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  885. void *data);
  886. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  887. {
  888. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  889. }
  890. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  891. {
  892. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  893. }
  894. /**
  895. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  896. * contains all required attributes and no attributes not allowed for
  897. * the given QP state transition.
  898. * @cur_state: Current QP state
  899. * @next_state: Next QP state
  900. * @type: QP type
  901. * @mask: Mask of supplied QP attributes
  902. *
  903. * This function is a helper function that a low-level driver's
  904. * modify_qp method can use to validate the consumer's input. It
  905. * checks that cur_state and next_state are valid QP states, that a
  906. * transition from cur_state to next_state is allowed by the IB spec,
  907. * and that the attribute mask supplied is allowed for the transition.
  908. */
  909. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  910. enum ib_qp_type type, enum ib_qp_attr_mask mask);
  911. int ib_register_event_handler (struct ib_event_handler *event_handler);
  912. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  913. void ib_dispatch_event(struct ib_event *event);
  914. int ib_query_device(struct ib_device *device,
  915. struct ib_device_attr *device_attr);
  916. int ib_query_port(struct ib_device *device,
  917. u8 port_num, struct ib_port_attr *port_attr);
  918. int ib_query_gid(struct ib_device *device,
  919. u8 port_num, int index, union ib_gid *gid);
  920. int ib_query_pkey(struct ib_device *device,
  921. u8 port_num, u16 index, u16 *pkey);
  922. int ib_modify_device(struct ib_device *device,
  923. int device_modify_mask,
  924. struct ib_device_modify *device_modify);
  925. int ib_modify_port(struct ib_device *device,
  926. u8 port_num, int port_modify_mask,
  927. struct ib_port_modify *port_modify);
  928. /**
  929. * ib_alloc_pd - Allocates an unused protection domain.
  930. * @device: The device on which to allocate the protection domain.
  931. *
  932. * A protection domain object provides an association between QPs, shared
  933. * receive queues, address handles, memory regions, and memory windows.
  934. */
  935. struct ib_pd *ib_alloc_pd(struct ib_device *device);
  936. /**
  937. * ib_dealloc_pd - Deallocates a protection domain.
  938. * @pd: The protection domain to deallocate.
  939. */
  940. int ib_dealloc_pd(struct ib_pd *pd);
  941. /**
  942. * ib_create_ah - Creates an address handle for the given address vector.
  943. * @pd: The protection domain associated with the address handle.
  944. * @ah_attr: The attributes of the address vector.
  945. *
  946. * The address handle is used to reference a local or global destination
  947. * in all UD QP post sends.
  948. */
  949. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  950. /**
  951. * ib_create_ah_from_wc - Creates an address handle associated with the
  952. * sender of the specified work completion.
  953. * @pd: The protection domain associated with the address handle.
  954. * @wc: Work completion information associated with a received message.
  955. * @grh: References the received global route header. This parameter is
  956. * ignored unless the work completion indicates that the GRH is valid.
  957. * @port_num: The outbound port number to associate with the address.
  958. *
  959. * The address handle is used to reference a local or global destination
  960. * in all UD QP post sends.
  961. */
  962. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
  963. struct ib_grh *grh, u8 port_num);
  964. /**
  965. * ib_modify_ah - Modifies the address vector associated with an address
  966. * handle.
  967. * @ah: The address handle to modify.
  968. * @ah_attr: The new address vector attributes to associate with the
  969. * address handle.
  970. */
  971. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  972. /**
  973. * ib_query_ah - Queries the address vector associated with an address
  974. * handle.
  975. * @ah: The address handle to query.
  976. * @ah_attr: The address vector attributes associated with the address
  977. * handle.
  978. */
  979. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  980. /**
  981. * ib_destroy_ah - Destroys an address handle.
  982. * @ah: The address handle to destroy.
  983. */
  984. int ib_destroy_ah(struct ib_ah *ah);
  985. /**
  986. * ib_create_srq - Creates a SRQ associated with the specified protection
  987. * domain.
  988. * @pd: The protection domain associated with the SRQ.
  989. * @srq_init_attr: A list of initial attributes required to create the
  990. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  991. * the actual capabilities of the created SRQ.
  992. *
  993. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  994. * requested size of the SRQ, and set to the actual values allocated
  995. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  996. * will always be at least as large as the requested values.
  997. */
  998. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  999. struct ib_srq_init_attr *srq_init_attr);
  1000. /**
  1001. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  1002. * @srq: The SRQ to modify.
  1003. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  1004. * the current values of selected SRQ attributes are returned.
  1005. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  1006. * are being modified.
  1007. *
  1008. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  1009. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  1010. * the number of receives queued drops below the limit.
  1011. */
  1012. int ib_modify_srq(struct ib_srq *srq,
  1013. struct ib_srq_attr *srq_attr,
  1014. enum ib_srq_attr_mask srq_attr_mask);
  1015. /**
  1016. * ib_query_srq - Returns the attribute list and current values for the
  1017. * specified SRQ.
  1018. * @srq: The SRQ to query.
  1019. * @srq_attr: The attributes of the specified SRQ.
  1020. */
  1021. int ib_query_srq(struct ib_srq *srq,
  1022. struct ib_srq_attr *srq_attr);
  1023. /**
  1024. * ib_destroy_srq - Destroys the specified SRQ.
  1025. * @srq: The SRQ to destroy.
  1026. */
  1027. int ib_destroy_srq(struct ib_srq *srq);
  1028. /**
  1029. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  1030. * @srq: The SRQ to post the work request on.
  1031. * @recv_wr: A list of work requests to post on the receive queue.
  1032. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1033. * the work request that failed to be posted on the QP.
  1034. */
  1035. static inline int ib_post_srq_recv(struct ib_srq *srq,
  1036. struct ib_recv_wr *recv_wr,
  1037. struct ib_recv_wr **bad_recv_wr)
  1038. {
  1039. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  1040. }
  1041. /**
  1042. * ib_create_qp - Creates a QP associated with the specified protection
  1043. * domain.
  1044. * @pd: The protection domain associated with the QP.
  1045. * @qp_init_attr: A list of initial attributes required to create the
  1046. * QP. If QP creation succeeds, then the attributes are updated to
  1047. * the actual capabilities of the created QP.
  1048. */
  1049. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  1050. struct ib_qp_init_attr *qp_init_attr);
  1051. /**
  1052. * ib_modify_qp - Modifies the attributes for the specified QP and then
  1053. * transitions the QP to the given state.
  1054. * @qp: The QP to modify.
  1055. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  1056. * the current values of selected QP attributes are returned.
  1057. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  1058. * are being modified.
  1059. */
  1060. int ib_modify_qp(struct ib_qp *qp,
  1061. struct ib_qp_attr *qp_attr,
  1062. int qp_attr_mask);
  1063. /**
  1064. * ib_query_qp - Returns the attribute list and current values for the
  1065. * specified QP.
  1066. * @qp: The QP to query.
  1067. * @qp_attr: The attributes of the specified QP.
  1068. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  1069. * @qp_init_attr: Additional attributes of the selected QP.
  1070. *
  1071. * The qp_attr_mask may be used to limit the query to gathering only the
  1072. * selected attributes.
  1073. */
  1074. int ib_query_qp(struct ib_qp *qp,
  1075. struct ib_qp_attr *qp_attr,
  1076. int qp_attr_mask,
  1077. struct ib_qp_init_attr *qp_init_attr);
  1078. /**
  1079. * ib_destroy_qp - Destroys the specified QP.
  1080. * @qp: The QP to destroy.
  1081. */
  1082. int ib_destroy_qp(struct ib_qp *qp);
  1083. /**
  1084. * ib_post_send - Posts a list of work requests to the send queue of
  1085. * the specified QP.
  1086. * @qp: The QP to post the work request on.
  1087. * @send_wr: A list of work requests to post on the send queue.
  1088. * @bad_send_wr: On an immediate failure, this parameter will reference
  1089. * the work request that failed to be posted on the QP.
  1090. */
  1091. static inline int ib_post_send(struct ib_qp *qp,
  1092. struct ib_send_wr *send_wr,
  1093. struct ib_send_wr **bad_send_wr)
  1094. {
  1095. return qp->device->post_send(qp, send_wr, bad_send_wr);
  1096. }
  1097. /**
  1098. * ib_post_recv - Posts a list of work requests to the receive queue of
  1099. * the specified QP.
  1100. * @qp: The QP to post the work request on.
  1101. * @recv_wr: A list of work requests to post on the receive queue.
  1102. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1103. * the work request that failed to be posted on the QP.
  1104. */
  1105. static inline int ib_post_recv(struct ib_qp *qp,
  1106. struct ib_recv_wr *recv_wr,
  1107. struct ib_recv_wr **bad_recv_wr)
  1108. {
  1109. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  1110. }
  1111. /**
  1112. * ib_create_cq - Creates a CQ on the specified device.
  1113. * @device: The device on which to create the CQ.
  1114. * @comp_handler: A user-specified callback that is invoked when a
  1115. * completion event occurs on the CQ.
  1116. * @event_handler: A user-specified callback that is invoked when an
  1117. * asynchronous event not associated with a completion occurs on the CQ.
  1118. * @cq_context: Context associated with the CQ returned to the user via
  1119. * the associated completion and event handlers.
  1120. * @cqe: The minimum size of the CQ.
  1121. *
  1122. * Users can examine the cq structure to determine the actual CQ size.
  1123. */
  1124. struct ib_cq *ib_create_cq(struct ib_device *device,
  1125. ib_comp_handler comp_handler,
  1126. void (*event_handler)(struct ib_event *, void *),
  1127. void *cq_context, int cqe);
  1128. /**
  1129. * ib_resize_cq - Modifies the capacity of the CQ.
  1130. * @cq: The CQ to resize.
  1131. * @cqe: The minimum size of the CQ.
  1132. *
  1133. * Users can examine the cq structure to determine the actual CQ size.
  1134. */
  1135. int ib_resize_cq(struct ib_cq *cq, int cqe);
  1136. /**
  1137. * ib_destroy_cq - Destroys the specified CQ.
  1138. * @cq: The CQ to destroy.
  1139. */
  1140. int ib_destroy_cq(struct ib_cq *cq);
  1141. /**
  1142. * ib_poll_cq - poll a CQ for completion(s)
  1143. * @cq:the CQ being polled
  1144. * @num_entries:maximum number of completions to return
  1145. * @wc:array of at least @num_entries &struct ib_wc where completions
  1146. * will be returned
  1147. *
  1148. * Poll a CQ for (possibly multiple) completions. If the return value
  1149. * is < 0, an error occurred. If the return value is >= 0, it is the
  1150. * number of completions returned. If the return value is
  1151. * non-negative and < num_entries, then the CQ was emptied.
  1152. */
  1153. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  1154. struct ib_wc *wc)
  1155. {
  1156. return cq->device->poll_cq(cq, num_entries, wc);
  1157. }
  1158. /**
  1159. * ib_peek_cq - Returns the number of unreaped completions currently
  1160. * on the specified CQ.
  1161. * @cq: The CQ to peek.
  1162. * @wc_cnt: A minimum number of unreaped completions to check for.
  1163. *
  1164. * If the number of unreaped completions is greater than or equal to wc_cnt,
  1165. * this function returns wc_cnt, otherwise, it returns the actual number of
  1166. * unreaped completions.
  1167. */
  1168. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  1169. /**
  1170. * ib_req_notify_cq - Request completion notification on a CQ.
  1171. * @cq: The CQ to generate an event for.
  1172. * @cq_notify: If set to %IB_CQ_SOLICITED, completion notification will
  1173. * occur on the next solicited event. If set to %IB_CQ_NEXT_COMP,
  1174. * notification will occur on the next completion.
  1175. */
  1176. static inline int ib_req_notify_cq(struct ib_cq *cq,
  1177. enum ib_cq_notify cq_notify)
  1178. {
  1179. return cq->device->req_notify_cq(cq, cq_notify);
  1180. }
  1181. /**
  1182. * ib_req_ncomp_notif - Request completion notification when there are
  1183. * at least the specified number of unreaped completions on the CQ.
  1184. * @cq: The CQ to generate an event for.
  1185. * @wc_cnt: The number of unreaped completions that should be on the
  1186. * CQ before an event is generated.
  1187. */
  1188. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  1189. {
  1190. return cq->device->req_ncomp_notif ?
  1191. cq->device->req_ncomp_notif(cq, wc_cnt) :
  1192. -ENOSYS;
  1193. }
  1194. /**
  1195. * ib_get_dma_mr - Returns a memory region for system memory that is
  1196. * usable for DMA.
  1197. * @pd: The protection domain associated with the memory region.
  1198. * @mr_access_flags: Specifies the memory access rights.
  1199. */
  1200. struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
  1201. /**
  1202. * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
  1203. * by an HCA.
  1204. * @pd: The protection domain associated assigned to the registered region.
  1205. * @phys_buf_array: Specifies a list of physical buffers to use in the
  1206. * memory region.
  1207. * @num_phys_buf: Specifies the size of the phys_buf_array.
  1208. * @mr_access_flags: Specifies the memory access rights.
  1209. * @iova_start: The offset of the region's starting I/O virtual address.
  1210. */
  1211. struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
  1212. struct ib_phys_buf *phys_buf_array,
  1213. int num_phys_buf,
  1214. int mr_access_flags,
  1215. u64 *iova_start);
  1216. /**
  1217. * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
  1218. * Conceptually, this call performs the functions deregister memory region
  1219. * followed by register physical memory region. Where possible,
  1220. * resources are reused instead of deallocated and reallocated.
  1221. * @mr: The memory region to modify.
  1222. * @mr_rereg_mask: A bit-mask used to indicate which of the following
  1223. * properties of the memory region are being modified.
  1224. * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
  1225. * the new protection domain to associated with the memory region,
  1226. * otherwise, this parameter is ignored.
  1227. * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1228. * field specifies a list of physical buffers to use in the new
  1229. * translation, otherwise, this parameter is ignored.
  1230. * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1231. * field specifies the size of the phys_buf_array, otherwise, this
  1232. * parameter is ignored.
  1233. * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
  1234. * field specifies the new memory access rights, otherwise, this
  1235. * parameter is ignored.
  1236. * @iova_start: The offset of the region's starting I/O virtual address.
  1237. */
  1238. int ib_rereg_phys_mr(struct ib_mr *mr,
  1239. int mr_rereg_mask,
  1240. struct ib_pd *pd,
  1241. struct ib_phys_buf *phys_buf_array,
  1242. int num_phys_buf,
  1243. int mr_access_flags,
  1244. u64 *iova_start);
  1245. /**
  1246. * ib_query_mr - Retrieves information about a specific memory region.
  1247. * @mr: The memory region to retrieve information about.
  1248. * @mr_attr: The attributes of the specified memory region.
  1249. */
  1250. int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
  1251. /**
  1252. * ib_dereg_mr - Deregisters a memory region and removes it from the
  1253. * HCA translation table.
  1254. * @mr: The memory region to deregister.
  1255. */
  1256. int ib_dereg_mr(struct ib_mr *mr);
  1257. /**
  1258. * ib_alloc_mw - Allocates a memory window.
  1259. * @pd: The protection domain associated with the memory window.
  1260. */
  1261. struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
  1262. /**
  1263. * ib_bind_mw - Posts a work request to the send queue of the specified
  1264. * QP, which binds the memory window to the given address range and
  1265. * remote access attributes.
  1266. * @qp: QP to post the bind work request on.
  1267. * @mw: The memory window to bind.
  1268. * @mw_bind: Specifies information about the memory window, including
  1269. * its address range, remote access rights, and associated memory region.
  1270. */
  1271. static inline int ib_bind_mw(struct ib_qp *qp,
  1272. struct ib_mw *mw,
  1273. struct ib_mw_bind *mw_bind)
  1274. {
  1275. /* XXX reference counting in corresponding MR? */
  1276. return mw->device->bind_mw ?
  1277. mw->device->bind_mw(qp, mw, mw_bind) :
  1278. -ENOSYS;
  1279. }
  1280. /**
  1281. * ib_dealloc_mw - Deallocates a memory window.
  1282. * @mw: The memory window to deallocate.
  1283. */
  1284. int ib_dealloc_mw(struct ib_mw *mw);
  1285. /**
  1286. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  1287. * @pd: The protection domain associated with the unmapped region.
  1288. * @mr_access_flags: Specifies the memory access rights.
  1289. * @fmr_attr: Attributes of the unmapped region.
  1290. *
  1291. * A fast memory region must be mapped before it can be used as part of
  1292. * a work request.
  1293. */
  1294. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  1295. int mr_access_flags,
  1296. struct ib_fmr_attr *fmr_attr);
  1297. /**
  1298. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  1299. * @fmr: The fast memory region to associate with the pages.
  1300. * @page_list: An array of physical pages to map to the fast memory region.
  1301. * @list_len: The number of pages in page_list.
  1302. * @iova: The I/O virtual address to use with the mapped region.
  1303. */
  1304. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  1305. u64 *page_list, int list_len,
  1306. u64 iova)
  1307. {
  1308. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  1309. }
  1310. /**
  1311. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  1312. * @fmr_list: A linked list of fast memory regions to unmap.
  1313. */
  1314. int ib_unmap_fmr(struct list_head *fmr_list);
  1315. /**
  1316. * ib_dealloc_fmr - Deallocates a fast memory region.
  1317. * @fmr: The fast memory region to deallocate.
  1318. */
  1319. int ib_dealloc_fmr(struct ib_fmr *fmr);
  1320. /**
  1321. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  1322. * @qp: QP to attach to the multicast group. The QP must be type
  1323. * IB_QPT_UD.
  1324. * @gid: Multicast group GID.
  1325. * @lid: Multicast group LID in host byte order.
  1326. *
  1327. * In order to send and receive multicast packets, subnet
  1328. * administration must have created the multicast group and configured
  1329. * the fabric appropriately. The port associated with the specified
  1330. * QP must also be a member of the multicast group.
  1331. */
  1332. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1333. /**
  1334. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  1335. * @qp: QP to detach from the multicast group.
  1336. * @gid: Multicast group GID.
  1337. * @lid: Multicast group LID in host byte order.
  1338. */
  1339. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1340. #endif /* IB_VERBS_H */