ib_verbs.h 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891
  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. u64 uverbs_cmd_mask;
  2455. char node_desc[IB_DEVICE_NODE_DESC_MAX];
  2456. __be64 node_guid;
  2457. u32 local_dma_lkey;
  2458. u16 is_switch:1;
  2459. /* Indicates kernel verbs support, should not be used in drivers */
  2460. u16 kverbs_provider:1;
  2461. /* CQ adaptive moderation (RDMA DIM) */
  2462. u16 use_cq_dim:1;
  2463. u8 node_type;
  2464. u32 phys_port_cnt;
  2465. struct ib_device_attr attrs;
  2466. struct hw_stats_device_data *hw_stats_data;
  2467. #ifdef CONFIG_CGROUP_RDMA
  2468. struct rdmacg_device cg_device;
  2469. #endif
  2470. u32 index;
  2471. spinlock_t cq_pools_lock;
  2472. struct list_head cq_pools[IB_POLL_LAST_POOL_TYPE + 1];
  2473. struct rdma_restrack_root *res;
  2474. const struct uapi_definition *driver_def;
  2475. /*
  2476. * Positive refcount indicates that the device is currently
  2477. * registered and cannot be unregistered.
  2478. */
  2479. refcount_t refcount;
  2480. struct completion unreg_completion;
  2481. struct work_struct unregistration_work;
  2482. const struct rdma_link_ops *link_ops;
  2483. /* Protects compat_devs xarray modifications */
  2484. struct mutex compat_devs_mutex;
  2485. /* Maintains compat devices for each net namespace */
  2486. struct xarray compat_devs;
  2487. /* Used by iWarp CM */
  2488. char iw_ifname[IFNAMSIZ];
  2489. u32 iw_driver_flags;
  2490. u32 lag_flags;
  2491. /* A parent device has a list of sub-devices */
  2492. struct mutex subdev_lock;
  2493. struct list_head subdev_list_head;
  2494. /* A sub device has a type and a parent */
  2495. enum rdma_nl_dev_type type;
  2496. struct ib_device *parent;
  2497. struct list_head subdev_list;
  2498. enum rdma_nl_name_assign_type name_assign_type;
  2499. };
  2500. static inline void *rdma_zalloc_obj(struct ib_device *dev, size_t size,
  2501. gfp_t gfp, bool is_numa_aware)
  2502. {
  2503. if (is_numa_aware && dev->ops.get_numa_node)
  2504. return kzalloc_node(size, gfp, dev->ops.get_numa_node(dev));
  2505. return kzalloc(size, gfp);
  2506. }
  2507. struct ib_client_nl_info;
  2508. struct ib_client {
  2509. const char *name;
  2510. int (*add)(struct ib_device *ibdev);
  2511. void (*remove)(struct ib_device *, void *client_data);
  2512. void (*rename)(struct ib_device *dev, void *client_data);
  2513. int (*get_nl_info)(struct ib_device *ibdev, void *client_data,
  2514. struct ib_client_nl_info *res);
  2515. int (*get_global_nl_info)(struct ib_client_nl_info *res);
  2516. /* Returns the net_dev belonging to this ib_client and matching the
  2517. * given parameters.
  2518. * @dev: An RDMA device that the net_dev use for communication.
  2519. * @port: A physical port number on the RDMA device.
  2520. * @pkey: P_Key that the net_dev uses if applicable.
  2521. * @gid: A GID that the net_dev uses to communicate.
  2522. * @addr: An IP address the net_dev is configured with.
  2523. * @client_data: The device's client data set by ib_set_client_data().
  2524. *
  2525. * An ib_client that implements a net_dev on top of RDMA devices
  2526. * (such as IP over IB) should implement this callback, allowing the
  2527. * rdma_cm module to find the right net_dev for a given request.
  2528. *
  2529. * The caller is responsible for calling dev_put on the returned
  2530. * netdev. */
  2531. struct net_device *(*get_net_dev_by_params)(
  2532. struct ib_device *dev,
  2533. u32 port,
  2534. u16 pkey,
  2535. const union ib_gid *gid,
  2536. const struct sockaddr *addr,
  2537. void *client_data);
  2538. refcount_t uses;
  2539. struct completion uses_zero;
  2540. u32 client_id;
  2541. /* kverbs are not required by the client */
  2542. u8 no_kverbs_req:1;
  2543. };
  2544. /*
  2545. * IB block DMA iterator
  2546. *
  2547. * Iterates the DMA-mapped SGL in contiguous memory blocks aligned
  2548. * to a HW supported page size.
  2549. */
  2550. struct ib_block_iter {
  2551. /* internal states */
  2552. struct scatterlist *__sg; /* sg holding the current aligned block */
  2553. dma_addr_t __dma_addr; /* unaligned DMA address of this block */
  2554. size_t __sg_numblocks; /* ib_umem_num_dma_blocks() */
  2555. unsigned int __sg_nents; /* number of SG entries */
  2556. unsigned int __sg_advance; /* number of bytes to advance in sg in next step */
  2557. unsigned int __pg_bit; /* alignment of current block */
  2558. };
  2559. struct ib_device *_ib_alloc_device(size_t size);
  2560. #define ib_alloc_device(drv_struct, member) \
  2561. container_of(_ib_alloc_device(sizeof(struct drv_struct) + \
  2562. BUILD_BUG_ON_ZERO(offsetof( \
  2563. struct drv_struct, member))), \
  2564. struct drv_struct, member)
  2565. void ib_dealloc_device(struct ib_device *device);
  2566. void ib_get_device_fw_str(struct ib_device *device, char *str);
  2567. int ib_register_device(struct ib_device *device, const char *name,
  2568. struct device *dma_device);
  2569. void ib_unregister_device(struct ib_device *device);
  2570. void ib_unregister_driver(enum rdma_driver_id driver_id);
  2571. void ib_unregister_device_and_put(struct ib_device *device);
  2572. void ib_unregister_device_queued(struct ib_device *ib_dev);
  2573. int ib_register_client (struct ib_client *client);
  2574. void ib_unregister_client(struct ib_client *client);
  2575. void __rdma_block_iter_start(struct ib_block_iter *biter,
  2576. struct scatterlist *sglist,
  2577. unsigned int nents,
  2578. unsigned long pgsz);
  2579. bool __rdma_block_iter_next(struct ib_block_iter *biter);
  2580. /**
  2581. * rdma_block_iter_dma_address - get the aligned dma address of the current
  2582. * block held by the block iterator.
  2583. * @biter: block iterator holding the memory block
  2584. */
  2585. static inline dma_addr_t
  2586. rdma_block_iter_dma_address(struct ib_block_iter *biter)
  2587. {
  2588. return biter->__dma_addr & ~(BIT_ULL(biter->__pg_bit) - 1);
  2589. }
  2590. /**
  2591. * rdma_for_each_block - iterate over contiguous memory blocks of the sg list
  2592. * @sglist: sglist to iterate over
  2593. * @biter: block iterator holding the memory block
  2594. * @nents: maximum number of sg entries to iterate over
  2595. * @pgsz: best HW supported page size to use
  2596. *
  2597. * Callers may use rdma_block_iter_dma_address() to get each
  2598. * blocks aligned DMA address.
  2599. */
  2600. #define rdma_for_each_block(sglist, biter, nents, pgsz) \
  2601. for (__rdma_block_iter_start(biter, sglist, nents, \
  2602. pgsz); \
  2603. __rdma_block_iter_next(biter);)
  2604. /**
  2605. * ib_get_client_data - Get IB client context
  2606. * @device:Device to get context for
  2607. * @client:Client to get context for
  2608. *
  2609. * ib_get_client_data() returns the client context data set with
  2610. * ib_set_client_data(). This can only be called while the client is
  2611. * registered to the device, once the ib_client remove() callback returns this
  2612. * cannot be called.
  2613. */
  2614. static inline void *ib_get_client_data(struct ib_device *device,
  2615. struct ib_client *client)
  2616. {
  2617. return xa_load(&device->client_data, client->client_id);
  2618. }
  2619. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  2620. void *data);
  2621. void ib_set_device_ops(struct ib_device *device,
  2622. const struct ib_device_ops *ops);
  2623. int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma,
  2624. unsigned long pfn, unsigned long size, pgprot_t prot,
  2625. struct rdma_user_mmap_entry *entry);
  2626. int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
  2627. struct rdma_user_mmap_entry *entry,
  2628. size_t length);
  2629. int rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
  2630. struct rdma_user_mmap_entry *entry,
  2631. size_t length, u32 min_pgoff,
  2632. u32 max_pgoff);
  2633. #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
  2634. void rdma_user_mmap_disassociate(struct ib_device *device);
  2635. #else
  2636. static inline void rdma_user_mmap_disassociate(struct ib_device *device)
  2637. {
  2638. }
  2639. #endif
  2640. static inline int
  2641. rdma_user_mmap_entry_insert_exact(struct ib_ucontext *ucontext,
  2642. struct rdma_user_mmap_entry *entry,
  2643. size_t length, u32 pgoff)
  2644. {
  2645. return rdma_user_mmap_entry_insert_range(ucontext, entry, length, pgoff,
  2646. pgoff);
  2647. }
  2648. struct rdma_user_mmap_entry *
  2649. rdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext,
  2650. unsigned long pgoff);
  2651. struct rdma_user_mmap_entry *
  2652. rdma_user_mmap_entry_get(struct ib_ucontext *ucontext,
  2653. struct vm_area_struct *vma);
  2654. void rdma_user_mmap_entry_put(struct rdma_user_mmap_entry *entry);
  2655. void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry);
  2656. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  2657. {
  2658. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  2659. }
  2660. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  2661. {
  2662. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  2663. }
  2664. static inline bool ib_is_buffer_cleared(const void __user *p,
  2665. size_t len)
  2666. {
  2667. bool ret;
  2668. u8 *buf;
  2669. if (len > USHRT_MAX)
  2670. return false;
  2671. buf = memdup_user(p, len);
  2672. if (IS_ERR(buf))
  2673. return false;
  2674. ret = !memchr_inv(buf, 0, len);
  2675. kfree(buf);
  2676. return ret;
  2677. }
  2678. static inline bool ib_is_udata_cleared(struct ib_udata *udata,
  2679. size_t offset,
  2680. size_t len)
  2681. {
  2682. return ib_is_buffer_cleared(udata->inbuf + offset, len);
  2683. }
  2684. /**
  2685. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  2686. * contains all required attributes and no attributes not allowed for
  2687. * the given QP state transition.
  2688. * @cur_state: Current QP state
  2689. * @next_state: Next QP state
  2690. * @type: QP type
  2691. * @mask: Mask of supplied QP attributes
  2692. *
  2693. * This function is a helper function that a low-level driver's
  2694. * modify_qp method can use to validate the consumer's input. It
  2695. * checks that cur_state and next_state are valid QP states, that a
  2696. * transition from cur_state to next_state is allowed by the IB spec,
  2697. * and that the attribute mask supplied is allowed for the transition.
  2698. */
  2699. bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  2700. enum ib_qp_type type, enum ib_qp_attr_mask mask);
  2701. void ib_register_event_handler(struct ib_event_handler *event_handler);
  2702. void ib_unregister_event_handler(struct ib_event_handler *event_handler);
  2703. void ib_dispatch_event(const struct ib_event *event);
  2704. int ib_query_port(struct ib_device *device,
  2705. u32 port_num, struct ib_port_attr *port_attr);
  2706. enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
  2707. u32 port_num);
  2708. /**
  2709. * rdma_cap_ib_switch - Check if the device is IB switch
  2710. * @device: Device to check
  2711. *
  2712. * Device driver is responsible for setting is_switch bit on
  2713. * in ib_device structure at init time.
  2714. *
  2715. * Return: true if the device is IB switch.
  2716. */
  2717. static inline bool rdma_cap_ib_switch(const struct ib_device *device)
  2718. {
  2719. return device->is_switch;
  2720. }
  2721. /**
  2722. * rdma_start_port - Return the first valid port number for the device
  2723. * specified
  2724. *
  2725. * @device: Device to be checked
  2726. *
  2727. * Return start port number
  2728. */
  2729. static inline u32 rdma_start_port(const struct ib_device *device)
  2730. {
  2731. return rdma_cap_ib_switch(device) ? 0 : 1;
  2732. }
  2733. /**
  2734. * rdma_for_each_port - Iterate over all valid port numbers of the IB device
  2735. * @device - The struct ib_device * to iterate over
  2736. * @iter - The unsigned int to store the port number
  2737. */
  2738. #define rdma_for_each_port(device, iter) \
  2739. for (iter = rdma_start_port(device + \
  2740. BUILD_BUG_ON_ZERO(!__same_type(u32, \
  2741. iter))); \
  2742. iter <= rdma_end_port(device); iter++)
  2743. /**
  2744. * rdma_end_port - Return the last valid port number for the device
  2745. * specified
  2746. *
  2747. * @device: Device to be checked
  2748. *
  2749. * Return last port number
  2750. */
  2751. static inline u32 rdma_end_port(const struct ib_device *device)
  2752. {
  2753. return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
  2754. }
  2755. static inline int rdma_is_port_valid(const struct ib_device *device,
  2756. unsigned int port)
  2757. {
  2758. return (port >= rdma_start_port(device) &&
  2759. port <= rdma_end_port(device));
  2760. }
  2761. static inline bool rdma_is_grh_required(const struct ib_device *device,
  2762. u32 port_num)
  2763. {
  2764. return device->port_data[port_num].immutable.core_cap_flags &
  2765. RDMA_CORE_PORT_IB_GRH_REQUIRED;
  2766. }
  2767. static inline bool rdma_protocol_ib(const struct ib_device *device,
  2768. u32 port_num)
  2769. {
  2770. return device->port_data[port_num].immutable.core_cap_flags &
  2771. RDMA_CORE_CAP_PROT_IB;
  2772. }
  2773. static inline bool rdma_protocol_roce(const struct ib_device *device,
  2774. u32 port_num)
  2775. {
  2776. return device->port_data[port_num].immutable.core_cap_flags &
  2777. (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
  2778. }
  2779. static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device,
  2780. u32 port_num)
  2781. {
  2782. return device->port_data[port_num].immutable.core_cap_flags &
  2783. RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
  2784. }
  2785. static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device,
  2786. u32 port_num)
  2787. {
  2788. return device->port_data[port_num].immutable.core_cap_flags &
  2789. RDMA_CORE_CAP_PROT_ROCE;
  2790. }
  2791. static inline bool rdma_protocol_iwarp(const struct ib_device *device,
  2792. u32 port_num)
  2793. {
  2794. return device->port_data[port_num].immutable.core_cap_flags &
  2795. RDMA_CORE_CAP_PROT_IWARP;
  2796. }
  2797. static inline bool rdma_ib_or_roce(const struct ib_device *device,
  2798. u32 port_num)
  2799. {
  2800. return rdma_protocol_ib(device, port_num) ||
  2801. rdma_protocol_roce(device, port_num);
  2802. }
  2803. static inline bool rdma_protocol_raw_packet(const struct ib_device *device,
  2804. u32 port_num)
  2805. {
  2806. return device->port_data[port_num].immutable.core_cap_flags &
  2807. RDMA_CORE_CAP_PROT_RAW_PACKET;
  2808. }
  2809. static inline bool rdma_protocol_usnic(const struct ib_device *device,
  2810. u32 port_num)
  2811. {
  2812. return device->port_data[port_num].immutable.core_cap_flags &
  2813. RDMA_CORE_CAP_PROT_USNIC;
  2814. }
  2815. /**
  2816. * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
  2817. * Management Datagrams.
  2818. * @device: Device to check
  2819. * @port_num: Port number to check
  2820. *
  2821. * Management Datagrams (MAD) are a required part of the InfiniBand
  2822. * specification and are supported on all InfiniBand devices. A slightly
  2823. * extended version are also supported on OPA interfaces.
  2824. *
  2825. * Return: true if the port supports sending/receiving of MAD packets.
  2826. */
  2827. static inline bool rdma_cap_ib_mad(const struct ib_device *device, u32 port_num)
  2828. {
  2829. return device->port_data[port_num].immutable.core_cap_flags &
  2830. RDMA_CORE_CAP_IB_MAD;
  2831. }
  2832. /**
  2833. * rdma_cap_opa_mad - Check if the port of device provides support for OPA
  2834. * Management Datagrams.
  2835. * @device: Device to check
  2836. * @port_num: Port number to check
  2837. *
  2838. * Intel OmniPath devices extend and/or replace the InfiniBand Management
  2839. * datagrams with their own versions. These OPA MADs share many but not all of
  2840. * the characteristics of InfiniBand MADs.
  2841. *
  2842. * OPA MADs differ in the following ways:
  2843. *
  2844. * 1) MADs are variable size up to 2K
  2845. * IBTA defined MADs remain fixed at 256 bytes
  2846. * 2) OPA SMPs must carry valid PKeys
  2847. * 3) OPA SMP packets are a different format
  2848. *
  2849. * Return: true if the port supports OPA MAD packet formats.
  2850. */
  2851. static inline bool rdma_cap_opa_mad(struct ib_device *device, u32 port_num)
  2852. {
  2853. return device->port_data[port_num].immutable.core_cap_flags &
  2854. RDMA_CORE_CAP_OPA_MAD;
  2855. }
  2856. /**
  2857. * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
  2858. * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
  2859. * @device: Device to check
  2860. * @port_num: Port number to check
  2861. *
  2862. * Each InfiniBand node is required to provide a Subnet Management Agent
  2863. * that the subnet manager can access. Prior to the fabric being fully
  2864. * configured by the subnet manager, the SMA is accessed via a well known
  2865. * interface called the Subnet Management Interface (SMI). This interface
  2866. * uses directed route packets to communicate with the SM to get around the
  2867. * chicken and egg problem of the SM needing to know what's on the fabric
  2868. * in order to configure the fabric, and needing to configure the fabric in
  2869. * order to send packets to the devices on the fabric. These directed
  2870. * route packets do not need the fabric fully configured in order to reach
  2871. * their destination. The SMI is the only method allowed to send
  2872. * directed route packets on an InfiniBand fabric.
  2873. *
  2874. * Return: true if the port provides an SMI.
  2875. */
  2876. static inline bool rdma_cap_ib_smi(const struct ib_device *device, u32 port_num)
  2877. {
  2878. return device->port_data[port_num].immutable.core_cap_flags &
  2879. RDMA_CORE_CAP_IB_SMI;
  2880. }
  2881. /**
  2882. * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
  2883. * Communication Manager.
  2884. * @device: Device to check
  2885. * @port_num: Port number to check
  2886. *
  2887. * The InfiniBand Communication Manager is one of many pre-defined General
  2888. * Service Agents (GSA) that are accessed via the General Service
  2889. * Interface (GSI). It's role is to facilitate establishment of connections
  2890. * between nodes as well as other management related tasks for established
  2891. * connections.
  2892. *
  2893. * Return: true if the port supports an IB CM (this does not guarantee that
  2894. * a CM is actually running however).
  2895. */
  2896. static inline bool rdma_cap_ib_cm(const struct ib_device *device, u32 port_num)
  2897. {
  2898. return device->port_data[port_num].immutable.core_cap_flags &
  2899. RDMA_CORE_CAP_IB_CM;
  2900. }
  2901. /**
  2902. * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
  2903. * Communication Manager.
  2904. * @device: Device to check
  2905. * @port_num: Port number to check
  2906. *
  2907. * Similar to above, but specific to iWARP connections which have a different
  2908. * managment protocol than InfiniBand.
  2909. *
  2910. * Return: true if the port supports an iWARP CM (this does not guarantee that
  2911. * a CM is actually running however).
  2912. */
  2913. static inline bool rdma_cap_iw_cm(const struct ib_device *device, u32 port_num)
  2914. {
  2915. return device->port_data[port_num].immutable.core_cap_flags &
  2916. RDMA_CORE_CAP_IW_CM;
  2917. }
  2918. /**
  2919. * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
  2920. * Subnet Administration.
  2921. * @device: Device to check
  2922. * @port_num: Port number to check
  2923. *
  2924. * An InfiniBand Subnet Administration (SA) service is a pre-defined General
  2925. * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
  2926. * fabrics, devices should resolve routes to other hosts by contacting the
  2927. * SA to query the proper route.
  2928. *
  2929. * Return: true if the port should act as a client to the fabric Subnet
  2930. * Administration interface. This does not imply that the SA service is
  2931. * running locally.
  2932. */
  2933. static inline bool rdma_cap_ib_sa(const struct ib_device *device, u32 port_num)
  2934. {
  2935. return device->port_data[port_num].immutable.core_cap_flags &
  2936. RDMA_CORE_CAP_IB_SA;
  2937. }
  2938. /**
  2939. * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
  2940. * Multicast.
  2941. * @device: Device to check
  2942. * @port_num: Port number to check
  2943. *
  2944. * InfiniBand multicast registration is more complex than normal IPv4 or
  2945. * IPv6 multicast registration. Each Host Channel Adapter must register
  2946. * with the Subnet Manager when it wishes to join a multicast group. It
  2947. * should do so only once regardless of how many queue pairs it subscribes
  2948. * to this group. And it should leave the group only after all queue pairs
  2949. * attached to the group have been detached.
  2950. *
  2951. * Return: true if the port must undertake the additional adminstrative
  2952. * overhead of registering/unregistering with the SM and tracking of the
  2953. * total number of queue pairs attached to the multicast group.
  2954. */
  2955. static inline bool rdma_cap_ib_mcast(const struct ib_device *device,
  2956. u32 port_num)
  2957. {
  2958. return rdma_cap_ib_sa(device, port_num);
  2959. }
  2960. /**
  2961. * rdma_cap_af_ib - Check if the port of device has the capability
  2962. * Native Infiniband Address.
  2963. * @device: Device to check
  2964. * @port_num: Port number to check
  2965. *
  2966. * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
  2967. * GID. RoCE uses a different mechanism, but still generates a GID via
  2968. * a prescribed mechanism and port specific data.
  2969. *
  2970. * Return: true if the port uses a GID address to identify devices on the
  2971. * network.
  2972. */
  2973. static inline bool rdma_cap_af_ib(const struct ib_device *device, u32 port_num)
  2974. {
  2975. return device->port_data[port_num].immutable.core_cap_flags &
  2976. RDMA_CORE_CAP_AF_IB;
  2977. }
  2978. /**
  2979. * rdma_cap_eth_ah - Check if the port of device has the capability
  2980. * Ethernet Address Handle.
  2981. * @device: Device to check
  2982. * @port_num: Port number to check
  2983. *
  2984. * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
  2985. * to fabricate GIDs over Ethernet/IP specific addresses native to the
  2986. * port. Normally, packet headers are generated by the sending host
  2987. * adapter, but when sending connectionless datagrams, we must manually
  2988. * inject the proper headers for the fabric we are communicating over.
  2989. *
  2990. * Return: true if we are running as a RoCE port and must force the
  2991. * addition of a Global Route Header built from our Ethernet Address
  2992. * Handle into our header list for connectionless packets.
  2993. */
  2994. static inline bool rdma_cap_eth_ah(const struct ib_device *device, u32 port_num)
  2995. {
  2996. return device->port_data[port_num].immutable.core_cap_flags &
  2997. RDMA_CORE_CAP_ETH_AH;
  2998. }
  2999. /**
  3000. * rdma_cap_opa_ah - Check if the port of device supports
  3001. * OPA Address handles
  3002. * @device: Device to check
  3003. * @port_num: Port number to check
  3004. *
  3005. * Return: true if we are running on an OPA device which supports
  3006. * the extended OPA addressing.
  3007. */
  3008. static inline bool rdma_cap_opa_ah(struct ib_device *device, u32 port_num)
  3009. {
  3010. return (device->port_data[port_num].immutable.core_cap_flags &
  3011. RDMA_CORE_CAP_OPA_AH) == RDMA_CORE_CAP_OPA_AH;
  3012. }
  3013. /**
  3014. * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
  3015. *
  3016. * @device: Device
  3017. * @port_num: Port number
  3018. *
  3019. * This MAD size includes the MAD headers and MAD payload. No other headers
  3020. * are included.
  3021. *
  3022. * Return the max MAD size required by the Port. Will return 0 if the port
  3023. * does not support MADs
  3024. */
  3025. static inline size_t rdma_max_mad_size(const struct ib_device *device,
  3026. u32 port_num)
  3027. {
  3028. return device->port_data[port_num].immutable.max_mad_size;
  3029. }
  3030. /**
  3031. * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
  3032. * @device: Device to check
  3033. * @port_num: Port number to check
  3034. *
  3035. * RoCE GID table mechanism manages the various GIDs for a device.
  3036. *
  3037. * NOTE: if allocating the port's GID table has failed, this call will still
  3038. * return true, but any RoCE GID table API will fail.
  3039. *
  3040. * Return: true if the port uses RoCE GID table mechanism in order to manage
  3041. * its GIDs.
  3042. */
  3043. static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
  3044. u32 port_num)
  3045. {
  3046. return rdma_protocol_roce(device, port_num) &&
  3047. device->ops.add_gid && device->ops.del_gid;
  3048. }
  3049. /*
  3050. * Check if the device supports READ W/ INVALIDATE.
  3051. */
  3052. static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
  3053. {
  3054. /*
  3055. * iWarp drivers must support READ W/ INVALIDATE. No other protocol
  3056. * has support for it yet.
  3057. */
  3058. return rdma_protocol_iwarp(dev, port_num);
  3059. }
  3060. /**
  3061. * rdma_core_cap_opa_port - Return whether the RDMA Port is OPA or not.
  3062. * @device: Device
  3063. * @port_num: 1 based Port number
  3064. *
  3065. * Return true if port is an Intel OPA port , false if not
  3066. */
  3067. static inline bool rdma_core_cap_opa_port(struct ib_device *device,
  3068. u32 port_num)
  3069. {
  3070. return (device->port_data[port_num].immutable.core_cap_flags &
  3071. RDMA_CORE_PORT_INTEL_OPA) == RDMA_CORE_PORT_INTEL_OPA;
  3072. }
  3073. /**
  3074. * rdma_mtu_enum_to_int - Return the mtu of the port as an integer value.
  3075. * @device: Device
  3076. * @port_num: Port number
  3077. * @mtu: enum value of MTU
  3078. *
  3079. * Return the MTU size supported by the port as an integer value. Will return
  3080. * -1 if enum value of mtu is not supported.
  3081. */
  3082. static inline int rdma_mtu_enum_to_int(struct ib_device *device, u32 port,
  3083. int mtu)
  3084. {
  3085. if (rdma_core_cap_opa_port(device, port))
  3086. return opa_mtu_enum_to_int((enum opa_mtu)mtu);
  3087. else
  3088. return ib_mtu_enum_to_int((enum ib_mtu)mtu);
  3089. }
  3090. /**
  3091. * rdma_mtu_from_attr - Return the mtu of the port from the port attribute.
  3092. * @device: Device
  3093. * @port_num: Port number
  3094. * @attr: port attribute
  3095. *
  3096. * Return the MTU size supported by the port as an integer value.
  3097. */
  3098. static inline int rdma_mtu_from_attr(struct ib_device *device, u32 port,
  3099. struct ib_port_attr *attr)
  3100. {
  3101. if (rdma_core_cap_opa_port(device, port))
  3102. return attr->phys_mtu;
  3103. else
  3104. return ib_mtu_enum_to_int(attr->max_mtu);
  3105. }
  3106. int ib_set_vf_link_state(struct ib_device *device, int vf, u32 port,
  3107. int state);
  3108. int ib_get_vf_config(struct ib_device *device, int vf, u32 port,
  3109. struct ifla_vf_info *info);
  3110. int ib_get_vf_stats(struct ib_device *device, int vf, u32 port,
  3111. struct ifla_vf_stats *stats);
  3112. int ib_get_vf_guid(struct ib_device *device, int vf, u32 port,
  3113. struct ifla_vf_guid *node_guid,
  3114. struct ifla_vf_guid *port_guid);
  3115. int ib_set_vf_guid(struct ib_device *device, int vf, u32 port, u64 guid,
  3116. int type);
  3117. int ib_query_pkey(struct ib_device *device,
  3118. u32 port_num, u16 index, u16 *pkey);
  3119. int ib_modify_device(struct ib_device *device,
  3120. int device_modify_mask,
  3121. struct ib_device_modify *device_modify);
  3122. int ib_modify_port(struct ib_device *device,
  3123. u32 port_num, int port_modify_mask,
  3124. struct ib_port_modify *port_modify);
  3125. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  3126. u32 *port_num, u16 *index);
  3127. int ib_find_pkey(struct ib_device *device,
  3128. u32 port_num, u16 pkey, u16 *index);
  3129. enum ib_pd_flags {
  3130. /*
  3131. * Create a memory registration for all memory in the system and place
  3132. * the rkey for it into pd->unsafe_global_rkey. This can be used by
  3133. * ULPs to avoid the overhead of dynamic MRs.
  3134. *
  3135. * This flag is generally considered unsafe and must only be used in
  3136. * extremly trusted environments. Every use of it will log a warning
  3137. * in the kernel log.
  3138. */
  3139. IB_PD_UNSAFE_GLOBAL_RKEY = 0x01,
  3140. };
  3141. struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
  3142. const char *caller);
  3143. /**
  3144. * ib_alloc_pd - Allocates an unused protection domain.
  3145. * @device: The device on which to allocate the protection domain.
  3146. * @flags: protection domain flags
  3147. *
  3148. * A protection domain object provides an association between QPs, shared
  3149. * receive queues, address handles, memory regions, and memory windows.
  3150. *
  3151. * Every PD has a local_dma_lkey which can be used as the lkey value for local
  3152. * memory operations.
  3153. */
  3154. #define ib_alloc_pd(device, flags) \
  3155. __ib_alloc_pd((device), (flags), KBUILD_MODNAME)
  3156. int ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata);
  3157. /**
  3158. * ib_dealloc_pd - Deallocate kernel PD
  3159. * @pd: The protection domain
  3160. *
  3161. * NOTE: for user PD use ib_dealloc_pd_user with valid udata!
  3162. */
  3163. static inline void ib_dealloc_pd(struct ib_pd *pd)
  3164. {
  3165. int ret = ib_dealloc_pd_user(pd, NULL);
  3166. WARN_ONCE(ret, "Destroy of kernel PD shouldn't fail");
  3167. }
  3168. enum rdma_create_ah_flags {
  3169. /* In a sleepable context */
  3170. RDMA_CREATE_AH_SLEEPABLE = BIT(0),
  3171. };
  3172. /**
  3173. * rdma_create_ah - Creates an address handle for the given address vector.
  3174. * @pd: The protection domain associated with the address handle.
  3175. * @ah_attr: The attributes of the address vector.
  3176. * @flags: Create address handle flags (see enum rdma_create_ah_flags).
  3177. *
  3178. * The address handle is used to reference a local or global destination
  3179. * in all UD QP post sends.
  3180. */
  3181. struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
  3182. u32 flags);
  3183. /**
  3184. * rdma_create_user_ah - Creates an address handle for the given address vector.
  3185. * It resolves destination mac address for ah attribute of RoCE type.
  3186. * @pd: The protection domain associated with the address handle.
  3187. * @ah_attr: The attributes of the address vector.
  3188. * @udata: pointer to user's input output buffer information need by
  3189. * provider driver.
  3190. *
  3191. * It returns 0 on success and returns appropriate error code on error.
  3192. * The address handle is used to reference a local or global destination
  3193. * in all UD QP post sends.
  3194. */
  3195. struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
  3196. struct rdma_ah_attr *ah_attr,
  3197. struct ib_udata *udata);
  3198. /**
  3199. * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header
  3200. * work completion.
  3201. * @hdr: the L3 header to parse
  3202. * @net_type: type of header to parse
  3203. * @sgid: place to store source gid
  3204. * @dgid: place to store destination gid
  3205. */
  3206. int ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr,
  3207. enum rdma_network_type net_type,
  3208. union ib_gid *sgid, union ib_gid *dgid);
  3209. /**
  3210. * ib_get_rdma_header_version - Get the header version
  3211. * @hdr: the L3 header to parse
  3212. */
  3213. int ib_get_rdma_header_version(const union rdma_network_hdr *hdr);
  3214. /**
  3215. * ib_init_ah_attr_from_wc - Initializes address handle attributes from a
  3216. * work completion.
  3217. * @device: Device on which the received message arrived.
  3218. * @port_num: Port on which the received message arrived.
  3219. * @wc: Work completion associated with the received message.
  3220. * @grh: References the received global route header. This parameter is
  3221. * ignored unless the work completion indicates that the GRH is valid.
  3222. * @ah_attr: Returned attributes that can be used when creating an address
  3223. * handle for replying to the message.
  3224. * When ib_init_ah_attr_from_wc() returns success,
  3225. * (a) for IB link layer it optionally contains a reference to SGID attribute
  3226. * when GRH is present for IB link layer.
  3227. * (b) for RoCE link layer it contains a reference to SGID attribute.
  3228. * User must invoke rdma_cleanup_ah_attr_gid_attr() to release reference to SGID
  3229. * attributes which are initialized using ib_init_ah_attr_from_wc().
  3230. *
  3231. */
  3232. int ib_init_ah_attr_from_wc(struct ib_device *device, u32 port_num,
  3233. const struct ib_wc *wc, const struct ib_grh *grh,
  3234. struct rdma_ah_attr *ah_attr);
  3235. /**
  3236. * ib_create_ah_from_wc - Creates an address handle associated with the
  3237. * sender of the specified work completion.
  3238. * @pd: The protection domain associated with the address handle.
  3239. * @wc: Work completion information associated with a received message.
  3240. * @grh: References the received global route header. This parameter is
  3241. * ignored unless the work completion indicates that the GRH is valid.
  3242. * @port_num: The outbound port number to associate with the address.
  3243. *
  3244. * The address handle is used to reference a local or global destination
  3245. * in all UD QP post sends.
  3246. */
  3247. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
  3248. const struct ib_grh *grh, u32 port_num);
  3249. /**
  3250. * rdma_modify_ah - Modifies the address vector associated with an address
  3251. * handle.
  3252. * @ah: The address handle to modify.
  3253. * @ah_attr: The new address vector attributes to associate with the
  3254. * address handle.
  3255. */
  3256. int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
  3257. /**
  3258. * rdma_query_ah - Queries the address vector associated with an address
  3259. * handle.
  3260. * @ah: The address handle to query.
  3261. * @ah_attr: The address vector attributes associated with the address
  3262. * handle.
  3263. */
  3264. int rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
  3265. enum rdma_destroy_ah_flags {
  3266. /* In a sleepable context */
  3267. RDMA_DESTROY_AH_SLEEPABLE = BIT(0),
  3268. };
  3269. /**
  3270. * rdma_destroy_ah_user - Destroys an address handle.
  3271. * @ah: The address handle to destroy.
  3272. * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
  3273. * @udata: Valid user data or NULL for kernel objects
  3274. */
  3275. int rdma_destroy_ah_user(struct ib_ah *ah, u32 flags, struct ib_udata *udata);
  3276. /**
  3277. * rdma_destroy_ah - Destroys an kernel address handle.
  3278. * @ah: The address handle to destroy.
  3279. * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
  3280. *
  3281. * NOTE: for user ah use rdma_destroy_ah_user with valid udata!
  3282. */
  3283. static inline void rdma_destroy_ah(struct ib_ah *ah, u32 flags)
  3284. {
  3285. int ret = rdma_destroy_ah_user(ah, flags, NULL);
  3286. WARN_ONCE(ret, "Destroy of kernel AH shouldn't fail");
  3287. }
  3288. struct ib_srq *ib_create_srq_user(struct ib_pd *pd,
  3289. struct ib_srq_init_attr *srq_init_attr,
  3290. struct ib_usrq_object *uobject,
  3291. struct ib_udata *udata);
  3292. static inline struct ib_srq *
  3293. ib_create_srq(struct ib_pd *pd, struct ib_srq_init_attr *srq_init_attr)
  3294. {
  3295. if (!pd->device->ops.create_srq)
  3296. return ERR_PTR(-EOPNOTSUPP);
  3297. return ib_create_srq_user(pd, srq_init_attr, NULL, NULL);
  3298. }
  3299. /**
  3300. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  3301. * @srq: The SRQ to modify.
  3302. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  3303. * the current values of selected SRQ attributes are returned.
  3304. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  3305. * are being modified.
  3306. *
  3307. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  3308. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  3309. * the number of receives queued drops below the limit.
  3310. */
  3311. int ib_modify_srq(struct ib_srq *srq,
  3312. struct ib_srq_attr *srq_attr,
  3313. enum ib_srq_attr_mask srq_attr_mask);
  3314. /**
  3315. * ib_query_srq - Returns the attribute list and current values for the
  3316. * specified SRQ.
  3317. * @srq: The SRQ to query.
  3318. * @srq_attr: The attributes of the specified SRQ.
  3319. */
  3320. int ib_query_srq(struct ib_srq *srq,
  3321. struct ib_srq_attr *srq_attr);
  3322. /**
  3323. * ib_destroy_srq_user - Destroys the specified SRQ.
  3324. * @srq: The SRQ to destroy.
  3325. * @udata: Valid user data or NULL for kernel objects
  3326. */
  3327. int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata);
  3328. /**
  3329. * ib_destroy_srq - Destroys the specified kernel SRQ.
  3330. * @srq: The SRQ to destroy.
  3331. *
  3332. * NOTE: for user srq use ib_destroy_srq_user with valid udata!
  3333. */
  3334. static inline void ib_destroy_srq(struct ib_srq *srq)
  3335. {
  3336. int ret = ib_destroy_srq_user(srq, NULL);
  3337. WARN_ONCE(ret, "Destroy of kernel SRQ shouldn't fail");
  3338. }
  3339. /**
  3340. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  3341. * @srq: The SRQ to post the work request on.
  3342. * @recv_wr: A list of work requests to post on the receive queue.
  3343. * @bad_recv_wr: On an immediate failure, this parameter will reference
  3344. * the work request that failed to be posted on the QP.
  3345. */
  3346. static inline int ib_post_srq_recv(struct ib_srq *srq,
  3347. const struct ib_recv_wr *recv_wr,
  3348. const struct ib_recv_wr **bad_recv_wr)
  3349. {
  3350. const struct ib_recv_wr *dummy;
  3351. return srq->device->ops.post_srq_recv(srq, recv_wr,
  3352. bad_recv_wr ? : &dummy);
  3353. }
  3354. struct ib_qp *ib_create_qp_kernel(struct ib_pd *pd,
  3355. struct ib_qp_init_attr *qp_init_attr,
  3356. const char *caller);
  3357. /**
  3358. * ib_create_qp - Creates a kernel QP associated with the specific protection
  3359. * domain.
  3360. * @pd: The protection domain associated with the QP.
  3361. * @init_attr: A list of initial attributes required to create the
  3362. * QP. If QP creation succeeds, then the attributes are updated to
  3363. * the actual capabilities of the created QP.
  3364. */
  3365. static inline struct ib_qp *ib_create_qp(struct ib_pd *pd,
  3366. struct ib_qp_init_attr *init_attr)
  3367. {
  3368. return ib_create_qp_kernel(pd, init_attr, KBUILD_MODNAME);
  3369. }
  3370. /**
  3371. * ib_modify_qp_with_udata - Modifies the attributes for the specified QP.
  3372. * @qp: The QP to modify.
  3373. * @attr: On input, specifies the QP attributes to modify. On output,
  3374. * the current values of selected QP attributes are returned.
  3375. * @attr_mask: A bit-mask used to specify which attributes of the QP
  3376. * are being modified.
  3377. * @udata: pointer to user's input output buffer information
  3378. * are being modified.
  3379. * It returns 0 on success and returns appropriate error code on error.
  3380. */
  3381. int ib_modify_qp_with_udata(struct ib_qp *qp,
  3382. struct ib_qp_attr *attr,
  3383. int attr_mask,
  3384. struct ib_udata *udata);
  3385. /**
  3386. * ib_modify_qp - Modifies the attributes for the specified QP and then
  3387. * transitions the QP to the given state.
  3388. * @qp: The QP to modify.
  3389. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  3390. * the current values of selected QP attributes are returned.
  3391. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  3392. * are being modified.
  3393. */
  3394. int ib_modify_qp(struct ib_qp *qp,
  3395. struct ib_qp_attr *qp_attr,
  3396. int qp_attr_mask);
  3397. /**
  3398. * ib_query_qp - Returns the attribute list and current values for the
  3399. * specified QP.
  3400. * @qp: The QP to query.
  3401. * @qp_attr: The attributes of the specified QP.
  3402. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  3403. * @qp_init_attr: Additional attributes of the selected QP.
  3404. *
  3405. * The qp_attr_mask may be used to limit the query to gathering only the
  3406. * selected attributes.
  3407. */
  3408. int ib_query_qp(struct ib_qp *qp,
  3409. struct ib_qp_attr *qp_attr,
  3410. int qp_attr_mask,
  3411. struct ib_qp_init_attr *qp_init_attr);
  3412. /**
  3413. * ib_destroy_qp - Destroys the specified QP.
  3414. * @qp: The QP to destroy.
  3415. * @udata: Valid udata or NULL for kernel objects
  3416. */
  3417. int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata);
  3418. /**
  3419. * ib_destroy_qp - Destroys the specified kernel QP.
  3420. * @qp: The QP to destroy.
  3421. *
  3422. * NOTE: for user qp use ib_destroy_qp_user with valid udata!
  3423. */
  3424. static inline int ib_destroy_qp(struct ib_qp *qp)
  3425. {
  3426. return ib_destroy_qp_user(qp, NULL);
  3427. }
  3428. /**
  3429. * ib_open_qp - Obtain a reference to an existing sharable QP.
  3430. * @xrcd - XRC domain
  3431. * @qp_open_attr: Attributes identifying the QP to open.
  3432. *
  3433. * Returns a reference to a sharable QP.
  3434. */
  3435. struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
  3436. struct ib_qp_open_attr *qp_open_attr);
  3437. /**
  3438. * ib_close_qp - Release an external reference to a QP.
  3439. * @qp: The QP handle to release
  3440. *
  3441. * The opened QP handle is released by the caller. The underlying
  3442. * shared QP is not destroyed until all internal references are released.
  3443. */
  3444. int ib_close_qp(struct ib_qp *qp);
  3445. /**
  3446. * ib_post_send - Posts a list of work requests to the send queue of
  3447. * the specified QP.
  3448. * @qp: The QP to post the work request on.
  3449. * @send_wr: A list of work requests to post on the send queue.
  3450. * @bad_send_wr: On an immediate failure, this parameter will reference
  3451. * the work request that failed to be posted on the QP.
  3452. *
  3453. * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
  3454. * error is returned, the QP state shall not be affected,
  3455. * ib_post_send() will return an immediate error after queueing any
  3456. * earlier work requests in the list.
  3457. */
  3458. static inline int ib_post_send(struct ib_qp *qp,
  3459. const struct ib_send_wr *send_wr,
  3460. const struct ib_send_wr **bad_send_wr)
  3461. {
  3462. const struct ib_send_wr *dummy;
  3463. return qp->device->ops.post_send(qp, send_wr, bad_send_wr ? : &dummy);
  3464. }
  3465. /**
  3466. * ib_post_recv - Posts a list of work requests to the receive queue of
  3467. * the specified QP.
  3468. * @qp: The QP to post the work request on.
  3469. * @recv_wr: A list of work requests to post on the receive queue.
  3470. * @bad_recv_wr: On an immediate failure, this parameter will reference
  3471. * the work request that failed to be posted on the QP.
  3472. */
  3473. static inline int ib_post_recv(struct ib_qp *qp,
  3474. const struct ib_recv_wr *recv_wr,
  3475. const struct ib_recv_wr **bad_recv_wr)
  3476. {
  3477. const struct ib_recv_wr *dummy;
  3478. return qp->device->ops.post_recv(qp, recv_wr, bad_recv_wr ? : &dummy);
  3479. }
  3480. struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe,
  3481. int comp_vector, enum ib_poll_context poll_ctx,
  3482. const char *caller);
  3483. static inline struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
  3484. int nr_cqe, int comp_vector,
  3485. enum ib_poll_context poll_ctx)
  3486. {
  3487. return __ib_alloc_cq(dev, private, nr_cqe, comp_vector, poll_ctx,
  3488. KBUILD_MODNAME);
  3489. }
  3490. struct ib_cq *__ib_alloc_cq_any(struct ib_device *dev, void *private,
  3491. int nr_cqe, enum ib_poll_context poll_ctx,
  3492. const char *caller);
  3493. /**
  3494. * ib_alloc_cq_any: Allocate kernel CQ
  3495. * @dev: The IB device
  3496. * @private: Private data attached to the CQE
  3497. * @nr_cqe: Number of CQEs in the CQ
  3498. * @poll_ctx: Context used for polling the CQ
  3499. */
  3500. static inline struct ib_cq *ib_alloc_cq_any(struct ib_device *dev,
  3501. void *private, int nr_cqe,
  3502. enum ib_poll_context poll_ctx)
  3503. {
  3504. return __ib_alloc_cq_any(dev, private, nr_cqe, poll_ctx,
  3505. KBUILD_MODNAME);
  3506. }
  3507. void ib_free_cq(struct ib_cq *cq);
  3508. int ib_process_cq_direct(struct ib_cq *cq, int budget);
  3509. /**
  3510. * ib_create_cq - Creates a CQ on the specified device.
  3511. * @device: The device on which to create the CQ.
  3512. * @comp_handler: A user-specified callback that is invoked when a
  3513. * completion event occurs on the CQ.
  3514. * @event_handler: A user-specified callback that is invoked when an
  3515. * asynchronous event not associated with a completion occurs on the CQ.
  3516. * @cq_context: Context associated with the CQ returned to the user via
  3517. * the associated completion and event handlers.
  3518. * @cq_attr: The attributes the CQ should be created upon.
  3519. *
  3520. * Users can examine the cq structure to determine the actual CQ size.
  3521. */
  3522. struct ib_cq *__ib_create_cq(struct ib_device *device,
  3523. ib_comp_handler comp_handler,
  3524. void (*event_handler)(struct ib_event *, void *),
  3525. void *cq_context,
  3526. const struct ib_cq_init_attr *cq_attr,
  3527. const char *caller);
  3528. #define ib_create_cq(device, cmp_hndlr, evt_hndlr, cq_ctxt, cq_attr) \
  3529. __ib_create_cq((device), (cmp_hndlr), (evt_hndlr), (cq_ctxt), (cq_attr), KBUILD_MODNAME)
  3530. /**
  3531. * ib_resize_cq - Modifies the capacity of the CQ.
  3532. * @cq: The CQ to resize.
  3533. * @cqe: The minimum size of the CQ.
  3534. *
  3535. * Users can examine the cq structure to determine the actual CQ size.
  3536. */
  3537. int ib_resize_cq(struct ib_cq *cq, int cqe);
  3538. /**
  3539. * rdma_set_cq_moderation - Modifies moderation params of the CQ
  3540. * @cq: The CQ to modify.
  3541. * @cq_count: number of CQEs that will trigger an event
  3542. * @cq_period: max period of time in usec before triggering an event
  3543. *
  3544. */
  3545. int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  3546. /**
  3547. * ib_destroy_cq_user - Destroys the specified CQ.
  3548. * @cq: The CQ to destroy.
  3549. * @udata: Valid user data or NULL for kernel objects
  3550. */
  3551. int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata);
  3552. /**
  3553. * ib_destroy_cq - Destroys the specified kernel CQ.
  3554. * @cq: The CQ to destroy.
  3555. *
  3556. * NOTE: for user cq use ib_destroy_cq_user with valid udata!
  3557. */
  3558. static inline void ib_destroy_cq(struct ib_cq *cq)
  3559. {
  3560. int ret = ib_destroy_cq_user(cq, NULL);
  3561. WARN_ONCE(ret, "Destroy of kernel CQ shouldn't fail");
  3562. }
  3563. /**
  3564. * ib_poll_cq - poll a CQ for completion(s)
  3565. * @cq:the CQ being polled
  3566. * @num_entries:maximum number of completions to return
  3567. * @wc:array of at least @num_entries &struct ib_wc where completions
  3568. * will be returned
  3569. *
  3570. * Poll a CQ for (possibly multiple) completions. If the return value
  3571. * is < 0, an error occurred. If the return value is >= 0, it is the
  3572. * number of completions returned. If the return value is
  3573. * non-negative and < num_entries, then the CQ was emptied.
  3574. */
  3575. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  3576. struct ib_wc *wc)
  3577. {
  3578. return cq->device->ops.poll_cq(cq, num_entries, wc);
  3579. }
  3580. /**
  3581. * ib_req_notify_cq - Request completion notification on a CQ.
  3582. * @cq: The CQ to generate an event for.
  3583. * @flags:
  3584. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  3585. * to request an event on the next solicited event or next work
  3586. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  3587. * may also be |ed in to request a hint about missed events, as
  3588. * described below.
  3589. *
  3590. * Return Value:
  3591. * < 0 means an error occurred while requesting notification
  3592. * == 0 means notification was requested successfully, and if
  3593. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  3594. * were missed and it is safe to wait for another event. In
  3595. * this case is it guaranteed that any work completions added
  3596. * to the CQ since the last CQ poll will trigger a completion
  3597. * notification event.
  3598. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  3599. * in. It means that the consumer must poll the CQ again to
  3600. * make sure it is empty to avoid missing an event because of a
  3601. * race between requesting notification and an entry being
  3602. * added to the CQ. This return value means it is possible
  3603. * (but not guaranteed) that a work completion has been added
  3604. * to the CQ since the last poll without triggering a
  3605. * completion notification event.
  3606. */
  3607. static inline int ib_req_notify_cq(struct ib_cq *cq,
  3608. enum ib_cq_notify_flags flags)
  3609. {
  3610. return cq->device->ops.req_notify_cq(cq, flags);
  3611. }
  3612. struct ib_cq *ib_cq_pool_get(struct ib_device *dev, unsigned int nr_cqe,
  3613. int comp_vector_hint,
  3614. enum ib_poll_context poll_ctx);
  3615. void ib_cq_pool_put(struct ib_cq *cq, unsigned int nr_cqe);
  3616. /*
  3617. * Drivers that don't need a DMA mapping at the RDMA layer, set dma_device to
  3618. * NULL. This causes the ib_dma* helpers to just stash the kernel virtual
  3619. * address into the dma address.
  3620. */
  3621. static inline bool ib_uses_virt_dma(struct ib_device *dev)
  3622. {
  3623. return IS_ENABLED(CONFIG_INFINIBAND_VIRT_DMA) && !dev->dma_device;
  3624. }
  3625. /*
  3626. * Check if a IB device's underlying DMA mapping supports P2PDMA transfers.
  3627. */
  3628. static inline bool ib_dma_pci_p2p_dma_supported(struct ib_device *dev)
  3629. {
  3630. if (ib_uses_virt_dma(dev))
  3631. return false;
  3632. return dma_pci_p2pdma_supported(dev->dma_device);
  3633. }
  3634. /**
  3635. * ib_virt_dma_to_ptr - Convert a dma_addr to a kernel pointer
  3636. * @dma_addr: The DMA address
  3637. *
  3638. * Used by ib_uses_virt_dma() devices to get back to the kernel pointer after
  3639. * going through the dma_addr marshalling.
  3640. */
  3641. static inline void *ib_virt_dma_to_ptr(u64 dma_addr)
  3642. {
  3643. /* virt_dma mode maps the kvs's directly into the dma addr */
  3644. return (void *)(uintptr_t)dma_addr;
  3645. }
  3646. /**
  3647. * ib_virt_dma_to_page - Convert a dma_addr to a struct page
  3648. * @dma_addr: The DMA address
  3649. *
  3650. * Used by ib_uses_virt_dma() device to get back to the struct page after going
  3651. * through the dma_addr marshalling.
  3652. */
  3653. static inline struct page *ib_virt_dma_to_page(u64 dma_addr)
  3654. {
  3655. return virt_to_page(ib_virt_dma_to_ptr(dma_addr));
  3656. }
  3657. /**
  3658. * ib_dma_mapping_error - check a DMA addr for error
  3659. * @dev: The device for which the dma_addr was created
  3660. * @dma_addr: The DMA address to check
  3661. */
  3662. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  3663. {
  3664. if (ib_uses_virt_dma(dev))
  3665. return 0;
  3666. return dma_mapping_error(dev->dma_device, dma_addr);
  3667. }
  3668. /**
  3669. * ib_dma_map_single - Map a kernel virtual address to DMA address
  3670. * @dev: The device for which the dma_addr is to be created
  3671. * @cpu_addr: The kernel virtual address
  3672. * @size: The size of the region in bytes
  3673. * @direction: The direction of the DMA
  3674. */
  3675. static inline u64 ib_dma_map_single(struct ib_device *dev,
  3676. void *cpu_addr, size_t size,
  3677. enum dma_data_direction direction)
  3678. {
  3679. if (ib_uses_virt_dma(dev))
  3680. return (uintptr_t)cpu_addr;
  3681. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  3682. }
  3683. /**
  3684. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  3685. * @dev: The device for which the DMA address was created
  3686. * @addr: The DMA address
  3687. * @size: The size of the region in bytes
  3688. * @direction: The direction of the DMA
  3689. */
  3690. static inline void ib_dma_unmap_single(struct ib_device *dev,
  3691. u64 addr, size_t size,
  3692. enum dma_data_direction direction)
  3693. {
  3694. if (!ib_uses_virt_dma(dev))
  3695. dma_unmap_single(dev->dma_device, addr, size, direction);
  3696. }
  3697. /**
  3698. * ib_dma_map_page - Map a physical page to DMA address
  3699. * @dev: The device for which the dma_addr is to be created
  3700. * @page: The page to be mapped
  3701. * @offset: The offset within the page
  3702. * @size: The size of the region in bytes
  3703. * @direction: The direction of the DMA
  3704. */
  3705. static inline u64 ib_dma_map_page(struct ib_device *dev,
  3706. struct page *page,
  3707. unsigned long offset,
  3708. size_t size,
  3709. enum dma_data_direction direction)
  3710. {
  3711. if (ib_uses_virt_dma(dev))
  3712. return (uintptr_t)(page_address(page) + offset);
  3713. return dma_map_page(dev->dma_device, page, offset, size, direction);
  3714. }
  3715. /**
  3716. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  3717. * @dev: The device for which the DMA address was created
  3718. * @addr: The DMA address
  3719. * @size: The size of the region in bytes
  3720. * @direction: The direction of the DMA
  3721. */
  3722. static inline void ib_dma_unmap_page(struct ib_device *dev,
  3723. u64 addr, size_t size,
  3724. enum dma_data_direction direction)
  3725. {
  3726. if (!ib_uses_virt_dma(dev))
  3727. dma_unmap_page(dev->dma_device, addr, size, direction);
  3728. }
  3729. int ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents);
  3730. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  3731. struct scatterlist *sg, int nents,
  3732. enum dma_data_direction direction,
  3733. unsigned long dma_attrs)
  3734. {
  3735. if (ib_uses_virt_dma(dev))
  3736. return ib_dma_virt_map_sg(dev, sg, nents);
  3737. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
  3738. dma_attrs);
  3739. }
  3740. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  3741. struct scatterlist *sg, int nents,
  3742. enum dma_data_direction direction,
  3743. unsigned long dma_attrs)
  3744. {
  3745. if (!ib_uses_virt_dma(dev))
  3746. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction,
  3747. dma_attrs);
  3748. }
  3749. /**
  3750. * ib_dma_map_sgtable_attrs - Map a scatter/gather table to DMA addresses
  3751. * @dev: The device for which the DMA addresses are to be created
  3752. * @sg: The sg_table object describing the buffer
  3753. * @direction: The direction of the DMA
  3754. * @attrs: Optional DMA attributes for the map operation
  3755. */
  3756. static inline int ib_dma_map_sgtable_attrs(struct ib_device *dev,
  3757. struct sg_table *sgt,
  3758. enum dma_data_direction direction,
  3759. unsigned long dma_attrs)
  3760. {
  3761. int nents;
  3762. if (ib_uses_virt_dma(dev)) {
  3763. nents = ib_dma_virt_map_sg(dev, sgt->sgl, sgt->orig_nents);
  3764. if (!nents)
  3765. return -EIO;
  3766. sgt->nents = nents;
  3767. return 0;
  3768. }
  3769. return dma_map_sgtable(dev->dma_device, sgt, direction, dma_attrs);
  3770. }
  3771. static inline void ib_dma_unmap_sgtable_attrs(struct ib_device *dev,
  3772. struct sg_table *sgt,
  3773. enum dma_data_direction direction,
  3774. unsigned long dma_attrs)
  3775. {
  3776. if (!ib_uses_virt_dma(dev))
  3777. dma_unmap_sgtable(dev->dma_device, sgt, direction, dma_attrs);
  3778. }
  3779. /**
  3780. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  3781. * @dev: The device for which the DMA addresses are to be created
  3782. * @sg: The array of scatter/gather entries
  3783. * @nents: The number of scatter/gather entries
  3784. * @direction: The direction of the DMA
  3785. */
  3786. static inline int ib_dma_map_sg(struct ib_device *dev,
  3787. struct scatterlist *sg, int nents,
  3788. enum dma_data_direction direction)
  3789. {
  3790. return ib_dma_map_sg_attrs(dev, sg, nents, direction, 0);
  3791. }
  3792. /**
  3793. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  3794. * @dev: The device for which the DMA addresses were created
  3795. * @sg: The array of scatter/gather entries
  3796. * @nents: The number of scatter/gather entries
  3797. * @direction: The direction of the DMA
  3798. */
  3799. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  3800. struct scatterlist *sg, int nents,
  3801. enum dma_data_direction direction)
  3802. {
  3803. ib_dma_unmap_sg_attrs(dev, sg, nents, direction, 0);
  3804. }
  3805. /**
  3806. * ib_dma_max_seg_size - Return the size limit of a single DMA transfer
  3807. * @dev: The device to query
  3808. *
  3809. * The returned value represents a size in bytes.
  3810. */
  3811. static inline unsigned int ib_dma_max_seg_size(struct ib_device *dev)
  3812. {
  3813. if (ib_uses_virt_dma(dev))
  3814. return UINT_MAX;
  3815. return dma_get_max_seg_size(dev->dma_device);
  3816. }
  3817. /**
  3818. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  3819. * @dev: The device for which the DMA address was created
  3820. * @addr: The DMA address
  3821. * @size: The size of the region in bytes
  3822. * @dir: The direction of the DMA
  3823. */
  3824. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  3825. u64 addr,
  3826. size_t size,
  3827. enum dma_data_direction dir)
  3828. {
  3829. if (!ib_uses_virt_dma(dev))
  3830. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  3831. }
  3832. /**
  3833. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  3834. * @dev: The device for which the DMA address was created
  3835. * @addr: The DMA address
  3836. * @size: The size of the region in bytes
  3837. * @dir: The direction of the DMA
  3838. */
  3839. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  3840. u64 addr,
  3841. size_t size,
  3842. enum dma_data_direction dir)
  3843. {
  3844. if (!ib_uses_virt_dma(dev))
  3845. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  3846. }
  3847. /* ib_reg_user_mr - register a memory region for virtual addresses from kernel
  3848. * space. This function should be called when 'current' is the owning MM.
  3849. */
  3850. struct ib_mr *ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
  3851. u64 virt_addr, int mr_access_flags);
  3852. /* ib_advise_mr - give an advice about an address range in a memory region */
  3853. int ib_advise_mr(struct ib_pd *pd, enum ib_uverbs_advise_mr_advice advice,
  3854. u32 flags, struct ib_sge *sg_list, u32 num_sge);
  3855. /**
  3856. * ib_dereg_mr_user - Deregisters a memory region and removes it from the
  3857. * HCA translation table.
  3858. * @mr: The memory region to deregister.
  3859. * @udata: Valid user data or NULL for kernel object
  3860. *
  3861. * This function can fail, if the memory region has memory windows bound to it.
  3862. */
  3863. int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata);
  3864. /**
  3865. * ib_dereg_mr - Deregisters a kernel memory region and removes it from the
  3866. * HCA translation table.
  3867. * @mr: The memory region to deregister.
  3868. *
  3869. * This function can fail, if the memory region has memory windows bound to it.
  3870. *
  3871. * NOTE: for user mr use ib_dereg_mr_user with valid udata!
  3872. */
  3873. static inline int ib_dereg_mr(struct ib_mr *mr)
  3874. {
  3875. return ib_dereg_mr_user(mr, NULL);
  3876. }
  3877. struct ib_mr *ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
  3878. u32 max_num_sg);
  3879. struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
  3880. u32 max_num_data_sg,
  3881. u32 max_num_meta_sg);
  3882. /**
  3883. * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
  3884. * R_Key and L_Key.
  3885. * @mr - struct ib_mr pointer to be updated.
  3886. * @newkey - new key to be used.
  3887. */
  3888. static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
  3889. {
  3890. mr->lkey = (mr->lkey & 0xffffff00) | newkey;
  3891. mr->rkey = (mr->rkey & 0xffffff00) | newkey;
  3892. }
  3893. /**
  3894. * ib_inc_rkey - increments the key portion of the given rkey. Can be used
  3895. * for calculating a new rkey for type 2 memory windows.
  3896. * @rkey - the rkey to increment.
  3897. */
  3898. static inline u32 ib_inc_rkey(u32 rkey)
  3899. {
  3900. const u32 mask = 0x000000ff;
  3901. return ((rkey + 1) & mask) | (rkey & ~mask);
  3902. }
  3903. /**
  3904. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  3905. * @qp: QP to attach to the multicast group. The QP must be type
  3906. * IB_QPT_UD.
  3907. * @gid: Multicast group GID.
  3908. * @lid: Multicast group LID in host byte order.
  3909. *
  3910. * In order to send and receive multicast packets, subnet
  3911. * administration must have created the multicast group and configured
  3912. * the fabric appropriately. The port associated with the specified
  3913. * QP must also be a member of the multicast group.
  3914. */
  3915. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  3916. /**
  3917. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  3918. * @qp: QP to detach from the multicast group.
  3919. * @gid: Multicast group GID.
  3920. * @lid: Multicast group LID in host byte order.
  3921. */
  3922. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  3923. struct ib_xrcd *ib_alloc_xrcd_user(struct ib_device *device,
  3924. struct inode *inode, struct ib_udata *udata);
  3925. int ib_dealloc_xrcd_user(struct ib_xrcd *xrcd, struct ib_udata *udata);
  3926. static inline int ib_check_mr_access(struct ib_device *ib_dev,
  3927. unsigned int flags)
  3928. {
  3929. u64 device_cap = ib_dev->attrs.device_cap_flags;
  3930. /*
  3931. * Local write permission is required if remote write or
  3932. * remote atomic permission is also requested.
  3933. */
  3934. if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
  3935. !(flags & IB_ACCESS_LOCAL_WRITE))
  3936. return -EINVAL;
  3937. if (flags & ~IB_ACCESS_SUPPORTED)
  3938. return -EINVAL;
  3939. if (flags & IB_ACCESS_ON_DEMAND &&
  3940. !(ib_dev->attrs.kernel_cap_flags & IBK_ON_DEMAND_PAGING))
  3941. return -EOPNOTSUPP;
  3942. if ((flags & IB_ACCESS_FLUSH_GLOBAL &&
  3943. !(device_cap & IB_DEVICE_FLUSH_GLOBAL)) ||
  3944. (flags & IB_ACCESS_FLUSH_PERSISTENT &&
  3945. !(device_cap & IB_DEVICE_FLUSH_PERSISTENT)))
  3946. return -EOPNOTSUPP;
  3947. return 0;
  3948. }
  3949. static inline bool ib_access_writable(int access_flags)
  3950. {
  3951. /*
  3952. * We have writable memory backing the MR if any of the following
  3953. * access flags are set. "Local write" and "remote write" obviously
  3954. * require write access. "Remote atomic" can do things like fetch and
  3955. * add, which will modify memory, and "MW bind" can change permissions
  3956. * by binding a window.
  3957. */
  3958. return access_flags &
  3959. (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE |
  3960. IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND);
  3961. }
  3962. /**
  3963. * ib_check_mr_status: lightweight check of MR status.
  3964. * This routine may provide status checks on a selected
  3965. * ib_mr. first use is for signature status check.
  3966. *
  3967. * @mr: A memory region.
  3968. * @check_mask: Bitmask of which checks to perform from
  3969. * ib_mr_status_check enumeration.
  3970. * @mr_status: The container of relevant status checks.
  3971. * failed checks will be indicated in the status bitmask
  3972. * and the relevant info shall be in the error item.
  3973. */
  3974. int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
  3975. struct ib_mr_status *mr_status);
  3976. /**
  3977. * ib_device_try_get: Hold a registration lock
  3978. * device: The device to lock
  3979. *
  3980. * A device under an active registration lock cannot become unregistered. It
  3981. * is only possible to obtain a registration lock on a device that is fully
  3982. * registered, otherwise this function returns false.
  3983. *
  3984. * The registration lock is only necessary for actions which require the
  3985. * device to still be registered. Uses that only require the device pointer to
  3986. * be valid should use get_device(&ibdev->dev) to hold the memory.
  3987. *
  3988. */
  3989. static inline bool ib_device_try_get(struct ib_device *dev)
  3990. {
  3991. return refcount_inc_not_zero(&dev->refcount);
  3992. }
  3993. void ib_device_put(struct ib_device *device);
  3994. struct ib_device *ib_device_get_by_netdev(struct net_device *ndev,
  3995. enum rdma_driver_id driver_id);
  3996. struct ib_device *ib_device_get_by_name(const char *name,
  3997. enum rdma_driver_id driver_id);
  3998. struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u32 port,
  3999. u16 pkey, const union ib_gid *gid,
  4000. const struct sockaddr *addr);
  4001. int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
  4002. unsigned int port);
  4003. struct net_device *ib_device_get_netdev(struct ib_device *ib_dev,
  4004. u32 port);
  4005. struct ib_wq *ib_create_wq(struct ib_pd *pd,
  4006. struct ib_wq_init_attr *init_attr);
  4007. int ib_destroy_wq_user(struct ib_wq *wq, struct ib_udata *udata);
  4008. int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  4009. unsigned int *sg_offset, unsigned int page_size);
  4010. int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg,
  4011. int data_sg_nents, unsigned int *data_sg_offset,
  4012. struct scatterlist *meta_sg, int meta_sg_nents,
  4013. unsigned int *meta_sg_offset, unsigned int page_size);
  4014. static inline int
  4015. ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  4016. unsigned int *sg_offset, unsigned int page_size)
  4017. {
  4018. int n;
  4019. n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
  4020. mr->iova = 0;
  4021. return n;
  4022. }
  4023. int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
  4024. unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
  4025. void ib_drain_rq(struct ib_qp *qp);
  4026. void ib_drain_sq(struct ib_qp *qp);
  4027. void ib_drain_qp(struct ib_qp *qp);
  4028. int ib_get_eth_speed(struct ib_device *dev, u32 port_num, u16 *speed,
  4029. u8 *width);
  4030. static inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr)
  4031. {
  4032. if (attr->type == RDMA_AH_ATTR_TYPE_ROCE)
  4033. return attr->roce.dmac;
  4034. return NULL;
  4035. }
  4036. static inline void rdma_ah_set_dlid(struct rdma_ah_attr *attr, u32 dlid)
  4037. {
  4038. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  4039. attr->ib.dlid = (u16)dlid;
  4040. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  4041. attr->opa.dlid = dlid;
  4042. }
  4043. static inline u32 rdma_ah_get_dlid(const struct rdma_ah_attr *attr)
  4044. {
  4045. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  4046. return attr->ib.dlid;
  4047. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  4048. return attr->opa.dlid;
  4049. return 0;
  4050. }
  4051. static inline void rdma_ah_set_sl(struct rdma_ah_attr *attr, u8 sl)
  4052. {
  4053. attr->sl = sl;
  4054. }
  4055. static inline u8 rdma_ah_get_sl(const struct rdma_ah_attr *attr)
  4056. {
  4057. return attr->sl;
  4058. }
  4059. static inline void rdma_ah_set_path_bits(struct rdma_ah_attr *attr,
  4060. u8 src_path_bits)
  4061. {
  4062. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  4063. attr->ib.src_path_bits = src_path_bits;
  4064. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  4065. attr->opa.src_path_bits = src_path_bits;
  4066. }
  4067. static inline u8 rdma_ah_get_path_bits(const struct rdma_ah_attr *attr)
  4068. {
  4069. if (attr->type == RDMA_AH_ATTR_TYPE_IB)
  4070. return attr->ib.src_path_bits;
  4071. else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  4072. return attr->opa.src_path_bits;
  4073. return 0;
  4074. }
  4075. static inline void rdma_ah_set_make_grd(struct rdma_ah_attr *attr,
  4076. bool make_grd)
  4077. {
  4078. if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  4079. attr->opa.make_grd = make_grd;
  4080. }
  4081. static inline bool rdma_ah_get_make_grd(const struct rdma_ah_attr *attr)
  4082. {
  4083. if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
  4084. return attr->opa.make_grd;
  4085. return false;
  4086. }
  4087. static inline void rdma_ah_set_port_num(struct rdma_ah_attr *attr, u32 port_num)
  4088. {
  4089. attr->port_num = port_num;
  4090. }
  4091. static inline u32 rdma_ah_get_port_num(const struct rdma_ah_attr *attr)
  4092. {
  4093. return attr->port_num;
  4094. }
  4095. static inline void rdma_ah_set_static_rate(struct rdma_ah_attr *attr,
  4096. u8 static_rate)
  4097. {
  4098. attr->static_rate = static_rate;
  4099. }
  4100. static inline u8 rdma_ah_get_static_rate(const struct rdma_ah_attr *attr)
  4101. {
  4102. return attr->static_rate;
  4103. }
  4104. static inline void rdma_ah_set_ah_flags(struct rdma_ah_attr *attr,
  4105. enum ib_ah_flags flag)
  4106. {
  4107. attr->ah_flags = flag;
  4108. }
  4109. static inline enum ib_ah_flags
  4110. rdma_ah_get_ah_flags(const struct rdma_ah_attr *attr)
  4111. {
  4112. return attr->ah_flags;
  4113. }
  4114. static inline const struct ib_global_route
  4115. *rdma_ah_read_grh(const struct rdma_ah_attr *attr)
  4116. {
  4117. return &attr->grh;
  4118. }
  4119. /*To retrieve and modify the grh */
  4120. static inline struct ib_global_route
  4121. *rdma_ah_retrieve_grh(struct rdma_ah_attr *attr)
  4122. {
  4123. return &attr->grh;
  4124. }
  4125. static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid)
  4126. {
  4127. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  4128. memcpy(grh->dgid.raw, dgid, sizeof(grh->dgid));
  4129. }
  4130. static inline void rdma_ah_set_subnet_prefix(struct rdma_ah_attr *attr,
  4131. __be64 prefix)
  4132. {
  4133. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  4134. grh->dgid.global.subnet_prefix = prefix;
  4135. }
  4136. static inline void rdma_ah_set_interface_id(struct rdma_ah_attr *attr,
  4137. __be64 if_id)
  4138. {
  4139. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  4140. grh->dgid.global.interface_id = if_id;
  4141. }
  4142. static inline void rdma_ah_set_grh(struct rdma_ah_attr *attr,
  4143. union ib_gid *dgid, u32 flow_label,
  4144. u8 sgid_index, u8 hop_limit,
  4145. u8 traffic_class)
  4146. {
  4147. struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
  4148. attr->ah_flags = IB_AH_GRH;
  4149. if (dgid)
  4150. grh->dgid = *dgid;
  4151. grh->flow_label = flow_label;
  4152. grh->sgid_index = sgid_index;
  4153. grh->hop_limit = hop_limit;
  4154. grh->traffic_class = traffic_class;
  4155. grh->sgid_attr = NULL;
  4156. }
  4157. void rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr);
  4158. void rdma_move_grh_sgid_attr(struct rdma_ah_attr *attr, union ib_gid *dgid,
  4159. u32 flow_label, u8 hop_limit, u8 traffic_class,
  4160. const struct ib_gid_attr *sgid_attr);
  4161. void rdma_copy_ah_attr(struct rdma_ah_attr *dest,
  4162. const struct rdma_ah_attr *src);
  4163. void rdma_replace_ah_attr(struct rdma_ah_attr *old,
  4164. const struct rdma_ah_attr *new);
  4165. void rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src);
  4166. /**
  4167. * rdma_ah_find_type - Return address handle type.
  4168. *
  4169. * @dev: Device to be checked
  4170. * @port_num: Port number
  4171. */
  4172. static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
  4173. u32 port_num)
  4174. {
  4175. if (rdma_protocol_roce(dev, port_num))
  4176. return RDMA_AH_ATTR_TYPE_ROCE;
  4177. if (rdma_protocol_ib(dev, port_num)) {
  4178. if (rdma_cap_opa_ah(dev, port_num))
  4179. return RDMA_AH_ATTR_TYPE_OPA;
  4180. return RDMA_AH_ATTR_TYPE_IB;
  4181. }
  4182. if (dev->type == RDMA_DEVICE_TYPE_SMI)
  4183. return RDMA_AH_ATTR_TYPE_IB;
  4184. return RDMA_AH_ATTR_TYPE_UNDEFINED;
  4185. }
  4186. /**
  4187. * ib_lid_cpu16 - Return lid in 16bit CPU encoding.
  4188. * In the current implementation the only way to
  4189. * get the 32bit lid is from other sources for OPA.
  4190. * For IB, lids will always be 16bits so cast the
  4191. * value accordingly.
  4192. *
  4193. * @lid: A 32bit LID
  4194. */
  4195. static inline u16 ib_lid_cpu16(u32 lid)
  4196. {
  4197. WARN_ON_ONCE(lid & 0xFFFF0000);
  4198. return (u16)lid;
  4199. }
  4200. /**
  4201. * ib_lid_be16 - Return lid in 16bit BE encoding.
  4202. *
  4203. * @lid: A 32bit LID
  4204. */
  4205. static inline __be16 ib_lid_be16(u32 lid)
  4206. {
  4207. WARN_ON_ONCE(lid & 0xFFFF0000);
  4208. return cpu_to_be16((u16)lid);
  4209. }
  4210. /**
  4211. * ib_get_vector_affinity - Get the affinity mappings of a given completion
  4212. * vector
  4213. * @device: the rdma device
  4214. * @comp_vector: index of completion vector
  4215. *
  4216. * Returns NULL on failure, otherwise a corresponding cpu map of the
  4217. * completion vector (returns all-cpus map if the device driver doesn't
  4218. * implement get_vector_affinity).
  4219. */
  4220. static inline const struct cpumask *
  4221. ib_get_vector_affinity(struct ib_device *device, int comp_vector)
  4222. {
  4223. if (comp_vector < 0 || comp_vector >= device->num_comp_vectors ||
  4224. !device->ops.get_vector_affinity)
  4225. return NULL;
  4226. return device->ops.get_vector_affinity(device, comp_vector);
  4227. }
  4228. /**
  4229. * rdma_roce_rescan_device - Rescan all of the network devices in the system
  4230. * and add their gids, as needed, to the relevant RoCE devices.
  4231. *
  4232. * @device: the rdma device
  4233. */
  4234. void rdma_roce_rescan_device(struct ib_device *ibdev);
  4235. void rdma_roce_rescan_port(struct ib_device *ib_dev, u32 port);
  4236. void roce_del_all_netdev_gids(struct ib_device *ib_dev,
  4237. u32 port, struct net_device *ndev);
  4238. struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
  4239. int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs);
  4240. struct net_device *rdma_alloc_netdev(struct ib_device *device, u32 port_num,
  4241. enum rdma_netdev_t type, const char *name,
  4242. unsigned char name_assign_type,
  4243. void (*setup)(struct net_device *));
  4244. int rdma_init_netdev(struct ib_device *device, u32 port_num,
  4245. enum rdma_netdev_t type, const char *name,
  4246. unsigned char name_assign_type,
  4247. void (*setup)(struct net_device *),
  4248. struct net_device *netdev);
  4249. /**
  4250. * rdma_device_to_ibdev - Get ib_device pointer from device pointer
  4251. *
  4252. * @device: device pointer for which ib_device pointer to retrieve
  4253. *
  4254. * rdma_device_to_ibdev() retrieves ib_device pointer from device.
  4255. *
  4256. */
  4257. static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
  4258. {
  4259. struct ib_core_device *coredev =
  4260. container_of(device, struct ib_core_device, dev);
  4261. return coredev->owner;
  4262. }
  4263. /**
  4264. * ibdev_to_node - return the NUMA node for a given ib_device
  4265. * @dev: device to get the NUMA node for.
  4266. */
  4267. static inline int ibdev_to_node(struct ib_device *ibdev)
  4268. {
  4269. struct device *parent = ibdev->dev.parent;
  4270. if (!parent)
  4271. return NUMA_NO_NODE;
  4272. return dev_to_node(parent);
  4273. }
  4274. /**
  4275. * rdma_device_to_drv_device - Helper macro to reach back to driver's
  4276. * ib_device holder structure from device pointer.
  4277. *
  4278. * NOTE: New drivers should not make use of this API; This API is only for
  4279. * existing drivers who have exposed sysfs entries using
  4280. * ops->device_group.
  4281. */
  4282. #define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member) \
  4283. container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)
  4284. bool rdma_dev_access_netns(const struct ib_device *device,
  4285. const struct net *net);
  4286. #define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
  4287. #define IB_ROCE_UDP_ENCAP_VALID_PORT_MAX (0xFFFF)
  4288. #define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
  4289. /**
  4290. * rdma_flow_label_to_udp_sport - generate a RoCE v2 UDP src port value based
  4291. * on the flow_label
  4292. *
  4293. * This function will convert the 20 bit flow_label input to a valid RoCE v2
  4294. * UDP src port 14 bit value. All RoCE V2 drivers should use this same
  4295. * convention.
  4296. */
  4297. static inline u16 rdma_flow_label_to_udp_sport(u32 fl)
  4298. {
  4299. u32 fl_low = fl & 0x03fff, fl_high = fl & 0xFC000;
  4300. fl_low ^= fl_high >> 14;
  4301. return (u16)(fl_low | IB_ROCE_UDP_ENCAP_VALID_PORT_MIN);
  4302. }
  4303. /**
  4304. * rdma_calc_flow_label - generate a RDMA symmetric flow label value based on
  4305. * local and remote qpn values
  4306. *
  4307. * This function folded the multiplication results of two qpns, 24 bit each,
  4308. * fields, and converts it to a 20 bit results.
  4309. *
  4310. * This function will create symmetric flow_label value based on the local
  4311. * and remote qpn values. this will allow both the requester and responder
  4312. * to calculate the same flow_label for a given connection.
  4313. *
  4314. * This helper function should be used by driver in case the upper layer
  4315. * provide a zero flow_label value. This is to improve entropy of RDMA
  4316. * traffic in the network.
  4317. */
  4318. static inline u32 rdma_calc_flow_label(u32 lqpn, u32 rqpn)
  4319. {
  4320. u64 v = (u64)lqpn * rqpn;
  4321. v ^= v >> 20;
  4322. v ^= v >> 40;
  4323. return (u32)(v & IB_GRH_FLOWLABEL_MASK);
  4324. }
  4325. /**
  4326. * rdma_get_udp_sport - Calculate and set UDP source port based on the flow
  4327. * label. If flow label is not defined in GRH then
  4328. * calculate it based on lqpn/rqpn.
  4329. *
  4330. * @fl: flow label from GRH
  4331. * @lqpn: local qp number
  4332. * @rqpn: remote qp number
  4333. */
  4334. static inline u16 rdma_get_udp_sport(u32 fl, u32 lqpn, u32 rqpn)
  4335. {
  4336. if (!fl)
  4337. fl = rdma_calc_flow_label(lqpn, rqpn);
  4338. return rdma_flow_label_to_udp_sport(fl);
  4339. }
  4340. const struct ib_port_immutable*
  4341. ib_port_immutable_read(struct ib_device *dev, unsigned int port);
  4342. /** ib_add_sub_device - Add a sub IB device on an existing one
  4343. *
  4344. * @parent: The IB device that needs to add a sub device
  4345. * @type: The type of the new sub device
  4346. * @name: The name of the new sub device
  4347. *
  4348. *
  4349. * Return 0 on success, an error code otherwise
  4350. */
  4351. int ib_add_sub_device(struct ib_device *parent,
  4352. enum rdma_nl_dev_type type,
  4353. const char *name);
  4354. /** ib_del_sub_device_and_put - Delect an IB sub device while holding a 'get'
  4355. *
  4356. * @sub: The sub device that is going to be deleted
  4357. *
  4358. * Return 0 on success, an error code otherwise
  4359. */
  4360. int ib_del_sub_device_and_put(struct ib_device *sub);
  4361. static inline void ib_mark_name_assigned_by_user(struct ib_device *ibdev)
  4362. {
  4363. ibdev->name_assign_type = RDMA_NAME_ASSIGN_TYPE_USER;
  4364. }
  4365. #endif /* IB_VERBS_H */