ib_verbs.h 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179
  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 const struct ib_rdma_wr *rdma_wr(const 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 const struct ib_atomic_wr *atomic_wr(const 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 const struct ib_ud_wr *ud_wr(const 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 const struct ib_reg_wr *reg_wr(const 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 const struct ib_sig_handover_wr *
  1272. sig_handover_wr(const struct ib_send_wr *wr)
  1273. {
  1274. return container_of(wr, struct ib_sig_handover_wr, wr);
  1275. }
  1276. struct ib_recv_wr {
  1277. struct ib_recv_wr *next;
  1278. union {
  1279. u64 wr_id;
  1280. struct ib_cqe *wr_cqe;
  1281. };
  1282. struct ib_sge *sg_list;
  1283. int num_sge;
  1284. };
  1285. enum ib_access_flags {
  1286. IB_ACCESS_LOCAL_WRITE = IB_UVERBS_ACCESS_LOCAL_WRITE,
  1287. IB_ACCESS_REMOTE_WRITE = IB_UVERBS_ACCESS_REMOTE_WRITE,
  1288. IB_ACCESS_REMOTE_READ = IB_UVERBS_ACCESS_REMOTE_READ,
  1289. IB_ACCESS_REMOTE_ATOMIC = IB_UVERBS_ACCESS_REMOTE_ATOMIC,
  1290. IB_ACCESS_MW_BIND = IB_UVERBS_ACCESS_MW_BIND,
  1291. IB_ZERO_BASED = IB_UVERBS_ACCESS_ZERO_BASED,
  1292. IB_ACCESS_ON_DEMAND = IB_UVERBS_ACCESS_ON_DEMAND,
  1293. IB_ACCESS_HUGETLB = IB_UVERBS_ACCESS_HUGETLB,
  1294. IB_ACCESS_SUPPORTED = ((IB_ACCESS_HUGETLB << 1) - 1)
  1295. };
  1296. /*
  1297. * XXX: these are apparently used for ->rereg_user_mr, no idea why they
  1298. * are hidden here instead of a uapi header!
  1299. */
  1300. enum ib_mr_rereg_flags {
  1301. IB_MR_REREG_TRANS = 1,
  1302. IB_MR_REREG_PD = (1<<1),
  1303. IB_MR_REREG_ACCESS = (1<<2),
  1304. IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
  1305. };
  1306. struct ib_fmr_attr {
  1307. int max_pages;
  1308. int max_maps;
  1309. u8 page_shift;
  1310. };
  1311. struct ib_umem;
  1312. enum rdma_remove_reason {
  1313. /*
  1314. * Userspace requested uobject deletion or initial try
  1315. * to remove uobject via cleanup. Call could fail
  1316. */
  1317. RDMA_REMOVE_DESTROY,
  1318. /* Context deletion. This call should delete the actual object itself */
  1319. RDMA_REMOVE_CLOSE,
  1320. /* Driver is being hot-unplugged. This call should delete the actual object itself */
  1321. RDMA_REMOVE_DRIVER_REMOVE,
  1322. /* uobj is being cleaned-up before being committed */
  1323. RDMA_REMOVE_ABORT,
  1324. };
  1325. struct ib_rdmacg_object {
  1326. #ifdef CONFIG_CGROUP_RDMA
  1327. struct rdma_cgroup *cg; /* owner rdma cgroup */
  1328. #endif
  1329. };
  1330. struct ib_ucontext {
  1331. struct ib_device *device;
  1332. struct ib_uverbs_file *ufile;
  1333. /*
  1334. * 'closing' can be read by the driver only during a destroy callback,
  1335. * it is set when we are closing the file descriptor and indicates
  1336. * that mm_sem may be locked.
  1337. */
  1338. int closing;
  1339. bool cleanup_retryable;
  1340. struct pid *tgid;
  1341. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  1342. struct rb_root_cached umem_tree;
  1343. /*
  1344. * Protects .umem_rbroot and tree, as well as odp_mrs_count and
  1345. * mmu notifiers registration.
  1346. */
  1347. struct rw_semaphore umem_rwsem;
  1348. void (*invalidate_range)(struct ib_umem *umem,
  1349. unsigned long start, unsigned long end);
  1350. struct mmu_notifier mn;
  1351. atomic_t notifier_count;
  1352. /* A list of umems that don't have private mmu notifier counters yet. */
  1353. struct list_head no_private_counters;
  1354. int odp_mrs_count;
  1355. #endif
  1356. struct ib_rdmacg_object cg_obj;
  1357. };
  1358. struct ib_uobject {
  1359. u64 user_handle; /* handle given to us by userspace */
  1360. /* ufile & ucontext owning this object */
  1361. struct ib_uverbs_file *ufile;
  1362. /* FIXME, save memory: ufile->context == context */
  1363. struct ib_ucontext *context; /* associated user context */
  1364. void *object; /* containing object */
  1365. struct list_head list; /* link to context's list */
  1366. struct ib_rdmacg_object cg_obj; /* rdmacg object */
  1367. int id; /* index into kernel idr */
  1368. struct kref ref;
  1369. atomic_t usecnt; /* protects exclusive access */
  1370. struct rcu_head rcu; /* kfree_rcu() overhead */
  1371. const struct uverbs_api_object *uapi_object;
  1372. };
  1373. struct ib_udata {
  1374. const void __user *inbuf;
  1375. void __user *outbuf;
  1376. size_t inlen;
  1377. size_t outlen;
  1378. };
  1379. struct ib_pd {
  1380. u32 local_dma_lkey;
  1381. u32 flags;
  1382. struct ib_device *device;
  1383. struct ib_uobject *uobject;
  1384. atomic_t usecnt; /* count all resources */
  1385. u32 unsafe_global_rkey;
  1386. /*
  1387. * Implementation details of the RDMA core, don't use in drivers:
  1388. */
  1389. struct ib_mr *__internal_mr;
  1390. struct rdma_restrack_entry res;
  1391. };
  1392. struct ib_xrcd {
  1393. struct ib_device *device;
  1394. atomic_t usecnt; /* count all exposed resources */
  1395. struct inode *inode;
  1396. struct mutex tgt_qp_mutex;
  1397. struct list_head tgt_qp_list;
  1398. };
  1399. struct ib_ah {
  1400. struct ib_device *device;
  1401. struct ib_pd *pd;
  1402. struct ib_uobject *uobject;
  1403. const struct ib_gid_attr *sgid_attr;
  1404. enum rdma_ah_attr_type type;
  1405. };
  1406. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  1407. enum ib_poll_context {
  1408. IB_POLL_DIRECT, /* caller context, no hw completions */
  1409. IB_POLL_SOFTIRQ, /* poll from softirq context */
  1410. IB_POLL_WORKQUEUE, /* poll from workqueue */
  1411. };
  1412. struct ib_cq {
  1413. struct ib_device *device;
  1414. struct ib_uobject *uobject;
  1415. ib_comp_handler comp_handler;
  1416. void (*event_handler)(struct ib_event *, void *);
  1417. void *cq_context;
  1418. int cqe;
  1419. atomic_t usecnt; /* count number of work queues */
  1420. enum ib_poll_context poll_ctx;
  1421. struct ib_wc *wc;
  1422. union {
  1423. struct irq_poll iop;
  1424. struct work_struct work;
  1425. };
  1426. /*
  1427. * Implementation details of the RDMA core, don't use in drivers:
  1428. */
  1429. struct rdma_restrack_entry res;
  1430. };
  1431. struct ib_srq {
  1432. struct ib_device *device;
  1433. struct ib_pd *pd;
  1434. struct ib_uobject *uobject;
  1435. void (*event_handler)(struct ib_event *, void *);
  1436. void *srq_context;
  1437. enum ib_srq_type srq_type;
  1438. atomic_t usecnt;
  1439. struct {
  1440. struct ib_cq *cq;
  1441. union {
  1442. struct {
  1443. struct ib_xrcd *xrcd;
  1444. u32 srq_num;
  1445. } xrc;
  1446. };
  1447. } ext;
  1448. };
  1449. enum ib_raw_packet_caps {
  1450. /* Strip cvlan from incoming packet and report it in the matching work
  1451. * completion is supported.
  1452. */
  1453. IB_RAW_PACKET_CAP_CVLAN_STRIPPING = (1 << 0),
  1454. /* Scatter FCS field of an incoming packet to host memory is supported.
  1455. */
  1456. IB_RAW_PACKET_CAP_SCATTER_FCS = (1 << 1),
  1457. /* Checksum offloads are supported (for both send and receive). */
  1458. IB_RAW_PACKET_CAP_IP_CSUM = (1 << 2),
  1459. /* When a packet is received for an RQ with no receive WQEs, the
  1460. * packet processing is delayed.
  1461. */
  1462. IB_RAW_PACKET_CAP_DELAY_DROP = (1 << 3),
  1463. };
  1464. enum ib_wq_type {
  1465. IB_WQT_RQ
  1466. };
  1467. enum ib_wq_state {
  1468. IB_WQS_RESET,
  1469. IB_WQS_RDY,
  1470. IB_WQS_ERR
  1471. };
  1472. struct ib_wq {
  1473. struct ib_device *device;
  1474. struct ib_uobject *uobject;
  1475. void *wq_context;
  1476. void (*event_handler)(struct ib_event *, void *);
  1477. struct ib_pd *pd;
  1478. struct ib_cq *cq;
  1479. u32 wq_num;
  1480. enum ib_wq_state state;
  1481. enum ib_wq_type wq_type;
  1482. atomic_t usecnt;
  1483. };
  1484. enum ib_wq_flags {
  1485. IB_WQ_FLAGS_CVLAN_STRIPPING = 1 << 0,
  1486. IB_WQ_FLAGS_SCATTER_FCS = 1 << 1,
  1487. IB_WQ_FLAGS_DELAY_DROP = 1 << 2,
  1488. IB_WQ_FLAGS_PCI_WRITE_END_PADDING = 1 << 3,
  1489. };
  1490. struct ib_wq_init_attr {
  1491. void *wq_context;
  1492. enum ib_wq_type wq_type;
  1493. u32 max_wr;
  1494. u32 max_sge;
  1495. struct ib_cq *cq;
  1496. void (*event_handler)(struct ib_event *, void *);
  1497. u32 create_flags; /* Use enum ib_wq_flags */
  1498. };
  1499. enum ib_wq_attr_mask {
  1500. IB_WQ_STATE = 1 << 0,
  1501. IB_WQ_CUR_STATE = 1 << 1,
  1502. IB_WQ_FLAGS = 1 << 2,
  1503. };
  1504. struct ib_wq_attr {
  1505. enum ib_wq_state wq_state;
  1506. enum ib_wq_state curr_wq_state;
  1507. u32 flags; /* Use enum ib_wq_flags */
  1508. u32 flags_mask; /* Use enum ib_wq_flags */
  1509. };
  1510. struct ib_rwq_ind_table {
  1511. struct ib_device *device;
  1512. struct ib_uobject *uobject;
  1513. atomic_t usecnt;
  1514. u32 ind_tbl_num;
  1515. u32 log_ind_tbl_size;
  1516. struct ib_wq **ind_tbl;
  1517. };
  1518. struct ib_rwq_ind_table_init_attr {
  1519. u32 log_ind_tbl_size;
  1520. /* Each entry is a pointer to Receive Work Queue */
  1521. struct ib_wq **ind_tbl;
  1522. };
  1523. enum port_pkey_state {
  1524. IB_PORT_PKEY_NOT_VALID = 0,
  1525. IB_PORT_PKEY_VALID = 1,
  1526. IB_PORT_PKEY_LISTED = 2,
  1527. };
  1528. struct ib_qp_security;
  1529. struct ib_port_pkey {
  1530. enum port_pkey_state state;
  1531. u16 pkey_index;
  1532. u8 port_num;
  1533. struct list_head qp_list;
  1534. struct list_head to_error_list;
  1535. struct ib_qp_security *sec;
  1536. };
  1537. struct ib_ports_pkeys {
  1538. struct ib_port_pkey main;
  1539. struct ib_port_pkey alt;
  1540. };
  1541. struct ib_qp_security {
  1542. struct ib_qp *qp;
  1543. struct ib_device *dev;
  1544. /* Hold this mutex when changing port and pkey settings. */
  1545. struct mutex mutex;
  1546. struct ib_ports_pkeys *ports_pkeys;
  1547. /* A list of all open shared QP handles. Required to enforce security
  1548. * properly for all users of a shared QP.
  1549. */
  1550. struct list_head shared_qp_list;
  1551. void *security;
  1552. bool destroying;
  1553. atomic_t error_list_count;
  1554. struct completion error_complete;
  1555. int error_comps_pending;
  1556. };
  1557. /*
  1558. * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
  1559. * @max_read_sge: Maximum SGE elements per RDMA READ request.
  1560. */
  1561. struct ib_qp {
  1562. struct ib_device *device;
  1563. struct ib_pd *pd;
  1564. struct ib_cq *send_cq;
  1565. struct ib_cq *recv_cq;
  1566. spinlock_t mr_lock;
  1567. int mrs_used;
  1568. struct list_head rdma_mrs;
  1569. struct list_head sig_mrs;
  1570. struct ib_srq *srq;
  1571. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  1572. struct list_head xrcd_list;
  1573. /* count times opened, mcast attaches, flow attaches */
  1574. atomic_t usecnt;
  1575. struct list_head open_list;
  1576. struct ib_qp *real_qp;
  1577. struct ib_uobject *uobject;
  1578. void (*event_handler)(struct ib_event *, void *);
  1579. void *qp_context;
  1580. /* sgid_attrs associated with the AV's */
  1581. const struct ib_gid_attr *av_sgid_attr;
  1582. const struct ib_gid_attr *alt_path_sgid_attr;
  1583. u32 qp_num;
  1584. u32 max_write_sge;
  1585. u32 max_read_sge;
  1586. enum ib_qp_type qp_type;
  1587. struct ib_rwq_ind_table *rwq_ind_tbl;
  1588. struct ib_qp_security *qp_sec;
  1589. u8 port;
  1590. /*
  1591. * Implementation details of the RDMA core, don't use in drivers:
  1592. */
  1593. struct rdma_restrack_entry res;
  1594. };
  1595. struct ib_dm {
  1596. struct ib_device *device;
  1597. u32 length;
  1598. u32 flags;
  1599. struct ib_uobject *uobject;
  1600. atomic_t usecnt;
  1601. };
  1602. struct ib_mr {
  1603. struct ib_device *device;
  1604. struct ib_pd *pd;
  1605. u32 lkey;
  1606. u32 rkey;
  1607. u64 iova;
  1608. u64 length;
  1609. unsigned int page_size;
  1610. bool need_inval;
  1611. union {
  1612. struct ib_uobject *uobject; /* user */
  1613. struct list_head qp_entry; /* FR */
  1614. };
  1615. struct ib_dm *dm;
  1616. /*
  1617. * Implementation details of the RDMA core, don't use in drivers:
  1618. */
  1619. struct rdma_restrack_entry res;
  1620. };
  1621. struct ib_mw {
  1622. struct ib_device *device;
  1623. struct ib_pd *pd;
  1624. struct ib_uobject *uobject;
  1625. u32 rkey;
  1626. enum ib_mw_type type;
  1627. };
  1628. struct ib_fmr {
  1629. struct ib_device *device;
  1630. struct ib_pd *pd;
  1631. struct list_head list;
  1632. u32 lkey;
  1633. u32 rkey;
  1634. };
  1635. /* Supported steering options */
  1636. enum ib_flow_attr_type {
  1637. /* steering according to rule specifications */
  1638. IB_FLOW_ATTR_NORMAL = 0x0,
  1639. /* default unicast and multicast rule -
  1640. * receive all Eth traffic which isn't steered to any QP
  1641. */
  1642. IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
  1643. /* default multicast rule -
  1644. * receive all Eth multicast traffic which isn't steered to any QP
  1645. */
  1646. IB_FLOW_ATTR_MC_DEFAULT = 0x2,
  1647. /* sniffer rule - receive all port traffic */
  1648. IB_FLOW_ATTR_SNIFFER = 0x3
  1649. };
  1650. /* Supported steering header types */
  1651. enum ib_flow_spec_type {
  1652. /* L2 headers*/
  1653. IB_FLOW_SPEC_ETH = 0x20,
  1654. IB_FLOW_SPEC_IB = 0x22,
  1655. /* L3 header*/
  1656. IB_FLOW_SPEC_IPV4 = 0x30,
  1657. IB_FLOW_SPEC_IPV6 = 0x31,
  1658. IB_FLOW_SPEC_ESP = 0x34,
  1659. /* L4 headers*/
  1660. IB_FLOW_SPEC_TCP = 0x40,
  1661. IB_FLOW_SPEC_UDP = 0x41,
  1662. IB_FLOW_SPEC_VXLAN_TUNNEL = 0x50,
  1663. IB_FLOW_SPEC_GRE = 0x51,
  1664. IB_FLOW_SPEC_MPLS = 0x60,
  1665. IB_FLOW_SPEC_INNER = 0x100,
  1666. /* Actions */
  1667. IB_FLOW_SPEC_ACTION_TAG = 0x1000,
  1668. IB_FLOW_SPEC_ACTION_DROP = 0x1001,
  1669. IB_FLOW_SPEC_ACTION_HANDLE = 0x1002,
  1670. IB_FLOW_SPEC_ACTION_COUNT = 0x1003,
  1671. };
  1672. #define IB_FLOW_SPEC_LAYER_MASK 0xF0
  1673. #define IB_FLOW_SPEC_SUPPORT_LAYERS 10
  1674. /* Flow steering rule priority is set according to it's domain.
  1675. * Lower domain value means higher priority.
  1676. */
  1677. enum ib_flow_domain {
  1678. IB_FLOW_DOMAIN_USER,
  1679. IB_FLOW_DOMAIN_ETHTOOL,
  1680. IB_FLOW_DOMAIN_RFS,
  1681. IB_FLOW_DOMAIN_NIC,
  1682. IB_FLOW_DOMAIN_NUM /* Must be last */
  1683. };
  1684. enum ib_flow_flags {
  1685. IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
  1686. IB_FLOW_ATTR_FLAGS_EGRESS = 1UL << 2, /* Egress flow */
  1687. IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 3 /* Must be last */
  1688. };
  1689. struct ib_flow_eth_filter {
  1690. u8 dst_mac[6];
  1691. u8 src_mac[6];
  1692. __be16 ether_type;
  1693. __be16 vlan_tag;
  1694. /* Must be last */
  1695. u8 real_sz[0];
  1696. };
  1697. struct ib_flow_spec_eth {
  1698. u32 type;
  1699. u16 size;
  1700. struct ib_flow_eth_filter val;
  1701. struct ib_flow_eth_filter mask;
  1702. };
  1703. struct ib_flow_ib_filter {
  1704. __be16 dlid;
  1705. __u8 sl;
  1706. /* Must be last */
  1707. u8 real_sz[0];
  1708. };
  1709. struct ib_flow_spec_ib {
  1710. u32 type;
  1711. u16 size;
  1712. struct ib_flow_ib_filter val;
  1713. struct ib_flow_ib_filter mask;
  1714. };
  1715. /* IPv4 header flags */
  1716. enum ib_ipv4_flags {
  1717. IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
  1718. IB_IPV4_MORE_FRAG = 0X4 /* For All fragmented packets except the
  1719. last have this flag set */
  1720. };
  1721. struct ib_flow_ipv4_filter {
  1722. __be32 src_ip;
  1723. __be32 dst_ip;
  1724. u8 proto;
  1725. u8 tos;
  1726. u8 ttl;
  1727. u8 flags;
  1728. /* Must be last */
  1729. u8 real_sz[0];
  1730. };
  1731. struct ib_flow_spec_ipv4 {
  1732. u32 type;
  1733. u16 size;
  1734. struct ib_flow_ipv4_filter val;
  1735. struct ib_flow_ipv4_filter mask;
  1736. };
  1737. struct ib_flow_ipv6_filter {
  1738. u8 src_ip[16];
  1739. u8 dst_ip[16];
  1740. __be32 flow_label;
  1741. u8 next_hdr;
  1742. u8 traffic_class;
  1743. u8 hop_limit;
  1744. /* Must be last */
  1745. u8 real_sz[0];
  1746. };
  1747. struct ib_flow_spec_ipv6 {
  1748. u32 type;
  1749. u16 size;
  1750. struct ib_flow_ipv6_filter val;
  1751. struct ib_flow_ipv6_filter mask;
  1752. };
  1753. struct ib_flow_tcp_udp_filter {
  1754. __be16 dst_port;
  1755. __be16 src_port;
  1756. /* Must be last */
  1757. u8 real_sz[0];
  1758. };
  1759. struct ib_flow_spec_tcp_udp {
  1760. u32 type;
  1761. u16 size;
  1762. struct ib_flow_tcp_udp_filter val;
  1763. struct ib_flow_tcp_udp_filter mask;
  1764. };
  1765. struct ib_flow_tunnel_filter {
  1766. __be32 tunnel_id;
  1767. u8 real_sz[0];
  1768. };
  1769. /* ib_flow_spec_tunnel describes the Vxlan tunnel
  1770. * the tunnel_id from val has the vni value
  1771. */
  1772. struct ib_flow_spec_tunnel {
  1773. u32 type;
  1774. u16 size;
  1775. struct ib_flow_tunnel_filter val;
  1776. struct ib_flow_tunnel_filter mask;
  1777. };
  1778. struct ib_flow_esp_filter {
  1779. __be32 spi;
  1780. __be32 seq;
  1781. /* Must be last */
  1782. u8 real_sz[0];
  1783. };
  1784. struct ib_flow_spec_esp {
  1785. u32 type;
  1786. u16 size;
  1787. struct ib_flow_esp_filter val;
  1788. struct ib_flow_esp_filter mask;
  1789. };
  1790. struct ib_flow_gre_filter {
  1791. __be16 c_ks_res0_ver;
  1792. __be16 protocol;
  1793. __be32 key;
  1794. /* Must be last */
  1795. u8 real_sz[0];
  1796. };
  1797. struct ib_flow_spec_gre {
  1798. u32 type;
  1799. u16 size;
  1800. struct ib_flow_gre_filter val;
  1801. struct ib_flow_gre_filter mask;
  1802. };
  1803. struct ib_flow_mpls_filter {
  1804. __be32 tag;
  1805. /* Must be last */
  1806. u8 real_sz[0];
  1807. };
  1808. struct ib_flow_spec_mpls {
  1809. u32 type;
  1810. u16 size;
  1811. struct ib_flow_mpls_filter val;
  1812. struct ib_flow_mpls_filter mask;
  1813. };
  1814. struct ib_flow_spec_action_tag {
  1815. enum ib_flow_spec_type type;
  1816. u16 size;
  1817. u32 tag_id;
  1818. };
  1819. struct ib_flow_spec_action_drop {
  1820. enum ib_flow_spec_type type;
  1821. u16 size;
  1822. };
  1823. struct ib_flow_spec_action_handle {
  1824. enum ib_flow_spec_type type;
  1825. u16 size;
  1826. struct ib_flow_action *act;
  1827. };
  1828. enum ib_counters_description {
  1829. IB_COUNTER_PACKETS,
  1830. IB_COUNTER_BYTES,
  1831. };
  1832. struct ib_flow_spec_action_count {
  1833. enum ib_flow_spec_type type;
  1834. u16 size;
  1835. struct ib_counters *counters;
  1836. };
  1837. union ib_flow_spec {
  1838. struct {
  1839. u32 type;
  1840. u16 size;
  1841. };
  1842. struct ib_flow_spec_eth eth;
  1843. struct ib_flow_spec_ib ib;
  1844. struct ib_flow_spec_ipv4 ipv4;
  1845. struct ib_flow_spec_tcp_udp tcp_udp;
  1846. struct ib_flow_spec_ipv6 ipv6;
  1847. struct ib_flow_spec_tunnel tunnel;
  1848. struct ib_flow_spec_esp esp;
  1849. struct ib_flow_spec_gre gre;
  1850. struct ib_flow_spec_mpls mpls;
  1851. struct ib_flow_spec_action_tag flow_tag;
  1852. struct ib_flow_spec_action_drop drop;
  1853. struct ib_flow_spec_action_handle action;
  1854. struct ib_flow_spec_action_count flow_count;
  1855. };
  1856. struct ib_flow_attr {
  1857. enum ib_flow_attr_type type;
  1858. u16 size;
  1859. u16 priority;
  1860. u32 flags;
  1861. u8 num_of_specs;
  1862. u8 port;
  1863. union ib_flow_spec flows[];
  1864. };
  1865. struct ib_flow {
  1866. struct ib_qp *qp;
  1867. struct ib_device *device;
  1868. struct ib_uobject *uobject;
  1869. };
  1870. enum ib_flow_action_type {
  1871. IB_FLOW_ACTION_UNSPECIFIED,
  1872. IB_FLOW_ACTION_ESP = 1,
  1873. };
  1874. struct ib_flow_action_attrs_esp_keymats {
  1875. enum ib_uverbs_flow_action_esp_keymat protocol;
  1876. union {
  1877. struct ib_uverbs_flow_action_esp_keymat_aes_gcm aes_gcm;
  1878. } keymat;
  1879. };
  1880. struct ib_flow_action_attrs_esp_replays {
  1881. enum ib_uverbs_flow_action_esp_replay protocol;
  1882. union {
  1883. struct ib_uverbs_flow_action_esp_replay_bmp bmp;
  1884. } replay;
  1885. };
  1886. enum ib_flow_action_attrs_esp_flags {
  1887. /* All user-space flags at the top: Use enum ib_uverbs_flow_action_esp_flags
  1888. * This is done in order to share the same flags between user-space and
  1889. * kernel and spare an unnecessary translation.
  1890. */
  1891. /* Kernel flags */
  1892. IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED = 1ULL << 32,
  1893. IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS = 1ULL << 33,
  1894. };
  1895. struct ib_flow_spec_list {
  1896. struct ib_flow_spec_list *next;
  1897. union ib_flow_spec spec;
  1898. };
  1899. struct ib_flow_action_attrs_esp {
  1900. struct ib_flow_action_attrs_esp_keymats *keymat;
  1901. struct ib_flow_action_attrs_esp_replays *replay;
  1902. struct ib_flow_spec_list *encap;
  1903. /* Used only if IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED is enabled.
  1904. * Value of 0 is a valid value.
  1905. */
  1906. u32 esn;
  1907. u32 spi;
  1908. u32 seq;
  1909. u32 tfc_pad;
  1910. /* Use enum ib_flow_action_attrs_esp_flags */
  1911. u64 flags;
  1912. u64 hard_limit_pkts;
  1913. };
  1914. struct ib_flow_action {
  1915. struct ib_device *device;
  1916. struct ib_uobject *uobject;
  1917. enum ib_flow_action_type type;
  1918. atomic_t usecnt;
  1919. };
  1920. struct ib_mad_hdr;
  1921. struct ib_grh;
  1922. enum ib_process_mad_flags {
  1923. IB_MAD_IGNORE_MKEY = 1,
  1924. IB_MAD_IGNORE_BKEY = 2,
  1925. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  1926. };
  1927. enum ib_mad_result {
  1928. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  1929. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  1930. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  1931. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  1932. };
  1933. struct ib_port_cache {
  1934. u64 subnet_prefix;
  1935. struct ib_pkey_cache *pkey;
  1936. struct ib_gid_table *gid;
  1937. u8 lmc;
  1938. enum ib_port_state port_state;
  1939. };
  1940. struct ib_cache {
  1941. rwlock_t lock;
  1942. struct ib_event_handler event_handler;
  1943. struct ib_port_cache *ports;
  1944. };
  1945. struct iw_cm_verbs;
  1946. struct ib_port_immutable {
  1947. int pkey_tbl_len;
  1948. int gid_tbl_len;
  1949. u32 core_cap_flags;
  1950. u32 max_mad_size;
  1951. };
  1952. /* rdma netdev type - specifies protocol type */
  1953. enum rdma_netdev_t {
  1954. RDMA_NETDEV_OPA_VNIC,
  1955. RDMA_NETDEV_IPOIB,
  1956. };
  1957. /**
  1958. * struct rdma_netdev - rdma netdev
  1959. * For cases where netstack interfacing is required.
  1960. */
  1961. struct rdma_netdev {
  1962. void *clnt_priv;
  1963. struct ib_device *hca;
  1964. u8 port_num;
  1965. /*
  1966. * cleanup function must be specified.
  1967. * FIXME: This is only used for OPA_VNIC and that usage should be
  1968. * removed too.
  1969. */
  1970. void (*free_rdma_netdev)(struct net_device *netdev);
  1971. /* control functions */
  1972. void (*set_id)(struct net_device *netdev, int id);
  1973. /* send packet */
  1974. int (*send)(struct net_device *dev, struct sk_buff *skb,
  1975. struct ib_ah *address, u32 dqpn);
  1976. /* multicast */
  1977. int (*attach_mcast)(struct net_device *dev, struct ib_device *hca,
  1978. union ib_gid *gid, u16 mlid,
  1979. int set_qkey, u32 qkey);
  1980. int (*detach_mcast)(struct net_device *dev, struct ib_device *hca,
  1981. union ib_gid *gid, u16 mlid);
  1982. };
  1983. struct ib_port_pkey_list {
  1984. /* Lock to hold while modifying the list. */
  1985. spinlock_t list_lock;
  1986. struct list_head pkey_list;
  1987. };
  1988. struct ib_counters {
  1989. struct ib_device *device;
  1990. struct ib_uobject *uobject;
  1991. /* num of objects attached */
  1992. atomic_t usecnt;
  1993. };
  1994. struct ib_counters_read_attr {
  1995. u64 *counters_buff;
  1996. u32 ncounters;
  1997. u32 flags; /* use enum ib_read_counters_flags */
  1998. };
  1999. struct uverbs_attr_bundle;
  2000. struct ib_device {
  2001. /* Do not access @dma_device directly from ULP nor from HW drivers. */
  2002. struct device *dma_device;
  2003. char name[IB_DEVICE_NAME_MAX];
  2004. struct list_head event_handler_list;
  2005. spinlock_t event_handler_lock;
  2006. spinlock_t client_data_lock;
  2007. struct list_head core_list;
  2008. /* Access to the client_data_list is protected by the client_data_lock
  2009. * spinlock and the lists_rwsem read-write semaphore */
  2010. struct list_head client_data_list;
  2011. struct ib_cache cache;
  2012. /**
  2013. * port_immutable is indexed by port number
  2014. */
  2015. struct ib_port_immutable *port_immutable;
  2016. int num_comp_vectors;
  2017. struct ib_port_pkey_list *port_pkey_list;
  2018. struct iw_cm_verbs *iwcm;
  2019. /**
  2020. * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
  2021. * driver initialized data. The struct is kfree()'ed by the sysfs
  2022. * core when the device is removed. A lifespan of -1 in the return
  2023. * struct tells the core to set a default lifespan.
  2024. */
  2025. struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
  2026. u8 port_num);
  2027. /**
  2028. * get_hw_stats - Fill in the counter value(s) in the stats struct.
  2029. * @index - The index in the value array we wish to have updated, or
  2030. * num_counters if we want all stats updated
  2031. * Return codes -
  2032. * < 0 - Error, no counters updated
  2033. * index - Updated the single counter pointed to by index
  2034. * num_counters - Updated all counters (will reset the timestamp
  2035. * and prevent further calls for lifespan milliseconds)
  2036. * Drivers are allowed to update all counters in leiu of just the
  2037. * one given in index at their option
  2038. */
  2039. int (*get_hw_stats)(struct ib_device *device,
  2040. struct rdma_hw_stats *stats,
  2041. u8 port, int index);
  2042. int (*query_device)(struct ib_device *device,
  2043. struct ib_device_attr *device_attr,
  2044. struct ib_udata *udata);
  2045. int (*query_port)(struct ib_device *device,
  2046. u8 port_num,
  2047. struct ib_port_attr *port_attr);
  2048. enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
  2049. u8 port_num);
  2050. /* When calling get_netdev, the HW vendor's driver should return the
  2051. * net device of device @device at port @port_num or NULL if such
  2052. * a net device doesn't exist. The vendor driver should call dev_hold
  2053. * on this net device. The HW vendor's device driver must guarantee
  2054. * that this function returns NULL before the net device has finished
  2055. * NETDEV_UNREGISTER state.
  2056. */
  2057. struct net_device *(*get_netdev)(struct ib_device *device,
  2058. u8 port_num);
  2059. /* query_gid should be return GID value for @device, when @port_num
  2060. * link layer is either IB or iWarp. It is no-op if @port_num port
  2061. * is RoCE link layer.
  2062. */
  2063. int (*query_gid)(struct ib_device *device,
  2064. u8 port_num, int index,
  2065. union ib_gid *gid);
  2066. /* When calling add_gid, the HW vendor's driver should add the gid
  2067. * of device of port at gid index available at @attr. Meta-info of
  2068. * that gid (for example, the network device related to this gid) is
  2069. * available at @attr. @context allows the HW vendor driver to store
  2070. * extra information together with a GID entry. The HW vendor driver may
  2071. * allocate memory to contain this information and store it in @context
  2072. * when a new GID entry is written to. Params are consistent until the
  2073. * next call of add_gid or delete_gid. The function should return 0 on
  2074. * success or error otherwise. The function could be called
  2075. * concurrently for different ports. This function is only called when
  2076. * roce_gid_table is used.
  2077. */
  2078. int (*add_gid)(const struct ib_gid_attr *attr,
  2079. void **context);
  2080. /* When calling del_gid, the HW vendor's driver should delete the
  2081. * gid of device @device at gid index gid_index of port port_num
  2082. * available in @attr.
  2083. * Upon the deletion of a GID entry, the HW vendor must free any
  2084. * allocated memory. The caller will clear @context afterwards.
  2085. * This function is only called when roce_gid_table is used.
  2086. */
  2087. int (*del_gid)(const struct ib_gid_attr *attr,
  2088. void **context);
  2089. int (*query_pkey)(struct ib_device *device,
  2090. u8 port_num, u16 index, u16 *pkey);
  2091. int (*modify_device)(struct ib_device *device,
  2092. int device_modify_mask,
  2093. struct ib_device_modify *device_modify);
  2094. int (*modify_port)(struct ib_device *device,
  2095. u8 port_num, int port_modify_mask,
  2096. struct ib_port_modify *port_modify);
  2097. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  2098. struct ib_udata *udata);
  2099. int (*dealloc_ucontext)(struct ib_ucontext *context);
  2100. int (*mmap)(struct ib_ucontext *context,
  2101. struct vm_area_struct *vma);
  2102. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  2103. struct ib_ucontext *context,
  2104. struct ib_udata *udata);
  2105. int (*dealloc_pd)(struct ib_pd *pd);
  2106. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  2107. struct rdma_ah_attr *ah_attr,
  2108. struct ib_udata *udata);
  2109. int (*modify_ah)(struct ib_ah *ah,
  2110. struct rdma_ah_attr *ah_attr);
  2111. int (*query_ah)(struct ib_ah *ah,
  2112. struct rdma_ah_attr *ah_attr);
  2113. int (*destroy_ah)(struct ib_ah *ah);
  2114. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  2115. struct ib_srq_init_attr *srq_init_attr,
  2116. struct ib_udata *udata);
  2117. int (*modify_srq)(struct ib_srq *srq,
  2118. struct ib_srq_attr *srq_attr,
  2119. enum ib_srq_attr_mask srq_attr_mask,
  2120. struct ib_udata *udata);
  2121. int (*query_srq)(struct ib_srq *srq,
  2122. struct ib_srq_attr *srq_attr);
  2123. int (*destroy_srq)(struct ib_srq *srq);
  2124. int (*post_srq_recv)(struct ib_srq *srq,
  2125. const struct ib_recv_wr *recv_wr,
  2126. const struct ib_recv_wr **bad_recv_wr);
  2127. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  2128. struct ib_qp_init_attr *qp_init_attr,
  2129. struct ib_udata *udata);
  2130. int (*modify_qp)(struct ib_qp *qp,
  2131. struct ib_qp_attr *qp_attr,
  2132. int qp_attr_mask,
  2133. struct ib_udata *udata);
  2134. int (*query_qp)(struct ib_qp *qp,
  2135. struct ib_qp_attr *qp_attr,
  2136. int qp_attr_mask,
  2137. struct ib_qp_init_attr *qp_init_attr);
  2138. int (*destroy_qp)(struct ib_qp *qp);
  2139. int (*post_send)(struct ib_qp *qp,
  2140. const struct ib_send_wr *send_wr,
  2141. const struct ib_send_wr **bad_send_wr);
  2142. int (*post_recv)(struct ib_qp *qp,
  2143. const struct ib_recv_wr *recv_wr,
  2144. const struct ib_recv_wr **bad_recv_wr);
  2145. struct ib_cq * (*create_cq)(struct ib_device *device,
  2146. const struct ib_cq_init_attr *attr,
  2147. struct ib_ucontext *context,
  2148. struct ib_udata *udata);
  2149. int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
  2150. u16 cq_period);
  2151. int (*destroy_cq)(struct ib_cq *cq);
  2152. int (*resize_cq)(struct ib_cq *cq, int cqe,
  2153. struct ib_udata *udata);
  2154. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  2155. struct ib_wc *wc);
  2156. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  2157. int (*req_notify_cq)(struct ib_cq *cq,
  2158. enum ib_cq_notify_flags flags);
  2159. int (*req_ncomp_notif)(struct ib_cq *cq,
  2160. int wc_cnt);
  2161. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  2162. int mr_access_flags);
  2163. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  2164. u64 start, u64 length,
  2165. u64 virt_addr,
  2166. int mr_access_flags,
  2167. struct ib_udata *udata);
  2168. int (*rereg_user_mr)(struct ib_mr *mr,
  2169. int flags,
  2170. u64 start, u64 length,
  2171. u64 virt_addr,
  2172. int mr_access_flags,
  2173. struct ib_pd *pd,
  2174. struct ib_udata *udata);
  2175. int (*dereg_mr)(struct ib_mr *mr);
  2176. struct ib_mr * (*alloc_mr)(struct ib_pd *pd,
  2177. enum ib_mr_type mr_type,
  2178. u32 max_num_sg);
  2179. int (*map_mr_sg)(struct ib_mr *mr,
  2180. struct scatterlist *sg,
  2181. int sg_nents,
  2182. unsigned int *sg_offset);
  2183. struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
  2184. enum ib_mw_type type,
  2185. struct ib_udata *udata);
  2186. int (*dealloc_mw)(struct ib_mw *mw);
  2187. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  2188. int mr_access_flags,
  2189. struct ib_fmr_attr *fmr_attr);
  2190. int (*map_phys_fmr)(struct ib_fmr *fmr,
  2191. u64 *page_list, int list_len,
  2192. u64 iova);
  2193. int (*unmap_fmr)(struct list_head *fmr_list);
  2194. int (*dealloc_fmr)(struct ib_fmr *fmr);
  2195. int (*attach_mcast)(struct ib_qp *qp,
  2196. union ib_gid *gid,
  2197. u16 lid);
  2198. int (*detach_mcast)(struct ib_qp *qp,
  2199. union ib_gid *gid,
  2200. u16 lid);
  2201. int (*process_mad)(struct ib_device *device,
  2202. int process_mad_flags,
  2203. u8 port_num,
  2204. const struct ib_wc *in_wc,
  2205. const struct ib_grh *in_grh,
  2206. const struct ib_mad_hdr *in_mad,
  2207. size_t in_mad_size,
  2208. struct ib_mad_hdr *out_mad,
  2209. size_t *out_mad_size,
  2210. u16 *out_mad_pkey_index);
  2211. struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
  2212. struct ib_ucontext *ucontext,
  2213. struct ib_udata *udata);
  2214. int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
  2215. struct ib_flow * (*create_flow)(struct ib_qp *qp,
  2216. struct ib_flow_attr
  2217. *flow_attr,
  2218. int domain,
  2219. struct ib_udata *udata);
  2220. int (*destroy_flow)(struct ib_flow *flow_id);
  2221. int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
  2222. struct ib_mr_status *mr_status);
  2223. void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
  2224. void (*drain_rq)(struct ib_qp *qp);
  2225. void (*drain_sq)(struct ib_qp *qp);
  2226. int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
  2227. int state);
  2228. int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
  2229. struct ifla_vf_info *ivf);
  2230. int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
  2231. struct ifla_vf_stats *stats);
  2232. int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
  2233. int type);
  2234. struct ib_wq * (*create_wq)(struct ib_pd *pd,
  2235. struct ib_wq_init_attr *init_attr,
  2236. struct ib_udata *udata);
  2237. int (*destroy_wq)(struct ib_wq *wq);
  2238. int (*modify_wq)(struct ib_wq *wq,
  2239. struct ib_wq_attr *attr,
  2240. u32 wq_attr_mask,
  2241. struct ib_udata *udata);
  2242. struct ib_rwq_ind_table * (*create_rwq_ind_table)(struct ib_device *device,
  2243. struct ib_rwq_ind_table_init_attr *init_attr,
  2244. struct ib_udata *udata);
  2245. int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
  2246. struct ib_flow_action * (*create_flow_action_esp)(struct ib_device *device,
  2247. const struct ib_flow_action_attrs_esp *attr,
  2248. struct uverbs_attr_bundle *attrs);
  2249. int (*destroy_flow_action)(struct ib_flow_action *action);
  2250. int (*modify_flow_action_esp)(struct ib_flow_action *action,
  2251. const struct ib_flow_action_attrs_esp *attr,
  2252. struct uverbs_attr_bundle *attrs);
  2253. struct ib_dm * (*alloc_dm)(struct ib_device *device,
  2254. struct ib_ucontext *context,
  2255. struct ib_dm_alloc_attr *attr,
  2256. struct uverbs_attr_bundle *attrs);
  2257. int (*dealloc_dm)(struct ib_dm *dm);
  2258. struct ib_mr * (*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
  2259. struct ib_dm_mr_attr *attr,
  2260. struct uverbs_attr_bundle *attrs);
  2261. struct ib_counters * (*create_counters)(struct ib_device *device,
  2262. struct uverbs_attr_bundle *attrs);
  2263. int (*destroy_counters)(struct ib_counters *counters);
  2264. int (*read_counters)(struct ib_counters *counters,
  2265. struct ib_counters_read_attr *counters_read_attr,
  2266. struct uverbs_attr_bundle *attrs);
  2267. /**
  2268. * rdma netdev operation
  2269. *
  2270. * Driver implementing alloc_rdma_netdev must return -EOPNOTSUPP if it
  2271. * doesn't support the specified rdma netdev type.
  2272. */
  2273. struct net_device *(*alloc_rdma_netdev)(
  2274. struct ib_device *device,
  2275. u8 port_num,
  2276. enum rdma_netdev_t type,
  2277. const char *name,
  2278. unsigned char name_assign_type,
  2279. void (*setup)(struct net_device *));
  2280. struct module *owner;
  2281. struct device dev;
  2282. struct kobject *ports_parent;
  2283. struct list_head port_list;
  2284. enum {
  2285. IB_DEV_UNINITIALIZED,
  2286. IB_DEV_REGISTERED,
  2287. IB_DEV_UNREGISTERED
  2288. } reg_state;
  2289. int uverbs_abi_ver;
  2290. u64 uverbs_cmd_mask;
  2291. u64 uverbs_ex_cmd_mask;
  2292. char node_desc[IB_DEVICE_NODE_DESC_MAX];
  2293. __be64 node_guid;
  2294. u32 local_dma_lkey;
  2295. u16 is_switch:1;
  2296. u8 node_type;
  2297. u8 phys_port_cnt;
  2298. struct ib_device_attr attrs;
  2299. struct attribute_group *hw_stats_ag;
  2300. struct rdma_hw_stats *hw_stats;
  2301. #ifdef CONFIG_CGROUP_RDMA
  2302. struct rdmacg_device cg_device;
  2303. #endif
  2304. u32 index;
  2305. /*
  2306. * Implementation details of the RDMA core, don't use in drivers
  2307. */
  2308. struct rdma_restrack_root res;
  2309. /**
  2310. * The following mandatory functions are used only at device
  2311. * registration. Keep functions such as these at the end of this
  2312. * structure to avoid cache line misses when accessing struct ib_device
  2313. * in fast paths.
  2314. */
  2315. int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
  2316. void (*get_dev_fw_str)(struct ib_device *, char *str);
  2317. const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev,
  2318. int comp_vector);
  2319. const struct uverbs_object_tree_def *const *driver_specs;
  2320. enum rdma_driver_id driver_id;
  2321. };
  2322. struct ib_client {
  2323. char *name;
  2324. void (*add) (struct ib_device *);
  2325. void (*remove)(struct ib_device *, void *client_data);
  2326. /* Returns the net_dev belonging to this ib_client and matching the
  2327. * given parameters.
  2328. * @dev: An RDMA device that the net_dev use for communication.
  2329. * @port: A physical port number on the RDMA device.
  2330. * @pkey: P_Key that the net_dev uses if applicable.
  2331. * @gid: A GID that the net_dev uses to communicate.
  2332. * @addr: An IP address the net_dev is configured with.
  2333. * @client_data: The device's client data set by ib_set_client_data().
  2334. *
  2335. * An ib_client that implements a net_dev on top of RDMA devices
  2336. * (such as IP over IB) should implement this callback, allowing the
  2337. * rdma_cm module to find the right net_dev for a given request.
  2338. *
  2339. * The caller is responsible for calling dev_put on the returned
  2340. * netdev. */
  2341. struct net_device *(*get_net_dev_by_params)(
  2342. struct ib_device *dev,
  2343. u8 port,
  2344. u16 pkey,
  2345. const union ib_gid *gid,
  2346. const struct sockaddr *addr,
  2347. void *client_data);
  2348. struct list_head list;
  2349. };
  2350. struct ib_device *ib_alloc_device(size_t size);
  2351. void ib_dealloc_device(struct ib_device *device);
  2352. void ib_get_device_fw_str(struct ib_device *device, char *str);
  2353. int ib_register_device(struct ib_device *device,
  2354. int (*port_callback)(struct ib_device *,
  2355. u8, struct kobject *));
  2356. void ib_unregister_device(struct ib_device *device);
  2357. int ib_register_client (struct ib_client *client);
  2358. void ib_unregister_client(struct ib_client *client);
  2359. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  2360. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  2361. void *data);
  2362. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  2363. {
  2364. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  2365. }
  2366. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  2367. {
  2368. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  2369. }
  2370. static inline bool ib_is_buffer_cleared(const void __user *p,
  2371. size_t len)
  2372. {
  2373. bool ret;
  2374. u8 *buf;
  2375. if (len > USHRT_MAX)
  2376. return false;
  2377. buf = memdup_user(p, len);
  2378. if (IS_ERR(buf))
  2379. return false;
  2380. ret = !memchr_inv(buf, 0, len);
  2381. kfree(buf);
  2382. return ret;
  2383. }
  2384. static inline bool ib_is_udata_cleared(struct ib_udata *udata,
  2385. size_t offset,
  2386. size_t len)
  2387. {
  2388. return ib_is_buffer_cleared(udata->inbuf + offset, len);
  2389. }
  2390. /**
  2391. * ib_is_destroy_retryable - Check whether the uobject destruction
  2392. * is retryable.
  2393. * @ret: The initial destruction return code
  2394. * @why: remove reason
  2395. * @uobj: The uobject that is destroyed
  2396. *
  2397. * This function is a helper function that IB layer and low-level drivers
  2398. * can use to consider whether the destruction of the given uobject is
  2399. * retry-able.
  2400. * It checks the original return code, if it wasn't success the destruction
  2401. * is retryable according to the ucontext state (i.e. cleanup_retryable) and
  2402. * the remove reason. (i.e. why).
  2403. * Must be called with the object locked for destroy.
  2404. */
  2405. static inline bool ib_is_destroy_retryable(int ret, enum rdma_remove_reason why,
  2406. struct ib_uobject *uobj)
  2407. {
  2408. return ret && (why == RDMA_REMOVE_DESTROY ||
  2409. uobj->context->cleanup_retryable);
  2410. }
  2411. /**
  2412. * ib_destroy_usecnt - Called during destruction to check the usecnt
  2413. * @usecnt: The usecnt atomic
  2414. * @why: remove reason
  2415. * @uobj: The uobject that is destroyed
  2416. *
  2417. * Non-zero usecnts will block destruction unless destruction was triggered by
  2418. * a ucontext cleanup.
  2419. */
  2420. static inline int ib_destroy_usecnt(atomic_t *usecnt,
  2421. enum rdma_remove_reason why,
  2422. struct ib_uobject *uobj)
  2423. {
  2424. if (atomic_read(usecnt) && ib_is_destroy_retryable(-EBUSY, why, uobj))
  2425. return -EBUSY;
  2426. return 0;
  2427. }
  2428. /**
  2429. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  2430. * contains all required attributes and no attributes not allowed for
  2431. * the given QP state transition.
  2432. * @cur_state: Current QP state
  2433. * @next_state: Next QP state
  2434. * @type: QP type
  2435. * @mask: Mask of supplied QP attributes
  2436. * @ll : link layer of port
  2437. *
  2438. * This function is a helper function that a low-level driver's
  2439. * modify_qp method can use to validate the consumer's input. It
  2440. * checks that cur_state and next_state are valid QP states, that a
  2441. * transition from cur_state to next_state is allowed by the IB spec,
  2442. * and that the attribute mask supplied is allowed for the transition.
  2443. */
  2444. bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  2445. enum ib_qp_type type, enum ib_qp_attr_mask mask,
  2446. enum rdma_link_layer ll);
  2447. void ib_register_event_handler(struct ib_event_handler *event_handler);
  2448. void ib_unregister_event_handler(struct ib_event_handler *event_handler);
  2449. void ib_dispatch_event(struct ib_event *event);
  2450. int ib_query_port(struct ib_device *device,
  2451. u8 port_num, struct ib_port_attr *port_attr);
  2452. enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
  2453. u8 port_num);
  2454. /**
  2455. * rdma_cap_ib_switch - Check if the device is IB switch
  2456. * @device: Device to check
  2457. *
  2458. * Device driver is responsible for setting is_switch bit on
  2459. * in ib_device structure at init time.
  2460. *
  2461. * Return: true if the device is IB switch.
  2462. */
  2463. static inline bool rdma_cap_ib_switch(const struct ib_device *device)
  2464. {
  2465. return device->is_switch;
  2466. }
  2467. /**
  2468. * rdma_start_port - Return the first valid port number for the device
  2469. * specified
  2470. *
  2471. * @device: Device to be checked
  2472. *
  2473. * Return start port number
  2474. */
  2475. static inline u8 rdma_start_port(const struct ib_device *device)
  2476. {
  2477. return rdma_cap_ib_switch(device) ? 0 : 1;
  2478. }
  2479. /**
  2480. * rdma_end_port - Return the last valid port number for the device
  2481. * specified
  2482. *
  2483. * @device: Device to be checked
  2484. *
  2485. * Return last port number
  2486. */
  2487. static inline u8 rdma_end_port(const struct ib_device *device)
  2488. {
  2489. return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
  2490. }
  2491. static inline int rdma_is_port_valid(const struct ib_device *device,
  2492. unsigned int port)
  2493. {
  2494. return (port >= rdma_start_port(device) &&
  2495. port <= rdma_end_port(device));
  2496. }
  2497. static inline bool rdma_is_grh_required(const struct ib_device *device,
  2498. u8 port_num)
  2499. {
  2500. return device->port_immutable[port_num].core_cap_flags &
  2501. RDMA_CORE_PORT_IB_GRH_REQUIRED;
  2502. }
  2503. static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
  2504. {
  2505. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
  2506. }
  2507. static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
  2508. {
  2509. return device->port_immutable[port_num].core_cap_flags &
  2510. (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
  2511. }
  2512. static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
  2513. {
  2514. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
  2515. }
  2516. static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
  2517. {
  2518. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
  2519. }
  2520. static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
  2521. {
  2522. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
  2523. }
  2524. static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
  2525. {
  2526. return rdma_protocol_ib(device, port_num) ||
  2527. rdma_protocol_roce(device, port_num);
  2528. }
  2529. static inline bool rdma_protocol_raw_packet(const struct ib_device *device, u8 port_num)
  2530. {
  2531. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_RAW_PACKET;
  2532. }
  2533. static inline bool rdma_protocol_usnic(const struct ib_device *device, u8 port_num)
  2534. {
  2535. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_USNIC;
  2536. }
  2537. /**
  2538. * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
  2539. * Management Datagrams.
  2540. * @device: Device to check
  2541. * @port_num: Port number to check
  2542. *
  2543. * Management Datagrams (MAD) are a required part of the InfiniBand
  2544. * specification and are supported on all InfiniBand devices. A slightly
  2545. * extended version are also supported on OPA interfaces.
  2546. *
  2547. * Return: true if the port supports sending/receiving of MAD packets.
  2548. */
  2549. static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
  2550. {
  2551. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
  2552. }
  2553. /**
  2554. * rdma_cap_opa_mad - Check if the port of device provides support for OPA
  2555. * Management Datagrams.
  2556. * @device: Device to check
  2557. * @port_num: Port number to check
  2558. *
  2559. * Intel OmniPath devices extend and/or replace the InfiniBand Management
  2560. * datagrams with their own versions. These OPA MADs share many but not all of
  2561. * the characteristics of InfiniBand MADs.
  2562. *
  2563. * OPA MADs differ in the following ways:
  2564. *
  2565. * 1) MADs are variable size up to 2K
  2566. * IBTA defined MADs remain fixed at 256 bytes
  2567. * 2) OPA SMPs must carry valid PKeys
  2568. * 3) OPA SMP packets are a different format
  2569. *
  2570. * Return: true if the port supports OPA MAD packet formats.
  2571. */
  2572. static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
  2573. {
  2574. return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
  2575. == RDMA_CORE_CAP_OPA_MAD;
  2576. }
  2577. /**
  2578. * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
  2579. * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
  2580. * @device: Device to check
  2581. * @port_num: Port number to check
  2582. *
  2583. * Each InfiniBand node is required to provide a Subnet Management Agent
  2584. * that the subnet manager can access. Prior to the fabric being fully
  2585. * configured by the subnet manager, the SMA is accessed via a well known
  2586. * interface called the Subnet Management Interface (SMI). This interface
  2587. * uses directed route packets to communicate with the SM to get around the
  2588. * chicken and egg problem of the SM needing to know what's on the fabric
  2589. * in order to configure the fabric, and needing to configure the fabric in
  2590. * order to send packets to the devices on the fabric. These directed
  2591. * route packets do not need the fabric fully configured in order to reach
  2592. * their destination. The SMI is the only method allowed to send
  2593. * directed route packets on an InfiniBand fabric.
  2594. *
  2595. * Return: true if the port provides an SMI.
  2596. */
  2597. static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
  2598. {
  2599. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
  2600. }
  2601. /**
  2602. * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
  2603. * Communication Manager.
  2604. * @device: Device to check
  2605. * @port_num: Port number to check
  2606. *
  2607. * The InfiniBand Communication Manager is one of many pre-defined General
  2608. * Service Agents (GSA) that are accessed via the General Service
  2609. * Interface (GSI). It's role is to facilitate establishment of connections
  2610. * between nodes as well as other management related tasks for established
  2611. * connections.
  2612. *
  2613. * Return: true if the port supports an IB CM (this does not guarantee that
  2614. * a CM is actually running however).
  2615. */
  2616. static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
  2617. {
  2618. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
  2619. }
  2620. /**
  2621. * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
  2622. * Communication Manager.
  2623. * @device: Device to check
  2624. * @port_num: Port number to check
  2625. *
  2626. * Similar to above, but specific to iWARP connections which have a different
  2627. * managment protocol than InfiniBand.
  2628. *
  2629. * Return: true if the port supports an iWARP CM (this does not guarantee that
  2630. * a CM is actually running however).
  2631. */
  2632. static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
  2633. {
  2634. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
  2635. }
  2636. /**
  2637. * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
  2638. * Subnet Administration.
  2639. * @device: Device to check
  2640. * @port_num: Port number to check
  2641. *
  2642. * An InfiniBand Subnet Administration (SA) service is a pre-defined General
  2643. * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
  2644. * fabrics, devices should resolve routes to other hosts by contacting the
  2645. * SA to query the proper route.
  2646. *
  2647. * Return: true if the port should act as a client to the fabric Subnet
  2648. * Administration interface. This does not imply that the SA service is
  2649. * running locally.
  2650. */
  2651. static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
  2652. {
  2653. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
  2654. }
  2655. /**
  2656. * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
  2657. * Multicast.
  2658. * @device: Device to check
  2659. * @port_num: Port number to check
  2660. *
  2661. * InfiniBand multicast registration is more complex than normal IPv4 or
  2662. * IPv6 multicast registration. Each Host Channel Adapter must register
  2663. * with the Subnet Manager when it wishes to join a multicast group. It
  2664. * should do so only once regardless of how many queue pairs it subscribes
  2665. * to this group. And it should leave the group only after all queue pairs
  2666. * attached to the group have been detached.
  2667. *
  2668. * Return: true if the port must undertake the additional adminstrative
  2669. * overhead of registering/unregistering with the SM and tracking of the
  2670. * total number of queue pairs attached to the multicast group.
  2671. */
  2672. static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
  2673. {
  2674. return rdma_cap_ib_sa(device, port_num);
  2675. }
  2676. /**
  2677. * rdma_cap_af_ib - Check if the port of device has the capability
  2678. * Native Infiniband Address.
  2679. * @device: Device to check
  2680. * @port_num: Port number to check
  2681. *
  2682. * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
  2683. * GID. RoCE uses a different mechanism, but still generates a GID via
  2684. * a prescribed mechanism and port specific data.
  2685. *
  2686. * Return: true if the port uses a GID address to identify devices on the
  2687. * network.
  2688. */
  2689. static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
  2690. {
  2691. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
  2692. }
  2693. /**
  2694. * rdma_cap_eth_ah - Check if the port of device has the capability
  2695. * Ethernet Address Handle.
  2696. * @device: Device to check
  2697. * @port_num: Port number to check
  2698. *
  2699. * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
  2700. * to fabricate GIDs over Ethernet/IP specific addresses native to the
  2701. * port. Normally, packet headers are generated by the sending host
  2702. * adapter, but when sending connectionless datagrams, we must manually
  2703. * inject the proper headers for the fabric we are communicating over.
  2704. *
  2705. * Return: true if we are running as a RoCE port and must force the
  2706. * addition of a Global Route Header built from our Ethernet Address
  2707. * Handle into our header list for connectionless packets.
  2708. */
  2709. static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
  2710. {
  2711. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
  2712. }
  2713. /**
  2714. * rdma_cap_opa_ah - Check if the port of device supports
  2715. * OPA Address handles
  2716. * @device: Device to check
  2717. * @port_num: Port number to check
  2718. *
  2719. * Return: true if we are running on an OPA device which supports
  2720. * the extended OPA addressing.
  2721. */
  2722. static inline bool rdma_cap_opa_ah(struct ib_device *device, u8 port_num)
  2723. {
  2724. return (device->port_immutable[port_num].core_cap_flags &
  2725. RDMA_CORE_CAP_OPA_AH) == RDMA_CORE_CAP_OPA_AH;
  2726. }
  2727. /**
  2728. * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
  2729. *
  2730. * @device: Device
  2731. * @port_num: Port number
  2732. *
  2733. * This MAD size includes the MAD headers and MAD payload. No other headers
  2734. * are included.
  2735. *
  2736. * Return the max MAD size required by the Port. Will return 0 if the port
  2737. * does not support MADs
  2738. */
  2739. static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
  2740. {
  2741. return device->port_immutable[port_num].max_mad_size;
  2742. }
  2743. /**
  2744. * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
  2745. * @device: Device to check
  2746. * @port_num: Port number to check
  2747. *
  2748. * RoCE GID table mechanism manages the various GIDs for a device.
  2749. *
  2750. * NOTE: if allocating the port's GID table has failed, this call will still
  2751. * return true, but any RoCE GID table API will fail.
  2752. *
  2753. * Return: true if the port uses RoCE GID table mechanism in order to manage
  2754. * its GIDs.
  2755. */
  2756. static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
  2757. u8 port_num)
  2758. {
  2759. return rdma_protocol_roce(device, port_num) &&
  2760. device->add_gid && device->del_gid;
  2761. }
  2762. /*
  2763. * Check if the device supports READ W/ INVALIDATE.
  2764. */
  2765. static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
  2766. {
  2767. /*
  2768. * iWarp drivers must support READ W/ INVALIDATE. No other protocol
  2769. * has support for it yet.
  2770. */
  2771. return rdma_protocol_iwarp(dev, port_num);
  2772. }
  2773. int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
  2774. int state);
  2775. int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
  2776. struct ifla_vf_info *info);
  2777. int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
  2778. struct ifla_vf_stats *stats);
  2779. int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
  2780. int type);
  2781. int ib_query_pkey(struct ib_device *device,
  2782. u8 port_num, u16 index, u16 *pkey);
  2783. int ib_modify_device(struct ib_device *device,
  2784. int device_modify_mask,
  2785. struct ib_device_modify *device_modify);
  2786. int ib_modify_port(struct ib_device *device,
  2787. u8 port_num, int port_modify_mask,
  2788. struct ib_port_modify *port_modify);
  2789. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  2790. u8 *port_num, u16 *index);
  2791. int ib_find_pkey(struct ib_device *device,
  2792. u8 port_num, u16 pkey, u16 *index);
  2793. enum ib_pd_flags {
  2794. /*
  2795. * Create a memory registration for all memory in the system and place
  2796. * the rkey for it into pd->unsafe_global_rkey. This can be used by
  2797. * ULPs to avoid the overhead of dynamic MRs.
  2798. *
  2799. * This flag is generally considered unsafe and must only be used in
  2800. * extremly trusted environments. Every use of it will log a warning
  2801. * in the kernel log.
  2802. */
  2803. IB_PD_UNSAFE_GLOBAL_RKEY = 0x01,
  2804. };
  2805. struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
  2806. const char *caller);
  2807. #define ib_alloc_pd(device, flags) \
  2808. __ib_alloc_pd((device), (flags), KBUILD_MODNAME)
  2809. void ib_dealloc_pd(struct ib_pd *pd);
  2810. /**
  2811. * rdma_create_ah - Creates an address handle for the given address vector.
  2812. * @pd: The protection domain associated with the address handle.
  2813. * @ah_attr: The attributes of the address vector.
  2814. *
  2815. * The address handle is used to reference a local or global destination
  2816. * in all UD QP post sends.
  2817. */
  2818. struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr);
  2819. /**
  2820. * rdma_create_user_ah - Creates an address handle for the given address vector.
  2821. * It resolves destination mac address for ah attribute of RoCE type.
  2822. * @pd: The protection domain associated with the address handle.
  2823. * @ah_attr: The attributes of the address vector.
  2824. * @udata: pointer to user's input output buffer information need by
  2825. * provider driver.
  2826. *
  2827. * It returns 0 on success and returns appropriate error code on error.
  2828. * The address handle is used to reference a local or global destination
  2829. * in all UD QP post sends.
  2830. */
  2831. struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
  2832. struct rdma_ah_attr *ah_attr,
  2833. struct ib_udata *udata);
  2834. /**
  2835. * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header
  2836. * work completion.
  2837. * @hdr: the L3 header to parse
  2838. * @net_type: type of header to parse
  2839. * @sgid: place to store source gid
  2840. * @dgid: place to store destination gid
  2841. */
  2842. int ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr,
  2843. enum rdma_network_type net_type,
  2844. union ib_gid *sgid, union ib_gid *dgid);
  2845. /**
  2846. * ib_get_rdma_header_version - Get the header version
  2847. * @hdr: the L3 header to parse
  2848. */
  2849. int ib_get_rdma_header_version(const union rdma_network_hdr *hdr);
  2850. /**
  2851. * ib_init_ah_attr_from_wc - Initializes address handle attributes from a
  2852. * work completion.
  2853. * @device: Device on which the received message arrived.
  2854. * @port_num: Port on which the received message arrived.
  2855. * @wc: Work completion associated with the received message.
  2856. * @grh: References the received global route header. This parameter is
  2857. * ignored unless the work completion indicates that the GRH is valid.
  2858. * @ah_attr: Returned attributes that can be used when creating an address
  2859. * handle for replying to the message.
  2860. * When ib_init_ah_attr_from_wc() returns success,
  2861. * (a) for IB link layer it optionally contains a reference to SGID attribute
  2862. * when GRH is present for IB link layer.
  2863. * (b) for RoCE link layer it contains a reference to SGID attribute.
  2864. * User must invoke rdma_cleanup_ah_attr_gid_attr() to release reference to SGID
  2865. * attributes which are initialized using ib_init_ah_attr_from_wc().
  2866. *
  2867. */
  2868. int ib_init_ah_attr_from_wc(struct ib_device *device, u8 port_num,
  2869. const struct ib_wc *wc, const struct ib_grh *grh,
  2870. struct rdma_ah_attr *ah_attr);
  2871. /**
  2872. * ib_create_ah_from_wc - Creates an address handle associated with the
  2873. * sender of the specified work completion.
  2874. * @pd: The protection domain associated with the address handle.
  2875. * @wc: Work completion information associated with a received message.
  2876. * @grh: References the received global route header. This parameter is
  2877. * ignored unless the work completion indicates that the GRH is valid.
  2878. * @port_num: The outbound port number to associate with the address.
  2879. *
  2880. * The address handle is used to reference a local or global destination
  2881. * in all UD QP post sends.
  2882. */
  2883. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
  2884. const struct ib_grh *grh, u8 port_num);
  2885. /**
  2886. * rdma_modify_ah - Modifies the address vector associated with an address
  2887. * handle.
  2888. * @ah: The address handle to modify.
  2889. * @ah_attr: The new address vector attributes to associate with the
  2890. * address handle.
  2891. */
  2892. int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
  2893. /**
  2894. * rdma_query_ah - Queries the address vector associated with an address
  2895. * handle.
  2896. * @ah: The address handle to query.
  2897. * @ah_attr: The address vector attributes associated with the address
  2898. * handle.
  2899. */
  2900. int rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
  2901. /**
  2902. * rdma_destroy_ah - Destroys an address handle.
  2903. * @ah: The address handle to destroy.
  2904. */
  2905. int rdma_destroy_ah(struct ib_ah *ah);
  2906. /**
  2907. * ib_create_srq - Creates a SRQ associated with the specified protection
  2908. * domain.
  2909. * @pd: The protection domain associated with the SRQ.
  2910. * @srq_init_attr: A list of initial attributes required to create the
  2911. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  2912. * the actual capabilities of the created SRQ.
  2913. *
  2914. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  2915. * requested size of the SRQ, and set to the actual values allocated
  2916. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  2917. * will always be at least as large as the requested values.
  2918. */
  2919. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  2920. struct ib_srq_init_attr *srq_init_attr);
  2921. /**
  2922. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  2923. * @srq: The SRQ to modify.
  2924. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  2925. * the current values of selected SRQ attributes are returned.
  2926. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  2927. * are being modified.
  2928. *
  2929. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  2930. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  2931. * the number of receives queued drops below the limit.
  2932. */
  2933. int ib_modify_srq(struct ib_srq *srq,
  2934. struct ib_srq_attr *srq_attr,
  2935. enum ib_srq_attr_mask srq_attr_mask);
  2936. /**
  2937. * ib_query_srq - Returns the attribute list and current values for the
  2938. * specified SRQ.
  2939. * @srq: The SRQ to query.
  2940. * @srq_attr: The attributes of the specified SRQ.
  2941. */
  2942. int ib_query_srq(struct ib_srq *srq,
  2943. struct ib_srq_attr *srq_attr);
  2944. /**
  2945. * ib_destroy_srq - Destroys the specified SRQ.
  2946. * @srq: The SRQ to destroy.
  2947. */
  2948. int ib_destroy_srq(struct ib_srq *srq);
  2949. /**
  2950. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  2951. * @srq: The SRQ to post the work request on.
  2952. * @recv_wr: A list of work requests to post on the receive queue.
  2953. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2954. * the work request that failed to be posted on the QP.
  2955. */
  2956. static inline int ib_post_srq_recv(struct ib_srq *srq,
  2957. const struct ib_recv_wr *recv_wr,
  2958. const struct ib_recv_wr **bad_recv_wr)
  2959. {
  2960. const struct ib_recv_wr *dummy;
  2961. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr ? : &dummy);
  2962. }
  2963. /**
  2964. * ib_create_qp - Creates a QP associated with the specified protection
  2965. * domain.
  2966. * @pd: The protection domain associated with the QP.
  2967. * @qp_init_attr: A list of initial attributes required to create the
  2968. * QP. If QP creation succeeds, then the attributes are updated to
  2969. * the actual capabilities of the created QP.
  2970. */
  2971. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  2972. struct ib_qp_init_attr *qp_init_attr);
  2973. /**
  2974. * ib_modify_qp_with_udata - Modifies the attributes for the specified QP.
  2975. * @qp: The QP to modify.
  2976. * @attr: On input, specifies the QP attributes to modify. On output,
  2977. * the current values of selected QP attributes are returned.
  2978. * @attr_mask: A bit-mask used to specify which attributes of the QP
  2979. * are being modified.
  2980. * @udata: pointer to user's input output buffer information
  2981. * are being modified.
  2982. * It returns 0 on success and returns appropriate error code on error.
  2983. */
  2984. int ib_modify_qp_with_udata(struct ib_qp *qp,
  2985. struct ib_qp_attr *attr,
  2986. int attr_mask,
  2987. struct ib_udata *udata);
  2988. /**
  2989. * ib_modify_qp - Modifies the attributes for the specified QP and then
  2990. * transitions the QP to the given state.
  2991. * @qp: The QP to modify.
  2992. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  2993. * the current values of selected QP attributes are returned.
  2994. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  2995. * are being modified.
  2996. */
  2997. int ib_modify_qp(struct ib_qp *qp,
  2998. struct ib_qp_attr *qp_attr,
  2999. int qp_attr_mask);
  3000. /**
  3001. * ib_query_qp - Returns the attribute list and current values for the
  3002. * specified QP.
  3003. * @qp: The QP to query.
  3004. * @qp_attr: The attributes of the specified QP.
  3005. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  3006. * @qp_init_attr: Additional attributes of the selected QP.
  3007. *
  3008. * The qp_attr_mask may be used to limit the query to gathering only the
  3009. * selected attributes.
  3010. */
  3011. int ib_query_qp(struct ib_qp *qp,
  3012. struct ib_qp_attr *qp_attr,
  3013. int qp_attr_mask,
  3014. struct ib_qp_init_attr *qp_init_attr);
  3015. /**
  3016. * ib_destroy_qp - Destroys the specified QP.
  3017. * @qp: The QP to destroy.
  3018. */
  3019. int ib_destroy_qp(struct ib_qp *qp);
  3020. /**
  3021. * ib_open_qp - Obtain a reference to an existing sharable QP.
  3022. * @xrcd - XRC domain
  3023. * @qp_open_attr: Attributes identifying the QP to open.
  3024. *
  3025. * Returns a reference to a sharable QP.
  3026. */
  3027. struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
  3028. struct ib_qp_open_attr *qp_open_attr);
  3029. /**
  3030. * ib_close_qp - Release an external reference to a QP.
  3031. * @qp: The QP handle to release
  3032. *
  3033. * The opened QP handle is released by the caller. The underlying
  3034. * shared QP is not destroyed until all internal references are released.
  3035. */
  3036. int ib_close_qp(struct ib_qp *qp);
  3037. /**
  3038. * ib_post_send - Posts a list of work requests to the send queue of
  3039. * the specified QP.
  3040. * @qp: The QP to post the work request on.
  3041. * @send_wr: A list of work requests to post on the send queue.
  3042. * @bad_send_wr: On an immediate failure, this parameter will reference
  3043. * the work request that failed to be posted on the QP.
  3044. *
  3045. * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
  3046. * error is returned, the QP state shall not be affected,
  3047. * ib_post_send() will return an immediate error after queueing any
  3048. * earlier work requests in the list.
  3049. */
  3050. static inline int ib_post_send(struct ib_qp *qp,
  3051. const struct ib_send_wr *send_wr,
  3052. const struct ib_send_wr **bad_send_wr)
  3053. {
  3054. const struct ib_send_wr *dummy;
  3055. return qp->device->post_send(qp, send_wr, bad_send_wr ? : &dummy);
  3056. }
  3057. /**
  3058. * ib_post_recv - Posts a list of work requests to the receive queue of
  3059. * the specified QP.
  3060. * @qp: The QP to post the work request on.
  3061. * @recv_wr: A list of work requests to post on the receive queue.
  3062. * @bad_recv_wr: On an immediate failure, this parameter will reference
  3063. * the work request that failed to be posted on the QP.
  3064. */
  3065. static inline int ib_post_recv(struct ib_qp *qp,
  3066. const struct ib_recv_wr *recv_wr,
  3067. const struct ib_recv_wr **bad_recv_wr)
  3068. {
  3069. const struct ib_recv_wr *dummy;
  3070. return qp->device->post_recv(qp, recv_wr, bad_recv_wr ? : &dummy);
  3071. }
  3072. struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private,
  3073. int nr_cqe, int comp_vector,
  3074. enum ib_poll_context poll_ctx, const char *caller);
  3075. #define ib_alloc_cq(device, priv, nr_cqe, comp_vect, poll_ctx) \
  3076. __ib_alloc_cq((device), (priv), (nr_cqe), (comp_vect), (poll_ctx), KBUILD_MODNAME)
  3077. void ib_free_cq(struct ib_cq *cq);
  3078. int ib_process_cq_direct(struct ib_cq *cq, int budget);
  3079. /**
  3080. * ib_create_cq - Creates a CQ on the specified device.
  3081. * @device: The device on which to create the CQ.
  3082. * @comp_handler: A user-specified callback that is invoked when a
  3083. * completion event occurs on the CQ.
  3084. * @event_handler: A user-specified callback that is invoked when an
  3085. * asynchronous event not associated with a completion occurs on the CQ.
  3086. * @cq_context: Context associated with the CQ returned to the user via
  3087. * the associated completion and event handlers.
  3088. * @cq_attr: The attributes the CQ should be created upon.
  3089. *
  3090. * Users can examine the cq structure to determine the actual CQ size.
  3091. */
  3092. struct ib_cq *ib_create_cq(struct ib_device *device,
  3093. ib_comp_handler comp_handler,
  3094. void (*event_handler)(struct ib_event *, void *),
  3095. void *cq_context,
  3096. const struct ib_cq_init_attr *cq_attr);
  3097. /**
  3098. * ib_resize_cq - Modifies the capacity of the CQ.
  3099. * @cq: The CQ to resize.
  3100. * @cqe: The minimum size of the CQ.
  3101. *
  3102. * Users can examine the cq structure to determine the actual CQ size.
  3103. */
  3104. int ib_resize_cq(struct ib_cq *cq, int cqe);
  3105. /**
  3106. * rdma_set_cq_moderation - Modifies moderation params of the CQ
  3107. * @cq: The CQ to modify.
  3108. * @cq_count: number of CQEs that will trigger an event
  3109. * @cq_period: max period of time in usec before triggering an event
  3110. *
  3111. */
  3112. int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  3113. /**
  3114. * ib_destroy_cq - Destroys the specified CQ.
  3115. * @cq: The CQ to destroy.
  3116. */
  3117. int ib_destroy_cq(struct ib_cq *cq);
  3118. /**
  3119. * ib_poll_cq - poll a CQ for completion(s)
  3120. * @cq:the CQ being polled
  3121. * @num_entries:maximum number of completions to return
  3122. * @wc:array of at least @num_entries &struct ib_wc where completions
  3123. * will be returned
  3124. *
  3125. * Poll a CQ for (possibly multiple) completions. If the return value
  3126. * is < 0, an error occurred. If the return value is >= 0, it is the
  3127. * number of completions returned. If the return value is
  3128. * non-negative and < num_entries, then the CQ was emptied.
  3129. */
  3130. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  3131. struct ib_wc *wc)
  3132. {
  3133. return cq->device->poll_cq(cq, num_entries, wc);
  3134. }
  3135. /**
  3136. * ib_req_notify_cq - Request completion notification on a CQ.
  3137. * @cq: The CQ to generate an event for.
  3138. * @flags:
  3139. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  3140. * to request an event on the next solicited event or next work
  3141. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  3142. * may also be |ed in to request a hint about missed events, as
  3143. * described below.
  3144. *
  3145. * Return Value:
  3146. * < 0 means an error occurred while requesting notification
  3147. * == 0 means notification was requested successfully, and if
  3148. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  3149. * were missed and it is safe to wait for another event. In
  3150. * this case is it guaranteed that any work completions added
  3151. * to the CQ since the last CQ poll will trigger a completion
  3152. * notification event.
  3153. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  3154. * in. It means that the consumer must poll the CQ again to
  3155. * make sure it is empty to avoid missing an event because of a
  3156. * race between requesting notification and an entry being
  3157. * added to the CQ. This return value means it is possible
  3158. * (but not guaranteed) that a work completion has been added
  3159. * to the CQ since the last poll without triggering a
  3160. * completion notification event.
  3161. */
  3162. static inline int ib_req_notify_cq(struct ib_cq *cq,
  3163. enum ib_cq_notify_flags flags)
  3164. {
  3165. return cq->device->req_notify_cq(cq, flags);
  3166. }
  3167. /**
  3168. * ib_req_ncomp_notif - Request completion notification when there are
  3169. * at least the specified number of unreaped completions on the CQ.
  3170. * @cq: The CQ to generate an event for.
  3171. * @wc_cnt: The number of unreaped completions that should be on the
  3172. * CQ before an event is generated.
  3173. */
  3174. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  3175. {
  3176. return cq->device->req_ncomp_notif ?
  3177. cq->device->req_ncomp_notif(cq, wc_cnt) :
  3178. -ENOSYS;
  3179. }
  3180. /**
  3181. * ib_dma_mapping_error - check a DMA addr for error
  3182. * @dev: The device for which the dma_addr was created
  3183. * @dma_addr: The DMA address to check
  3184. */
  3185. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  3186. {
  3187. return dma_mapping_error(dev->dma_device, dma_addr);
  3188. }
  3189. /**
  3190. * ib_dma_map_single - Map a kernel virtual address to DMA address
  3191. * @dev: The device for which the dma_addr is to be created
  3192. * @cpu_addr: The kernel virtual address
  3193. * @size: The size of the region in bytes
  3194. * @direction: The direction of the DMA
  3195. */
  3196. static inline u64 ib_dma_map_single(struct ib_device *dev,
  3197. void *cpu_addr, size_t size,
  3198. enum dma_data_direction direction)
  3199. {
  3200. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  3201. }
  3202. /**
  3203. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  3204. * @dev: The device for which the DMA address was created
  3205. * @addr: The DMA address
  3206. * @size: The size of the region in bytes
  3207. * @direction: The direction of the DMA
  3208. */
  3209. static inline void ib_dma_unmap_single(struct ib_device *dev,
  3210. u64 addr, size_t size,
  3211. enum dma_data_direction direction)
  3212. {
  3213. dma_unmap_single(dev->dma_device, addr, size, direction);
  3214. }
  3215. /**
  3216. * ib_dma_map_page - Map a physical page to DMA address
  3217. * @dev: The device for which the dma_addr is to be created
  3218. * @page: The page to be mapped
  3219. * @offset: The offset within the page
  3220. * @size: The size of the region in bytes
  3221. * @direction: The direction of the DMA
  3222. */
  3223. static inline u64 ib_dma_map_page(struct ib_device *dev,
  3224. struct page *page,
  3225. unsigned long offset,
  3226. size_t size,
  3227. enum dma_data_direction direction)
  3228. {
  3229. return dma_map_page(dev->dma_device, page, offset, size, direction);
  3230. }
  3231. /**
  3232. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  3233. * @dev: The device for which the DMA address was created
  3234. * @addr: The DMA address
  3235. * @size: The size of the region in bytes
  3236. * @direction: The direction of the DMA
  3237. */
  3238. static inline void ib_dma_unmap_page(struct ib_device *dev,
  3239. u64 addr, size_t size,
  3240. enum dma_data_direction direction)
  3241. {
  3242. dma_unmap_page(dev->dma_device, addr, size, direction);
  3243. }
  3244. /**
  3245. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  3246. * @dev: The device for which the DMA addresses are to be 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 int ib_dma_map_sg(struct ib_device *dev,
  3252. struct scatterlist *sg, int nents,
  3253. enum dma_data_direction direction)
  3254. {
  3255. return dma_map_sg(dev->dma_device, sg, nents, direction);
  3256. }
  3257. /**
  3258. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  3259. * @dev: The device for which the DMA addresses were created
  3260. * @sg: The array of scatter/gather entries
  3261. * @nents: The number of scatter/gather entries
  3262. * @direction: The direction of the DMA
  3263. */
  3264. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  3265. struct scatterlist *sg, int nents,
  3266. enum dma_data_direction direction)
  3267. {
  3268. dma_unmap_sg(dev->dma_device, sg, nents, direction);
  3269. }
  3270. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  3271. struct scatterlist *sg, int nents,
  3272. enum dma_data_direction direction,
  3273. unsigned long dma_attrs)
  3274. {
  3275. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
  3276. dma_attrs);
  3277. }
  3278. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  3279. struct scatterlist *sg, int nents,
  3280. enum dma_data_direction direction,
  3281. unsigned long dma_attrs)
  3282. {
  3283. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, dma_attrs);
  3284. }
  3285. /**
  3286. * ib_sg_dma_address - Return the DMA address 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_address() into sg_dma_address().
  3292. */
  3293. static inline u64 ib_sg_dma_address(struct ib_device *dev,
  3294. struct scatterlist *sg)
  3295. {
  3296. return sg_dma_address(sg);
  3297. }
  3298. /**
  3299. * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
  3300. * @dev: The device for which the DMA addresses were created
  3301. * @sg: The scatter/gather entry
  3302. *
  3303. * Note: this function is obsolete. To do: change all occurrences of
  3304. * ib_sg_dma_len() into sg_dma_len().
  3305. */
  3306. static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
  3307. struct scatterlist *sg)
  3308. {
  3309. return sg_dma_len(sg);
  3310. }
  3311. /**
  3312. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  3313. * @dev: The device for which the DMA address was created
  3314. * @addr: The DMA address
  3315. * @size: The size of the region in bytes
  3316. * @dir: The direction of the DMA
  3317. */
  3318. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  3319. u64 addr,
  3320. size_t size,
  3321. enum dma_data_direction dir)
  3322. {
  3323. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  3324. }
  3325. /**
  3326. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  3327. * @dev: The device for which the DMA address was created
  3328. * @addr: The DMA address
  3329. * @size: The size of the region in bytes
  3330. * @dir: The direction of the DMA
  3331. */
  3332. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  3333. u64 addr,
  3334. size_t size,
  3335. enum dma_data_direction dir)
  3336. {
  3337. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  3338. }
  3339. /**
  3340. * ib_dma_alloc_coherent - Allocate memory and map it for DMA
  3341. * @dev: The device for which the DMA address is requested
  3342. * @size: The size of the region to allocate in bytes
  3343. * @dma_handle: A pointer for returning the DMA address of the region
  3344. * @flag: memory allocator flags
  3345. */
  3346. static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
  3347. size_t size,
  3348. dma_addr_t *dma_handle,
  3349. gfp_t flag)
  3350. {
  3351. return dma_alloc_coherent(dev->dma_device, size, dma_handle, flag);
  3352. }
  3353. /**
  3354. * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
  3355. * @dev: The device for which the DMA addresses were allocated
  3356. * @size: The size of the region
  3357. * @cpu_addr: the address returned by ib_dma_alloc_coherent()
  3358. * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
  3359. */
  3360. static inline void ib_dma_free_coherent(struct ib_device *dev,
  3361. size_t size, void *cpu_addr,
  3362. dma_addr_t dma_handle)
  3363. {
  3364. dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
  3365. }
  3366. /**
  3367. * ib_dereg_mr - Deregisters a memory region and removes it from the
  3368. * HCA translation table.
  3369. * @mr: The memory region to deregister.
  3370. *
  3371. * This function can fail, if the memory region has memory windows bound to it.
  3372. */
  3373. int ib_dereg_mr(struct ib_mr *mr);
  3374. struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
  3375. enum ib_mr_type mr_type,
  3376. u32 max_num_sg);
  3377. /**
  3378. * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
  3379. * R_Key and L_Key.
  3380. * @mr - struct ib_mr pointer to be updated.
  3381. * @newkey - new key to be used.
  3382. */
  3383. static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
  3384. {
  3385. mr->lkey = (mr->lkey & 0xffffff00) | newkey;
  3386. mr->rkey = (mr->rkey & 0xffffff00) | newkey;
  3387. }
  3388. /**
  3389. * ib_inc_rkey - increments the key portion of the given rkey. Can be used
  3390. * for calculating a new rkey for type 2 memory windows.
  3391. * @rkey - the rkey to increment.
  3392. */
  3393. static inline u32 ib_inc_rkey(u32 rkey)
  3394. {
  3395. const u32 mask = 0x000000ff;
  3396. return ((rkey + 1) & mask) | (rkey & ~mask);
  3397. }
  3398. /**
  3399. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  3400. * @pd: The protection domain associated with the unmapped region.
  3401. * @mr_access_flags: Specifies the memory access rights.
  3402. * @fmr_attr: Attributes of the unmapped region.
  3403. *
  3404. * A fast memory region must be mapped before it can be used as part of
  3405. * a work request.
  3406. */
  3407. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  3408. int mr_access_flags,
  3409. struct ib_fmr_attr *fmr_attr);
  3410. /**
  3411. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  3412. * @fmr: The fast memory region to associate with the pages.
  3413. * @page_list: An array of physical pages to map to the fast memory region.
  3414. * @list_len: The number of pages in page_list.
  3415. * @iova: The I/O virtual address to use with the mapped region.
  3416. */
  3417. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  3418. u64 *page_list, int list_len,
  3419. u64 iova)
  3420. {
  3421. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  3422. }
  3423. /**
  3424. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  3425. * @fmr_list: A linked list of fast memory regions to unmap.
  3426. */
  3427. int ib_unmap_fmr(struct list_head *fmr_list);
  3428. /**
  3429. * ib_dealloc_fmr - Deallocates a fast memory region.
  3430. * @fmr: The fast memory region to deallocate.
  3431. */
  3432. int ib_dealloc_fmr(struct ib_fmr *fmr);
  3433. /**
  3434. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  3435. * @qp: QP to attach to the multicast group. The QP must be type
  3436. * IB_QPT_UD.
  3437. * @gid: Multicast group GID.
  3438. * @lid: Multicast group LID in host byte order.
  3439. *
  3440. * In order to send and receive multicast packets, subnet
  3441. * administration must have created the multicast group and configured
  3442. * the fabric appropriately. The port associated with the specified
  3443. * QP must also be a member of the multicast group.
  3444. */
  3445. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  3446. /**
  3447. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  3448. * @qp: QP to detach from the multicast group.
  3449. * @gid: Multicast group GID.
  3450. * @lid: Multicast group LID in host byte order.
  3451. */
  3452. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  3453. /**
  3454. * ib_alloc_xrcd - Allocates an XRC domain.
  3455. * @device: The device on which to allocate the XRC domain.
  3456. * @caller: Module name for kernel consumers
  3457. */
  3458. struct ib_xrcd *__ib_alloc_xrcd(struct ib_device *device, const char *caller);
  3459. #define ib_alloc_xrcd(device) \
  3460. __ib_alloc_xrcd((device), KBUILD_MODNAME)
  3461. /**
  3462. * ib_dealloc_xrcd - Deallocates an XRC domain.
  3463. * @xrcd: The XRC domain to deallocate.
  3464. */
  3465. int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  3466. static inline int ib_check_mr_access(int flags)
  3467. {
  3468. /*
  3469. * Local write permission is required if remote write or
  3470. * remote atomic permission is also requested.
  3471. */
  3472. if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
  3473. !(flags & IB_ACCESS_LOCAL_WRITE))
  3474. return -EINVAL;
  3475. return 0;
  3476. }
  3477. static inline bool ib_access_writable(int access_flags)
  3478. {
  3479. /*
  3480. * We have writable memory backing the MR if any of the following
  3481. * access flags are set. "Local write" and "remote write" obviously
  3482. * require write access. "Remote atomic" can do things like fetch and
  3483. * add, which will modify memory, and "MW bind" can change permissions
  3484. * by binding a window.
  3485. */
  3486. return access_flags &
  3487. (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE |
  3488. IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND);
  3489. }
  3490. /**
  3491. * ib_check_mr_status: lightweight check of MR status.
  3492. * This routine may provide status checks on a selected
  3493. * ib_mr. first use is for signature status check.
  3494. *
  3495. * @mr: A memory region.
  3496. * @check_mask: Bitmask of which checks to perform from
  3497. * ib_mr_status_check enumeration.
  3498. * @mr_status: The container of relevant status checks.
  3499. * failed checks will be indicated in the status bitmask
  3500. * and the relevant info shall be in the error item.
  3501. */
  3502. int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
  3503. struct ib_mr_status *mr_status);
  3504. struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
  3505. u16 pkey, const union ib_gid *gid,
  3506. const struct sockaddr *addr);
  3507. struct ib_wq *ib_create_wq(struct ib_pd *pd,
  3508. struct ib_wq_init_attr *init_attr);
  3509. int ib_destroy_wq(struct ib_wq *wq);
  3510. int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
  3511. u32 wq_attr_mask);
  3512. struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
  3513. struct ib_rwq_ind_table_init_attr*
  3514. wq_ind_table_init_attr);
  3515. int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
  3516. int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  3517. unsigned int *sg_offset, unsigned int page_size);
  3518. static inline int
  3519. ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  3520. unsigned int *sg_offset, unsigned int page_size)
  3521. {
  3522. int n;
  3523. n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
  3524. mr->iova = 0;
  3525. return n;
  3526. }
  3527. int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
  3528. unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
  3529. void ib_drain_rq(struct ib_qp *qp);
  3530. void ib_drain_sq(struct ib_qp *qp);
  3531. void ib_drain_qp(struct ib_qp *qp);
  3532. int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width);
  3533. static inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr)
  3534. {
  3535. if (attr->type == RDMA_AH_ATTR_TYPE_ROCE)
  3536. return attr->roce.dmac;
  3537. return NULL;
  3538. }
  3539. static inline void rdma_ah_set_dlid(struct rdma_ah_attr *attr, u32 dlid)
  3540. {
  3541. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  3542. attr->ib.dlid = (u16)dlid;
  3543. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  3544. attr->opa.dlid = dlid;
  3545. }
  3546. static inline u32 rdma_ah_get_dlid(const struct rdma_ah_attr *attr)
  3547. {
  3548. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  3549. return attr->ib.dlid;
  3550. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  3551. return attr->opa.dlid;
  3552. return 0;
  3553. }
  3554. static inline void rdma_ah_set_sl(struct rdma_ah_attr *attr, u8 sl)
  3555. {
  3556. attr->sl = sl;
  3557. }
  3558. static inline u8 rdma_ah_get_sl(const struct rdma_ah_attr *attr)
  3559. {
  3560. return attr->sl;
  3561. }
  3562. static inline void rdma_ah_set_path_bits(struct rdma_ah_attr *attr,
  3563. u8 src_path_bits)
  3564. {
  3565. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  3566. attr->ib.src_path_bits = src_path_bits;
  3567. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  3568. attr->opa.src_path_bits = src_path_bits;
  3569. }
  3570. static inline u8 rdma_ah_get_path_bits(const struct rdma_ah_attr *attr)
  3571. {
  3572. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  3573. return attr->ib.src_path_bits;
  3574. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  3575. return attr->opa.src_path_bits;
  3576. return 0;
  3577. }
  3578. static inline void rdma_ah_set_make_grd(struct rdma_ah_attr *attr,
  3579. bool make_grd)
  3580. {
  3581. if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  3582. attr->opa.make_grd = make_grd;
  3583. }
  3584. static inline bool rdma_ah_get_make_grd(const struct rdma_ah_attr *attr)
  3585. {
  3586. if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  3587. return attr->opa.make_grd;
  3588. return false;
  3589. }
  3590. static inline void rdma_ah_set_port_num(struct rdma_ah_attr *attr, u8 port_num)
  3591. {
  3592. attr->port_num = port_num;
  3593. }
  3594. static inline u8 rdma_ah_get_port_num(const struct rdma_ah_attr *attr)
  3595. {
  3596. return attr->port_num;
  3597. }
  3598. static inline void rdma_ah_set_static_rate(struct rdma_ah_attr *attr,
  3599. u8 static_rate)
  3600. {
  3601. attr->static_rate = static_rate;
  3602. }
  3603. static inline u8 rdma_ah_get_static_rate(const struct rdma_ah_attr *attr)
  3604. {
  3605. return attr->static_rate;
  3606. }
  3607. static inline void rdma_ah_set_ah_flags(struct rdma_ah_attr *attr,
  3608. enum ib_ah_flags flag)
  3609. {
  3610. attr->ah_flags = flag;
  3611. }
  3612. static inline enum ib_ah_flags
  3613. rdma_ah_get_ah_flags(const struct rdma_ah_attr *attr)
  3614. {
  3615. return attr->ah_flags;
  3616. }
  3617. static inline const struct ib_global_route
  3618. *rdma_ah_read_grh(const struct rdma_ah_attr *attr)
  3619. {
  3620. return &attr->grh;
  3621. }
  3622. /*To retrieve and modify the grh */
  3623. static inline struct ib_global_route
  3624. *rdma_ah_retrieve_grh(struct rdma_ah_attr *attr)
  3625. {
  3626. return &attr->grh;
  3627. }
  3628. static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid)
  3629. {
  3630. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  3631. memcpy(grh->dgid.raw, dgid, sizeof(grh->dgid));
  3632. }
  3633. static inline void rdma_ah_set_subnet_prefix(struct rdma_ah_attr *attr,
  3634. __be64 prefix)
  3635. {
  3636. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  3637. grh->dgid.global.subnet_prefix = prefix;
  3638. }
  3639. static inline void rdma_ah_set_interface_id(struct rdma_ah_attr *attr,
  3640. __be64 if_id)
  3641. {
  3642. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  3643. grh->dgid.global.interface_id = if_id;
  3644. }
  3645. static inline void rdma_ah_set_grh(struct rdma_ah_attr *attr,
  3646. union ib_gid *dgid, u32 flow_label,
  3647. u8 sgid_index, u8 hop_limit,
  3648. u8 traffic_class)
  3649. {
  3650. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  3651. attr->ah_flags = IB_AH_GRH;
  3652. if (dgid)
  3653. grh->dgid = *dgid;
  3654. grh->flow_label = flow_label;
  3655. grh->sgid_index = sgid_index;
  3656. grh->hop_limit = hop_limit;
  3657. grh->traffic_class = traffic_class;
  3658. grh->sgid_attr = NULL;
  3659. }
  3660. void rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr);
  3661. void rdma_move_grh_sgid_attr(struct rdma_ah_attr *attr, union ib_gid *dgid,
  3662. u32 flow_label, u8 hop_limit, u8 traffic_class,
  3663. const struct ib_gid_attr *sgid_attr);
  3664. void rdma_copy_ah_attr(struct rdma_ah_attr *dest,
  3665. const struct rdma_ah_attr *src);
  3666. void rdma_replace_ah_attr(struct rdma_ah_attr *old,
  3667. const struct rdma_ah_attr *new);
  3668. void rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src);
  3669. /**
  3670. * rdma_ah_find_type - Return address handle type.
  3671. *
  3672. * @dev: Device to be checked
  3673. * @port_num: Port number
  3674. */
  3675. static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
  3676. u8 port_num)
  3677. {
  3678. if (rdma_protocol_roce(dev, port_num))
  3679. return RDMA_AH_ATTR_TYPE_ROCE;
  3680. if (rdma_protocol_ib(dev, port_num)) {
  3681. if (rdma_cap_opa_ah(dev, port_num))
  3682. return RDMA_AH_ATTR_TYPE_OPA;
  3683. return RDMA_AH_ATTR_TYPE_IB;
  3684. }
  3685. return RDMA_AH_ATTR_TYPE_UNDEFINED;
  3686. }
  3687. /**
  3688. * ib_lid_cpu16 - Return lid in 16bit CPU encoding.
  3689. * In the current implementation the only way to get
  3690. * get the 32bit lid is from other sources for OPA.
  3691. * For IB, lids will always be 16bits so cast the
  3692. * value accordingly.
  3693. *
  3694. * @lid: A 32bit LID
  3695. */
  3696. static inline u16 ib_lid_cpu16(u32 lid)
  3697. {
  3698. WARN_ON_ONCE(lid & 0xFFFF0000);
  3699. return (u16)lid;
  3700. }
  3701. /**
  3702. * ib_lid_be16 - Return lid in 16bit BE encoding.
  3703. *
  3704. * @lid: A 32bit LID
  3705. */
  3706. static inline __be16 ib_lid_be16(u32 lid)
  3707. {
  3708. WARN_ON_ONCE(lid & 0xFFFF0000);
  3709. return cpu_to_be16((u16)lid);
  3710. }
  3711. /**
  3712. * ib_get_vector_affinity - Get the affinity mappings of a given completion
  3713. * vector
  3714. * @device: the rdma device
  3715. * @comp_vector: index of completion vector
  3716. *
  3717. * Returns NULL on failure, otherwise a corresponding cpu map of the
  3718. * completion vector (returns all-cpus map if the device driver doesn't
  3719. * implement get_vector_affinity).
  3720. */
  3721. static inline const struct cpumask *
  3722. ib_get_vector_affinity(struct ib_device *device, int comp_vector)
  3723. {
  3724. if (comp_vector < 0 || comp_vector >= device->num_comp_vectors ||
  3725. !device->get_vector_affinity)
  3726. return NULL;
  3727. return device->get_vector_affinity(device, comp_vector);
  3728. }
  3729. static inline void ib_set_flow(struct ib_uobject *uobj, struct ib_flow *ibflow,
  3730. struct ib_qp *qp, struct ib_device *device)
  3731. {
  3732. uobj->object = ibflow;
  3733. ibflow->uobject = uobj;
  3734. if (qp) {
  3735. atomic_inc(&qp->usecnt);
  3736. ibflow->qp = qp;
  3737. }
  3738. ibflow->device = device;
  3739. }
  3740. /**
  3741. * rdma_roce_rescan_device - Rescan all of the network devices in the system
  3742. * and add their gids, as needed, to the relevant RoCE devices.
  3743. *
  3744. * @device: the rdma device
  3745. */
  3746. void rdma_roce_rescan_device(struct ib_device *ibdev);
  3747. struct ib_ucontext *ib_uverbs_get_ucontext(struct ib_uverbs_file *ufile);
  3748. int uverbs_destroy_def_handler(struct ib_uverbs_file *file,
  3749. struct uverbs_attr_bundle *attrs);
  3750. #endif /* IB_VERBS_H */