ib_verbs.h 117 KB

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