ib_verbs.h 64 KB

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