ib_verbs.h 68 KB

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