ib_verbs.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  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. IB_EVENT_CLIENT_REREGISTER
  245. };
  246. struct ib_event {
  247. struct ib_device *device;
  248. union {
  249. struct ib_cq *cq;
  250. struct ib_qp *qp;
  251. struct ib_srq *srq;
  252. u8 port_num;
  253. } element;
  254. enum ib_event_type event;
  255. };
  256. struct ib_event_handler {
  257. struct ib_device *device;
  258. void (*handler)(struct ib_event_handler *, struct ib_event *);
  259. struct list_head list;
  260. };
  261. #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
  262. do { \
  263. (_ptr)->device = _device; \
  264. (_ptr)->handler = _handler; \
  265. INIT_LIST_HEAD(&(_ptr)->list); \
  266. } while (0)
  267. struct ib_global_route {
  268. union ib_gid dgid;
  269. u32 flow_label;
  270. u8 sgid_index;
  271. u8 hop_limit;
  272. u8 traffic_class;
  273. };
  274. struct ib_grh {
  275. __be32 version_tclass_flow;
  276. __be16 paylen;
  277. u8 next_hdr;
  278. u8 hop_limit;
  279. union ib_gid sgid;
  280. union ib_gid dgid;
  281. };
  282. enum {
  283. IB_MULTICAST_QPN = 0xffffff
  284. };
  285. #define IB_LID_PERMISSIVE __constant_htons(0xFFFF)
  286. enum ib_ah_flags {
  287. IB_AH_GRH = 1
  288. };
  289. enum ib_rate {
  290. IB_RATE_PORT_CURRENT = 0,
  291. IB_RATE_2_5_GBPS = 2,
  292. IB_RATE_5_GBPS = 5,
  293. IB_RATE_10_GBPS = 3,
  294. IB_RATE_20_GBPS = 6,
  295. IB_RATE_30_GBPS = 4,
  296. IB_RATE_40_GBPS = 7,
  297. IB_RATE_60_GBPS = 8,
  298. IB_RATE_80_GBPS = 9,
  299. IB_RATE_120_GBPS = 10
  300. };
  301. /**
  302. * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
  303. * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
  304. * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
  305. * @rate: rate to convert.
  306. */
  307. int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
  308. /**
  309. * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
  310. * enum.
  311. * @mult: multiple to convert.
  312. */
  313. enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
  314. struct ib_ah_attr {
  315. struct ib_global_route grh;
  316. u16 dlid;
  317. u8 sl;
  318. u8 src_path_bits;
  319. u8 static_rate;
  320. u8 ah_flags;
  321. u8 port_num;
  322. };
  323. enum ib_wc_status {
  324. IB_WC_SUCCESS,
  325. IB_WC_LOC_LEN_ERR,
  326. IB_WC_LOC_QP_OP_ERR,
  327. IB_WC_LOC_EEC_OP_ERR,
  328. IB_WC_LOC_PROT_ERR,
  329. IB_WC_WR_FLUSH_ERR,
  330. IB_WC_MW_BIND_ERR,
  331. IB_WC_BAD_RESP_ERR,
  332. IB_WC_LOC_ACCESS_ERR,
  333. IB_WC_REM_INV_REQ_ERR,
  334. IB_WC_REM_ACCESS_ERR,
  335. IB_WC_REM_OP_ERR,
  336. IB_WC_RETRY_EXC_ERR,
  337. IB_WC_RNR_RETRY_EXC_ERR,
  338. IB_WC_LOC_RDD_VIOL_ERR,
  339. IB_WC_REM_INV_RD_REQ_ERR,
  340. IB_WC_REM_ABORT_ERR,
  341. IB_WC_INV_EECN_ERR,
  342. IB_WC_INV_EEC_STATE_ERR,
  343. IB_WC_FATAL_ERR,
  344. IB_WC_RESP_TIMEOUT_ERR,
  345. IB_WC_GENERAL_ERR
  346. };
  347. enum ib_wc_opcode {
  348. IB_WC_SEND,
  349. IB_WC_RDMA_WRITE,
  350. IB_WC_RDMA_READ,
  351. IB_WC_COMP_SWAP,
  352. IB_WC_FETCH_ADD,
  353. IB_WC_BIND_MW,
  354. /*
  355. * Set value of IB_WC_RECV so consumers can test if a completion is a
  356. * receive by testing (opcode & IB_WC_RECV).
  357. */
  358. IB_WC_RECV = 1 << 7,
  359. IB_WC_RECV_RDMA_WITH_IMM
  360. };
  361. enum ib_wc_flags {
  362. IB_WC_GRH = 1,
  363. IB_WC_WITH_IMM = (1<<1)
  364. };
  365. struct ib_wc {
  366. u64 wr_id;
  367. enum ib_wc_status status;
  368. enum ib_wc_opcode opcode;
  369. u32 vendor_err;
  370. u32 byte_len;
  371. __be32 imm_data;
  372. u32 qp_num;
  373. u32 src_qp;
  374. int wc_flags;
  375. u16 pkey_index;
  376. u16 slid;
  377. u8 sl;
  378. u8 dlid_path_bits;
  379. u8 port_num; /* valid only for DR SMPs on switches */
  380. };
  381. enum ib_cq_notify {
  382. IB_CQ_SOLICITED,
  383. IB_CQ_NEXT_COMP
  384. };
  385. enum ib_srq_attr_mask {
  386. IB_SRQ_MAX_WR = 1 << 0,
  387. IB_SRQ_LIMIT = 1 << 1,
  388. };
  389. struct ib_srq_attr {
  390. u32 max_wr;
  391. u32 max_sge;
  392. u32 srq_limit;
  393. };
  394. struct ib_srq_init_attr {
  395. void (*event_handler)(struct ib_event *, void *);
  396. void *srq_context;
  397. struct ib_srq_attr attr;
  398. };
  399. struct ib_qp_cap {
  400. u32 max_send_wr;
  401. u32 max_recv_wr;
  402. u32 max_send_sge;
  403. u32 max_recv_sge;
  404. u32 max_inline_data;
  405. };
  406. enum ib_sig_type {
  407. IB_SIGNAL_ALL_WR,
  408. IB_SIGNAL_REQ_WR
  409. };
  410. enum ib_qp_type {
  411. /*
  412. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  413. * here (and in that order) since the MAD layer uses them as
  414. * indices into a 2-entry table.
  415. */
  416. IB_QPT_SMI,
  417. IB_QPT_GSI,
  418. IB_QPT_RC,
  419. IB_QPT_UC,
  420. IB_QPT_UD,
  421. IB_QPT_RAW_IPV6,
  422. IB_QPT_RAW_ETY
  423. };
  424. struct ib_qp_init_attr {
  425. void (*event_handler)(struct ib_event *, void *);
  426. void *qp_context;
  427. struct ib_cq *send_cq;
  428. struct ib_cq *recv_cq;
  429. struct ib_srq *srq;
  430. struct ib_qp_cap cap;
  431. enum ib_sig_type sq_sig_type;
  432. enum ib_qp_type qp_type;
  433. u8 port_num; /* special QP types only */
  434. };
  435. enum ib_rnr_timeout {
  436. IB_RNR_TIMER_655_36 = 0,
  437. IB_RNR_TIMER_000_01 = 1,
  438. IB_RNR_TIMER_000_02 = 2,
  439. IB_RNR_TIMER_000_03 = 3,
  440. IB_RNR_TIMER_000_04 = 4,
  441. IB_RNR_TIMER_000_06 = 5,
  442. IB_RNR_TIMER_000_08 = 6,
  443. IB_RNR_TIMER_000_12 = 7,
  444. IB_RNR_TIMER_000_16 = 8,
  445. IB_RNR_TIMER_000_24 = 9,
  446. IB_RNR_TIMER_000_32 = 10,
  447. IB_RNR_TIMER_000_48 = 11,
  448. IB_RNR_TIMER_000_64 = 12,
  449. IB_RNR_TIMER_000_96 = 13,
  450. IB_RNR_TIMER_001_28 = 14,
  451. IB_RNR_TIMER_001_92 = 15,
  452. IB_RNR_TIMER_002_56 = 16,
  453. IB_RNR_TIMER_003_84 = 17,
  454. IB_RNR_TIMER_005_12 = 18,
  455. IB_RNR_TIMER_007_68 = 19,
  456. IB_RNR_TIMER_010_24 = 20,
  457. IB_RNR_TIMER_015_36 = 21,
  458. IB_RNR_TIMER_020_48 = 22,
  459. IB_RNR_TIMER_030_72 = 23,
  460. IB_RNR_TIMER_040_96 = 24,
  461. IB_RNR_TIMER_061_44 = 25,
  462. IB_RNR_TIMER_081_92 = 26,
  463. IB_RNR_TIMER_122_88 = 27,
  464. IB_RNR_TIMER_163_84 = 28,
  465. IB_RNR_TIMER_245_76 = 29,
  466. IB_RNR_TIMER_327_68 = 30,
  467. IB_RNR_TIMER_491_52 = 31
  468. };
  469. enum ib_qp_attr_mask {
  470. IB_QP_STATE = 1,
  471. IB_QP_CUR_STATE = (1<<1),
  472. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  473. IB_QP_ACCESS_FLAGS = (1<<3),
  474. IB_QP_PKEY_INDEX = (1<<4),
  475. IB_QP_PORT = (1<<5),
  476. IB_QP_QKEY = (1<<6),
  477. IB_QP_AV = (1<<7),
  478. IB_QP_PATH_MTU = (1<<8),
  479. IB_QP_TIMEOUT = (1<<9),
  480. IB_QP_RETRY_CNT = (1<<10),
  481. IB_QP_RNR_RETRY = (1<<11),
  482. IB_QP_RQ_PSN = (1<<12),
  483. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  484. IB_QP_ALT_PATH = (1<<14),
  485. IB_QP_MIN_RNR_TIMER = (1<<15),
  486. IB_QP_SQ_PSN = (1<<16),
  487. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  488. IB_QP_PATH_MIG_STATE = (1<<18),
  489. IB_QP_CAP = (1<<19),
  490. IB_QP_DEST_QPN = (1<<20)
  491. };
  492. enum ib_qp_state {
  493. IB_QPS_RESET,
  494. IB_QPS_INIT,
  495. IB_QPS_RTR,
  496. IB_QPS_RTS,
  497. IB_QPS_SQD,
  498. IB_QPS_SQE,
  499. IB_QPS_ERR
  500. };
  501. enum ib_mig_state {
  502. IB_MIG_MIGRATED,
  503. IB_MIG_REARM,
  504. IB_MIG_ARMED
  505. };
  506. struct ib_qp_attr {
  507. enum ib_qp_state qp_state;
  508. enum ib_qp_state cur_qp_state;
  509. enum ib_mtu path_mtu;
  510. enum ib_mig_state path_mig_state;
  511. u32 qkey;
  512. u32 rq_psn;
  513. u32 sq_psn;
  514. u32 dest_qp_num;
  515. int qp_access_flags;
  516. struct ib_qp_cap cap;
  517. struct ib_ah_attr ah_attr;
  518. struct ib_ah_attr alt_ah_attr;
  519. u16 pkey_index;
  520. u16 alt_pkey_index;
  521. u8 en_sqd_async_notify;
  522. u8 sq_draining;
  523. u8 max_rd_atomic;
  524. u8 max_dest_rd_atomic;
  525. u8 min_rnr_timer;
  526. u8 port_num;
  527. u8 timeout;
  528. u8 retry_cnt;
  529. u8 rnr_retry;
  530. u8 alt_port_num;
  531. u8 alt_timeout;
  532. };
  533. enum ib_wr_opcode {
  534. IB_WR_RDMA_WRITE,
  535. IB_WR_RDMA_WRITE_WITH_IMM,
  536. IB_WR_SEND,
  537. IB_WR_SEND_WITH_IMM,
  538. IB_WR_RDMA_READ,
  539. IB_WR_ATOMIC_CMP_AND_SWP,
  540. IB_WR_ATOMIC_FETCH_AND_ADD
  541. };
  542. enum ib_send_flags {
  543. IB_SEND_FENCE = 1,
  544. IB_SEND_SIGNALED = (1<<1),
  545. IB_SEND_SOLICITED = (1<<2),
  546. IB_SEND_INLINE = (1<<3)
  547. };
  548. struct ib_sge {
  549. u64 addr;
  550. u32 length;
  551. u32 lkey;
  552. };
  553. struct ib_send_wr {
  554. struct ib_send_wr *next;
  555. u64 wr_id;
  556. struct ib_sge *sg_list;
  557. int num_sge;
  558. enum ib_wr_opcode opcode;
  559. int send_flags;
  560. __be32 imm_data;
  561. union {
  562. struct {
  563. u64 remote_addr;
  564. u32 rkey;
  565. } rdma;
  566. struct {
  567. u64 remote_addr;
  568. u64 compare_add;
  569. u64 swap;
  570. u32 rkey;
  571. } atomic;
  572. struct {
  573. struct ib_ah *ah;
  574. u32 remote_qpn;
  575. u32 remote_qkey;
  576. u16 pkey_index; /* valid for GSI only */
  577. u8 port_num; /* valid for DR SMPs on switch only */
  578. } ud;
  579. } wr;
  580. };
  581. struct ib_recv_wr {
  582. struct ib_recv_wr *next;
  583. u64 wr_id;
  584. struct ib_sge *sg_list;
  585. int num_sge;
  586. };
  587. enum ib_access_flags {
  588. IB_ACCESS_LOCAL_WRITE = 1,
  589. IB_ACCESS_REMOTE_WRITE = (1<<1),
  590. IB_ACCESS_REMOTE_READ = (1<<2),
  591. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  592. IB_ACCESS_MW_BIND = (1<<4)
  593. };
  594. struct ib_phys_buf {
  595. u64 addr;
  596. u64 size;
  597. };
  598. struct ib_mr_attr {
  599. struct ib_pd *pd;
  600. u64 device_virt_addr;
  601. u64 size;
  602. int mr_access_flags;
  603. u32 lkey;
  604. u32 rkey;
  605. };
  606. enum ib_mr_rereg_flags {
  607. IB_MR_REREG_TRANS = 1,
  608. IB_MR_REREG_PD = (1<<1),
  609. IB_MR_REREG_ACCESS = (1<<2)
  610. };
  611. struct ib_mw_bind {
  612. struct ib_mr *mr;
  613. u64 wr_id;
  614. u64 addr;
  615. u32 length;
  616. int send_flags;
  617. int mw_access_flags;
  618. };
  619. struct ib_fmr_attr {
  620. int max_pages;
  621. int max_maps;
  622. u8 page_shift;
  623. };
  624. struct ib_ucontext {
  625. struct ib_device *device;
  626. struct list_head pd_list;
  627. struct list_head mr_list;
  628. struct list_head mw_list;
  629. struct list_head cq_list;
  630. struct list_head qp_list;
  631. struct list_head srq_list;
  632. struct list_head ah_list;
  633. };
  634. struct ib_uobject {
  635. u64 user_handle; /* handle given to us by userspace */
  636. struct ib_ucontext *context; /* associated user context */
  637. void *object; /* containing object */
  638. struct list_head list; /* link to context's list */
  639. u32 id; /* index into kernel idr */
  640. struct kref ref;
  641. struct rw_semaphore mutex; /* protects .live */
  642. int live;
  643. };
  644. struct ib_umem {
  645. unsigned long user_base;
  646. unsigned long virt_base;
  647. size_t length;
  648. int offset;
  649. int page_size;
  650. int writable;
  651. struct list_head chunk_list;
  652. };
  653. struct ib_umem_chunk {
  654. struct list_head list;
  655. int nents;
  656. int nmap;
  657. struct scatterlist page_list[0];
  658. };
  659. struct ib_udata {
  660. void __user *inbuf;
  661. void __user *outbuf;
  662. size_t inlen;
  663. size_t outlen;
  664. };
  665. #define IB_UMEM_MAX_PAGE_CHUNK \
  666. ((PAGE_SIZE - offsetof(struct ib_umem_chunk, page_list)) / \
  667. ((void *) &((struct ib_umem_chunk *) 0)->page_list[1] - \
  668. (void *) &((struct ib_umem_chunk *) 0)->page_list[0]))
  669. struct ib_umem_object {
  670. struct ib_uobject uobject;
  671. struct ib_umem umem;
  672. };
  673. struct ib_pd {
  674. struct ib_device *device;
  675. struct ib_uobject *uobject;
  676. atomic_t usecnt; /* count all resources */
  677. };
  678. struct ib_ah {
  679. struct ib_device *device;
  680. struct ib_pd *pd;
  681. struct ib_uobject *uobject;
  682. };
  683. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  684. struct ib_cq {
  685. struct ib_device *device;
  686. struct ib_uobject *uobject;
  687. ib_comp_handler comp_handler;
  688. void (*event_handler)(struct ib_event *, void *);
  689. void * cq_context;
  690. int cqe;
  691. atomic_t usecnt; /* count number of work queues */
  692. };
  693. struct ib_srq {
  694. struct ib_device *device;
  695. struct ib_pd *pd;
  696. struct ib_uobject *uobject;
  697. void (*event_handler)(struct ib_event *, void *);
  698. void *srq_context;
  699. atomic_t usecnt;
  700. };
  701. struct ib_qp {
  702. struct ib_device *device;
  703. struct ib_pd *pd;
  704. struct ib_cq *send_cq;
  705. struct ib_cq *recv_cq;
  706. struct ib_srq *srq;
  707. struct ib_uobject *uobject;
  708. void (*event_handler)(struct ib_event *, void *);
  709. void *qp_context;
  710. u32 qp_num;
  711. enum ib_qp_type qp_type;
  712. };
  713. struct ib_mr {
  714. struct ib_device *device;
  715. struct ib_pd *pd;
  716. struct ib_uobject *uobject;
  717. u32 lkey;
  718. u32 rkey;
  719. atomic_t usecnt; /* count number of MWs */
  720. };
  721. struct ib_mw {
  722. struct ib_device *device;
  723. struct ib_pd *pd;
  724. struct ib_uobject *uobject;
  725. u32 rkey;
  726. };
  727. struct ib_fmr {
  728. struct ib_device *device;
  729. struct ib_pd *pd;
  730. struct list_head list;
  731. u32 lkey;
  732. u32 rkey;
  733. };
  734. struct ib_mad;
  735. struct ib_grh;
  736. enum ib_process_mad_flags {
  737. IB_MAD_IGNORE_MKEY = 1,
  738. IB_MAD_IGNORE_BKEY = 2,
  739. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  740. };
  741. enum ib_mad_result {
  742. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  743. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  744. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  745. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  746. };
  747. #define IB_DEVICE_NAME_MAX 64
  748. struct ib_cache {
  749. rwlock_t lock;
  750. struct ib_event_handler event_handler;
  751. struct ib_pkey_cache **pkey_cache;
  752. struct ib_gid_cache **gid_cache;
  753. u8 *lmc_cache;
  754. };
  755. struct ib_device {
  756. struct device *dma_device;
  757. char name[IB_DEVICE_NAME_MAX];
  758. struct list_head event_handler_list;
  759. spinlock_t event_handler_lock;
  760. struct list_head core_list;
  761. struct list_head client_data_list;
  762. spinlock_t client_data_lock;
  763. struct ib_cache cache;
  764. u32 flags;
  765. int (*query_device)(struct ib_device *device,
  766. struct ib_device_attr *device_attr);
  767. int (*query_port)(struct ib_device *device,
  768. u8 port_num,
  769. struct ib_port_attr *port_attr);
  770. int (*query_gid)(struct ib_device *device,
  771. u8 port_num, int index,
  772. union ib_gid *gid);
  773. int (*query_pkey)(struct ib_device *device,
  774. u8 port_num, u16 index, u16 *pkey);
  775. int (*modify_device)(struct ib_device *device,
  776. int device_modify_mask,
  777. struct ib_device_modify *device_modify);
  778. int (*modify_port)(struct ib_device *device,
  779. u8 port_num, int port_modify_mask,
  780. struct ib_port_modify *port_modify);
  781. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  782. struct ib_udata *udata);
  783. int (*dealloc_ucontext)(struct ib_ucontext *context);
  784. int (*mmap)(struct ib_ucontext *context,
  785. struct vm_area_struct *vma);
  786. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  787. struct ib_ucontext *context,
  788. struct ib_udata *udata);
  789. int (*dealloc_pd)(struct ib_pd *pd);
  790. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  791. struct ib_ah_attr *ah_attr);
  792. int (*modify_ah)(struct ib_ah *ah,
  793. struct ib_ah_attr *ah_attr);
  794. int (*query_ah)(struct ib_ah *ah,
  795. struct ib_ah_attr *ah_attr);
  796. int (*destroy_ah)(struct ib_ah *ah);
  797. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  798. struct ib_srq_init_attr *srq_init_attr,
  799. struct ib_udata *udata);
  800. int (*modify_srq)(struct ib_srq *srq,
  801. struct ib_srq_attr *srq_attr,
  802. enum ib_srq_attr_mask srq_attr_mask);
  803. int (*query_srq)(struct ib_srq *srq,
  804. struct ib_srq_attr *srq_attr);
  805. int (*destroy_srq)(struct ib_srq *srq);
  806. int (*post_srq_recv)(struct ib_srq *srq,
  807. struct ib_recv_wr *recv_wr,
  808. struct ib_recv_wr **bad_recv_wr);
  809. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  810. struct ib_qp_init_attr *qp_init_attr,
  811. struct ib_udata *udata);
  812. int (*modify_qp)(struct ib_qp *qp,
  813. struct ib_qp_attr *qp_attr,
  814. int qp_attr_mask);
  815. int (*query_qp)(struct ib_qp *qp,
  816. struct ib_qp_attr *qp_attr,
  817. int qp_attr_mask,
  818. struct ib_qp_init_attr *qp_init_attr);
  819. int (*destroy_qp)(struct ib_qp *qp);
  820. int (*post_send)(struct ib_qp *qp,
  821. struct ib_send_wr *send_wr,
  822. struct ib_send_wr **bad_send_wr);
  823. int (*post_recv)(struct ib_qp *qp,
  824. struct ib_recv_wr *recv_wr,
  825. struct ib_recv_wr **bad_recv_wr);
  826. struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
  827. struct ib_ucontext *context,
  828. struct ib_udata *udata);
  829. int (*destroy_cq)(struct ib_cq *cq);
  830. int (*resize_cq)(struct ib_cq *cq, int cqe,
  831. struct ib_udata *udata);
  832. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  833. struct ib_wc *wc);
  834. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  835. int (*req_notify_cq)(struct ib_cq *cq,
  836. enum ib_cq_notify cq_notify);
  837. int (*req_ncomp_notif)(struct ib_cq *cq,
  838. int wc_cnt);
  839. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  840. int mr_access_flags);
  841. struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
  842. struct ib_phys_buf *phys_buf_array,
  843. int num_phys_buf,
  844. int mr_access_flags,
  845. u64 *iova_start);
  846. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  847. struct ib_umem *region,
  848. int mr_access_flags,
  849. struct ib_udata *udata);
  850. int (*query_mr)(struct ib_mr *mr,
  851. struct ib_mr_attr *mr_attr);
  852. int (*dereg_mr)(struct ib_mr *mr);
  853. int (*rereg_phys_mr)(struct ib_mr *mr,
  854. int mr_rereg_mask,
  855. struct ib_pd *pd,
  856. struct ib_phys_buf *phys_buf_array,
  857. int num_phys_buf,
  858. int mr_access_flags,
  859. u64 *iova_start);
  860. struct ib_mw * (*alloc_mw)(struct ib_pd *pd);
  861. int (*bind_mw)(struct ib_qp *qp,
  862. struct ib_mw *mw,
  863. struct ib_mw_bind *mw_bind);
  864. int (*dealloc_mw)(struct ib_mw *mw);
  865. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  866. int mr_access_flags,
  867. struct ib_fmr_attr *fmr_attr);
  868. int (*map_phys_fmr)(struct ib_fmr *fmr,
  869. u64 *page_list, int list_len,
  870. u64 iova);
  871. int (*unmap_fmr)(struct list_head *fmr_list);
  872. int (*dealloc_fmr)(struct ib_fmr *fmr);
  873. int (*attach_mcast)(struct ib_qp *qp,
  874. union ib_gid *gid,
  875. u16 lid);
  876. int (*detach_mcast)(struct ib_qp *qp,
  877. union ib_gid *gid,
  878. u16 lid);
  879. int (*process_mad)(struct ib_device *device,
  880. int process_mad_flags,
  881. u8 port_num,
  882. struct ib_wc *in_wc,
  883. struct ib_grh *in_grh,
  884. struct ib_mad *in_mad,
  885. struct ib_mad *out_mad);
  886. struct module *owner;
  887. struct class_device class_dev;
  888. struct kobject ports_parent;
  889. struct list_head port_list;
  890. enum {
  891. IB_DEV_UNINITIALIZED,
  892. IB_DEV_REGISTERED,
  893. IB_DEV_UNREGISTERED
  894. } reg_state;
  895. u64 uverbs_cmd_mask;
  896. int uverbs_abi_ver;
  897. char node_desc[64];
  898. __be64 node_guid;
  899. u8 node_type;
  900. u8 phys_port_cnt;
  901. };
  902. struct ib_client {
  903. char *name;
  904. void (*add) (struct ib_device *);
  905. void (*remove)(struct ib_device *);
  906. struct list_head list;
  907. };
  908. struct ib_device *ib_alloc_device(size_t size);
  909. void ib_dealloc_device(struct ib_device *device);
  910. int ib_register_device (struct ib_device *device);
  911. void ib_unregister_device(struct ib_device *device);
  912. int ib_register_client (struct ib_client *client);
  913. void ib_unregister_client(struct ib_client *client);
  914. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  915. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  916. void *data);
  917. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  918. {
  919. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  920. }
  921. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  922. {
  923. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  924. }
  925. /**
  926. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  927. * contains all required attributes and no attributes not allowed for
  928. * the given QP state transition.
  929. * @cur_state: Current QP state
  930. * @next_state: Next QP state
  931. * @type: QP type
  932. * @mask: Mask of supplied QP attributes
  933. *
  934. * This function is a helper function that a low-level driver's
  935. * modify_qp method can use to validate the consumer's input. It
  936. * checks that cur_state and next_state are valid QP states, that a
  937. * transition from cur_state to next_state is allowed by the IB spec,
  938. * and that the attribute mask supplied is allowed for the transition.
  939. */
  940. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  941. enum ib_qp_type type, enum ib_qp_attr_mask mask);
  942. int ib_register_event_handler (struct ib_event_handler *event_handler);
  943. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  944. void ib_dispatch_event(struct ib_event *event);
  945. int ib_query_device(struct ib_device *device,
  946. struct ib_device_attr *device_attr);
  947. int ib_query_port(struct ib_device *device,
  948. u8 port_num, struct ib_port_attr *port_attr);
  949. int ib_query_gid(struct ib_device *device,
  950. u8 port_num, int index, union ib_gid *gid);
  951. int ib_query_pkey(struct ib_device *device,
  952. u8 port_num, u16 index, u16 *pkey);
  953. int ib_modify_device(struct ib_device *device,
  954. int device_modify_mask,
  955. struct ib_device_modify *device_modify);
  956. int ib_modify_port(struct ib_device *device,
  957. u8 port_num, int port_modify_mask,
  958. struct ib_port_modify *port_modify);
  959. /**
  960. * ib_alloc_pd - Allocates an unused protection domain.
  961. * @device: The device on which to allocate the protection domain.
  962. *
  963. * A protection domain object provides an association between QPs, shared
  964. * receive queues, address handles, memory regions, and memory windows.
  965. */
  966. struct ib_pd *ib_alloc_pd(struct ib_device *device);
  967. /**
  968. * ib_dealloc_pd - Deallocates a protection domain.
  969. * @pd: The protection domain to deallocate.
  970. */
  971. int ib_dealloc_pd(struct ib_pd *pd);
  972. /**
  973. * ib_create_ah - Creates an address handle for the given address vector.
  974. * @pd: The protection domain associated with the address handle.
  975. * @ah_attr: The attributes of the address vector.
  976. *
  977. * The address handle is used to reference a local or global destination
  978. * in all UD QP post sends.
  979. */
  980. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  981. /**
  982. * ib_init_ah_from_wc - Initializes address handle attributes from a
  983. * work completion.
  984. * @device: Device on which the received message arrived.
  985. * @port_num: Port on which the received message arrived.
  986. * @wc: Work completion associated with the received message.
  987. * @grh: References the received global route header. This parameter is
  988. * ignored unless the work completion indicates that the GRH is valid.
  989. * @ah_attr: Returned attributes that can be used when creating an address
  990. * handle for replying to the message.
  991. */
  992. int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
  993. struct ib_grh *grh, struct ib_ah_attr *ah_attr);
  994. /**
  995. * ib_create_ah_from_wc - Creates an address handle associated with the
  996. * sender of the specified work completion.
  997. * @pd: The protection domain associated with the address handle.
  998. * @wc: Work completion information associated with a received message.
  999. * @grh: References the received global route header. This parameter is
  1000. * ignored unless the work completion indicates that the GRH is valid.
  1001. * @port_num: The outbound port number to associate with the address.
  1002. *
  1003. * The address handle is used to reference a local or global destination
  1004. * in all UD QP post sends.
  1005. */
  1006. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
  1007. struct ib_grh *grh, u8 port_num);
  1008. /**
  1009. * ib_modify_ah - Modifies the address vector associated with an address
  1010. * handle.
  1011. * @ah: The address handle to modify.
  1012. * @ah_attr: The new address vector attributes to associate with the
  1013. * address handle.
  1014. */
  1015. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1016. /**
  1017. * ib_query_ah - Queries the address vector associated with an address
  1018. * handle.
  1019. * @ah: The address handle to query.
  1020. * @ah_attr: The address vector attributes associated with the address
  1021. * handle.
  1022. */
  1023. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1024. /**
  1025. * ib_destroy_ah - Destroys an address handle.
  1026. * @ah: The address handle to destroy.
  1027. */
  1028. int ib_destroy_ah(struct ib_ah *ah);
  1029. /**
  1030. * ib_create_srq - Creates a SRQ associated with the specified protection
  1031. * domain.
  1032. * @pd: The protection domain associated with the SRQ.
  1033. * @srq_init_attr: A list of initial attributes required to create the
  1034. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  1035. * the actual capabilities of the created SRQ.
  1036. *
  1037. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  1038. * requested size of the SRQ, and set to the actual values allocated
  1039. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  1040. * will always be at least as large as the requested values.
  1041. */
  1042. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  1043. struct ib_srq_init_attr *srq_init_attr);
  1044. /**
  1045. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  1046. * @srq: The SRQ to modify.
  1047. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  1048. * the current values of selected SRQ attributes are returned.
  1049. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  1050. * are being modified.
  1051. *
  1052. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  1053. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  1054. * the number of receives queued drops below the limit.
  1055. */
  1056. int ib_modify_srq(struct ib_srq *srq,
  1057. struct ib_srq_attr *srq_attr,
  1058. enum ib_srq_attr_mask srq_attr_mask);
  1059. /**
  1060. * ib_query_srq - Returns the attribute list and current values for the
  1061. * specified SRQ.
  1062. * @srq: The SRQ to query.
  1063. * @srq_attr: The attributes of the specified SRQ.
  1064. */
  1065. int ib_query_srq(struct ib_srq *srq,
  1066. struct ib_srq_attr *srq_attr);
  1067. /**
  1068. * ib_destroy_srq - Destroys the specified SRQ.
  1069. * @srq: The SRQ to destroy.
  1070. */
  1071. int ib_destroy_srq(struct ib_srq *srq);
  1072. /**
  1073. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  1074. * @srq: The SRQ to post the work request on.
  1075. * @recv_wr: A list of work requests to post on the receive queue.
  1076. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1077. * the work request that failed to be posted on the QP.
  1078. */
  1079. static inline int ib_post_srq_recv(struct ib_srq *srq,
  1080. struct ib_recv_wr *recv_wr,
  1081. struct ib_recv_wr **bad_recv_wr)
  1082. {
  1083. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  1084. }
  1085. /**
  1086. * ib_create_qp - Creates a QP associated with the specified protection
  1087. * domain.
  1088. * @pd: The protection domain associated with the QP.
  1089. * @qp_init_attr: A list of initial attributes required to create the
  1090. * QP. If QP creation succeeds, then the attributes are updated to
  1091. * the actual capabilities of the created QP.
  1092. */
  1093. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  1094. struct ib_qp_init_attr *qp_init_attr);
  1095. /**
  1096. * ib_modify_qp - Modifies the attributes for the specified QP and then
  1097. * transitions the QP to the given state.
  1098. * @qp: The QP to modify.
  1099. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  1100. * the current values of selected QP attributes are returned.
  1101. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  1102. * are being modified.
  1103. */
  1104. int ib_modify_qp(struct ib_qp *qp,
  1105. struct ib_qp_attr *qp_attr,
  1106. int qp_attr_mask);
  1107. /**
  1108. * ib_query_qp - Returns the attribute list and current values for the
  1109. * specified QP.
  1110. * @qp: The QP to query.
  1111. * @qp_attr: The attributes of the specified QP.
  1112. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  1113. * @qp_init_attr: Additional attributes of the selected QP.
  1114. *
  1115. * The qp_attr_mask may be used to limit the query to gathering only the
  1116. * selected attributes.
  1117. */
  1118. int ib_query_qp(struct ib_qp *qp,
  1119. struct ib_qp_attr *qp_attr,
  1120. int qp_attr_mask,
  1121. struct ib_qp_init_attr *qp_init_attr);
  1122. /**
  1123. * ib_destroy_qp - Destroys the specified QP.
  1124. * @qp: The QP to destroy.
  1125. */
  1126. int ib_destroy_qp(struct ib_qp *qp);
  1127. /**
  1128. * ib_post_send - Posts a list of work requests to the send queue of
  1129. * the specified QP.
  1130. * @qp: The QP to post the work request on.
  1131. * @send_wr: A list of work requests to post on the send queue.
  1132. * @bad_send_wr: On an immediate failure, this parameter will reference
  1133. * the work request that failed to be posted on the QP.
  1134. */
  1135. static inline int ib_post_send(struct ib_qp *qp,
  1136. struct ib_send_wr *send_wr,
  1137. struct ib_send_wr **bad_send_wr)
  1138. {
  1139. return qp->device->post_send(qp, send_wr, bad_send_wr);
  1140. }
  1141. /**
  1142. * ib_post_recv - Posts a list of work requests to the receive queue of
  1143. * the specified QP.
  1144. * @qp: The QP to post the work request on.
  1145. * @recv_wr: A list of work requests to post on the receive queue.
  1146. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1147. * the work request that failed to be posted on the QP.
  1148. */
  1149. static inline int ib_post_recv(struct ib_qp *qp,
  1150. struct ib_recv_wr *recv_wr,
  1151. struct ib_recv_wr **bad_recv_wr)
  1152. {
  1153. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  1154. }
  1155. /**
  1156. * ib_create_cq - Creates a CQ on the specified device.
  1157. * @device: The device on which to create the CQ.
  1158. * @comp_handler: A user-specified callback that is invoked when a
  1159. * completion event occurs on the CQ.
  1160. * @event_handler: A user-specified callback that is invoked when an
  1161. * asynchronous event not associated with a completion occurs on the CQ.
  1162. * @cq_context: Context associated with the CQ returned to the user via
  1163. * the associated completion and event handlers.
  1164. * @cqe: The minimum size of the CQ.
  1165. *
  1166. * Users can examine the cq structure to determine the actual CQ size.
  1167. */
  1168. struct ib_cq *ib_create_cq(struct ib_device *device,
  1169. ib_comp_handler comp_handler,
  1170. void (*event_handler)(struct ib_event *, void *),
  1171. void *cq_context, int cqe);
  1172. /**
  1173. * ib_resize_cq - Modifies the capacity of the CQ.
  1174. * @cq: The CQ to resize.
  1175. * @cqe: The minimum size of the CQ.
  1176. *
  1177. * Users can examine the cq structure to determine the actual CQ size.
  1178. */
  1179. int ib_resize_cq(struct ib_cq *cq, int cqe);
  1180. /**
  1181. * ib_destroy_cq - Destroys the specified CQ.
  1182. * @cq: The CQ to destroy.
  1183. */
  1184. int ib_destroy_cq(struct ib_cq *cq);
  1185. /**
  1186. * ib_poll_cq - poll a CQ for completion(s)
  1187. * @cq:the CQ being polled
  1188. * @num_entries:maximum number of completions to return
  1189. * @wc:array of at least @num_entries &struct ib_wc where completions
  1190. * will be returned
  1191. *
  1192. * Poll a CQ for (possibly multiple) completions. If the return value
  1193. * is < 0, an error occurred. If the return value is >= 0, it is the
  1194. * number of completions returned. If the return value is
  1195. * non-negative and < num_entries, then the CQ was emptied.
  1196. */
  1197. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  1198. struct ib_wc *wc)
  1199. {
  1200. return cq->device->poll_cq(cq, num_entries, wc);
  1201. }
  1202. /**
  1203. * ib_peek_cq - Returns the number of unreaped completions currently
  1204. * on the specified CQ.
  1205. * @cq: The CQ to peek.
  1206. * @wc_cnt: A minimum number of unreaped completions to check for.
  1207. *
  1208. * If the number of unreaped completions is greater than or equal to wc_cnt,
  1209. * this function returns wc_cnt, otherwise, it returns the actual number of
  1210. * unreaped completions.
  1211. */
  1212. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  1213. /**
  1214. * ib_req_notify_cq - Request completion notification on a CQ.
  1215. * @cq: The CQ to generate an event for.
  1216. * @cq_notify: If set to %IB_CQ_SOLICITED, completion notification will
  1217. * occur on the next solicited event. If set to %IB_CQ_NEXT_COMP,
  1218. * notification will occur on the next completion.
  1219. */
  1220. static inline int ib_req_notify_cq(struct ib_cq *cq,
  1221. enum ib_cq_notify cq_notify)
  1222. {
  1223. return cq->device->req_notify_cq(cq, cq_notify);
  1224. }
  1225. /**
  1226. * ib_req_ncomp_notif - Request completion notification when there are
  1227. * at least the specified number of unreaped completions on the CQ.
  1228. * @cq: The CQ to generate an event for.
  1229. * @wc_cnt: The number of unreaped completions that should be on the
  1230. * CQ before an event is generated.
  1231. */
  1232. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  1233. {
  1234. return cq->device->req_ncomp_notif ?
  1235. cq->device->req_ncomp_notif(cq, wc_cnt) :
  1236. -ENOSYS;
  1237. }
  1238. /**
  1239. * ib_get_dma_mr - Returns a memory region for system memory that is
  1240. * usable for DMA.
  1241. * @pd: The protection domain associated with the memory region.
  1242. * @mr_access_flags: Specifies the memory access rights.
  1243. */
  1244. struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
  1245. /**
  1246. * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
  1247. * by an HCA.
  1248. * @pd: The protection domain associated assigned to the registered region.
  1249. * @phys_buf_array: Specifies a list of physical buffers to use in the
  1250. * memory region.
  1251. * @num_phys_buf: Specifies the size of the phys_buf_array.
  1252. * @mr_access_flags: Specifies the memory access rights.
  1253. * @iova_start: The offset of the region's starting I/O virtual address.
  1254. */
  1255. struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
  1256. struct ib_phys_buf *phys_buf_array,
  1257. int num_phys_buf,
  1258. int mr_access_flags,
  1259. u64 *iova_start);
  1260. /**
  1261. * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
  1262. * Conceptually, this call performs the functions deregister memory region
  1263. * followed by register physical memory region. Where possible,
  1264. * resources are reused instead of deallocated and reallocated.
  1265. * @mr: The memory region to modify.
  1266. * @mr_rereg_mask: A bit-mask used to indicate which of the following
  1267. * properties of the memory region are being modified.
  1268. * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
  1269. * the new protection domain to associated with the memory region,
  1270. * otherwise, this parameter is ignored.
  1271. * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1272. * field specifies a list of physical buffers to use in the new
  1273. * translation, otherwise, this parameter is ignored.
  1274. * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1275. * field specifies the size of the phys_buf_array, otherwise, this
  1276. * parameter is ignored.
  1277. * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
  1278. * field specifies the new memory access rights, otherwise, this
  1279. * parameter is ignored.
  1280. * @iova_start: The offset of the region's starting I/O virtual address.
  1281. */
  1282. int ib_rereg_phys_mr(struct ib_mr *mr,
  1283. int mr_rereg_mask,
  1284. struct ib_pd *pd,
  1285. struct ib_phys_buf *phys_buf_array,
  1286. int num_phys_buf,
  1287. int mr_access_flags,
  1288. u64 *iova_start);
  1289. /**
  1290. * ib_query_mr - Retrieves information about a specific memory region.
  1291. * @mr: The memory region to retrieve information about.
  1292. * @mr_attr: The attributes of the specified memory region.
  1293. */
  1294. int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
  1295. /**
  1296. * ib_dereg_mr - Deregisters a memory region and removes it from the
  1297. * HCA translation table.
  1298. * @mr: The memory region to deregister.
  1299. */
  1300. int ib_dereg_mr(struct ib_mr *mr);
  1301. /**
  1302. * ib_alloc_mw - Allocates a memory window.
  1303. * @pd: The protection domain associated with the memory window.
  1304. */
  1305. struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
  1306. /**
  1307. * ib_bind_mw - Posts a work request to the send queue of the specified
  1308. * QP, which binds the memory window to the given address range and
  1309. * remote access attributes.
  1310. * @qp: QP to post the bind work request on.
  1311. * @mw: The memory window to bind.
  1312. * @mw_bind: Specifies information about the memory window, including
  1313. * its address range, remote access rights, and associated memory region.
  1314. */
  1315. static inline int ib_bind_mw(struct ib_qp *qp,
  1316. struct ib_mw *mw,
  1317. struct ib_mw_bind *mw_bind)
  1318. {
  1319. /* XXX reference counting in corresponding MR? */
  1320. return mw->device->bind_mw ?
  1321. mw->device->bind_mw(qp, mw, mw_bind) :
  1322. -ENOSYS;
  1323. }
  1324. /**
  1325. * ib_dealloc_mw - Deallocates a memory window.
  1326. * @mw: The memory window to deallocate.
  1327. */
  1328. int ib_dealloc_mw(struct ib_mw *mw);
  1329. /**
  1330. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  1331. * @pd: The protection domain associated with the unmapped region.
  1332. * @mr_access_flags: Specifies the memory access rights.
  1333. * @fmr_attr: Attributes of the unmapped region.
  1334. *
  1335. * A fast memory region must be mapped before it can be used as part of
  1336. * a work request.
  1337. */
  1338. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  1339. int mr_access_flags,
  1340. struct ib_fmr_attr *fmr_attr);
  1341. /**
  1342. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  1343. * @fmr: The fast memory region to associate with the pages.
  1344. * @page_list: An array of physical pages to map to the fast memory region.
  1345. * @list_len: The number of pages in page_list.
  1346. * @iova: The I/O virtual address to use with the mapped region.
  1347. */
  1348. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  1349. u64 *page_list, int list_len,
  1350. u64 iova)
  1351. {
  1352. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  1353. }
  1354. /**
  1355. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  1356. * @fmr_list: A linked list of fast memory regions to unmap.
  1357. */
  1358. int ib_unmap_fmr(struct list_head *fmr_list);
  1359. /**
  1360. * ib_dealloc_fmr - Deallocates a fast memory region.
  1361. * @fmr: The fast memory region to deallocate.
  1362. */
  1363. int ib_dealloc_fmr(struct ib_fmr *fmr);
  1364. /**
  1365. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  1366. * @qp: QP to attach to the multicast group. The QP must be type
  1367. * IB_QPT_UD.
  1368. * @gid: Multicast group GID.
  1369. * @lid: Multicast group LID in host byte order.
  1370. *
  1371. * In order to send and receive multicast packets, subnet
  1372. * administration must have created the multicast group and configured
  1373. * the fabric appropriately. The port associated with the specified
  1374. * QP must also be a member of the multicast group.
  1375. */
  1376. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1377. /**
  1378. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  1379. * @qp: QP to detach from the multicast group.
  1380. * @gid: Multicast group GID.
  1381. * @lid: Multicast group LID in host byte order.
  1382. */
  1383. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1384. #endif /* IB_VERBS_H */