ib_verbs.h 106 KB

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