ib_verbs.h 121 KB

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