ib_verbs.h 97 KB

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