15a2cc190SJeff Kirsher /* 25a2cc190SJeff Kirsher * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 35a2cc190SJeff Kirsher * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved. 45a2cc190SJeff Kirsher * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved. 55a2cc190SJeff Kirsher * 65a2cc190SJeff Kirsher * This software is available to you under a choice of one of two 75a2cc190SJeff Kirsher * licenses. You may choose to be licensed under the terms of the GNU 85a2cc190SJeff Kirsher * General Public License (GPL) Version 2, available from the file 95a2cc190SJeff Kirsher * COPYING in the main directory of this source tree, or the 105a2cc190SJeff Kirsher * OpenIB.org BSD license below: 115a2cc190SJeff Kirsher * 125a2cc190SJeff Kirsher * Redistribution and use in source and binary forms, with or 135a2cc190SJeff Kirsher * without modification, are permitted provided that the following 145a2cc190SJeff Kirsher * conditions are met: 155a2cc190SJeff Kirsher * 165a2cc190SJeff Kirsher * - Redistributions of source code must retain the above 175a2cc190SJeff Kirsher * copyright notice, this list of conditions and the following 185a2cc190SJeff Kirsher * disclaimer. 195a2cc190SJeff Kirsher * 205a2cc190SJeff Kirsher * - Redistributions in binary form must reproduce the above 215a2cc190SJeff Kirsher * copyright notice, this list of conditions and the following 225a2cc190SJeff Kirsher * disclaimer in the documentation and/or other materials 235a2cc190SJeff Kirsher * provided with the distribution. 245a2cc190SJeff Kirsher * 255a2cc190SJeff Kirsher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 265a2cc190SJeff Kirsher * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 275a2cc190SJeff Kirsher * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 285a2cc190SJeff Kirsher * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 295a2cc190SJeff Kirsher * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 305a2cc190SJeff Kirsher * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 315a2cc190SJeff Kirsher * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 325a2cc190SJeff Kirsher * SOFTWARE. 335a2cc190SJeff Kirsher */ 345a2cc190SJeff Kirsher 355a2cc190SJeff Kirsher #include <linux/sched.h> 365a2cc190SJeff Kirsher #include <linux/slab.h> 37ee40fa06SPaul Gortmaker #include <linux/export.h> 385a2cc190SJeff Kirsher #include <linux/pci.h> 395a2cc190SJeff Kirsher #include <linux/errno.h> 405a2cc190SJeff Kirsher 415a2cc190SJeff Kirsher #include <linux/mlx4/cmd.h> 42948e306dSRony Efraim #include <linux/mlx4/device.h> 43e8f081aaSYevgeny Petrilin #include <linux/semaphore.h> 440a9a0188SJack Morgenstein #include <rdma/ib_smi.h> 455a2cc190SJeff Kirsher 465a2cc190SJeff Kirsher #include <asm/io.h> 475a2cc190SJeff Kirsher 485a2cc190SJeff Kirsher #include "mlx4.h" 49e8f081aaSYevgeny Petrilin #include "fw.h" 505a2cc190SJeff Kirsher 515a2cc190SJeff Kirsher #define CMD_POLL_TOKEN 0xffff 52e8f081aaSYevgeny Petrilin #define INBOX_MASK 0xffffffffffffff00ULL 53e8f081aaSYevgeny Petrilin 54e8f081aaSYevgeny Petrilin #define CMD_CHAN_VER 1 55e8f081aaSYevgeny Petrilin #define CMD_CHAN_IF_REV 1 565a2cc190SJeff Kirsher 575a2cc190SJeff Kirsher enum { 585a2cc190SJeff Kirsher /* command completed successfully: */ 595a2cc190SJeff Kirsher CMD_STAT_OK = 0x00, 605a2cc190SJeff Kirsher /* Internal error (such as a bus error) occurred while processing command: */ 615a2cc190SJeff Kirsher CMD_STAT_INTERNAL_ERR = 0x01, 625a2cc190SJeff Kirsher /* Operation/command not supported or opcode modifier not supported: */ 635a2cc190SJeff Kirsher CMD_STAT_BAD_OP = 0x02, 645a2cc190SJeff Kirsher /* Parameter not supported or parameter out of range: */ 655a2cc190SJeff Kirsher CMD_STAT_BAD_PARAM = 0x03, 665a2cc190SJeff Kirsher /* System not enabled or bad system state: */ 675a2cc190SJeff Kirsher CMD_STAT_BAD_SYS_STATE = 0x04, 685a2cc190SJeff Kirsher /* Attempt to access reserved or unallocaterd resource: */ 695a2cc190SJeff Kirsher CMD_STAT_BAD_RESOURCE = 0x05, 705a2cc190SJeff Kirsher /* Requested resource is currently executing a command, or is otherwise busy: */ 715a2cc190SJeff Kirsher CMD_STAT_RESOURCE_BUSY = 0x06, 725a2cc190SJeff Kirsher /* Required capability exceeds device limits: */ 735a2cc190SJeff Kirsher CMD_STAT_EXCEED_LIM = 0x08, 745a2cc190SJeff Kirsher /* Resource is not in the appropriate state or ownership: */ 755a2cc190SJeff Kirsher CMD_STAT_BAD_RES_STATE = 0x09, 765a2cc190SJeff Kirsher /* Index out of range: */ 775a2cc190SJeff Kirsher CMD_STAT_BAD_INDEX = 0x0a, 785a2cc190SJeff Kirsher /* FW image corrupted: */ 795a2cc190SJeff Kirsher CMD_STAT_BAD_NVMEM = 0x0b, 805a2cc190SJeff Kirsher /* Error in ICM mapping (e.g. not enough auxiliary ICM pages to execute command): */ 815a2cc190SJeff Kirsher CMD_STAT_ICM_ERROR = 0x0c, 825a2cc190SJeff Kirsher /* Attempt to modify a QP/EE which is not in the presumed state: */ 835a2cc190SJeff Kirsher CMD_STAT_BAD_QP_STATE = 0x10, 845a2cc190SJeff Kirsher /* Bad segment parameters (Address/Size): */ 855a2cc190SJeff Kirsher CMD_STAT_BAD_SEG_PARAM = 0x20, 865a2cc190SJeff Kirsher /* Memory Region has Memory Windows bound to: */ 875a2cc190SJeff Kirsher CMD_STAT_REG_BOUND = 0x21, 885a2cc190SJeff Kirsher /* HCA local attached memory not present: */ 895a2cc190SJeff Kirsher CMD_STAT_LAM_NOT_PRE = 0x22, 905a2cc190SJeff Kirsher /* Bad management packet (silently discarded): */ 915a2cc190SJeff Kirsher CMD_STAT_BAD_PKT = 0x30, 925a2cc190SJeff Kirsher /* More outstanding CQEs in CQ than new CQ size: */ 935a2cc190SJeff Kirsher CMD_STAT_BAD_SIZE = 0x40, 945a2cc190SJeff Kirsher /* Multi Function device support required: */ 955a2cc190SJeff Kirsher CMD_STAT_MULTI_FUNC_REQ = 0x50, 965a2cc190SJeff Kirsher }; 975a2cc190SJeff Kirsher 985a2cc190SJeff Kirsher enum { 995a2cc190SJeff Kirsher HCR_IN_PARAM_OFFSET = 0x00, 1005a2cc190SJeff Kirsher HCR_IN_MODIFIER_OFFSET = 0x08, 1015a2cc190SJeff Kirsher HCR_OUT_PARAM_OFFSET = 0x0c, 1025a2cc190SJeff Kirsher HCR_TOKEN_OFFSET = 0x14, 1035a2cc190SJeff Kirsher HCR_STATUS_OFFSET = 0x18, 1045a2cc190SJeff Kirsher 1055a2cc190SJeff Kirsher HCR_OPMOD_SHIFT = 12, 1065a2cc190SJeff Kirsher HCR_T_BIT = 21, 1075a2cc190SJeff Kirsher HCR_E_BIT = 22, 1085a2cc190SJeff Kirsher HCR_GO_BIT = 23 1095a2cc190SJeff Kirsher }; 1105a2cc190SJeff Kirsher 1115a2cc190SJeff Kirsher enum { 1125a2cc190SJeff Kirsher GO_BIT_TIMEOUT_MSECS = 10000 1135a2cc190SJeff Kirsher }; 1145a2cc190SJeff Kirsher 115b01978caSJack Morgenstein enum mlx4_vlan_transition { 116b01978caSJack Morgenstein MLX4_VLAN_TRANSITION_VST_VST = 0, 117b01978caSJack Morgenstein MLX4_VLAN_TRANSITION_VST_VGT = 1, 118b01978caSJack Morgenstein MLX4_VLAN_TRANSITION_VGT_VST = 2, 119b01978caSJack Morgenstein MLX4_VLAN_TRANSITION_VGT_VGT = 3, 120b01978caSJack Morgenstein }; 121b01978caSJack Morgenstein 122b01978caSJack Morgenstein 1235a2cc190SJeff Kirsher struct mlx4_cmd_context { 1245a2cc190SJeff Kirsher struct completion done; 1255a2cc190SJeff Kirsher int result; 1265a2cc190SJeff Kirsher int next; 1275a2cc190SJeff Kirsher u64 out_param; 1285a2cc190SJeff Kirsher u16 token; 129e8f081aaSYevgeny Petrilin u8 fw_status; 1305a2cc190SJeff Kirsher }; 1315a2cc190SJeff Kirsher 132e8f081aaSYevgeny Petrilin static int mlx4_master_process_vhcr(struct mlx4_dev *dev, int slave, 133e8f081aaSYevgeny Petrilin struct mlx4_vhcr_cmd *in_vhcr); 134e8f081aaSYevgeny Petrilin 1355a2cc190SJeff Kirsher static int mlx4_status_to_errno(u8 status) 1365a2cc190SJeff Kirsher { 1375a2cc190SJeff Kirsher static const int trans_table[] = { 1385a2cc190SJeff Kirsher [CMD_STAT_INTERNAL_ERR] = -EIO, 1395a2cc190SJeff Kirsher [CMD_STAT_BAD_OP] = -EPERM, 1405a2cc190SJeff Kirsher [CMD_STAT_BAD_PARAM] = -EINVAL, 1415a2cc190SJeff Kirsher [CMD_STAT_BAD_SYS_STATE] = -ENXIO, 1425a2cc190SJeff Kirsher [CMD_STAT_BAD_RESOURCE] = -EBADF, 1435a2cc190SJeff Kirsher [CMD_STAT_RESOURCE_BUSY] = -EBUSY, 1445a2cc190SJeff Kirsher [CMD_STAT_EXCEED_LIM] = -ENOMEM, 1455a2cc190SJeff Kirsher [CMD_STAT_BAD_RES_STATE] = -EBADF, 1465a2cc190SJeff Kirsher [CMD_STAT_BAD_INDEX] = -EBADF, 1475a2cc190SJeff Kirsher [CMD_STAT_BAD_NVMEM] = -EFAULT, 1485a2cc190SJeff Kirsher [CMD_STAT_ICM_ERROR] = -ENFILE, 1495a2cc190SJeff Kirsher [CMD_STAT_BAD_QP_STATE] = -EINVAL, 1505a2cc190SJeff Kirsher [CMD_STAT_BAD_SEG_PARAM] = -EFAULT, 1515a2cc190SJeff Kirsher [CMD_STAT_REG_BOUND] = -EBUSY, 1525a2cc190SJeff Kirsher [CMD_STAT_LAM_NOT_PRE] = -EAGAIN, 1535a2cc190SJeff Kirsher [CMD_STAT_BAD_PKT] = -EINVAL, 1545a2cc190SJeff Kirsher [CMD_STAT_BAD_SIZE] = -ENOMEM, 1555a2cc190SJeff Kirsher [CMD_STAT_MULTI_FUNC_REQ] = -EACCES, 1565a2cc190SJeff Kirsher }; 1575a2cc190SJeff Kirsher 1585a2cc190SJeff Kirsher if (status >= ARRAY_SIZE(trans_table) || 1595a2cc190SJeff Kirsher (status != CMD_STAT_OK && trans_table[status] == 0)) 1605a2cc190SJeff Kirsher return -EIO; 1615a2cc190SJeff Kirsher 1625a2cc190SJeff Kirsher return trans_table[status]; 1635a2cc190SJeff Kirsher } 1645a2cc190SJeff Kirsher 16572be84f1SYevgeny Petrilin static u8 mlx4_errno_to_status(int errno) 16672be84f1SYevgeny Petrilin { 16772be84f1SYevgeny Petrilin switch (errno) { 16872be84f1SYevgeny Petrilin case -EPERM: 16972be84f1SYevgeny Petrilin return CMD_STAT_BAD_OP; 17072be84f1SYevgeny Petrilin case -EINVAL: 17172be84f1SYevgeny Petrilin return CMD_STAT_BAD_PARAM; 17272be84f1SYevgeny Petrilin case -ENXIO: 17372be84f1SYevgeny Petrilin return CMD_STAT_BAD_SYS_STATE; 17472be84f1SYevgeny Petrilin case -EBUSY: 17572be84f1SYevgeny Petrilin return CMD_STAT_RESOURCE_BUSY; 17672be84f1SYevgeny Petrilin case -ENOMEM: 17772be84f1SYevgeny Petrilin return CMD_STAT_EXCEED_LIM; 17872be84f1SYevgeny Petrilin case -ENFILE: 17972be84f1SYevgeny Petrilin return CMD_STAT_ICM_ERROR; 18072be84f1SYevgeny Petrilin default: 18172be84f1SYevgeny Petrilin return CMD_STAT_INTERNAL_ERR; 18272be84f1SYevgeny Petrilin } 18372be84f1SYevgeny Petrilin } 18472be84f1SYevgeny Petrilin 185e8f081aaSYevgeny Petrilin static int comm_pending(struct mlx4_dev *dev) 186e8f081aaSYevgeny Petrilin { 187e8f081aaSYevgeny Petrilin struct mlx4_priv *priv = mlx4_priv(dev); 188e8f081aaSYevgeny Petrilin u32 status = readl(&priv->mfunc.comm->slave_read); 189e8f081aaSYevgeny Petrilin 190e8f081aaSYevgeny Petrilin return (swab32(status) >> 31) != priv->cmd.comm_toggle; 191e8f081aaSYevgeny Petrilin } 192e8f081aaSYevgeny Petrilin 193e8f081aaSYevgeny Petrilin static void mlx4_comm_cmd_post(struct mlx4_dev *dev, u8 cmd, u16 param) 194e8f081aaSYevgeny Petrilin { 195e8f081aaSYevgeny Petrilin struct mlx4_priv *priv = mlx4_priv(dev); 196e8f081aaSYevgeny Petrilin u32 val; 197e8f081aaSYevgeny Petrilin 198e8f081aaSYevgeny Petrilin priv->cmd.comm_toggle ^= 1; 199e8f081aaSYevgeny Petrilin val = param | (cmd << 16) | (priv->cmd.comm_toggle << 31); 200e8f081aaSYevgeny Petrilin __raw_writel((__force u32) cpu_to_be32(val), 201e8f081aaSYevgeny Petrilin &priv->mfunc.comm->slave_write); 202e8f081aaSYevgeny Petrilin mmiowb(); 203e8f081aaSYevgeny Petrilin } 204e8f081aaSYevgeny Petrilin 205e8f081aaSYevgeny Petrilin static int mlx4_comm_cmd_poll(struct mlx4_dev *dev, u8 cmd, u16 param, 206e8f081aaSYevgeny Petrilin unsigned long timeout) 207e8f081aaSYevgeny Petrilin { 208e8f081aaSYevgeny Petrilin struct mlx4_priv *priv = mlx4_priv(dev); 209e8f081aaSYevgeny Petrilin unsigned long end; 210e8f081aaSYevgeny Petrilin int err = 0; 211e8f081aaSYevgeny Petrilin int ret_from_pending = 0; 212e8f081aaSYevgeny Petrilin 213e8f081aaSYevgeny Petrilin /* First, verify that the master reports correct status */ 214e8f081aaSYevgeny Petrilin if (comm_pending(dev)) { 215e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Communication channel is not idle." 216e8f081aaSYevgeny Petrilin "my toggle is %d (cmd:0x%x)\n", 217e8f081aaSYevgeny Petrilin priv->cmd.comm_toggle, cmd); 218e8f081aaSYevgeny Petrilin return -EAGAIN; 219e8f081aaSYevgeny Petrilin } 220e8f081aaSYevgeny Petrilin 221e8f081aaSYevgeny Petrilin /* Write command */ 222e8f081aaSYevgeny Petrilin down(&priv->cmd.poll_sem); 223e8f081aaSYevgeny Petrilin mlx4_comm_cmd_post(dev, cmd, param); 224e8f081aaSYevgeny Petrilin 225e8f081aaSYevgeny Petrilin end = msecs_to_jiffies(timeout) + jiffies; 226e8f081aaSYevgeny Petrilin while (comm_pending(dev) && time_before(jiffies, end)) 227e8f081aaSYevgeny Petrilin cond_resched(); 228e8f081aaSYevgeny Petrilin ret_from_pending = comm_pending(dev); 229e8f081aaSYevgeny Petrilin if (ret_from_pending) { 230e8f081aaSYevgeny Petrilin /* check if the slave is trying to boot in the middle of 231e8f081aaSYevgeny Petrilin * FLR process. The only non-zero result in the RESET command 232e8f081aaSYevgeny Petrilin * is MLX4_DELAY_RESET_SLAVE*/ 233e8f081aaSYevgeny Petrilin if ((MLX4_COMM_CMD_RESET == cmd)) { 234e8f081aaSYevgeny Petrilin err = MLX4_DELAY_RESET_SLAVE; 235e8f081aaSYevgeny Petrilin } else { 236e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Communication channel timed out\n"); 237e8f081aaSYevgeny Petrilin err = -ETIMEDOUT; 238e8f081aaSYevgeny Petrilin } 239e8f081aaSYevgeny Petrilin } 240e8f081aaSYevgeny Petrilin 241e8f081aaSYevgeny Petrilin up(&priv->cmd.poll_sem); 242e8f081aaSYevgeny Petrilin return err; 243e8f081aaSYevgeny Petrilin } 244e8f081aaSYevgeny Petrilin 245e8f081aaSYevgeny Petrilin static int mlx4_comm_cmd_wait(struct mlx4_dev *dev, u8 op, 246e8f081aaSYevgeny Petrilin u16 param, unsigned long timeout) 247e8f081aaSYevgeny Petrilin { 248e8f081aaSYevgeny Petrilin struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd; 249e8f081aaSYevgeny Petrilin struct mlx4_cmd_context *context; 25058a3de05SEugenia Emantayev unsigned long end; 251e8f081aaSYevgeny Petrilin int err = 0; 252e8f081aaSYevgeny Petrilin 253e8f081aaSYevgeny Petrilin down(&cmd->event_sem); 254e8f081aaSYevgeny Petrilin 255e8f081aaSYevgeny Petrilin spin_lock(&cmd->context_lock); 256e8f081aaSYevgeny Petrilin BUG_ON(cmd->free_head < 0); 257e8f081aaSYevgeny Petrilin context = &cmd->context[cmd->free_head]; 258e8f081aaSYevgeny Petrilin context->token += cmd->token_mask + 1; 259e8f081aaSYevgeny Petrilin cmd->free_head = context->next; 260e8f081aaSYevgeny Petrilin spin_unlock(&cmd->context_lock); 261e8f081aaSYevgeny Petrilin 262e8f081aaSYevgeny Petrilin init_completion(&context->done); 263e8f081aaSYevgeny Petrilin 264e8f081aaSYevgeny Petrilin mlx4_comm_cmd_post(dev, op, param); 265e8f081aaSYevgeny Petrilin 266e8f081aaSYevgeny Petrilin if (!wait_for_completion_timeout(&context->done, 267e8f081aaSYevgeny Petrilin msecs_to_jiffies(timeout))) { 268674925edSDotan Barak mlx4_warn(dev, "communication channel command 0x%x timed out\n", 269674925edSDotan Barak op); 270e8f081aaSYevgeny Petrilin err = -EBUSY; 271e8f081aaSYevgeny Petrilin goto out; 272e8f081aaSYevgeny Petrilin } 273e8f081aaSYevgeny Petrilin 274e8f081aaSYevgeny Petrilin err = context->result; 275e8f081aaSYevgeny Petrilin if (err && context->fw_status != CMD_STAT_MULTI_FUNC_REQ) { 276e8f081aaSYevgeny Petrilin mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n", 277e8f081aaSYevgeny Petrilin op, context->fw_status); 278e8f081aaSYevgeny Petrilin goto out; 279e8f081aaSYevgeny Petrilin } 280e8f081aaSYevgeny Petrilin 281e8f081aaSYevgeny Petrilin out: 28258a3de05SEugenia Emantayev /* wait for comm channel ready 28358a3de05SEugenia Emantayev * this is necessary for prevention the race 28458a3de05SEugenia Emantayev * when switching between event to polling mode 28558a3de05SEugenia Emantayev */ 28658a3de05SEugenia Emantayev end = msecs_to_jiffies(timeout) + jiffies; 28758a3de05SEugenia Emantayev while (comm_pending(dev) && time_before(jiffies, end)) 28858a3de05SEugenia Emantayev cond_resched(); 28958a3de05SEugenia Emantayev 290e8f081aaSYevgeny Petrilin spin_lock(&cmd->context_lock); 291e8f081aaSYevgeny Petrilin context->next = cmd->free_head; 292e8f081aaSYevgeny Petrilin cmd->free_head = context - cmd->context; 293e8f081aaSYevgeny Petrilin spin_unlock(&cmd->context_lock); 294e8f081aaSYevgeny Petrilin 295e8f081aaSYevgeny Petrilin up(&cmd->event_sem); 296e8f081aaSYevgeny Petrilin return err; 297e8f081aaSYevgeny Petrilin } 298e8f081aaSYevgeny Petrilin 299ab9c17a0SJack Morgenstein int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param, 300e8f081aaSYevgeny Petrilin unsigned long timeout) 301e8f081aaSYevgeny Petrilin { 302e8f081aaSYevgeny Petrilin if (mlx4_priv(dev)->cmd.use_events) 303e8f081aaSYevgeny Petrilin return mlx4_comm_cmd_wait(dev, cmd, param, timeout); 304e8f081aaSYevgeny Petrilin return mlx4_comm_cmd_poll(dev, cmd, param, timeout); 305e8f081aaSYevgeny Petrilin } 306e8f081aaSYevgeny Petrilin 3075a2cc190SJeff Kirsher static int cmd_pending(struct mlx4_dev *dev) 3085a2cc190SJeff Kirsher { 30957dbf29aSKleber Sacilotto de Souza u32 status; 31057dbf29aSKleber Sacilotto de Souza 31157dbf29aSKleber Sacilotto de Souza if (pci_channel_offline(dev->pdev)) 31257dbf29aSKleber Sacilotto de Souza return -EIO; 31357dbf29aSKleber Sacilotto de Souza 31457dbf29aSKleber Sacilotto de Souza status = readl(mlx4_priv(dev)->cmd.hcr + HCR_STATUS_OFFSET); 3155a2cc190SJeff Kirsher 3165a2cc190SJeff Kirsher return (status & swab32(1 << HCR_GO_BIT)) || 3175a2cc190SJeff Kirsher (mlx4_priv(dev)->cmd.toggle == 3185a2cc190SJeff Kirsher !!(status & swab32(1 << HCR_T_BIT))); 3195a2cc190SJeff Kirsher } 3205a2cc190SJeff Kirsher 3215a2cc190SJeff Kirsher static int mlx4_cmd_post(struct mlx4_dev *dev, u64 in_param, u64 out_param, 3225a2cc190SJeff Kirsher u32 in_modifier, u8 op_modifier, u16 op, u16 token, 3235a2cc190SJeff Kirsher int event) 3245a2cc190SJeff Kirsher { 3255a2cc190SJeff Kirsher struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd; 3265a2cc190SJeff Kirsher u32 __iomem *hcr = cmd->hcr; 3275a2cc190SJeff Kirsher int ret = -EAGAIN; 3285a2cc190SJeff Kirsher unsigned long end; 3295a2cc190SJeff Kirsher 3305a2cc190SJeff Kirsher mutex_lock(&cmd->hcr_mutex); 3315a2cc190SJeff Kirsher 33257dbf29aSKleber Sacilotto de Souza if (pci_channel_offline(dev->pdev)) { 33357dbf29aSKleber Sacilotto de Souza /* 33457dbf29aSKleber Sacilotto de Souza * Device is going through error recovery 33557dbf29aSKleber Sacilotto de Souza * and cannot accept commands. 33657dbf29aSKleber Sacilotto de Souza */ 33757dbf29aSKleber Sacilotto de Souza ret = -EIO; 33857dbf29aSKleber Sacilotto de Souza goto out; 33957dbf29aSKleber Sacilotto de Souza } 34057dbf29aSKleber Sacilotto de Souza 3415a2cc190SJeff Kirsher end = jiffies; 3425a2cc190SJeff Kirsher if (event) 3435a2cc190SJeff Kirsher end += msecs_to_jiffies(GO_BIT_TIMEOUT_MSECS); 3445a2cc190SJeff Kirsher 3455a2cc190SJeff Kirsher while (cmd_pending(dev)) { 34657dbf29aSKleber Sacilotto de Souza if (pci_channel_offline(dev->pdev)) { 34757dbf29aSKleber Sacilotto de Souza /* 34857dbf29aSKleber Sacilotto de Souza * Device is going through error recovery 34957dbf29aSKleber Sacilotto de Souza * and cannot accept commands. 35057dbf29aSKleber Sacilotto de Souza */ 35157dbf29aSKleber Sacilotto de Souza ret = -EIO; 35257dbf29aSKleber Sacilotto de Souza goto out; 35357dbf29aSKleber Sacilotto de Souza } 35457dbf29aSKleber Sacilotto de Souza 355e8f081aaSYevgeny Petrilin if (time_after_eq(jiffies, end)) { 356e8f081aaSYevgeny Petrilin mlx4_err(dev, "%s:cmd_pending failed\n", __func__); 3575a2cc190SJeff Kirsher goto out; 358e8f081aaSYevgeny Petrilin } 3595a2cc190SJeff Kirsher cond_resched(); 3605a2cc190SJeff Kirsher } 3615a2cc190SJeff Kirsher 3625a2cc190SJeff Kirsher /* 3635a2cc190SJeff Kirsher * We use writel (instead of something like memcpy_toio) 3645a2cc190SJeff Kirsher * because writes of less than 32 bits to the HCR don't work 3655a2cc190SJeff Kirsher * (and some architectures such as ia64 implement memcpy_toio 3665a2cc190SJeff Kirsher * in terms of writeb). 3675a2cc190SJeff Kirsher */ 3685a2cc190SJeff Kirsher __raw_writel((__force u32) cpu_to_be32(in_param >> 32), hcr + 0); 3695a2cc190SJeff Kirsher __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), hcr + 1); 3705a2cc190SJeff Kirsher __raw_writel((__force u32) cpu_to_be32(in_modifier), hcr + 2); 3715a2cc190SJeff Kirsher __raw_writel((__force u32) cpu_to_be32(out_param >> 32), hcr + 3); 3725a2cc190SJeff Kirsher __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), hcr + 4); 3735a2cc190SJeff Kirsher __raw_writel((__force u32) cpu_to_be32(token << 16), hcr + 5); 3745a2cc190SJeff Kirsher 3755a2cc190SJeff Kirsher /* __raw_writel may not order writes. */ 3765a2cc190SJeff Kirsher wmb(); 3775a2cc190SJeff Kirsher 3785a2cc190SJeff Kirsher __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) | 3795a2cc190SJeff Kirsher (cmd->toggle << HCR_T_BIT) | 3805a2cc190SJeff Kirsher (event ? (1 << HCR_E_BIT) : 0) | 3815a2cc190SJeff Kirsher (op_modifier << HCR_OPMOD_SHIFT) | 3825a2cc190SJeff Kirsher op), hcr + 6); 3835a2cc190SJeff Kirsher 3845a2cc190SJeff Kirsher /* 3855a2cc190SJeff Kirsher * Make sure that our HCR writes don't get mixed in with 3865a2cc190SJeff Kirsher * writes from another CPU starting a FW command. 3875a2cc190SJeff Kirsher */ 3885a2cc190SJeff Kirsher mmiowb(); 3895a2cc190SJeff Kirsher 3905a2cc190SJeff Kirsher cmd->toggle = cmd->toggle ^ 1; 3915a2cc190SJeff Kirsher 3925a2cc190SJeff Kirsher ret = 0; 3935a2cc190SJeff Kirsher 3945a2cc190SJeff Kirsher out: 3955a2cc190SJeff Kirsher mutex_unlock(&cmd->hcr_mutex); 3965a2cc190SJeff Kirsher return ret; 3975a2cc190SJeff Kirsher } 3985a2cc190SJeff Kirsher 399e8f081aaSYevgeny Petrilin static int mlx4_slave_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param, 400e8f081aaSYevgeny Petrilin int out_is_imm, u32 in_modifier, u8 op_modifier, 401e8f081aaSYevgeny Petrilin u16 op, unsigned long timeout) 402e8f081aaSYevgeny Petrilin { 403e8f081aaSYevgeny Petrilin struct mlx4_priv *priv = mlx4_priv(dev); 404e8f081aaSYevgeny Petrilin struct mlx4_vhcr_cmd *vhcr = priv->mfunc.vhcr; 405e8f081aaSYevgeny Petrilin int ret; 406e8f081aaSYevgeny Petrilin 407f3d4c89eSRoland Dreier mutex_lock(&priv->cmd.slave_cmd_mutex); 408f3d4c89eSRoland Dreier 409e8f081aaSYevgeny Petrilin vhcr->in_param = cpu_to_be64(in_param); 410e8f081aaSYevgeny Petrilin vhcr->out_param = out_param ? cpu_to_be64(*out_param) : 0; 411e8f081aaSYevgeny Petrilin vhcr->in_modifier = cpu_to_be32(in_modifier); 412e8f081aaSYevgeny Petrilin vhcr->opcode = cpu_to_be16((((u16) op_modifier) << 12) | (op & 0xfff)); 413e8f081aaSYevgeny Petrilin vhcr->token = cpu_to_be16(CMD_POLL_TOKEN); 414e8f081aaSYevgeny Petrilin vhcr->status = 0; 415e8f081aaSYevgeny Petrilin vhcr->flags = !!(priv->cmd.use_events) << 6; 416f3d4c89eSRoland Dreier 417e8f081aaSYevgeny Petrilin if (mlx4_is_master(dev)) { 418e8f081aaSYevgeny Petrilin ret = mlx4_master_process_vhcr(dev, dev->caps.function, vhcr); 419e8f081aaSYevgeny Petrilin if (!ret) { 420e8f081aaSYevgeny Petrilin if (out_is_imm) { 421e8f081aaSYevgeny Petrilin if (out_param) 422e8f081aaSYevgeny Petrilin *out_param = 423e8f081aaSYevgeny Petrilin be64_to_cpu(vhcr->out_param); 424e8f081aaSYevgeny Petrilin else { 425e8f081aaSYevgeny Petrilin mlx4_err(dev, "response expected while" 426e8f081aaSYevgeny Petrilin "output mailbox is NULL for " 427e8f081aaSYevgeny Petrilin "command 0x%x\n", op); 42872be84f1SYevgeny Petrilin vhcr->status = CMD_STAT_BAD_PARAM; 429e8f081aaSYevgeny Petrilin } 430e8f081aaSYevgeny Petrilin } 43172be84f1SYevgeny Petrilin ret = mlx4_status_to_errno(vhcr->status); 432e8f081aaSYevgeny Petrilin } 433e8f081aaSYevgeny Petrilin } else { 434e8f081aaSYevgeny Petrilin ret = mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_POST, 0, 435e8f081aaSYevgeny Petrilin MLX4_COMM_TIME + timeout); 436e8f081aaSYevgeny Petrilin if (!ret) { 437e8f081aaSYevgeny Petrilin if (out_is_imm) { 438e8f081aaSYevgeny Petrilin if (out_param) 439e8f081aaSYevgeny Petrilin *out_param = 440e8f081aaSYevgeny Petrilin be64_to_cpu(vhcr->out_param); 441e8f081aaSYevgeny Petrilin else { 442e8f081aaSYevgeny Petrilin mlx4_err(dev, "response expected while" 443e8f081aaSYevgeny Petrilin "output mailbox is NULL for " 444e8f081aaSYevgeny Petrilin "command 0x%x\n", op); 44572be84f1SYevgeny Petrilin vhcr->status = CMD_STAT_BAD_PARAM; 446e8f081aaSYevgeny Petrilin } 447e8f081aaSYevgeny Petrilin } 44872be84f1SYevgeny Petrilin ret = mlx4_status_to_errno(vhcr->status); 449e8f081aaSYevgeny Petrilin } else 450e8f081aaSYevgeny Petrilin mlx4_err(dev, "failed execution of VHCR_POST command" 451e8f081aaSYevgeny Petrilin "opcode 0x%x\n", op); 452e8f081aaSYevgeny Petrilin } 453f3d4c89eSRoland Dreier 454f3d4c89eSRoland Dreier mutex_unlock(&priv->cmd.slave_cmd_mutex); 455e8f081aaSYevgeny Petrilin return ret; 456e8f081aaSYevgeny Petrilin } 457e8f081aaSYevgeny Petrilin 4585a2cc190SJeff Kirsher static int mlx4_cmd_poll(struct mlx4_dev *dev, u64 in_param, u64 *out_param, 4595a2cc190SJeff Kirsher int out_is_imm, u32 in_modifier, u8 op_modifier, 4605a2cc190SJeff Kirsher u16 op, unsigned long timeout) 4615a2cc190SJeff Kirsher { 4625a2cc190SJeff Kirsher struct mlx4_priv *priv = mlx4_priv(dev); 4635a2cc190SJeff Kirsher void __iomem *hcr = priv->cmd.hcr; 4645a2cc190SJeff Kirsher int err = 0; 4655a2cc190SJeff Kirsher unsigned long end; 466e8f081aaSYevgeny Petrilin u32 stat; 4675a2cc190SJeff Kirsher 4685a2cc190SJeff Kirsher down(&priv->cmd.poll_sem); 4695a2cc190SJeff Kirsher 47057dbf29aSKleber Sacilotto de Souza if (pci_channel_offline(dev->pdev)) { 47157dbf29aSKleber Sacilotto de Souza /* 47257dbf29aSKleber Sacilotto de Souza * Device is going through error recovery 47357dbf29aSKleber Sacilotto de Souza * and cannot accept commands. 47457dbf29aSKleber Sacilotto de Souza */ 47557dbf29aSKleber Sacilotto de Souza err = -EIO; 47657dbf29aSKleber Sacilotto de Souza goto out; 47757dbf29aSKleber Sacilotto de Souza } 47857dbf29aSKleber Sacilotto de Souza 4795a2cc190SJeff Kirsher err = mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0, 4805a2cc190SJeff Kirsher in_modifier, op_modifier, op, CMD_POLL_TOKEN, 0); 4815a2cc190SJeff Kirsher if (err) 4825a2cc190SJeff Kirsher goto out; 4835a2cc190SJeff Kirsher 4845a2cc190SJeff Kirsher end = msecs_to_jiffies(timeout) + jiffies; 48557dbf29aSKleber Sacilotto de Souza while (cmd_pending(dev) && time_before(jiffies, end)) { 48657dbf29aSKleber Sacilotto de Souza if (pci_channel_offline(dev->pdev)) { 48757dbf29aSKleber Sacilotto de Souza /* 48857dbf29aSKleber Sacilotto de Souza * Device is going through error recovery 48957dbf29aSKleber Sacilotto de Souza * and cannot accept commands. 49057dbf29aSKleber Sacilotto de Souza */ 49157dbf29aSKleber Sacilotto de Souza err = -EIO; 49257dbf29aSKleber Sacilotto de Souza goto out; 49357dbf29aSKleber Sacilotto de Souza } 49457dbf29aSKleber Sacilotto de Souza 4955a2cc190SJeff Kirsher cond_resched(); 49657dbf29aSKleber Sacilotto de Souza } 4975a2cc190SJeff Kirsher 4985a2cc190SJeff Kirsher if (cmd_pending(dev)) { 499674925edSDotan Barak mlx4_warn(dev, "command 0x%x timed out (go bit not cleared)\n", 500674925edSDotan Barak op); 5015a2cc190SJeff Kirsher err = -ETIMEDOUT; 5025a2cc190SJeff Kirsher goto out; 5035a2cc190SJeff Kirsher } 5045a2cc190SJeff Kirsher 5055a2cc190SJeff Kirsher if (out_is_imm) 5065a2cc190SJeff Kirsher *out_param = 5075a2cc190SJeff Kirsher (u64) be32_to_cpu((__force __be32) 5085a2cc190SJeff Kirsher __raw_readl(hcr + HCR_OUT_PARAM_OFFSET)) << 32 | 5095a2cc190SJeff Kirsher (u64) be32_to_cpu((__force __be32) 5105a2cc190SJeff Kirsher __raw_readl(hcr + HCR_OUT_PARAM_OFFSET + 4)); 511e8f081aaSYevgeny Petrilin stat = be32_to_cpu((__force __be32) 512e8f081aaSYevgeny Petrilin __raw_readl(hcr + HCR_STATUS_OFFSET)) >> 24; 513e8f081aaSYevgeny Petrilin err = mlx4_status_to_errno(stat); 514e8f081aaSYevgeny Petrilin if (err) 515e8f081aaSYevgeny Petrilin mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n", 516e8f081aaSYevgeny Petrilin op, stat); 5175a2cc190SJeff Kirsher 5185a2cc190SJeff Kirsher out: 5195a2cc190SJeff Kirsher up(&priv->cmd.poll_sem); 5205a2cc190SJeff Kirsher return err; 5215a2cc190SJeff Kirsher } 5225a2cc190SJeff Kirsher 5235a2cc190SJeff Kirsher void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param) 5245a2cc190SJeff Kirsher { 5255a2cc190SJeff Kirsher struct mlx4_priv *priv = mlx4_priv(dev); 5265a2cc190SJeff Kirsher struct mlx4_cmd_context *context = 5275a2cc190SJeff Kirsher &priv->cmd.context[token & priv->cmd.token_mask]; 5285a2cc190SJeff Kirsher 5295a2cc190SJeff Kirsher /* previously timed out command completing at long last */ 5305a2cc190SJeff Kirsher if (token != context->token) 5315a2cc190SJeff Kirsher return; 5325a2cc190SJeff Kirsher 533e8f081aaSYevgeny Petrilin context->fw_status = status; 5345a2cc190SJeff Kirsher context->result = mlx4_status_to_errno(status); 5355a2cc190SJeff Kirsher context->out_param = out_param; 5365a2cc190SJeff Kirsher 5375a2cc190SJeff Kirsher complete(&context->done); 5385a2cc190SJeff Kirsher } 5395a2cc190SJeff Kirsher 5405a2cc190SJeff Kirsher static int mlx4_cmd_wait(struct mlx4_dev *dev, u64 in_param, u64 *out_param, 5415a2cc190SJeff Kirsher int out_is_imm, u32 in_modifier, u8 op_modifier, 5425a2cc190SJeff Kirsher u16 op, unsigned long timeout) 5435a2cc190SJeff Kirsher { 5445a2cc190SJeff Kirsher struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd; 5455a2cc190SJeff Kirsher struct mlx4_cmd_context *context; 5465a2cc190SJeff Kirsher int err = 0; 5475a2cc190SJeff Kirsher 5485a2cc190SJeff Kirsher down(&cmd->event_sem); 5495a2cc190SJeff Kirsher 5505a2cc190SJeff Kirsher spin_lock(&cmd->context_lock); 5515a2cc190SJeff Kirsher BUG_ON(cmd->free_head < 0); 5525a2cc190SJeff Kirsher context = &cmd->context[cmd->free_head]; 5535a2cc190SJeff Kirsher context->token += cmd->token_mask + 1; 5545a2cc190SJeff Kirsher cmd->free_head = context->next; 5555a2cc190SJeff Kirsher spin_unlock(&cmd->context_lock); 5565a2cc190SJeff Kirsher 5575a2cc190SJeff Kirsher init_completion(&context->done); 5585a2cc190SJeff Kirsher 5595a2cc190SJeff Kirsher mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0, 5605a2cc190SJeff Kirsher in_modifier, op_modifier, op, context->token, 1); 5615a2cc190SJeff Kirsher 562e8f081aaSYevgeny Petrilin if (!wait_for_completion_timeout(&context->done, 563e8f081aaSYevgeny Petrilin msecs_to_jiffies(timeout))) { 564674925edSDotan Barak mlx4_warn(dev, "command 0x%x timed out (go bit not cleared)\n", 565674925edSDotan Barak op); 5665a2cc190SJeff Kirsher err = -EBUSY; 5675a2cc190SJeff Kirsher goto out; 5685a2cc190SJeff Kirsher } 5695a2cc190SJeff Kirsher 5705a2cc190SJeff Kirsher err = context->result; 571e8f081aaSYevgeny Petrilin if (err) { 572e8f081aaSYevgeny Petrilin mlx4_err(dev, "command 0x%x failed: fw status = 0x%x\n", 573e8f081aaSYevgeny Petrilin op, context->fw_status); 5745a2cc190SJeff Kirsher goto out; 575e8f081aaSYevgeny Petrilin } 5765a2cc190SJeff Kirsher 5775a2cc190SJeff Kirsher if (out_is_imm) 5785a2cc190SJeff Kirsher *out_param = context->out_param; 5795a2cc190SJeff Kirsher 5805a2cc190SJeff Kirsher out: 5815a2cc190SJeff Kirsher spin_lock(&cmd->context_lock); 5825a2cc190SJeff Kirsher context->next = cmd->free_head; 5835a2cc190SJeff Kirsher cmd->free_head = context - cmd->context; 5845a2cc190SJeff Kirsher spin_unlock(&cmd->context_lock); 5855a2cc190SJeff Kirsher 5865a2cc190SJeff Kirsher up(&cmd->event_sem); 5875a2cc190SJeff Kirsher return err; 5885a2cc190SJeff Kirsher } 5895a2cc190SJeff Kirsher 5905a2cc190SJeff Kirsher int __mlx4_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param, 5915a2cc190SJeff Kirsher int out_is_imm, u32 in_modifier, u8 op_modifier, 592f9baff50SJack Morgenstein u16 op, unsigned long timeout, int native) 5935a2cc190SJeff Kirsher { 59457dbf29aSKleber Sacilotto de Souza if (pci_channel_offline(dev->pdev)) 59557dbf29aSKleber Sacilotto de Souza return -EIO; 59657dbf29aSKleber Sacilotto de Souza 597e8f081aaSYevgeny Petrilin if (!mlx4_is_mfunc(dev) || (native && mlx4_is_master(dev))) { 5985a2cc190SJeff Kirsher if (mlx4_priv(dev)->cmd.use_events) 599e8f081aaSYevgeny Petrilin return mlx4_cmd_wait(dev, in_param, out_param, 600e8f081aaSYevgeny Petrilin out_is_imm, in_modifier, 601e8f081aaSYevgeny Petrilin op_modifier, op, timeout); 6025a2cc190SJeff Kirsher else 603e8f081aaSYevgeny Petrilin return mlx4_cmd_poll(dev, in_param, out_param, 604e8f081aaSYevgeny Petrilin out_is_imm, in_modifier, 605e8f081aaSYevgeny Petrilin op_modifier, op, timeout); 606e8f081aaSYevgeny Petrilin } 607e8f081aaSYevgeny Petrilin return mlx4_slave_cmd(dev, in_param, out_param, out_is_imm, 6085a2cc190SJeff Kirsher in_modifier, op_modifier, op, timeout); 6095a2cc190SJeff Kirsher } 6105a2cc190SJeff Kirsher EXPORT_SYMBOL_GPL(__mlx4_cmd); 6115a2cc190SJeff Kirsher 612e8f081aaSYevgeny Petrilin 613e8f081aaSYevgeny Petrilin static int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev *dev) 614e8f081aaSYevgeny Petrilin { 615e8f081aaSYevgeny Petrilin return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_ARM_COMM_CHANNEL, 616e8f081aaSYevgeny Petrilin MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE); 617e8f081aaSYevgeny Petrilin } 618e8f081aaSYevgeny Petrilin 619e8f081aaSYevgeny Petrilin static int mlx4_ACCESS_MEM(struct mlx4_dev *dev, u64 master_addr, 620e8f081aaSYevgeny Petrilin int slave, u64 slave_addr, 621e8f081aaSYevgeny Petrilin int size, int is_read) 622e8f081aaSYevgeny Petrilin { 623e8f081aaSYevgeny Petrilin u64 in_param; 624e8f081aaSYevgeny Petrilin u64 out_param; 625e8f081aaSYevgeny Petrilin 626e8f081aaSYevgeny Petrilin if ((slave_addr & 0xfff) | (master_addr & 0xfff) | 627e8f081aaSYevgeny Petrilin (slave & ~0x7f) | (size & 0xff)) { 628e8f081aaSYevgeny Petrilin mlx4_err(dev, "Bad access mem params - slave_addr:0x%llx " 629e8f081aaSYevgeny Petrilin "master_addr:0x%llx slave_id:%d size:%d\n", 630e8f081aaSYevgeny Petrilin slave_addr, master_addr, slave, size); 631e8f081aaSYevgeny Petrilin return -EINVAL; 632e8f081aaSYevgeny Petrilin } 633e8f081aaSYevgeny Petrilin 634e8f081aaSYevgeny Petrilin if (is_read) { 635e8f081aaSYevgeny Petrilin in_param = (u64) slave | slave_addr; 636e8f081aaSYevgeny Petrilin out_param = (u64) dev->caps.function | master_addr; 637e8f081aaSYevgeny Petrilin } else { 638e8f081aaSYevgeny Petrilin in_param = (u64) dev->caps.function | master_addr; 639e8f081aaSYevgeny Petrilin out_param = (u64) slave | slave_addr; 640e8f081aaSYevgeny Petrilin } 641e8f081aaSYevgeny Petrilin 642e8f081aaSYevgeny Petrilin return mlx4_cmd_imm(dev, in_param, &out_param, size, 0, 643e8f081aaSYevgeny Petrilin MLX4_CMD_ACCESS_MEM, 644e8f081aaSYevgeny Petrilin MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 645e8f081aaSYevgeny Petrilin } 646e8f081aaSYevgeny Petrilin 6470a9a0188SJack Morgenstein static int query_pkey_block(struct mlx4_dev *dev, u8 port, u16 index, u16 *pkey, 6480a9a0188SJack Morgenstein struct mlx4_cmd_mailbox *inbox, 6490a9a0188SJack Morgenstein struct mlx4_cmd_mailbox *outbox) 6500a9a0188SJack Morgenstein { 6510a9a0188SJack Morgenstein struct ib_smp *in_mad = (struct ib_smp *)(inbox->buf); 6520a9a0188SJack Morgenstein struct ib_smp *out_mad = (struct ib_smp *)(outbox->buf); 6530a9a0188SJack Morgenstein int err; 6540a9a0188SJack Morgenstein int i; 6550a9a0188SJack Morgenstein 6560a9a0188SJack Morgenstein if (index & 0x1f) 6570a9a0188SJack Morgenstein return -EINVAL; 6580a9a0188SJack Morgenstein 6590a9a0188SJack Morgenstein in_mad->attr_mod = cpu_to_be32(index / 32); 6600a9a0188SJack Morgenstein 6610a9a0188SJack Morgenstein err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, port, 3, 6620a9a0188SJack Morgenstein MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C, 6630a9a0188SJack Morgenstein MLX4_CMD_NATIVE); 6640a9a0188SJack Morgenstein if (err) 6650a9a0188SJack Morgenstein return err; 6660a9a0188SJack Morgenstein 6670a9a0188SJack Morgenstein for (i = 0; i < 32; ++i) 6680a9a0188SJack Morgenstein pkey[i] = be16_to_cpu(((__be16 *) out_mad->data)[i]); 6690a9a0188SJack Morgenstein 6700a9a0188SJack Morgenstein return err; 6710a9a0188SJack Morgenstein } 6720a9a0188SJack Morgenstein 6730a9a0188SJack Morgenstein static int get_full_pkey_table(struct mlx4_dev *dev, u8 port, u16 *table, 6740a9a0188SJack Morgenstein struct mlx4_cmd_mailbox *inbox, 6750a9a0188SJack Morgenstein struct mlx4_cmd_mailbox *outbox) 6760a9a0188SJack Morgenstein { 6770a9a0188SJack Morgenstein int i; 6780a9a0188SJack Morgenstein int err; 6790a9a0188SJack Morgenstein 6800a9a0188SJack Morgenstein for (i = 0; i < dev->caps.pkey_table_len[port]; i += 32) { 6810a9a0188SJack Morgenstein err = query_pkey_block(dev, port, i, table + i, inbox, outbox); 6820a9a0188SJack Morgenstein if (err) 6830a9a0188SJack Morgenstein return err; 6840a9a0188SJack Morgenstein } 6850a9a0188SJack Morgenstein 6860a9a0188SJack Morgenstein return 0; 6870a9a0188SJack Morgenstein } 6880a9a0188SJack Morgenstein #define PORT_CAPABILITY_LOCATION_IN_SMP 20 6890a9a0188SJack Morgenstein #define PORT_STATE_OFFSET 32 6900a9a0188SJack Morgenstein 6910a9a0188SJack Morgenstein static enum ib_port_state vf_port_state(struct mlx4_dev *dev, int port, int vf) 6920a9a0188SJack Morgenstein { 693a0c64a17SJack Morgenstein if (mlx4_get_slave_port_state(dev, vf, port) == SLAVE_PORT_UP) 694a0c64a17SJack Morgenstein return IB_PORT_ACTIVE; 695a0c64a17SJack Morgenstein else 6960a9a0188SJack Morgenstein return IB_PORT_DOWN; 6970a9a0188SJack Morgenstein } 6980a9a0188SJack Morgenstein 6990a9a0188SJack Morgenstein static int mlx4_MAD_IFC_wrapper(struct mlx4_dev *dev, int slave, 7000a9a0188SJack Morgenstein struct mlx4_vhcr *vhcr, 7010a9a0188SJack Morgenstein struct mlx4_cmd_mailbox *inbox, 7020a9a0188SJack Morgenstein struct mlx4_cmd_mailbox *outbox, 7030a9a0188SJack Morgenstein struct mlx4_cmd_info *cmd) 7040a9a0188SJack Morgenstein { 7050a9a0188SJack Morgenstein struct ib_smp *smp = inbox->buf; 7060a9a0188SJack Morgenstein u32 index; 7070a9a0188SJack Morgenstein u8 port; 7080a9a0188SJack Morgenstein u16 *table; 7090a9a0188SJack Morgenstein int err; 7100a9a0188SJack Morgenstein int vidx, pidx; 7110a9a0188SJack Morgenstein struct mlx4_priv *priv = mlx4_priv(dev); 7120a9a0188SJack Morgenstein struct ib_smp *outsmp = outbox->buf; 7130a9a0188SJack Morgenstein __be16 *outtab = (__be16 *)(outsmp->data); 7140a9a0188SJack Morgenstein __be32 slave_cap_mask; 715afa8fd1dSJack Morgenstein __be64 slave_node_guid; 7160a9a0188SJack Morgenstein port = vhcr->in_modifier; 7170a9a0188SJack Morgenstein 7180a9a0188SJack Morgenstein if (smp->base_version == 1 && 7190a9a0188SJack Morgenstein smp->mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED && 7200a9a0188SJack Morgenstein smp->class_version == 1) { 7210a9a0188SJack Morgenstein if (smp->method == IB_MGMT_METHOD_GET) { 7220a9a0188SJack Morgenstein if (smp->attr_id == IB_SMP_ATTR_PKEY_TABLE) { 7230a9a0188SJack Morgenstein index = be32_to_cpu(smp->attr_mod); 7240a9a0188SJack Morgenstein if (port < 1 || port > dev->caps.num_ports) 7250a9a0188SJack Morgenstein return -EINVAL; 7260a9a0188SJack Morgenstein table = kcalloc(dev->caps.pkey_table_len[port], sizeof *table, GFP_KERNEL); 7270a9a0188SJack Morgenstein if (!table) 7280a9a0188SJack Morgenstein return -ENOMEM; 7290a9a0188SJack Morgenstein /* need to get the full pkey table because the paravirtualized 7300a9a0188SJack Morgenstein * pkeys may be scattered among several pkey blocks. 7310a9a0188SJack Morgenstein */ 7320a9a0188SJack Morgenstein err = get_full_pkey_table(dev, port, table, inbox, outbox); 7330a9a0188SJack Morgenstein if (!err) { 7340a9a0188SJack Morgenstein for (vidx = index * 32; vidx < (index + 1) * 32; ++vidx) { 7350a9a0188SJack Morgenstein pidx = priv->virt2phys_pkey[slave][port - 1][vidx]; 7360a9a0188SJack Morgenstein outtab[vidx % 32] = cpu_to_be16(table[pidx]); 7370a9a0188SJack Morgenstein } 7380a9a0188SJack Morgenstein } 7390a9a0188SJack Morgenstein kfree(table); 7400a9a0188SJack Morgenstein return err; 7410a9a0188SJack Morgenstein } 7420a9a0188SJack Morgenstein if (smp->attr_id == IB_SMP_ATTR_PORT_INFO) { 7430a9a0188SJack Morgenstein /*get the slave specific caps:*/ 7440a9a0188SJack Morgenstein /*do the command */ 7450a9a0188SJack Morgenstein err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, 7460a9a0188SJack Morgenstein vhcr->in_modifier, vhcr->op_modifier, 7470a9a0188SJack Morgenstein vhcr->op, MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE); 7480a9a0188SJack Morgenstein /* modify the response for slaves */ 7490a9a0188SJack Morgenstein if (!err && slave != mlx4_master_func_num(dev)) { 7500a9a0188SJack Morgenstein u8 *state = outsmp->data + PORT_STATE_OFFSET; 7510a9a0188SJack Morgenstein 7520a9a0188SJack Morgenstein *state = (*state & 0xf0) | vf_port_state(dev, port, slave); 7530a9a0188SJack Morgenstein slave_cap_mask = priv->mfunc.master.slave_state[slave].ib_cap_mask[port]; 7540a9a0188SJack Morgenstein memcpy(outsmp->data + PORT_CAPABILITY_LOCATION_IN_SMP, &slave_cap_mask, 4); 7550a9a0188SJack Morgenstein } 7560a9a0188SJack Morgenstein return err; 7570a9a0188SJack Morgenstein } 7580a9a0188SJack Morgenstein if (smp->attr_id == IB_SMP_ATTR_GUID_INFO) { 7590a9a0188SJack Morgenstein /* compute slave's gid block */ 7600a9a0188SJack Morgenstein smp->attr_mod = cpu_to_be32(slave / 8); 7610a9a0188SJack Morgenstein /* execute cmd */ 7620a9a0188SJack Morgenstein err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, 7630a9a0188SJack Morgenstein vhcr->in_modifier, vhcr->op_modifier, 7640a9a0188SJack Morgenstein vhcr->op, MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE); 7650a9a0188SJack Morgenstein if (!err) { 7660a9a0188SJack Morgenstein /* if needed, move slave gid to index 0 */ 7670a9a0188SJack Morgenstein if (slave % 8) 7680a9a0188SJack Morgenstein memcpy(outsmp->data, 7690a9a0188SJack Morgenstein outsmp->data + (slave % 8) * 8, 8); 7700a9a0188SJack Morgenstein /* delete all other gids */ 7710a9a0188SJack Morgenstein memset(outsmp->data + 8, 0, 56); 7720a9a0188SJack Morgenstein } 7730a9a0188SJack Morgenstein return err; 7740a9a0188SJack Morgenstein } 775afa8fd1dSJack Morgenstein if (smp->attr_id == IB_SMP_ATTR_NODE_INFO) { 776afa8fd1dSJack Morgenstein err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, 777afa8fd1dSJack Morgenstein vhcr->in_modifier, vhcr->op_modifier, 778afa8fd1dSJack Morgenstein vhcr->op, MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE); 779afa8fd1dSJack Morgenstein if (!err) { 780afa8fd1dSJack Morgenstein slave_node_guid = mlx4_get_slave_node_guid(dev, slave); 781afa8fd1dSJack Morgenstein memcpy(outsmp->data + 12, &slave_node_guid, 8); 782afa8fd1dSJack Morgenstein } 783afa8fd1dSJack Morgenstein return err; 784afa8fd1dSJack Morgenstein } 7850a9a0188SJack Morgenstein } 7860a9a0188SJack Morgenstein } 7870a9a0188SJack Morgenstein if (slave != mlx4_master_func_num(dev) && 7880a9a0188SJack Morgenstein ((smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) || 7890a9a0188SJack Morgenstein (smp->mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED && 7900a9a0188SJack Morgenstein smp->method == IB_MGMT_METHOD_SET))) { 7910a9a0188SJack Morgenstein mlx4_err(dev, "slave %d is trying to execute a Subnet MGMT MAD, " 7920a9a0188SJack Morgenstein "class 0x%x, method 0x%x for attr 0x%x. Rejecting\n", 7930a9a0188SJack Morgenstein slave, smp->method, smp->mgmt_class, 7940a9a0188SJack Morgenstein be16_to_cpu(smp->attr_id)); 7950a9a0188SJack Morgenstein return -EPERM; 7960a9a0188SJack Morgenstein } 7970a9a0188SJack Morgenstein /*default:*/ 7980a9a0188SJack Morgenstein return mlx4_cmd_box(dev, inbox->dma, outbox->dma, 7990a9a0188SJack Morgenstein vhcr->in_modifier, vhcr->op_modifier, 8000a9a0188SJack Morgenstein vhcr->op, MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE); 8010a9a0188SJack Morgenstein } 8020a9a0188SJack Morgenstein 803*b7475794SOr Gerlitz static int mlx4_CMD_EPERM_wrapper(struct mlx4_dev *dev, int slave, 804fe6f700dSYevgeny Petrilin struct mlx4_vhcr *vhcr, 805fe6f700dSYevgeny Petrilin struct mlx4_cmd_mailbox *inbox, 806fe6f700dSYevgeny Petrilin struct mlx4_cmd_mailbox *outbox, 807fe6f700dSYevgeny Petrilin struct mlx4_cmd_info *cmd) 808fe6f700dSYevgeny Petrilin { 809fe6f700dSYevgeny Petrilin return -EPERM; 810fe6f700dSYevgeny Petrilin } 811fe6f700dSYevgeny Petrilin 812e8f081aaSYevgeny Petrilin int mlx4_DMA_wrapper(struct mlx4_dev *dev, int slave, 813e8f081aaSYevgeny Petrilin struct mlx4_vhcr *vhcr, 814e8f081aaSYevgeny Petrilin struct mlx4_cmd_mailbox *inbox, 815e8f081aaSYevgeny Petrilin struct mlx4_cmd_mailbox *outbox, 816e8f081aaSYevgeny Petrilin struct mlx4_cmd_info *cmd) 817e8f081aaSYevgeny Petrilin { 818e8f081aaSYevgeny Petrilin u64 in_param; 819e8f081aaSYevgeny Petrilin u64 out_param; 820e8f081aaSYevgeny Petrilin int err; 821e8f081aaSYevgeny Petrilin 822e8f081aaSYevgeny Petrilin in_param = cmd->has_inbox ? (u64) inbox->dma : vhcr->in_param; 823e8f081aaSYevgeny Petrilin out_param = cmd->has_outbox ? (u64) outbox->dma : vhcr->out_param; 824e8f081aaSYevgeny Petrilin if (cmd->encode_slave_id) { 825e8f081aaSYevgeny Petrilin in_param &= 0xffffffffffffff00ll; 826e8f081aaSYevgeny Petrilin in_param |= slave; 827e8f081aaSYevgeny Petrilin } 828e8f081aaSYevgeny Petrilin 829e8f081aaSYevgeny Petrilin err = __mlx4_cmd(dev, in_param, &out_param, cmd->out_is_imm, 830e8f081aaSYevgeny Petrilin vhcr->in_modifier, vhcr->op_modifier, vhcr->op, 831e8f081aaSYevgeny Petrilin MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE); 832e8f081aaSYevgeny Petrilin 833e8f081aaSYevgeny Petrilin if (cmd->out_is_imm) 834e8f081aaSYevgeny Petrilin vhcr->out_param = out_param; 835e8f081aaSYevgeny Petrilin 836e8f081aaSYevgeny Petrilin return err; 837e8f081aaSYevgeny Petrilin } 838e8f081aaSYevgeny Petrilin 839e8f081aaSYevgeny Petrilin static struct mlx4_cmd_info cmd_info[] = { 840e8f081aaSYevgeny Petrilin { 841e8f081aaSYevgeny Petrilin .opcode = MLX4_CMD_QUERY_FW, 842e8f081aaSYevgeny Petrilin .has_inbox = false, 843e8f081aaSYevgeny Petrilin .has_outbox = true, 844e8f081aaSYevgeny Petrilin .out_is_imm = false, 845e8f081aaSYevgeny Petrilin .encode_slave_id = false, 846e8f081aaSYevgeny Petrilin .verify = NULL, 847b91cb3ebSJack Morgenstein .wrapper = mlx4_QUERY_FW_wrapper 848e8f081aaSYevgeny Petrilin }, 849e8f081aaSYevgeny Petrilin { 850e8f081aaSYevgeny Petrilin .opcode = MLX4_CMD_QUERY_HCA, 851e8f081aaSYevgeny Petrilin .has_inbox = false, 852e8f081aaSYevgeny Petrilin .has_outbox = true, 853e8f081aaSYevgeny Petrilin .out_is_imm = false, 854e8f081aaSYevgeny Petrilin .encode_slave_id = false, 855e8f081aaSYevgeny Petrilin .verify = NULL, 856e8f081aaSYevgeny Petrilin .wrapper = NULL 857e8f081aaSYevgeny Petrilin }, 858e8f081aaSYevgeny Petrilin { 859e8f081aaSYevgeny Petrilin .opcode = MLX4_CMD_QUERY_DEV_CAP, 860e8f081aaSYevgeny Petrilin .has_inbox = false, 861e8f081aaSYevgeny Petrilin .has_outbox = true, 862e8f081aaSYevgeny Petrilin .out_is_imm = false, 863e8f081aaSYevgeny Petrilin .encode_slave_id = false, 864e8f081aaSYevgeny Petrilin .verify = NULL, 865b91cb3ebSJack Morgenstein .wrapper = mlx4_QUERY_DEV_CAP_wrapper 866e8f081aaSYevgeny Petrilin }, 867c82e9aa0SEli Cohen { 868c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_FUNC_CAP, 869c82e9aa0SEli Cohen .has_inbox = false, 870c82e9aa0SEli Cohen .has_outbox = true, 871c82e9aa0SEli Cohen .out_is_imm = false, 872c82e9aa0SEli Cohen .encode_slave_id = false, 873c82e9aa0SEli Cohen .verify = NULL, 874c82e9aa0SEli Cohen .wrapper = mlx4_QUERY_FUNC_CAP_wrapper 875c82e9aa0SEli Cohen }, 876c82e9aa0SEli Cohen { 877c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_ADAPTER, 878c82e9aa0SEli Cohen .has_inbox = false, 879c82e9aa0SEli Cohen .has_outbox = true, 880c82e9aa0SEli Cohen .out_is_imm = false, 881c82e9aa0SEli Cohen .encode_slave_id = false, 882c82e9aa0SEli Cohen .verify = NULL, 883c82e9aa0SEli Cohen .wrapper = NULL 884c82e9aa0SEli Cohen }, 885c82e9aa0SEli Cohen { 886c82e9aa0SEli Cohen .opcode = MLX4_CMD_INIT_PORT, 887c82e9aa0SEli Cohen .has_inbox = false, 888c82e9aa0SEli Cohen .has_outbox = false, 889c82e9aa0SEli Cohen .out_is_imm = false, 890c82e9aa0SEli Cohen .encode_slave_id = false, 891c82e9aa0SEli Cohen .verify = NULL, 892c82e9aa0SEli Cohen .wrapper = mlx4_INIT_PORT_wrapper 893c82e9aa0SEli Cohen }, 894c82e9aa0SEli Cohen { 895c82e9aa0SEli Cohen .opcode = MLX4_CMD_CLOSE_PORT, 896c82e9aa0SEli Cohen .has_inbox = false, 897c82e9aa0SEli Cohen .has_outbox = false, 898c82e9aa0SEli Cohen .out_is_imm = false, 899c82e9aa0SEli Cohen .encode_slave_id = false, 900c82e9aa0SEli Cohen .verify = NULL, 901c82e9aa0SEli Cohen .wrapper = mlx4_CLOSE_PORT_wrapper 902c82e9aa0SEli Cohen }, 903c82e9aa0SEli Cohen { 904c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_PORT, 905c82e9aa0SEli Cohen .has_inbox = false, 906c82e9aa0SEli Cohen .has_outbox = true, 907c82e9aa0SEli Cohen .out_is_imm = false, 908c82e9aa0SEli Cohen .encode_slave_id = false, 909c82e9aa0SEli Cohen .verify = NULL, 910c82e9aa0SEli Cohen .wrapper = mlx4_QUERY_PORT_wrapper 911c82e9aa0SEli Cohen }, 912c82e9aa0SEli Cohen { 913ffe455adSEugenia Emantayev .opcode = MLX4_CMD_SET_PORT, 914ffe455adSEugenia Emantayev .has_inbox = true, 915ffe455adSEugenia Emantayev .has_outbox = false, 916ffe455adSEugenia Emantayev .out_is_imm = false, 917ffe455adSEugenia Emantayev .encode_slave_id = false, 918ffe455adSEugenia Emantayev .verify = NULL, 919ffe455adSEugenia Emantayev .wrapper = mlx4_SET_PORT_wrapper 920ffe455adSEugenia Emantayev }, 921ffe455adSEugenia Emantayev { 922c82e9aa0SEli Cohen .opcode = MLX4_CMD_MAP_EQ, 923c82e9aa0SEli Cohen .has_inbox = false, 924c82e9aa0SEli Cohen .has_outbox = false, 925c82e9aa0SEli Cohen .out_is_imm = false, 926c82e9aa0SEli Cohen .encode_slave_id = false, 927c82e9aa0SEli Cohen .verify = NULL, 928c82e9aa0SEli Cohen .wrapper = mlx4_MAP_EQ_wrapper 929c82e9aa0SEli Cohen }, 930c82e9aa0SEli Cohen { 931c82e9aa0SEli Cohen .opcode = MLX4_CMD_SW2HW_EQ, 932c82e9aa0SEli Cohen .has_inbox = true, 933c82e9aa0SEli Cohen .has_outbox = false, 934c82e9aa0SEli Cohen .out_is_imm = false, 935c82e9aa0SEli Cohen .encode_slave_id = true, 936c82e9aa0SEli Cohen .verify = NULL, 937c82e9aa0SEli Cohen .wrapper = mlx4_SW2HW_EQ_wrapper 938c82e9aa0SEli Cohen }, 939c82e9aa0SEli Cohen { 940c82e9aa0SEli Cohen .opcode = MLX4_CMD_HW_HEALTH_CHECK, 941c82e9aa0SEli Cohen .has_inbox = false, 942c82e9aa0SEli Cohen .has_outbox = false, 943c82e9aa0SEli Cohen .out_is_imm = false, 944c82e9aa0SEli Cohen .encode_slave_id = false, 945c82e9aa0SEli Cohen .verify = NULL, 946c82e9aa0SEli Cohen .wrapper = NULL 947c82e9aa0SEli Cohen }, 948c82e9aa0SEli Cohen { 949c82e9aa0SEli Cohen .opcode = MLX4_CMD_NOP, 950c82e9aa0SEli Cohen .has_inbox = false, 951c82e9aa0SEli Cohen .has_outbox = false, 952c82e9aa0SEli Cohen .out_is_imm = false, 953c82e9aa0SEli Cohen .encode_slave_id = false, 954c82e9aa0SEli Cohen .verify = NULL, 955c82e9aa0SEli Cohen .wrapper = NULL 956c82e9aa0SEli Cohen }, 957c82e9aa0SEli Cohen { 958c82e9aa0SEli Cohen .opcode = MLX4_CMD_ALLOC_RES, 959c82e9aa0SEli Cohen .has_inbox = false, 960c82e9aa0SEli Cohen .has_outbox = false, 961c82e9aa0SEli Cohen .out_is_imm = true, 962c82e9aa0SEli Cohen .encode_slave_id = false, 963c82e9aa0SEli Cohen .verify = NULL, 964c82e9aa0SEli Cohen .wrapper = mlx4_ALLOC_RES_wrapper 965c82e9aa0SEli Cohen }, 966c82e9aa0SEli Cohen { 967c82e9aa0SEli Cohen .opcode = MLX4_CMD_FREE_RES, 968c82e9aa0SEli Cohen .has_inbox = false, 969c82e9aa0SEli Cohen .has_outbox = false, 970c82e9aa0SEli Cohen .out_is_imm = false, 971c82e9aa0SEli Cohen .encode_slave_id = false, 972c82e9aa0SEli Cohen .verify = NULL, 973c82e9aa0SEli Cohen .wrapper = mlx4_FREE_RES_wrapper 974c82e9aa0SEli Cohen }, 975c82e9aa0SEli Cohen { 976c82e9aa0SEli Cohen .opcode = MLX4_CMD_SW2HW_MPT, 977c82e9aa0SEli Cohen .has_inbox = true, 978c82e9aa0SEli Cohen .has_outbox = false, 979c82e9aa0SEli Cohen .out_is_imm = false, 980c82e9aa0SEli Cohen .encode_slave_id = true, 981c82e9aa0SEli Cohen .verify = NULL, 982c82e9aa0SEli Cohen .wrapper = mlx4_SW2HW_MPT_wrapper 983c82e9aa0SEli Cohen }, 984c82e9aa0SEli Cohen { 985c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_MPT, 986c82e9aa0SEli Cohen .has_inbox = false, 987c82e9aa0SEli Cohen .has_outbox = true, 988c82e9aa0SEli Cohen .out_is_imm = false, 989c82e9aa0SEli Cohen .encode_slave_id = false, 990c82e9aa0SEli Cohen .verify = NULL, 991c82e9aa0SEli Cohen .wrapper = mlx4_QUERY_MPT_wrapper 992c82e9aa0SEli Cohen }, 993c82e9aa0SEli Cohen { 994c82e9aa0SEli Cohen .opcode = MLX4_CMD_HW2SW_MPT, 995c82e9aa0SEli Cohen .has_inbox = false, 996c82e9aa0SEli Cohen .has_outbox = false, 997c82e9aa0SEli Cohen .out_is_imm = false, 998c82e9aa0SEli Cohen .encode_slave_id = false, 999c82e9aa0SEli Cohen .verify = NULL, 1000c82e9aa0SEli Cohen .wrapper = mlx4_HW2SW_MPT_wrapper 1001c82e9aa0SEli Cohen }, 1002c82e9aa0SEli Cohen { 1003c82e9aa0SEli Cohen .opcode = MLX4_CMD_READ_MTT, 1004c82e9aa0SEli Cohen .has_inbox = false, 1005c82e9aa0SEli Cohen .has_outbox = true, 1006c82e9aa0SEli Cohen .out_is_imm = false, 1007c82e9aa0SEli Cohen .encode_slave_id = false, 1008c82e9aa0SEli Cohen .verify = NULL, 1009c82e9aa0SEli Cohen .wrapper = NULL 1010c82e9aa0SEli Cohen }, 1011c82e9aa0SEli Cohen { 1012c82e9aa0SEli Cohen .opcode = MLX4_CMD_WRITE_MTT, 1013c82e9aa0SEli Cohen .has_inbox = true, 1014c82e9aa0SEli Cohen .has_outbox = false, 1015c82e9aa0SEli Cohen .out_is_imm = false, 1016c82e9aa0SEli Cohen .encode_slave_id = false, 1017c82e9aa0SEli Cohen .verify = NULL, 1018c82e9aa0SEli Cohen .wrapper = mlx4_WRITE_MTT_wrapper 1019c82e9aa0SEli Cohen }, 1020c82e9aa0SEli Cohen { 1021c82e9aa0SEli Cohen .opcode = MLX4_CMD_SYNC_TPT, 1022c82e9aa0SEli Cohen .has_inbox = true, 1023c82e9aa0SEli Cohen .has_outbox = false, 1024c82e9aa0SEli Cohen .out_is_imm = false, 1025c82e9aa0SEli Cohen .encode_slave_id = false, 1026c82e9aa0SEli Cohen .verify = NULL, 1027c82e9aa0SEli Cohen .wrapper = NULL 1028c82e9aa0SEli Cohen }, 1029c82e9aa0SEli Cohen { 1030c82e9aa0SEli Cohen .opcode = MLX4_CMD_HW2SW_EQ, 1031c82e9aa0SEli Cohen .has_inbox = false, 1032c82e9aa0SEli Cohen .has_outbox = true, 1033c82e9aa0SEli Cohen .out_is_imm = false, 1034c82e9aa0SEli Cohen .encode_slave_id = true, 1035c82e9aa0SEli Cohen .verify = NULL, 1036c82e9aa0SEli Cohen .wrapper = mlx4_HW2SW_EQ_wrapper 1037c82e9aa0SEli Cohen }, 1038c82e9aa0SEli Cohen { 1039c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_EQ, 1040c82e9aa0SEli Cohen .has_inbox = false, 1041c82e9aa0SEli Cohen .has_outbox = true, 1042c82e9aa0SEli Cohen .out_is_imm = false, 1043c82e9aa0SEli Cohen .encode_slave_id = true, 1044c82e9aa0SEli Cohen .verify = NULL, 1045c82e9aa0SEli Cohen .wrapper = mlx4_QUERY_EQ_wrapper 1046c82e9aa0SEli Cohen }, 1047c82e9aa0SEli Cohen { 1048c82e9aa0SEli Cohen .opcode = MLX4_CMD_SW2HW_CQ, 1049c82e9aa0SEli Cohen .has_inbox = true, 1050c82e9aa0SEli Cohen .has_outbox = false, 1051c82e9aa0SEli Cohen .out_is_imm = false, 1052c82e9aa0SEli Cohen .encode_slave_id = true, 1053c82e9aa0SEli Cohen .verify = NULL, 1054c82e9aa0SEli Cohen .wrapper = mlx4_SW2HW_CQ_wrapper 1055c82e9aa0SEli Cohen }, 1056c82e9aa0SEli Cohen { 1057c82e9aa0SEli Cohen .opcode = MLX4_CMD_HW2SW_CQ, 1058c82e9aa0SEli Cohen .has_inbox = false, 1059c82e9aa0SEli Cohen .has_outbox = false, 1060c82e9aa0SEli Cohen .out_is_imm = false, 1061c82e9aa0SEli Cohen .encode_slave_id = false, 1062c82e9aa0SEli Cohen .verify = NULL, 1063c82e9aa0SEli Cohen .wrapper = mlx4_HW2SW_CQ_wrapper 1064c82e9aa0SEli Cohen }, 1065c82e9aa0SEli Cohen { 1066c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_CQ, 1067c82e9aa0SEli Cohen .has_inbox = false, 1068c82e9aa0SEli Cohen .has_outbox = true, 1069c82e9aa0SEli Cohen .out_is_imm = false, 1070c82e9aa0SEli Cohen .encode_slave_id = false, 1071c82e9aa0SEli Cohen .verify = NULL, 1072c82e9aa0SEli Cohen .wrapper = mlx4_QUERY_CQ_wrapper 1073c82e9aa0SEli Cohen }, 1074c82e9aa0SEli Cohen { 1075c82e9aa0SEli Cohen .opcode = MLX4_CMD_MODIFY_CQ, 1076c82e9aa0SEli Cohen .has_inbox = true, 1077c82e9aa0SEli Cohen .has_outbox = false, 1078c82e9aa0SEli Cohen .out_is_imm = true, 1079c82e9aa0SEli Cohen .encode_slave_id = false, 1080c82e9aa0SEli Cohen .verify = NULL, 1081c82e9aa0SEli Cohen .wrapper = mlx4_MODIFY_CQ_wrapper 1082c82e9aa0SEli Cohen }, 1083c82e9aa0SEli Cohen { 1084c82e9aa0SEli Cohen .opcode = MLX4_CMD_SW2HW_SRQ, 1085c82e9aa0SEli Cohen .has_inbox = true, 1086c82e9aa0SEli Cohen .has_outbox = false, 1087c82e9aa0SEli Cohen .out_is_imm = false, 1088c82e9aa0SEli Cohen .encode_slave_id = true, 1089c82e9aa0SEli Cohen .verify = NULL, 1090c82e9aa0SEli Cohen .wrapper = mlx4_SW2HW_SRQ_wrapper 1091c82e9aa0SEli Cohen }, 1092c82e9aa0SEli Cohen { 1093c82e9aa0SEli Cohen .opcode = MLX4_CMD_HW2SW_SRQ, 1094c82e9aa0SEli Cohen .has_inbox = false, 1095c82e9aa0SEli Cohen .has_outbox = false, 1096c82e9aa0SEli Cohen .out_is_imm = false, 1097c82e9aa0SEli Cohen .encode_slave_id = false, 1098c82e9aa0SEli Cohen .verify = NULL, 1099c82e9aa0SEli Cohen .wrapper = mlx4_HW2SW_SRQ_wrapper 1100c82e9aa0SEli Cohen }, 1101c82e9aa0SEli Cohen { 1102c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_SRQ, 1103c82e9aa0SEli Cohen .has_inbox = false, 1104c82e9aa0SEli Cohen .has_outbox = true, 1105c82e9aa0SEli Cohen .out_is_imm = false, 1106c82e9aa0SEli Cohen .encode_slave_id = false, 1107c82e9aa0SEli Cohen .verify = NULL, 1108c82e9aa0SEli Cohen .wrapper = mlx4_QUERY_SRQ_wrapper 1109c82e9aa0SEli Cohen }, 1110c82e9aa0SEli Cohen { 1111c82e9aa0SEli Cohen .opcode = MLX4_CMD_ARM_SRQ, 1112c82e9aa0SEli Cohen .has_inbox = false, 1113c82e9aa0SEli Cohen .has_outbox = false, 1114c82e9aa0SEli Cohen .out_is_imm = false, 1115c82e9aa0SEli Cohen .encode_slave_id = false, 1116c82e9aa0SEli Cohen .verify = NULL, 1117c82e9aa0SEli Cohen .wrapper = mlx4_ARM_SRQ_wrapper 1118c82e9aa0SEli Cohen }, 1119c82e9aa0SEli Cohen { 1120c82e9aa0SEli Cohen .opcode = MLX4_CMD_RST2INIT_QP, 1121c82e9aa0SEli Cohen .has_inbox = true, 1122c82e9aa0SEli Cohen .has_outbox = false, 1123c82e9aa0SEli Cohen .out_is_imm = false, 1124c82e9aa0SEli Cohen .encode_slave_id = true, 1125c82e9aa0SEli Cohen .verify = NULL, 1126c82e9aa0SEli Cohen .wrapper = mlx4_RST2INIT_QP_wrapper 1127c82e9aa0SEli Cohen }, 1128c82e9aa0SEli Cohen { 1129c82e9aa0SEli Cohen .opcode = MLX4_CMD_INIT2INIT_QP, 1130c82e9aa0SEli Cohen .has_inbox = true, 1131c82e9aa0SEli Cohen .has_outbox = false, 1132c82e9aa0SEli Cohen .out_is_imm = false, 1133c82e9aa0SEli Cohen .encode_slave_id = false, 1134c82e9aa0SEli Cohen .verify = NULL, 113554679e14SJack Morgenstein .wrapper = mlx4_INIT2INIT_QP_wrapper 1136c82e9aa0SEli Cohen }, 1137c82e9aa0SEli Cohen { 1138c82e9aa0SEli Cohen .opcode = MLX4_CMD_INIT2RTR_QP, 1139c82e9aa0SEli Cohen .has_inbox = true, 1140c82e9aa0SEli Cohen .has_outbox = false, 1141c82e9aa0SEli Cohen .out_is_imm = false, 1142c82e9aa0SEli Cohen .encode_slave_id = false, 1143c82e9aa0SEli Cohen .verify = NULL, 1144c82e9aa0SEli Cohen .wrapper = mlx4_INIT2RTR_QP_wrapper 1145c82e9aa0SEli Cohen }, 1146c82e9aa0SEli Cohen { 1147c82e9aa0SEli Cohen .opcode = MLX4_CMD_RTR2RTS_QP, 1148c82e9aa0SEli Cohen .has_inbox = true, 1149c82e9aa0SEli Cohen .has_outbox = false, 1150c82e9aa0SEli Cohen .out_is_imm = false, 1151c82e9aa0SEli Cohen .encode_slave_id = false, 1152c82e9aa0SEli Cohen .verify = NULL, 115354679e14SJack Morgenstein .wrapper = mlx4_RTR2RTS_QP_wrapper 1154c82e9aa0SEli Cohen }, 1155c82e9aa0SEli Cohen { 1156c82e9aa0SEli Cohen .opcode = MLX4_CMD_RTS2RTS_QP, 1157c82e9aa0SEli Cohen .has_inbox = true, 1158c82e9aa0SEli Cohen .has_outbox = false, 1159c82e9aa0SEli Cohen .out_is_imm = false, 1160c82e9aa0SEli Cohen .encode_slave_id = false, 1161c82e9aa0SEli Cohen .verify = NULL, 116254679e14SJack Morgenstein .wrapper = mlx4_RTS2RTS_QP_wrapper 1163c82e9aa0SEli Cohen }, 1164c82e9aa0SEli Cohen { 1165c82e9aa0SEli Cohen .opcode = MLX4_CMD_SQERR2RTS_QP, 1166c82e9aa0SEli Cohen .has_inbox = true, 1167c82e9aa0SEli Cohen .has_outbox = false, 1168c82e9aa0SEli Cohen .out_is_imm = false, 1169c82e9aa0SEli Cohen .encode_slave_id = false, 1170c82e9aa0SEli Cohen .verify = NULL, 117154679e14SJack Morgenstein .wrapper = mlx4_SQERR2RTS_QP_wrapper 1172c82e9aa0SEli Cohen }, 1173c82e9aa0SEli Cohen { 1174c82e9aa0SEli Cohen .opcode = MLX4_CMD_2ERR_QP, 1175c82e9aa0SEli Cohen .has_inbox = false, 1176c82e9aa0SEli Cohen .has_outbox = false, 1177c82e9aa0SEli Cohen .out_is_imm = false, 1178c82e9aa0SEli Cohen .encode_slave_id = false, 1179c82e9aa0SEli Cohen .verify = NULL, 1180c82e9aa0SEli Cohen .wrapper = mlx4_GEN_QP_wrapper 1181c82e9aa0SEli Cohen }, 1182c82e9aa0SEli Cohen { 1183c82e9aa0SEli Cohen .opcode = MLX4_CMD_RTS2SQD_QP, 1184c82e9aa0SEli Cohen .has_inbox = false, 1185c82e9aa0SEli Cohen .has_outbox = false, 1186c82e9aa0SEli Cohen .out_is_imm = false, 1187c82e9aa0SEli Cohen .encode_slave_id = false, 1188c82e9aa0SEli Cohen .verify = NULL, 1189c82e9aa0SEli Cohen .wrapper = mlx4_GEN_QP_wrapper 1190c82e9aa0SEli Cohen }, 1191c82e9aa0SEli Cohen { 1192c82e9aa0SEli Cohen .opcode = MLX4_CMD_SQD2SQD_QP, 1193c82e9aa0SEli Cohen .has_inbox = true, 1194c82e9aa0SEli Cohen .has_outbox = false, 1195c82e9aa0SEli Cohen .out_is_imm = false, 1196c82e9aa0SEli Cohen .encode_slave_id = false, 1197c82e9aa0SEli Cohen .verify = NULL, 119854679e14SJack Morgenstein .wrapper = mlx4_SQD2SQD_QP_wrapper 1199c82e9aa0SEli Cohen }, 1200c82e9aa0SEli Cohen { 1201c82e9aa0SEli Cohen .opcode = MLX4_CMD_SQD2RTS_QP, 1202c82e9aa0SEli Cohen .has_inbox = true, 1203c82e9aa0SEli Cohen .has_outbox = false, 1204c82e9aa0SEli Cohen .out_is_imm = false, 1205c82e9aa0SEli Cohen .encode_slave_id = false, 1206c82e9aa0SEli Cohen .verify = NULL, 120754679e14SJack Morgenstein .wrapper = mlx4_SQD2RTS_QP_wrapper 1208c82e9aa0SEli Cohen }, 1209c82e9aa0SEli Cohen { 1210c82e9aa0SEli Cohen .opcode = MLX4_CMD_2RST_QP, 1211c82e9aa0SEli Cohen .has_inbox = false, 1212c82e9aa0SEli Cohen .has_outbox = false, 1213c82e9aa0SEli Cohen .out_is_imm = false, 1214c82e9aa0SEli Cohen .encode_slave_id = false, 1215c82e9aa0SEli Cohen .verify = NULL, 1216c82e9aa0SEli Cohen .wrapper = mlx4_2RST_QP_wrapper 1217c82e9aa0SEli Cohen }, 1218c82e9aa0SEli Cohen { 1219c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_QP, 1220c82e9aa0SEli Cohen .has_inbox = false, 1221c82e9aa0SEli Cohen .has_outbox = true, 1222c82e9aa0SEli Cohen .out_is_imm = false, 1223c82e9aa0SEli Cohen .encode_slave_id = false, 1224c82e9aa0SEli Cohen .verify = NULL, 1225c82e9aa0SEli Cohen .wrapper = mlx4_GEN_QP_wrapper 1226c82e9aa0SEli Cohen }, 1227c82e9aa0SEli Cohen { 1228c82e9aa0SEli Cohen .opcode = MLX4_CMD_SUSPEND_QP, 1229c82e9aa0SEli Cohen .has_inbox = false, 1230c82e9aa0SEli Cohen .has_outbox = false, 1231c82e9aa0SEli Cohen .out_is_imm = false, 1232c82e9aa0SEli Cohen .encode_slave_id = false, 1233c82e9aa0SEli Cohen .verify = NULL, 1234c82e9aa0SEli Cohen .wrapper = mlx4_GEN_QP_wrapper 1235c82e9aa0SEli Cohen }, 1236c82e9aa0SEli Cohen { 1237c82e9aa0SEli Cohen .opcode = MLX4_CMD_UNSUSPEND_QP, 1238c82e9aa0SEli Cohen .has_inbox = false, 1239c82e9aa0SEli Cohen .has_outbox = false, 1240c82e9aa0SEli Cohen .out_is_imm = false, 1241c82e9aa0SEli Cohen .encode_slave_id = false, 1242c82e9aa0SEli Cohen .verify = NULL, 1243c82e9aa0SEli Cohen .wrapper = mlx4_GEN_QP_wrapper 1244c82e9aa0SEli Cohen }, 1245c82e9aa0SEli Cohen { 1246b01978caSJack Morgenstein .opcode = MLX4_CMD_UPDATE_QP, 1247b01978caSJack Morgenstein .has_inbox = false, 1248b01978caSJack Morgenstein .has_outbox = false, 1249b01978caSJack Morgenstein .out_is_imm = false, 1250b01978caSJack Morgenstein .encode_slave_id = false, 1251b01978caSJack Morgenstein .verify = NULL, 1252*b7475794SOr Gerlitz .wrapper = mlx4_CMD_EPERM_wrapper 1253b01978caSJack Morgenstein }, 1254b01978caSJack Morgenstein { 1255fe6f700dSYevgeny Petrilin .opcode = MLX4_CMD_GET_OP_REQ, 1256fe6f700dSYevgeny Petrilin .has_inbox = false, 1257fe6f700dSYevgeny Petrilin .has_outbox = false, 1258fe6f700dSYevgeny Petrilin .out_is_imm = false, 1259fe6f700dSYevgeny Petrilin .encode_slave_id = false, 1260fe6f700dSYevgeny Petrilin .verify = NULL, 1261*b7475794SOr Gerlitz .wrapper = mlx4_CMD_EPERM_wrapper, 1262fe6f700dSYevgeny Petrilin }, 1263fe6f700dSYevgeny Petrilin { 12640a9a0188SJack Morgenstein .opcode = MLX4_CMD_CONF_SPECIAL_QP, 12650a9a0188SJack Morgenstein .has_inbox = false, 12660a9a0188SJack Morgenstein .has_outbox = false, 12670a9a0188SJack Morgenstein .out_is_imm = false, 12680a9a0188SJack Morgenstein .encode_slave_id = false, 12690a9a0188SJack Morgenstein .verify = NULL, /* XXX verify: only demux can do this */ 12700a9a0188SJack Morgenstein .wrapper = NULL 12710a9a0188SJack Morgenstein }, 12720a9a0188SJack Morgenstein { 12730a9a0188SJack Morgenstein .opcode = MLX4_CMD_MAD_IFC, 12740a9a0188SJack Morgenstein .has_inbox = true, 12750a9a0188SJack Morgenstein .has_outbox = true, 12760a9a0188SJack Morgenstein .out_is_imm = false, 12770a9a0188SJack Morgenstein .encode_slave_id = false, 12780a9a0188SJack Morgenstein .verify = NULL, 12790a9a0188SJack Morgenstein .wrapper = mlx4_MAD_IFC_wrapper 12800a9a0188SJack Morgenstein }, 12810a9a0188SJack Morgenstein { 1282c82e9aa0SEli Cohen .opcode = MLX4_CMD_QUERY_IF_STAT, 1283c82e9aa0SEli Cohen .has_inbox = false, 1284c82e9aa0SEli Cohen .has_outbox = true, 1285c82e9aa0SEli Cohen .out_is_imm = false, 1286c82e9aa0SEli Cohen .encode_slave_id = false, 1287c82e9aa0SEli Cohen .verify = NULL, 1288c82e9aa0SEli Cohen .wrapper = mlx4_QUERY_IF_STAT_wrapper 1289c82e9aa0SEli Cohen }, 1290c82e9aa0SEli Cohen /* Native multicast commands are not available for guests */ 1291c82e9aa0SEli Cohen { 1292c82e9aa0SEli Cohen .opcode = MLX4_CMD_QP_ATTACH, 1293c82e9aa0SEli Cohen .has_inbox = true, 1294c82e9aa0SEli Cohen .has_outbox = false, 1295c82e9aa0SEli Cohen .out_is_imm = false, 1296c82e9aa0SEli Cohen .encode_slave_id = false, 1297c82e9aa0SEli Cohen .verify = NULL, 1298c82e9aa0SEli Cohen .wrapper = mlx4_QP_ATTACH_wrapper 1299c82e9aa0SEli Cohen }, 1300c82e9aa0SEli Cohen { 13010ec2c0f8SEugenia Emantayev .opcode = MLX4_CMD_PROMISC, 13020ec2c0f8SEugenia Emantayev .has_inbox = false, 13030ec2c0f8SEugenia Emantayev .has_outbox = false, 13040ec2c0f8SEugenia Emantayev .out_is_imm = false, 13050ec2c0f8SEugenia Emantayev .encode_slave_id = false, 13060ec2c0f8SEugenia Emantayev .verify = NULL, 13070ec2c0f8SEugenia Emantayev .wrapper = mlx4_PROMISC_wrapper 13080ec2c0f8SEugenia Emantayev }, 1309ffe455adSEugenia Emantayev /* Ethernet specific commands */ 1310ffe455adSEugenia Emantayev { 1311ffe455adSEugenia Emantayev .opcode = MLX4_CMD_SET_VLAN_FLTR, 1312ffe455adSEugenia Emantayev .has_inbox = true, 1313ffe455adSEugenia Emantayev .has_outbox = false, 1314ffe455adSEugenia Emantayev .out_is_imm = false, 1315ffe455adSEugenia Emantayev .encode_slave_id = false, 1316ffe455adSEugenia Emantayev .verify = NULL, 1317ffe455adSEugenia Emantayev .wrapper = mlx4_SET_VLAN_FLTR_wrapper 1318ffe455adSEugenia Emantayev }, 1319ffe455adSEugenia Emantayev { 1320ffe455adSEugenia Emantayev .opcode = MLX4_CMD_SET_MCAST_FLTR, 1321ffe455adSEugenia Emantayev .has_inbox = false, 1322ffe455adSEugenia Emantayev .has_outbox = false, 1323ffe455adSEugenia Emantayev .out_is_imm = false, 1324ffe455adSEugenia Emantayev .encode_slave_id = false, 1325ffe455adSEugenia Emantayev .verify = NULL, 1326ffe455adSEugenia Emantayev .wrapper = mlx4_SET_MCAST_FLTR_wrapper 1327ffe455adSEugenia Emantayev }, 1328ffe455adSEugenia Emantayev { 1329ffe455adSEugenia Emantayev .opcode = MLX4_CMD_DUMP_ETH_STATS, 1330ffe455adSEugenia Emantayev .has_inbox = false, 1331ffe455adSEugenia Emantayev .has_outbox = true, 1332ffe455adSEugenia Emantayev .out_is_imm = false, 1333ffe455adSEugenia Emantayev .encode_slave_id = false, 1334ffe455adSEugenia Emantayev .verify = NULL, 1335ffe455adSEugenia Emantayev .wrapper = mlx4_DUMP_ETH_STATS_wrapper 1336ffe455adSEugenia Emantayev }, 13370ec2c0f8SEugenia Emantayev { 1338c82e9aa0SEli Cohen .opcode = MLX4_CMD_INFORM_FLR_DONE, 1339c82e9aa0SEli Cohen .has_inbox = false, 1340c82e9aa0SEli Cohen .has_outbox = false, 1341c82e9aa0SEli Cohen .out_is_imm = false, 1342c82e9aa0SEli Cohen .encode_slave_id = false, 1343c82e9aa0SEli Cohen .verify = NULL, 1344c82e9aa0SEli Cohen .wrapper = NULL 1345c82e9aa0SEli Cohen }, 13468fcfb4dbSHadar Hen Zion /* flow steering commands */ 13478fcfb4dbSHadar Hen Zion { 13488fcfb4dbSHadar Hen Zion .opcode = MLX4_QP_FLOW_STEERING_ATTACH, 13498fcfb4dbSHadar Hen Zion .has_inbox = true, 13508fcfb4dbSHadar Hen Zion .has_outbox = false, 13518fcfb4dbSHadar Hen Zion .out_is_imm = true, 13528fcfb4dbSHadar Hen Zion .encode_slave_id = false, 13538fcfb4dbSHadar Hen Zion .verify = NULL, 13548fcfb4dbSHadar Hen Zion .wrapper = mlx4_QP_FLOW_STEERING_ATTACH_wrapper 13558fcfb4dbSHadar Hen Zion }, 13568fcfb4dbSHadar Hen Zion { 13578fcfb4dbSHadar Hen Zion .opcode = MLX4_QP_FLOW_STEERING_DETACH, 13588fcfb4dbSHadar Hen Zion .has_inbox = false, 13598fcfb4dbSHadar Hen Zion .has_outbox = false, 13608fcfb4dbSHadar Hen Zion .out_is_imm = false, 13618fcfb4dbSHadar Hen Zion .encode_slave_id = false, 13628fcfb4dbSHadar Hen Zion .verify = NULL, 13638fcfb4dbSHadar Hen Zion .wrapper = mlx4_QP_FLOW_STEERING_DETACH_wrapper 13648fcfb4dbSHadar Hen Zion }, 13654de65803SMatan Barak { 13664de65803SMatan Barak .opcode = MLX4_FLOW_STEERING_IB_UC_QP_RANGE, 13674de65803SMatan Barak .has_inbox = false, 13684de65803SMatan Barak .has_outbox = false, 13694de65803SMatan Barak .out_is_imm = false, 13704de65803SMatan Barak .encode_slave_id = false, 13714de65803SMatan Barak .verify = NULL, 1372*b7475794SOr Gerlitz .wrapper = mlx4_CMD_EPERM_wrapper 13734de65803SMatan Barak }, 1374e8f081aaSYevgeny Petrilin }; 1375e8f081aaSYevgeny Petrilin 1376e8f081aaSYevgeny Petrilin static int mlx4_master_process_vhcr(struct mlx4_dev *dev, int slave, 1377e8f081aaSYevgeny Petrilin struct mlx4_vhcr_cmd *in_vhcr) 1378e8f081aaSYevgeny Petrilin { 1379e8f081aaSYevgeny Petrilin struct mlx4_priv *priv = mlx4_priv(dev); 1380e8f081aaSYevgeny Petrilin struct mlx4_cmd_info *cmd = NULL; 1381e8f081aaSYevgeny Petrilin struct mlx4_vhcr_cmd *vhcr_cmd = in_vhcr ? in_vhcr : priv->mfunc.vhcr; 1382e8f081aaSYevgeny Petrilin struct mlx4_vhcr *vhcr; 1383e8f081aaSYevgeny Petrilin struct mlx4_cmd_mailbox *inbox = NULL; 1384e8f081aaSYevgeny Petrilin struct mlx4_cmd_mailbox *outbox = NULL; 1385e8f081aaSYevgeny Petrilin u64 in_param; 1386e8f081aaSYevgeny Petrilin u64 out_param; 1387e8f081aaSYevgeny Petrilin int ret = 0; 1388e8f081aaSYevgeny Petrilin int i; 138972be84f1SYevgeny Petrilin int err = 0; 1390e8f081aaSYevgeny Petrilin 1391e8f081aaSYevgeny Petrilin /* Create sw representation of Virtual HCR */ 1392e8f081aaSYevgeny Petrilin vhcr = kzalloc(sizeof(struct mlx4_vhcr), GFP_KERNEL); 1393e8f081aaSYevgeny Petrilin if (!vhcr) 1394e8f081aaSYevgeny Petrilin return -ENOMEM; 1395e8f081aaSYevgeny Petrilin 1396e8f081aaSYevgeny Petrilin /* DMA in the vHCR */ 1397e8f081aaSYevgeny Petrilin if (!in_vhcr) { 1398e8f081aaSYevgeny Petrilin ret = mlx4_ACCESS_MEM(dev, priv->mfunc.vhcr_dma, slave, 1399e8f081aaSYevgeny Petrilin priv->mfunc.master.slave_state[slave].vhcr_dma, 1400e8f081aaSYevgeny Petrilin ALIGN(sizeof(struct mlx4_vhcr_cmd), 1401e8f081aaSYevgeny Petrilin MLX4_ACCESS_MEM_ALIGN), 1); 1402e8f081aaSYevgeny Petrilin if (ret) { 1403e8f081aaSYevgeny Petrilin mlx4_err(dev, "%s:Failed reading vhcr" 1404e8f081aaSYevgeny Petrilin "ret: 0x%x\n", __func__, ret); 1405e8f081aaSYevgeny Petrilin kfree(vhcr); 1406e8f081aaSYevgeny Petrilin return ret; 1407e8f081aaSYevgeny Petrilin } 1408e8f081aaSYevgeny Petrilin } 1409e8f081aaSYevgeny Petrilin 1410e8f081aaSYevgeny Petrilin /* Fill SW VHCR fields */ 1411e8f081aaSYevgeny Petrilin vhcr->in_param = be64_to_cpu(vhcr_cmd->in_param); 1412e8f081aaSYevgeny Petrilin vhcr->out_param = be64_to_cpu(vhcr_cmd->out_param); 1413e8f081aaSYevgeny Petrilin vhcr->in_modifier = be32_to_cpu(vhcr_cmd->in_modifier); 1414e8f081aaSYevgeny Petrilin vhcr->token = be16_to_cpu(vhcr_cmd->token); 1415e8f081aaSYevgeny Petrilin vhcr->op = be16_to_cpu(vhcr_cmd->opcode) & 0xfff; 1416e8f081aaSYevgeny Petrilin vhcr->op_modifier = (u8) (be16_to_cpu(vhcr_cmd->opcode) >> 12); 1417e8f081aaSYevgeny Petrilin vhcr->e_bit = vhcr_cmd->flags & (1 << 6); 1418e8f081aaSYevgeny Petrilin 1419e8f081aaSYevgeny Petrilin /* Lookup command */ 1420e8f081aaSYevgeny Petrilin for (i = 0; i < ARRAY_SIZE(cmd_info); ++i) { 1421e8f081aaSYevgeny Petrilin if (vhcr->op == cmd_info[i].opcode) { 1422e8f081aaSYevgeny Petrilin cmd = &cmd_info[i]; 1423e8f081aaSYevgeny Petrilin break; 1424e8f081aaSYevgeny Petrilin } 1425e8f081aaSYevgeny Petrilin } 1426e8f081aaSYevgeny Petrilin if (!cmd) { 1427e8f081aaSYevgeny Petrilin mlx4_err(dev, "Unknown command:0x%x accepted from slave:%d\n", 1428e8f081aaSYevgeny Petrilin vhcr->op, slave); 142972be84f1SYevgeny Petrilin vhcr_cmd->status = CMD_STAT_BAD_PARAM; 1430e8f081aaSYevgeny Petrilin goto out_status; 1431e8f081aaSYevgeny Petrilin } 1432e8f081aaSYevgeny Petrilin 1433e8f081aaSYevgeny Petrilin /* Read inbox */ 1434e8f081aaSYevgeny Petrilin if (cmd->has_inbox) { 1435e8f081aaSYevgeny Petrilin vhcr->in_param &= INBOX_MASK; 1436e8f081aaSYevgeny Petrilin inbox = mlx4_alloc_cmd_mailbox(dev); 1437e8f081aaSYevgeny Petrilin if (IS_ERR(inbox)) { 143872be84f1SYevgeny Petrilin vhcr_cmd->status = CMD_STAT_BAD_SIZE; 1439e8f081aaSYevgeny Petrilin inbox = NULL; 144072be84f1SYevgeny Petrilin goto out_status; 1441e8f081aaSYevgeny Petrilin } 1442e8f081aaSYevgeny Petrilin 144372be84f1SYevgeny Petrilin if (mlx4_ACCESS_MEM(dev, inbox->dma, slave, 1444e8f081aaSYevgeny Petrilin vhcr->in_param, 144572be84f1SYevgeny Petrilin MLX4_MAILBOX_SIZE, 1)) { 1446e8f081aaSYevgeny Petrilin mlx4_err(dev, "%s: Failed reading inbox (cmd:0x%x)\n", 1447e8f081aaSYevgeny Petrilin __func__, cmd->opcode); 144872be84f1SYevgeny Petrilin vhcr_cmd->status = CMD_STAT_INTERNAL_ERR; 144972be84f1SYevgeny Petrilin goto out_status; 1450e8f081aaSYevgeny Petrilin } 1451e8f081aaSYevgeny Petrilin } 1452e8f081aaSYevgeny Petrilin 1453e8f081aaSYevgeny Petrilin /* Apply permission and bound checks if applicable */ 1454e8f081aaSYevgeny Petrilin if (cmd->verify && cmd->verify(dev, slave, vhcr, inbox)) { 1455e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Command:0x%x from slave: %d failed protection " 1456e8f081aaSYevgeny Petrilin "checks for resource_id:%d\n", vhcr->op, slave, 1457e8f081aaSYevgeny Petrilin vhcr->in_modifier); 145872be84f1SYevgeny Petrilin vhcr_cmd->status = CMD_STAT_BAD_OP; 1459e8f081aaSYevgeny Petrilin goto out_status; 1460e8f081aaSYevgeny Petrilin } 1461e8f081aaSYevgeny Petrilin 1462e8f081aaSYevgeny Petrilin /* Allocate outbox */ 1463e8f081aaSYevgeny Petrilin if (cmd->has_outbox) { 1464e8f081aaSYevgeny Petrilin outbox = mlx4_alloc_cmd_mailbox(dev); 1465e8f081aaSYevgeny Petrilin if (IS_ERR(outbox)) { 146672be84f1SYevgeny Petrilin vhcr_cmd->status = CMD_STAT_BAD_SIZE; 1467e8f081aaSYevgeny Petrilin outbox = NULL; 146872be84f1SYevgeny Petrilin goto out_status; 1469e8f081aaSYevgeny Petrilin } 1470e8f081aaSYevgeny Petrilin } 1471e8f081aaSYevgeny Petrilin 1472e8f081aaSYevgeny Petrilin /* Execute the command! */ 1473e8f081aaSYevgeny Petrilin if (cmd->wrapper) { 147472be84f1SYevgeny Petrilin err = cmd->wrapper(dev, slave, vhcr, inbox, outbox, 1475e8f081aaSYevgeny Petrilin cmd); 1476e8f081aaSYevgeny Petrilin if (cmd->out_is_imm) 1477e8f081aaSYevgeny Petrilin vhcr_cmd->out_param = cpu_to_be64(vhcr->out_param); 1478e8f081aaSYevgeny Petrilin } else { 1479e8f081aaSYevgeny Petrilin in_param = cmd->has_inbox ? (u64) inbox->dma : 1480e8f081aaSYevgeny Petrilin vhcr->in_param; 1481e8f081aaSYevgeny Petrilin out_param = cmd->has_outbox ? (u64) outbox->dma : 1482e8f081aaSYevgeny Petrilin vhcr->out_param; 148372be84f1SYevgeny Petrilin err = __mlx4_cmd(dev, in_param, &out_param, 1484e8f081aaSYevgeny Petrilin cmd->out_is_imm, vhcr->in_modifier, 1485e8f081aaSYevgeny Petrilin vhcr->op_modifier, vhcr->op, 1486e8f081aaSYevgeny Petrilin MLX4_CMD_TIME_CLASS_A, 1487e8f081aaSYevgeny Petrilin MLX4_CMD_NATIVE); 1488e8f081aaSYevgeny Petrilin 1489e8f081aaSYevgeny Petrilin if (cmd->out_is_imm) { 1490e8f081aaSYevgeny Petrilin vhcr->out_param = out_param; 1491e8f081aaSYevgeny Petrilin vhcr_cmd->out_param = cpu_to_be64(vhcr->out_param); 1492e8f081aaSYevgeny Petrilin } 1493e8f081aaSYevgeny Petrilin } 1494e8f081aaSYevgeny Petrilin 149572be84f1SYevgeny Petrilin if (err) { 149672be84f1SYevgeny Petrilin mlx4_warn(dev, "vhcr command:0x%x slave:%d failed with" 149772be84f1SYevgeny Petrilin " error:%d, status %d\n", 149872be84f1SYevgeny Petrilin vhcr->op, slave, vhcr->errno, err); 149972be84f1SYevgeny Petrilin vhcr_cmd->status = mlx4_errno_to_status(err); 150072be84f1SYevgeny Petrilin goto out_status; 150172be84f1SYevgeny Petrilin } 150272be84f1SYevgeny Petrilin 150372be84f1SYevgeny Petrilin 1504e8f081aaSYevgeny Petrilin /* Write outbox if command completed successfully */ 150572be84f1SYevgeny Petrilin if (cmd->has_outbox && !vhcr_cmd->status) { 1506e8f081aaSYevgeny Petrilin ret = mlx4_ACCESS_MEM(dev, outbox->dma, slave, 1507e8f081aaSYevgeny Petrilin vhcr->out_param, 1508e8f081aaSYevgeny Petrilin MLX4_MAILBOX_SIZE, MLX4_CMD_WRAPPED); 1509e8f081aaSYevgeny Petrilin if (ret) { 151072be84f1SYevgeny Petrilin /* If we failed to write back the outbox after the 151172be84f1SYevgeny Petrilin *command was successfully executed, we must fail this 151272be84f1SYevgeny Petrilin * slave, as it is now in undefined state */ 1513e8f081aaSYevgeny Petrilin mlx4_err(dev, "%s:Failed writing outbox\n", __func__); 1514e8f081aaSYevgeny Petrilin goto out; 1515e8f081aaSYevgeny Petrilin } 1516e8f081aaSYevgeny Petrilin } 1517e8f081aaSYevgeny Petrilin 1518e8f081aaSYevgeny Petrilin out_status: 1519e8f081aaSYevgeny Petrilin /* DMA back vhcr result */ 1520e8f081aaSYevgeny Petrilin if (!in_vhcr) { 1521e8f081aaSYevgeny Petrilin ret = mlx4_ACCESS_MEM(dev, priv->mfunc.vhcr_dma, slave, 1522e8f081aaSYevgeny Petrilin priv->mfunc.master.slave_state[slave].vhcr_dma, 1523e8f081aaSYevgeny Petrilin ALIGN(sizeof(struct mlx4_vhcr), 1524e8f081aaSYevgeny Petrilin MLX4_ACCESS_MEM_ALIGN), 1525e8f081aaSYevgeny Petrilin MLX4_CMD_WRAPPED); 1526e8f081aaSYevgeny Petrilin if (ret) 1527e8f081aaSYevgeny Petrilin mlx4_err(dev, "%s:Failed writing vhcr result\n", 1528e8f081aaSYevgeny Petrilin __func__); 1529e8f081aaSYevgeny Petrilin else if (vhcr->e_bit && 1530e8f081aaSYevgeny Petrilin mlx4_GEN_EQE(dev, slave, &priv->mfunc.master.cmd_eqe)) 1531e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Failed to generate command completion " 1532e8f081aaSYevgeny Petrilin "eqe for slave %d\n", slave); 1533e8f081aaSYevgeny Petrilin } 1534e8f081aaSYevgeny Petrilin 1535e8f081aaSYevgeny Petrilin out: 1536e8f081aaSYevgeny Petrilin kfree(vhcr); 1537e8f081aaSYevgeny Petrilin mlx4_free_cmd_mailbox(dev, inbox); 1538e8f081aaSYevgeny Petrilin mlx4_free_cmd_mailbox(dev, outbox); 1539e8f081aaSYevgeny Petrilin return ret; 1540e8f081aaSYevgeny Petrilin } 1541e8f081aaSYevgeny Petrilin 1542f094668cSJingoo Han static int mlx4_master_immediate_activate_vlan_qos(struct mlx4_priv *priv, 1543b01978caSJack Morgenstein int slave, int port) 1544b01978caSJack Morgenstein { 1545b01978caSJack Morgenstein struct mlx4_vport_oper_state *vp_oper; 1546b01978caSJack Morgenstein struct mlx4_vport_state *vp_admin; 1547b01978caSJack Morgenstein struct mlx4_vf_immed_vlan_work *work; 15480a6eac24SRony Efraim struct mlx4_dev *dev = &(priv->dev); 1549b01978caSJack Morgenstein int err; 1550b01978caSJack Morgenstein int admin_vlan_ix = NO_INDX; 1551b01978caSJack Morgenstein 1552b01978caSJack Morgenstein vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port]; 1553b01978caSJack Morgenstein vp_admin = &priv->mfunc.master.vf_admin[slave].vport[port]; 1554b01978caSJack Morgenstein 1555b01978caSJack Morgenstein if (vp_oper->state.default_vlan == vp_admin->default_vlan && 15560a6eac24SRony Efraim vp_oper->state.default_qos == vp_admin->default_qos && 15570a6eac24SRony Efraim vp_oper->state.link_state == vp_admin->link_state) 1558b01978caSJack Morgenstein return 0; 1559b01978caSJack Morgenstein 15600a6eac24SRony Efraim if (!(priv->mfunc.master.slave_state[slave].active && 1561f0f829bfSRony Efraim dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_UPDATE_QP)) { 15620a6eac24SRony Efraim /* even if the UPDATE_QP command isn't supported, we still want 15630a6eac24SRony Efraim * to set this VF link according to the admin directive 15640a6eac24SRony Efraim */ 15650a6eac24SRony Efraim vp_oper->state.link_state = vp_admin->link_state; 15660a6eac24SRony Efraim return -1; 15670a6eac24SRony Efraim } 15680a6eac24SRony Efraim 15690a6eac24SRony Efraim mlx4_dbg(dev, "updating immediately admin params slave %d port %d\n", 15700a6eac24SRony Efraim slave, port); 15710a6eac24SRony Efraim mlx4_dbg(dev, "vlan %d QoS %d link down %d\n", vp_admin->default_vlan, 15720a6eac24SRony Efraim vp_admin->default_qos, vp_admin->link_state); 15730a6eac24SRony Efraim 1574b01978caSJack Morgenstein work = kzalloc(sizeof(*work), GFP_KERNEL); 1575b01978caSJack Morgenstein if (!work) 1576b01978caSJack Morgenstein return -ENOMEM; 1577b01978caSJack Morgenstein 1578b01978caSJack Morgenstein if (vp_oper->state.default_vlan != vp_admin->default_vlan) { 1579f0f829bfSRony Efraim if (MLX4_VGT != vp_admin->default_vlan) { 1580b01978caSJack Morgenstein err = __mlx4_register_vlan(&priv->dev, port, 1581b01978caSJack Morgenstein vp_admin->default_vlan, 1582b01978caSJack Morgenstein &admin_vlan_ix); 1583b01978caSJack Morgenstein if (err) { 15849caf83c3SDan Carpenter kfree(work); 1585b01978caSJack Morgenstein mlx4_warn((&priv->dev), 1586b01978caSJack Morgenstein "No vlan resources slave %d, port %d\n", 1587b01978caSJack Morgenstein slave, port); 1588b01978caSJack Morgenstein return err; 1589b01978caSJack Morgenstein } 1590f0f829bfSRony Efraim } else { 1591f0f829bfSRony Efraim admin_vlan_ix = NO_INDX; 1592f0f829bfSRony Efraim } 1593b01978caSJack Morgenstein work->flags |= MLX4_VF_IMMED_VLAN_FLAG_VLAN; 1594b01978caSJack Morgenstein mlx4_dbg((&(priv->dev)), 1595b01978caSJack Morgenstein "alloc vlan %d idx %d slave %d port %d\n", 1596b01978caSJack Morgenstein (int)(vp_admin->default_vlan), 1597b01978caSJack Morgenstein admin_vlan_ix, slave, port); 1598b01978caSJack Morgenstein } 1599b01978caSJack Morgenstein 1600b01978caSJack Morgenstein /* save original vlan ix and vlan id */ 1601b01978caSJack Morgenstein work->orig_vlan_id = vp_oper->state.default_vlan; 1602b01978caSJack Morgenstein work->orig_vlan_ix = vp_oper->vlan_idx; 1603b01978caSJack Morgenstein 1604b01978caSJack Morgenstein /* handle new qos */ 1605b01978caSJack Morgenstein if (vp_oper->state.default_qos != vp_admin->default_qos) 1606b01978caSJack Morgenstein work->flags |= MLX4_VF_IMMED_VLAN_FLAG_QOS; 1607b01978caSJack Morgenstein 1608b01978caSJack Morgenstein if (work->flags & MLX4_VF_IMMED_VLAN_FLAG_VLAN) 1609b01978caSJack Morgenstein vp_oper->vlan_idx = admin_vlan_ix; 1610b01978caSJack Morgenstein 1611b01978caSJack Morgenstein vp_oper->state.default_vlan = vp_admin->default_vlan; 1612b01978caSJack Morgenstein vp_oper->state.default_qos = vp_admin->default_qos; 16130a6eac24SRony Efraim vp_oper->state.link_state = vp_admin->link_state; 16140a6eac24SRony Efraim 16150a6eac24SRony Efraim if (vp_admin->link_state == IFLA_VF_LINK_STATE_DISABLE) 16160a6eac24SRony Efraim work->flags |= MLX4_VF_IMMED_VLAN_FLAG_LINK_DISABLE; 1617b01978caSJack Morgenstein 1618b01978caSJack Morgenstein /* iterate over QPs owned by this slave, using UPDATE_QP */ 1619b01978caSJack Morgenstein work->port = port; 1620b01978caSJack Morgenstein work->slave = slave; 1621b01978caSJack Morgenstein work->qos = vp_oper->state.default_qos; 1622b01978caSJack Morgenstein work->vlan_id = vp_oper->state.default_vlan; 1623b01978caSJack Morgenstein work->vlan_ix = vp_oper->vlan_idx; 1624b01978caSJack Morgenstein work->priv = priv; 1625b01978caSJack Morgenstein INIT_WORK(&work->work, mlx4_vf_immed_vlan_work_handler); 1626b01978caSJack Morgenstein queue_work(priv->mfunc.master.comm_wq, &work->work); 1627b01978caSJack Morgenstein 1628b01978caSJack Morgenstein return 0; 1629b01978caSJack Morgenstein } 1630b01978caSJack Morgenstein 1631b01978caSJack Morgenstein 16320eb62b93SRony Efraim static int mlx4_master_activate_admin_state(struct mlx4_priv *priv, int slave) 16330eb62b93SRony Efraim { 16343f7fb021SRony Efraim int port, err; 16353f7fb021SRony Efraim struct mlx4_vport_state *vp_admin; 16363f7fb021SRony Efraim struct mlx4_vport_oper_state *vp_oper; 1637449fc488SMatan Barak struct mlx4_active_ports actv_ports = mlx4_get_active_ports( 1638449fc488SMatan Barak &priv->dev, slave); 1639449fc488SMatan Barak int min_port = find_first_bit(actv_ports.ports, 1640449fc488SMatan Barak priv->dev.caps.num_ports) + 1; 1641449fc488SMatan Barak int max_port = min_port - 1 + 1642449fc488SMatan Barak bitmap_weight(actv_ports.ports, priv->dev.caps.num_ports); 16433f7fb021SRony Efraim 1644449fc488SMatan Barak for (port = min_port; port <= max_port; port++) { 1645449fc488SMatan Barak if (!test_bit(port - 1, actv_ports.ports)) 1646449fc488SMatan Barak continue; 16473f7fb021SRony Efraim vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port]; 16483f7fb021SRony Efraim vp_admin = &priv->mfunc.master.vf_admin[slave].vport[port]; 16493f7fb021SRony Efraim vp_oper->state = *vp_admin; 16503f7fb021SRony Efraim if (MLX4_VGT != vp_admin->default_vlan) { 16513f7fb021SRony Efraim err = __mlx4_register_vlan(&priv->dev, port, 16523f7fb021SRony Efraim vp_admin->default_vlan, &(vp_oper->vlan_idx)); 16533f7fb021SRony Efraim if (err) { 16543f7fb021SRony Efraim vp_oper->vlan_idx = NO_INDX; 16553f7fb021SRony Efraim mlx4_warn((&priv->dev), 16563f7fb021SRony Efraim "No vlan resorces slave %d, port %d\n", 16573f7fb021SRony Efraim slave, port); 16583f7fb021SRony Efraim return err; 16593f7fb021SRony Efraim } 16603f7fb021SRony Efraim mlx4_dbg((&(priv->dev)), "alloc vlan %d idx %d slave %d port %d\n", 16613f7fb021SRony Efraim (int)(vp_oper->state.default_vlan), 16623f7fb021SRony Efraim vp_oper->vlan_idx, slave, port); 16633f7fb021SRony Efraim } 1664e6b6a231SRony Efraim if (vp_admin->spoofchk) { 1665e6b6a231SRony Efraim vp_oper->mac_idx = __mlx4_register_mac(&priv->dev, 1666e6b6a231SRony Efraim port, 1667e6b6a231SRony Efraim vp_admin->mac); 1668e6b6a231SRony Efraim if (0 > vp_oper->mac_idx) { 1669e6b6a231SRony Efraim err = vp_oper->mac_idx; 1670e6b6a231SRony Efraim vp_oper->mac_idx = NO_INDX; 1671e6b6a231SRony Efraim mlx4_warn((&priv->dev), 1672e6b6a231SRony Efraim "No mac resorces slave %d, port %d\n", 1673e6b6a231SRony Efraim slave, port); 1674e6b6a231SRony Efraim return err; 1675e6b6a231SRony Efraim } 1676e6b6a231SRony Efraim mlx4_dbg((&(priv->dev)), "alloc mac %llx idx %d slave %d port %d\n", 1677e6b6a231SRony Efraim vp_oper->state.mac, vp_oper->mac_idx, slave, port); 1678e6b6a231SRony Efraim } 16790eb62b93SRony Efraim } 16800eb62b93SRony Efraim return 0; 16810eb62b93SRony Efraim } 16820eb62b93SRony Efraim 16833f7fb021SRony Efraim static void mlx4_master_deactivate_admin_state(struct mlx4_priv *priv, int slave) 16843f7fb021SRony Efraim { 16853f7fb021SRony Efraim int port; 16863f7fb021SRony Efraim struct mlx4_vport_oper_state *vp_oper; 1687449fc488SMatan Barak struct mlx4_active_ports actv_ports = mlx4_get_active_ports( 1688449fc488SMatan Barak &priv->dev, slave); 1689449fc488SMatan Barak int min_port = find_first_bit(actv_ports.ports, 1690449fc488SMatan Barak priv->dev.caps.num_ports) + 1; 1691449fc488SMatan Barak int max_port = min_port - 1 + 1692449fc488SMatan Barak bitmap_weight(actv_ports.ports, priv->dev.caps.num_ports); 16933f7fb021SRony Efraim 1694449fc488SMatan Barak 1695449fc488SMatan Barak for (port = min_port; port <= max_port; port++) { 1696449fc488SMatan Barak if (!test_bit(port - 1, actv_ports.ports)) 1697449fc488SMatan Barak continue; 16983f7fb021SRony Efraim vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port]; 16993f7fb021SRony Efraim if (NO_INDX != vp_oper->vlan_idx) { 17003f7fb021SRony Efraim __mlx4_unregister_vlan(&priv->dev, 17012009d005SJack Morgenstein port, vp_oper->state.default_vlan); 17023f7fb021SRony Efraim vp_oper->vlan_idx = NO_INDX; 17033f7fb021SRony Efraim } 1704e6b6a231SRony Efraim if (NO_INDX != vp_oper->mac_idx) { 1705c32b7dfbSJack Morgenstein __mlx4_unregister_mac(&priv->dev, port, vp_oper->state.mac); 1706e6b6a231SRony Efraim vp_oper->mac_idx = NO_INDX; 1707e6b6a231SRony Efraim } 17083f7fb021SRony Efraim } 17093f7fb021SRony Efraim return; 17103f7fb021SRony Efraim } 17113f7fb021SRony Efraim 1712e8f081aaSYevgeny Petrilin static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd, 1713e8f081aaSYevgeny Petrilin u16 param, u8 toggle) 1714e8f081aaSYevgeny Petrilin { 1715e8f081aaSYevgeny Petrilin struct mlx4_priv *priv = mlx4_priv(dev); 1716e8f081aaSYevgeny Petrilin struct mlx4_slave_state *slave_state = priv->mfunc.master.slave_state; 1717e8f081aaSYevgeny Petrilin u32 reply; 1718e8f081aaSYevgeny Petrilin u8 is_going_down = 0; 1719803143fbSMarcel Apfelbaum int i; 1720311f813aSJack Morgenstein unsigned long flags; 1721e8f081aaSYevgeny Petrilin 1722e8f081aaSYevgeny Petrilin slave_state[slave].comm_toggle ^= 1; 1723e8f081aaSYevgeny Petrilin reply = (u32) slave_state[slave].comm_toggle << 31; 1724e8f081aaSYevgeny Petrilin if (toggle != slave_state[slave].comm_toggle) { 1725e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Incorrect toggle %d from slave %d. *** MASTER" 1726e8f081aaSYevgeny Petrilin "STATE COMPROMISIED ***\n", toggle, slave); 1727e8f081aaSYevgeny Petrilin goto reset_slave; 1728e8f081aaSYevgeny Petrilin } 1729e8f081aaSYevgeny Petrilin if (cmd == MLX4_COMM_CMD_RESET) { 1730e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Received reset from slave:%d\n", slave); 1731e8f081aaSYevgeny Petrilin slave_state[slave].active = false; 17322c957ff2SJack Morgenstein slave_state[slave].old_vlan_api = false; 17333f7fb021SRony Efraim mlx4_master_deactivate_admin_state(priv, slave); 1734803143fbSMarcel Apfelbaum for (i = 0; i < MLX4_EVENT_TYPES_NUM; ++i) { 1735803143fbSMarcel Apfelbaum slave_state[slave].event_eq[i].eqn = -1; 1736803143fbSMarcel Apfelbaum slave_state[slave].event_eq[i].token = 0; 1737803143fbSMarcel Apfelbaum } 1738e8f081aaSYevgeny Petrilin /*check if we are in the middle of FLR process, 1739e8f081aaSYevgeny Petrilin if so return "retry" status to the slave*/ 1740162344edSOr Gerlitz if (MLX4_COMM_CMD_FLR == slave_state[slave].last_cmd) 1741e8f081aaSYevgeny Petrilin goto inform_slave_state; 1742e8f081aaSYevgeny Petrilin 1743fc06573dSJack Morgenstein mlx4_dispatch_event(dev, MLX4_DEV_EVENT_SLAVE_SHUTDOWN, slave); 1744fc06573dSJack Morgenstein 1745e8f081aaSYevgeny Petrilin /* write the version in the event field */ 1746e8f081aaSYevgeny Petrilin reply |= mlx4_comm_get_version(); 1747e8f081aaSYevgeny Petrilin 1748e8f081aaSYevgeny Petrilin goto reset_slave; 1749e8f081aaSYevgeny Petrilin } 1750e8f081aaSYevgeny Petrilin /*command from slave in the middle of FLR*/ 1751e8f081aaSYevgeny Petrilin if (cmd != MLX4_COMM_CMD_RESET && 1752e8f081aaSYevgeny Petrilin MLX4_COMM_CMD_FLR == slave_state[slave].last_cmd) { 1753e8f081aaSYevgeny Petrilin mlx4_warn(dev, "slave:%d is Trying to run cmd(0x%x) " 1754e8f081aaSYevgeny Petrilin "in the middle of FLR\n", slave, cmd); 1755e8f081aaSYevgeny Petrilin return; 1756e8f081aaSYevgeny Petrilin } 1757e8f081aaSYevgeny Petrilin 1758e8f081aaSYevgeny Petrilin switch (cmd) { 1759e8f081aaSYevgeny Petrilin case MLX4_COMM_CMD_VHCR0: 1760e8f081aaSYevgeny Petrilin if (slave_state[slave].last_cmd != MLX4_COMM_CMD_RESET) 1761e8f081aaSYevgeny Petrilin goto reset_slave; 1762e8f081aaSYevgeny Petrilin slave_state[slave].vhcr_dma = ((u64) param) << 48; 1763e8f081aaSYevgeny Petrilin priv->mfunc.master.slave_state[slave].cookie = 0; 1764e8f081aaSYevgeny Petrilin mutex_init(&priv->mfunc.master.gen_eqe_mutex[slave]); 1765e8f081aaSYevgeny Petrilin break; 1766e8f081aaSYevgeny Petrilin case MLX4_COMM_CMD_VHCR1: 1767e8f081aaSYevgeny Petrilin if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR0) 1768e8f081aaSYevgeny Petrilin goto reset_slave; 1769e8f081aaSYevgeny Petrilin slave_state[slave].vhcr_dma |= ((u64) param) << 32; 1770e8f081aaSYevgeny Petrilin break; 1771e8f081aaSYevgeny Petrilin case MLX4_COMM_CMD_VHCR2: 1772e8f081aaSYevgeny Petrilin if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR1) 1773e8f081aaSYevgeny Petrilin goto reset_slave; 1774e8f081aaSYevgeny Petrilin slave_state[slave].vhcr_dma |= ((u64) param) << 16; 1775e8f081aaSYevgeny Petrilin break; 1776e8f081aaSYevgeny Petrilin case MLX4_COMM_CMD_VHCR_EN: 1777e8f081aaSYevgeny Petrilin if (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR2) 1778e8f081aaSYevgeny Petrilin goto reset_slave; 1779e8f081aaSYevgeny Petrilin slave_state[slave].vhcr_dma |= param; 17803f7fb021SRony Efraim if (mlx4_master_activate_admin_state(priv, slave)) 17813f7fb021SRony Efraim goto reset_slave; 1782e8f081aaSYevgeny Petrilin slave_state[slave].active = true; 1783fc06573dSJack Morgenstein mlx4_dispatch_event(dev, MLX4_DEV_EVENT_SLAVE_INIT, slave); 1784e8f081aaSYevgeny Petrilin break; 1785e8f081aaSYevgeny Petrilin case MLX4_COMM_CMD_VHCR_POST: 1786e8f081aaSYevgeny Petrilin if ((slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR_EN) && 1787e8f081aaSYevgeny Petrilin (slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR_POST)) 1788e8f081aaSYevgeny Petrilin goto reset_slave; 1789f3d4c89eSRoland Dreier 1790f3d4c89eSRoland Dreier mutex_lock(&priv->cmd.slave_cmd_mutex); 1791e8f081aaSYevgeny Petrilin if (mlx4_master_process_vhcr(dev, slave, NULL)) { 1792e8f081aaSYevgeny Petrilin mlx4_err(dev, "Failed processing vhcr for slave:%d," 17938d9eb069SMasanari Iida " resetting slave.\n", slave); 1794f3d4c89eSRoland Dreier mutex_unlock(&priv->cmd.slave_cmd_mutex); 1795e8f081aaSYevgeny Petrilin goto reset_slave; 1796e8f081aaSYevgeny Petrilin } 1797f3d4c89eSRoland Dreier mutex_unlock(&priv->cmd.slave_cmd_mutex); 1798e8f081aaSYevgeny Petrilin break; 1799e8f081aaSYevgeny Petrilin default: 1800e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Bad comm cmd:%d from slave:%d\n", cmd, slave); 1801e8f081aaSYevgeny Petrilin goto reset_slave; 1802e8f081aaSYevgeny Petrilin } 1803311f813aSJack Morgenstein spin_lock_irqsave(&priv->mfunc.master.slave_state_lock, flags); 1804e8f081aaSYevgeny Petrilin if (!slave_state[slave].is_slave_going_down) 1805e8f081aaSYevgeny Petrilin slave_state[slave].last_cmd = cmd; 1806e8f081aaSYevgeny Petrilin else 1807e8f081aaSYevgeny Petrilin is_going_down = 1; 1808311f813aSJack Morgenstein spin_unlock_irqrestore(&priv->mfunc.master.slave_state_lock, flags); 1809e8f081aaSYevgeny Petrilin if (is_going_down) { 1810e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Slave is going down aborting command(%d)" 1811e8f081aaSYevgeny Petrilin " executing from slave:%d\n", 1812e8f081aaSYevgeny Petrilin cmd, slave); 1813e8f081aaSYevgeny Petrilin return; 1814e8f081aaSYevgeny Petrilin } 1815e8f081aaSYevgeny Petrilin __raw_writel((__force u32) cpu_to_be32(reply), 1816e8f081aaSYevgeny Petrilin &priv->mfunc.comm[slave].slave_read); 1817e8f081aaSYevgeny Petrilin mmiowb(); 1818e8f081aaSYevgeny Petrilin 1819e8f081aaSYevgeny Petrilin return; 1820e8f081aaSYevgeny Petrilin 1821e8f081aaSYevgeny Petrilin reset_slave: 1822c82e9aa0SEli Cohen /* cleanup any slave resources */ 1823c82e9aa0SEli Cohen mlx4_delete_all_resources_for_slave(dev, slave); 1824311f813aSJack Morgenstein spin_lock_irqsave(&priv->mfunc.master.slave_state_lock, flags); 1825e8f081aaSYevgeny Petrilin if (!slave_state[slave].is_slave_going_down) 1826e8f081aaSYevgeny Petrilin slave_state[slave].last_cmd = MLX4_COMM_CMD_RESET; 1827311f813aSJack Morgenstein spin_unlock_irqrestore(&priv->mfunc.master.slave_state_lock, flags); 1828e8f081aaSYevgeny Petrilin /*with slave in the middle of flr, no need to clean resources again.*/ 1829e8f081aaSYevgeny Petrilin inform_slave_state: 1830e8f081aaSYevgeny Petrilin memset(&slave_state[slave].event_eq, 0, 1831e8f081aaSYevgeny Petrilin sizeof(struct mlx4_slave_event_eq_info)); 1832e8f081aaSYevgeny Petrilin __raw_writel((__force u32) cpu_to_be32(reply), 1833e8f081aaSYevgeny Petrilin &priv->mfunc.comm[slave].slave_read); 1834e8f081aaSYevgeny Petrilin wmb(); 1835e8f081aaSYevgeny Petrilin } 1836e8f081aaSYevgeny Petrilin 1837e8f081aaSYevgeny Petrilin /* master command processing */ 1838e8f081aaSYevgeny Petrilin void mlx4_master_comm_channel(struct work_struct *work) 1839e8f081aaSYevgeny Petrilin { 1840e8f081aaSYevgeny Petrilin struct mlx4_mfunc_master_ctx *master = 1841e8f081aaSYevgeny Petrilin container_of(work, 1842e8f081aaSYevgeny Petrilin struct mlx4_mfunc_master_ctx, 1843e8f081aaSYevgeny Petrilin comm_work); 1844e8f081aaSYevgeny Petrilin struct mlx4_mfunc *mfunc = 1845e8f081aaSYevgeny Petrilin container_of(master, struct mlx4_mfunc, master); 1846e8f081aaSYevgeny Petrilin struct mlx4_priv *priv = 1847e8f081aaSYevgeny Petrilin container_of(mfunc, struct mlx4_priv, mfunc); 1848e8f081aaSYevgeny Petrilin struct mlx4_dev *dev = &priv->dev; 1849e8f081aaSYevgeny Petrilin __be32 *bit_vec; 1850e8f081aaSYevgeny Petrilin u32 comm_cmd; 1851e8f081aaSYevgeny Petrilin u32 vec; 1852e8f081aaSYevgeny Petrilin int i, j, slave; 1853e8f081aaSYevgeny Petrilin int toggle; 1854e8f081aaSYevgeny Petrilin int served = 0; 1855e8f081aaSYevgeny Petrilin int reported = 0; 1856e8f081aaSYevgeny Petrilin u32 slt; 1857e8f081aaSYevgeny Petrilin 1858e8f081aaSYevgeny Petrilin bit_vec = master->comm_arm_bit_vector; 1859e8f081aaSYevgeny Petrilin for (i = 0; i < COMM_CHANNEL_BIT_ARRAY_SIZE; i++) { 1860e8f081aaSYevgeny Petrilin vec = be32_to_cpu(bit_vec[i]); 1861e8f081aaSYevgeny Petrilin for (j = 0; j < 32; j++) { 1862e8f081aaSYevgeny Petrilin if (!(vec & (1 << j))) 1863e8f081aaSYevgeny Petrilin continue; 1864e8f081aaSYevgeny Petrilin ++reported; 1865e8f081aaSYevgeny Petrilin slave = (i * 32) + j; 1866e8f081aaSYevgeny Petrilin comm_cmd = swab32(readl( 1867e8f081aaSYevgeny Petrilin &mfunc->comm[slave].slave_write)); 1868e8f081aaSYevgeny Petrilin slt = swab32(readl(&mfunc->comm[slave].slave_read)) 1869e8f081aaSYevgeny Petrilin >> 31; 1870e8f081aaSYevgeny Petrilin toggle = comm_cmd >> 31; 1871e8f081aaSYevgeny Petrilin if (toggle != slt) { 1872e8f081aaSYevgeny Petrilin if (master->slave_state[slave].comm_toggle 1873e8f081aaSYevgeny Petrilin != slt) { 1874e8f081aaSYevgeny Petrilin printk(KERN_INFO "slave %d out of sync." 1875e8f081aaSYevgeny Petrilin " read toggle %d, state toggle %d. " 1876e8f081aaSYevgeny Petrilin "Resynching.\n", slave, slt, 1877e8f081aaSYevgeny Petrilin master->slave_state[slave].comm_toggle); 1878e8f081aaSYevgeny Petrilin master->slave_state[slave].comm_toggle = 1879e8f081aaSYevgeny Petrilin slt; 1880e8f081aaSYevgeny Petrilin } 1881e8f081aaSYevgeny Petrilin mlx4_master_do_cmd(dev, slave, 1882e8f081aaSYevgeny Petrilin comm_cmd >> 16 & 0xff, 1883e8f081aaSYevgeny Petrilin comm_cmd & 0xffff, toggle); 1884e8f081aaSYevgeny Petrilin ++served; 1885e8f081aaSYevgeny Petrilin } 1886e8f081aaSYevgeny Petrilin } 1887e8f081aaSYevgeny Petrilin } 1888e8f081aaSYevgeny Petrilin 1889e8f081aaSYevgeny Petrilin if (reported && reported != served) 1890e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Got command event with bitmask from %d slaves" 1891e8f081aaSYevgeny Petrilin " but %d were served\n", 1892e8f081aaSYevgeny Petrilin reported, served); 1893e8f081aaSYevgeny Petrilin 1894e8f081aaSYevgeny Petrilin if (mlx4_ARM_COMM_CHANNEL(dev)) 1895e8f081aaSYevgeny Petrilin mlx4_warn(dev, "Failed to arm comm channel events\n"); 1896e8f081aaSYevgeny Petrilin } 1897e8f081aaSYevgeny Petrilin 1898ab9c17a0SJack Morgenstein static int sync_toggles(struct mlx4_dev *dev) 1899ab9c17a0SJack Morgenstein { 1900ab9c17a0SJack Morgenstein struct mlx4_priv *priv = mlx4_priv(dev); 1901ab9c17a0SJack Morgenstein int wr_toggle; 1902ab9c17a0SJack Morgenstein int rd_toggle; 1903ab9c17a0SJack Morgenstein unsigned long end; 1904ab9c17a0SJack Morgenstein 1905ab9c17a0SJack Morgenstein wr_toggle = swab32(readl(&priv->mfunc.comm->slave_write)) >> 31; 1906ab9c17a0SJack Morgenstein end = jiffies + msecs_to_jiffies(5000); 1907ab9c17a0SJack Morgenstein 1908ab9c17a0SJack Morgenstein while (time_before(jiffies, end)) { 1909ab9c17a0SJack Morgenstein rd_toggle = swab32(readl(&priv->mfunc.comm->slave_read)) >> 31; 1910ab9c17a0SJack Morgenstein if (rd_toggle == wr_toggle) { 1911ab9c17a0SJack Morgenstein priv->cmd.comm_toggle = rd_toggle; 1912ab9c17a0SJack Morgenstein return 0; 1913ab9c17a0SJack Morgenstein } 1914ab9c17a0SJack Morgenstein 1915ab9c17a0SJack Morgenstein cond_resched(); 1916ab9c17a0SJack Morgenstein } 1917ab9c17a0SJack Morgenstein 1918ab9c17a0SJack Morgenstein /* 1919ab9c17a0SJack Morgenstein * we could reach here if for example the previous VM using this 1920ab9c17a0SJack Morgenstein * function misbehaved and left the channel with unsynced state. We 1921ab9c17a0SJack Morgenstein * should fix this here and give this VM a chance to use a properly 1922ab9c17a0SJack Morgenstein * synced channel 1923ab9c17a0SJack Morgenstein */ 1924ab9c17a0SJack Morgenstein mlx4_warn(dev, "recovering from previously mis-behaved VM\n"); 1925ab9c17a0SJack Morgenstein __raw_writel((__force u32) 0, &priv->mfunc.comm->slave_read); 1926ab9c17a0SJack Morgenstein __raw_writel((__force u32) 0, &priv->mfunc.comm->slave_write); 1927ab9c17a0SJack Morgenstein priv->cmd.comm_toggle = 0; 1928ab9c17a0SJack Morgenstein 1929ab9c17a0SJack Morgenstein return 0; 1930ab9c17a0SJack Morgenstein } 1931ab9c17a0SJack Morgenstein 1932ab9c17a0SJack Morgenstein int mlx4_multi_func_init(struct mlx4_dev *dev) 1933ab9c17a0SJack Morgenstein { 1934ab9c17a0SJack Morgenstein struct mlx4_priv *priv = mlx4_priv(dev); 1935ab9c17a0SJack Morgenstein struct mlx4_slave_state *s_state; 1936803143fbSMarcel Apfelbaum int i, j, err, port; 1937ab9c17a0SJack Morgenstein 1938ab9c17a0SJack Morgenstein if (mlx4_is_master(dev)) 1939ab9c17a0SJack Morgenstein priv->mfunc.comm = 1940ab9c17a0SJack Morgenstein ioremap(pci_resource_start(dev->pdev, priv->fw.comm_bar) + 1941ab9c17a0SJack Morgenstein priv->fw.comm_base, MLX4_COMM_PAGESIZE); 1942ab9c17a0SJack Morgenstein else 1943ab9c17a0SJack Morgenstein priv->mfunc.comm = 1944ab9c17a0SJack Morgenstein ioremap(pci_resource_start(dev->pdev, 2) + 1945ab9c17a0SJack Morgenstein MLX4_SLAVE_COMM_BASE, MLX4_COMM_PAGESIZE); 1946ab9c17a0SJack Morgenstein if (!priv->mfunc.comm) { 1947ab9c17a0SJack Morgenstein mlx4_err(dev, "Couldn't map communication vector.\n"); 1948ab9c17a0SJack Morgenstein goto err_vhcr; 1949ab9c17a0SJack Morgenstein } 1950ab9c17a0SJack Morgenstein 1951ab9c17a0SJack Morgenstein if (mlx4_is_master(dev)) { 1952ab9c17a0SJack Morgenstein priv->mfunc.master.slave_state = 1953ab9c17a0SJack Morgenstein kzalloc(dev->num_slaves * 1954ab9c17a0SJack Morgenstein sizeof(struct mlx4_slave_state), GFP_KERNEL); 1955ab9c17a0SJack Morgenstein if (!priv->mfunc.master.slave_state) 1956ab9c17a0SJack Morgenstein goto err_comm; 1957ab9c17a0SJack Morgenstein 19580eb62b93SRony Efraim priv->mfunc.master.vf_admin = 19590eb62b93SRony Efraim kzalloc(dev->num_slaves * 19600eb62b93SRony Efraim sizeof(struct mlx4_vf_admin_state), GFP_KERNEL); 19610eb62b93SRony Efraim if (!priv->mfunc.master.vf_admin) 19620eb62b93SRony Efraim goto err_comm_admin; 19630eb62b93SRony Efraim 19640eb62b93SRony Efraim priv->mfunc.master.vf_oper = 19650eb62b93SRony Efraim kzalloc(dev->num_slaves * 19660eb62b93SRony Efraim sizeof(struct mlx4_vf_oper_state), GFP_KERNEL); 19670eb62b93SRony Efraim if (!priv->mfunc.master.vf_oper) 19680eb62b93SRony Efraim goto err_comm_oper; 19690eb62b93SRony Efraim 1970ab9c17a0SJack Morgenstein for (i = 0; i < dev->num_slaves; ++i) { 1971ab9c17a0SJack Morgenstein s_state = &priv->mfunc.master.slave_state[i]; 1972ab9c17a0SJack Morgenstein s_state->last_cmd = MLX4_COMM_CMD_RESET; 1973803143fbSMarcel Apfelbaum for (j = 0; j < MLX4_EVENT_TYPES_NUM; ++j) 1974803143fbSMarcel Apfelbaum s_state->event_eq[j].eqn = -1; 1975ab9c17a0SJack Morgenstein __raw_writel((__force u32) 0, 1976ab9c17a0SJack Morgenstein &priv->mfunc.comm[i].slave_write); 1977ab9c17a0SJack Morgenstein __raw_writel((__force u32) 0, 1978ab9c17a0SJack Morgenstein &priv->mfunc.comm[i].slave_read); 1979ab9c17a0SJack Morgenstein mmiowb(); 1980ab9c17a0SJack Morgenstein for (port = 1; port <= MLX4_MAX_PORTS; port++) { 1981ab9c17a0SJack Morgenstein s_state->vlan_filter[port] = 1982ab9c17a0SJack Morgenstein kzalloc(sizeof(struct mlx4_vlan_fltr), 1983ab9c17a0SJack Morgenstein GFP_KERNEL); 1984ab9c17a0SJack Morgenstein if (!s_state->vlan_filter[port]) { 1985ab9c17a0SJack Morgenstein if (--port) 1986ab9c17a0SJack Morgenstein kfree(s_state->vlan_filter[port]); 1987ab9c17a0SJack Morgenstein goto err_slaves; 1988ab9c17a0SJack Morgenstein } 1989ab9c17a0SJack Morgenstein INIT_LIST_HEAD(&s_state->mcast_filters[port]); 19900eb62b93SRony Efraim priv->mfunc.master.vf_admin[i].vport[port].default_vlan = MLX4_VGT; 19913f7fb021SRony Efraim priv->mfunc.master.vf_oper[i].vport[port].state.default_vlan = MLX4_VGT; 19920eb62b93SRony Efraim priv->mfunc.master.vf_oper[i].vport[port].vlan_idx = NO_INDX; 19930eb62b93SRony Efraim priv->mfunc.master.vf_oper[i].vport[port].mac_idx = NO_INDX; 1994ab9c17a0SJack Morgenstein } 1995ab9c17a0SJack Morgenstein spin_lock_init(&s_state->lock); 1996ab9c17a0SJack Morgenstein } 1997ab9c17a0SJack Morgenstein 199808ff3235SOr Gerlitz memset(&priv->mfunc.master.cmd_eqe, 0, dev->caps.eqe_size); 1999ab9c17a0SJack Morgenstein priv->mfunc.master.cmd_eqe.type = MLX4_EVENT_TYPE_CMD; 2000ab9c17a0SJack Morgenstein INIT_WORK(&priv->mfunc.master.comm_work, 2001ab9c17a0SJack Morgenstein mlx4_master_comm_channel); 2002ab9c17a0SJack Morgenstein INIT_WORK(&priv->mfunc.master.slave_event_work, 2003ab9c17a0SJack Morgenstein mlx4_gen_slave_eqe); 2004ab9c17a0SJack Morgenstein INIT_WORK(&priv->mfunc.master.slave_flr_event_work, 2005ab9c17a0SJack Morgenstein mlx4_master_handle_slave_flr); 2006ab9c17a0SJack Morgenstein spin_lock_init(&priv->mfunc.master.slave_state_lock); 2007992e8e6eSJack Morgenstein spin_lock_init(&priv->mfunc.master.slave_eq.event_lock); 2008ab9c17a0SJack Morgenstein priv->mfunc.master.comm_wq = 2009ab9c17a0SJack Morgenstein create_singlethread_workqueue("mlx4_comm"); 2010ab9c17a0SJack Morgenstein if (!priv->mfunc.master.comm_wq) 2011ab9c17a0SJack Morgenstein goto err_slaves; 2012ab9c17a0SJack Morgenstein 2013ab9c17a0SJack Morgenstein if (mlx4_init_resource_tracker(dev)) 2014ab9c17a0SJack Morgenstein goto err_thread; 2015ab9c17a0SJack Morgenstein 2016ab9c17a0SJack Morgenstein err = mlx4_ARM_COMM_CHANNEL(dev); 2017ab9c17a0SJack Morgenstein if (err) { 2018ab9c17a0SJack Morgenstein mlx4_err(dev, " Failed to arm comm channel eq: %x\n", 2019ab9c17a0SJack Morgenstein err); 2020ab9c17a0SJack Morgenstein goto err_resource; 2021ab9c17a0SJack Morgenstein } 2022ab9c17a0SJack Morgenstein 2023ab9c17a0SJack Morgenstein } else { 2024ab9c17a0SJack Morgenstein err = sync_toggles(dev); 2025ab9c17a0SJack Morgenstein if (err) { 2026ab9c17a0SJack Morgenstein mlx4_err(dev, "Couldn't sync toggles\n"); 2027ab9c17a0SJack Morgenstein goto err_comm; 2028ab9c17a0SJack Morgenstein } 2029ab9c17a0SJack Morgenstein } 2030ab9c17a0SJack Morgenstein return 0; 2031ab9c17a0SJack Morgenstein 2032ab9c17a0SJack Morgenstein err_resource: 2033b8924951SJack Morgenstein mlx4_free_resource_tracker(dev, RES_TR_FREE_ALL); 2034ab9c17a0SJack Morgenstein err_thread: 2035ab9c17a0SJack Morgenstein flush_workqueue(priv->mfunc.master.comm_wq); 2036ab9c17a0SJack Morgenstein destroy_workqueue(priv->mfunc.master.comm_wq); 2037ab9c17a0SJack Morgenstein err_slaves: 2038ab9c17a0SJack Morgenstein while (--i) { 2039ab9c17a0SJack Morgenstein for (port = 1; port <= MLX4_MAX_PORTS; port++) 2040ab9c17a0SJack Morgenstein kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]); 2041ab9c17a0SJack Morgenstein } 20420eb62b93SRony Efraim kfree(priv->mfunc.master.vf_oper); 20430eb62b93SRony Efraim err_comm_oper: 20440eb62b93SRony Efraim kfree(priv->mfunc.master.vf_admin); 20450eb62b93SRony Efraim err_comm_admin: 2046ab9c17a0SJack Morgenstein kfree(priv->mfunc.master.slave_state); 2047ab9c17a0SJack Morgenstein err_comm: 2048ab9c17a0SJack Morgenstein iounmap(priv->mfunc.comm); 2049ab9c17a0SJack Morgenstein err_vhcr: 2050ab9c17a0SJack Morgenstein dma_free_coherent(&(dev->pdev->dev), PAGE_SIZE, 2051ab9c17a0SJack Morgenstein priv->mfunc.vhcr, 2052ab9c17a0SJack Morgenstein priv->mfunc.vhcr_dma); 2053ab9c17a0SJack Morgenstein priv->mfunc.vhcr = NULL; 2054ab9c17a0SJack Morgenstein return -ENOMEM; 2055ab9c17a0SJack Morgenstein } 2056ab9c17a0SJack Morgenstein 20575a2cc190SJeff Kirsher int mlx4_cmd_init(struct mlx4_dev *dev) 20585a2cc190SJeff Kirsher { 20595a2cc190SJeff Kirsher struct mlx4_priv *priv = mlx4_priv(dev); 20605a2cc190SJeff Kirsher 20615a2cc190SJeff Kirsher mutex_init(&priv->cmd.hcr_mutex); 2062f3d4c89eSRoland Dreier mutex_init(&priv->cmd.slave_cmd_mutex); 20635a2cc190SJeff Kirsher sema_init(&priv->cmd.poll_sem, 1); 20645a2cc190SJeff Kirsher priv->cmd.use_events = 0; 20655a2cc190SJeff Kirsher priv->cmd.toggle = 1; 20665a2cc190SJeff Kirsher 2067e8f081aaSYevgeny Petrilin priv->cmd.hcr = NULL; 2068e8f081aaSYevgeny Petrilin priv->mfunc.vhcr = NULL; 2069e8f081aaSYevgeny Petrilin 2070e8f081aaSYevgeny Petrilin if (!mlx4_is_slave(dev)) { 2071e8f081aaSYevgeny Petrilin priv->cmd.hcr = ioremap(pci_resource_start(dev->pdev, 0) + 2072e8f081aaSYevgeny Petrilin MLX4_HCR_BASE, MLX4_HCR_SIZE); 20735a2cc190SJeff Kirsher if (!priv->cmd.hcr) { 2074e8f081aaSYevgeny Petrilin mlx4_err(dev, "Couldn't map command register.\n"); 20755a2cc190SJeff Kirsher return -ENOMEM; 20765a2cc190SJeff Kirsher } 2077e8f081aaSYevgeny Petrilin } 20785a2cc190SJeff Kirsher 2079f3d4c89eSRoland Dreier if (mlx4_is_mfunc(dev)) { 2080f3d4c89eSRoland Dreier priv->mfunc.vhcr = dma_alloc_coherent(&(dev->pdev->dev), PAGE_SIZE, 2081f3d4c89eSRoland Dreier &priv->mfunc.vhcr_dma, 2082f3d4c89eSRoland Dreier GFP_KERNEL); 2083d0320f75SJoe Perches if (!priv->mfunc.vhcr) 2084f3d4c89eSRoland Dreier goto err_hcr; 2085f3d4c89eSRoland Dreier } 2086f3d4c89eSRoland Dreier 20875a2cc190SJeff Kirsher priv->cmd.pool = pci_pool_create("mlx4_cmd", dev->pdev, 20885a2cc190SJeff Kirsher MLX4_MAILBOX_SIZE, 20895a2cc190SJeff Kirsher MLX4_MAILBOX_SIZE, 0); 2090e8f081aaSYevgeny Petrilin if (!priv->cmd.pool) 2091f3d4c89eSRoland Dreier goto err_vhcr; 20925a2cc190SJeff Kirsher 20935a2cc190SJeff Kirsher return 0; 2094e8f081aaSYevgeny Petrilin 2095f3d4c89eSRoland Dreier err_vhcr: 2096f3d4c89eSRoland Dreier if (mlx4_is_mfunc(dev)) 2097f3d4c89eSRoland Dreier dma_free_coherent(&(dev->pdev->dev), PAGE_SIZE, 2098f3d4c89eSRoland Dreier priv->mfunc.vhcr, priv->mfunc.vhcr_dma); 2099f3d4c89eSRoland Dreier priv->mfunc.vhcr = NULL; 2100f3d4c89eSRoland Dreier 2101e8f081aaSYevgeny Petrilin err_hcr: 2102e8f081aaSYevgeny Petrilin if (!mlx4_is_slave(dev)) 2103e8f081aaSYevgeny Petrilin iounmap(priv->cmd.hcr); 2104e8f081aaSYevgeny Petrilin return -ENOMEM; 21055a2cc190SJeff Kirsher } 21065a2cc190SJeff Kirsher 2107ab9c17a0SJack Morgenstein void mlx4_multi_func_cleanup(struct mlx4_dev *dev) 2108ab9c17a0SJack Morgenstein { 2109ab9c17a0SJack Morgenstein struct mlx4_priv *priv = mlx4_priv(dev); 2110ab9c17a0SJack Morgenstein int i, port; 2111ab9c17a0SJack Morgenstein 2112ab9c17a0SJack Morgenstein if (mlx4_is_master(dev)) { 2113ab9c17a0SJack Morgenstein flush_workqueue(priv->mfunc.master.comm_wq); 2114ab9c17a0SJack Morgenstein destroy_workqueue(priv->mfunc.master.comm_wq); 2115ab9c17a0SJack Morgenstein for (i = 0; i < dev->num_slaves; i++) { 2116ab9c17a0SJack Morgenstein for (port = 1; port <= MLX4_MAX_PORTS; port++) 2117ab9c17a0SJack Morgenstein kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]); 2118ab9c17a0SJack Morgenstein } 2119ab9c17a0SJack Morgenstein kfree(priv->mfunc.master.slave_state); 21200eb62b93SRony Efraim kfree(priv->mfunc.master.vf_admin); 21210eb62b93SRony Efraim kfree(priv->mfunc.master.vf_oper); 2122f08ad06cSEugenia Emantayev } 2123f08ad06cSEugenia Emantayev 2124ab9c17a0SJack Morgenstein iounmap(priv->mfunc.comm); 2125ab9c17a0SJack Morgenstein } 2126ab9c17a0SJack Morgenstein 21275a2cc190SJeff Kirsher void mlx4_cmd_cleanup(struct mlx4_dev *dev) 21285a2cc190SJeff Kirsher { 21295a2cc190SJeff Kirsher struct mlx4_priv *priv = mlx4_priv(dev); 21305a2cc190SJeff Kirsher 21315a2cc190SJeff Kirsher pci_pool_destroy(priv->cmd.pool); 2132e8f081aaSYevgeny Petrilin 2133e8f081aaSYevgeny Petrilin if (!mlx4_is_slave(dev)) 21345a2cc190SJeff Kirsher iounmap(priv->cmd.hcr); 2135f3d4c89eSRoland Dreier if (mlx4_is_mfunc(dev)) 2136f3d4c89eSRoland Dreier dma_free_coherent(&(dev->pdev->dev), PAGE_SIZE, 2137f3d4c89eSRoland Dreier priv->mfunc.vhcr, priv->mfunc.vhcr_dma); 2138f3d4c89eSRoland Dreier priv->mfunc.vhcr = NULL; 21395a2cc190SJeff Kirsher } 21405a2cc190SJeff Kirsher 21415a2cc190SJeff Kirsher /* 21425a2cc190SJeff Kirsher * Switch to using events to issue FW commands (can only be called 21435a2cc190SJeff Kirsher * after event queue for command events has been initialized). 21445a2cc190SJeff Kirsher */ 21455a2cc190SJeff Kirsher int mlx4_cmd_use_events(struct mlx4_dev *dev) 21465a2cc190SJeff Kirsher { 21475a2cc190SJeff Kirsher struct mlx4_priv *priv = mlx4_priv(dev); 21485a2cc190SJeff Kirsher int i; 2149e8f081aaSYevgeny Petrilin int err = 0; 21505a2cc190SJeff Kirsher 21515a2cc190SJeff Kirsher priv->cmd.context = kmalloc(priv->cmd.max_cmds * 21525a2cc190SJeff Kirsher sizeof (struct mlx4_cmd_context), 21535a2cc190SJeff Kirsher GFP_KERNEL); 21545a2cc190SJeff Kirsher if (!priv->cmd.context) 21555a2cc190SJeff Kirsher return -ENOMEM; 21565a2cc190SJeff Kirsher 21575a2cc190SJeff Kirsher for (i = 0; i < priv->cmd.max_cmds; ++i) { 21585a2cc190SJeff Kirsher priv->cmd.context[i].token = i; 21595a2cc190SJeff Kirsher priv->cmd.context[i].next = i + 1; 21605a2cc190SJeff Kirsher } 21615a2cc190SJeff Kirsher 21625a2cc190SJeff Kirsher priv->cmd.context[priv->cmd.max_cmds - 1].next = -1; 21635a2cc190SJeff Kirsher priv->cmd.free_head = 0; 21645a2cc190SJeff Kirsher 21655a2cc190SJeff Kirsher sema_init(&priv->cmd.event_sem, priv->cmd.max_cmds); 21665a2cc190SJeff Kirsher spin_lock_init(&priv->cmd.context_lock); 21675a2cc190SJeff Kirsher 21685a2cc190SJeff Kirsher for (priv->cmd.token_mask = 1; 21695a2cc190SJeff Kirsher priv->cmd.token_mask < priv->cmd.max_cmds; 21705a2cc190SJeff Kirsher priv->cmd.token_mask <<= 1) 21715a2cc190SJeff Kirsher ; /* nothing */ 21725a2cc190SJeff Kirsher --priv->cmd.token_mask; 21735a2cc190SJeff Kirsher 2174e8f081aaSYevgeny Petrilin down(&priv->cmd.poll_sem); 21755a2cc190SJeff Kirsher priv->cmd.use_events = 1; 21765a2cc190SJeff Kirsher 2177e8f081aaSYevgeny Petrilin return err; 21785a2cc190SJeff Kirsher } 21795a2cc190SJeff Kirsher 21805a2cc190SJeff Kirsher /* 21815a2cc190SJeff Kirsher * Switch back to polling (used when shutting down the device) 21825a2cc190SJeff Kirsher */ 21835a2cc190SJeff Kirsher void mlx4_cmd_use_polling(struct mlx4_dev *dev) 21845a2cc190SJeff Kirsher { 21855a2cc190SJeff Kirsher struct mlx4_priv *priv = mlx4_priv(dev); 21865a2cc190SJeff Kirsher int i; 21875a2cc190SJeff Kirsher 21885a2cc190SJeff Kirsher priv->cmd.use_events = 0; 21895a2cc190SJeff Kirsher 21905a2cc190SJeff Kirsher for (i = 0; i < priv->cmd.max_cmds; ++i) 21915a2cc190SJeff Kirsher down(&priv->cmd.event_sem); 21925a2cc190SJeff Kirsher 21935a2cc190SJeff Kirsher kfree(priv->cmd.context); 21945a2cc190SJeff Kirsher 21955a2cc190SJeff Kirsher up(&priv->cmd.poll_sem); 21965a2cc190SJeff Kirsher } 21975a2cc190SJeff Kirsher 21985a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct mlx4_dev *dev) 21995a2cc190SJeff Kirsher { 22005a2cc190SJeff Kirsher struct mlx4_cmd_mailbox *mailbox; 22015a2cc190SJeff Kirsher 22025a2cc190SJeff Kirsher mailbox = kmalloc(sizeof *mailbox, GFP_KERNEL); 22035a2cc190SJeff Kirsher if (!mailbox) 22045a2cc190SJeff Kirsher return ERR_PTR(-ENOMEM); 22055a2cc190SJeff Kirsher 22065a2cc190SJeff Kirsher mailbox->buf = pci_pool_alloc(mlx4_priv(dev)->cmd.pool, GFP_KERNEL, 22075a2cc190SJeff Kirsher &mailbox->dma); 22085a2cc190SJeff Kirsher if (!mailbox->buf) { 22095a2cc190SJeff Kirsher kfree(mailbox); 22105a2cc190SJeff Kirsher return ERR_PTR(-ENOMEM); 22115a2cc190SJeff Kirsher } 22125a2cc190SJeff Kirsher 2213571b8b92SJack Morgenstein memset(mailbox->buf, 0, MLX4_MAILBOX_SIZE); 2214571b8b92SJack Morgenstein 22155a2cc190SJeff Kirsher return mailbox; 22165a2cc190SJeff Kirsher } 22175a2cc190SJeff Kirsher EXPORT_SYMBOL_GPL(mlx4_alloc_cmd_mailbox); 22185a2cc190SJeff Kirsher 2219e8f081aaSYevgeny Petrilin void mlx4_free_cmd_mailbox(struct mlx4_dev *dev, 2220e8f081aaSYevgeny Petrilin struct mlx4_cmd_mailbox *mailbox) 22215a2cc190SJeff Kirsher { 22225a2cc190SJeff Kirsher if (!mailbox) 22235a2cc190SJeff Kirsher return; 22245a2cc190SJeff Kirsher 22255a2cc190SJeff Kirsher pci_pool_free(mlx4_priv(dev)->cmd.pool, mailbox->buf, mailbox->dma); 22265a2cc190SJeff Kirsher kfree(mailbox); 22275a2cc190SJeff Kirsher } 22285a2cc190SJeff Kirsher EXPORT_SYMBOL_GPL(mlx4_free_cmd_mailbox); 2229e8f081aaSYevgeny Petrilin 2230e8f081aaSYevgeny Petrilin u32 mlx4_comm_get_version(void) 2231e8f081aaSYevgeny Petrilin { 2232e8f081aaSYevgeny Petrilin return ((u32) CMD_CHAN_IF_REV << 8) | (u32) CMD_CHAN_VER; 2233e8f081aaSYevgeny Petrilin } 22348f7ba3caSRony Efraim 22358f7ba3caSRony Efraim static int mlx4_get_slave_indx(struct mlx4_dev *dev, int vf) 22368f7ba3caSRony Efraim { 22378f7ba3caSRony Efraim if ((vf < 0) || (vf >= dev->num_vfs)) { 22388f7ba3caSRony Efraim mlx4_err(dev, "Bad vf number:%d (number of activated vf: %d)\n", vf, dev->num_vfs); 22398f7ba3caSRony Efraim return -EINVAL; 22408f7ba3caSRony Efraim } 22418f7ba3caSRony Efraim 22428f7ba3caSRony Efraim return vf+1; 22438f7ba3caSRony Efraim } 22448f7ba3caSRony Efraim 2245f74462acSMatan Barak int mlx4_get_vf_indx(struct mlx4_dev *dev, int slave) 2246f74462acSMatan Barak { 2247f74462acSMatan Barak if (slave < 1 || slave > dev->num_vfs) { 2248f74462acSMatan Barak mlx4_err(dev, 2249f74462acSMatan Barak "Bad slave number:%d (number of activated slaves: %lu)\n", 2250f74462acSMatan Barak slave, dev->num_slaves); 2251f74462acSMatan Barak return -EINVAL; 2252f74462acSMatan Barak } 2253f74462acSMatan Barak return slave - 1; 2254f74462acSMatan Barak } 2255f74462acSMatan Barak 2256f74462acSMatan Barak struct mlx4_active_ports mlx4_get_active_ports(struct mlx4_dev *dev, int slave) 2257f74462acSMatan Barak { 2258f74462acSMatan Barak struct mlx4_active_ports actv_ports; 2259f74462acSMatan Barak int vf; 2260f74462acSMatan Barak 2261f74462acSMatan Barak bitmap_zero(actv_ports.ports, MLX4_MAX_PORTS); 2262f74462acSMatan Barak 2263f74462acSMatan Barak if (slave == 0) { 2264f74462acSMatan Barak bitmap_fill(actv_ports.ports, dev->caps.num_ports); 2265f74462acSMatan Barak return actv_ports; 2266f74462acSMatan Barak } 2267f74462acSMatan Barak 2268f74462acSMatan Barak vf = mlx4_get_vf_indx(dev, slave); 2269f74462acSMatan Barak if (vf < 0) 2270f74462acSMatan Barak return actv_ports; 2271f74462acSMatan Barak 2272f74462acSMatan Barak bitmap_set(actv_ports.ports, dev->dev_vfs[vf].min_port - 1, 2273f74462acSMatan Barak min((int)dev->dev_vfs[mlx4_get_vf_indx(dev, slave)].n_ports, 2274f74462acSMatan Barak dev->caps.num_ports)); 2275f74462acSMatan Barak 2276f74462acSMatan Barak return actv_ports; 2277f74462acSMatan Barak } 2278f74462acSMatan Barak EXPORT_SYMBOL_GPL(mlx4_get_active_ports); 2279f74462acSMatan Barak 2280f74462acSMatan Barak int mlx4_slave_convert_port(struct mlx4_dev *dev, int slave, int port) 2281f74462acSMatan Barak { 2282f74462acSMatan Barak unsigned n; 2283f74462acSMatan Barak struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave); 2284f74462acSMatan Barak unsigned m = bitmap_weight(actv_ports.ports, dev->caps.num_ports); 2285f74462acSMatan Barak 2286f74462acSMatan Barak if (port <= 0 || port > m) 2287f74462acSMatan Barak return -EINVAL; 2288f74462acSMatan Barak 2289f74462acSMatan Barak n = find_first_bit(actv_ports.ports, dev->caps.num_ports); 2290f74462acSMatan Barak if (port <= n) 2291f74462acSMatan Barak port = n + 1; 2292f74462acSMatan Barak 2293f74462acSMatan Barak return port; 2294f74462acSMatan Barak } 2295f74462acSMatan Barak EXPORT_SYMBOL_GPL(mlx4_slave_convert_port); 2296f74462acSMatan Barak 2297f74462acSMatan Barak int mlx4_phys_to_slave_port(struct mlx4_dev *dev, int slave, int port) 2298f74462acSMatan Barak { 2299f74462acSMatan Barak struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave); 2300f74462acSMatan Barak if (test_bit(port - 1, actv_ports.ports)) 2301f74462acSMatan Barak return port - 2302f74462acSMatan Barak find_first_bit(actv_ports.ports, dev->caps.num_ports); 2303f74462acSMatan Barak 2304f74462acSMatan Barak return -1; 2305f74462acSMatan Barak } 2306f74462acSMatan Barak EXPORT_SYMBOL_GPL(mlx4_phys_to_slave_port); 2307f74462acSMatan Barak 2308f74462acSMatan Barak struct mlx4_slaves_pport mlx4_phys_to_slaves_pport(struct mlx4_dev *dev, 2309f74462acSMatan Barak int port) 2310f74462acSMatan Barak { 2311f74462acSMatan Barak unsigned i; 2312f74462acSMatan Barak struct mlx4_slaves_pport slaves_pport; 2313f74462acSMatan Barak 2314f74462acSMatan Barak bitmap_zero(slaves_pport.slaves, MLX4_MFUNC_MAX); 2315f74462acSMatan Barak 2316f74462acSMatan Barak if (port <= 0 || port > dev->caps.num_ports) 2317f74462acSMatan Barak return slaves_pport; 2318f74462acSMatan Barak 2319f74462acSMatan Barak for (i = 0; i < dev->num_vfs + 1; i++) { 2320f74462acSMatan Barak struct mlx4_active_ports actv_ports = 2321f74462acSMatan Barak mlx4_get_active_ports(dev, i); 2322f74462acSMatan Barak if (test_bit(port - 1, actv_ports.ports)) 2323f74462acSMatan Barak set_bit(i, slaves_pport.slaves); 2324f74462acSMatan Barak } 2325f74462acSMatan Barak 2326f74462acSMatan Barak return slaves_pport; 2327f74462acSMatan Barak } 2328f74462acSMatan Barak EXPORT_SYMBOL_GPL(mlx4_phys_to_slaves_pport); 2329f74462acSMatan Barak 2330f74462acSMatan Barak struct mlx4_slaves_pport mlx4_phys_to_slaves_pport_actv( 2331f74462acSMatan Barak struct mlx4_dev *dev, 2332f74462acSMatan Barak const struct mlx4_active_ports *crit_ports) 2333f74462acSMatan Barak { 2334f74462acSMatan Barak unsigned i; 2335f74462acSMatan Barak struct mlx4_slaves_pport slaves_pport; 2336f74462acSMatan Barak 2337f74462acSMatan Barak bitmap_zero(slaves_pport.slaves, MLX4_MFUNC_MAX); 2338f74462acSMatan Barak 2339f74462acSMatan Barak for (i = 0; i < dev->num_vfs + 1; i++) { 2340f74462acSMatan Barak struct mlx4_active_ports actv_ports = 2341f74462acSMatan Barak mlx4_get_active_ports(dev, i); 2342f74462acSMatan Barak if (bitmap_equal(crit_ports->ports, actv_ports.ports, 2343f74462acSMatan Barak dev->caps.num_ports)) 2344f74462acSMatan Barak set_bit(i, slaves_pport.slaves); 2345f74462acSMatan Barak } 2346f74462acSMatan Barak 2347f74462acSMatan Barak return slaves_pport; 2348f74462acSMatan Barak } 2349f74462acSMatan Barak EXPORT_SYMBOL_GPL(mlx4_phys_to_slaves_pport_actv); 2350f74462acSMatan Barak 23518f7ba3caSRony Efraim int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u64 mac) 23528f7ba3caSRony Efraim { 23538f7ba3caSRony Efraim struct mlx4_priv *priv = mlx4_priv(dev); 23548f7ba3caSRony Efraim struct mlx4_vport_state *s_info; 23558f7ba3caSRony Efraim int slave; 23568f7ba3caSRony Efraim 23578f7ba3caSRony Efraim if (!mlx4_is_master(dev)) 23588f7ba3caSRony Efraim return -EPROTONOSUPPORT; 23598f7ba3caSRony Efraim 23608f7ba3caSRony Efraim slave = mlx4_get_slave_indx(dev, vf); 23618f7ba3caSRony Efraim if (slave < 0) 23628f7ba3caSRony Efraim return -EINVAL; 23638f7ba3caSRony Efraim 23648f7ba3caSRony Efraim s_info = &priv->mfunc.master.vf_admin[slave].vport[port]; 23658f7ba3caSRony Efraim s_info->mac = mac; 23668f7ba3caSRony Efraim mlx4_info(dev, "default mac on vf %d port %d to %llX will take afect only after vf restart\n", 23678f7ba3caSRony Efraim vf, port, s_info->mac); 23688f7ba3caSRony Efraim return 0; 23698f7ba3caSRony Efraim } 23708f7ba3caSRony Efraim EXPORT_SYMBOL_GPL(mlx4_set_vf_mac); 23713f7fb021SRony Efraim 2372b01978caSJack Morgenstein 23733f7fb021SRony Efraim int mlx4_set_vf_vlan(struct mlx4_dev *dev, int port, int vf, u16 vlan, u8 qos) 23743f7fb021SRony Efraim { 23753f7fb021SRony Efraim struct mlx4_priv *priv = mlx4_priv(dev); 2376b01978caSJack Morgenstein struct mlx4_vport_state *vf_admin; 23773f7fb021SRony Efraim int slave; 23783f7fb021SRony Efraim 23793f7fb021SRony Efraim if ((!mlx4_is_master(dev)) || 23803f7fb021SRony Efraim !(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VLAN_CONTROL)) 23813f7fb021SRony Efraim return -EPROTONOSUPPORT; 23823f7fb021SRony Efraim 23833f7fb021SRony Efraim if ((vlan > 4095) || (qos > 7)) 23843f7fb021SRony Efraim return -EINVAL; 23853f7fb021SRony Efraim 23863f7fb021SRony Efraim slave = mlx4_get_slave_indx(dev, vf); 23873f7fb021SRony Efraim if (slave < 0) 23883f7fb021SRony Efraim return -EINVAL; 23893f7fb021SRony Efraim 2390b01978caSJack Morgenstein vf_admin = &priv->mfunc.master.vf_admin[slave].vport[port]; 2391b01978caSJack Morgenstein 23923f7fb021SRony Efraim if ((0 == vlan) && (0 == qos)) 2393b01978caSJack Morgenstein vf_admin->default_vlan = MLX4_VGT; 23943f7fb021SRony Efraim else 2395b01978caSJack Morgenstein vf_admin->default_vlan = vlan; 2396b01978caSJack Morgenstein vf_admin->default_qos = qos; 2397b01978caSJack Morgenstein 23980a6eac24SRony Efraim if (mlx4_master_immediate_activate_vlan_qos(priv, slave, port)) 23990a6eac24SRony Efraim mlx4_info(dev, 24000a6eac24SRony Efraim "updating vf %d port %d config will take effect on next VF restart\n", 2401b01978caSJack Morgenstein vf, port); 24023f7fb021SRony Efraim return 0; 24033f7fb021SRony Efraim } 24043f7fb021SRony Efraim EXPORT_SYMBOL_GPL(mlx4_set_vf_vlan); 2405e6b6a231SRony Efraim 24065ea8bbfcSJack Morgenstein /* mlx4_get_slave_default_vlan - 24075ea8bbfcSJack Morgenstein * return true if VST ( default vlan) 24085ea8bbfcSJack Morgenstein * if VST, will return vlan & qos (if not NULL) 24095ea8bbfcSJack Morgenstein */ 24105ea8bbfcSJack Morgenstein bool mlx4_get_slave_default_vlan(struct mlx4_dev *dev, int port, int slave, 24115ea8bbfcSJack Morgenstein u16 *vlan, u8 *qos) 24125ea8bbfcSJack Morgenstein { 24135ea8bbfcSJack Morgenstein struct mlx4_vport_oper_state *vp_oper; 24145ea8bbfcSJack Morgenstein struct mlx4_priv *priv; 24155ea8bbfcSJack Morgenstein 24165ea8bbfcSJack Morgenstein priv = mlx4_priv(dev); 24175ea8bbfcSJack Morgenstein vp_oper = &priv->mfunc.master.vf_oper[slave].vport[port]; 24185ea8bbfcSJack Morgenstein 24195ea8bbfcSJack Morgenstein if (MLX4_VGT != vp_oper->state.default_vlan) { 24205ea8bbfcSJack Morgenstein if (vlan) 24215ea8bbfcSJack Morgenstein *vlan = vp_oper->state.default_vlan; 24225ea8bbfcSJack Morgenstein if (qos) 24235ea8bbfcSJack Morgenstein *qos = vp_oper->state.default_qos; 24245ea8bbfcSJack Morgenstein return true; 24255ea8bbfcSJack Morgenstein } 24265ea8bbfcSJack Morgenstein return false; 24275ea8bbfcSJack Morgenstein } 24285ea8bbfcSJack Morgenstein EXPORT_SYMBOL_GPL(mlx4_get_slave_default_vlan); 24295ea8bbfcSJack Morgenstein 2430e6b6a231SRony Efraim int mlx4_set_vf_spoofchk(struct mlx4_dev *dev, int port, int vf, bool setting) 2431e6b6a231SRony Efraim { 2432e6b6a231SRony Efraim struct mlx4_priv *priv = mlx4_priv(dev); 2433e6b6a231SRony Efraim struct mlx4_vport_state *s_info; 2434e6b6a231SRony Efraim int slave; 2435e6b6a231SRony Efraim 2436e6b6a231SRony Efraim if ((!mlx4_is_master(dev)) || 2437e6b6a231SRony Efraim !(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FSM)) 2438e6b6a231SRony Efraim return -EPROTONOSUPPORT; 2439e6b6a231SRony Efraim 2440e6b6a231SRony Efraim slave = mlx4_get_slave_indx(dev, vf); 2441e6b6a231SRony Efraim if (slave < 0) 2442e6b6a231SRony Efraim return -EINVAL; 2443e6b6a231SRony Efraim 2444e6b6a231SRony Efraim s_info = &priv->mfunc.master.vf_admin[slave].vport[port]; 2445e6b6a231SRony Efraim s_info->spoofchk = setting; 2446e6b6a231SRony Efraim 2447e6b6a231SRony Efraim return 0; 2448e6b6a231SRony Efraim } 2449e6b6a231SRony Efraim EXPORT_SYMBOL_GPL(mlx4_set_vf_spoofchk); 24502cccb9e4SRony Efraim 24512cccb9e4SRony Efraim int mlx4_get_vf_config(struct mlx4_dev *dev, int port, int vf, struct ifla_vf_info *ivf) 24522cccb9e4SRony Efraim { 24532cccb9e4SRony Efraim struct mlx4_priv *priv = mlx4_priv(dev); 24542cccb9e4SRony Efraim struct mlx4_vport_state *s_info; 24552cccb9e4SRony Efraim int slave; 24562cccb9e4SRony Efraim 24572cccb9e4SRony Efraim if (!mlx4_is_master(dev)) 24582cccb9e4SRony Efraim return -EPROTONOSUPPORT; 24592cccb9e4SRony Efraim 24602cccb9e4SRony Efraim slave = mlx4_get_slave_indx(dev, vf); 24612cccb9e4SRony Efraim if (slave < 0) 24622cccb9e4SRony Efraim return -EINVAL; 24632cccb9e4SRony Efraim 24642cccb9e4SRony Efraim s_info = &priv->mfunc.master.vf_admin[slave].vport[port]; 24652cccb9e4SRony Efraim ivf->vf = vf; 24662cccb9e4SRony Efraim 24672cccb9e4SRony Efraim /* need to convert it to a func */ 24682cccb9e4SRony Efraim ivf->mac[0] = ((s_info->mac >> (5*8)) & 0xff); 24692cccb9e4SRony Efraim ivf->mac[1] = ((s_info->mac >> (4*8)) & 0xff); 24702cccb9e4SRony Efraim ivf->mac[2] = ((s_info->mac >> (3*8)) & 0xff); 24712cccb9e4SRony Efraim ivf->mac[3] = ((s_info->mac >> (2*8)) & 0xff); 24722cccb9e4SRony Efraim ivf->mac[4] = ((s_info->mac >> (1*8)) & 0xff); 24732cccb9e4SRony Efraim ivf->mac[5] = ((s_info->mac) & 0xff); 24742cccb9e4SRony Efraim 24752cccb9e4SRony Efraim ivf->vlan = s_info->default_vlan; 24762cccb9e4SRony Efraim ivf->qos = s_info->default_qos; 24772cccb9e4SRony Efraim ivf->tx_rate = s_info->tx_rate; 24782cccb9e4SRony Efraim ivf->spoofchk = s_info->spoofchk; 2479948e306dSRony Efraim ivf->linkstate = s_info->link_state; 24802cccb9e4SRony Efraim 24812cccb9e4SRony Efraim return 0; 24822cccb9e4SRony Efraim } 24832cccb9e4SRony Efraim EXPORT_SYMBOL_GPL(mlx4_get_vf_config); 2484948e306dSRony Efraim 2485948e306dSRony Efraim int mlx4_set_vf_link_state(struct mlx4_dev *dev, int port, int vf, int link_state) 2486948e306dSRony Efraim { 2487948e306dSRony Efraim struct mlx4_priv *priv = mlx4_priv(dev); 2488948e306dSRony Efraim struct mlx4_vport_state *s_info; 2489948e306dSRony Efraim int slave; 2490948e306dSRony Efraim u8 link_stat_event; 2491948e306dSRony Efraim 2492948e306dSRony Efraim slave = mlx4_get_slave_indx(dev, vf); 2493948e306dSRony Efraim if (slave < 0) 2494948e306dSRony Efraim return -EINVAL; 2495948e306dSRony Efraim 2496948e306dSRony Efraim switch (link_state) { 2497948e306dSRony Efraim case IFLA_VF_LINK_STATE_AUTO: 2498948e306dSRony Efraim /* get current link state */ 2499948e306dSRony Efraim if (!priv->sense.do_sense_port[port]) 2500948e306dSRony Efraim link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_ACTIVE; 2501948e306dSRony Efraim else 2502948e306dSRony Efraim link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_DOWN; 2503948e306dSRony Efraim break; 2504948e306dSRony Efraim 2505948e306dSRony Efraim case IFLA_VF_LINK_STATE_ENABLE: 2506948e306dSRony Efraim link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_ACTIVE; 2507948e306dSRony Efraim break; 2508948e306dSRony Efraim 2509948e306dSRony Efraim case IFLA_VF_LINK_STATE_DISABLE: 2510948e306dSRony Efraim link_stat_event = MLX4_PORT_CHANGE_SUBTYPE_DOWN; 2511948e306dSRony Efraim break; 2512948e306dSRony Efraim 2513948e306dSRony Efraim default: 2514948e306dSRony Efraim mlx4_warn(dev, "unknown value for link_state %02x on slave %d port %d\n", 2515948e306dSRony Efraim link_state, slave, port); 2516948e306dSRony Efraim return -EINVAL; 2517948e306dSRony Efraim }; 2518948e306dSRony Efraim s_info = &priv->mfunc.master.vf_admin[slave].vport[port]; 2519948e306dSRony Efraim s_info->link_state = link_state; 2520948e306dSRony Efraim 2521948e306dSRony Efraim /* send event */ 2522948e306dSRony Efraim mlx4_gen_port_state_change_eqe(dev, slave, port, link_stat_event); 25230a6eac24SRony Efraim 25240a6eac24SRony Efraim if (mlx4_master_immediate_activate_vlan_qos(priv, slave, port)) 25250a6eac24SRony Efraim mlx4_dbg(dev, 25260a6eac24SRony Efraim "updating vf %d port %d no link state HW enforcment\n", 25270a6eac24SRony Efraim vf, port); 2528948e306dSRony Efraim return 0; 2529948e306dSRony Efraim } 2530948e306dSRony Efraim EXPORT_SYMBOL_GPL(mlx4_set_vf_link_state); 2531