ib_verbs.h 74 KB

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