ib_verbs.h 140 KB

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