ib_verbs.h 74 KB

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