ib_verbs.h 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387
  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/atomic.h>
  50. #include <asm/uaccess.h>
  51. extern struct workqueue_struct *ib_wq;
  52. union ib_gid {
  53. u8 raw[16];
  54. struct {
  55. __be64 subnet_prefix;
  56. __be64 interface_id;
  57. } global;
  58. };
  59. enum rdma_node_type {
  60. /* IB values map to NodeInfo:NodeType. */
  61. RDMA_NODE_IB_CA = 1,
  62. RDMA_NODE_IB_SWITCH,
  63. RDMA_NODE_IB_ROUTER,
  64. RDMA_NODE_RNIC
  65. };
  66. enum rdma_transport_type {
  67. RDMA_TRANSPORT_IB,
  68. RDMA_TRANSPORT_IWARP
  69. };
  70. enum rdma_transport_type
  71. rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
  72. enum rdma_link_layer {
  73. IB_LINK_LAYER_UNSPECIFIED,
  74. IB_LINK_LAYER_INFINIBAND,
  75. IB_LINK_LAYER_ETHERNET,
  76. };
  77. enum ib_device_cap_flags {
  78. IB_DEVICE_RESIZE_MAX_WR = 1,
  79. IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
  80. IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
  81. IB_DEVICE_RAW_MULTI = (1<<3),
  82. IB_DEVICE_AUTO_PATH_MIG = (1<<4),
  83. IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
  84. IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
  85. IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
  86. IB_DEVICE_SHUTDOWN_PORT = (1<<8),
  87. IB_DEVICE_INIT_TYPE = (1<<9),
  88. IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
  89. IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
  90. IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
  91. IB_DEVICE_SRQ_RESIZE = (1<<13),
  92. IB_DEVICE_N_NOTIFY_CQ = (1<<14),
  93. IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
  94. IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
  95. IB_DEVICE_MEM_WINDOW = (1<<17),
  96. /*
  97. * Devices should set IB_DEVICE_UD_IP_SUM if they support
  98. * insertion of UDP and TCP checksum on outgoing UD IPoIB
  99. * messages and can verify the validity of checksum for
  100. * incoming messages. Setting this flag implies that the
  101. * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
  102. */
  103. IB_DEVICE_UD_IP_CSUM = (1<<18),
  104. IB_DEVICE_UD_TSO = (1<<19),
  105. IB_DEVICE_XRC = (1<<20),
  106. IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
  107. IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
  108. IB_DEVICE_MEM_WINDOW_TYPE_2A = (1<<23),
  109. IB_DEVICE_MEM_WINDOW_TYPE_2B = (1<<24),
  110. IB_DEVICE_MANAGED_FLOW_STEERING = (1<<29)
  111. };
  112. enum ib_atomic_cap {
  113. IB_ATOMIC_NONE,
  114. IB_ATOMIC_HCA,
  115. IB_ATOMIC_GLOB
  116. };
  117. struct ib_device_attr {
  118. u64 fw_ver;
  119. __be64 sys_image_guid;
  120. u64 max_mr_size;
  121. u64 page_size_cap;
  122. u32 vendor_id;
  123. u32 vendor_part_id;
  124. u32 hw_ver;
  125. int max_qp;
  126. int max_qp_wr;
  127. int device_cap_flags;
  128. int max_sge;
  129. int max_sge_rd;
  130. int max_cq;
  131. int max_cqe;
  132. int max_mr;
  133. int max_pd;
  134. int max_qp_rd_atom;
  135. int max_ee_rd_atom;
  136. int max_res_rd_atom;
  137. int max_qp_init_rd_atom;
  138. int max_ee_init_rd_atom;
  139. enum ib_atomic_cap atomic_cap;
  140. enum ib_atomic_cap masked_atomic_cap;
  141. int max_ee;
  142. int max_rdd;
  143. int max_mw;
  144. int max_raw_ipv6_qp;
  145. int max_raw_ethy_qp;
  146. int max_mcast_grp;
  147. int max_mcast_qp_attach;
  148. int max_total_mcast_qp_attach;
  149. int max_ah;
  150. int max_fmr;
  151. int max_map_per_fmr;
  152. int max_srq;
  153. int max_srq_wr;
  154. int max_srq_sge;
  155. unsigned int max_fast_reg_page_list_len;
  156. u16 max_pkeys;
  157. u8 local_ca_ack_delay;
  158. };
  159. enum ib_mtu {
  160. IB_MTU_256 = 1,
  161. IB_MTU_512 = 2,
  162. IB_MTU_1024 = 3,
  163. IB_MTU_2048 = 4,
  164. IB_MTU_4096 = 5
  165. };
  166. static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
  167. {
  168. switch (mtu) {
  169. case IB_MTU_256: return 256;
  170. case IB_MTU_512: return 512;
  171. case IB_MTU_1024: return 1024;
  172. case IB_MTU_2048: return 2048;
  173. case IB_MTU_4096: return 4096;
  174. default: return -1;
  175. }
  176. }
  177. enum ib_port_state {
  178. IB_PORT_NOP = 0,
  179. IB_PORT_DOWN = 1,
  180. IB_PORT_INIT = 2,
  181. IB_PORT_ARMED = 3,
  182. IB_PORT_ACTIVE = 4,
  183. IB_PORT_ACTIVE_DEFER = 5
  184. };
  185. enum ib_port_cap_flags {
  186. IB_PORT_SM = 1 << 1,
  187. IB_PORT_NOTICE_SUP = 1 << 2,
  188. IB_PORT_TRAP_SUP = 1 << 3,
  189. IB_PORT_OPT_IPD_SUP = 1 << 4,
  190. IB_PORT_AUTO_MIGR_SUP = 1 << 5,
  191. IB_PORT_SL_MAP_SUP = 1 << 6,
  192. IB_PORT_MKEY_NVRAM = 1 << 7,
  193. IB_PORT_PKEY_NVRAM = 1 << 8,
  194. IB_PORT_LED_INFO_SUP = 1 << 9,
  195. IB_PORT_SM_DISABLED = 1 << 10,
  196. IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
  197. IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
  198. IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
  199. IB_PORT_CM_SUP = 1 << 16,
  200. IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
  201. IB_PORT_REINIT_SUP = 1 << 18,
  202. IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
  203. IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
  204. IB_PORT_DR_NOTICE_SUP = 1 << 21,
  205. IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
  206. IB_PORT_BOOT_MGMT_SUP = 1 << 23,
  207. IB_PORT_LINK_LATENCY_SUP = 1 << 24,
  208. IB_PORT_CLIENT_REG_SUP = 1 << 25
  209. };
  210. enum ib_port_width {
  211. IB_WIDTH_1X = 1,
  212. IB_WIDTH_4X = 2,
  213. IB_WIDTH_8X = 4,
  214. IB_WIDTH_12X = 8
  215. };
  216. static inline int ib_width_enum_to_int(enum ib_port_width width)
  217. {
  218. switch (width) {
  219. case IB_WIDTH_1X: return 1;
  220. case IB_WIDTH_4X: return 4;
  221. case IB_WIDTH_8X: return 8;
  222. case IB_WIDTH_12X: return 12;
  223. default: return -1;
  224. }
  225. }
  226. enum ib_port_speed {
  227. IB_SPEED_SDR = 1,
  228. IB_SPEED_DDR = 2,
  229. IB_SPEED_QDR = 4,
  230. IB_SPEED_FDR10 = 8,
  231. IB_SPEED_FDR = 16,
  232. IB_SPEED_EDR = 32
  233. };
  234. struct ib_protocol_stats {
  235. /* TBD... */
  236. };
  237. struct iw_protocol_stats {
  238. u64 ipInReceives;
  239. u64 ipInHdrErrors;
  240. u64 ipInTooBigErrors;
  241. u64 ipInNoRoutes;
  242. u64 ipInAddrErrors;
  243. u64 ipInUnknownProtos;
  244. u64 ipInTruncatedPkts;
  245. u64 ipInDiscards;
  246. u64 ipInDelivers;
  247. u64 ipOutForwDatagrams;
  248. u64 ipOutRequests;
  249. u64 ipOutDiscards;
  250. u64 ipOutNoRoutes;
  251. u64 ipReasmTimeout;
  252. u64 ipReasmReqds;
  253. u64 ipReasmOKs;
  254. u64 ipReasmFails;
  255. u64 ipFragOKs;
  256. u64 ipFragFails;
  257. u64 ipFragCreates;
  258. u64 ipInMcastPkts;
  259. u64 ipOutMcastPkts;
  260. u64 ipInBcastPkts;
  261. u64 ipOutBcastPkts;
  262. u64 tcpRtoAlgorithm;
  263. u64 tcpRtoMin;
  264. u64 tcpRtoMax;
  265. u64 tcpMaxConn;
  266. u64 tcpActiveOpens;
  267. u64 tcpPassiveOpens;
  268. u64 tcpAttemptFails;
  269. u64 tcpEstabResets;
  270. u64 tcpCurrEstab;
  271. u64 tcpInSegs;
  272. u64 tcpOutSegs;
  273. u64 tcpRetransSegs;
  274. u64 tcpInErrs;
  275. u64 tcpOutRsts;
  276. };
  277. union rdma_protocol_stats {
  278. struct ib_protocol_stats ib;
  279. struct iw_protocol_stats iw;
  280. };
  281. struct ib_port_attr {
  282. enum ib_port_state state;
  283. enum ib_mtu max_mtu;
  284. enum ib_mtu active_mtu;
  285. int gid_tbl_len;
  286. u32 port_cap_flags;
  287. u32 max_msg_sz;
  288. u32 bad_pkey_cntr;
  289. u32 qkey_viol_cntr;
  290. u16 pkey_tbl_len;
  291. u16 lid;
  292. u16 sm_lid;
  293. u8 lmc;
  294. u8 max_vl_num;
  295. u8 sm_sl;
  296. u8 subnet_timeout;
  297. u8 init_type_reply;
  298. u8 active_width;
  299. u8 active_speed;
  300. u8 phys_state;
  301. };
  302. enum ib_device_modify_flags {
  303. IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
  304. IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
  305. };
  306. struct ib_device_modify {
  307. u64 sys_image_guid;
  308. char node_desc[64];
  309. };
  310. enum ib_port_modify_flags {
  311. IB_PORT_SHUTDOWN = 1,
  312. IB_PORT_INIT_TYPE = (1<<2),
  313. IB_PORT_RESET_QKEY_CNTR = (1<<3)
  314. };
  315. struct ib_port_modify {
  316. u32 set_port_cap_mask;
  317. u32 clr_port_cap_mask;
  318. u8 init_type;
  319. };
  320. enum ib_event_type {
  321. IB_EVENT_CQ_ERR,
  322. IB_EVENT_QP_FATAL,
  323. IB_EVENT_QP_REQ_ERR,
  324. IB_EVENT_QP_ACCESS_ERR,
  325. IB_EVENT_COMM_EST,
  326. IB_EVENT_SQ_DRAINED,
  327. IB_EVENT_PATH_MIG,
  328. IB_EVENT_PATH_MIG_ERR,
  329. IB_EVENT_DEVICE_FATAL,
  330. IB_EVENT_PORT_ACTIVE,
  331. IB_EVENT_PORT_ERR,
  332. IB_EVENT_LID_CHANGE,
  333. IB_EVENT_PKEY_CHANGE,
  334. IB_EVENT_SM_CHANGE,
  335. IB_EVENT_SRQ_ERR,
  336. IB_EVENT_SRQ_LIMIT_REACHED,
  337. IB_EVENT_QP_LAST_WQE_REACHED,
  338. IB_EVENT_CLIENT_REREGISTER,
  339. IB_EVENT_GID_CHANGE,
  340. };
  341. struct ib_event {
  342. struct ib_device *device;
  343. union {
  344. struct ib_cq *cq;
  345. struct ib_qp *qp;
  346. struct ib_srq *srq;
  347. u8 port_num;
  348. } element;
  349. enum ib_event_type event;
  350. };
  351. struct ib_event_handler {
  352. struct ib_device *device;
  353. void (*handler)(struct ib_event_handler *, struct ib_event *);
  354. struct list_head list;
  355. };
  356. #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
  357. do { \
  358. (_ptr)->device = _device; \
  359. (_ptr)->handler = _handler; \
  360. INIT_LIST_HEAD(&(_ptr)->list); \
  361. } while (0)
  362. struct ib_global_route {
  363. union ib_gid dgid;
  364. u32 flow_label;
  365. u8 sgid_index;
  366. u8 hop_limit;
  367. u8 traffic_class;
  368. };
  369. struct ib_grh {
  370. __be32 version_tclass_flow;
  371. __be16 paylen;
  372. u8 next_hdr;
  373. u8 hop_limit;
  374. union ib_gid sgid;
  375. union ib_gid dgid;
  376. };
  377. enum {
  378. IB_MULTICAST_QPN = 0xffffff
  379. };
  380. #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
  381. enum ib_ah_flags {
  382. IB_AH_GRH = 1
  383. };
  384. enum ib_rate {
  385. IB_RATE_PORT_CURRENT = 0,
  386. IB_RATE_2_5_GBPS = 2,
  387. IB_RATE_5_GBPS = 5,
  388. IB_RATE_10_GBPS = 3,
  389. IB_RATE_20_GBPS = 6,
  390. IB_RATE_30_GBPS = 4,
  391. IB_RATE_40_GBPS = 7,
  392. IB_RATE_60_GBPS = 8,
  393. IB_RATE_80_GBPS = 9,
  394. IB_RATE_120_GBPS = 10,
  395. IB_RATE_14_GBPS = 11,
  396. IB_RATE_56_GBPS = 12,
  397. IB_RATE_112_GBPS = 13,
  398. IB_RATE_168_GBPS = 14,
  399. IB_RATE_25_GBPS = 15,
  400. IB_RATE_100_GBPS = 16,
  401. IB_RATE_200_GBPS = 17,
  402. IB_RATE_300_GBPS = 18
  403. };
  404. /**
  405. * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
  406. * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
  407. * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
  408. * @rate: rate to convert.
  409. */
  410. int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
  411. /**
  412. * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
  413. * For example, IB_RATE_2_5_GBPS will be converted to 2500.
  414. * @rate: rate to convert.
  415. */
  416. int ib_rate_to_mbps(enum ib_rate rate) __attribute_const__;
  417. /**
  418. * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
  419. * enum.
  420. * @mult: multiple to convert.
  421. */
  422. enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
  423. struct ib_ah_attr {
  424. struct ib_global_route grh;
  425. u16 dlid;
  426. u8 sl;
  427. u8 src_path_bits;
  428. u8 static_rate;
  429. u8 ah_flags;
  430. u8 port_num;
  431. };
  432. enum ib_wc_status {
  433. IB_WC_SUCCESS,
  434. IB_WC_LOC_LEN_ERR,
  435. IB_WC_LOC_QP_OP_ERR,
  436. IB_WC_LOC_EEC_OP_ERR,
  437. IB_WC_LOC_PROT_ERR,
  438. IB_WC_WR_FLUSH_ERR,
  439. IB_WC_MW_BIND_ERR,
  440. IB_WC_BAD_RESP_ERR,
  441. IB_WC_LOC_ACCESS_ERR,
  442. IB_WC_REM_INV_REQ_ERR,
  443. IB_WC_REM_ACCESS_ERR,
  444. IB_WC_REM_OP_ERR,
  445. IB_WC_RETRY_EXC_ERR,
  446. IB_WC_RNR_RETRY_EXC_ERR,
  447. IB_WC_LOC_RDD_VIOL_ERR,
  448. IB_WC_REM_INV_RD_REQ_ERR,
  449. IB_WC_REM_ABORT_ERR,
  450. IB_WC_INV_EECN_ERR,
  451. IB_WC_INV_EEC_STATE_ERR,
  452. IB_WC_FATAL_ERR,
  453. IB_WC_RESP_TIMEOUT_ERR,
  454. IB_WC_GENERAL_ERR
  455. };
  456. enum ib_wc_opcode {
  457. IB_WC_SEND,
  458. IB_WC_RDMA_WRITE,
  459. IB_WC_RDMA_READ,
  460. IB_WC_COMP_SWAP,
  461. IB_WC_FETCH_ADD,
  462. IB_WC_BIND_MW,
  463. IB_WC_LSO,
  464. IB_WC_LOCAL_INV,
  465. IB_WC_FAST_REG_MR,
  466. IB_WC_MASKED_COMP_SWAP,
  467. IB_WC_MASKED_FETCH_ADD,
  468. /*
  469. * Set value of IB_WC_RECV so consumers can test if a completion is a
  470. * receive by testing (opcode & IB_WC_RECV).
  471. */
  472. IB_WC_RECV = 1 << 7,
  473. IB_WC_RECV_RDMA_WITH_IMM
  474. };
  475. enum ib_wc_flags {
  476. IB_WC_GRH = 1,
  477. IB_WC_WITH_IMM = (1<<1),
  478. IB_WC_WITH_INVALIDATE = (1<<2),
  479. IB_WC_IP_CSUM_OK = (1<<3),
  480. };
  481. struct ib_wc {
  482. u64 wr_id;
  483. enum ib_wc_status status;
  484. enum ib_wc_opcode opcode;
  485. u32 vendor_err;
  486. u32 byte_len;
  487. struct ib_qp *qp;
  488. union {
  489. __be32 imm_data;
  490. u32 invalidate_rkey;
  491. } ex;
  492. u32 src_qp;
  493. int wc_flags;
  494. u16 pkey_index;
  495. u16 slid;
  496. u8 sl;
  497. u8 dlid_path_bits;
  498. u8 port_num; /* valid only for DR SMPs on switches */
  499. };
  500. enum ib_cq_notify_flags {
  501. IB_CQ_SOLICITED = 1 << 0,
  502. IB_CQ_NEXT_COMP = 1 << 1,
  503. IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
  504. IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
  505. };
  506. enum ib_srq_type {
  507. IB_SRQT_BASIC,
  508. IB_SRQT_XRC
  509. };
  510. enum ib_srq_attr_mask {
  511. IB_SRQ_MAX_WR = 1 << 0,
  512. IB_SRQ_LIMIT = 1 << 1,
  513. };
  514. struct ib_srq_attr {
  515. u32 max_wr;
  516. u32 max_sge;
  517. u32 srq_limit;
  518. };
  519. struct ib_srq_init_attr {
  520. void (*event_handler)(struct ib_event *, void *);
  521. void *srq_context;
  522. struct ib_srq_attr attr;
  523. enum ib_srq_type srq_type;
  524. union {
  525. struct {
  526. struct ib_xrcd *xrcd;
  527. struct ib_cq *cq;
  528. } xrc;
  529. } ext;
  530. };
  531. struct ib_qp_cap {
  532. u32 max_send_wr;
  533. u32 max_recv_wr;
  534. u32 max_send_sge;
  535. u32 max_recv_sge;
  536. u32 max_inline_data;
  537. };
  538. enum ib_sig_type {
  539. IB_SIGNAL_ALL_WR,
  540. IB_SIGNAL_REQ_WR
  541. };
  542. enum ib_qp_type {
  543. /*
  544. * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
  545. * here (and in that order) since the MAD layer uses them as
  546. * indices into a 2-entry table.
  547. */
  548. IB_QPT_SMI,
  549. IB_QPT_GSI,
  550. IB_QPT_RC,
  551. IB_QPT_UC,
  552. IB_QPT_UD,
  553. IB_QPT_RAW_IPV6,
  554. IB_QPT_RAW_ETHERTYPE,
  555. IB_QPT_RAW_PACKET = 8,
  556. IB_QPT_XRC_INI = 9,
  557. IB_QPT_XRC_TGT,
  558. IB_QPT_MAX,
  559. /* Reserve a range for qp types internal to the low level driver.
  560. * These qp types will not be visible at the IB core layer, so the
  561. * IB_QPT_MAX usages should not be affected in the core layer
  562. */
  563. IB_QPT_RESERVED1 = 0x1000,
  564. IB_QPT_RESERVED2,
  565. IB_QPT_RESERVED3,
  566. IB_QPT_RESERVED4,
  567. IB_QPT_RESERVED5,
  568. IB_QPT_RESERVED6,
  569. IB_QPT_RESERVED7,
  570. IB_QPT_RESERVED8,
  571. IB_QPT_RESERVED9,
  572. IB_QPT_RESERVED10,
  573. };
  574. enum ib_qp_create_flags {
  575. IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
  576. IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
  577. /* reserve bits 26-31 for low level drivers' internal use */
  578. IB_QP_CREATE_RESERVED_START = 1 << 26,
  579. IB_QP_CREATE_RESERVED_END = 1 << 31,
  580. };
  581. /*
  582. * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
  583. * callback to destroy the passed in QP.
  584. */
  585. struct ib_qp_init_attr {
  586. void (*event_handler)(struct ib_event *, void *);
  587. void *qp_context;
  588. struct ib_cq *send_cq;
  589. struct ib_cq *recv_cq;
  590. struct ib_srq *srq;
  591. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  592. struct ib_qp_cap cap;
  593. enum ib_sig_type sq_sig_type;
  594. enum ib_qp_type qp_type;
  595. enum ib_qp_create_flags create_flags;
  596. u8 port_num; /* special QP types only */
  597. };
  598. struct ib_qp_open_attr {
  599. void (*event_handler)(struct ib_event *, void *);
  600. void *qp_context;
  601. u32 qp_num;
  602. enum ib_qp_type qp_type;
  603. };
  604. enum ib_rnr_timeout {
  605. IB_RNR_TIMER_655_36 = 0,
  606. IB_RNR_TIMER_000_01 = 1,
  607. IB_RNR_TIMER_000_02 = 2,
  608. IB_RNR_TIMER_000_03 = 3,
  609. IB_RNR_TIMER_000_04 = 4,
  610. IB_RNR_TIMER_000_06 = 5,
  611. IB_RNR_TIMER_000_08 = 6,
  612. IB_RNR_TIMER_000_12 = 7,
  613. IB_RNR_TIMER_000_16 = 8,
  614. IB_RNR_TIMER_000_24 = 9,
  615. IB_RNR_TIMER_000_32 = 10,
  616. IB_RNR_TIMER_000_48 = 11,
  617. IB_RNR_TIMER_000_64 = 12,
  618. IB_RNR_TIMER_000_96 = 13,
  619. IB_RNR_TIMER_001_28 = 14,
  620. IB_RNR_TIMER_001_92 = 15,
  621. IB_RNR_TIMER_002_56 = 16,
  622. IB_RNR_TIMER_003_84 = 17,
  623. IB_RNR_TIMER_005_12 = 18,
  624. IB_RNR_TIMER_007_68 = 19,
  625. IB_RNR_TIMER_010_24 = 20,
  626. IB_RNR_TIMER_015_36 = 21,
  627. IB_RNR_TIMER_020_48 = 22,
  628. IB_RNR_TIMER_030_72 = 23,
  629. IB_RNR_TIMER_040_96 = 24,
  630. IB_RNR_TIMER_061_44 = 25,
  631. IB_RNR_TIMER_081_92 = 26,
  632. IB_RNR_TIMER_122_88 = 27,
  633. IB_RNR_TIMER_163_84 = 28,
  634. IB_RNR_TIMER_245_76 = 29,
  635. IB_RNR_TIMER_327_68 = 30,
  636. IB_RNR_TIMER_491_52 = 31
  637. };
  638. enum ib_qp_attr_mask {
  639. IB_QP_STATE = 1,
  640. IB_QP_CUR_STATE = (1<<1),
  641. IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
  642. IB_QP_ACCESS_FLAGS = (1<<3),
  643. IB_QP_PKEY_INDEX = (1<<4),
  644. IB_QP_PORT = (1<<5),
  645. IB_QP_QKEY = (1<<6),
  646. IB_QP_AV = (1<<7),
  647. IB_QP_PATH_MTU = (1<<8),
  648. IB_QP_TIMEOUT = (1<<9),
  649. IB_QP_RETRY_CNT = (1<<10),
  650. IB_QP_RNR_RETRY = (1<<11),
  651. IB_QP_RQ_PSN = (1<<12),
  652. IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
  653. IB_QP_ALT_PATH = (1<<14),
  654. IB_QP_MIN_RNR_TIMER = (1<<15),
  655. IB_QP_SQ_PSN = (1<<16),
  656. IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
  657. IB_QP_PATH_MIG_STATE = (1<<18),
  658. IB_QP_CAP = (1<<19),
  659. IB_QP_DEST_QPN = (1<<20)
  660. };
  661. enum ib_qp_state {
  662. IB_QPS_RESET,
  663. IB_QPS_INIT,
  664. IB_QPS_RTR,
  665. IB_QPS_RTS,
  666. IB_QPS_SQD,
  667. IB_QPS_SQE,
  668. IB_QPS_ERR
  669. };
  670. enum ib_mig_state {
  671. IB_MIG_MIGRATED,
  672. IB_MIG_REARM,
  673. IB_MIG_ARMED
  674. };
  675. enum ib_mw_type {
  676. IB_MW_TYPE_1 = 1,
  677. IB_MW_TYPE_2 = 2
  678. };
  679. struct ib_qp_attr {
  680. enum ib_qp_state qp_state;
  681. enum ib_qp_state cur_qp_state;
  682. enum ib_mtu path_mtu;
  683. enum ib_mig_state path_mig_state;
  684. u32 qkey;
  685. u32 rq_psn;
  686. u32 sq_psn;
  687. u32 dest_qp_num;
  688. int qp_access_flags;
  689. struct ib_qp_cap cap;
  690. struct ib_ah_attr ah_attr;
  691. struct ib_ah_attr alt_ah_attr;
  692. u16 pkey_index;
  693. u16 alt_pkey_index;
  694. u8 en_sqd_async_notify;
  695. u8 sq_draining;
  696. u8 max_rd_atomic;
  697. u8 max_dest_rd_atomic;
  698. u8 min_rnr_timer;
  699. u8 port_num;
  700. u8 timeout;
  701. u8 retry_cnt;
  702. u8 rnr_retry;
  703. u8 alt_port_num;
  704. u8 alt_timeout;
  705. };
  706. enum ib_wr_opcode {
  707. IB_WR_RDMA_WRITE,
  708. IB_WR_RDMA_WRITE_WITH_IMM,
  709. IB_WR_SEND,
  710. IB_WR_SEND_WITH_IMM,
  711. IB_WR_RDMA_READ,
  712. IB_WR_ATOMIC_CMP_AND_SWP,
  713. IB_WR_ATOMIC_FETCH_AND_ADD,
  714. IB_WR_LSO,
  715. IB_WR_SEND_WITH_INV,
  716. IB_WR_RDMA_READ_WITH_INV,
  717. IB_WR_LOCAL_INV,
  718. IB_WR_FAST_REG_MR,
  719. IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
  720. IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
  721. IB_WR_BIND_MW,
  722. /* reserve values for low level drivers' internal use.
  723. * These values will not be used at all in the ib core layer.
  724. */
  725. IB_WR_RESERVED1 = 0xf0,
  726. IB_WR_RESERVED2,
  727. IB_WR_RESERVED3,
  728. IB_WR_RESERVED4,
  729. IB_WR_RESERVED5,
  730. IB_WR_RESERVED6,
  731. IB_WR_RESERVED7,
  732. IB_WR_RESERVED8,
  733. IB_WR_RESERVED9,
  734. IB_WR_RESERVED10,
  735. };
  736. enum ib_send_flags {
  737. IB_SEND_FENCE = 1,
  738. IB_SEND_SIGNALED = (1<<1),
  739. IB_SEND_SOLICITED = (1<<2),
  740. IB_SEND_INLINE = (1<<3),
  741. IB_SEND_IP_CSUM = (1<<4),
  742. /* reserve bits 26-31 for low level drivers' internal use */
  743. IB_SEND_RESERVED_START = (1 << 26),
  744. IB_SEND_RESERVED_END = (1 << 31),
  745. };
  746. struct ib_sge {
  747. u64 addr;
  748. u32 length;
  749. u32 lkey;
  750. };
  751. struct ib_fast_reg_page_list {
  752. struct ib_device *device;
  753. u64 *page_list;
  754. unsigned int max_page_list_len;
  755. };
  756. /**
  757. * struct ib_mw_bind_info - Parameters for a memory window bind operation.
  758. * @mr: A memory region to bind the memory window to.
  759. * @addr: The address where the memory window should begin.
  760. * @length: The length of the memory window, in bytes.
  761. * @mw_access_flags: Access flags from enum ib_access_flags for the window.
  762. *
  763. * This struct contains the shared parameters for type 1 and type 2
  764. * memory window bind operations.
  765. */
  766. struct ib_mw_bind_info {
  767. struct ib_mr *mr;
  768. u64 addr;
  769. u64 length;
  770. int mw_access_flags;
  771. };
  772. struct ib_send_wr {
  773. struct ib_send_wr *next;
  774. u64 wr_id;
  775. struct ib_sge *sg_list;
  776. int num_sge;
  777. enum ib_wr_opcode opcode;
  778. int send_flags;
  779. union {
  780. __be32 imm_data;
  781. u32 invalidate_rkey;
  782. } ex;
  783. union {
  784. struct {
  785. u64 remote_addr;
  786. u32 rkey;
  787. } rdma;
  788. struct {
  789. u64 remote_addr;
  790. u64 compare_add;
  791. u64 swap;
  792. u64 compare_add_mask;
  793. u64 swap_mask;
  794. u32 rkey;
  795. } atomic;
  796. struct {
  797. struct ib_ah *ah;
  798. void *header;
  799. int hlen;
  800. int mss;
  801. u32 remote_qpn;
  802. u32 remote_qkey;
  803. u16 pkey_index; /* valid for GSI only */
  804. u8 port_num; /* valid for DR SMPs on switch only */
  805. } ud;
  806. struct {
  807. u64 iova_start;
  808. struct ib_fast_reg_page_list *page_list;
  809. unsigned int page_shift;
  810. unsigned int page_list_len;
  811. u32 length;
  812. int access_flags;
  813. u32 rkey;
  814. } fast_reg;
  815. struct {
  816. struct ib_mw *mw;
  817. /* The new rkey for the memory window. */
  818. u32 rkey;
  819. struct ib_mw_bind_info bind_info;
  820. } bind_mw;
  821. } wr;
  822. u32 xrc_remote_srq_num; /* XRC TGT QPs only */
  823. };
  824. struct ib_recv_wr {
  825. struct ib_recv_wr *next;
  826. u64 wr_id;
  827. struct ib_sge *sg_list;
  828. int num_sge;
  829. };
  830. enum ib_access_flags {
  831. IB_ACCESS_LOCAL_WRITE = 1,
  832. IB_ACCESS_REMOTE_WRITE = (1<<1),
  833. IB_ACCESS_REMOTE_READ = (1<<2),
  834. IB_ACCESS_REMOTE_ATOMIC = (1<<3),
  835. IB_ACCESS_MW_BIND = (1<<4),
  836. IB_ZERO_BASED = (1<<5)
  837. };
  838. struct ib_phys_buf {
  839. u64 addr;
  840. u64 size;
  841. };
  842. struct ib_mr_attr {
  843. struct ib_pd *pd;
  844. u64 device_virt_addr;
  845. u64 size;
  846. int mr_access_flags;
  847. u32 lkey;
  848. u32 rkey;
  849. };
  850. enum ib_mr_rereg_flags {
  851. IB_MR_REREG_TRANS = 1,
  852. IB_MR_REREG_PD = (1<<1),
  853. IB_MR_REREG_ACCESS = (1<<2)
  854. };
  855. /**
  856. * struct ib_mw_bind - Parameters for a type 1 memory window bind operation.
  857. * @wr_id: Work request id.
  858. * @send_flags: Flags from ib_send_flags enum.
  859. * @bind_info: More parameters of the bind operation.
  860. */
  861. struct ib_mw_bind {
  862. u64 wr_id;
  863. int send_flags;
  864. struct ib_mw_bind_info bind_info;
  865. };
  866. struct ib_fmr_attr {
  867. int max_pages;
  868. int max_maps;
  869. u8 page_shift;
  870. };
  871. struct ib_ucontext {
  872. struct ib_device *device;
  873. struct list_head pd_list;
  874. struct list_head mr_list;
  875. struct list_head mw_list;
  876. struct list_head cq_list;
  877. struct list_head qp_list;
  878. struct list_head srq_list;
  879. struct list_head ah_list;
  880. struct list_head xrcd_list;
  881. struct list_head rule_list;
  882. int closing;
  883. };
  884. struct ib_uobject {
  885. u64 user_handle; /* handle given to us by userspace */
  886. struct ib_ucontext *context; /* associated user context */
  887. void *object; /* containing object */
  888. struct list_head list; /* link to context's list */
  889. int id; /* index into kernel idr */
  890. struct kref ref;
  891. struct rw_semaphore mutex; /* protects .live */
  892. int live;
  893. };
  894. struct ib_udata {
  895. void __user *inbuf;
  896. void __user *outbuf;
  897. size_t inlen;
  898. size_t outlen;
  899. };
  900. struct ib_pd {
  901. struct ib_device *device;
  902. struct ib_uobject *uobject;
  903. atomic_t usecnt; /* count all resources */
  904. };
  905. struct ib_xrcd {
  906. struct ib_device *device;
  907. atomic_t usecnt; /* count all exposed resources */
  908. struct inode *inode;
  909. struct mutex tgt_qp_mutex;
  910. struct list_head tgt_qp_list;
  911. };
  912. struct ib_ah {
  913. struct ib_device *device;
  914. struct ib_pd *pd;
  915. struct ib_uobject *uobject;
  916. };
  917. typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
  918. struct ib_cq {
  919. struct ib_device *device;
  920. struct ib_uobject *uobject;
  921. ib_comp_handler comp_handler;
  922. void (*event_handler)(struct ib_event *, void *);
  923. void *cq_context;
  924. int cqe;
  925. atomic_t usecnt; /* count number of work queues */
  926. };
  927. struct ib_srq {
  928. struct ib_device *device;
  929. struct ib_pd *pd;
  930. struct ib_uobject *uobject;
  931. void (*event_handler)(struct ib_event *, void *);
  932. void *srq_context;
  933. enum ib_srq_type srq_type;
  934. atomic_t usecnt;
  935. union {
  936. struct {
  937. struct ib_xrcd *xrcd;
  938. struct ib_cq *cq;
  939. u32 srq_num;
  940. } xrc;
  941. } ext;
  942. };
  943. struct ib_qp {
  944. struct ib_device *device;
  945. struct ib_pd *pd;
  946. struct ib_cq *send_cq;
  947. struct ib_cq *recv_cq;
  948. struct ib_srq *srq;
  949. struct ib_xrcd *xrcd; /* XRC TGT QPs only */
  950. struct list_head xrcd_list;
  951. /* count times opened, mcast attaches, flow attaches */
  952. atomic_t usecnt;
  953. struct list_head open_list;
  954. struct ib_qp *real_qp;
  955. struct ib_uobject *uobject;
  956. void (*event_handler)(struct ib_event *, void *);
  957. void *qp_context;
  958. u32 qp_num;
  959. enum ib_qp_type qp_type;
  960. };
  961. struct ib_mr {
  962. struct ib_device *device;
  963. struct ib_pd *pd;
  964. struct ib_uobject *uobject;
  965. u32 lkey;
  966. u32 rkey;
  967. atomic_t usecnt; /* count number of MWs */
  968. };
  969. struct ib_mw {
  970. struct ib_device *device;
  971. struct ib_pd *pd;
  972. struct ib_uobject *uobject;
  973. u32 rkey;
  974. enum ib_mw_type type;
  975. };
  976. struct ib_fmr {
  977. struct ib_device *device;
  978. struct ib_pd *pd;
  979. struct list_head list;
  980. u32 lkey;
  981. u32 rkey;
  982. };
  983. /* Supported steering options */
  984. enum ib_flow_attr_type {
  985. /* steering according to rule specifications */
  986. IB_FLOW_ATTR_NORMAL = 0x0,
  987. /* default unicast and multicast rule -
  988. * receive all Eth traffic which isn't steered to any QP
  989. */
  990. IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
  991. /* default multicast rule -
  992. * receive all Eth multicast traffic which isn't steered to any QP
  993. */
  994. IB_FLOW_ATTR_MC_DEFAULT = 0x2,
  995. /* sniffer rule - receive all port traffic */
  996. IB_FLOW_ATTR_SNIFFER = 0x3
  997. };
  998. /* Supported steering header types */
  999. enum ib_flow_spec_type {
  1000. /* L2 headers*/
  1001. IB_FLOW_SPEC_ETH = 0x20,
  1002. /* L3 header*/
  1003. IB_FLOW_SPEC_IPV4 = 0x30,
  1004. /* L4 headers*/
  1005. IB_FLOW_SPEC_TCP = 0x40,
  1006. IB_FLOW_SPEC_UDP = 0x41
  1007. };
  1008. #define IB_FLOW_SPEC_SUPPORT_LAYERS 4
  1009. /* Flow steering rule priority is set according to it's domain.
  1010. * Lower domain value means higher priority.
  1011. */
  1012. enum ib_flow_domain {
  1013. IB_FLOW_DOMAIN_USER,
  1014. IB_FLOW_DOMAIN_ETHTOOL,
  1015. IB_FLOW_DOMAIN_RFS,
  1016. IB_FLOW_DOMAIN_NIC,
  1017. IB_FLOW_DOMAIN_NUM /* Must be last */
  1018. };
  1019. struct ib_flow_eth_filter {
  1020. u8 dst_mac[6];
  1021. u8 src_mac[6];
  1022. __be16 ether_type;
  1023. __be16 vlan_tag;
  1024. };
  1025. struct ib_flow_spec_eth {
  1026. enum ib_flow_spec_type type;
  1027. u16 size;
  1028. struct ib_flow_eth_filter val;
  1029. struct ib_flow_eth_filter mask;
  1030. };
  1031. struct ib_flow_ipv4_filter {
  1032. __be32 src_ip;
  1033. __be32 dst_ip;
  1034. };
  1035. struct ib_flow_spec_ipv4 {
  1036. enum ib_flow_spec_type type;
  1037. u16 size;
  1038. struct ib_flow_ipv4_filter val;
  1039. struct ib_flow_ipv4_filter mask;
  1040. };
  1041. struct ib_flow_tcp_udp_filter {
  1042. __be16 dst_port;
  1043. __be16 src_port;
  1044. };
  1045. struct ib_flow_spec_tcp_udp {
  1046. enum ib_flow_spec_type type;
  1047. u16 size;
  1048. struct ib_flow_tcp_udp_filter val;
  1049. struct ib_flow_tcp_udp_filter mask;
  1050. };
  1051. union ib_flow_spec {
  1052. struct {
  1053. enum ib_flow_spec_type type;
  1054. u16 size;
  1055. };
  1056. struct ib_flow_spec_eth eth;
  1057. struct ib_flow_spec_ipv4 ipv4;
  1058. struct ib_flow_spec_tcp_udp tcp_udp;
  1059. };
  1060. struct ib_flow_attr {
  1061. enum ib_flow_attr_type type;
  1062. u16 size;
  1063. u16 priority;
  1064. u32 flags;
  1065. u8 num_of_specs;
  1066. u8 port;
  1067. /* Following are the optional layers according to user request
  1068. * struct ib_flow_spec_xxx
  1069. * struct ib_flow_spec_yyy
  1070. */
  1071. };
  1072. struct ib_flow {
  1073. struct ib_qp *qp;
  1074. struct ib_uobject *uobject;
  1075. };
  1076. struct ib_mad;
  1077. struct ib_grh;
  1078. enum ib_process_mad_flags {
  1079. IB_MAD_IGNORE_MKEY = 1,
  1080. IB_MAD_IGNORE_BKEY = 2,
  1081. IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
  1082. };
  1083. enum ib_mad_result {
  1084. IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
  1085. IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
  1086. IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
  1087. IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
  1088. };
  1089. #define IB_DEVICE_NAME_MAX 64
  1090. struct ib_cache {
  1091. rwlock_t lock;
  1092. struct ib_event_handler event_handler;
  1093. struct ib_pkey_cache **pkey_cache;
  1094. struct ib_gid_cache **gid_cache;
  1095. u8 *lmc_cache;
  1096. };
  1097. struct ib_dma_mapping_ops {
  1098. int (*mapping_error)(struct ib_device *dev,
  1099. u64 dma_addr);
  1100. u64 (*map_single)(struct ib_device *dev,
  1101. void *ptr, size_t size,
  1102. enum dma_data_direction direction);
  1103. void (*unmap_single)(struct ib_device *dev,
  1104. u64 addr, size_t size,
  1105. enum dma_data_direction direction);
  1106. u64 (*map_page)(struct ib_device *dev,
  1107. struct page *page, unsigned long offset,
  1108. size_t size,
  1109. enum dma_data_direction direction);
  1110. void (*unmap_page)(struct ib_device *dev,
  1111. u64 addr, size_t size,
  1112. enum dma_data_direction direction);
  1113. int (*map_sg)(struct ib_device *dev,
  1114. struct scatterlist *sg, int nents,
  1115. enum dma_data_direction direction);
  1116. void (*unmap_sg)(struct ib_device *dev,
  1117. struct scatterlist *sg, int nents,
  1118. enum dma_data_direction direction);
  1119. u64 (*dma_address)(struct ib_device *dev,
  1120. struct scatterlist *sg);
  1121. unsigned int (*dma_len)(struct ib_device *dev,
  1122. struct scatterlist *sg);
  1123. void (*sync_single_for_cpu)(struct ib_device *dev,
  1124. u64 dma_handle,
  1125. size_t size,
  1126. enum dma_data_direction dir);
  1127. void (*sync_single_for_device)(struct ib_device *dev,
  1128. u64 dma_handle,
  1129. size_t size,
  1130. enum dma_data_direction dir);
  1131. void *(*alloc_coherent)(struct ib_device *dev,
  1132. size_t size,
  1133. u64 *dma_handle,
  1134. gfp_t flag);
  1135. void (*free_coherent)(struct ib_device *dev,
  1136. size_t size, void *cpu_addr,
  1137. u64 dma_handle);
  1138. };
  1139. struct iw_cm_verbs;
  1140. struct ib_device {
  1141. struct device *dma_device;
  1142. char name[IB_DEVICE_NAME_MAX];
  1143. struct list_head event_handler_list;
  1144. spinlock_t event_handler_lock;
  1145. spinlock_t client_data_lock;
  1146. struct list_head core_list;
  1147. struct list_head client_data_list;
  1148. struct ib_cache cache;
  1149. int *pkey_tbl_len;
  1150. int *gid_tbl_len;
  1151. int num_comp_vectors;
  1152. struct iw_cm_verbs *iwcm;
  1153. int (*get_protocol_stats)(struct ib_device *device,
  1154. union rdma_protocol_stats *stats);
  1155. int (*query_device)(struct ib_device *device,
  1156. struct ib_device_attr *device_attr);
  1157. int (*query_port)(struct ib_device *device,
  1158. u8 port_num,
  1159. struct ib_port_attr *port_attr);
  1160. enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
  1161. u8 port_num);
  1162. int (*query_gid)(struct ib_device *device,
  1163. u8 port_num, int index,
  1164. union ib_gid *gid);
  1165. int (*query_pkey)(struct ib_device *device,
  1166. u8 port_num, u16 index, u16 *pkey);
  1167. int (*modify_device)(struct ib_device *device,
  1168. int device_modify_mask,
  1169. struct ib_device_modify *device_modify);
  1170. int (*modify_port)(struct ib_device *device,
  1171. u8 port_num, int port_modify_mask,
  1172. struct ib_port_modify *port_modify);
  1173. struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
  1174. struct ib_udata *udata);
  1175. int (*dealloc_ucontext)(struct ib_ucontext *context);
  1176. int (*mmap)(struct ib_ucontext *context,
  1177. struct vm_area_struct *vma);
  1178. struct ib_pd * (*alloc_pd)(struct ib_device *device,
  1179. struct ib_ucontext *context,
  1180. struct ib_udata *udata);
  1181. int (*dealloc_pd)(struct ib_pd *pd);
  1182. struct ib_ah * (*create_ah)(struct ib_pd *pd,
  1183. struct ib_ah_attr *ah_attr);
  1184. int (*modify_ah)(struct ib_ah *ah,
  1185. struct ib_ah_attr *ah_attr);
  1186. int (*query_ah)(struct ib_ah *ah,
  1187. struct ib_ah_attr *ah_attr);
  1188. int (*destroy_ah)(struct ib_ah *ah);
  1189. struct ib_srq * (*create_srq)(struct ib_pd *pd,
  1190. struct ib_srq_init_attr *srq_init_attr,
  1191. struct ib_udata *udata);
  1192. int (*modify_srq)(struct ib_srq *srq,
  1193. struct ib_srq_attr *srq_attr,
  1194. enum ib_srq_attr_mask srq_attr_mask,
  1195. struct ib_udata *udata);
  1196. int (*query_srq)(struct ib_srq *srq,
  1197. struct ib_srq_attr *srq_attr);
  1198. int (*destroy_srq)(struct ib_srq *srq);
  1199. int (*post_srq_recv)(struct ib_srq *srq,
  1200. struct ib_recv_wr *recv_wr,
  1201. struct ib_recv_wr **bad_recv_wr);
  1202. struct ib_qp * (*create_qp)(struct ib_pd *pd,
  1203. struct ib_qp_init_attr *qp_init_attr,
  1204. struct ib_udata *udata);
  1205. int (*modify_qp)(struct ib_qp *qp,
  1206. struct ib_qp_attr *qp_attr,
  1207. int qp_attr_mask,
  1208. struct ib_udata *udata);
  1209. int (*query_qp)(struct ib_qp *qp,
  1210. struct ib_qp_attr *qp_attr,
  1211. int qp_attr_mask,
  1212. struct ib_qp_init_attr *qp_init_attr);
  1213. int (*destroy_qp)(struct ib_qp *qp);
  1214. int (*post_send)(struct ib_qp *qp,
  1215. struct ib_send_wr *send_wr,
  1216. struct ib_send_wr **bad_send_wr);
  1217. int (*post_recv)(struct ib_qp *qp,
  1218. struct ib_recv_wr *recv_wr,
  1219. struct ib_recv_wr **bad_recv_wr);
  1220. struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
  1221. int comp_vector,
  1222. struct ib_ucontext *context,
  1223. struct ib_udata *udata);
  1224. int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
  1225. u16 cq_period);
  1226. int (*destroy_cq)(struct ib_cq *cq);
  1227. int (*resize_cq)(struct ib_cq *cq, int cqe,
  1228. struct ib_udata *udata);
  1229. int (*poll_cq)(struct ib_cq *cq, int num_entries,
  1230. struct ib_wc *wc);
  1231. int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
  1232. int (*req_notify_cq)(struct ib_cq *cq,
  1233. enum ib_cq_notify_flags flags);
  1234. int (*req_ncomp_notif)(struct ib_cq *cq,
  1235. int wc_cnt);
  1236. struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
  1237. int mr_access_flags);
  1238. struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
  1239. struct ib_phys_buf *phys_buf_array,
  1240. int num_phys_buf,
  1241. int mr_access_flags,
  1242. u64 *iova_start);
  1243. struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
  1244. u64 start, u64 length,
  1245. u64 virt_addr,
  1246. int mr_access_flags,
  1247. struct ib_udata *udata);
  1248. int (*query_mr)(struct ib_mr *mr,
  1249. struct ib_mr_attr *mr_attr);
  1250. int (*dereg_mr)(struct ib_mr *mr);
  1251. struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
  1252. int max_page_list_len);
  1253. struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
  1254. int page_list_len);
  1255. void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
  1256. int (*rereg_phys_mr)(struct ib_mr *mr,
  1257. int mr_rereg_mask,
  1258. struct ib_pd *pd,
  1259. struct ib_phys_buf *phys_buf_array,
  1260. int num_phys_buf,
  1261. int mr_access_flags,
  1262. u64 *iova_start);
  1263. struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
  1264. enum ib_mw_type type);
  1265. int (*bind_mw)(struct ib_qp *qp,
  1266. struct ib_mw *mw,
  1267. struct ib_mw_bind *mw_bind);
  1268. int (*dealloc_mw)(struct ib_mw *mw);
  1269. struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
  1270. int mr_access_flags,
  1271. struct ib_fmr_attr *fmr_attr);
  1272. int (*map_phys_fmr)(struct ib_fmr *fmr,
  1273. u64 *page_list, int list_len,
  1274. u64 iova);
  1275. int (*unmap_fmr)(struct list_head *fmr_list);
  1276. int (*dealloc_fmr)(struct ib_fmr *fmr);
  1277. int (*attach_mcast)(struct ib_qp *qp,
  1278. union ib_gid *gid,
  1279. u16 lid);
  1280. int (*detach_mcast)(struct ib_qp *qp,
  1281. union ib_gid *gid,
  1282. u16 lid);
  1283. int (*process_mad)(struct ib_device *device,
  1284. int process_mad_flags,
  1285. u8 port_num,
  1286. struct ib_wc *in_wc,
  1287. struct ib_grh *in_grh,
  1288. struct ib_mad *in_mad,
  1289. struct ib_mad *out_mad);
  1290. struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
  1291. struct ib_ucontext *ucontext,
  1292. struct ib_udata *udata);
  1293. int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
  1294. struct ib_flow * (*create_flow)(struct ib_qp *qp,
  1295. struct ib_flow_attr
  1296. *flow_attr,
  1297. int domain);
  1298. int (*destroy_flow)(struct ib_flow *flow_id);
  1299. struct ib_dma_mapping_ops *dma_ops;
  1300. struct module *owner;
  1301. struct device dev;
  1302. struct kobject *ports_parent;
  1303. struct list_head port_list;
  1304. enum {
  1305. IB_DEV_UNINITIALIZED,
  1306. IB_DEV_REGISTERED,
  1307. IB_DEV_UNREGISTERED
  1308. } reg_state;
  1309. int uverbs_abi_ver;
  1310. u64 uverbs_cmd_mask;
  1311. char node_desc[64];
  1312. __be64 node_guid;
  1313. u32 local_dma_lkey;
  1314. u8 node_type;
  1315. u8 phys_port_cnt;
  1316. };
  1317. struct ib_client {
  1318. char *name;
  1319. void (*add) (struct ib_device *);
  1320. void (*remove)(struct ib_device *);
  1321. struct list_head list;
  1322. };
  1323. struct ib_device *ib_alloc_device(size_t size);
  1324. void ib_dealloc_device(struct ib_device *device);
  1325. int ib_register_device(struct ib_device *device,
  1326. int (*port_callback)(struct ib_device *,
  1327. u8, struct kobject *));
  1328. void ib_unregister_device(struct ib_device *device);
  1329. int ib_register_client (struct ib_client *client);
  1330. void ib_unregister_client(struct ib_client *client);
  1331. void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
  1332. void ib_set_client_data(struct ib_device *device, struct ib_client *client,
  1333. void *data);
  1334. static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
  1335. {
  1336. return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
  1337. }
  1338. static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
  1339. {
  1340. return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
  1341. }
  1342. /**
  1343. * ib_modify_qp_is_ok - Check that the supplied attribute mask
  1344. * contains all required attributes and no attributes not allowed for
  1345. * the given QP state transition.
  1346. * @cur_state: Current QP state
  1347. * @next_state: Next QP state
  1348. * @type: QP type
  1349. * @mask: Mask of supplied QP attributes
  1350. *
  1351. * This function is a helper function that a low-level driver's
  1352. * modify_qp method can use to validate the consumer's input. It
  1353. * checks that cur_state and next_state are valid QP states, that a
  1354. * transition from cur_state to next_state is allowed by the IB spec,
  1355. * and that the attribute mask supplied is allowed for the transition.
  1356. */
  1357. int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
  1358. enum ib_qp_type type, enum ib_qp_attr_mask mask);
  1359. int ib_register_event_handler (struct ib_event_handler *event_handler);
  1360. int ib_unregister_event_handler(struct ib_event_handler *event_handler);
  1361. void ib_dispatch_event(struct ib_event *event);
  1362. int ib_query_device(struct ib_device *device,
  1363. struct ib_device_attr *device_attr);
  1364. int ib_query_port(struct ib_device *device,
  1365. u8 port_num, struct ib_port_attr *port_attr);
  1366. enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
  1367. u8 port_num);
  1368. int ib_query_gid(struct ib_device *device,
  1369. u8 port_num, int index, union ib_gid *gid);
  1370. int ib_query_pkey(struct ib_device *device,
  1371. u8 port_num, u16 index, u16 *pkey);
  1372. int ib_modify_device(struct ib_device *device,
  1373. int device_modify_mask,
  1374. struct ib_device_modify *device_modify);
  1375. int ib_modify_port(struct ib_device *device,
  1376. u8 port_num, int port_modify_mask,
  1377. struct ib_port_modify *port_modify);
  1378. int ib_find_gid(struct ib_device *device, union ib_gid *gid,
  1379. u8 *port_num, u16 *index);
  1380. int ib_find_pkey(struct ib_device *device,
  1381. u8 port_num, u16 pkey, u16 *index);
  1382. /**
  1383. * ib_alloc_pd - Allocates an unused protection domain.
  1384. * @device: The device on which to allocate the protection domain.
  1385. *
  1386. * A protection domain object provides an association between QPs, shared
  1387. * receive queues, address handles, memory regions, and memory windows.
  1388. */
  1389. struct ib_pd *ib_alloc_pd(struct ib_device *device);
  1390. /**
  1391. * ib_dealloc_pd - Deallocates a protection domain.
  1392. * @pd: The protection domain to deallocate.
  1393. */
  1394. int ib_dealloc_pd(struct ib_pd *pd);
  1395. /**
  1396. * ib_create_ah - Creates an address handle for the given address vector.
  1397. * @pd: The protection domain associated with the address handle.
  1398. * @ah_attr: The attributes of the address vector.
  1399. *
  1400. * The address handle is used to reference a local or global destination
  1401. * in all UD QP post sends.
  1402. */
  1403. struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
  1404. /**
  1405. * ib_init_ah_from_wc - Initializes address handle attributes from a
  1406. * work completion.
  1407. * @device: Device on which the received message arrived.
  1408. * @port_num: Port on which the received message arrived.
  1409. * @wc: Work completion associated with the received message.
  1410. * @grh: References the received global route header. This parameter is
  1411. * ignored unless the work completion indicates that the GRH is valid.
  1412. * @ah_attr: Returned attributes that can be used when creating an address
  1413. * handle for replying to the message.
  1414. */
  1415. int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
  1416. struct ib_grh *grh, struct ib_ah_attr *ah_attr);
  1417. /**
  1418. * ib_create_ah_from_wc - Creates an address handle associated with the
  1419. * sender of the specified work completion.
  1420. * @pd: The protection domain associated with the address handle.
  1421. * @wc: Work completion information associated with a received message.
  1422. * @grh: References the received global route header. This parameter is
  1423. * ignored unless the work completion indicates that the GRH is valid.
  1424. * @port_num: The outbound port number to associate with the address.
  1425. *
  1426. * The address handle is used to reference a local or global destination
  1427. * in all UD QP post sends.
  1428. */
  1429. struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
  1430. struct ib_grh *grh, u8 port_num);
  1431. /**
  1432. * ib_modify_ah - Modifies the address vector associated with an address
  1433. * handle.
  1434. * @ah: The address handle to modify.
  1435. * @ah_attr: The new address vector attributes to associate with the
  1436. * address handle.
  1437. */
  1438. int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1439. /**
  1440. * ib_query_ah - Queries the address vector associated with an address
  1441. * handle.
  1442. * @ah: The address handle to query.
  1443. * @ah_attr: The address vector attributes associated with the address
  1444. * handle.
  1445. */
  1446. int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
  1447. /**
  1448. * ib_destroy_ah - Destroys an address handle.
  1449. * @ah: The address handle to destroy.
  1450. */
  1451. int ib_destroy_ah(struct ib_ah *ah);
  1452. /**
  1453. * ib_create_srq - Creates a SRQ associated with the specified protection
  1454. * domain.
  1455. * @pd: The protection domain associated with the SRQ.
  1456. * @srq_init_attr: A list of initial attributes required to create the
  1457. * SRQ. If SRQ creation succeeds, then the attributes are updated to
  1458. * the actual capabilities of the created SRQ.
  1459. *
  1460. * srq_attr->max_wr and srq_attr->max_sge are read the determine the
  1461. * requested size of the SRQ, and set to the actual values allocated
  1462. * on return. If ib_create_srq() succeeds, then max_wr and max_sge
  1463. * will always be at least as large as the requested values.
  1464. */
  1465. struct ib_srq *ib_create_srq(struct ib_pd *pd,
  1466. struct ib_srq_init_attr *srq_init_attr);
  1467. /**
  1468. * ib_modify_srq - Modifies the attributes for the specified SRQ.
  1469. * @srq: The SRQ to modify.
  1470. * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
  1471. * the current values of selected SRQ attributes are returned.
  1472. * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
  1473. * are being modified.
  1474. *
  1475. * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
  1476. * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
  1477. * the number of receives queued drops below the limit.
  1478. */
  1479. int ib_modify_srq(struct ib_srq *srq,
  1480. struct ib_srq_attr *srq_attr,
  1481. enum ib_srq_attr_mask srq_attr_mask);
  1482. /**
  1483. * ib_query_srq - Returns the attribute list and current values for the
  1484. * specified SRQ.
  1485. * @srq: The SRQ to query.
  1486. * @srq_attr: The attributes of the specified SRQ.
  1487. */
  1488. int ib_query_srq(struct ib_srq *srq,
  1489. struct ib_srq_attr *srq_attr);
  1490. /**
  1491. * ib_destroy_srq - Destroys the specified SRQ.
  1492. * @srq: The SRQ to destroy.
  1493. */
  1494. int ib_destroy_srq(struct ib_srq *srq);
  1495. /**
  1496. * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
  1497. * @srq: The SRQ to post the work request on.
  1498. * @recv_wr: A list of work requests to post on the receive queue.
  1499. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1500. * the work request that failed to be posted on the QP.
  1501. */
  1502. static inline int ib_post_srq_recv(struct ib_srq *srq,
  1503. struct ib_recv_wr *recv_wr,
  1504. struct ib_recv_wr **bad_recv_wr)
  1505. {
  1506. return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
  1507. }
  1508. /**
  1509. * ib_create_qp - Creates a QP associated with the specified protection
  1510. * domain.
  1511. * @pd: The protection domain associated with the QP.
  1512. * @qp_init_attr: A list of initial attributes required to create the
  1513. * QP. If QP creation succeeds, then the attributes are updated to
  1514. * the actual capabilities of the created QP.
  1515. */
  1516. struct ib_qp *ib_create_qp(struct ib_pd *pd,
  1517. struct ib_qp_init_attr *qp_init_attr);
  1518. /**
  1519. * ib_modify_qp - Modifies the attributes for the specified QP and then
  1520. * transitions the QP to the given state.
  1521. * @qp: The QP to modify.
  1522. * @qp_attr: On input, specifies the QP attributes to modify. On output,
  1523. * the current values of selected QP attributes are returned.
  1524. * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
  1525. * are being modified.
  1526. */
  1527. int ib_modify_qp(struct ib_qp *qp,
  1528. struct ib_qp_attr *qp_attr,
  1529. int qp_attr_mask);
  1530. /**
  1531. * ib_query_qp - Returns the attribute list and current values for the
  1532. * specified QP.
  1533. * @qp: The QP to query.
  1534. * @qp_attr: The attributes of the specified QP.
  1535. * @qp_attr_mask: A bit-mask used to select specific attributes to query.
  1536. * @qp_init_attr: Additional attributes of the selected QP.
  1537. *
  1538. * The qp_attr_mask may be used to limit the query to gathering only the
  1539. * selected attributes.
  1540. */
  1541. int ib_query_qp(struct ib_qp *qp,
  1542. struct ib_qp_attr *qp_attr,
  1543. int qp_attr_mask,
  1544. struct ib_qp_init_attr *qp_init_attr);
  1545. /**
  1546. * ib_destroy_qp - Destroys the specified QP.
  1547. * @qp: The QP to destroy.
  1548. */
  1549. int ib_destroy_qp(struct ib_qp *qp);
  1550. /**
  1551. * ib_open_qp - Obtain a reference to an existing sharable QP.
  1552. * @xrcd - XRC domain
  1553. * @qp_open_attr: Attributes identifying the QP to open.
  1554. *
  1555. * Returns a reference to a sharable QP.
  1556. */
  1557. struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
  1558. struct ib_qp_open_attr *qp_open_attr);
  1559. /**
  1560. * ib_close_qp - Release an external reference to a QP.
  1561. * @qp: The QP handle to release
  1562. *
  1563. * The opened QP handle is released by the caller. The underlying
  1564. * shared QP is not destroyed until all internal references are released.
  1565. */
  1566. int ib_close_qp(struct ib_qp *qp);
  1567. /**
  1568. * ib_post_send - Posts a list of work requests to the send queue of
  1569. * the specified QP.
  1570. * @qp: The QP to post the work request on.
  1571. * @send_wr: A list of work requests to post on the send queue.
  1572. * @bad_send_wr: On an immediate failure, this parameter will reference
  1573. * the work request that failed to be posted on the QP.
  1574. *
  1575. * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
  1576. * error is returned, the QP state shall not be affected,
  1577. * ib_post_send() will return an immediate error after queueing any
  1578. * earlier work requests in the list.
  1579. */
  1580. static inline int ib_post_send(struct ib_qp *qp,
  1581. struct ib_send_wr *send_wr,
  1582. struct ib_send_wr **bad_send_wr)
  1583. {
  1584. return qp->device->post_send(qp, send_wr, bad_send_wr);
  1585. }
  1586. /**
  1587. * ib_post_recv - Posts a list of work requests to the receive queue of
  1588. * the specified QP.
  1589. * @qp: The QP to post the work request on.
  1590. * @recv_wr: A list of work requests to post on the receive queue.
  1591. * @bad_recv_wr: On an immediate failure, this parameter will reference
  1592. * the work request that failed to be posted on the QP.
  1593. */
  1594. static inline int ib_post_recv(struct ib_qp *qp,
  1595. struct ib_recv_wr *recv_wr,
  1596. struct ib_recv_wr **bad_recv_wr)
  1597. {
  1598. return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
  1599. }
  1600. /**
  1601. * ib_create_cq - Creates a CQ on the specified device.
  1602. * @device: The device on which to create the CQ.
  1603. * @comp_handler: A user-specified callback that is invoked when a
  1604. * completion event occurs on the CQ.
  1605. * @event_handler: A user-specified callback that is invoked when an
  1606. * asynchronous event not associated with a completion occurs on the CQ.
  1607. * @cq_context: Context associated with the CQ returned to the user via
  1608. * the associated completion and event handlers.
  1609. * @cqe: The minimum size of the CQ.
  1610. * @comp_vector - Completion vector used to signal completion events.
  1611. * Must be >= 0 and < context->num_comp_vectors.
  1612. *
  1613. * Users can examine the cq structure to determine the actual CQ size.
  1614. */
  1615. struct ib_cq *ib_create_cq(struct ib_device *device,
  1616. ib_comp_handler comp_handler,
  1617. void (*event_handler)(struct ib_event *, void *),
  1618. void *cq_context, int cqe, int comp_vector);
  1619. /**
  1620. * ib_resize_cq - Modifies the capacity of the CQ.
  1621. * @cq: The CQ to resize.
  1622. * @cqe: The minimum size of the CQ.
  1623. *
  1624. * Users can examine the cq structure to determine the actual CQ size.
  1625. */
  1626. int ib_resize_cq(struct ib_cq *cq, int cqe);
  1627. /**
  1628. * ib_modify_cq - Modifies moderation params of the CQ
  1629. * @cq: The CQ to modify.
  1630. * @cq_count: number of CQEs that will trigger an event
  1631. * @cq_period: max period of time in usec before triggering an event
  1632. *
  1633. */
  1634. int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
  1635. /**
  1636. * ib_destroy_cq - Destroys the specified CQ.
  1637. * @cq: The CQ to destroy.
  1638. */
  1639. int ib_destroy_cq(struct ib_cq *cq);
  1640. /**
  1641. * ib_poll_cq - poll a CQ for completion(s)
  1642. * @cq:the CQ being polled
  1643. * @num_entries:maximum number of completions to return
  1644. * @wc:array of at least @num_entries &struct ib_wc where completions
  1645. * will be returned
  1646. *
  1647. * Poll a CQ for (possibly multiple) completions. If the return value
  1648. * is < 0, an error occurred. If the return value is >= 0, it is the
  1649. * number of completions returned. If the return value is
  1650. * non-negative and < num_entries, then the CQ was emptied.
  1651. */
  1652. static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
  1653. struct ib_wc *wc)
  1654. {
  1655. return cq->device->poll_cq(cq, num_entries, wc);
  1656. }
  1657. /**
  1658. * ib_peek_cq - Returns the number of unreaped completions currently
  1659. * on the specified CQ.
  1660. * @cq: The CQ to peek.
  1661. * @wc_cnt: A minimum number of unreaped completions to check for.
  1662. *
  1663. * If the number of unreaped completions is greater than or equal to wc_cnt,
  1664. * this function returns wc_cnt, otherwise, it returns the actual number of
  1665. * unreaped completions.
  1666. */
  1667. int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
  1668. /**
  1669. * ib_req_notify_cq - Request completion notification on a CQ.
  1670. * @cq: The CQ to generate an event for.
  1671. * @flags:
  1672. * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
  1673. * to request an event on the next solicited event or next work
  1674. * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
  1675. * may also be |ed in to request a hint about missed events, as
  1676. * described below.
  1677. *
  1678. * Return Value:
  1679. * < 0 means an error occurred while requesting notification
  1680. * == 0 means notification was requested successfully, and if
  1681. * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
  1682. * were missed and it is safe to wait for another event. In
  1683. * this case is it guaranteed that any work completions added
  1684. * to the CQ since the last CQ poll will trigger a completion
  1685. * notification event.
  1686. * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
  1687. * in. It means that the consumer must poll the CQ again to
  1688. * make sure it is empty to avoid missing an event because of a
  1689. * race between requesting notification and an entry being
  1690. * added to the CQ. This return value means it is possible
  1691. * (but not guaranteed) that a work completion has been added
  1692. * to the CQ since the last poll without triggering a
  1693. * completion notification event.
  1694. */
  1695. static inline int ib_req_notify_cq(struct ib_cq *cq,
  1696. enum ib_cq_notify_flags flags)
  1697. {
  1698. return cq->device->req_notify_cq(cq, flags);
  1699. }
  1700. /**
  1701. * ib_req_ncomp_notif - Request completion notification when there are
  1702. * at least the specified number of unreaped completions on the CQ.
  1703. * @cq: The CQ to generate an event for.
  1704. * @wc_cnt: The number of unreaped completions that should be on the
  1705. * CQ before an event is generated.
  1706. */
  1707. static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
  1708. {
  1709. return cq->device->req_ncomp_notif ?
  1710. cq->device->req_ncomp_notif(cq, wc_cnt) :
  1711. -ENOSYS;
  1712. }
  1713. /**
  1714. * ib_get_dma_mr - Returns a memory region for system memory that is
  1715. * usable for DMA.
  1716. * @pd: The protection domain associated with the memory region.
  1717. * @mr_access_flags: Specifies the memory access rights.
  1718. *
  1719. * Note that the ib_dma_*() functions defined below must be used
  1720. * to create/destroy addresses used with the Lkey or Rkey returned
  1721. * by ib_get_dma_mr().
  1722. */
  1723. struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
  1724. /**
  1725. * ib_dma_mapping_error - check a DMA addr for error
  1726. * @dev: The device for which the dma_addr was created
  1727. * @dma_addr: The DMA address to check
  1728. */
  1729. static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
  1730. {
  1731. if (dev->dma_ops)
  1732. return dev->dma_ops->mapping_error(dev, dma_addr);
  1733. return dma_mapping_error(dev->dma_device, dma_addr);
  1734. }
  1735. /**
  1736. * ib_dma_map_single - Map a kernel virtual address to DMA address
  1737. * @dev: The device for which the dma_addr is to be created
  1738. * @cpu_addr: The kernel virtual address
  1739. * @size: The size of the region in bytes
  1740. * @direction: The direction of the DMA
  1741. */
  1742. static inline u64 ib_dma_map_single(struct ib_device *dev,
  1743. void *cpu_addr, size_t size,
  1744. enum dma_data_direction direction)
  1745. {
  1746. if (dev->dma_ops)
  1747. return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
  1748. return dma_map_single(dev->dma_device, cpu_addr, size, direction);
  1749. }
  1750. /**
  1751. * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
  1752. * @dev: The device for which the DMA address was created
  1753. * @addr: The DMA address
  1754. * @size: The size of the region in bytes
  1755. * @direction: The direction of the DMA
  1756. */
  1757. static inline void ib_dma_unmap_single(struct ib_device *dev,
  1758. u64 addr, size_t size,
  1759. enum dma_data_direction direction)
  1760. {
  1761. if (dev->dma_ops)
  1762. dev->dma_ops->unmap_single(dev, addr, size, direction);
  1763. else
  1764. dma_unmap_single(dev->dma_device, addr, size, direction);
  1765. }
  1766. static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
  1767. void *cpu_addr, size_t size,
  1768. enum dma_data_direction direction,
  1769. struct dma_attrs *attrs)
  1770. {
  1771. return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
  1772. direction, attrs);
  1773. }
  1774. static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
  1775. u64 addr, size_t size,
  1776. enum dma_data_direction direction,
  1777. struct dma_attrs *attrs)
  1778. {
  1779. return dma_unmap_single_attrs(dev->dma_device, addr, size,
  1780. direction, attrs);
  1781. }
  1782. /**
  1783. * ib_dma_map_page - Map a physical page to DMA address
  1784. * @dev: The device for which the dma_addr is to be created
  1785. * @page: The page to be mapped
  1786. * @offset: The offset within the page
  1787. * @size: The size of the region in bytes
  1788. * @direction: The direction of the DMA
  1789. */
  1790. static inline u64 ib_dma_map_page(struct ib_device *dev,
  1791. struct page *page,
  1792. unsigned long offset,
  1793. size_t size,
  1794. enum dma_data_direction direction)
  1795. {
  1796. if (dev->dma_ops)
  1797. return dev->dma_ops->map_page(dev, page, offset, size, direction);
  1798. return dma_map_page(dev->dma_device, page, offset, size, direction);
  1799. }
  1800. /**
  1801. * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
  1802. * @dev: The device for which the DMA address was created
  1803. * @addr: The DMA address
  1804. * @size: The size of the region in bytes
  1805. * @direction: The direction of the DMA
  1806. */
  1807. static inline void ib_dma_unmap_page(struct ib_device *dev,
  1808. u64 addr, size_t size,
  1809. enum dma_data_direction direction)
  1810. {
  1811. if (dev->dma_ops)
  1812. dev->dma_ops->unmap_page(dev, addr, size, direction);
  1813. else
  1814. dma_unmap_page(dev->dma_device, addr, size, direction);
  1815. }
  1816. /**
  1817. * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
  1818. * @dev: The device for which the DMA addresses are to be created
  1819. * @sg: The array of scatter/gather entries
  1820. * @nents: The number of scatter/gather entries
  1821. * @direction: The direction of the DMA
  1822. */
  1823. static inline int ib_dma_map_sg(struct ib_device *dev,
  1824. struct scatterlist *sg, int nents,
  1825. enum dma_data_direction direction)
  1826. {
  1827. if (dev->dma_ops)
  1828. return dev->dma_ops->map_sg(dev, sg, nents, direction);
  1829. return dma_map_sg(dev->dma_device, sg, nents, direction);
  1830. }
  1831. /**
  1832. * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
  1833. * @dev: The device for which the DMA addresses were created
  1834. * @sg: The array of scatter/gather entries
  1835. * @nents: The number of scatter/gather entries
  1836. * @direction: The direction of the DMA
  1837. */
  1838. static inline void ib_dma_unmap_sg(struct ib_device *dev,
  1839. struct scatterlist *sg, int nents,
  1840. enum dma_data_direction direction)
  1841. {
  1842. if (dev->dma_ops)
  1843. dev->dma_ops->unmap_sg(dev, sg, nents, direction);
  1844. else
  1845. dma_unmap_sg(dev->dma_device, sg, nents, direction);
  1846. }
  1847. static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
  1848. struct scatterlist *sg, int nents,
  1849. enum dma_data_direction direction,
  1850. struct dma_attrs *attrs)
  1851. {
  1852. return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  1853. }
  1854. static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
  1855. struct scatterlist *sg, int nents,
  1856. enum dma_data_direction direction,
  1857. struct dma_attrs *attrs)
  1858. {
  1859. dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
  1860. }
  1861. /**
  1862. * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
  1863. * @dev: The device for which the DMA addresses were created
  1864. * @sg: The scatter/gather entry
  1865. */
  1866. static inline u64 ib_sg_dma_address(struct ib_device *dev,
  1867. struct scatterlist *sg)
  1868. {
  1869. if (dev->dma_ops)
  1870. return dev->dma_ops->dma_address(dev, sg);
  1871. return sg_dma_address(sg);
  1872. }
  1873. /**
  1874. * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
  1875. * @dev: The device for which the DMA addresses were created
  1876. * @sg: The scatter/gather entry
  1877. */
  1878. static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
  1879. struct scatterlist *sg)
  1880. {
  1881. if (dev->dma_ops)
  1882. return dev->dma_ops->dma_len(dev, sg);
  1883. return sg_dma_len(sg);
  1884. }
  1885. /**
  1886. * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
  1887. * @dev: The device for which the DMA address was created
  1888. * @addr: The DMA address
  1889. * @size: The size of the region in bytes
  1890. * @dir: The direction of the DMA
  1891. */
  1892. static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
  1893. u64 addr,
  1894. size_t size,
  1895. enum dma_data_direction dir)
  1896. {
  1897. if (dev->dma_ops)
  1898. dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
  1899. else
  1900. dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
  1901. }
  1902. /**
  1903. * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
  1904. * @dev: The device for which the DMA address was created
  1905. * @addr: The DMA address
  1906. * @size: The size of the region in bytes
  1907. * @dir: The direction of the DMA
  1908. */
  1909. static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
  1910. u64 addr,
  1911. size_t size,
  1912. enum dma_data_direction dir)
  1913. {
  1914. if (dev->dma_ops)
  1915. dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
  1916. else
  1917. dma_sync_single_for_device(dev->dma_device, addr, size, dir);
  1918. }
  1919. /**
  1920. * ib_dma_alloc_coherent - Allocate memory and map it for DMA
  1921. * @dev: The device for which the DMA address is requested
  1922. * @size: The size of the region to allocate in bytes
  1923. * @dma_handle: A pointer for returning the DMA address of the region
  1924. * @flag: memory allocator flags
  1925. */
  1926. static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
  1927. size_t size,
  1928. u64 *dma_handle,
  1929. gfp_t flag)
  1930. {
  1931. if (dev->dma_ops)
  1932. return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  1933. else {
  1934. dma_addr_t handle;
  1935. void *ret;
  1936. ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
  1937. *dma_handle = handle;
  1938. return ret;
  1939. }
  1940. }
  1941. /**
  1942. * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
  1943. * @dev: The device for which the DMA addresses were allocated
  1944. * @size: The size of the region
  1945. * @cpu_addr: the address returned by ib_dma_alloc_coherent()
  1946. * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
  1947. */
  1948. static inline void ib_dma_free_coherent(struct ib_device *dev,
  1949. size_t size, void *cpu_addr,
  1950. u64 dma_handle)
  1951. {
  1952. if (dev->dma_ops)
  1953. dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  1954. else
  1955. dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
  1956. }
  1957. /**
  1958. * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
  1959. * by an HCA.
  1960. * @pd: The protection domain associated assigned to the registered region.
  1961. * @phys_buf_array: Specifies a list of physical buffers to use in the
  1962. * memory region.
  1963. * @num_phys_buf: Specifies the size of the phys_buf_array.
  1964. * @mr_access_flags: Specifies the memory access rights.
  1965. * @iova_start: The offset of the region's starting I/O virtual address.
  1966. */
  1967. struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
  1968. struct ib_phys_buf *phys_buf_array,
  1969. int num_phys_buf,
  1970. int mr_access_flags,
  1971. u64 *iova_start);
  1972. /**
  1973. * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
  1974. * Conceptually, this call performs the functions deregister memory region
  1975. * followed by register physical memory region. Where possible,
  1976. * resources are reused instead of deallocated and reallocated.
  1977. * @mr: The memory region to modify.
  1978. * @mr_rereg_mask: A bit-mask used to indicate which of the following
  1979. * properties of the memory region are being modified.
  1980. * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
  1981. * the new protection domain to associated with the memory region,
  1982. * otherwise, this parameter is ignored.
  1983. * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1984. * field specifies a list of physical buffers to use in the new
  1985. * translation, otherwise, this parameter is ignored.
  1986. * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
  1987. * field specifies the size of the phys_buf_array, otherwise, this
  1988. * parameter is ignored.
  1989. * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
  1990. * field specifies the new memory access rights, otherwise, this
  1991. * parameter is ignored.
  1992. * @iova_start: The offset of the region's starting I/O virtual address.
  1993. */
  1994. int ib_rereg_phys_mr(struct ib_mr *mr,
  1995. int mr_rereg_mask,
  1996. struct ib_pd *pd,
  1997. struct ib_phys_buf *phys_buf_array,
  1998. int num_phys_buf,
  1999. int mr_access_flags,
  2000. u64 *iova_start);
  2001. /**
  2002. * ib_query_mr - Retrieves information about a specific memory region.
  2003. * @mr: The memory region to retrieve information about.
  2004. * @mr_attr: The attributes of the specified memory region.
  2005. */
  2006. int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
  2007. /**
  2008. * ib_dereg_mr - Deregisters a memory region and removes it from the
  2009. * HCA translation table.
  2010. * @mr: The memory region to deregister.
  2011. *
  2012. * This function can fail, if the memory region has memory windows bound to it.
  2013. */
  2014. int ib_dereg_mr(struct ib_mr *mr);
  2015. /**
  2016. * ib_alloc_fast_reg_mr - Allocates memory region usable with the
  2017. * IB_WR_FAST_REG_MR send work request.
  2018. * @pd: The protection domain associated with the region.
  2019. * @max_page_list_len: requested max physical buffer list length to be
  2020. * used with fast register work requests for this MR.
  2021. */
  2022. struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
  2023. /**
  2024. * ib_alloc_fast_reg_page_list - Allocates a page list array
  2025. * @device - ib device pointer.
  2026. * @page_list_len - size of the page list array to be allocated.
  2027. *
  2028. * This allocates and returns a struct ib_fast_reg_page_list * and a
  2029. * page_list array that is at least page_list_len in size. The actual
  2030. * size is returned in max_page_list_len. The caller is responsible
  2031. * for initializing the contents of the page_list array before posting
  2032. * a send work request with the IB_WC_FAST_REG_MR opcode.
  2033. *
  2034. * The page_list array entries must be translated using one of the
  2035. * ib_dma_*() functions just like the addresses passed to
  2036. * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
  2037. * ib_fast_reg_page_list must not be modified by the caller until the
  2038. * IB_WC_FAST_REG_MR work request completes.
  2039. */
  2040. struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
  2041. struct ib_device *device, int page_list_len);
  2042. /**
  2043. * ib_free_fast_reg_page_list - Deallocates a previously allocated
  2044. * page list array.
  2045. * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
  2046. */
  2047. void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
  2048. /**
  2049. * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
  2050. * R_Key and L_Key.
  2051. * @mr - struct ib_mr pointer to be updated.
  2052. * @newkey - new key to be used.
  2053. */
  2054. static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
  2055. {
  2056. mr->lkey = (mr->lkey & 0xffffff00) | newkey;
  2057. mr->rkey = (mr->rkey & 0xffffff00) | newkey;
  2058. }
  2059. /**
  2060. * ib_inc_rkey - increments the key portion of the given rkey. Can be used
  2061. * for calculating a new rkey for type 2 memory windows.
  2062. * @rkey - the rkey to increment.
  2063. */
  2064. static inline u32 ib_inc_rkey(u32 rkey)
  2065. {
  2066. const u32 mask = 0x000000ff;
  2067. return ((rkey + 1) & mask) | (rkey & ~mask);
  2068. }
  2069. /**
  2070. * ib_alloc_mw - Allocates a memory window.
  2071. * @pd: The protection domain associated with the memory window.
  2072. * @type: The type of the memory window (1 or 2).
  2073. */
  2074. struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
  2075. /**
  2076. * ib_bind_mw - Posts a work request to the send queue of the specified
  2077. * QP, which binds the memory window to the given address range and
  2078. * remote access attributes.
  2079. * @qp: QP to post the bind work request on.
  2080. * @mw: The memory window to bind.
  2081. * @mw_bind: Specifies information about the memory window, including
  2082. * its address range, remote access rights, and associated memory region.
  2083. *
  2084. * If there is no immediate error, the function will update the rkey member
  2085. * of the mw parameter to its new value. The bind operation can still fail
  2086. * asynchronously.
  2087. */
  2088. static inline int ib_bind_mw(struct ib_qp *qp,
  2089. struct ib_mw *mw,
  2090. struct ib_mw_bind *mw_bind)
  2091. {
  2092. /* XXX reference counting in corresponding MR? */
  2093. return mw->device->bind_mw ?
  2094. mw->device->bind_mw(qp, mw, mw_bind) :
  2095. -ENOSYS;
  2096. }
  2097. /**
  2098. * ib_dealloc_mw - Deallocates a memory window.
  2099. * @mw: The memory window to deallocate.
  2100. */
  2101. int ib_dealloc_mw(struct ib_mw *mw);
  2102. /**
  2103. * ib_alloc_fmr - Allocates a unmapped fast memory region.
  2104. * @pd: The protection domain associated with the unmapped region.
  2105. * @mr_access_flags: Specifies the memory access rights.
  2106. * @fmr_attr: Attributes of the unmapped region.
  2107. *
  2108. * A fast memory region must be mapped before it can be used as part of
  2109. * a work request.
  2110. */
  2111. struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
  2112. int mr_access_flags,
  2113. struct ib_fmr_attr *fmr_attr);
  2114. /**
  2115. * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
  2116. * @fmr: The fast memory region to associate with the pages.
  2117. * @page_list: An array of physical pages to map to the fast memory region.
  2118. * @list_len: The number of pages in page_list.
  2119. * @iova: The I/O virtual address to use with the mapped region.
  2120. */
  2121. static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
  2122. u64 *page_list, int list_len,
  2123. u64 iova)
  2124. {
  2125. return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
  2126. }
  2127. /**
  2128. * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
  2129. * @fmr_list: A linked list of fast memory regions to unmap.
  2130. */
  2131. int ib_unmap_fmr(struct list_head *fmr_list);
  2132. /**
  2133. * ib_dealloc_fmr - Deallocates a fast memory region.
  2134. * @fmr: The fast memory region to deallocate.
  2135. */
  2136. int ib_dealloc_fmr(struct ib_fmr *fmr);
  2137. /**
  2138. * ib_attach_mcast - Attaches the specified QP to a multicast group.
  2139. * @qp: QP to attach to the multicast group. The QP must be type
  2140. * IB_QPT_UD.
  2141. * @gid: Multicast group GID.
  2142. * @lid: Multicast group LID in host byte order.
  2143. *
  2144. * In order to send and receive multicast packets, subnet
  2145. * administration must have created the multicast group and configured
  2146. * the fabric appropriately. The port associated with the specified
  2147. * QP must also be a member of the multicast group.
  2148. */
  2149. int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2150. /**
  2151. * ib_detach_mcast - Detaches the specified QP from a multicast group.
  2152. * @qp: QP to detach from the multicast group.
  2153. * @gid: Multicast group GID.
  2154. * @lid: Multicast group LID in host byte order.
  2155. */
  2156. int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
  2157. /**
  2158. * ib_alloc_xrcd - Allocates an XRC domain.
  2159. * @device: The device on which to allocate the XRC domain.
  2160. */
  2161. struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
  2162. /**
  2163. * ib_dealloc_xrcd - Deallocates an XRC domain.
  2164. * @xrcd: The XRC domain to deallocate.
  2165. */
  2166. int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
  2167. struct ib_flow *ib_create_flow(struct ib_qp *qp,
  2168. struct ib_flow_attr *flow_attr, int domain);
  2169. int ib_destroy_flow(struct ib_flow *flow_id);
  2170. #endif /* IB_VERBS_H */