ib_verbs.h 69 KB

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