ib_verbs.h 90 KB

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