ib_verbs.h 44 KB

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