ib_verbs.h 75 KB

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