ib_verbs.h 143 KB

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