ib_verbs.h 37 KB

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