ib_verbs.h 115 KB

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