/drivers/net/ethernet/mellanox/mlx4/cmd.c
http://github.com/mirrors/linux · C · 3430 lines · 2817 code · 388 blank · 225 comment · 458 complexity · 4553e48983bda30e59056f4e3ff26bb7 MD5 · raw file
Large files are truncated click here to view the full file
- /*
- * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
- * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
- * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
- *
- * This software is available to you under a choice of one of two
- * licenses. You may choose to be licensed under the terms of the GNU
- * General Public License (GPL) Version 2, available from the file
- * COPYING in the main directory of this source tree, or the
- * OpenIB.org BSD license below:
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the following
- * disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
- #include <linux/sched.h>
- #include <linux/slab.h>
- #include <linux/export.h>
- #include <linux/pci.h>
- #include <linux/errno.h>
- #include <linux/mlx4/cmd.h>
- #include <linux/mlx4/device.h>
- #include <linux/semaphore.h>
- #include <rdma/ib_smi.h>
- #include <linux/delay.h>
- #include <linux/etherdevice.h>
- #include <asm/io.h>
- #include "mlx4.h"
- #include "fw.h"
- #include "fw_qos.h"
- #include "mlx4_stats.h"
- #define CMD_POLL_TOKEN 0xffff
- #define INBOX_MASK 0xffffffffffffff00ULL
- #define CMD_CHAN_VER 1
- #define CMD_CHAN_IF_REV 1
- enum {
- /* command completed successfully: */
- CMD_STAT_OK = 0x00,
- /* Internal error (such as a bus error) occurred while processing command: */
- CMD_STAT_INTERNAL_ERR = 0x01,
- /* Operation/command not supported or opcode modifier not supported: */
- CMD_STAT_BAD_OP = 0x02,
- /* Parameter not supported or parameter out of range: */
- CMD_STAT_BAD_PARAM = 0x03,
- /* System not enabled or bad system state: */
- CMD_STAT_BAD_SYS_STATE = 0x04,
- /* Attempt to access reserved or unallocaterd resource: */
- CMD_STAT_BAD_RESOURCE = 0x05,
- /* Requested resource is currently executing a command, or is otherwise busy: */
- CMD_STAT_RESOURCE_BUSY = 0x06,
- /* Required capability exceeds device limits: */
- CMD_STAT_EXCEED_LIM = 0x08,
- /* Resource is not in the appropriate state or ownership: */
- CMD_STAT_BAD_RES_STATE = 0x09,
- /* Index out of range: */
- CMD_STAT_BAD_INDEX = 0x0a,
- /* FW image corrupted: */
- CMD_STAT_BAD_NVMEM = 0x0b,
- /* Error in ICM mapping (e.g. not enough auxiliary ICM pages to execute command): */
- CMD_STAT_ICM_ERROR = 0x0c,
- /* Attempt to modify a QP/EE which is not in the presumed state: */
- CMD_STAT_BAD_QP_STATE = 0x10,
- /* Bad segment parameters (Address/Size): */
- CMD_STAT_BAD_SEG_PARAM = 0x20,
- /* Memory Region has Memory Windows bound to: */
- CMD_STAT_REG_BOUND = 0x21,
- /* HCA local attached memory not present: */
- CMD_STAT_LAM_NOT_PRE = 0x22,
- /* Bad management packet (silently discarded): */
- CMD_STAT_BAD_PKT = 0x30,
- /* More outstanding CQEs in CQ than new CQ size: */
- CMD_STAT_BAD_SIZE = 0x40,
- /* Multi Function device support required: */
- CMD_STAT_MULTI_FUNC_REQ = 0x50,
- };
- enum {
- HCR_IN_PARAM_OFFSET = 0x00,
- HCR_IN_MODIFIER_OFFSET = 0x08,
- HCR_OUT_PARAM_OFFSET = 0x0c,
- HCR_TOKEN_OFFSET = 0x14,
- HCR_STATUS_OFFSET = 0x18,
- HCR_OPMOD_SHIFT = 12,
- HCR_T_BIT = 21,
- HCR_E_BIT = 22,
- HCR_GO_BIT = 23
- };
- enum {
- GO_BIT_TIMEOUT_MSECS = 10000
- };
- enum mlx4_vlan_transition {
- MLX4_VLAN_TRANSITION_VST_VST = 0,
- MLX4_VLAN_TRANSITION_VST_VGT = 1,
- MLX4_VLAN_TRANSITION_VGT_VST = 2,
- MLX4_VLAN_TRANSITION_VGT_VGT = 3,
- };
- struct mlx4_cmd_context {
- struct completion done;
- int result;
- int next;
- u64 out_param;
- u16 token;
- u8 fw_status;
- };
- static int mlx4_master_process_vhcr(struct mlx4_dev *dev, int slave,
- struct mlx4_vhcr_cmd *in_vhcr);
- static int mlx4_status_to_errno(u8 status)
- {
- static const int trans_table[] = {
- [CMD_STAT_INTERNAL_ERR] = -EIO,
- [CMD_STAT_BAD_OP] = -EPERM,
- [CMD_STAT_BAD_PARAM] = -EINVAL,
- [CMD_STAT_BAD_SYS_STATE] = -ENXIO,
- [CMD_STAT_BAD_RESOURCE] = -EBADF,
- [CMD_STAT_RESOURCE_BUSY] = -EBUSY,
- [CMD_STAT_EXCEED_LIM] = -ENOMEM,
- [CMD_STAT_BAD_RES_STATE] = -EBADF,
- [CMD_STAT_BAD_INDEX] = -EBADF,
- [CMD_STAT_BAD_NVMEM] = -EFAULT,
- [CMD_STAT_ICM_ERROR] = -ENFILE,
- [CMD_STAT_BAD_QP_STATE] = -EINVAL,
- [CMD_STAT_BAD_SEG_PARAM] = -EFAULT,
- [CMD_STAT_REG_BOUND] = -EBUSY,
- [CMD_STAT_LAM_NOT_PRE] = -EAGAIN,
- [CMD_STAT_BAD_PKT] = -EINVAL,
- [CMD_STAT_BAD_SIZE] = -ENOMEM,
- [CMD_STAT_MULTI_FUNC_REQ] = -EACCES,
- };
- if (status >= ARRAY_SIZE(trans_table) ||
- (status != CMD_STAT_OK && trans_table[status] == 0))
- return -EIO;
- return trans_table[status];
- }
- static u8 mlx4_errno_to_status(int errno)
- {
- switch (errno) {
- case -EPERM:
- return CMD_STAT_BAD_OP;
- case -EINVAL:
- return CMD_STAT_BAD_PARAM;
- case -ENXIO:
- return CMD_STAT_BAD_SYS_STATE;
- case -EBUSY:
- return CMD_STAT_RESOURCE_BUSY;
- case -ENOMEM:
- return CMD_STAT_EXCEED_LIM;
- case -ENFILE:
- return CMD_STAT_ICM_ERROR;
- default:
- return CMD_STAT_INTERNAL_ERR;
- }
- }
- static int mlx4_internal_err_ret_value(struct mlx4_dev *dev, u16 op,
- u8 op_modifier)
- {
- switch (op) {
- case MLX4_CMD_UNMAP_ICM:
- case MLX4_CMD_UNMAP_ICM_AUX:
- case MLX4_CMD_UNMAP_FA:
- case MLX4_CMD_2RST_QP:
- case MLX4_CMD_HW2SW_EQ:
- case MLX4_CMD_HW2SW_CQ:
- case MLX4_CMD_HW2SW_SRQ:
- case MLX4_CMD_HW2SW_MPT:
- case MLX4_CMD_CLOSE_HCA:
- case MLX4_QP_FLOW_STEERING_DETACH:
- case MLX4_CMD_FREE_RES:
- case MLX4_CMD_CLOSE_PORT:
- return CMD_STAT_OK;
- case MLX4_CMD_QP_ATTACH:
- /* On Detach case return success */
- if (op_modifier == 0)
- return CMD_STAT_OK;
- return mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
- default:
- return mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
- }
- }
- static int mlx4_closing_cmd_fatal_error(u16 op, u8 fw_status)
- {
- /* Any error during the closing commands below is considered fatal */
- if (op == MLX4_CMD_CLOSE_HCA ||
- op == MLX4_CMD_HW2SW_EQ ||
- op == MLX4_CMD_HW2SW_CQ ||
- op == MLX4_CMD_2RST_QP ||
- op == MLX4_CMD_HW2SW_SRQ ||
- op == MLX4_CMD_SYNC_TPT ||
- op == MLX4_CMD_UNMAP_ICM ||
- op == MLX4_CMD_UNMAP_ICM_AUX ||
- op == MLX4_CMD_UNMAP_FA)
- return 1;
- /* Error on MLX4_CMD_HW2SW_MPT is fatal except when fw status equals
- * CMD_STAT_REG_BOUND.
- * This status indicates that memory region has memory windows bound to it
- * which may result from invalid user space usage and is not fatal.
- */
- if (op == MLX4_CMD_HW2SW_MPT && fw_status != CMD_STAT_REG_BOUND)
- return 1;
- return 0;
- }
- static int mlx4_cmd_reset_flow(struct mlx4_dev *dev, u16 op, u8 op_modifier,
- int err)
- {
- /* Only if reset flow is really active return code is based on
- * command, otherwise current error code is returned.
- */
- if (mlx4_internal_err_reset) {
- mlx4_enter_error_state(dev->persist);
- err = mlx4_internal_err_ret_value(dev, op, op_modifier);
- }
- return err;
- }
- static int comm_pending(struct mlx4_dev *dev)
- {
- struct mlx4_priv *priv = mlx4_priv(dev);
- u32 status = readl(&priv->mfunc.comm->slave_read);
- return (swab32(status) >> 31) != priv->cmd.comm_toggle;
- }
- static int mlx4_comm_cmd_post(struct mlx4_dev *dev, u8 cmd, u16 param)
- {
- struct mlx4_priv *priv = mlx4_priv(dev);
- u32 val;
- /* To avoid writing to unknown addresses after the device state was
- * changed to internal error and the function was rest,
- * check the INTERNAL_ERROR flag which is updated under
- * device_state_mutex lock.
- */
- mutex_lock(&dev->persist->device_state_mutex);
- if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR) {
- mutex_unlock(&dev->persist->device_state_mutex);
- return -EIO;
- }
- priv->cmd.comm_toggle ^= 1;
- val = param | (cmd << 16) | (priv->cmd.comm_toggle << 31);
- __raw_writel((__force u32) cpu_to_be32(val),
- &priv->mfunc.comm->slave_write);
- mutex_unlock(&dev->persist->device_state_mutex);
- return 0;
- }
- static int mlx4_comm_cmd_poll(struct mlx4_dev *dev, u8 cmd, u16 param,
- unsigned long timeout)
- {
- struct mlx4_priv *priv = mlx4_priv(dev);
- unsigned long end;
- int err = 0;
- int ret_from_pending = 0;
- /* First, verify that the master reports correct status */
- if (comm_pending(dev)) {
- mlx4_warn(dev, "Communication channel is not idle - my toggle is %d (cmd:0x%x)\n",
- priv->cmd.comm_toggle, cmd);
- return -EAGAIN;
- }
- /* Write command */
- down(&priv->cmd.poll_sem);
- if (mlx4_comm_cmd_post(dev, cmd, param)) {
- /* Only in case the device state is INTERNAL_ERROR,
- * mlx4_comm_cmd_post returns with an error
- */
- err = mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
- goto out;
- }
- end = msecs_to_jiffies(timeout) + jiffies;
- while (comm_pending(dev) && time_before(jiffies, end))
- cond_resched();
- ret_from_pending = comm_pending(dev);
- if (ret_from_pending) {
- /* check if the slave is trying to boot in the middle of
- * FLR process. The only non-zero result in the RESET command
- * is MLX4_DELAY_RESET_SLAVE*/
- if ((MLX4_COMM_CMD_RESET == cmd)) {
- err = MLX4_DELAY_RESET_SLAVE;
- goto out;
- } else {
- mlx4_warn(dev, "Communication channel command 0x%x timed out\n",
- cmd);
- err = mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
- }
- }
- if (err)
- mlx4_enter_error_state(dev->persist);
- out:
- up(&priv->cmd.poll_sem);
- return err;
- }
- static int mlx4_comm_cmd_wait(struct mlx4_dev *dev, u8 vhcr_cmd,
- u16 param, u16 op, unsigned long timeout)
- {
- struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
- struct mlx4_cmd_context *context;
- unsigned long end;
- int err = 0;
- down(&cmd->event_sem);
- spin_lock(&cmd->context_lock);
- BUG_ON(cmd->free_head < 0);
- context = &cmd->context[cmd->free_head];
- context->token += cmd->token_mask + 1;
- cmd->free_head = context->next;
- spin_unlock(&cmd->context_lock);
- reinit_completion(&context->done);
- if (mlx4_comm_cmd_post(dev, vhcr_cmd, param)) {
- /* Only in case the device state is INTERNAL_ERROR,
- * mlx4_comm_cmd_post returns with an error
- */
- err = mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
- goto out;
- }
- if (!wait_for_completion_timeout(&context->done,
- msecs_to_jiffies(timeout))) {
- mlx4_warn(dev, "communication channel command 0x%x (op=0x%x) timed out\n",
- vhcr_cmd, op);
- goto out_reset;
- }
- err = context->result;
- if (err && context->fw_status != CMD_STAT_MULTI_FUNC_REQ) {
- mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n",
- vhcr_cmd, context->fw_status);
- if (mlx4_closing_cmd_fatal_error(op, context->fw_status))
- goto out_reset;
- }
- /* wait for comm channel ready
- * this is necessary for prevention the race
- * when switching between event to polling mode
- * Skipping this section in case the device is in FATAL_ERROR state,
- * In this state, no commands are sent via the comm channel until
- * the device has returned from reset.
- */
- if (!(dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)) {
- end = msecs_to_jiffies(timeout) + jiffies;
- while (comm_pending(dev) && time_before(jiffies, end))
- cond_resched();
- }
- goto out;
- out_reset:
- err = mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
- mlx4_enter_error_state(dev->persist);
- out:
- spin_lock(&cmd->context_lock);
- context->next = cmd->free_head;
- cmd->free_head = context - cmd->context;
- spin_unlock(&cmd->context_lock);
- up(&cmd->event_sem);
- return err;
- }
- int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param,
- u16 op, unsigned long timeout)
- {
- if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)
- return mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
- if (mlx4_priv(dev)->cmd.use_events)
- return mlx4_comm_cmd_wait(dev, cmd, param, op, timeout);
- return mlx4_comm_cmd_poll(dev, cmd, param, timeout);
- }
- static int cmd_pending(struct mlx4_dev *dev)
- {
- u32 status;
- if (pci_channel_offline(dev->persist->pdev))
- return -EIO;
- status = readl(mlx4_priv(dev)->cmd.hcr + HCR_STATUS_OFFSET);
- return (status & swab32(1 << HCR_GO_BIT)) ||
- (mlx4_priv(dev)->cmd.toggle ==
- !!(status & swab32(1 << HCR_T_BIT)));
- }
- static int mlx4_cmd_post(struct mlx4_dev *dev, u64 in_param, u64 out_param,
- u32 in_modifier, u8 op_modifier, u16 op, u16 token,
- int event)
- {
- struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
- u32 __iomem *hcr = cmd->hcr;
- int ret = -EIO;
- unsigned long end;
- mutex_lock(&dev->persist->device_state_mutex);
- /* To avoid writing to unknown addresses after the device state was
- * changed to internal error and the chip was reset,
- * check the INTERNAL_ERROR flag which is updated under
- * device_state_mutex lock.
- */
- if (pci_channel_offline(dev->persist->pdev) ||
- (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)) {
- /*
- * Device is going through error recovery
- * and cannot accept commands.
- */
- goto out;
- }
- end = jiffies;
- if (event)
- end += msecs_to_jiffies(GO_BIT_TIMEOUT_MSECS);
- while (cmd_pending(dev)) {
- if (pci_channel_offline(dev->persist->pdev)) {
- /*
- * Device is going through error recovery
- * and cannot accept commands.
- */
- goto out;
- }
- if (time_after_eq(jiffies, end)) {
- mlx4_err(dev, "%s:cmd_pending failed\n", __func__);
- goto out;
- }
- cond_resched();
- }
- /*
- * We use writel (instead of something like memcpy_toio)
- * because writes of less than 32 bits to the HCR don't work
- * (and some architectures such as ia64 implement memcpy_toio
- * in terms of writeb).
- */
- __raw_writel((__force u32) cpu_to_be32(in_param >> 32), hcr + 0);
- __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), hcr + 1);
- __raw_writel((__force u32) cpu_to_be32(in_modifier), hcr + 2);
- __raw_writel((__force u32) cpu_to_be32(out_param >> 32), hcr + 3);
- __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), hcr + 4);
- __raw_writel((__force u32) cpu_to_be32(token << 16), hcr + 5);
- /* __raw_writel may not order writes. */
- wmb();
- __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
- (cmd->toggle << HCR_T_BIT) |
- (event ? (1 << HCR_E_BIT) : 0) |
- (op_modifier << HCR_OPMOD_SHIFT) |
- op), hcr + 6);
- cmd->toggle = cmd->toggle ^ 1;
- ret = 0;
- out:
- if (ret)
- mlx4_warn(dev, "Could not post command 0x%x: ret=%d, in_param=0x%llx, in_mod=0x%x, op_mod=0x%x\n",
- op, ret, in_param, in_modifier, op_modifier);
- mutex_unlock(&dev->persist->device_state_mutex);
- return ret;
- }
- static int mlx4_slave_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
- int out_is_imm, u32 in_modifier, u8 op_modifier,
- u16 op, unsigned long timeout)
- {
- struct mlx4_priv *priv = mlx4_priv(dev);
- struct mlx4_vhcr_cmd *vhcr = priv->mfunc.vhcr;
- int ret;
- mutex_lock(&priv->cmd.slave_cmd_mutex);
- vhcr->in_param = cpu_to_be64(in_param);
- vhcr->out_param = out_param ? cpu_to_be64(*out_param) : 0;
- vhcr->in_modifier = cpu_to_be32(in_modifier);
- vhcr->opcode = cpu_to_be16((((u16) op_modifier) << 12) | (op & 0xfff));
- vhcr->token = cpu_to_be16(CMD_POLL_TOKEN);
- vhcr->status = 0;
- vhcr->flags = !!(priv->cmd.use_events) << 6;
- if (mlx4_is_master(dev)) {
- ret = mlx4_master_process_vhcr(dev, dev->caps.function, vhcr);
- if (!ret) {
- if (out_is_imm) {
- if (out_param)
- *out_param =
- be64_to_cpu(vhcr->out_param);
- else {
- mlx4_err(dev, "response expected while output mailbox is NULL for command 0x%x\n",
- op);
- vhcr->status = CMD_STAT_BAD_PARAM;
- }
- }
- ret = mlx4_status_to_errno(vhcr->status);
- }
- if (ret &&
- dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)
- ret = mlx4_internal_err_ret_value(dev, op, op_modifier);
- } else {
- ret = mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_POST, 0, op,
- MLX4_COMM_TIME + timeout);
- if (!ret) {
- if (out_is_imm) {
- if (out_param)
- *out_param =
- be64_to_cpu(vhcr->out_param);
- else {
- mlx4_err(dev, "response expected while output mailbox is NULL for command 0x%x\n",
- op);
- vhcr->status = CMD_STAT_BAD_PARAM;
- }
- }
- ret = mlx4_status_to_errno(vhcr->status);
- } else {
- if (dev->persist->state &
- MLX4_DEVICE_STATE_INTERNAL_ERROR)
- ret = mlx4_internal_err_ret_value(dev, op,
- op_modifier);
- else
- mlx4_err(dev, "failed execution of VHCR_POST command opcode 0x%x\n", op);
- }
- }
- mutex_unlock(&priv->cmd.slave_cmd_mutex);
- return ret;
- }
- static int mlx4_cmd_poll(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
- int out_is_imm, u32 in_modifier, u8 op_modifier,
- u16 op, unsigned long timeout)
- {
- struct mlx4_priv *priv = mlx4_priv(dev);
- void __iomem *hcr = priv->cmd.hcr;
- int err = 0;
- unsigned long end;
- u32 stat;
- down(&priv->cmd.poll_sem);
- if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR) {
- /*
- * Device is going through error recovery
- * and cannot accept commands.
- */
- err = mlx4_internal_err_ret_value(dev, op, op_modifier);
- goto out;
- }
- if (out_is_imm && !out_param) {
- mlx4_err(dev, "response expected while output mailbox is NULL for command 0x%x\n",
- op);
- err = -EINVAL;
- goto out;
- }
- err = mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
- in_modifier, op_modifier, op, CMD_POLL_TOKEN, 0);
- if (err)
- goto out_reset;
- end = msecs_to_jiffies(timeout) + jiffies;
- while (cmd_pending(dev) && time_before(jiffies, end)) {
- if (pci_channel_offline(dev->persist->pdev)) {
- /*
- * Device is going through error recovery
- * and cannot accept commands.
- */
- err = -EIO;
- goto out_reset;
- }
- if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR) {
- err = mlx4_internal_err_ret_value(dev, op, op_modifier);
- goto out;
- }
- cond_resched();
- }
- if (cmd_pending(dev)) {
- mlx4_warn(dev, "command 0x%x timed out (go bit not cleared)\n",
- op);
- err = -EIO;
- goto out_reset;
- }
- if (out_is_imm)
- *out_param =
- (u64) be32_to_cpu((__force __be32)
- __raw_readl(hcr + HCR_OUT_PARAM_OFFSET)) << 32 |
- (u64) be32_to_cpu((__force __be32)
- __raw_readl(hcr + HCR_OUT_PARAM_OFFSET + 4));
- stat = be32_to_cpu((__force __be32)
- __raw_readl(hcr + HCR_STATUS_OFFSET)) >> 24;
- err = mlx4_status_to_errno(stat);
- if (err) {
- mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n",
- op, stat);
- if (mlx4_closing_cmd_fatal_error(op, stat))
- goto out_reset;
- goto out;
- }
- out_reset:
- if (err)
- err = mlx4_cmd_reset_flow(dev, op, op_modifier, err);
- out:
- up(&priv->cmd.poll_sem);
- return err;
- }
- void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param)
- {
- struct mlx4_priv *priv = mlx4_priv(dev);
- struct mlx4_cmd_context *context =
- &priv->cmd.context[token & priv->cmd.token_mask];
- /* previously timed out command completing at long last */
- if (token != context->token)
- return;
- context->fw_status = status;
- context->result = mlx4_status_to_errno(status);
- context->out_param = out_param;
- complete(&context->done);
- }
- static int mlx4_cmd_wait(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
- int out_is_imm, u32 in_modifier, u8 op_modifier,
- u16 op, unsigned long timeout)
- {
- struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
- struct mlx4_cmd_context *context;
- long ret_wait;
- int err = 0;
- down(&cmd->event_sem);
- spin_lock(&cmd->context_lock);
- BUG_ON(cmd->free_head < 0);
- context = &cmd->context[cmd->free_head];
- context->token += cmd->token_mask + 1;
- cmd->free_head = context->next;
- spin_unlock(&cmd->context_lock);
- if (out_is_imm && !out_param) {
- mlx4_err(dev, "response expected while output mailbox is NULL for command 0x%x\n",
- op);
- err = -EINVAL;
- goto out;
- }
- reinit_completion(&context->done);
- err = mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
- in_modifier, op_modifier, op, context->token, 1);
- if (err)
- goto out_reset;
- if (op == MLX4_CMD_SENSE_PORT) {
- ret_wait =
- wait_for_completion_interruptible_timeout(&context->done,
- msecs_to_jiffies(timeout));
- if (ret_wait < 0) {
- context->fw_status = 0;
- context->out_param = 0;
- context->result = 0;
- }
- } else {
- ret_wait = (long)wait_for_completion_timeout(&context->done,
- msecs_to_jiffies(timeout));
- }
- if (!ret_wait) {
- mlx4_warn(dev, "command 0x%x timed out (go bit not cleared)\n",
- op);
- if (op == MLX4_CMD_NOP) {
- err = -EBUSY;
- goto out;
- } else {
- err = -EIO;
- goto out_reset;
- }
- }
- err = context->result;
- if (err) {
- /* Since we do not want to have this error message always
- * displayed at driver start when there are ConnectX2 HCAs
- * on the host, we deprecate the error message for this
- * specific command/input_mod/opcode_mod/fw-status to be debug.
- */
- if (op == MLX4_CMD_SET_PORT &&
- (in_modifier == 1 || in_modifier == 2) &&
- op_modifier == MLX4_SET_PORT_IB_OPCODE &&
- context->fw_status == CMD_STAT_BAD_SIZE)
- mlx4_dbg(dev, "command 0x%x failed: fw status = 0x%x\n",
- op, context->fw_status);
- else
- mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n",
- op, context->fw_status);
- if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)
- err = mlx4_internal_err_ret_value(dev, op, op_modifier);
- else if (mlx4_closing_cmd_fatal_error(op, context->fw_status))
- goto out_reset;
- goto out;
- }
- if (out_is_imm)
- *out_param = context->out_param;
- out_reset:
- if (err)
- err = mlx4_cmd_reset_flow(dev, op, op_modifier, err);
- out:
- spin_lock(&cmd->context_lock);
- context->next = cmd->free_head;
- cmd->free_head = context - cmd->context;
- spin_unlock(&cmd->context_lock);
- up(&cmd->event_sem);
- return err;
- }
- int __mlx4_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
- int out_is_imm, u32 in_modifier, u8 op_modifier,
- u16 op, unsigned long timeout, int native)
- {
- if (pci_channel_offline(dev->persist->pdev))
- return mlx4_cmd_reset_flow(dev, op, op_modifier, -EIO);
- if (!mlx4_is_mfunc(dev) || (native && mlx4_is_master(dev))) {
- int ret;
- if (dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)
- return mlx4_internal_err_ret_value(dev, op,
- op_modifier);
- down_read(&mlx4_priv(dev)->cmd.switch_sem);
- if (mlx4_priv(dev)->cmd.use_events)
- ret = mlx4_cmd_wait(dev, in_param, out_param,
- out_is_imm, in_modifier,
- op_modifier, op, timeout);
- else
- ret = mlx4_cmd_poll(dev, in_param, out_param,
- out_is_imm, in_modifier,
- op_modifier, op, timeout);
- up_read(&mlx4_priv(dev)->cmd.switch_sem);
- return ret;
- }
- return mlx4_slave_cmd(dev, in_param, out_param, out_is_imm,
- in_modifier, op_modifier, op, timeout);
- }
- EXPORT_SYMBOL_GPL(__mlx4_cmd);
- int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev *dev)
- {
- return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_ARM_COMM_CHANNEL,
- MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
- }
- static int mlx4_ACCESS_MEM(struct mlx4_dev *dev, u64 master_addr,
- int slave, u64 slave_addr,
- int size, int is_read)
- {
- u64 in_param;
- u64 out_param;
- if ((slave_addr & 0xfff) | (master_addr & 0xfff) |
- (slave & ~0x7f) | (size & 0xff)) {
- mlx4_err(dev, "Bad access mem params - slave_addr:0x%llx master_addr:0x%llx slave_id:%d size:%d\n",
- slave_addr, master_addr, slave, size);
- return -EINVAL;
- }
- if (is_read) {
- in_param = (u64) slave | slave_addr;
- out_param = (u64) dev->caps.function | master_addr;
- } else {
- in_param = (u64) dev->caps.function | master_addr;
- out_param = (u64) slave | slave_addr;
- }
- return mlx4_cmd_imm(dev, in_param, &out_param, size, 0,
- MLX4_CMD_ACCESS_MEM,
- MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
- }
- static int query_pkey_block(struct mlx4_dev *dev, u8 port, u16 index, u16 *pkey,
- struct mlx4_cmd_mailbox *inbox,
- struct mlx4_cmd_mailbox *outbox)
- {
- struct ib_smp *in_mad = (struct ib_smp *)(inbox->buf);
- struct ib_smp *out_mad = (struct ib_smp *)(outbox->buf);
- int err;
- int i;
- if (index & 0x1f)
- return -EINVAL;
- in_mad->attr_mod = cpu_to_be32(index / 32);
- err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, port, 3,
- MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C,
- MLX4_CMD_NATIVE);
- if (err)
- return err;
- for (i = 0; i < 32; ++i)
- pkey[i] = be16_to_cpu(((__be16 *) out_mad->data)[i]);
- return err;
- }
- static int get_full_pkey_table(struct mlx4_dev *dev, u8 port, u16 *table,
- struct mlx4_cmd_mailbox *inbox,
- struct mlx4_cmd_mailbox *outbox)
- {
- int i;
- int err;
- for (i = 0; i < dev->caps.pkey_table_len[port]; i += 32) {
- err = query_pkey_block(dev, port, i, table + i, inbox, outbox);
- if (err)
- return err;
- }
- return 0;
- }
- #define PORT_CAPABILITY_LOCATION_IN_SMP 20
- #define PORT_STATE_OFFSET 32
- static enum ib_port_state vf_port_state(struct mlx4_dev *dev, int port, int vf)
- {
- if (mlx4_get_slave_port_state(dev, vf, port) == SLAVE_PORT_UP)
- return IB_PORT_ACTIVE;
- else
- return IB_PORT_DOWN;
- }
- static int mlx4_MAD_IFC_wrapper(struct mlx4_dev *dev, int slave,
- struct mlx4_vhcr *vhcr,
- struct mlx4_cmd_mailbox *inbox,
- struct mlx4_cmd_mailbox *outbox,
- struct mlx4_cmd_info *cmd)
- {
- struct ib_smp *smp = inbox->buf;
- u32 index;
- u8 port, slave_port;
- u8 opcode_modifier;
- u16 *table;
- int err;
- int vidx, pidx;
- int network_view;
- struct mlx4_priv *priv = mlx4_priv(dev);
- struct ib_smp *outsmp = outbox->buf;
- __be16 *outtab = (__be16 *)(outsmp->data);
- __be32 slave_cap_mask;
- __be64 slave_node_guid;
- slave_port = vhcr->in_modifier;
- port = mlx4_slave_convert_port(dev, slave, slave_port);
- /* network-view bit is for driver use only, and should not be passed to FW */
- opcode_modifier = vhcr->op_modifier & ~0x8; /* clear netw view bit */
- network_view = !!(vhcr->op_modifier & 0x8);
- if (smp->base_version == 1 &&
- smp->mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED &&
- smp->class_version == 1) {
- /* host view is paravirtualized */
- if (!network_view && smp->method == IB_MGMT_METHOD_GET) {
- if (smp->attr_id == IB_SMP_ATTR_PKEY_TABLE) {
- index = be32_to_cpu(smp->attr_mod);
- if (port < 1 || port > dev->caps.num_ports)
- return -EINVAL;
- table = kcalloc((dev->caps.pkey_table_len[port] / 32) + 1,
- sizeof(*table) * 32, GFP_KERNEL);
- if (!table)
- return -ENOMEM;
- /* need to get the full pkey table because the paravirtualized
- * pkeys may be scattered among several pkey blocks.
- */
- err = get_full_pkey_table(dev, port, table, inbox, outbox);
- if (!err) {
- for (vidx = index * 32; vidx < (index + 1) * 32; ++vidx) {
- pidx = priv->virt2phys_pkey[slave][port - 1][vidx];
- outtab[vidx % 32] = cpu_to_be16(table[pidx]);
- }
- }
- kfree(table);
- return err;
- }
- if (smp->attr_id == IB_SMP_ATTR_PORT_INFO) {
- /*get the slave specific caps:*/
- /*do the command */
- smp->attr_mod = cpu_to_be32(port);
- err = mlx4_cmd_box(dev, inbox->dma, outbox->dma,
- port, opcode_modifier,
- vhcr->op, MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE);
- /* modify the response for slaves */
- if (!err && slave != mlx4_master_func_num(dev)) {
- u8 *state = outsmp->data + PORT_STATE_OFFSET;
- *state = (*state & 0xf0) | vf_port_state(dev, port, slave);
- slave_cap_mask = priv->mfunc.master.slave_state[slave].ib_cap_mask[port];
- memcpy(outsmp->data + PORT_CAPABILITY_LOCATION_IN_SMP, &slave_cap_mask, 4);
- }
- return err;
- }
- if (smp->attr_id == IB_SMP_ATTR_GUID_INFO) {
- __be64 guid = mlx4_get_admin_guid(dev, slave,
- port);
- /* set the PF admin guid to the FW/HW burned
- * GUID, if it wasn't yet set
- */
- if (slave == 0 && guid == 0) {
- smp->attr_mod = 0;
- err = mlx4_cmd_box(dev,
- inbox->dma,
- outbox->dma,
- vhcr->in_modifier,
- opcode_modifier,
- vhcr->op,
- MLX4_CMD_TIME_CLASS_C,
- MLX4_CMD_NATIVE);
- if (err)
- return err;
- mlx4_set_admin_guid(dev,
- *(__be64 *)outsmp->
- data, slave, port);
- } else {
- memcpy(outsmp->data, &guid, 8);
- }
- /* clean all other gids */
- memset(outsmp->data + 8, 0, 56);
- return 0;
- }
- if (smp->attr_id == IB_SMP_ATTR_NODE_INFO) {
- err = mlx4_cmd_box(dev, inbox->dma, outbox->dma,
- port, opcode_modifier,
- vhcr->op, MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE);
- if (!err) {
- slave_node_guid = mlx4_get_slave_node_guid(dev, slave);
- memcpy(outsmp->data + 12, &slave_node_guid, 8);
- }
- return err;
- }
- }
- }
- /* Non-privileged VFs are only allowed "host" view LID-routed 'Get' MADs.
- * These are the MADs used by ib verbs (such as ib_query_gids).
- */
- if (slave != mlx4_master_func_num(dev) &&
- !mlx4_vf_smi_enabled(dev, slave, port)) {
- if (!(smp->mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED &&
- smp->method == IB_MGMT_METHOD_GET) || network_view) {
- mlx4_err(dev, "Unprivileged slave %d is trying to execute a Subnet MGMT MAD, class 0x%x, method 0x%x, view=%s for attr 0x%x. Rejecting\n",
- slave, smp->mgmt_class, smp->method,
- network_view ? "Network" : "Host",
- be16_to_cpu(smp->attr_id));
- return -EPERM;
- }
- }
- return mlx4_cmd_box(dev, inbox->dma, outbox->dma,
- vhcr->in_modifier, opcode_modifier,
- vhcr->op, MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE);
- }
- static int mlx4_CMD_EPERM_wrapper(struct mlx4_dev *dev, int slave,
- struct mlx4_vhcr *vhcr,
- struct mlx4_cmd_mailbox *inbox,
- struct mlx4_cmd_mailbox *outbox,
- struct mlx4_cmd_info *cmd)
- {
- return -EPERM;
- }
- int mlx4_DMA_wrapper(struct mlx4_dev *dev, int slave,
- struct mlx4_vhcr *vhcr,
- struct mlx4_cmd_mailbox *inbox,
- struct mlx4_cmd_mailbox *outbox,
- struct mlx4_cmd_info *cmd)
- {
- u64 in_param;
- u64 out_param;
- int err;
- in_param = cmd->has_inbox ? (u64) inbox->dma : vhcr->in_param;
- out_param = cmd->has_outbox ? (u64) outbox->dma : vhcr->out_param;
- if (cmd->encode_slave_id) {
- in_param &= 0xffffffffffffff00ll;
- in_param |= slave;
- }
- err = __mlx4_cmd(dev, in_param, &out_param, cmd->out_is_imm,
- vhcr->in_modifier, vhcr->op_modifier, vhcr->op,
- MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
- if (cmd->out_is_imm)
- vhcr->out_param = out_param;
- return err;
- }
- static struct mlx4_cmd_info cmd_info[] = {
- {
- .opcode = MLX4_CMD_QUERY_FW,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_FW_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_HCA,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = NULL
- },
- {
- .opcode = MLX4_CMD_QUERY_DEV_CAP,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_DEV_CAP_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_FUNC_CAP,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_FUNC_CAP_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_ADAPTER,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = NULL
- },
- {
- .opcode = MLX4_CMD_INIT_PORT,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_INIT_PORT_wrapper
- },
- {
- .opcode = MLX4_CMD_CLOSE_PORT,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CLOSE_PORT_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_PORT,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_PORT_wrapper
- },
- {
- .opcode = MLX4_CMD_SET_PORT,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_SET_PORT_wrapper
- },
- {
- .opcode = MLX4_CMD_MAP_EQ,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_MAP_EQ_wrapper
- },
- {
- .opcode = MLX4_CMD_SW2HW_EQ,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = true,
- .verify = NULL,
- .wrapper = mlx4_SW2HW_EQ_wrapper
- },
- {
- .opcode = MLX4_CMD_HW_HEALTH_CHECK,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = NULL
- },
- {
- .opcode = MLX4_CMD_NOP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = NULL
- },
- {
- .opcode = MLX4_CMD_CONFIG_DEV,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CONFIG_DEV_wrapper
- },
- {
- .opcode = MLX4_CMD_ALLOC_RES,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = true,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_ALLOC_RES_wrapper
- },
- {
- .opcode = MLX4_CMD_FREE_RES,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_FREE_RES_wrapper
- },
- {
- .opcode = MLX4_CMD_SW2HW_MPT,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = true,
- .verify = NULL,
- .wrapper = mlx4_SW2HW_MPT_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_MPT,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_MPT_wrapper
- },
- {
- .opcode = MLX4_CMD_HW2SW_MPT,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_HW2SW_MPT_wrapper
- },
- {
- .opcode = MLX4_CMD_READ_MTT,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = NULL
- },
- {
- .opcode = MLX4_CMD_WRITE_MTT,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_WRITE_MTT_wrapper
- },
- {
- .opcode = MLX4_CMD_SYNC_TPT,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = NULL
- },
- {
- .opcode = MLX4_CMD_HW2SW_EQ,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = true,
- .verify = NULL,
- .wrapper = mlx4_HW2SW_EQ_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_EQ,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = true,
- .verify = NULL,
- .wrapper = mlx4_QUERY_EQ_wrapper
- },
- {
- .opcode = MLX4_CMD_SW2HW_CQ,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = true,
- .verify = NULL,
- .wrapper = mlx4_SW2HW_CQ_wrapper
- },
- {
- .opcode = MLX4_CMD_HW2SW_CQ,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_HW2SW_CQ_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_CQ,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_CQ_wrapper
- },
- {
- .opcode = MLX4_CMD_MODIFY_CQ,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = true,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_MODIFY_CQ_wrapper
- },
- {
- .opcode = MLX4_CMD_SW2HW_SRQ,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = true,
- .verify = NULL,
- .wrapper = mlx4_SW2HW_SRQ_wrapper
- },
- {
- .opcode = MLX4_CMD_HW2SW_SRQ,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_HW2SW_SRQ_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_SRQ,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_SRQ_wrapper
- },
- {
- .opcode = MLX4_CMD_ARM_SRQ,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_ARM_SRQ_wrapper
- },
- {
- .opcode = MLX4_CMD_RST2INIT_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = true,
- .verify = NULL,
- .wrapper = mlx4_RST2INIT_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_INIT2INIT_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_INIT2INIT_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_INIT2RTR_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_INIT2RTR_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_RTR2RTS_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_RTR2RTS_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_RTS2RTS_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_RTS2RTS_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_SQERR2RTS_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_SQERR2RTS_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_2ERR_QP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_GEN_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_RTS2SQD_QP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_GEN_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_SQD2SQD_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_SQD2SQD_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_SQD2RTS_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_SQD2RTS_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_2RST_QP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_2RST_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_QP,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_GEN_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_SUSPEND_QP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_GEN_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_UNSUSPEND_QP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_GEN_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_UPDATE_QP,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_UPDATE_QP_wrapper
- },
- {
- .opcode = MLX4_CMD_GET_OP_REQ,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CMD_EPERM_wrapper,
- },
- {
- .opcode = MLX4_CMD_ALLOCATE_VPP,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CMD_EPERM_wrapper,
- },
- {
- .opcode = MLX4_CMD_SET_VPORT_QOS,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CMD_EPERM_wrapper,
- },
- {
- .opcode = MLX4_CMD_CONF_SPECIAL_QP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL, /* XXX verify: only demux can do this */
- .wrapper = NULL
- },
- {
- .opcode = MLX4_CMD_MAD_IFC,
- .has_inbox = true,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_MAD_IFC_wrapper
- },
- {
- .opcode = MLX4_CMD_MAD_DEMUX,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CMD_EPERM_wrapper
- },
- {
- .opcode = MLX4_CMD_QUERY_IF_STAT,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QUERY_IF_STAT_wrapper
- },
- {
- .opcode = MLX4_CMD_ACCESS_REG,
- .has_inbox = true,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_ACCESS_REG_wrapper,
- },
- {
- .opcode = MLX4_CMD_CONGESTION_CTRL_OPCODE,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CMD_EPERM_wrapper,
- },
- /* Native multicast commands are not available for guests */
- {
- .opcode = MLX4_CMD_QP_ATTACH,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QP_ATTACH_wrapper
- },
- {
- .opcode = MLX4_CMD_PROMISC,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_PROMISC_wrapper
- },
- /* Ethernet specific commands */
- {
- .opcode = MLX4_CMD_SET_VLAN_FLTR,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_SET_VLAN_FLTR_wrapper
- },
- {
- .opcode = MLX4_CMD_SET_MCAST_FLTR,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_SET_MCAST_FLTR_wrapper
- },
- {
- .opcode = MLX4_CMD_DUMP_ETH_STATS,
- .has_inbox = false,
- .has_outbox = true,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_DUMP_ETH_STATS_wrapper
- },
- {
- .opcode = MLX4_CMD_INFORM_FLR_DONE,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = NULL
- },
- /* flow steering commands */
- {
- .opcode = MLX4_QP_FLOW_STEERING_ATTACH,
- .has_inbox = true,
- .has_outbox = false,
- .out_is_imm = true,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QP_FLOW_STEERING_ATTACH_wrapper
- },
- {
- .opcode = MLX4_QP_FLOW_STEERING_DETACH,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_QP_FLOW_STEERING_DETACH_wrapper
- },
- {
- .opcode = MLX4_FLOW_STEERING_IB_UC_QP_RANGE,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CMD_EPERM_wrapper
- },
- {
- .opcode = MLX4_CMD_VIRT_PORT_MAP,
- .has_inbox = false,
- .has_outbox = false,
- .out_is_imm = false,
- .encode_slave_id = false,
- .verify = NULL,
- .wrapper = mlx4_CMD_EPERM_wrapper
- },
- };
- static int mlx4_master_process_vhcr(struct mlx4_dev *dev, int slave,
- struct mlx4_vhcr_cmd *in_vhcr)
- {
- struct mlx4_priv *priv = mlx4_priv(dev);
- struct mlx4_cmd_info *cmd = NULL;
- struct mlx4_vhcr_cmd *vhcr_cmd = in_vhcr ? in_vhcr : priv->mfunc.vhcr;
- struct mlx4_vhcr *vhcr;
- struct mlx4_cmd_mailbox *inbox = NULL;
- struct mlx4_cmd_mailbox *outbox = NULL;
- u64 in_param;
- u64 out_param;
- int ret = 0;
- int i;
- int err = 0;
- /* Create sw representation of Virtual HCR */
- vhcr = kzalloc(sizeof(struct mlx4_vhcr), GFP_KERNEL);
- if (!vhcr)
- return -ENOMEM;
- /* DMA in the vHCR */
- if (!in_vhcr) {
- ret = mlx4_ACCESS_MEM(dev, priv->mfunc.vhcr_dma, slave,
- priv->mfunc.master.slave_state[slave].vhcr_dma,
- ALIGN(sizeof(struct mlx4_vhcr_cmd),
- MLX4_ACCESS_MEM_ALIGN), 1);
- if (ret) {
- if (!(dev->persist->state &
- MLX4_DEVICE_STATE_INTERNAL_ERROR))
- mlx4_err(dev, "%s: Failed reading vhcr ret: 0x%x\n",
- __func__, ret);
- kfree(vhcr);
- return ret;
- }
- }
- /* Fill SW VHCR fields */
- vhcr->in_param = be64_to_cpu(vhcr_cmd->in_param);
- vhcr->out_param = be64_to_cpu(vhcr_cmd->out_param);
- vhcr->in_modifier = be32_to_cpu(vhcr_cmd->in_modifier);
- vhcr->token = be16_to_cpu(vhcr_cmd->token);
- vhcr->op = be16_to_cpu(vhcr_cmd->opcode) & 0xfff;
- vhcr->op_modifier = (u8) (be16_to_cpu(vhcr_cmd->opcode) >> 12);
- vhcr->e_bit = vhcr_cmd->flags & (1 << 6);
- /* Lookup command */
- for (i = 0; i < ARRAY_SIZE(cmd_info); ++i) {
- if (vhcr->op == cmd_info[i].opcode) {
- cmd = &cmd_info[i];
- break;
- }
- }
- if (!cmd) {
- mlx4_err(dev, "Unknown command:0x%x accepted from slave:%d\n",
- vhcr->op, slave);
- vhcr_cmd->status = CMD_STAT_BAD_PARAM;
- goto out_status;
- }
- /* Read inbox */
- if (cmd->has_inbox) {
- vhcr->in_param &= INBOX_MASK;
- inbox = mlx4_alloc_cmd_mailbox(dev);
- if (IS_ERR(inbox)) {
- vhcr_cmd->status = CMD_STAT_BAD_SIZE;
- inbox = NULL;
- goto out_status;
- }
- ret = mlx4_ACCESS_MEM(dev, inbox->dma, slave,
- vhcr->in_param,
- MLX4_MAILBOX_SIZE, 1);
- if (ret) {
- if (!(dev->persist->state &
- MLX4_DEVICE_STATE_INTERNAL_ERROR))
- mlx4_err(dev, "%s: Failed reading inbox (cmd:0x%x)\n",
- __func__, cmd->opcode);
- vhcr_cmd->status = CMD_STAT_INTERNAL_ERR;
- goto out_status;
- }
- }
- /* Apply permission and bound checks if applicable */
- if (cmd->verify && cmd->verify(dev, slave, vhcr, inbox)) {
- mlx4_warn(dev, "Command:0x%x from slave: %d failed protection checks for resource_id:%d\n",
- vhcr->op, slave, vhcr->in_modifier);
- vhcr_cmd->status = CMD_STAT_BAD_OP;
- goto out_status;
- }
- /* Allocate outbox */
- if (cmd->has_outbox) {
- outbox = mlx4_alloc_cmd_mailbox(dev);
- if (IS_ERR(outbox)) {
- vhcr_cmd->status = CMD_STAT_BAD_SIZE;
- outbox = NULL;
- goto out_status;
- }
- }
- /* Execute the command! */
- if (cmd->wrapper) {
- err = cmd->wrapper(dev, slave, vhcr, inbox, outbox,
- cmd);
- if (cmd->out_is_imm)
- vhcr_cmd->out_param = cpu_to_be64(vhcr->out_param);
- } else {
- in_param = cmd->has_inbox ? (u64) inbox->dma :
- vhcr->in_param;
- out_param = cmd->has_outbox ? (u64) outbox->dma :
- vhcr->out_param;
- err = __mlx4_cmd(dev, in_param, &out_param,
- cmd->out_is_imm, vhcr->in_modifier,
- vhcr->op_modifier, vhcr->op,
- MLX4_CMD_TIME_CLASS_A,
- MLX4_CMD_NATIVE);
- if (cmd->out_is_imm) {
- vhcr->out_param = out_param;
- vhcr_cmd->out_param = cpu_to_be64(vhcr->out_param);
- }
- }
- if (err) {
- if (!(dev->persist->state & MLX4_DEVICE_STATE_INTERNAL_ERROR)) {
- if (vhcr->op == MLX4_CMD_ALLOC_RES &&
- (vhcr->in_modifier & 0xff) == RES_COUNTER &&
- err == -EDQUOT)
- mlx4_dbg(dev,
- "Unable to allocate counter for slave %d (%d)\n",
- slave, err);
- else
- mlx4_warn(dev, "vhcr command:0x%x slave:%d failed with error:%d, status %d\n",
- vhcr->op, slave, vhcr->errno, err);
- }
- vhcr_cmd->status = mlx4_errno_to_status(err);
- goto out_status;
- }
- /* Write outbox if command completed successfully */
- if (cmd->has_outbox && !vhcr_cmd->status) {
- ret = mlx4_ACCESS_MEM(dev, outbox->dma, slave,
- vhcr->out_param,
- MLX4_MAILBOX_SIZE, MLX4_CMD_WRAPPED);
- if (ret) {
- /* If we failed to write back the outbox after the
- *command was successfully executed, we must fail this
- * slave, as it is now in undefined state */
- if (!(dev->persist->state &
- MLX4_DEVICE_STATE_INTERNAL_ERROR))
- mlx4_err(dev, "%s:Failed writing outbox\n", __func__);
- goto out;
- }
- }
- out_status:
- /* DMA back vhcr result */
- if (!in_vhcr) {
- ret = mlx4_ACCESS_MEM(dev, priv->mfunc.vhcr_dma, slave,
- priv->mfunc.master.slave_state[slave].vhcr_dma,
- ALIGN(sizeof(struct mlx4_vhcr),
- MLX4_ACCESS_MEM_ALIGN),
- MLX4_CMD_WRAPPED);
- if (ret)
- mlx4_err(dev, "%s:Failed writing vhcr result\n",
- __func__);
- else if (vhcr->e_bit &&
- mlx4_GEN_EQE(dev, slave, &priv->mfunc.master.cmd_eqe))
- mlx4_warn(dev, "Failed to generate command completion eqe for slave %d\n",
- slave);
- }
- out:
- kfree(vhcr);
- mlx4_free_cmd_mailbox(dev, inbox);
- mlx4_free_cmd_mailbox(dev, outbox);
- return ret;
- }
- static int mlx4_master_immediate_activate_vlan_qos(struct mlx4_priv *priv,
- int slave, int port)
- {
- struct mlx4_vport_oper_state *vp_oper;
- struct mlx4_vport_state *vp_admin;
- struct mlx4_vf_immed_vlan_work *work;
- struct mlx4_dev *dev = &(priv->dev);
- int err;
- int admin_vlan_ix = NO_INDX;
- vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port];
- vp_admin = &priv->mfunc.master.vf_admin[slave].vport[port];
- if (vp_oper->state.default_vlan == vp_admin->default_vlan &&
- vp_oper->state.default_qos == vp_admin->default_qos &&
- vp_oper->state.vlan_proto == vp_admin->vlan_proto &&
- vp_oper->state.link_state == vp_admin->link_state &&
- vp_oper->state.qos_vport == vp_admin->qos_vport)
- return 0;
- if (!(priv->mfunc.master.slave_state[slave].active &&
- dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_UPDATE_QP)) {
- /* even if the UPDATE_QP command isn't supported, we still want
- * to set this VF link according to the admin directive
- */
- vp_oper->state.link_state = vp_admin->link_state;
- return -1;
- }
- mlx4_dbg(dev, "updating immediately admin params slave %d port %d\n",
- slave, port);
- mlx4_dbg(dev, "vlan %d QoS %d link down %d\n",
- vp_admin->default_vlan, vp_admin->default_qos,
- vp_admin->link_state);
- work = kzalloc(sizeof(*work), GFP_KERNEL);
- if (!work)
- return -ENOMEM;
- if (vp_oper->state.default_vlan != vp_admin->default_vlan) {
- if (MLX4_VGT != vp_admin->default_vlan) {
- err = __mlx4_register_vlan(&priv->dev, port,
- vp_admin->default_vlan,
- &admin_vlan_ix);
- if (err) {
- kfree(work);
- mlx4_warn(&priv->dev,
- "No vlan resources slave %d, port %d\n",
- slave, port);
- return err;
- }
- } else {
- admin_vlan_ix = NO_INDX;
- }
- work->flags |= MLX4_VF_IMMED_VLAN_FLAG_V…