ib_verbs.h 69 KB

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