ib_verbs.h 59 KB

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