cmd.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. 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/sched.h>
  35. #include <linux/slab.h>
  36. #include <linux/export.h>
  37. #include <linux/pci.h>
  38. #include <linux/errno.h>
  39. #include <linux/mlx4/cmd.h>
  40. #include <linux/semaphore.h>
  41. #include <asm/io.h>
  42. #include "mlx4.h"
  43. #include "fw.h"
  44. #define CMD_POLL_TOKEN 0xffff
  45. #define INBOX_MASK 0xffffffffffffff00ULL
  46. #define CMD_CHAN_VER 1
  47. #define CMD_CHAN_IF_REV 1
  48. enum {
  49. /* command completed successfully: */
  50. CMD_STAT_OK = 0x00,
  51. /* Internal error (such as a bus error) occurred while processing command: */
  52. CMD_STAT_INTERNAL_ERR = 0x01,
  53. /* Operation/command not supported or opcode modifier not supported: */
  54. CMD_STAT_BAD_OP = 0x02,
  55. /* Parameter not supported or parameter out of range: */
  56. CMD_STAT_BAD_PARAM = 0x03,
  57. /* System not enabled or bad system state: */
  58. CMD_STAT_BAD_SYS_STATE = 0x04,
  59. /* Attempt to access reserved or unallocaterd resource: */
  60. CMD_STAT_BAD_RESOURCE = 0x05,
  61. /* Requested resource is currently executing a command, or is otherwise busy: */
  62. CMD_STAT_RESOURCE_BUSY = 0x06,
  63. /* Required capability exceeds device limits: */
  64. CMD_STAT_EXCEED_LIM = 0x08,
  65. /* Resource is not in the appropriate state or ownership: */
  66. CMD_STAT_BAD_RES_STATE = 0x09,
  67. /* Index out of range: */
  68. CMD_STAT_BAD_INDEX = 0x0a,
  69. /* FW image corrupted: */
  70. CMD_STAT_BAD_NVMEM = 0x0b,
  71. /* Error in ICM mapping (e.g. not enough auxiliary ICM pages to execute command): */
  72. CMD_STAT_ICM_ERROR = 0x0c,
  73. /* Attempt to modify a QP/EE which is not in the presumed state: */
  74. CMD_STAT_BAD_QP_STATE = 0x10,
  75. /* Bad segment parameters (Address/Size): */
  76. CMD_STAT_BAD_SEG_PARAM = 0x20,
  77. /* Memory Region has Memory Windows bound to: */
  78. CMD_STAT_REG_BOUND = 0x21,
  79. /* HCA local attached memory not present: */
  80. CMD_STAT_LAM_NOT_PRE = 0x22,
  81. /* Bad management packet (silently discarded): */
  82. CMD_STAT_BAD_PKT = 0x30,
  83. /* More outstanding CQEs in CQ than new CQ size: */
  84. CMD_STAT_BAD_SIZE = 0x40,
  85. /* Multi Function device support required: */
  86. CMD_STAT_MULTI_FUNC_REQ = 0x50,
  87. };
  88. enum {
  89. HCR_IN_PARAM_OFFSET = 0x00,
  90. HCR_IN_MODIFIER_OFFSET = 0x08,
  91. HCR_OUT_PARAM_OFFSET = 0x0c,
  92. HCR_TOKEN_OFFSET = 0x14,
  93. HCR_STATUS_OFFSET = 0x18,
  94. HCR_OPMOD_SHIFT = 12,
  95. HCR_T_BIT = 21,
  96. HCR_E_BIT = 22,
  97. HCR_GO_BIT = 23
  98. };
  99. enum {
  100. GO_BIT_TIMEOUT_MSECS = 10000
  101. };
  102. struct mlx4_cmd_context {
  103. struct completion done;
  104. int result;
  105. int next;
  106. u64 out_param;
  107. u16 token;
  108. u8 fw_status;
  109. };
  110. static int mlx4_master_process_vhcr(struct mlx4_dev *dev, int slave,
  111. struct mlx4_vhcr_cmd *in_vhcr);
  112. static int mlx4_status_to_errno(u8 status)
  113. {
  114. static const int trans_table[] = {
  115. [CMD_STAT_INTERNAL_ERR] = -EIO,
  116. [CMD_STAT_BAD_OP] = -EPERM,
  117. [CMD_STAT_BAD_PARAM] = -EINVAL,
  118. [CMD_STAT_BAD_SYS_STATE] = -ENXIO,
  119. [CMD_STAT_BAD_RESOURCE] = -EBADF,
  120. [CMD_STAT_RESOURCE_BUSY] = -EBUSY,
  121. [CMD_STAT_EXCEED_LIM] = -ENOMEM,
  122. [CMD_STAT_BAD_RES_STATE] = -EBADF,
  123. [CMD_STAT_BAD_INDEX] = -EBADF,
  124. [CMD_STAT_BAD_NVMEM] = -EFAULT,
  125. [CMD_STAT_ICM_ERROR] = -ENFILE,
  126. [CMD_STAT_BAD_QP_STATE] = -EINVAL,
  127. [CMD_STAT_BAD_SEG_PARAM] = -EFAULT,
  128. [CMD_STAT_REG_BOUND] = -EBUSY,
  129. [CMD_STAT_LAM_NOT_PRE] = -EAGAIN,
  130. [CMD_STAT_BAD_PKT] = -EINVAL,
  131. [CMD_STAT_BAD_SIZE] = -ENOMEM,
  132. [CMD_STAT_MULTI_FUNC_REQ] = -EACCES,
  133. };
  134. if (status >= ARRAY_SIZE(trans_table) ||
  135. (status != CMD_STAT_OK && trans_table[status] == 0))
  136. return -EIO;
  137. return trans_table[status];
  138. }
  139. static u8 mlx4_errno_to_status(int errno)
  140. {
  141. switch (errno) {
  142. case -EPERM:
  143. return CMD_STAT_BAD_OP;
  144. case -EINVAL:
  145. return CMD_STAT_BAD_PARAM;
  146. case -ENXIO:
  147. return CMD_STAT_BAD_SYS_STATE;
  148. case -EBUSY:
  149. return CMD_STAT_RESOURCE_BUSY;
  150. case -ENOMEM:
  151. return CMD_STAT_EXCEED_LIM;
  152. case -ENFILE:
  153. return CMD_STAT_ICM_ERROR;
  154. default:
  155. return CMD_STAT_INTERNAL_ERR;
  156. }
  157. }
  158. static int comm_pending(struct mlx4_dev *dev)
  159. {
  160. struct mlx4_priv *priv = mlx4_priv(dev);
  161. u32 status = readl(&priv->mfunc.comm->slave_read);
  162. return (swab32(status) >> 31) != priv->cmd.comm_toggle;
  163. }
  164. static void mlx4_comm_cmd_post(struct mlx4_dev *dev, u8 cmd, u16 param)
  165. {
  166. struct mlx4_priv *priv = mlx4_priv(dev);
  167. u32 val;
  168. priv->cmd.comm_toggle ^= 1;
  169. val = param | (cmd << 16) | (priv->cmd.comm_toggle << 31);
  170. __raw_writel((__force u32) cpu_to_be32(val),
  171. &priv->mfunc.comm->slave_write);
  172. mmiowb();
  173. }
  174. static int mlx4_comm_cmd_poll(struct mlx4_dev *dev, u8 cmd, u16 param,
  175. unsigned long timeout)
  176. {
  177. struct mlx4_priv *priv = mlx4_priv(dev);
  178. unsigned long end;
  179. int err = 0;
  180. int ret_from_pending = 0;
  181. /* First, verify that the master reports correct status */
  182. if (comm_pending(dev)) {
  183. mlx4_warn(dev, "Communication channel is not idle."
  184. "my toggle is %d (cmd:0x%x)\n",
  185. priv->cmd.comm_toggle, cmd);
  186. return -EAGAIN;
  187. }
  188. /* Write command */
  189. down(&priv->cmd.poll_sem);
  190. mlx4_comm_cmd_post(dev, cmd, param);
  191. end = msecs_to_jiffies(timeout) + jiffies;
  192. while (comm_pending(dev) && time_before(jiffies, end))
  193. cond_resched();
  194. ret_from_pending = comm_pending(dev);
  195. if (ret_from_pending) {
  196. /* check if the slave is trying to boot in the middle of
  197. * FLR process. The only non-zero result in the RESET command
  198. * is MLX4_DELAY_RESET_SLAVE*/
  199. if ((MLX4_COMM_CMD_RESET == cmd)) {
  200. mlx4_warn(dev, "Got slave FLRed from Communication"
  201. " channel (ret:0x%x)\n", ret_from_pending);
  202. err = MLX4_DELAY_RESET_SLAVE;
  203. } else {
  204. mlx4_warn(dev, "Communication channel timed out\n");
  205. err = -ETIMEDOUT;
  206. }
  207. }
  208. up(&priv->cmd.poll_sem);
  209. return err;
  210. }
  211. static int mlx4_comm_cmd_wait(struct mlx4_dev *dev, u8 op,
  212. u16 param, unsigned long timeout)
  213. {
  214. struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
  215. struct mlx4_cmd_context *context;
  216. int err = 0;
  217. down(&cmd->event_sem);
  218. spin_lock(&cmd->context_lock);
  219. BUG_ON(cmd->free_head < 0);
  220. context = &cmd->context[cmd->free_head];
  221. context->token += cmd->token_mask + 1;
  222. cmd->free_head = context->next;
  223. spin_unlock(&cmd->context_lock);
  224. init_completion(&context->done);
  225. mlx4_comm_cmd_post(dev, op, param);
  226. if (!wait_for_completion_timeout(&context->done,
  227. msecs_to_jiffies(timeout))) {
  228. err = -EBUSY;
  229. goto out;
  230. }
  231. err = context->result;
  232. if (err && context->fw_status != CMD_STAT_MULTI_FUNC_REQ) {
  233. mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n",
  234. op, context->fw_status);
  235. goto out;
  236. }
  237. out:
  238. spin_lock(&cmd->context_lock);
  239. context->next = cmd->free_head;
  240. cmd->free_head = context - cmd->context;
  241. spin_unlock(&cmd->context_lock);
  242. up(&cmd->event_sem);
  243. return err;
  244. }
  245. int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param,
  246. unsigned long timeout)
  247. {
  248. if (mlx4_priv(dev)->cmd.use_events)
  249. return mlx4_comm_cmd_wait(dev, cmd, param, timeout);
  250. return mlx4_comm_cmd_poll(dev, cmd, param, timeout);
  251. }
  252. static int cmd_pending(struct mlx4_dev *dev)
  253. {
  254. u32 status = readl(mlx4_priv(dev)->cmd.hcr + HCR_STATUS_OFFSET);
  255. return (status & swab32(1 << HCR_GO_BIT)) ||
  256. (mlx4_priv(dev)->cmd.toggle ==
  257. !!(status & swab32(1 << HCR_T_BIT)));
  258. }
  259. static int mlx4_cmd_post(struct mlx4_dev *dev, u64 in_param, u64 out_param,
  260. u32 in_modifier, u8 op_modifier, u16 op, u16 token,
  261. int event)
  262. {
  263. struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
  264. u32 __iomem *hcr = cmd->hcr;
  265. int ret = -EAGAIN;
  266. unsigned long end;
  267. mutex_lock(&cmd->hcr_mutex);
  268. end = jiffies;
  269. if (event)
  270. end += msecs_to_jiffies(GO_BIT_TIMEOUT_MSECS);
  271. while (cmd_pending(dev)) {
  272. if (time_after_eq(jiffies, end)) {
  273. mlx4_err(dev, "%s:cmd_pending failed\n", __func__);
  274. goto out;
  275. }
  276. cond_resched();
  277. }
  278. /*
  279. * We use writel (instead of something like memcpy_toio)
  280. * because writes of less than 32 bits to the HCR don't work
  281. * (and some architectures such as ia64 implement memcpy_toio
  282. * in terms of writeb).
  283. */
  284. __raw_writel((__force u32) cpu_to_be32(in_param >> 32), hcr + 0);
  285. __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), hcr + 1);
  286. __raw_writel((__force u32) cpu_to_be32(in_modifier), hcr + 2);
  287. __raw_writel((__force u32) cpu_to_be32(out_param >> 32), hcr + 3);
  288. __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), hcr + 4);
  289. __raw_writel((__force u32) cpu_to_be32(token << 16), hcr + 5);
  290. /* __raw_writel may not order writes. */
  291. wmb();
  292. __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
  293. (cmd->toggle << HCR_T_BIT) |
  294. (event ? (1 << HCR_E_BIT) : 0) |
  295. (op_modifier << HCR_OPMOD_SHIFT) |
  296. op), hcr + 6);
  297. /*
  298. * Make sure that our HCR writes don't get mixed in with
  299. * writes from another CPU starting a FW command.
  300. */
  301. mmiowb();
  302. cmd->toggle = cmd->toggle ^ 1;
  303. ret = 0;
  304. out:
  305. mutex_unlock(&cmd->hcr_mutex);
  306. return ret;
  307. }
  308. static int mlx4_slave_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
  309. int out_is_imm, u32 in_modifier, u8 op_modifier,
  310. u16 op, unsigned long timeout)
  311. {
  312. struct mlx4_priv *priv = mlx4_priv(dev);
  313. struct mlx4_vhcr_cmd *vhcr = priv->mfunc.vhcr;
  314. int ret;
  315. down(&priv->cmd.slave_sem);
  316. vhcr->in_param = cpu_to_be64(in_param);
  317. vhcr->out_param = out_param ? cpu_to_be64(*out_param) : 0;
  318. vhcr->in_modifier = cpu_to_be32(in_modifier);
  319. vhcr->opcode = cpu_to_be16((((u16) op_modifier) << 12) | (op & 0xfff));
  320. vhcr->token = cpu_to_be16(CMD_POLL_TOKEN);
  321. vhcr->status = 0;
  322. vhcr->flags = !!(priv->cmd.use_events) << 6;
  323. if (mlx4_is_master(dev)) {
  324. ret = mlx4_master_process_vhcr(dev, dev->caps.function, vhcr);
  325. if (!ret) {
  326. if (out_is_imm) {
  327. if (out_param)
  328. *out_param =
  329. be64_to_cpu(vhcr->out_param);
  330. else {
  331. mlx4_err(dev, "response expected while"
  332. "output mailbox is NULL for "
  333. "command 0x%x\n", op);
  334. vhcr->status = CMD_STAT_BAD_PARAM;
  335. }
  336. }
  337. ret = mlx4_status_to_errno(vhcr->status);
  338. }
  339. } else {
  340. ret = mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_POST, 0,
  341. MLX4_COMM_TIME + timeout);
  342. if (!ret) {
  343. if (out_is_imm) {
  344. if (out_param)
  345. *out_param =
  346. be64_to_cpu(vhcr->out_param);
  347. else {
  348. mlx4_err(dev, "response expected while"
  349. "output mailbox is NULL for "
  350. "command 0x%x\n", op);
  351. vhcr->status = CMD_STAT_BAD_PARAM;
  352. }
  353. }
  354. ret = mlx4_status_to_errno(vhcr->status);
  355. } else
  356. mlx4_err(dev, "failed execution of VHCR_POST command"
  357. "opcode 0x%x\n", op);
  358. }
  359. up(&priv->cmd.slave_sem);
  360. return ret;
  361. }
  362. static int mlx4_cmd_poll(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
  363. int out_is_imm, u32 in_modifier, u8 op_modifier,
  364. u16 op, unsigned long timeout)
  365. {
  366. struct mlx4_priv *priv = mlx4_priv(dev);
  367. void __iomem *hcr = priv->cmd.hcr;
  368. int err = 0;
  369. unsigned long end;
  370. u32 stat;
  371. down(&priv->cmd.poll_sem);
  372. err = mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
  373. in_modifier, op_modifier, op, CMD_POLL_TOKEN, 0);
  374. if (err)
  375. goto out;
  376. end = msecs_to_jiffies(timeout) + jiffies;
  377. while (cmd_pending(dev) && time_before(jiffies, end))
  378. cond_resched();
  379. if (cmd_pending(dev)) {
  380. err = -ETIMEDOUT;
  381. goto out;
  382. }
  383. if (out_is_imm)
  384. *out_param =
  385. (u64) be32_to_cpu((__force __be32)
  386. __raw_readl(hcr + HCR_OUT_PARAM_OFFSET)) << 32 |
  387. (u64) be32_to_cpu((__force __be32)
  388. __raw_readl(hcr + HCR_OUT_PARAM_OFFSET + 4));
  389. stat = be32_to_cpu((__force __be32)
  390. __raw_readl(hcr + HCR_STATUS_OFFSET)) >> 24;
  391. err = mlx4_status_to_errno(stat);
  392. if (err)
  393. mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n",
  394. op, stat);
  395. out:
  396. up(&priv->cmd.poll_sem);
  397. return err;
  398. }
  399. void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param)
  400. {
  401. struct mlx4_priv *priv = mlx4_priv(dev);
  402. struct mlx4_cmd_context *context =
  403. &priv->cmd.context[token & priv->cmd.token_mask];
  404. /* previously timed out command completing at long last */
  405. if (token != context->token)
  406. return;
  407. context->fw_status = status;
  408. context->result = mlx4_status_to_errno(status);
  409. context->out_param = out_param;
  410. complete(&context->done);
  411. }
  412. static int mlx4_cmd_wait(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
  413. int out_is_imm, u32 in_modifier, u8 op_modifier,
  414. u16 op, unsigned long timeout)
  415. {
  416. struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
  417. struct mlx4_cmd_context *context;
  418. int err = 0;
  419. down(&cmd->event_sem);
  420. spin_lock(&cmd->context_lock);
  421. BUG_ON(cmd->free_head < 0);
  422. context = &cmd->context[cmd->free_head];
  423. context->token += cmd->token_mask + 1;
  424. cmd->free_head = context->next;
  425. spin_unlock(&cmd->context_lock);
  426. init_completion(&context->done);
  427. mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
  428. in_modifier, op_modifier, op, context->token, 1);
  429. if (!wait_for_completion_timeout(&context->done,
  430. msecs_to_jiffies(timeout))) {
  431. err = -EBUSY;
  432. goto out;
  433. }
  434. err = context->result;
  435. if (err) {
  436. mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n",
  437. op, context->fw_status);
  438. goto out;
  439. }
  440. if (out_is_imm)
  441. *out_param = context->out_param;
  442. out:
  443. spin_lock(&cmd->context_lock);
  444. context->next = cmd->free_head;
  445. cmd->free_head = context - cmd->context;
  446. spin_unlock(&cmd->context_lock);
  447. up(&cmd->event_sem);
  448. return err;
  449. }
  450. int __mlx4_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
  451. int out_is_imm, u32 in_modifier, u8 op_modifier,
  452. u16 op, unsigned long timeout, int native)
  453. {
  454. if (!mlx4_is_mfunc(dev) || (native && mlx4_is_master(dev))) {
  455. if (mlx4_priv(dev)->cmd.use_events)
  456. return mlx4_cmd_wait(dev, in_param, out_param,
  457. out_is_imm, in_modifier,
  458. op_modifier, op, timeout);
  459. else
  460. return mlx4_cmd_poll(dev, in_param, out_param,
  461. out_is_imm, in_modifier,
  462. op_modifier, op, timeout);
  463. }
  464. return mlx4_slave_cmd(dev, in_param, out_param, out_is_imm,
  465. in_modifier, op_modifier, op, timeout);
  466. }
  467. EXPORT_SYMBOL_GPL(__mlx4_cmd);
  468. static int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev *dev)
  469. {
  470. return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_ARM_COMM_CHANNEL,
  471. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  472. }
  473. static int mlx4_ACCESS_MEM(struct mlx4_dev *dev, u64 master_addr,
  474. int slave, u64 slave_addr,
  475. int size, int is_read)
  476. {
  477. u64 in_param;
  478. u64 out_param;
  479. if ((slave_addr & 0xfff) | (master_addr & 0xfff) |
  480. (slave & ~0x7f) | (size & 0xff)) {
  481. mlx4_err(dev, "Bad access mem params - slave_addr:0x%llx "
  482. "master_addr:0x%llx slave_id:%d size:%d\n",
  483. slave_addr, master_addr, slave, size);
  484. return -EINVAL;
  485. }
  486. if (is_read) {
  487. in_param = (u64) slave | slave_addr;
  488. out_param = (u64) dev->caps.function | master_addr;
  489. } else {
  490. in_param = (u64) dev->caps.function | master_addr;
  491. out_param = (u64) slave | slave_addr;
  492. }
  493. return mlx4_cmd_imm(dev, in_param, &out_param, size, 0,
  494. MLX4_CMD_ACCESS_MEM,
  495. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  496. }
  497. int mlx4_DMA_wrapper(struct mlx4_dev *dev, int slave,
  498. struct mlx4_vhcr *vhcr,
  499. struct mlx4_cmd_mailbox *inbox,
  500. struct mlx4_cmd_mailbox *outbox,
  501. struct mlx4_cmd_info *cmd)
  502. {
  503. u64 in_param;
  504. u64 out_param;
  505. int err;
  506. in_param = cmd->has_inbox ? (u64) inbox->dma : vhcr->in_param;
  507. out_param = cmd->has_outbox ? (u64) outbox->dma : vhcr->out_param;
  508. if (cmd->encode_slave_id) {
  509. in_param &= 0xffffffffffffff00ll;
  510. in_param |= slave;
  511. }
  512. err = __mlx4_cmd(dev, in_param, &out_param, cmd->out_is_imm,
  513. vhcr->in_modifier, vhcr->op_modifier, vhcr->op,
  514. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  515. if (cmd->out_is_imm)
  516. vhcr->out_param = out_param;
  517. return err;
  518. }
  519. static struct mlx4_cmd_info cmd_info[] = {
  520. {
  521. .opcode = MLX4_CMD_QUERY_FW,
  522. .has_inbox = false,
  523. .has_outbox = true,
  524. .out_is_imm = false,
  525. .encode_slave_id = false,
  526. .verify = NULL,
  527. .wrapper = NULL
  528. },
  529. {
  530. .opcode = MLX4_CMD_QUERY_HCA,
  531. .has_inbox = false,
  532. .has_outbox = true,
  533. .out_is_imm = false,
  534. .encode_slave_id = false,
  535. .verify = NULL,
  536. .wrapper = NULL
  537. },
  538. {
  539. .opcode = MLX4_CMD_QUERY_DEV_CAP,
  540. .has_inbox = false,
  541. .has_outbox = true,
  542. .out_is_imm = false,
  543. .encode_slave_id = false,
  544. .verify = NULL,
  545. .wrapper = NULL
  546. },
  547. {
  548. .opcode = MLX4_CMD_QUERY_FUNC_CAP,
  549. .has_inbox = false,
  550. .has_outbox = true,
  551. .out_is_imm = false,
  552. .encode_slave_id = false,
  553. .verify = NULL,
  554. .wrapper = mlx4_QUERY_FUNC_CAP_wrapper
  555. },
  556. {
  557. .opcode = MLX4_CMD_QUERY_ADAPTER,
  558. .has_inbox = false,
  559. .has_outbox = true,
  560. .out_is_imm = false,
  561. .encode_slave_id = false,
  562. .verify = NULL,
  563. .wrapper = NULL
  564. },
  565. {
  566. .opcode = MLX4_CMD_INIT_PORT,
  567. .has_inbox = false,
  568. .has_outbox = false,
  569. .out_is_imm = false,
  570. .encode_slave_id = false,
  571. .verify = NULL,
  572. .wrapper = mlx4_INIT_PORT_wrapper
  573. },
  574. {
  575. .opcode = MLX4_CMD_CLOSE_PORT,
  576. .has_inbox = false,
  577. .has_outbox = false,
  578. .out_is_imm = false,
  579. .encode_slave_id = false,
  580. .verify = NULL,
  581. .wrapper = mlx4_CLOSE_PORT_wrapper
  582. },
  583. {
  584. .opcode = MLX4_CMD_QUERY_PORT,
  585. .has_inbox = false,
  586. .has_outbox = true,
  587. .out_is_imm = false,
  588. .encode_slave_id = false,
  589. .verify = NULL,
  590. .wrapper = mlx4_QUERY_PORT_wrapper
  591. },
  592. {
  593. .opcode = MLX4_CMD_SET_PORT,
  594. .has_inbox = true,
  595. .has_outbox = false,
  596. .out_is_imm = false,
  597. .encode_slave_id = false,
  598. .verify = NULL,
  599. .wrapper = mlx4_SET_PORT_wrapper
  600. },
  601. {
  602. .opcode = MLX4_CMD_MAP_EQ,
  603. .has_inbox = false,
  604. .has_outbox = false,
  605. .out_is_imm = false,
  606. .encode_slave_id = false,
  607. .verify = NULL,
  608. .wrapper = mlx4_MAP_EQ_wrapper
  609. },
  610. {
  611. .opcode = MLX4_CMD_SW2HW_EQ,
  612. .has_inbox = true,
  613. .has_outbox = false,
  614. .out_is_imm = false,
  615. .encode_slave_id = true,
  616. .verify = NULL,
  617. .wrapper = mlx4_SW2HW_EQ_wrapper
  618. },
  619. {
  620. .opcode = MLX4_CMD_HW_HEALTH_CHECK,
  621. .has_inbox = false,
  622. .has_outbox = false,
  623. .out_is_imm = false,
  624. .encode_slave_id = false,
  625. .verify = NULL,
  626. .wrapper = NULL
  627. },
  628. {
  629. .opcode = MLX4_CMD_NOP,
  630. .has_inbox = false,
  631. .has_outbox = false,
  632. .out_is_imm = false,
  633. .encode_slave_id = false,
  634. .verify = NULL,
  635. .wrapper = NULL
  636. },
  637. {
  638. .opcode = MLX4_CMD_ALLOC_RES,
  639. .has_inbox = false,
  640. .has_outbox = false,
  641. .out_is_imm = true,
  642. .encode_slave_id = false,
  643. .verify = NULL,
  644. .wrapper = mlx4_ALLOC_RES_wrapper
  645. },
  646. {
  647. .opcode = MLX4_CMD_FREE_RES,
  648. .has_inbox = false,
  649. .has_outbox = false,
  650. .out_is_imm = false,
  651. .encode_slave_id = false,
  652. .verify = NULL,
  653. .wrapper = mlx4_FREE_RES_wrapper
  654. },
  655. {
  656. .opcode = MLX4_CMD_SW2HW_MPT,
  657. .has_inbox = true,
  658. .has_outbox = false,
  659. .out_is_imm = false,
  660. .encode_slave_id = true,
  661. .verify = NULL,
  662. .wrapper = mlx4_SW2HW_MPT_wrapper
  663. },
  664. {
  665. .opcode = MLX4_CMD_QUERY_MPT,
  666. .has_inbox = false,
  667. .has_outbox = true,
  668. .out_is_imm = false,
  669. .encode_slave_id = false,
  670. .verify = NULL,
  671. .wrapper = mlx4_QUERY_MPT_wrapper
  672. },
  673. {
  674. .opcode = MLX4_CMD_HW2SW_MPT,
  675. .has_inbox = false,
  676. .has_outbox = false,
  677. .out_is_imm = false,
  678. .encode_slave_id = false,
  679. .verify = NULL,
  680. .wrapper = mlx4_HW2SW_MPT_wrapper
  681. },
  682. {
  683. .opcode = MLX4_CMD_READ_MTT,
  684. .has_inbox = false,
  685. .has_outbox = true,
  686. .out_is_imm = false,
  687. .encode_slave_id = false,
  688. .verify = NULL,
  689. .wrapper = NULL
  690. },
  691. {
  692. .opcode = MLX4_CMD_WRITE_MTT,
  693. .has_inbox = true,
  694. .has_outbox = false,
  695. .out_is_imm = false,
  696. .encode_slave_id = false,
  697. .verify = NULL,
  698. .wrapper = mlx4_WRITE_MTT_wrapper
  699. },
  700. {
  701. .opcode = MLX4_CMD_SYNC_TPT,
  702. .has_inbox = true,
  703. .has_outbox = false,
  704. .out_is_imm = false,
  705. .encode_slave_id = false,
  706. .verify = NULL,
  707. .wrapper = NULL
  708. },
  709. {
  710. .opcode = MLX4_CMD_HW2SW_EQ,
  711. .has_inbox = false,
  712. .has_outbox = true,
  713. .out_is_imm = false,
  714. .encode_slave_id = true,
  715. .verify = NULL,
  716. .wrapper = mlx4_HW2SW_EQ_wrapper
  717. },
  718. {
  719. .opcode = MLX4_CMD_QUERY_EQ,
  720. .has_inbox = false,
  721. .has_outbox = true,
  722. .out_is_imm = false,
  723. .encode_slave_id = true,
  724. .verify = NULL,
  725. .wrapper = mlx4_QUERY_EQ_wrapper
  726. },
  727. {
  728. .opcode = MLX4_CMD_SW2HW_CQ,
  729. .has_inbox = true,
  730. .has_outbox = false,
  731. .out_is_imm = false,
  732. .encode_slave_id = true,
  733. .verify = NULL,
  734. .wrapper = mlx4_SW2HW_CQ_wrapper
  735. },
  736. {
  737. .opcode = MLX4_CMD_HW2SW_CQ,
  738. .has_inbox = false,
  739. .has_outbox = false,
  740. .out_is_imm = false,
  741. .encode_slave_id = false,
  742. .verify = NULL,
  743. .wrapper = mlx4_HW2SW_CQ_wrapper
  744. },
  745. {
  746. .opcode = MLX4_CMD_QUERY_CQ,
  747. .has_inbox = false,
  748. .has_outbox = true,
  749. .out_is_imm = false,
  750. .encode_slave_id = false,
  751. .verify = NULL,
  752. .wrapper = mlx4_QUERY_CQ_wrapper
  753. },
  754. {
  755. .opcode = MLX4_CMD_MODIFY_CQ,
  756. .has_inbox = true,
  757. .has_outbox = false,
  758. .out_is_imm = true,
  759. .encode_slave_id = false,
  760. .verify = NULL,
  761. .wrapper = mlx4_MODIFY_CQ_wrapper
  762. },
  763. {
  764. .opcode = MLX4_CMD_SW2HW_SRQ,
  765. .has_inbox = true,
  766. .has_outbox = false,
  767. .out_is_imm = false,
  768. .encode_slave_id = true,
  769. .verify = NULL,
  770. .wrapper = mlx4_SW2HW_SRQ_wrapper
  771. },
  772. {
  773. .opcode = MLX4_CMD_HW2SW_SRQ,
  774. .has_inbox = false,
  775. .has_outbox = false,
  776. .out_is_imm = false,
  777. .encode_slave_id = false,
  778. .verify = NULL,
  779. .wrapper = mlx4_HW2SW_SRQ_wrapper
  780. },
  781. {
  782. .opcode = MLX4_CMD_QUERY_SRQ,
  783. .has_inbox = false,
  784. .has_outbox = true,
  785. .out_is_imm = false,
  786. .encode_slave_id = false,
  787. .verify = NULL,
  788. .wrapper = mlx4_QUERY_SRQ_wrapper
  789. },
  790. {
  791. .opcode = MLX4_CMD_ARM_SRQ,
  792. .has_inbox = false,
  793. .has_outbox = false,
  794. .out_is_imm = false,
  795. .encode_slave_id = false,
  796. .verify = NULL,
  797. .wrapper = mlx4_ARM_SRQ_wrapper
  798. },
  799. {
  800. .opcode = MLX4_CMD_RST2INIT_QP,
  801. .has_inbox = true,
  802. .has_outbox = false,
  803. .out_is_imm = false,
  804. .encode_slave_id = true,
  805. .verify = NULL,
  806. .wrapper = mlx4_RST2INIT_QP_wrapper
  807. },
  808. {
  809. .opcode = MLX4_CMD_INIT2INIT_QP,
  810. .has_inbox = true,
  811. .has_outbox = false,
  812. .out_is_imm = false,
  813. .encode_slave_id = false,
  814. .verify = NULL,
  815. .wrapper = mlx4_GEN_QP_wrapper
  816. },
  817. {
  818. .opcode = MLX4_CMD_INIT2RTR_QP,
  819. .has_inbox = true,
  820. .has_outbox = false,
  821. .out_is_imm = false,
  822. .encode_slave_id = false,
  823. .verify = NULL,
  824. .wrapper = mlx4_INIT2RTR_QP_wrapper
  825. },
  826. {
  827. .opcode = MLX4_CMD_RTR2RTS_QP,
  828. .has_inbox = true,
  829. .has_outbox = false,
  830. .out_is_imm = false,
  831. .encode_slave_id = false,
  832. .verify = NULL,
  833. .wrapper = mlx4_GEN_QP_wrapper
  834. },
  835. {
  836. .opcode = MLX4_CMD_RTS2RTS_QP,
  837. .has_inbox = true,
  838. .has_outbox = false,
  839. .out_is_imm = false,
  840. .encode_slave_id = false,
  841. .verify = NULL,
  842. .wrapper = mlx4_GEN_QP_wrapper
  843. },
  844. {
  845. .opcode = MLX4_CMD_SQERR2RTS_QP,
  846. .has_inbox = true,
  847. .has_outbox = false,
  848. .out_is_imm = false,
  849. .encode_slave_id = false,
  850. .verify = NULL,
  851. .wrapper = mlx4_GEN_QP_wrapper
  852. },
  853. {
  854. .opcode = MLX4_CMD_2ERR_QP,
  855. .has_inbox = false,
  856. .has_outbox = false,
  857. .out_is_imm = false,
  858. .encode_slave_id = false,
  859. .verify = NULL,
  860. .wrapper = mlx4_GEN_QP_wrapper
  861. },
  862. {
  863. .opcode = MLX4_CMD_RTS2SQD_QP,
  864. .has_inbox = false,
  865. .has_outbox = false,
  866. .out_is_imm = false,
  867. .encode_slave_id = false,
  868. .verify = NULL,
  869. .wrapper = mlx4_GEN_QP_wrapper
  870. },
  871. {
  872. .opcode = MLX4_CMD_SQD2SQD_QP,
  873. .has_inbox = true,
  874. .has_outbox = false,
  875. .out_is_imm = false,
  876. .encode_slave_id = false,
  877. .verify = NULL,
  878. .wrapper = mlx4_GEN_QP_wrapper
  879. },
  880. {
  881. .opcode = MLX4_CMD_SQD2RTS_QP,
  882. .has_inbox = true,
  883. .has_outbox = false,
  884. .out_is_imm = false,
  885. .encode_slave_id = false,
  886. .verify = NULL,
  887. .wrapper = mlx4_GEN_QP_wrapper
  888. },
  889. {
  890. .opcode = MLX4_CMD_2RST_QP,
  891. .has_inbox = false,
  892. .has_outbox = false,
  893. .out_is_imm = false,
  894. .encode_slave_id = false,
  895. .verify = NULL,
  896. .wrapper = mlx4_2RST_QP_wrapper
  897. },
  898. {
  899. .opcode = MLX4_CMD_QUERY_QP,
  900. .has_inbox = false,
  901. .has_outbox = true,
  902. .out_is_imm = false,
  903. .encode_slave_id = false,
  904. .verify = NULL,
  905. .wrapper = mlx4_GEN_QP_wrapper
  906. },
  907. {
  908. .opcode = MLX4_CMD_SUSPEND_QP,
  909. .has_inbox = false,
  910. .has_outbox = false,
  911. .out_is_imm = false,
  912. .encode_slave_id = false,
  913. .verify = NULL,
  914. .wrapper = mlx4_GEN_QP_wrapper
  915. },
  916. {
  917. .opcode = MLX4_CMD_UNSUSPEND_QP,
  918. .has_inbox = false,
  919. .has_outbox = false,
  920. .out_is_imm = false,
  921. .encode_slave_id = false,
  922. .verify = NULL,
  923. .wrapper = mlx4_GEN_QP_wrapper
  924. },
  925. {
  926. .opcode = MLX4_CMD_QUERY_IF_STAT,
  927. .has_inbox = false,
  928. .has_outbox = true,
  929. .out_is_imm = false,
  930. .encode_slave_id = false,
  931. .verify = NULL,
  932. .wrapper = mlx4_QUERY_IF_STAT_wrapper
  933. },
  934. /* Native multicast commands are not available for guests */
  935. {
  936. .opcode = MLX4_CMD_QP_ATTACH,
  937. .has_inbox = true,
  938. .has_outbox = false,
  939. .out_is_imm = false,
  940. .encode_slave_id = false,
  941. .verify = NULL,
  942. .wrapper = mlx4_QP_ATTACH_wrapper
  943. },
  944. {
  945. .opcode = MLX4_CMD_PROMISC,
  946. .has_inbox = false,
  947. .has_outbox = false,
  948. .out_is_imm = false,
  949. .encode_slave_id = false,
  950. .verify = NULL,
  951. .wrapper = mlx4_PROMISC_wrapper
  952. },
  953. /* Ethernet specific commands */
  954. {
  955. .opcode = MLX4_CMD_SET_VLAN_FLTR,
  956. .has_inbox = true,
  957. .has_outbox = false,
  958. .out_is_imm = false,
  959. .encode_slave_id = false,
  960. .verify = NULL,
  961. .wrapper = mlx4_SET_VLAN_FLTR_wrapper
  962. },
  963. {
  964. .opcode = MLX4_CMD_SET_MCAST_FLTR,
  965. .has_inbox = false,
  966. .has_outbox = false,
  967. .out_is_imm = false,
  968. .encode_slave_id = false,
  969. .verify = NULL,
  970. .wrapper = mlx4_SET_MCAST_FLTR_wrapper
  971. },
  972. {
  973. .opcode = MLX4_CMD_DUMP_ETH_STATS,
  974. .has_inbox = false,
  975. .has_outbox = true,
  976. .out_is_imm = false,
  977. .encode_slave_id = false,
  978. .verify = NULL,
  979. .wrapper = mlx4_DUMP_ETH_STATS_wrapper
  980. },
  981. {
  982. .opcode = MLX4_CMD_INFORM_FLR_DONE,
  983. .has_inbox = false,
  984. .has_outbox = false,
  985. .out_is_imm = false,
  986. .encode_slave_id = false,
  987. .verify = NULL,
  988. .wrapper = NULL
  989. },
  990. };
  991. static int mlx4_master_process_vhcr(struct mlx4_dev *dev, int slave,
  992. struct mlx4_vhcr_cmd *in_vhcr)
  993. {
  994. struct mlx4_priv *priv = mlx4_priv(dev);
  995. struct mlx4_cmd_info *cmd = NULL;
  996. struct mlx4_vhcr_cmd *vhcr_cmd = in_vhcr ? in_vhcr : priv->mfunc.vhcr;
  997. struct mlx4_vhcr *vhcr;
  998. struct mlx4_cmd_mailbox *inbox = NULL;
  999. struct mlx4_cmd_mailbox *outbox = NULL;
  1000. u64 in_param;
  1001. u64 out_param;
  1002. int ret = 0;
  1003. int i;
  1004. int err = 0;
  1005. /* Create sw representation of Virtual HCR */
  1006. vhcr = kzalloc(sizeof(struct mlx4_vhcr), GFP_KERNEL);
  1007. if (!vhcr)
  1008. return -ENOMEM;
  1009. /* DMA in the vHCR */
  1010. if (!in_vhcr) {
  1011. ret = mlx4_ACCESS_MEM(dev, priv->mfunc.vhcr_dma, slave,
  1012. priv->mfunc.master.slave_state[slave].vhcr_dma,
  1013. ALIGN(sizeof(struct mlx4_vhcr_cmd),
  1014. MLX4_ACCESS_MEM_ALIGN), 1);
  1015. if (ret) {
  1016. mlx4_err(dev, "%s:Failed reading vhcr"
  1017. "ret: 0x%x\n", __func__, ret);
  1018. kfree(vhcr);
  1019. return ret;
  1020. }
  1021. }
  1022. /* Fill SW VHCR fields */
  1023. vhcr->in_param = be64_to_cpu(vhcr_cmd->in_param);
  1024. vhcr->out_param = be64_to_cpu(vhcr_cmd->out_param);
  1025. vhcr->in_modifier = be32_to_cpu(vhcr_cmd->in_modifier);
  1026. vhcr->token = be16_to_cpu(vhcr_cmd->token);
  1027. vhcr->op = be16_to_cpu(vhcr_cmd->opcode) & 0xfff;
  1028. vhcr->op_modifier = (u8) (be16_to_cpu(vhcr_cmd->opcode) >> 12);
  1029. vhcr->e_bit = vhcr_cmd->flags & (1 << 6);
  1030. /* Lookup command */
  1031. for (i = 0; i < ARRAY_SIZE(cmd_info); ++i) {
  1032. if (vhcr->op == cmd_info[i].opcode) {
  1033. cmd = &cmd_info[i];
  1034. break;
  1035. }
  1036. }
  1037. if (!cmd) {
  1038. mlx4_err(dev, "Unknown command:0x%x accepted from slave:%d\n",
  1039. vhcr->op, slave);
  1040. vhcr_cmd->status = CMD_STAT_BAD_PARAM;
  1041. goto out_status;
  1042. }
  1043. /* Read inbox */
  1044. if (cmd->has_inbox) {
  1045. vhcr->in_param &= INBOX_MASK;
  1046. inbox = mlx4_alloc_cmd_mailbox(dev);
  1047. if (IS_ERR(inbox)) {
  1048. vhcr_cmd->status = CMD_STAT_BAD_SIZE;
  1049. inbox = NULL;
  1050. goto out_status;
  1051. }
  1052. if (mlx4_ACCESS_MEM(dev, inbox->dma, slave,
  1053. vhcr->in_param,
  1054. MLX4_MAILBOX_SIZE, 1)) {
  1055. mlx4_err(dev, "%s: Failed reading inbox (cmd:0x%x)\n",
  1056. __func__, cmd->opcode);
  1057. vhcr_cmd->status = CMD_STAT_INTERNAL_ERR;
  1058. goto out_status;
  1059. }
  1060. }
  1061. /* Apply permission and bound checks if applicable */
  1062. if (cmd->verify && cmd->verify(dev, slave, vhcr, inbox)) {
  1063. mlx4_warn(dev, "Command:0x%x from slave: %d failed protection "
  1064. "checks for resource_id:%d\n", vhcr->op, slave,
  1065. vhcr->in_modifier);
  1066. vhcr_cmd->status = CMD_STAT_BAD_OP;
  1067. goto out_status;
  1068. }
  1069. /* Allocate outbox */
  1070. if (cmd->has_outbox) {
  1071. outbox = mlx4_alloc_cmd_mailbox(dev);
  1072. if (IS_ERR(outbox)) {
  1073. vhcr_cmd->status = CMD_STAT_BAD_SIZE;
  1074. outbox = NULL;
  1075. goto out_status;
  1076. }
  1077. }
  1078. /* Execute the command! */
  1079. if (cmd->wrapper) {
  1080. err = cmd->wrapper(dev, slave, vhcr, inbox, outbox,
  1081. cmd);
  1082. if (cmd->out_is_imm)
  1083. vhcr_cmd->out_param = cpu_to_be64(vhcr->out_param);
  1084. } else {
  1085. in_param = cmd->has_inbox ? (u64) inbox->dma :
  1086. vhcr->in_param;
  1087. out_param = cmd->has_outbox ? (u64) outbox->dma :
  1088. vhcr->out_param;
  1089. err = __mlx4_cmd(dev, in_param, &out_param,
  1090. cmd->out_is_imm, vhcr->in_modifier,
  1091. vhcr->op_modifier, vhcr->op,
  1092. MLX4_CMD_TIME_CLASS_A,
  1093. MLX4_CMD_NATIVE);
  1094. if (cmd->out_is_imm) {
  1095. vhcr->out_param = out_param;
  1096. vhcr_cmd->out_param = cpu_to_be64(vhcr->out_param);
  1097. }
  1098. }
  1099. if (err) {
  1100. mlx4_warn(dev, "vhcr command:0x%x slave:%d failed with"
  1101. " error:%d, status %d\n",
  1102. vhcr->op, slave, vhcr->errno, err);
  1103. vhcr_cmd->status = mlx4_errno_to_status(err);
  1104. goto out_status;
  1105. }
  1106. /* Write outbox if command completed successfully */
  1107. if (cmd->has_outbox && !vhcr_cmd->status) {
  1108. ret = mlx4_ACCESS_MEM(dev, outbox->dma, slave,
  1109. vhcr->out_param,
  1110. MLX4_MAILBOX_SIZE, MLX4_CMD_WRAPPED);
  1111. if (ret) {
  1112. /* If we failed to write back the outbox after the
  1113. *command was successfully executed, we must fail this
  1114. * slave, as it is now in undefined state */
  1115. mlx4_err(dev, "%s:Failed writing outbox\n", __func__);
  1116. goto out;
  1117. }
  1118. }
  1119. out_status:
  1120. /* DMA back vhcr result */
  1121. if (!in_vhcr) {
  1122. ret = mlx4_ACCESS_MEM(dev, priv->mfunc.vhcr_dma, slave,
  1123. priv->mfunc.master.slave_state[slave].vhcr_dma,
  1124. ALIGN(sizeof(struct mlx4_vhcr),
  1125. MLX4_ACCESS_MEM_ALIGN),
  1126. MLX4_CMD_WRAPPED);
  1127. if (ret)
  1128. mlx4_err(dev, "%s:Failed writing vhcr result\n",
  1129. __func__);
  1130. else if (vhcr->e_bit &&
  1131. mlx4_GEN_EQE(dev, slave, &priv->mfunc.master.cmd_eqe))
  1132. mlx4_warn(dev, "Failed to generate command completion "
  1133. "eqe for slave %d\n", slave);
  1134. }
  1135. out:
  1136. kfree(vhcr);
  1137. mlx4_free_cmd_mailbox(dev, inbox);
  1138. mlx4_free_cmd_mailbox(dev, outbox);
  1139. return ret;
  1140. }
  1141. static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd,
  1142. u16 param, u8 toggle)
  1143. {
  1144. struct mlx4_priv *priv = mlx4_priv(dev);
  1145. struct mlx4_slave_state *slave_state = priv->mfunc.master.slave_state;
  1146. u32 reply;
  1147. u32 slave_status = 0;
  1148. u8 is_going_down = 0;
  1149. slave_state[slave].comm_toggle ^= 1;
  1150. reply = (u32) slave_state[slave].comm_toggle << 31;
  1151. if (toggle != slave_state[slave].comm_toggle) {
  1152. mlx4_warn(dev, "Incorrect toggle %d from slave %d. *** MASTER"
  1153. "STATE COMPROMISIED ***\n", toggle, slave);
  1154. goto reset_slave;
  1155. }
  1156. if (cmd == MLX4_COMM_CMD_RESET) {
  1157. mlx4_warn(dev, "Received reset from slave:%d\n", slave);
  1158. slave_state[slave].active = false;
  1159. /*check if we are in the middle of FLR process,
  1160. if so return "retry" status to the slave*/
  1161. if (MLX4_COMM_CMD_FLR == slave_state[slave].last_cmd) {
  1162. slave_status = MLX4_DELAY_RESET_SLAVE;
  1163. goto inform_slave_state;
  1164. }
  1165. /* write the version in the event field */
  1166. reply |= mlx4_comm_get_version();
  1167. goto reset_slave;
  1168. }
  1169. /*command from slave in the middle of FLR*/
  1170. if (cmd != MLX4_COMM_CMD_RESET &&
  1171. MLX4_COMM_CMD_FLR == slave_state[slave].last_cmd) {
  1172. mlx4_warn(dev, "slave:%d is Trying to run cmd(0x%x) "
  1173. "in the middle of FLR\n", slave, cmd);
  1174. return;
  1175. }
  1176. switch (cmd) {
  1177. case MLX4_COMM_CMD_VHCR0:
  1178. if (slave_state[slave].last_cmd != MLX4_COMM_CMD_RESET)
  1179. goto reset_slave;
  1180. slave_state[slave].vhcr_dma = ((u64) param) << 48;
  1181. priv->mfunc.master.slave_state[slave].cookie = 0;
  1182. mutex_init(&priv->mfunc.master.gen_eqe_mutex[slave]);
  1183. break;
  1184. case MLX4_COMM_CMD_VHCR1:
  1185. if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR0)
  1186. goto reset_slave;
  1187. slave_state[slave].vhcr_dma |= ((u64) param) << 32;
  1188. break;
  1189. case MLX4_COMM_CMD_VHCR2:
  1190. if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR1)
  1191. goto reset_slave;
  1192. slave_state[slave].vhcr_dma |= ((u64) param) << 16;
  1193. break;
  1194. case MLX4_COMM_CMD_VHCR_EN:
  1195. if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR2)
  1196. goto reset_slave;
  1197. slave_state[slave].vhcr_dma |= param;
  1198. slave_state[slave].active = true;
  1199. break;
  1200. case MLX4_COMM_CMD_VHCR_POST:
  1201. if ((slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR_EN) &&
  1202. (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR_POST))
  1203. goto reset_slave;
  1204. down(&priv->cmd.slave_sem);
  1205. if (mlx4_master_process_vhcr(dev, slave, NULL)) {
  1206. mlx4_err(dev, "Failed processing vhcr for slave:%d,"
  1207. " reseting slave.\n", slave);
  1208. up(&priv->cmd.slave_sem);
  1209. goto reset_slave;
  1210. }
  1211. up(&priv->cmd.slave_sem);
  1212. break;
  1213. default:
  1214. mlx4_warn(dev, "Bad comm cmd:%d from slave:%d\n", cmd, slave);
  1215. goto reset_slave;
  1216. }
  1217. spin_lock(&priv->mfunc.master.slave_state_lock);
  1218. if (!slave_state[slave].is_slave_going_down)
  1219. slave_state[slave].last_cmd = cmd;
  1220. else
  1221. is_going_down = 1;
  1222. spin_unlock(&priv->mfunc.master.slave_state_lock);
  1223. if (is_going_down) {
  1224. mlx4_warn(dev, "Slave is going down aborting command(%d)"
  1225. " executing from slave:%d\n",
  1226. cmd, slave);
  1227. return;
  1228. }
  1229. __raw_writel((__force u32) cpu_to_be32(reply),
  1230. &priv->mfunc.comm[slave].slave_read);
  1231. mmiowb();
  1232. return;
  1233. reset_slave:
  1234. /* cleanup any slave resources */
  1235. mlx4_delete_all_resources_for_slave(dev, slave);
  1236. spin_lock(&priv->mfunc.master.slave_state_lock);
  1237. if (!slave_state[slave].is_slave_going_down)
  1238. slave_state[slave].last_cmd = MLX4_COMM_CMD_RESET;
  1239. spin_unlock(&priv->mfunc.master.slave_state_lock);
  1240. /*with slave in the middle of flr, no need to clean resources again.*/
  1241. inform_slave_state:
  1242. memset(&slave_state[slave].event_eq, 0,
  1243. sizeof(struct mlx4_slave_event_eq_info));
  1244. __raw_writel((__force u32) cpu_to_be32(reply),
  1245. &priv->mfunc.comm[slave].slave_read);
  1246. wmb();
  1247. }
  1248. /* master command processing */
  1249. void mlx4_master_comm_channel(struct work_struct *work)
  1250. {
  1251. struct mlx4_mfunc_master_ctx *master =
  1252. container_of(work,
  1253. struct mlx4_mfunc_master_ctx,
  1254. comm_work);
  1255. struct mlx4_mfunc *mfunc =
  1256. container_of(master, struct mlx4_mfunc, master);
  1257. struct mlx4_priv *priv =
  1258. container_of(mfunc, struct mlx4_priv, mfunc);
  1259. struct mlx4_dev *dev = &priv->dev;
  1260. __be32 *bit_vec;
  1261. u32 comm_cmd;
  1262. u32 vec;
  1263. int i, j, slave;
  1264. int toggle;
  1265. int served = 0;
  1266. int reported = 0;
  1267. u32 slt;
  1268. bit_vec = master->comm_arm_bit_vector;
  1269. for (i = 0; i < COMM_CHANNEL_BIT_ARRAY_SIZE; i++) {
  1270. vec = be32_to_cpu(bit_vec[i]);
  1271. for (j = 0; j < 32; j++) {
  1272. if (!(vec & (1 << j)))
  1273. continue;
  1274. ++reported;
  1275. slave = (i * 32) + j;
  1276. comm_cmd = swab32(readl(
  1277. &mfunc->comm[slave].slave_write));
  1278. slt = swab32(readl(&mfunc->comm[slave].slave_read))
  1279. >> 31;
  1280. toggle = comm_cmd >> 31;
  1281. if (toggle != slt) {
  1282. if (master->slave_state[slave].comm_toggle
  1283. != slt) {
  1284. printk(KERN_INFO "slave %d out of sync."
  1285. " read toggle %d, state toggle %d. "
  1286. "Resynching.\n", slave, slt,
  1287. master->slave_state[slave].comm_toggle);
  1288. master->slave_state[slave].comm_toggle =
  1289. slt;
  1290. }
  1291. mlx4_master_do_cmd(dev, slave,
  1292. comm_cmd >> 16 & 0xff,
  1293. comm_cmd & 0xffff, toggle);
  1294. ++served;
  1295. }
  1296. }
  1297. }
  1298. if (reported && reported != served)
  1299. mlx4_warn(dev, "Got command event with bitmask from %d slaves"
  1300. " but %d were served\n",
  1301. reported, served);
  1302. if (mlx4_ARM_COMM_CHANNEL(dev))
  1303. mlx4_warn(dev, "Failed to arm comm channel events\n");
  1304. }
  1305. static int sync_toggles(struct mlx4_dev *dev)
  1306. {
  1307. struct mlx4_priv *priv = mlx4_priv(dev);
  1308. int wr_toggle;
  1309. int rd_toggle;
  1310. unsigned long end;
  1311. wr_toggle = swab32(readl(&priv->mfunc.comm->slave_write)) >> 31;
  1312. end = jiffies + msecs_to_jiffies(5000);
  1313. while (time_before(jiffies, end)) {
  1314. rd_toggle = swab32(readl(&priv->mfunc.comm->slave_read)) >> 31;
  1315. if (rd_toggle == wr_toggle) {
  1316. priv->cmd.comm_toggle = rd_toggle;
  1317. return 0;
  1318. }
  1319. cond_resched();
  1320. }
  1321. /*
  1322. * we could reach here if for example the previous VM using this
  1323. * function misbehaved and left the channel with unsynced state. We
  1324. * should fix this here and give this VM a chance to use a properly
  1325. * synced channel
  1326. */
  1327. mlx4_warn(dev, "recovering from previously mis-behaved VM\n");
  1328. __raw_writel((__force u32) 0, &priv->mfunc.comm->slave_read);
  1329. __raw_writel((__force u32) 0, &priv->mfunc.comm->slave_write);
  1330. priv->cmd.comm_toggle = 0;
  1331. return 0;
  1332. }
  1333. int mlx4_multi_func_init(struct mlx4_dev *dev)
  1334. {
  1335. struct mlx4_priv *priv = mlx4_priv(dev);
  1336. struct mlx4_slave_state *s_state;
  1337. int i, err, port;
  1338. priv->mfunc.vhcr = dma_alloc_coherent(&(dev->pdev->dev), PAGE_SIZE,
  1339. &priv->mfunc.vhcr_dma,
  1340. GFP_KERNEL);
  1341. if (!priv->mfunc.vhcr) {
  1342. mlx4_err(dev, "Couldn't allocate vhcr.\n");
  1343. return -ENOMEM;
  1344. }
  1345. if (mlx4_is_master(dev))
  1346. priv->mfunc.comm =
  1347. ioremap(pci_resource_start(dev->pdev, priv->fw.comm_bar) +
  1348. priv->fw.comm_base, MLX4_COMM_PAGESIZE);
  1349. else
  1350. priv->mfunc.comm =
  1351. ioremap(pci_resource_start(dev->pdev, 2) +
  1352. MLX4_SLAVE_COMM_BASE, MLX4_COMM_PAGESIZE);
  1353. if (!priv->mfunc.comm) {
  1354. mlx4_err(dev, "Couldn't map communication vector.\n");
  1355. goto err_vhcr;
  1356. }
  1357. if (mlx4_is_master(dev)) {
  1358. priv->mfunc.master.slave_state =
  1359. kzalloc(dev->num_slaves *
  1360. sizeof(struct mlx4_slave_state), GFP_KERNEL);
  1361. if (!priv->mfunc.master.slave_state)
  1362. goto err_comm;
  1363. for (i = 0; i < dev->num_slaves; ++i) {
  1364. s_state = &priv->mfunc.master.slave_state[i];
  1365. s_state->last_cmd = MLX4_COMM_CMD_RESET;
  1366. __raw_writel((__force u32) 0,
  1367. &priv->mfunc.comm[i].slave_write);
  1368. __raw_writel((__force u32) 0,
  1369. &priv->mfunc.comm[i].slave_read);
  1370. mmiowb();
  1371. for (port = 1; port <= MLX4_MAX_PORTS; port++) {
  1372. s_state->vlan_filter[port] =
  1373. kzalloc(sizeof(struct mlx4_vlan_fltr),
  1374. GFP_KERNEL);
  1375. if (!s_state->vlan_filter[port]) {
  1376. if (--port)
  1377. kfree(s_state->vlan_filter[port]);
  1378. goto err_slaves;
  1379. }
  1380. INIT_LIST_HEAD(&s_state->mcast_filters[port]);
  1381. }
  1382. spin_lock_init(&s_state->lock);
  1383. }
  1384. memset(&priv->mfunc.master.cmd_eqe, 0, sizeof(struct mlx4_eqe));
  1385. priv->mfunc.master.cmd_eqe.type = MLX4_EVENT_TYPE_CMD;
  1386. INIT_WORK(&priv->mfunc.master.comm_work,
  1387. mlx4_master_comm_channel);
  1388. INIT_WORK(&priv->mfunc.master.slave_event_work,
  1389. mlx4_gen_slave_eqe);
  1390. INIT_WORK(&priv->mfunc.master.slave_flr_event_work,
  1391. mlx4_master_handle_slave_flr);
  1392. spin_lock_init(&priv->mfunc.master.slave_state_lock);
  1393. priv->mfunc.master.comm_wq =
  1394. create_singlethread_workqueue("mlx4_comm");
  1395. if (!priv->mfunc.master.comm_wq)
  1396. goto err_slaves;
  1397. if (mlx4_init_resource_tracker(dev))
  1398. goto err_thread;
  1399. sema_init(&priv->cmd.slave_sem, 1);
  1400. err = mlx4_ARM_COMM_CHANNEL(dev);
  1401. if (err) {
  1402. mlx4_err(dev, " Failed to arm comm channel eq: %x\n",
  1403. err);
  1404. goto err_resource;
  1405. }
  1406. } else {
  1407. err = sync_toggles(dev);
  1408. if (err) {
  1409. mlx4_err(dev, "Couldn't sync toggles\n");
  1410. goto err_comm;
  1411. }
  1412. sema_init(&priv->cmd.slave_sem, 1);
  1413. }
  1414. return 0;
  1415. err_resource:
  1416. mlx4_free_resource_tracker(dev);
  1417. err_thread:
  1418. flush_workqueue(priv->mfunc.master.comm_wq);
  1419. destroy_workqueue(priv->mfunc.master.comm_wq);
  1420. err_slaves:
  1421. while (--i) {
  1422. for (port = 1; port <= MLX4_MAX_PORTS; port++)
  1423. kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]);
  1424. }
  1425. kfree(priv->mfunc.master.slave_state);
  1426. err_comm:
  1427. iounmap(priv->mfunc.comm);
  1428. err_vhcr:
  1429. dma_free_coherent(&(dev->pdev->dev), PAGE_SIZE,
  1430. priv->mfunc.vhcr,
  1431. priv->mfunc.vhcr_dma);
  1432. priv->mfunc.vhcr = NULL;
  1433. return -ENOMEM;
  1434. }
  1435. int mlx4_cmd_init(struct mlx4_dev *dev)
  1436. {
  1437. struct mlx4_priv *priv = mlx4_priv(dev);
  1438. mutex_init(&priv->cmd.hcr_mutex);
  1439. sema_init(&priv->cmd.poll_sem, 1);
  1440. priv->cmd.use_events = 0;
  1441. priv->cmd.toggle = 1;
  1442. priv->cmd.hcr = NULL;
  1443. priv->mfunc.vhcr = NULL;
  1444. if (!mlx4_is_slave(dev)) {
  1445. priv->cmd.hcr = ioremap(pci_resource_start(dev->pdev, 0) +
  1446. MLX4_HCR_BASE, MLX4_HCR_SIZE);
  1447. if (!priv->cmd.hcr) {
  1448. mlx4_err(dev, "Couldn't map command register.\n");
  1449. return -ENOMEM;
  1450. }
  1451. }
  1452. priv->cmd.pool = pci_pool_create("mlx4_cmd", dev->pdev,
  1453. MLX4_MAILBOX_SIZE,
  1454. MLX4_MAILBOX_SIZE, 0);
  1455. if (!priv->cmd.pool)
  1456. goto err_hcr;
  1457. return 0;
  1458. err_hcr:
  1459. if (!mlx4_is_slave(dev))
  1460. iounmap(priv->cmd.hcr);
  1461. return -ENOMEM;
  1462. }
  1463. void mlx4_multi_func_cleanup(struct mlx4_dev *dev)
  1464. {
  1465. struct mlx4_priv *priv = mlx4_priv(dev);
  1466. int i, port;
  1467. if (mlx4_is_master(dev)) {
  1468. flush_workqueue(priv->mfunc.master.comm_wq);
  1469. destroy_workqueue(priv->mfunc.master.comm_wq);
  1470. for (i = 0; i < dev->num_slaves; i++) {
  1471. for (port = 1; port <= MLX4_MAX_PORTS; port++)
  1472. kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]);
  1473. }
  1474. kfree(priv->mfunc.master.slave_state);
  1475. iounmap(priv->mfunc.comm);
  1476. dma_free_coherent(&(dev->pdev->dev), PAGE_SIZE,
  1477. priv->mfunc.vhcr,
  1478. priv->mfunc.vhcr_dma);
  1479. priv->mfunc.vhcr = NULL;
  1480. }
  1481. }
  1482. void mlx4_cmd_cleanup(struct mlx4_dev *dev)
  1483. {
  1484. struct mlx4_priv *priv = mlx4_priv(dev);
  1485. pci_pool_destroy(priv->cmd.pool);
  1486. if (!mlx4_is_slave(dev))
  1487. iounmap(priv->cmd.hcr);
  1488. }
  1489. /*
  1490. * Switch to using events to issue FW commands (can only be called
  1491. * after event queue for command events has been initialized).
  1492. */
  1493. int mlx4_cmd_use_events(struct mlx4_dev *dev)
  1494. {
  1495. struct mlx4_priv *priv = mlx4_priv(dev);
  1496. int i;
  1497. int err = 0;
  1498. priv->cmd.context = kmalloc(priv->cmd.max_cmds *
  1499. sizeof (struct mlx4_cmd_context),
  1500. GFP_KERNEL);
  1501. if (!priv->cmd.context)
  1502. return -ENOMEM;
  1503. for (i = 0; i < priv->cmd.max_cmds; ++i) {
  1504. priv->cmd.context[i].token = i;
  1505. priv->cmd.context[i].next = i + 1;
  1506. }
  1507. priv->cmd.context[priv->cmd.max_cmds - 1].next = -1;
  1508. priv->cmd.free_head = 0;
  1509. sema_init(&priv->cmd.event_sem, priv->cmd.max_cmds);
  1510. spin_lock_init(&priv->cmd.context_lock);
  1511. for (priv->cmd.token_mask = 1;
  1512. priv->cmd.token_mask < priv->cmd.max_cmds;
  1513. priv->cmd.token_mask <<= 1)
  1514. ; /* nothing */
  1515. --priv->cmd.token_mask;
  1516. down(&priv->cmd.poll_sem);
  1517. priv->cmd.use_events = 1;
  1518. return err;
  1519. }
  1520. /*
  1521. * Switch back to polling (used when shutting down the device)
  1522. */
  1523. void mlx4_cmd_use_polling(struct mlx4_dev *dev)
  1524. {
  1525. struct mlx4_priv *priv = mlx4_priv(dev);
  1526. int i;
  1527. priv->cmd.use_events = 0;
  1528. for (i = 0; i < priv->cmd.max_cmds; ++i)
  1529. down(&priv->cmd.event_sem);
  1530. kfree(priv->cmd.context);
  1531. up(&priv->cmd.poll_sem);
  1532. }
  1533. struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct mlx4_dev *dev)
  1534. {
  1535. struct mlx4_cmd_mailbox *mailbox;
  1536. mailbox = kmalloc(sizeof *mailbox, GFP_KERNEL);
  1537. if (!mailbox)
  1538. return ERR_PTR(-ENOMEM);
  1539. mailbox->buf = pci_pool_alloc(mlx4_priv(dev)->cmd.pool, GFP_KERNEL,
  1540. &mailbox->dma);
  1541. if (!mailbox->buf) {
  1542. kfree(mailbox);
  1543. return ERR_PTR(-ENOMEM);
  1544. }
  1545. return mailbox;
  1546. }
  1547. EXPORT_SYMBOL_GPL(mlx4_alloc_cmd_mailbox);
  1548. void mlx4_free_cmd_mailbox(struct mlx4_dev *dev,
  1549. struct mlx4_cmd_mailbox *mailbox)
  1550. {
  1551. if (!mailbox)
  1552. return;
  1553. pci_pool_free(mlx4_priv(dev)->cmd.pool, mailbox->buf, mailbox->dma);
  1554. kfree(mailbox);
  1555. }
  1556. EXPORT_SYMBOL_GPL(mlx4_free_cmd_mailbox);
  1557. u32 mlx4_comm_get_version(void)
  1558. {
  1559. return ((u32) CMD_CHAN_IF_REV << 8) | (u32) CMD_CHAN_VER;
  1560. }