ib_verbs.h 53 KB

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