ib_verbs.h 63 KB

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