ib_verbs.h 86 KB

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