ib_verbs.h 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192
  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 = (1 << 31),
  199. IB_DEVICE_SG_GAPS_REG = (1ULL << 32),
  200. IB_DEVICE_VIRTUAL_FUNCTION = ((u64)1 << 33),
  201. IB_DEVICE_RAW_SCATTER_FCS = ((u64)1 << 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. };
  513. const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
  514. struct ib_event {
  515. struct ib_device *device;
  516. union {
  517. struct ib_cq *cq;
  518. struct ib_qp *qp;
  519. struct ib_srq *srq;
  520. u8 port_num;
  521. } element;
  522. enum ib_event_type event;
  523. };
  524. struct ib_event_handler {
  525. struct ib_device *device;
  526. void (*handler)(struct ib_event_handler *, struct ib_event *);
  527. struct list_head list;
  528. };
  529. #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
  530. do { \
  531. (_ptr)->device = _device; \
  532. (_ptr)->handler = _handler; \
  533. INIT_LIST_HEAD(&(_ptr)->list); \
  534. } while (0)
  535. struct ib_global_route {
  536. union ib_gid dgid;
  537. u32 flow_label;
  538. u8 sgid_index;
  539. u8 hop_limit;
  540. u8 traffic_class;
  541. };
  542. struct ib_grh {
  543. __be32 version_tclass_flow;
  544. __be16 paylen;
  545. u8 next_hdr;
  546. u8 hop_limit;
  547. union ib_gid sgid;
  548. union ib_gid dgid;
  549. };
  550. union rdma_network_hdr {
  551. struct ib_grh ibgrh;
  552. struct {
  553. /* The IB spec states that if it's IPv4, the header
  554. * is located in the last 20 bytes of the header.
  555. */
  556. u8 reserved[20];
  557. struct iphdr roce4grh;
  558. };
  559. };
  560. enum {
  561. IB_MULTICAST_QPN = 0xffffff
  562. };
  563. #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
  564. #define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000)
  565. enum ib_ah_flags {
  566. IB_AH_GRH = 1
  567. };
  568. enum ib_rate {
  569. IB_RATE_PORT_CURRENT = 0,
  570. IB_RATE_2_5_GBPS = 2,
  571. IB_RATE_5_GBPS = 5,
  572. IB_RATE_10_GBPS = 3,
  573. IB_RATE_20_GBPS = 6,
  574. IB_RATE_30_GBPS = 4,
  575. IB_RATE_40_GBPS = 7,
  576. IB_RATE_60_GBPS = 8,
  577. IB_RATE_80_GBPS = 9,
  578. IB_RATE_120_GBPS = 10,
  579. IB_RATE_14_GBPS = 11,
  580. IB_RATE_56_GBPS = 12,
  581. IB_RATE_112_GBPS = 13,
  582. IB_RATE_168_GBPS = 14,
  583. IB_RATE_25_GBPS = 15,
  584. IB_RATE_100_GBPS = 16,
  585. IB_RATE_200_GBPS = 17,
  586. IB_RATE_300_GBPS = 18
  587. };
  588. /**
  589. * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
  590. * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
  591. * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
  592. * @rate: rate to convert.
  593. */
  594. __attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
  595. /**
  596. * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
  597. * For example, IB_RATE_2_5_GBPS will be converted to 2500.
  598. * @rate: rate to convert.
  599. */
  600. __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
  601. /**
  602. * enum ib_mr_type - memory region type
  603. * @IB_MR_TYPE_MEM_REG: memory region that is used for
  604. * normal registration
  605. * @IB_MR_TYPE_SIGNATURE: memory region that is used for
  606. * signature operations (data-integrity
  607. * capable regions)
  608. * @IB_MR_TYPE_SG_GAPS: memory region that is capable to
  609. * register any arbitrary sg lists (without
  610. * the normal mr constraints - see
  611. * ib_map_mr_sg)
  612. */
  613. enum ib_mr_type {
  614. IB_MR_TYPE_MEM_REG,
  615. IB_MR_TYPE_SIGNATURE,
  616. IB_MR_TYPE_SG_GAPS,
  617. };
  618. /**
  619. * Signature types
  620. * IB_SIG_TYPE_NONE: Unprotected.
  621. * IB_SIG_TYPE_T10_DIF: Type T10-DIF
  622. */
  623. enum ib_signature_type {
  624. IB_SIG_TYPE_NONE,
  625. IB_SIG_TYPE_T10_DIF,
  626. };
  627. /**
  628. * Signature T10-DIF block-guard types
  629. * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
  630. * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
  631. */
  632. enum ib_t10_dif_bg_type {
  633. IB_T10DIF_CRC,
  634. IB_T10DIF_CSUM
  635. };
  636. /**
  637. * struct ib_t10_dif_domain - Parameters specific for T10-DIF
  638. * domain.
  639. * @bg_type: T10-DIF block guard type (CRC|CSUM)
  640. * @pi_interval: protection information interval.
  641. * @bg: seed of guard computation.
  642. * @app_tag: application tag of guard block
  643. * @ref_tag: initial guard block reference tag.
  644. * @ref_remap: Indicate wethear the reftag increments each block
  645. * @app_escape: Indicate to skip block check if apptag=0xffff
  646. * @ref_escape: Indicate to skip block check if reftag=0xffffffff
  647. * @apptag_check_mask: check bitmask of application tag.
  648. */
  649. struct ib_t10_dif_domain {
  650. enum ib_t10_dif_bg_type bg_type;
  651. u16 pi_interval;
  652. u16 bg;
  653. u16 app_tag;
  654. u32 ref_tag;
  655. bool ref_remap;
  656. bool app_escape;
  657. bool ref_escape;
  658. u16 apptag_check_mask;
  659. };
  660. /**
  661. * struct ib_sig_domain - Parameters for signature domain
  662. * @sig_type: specific signauture type
  663. * @sig: union of all signature domain attributes that may
  664. * be used to set domain layout.
  665. */
  666. struct ib_sig_domain {
  667. enum ib_signature_type sig_type;
  668. union {
  669. struct ib_t10_dif_domain dif;
  670. } sig;
  671. };
  672. /**
  673. * struct ib_sig_attrs - Parameters for signature handover operation
  674. * @check_mask: bitmask for signature byte check (8 bytes)
  675. * @mem: memory domain layout desciptor.
  676. * @wire: wire domain layout desciptor.
  677. */
  678. struct ib_sig_attrs {
  679. u8 check_mask;
  680. struct ib_sig_domain mem;
  681. struct ib_sig_domain wire;
  682. };
  683. enum ib_sig_err_type {
  684. IB_SIG_BAD_GUARD,
  685. IB_SIG_BAD_REFTAG,
  686. IB_SIG_BAD_APPTAG,
  687. };
  688. /**
  689. * struct ib_sig_err - signature error descriptor
  690. */
  691. struct ib_sig_err {
  692. enum ib_sig_err_type err_type;
  693. u32 expected;
  694. u32 actual;
  695. u64 sig_err_offset;
  696. u32 key;
  697. };
  698. enum ib_mr_status_check {
  699. IB_MR_CHECK_SIG_STATUS = 1,
  700. };
  701. /**
  702. * struct ib_mr_status - Memory region status container
  703. *
  704. * @fail_status: Bitmask of MR checks status. For each
  705. * failed check a corresponding status bit is set.
  706. * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
  707. * failure.
  708. */
  709. struct ib_mr_status {
  710. u32 fail_status;
  711. struct ib_sig_err sig_err;
  712. };
  713. /**
  714. * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
  715. * enum.
  716. * @mult: multiple to convert.
  717. */
  718. __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
  719. struct ib_ah_attr {
  720. struct ib_global_route grh;
  721. u16 dlid;
  722. u8 sl;
  723. u8 src_path_bits;
  724. u8 static_rate;
  725. u8 ah_flags;
  726. u8 port_num;
  727. u8 dmac[ETH_ALEN];
  728. };
  729. enum ib_wc_status {
  730. IB_WC_SUCCESS,
  731. IB_WC_LOC_LEN_ERR,
  732. IB_WC_LOC_QP_OP_ERR,
  733. IB_WC_LOC_EEC_OP_ERR,
  734. IB_WC_LOC_PROT_ERR,
  735. IB_WC_WR_FLUSH_ERR,
  736. IB_WC_MW_BIND_ERR,
  737. IB_WC_BAD_RESP_ERR,
  738. IB_WC_LOC_ACCESS_ERR,
  739. IB_WC_REM_INV_REQ_ERR,
  740. IB_WC_REM_ACCESS_ERR,
  741. IB_WC_REM_OP_ERR,
  742. IB_WC_RETRY_EXC_ERR,
  743. IB_WC_RNR_RETRY_EXC_ERR,
  744. IB_WC_LOC_RDD_VIOL_ERR,
  745. IB_WC_REM_INV_RD_REQ_ERR,
  746. IB_WC_REM_ABORT_ERR,
  747. IB_WC_INV_EECN_ERR,
  748. IB_WC_INV_EEC_STATE_ERR,
  749. IB_WC_FATAL_ERR,
  750. IB_WC_RESP_TIMEOUT_ERR,
  751. IB_WC_GENERAL_ERR
  752. };
  753. const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
  754. enum ib_wc_opcode {
  755. IB_WC_SEND,
  756. IB_WC_RDMA_WRITE,
  757. IB_WC_RDMA_READ,
  758. IB_WC_COMP_SWAP,
  759. IB_WC_FETCH_ADD,
  760. IB_WC_LSO,
  761. IB_WC_LOCAL_INV,
  762. IB_WC_REG_MR,
  763. IB_WC_MASKED_COMP_SWAP,
  764. IB_WC_MASKED_FETCH_ADD,
  765. /*
  766. * Set value of IB_WC_RECV so consumers can test if a completion is a
  767. * receive by testing (opcode & IB_WC_RECV).
  768. */
  769. IB_WC_RECV = 1 << 7,
  770. IB_WC_RECV_RDMA_WITH_IMM
  771. };
  772. enum ib_wc_flags {
  773. IB_WC_GRH = 1,
  774. IB_WC_WITH_IMM = (1<<1),
  775. IB_WC_WITH_INVALIDATE = (1<<2),
  776. IB_WC_IP_CSUM_OK = (1<<3),
  777. IB_WC_WITH_SMAC = (1<<4),
  778. IB_WC_WITH_VLAN = (1<<5),
  779. IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6),
  780. };
  781. struct ib_wc {
  782. union {
  783. u64 wr_id;
  784. struct ib_cqe *wr_cqe;
  785. };
  786. enum ib_wc_status status;
  787. enum ib_wc_opcode opcode;
  788. u32 vendor_err;
  789. u32 byte_len;
  790. struct ib_qp *qp;
  791. union {
  792. __be32 imm_data;
  793. u32 invalidate_rkey;
  794. } ex;
  795. u32 src_qp;
  796. int wc_flags;
  797. u16 pkey_index;
  798. u16 slid;
  799. u8 sl;
  800. u8 dlid_path_bits;
  801. u8 port_num; /* valid only for DR SMPs on switches */
  802. u8 smac[ETH_ALEN];
  803. u16 vlan_id;
  804. u8 network_hdr_type;
  805. };
  806. enum ib_cq_notify_flags {
  807. IB_CQ_SOLICITED = 1 << 0,
  808. IB_CQ_NEXT_COMP = 1 << 1,
  809. IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
  810. IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
  811. };
  812. enum ib_srq_type {
  813. IB_SRQT_BASIC,
  814. IB_SRQT_XRC
  815. };
  816. enum ib_srq_attr_mask {
  817. IB_SRQ_MAX_WR = 1 << 0,
  818. IB_SRQ_LIMIT = 1 << 1,
  819. };
  820. struct ib_srq_attr {
  821. u32 max_wr;
  822. u32 max_sge;
  823. u32 srq_limit;
  824. };
  825. struct ib_srq_init_attr {
  826. void (*event_handler)(struct ib_event *, void *);
  827. void *srq_context;
  828. struct ib_srq_attr attr;
  829. enum ib_srq_type srq_type;
  830. union {
  831. struct {
  832. struct ib_xrcd *xrcd;
  833. struct ib_cq *cq;
  834. } xrc;
  835. } ext;
  836. };
  837. struct ib_qp_cap {
  838. u32 max_send_wr;
  839. u32 max_recv_wr;
  840. u32 max_send_sge;
  841. u32 max_recv_sge;
  842. u32 max_inline_data;
  843. /*
  844. * Maximum number of rdma_rw_ctx structures in flight at a time.
  845. * ib_create_qp() will calculate the right amount of neededed WRs
  846. * and MRs based on this.
  847. */
  848. u32 max_rdma_ctxs;
  849. };
  850. enum ib_sig_type {
  851. IB_SIGNAL_ALL_WR,
  852. IB_SIGNAL_REQ_WR
  853. };
  854. enum ib_qp_type {
  855. /*
  856. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  857. * here (and in that order) since the MAD layer uses them as
  858. * indices into a 2-entry table.
  859. */
  860. IB_QPT_SMI,
  861. IB_QPT_GSI,
  862. IB_QPT_RC,
  863. IB_QPT_UC,
  864. IB_QPT_UD,
  865. IB_QPT_RAW_IPV6,
  866. IB_QPT_RAW_ETHERTYPE,
  867. IB_QPT_RAW_PACKET = 8,
  868. IB_QPT_XRC_INI = 9,
  869. IB_QPT_XRC_TGT,
  870. IB_QPT_MAX,
  871. /* Reserve a range for qp types internal to the low level driver.
  872. * These qp types will not be visible at the IB core layer, so the
  873. * IB_QPT_MAX usages should not be affected in the core layer
  874. */
  875. IB_QPT_RESERVED1 = 0x1000,
  876. IB_QPT_RESERVED2,
  877. IB_QPT_RESERVED3,
  878. IB_QPT_RESERVED4,
  879. IB_QPT_RESERVED5,
  880. IB_QPT_RESERVED6,
  881. IB_QPT_RESERVED7,
  882. IB_QPT_RESERVED8,
  883. IB_QPT_RESERVED9,
  884. IB_QPT_RESERVED10,
  885. };
  886. enum ib_qp_create_flags {
  887. IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
  888. IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
  889. IB_QP_CREATE_CROSS_CHANNEL = 1 << 2,
  890. IB_QP_CREATE_MANAGED_SEND = 1 << 3,
  891. IB_QP_CREATE_MANAGED_RECV = 1 << 4,
  892. IB_QP_CREATE_NETIF_QP = 1 << 5,
  893. IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
  894. IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
  895. IB_QP_CREATE_SCATTER_FCS = 1 << 8,
  896. /* reserve bits 26-31 for low level drivers' internal use */
  897. IB_QP_CREATE_RESERVED_START = 1 << 26,
  898. IB_QP_CREATE_RESERVED_END = 1 << 31,
  899. };
  900. /*
  901. * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
  902. * callback to destroy the passed in QP.
  903. */
  904. struct ib_qp_init_attr {
  905. void (*event_handler)(struct ib_event *, void *);
  906. void *qp_context;
  907. struct ib_cq *send_cq;
  908. struct ib_cq *recv_cq;
  909. struct ib_srq *srq;
  910. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  911. struct ib_qp_cap cap;
  912. enum ib_sig_type sq_sig_type;
  913. enum ib_qp_type qp_type;
  914. enum ib_qp_create_flags create_flags;
  915. /*
  916. * Only needed for special QP types, or when using the RW API.
  917. */
  918. u8 port_num;
  919. };
  920. struct ib_qp_open_attr {
  921. void (*event_handler)(struct ib_event *, void *);
  922. void *qp_context;
  923. u32 qp_num;
  924. enum ib_qp_type qp_type;
  925. };
  926. enum ib_rnr_timeout {
  927. IB_RNR_TIMER_655_36 = 0,
  928. IB_RNR_TIMER_000_01 = 1,
  929. IB_RNR_TIMER_000_02 = 2,
  930. IB_RNR_TIMER_000_03 = 3,
  931. IB_RNR_TIMER_000_04 = 4,
  932. IB_RNR_TIMER_000_06 = 5,
  933. IB_RNR_TIMER_000_08 = 6,
  934. IB_RNR_TIMER_000_12 = 7,
  935. IB_RNR_TIMER_000_16 = 8,
  936. IB_RNR_TIMER_000_24 = 9,
  937. IB_RNR_TIMER_000_32 = 10,
  938. IB_RNR_TIMER_000_48 = 11,
  939. IB_RNR_TIMER_000_64 = 12,
  940. IB_RNR_TIMER_000_96 = 13,
  941. IB_RNR_TIMER_001_28 = 14,
  942. IB_RNR_TIMER_001_92 = 15,
  943. IB_RNR_TIMER_002_56 = 16,
  944. IB_RNR_TIMER_003_84 = 17,
  945. IB_RNR_TIMER_005_12 = 18,
  946. IB_RNR_TIMER_007_68 = 19,
  947. IB_RNR_TIMER_010_24 = 20,
  948. IB_RNR_TIMER_015_36 = 21,
  949. IB_RNR_TIMER_020_48 = 22,
  950. IB_RNR_TIMER_030_72 = 23,
  951. IB_RNR_TIMER_040_96 = 24,
  952. IB_RNR_TIMER_061_44 = 25,
  953. IB_RNR_TIMER_081_92 = 26,
  954. IB_RNR_TIMER_122_88 = 27,
  955. IB_RNR_TIMER_163_84 = 28,
  956. IB_RNR_TIMER_245_76 = 29,
  957. IB_RNR_TIMER_327_68 = 30,
  958. IB_RNR_TIMER_491_52 = 31
  959. };
  960. enum ib_qp_attr_mask {
  961. IB_QP_STATE = 1,
  962. IB_QP_CUR_STATE = (1<<1),
  963. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  964. IB_QP_ACCESS_FLAGS = (1<<3),
  965. IB_QP_PKEY_INDEX = (1<<4),
  966. IB_QP_PORT = (1<<5),
  967. IB_QP_QKEY = (1<<6),
  968. IB_QP_AV = (1<<7),
  969. IB_QP_PATH_MTU = (1<<8),
  970. IB_QP_TIMEOUT = (1<<9),
  971. IB_QP_RETRY_CNT = (1<<10),
  972. IB_QP_RNR_RETRY = (1<<11),
  973. IB_QP_RQ_PSN = (1<<12),
  974. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  975. IB_QP_ALT_PATH = (1<<14),
  976. IB_QP_MIN_RNR_TIMER = (1<<15),
  977. IB_QP_SQ_PSN = (1<<16),
  978. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  979. IB_QP_PATH_MIG_STATE = (1<<18),
  980. IB_QP_CAP = (1<<19),
  981. IB_QP_DEST_QPN = (1<<20),
  982. IB_QP_RESERVED1 = (1<<21),
  983. IB_QP_RESERVED2 = (1<<22),
  984. IB_QP_RESERVED3 = (1<<23),
  985. IB_QP_RESERVED4 = (1<<24),
  986. };
  987. enum ib_qp_state {
  988. IB_QPS_RESET,
  989. IB_QPS_INIT,
  990. IB_QPS_RTR,
  991. IB_QPS_RTS,
  992. IB_QPS_SQD,
  993. IB_QPS_SQE,
  994. IB_QPS_ERR
  995. };
  996. enum ib_mig_state {
  997. IB_MIG_MIGRATED,
  998. IB_MIG_REARM,
  999. IB_MIG_ARMED
  1000. };
  1001. enum ib_mw_type {
  1002. IB_MW_TYPE_1 = 1,
  1003. IB_MW_TYPE_2 = 2
  1004. };
  1005. struct ib_qp_attr {
  1006. enum ib_qp_state qp_state;
  1007. enum ib_qp_state cur_qp_state;
  1008. enum ib_mtu path_mtu;
  1009. enum ib_mig_state path_mig_state;
  1010. u32 qkey;
  1011. u32 rq_psn;
  1012. u32 sq_psn;
  1013. u32 dest_qp_num;
  1014. int qp_access_flags;
  1015. struct ib_qp_cap cap;
  1016. struct ib_ah_attr ah_attr;
  1017. struct ib_ah_attr alt_ah_attr;
  1018. u16 pkey_index;
  1019. u16 alt_pkey_index;
  1020. u8 en_sqd_async_notify;
  1021. u8 sq_draining;
  1022. u8 max_rd_atomic;
  1023. u8 max_dest_rd_atomic;
  1024. u8 min_rnr_timer;
  1025. u8 port_num;
  1026. u8 timeout;
  1027. u8 retry_cnt;
  1028. u8 rnr_retry;
  1029. u8 alt_port_num;
  1030. u8 alt_timeout;
  1031. };
  1032. enum ib_wr_opcode {
  1033. IB_WR_RDMA_WRITE,
  1034. IB_WR_RDMA_WRITE_WITH_IMM,
  1035. IB_WR_SEND,
  1036. IB_WR_SEND_WITH_IMM,
  1037. IB_WR_RDMA_READ,
  1038. IB_WR_ATOMIC_CMP_AND_SWP,
  1039. IB_WR_ATOMIC_FETCH_AND_ADD,
  1040. IB_WR_LSO,
  1041. IB_WR_SEND_WITH_INV,
  1042. IB_WR_RDMA_READ_WITH_INV,
  1043. IB_WR_LOCAL_INV,
  1044. IB_WR_REG_MR,
  1045. IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
  1046. IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
  1047. IB_WR_REG_SIG_MR,
  1048. /* reserve values for low level drivers' internal use.
  1049. * These values will not be used at all in the ib core layer.
  1050. */
  1051. IB_WR_RESERVED1 = 0xf0,
  1052. IB_WR_RESERVED2,
  1053. IB_WR_RESERVED3,
  1054. IB_WR_RESERVED4,
  1055. IB_WR_RESERVED5,
  1056. IB_WR_RESERVED6,
  1057. IB_WR_RESERVED7,
  1058. IB_WR_RESERVED8,
  1059. IB_WR_RESERVED9,
  1060. IB_WR_RESERVED10,
  1061. };
  1062. enum ib_send_flags {
  1063. IB_SEND_FENCE = 1,
  1064. IB_SEND_SIGNALED = (1<<1),
  1065. IB_SEND_SOLICITED = (1<<2),
  1066. IB_SEND_INLINE = (1<<3),
  1067. IB_SEND_IP_CSUM = (1<<4),
  1068. /* reserve bits 26-31 for low level drivers' internal use */
  1069. IB_SEND_RESERVED_START = (1 << 26),
  1070. IB_SEND_RESERVED_END = (1 << 31),
  1071. };
  1072. struct ib_sge {
  1073. u64 addr;
  1074. u32 length;
  1075. u32 lkey;
  1076. };
  1077. struct ib_cqe {
  1078. void (*done)(struct ib_cq *cq, struct ib_wc *wc);
  1079. };
  1080. struct ib_send_wr {
  1081. struct ib_send_wr *next;
  1082. union {
  1083. u64 wr_id;
  1084. struct ib_cqe *wr_cqe;
  1085. };
  1086. struct ib_sge *sg_list;
  1087. int num_sge;
  1088. enum ib_wr_opcode opcode;
  1089. int send_flags;
  1090. union {
  1091. __be32 imm_data;
  1092. u32 invalidate_rkey;
  1093. } ex;
  1094. };
  1095. struct ib_rdma_wr {
  1096. struct ib_send_wr wr;
  1097. u64 remote_addr;
  1098. u32 rkey;
  1099. };
  1100. static inline struct ib_rdma_wr *rdma_wr(struct ib_send_wr *wr)
  1101. {
  1102. return container_of(wr, struct ib_rdma_wr, wr);
  1103. }
  1104. struct ib_atomic_wr {
  1105. struct ib_send_wr wr;
  1106. u64 remote_addr;
  1107. u64 compare_add;
  1108. u64 swap;
  1109. u64 compare_add_mask;
  1110. u64 swap_mask;
  1111. u32 rkey;
  1112. };
  1113. static inline struct ib_atomic_wr *atomic_wr(struct ib_send_wr *wr)
  1114. {
  1115. return container_of(wr, struct ib_atomic_wr, wr);
  1116. }
  1117. struct ib_ud_wr {
  1118. struct ib_send_wr wr;
  1119. struct ib_ah *ah;
  1120. void *header;
  1121. int hlen;
  1122. int mss;
  1123. u32 remote_qpn;
  1124. u32 remote_qkey;
  1125. u16 pkey_index; /* valid for GSI only */
  1126. u8 port_num; /* valid for DR SMPs on switch only */
  1127. };
  1128. static inline struct ib_ud_wr *ud_wr(struct ib_send_wr *wr)
  1129. {
  1130. return container_of(wr, struct ib_ud_wr, wr);
  1131. }
  1132. struct ib_reg_wr {
  1133. struct ib_send_wr wr;
  1134. struct ib_mr *mr;
  1135. u32 key;
  1136. int access;
  1137. };
  1138. static inline struct ib_reg_wr *reg_wr(struct ib_send_wr *wr)
  1139. {
  1140. return container_of(wr, struct ib_reg_wr, wr);
  1141. }
  1142. struct ib_sig_handover_wr {
  1143. struct ib_send_wr wr;
  1144. struct ib_sig_attrs *sig_attrs;
  1145. struct ib_mr *sig_mr;
  1146. int access_flags;
  1147. struct ib_sge *prot;
  1148. };
  1149. static inline struct ib_sig_handover_wr *sig_handover_wr(struct ib_send_wr *wr)
  1150. {
  1151. return container_of(wr, struct ib_sig_handover_wr, wr);
  1152. }
  1153. struct ib_recv_wr {
  1154. struct ib_recv_wr *next;
  1155. union {
  1156. u64 wr_id;
  1157. struct ib_cqe *wr_cqe;
  1158. };
  1159. struct ib_sge *sg_list;
  1160. int num_sge;
  1161. };
  1162. enum ib_access_flags {
  1163. IB_ACCESS_LOCAL_WRITE = 1,
  1164. IB_ACCESS_REMOTE_WRITE = (1<<1),
  1165. IB_ACCESS_REMOTE_READ = (1<<2),
  1166. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  1167. IB_ACCESS_MW_BIND = (1<<4),
  1168. IB_ZERO_BASED = (1<<5),
  1169. IB_ACCESS_ON_DEMAND = (1<<6),
  1170. };
  1171. /*
  1172. * XXX: these are apparently used for ->rereg_user_mr, no idea why they
  1173. * are hidden here instead of a uapi header!
  1174. */
  1175. enum ib_mr_rereg_flags {
  1176. IB_MR_REREG_TRANS = 1,
  1177. IB_MR_REREG_PD = (1<<1),
  1178. IB_MR_REREG_ACCESS = (1<<2),
  1179. IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
  1180. };
  1181. struct ib_fmr_attr {
  1182. int max_pages;
  1183. int max_maps;
  1184. u8 page_shift;
  1185. };
  1186. struct ib_umem;
  1187. struct ib_ucontext {
  1188. struct ib_device *device;
  1189. struct list_head pd_list;
  1190. struct list_head mr_list;
  1191. struct list_head mw_list;
  1192. struct list_head cq_list;
  1193. struct list_head qp_list;
  1194. struct list_head srq_list;
  1195. struct list_head ah_list;
  1196. struct list_head xrcd_list;
  1197. struct list_head rule_list;
  1198. int closing;
  1199. struct pid *tgid;
  1200. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  1201. struct rb_root umem_tree;
  1202. /*
  1203. * Protects .umem_rbroot and tree, as well as odp_mrs_count and
  1204. * mmu notifiers registration.
  1205. */
  1206. struct rw_semaphore umem_rwsem;
  1207. void (*invalidate_range)(struct ib_umem *umem,
  1208. unsigned long start, unsigned long end);
  1209. struct mmu_notifier mn;
  1210. atomic_t notifier_count;
  1211. /* A list of umems that don't have private mmu notifier counters yet. */
  1212. struct list_head no_private_counters;
  1213. int odp_mrs_count;
  1214. #endif
  1215. };
  1216. struct ib_uobject {
  1217. u64 user_handle; /* handle given to us by userspace */
  1218. struct ib_ucontext *context; /* associated user context */
  1219. void *object; /* containing object */
  1220. struct list_head list; /* link to context's list */
  1221. int id; /* index into kernel idr */
  1222. struct kref ref;
  1223. struct rw_semaphore mutex; /* protects .live */
  1224. struct rcu_head rcu; /* kfree_rcu() overhead */
  1225. int live;
  1226. };
  1227. struct ib_udata {
  1228. const void __user *inbuf;
  1229. void __user *outbuf;
  1230. size_t inlen;
  1231. size_t outlen;
  1232. };
  1233. struct ib_pd {
  1234. u32 local_dma_lkey;
  1235. struct ib_device *device;
  1236. struct ib_uobject *uobject;
  1237. atomic_t usecnt; /* count all resources */
  1238. struct ib_mr *local_mr;
  1239. };
  1240. struct ib_xrcd {
  1241. struct ib_device *device;
  1242. atomic_t usecnt; /* count all exposed resources */
  1243. struct inode *inode;
  1244. struct mutex tgt_qp_mutex;
  1245. struct list_head tgt_qp_list;
  1246. };
  1247. struct ib_ah {
  1248. struct ib_device *device;
  1249. struct ib_pd *pd;
  1250. struct ib_uobject *uobject;
  1251. };
  1252. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  1253. enum ib_poll_context {
  1254. IB_POLL_DIRECT, /* caller context, no hw completions */
  1255. IB_POLL_SOFTIRQ, /* poll from softirq context */
  1256. IB_POLL_WORKQUEUE, /* poll from workqueue */
  1257. };
  1258. struct ib_cq {
  1259. struct ib_device *device;
  1260. struct ib_uobject *uobject;
  1261. ib_comp_handler comp_handler;
  1262. void (*event_handler)(struct ib_event *, void *);
  1263. void *cq_context;
  1264. int cqe;
  1265. atomic_t usecnt; /* count number of work queues */
  1266. enum ib_poll_context poll_ctx;
  1267. struct ib_wc *wc;
  1268. union {
  1269. struct irq_poll iop;
  1270. struct work_struct work;
  1271. };
  1272. };
  1273. struct ib_srq {
  1274. struct ib_device *device;
  1275. struct ib_pd *pd;
  1276. struct ib_uobject *uobject;
  1277. void (*event_handler)(struct ib_event *, void *);
  1278. void *srq_context;
  1279. enum ib_srq_type srq_type;
  1280. atomic_t usecnt;
  1281. union {
  1282. struct {
  1283. struct ib_xrcd *xrcd;
  1284. struct ib_cq *cq;
  1285. u32 srq_num;
  1286. } xrc;
  1287. } ext;
  1288. };
  1289. struct ib_qp {
  1290. struct ib_device *device;
  1291. struct ib_pd *pd;
  1292. struct ib_cq *send_cq;
  1293. struct ib_cq *recv_cq;
  1294. spinlock_t mr_lock;
  1295. int mrs_used;
  1296. struct list_head rdma_mrs;
  1297. struct list_head sig_mrs;
  1298. struct ib_srq *srq;
  1299. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  1300. struct list_head xrcd_list;
  1301. /* count times opened, mcast attaches, flow attaches */
  1302. atomic_t usecnt;
  1303. struct list_head open_list;
  1304. struct ib_qp *real_qp;
  1305. struct ib_uobject *uobject;
  1306. void (*event_handler)(struct ib_event *, void *);
  1307. void *qp_context;
  1308. u32 qp_num;
  1309. enum ib_qp_type qp_type;
  1310. };
  1311. struct ib_mr {
  1312. struct ib_device *device;
  1313. struct ib_pd *pd;
  1314. u32 lkey;
  1315. u32 rkey;
  1316. u64 iova;
  1317. u32 length;
  1318. unsigned int page_size;
  1319. bool need_inval;
  1320. union {
  1321. struct ib_uobject *uobject; /* user */
  1322. struct list_head qp_entry; /* FR */
  1323. };
  1324. };
  1325. struct ib_mw {
  1326. struct ib_device *device;
  1327. struct ib_pd *pd;
  1328. struct ib_uobject *uobject;
  1329. u32 rkey;
  1330. enum ib_mw_type type;
  1331. };
  1332. struct ib_fmr {
  1333. struct ib_device *device;
  1334. struct ib_pd *pd;
  1335. struct list_head list;
  1336. u32 lkey;
  1337. u32 rkey;
  1338. };
  1339. /* Supported steering options */
  1340. enum ib_flow_attr_type {
  1341. /* steering according to rule specifications */
  1342. IB_FLOW_ATTR_NORMAL = 0x0,
  1343. /* default unicast and multicast rule -
  1344. * receive all Eth traffic which isn't steered to any QP
  1345. */
  1346. IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
  1347. /* default multicast rule -
  1348. * receive all Eth multicast traffic which isn't steered to any QP
  1349. */
  1350. IB_FLOW_ATTR_MC_DEFAULT = 0x2,
  1351. /* sniffer rule - receive all port traffic */
  1352. IB_FLOW_ATTR_SNIFFER = 0x3
  1353. };
  1354. /* Supported steering header types */
  1355. enum ib_flow_spec_type {
  1356. /* L2 headers*/
  1357. IB_FLOW_SPEC_ETH = 0x20,
  1358. IB_FLOW_SPEC_IB = 0x22,
  1359. /* L3 header*/
  1360. IB_FLOW_SPEC_IPV4 = 0x30,
  1361. /* L4 headers*/
  1362. IB_FLOW_SPEC_TCP = 0x40,
  1363. IB_FLOW_SPEC_UDP = 0x41
  1364. };
  1365. #define IB_FLOW_SPEC_LAYER_MASK 0xF0
  1366. #define IB_FLOW_SPEC_SUPPORT_LAYERS 4
  1367. /* Flow steering rule priority is set according to it's domain.
  1368. * Lower domain value means higher priority.
  1369. */
  1370. enum ib_flow_domain {
  1371. IB_FLOW_DOMAIN_USER,
  1372. IB_FLOW_DOMAIN_ETHTOOL,
  1373. IB_FLOW_DOMAIN_RFS,
  1374. IB_FLOW_DOMAIN_NIC,
  1375. IB_FLOW_DOMAIN_NUM /* Must be last */
  1376. };
  1377. enum ib_flow_flags {
  1378. IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
  1379. IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 2 /* Must be last */
  1380. };
  1381. struct ib_flow_eth_filter {
  1382. u8 dst_mac[6];
  1383. u8 src_mac[6];
  1384. __be16 ether_type;
  1385. __be16 vlan_tag;
  1386. };
  1387. struct ib_flow_spec_eth {
  1388. enum ib_flow_spec_type type;
  1389. u16 size;
  1390. struct ib_flow_eth_filter val;
  1391. struct ib_flow_eth_filter mask;
  1392. };
  1393. struct ib_flow_ib_filter {
  1394. __be16 dlid;
  1395. __u8 sl;
  1396. };
  1397. struct ib_flow_spec_ib {
  1398. enum ib_flow_spec_type type;
  1399. u16 size;
  1400. struct ib_flow_ib_filter val;
  1401. struct ib_flow_ib_filter mask;
  1402. };
  1403. struct ib_flow_ipv4_filter {
  1404. __be32 src_ip;
  1405. __be32 dst_ip;
  1406. };
  1407. struct ib_flow_spec_ipv4 {
  1408. enum ib_flow_spec_type type;
  1409. u16 size;
  1410. struct ib_flow_ipv4_filter val;
  1411. struct ib_flow_ipv4_filter mask;
  1412. };
  1413. struct ib_flow_tcp_udp_filter {
  1414. __be16 dst_port;
  1415. __be16 src_port;
  1416. };
  1417. struct ib_flow_spec_tcp_udp {
  1418. enum ib_flow_spec_type type;
  1419. u16 size;
  1420. struct ib_flow_tcp_udp_filter val;
  1421. struct ib_flow_tcp_udp_filter mask;
  1422. };
  1423. union ib_flow_spec {
  1424. struct {
  1425. enum ib_flow_spec_type type;
  1426. u16 size;
  1427. };
  1428. struct ib_flow_spec_eth eth;
  1429. struct ib_flow_spec_ib ib;
  1430. struct ib_flow_spec_ipv4 ipv4;
  1431. struct ib_flow_spec_tcp_udp tcp_udp;
  1432. };
  1433. struct ib_flow_attr {
  1434. enum ib_flow_attr_type type;
  1435. u16 size;
  1436. u16 priority;
  1437. u32 flags;
  1438. u8 num_of_specs;
  1439. u8 port;
  1440. /* Following are the optional layers according to user request
  1441. * struct ib_flow_spec_xxx
  1442. * struct ib_flow_spec_yyy
  1443. */
  1444. };
  1445. struct ib_flow {
  1446. struct ib_qp *qp;
  1447. struct ib_uobject *uobject;
  1448. };
  1449. struct ib_mad_hdr;
  1450. struct ib_grh;
  1451. enum ib_process_mad_flags {
  1452. IB_MAD_IGNORE_MKEY = 1,
  1453. IB_MAD_IGNORE_BKEY = 2,
  1454. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  1455. };
  1456. enum ib_mad_result {
  1457. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  1458. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  1459. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  1460. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  1461. };
  1462. #define IB_DEVICE_NAME_MAX 64
  1463. struct ib_cache {
  1464. rwlock_t lock;
  1465. struct ib_event_handler event_handler;
  1466. struct ib_pkey_cache **pkey_cache;
  1467. struct ib_gid_table **gid_cache;
  1468. u8 *lmc_cache;
  1469. };
  1470. struct ib_dma_mapping_ops {
  1471. int (*mapping_error)(struct ib_device *dev,
  1472. u64 dma_addr);
  1473. u64 (*map_single)(struct ib_device *dev,
  1474. void *ptr, size_t size,
  1475. enum dma_data_direction direction);
  1476. void (*unmap_single)(struct ib_device *dev,
  1477. u64 addr, size_t size,
  1478. enum dma_data_direction direction);
  1479. u64 (*map_page)(struct ib_device *dev,
  1480. struct page *page, unsigned long offset,
  1481. size_t size,
  1482. enum dma_data_direction direction);
  1483. void (*unmap_page)(struct ib_device *dev,
  1484. u64 addr, size_t size,
  1485. enum dma_data_direction direction);
  1486. int (*map_sg)(struct ib_device *dev,
  1487. struct scatterlist *sg, int nents,
  1488. enum dma_data_direction direction);
  1489. void (*unmap_sg)(struct ib_device *dev,
  1490. struct scatterlist *sg, int nents,
  1491. enum dma_data_direction direction);
  1492. void (*sync_single_for_cpu)(struct ib_device *dev,
  1493. u64 dma_handle,
  1494. size_t size,
  1495. enum dma_data_direction dir);
  1496. void (*sync_single_for_device)(struct ib_device *dev,
  1497. u64 dma_handle,
  1498. size_t size,
  1499. enum dma_data_direction dir);
  1500. void *(*alloc_coherent)(struct ib_device *dev,
  1501. size_t size,
  1502. u64 *dma_handle,
  1503. gfp_t flag);
  1504. void (*free_coherent)(struct ib_device *dev,
  1505. size_t size, void *cpu_addr,
  1506. u64 dma_handle);
  1507. };
  1508. struct iw_cm_verbs;
  1509. struct ib_port_immutable {
  1510. int pkey_tbl_len;
  1511. int gid_tbl_len;
  1512. u32 core_cap_flags;
  1513. u32 max_mad_size;
  1514. };
  1515. struct ib_device {
  1516. struct device *dma_device;
  1517. char name[IB_DEVICE_NAME_MAX];
  1518. struct list_head event_handler_list;
  1519. spinlock_t event_handler_lock;
  1520. spinlock_t client_data_lock;
  1521. struct list_head core_list;
  1522. /* Access to the client_data_list is protected by the client_data_lock
  1523. * spinlock and the lists_rwsem read-write semaphore */
  1524. struct list_head client_data_list;
  1525. struct ib_cache cache;
  1526. /**
  1527. * port_immutable is indexed by port number
  1528. */
  1529. struct ib_port_immutable *port_immutable;
  1530. int num_comp_vectors;
  1531. struct iw_cm_verbs *iwcm;
  1532. /**
  1533. * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
  1534. * driver initialized data. The struct is kfree()'ed by the sysfs
  1535. * core when the device is removed. A lifespan of -1 in the return
  1536. * struct tells the core to set a default lifespan.
  1537. */
  1538. struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
  1539. u8 port_num);
  1540. /**
  1541. * get_hw_stats - Fill in the counter value(s) in the stats struct.
  1542. * @index - The index in the value array we wish to have updated, or
  1543. * num_counters if we want all stats updated
  1544. * Return codes -
  1545. * < 0 - Error, no counters updated
  1546. * index - Updated the single counter pointed to by index
  1547. * num_counters - Updated all counters (will reset the timestamp
  1548. * and prevent further calls for lifespan milliseconds)
  1549. * Drivers are allowed to update all counters in leiu of just the
  1550. * one given in index at their option
  1551. */
  1552. int (*get_hw_stats)(struct ib_device *device,
  1553. struct rdma_hw_stats *stats,
  1554. u8 port, int index);
  1555. int (*query_device)(struct ib_device *device,
  1556. struct ib_device_attr *device_attr,
  1557. struct ib_udata *udata);
  1558. int (*query_port)(struct ib_device *device,
  1559. u8 port_num,
  1560. struct ib_port_attr *port_attr);
  1561. enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
  1562. u8 port_num);
  1563. /* When calling get_netdev, the HW vendor's driver should return the
  1564. * net device of device @device at port @port_num or NULL if such
  1565. * a net device doesn't exist. The vendor driver should call dev_hold
  1566. * on this net device. The HW vendor's device driver must guarantee
  1567. * that this function returns NULL before the net device reaches
  1568. * NETDEV_UNREGISTER_FINAL state.
  1569. */
  1570. struct net_device *(*get_netdev)(struct ib_device *device,
  1571. u8 port_num);
  1572. int (*query_gid)(struct ib_device *device,
  1573. u8 port_num, int index,
  1574. union ib_gid *gid);
  1575. /* When calling add_gid, the HW vendor's driver should
  1576. * add the gid of device @device at gid index @index of
  1577. * port @port_num to be @gid. Meta-info of that gid (for example,
  1578. * the network device related to this gid is available
  1579. * at @attr. @context allows the HW vendor driver to store extra
  1580. * information together with a GID entry. The HW vendor may allocate
  1581. * memory to contain this information and store it in @context when a
  1582. * new GID entry is written to. Params are consistent until the next
  1583. * call of add_gid or delete_gid. The function should return 0 on
  1584. * success or error otherwise. The function could be called
  1585. * concurrently for different ports. This function is only called
  1586. * when roce_gid_table is used.
  1587. */
  1588. int (*add_gid)(struct ib_device *device,
  1589. u8 port_num,
  1590. unsigned int index,
  1591. const union ib_gid *gid,
  1592. const struct ib_gid_attr *attr,
  1593. void **context);
  1594. /* When calling del_gid, the HW vendor's driver should delete the
  1595. * gid of device @device at gid index @index of port @port_num.
  1596. * Upon the deletion of a GID entry, the HW vendor must free any
  1597. * allocated memory. The caller will clear @context afterwards.
  1598. * This function is only called when roce_gid_table is used.
  1599. */
  1600. int (*del_gid)(struct ib_device *device,
  1601. u8 port_num,
  1602. unsigned int index,
  1603. void **context);
  1604. int (*query_pkey)(struct ib_device *device,
  1605. u8 port_num, u16 index, u16 *pkey);
  1606. int (*modify_device)(struct ib_device *device,
  1607. int device_modify_mask,
  1608. struct ib_device_modify *device_modify);
  1609. int (*modify_port)(struct ib_device *device,
  1610. u8 port_num, int port_modify_mask,
  1611. struct ib_port_modify *port_modify);
  1612. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  1613. struct ib_udata *udata);
  1614. int (*dealloc_ucontext)(struct ib_ucontext *context);
  1615. int (*mmap)(struct ib_ucontext *context,
  1616. struct vm_area_struct *vma);
  1617. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  1618. struct ib_ucontext *context,
  1619. struct ib_udata *udata);
  1620. int (*dealloc_pd)(struct ib_pd *pd);
  1621. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  1622. struct ib_ah_attr *ah_attr);
  1623. int (*modify_ah)(struct ib_ah *ah,
  1624. struct ib_ah_attr *ah_attr);
  1625. int (*query_ah)(struct ib_ah *ah,
  1626. struct ib_ah_attr *ah_attr);
  1627. int (*destroy_ah)(struct ib_ah *ah);
  1628. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  1629. struct ib_srq_init_attr *srq_init_attr,
  1630. struct ib_udata *udata);
  1631. int (*modify_srq)(struct ib_srq *srq,
  1632. struct ib_srq_attr *srq_attr,
  1633. enum ib_srq_attr_mask srq_attr_mask,
  1634. struct ib_udata *udata);
  1635. int (*query_srq)(struct ib_srq *srq,
  1636. struct ib_srq_attr *srq_attr);
  1637. int (*destroy_srq)(struct ib_srq *srq);
  1638. int (*post_srq_recv)(struct ib_srq *srq,
  1639. struct ib_recv_wr *recv_wr,
  1640. struct ib_recv_wr **bad_recv_wr);
  1641. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  1642. struct ib_qp_init_attr *qp_init_attr,
  1643. struct ib_udata *udata);
  1644. int (*modify_qp)(struct ib_qp *qp,
  1645. struct ib_qp_attr *qp_attr,
  1646. int qp_attr_mask,
  1647. struct ib_udata *udata);
  1648. int (*query_qp)(struct ib_qp *qp,
  1649. struct ib_qp_attr *qp_attr,
  1650. int qp_attr_mask,
  1651. struct ib_qp_init_attr *qp_init_attr);
  1652. int (*destroy_qp)(struct ib_qp *qp);
  1653. int (*post_send)(struct ib_qp *qp,
  1654. struct ib_send_wr *send_wr,
  1655. struct ib_send_wr **bad_send_wr);
  1656. int (*post_recv)(struct ib_qp *qp,
  1657. struct ib_recv_wr *recv_wr,
  1658. struct ib_recv_wr **bad_recv_wr);
  1659. struct ib_cq * (*create_cq)(struct ib_device *device,
  1660. const struct ib_cq_init_attr *attr,
  1661. struct ib_ucontext *context,
  1662. struct ib_udata *udata);
  1663. int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
  1664. u16 cq_period);
  1665. int (*destroy_cq)(struct ib_cq *cq);
  1666. int (*resize_cq)(struct ib_cq *cq, int cqe,
  1667. struct ib_udata *udata);
  1668. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  1669. struct ib_wc *wc);
  1670. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  1671. int (*req_notify_cq)(struct ib_cq *cq,
  1672. enum ib_cq_notify_flags flags);
  1673. int (*req_ncomp_notif)(struct ib_cq *cq,
  1674. int wc_cnt);
  1675. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  1676. int mr_access_flags);
  1677. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  1678. u64 start, u64 length,
  1679. u64 virt_addr,
  1680. int mr_access_flags,
  1681. struct ib_udata *udata);
  1682. int (*rereg_user_mr)(struct ib_mr *mr,
  1683. int flags,
  1684. u64 start, u64 length,
  1685. u64 virt_addr,
  1686. int mr_access_flags,
  1687. struct ib_pd *pd,
  1688. struct ib_udata *udata);
  1689. int (*dereg_mr)(struct ib_mr *mr);
  1690. struct ib_mr * (*alloc_mr)(struct ib_pd *pd,
  1691. enum ib_mr_type mr_type,
  1692. u32 max_num_sg);
  1693. int (*map_mr_sg)(struct ib_mr *mr,
  1694. struct scatterlist *sg,
  1695. int sg_nents,
  1696. unsigned int *sg_offset);
  1697. struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
  1698. enum ib_mw_type type,
  1699. struct ib_udata *udata);
  1700. int (*dealloc_mw)(struct ib_mw *mw);
  1701. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  1702. int mr_access_flags,
  1703. struct ib_fmr_attr *fmr_attr);
  1704. int (*map_phys_fmr)(struct ib_fmr *fmr,
  1705. u64 *page_list, int list_len,
  1706. u64 iova);
  1707. int (*unmap_fmr)(struct list_head *fmr_list);
  1708. int (*dealloc_fmr)(struct ib_fmr *fmr);
  1709. int (*attach_mcast)(struct ib_qp *qp,
  1710. union ib_gid *gid,
  1711. u16 lid);
  1712. int (*detach_mcast)(struct ib_qp *qp,
  1713. union ib_gid *gid,
  1714. u16 lid);
  1715. int (*process_mad)(struct ib_device *device,
  1716. int process_mad_flags,
  1717. u8 port_num,
  1718. const struct ib_wc *in_wc,
  1719. const struct ib_grh *in_grh,
  1720. const struct ib_mad_hdr *in_mad,
  1721. size_t in_mad_size,
  1722. struct ib_mad_hdr *out_mad,
  1723. size_t *out_mad_size,
  1724. u16 *out_mad_pkey_index);
  1725. struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
  1726. struct ib_ucontext *ucontext,
  1727. struct ib_udata *udata);
  1728. int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
  1729. struct ib_flow * (*create_flow)(struct ib_qp *qp,
  1730. struct ib_flow_attr
  1731. *flow_attr,
  1732. int domain);
  1733. int (*destroy_flow)(struct ib_flow *flow_id);
  1734. int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
  1735. struct ib_mr_status *mr_status);
  1736. void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
  1737. void (*drain_rq)(struct ib_qp *qp);
  1738. void (*drain_sq)(struct ib_qp *qp);
  1739. int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
  1740. int state);
  1741. int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
  1742. struct ifla_vf_info *ivf);
  1743. int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
  1744. struct ifla_vf_stats *stats);
  1745. int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
  1746. int type);
  1747. struct ib_dma_mapping_ops *dma_ops;
  1748. struct module *owner;
  1749. struct device dev;
  1750. struct kobject *ports_parent;
  1751. struct list_head port_list;
  1752. enum {
  1753. IB_DEV_UNINITIALIZED,
  1754. IB_DEV_REGISTERED,
  1755. IB_DEV_UNREGISTERED
  1756. } reg_state;
  1757. int uverbs_abi_ver;
  1758. u64 uverbs_cmd_mask;
  1759. u64 uverbs_ex_cmd_mask;
  1760. char node_desc[64];
  1761. __be64 node_guid;
  1762. u32 local_dma_lkey;
  1763. u16 is_switch:1;
  1764. u8 node_type;
  1765. u8 phys_port_cnt;
  1766. struct ib_device_attr attrs;
  1767. struct attribute_group *hw_stats_ag;
  1768. struct rdma_hw_stats *hw_stats;
  1769. /**
  1770. * The following mandatory functions are used only at device
  1771. * registration. Keep functions such as these at the end of this
  1772. * structure to avoid cache line misses when accessing struct ib_device
  1773. * in fast paths.
  1774. */
  1775. int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
  1776. };
  1777. struct ib_client {
  1778. char *name;
  1779. void (*add) (struct ib_device *);
  1780. void (*remove)(struct ib_device *, void *client_data);
  1781. /* Returns the net_dev belonging to this ib_client and matching the
  1782. * given parameters.
  1783. * @dev: An RDMA device that the net_dev use for communication.
  1784. * @port: A physical port number on the RDMA device.
  1785. * @pkey: P_Key that the net_dev uses if applicable.
  1786. * @gid: A GID that the net_dev uses to communicate.
  1787. * @addr: An IP address the net_dev is configured with.
  1788. * @client_data: The device's client data set by ib_set_client_data().
  1789. *
  1790. * An ib_client that implements a net_dev on top of RDMA devices
  1791. * (such as IP over IB) should implement this callback, allowing the
  1792. * rdma_cm module to find the right net_dev for a given request.
  1793. *
  1794. * The caller is responsible for calling dev_put on the returned
  1795. * netdev. */
  1796. struct net_device *(*get_net_dev_by_params)(
  1797. struct ib_device *dev,
  1798. u8 port,
  1799. u16 pkey,
  1800. const union ib_gid *gid,
  1801. const struct sockaddr *addr,
  1802. void *client_data);
  1803. struct list_head list;
  1804. };
  1805. struct ib_device *ib_alloc_device(size_t size);
  1806. void ib_dealloc_device(struct ib_device *device);
  1807. int ib_register_device(struct ib_device *device,
  1808. int (*port_callback)(struct ib_device *,
  1809. u8, struct kobject *));
  1810. void ib_unregister_device(struct ib_device *device);
  1811. int ib_register_client (struct ib_client *client);
  1812. void ib_unregister_client(struct ib_client *client);
  1813. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  1814. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  1815. void *data);
  1816. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  1817. {
  1818. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  1819. }
  1820. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  1821. {
  1822. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  1823. }
  1824. static inline bool ib_is_udata_cleared(struct ib_udata *udata,
  1825. size_t offset,
  1826. size_t len)
  1827. {
  1828. const void __user *p = udata->inbuf + offset;
  1829. bool ret = false;
  1830. u8 *buf;
  1831. if (len > USHRT_MAX)
  1832. return false;
  1833. buf = kmalloc(len, GFP_KERNEL);
  1834. if (!buf)
  1835. return false;
  1836. if (copy_from_user(buf, p, len))
  1837. goto free;
  1838. ret = !memchr_inv(buf, 0, len);
  1839. free:
  1840. kfree(buf);
  1841. return ret;
  1842. }
  1843. /**
  1844. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  1845. * contains all required attributes and no attributes not allowed for
  1846. * the given QP state transition.
  1847. * @cur_state: Current QP state
  1848. * @next_state: Next QP state
  1849. * @type: QP type
  1850. * @mask: Mask of supplied QP attributes
  1851. * @ll : link layer of port
  1852. *
  1853. * This function is a helper function that a low-level driver's
  1854. * modify_qp method can use to validate the consumer's input. It
  1855. * checks that cur_state and next_state are valid QP states, that a
  1856. * transition from cur_state to next_state is allowed by the IB spec,
  1857. * and that the attribute mask supplied is allowed for the transition.
  1858. */
  1859. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  1860. enum ib_qp_type type, enum ib_qp_attr_mask mask,
  1861. enum rdma_link_layer ll);
  1862. int ib_register_event_handler (struct ib_event_handler *event_handler);
  1863. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  1864. void ib_dispatch_event(struct ib_event *event);
  1865. int ib_query_port(struct ib_device *device,
  1866. u8 port_num, struct ib_port_attr *port_attr);
  1867. enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
  1868. u8 port_num);
  1869. /**
  1870. * rdma_cap_ib_switch - Check if the device is IB switch
  1871. * @device: Device to check
  1872. *
  1873. * Device driver is responsible for setting is_switch bit on
  1874. * in ib_device structure at init time.
  1875. *
  1876. * Return: true if the device is IB switch.
  1877. */
  1878. static inline bool rdma_cap_ib_switch(const struct ib_device *device)
  1879. {
  1880. return device->is_switch;
  1881. }
  1882. /**
  1883. * rdma_start_port - Return the first valid port number for the device
  1884. * specified
  1885. *
  1886. * @device: Device to be checked
  1887. *
  1888. * Return start port number
  1889. */
  1890. static inline u8 rdma_start_port(const struct ib_device *device)
  1891. {
  1892. return rdma_cap_ib_switch(device) ? 0 : 1;
  1893. }
  1894. /**
  1895. * rdma_end_port - Return the last valid port number for the device
  1896. * specified
  1897. *
  1898. * @device: Device to be checked
  1899. *
  1900. * Return last port number
  1901. */
  1902. static inline u8 rdma_end_port(const struct ib_device *device)
  1903. {
  1904. return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
  1905. }
  1906. static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
  1907. {
  1908. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
  1909. }
  1910. static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
  1911. {
  1912. return device->port_immutable[port_num].core_cap_flags &
  1913. (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
  1914. }
  1915. static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
  1916. {
  1917. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
  1918. }
  1919. static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
  1920. {
  1921. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
  1922. }
  1923. static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
  1924. {
  1925. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
  1926. }
  1927. static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
  1928. {
  1929. return rdma_protocol_ib(device, port_num) ||
  1930. rdma_protocol_roce(device, port_num);
  1931. }
  1932. /**
  1933. * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
  1934. * Management Datagrams.
  1935. * @device: Device to check
  1936. * @port_num: Port number to check
  1937. *
  1938. * Management Datagrams (MAD) are a required part of the InfiniBand
  1939. * specification and are supported on all InfiniBand devices. A slightly
  1940. * extended version are also supported on OPA interfaces.
  1941. *
  1942. * Return: true if the port supports sending/receiving of MAD packets.
  1943. */
  1944. static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
  1945. {
  1946. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
  1947. }
  1948. /**
  1949. * rdma_cap_opa_mad - Check if the port of device provides support for OPA
  1950. * Management Datagrams.
  1951. * @device: Device to check
  1952. * @port_num: Port number to check
  1953. *
  1954. * Intel OmniPath devices extend and/or replace the InfiniBand Management
  1955. * datagrams with their own versions. These OPA MADs share many but not all of
  1956. * the characteristics of InfiniBand MADs.
  1957. *
  1958. * OPA MADs differ in the following ways:
  1959. *
  1960. * 1) MADs are variable size up to 2K
  1961. * IBTA defined MADs remain fixed at 256 bytes
  1962. * 2) OPA SMPs must carry valid PKeys
  1963. * 3) OPA SMP packets are a different format
  1964. *
  1965. * Return: true if the port supports OPA MAD packet formats.
  1966. */
  1967. static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
  1968. {
  1969. return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
  1970. == RDMA_CORE_CAP_OPA_MAD;
  1971. }
  1972. /**
  1973. * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
  1974. * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
  1975. * @device: Device to check
  1976. * @port_num: Port number to check
  1977. *
  1978. * Each InfiniBand node is required to provide a Subnet Management Agent
  1979. * that the subnet manager can access. Prior to the fabric being fully
  1980. * configured by the subnet manager, the SMA is accessed via a well known
  1981. * interface called the Subnet Management Interface (SMI). This interface
  1982. * uses directed route packets to communicate with the SM to get around the
  1983. * chicken and egg problem of the SM needing to know what's on the fabric
  1984. * in order to configure the fabric, and needing to configure the fabric in
  1985. * order to send packets to the devices on the fabric. These directed
  1986. * route packets do not need the fabric fully configured in order to reach
  1987. * their destination. The SMI is the only method allowed to send
  1988. * directed route packets on an InfiniBand fabric.
  1989. *
  1990. * Return: true if the port provides an SMI.
  1991. */
  1992. static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
  1993. {
  1994. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
  1995. }
  1996. /**
  1997. * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
  1998. * Communication Manager.
  1999. * @device: Device to check
  2000. * @port_num: Port number to check
  2001. *
  2002. * The InfiniBand Communication Manager is one of many pre-defined General
  2003. * Service Agents (GSA) that are accessed via the General Service
  2004. * Interface (GSI). It's role is to facilitate establishment of connections
  2005. * between nodes as well as other management related tasks for established
  2006. * connections.
  2007. *
  2008. * Return: true if the port supports an IB CM (this does not guarantee that
  2009. * a CM is actually running however).
  2010. */
  2011. static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
  2012. {
  2013. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
  2014. }
  2015. /**
  2016. * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
  2017. * Communication Manager.
  2018. * @device: Device to check
  2019. * @port_num: Port number to check
  2020. *
  2021. * Similar to above, but specific to iWARP connections which have a different
  2022. * managment protocol than InfiniBand.
  2023. *
  2024. * Return: true if the port supports an iWARP CM (this does not guarantee that
  2025. * a CM is actually running however).
  2026. */
  2027. static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
  2028. {
  2029. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
  2030. }
  2031. /**
  2032. * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
  2033. * Subnet Administration.
  2034. * @device: Device to check
  2035. * @port_num: Port number to check
  2036. *
  2037. * An InfiniBand Subnet Administration (SA) service is a pre-defined General
  2038. * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
  2039. * fabrics, devices should resolve routes to other hosts by contacting the
  2040. * SA to query the proper route.
  2041. *
  2042. * Return: true if the port should act as a client to the fabric Subnet
  2043. * Administration interface. This does not imply that the SA service is
  2044. * running locally.
  2045. */
  2046. static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
  2047. {
  2048. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
  2049. }
  2050. /**
  2051. * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
  2052. * Multicast.
  2053. * @device: Device to check
  2054. * @port_num: Port number to check
  2055. *
  2056. * InfiniBand multicast registration is more complex than normal IPv4 or
  2057. * IPv6 multicast registration. Each Host Channel Adapter must register
  2058. * with the Subnet Manager when it wishes to join a multicast group. It
  2059. * should do so only once regardless of how many queue pairs it subscribes
  2060. * to this group. And it should leave the group only after all queue pairs
  2061. * attached to the group have been detached.
  2062. *
  2063. * Return: true if the port must undertake the additional adminstrative
  2064. * overhead of registering/unregistering with the SM and tracking of the
  2065. * total number of queue pairs attached to the multicast group.
  2066. */
  2067. static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
  2068. {
  2069. return rdma_cap_ib_sa(device, port_num);
  2070. }
  2071. /**
  2072. * rdma_cap_af_ib - Check if the port of device has the capability
  2073. * Native Infiniband Address.
  2074. * @device: Device to check
  2075. * @port_num: Port number to check
  2076. *
  2077. * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
  2078. * GID. RoCE uses a different mechanism, but still generates a GID via
  2079. * a prescribed mechanism and port specific data.
  2080. *
  2081. * Return: true if the port uses a GID address to identify devices on the
  2082. * network.
  2083. */
  2084. static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
  2085. {
  2086. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
  2087. }
  2088. /**
  2089. * rdma_cap_eth_ah - Check if the port of device has the capability
  2090. * Ethernet Address Handle.
  2091. * @device: Device to check
  2092. * @port_num: Port number to check
  2093. *
  2094. * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
  2095. * to fabricate GIDs over Ethernet/IP specific addresses native to the
  2096. * port. Normally, packet headers are generated by the sending host
  2097. * adapter, but when sending connectionless datagrams, we must manually
  2098. * inject the proper headers for the fabric we are communicating over.
  2099. *
  2100. * Return: true if we are running as a RoCE port and must force the
  2101. * addition of a Global Route Header built from our Ethernet Address
  2102. * Handle into our header list for connectionless packets.
  2103. */
  2104. static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
  2105. {
  2106. return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
  2107. }
  2108. /**
  2109. * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
  2110. *
  2111. * @device: Device
  2112. * @port_num: Port number
  2113. *
  2114. * This MAD size includes the MAD headers and MAD payload. No other headers
  2115. * are included.
  2116. *
  2117. * Return the max MAD size required by the Port. Will return 0 if the port
  2118. * does not support MADs
  2119. */
  2120. static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
  2121. {
  2122. return device->port_immutable[port_num].max_mad_size;
  2123. }
  2124. /**
  2125. * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
  2126. * @device: Device to check
  2127. * @port_num: Port number to check
  2128. *
  2129. * RoCE GID table mechanism manages the various GIDs for a device.
  2130. *
  2131. * NOTE: if allocating the port's GID table has failed, this call will still
  2132. * return true, but any RoCE GID table API will fail.
  2133. *
  2134. * Return: true if the port uses RoCE GID table mechanism in order to manage
  2135. * its GIDs.
  2136. */
  2137. static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
  2138. u8 port_num)
  2139. {
  2140. return rdma_protocol_roce(device, port_num) &&
  2141. device->add_gid && device->del_gid;
  2142. }
  2143. /*
  2144. * Check if the device supports READ W/ INVALIDATE.
  2145. */
  2146. static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
  2147. {
  2148. /*
  2149. * iWarp drivers must support READ W/ INVALIDATE. No other protocol
  2150. * has support for it yet.
  2151. */
  2152. return rdma_protocol_iwarp(dev, port_num);
  2153. }
  2154. int ib_query_gid(struct ib_device *device,
  2155. u8 port_num, int index, union ib_gid *gid,
  2156. struct ib_gid_attr *attr);
  2157. int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
  2158. int state);
  2159. int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
  2160. struct ifla_vf_info *info);
  2161. int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
  2162. struct ifla_vf_stats *stats);
  2163. int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
  2164. int type);
  2165. int ib_query_pkey(struct ib_device *device,
  2166. u8 port_num, u16 index, u16 *pkey);
  2167. int ib_modify_device(struct ib_device *device,
  2168. int device_modify_mask,
  2169. struct ib_device_modify *device_modify);
  2170. int ib_modify_port(struct ib_device *device,
  2171. u8 port_num, int port_modify_mask,
  2172. struct ib_port_modify *port_modify);
  2173. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  2174. enum ib_gid_type gid_type, struct net_device *ndev,
  2175. u8 *port_num, u16 *index);
  2176. int ib_find_pkey(struct ib_device *device,
  2177. u8 port_num, u16 pkey, u16 *index);
  2178. struct ib_pd *ib_alloc_pd(struct ib_device *device);
  2179. void ib_dealloc_pd(struct ib_pd *pd);
  2180. /**
  2181. * ib_create_ah - Creates an address handle for the given address vector.
  2182. * @pd: The protection domain associated with the address handle.
  2183. * @ah_attr: The attributes of the address vector.
  2184. *
  2185. * The address handle is used to reference a local or global destination
  2186. * in all UD QP post sends.
  2187. */
  2188. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  2189. /**
  2190. * ib_init_ah_from_wc - Initializes address handle attributes from a
  2191. * work completion.
  2192. * @device: Device on which the received message arrived.
  2193. * @port_num: Port on which the received message arrived.
  2194. * @wc: Work completion associated with the received message.
  2195. * @grh: References the received global route header. This parameter is
  2196. * ignored unless the work completion indicates that the GRH is valid.
  2197. * @ah_attr: Returned attributes that can be used when creating an address
  2198. * handle for replying to the message.
  2199. */
  2200. int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
  2201. const struct ib_wc *wc, const struct ib_grh *grh,
  2202. struct ib_ah_attr *ah_attr);
  2203. /**
  2204. * ib_create_ah_from_wc - Creates an address handle associated with the
  2205. * sender of the specified work completion.
  2206. * @pd: The protection domain associated with the address handle.
  2207. * @wc: Work completion information associated with a received message.
  2208. * @grh: References the received global route header. This parameter is
  2209. * ignored unless the work completion indicates that the GRH is valid.
  2210. * @port_num: The outbound port number to associate with the address.
  2211. *
  2212. * The address handle is used to reference a local or global destination
  2213. * in all UD QP post sends.
  2214. */
  2215. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
  2216. const struct ib_grh *grh, u8 port_num);
  2217. /**
  2218. * ib_modify_ah - Modifies the address vector associated with an address
  2219. * handle.
  2220. * @ah: The address handle to modify.
  2221. * @ah_attr: The new address vector attributes to associate with the
  2222. * address handle.
  2223. */
  2224. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  2225. /**
  2226. * ib_query_ah - Queries the address vector associated with an address
  2227. * handle.
  2228. * @ah: The address handle to query.
  2229. * @ah_attr: The address vector attributes associated with the address
  2230. * handle.
  2231. */
  2232. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  2233. /**
  2234. * ib_destroy_ah - Destroys an address handle.
  2235. * @ah: The address handle to destroy.
  2236. */
  2237. int ib_destroy_ah(struct ib_ah *ah);
  2238. /**
  2239. * ib_create_srq - Creates a SRQ associated with the specified protection
  2240. * domain.
  2241. * @pd: The protection domain associated with the SRQ.
  2242. * @srq_init_attr: A list of initial attributes required to create the
  2243. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  2244. * the actual capabilities of the created SRQ.
  2245. *
  2246. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  2247. * requested size of the SRQ, and set to the actual values allocated
  2248. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  2249. * will always be at least as large as the requested values.
  2250. */
  2251. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  2252. struct ib_srq_init_attr *srq_init_attr);
  2253. /**
  2254. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  2255. * @srq: The SRQ to modify.
  2256. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  2257. * the current values of selected SRQ attributes are returned.
  2258. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  2259. * are being modified.
  2260. *
  2261. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  2262. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  2263. * the number of receives queued drops below the limit.
  2264. */
  2265. int ib_modify_srq(struct ib_srq *srq,
  2266. struct ib_srq_attr *srq_attr,
  2267. enum ib_srq_attr_mask srq_attr_mask);
  2268. /**
  2269. * ib_query_srq - Returns the attribute list and current values for the
  2270. * specified SRQ.
  2271. * @srq: The SRQ to query.
  2272. * @srq_attr: The attributes of the specified SRQ.
  2273. */
  2274. int ib_query_srq(struct ib_srq *srq,
  2275. struct ib_srq_attr *srq_attr);
  2276. /**
  2277. * ib_destroy_srq - Destroys the specified SRQ.
  2278. * @srq: The SRQ to destroy.
  2279. */
  2280. int ib_destroy_srq(struct ib_srq *srq);
  2281. /**
  2282. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  2283. * @srq: The SRQ to post the work request on.
  2284. * @recv_wr: A list of work requests to post on the receive queue.
  2285. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2286. * the work request that failed to be posted on the QP.
  2287. */
  2288. static inline int ib_post_srq_recv(struct ib_srq *srq,
  2289. struct ib_recv_wr *recv_wr,
  2290. struct ib_recv_wr **bad_recv_wr)
  2291. {
  2292. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  2293. }
  2294. /**
  2295. * ib_create_qp - Creates a QP associated with the specified protection
  2296. * domain.
  2297. * @pd: The protection domain associated with the QP.
  2298. * @qp_init_attr: A list of initial attributes required to create the
  2299. * QP. If QP creation succeeds, then the attributes are updated to
  2300. * the actual capabilities of the created QP.
  2301. */
  2302. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  2303. struct ib_qp_init_attr *qp_init_attr);
  2304. /**
  2305. * ib_modify_qp - Modifies the attributes for the specified QP and then
  2306. * transitions the QP to the given state.
  2307. * @qp: The QP to modify.
  2308. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  2309. * the current values of selected QP attributes are returned.
  2310. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  2311. * are being modified.
  2312. */
  2313. int ib_modify_qp(struct ib_qp *qp,
  2314. struct ib_qp_attr *qp_attr,
  2315. int qp_attr_mask);
  2316. /**
  2317. * ib_query_qp - Returns the attribute list and current values for the
  2318. * specified QP.
  2319. * @qp: The QP to query.
  2320. * @qp_attr: The attributes of the specified QP.
  2321. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  2322. * @qp_init_attr: Additional attributes of the selected QP.
  2323. *
  2324. * The qp_attr_mask may be used to limit the query to gathering only the
  2325. * selected attributes.
  2326. */
  2327. int ib_query_qp(struct ib_qp *qp,
  2328. struct ib_qp_attr *qp_attr,
  2329. int qp_attr_mask,
  2330. struct ib_qp_init_attr *qp_init_attr);
  2331. /**
  2332. * ib_destroy_qp - Destroys the specified QP.
  2333. * @qp: The QP to destroy.
  2334. */
  2335. int ib_destroy_qp(struct ib_qp *qp);
  2336. /**
  2337. * ib_open_qp - Obtain a reference to an existing sharable QP.
  2338. * @xrcd - XRC domain
  2339. * @qp_open_attr: Attributes identifying the QP to open.
  2340. *
  2341. * Returns a reference to a sharable QP.
  2342. */
  2343. struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
  2344. struct ib_qp_open_attr *qp_open_attr);
  2345. /**
  2346. * ib_close_qp - Release an external reference to a QP.
  2347. * @qp: The QP handle to release
  2348. *
  2349. * The opened QP handle is released by the caller. The underlying
  2350. * shared QP is not destroyed until all internal references are released.
  2351. */
  2352. int ib_close_qp(struct ib_qp *qp);
  2353. /**
  2354. * ib_post_send - Posts a list of work requests to the send queue of
  2355. * the specified QP.
  2356. * @qp: The QP to post the work request on.
  2357. * @send_wr: A list of work requests to post on the send queue.
  2358. * @bad_send_wr: On an immediate failure, this parameter will reference
  2359. * the work request that failed to be posted on the QP.
  2360. *
  2361. * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
  2362. * error is returned, the QP state shall not be affected,
  2363. * ib_post_send() will return an immediate error after queueing any
  2364. * earlier work requests in the list.
  2365. */
  2366. static inline int ib_post_send(struct ib_qp *qp,
  2367. struct ib_send_wr *send_wr,
  2368. struct ib_send_wr **bad_send_wr)
  2369. {
  2370. return qp->device->post_send(qp, send_wr, bad_send_wr);
  2371. }
  2372. /**
  2373. * ib_post_recv - Posts a list of work requests to the receive queue of
  2374. * the specified QP.
  2375. * @qp: The QP to post the work request on.
  2376. * @recv_wr: A list of work requests to post on the receive queue.
  2377. * @bad_recv_wr: On an immediate failure, this parameter will reference
  2378. * the work request that failed to be posted on the QP.
  2379. */
  2380. static inline int ib_post_recv(struct ib_qp *qp,
  2381. struct ib_recv_wr *recv_wr,
  2382. struct ib_recv_wr **bad_recv_wr)
  2383. {
  2384. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  2385. }
  2386. struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
  2387. int nr_cqe, int comp_vector, enum ib_poll_context poll_ctx);
  2388. void ib_free_cq(struct ib_cq *cq);
  2389. int ib_process_cq_direct(struct ib_cq *cq, int budget);
  2390. /**
  2391. * ib_create_cq - Creates a CQ on the specified device.
  2392. * @device: The device on which to create the CQ.
  2393. * @comp_handler: A user-specified callback that is invoked when a
  2394. * completion event occurs on the CQ.
  2395. * @event_handler: A user-specified callback that is invoked when an
  2396. * asynchronous event not associated with a completion occurs on the CQ.
  2397. * @cq_context: Context associated with the CQ returned to the user via
  2398. * the associated completion and event handlers.
  2399. * @cq_attr: The attributes the CQ should be created upon.
  2400. *
  2401. * Users can examine the cq structure to determine the actual CQ size.
  2402. */
  2403. struct ib_cq *ib_create_cq(struct ib_device *device,
  2404. ib_comp_handler comp_handler,
  2405. void (*event_handler)(struct ib_event *, void *),
  2406. void *cq_context,
  2407. const struct ib_cq_init_attr *cq_attr);
  2408. /**
  2409. * ib_resize_cq - Modifies the capacity of the CQ.
  2410. * @cq: The CQ to resize.
  2411. * @cqe: The minimum size of the CQ.
  2412. *
  2413. * Users can examine the cq structure to determine the actual CQ size.
  2414. */
  2415. int ib_resize_cq(struct ib_cq *cq, int cqe);
  2416. /**
  2417. * ib_modify_cq - Modifies moderation params of the CQ
  2418. * @cq: The CQ to modify.
  2419. * @cq_count: number of CQEs that will trigger an event
  2420. * @cq_period: max period of time in usec before triggering an event
  2421. *
  2422. */
  2423. int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  2424. /**
  2425. * ib_destroy_cq - Destroys the specified CQ.
  2426. * @cq: The CQ to destroy.
  2427. */
  2428. int ib_destroy_cq(struct ib_cq *cq);
  2429. /**
  2430. * ib_poll_cq - poll a CQ for completion(s)
  2431. * @cq:the CQ being polled
  2432. * @num_entries:maximum number of completions to return
  2433. * @wc:array of at least @num_entries &struct ib_wc where completions
  2434. * will be returned
  2435. *
  2436. * Poll a CQ for (possibly multiple) completions. If the return value
  2437. * is < 0, an error occurred. If the return value is >= 0, it is the
  2438. * number of completions returned. If the return value is
  2439. * non-negative and < num_entries, then the CQ was emptied.
  2440. */
  2441. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  2442. struct ib_wc *wc)
  2443. {
  2444. return cq->device->poll_cq(cq, num_entries, wc);
  2445. }
  2446. /**
  2447. * ib_peek_cq - Returns the number of unreaped completions currently
  2448. * on the specified CQ.
  2449. * @cq: The CQ to peek.
  2450. * @wc_cnt: A minimum number of unreaped completions to check for.
  2451. *
  2452. * If the number of unreaped completions is greater than or equal to wc_cnt,
  2453. * this function returns wc_cnt, otherwise, it returns the actual number of
  2454. * unreaped completions.
  2455. */
  2456. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  2457. /**
  2458. * ib_req_notify_cq - Request completion notification on a CQ.
  2459. * @cq: The CQ to generate an event for.
  2460. * @flags:
  2461. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  2462. * to request an event on the next solicited event or next work
  2463. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  2464. * may also be |ed in to request a hint about missed events, as
  2465. * described below.
  2466. *
  2467. * Return Value:
  2468. * < 0 means an error occurred while requesting notification
  2469. * == 0 means notification was requested successfully, and if
  2470. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  2471. * were missed and it is safe to wait for another event. In
  2472. * this case is it guaranteed that any work completions added
  2473. * to the CQ since the last CQ poll will trigger a completion
  2474. * notification event.
  2475. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  2476. * in. It means that the consumer must poll the CQ again to
  2477. * make sure it is empty to avoid missing an event because of a
  2478. * race between requesting notification and an entry being
  2479. * added to the CQ. This return value means it is possible
  2480. * (but not guaranteed) that a work completion has been added
  2481. * to the CQ since the last poll without triggering a
  2482. * completion notification event.
  2483. */
  2484. static inline int ib_req_notify_cq(struct ib_cq *cq,
  2485. enum ib_cq_notify_flags flags)
  2486. {
  2487. return cq->device->req_notify_cq(cq, flags);
  2488. }
  2489. /**
  2490. * ib_req_ncomp_notif - Request completion notification when there are
  2491. * at least the specified number of unreaped completions on the CQ.
  2492. * @cq: The CQ to generate an event for.
  2493. * @wc_cnt: The number of unreaped completions that should be on the
  2494. * CQ before an event is generated.
  2495. */
  2496. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  2497. {
  2498. return cq->device->req_ncomp_notif ?
  2499. cq->device->req_ncomp_notif(cq, wc_cnt) :
  2500. -ENOSYS;
  2501. }
  2502. /**
  2503. * ib_get_dma_mr - Returns a memory region for system memory that is
  2504. * usable for DMA.
  2505. * @pd: The protection domain associated with the memory region.
  2506. * @mr_access_flags: Specifies the memory access rights.
  2507. *
  2508. * Note that the ib_dma_*() functions defined below must be used
  2509. * to create/destroy addresses used with the Lkey or Rkey returned
  2510. * by ib_get_dma_mr().
  2511. */
  2512. struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
  2513. /**
  2514. * ib_dma_mapping_error - check a DMA addr for error
  2515. * @dev: The device for which the dma_addr was created
  2516. * @dma_addr: The DMA address to check
  2517. */
  2518. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  2519. {
  2520. if (dev->dma_ops)
  2521. return dev->dma_ops->mapping_error(dev, dma_addr);
  2522. return dma_mapping_error(dev->dma_device, dma_addr);
  2523. }
  2524. /**
  2525. * ib_dma_map_single - Map a kernel virtual address to DMA address
  2526. * @dev: The device for which the dma_addr is to be created
  2527. * @cpu_addr: The kernel virtual address
  2528. * @size: The size of the region in bytes
  2529. * @direction: The direction of the DMA
  2530. */
  2531. static inline u64 ib_dma_map_single(struct ib_device *dev,
  2532. void *cpu_addr, size_t size,
  2533. enum dma_data_direction direction)
  2534. {
  2535. if (dev->dma_ops)
  2536. return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
  2537. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  2538. }
  2539. /**
  2540. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  2541. * @dev: The device for which the DMA address was created
  2542. * @addr: The DMA address
  2543. * @size: The size of the region in bytes
  2544. * @direction: The direction of the DMA
  2545. */
  2546. static inline void ib_dma_unmap_single(struct ib_device *dev,
  2547. u64 addr, size_t size,
  2548. enum dma_data_direction direction)
  2549. {
  2550. if (dev->dma_ops)
  2551. dev->dma_ops->unmap_single(dev, addr, size, direction);
  2552. else
  2553. dma_unmap_single(dev->dma_device, addr, size, direction);
  2554. }
  2555. static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
  2556. void *cpu_addr, size_t size,
  2557. enum dma_data_direction direction,
  2558. struct dma_attrs *attrs)
  2559. {
  2560. return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
  2561. direction, attrs);
  2562. }
  2563. static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
  2564. u64 addr, size_t size,
  2565. enum dma_data_direction direction,
  2566. struct dma_attrs *attrs)
  2567. {
  2568. return dma_unmap_single_attrs(dev->dma_device, addr, size,
  2569. direction, attrs);
  2570. }
  2571. /**
  2572. * ib_dma_map_page - Map a physical page to DMA address
  2573. * @dev: The device for which the dma_addr is to be created
  2574. * @page: The page to be mapped
  2575. * @offset: The offset within the page
  2576. * @size: The size of the region in bytes
  2577. * @direction: The direction of the DMA
  2578. */
  2579. static inline u64 ib_dma_map_page(struct ib_device *dev,
  2580. struct page *page,
  2581. unsigned long offset,
  2582. size_t size,
  2583. enum dma_data_direction direction)
  2584. {
  2585. if (dev->dma_ops)
  2586. return dev->dma_ops->map_page(dev, page, offset, size, direction);
  2587. return dma_map_page(dev->dma_device, page, offset, size, direction);
  2588. }
  2589. /**
  2590. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  2591. * @dev: The device for which the DMA address was created
  2592. * @addr: The DMA address
  2593. * @size: The size of the region in bytes
  2594. * @direction: The direction of the DMA
  2595. */
  2596. static inline void ib_dma_unmap_page(struct ib_device *dev,
  2597. u64 addr, size_t size,
  2598. enum dma_data_direction direction)
  2599. {
  2600. if (dev->dma_ops)
  2601. dev->dma_ops->unmap_page(dev, addr, size, direction);
  2602. else
  2603. dma_unmap_page(dev->dma_device, addr, size, direction);
  2604. }
  2605. /**
  2606. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  2607. * @dev: The device for which the DMA addresses are to be created
  2608. * @sg: The array of scatter/gather entries
  2609. * @nents: The number of scatter/gather entries
  2610. * @direction: The direction of the DMA
  2611. */
  2612. static inline int ib_dma_map_sg(struct ib_device *dev,
  2613. struct scatterlist *sg, int nents,
  2614. enum dma_data_direction direction)
  2615. {
  2616. if (dev->dma_ops)
  2617. return dev->dma_ops->map_sg(dev, sg, nents, direction);
  2618. return dma_map_sg(dev->dma_device, sg, nents, direction);
  2619. }
  2620. /**
  2621. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  2622. * @dev: The device for which the DMA addresses were created
  2623. * @sg: The array of scatter/gather entries
  2624. * @nents: The number of scatter/gather entries
  2625. * @direction: The direction of the DMA
  2626. */
  2627. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  2628. struct scatterlist *sg, int nents,
  2629. enum dma_data_direction direction)
  2630. {
  2631. if (dev->dma_ops)
  2632. dev->dma_ops->unmap_sg(dev, sg, nents, direction);
  2633. else
  2634. dma_unmap_sg(dev->dma_device, sg, nents, direction);
  2635. }
  2636. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  2637. struct scatterlist *sg, int nents,
  2638. enum dma_data_direction direction,
  2639. struct dma_attrs *attrs)
  2640. {
  2641. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  2642. }
  2643. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  2644. struct scatterlist *sg, int nents,
  2645. enum dma_data_direction direction,
  2646. struct dma_attrs *attrs)
  2647. {
  2648. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  2649. }
  2650. /**
  2651. * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
  2652. * @dev: The device for which the DMA addresses were created
  2653. * @sg: The scatter/gather entry
  2654. *
  2655. * Note: this function is obsolete. To do: change all occurrences of
  2656. * ib_sg_dma_address() into sg_dma_address().
  2657. */
  2658. static inline u64 ib_sg_dma_address(struct ib_device *dev,
  2659. struct scatterlist *sg)
  2660. {
  2661. return sg_dma_address(sg);
  2662. }
  2663. /**
  2664. * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
  2665. * @dev: The device for which the DMA addresses were created
  2666. * @sg: The scatter/gather entry
  2667. *
  2668. * Note: this function is obsolete. To do: change all occurrences of
  2669. * ib_sg_dma_len() into sg_dma_len().
  2670. */
  2671. static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
  2672. struct scatterlist *sg)
  2673. {
  2674. return sg_dma_len(sg);
  2675. }
  2676. /**
  2677. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  2678. * @dev: The device for which the DMA address was created
  2679. * @addr: The DMA address
  2680. * @size: The size of the region in bytes
  2681. * @dir: The direction of the DMA
  2682. */
  2683. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  2684. u64 addr,
  2685. size_t size,
  2686. enum dma_data_direction dir)
  2687. {
  2688. if (dev->dma_ops)
  2689. dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
  2690. else
  2691. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  2692. }
  2693. /**
  2694. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  2695. * @dev: The device for which the DMA address was created
  2696. * @addr: The DMA address
  2697. * @size: The size of the region in bytes
  2698. * @dir: The direction of the DMA
  2699. */
  2700. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  2701. u64 addr,
  2702. size_t size,
  2703. enum dma_data_direction dir)
  2704. {
  2705. if (dev->dma_ops)
  2706. dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
  2707. else
  2708. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  2709. }
  2710. /**
  2711. * ib_dma_alloc_coherent - Allocate memory and map it for DMA
  2712. * @dev: The device for which the DMA address is requested
  2713. * @size: The size of the region to allocate in bytes
  2714. * @dma_handle: A pointer for returning the DMA address of the region
  2715. * @flag: memory allocator flags
  2716. */
  2717. static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
  2718. size_t size,
  2719. u64 *dma_handle,
  2720. gfp_t flag)
  2721. {
  2722. if (dev->dma_ops)
  2723. return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  2724. else {
  2725. dma_addr_t handle;
  2726. void *ret;
  2727. ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
  2728. *dma_handle = handle;
  2729. return ret;
  2730. }
  2731. }
  2732. /**
  2733. * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
  2734. * @dev: The device for which the DMA addresses were allocated
  2735. * @size: The size of the region
  2736. * @cpu_addr: the address returned by ib_dma_alloc_coherent()
  2737. * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
  2738. */
  2739. static inline void ib_dma_free_coherent(struct ib_device *dev,
  2740. size_t size, void *cpu_addr,
  2741. u64 dma_handle)
  2742. {
  2743. if (dev->dma_ops)
  2744. dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  2745. else
  2746. dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
  2747. }
  2748. /**
  2749. * ib_dereg_mr - Deregisters a memory region and removes it from the
  2750. * HCA translation table.
  2751. * @mr: The memory region to deregister.
  2752. *
  2753. * This function can fail, if the memory region has memory windows bound to it.
  2754. */
  2755. int ib_dereg_mr(struct ib_mr *mr);
  2756. struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
  2757. enum ib_mr_type mr_type,
  2758. u32 max_num_sg);
  2759. /**
  2760. * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
  2761. * R_Key and L_Key.
  2762. * @mr - struct ib_mr pointer to be updated.
  2763. * @newkey - new key to be used.
  2764. */
  2765. static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
  2766. {
  2767. mr->lkey = (mr->lkey & 0xffffff00) | newkey;
  2768. mr->rkey = (mr->rkey & 0xffffff00) | newkey;
  2769. }
  2770. /**
  2771. * ib_inc_rkey - increments the key portion of the given rkey. Can be used
  2772. * for calculating a new rkey for type 2 memory windows.
  2773. * @rkey - the rkey to increment.
  2774. */
  2775. static inline u32 ib_inc_rkey(u32 rkey)
  2776. {
  2777. const u32 mask = 0x000000ff;
  2778. return ((rkey + 1) & mask) | (rkey & ~mask);
  2779. }
  2780. /**
  2781. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  2782. * @pd: The protection domain associated with the unmapped region.
  2783. * @mr_access_flags: Specifies the memory access rights.
  2784. * @fmr_attr: Attributes of the unmapped region.
  2785. *
  2786. * A fast memory region must be mapped before it can be used as part of
  2787. * a work request.
  2788. */
  2789. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  2790. int mr_access_flags,
  2791. struct ib_fmr_attr *fmr_attr);
  2792. /**
  2793. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  2794. * @fmr: The fast memory region to associate with the pages.
  2795. * @page_list: An array of physical pages to map to the fast memory region.
  2796. * @list_len: The number of pages in page_list.
  2797. * @iova: The I/O virtual address to use with the mapped region.
  2798. */
  2799. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  2800. u64 *page_list, int list_len,
  2801. u64 iova)
  2802. {
  2803. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  2804. }
  2805. /**
  2806. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  2807. * @fmr_list: A linked list of fast memory regions to unmap.
  2808. */
  2809. int ib_unmap_fmr(struct list_head *fmr_list);
  2810. /**
  2811. * ib_dealloc_fmr - Deallocates a fast memory region.
  2812. * @fmr: The fast memory region to deallocate.
  2813. */
  2814. int ib_dealloc_fmr(struct ib_fmr *fmr);
  2815. /**
  2816. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  2817. * @qp: QP to attach to the multicast group. The QP must be type
  2818. * IB_QPT_UD.
  2819. * @gid: Multicast group GID.
  2820. * @lid: Multicast group LID in host byte order.
  2821. *
  2822. * In order to send and receive multicast packets, subnet
  2823. * administration must have created the multicast group and configured
  2824. * the fabric appropriately. The port associated with the specified
  2825. * QP must also be a member of the multicast group.
  2826. */
  2827. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2828. /**
  2829. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  2830. * @qp: QP to detach from the multicast group.
  2831. * @gid: Multicast group GID.
  2832. * @lid: Multicast group LID in host byte order.
  2833. */
  2834. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2835. /**
  2836. * ib_alloc_xrcd - Allocates an XRC domain.
  2837. * @device: The device on which to allocate the XRC domain.
  2838. */
  2839. struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
  2840. /**
  2841. * ib_dealloc_xrcd - Deallocates an XRC domain.
  2842. * @xrcd: The XRC domain to deallocate.
  2843. */
  2844. int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  2845. struct ib_flow *ib_create_flow(struct ib_qp *qp,
  2846. struct ib_flow_attr *flow_attr, int domain);
  2847. int ib_destroy_flow(struct ib_flow *flow_id);
  2848. static inline int ib_check_mr_access(int flags)
  2849. {
  2850. /*
  2851. * Local write permission is required if remote write or
  2852. * remote atomic permission is also requested.
  2853. */
  2854. if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
  2855. !(flags & IB_ACCESS_LOCAL_WRITE))
  2856. return -EINVAL;
  2857. return 0;
  2858. }
  2859. /**
  2860. * ib_check_mr_status: lightweight check of MR status.
  2861. * This routine may provide status checks on a selected
  2862. * ib_mr. first use is for signature status check.
  2863. *
  2864. * @mr: A memory region.
  2865. * @check_mask: Bitmask of which checks to perform from
  2866. * ib_mr_status_check enumeration.
  2867. * @mr_status: The container of relevant status checks.
  2868. * failed checks will be indicated in the status bitmask
  2869. * and the relevant info shall be in the error item.
  2870. */
  2871. int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
  2872. struct ib_mr_status *mr_status);
  2873. struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
  2874. u16 pkey, const union ib_gid *gid,
  2875. const struct sockaddr *addr);
  2876. int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  2877. unsigned int *sg_offset, unsigned int page_size);
  2878. static inline int
  2879. ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
  2880. unsigned int *sg_offset, unsigned int page_size)
  2881. {
  2882. int n;
  2883. n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
  2884. mr->iova = 0;
  2885. return n;
  2886. }
  2887. int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
  2888. unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
  2889. void ib_drain_rq(struct ib_qp *qp);
  2890. void ib_drain_sq(struct ib_qp *qp);
  2891. void ib_drain_qp(struct ib_qp *qp);
  2892. #endif /* IB_VERBS_H */