ib_verbs.h 59 KB

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