ib_verbs.h 103 KB

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