ib_verbs.h 68 KB

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