ib_verbs.h 87 KB

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