ib_verbs.h 88 KB

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