ib_verbs.h 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901
  1. /*
  2. * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
  4. * Copyright (c) 2004 Intel Corporation. All rights reserved.
  5. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  6. * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
  7. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  8. * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
  9. *
  10. * This software is available to you under a choice of one of two
  11. * licenses. You may choose to be licensed under the terms of the GNU
  12. * General Public License (GPL) Version 2, available from the file
  13. * COPYING in the main directory of this source tree, or the
  14. * OpenIB.org BSD license below:
  15. *
  16. * Redistribution and use in source and binary forms, with or
  17. * without modification, are permitted provided that the following
  18. * conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer.
  23. *
  24. * - Redistributions in binary form must reproduce the above
  25. * copyright notice, this list of conditions and the following
  26. * disclaimer in the documentation and/or other materials
  27. * provided with the distribution.
  28. *
  29. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  33. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  34. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  36. * SOFTWARE.
  37. *
  38. * $Id: ib_verbs.h 1349 2004-12-16 21:09:43Z roland $
  39. */
  40. #if !defined(IB_VERBS_H)
  41. #define IB_VERBS_H
  42. #include <linux/types.h>
  43. #include <linux/device.h>
  44. #include <linux/mm.h>
  45. #include <linux/dma-mapping.h>
  46. #include <linux/kref.h>
  47. #include <linux/list.h>
  48. #include <linux/rwsem.h>
  49. #include <linux/scatterlist.h>
  50. #include <asm/atomic.h>
  51. #include <asm/uaccess.h>
  52. union ib_gid {
  53. u8 raw[16];
  54. struct {
  55. __be64 subnet_prefix;
  56. __be64 interface_id;
  57. } global;
  58. };
  59. enum rdma_node_type {
  60. /* IB values map to NodeInfo:NodeType. */
  61. RDMA_NODE_IB_CA = 1,
  62. RDMA_NODE_IB_SWITCH,
  63. RDMA_NODE_IB_ROUTER,
  64. RDMA_NODE_RNIC
  65. };
  66. enum rdma_transport_type {
  67. RDMA_TRANSPORT_IB,
  68. RDMA_TRANSPORT_IWARP
  69. };
  70. enum rdma_transport_type
  71. rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
  72. enum ib_device_cap_flags {
  73. IB_DEVICE_RESIZE_MAX_WR = 1,
  74. IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
  75. IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
  76. IB_DEVICE_RAW_MULTI = (1<<3),
  77. IB_DEVICE_AUTO_PATH_MIG = (1<<4),
  78. IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
  79. IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
  80. IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
  81. IB_DEVICE_SHUTDOWN_PORT = (1<<8),
  82. IB_DEVICE_INIT_TYPE = (1<<9),
  83. IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
  84. IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
  85. IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
  86. IB_DEVICE_SRQ_RESIZE = (1<<13),
  87. IB_DEVICE_N_NOTIFY_CQ = (1<<14),
  88. IB_DEVICE_ZERO_STAG = (1<<15),
  89. IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
  90. IB_DEVICE_MEM_WINDOW = (1<<17),
  91. /*
  92. * Devices should set IB_DEVICE_UD_IP_SUM if they support
  93. * insertion of UDP and TCP checksum on outgoing UD IPoIB
  94. * messages and can verify the validity of checksum for
  95. * incoming messages. Setting this flag implies that the
  96. * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
  97. */
  98. IB_DEVICE_UD_IP_CSUM = (1<<18),
  99. IB_DEVICE_UD_TSO = (1<<19),
  100. };
  101. enum ib_atomic_cap {
  102. IB_ATOMIC_NONE,
  103. IB_ATOMIC_HCA,
  104. IB_ATOMIC_GLOB
  105. };
  106. struct ib_device_attr {
  107. u64 fw_ver;
  108. __be64 sys_image_guid;
  109. u64 max_mr_size;
  110. u64 page_size_cap;
  111. u32 vendor_id;
  112. u32 vendor_part_id;
  113. u32 hw_ver;
  114. int max_qp;
  115. int max_qp_wr;
  116. int device_cap_flags;
  117. int max_sge;
  118. int max_sge_rd;
  119. int max_cq;
  120. int max_cqe;
  121. int max_mr;
  122. int max_pd;
  123. int max_qp_rd_atom;
  124. int max_ee_rd_atom;
  125. int max_res_rd_atom;
  126. int max_qp_init_rd_atom;
  127. int max_ee_init_rd_atom;
  128. enum ib_atomic_cap atomic_cap;
  129. int max_ee;
  130. int max_rdd;
  131. int max_mw;
  132. int max_raw_ipv6_qp;
  133. int max_raw_ethy_qp;
  134. int max_mcast_grp;
  135. int max_mcast_qp_attach;
  136. int max_total_mcast_qp_attach;
  137. int max_ah;
  138. int max_fmr;
  139. int max_map_per_fmr;
  140. int max_srq;
  141. int max_srq_wr;
  142. int max_srq_sge;
  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. /*
  381. * Set value of IB_WC_RECV so consumers can test if a completion is a
  382. * receive by testing (opcode & IB_WC_RECV).
  383. */
  384. IB_WC_RECV = 1 << 7,
  385. IB_WC_RECV_RDMA_WITH_IMM
  386. };
  387. enum ib_wc_flags {
  388. IB_WC_GRH = 1,
  389. IB_WC_WITH_IMM = (1<<1)
  390. };
  391. struct ib_wc {
  392. u64 wr_id;
  393. enum ib_wc_status status;
  394. enum ib_wc_opcode opcode;
  395. u32 vendor_err;
  396. u32 byte_len;
  397. struct ib_qp *qp;
  398. __be32 imm_data;
  399. u32 src_qp;
  400. int wc_flags;
  401. u16 pkey_index;
  402. u16 slid;
  403. u8 sl;
  404. u8 dlid_path_bits;
  405. u8 port_num; /* valid only for DR SMPs on switches */
  406. int csum_ok;
  407. };
  408. enum ib_cq_notify_flags {
  409. IB_CQ_SOLICITED = 1 << 0,
  410. IB_CQ_NEXT_COMP = 1 << 1,
  411. IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
  412. IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
  413. };
  414. enum ib_srq_attr_mask {
  415. IB_SRQ_MAX_WR = 1 << 0,
  416. IB_SRQ_LIMIT = 1 << 1,
  417. };
  418. struct ib_srq_attr {
  419. u32 max_wr;
  420. u32 max_sge;
  421. u32 srq_limit;
  422. };
  423. struct ib_srq_init_attr {
  424. void (*event_handler)(struct ib_event *, void *);
  425. void *srq_context;
  426. struct ib_srq_attr attr;
  427. };
  428. struct ib_qp_cap {
  429. u32 max_send_wr;
  430. u32 max_recv_wr;
  431. u32 max_send_sge;
  432. u32 max_recv_sge;
  433. u32 max_inline_data;
  434. };
  435. enum ib_sig_type {
  436. IB_SIGNAL_ALL_WR,
  437. IB_SIGNAL_REQ_WR
  438. };
  439. enum ib_qp_type {
  440. /*
  441. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  442. * here (and in that order) since the MAD layer uses them as
  443. * indices into a 2-entry table.
  444. */
  445. IB_QPT_SMI,
  446. IB_QPT_GSI,
  447. IB_QPT_RC,
  448. IB_QPT_UC,
  449. IB_QPT_UD,
  450. IB_QPT_RAW_IPV6,
  451. IB_QPT_RAW_ETY
  452. };
  453. enum ib_qp_create_flags {
  454. IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
  455. };
  456. struct ib_qp_init_attr {
  457. void (*event_handler)(struct ib_event *, void *);
  458. void *qp_context;
  459. struct ib_cq *send_cq;
  460. struct ib_cq *recv_cq;
  461. struct ib_srq *srq;
  462. struct ib_qp_cap cap;
  463. enum ib_sig_type sq_sig_type;
  464. enum ib_qp_type qp_type;
  465. enum ib_qp_create_flags create_flags;
  466. u8 port_num; /* special QP types only */
  467. };
  468. enum ib_rnr_timeout {
  469. IB_RNR_TIMER_655_36 = 0,
  470. IB_RNR_TIMER_000_01 = 1,
  471. IB_RNR_TIMER_000_02 = 2,
  472. IB_RNR_TIMER_000_03 = 3,
  473. IB_RNR_TIMER_000_04 = 4,
  474. IB_RNR_TIMER_000_06 = 5,
  475. IB_RNR_TIMER_000_08 = 6,
  476. IB_RNR_TIMER_000_12 = 7,
  477. IB_RNR_TIMER_000_16 = 8,
  478. IB_RNR_TIMER_000_24 = 9,
  479. IB_RNR_TIMER_000_32 = 10,
  480. IB_RNR_TIMER_000_48 = 11,
  481. IB_RNR_TIMER_000_64 = 12,
  482. IB_RNR_TIMER_000_96 = 13,
  483. IB_RNR_TIMER_001_28 = 14,
  484. IB_RNR_TIMER_001_92 = 15,
  485. IB_RNR_TIMER_002_56 = 16,
  486. IB_RNR_TIMER_003_84 = 17,
  487. IB_RNR_TIMER_005_12 = 18,
  488. IB_RNR_TIMER_007_68 = 19,
  489. IB_RNR_TIMER_010_24 = 20,
  490. IB_RNR_TIMER_015_36 = 21,
  491. IB_RNR_TIMER_020_48 = 22,
  492. IB_RNR_TIMER_030_72 = 23,
  493. IB_RNR_TIMER_040_96 = 24,
  494. IB_RNR_TIMER_061_44 = 25,
  495. IB_RNR_TIMER_081_92 = 26,
  496. IB_RNR_TIMER_122_88 = 27,
  497. IB_RNR_TIMER_163_84 = 28,
  498. IB_RNR_TIMER_245_76 = 29,
  499. IB_RNR_TIMER_327_68 = 30,
  500. IB_RNR_TIMER_491_52 = 31
  501. };
  502. enum ib_qp_attr_mask {
  503. IB_QP_STATE = 1,
  504. IB_QP_CUR_STATE = (1<<1),
  505. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  506. IB_QP_ACCESS_FLAGS = (1<<3),
  507. IB_QP_PKEY_INDEX = (1<<4),
  508. IB_QP_PORT = (1<<5),
  509. IB_QP_QKEY = (1<<6),
  510. IB_QP_AV = (1<<7),
  511. IB_QP_PATH_MTU = (1<<8),
  512. IB_QP_TIMEOUT = (1<<9),
  513. IB_QP_RETRY_CNT = (1<<10),
  514. IB_QP_RNR_RETRY = (1<<11),
  515. IB_QP_RQ_PSN = (1<<12),
  516. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  517. IB_QP_ALT_PATH = (1<<14),
  518. IB_QP_MIN_RNR_TIMER = (1<<15),
  519. IB_QP_SQ_PSN = (1<<16),
  520. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  521. IB_QP_PATH_MIG_STATE = (1<<18),
  522. IB_QP_CAP = (1<<19),
  523. IB_QP_DEST_QPN = (1<<20)
  524. };
  525. enum ib_qp_state {
  526. IB_QPS_RESET,
  527. IB_QPS_INIT,
  528. IB_QPS_RTR,
  529. IB_QPS_RTS,
  530. IB_QPS_SQD,
  531. IB_QPS_SQE,
  532. IB_QPS_ERR
  533. };
  534. enum ib_mig_state {
  535. IB_MIG_MIGRATED,
  536. IB_MIG_REARM,
  537. IB_MIG_ARMED
  538. };
  539. struct ib_qp_attr {
  540. enum ib_qp_state qp_state;
  541. enum ib_qp_state cur_qp_state;
  542. enum ib_mtu path_mtu;
  543. enum ib_mig_state path_mig_state;
  544. u32 qkey;
  545. u32 rq_psn;
  546. u32 sq_psn;
  547. u32 dest_qp_num;
  548. int qp_access_flags;
  549. struct ib_qp_cap cap;
  550. struct ib_ah_attr ah_attr;
  551. struct ib_ah_attr alt_ah_attr;
  552. u16 pkey_index;
  553. u16 alt_pkey_index;
  554. u8 en_sqd_async_notify;
  555. u8 sq_draining;
  556. u8 max_rd_atomic;
  557. u8 max_dest_rd_atomic;
  558. u8 min_rnr_timer;
  559. u8 port_num;
  560. u8 timeout;
  561. u8 retry_cnt;
  562. u8 rnr_retry;
  563. u8 alt_port_num;
  564. u8 alt_timeout;
  565. };
  566. enum ib_wr_opcode {
  567. IB_WR_RDMA_WRITE,
  568. IB_WR_RDMA_WRITE_WITH_IMM,
  569. IB_WR_SEND,
  570. IB_WR_SEND_WITH_IMM,
  571. IB_WR_RDMA_READ,
  572. IB_WR_ATOMIC_CMP_AND_SWP,
  573. IB_WR_ATOMIC_FETCH_AND_ADD,
  574. IB_WR_LSO,
  575. IB_WR_SEND_WITH_INV,
  576. };
  577. enum ib_send_flags {
  578. IB_SEND_FENCE = 1,
  579. IB_SEND_SIGNALED = (1<<1),
  580. IB_SEND_SOLICITED = (1<<2),
  581. IB_SEND_INLINE = (1<<3),
  582. IB_SEND_IP_CSUM = (1<<4)
  583. };
  584. struct ib_sge {
  585. u64 addr;
  586. u32 length;
  587. u32 lkey;
  588. };
  589. struct ib_send_wr {
  590. struct ib_send_wr *next;
  591. u64 wr_id;
  592. struct ib_sge *sg_list;
  593. int num_sge;
  594. enum ib_wr_opcode opcode;
  595. int send_flags;
  596. union {
  597. __be32 imm_data;
  598. u32 invalidate_rkey;
  599. } ex;
  600. union {
  601. struct {
  602. u64 remote_addr;
  603. u32 rkey;
  604. } rdma;
  605. struct {
  606. u64 remote_addr;
  607. u64 compare_add;
  608. u64 swap;
  609. u32 rkey;
  610. } atomic;
  611. struct {
  612. struct ib_ah *ah;
  613. void *header;
  614. int hlen;
  615. int mss;
  616. u32 remote_qpn;
  617. u32 remote_qkey;
  618. u16 pkey_index; /* valid for GSI only */
  619. u8 port_num; /* valid for DR SMPs on switch only */
  620. } ud;
  621. } wr;
  622. };
  623. struct ib_recv_wr {
  624. struct ib_recv_wr *next;
  625. u64 wr_id;
  626. struct ib_sge *sg_list;
  627. int num_sge;
  628. };
  629. enum ib_access_flags {
  630. IB_ACCESS_LOCAL_WRITE = 1,
  631. IB_ACCESS_REMOTE_WRITE = (1<<1),
  632. IB_ACCESS_REMOTE_READ = (1<<2),
  633. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  634. IB_ACCESS_MW_BIND = (1<<4)
  635. };
  636. struct ib_phys_buf {
  637. u64 addr;
  638. u64 size;
  639. };
  640. struct ib_mr_attr {
  641. struct ib_pd *pd;
  642. u64 device_virt_addr;
  643. u64 size;
  644. int mr_access_flags;
  645. u32 lkey;
  646. u32 rkey;
  647. };
  648. enum ib_mr_rereg_flags {
  649. IB_MR_REREG_TRANS = 1,
  650. IB_MR_REREG_PD = (1<<1),
  651. IB_MR_REREG_ACCESS = (1<<2)
  652. };
  653. struct ib_mw_bind {
  654. struct ib_mr *mr;
  655. u64 wr_id;
  656. u64 addr;
  657. u32 length;
  658. int send_flags;
  659. int mw_access_flags;
  660. };
  661. struct ib_fmr_attr {
  662. int max_pages;
  663. int max_maps;
  664. u8 page_shift;
  665. };
  666. struct ib_ucontext {
  667. struct ib_device *device;
  668. struct list_head pd_list;
  669. struct list_head mr_list;
  670. struct list_head mw_list;
  671. struct list_head cq_list;
  672. struct list_head qp_list;
  673. struct list_head srq_list;
  674. struct list_head ah_list;
  675. int closing;
  676. };
  677. struct ib_uobject {
  678. u64 user_handle; /* handle given to us by userspace */
  679. struct ib_ucontext *context; /* associated user context */
  680. void *object; /* containing object */
  681. struct list_head list; /* link to context's list */
  682. int id; /* index into kernel idr */
  683. struct kref ref;
  684. struct rw_semaphore mutex; /* protects .live */
  685. int live;
  686. };
  687. struct ib_udata {
  688. void __user *inbuf;
  689. void __user *outbuf;
  690. size_t inlen;
  691. size_t outlen;
  692. };
  693. struct ib_pd {
  694. struct ib_device *device;
  695. struct ib_uobject *uobject;
  696. atomic_t usecnt; /* count all resources */
  697. };
  698. struct ib_ah {
  699. struct ib_device *device;
  700. struct ib_pd *pd;
  701. struct ib_uobject *uobject;
  702. };
  703. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  704. struct ib_cq {
  705. struct ib_device *device;
  706. struct ib_uobject *uobject;
  707. ib_comp_handler comp_handler;
  708. void (*event_handler)(struct ib_event *, void *);
  709. void * cq_context;
  710. int cqe;
  711. atomic_t usecnt; /* count number of work queues */
  712. };
  713. struct ib_srq {
  714. struct ib_device *device;
  715. struct ib_pd *pd;
  716. struct ib_uobject *uobject;
  717. void (*event_handler)(struct ib_event *, void *);
  718. void *srq_context;
  719. atomic_t usecnt;
  720. };
  721. struct ib_qp {
  722. struct ib_device *device;
  723. struct ib_pd *pd;
  724. struct ib_cq *send_cq;
  725. struct ib_cq *recv_cq;
  726. struct ib_srq *srq;
  727. struct ib_uobject *uobject;
  728. void (*event_handler)(struct ib_event *, void *);
  729. void *qp_context;
  730. u32 qp_num;
  731. enum ib_qp_type qp_type;
  732. };
  733. struct ib_mr {
  734. struct ib_device *device;
  735. struct ib_pd *pd;
  736. struct ib_uobject *uobject;
  737. u32 lkey;
  738. u32 rkey;
  739. atomic_t usecnt; /* count number of MWs */
  740. };
  741. struct ib_mw {
  742. struct ib_device *device;
  743. struct ib_pd *pd;
  744. struct ib_uobject *uobject;
  745. u32 rkey;
  746. };
  747. struct ib_fmr {
  748. struct ib_device *device;
  749. struct ib_pd *pd;
  750. struct list_head list;
  751. u32 lkey;
  752. u32 rkey;
  753. };
  754. struct ib_mad;
  755. struct ib_grh;
  756. enum ib_process_mad_flags {
  757. IB_MAD_IGNORE_MKEY = 1,
  758. IB_MAD_IGNORE_BKEY = 2,
  759. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  760. };
  761. enum ib_mad_result {
  762. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  763. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  764. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  765. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  766. };
  767. #define IB_DEVICE_NAME_MAX 64
  768. struct ib_cache {
  769. rwlock_t lock;
  770. struct ib_event_handler event_handler;
  771. struct ib_pkey_cache **pkey_cache;
  772. struct ib_gid_cache **gid_cache;
  773. u8 *lmc_cache;
  774. };
  775. struct ib_dma_mapping_ops {
  776. int (*mapping_error)(struct ib_device *dev,
  777. u64 dma_addr);
  778. u64 (*map_single)(struct ib_device *dev,
  779. void *ptr, size_t size,
  780. enum dma_data_direction direction);
  781. void (*unmap_single)(struct ib_device *dev,
  782. u64 addr, size_t size,
  783. enum dma_data_direction direction);
  784. u64 (*map_page)(struct ib_device *dev,
  785. struct page *page, unsigned long offset,
  786. size_t size,
  787. enum dma_data_direction direction);
  788. void (*unmap_page)(struct ib_device *dev,
  789. u64 addr, size_t size,
  790. enum dma_data_direction direction);
  791. int (*map_sg)(struct ib_device *dev,
  792. struct scatterlist *sg, int nents,
  793. enum dma_data_direction direction);
  794. void (*unmap_sg)(struct ib_device *dev,
  795. struct scatterlist *sg, int nents,
  796. enum dma_data_direction direction);
  797. u64 (*dma_address)(struct ib_device *dev,
  798. struct scatterlist *sg);
  799. unsigned int (*dma_len)(struct ib_device *dev,
  800. struct scatterlist *sg);
  801. void (*sync_single_for_cpu)(struct ib_device *dev,
  802. u64 dma_handle,
  803. size_t size,
  804. enum dma_data_direction dir);
  805. void (*sync_single_for_device)(struct ib_device *dev,
  806. u64 dma_handle,
  807. size_t size,
  808. enum dma_data_direction dir);
  809. void *(*alloc_coherent)(struct ib_device *dev,
  810. size_t size,
  811. u64 *dma_handle,
  812. gfp_t flag);
  813. void (*free_coherent)(struct ib_device *dev,
  814. size_t size, void *cpu_addr,
  815. u64 dma_handle);
  816. };
  817. struct iw_cm_verbs;
  818. struct ib_device {
  819. struct device *dma_device;
  820. char name[IB_DEVICE_NAME_MAX];
  821. struct list_head event_handler_list;
  822. spinlock_t event_handler_lock;
  823. struct list_head core_list;
  824. struct list_head client_data_list;
  825. spinlock_t client_data_lock;
  826. struct ib_cache cache;
  827. int *pkey_tbl_len;
  828. int *gid_tbl_len;
  829. int num_comp_vectors;
  830. struct iw_cm_verbs *iwcm;
  831. int (*query_device)(struct ib_device *device,
  832. struct ib_device_attr *device_attr);
  833. int (*query_port)(struct ib_device *device,
  834. u8 port_num,
  835. struct ib_port_attr *port_attr);
  836. int (*query_gid)(struct ib_device *device,
  837. u8 port_num, int index,
  838. union ib_gid *gid);
  839. int (*query_pkey)(struct ib_device *device,
  840. u8 port_num, u16 index, u16 *pkey);
  841. int (*modify_device)(struct ib_device *device,
  842. int device_modify_mask,
  843. struct ib_device_modify *device_modify);
  844. int (*modify_port)(struct ib_device *device,
  845. u8 port_num, int port_modify_mask,
  846. struct ib_port_modify *port_modify);
  847. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  848. struct ib_udata *udata);
  849. int (*dealloc_ucontext)(struct ib_ucontext *context);
  850. int (*mmap)(struct ib_ucontext *context,
  851. struct vm_area_struct *vma);
  852. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  853. struct ib_ucontext *context,
  854. struct ib_udata *udata);
  855. int (*dealloc_pd)(struct ib_pd *pd);
  856. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  857. struct ib_ah_attr *ah_attr);
  858. int (*modify_ah)(struct ib_ah *ah,
  859. struct ib_ah_attr *ah_attr);
  860. int (*query_ah)(struct ib_ah *ah,
  861. struct ib_ah_attr *ah_attr);
  862. int (*destroy_ah)(struct ib_ah *ah);
  863. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  864. struct ib_srq_init_attr *srq_init_attr,
  865. struct ib_udata *udata);
  866. int (*modify_srq)(struct ib_srq *srq,
  867. struct ib_srq_attr *srq_attr,
  868. enum ib_srq_attr_mask srq_attr_mask,
  869. struct ib_udata *udata);
  870. int (*query_srq)(struct ib_srq *srq,
  871. struct ib_srq_attr *srq_attr);
  872. int (*destroy_srq)(struct ib_srq *srq);
  873. int (*post_srq_recv)(struct ib_srq *srq,
  874. struct ib_recv_wr *recv_wr,
  875. struct ib_recv_wr **bad_recv_wr);
  876. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  877. struct ib_qp_init_attr *qp_init_attr,
  878. struct ib_udata *udata);
  879. int (*modify_qp)(struct ib_qp *qp,
  880. struct ib_qp_attr *qp_attr,
  881. int qp_attr_mask,
  882. struct ib_udata *udata);
  883. int (*query_qp)(struct ib_qp *qp,
  884. struct ib_qp_attr *qp_attr,
  885. int qp_attr_mask,
  886. struct ib_qp_init_attr *qp_init_attr);
  887. int (*destroy_qp)(struct ib_qp *qp);
  888. int (*post_send)(struct ib_qp *qp,
  889. struct ib_send_wr *send_wr,
  890. struct ib_send_wr **bad_send_wr);
  891. int (*post_recv)(struct ib_qp *qp,
  892. struct ib_recv_wr *recv_wr,
  893. struct ib_recv_wr **bad_recv_wr);
  894. struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
  895. int comp_vector,
  896. struct ib_ucontext *context,
  897. struct ib_udata *udata);
  898. int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
  899. u16 cq_period);
  900. int (*destroy_cq)(struct ib_cq *cq);
  901. int (*resize_cq)(struct ib_cq *cq, int cqe,
  902. struct ib_udata *udata);
  903. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  904. struct ib_wc *wc);
  905. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  906. int (*req_notify_cq)(struct ib_cq *cq,
  907. enum ib_cq_notify_flags flags);
  908. int (*req_ncomp_notif)(struct ib_cq *cq,
  909. int wc_cnt);
  910. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  911. int mr_access_flags);
  912. struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
  913. struct ib_phys_buf *phys_buf_array,
  914. int num_phys_buf,
  915. int mr_access_flags,
  916. u64 *iova_start);
  917. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  918. u64 start, u64 length,
  919. u64 virt_addr,
  920. int mr_access_flags,
  921. struct ib_udata *udata);
  922. int (*query_mr)(struct ib_mr *mr,
  923. struct ib_mr_attr *mr_attr);
  924. int (*dereg_mr)(struct ib_mr *mr);
  925. int (*rereg_phys_mr)(struct ib_mr *mr,
  926. int mr_rereg_mask,
  927. struct ib_pd *pd,
  928. struct ib_phys_buf *phys_buf_array,
  929. int num_phys_buf,
  930. int mr_access_flags,
  931. u64 *iova_start);
  932. struct ib_mw * (*alloc_mw)(struct ib_pd *pd);
  933. int (*bind_mw)(struct ib_qp *qp,
  934. struct ib_mw *mw,
  935. struct ib_mw_bind *mw_bind);
  936. int (*dealloc_mw)(struct ib_mw *mw);
  937. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  938. int mr_access_flags,
  939. struct ib_fmr_attr *fmr_attr);
  940. int (*map_phys_fmr)(struct ib_fmr *fmr,
  941. u64 *page_list, int list_len,
  942. u64 iova);
  943. int (*unmap_fmr)(struct list_head *fmr_list);
  944. int (*dealloc_fmr)(struct ib_fmr *fmr);
  945. int (*attach_mcast)(struct ib_qp *qp,
  946. union ib_gid *gid,
  947. u16 lid);
  948. int (*detach_mcast)(struct ib_qp *qp,
  949. union ib_gid *gid,
  950. u16 lid);
  951. int (*process_mad)(struct ib_device *device,
  952. int process_mad_flags,
  953. u8 port_num,
  954. struct ib_wc *in_wc,
  955. struct ib_grh *in_grh,
  956. struct ib_mad *in_mad,
  957. struct ib_mad *out_mad);
  958. struct ib_dma_mapping_ops *dma_ops;
  959. struct module *owner;
  960. struct device dev;
  961. struct kobject *ports_parent;
  962. struct list_head port_list;
  963. enum {
  964. IB_DEV_UNINITIALIZED,
  965. IB_DEV_REGISTERED,
  966. IB_DEV_UNREGISTERED
  967. } reg_state;
  968. u64 uverbs_cmd_mask;
  969. int uverbs_abi_ver;
  970. char node_desc[64];
  971. __be64 node_guid;
  972. u8 node_type;
  973. u8 phys_port_cnt;
  974. };
  975. struct ib_client {
  976. char *name;
  977. void (*add) (struct ib_device *);
  978. void (*remove)(struct ib_device *);
  979. struct list_head list;
  980. };
  981. struct ib_device *ib_alloc_device(size_t size);
  982. void ib_dealloc_device(struct ib_device *device);
  983. int ib_register_device (struct ib_device *device);
  984. void ib_unregister_device(struct ib_device *device);
  985. int ib_register_client (struct ib_client *client);
  986. void ib_unregister_client(struct ib_client *client);
  987. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  988. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  989. void *data);
  990. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  991. {
  992. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  993. }
  994. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  995. {
  996. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  997. }
  998. /**
  999. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  1000. * contains all required attributes and no attributes not allowed for
  1001. * the given QP state transition.
  1002. * @cur_state: Current QP state
  1003. * @next_state: Next QP state
  1004. * @type: QP type
  1005. * @mask: Mask of supplied QP attributes
  1006. *
  1007. * This function is a helper function that a low-level driver's
  1008. * modify_qp method can use to validate the consumer's input. It
  1009. * checks that cur_state and next_state are valid QP states, that a
  1010. * transition from cur_state to next_state is allowed by the IB spec,
  1011. * and that the attribute mask supplied is allowed for the transition.
  1012. */
  1013. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  1014. enum ib_qp_type type, enum ib_qp_attr_mask mask);
  1015. int ib_register_event_handler (struct ib_event_handler *event_handler);
  1016. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  1017. void ib_dispatch_event(struct ib_event *event);
  1018. int ib_query_device(struct ib_device *device,
  1019. struct ib_device_attr *device_attr);
  1020. int ib_query_port(struct ib_device *device,
  1021. u8 port_num, struct ib_port_attr *port_attr);
  1022. int ib_query_gid(struct ib_device *device,
  1023. u8 port_num, int index, union ib_gid *gid);
  1024. int ib_query_pkey(struct ib_device *device,
  1025. u8 port_num, u16 index, u16 *pkey);
  1026. int ib_modify_device(struct ib_device *device,
  1027. int device_modify_mask,
  1028. struct ib_device_modify *device_modify);
  1029. int ib_modify_port(struct ib_device *device,
  1030. u8 port_num, int port_modify_mask,
  1031. struct ib_port_modify *port_modify);
  1032. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  1033. u8 *port_num, u16 *index);
  1034. int ib_find_pkey(struct ib_device *device,
  1035. u8 port_num, u16 pkey, u16 *index);
  1036. /**
  1037. * ib_alloc_pd - Allocates an unused protection domain.
  1038. * @device: The device on which to allocate the protection domain.
  1039. *
  1040. * A protection domain object provides an association between QPs, shared
  1041. * receive queues, address handles, memory regions, and memory windows.
  1042. */
  1043. struct ib_pd *ib_alloc_pd(struct ib_device *device);
  1044. /**
  1045. * ib_dealloc_pd - Deallocates a protection domain.
  1046. * @pd: The protection domain to deallocate.
  1047. */
  1048. int ib_dealloc_pd(struct ib_pd *pd);
  1049. /**
  1050. * ib_create_ah - Creates an address handle for the given address vector.
  1051. * @pd: The protection domain associated with the address handle.
  1052. * @ah_attr: The attributes of the address vector.
  1053. *
  1054. * The address handle is used to reference a local or global destination
  1055. * in all UD QP post sends.
  1056. */
  1057. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  1058. /**
  1059. * ib_init_ah_from_wc - Initializes address handle attributes from a
  1060. * work completion.
  1061. * @device: Device on which the received message arrived.
  1062. * @port_num: Port on which the received message arrived.
  1063. * @wc: Work completion associated with the received message.
  1064. * @grh: References the received global route header. This parameter is
  1065. * ignored unless the work completion indicates that the GRH is valid.
  1066. * @ah_attr: Returned attributes that can be used when creating an address
  1067. * handle for replying to the message.
  1068. */
  1069. int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
  1070. struct ib_grh *grh, struct ib_ah_attr *ah_attr);
  1071. /**
  1072. * ib_create_ah_from_wc - Creates an address handle associated with the
  1073. * sender of the specified work completion.
  1074. * @pd: The protection domain associated with the address handle.
  1075. * @wc: Work completion information associated with a received message.
  1076. * @grh: References the received global route header. This parameter is
  1077. * ignored unless the work completion indicates that the GRH is valid.
  1078. * @port_num: The outbound port number to associate with the address.
  1079. *
  1080. * The address handle is used to reference a local or global destination
  1081. * in all UD QP post sends.
  1082. */
  1083. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
  1084. struct ib_grh *grh, u8 port_num);
  1085. /**
  1086. * ib_modify_ah - Modifies the address vector associated with an address
  1087. * handle.
  1088. * @ah: The address handle to modify.
  1089. * @ah_attr: The new address vector attributes to associate with the
  1090. * address handle.
  1091. */
  1092. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1093. /**
  1094. * ib_query_ah - Queries the address vector associated with an address
  1095. * handle.
  1096. * @ah: The address handle to query.
  1097. * @ah_attr: The address vector attributes associated with the address
  1098. * handle.
  1099. */
  1100. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1101. /**
  1102. * ib_destroy_ah - Destroys an address handle.
  1103. * @ah: The address handle to destroy.
  1104. */
  1105. int ib_destroy_ah(struct ib_ah *ah);
  1106. /**
  1107. * ib_create_srq - Creates a SRQ associated with the specified protection
  1108. * domain.
  1109. * @pd: The protection domain associated with the SRQ.
  1110. * @srq_init_attr: A list of initial attributes required to create the
  1111. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  1112. * the actual capabilities of the created SRQ.
  1113. *
  1114. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  1115. * requested size of the SRQ, and set to the actual values allocated
  1116. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  1117. * will always be at least as large as the requested values.
  1118. */
  1119. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  1120. struct ib_srq_init_attr *srq_init_attr);
  1121. /**
  1122. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  1123. * @srq: The SRQ to modify.
  1124. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  1125. * the current values of selected SRQ attributes are returned.
  1126. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  1127. * are being modified.
  1128. *
  1129. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  1130. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  1131. * the number of receives queued drops below the limit.
  1132. */
  1133. int ib_modify_srq(struct ib_srq *srq,
  1134. struct ib_srq_attr *srq_attr,
  1135. enum ib_srq_attr_mask srq_attr_mask);
  1136. /**
  1137. * ib_query_srq - Returns the attribute list and current values for the
  1138. * specified SRQ.
  1139. * @srq: The SRQ to query.
  1140. * @srq_attr: The attributes of the specified SRQ.
  1141. */
  1142. int ib_query_srq(struct ib_srq *srq,
  1143. struct ib_srq_attr *srq_attr);
  1144. /**
  1145. * ib_destroy_srq - Destroys the specified SRQ.
  1146. * @srq: The SRQ to destroy.
  1147. */
  1148. int ib_destroy_srq(struct ib_srq *srq);
  1149. /**
  1150. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  1151. * @srq: The SRQ to post the work request on.
  1152. * @recv_wr: A list of work requests to post on the receive queue.
  1153. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1154. * the work request that failed to be posted on the QP.
  1155. */
  1156. static inline int ib_post_srq_recv(struct ib_srq *srq,
  1157. struct ib_recv_wr *recv_wr,
  1158. struct ib_recv_wr **bad_recv_wr)
  1159. {
  1160. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  1161. }
  1162. /**
  1163. * ib_create_qp - Creates a QP associated with the specified protection
  1164. * domain.
  1165. * @pd: The protection domain associated with the QP.
  1166. * @qp_init_attr: A list of initial attributes required to create the
  1167. * QP. If QP creation succeeds, then the attributes are updated to
  1168. * the actual capabilities of the created QP.
  1169. */
  1170. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  1171. struct ib_qp_init_attr *qp_init_attr);
  1172. /**
  1173. * ib_modify_qp - Modifies the attributes for the specified QP and then
  1174. * transitions the QP to the given state.
  1175. * @qp: The QP to modify.
  1176. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  1177. * the current values of selected QP attributes are returned.
  1178. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  1179. * are being modified.
  1180. */
  1181. int ib_modify_qp(struct ib_qp *qp,
  1182. struct ib_qp_attr *qp_attr,
  1183. int qp_attr_mask);
  1184. /**
  1185. * ib_query_qp - Returns the attribute list and current values for the
  1186. * specified QP.
  1187. * @qp: The QP to query.
  1188. * @qp_attr: The attributes of the specified QP.
  1189. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  1190. * @qp_init_attr: Additional attributes of the selected QP.
  1191. *
  1192. * The qp_attr_mask may be used to limit the query to gathering only the
  1193. * selected attributes.
  1194. */
  1195. int ib_query_qp(struct ib_qp *qp,
  1196. struct ib_qp_attr *qp_attr,
  1197. int qp_attr_mask,
  1198. struct ib_qp_init_attr *qp_init_attr);
  1199. /**
  1200. * ib_destroy_qp - Destroys the specified QP.
  1201. * @qp: The QP to destroy.
  1202. */
  1203. int ib_destroy_qp(struct ib_qp *qp);
  1204. /**
  1205. * ib_post_send - Posts a list of work requests to the send queue of
  1206. * the specified QP.
  1207. * @qp: The QP to post the work request on.
  1208. * @send_wr: A list of work requests to post on the send queue.
  1209. * @bad_send_wr: On an immediate failure, this parameter will reference
  1210. * the work request that failed to be posted on the QP.
  1211. */
  1212. static inline int ib_post_send(struct ib_qp *qp,
  1213. struct ib_send_wr *send_wr,
  1214. struct ib_send_wr **bad_send_wr)
  1215. {
  1216. return qp->device->post_send(qp, send_wr, bad_send_wr);
  1217. }
  1218. /**
  1219. * ib_post_recv - Posts a list of work requests to the receive queue of
  1220. * the specified QP.
  1221. * @qp: The QP to post the work request on.
  1222. * @recv_wr: A list of work requests to post on the receive queue.
  1223. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1224. * the work request that failed to be posted on the QP.
  1225. */
  1226. static inline int ib_post_recv(struct ib_qp *qp,
  1227. struct ib_recv_wr *recv_wr,
  1228. struct ib_recv_wr **bad_recv_wr)
  1229. {
  1230. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  1231. }
  1232. /**
  1233. * ib_create_cq - Creates a CQ on the specified device.
  1234. * @device: The device on which to create the CQ.
  1235. * @comp_handler: A user-specified callback that is invoked when a
  1236. * completion event occurs on the CQ.
  1237. * @event_handler: A user-specified callback that is invoked when an
  1238. * asynchronous event not associated with a completion occurs on the CQ.
  1239. * @cq_context: Context associated with the CQ returned to the user via
  1240. * the associated completion and event handlers.
  1241. * @cqe: The minimum size of the CQ.
  1242. * @comp_vector - Completion vector used to signal completion events.
  1243. * Must be >= 0 and < context->num_comp_vectors.
  1244. *
  1245. * Users can examine the cq structure to determine the actual CQ size.
  1246. */
  1247. struct ib_cq *ib_create_cq(struct ib_device *device,
  1248. ib_comp_handler comp_handler,
  1249. void (*event_handler)(struct ib_event *, void *),
  1250. void *cq_context, int cqe, int comp_vector);
  1251. /**
  1252. * ib_resize_cq - Modifies the capacity of the CQ.
  1253. * @cq: The CQ to resize.
  1254. * @cqe: The minimum size of the CQ.
  1255. *
  1256. * Users can examine the cq structure to determine the actual CQ size.
  1257. */
  1258. int ib_resize_cq(struct ib_cq *cq, int cqe);
  1259. /**
  1260. * ib_modify_cq - Modifies moderation params of the CQ
  1261. * @cq: The CQ to modify.
  1262. * @cq_count: number of CQEs that will trigger an event
  1263. * @cq_period: max period of time in usec before triggering an event
  1264. *
  1265. */
  1266. int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  1267. /**
  1268. * ib_destroy_cq - Destroys the specified CQ.
  1269. * @cq: The CQ to destroy.
  1270. */
  1271. int ib_destroy_cq(struct ib_cq *cq);
  1272. /**
  1273. * ib_poll_cq - poll a CQ for completion(s)
  1274. * @cq:the CQ being polled
  1275. * @num_entries:maximum number of completions to return
  1276. * @wc:array of at least @num_entries &struct ib_wc where completions
  1277. * will be returned
  1278. *
  1279. * Poll a CQ for (possibly multiple) completions. If the return value
  1280. * is < 0, an error occurred. If the return value is >= 0, it is the
  1281. * number of completions returned. If the return value is
  1282. * non-negative and < num_entries, then the CQ was emptied.
  1283. */
  1284. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  1285. struct ib_wc *wc)
  1286. {
  1287. return cq->device->poll_cq(cq, num_entries, wc);
  1288. }
  1289. /**
  1290. * ib_peek_cq - Returns the number of unreaped completions currently
  1291. * on the specified CQ.
  1292. * @cq: The CQ to peek.
  1293. * @wc_cnt: A minimum number of unreaped completions to check for.
  1294. *
  1295. * If the number of unreaped completions is greater than or equal to wc_cnt,
  1296. * this function returns wc_cnt, otherwise, it returns the actual number of
  1297. * unreaped completions.
  1298. */
  1299. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  1300. /**
  1301. * ib_req_notify_cq - Request completion notification on a CQ.
  1302. * @cq: The CQ to generate an event for.
  1303. * @flags:
  1304. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  1305. * to request an event on the next solicited event or next work
  1306. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  1307. * may also be |ed in to request a hint about missed events, as
  1308. * described below.
  1309. *
  1310. * Return Value:
  1311. * < 0 means an error occurred while requesting notification
  1312. * == 0 means notification was requested successfully, and if
  1313. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  1314. * were missed and it is safe to wait for another event. In
  1315. * this case is it guaranteed that any work completions added
  1316. * to the CQ since the last CQ poll will trigger a completion
  1317. * notification event.
  1318. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  1319. * in. It means that the consumer must poll the CQ again to
  1320. * make sure it is empty to avoid missing an event because of a
  1321. * race between requesting notification and an entry being
  1322. * added to the CQ. This return value means it is possible
  1323. * (but not guaranteed) that a work completion has been added
  1324. * to the CQ since the last poll without triggering a
  1325. * completion notification event.
  1326. */
  1327. static inline int ib_req_notify_cq(struct ib_cq *cq,
  1328. enum ib_cq_notify_flags flags)
  1329. {
  1330. return cq->device->req_notify_cq(cq, flags);
  1331. }
  1332. /**
  1333. * ib_req_ncomp_notif - Request completion notification when there are
  1334. * at least the specified number of unreaped completions on the CQ.
  1335. * @cq: The CQ to generate an event for.
  1336. * @wc_cnt: The number of unreaped completions that should be on the
  1337. * CQ before an event is generated.
  1338. */
  1339. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  1340. {
  1341. return cq->device->req_ncomp_notif ?
  1342. cq->device->req_ncomp_notif(cq, wc_cnt) :
  1343. -ENOSYS;
  1344. }
  1345. /**
  1346. * ib_get_dma_mr - Returns a memory region for system memory that is
  1347. * usable for DMA.
  1348. * @pd: The protection domain associated with the memory region.
  1349. * @mr_access_flags: Specifies the memory access rights.
  1350. *
  1351. * Note that the ib_dma_*() functions defined below must be used
  1352. * to create/destroy addresses used with the Lkey or Rkey returned
  1353. * by ib_get_dma_mr().
  1354. */
  1355. struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
  1356. /**
  1357. * ib_dma_mapping_error - check a DMA addr for error
  1358. * @dev: The device for which the dma_addr was created
  1359. * @dma_addr: The DMA address to check
  1360. */
  1361. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  1362. {
  1363. if (dev->dma_ops)
  1364. return dev->dma_ops->mapping_error(dev, dma_addr);
  1365. return dma_mapping_error(dma_addr);
  1366. }
  1367. /**
  1368. * ib_dma_map_single - Map a kernel virtual address to DMA address
  1369. * @dev: The device for which the dma_addr is to be created
  1370. * @cpu_addr: The kernel virtual address
  1371. * @size: The size of the region in bytes
  1372. * @direction: The direction of the DMA
  1373. */
  1374. static inline u64 ib_dma_map_single(struct ib_device *dev,
  1375. void *cpu_addr, size_t size,
  1376. enum dma_data_direction direction)
  1377. {
  1378. if (dev->dma_ops)
  1379. return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
  1380. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  1381. }
  1382. /**
  1383. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  1384. * @dev: The device for which the DMA address was created
  1385. * @addr: The DMA address
  1386. * @size: The size of the region in bytes
  1387. * @direction: The direction of the DMA
  1388. */
  1389. static inline void ib_dma_unmap_single(struct ib_device *dev,
  1390. u64 addr, size_t size,
  1391. enum dma_data_direction direction)
  1392. {
  1393. if (dev->dma_ops)
  1394. dev->dma_ops->unmap_single(dev, addr, size, direction);
  1395. else
  1396. dma_unmap_single(dev->dma_device, addr, size, direction);
  1397. }
  1398. static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
  1399. void *cpu_addr, size_t size,
  1400. enum dma_data_direction direction,
  1401. struct dma_attrs *attrs)
  1402. {
  1403. return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
  1404. direction, attrs);
  1405. }
  1406. static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
  1407. u64 addr, size_t size,
  1408. enum dma_data_direction direction,
  1409. struct dma_attrs *attrs)
  1410. {
  1411. return dma_unmap_single_attrs(dev->dma_device, addr, size,
  1412. direction, attrs);
  1413. }
  1414. /**
  1415. * ib_dma_map_page - Map a physical page to DMA address
  1416. * @dev: The device for which the dma_addr is to be created
  1417. * @page: The page to be mapped
  1418. * @offset: The offset within the page
  1419. * @size: The size of the region in bytes
  1420. * @direction: The direction of the DMA
  1421. */
  1422. static inline u64 ib_dma_map_page(struct ib_device *dev,
  1423. struct page *page,
  1424. unsigned long offset,
  1425. size_t size,
  1426. enum dma_data_direction direction)
  1427. {
  1428. if (dev->dma_ops)
  1429. return dev->dma_ops->map_page(dev, page, offset, size, direction);
  1430. return dma_map_page(dev->dma_device, page, offset, size, direction);
  1431. }
  1432. /**
  1433. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  1434. * @dev: The device for which the DMA address was created
  1435. * @addr: The DMA address
  1436. * @size: The size of the region in bytes
  1437. * @direction: The direction of the DMA
  1438. */
  1439. static inline void ib_dma_unmap_page(struct ib_device *dev,
  1440. u64 addr, size_t size,
  1441. enum dma_data_direction direction)
  1442. {
  1443. if (dev->dma_ops)
  1444. dev->dma_ops->unmap_page(dev, addr, size, direction);
  1445. else
  1446. dma_unmap_page(dev->dma_device, addr, size, direction);
  1447. }
  1448. /**
  1449. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  1450. * @dev: The device for which the DMA addresses are to be created
  1451. * @sg: The array of scatter/gather entries
  1452. * @nents: The number of scatter/gather entries
  1453. * @direction: The direction of the DMA
  1454. */
  1455. static inline int ib_dma_map_sg(struct ib_device *dev,
  1456. struct scatterlist *sg, int nents,
  1457. enum dma_data_direction direction)
  1458. {
  1459. if (dev->dma_ops)
  1460. return dev->dma_ops->map_sg(dev, sg, nents, direction);
  1461. return dma_map_sg(dev->dma_device, sg, nents, direction);
  1462. }
  1463. /**
  1464. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  1465. * @dev: The device for which the DMA addresses were created
  1466. * @sg: The array of scatter/gather entries
  1467. * @nents: The number of scatter/gather entries
  1468. * @direction: The direction of the DMA
  1469. */
  1470. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  1471. struct scatterlist *sg, int nents,
  1472. enum dma_data_direction direction)
  1473. {
  1474. if (dev->dma_ops)
  1475. dev->dma_ops->unmap_sg(dev, sg, nents, direction);
  1476. else
  1477. dma_unmap_sg(dev->dma_device, sg, nents, direction);
  1478. }
  1479. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  1480. struct scatterlist *sg, int nents,
  1481. enum dma_data_direction direction,
  1482. struct dma_attrs *attrs)
  1483. {
  1484. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  1485. }
  1486. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  1487. struct scatterlist *sg, int nents,
  1488. enum dma_data_direction direction,
  1489. struct dma_attrs *attrs)
  1490. {
  1491. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  1492. }
  1493. /**
  1494. * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
  1495. * @dev: The device for which the DMA addresses were created
  1496. * @sg: The scatter/gather entry
  1497. */
  1498. static inline u64 ib_sg_dma_address(struct ib_device *dev,
  1499. struct scatterlist *sg)
  1500. {
  1501. if (dev->dma_ops)
  1502. return dev->dma_ops->dma_address(dev, sg);
  1503. return sg_dma_address(sg);
  1504. }
  1505. /**
  1506. * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
  1507. * @dev: The device for which the DMA addresses were created
  1508. * @sg: The scatter/gather entry
  1509. */
  1510. static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
  1511. struct scatterlist *sg)
  1512. {
  1513. if (dev->dma_ops)
  1514. return dev->dma_ops->dma_len(dev, sg);
  1515. return sg_dma_len(sg);
  1516. }
  1517. /**
  1518. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  1519. * @dev: The device for which the DMA address was created
  1520. * @addr: The DMA address
  1521. * @size: The size of the region in bytes
  1522. * @dir: The direction of the DMA
  1523. */
  1524. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  1525. u64 addr,
  1526. size_t size,
  1527. enum dma_data_direction dir)
  1528. {
  1529. if (dev->dma_ops)
  1530. dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
  1531. else
  1532. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  1533. }
  1534. /**
  1535. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  1536. * @dev: The device for which the DMA address was created
  1537. * @addr: The DMA address
  1538. * @size: The size of the region in bytes
  1539. * @dir: The direction of the DMA
  1540. */
  1541. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  1542. u64 addr,
  1543. size_t size,
  1544. enum dma_data_direction dir)
  1545. {
  1546. if (dev->dma_ops)
  1547. dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
  1548. else
  1549. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  1550. }
  1551. /**
  1552. * ib_dma_alloc_coherent - Allocate memory and map it for DMA
  1553. * @dev: The device for which the DMA address is requested
  1554. * @size: The size of the region to allocate in bytes
  1555. * @dma_handle: A pointer for returning the DMA address of the region
  1556. * @flag: memory allocator flags
  1557. */
  1558. static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
  1559. size_t size,
  1560. u64 *dma_handle,
  1561. gfp_t flag)
  1562. {
  1563. if (dev->dma_ops)
  1564. return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  1565. else {
  1566. dma_addr_t handle;
  1567. void *ret;
  1568. ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
  1569. *dma_handle = handle;
  1570. return ret;
  1571. }
  1572. }
  1573. /**
  1574. * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
  1575. * @dev: The device for which the DMA addresses were allocated
  1576. * @size: The size of the region
  1577. * @cpu_addr: the address returned by ib_dma_alloc_coherent()
  1578. * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
  1579. */
  1580. static inline void ib_dma_free_coherent(struct ib_device *dev,
  1581. size_t size, void *cpu_addr,
  1582. u64 dma_handle)
  1583. {
  1584. if (dev->dma_ops)
  1585. dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  1586. else
  1587. dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
  1588. }
  1589. /**
  1590. * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
  1591. * by an HCA.
  1592. * @pd: The protection domain associated assigned to the registered region.
  1593. * @phys_buf_array: Specifies a list of physical buffers to use in the
  1594. * memory region.
  1595. * @num_phys_buf: Specifies the size of the phys_buf_array.
  1596. * @mr_access_flags: Specifies the memory access rights.
  1597. * @iova_start: The offset of the region's starting I/O virtual address.
  1598. */
  1599. struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
  1600. struct ib_phys_buf *phys_buf_array,
  1601. int num_phys_buf,
  1602. int mr_access_flags,
  1603. u64 *iova_start);
  1604. /**
  1605. * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
  1606. * Conceptually, this call performs the functions deregister memory region
  1607. * followed by register physical memory region. Where possible,
  1608. * resources are reused instead of deallocated and reallocated.
  1609. * @mr: The memory region to modify.
  1610. * @mr_rereg_mask: A bit-mask used to indicate which of the following
  1611. * properties of the memory region are being modified.
  1612. * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
  1613. * the new protection domain to associated with the memory region,
  1614. * otherwise, this parameter is ignored.
  1615. * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1616. * field specifies a list of physical buffers to use in the new
  1617. * translation, otherwise, this parameter is ignored.
  1618. * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1619. * field specifies the size of the phys_buf_array, otherwise, this
  1620. * parameter is ignored.
  1621. * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
  1622. * field specifies the new memory access rights, otherwise, this
  1623. * parameter is ignored.
  1624. * @iova_start: The offset of the region's starting I/O virtual address.
  1625. */
  1626. int ib_rereg_phys_mr(struct ib_mr *mr,
  1627. int mr_rereg_mask,
  1628. struct ib_pd *pd,
  1629. struct ib_phys_buf *phys_buf_array,
  1630. int num_phys_buf,
  1631. int mr_access_flags,
  1632. u64 *iova_start);
  1633. /**
  1634. * ib_query_mr - Retrieves information about a specific memory region.
  1635. * @mr: The memory region to retrieve information about.
  1636. * @mr_attr: The attributes of the specified memory region.
  1637. */
  1638. int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
  1639. /**
  1640. * ib_dereg_mr - Deregisters a memory region and removes it from the
  1641. * HCA translation table.
  1642. * @mr: The memory region to deregister.
  1643. */
  1644. int ib_dereg_mr(struct ib_mr *mr);
  1645. /**
  1646. * ib_alloc_mw - Allocates a memory window.
  1647. * @pd: The protection domain associated with the memory window.
  1648. */
  1649. struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
  1650. /**
  1651. * ib_bind_mw - Posts a work request to the send queue of the specified
  1652. * QP, which binds the memory window to the given address range and
  1653. * remote access attributes.
  1654. * @qp: QP to post the bind work request on.
  1655. * @mw: The memory window to bind.
  1656. * @mw_bind: Specifies information about the memory window, including
  1657. * its address range, remote access rights, and associated memory region.
  1658. */
  1659. static inline int ib_bind_mw(struct ib_qp *qp,
  1660. struct ib_mw *mw,
  1661. struct ib_mw_bind *mw_bind)
  1662. {
  1663. /* XXX reference counting in corresponding MR? */
  1664. return mw->device->bind_mw ?
  1665. mw->device->bind_mw(qp, mw, mw_bind) :
  1666. -ENOSYS;
  1667. }
  1668. /**
  1669. * ib_dealloc_mw - Deallocates a memory window.
  1670. * @mw: The memory window to deallocate.
  1671. */
  1672. int ib_dealloc_mw(struct ib_mw *mw);
  1673. /**
  1674. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  1675. * @pd: The protection domain associated with the unmapped region.
  1676. * @mr_access_flags: Specifies the memory access rights.
  1677. * @fmr_attr: Attributes of the unmapped region.
  1678. *
  1679. * A fast memory region must be mapped before it can be used as part of
  1680. * a work request.
  1681. */
  1682. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  1683. int mr_access_flags,
  1684. struct ib_fmr_attr *fmr_attr);
  1685. /**
  1686. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  1687. * @fmr: The fast memory region to associate with the pages.
  1688. * @page_list: An array of physical pages to map to the fast memory region.
  1689. * @list_len: The number of pages in page_list.
  1690. * @iova: The I/O virtual address to use with the mapped region.
  1691. */
  1692. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  1693. u64 *page_list, int list_len,
  1694. u64 iova)
  1695. {
  1696. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  1697. }
  1698. /**
  1699. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  1700. * @fmr_list: A linked list of fast memory regions to unmap.
  1701. */
  1702. int ib_unmap_fmr(struct list_head *fmr_list);
  1703. /**
  1704. * ib_dealloc_fmr - Deallocates a fast memory region.
  1705. * @fmr: The fast memory region to deallocate.
  1706. */
  1707. int ib_dealloc_fmr(struct ib_fmr *fmr);
  1708. /**
  1709. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  1710. * @qp: QP to attach to the multicast group. The QP must be type
  1711. * IB_QPT_UD.
  1712. * @gid: Multicast group GID.
  1713. * @lid: Multicast group LID in host byte order.
  1714. *
  1715. * In order to send and receive multicast packets, subnet
  1716. * administration must have created the multicast group and configured
  1717. * the fabric appropriately. The port associated with the specified
  1718. * QP must also be a member of the multicast group.
  1719. */
  1720. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1721. /**
  1722. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  1723. * @qp: QP to detach from the multicast group.
  1724. * @gid: Multicast group GID.
  1725. * @lid: Multicast group LID in host byte order.
  1726. */
  1727. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1728. #endif /* IB_VERBS_H */