ib_verbs.h 88 KB

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