ib_verbs.h 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377
  1. /*
  2. * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
  4. * Copyright (c) 2004 Intel Corporation. All rights reserved.
  5. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  6. * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
  7. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  8. * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
  9. *
  10. * This software is available to you under a choice of one of two
  11. * licenses. You may choose to be licensed under the terms of the GNU
  12. * General Public License (GPL) Version 2, available from the file
  13. * COPYING in the main directory of this source tree, or the
  14. * OpenIB.org BSD license below:
  15. *
  16. * Redistribution and use in source and binary forms, with or
  17. * without modification, are permitted provided that the following
  18. * conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer.
  23. *
  24. * - Redistributions in binary form must reproduce the above
  25. * copyright notice, this list of conditions and the following
  26. * disclaimer in the documentation and/or other materials
  27. * provided with the distribution.
  28. *
  29. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  33. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  34. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  36. * SOFTWARE.
  37. */
  38. #if !defined(IB_VERBS_H)
  39. #define IB_VERBS_H
  40. #include <linux/types.h>
  41. #include <linux/device.h>
  42. #include <linux/mm.h>
  43. #include <linux/dma-mapping.h>
  44. #include <linux/kref.h>
  45. #include <linux/list.h>
  46. #include <linux/rwsem.h>
  47. #include <linux/scatterlist.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/socket.h>
  50. #include <linux/irq_poll.h>
  51. #include <uapi/linux/if_ether.h>
  52. #include <net/ipv6.h>
  53. #include <net/ip.h>
  54. #include <linux/string.h>
  55. #include <linux/slab.h>
  56. #include <linux/if_link.h>
  57. #include <linux/atomic.h>
  58. #include <linux/mmu_notifier.h>
  59. #include <asm/uaccess.h>
  60. extern struct workqueue_struct *ib_wq;
  61. extern struct workqueue_struct *ib_comp_wq;
  62. extern struct workqueue_struct *ib_comp_unbound_wq;
  63. union ib_gid {
  64. u8 raw[16];
  65. struct {
  66. __be64 subnet_prefix;
  67. __be64 interface_id;
  68. } global;
  69. };
  70. extern union ib_gid zgid;
  71. enum ib_gid_type {
  72. /* If link layer is Ethernet, this is RoCE V1 */
  73. IB_GID_TYPE_IB = 0,
  74. IB_GID_TYPE_ROCE = 0,
  75. IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
  76. IB_GID_TYPE_SIZE
  77. };
  78. #define ROCE_V2_UDP_DPORT 4791
  79. struct ib_gid_attr {
  80. enum ib_gid_type gid_type;
  81. struct net_device *ndev;
  82. };
  83. enum rdma_node_type {
  84. /* IB values map to NodeInfo:NodeType. */
  85. RDMA_NODE_IB_CA = 1,
  86. RDMA_NODE_IB_SWITCH,
  87. RDMA_NODE_IB_ROUTER,
  88. RDMA_NODE_RNIC,
  89. RDMA_NODE_USNIC,
  90. RDMA_NODE_USNIC_UDP,
  91. };
  92. enum {
  93. /* set the local administered indication */
  94. IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2,
  95. };
  96. enum rdma_transport_type {
  97. RDMA_TRANSPORT_IB,
  98. RDMA_TRANSPORT_IWARP,
  99. RDMA_TRANSPORT_USNIC,
  100. RDMA_TRANSPORT_USNIC_UDP
  101. };
  102. enum rdma_protocol_type {
  103. RDMA_PROTOCOL_IB,
  104. RDMA_PROTOCOL_IBOE,
  105. RDMA_PROTOCOL_IWARP,
  106. RDMA_PROTOCOL_USNIC_UDP
  107. };
  108. __attribute_const__ enum rdma_transport_type
  109. rdma_node_get_transport(enum rdma_node_type node_type);
  110. enum rdma_network_type {
  111. RDMA_NETWORK_IB,
  112. RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
  113. RDMA_NETWORK_IPV4,
  114. RDMA_NETWORK_IPV6
  115. };
  116. static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
  117. {
  118. if (network_type == RDMA_NETWORK_IPV4 ||
  119. network_type == RDMA_NETWORK_IPV6)
  120. return IB_GID_TYPE_ROCE_UDP_ENCAP;
  121. /* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
  122. return IB_GID_TYPE_IB;
  123. }
  124. static inline enum rdma_network_type ib_gid_to_network_type(enum ib_gid_type gid_type,
  125. union ib_gid *gid)
  126. {
  127. if (gid_type == IB_GID_TYPE_IB)
  128. return RDMA_NETWORK_IB;
  129. if (ipv6_addr_v4mapped((struct in6_addr *)gid))
  130. return RDMA_NETWORK_IPV4;
  131. else
  132. return RDMA_NETWORK_IPV6;
  133. }
  134. enum rdma_link_layer {
  135. IB_LINK_LAYER_UNSPECIFIED,
  136. IB_LINK_LAYER_INFINIBAND,
  137. IB_LINK_LAYER_ETHERNET,
  138. };
  139. enum ib_device_cap_flags {
  140. IB_DEVICE_RESIZE_MAX_WR = (1 << 0),
  141. IB_DEVICE_BAD_PKEY_CNTR = (1 << 1),
  142. IB_DEVICE_BAD_QKEY_CNTR = (1 << 2),
  143. IB_DEVICE_RAW_MULTI = (1 << 3),
  144. IB_DEVICE_AUTO_PATH_MIG = (1 << 4),
  145. IB_DEVICE_CHANGE_PHY_PORT = (1 << 5),
  146. IB_DEVICE_UD_AV_PORT_ENFORCE = (1 << 6),
  147. IB_DEVICE_CURR_QP_STATE_MOD = (1 << 7),
  148. IB_DEVICE_SHUTDOWN_PORT = (1 << 8),
  149. IB_DEVICE_INIT_TYPE = (1 << 9),
  150. IB_DEVICE_PORT_ACTIVE_EVENT = (1 << 10),
  151. IB_DEVICE_SYS_IMAGE_GUID = (1 << 11),
  152. IB_DEVICE_RC_RNR_NAK_GEN = (1 << 12),
  153. IB_DEVICE_SRQ_RESIZE = (1 << 13),
  154. IB_DEVICE_N_NOTIFY_CQ = (1 << 14),
  155. /*
  156. * This device supports a per-device lkey or stag that can be
  157. * used without performing a memory registration for the local
  158. * memory. Note that ULPs should never check this flag, but
  159. * instead of use the local_dma_lkey flag in the ib_pd structure,
  160. * which will always contain a usable lkey.
  161. */
  162. IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15),
  163. IB_DEVICE_RESERVED /* old SEND_W_INV */ = (1 << 16),
  164. IB_DEVICE_MEM_WINDOW = (1 << 17),
  165. /*
  166. * Devices should set IB_DEVICE_UD_IP_SUM if they support
  167. * insertion of UDP and TCP checksum on outgoing UD IPoIB
  168. * messages and can verify the validity of checksum for
  169. * incoming messages. Setting this flag implies that the
  170. * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
  171. */
  172. IB_DEVICE_UD_IP_CSUM = (1 << 18),
  173. IB_DEVICE_UD_TSO = (1 << 19),
  174. IB_DEVICE_XRC = (1 << 20),
  175. /*
  176. * This device supports the IB "base memory management extension",
  177. * which includes support for fast registrations (IB_WR_REG_MR,
  178. * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs). This flag should
  179. * also be set by any iWarp device which must support FRs to comply
  180. * to the iWarp verbs spec. iWarp devices also support the
  181. * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
  182. * stag.
  183. */
  184. IB_DEVICE_MEM_MGT_EXTENSIONS = (1 << 21),
  185. IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1 << 22),
  186. IB_DEVICE_MEM_WINDOW_TYPE_2A = (1 << 23),
  187. IB_DEVICE_MEM_WINDOW_TYPE_2B = (1 << 24),
  188. IB_DEVICE_RC_IP_CSUM = (1 << 25),
  189. IB_DEVICE_RAW_IP_CSUM = (1 << 26),
  190. /*
  191. * Devices should set IB_DEVICE_CROSS_CHANNEL if they
  192. * support execution of WQEs that involve synchronization
  193. * of I/O operations with single completion queue managed
  194. * by hardware.
  195. */
  196. IB_DEVICE_CROSS_CHANNEL = (1 << 27),
  197. IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29),
  198. IB_DEVICE_SIGNATURE_HANDOVER = (1 << 30),
  199. IB_DEVICE_ON_DEMAND_PAGING = (1ULL << 31),
  200. IB_DEVICE_SG_GAPS_REG = (1ULL << 32),
  201. IB_DEVICE_VIRTUAL_FUNCTION = (1ULL << 33),
  202. IB_DEVICE_RAW_SCATTER_FCS = (1ULL << 34),
  203. };
  204. enum ib_signature_prot_cap {
  205. IB_PROT_T10DIF_TYPE_1 = 1,
  206. IB_PROT_T10DIF_TYPE_2 = 1 << 1,
  207. IB_PROT_T10DIF_TYPE_3 = 1 << 2,
  208. };
  209. enum ib_signature_guard_cap {
  210. IB_GUARD_T10DIF_CRC = 1,
  211. IB_GUARD_T10DIF_CSUM = 1 << 1,
  212. };
  213. enum ib_atomic_cap {
  214. IB_ATOMIC_NONE,
  215. IB_ATOMIC_HCA,
  216. IB_ATOMIC_GLOB
  217. };
  218. enum ib_odp_general_cap_bits {
  219. IB_ODP_SUPPORT = 1 << 0,
  220. };
  221. enum ib_odp_transport_cap_bits {
  222. IB_ODP_SUPPORT_SEND = 1 << 0,
  223. IB_ODP_SUPPORT_RECV = 1 << 1,
  224. IB_ODP_SUPPORT_WRITE = 1 << 2,
  225. IB_ODP_SUPPORT_READ = 1 << 3,
  226. IB_ODP_SUPPORT_ATOMIC = 1 << 4,
  227. };
  228. struct ib_odp_caps {
  229. uint64_t general_caps;
  230. struct {
  231. uint32_t rc_odp_caps;
  232. uint32_t uc_odp_caps;
  233. uint32_t ud_odp_caps;
  234. } per_transport_caps;
  235. };
  236. struct ib_rss_caps {
  237. /* Corresponding bit will be set if qp type from
  238. * 'enum ib_qp_type' is supported, e.g.
  239. * supported_qpts |= 1 << IB_QPT_UD
  240. */
  241. u32 supported_qpts;
  242. u32 max_rwq_indirection_tables;
  243. u32 max_rwq_indirection_table_size;
  244. };
  245. enum ib_cq_creation_flags {
  246. IB_CQ_FLAGS_TIMESTAMP_COMPLETION = 1 << 0,
  247. IB_CQ_FLAGS_IGNORE_OVERRUN = 1 << 1,
  248. };
  249. struct ib_cq_init_attr {
  250. unsigned int cqe;
  251. int comp_vector;
  252. u32 flags;
  253. };
  254. struct ib_device_attr {
  255. u64 fw_ver;
  256. __be64 sys_image_guid;
  257. u64 max_mr_size;
  258. u64 page_size_cap;
  259. u32 vendor_id;
  260. u32 vendor_part_id;
  261. u32 hw_ver;
  262. int max_qp;
  263. int max_qp_wr;
  264. u64 device_cap_flags;
  265. int max_sge;
  266. int max_sge_rd;
  267. int max_cq;
  268. int max_cqe;
  269. int max_mr;
  270. int max_pd;
  271. int max_qp_rd_atom;
  272. int max_ee_rd_atom;
  273. int max_res_rd_atom;
  274. int max_qp_init_rd_atom;
  275. int max_ee_init_rd_atom;
  276. enum ib_atomic_cap atomic_cap;
  277. enum ib_atomic_cap masked_atomic_cap;
  278. int max_ee;
  279. int max_rdd;
  280. int max_mw;
  281. int max_raw_ipv6_qp;
  282. int max_raw_ethy_qp;
  283. int max_mcast_grp;
  284. int max_mcast_qp_attach;
  285. int max_total_mcast_qp_attach;
  286. int max_ah;
  287. int max_fmr;
  288. int max_map_per_fmr;
  289. int max_srq;
  290. int max_srq_wr;
  291. int max_srq_sge;
  292. unsigned int max_fast_reg_page_list_len;
  293. u16 max_pkeys;
  294. u8 local_ca_ack_delay;
  295. int sig_prot_cap;
  296. int sig_guard_cap;
  297. struct ib_odp_caps odp_caps;
  298. uint64_t timestamp_mask;
  299. uint64_t hca_core_clock; /* in KHZ */
  300. struct ib_rss_caps rss_caps;
  301. u32 max_wq_type_rq;
  302. };
  303. enum ib_mtu {
  304. IB_MTU_256 = 1,
  305. IB_MTU_512 = 2,
  306. IB_MTU_1024 = 3,
  307. IB_MTU_2048 = 4,
  308. IB_MTU_4096 = 5
  309. };
  310. static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
  311. {
  312. switch (mtu) {
  313. case IB_MTU_256: return 256;
  314. case IB_MTU_512: return 512;
  315. case IB_MTU_1024: return 1024;
  316. case IB_MTU_2048: return 2048;
  317. case IB_MTU_4096: return 4096;
  318. default: return -1;
  319. }
  320. }
  321. enum ib_port_state {
  322. IB_PORT_NOP = 0,
  323. IB_PORT_DOWN = 1,
  324. IB_PORT_INIT = 2,
  325. IB_PORT_ARMED = 3,
  326. IB_PORT_ACTIVE = 4,
  327. IB_PORT_ACTIVE_DEFER = 5
  328. };
  329. enum ib_port_cap_flags {
  330. IB_PORT_SM = 1 << 1,
  331. IB_PORT_NOTICE_SUP = 1 << 2,
  332. IB_PORT_TRAP_SUP = 1 << 3,
  333. IB_PORT_OPT_IPD_SUP = 1 << 4,
  334. IB_PORT_AUTO_MIGR_SUP = 1 << 5,
  335. IB_PORT_SL_MAP_SUP = 1 << 6,
  336. IB_PORT_MKEY_NVRAM = 1 << 7,
  337. IB_PORT_PKEY_NVRAM = 1 << 8,
  338. IB_PORT_LED_INFO_SUP = 1 << 9,
  339. IB_PORT_SM_DISABLED = 1 << 10,
  340. IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  341. IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  342. IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
  343. IB_PORT_CM_SUP = 1 << 16,
  344. IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  345. IB_PORT_REINIT_SUP = 1 << 18,
  346. IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
  347. IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
  348. IB_PORT_DR_NOTICE_SUP = 1 << 21,
  349. IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  350. IB_PORT_BOOT_MGMT_SUP = 1 << 23,
  351. IB_PORT_LINK_LATENCY_SUP = 1 << 24,
  352. IB_PORT_CLIENT_REG_SUP = 1 << 25,
  353. IB_PORT_IP_BASED_GIDS = 1 << 26,
  354. };
  355. enum ib_port_width {
  356. IB_WIDTH_1X = 1,
  357. IB_WIDTH_4X = 2,
  358. IB_WIDTH_8X = 4,
  359. IB_WIDTH_12X = 8
  360. };
  361. static inline int ib_width_enum_to_int(enum ib_port_width width)
  362. {
  363. switch (width) {
  364. case IB_WIDTH_1X: return 1;
  365. case IB_WIDTH_4X: return 4;
  366. case IB_WIDTH_8X: return 8;
  367. case IB_WIDTH_12X: return 12;
  368. default: return -1;
  369. }
  370. }
  371. enum ib_port_speed {
  372. IB_SPEED_SDR = 1,
  373. IB_SPEED_DDR = 2,
  374. IB_SPEED_QDR = 4,
  375. IB_SPEED_FDR10 = 8,
  376. IB_SPEED_FDR = 16,
  377. IB_SPEED_EDR = 32
  378. };
  379. /**
  380. * struct rdma_hw_stats
  381. * @timestamp - Used by the core code to track when the last update was
  382. * @lifespan - Used by the core code to determine how old the counters
  383. * should be before being updated again. Stored in jiffies, defaults
  384. * to 10 milliseconds, drivers can override the default be specifying
  385. * their own value during their allocation routine.
  386. * @name - Array of pointers to static names used for the counters in
  387. * directory.
  388. * @num_counters - How many hardware counters there are. If name is
  389. * shorter than this number, a kernel oops will result. Driver authors
  390. * are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
  391. * in their code to prevent this.
  392. * @value - Array of u64 counters that are accessed by the sysfs code and
  393. * filled in by the drivers get_stats routine
  394. */
  395. struct rdma_hw_stats {
  396. unsigned long timestamp;
  397. unsigned long lifespan;
  398. const char * const *names;
  399. int num_counters;
  400. u64 value[];
  401. };
  402. #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
  403. /**
  404. * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
  405. * for drivers.
  406. * @names - Array of static const char *
  407. * @num_counters - How many elements in array
  408. * @lifespan - How many milliseconds between updates
  409. */
  410. static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
  411. const char * const *names, int num_counters,
  412. unsigned long lifespan)
  413. {
  414. struct rdma_hw_stats *stats;
  415. stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
  416. GFP_KERNEL);
  417. if (!stats)
  418. return NULL;
  419. stats->names = names;
  420. stats->num_counters = num_counters;
  421. stats->lifespan = msecs_to_jiffies(lifespan);
  422. return stats;
  423. }
  424. /* Define bits for the various functionality this port needs to be supported by
  425. * the core.
  426. */
  427. /* Management 0x00000FFF */
  428. #define RDMA_CORE_CAP_IB_MAD 0x00000001
  429. #define RDMA_CORE_CAP_IB_SMI 0x00000002
  430. #define RDMA_CORE_CAP_IB_CM 0x00000004
  431. #define RDMA_CORE_CAP_IW_CM 0x00000008
  432. #define RDMA_CORE_CAP_IB_SA 0x00000010
  433. #define RDMA_CORE_CAP_OPA_MAD 0x00000020
  434. /* Address format 0x000FF000 */
  435. #define RDMA_CORE_CAP_AF_IB 0x00001000
  436. #define RDMA_CORE_CAP_ETH_AH 0x00002000
  437. /* Protocol 0xFFF00000 */
  438. #define RDMA_CORE_CAP_PROT_IB 0x00100000
  439. #define RDMA_CORE_CAP_PROT_ROCE 0x00200000
  440. #define RDMA_CORE_CAP_PROT_IWARP 0x00400000
  441. #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
  442. #define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
  443. | RDMA_CORE_CAP_IB_MAD \
  444. | RDMA_CORE_CAP_IB_SMI \
  445. | RDMA_CORE_CAP_IB_CM \
  446. | RDMA_CORE_CAP_IB_SA \
  447. | RDMA_CORE_CAP_AF_IB)
  448. #define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
  449. | RDMA_CORE_CAP_IB_MAD \
  450. | RDMA_CORE_CAP_IB_CM \
  451. | RDMA_CORE_CAP_AF_IB \
  452. | RDMA_CORE_CAP_ETH_AH)
  453. #define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \
  454. (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
  455. | RDMA_CORE_CAP_IB_MAD \
  456. | RDMA_CORE_CAP_IB_CM \
  457. | RDMA_CORE_CAP_AF_IB \
  458. | RDMA_CORE_CAP_ETH_AH)
  459. #define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
  460. | RDMA_CORE_CAP_IW_CM)
  461. #define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \
  462. | RDMA_CORE_CAP_OPA_MAD)
  463. struct ib_port_attr {
  464. u64 subnet_prefix;
  465. enum ib_port_state state;
  466. enum ib_mtu max_mtu;
  467. enum ib_mtu active_mtu;
  468. int gid_tbl_len;
  469. u32 port_cap_flags;
  470. u32 max_msg_sz;
  471. u32 bad_pkey_cntr;
  472. u32 qkey_viol_cntr;
  473. u16 pkey_tbl_len;
  474. u16 lid;
  475. u16 sm_lid;
  476. u8 lmc;
  477. u8 max_vl_num;
  478. u8 sm_sl;
  479. u8 subnet_timeout;
  480. u8 init_type_reply;
  481. u8 active_width;
  482. u8 active_speed;
  483. u8 phys_state;
  484. bool grh_required;
  485. };
  486. enum ib_device_modify_flags {
  487. IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
  488. IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
  489. };
  490. #define IB_DEVICE_NODE_DESC_MAX 64
  491. struct ib_device_modify {
  492. u64 sys_image_guid;
  493. char node_desc[IB_DEVICE_NODE_DESC_MAX];
  494. };
  495. enum ib_port_modify_flags {
  496. IB_PORT_SHUTDOWN = 1,
  497. IB_PORT_INIT_TYPE = (1<<2),
  498. IB_PORT_RESET_QKEY_CNTR = (1<<3)
  499. };
  500. struct ib_port_modify {
  501. u32 set_port_cap_mask;
  502. u32 clr_port_cap_mask;
  503. u8 init_type;
  504. };
  505. enum ib_event_type {
  506. IB_EVENT_CQ_ERR,
  507. IB_EVENT_QP_FATAL,
  508. IB_EVENT_QP_REQ_ERR,
  509. IB_EVENT_QP_ACCESS_ERR,
  510. IB_EVENT_COMM_EST,
  511. IB_EVENT_SQ_DRAINED,
  512. IB_EVENT_PATH_MIG,
  513. IB_EVENT_PATH_MIG_ERR,
  514. IB_EVENT_DEVICE_FATAL,
  515. IB_EVENT_PORT_ACTIVE,
  516. IB_EVENT_PORT_ERR,
  517. IB_EVENT_LID_CHANGE,
  518. IB_EVENT_PKEY_CHANGE,
  519. IB_EVENT_SM_CHANGE,
  520. IB_EVENT_SRQ_ERR,
  521. IB_EVENT_SRQ_LIMIT_REACHED,
  522. IB_EVENT_QP_LAST_WQE_REACHED,
  523. IB_EVENT_CLIENT_REREGISTER,
  524. IB_EVENT_GID_CHANGE,
  525. IB_EVENT_WQ_FATAL,
  526. };
  527. const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
  528. struct ib_event {
  529. struct ib_device *device;
  530. union {
  531. struct ib_cq *cq;
  532. struct ib_qp *qp;
  533. struct ib_srq *srq;
  534. struct ib_wq *wq;
  535. u8 port_num;
  536. } element;
  537. enum ib_event_type event;
  538. };
  539. struct ib_event_handler {
  540. struct ib_device *device;
  541. void (*handler)(struct ib_event_handler *, struct ib_event *);
  542. struct list_head list;
  543. };
  544. #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
  545. do { \
  546. (_ptr)->device = _device; \
  547. (_ptr)->handler = _handler; \
  548. INIT_LIST_HEAD(&(_ptr)->list); \
  549. } while (0)
  550. struct ib_global_route {
  551. union ib_gid dgid;
  552. u32 flow_label;
  553. u8 sgid_index;
  554. u8 hop_limit;
  555. u8 traffic_class;
  556. };
  557. struct ib_grh {
  558. __be32 version_tclass_flow;
  559. __be16 paylen;
  560. u8 next_hdr;
  561. u8 hop_limit;
  562. union ib_gid sgid;
  563. union ib_gid dgid;
  564. };
  565. union rdma_network_hdr {
  566. struct ib_grh ibgrh;
  567. struct {
  568. /* The IB spec states that if it's IPv4, the header
  569. * is located in the last 20 bytes of the header.
  570. */
  571. u8 reserved[20];
  572. struct iphdr roce4grh;
  573. };
  574. };
  575. enum {
  576. IB_MULTICAST_QPN = 0xffffff
  577. };
  578. #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
  579. #define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000)
  580. enum ib_ah_flags {
  581. IB_AH_GRH = 1
  582. };
  583. enum ib_rate {
  584. IB_RATE_PORT_CURRENT = 0,
  585. IB_RATE_2_5_GBPS = 2,
  586. IB_RATE_5_GBPS = 5,
  587. IB_RATE_10_GBPS = 3,
  588. IB_RATE_20_GBPS = 6,
  589. IB_RATE_30_GBPS = 4,
  590. IB_RATE_40_GBPS = 7,
  591. IB_RATE_60_GBPS = 8,
  592. IB_RATE_80_GBPS = 9,
  593. IB_RATE_120_GBPS = 10,
  594. IB_RATE_14_GBPS = 11,
  595. IB_RATE_56_GBPS = 12,
  596. IB_RATE_112_GBPS = 13,
  597. IB_RATE_168_GBPS = 14,
  598. IB_RATE_25_GBPS = 15,
  599. IB_RATE_100_GBPS = 16,
  600. IB_RATE_200_GBPS = 17,
  601. IB_RATE_300_GBPS = 18
  602. };
  603. /**
  604. * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
  605. * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
  606. * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
  607. * @rate: rate to convert.
  608. */
  609. __attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
  610. /**
  611. * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
  612. * For example, IB_RATE_2_5_GBPS will be converted to 2500.
  613. * @rate: rate to convert.
  614. */
  615. __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
  616. /**
  617. * enum ib_mr_type - memory region type
  618. * @IB_MR_TYPE_MEM_REG: memory region that is used for
  619. * normal registration
  620. * @IB_MR_TYPE_SIGNATURE: memory region that is used for
  621. * signature operations (data-integrity
  622. * capable regions)
  623. * @IB_MR_TYPE_SG_GAPS: memory region that is capable to
  624. * register any arbitrary sg lists (without
  625. * the normal mr constraints - see
  626. * ib_map_mr_sg)
  627. */
  628. enum ib_mr_type {
  629. IB_MR_TYPE_MEM_REG,
  630. IB_MR_TYPE_SIGNATURE,
  631. IB_MR_TYPE_SG_GAPS,
  632. };
  633. /**
  634. * Signature types
  635. * IB_SIG_TYPE_NONE: Unprotected.
  636. * IB_SIG_TYPE_T10_DIF: Type T10-DIF
  637. */
  638. enum ib_signature_type {
  639. IB_SIG_TYPE_NONE,
  640. IB_SIG_TYPE_T10_DIF,
  641. };
  642. /**
  643. * Signature T10-DIF block-guard types
  644. * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
  645. * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
  646. */
  647. enum ib_t10_dif_bg_type {
  648. IB_T10DIF_CRC,
  649. IB_T10DIF_CSUM
  650. };
  651. /**
  652. * struct ib_t10_dif_domain - Parameters specific for T10-DIF
  653. * domain.
  654. * @bg_type: T10-DIF block guard type (CRC|CSUM)
  655. * @pi_interval: protection information interval.
  656. * @bg: seed of guard computation.
  657. * @app_tag: application tag of guard block
  658. * @ref_tag: initial guard block reference tag.
  659. * @ref_remap: Indicate wethear the reftag increments each block
  660. * @app_escape: Indicate to skip block check if apptag=0xffff
  661. * @ref_escape: Indicate to skip block check if reftag=0xffffffff
  662. * @apptag_check_mask: check bitmask of application tag.
  663. */
  664. struct ib_t10_dif_domain {
  665. enum ib_t10_dif_bg_type bg_type;
  666. u16 pi_interval;
  667. u16 bg;
  668. u16 app_tag;
  669. u32 ref_tag;
  670. bool ref_remap;
  671. bool app_escape;
  672. bool ref_escape;
  673. u16 apptag_check_mask;
  674. };
  675. /**
  676. * struct ib_sig_domain - Parameters for signature domain
  677. * @sig_type: specific signauture type
  678. * @sig: union of all signature domain attributes that may
  679. * be used to set domain layout.
  680. */
  681. struct ib_sig_domain {
  682. enum ib_signature_type sig_type;
  683. union {
  684. struct ib_t10_dif_domain dif;
  685. } sig;
  686. };
  687. /**
  688. * struct ib_sig_attrs - Parameters for signature handover operation
  689. * @check_mask: bitmask for signature byte check (8 bytes)
  690. * @mem: memory domain layout desciptor.
  691. * @wire: wire domain layout desciptor.
  692. */
  693. struct ib_sig_attrs {
  694. u8 check_mask;
  695. struct ib_sig_domain mem;
  696. struct ib_sig_domain wire;
  697. };
  698. enum ib_sig_err_type {
  699. IB_SIG_BAD_GUARD,
  700. IB_SIG_BAD_REFTAG,
  701. IB_SIG_BAD_APPTAG,
  702. };
  703. /**
  704. * struct ib_sig_err - signature error descriptor
  705. */
  706. struct ib_sig_err {
  707. enum ib_sig_err_type err_type;
  708. u32 expected;
  709. u32 actual;
  710. u64 sig_err_offset;
  711. u32 key;
  712. };
  713. enum ib_mr_status_check {
  714. IB_MR_CHECK_SIG_STATUS = 1,
  715. };
  716. /**
  717. * struct ib_mr_status - Memory region status container
  718. *
  719. * @fail_status: Bitmask of MR checks status. For each
  720. * failed check a corresponding status bit is set.
  721. * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
  722. * failure.
  723. */
  724. struct ib_mr_status {
  725. u32 fail_status;
  726. struct ib_sig_err sig_err;
  727. };
  728. /**
  729. * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
  730. * enum.
  731. * @mult: multiple to convert.
  732. */
  733. __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
  734. struct ib_ah_attr {
  735. struct ib_global_route grh;
  736. u16 dlid;
  737. u8 sl;
  738. u8 src_path_bits;
  739. u8 static_rate;
  740. u8 ah_flags;
  741. u8 port_num;
  742. u8 dmac[ETH_ALEN];
  743. };
  744. enum ib_wc_status {
  745. IB_WC_SUCCESS,
  746. IB_WC_LOC_LEN_ERR,
  747. IB_WC_LOC_QP_OP_ERR,
  748. IB_WC_LOC_EEC_OP_ERR,
  749. IB_WC_LOC_PROT_ERR,
  750. IB_WC_WR_FLUSH_ERR,
  751. IB_WC_MW_BIND_ERR,
  752. IB_WC_BAD_RESP_ERR,
  753. IB_WC_LOC_ACCESS_ERR,
  754. IB_WC_REM_INV_REQ_ERR,
  755. IB_WC_REM_ACCESS_ERR,
  756. IB_WC_REM_OP_ERR,
  757. IB_WC_RETRY_EXC_ERR,
  758. IB_WC_RNR_RETRY_EXC_ERR,
  759. IB_WC_LOC_RDD_VIOL_ERR,
  760. IB_WC_REM_INV_RD_REQ_ERR,
  761. IB_WC_REM_ABORT_ERR,
  762. IB_WC_INV_EECN_ERR,
  763. IB_WC_INV_EEC_STATE_ERR,
  764. IB_WC_FATAL_ERR,
  765. IB_WC_RESP_TIMEOUT_ERR,
  766. IB_WC_GENERAL_ERR
  767. };
  768. const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
  769. enum ib_wc_opcode {
  770. IB_WC_SEND,
  771. IB_WC_RDMA_WRITE,
  772. IB_WC_RDMA_READ,
  773. IB_WC_COMP_SWAP,
  774. IB_WC_FETCH_ADD,
  775. IB_WC_LSO,
  776. IB_WC_LOCAL_INV,
  777. IB_WC_REG_MR,
  778. IB_WC_MASKED_COMP_SWAP,
  779. IB_WC_MASKED_FETCH_ADD,
  780. /*
  781. * Set value of IB_WC_RECV so consumers can test if a completion is a
  782. * receive by testing (opcode & IB_WC_RECV).
  783. */
  784. IB_WC_RECV = 1 << 7,
  785. IB_WC_RECV_RDMA_WITH_IMM
  786. };
  787. enum ib_wc_flags {
  788. IB_WC_GRH = 1,
  789. IB_WC_WITH_IMM = (1<<1),
  790. IB_WC_WITH_INVALIDATE = (1<<2),
  791. IB_WC_IP_CSUM_OK = (1<<3),
  792. IB_WC_WITH_SMAC = (1<<4),
  793. IB_WC_WITH_VLAN = (1<<5),
  794. IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6),
  795. };
  796. struct ib_wc {
  797. union {
  798. u64 wr_id;
  799. struct ib_cqe *wr_cqe;
  800. };
  801. enum ib_wc_status status;
  802. enum ib_wc_opcode opcode;
  803. u32 vendor_err;
  804. u32 byte_len;
  805. struct ib_qp *qp;
  806. union {
  807. __be32 imm_data;
  808. u32 invalidate_rkey;
  809. } ex;
  810. u32 src_qp;
  811. int wc_flags;
  812. u16 pkey_index;
  813. u16 slid;
  814. u8 sl;
  815. u8 dlid_path_bits;
  816. u8 port_num; /* valid only for DR SMPs on switches */
  817. u8 smac[ETH_ALEN];
  818. u16 vlan_id;
  819. u8 network_hdr_type;
  820. };
  821. enum ib_cq_notify_flags {
  822. IB_CQ_SOLICITED = 1 << 0,
  823. IB_CQ_NEXT_COMP = 1 << 1,
  824. IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
  825. IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
  826. };
  827. enum ib_srq_type {
  828. IB_SRQT_BASIC,
  829. IB_SRQT_XRC
  830. };
  831. enum ib_srq_attr_mask {
  832. IB_SRQ_MAX_WR = 1 << 0,
  833. IB_SRQ_LIMIT = 1 << 1,
  834. };
  835. struct ib_srq_attr {
  836. u32 max_wr;
  837. u32 max_sge;
  838. u32 srq_limit;
  839. };
  840. struct ib_srq_init_attr {
  841. void (*event_handler)(struct ib_event *, void *);
  842. void *srq_context;
  843. struct ib_srq_attr attr;
  844. enum ib_srq_type srq_type;
  845. union {
  846. struct {
  847. struct ib_xrcd *xrcd;
  848. struct ib_cq *cq;
  849. } xrc;
  850. } ext;
  851. };
  852. struct ib_qp_cap {
  853. u32 max_send_wr;
  854. u32 max_recv_wr;
  855. u32 max_send_sge;
  856. u32 max_recv_sge;
  857. u32 max_inline_data;
  858. /*
  859. * Maximum number of rdma_rw_ctx structures in flight at a time.
  860. * ib_create_qp() will calculate the right amount of neededed WRs
  861. * and MRs based on this.
  862. */
  863. u32 max_rdma_ctxs;
  864. };
  865. enum ib_sig_type {
  866. IB_SIGNAL_ALL_WR,
  867. IB_SIGNAL_REQ_WR
  868. };
  869. enum ib_qp_type {
  870. /*
  871. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  872. * here (and in that order) since the MAD layer uses them as
  873. * indices into a 2-entry table.
  874. */
  875. IB_QPT_SMI,
  876. IB_QPT_GSI,
  877. IB_QPT_RC,
  878. IB_QPT_UC,
  879. IB_QPT_UD,
  880. IB_QPT_RAW_IPV6,
  881. IB_QPT_RAW_ETHERTYPE,
  882. IB_QPT_RAW_PACKET = 8,
  883. IB_QPT_XRC_INI = 9,
  884. IB_QPT_XRC_TGT,
  885. IB_QPT_MAX,
  886. /* Reserve a range for qp types internal to the low level driver.
  887. * These qp types will not be visible at the IB core layer, so the
  888. * IB_QPT_MAX usages should not be affected in the core layer
  889. */
  890. IB_QPT_RESERVED1 = 0x1000,
  891. IB_QPT_RESERVED2,
  892. IB_QPT_RESERVED3,
  893. IB_QPT_RESERVED4,
  894. IB_QPT_RESERVED5,
  895. IB_QPT_RESERVED6,
  896. IB_QPT_RESERVED7,
  897. IB_QPT_RESERVED8,
  898. IB_QPT_RESERVED9,
  899. IB_QPT_RESERVED10,
  900. };
  901. enum ib_qp_create_flags {
  902. IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
  903. IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
  904. IB_QP_CREATE_CROSS_CHANNEL = 1 << 2,
  905. IB_QP_CREATE_MANAGED_SEND = 1 << 3,
  906. IB_QP_CREATE_MANAGED_RECV = 1 << 4,
  907. IB_QP_CREATE_NETIF_QP = 1 << 5,
  908. IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
  909. IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
  910. IB_QP_CREATE_SCATTER_FCS = 1 << 8,
  911. /* reserve bits 26-31 for low level drivers' internal use */
  912. IB_QP_CREATE_RESERVED_START = 1 << 26,
  913. IB_QP_CREATE_RESERVED_END = 1 << 31,
  914. };
  915. /*
  916. * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
  917. * callback to destroy the passed in QP.
  918. */
  919. struct ib_qp_init_attr {
  920. void (*event_handler)(struct ib_event *, void *);
  921. void *qp_context;
  922. struct ib_cq *send_cq;
  923. struct ib_cq *recv_cq;
  924. struct ib_srq *srq;
  925. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  926. struct ib_qp_cap cap;
  927. enum ib_sig_type sq_sig_type;
  928. enum ib_qp_type qp_type;
  929. enum ib_qp_create_flags create_flags;
  930. /*
  931. * Only needed for special QP types, or when using the RW API.
  932. */
  933. u8 port_num;
  934. struct ib_rwq_ind_table *rwq_ind_tbl;
  935. };
  936. struct ib_qp_open_attr {
  937. void (*event_handler)(struct ib_event *, void *);
  938. void *qp_context;
  939. u32 qp_num;
  940. enum ib_qp_type qp_type;
  941. };
  942. enum ib_rnr_timeout {
  943. IB_RNR_TIMER_655_36 = 0,
  944. IB_RNR_TIMER_000_01 = 1,
  945. IB_RNR_TIMER_000_02 = 2,
  946. IB_RNR_TIMER_000_03 = 3,
  947. IB_RNR_TIMER_000_04 = 4,
  948. IB_RNR_TIMER_000_06 = 5,
  949. IB_RNR_TIMER_000_08 = 6,
  950. IB_RNR_TIMER_000_12 = 7,
  951. IB_RNR_TIMER_000_16 = 8,
  952. IB_RNR_TIMER_000_24 = 9,
  953. IB_RNR_TIMER_000_32 = 10,
  954. IB_RNR_TIMER_000_48 = 11,
  955. IB_RNR_TIMER_000_64 = 12,
  956. IB_RNR_TIMER_000_96 = 13,
  957. IB_RNR_TIMER_001_28 = 14,
  958. IB_RNR_TIMER_001_92 = 15,
  959. IB_RNR_TIMER_002_56 = 16,
  960. IB_RNR_TIMER_003_84 = 17,
  961. IB_RNR_TIMER_005_12 = 18,
  962. IB_RNR_TIMER_007_68 = 19,
  963. IB_RNR_TIMER_010_24 = 20,
  964. IB_RNR_TIMER_015_36 = 21,
  965. IB_RNR_TIMER_020_48 = 22,
  966. IB_RNR_TIMER_030_72 = 23,
  967. IB_RNR_TIMER_040_96 = 24,
  968. IB_RNR_TIMER_061_44 = 25,
  969. IB_RNR_TIMER_081_92 = 26,
  970. IB_RNR_TIMER_122_88 = 27,
  971. IB_RNR_TIMER_163_84 = 28,
  972. IB_RNR_TIMER_245_76 = 29,
  973. IB_RNR_TIMER_327_68 = 30,
  974. IB_RNR_TIMER_491_52 = 31
  975. };
  976. enum ib_qp_attr_mask {
  977. IB_QP_STATE = 1,
  978. IB_QP_CUR_STATE = (1<<1),
  979. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  980. IB_QP_ACCESS_FLAGS = (1<<3),
  981. IB_QP_PKEY_INDEX = (1<<4),
  982. IB_QP_PORT = (1<<5),
  983. IB_QP_QKEY = (1<<6),
  984. IB_QP_AV = (1<<7),
  985. IB_QP_PATH_MTU = (1<<8),
  986. IB_QP_TIMEOUT = (1<<9),
  987. IB_QP_RETRY_CNT = (1<<10),
  988. IB_QP_RNR_RETRY = (1<<11),
  989. IB_QP_RQ_PSN = (1<<12),
  990. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  991. IB_QP_ALT_PATH = (1<<14),
  992. IB_QP_MIN_RNR_TIMER = (1<<15),
  993. IB_QP_SQ_PSN = (1<<16),
  994. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  995. IB_QP_PATH_MIG_STATE = (1<<18),
  996. IB_QP_CAP = (1<<19),
  997. IB_QP_DEST_QPN = (1<<20),
  998. IB_QP_RESERVED1 = (1<<21),
  999. IB_QP_RESERVED2 = (1<<22),
  1000. IB_QP_RESERVED3 = (1<<23),
  1001. IB_QP_RESERVED4 = (1<<24),
  1002. };
  1003. enum ib_qp_state {
  1004. IB_QPS_RESET,
  1005. IB_QPS_INIT,
  1006. IB_QPS_RTR,
  1007. IB_QPS_RTS,
  1008. IB_QPS_SQD,
  1009. IB_QPS_SQE,
  1010. IB_QPS_ERR
  1011. };
  1012. enum ib_mig_state {
  1013. IB_MIG_MIGRATED,
  1014. IB_MIG_REARM,
  1015. IB_MIG_ARMED
  1016. };
  1017. enum ib_mw_type {
  1018. IB_MW_TYPE_1 = 1,
  1019. IB_MW_TYPE_2 = 2
  1020. };
  1021. struct ib_qp_attr {
  1022. enum ib_qp_state qp_state;
  1023. enum ib_qp_state cur_qp_state;
  1024. enum ib_mtu path_mtu;
  1025. enum ib_mig_state path_mig_state;
  1026. u32 qkey;
  1027. u32 rq_psn;
  1028. u32 sq_psn;
  1029. u32 dest_qp_num;
  1030. int qp_access_flags;
  1031. struct ib_qp_cap cap;
  1032. struct ib_ah_attr ah_attr;
  1033. struct ib_ah_attr alt_ah_attr;
  1034. u16 pkey_index;
  1035. u16 alt_pkey_index;
  1036. u8 en_sqd_async_notify;
  1037. u8 sq_draining;
  1038. u8 max_rd_atomic;
  1039. u8 max_dest_rd_atomic;
  1040. u8 min_rnr_timer;
  1041. u8 port_num;
  1042. u8 timeout;
  1043. u8 retry_cnt;
  1044. u8 rnr_retry;
  1045. u8 alt_port_num;
  1046. u8 alt_timeout;
  1047. };
  1048. enum ib_wr_opcode {
  1049. IB_WR_RDMA_WRITE,
  1050. IB_WR_RDMA_WRITE_WITH_IMM,
  1051. IB_WR_SEND,
  1052. IB_WR_SEND_WITH_IMM,
  1053. IB_WR_RDMA_READ,
  1054. IB_WR_ATOMIC_CMP_AND_SWP,
  1055. IB_WR_ATOMIC_FETCH_AND_ADD,
  1056. IB_WR_LSO,
  1057. IB_WR_SEND_WITH_INV,
  1058. IB_WR_RDMA_READ_WITH_INV,
  1059. IB_WR_LOCAL_INV,
  1060. IB_WR_REG_MR,
  1061. IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
  1062. IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
  1063. IB_WR_REG_SIG_MR,
  1064. /* reserve values for low level drivers' internal use.
  1065. * These values will not be used at all in the ib core layer.
  1066. */
  1067. IB_WR_RESERVED1 = 0xf0,
  1068. IB_WR_RESERVED2,
  1069. IB_WR_RESERVED3,
  1070. IB_WR_RESERVED4,
  1071. IB_WR_RESERVED5,
  1072. IB_WR_RESERVED6,
  1073. IB_WR_RESERVED7,
  1074. IB_WR_RESERVED8,
  1075. IB_WR_RESERVED9,
  1076. IB_WR_RESERVED10,
  1077. };
  1078. enum ib_send_flags {
  1079. IB_SEND_FENCE = 1,
  1080. IB_SEND_SIGNALED = (1<<1),
  1081. IB_SEND_SOLICITED = (1<<2),
  1082. IB_SEND_INLINE = (1<<3),
  1083. IB_SEND_IP_CSUM = (1<<4),
  1084. /* reserve bits 26-31 for low level drivers' internal use */
  1085. IB_SEND_RESERVED_START = (1 << 26),
  1086. IB_SEND_RESERVED_END = (1 << 31),
  1087. };
  1088. struct ib_sge {
  1089. u64 addr;
  1090. u32 length;
  1091. u32 lkey;
  1092. };
  1093. struct ib_cqe {
  1094. void (*done)(struct ib_cq *cq, struct ib_wc *wc);
  1095. };
  1096. struct ib_send_wr {
  1097. struct ib_send_wr *next;
  1098. union {
  1099. u64 wr_id;
  1100. struct ib_cqe *wr_cqe;
  1101. };
  1102. struct ib_sge *sg_list;
  1103. int num_sge;
  1104. enum ib_wr_opcode opcode;
  1105. int send_flags;
  1106. union {
  1107. __be32 imm_data;
  1108. u32 invalidate_rkey;
  1109. } ex;
  1110. };
  1111. struct ib_rdma_wr {
  1112. struct ib_send_wr wr;
  1113. u64 remote_addr;
  1114. u32 rkey;
  1115. };
  1116. static inline struct ib_rdma_wr *rdma_wr(struct ib_send_wr *wr)
  1117. {
  1118. return container_of(wr, struct ib_rdma_wr, wr);
  1119. }
  1120. struct ib_atomic_wr {
  1121. struct ib_send_wr wr;
  1122. u64 remote_addr;
  1123. u64 compare_add;
  1124. u64 swap;
  1125. u64 compare_add_mask;
  1126. u64 swap_mask;
  1127. u32 rkey;
  1128. };
  1129. static inline struct ib_atomic_wr *atomic_wr(struct ib_send_wr *wr)
  1130. {
  1131. return container_of(wr, struct ib_atomic_wr, wr);
  1132. }
  1133. struct ib_ud_wr {
  1134. struct ib_send_wr wr;
  1135. struct ib_ah *ah;
  1136. void *header;
  1137. int hlen;
  1138. int mss;
  1139. u32 remote_qpn;
  1140. u32 remote_qkey;
  1141. u16 pkey_index; /* valid for GSI only */
  1142. u8 port_num; /* valid for DR SMPs on switch only */
  1143. };
  1144. static inline struct ib_ud_wr *ud_wr(struct ib_send_wr *wr)
  1145. {
  1146. return container_of(wr, struct ib_ud_wr, wr);
  1147. }
  1148. struct ib_reg_wr {
  1149. struct ib_send_wr wr;
  1150. struct ib_mr *mr;
  1151. u32 key;
  1152. int access;
  1153. };
  1154. static inline struct ib_reg_wr *reg_wr(struct ib_send_wr *wr)
  1155. {
  1156. return container_of(wr, struct ib_reg_wr, wr);
  1157. }
  1158. struct ib_sig_handover_wr {
  1159. struct ib_send_wr wr;
  1160. struct ib_sig_attrs *sig_attrs;
  1161. struct ib_mr *sig_mr;
  1162. int access_flags;
  1163. struct ib_sge *prot;
  1164. };
  1165. static inline struct ib_sig_handover_wr *sig_handover_wr(struct ib_send_wr *wr)
  1166. {
  1167. return container_of(wr, struct ib_sig_handover_wr, wr);
  1168. }
  1169. struct ib_recv_wr {
  1170. struct ib_recv_wr *next;
  1171. union {
  1172. u64 wr_id;
  1173. struct ib_cqe *wr_cqe;
  1174. };
  1175. struct ib_sge *sg_list;
  1176. int num_sge;
  1177. };
  1178. enum ib_access_flags {
  1179. IB_ACCESS_LOCAL_WRITE = 1,
  1180. IB_ACCESS_REMOTE_WRITE = (1<<1),
  1181. IB_ACCESS_REMOTE_READ = (1<<2),
  1182. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  1183. IB_ACCESS_MW_BIND = (1<<4),
  1184. IB_ZERO_BASED = (1<<5),
  1185. IB_ACCESS_ON_DEMAND = (1<<6),
  1186. };
  1187. /*
  1188. * XXX: these are apparently used for ->rereg_user_mr, no idea why they
  1189. * are hidden here instead of a uapi header!
  1190. */
  1191. enum ib_mr_rereg_flags {
  1192. IB_MR_REREG_TRANS = 1,
  1193. IB_MR_REREG_PD = (1<<1),
  1194. IB_MR_REREG_ACCESS = (1<<2),
  1195. IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
  1196. };
  1197. struct ib_fmr_attr {
  1198. int max_pages;
  1199. int max_maps;
  1200. u8 page_shift;
  1201. };
  1202. struct ib_umem;
  1203. struct ib_ucontext {
  1204. struct ib_device *device;
  1205. struct list_head pd_list;
  1206. struct list_head mr_list;
  1207. struct list_head mw_list;
  1208. struct list_head cq_list;
  1209. struct list_head qp_list;
  1210. struct list_head srq_list;
  1211. struct list_head ah_list;
  1212. struct list_head xrcd_list;
  1213. struct list_head rule_list;
  1214. struct list_head wq_list;
  1215. struct list_head rwq_ind_tbl_list;
  1216. int closing;
  1217. struct pid *tgid;
  1218. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  1219. struct rb_root umem_tree;
  1220. /*
  1221. * Protects .umem_rbroot and tree, as well as odp_mrs_count and
  1222. * mmu notifiers registration.
  1223. */
  1224. struct rw_semaphore umem_rwsem;
  1225. void (*invalidate_range)(struct ib_umem *umem,
  1226. unsigned long start, unsigned long end);
  1227. struct mmu_notifier mn;
  1228. atomic_t notifier_count;
  1229. /* A list of umems that don't have private mmu notifier counters yet. */
  1230. struct list_head no_private_counters;
  1231. int odp_mrs_count;
  1232. #endif
  1233. };
  1234. struct ib_uobject {
  1235. u64 user_handle; /* handle given to us by userspace */
  1236. struct ib_ucontext *context; /* associated user context */
  1237. void *object; /* containing object */
  1238. struct list_head list; /* link to context's list */
  1239. int id; /* index into kernel idr */
  1240. struct kref ref;
  1241. struct rw_semaphore mutex; /* protects .live */
  1242. struct rcu_head rcu; /* kfree_rcu() overhead */
  1243. int live;
  1244. };
  1245. struct ib_udata {
  1246. const void __user *inbuf;
  1247. void __user *outbuf;
  1248. size_t inlen;
  1249. size_t outlen;
  1250. };
  1251. struct ib_pd {
  1252. u32 local_dma_lkey;
  1253. u32 flags;
  1254. struct ib_device *device;
  1255. struct ib_uobject *uobject;
  1256. atomic_t usecnt; /* count all resources */
  1257. u32 unsafe_global_rkey;
  1258. /*
  1259. * Implementation details of the RDMA core, don't use in drivers:
  1260. */
  1261. struct ib_mr *__internal_mr;
  1262. };
  1263. struct ib_xrcd {
  1264. struct ib_device *device;
  1265. atomic_t usecnt; /* count all exposed resources */
  1266. struct inode *inode;
  1267. struct mutex tgt_qp_mutex;
  1268. struct list_head tgt_qp_list;
  1269. };
  1270. struct ib_ah {
  1271. struct ib_device *device;
  1272. struct ib_pd *pd;
  1273. struct ib_uobject *uobject;
  1274. };
  1275. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  1276. enum ib_poll_context {
  1277. IB_POLL_DIRECT, /* caller context, no hw completions */
  1278. IB_POLL_SOFTIRQ, /* poll from softirq context */
  1279. IB_POLL_WORKQUEUE, /* poll from workqueue */
  1280. IB_POLL_UNBOUND_WORKQUEUE, /* poll from unbound workqueue */
  1281. };
  1282. struct ib_cq {
  1283. struct ib_device *device;
  1284. struct ib_uobject *uobject;
  1285. ib_comp_handler comp_handler;
  1286. void (*event_handler)(struct ib_event *, void *);
  1287. void *cq_context;
  1288. int cqe;
  1289. atomic_t usecnt; /* count number of work queues */
  1290. enum ib_poll_context poll_ctx;
  1291. struct ib_wc *wc;
  1292. union {
  1293. struct irq_poll iop;
  1294. struct work_struct work;
  1295. };
  1296. struct workqueue_struct *comp_wq;
  1297. };
  1298. struct ib_srq {
  1299. struct ib_device *device;
  1300. struct ib_pd *pd;
  1301. struct ib_uobject *uobject;
  1302. void (*event_handler)(struct ib_event *, void *);
  1303. void *srq_context;
  1304. enum ib_srq_type srq_type;
  1305. atomic_t usecnt;
  1306. union {
  1307. struct {
  1308. struct ib_xrcd *xrcd;
  1309. struct ib_cq *cq;
  1310. u32 srq_num;
  1311. } xrc;
  1312. } ext;
  1313. };
  1314. enum ib_wq_type {
  1315. IB_WQT_RQ
  1316. };
  1317. enum ib_wq_state {
  1318. IB_WQS_RESET,
  1319. IB_WQS_RDY,
  1320. IB_WQS_ERR
  1321. };
  1322. struct ib_wq {
  1323. struct ib_device *device;
  1324. struct ib_uobject *uobject;
  1325. void *wq_context;
  1326. void (*event_handler)(struct ib_event *, void *);
  1327. struct ib_pd *pd;
  1328. struct ib_cq *cq;
  1329. u32 wq_num;
  1330. enum ib_wq_state state;
  1331. enum ib_wq_type wq_type;
  1332. atomic_t usecnt;
  1333. };
  1334. struct ib_wq_init_attr {
  1335. void *wq_context;
  1336. enum ib_wq_type wq_type;
  1337. u32 max_wr;
  1338. u32 max_sge;
  1339. struct ib_cq *cq;
  1340. void (*event_handler)(struct ib_event *, void *);
  1341. };
  1342. enum ib_wq_attr_mask {
  1343. IB_WQ_STATE = 1 << 0,
  1344. IB_WQ_CUR_STATE = 1 << 1,
  1345. };
  1346. struct ib_wq_attr {
  1347. enum ib_wq_state wq_state;
  1348. enum ib_wq_state curr_wq_state;
  1349. };
  1350. struct ib_rwq_ind_table {
  1351. struct ib_device *device;
  1352. struct ib_uobject *uobject;
  1353. atomic_t usecnt;
  1354. u32 ind_tbl_num;
  1355. u32 log_ind_tbl_size;
  1356. struct ib_wq **ind_tbl;
  1357. };
  1358. struct ib_rwq_ind_table_init_attr {
  1359. u32 log_ind_tbl_size;
  1360. /* Each entry is a pointer to Receive Work Queue */
  1361. struct ib_wq **ind_tbl;
  1362. };
  1363. /*
  1364. * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
  1365. * @max_read_sge: Maximum SGE elements per RDMA READ request.
  1366. */
  1367. struct ib_qp {
  1368. struct ib_device *device;
  1369. struct ib_pd *pd;
  1370. struct ib_cq *send_cq;
  1371. struct ib_cq *recv_cq;
  1372. spinlock_t mr_lock;
  1373. int mrs_used;
  1374. struct list_head rdma_mrs;
  1375. struct list_head sig_mrs;
  1376. struct ib_srq *srq;
  1377. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  1378. struct list_head xrcd_list;
  1379. /* count times opened, mcast attaches, flow attaches */
  1380. atomic_t usecnt;
  1381. struct list_head open_list;
  1382. struct ib_qp *real_qp;
  1383. struct ib_uobject *uobject;
  1384. void (*event_handler)(struct ib_event *, void *);
  1385. void *qp_context;
  1386. u32 qp_num;
  1387. u32 max_write_sge;
  1388. u32 max_read_sge;
  1389. enum ib_qp_type qp_type;
  1390. struct ib_rwq_ind_table *rwq_ind_tbl;
  1391. };
  1392. struct ib_mr {
  1393. struct ib_device *device;
  1394. struct ib_pd *pd;
  1395. u32 lkey;
  1396. u32 rkey;
  1397. u64 iova;
  1398. u32 length;
  1399. unsigned int page_size;
  1400. bool need_inval;
  1401. union {
  1402. struct ib_uobject *uobject; /* user */
  1403. struct list_head qp_entry; /* FR */
  1404. };
  1405. };
  1406. struct ib_mw {
  1407. struct ib_device *device;
  1408. struct ib_pd *pd;
  1409. struct ib_uobject *uobject;
  1410. u32 rkey;
  1411. enum ib_mw_type type;
  1412. };
  1413. struct ib_fmr {
  1414. struct ib_device *device;
  1415. struct ib_pd *pd;
  1416. struct list_head list;
  1417. u32 lkey;
  1418. u32 rkey;
  1419. };
  1420. /* Supported steering options */
  1421. enum ib_flow_attr_type {
  1422. /* steering according to rule specifications */
  1423. IB_FLOW_ATTR_NORMAL = 0x0,
  1424. /* default unicast and multicast rule -
  1425. * receive all Eth traffic which isn't steered to any QP
  1426. */
  1427. IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
  1428. /* default multicast rule -
  1429. * receive all Eth multicast traffic which isn't steered to any QP
  1430. */
  1431. IB_FLOW_ATTR_MC_DEFAULT = 0x2,
  1432. /* sniffer rule - receive all port traffic */
  1433. IB_FLOW_ATTR_SNIFFER = 0x3
  1434. };
  1435. /* Supported steering header types */
  1436. enum ib_flow_spec_type {
  1437. /* L2 headers*/
  1438. IB_FLOW_SPEC_ETH = 0x20,
  1439. IB_FLOW_SPEC_IB = 0x22,
  1440. /* L3 header*/
  1441. IB_FLOW_SPEC_IPV4 = 0x30,
  1442. IB_FLOW_SPEC_IPV6 = 0x31,
  1443. /* L4 headers*/
  1444. IB_FLOW_SPEC_TCP = 0x40,
  1445. IB_FLOW_SPEC_UDP = 0x41
  1446. };
  1447. #define IB_FLOW_SPEC_LAYER_MASK 0xF0
  1448. #define IB_FLOW_SPEC_SUPPORT_LAYERS 4
  1449. /* Flow steering rule priority is set according to it's domain.
  1450. * Lower domain value means higher priority.
  1451. */
  1452. enum ib_flow_domain {
  1453. IB_FLOW_DOMAIN_USER,
  1454. IB_FLOW_DOMAIN_ETHTOOL,
  1455. IB_FLOW_DOMAIN_RFS,
  1456. IB_FLOW_DOMAIN_NIC,
  1457. IB_FLOW_DOMAIN_NUM /* Must be last */
  1458. };
  1459. enum ib_flow_flags {
  1460. IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
  1461. IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 2 /* Must be last */
  1462. };
  1463. struct ib_flow_eth_filter {
  1464. u8 dst_mac[6];
  1465. u8 src_mac[6];
  1466. __be16 ether_type;
  1467. __be16 vlan_tag;
  1468. /* Must be last */
  1469. u8 real_sz[0];
  1470. };
  1471. struct ib_flow_spec_eth {
  1472. enum ib_flow_spec_type type;
  1473. u16 size;
  1474. struct ib_flow_eth_filter val;
  1475. struct ib_flow_eth_filter mask;
  1476. };
  1477. struct ib_flow_ib_filter {
  1478. __be16 dlid;
  1479. __u8 sl;
  1480. /* Must be last */
  1481. u8 real_sz[0];
  1482. };
  1483. struct ib_flow_spec_ib {
  1484. enum ib_flow_spec_type type;
  1485. u16 size;
  1486. struct ib_flow_ib_filter val;
  1487. struct ib_flow_ib_filter mask;
  1488. };
  1489. /* IPv4 header flags */
  1490. enum ib_ipv4_flags {
  1491. IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
  1492. IB_IPV4_MORE_FRAG = 0X4 /* For All fragmented packets except the
  1493. last have this flag set */
  1494. };
  1495. struct ib_flow_ipv4_filter {
  1496. __be32 src_ip;
  1497. __be32 dst_ip;
  1498. u8 proto;
  1499. u8 tos;
  1500. u8 ttl;
  1501. u8 flags;
  1502. /* Must be last */
  1503. u8 real_sz[0];
  1504. };
  1505. struct ib_flow_spec_ipv4 {
  1506. enum ib_flow_spec_type type;
  1507. u16 size;
  1508. struct ib_flow_ipv4_filter val;
  1509. struct ib_flow_ipv4_filter mask;
  1510. };
  1511. struct ib_flow_ipv6_filter {
  1512. u8 src_ip[16];
  1513. u8 dst_ip[16];
  1514. __be32 flow_label;
  1515. u8 next_hdr;
  1516. u8 traffic_class;
  1517. u8 hop_limit;
  1518. /* Must be last */
  1519. u8 real_sz[0];
  1520. };
  1521. struct ib_flow_spec_ipv6 {
  1522. enum ib_flow_spec_type type;
  1523. u16 size;
  1524. struct ib_flow_ipv6_filter val;
  1525. struct ib_flow_ipv6_filter mask;
  1526. };
  1527. struct ib_flow_tcp_udp_filter {
  1528. __be16 dst_port;
  1529. __be16 src_port;
  1530. /* Must be last */
  1531. u8 real_sz[0];
  1532. };
  1533. struct ib_flow_spec_tcp_udp {
  1534. enum ib_flow_spec_type type;
  1535. u16 size;
  1536. struct ib_flow_tcp_udp_filter val;
  1537. struct ib_flow_tcp_udp_filter mask;
  1538. };
  1539. union ib_flow_spec {
  1540. struct {
  1541. enum ib_flow_spec_type type;
  1542. u16 size;
  1543. };
  1544. struct ib_flow_spec_eth eth;
  1545. struct ib_flow_spec_ib ib;
  1546. struct ib_flow_spec_ipv4 ipv4;
  1547. struct ib_flow_spec_tcp_udp tcp_udp;
  1548. struct ib_flow_spec_ipv6 ipv6;
  1549. };
  1550. struct ib_flow_attr {
  1551. enum ib_flow_attr_type type;
  1552. u16 size;
  1553. u16 priority;
  1554. u32 flags;
  1555. u8 num_of_specs;
  1556. u8 port;
  1557. /* Following are the optional layers according to user request
  1558. * struct ib_flow_spec_xxx
  1559. * struct ib_flow_spec_yyy
  1560. */
  1561. };
  1562. struct ib_flow {
  1563. struct ib_qp *qp;
  1564. struct ib_uobject *uobject;
  1565. };
  1566. struct ib_mad_hdr;
  1567. struct ib_grh;
  1568. enum ib_process_mad_flags {
  1569. IB_MAD_IGNORE_MKEY = 1,
  1570. IB_MAD_IGNORE_BKEY = 2,
  1571. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  1572. };
  1573. enum ib_mad_result {
  1574. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  1575. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  1576. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  1577. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  1578. };
  1579. #define IB_DEVICE_NAME_MAX 64
  1580. struct ib_cache {
  1581. rwlock_t lock;
  1582. struct ib_event_handler event_handler;
  1583. struct ib_pkey_cache **pkey_cache;
  1584. struct ib_gid_table **gid_cache;
  1585. u8 *lmc_cache;
  1586. };
  1587. struct ib_dma_mapping_ops {
  1588. int (*mapping_error)(struct ib_device *dev,
  1589. u64 dma_addr);
  1590. u64 (*map_single)(struct ib_device *dev,
  1591. void *ptr, size_t size,
  1592. enum dma_data_direction direction);
  1593. void (*unmap_single)(struct ib_device *dev,
  1594. u64 addr, size_t size,
  1595. enum dma_data_direction direction);
  1596. u64 (*map_page)(struct ib_device *dev,
  1597. struct page *page, unsigned long offset,
  1598. size_t size,
  1599. enum dma_data_direction direction);
  1600. void (*unmap_page)(struct ib_device *dev,
  1601. u64 addr, size_t size,
  1602. enum dma_data_direction direction);
  1603. int (*map_sg)(struct ib_device *dev,
  1604. struct scatterlist *sg, int nents,
  1605. enum dma_data_direction direction);
  1606. void (*unmap_sg)(struct ib_device *dev,
  1607. struct scatterlist *sg, int nents,
  1608. enum dma_data_direction direction);
  1609. int (*map_sg_attrs)(struct ib_device *dev,
  1610. struct scatterlist *sg, int nents,
  1611. enum dma_data_direction direction,
  1612. unsigned long attrs);
  1613. void (*unmap_sg_attrs)(struct ib_device *dev,
  1614. struct scatterlist *sg, int nents,
  1615. enum dma_data_direction direction,
  1616. unsigned long attrs);
  1617. void (*sync_single_for_cpu)(struct ib_device *dev,
  1618. u64 dma_handle,
  1619. size_t size,
  1620. enum dma_data_direction dir);
  1621. void (*sync_single_for_device)(struct ib_device *dev,
  1622. u64 dma_handle,
  1623. size_t size,
  1624. enum dma_data_direction dir);
  1625. void *(*alloc_coherent)(struct ib_device *dev,
  1626. size_t size,
  1627. u64 *dma_handle,
  1628. gfp_t flag);
  1629. void (*free_coherent)(struct ib_device *dev,
  1630. size_t size, void *cpu_addr,
  1631. u64 dma_handle);
  1632. };
  1633. struct iw_cm_verbs;
  1634. struct ib_port_immutable {
  1635. int pkey_tbl_len;
  1636. int gid_tbl_len;
  1637. u32 core_cap_flags;
  1638. u32 max_mad_size;
  1639. };
  1640. struct ib_device {
  1641. struct device *dma_device;
  1642. char name[IB_DEVICE_NAME_MAX];
  1643. struct list_head event_handler_list;
  1644. spinlock_t event_handler_lock;
  1645. spinlock_t client_data_lock;
  1646. struct list_head core_list;
  1647. /* Access to the client_data_list is protected by the client_data_lock
  1648. * spinlock and the lists_rwsem read-write semaphore */
  1649. struct list_head client_data_list;
  1650. struct ib_cache cache;
  1651. /**
  1652. * port_immutable is indexed by port number
  1653. */
  1654. struct ib_port_immutable *port_immutable;
  1655. int num_comp_vectors;
  1656. struct iw_cm_verbs *iwcm;
  1657. /**
  1658. * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
  1659. * driver initialized data. The struct is kfree()'ed by the sysfs
  1660. * core when the device is removed. A lifespan of -1 in the return
  1661. * struct tells the core to set a default lifespan.
  1662. */
  1663. struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
  1664. u8 port_num);
  1665. /**
  1666. * get_hw_stats - Fill in the counter value(s) in the stats struct.
  1667. * @index - The index in the value array we wish to have updated, or
  1668. * num_counters if we want all stats updated
  1669. * Return codes -
  1670. * < 0 - Error, no counters updated
  1671. * index - Updated the single counter pointed to by index
  1672. * num_counters - Updated all counters (will reset the timestamp
  1673. * and prevent further calls for lifespan milliseconds)
  1674. * Drivers are allowed to update all counters in leiu of just the
  1675. * one given in index at their option
  1676. */
  1677. int (*get_hw_stats)(struct ib_device *device,
  1678. struct rdma_hw_stats *stats,
  1679. u8 port, int index);
  1680. int (*query_device)(struct ib_device *device,
  1681. struct ib_device_attr *device_attr,
  1682. struct ib_udata *udata);
  1683. int (*query_port)(struct ib_device *device,
  1684. u8 port_num,
  1685. struct ib_port_attr *port_attr);
  1686. enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
  1687. u8 port_num);
  1688. /* When calling get_netdev, the HW vendor's driver should return the
  1689. * net device of device @device at port @port_num or NULL if such
  1690. * a net device doesn't exist. The vendor driver should call dev_hold
  1691. * on this net device. The HW vendor's device driver must guarantee
  1692. * that this function returns NULL before the net device reaches
  1693. * NETDEV_UNREGISTER_FINAL state.
  1694. */
  1695. struct net_device *(*get_netdev)(struct ib_device *device,
  1696. u8 port_num);
  1697. int (*query_gid)(struct ib_device *device,
  1698. u8 port_num, int index,
  1699. union ib_gid *gid);
  1700. /* When calling add_gid, the HW vendor's driver should
  1701. * add the gid of device @device at gid index @index of
  1702. * port @port_num to be @gid. Meta-info of that gid (for example,
  1703. * the network device related to this gid is available
  1704. * at @attr. @context allows the HW vendor driver to store extra
  1705. * information together with a GID entry. The HW vendor may allocate
  1706. * memory to contain this information and store it in @context when a
  1707. * new GID entry is written to. Params are consistent until the next
  1708. * call of add_gid or delete_gid. The function should return 0 on
  1709. * success or error otherwise. The function could be called
  1710. * concurrently for different ports. This function is only called
  1711. * when roce_gid_table is used.
  1712. */
  1713. int (*add_gid)(struct ib_device *device,
  1714. u8 port_num,
  1715. unsigned int index,
  1716. const union ib_gid *gid,
  1717. const struct ib_gid_attr *attr,
  1718. void **context);
  1719. /* When calling del_gid, the HW vendor's driver should delete the
  1720. * gid of device @device at gid index @index of port @port_num.
  1721. * Upon the deletion of a GID entry, the HW vendor must free any
  1722. * allocated memory. The caller will clear @context afterwards.
  1723. * This function is only called when roce_gid_table is used.
  1724. */
  1725. int (*del_gid)(struct ib_device *device,
  1726. u8 port_num,
  1727. unsigned int index,
  1728. void **context);
  1729. int (*query_pkey)(struct ib_device *device,
  1730. u8 port_num, u16 index, u16 *pkey);
  1731. int (*modify_device)(struct ib_device *device,
  1732. int device_modify_mask,
  1733. struct ib_device_modify *device_modify);
  1734. int (*modify_port)(struct ib_device *device,
  1735. u8 port_num, int port_modify_mask,
  1736. struct ib_port_modify *port_modify);
  1737. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  1738. struct ib_udata *udata);
  1739. int (*dealloc_ucontext)(struct ib_ucontext *context);
  1740. int (*mmap)(struct ib_ucontext *context,
  1741. struct vm_area_struct *vma);
  1742. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  1743. struct ib_ucontext *context,
  1744. struct ib_udata *udata);
  1745. int (*dealloc_pd)(struct ib_pd *pd);
  1746. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  1747. struct ib_ah_attr *ah_attr);
  1748. int (*modify_ah)(struct ib_ah *ah,
  1749. struct ib_ah_attr *ah_attr);
  1750. int (*query_ah)(struct ib_ah *ah,
  1751. struct ib_ah_attr *ah_attr);
  1752. int (*destroy_ah)(struct ib_ah *ah);
  1753. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  1754. struct ib_srq_init_attr *srq_init_attr,
  1755. struct ib_udata *udata);
  1756. int (*modify_srq)(struct ib_srq *srq,
  1757. struct ib_srq_attr *srq_attr,
  1758. enum ib_srq_attr_mask srq_attr_mask,
  1759. struct ib_udata *udata);
  1760. int (*query_srq)(struct ib_srq *srq,
  1761. struct ib_srq_attr *srq_attr);
  1762. int (*destroy_srq)(struct ib_srq *srq);
  1763. int (*post_srq_recv)(struct ib_srq *srq,
  1764. struct ib_recv_wr *recv_wr,
  1765. struct ib_recv_wr **bad_recv_wr);
  1766. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  1767. struct ib_qp_init_attr *qp_init_attr,
  1768. struct ib_udata *udata);
  1769. int (*modify_qp)(struct ib_qp *qp,
  1770. struct ib_qp_attr *qp_attr,
  1771. int qp_attr_mask,
  1772. struct ib_udata *udata);
  1773. int (*query_qp)(struct ib_qp *qp,
  1774. struct ib_qp_attr *qp_attr,
  1775. int qp_attr_mask,
  1776. struct ib_qp_init_attr *qp_init_attr);
  1777. int (*destroy_qp)(struct ib_qp *qp);
  1778. int (*post_send)(struct ib_qp *qp,
  1779. struct ib_send_wr *send_wr,
  1780. struct ib_send_wr **bad_send_wr);
  1781. int (*post_recv)(struct ib_qp *qp,
  1782. struct ib_recv_wr *recv_wr,
  1783. struct ib_recv_wr **bad_recv_wr);
  1784. struct ib_cq * (*create_cq)(struct ib_device *device,
  1785. const struct ib_cq_init_attr *attr,
  1786. struct ib_ucontext *context,
  1787. struct ib_udata *udata);
  1788. int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
  1789. u16 cq_period);
  1790. int (*destroy_cq)(struct ib_cq *cq);
  1791. int (*resize_cq)(struct ib_cq *cq, int cqe,
  1792. struct ib_udata *udata);
  1793. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  1794. struct ib_wc *wc);
  1795. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  1796. int (*req_notify_cq)(struct ib_cq *cq,
  1797. enum ib_cq_notify_flags flags);
  1798. int (*req_ncomp_notif)(struct ib_cq *cq,
  1799. int wc_cnt);
  1800. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  1801. int mr_access_flags);
  1802. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  1803. u64 start, u64 length,
  1804. u64 virt_addr,
  1805. int mr_access_flags,
  1806. struct ib_udata *udata);
  1807. int (*rereg_user_mr)(struct ib_mr *mr,
  1808. int flags,
  1809. u64 start, u64 length,
  1810. u64 virt_addr,
  1811. int mr_access_flags,
  1812. struct ib_pd *pd,
  1813. struct ib_udata *udata);
  1814. int (*dereg_mr)(struct ib_mr *mr);
  1815. struct ib_mr * (*alloc_mr)(struct ib_pd *pd,
  1816. enum ib_mr_type mr_type,
  1817. u32 max_num_sg);
  1818. int (*map_mr_sg)(struct ib_mr *mr,
  1819. struct scatterlist *sg,
  1820. int sg_nents,
  1821. unsigned int *sg_offset);
  1822. struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
  1823. enum ib_mw_type type,
  1824. struct ib_udata *udata);
  1825. int (*dealloc_mw)(struct ib_mw *mw);
  1826. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  1827. int mr_access_flags,
  1828. struct ib_fmr_attr *fmr_attr);
  1829. int (*map_phys_fmr)(struct ib_fmr *fmr,
  1830. u64 *page_list, int list_len,
  1831. u64 iova);
  1832. int (*unmap_fmr)(struct list_head *fmr_list);
  1833. int (*dealloc_fmr)(struct ib_fmr *fmr);
  1834. int (*attach_mcast)(struct ib_qp *qp,
  1835. union ib_gid *gid,
  1836. u16 lid);
  1837. int (*detach_mcast)(struct ib_qp *qp,
  1838. union ib_gid *gid,
  1839. u16 lid);
  1840. int (*process_mad)(struct ib_device *device,
  1841. int process_mad_flags,
  1842. u8 port_num,
  1843. const struct ib_wc *in_wc,
  1844. const struct ib_grh *in_grh,
  1845. const struct ib_mad_hdr *in_mad,
  1846. size_t in_mad_size,
  1847. struct ib_mad_hdr *out_mad,
  1848. size_t *out_mad_size,
  1849. u16 *out_mad_pkey_index);
  1850. struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
  1851. struct ib_ucontext *ucontext,
  1852. struct ib_udata *udata);
  1853. int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
  1854. struct ib_flow * (*create_flow)(struct ib_qp *qp,
  1855. struct ib_flow_attr
  1856. *flow_attr,
  1857. int domain);
  1858. int (*destroy_flow)(struct ib_flow *flow_id);
  1859. int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
  1860. struct ib_mr_status *mr_status);
  1861. void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
  1862. void (*drain_rq)(struct ib_qp *qp);
  1863. void (*drain_sq)(struct ib_qp *qp);
  1864. int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
  1865. int state);
  1866. int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
  1867. struct ifla_vf_info *ivf);
  1868. int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
  1869. struct ifla_vf_stats *stats);
  1870. int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
  1871. int type);
  1872. struct ib_wq * (*create_wq)(struct ib_pd *pd,
  1873. struct ib_wq_init_attr *init_attr,
  1874. struct ib_udata *udata);
  1875. int (*destroy_wq)(struct ib_wq *wq);
  1876. int (*modify_wq)(struct ib_wq *wq,
  1877. struct ib_wq_attr *attr,
  1878. u32 wq_attr_mask,
  1879. struct ib_udata *udata);
  1880. struct ib_rwq_ind_table * (*create_rwq_ind_table)(struct ib_device *device,
  1881. struct ib_rwq_ind_table_init_attr *init_attr,
  1882. struct ib_udata *udata);
  1883. int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
  1884. struct ib_dma_mapping_ops *dma_ops;
  1885. struct module *owner;
  1886. struct device dev;
  1887. struct kobject *ports_parent;
  1888. struct list_head port_list;
  1889. enum {
  1890. IB_DEV_UNINITIALIZED,
  1891. IB_DEV_REGISTERED,
  1892. IB_DEV_UNREGISTERED
  1893. } reg_state;
  1894. int uverbs_abi_ver;
  1895. u64 uverbs_cmd_mask;
  1896. u64 uverbs_ex_cmd_mask;
  1897. char node_desc[IB_DEVICE_NODE_DESC_MAX];
  1898. __be64 node_guid;
  1899. u32 local_dma_lkey;
  1900. u16 is_switch:1;
  1901. u8 node_type;
  1902. u8 phys_port_cnt;
  1903. struct ib_device_attr attrs;
  1904. struct attribute_group *hw_stats_ag;
  1905. struct rdma_hw_stats *hw_stats;
  1906. /**
  1907. * The following mandatory functions are used only at device
  1908. * registration. Keep functions such as these at the end of this
  1909. * structure to avoid cache line misses when accessing struct ib_device
  1910. * in fast paths.
  1911. */
  1912. int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
  1913. void (*get_dev_fw_str)(struct ib_device *, char *str, size_t str_len);
  1914. };
  1915. struct ib_client {
  1916. char *name;
  1917. void (*add) (struct ib_device *);
  1918. void (*remove)(struct ib_device *, void *client_data);
  1919. /* Returns the net_dev belonging to this ib_client and matching the
  1920. * given parameters.
  1921. * @dev: An RDMA device that the net_dev use for communication.
  1922. * @port: A physical port number on the RDMA device.
  1923. * @pkey: P_Key that the net_dev uses if applicable.
  1924. * @gid: A GID that the net_dev uses to communicate.
  1925. * @addr: An IP address the net_dev is configured with.
  1926. * @client_data: The device's client data set by ib_set_client_data().
  1927. *
  1928. * An ib_client that implements a net_dev on top of RDMA devices
  1929. * (such as IP over IB) should implement this callback, allowing the
  1930. * rdma_cm module to find the right net_dev for a given request.
  1931. *
  1932. * The caller is responsible for calling dev_put on the returned
  1933. * netdev. */
  1934. struct net_device *(*get_net_dev_by_params)(
  1935. struct ib_device *dev,
  1936. u8 port,
  1937. u16 pkey,
  1938. const union ib_gid *gid,
  1939. const struct sockaddr *addr,
  1940. void *client_data);
  1941. struct list_head list;
  1942. };
  1943. struct ib_device *ib_alloc_device(size_t size);
  1944. void ib_dealloc_device(struct ib_device *device);
  1945. void ib_get_device_fw_str(struct ib_device *device, char *str, size_t str_len);
  1946. int ib_register_device(struct ib_device *device,
  1947. int (*port_callback)(struct ib_device *,
  1948. u8, struct kobject *));
  1949. void ib_unregister_device(struct ib_device *device);
  1950. int ib_register_client (struct ib_client *client);
  1951. void ib_unregister_client(struct ib_client *client);
  1952. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  1953. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  1954. void *data);
  1955. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  1956. {
  1957. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  1958. }
  1959. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  1960. {
  1961. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  1962. }
  1963. static inline bool ib_is_udata_cleared(struct ib_udata *udata,
  1964. size_t offset,
  1965. size_t len)
  1966. {
  1967. const void __user *p = udata->inbuf + offset;
  1968. bool ret;
  1969. u8 *buf;
  1970. if (len > USHRT_MAX)
  1971. return false;
  1972. buf = memdup_user(p, len);
  1973. if (IS_ERR(buf))
  1974. return false;
  1975. ret = !memchr_inv(buf, 0, len);
  1976. kfree(buf);
  1977. return ret;
  1978. }
  1979. /**
  1980. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  1981. * contains all required attributes and no attributes not allowed for
  1982. * the given QP state transition.
  1983. * @cur_state: Current QP state
  1984. * @next_state: Next QP state
  1985. * @type: QP type
  1986. * @mask: Mask of supplied QP attributes
  1987. * @ll : link layer of port
  1988. *
  1989. * This function is a helper function that a low-level driver's
  1990. * modify_qp method can use to validate the consumer's input. It
  1991. * checks that cur_state and next_state are valid QP states, that a
  1992. * transition from cur_state to next_state is allowed by the IB spec,
  1993. * and that the attribute mask supplied is allowed for the transition.
  1994. */
  1995. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  1996. enum ib_qp_type type, enum ib_qp_attr_mask mask,
  1997. enum rdma_link_layer ll);
  1998. int ib_register_event_handler (struct ib_event_handler *event_handler);
  1999. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  2000. void ib_dispatch_event(struct ib_event *event);
  2001. int ib_query_port(struct ib_device *device,
  2002. u8 port_num, struct ib_port_attr *port_attr);
  2003. enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
  2004. u8 port_num);
  2005. /**
  2006. * rdma_cap_ib_switch - Check if the device is IB switch
  2007. * @device: Device to check
  2008. *
  2009. * Device driver is responsible for setting is_switch bit on
  2010. * in ib_device structure at init time.
  2011. *
  2012. * Return: true if the device is IB switch.
  2013. */
  2014. static inline bool rdma_cap_ib_switch(const struct ib_device *device)
  2015. {
  2016. return device->is_switch;
  2017. }
  2018. /**
  2019. * rdma_start_port - Return the first valid port number for the device
  2020. * specified
  2021. *
  2022. * @device: Device to be checked
  2023. *
  2024. * Return start port number
  2025. */
  2026. static inline u8 rdma_start_port(const struct ib_device *device)
  2027. {
  2028. return rdma_cap_ib_switch(device) ? 0 : 1;
  2029. }
  2030. /**
  2031. * rdma_end_port - Return the last valid port number for the device
  2032. * specified
  2033. *
  2034. * @device: Device to be checked
  2035. *
  2036. * Return last port number
  2037. */
  2038. static inline u8 rdma_end_port(const struct ib_device *device)
  2039. {
  2040. return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
  2041. }
  2042. static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
  2043. {
  2044. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
  2045. }
  2046. static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
  2047. {
  2048. return device->port_immutable[port_num].core_cap_flags &
  2049. (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
  2050. }
  2051. static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
  2052. {
  2053. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
  2054. }
  2055. static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
  2056. {
  2057. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
  2058. }
  2059. static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
  2060. {
  2061. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
  2062. }
  2063. static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
  2064. {
  2065. return rdma_protocol_ib(device, port_num) ||
  2066. rdma_protocol_roce(device, port_num);
  2067. }
  2068. /**
  2069. * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
  2070. * Management Datagrams.
  2071. * @device: Device to check
  2072. * @port_num: Port number to check
  2073. *
  2074. * Management Datagrams (MAD) are a required part of the InfiniBand
  2075. * specification and are supported on all InfiniBand devices. A slightly
  2076. * extended version are also supported on OPA interfaces.
  2077. *
  2078. * Return: true if the port supports sending/receiving of MAD packets.
  2079. */
  2080. static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
  2081. {
  2082. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
  2083. }
  2084. /**
  2085. * rdma_cap_opa_mad - Check if the port of device provides support for OPA
  2086. * Management Datagrams.
  2087. * @device: Device to check
  2088. * @port_num: Port number to check
  2089. *
  2090. * Intel OmniPath devices extend and/or replace the InfiniBand Management
  2091. * datagrams with their own versions. These OPA MADs share many but not all of
  2092. * the characteristics of InfiniBand MADs.
  2093. *
  2094. * OPA MADs differ in the following ways:
  2095. *
  2096. * 1) MADs are variable size up to 2K
  2097. * IBTA defined MADs remain fixed at 256 bytes
  2098. * 2) OPA SMPs must carry valid PKeys
  2099. * 3) OPA SMP packets are a different format
  2100. *
  2101. * Return: true if the port supports OPA MAD packet formats.
  2102. */
  2103. static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
  2104. {
  2105. return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
  2106. == RDMA_CORE_CAP_OPA_MAD;
  2107. }
  2108. /**
  2109. * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
  2110. * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
  2111. * @device: Device to check
  2112. * @port_num: Port number to check
  2113. *
  2114. * Each InfiniBand node is required to provide a Subnet Management Agent
  2115. * that the subnet manager can access. Prior to the fabric being fully
  2116. * configured by the subnet manager, the SMA is accessed via a well known
  2117. * interface called the Subnet Management Interface (SMI). This interface
  2118. * uses directed route packets to communicate with the SM to get around the
  2119. * chicken and egg problem of the SM needing to know what's on the fabric
  2120. * in order to configure the fabric, and needing to configure the fabric in
  2121. * order to send packets to the devices on the fabric. These directed
  2122. * route packets do not need the fabric fully configured in order to reach
  2123. * their destination. The SMI is the only method allowed to send
  2124. * directed route packets on an InfiniBand fabric.
  2125. *
  2126. * Return: true if the port provides an SMI.
  2127. */
  2128. static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
  2129. {
  2130. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
  2131. }
  2132. /**
  2133. * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
  2134. * Communication Manager.
  2135. * @device: Device to check
  2136. * @port_num: Port number to check
  2137. *
  2138. * The InfiniBand Communication Manager is one of many pre-defined General
  2139. * Service Agents (GSA) that are accessed via the General Service
  2140. * Interface (GSI). It's role is to facilitate establishment of connections
  2141. * between nodes as well as other management related tasks for established
  2142. * connections.
  2143. *
  2144. * Return: true if the port supports an IB CM (this does not guarantee that
  2145. * a CM is actually running however).
  2146. */
  2147. static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
  2148. {
  2149. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
  2150. }
  2151. /**
  2152. * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
  2153. * Communication Manager.
  2154. * @device: Device to check
  2155. * @port_num: Port number to check
  2156. *
  2157. * Similar to above, but specific to iWARP connections which have a different
  2158. * managment protocol than InfiniBand.
  2159. *
  2160. * Return: true if the port supports an iWARP CM (this does not guarantee that
  2161. * a CM is actually running however).
  2162. */
  2163. static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
  2164. {
  2165. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
  2166. }
  2167. /**
  2168. * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
  2169. * Subnet Administration.
  2170. * @device: Device to check
  2171. * @port_num: Port number to check
  2172. *
  2173. * An InfiniBand Subnet Administration (SA) service is a pre-defined General
  2174. * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
  2175. * fabrics, devices should resolve routes to other hosts by contacting the
  2176. * SA to query the proper route.
  2177. *
  2178. * Return: true if the port should act as a client to the fabric Subnet
  2179. * Administration interface. This does not imply that the SA service is
  2180. * running locally.
  2181. */
  2182. static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
  2183. {
  2184. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
  2185. }
  2186. /**
  2187. * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
  2188. * Multicast.
  2189. * @device: Device to check
  2190. * @port_num: Port number to check
  2191. *
  2192. * InfiniBand multicast registration is more complex than normal IPv4 or
  2193. * IPv6 multicast registration. Each Host Channel Adapter must register
  2194. * with the Subnet Manager when it wishes to join a multicast group. It
  2195. * should do so only once regardless of how many queue pairs it subscribes
  2196. * to this group. And it should leave the group only after all queue pairs
  2197. * attached to the group have been detached.
  2198. *
  2199. * Return: true if the port must undertake the additional adminstrative
  2200. * overhead of registering/unregistering with the SM and tracking of the
  2201. * total number of queue pairs attached to the multicast group.
  2202. */
  2203. static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
  2204. {
  2205. return rdma_cap_ib_sa(device, port_num);
  2206. }
  2207. /**
  2208. * rdma_cap_af_ib - Check if the port of device has the capability
  2209. * Native Infiniband Address.
  2210. * @device: Device to check
  2211. * @port_num: Port number to check
  2212. *
  2213. * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
  2214. * GID. RoCE uses a different mechanism, but still generates a GID via
  2215. * a prescribed mechanism and port specific data.
  2216. *
  2217. * Return: true if the port uses a GID address to identify devices on the
  2218. * network.
  2219. */
  2220. static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
  2221. {
  2222. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
  2223. }
  2224. /**
  2225. * rdma_cap_eth_ah - Check if the port of device has the capability
  2226. * Ethernet Address Handle.
  2227. * @device: Device to check
  2228. * @port_num: Port number to check
  2229. *
  2230. * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
  2231. * to fabricate GIDs over Ethernet/IP specific addresses native to the
  2232. * port. Normally, packet headers are generated by the sending host
  2233. * adapter, but when sending connectionless datagrams, we must manually
  2234. * inject the proper headers for the fabric we are communicating over.
  2235. *
  2236. * Return: true if we are running as a RoCE port and must force the
  2237. * addition of a Global Route Header built from our Ethernet Address
  2238. * Handle into our header list for connectionless packets.
  2239. */
  2240. static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
  2241. {
  2242. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
  2243. }
  2244. /**
  2245. * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
  2246. *
  2247. * @device: Device
  2248. * @port_num: Port number
  2249. *
  2250. * This MAD size includes the MAD headers and MAD payload. No other headers
  2251. * are included.
  2252. *
  2253. * Return the max MAD size required by the Port. Will return 0 if the port
  2254. * does not support MADs
  2255. */
  2256. static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
  2257. {
  2258. return device->port_immutable[port_num].max_mad_size;
  2259. }
  2260. /**
  2261. * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
  2262. * @device: Device to check
  2263. * @port_num: Port number to check
  2264. *
  2265. * RoCE GID table mechanism manages the various GIDs for a device.
  2266. *
  2267. * NOTE: if allocating the port's GID table has failed, this call will still
  2268. * return true, but any RoCE GID table API will fail.
  2269. *
  2270. * Return: true if the port uses RoCE GID table mechanism in order to manage
  2271. * its GIDs.
  2272. */
  2273. static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
  2274. u8 port_num)
  2275. {
  2276. return rdma_protocol_roce(device, port_num) &&
  2277. device->add_gid && device->del_gid;
  2278. }
  2279. /*
  2280. * Check if the device supports READ W/ INVALIDATE.
  2281. */
  2282. static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
  2283. {
  2284. /*
  2285. * iWarp drivers must support READ W/ INVALIDATE. No other protocol
  2286. * has support for it yet.
  2287. */
  2288. return rdma_protocol_iwarp(dev, port_num);
  2289. }
  2290. int ib_query_gid(struct ib_device *device,
  2291. u8 port_num, int index, union ib_gid *gid,
  2292. struct ib_gid_attr *attr);
  2293. int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
  2294. int state);
  2295. int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
  2296. struct ifla_vf_info *info);
  2297. int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
  2298. struct ifla_vf_stats *stats);
  2299. int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
  2300. int type);
  2301. int ib_query_pkey(struct ib_device *device,
  2302. u8 port_num, u16 index, u16 *pkey);
  2303. int ib_modify_device(struct ib_device *device,
  2304. int device_modify_mask,
  2305. struct ib_device_modify *device_modify);
  2306. int ib_modify_port(struct ib_device *device,
  2307. u8 port_num, int port_modify_mask,
  2308. struct ib_port_modify *port_modify);
  2309. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  2310. enum ib_gid_type gid_type, struct net_device *ndev,
  2311. u8 *port_num, u16 *index);
  2312. int ib_find_pkey(struct ib_device *device,
  2313. u8 port_num, u16 pkey, u16 *index);
  2314. enum ib_pd_flags {
  2315. /*
  2316. * Create a memory registration for all memory in the system and place
  2317. * the rkey for it into pd->unsafe_global_rkey. This can be used by
  2318. * ULPs to avoid the overhead of dynamic MRs.
  2319. *
  2320. * This flag is generally considered unsafe and must only be used in
  2321. * extremly trusted environments. Every use of it will log a warning
  2322. * in the kernel log.
  2323. */
  2324. IB_PD_UNSAFE_GLOBAL_RKEY = 0x01,
  2325. };
  2326. struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
  2327. const char *caller);
  2328. #define ib_alloc_pd(device, flags) \
  2329. __ib_alloc_pd((device), (flags), __func__)
  2330. void ib_dealloc_pd(struct ib_pd *pd);
  2331. /**
  2332. * ib_create_ah - Creates an address handle for the given address vector.
  2333. * @pd: The protection domain associated with the address handle.
  2334. * @ah_attr: The attributes of the address vector.
  2335. *
  2336. * The address handle is used to reference a local or global destination
  2337. * in all UD QP post sends.
  2338. */
  2339. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  2340. /**
  2341. * ib_init_ah_from_wc - Initializes address handle attributes from a
  2342. * work completion.
  2343. * @device: Device on which the received message arrived.
  2344. * @port_num: Port on which the received message arrived.
  2345. * @wc: Work completion associated with the received message.
  2346. * @grh: References the received global route header. This parameter is
  2347. * ignored unless the work completion indicates that the GRH is valid.
  2348. * @ah_attr: Returned attributes that can be used when creating an address
  2349. * handle for replying to the message.
  2350. */
  2351. int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
  2352. const struct ib_wc *wc, const struct ib_grh *grh,
  2353. struct ib_ah_attr *ah_attr);
  2354. /**
  2355. * ib_create_ah_from_wc - Creates an address handle associated with the
  2356. * sender of the specified work completion.
  2357. * @pd: The protection domain associated with the address handle.
  2358. * @wc: Work completion information associated with a received message.
  2359. * @grh: References the received global route header. This parameter is
  2360. * ignored unless the work completion indicates that the GRH is valid.
  2361. * @port_num: The outbound port number to associate with the address.
  2362. *
  2363. * The address handle is used to reference a local or global destination
  2364. * in all UD QP post sends.
  2365. */
  2366. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
  2367. const struct ib_grh *grh, u8 port_num);
  2368. /**
  2369. * ib_modify_ah - Modifies the address vector associated with an address
  2370. * handle.
  2371. * @ah: The address handle to modify.
  2372. * @ah_attr: The new address vector attributes to associate with the
  2373. * address handle.
  2374. */
  2375. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  2376. /**
  2377. * ib_query_ah - Queries the address vector associated with an address
  2378. * handle.
  2379. * @ah: The address handle to query.
  2380. * @ah_attr: The address vector attributes associated with the address
  2381. * handle.
  2382. */
  2383. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  2384. /**
  2385. * ib_destroy_ah - Destroys an address handle.
  2386. * @ah: The address handle to destroy.
  2387. */
  2388. int ib_destroy_ah(struct ib_ah *ah);
  2389. /**
  2390. * ib_create_srq - Creates a SRQ associated with the specified protection
  2391. * domain.
  2392. * @pd: The protection domain associated with the SRQ.
  2393. * @srq_init_attr: A list of initial attributes required to create the
  2394. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  2395. * the actual capabilities of the created SRQ.
  2396. *
  2397. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  2398. * requested size of the SRQ, and set to the actual values allocated
  2399. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  2400. * will always be at least as large as the requested values.
  2401. */
  2402. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  2403. struct ib_srq_init_attr *srq_init_attr);
  2404. /**
  2405. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  2406. * @srq: The SRQ to modify.
  2407. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  2408. * the current values of selected SRQ attributes are returned.
  2409. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  2410. * are being modified.
  2411. *
  2412. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  2413. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  2414. * the number of receives queued drops below the limit.
  2415. */
  2416. int ib_modify_srq(struct ib_srq *srq,
  2417. struct ib_srq_attr *srq_attr,
  2418. enum ib_srq_attr_mask srq_attr_mask);
  2419. /**
  2420. * ib_query_srq - Returns the attribute list and current values for the
  2421. * specified SRQ.
  2422. * @srq: The SRQ to query.
  2423. * @srq_attr: The attributes of the specified SRQ.
  2424. */
  2425. int ib_query_srq(struct ib_srq *srq,
  2426. struct ib_srq_attr *srq_attr);
  2427. /**
  2428. * ib_destroy_srq - Destroys the specified SRQ.
  2429. * @srq: The SRQ to destroy.
  2430. */
  2431. int ib_destroy_srq(struct ib_srq *srq);
  2432. /**
  2433. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  2434. * @srq: The SRQ to post the work request on.
  2435. * @recv_wr: A list of work requests to post on the receive queue.
  2436. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2437. * the work request that failed to be posted on the QP.
  2438. */
  2439. static inline int ib_post_srq_recv(struct ib_srq *srq,
  2440. struct ib_recv_wr *recv_wr,
  2441. struct ib_recv_wr **bad_recv_wr)
  2442. {
  2443. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  2444. }
  2445. /**
  2446. * ib_create_qp - Creates a QP associated with the specified protection
  2447. * domain.
  2448. * @pd: The protection domain associated with the QP.
  2449. * @qp_init_attr: A list of initial attributes required to create the
  2450. * QP. If QP creation succeeds, then the attributes are updated to
  2451. * the actual capabilities of the created QP.
  2452. */
  2453. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  2454. struct ib_qp_init_attr *qp_init_attr);
  2455. /**
  2456. * ib_modify_qp - Modifies the attributes for the specified QP and then
  2457. * transitions the QP to the given state.
  2458. * @qp: The QP to modify.
  2459. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  2460. * the current values of selected QP attributes are returned.
  2461. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  2462. * are being modified.
  2463. */
  2464. int ib_modify_qp(struct ib_qp *qp,
  2465. struct ib_qp_attr *qp_attr,
  2466. int qp_attr_mask);
  2467. /**
  2468. * ib_query_qp - Returns the attribute list and current values for the
  2469. * specified QP.
  2470. * @qp: The QP to query.
  2471. * @qp_attr: The attributes of the specified QP.
  2472. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  2473. * @qp_init_attr: Additional attributes of the selected QP.
  2474. *
  2475. * The qp_attr_mask may be used to limit the query to gathering only the
  2476. * selected attributes.
  2477. */
  2478. int ib_query_qp(struct ib_qp *qp,
  2479. struct ib_qp_attr *qp_attr,
  2480. int qp_attr_mask,
  2481. struct ib_qp_init_attr *qp_init_attr);
  2482. /**
  2483. * ib_destroy_qp - Destroys the specified QP.
  2484. * @qp: The QP to destroy.
  2485. */
  2486. int ib_destroy_qp(struct ib_qp *qp);
  2487. /**
  2488. * ib_open_qp - Obtain a reference to an existing sharable QP.
  2489. * @xrcd - XRC domain
  2490. * @qp_open_attr: Attributes identifying the QP to open.
  2491. *
  2492. * Returns a reference to a sharable QP.
  2493. */
  2494. struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
  2495. struct ib_qp_open_attr *qp_open_attr);
  2496. /**
  2497. * ib_close_qp - Release an external reference to a QP.
  2498. * @qp: The QP handle to release
  2499. *
  2500. * The opened QP handle is released by the caller. The underlying
  2501. * shared QP is not destroyed until all internal references are released.
  2502. */
  2503. int ib_close_qp(struct ib_qp *qp);
  2504. /**
  2505. * ib_post_send - Posts a list of work requests to the send queue of
  2506. * the specified QP.
  2507. * @qp: The QP to post the work request on.
  2508. * @send_wr: A list of work requests to post on the send queue.
  2509. * @bad_send_wr: On an immediate failure, this parameter will reference
  2510. * the work request that failed to be posted on the QP.
  2511. *
  2512. * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
  2513. * error is returned, the QP state shall not be affected,
  2514. * ib_post_send() will return an immediate error after queueing any
  2515. * earlier work requests in the list.
  2516. */
  2517. static inline int ib_post_send(struct ib_qp *qp,
  2518. struct ib_send_wr *send_wr,
  2519. struct ib_send_wr **bad_send_wr)
  2520. {
  2521. return qp->device->post_send(qp, send_wr, bad_send_wr);
  2522. }
  2523. /**
  2524. * ib_post_recv - Posts a list of work requests to the receive queue of
  2525. * the specified QP.
  2526. * @qp: The QP to post the work request on.
  2527. * @recv_wr: A list of work requests to post on the receive queue.
  2528. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2529. * the work request that failed to be posted on the QP.
  2530. */
  2531. static inline int ib_post_recv(struct ib_qp *qp,
  2532. struct ib_recv_wr *recv_wr,
  2533. struct ib_recv_wr **bad_recv_wr)
  2534. {
  2535. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  2536. }
  2537. struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
  2538. int nr_cqe, int comp_vector, enum ib_poll_context poll_ctx);
  2539. void ib_free_cq(struct ib_cq *cq);
  2540. int ib_process_cq_direct(struct ib_cq *cq, int budget);
  2541. /**
  2542. * ib_create_cq - Creates a CQ on the specified device.
  2543. * @device: The device on which to create the CQ.
  2544. * @comp_handler: A user-specified callback that is invoked when a
  2545. * completion event occurs on the CQ.
  2546. * @event_handler: A user-specified callback that is invoked when an
  2547. * asynchronous event not associated with a completion occurs on the CQ.
  2548. * @cq_context: Context associated with the CQ returned to the user via
  2549. * the associated completion and event handlers.
  2550. * @cq_attr: The attributes the CQ should be created upon.
  2551. *
  2552. * Users can examine the cq structure to determine the actual CQ size.
  2553. */
  2554. struct ib_cq *ib_create_cq(struct ib_device *device,
  2555. ib_comp_handler comp_handler,
  2556. void (*event_handler)(struct ib_event *, void *),
  2557. void *cq_context,
  2558. const struct ib_cq_init_attr *cq_attr);
  2559. /**
  2560. * ib_resize_cq - Modifies the capacity of the CQ.
  2561. * @cq: The CQ to resize.
  2562. * @cqe: The minimum size of the CQ.
  2563. *
  2564. * Users can examine the cq structure to determine the actual CQ size.
  2565. */
  2566. int ib_resize_cq(struct ib_cq *cq, int cqe);
  2567. /**
  2568. * ib_modify_cq - Modifies moderation params of the CQ
  2569. * @cq: The CQ to modify.
  2570. * @cq_count: number of CQEs that will trigger an event
  2571. * @cq_period: max period of time in usec before triggering an event
  2572. *
  2573. */
  2574. int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  2575. /**
  2576. * ib_destroy_cq - Destroys the specified CQ.
  2577. * @cq: The CQ to destroy.
  2578. */
  2579. int ib_destroy_cq(struct ib_cq *cq);
  2580. /**
  2581. * ib_poll_cq - poll a CQ for completion(s)
  2582. * @cq:the CQ being polled
  2583. * @num_entries:maximum number of completions to return
  2584. * @wc:array of at least @num_entries &struct ib_wc where completions
  2585. * will be returned
  2586. *
  2587. * Poll a CQ for (possibly multiple) completions. If the return value
  2588. * is < 0, an error occurred. If the return value is >= 0, it is the
  2589. * number of completions returned. If the return value is
  2590. * non-negative and < num_entries, then the CQ was emptied.
  2591. */
  2592. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  2593. struct ib_wc *wc)
  2594. {
  2595. return cq->device->poll_cq(cq, num_entries, wc);
  2596. }
  2597. /**
  2598. * ib_peek_cq - Returns the number of unreaped completions currently
  2599. * on the specified CQ.
  2600. * @cq: The CQ to peek.
  2601. * @wc_cnt: A minimum number of unreaped completions to check for.
  2602. *
  2603. * If the number of unreaped completions is greater than or equal to wc_cnt,
  2604. * this function returns wc_cnt, otherwise, it returns the actual number of
  2605. * unreaped completions.
  2606. */
  2607. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  2608. /**
  2609. * ib_req_notify_cq - Request completion notification on a CQ.
  2610. * @cq: The CQ to generate an event for.
  2611. * @flags:
  2612. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  2613. * to request an event on the next solicited event or next work
  2614. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  2615. * may also be |ed in to request a hint about missed events, as
  2616. * described below.
  2617. *
  2618. * Return Value:
  2619. * < 0 means an error occurred while requesting notification
  2620. * == 0 means notification was requested successfully, and if
  2621. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  2622. * were missed and it is safe to wait for another event. In
  2623. * this case is it guaranteed that any work completions added
  2624. * to the CQ since the last CQ poll will trigger a completion
  2625. * notification event.
  2626. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  2627. * in. It means that the consumer must poll the CQ again to
  2628. * make sure it is empty to avoid missing an event because of a
  2629. * race between requesting notification and an entry being
  2630. * added to the CQ. This return value means it is possible
  2631. * (but not guaranteed) that a work completion has been added
  2632. * to the CQ since the last poll without triggering a
  2633. * completion notification event.
  2634. */
  2635. static inline int ib_req_notify_cq(struct ib_cq *cq,
  2636. enum ib_cq_notify_flags flags)
  2637. {
  2638. return cq->device->req_notify_cq(cq, flags);
  2639. }
  2640. /**
  2641. * ib_req_ncomp_notif - Request completion notification when there are
  2642. * at least the specified number of unreaped completions on the CQ.
  2643. * @cq: The CQ to generate an event for.
  2644. * @wc_cnt: The number of unreaped completions that should be on the
  2645. * CQ before an event is generated.
  2646. */
  2647. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  2648. {
  2649. return cq->device->req_ncomp_notif ?
  2650. cq->device->req_ncomp_notif(cq, wc_cnt) :
  2651. -ENOSYS;
  2652. }
  2653. /**
  2654. * ib_dma_mapping_error - check a DMA addr for error
  2655. * @dev: The device for which the dma_addr was created
  2656. * @dma_addr: The DMA address to check
  2657. */
  2658. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  2659. {
  2660. if (dev->dma_ops)
  2661. return dev->dma_ops->mapping_error(dev, dma_addr);
  2662. return dma_mapping_error(dev->dma_device, dma_addr);
  2663. }
  2664. /**
  2665. * ib_dma_map_single - Map a kernel virtual address to DMA address
  2666. * @dev: The device for which the dma_addr is to be created
  2667. * @cpu_addr: The kernel virtual address
  2668. * @size: The size of the region in bytes
  2669. * @direction: The direction of the DMA
  2670. */
  2671. static inline u64 ib_dma_map_single(struct ib_device *dev,
  2672. void *cpu_addr, size_t size,
  2673. enum dma_data_direction direction)
  2674. {
  2675. if (dev->dma_ops)
  2676. return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
  2677. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  2678. }
  2679. /**
  2680. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  2681. * @dev: The device for which the DMA address was created
  2682. * @addr: The DMA address
  2683. * @size: The size of the region in bytes
  2684. * @direction: The direction of the DMA
  2685. */
  2686. static inline void ib_dma_unmap_single(struct ib_device *dev,
  2687. u64 addr, size_t size,
  2688. enum dma_data_direction direction)
  2689. {
  2690. if (dev->dma_ops)
  2691. dev->dma_ops->unmap_single(dev, addr, size, direction);
  2692. else
  2693. dma_unmap_single(dev->dma_device, addr, size, direction);
  2694. }
  2695. static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
  2696. void *cpu_addr, size_t size,
  2697. enum dma_data_direction direction,
  2698. unsigned long dma_attrs)
  2699. {
  2700. return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
  2701. direction, dma_attrs);
  2702. }
  2703. static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
  2704. u64 addr, size_t size,
  2705. enum dma_data_direction direction,
  2706. unsigned long dma_attrs)
  2707. {
  2708. return dma_unmap_single_attrs(dev->dma_device, addr, size,
  2709. direction, dma_attrs);
  2710. }
  2711. /**
  2712. * ib_dma_map_page - Map a physical page to DMA address
  2713. * @dev: The device for which the dma_addr is to be created
  2714. * @page: The page to be mapped
  2715. * @offset: The offset within the page
  2716. * @size: The size of the region in bytes
  2717. * @direction: The direction of the DMA
  2718. */
  2719. static inline u64 ib_dma_map_page(struct ib_device *dev,
  2720. struct page *page,
  2721. unsigned long offset,
  2722. size_t size,
  2723. enum dma_data_direction direction)
  2724. {
  2725. if (dev->dma_ops)
  2726. return dev->dma_ops->map_page(dev, page, offset, size, direction);
  2727. return dma_map_page(dev->dma_device, page, offset, size, direction);
  2728. }
  2729. /**
  2730. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  2731. * @dev: The device for which the DMA address was created
  2732. * @addr: The DMA address
  2733. * @size: The size of the region in bytes
  2734. * @direction: The direction of the DMA
  2735. */
  2736. static inline void ib_dma_unmap_page(struct ib_device *dev,
  2737. u64 addr, size_t size,
  2738. enum dma_data_direction direction)
  2739. {
  2740. if (dev->dma_ops)
  2741. dev->dma_ops->unmap_page(dev, addr, size, direction);
  2742. else
  2743. dma_unmap_page(dev->dma_device, addr, size, direction);
  2744. }
  2745. /**
  2746. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  2747. * @dev: The device for which the DMA addresses are to be created
  2748. * @sg: The array of scatter/gather entries
  2749. * @nents: The number of scatter/gather entries
  2750. * @direction: The direction of the DMA
  2751. */
  2752. static inline int ib_dma_map_sg(struct ib_device *dev,
  2753. struct scatterlist *sg, int nents,
  2754. enum dma_data_direction direction)
  2755. {
  2756. if (dev->dma_ops)
  2757. return dev->dma_ops->map_sg(dev, sg, nents, direction);
  2758. return dma_map_sg(dev->dma_device, sg, nents, direction);
  2759. }
  2760. /**
  2761. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  2762. * @dev: The device for which the DMA addresses were created
  2763. * @sg: The array of scatter/gather entries
  2764. * @nents: The number of scatter/gather entries
  2765. * @direction: The direction of the DMA
  2766. */
  2767. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  2768. struct scatterlist *sg, int nents,
  2769. enum dma_data_direction direction)
  2770. {
  2771. if (dev->dma_ops)
  2772. dev->dma_ops->unmap_sg(dev, sg, nents, direction);
  2773. else
  2774. dma_unmap_sg(dev->dma_device, sg, nents, direction);
  2775. }
  2776. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  2777. struct scatterlist *sg, int nents,
  2778. enum dma_data_direction direction,
  2779. unsigned long dma_attrs)
  2780. {
  2781. if (dev->dma_ops)
  2782. return dev->dma_ops->map_sg_attrs(dev, sg, nents, direction,
  2783. dma_attrs);
  2784. else
  2785. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
  2786. dma_attrs);
  2787. }
  2788. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  2789. struct scatterlist *sg, int nents,
  2790. enum dma_data_direction direction,
  2791. unsigned long dma_attrs)
  2792. {
  2793. if (dev->dma_ops)
  2794. return dev->dma_ops->unmap_sg_attrs(dev, sg, nents, direction,
  2795. dma_attrs);
  2796. else
  2797. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction,
  2798. dma_attrs);
  2799. }
  2800. /**
  2801. * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
  2802. * @dev: The device for which the DMA addresses were created
  2803. * @sg: The scatter/gather entry
  2804. *
  2805. * Note: this function is obsolete. To do: change all occurrences of
  2806. * ib_sg_dma_address() into sg_dma_address().
  2807. */
  2808. static inline u64 ib_sg_dma_address(struct ib_device *dev,
  2809. struct scatterlist *sg)
  2810. {
  2811. return sg_dma_address(sg);
  2812. }
  2813. /**
  2814. * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
  2815. * @dev: The device for which the DMA addresses were created
  2816. * @sg: The scatter/gather entry
  2817. *
  2818. * Note: this function is obsolete. To do: change all occurrences of
  2819. * ib_sg_dma_len() into sg_dma_len().
  2820. */
  2821. static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
  2822. struct scatterlist *sg)
  2823. {
  2824. return sg_dma_len(sg);
  2825. }
  2826. /**
  2827. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  2828. * @dev: The device for which the DMA address was created
  2829. * @addr: The DMA address
  2830. * @size: The size of the region in bytes
  2831. * @dir: The direction of the DMA
  2832. */
  2833. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  2834. u64 addr,
  2835. size_t size,
  2836. enum dma_data_direction dir)
  2837. {
  2838. if (dev->dma_ops)
  2839. dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
  2840. else
  2841. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  2842. }
  2843. /**
  2844. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  2845. * @dev: The device for which the DMA address was created
  2846. * @addr: The DMA address
  2847. * @size: The size of the region in bytes
  2848. * @dir: The direction of the DMA
  2849. */
  2850. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  2851. u64 addr,
  2852. size_t size,
  2853. enum dma_data_direction dir)
  2854. {
  2855. if (dev->dma_ops)
  2856. dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
  2857. else
  2858. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  2859. }
  2860. /**
  2861. * ib_dma_alloc_coherent - Allocate memory and map it for DMA
  2862. * @dev: The device for which the DMA address is requested
  2863. * @size: The size of the region to allocate in bytes
  2864. * @dma_handle: A pointer for returning the DMA address of the region
  2865. * @flag: memory allocator flags
  2866. */
  2867. static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
  2868. size_t size,
  2869. u64 *dma_handle,
  2870. gfp_t flag)
  2871. {
  2872. if (dev->dma_ops)
  2873. return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  2874. else {
  2875. dma_addr_t handle;
  2876. void *ret;
  2877. ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
  2878. *dma_handle = handle;
  2879. return ret;
  2880. }
  2881. }
  2882. /**
  2883. * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
  2884. * @dev: The device for which the DMA addresses were allocated
  2885. * @size: The size of the region
  2886. * @cpu_addr: the address returned by ib_dma_alloc_coherent()
  2887. * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
  2888. */
  2889. static inline void ib_dma_free_coherent(struct ib_device *dev,
  2890. size_t size, void *cpu_addr,
  2891. u64 dma_handle)
  2892. {
  2893. if (dev->dma_ops)
  2894. dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  2895. else
  2896. dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
  2897. }
  2898. /**
  2899. * ib_dereg_mr - Deregisters a memory region and removes it from the
  2900. * HCA translation table.
  2901. * @mr: The memory region to deregister.
  2902. *
  2903. * This function can fail, if the memory region has memory windows bound to it.
  2904. */
  2905. int ib_dereg_mr(struct ib_mr *mr);
  2906. struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
  2907. enum ib_mr_type mr_type,
  2908. u32 max_num_sg);
  2909. /**
  2910. * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
  2911. * R_Key and L_Key.
  2912. * @mr - struct ib_mr pointer to be updated.
  2913. * @newkey - new key to be used.
  2914. */
  2915. static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
  2916. {
  2917. mr->lkey = (mr->lkey & 0xffffff00) | newkey;
  2918. mr->rkey = (mr->rkey & 0xffffff00) | newkey;
  2919. }
  2920. /**
  2921. * ib_inc_rkey - increments the key portion of the given rkey. Can be used
  2922. * for calculating a new rkey for type 2 memory windows.
  2923. * @rkey - the rkey to increment.
  2924. */
  2925. static inline u32 ib_inc_rkey(u32 rkey)
  2926. {
  2927. const u32 mask = 0x000000ff;
  2928. return ((rkey + 1) & mask) | (rkey & ~mask);
  2929. }
  2930. /**
  2931. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  2932. * @pd: The protection domain associated with the unmapped region.
  2933. * @mr_access_flags: Specifies the memory access rights.
  2934. * @fmr_attr: Attributes of the unmapped region.
  2935. *
  2936. * A fast memory region must be mapped before it can be used as part of
  2937. * a work request.
  2938. */
  2939. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  2940. int mr_access_flags,
  2941. struct ib_fmr_attr *fmr_attr);
  2942. /**
  2943. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  2944. * @fmr: The fast memory region to associate with the pages.
  2945. * @page_list: An array of physical pages to map to the fast memory region.
  2946. * @list_len: The number of pages in page_list.
  2947. * @iova: The I/O virtual address to use with the mapped region.
  2948. */
  2949. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  2950. u64 *page_list, int list_len,
  2951. u64 iova)
  2952. {
  2953. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  2954. }
  2955. /**
  2956. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  2957. * @fmr_list: A linked list of fast memory regions to unmap.
  2958. */
  2959. int ib_unmap_fmr(struct list_head *fmr_list);
  2960. /**
  2961. * ib_dealloc_fmr - Deallocates a fast memory region.
  2962. * @fmr: The fast memory region to deallocate.
  2963. */
  2964. int ib_dealloc_fmr(struct ib_fmr *fmr);
  2965. /**
  2966. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  2967. * @qp: QP to attach to the multicast group. The QP must be type
  2968. * IB_QPT_UD.
  2969. * @gid: Multicast group GID.
  2970. * @lid: Multicast group LID in host byte order.
  2971. *
  2972. * In order to send and receive multicast packets, subnet
  2973. * administration must have created the multicast group and configured
  2974. * the fabric appropriately. The port associated with the specified
  2975. * QP must also be a member of the multicast group.
  2976. */
  2977. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2978. /**
  2979. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  2980. * @qp: QP to detach from the multicast group.
  2981. * @gid: Multicast group GID.
  2982. * @lid: Multicast group LID in host byte order.
  2983. */
  2984. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2985. /**
  2986. * ib_alloc_xrcd - Allocates an XRC domain.
  2987. * @device: The device on which to allocate the XRC domain.
  2988. */
  2989. struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
  2990. /**
  2991. * ib_dealloc_xrcd - Deallocates an XRC domain.
  2992. * @xrcd: The XRC domain to deallocate.
  2993. */
  2994. int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  2995. struct ib_flow *ib_create_flow(struct ib_qp *qp,
  2996. struct ib_flow_attr *flow_attr, int domain);
  2997. int ib_destroy_flow(struct ib_flow *flow_id);
  2998. static inline int ib_check_mr_access(int flags)
  2999. {
  3000. /*
  3001. * Local write permission is required if remote write or
  3002. * remote atomic permission is also requested.
  3003. */
  3004. if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
  3005. !(flags & IB_ACCESS_LOCAL_WRITE))
  3006. return -EINVAL;
  3007. return 0;
  3008. }
  3009. static inline bool ib_access_writable(int access_flags)
  3010. {
  3011. /*
  3012. * We have writable memory backing the MR if any of the following
  3013. * access flags are set. "Local write" and "remote write" obviously
  3014. * require write access. "Remote atomic" can do things like fetch and
  3015. * add, which will modify memory, and "MW bind" can change permissions
  3016. * by binding a window.
  3017. */
  3018. return access_flags &
  3019. (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE |
  3020. IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND);
  3021. }
  3022. /**
  3023. * ib_check_mr_status: lightweight check of MR status.
  3024. * This routine may provide status checks on a selected
  3025. * ib_mr. first use is for signature status check.
  3026. *
  3027. * @mr: A memory region.
  3028. * @check_mask: Bitmask of which checks to perform from
  3029. * ib_mr_status_check enumeration.
  3030. * @mr_status: The container of relevant status checks.
  3031. * failed checks will be indicated in the status bitmask
  3032. * and the relevant info shall be in the error item.
  3033. */
  3034. int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
  3035. struct ib_mr_status *mr_status);
  3036. struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
  3037. u16 pkey, const union ib_gid *gid,
  3038. const struct sockaddr *addr);
  3039. struct ib_wq *ib_create_wq(struct ib_pd *pd,
  3040. struct ib_wq_init_attr *init_attr);
  3041. int ib_destroy_wq(struct ib_wq *wq);
  3042. int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
  3043. u32 wq_attr_mask);
  3044. struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
  3045. struct ib_rwq_ind_table_init_attr*
  3046. wq_ind_table_init_attr);
  3047. int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
  3048. int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  3049. unsigned int *sg_offset, unsigned int page_size);
  3050. static inline int
  3051. ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  3052. unsigned int *sg_offset, unsigned int page_size)
  3053. {
  3054. int n;
  3055. n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
  3056. mr->iova = 0;
  3057. return n;
  3058. }
  3059. int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
  3060. unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
  3061. void ib_drain_rq(struct ib_qp *qp);
  3062. void ib_drain_sq(struct ib_qp *qp);
  3063. void ib_drain_qp(struct ib_qp *qp);
  3064. #endif /* IB_VERBS_H */