ib_verbs.h 118 KB

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