ib_verbs.h 60 KB

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