ib_verbs.h 88 KB

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