mthca_cmd.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/completion.h>
  35. #include <linux/pci.h>
  36. #include <linux/errno.h>
  37. #include <linux/sched.h>
  38. #include <linux/module.h>
  39. #include <linux/slab.h>
  40. #include <asm/io.h>
  41. #include <rdma/ib_mad.h>
  42. #include "mthca_dev.h"
  43. #include "mthca_config_reg.h"
  44. #include "mthca_cmd.h"
  45. #include "mthca_memfree.h"
  46. #define CMD_POLL_TOKEN 0xffff
  47. enum {
  48. HCR_IN_PARAM_OFFSET = 0x00,
  49. HCR_IN_MODIFIER_OFFSET = 0x08,
  50. HCR_OUT_PARAM_OFFSET = 0x0c,
  51. HCR_TOKEN_OFFSET = 0x14,
  52. HCR_STATUS_OFFSET = 0x18,
  53. HCR_OPMOD_SHIFT = 12,
  54. HCA_E_BIT = 22,
  55. HCR_GO_BIT = 23
  56. };
  57. enum {
  58. /* initialization and general commands */
  59. CMD_SYS_EN = 0x1,
  60. CMD_SYS_DIS = 0x2,
  61. CMD_MAP_FA = 0xfff,
  62. CMD_UNMAP_FA = 0xffe,
  63. CMD_RUN_FW = 0xff6,
  64. CMD_MOD_STAT_CFG = 0x34,
  65. CMD_QUERY_DEV_LIM = 0x3,
  66. CMD_QUERY_FW = 0x4,
  67. CMD_ENABLE_LAM = 0xff8,
  68. CMD_DISABLE_LAM = 0xff7,
  69. CMD_QUERY_DDR = 0x5,
  70. CMD_QUERY_ADAPTER = 0x6,
  71. CMD_INIT_HCA = 0x7,
  72. CMD_CLOSE_HCA = 0x8,
  73. CMD_INIT_IB = 0x9,
  74. CMD_CLOSE_IB = 0xa,
  75. CMD_QUERY_HCA = 0xb,
  76. CMD_SET_IB = 0xc,
  77. CMD_ACCESS_DDR = 0x2e,
  78. CMD_MAP_ICM = 0xffa,
  79. CMD_UNMAP_ICM = 0xff9,
  80. CMD_MAP_ICM_AUX = 0xffc,
  81. CMD_UNMAP_ICM_AUX = 0xffb,
  82. CMD_SET_ICM_SIZE = 0xffd,
  83. /* TPT commands */
  84. CMD_SW2HW_MPT = 0xd,
  85. CMD_QUERY_MPT = 0xe,
  86. CMD_HW2SW_MPT = 0xf,
  87. CMD_READ_MTT = 0x10,
  88. CMD_WRITE_MTT = 0x11,
  89. CMD_SYNC_TPT = 0x2f,
  90. /* EQ commands */
  91. CMD_MAP_EQ = 0x12,
  92. CMD_SW2HW_EQ = 0x13,
  93. CMD_HW2SW_EQ = 0x14,
  94. CMD_QUERY_EQ = 0x15,
  95. /* CQ commands */
  96. CMD_SW2HW_CQ = 0x16,
  97. CMD_HW2SW_CQ = 0x17,
  98. CMD_QUERY_CQ = 0x18,
  99. CMD_RESIZE_CQ = 0x2c,
  100. /* SRQ commands */
  101. CMD_SW2HW_SRQ = 0x35,
  102. CMD_HW2SW_SRQ = 0x36,
  103. CMD_QUERY_SRQ = 0x37,
  104. CMD_ARM_SRQ = 0x40,
  105. /* QP/EE commands */
  106. CMD_RST2INIT_QPEE = 0x19,
  107. CMD_INIT2RTR_QPEE = 0x1a,
  108. CMD_RTR2RTS_QPEE = 0x1b,
  109. CMD_RTS2RTS_QPEE = 0x1c,
  110. CMD_SQERR2RTS_QPEE = 0x1d,
  111. CMD_2ERR_QPEE = 0x1e,
  112. CMD_RTS2SQD_QPEE = 0x1f,
  113. CMD_SQD2SQD_QPEE = 0x38,
  114. CMD_SQD2RTS_QPEE = 0x20,
  115. CMD_ERR2RST_QPEE = 0x21,
  116. CMD_QUERY_QPEE = 0x22,
  117. CMD_INIT2INIT_QPEE = 0x2d,
  118. CMD_SUSPEND_QPEE = 0x32,
  119. CMD_UNSUSPEND_QPEE = 0x33,
  120. /* special QPs and management commands */
  121. CMD_CONF_SPECIAL_QP = 0x23,
  122. CMD_MAD_IFC = 0x24,
  123. /* multicast commands */
  124. CMD_READ_MGM = 0x25,
  125. CMD_WRITE_MGM = 0x26,
  126. CMD_MGID_HASH = 0x27,
  127. /* miscellaneous commands */
  128. CMD_DIAG_RPRT = 0x30,
  129. CMD_NOP = 0x31,
  130. /* debug commands */
  131. CMD_QUERY_DEBUG_MSG = 0x2a,
  132. CMD_SET_DEBUG_MSG = 0x2b,
  133. };
  134. /*
  135. * According to Mellanox code, FW may be starved and never complete
  136. * commands. So we can't use strict timeouts described in PRM -- we
  137. * just arbitrarily select 60 seconds for now.
  138. */
  139. #if 0
  140. /*
  141. * Round up and add 1 to make sure we get the full wait time (since we
  142. * will be starting in the middle of a jiffy)
  143. */
  144. enum {
  145. CMD_TIME_CLASS_A = (HZ + 999) / 1000 + 1,
  146. CMD_TIME_CLASS_B = (HZ + 99) / 100 + 1,
  147. CMD_TIME_CLASS_C = (HZ + 9) / 10 + 1,
  148. CMD_TIME_CLASS_D = 60 * HZ
  149. };
  150. #else
  151. enum {
  152. CMD_TIME_CLASS_A = 60 * HZ,
  153. CMD_TIME_CLASS_B = 60 * HZ,
  154. CMD_TIME_CLASS_C = 60 * HZ,
  155. CMD_TIME_CLASS_D = 60 * HZ
  156. };
  157. #endif
  158. enum {
  159. GO_BIT_TIMEOUT = HZ * 10
  160. };
  161. struct mthca_cmd_context {
  162. struct completion done;
  163. int result;
  164. int next;
  165. u64 out_param;
  166. u16 token;
  167. u8 status;
  168. };
  169. static int fw_cmd_doorbell = 0;
  170. module_param(fw_cmd_doorbell, int, 0644);
  171. MODULE_PARM_DESC(fw_cmd_doorbell, "post FW commands through doorbell page if nonzero "
  172. "(and supported by FW)");
  173. static inline int go_bit(struct mthca_dev *dev)
  174. {
  175. return readl(dev->hcr + HCR_STATUS_OFFSET) &
  176. swab32(1 << HCR_GO_BIT);
  177. }
  178. static void mthca_cmd_post_dbell(struct mthca_dev *dev,
  179. u64 in_param,
  180. u64 out_param,
  181. u32 in_modifier,
  182. u8 op_modifier,
  183. u16 op,
  184. u16 token)
  185. {
  186. void __iomem *ptr = dev->cmd.dbell_map;
  187. u16 *offs = dev->cmd.dbell_offsets;
  188. __raw_writel((__force u32) cpu_to_be32(in_param >> 32), ptr + offs[0]);
  189. wmb();
  190. __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), ptr + offs[1]);
  191. wmb();
  192. __raw_writel((__force u32) cpu_to_be32(in_modifier), ptr + offs[2]);
  193. wmb();
  194. __raw_writel((__force u32) cpu_to_be32(out_param >> 32), ptr + offs[3]);
  195. wmb();
  196. __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), ptr + offs[4]);
  197. wmb();
  198. __raw_writel((__force u32) cpu_to_be32(token << 16), ptr + offs[5]);
  199. wmb();
  200. __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
  201. (1 << HCA_E_BIT) |
  202. (op_modifier << HCR_OPMOD_SHIFT) |
  203. op), ptr + offs[6]);
  204. wmb();
  205. __raw_writel((__force u32) 0, ptr + offs[7]);
  206. wmb();
  207. }
  208. static int mthca_cmd_post_hcr(struct mthca_dev *dev,
  209. u64 in_param,
  210. u64 out_param,
  211. u32 in_modifier,
  212. u8 op_modifier,
  213. u16 op,
  214. u16 token,
  215. int event)
  216. {
  217. if (event) {
  218. unsigned long end = jiffies + GO_BIT_TIMEOUT;
  219. while (go_bit(dev) && time_before(jiffies, end)) {
  220. set_current_state(TASK_RUNNING);
  221. schedule();
  222. }
  223. }
  224. if (go_bit(dev))
  225. return -EAGAIN;
  226. /*
  227. * We use writel (instead of something like memcpy_toio)
  228. * because writes of less than 32 bits to the HCR don't work
  229. * (and some architectures such as ia64 implement memcpy_toio
  230. * in terms of writeb).
  231. */
  232. __raw_writel((__force u32) cpu_to_be32(in_param >> 32), dev->hcr + 0 * 4);
  233. __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), dev->hcr + 1 * 4);
  234. __raw_writel((__force u32) cpu_to_be32(in_modifier), dev->hcr + 2 * 4);
  235. __raw_writel((__force u32) cpu_to_be32(out_param >> 32), dev->hcr + 3 * 4);
  236. __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), dev->hcr + 4 * 4);
  237. __raw_writel((__force u32) cpu_to_be32(token << 16), dev->hcr + 5 * 4);
  238. /* __raw_writel may not order writes. */
  239. wmb();
  240. __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
  241. (event ? (1 << HCA_E_BIT) : 0) |
  242. (op_modifier << HCR_OPMOD_SHIFT) |
  243. op), dev->hcr + 6 * 4);
  244. return 0;
  245. }
  246. static int mthca_cmd_post(struct mthca_dev *dev,
  247. u64 in_param,
  248. u64 out_param,
  249. u32 in_modifier,
  250. u8 op_modifier,
  251. u16 op,
  252. u16 token,
  253. int event)
  254. {
  255. int err = 0;
  256. mutex_lock(&dev->cmd.hcr_mutex);
  257. if (event && dev->cmd.flags & MTHCA_CMD_POST_DOORBELLS && fw_cmd_doorbell)
  258. mthca_cmd_post_dbell(dev, in_param, out_param, in_modifier,
  259. op_modifier, op, token);
  260. else
  261. err = mthca_cmd_post_hcr(dev, in_param, out_param, in_modifier,
  262. op_modifier, op, token, event);
  263. /*
  264. * Make sure that our HCR writes don't get mixed in with
  265. * writes from another CPU starting a FW command.
  266. */
  267. mmiowb();
  268. mutex_unlock(&dev->cmd.hcr_mutex);
  269. return err;
  270. }
  271. static int mthca_status_to_errno(u8 status)
  272. {
  273. static const int trans_table[] = {
  274. [MTHCA_CMD_STAT_INTERNAL_ERR] = -EIO,
  275. [MTHCA_CMD_STAT_BAD_OP] = -EPERM,
  276. [MTHCA_CMD_STAT_BAD_PARAM] = -EINVAL,
  277. [MTHCA_CMD_STAT_BAD_SYS_STATE] = -ENXIO,
  278. [MTHCA_CMD_STAT_BAD_RESOURCE] = -EBADF,
  279. [MTHCA_CMD_STAT_RESOURCE_BUSY] = -EBUSY,
  280. [MTHCA_CMD_STAT_DDR_MEM_ERR] = -ENOMEM,
  281. [MTHCA_CMD_STAT_EXCEED_LIM] = -ENOMEM,
  282. [MTHCA_CMD_STAT_BAD_RES_STATE] = -EBADF,
  283. [MTHCA_CMD_STAT_BAD_INDEX] = -EBADF,
  284. [MTHCA_CMD_STAT_BAD_NVMEM] = -EFAULT,
  285. [MTHCA_CMD_STAT_BAD_QPEE_STATE] = -EINVAL,
  286. [MTHCA_CMD_STAT_BAD_SEG_PARAM] = -EFAULT,
  287. [MTHCA_CMD_STAT_REG_BOUND] = -EBUSY,
  288. [MTHCA_CMD_STAT_LAM_NOT_PRE] = -EAGAIN,
  289. [MTHCA_CMD_STAT_BAD_PKT] = -EBADMSG,
  290. [MTHCA_CMD_STAT_BAD_SIZE] = -ENOMEM,
  291. };
  292. if (status >= ARRAY_SIZE(trans_table) ||
  293. (status != MTHCA_CMD_STAT_OK
  294. && trans_table[status] == 0))
  295. return -EINVAL;
  296. return trans_table[status];
  297. }
  298. static int mthca_cmd_poll(struct mthca_dev *dev,
  299. u64 in_param,
  300. u64 *out_param,
  301. int out_is_imm,
  302. u32 in_modifier,
  303. u8 op_modifier,
  304. u16 op,
  305. unsigned long timeout)
  306. {
  307. int err = 0;
  308. unsigned long end;
  309. u8 status;
  310. down(&dev->cmd.poll_sem);
  311. err = mthca_cmd_post(dev, in_param,
  312. out_param ? *out_param : 0,
  313. in_modifier, op_modifier,
  314. op, CMD_POLL_TOKEN, 0);
  315. if (err)
  316. goto out;
  317. end = timeout + jiffies;
  318. while (go_bit(dev) && time_before(jiffies, end)) {
  319. set_current_state(TASK_RUNNING);
  320. schedule();
  321. }
  322. if (go_bit(dev)) {
  323. err = -EBUSY;
  324. goto out;
  325. }
  326. if (out_is_imm)
  327. *out_param =
  328. (u64) be32_to_cpu((__force __be32)
  329. __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET)) << 32 |
  330. (u64) be32_to_cpu((__force __be32)
  331. __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET + 4));
  332. status = be32_to_cpu((__force __be32) __raw_readl(dev->hcr + HCR_STATUS_OFFSET)) >> 24;
  333. if (status) {
  334. mthca_dbg(dev, "Command %02x completed with status %02x\n",
  335. op, status);
  336. err = mthca_status_to_errno(status);
  337. }
  338. out:
  339. up(&dev->cmd.poll_sem);
  340. return err;
  341. }
  342. void mthca_cmd_event(struct mthca_dev *dev,
  343. u16 token,
  344. u8 status,
  345. u64 out_param)
  346. {
  347. struct mthca_cmd_context *context =
  348. &dev->cmd.context[token & dev->cmd.token_mask];
  349. /* previously timed out command completing at long last */
  350. if (token != context->token)
  351. return;
  352. context->result = 0;
  353. context->status = status;
  354. context->out_param = out_param;
  355. complete(&context->done);
  356. }
  357. static int mthca_cmd_wait(struct mthca_dev *dev,
  358. u64 in_param,
  359. u64 *out_param,
  360. int out_is_imm,
  361. u32 in_modifier,
  362. u8 op_modifier,
  363. u16 op,
  364. unsigned long timeout)
  365. {
  366. int err = 0;
  367. struct mthca_cmd_context *context;
  368. down(&dev->cmd.event_sem);
  369. spin_lock(&dev->cmd.context_lock);
  370. BUG_ON(dev->cmd.free_head < 0);
  371. context = &dev->cmd.context[dev->cmd.free_head];
  372. context->token += dev->cmd.token_mask + 1;
  373. dev->cmd.free_head = context->next;
  374. spin_unlock(&dev->cmd.context_lock);
  375. init_completion(&context->done);
  376. err = mthca_cmd_post(dev, in_param,
  377. out_param ? *out_param : 0,
  378. in_modifier, op_modifier,
  379. op, context->token, 1);
  380. if (err)
  381. goto out;
  382. if (!wait_for_completion_timeout(&context->done, timeout)) {
  383. err = -EBUSY;
  384. goto out;
  385. }
  386. err = context->result;
  387. if (err)
  388. goto out;
  389. if (context->status) {
  390. mthca_dbg(dev, "Command %02x completed with status %02x\n",
  391. op, context->status);
  392. err = mthca_status_to_errno(context->status);
  393. }
  394. if (out_is_imm)
  395. *out_param = context->out_param;
  396. out:
  397. spin_lock(&dev->cmd.context_lock);
  398. context->next = dev->cmd.free_head;
  399. dev->cmd.free_head = context - dev->cmd.context;
  400. spin_unlock(&dev->cmd.context_lock);
  401. up(&dev->cmd.event_sem);
  402. return err;
  403. }
  404. /* Invoke a command with an output mailbox */
  405. static int mthca_cmd_box(struct mthca_dev *dev,
  406. u64 in_param,
  407. u64 out_param,
  408. u32 in_modifier,
  409. u8 op_modifier,
  410. u16 op,
  411. unsigned long timeout)
  412. {
  413. if (dev->cmd.flags & MTHCA_CMD_USE_EVENTS)
  414. return mthca_cmd_wait(dev, in_param, &out_param, 0,
  415. in_modifier, op_modifier, op,
  416. timeout);
  417. else
  418. return mthca_cmd_poll(dev, in_param, &out_param, 0,
  419. in_modifier, op_modifier, op,
  420. timeout);
  421. }
  422. /* Invoke a command with no output parameter */
  423. static int mthca_cmd(struct mthca_dev *dev,
  424. u64 in_param,
  425. u32 in_modifier,
  426. u8 op_modifier,
  427. u16 op,
  428. unsigned long timeout)
  429. {
  430. return mthca_cmd_box(dev, in_param, 0, in_modifier,
  431. op_modifier, op, timeout);
  432. }
  433. /*
  434. * Invoke a command with an immediate output parameter (and copy the
  435. * output into the caller's out_param pointer after the command
  436. * executes).
  437. */
  438. static int mthca_cmd_imm(struct mthca_dev *dev,
  439. u64 in_param,
  440. u64 *out_param,
  441. u32 in_modifier,
  442. u8 op_modifier,
  443. u16 op,
  444. unsigned long timeout)
  445. {
  446. if (dev->cmd.flags & MTHCA_CMD_USE_EVENTS)
  447. return mthca_cmd_wait(dev, in_param, out_param, 1,
  448. in_modifier, op_modifier, op,
  449. timeout);
  450. else
  451. return mthca_cmd_poll(dev, in_param, out_param, 1,
  452. in_modifier, op_modifier, op,
  453. timeout);
  454. }
  455. int mthca_cmd_init(struct mthca_dev *dev)
  456. {
  457. mutex_init(&dev->cmd.hcr_mutex);
  458. sema_init(&dev->cmd.poll_sem, 1);
  459. dev->cmd.flags = 0;
  460. dev->hcr = ioremap(pci_resource_start(dev->pdev, 0) + MTHCA_HCR_BASE,
  461. MTHCA_HCR_SIZE);
  462. if (!dev->hcr) {
  463. mthca_err(dev, "Couldn't map command register.");
  464. return -ENOMEM;
  465. }
  466. dev->cmd.pool = pci_pool_create("mthca_cmd", dev->pdev,
  467. MTHCA_MAILBOX_SIZE,
  468. MTHCA_MAILBOX_SIZE, 0);
  469. if (!dev->cmd.pool) {
  470. iounmap(dev->hcr);
  471. return -ENOMEM;
  472. }
  473. return 0;
  474. }
  475. void mthca_cmd_cleanup(struct mthca_dev *dev)
  476. {
  477. pci_pool_destroy(dev->cmd.pool);
  478. iounmap(dev->hcr);
  479. if (dev->cmd.flags & MTHCA_CMD_POST_DOORBELLS)
  480. iounmap(dev->cmd.dbell_map);
  481. }
  482. /*
  483. * Switch to using events to issue FW commands (should be called after
  484. * event queue to command events has been initialized).
  485. */
  486. int mthca_cmd_use_events(struct mthca_dev *dev)
  487. {
  488. int i;
  489. dev->cmd.context = kmalloc(dev->cmd.max_cmds *
  490. sizeof (struct mthca_cmd_context),
  491. GFP_KERNEL);
  492. if (!dev->cmd.context)
  493. return -ENOMEM;
  494. for (i = 0; i < dev->cmd.max_cmds; ++i) {
  495. dev->cmd.context[i].token = i;
  496. dev->cmd.context[i].next = i + 1;
  497. }
  498. dev->cmd.context[dev->cmd.max_cmds - 1].next = -1;
  499. dev->cmd.free_head = 0;
  500. sema_init(&dev->cmd.event_sem, dev->cmd.max_cmds);
  501. spin_lock_init(&dev->cmd.context_lock);
  502. for (dev->cmd.token_mask = 1;
  503. dev->cmd.token_mask < dev->cmd.max_cmds;
  504. dev->cmd.token_mask <<= 1)
  505. ; /* nothing */
  506. --dev->cmd.token_mask;
  507. dev->cmd.flags |= MTHCA_CMD_USE_EVENTS;
  508. down(&dev->cmd.poll_sem);
  509. return 0;
  510. }
  511. /*
  512. * Switch back to polling (used when shutting down the device)
  513. */
  514. void mthca_cmd_use_polling(struct mthca_dev *dev)
  515. {
  516. int i;
  517. dev->cmd.flags &= ~MTHCA_CMD_USE_EVENTS;
  518. for (i = 0; i < dev->cmd.max_cmds; ++i)
  519. down(&dev->cmd.event_sem);
  520. kfree(dev->cmd.context);
  521. up(&dev->cmd.poll_sem);
  522. }
  523. struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
  524. gfp_t gfp_mask)
  525. {
  526. struct mthca_mailbox *mailbox;
  527. mailbox = kmalloc(sizeof *mailbox, gfp_mask);
  528. if (!mailbox)
  529. return ERR_PTR(-ENOMEM);
  530. mailbox->buf = pci_pool_alloc(dev->cmd.pool, gfp_mask, &mailbox->dma);
  531. if (!mailbox->buf) {
  532. kfree(mailbox);
  533. return ERR_PTR(-ENOMEM);
  534. }
  535. return mailbox;
  536. }
  537. void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox)
  538. {
  539. if (!mailbox)
  540. return;
  541. pci_pool_free(dev->cmd.pool, mailbox->buf, mailbox->dma);
  542. kfree(mailbox);
  543. }
  544. int mthca_SYS_EN(struct mthca_dev *dev)
  545. {
  546. u64 out;
  547. int ret;
  548. ret = mthca_cmd_imm(dev, 0, &out, 0, 0, CMD_SYS_EN, CMD_TIME_CLASS_D);
  549. if (ret == -ENOMEM)
  550. mthca_warn(dev, "SYS_EN DDR error: syn=%x, sock=%d, "
  551. "sladdr=%d, SPD source=%s\n",
  552. (int) (out >> 6) & 0xf, (int) (out >> 4) & 3,
  553. (int) (out >> 1) & 7, (int) out & 1 ? "NVMEM" : "DIMM");
  554. return ret;
  555. }
  556. int mthca_SYS_DIS(struct mthca_dev *dev)
  557. {
  558. return mthca_cmd(dev, 0, 0, 0, CMD_SYS_DIS, CMD_TIME_CLASS_C);
  559. }
  560. static int mthca_map_cmd(struct mthca_dev *dev, u16 op, struct mthca_icm *icm,
  561. u64 virt)
  562. {
  563. struct mthca_mailbox *mailbox;
  564. struct mthca_icm_iter iter;
  565. __be64 *pages;
  566. int lg;
  567. int nent = 0;
  568. int i;
  569. int err = 0;
  570. int ts = 0, tc = 0;
  571. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  572. if (IS_ERR(mailbox))
  573. return PTR_ERR(mailbox);
  574. memset(mailbox->buf, 0, MTHCA_MAILBOX_SIZE);
  575. pages = mailbox->buf;
  576. for (mthca_icm_first(icm, &iter);
  577. !mthca_icm_last(&iter);
  578. mthca_icm_next(&iter)) {
  579. /*
  580. * We have to pass pages that are aligned to their
  581. * size, so find the least significant 1 in the
  582. * address or size and use that as our log2 size.
  583. */
  584. lg = ffs(mthca_icm_addr(&iter) | mthca_icm_size(&iter)) - 1;
  585. if (lg < MTHCA_ICM_PAGE_SHIFT) {
  586. mthca_warn(dev, "Got FW area not aligned to %d (%llx/%lx).\n",
  587. MTHCA_ICM_PAGE_SIZE,
  588. (unsigned long long) mthca_icm_addr(&iter),
  589. mthca_icm_size(&iter));
  590. err = -EINVAL;
  591. goto out;
  592. }
  593. for (i = 0; i < mthca_icm_size(&iter) >> lg; ++i) {
  594. if (virt != -1) {
  595. pages[nent * 2] = cpu_to_be64(virt);
  596. virt += 1 << lg;
  597. }
  598. pages[nent * 2 + 1] =
  599. cpu_to_be64((mthca_icm_addr(&iter) + (i << lg)) |
  600. (lg - MTHCA_ICM_PAGE_SHIFT));
  601. ts += 1 << (lg - 10);
  602. ++tc;
  603. if (++nent == MTHCA_MAILBOX_SIZE / 16) {
  604. err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
  605. CMD_TIME_CLASS_B);
  606. if (err)
  607. goto out;
  608. nent = 0;
  609. }
  610. }
  611. }
  612. if (nent)
  613. err = mthca_cmd(dev, mailbox->dma, nent, 0, op,
  614. CMD_TIME_CLASS_B);
  615. switch (op) {
  616. case CMD_MAP_FA:
  617. mthca_dbg(dev, "Mapped %d chunks/%d KB for FW.\n", tc, ts);
  618. break;
  619. case CMD_MAP_ICM_AUX:
  620. mthca_dbg(dev, "Mapped %d chunks/%d KB for ICM aux.\n", tc, ts);
  621. break;
  622. case CMD_MAP_ICM:
  623. mthca_dbg(dev, "Mapped %d chunks/%d KB at %llx for ICM.\n",
  624. tc, ts, (unsigned long long) virt - (ts << 10));
  625. break;
  626. }
  627. out:
  628. mthca_free_mailbox(dev, mailbox);
  629. return err;
  630. }
  631. int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm)
  632. {
  633. return mthca_map_cmd(dev, CMD_MAP_FA, icm, -1);
  634. }
  635. int mthca_UNMAP_FA(struct mthca_dev *dev)
  636. {
  637. return mthca_cmd(dev, 0, 0, 0, CMD_UNMAP_FA, CMD_TIME_CLASS_B);
  638. }
  639. int mthca_RUN_FW(struct mthca_dev *dev)
  640. {
  641. return mthca_cmd(dev, 0, 0, 0, CMD_RUN_FW, CMD_TIME_CLASS_A);
  642. }
  643. static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
  644. {
  645. phys_addr_t addr;
  646. u16 max_off = 0;
  647. int i;
  648. for (i = 0; i < 8; ++i)
  649. max_off = max(max_off, dev->cmd.dbell_offsets[i]);
  650. if ((base & PAGE_MASK) != ((base + max_off) & PAGE_MASK)) {
  651. mthca_warn(dev, "Firmware doorbell region at 0x%016llx, "
  652. "length 0x%x crosses a page boundary\n",
  653. (unsigned long long) base, max_off);
  654. return;
  655. }
  656. addr = pci_resource_start(dev->pdev, 2) +
  657. ((pci_resource_len(dev->pdev, 2) - 1) & base);
  658. dev->cmd.dbell_map = ioremap(addr, max_off + sizeof(u32));
  659. if (!dev->cmd.dbell_map)
  660. return;
  661. dev->cmd.flags |= MTHCA_CMD_POST_DOORBELLS;
  662. mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
  663. }
  664. int mthca_QUERY_FW(struct mthca_dev *dev)
  665. {
  666. struct mthca_mailbox *mailbox;
  667. u32 *outbox;
  668. u64 base;
  669. u32 tmp;
  670. int err = 0;
  671. u8 lg;
  672. int i;
  673. #define QUERY_FW_OUT_SIZE 0x100
  674. #define QUERY_FW_VER_OFFSET 0x00
  675. #define QUERY_FW_MAX_CMD_OFFSET 0x0f
  676. #define QUERY_FW_ERR_START_OFFSET 0x30
  677. #define QUERY_FW_ERR_SIZE_OFFSET 0x38
  678. #define QUERY_FW_CMD_DB_EN_OFFSET 0x10
  679. #define QUERY_FW_CMD_DB_OFFSET 0x50
  680. #define QUERY_FW_CMD_DB_BASE 0x60
  681. #define QUERY_FW_START_OFFSET 0x20
  682. #define QUERY_FW_END_OFFSET 0x28
  683. #define QUERY_FW_SIZE_OFFSET 0x00
  684. #define QUERY_FW_CLR_INT_BASE_OFFSET 0x20
  685. #define QUERY_FW_EQ_ARM_BASE_OFFSET 0x40
  686. #define QUERY_FW_EQ_SET_CI_BASE_OFFSET 0x48
  687. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  688. if (IS_ERR(mailbox))
  689. return PTR_ERR(mailbox);
  690. outbox = mailbox->buf;
  691. err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_FW,
  692. CMD_TIME_CLASS_A);
  693. if (err)
  694. goto out;
  695. MTHCA_GET(dev->fw_ver, outbox, QUERY_FW_VER_OFFSET);
  696. /*
  697. * FW subminor version is at more significant bits than minor
  698. * version, so swap here.
  699. */
  700. dev->fw_ver = (dev->fw_ver & 0xffff00000000ull) |
  701. ((dev->fw_ver & 0xffff0000ull) >> 16) |
  702. ((dev->fw_ver & 0x0000ffffull) << 16);
  703. MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
  704. dev->cmd.max_cmds = 1 << lg;
  705. mthca_dbg(dev, "FW version %012llx, max commands %d\n",
  706. (unsigned long long) dev->fw_ver, dev->cmd.max_cmds);
  707. MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET);
  708. MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET);
  709. mthca_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x\n",
  710. (unsigned long long) dev->catas_err.addr, dev->catas_err.size);
  711. MTHCA_GET(tmp, outbox, QUERY_FW_CMD_DB_EN_OFFSET);
  712. if (tmp & 0x1) {
  713. mthca_dbg(dev, "FW supports commands through doorbells\n");
  714. MTHCA_GET(base, outbox, QUERY_FW_CMD_DB_BASE);
  715. for (i = 0; i < MTHCA_CMD_NUM_DBELL_DWORDS; ++i)
  716. MTHCA_GET(dev->cmd.dbell_offsets[i], outbox,
  717. QUERY_FW_CMD_DB_OFFSET + (i << 1));
  718. mthca_setup_cmd_doorbells(dev, base);
  719. }
  720. if (mthca_is_memfree(dev)) {
  721. MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
  722. MTHCA_GET(dev->fw.arbel.clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET);
  723. MTHCA_GET(dev->fw.arbel.eq_arm_base, outbox, QUERY_FW_EQ_ARM_BASE_OFFSET);
  724. MTHCA_GET(dev->fw.arbel.eq_set_ci_base, outbox, QUERY_FW_EQ_SET_CI_BASE_OFFSET);
  725. mthca_dbg(dev, "FW size %d KB\n", dev->fw.arbel.fw_pages << 2);
  726. /*
  727. * Round up number of system pages needed in case
  728. * MTHCA_ICM_PAGE_SIZE < PAGE_SIZE.
  729. */
  730. dev->fw.arbel.fw_pages =
  731. ALIGN(dev->fw.arbel.fw_pages, PAGE_SIZE / MTHCA_ICM_PAGE_SIZE) >>
  732. (PAGE_SHIFT - MTHCA_ICM_PAGE_SHIFT);
  733. mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n",
  734. (unsigned long long) dev->fw.arbel.clr_int_base,
  735. (unsigned long long) dev->fw.arbel.eq_arm_base,
  736. (unsigned long long) dev->fw.arbel.eq_set_ci_base);
  737. } else {
  738. MTHCA_GET(dev->fw.tavor.fw_start, outbox, QUERY_FW_START_OFFSET);
  739. MTHCA_GET(dev->fw.tavor.fw_end, outbox, QUERY_FW_END_OFFSET);
  740. mthca_dbg(dev, "FW size %d KB (start %llx, end %llx)\n",
  741. (int) ((dev->fw.tavor.fw_end - dev->fw.tavor.fw_start) >> 10),
  742. (unsigned long long) dev->fw.tavor.fw_start,
  743. (unsigned long long) dev->fw.tavor.fw_end);
  744. }
  745. out:
  746. mthca_free_mailbox(dev, mailbox);
  747. return err;
  748. }
  749. int mthca_ENABLE_LAM(struct mthca_dev *dev)
  750. {
  751. struct mthca_mailbox *mailbox;
  752. u8 info;
  753. u32 *outbox;
  754. int err = 0;
  755. #define ENABLE_LAM_OUT_SIZE 0x100
  756. #define ENABLE_LAM_START_OFFSET 0x00
  757. #define ENABLE_LAM_END_OFFSET 0x08
  758. #define ENABLE_LAM_INFO_OFFSET 0x13
  759. #define ENABLE_LAM_INFO_HIDDEN_FLAG (1 << 4)
  760. #define ENABLE_LAM_INFO_ECC_MASK 0x3
  761. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  762. if (IS_ERR(mailbox))
  763. return PTR_ERR(mailbox);
  764. outbox = mailbox->buf;
  765. err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_ENABLE_LAM,
  766. CMD_TIME_CLASS_C);
  767. if (err)
  768. goto out;
  769. MTHCA_GET(dev->ddr_start, outbox, ENABLE_LAM_START_OFFSET);
  770. MTHCA_GET(dev->ddr_end, outbox, ENABLE_LAM_END_OFFSET);
  771. MTHCA_GET(info, outbox, ENABLE_LAM_INFO_OFFSET);
  772. if (!!(info & ENABLE_LAM_INFO_HIDDEN_FLAG) !=
  773. !!(dev->mthca_flags & MTHCA_FLAG_DDR_HIDDEN)) {
  774. mthca_info(dev, "FW reports that HCA-attached memory "
  775. "is %s hidden; does not match PCI config\n",
  776. (info & ENABLE_LAM_INFO_HIDDEN_FLAG) ?
  777. "" : "not");
  778. }
  779. if (info & ENABLE_LAM_INFO_HIDDEN_FLAG)
  780. mthca_dbg(dev, "HCA-attached memory is hidden.\n");
  781. mthca_dbg(dev, "HCA memory size %d KB (start %llx, end %llx)\n",
  782. (int) ((dev->ddr_end - dev->ddr_start) >> 10),
  783. (unsigned long long) dev->ddr_start,
  784. (unsigned long long) dev->ddr_end);
  785. out:
  786. mthca_free_mailbox(dev, mailbox);
  787. return err;
  788. }
  789. int mthca_DISABLE_LAM(struct mthca_dev *dev)
  790. {
  791. return mthca_cmd(dev, 0, 0, 0, CMD_SYS_DIS, CMD_TIME_CLASS_C);
  792. }
  793. int mthca_QUERY_DDR(struct mthca_dev *dev)
  794. {
  795. struct mthca_mailbox *mailbox;
  796. u8 info;
  797. u32 *outbox;
  798. int err = 0;
  799. #define QUERY_DDR_OUT_SIZE 0x100
  800. #define QUERY_DDR_START_OFFSET 0x00
  801. #define QUERY_DDR_END_OFFSET 0x08
  802. #define QUERY_DDR_INFO_OFFSET 0x13
  803. #define QUERY_DDR_INFO_HIDDEN_FLAG (1 << 4)
  804. #define QUERY_DDR_INFO_ECC_MASK 0x3
  805. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  806. if (IS_ERR(mailbox))
  807. return PTR_ERR(mailbox);
  808. outbox = mailbox->buf;
  809. err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DDR,
  810. CMD_TIME_CLASS_A);
  811. if (err)
  812. goto out;
  813. MTHCA_GET(dev->ddr_start, outbox, QUERY_DDR_START_OFFSET);
  814. MTHCA_GET(dev->ddr_end, outbox, QUERY_DDR_END_OFFSET);
  815. MTHCA_GET(info, outbox, QUERY_DDR_INFO_OFFSET);
  816. if (!!(info & QUERY_DDR_INFO_HIDDEN_FLAG) !=
  817. !!(dev->mthca_flags & MTHCA_FLAG_DDR_HIDDEN)) {
  818. mthca_info(dev, "FW reports that HCA-attached memory "
  819. "is %s hidden; does not match PCI config\n",
  820. (info & QUERY_DDR_INFO_HIDDEN_FLAG) ?
  821. "" : "not");
  822. }
  823. if (info & QUERY_DDR_INFO_HIDDEN_FLAG)
  824. mthca_dbg(dev, "HCA-attached memory is hidden.\n");
  825. mthca_dbg(dev, "HCA memory size %d KB (start %llx, end %llx)\n",
  826. (int) ((dev->ddr_end - dev->ddr_start) >> 10),
  827. (unsigned long long) dev->ddr_start,
  828. (unsigned long long) dev->ddr_end);
  829. out:
  830. mthca_free_mailbox(dev, mailbox);
  831. return err;
  832. }
  833. int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
  834. struct mthca_dev_lim *dev_lim)
  835. {
  836. struct mthca_mailbox *mailbox;
  837. u32 *outbox;
  838. u8 field;
  839. u16 size;
  840. u16 stat_rate;
  841. int err;
  842. #define QUERY_DEV_LIM_OUT_SIZE 0x100
  843. #define QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET 0x10
  844. #define QUERY_DEV_LIM_MAX_QP_SZ_OFFSET 0x11
  845. #define QUERY_DEV_LIM_RSVD_QP_OFFSET 0x12
  846. #define QUERY_DEV_LIM_MAX_QP_OFFSET 0x13
  847. #define QUERY_DEV_LIM_RSVD_SRQ_OFFSET 0x14
  848. #define QUERY_DEV_LIM_MAX_SRQ_OFFSET 0x15
  849. #define QUERY_DEV_LIM_RSVD_EEC_OFFSET 0x16
  850. #define QUERY_DEV_LIM_MAX_EEC_OFFSET 0x17
  851. #define QUERY_DEV_LIM_MAX_CQ_SZ_OFFSET 0x19
  852. #define QUERY_DEV_LIM_RSVD_CQ_OFFSET 0x1a
  853. #define QUERY_DEV_LIM_MAX_CQ_OFFSET 0x1b
  854. #define QUERY_DEV_LIM_MAX_MPT_OFFSET 0x1d
  855. #define QUERY_DEV_LIM_RSVD_EQ_OFFSET 0x1e
  856. #define QUERY_DEV_LIM_MAX_EQ_OFFSET 0x1f
  857. #define QUERY_DEV_LIM_RSVD_MTT_OFFSET 0x20
  858. #define QUERY_DEV_LIM_MAX_MRW_SZ_OFFSET 0x21
  859. #define QUERY_DEV_LIM_RSVD_MRW_OFFSET 0x22
  860. #define QUERY_DEV_LIM_MAX_MTT_SEG_OFFSET 0x23
  861. #define QUERY_DEV_LIM_MAX_AV_OFFSET 0x27
  862. #define QUERY_DEV_LIM_MAX_REQ_QP_OFFSET 0x29
  863. #define QUERY_DEV_LIM_MAX_RES_QP_OFFSET 0x2b
  864. #define QUERY_DEV_LIM_MAX_RDMA_OFFSET 0x2f
  865. #define QUERY_DEV_LIM_RSZ_SRQ_OFFSET 0x33
  866. #define QUERY_DEV_LIM_ACK_DELAY_OFFSET 0x35
  867. #define QUERY_DEV_LIM_MTU_WIDTH_OFFSET 0x36
  868. #define QUERY_DEV_LIM_VL_PORT_OFFSET 0x37
  869. #define QUERY_DEV_LIM_MAX_GID_OFFSET 0x3b
  870. #define QUERY_DEV_LIM_RATE_SUPPORT_OFFSET 0x3c
  871. #define QUERY_DEV_LIM_MAX_PKEY_OFFSET 0x3f
  872. #define QUERY_DEV_LIM_FLAGS_OFFSET 0x44
  873. #define QUERY_DEV_LIM_RSVD_UAR_OFFSET 0x48
  874. #define QUERY_DEV_LIM_UAR_SZ_OFFSET 0x49
  875. #define QUERY_DEV_LIM_PAGE_SZ_OFFSET 0x4b
  876. #define QUERY_DEV_LIM_MAX_SG_OFFSET 0x51
  877. #define QUERY_DEV_LIM_MAX_DESC_SZ_OFFSET 0x52
  878. #define QUERY_DEV_LIM_MAX_SG_RQ_OFFSET 0x55
  879. #define QUERY_DEV_LIM_MAX_DESC_SZ_RQ_OFFSET 0x56
  880. #define QUERY_DEV_LIM_MAX_QP_MCG_OFFSET 0x61
  881. #define QUERY_DEV_LIM_RSVD_MCG_OFFSET 0x62
  882. #define QUERY_DEV_LIM_MAX_MCG_OFFSET 0x63
  883. #define QUERY_DEV_LIM_RSVD_PD_OFFSET 0x64
  884. #define QUERY_DEV_LIM_MAX_PD_OFFSET 0x65
  885. #define QUERY_DEV_LIM_RSVD_RDD_OFFSET 0x66
  886. #define QUERY_DEV_LIM_MAX_RDD_OFFSET 0x67
  887. #define QUERY_DEV_LIM_EEC_ENTRY_SZ_OFFSET 0x80
  888. #define QUERY_DEV_LIM_QPC_ENTRY_SZ_OFFSET 0x82
  889. #define QUERY_DEV_LIM_EEEC_ENTRY_SZ_OFFSET 0x84
  890. #define QUERY_DEV_LIM_EQPC_ENTRY_SZ_OFFSET 0x86
  891. #define QUERY_DEV_LIM_EQC_ENTRY_SZ_OFFSET 0x88
  892. #define QUERY_DEV_LIM_CQC_ENTRY_SZ_OFFSET 0x8a
  893. #define QUERY_DEV_LIM_SRQ_ENTRY_SZ_OFFSET 0x8c
  894. #define QUERY_DEV_LIM_UAR_ENTRY_SZ_OFFSET 0x8e
  895. #define QUERY_DEV_LIM_MTT_ENTRY_SZ_OFFSET 0x90
  896. #define QUERY_DEV_LIM_MPT_ENTRY_SZ_OFFSET 0x92
  897. #define QUERY_DEV_LIM_PBL_SZ_OFFSET 0x96
  898. #define QUERY_DEV_LIM_BMME_FLAGS_OFFSET 0x97
  899. #define QUERY_DEV_LIM_RSVD_LKEY_OFFSET 0x98
  900. #define QUERY_DEV_LIM_LAMR_OFFSET 0x9f
  901. #define QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET 0xa0
  902. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  903. if (IS_ERR(mailbox))
  904. return PTR_ERR(mailbox);
  905. outbox = mailbox->buf;
  906. err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_DEV_LIM,
  907. CMD_TIME_CLASS_A);
  908. if (err)
  909. goto out;
  910. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_QP_OFFSET);
  911. dev_lim->reserved_qps = 1 << (field & 0xf);
  912. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_OFFSET);
  913. dev_lim->max_qps = 1 << (field & 0x1f);
  914. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_SRQ_OFFSET);
  915. dev_lim->reserved_srqs = 1 << (field >> 4);
  916. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_OFFSET);
  917. dev_lim->max_srqs = 1 << (field & 0x1f);
  918. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_EEC_OFFSET);
  919. dev_lim->reserved_eecs = 1 << (field & 0xf);
  920. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_EEC_OFFSET);
  921. dev_lim->max_eecs = 1 << (field & 0x1f);
  922. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_CQ_SZ_OFFSET);
  923. dev_lim->max_cq_sz = 1 << field;
  924. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_CQ_OFFSET);
  925. dev_lim->reserved_cqs = 1 << (field & 0xf);
  926. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_CQ_OFFSET);
  927. dev_lim->max_cqs = 1 << (field & 0x1f);
  928. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MPT_OFFSET);
  929. dev_lim->max_mpts = 1 << (field & 0x3f);
  930. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_EQ_OFFSET);
  931. dev_lim->reserved_eqs = 1 << (field & 0xf);
  932. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_EQ_OFFSET);
  933. dev_lim->max_eqs = 1 << (field & 0x7);
  934. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MTT_OFFSET);
  935. if (mthca_is_memfree(dev))
  936. dev_lim->reserved_mtts = ALIGN((1 << (field >> 4)) * sizeof(u64),
  937. dev->limits.mtt_seg_size) / dev->limits.mtt_seg_size;
  938. else
  939. dev_lim->reserved_mtts = 1 << (field >> 4);
  940. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MRW_SZ_OFFSET);
  941. dev_lim->max_mrw_sz = 1 << field;
  942. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MRW_OFFSET);
  943. dev_lim->reserved_mrws = 1 << (field & 0xf);
  944. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MTT_SEG_OFFSET);
  945. dev_lim->max_mtt_seg = 1 << (field & 0x3f);
  946. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_REQ_QP_OFFSET);
  947. dev_lim->max_requester_per_qp = 1 << (field & 0x3f);
  948. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RES_QP_OFFSET);
  949. dev_lim->max_responder_per_qp = 1 << (field & 0x3f);
  950. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RDMA_OFFSET);
  951. dev_lim->max_rdma_global = 1 << (field & 0x3f);
  952. MTHCA_GET(field, outbox, QUERY_DEV_LIM_ACK_DELAY_OFFSET);
  953. dev_lim->local_ca_ack_delay = field & 0x1f;
  954. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MTU_WIDTH_OFFSET);
  955. dev_lim->max_mtu = field >> 4;
  956. dev_lim->max_port_width = field & 0xf;
  957. MTHCA_GET(field, outbox, QUERY_DEV_LIM_VL_PORT_OFFSET);
  958. dev_lim->max_vl = field >> 4;
  959. dev_lim->num_ports = field & 0xf;
  960. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_GID_OFFSET);
  961. dev_lim->max_gids = 1 << (field & 0xf);
  962. MTHCA_GET(stat_rate, outbox, QUERY_DEV_LIM_RATE_SUPPORT_OFFSET);
  963. dev_lim->stat_rate_support = stat_rate;
  964. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PKEY_OFFSET);
  965. dev_lim->max_pkeys = 1 << (field & 0xf);
  966. MTHCA_GET(dev_lim->flags, outbox, QUERY_DEV_LIM_FLAGS_OFFSET);
  967. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_UAR_OFFSET);
  968. dev_lim->reserved_uars = field >> 4;
  969. MTHCA_GET(field, outbox, QUERY_DEV_LIM_UAR_SZ_OFFSET);
  970. dev_lim->uar_size = 1 << ((field & 0x3f) + 20);
  971. MTHCA_GET(field, outbox, QUERY_DEV_LIM_PAGE_SZ_OFFSET);
  972. dev_lim->min_page_sz = 1 << field;
  973. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_OFFSET);
  974. dev_lim->max_sg = field;
  975. MTHCA_GET(size, outbox, QUERY_DEV_LIM_MAX_DESC_SZ_OFFSET);
  976. dev_lim->max_desc_sz = size;
  977. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_MCG_OFFSET);
  978. dev_lim->max_qp_per_mcg = 1 << field;
  979. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_MCG_OFFSET);
  980. dev_lim->reserved_mgms = field & 0xf;
  981. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_MCG_OFFSET);
  982. dev_lim->max_mcgs = 1 << field;
  983. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_PD_OFFSET);
  984. dev_lim->reserved_pds = field >> 4;
  985. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PD_OFFSET);
  986. dev_lim->max_pds = 1 << (field & 0x3f);
  987. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_RDD_OFFSET);
  988. dev_lim->reserved_rdds = field >> 4;
  989. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_RDD_OFFSET);
  990. dev_lim->max_rdds = 1 << (field & 0x3f);
  991. MTHCA_GET(size, outbox, QUERY_DEV_LIM_EEC_ENTRY_SZ_OFFSET);
  992. dev_lim->eec_entry_sz = size;
  993. MTHCA_GET(size, outbox, QUERY_DEV_LIM_QPC_ENTRY_SZ_OFFSET);
  994. dev_lim->qpc_entry_sz = size;
  995. MTHCA_GET(size, outbox, QUERY_DEV_LIM_EEEC_ENTRY_SZ_OFFSET);
  996. dev_lim->eeec_entry_sz = size;
  997. MTHCA_GET(size, outbox, QUERY_DEV_LIM_EQPC_ENTRY_SZ_OFFSET);
  998. dev_lim->eqpc_entry_sz = size;
  999. MTHCA_GET(size, outbox, QUERY_DEV_LIM_EQC_ENTRY_SZ_OFFSET);
  1000. dev_lim->eqc_entry_sz = size;
  1001. MTHCA_GET(size, outbox, QUERY_DEV_LIM_CQC_ENTRY_SZ_OFFSET);
  1002. dev_lim->cqc_entry_sz = size;
  1003. MTHCA_GET(size, outbox, QUERY_DEV_LIM_SRQ_ENTRY_SZ_OFFSET);
  1004. dev_lim->srq_entry_sz = size;
  1005. MTHCA_GET(size, outbox, QUERY_DEV_LIM_UAR_ENTRY_SZ_OFFSET);
  1006. dev_lim->uar_scratch_entry_sz = size;
  1007. if (mthca_is_memfree(dev)) {
  1008. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET);
  1009. dev_lim->max_srq_sz = 1 << field;
  1010. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET);
  1011. dev_lim->max_qp_sz = 1 << field;
  1012. MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSZ_SRQ_OFFSET);
  1013. dev_lim->hca.arbel.resize_srq = field & 1;
  1014. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_RQ_OFFSET);
  1015. dev_lim->max_sg = min_t(int, field, dev_lim->max_sg);
  1016. MTHCA_GET(size, outbox, QUERY_DEV_LIM_MAX_DESC_SZ_RQ_OFFSET);
  1017. dev_lim->max_desc_sz = min_t(int, size, dev_lim->max_desc_sz);
  1018. MTHCA_GET(size, outbox, QUERY_DEV_LIM_MPT_ENTRY_SZ_OFFSET);
  1019. dev_lim->mpt_entry_sz = size;
  1020. MTHCA_GET(field, outbox, QUERY_DEV_LIM_PBL_SZ_OFFSET);
  1021. dev_lim->hca.arbel.max_pbl_sz = 1 << (field & 0x3f);
  1022. MTHCA_GET(dev_lim->hca.arbel.bmme_flags, outbox,
  1023. QUERY_DEV_LIM_BMME_FLAGS_OFFSET);
  1024. MTHCA_GET(dev_lim->hca.arbel.reserved_lkey, outbox,
  1025. QUERY_DEV_LIM_RSVD_LKEY_OFFSET);
  1026. MTHCA_GET(field, outbox, QUERY_DEV_LIM_LAMR_OFFSET);
  1027. dev_lim->hca.arbel.lam_required = field & 1;
  1028. MTHCA_GET(dev_lim->hca.arbel.max_icm_sz, outbox,
  1029. QUERY_DEV_LIM_MAX_ICM_SZ_OFFSET);
  1030. if (dev_lim->hca.arbel.bmme_flags & 1)
  1031. mthca_dbg(dev, "Base MM extensions: yes "
  1032. "(flags %d, max PBL %d, rsvd L_Key %08x)\n",
  1033. dev_lim->hca.arbel.bmme_flags,
  1034. dev_lim->hca.arbel.max_pbl_sz,
  1035. dev_lim->hca.arbel.reserved_lkey);
  1036. else
  1037. mthca_dbg(dev, "Base MM extensions: no\n");
  1038. mthca_dbg(dev, "Max ICM size %lld MB\n",
  1039. (unsigned long long) dev_lim->hca.arbel.max_icm_sz >> 20);
  1040. } else {
  1041. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET);
  1042. dev_lim->max_srq_sz = (1 << field) - 1;
  1043. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET);
  1044. dev_lim->max_qp_sz = (1 << field) - 1;
  1045. MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_AV_OFFSET);
  1046. dev_lim->hca.tavor.max_avs = 1 << (field & 0x3f);
  1047. dev_lim->mpt_entry_sz = MTHCA_MPT_ENTRY_SIZE;
  1048. }
  1049. mthca_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n",
  1050. dev_lim->max_qps, dev_lim->reserved_qps, dev_lim->qpc_entry_sz);
  1051. mthca_dbg(dev, "Max SRQs: %d, reserved SRQs: %d, entry size: %d\n",
  1052. dev_lim->max_srqs, dev_lim->reserved_srqs, dev_lim->srq_entry_sz);
  1053. mthca_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n",
  1054. dev_lim->max_cqs, dev_lim->reserved_cqs, dev_lim->cqc_entry_sz);
  1055. mthca_dbg(dev, "Max EQs: %d, reserved EQs: %d, entry size: %d\n",
  1056. dev_lim->max_eqs, dev_lim->reserved_eqs, dev_lim->eqc_entry_sz);
  1057. mthca_dbg(dev, "reserved MPTs: %d, reserved MTTs: %d\n",
  1058. dev_lim->reserved_mrws, dev_lim->reserved_mtts);
  1059. mthca_dbg(dev, "Max PDs: %d, reserved PDs: %d, reserved UARs: %d\n",
  1060. dev_lim->max_pds, dev_lim->reserved_pds, dev_lim->reserved_uars);
  1061. mthca_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n",
  1062. dev_lim->max_pds, dev_lim->reserved_mgms);
  1063. mthca_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n",
  1064. dev_lim->max_cq_sz, dev_lim->max_qp_sz, dev_lim->max_srq_sz);
  1065. mthca_dbg(dev, "Flags: %08x\n", dev_lim->flags);
  1066. out:
  1067. mthca_free_mailbox(dev, mailbox);
  1068. return err;
  1069. }
  1070. static void get_board_id(void *vsd, char *board_id)
  1071. {
  1072. int i;
  1073. #define VSD_OFFSET_SIG1 0x00
  1074. #define VSD_OFFSET_SIG2 0xde
  1075. #define VSD_OFFSET_MLX_BOARD_ID 0xd0
  1076. #define VSD_OFFSET_TS_BOARD_ID 0x20
  1077. #define VSD_SIGNATURE_TOPSPIN 0x5ad
  1078. memset(board_id, 0, MTHCA_BOARD_ID_LEN);
  1079. if (be16_to_cpup(vsd + VSD_OFFSET_SIG1) == VSD_SIGNATURE_TOPSPIN &&
  1080. be16_to_cpup(vsd + VSD_OFFSET_SIG2) == VSD_SIGNATURE_TOPSPIN) {
  1081. strlcpy(board_id, vsd + VSD_OFFSET_TS_BOARD_ID, MTHCA_BOARD_ID_LEN);
  1082. } else {
  1083. /*
  1084. * The board ID is a string but the firmware byte
  1085. * swaps each 4-byte word before passing it back to
  1086. * us. Therefore we need to swab it before printing.
  1087. */
  1088. for (i = 0; i < 4; ++i)
  1089. ((u32 *) board_id)[i] =
  1090. swab32(*(u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4));
  1091. }
  1092. }
  1093. int mthca_QUERY_ADAPTER(struct mthca_dev *dev,
  1094. struct mthca_adapter *adapter)
  1095. {
  1096. struct mthca_mailbox *mailbox;
  1097. u32 *outbox;
  1098. int err;
  1099. #define QUERY_ADAPTER_OUT_SIZE 0x100
  1100. #define QUERY_ADAPTER_VENDOR_ID_OFFSET 0x00
  1101. #define QUERY_ADAPTER_DEVICE_ID_OFFSET 0x04
  1102. #define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08
  1103. #define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10
  1104. #define QUERY_ADAPTER_VSD_OFFSET 0x20
  1105. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1106. if (IS_ERR(mailbox))
  1107. return PTR_ERR(mailbox);
  1108. outbox = mailbox->buf;
  1109. err = mthca_cmd_box(dev, 0, mailbox->dma, 0, 0, CMD_QUERY_ADAPTER,
  1110. CMD_TIME_CLASS_A);
  1111. if (err)
  1112. goto out;
  1113. if (!mthca_is_memfree(dev)) {
  1114. MTHCA_GET(adapter->vendor_id, outbox,
  1115. QUERY_ADAPTER_VENDOR_ID_OFFSET);
  1116. MTHCA_GET(adapter->device_id, outbox,
  1117. QUERY_ADAPTER_DEVICE_ID_OFFSET);
  1118. MTHCA_GET(adapter->revision_id, outbox,
  1119. QUERY_ADAPTER_REVISION_ID_OFFSET);
  1120. }
  1121. MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);
  1122. get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4,
  1123. adapter->board_id);
  1124. out:
  1125. mthca_free_mailbox(dev, mailbox);
  1126. return err;
  1127. }
  1128. int mthca_INIT_HCA(struct mthca_dev *dev,
  1129. struct mthca_init_hca_param *param)
  1130. {
  1131. struct mthca_mailbox *mailbox;
  1132. __be32 *inbox;
  1133. int err;
  1134. #define INIT_HCA_IN_SIZE 0x200
  1135. #define INIT_HCA_FLAGS1_OFFSET 0x00c
  1136. #define INIT_HCA_FLAGS2_OFFSET 0x014
  1137. #define INIT_HCA_QPC_OFFSET 0x020
  1138. #define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10)
  1139. #define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17)
  1140. #define INIT_HCA_EEC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x20)
  1141. #define INIT_HCA_LOG_EEC_OFFSET (INIT_HCA_QPC_OFFSET + 0x27)
  1142. #define INIT_HCA_SRQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x28)
  1143. #define INIT_HCA_LOG_SRQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x2f)
  1144. #define INIT_HCA_CQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x30)
  1145. #define INIT_HCA_LOG_CQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x37)
  1146. #define INIT_HCA_EQPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x40)
  1147. #define INIT_HCA_EEEC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x50)
  1148. #define INIT_HCA_EQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x60)
  1149. #define INIT_HCA_LOG_EQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x67)
  1150. #define INIT_HCA_RDB_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x70)
  1151. #define INIT_HCA_UDAV_OFFSET 0x0b0
  1152. #define INIT_HCA_UDAV_LKEY_OFFSET (INIT_HCA_UDAV_OFFSET + 0x0)
  1153. #define INIT_HCA_UDAV_PD_OFFSET (INIT_HCA_UDAV_OFFSET + 0x4)
  1154. #define INIT_HCA_MCAST_OFFSET 0x0c0
  1155. #define INIT_HCA_MC_BASE_OFFSET (INIT_HCA_MCAST_OFFSET + 0x00)
  1156. #define INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12)
  1157. #define INIT_HCA_MC_HASH_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x16)
  1158. #define INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b)
  1159. #define INIT_HCA_TPT_OFFSET 0x0f0
  1160. #define INIT_HCA_MPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x00)
  1161. #define INIT_HCA_MTT_SEG_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x09)
  1162. #define INIT_HCA_LOG_MPT_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x0b)
  1163. #define INIT_HCA_MTT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x10)
  1164. #define INIT_HCA_UAR_OFFSET 0x120
  1165. #define INIT_HCA_UAR_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x00)
  1166. #define INIT_HCA_UARC_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x09)
  1167. #define INIT_HCA_LOG_UAR_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0a)
  1168. #define INIT_HCA_UAR_PAGE_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0b)
  1169. #define INIT_HCA_UAR_SCATCH_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x10)
  1170. #define INIT_HCA_UAR_CTX_BASE_OFFSET (INIT_HCA_UAR_OFFSET + 0x18)
  1171. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1172. if (IS_ERR(mailbox))
  1173. return PTR_ERR(mailbox);
  1174. inbox = mailbox->buf;
  1175. memset(inbox, 0, INIT_HCA_IN_SIZE);
  1176. if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
  1177. MTHCA_PUT(inbox, 0x1, INIT_HCA_FLAGS1_OFFSET);
  1178. #if defined(__LITTLE_ENDIAN)
  1179. *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) &= ~cpu_to_be32(1 << 1);
  1180. #elif defined(__BIG_ENDIAN)
  1181. *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(1 << 1);
  1182. #else
  1183. #error Host endianness not defined
  1184. #endif
  1185. /* Check port for UD address vector: */
  1186. *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(1);
  1187. /* Enable IPoIB checksumming if we can: */
  1188. if (dev->device_cap_flags & IB_DEVICE_UD_IP_CSUM)
  1189. *(inbox + INIT_HCA_FLAGS2_OFFSET / 4) |= cpu_to_be32(7 << 3);
  1190. /* We leave wqe_quota, responder_exu, etc as 0 (default) */
  1191. /* QPC/EEC/CQC/EQC/RDB attributes */
  1192. MTHCA_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET);
  1193. MTHCA_PUT(inbox, param->log_num_qps, INIT_HCA_LOG_QP_OFFSET);
  1194. MTHCA_PUT(inbox, param->eec_base, INIT_HCA_EEC_BASE_OFFSET);
  1195. MTHCA_PUT(inbox, param->log_num_eecs, INIT_HCA_LOG_EEC_OFFSET);
  1196. MTHCA_PUT(inbox, param->srqc_base, INIT_HCA_SRQC_BASE_OFFSET);
  1197. MTHCA_PUT(inbox, param->log_num_srqs, INIT_HCA_LOG_SRQ_OFFSET);
  1198. MTHCA_PUT(inbox, param->cqc_base, INIT_HCA_CQC_BASE_OFFSET);
  1199. MTHCA_PUT(inbox, param->log_num_cqs, INIT_HCA_LOG_CQ_OFFSET);
  1200. MTHCA_PUT(inbox, param->eqpc_base, INIT_HCA_EQPC_BASE_OFFSET);
  1201. MTHCA_PUT(inbox, param->eeec_base, INIT_HCA_EEEC_BASE_OFFSET);
  1202. MTHCA_PUT(inbox, param->eqc_base, INIT_HCA_EQC_BASE_OFFSET);
  1203. MTHCA_PUT(inbox, param->log_num_eqs, INIT_HCA_LOG_EQ_OFFSET);
  1204. MTHCA_PUT(inbox, param->rdb_base, INIT_HCA_RDB_BASE_OFFSET);
  1205. /* UD AV attributes */
  1206. /* multicast attributes */
  1207. MTHCA_PUT(inbox, param->mc_base, INIT_HCA_MC_BASE_OFFSET);
  1208. MTHCA_PUT(inbox, param->log_mc_entry_sz, INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET);
  1209. MTHCA_PUT(inbox, param->mc_hash_sz, INIT_HCA_MC_HASH_SZ_OFFSET);
  1210. MTHCA_PUT(inbox, param->log_mc_table_sz, INIT_HCA_LOG_MC_TABLE_SZ_OFFSET);
  1211. /* TPT attributes */
  1212. MTHCA_PUT(inbox, param->mpt_base, INIT_HCA_MPT_BASE_OFFSET);
  1213. if (!mthca_is_memfree(dev))
  1214. MTHCA_PUT(inbox, param->mtt_seg_sz, INIT_HCA_MTT_SEG_SZ_OFFSET);
  1215. MTHCA_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET);
  1216. MTHCA_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET);
  1217. /* UAR attributes */
  1218. {
  1219. u8 uar_page_sz = PAGE_SHIFT - 12;
  1220. MTHCA_PUT(inbox, uar_page_sz, INIT_HCA_UAR_PAGE_SZ_OFFSET);
  1221. }
  1222. MTHCA_PUT(inbox, param->uar_scratch_base, INIT_HCA_UAR_SCATCH_BASE_OFFSET);
  1223. if (mthca_is_memfree(dev)) {
  1224. MTHCA_PUT(inbox, param->log_uarc_sz, INIT_HCA_UARC_SZ_OFFSET);
  1225. MTHCA_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET);
  1226. MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET);
  1227. }
  1228. err = mthca_cmd(dev, mailbox->dma, 0, 0,
  1229. CMD_INIT_HCA, CMD_TIME_CLASS_D);
  1230. mthca_free_mailbox(dev, mailbox);
  1231. return err;
  1232. }
  1233. int mthca_INIT_IB(struct mthca_dev *dev,
  1234. struct mthca_init_ib_param *param,
  1235. int port)
  1236. {
  1237. struct mthca_mailbox *mailbox;
  1238. u32 *inbox;
  1239. int err;
  1240. u32 flags;
  1241. #define INIT_IB_IN_SIZE 56
  1242. #define INIT_IB_FLAGS_OFFSET 0x00
  1243. #define INIT_IB_FLAG_SIG (1 << 18)
  1244. #define INIT_IB_FLAG_NG (1 << 17)
  1245. #define INIT_IB_FLAG_G0 (1 << 16)
  1246. #define INIT_IB_VL_SHIFT 4
  1247. #define INIT_IB_PORT_WIDTH_SHIFT 8
  1248. #define INIT_IB_MTU_SHIFT 12
  1249. #define INIT_IB_MAX_GID_OFFSET 0x06
  1250. #define INIT_IB_MAX_PKEY_OFFSET 0x0a
  1251. #define INIT_IB_GUID0_OFFSET 0x10
  1252. #define INIT_IB_NODE_GUID_OFFSET 0x18
  1253. #define INIT_IB_SI_GUID_OFFSET 0x20
  1254. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1255. if (IS_ERR(mailbox))
  1256. return PTR_ERR(mailbox);
  1257. inbox = mailbox->buf;
  1258. memset(inbox, 0, INIT_IB_IN_SIZE);
  1259. flags = 0;
  1260. flags |= param->set_guid0 ? INIT_IB_FLAG_G0 : 0;
  1261. flags |= param->set_node_guid ? INIT_IB_FLAG_NG : 0;
  1262. flags |= param->set_si_guid ? INIT_IB_FLAG_SIG : 0;
  1263. flags |= param->vl_cap << INIT_IB_VL_SHIFT;
  1264. flags |= param->port_width << INIT_IB_PORT_WIDTH_SHIFT;
  1265. flags |= param->mtu_cap << INIT_IB_MTU_SHIFT;
  1266. MTHCA_PUT(inbox, flags, INIT_IB_FLAGS_OFFSET);
  1267. MTHCA_PUT(inbox, param->gid_cap, INIT_IB_MAX_GID_OFFSET);
  1268. MTHCA_PUT(inbox, param->pkey_cap, INIT_IB_MAX_PKEY_OFFSET);
  1269. MTHCA_PUT(inbox, param->guid0, INIT_IB_GUID0_OFFSET);
  1270. MTHCA_PUT(inbox, param->node_guid, INIT_IB_NODE_GUID_OFFSET);
  1271. MTHCA_PUT(inbox, param->si_guid, INIT_IB_SI_GUID_OFFSET);
  1272. err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_INIT_IB,
  1273. CMD_TIME_CLASS_A);
  1274. mthca_free_mailbox(dev, mailbox);
  1275. return err;
  1276. }
  1277. int mthca_CLOSE_IB(struct mthca_dev *dev, int port)
  1278. {
  1279. return mthca_cmd(dev, 0, port, 0, CMD_CLOSE_IB, CMD_TIME_CLASS_A);
  1280. }
  1281. int mthca_CLOSE_HCA(struct mthca_dev *dev, int panic)
  1282. {
  1283. return mthca_cmd(dev, 0, 0, panic, CMD_CLOSE_HCA, CMD_TIME_CLASS_C);
  1284. }
  1285. int mthca_SET_IB(struct mthca_dev *dev, struct mthca_set_ib_param *param,
  1286. int port)
  1287. {
  1288. struct mthca_mailbox *mailbox;
  1289. u32 *inbox;
  1290. int err;
  1291. u32 flags = 0;
  1292. #define SET_IB_IN_SIZE 0x40
  1293. #define SET_IB_FLAGS_OFFSET 0x00
  1294. #define SET_IB_FLAG_SIG (1 << 18)
  1295. #define SET_IB_FLAG_RQK (1 << 0)
  1296. #define SET_IB_CAP_MASK_OFFSET 0x04
  1297. #define SET_IB_SI_GUID_OFFSET 0x08
  1298. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1299. if (IS_ERR(mailbox))
  1300. return PTR_ERR(mailbox);
  1301. inbox = mailbox->buf;
  1302. memset(inbox, 0, SET_IB_IN_SIZE);
  1303. flags |= param->set_si_guid ? SET_IB_FLAG_SIG : 0;
  1304. flags |= param->reset_qkey_viol ? SET_IB_FLAG_RQK : 0;
  1305. MTHCA_PUT(inbox, flags, SET_IB_FLAGS_OFFSET);
  1306. MTHCA_PUT(inbox, param->cap_mask, SET_IB_CAP_MASK_OFFSET);
  1307. MTHCA_PUT(inbox, param->si_guid, SET_IB_SI_GUID_OFFSET);
  1308. err = mthca_cmd(dev, mailbox->dma, port, 0, CMD_SET_IB,
  1309. CMD_TIME_CLASS_B);
  1310. mthca_free_mailbox(dev, mailbox);
  1311. return err;
  1312. }
  1313. int mthca_MAP_ICM(struct mthca_dev *dev, struct mthca_icm *icm, u64 virt)
  1314. {
  1315. return mthca_map_cmd(dev, CMD_MAP_ICM, icm, virt);
  1316. }
  1317. int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt)
  1318. {
  1319. struct mthca_mailbox *mailbox;
  1320. __be64 *inbox;
  1321. int err;
  1322. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1323. if (IS_ERR(mailbox))
  1324. return PTR_ERR(mailbox);
  1325. inbox = mailbox->buf;
  1326. inbox[0] = cpu_to_be64(virt);
  1327. inbox[1] = cpu_to_be64(dma_addr);
  1328. err = mthca_cmd(dev, mailbox->dma, 1, 0, CMD_MAP_ICM,
  1329. CMD_TIME_CLASS_B);
  1330. mthca_free_mailbox(dev, mailbox);
  1331. if (!err)
  1332. mthca_dbg(dev, "Mapped page at %llx to %llx for ICM.\n",
  1333. (unsigned long long) dma_addr, (unsigned long long) virt);
  1334. return err;
  1335. }
  1336. int mthca_UNMAP_ICM(struct mthca_dev *dev, u64 virt, u32 page_count)
  1337. {
  1338. mthca_dbg(dev, "Unmapping %d pages at %llx from ICM.\n",
  1339. page_count, (unsigned long long) virt);
  1340. return mthca_cmd(dev, virt, page_count, 0,
  1341. CMD_UNMAP_ICM, CMD_TIME_CLASS_B);
  1342. }
  1343. int mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm)
  1344. {
  1345. return mthca_map_cmd(dev, CMD_MAP_ICM_AUX, icm, -1);
  1346. }
  1347. int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev)
  1348. {
  1349. return mthca_cmd(dev, 0, 0, 0, CMD_UNMAP_ICM_AUX, CMD_TIME_CLASS_B);
  1350. }
  1351. int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages)
  1352. {
  1353. int ret = mthca_cmd_imm(dev, icm_size, aux_pages, 0,
  1354. 0, CMD_SET_ICM_SIZE, CMD_TIME_CLASS_A);
  1355. if (ret)
  1356. return ret;
  1357. /*
  1358. * Round up number of system pages needed in case
  1359. * MTHCA_ICM_PAGE_SIZE < PAGE_SIZE.
  1360. */
  1361. *aux_pages = ALIGN(*aux_pages, PAGE_SIZE / MTHCA_ICM_PAGE_SIZE) >>
  1362. (PAGE_SHIFT - MTHCA_ICM_PAGE_SHIFT);
  1363. return 0;
  1364. }
  1365. int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1366. int mpt_index)
  1367. {
  1368. return mthca_cmd(dev, mailbox->dma, mpt_index, 0, CMD_SW2HW_MPT,
  1369. CMD_TIME_CLASS_B);
  1370. }
  1371. int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1372. int mpt_index)
  1373. {
  1374. return mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index,
  1375. !mailbox, CMD_HW2SW_MPT,
  1376. CMD_TIME_CLASS_B);
  1377. }
  1378. int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1379. int num_mtt)
  1380. {
  1381. return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
  1382. CMD_TIME_CLASS_B);
  1383. }
  1384. int mthca_SYNC_TPT(struct mthca_dev *dev)
  1385. {
  1386. return mthca_cmd(dev, 0, 0, 0, CMD_SYNC_TPT, CMD_TIME_CLASS_B);
  1387. }
  1388. int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
  1389. int eq_num)
  1390. {
  1391. mthca_dbg(dev, "%s mask %016llx for eqn %d\n",
  1392. unmap ? "Clearing" : "Setting",
  1393. (unsigned long long) event_mask, eq_num);
  1394. return mthca_cmd(dev, event_mask, (unmap << 31) | eq_num,
  1395. 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
  1396. }
  1397. int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1398. int eq_num)
  1399. {
  1400. return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
  1401. CMD_TIME_CLASS_A);
  1402. }
  1403. int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1404. int eq_num)
  1405. {
  1406. return mthca_cmd_box(dev, 0, mailbox->dma, eq_num, 0,
  1407. CMD_HW2SW_EQ,
  1408. CMD_TIME_CLASS_A);
  1409. }
  1410. int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1411. int cq_num)
  1412. {
  1413. return mthca_cmd(dev, mailbox->dma, cq_num, 0, CMD_SW2HW_CQ,
  1414. CMD_TIME_CLASS_A);
  1415. }
  1416. int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1417. int cq_num)
  1418. {
  1419. return mthca_cmd_box(dev, 0, mailbox->dma, cq_num, 0,
  1420. CMD_HW2SW_CQ,
  1421. CMD_TIME_CLASS_A);
  1422. }
  1423. int mthca_RESIZE_CQ(struct mthca_dev *dev, int cq_num, u32 lkey, u8 log_size)
  1424. {
  1425. struct mthca_mailbox *mailbox;
  1426. __be32 *inbox;
  1427. int err;
  1428. #define RESIZE_CQ_IN_SIZE 0x40
  1429. #define RESIZE_CQ_LOG_SIZE_OFFSET 0x0c
  1430. #define RESIZE_CQ_LKEY_OFFSET 0x1c
  1431. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1432. if (IS_ERR(mailbox))
  1433. return PTR_ERR(mailbox);
  1434. inbox = mailbox->buf;
  1435. memset(inbox, 0, RESIZE_CQ_IN_SIZE);
  1436. /*
  1437. * Leave start address fields zeroed out -- mthca assumes that
  1438. * MRs for CQs always start at virtual address 0.
  1439. */
  1440. MTHCA_PUT(inbox, log_size, RESIZE_CQ_LOG_SIZE_OFFSET);
  1441. MTHCA_PUT(inbox, lkey, RESIZE_CQ_LKEY_OFFSET);
  1442. err = mthca_cmd(dev, mailbox->dma, cq_num, 1, CMD_RESIZE_CQ,
  1443. CMD_TIME_CLASS_B);
  1444. mthca_free_mailbox(dev, mailbox);
  1445. return err;
  1446. }
  1447. int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1448. int srq_num)
  1449. {
  1450. return mthca_cmd(dev, mailbox->dma, srq_num, 0, CMD_SW2HW_SRQ,
  1451. CMD_TIME_CLASS_A);
  1452. }
  1453. int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1454. int srq_num)
  1455. {
  1456. return mthca_cmd_box(dev, 0, mailbox->dma, srq_num, 0,
  1457. CMD_HW2SW_SRQ,
  1458. CMD_TIME_CLASS_A);
  1459. }
  1460. int mthca_QUERY_SRQ(struct mthca_dev *dev, u32 num,
  1461. struct mthca_mailbox *mailbox)
  1462. {
  1463. return mthca_cmd_box(dev, 0, mailbox->dma, num, 0,
  1464. CMD_QUERY_SRQ, CMD_TIME_CLASS_A);
  1465. }
  1466. int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit)
  1467. {
  1468. return mthca_cmd(dev, limit, srq_num, 0, CMD_ARM_SRQ,
  1469. CMD_TIME_CLASS_B);
  1470. }
  1471. int mthca_MODIFY_QP(struct mthca_dev *dev, enum ib_qp_state cur,
  1472. enum ib_qp_state next, u32 num, int is_ee,
  1473. struct mthca_mailbox *mailbox, u32 optmask)
  1474. {
  1475. static const u16 op[IB_QPS_ERR + 1][IB_QPS_ERR + 1] = {
  1476. [IB_QPS_RESET] = {
  1477. [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
  1478. [IB_QPS_ERR] = CMD_2ERR_QPEE,
  1479. [IB_QPS_INIT] = CMD_RST2INIT_QPEE,
  1480. },
  1481. [IB_QPS_INIT] = {
  1482. [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
  1483. [IB_QPS_ERR] = CMD_2ERR_QPEE,
  1484. [IB_QPS_INIT] = CMD_INIT2INIT_QPEE,
  1485. [IB_QPS_RTR] = CMD_INIT2RTR_QPEE,
  1486. },
  1487. [IB_QPS_RTR] = {
  1488. [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
  1489. [IB_QPS_ERR] = CMD_2ERR_QPEE,
  1490. [IB_QPS_RTS] = CMD_RTR2RTS_QPEE,
  1491. },
  1492. [IB_QPS_RTS] = {
  1493. [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
  1494. [IB_QPS_ERR] = CMD_2ERR_QPEE,
  1495. [IB_QPS_RTS] = CMD_RTS2RTS_QPEE,
  1496. [IB_QPS_SQD] = CMD_RTS2SQD_QPEE,
  1497. },
  1498. [IB_QPS_SQD] = {
  1499. [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
  1500. [IB_QPS_ERR] = CMD_2ERR_QPEE,
  1501. [IB_QPS_RTS] = CMD_SQD2RTS_QPEE,
  1502. [IB_QPS_SQD] = CMD_SQD2SQD_QPEE,
  1503. },
  1504. [IB_QPS_SQE] = {
  1505. [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
  1506. [IB_QPS_ERR] = CMD_2ERR_QPEE,
  1507. [IB_QPS_RTS] = CMD_SQERR2RTS_QPEE,
  1508. },
  1509. [IB_QPS_ERR] = {
  1510. [IB_QPS_RESET] = CMD_ERR2RST_QPEE,
  1511. [IB_QPS_ERR] = CMD_2ERR_QPEE,
  1512. }
  1513. };
  1514. u8 op_mod = 0;
  1515. int my_mailbox = 0;
  1516. int err;
  1517. if (op[cur][next] == CMD_ERR2RST_QPEE) {
  1518. op_mod = 3; /* don't write outbox, any->reset */
  1519. /* For debugging */
  1520. if (!mailbox) {
  1521. mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1522. if (!IS_ERR(mailbox)) {
  1523. my_mailbox = 1;
  1524. op_mod = 2; /* write outbox, any->reset */
  1525. } else
  1526. mailbox = NULL;
  1527. }
  1528. err = mthca_cmd_box(dev, 0, mailbox ? mailbox->dma : 0,
  1529. (!!is_ee << 24) | num, op_mod,
  1530. op[cur][next], CMD_TIME_CLASS_C);
  1531. if (0 && mailbox) {
  1532. int i;
  1533. mthca_dbg(dev, "Dumping QP context:\n");
  1534. printk(" %08x\n", be32_to_cpup(mailbox->buf));
  1535. for (i = 0; i < 0x100 / 4; ++i) {
  1536. if (i % 8 == 0)
  1537. printk("[%02x] ", i * 4);
  1538. printk(" %08x",
  1539. be32_to_cpu(((__be32 *) mailbox->buf)[i + 2]));
  1540. if ((i + 1) % 8 == 0)
  1541. printk("\n");
  1542. }
  1543. }
  1544. if (my_mailbox)
  1545. mthca_free_mailbox(dev, mailbox);
  1546. } else {
  1547. if (0) {
  1548. int i;
  1549. mthca_dbg(dev, "Dumping QP context:\n");
  1550. printk(" opt param mask: %08x\n", be32_to_cpup(mailbox->buf));
  1551. for (i = 0; i < 0x100 / 4; ++i) {
  1552. if (i % 8 == 0)
  1553. printk(" [%02x] ", i * 4);
  1554. printk(" %08x",
  1555. be32_to_cpu(((__be32 *) mailbox->buf)[i + 2]));
  1556. if ((i + 1) % 8 == 0)
  1557. printk("\n");
  1558. }
  1559. }
  1560. err = mthca_cmd(dev, mailbox->dma, optmask | (!!is_ee << 24) | num,
  1561. op_mod, op[cur][next], CMD_TIME_CLASS_C);
  1562. }
  1563. return err;
  1564. }
  1565. int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
  1566. struct mthca_mailbox *mailbox)
  1567. {
  1568. return mthca_cmd_box(dev, 0, mailbox->dma, (!!is_ee << 24) | num, 0,
  1569. CMD_QUERY_QPEE, CMD_TIME_CLASS_A);
  1570. }
  1571. int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
  1572. {
  1573. u8 op_mod;
  1574. switch (type) {
  1575. case IB_QPT_SMI:
  1576. op_mod = 0;
  1577. break;
  1578. case IB_QPT_GSI:
  1579. op_mod = 1;
  1580. break;
  1581. case IB_QPT_RAW_IPV6:
  1582. op_mod = 2;
  1583. break;
  1584. case IB_QPT_RAW_ETHERTYPE:
  1585. op_mod = 3;
  1586. break;
  1587. default:
  1588. return -EINVAL;
  1589. }
  1590. return mthca_cmd(dev, 0, qpn, op_mod, CMD_CONF_SPECIAL_QP,
  1591. CMD_TIME_CLASS_B);
  1592. }
  1593. int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
  1594. int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
  1595. void *in_mad, void *response_mad)
  1596. {
  1597. struct mthca_mailbox *inmailbox, *outmailbox;
  1598. void *inbox;
  1599. int err;
  1600. u32 in_modifier = port;
  1601. u8 op_modifier = 0;
  1602. #define MAD_IFC_BOX_SIZE 0x400
  1603. #define MAD_IFC_MY_QPN_OFFSET 0x100
  1604. #define MAD_IFC_RQPN_OFFSET 0x108
  1605. #define MAD_IFC_SL_OFFSET 0x10c
  1606. #define MAD_IFC_G_PATH_OFFSET 0x10d
  1607. #define MAD_IFC_RLID_OFFSET 0x10e
  1608. #define MAD_IFC_PKEY_OFFSET 0x112
  1609. #define MAD_IFC_GRH_OFFSET 0x140
  1610. inmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1611. if (IS_ERR(inmailbox))
  1612. return PTR_ERR(inmailbox);
  1613. inbox = inmailbox->buf;
  1614. outmailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
  1615. if (IS_ERR(outmailbox)) {
  1616. mthca_free_mailbox(dev, inmailbox);
  1617. return PTR_ERR(outmailbox);
  1618. }
  1619. memcpy(inbox, in_mad, 256);
  1620. /*
  1621. * Key check traps can't be generated unless we have in_wc to
  1622. * tell us where to send the trap.
  1623. */
  1624. if (ignore_mkey || !in_wc)
  1625. op_modifier |= 0x1;
  1626. if (ignore_bkey || !in_wc)
  1627. op_modifier |= 0x2;
  1628. if (in_wc) {
  1629. u8 val;
  1630. memset(inbox + 256, 0, 256);
  1631. MTHCA_PUT(inbox, in_wc->qp->qp_num, MAD_IFC_MY_QPN_OFFSET);
  1632. MTHCA_PUT(inbox, in_wc->src_qp, MAD_IFC_RQPN_OFFSET);
  1633. val = in_wc->sl << 4;
  1634. MTHCA_PUT(inbox, val, MAD_IFC_SL_OFFSET);
  1635. val = in_wc->dlid_path_bits |
  1636. (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0);
  1637. MTHCA_PUT(inbox, val, MAD_IFC_G_PATH_OFFSET);
  1638. MTHCA_PUT(inbox, in_wc->slid, MAD_IFC_RLID_OFFSET);
  1639. MTHCA_PUT(inbox, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET);
  1640. if (in_grh)
  1641. memcpy(inbox + MAD_IFC_GRH_OFFSET, in_grh, 40);
  1642. op_modifier |= 0x4;
  1643. in_modifier |= in_wc->slid << 16;
  1644. }
  1645. err = mthca_cmd_box(dev, inmailbox->dma, outmailbox->dma,
  1646. in_modifier, op_modifier,
  1647. CMD_MAD_IFC, CMD_TIME_CLASS_C);
  1648. if (!err)
  1649. memcpy(response_mad, outmailbox->buf, 256);
  1650. mthca_free_mailbox(dev, inmailbox);
  1651. mthca_free_mailbox(dev, outmailbox);
  1652. return err;
  1653. }
  1654. int mthca_READ_MGM(struct mthca_dev *dev, int index,
  1655. struct mthca_mailbox *mailbox)
  1656. {
  1657. return mthca_cmd_box(dev, 0, mailbox->dma, index, 0,
  1658. CMD_READ_MGM, CMD_TIME_CLASS_A);
  1659. }
  1660. int mthca_WRITE_MGM(struct mthca_dev *dev, int index,
  1661. struct mthca_mailbox *mailbox)
  1662. {
  1663. return mthca_cmd(dev, mailbox->dma, index, 0, CMD_WRITE_MGM,
  1664. CMD_TIME_CLASS_A);
  1665. }
  1666. int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
  1667. u16 *hash)
  1668. {
  1669. u64 imm;
  1670. int err;
  1671. err = mthca_cmd_imm(dev, mailbox->dma, &imm, 0, 0, CMD_MGID_HASH,
  1672. CMD_TIME_CLASS_A);
  1673. *hash = imm;
  1674. return err;
  1675. }
  1676. int mthca_NOP(struct mthca_dev *dev)
  1677. {
  1678. return mthca_cmd(dev, 0, 0x1f, 0, CMD_NOP, msecs_to_jiffies(100));
  1679. }