verbs.h 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2004, 2011-2012 Intel Corporation. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
  5. * Copyright (c) 2005 PathScale, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #ifndef INFINIBAND_VERBS_H
  36. #define INFINIBAND_VERBS_H
  37. #include <stdint.h>
  38. #include <pthread.h>
  39. #include <stddef.h>
  40. #include <errno.h>
  41. #include <string.h>
  42. #include <linux/types.h>
  43. #include <stdint.h>
  44. #include <sys/types.h>
  45. #include <infiniband/verbs_api.h>
  46. #ifdef __cplusplus
  47. #include <limits>
  48. #endif
  49. #if __GNUC__ >= 3
  50. # define __attribute_const __attribute__((const))
  51. #else
  52. # define __attribute_const
  53. #endif
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. union ibv_gid {
  58. uint8_t raw[16];
  59. struct {
  60. __be64 subnet_prefix;
  61. __be64 interface_id;
  62. } global;
  63. };
  64. enum ibv_gid_type {
  65. IBV_GID_TYPE_IB,
  66. IBV_GID_TYPE_ROCE_V1,
  67. IBV_GID_TYPE_ROCE_V2,
  68. };
  69. struct ibv_gid_entry {
  70. union ibv_gid gid;
  71. uint32_t gid_index;
  72. uint32_t port_num;
  73. uint32_t gid_type; /* enum ibv_gid_type */
  74. uint32_t ndev_ifindex;
  75. };
  76. #define vext_field_avail(type, fld, sz) (offsetof(type, fld) < (sz))
  77. #ifdef __cplusplus
  78. #define __VERBS_ABI_IS_EXTENDED ((void *)std::numeric_limits<uintptr_t>::max())
  79. #else
  80. #define __VERBS_ABI_IS_EXTENDED ((void *)UINTPTR_MAX)
  81. #endif
  82. enum ibv_node_type {
  83. IBV_NODE_UNKNOWN = -1,
  84. IBV_NODE_CA = 1,
  85. IBV_NODE_SWITCH,
  86. IBV_NODE_ROUTER,
  87. IBV_NODE_RNIC,
  88. IBV_NODE_USNIC,
  89. IBV_NODE_USNIC_UDP,
  90. IBV_NODE_UNSPECIFIED,
  91. };
  92. enum ibv_transport_type {
  93. IBV_TRANSPORT_UNKNOWN = -1,
  94. IBV_TRANSPORT_IB = 0,
  95. IBV_TRANSPORT_IWARP,
  96. IBV_TRANSPORT_USNIC,
  97. IBV_TRANSPORT_USNIC_UDP,
  98. IBV_TRANSPORT_UNSPECIFIED,
  99. };
  100. enum ibv_device_cap_flags {
  101. IBV_DEVICE_RESIZE_MAX_WR = 1,
  102. IBV_DEVICE_BAD_PKEY_CNTR = 1 << 1,
  103. IBV_DEVICE_BAD_QKEY_CNTR = 1 << 2,
  104. IBV_DEVICE_RAW_MULTI = 1 << 3,
  105. IBV_DEVICE_AUTO_PATH_MIG = 1 << 4,
  106. IBV_DEVICE_CHANGE_PHY_PORT = 1 << 5,
  107. IBV_DEVICE_UD_AV_PORT_ENFORCE = 1 << 6,
  108. IBV_DEVICE_CURR_QP_STATE_MOD = 1 << 7,
  109. IBV_DEVICE_SHUTDOWN_PORT = 1 << 8,
  110. IBV_DEVICE_INIT_TYPE = 1 << 9,
  111. IBV_DEVICE_PORT_ACTIVE_EVENT = 1 << 10,
  112. IBV_DEVICE_SYS_IMAGE_GUID = 1 << 11,
  113. IBV_DEVICE_RC_RNR_NAK_GEN = 1 << 12,
  114. IBV_DEVICE_SRQ_RESIZE = 1 << 13,
  115. IBV_DEVICE_N_NOTIFY_CQ = 1 << 14,
  116. IBV_DEVICE_MEM_WINDOW = 1 << 17,
  117. IBV_DEVICE_UD_IP_CSUM = 1 << 18,
  118. IBV_DEVICE_XRC = 1 << 20,
  119. IBV_DEVICE_MEM_MGT_EXTENSIONS = 1 << 21,
  120. IBV_DEVICE_MEM_WINDOW_TYPE_2A = 1 << 23,
  121. IBV_DEVICE_MEM_WINDOW_TYPE_2B = 1 << 24,
  122. IBV_DEVICE_RC_IP_CSUM = 1 << 25,
  123. IBV_DEVICE_RAW_IP_CSUM = 1 << 26,
  124. IBV_DEVICE_MANAGED_FLOW_STEERING = 1 << 29
  125. };
  126. /*
  127. * Can't extended above ibv_device_cap_flags enum as in some systems/compilers
  128. * enum range is limited to 4 bytes.
  129. */
  130. #define IBV_DEVICE_RAW_SCATTER_FCS (1ULL << 34)
  131. #define IBV_DEVICE_PCI_WRITE_END_PADDING (1ULL << 36)
  132. enum ibv_atomic_cap {
  133. IBV_ATOMIC_NONE,
  134. IBV_ATOMIC_HCA,
  135. IBV_ATOMIC_GLOB
  136. };
  137. struct ibv_alloc_dm_attr {
  138. size_t length;
  139. uint32_t log_align_req;
  140. uint32_t comp_mask;
  141. };
  142. struct ibv_dm {
  143. struct ibv_context *context;
  144. int (*memcpy_to_dm)(struct ibv_dm *dm, uint64_t dm_offset,
  145. const void *host_addr, size_t length);
  146. int (*memcpy_from_dm)(void *host_addr, struct ibv_dm *dm,
  147. uint64_t dm_offset, size_t length);
  148. uint32_t comp_mask;
  149. };
  150. struct ibv_device_attr {
  151. char fw_ver[64];
  152. __be64 node_guid;
  153. __be64 sys_image_guid;
  154. uint64_t max_mr_size;
  155. uint64_t page_size_cap;
  156. uint32_t vendor_id;
  157. uint32_t vendor_part_id;
  158. uint32_t hw_ver;
  159. int max_qp;
  160. int max_qp_wr;
  161. unsigned int device_cap_flags;
  162. int max_sge;
  163. int max_sge_rd;
  164. int max_cq;
  165. int max_cqe;
  166. int max_mr;
  167. int max_pd;
  168. int max_qp_rd_atom;
  169. int max_ee_rd_atom;
  170. int max_res_rd_atom;
  171. int max_qp_init_rd_atom;
  172. int max_ee_init_rd_atom;
  173. enum ibv_atomic_cap atomic_cap;
  174. int max_ee;
  175. int max_rdd;
  176. int max_mw;
  177. int max_raw_ipv6_qp;
  178. int max_raw_ethy_qp;
  179. int max_mcast_grp;
  180. int max_mcast_qp_attach;
  181. int max_total_mcast_qp_attach;
  182. int max_ah;
  183. int max_fmr;
  184. int max_map_per_fmr;
  185. int max_srq;
  186. int max_srq_wr;
  187. int max_srq_sge;
  188. uint16_t max_pkeys;
  189. uint8_t local_ca_ack_delay;
  190. uint8_t phys_port_cnt;
  191. };
  192. /* An extensible input struct for possible future extensions of the
  193. * ibv_query_device_ex verb. */
  194. struct ibv_query_device_ex_input {
  195. uint32_t comp_mask;
  196. };
  197. enum ibv_odp_transport_cap_bits {
  198. IBV_ODP_SUPPORT_SEND = 1 << 0,
  199. IBV_ODP_SUPPORT_RECV = 1 << 1,
  200. IBV_ODP_SUPPORT_WRITE = 1 << 2,
  201. IBV_ODP_SUPPORT_READ = 1 << 3,
  202. IBV_ODP_SUPPORT_ATOMIC = 1 << 4,
  203. IBV_ODP_SUPPORT_SRQ_RECV = 1 << 5,
  204. };
  205. struct ibv_odp_caps {
  206. uint64_t general_caps;
  207. struct {
  208. uint32_t rc_odp_caps;
  209. uint32_t uc_odp_caps;
  210. uint32_t ud_odp_caps;
  211. } per_transport_caps;
  212. };
  213. enum ibv_odp_general_caps {
  214. IBV_ODP_SUPPORT = 1 << 0,
  215. IBV_ODP_SUPPORT_IMPLICIT = 1 << 1,
  216. };
  217. struct ibv_tso_caps {
  218. uint32_t max_tso;
  219. uint32_t supported_qpts;
  220. };
  221. /* RX Hash function flags */
  222. enum ibv_rx_hash_function_flags {
  223. IBV_RX_HASH_FUNC_TOEPLITZ = 1 << 0,
  224. };
  225. /*
  226. * RX Hash fields enable to set which incoming packet's field should
  227. * participates in RX Hash. Each flag represent certain packet's field,
  228. * when the flag is set the field that is represented by the flag will
  229. * participate in RX Hash calculation.
  230. * Note: *IPV4 and *IPV6 flags can't be enabled together on the same QP
  231. * and *TCP and *UDP flags can't be enabled together on the same QP.
  232. */
  233. enum ibv_rx_hash_fields {
  234. IBV_RX_HASH_SRC_IPV4 = 1 << 0,
  235. IBV_RX_HASH_DST_IPV4 = 1 << 1,
  236. IBV_RX_HASH_SRC_IPV6 = 1 << 2,
  237. IBV_RX_HASH_DST_IPV6 = 1 << 3,
  238. IBV_RX_HASH_SRC_PORT_TCP = 1 << 4,
  239. IBV_RX_HASH_DST_PORT_TCP = 1 << 5,
  240. IBV_RX_HASH_SRC_PORT_UDP = 1 << 6,
  241. IBV_RX_HASH_DST_PORT_UDP = 1 << 7,
  242. IBV_RX_HASH_IPSEC_SPI = 1 << 8,
  243. IBV_RX_HASH_INNER = (1UL << 31),
  244. };
  245. struct ibv_rss_caps {
  246. uint32_t supported_qpts;
  247. uint32_t max_rwq_indirection_tables;
  248. uint32_t max_rwq_indirection_table_size;
  249. uint64_t rx_hash_fields_mask; /* enum ibv_rx_hash_fields */
  250. uint8_t rx_hash_function; /* enum ibv_rx_hash_function_flags */
  251. };
  252. struct ibv_packet_pacing_caps {
  253. uint32_t qp_rate_limit_min;
  254. uint32_t qp_rate_limit_max; /* In kbps */
  255. uint32_t supported_qpts;
  256. };
  257. enum ibv_raw_packet_caps {
  258. IBV_RAW_PACKET_CAP_CVLAN_STRIPPING = 1 << 0,
  259. IBV_RAW_PACKET_CAP_SCATTER_FCS = 1 << 1,
  260. IBV_RAW_PACKET_CAP_IP_CSUM = 1 << 2,
  261. IBV_RAW_PACKET_CAP_DELAY_DROP = 1 << 3,
  262. };
  263. enum ibv_tm_cap_flags {
  264. IBV_TM_CAP_RC = 1 << 0,
  265. };
  266. struct ibv_tm_caps {
  267. /* Max size of rendezvous request header */
  268. uint32_t max_rndv_hdr_size;
  269. /* Max number of tagged buffers in a TM-SRQ matching list */
  270. uint32_t max_num_tags;
  271. /* From enum ibv_tm_cap_flags */
  272. uint32_t flags;
  273. /* Max number of outstanding list operations */
  274. uint32_t max_ops;
  275. /* Max number of SGEs in a tagged buffer */
  276. uint32_t max_sge;
  277. };
  278. struct ibv_cq_moderation_caps {
  279. uint16_t max_cq_count;
  280. uint16_t max_cq_period; /* in micro seconds */
  281. };
  282. enum ibv_pci_atomic_op_size {
  283. IBV_PCI_ATOMIC_OPERATION_4_BYTE_SIZE_SUP = 1 << 0,
  284. IBV_PCI_ATOMIC_OPERATION_8_BYTE_SIZE_SUP = 1 << 1,
  285. IBV_PCI_ATOMIC_OPERATION_16_BYTE_SIZE_SUP = 1 << 2,
  286. };
  287. /*
  288. * Bitmask for supported operation sizes
  289. * Use enum ibv_pci_atomic_op_size
  290. */
  291. struct ibv_pci_atomic_caps {
  292. uint16_t fetch_add;
  293. uint16_t swap;
  294. uint16_t compare_swap;
  295. };
  296. struct ibv_device_attr_ex {
  297. struct ibv_device_attr orig_attr;
  298. uint32_t comp_mask;
  299. struct ibv_odp_caps odp_caps;
  300. uint64_t completion_timestamp_mask;
  301. uint64_t hca_core_clock;
  302. uint64_t device_cap_flags_ex;
  303. struct ibv_tso_caps tso_caps;
  304. struct ibv_rss_caps rss_caps;
  305. uint32_t max_wq_type_rq;
  306. struct ibv_packet_pacing_caps packet_pacing_caps;
  307. uint32_t raw_packet_caps; /* Use ibv_raw_packet_caps */
  308. struct ibv_tm_caps tm_caps;
  309. struct ibv_cq_moderation_caps cq_mod_caps;
  310. uint64_t max_dm_size;
  311. struct ibv_pci_atomic_caps pci_atomic_caps;
  312. uint32_t xrc_odp_caps;
  313. };
  314. enum ibv_mtu {
  315. IBV_MTU_256 = 1,
  316. IBV_MTU_512 = 2,
  317. IBV_MTU_1024 = 3,
  318. IBV_MTU_2048 = 4,
  319. IBV_MTU_4096 = 5
  320. };
  321. enum ibv_port_state {
  322. IBV_PORT_NOP = 0,
  323. IBV_PORT_DOWN = 1,
  324. IBV_PORT_INIT = 2,
  325. IBV_PORT_ARMED = 3,
  326. IBV_PORT_ACTIVE = 4,
  327. IBV_PORT_ACTIVE_DEFER = 5
  328. };
  329. enum {
  330. IBV_LINK_LAYER_UNSPECIFIED,
  331. IBV_LINK_LAYER_INFINIBAND,
  332. IBV_LINK_LAYER_ETHERNET,
  333. };
  334. enum ibv_port_cap_flags {
  335. IBV_PORT_SM = 1 << 1,
  336. IBV_PORT_NOTICE_SUP = 1 << 2,
  337. IBV_PORT_TRAP_SUP = 1 << 3,
  338. IBV_PORT_OPT_IPD_SUP = 1 << 4,
  339. IBV_PORT_AUTO_MIGR_SUP = 1 << 5,
  340. IBV_PORT_SL_MAP_SUP = 1 << 6,
  341. IBV_PORT_MKEY_NVRAM = 1 << 7,
  342. IBV_PORT_PKEY_NVRAM = 1 << 8,
  343. IBV_PORT_LED_INFO_SUP = 1 << 9,
  344. IBV_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  345. IBV_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  346. IBV_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
  347. IBV_PORT_CAP_MASK2_SUP = 1 << 15,
  348. IBV_PORT_CM_SUP = 1 << 16,
  349. IBV_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  350. IBV_PORT_REINIT_SUP = 1 << 18,
  351. IBV_PORT_DEVICE_MGMT_SUP = 1 << 19,
  352. IBV_PORT_VENDOR_CLASS_SUP = 1 << 20,
  353. IBV_PORT_DR_NOTICE_SUP = 1 << 21,
  354. IBV_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  355. IBV_PORT_BOOT_MGMT_SUP = 1 << 23,
  356. IBV_PORT_LINK_LATENCY_SUP = 1 << 24,
  357. IBV_PORT_CLIENT_REG_SUP = 1 << 25,
  358. IBV_PORT_IP_BASED_GIDS = 1 << 26
  359. };
  360. enum ibv_port_cap_flags2 {
  361. IBV_PORT_SET_NODE_DESC_SUP = 1 << 0,
  362. IBV_PORT_INFO_EXT_SUP = 1 << 1,
  363. IBV_PORT_VIRT_SUP = 1 << 2,
  364. IBV_PORT_SWITCH_PORT_STATE_TABLE_SUP = 1 << 3,
  365. IBV_PORT_LINK_WIDTH_2X_SUP = 1 << 4,
  366. IBV_PORT_LINK_SPEED_HDR_SUP = 1 << 5,
  367. };
  368. struct ibv_port_attr {
  369. enum ibv_port_state state;
  370. enum ibv_mtu max_mtu;
  371. enum ibv_mtu active_mtu;
  372. int gid_tbl_len;
  373. uint32_t port_cap_flags;
  374. uint32_t max_msg_sz;
  375. uint32_t bad_pkey_cntr;
  376. uint32_t qkey_viol_cntr;
  377. uint16_t pkey_tbl_len;
  378. uint16_t lid;
  379. uint16_t sm_lid;
  380. uint8_t lmc;
  381. uint8_t max_vl_num;
  382. uint8_t sm_sl;
  383. uint8_t subnet_timeout;
  384. uint8_t init_type_reply;
  385. uint8_t active_width;
  386. uint8_t active_speed;
  387. uint8_t phys_state;
  388. uint8_t link_layer;
  389. uint8_t flags;
  390. uint16_t port_cap_flags2;
  391. };
  392. enum ibv_event_type {
  393. IBV_EVENT_CQ_ERR,
  394. IBV_EVENT_QP_FATAL,
  395. IBV_EVENT_QP_REQ_ERR,
  396. IBV_EVENT_QP_ACCESS_ERR,
  397. IBV_EVENT_COMM_EST,
  398. IBV_EVENT_SQ_DRAINED,
  399. IBV_EVENT_PATH_MIG,
  400. IBV_EVENT_PATH_MIG_ERR,
  401. IBV_EVENT_DEVICE_FATAL,
  402. IBV_EVENT_PORT_ACTIVE,
  403. IBV_EVENT_PORT_ERR,
  404. IBV_EVENT_LID_CHANGE,
  405. IBV_EVENT_PKEY_CHANGE,
  406. IBV_EVENT_SM_CHANGE,
  407. IBV_EVENT_SRQ_ERR,
  408. IBV_EVENT_SRQ_LIMIT_REACHED,
  409. IBV_EVENT_QP_LAST_WQE_REACHED,
  410. IBV_EVENT_CLIENT_REREGISTER,
  411. IBV_EVENT_GID_CHANGE,
  412. IBV_EVENT_WQ_FATAL,
  413. };
  414. struct ibv_async_event {
  415. union {
  416. struct ibv_cq *cq;
  417. struct ibv_qp *qp;
  418. struct ibv_srq *srq;
  419. struct ibv_wq *wq;
  420. int port_num;
  421. } element;
  422. enum ibv_event_type event_type;
  423. };
  424. enum ibv_wc_status {
  425. IBV_WC_SUCCESS,
  426. IBV_WC_LOC_LEN_ERR,
  427. IBV_WC_LOC_QP_OP_ERR,
  428. IBV_WC_LOC_EEC_OP_ERR,
  429. IBV_WC_LOC_PROT_ERR,
  430. IBV_WC_WR_FLUSH_ERR,
  431. IBV_WC_MW_BIND_ERR,
  432. IBV_WC_BAD_RESP_ERR,
  433. IBV_WC_LOC_ACCESS_ERR,
  434. IBV_WC_REM_INV_REQ_ERR,
  435. IBV_WC_REM_ACCESS_ERR,
  436. IBV_WC_REM_OP_ERR,
  437. IBV_WC_RETRY_EXC_ERR,
  438. IBV_WC_RNR_RETRY_EXC_ERR,
  439. IBV_WC_LOC_RDD_VIOL_ERR,
  440. IBV_WC_REM_INV_RD_REQ_ERR,
  441. IBV_WC_REM_ABORT_ERR,
  442. IBV_WC_INV_EECN_ERR,
  443. IBV_WC_INV_EEC_STATE_ERR,
  444. IBV_WC_FATAL_ERR,
  445. IBV_WC_RESP_TIMEOUT_ERR,
  446. IBV_WC_GENERAL_ERR,
  447. IBV_WC_TM_ERR,
  448. IBV_WC_TM_RNDV_INCOMPLETE,
  449. };
  450. const char *ibv_wc_status_str(enum ibv_wc_status status);
  451. enum ibv_wc_opcode {
  452. IBV_WC_SEND,
  453. IBV_WC_RDMA_WRITE,
  454. IBV_WC_RDMA_READ,
  455. IBV_WC_COMP_SWAP,
  456. IBV_WC_FETCH_ADD,
  457. IBV_WC_BIND_MW,
  458. IBV_WC_LOCAL_INV,
  459. IBV_WC_TSO,
  460. /*
  461. * Set value of IBV_WC_RECV so consumers can test if a completion is a
  462. * receive by testing (opcode & IBV_WC_RECV).
  463. */
  464. IBV_WC_RECV = 1 << 7,
  465. IBV_WC_RECV_RDMA_WITH_IMM,
  466. IBV_WC_TM_ADD,
  467. IBV_WC_TM_DEL,
  468. IBV_WC_TM_SYNC,
  469. IBV_WC_TM_RECV,
  470. IBV_WC_TM_NO_TAG,
  471. IBV_WC_DRIVER1,
  472. };
  473. enum {
  474. IBV_WC_IP_CSUM_OK_SHIFT = 2
  475. };
  476. enum ibv_create_cq_wc_flags {
  477. IBV_WC_EX_WITH_BYTE_LEN = 1 << 0,
  478. IBV_WC_EX_WITH_IMM = 1 << 1,
  479. IBV_WC_EX_WITH_QP_NUM = 1 << 2,
  480. IBV_WC_EX_WITH_SRC_QP = 1 << 3,
  481. IBV_WC_EX_WITH_SLID = 1 << 4,
  482. IBV_WC_EX_WITH_SL = 1 << 5,
  483. IBV_WC_EX_WITH_DLID_PATH_BITS = 1 << 6,
  484. IBV_WC_EX_WITH_COMPLETION_TIMESTAMP = 1 << 7,
  485. IBV_WC_EX_WITH_CVLAN = 1 << 8,
  486. IBV_WC_EX_WITH_FLOW_TAG = 1 << 9,
  487. IBV_WC_EX_WITH_TM_INFO = 1 << 10,
  488. IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK = 1 << 11,
  489. };
  490. enum {
  491. IBV_WC_STANDARD_FLAGS = IBV_WC_EX_WITH_BYTE_LEN |
  492. IBV_WC_EX_WITH_IMM |
  493. IBV_WC_EX_WITH_QP_NUM |
  494. IBV_WC_EX_WITH_SRC_QP |
  495. IBV_WC_EX_WITH_SLID |
  496. IBV_WC_EX_WITH_SL |
  497. IBV_WC_EX_WITH_DLID_PATH_BITS
  498. };
  499. enum {
  500. IBV_CREATE_CQ_SUP_WC_FLAGS = IBV_WC_STANDARD_FLAGS |
  501. IBV_WC_EX_WITH_COMPLETION_TIMESTAMP |
  502. IBV_WC_EX_WITH_CVLAN |
  503. IBV_WC_EX_WITH_FLOW_TAG |
  504. IBV_WC_EX_WITH_TM_INFO |
  505. IBV_WC_EX_WITH_COMPLETION_TIMESTAMP_WALLCLOCK
  506. };
  507. enum ibv_wc_flags {
  508. IBV_WC_GRH = 1 << 0,
  509. IBV_WC_WITH_IMM = 1 << 1,
  510. IBV_WC_IP_CSUM_OK = 1 << IBV_WC_IP_CSUM_OK_SHIFT,
  511. IBV_WC_WITH_INV = 1 << 3,
  512. IBV_WC_TM_SYNC_REQ = 1 << 4,
  513. IBV_WC_TM_MATCH = 1 << 5,
  514. IBV_WC_TM_DATA_VALID = 1 << 6,
  515. };
  516. struct ibv_wc {
  517. uint64_t wr_id;
  518. enum ibv_wc_status status;
  519. enum ibv_wc_opcode opcode;
  520. uint32_t vendor_err;
  521. uint32_t byte_len;
  522. /* When (wc_flags & IBV_WC_WITH_IMM): Immediate data in network byte order.
  523. * When (wc_flags & IBV_WC_WITH_INV): Stores the invalidated rkey.
  524. */
  525. union {
  526. __be32 imm_data;
  527. uint32_t invalidated_rkey;
  528. };
  529. uint32_t qp_num;
  530. uint32_t src_qp;
  531. unsigned int wc_flags;
  532. uint16_t pkey_index;
  533. uint16_t slid;
  534. uint8_t sl;
  535. uint8_t dlid_path_bits;
  536. };
  537. enum ibv_access_flags {
  538. IBV_ACCESS_LOCAL_WRITE = 1,
  539. IBV_ACCESS_REMOTE_WRITE = (1<<1),
  540. IBV_ACCESS_REMOTE_READ = (1<<2),
  541. IBV_ACCESS_REMOTE_ATOMIC = (1<<3),
  542. IBV_ACCESS_MW_BIND = (1<<4),
  543. IBV_ACCESS_ZERO_BASED = (1<<5),
  544. IBV_ACCESS_ON_DEMAND = (1<<6),
  545. IBV_ACCESS_HUGETLB = (1<<7),
  546. IBV_ACCESS_RELAXED_ORDERING = IBV_ACCESS_OPTIONAL_FIRST,
  547. };
  548. struct ibv_mw_bind_info {
  549. struct ibv_mr *mr;
  550. uint64_t addr;
  551. uint64_t length;
  552. unsigned int mw_access_flags; /* use ibv_access_flags */
  553. };
  554. struct ibv_pd {
  555. struct ibv_context *context;
  556. uint32_t handle;
  557. };
  558. struct ibv_td_init_attr {
  559. uint32_t comp_mask;
  560. };
  561. struct ibv_td {
  562. struct ibv_context *context;
  563. };
  564. enum ibv_xrcd_init_attr_mask {
  565. IBV_XRCD_INIT_ATTR_FD = 1 << 0,
  566. IBV_XRCD_INIT_ATTR_OFLAGS = 1 << 1,
  567. IBV_XRCD_INIT_ATTR_RESERVED = 1 << 2
  568. };
  569. struct ibv_xrcd_init_attr {
  570. uint32_t comp_mask;
  571. int fd;
  572. int oflags;
  573. };
  574. struct ibv_xrcd {
  575. struct ibv_context *context;
  576. };
  577. enum ibv_rereg_mr_flags {
  578. IBV_REREG_MR_CHANGE_TRANSLATION = (1 << 0),
  579. IBV_REREG_MR_CHANGE_PD = (1 << 1),
  580. IBV_REREG_MR_CHANGE_ACCESS = (1 << 2),
  581. IBV_REREG_MR_KEEP_VALID = (1 << 3),
  582. IBV_REREG_MR_FLAGS_SUPPORTED = ((IBV_REREG_MR_KEEP_VALID << 1) - 1)
  583. };
  584. struct ibv_mr {
  585. struct ibv_context *context;
  586. struct ibv_pd *pd;
  587. void *addr;
  588. size_t length;
  589. uint32_t handle;
  590. uint32_t lkey;
  591. uint32_t rkey;
  592. };
  593. enum ibv_mw_type {
  594. IBV_MW_TYPE_1 = 1,
  595. IBV_MW_TYPE_2 = 2
  596. };
  597. struct ibv_mw {
  598. struct ibv_context *context;
  599. struct ibv_pd *pd;
  600. uint32_t rkey;
  601. uint32_t handle;
  602. enum ibv_mw_type type;
  603. };
  604. struct ibv_global_route {
  605. union ibv_gid dgid;
  606. uint32_t flow_label;
  607. uint8_t sgid_index;
  608. uint8_t hop_limit;
  609. uint8_t traffic_class;
  610. };
  611. struct ibv_grh {
  612. __be32 version_tclass_flow;
  613. __be16 paylen;
  614. uint8_t next_hdr;
  615. uint8_t hop_limit;
  616. union ibv_gid sgid;
  617. union ibv_gid dgid;
  618. };
  619. enum ibv_rate {
  620. IBV_RATE_MAX = 0,
  621. IBV_RATE_2_5_GBPS = 2,
  622. IBV_RATE_5_GBPS = 5,
  623. IBV_RATE_10_GBPS = 3,
  624. IBV_RATE_20_GBPS = 6,
  625. IBV_RATE_30_GBPS = 4,
  626. IBV_RATE_40_GBPS = 7,
  627. IBV_RATE_60_GBPS = 8,
  628. IBV_RATE_80_GBPS = 9,
  629. IBV_RATE_120_GBPS = 10,
  630. IBV_RATE_14_GBPS = 11,
  631. IBV_RATE_56_GBPS = 12,
  632. IBV_RATE_112_GBPS = 13,
  633. IBV_RATE_168_GBPS = 14,
  634. IBV_RATE_25_GBPS = 15,
  635. IBV_RATE_100_GBPS = 16,
  636. IBV_RATE_200_GBPS = 17,
  637. IBV_RATE_300_GBPS = 18,
  638. IBV_RATE_28_GBPS = 19,
  639. IBV_RATE_50_GBPS = 20,
  640. IBV_RATE_400_GBPS = 21,
  641. IBV_RATE_600_GBPS = 22,
  642. };
  643. /**
  644. * ibv_rate_to_mult - Convert the IB rate enum to a multiple of the
  645. * base rate of 2.5 Gbit/sec. For example, IBV_RATE_5_GBPS will be
  646. * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
  647. * @rate: rate to convert.
  648. */
  649. int __attribute_const ibv_rate_to_mult(enum ibv_rate rate);
  650. /**
  651. * mult_to_ibv_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate enum.
  652. * @mult: multiple to convert.
  653. */
  654. enum ibv_rate __attribute_const mult_to_ibv_rate(int mult);
  655. /**
  656. * ibv_rate_to_mbps - Convert the IB rate enum to Mbit/sec.
  657. * For example, IBV_RATE_5_GBPS will return the value 5000.
  658. * @rate: rate to convert.
  659. */
  660. int __attribute_const ibv_rate_to_mbps(enum ibv_rate rate);
  661. /**
  662. * mbps_to_ibv_rate - Convert a Mbit/sec value to an IB rate enum.
  663. * @mbps: value to convert.
  664. */
  665. enum ibv_rate __attribute_const mbps_to_ibv_rate(int mbps) __attribute_const;
  666. struct ibv_ah_attr {
  667. struct ibv_global_route grh;
  668. uint16_t dlid;
  669. uint8_t sl;
  670. uint8_t src_path_bits;
  671. uint8_t static_rate;
  672. uint8_t is_global;
  673. uint8_t port_num;
  674. };
  675. enum ibv_srq_attr_mask {
  676. IBV_SRQ_MAX_WR = 1 << 0,
  677. IBV_SRQ_LIMIT = 1 << 1
  678. };
  679. struct ibv_srq_attr {
  680. uint32_t max_wr;
  681. uint32_t max_sge;
  682. uint32_t srq_limit;
  683. };
  684. struct ibv_srq_init_attr {
  685. void *srq_context;
  686. struct ibv_srq_attr attr;
  687. };
  688. enum ibv_srq_type {
  689. IBV_SRQT_BASIC,
  690. IBV_SRQT_XRC,
  691. IBV_SRQT_TM,
  692. };
  693. enum ibv_srq_init_attr_mask {
  694. IBV_SRQ_INIT_ATTR_TYPE = 1 << 0,
  695. IBV_SRQ_INIT_ATTR_PD = 1 << 1,
  696. IBV_SRQ_INIT_ATTR_XRCD = 1 << 2,
  697. IBV_SRQ_INIT_ATTR_CQ = 1 << 3,
  698. IBV_SRQ_INIT_ATTR_TM = 1 << 4,
  699. IBV_SRQ_INIT_ATTR_RESERVED = 1 << 5,
  700. };
  701. struct ibv_tm_cap {
  702. uint32_t max_num_tags;
  703. uint32_t max_ops;
  704. };
  705. struct ibv_srq_init_attr_ex {
  706. void *srq_context;
  707. struct ibv_srq_attr attr;
  708. uint32_t comp_mask;
  709. enum ibv_srq_type srq_type;
  710. struct ibv_pd *pd;
  711. struct ibv_xrcd *xrcd;
  712. struct ibv_cq *cq;
  713. struct ibv_tm_cap tm_cap;
  714. };
  715. enum ibv_wq_type {
  716. IBV_WQT_RQ
  717. };
  718. enum ibv_wq_init_attr_mask {
  719. IBV_WQ_INIT_ATTR_FLAGS = 1 << 0,
  720. IBV_WQ_INIT_ATTR_RESERVED = 1 << 1,
  721. };
  722. enum ibv_wq_flags {
  723. IBV_WQ_FLAGS_CVLAN_STRIPPING = 1 << 0,
  724. IBV_WQ_FLAGS_SCATTER_FCS = 1 << 1,
  725. IBV_WQ_FLAGS_DELAY_DROP = 1 << 2,
  726. IBV_WQ_FLAGS_PCI_WRITE_END_PADDING = 1 << 3,
  727. IBV_WQ_FLAGS_RESERVED = 1 << 4,
  728. };
  729. struct ibv_wq_init_attr {
  730. void *wq_context;
  731. enum ibv_wq_type wq_type;
  732. uint32_t max_wr;
  733. uint32_t max_sge;
  734. struct ibv_pd *pd;
  735. struct ibv_cq *cq;
  736. uint32_t comp_mask; /* Use ibv_wq_init_attr_mask */
  737. uint32_t create_flags; /* use ibv_wq_flags */
  738. };
  739. enum ibv_wq_state {
  740. IBV_WQS_RESET,
  741. IBV_WQS_RDY,
  742. IBV_WQS_ERR,
  743. IBV_WQS_UNKNOWN
  744. };
  745. enum ibv_wq_attr_mask {
  746. IBV_WQ_ATTR_STATE = 1 << 0,
  747. IBV_WQ_ATTR_CURR_STATE = 1 << 1,
  748. IBV_WQ_ATTR_FLAGS = 1 << 2,
  749. IBV_WQ_ATTR_RESERVED = 1 << 3,
  750. };
  751. struct ibv_wq_attr {
  752. /* enum ibv_wq_attr_mask */
  753. uint32_t attr_mask;
  754. /* Move the WQ to this state */
  755. enum ibv_wq_state wq_state;
  756. /* Assume this is the current WQ state */
  757. enum ibv_wq_state curr_wq_state;
  758. uint32_t flags; /* Use ibv_wq_flags */
  759. uint32_t flags_mask; /* Use ibv_wq_flags */
  760. };
  761. /*
  762. * Receive Work Queue Indirection Table.
  763. * It's used in order to distribute incoming packets between different
  764. * Receive Work Queues. Associating Receive WQs with different CPU cores
  765. * allows one to workload the traffic between different CPU cores.
  766. * The Indirection Table can contain only WQs of type IBV_WQT_RQ.
  767. */
  768. struct ibv_rwq_ind_table {
  769. struct ibv_context *context;
  770. int ind_tbl_handle;
  771. int ind_tbl_num;
  772. uint32_t comp_mask;
  773. };
  774. enum ibv_ind_table_init_attr_mask {
  775. IBV_CREATE_IND_TABLE_RESERVED = (1 << 0)
  776. };
  777. /*
  778. * Receive Work Queue Indirection Table attributes
  779. */
  780. struct ibv_rwq_ind_table_init_attr {
  781. uint32_t log_ind_tbl_size;
  782. /* Each entry is a pointer to a Receive Work Queue */
  783. struct ibv_wq **ind_tbl;
  784. uint32_t comp_mask;
  785. };
  786. enum ibv_qp_type {
  787. IBV_QPT_RC = 2,
  788. IBV_QPT_UC,
  789. IBV_QPT_UD,
  790. IBV_QPT_RAW_PACKET = 8,
  791. IBV_QPT_XRC_SEND = 9,
  792. IBV_QPT_XRC_RECV,
  793. IBV_QPT_DRIVER = 0xff,
  794. };
  795. struct ibv_qp_cap {
  796. uint32_t max_send_wr;
  797. uint32_t max_recv_wr;
  798. uint32_t max_send_sge;
  799. uint32_t max_recv_sge;
  800. uint32_t max_inline_data;
  801. };
  802. struct ibv_qp_init_attr {
  803. void *qp_context;
  804. struct ibv_cq *send_cq;
  805. struct ibv_cq *recv_cq;
  806. struct ibv_srq *srq;
  807. struct ibv_qp_cap cap;
  808. enum ibv_qp_type qp_type;
  809. int sq_sig_all;
  810. };
  811. enum ibv_qp_init_attr_mask {
  812. IBV_QP_INIT_ATTR_PD = 1 << 0,
  813. IBV_QP_INIT_ATTR_XRCD = 1 << 1,
  814. IBV_QP_INIT_ATTR_CREATE_FLAGS = 1 << 2,
  815. IBV_QP_INIT_ATTR_MAX_TSO_HEADER = 1 << 3,
  816. IBV_QP_INIT_ATTR_IND_TABLE = 1 << 4,
  817. IBV_QP_INIT_ATTR_RX_HASH = 1 << 5,
  818. IBV_QP_INIT_ATTR_SEND_OPS_FLAGS = 1 << 6,
  819. };
  820. enum ibv_qp_create_flags {
  821. IBV_QP_CREATE_BLOCK_SELF_MCAST_LB = 1 << 1,
  822. IBV_QP_CREATE_SCATTER_FCS = 1 << 8,
  823. IBV_QP_CREATE_CVLAN_STRIPPING = 1 << 9,
  824. IBV_QP_CREATE_SOURCE_QPN = 1 << 10,
  825. IBV_QP_CREATE_PCI_WRITE_END_PADDING = 1 << 11,
  826. };
  827. enum ibv_qp_create_send_ops_flags {
  828. IBV_QP_EX_WITH_RDMA_WRITE = 1 << 0,
  829. IBV_QP_EX_WITH_RDMA_WRITE_WITH_IMM = 1 << 1,
  830. IBV_QP_EX_WITH_SEND = 1 << 2,
  831. IBV_QP_EX_WITH_SEND_WITH_IMM = 1 << 3,
  832. IBV_QP_EX_WITH_RDMA_READ = 1 << 4,
  833. IBV_QP_EX_WITH_ATOMIC_CMP_AND_SWP = 1 << 5,
  834. IBV_QP_EX_WITH_ATOMIC_FETCH_AND_ADD = 1 << 6,
  835. IBV_QP_EX_WITH_LOCAL_INV = 1 << 7,
  836. IBV_QP_EX_WITH_BIND_MW = 1 << 8,
  837. IBV_QP_EX_WITH_SEND_WITH_INV = 1 << 9,
  838. IBV_QP_EX_WITH_TSO = 1 << 10,
  839. };
  840. struct ibv_rx_hash_conf {
  841. /* enum ibv_rx_hash_function_flags */
  842. uint8_t rx_hash_function;
  843. uint8_t rx_hash_key_len;
  844. uint8_t *rx_hash_key;
  845. /* enum ibv_rx_hash_fields */
  846. uint64_t rx_hash_fields_mask;
  847. };
  848. struct ibv_qp_init_attr_ex {
  849. void *qp_context;
  850. struct ibv_cq *send_cq;
  851. struct ibv_cq *recv_cq;
  852. struct ibv_srq *srq;
  853. struct ibv_qp_cap cap;
  854. enum ibv_qp_type qp_type;
  855. int sq_sig_all;
  856. uint32_t comp_mask;
  857. struct ibv_pd *pd;
  858. struct ibv_xrcd *xrcd;
  859. uint32_t create_flags;
  860. uint16_t max_tso_header;
  861. struct ibv_rwq_ind_table *rwq_ind_tbl;
  862. struct ibv_rx_hash_conf rx_hash_conf;
  863. uint32_t source_qpn;
  864. /* See enum ibv_qp_create_send_ops_flags */
  865. uint64_t send_ops_flags;
  866. };
  867. enum ibv_qp_open_attr_mask {
  868. IBV_QP_OPEN_ATTR_NUM = 1 << 0,
  869. IBV_QP_OPEN_ATTR_XRCD = 1 << 1,
  870. IBV_QP_OPEN_ATTR_CONTEXT = 1 << 2,
  871. IBV_QP_OPEN_ATTR_TYPE = 1 << 3,
  872. IBV_QP_OPEN_ATTR_RESERVED = 1 << 4
  873. };
  874. struct ibv_qp_open_attr {
  875. uint32_t comp_mask;
  876. uint32_t qp_num;
  877. struct ibv_xrcd *xrcd;
  878. void *qp_context;
  879. enum ibv_qp_type qp_type;
  880. };
  881. enum ibv_qp_attr_mask {
  882. IBV_QP_STATE = 1 << 0,
  883. IBV_QP_CUR_STATE = 1 << 1,
  884. IBV_QP_EN_SQD_ASYNC_NOTIFY = 1 << 2,
  885. IBV_QP_ACCESS_FLAGS = 1 << 3,
  886. IBV_QP_PKEY_INDEX = 1 << 4,
  887. IBV_QP_PORT = 1 << 5,
  888. IBV_QP_QKEY = 1 << 6,
  889. IBV_QP_AV = 1 << 7,
  890. IBV_QP_PATH_MTU = 1 << 8,
  891. IBV_QP_TIMEOUT = 1 << 9,
  892. IBV_QP_RETRY_CNT = 1 << 10,
  893. IBV_QP_RNR_RETRY = 1 << 11,
  894. IBV_QP_RQ_PSN = 1 << 12,
  895. IBV_QP_MAX_QP_RD_ATOMIC = 1 << 13,
  896. IBV_QP_ALT_PATH = 1 << 14,
  897. IBV_QP_MIN_RNR_TIMER = 1 << 15,
  898. IBV_QP_SQ_PSN = 1 << 16,
  899. IBV_QP_MAX_DEST_RD_ATOMIC = 1 << 17,
  900. IBV_QP_PATH_MIG_STATE = 1 << 18,
  901. IBV_QP_CAP = 1 << 19,
  902. IBV_QP_DEST_QPN = 1 << 20,
  903. /* These bits were supported on older kernels, but never exposed from
  904. libibverbs:
  905. _IBV_QP_SMAC = 1 << 21,
  906. _IBV_QP_ALT_SMAC = 1 << 22,
  907. _IBV_QP_VID = 1 << 23,
  908. _IBV_QP_ALT_VID = 1 << 24,
  909. */
  910. IBV_QP_RATE_LIMIT = 1 << 25,
  911. };
  912. enum ibv_qp_state {
  913. IBV_QPS_RESET,
  914. IBV_QPS_INIT,
  915. IBV_QPS_RTR,
  916. IBV_QPS_RTS,
  917. IBV_QPS_SQD,
  918. IBV_QPS_SQE,
  919. IBV_QPS_ERR,
  920. IBV_QPS_UNKNOWN
  921. };
  922. enum ibv_mig_state {
  923. IBV_MIG_MIGRATED,
  924. IBV_MIG_REARM,
  925. IBV_MIG_ARMED
  926. };
  927. struct ibv_qp_attr {
  928. enum ibv_qp_state qp_state;
  929. enum ibv_qp_state cur_qp_state;
  930. enum ibv_mtu path_mtu;
  931. enum ibv_mig_state path_mig_state;
  932. uint32_t qkey;
  933. uint32_t rq_psn;
  934. uint32_t sq_psn;
  935. uint32_t dest_qp_num;
  936. unsigned int qp_access_flags;
  937. struct ibv_qp_cap cap;
  938. struct ibv_ah_attr ah_attr;
  939. struct ibv_ah_attr alt_ah_attr;
  940. uint16_t pkey_index;
  941. uint16_t alt_pkey_index;
  942. uint8_t en_sqd_async_notify;
  943. uint8_t sq_draining;
  944. uint8_t max_rd_atomic;
  945. uint8_t max_dest_rd_atomic;
  946. uint8_t min_rnr_timer;
  947. uint8_t port_num;
  948. uint8_t timeout;
  949. uint8_t retry_cnt;
  950. uint8_t rnr_retry;
  951. uint8_t alt_port_num;
  952. uint8_t alt_timeout;
  953. uint32_t rate_limit;
  954. };
  955. struct ibv_qp_rate_limit_attr {
  956. uint32_t rate_limit; /* in kbps */
  957. uint32_t max_burst_sz; /* total burst size in bytes */
  958. uint16_t typical_pkt_sz; /* typical send packet size in bytes */
  959. uint32_t comp_mask;
  960. };
  961. enum ibv_wr_opcode {
  962. IBV_WR_RDMA_WRITE,
  963. IBV_WR_RDMA_WRITE_WITH_IMM,
  964. IBV_WR_SEND,
  965. IBV_WR_SEND_WITH_IMM,
  966. IBV_WR_RDMA_READ,
  967. IBV_WR_ATOMIC_CMP_AND_SWP,
  968. IBV_WR_ATOMIC_FETCH_AND_ADD,
  969. IBV_WR_LOCAL_INV,
  970. IBV_WR_BIND_MW,
  971. IBV_WR_SEND_WITH_INV,
  972. IBV_WR_TSO,
  973. IBV_WR_DRIVER1,
  974. };
  975. enum ibv_send_flags {
  976. IBV_SEND_FENCE = 1 << 0,
  977. IBV_SEND_SIGNALED = 1 << 1,
  978. IBV_SEND_SOLICITED = 1 << 2,
  979. IBV_SEND_INLINE = 1 << 3,
  980. IBV_SEND_IP_CSUM = 1 << 4
  981. };
  982. struct ibv_data_buf {
  983. void *addr;
  984. size_t length;
  985. };
  986. struct ibv_sge {
  987. uint64_t addr;
  988. uint32_t length;
  989. uint32_t lkey;
  990. };
  991. struct ibv_send_wr {
  992. uint64_t wr_id;
  993. struct ibv_send_wr *next;
  994. struct ibv_sge *sg_list;
  995. int num_sge;
  996. enum ibv_wr_opcode opcode;
  997. unsigned int send_flags;
  998. /* When opcode is *_WITH_IMM: Immediate data in network byte order.
  999. * When opcode is *_INV: Stores the rkey to invalidate
  1000. */
  1001. union {
  1002. __be32 imm_data;
  1003. uint32_t invalidate_rkey;
  1004. };
  1005. union {
  1006. struct {
  1007. uint64_t remote_addr;
  1008. uint32_t rkey;
  1009. } rdma;
  1010. struct {
  1011. uint64_t remote_addr;
  1012. uint64_t compare_add;
  1013. uint64_t swap;
  1014. uint32_t rkey;
  1015. } atomic;
  1016. struct {
  1017. struct ibv_ah *ah;
  1018. uint32_t remote_qpn;
  1019. uint32_t remote_qkey;
  1020. } ud;
  1021. } wr;
  1022. union {
  1023. struct {
  1024. uint32_t remote_srqn;
  1025. } xrc;
  1026. } qp_type;
  1027. union {
  1028. struct {
  1029. struct ibv_mw *mw;
  1030. uint32_t rkey;
  1031. struct ibv_mw_bind_info bind_info;
  1032. } bind_mw;
  1033. struct {
  1034. void *hdr;
  1035. uint16_t hdr_sz;
  1036. uint16_t mss;
  1037. } tso;
  1038. };
  1039. };
  1040. struct ibv_recv_wr {
  1041. uint64_t wr_id;
  1042. struct ibv_recv_wr *next;
  1043. struct ibv_sge *sg_list;
  1044. int num_sge;
  1045. };
  1046. enum ibv_ops_wr_opcode {
  1047. IBV_WR_TAG_ADD,
  1048. IBV_WR_TAG_DEL,
  1049. IBV_WR_TAG_SYNC,
  1050. };
  1051. enum ibv_ops_flags {
  1052. IBV_OPS_SIGNALED = 1 << 0,
  1053. IBV_OPS_TM_SYNC = 1 << 1,
  1054. };
  1055. struct ibv_ops_wr {
  1056. uint64_t wr_id;
  1057. struct ibv_ops_wr *next;
  1058. enum ibv_ops_wr_opcode opcode;
  1059. int flags;
  1060. struct {
  1061. uint32_t unexpected_cnt;
  1062. uint32_t handle;
  1063. struct {
  1064. uint64_t recv_wr_id;
  1065. struct ibv_sge *sg_list;
  1066. int num_sge;
  1067. uint64_t tag;
  1068. uint64_t mask;
  1069. } add;
  1070. } tm;
  1071. };
  1072. struct ibv_mw_bind {
  1073. uint64_t wr_id;
  1074. unsigned int send_flags;
  1075. struct ibv_mw_bind_info bind_info;
  1076. };
  1077. struct ibv_srq {
  1078. struct ibv_context *context;
  1079. void *srq_context;
  1080. struct ibv_pd *pd;
  1081. uint32_t handle;
  1082. pthread_mutex_t mutex;
  1083. pthread_cond_t cond;
  1084. uint32_t events_completed;
  1085. };
  1086. /*
  1087. * Work Queue. QP can be created without internal WQs "packaged" inside it,
  1088. * this QP can be configured to use "external" WQ object as its
  1089. * receive/send queue.
  1090. * WQ associated (many to one) with Completion Queue it owns WQ properties
  1091. * (PD, WQ size etc).
  1092. * WQ of type IBV_WQT_RQ:
  1093. * - Contains receive WQEs, in this case its PD serves as scatter as well.
  1094. * - Exposes post receive function to be used to post a list of work
  1095. * requests (WRs) to its receive queue.
  1096. */
  1097. struct ibv_wq {
  1098. struct ibv_context *context;
  1099. void *wq_context;
  1100. struct ibv_pd *pd;
  1101. struct ibv_cq *cq;
  1102. uint32_t wq_num;
  1103. uint32_t handle;
  1104. enum ibv_wq_state state;
  1105. enum ibv_wq_type wq_type;
  1106. int (*post_recv)(struct ibv_wq *current,
  1107. struct ibv_recv_wr *recv_wr,
  1108. struct ibv_recv_wr **bad_recv_wr);
  1109. pthread_mutex_t mutex;
  1110. pthread_cond_t cond;
  1111. uint32_t events_completed;
  1112. uint32_t comp_mask;
  1113. };
  1114. struct ibv_qp {
  1115. struct ibv_context *context;
  1116. void *qp_context;
  1117. struct ibv_pd *pd;
  1118. struct ibv_cq *send_cq;
  1119. struct ibv_cq *recv_cq;
  1120. struct ibv_srq *srq;
  1121. uint32_t handle;
  1122. uint32_t qp_num;
  1123. enum ibv_qp_state state;
  1124. enum ibv_qp_type qp_type;
  1125. pthread_mutex_t mutex;
  1126. pthread_cond_t cond;
  1127. uint32_t events_completed;
  1128. };
  1129. struct ibv_qp_ex {
  1130. struct ibv_qp qp_base;
  1131. uint64_t comp_mask;
  1132. uint64_t wr_id;
  1133. /* bitmask from enum ibv_send_flags */
  1134. unsigned int wr_flags;
  1135. void (*wr_atomic_cmp_swp)(struct ibv_qp_ex *qp, uint32_t rkey,
  1136. uint64_t remote_addr, uint64_t compare,
  1137. uint64_t swap);
  1138. void (*wr_atomic_fetch_add)(struct ibv_qp_ex *qp, uint32_t rkey,
  1139. uint64_t remote_addr, uint64_t add);
  1140. void (*wr_bind_mw)(struct ibv_qp_ex *qp, struct ibv_mw *mw,
  1141. uint32_t rkey,
  1142. const struct ibv_mw_bind_info *bind_info);
  1143. void (*wr_local_inv)(struct ibv_qp_ex *qp, uint32_t invalidate_rkey);
  1144. void (*wr_rdma_read)(struct ibv_qp_ex *qp, uint32_t rkey,
  1145. uint64_t remote_addr);
  1146. void (*wr_rdma_write)(struct ibv_qp_ex *qp, uint32_t rkey,
  1147. uint64_t remote_addr);
  1148. void (*wr_rdma_write_imm)(struct ibv_qp_ex *qp, uint32_t rkey,
  1149. uint64_t remote_addr, __be32 imm_data);
  1150. void (*wr_send)(struct ibv_qp_ex *qp);
  1151. void (*wr_send_imm)(struct ibv_qp_ex *qp, __be32 imm_data);
  1152. void (*wr_send_inv)(struct ibv_qp_ex *qp, uint32_t invalidate_rkey);
  1153. void (*wr_send_tso)(struct ibv_qp_ex *qp, void *hdr, uint16_t hdr_sz,
  1154. uint16_t mss);
  1155. void (*wr_set_ud_addr)(struct ibv_qp_ex *qp, struct ibv_ah *ah,
  1156. uint32_t remote_qpn, uint32_t remote_qkey);
  1157. void (*wr_set_xrc_srqn)(struct ibv_qp_ex *qp, uint32_t remote_srqn);
  1158. void (*wr_set_inline_data)(struct ibv_qp_ex *qp, void *addr,
  1159. size_t length);
  1160. void (*wr_set_inline_data_list)(struct ibv_qp_ex *qp, size_t num_buf,
  1161. const struct ibv_data_buf *buf_list);
  1162. void (*wr_set_sge)(struct ibv_qp_ex *qp, uint32_t lkey, uint64_t addr,
  1163. uint32_t length);
  1164. void (*wr_set_sge_list)(struct ibv_qp_ex *qp, size_t num_sge,
  1165. const struct ibv_sge *sg_list);
  1166. void (*wr_start)(struct ibv_qp_ex *qp);
  1167. int (*wr_complete)(struct ibv_qp_ex *qp);
  1168. void (*wr_abort)(struct ibv_qp_ex *qp);
  1169. };
  1170. struct ibv_qp_ex *ibv_qp_to_qp_ex(struct ibv_qp *qp);
  1171. static inline void ibv_wr_atomic_cmp_swp(struct ibv_qp_ex *qp, uint32_t rkey,
  1172. uint64_t remote_addr, uint64_t compare,
  1173. uint64_t swap)
  1174. {
  1175. qp->wr_atomic_cmp_swp(qp, rkey, remote_addr, compare, swap);
  1176. }
  1177. static inline void ibv_wr_atomic_fetch_add(struct ibv_qp_ex *qp, uint32_t rkey,
  1178. uint64_t remote_addr, uint64_t add)
  1179. {
  1180. qp->wr_atomic_fetch_add(qp, rkey, remote_addr, add);
  1181. }
  1182. static inline void ibv_wr_bind_mw(struct ibv_qp_ex *qp, struct ibv_mw *mw,
  1183. uint32_t rkey,
  1184. const struct ibv_mw_bind_info *bind_info)
  1185. {
  1186. qp->wr_bind_mw(qp, mw, rkey, bind_info);
  1187. }
  1188. static inline void ibv_wr_local_inv(struct ibv_qp_ex *qp,
  1189. uint32_t invalidate_rkey)
  1190. {
  1191. qp->wr_local_inv(qp, invalidate_rkey);
  1192. }
  1193. static inline void ibv_wr_rdma_read(struct ibv_qp_ex *qp, uint32_t rkey,
  1194. uint64_t remote_addr)
  1195. {
  1196. qp->wr_rdma_read(qp, rkey, remote_addr);
  1197. }
  1198. static inline void ibv_wr_rdma_write(struct ibv_qp_ex *qp, uint32_t rkey,
  1199. uint64_t remote_addr)
  1200. {
  1201. qp->wr_rdma_write(qp, rkey, remote_addr);
  1202. }
  1203. static inline void ibv_wr_rdma_write_imm(struct ibv_qp_ex *qp, uint32_t rkey,
  1204. uint64_t remote_addr, __be32 imm_data)
  1205. {
  1206. qp->wr_rdma_write_imm(qp, rkey, remote_addr, imm_data);
  1207. }
  1208. static inline void ibv_wr_send(struct ibv_qp_ex *qp)
  1209. {
  1210. qp->wr_send(qp);
  1211. }
  1212. static inline void ibv_wr_send_imm(struct ibv_qp_ex *qp, __be32 imm_data)
  1213. {
  1214. qp->wr_send_imm(qp, imm_data);
  1215. }
  1216. static inline void ibv_wr_send_inv(struct ibv_qp_ex *qp,
  1217. uint32_t invalidate_rkey)
  1218. {
  1219. qp->wr_send_inv(qp, invalidate_rkey);
  1220. }
  1221. static inline void ibv_wr_send_tso(struct ibv_qp_ex *qp, void *hdr,
  1222. uint16_t hdr_sz, uint16_t mss)
  1223. {
  1224. qp->wr_send_tso(qp, hdr, hdr_sz, mss);
  1225. }
  1226. static inline void ibv_wr_set_ud_addr(struct ibv_qp_ex *qp, struct ibv_ah *ah,
  1227. uint32_t remote_qpn, uint32_t remote_qkey)
  1228. {
  1229. qp->wr_set_ud_addr(qp, ah, remote_qpn, remote_qkey);
  1230. }
  1231. static inline void ibv_wr_set_xrc_srqn(struct ibv_qp_ex *qp,
  1232. uint32_t remote_srqn)
  1233. {
  1234. qp->wr_set_xrc_srqn(qp, remote_srqn);
  1235. }
  1236. static inline void ibv_wr_set_inline_data(struct ibv_qp_ex *qp, void *addr,
  1237. size_t length)
  1238. {
  1239. qp->wr_set_inline_data(qp, addr, length);
  1240. }
  1241. static inline void ibv_wr_set_inline_data_list(struct ibv_qp_ex *qp,
  1242. size_t num_buf,
  1243. const struct ibv_data_buf *buf_list)
  1244. {
  1245. qp->wr_set_inline_data_list(qp, num_buf, buf_list);
  1246. }
  1247. static inline void ibv_wr_set_sge(struct ibv_qp_ex *qp, uint32_t lkey,
  1248. uint64_t addr, uint32_t length)
  1249. {
  1250. qp->wr_set_sge(qp, lkey, addr, length);
  1251. }
  1252. static inline void ibv_wr_set_sge_list(struct ibv_qp_ex *qp, size_t num_sge,
  1253. const struct ibv_sge *sg_list)
  1254. {
  1255. qp->wr_set_sge_list(qp, num_sge, sg_list);
  1256. }
  1257. static inline void ibv_wr_start(struct ibv_qp_ex *qp)
  1258. {
  1259. qp->wr_start(qp);
  1260. }
  1261. static inline int ibv_wr_complete(struct ibv_qp_ex *qp)
  1262. {
  1263. return qp->wr_complete(qp);
  1264. }
  1265. static inline void ibv_wr_abort(struct ibv_qp_ex *qp)
  1266. {
  1267. qp->wr_abort(qp);
  1268. }
  1269. struct ibv_ece {
  1270. /*
  1271. * Unique identifier of the provider vendor on the network.
  1272. * The providers will set IEEE OUI here to distinguish
  1273. * itself in non-homogenius network.
  1274. */
  1275. uint32_t vendor_id;
  1276. /*
  1277. * Provider specific attributes which are supported or
  1278. * needed to be enabled by ECE users.
  1279. */
  1280. uint32_t options;
  1281. uint32_t comp_mask;
  1282. };
  1283. struct ibv_comp_channel {
  1284. struct ibv_context *context;
  1285. int fd;
  1286. int refcnt;
  1287. };
  1288. struct ibv_cq {
  1289. struct ibv_context *context;
  1290. struct ibv_comp_channel *channel;
  1291. void *cq_context;
  1292. uint32_t handle;
  1293. int cqe;
  1294. pthread_mutex_t mutex;
  1295. pthread_cond_t cond;
  1296. uint32_t comp_events_completed;
  1297. uint32_t async_events_completed;
  1298. };
  1299. struct ibv_poll_cq_attr {
  1300. uint32_t comp_mask;
  1301. };
  1302. struct ibv_wc_tm_info {
  1303. uint64_t tag; /* tag from TMH */
  1304. uint32_t priv; /* opaque user data from TMH */
  1305. };
  1306. struct ibv_cq_ex {
  1307. struct ibv_context *context;
  1308. struct ibv_comp_channel *channel;
  1309. void *cq_context;
  1310. uint32_t handle;
  1311. int cqe;
  1312. pthread_mutex_t mutex;
  1313. pthread_cond_t cond;
  1314. uint32_t comp_events_completed;
  1315. uint32_t async_events_completed;
  1316. uint32_t comp_mask;
  1317. enum ibv_wc_status status;
  1318. uint64_t wr_id;
  1319. int (*start_poll)(struct ibv_cq_ex *current,
  1320. struct ibv_poll_cq_attr *attr);
  1321. int (*next_poll)(struct ibv_cq_ex *current);
  1322. void (*end_poll)(struct ibv_cq_ex *current);
  1323. enum ibv_wc_opcode (*read_opcode)(struct ibv_cq_ex *current);
  1324. uint32_t (*read_vendor_err)(struct ibv_cq_ex *current);
  1325. uint32_t (*read_byte_len)(struct ibv_cq_ex *current);
  1326. __be32 (*read_imm_data)(struct ibv_cq_ex *current);
  1327. uint32_t (*read_qp_num)(struct ibv_cq_ex *current);
  1328. uint32_t (*read_src_qp)(struct ibv_cq_ex *current);
  1329. unsigned int (*read_wc_flags)(struct ibv_cq_ex *current);
  1330. uint32_t (*read_slid)(struct ibv_cq_ex *current);
  1331. uint8_t (*read_sl)(struct ibv_cq_ex *current);
  1332. uint8_t (*read_dlid_path_bits)(struct ibv_cq_ex *current);
  1333. uint64_t (*read_completion_ts)(struct ibv_cq_ex *current);
  1334. uint16_t (*read_cvlan)(struct ibv_cq_ex *current);
  1335. uint32_t (*read_flow_tag)(struct ibv_cq_ex *current);
  1336. void (*read_tm_info)(struct ibv_cq_ex *current,
  1337. struct ibv_wc_tm_info *tm_info);
  1338. uint64_t (*read_completion_wallclock_ns)(struct ibv_cq_ex *current);
  1339. };
  1340. static inline struct ibv_cq *ibv_cq_ex_to_cq(struct ibv_cq_ex *cq)
  1341. {
  1342. return (struct ibv_cq *)cq;
  1343. }
  1344. enum ibv_cq_attr_mask {
  1345. IBV_CQ_ATTR_MODERATE = 1 << 0,
  1346. IBV_CQ_ATTR_RESERVED = 1 << 1,
  1347. };
  1348. struct ibv_moderate_cq {
  1349. uint16_t cq_count;
  1350. uint16_t cq_period; /* in micro seconds */
  1351. };
  1352. struct ibv_modify_cq_attr {
  1353. uint32_t attr_mask;
  1354. struct ibv_moderate_cq moderate;
  1355. };
  1356. static inline int ibv_start_poll(struct ibv_cq_ex *cq,
  1357. struct ibv_poll_cq_attr *attr)
  1358. {
  1359. return cq->start_poll(cq, attr);
  1360. }
  1361. static inline int ibv_next_poll(struct ibv_cq_ex *cq)
  1362. {
  1363. return cq->next_poll(cq);
  1364. }
  1365. static inline void ibv_end_poll(struct ibv_cq_ex *cq)
  1366. {
  1367. cq->end_poll(cq);
  1368. }
  1369. static inline enum ibv_wc_opcode ibv_wc_read_opcode(struct ibv_cq_ex *cq)
  1370. {
  1371. return cq->read_opcode(cq);
  1372. }
  1373. static inline uint32_t ibv_wc_read_vendor_err(struct ibv_cq_ex *cq)
  1374. {
  1375. return cq->read_vendor_err(cq);
  1376. }
  1377. static inline uint32_t ibv_wc_read_byte_len(struct ibv_cq_ex *cq)
  1378. {
  1379. return cq->read_byte_len(cq);
  1380. }
  1381. static inline __be32 ibv_wc_read_imm_data(struct ibv_cq_ex *cq)
  1382. {
  1383. return cq->read_imm_data(cq);
  1384. }
  1385. static inline uint32_t ibv_wc_read_invalidated_rkey(struct ibv_cq_ex *cq)
  1386. {
  1387. #ifdef __CHECKER__
  1388. return (__attribute__((force)) uint32_t)cq->read_imm_data(cq);
  1389. #else
  1390. return cq->read_imm_data(cq);
  1391. #endif
  1392. }
  1393. static inline uint32_t ibv_wc_read_qp_num(struct ibv_cq_ex *cq)
  1394. {
  1395. return cq->read_qp_num(cq);
  1396. }
  1397. static inline uint32_t ibv_wc_read_src_qp(struct ibv_cq_ex *cq)
  1398. {
  1399. return cq->read_src_qp(cq);
  1400. }
  1401. static inline unsigned int ibv_wc_read_wc_flags(struct ibv_cq_ex *cq)
  1402. {
  1403. return cq->read_wc_flags(cq);
  1404. }
  1405. static inline uint32_t ibv_wc_read_slid(struct ibv_cq_ex *cq)
  1406. {
  1407. return cq->read_slid(cq);
  1408. }
  1409. static inline uint8_t ibv_wc_read_sl(struct ibv_cq_ex *cq)
  1410. {
  1411. return cq->read_sl(cq);
  1412. }
  1413. static inline uint8_t ibv_wc_read_dlid_path_bits(struct ibv_cq_ex *cq)
  1414. {
  1415. return cq->read_dlid_path_bits(cq);
  1416. }
  1417. static inline uint64_t ibv_wc_read_completion_ts(struct ibv_cq_ex *cq)
  1418. {
  1419. return cq->read_completion_ts(cq);
  1420. }
  1421. static inline uint64_t ibv_wc_read_completion_wallclock_ns(struct ibv_cq_ex *cq)
  1422. {
  1423. return cq->read_completion_wallclock_ns(cq);
  1424. }
  1425. static inline uint16_t ibv_wc_read_cvlan(struct ibv_cq_ex *cq)
  1426. {
  1427. return cq->read_cvlan(cq);
  1428. }
  1429. static inline uint32_t ibv_wc_read_flow_tag(struct ibv_cq_ex *cq)
  1430. {
  1431. return cq->read_flow_tag(cq);
  1432. }
  1433. static inline void ibv_wc_read_tm_info(struct ibv_cq_ex *cq,
  1434. struct ibv_wc_tm_info *tm_info)
  1435. {
  1436. cq->read_tm_info(cq, tm_info);
  1437. }
  1438. static inline int ibv_post_wq_recv(struct ibv_wq *wq,
  1439. struct ibv_recv_wr *recv_wr,
  1440. struct ibv_recv_wr **bad_recv_wr)
  1441. {
  1442. return wq->post_recv(wq, recv_wr, bad_recv_wr);
  1443. }
  1444. struct ibv_ah {
  1445. struct ibv_context *context;
  1446. struct ibv_pd *pd;
  1447. uint32_t handle;
  1448. };
  1449. enum ibv_flow_flags {
  1450. /* First bit is deprecated and can't be used */
  1451. IBV_FLOW_ATTR_FLAGS_DONT_TRAP = 1 << 1,
  1452. IBV_FLOW_ATTR_FLAGS_EGRESS = 1 << 2,
  1453. };
  1454. enum ibv_flow_attr_type {
  1455. /* steering according to rule specifications */
  1456. IBV_FLOW_ATTR_NORMAL = 0x0,
  1457. /* default unicast and multicast rule -
  1458. * receive all Eth traffic which isn't steered to any QP
  1459. */
  1460. IBV_FLOW_ATTR_ALL_DEFAULT = 0x1,
  1461. /* default multicast rule -
  1462. * receive all Eth multicast traffic which isn't steered to any QP
  1463. */
  1464. IBV_FLOW_ATTR_MC_DEFAULT = 0x2,
  1465. /* sniffer rule - receive all port traffic */
  1466. IBV_FLOW_ATTR_SNIFFER = 0x3,
  1467. };
  1468. enum ibv_flow_spec_type {
  1469. IBV_FLOW_SPEC_ETH = 0x20,
  1470. IBV_FLOW_SPEC_IPV4 = 0x30,
  1471. IBV_FLOW_SPEC_IPV6 = 0x31,
  1472. IBV_FLOW_SPEC_IPV4_EXT = 0x32,
  1473. IBV_FLOW_SPEC_ESP = 0x34,
  1474. IBV_FLOW_SPEC_TCP = 0x40,
  1475. IBV_FLOW_SPEC_UDP = 0x41,
  1476. IBV_FLOW_SPEC_VXLAN_TUNNEL = 0x50,
  1477. IBV_FLOW_SPEC_GRE = 0x51,
  1478. IBV_FLOW_SPEC_MPLS = 0x60,
  1479. IBV_FLOW_SPEC_INNER = 0x100,
  1480. IBV_FLOW_SPEC_ACTION_TAG = 0x1000,
  1481. IBV_FLOW_SPEC_ACTION_DROP = 0x1001,
  1482. IBV_FLOW_SPEC_ACTION_HANDLE = 0x1002,
  1483. IBV_FLOW_SPEC_ACTION_COUNT = 0x1003,
  1484. };
  1485. struct ibv_flow_eth_filter {
  1486. uint8_t dst_mac[6];
  1487. uint8_t src_mac[6];
  1488. uint16_t ether_type;
  1489. /*
  1490. * same layout as 802.1q: prio 3, cfi 1, vlan id 12
  1491. */
  1492. uint16_t vlan_tag;
  1493. };
  1494. struct ibv_flow_spec_eth {
  1495. enum ibv_flow_spec_type type;
  1496. uint16_t size;
  1497. struct ibv_flow_eth_filter val;
  1498. struct ibv_flow_eth_filter mask;
  1499. };
  1500. struct ibv_flow_ipv4_filter {
  1501. uint32_t src_ip;
  1502. uint32_t dst_ip;
  1503. };
  1504. struct ibv_flow_spec_ipv4 {
  1505. enum ibv_flow_spec_type type;
  1506. uint16_t size;
  1507. struct ibv_flow_ipv4_filter val;
  1508. struct ibv_flow_ipv4_filter mask;
  1509. };
  1510. struct ibv_flow_ipv4_ext_filter {
  1511. uint32_t src_ip;
  1512. uint32_t dst_ip;
  1513. uint8_t proto;
  1514. uint8_t tos;
  1515. uint8_t ttl;
  1516. uint8_t flags;
  1517. };
  1518. struct ibv_flow_spec_ipv4_ext {
  1519. enum ibv_flow_spec_type type;
  1520. uint16_t size;
  1521. struct ibv_flow_ipv4_ext_filter val;
  1522. struct ibv_flow_ipv4_ext_filter mask;
  1523. };
  1524. struct ibv_flow_ipv6_filter {
  1525. uint8_t src_ip[16];
  1526. uint8_t dst_ip[16];
  1527. uint32_t flow_label;
  1528. uint8_t next_hdr;
  1529. uint8_t traffic_class;
  1530. uint8_t hop_limit;
  1531. };
  1532. struct ibv_flow_spec_ipv6 {
  1533. enum ibv_flow_spec_type type;
  1534. uint16_t size;
  1535. struct ibv_flow_ipv6_filter val;
  1536. struct ibv_flow_ipv6_filter mask;
  1537. };
  1538. struct ibv_flow_esp_filter {
  1539. uint32_t spi;
  1540. uint32_t seq;
  1541. };
  1542. struct ibv_flow_spec_esp {
  1543. enum ibv_flow_spec_type type;
  1544. uint16_t size;
  1545. struct ibv_flow_esp_filter val;
  1546. struct ibv_flow_esp_filter mask;
  1547. };
  1548. struct ibv_flow_tcp_udp_filter {
  1549. uint16_t dst_port;
  1550. uint16_t src_port;
  1551. };
  1552. struct ibv_flow_spec_tcp_udp {
  1553. enum ibv_flow_spec_type type;
  1554. uint16_t size;
  1555. struct ibv_flow_tcp_udp_filter val;
  1556. struct ibv_flow_tcp_udp_filter mask;
  1557. };
  1558. struct ibv_flow_gre_filter {
  1559. /* c_ks_res0_ver field is bits 0-15 in offset 0 of a standard GRE header:
  1560. * bit 0 - checksum present bit.
  1561. * bit 1 - reserved. set to 0.
  1562. * bit 2 - key present bit.
  1563. * bit 3 - sequence number present bit.
  1564. * bits 4:12 - reserved. set to 0.
  1565. * bits 13:15 - GRE version.
  1566. */
  1567. uint16_t c_ks_res0_ver;
  1568. uint16_t protocol;
  1569. uint32_t key;
  1570. };
  1571. struct ibv_flow_spec_gre {
  1572. enum ibv_flow_spec_type type;
  1573. uint16_t size;
  1574. struct ibv_flow_gre_filter val;
  1575. struct ibv_flow_gre_filter mask;
  1576. };
  1577. struct ibv_flow_mpls_filter {
  1578. /* The field includes the entire MPLS label:
  1579. * bits 0:19 - label value field.
  1580. * bits 20:22 - traffic class field.
  1581. * bits 23 - bottom of stack bit.
  1582. * bits 24:31 - ttl field.
  1583. */
  1584. uint32_t label;
  1585. };
  1586. struct ibv_flow_spec_mpls {
  1587. enum ibv_flow_spec_type type;
  1588. uint16_t size;
  1589. struct ibv_flow_mpls_filter val;
  1590. struct ibv_flow_mpls_filter mask;
  1591. };
  1592. struct ibv_flow_tunnel_filter {
  1593. uint32_t tunnel_id;
  1594. };
  1595. struct ibv_flow_spec_tunnel {
  1596. enum ibv_flow_spec_type type;
  1597. uint16_t size;
  1598. struct ibv_flow_tunnel_filter val;
  1599. struct ibv_flow_tunnel_filter mask;
  1600. };
  1601. struct ibv_flow_spec_action_tag {
  1602. enum ibv_flow_spec_type type;
  1603. uint16_t size;
  1604. uint32_t tag_id;
  1605. };
  1606. struct ibv_flow_spec_action_drop {
  1607. enum ibv_flow_spec_type type;
  1608. uint16_t size;
  1609. };
  1610. struct ibv_flow_spec_action_handle {
  1611. enum ibv_flow_spec_type type;
  1612. uint16_t size;
  1613. const struct ibv_flow_action *action;
  1614. };
  1615. struct ibv_flow_spec_counter_action {
  1616. enum ibv_flow_spec_type type;
  1617. uint16_t size;
  1618. struct ibv_counters *counters;
  1619. };
  1620. struct ibv_flow_spec {
  1621. union {
  1622. struct {
  1623. enum ibv_flow_spec_type type;
  1624. uint16_t size;
  1625. } hdr;
  1626. struct ibv_flow_spec_eth eth;
  1627. struct ibv_flow_spec_ipv4 ipv4;
  1628. struct ibv_flow_spec_tcp_udp tcp_udp;
  1629. struct ibv_flow_spec_ipv4_ext ipv4_ext;
  1630. struct ibv_flow_spec_ipv6 ipv6;
  1631. struct ibv_flow_spec_esp esp;
  1632. struct ibv_flow_spec_tunnel tunnel;
  1633. struct ibv_flow_spec_gre gre;
  1634. struct ibv_flow_spec_mpls mpls;
  1635. struct ibv_flow_spec_action_tag flow_tag;
  1636. struct ibv_flow_spec_action_drop drop;
  1637. struct ibv_flow_spec_action_handle handle;
  1638. struct ibv_flow_spec_counter_action flow_count;
  1639. };
  1640. };
  1641. struct ibv_flow_attr {
  1642. uint32_t comp_mask;
  1643. enum ibv_flow_attr_type type;
  1644. uint16_t size;
  1645. uint16_t priority;
  1646. uint8_t num_of_specs;
  1647. uint8_t port;
  1648. uint32_t flags;
  1649. /* Following are the optional layers according to user request
  1650. * struct ibv_flow_spec_xxx [L2]
  1651. * struct ibv_flow_spec_yyy [L3/L4]
  1652. */
  1653. };
  1654. struct ibv_flow {
  1655. uint32_t comp_mask;
  1656. struct ibv_context *context;
  1657. uint32_t handle;
  1658. };
  1659. struct ibv_flow_action {
  1660. struct ibv_context *context;
  1661. };
  1662. enum ibv_flow_action_esp_mask {
  1663. IBV_FLOW_ACTION_ESP_MASK_ESN = 1UL << 0,
  1664. };
  1665. struct ibv_flow_action_esp_attr {
  1666. struct ibv_flow_action_esp *esp_attr;
  1667. enum ibv_flow_action_esp_keymat keymat_proto;
  1668. uint16_t keymat_len;
  1669. void *keymat_ptr;
  1670. enum ibv_flow_action_esp_replay replay_proto;
  1671. uint16_t replay_len;
  1672. void *replay_ptr;
  1673. struct ibv_flow_action_esp_encap *esp_encap;
  1674. uint32_t comp_mask; /* Use enum ibv_flow_action_esp_mask */
  1675. uint32_t esn;
  1676. };
  1677. struct ibv_device;
  1678. struct ibv_context;
  1679. /* Obsolete, never used, do not touch */
  1680. struct _ibv_device_ops {
  1681. struct ibv_context * (*_dummy1)(struct ibv_device *device, int cmd_fd);
  1682. void (*_dummy2)(struct ibv_context *context);
  1683. };
  1684. enum {
  1685. IBV_SYSFS_NAME_MAX = 64,
  1686. IBV_SYSFS_PATH_MAX = 256
  1687. };
  1688. struct ibv_device {
  1689. struct _ibv_device_ops _ops;
  1690. enum ibv_node_type node_type;
  1691. enum ibv_transport_type transport_type;
  1692. /* Name of underlying kernel IB device, eg "mthca0" */
  1693. char name[IBV_SYSFS_NAME_MAX];
  1694. /* Name of uverbs device, eg "uverbs0" */
  1695. char dev_name[IBV_SYSFS_NAME_MAX];
  1696. /* Path to infiniband_verbs class device in sysfs */
  1697. char dev_path[IBV_SYSFS_PATH_MAX];
  1698. /* Path to infiniband class device in sysfs */
  1699. char ibdev_path[IBV_SYSFS_PATH_MAX];
  1700. };
  1701. struct _compat_ibv_port_attr;
  1702. struct ibv_context_ops {
  1703. void *(*_compat_query_device)(void);
  1704. int (*_compat_query_port)(struct ibv_context *context,
  1705. uint8_t port_num,
  1706. struct _compat_ibv_port_attr *port_attr);
  1707. void *(*_compat_alloc_pd)(void);
  1708. void *(*_compat_dealloc_pd)(void);
  1709. void *(*_compat_reg_mr)(void);
  1710. void *(*_compat_rereg_mr)(void);
  1711. void *(*_compat_dereg_mr)(void);
  1712. struct ibv_mw * (*alloc_mw)(struct ibv_pd *pd, enum ibv_mw_type type);
  1713. int (*bind_mw)(struct ibv_qp *qp, struct ibv_mw *mw,
  1714. struct ibv_mw_bind *mw_bind);
  1715. int (*dealloc_mw)(struct ibv_mw *mw);
  1716. void *(*_compat_create_cq)(void);
  1717. int (*poll_cq)(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc);
  1718. int (*req_notify_cq)(struct ibv_cq *cq, int solicited_only);
  1719. void *(*_compat_cq_event)(void);
  1720. void *(*_compat_resize_cq)(void);
  1721. void *(*_compat_destroy_cq)(void);
  1722. void *(*_compat_create_srq)(void);
  1723. void *(*_compat_modify_srq)(void);
  1724. void *(*_compat_query_srq)(void);
  1725. void *(*_compat_destroy_srq)(void);
  1726. int (*post_srq_recv)(struct ibv_srq *srq,
  1727. struct ibv_recv_wr *recv_wr,
  1728. struct ibv_recv_wr **bad_recv_wr);
  1729. void *(*_compat_create_qp)(void);
  1730. void *(*_compat_query_qp)(void);
  1731. void *(*_compat_modify_qp)(void);
  1732. void *(*_compat_destroy_qp)(void);
  1733. int (*post_send)(struct ibv_qp *qp, struct ibv_send_wr *wr,
  1734. struct ibv_send_wr **bad_wr);
  1735. int (*post_recv)(struct ibv_qp *qp, struct ibv_recv_wr *wr,
  1736. struct ibv_recv_wr **bad_wr);
  1737. void *(*_compat_create_ah)(void);
  1738. void *(*_compat_destroy_ah)(void);
  1739. void *(*_compat_attach_mcast)(void);
  1740. void *(*_compat_detach_mcast)(void);
  1741. void *(*_compat_async_event)(void);
  1742. };
  1743. struct ibv_context {
  1744. struct ibv_device *device;
  1745. struct ibv_context_ops ops;
  1746. int cmd_fd;
  1747. int async_fd;
  1748. int num_comp_vectors;
  1749. pthread_mutex_t mutex;
  1750. void *abi_compat;
  1751. };
  1752. enum ibv_cq_init_attr_mask {
  1753. IBV_CQ_INIT_ATTR_MASK_FLAGS = 1 << 0,
  1754. IBV_CQ_INIT_ATTR_MASK_PD = 1 << 1,
  1755. };
  1756. enum ibv_create_cq_attr_flags {
  1757. IBV_CREATE_CQ_ATTR_SINGLE_THREADED = 1 << 0,
  1758. IBV_CREATE_CQ_ATTR_IGNORE_OVERRUN = 1 << 1,
  1759. };
  1760. struct ibv_cq_init_attr_ex {
  1761. /* Minimum number of entries required for CQ */
  1762. uint32_t cqe;
  1763. /* Consumer-supplied context returned for completion events */
  1764. void *cq_context;
  1765. /* Completion channel where completion events will be queued.
  1766. * May be NULL if completion events will not be used.
  1767. */
  1768. struct ibv_comp_channel *channel;
  1769. /* Completion vector used to signal completion events.
  1770. * Must be < context->num_comp_vectors.
  1771. */
  1772. uint32_t comp_vector;
  1773. /* Or'ed bit of enum ibv_create_cq_wc_flags. */
  1774. uint64_t wc_flags;
  1775. /* compatibility mask (extended verb). Or'd flags of
  1776. * enum ibv_cq_init_attr_mask
  1777. */
  1778. uint32_t comp_mask;
  1779. /* create cq attr flags - one or more flags from
  1780. * enum ibv_create_cq_attr_flags
  1781. */
  1782. uint32_t flags;
  1783. struct ibv_pd *parent_domain;
  1784. };
  1785. enum ibv_parent_domain_init_attr_mask {
  1786. IBV_PARENT_DOMAIN_INIT_ATTR_ALLOCATORS = 1 << 0,
  1787. IBV_PARENT_DOMAIN_INIT_ATTR_PD_CONTEXT = 1 << 1,
  1788. };
  1789. #define IBV_ALLOCATOR_USE_DEFAULT ((void *)-1)
  1790. struct ibv_parent_domain_init_attr {
  1791. struct ibv_pd *pd; /* referance to a protection domain object, can't be NULL */
  1792. struct ibv_td *td; /* referance to a thread domain object, or NULL */
  1793. uint32_t comp_mask;
  1794. void *(*alloc)(struct ibv_pd *pd, void *pd_context, size_t size,
  1795. size_t alignment, uint64_t resource_type);
  1796. void (*free)(struct ibv_pd *pd, void *pd_context, void *ptr,
  1797. uint64_t resource_type);
  1798. void *pd_context;
  1799. };
  1800. struct ibv_counters_init_attr {
  1801. uint32_t comp_mask;
  1802. };
  1803. struct ibv_counters {
  1804. struct ibv_context *context;
  1805. };
  1806. enum ibv_counter_description {
  1807. IBV_COUNTER_PACKETS,
  1808. IBV_COUNTER_BYTES,
  1809. };
  1810. struct ibv_counter_attach_attr {
  1811. enum ibv_counter_description counter_desc;
  1812. uint32_t index; /* Desired location index of the counter at the counters object */
  1813. uint32_t comp_mask;
  1814. };
  1815. enum ibv_read_counters_flags {
  1816. IBV_READ_COUNTERS_ATTR_PREFER_CACHED = 1 << 0,
  1817. };
  1818. enum ibv_values_mask {
  1819. IBV_VALUES_MASK_RAW_CLOCK = 1 << 0,
  1820. IBV_VALUES_MASK_RESERVED = 1 << 1
  1821. };
  1822. struct ibv_values_ex {
  1823. uint32_t comp_mask;
  1824. struct timespec raw_clock;
  1825. };
  1826. struct verbs_context {
  1827. /* "grows up" - new fields go here */
  1828. int (*query_port)(struct ibv_context *context, uint8_t port_num,
  1829. struct ibv_port_attr *port_attr,
  1830. size_t port_attr_len);
  1831. int (*advise_mr)(struct ibv_pd *pd,
  1832. enum ibv_advise_mr_advice advice,
  1833. uint32_t flags,
  1834. struct ibv_sge *sg_list,
  1835. uint32_t num_sges);
  1836. struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
  1837. int (*read_counters)(struct ibv_counters *counters,
  1838. uint64_t *counters_value,
  1839. uint32_t ncounters,
  1840. uint32_t flags);
  1841. int (*attach_counters_point_flow)(struct ibv_counters *counters,
  1842. struct ibv_counter_attach_attr *attr,
  1843. struct ibv_flow *flow);
  1844. struct ibv_counters *(*create_counters)(struct ibv_context *context,
  1845. struct ibv_counters_init_attr *init_attr);
  1846. int (*destroy_counters)(struct ibv_counters *counters);
  1847. struct ibv_mr *(*reg_dm_mr)(struct ibv_pd *pd, struct ibv_dm *dm,
  1848. uint64_t dm_offset, size_t length,
  1849. unsigned int access);
  1850. struct ibv_dm *(*alloc_dm)(struct ibv_context *context,
  1851. struct ibv_alloc_dm_attr *attr);
  1852. int (*free_dm)(struct ibv_dm *dm);
  1853. int (*modify_flow_action_esp)(struct ibv_flow_action *action,
  1854. struct ibv_flow_action_esp_attr *attr);
  1855. int (*destroy_flow_action)(struct ibv_flow_action *action);
  1856. struct ibv_flow_action *(*create_flow_action_esp)(struct ibv_context *context,
  1857. struct ibv_flow_action_esp_attr *attr);
  1858. int (*modify_qp_rate_limit)(struct ibv_qp *qp,
  1859. struct ibv_qp_rate_limit_attr *attr);
  1860. struct ibv_pd *(*alloc_parent_domain)(struct ibv_context *context,
  1861. struct ibv_parent_domain_init_attr *attr);
  1862. int (*dealloc_td)(struct ibv_td *td);
  1863. struct ibv_td *(*alloc_td)(struct ibv_context *context, struct ibv_td_init_attr *init_attr);
  1864. int (*modify_cq)(struct ibv_cq *cq, struct ibv_modify_cq_attr *attr);
  1865. int (*post_srq_ops)(struct ibv_srq *srq,
  1866. struct ibv_ops_wr *op,
  1867. struct ibv_ops_wr **bad_op);
  1868. int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
  1869. struct ibv_rwq_ind_table *(*create_rwq_ind_table)(struct ibv_context *context,
  1870. struct ibv_rwq_ind_table_init_attr *init_attr);
  1871. int (*destroy_wq)(struct ibv_wq *wq);
  1872. int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
  1873. struct ibv_wq * (*create_wq)(struct ibv_context *context,
  1874. struct ibv_wq_init_attr *wq_init_attr);
  1875. int (*query_rt_values)(struct ibv_context *context,
  1876. struct ibv_values_ex *values);
  1877. struct ibv_cq_ex *(*create_cq_ex)(struct ibv_context *context,
  1878. struct ibv_cq_init_attr_ex *init_attr);
  1879. struct verbs_ex_private *priv;
  1880. int (*query_device_ex)(struct ibv_context *context,
  1881. const struct ibv_query_device_ex_input *input,
  1882. struct ibv_device_attr_ex *attr,
  1883. size_t attr_size);
  1884. int (*ibv_destroy_flow) (struct ibv_flow *flow);
  1885. void (*ABI_placeholder2) (void); /* DO NOT COPY THIS GARBAGE */
  1886. struct ibv_flow * (*ibv_create_flow) (struct ibv_qp *qp,
  1887. struct ibv_flow_attr *flow_attr);
  1888. void (*ABI_placeholder1) (void); /* DO NOT COPY THIS GARBAGE */
  1889. struct ibv_qp *(*open_qp)(struct ibv_context *context,
  1890. struct ibv_qp_open_attr *attr);
  1891. struct ibv_qp *(*create_qp_ex)(struct ibv_context *context,
  1892. struct ibv_qp_init_attr_ex *qp_init_attr_ex);
  1893. int (*get_srq_num)(struct ibv_srq *srq, uint32_t *srq_num);
  1894. struct ibv_srq * (*create_srq_ex)(struct ibv_context *context,
  1895. struct ibv_srq_init_attr_ex *srq_init_attr_ex);
  1896. struct ibv_xrcd * (*open_xrcd)(struct ibv_context *context,
  1897. struct ibv_xrcd_init_attr *xrcd_init_attr);
  1898. int (*close_xrcd)(struct ibv_xrcd *xrcd);
  1899. uint64_t _ABI_placeholder3;
  1900. size_t sz; /* Must be immediately before struct ibv_context */
  1901. struct ibv_context context; /* Must be last field in the struct */
  1902. };
  1903. static inline struct verbs_context *verbs_get_ctx(struct ibv_context *ctx)
  1904. {
  1905. if (ctx->abi_compat != __VERBS_ABI_IS_EXTENDED)
  1906. return NULL;
  1907. /* open code container_of to not pollute the global namespace */
  1908. return (struct verbs_context *)(((uint8_t *)ctx) -
  1909. offsetof(struct verbs_context,
  1910. context));
  1911. }
  1912. #define verbs_get_ctx_op(ctx, op) ({ \
  1913. struct verbs_context *__vctx = verbs_get_ctx(ctx); \
  1914. (!__vctx || (__vctx->sz < sizeof(*__vctx) - offsetof(struct verbs_context, op)) || \
  1915. !__vctx->op) ? NULL : __vctx; })
  1916. /**
  1917. * ibv_get_device_list - Get list of IB devices currently available
  1918. * @num_devices: optional. if non-NULL, set to the number of devices
  1919. * returned in the array.
  1920. *
  1921. * Return a NULL-terminated array of IB devices. The array can be
  1922. * released with ibv_free_device_list().
  1923. */
  1924. struct ibv_device **ibv_get_device_list(int *num_devices);
  1925. /*
  1926. * When statically linking the user can set RDMA_STATIC_PROVIDERS to a comma
  1927. * separated list of provider names to include in the static link, and this
  1928. * machinery will cause those providers to be included statically.
  1929. *
  1930. * Linking will fail if this is set for dynamic linking.
  1931. */
  1932. #ifdef RDMA_STATIC_PROVIDERS
  1933. #define _RDMA_STATIC_PREFIX_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, \
  1934. _12, _13, _14, _15, _16, _17, ...) \
  1935. &verbs_provider_##_1, &verbs_provider_##_2, &verbs_provider_##_3, \
  1936. &verbs_provider_##_4, &verbs_provider_##_5, \
  1937. &verbs_provider_##_6, &verbs_provider_##_7, \
  1938. &verbs_provider_##_8, &verbs_provider_##_9, \
  1939. &verbs_provider_##_10, &verbs_provider_##_11, \
  1940. &verbs_provider_##_12, &verbs_provider_##_13, \
  1941. &verbs_provider_##_14, &verbs_provider_##_15, \
  1942. &verbs_provider_##_16, &verbs_provider_##_17
  1943. #define _RDMA_STATIC_PREFIX(arg) \
  1944. _RDMA_STATIC_PREFIX_(arg, none, none, none, none, none, none, none, \
  1945. none, none, none, none, none, none, none, none, \
  1946. none)
  1947. struct verbs_devices_ops;
  1948. extern const struct verbs_device_ops verbs_provider_bnxt_re;
  1949. extern const struct verbs_device_ops verbs_provider_cxgb4;
  1950. extern const struct verbs_device_ops verbs_provider_efa;
  1951. extern const struct verbs_device_ops verbs_provider_hfi1verbs;
  1952. extern const struct verbs_device_ops verbs_provider_hns;
  1953. extern const struct verbs_device_ops verbs_provider_i40iw;
  1954. extern const struct verbs_device_ops verbs_provider_ipathverbs;
  1955. extern const struct verbs_device_ops verbs_provider_mlx4;
  1956. extern const struct verbs_device_ops verbs_provider_mlx5;
  1957. extern const struct verbs_device_ops verbs_provider_mthca;
  1958. extern const struct verbs_device_ops verbs_provider_ocrdma;
  1959. extern const struct verbs_device_ops verbs_provider_qedr;
  1960. extern const struct verbs_device_ops verbs_provider_rxe;
  1961. extern const struct verbs_device_ops verbs_provider_siw;
  1962. extern const struct verbs_device_ops verbs_provider_vmw_pvrdma;
  1963. extern const struct verbs_device_ops verbs_provider_all;
  1964. extern const struct verbs_device_ops verbs_provider_none;
  1965. void ibv_static_providers(void *unused, ...);
  1966. static inline struct ibv_device **__ibv_get_device_list(int *num_devices)
  1967. {
  1968. ibv_static_providers(NULL, _RDMA_STATIC_PREFIX(RDMA_STATIC_PROVIDERS),
  1969. NULL);
  1970. return ibv_get_device_list(num_devices);
  1971. }
  1972. #define ibv_get_device_list(num_devices) __ibv_get_device_list(num_devices)
  1973. #endif
  1974. /**
  1975. * ibv_free_device_list - Free list from ibv_get_device_list()
  1976. *
  1977. * Free an array of devices returned from ibv_get_device_list(). Once
  1978. * the array is freed, pointers to devices that were not opened with
  1979. * ibv_open_device() are no longer valid. Client code must open all
  1980. * devices it intends to use before calling ibv_free_device_list().
  1981. */
  1982. void ibv_free_device_list(struct ibv_device **list);
  1983. /**
  1984. * ibv_get_device_name - Return kernel device name
  1985. */
  1986. const char *ibv_get_device_name(struct ibv_device *device);
  1987. /**
  1988. * ibv_get_device_index - Return kernel device index
  1989. *
  1990. * Available for the kernel with support of IB device query
  1991. * over netlink interface. For the unsupported kernels, the
  1992. * relevant -1 will be returned.
  1993. */
  1994. int ibv_get_device_index(struct ibv_device *device);
  1995. /**
  1996. * ibv_get_device_guid - Return device's node GUID
  1997. */
  1998. __be64 ibv_get_device_guid(struct ibv_device *device);
  1999. /**
  2000. * ibv_open_device - Initialize device for use
  2001. */
  2002. struct ibv_context *ibv_open_device(struct ibv_device *device);
  2003. /**
  2004. * ibv_close_device - Release device
  2005. */
  2006. int ibv_close_device(struct ibv_context *context);
  2007. /**
  2008. * ibv_import_device - Import device
  2009. */
  2010. struct ibv_context *ibv_import_device(int cmd_fd);
  2011. /**
  2012. * ibv_import_pd - Import a protetion domain
  2013. */
  2014. struct ibv_pd *ibv_import_pd(struct ibv_context *context,
  2015. uint32_t pd_handle);
  2016. /**
  2017. * ibv_unimport_pd - Unimport a protetion domain
  2018. */
  2019. void ibv_unimport_pd(struct ibv_pd *pd);
  2020. /**
  2021. * ibv_import_mr - Import a memory region
  2022. */
  2023. struct ibv_mr *ibv_import_mr(struct ibv_pd *pd, uint32_t mr_handle);
  2024. /**
  2025. * ibv_unimport_mr - Unimport a memory region
  2026. */
  2027. void ibv_unimport_mr(struct ibv_mr *mr);
  2028. /**
  2029. * ibv_get_async_event - Get next async event
  2030. * @event: Pointer to use to return async event
  2031. *
  2032. * All async events returned by ibv_get_async_event() must eventually
  2033. * be acknowledged with ibv_ack_async_event().
  2034. */
  2035. int ibv_get_async_event(struct ibv_context *context,
  2036. struct ibv_async_event *event);
  2037. /**
  2038. * ibv_ack_async_event - Acknowledge an async event
  2039. * @event: Event to be acknowledged.
  2040. *
  2041. * All async events which are returned by ibv_get_async_event() must
  2042. * be acknowledged. To avoid races, destroying an object (CQ, SRQ or
  2043. * QP) will wait for all affiliated events to be acknowledged, so
  2044. * there should be a one-to-one correspondence between acks and
  2045. * successful gets.
  2046. */
  2047. void ibv_ack_async_event(struct ibv_async_event *event);
  2048. /**
  2049. * ibv_query_device - Get device properties
  2050. */
  2051. int ibv_query_device(struct ibv_context *context,
  2052. struct ibv_device_attr *device_attr);
  2053. /**
  2054. * ibv_query_port - Get port properties
  2055. */
  2056. int ibv_query_port(struct ibv_context *context, uint8_t port_num,
  2057. struct _compat_ibv_port_attr *port_attr);
  2058. static inline int ___ibv_query_port(struct ibv_context *context,
  2059. uint8_t port_num,
  2060. struct ibv_port_attr *port_attr)
  2061. {
  2062. struct verbs_context *vctx = verbs_get_ctx_op(context, query_port);
  2063. if (!vctx) {
  2064. int rc;
  2065. memset(port_attr, 0, sizeof(*port_attr));
  2066. rc = ibv_query_port(context, port_num,
  2067. (struct _compat_ibv_port_attr *)port_attr);
  2068. return rc;
  2069. }
  2070. return vctx->query_port(context, port_num, port_attr,
  2071. sizeof(*port_attr));
  2072. }
  2073. #define ibv_query_port(context, port_num, port_attr) \
  2074. ___ibv_query_port(context, port_num, port_attr)
  2075. /**
  2076. * ibv_query_gid - Get a GID table entry
  2077. */
  2078. int ibv_query_gid(struct ibv_context *context, uint8_t port_num,
  2079. int index, union ibv_gid *gid);
  2080. int _ibv_query_gid_ex(struct ibv_context *context, uint32_t port_num,
  2081. uint32_t gid_index, struct ibv_gid_entry *entry,
  2082. uint32_t flags, size_t entry_size);
  2083. /**
  2084. * ibv_query_gid_ex - Read a GID table entry
  2085. */
  2086. static inline int ibv_query_gid_ex(struct ibv_context *context,
  2087. uint32_t port_num, uint32_t gid_index,
  2088. struct ibv_gid_entry *entry, uint32_t flags)
  2089. {
  2090. return _ibv_query_gid_ex(context, port_num, gid_index, entry, flags,
  2091. sizeof(*entry));
  2092. }
  2093. ssize_t _ibv_query_gid_table(struct ibv_context *context,
  2094. struct ibv_gid_entry *entries, size_t max_entries,
  2095. uint32_t flags, size_t entry_size);
  2096. /*
  2097. * ibv_query_gid_table - Get all valid GID table entries
  2098. */
  2099. static inline ssize_t ibv_query_gid_table(struct ibv_context *context,
  2100. struct ibv_gid_entry *entries,
  2101. size_t max_entries, uint32_t flags)
  2102. {
  2103. return _ibv_query_gid_table(context, entries, max_entries, flags,
  2104. sizeof(*entries));
  2105. }
  2106. /**
  2107. * ibv_query_pkey - Get a P_Key table entry
  2108. */
  2109. int ibv_query_pkey(struct ibv_context *context, uint8_t port_num,
  2110. int index, __be16 *pkey);
  2111. /**
  2112. * ibv_get_pkey_index - Translate a P_Key into a P_Key index
  2113. */
  2114. int ibv_get_pkey_index(struct ibv_context *context, uint8_t port_num,
  2115. __be16 pkey);
  2116. /**
  2117. * ibv_alloc_pd - Allocate a protection domain
  2118. */
  2119. struct ibv_pd *ibv_alloc_pd(struct ibv_context *context);
  2120. /**
  2121. * ibv_dealloc_pd - Free a protection domain
  2122. */
  2123. int ibv_dealloc_pd(struct ibv_pd *pd);
  2124. static inline struct ibv_flow *ibv_create_flow(struct ibv_qp *qp,
  2125. struct ibv_flow_attr *flow)
  2126. {
  2127. struct verbs_context *vctx = verbs_get_ctx_op(qp->context,
  2128. ibv_create_flow);
  2129. if (!vctx) {
  2130. errno = EOPNOTSUPP;
  2131. return NULL;
  2132. }
  2133. return vctx->ibv_create_flow(qp, flow);
  2134. }
  2135. static inline int ibv_destroy_flow(struct ibv_flow *flow_id)
  2136. {
  2137. struct verbs_context *vctx = verbs_get_ctx_op(flow_id->context,
  2138. ibv_destroy_flow);
  2139. if (!vctx)
  2140. return EOPNOTSUPP;
  2141. return vctx->ibv_destroy_flow(flow_id);
  2142. }
  2143. static inline struct ibv_flow_action *
  2144. ibv_create_flow_action_esp(struct ibv_context *ctx,
  2145. struct ibv_flow_action_esp_attr *esp)
  2146. {
  2147. struct verbs_context *vctx = verbs_get_ctx_op(ctx,
  2148. create_flow_action_esp);
  2149. if (!vctx) {
  2150. errno = EOPNOTSUPP;
  2151. return NULL;
  2152. }
  2153. return vctx->create_flow_action_esp(ctx, esp);
  2154. }
  2155. static inline int
  2156. ibv_modify_flow_action_esp(struct ibv_flow_action *action,
  2157. struct ibv_flow_action_esp_attr *esp)
  2158. {
  2159. struct verbs_context *vctx = verbs_get_ctx_op(action->context,
  2160. modify_flow_action_esp);
  2161. if (!vctx)
  2162. return EOPNOTSUPP;
  2163. return vctx->modify_flow_action_esp(action, esp);
  2164. }
  2165. static inline int ibv_destroy_flow_action(struct ibv_flow_action *action)
  2166. {
  2167. struct verbs_context *vctx = verbs_get_ctx_op(action->context,
  2168. destroy_flow_action);
  2169. if (!vctx)
  2170. return EOPNOTSUPP;
  2171. return vctx->destroy_flow_action(action);
  2172. }
  2173. /**
  2174. * ibv_open_xrcd - Open an extended connection domain
  2175. */
  2176. static inline struct ibv_xrcd *
  2177. ibv_open_xrcd(struct ibv_context *context, struct ibv_xrcd_init_attr *xrcd_init_attr)
  2178. {
  2179. struct verbs_context *vctx = verbs_get_ctx_op(context, open_xrcd);
  2180. if (!vctx) {
  2181. errno = EOPNOTSUPP;
  2182. return NULL;
  2183. }
  2184. return vctx->open_xrcd(context, xrcd_init_attr);
  2185. }
  2186. /**
  2187. * ibv_close_xrcd - Close an extended connection domain
  2188. */
  2189. static inline int ibv_close_xrcd(struct ibv_xrcd *xrcd)
  2190. {
  2191. struct verbs_context *vctx = verbs_get_ctx(xrcd->context);
  2192. return vctx->close_xrcd(xrcd);
  2193. }
  2194. /**
  2195. * ibv_reg_mr_iova2 - Register memory region with a virtual offset address
  2196. *
  2197. * This version will be called if ibv_reg_mr or ibv_reg_mr_iova were called
  2198. * with at least one potential access flag from the IBV_OPTIONAL_ACCESS_RANGE
  2199. * flags range The optional access flags will be masked if running over kernel
  2200. * that does not support passing them.
  2201. */
  2202. struct ibv_mr *ibv_reg_mr_iova2(struct ibv_pd *pd, void *addr, size_t length,
  2203. uint64_t iova, unsigned int access);
  2204. /**
  2205. * ibv_reg_mr - Register a memory region
  2206. */
  2207. struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
  2208. int access);
  2209. /* use new ibv_reg_mr version only if access flags that require it are used */
  2210. __attribute__((__always_inline__)) static inline struct ibv_mr *
  2211. __ibv_reg_mr(struct ibv_pd *pd, void *addr, size_t length, unsigned int access,
  2212. int is_access_const)
  2213. {
  2214. if (is_access_const && (access & IBV_ACCESS_OPTIONAL_RANGE) == 0)
  2215. return ibv_reg_mr(pd, addr, length, access);
  2216. else
  2217. return ibv_reg_mr_iova2(pd, addr, length, (uintptr_t)addr,
  2218. access);
  2219. }
  2220. #define ibv_reg_mr(pd, addr, length, access) \
  2221. __ibv_reg_mr(pd, addr, length, access, \
  2222. __builtin_constant_p( \
  2223. ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
  2224. /**
  2225. * ibv_reg_mr_iova - Register a memory region with a virtual offset
  2226. * address
  2227. */
  2228. struct ibv_mr *ibv_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length,
  2229. uint64_t iova, int access);
  2230. /* use new ibv_reg_mr version only if access flags that require it are used */
  2231. __attribute__((__always_inline__)) static inline struct ibv_mr *
  2232. __ibv_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length, uint64_t iova,
  2233. unsigned int access, int is_access_const)
  2234. {
  2235. if (is_access_const && (access & IBV_ACCESS_OPTIONAL_RANGE) == 0)
  2236. return ibv_reg_mr_iova(pd, addr, length, iova, access);
  2237. else
  2238. return ibv_reg_mr_iova2(pd, addr, length, iova, access);
  2239. }
  2240. #define ibv_reg_mr_iova(pd, addr, length, iova, access) \
  2241. __ibv_reg_mr_iova(pd, addr, length, iova, access, \
  2242. __builtin_constant_p( \
  2243. ((access) & IBV_ACCESS_OPTIONAL_RANGE) == 0))
  2244. enum ibv_rereg_mr_err_code {
  2245. /* Old MR is valid, invalid input */
  2246. IBV_REREG_MR_ERR_INPUT = -1,
  2247. /* Old MR is valid, failed via don't fork on new address range */
  2248. IBV_REREG_MR_ERR_DONT_FORK_NEW = -2,
  2249. /* New MR is valid, failed via do fork on old address range */
  2250. IBV_REREG_MR_ERR_DO_FORK_OLD = -3,
  2251. /* MR shouldn't be used, command error */
  2252. IBV_REREG_MR_ERR_CMD = -4,
  2253. /* MR shouldn't be used, command error, invalid fork state on new address range */
  2254. IBV_REREG_MR_ERR_CMD_AND_DO_FORK_NEW = -5,
  2255. };
  2256. /**
  2257. * ibv_rereg_mr - Re-Register a memory region
  2258. */
  2259. int ibv_rereg_mr(struct ibv_mr *mr, int flags,
  2260. struct ibv_pd *pd, void *addr,
  2261. size_t length, int access);
  2262. /**
  2263. * ibv_dereg_mr - Deregister a memory region
  2264. */
  2265. int ibv_dereg_mr(struct ibv_mr *mr);
  2266. /**
  2267. * ibv_alloc_mw - Allocate a memory window
  2268. */
  2269. static inline struct ibv_mw *ibv_alloc_mw(struct ibv_pd *pd,
  2270. enum ibv_mw_type type)
  2271. {
  2272. struct ibv_mw *mw;
  2273. if (!pd->context->ops.alloc_mw) {
  2274. errno = EOPNOTSUPP;
  2275. return NULL;
  2276. }
  2277. mw = pd->context->ops.alloc_mw(pd, type);
  2278. return mw;
  2279. }
  2280. /**
  2281. * ibv_dealloc_mw - Free a memory window
  2282. */
  2283. static inline int ibv_dealloc_mw(struct ibv_mw *mw)
  2284. {
  2285. return mw->context->ops.dealloc_mw(mw);
  2286. }
  2287. /**
  2288. * ibv_inc_rkey - Increase the 8 lsb in the given rkey
  2289. */
  2290. static inline uint32_t ibv_inc_rkey(uint32_t rkey)
  2291. {
  2292. const uint32_t mask = 0x000000ff;
  2293. uint8_t newtag = (uint8_t)((rkey + 1) & mask);
  2294. return (rkey & ~mask) | newtag;
  2295. }
  2296. /**
  2297. * ibv_bind_mw - Bind a memory window to a region
  2298. */
  2299. static inline int ibv_bind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
  2300. struct ibv_mw_bind *mw_bind)
  2301. {
  2302. if (mw->type != IBV_MW_TYPE_1)
  2303. return EINVAL;
  2304. return mw->context->ops.bind_mw(qp, mw, mw_bind);
  2305. }
  2306. /**
  2307. * ibv_create_comp_channel - Create a completion event channel
  2308. */
  2309. struct ibv_comp_channel *ibv_create_comp_channel(struct ibv_context *context);
  2310. /**
  2311. * ibv_destroy_comp_channel - Destroy a completion event channel
  2312. */
  2313. int ibv_destroy_comp_channel(struct ibv_comp_channel *channel);
  2314. /**
  2315. * ibv_advise_mr - Gives advice about an address range in MRs
  2316. * @pd - protection domain of all MRs for which the advice is for
  2317. * @advice - type of advice
  2318. * @flags - advice modifiers
  2319. * @sg_list - an array of memory ranges
  2320. * @num_sge - number of elements in the array
  2321. */
  2322. static inline int ibv_advise_mr(struct ibv_pd *pd,
  2323. enum ibv_advise_mr_advice advice,
  2324. uint32_t flags,
  2325. struct ibv_sge *sg_list,
  2326. uint32_t num_sge)
  2327. {
  2328. struct verbs_context *vctx;
  2329. vctx = verbs_get_ctx_op(pd->context, advise_mr);
  2330. if (!vctx)
  2331. return EOPNOTSUPP;
  2332. return vctx->advise_mr(pd, advice, flags, sg_list, num_sge);
  2333. }
  2334. /**
  2335. * ibv_alloc_dm - Allocate device memory
  2336. * @context - Context DM will be attached to
  2337. * @attr - Attributes to allocate the DM with
  2338. */
  2339. static inline
  2340. struct ibv_dm *ibv_alloc_dm(struct ibv_context *context,
  2341. struct ibv_alloc_dm_attr *attr)
  2342. {
  2343. struct verbs_context *vctx = verbs_get_ctx_op(context, alloc_dm);
  2344. if (!vctx) {
  2345. errno = EOPNOTSUPP;
  2346. return NULL;
  2347. }
  2348. return vctx->alloc_dm(context, attr);
  2349. }
  2350. /**
  2351. * ibv_free_dm - Free device allocated memory
  2352. * @dm - The DM to free
  2353. */
  2354. static inline
  2355. int ibv_free_dm(struct ibv_dm *dm)
  2356. {
  2357. struct verbs_context *vctx = verbs_get_ctx_op(dm->context, free_dm);
  2358. if (!vctx)
  2359. return EOPNOTSUPP;
  2360. return vctx->free_dm(dm);
  2361. }
  2362. /**
  2363. * ibv_memcpy_to/from_dm - copy to/from device allocated memory
  2364. * @dm - The DM to copy to/from
  2365. * @dm_offset - Offset in bytes from beginning of DM to start copy to/form
  2366. * @host_addr - Host memory address to copy to/from
  2367. * @length - Number of bytes to copy
  2368. */
  2369. static inline
  2370. int ibv_memcpy_to_dm(struct ibv_dm *dm, uint64_t dm_offset,
  2371. const void *host_addr, size_t length)
  2372. {
  2373. return dm->memcpy_to_dm(dm, dm_offset, host_addr, length);
  2374. }
  2375. static inline
  2376. int ibv_memcpy_from_dm(void *host_addr, struct ibv_dm *dm,
  2377. uint64_t dm_offset, size_t length)
  2378. {
  2379. return dm->memcpy_from_dm(host_addr, dm, dm_offset, length);
  2380. }
  2381. /*
  2382. * ibv_alloc_null_mr - Allocate a null memory region.
  2383. * @pd - The protection domain associated with the MR.
  2384. */
  2385. static inline
  2386. struct ibv_mr *ibv_alloc_null_mr(struct ibv_pd *pd)
  2387. {
  2388. struct verbs_context *vctx;
  2389. vctx = verbs_get_ctx_op(pd->context, alloc_null_mr);
  2390. if (!vctx) {
  2391. errno = EOPNOTSUPP;
  2392. return NULL;
  2393. }
  2394. return vctx->alloc_null_mr(pd);
  2395. }
  2396. /**
  2397. * ibv_reg_dm_mr - Register device memory as a memory region
  2398. * @pd - The PD to associated this MR with
  2399. * @dm - The DM to register
  2400. * @dm_offset - Offset in bytes from beginning of DM to start registration from
  2401. * @length - Number of bytes to register
  2402. * @access - memory region access flags
  2403. */
  2404. static inline
  2405. struct ibv_mr *ibv_reg_dm_mr(struct ibv_pd *pd, struct ibv_dm *dm,
  2406. uint64_t dm_offset,
  2407. size_t length, unsigned int access)
  2408. {
  2409. struct verbs_context *vctx = verbs_get_ctx_op(pd->context, reg_dm_mr);
  2410. if (!vctx) {
  2411. errno = EOPNOTSUPP;
  2412. return NULL;
  2413. }
  2414. return vctx->reg_dm_mr(pd, dm, dm_offset, length, access);
  2415. }
  2416. /**
  2417. * ibv_create_cq - Create a completion queue
  2418. * @context - Context CQ will be attached to
  2419. * @cqe - Minimum number of entries required for CQ
  2420. * @cq_context - Consumer-supplied context returned for completion events
  2421. * @channel - Completion channel where completion events will be queued.
  2422. * May be NULL if completion events will not be used.
  2423. * @comp_vector - Completion vector used to signal completion events.
  2424. * Must be >= 0 and < context->num_comp_vectors.
  2425. */
  2426. struct ibv_cq *ibv_create_cq(struct ibv_context *context, int cqe,
  2427. void *cq_context,
  2428. struct ibv_comp_channel *channel,
  2429. int comp_vector);
  2430. /**
  2431. * ibv_create_cq_ex - Create a completion queue
  2432. * @context - Context CQ will be attached to
  2433. * @cq_attr - Attributes to create the CQ with
  2434. */
  2435. static inline
  2436. struct ibv_cq_ex *ibv_create_cq_ex(struct ibv_context *context,
  2437. struct ibv_cq_init_attr_ex *cq_attr)
  2438. {
  2439. struct verbs_context *vctx = verbs_get_ctx_op(context, create_cq_ex);
  2440. if (!vctx) {
  2441. errno = EOPNOTSUPP;
  2442. return NULL;
  2443. }
  2444. return vctx->create_cq_ex(context, cq_attr);
  2445. }
  2446. /**
  2447. * ibv_resize_cq - Modifies the capacity of the CQ.
  2448. * @cq: The CQ to resize.
  2449. * @cqe: The minimum size of the CQ.
  2450. *
  2451. * Users can examine the cq structure to determine the actual CQ size.
  2452. */
  2453. int ibv_resize_cq(struct ibv_cq *cq, int cqe);
  2454. /**
  2455. * ibv_destroy_cq - Destroy a completion queue
  2456. */
  2457. int ibv_destroy_cq(struct ibv_cq *cq);
  2458. /**
  2459. * ibv_get_cq_event - Read next CQ event
  2460. * @channel: Channel to get next event from.
  2461. * @cq: Used to return pointer to CQ.
  2462. * @cq_context: Used to return consumer-supplied CQ context.
  2463. *
  2464. * All completion events returned by ibv_get_cq_event() must
  2465. * eventually be acknowledged with ibv_ack_cq_events().
  2466. */
  2467. int ibv_get_cq_event(struct ibv_comp_channel *channel,
  2468. struct ibv_cq **cq, void **cq_context);
  2469. /**
  2470. * ibv_ack_cq_events - Acknowledge CQ completion events
  2471. * @cq: CQ to acknowledge events for
  2472. * @nevents: Number of events to acknowledge.
  2473. *
  2474. * All completion events which are returned by ibv_get_cq_event() must
  2475. * be acknowledged. To avoid races, ibv_destroy_cq() will wait for
  2476. * all completion events to be acknowledged, so there should be a
  2477. * one-to-one correspondence between acks and successful gets. An
  2478. * application may accumulate multiple completion events and
  2479. * acknowledge them in a single call to ibv_ack_cq_events() by passing
  2480. * the number of events to ack in @nevents.
  2481. */
  2482. void ibv_ack_cq_events(struct ibv_cq *cq, unsigned int nevents);
  2483. /**
  2484. * ibv_poll_cq - Poll a CQ for work completions
  2485. * @cq:the CQ being polled
  2486. * @num_entries:maximum number of completions to return
  2487. * @wc:array of at least @num_entries of &struct ibv_wc where completions
  2488. * will be returned
  2489. *
  2490. * Poll a CQ for (possibly multiple) completions. If the return value
  2491. * is < 0, an error occurred. If the return value is >= 0, it is the
  2492. * number of completions returned. If the return value is
  2493. * non-negative and strictly less than num_entries, then the CQ was
  2494. * emptied.
  2495. */
  2496. static inline int ibv_poll_cq(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc)
  2497. {
  2498. return cq->context->ops.poll_cq(cq, num_entries, wc);
  2499. }
  2500. /**
  2501. * ibv_req_notify_cq - Request completion notification on a CQ. An
  2502. * event will be added to the completion channel associated with the
  2503. * CQ when an entry is added to the CQ.
  2504. * @cq: The completion queue to request notification for.
  2505. * @solicited_only: If non-zero, an event will be generated only for
  2506. * the next solicited CQ entry. If zero, any CQ entry, solicited or
  2507. * not, will generate an event.
  2508. */
  2509. static inline int ibv_req_notify_cq(struct ibv_cq *cq, int solicited_only)
  2510. {
  2511. return cq->context->ops.req_notify_cq(cq, solicited_only);
  2512. }
  2513. static inline int ibv_modify_cq(struct ibv_cq *cq, struct ibv_modify_cq_attr *attr)
  2514. {
  2515. struct verbs_context *vctx = verbs_get_ctx_op(cq->context, modify_cq);
  2516. if (!vctx)
  2517. return EOPNOTSUPP;
  2518. return vctx->modify_cq(cq, attr);
  2519. }
  2520. /**
  2521. * ibv_create_srq - Creates a SRQ associated with the specified protection
  2522. * domain.
  2523. * @pd: The protection domain associated with the SRQ.
  2524. * @srq_init_attr: A list of initial attributes required to create the SRQ.
  2525. *
  2526. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  2527. * requested size of the SRQ, and set to the actual values allocated
  2528. * on return. If ibv_create_srq() succeeds, then max_wr and max_sge
  2529. * will always be at least as large as the requested values.
  2530. */
  2531. struct ibv_srq *ibv_create_srq(struct ibv_pd *pd,
  2532. struct ibv_srq_init_attr *srq_init_attr);
  2533. static inline struct ibv_srq *
  2534. ibv_create_srq_ex(struct ibv_context *context,
  2535. struct ibv_srq_init_attr_ex *srq_init_attr_ex)
  2536. {
  2537. struct verbs_context *vctx;
  2538. uint32_t mask = srq_init_attr_ex->comp_mask;
  2539. if (!(mask & ~(IBV_SRQ_INIT_ATTR_PD | IBV_SRQ_INIT_ATTR_TYPE)) &&
  2540. (mask & IBV_SRQ_INIT_ATTR_PD) &&
  2541. (!(mask & IBV_SRQ_INIT_ATTR_TYPE) ||
  2542. (srq_init_attr_ex->srq_type == IBV_SRQT_BASIC)))
  2543. return ibv_create_srq(srq_init_attr_ex->pd,
  2544. (struct ibv_srq_init_attr *)srq_init_attr_ex);
  2545. vctx = verbs_get_ctx_op(context, create_srq_ex);
  2546. if (!vctx) {
  2547. errno = EOPNOTSUPP;
  2548. return NULL;
  2549. }
  2550. return vctx->create_srq_ex(context, srq_init_attr_ex);
  2551. }
  2552. /**
  2553. * ibv_modify_srq - Modifies the attributes for the specified SRQ.
  2554. * @srq: The SRQ to modify.
  2555. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  2556. * the current values of selected SRQ attributes are returned.
  2557. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  2558. * are being modified.
  2559. *
  2560. * The mask may contain IBV_SRQ_MAX_WR to resize the SRQ and/or
  2561. * IBV_SRQ_LIMIT to set the SRQ's limit and request notification when
  2562. * the number of receives queued drops below the limit.
  2563. */
  2564. int ibv_modify_srq(struct ibv_srq *srq,
  2565. struct ibv_srq_attr *srq_attr,
  2566. int srq_attr_mask);
  2567. /**
  2568. * ibv_query_srq - Returns the attribute list and current values for the
  2569. * specified SRQ.
  2570. * @srq: The SRQ to query.
  2571. * @srq_attr: The attributes of the specified SRQ.
  2572. */
  2573. int ibv_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr);
  2574. static inline int ibv_get_srq_num(struct ibv_srq *srq, uint32_t *srq_num)
  2575. {
  2576. struct verbs_context *vctx = verbs_get_ctx_op(srq->context, get_srq_num);
  2577. if (!vctx)
  2578. return EOPNOTSUPP;
  2579. return vctx->get_srq_num(srq, srq_num);
  2580. }
  2581. /**
  2582. * ibv_destroy_srq - Destroys the specified SRQ.
  2583. * @srq: The SRQ to destroy.
  2584. */
  2585. int ibv_destroy_srq(struct ibv_srq *srq);
  2586. /**
  2587. * ibv_post_srq_recv - Posts a list of work requests to the specified SRQ.
  2588. * @srq: The SRQ to post the work request on.
  2589. * @recv_wr: A list of work requests to post on the receive queue.
  2590. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2591. * the work request that failed to be posted on the QP.
  2592. */
  2593. static inline int ibv_post_srq_recv(struct ibv_srq *srq,
  2594. struct ibv_recv_wr *recv_wr,
  2595. struct ibv_recv_wr **bad_recv_wr)
  2596. {
  2597. return srq->context->ops.post_srq_recv(srq, recv_wr, bad_recv_wr);
  2598. }
  2599. static inline int ibv_post_srq_ops(struct ibv_srq *srq,
  2600. struct ibv_ops_wr *op,
  2601. struct ibv_ops_wr **bad_op)
  2602. {
  2603. struct verbs_context *vctx;
  2604. vctx = verbs_get_ctx_op(srq->context, post_srq_ops);
  2605. if (!vctx) {
  2606. *bad_op = op;
  2607. return EOPNOTSUPP;
  2608. }
  2609. return vctx->post_srq_ops(srq, op, bad_op);
  2610. }
  2611. /**
  2612. * ibv_create_qp - Create a queue pair.
  2613. */
  2614. struct ibv_qp *ibv_create_qp(struct ibv_pd *pd,
  2615. struct ibv_qp_init_attr *qp_init_attr);
  2616. static inline struct ibv_qp *
  2617. ibv_create_qp_ex(struct ibv_context *context, struct ibv_qp_init_attr_ex *qp_init_attr_ex)
  2618. {
  2619. struct verbs_context *vctx;
  2620. uint32_t mask = qp_init_attr_ex->comp_mask;
  2621. if (mask == IBV_QP_INIT_ATTR_PD)
  2622. return ibv_create_qp(qp_init_attr_ex->pd,
  2623. (struct ibv_qp_init_attr *)qp_init_attr_ex);
  2624. vctx = verbs_get_ctx_op(context, create_qp_ex);
  2625. if (!vctx) {
  2626. errno = EOPNOTSUPP;
  2627. return NULL;
  2628. }
  2629. return vctx->create_qp_ex(context, qp_init_attr_ex);
  2630. }
  2631. /**
  2632. * ibv_alloc_td - Allocate a thread domain
  2633. */
  2634. static inline struct ibv_td *ibv_alloc_td(struct ibv_context *context,
  2635. struct ibv_td_init_attr *init_attr)
  2636. {
  2637. struct verbs_context *vctx;
  2638. vctx = verbs_get_ctx_op(context, alloc_td);
  2639. if (!vctx) {
  2640. errno = EOPNOTSUPP;
  2641. return NULL;
  2642. }
  2643. return vctx->alloc_td(context, init_attr);
  2644. }
  2645. /**
  2646. * ibv_dealloc_td - Free a thread domain
  2647. */
  2648. static inline int ibv_dealloc_td(struct ibv_td *td)
  2649. {
  2650. struct verbs_context *vctx;
  2651. vctx = verbs_get_ctx_op(td->context, dealloc_td);
  2652. if (!vctx)
  2653. return EOPNOTSUPP;
  2654. return vctx->dealloc_td(td);
  2655. }
  2656. /**
  2657. * ibv_alloc_parent_domain - Allocate a parent domain
  2658. */
  2659. static inline struct ibv_pd *
  2660. ibv_alloc_parent_domain(struct ibv_context *context,
  2661. struct ibv_parent_domain_init_attr *attr)
  2662. {
  2663. struct verbs_context *vctx;
  2664. vctx = verbs_get_ctx_op(context, alloc_parent_domain);
  2665. if (!vctx) {
  2666. errno = EOPNOTSUPP;
  2667. return NULL;
  2668. }
  2669. return vctx->alloc_parent_domain(context, attr);
  2670. }
  2671. /**
  2672. * ibv_query_rt_values_ex - Get current real time @values of a device.
  2673. * @values - in/out - defines the attributes we need to query/queried.
  2674. * (Or's bits of enum ibv_values_mask on values->comp_mask field)
  2675. */
  2676. static inline int
  2677. ibv_query_rt_values_ex(struct ibv_context *context,
  2678. struct ibv_values_ex *values)
  2679. {
  2680. struct verbs_context *vctx;
  2681. vctx = verbs_get_ctx_op(context, query_rt_values);
  2682. if (!vctx)
  2683. return EOPNOTSUPP;
  2684. return vctx->query_rt_values(context, values);
  2685. }
  2686. /**
  2687. * ibv_query_device_ex - Get extended device properties
  2688. */
  2689. static inline int
  2690. ibv_query_device_ex(struct ibv_context *context,
  2691. const struct ibv_query_device_ex_input *input,
  2692. struct ibv_device_attr_ex *attr)
  2693. {
  2694. struct verbs_context *vctx;
  2695. int ret;
  2696. if (input && input->comp_mask)
  2697. return EINVAL;
  2698. vctx = verbs_get_ctx_op(context, query_device_ex);
  2699. if (!vctx)
  2700. goto legacy;
  2701. ret = vctx->query_device_ex(context, input, attr, sizeof(*attr));
  2702. if (ret == EOPNOTSUPP || ret == ENOSYS)
  2703. goto legacy;
  2704. return ret;
  2705. legacy:
  2706. memset(attr, 0, sizeof(*attr));
  2707. ret = ibv_query_device(context, &attr->orig_attr);
  2708. return ret;
  2709. }
  2710. /**
  2711. * ibv_open_qp - Open a shareable queue pair.
  2712. */
  2713. static inline struct ibv_qp *
  2714. ibv_open_qp(struct ibv_context *context, struct ibv_qp_open_attr *qp_open_attr)
  2715. {
  2716. struct verbs_context *vctx = verbs_get_ctx_op(context, open_qp);
  2717. if (!vctx) {
  2718. errno = EOPNOTSUPP;
  2719. return NULL;
  2720. }
  2721. return vctx->open_qp(context, qp_open_attr);
  2722. }
  2723. /**
  2724. * ibv_modify_qp - Modify a queue pair.
  2725. */
  2726. int ibv_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
  2727. int attr_mask);
  2728. /**
  2729. * ibv_modify_qp_rate_limit - Modify a queue pair rate limit values
  2730. * @qp - QP object to modify
  2731. * @attr - Attributes to configure the rate limiting values of the QP
  2732. */
  2733. static inline int
  2734. ibv_modify_qp_rate_limit(struct ibv_qp *qp,
  2735. struct ibv_qp_rate_limit_attr *attr)
  2736. {
  2737. struct verbs_context *vctx;
  2738. vctx = verbs_get_ctx_op(qp->context, modify_qp_rate_limit);
  2739. if (!vctx)
  2740. return EOPNOTSUPP;
  2741. return vctx->modify_qp_rate_limit(qp, attr);
  2742. }
  2743. /**
  2744. * ibv_query_qp - Returns the attribute list and current values for the
  2745. * specified QP.
  2746. * @qp: The QP to query.
  2747. * @attr: The attributes of the specified QP.
  2748. * @attr_mask: A bit-mask used to select specific attributes to query.
  2749. * @init_attr: Additional attributes of the selected QP.
  2750. *
  2751. * The qp_attr_mask may be used to limit the query to gathering only the
  2752. * selected attributes.
  2753. */
  2754. int ibv_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
  2755. int attr_mask,
  2756. struct ibv_qp_init_attr *init_attr);
  2757. /**
  2758. * ibv_destroy_qp - Destroy a queue pair.
  2759. */
  2760. int ibv_destroy_qp(struct ibv_qp *qp);
  2761. /*
  2762. * ibv_create_wq - Creates a WQ associated with the specified protection
  2763. * domain.
  2764. * @context: ibv_context.
  2765. * @wq_init_attr: A list of initial attributes required to create the
  2766. * WQ. If WQ creation succeeds, then the attributes are updated to
  2767. * the actual capabilities of the created WQ.
  2768. *
  2769. * wq_init_attr->max_wr and wq_init_attr->max_sge determine
  2770. * the requested size of the WQ, and set to the actual values allocated
  2771. * on return.
  2772. * If ibv_create_wq() succeeds, then max_wr and max_sge will always be
  2773. * at least as large as the requested values.
  2774. *
  2775. * Return Value
  2776. * ibv_create_wq() returns a pointer to the created WQ, or NULL if the request
  2777. * fails.
  2778. */
  2779. static inline struct ibv_wq *ibv_create_wq(struct ibv_context *context,
  2780. struct ibv_wq_init_attr *wq_init_attr)
  2781. {
  2782. struct verbs_context *vctx = verbs_get_ctx_op(context, create_wq);
  2783. struct ibv_wq *wq;
  2784. if (!vctx) {
  2785. errno = EOPNOTSUPP;
  2786. return NULL;
  2787. }
  2788. wq = vctx->create_wq(context, wq_init_attr);
  2789. if (wq) {
  2790. wq->wq_context = wq_init_attr->wq_context;
  2791. wq->events_completed = 0;
  2792. pthread_mutex_init(&wq->mutex, NULL);
  2793. pthread_cond_init(&wq->cond, NULL);
  2794. }
  2795. return wq;
  2796. }
  2797. /*
  2798. * ibv_modify_wq - Modifies the attributes for the specified WQ.
  2799. * @wq: The WQ to modify.
  2800. * @wq_attr: On input, specifies the WQ attributes to modify.
  2801. * wq_attr->attr_mask: A bit-mask used to specify which attributes of the WQ
  2802. * are being modified.
  2803. * On output, the current values of selected WQ attributes are returned.
  2804. *
  2805. * Return Value
  2806. * ibv_modify_wq() returns 0 on success, or the value of errno
  2807. * on failure (which indicates the failure reason).
  2808. *
  2809. */
  2810. static inline int ibv_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
  2811. {
  2812. struct verbs_context *vctx = verbs_get_ctx_op(wq->context, modify_wq);
  2813. if (!vctx)
  2814. return EOPNOTSUPP;
  2815. return vctx->modify_wq(wq, wq_attr);
  2816. }
  2817. /*
  2818. * ibv_destroy_wq - Destroys the specified WQ.
  2819. * @ibv_wq: The WQ to destroy.
  2820. * Return Value
  2821. * ibv_destroy_wq() returns 0 on success, or the value of errno
  2822. * on failure (which indicates the failure reason).
  2823. */
  2824. static inline int ibv_destroy_wq(struct ibv_wq *wq)
  2825. {
  2826. struct verbs_context *vctx;
  2827. vctx = verbs_get_ctx_op(wq->context, destroy_wq);
  2828. if (!vctx)
  2829. return EOPNOTSUPP;
  2830. return vctx->destroy_wq(wq);
  2831. }
  2832. /*
  2833. * ibv_create_rwq_ind_table - Creates a receive work queue Indirection Table
  2834. * @context: ibv_context.
  2835. * @init_attr: A list of initial attributes required to create the Indirection Table.
  2836. * Return Value
  2837. * ibv_create_rwq_ind_table returns a pointer to the created
  2838. * Indirection Table, or NULL if the request fails.
  2839. */
  2840. static inline struct ibv_rwq_ind_table *ibv_create_rwq_ind_table(struct ibv_context *context,
  2841. struct ibv_rwq_ind_table_init_attr *init_attr)
  2842. {
  2843. struct verbs_context *vctx;
  2844. vctx = verbs_get_ctx_op(context, create_rwq_ind_table);
  2845. if (!vctx) {
  2846. errno = EOPNOTSUPP;
  2847. return NULL;
  2848. }
  2849. return vctx->create_rwq_ind_table(context, init_attr);
  2850. }
  2851. /*
  2852. * ibv_destroy_rwq_ind_table - Destroys the specified Indirection Table.
  2853. * @rwq_ind_table: The Indirection Table to destroy.
  2854. * Return Value
  2855. * ibv_destroy_rwq_ind_table() returns 0 on success, or the value of errno
  2856. * on failure (which indicates the failure reason).
  2857. */
  2858. static inline int ibv_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
  2859. {
  2860. struct verbs_context *vctx;
  2861. vctx = verbs_get_ctx_op(rwq_ind_table->context, destroy_rwq_ind_table);
  2862. if (!vctx)
  2863. return EOPNOTSUPP;
  2864. return vctx->destroy_rwq_ind_table(rwq_ind_table);
  2865. }
  2866. /**
  2867. * ibv_post_send - Post a list of work requests to a send queue.
  2868. *
  2869. * If IBV_SEND_INLINE flag is set, the data buffers can be reused
  2870. * immediately after the call returns.
  2871. */
  2872. static inline int ibv_post_send(struct ibv_qp *qp, struct ibv_send_wr *wr,
  2873. struct ibv_send_wr **bad_wr)
  2874. {
  2875. return qp->context->ops.post_send(qp, wr, bad_wr);
  2876. }
  2877. /**
  2878. * ibv_post_recv - Post a list of work requests to a receive queue.
  2879. */
  2880. static inline int ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr,
  2881. struct ibv_recv_wr **bad_wr)
  2882. {
  2883. return qp->context->ops.post_recv(qp, wr, bad_wr);
  2884. }
  2885. /**
  2886. * ibv_create_ah - Create an address handle.
  2887. */
  2888. struct ibv_ah *ibv_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr);
  2889. /**
  2890. * ibv_init_ah_from_wc - Initializes address handle attributes from a
  2891. * work completion.
  2892. * @context: Device context on which the received message arrived.
  2893. * @port_num: Port on which the received message arrived.
  2894. * @wc: Work completion associated with the received message.
  2895. * @grh: References the received global route header. This parameter is
  2896. * ignored unless the work completion indicates that the GRH is valid.
  2897. * @ah_attr: Returned attributes that can be used when creating an address
  2898. * handle for replying to the message.
  2899. */
  2900. int ibv_init_ah_from_wc(struct ibv_context *context, uint8_t port_num,
  2901. struct ibv_wc *wc, struct ibv_grh *grh,
  2902. struct ibv_ah_attr *ah_attr);
  2903. /**
  2904. * ibv_create_ah_from_wc - Creates an address handle associated with the
  2905. * sender of the specified work completion.
  2906. * @pd: The protection domain associated with the address handle.
  2907. * @wc: Work completion information associated with a received message.
  2908. * @grh: References the received global route header. This parameter is
  2909. * ignored unless the work completion indicates that the GRH is valid.
  2910. * @port_num: The outbound port number to associate with the address.
  2911. *
  2912. * The address handle is used to reference a local or global destination
  2913. * in all UD QP post sends.
  2914. */
  2915. struct ibv_ah *ibv_create_ah_from_wc(struct ibv_pd *pd, struct ibv_wc *wc,
  2916. struct ibv_grh *grh, uint8_t port_num);
  2917. /**
  2918. * ibv_destroy_ah - Destroy an address handle.
  2919. */
  2920. int ibv_destroy_ah(struct ibv_ah *ah);
  2921. /**
  2922. * ibv_attach_mcast - Attaches the specified QP to a multicast group.
  2923. * @qp: QP to attach to the multicast group. The QP must be a UD QP.
  2924. * @gid: Multicast group GID.
  2925. * @lid: Multicast group LID in host byte order.
  2926. *
  2927. * In order to route multicast packets correctly, subnet
  2928. * administration must have created the multicast group and configured
  2929. * the fabric appropriately. The port associated with the specified
  2930. * QP must also be a member of the multicast group.
  2931. */
  2932. int ibv_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
  2933. /**
  2934. * ibv_detach_mcast - Detaches the specified QP from a multicast group.
  2935. * @qp: QP to detach from the multicast group.
  2936. * @gid: Multicast group GID.
  2937. * @lid: Multicast group LID in host byte order.
  2938. */
  2939. int ibv_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
  2940. /**
  2941. * ibv_fork_init - Prepare data structures so that fork() may be used
  2942. * safely. If this function is not called or returns a non-zero
  2943. * status, then libibverbs data structures are not fork()-safe and the
  2944. * effect of an application calling fork() is undefined.
  2945. */
  2946. int ibv_fork_init(void);
  2947. /**
  2948. * ibv_node_type_str - Return string describing node_type enum value
  2949. */
  2950. const char *ibv_node_type_str(enum ibv_node_type node_type);
  2951. /**
  2952. * ibv_port_state_str - Return string describing port_state enum value
  2953. */
  2954. const char *ibv_port_state_str(enum ibv_port_state port_state);
  2955. /**
  2956. * ibv_event_type_str - Return string describing event_type enum value
  2957. */
  2958. const char *ibv_event_type_str(enum ibv_event_type event);
  2959. #define ETHERNET_LL_SIZE 6
  2960. int ibv_resolve_eth_l2_from_gid(struct ibv_context *context,
  2961. struct ibv_ah_attr *attr,
  2962. uint8_t eth_mac[ETHERNET_LL_SIZE],
  2963. uint16_t *vid);
  2964. static inline int ibv_is_qpt_supported(uint32_t caps, enum ibv_qp_type qpt)
  2965. {
  2966. return !!(caps & (1 << qpt));
  2967. }
  2968. static inline struct ibv_counters *ibv_create_counters(struct ibv_context *context,
  2969. struct ibv_counters_init_attr *init_attr)
  2970. {
  2971. struct verbs_context *vctx;
  2972. vctx = verbs_get_ctx_op(context, create_counters);
  2973. if (!vctx) {
  2974. errno = EOPNOTSUPP;
  2975. return NULL;
  2976. }
  2977. return vctx->create_counters(context, init_attr);
  2978. }
  2979. static inline int ibv_destroy_counters(struct ibv_counters *counters)
  2980. {
  2981. struct verbs_context *vctx;
  2982. vctx = verbs_get_ctx_op(counters->context, destroy_counters);
  2983. if (!vctx)
  2984. return EOPNOTSUPP;
  2985. return vctx->destroy_counters(counters);
  2986. }
  2987. static inline int ibv_attach_counters_point_flow(struct ibv_counters *counters,
  2988. struct ibv_counter_attach_attr *attr,
  2989. struct ibv_flow *flow)
  2990. {
  2991. struct verbs_context *vctx;
  2992. vctx = verbs_get_ctx_op(counters->context, attach_counters_point_flow);
  2993. if (!vctx)
  2994. return EOPNOTSUPP;
  2995. return vctx->attach_counters_point_flow(counters, attr, flow);
  2996. }
  2997. static inline int ibv_read_counters(struct ibv_counters *counters,
  2998. uint64_t *counters_value,
  2999. uint32_t ncounters,
  3000. uint32_t flags)
  3001. {
  3002. struct verbs_context *vctx;
  3003. vctx = verbs_get_ctx_op(counters->context, read_counters);
  3004. if (!vctx)
  3005. return EOPNOTSUPP;
  3006. return vctx->read_counters(counters, counters_value, ncounters, flags);
  3007. }
  3008. #define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
  3009. #define IB_ROCE_UDP_ENCAP_VALID_PORT_MAX (0xFFFF)
  3010. #define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
  3011. static inline uint16_t ibv_flow_label_to_udp_sport(uint32_t fl)
  3012. {
  3013. uint32_t fl_low = fl & 0x03FFF, fl_high = fl & 0xFC000;
  3014. fl_low ^= fl_high >> 14;
  3015. return (uint16_t)(fl_low | IB_ROCE_UDP_ENCAP_VALID_PORT_MIN);
  3016. }
  3017. /**
  3018. * ibv_set_ece - Set ECE options
  3019. */
  3020. int ibv_set_ece(struct ibv_qp *qp, struct ibv_ece *ece);
  3021. /**
  3022. * ibv_query_ece - Get accepted ECE options
  3023. */
  3024. int ibv_query_ece(struct ibv_qp *qp, struct ibv_ece *ece);
  3025. #ifdef __cplusplus
  3026. }
  3027. #endif
  3028. # undef __attribute_const
  3029. #endif /* INFINIBAND_VERBS_H */