ib_verbs.h 62 KB

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