ib_verbs.h 97 KB

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