mthca_qp.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126
  1. /*
  2. * Copyright (c) 2004 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Cisco Systems. All rights reserved.
  4. * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  5. * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. *
  35. * $Id: mthca_qp.c 1355 2004-12-17 15:23:43Z roland $
  36. */
  37. #include <linux/init.h>
  38. #include <rdma/ib_verbs.h>
  39. #include <rdma/ib_cache.h>
  40. #include <rdma/ib_pack.h>
  41. #include "mthca_dev.h"
  42. #include "mthca_cmd.h"
  43. #include "mthca_memfree.h"
  44. #include "mthca_wqe.h"
  45. enum {
  46. MTHCA_MAX_DIRECT_QP_SIZE = 4 * PAGE_SIZE,
  47. MTHCA_ACK_REQ_FREQ = 10,
  48. MTHCA_FLIGHT_LIMIT = 9,
  49. MTHCA_UD_HEADER_SIZE = 72, /* largest UD header possible */
  50. MTHCA_INLINE_HEADER_SIZE = 4, /* data segment overhead for inline */
  51. MTHCA_INLINE_CHUNK_SIZE = 16 /* inline data segment chunk */
  52. };
  53. enum {
  54. MTHCA_QP_STATE_RST = 0,
  55. MTHCA_QP_STATE_INIT = 1,
  56. MTHCA_QP_STATE_RTR = 2,
  57. MTHCA_QP_STATE_RTS = 3,
  58. MTHCA_QP_STATE_SQE = 4,
  59. MTHCA_QP_STATE_SQD = 5,
  60. MTHCA_QP_STATE_ERR = 6,
  61. MTHCA_QP_STATE_DRAINING = 7
  62. };
  63. enum {
  64. MTHCA_QP_ST_RC = 0x0,
  65. MTHCA_QP_ST_UC = 0x1,
  66. MTHCA_QP_ST_RD = 0x2,
  67. MTHCA_QP_ST_UD = 0x3,
  68. MTHCA_QP_ST_MLX = 0x7
  69. };
  70. enum {
  71. MTHCA_QP_PM_MIGRATED = 0x3,
  72. MTHCA_QP_PM_ARMED = 0x0,
  73. MTHCA_QP_PM_REARM = 0x1
  74. };
  75. enum {
  76. /* qp_context flags */
  77. MTHCA_QP_BIT_DE = 1 << 8,
  78. /* params1 */
  79. MTHCA_QP_BIT_SRE = 1 << 15,
  80. MTHCA_QP_BIT_SWE = 1 << 14,
  81. MTHCA_QP_BIT_SAE = 1 << 13,
  82. MTHCA_QP_BIT_SIC = 1 << 4,
  83. MTHCA_QP_BIT_SSC = 1 << 3,
  84. /* params2 */
  85. MTHCA_QP_BIT_RRE = 1 << 15,
  86. MTHCA_QP_BIT_RWE = 1 << 14,
  87. MTHCA_QP_BIT_RAE = 1 << 13,
  88. MTHCA_QP_BIT_RIC = 1 << 4,
  89. MTHCA_QP_BIT_RSC = 1 << 3
  90. };
  91. struct mthca_qp_path {
  92. __be32 port_pkey;
  93. u8 rnr_retry;
  94. u8 g_mylmc;
  95. __be16 rlid;
  96. u8 ackto;
  97. u8 mgid_index;
  98. u8 static_rate;
  99. u8 hop_limit;
  100. __be32 sl_tclass_flowlabel;
  101. u8 rgid[16];
  102. } __attribute__((packed));
  103. struct mthca_qp_context {
  104. __be32 flags;
  105. __be32 tavor_sched_queue; /* Reserved on Arbel */
  106. u8 mtu_msgmax;
  107. u8 rq_size_stride; /* Reserved on Tavor */
  108. u8 sq_size_stride; /* Reserved on Tavor */
  109. u8 rlkey_arbel_sched_queue; /* Reserved on Tavor */
  110. __be32 usr_page;
  111. __be32 local_qpn;
  112. __be32 remote_qpn;
  113. u32 reserved1[2];
  114. struct mthca_qp_path pri_path;
  115. struct mthca_qp_path alt_path;
  116. __be32 rdd;
  117. __be32 pd;
  118. __be32 wqe_base;
  119. __be32 wqe_lkey;
  120. __be32 params1;
  121. __be32 reserved2;
  122. __be32 next_send_psn;
  123. __be32 cqn_snd;
  124. __be32 snd_wqe_base_l; /* Next send WQE on Tavor */
  125. __be32 snd_db_index; /* (debugging only entries) */
  126. __be32 last_acked_psn;
  127. __be32 ssn;
  128. __be32 params2;
  129. __be32 rnr_nextrecvpsn;
  130. __be32 ra_buff_indx;
  131. __be32 cqn_rcv;
  132. __be32 rcv_wqe_base_l; /* Next recv WQE on Tavor */
  133. __be32 rcv_db_index; /* (debugging only entries) */
  134. __be32 qkey;
  135. __be32 srqn;
  136. __be32 rmsn;
  137. __be16 rq_wqe_counter; /* reserved on Tavor */
  138. __be16 sq_wqe_counter; /* reserved on Tavor */
  139. u32 reserved3[18];
  140. } __attribute__((packed));
  141. struct mthca_qp_param {
  142. __be32 opt_param_mask;
  143. u32 reserved1;
  144. struct mthca_qp_context context;
  145. u32 reserved2[62];
  146. } __attribute__((packed));
  147. enum {
  148. MTHCA_QP_OPTPAR_ALT_ADDR_PATH = 1 << 0,
  149. MTHCA_QP_OPTPAR_RRE = 1 << 1,
  150. MTHCA_QP_OPTPAR_RAE = 1 << 2,
  151. MTHCA_QP_OPTPAR_RWE = 1 << 3,
  152. MTHCA_QP_OPTPAR_PKEY_INDEX = 1 << 4,
  153. MTHCA_QP_OPTPAR_Q_KEY = 1 << 5,
  154. MTHCA_QP_OPTPAR_RNR_TIMEOUT = 1 << 6,
  155. MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH = 1 << 7,
  156. MTHCA_QP_OPTPAR_SRA_MAX = 1 << 8,
  157. MTHCA_QP_OPTPAR_RRA_MAX = 1 << 9,
  158. MTHCA_QP_OPTPAR_PM_STATE = 1 << 10,
  159. MTHCA_QP_OPTPAR_PORT_NUM = 1 << 11,
  160. MTHCA_QP_OPTPAR_RETRY_COUNT = 1 << 12,
  161. MTHCA_QP_OPTPAR_ALT_RNR_RETRY = 1 << 13,
  162. MTHCA_QP_OPTPAR_ACK_TIMEOUT = 1 << 14,
  163. MTHCA_QP_OPTPAR_RNR_RETRY = 1 << 15,
  164. MTHCA_QP_OPTPAR_SCHED_QUEUE = 1 << 16
  165. };
  166. static const u8 mthca_opcode[] = {
  167. [IB_WR_SEND] = MTHCA_OPCODE_SEND,
  168. [IB_WR_SEND_WITH_IMM] = MTHCA_OPCODE_SEND_IMM,
  169. [IB_WR_RDMA_WRITE] = MTHCA_OPCODE_RDMA_WRITE,
  170. [IB_WR_RDMA_WRITE_WITH_IMM] = MTHCA_OPCODE_RDMA_WRITE_IMM,
  171. [IB_WR_RDMA_READ] = MTHCA_OPCODE_RDMA_READ,
  172. [IB_WR_ATOMIC_CMP_AND_SWP] = MTHCA_OPCODE_ATOMIC_CS,
  173. [IB_WR_ATOMIC_FETCH_AND_ADD] = MTHCA_OPCODE_ATOMIC_FA,
  174. };
  175. static int is_sqp(struct mthca_dev *dev, struct mthca_qp *qp)
  176. {
  177. return qp->qpn >= dev->qp_table.sqp_start &&
  178. qp->qpn <= dev->qp_table.sqp_start + 3;
  179. }
  180. static int is_qp0(struct mthca_dev *dev, struct mthca_qp *qp)
  181. {
  182. return qp->qpn >= dev->qp_table.sqp_start &&
  183. qp->qpn <= dev->qp_table.sqp_start + 1;
  184. }
  185. static void *get_recv_wqe(struct mthca_qp *qp, int n)
  186. {
  187. if (qp->is_direct)
  188. return qp->queue.direct.buf + (n << qp->rq.wqe_shift);
  189. else
  190. return qp->queue.page_list[(n << qp->rq.wqe_shift) >> PAGE_SHIFT].buf +
  191. ((n << qp->rq.wqe_shift) & (PAGE_SIZE - 1));
  192. }
  193. static void *get_send_wqe(struct mthca_qp *qp, int n)
  194. {
  195. if (qp->is_direct)
  196. return qp->queue.direct.buf + qp->send_wqe_offset +
  197. (n << qp->sq.wqe_shift);
  198. else
  199. return qp->queue.page_list[(qp->send_wqe_offset +
  200. (n << qp->sq.wqe_shift)) >>
  201. PAGE_SHIFT].buf +
  202. ((qp->send_wqe_offset + (n << qp->sq.wqe_shift)) &
  203. (PAGE_SIZE - 1));
  204. }
  205. static void mthca_wq_init(struct mthca_wq *wq)
  206. {
  207. spin_lock_init(&wq->lock);
  208. wq->next_ind = 0;
  209. wq->last_comp = wq->max - 1;
  210. wq->head = 0;
  211. wq->tail = 0;
  212. }
  213. void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
  214. enum ib_event_type event_type)
  215. {
  216. struct mthca_qp *qp;
  217. struct ib_event event;
  218. spin_lock(&dev->qp_table.lock);
  219. qp = mthca_array_get(&dev->qp_table.qp, qpn & (dev->limits.num_qps - 1));
  220. if (qp)
  221. atomic_inc(&qp->refcount);
  222. spin_unlock(&dev->qp_table.lock);
  223. if (!qp) {
  224. mthca_warn(dev, "Async event for bogus QP %08x\n", qpn);
  225. return;
  226. }
  227. event.device = &dev->ib_dev;
  228. event.event = event_type;
  229. event.element.qp = &qp->ibqp;
  230. if (qp->ibqp.event_handler)
  231. qp->ibqp.event_handler(&event, qp->ibqp.qp_context);
  232. if (atomic_dec_and_test(&qp->refcount))
  233. wake_up(&qp->wait);
  234. }
  235. static int to_mthca_state(enum ib_qp_state ib_state)
  236. {
  237. switch (ib_state) {
  238. case IB_QPS_RESET: return MTHCA_QP_STATE_RST;
  239. case IB_QPS_INIT: return MTHCA_QP_STATE_INIT;
  240. case IB_QPS_RTR: return MTHCA_QP_STATE_RTR;
  241. case IB_QPS_RTS: return MTHCA_QP_STATE_RTS;
  242. case IB_QPS_SQD: return MTHCA_QP_STATE_SQD;
  243. case IB_QPS_SQE: return MTHCA_QP_STATE_SQE;
  244. case IB_QPS_ERR: return MTHCA_QP_STATE_ERR;
  245. default: return -1;
  246. }
  247. }
  248. enum { RC, UC, UD, RD, RDEE, MLX, NUM_TRANS };
  249. static int to_mthca_st(int transport)
  250. {
  251. switch (transport) {
  252. case RC: return MTHCA_QP_ST_RC;
  253. case UC: return MTHCA_QP_ST_UC;
  254. case UD: return MTHCA_QP_ST_UD;
  255. case RD: return MTHCA_QP_ST_RD;
  256. case MLX: return MTHCA_QP_ST_MLX;
  257. default: return -1;
  258. }
  259. }
  260. static const struct {
  261. int trans;
  262. u32 req_param[NUM_TRANS];
  263. u32 opt_param[NUM_TRANS];
  264. } state_table[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
  265. [IB_QPS_RESET] = {
  266. [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
  267. [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
  268. [IB_QPS_INIT] = {
  269. .trans = MTHCA_TRANS_RST2INIT,
  270. .req_param = {
  271. [UD] = (IB_QP_PKEY_INDEX |
  272. IB_QP_PORT |
  273. IB_QP_QKEY),
  274. [UC] = (IB_QP_PKEY_INDEX |
  275. IB_QP_PORT |
  276. IB_QP_ACCESS_FLAGS),
  277. [RC] = (IB_QP_PKEY_INDEX |
  278. IB_QP_PORT |
  279. IB_QP_ACCESS_FLAGS),
  280. [MLX] = (IB_QP_PKEY_INDEX |
  281. IB_QP_QKEY),
  282. },
  283. /* bug-for-bug compatibility with VAPI: */
  284. .opt_param = {
  285. [MLX] = IB_QP_PORT
  286. }
  287. },
  288. },
  289. [IB_QPS_INIT] = {
  290. [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
  291. [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
  292. [IB_QPS_INIT] = {
  293. .trans = MTHCA_TRANS_INIT2INIT,
  294. .opt_param = {
  295. [UD] = (IB_QP_PKEY_INDEX |
  296. IB_QP_PORT |
  297. IB_QP_QKEY),
  298. [UC] = (IB_QP_PKEY_INDEX |
  299. IB_QP_PORT |
  300. IB_QP_ACCESS_FLAGS),
  301. [RC] = (IB_QP_PKEY_INDEX |
  302. IB_QP_PORT |
  303. IB_QP_ACCESS_FLAGS),
  304. [MLX] = (IB_QP_PKEY_INDEX |
  305. IB_QP_QKEY),
  306. }
  307. },
  308. [IB_QPS_RTR] = {
  309. .trans = MTHCA_TRANS_INIT2RTR,
  310. .req_param = {
  311. [UC] = (IB_QP_AV |
  312. IB_QP_PATH_MTU |
  313. IB_QP_DEST_QPN |
  314. IB_QP_RQ_PSN),
  315. [RC] = (IB_QP_AV |
  316. IB_QP_PATH_MTU |
  317. IB_QP_DEST_QPN |
  318. IB_QP_RQ_PSN |
  319. IB_QP_MAX_DEST_RD_ATOMIC |
  320. IB_QP_MIN_RNR_TIMER),
  321. },
  322. .opt_param = {
  323. [UD] = (IB_QP_PKEY_INDEX |
  324. IB_QP_QKEY),
  325. [UC] = (IB_QP_ALT_PATH |
  326. IB_QP_ACCESS_FLAGS |
  327. IB_QP_PKEY_INDEX),
  328. [RC] = (IB_QP_ALT_PATH |
  329. IB_QP_ACCESS_FLAGS |
  330. IB_QP_PKEY_INDEX),
  331. [MLX] = (IB_QP_PKEY_INDEX |
  332. IB_QP_QKEY),
  333. }
  334. }
  335. },
  336. [IB_QPS_RTR] = {
  337. [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
  338. [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
  339. [IB_QPS_RTS] = {
  340. .trans = MTHCA_TRANS_RTR2RTS,
  341. .req_param = {
  342. [UD] = IB_QP_SQ_PSN,
  343. [UC] = IB_QP_SQ_PSN,
  344. [RC] = (IB_QP_TIMEOUT |
  345. IB_QP_RETRY_CNT |
  346. IB_QP_RNR_RETRY |
  347. IB_QP_SQ_PSN |
  348. IB_QP_MAX_QP_RD_ATOMIC),
  349. [MLX] = IB_QP_SQ_PSN,
  350. },
  351. .opt_param = {
  352. [UD] = (IB_QP_CUR_STATE |
  353. IB_QP_QKEY),
  354. [UC] = (IB_QP_CUR_STATE |
  355. IB_QP_ALT_PATH |
  356. IB_QP_ACCESS_FLAGS |
  357. IB_QP_PKEY_INDEX |
  358. IB_QP_PATH_MIG_STATE),
  359. [RC] = (IB_QP_CUR_STATE |
  360. IB_QP_ALT_PATH |
  361. IB_QP_ACCESS_FLAGS |
  362. IB_QP_PKEY_INDEX |
  363. IB_QP_MIN_RNR_TIMER |
  364. IB_QP_PATH_MIG_STATE),
  365. [MLX] = (IB_QP_CUR_STATE |
  366. IB_QP_QKEY),
  367. }
  368. }
  369. },
  370. [IB_QPS_RTS] = {
  371. [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
  372. [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
  373. [IB_QPS_RTS] = {
  374. .trans = MTHCA_TRANS_RTS2RTS,
  375. .opt_param = {
  376. [UD] = (IB_QP_CUR_STATE |
  377. IB_QP_QKEY),
  378. [UC] = (IB_QP_ACCESS_FLAGS |
  379. IB_QP_ALT_PATH |
  380. IB_QP_PATH_MIG_STATE),
  381. [RC] = (IB_QP_ACCESS_FLAGS |
  382. IB_QP_ALT_PATH |
  383. IB_QP_PATH_MIG_STATE |
  384. IB_QP_MIN_RNR_TIMER),
  385. [MLX] = (IB_QP_CUR_STATE |
  386. IB_QP_QKEY),
  387. }
  388. },
  389. [IB_QPS_SQD] = {
  390. .trans = MTHCA_TRANS_RTS2SQD,
  391. },
  392. },
  393. [IB_QPS_SQD] = {
  394. [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
  395. [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
  396. [IB_QPS_RTS] = {
  397. .trans = MTHCA_TRANS_SQD2RTS,
  398. .opt_param = {
  399. [UD] = (IB_QP_CUR_STATE |
  400. IB_QP_QKEY),
  401. [UC] = (IB_QP_CUR_STATE |
  402. IB_QP_ALT_PATH |
  403. IB_QP_ACCESS_FLAGS |
  404. IB_QP_PATH_MIG_STATE),
  405. [RC] = (IB_QP_CUR_STATE |
  406. IB_QP_ALT_PATH |
  407. IB_QP_ACCESS_FLAGS |
  408. IB_QP_MIN_RNR_TIMER |
  409. IB_QP_PATH_MIG_STATE),
  410. [MLX] = (IB_QP_CUR_STATE |
  411. IB_QP_QKEY),
  412. }
  413. },
  414. [IB_QPS_SQD] = {
  415. .trans = MTHCA_TRANS_SQD2SQD,
  416. .opt_param = {
  417. [UD] = (IB_QP_PKEY_INDEX |
  418. IB_QP_QKEY),
  419. [UC] = (IB_QP_AV |
  420. IB_QP_CUR_STATE |
  421. IB_QP_ALT_PATH |
  422. IB_QP_ACCESS_FLAGS |
  423. IB_QP_PKEY_INDEX |
  424. IB_QP_PATH_MIG_STATE),
  425. [RC] = (IB_QP_AV |
  426. IB_QP_TIMEOUT |
  427. IB_QP_RETRY_CNT |
  428. IB_QP_RNR_RETRY |
  429. IB_QP_MAX_QP_RD_ATOMIC |
  430. IB_QP_MAX_DEST_RD_ATOMIC |
  431. IB_QP_CUR_STATE |
  432. IB_QP_ALT_PATH |
  433. IB_QP_ACCESS_FLAGS |
  434. IB_QP_PKEY_INDEX |
  435. IB_QP_MIN_RNR_TIMER |
  436. IB_QP_PATH_MIG_STATE),
  437. [MLX] = (IB_QP_PKEY_INDEX |
  438. IB_QP_QKEY),
  439. }
  440. }
  441. },
  442. [IB_QPS_SQE] = {
  443. [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
  444. [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR },
  445. [IB_QPS_RTS] = {
  446. .trans = MTHCA_TRANS_SQERR2RTS,
  447. .opt_param = {
  448. [UD] = (IB_QP_CUR_STATE |
  449. IB_QP_QKEY),
  450. [UC] = IB_QP_CUR_STATE,
  451. [RC] = (IB_QP_CUR_STATE |
  452. IB_QP_MIN_RNR_TIMER),
  453. [MLX] = (IB_QP_CUR_STATE |
  454. IB_QP_QKEY),
  455. }
  456. }
  457. },
  458. [IB_QPS_ERR] = {
  459. [IB_QPS_RESET] = { .trans = MTHCA_TRANS_ANY2RST },
  460. [IB_QPS_ERR] = { .trans = MTHCA_TRANS_ANY2ERR }
  461. }
  462. };
  463. static void store_attrs(struct mthca_sqp *sqp, struct ib_qp_attr *attr,
  464. int attr_mask)
  465. {
  466. if (attr_mask & IB_QP_PKEY_INDEX)
  467. sqp->pkey_index = attr->pkey_index;
  468. if (attr_mask & IB_QP_QKEY)
  469. sqp->qkey = attr->qkey;
  470. if (attr_mask & IB_QP_SQ_PSN)
  471. sqp->send_psn = attr->sq_psn;
  472. }
  473. static void init_port(struct mthca_dev *dev, int port)
  474. {
  475. int err;
  476. u8 status;
  477. struct mthca_init_ib_param param;
  478. memset(&param, 0, sizeof param);
  479. param.port_width = dev->limits.port_width_cap;
  480. param.vl_cap = dev->limits.vl_cap;
  481. param.mtu_cap = dev->limits.mtu_cap;
  482. param.gid_cap = dev->limits.gid_table_len;
  483. param.pkey_cap = dev->limits.pkey_table_len;
  484. err = mthca_INIT_IB(dev, &param, port, &status);
  485. if (err)
  486. mthca_warn(dev, "INIT_IB failed, return code %d.\n", err);
  487. if (status)
  488. mthca_warn(dev, "INIT_IB returned status %02x.\n", status);
  489. }
  490. int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
  491. {
  492. struct mthca_dev *dev = to_mdev(ibqp->device);
  493. struct mthca_qp *qp = to_mqp(ibqp);
  494. enum ib_qp_state cur_state, new_state;
  495. struct mthca_mailbox *mailbox;
  496. struct mthca_qp_param *qp_param;
  497. struct mthca_qp_context *qp_context;
  498. u32 req_param, opt_param;
  499. u8 status;
  500. int err;
  501. if (attr_mask & IB_QP_CUR_STATE) {
  502. if (attr->cur_qp_state != IB_QPS_RTR &&
  503. attr->cur_qp_state != IB_QPS_RTS &&
  504. attr->cur_qp_state != IB_QPS_SQD &&
  505. attr->cur_qp_state != IB_QPS_SQE)
  506. return -EINVAL;
  507. else
  508. cur_state = attr->cur_qp_state;
  509. } else {
  510. spin_lock_irq(&qp->sq.lock);
  511. spin_lock(&qp->rq.lock);
  512. cur_state = qp->state;
  513. spin_unlock(&qp->rq.lock);
  514. spin_unlock_irq(&qp->sq.lock);
  515. }
  516. if (attr_mask & IB_QP_STATE) {
  517. if (attr->qp_state < 0 || attr->qp_state > IB_QPS_ERR)
  518. return -EINVAL;
  519. new_state = attr->qp_state;
  520. } else
  521. new_state = cur_state;
  522. if (state_table[cur_state][new_state].trans == MTHCA_TRANS_INVALID) {
  523. mthca_dbg(dev, "Illegal QP transition "
  524. "%d->%d\n", cur_state, new_state);
  525. return -EINVAL;
  526. }
  527. req_param = state_table[cur_state][new_state].req_param[qp->transport];
  528. opt_param = state_table[cur_state][new_state].opt_param[qp->transport];
  529. if ((req_param & attr_mask) != req_param) {
  530. mthca_dbg(dev, "QP transition "
  531. "%d->%d missing req attr 0x%08x\n",
  532. cur_state, new_state,
  533. req_param & ~attr_mask);
  534. return -EINVAL;
  535. }
  536. if (attr_mask & ~(req_param | opt_param | IB_QP_STATE)) {
  537. mthca_dbg(dev, "QP transition (transport %d) "
  538. "%d->%d has extra attr 0x%08x\n",
  539. qp->transport,
  540. cur_state, new_state,
  541. attr_mask & ~(req_param | opt_param |
  542. IB_QP_STATE));
  543. return -EINVAL;
  544. }
  545. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  546. if (IS_ERR(mailbox))
  547. return PTR_ERR(mailbox);
  548. qp_param = mailbox->buf;
  549. qp_context = &qp_param->context;
  550. memset(qp_param, 0, sizeof *qp_param);
  551. qp_context->flags = cpu_to_be32((to_mthca_state(new_state) << 28) |
  552. (to_mthca_st(qp->transport) << 16));
  553. qp_context->flags |= cpu_to_be32(MTHCA_QP_BIT_DE);
  554. if (!(attr_mask & IB_QP_PATH_MIG_STATE))
  555. qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_MIGRATED << 11);
  556. else {
  557. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PM_STATE);
  558. switch (attr->path_mig_state) {
  559. case IB_MIG_MIGRATED:
  560. qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_MIGRATED << 11);
  561. break;
  562. case IB_MIG_REARM:
  563. qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_REARM << 11);
  564. break;
  565. case IB_MIG_ARMED:
  566. qp_context->flags |= cpu_to_be32(MTHCA_QP_PM_ARMED << 11);
  567. break;
  568. }
  569. }
  570. /* leave tavor_sched_queue as 0 */
  571. if (qp->transport == MLX || qp->transport == UD)
  572. qp_context->mtu_msgmax = (IB_MTU_2048 << 5) | 11;
  573. else if (attr_mask & IB_QP_PATH_MTU)
  574. qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31;
  575. if (mthca_is_memfree(dev)) {
  576. if (qp->rq.max)
  577. qp_context->rq_size_stride = long_log2(qp->rq.max) << 3;
  578. qp_context->rq_size_stride |= qp->rq.wqe_shift - 4;
  579. if (qp->sq.max)
  580. qp_context->sq_size_stride = long_log2(qp->sq.max) << 3;
  581. qp_context->sq_size_stride |= qp->sq.wqe_shift - 4;
  582. }
  583. /* leave arbel_sched_queue as 0 */
  584. if (qp->ibqp.uobject)
  585. qp_context->usr_page =
  586. cpu_to_be32(to_mucontext(qp->ibqp.uobject->context)->uar.index);
  587. else
  588. qp_context->usr_page = cpu_to_be32(dev->driver_uar.index);
  589. qp_context->local_qpn = cpu_to_be32(qp->qpn);
  590. if (attr_mask & IB_QP_DEST_QPN) {
  591. qp_context->remote_qpn = cpu_to_be32(attr->dest_qp_num);
  592. }
  593. if (qp->transport == MLX)
  594. qp_context->pri_path.port_pkey |=
  595. cpu_to_be32(to_msqp(qp)->port << 24);
  596. else {
  597. if (attr_mask & IB_QP_PORT) {
  598. qp_context->pri_path.port_pkey |=
  599. cpu_to_be32(attr->port_num << 24);
  600. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PORT_NUM);
  601. }
  602. }
  603. if (attr_mask & IB_QP_PKEY_INDEX) {
  604. qp_context->pri_path.port_pkey |=
  605. cpu_to_be32(attr->pkey_index);
  606. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PKEY_INDEX);
  607. }
  608. if (attr_mask & IB_QP_RNR_RETRY) {
  609. qp_context->pri_path.rnr_retry = attr->rnr_retry << 5;
  610. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_RETRY);
  611. }
  612. if (attr_mask & IB_QP_AV) {
  613. qp_context->pri_path.g_mylmc = attr->ah_attr.src_path_bits & 0x7f;
  614. qp_context->pri_path.rlid = cpu_to_be16(attr->ah_attr.dlid);
  615. qp_context->pri_path.static_rate = !!attr->ah_attr.static_rate;
  616. if (attr->ah_attr.ah_flags & IB_AH_GRH) {
  617. qp_context->pri_path.g_mylmc |= 1 << 7;
  618. qp_context->pri_path.mgid_index = attr->ah_attr.grh.sgid_index;
  619. qp_context->pri_path.hop_limit = attr->ah_attr.grh.hop_limit;
  620. qp_context->pri_path.sl_tclass_flowlabel =
  621. cpu_to_be32((attr->ah_attr.sl << 28) |
  622. (attr->ah_attr.grh.traffic_class << 20) |
  623. (attr->ah_attr.grh.flow_label));
  624. memcpy(qp_context->pri_path.rgid,
  625. attr->ah_attr.grh.dgid.raw, 16);
  626. } else {
  627. qp_context->pri_path.sl_tclass_flowlabel =
  628. cpu_to_be32(attr->ah_attr.sl << 28);
  629. }
  630. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH);
  631. }
  632. if (attr_mask & IB_QP_TIMEOUT) {
  633. qp_context->pri_path.ackto = attr->timeout << 3;
  634. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_ACK_TIMEOUT);
  635. }
  636. /* XXX alt_path */
  637. /* leave rdd as 0 */
  638. qp_context->pd = cpu_to_be32(to_mpd(ibqp->pd)->pd_num);
  639. /* leave wqe_base as 0 (we always create an MR based at 0 for WQs) */
  640. qp_context->wqe_lkey = cpu_to_be32(qp->mr.ibmr.lkey);
  641. qp_context->params1 = cpu_to_be32((MTHCA_ACK_REQ_FREQ << 28) |
  642. (MTHCA_FLIGHT_LIMIT << 24) |
  643. MTHCA_QP_BIT_SRE |
  644. MTHCA_QP_BIT_SWE |
  645. MTHCA_QP_BIT_SAE);
  646. if (qp->sq_policy == IB_SIGNAL_ALL_WR)
  647. qp_context->params1 |= cpu_to_be32(MTHCA_QP_BIT_SSC);
  648. if (attr_mask & IB_QP_RETRY_CNT) {
  649. qp_context->params1 |= cpu_to_be32(attr->retry_cnt << 16);
  650. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RETRY_COUNT);
  651. }
  652. if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
  653. qp_context->params1 |= cpu_to_be32(min(attr->max_rd_atomic ?
  654. ffs(attr->max_rd_atomic) - 1 : 0,
  655. 7) << 21);
  656. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_SRA_MAX);
  657. }
  658. if (attr_mask & IB_QP_SQ_PSN)
  659. qp_context->next_send_psn = cpu_to_be32(attr->sq_psn);
  660. qp_context->cqn_snd = cpu_to_be32(to_mcq(ibqp->send_cq)->cqn);
  661. if (mthca_is_memfree(dev)) {
  662. qp_context->snd_wqe_base_l = cpu_to_be32(qp->send_wqe_offset);
  663. qp_context->snd_db_index = cpu_to_be32(qp->sq.db_index);
  664. }
  665. if (attr_mask & IB_QP_ACCESS_FLAGS) {
  666. /*
  667. * Only enable RDMA/atomics if we have responder
  668. * resources set to a non-zero value.
  669. */
  670. if (qp->resp_depth) {
  671. qp_context->params2 |=
  672. cpu_to_be32(attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE ?
  673. MTHCA_QP_BIT_RWE : 0);
  674. qp_context->params2 |=
  675. cpu_to_be32(attr->qp_access_flags & IB_ACCESS_REMOTE_READ ?
  676. MTHCA_QP_BIT_RRE : 0);
  677. qp_context->params2 |=
  678. cpu_to_be32(attr->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC ?
  679. MTHCA_QP_BIT_RAE : 0);
  680. }
  681. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RWE |
  682. MTHCA_QP_OPTPAR_RRE |
  683. MTHCA_QP_OPTPAR_RAE);
  684. qp->atomic_rd_en = attr->qp_access_flags;
  685. }
  686. if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
  687. u8 rra_max;
  688. if (qp->resp_depth && !attr->max_dest_rd_atomic) {
  689. /*
  690. * Lowering our responder resources to zero.
  691. * Turn off RDMA/atomics as responder.
  692. * (RWE/RRE/RAE in params2 already zero)
  693. */
  694. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RWE |
  695. MTHCA_QP_OPTPAR_RRE |
  696. MTHCA_QP_OPTPAR_RAE);
  697. }
  698. if (!qp->resp_depth && attr->max_dest_rd_atomic) {
  699. /*
  700. * Increasing our responder resources from
  701. * zero. Turn on RDMA/atomics as appropriate.
  702. */
  703. qp_context->params2 |=
  704. cpu_to_be32(qp->atomic_rd_en & IB_ACCESS_REMOTE_WRITE ?
  705. MTHCA_QP_BIT_RWE : 0);
  706. qp_context->params2 |=
  707. cpu_to_be32(qp->atomic_rd_en & IB_ACCESS_REMOTE_READ ?
  708. MTHCA_QP_BIT_RRE : 0);
  709. qp_context->params2 |=
  710. cpu_to_be32(qp->atomic_rd_en & IB_ACCESS_REMOTE_ATOMIC ?
  711. MTHCA_QP_BIT_RAE : 0);
  712. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RWE |
  713. MTHCA_QP_OPTPAR_RRE |
  714. MTHCA_QP_OPTPAR_RAE);
  715. }
  716. for (rra_max = 0;
  717. 1 << rra_max < attr->max_dest_rd_atomic &&
  718. rra_max < dev->qp_table.rdb_shift;
  719. ++rra_max)
  720. ; /* nothing */
  721. qp_context->params2 |= cpu_to_be32(rra_max << 21);
  722. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RRA_MAX);
  723. qp->resp_depth = attr->max_dest_rd_atomic;
  724. }
  725. qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC);
  726. if (ibqp->srq)
  727. qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RIC);
  728. if (attr_mask & IB_QP_MIN_RNR_TIMER) {
  729. qp_context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24);
  730. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_TIMEOUT);
  731. }
  732. if (attr_mask & IB_QP_RQ_PSN)
  733. qp_context->rnr_nextrecvpsn |= cpu_to_be32(attr->rq_psn);
  734. qp_context->ra_buff_indx =
  735. cpu_to_be32(dev->qp_table.rdb_base +
  736. ((qp->qpn & (dev->limits.num_qps - 1)) * MTHCA_RDB_ENTRY_SIZE <<
  737. dev->qp_table.rdb_shift));
  738. qp_context->cqn_rcv = cpu_to_be32(to_mcq(ibqp->recv_cq)->cqn);
  739. if (mthca_is_memfree(dev))
  740. qp_context->rcv_db_index = cpu_to_be32(qp->rq.db_index);
  741. if (attr_mask & IB_QP_QKEY) {
  742. qp_context->qkey = cpu_to_be32(attr->qkey);
  743. qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_Q_KEY);
  744. }
  745. if (ibqp->srq)
  746. qp_context->srqn = cpu_to_be32(1 << 24 |
  747. to_msrq(ibqp->srq)->srqn);
  748. err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,
  749. qp->qpn, 0, mailbox, 0, &status);
  750. if (status) {
  751. mthca_warn(dev, "modify QP %d returned status %02x.\n",
  752. state_table[cur_state][new_state].trans, status);
  753. err = -EINVAL;
  754. }
  755. if (!err)
  756. qp->state = new_state;
  757. mthca_free_mailbox(dev, mailbox);
  758. if (is_sqp(dev, qp))
  759. store_attrs(to_msqp(qp), attr, attr_mask);
  760. /*
  761. * If we moved QP0 to RTR, bring the IB link up; if we moved
  762. * QP0 to RESET or ERROR, bring the link back down.
  763. */
  764. if (is_qp0(dev, qp)) {
  765. if (cur_state != IB_QPS_RTR &&
  766. new_state == IB_QPS_RTR)
  767. init_port(dev, to_msqp(qp)->port);
  768. if (cur_state != IB_QPS_RESET &&
  769. cur_state != IB_QPS_ERR &&
  770. (new_state == IB_QPS_RESET ||
  771. new_state == IB_QPS_ERR))
  772. mthca_CLOSE_IB(dev, to_msqp(qp)->port, &status);
  773. }
  774. /*
  775. * If we moved a kernel QP to RESET, clean up all old CQ
  776. * entries and reinitialize the QP.
  777. */
  778. if (!err && new_state == IB_QPS_RESET && !qp->ibqp.uobject) {
  779. mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn,
  780. qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
  781. if (qp->ibqp.send_cq != qp->ibqp.recv_cq)
  782. mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn,
  783. qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
  784. mthca_wq_init(&qp->sq);
  785. mthca_wq_init(&qp->rq);
  786. if (mthca_is_memfree(dev)) {
  787. *qp->sq.db = 0;
  788. *qp->rq.db = 0;
  789. }
  790. }
  791. return err;
  792. }
  793. /*
  794. * Allocate and register buffer for WQEs. qp->rq.max, sq.max,
  795. * rq.max_gs and sq.max_gs must all be assigned.
  796. * mthca_alloc_wqe_buf will calculate rq.wqe_shift and
  797. * sq.wqe_shift (as well as send_wqe_offset, is_direct, and
  798. * queue)
  799. */
  800. static int mthca_alloc_wqe_buf(struct mthca_dev *dev,
  801. struct mthca_pd *pd,
  802. struct mthca_qp *qp)
  803. {
  804. int size;
  805. int err = -ENOMEM;
  806. size = sizeof (struct mthca_next_seg) +
  807. qp->rq.max_gs * sizeof (struct mthca_data_seg);
  808. for (qp->rq.wqe_shift = 6; 1 << qp->rq.wqe_shift < size;
  809. qp->rq.wqe_shift++)
  810. ; /* nothing */
  811. size = sizeof (struct mthca_next_seg) +
  812. qp->sq.max_gs * sizeof (struct mthca_data_seg);
  813. switch (qp->transport) {
  814. case MLX:
  815. size += 2 * sizeof (struct mthca_data_seg);
  816. break;
  817. case UD:
  818. if (mthca_is_memfree(dev))
  819. size += sizeof (struct mthca_arbel_ud_seg);
  820. else
  821. size += sizeof (struct mthca_tavor_ud_seg);
  822. break;
  823. default:
  824. /* bind seg is as big as atomic + raddr segs */
  825. size += sizeof (struct mthca_bind_seg);
  826. }
  827. for (qp->sq.wqe_shift = 6; 1 << qp->sq.wqe_shift < size;
  828. qp->sq.wqe_shift++)
  829. ; /* nothing */
  830. qp->send_wqe_offset = ALIGN(qp->rq.max << qp->rq.wqe_shift,
  831. 1 << qp->sq.wqe_shift);
  832. /*
  833. * If this is a userspace QP, we don't actually have to
  834. * allocate anything. All we need is to calculate the WQE
  835. * sizes and the send_wqe_offset, so we're done now.
  836. */
  837. if (pd->ibpd.uobject)
  838. return 0;
  839. size = PAGE_ALIGN(qp->send_wqe_offset +
  840. (qp->sq.max << qp->sq.wqe_shift));
  841. qp->wrid = kmalloc((qp->rq.max + qp->sq.max) * sizeof (u64),
  842. GFP_KERNEL);
  843. if (!qp->wrid)
  844. goto err_out;
  845. err = mthca_buf_alloc(dev, size, MTHCA_MAX_DIRECT_QP_SIZE,
  846. &qp->queue, &qp->is_direct, pd, 0, &qp->mr);
  847. if (err)
  848. goto err_out;
  849. return 0;
  850. err_out:
  851. kfree(qp->wrid);
  852. return err;
  853. }
  854. static void mthca_free_wqe_buf(struct mthca_dev *dev,
  855. struct mthca_qp *qp)
  856. {
  857. mthca_buf_free(dev, PAGE_ALIGN(qp->send_wqe_offset +
  858. (qp->sq.max << qp->sq.wqe_shift)),
  859. &qp->queue, qp->is_direct, &qp->mr);
  860. kfree(qp->wrid);
  861. }
  862. static int mthca_map_memfree(struct mthca_dev *dev,
  863. struct mthca_qp *qp)
  864. {
  865. int ret;
  866. if (mthca_is_memfree(dev)) {
  867. ret = mthca_table_get(dev, dev->qp_table.qp_table, qp->qpn);
  868. if (ret)
  869. return ret;
  870. ret = mthca_table_get(dev, dev->qp_table.eqp_table, qp->qpn);
  871. if (ret)
  872. goto err_qpc;
  873. ret = mthca_table_get(dev, dev->qp_table.rdb_table,
  874. qp->qpn << dev->qp_table.rdb_shift);
  875. if (ret)
  876. goto err_eqpc;
  877. }
  878. return 0;
  879. err_eqpc:
  880. mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
  881. err_qpc:
  882. mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
  883. return ret;
  884. }
  885. static void mthca_unmap_memfree(struct mthca_dev *dev,
  886. struct mthca_qp *qp)
  887. {
  888. mthca_table_put(dev, dev->qp_table.rdb_table,
  889. qp->qpn << dev->qp_table.rdb_shift);
  890. mthca_table_put(dev, dev->qp_table.eqp_table, qp->qpn);
  891. mthca_table_put(dev, dev->qp_table.qp_table, qp->qpn);
  892. }
  893. static int mthca_alloc_memfree(struct mthca_dev *dev,
  894. struct mthca_qp *qp)
  895. {
  896. int ret = 0;
  897. if (mthca_is_memfree(dev)) {
  898. qp->rq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_RQ,
  899. qp->qpn, &qp->rq.db);
  900. if (qp->rq.db_index < 0)
  901. return ret;
  902. qp->sq.db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SQ,
  903. qp->qpn, &qp->sq.db);
  904. if (qp->sq.db_index < 0)
  905. mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
  906. }
  907. return ret;
  908. }
  909. static void mthca_free_memfree(struct mthca_dev *dev,
  910. struct mthca_qp *qp)
  911. {
  912. if (mthca_is_memfree(dev)) {
  913. mthca_free_db(dev, MTHCA_DB_TYPE_SQ, qp->sq.db_index);
  914. mthca_free_db(dev, MTHCA_DB_TYPE_RQ, qp->rq.db_index);
  915. }
  916. }
  917. static int mthca_alloc_qp_common(struct mthca_dev *dev,
  918. struct mthca_pd *pd,
  919. struct mthca_cq *send_cq,
  920. struct mthca_cq *recv_cq,
  921. enum ib_sig_type send_policy,
  922. struct mthca_qp *qp)
  923. {
  924. int ret;
  925. int i;
  926. atomic_set(&qp->refcount, 1);
  927. init_waitqueue_head(&qp->wait);
  928. qp->state = IB_QPS_RESET;
  929. qp->atomic_rd_en = 0;
  930. qp->resp_depth = 0;
  931. qp->sq_policy = send_policy;
  932. mthca_wq_init(&qp->sq);
  933. mthca_wq_init(&qp->rq);
  934. ret = mthca_map_memfree(dev, qp);
  935. if (ret)
  936. return ret;
  937. ret = mthca_alloc_wqe_buf(dev, pd, qp);
  938. if (ret) {
  939. mthca_unmap_memfree(dev, qp);
  940. return ret;
  941. }
  942. /*
  943. * If this is a userspace QP, we're done now. The doorbells
  944. * will be allocated and buffers will be initialized in
  945. * userspace.
  946. */
  947. if (pd->ibpd.uobject)
  948. return 0;
  949. ret = mthca_alloc_memfree(dev, qp);
  950. if (ret) {
  951. mthca_free_wqe_buf(dev, qp);
  952. mthca_unmap_memfree(dev, qp);
  953. return ret;
  954. }
  955. if (mthca_is_memfree(dev)) {
  956. struct mthca_next_seg *next;
  957. struct mthca_data_seg *scatter;
  958. int size = (sizeof (struct mthca_next_seg) +
  959. qp->rq.max_gs * sizeof (struct mthca_data_seg)) / 16;
  960. for (i = 0; i < qp->rq.max; ++i) {
  961. next = get_recv_wqe(qp, i);
  962. next->nda_op = cpu_to_be32(((i + 1) & (qp->rq.max - 1)) <<
  963. qp->rq.wqe_shift);
  964. next->ee_nds = cpu_to_be32(size);
  965. for (scatter = (void *) (next + 1);
  966. (void *) scatter < (void *) next + (1 << qp->rq.wqe_shift);
  967. ++scatter)
  968. scatter->lkey = cpu_to_be32(MTHCA_INVAL_LKEY);
  969. }
  970. for (i = 0; i < qp->sq.max; ++i) {
  971. next = get_send_wqe(qp, i);
  972. next->nda_op = cpu_to_be32((((i + 1) & (qp->sq.max - 1)) <<
  973. qp->sq.wqe_shift) +
  974. qp->send_wqe_offset);
  975. }
  976. }
  977. qp->sq.last = get_send_wqe(qp, qp->sq.max - 1);
  978. qp->rq.last = get_recv_wqe(qp, qp->rq.max - 1);
  979. return 0;
  980. }
  981. static int mthca_set_qp_size(struct mthca_dev *dev, struct ib_qp_cap *cap,
  982. struct mthca_qp *qp)
  983. {
  984. /* Sanity check QP size before proceeding */
  985. if (cap->max_send_wr > dev->limits.max_wqes ||
  986. cap->max_recv_wr > dev->limits.max_wqes ||
  987. cap->max_send_sge > dev->limits.max_sg ||
  988. cap->max_recv_sge > dev->limits.max_sg)
  989. return -EINVAL;
  990. if (mthca_is_memfree(dev)) {
  991. qp->rq.max = cap->max_recv_wr ?
  992. roundup_pow_of_two(cap->max_recv_wr) : 0;
  993. qp->sq.max = cap->max_send_wr ?
  994. roundup_pow_of_two(cap->max_send_wr) : 0;
  995. } else {
  996. qp->rq.max = cap->max_recv_wr;
  997. qp->sq.max = cap->max_send_wr;
  998. }
  999. qp->rq.max_gs = cap->max_recv_sge;
  1000. qp->sq.max_gs = max_t(int, cap->max_send_sge,
  1001. ALIGN(cap->max_inline_data + MTHCA_INLINE_HEADER_SIZE,
  1002. MTHCA_INLINE_CHUNK_SIZE) /
  1003. sizeof (struct mthca_data_seg));
  1004. /*
  1005. * For MLX transport we need 2 extra S/G entries:
  1006. * one for the header and one for the checksum at the end
  1007. */
  1008. if ((qp->transport == MLX && qp->sq.max_gs + 2 > dev->limits.max_sg) ||
  1009. qp->sq.max_gs > dev->limits.max_sg || qp->rq.max_gs > dev->limits.max_sg)
  1010. return -EINVAL;
  1011. return 0;
  1012. }
  1013. int mthca_alloc_qp(struct mthca_dev *dev,
  1014. struct mthca_pd *pd,
  1015. struct mthca_cq *send_cq,
  1016. struct mthca_cq *recv_cq,
  1017. enum ib_qp_type type,
  1018. enum ib_sig_type send_policy,
  1019. struct ib_qp_cap *cap,
  1020. struct mthca_qp *qp)
  1021. {
  1022. int err;
  1023. err = mthca_set_qp_size(dev, cap, qp);
  1024. if (err)
  1025. return err;
  1026. switch (type) {
  1027. case IB_QPT_RC: qp->transport = RC; break;
  1028. case IB_QPT_UC: qp->transport = UC; break;
  1029. case IB_QPT_UD: qp->transport = UD; break;
  1030. default: return -EINVAL;
  1031. }
  1032. qp->qpn = mthca_alloc(&dev->qp_table.alloc);
  1033. if (qp->qpn == -1)
  1034. return -ENOMEM;
  1035. err = mthca_alloc_qp_common(dev, pd, send_cq, recv_cq,
  1036. send_policy, qp);
  1037. if (err) {
  1038. mthca_free(&dev->qp_table.alloc, qp->qpn);
  1039. return err;
  1040. }
  1041. spin_lock_irq(&dev->qp_table.lock);
  1042. mthca_array_set(&dev->qp_table.qp,
  1043. qp->qpn & (dev->limits.num_qps - 1), qp);
  1044. spin_unlock_irq(&dev->qp_table.lock);
  1045. return 0;
  1046. }
  1047. int mthca_alloc_sqp(struct mthca_dev *dev,
  1048. struct mthca_pd *pd,
  1049. struct mthca_cq *send_cq,
  1050. struct mthca_cq *recv_cq,
  1051. enum ib_sig_type send_policy,
  1052. struct ib_qp_cap *cap,
  1053. int qpn,
  1054. int port,
  1055. struct mthca_sqp *sqp)
  1056. {
  1057. u32 mqpn = qpn * 2 + dev->qp_table.sqp_start + port - 1;
  1058. int err;
  1059. err = mthca_set_qp_size(dev, cap, &sqp->qp);
  1060. if (err)
  1061. return err;
  1062. sqp->header_buf_size = sqp->qp.sq.max * MTHCA_UD_HEADER_SIZE;
  1063. sqp->header_buf = dma_alloc_coherent(&dev->pdev->dev, sqp->header_buf_size,
  1064. &sqp->header_dma, GFP_KERNEL);
  1065. if (!sqp->header_buf)
  1066. return -ENOMEM;
  1067. spin_lock_irq(&dev->qp_table.lock);
  1068. if (mthca_array_get(&dev->qp_table.qp, mqpn))
  1069. err = -EBUSY;
  1070. else
  1071. mthca_array_set(&dev->qp_table.qp, mqpn, sqp);
  1072. spin_unlock_irq(&dev->qp_table.lock);
  1073. if (err)
  1074. goto err_out;
  1075. sqp->port = port;
  1076. sqp->qp.qpn = mqpn;
  1077. sqp->qp.transport = MLX;
  1078. err = mthca_alloc_qp_common(dev, pd, send_cq, recv_cq,
  1079. send_policy, &sqp->qp);
  1080. if (err)
  1081. goto err_out_free;
  1082. atomic_inc(&pd->sqp_count);
  1083. return 0;
  1084. err_out_free:
  1085. /*
  1086. * Lock CQs here, so that CQ polling code can do QP lookup
  1087. * without taking a lock.
  1088. */
  1089. spin_lock_irq(&send_cq->lock);
  1090. if (send_cq != recv_cq)
  1091. spin_lock(&recv_cq->lock);
  1092. spin_lock(&dev->qp_table.lock);
  1093. mthca_array_clear(&dev->qp_table.qp, mqpn);
  1094. spin_unlock(&dev->qp_table.lock);
  1095. if (send_cq != recv_cq)
  1096. spin_unlock(&recv_cq->lock);
  1097. spin_unlock_irq(&send_cq->lock);
  1098. err_out:
  1099. dma_free_coherent(&dev->pdev->dev, sqp->header_buf_size,
  1100. sqp->header_buf, sqp->header_dma);
  1101. return err;
  1102. }
  1103. void mthca_free_qp(struct mthca_dev *dev,
  1104. struct mthca_qp *qp)
  1105. {
  1106. u8 status;
  1107. struct mthca_cq *send_cq;
  1108. struct mthca_cq *recv_cq;
  1109. send_cq = to_mcq(qp->ibqp.send_cq);
  1110. recv_cq = to_mcq(qp->ibqp.recv_cq);
  1111. /*
  1112. * Lock CQs here, so that CQ polling code can do QP lookup
  1113. * without taking a lock.
  1114. */
  1115. spin_lock_irq(&send_cq->lock);
  1116. if (send_cq != recv_cq)
  1117. spin_lock(&recv_cq->lock);
  1118. spin_lock(&dev->qp_table.lock);
  1119. mthca_array_clear(&dev->qp_table.qp,
  1120. qp->qpn & (dev->limits.num_qps - 1));
  1121. spin_unlock(&dev->qp_table.lock);
  1122. if (send_cq != recv_cq)
  1123. spin_unlock(&recv_cq->lock);
  1124. spin_unlock_irq(&send_cq->lock);
  1125. atomic_dec(&qp->refcount);
  1126. wait_event(qp->wait, !atomic_read(&qp->refcount));
  1127. if (qp->state != IB_QPS_RESET)
  1128. mthca_MODIFY_QP(dev, MTHCA_TRANS_ANY2RST, qp->qpn, 0, NULL, 0, &status);
  1129. /*
  1130. * If this is a userspace QP, the buffers, MR, CQs and so on
  1131. * will be cleaned up in userspace, so all we have to do is
  1132. * unref the mem-free tables and free the QPN in our table.
  1133. */
  1134. if (!qp->ibqp.uobject) {
  1135. mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn,
  1136. qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
  1137. if (qp->ibqp.send_cq != qp->ibqp.recv_cq)
  1138. mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn,
  1139. qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);
  1140. mthca_free_memfree(dev, qp);
  1141. mthca_free_wqe_buf(dev, qp);
  1142. }
  1143. mthca_unmap_memfree(dev, qp);
  1144. if (is_sqp(dev, qp)) {
  1145. atomic_dec(&(to_mpd(qp->ibqp.pd)->sqp_count));
  1146. dma_free_coherent(&dev->pdev->dev,
  1147. to_msqp(qp)->header_buf_size,
  1148. to_msqp(qp)->header_buf,
  1149. to_msqp(qp)->header_dma);
  1150. } else
  1151. mthca_free(&dev->qp_table.alloc, qp->qpn);
  1152. }
  1153. /* Create UD header for an MLX send and build a data segment for it */
  1154. static int build_mlx_header(struct mthca_dev *dev, struct mthca_sqp *sqp,
  1155. int ind, struct ib_send_wr *wr,
  1156. struct mthca_mlx_seg *mlx,
  1157. struct mthca_data_seg *data)
  1158. {
  1159. int header_size;
  1160. int err;
  1161. u16 pkey;
  1162. ib_ud_header_init(256, /* assume a MAD */
  1163. sqp->ud_header.grh_present,
  1164. &sqp->ud_header);
  1165. err = mthca_read_ah(dev, to_mah(wr->wr.ud.ah), &sqp->ud_header);
  1166. if (err)
  1167. return err;
  1168. mlx->flags &= ~cpu_to_be32(MTHCA_NEXT_SOLICIT | 1);
  1169. mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MTHCA_MLX_VL15 : 0) |
  1170. (sqp->ud_header.lrh.destination_lid ==
  1171. IB_LID_PERMISSIVE ? MTHCA_MLX_SLR : 0) |
  1172. (sqp->ud_header.lrh.service_level << 8));
  1173. mlx->rlid = sqp->ud_header.lrh.destination_lid;
  1174. mlx->vcrc = 0;
  1175. switch (wr->opcode) {
  1176. case IB_WR_SEND:
  1177. sqp->ud_header.bth.opcode = IB_OPCODE_UD_SEND_ONLY;
  1178. sqp->ud_header.immediate_present = 0;
  1179. break;
  1180. case IB_WR_SEND_WITH_IMM:
  1181. sqp->ud_header.bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE;
  1182. sqp->ud_header.immediate_present = 1;
  1183. sqp->ud_header.immediate_data = wr->imm_data;
  1184. break;
  1185. default:
  1186. return -EINVAL;
  1187. }
  1188. sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0;
  1189. if (sqp->ud_header.lrh.destination_lid == IB_LID_PERMISSIVE)
  1190. sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE;
  1191. sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);
  1192. if (!sqp->qp.ibqp.qp_num)
  1193. ib_get_cached_pkey(&dev->ib_dev, sqp->port,
  1194. sqp->pkey_index, &pkey);
  1195. else
  1196. ib_get_cached_pkey(&dev->ib_dev, sqp->port,
  1197. wr->wr.ud.pkey_index, &pkey);
  1198. sqp->ud_header.bth.pkey = cpu_to_be16(pkey);
  1199. sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn);
  1200. sqp->ud_header.bth.psn = cpu_to_be32((sqp->send_psn++) & ((1 << 24) - 1));
  1201. sqp->ud_header.deth.qkey = cpu_to_be32(wr->wr.ud.remote_qkey & 0x80000000 ?
  1202. sqp->qkey : wr->wr.ud.remote_qkey);
  1203. sqp->ud_header.deth.source_qpn = cpu_to_be32(sqp->qp.ibqp.qp_num);
  1204. header_size = ib_ud_header_pack(&sqp->ud_header,
  1205. sqp->header_buf +
  1206. ind * MTHCA_UD_HEADER_SIZE);
  1207. data->byte_count = cpu_to_be32(header_size);
  1208. data->lkey = cpu_to_be32(to_mpd(sqp->qp.ibqp.pd)->ntmr.ibmr.lkey);
  1209. data->addr = cpu_to_be64(sqp->header_dma +
  1210. ind * MTHCA_UD_HEADER_SIZE);
  1211. return 0;
  1212. }
  1213. static inline int mthca_wq_overflow(struct mthca_wq *wq, int nreq,
  1214. struct ib_cq *ib_cq)
  1215. {
  1216. unsigned cur;
  1217. struct mthca_cq *cq;
  1218. cur = wq->head - wq->tail;
  1219. if (likely(cur + nreq < wq->max))
  1220. return 0;
  1221. cq = to_mcq(ib_cq);
  1222. spin_lock(&cq->lock);
  1223. cur = wq->head - wq->tail;
  1224. spin_unlock(&cq->lock);
  1225. return cur + nreq >= wq->max;
  1226. }
  1227. int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  1228. struct ib_send_wr **bad_wr)
  1229. {
  1230. struct mthca_dev *dev = to_mdev(ibqp->device);
  1231. struct mthca_qp *qp = to_mqp(ibqp);
  1232. void *wqe;
  1233. void *prev_wqe;
  1234. unsigned long flags;
  1235. int err = 0;
  1236. int nreq;
  1237. int i;
  1238. int size;
  1239. int size0 = 0;
  1240. u32 f0 = 0;
  1241. int ind;
  1242. u8 op0 = 0;
  1243. spin_lock_irqsave(&qp->sq.lock, flags);
  1244. /* XXX check that state is OK to post send */
  1245. ind = qp->sq.next_ind;
  1246. for (nreq = 0; wr; ++nreq, wr = wr->next) {
  1247. if (mthca_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq)) {
  1248. mthca_err(dev, "SQ %06x full (%u head, %u tail,"
  1249. " %d max, %d nreq)\n", qp->qpn,
  1250. qp->sq.head, qp->sq.tail,
  1251. qp->sq.max, nreq);
  1252. err = -ENOMEM;
  1253. *bad_wr = wr;
  1254. goto out;
  1255. }
  1256. wqe = get_send_wqe(qp, ind);
  1257. prev_wqe = qp->sq.last;
  1258. qp->sq.last = wqe;
  1259. ((struct mthca_next_seg *) wqe)->nda_op = 0;
  1260. ((struct mthca_next_seg *) wqe)->ee_nds = 0;
  1261. ((struct mthca_next_seg *) wqe)->flags =
  1262. ((wr->send_flags & IB_SEND_SIGNALED) ?
  1263. cpu_to_be32(MTHCA_NEXT_CQ_UPDATE) : 0) |
  1264. ((wr->send_flags & IB_SEND_SOLICITED) ?
  1265. cpu_to_be32(MTHCA_NEXT_SOLICIT) : 0) |
  1266. cpu_to_be32(1);
  1267. if (wr->opcode == IB_WR_SEND_WITH_IMM ||
  1268. wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM)
  1269. ((struct mthca_next_seg *) wqe)->imm = wr->imm_data;
  1270. wqe += sizeof (struct mthca_next_seg);
  1271. size = sizeof (struct mthca_next_seg) / 16;
  1272. switch (qp->transport) {
  1273. case RC:
  1274. switch (wr->opcode) {
  1275. case IB_WR_ATOMIC_CMP_AND_SWP:
  1276. case IB_WR_ATOMIC_FETCH_AND_ADD:
  1277. ((struct mthca_raddr_seg *) wqe)->raddr =
  1278. cpu_to_be64(wr->wr.atomic.remote_addr);
  1279. ((struct mthca_raddr_seg *) wqe)->rkey =
  1280. cpu_to_be32(wr->wr.atomic.rkey);
  1281. ((struct mthca_raddr_seg *) wqe)->reserved = 0;
  1282. wqe += sizeof (struct mthca_raddr_seg);
  1283. if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
  1284. ((struct mthca_atomic_seg *) wqe)->swap_add =
  1285. cpu_to_be64(wr->wr.atomic.swap);
  1286. ((struct mthca_atomic_seg *) wqe)->compare =
  1287. cpu_to_be64(wr->wr.atomic.compare_add);
  1288. } else {
  1289. ((struct mthca_atomic_seg *) wqe)->swap_add =
  1290. cpu_to_be64(wr->wr.atomic.compare_add);
  1291. ((struct mthca_atomic_seg *) wqe)->compare = 0;
  1292. }
  1293. wqe += sizeof (struct mthca_atomic_seg);
  1294. size += sizeof (struct mthca_raddr_seg) / 16 +
  1295. sizeof (struct mthca_atomic_seg);
  1296. break;
  1297. case IB_WR_RDMA_WRITE:
  1298. case IB_WR_RDMA_WRITE_WITH_IMM:
  1299. case IB_WR_RDMA_READ:
  1300. ((struct mthca_raddr_seg *) wqe)->raddr =
  1301. cpu_to_be64(wr->wr.rdma.remote_addr);
  1302. ((struct mthca_raddr_seg *) wqe)->rkey =
  1303. cpu_to_be32(wr->wr.rdma.rkey);
  1304. ((struct mthca_raddr_seg *) wqe)->reserved = 0;
  1305. wqe += sizeof (struct mthca_raddr_seg);
  1306. size += sizeof (struct mthca_raddr_seg) / 16;
  1307. break;
  1308. default:
  1309. /* No extra segments required for sends */
  1310. break;
  1311. }
  1312. break;
  1313. case UC:
  1314. switch (wr->opcode) {
  1315. case IB_WR_RDMA_WRITE:
  1316. case IB_WR_RDMA_WRITE_WITH_IMM:
  1317. ((struct mthca_raddr_seg *) wqe)->raddr =
  1318. cpu_to_be64(wr->wr.rdma.remote_addr);
  1319. ((struct mthca_raddr_seg *) wqe)->rkey =
  1320. cpu_to_be32(wr->wr.rdma.rkey);
  1321. ((struct mthca_raddr_seg *) wqe)->reserved = 0;
  1322. wqe += sizeof (struct mthca_raddr_seg);
  1323. size += sizeof (struct mthca_raddr_seg) / 16;
  1324. break;
  1325. default:
  1326. /* No extra segments required for sends */
  1327. break;
  1328. }
  1329. break;
  1330. case UD:
  1331. ((struct mthca_tavor_ud_seg *) wqe)->lkey =
  1332. cpu_to_be32(to_mah(wr->wr.ud.ah)->key);
  1333. ((struct mthca_tavor_ud_seg *) wqe)->av_addr =
  1334. cpu_to_be64(to_mah(wr->wr.ud.ah)->avdma);
  1335. ((struct mthca_tavor_ud_seg *) wqe)->dqpn =
  1336. cpu_to_be32(wr->wr.ud.remote_qpn);
  1337. ((struct mthca_tavor_ud_seg *) wqe)->qkey =
  1338. cpu_to_be32(wr->wr.ud.remote_qkey);
  1339. wqe += sizeof (struct mthca_tavor_ud_seg);
  1340. size += sizeof (struct mthca_tavor_ud_seg) / 16;
  1341. break;
  1342. case MLX:
  1343. err = build_mlx_header(dev, to_msqp(qp), ind, wr,
  1344. wqe - sizeof (struct mthca_next_seg),
  1345. wqe);
  1346. if (err) {
  1347. *bad_wr = wr;
  1348. goto out;
  1349. }
  1350. wqe += sizeof (struct mthca_data_seg);
  1351. size += sizeof (struct mthca_data_seg) / 16;
  1352. break;
  1353. }
  1354. if (wr->num_sge > qp->sq.max_gs) {
  1355. mthca_err(dev, "too many gathers\n");
  1356. err = -EINVAL;
  1357. *bad_wr = wr;
  1358. goto out;
  1359. }
  1360. for (i = 0; i < wr->num_sge; ++i) {
  1361. ((struct mthca_data_seg *) wqe)->byte_count =
  1362. cpu_to_be32(wr->sg_list[i].length);
  1363. ((struct mthca_data_seg *) wqe)->lkey =
  1364. cpu_to_be32(wr->sg_list[i].lkey);
  1365. ((struct mthca_data_seg *) wqe)->addr =
  1366. cpu_to_be64(wr->sg_list[i].addr);
  1367. wqe += sizeof (struct mthca_data_seg);
  1368. size += sizeof (struct mthca_data_seg) / 16;
  1369. }
  1370. /* Add one more inline data segment for ICRC */
  1371. if (qp->transport == MLX) {
  1372. ((struct mthca_data_seg *) wqe)->byte_count =
  1373. cpu_to_be32((1 << 31) | 4);
  1374. ((u32 *) wqe)[1] = 0;
  1375. wqe += sizeof (struct mthca_data_seg);
  1376. size += sizeof (struct mthca_data_seg) / 16;
  1377. }
  1378. qp->wrid[ind + qp->rq.max] = wr->wr_id;
  1379. if (wr->opcode >= ARRAY_SIZE(mthca_opcode)) {
  1380. mthca_err(dev, "opcode invalid\n");
  1381. err = -EINVAL;
  1382. *bad_wr = wr;
  1383. goto out;
  1384. }
  1385. ((struct mthca_next_seg *) prev_wqe)->nda_op =
  1386. cpu_to_be32(((ind << qp->sq.wqe_shift) +
  1387. qp->send_wqe_offset) |
  1388. mthca_opcode[wr->opcode]);
  1389. wmb();
  1390. ((struct mthca_next_seg *) prev_wqe)->ee_nds =
  1391. cpu_to_be32((size0 ? 0 : MTHCA_NEXT_DBD) | size);
  1392. if (!size0) {
  1393. size0 = size;
  1394. op0 = mthca_opcode[wr->opcode];
  1395. }
  1396. ++ind;
  1397. if (unlikely(ind >= qp->sq.max))
  1398. ind -= qp->sq.max;
  1399. }
  1400. out:
  1401. if (likely(nreq)) {
  1402. __be32 doorbell[2];
  1403. doorbell[0] = cpu_to_be32(((qp->sq.next_ind << qp->sq.wqe_shift) +
  1404. qp->send_wqe_offset) | f0 | op0);
  1405. doorbell[1] = cpu_to_be32((qp->qpn << 8) | size0);
  1406. wmb();
  1407. mthca_write64(doorbell,
  1408. dev->kar + MTHCA_SEND_DOORBELL,
  1409. MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
  1410. }
  1411. qp->sq.next_ind = ind;
  1412. qp->sq.head += nreq;
  1413. spin_unlock_irqrestore(&qp->sq.lock, flags);
  1414. return err;
  1415. }
  1416. int mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  1417. struct ib_recv_wr **bad_wr)
  1418. {
  1419. struct mthca_dev *dev = to_mdev(ibqp->device);
  1420. struct mthca_qp *qp = to_mqp(ibqp);
  1421. unsigned long flags;
  1422. int err = 0;
  1423. int nreq;
  1424. int i;
  1425. int size;
  1426. int size0 = 0;
  1427. int ind;
  1428. void *wqe;
  1429. void *prev_wqe;
  1430. spin_lock_irqsave(&qp->rq.lock, flags);
  1431. /* XXX check that state is OK to post receive */
  1432. ind = qp->rq.next_ind;
  1433. for (nreq = 0; wr; ++nreq, wr = wr->next) {
  1434. if (mthca_wq_overflow(&qp->rq, nreq, qp->ibqp.recv_cq)) {
  1435. mthca_err(dev, "RQ %06x full (%u head, %u tail,"
  1436. " %d max, %d nreq)\n", qp->qpn,
  1437. qp->rq.head, qp->rq.tail,
  1438. qp->rq.max, nreq);
  1439. err = -ENOMEM;
  1440. *bad_wr = wr;
  1441. goto out;
  1442. }
  1443. wqe = get_recv_wqe(qp, ind);
  1444. prev_wqe = qp->rq.last;
  1445. qp->rq.last = wqe;
  1446. ((struct mthca_next_seg *) wqe)->nda_op = 0;
  1447. ((struct mthca_next_seg *) wqe)->ee_nds =
  1448. cpu_to_be32(MTHCA_NEXT_DBD);
  1449. ((struct mthca_next_seg *) wqe)->flags = 0;
  1450. wqe += sizeof (struct mthca_next_seg);
  1451. size = sizeof (struct mthca_next_seg) / 16;
  1452. if (unlikely(wr->num_sge > qp->rq.max_gs)) {
  1453. err = -EINVAL;
  1454. *bad_wr = wr;
  1455. goto out;
  1456. }
  1457. for (i = 0; i < wr->num_sge; ++i) {
  1458. ((struct mthca_data_seg *) wqe)->byte_count =
  1459. cpu_to_be32(wr->sg_list[i].length);
  1460. ((struct mthca_data_seg *) wqe)->lkey =
  1461. cpu_to_be32(wr->sg_list[i].lkey);
  1462. ((struct mthca_data_seg *) wqe)->addr =
  1463. cpu_to_be64(wr->sg_list[i].addr);
  1464. wqe += sizeof (struct mthca_data_seg);
  1465. size += sizeof (struct mthca_data_seg) / 16;
  1466. }
  1467. qp->wrid[ind] = wr->wr_id;
  1468. ((struct mthca_next_seg *) prev_wqe)->nda_op =
  1469. cpu_to_be32((ind << qp->rq.wqe_shift) | 1);
  1470. wmb();
  1471. ((struct mthca_next_seg *) prev_wqe)->ee_nds =
  1472. cpu_to_be32(MTHCA_NEXT_DBD | size);
  1473. if (!size0)
  1474. size0 = size;
  1475. ++ind;
  1476. if (unlikely(ind >= qp->rq.max))
  1477. ind -= qp->rq.max;
  1478. }
  1479. out:
  1480. if (likely(nreq)) {
  1481. __be32 doorbell[2];
  1482. doorbell[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);
  1483. doorbell[1] = cpu_to_be32((qp->qpn << 8) | nreq);
  1484. wmb();
  1485. mthca_write64(doorbell,
  1486. dev->kar + MTHCA_RECEIVE_DOORBELL,
  1487. MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
  1488. }
  1489. qp->rq.next_ind = ind;
  1490. qp->rq.head += nreq;
  1491. spin_unlock_irqrestore(&qp->rq.lock, flags);
  1492. return err;
  1493. }
  1494. int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  1495. struct ib_send_wr **bad_wr)
  1496. {
  1497. struct mthca_dev *dev = to_mdev(ibqp->device);
  1498. struct mthca_qp *qp = to_mqp(ibqp);
  1499. void *wqe;
  1500. void *prev_wqe;
  1501. unsigned long flags;
  1502. int err = 0;
  1503. int nreq;
  1504. int i;
  1505. int size;
  1506. int size0 = 0;
  1507. u32 f0 = 0;
  1508. int ind;
  1509. u8 op0 = 0;
  1510. spin_lock_irqsave(&qp->sq.lock, flags);
  1511. /* XXX check that state is OK to post send */
  1512. ind = qp->sq.head & (qp->sq.max - 1);
  1513. for (nreq = 0; wr; ++nreq, wr = wr->next) {
  1514. if (mthca_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq)) {
  1515. mthca_err(dev, "SQ %06x full (%u head, %u tail,"
  1516. " %d max, %d nreq)\n", qp->qpn,
  1517. qp->sq.head, qp->sq.tail,
  1518. qp->sq.max, nreq);
  1519. err = -ENOMEM;
  1520. *bad_wr = wr;
  1521. goto out;
  1522. }
  1523. wqe = get_send_wqe(qp, ind);
  1524. prev_wqe = qp->sq.last;
  1525. qp->sq.last = wqe;
  1526. ((struct mthca_next_seg *) wqe)->flags =
  1527. ((wr->send_flags & IB_SEND_SIGNALED) ?
  1528. cpu_to_be32(MTHCA_NEXT_CQ_UPDATE) : 0) |
  1529. ((wr->send_flags & IB_SEND_SOLICITED) ?
  1530. cpu_to_be32(MTHCA_NEXT_SOLICIT) : 0) |
  1531. cpu_to_be32(1);
  1532. if (wr->opcode == IB_WR_SEND_WITH_IMM ||
  1533. wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM)
  1534. ((struct mthca_next_seg *) wqe)->imm = wr->imm_data;
  1535. wqe += sizeof (struct mthca_next_seg);
  1536. size = sizeof (struct mthca_next_seg) / 16;
  1537. switch (qp->transport) {
  1538. case RC:
  1539. switch (wr->opcode) {
  1540. case IB_WR_ATOMIC_CMP_AND_SWP:
  1541. case IB_WR_ATOMIC_FETCH_AND_ADD:
  1542. ((struct mthca_raddr_seg *) wqe)->raddr =
  1543. cpu_to_be64(wr->wr.atomic.remote_addr);
  1544. ((struct mthca_raddr_seg *) wqe)->rkey =
  1545. cpu_to_be32(wr->wr.atomic.rkey);
  1546. ((struct mthca_raddr_seg *) wqe)->reserved = 0;
  1547. wqe += sizeof (struct mthca_raddr_seg);
  1548. if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
  1549. ((struct mthca_atomic_seg *) wqe)->swap_add =
  1550. cpu_to_be64(wr->wr.atomic.swap);
  1551. ((struct mthca_atomic_seg *) wqe)->compare =
  1552. cpu_to_be64(wr->wr.atomic.compare_add);
  1553. } else {
  1554. ((struct mthca_atomic_seg *) wqe)->swap_add =
  1555. cpu_to_be64(wr->wr.atomic.compare_add);
  1556. ((struct mthca_atomic_seg *) wqe)->compare = 0;
  1557. }
  1558. wqe += sizeof (struct mthca_atomic_seg);
  1559. size += sizeof (struct mthca_raddr_seg) / 16 +
  1560. sizeof (struct mthca_atomic_seg);
  1561. break;
  1562. case IB_WR_RDMA_READ:
  1563. case IB_WR_RDMA_WRITE:
  1564. case IB_WR_RDMA_WRITE_WITH_IMM:
  1565. ((struct mthca_raddr_seg *) wqe)->raddr =
  1566. cpu_to_be64(wr->wr.rdma.remote_addr);
  1567. ((struct mthca_raddr_seg *) wqe)->rkey =
  1568. cpu_to_be32(wr->wr.rdma.rkey);
  1569. ((struct mthca_raddr_seg *) wqe)->reserved = 0;
  1570. wqe += sizeof (struct mthca_raddr_seg);
  1571. size += sizeof (struct mthca_raddr_seg) / 16;
  1572. break;
  1573. default:
  1574. /* No extra segments required for sends */
  1575. break;
  1576. }
  1577. break;
  1578. case UC:
  1579. switch (wr->opcode) {
  1580. case IB_WR_RDMA_WRITE:
  1581. case IB_WR_RDMA_WRITE_WITH_IMM:
  1582. ((struct mthca_raddr_seg *) wqe)->raddr =
  1583. cpu_to_be64(wr->wr.rdma.remote_addr);
  1584. ((struct mthca_raddr_seg *) wqe)->rkey =
  1585. cpu_to_be32(wr->wr.rdma.rkey);
  1586. ((struct mthca_raddr_seg *) wqe)->reserved = 0;
  1587. wqe += sizeof (struct mthca_raddr_seg);
  1588. size += sizeof (struct mthca_raddr_seg) / 16;
  1589. break;
  1590. default:
  1591. /* No extra segments required for sends */
  1592. break;
  1593. }
  1594. break;
  1595. case UD:
  1596. memcpy(((struct mthca_arbel_ud_seg *) wqe)->av,
  1597. to_mah(wr->wr.ud.ah)->av, MTHCA_AV_SIZE);
  1598. ((struct mthca_arbel_ud_seg *) wqe)->dqpn =
  1599. cpu_to_be32(wr->wr.ud.remote_qpn);
  1600. ((struct mthca_arbel_ud_seg *) wqe)->qkey =
  1601. cpu_to_be32(wr->wr.ud.remote_qkey);
  1602. wqe += sizeof (struct mthca_arbel_ud_seg);
  1603. size += sizeof (struct mthca_arbel_ud_seg) / 16;
  1604. break;
  1605. case MLX:
  1606. err = build_mlx_header(dev, to_msqp(qp), ind, wr,
  1607. wqe - sizeof (struct mthca_next_seg),
  1608. wqe);
  1609. if (err) {
  1610. *bad_wr = wr;
  1611. goto out;
  1612. }
  1613. wqe += sizeof (struct mthca_data_seg);
  1614. size += sizeof (struct mthca_data_seg) / 16;
  1615. break;
  1616. }
  1617. if (wr->num_sge > qp->sq.max_gs) {
  1618. mthca_err(dev, "too many gathers\n");
  1619. err = -EINVAL;
  1620. *bad_wr = wr;
  1621. goto out;
  1622. }
  1623. for (i = 0; i < wr->num_sge; ++i) {
  1624. ((struct mthca_data_seg *) wqe)->byte_count =
  1625. cpu_to_be32(wr->sg_list[i].length);
  1626. ((struct mthca_data_seg *) wqe)->lkey =
  1627. cpu_to_be32(wr->sg_list[i].lkey);
  1628. ((struct mthca_data_seg *) wqe)->addr =
  1629. cpu_to_be64(wr->sg_list[i].addr);
  1630. wqe += sizeof (struct mthca_data_seg);
  1631. size += sizeof (struct mthca_data_seg) / 16;
  1632. }
  1633. /* Add one more inline data segment for ICRC */
  1634. if (qp->transport == MLX) {
  1635. ((struct mthca_data_seg *) wqe)->byte_count =
  1636. cpu_to_be32((1 << 31) | 4);
  1637. ((u32 *) wqe)[1] = 0;
  1638. wqe += sizeof (struct mthca_data_seg);
  1639. size += sizeof (struct mthca_data_seg) / 16;
  1640. }
  1641. qp->wrid[ind + qp->rq.max] = wr->wr_id;
  1642. if (wr->opcode >= ARRAY_SIZE(mthca_opcode)) {
  1643. mthca_err(dev, "opcode invalid\n");
  1644. err = -EINVAL;
  1645. *bad_wr = wr;
  1646. goto out;
  1647. }
  1648. ((struct mthca_next_seg *) prev_wqe)->nda_op =
  1649. cpu_to_be32(((ind << qp->sq.wqe_shift) +
  1650. qp->send_wqe_offset) |
  1651. mthca_opcode[wr->opcode]);
  1652. wmb();
  1653. ((struct mthca_next_seg *) prev_wqe)->ee_nds =
  1654. cpu_to_be32(MTHCA_NEXT_DBD | size);
  1655. if (!size0) {
  1656. size0 = size;
  1657. op0 = mthca_opcode[wr->opcode];
  1658. }
  1659. ++ind;
  1660. if (unlikely(ind >= qp->sq.max))
  1661. ind -= qp->sq.max;
  1662. }
  1663. out:
  1664. if (likely(nreq)) {
  1665. __be32 doorbell[2];
  1666. doorbell[0] = cpu_to_be32((nreq << 24) |
  1667. ((qp->sq.head & 0xffff) << 8) |
  1668. f0 | op0);
  1669. doorbell[1] = cpu_to_be32((qp->qpn << 8) | size0);
  1670. qp->sq.head += nreq;
  1671. /*
  1672. * Make sure that descriptors are written before
  1673. * doorbell record.
  1674. */
  1675. wmb();
  1676. *qp->sq.db = cpu_to_be32(qp->sq.head & 0xffff);
  1677. /*
  1678. * Make sure doorbell record is written before we
  1679. * write MMIO send doorbell.
  1680. */
  1681. wmb();
  1682. mthca_write64(doorbell,
  1683. dev->kar + MTHCA_SEND_DOORBELL,
  1684. MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
  1685. }
  1686. spin_unlock_irqrestore(&qp->sq.lock, flags);
  1687. return err;
  1688. }
  1689. int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  1690. struct ib_recv_wr **bad_wr)
  1691. {
  1692. struct mthca_dev *dev = to_mdev(ibqp->device);
  1693. struct mthca_qp *qp = to_mqp(ibqp);
  1694. unsigned long flags;
  1695. int err = 0;
  1696. int nreq;
  1697. int ind;
  1698. int i;
  1699. void *wqe;
  1700. spin_lock_irqsave(&qp->rq.lock, flags);
  1701. /* XXX check that state is OK to post receive */
  1702. ind = qp->rq.head & (qp->rq.max - 1);
  1703. for (nreq = 0; wr; ++nreq, wr = wr->next) {
  1704. if (mthca_wq_overflow(&qp->rq, nreq, qp->ibqp.recv_cq)) {
  1705. mthca_err(dev, "RQ %06x full (%u head, %u tail,"
  1706. " %d max, %d nreq)\n", qp->qpn,
  1707. qp->rq.head, qp->rq.tail,
  1708. qp->rq.max, nreq);
  1709. err = -ENOMEM;
  1710. *bad_wr = wr;
  1711. goto out;
  1712. }
  1713. wqe = get_recv_wqe(qp, ind);
  1714. ((struct mthca_next_seg *) wqe)->flags = 0;
  1715. wqe += sizeof (struct mthca_next_seg);
  1716. if (unlikely(wr->num_sge > qp->rq.max_gs)) {
  1717. err = -EINVAL;
  1718. *bad_wr = wr;
  1719. goto out;
  1720. }
  1721. for (i = 0; i < wr->num_sge; ++i) {
  1722. ((struct mthca_data_seg *) wqe)->byte_count =
  1723. cpu_to_be32(wr->sg_list[i].length);
  1724. ((struct mthca_data_seg *) wqe)->lkey =
  1725. cpu_to_be32(wr->sg_list[i].lkey);
  1726. ((struct mthca_data_seg *) wqe)->addr =
  1727. cpu_to_be64(wr->sg_list[i].addr);
  1728. wqe += sizeof (struct mthca_data_seg);
  1729. }
  1730. if (i < qp->rq.max_gs) {
  1731. ((struct mthca_data_seg *) wqe)->byte_count = 0;
  1732. ((struct mthca_data_seg *) wqe)->lkey = cpu_to_be32(MTHCA_INVAL_LKEY);
  1733. ((struct mthca_data_seg *) wqe)->addr = 0;
  1734. }
  1735. qp->wrid[ind] = wr->wr_id;
  1736. ++ind;
  1737. if (unlikely(ind >= qp->rq.max))
  1738. ind -= qp->rq.max;
  1739. }
  1740. out:
  1741. if (likely(nreq)) {
  1742. qp->rq.head += nreq;
  1743. /*
  1744. * Make sure that descriptors are written before
  1745. * doorbell record.
  1746. */
  1747. wmb();
  1748. *qp->rq.db = cpu_to_be32(qp->rq.head & 0xffff);
  1749. }
  1750. spin_unlock_irqrestore(&qp->rq.lock, flags);
  1751. return err;
  1752. }
  1753. int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
  1754. int index, int *dbd, __be32 *new_wqe)
  1755. {
  1756. struct mthca_next_seg *next;
  1757. /*
  1758. * For SRQs, all WQEs generate a CQE, so we're always at the
  1759. * end of the doorbell chain.
  1760. */
  1761. if (qp->ibqp.srq) {
  1762. *new_wqe = 0;
  1763. return 0;
  1764. }
  1765. if (is_send)
  1766. next = get_send_wqe(qp, index);
  1767. else
  1768. next = get_recv_wqe(qp, index);
  1769. *dbd = !!(next->ee_nds & cpu_to_be32(MTHCA_NEXT_DBD));
  1770. if (next->ee_nds & cpu_to_be32(0x3f))
  1771. *new_wqe = (next->nda_op & cpu_to_be32(~0x3f)) |
  1772. (next->ee_nds & cpu_to_be32(0x3f));
  1773. else
  1774. *new_wqe = 0;
  1775. return 0;
  1776. }
  1777. int __devinit mthca_init_qp_table(struct mthca_dev *dev)
  1778. {
  1779. int err;
  1780. u8 status;
  1781. int i;
  1782. spin_lock_init(&dev->qp_table.lock);
  1783. /*
  1784. * We reserve 2 extra QPs per port for the special QPs. The
  1785. * special QP for port 1 has to be even, so round up.
  1786. */
  1787. dev->qp_table.sqp_start = (dev->limits.reserved_qps + 1) & ~1UL;
  1788. err = mthca_alloc_init(&dev->qp_table.alloc,
  1789. dev->limits.num_qps,
  1790. (1 << 24) - 1,
  1791. dev->qp_table.sqp_start +
  1792. MTHCA_MAX_PORTS * 2);
  1793. if (err)
  1794. return err;
  1795. err = mthca_array_init(&dev->qp_table.qp,
  1796. dev->limits.num_qps);
  1797. if (err) {
  1798. mthca_alloc_cleanup(&dev->qp_table.alloc);
  1799. return err;
  1800. }
  1801. for (i = 0; i < 2; ++i) {
  1802. err = mthca_CONF_SPECIAL_QP(dev, i ? IB_QPT_GSI : IB_QPT_SMI,
  1803. dev->qp_table.sqp_start + i * 2,
  1804. &status);
  1805. if (err)
  1806. goto err_out;
  1807. if (status) {
  1808. mthca_warn(dev, "CONF_SPECIAL_QP returned "
  1809. "status %02x, aborting.\n",
  1810. status);
  1811. err = -EINVAL;
  1812. goto err_out;
  1813. }
  1814. }
  1815. return 0;
  1816. err_out:
  1817. for (i = 0; i < 2; ++i)
  1818. mthca_CONF_SPECIAL_QP(dev, i, 0, &status);
  1819. mthca_array_cleanup(&dev->qp_table.qp, dev->limits.num_qps);
  1820. mthca_alloc_cleanup(&dev->qp_table.alloc);
  1821. return err;
  1822. }
  1823. void __devexit mthca_cleanup_qp_table(struct mthca_dev *dev)
  1824. {
  1825. int i;
  1826. u8 status;
  1827. for (i = 0; i < 2; ++i)
  1828. mthca_CONF_SPECIAL_QP(dev, i, 0, &status);
  1829. mthca_array_cleanup(&dev->qp_table.qp, dev->limits.num_qps);
  1830. mthca_alloc_cleanup(&dev->qp_table.alloc);
  1831. }