ib_verbs.h 79 KB

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