ib_verbs.h 53 KB

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