ib_verbs.h 88 KB

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