ib_verbs.h 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  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 <asm/atomic.h>
  49. #include <asm/uaccess.h>
  50. union ib_gid {
  51. u8 raw[16];
  52. struct {
  53. __be64 subnet_prefix;
  54. __be64 interface_id;
  55. } global;
  56. };
  57. enum rdma_node_type {
  58. /* IB values map to NodeInfo:NodeType. */
  59. RDMA_NODE_IB_CA = 1,
  60. RDMA_NODE_IB_SWITCH,
  61. RDMA_NODE_IB_ROUTER,
  62. RDMA_NODE_RNIC
  63. };
  64. enum rdma_transport_type {
  65. RDMA_TRANSPORT_IB,
  66. RDMA_TRANSPORT_IWARP
  67. };
  68. enum rdma_transport_type
  69. rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
  70. enum rdma_link_layer {
  71. IB_LINK_LAYER_UNSPECIFIED,
  72. IB_LINK_LAYER_INFINIBAND,
  73. IB_LINK_LAYER_ETHERNET,
  74. };
  75. enum ib_device_cap_flags {
  76. IB_DEVICE_RESIZE_MAX_WR = 1,
  77. IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
  78. IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
  79. IB_DEVICE_RAW_MULTI = (1<<3),
  80. IB_DEVICE_AUTO_PATH_MIG = (1<<4),
  81. IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
  82. IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
  83. IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
  84. IB_DEVICE_SHUTDOWN_PORT = (1<<8),
  85. IB_DEVICE_INIT_TYPE = (1<<9),
  86. IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
  87. IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
  88. IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
  89. IB_DEVICE_SRQ_RESIZE = (1<<13),
  90. IB_DEVICE_N_NOTIFY_CQ = (1<<14),
  91. IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
  92. IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
  93. IB_DEVICE_MEM_WINDOW = (1<<17),
  94. /*
  95. * Devices should set IB_DEVICE_UD_IP_SUM if they support
  96. * insertion of UDP and TCP checksum on outgoing UD IPoIB
  97. * messages and can verify the validity of checksum for
  98. * incoming messages. Setting this flag implies that the
  99. * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
  100. */
  101. IB_DEVICE_UD_IP_CSUM = (1<<18),
  102. IB_DEVICE_UD_TSO = (1<<19),
  103. IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
  104. IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
  105. };
  106. enum ib_atomic_cap {
  107. IB_ATOMIC_NONE,
  108. IB_ATOMIC_HCA,
  109. IB_ATOMIC_GLOB
  110. };
  111. struct ib_device_attr {
  112. u64 fw_ver;
  113. __be64 sys_image_guid;
  114. u64 max_mr_size;
  115. u64 page_size_cap;
  116. u32 vendor_id;
  117. u32 vendor_part_id;
  118. u32 hw_ver;
  119. int max_qp;
  120. int max_qp_wr;
  121. int device_cap_flags;
  122. int max_sge;
  123. int max_sge_rd;
  124. int max_cq;
  125. int max_cqe;
  126. int max_mr;
  127. int max_pd;
  128. int max_qp_rd_atom;
  129. int max_ee_rd_atom;
  130. int max_res_rd_atom;
  131. int max_qp_init_rd_atom;
  132. int max_ee_init_rd_atom;
  133. enum ib_atomic_cap atomic_cap;
  134. enum ib_atomic_cap masked_atomic_cap;
  135. int max_ee;
  136. int max_rdd;
  137. int max_mw;
  138. int max_raw_ipv6_qp;
  139. int max_raw_ethy_qp;
  140. int max_mcast_grp;
  141. int max_mcast_qp_attach;
  142. int max_total_mcast_qp_attach;
  143. int max_ah;
  144. int max_fmr;
  145. int max_map_per_fmr;
  146. int max_srq;
  147. int max_srq_wr;
  148. int max_srq_sge;
  149. unsigned int max_fast_reg_page_list_len;
  150. u16 max_pkeys;
  151. u8 local_ca_ack_delay;
  152. };
  153. enum ib_mtu {
  154. IB_MTU_256 = 1,
  155. IB_MTU_512 = 2,
  156. IB_MTU_1024 = 3,
  157. IB_MTU_2048 = 4,
  158. IB_MTU_4096 = 5
  159. };
  160. static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
  161. {
  162. switch (mtu) {
  163. case IB_MTU_256: return 256;
  164. case IB_MTU_512: return 512;
  165. case IB_MTU_1024: return 1024;
  166. case IB_MTU_2048: return 2048;
  167. case IB_MTU_4096: return 4096;
  168. default: return -1;
  169. }
  170. }
  171. enum ib_port_state {
  172. IB_PORT_NOP = 0,
  173. IB_PORT_DOWN = 1,
  174. IB_PORT_INIT = 2,
  175. IB_PORT_ARMED = 3,
  176. IB_PORT_ACTIVE = 4,
  177. IB_PORT_ACTIVE_DEFER = 5
  178. };
  179. enum ib_port_cap_flags {
  180. IB_PORT_SM = 1 << 1,
  181. IB_PORT_NOTICE_SUP = 1 << 2,
  182. IB_PORT_TRAP_SUP = 1 << 3,
  183. IB_PORT_OPT_IPD_SUP = 1 << 4,
  184. IB_PORT_AUTO_MIGR_SUP = 1 << 5,
  185. IB_PORT_SL_MAP_SUP = 1 << 6,
  186. IB_PORT_MKEY_NVRAM = 1 << 7,
  187. IB_PORT_PKEY_NVRAM = 1 << 8,
  188. IB_PORT_LED_INFO_SUP = 1 << 9,
  189. IB_PORT_SM_DISABLED = 1 << 10,
  190. IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  191. IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  192. IB_PORT_CM_SUP = 1 << 16,
  193. IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  194. IB_PORT_REINIT_SUP = 1 << 18,
  195. IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
  196. IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
  197. IB_PORT_DR_NOTICE_SUP = 1 << 21,
  198. IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  199. IB_PORT_BOOT_MGMT_SUP = 1 << 23,
  200. IB_PORT_LINK_LATENCY_SUP = 1 << 24,
  201. IB_PORT_CLIENT_REG_SUP = 1 << 25
  202. };
  203. enum ib_port_width {
  204. IB_WIDTH_1X = 1,
  205. IB_WIDTH_4X = 2,
  206. IB_WIDTH_8X = 4,
  207. IB_WIDTH_12X = 8
  208. };
  209. static inline int ib_width_enum_to_int(enum ib_port_width width)
  210. {
  211. switch (width) {
  212. case IB_WIDTH_1X: return 1;
  213. case IB_WIDTH_4X: return 4;
  214. case IB_WIDTH_8X: return 8;
  215. case IB_WIDTH_12X: return 12;
  216. default: return -1;
  217. }
  218. }
  219. struct ib_protocol_stats {
  220. /* TBD... */
  221. };
  222. struct iw_protocol_stats {
  223. u64 ipInReceives;
  224. u64 ipInHdrErrors;
  225. u64 ipInTooBigErrors;
  226. u64 ipInNoRoutes;
  227. u64 ipInAddrErrors;
  228. u64 ipInUnknownProtos;
  229. u64 ipInTruncatedPkts;
  230. u64 ipInDiscards;
  231. u64 ipInDelivers;
  232. u64 ipOutForwDatagrams;
  233. u64 ipOutRequests;
  234. u64 ipOutDiscards;
  235. u64 ipOutNoRoutes;
  236. u64 ipReasmTimeout;
  237. u64 ipReasmReqds;
  238. u64 ipReasmOKs;
  239. u64 ipReasmFails;
  240. u64 ipFragOKs;
  241. u64 ipFragFails;
  242. u64 ipFragCreates;
  243. u64 ipInMcastPkts;
  244. u64 ipOutMcastPkts;
  245. u64 ipInBcastPkts;
  246. u64 ipOutBcastPkts;
  247. u64 tcpRtoAlgorithm;
  248. u64 tcpRtoMin;
  249. u64 tcpRtoMax;
  250. u64 tcpMaxConn;
  251. u64 tcpActiveOpens;
  252. u64 tcpPassiveOpens;
  253. u64 tcpAttemptFails;
  254. u64 tcpEstabResets;
  255. u64 tcpCurrEstab;
  256. u64 tcpInSegs;
  257. u64 tcpOutSegs;
  258. u64 tcpRetransSegs;
  259. u64 tcpInErrs;
  260. u64 tcpOutRsts;
  261. };
  262. union rdma_protocol_stats {
  263. struct ib_protocol_stats ib;
  264. struct iw_protocol_stats iw;
  265. };
  266. struct ib_port_attr {
  267. enum ib_port_state state;
  268. enum ib_mtu max_mtu;
  269. enum ib_mtu active_mtu;
  270. int gid_tbl_len;
  271. u32 port_cap_flags;
  272. u32 max_msg_sz;
  273. u32 bad_pkey_cntr;
  274. u32 qkey_viol_cntr;
  275. u16 pkey_tbl_len;
  276. u16 lid;
  277. u16 sm_lid;
  278. u8 lmc;
  279. u8 max_vl_num;
  280. u8 sm_sl;
  281. u8 subnet_timeout;
  282. u8 init_type_reply;
  283. u8 active_width;
  284. u8 active_speed;
  285. u8 phys_state;
  286. };
  287. enum ib_device_modify_flags {
  288. IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
  289. IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
  290. };
  291. struct ib_device_modify {
  292. u64 sys_image_guid;
  293. char node_desc[64];
  294. };
  295. enum ib_port_modify_flags {
  296. IB_PORT_SHUTDOWN = 1,
  297. IB_PORT_INIT_TYPE = (1<<2),
  298. IB_PORT_RESET_QKEY_CNTR = (1<<3)
  299. };
  300. struct ib_port_modify {
  301. u32 set_port_cap_mask;
  302. u32 clr_port_cap_mask;
  303. u8 init_type;
  304. };
  305. enum ib_event_type {
  306. IB_EVENT_CQ_ERR,
  307. IB_EVENT_QP_FATAL,
  308. IB_EVENT_QP_REQ_ERR,
  309. IB_EVENT_QP_ACCESS_ERR,
  310. IB_EVENT_COMM_EST,
  311. IB_EVENT_SQ_DRAINED,
  312. IB_EVENT_PATH_MIG,
  313. IB_EVENT_PATH_MIG_ERR,
  314. IB_EVENT_DEVICE_FATAL,
  315. IB_EVENT_PORT_ACTIVE,
  316. IB_EVENT_PORT_ERR,
  317. IB_EVENT_LID_CHANGE,
  318. IB_EVENT_PKEY_CHANGE,
  319. IB_EVENT_SM_CHANGE,
  320. IB_EVENT_SRQ_ERR,
  321. IB_EVENT_SRQ_LIMIT_REACHED,
  322. IB_EVENT_QP_LAST_WQE_REACHED,
  323. IB_EVENT_CLIENT_REREGISTER
  324. };
  325. struct ib_event {
  326. struct ib_device *device;
  327. union {
  328. struct ib_cq *cq;
  329. struct ib_qp *qp;
  330. struct ib_srq *srq;
  331. u8 port_num;
  332. } element;
  333. enum ib_event_type event;
  334. };
  335. struct ib_event_handler {
  336. struct ib_device *device;
  337. void (*handler)(struct ib_event_handler *, struct ib_event *);
  338. struct list_head list;
  339. };
  340. #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
  341. do { \
  342. (_ptr)->device = _device; \
  343. (_ptr)->handler = _handler; \
  344. INIT_LIST_HEAD(&(_ptr)->list); \
  345. } while (0)
  346. struct ib_global_route {
  347. union ib_gid dgid;
  348. u32 flow_label;
  349. u8 sgid_index;
  350. u8 hop_limit;
  351. u8 traffic_class;
  352. };
  353. struct ib_grh {
  354. __be32 version_tclass_flow;
  355. __be16 paylen;
  356. u8 next_hdr;
  357. u8 hop_limit;
  358. union ib_gid sgid;
  359. union ib_gid dgid;
  360. };
  361. enum {
  362. IB_MULTICAST_QPN = 0xffffff
  363. };
  364. #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
  365. enum ib_ah_flags {
  366. IB_AH_GRH = 1
  367. };
  368. enum ib_rate {
  369. IB_RATE_PORT_CURRENT = 0,
  370. IB_RATE_2_5_GBPS = 2,
  371. IB_RATE_5_GBPS = 5,
  372. IB_RATE_10_GBPS = 3,
  373. IB_RATE_20_GBPS = 6,
  374. IB_RATE_30_GBPS = 4,
  375. IB_RATE_40_GBPS = 7,
  376. IB_RATE_60_GBPS = 8,
  377. IB_RATE_80_GBPS = 9,
  378. IB_RATE_120_GBPS = 10
  379. };
  380. /**
  381. * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
  382. * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
  383. * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
  384. * @rate: rate to convert.
  385. */
  386. int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
  387. /**
  388. * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
  389. * enum.
  390. * @mult: multiple to convert.
  391. */
  392. enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
  393. struct ib_ah_attr {
  394. struct ib_global_route grh;
  395. u16 dlid;
  396. u8 sl;
  397. u8 src_path_bits;
  398. u8 static_rate;
  399. u8 ah_flags;
  400. u8 port_num;
  401. };
  402. enum ib_wc_status {
  403. IB_WC_SUCCESS,
  404. IB_WC_LOC_LEN_ERR,
  405. IB_WC_LOC_QP_OP_ERR,
  406. IB_WC_LOC_EEC_OP_ERR,
  407. IB_WC_LOC_PROT_ERR,
  408. IB_WC_WR_FLUSH_ERR,
  409. IB_WC_MW_BIND_ERR,
  410. IB_WC_BAD_RESP_ERR,
  411. IB_WC_LOC_ACCESS_ERR,
  412. IB_WC_REM_INV_REQ_ERR,
  413. IB_WC_REM_ACCESS_ERR,
  414. IB_WC_REM_OP_ERR,
  415. IB_WC_RETRY_EXC_ERR,
  416. IB_WC_RNR_RETRY_EXC_ERR,
  417. IB_WC_LOC_RDD_VIOL_ERR,
  418. IB_WC_REM_INV_RD_REQ_ERR,
  419. IB_WC_REM_ABORT_ERR,
  420. IB_WC_INV_EECN_ERR,
  421. IB_WC_INV_EEC_STATE_ERR,
  422. IB_WC_FATAL_ERR,
  423. IB_WC_RESP_TIMEOUT_ERR,
  424. IB_WC_GENERAL_ERR
  425. };
  426. enum ib_wc_opcode {
  427. IB_WC_SEND,
  428. IB_WC_RDMA_WRITE,
  429. IB_WC_RDMA_READ,
  430. IB_WC_COMP_SWAP,
  431. IB_WC_FETCH_ADD,
  432. IB_WC_BIND_MW,
  433. IB_WC_LSO,
  434. IB_WC_LOCAL_INV,
  435. IB_WC_FAST_REG_MR,
  436. IB_WC_MASKED_COMP_SWAP,
  437. IB_WC_MASKED_FETCH_ADD,
  438. /*
  439. * Set value of IB_WC_RECV so consumers can test if a completion is a
  440. * receive by testing (opcode & IB_WC_RECV).
  441. */
  442. IB_WC_RECV = 1 << 7,
  443. IB_WC_RECV_RDMA_WITH_IMM
  444. };
  445. enum ib_wc_flags {
  446. IB_WC_GRH = 1,
  447. IB_WC_WITH_IMM = (1<<1),
  448. IB_WC_WITH_INVALIDATE = (1<<2),
  449. };
  450. struct ib_wc {
  451. u64 wr_id;
  452. enum ib_wc_status status;
  453. enum ib_wc_opcode opcode;
  454. u32 vendor_err;
  455. u32 byte_len;
  456. struct ib_qp *qp;
  457. union {
  458. __be32 imm_data;
  459. u32 invalidate_rkey;
  460. } ex;
  461. u32 src_qp;
  462. int wc_flags;
  463. u16 pkey_index;
  464. u16 slid;
  465. u8 sl;
  466. u8 dlid_path_bits;
  467. u8 port_num; /* valid only for DR SMPs on switches */
  468. int csum_ok;
  469. };
  470. enum ib_cq_notify_flags {
  471. IB_CQ_SOLICITED = 1 << 0,
  472. IB_CQ_NEXT_COMP = 1 << 1,
  473. IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
  474. IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
  475. };
  476. enum ib_srq_attr_mask {
  477. IB_SRQ_MAX_WR = 1 << 0,
  478. IB_SRQ_LIMIT = 1 << 1,
  479. };
  480. struct ib_srq_attr {
  481. u32 max_wr;
  482. u32 max_sge;
  483. u32 srq_limit;
  484. };
  485. struct ib_srq_init_attr {
  486. void (*event_handler)(struct ib_event *, void *);
  487. void *srq_context;
  488. struct ib_srq_attr attr;
  489. };
  490. struct ib_qp_cap {
  491. u32 max_send_wr;
  492. u32 max_recv_wr;
  493. u32 max_send_sge;
  494. u32 max_recv_sge;
  495. u32 max_inline_data;
  496. };
  497. enum ib_sig_type {
  498. IB_SIGNAL_ALL_WR,
  499. IB_SIGNAL_REQ_WR
  500. };
  501. enum ib_qp_type {
  502. /*
  503. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  504. * here (and in that order) since the MAD layer uses them as
  505. * indices into a 2-entry table.
  506. */
  507. IB_QPT_SMI,
  508. IB_QPT_GSI,
  509. IB_QPT_RC,
  510. IB_QPT_UC,
  511. IB_QPT_UD,
  512. IB_QPT_RAW_IPV6,
  513. IB_QPT_RAW_ETHERTYPE
  514. };
  515. enum ib_qp_create_flags {
  516. IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
  517. IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
  518. };
  519. struct ib_qp_init_attr {
  520. void (*event_handler)(struct ib_event *, void *);
  521. void *qp_context;
  522. struct ib_cq *send_cq;
  523. struct ib_cq *recv_cq;
  524. struct ib_srq *srq;
  525. struct ib_qp_cap cap;
  526. enum ib_sig_type sq_sig_type;
  527. enum ib_qp_type qp_type;
  528. enum ib_qp_create_flags create_flags;
  529. u8 port_num; /* special QP types only */
  530. };
  531. enum ib_rnr_timeout {
  532. IB_RNR_TIMER_655_36 = 0,
  533. IB_RNR_TIMER_000_01 = 1,
  534. IB_RNR_TIMER_000_02 = 2,
  535. IB_RNR_TIMER_000_03 = 3,
  536. IB_RNR_TIMER_000_04 = 4,
  537. IB_RNR_TIMER_000_06 = 5,
  538. IB_RNR_TIMER_000_08 = 6,
  539. IB_RNR_TIMER_000_12 = 7,
  540. IB_RNR_TIMER_000_16 = 8,
  541. IB_RNR_TIMER_000_24 = 9,
  542. IB_RNR_TIMER_000_32 = 10,
  543. IB_RNR_TIMER_000_48 = 11,
  544. IB_RNR_TIMER_000_64 = 12,
  545. IB_RNR_TIMER_000_96 = 13,
  546. IB_RNR_TIMER_001_28 = 14,
  547. IB_RNR_TIMER_001_92 = 15,
  548. IB_RNR_TIMER_002_56 = 16,
  549. IB_RNR_TIMER_003_84 = 17,
  550. IB_RNR_TIMER_005_12 = 18,
  551. IB_RNR_TIMER_007_68 = 19,
  552. IB_RNR_TIMER_010_24 = 20,
  553. IB_RNR_TIMER_015_36 = 21,
  554. IB_RNR_TIMER_020_48 = 22,
  555. IB_RNR_TIMER_030_72 = 23,
  556. IB_RNR_TIMER_040_96 = 24,
  557. IB_RNR_TIMER_061_44 = 25,
  558. IB_RNR_TIMER_081_92 = 26,
  559. IB_RNR_TIMER_122_88 = 27,
  560. IB_RNR_TIMER_163_84 = 28,
  561. IB_RNR_TIMER_245_76 = 29,
  562. IB_RNR_TIMER_327_68 = 30,
  563. IB_RNR_TIMER_491_52 = 31
  564. };
  565. enum ib_qp_attr_mask {
  566. IB_QP_STATE = 1,
  567. IB_QP_CUR_STATE = (1<<1),
  568. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  569. IB_QP_ACCESS_FLAGS = (1<<3),
  570. IB_QP_PKEY_INDEX = (1<<4),
  571. IB_QP_PORT = (1<<5),
  572. IB_QP_QKEY = (1<<6),
  573. IB_QP_AV = (1<<7),
  574. IB_QP_PATH_MTU = (1<<8),
  575. IB_QP_TIMEOUT = (1<<9),
  576. IB_QP_RETRY_CNT = (1<<10),
  577. IB_QP_RNR_RETRY = (1<<11),
  578. IB_QP_RQ_PSN = (1<<12),
  579. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  580. IB_QP_ALT_PATH = (1<<14),
  581. IB_QP_MIN_RNR_TIMER = (1<<15),
  582. IB_QP_SQ_PSN = (1<<16),
  583. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  584. IB_QP_PATH_MIG_STATE = (1<<18),
  585. IB_QP_CAP = (1<<19),
  586. IB_QP_DEST_QPN = (1<<20)
  587. };
  588. enum ib_qp_state {
  589. IB_QPS_RESET,
  590. IB_QPS_INIT,
  591. IB_QPS_RTR,
  592. IB_QPS_RTS,
  593. IB_QPS_SQD,
  594. IB_QPS_SQE,
  595. IB_QPS_ERR
  596. };
  597. enum ib_mig_state {
  598. IB_MIG_MIGRATED,
  599. IB_MIG_REARM,
  600. IB_MIG_ARMED
  601. };
  602. struct ib_qp_attr {
  603. enum ib_qp_state qp_state;
  604. enum ib_qp_state cur_qp_state;
  605. enum ib_mtu path_mtu;
  606. enum ib_mig_state path_mig_state;
  607. u32 qkey;
  608. u32 rq_psn;
  609. u32 sq_psn;
  610. u32 dest_qp_num;
  611. int qp_access_flags;
  612. struct ib_qp_cap cap;
  613. struct ib_ah_attr ah_attr;
  614. struct ib_ah_attr alt_ah_attr;
  615. u16 pkey_index;
  616. u16 alt_pkey_index;
  617. u8 en_sqd_async_notify;
  618. u8 sq_draining;
  619. u8 max_rd_atomic;
  620. u8 max_dest_rd_atomic;
  621. u8 min_rnr_timer;
  622. u8 port_num;
  623. u8 timeout;
  624. u8 retry_cnt;
  625. u8 rnr_retry;
  626. u8 alt_port_num;
  627. u8 alt_timeout;
  628. };
  629. enum ib_wr_opcode {
  630. IB_WR_RDMA_WRITE,
  631. IB_WR_RDMA_WRITE_WITH_IMM,
  632. IB_WR_SEND,
  633. IB_WR_SEND_WITH_IMM,
  634. IB_WR_RDMA_READ,
  635. IB_WR_ATOMIC_CMP_AND_SWP,
  636. IB_WR_ATOMIC_FETCH_AND_ADD,
  637. IB_WR_LSO,
  638. IB_WR_SEND_WITH_INV,
  639. IB_WR_RDMA_READ_WITH_INV,
  640. IB_WR_LOCAL_INV,
  641. IB_WR_FAST_REG_MR,
  642. IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
  643. IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
  644. };
  645. enum ib_send_flags {
  646. IB_SEND_FENCE = 1,
  647. IB_SEND_SIGNALED = (1<<1),
  648. IB_SEND_SOLICITED = (1<<2),
  649. IB_SEND_INLINE = (1<<3),
  650. IB_SEND_IP_CSUM = (1<<4)
  651. };
  652. struct ib_sge {
  653. u64 addr;
  654. u32 length;
  655. u32 lkey;
  656. };
  657. struct ib_fast_reg_page_list {
  658. struct ib_device *device;
  659. u64 *page_list;
  660. unsigned int max_page_list_len;
  661. };
  662. struct ib_send_wr {
  663. struct ib_send_wr *next;
  664. u64 wr_id;
  665. struct ib_sge *sg_list;
  666. int num_sge;
  667. enum ib_wr_opcode opcode;
  668. int send_flags;
  669. union {
  670. __be32 imm_data;
  671. u32 invalidate_rkey;
  672. } ex;
  673. union {
  674. struct {
  675. u64 remote_addr;
  676. u32 rkey;
  677. } rdma;
  678. struct {
  679. u64 remote_addr;
  680. u64 compare_add;
  681. u64 swap;
  682. u64 compare_add_mask;
  683. u64 swap_mask;
  684. u32 rkey;
  685. } atomic;
  686. struct {
  687. struct ib_ah *ah;
  688. void *header;
  689. int hlen;
  690. int mss;
  691. u32 remote_qpn;
  692. u32 remote_qkey;
  693. u16 pkey_index; /* valid for GSI only */
  694. u8 port_num; /* valid for DR SMPs on switch only */
  695. } ud;
  696. struct {
  697. u64 iova_start;
  698. struct ib_fast_reg_page_list *page_list;
  699. unsigned int page_shift;
  700. unsigned int page_list_len;
  701. u32 length;
  702. int access_flags;
  703. u32 rkey;
  704. } fast_reg;
  705. } wr;
  706. };
  707. struct ib_recv_wr {
  708. struct ib_recv_wr *next;
  709. u64 wr_id;
  710. struct ib_sge *sg_list;
  711. int num_sge;
  712. };
  713. enum ib_access_flags {
  714. IB_ACCESS_LOCAL_WRITE = 1,
  715. IB_ACCESS_REMOTE_WRITE = (1<<1),
  716. IB_ACCESS_REMOTE_READ = (1<<2),
  717. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  718. IB_ACCESS_MW_BIND = (1<<4)
  719. };
  720. struct ib_phys_buf {
  721. u64 addr;
  722. u64 size;
  723. };
  724. struct ib_mr_attr {
  725. struct ib_pd *pd;
  726. u64 device_virt_addr;
  727. u64 size;
  728. int mr_access_flags;
  729. u32 lkey;
  730. u32 rkey;
  731. };
  732. enum ib_mr_rereg_flags {
  733. IB_MR_REREG_TRANS = 1,
  734. IB_MR_REREG_PD = (1<<1),
  735. IB_MR_REREG_ACCESS = (1<<2)
  736. };
  737. struct ib_mw_bind {
  738. struct ib_mr *mr;
  739. u64 wr_id;
  740. u64 addr;
  741. u32 length;
  742. int send_flags;
  743. int mw_access_flags;
  744. };
  745. struct ib_fmr_attr {
  746. int max_pages;
  747. int max_maps;
  748. u8 page_shift;
  749. };
  750. struct ib_ucontext {
  751. struct ib_device *device;
  752. struct list_head pd_list;
  753. struct list_head mr_list;
  754. struct list_head mw_list;
  755. struct list_head cq_list;
  756. struct list_head qp_list;
  757. struct list_head srq_list;
  758. struct list_head ah_list;
  759. int closing;
  760. };
  761. struct ib_uobject {
  762. u64 user_handle; /* handle given to us by userspace */
  763. struct ib_ucontext *context; /* associated user context */
  764. void *object; /* containing object */
  765. struct list_head list; /* link to context's list */
  766. int id; /* index into kernel idr */
  767. struct kref ref;
  768. struct rw_semaphore mutex; /* protects .live */
  769. int live;
  770. };
  771. struct ib_udata {
  772. void __user *inbuf;
  773. void __user *outbuf;
  774. size_t inlen;
  775. size_t outlen;
  776. };
  777. struct ib_pd {
  778. struct ib_device *device;
  779. struct ib_uobject *uobject;
  780. atomic_t usecnt; /* count all resources */
  781. };
  782. struct ib_ah {
  783. struct ib_device *device;
  784. struct ib_pd *pd;
  785. struct ib_uobject *uobject;
  786. };
  787. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  788. struct ib_cq {
  789. struct ib_device *device;
  790. struct ib_uobject *uobject;
  791. ib_comp_handler comp_handler;
  792. void (*event_handler)(struct ib_event *, void *);
  793. void *cq_context;
  794. int cqe;
  795. atomic_t usecnt; /* count number of work queues */
  796. };
  797. struct ib_srq {
  798. struct ib_device *device;
  799. struct ib_pd *pd;
  800. struct ib_uobject *uobject;
  801. void (*event_handler)(struct ib_event *, void *);
  802. void *srq_context;
  803. atomic_t usecnt;
  804. };
  805. struct ib_qp {
  806. struct ib_device *device;
  807. struct ib_pd *pd;
  808. struct ib_cq *send_cq;
  809. struct ib_cq *recv_cq;
  810. struct ib_srq *srq;
  811. struct ib_uobject *uobject;
  812. void (*event_handler)(struct ib_event *, void *);
  813. void *qp_context;
  814. u32 qp_num;
  815. enum ib_qp_type qp_type;
  816. };
  817. struct ib_mr {
  818. struct ib_device *device;
  819. struct ib_pd *pd;
  820. struct ib_uobject *uobject;
  821. u32 lkey;
  822. u32 rkey;
  823. atomic_t usecnt; /* count number of MWs */
  824. };
  825. struct ib_mw {
  826. struct ib_device *device;
  827. struct ib_pd *pd;
  828. struct ib_uobject *uobject;
  829. u32 rkey;
  830. };
  831. struct ib_fmr {
  832. struct ib_device *device;
  833. struct ib_pd *pd;
  834. struct list_head list;
  835. u32 lkey;
  836. u32 rkey;
  837. };
  838. struct ib_mad;
  839. struct ib_grh;
  840. enum ib_process_mad_flags {
  841. IB_MAD_IGNORE_MKEY = 1,
  842. IB_MAD_IGNORE_BKEY = 2,
  843. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  844. };
  845. enum ib_mad_result {
  846. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  847. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  848. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  849. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  850. };
  851. #define IB_DEVICE_NAME_MAX 64
  852. struct ib_cache {
  853. rwlock_t lock;
  854. struct ib_event_handler event_handler;
  855. struct ib_pkey_cache **pkey_cache;
  856. struct ib_gid_cache **gid_cache;
  857. u8 *lmc_cache;
  858. };
  859. struct ib_dma_mapping_ops {
  860. int (*mapping_error)(struct ib_device *dev,
  861. u64 dma_addr);
  862. u64 (*map_single)(struct ib_device *dev,
  863. void *ptr, size_t size,
  864. enum dma_data_direction direction);
  865. void (*unmap_single)(struct ib_device *dev,
  866. u64 addr, size_t size,
  867. enum dma_data_direction direction);
  868. u64 (*map_page)(struct ib_device *dev,
  869. struct page *page, unsigned long offset,
  870. size_t size,
  871. enum dma_data_direction direction);
  872. void (*unmap_page)(struct ib_device *dev,
  873. u64 addr, size_t size,
  874. enum dma_data_direction direction);
  875. int (*map_sg)(struct ib_device *dev,
  876. struct scatterlist *sg, int nents,
  877. enum dma_data_direction direction);
  878. void (*unmap_sg)(struct ib_device *dev,
  879. struct scatterlist *sg, int nents,
  880. enum dma_data_direction direction);
  881. u64 (*dma_address)(struct ib_device *dev,
  882. struct scatterlist *sg);
  883. unsigned int (*dma_len)(struct ib_device *dev,
  884. struct scatterlist *sg);
  885. void (*sync_single_for_cpu)(struct ib_device *dev,
  886. u64 dma_handle,
  887. size_t size,
  888. enum dma_data_direction dir);
  889. void (*sync_single_for_device)(struct ib_device *dev,
  890. u64 dma_handle,
  891. size_t size,
  892. enum dma_data_direction dir);
  893. void *(*alloc_coherent)(struct ib_device *dev,
  894. size_t size,
  895. u64 *dma_handle,
  896. gfp_t flag);
  897. void (*free_coherent)(struct ib_device *dev,
  898. size_t size, void *cpu_addr,
  899. u64 dma_handle);
  900. };
  901. struct iw_cm_verbs;
  902. struct ib_device {
  903. struct device *dma_device;
  904. char name[IB_DEVICE_NAME_MAX];
  905. struct list_head event_handler_list;
  906. spinlock_t event_handler_lock;
  907. spinlock_t client_data_lock;
  908. struct list_head core_list;
  909. struct list_head client_data_list;
  910. struct ib_cache cache;
  911. int *pkey_tbl_len;
  912. int *gid_tbl_len;
  913. int num_comp_vectors;
  914. struct iw_cm_verbs *iwcm;
  915. int (*get_protocol_stats)(struct ib_device *device,
  916. union rdma_protocol_stats *stats);
  917. int (*query_device)(struct ib_device *device,
  918. struct ib_device_attr *device_attr);
  919. int (*query_port)(struct ib_device *device,
  920. u8 port_num,
  921. struct ib_port_attr *port_attr);
  922. enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
  923. u8 port_num);
  924. int (*query_gid)(struct ib_device *device,
  925. u8 port_num, int index,
  926. union ib_gid *gid);
  927. int (*query_pkey)(struct ib_device *device,
  928. u8 port_num, u16 index, u16 *pkey);
  929. int (*modify_device)(struct ib_device *device,
  930. int device_modify_mask,
  931. struct ib_device_modify *device_modify);
  932. int (*modify_port)(struct ib_device *device,
  933. u8 port_num, int port_modify_mask,
  934. struct ib_port_modify *port_modify);
  935. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  936. struct ib_udata *udata);
  937. int (*dealloc_ucontext)(struct ib_ucontext *context);
  938. int (*mmap)(struct ib_ucontext *context,
  939. struct vm_area_struct *vma);
  940. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  941. struct ib_ucontext *context,
  942. struct ib_udata *udata);
  943. int (*dealloc_pd)(struct ib_pd *pd);
  944. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  945. struct ib_ah_attr *ah_attr);
  946. int (*modify_ah)(struct ib_ah *ah,
  947. struct ib_ah_attr *ah_attr);
  948. int (*query_ah)(struct ib_ah *ah,
  949. struct ib_ah_attr *ah_attr);
  950. int (*destroy_ah)(struct ib_ah *ah);
  951. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  952. struct ib_srq_init_attr *srq_init_attr,
  953. struct ib_udata *udata);
  954. int (*modify_srq)(struct ib_srq *srq,
  955. struct ib_srq_attr *srq_attr,
  956. enum ib_srq_attr_mask srq_attr_mask,
  957. struct ib_udata *udata);
  958. int (*query_srq)(struct ib_srq *srq,
  959. struct ib_srq_attr *srq_attr);
  960. int (*destroy_srq)(struct ib_srq *srq);
  961. int (*post_srq_recv)(struct ib_srq *srq,
  962. struct ib_recv_wr *recv_wr,
  963. struct ib_recv_wr **bad_recv_wr);
  964. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  965. struct ib_qp_init_attr *qp_init_attr,
  966. struct ib_udata *udata);
  967. int (*modify_qp)(struct ib_qp *qp,
  968. struct ib_qp_attr *qp_attr,
  969. int qp_attr_mask,
  970. struct ib_udata *udata);
  971. int (*query_qp)(struct ib_qp *qp,
  972. struct ib_qp_attr *qp_attr,
  973. int qp_attr_mask,
  974. struct ib_qp_init_attr *qp_init_attr);
  975. int (*destroy_qp)(struct ib_qp *qp);
  976. int (*post_send)(struct ib_qp *qp,
  977. struct ib_send_wr *send_wr,
  978. struct ib_send_wr **bad_send_wr);
  979. int (*post_recv)(struct ib_qp *qp,
  980. struct ib_recv_wr *recv_wr,
  981. struct ib_recv_wr **bad_recv_wr);
  982. struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
  983. int comp_vector,
  984. struct ib_ucontext *context,
  985. struct ib_udata *udata);
  986. int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
  987. u16 cq_period);
  988. int (*destroy_cq)(struct ib_cq *cq);
  989. int (*resize_cq)(struct ib_cq *cq, int cqe,
  990. struct ib_udata *udata);
  991. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  992. struct ib_wc *wc);
  993. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  994. int (*req_notify_cq)(struct ib_cq *cq,
  995. enum ib_cq_notify_flags flags);
  996. int (*req_ncomp_notif)(struct ib_cq *cq,
  997. int wc_cnt);
  998. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  999. int mr_access_flags);
  1000. struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
  1001. struct ib_phys_buf *phys_buf_array,
  1002. int num_phys_buf,
  1003. int mr_access_flags,
  1004. u64 *iova_start);
  1005. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  1006. u64 start, u64 length,
  1007. u64 virt_addr,
  1008. int mr_access_flags,
  1009. struct ib_udata *udata);
  1010. int (*query_mr)(struct ib_mr *mr,
  1011. struct ib_mr_attr *mr_attr);
  1012. int (*dereg_mr)(struct ib_mr *mr);
  1013. struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
  1014. int max_page_list_len);
  1015. struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
  1016. int page_list_len);
  1017. void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
  1018. int (*rereg_phys_mr)(struct ib_mr *mr,
  1019. int mr_rereg_mask,
  1020. struct ib_pd *pd,
  1021. struct ib_phys_buf *phys_buf_array,
  1022. int num_phys_buf,
  1023. int mr_access_flags,
  1024. u64 *iova_start);
  1025. struct ib_mw * (*alloc_mw)(struct ib_pd *pd);
  1026. int (*bind_mw)(struct ib_qp *qp,
  1027. struct ib_mw *mw,
  1028. struct ib_mw_bind *mw_bind);
  1029. int (*dealloc_mw)(struct ib_mw *mw);
  1030. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  1031. int mr_access_flags,
  1032. struct ib_fmr_attr *fmr_attr);
  1033. int (*map_phys_fmr)(struct ib_fmr *fmr,
  1034. u64 *page_list, int list_len,
  1035. u64 iova);
  1036. int (*unmap_fmr)(struct list_head *fmr_list);
  1037. int (*dealloc_fmr)(struct ib_fmr *fmr);
  1038. int (*attach_mcast)(struct ib_qp *qp,
  1039. union ib_gid *gid,
  1040. u16 lid);
  1041. int (*detach_mcast)(struct ib_qp *qp,
  1042. union ib_gid *gid,
  1043. u16 lid);
  1044. int (*process_mad)(struct ib_device *device,
  1045. int process_mad_flags,
  1046. u8 port_num,
  1047. struct ib_wc *in_wc,
  1048. struct ib_grh *in_grh,
  1049. struct ib_mad *in_mad,
  1050. struct ib_mad *out_mad);
  1051. struct ib_dma_mapping_ops *dma_ops;
  1052. struct module *owner;
  1053. struct device dev;
  1054. struct kobject *ports_parent;
  1055. struct list_head port_list;
  1056. enum {
  1057. IB_DEV_UNINITIALIZED,
  1058. IB_DEV_REGISTERED,
  1059. IB_DEV_UNREGISTERED
  1060. } reg_state;
  1061. int uverbs_abi_ver;
  1062. u64 uverbs_cmd_mask;
  1063. char node_desc[64];
  1064. __be64 node_guid;
  1065. u32 local_dma_lkey;
  1066. u8 node_type;
  1067. u8 phys_port_cnt;
  1068. };
  1069. struct ib_client {
  1070. char *name;
  1071. void (*add) (struct ib_device *);
  1072. void (*remove)(struct ib_device *);
  1073. struct list_head list;
  1074. };
  1075. struct ib_device *ib_alloc_device(size_t size);
  1076. void ib_dealloc_device(struct ib_device *device);
  1077. int ib_register_device(struct ib_device *device,
  1078. int (*port_callback)(struct ib_device *,
  1079. u8, struct kobject *));
  1080. void ib_unregister_device(struct ib_device *device);
  1081. int ib_register_client (struct ib_client *client);
  1082. void ib_unregister_client(struct ib_client *client);
  1083. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  1084. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  1085. void *data);
  1086. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  1087. {
  1088. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  1089. }
  1090. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  1091. {
  1092. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  1093. }
  1094. /**
  1095. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  1096. * contains all required attributes and no attributes not allowed for
  1097. * the given QP state transition.
  1098. * @cur_state: Current QP state
  1099. * @next_state: Next QP state
  1100. * @type: QP type
  1101. * @mask: Mask of supplied QP attributes
  1102. *
  1103. * This function is a helper function that a low-level driver's
  1104. * modify_qp method can use to validate the consumer's input. It
  1105. * checks that cur_state and next_state are valid QP states, that a
  1106. * transition from cur_state to next_state is allowed by the IB spec,
  1107. * and that the attribute mask supplied is allowed for the transition.
  1108. */
  1109. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  1110. enum ib_qp_type type, enum ib_qp_attr_mask mask);
  1111. int ib_register_event_handler (struct ib_event_handler *event_handler);
  1112. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  1113. void ib_dispatch_event(struct ib_event *event);
  1114. int ib_query_device(struct ib_device *device,
  1115. struct ib_device_attr *device_attr);
  1116. int ib_query_port(struct ib_device *device,
  1117. u8 port_num, struct ib_port_attr *port_attr);
  1118. enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
  1119. u8 port_num);
  1120. int ib_query_gid(struct ib_device *device,
  1121. u8 port_num, int index, union ib_gid *gid);
  1122. int ib_query_pkey(struct ib_device *device,
  1123. u8 port_num, u16 index, u16 *pkey);
  1124. int ib_modify_device(struct ib_device *device,
  1125. int device_modify_mask,
  1126. struct ib_device_modify *device_modify);
  1127. int ib_modify_port(struct ib_device *device,
  1128. u8 port_num, int port_modify_mask,
  1129. struct ib_port_modify *port_modify);
  1130. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  1131. u8 *port_num, u16 *index);
  1132. int ib_find_pkey(struct ib_device *device,
  1133. u8 port_num, u16 pkey, u16 *index);
  1134. /**
  1135. * ib_alloc_pd - Allocates an unused protection domain.
  1136. * @device: The device on which to allocate the protection domain.
  1137. *
  1138. * A protection domain object provides an association between QPs, shared
  1139. * receive queues, address handles, memory regions, and memory windows.
  1140. */
  1141. struct ib_pd *ib_alloc_pd(struct ib_device *device);
  1142. /**
  1143. * ib_dealloc_pd - Deallocates a protection domain.
  1144. * @pd: The protection domain to deallocate.
  1145. */
  1146. int ib_dealloc_pd(struct ib_pd *pd);
  1147. /**
  1148. * ib_create_ah - Creates an address handle for the given address vector.
  1149. * @pd: The protection domain associated with the address handle.
  1150. * @ah_attr: The attributes of the address vector.
  1151. *
  1152. * The address handle is used to reference a local or global destination
  1153. * in all UD QP post sends.
  1154. */
  1155. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  1156. /**
  1157. * ib_init_ah_from_wc - Initializes address handle attributes from a
  1158. * work completion.
  1159. * @device: Device on which the received message arrived.
  1160. * @port_num: Port on which the received message arrived.
  1161. * @wc: Work completion associated with the received message.
  1162. * @grh: References the received global route header. This parameter is
  1163. * ignored unless the work completion indicates that the GRH is valid.
  1164. * @ah_attr: Returned attributes that can be used when creating an address
  1165. * handle for replying to the message.
  1166. */
  1167. int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
  1168. struct ib_grh *grh, struct ib_ah_attr *ah_attr);
  1169. /**
  1170. * ib_create_ah_from_wc - Creates an address handle associated with the
  1171. * sender of the specified work completion.
  1172. * @pd: The protection domain associated with the address handle.
  1173. * @wc: Work completion information associated with a received message.
  1174. * @grh: References the received global route header. This parameter is
  1175. * ignored unless the work completion indicates that the GRH is valid.
  1176. * @port_num: The outbound port number to associate with the address.
  1177. *
  1178. * The address handle is used to reference a local or global destination
  1179. * in all UD QP post sends.
  1180. */
  1181. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
  1182. struct ib_grh *grh, u8 port_num);
  1183. /**
  1184. * ib_modify_ah - Modifies the address vector associated with an address
  1185. * handle.
  1186. * @ah: The address handle to modify.
  1187. * @ah_attr: The new address vector attributes to associate with the
  1188. * address handle.
  1189. */
  1190. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1191. /**
  1192. * ib_query_ah - Queries the address vector associated with an address
  1193. * handle.
  1194. * @ah: The address handle to query.
  1195. * @ah_attr: The address vector attributes associated with the address
  1196. * handle.
  1197. */
  1198. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1199. /**
  1200. * ib_destroy_ah - Destroys an address handle.
  1201. * @ah: The address handle to destroy.
  1202. */
  1203. int ib_destroy_ah(struct ib_ah *ah);
  1204. /**
  1205. * ib_create_srq - Creates a SRQ associated with the specified protection
  1206. * domain.
  1207. * @pd: The protection domain associated with the SRQ.
  1208. * @srq_init_attr: A list of initial attributes required to create the
  1209. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  1210. * the actual capabilities of the created SRQ.
  1211. *
  1212. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  1213. * requested size of the SRQ, and set to the actual values allocated
  1214. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  1215. * will always be at least as large as the requested values.
  1216. */
  1217. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  1218. struct ib_srq_init_attr *srq_init_attr);
  1219. /**
  1220. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  1221. * @srq: The SRQ to modify.
  1222. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  1223. * the current values of selected SRQ attributes are returned.
  1224. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  1225. * are being modified.
  1226. *
  1227. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  1228. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  1229. * the number of receives queued drops below the limit.
  1230. */
  1231. int ib_modify_srq(struct ib_srq *srq,
  1232. struct ib_srq_attr *srq_attr,
  1233. enum ib_srq_attr_mask srq_attr_mask);
  1234. /**
  1235. * ib_query_srq - Returns the attribute list and current values for the
  1236. * specified SRQ.
  1237. * @srq: The SRQ to query.
  1238. * @srq_attr: The attributes of the specified SRQ.
  1239. */
  1240. int ib_query_srq(struct ib_srq *srq,
  1241. struct ib_srq_attr *srq_attr);
  1242. /**
  1243. * ib_destroy_srq - Destroys the specified SRQ.
  1244. * @srq: The SRQ to destroy.
  1245. */
  1246. int ib_destroy_srq(struct ib_srq *srq);
  1247. /**
  1248. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  1249. * @srq: The SRQ to post the work request on.
  1250. * @recv_wr: A list of work requests to post on the receive queue.
  1251. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1252. * the work request that failed to be posted on the QP.
  1253. */
  1254. static inline int ib_post_srq_recv(struct ib_srq *srq,
  1255. struct ib_recv_wr *recv_wr,
  1256. struct ib_recv_wr **bad_recv_wr)
  1257. {
  1258. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  1259. }
  1260. /**
  1261. * ib_create_qp - Creates a QP associated with the specified protection
  1262. * domain.
  1263. * @pd: The protection domain associated with the QP.
  1264. * @qp_init_attr: A list of initial attributes required to create the
  1265. * QP. If QP creation succeeds, then the attributes are updated to
  1266. * the actual capabilities of the created QP.
  1267. */
  1268. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  1269. struct ib_qp_init_attr *qp_init_attr);
  1270. /**
  1271. * ib_modify_qp - Modifies the attributes for the specified QP and then
  1272. * transitions the QP to the given state.
  1273. * @qp: The QP to modify.
  1274. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  1275. * the current values of selected QP attributes are returned.
  1276. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  1277. * are being modified.
  1278. */
  1279. int ib_modify_qp(struct ib_qp *qp,
  1280. struct ib_qp_attr *qp_attr,
  1281. int qp_attr_mask);
  1282. /**
  1283. * ib_query_qp - Returns the attribute list and current values for the
  1284. * specified QP.
  1285. * @qp: The QP to query.
  1286. * @qp_attr: The attributes of the specified QP.
  1287. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  1288. * @qp_init_attr: Additional attributes of the selected QP.
  1289. *
  1290. * The qp_attr_mask may be used to limit the query to gathering only the
  1291. * selected attributes.
  1292. */
  1293. int ib_query_qp(struct ib_qp *qp,
  1294. struct ib_qp_attr *qp_attr,
  1295. int qp_attr_mask,
  1296. struct ib_qp_init_attr *qp_init_attr);
  1297. /**
  1298. * ib_destroy_qp - Destroys the specified QP.
  1299. * @qp: The QP to destroy.
  1300. */
  1301. int ib_destroy_qp(struct ib_qp *qp);
  1302. /**
  1303. * ib_post_send - Posts a list of work requests to the send queue of
  1304. * the specified QP.
  1305. * @qp: The QP to post the work request on.
  1306. * @send_wr: A list of work requests to post on the send queue.
  1307. * @bad_send_wr: On an immediate failure, this parameter will reference
  1308. * the work request that failed to be posted on the QP.
  1309. *
  1310. * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
  1311. * error is returned, the QP state shall not be affected,
  1312. * ib_post_send() will return an immediate error after queueing any
  1313. * earlier work requests in the list.
  1314. */
  1315. static inline int ib_post_send(struct ib_qp *qp,
  1316. struct ib_send_wr *send_wr,
  1317. struct ib_send_wr **bad_send_wr)
  1318. {
  1319. return qp->device->post_send(qp, send_wr, bad_send_wr);
  1320. }
  1321. /**
  1322. * ib_post_recv - Posts a list of work requests to the receive queue of
  1323. * the specified QP.
  1324. * @qp: The QP to post the work request on.
  1325. * @recv_wr: A list of work requests to post on the receive queue.
  1326. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1327. * the work request that failed to be posted on the QP.
  1328. */
  1329. static inline int ib_post_recv(struct ib_qp *qp,
  1330. struct ib_recv_wr *recv_wr,
  1331. struct ib_recv_wr **bad_recv_wr)
  1332. {
  1333. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  1334. }
  1335. /**
  1336. * ib_create_cq - Creates a CQ on the specified device.
  1337. * @device: The device on which to create the CQ.
  1338. * @comp_handler: A user-specified callback that is invoked when a
  1339. * completion event occurs on the CQ.
  1340. * @event_handler: A user-specified callback that is invoked when an
  1341. * asynchronous event not associated with a completion occurs on the CQ.
  1342. * @cq_context: Context associated with the CQ returned to the user via
  1343. * the associated completion and event handlers.
  1344. * @cqe: The minimum size of the CQ.
  1345. * @comp_vector - Completion vector used to signal completion events.
  1346. * Must be >= 0 and < context->num_comp_vectors.
  1347. *
  1348. * Users can examine the cq structure to determine the actual CQ size.
  1349. */
  1350. struct ib_cq *ib_create_cq(struct ib_device *device,
  1351. ib_comp_handler comp_handler,
  1352. void (*event_handler)(struct ib_event *, void *),
  1353. void *cq_context, int cqe, int comp_vector);
  1354. /**
  1355. * ib_resize_cq - Modifies the capacity of the CQ.
  1356. * @cq: The CQ to resize.
  1357. * @cqe: The minimum size of the CQ.
  1358. *
  1359. * Users can examine the cq structure to determine the actual CQ size.
  1360. */
  1361. int ib_resize_cq(struct ib_cq *cq, int cqe);
  1362. /**
  1363. * ib_modify_cq - Modifies moderation params of the CQ
  1364. * @cq: The CQ to modify.
  1365. * @cq_count: number of CQEs that will trigger an event
  1366. * @cq_period: max period of time in usec before triggering an event
  1367. *
  1368. */
  1369. int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  1370. /**
  1371. * ib_destroy_cq - Destroys the specified CQ.
  1372. * @cq: The CQ to destroy.
  1373. */
  1374. int ib_destroy_cq(struct ib_cq *cq);
  1375. /**
  1376. * ib_poll_cq - poll a CQ for completion(s)
  1377. * @cq:the CQ being polled
  1378. * @num_entries:maximum number of completions to return
  1379. * @wc:array of at least @num_entries &struct ib_wc where completions
  1380. * will be returned
  1381. *
  1382. * Poll a CQ for (possibly multiple) completions. If the return value
  1383. * is < 0, an error occurred. If the return value is >= 0, it is the
  1384. * number of completions returned. If the return value is
  1385. * non-negative and < num_entries, then the CQ was emptied.
  1386. */
  1387. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  1388. struct ib_wc *wc)
  1389. {
  1390. return cq->device->poll_cq(cq, num_entries, wc);
  1391. }
  1392. /**
  1393. * ib_peek_cq - Returns the number of unreaped completions currently
  1394. * on the specified CQ.
  1395. * @cq: The CQ to peek.
  1396. * @wc_cnt: A minimum number of unreaped completions to check for.
  1397. *
  1398. * If the number of unreaped completions is greater than or equal to wc_cnt,
  1399. * this function returns wc_cnt, otherwise, it returns the actual number of
  1400. * unreaped completions.
  1401. */
  1402. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  1403. /**
  1404. * ib_req_notify_cq - Request completion notification on a CQ.
  1405. * @cq: The CQ to generate an event for.
  1406. * @flags:
  1407. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  1408. * to request an event on the next solicited event or next work
  1409. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  1410. * may also be |ed in to request a hint about missed events, as
  1411. * described below.
  1412. *
  1413. * Return Value:
  1414. * < 0 means an error occurred while requesting notification
  1415. * == 0 means notification was requested successfully, and if
  1416. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  1417. * were missed and it is safe to wait for another event. In
  1418. * this case is it guaranteed that any work completions added
  1419. * to the CQ since the last CQ poll will trigger a completion
  1420. * notification event.
  1421. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  1422. * in. It means that the consumer must poll the CQ again to
  1423. * make sure it is empty to avoid missing an event because of a
  1424. * race between requesting notification and an entry being
  1425. * added to the CQ. This return value means it is possible
  1426. * (but not guaranteed) that a work completion has been added
  1427. * to the CQ since the last poll without triggering a
  1428. * completion notification event.
  1429. */
  1430. static inline int ib_req_notify_cq(struct ib_cq *cq,
  1431. enum ib_cq_notify_flags flags)
  1432. {
  1433. return cq->device->req_notify_cq(cq, flags);
  1434. }
  1435. /**
  1436. * ib_req_ncomp_notif - Request completion notification when there are
  1437. * at least the specified number of unreaped completions on the CQ.
  1438. * @cq: The CQ to generate an event for.
  1439. * @wc_cnt: The number of unreaped completions that should be on the
  1440. * CQ before an event is generated.
  1441. */
  1442. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  1443. {
  1444. return cq->device->req_ncomp_notif ?
  1445. cq->device->req_ncomp_notif(cq, wc_cnt) :
  1446. -ENOSYS;
  1447. }
  1448. /**
  1449. * ib_get_dma_mr - Returns a memory region for system memory that is
  1450. * usable for DMA.
  1451. * @pd: The protection domain associated with the memory region.
  1452. * @mr_access_flags: Specifies the memory access rights.
  1453. *
  1454. * Note that the ib_dma_*() functions defined below must be used
  1455. * to create/destroy addresses used with the Lkey or Rkey returned
  1456. * by ib_get_dma_mr().
  1457. */
  1458. struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
  1459. /**
  1460. * ib_dma_mapping_error - check a DMA addr for error
  1461. * @dev: The device for which the dma_addr was created
  1462. * @dma_addr: The DMA address to check
  1463. */
  1464. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  1465. {
  1466. if (dev->dma_ops)
  1467. return dev->dma_ops->mapping_error(dev, dma_addr);
  1468. return dma_mapping_error(dev->dma_device, dma_addr);
  1469. }
  1470. /**
  1471. * ib_dma_map_single - Map a kernel virtual address to DMA address
  1472. * @dev: The device for which the dma_addr is to be created
  1473. * @cpu_addr: The kernel virtual address
  1474. * @size: The size of the region in bytes
  1475. * @direction: The direction of the DMA
  1476. */
  1477. static inline u64 ib_dma_map_single(struct ib_device *dev,
  1478. void *cpu_addr, size_t size,
  1479. enum dma_data_direction direction)
  1480. {
  1481. if (dev->dma_ops)
  1482. return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
  1483. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  1484. }
  1485. /**
  1486. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  1487. * @dev: The device for which the DMA address was created
  1488. * @addr: The DMA address
  1489. * @size: The size of the region in bytes
  1490. * @direction: The direction of the DMA
  1491. */
  1492. static inline void ib_dma_unmap_single(struct ib_device *dev,
  1493. u64 addr, size_t size,
  1494. enum dma_data_direction direction)
  1495. {
  1496. if (dev->dma_ops)
  1497. dev->dma_ops->unmap_single(dev, addr, size, direction);
  1498. else
  1499. dma_unmap_single(dev->dma_device, addr, size, direction);
  1500. }
  1501. static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
  1502. void *cpu_addr, size_t size,
  1503. enum dma_data_direction direction,
  1504. struct dma_attrs *attrs)
  1505. {
  1506. return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
  1507. direction, attrs);
  1508. }
  1509. static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
  1510. u64 addr, size_t size,
  1511. enum dma_data_direction direction,
  1512. struct dma_attrs *attrs)
  1513. {
  1514. return dma_unmap_single_attrs(dev->dma_device, addr, size,
  1515. direction, attrs);
  1516. }
  1517. /**
  1518. * ib_dma_map_page - Map a physical page to DMA address
  1519. * @dev: The device for which the dma_addr is to be created
  1520. * @page: The page to be mapped
  1521. * @offset: The offset within the page
  1522. * @size: The size of the region in bytes
  1523. * @direction: The direction of the DMA
  1524. */
  1525. static inline u64 ib_dma_map_page(struct ib_device *dev,
  1526. struct page *page,
  1527. unsigned long offset,
  1528. size_t size,
  1529. enum dma_data_direction direction)
  1530. {
  1531. if (dev->dma_ops)
  1532. return dev->dma_ops->map_page(dev, page, offset, size, direction);
  1533. return dma_map_page(dev->dma_device, page, offset, size, direction);
  1534. }
  1535. /**
  1536. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  1537. * @dev: The device for which the DMA address was created
  1538. * @addr: The DMA address
  1539. * @size: The size of the region in bytes
  1540. * @direction: The direction of the DMA
  1541. */
  1542. static inline void ib_dma_unmap_page(struct ib_device *dev,
  1543. u64 addr, size_t size,
  1544. enum dma_data_direction direction)
  1545. {
  1546. if (dev->dma_ops)
  1547. dev->dma_ops->unmap_page(dev, addr, size, direction);
  1548. else
  1549. dma_unmap_page(dev->dma_device, addr, size, direction);
  1550. }
  1551. /**
  1552. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  1553. * @dev: The device for which the DMA addresses are to be created
  1554. * @sg: The array of scatter/gather entries
  1555. * @nents: The number of scatter/gather entries
  1556. * @direction: The direction of the DMA
  1557. */
  1558. static inline int ib_dma_map_sg(struct ib_device *dev,
  1559. struct scatterlist *sg, int nents,
  1560. enum dma_data_direction direction)
  1561. {
  1562. if (dev->dma_ops)
  1563. return dev->dma_ops->map_sg(dev, sg, nents, direction);
  1564. return dma_map_sg(dev->dma_device, sg, nents, direction);
  1565. }
  1566. /**
  1567. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  1568. * @dev: The device for which the DMA addresses were created
  1569. * @sg: The array of scatter/gather entries
  1570. * @nents: The number of scatter/gather entries
  1571. * @direction: The direction of the DMA
  1572. */
  1573. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  1574. struct scatterlist *sg, int nents,
  1575. enum dma_data_direction direction)
  1576. {
  1577. if (dev->dma_ops)
  1578. dev->dma_ops->unmap_sg(dev, sg, nents, direction);
  1579. else
  1580. dma_unmap_sg(dev->dma_device, sg, nents, direction);
  1581. }
  1582. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  1583. struct scatterlist *sg, int nents,
  1584. enum dma_data_direction direction,
  1585. struct dma_attrs *attrs)
  1586. {
  1587. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  1588. }
  1589. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  1590. struct scatterlist *sg, int nents,
  1591. enum dma_data_direction direction,
  1592. struct dma_attrs *attrs)
  1593. {
  1594. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  1595. }
  1596. /**
  1597. * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
  1598. * @dev: The device for which the DMA addresses were created
  1599. * @sg: The scatter/gather entry
  1600. */
  1601. static inline u64 ib_sg_dma_address(struct ib_device *dev,
  1602. struct scatterlist *sg)
  1603. {
  1604. if (dev->dma_ops)
  1605. return dev->dma_ops->dma_address(dev, sg);
  1606. return sg_dma_address(sg);
  1607. }
  1608. /**
  1609. * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
  1610. * @dev: The device for which the DMA addresses were created
  1611. * @sg: The scatter/gather entry
  1612. */
  1613. static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
  1614. struct scatterlist *sg)
  1615. {
  1616. if (dev->dma_ops)
  1617. return dev->dma_ops->dma_len(dev, sg);
  1618. return sg_dma_len(sg);
  1619. }
  1620. /**
  1621. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  1622. * @dev: The device for which the DMA address was created
  1623. * @addr: The DMA address
  1624. * @size: The size of the region in bytes
  1625. * @dir: The direction of the DMA
  1626. */
  1627. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  1628. u64 addr,
  1629. size_t size,
  1630. enum dma_data_direction dir)
  1631. {
  1632. if (dev->dma_ops)
  1633. dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
  1634. else
  1635. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  1636. }
  1637. /**
  1638. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  1639. * @dev: The device for which the DMA address was created
  1640. * @addr: The DMA address
  1641. * @size: The size of the region in bytes
  1642. * @dir: The direction of the DMA
  1643. */
  1644. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  1645. u64 addr,
  1646. size_t size,
  1647. enum dma_data_direction dir)
  1648. {
  1649. if (dev->dma_ops)
  1650. dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
  1651. else
  1652. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  1653. }
  1654. /**
  1655. * ib_dma_alloc_coherent - Allocate memory and map it for DMA
  1656. * @dev: The device for which the DMA address is requested
  1657. * @size: The size of the region to allocate in bytes
  1658. * @dma_handle: A pointer for returning the DMA address of the region
  1659. * @flag: memory allocator flags
  1660. */
  1661. static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
  1662. size_t size,
  1663. u64 *dma_handle,
  1664. gfp_t flag)
  1665. {
  1666. if (dev->dma_ops)
  1667. return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  1668. else {
  1669. dma_addr_t handle;
  1670. void *ret;
  1671. ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
  1672. *dma_handle = handle;
  1673. return ret;
  1674. }
  1675. }
  1676. /**
  1677. * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
  1678. * @dev: The device for which the DMA addresses were allocated
  1679. * @size: The size of the region
  1680. * @cpu_addr: the address returned by ib_dma_alloc_coherent()
  1681. * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
  1682. */
  1683. static inline void ib_dma_free_coherent(struct ib_device *dev,
  1684. size_t size, void *cpu_addr,
  1685. u64 dma_handle)
  1686. {
  1687. if (dev->dma_ops)
  1688. dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  1689. else
  1690. dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
  1691. }
  1692. /**
  1693. * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
  1694. * by an HCA.
  1695. * @pd: The protection domain associated assigned to the registered region.
  1696. * @phys_buf_array: Specifies a list of physical buffers to use in the
  1697. * memory region.
  1698. * @num_phys_buf: Specifies the size of the phys_buf_array.
  1699. * @mr_access_flags: Specifies the memory access rights.
  1700. * @iova_start: The offset of the region's starting I/O virtual address.
  1701. */
  1702. struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
  1703. struct ib_phys_buf *phys_buf_array,
  1704. int num_phys_buf,
  1705. int mr_access_flags,
  1706. u64 *iova_start);
  1707. /**
  1708. * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
  1709. * Conceptually, this call performs the functions deregister memory region
  1710. * followed by register physical memory region. Where possible,
  1711. * resources are reused instead of deallocated and reallocated.
  1712. * @mr: The memory region to modify.
  1713. * @mr_rereg_mask: A bit-mask used to indicate which of the following
  1714. * properties of the memory region are being modified.
  1715. * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
  1716. * the new protection domain to associated with the memory region,
  1717. * otherwise, this parameter is ignored.
  1718. * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1719. * field specifies a list of physical buffers to use in the new
  1720. * translation, otherwise, this parameter is ignored.
  1721. * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1722. * field specifies the size of the phys_buf_array, otherwise, this
  1723. * parameter is ignored.
  1724. * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
  1725. * field specifies the new memory access rights, otherwise, this
  1726. * parameter is ignored.
  1727. * @iova_start: The offset of the region's starting I/O virtual address.
  1728. */
  1729. int ib_rereg_phys_mr(struct ib_mr *mr,
  1730. int mr_rereg_mask,
  1731. struct ib_pd *pd,
  1732. struct ib_phys_buf *phys_buf_array,
  1733. int num_phys_buf,
  1734. int mr_access_flags,
  1735. u64 *iova_start);
  1736. /**
  1737. * ib_query_mr - Retrieves information about a specific memory region.
  1738. * @mr: The memory region to retrieve information about.
  1739. * @mr_attr: The attributes of the specified memory region.
  1740. */
  1741. int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
  1742. /**
  1743. * ib_dereg_mr - Deregisters a memory region and removes it from the
  1744. * HCA translation table.
  1745. * @mr: The memory region to deregister.
  1746. */
  1747. int ib_dereg_mr(struct ib_mr *mr);
  1748. /**
  1749. * ib_alloc_fast_reg_mr - Allocates memory region usable with the
  1750. * IB_WR_FAST_REG_MR send work request.
  1751. * @pd: The protection domain associated with the region.
  1752. * @max_page_list_len: requested max physical buffer list length to be
  1753. * used with fast register work requests for this MR.
  1754. */
  1755. struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
  1756. /**
  1757. * ib_alloc_fast_reg_page_list - Allocates a page list array
  1758. * @device - ib device pointer.
  1759. * @page_list_len - size of the page list array to be allocated.
  1760. *
  1761. * This allocates and returns a struct ib_fast_reg_page_list * and a
  1762. * page_list array that is at least page_list_len in size. The actual
  1763. * size is returned in max_page_list_len. The caller is responsible
  1764. * for initializing the contents of the page_list array before posting
  1765. * a send work request with the IB_WC_FAST_REG_MR opcode.
  1766. *
  1767. * The page_list array entries must be translated using one of the
  1768. * ib_dma_*() functions just like the addresses passed to
  1769. * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
  1770. * ib_fast_reg_page_list must not be modified by the caller until the
  1771. * IB_WC_FAST_REG_MR work request completes.
  1772. */
  1773. struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
  1774. struct ib_device *device, int page_list_len);
  1775. /**
  1776. * ib_free_fast_reg_page_list - Deallocates a previously allocated
  1777. * page list array.
  1778. * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
  1779. */
  1780. void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
  1781. /**
  1782. * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
  1783. * R_Key and L_Key.
  1784. * @mr - struct ib_mr pointer to be updated.
  1785. * @newkey - new key to be used.
  1786. */
  1787. static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
  1788. {
  1789. mr->lkey = (mr->lkey & 0xffffff00) | newkey;
  1790. mr->rkey = (mr->rkey & 0xffffff00) | newkey;
  1791. }
  1792. /**
  1793. * ib_alloc_mw - Allocates a memory window.
  1794. * @pd: The protection domain associated with the memory window.
  1795. */
  1796. struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
  1797. /**
  1798. * ib_bind_mw - Posts a work request to the send queue of the specified
  1799. * QP, which binds the memory window to the given address range and
  1800. * remote access attributes.
  1801. * @qp: QP to post the bind work request on.
  1802. * @mw: The memory window to bind.
  1803. * @mw_bind: Specifies information about the memory window, including
  1804. * its address range, remote access rights, and associated memory region.
  1805. */
  1806. static inline int ib_bind_mw(struct ib_qp *qp,
  1807. struct ib_mw *mw,
  1808. struct ib_mw_bind *mw_bind)
  1809. {
  1810. /* XXX reference counting in corresponding MR? */
  1811. return mw->device->bind_mw ?
  1812. mw->device->bind_mw(qp, mw, mw_bind) :
  1813. -ENOSYS;
  1814. }
  1815. /**
  1816. * ib_dealloc_mw - Deallocates a memory window.
  1817. * @mw: The memory window to deallocate.
  1818. */
  1819. int ib_dealloc_mw(struct ib_mw *mw);
  1820. /**
  1821. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  1822. * @pd: The protection domain associated with the unmapped region.
  1823. * @mr_access_flags: Specifies the memory access rights.
  1824. * @fmr_attr: Attributes of the unmapped region.
  1825. *
  1826. * A fast memory region must be mapped before it can be used as part of
  1827. * a work request.
  1828. */
  1829. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  1830. int mr_access_flags,
  1831. struct ib_fmr_attr *fmr_attr);
  1832. /**
  1833. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  1834. * @fmr: The fast memory region to associate with the pages.
  1835. * @page_list: An array of physical pages to map to the fast memory region.
  1836. * @list_len: The number of pages in page_list.
  1837. * @iova: The I/O virtual address to use with the mapped region.
  1838. */
  1839. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  1840. u64 *page_list, int list_len,
  1841. u64 iova)
  1842. {
  1843. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  1844. }
  1845. /**
  1846. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  1847. * @fmr_list: A linked list of fast memory regions to unmap.
  1848. */
  1849. int ib_unmap_fmr(struct list_head *fmr_list);
  1850. /**
  1851. * ib_dealloc_fmr - Deallocates a fast memory region.
  1852. * @fmr: The fast memory region to deallocate.
  1853. */
  1854. int ib_dealloc_fmr(struct ib_fmr *fmr);
  1855. /**
  1856. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  1857. * @qp: QP to attach to the multicast group. The QP must be type
  1858. * IB_QPT_UD.
  1859. * @gid: Multicast group GID.
  1860. * @lid: Multicast group LID in host byte order.
  1861. *
  1862. * In order to send and receive multicast packets, subnet
  1863. * administration must have created the multicast group and configured
  1864. * the fabric appropriately. The port associated with the specified
  1865. * QP must also be a member of the multicast group.
  1866. */
  1867. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1868. /**
  1869. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  1870. * @qp: QP to detach from the multicast group.
  1871. * @gid: Multicast group GID.
  1872. * @lid: Multicast group LID in host byte order.
  1873. */
  1874. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  1875. #endif /* IB_VERBS_H */