ib_verbs.h 88 KB

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