ib_verbs.h 58 KB

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