mthca_qp.c 56 KB

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