ib_verbs.h 74 KB

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