ib_verbs.h 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294
  1. /*
  2. * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
  4. * Copyright (c) 2004 Intel Corporation. All rights reserved.
  5. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  6. * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
  7. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  8. * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
  9. *
  10. * This software is available to you under a choice of one of two
  11. * licenses. You may choose to be licensed under the terms of the GNU
  12. * General Public License (GPL) Version 2, available from the file
  13. * COPYING in the main directory of this source tree, or the
  14. * OpenIB.org BSD license below:
  15. *
  16. * Redistribution and use in source and binary forms, with or
  17. * without modification, are permitted provided that the following
  18. * conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer.
  23. *
  24. * - Redistributions in binary form must reproduce the above
  25. * copyright notice, this list of conditions and the following
  26. * disclaimer in the documentation and/or other materials
  27. * provided with the distribution.
  28. *
  29. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  33. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  34. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  36. * SOFTWARE.
  37. */
  38. #if !defined(IB_VERBS_H)
  39. #define IB_VERBS_H
  40. #include <linux/types.h>
  41. #include <linux/device.h>
  42. #include <linux/mm.h>
  43. #include <linux/dma-mapping.h>
  44. #include <linux/kref.h>
  45. #include <linux/list.h>
  46. #include <linux/rwsem.h>
  47. #include <linux/scatterlist.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/socket.h>
  50. #include <linux/irq_poll.h>
  51. #include <uapi/linux/if_ether.h>
  52. #include <net/ipv6.h>
  53. #include <net/ip.h>
  54. #include <linux/string.h>
  55. #include <linux/slab.h>
  56. #include <linux/if_link.h>
  57. #include <linux/atomic.h>
  58. #include <linux/mmu_notifier.h>
  59. #include <asm/uaccess.h>
  60. extern struct workqueue_struct *ib_wq;
  61. extern struct workqueue_struct *ib_comp_wq;
  62. union ib_gid {
  63. u8 raw[16];
  64. struct {
  65. __be64 subnet_prefix;
  66. __be64 interface_id;
  67. } global;
  68. };
  69. extern union ib_gid zgid;
  70. enum ib_gid_type {
  71. /* If link layer is Ethernet, this is RoCE V1 */
  72. IB_GID_TYPE_IB = 0,
  73. IB_GID_TYPE_ROCE = 0,
  74. IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
  75. IB_GID_TYPE_SIZE
  76. };
  77. #define ROCE_V2_UDP_DPORT 4791
  78. struct ib_gid_attr {
  79. enum ib_gid_type gid_type;
  80. struct net_device *ndev;
  81. };
  82. enum rdma_node_type {
  83. /* IB values map to NodeInfo:NodeType. */
  84. RDMA_NODE_IB_CA = 1,
  85. RDMA_NODE_IB_SWITCH,
  86. RDMA_NODE_IB_ROUTER,
  87. RDMA_NODE_RNIC,
  88. RDMA_NODE_USNIC,
  89. RDMA_NODE_USNIC_UDP,
  90. };
  91. enum {
  92. /* set the local administered indication */
  93. IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2,
  94. };
  95. enum rdma_transport_type {
  96. RDMA_TRANSPORT_IB,
  97. RDMA_TRANSPORT_IWARP,
  98. RDMA_TRANSPORT_USNIC,
  99. RDMA_TRANSPORT_USNIC_UDP
  100. };
  101. enum rdma_protocol_type {
  102. RDMA_PROTOCOL_IB,
  103. RDMA_PROTOCOL_IBOE,
  104. RDMA_PROTOCOL_IWARP,
  105. RDMA_PROTOCOL_USNIC_UDP
  106. };
  107. __attribute_const__ enum rdma_transport_type
  108. rdma_node_get_transport(enum rdma_node_type node_type);
  109. enum rdma_network_type {
  110. RDMA_NETWORK_IB,
  111. RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
  112. RDMA_NETWORK_IPV4,
  113. RDMA_NETWORK_IPV6
  114. };
  115. static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
  116. {
  117. if (network_type == RDMA_NETWORK_IPV4 ||
  118. network_type == RDMA_NETWORK_IPV6)
  119. return IB_GID_TYPE_ROCE_UDP_ENCAP;
  120. /* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
  121. return IB_GID_TYPE_IB;
  122. }
  123. static inline enum rdma_network_type ib_gid_to_network_type(enum ib_gid_type gid_type,
  124. union ib_gid *gid)
  125. {
  126. if (gid_type == IB_GID_TYPE_IB)
  127. return RDMA_NETWORK_IB;
  128. if (ipv6_addr_v4mapped((struct in6_addr *)gid))
  129. return RDMA_NETWORK_IPV4;
  130. else
  131. return RDMA_NETWORK_IPV6;
  132. }
  133. enum rdma_link_layer {
  134. IB_LINK_LAYER_UNSPECIFIED,
  135. IB_LINK_LAYER_INFINIBAND,
  136. IB_LINK_LAYER_ETHERNET,
  137. };
  138. enum ib_device_cap_flags {
  139. IB_DEVICE_RESIZE_MAX_WR = (1 << 0),
  140. IB_DEVICE_BAD_PKEY_CNTR = (1 << 1),
  141. IB_DEVICE_BAD_QKEY_CNTR = (1 << 2),
  142. IB_DEVICE_RAW_MULTI = (1 << 3),
  143. IB_DEVICE_AUTO_PATH_MIG = (1 << 4),
  144. IB_DEVICE_CHANGE_PHY_PORT = (1 << 5),
  145. IB_DEVICE_UD_AV_PORT_ENFORCE = (1 << 6),
  146. IB_DEVICE_CURR_QP_STATE_MOD = (1 << 7),
  147. IB_DEVICE_SHUTDOWN_PORT = (1 << 8),
  148. IB_DEVICE_INIT_TYPE = (1 << 9),
  149. IB_DEVICE_PORT_ACTIVE_EVENT = (1 << 10),
  150. IB_DEVICE_SYS_IMAGE_GUID = (1 << 11),
  151. IB_DEVICE_RC_RNR_NAK_GEN = (1 << 12),
  152. IB_DEVICE_SRQ_RESIZE = (1 << 13),
  153. IB_DEVICE_N_NOTIFY_CQ = (1 << 14),
  154. /*
  155. * This device supports a per-device lkey or stag that can be
  156. * used without performing a memory registration for the local
  157. * memory. Note that ULPs should never check this flag, but
  158. * instead of use the local_dma_lkey flag in the ib_pd structure,
  159. * which will always contain a usable lkey.
  160. */
  161. IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15),
  162. IB_DEVICE_RESERVED /* old SEND_W_INV */ = (1 << 16),
  163. IB_DEVICE_MEM_WINDOW = (1 << 17),
  164. /*
  165. * Devices should set IB_DEVICE_UD_IP_SUM if they support
  166. * insertion of UDP and TCP checksum on outgoing UD IPoIB
  167. * messages and can verify the validity of checksum for
  168. * incoming messages. Setting this flag implies that the
  169. * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
  170. */
  171. IB_DEVICE_UD_IP_CSUM = (1 << 18),
  172. IB_DEVICE_UD_TSO = (1 << 19),
  173. IB_DEVICE_XRC = (1 << 20),
  174. /*
  175. * This device supports the IB "base memory management extension",
  176. * which includes support for fast registrations (IB_WR_REG_MR,
  177. * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs). This flag should
  178. * also be set by any iWarp device which must support FRs to comply
  179. * to the iWarp verbs spec. iWarp devices also support the
  180. * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
  181. * stag.
  182. */
  183. IB_DEVICE_MEM_MGT_EXTENSIONS = (1 << 21),
  184. IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1 << 22),
  185. IB_DEVICE_MEM_WINDOW_TYPE_2A = (1 << 23),
  186. IB_DEVICE_MEM_WINDOW_TYPE_2B = (1 << 24),
  187. IB_DEVICE_RC_IP_CSUM = (1 << 25),
  188. IB_DEVICE_RAW_IP_CSUM = (1 << 26),
  189. /*
  190. * Devices should set IB_DEVICE_CROSS_CHANNEL if they
  191. * support execution of WQEs that involve synchronization
  192. * of I/O operations with single completion queue managed
  193. * by hardware.
  194. */
  195. IB_DEVICE_CROSS_CHANNEL = (1 << 27),
  196. IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29),
  197. IB_DEVICE_SIGNATURE_HANDOVER = (1 << 30),
  198. IB_DEVICE_ON_DEMAND_PAGING = (1ULL << 31),
  199. IB_DEVICE_SG_GAPS_REG = (1ULL << 32),
  200. IB_DEVICE_VIRTUAL_FUNCTION = (1ULL << 33),
  201. IB_DEVICE_RAW_SCATTER_FCS = (1ULL << 34),
  202. };
  203. enum ib_signature_prot_cap {
  204. IB_PROT_T10DIF_TYPE_1 = 1,
  205. IB_PROT_T10DIF_TYPE_2 = 1 << 1,
  206. IB_PROT_T10DIF_TYPE_3 = 1 << 2,
  207. };
  208. enum ib_signature_guard_cap {
  209. IB_GUARD_T10DIF_CRC = 1,
  210. IB_GUARD_T10DIF_CSUM = 1 << 1,
  211. };
  212. enum ib_atomic_cap {
  213. IB_ATOMIC_NONE,
  214. IB_ATOMIC_HCA,
  215. IB_ATOMIC_GLOB
  216. };
  217. enum ib_odp_general_cap_bits {
  218. IB_ODP_SUPPORT = 1 << 0,
  219. };
  220. enum ib_odp_transport_cap_bits {
  221. IB_ODP_SUPPORT_SEND = 1 << 0,
  222. IB_ODP_SUPPORT_RECV = 1 << 1,
  223. IB_ODP_SUPPORT_WRITE = 1 << 2,
  224. IB_ODP_SUPPORT_READ = 1 << 3,
  225. IB_ODP_SUPPORT_ATOMIC = 1 << 4,
  226. };
  227. struct ib_odp_caps {
  228. uint64_t general_caps;
  229. struct {
  230. uint32_t rc_odp_caps;
  231. uint32_t uc_odp_caps;
  232. uint32_t ud_odp_caps;
  233. } per_transport_caps;
  234. };
  235. enum ib_cq_creation_flags {
  236. IB_CQ_FLAGS_TIMESTAMP_COMPLETION = 1 << 0,
  237. IB_CQ_FLAGS_IGNORE_OVERRUN = 1 << 1,
  238. };
  239. struct ib_cq_init_attr {
  240. unsigned int cqe;
  241. int comp_vector;
  242. u32 flags;
  243. };
  244. struct ib_device_attr {
  245. u64 fw_ver;
  246. __be64 sys_image_guid;
  247. u64 max_mr_size;
  248. u64 page_size_cap;
  249. u32 vendor_id;
  250. u32 vendor_part_id;
  251. u32 hw_ver;
  252. int max_qp;
  253. int max_qp_wr;
  254. u64 device_cap_flags;
  255. int max_sge;
  256. int max_sge_rd;
  257. int max_cq;
  258. int max_cqe;
  259. int max_mr;
  260. int max_pd;
  261. int max_qp_rd_atom;
  262. int max_ee_rd_atom;
  263. int max_res_rd_atom;
  264. int max_qp_init_rd_atom;
  265. int max_ee_init_rd_atom;
  266. enum ib_atomic_cap atomic_cap;
  267. enum ib_atomic_cap masked_atomic_cap;
  268. int max_ee;
  269. int max_rdd;
  270. int max_mw;
  271. int max_raw_ipv6_qp;
  272. int max_raw_ethy_qp;
  273. int max_mcast_grp;
  274. int max_mcast_qp_attach;
  275. int max_total_mcast_qp_attach;
  276. int max_ah;
  277. int max_fmr;
  278. int max_map_per_fmr;
  279. int max_srq;
  280. int max_srq_wr;
  281. int max_srq_sge;
  282. unsigned int max_fast_reg_page_list_len;
  283. u16 max_pkeys;
  284. u8 local_ca_ack_delay;
  285. int sig_prot_cap;
  286. int sig_guard_cap;
  287. struct ib_odp_caps odp_caps;
  288. uint64_t timestamp_mask;
  289. uint64_t hca_core_clock; /* in KHZ */
  290. };
  291. enum ib_mtu {
  292. IB_MTU_256 = 1,
  293. IB_MTU_512 = 2,
  294. IB_MTU_1024 = 3,
  295. IB_MTU_2048 = 4,
  296. IB_MTU_4096 = 5
  297. };
  298. static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
  299. {
  300. switch (mtu) {
  301. case IB_MTU_256: return 256;
  302. case IB_MTU_512: return 512;
  303. case IB_MTU_1024: return 1024;
  304. case IB_MTU_2048: return 2048;
  305. case IB_MTU_4096: return 4096;
  306. default: return -1;
  307. }
  308. }
  309. enum ib_port_state {
  310. IB_PORT_NOP = 0,
  311. IB_PORT_DOWN = 1,
  312. IB_PORT_INIT = 2,
  313. IB_PORT_ARMED = 3,
  314. IB_PORT_ACTIVE = 4,
  315. IB_PORT_ACTIVE_DEFER = 5
  316. };
  317. enum ib_port_cap_flags {
  318. IB_PORT_SM = 1 << 1,
  319. IB_PORT_NOTICE_SUP = 1 << 2,
  320. IB_PORT_TRAP_SUP = 1 << 3,
  321. IB_PORT_OPT_IPD_SUP = 1 << 4,
  322. IB_PORT_AUTO_MIGR_SUP = 1 << 5,
  323. IB_PORT_SL_MAP_SUP = 1 << 6,
  324. IB_PORT_MKEY_NVRAM = 1 << 7,
  325. IB_PORT_PKEY_NVRAM = 1 << 8,
  326. IB_PORT_LED_INFO_SUP = 1 << 9,
  327. IB_PORT_SM_DISABLED = 1 << 10,
  328. IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  329. IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  330. IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
  331. IB_PORT_CM_SUP = 1 << 16,
  332. IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  333. IB_PORT_REINIT_SUP = 1 << 18,
  334. IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
  335. IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
  336. IB_PORT_DR_NOTICE_SUP = 1 << 21,
  337. IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  338. IB_PORT_BOOT_MGMT_SUP = 1 << 23,
  339. IB_PORT_LINK_LATENCY_SUP = 1 << 24,
  340. IB_PORT_CLIENT_REG_SUP = 1 << 25,
  341. IB_PORT_IP_BASED_GIDS = 1 << 26,
  342. };
  343. enum ib_port_width {
  344. IB_WIDTH_1X = 1,
  345. IB_WIDTH_4X = 2,
  346. IB_WIDTH_8X = 4,
  347. IB_WIDTH_12X = 8
  348. };
  349. static inline int ib_width_enum_to_int(enum ib_port_width width)
  350. {
  351. switch (width) {
  352. case IB_WIDTH_1X: return 1;
  353. case IB_WIDTH_4X: return 4;
  354. case IB_WIDTH_8X: return 8;
  355. case IB_WIDTH_12X: return 12;
  356. default: return -1;
  357. }
  358. }
  359. enum ib_port_speed {
  360. IB_SPEED_SDR = 1,
  361. IB_SPEED_DDR = 2,
  362. IB_SPEED_QDR = 4,
  363. IB_SPEED_FDR10 = 8,
  364. IB_SPEED_FDR = 16,
  365. IB_SPEED_EDR = 32
  366. };
  367. /**
  368. * struct rdma_hw_stats
  369. * @timestamp - Used by the core code to track when the last update was
  370. * @lifespan - Used by the core code to determine how old the counters
  371. * should be before being updated again. Stored in jiffies, defaults
  372. * to 10 milliseconds, drivers can override the default be specifying
  373. * their own value during their allocation routine.
  374. * @name - Array of pointers to static names used for the counters in
  375. * directory.
  376. * @num_counters - How many hardware counters there are. If name is
  377. * shorter than this number, a kernel oops will result. Driver authors
  378. * are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
  379. * in their code to prevent this.
  380. * @value - Array of u64 counters that are accessed by the sysfs code and
  381. * filled in by the drivers get_stats routine
  382. */
  383. struct rdma_hw_stats {
  384. unsigned long timestamp;
  385. unsigned long lifespan;
  386. const char * const *names;
  387. int num_counters;
  388. u64 value[];
  389. };
  390. #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
  391. /**
  392. * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
  393. * for drivers.
  394. * @names - Array of static const char *
  395. * @num_counters - How many elements in array
  396. * @lifespan - How many milliseconds between updates
  397. */
  398. static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
  399. const char * const *names, int num_counters,
  400. unsigned long lifespan)
  401. {
  402. struct rdma_hw_stats *stats;
  403. stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
  404. GFP_KERNEL);
  405. if (!stats)
  406. return NULL;
  407. stats->names = names;
  408. stats->num_counters = num_counters;
  409. stats->lifespan = msecs_to_jiffies(lifespan);
  410. return stats;
  411. }
  412. /* Define bits for the various functionality this port needs to be supported by
  413. * the core.
  414. */
  415. /* Management 0x00000FFF */
  416. #define RDMA_CORE_CAP_IB_MAD 0x00000001
  417. #define RDMA_CORE_CAP_IB_SMI 0x00000002
  418. #define RDMA_CORE_CAP_IB_CM 0x00000004
  419. #define RDMA_CORE_CAP_IW_CM 0x00000008
  420. #define RDMA_CORE_CAP_IB_SA 0x00000010
  421. #define RDMA_CORE_CAP_OPA_MAD 0x00000020
  422. /* Address format 0x000FF000 */
  423. #define RDMA_CORE_CAP_AF_IB 0x00001000
  424. #define RDMA_CORE_CAP_ETH_AH 0x00002000
  425. /* Protocol 0xFFF00000 */
  426. #define RDMA_CORE_CAP_PROT_IB 0x00100000
  427. #define RDMA_CORE_CAP_PROT_ROCE 0x00200000
  428. #define RDMA_CORE_CAP_PROT_IWARP 0x00400000
  429. #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
  430. #define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
  431. | RDMA_CORE_CAP_IB_MAD \
  432. | RDMA_CORE_CAP_IB_SMI \
  433. | RDMA_CORE_CAP_IB_CM \
  434. | RDMA_CORE_CAP_IB_SA \
  435. | RDMA_CORE_CAP_AF_IB)
  436. #define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
  437. | RDMA_CORE_CAP_IB_MAD \
  438. | RDMA_CORE_CAP_IB_CM \
  439. | RDMA_CORE_CAP_AF_IB \
  440. | RDMA_CORE_CAP_ETH_AH)
  441. #define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \
  442. (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
  443. | RDMA_CORE_CAP_IB_MAD \
  444. | RDMA_CORE_CAP_IB_CM \
  445. | RDMA_CORE_CAP_AF_IB \
  446. | RDMA_CORE_CAP_ETH_AH)
  447. #define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
  448. | RDMA_CORE_CAP_IW_CM)
  449. #define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \
  450. | RDMA_CORE_CAP_OPA_MAD)
  451. struct ib_port_attr {
  452. u64 subnet_prefix;
  453. enum ib_port_state state;
  454. enum ib_mtu max_mtu;
  455. enum ib_mtu active_mtu;
  456. int gid_tbl_len;
  457. u32 port_cap_flags;
  458. u32 max_msg_sz;
  459. u32 bad_pkey_cntr;
  460. u32 qkey_viol_cntr;
  461. u16 pkey_tbl_len;
  462. u16 lid;
  463. u16 sm_lid;
  464. u8 lmc;
  465. u8 max_vl_num;
  466. u8 sm_sl;
  467. u8 subnet_timeout;
  468. u8 init_type_reply;
  469. u8 active_width;
  470. u8 active_speed;
  471. u8 phys_state;
  472. bool grh_required;
  473. };
  474. enum ib_device_modify_flags {
  475. IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
  476. IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
  477. };
  478. struct ib_device_modify {
  479. u64 sys_image_guid;
  480. char node_desc[64];
  481. };
  482. enum ib_port_modify_flags {
  483. IB_PORT_SHUTDOWN = 1,
  484. IB_PORT_INIT_TYPE = (1<<2),
  485. IB_PORT_RESET_QKEY_CNTR = (1<<3)
  486. };
  487. struct ib_port_modify {
  488. u32 set_port_cap_mask;
  489. u32 clr_port_cap_mask;
  490. u8 init_type;
  491. };
  492. enum ib_event_type {
  493. IB_EVENT_CQ_ERR,
  494. IB_EVENT_QP_FATAL,
  495. IB_EVENT_QP_REQ_ERR,
  496. IB_EVENT_QP_ACCESS_ERR,
  497. IB_EVENT_COMM_EST,
  498. IB_EVENT_SQ_DRAINED,
  499. IB_EVENT_PATH_MIG,
  500. IB_EVENT_PATH_MIG_ERR,
  501. IB_EVENT_DEVICE_FATAL,
  502. IB_EVENT_PORT_ACTIVE,
  503. IB_EVENT_PORT_ERR,
  504. IB_EVENT_LID_CHANGE,
  505. IB_EVENT_PKEY_CHANGE,
  506. IB_EVENT_SM_CHANGE,
  507. IB_EVENT_SRQ_ERR,
  508. IB_EVENT_SRQ_LIMIT_REACHED,
  509. IB_EVENT_QP_LAST_WQE_REACHED,
  510. IB_EVENT_CLIENT_REREGISTER,
  511. IB_EVENT_GID_CHANGE,
  512. IB_EVENT_WQ_FATAL,
  513. };
  514. const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
  515. struct ib_event {
  516. struct ib_device *device;
  517. union {
  518. struct ib_cq *cq;
  519. struct ib_qp *qp;
  520. struct ib_srq *srq;
  521. struct ib_wq *wq;
  522. u8 port_num;
  523. } element;
  524. enum ib_event_type event;
  525. };
  526. struct ib_event_handler {
  527. struct ib_device *device;
  528. void (*handler)(struct ib_event_handler *, struct ib_event *);
  529. struct list_head list;
  530. };
  531. #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
  532. do { \
  533. (_ptr)->device = _device; \
  534. (_ptr)->handler = _handler; \
  535. INIT_LIST_HEAD(&(_ptr)->list); \
  536. } while (0)
  537. struct ib_global_route {
  538. union ib_gid dgid;
  539. u32 flow_label;
  540. u8 sgid_index;
  541. u8 hop_limit;
  542. u8 traffic_class;
  543. };
  544. struct ib_grh {
  545. __be32 version_tclass_flow;
  546. __be16 paylen;
  547. u8 next_hdr;
  548. u8 hop_limit;
  549. union ib_gid sgid;
  550. union ib_gid dgid;
  551. };
  552. union rdma_network_hdr {
  553. struct ib_grh ibgrh;
  554. struct {
  555. /* The IB spec states that if it's IPv4, the header
  556. * is located in the last 20 bytes of the header.
  557. */
  558. u8 reserved[20];
  559. struct iphdr roce4grh;
  560. };
  561. };
  562. enum {
  563. IB_MULTICAST_QPN = 0xffffff
  564. };
  565. #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
  566. #define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000)
  567. enum ib_ah_flags {
  568. IB_AH_GRH = 1
  569. };
  570. enum ib_rate {
  571. IB_RATE_PORT_CURRENT = 0,
  572. IB_RATE_2_5_GBPS = 2,
  573. IB_RATE_5_GBPS = 5,
  574. IB_RATE_10_GBPS = 3,
  575. IB_RATE_20_GBPS = 6,
  576. IB_RATE_30_GBPS = 4,
  577. IB_RATE_40_GBPS = 7,
  578. IB_RATE_60_GBPS = 8,
  579. IB_RATE_80_GBPS = 9,
  580. IB_RATE_120_GBPS = 10,
  581. IB_RATE_14_GBPS = 11,
  582. IB_RATE_56_GBPS = 12,
  583. IB_RATE_112_GBPS = 13,
  584. IB_RATE_168_GBPS = 14,
  585. IB_RATE_25_GBPS = 15,
  586. IB_RATE_100_GBPS = 16,
  587. IB_RATE_200_GBPS = 17,
  588. IB_RATE_300_GBPS = 18
  589. };
  590. /**
  591. * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
  592. * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
  593. * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
  594. * @rate: rate to convert.
  595. */
  596. __attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
  597. /**
  598. * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
  599. * For example, IB_RATE_2_5_GBPS will be converted to 2500.
  600. * @rate: rate to convert.
  601. */
  602. __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
  603. /**
  604. * enum ib_mr_type - memory region type
  605. * @IB_MR_TYPE_MEM_REG: memory region that is used for
  606. * normal registration
  607. * @IB_MR_TYPE_SIGNATURE: memory region that is used for
  608. * signature operations (data-integrity
  609. * capable regions)
  610. * @IB_MR_TYPE_SG_GAPS: memory region that is capable to
  611. * register any arbitrary sg lists (without
  612. * the normal mr constraints - see
  613. * ib_map_mr_sg)
  614. */
  615. enum ib_mr_type {
  616. IB_MR_TYPE_MEM_REG,
  617. IB_MR_TYPE_SIGNATURE,
  618. IB_MR_TYPE_SG_GAPS,
  619. };
  620. /**
  621. * Signature types
  622. * IB_SIG_TYPE_NONE: Unprotected.
  623. * IB_SIG_TYPE_T10_DIF: Type T10-DIF
  624. */
  625. enum ib_signature_type {
  626. IB_SIG_TYPE_NONE,
  627. IB_SIG_TYPE_T10_DIF,
  628. };
  629. /**
  630. * Signature T10-DIF block-guard types
  631. * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
  632. * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
  633. */
  634. enum ib_t10_dif_bg_type {
  635. IB_T10DIF_CRC,
  636. IB_T10DIF_CSUM
  637. };
  638. /**
  639. * struct ib_t10_dif_domain - Parameters specific for T10-DIF
  640. * domain.
  641. * @bg_type: T10-DIF block guard type (CRC|CSUM)
  642. * @pi_interval: protection information interval.
  643. * @bg: seed of guard computation.
  644. * @app_tag: application tag of guard block
  645. * @ref_tag: initial guard block reference tag.
  646. * @ref_remap: Indicate wethear the reftag increments each block
  647. * @app_escape: Indicate to skip block check if apptag=0xffff
  648. * @ref_escape: Indicate to skip block check if reftag=0xffffffff
  649. * @apptag_check_mask: check bitmask of application tag.
  650. */
  651. struct ib_t10_dif_domain {
  652. enum ib_t10_dif_bg_type bg_type;
  653. u16 pi_interval;
  654. u16 bg;
  655. u16 app_tag;
  656. u32 ref_tag;
  657. bool ref_remap;
  658. bool app_escape;
  659. bool ref_escape;
  660. u16 apptag_check_mask;
  661. };
  662. /**
  663. * struct ib_sig_domain - Parameters for signature domain
  664. * @sig_type: specific signauture type
  665. * @sig: union of all signature domain attributes that may
  666. * be used to set domain layout.
  667. */
  668. struct ib_sig_domain {
  669. enum ib_signature_type sig_type;
  670. union {
  671. struct ib_t10_dif_domain dif;
  672. } sig;
  673. };
  674. /**
  675. * struct ib_sig_attrs - Parameters for signature handover operation
  676. * @check_mask: bitmask for signature byte check (8 bytes)
  677. * @mem: memory domain layout desciptor.
  678. * @wire: wire domain layout desciptor.
  679. */
  680. struct ib_sig_attrs {
  681. u8 check_mask;
  682. struct ib_sig_domain mem;
  683. struct ib_sig_domain wire;
  684. };
  685. enum ib_sig_err_type {
  686. IB_SIG_BAD_GUARD,
  687. IB_SIG_BAD_REFTAG,
  688. IB_SIG_BAD_APPTAG,
  689. };
  690. /**
  691. * struct ib_sig_err - signature error descriptor
  692. */
  693. struct ib_sig_err {
  694. enum ib_sig_err_type err_type;
  695. u32 expected;
  696. u32 actual;
  697. u64 sig_err_offset;
  698. u32 key;
  699. };
  700. enum ib_mr_status_check {
  701. IB_MR_CHECK_SIG_STATUS = 1,
  702. };
  703. /**
  704. * struct ib_mr_status - Memory region status container
  705. *
  706. * @fail_status: Bitmask of MR checks status. For each
  707. * failed check a corresponding status bit is set.
  708. * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
  709. * failure.
  710. */
  711. struct ib_mr_status {
  712. u32 fail_status;
  713. struct ib_sig_err sig_err;
  714. };
  715. /**
  716. * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
  717. * enum.
  718. * @mult: multiple to convert.
  719. */
  720. __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
  721. struct ib_ah_attr {
  722. struct ib_global_route grh;
  723. u16 dlid;
  724. u8 sl;
  725. u8 src_path_bits;
  726. u8 static_rate;
  727. u8 ah_flags;
  728. u8 port_num;
  729. u8 dmac[ETH_ALEN];
  730. };
  731. enum ib_wc_status {
  732. IB_WC_SUCCESS,
  733. IB_WC_LOC_LEN_ERR,
  734. IB_WC_LOC_QP_OP_ERR,
  735. IB_WC_LOC_EEC_OP_ERR,
  736. IB_WC_LOC_PROT_ERR,
  737. IB_WC_WR_FLUSH_ERR,
  738. IB_WC_MW_BIND_ERR,
  739. IB_WC_BAD_RESP_ERR,
  740. IB_WC_LOC_ACCESS_ERR,
  741. IB_WC_REM_INV_REQ_ERR,
  742. IB_WC_REM_ACCESS_ERR,
  743. IB_WC_REM_OP_ERR,
  744. IB_WC_RETRY_EXC_ERR,
  745. IB_WC_RNR_RETRY_EXC_ERR,
  746. IB_WC_LOC_RDD_VIOL_ERR,
  747. IB_WC_REM_INV_RD_REQ_ERR,
  748. IB_WC_REM_ABORT_ERR,
  749. IB_WC_INV_EECN_ERR,
  750. IB_WC_INV_EEC_STATE_ERR,
  751. IB_WC_FATAL_ERR,
  752. IB_WC_RESP_TIMEOUT_ERR,
  753. IB_WC_GENERAL_ERR
  754. };
  755. const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
  756. enum ib_wc_opcode {
  757. IB_WC_SEND,
  758. IB_WC_RDMA_WRITE,
  759. IB_WC_RDMA_READ,
  760. IB_WC_COMP_SWAP,
  761. IB_WC_FETCH_ADD,
  762. IB_WC_LSO,
  763. IB_WC_LOCAL_INV,
  764. IB_WC_REG_MR,
  765. IB_WC_MASKED_COMP_SWAP,
  766. IB_WC_MASKED_FETCH_ADD,
  767. /*
  768. * Set value of IB_WC_RECV so consumers can test if a completion is a
  769. * receive by testing (opcode & IB_WC_RECV).
  770. */
  771. IB_WC_RECV = 1 << 7,
  772. IB_WC_RECV_RDMA_WITH_IMM
  773. };
  774. enum ib_wc_flags {
  775. IB_WC_GRH = 1,
  776. IB_WC_WITH_IMM = (1<<1),
  777. IB_WC_WITH_INVALIDATE = (1<<2),
  778. IB_WC_IP_CSUM_OK = (1<<3),
  779. IB_WC_WITH_SMAC = (1<<4),
  780. IB_WC_WITH_VLAN = (1<<5),
  781. IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6),
  782. };
  783. struct ib_wc {
  784. union {
  785. u64 wr_id;
  786. struct ib_cqe *wr_cqe;
  787. };
  788. enum ib_wc_status status;
  789. enum ib_wc_opcode opcode;
  790. u32 vendor_err;
  791. u32 byte_len;
  792. struct ib_qp *qp;
  793. union {
  794. __be32 imm_data;
  795. u32 invalidate_rkey;
  796. } ex;
  797. u32 src_qp;
  798. int wc_flags;
  799. u16 pkey_index;
  800. u16 slid;
  801. u8 sl;
  802. u8 dlid_path_bits;
  803. u8 port_num; /* valid only for DR SMPs on switches */
  804. u8 smac[ETH_ALEN];
  805. u16 vlan_id;
  806. u8 network_hdr_type;
  807. };
  808. enum ib_cq_notify_flags {
  809. IB_CQ_SOLICITED = 1 << 0,
  810. IB_CQ_NEXT_COMP = 1 << 1,
  811. IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
  812. IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
  813. };
  814. enum ib_srq_type {
  815. IB_SRQT_BASIC,
  816. IB_SRQT_XRC
  817. };
  818. enum ib_srq_attr_mask {
  819. IB_SRQ_MAX_WR = 1 << 0,
  820. IB_SRQ_LIMIT = 1 << 1,
  821. };
  822. struct ib_srq_attr {
  823. u32 max_wr;
  824. u32 max_sge;
  825. u32 srq_limit;
  826. };
  827. struct ib_srq_init_attr {
  828. void (*event_handler)(struct ib_event *, void *);
  829. void *srq_context;
  830. struct ib_srq_attr attr;
  831. enum ib_srq_type srq_type;
  832. union {
  833. struct {
  834. struct ib_xrcd *xrcd;
  835. struct ib_cq *cq;
  836. } xrc;
  837. } ext;
  838. };
  839. struct ib_qp_cap {
  840. u32 max_send_wr;
  841. u32 max_recv_wr;
  842. u32 max_send_sge;
  843. u32 max_recv_sge;
  844. u32 max_inline_data;
  845. /*
  846. * Maximum number of rdma_rw_ctx structures in flight at a time.
  847. * ib_create_qp() will calculate the right amount of neededed WRs
  848. * and MRs based on this.
  849. */
  850. u32 max_rdma_ctxs;
  851. };
  852. enum ib_sig_type {
  853. IB_SIGNAL_ALL_WR,
  854. IB_SIGNAL_REQ_WR
  855. };
  856. enum ib_qp_type {
  857. /*
  858. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  859. * here (and in that order) since the MAD layer uses them as
  860. * indices into a 2-entry table.
  861. */
  862. IB_QPT_SMI,
  863. IB_QPT_GSI,
  864. IB_QPT_RC,
  865. IB_QPT_UC,
  866. IB_QPT_UD,
  867. IB_QPT_RAW_IPV6,
  868. IB_QPT_RAW_ETHERTYPE,
  869. IB_QPT_RAW_PACKET = 8,
  870. IB_QPT_XRC_INI = 9,
  871. IB_QPT_XRC_TGT,
  872. IB_QPT_MAX,
  873. /* Reserve a range for qp types internal to the low level driver.
  874. * These qp types will not be visible at the IB core layer, so the
  875. * IB_QPT_MAX usages should not be affected in the core layer
  876. */
  877. IB_QPT_RESERVED1 = 0x1000,
  878. IB_QPT_RESERVED2,
  879. IB_QPT_RESERVED3,
  880. IB_QPT_RESERVED4,
  881. IB_QPT_RESERVED5,
  882. IB_QPT_RESERVED6,
  883. IB_QPT_RESERVED7,
  884. IB_QPT_RESERVED8,
  885. IB_QPT_RESERVED9,
  886. IB_QPT_RESERVED10,
  887. };
  888. enum ib_qp_create_flags {
  889. IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
  890. IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
  891. IB_QP_CREATE_CROSS_CHANNEL = 1 << 2,
  892. IB_QP_CREATE_MANAGED_SEND = 1 << 3,
  893. IB_QP_CREATE_MANAGED_RECV = 1 << 4,
  894. IB_QP_CREATE_NETIF_QP = 1 << 5,
  895. IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
  896. IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
  897. IB_QP_CREATE_SCATTER_FCS = 1 << 8,
  898. /* reserve bits 26-31 for low level drivers' internal use */
  899. IB_QP_CREATE_RESERVED_START = 1 << 26,
  900. IB_QP_CREATE_RESERVED_END = 1 << 31,
  901. };
  902. /*
  903. * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
  904. * callback to destroy the passed in QP.
  905. */
  906. struct ib_qp_init_attr {
  907. void (*event_handler)(struct ib_event *, void *);
  908. void *qp_context;
  909. struct ib_cq *send_cq;
  910. struct ib_cq *recv_cq;
  911. struct ib_srq *srq;
  912. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  913. struct ib_qp_cap cap;
  914. enum ib_sig_type sq_sig_type;
  915. enum ib_qp_type qp_type;
  916. enum ib_qp_create_flags create_flags;
  917. /*
  918. * Only needed for special QP types, or when using the RW API.
  919. */
  920. u8 port_num;
  921. struct ib_rwq_ind_table *rwq_ind_tbl;
  922. };
  923. struct ib_qp_open_attr {
  924. void (*event_handler)(struct ib_event *, void *);
  925. void *qp_context;
  926. u32 qp_num;
  927. enum ib_qp_type qp_type;
  928. };
  929. enum ib_rnr_timeout {
  930. IB_RNR_TIMER_655_36 = 0,
  931. IB_RNR_TIMER_000_01 = 1,
  932. IB_RNR_TIMER_000_02 = 2,
  933. IB_RNR_TIMER_000_03 = 3,
  934. IB_RNR_TIMER_000_04 = 4,
  935. IB_RNR_TIMER_000_06 = 5,
  936. IB_RNR_TIMER_000_08 = 6,
  937. IB_RNR_TIMER_000_12 = 7,
  938. IB_RNR_TIMER_000_16 = 8,
  939. IB_RNR_TIMER_000_24 = 9,
  940. IB_RNR_TIMER_000_32 = 10,
  941. IB_RNR_TIMER_000_48 = 11,
  942. IB_RNR_TIMER_000_64 = 12,
  943. IB_RNR_TIMER_000_96 = 13,
  944. IB_RNR_TIMER_001_28 = 14,
  945. IB_RNR_TIMER_001_92 = 15,
  946. IB_RNR_TIMER_002_56 = 16,
  947. IB_RNR_TIMER_003_84 = 17,
  948. IB_RNR_TIMER_005_12 = 18,
  949. IB_RNR_TIMER_007_68 = 19,
  950. IB_RNR_TIMER_010_24 = 20,
  951. IB_RNR_TIMER_015_36 = 21,
  952. IB_RNR_TIMER_020_48 = 22,
  953. IB_RNR_TIMER_030_72 = 23,
  954. IB_RNR_TIMER_040_96 = 24,
  955. IB_RNR_TIMER_061_44 = 25,
  956. IB_RNR_TIMER_081_92 = 26,
  957. IB_RNR_TIMER_122_88 = 27,
  958. IB_RNR_TIMER_163_84 = 28,
  959. IB_RNR_TIMER_245_76 = 29,
  960. IB_RNR_TIMER_327_68 = 30,
  961. IB_RNR_TIMER_491_52 = 31
  962. };
  963. enum ib_qp_attr_mask {
  964. IB_QP_STATE = 1,
  965. IB_QP_CUR_STATE = (1<<1),
  966. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  967. IB_QP_ACCESS_FLAGS = (1<<3),
  968. IB_QP_PKEY_INDEX = (1<<4),
  969. IB_QP_PORT = (1<<5),
  970. IB_QP_QKEY = (1<<6),
  971. IB_QP_AV = (1<<7),
  972. IB_QP_PATH_MTU = (1<<8),
  973. IB_QP_TIMEOUT = (1<<9),
  974. IB_QP_RETRY_CNT = (1<<10),
  975. IB_QP_RNR_RETRY = (1<<11),
  976. IB_QP_RQ_PSN = (1<<12),
  977. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  978. IB_QP_ALT_PATH = (1<<14),
  979. IB_QP_MIN_RNR_TIMER = (1<<15),
  980. IB_QP_SQ_PSN = (1<<16),
  981. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  982. IB_QP_PATH_MIG_STATE = (1<<18),
  983. IB_QP_CAP = (1<<19),
  984. IB_QP_DEST_QPN = (1<<20),
  985. IB_QP_RESERVED1 = (1<<21),
  986. IB_QP_RESERVED2 = (1<<22),
  987. IB_QP_RESERVED3 = (1<<23),
  988. IB_QP_RESERVED4 = (1<<24),
  989. };
  990. enum ib_qp_state {
  991. IB_QPS_RESET,
  992. IB_QPS_INIT,
  993. IB_QPS_RTR,
  994. IB_QPS_RTS,
  995. IB_QPS_SQD,
  996. IB_QPS_SQE,
  997. IB_QPS_ERR
  998. };
  999. enum ib_mig_state {
  1000. IB_MIG_MIGRATED,
  1001. IB_MIG_REARM,
  1002. IB_MIG_ARMED
  1003. };
  1004. enum ib_mw_type {
  1005. IB_MW_TYPE_1 = 1,
  1006. IB_MW_TYPE_2 = 2
  1007. };
  1008. struct ib_qp_attr {
  1009. enum ib_qp_state qp_state;
  1010. enum ib_qp_state cur_qp_state;
  1011. enum ib_mtu path_mtu;
  1012. enum ib_mig_state path_mig_state;
  1013. u32 qkey;
  1014. u32 rq_psn;
  1015. u32 sq_psn;
  1016. u32 dest_qp_num;
  1017. int qp_access_flags;
  1018. struct ib_qp_cap cap;
  1019. struct ib_ah_attr ah_attr;
  1020. struct ib_ah_attr alt_ah_attr;
  1021. u16 pkey_index;
  1022. u16 alt_pkey_index;
  1023. u8 en_sqd_async_notify;
  1024. u8 sq_draining;
  1025. u8 max_rd_atomic;
  1026. u8 max_dest_rd_atomic;
  1027. u8 min_rnr_timer;
  1028. u8 port_num;
  1029. u8 timeout;
  1030. u8 retry_cnt;
  1031. u8 rnr_retry;
  1032. u8 alt_port_num;
  1033. u8 alt_timeout;
  1034. };
  1035. enum ib_wr_opcode {
  1036. IB_WR_RDMA_WRITE,
  1037. IB_WR_RDMA_WRITE_WITH_IMM,
  1038. IB_WR_SEND,
  1039. IB_WR_SEND_WITH_IMM,
  1040. IB_WR_RDMA_READ,
  1041. IB_WR_ATOMIC_CMP_AND_SWP,
  1042. IB_WR_ATOMIC_FETCH_AND_ADD,
  1043. IB_WR_LSO,
  1044. IB_WR_SEND_WITH_INV,
  1045. IB_WR_RDMA_READ_WITH_INV,
  1046. IB_WR_LOCAL_INV,
  1047. IB_WR_REG_MR,
  1048. IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
  1049. IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
  1050. IB_WR_REG_SIG_MR,
  1051. /* reserve values for low level drivers' internal use.
  1052. * These values will not be used at all in the ib core layer.
  1053. */
  1054. IB_WR_RESERVED1 = 0xf0,
  1055. IB_WR_RESERVED2,
  1056. IB_WR_RESERVED3,
  1057. IB_WR_RESERVED4,
  1058. IB_WR_RESERVED5,
  1059. IB_WR_RESERVED6,
  1060. IB_WR_RESERVED7,
  1061. IB_WR_RESERVED8,
  1062. IB_WR_RESERVED9,
  1063. IB_WR_RESERVED10,
  1064. };
  1065. enum ib_send_flags {
  1066. IB_SEND_FENCE = 1,
  1067. IB_SEND_SIGNALED = (1<<1),
  1068. IB_SEND_SOLICITED = (1<<2),
  1069. IB_SEND_INLINE = (1<<3),
  1070. IB_SEND_IP_CSUM = (1<<4),
  1071. /* reserve bits 26-31 for low level drivers' internal use */
  1072. IB_SEND_RESERVED_START = (1 << 26),
  1073. IB_SEND_RESERVED_END = (1 << 31),
  1074. };
  1075. struct ib_sge {
  1076. u64 addr;
  1077. u32 length;
  1078. u32 lkey;
  1079. };
  1080. struct ib_cqe {
  1081. void (*done)(struct ib_cq *cq, struct ib_wc *wc);
  1082. };
  1083. struct ib_send_wr {
  1084. struct ib_send_wr *next;
  1085. union {
  1086. u64 wr_id;
  1087. struct ib_cqe *wr_cqe;
  1088. };
  1089. struct ib_sge *sg_list;
  1090. int num_sge;
  1091. enum ib_wr_opcode opcode;
  1092. int send_flags;
  1093. union {
  1094. __be32 imm_data;
  1095. u32 invalidate_rkey;
  1096. } ex;
  1097. };
  1098. struct ib_rdma_wr {
  1099. struct ib_send_wr wr;
  1100. u64 remote_addr;
  1101. u32 rkey;
  1102. };
  1103. static inline struct ib_rdma_wr *rdma_wr(struct ib_send_wr *wr)
  1104. {
  1105. return container_of(wr, struct ib_rdma_wr, wr);
  1106. }
  1107. struct ib_atomic_wr {
  1108. struct ib_send_wr wr;
  1109. u64 remote_addr;
  1110. u64 compare_add;
  1111. u64 swap;
  1112. u64 compare_add_mask;
  1113. u64 swap_mask;
  1114. u32 rkey;
  1115. };
  1116. static inline struct ib_atomic_wr *atomic_wr(struct ib_send_wr *wr)
  1117. {
  1118. return container_of(wr, struct ib_atomic_wr, wr);
  1119. }
  1120. struct ib_ud_wr {
  1121. struct ib_send_wr wr;
  1122. struct ib_ah *ah;
  1123. void *header;
  1124. int hlen;
  1125. int mss;
  1126. u32 remote_qpn;
  1127. u32 remote_qkey;
  1128. u16 pkey_index; /* valid for GSI only */
  1129. u8 port_num; /* valid for DR SMPs on switch only */
  1130. };
  1131. static inline struct ib_ud_wr *ud_wr(struct ib_send_wr *wr)
  1132. {
  1133. return container_of(wr, struct ib_ud_wr, wr);
  1134. }
  1135. struct ib_reg_wr {
  1136. struct ib_send_wr wr;
  1137. struct ib_mr *mr;
  1138. u32 key;
  1139. int access;
  1140. };
  1141. static inline struct ib_reg_wr *reg_wr(struct ib_send_wr *wr)
  1142. {
  1143. return container_of(wr, struct ib_reg_wr, wr);
  1144. }
  1145. struct ib_sig_handover_wr {
  1146. struct ib_send_wr wr;
  1147. struct ib_sig_attrs *sig_attrs;
  1148. struct ib_mr *sig_mr;
  1149. int access_flags;
  1150. struct ib_sge *prot;
  1151. };
  1152. static inline struct ib_sig_handover_wr *sig_handover_wr(struct ib_send_wr *wr)
  1153. {
  1154. return container_of(wr, struct ib_sig_handover_wr, wr);
  1155. }
  1156. struct ib_recv_wr {
  1157. struct ib_recv_wr *next;
  1158. union {
  1159. u64 wr_id;
  1160. struct ib_cqe *wr_cqe;
  1161. };
  1162. struct ib_sge *sg_list;
  1163. int num_sge;
  1164. };
  1165. enum ib_access_flags {
  1166. IB_ACCESS_LOCAL_WRITE = 1,
  1167. IB_ACCESS_REMOTE_WRITE = (1<<1),
  1168. IB_ACCESS_REMOTE_READ = (1<<2),
  1169. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  1170. IB_ACCESS_MW_BIND = (1<<4),
  1171. IB_ZERO_BASED = (1<<5),
  1172. IB_ACCESS_ON_DEMAND = (1<<6),
  1173. };
  1174. /*
  1175. * XXX: these are apparently used for ->rereg_user_mr, no idea why they
  1176. * are hidden here instead of a uapi header!
  1177. */
  1178. enum ib_mr_rereg_flags {
  1179. IB_MR_REREG_TRANS = 1,
  1180. IB_MR_REREG_PD = (1<<1),
  1181. IB_MR_REREG_ACCESS = (1<<2),
  1182. IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
  1183. };
  1184. struct ib_fmr_attr {
  1185. int max_pages;
  1186. int max_maps;
  1187. u8 page_shift;
  1188. };
  1189. struct ib_umem;
  1190. struct ib_ucontext {
  1191. struct ib_device *device;
  1192. struct list_head pd_list;
  1193. struct list_head mr_list;
  1194. struct list_head mw_list;
  1195. struct list_head cq_list;
  1196. struct list_head qp_list;
  1197. struct list_head srq_list;
  1198. struct list_head ah_list;
  1199. struct list_head xrcd_list;
  1200. struct list_head rule_list;
  1201. struct list_head wq_list;
  1202. struct list_head rwq_ind_tbl_list;
  1203. int closing;
  1204. struct pid *tgid;
  1205. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  1206. struct rb_root umem_tree;
  1207. /*
  1208. * Protects .umem_rbroot and tree, as well as odp_mrs_count and
  1209. * mmu notifiers registration.
  1210. */
  1211. struct rw_semaphore umem_rwsem;
  1212. void (*invalidate_range)(struct ib_umem *umem,
  1213. unsigned long start, unsigned long end);
  1214. struct mmu_notifier mn;
  1215. atomic_t notifier_count;
  1216. /* A list of umems that don't have private mmu notifier counters yet. */
  1217. struct list_head no_private_counters;
  1218. int odp_mrs_count;
  1219. #endif
  1220. };
  1221. struct ib_uobject {
  1222. u64 user_handle; /* handle given to us by userspace */
  1223. struct ib_ucontext *context; /* associated user context */
  1224. void *object; /* containing object */
  1225. struct list_head list; /* link to context's list */
  1226. int id; /* index into kernel idr */
  1227. struct kref ref;
  1228. struct rw_semaphore mutex; /* protects .live */
  1229. struct rcu_head rcu; /* kfree_rcu() overhead */
  1230. int live;
  1231. };
  1232. struct ib_udata {
  1233. const void __user *inbuf;
  1234. void __user *outbuf;
  1235. size_t inlen;
  1236. size_t outlen;
  1237. };
  1238. struct ib_pd {
  1239. u32 local_dma_lkey;
  1240. struct ib_device *device;
  1241. struct ib_uobject *uobject;
  1242. atomic_t usecnt; /* count all resources */
  1243. struct ib_mr *local_mr;
  1244. };
  1245. struct ib_xrcd {
  1246. struct ib_device *device;
  1247. atomic_t usecnt; /* count all exposed resources */
  1248. struct inode *inode;
  1249. struct mutex tgt_qp_mutex;
  1250. struct list_head tgt_qp_list;
  1251. };
  1252. struct ib_ah {
  1253. struct ib_device *device;
  1254. struct ib_pd *pd;
  1255. struct ib_uobject *uobject;
  1256. };
  1257. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  1258. enum ib_poll_context {
  1259. IB_POLL_DIRECT, /* caller context, no hw completions */
  1260. IB_POLL_SOFTIRQ, /* poll from softirq context */
  1261. IB_POLL_WORKQUEUE, /* poll from workqueue */
  1262. };
  1263. struct ib_cq {
  1264. struct ib_device *device;
  1265. struct ib_uobject *uobject;
  1266. ib_comp_handler comp_handler;
  1267. void (*event_handler)(struct ib_event *, void *);
  1268. void *cq_context;
  1269. int cqe;
  1270. atomic_t usecnt; /* count number of work queues */
  1271. enum ib_poll_context poll_ctx;
  1272. struct ib_wc *wc;
  1273. union {
  1274. struct irq_poll iop;
  1275. struct work_struct work;
  1276. };
  1277. };
  1278. struct ib_srq {
  1279. struct ib_device *device;
  1280. struct ib_pd *pd;
  1281. struct ib_uobject *uobject;
  1282. void (*event_handler)(struct ib_event *, void *);
  1283. void *srq_context;
  1284. enum ib_srq_type srq_type;
  1285. atomic_t usecnt;
  1286. union {
  1287. struct {
  1288. struct ib_xrcd *xrcd;
  1289. struct ib_cq *cq;
  1290. u32 srq_num;
  1291. } xrc;
  1292. } ext;
  1293. };
  1294. enum ib_wq_type {
  1295. IB_WQT_RQ
  1296. };
  1297. enum ib_wq_state {
  1298. IB_WQS_RESET,
  1299. IB_WQS_RDY,
  1300. IB_WQS_ERR
  1301. };
  1302. struct ib_wq {
  1303. struct ib_device *device;
  1304. struct ib_uobject *uobject;
  1305. void *wq_context;
  1306. void (*event_handler)(struct ib_event *, void *);
  1307. struct ib_pd *pd;
  1308. struct ib_cq *cq;
  1309. u32 wq_num;
  1310. enum ib_wq_state state;
  1311. enum ib_wq_type wq_type;
  1312. atomic_t usecnt;
  1313. };
  1314. struct ib_wq_init_attr {
  1315. void *wq_context;
  1316. enum ib_wq_type wq_type;
  1317. u32 max_wr;
  1318. u32 max_sge;
  1319. struct ib_cq *cq;
  1320. void (*event_handler)(struct ib_event *, void *);
  1321. };
  1322. enum ib_wq_attr_mask {
  1323. IB_WQ_STATE = 1 << 0,
  1324. IB_WQ_CUR_STATE = 1 << 1,
  1325. };
  1326. struct ib_wq_attr {
  1327. enum ib_wq_state wq_state;
  1328. enum ib_wq_state curr_wq_state;
  1329. };
  1330. struct ib_rwq_ind_table {
  1331. struct ib_device *device;
  1332. struct ib_uobject *uobject;
  1333. atomic_t usecnt;
  1334. u32 ind_tbl_num;
  1335. u32 log_ind_tbl_size;
  1336. struct ib_wq **ind_tbl;
  1337. };
  1338. struct ib_rwq_ind_table_init_attr {
  1339. u32 log_ind_tbl_size;
  1340. /* Each entry is a pointer to Receive Work Queue */
  1341. struct ib_wq **ind_tbl;
  1342. };
  1343. /*
  1344. * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
  1345. * @max_read_sge: Maximum SGE elements per RDMA READ request.
  1346. */
  1347. struct ib_qp {
  1348. struct ib_device *device;
  1349. struct ib_pd *pd;
  1350. struct ib_cq *send_cq;
  1351. struct ib_cq *recv_cq;
  1352. spinlock_t mr_lock;
  1353. int mrs_used;
  1354. struct list_head rdma_mrs;
  1355. struct list_head sig_mrs;
  1356. struct ib_srq *srq;
  1357. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  1358. struct list_head xrcd_list;
  1359. /* count times opened, mcast attaches, flow attaches */
  1360. atomic_t usecnt;
  1361. struct list_head open_list;
  1362. struct ib_qp *real_qp;
  1363. struct ib_uobject *uobject;
  1364. void (*event_handler)(struct ib_event *, void *);
  1365. void *qp_context;
  1366. u32 qp_num;
  1367. u32 max_write_sge;
  1368. u32 max_read_sge;
  1369. enum ib_qp_type qp_type;
  1370. struct ib_rwq_ind_table *rwq_ind_tbl;
  1371. };
  1372. struct ib_mr {
  1373. struct ib_device *device;
  1374. struct ib_pd *pd;
  1375. u32 lkey;
  1376. u32 rkey;
  1377. u64 iova;
  1378. u32 length;
  1379. unsigned int page_size;
  1380. bool need_inval;
  1381. union {
  1382. struct ib_uobject *uobject; /* user */
  1383. struct list_head qp_entry; /* FR */
  1384. };
  1385. };
  1386. struct ib_mw {
  1387. struct ib_device *device;
  1388. struct ib_pd *pd;
  1389. struct ib_uobject *uobject;
  1390. u32 rkey;
  1391. enum ib_mw_type type;
  1392. };
  1393. struct ib_fmr {
  1394. struct ib_device *device;
  1395. struct ib_pd *pd;
  1396. struct list_head list;
  1397. u32 lkey;
  1398. u32 rkey;
  1399. };
  1400. /* Supported steering options */
  1401. enum ib_flow_attr_type {
  1402. /* steering according to rule specifications */
  1403. IB_FLOW_ATTR_NORMAL = 0x0,
  1404. /* default unicast and multicast rule -
  1405. * receive all Eth traffic which isn't steered to any QP
  1406. */
  1407. IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
  1408. /* default multicast rule -
  1409. * receive all Eth multicast traffic which isn't steered to any QP
  1410. */
  1411. IB_FLOW_ATTR_MC_DEFAULT = 0x2,
  1412. /* sniffer rule - receive all port traffic */
  1413. IB_FLOW_ATTR_SNIFFER = 0x3
  1414. };
  1415. /* Supported steering header types */
  1416. enum ib_flow_spec_type {
  1417. /* L2 headers*/
  1418. IB_FLOW_SPEC_ETH = 0x20,
  1419. IB_FLOW_SPEC_IB = 0x22,
  1420. /* L3 header*/
  1421. IB_FLOW_SPEC_IPV4 = 0x30,
  1422. IB_FLOW_SPEC_IPV6 = 0x31,
  1423. /* L4 headers*/
  1424. IB_FLOW_SPEC_TCP = 0x40,
  1425. IB_FLOW_SPEC_UDP = 0x41
  1426. };
  1427. #define IB_FLOW_SPEC_LAYER_MASK 0xF0
  1428. #define IB_FLOW_SPEC_SUPPORT_LAYERS 4
  1429. /* Flow steering rule priority is set according to it's domain.
  1430. * Lower domain value means higher priority.
  1431. */
  1432. enum ib_flow_domain {
  1433. IB_FLOW_DOMAIN_USER,
  1434. IB_FLOW_DOMAIN_ETHTOOL,
  1435. IB_FLOW_DOMAIN_RFS,
  1436. IB_FLOW_DOMAIN_NIC,
  1437. IB_FLOW_DOMAIN_NUM /* Must be last */
  1438. };
  1439. enum ib_flow_flags {
  1440. IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
  1441. IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 2 /* Must be last */
  1442. };
  1443. struct ib_flow_eth_filter {
  1444. u8 dst_mac[6];
  1445. u8 src_mac[6];
  1446. __be16 ether_type;
  1447. __be16 vlan_tag;
  1448. };
  1449. struct ib_flow_spec_eth {
  1450. enum ib_flow_spec_type type;
  1451. u16 size;
  1452. struct ib_flow_eth_filter val;
  1453. struct ib_flow_eth_filter mask;
  1454. };
  1455. struct ib_flow_ib_filter {
  1456. __be16 dlid;
  1457. __u8 sl;
  1458. };
  1459. struct ib_flow_spec_ib {
  1460. enum ib_flow_spec_type type;
  1461. u16 size;
  1462. struct ib_flow_ib_filter val;
  1463. struct ib_flow_ib_filter mask;
  1464. };
  1465. struct ib_flow_ipv4_filter {
  1466. __be32 src_ip;
  1467. __be32 dst_ip;
  1468. };
  1469. struct ib_flow_spec_ipv4 {
  1470. enum ib_flow_spec_type type;
  1471. u16 size;
  1472. struct ib_flow_ipv4_filter val;
  1473. struct ib_flow_ipv4_filter mask;
  1474. };
  1475. struct ib_flow_ipv6_filter {
  1476. u8 src_ip[16];
  1477. u8 dst_ip[16];
  1478. };
  1479. struct ib_flow_spec_ipv6 {
  1480. enum ib_flow_spec_type type;
  1481. u16 size;
  1482. struct ib_flow_ipv6_filter val;
  1483. struct ib_flow_ipv6_filter mask;
  1484. };
  1485. struct ib_flow_tcp_udp_filter {
  1486. __be16 dst_port;
  1487. __be16 src_port;
  1488. };
  1489. struct ib_flow_spec_tcp_udp {
  1490. enum ib_flow_spec_type type;
  1491. u16 size;
  1492. struct ib_flow_tcp_udp_filter val;
  1493. struct ib_flow_tcp_udp_filter mask;
  1494. };
  1495. union ib_flow_spec {
  1496. struct {
  1497. enum ib_flow_spec_type type;
  1498. u16 size;
  1499. };
  1500. struct ib_flow_spec_eth eth;
  1501. struct ib_flow_spec_ib ib;
  1502. struct ib_flow_spec_ipv4 ipv4;
  1503. struct ib_flow_spec_tcp_udp tcp_udp;
  1504. struct ib_flow_spec_ipv6 ipv6;
  1505. };
  1506. struct ib_flow_attr {
  1507. enum ib_flow_attr_type type;
  1508. u16 size;
  1509. u16 priority;
  1510. u32 flags;
  1511. u8 num_of_specs;
  1512. u8 port;
  1513. /* Following are the optional layers according to user request
  1514. * struct ib_flow_spec_xxx
  1515. * struct ib_flow_spec_yyy
  1516. */
  1517. };
  1518. struct ib_flow {
  1519. struct ib_qp *qp;
  1520. struct ib_uobject *uobject;
  1521. };
  1522. struct ib_mad_hdr;
  1523. struct ib_grh;
  1524. enum ib_process_mad_flags {
  1525. IB_MAD_IGNORE_MKEY = 1,
  1526. IB_MAD_IGNORE_BKEY = 2,
  1527. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  1528. };
  1529. enum ib_mad_result {
  1530. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  1531. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  1532. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  1533. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  1534. };
  1535. #define IB_DEVICE_NAME_MAX 64
  1536. struct ib_cache {
  1537. rwlock_t lock;
  1538. struct ib_event_handler event_handler;
  1539. struct ib_pkey_cache **pkey_cache;
  1540. struct ib_gid_table **gid_cache;
  1541. u8 *lmc_cache;
  1542. };
  1543. struct ib_dma_mapping_ops {
  1544. int (*mapping_error)(struct ib_device *dev,
  1545. u64 dma_addr);
  1546. u64 (*map_single)(struct ib_device *dev,
  1547. void *ptr, size_t size,
  1548. enum dma_data_direction direction);
  1549. void (*unmap_single)(struct ib_device *dev,
  1550. u64 addr, size_t size,
  1551. enum dma_data_direction direction);
  1552. u64 (*map_page)(struct ib_device *dev,
  1553. struct page *page, unsigned long offset,
  1554. size_t size,
  1555. enum dma_data_direction direction);
  1556. void (*unmap_page)(struct ib_device *dev,
  1557. u64 addr, size_t size,
  1558. enum dma_data_direction direction);
  1559. int (*map_sg)(struct ib_device *dev,
  1560. struct scatterlist *sg, int nents,
  1561. enum dma_data_direction direction);
  1562. void (*unmap_sg)(struct ib_device *dev,
  1563. struct scatterlist *sg, int nents,
  1564. enum dma_data_direction direction);
  1565. void (*sync_single_for_cpu)(struct ib_device *dev,
  1566. u64 dma_handle,
  1567. size_t size,
  1568. enum dma_data_direction dir);
  1569. void (*sync_single_for_device)(struct ib_device *dev,
  1570. u64 dma_handle,
  1571. size_t size,
  1572. enum dma_data_direction dir);
  1573. void *(*alloc_coherent)(struct ib_device *dev,
  1574. size_t size,
  1575. u64 *dma_handle,
  1576. gfp_t flag);
  1577. void (*free_coherent)(struct ib_device *dev,
  1578. size_t size, void *cpu_addr,
  1579. u64 dma_handle);
  1580. };
  1581. struct iw_cm_verbs;
  1582. struct ib_port_immutable {
  1583. int pkey_tbl_len;
  1584. int gid_tbl_len;
  1585. u32 core_cap_flags;
  1586. u32 max_mad_size;
  1587. };
  1588. struct ib_device {
  1589. struct device *dma_device;
  1590. char name[IB_DEVICE_NAME_MAX];
  1591. struct list_head event_handler_list;
  1592. spinlock_t event_handler_lock;
  1593. spinlock_t client_data_lock;
  1594. struct list_head core_list;
  1595. /* Access to the client_data_list is protected by the client_data_lock
  1596. * spinlock and the lists_rwsem read-write semaphore */
  1597. struct list_head client_data_list;
  1598. struct ib_cache cache;
  1599. /**
  1600. * port_immutable is indexed by port number
  1601. */
  1602. struct ib_port_immutable *port_immutable;
  1603. int num_comp_vectors;
  1604. struct iw_cm_verbs *iwcm;
  1605. /**
  1606. * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
  1607. * driver initialized data. The struct is kfree()'ed by the sysfs
  1608. * core when the device is removed. A lifespan of -1 in the return
  1609. * struct tells the core to set a default lifespan.
  1610. */
  1611. struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
  1612. u8 port_num);
  1613. /**
  1614. * get_hw_stats - Fill in the counter value(s) in the stats struct.
  1615. * @index - The index in the value array we wish to have updated, or
  1616. * num_counters if we want all stats updated
  1617. * Return codes -
  1618. * < 0 - Error, no counters updated
  1619. * index - Updated the single counter pointed to by index
  1620. * num_counters - Updated all counters (will reset the timestamp
  1621. * and prevent further calls for lifespan milliseconds)
  1622. * Drivers are allowed to update all counters in leiu of just the
  1623. * one given in index at their option
  1624. */
  1625. int (*get_hw_stats)(struct ib_device *device,
  1626. struct rdma_hw_stats *stats,
  1627. u8 port, int index);
  1628. int (*query_device)(struct ib_device *device,
  1629. struct ib_device_attr *device_attr,
  1630. struct ib_udata *udata);
  1631. int (*query_port)(struct ib_device *device,
  1632. u8 port_num,
  1633. struct ib_port_attr *port_attr);
  1634. enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
  1635. u8 port_num);
  1636. /* When calling get_netdev, the HW vendor's driver should return the
  1637. * net device of device @device at port @port_num or NULL if such
  1638. * a net device doesn't exist. The vendor driver should call dev_hold
  1639. * on this net device. The HW vendor's device driver must guarantee
  1640. * that this function returns NULL before the net device reaches
  1641. * NETDEV_UNREGISTER_FINAL state.
  1642. */
  1643. struct net_device *(*get_netdev)(struct ib_device *device,
  1644. u8 port_num);
  1645. int (*query_gid)(struct ib_device *device,
  1646. u8 port_num, int index,
  1647. union ib_gid *gid);
  1648. /* When calling add_gid, the HW vendor's driver should
  1649. * add the gid of device @device at gid index @index of
  1650. * port @port_num to be @gid. Meta-info of that gid (for example,
  1651. * the network device related to this gid is available
  1652. * at @attr. @context allows the HW vendor driver to store extra
  1653. * information together with a GID entry. The HW vendor may allocate
  1654. * memory to contain this information and store it in @context when a
  1655. * new GID entry is written to. Params are consistent until the next
  1656. * call of add_gid or delete_gid. The function should return 0 on
  1657. * success or error otherwise. The function could be called
  1658. * concurrently for different ports. This function is only called
  1659. * when roce_gid_table is used.
  1660. */
  1661. int (*add_gid)(struct ib_device *device,
  1662. u8 port_num,
  1663. unsigned int index,
  1664. const union ib_gid *gid,
  1665. const struct ib_gid_attr *attr,
  1666. void **context);
  1667. /* When calling del_gid, the HW vendor's driver should delete the
  1668. * gid of device @device at gid index @index of port @port_num.
  1669. * Upon the deletion of a GID entry, the HW vendor must free any
  1670. * allocated memory. The caller will clear @context afterwards.
  1671. * This function is only called when roce_gid_table is used.
  1672. */
  1673. int (*del_gid)(struct ib_device *device,
  1674. u8 port_num,
  1675. unsigned int index,
  1676. void **context);
  1677. int (*query_pkey)(struct ib_device *device,
  1678. u8 port_num, u16 index, u16 *pkey);
  1679. int (*modify_device)(struct ib_device *device,
  1680. int device_modify_mask,
  1681. struct ib_device_modify *device_modify);
  1682. int (*modify_port)(struct ib_device *device,
  1683. u8 port_num, int port_modify_mask,
  1684. struct ib_port_modify *port_modify);
  1685. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  1686. struct ib_udata *udata);
  1687. int (*dealloc_ucontext)(struct ib_ucontext *context);
  1688. int (*mmap)(struct ib_ucontext *context,
  1689. struct vm_area_struct *vma);
  1690. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  1691. struct ib_ucontext *context,
  1692. struct ib_udata *udata);
  1693. int (*dealloc_pd)(struct ib_pd *pd);
  1694. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  1695. struct ib_ah_attr *ah_attr);
  1696. int (*modify_ah)(struct ib_ah *ah,
  1697. struct ib_ah_attr *ah_attr);
  1698. int (*query_ah)(struct ib_ah *ah,
  1699. struct ib_ah_attr *ah_attr);
  1700. int (*destroy_ah)(struct ib_ah *ah);
  1701. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  1702. struct ib_srq_init_attr *srq_init_attr,
  1703. struct ib_udata *udata);
  1704. int (*modify_srq)(struct ib_srq *srq,
  1705. struct ib_srq_attr *srq_attr,
  1706. enum ib_srq_attr_mask srq_attr_mask,
  1707. struct ib_udata *udata);
  1708. int (*query_srq)(struct ib_srq *srq,
  1709. struct ib_srq_attr *srq_attr);
  1710. int (*destroy_srq)(struct ib_srq *srq);
  1711. int (*post_srq_recv)(struct ib_srq *srq,
  1712. struct ib_recv_wr *recv_wr,
  1713. struct ib_recv_wr **bad_recv_wr);
  1714. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  1715. struct ib_qp_init_attr *qp_init_attr,
  1716. struct ib_udata *udata);
  1717. int (*modify_qp)(struct ib_qp *qp,
  1718. struct ib_qp_attr *qp_attr,
  1719. int qp_attr_mask,
  1720. struct ib_udata *udata);
  1721. int (*query_qp)(struct ib_qp *qp,
  1722. struct ib_qp_attr *qp_attr,
  1723. int qp_attr_mask,
  1724. struct ib_qp_init_attr *qp_init_attr);
  1725. int (*destroy_qp)(struct ib_qp *qp);
  1726. int (*post_send)(struct ib_qp *qp,
  1727. struct ib_send_wr *send_wr,
  1728. struct ib_send_wr **bad_send_wr);
  1729. int (*post_recv)(struct ib_qp *qp,
  1730. struct ib_recv_wr *recv_wr,
  1731. struct ib_recv_wr **bad_recv_wr);
  1732. struct ib_cq * (*create_cq)(struct ib_device *device,
  1733. const struct ib_cq_init_attr *attr,
  1734. struct ib_ucontext *context,
  1735. struct ib_udata *udata);
  1736. int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
  1737. u16 cq_period);
  1738. int (*destroy_cq)(struct ib_cq *cq);
  1739. int (*resize_cq)(struct ib_cq *cq, int cqe,
  1740. struct ib_udata *udata);
  1741. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  1742. struct ib_wc *wc);
  1743. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  1744. int (*req_notify_cq)(struct ib_cq *cq,
  1745. enum ib_cq_notify_flags flags);
  1746. int (*req_ncomp_notif)(struct ib_cq *cq,
  1747. int wc_cnt);
  1748. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  1749. int mr_access_flags);
  1750. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  1751. u64 start, u64 length,
  1752. u64 virt_addr,
  1753. int mr_access_flags,
  1754. struct ib_udata *udata);
  1755. int (*rereg_user_mr)(struct ib_mr *mr,
  1756. int flags,
  1757. u64 start, u64 length,
  1758. u64 virt_addr,
  1759. int mr_access_flags,
  1760. struct ib_pd *pd,
  1761. struct ib_udata *udata);
  1762. int (*dereg_mr)(struct ib_mr *mr);
  1763. struct ib_mr * (*alloc_mr)(struct ib_pd *pd,
  1764. enum ib_mr_type mr_type,
  1765. u32 max_num_sg);
  1766. int (*map_mr_sg)(struct ib_mr *mr,
  1767. struct scatterlist *sg,
  1768. int sg_nents,
  1769. unsigned int *sg_offset);
  1770. struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
  1771. enum ib_mw_type type,
  1772. struct ib_udata *udata);
  1773. int (*dealloc_mw)(struct ib_mw *mw);
  1774. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  1775. int mr_access_flags,
  1776. struct ib_fmr_attr *fmr_attr);
  1777. int (*map_phys_fmr)(struct ib_fmr *fmr,
  1778. u64 *page_list, int list_len,
  1779. u64 iova);
  1780. int (*unmap_fmr)(struct list_head *fmr_list);
  1781. int (*dealloc_fmr)(struct ib_fmr *fmr);
  1782. int (*attach_mcast)(struct ib_qp *qp,
  1783. union ib_gid *gid,
  1784. u16 lid);
  1785. int (*detach_mcast)(struct ib_qp *qp,
  1786. union ib_gid *gid,
  1787. u16 lid);
  1788. int (*process_mad)(struct ib_device *device,
  1789. int process_mad_flags,
  1790. u8 port_num,
  1791. const struct ib_wc *in_wc,
  1792. const struct ib_grh *in_grh,
  1793. const struct ib_mad_hdr *in_mad,
  1794. size_t in_mad_size,
  1795. struct ib_mad_hdr *out_mad,
  1796. size_t *out_mad_size,
  1797. u16 *out_mad_pkey_index);
  1798. struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
  1799. struct ib_ucontext *ucontext,
  1800. struct ib_udata *udata);
  1801. int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
  1802. struct ib_flow * (*create_flow)(struct ib_qp *qp,
  1803. struct ib_flow_attr
  1804. *flow_attr,
  1805. int domain);
  1806. int (*destroy_flow)(struct ib_flow *flow_id);
  1807. int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
  1808. struct ib_mr_status *mr_status);
  1809. void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
  1810. void (*drain_rq)(struct ib_qp *qp);
  1811. void (*drain_sq)(struct ib_qp *qp);
  1812. int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
  1813. int state);
  1814. int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
  1815. struct ifla_vf_info *ivf);
  1816. int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
  1817. struct ifla_vf_stats *stats);
  1818. int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
  1819. int type);
  1820. struct ib_wq * (*create_wq)(struct ib_pd *pd,
  1821. struct ib_wq_init_attr *init_attr,
  1822. struct ib_udata *udata);
  1823. int (*destroy_wq)(struct ib_wq *wq);
  1824. int (*modify_wq)(struct ib_wq *wq,
  1825. struct ib_wq_attr *attr,
  1826. u32 wq_attr_mask,
  1827. struct ib_udata *udata);
  1828. struct ib_rwq_ind_table * (*create_rwq_ind_table)(struct ib_device *device,
  1829. struct ib_rwq_ind_table_init_attr *init_attr,
  1830. struct ib_udata *udata);
  1831. int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
  1832. struct ib_dma_mapping_ops *dma_ops;
  1833. struct module *owner;
  1834. struct device dev;
  1835. struct kobject *ports_parent;
  1836. struct list_head port_list;
  1837. enum {
  1838. IB_DEV_UNINITIALIZED,
  1839. IB_DEV_REGISTERED,
  1840. IB_DEV_UNREGISTERED
  1841. } reg_state;
  1842. int uverbs_abi_ver;
  1843. u64 uverbs_cmd_mask;
  1844. u64 uverbs_ex_cmd_mask;
  1845. char node_desc[64];
  1846. __be64 node_guid;
  1847. u32 local_dma_lkey;
  1848. u16 is_switch:1;
  1849. u8 node_type;
  1850. u8 phys_port_cnt;
  1851. struct ib_device_attr attrs;
  1852. struct attribute_group *hw_stats_ag;
  1853. struct rdma_hw_stats *hw_stats;
  1854. /**
  1855. * The following mandatory functions are used only at device
  1856. * registration. Keep functions such as these at the end of this
  1857. * structure to avoid cache line misses when accessing struct ib_device
  1858. * in fast paths.
  1859. */
  1860. int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
  1861. void (*get_dev_fw_str)(struct ib_device *, char *str, size_t str_len);
  1862. };
  1863. struct ib_client {
  1864. char *name;
  1865. void (*add) (struct ib_device *);
  1866. void (*remove)(struct ib_device *, void *client_data);
  1867. /* Returns the net_dev belonging to this ib_client and matching the
  1868. * given parameters.
  1869. * @dev: An RDMA device that the net_dev use for communication.
  1870. * @port: A physical port number on the RDMA device.
  1871. * @pkey: P_Key that the net_dev uses if applicable.
  1872. * @gid: A GID that the net_dev uses to communicate.
  1873. * @addr: An IP address the net_dev is configured with.
  1874. * @client_data: The device's client data set by ib_set_client_data().
  1875. *
  1876. * An ib_client that implements a net_dev on top of RDMA devices
  1877. * (such as IP over IB) should implement this callback, allowing the
  1878. * rdma_cm module to find the right net_dev for a given request.
  1879. *
  1880. * The caller is responsible for calling dev_put on the returned
  1881. * netdev. */
  1882. struct net_device *(*get_net_dev_by_params)(
  1883. struct ib_device *dev,
  1884. u8 port,
  1885. u16 pkey,
  1886. const union ib_gid *gid,
  1887. const struct sockaddr *addr,
  1888. void *client_data);
  1889. struct list_head list;
  1890. };
  1891. struct ib_device *ib_alloc_device(size_t size);
  1892. void ib_dealloc_device(struct ib_device *device);
  1893. void ib_get_device_fw_str(struct ib_device *device, char *str, size_t str_len);
  1894. int ib_register_device(struct ib_device *device,
  1895. int (*port_callback)(struct ib_device *,
  1896. u8, struct kobject *));
  1897. void ib_unregister_device(struct ib_device *device);
  1898. int ib_register_client (struct ib_client *client);
  1899. void ib_unregister_client(struct ib_client *client);
  1900. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  1901. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  1902. void *data);
  1903. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  1904. {
  1905. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  1906. }
  1907. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  1908. {
  1909. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  1910. }
  1911. static inline bool ib_is_udata_cleared(struct ib_udata *udata,
  1912. size_t offset,
  1913. size_t len)
  1914. {
  1915. const void __user *p = udata->inbuf + offset;
  1916. bool ret;
  1917. u8 *buf;
  1918. if (len > USHRT_MAX)
  1919. return false;
  1920. buf = memdup_user(p, len);
  1921. if (IS_ERR(buf))
  1922. return false;
  1923. ret = !memchr_inv(buf, 0, len);
  1924. kfree(buf);
  1925. return ret;
  1926. }
  1927. /**
  1928. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  1929. * contains all required attributes and no attributes not allowed for
  1930. * the given QP state transition.
  1931. * @cur_state: Current QP state
  1932. * @next_state: Next QP state
  1933. * @type: QP type
  1934. * @mask: Mask of supplied QP attributes
  1935. * @ll : link layer of port
  1936. *
  1937. * This function is a helper function that a low-level driver's
  1938. * modify_qp method can use to validate the consumer's input. It
  1939. * checks that cur_state and next_state are valid QP states, that a
  1940. * transition from cur_state to next_state is allowed by the IB spec,
  1941. * and that the attribute mask supplied is allowed for the transition.
  1942. */
  1943. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  1944. enum ib_qp_type type, enum ib_qp_attr_mask mask,
  1945. enum rdma_link_layer ll);
  1946. int ib_register_event_handler (struct ib_event_handler *event_handler);
  1947. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  1948. void ib_dispatch_event(struct ib_event *event);
  1949. int ib_query_port(struct ib_device *device,
  1950. u8 port_num, struct ib_port_attr *port_attr);
  1951. enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
  1952. u8 port_num);
  1953. /**
  1954. * rdma_cap_ib_switch - Check if the device is IB switch
  1955. * @device: Device to check
  1956. *
  1957. * Device driver is responsible for setting is_switch bit on
  1958. * in ib_device structure at init time.
  1959. *
  1960. * Return: true if the device is IB switch.
  1961. */
  1962. static inline bool rdma_cap_ib_switch(const struct ib_device *device)
  1963. {
  1964. return device->is_switch;
  1965. }
  1966. /**
  1967. * rdma_start_port - Return the first valid port number for the device
  1968. * specified
  1969. *
  1970. * @device: Device to be checked
  1971. *
  1972. * Return start port number
  1973. */
  1974. static inline u8 rdma_start_port(const struct ib_device *device)
  1975. {
  1976. return rdma_cap_ib_switch(device) ? 0 : 1;
  1977. }
  1978. /**
  1979. * rdma_end_port - Return the last valid port number for the device
  1980. * specified
  1981. *
  1982. * @device: Device to be checked
  1983. *
  1984. * Return last port number
  1985. */
  1986. static inline u8 rdma_end_port(const struct ib_device *device)
  1987. {
  1988. return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
  1989. }
  1990. static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
  1991. {
  1992. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
  1993. }
  1994. static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
  1995. {
  1996. return device->port_immutable[port_num].core_cap_flags &
  1997. (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
  1998. }
  1999. static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
  2000. {
  2001. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
  2002. }
  2003. static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
  2004. {
  2005. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
  2006. }
  2007. static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
  2008. {
  2009. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
  2010. }
  2011. static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
  2012. {
  2013. return rdma_protocol_ib(device, port_num) ||
  2014. rdma_protocol_roce(device, port_num);
  2015. }
  2016. /**
  2017. * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
  2018. * Management Datagrams.
  2019. * @device: Device to check
  2020. * @port_num: Port number to check
  2021. *
  2022. * Management Datagrams (MAD) are a required part of the InfiniBand
  2023. * specification and are supported on all InfiniBand devices. A slightly
  2024. * extended version are also supported on OPA interfaces.
  2025. *
  2026. * Return: true if the port supports sending/receiving of MAD packets.
  2027. */
  2028. static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
  2029. {
  2030. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
  2031. }
  2032. /**
  2033. * rdma_cap_opa_mad - Check if the port of device provides support for OPA
  2034. * Management Datagrams.
  2035. * @device: Device to check
  2036. * @port_num: Port number to check
  2037. *
  2038. * Intel OmniPath devices extend and/or replace the InfiniBand Management
  2039. * datagrams with their own versions. These OPA MADs share many but not all of
  2040. * the characteristics of InfiniBand MADs.
  2041. *
  2042. * OPA MADs differ in the following ways:
  2043. *
  2044. * 1) MADs are variable size up to 2K
  2045. * IBTA defined MADs remain fixed at 256 bytes
  2046. * 2) OPA SMPs must carry valid PKeys
  2047. * 3) OPA SMP packets are a different format
  2048. *
  2049. * Return: true if the port supports OPA MAD packet formats.
  2050. */
  2051. static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
  2052. {
  2053. return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
  2054. == RDMA_CORE_CAP_OPA_MAD;
  2055. }
  2056. /**
  2057. * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
  2058. * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
  2059. * @device: Device to check
  2060. * @port_num: Port number to check
  2061. *
  2062. * Each InfiniBand node is required to provide a Subnet Management Agent
  2063. * that the subnet manager can access. Prior to the fabric being fully
  2064. * configured by the subnet manager, the SMA is accessed via a well known
  2065. * interface called the Subnet Management Interface (SMI). This interface
  2066. * uses directed route packets to communicate with the SM to get around the
  2067. * chicken and egg problem of the SM needing to know what's on the fabric
  2068. * in order to configure the fabric, and needing to configure the fabric in
  2069. * order to send packets to the devices on the fabric. These directed
  2070. * route packets do not need the fabric fully configured in order to reach
  2071. * their destination. The SMI is the only method allowed to send
  2072. * directed route packets on an InfiniBand fabric.
  2073. *
  2074. * Return: true if the port provides an SMI.
  2075. */
  2076. static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
  2077. {
  2078. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
  2079. }
  2080. /**
  2081. * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
  2082. * Communication Manager.
  2083. * @device: Device to check
  2084. * @port_num: Port number to check
  2085. *
  2086. * The InfiniBand Communication Manager is one of many pre-defined General
  2087. * Service Agents (GSA) that are accessed via the General Service
  2088. * Interface (GSI). It's role is to facilitate establishment of connections
  2089. * between nodes as well as other management related tasks for established
  2090. * connections.
  2091. *
  2092. * Return: true if the port supports an IB CM (this does not guarantee that
  2093. * a CM is actually running however).
  2094. */
  2095. static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
  2096. {
  2097. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
  2098. }
  2099. /**
  2100. * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
  2101. * Communication Manager.
  2102. * @device: Device to check
  2103. * @port_num: Port number to check
  2104. *
  2105. * Similar to above, but specific to iWARP connections which have a different
  2106. * managment protocol than InfiniBand.
  2107. *
  2108. * Return: true if the port supports an iWARP CM (this does not guarantee that
  2109. * a CM is actually running however).
  2110. */
  2111. static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
  2112. {
  2113. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
  2114. }
  2115. /**
  2116. * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
  2117. * Subnet Administration.
  2118. * @device: Device to check
  2119. * @port_num: Port number to check
  2120. *
  2121. * An InfiniBand Subnet Administration (SA) service is a pre-defined General
  2122. * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
  2123. * fabrics, devices should resolve routes to other hosts by contacting the
  2124. * SA to query the proper route.
  2125. *
  2126. * Return: true if the port should act as a client to the fabric Subnet
  2127. * Administration interface. This does not imply that the SA service is
  2128. * running locally.
  2129. */
  2130. static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
  2131. {
  2132. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
  2133. }
  2134. /**
  2135. * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
  2136. * Multicast.
  2137. * @device: Device to check
  2138. * @port_num: Port number to check
  2139. *
  2140. * InfiniBand multicast registration is more complex than normal IPv4 or
  2141. * IPv6 multicast registration. Each Host Channel Adapter must register
  2142. * with the Subnet Manager when it wishes to join a multicast group. It
  2143. * should do so only once regardless of how many queue pairs it subscribes
  2144. * to this group. And it should leave the group only after all queue pairs
  2145. * attached to the group have been detached.
  2146. *
  2147. * Return: true if the port must undertake the additional adminstrative
  2148. * overhead of registering/unregistering with the SM and tracking of the
  2149. * total number of queue pairs attached to the multicast group.
  2150. */
  2151. static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
  2152. {
  2153. return rdma_cap_ib_sa(device, port_num);
  2154. }
  2155. /**
  2156. * rdma_cap_af_ib - Check if the port of device has the capability
  2157. * Native Infiniband Address.
  2158. * @device: Device to check
  2159. * @port_num: Port number to check
  2160. *
  2161. * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
  2162. * GID. RoCE uses a different mechanism, but still generates a GID via
  2163. * a prescribed mechanism and port specific data.
  2164. *
  2165. * Return: true if the port uses a GID address to identify devices on the
  2166. * network.
  2167. */
  2168. static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
  2169. {
  2170. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
  2171. }
  2172. /**
  2173. * rdma_cap_eth_ah - Check if the port of device has the capability
  2174. * Ethernet Address Handle.
  2175. * @device: Device to check
  2176. * @port_num: Port number to check
  2177. *
  2178. * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
  2179. * to fabricate GIDs over Ethernet/IP specific addresses native to the
  2180. * port. Normally, packet headers are generated by the sending host
  2181. * adapter, but when sending connectionless datagrams, we must manually
  2182. * inject the proper headers for the fabric we are communicating over.
  2183. *
  2184. * Return: true if we are running as a RoCE port and must force the
  2185. * addition of a Global Route Header built from our Ethernet Address
  2186. * Handle into our header list for connectionless packets.
  2187. */
  2188. static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
  2189. {
  2190. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
  2191. }
  2192. /**
  2193. * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
  2194. *
  2195. * @device: Device
  2196. * @port_num: Port number
  2197. *
  2198. * This MAD size includes the MAD headers and MAD payload. No other headers
  2199. * are included.
  2200. *
  2201. * Return the max MAD size required by the Port. Will return 0 if the port
  2202. * does not support MADs
  2203. */
  2204. static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
  2205. {
  2206. return device->port_immutable[port_num].max_mad_size;
  2207. }
  2208. /**
  2209. * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
  2210. * @device: Device to check
  2211. * @port_num: Port number to check
  2212. *
  2213. * RoCE GID table mechanism manages the various GIDs for a device.
  2214. *
  2215. * NOTE: if allocating the port's GID table has failed, this call will still
  2216. * return true, but any RoCE GID table API will fail.
  2217. *
  2218. * Return: true if the port uses RoCE GID table mechanism in order to manage
  2219. * its GIDs.
  2220. */
  2221. static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
  2222. u8 port_num)
  2223. {
  2224. return rdma_protocol_roce(device, port_num) &&
  2225. device->add_gid && device->del_gid;
  2226. }
  2227. /*
  2228. * Check if the device supports READ W/ INVALIDATE.
  2229. */
  2230. static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
  2231. {
  2232. /*
  2233. * iWarp drivers must support READ W/ INVALIDATE. No other protocol
  2234. * has support for it yet.
  2235. */
  2236. return rdma_protocol_iwarp(dev, port_num);
  2237. }
  2238. int ib_query_gid(struct ib_device *device,
  2239. u8 port_num, int index, union ib_gid *gid,
  2240. struct ib_gid_attr *attr);
  2241. int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
  2242. int state);
  2243. int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
  2244. struct ifla_vf_info *info);
  2245. int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
  2246. struct ifla_vf_stats *stats);
  2247. int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
  2248. int type);
  2249. int ib_query_pkey(struct ib_device *device,
  2250. u8 port_num, u16 index, u16 *pkey);
  2251. int ib_modify_device(struct ib_device *device,
  2252. int device_modify_mask,
  2253. struct ib_device_modify *device_modify);
  2254. int ib_modify_port(struct ib_device *device,
  2255. u8 port_num, int port_modify_mask,
  2256. struct ib_port_modify *port_modify);
  2257. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  2258. enum ib_gid_type gid_type, struct net_device *ndev,
  2259. u8 *port_num, u16 *index);
  2260. int ib_find_pkey(struct ib_device *device,
  2261. u8 port_num, u16 pkey, u16 *index);
  2262. struct ib_pd *ib_alloc_pd(struct ib_device *device);
  2263. void ib_dealloc_pd(struct ib_pd *pd);
  2264. /**
  2265. * ib_create_ah - Creates an address handle for the given address vector.
  2266. * @pd: The protection domain associated with the address handle.
  2267. * @ah_attr: The attributes of the address vector.
  2268. *
  2269. * The address handle is used to reference a local or global destination
  2270. * in all UD QP post sends.
  2271. */
  2272. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  2273. /**
  2274. * ib_init_ah_from_wc - Initializes address handle attributes from a
  2275. * work completion.
  2276. * @device: Device on which the received message arrived.
  2277. * @port_num: Port on which the received message arrived.
  2278. * @wc: Work completion associated with the received message.
  2279. * @grh: References the received global route header. This parameter is
  2280. * ignored unless the work completion indicates that the GRH is valid.
  2281. * @ah_attr: Returned attributes that can be used when creating an address
  2282. * handle for replying to the message.
  2283. */
  2284. int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
  2285. const struct ib_wc *wc, const struct ib_grh *grh,
  2286. struct ib_ah_attr *ah_attr);
  2287. /**
  2288. * ib_create_ah_from_wc - Creates an address handle associated with the
  2289. * sender of the specified work completion.
  2290. * @pd: The protection domain associated with the address handle.
  2291. * @wc: Work completion information associated with a received message.
  2292. * @grh: References the received global route header. This parameter is
  2293. * ignored unless the work completion indicates that the GRH is valid.
  2294. * @port_num: The outbound port number to associate with the address.
  2295. *
  2296. * The address handle is used to reference a local or global destination
  2297. * in all UD QP post sends.
  2298. */
  2299. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
  2300. const struct ib_grh *grh, u8 port_num);
  2301. /**
  2302. * ib_modify_ah - Modifies the address vector associated with an address
  2303. * handle.
  2304. * @ah: The address handle to modify.
  2305. * @ah_attr: The new address vector attributes to associate with the
  2306. * address handle.
  2307. */
  2308. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  2309. /**
  2310. * ib_query_ah - Queries the address vector associated with an address
  2311. * handle.
  2312. * @ah: The address handle to query.
  2313. * @ah_attr: The address vector attributes associated with the address
  2314. * handle.
  2315. */
  2316. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  2317. /**
  2318. * ib_destroy_ah - Destroys an address handle.
  2319. * @ah: The address handle to destroy.
  2320. */
  2321. int ib_destroy_ah(struct ib_ah *ah);
  2322. /**
  2323. * ib_create_srq - Creates a SRQ associated with the specified protection
  2324. * domain.
  2325. * @pd: The protection domain associated with the SRQ.
  2326. * @srq_init_attr: A list of initial attributes required to create the
  2327. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  2328. * the actual capabilities of the created SRQ.
  2329. *
  2330. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  2331. * requested size of the SRQ, and set to the actual values allocated
  2332. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  2333. * will always be at least as large as the requested values.
  2334. */
  2335. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  2336. struct ib_srq_init_attr *srq_init_attr);
  2337. /**
  2338. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  2339. * @srq: The SRQ to modify.
  2340. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  2341. * the current values of selected SRQ attributes are returned.
  2342. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  2343. * are being modified.
  2344. *
  2345. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  2346. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  2347. * the number of receives queued drops below the limit.
  2348. */
  2349. int ib_modify_srq(struct ib_srq *srq,
  2350. struct ib_srq_attr *srq_attr,
  2351. enum ib_srq_attr_mask srq_attr_mask);
  2352. /**
  2353. * ib_query_srq - Returns the attribute list and current values for the
  2354. * specified SRQ.
  2355. * @srq: The SRQ to query.
  2356. * @srq_attr: The attributes of the specified SRQ.
  2357. */
  2358. int ib_query_srq(struct ib_srq *srq,
  2359. struct ib_srq_attr *srq_attr);
  2360. /**
  2361. * ib_destroy_srq - Destroys the specified SRQ.
  2362. * @srq: The SRQ to destroy.
  2363. */
  2364. int ib_destroy_srq(struct ib_srq *srq);
  2365. /**
  2366. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  2367. * @srq: The SRQ to post the work request on.
  2368. * @recv_wr: A list of work requests to post on the receive queue.
  2369. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2370. * the work request that failed to be posted on the QP.
  2371. */
  2372. static inline int ib_post_srq_recv(struct ib_srq *srq,
  2373. struct ib_recv_wr *recv_wr,
  2374. struct ib_recv_wr **bad_recv_wr)
  2375. {
  2376. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  2377. }
  2378. /**
  2379. * ib_create_qp - Creates a QP associated with the specified protection
  2380. * domain.
  2381. * @pd: The protection domain associated with the QP.
  2382. * @qp_init_attr: A list of initial attributes required to create the
  2383. * QP. If QP creation succeeds, then the attributes are updated to
  2384. * the actual capabilities of the created QP.
  2385. */
  2386. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  2387. struct ib_qp_init_attr *qp_init_attr);
  2388. /**
  2389. * ib_modify_qp - Modifies the attributes for the specified QP and then
  2390. * transitions the QP to the given state.
  2391. * @qp: The QP to modify.
  2392. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  2393. * the current values of selected QP attributes are returned.
  2394. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  2395. * are being modified.
  2396. */
  2397. int ib_modify_qp(struct ib_qp *qp,
  2398. struct ib_qp_attr *qp_attr,
  2399. int qp_attr_mask);
  2400. /**
  2401. * ib_query_qp - Returns the attribute list and current values for the
  2402. * specified QP.
  2403. * @qp: The QP to query.
  2404. * @qp_attr: The attributes of the specified QP.
  2405. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  2406. * @qp_init_attr: Additional attributes of the selected QP.
  2407. *
  2408. * The qp_attr_mask may be used to limit the query to gathering only the
  2409. * selected attributes.
  2410. */
  2411. int ib_query_qp(struct ib_qp *qp,
  2412. struct ib_qp_attr *qp_attr,
  2413. int qp_attr_mask,
  2414. struct ib_qp_init_attr *qp_init_attr);
  2415. /**
  2416. * ib_destroy_qp - Destroys the specified QP.
  2417. * @qp: The QP to destroy.
  2418. */
  2419. int ib_destroy_qp(struct ib_qp *qp);
  2420. /**
  2421. * ib_open_qp - Obtain a reference to an existing sharable QP.
  2422. * @xrcd - XRC domain
  2423. * @qp_open_attr: Attributes identifying the QP to open.
  2424. *
  2425. * Returns a reference to a sharable QP.
  2426. */
  2427. struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
  2428. struct ib_qp_open_attr *qp_open_attr);
  2429. /**
  2430. * ib_close_qp - Release an external reference to a QP.
  2431. * @qp: The QP handle to release
  2432. *
  2433. * The opened QP handle is released by the caller. The underlying
  2434. * shared QP is not destroyed until all internal references are released.
  2435. */
  2436. int ib_close_qp(struct ib_qp *qp);
  2437. /**
  2438. * ib_post_send - Posts a list of work requests to the send queue of
  2439. * the specified QP.
  2440. * @qp: The QP to post the work request on.
  2441. * @send_wr: A list of work requests to post on the send queue.
  2442. * @bad_send_wr: On an immediate failure, this parameter will reference
  2443. * the work request that failed to be posted on the QP.
  2444. *
  2445. * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
  2446. * error is returned, the QP state shall not be affected,
  2447. * ib_post_send() will return an immediate error after queueing any
  2448. * earlier work requests in the list.
  2449. */
  2450. static inline int ib_post_send(struct ib_qp *qp,
  2451. struct ib_send_wr *send_wr,
  2452. struct ib_send_wr **bad_send_wr)
  2453. {
  2454. return qp->device->post_send(qp, send_wr, bad_send_wr);
  2455. }
  2456. /**
  2457. * ib_post_recv - Posts a list of work requests to the receive queue of
  2458. * the specified QP.
  2459. * @qp: The QP to post the work request on.
  2460. * @recv_wr: A list of work requests to post on the receive queue.
  2461. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2462. * the work request that failed to be posted on the QP.
  2463. */
  2464. static inline int ib_post_recv(struct ib_qp *qp,
  2465. struct ib_recv_wr *recv_wr,
  2466. struct ib_recv_wr **bad_recv_wr)
  2467. {
  2468. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  2469. }
  2470. struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
  2471. int nr_cqe, int comp_vector, enum ib_poll_context poll_ctx);
  2472. void ib_free_cq(struct ib_cq *cq);
  2473. int ib_process_cq_direct(struct ib_cq *cq, int budget);
  2474. /**
  2475. * ib_create_cq - Creates a CQ on the specified device.
  2476. * @device: The device on which to create the CQ.
  2477. * @comp_handler: A user-specified callback that is invoked when a
  2478. * completion event occurs on the CQ.
  2479. * @event_handler: A user-specified callback that is invoked when an
  2480. * asynchronous event not associated with a completion occurs on the CQ.
  2481. * @cq_context: Context associated with the CQ returned to the user via
  2482. * the associated completion and event handlers.
  2483. * @cq_attr: The attributes the CQ should be created upon.
  2484. *
  2485. * Users can examine the cq structure to determine the actual CQ size.
  2486. */
  2487. struct ib_cq *ib_create_cq(struct ib_device *device,
  2488. ib_comp_handler comp_handler,
  2489. void (*event_handler)(struct ib_event *, void *),
  2490. void *cq_context,
  2491. const struct ib_cq_init_attr *cq_attr);
  2492. /**
  2493. * ib_resize_cq - Modifies the capacity of the CQ.
  2494. * @cq: The CQ to resize.
  2495. * @cqe: The minimum size of the CQ.
  2496. *
  2497. * Users can examine the cq structure to determine the actual CQ size.
  2498. */
  2499. int ib_resize_cq(struct ib_cq *cq, int cqe);
  2500. /**
  2501. * ib_modify_cq - Modifies moderation params of the CQ
  2502. * @cq: The CQ to modify.
  2503. * @cq_count: number of CQEs that will trigger an event
  2504. * @cq_period: max period of time in usec before triggering an event
  2505. *
  2506. */
  2507. int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  2508. /**
  2509. * ib_destroy_cq - Destroys the specified CQ.
  2510. * @cq: The CQ to destroy.
  2511. */
  2512. int ib_destroy_cq(struct ib_cq *cq);
  2513. /**
  2514. * ib_poll_cq - poll a CQ for completion(s)
  2515. * @cq:the CQ being polled
  2516. * @num_entries:maximum number of completions to return
  2517. * @wc:array of at least @num_entries &struct ib_wc where completions
  2518. * will be returned
  2519. *
  2520. * Poll a CQ for (possibly multiple) completions. If the return value
  2521. * is < 0, an error occurred. If the return value is >= 0, it is the
  2522. * number of completions returned. If the return value is
  2523. * non-negative and < num_entries, then the CQ was emptied.
  2524. */
  2525. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  2526. struct ib_wc *wc)
  2527. {
  2528. return cq->device->poll_cq(cq, num_entries, wc);
  2529. }
  2530. /**
  2531. * ib_peek_cq - Returns the number of unreaped completions currently
  2532. * on the specified CQ.
  2533. * @cq: The CQ to peek.
  2534. * @wc_cnt: A minimum number of unreaped completions to check for.
  2535. *
  2536. * If the number of unreaped completions is greater than or equal to wc_cnt,
  2537. * this function returns wc_cnt, otherwise, it returns the actual number of
  2538. * unreaped completions.
  2539. */
  2540. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  2541. /**
  2542. * ib_req_notify_cq - Request completion notification on a CQ.
  2543. * @cq: The CQ to generate an event for.
  2544. * @flags:
  2545. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  2546. * to request an event on the next solicited event or next work
  2547. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  2548. * may also be |ed in to request a hint about missed events, as
  2549. * described below.
  2550. *
  2551. * Return Value:
  2552. * < 0 means an error occurred while requesting notification
  2553. * == 0 means notification was requested successfully, and if
  2554. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  2555. * were missed and it is safe to wait for another event. In
  2556. * this case is it guaranteed that any work completions added
  2557. * to the CQ since the last CQ poll will trigger a completion
  2558. * notification event.
  2559. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  2560. * in. It means that the consumer must poll the CQ again to
  2561. * make sure it is empty to avoid missing an event because of a
  2562. * race between requesting notification and an entry being
  2563. * added to the CQ. This return value means it is possible
  2564. * (but not guaranteed) that a work completion has been added
  2565. * to the CQ since the last poll without triggering a
  2566. * completion notification event.
  2567. */
  2568. static inline int ib_req_notify_cq(struct ib_cq *cq,
  2569. enum ib_cq_notify_flags flags)
  2570. {
  2571. return cq->device->req_notify_cq(cq, flags);
  2572. }
  2573. /**
  2574. * ib_req_ncomp_notif - Request completion notification when there are
  2575. * at least the specified number of unreaped completions on the CQ.
  2576. * @cq: The CQ to generate an event for.
  2577. * @wc_cnt: The number of unreaped completions that should be on the
  2578. * CQ before an event is generated.
  2579. */
  2580. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  2581. {
  2582. return cq->device->req_ncomp_notif ?
  2583. cq->device->req_ncomp_notif(cq, wc_cnt) :
  2584. -ENOSYS;
  2585. }
  2586. /**
  2587. * ib_get_dma_mr - Returns a memory region for system memory that is
  2588. * usable for DMA.
  2589. * @pd: The protection domain associated with the memory region.
  2590. * @mr_access_flags: Specifies the memory access rights.
  2591. *
  2592. * Note that the ib_dma_*() functions defined below must be used
  2593. * to create/destroy addresses used with the Lkey or Rkey returned
  2594. * by ib_get_dma_mr().
  2595. */
  2596. struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
  2597. /**
  2598. * ib_dma_mapping_error - check a DMA addr for error
  2599. * @dev: The device for which the dma_addr was created
  2600. * @dma_addr: The DMA address to check
  2601. */
  2602. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  2603. {
  2604. if (dev->dma_ops)
  2605. return dev->dma_ops->mapping_error(dev, dma_addr);
  2606. return dma_mapping_error(dev->dma_device, dma_addr);
  2607. }
  2608. /**
  2609. * ib_dma_map_single - Map a kernel virtual address to DMA address
  2610. * @dev: The device for which the dma_addr is to be created
  2611. * @cpu_addr: The kernel virtual address
  2612. * @size: The size of the region in bytes
  2613. * @direction: The direction of the DMA
  2614. */
  2615. static inline u64 ib_dma_map_single(struct ib_device *dev,
  2616. void *cpu_addr, size_t size,
  2617. enum dma_data_direction direction)
  2618. {
  2619. if (dev->dma_ops)
  2620. return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
  2621. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  2622. }
  2623. /**
  2624. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  2625. * @dev: The device for which the DMA address was created
  2626. * @addr: The DMA address
  2627. * @size: The size of the region in bytes
  2628. * @direction: The direction of the DMA
  2629. */
  2630. static inline void ib_dma_unmap_single(struct ib_device *dev,
  2631. u64 addr, size_t size,
  2632. enum dma_data_direction direction)
  2633. {
  2634. if (dev->dma_ops)
  2635. dev->dma_ops->unmap_single(dev, addr, size, direction);
  2636. else
  2637. dma_unmap_single(dev->dma_device, addr, size, direction);
  2638. }
  2639. static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
  2640. void *cpu_addr, size_t size,
  2641. enum dma_data_direction direction,
  2642. unsigned long dma_attrs)
  2643. {
  2644. return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
  2645. direction, dma_attrs);
  2646. }
  2647. static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
  2648. u64 addr, size_t size,
  2649. enum dma_data_direction direction,
  2650. unsigned long dma_attrs)
  2651. {
  2652. return dma_unmap_single_attrs(dev->dma_device, addr, size,
  2653. direction, dma_attrs);
  2654. }
  2655. /**
  2656. * ib_dma_map_page - Map a physical page to DMA address
  2657. * @dev: The device for which the dma_addr is to be created
  2658. * @page: The page to be mapped
  2659. * @offset: The offset within the page
  2660. * @size: The size of the region in bytes
  2661. * @direction: The direction of the DMA
  2662. */
  2663. static inline u64 ib_dma_map_page(struct ib_device *dev,
  2664. struct page *page,
  2665. unsigned long offset,
  2666. size_t size,
  2667. enum dma_data_direction direction)
  2668. {
  2669. if (dev->dma_ops)
  2670. return dev->dma_ops->map_page(dev, page, offset, size, direction);
  2671. return dma_map_page(dev->dma_device, page, offset, size, direction);
  2672. }
  2673. /**
  2674. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  2675. * @dev: The device for which the DMA address was created
  2676. * @addr: The DMA address
  2677. * @size: The size of the region in bytes
  2678. * @direction: The direction of the DMA
  2679. */
  2680. static inline void ib_dma_unmap_page(struct ib_device *dev,
  2681. u64 addr, size_t size,
  2682. enum dma_data_direction direction)
  2683. {
  2684. if (dev->dma_ops)
  2685. dev->dma_ops->unmap_page(dev, addr, size, direction);
  2686. else
  2687. dma_unmap_page(dev->dma_device, addr, size, direction);
  2688. }
  2689. /**
  2690. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  2691. * @dev: The device for which the DMA addresses are to be created
  2692. * @sg: The array of scatter/gather entries
  2693. * @nents: The number of scatter/gather entries
  2694. * @direction: The direction of the DMA
  2695. */
  2696. static inline int ib_dma_map_sg(struct ib_device *dev,
  2697. struct scatterlist *sg, int nents,
  2698. enum dma_data_direction direction)
  2699. {
  2700. if (dev->dma_ops)
  2701. return dev->dma_ops->map_sg(dev, sg, nents, direction);
  2702. return dma_map_sg(dev->dma_device, sg, nents, direction);
  2703. }
  2704. /**
  2705. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  2706. * @dev: The device for which the DMA addresses were created
  2707. * @sg: The array of scatter/gather entries
  2708. * @nents: The number of scatter/gather entries
  2709. * @direction: The direction of the DMA
  2710. */
  2711. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  2712. struct scatterlist *sg, int nents,
  2713. enum dma_data_direction direction)
  2714. {
  2715. if (dev->dma_ops)
  2716. dev->dma_ops->unmap_sg(dev, sg, nents, direction);
  2717. else
  2718. dma_unmap_sg(dev->dma_device, sg, nents, direction);
  2719. }
  2720. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  2721. struct scatterlist *sg, int nents,
  2722. enum dma_data_direction direction,
  2723. unsigned long dma_attrs)
  2724. {
  2725. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
  2726. dma_attrs);
  2727. }
  2728. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  2729. struct scatterlist *sg, int nents,
  2730. enum dma_data_direction direction,
  2731. unsigned long dma_attrs)
  2732. {
  2733. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, dma_attrs);
  2734. }
  2735. /**
  2736. * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
  2737. * @dev: The device for which the DMA addresses were created
  2738. * @sg: The scatter/gather entry
  2739. *
  2740. * Note: this function is obsolete. To do: change all occurrences of
  2741. * ib_sg_dma_address() into sg_dma_address().
  2742. */
  2743. static inline u64 ib_sg_dma_address(struct ib_device *dev,
  2744. struct scatterlist *sg)
  2745. {
  2746. return sg_dma_address(sg);
  2747. }
  2748. /**
  2749. * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
  2750. * @dev: The device for which the DMA addresses were created
  2751. * @sg: The scatter/gather entry
  2752. *
  2753. * Note: this function is obsolete. To do: change all occurrences of
  2754. * ib_sg_dma_len() into sg_dma_len().
  2755. */
  2756. static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
  2757. struct scatterlist *sg)
  2758. {
  2759. return sg_dma_len(sg);
  2760. }
  2761. /**
  2762. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  2763. * @dev: The device for which the DMA address was created
  2764. * @addr: The DMA address
  2765. * @size: The size of the region in bytes
  2766. * @dir: The direction of the DMA
  2767. */
  2768. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  2769. u64 addr,
  2770. size_t size,
  2771. enum dma_data_direction dir)
  2772. {
  2773. if (dev->dma_ops)
  2774. dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
  2775. else
  2776. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  2777. }
  2778. /**
  2779. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  2780. * @dev: The device for which the DMA address was created
  2781. * @addr: The DMA address
  2782. * @size: The size of the region in bytes
  2783. * @dir: The direction of the DMA
  2784. */
  2785. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  2786. u64 addr,
  2787. size_t size,
  2788. enum dma_data_direction dir)
  2789. {
  2790. if (dev->dma_ops)
  2791. dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
  2792. else
  2793. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  2794. }
  2795. /**
  2796. * ib_dma_alloc_coherent - Allocate memory and map it for DMA
  2797. * @dev: The device for which the DMA address is requested
  2798. * @size: The size of the region to allocate in bytes
  2799. * @dma_handle: A pointer for returning the DMA address of the region
  2800. * @flag: memory allocator flags
  2801. */
  2802. static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
  2803. size_t size,
  2804. u64 *dma_handle,
  2805. gfp_t flag)
  2806. {
  2807. if (dev->dma_ops)
  2808. return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  2809. else {
  2810. dma_addr_t handle;
  2811. void *ret;
  2812. ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
  2813. *dma_handle = handle;
  2814. return ret;
  2815. }
  2816. }
  2817. /**
  2818. * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
  2819. * @dev: The device for which the DMA addresses were allocated
  2820. * @size: The size of the region
  2821. * @cpu_addr: the address returned by ib_dma_alloc_coherent()
  2822. * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
  2823. */
  2824. static inline void ib_dma_free_coherent(struct ib_device *dev,
  2825. size_t size, void *cpu_addr,
  2826. u64 dma_handle)
  2827. {
  2828. if (dev->dma_ops)
  2829. dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  2830. else
  2831. dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
  2832. }
  2833. /**
  2834. * ib_dereg_mr - Deregisters a memory region and removes it from the
  2835. * HCA translation table.
  2836. * @mr: The memory region to deregister.
  2837. *
  2838. * This function can fail, if the memory region has memory windows bound to it.
  2839. */
  2840. int ib_dereg_mr(struct ib_mr *mr);
  2841. struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
  2842. enum ib_mr_type mr_type,
  2843. u32 max_num_sg);
  2844. /**
  2845. * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
  2846. * R_Key and L_Key.
  2847. * @mr - struct ib_mr pointer to be updated.
  2848. * @newkey - new key to be used.
  2849. */
  2850. static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
  2851. {
  2852. mr->lkey = (mr->lkey & 0xffffff00) | newkey;
  2853. mr->rkey = (mr->rkey & 0xffffff00) | newkey;
  2854. }
  2855. /**
  2856. * ib_inc_rkey - increments the key portion of the given rkey. Can be used
  2857. * for calculating a new rkey for type 2 memory windows.
  2858. * @rkey - the rkey to increment.
  2859. */
  2860. static inline u32 ib_inc_rkey(u32 rkey)
  2861. {
  2862. const u32 mask = 0x000000ff;
  2863. return ((rkey + 1) & mask) | (rkey & ~mask);
  2864. }
  2865. /**
  2866. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  2867. * @pd: The protection domain associated with the unmapped region.
  2868. * @mr_access_flags: Specifies the memory access rights.
  2869. * @fmr_attr: Attributes of the unmapped region.
  2870. *
  2871. * A fast memory region must be mapped before it can be used as part of
  2872. * a work request.
  2873. */
  2874. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  2875. int mr_access_flags,
  2876. struct ib_fmr_attr *fmr_attr);
  2877. /**
  2878. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  2879. * @fmr: The fast memory region to associate with the pages.
  2880. * @page_list: An array of physical pages to map to the fast memory region.
  2881. * @list_len: The number of pages in page_list.
  2882. * @iova: The I/O virtual address to use with the mapped region.
  2883. */
  2884. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  2885. u64 *page_list, int list_len,
  2886. u64 iova)
  2887. {
  2888. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  2889. }
  2890. /**
  2891. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  2892. * @fmr_list: A linked list of fast memory regions to unmap.
  2893. */
  2894. int ib_unmap_fmr(struct list_head *fmr_list);
  2895. /**
  2896. * ib_dealloc_fmr - Deallocates a fast memory region.
  2897. * @fmr: The fast memory region to deallocate.
  2898. */
  2899. int ib_dealloc_fmr(struct ib_fmr *fmr);
  2900. /**
  2901. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  2902. * @qp: QP to attach to the multicast group. The QP must be type
  2903. * IB_QPT_UD.
  2904. * @gid: Multicast group GID.
  2905. * @lid: Multicast group LID in host byte order.
  2906. *
  2907. * In order to send and receive multicast packets, subnet
  2908. * administration must have created the multicast group and configured
  2909. * the fabric appropriately. The port associated with the specified
  2910. * QP must also be a member of the multicast group.
  2911. */
  2912. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2913. /**
  2914. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  2915. * @qp: QP to detach from the multicast group.
  2916. * @gid: Multicast group GID.
  2917. * @lid: Multicast group LID in host byte order.
  2918. */
  2919. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2920. /**
  2921. * ib_alloc_xrcd - Allocates an XRC domain.
  2922. * @device: The device on which to allocate the XRC domain.
  2923. */
  2924. struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
  2925. /**
  2926. * ib_dealloc_xrcd - Deallocates an XRC domain.
  2927. * @xrcd: The XRC domain to deallocate.
  2928. */
  2929. int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  2930. struct ib_flow *ib_create_flow(struct ib_qp *qp,
  2931. struct ib_flow_attr *flow_attr, int domain);
  2932. int ib_destroy_flow(struct ib_flow *flow_id);
  2933. static inline int ib_check_mr_access(int flags)
  2934. {
  2935. /*
  2936. * Local write permission is required if remote write or
  2937. * remote atomic permission is also requested.
  2938. */
  2939. if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
  2940. !(flags & IB_ACCESS_LOCAL_WRITE))
  2941. return -EINVAL;
  2942. return 0;
  2943. }
  2944. /**
  2945. * ib_check_mr_status: lightweight check of MR status.
  2946. * This routine may provide status checks on a selected
  2947. * ib_mr. first use is for signature status check.
  2948. *
  2949. * @mr: A memory region.
  2950. * @check_mask: Bitmask of which checks to perform from
  2951. * ib_mr_status_check enumeration.
  2952. * @mr_status: The container of relevant status checks.
  2953. * failed checks will be indicated in the status bitmask
  2954. * and the relevant info shall be in the error item.
  2955. */
  2956. int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
  2957. struct ib_mr_status *mr_status);
  2958. struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
  2959. u16 pkey, const union ib_gid *gid,
  2960. const struct sockaddr *addr);
  2961. struct ib_wq *ib_create_wq(struct ib_pd *pd,
  2962. struct ib_wq_init_attr *init_attr);
  2963. int ib_destroy_wq(struct ib_wq *wq);
  2964. int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
  2965. u32 wq_attr_mask);
  2966. struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
  2967. struct ib_rwq_ind_table_init_attr*
  2968. wq_ind_table_init_attr);
  2969. int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
  2970. int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  2971. unsigned int *sg_offset, unsigned int page_size);
  2972. static inline int
  2973. ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  2974. unsigned int *sg_offset, unsigned int page_size)
  2975. {
  2976. int n;
  2977. n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
  2978. mr->iova = 0;
  2979. return n;
  2980. }
  2981. int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
  2982. unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
  2983. void ib_drain_rq(struct ib_qp *qp);
  2984. void ib_drain_sq(struct ib_qp *qp);
  2985. void ib_drain_qp(struct ib_qp *qp);
  2986. #endif /* IB_VERBS_H */