Skip to contentSkip to conversation

mlx4: Communication channel interrupts

PATCH In review Yevgeny Petrilin 1 participant 1 message Jun 10, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v4 19/19 mlx4: Communication channel interrupts

The master function receives am interrupt each time on eof the slaves writes to the communication channel, and then handles the channel from a deffered task. The slaves can now receive command completions an async events by interrupts. The open an EQ and the master generates eqes and "pushes" them to the slave's EQ using Firmware "GEN_EQE" command.

---
 drivers/net/mlx4/cmd.c      |  258 +++++++++++++++++++++++++++++++-------
 drivers/net/mlx4/eq.c       |  296 +++++++++++++++++++------------------------
 drivers/net/mlx4/main.c     |   50 +++-----
 drivers/net/mlx4/mlx4.h     |   97 +++++++++++++--
 include/linux/mlx4/cmd.h    |    7 +-
 include/linux/mlx4/device.h |    1 +
 6 files changed, 459 insertions(+), 250 deletions(-)
drivers/net/mlx4/cmd.c +214 -44
index 7efa85f..083ae0f 100644
@@ -148,19 +148,11 @@ static int comm_pending(struct mlx4_dev *dev)
 	return (swab32(status) >> 30) != priv->cmd.comm_toggle;
 }
 
-int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param, unsigned long timeout)
+static void mlx4_comm_cmd_post(struct mlx4_dev *dev, u8 cmd, u16 param)
 {
 	struct mlx4_priv *priv = mlx4_priv(dev);
-	unsigned long end;
 	u32 val;
 
-	/* First, verify that the master reports correct status */
-	if (comm_pending(dev)) {
-		mlx4_warn(dev, "Communication channel is not idle\n");
-		return -EAGAIN;
-	}
-
-	/* Write command */
 	if (cmd == MLX4_COMM_CMD_RESET)
 		priv->cmd.comm_toggle = 0;
 	else if (++priv->cmd.comm_toggle > 2)
@@ -168,6 +160,23 @@ int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param, unsigned long timeout
 	val = param | (cmd << 16) | (priv->cmd.comm_toggle << 30);
 	__raw_writel((__force u32) cpu_to_be32(val), &priv->mfunc.comm->slave_write);
 	wmb();
+}
+
+int mlx4_comm_cmd_poll(struct mlx4_dev *dev, u8 cmd, u16 param, unsigned long timeout)
+{
+	struct mlx4_priv *priv = mlx4_priv(dev);
+	unsigned long end;
+	int err = 0;
+
+	/* First, verify that the master reports correct status */
+	if (comm_pending(dev)) {
+		mlx4_warn(dev, "Communication channel is not idle\n");
+		return -EAGAIN;
+	}
+
+	/* Write command */
+	down(&priv->cmd.poll_sem);
+	mlx4_comm_cmd_post(dev, cmd, param);
 
 	end = msecs_to_jiffies(timeout) + jiffies;
 	while (comm_pending(dev) && time_before(jiffies, end))
@@ -175,11 +184,57 @@ int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param, unsigned long timeout
 
 	if (comm_pending(dev)) {
 		mlx4_warn(dev, "Communication channel timed out\n");
-		return -ETIMEDOUT;
+		err = -ETIMEDOUT;
 	}
+
+	up(&priv->cmd.poll_sem);
 	return 0;
 }
 
+static int mlx4_comm_cmd_wait(struct mlx4_dev *dev, u8 op,
+			      u16 param, unsigned long timeout)
+{
+	struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
+	struct mlx4_cmd_context *context;
+	int err = 0;
+
+	down(&cmd->event_sem);
+
+	spin_lock(&cmd->context_lock);
+	BUG_ON(cmd->free_head < 0);
+	context = &cmd->context[cmd->free_head];
+	context->token += cmd->token_mask + 1;
+	cmd->free_head = context->next;
+	spin_unlock(&cmd->context_lock);
+
+	init_completion(&context->done);
+
+	mlx4_comm_cmd_post(dev, op, param);
+
+	if (!wait_for_completion_timeout(&context->done, msecs_to_jiffies(timeout))) {
+		err = -EBUSY;
+		goto out;
+	}
+
+	err = context->result;
+
+out:
+	spin_lock(&cmd->context_lock);
+	context->next = cmd->free_head;
+	cmd->free_head = context - cmd->context;
+	spin_unlock(&cmd->context_lock);
+
+	up(&cmd->event_sem);
+	return err;
+}
+
+int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param, unsigned long timeout)
+{
+	if (mlx4_priv(dev)->cmd.use_events)
+		return mlx4_comm_cmd_wait(dev, cmd, param, timeout);
+	return mlx4_comm_cmd_poll(dev, cmd, param, timeout);
+}
+
 static int cmd_pending(struct mlx4_dev *dev)
 {
 	u32 status = readl(mlx4_priv(dev)->cmd.hcr + HCR_STATUS_OFFSET);
@@ -247,15 +302,15 @@ out:
 	return ret;
 }
 
-static int mlx4_slave_cmd_poll(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
-			 int out_is_imm, u32 in_modifier, u8 op_modifier,
-			 u16 op, unsigned long timeout)
+static int mlx4_slave_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
+			  int out_is_imm, u32 in_modifier, u8 op_modifier,
+			  u16 op, unsigned long timeout)
 {
 	struct mlx4_priv *priv = mlx4_priv(dev);
 	struct mlx4_vhcr *vhcr = priv->mfunc.vhcr;
 	int ret;
 
-	down(&priv->cmd.poll_sem);
+	down(&priv->cmd.slave_sem);
 	vhcr->in_param = in_param;
 	vhcr->out_param = out_param ? *out_param : 0;
 	vhcr->in_modifier = in_modifier;
@@ -270,7 +325,7 @@ static int mlx4_slave_cmd_poll(struct mlx4_dev *dev, u64 in_param, u64 *out_para
 			*out_param = vhcr->out_param;
 		ret = vhcr->errno;
 	}
-	up(&priv->cmd.poll_sem);
+	up(&priv->cmd.slave_sem);
 	return ret;
 }
 
@@ -378,19 +433,61 @@ int __mlx4_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
 	       int out_is_imm, u32 in_modifier, u8 op_modifier,
 	       u16 op, unsigned long timeout)
 {
+	if (mlx4_is_slave(dev))
+		return mlx4_slave_cmd(dev, in_param, out_param, out_is_imm,
+				      in_modifier, op_modifier, op, timeout);
+
 	if (mlx4_priv(dev)->cmd.use_events)
 		return mlx4_cmd_wait(dev, in_param, out_param, out_is_imm,
 				     in_modifier, op_modifier, op, timeout);
-
-	if (mlx4_is_slave(dev))
-		return mlx4_slave_cmd_poll(dev, in_param, out_param, out_is_imm,
-				     in_modifier, op_modifier, op, timeout);
 	else
 		return mlx4_cmd_poll(dev, in_param, out_param, out_is_imm,
 				     in_modifier, op_modifier, op, timeout);
 }
 EXPORT_SYMBOL_GPL(__mlx4_cmd);
 
+
+static int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev *dev)
+{
+	return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_ARM_COMM_CHANNEL, MLX4_CMD_TIME_CLASS_B);
+}
+
+int mlx4_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe)
+{
+	struct mlx4_priv *priv = mlx4_priv(dev);
+	struct mlx4_slave_event_eq_info *event_eq =
+		&priv->mfunc.master.slave_state[slave].event_eq;
+	struct mlx4_cmd_mailbox *mailbox;
+	u32 in_modifier = 0;
+	int err;
+
+	if (!event_eq->use_int)
+		return 0;
+
+	/* Create the event only if the slave is registered */
+	if ((event_eq->event_type & eqe->type) == 0)
+		return 0;
+
+	mailbox = mlx4_alloc_cmd_mailbox(dev);
+	if (IS_ERR(mailbox))
+		return PTR_ERR(mailbox);
+
+	if (eqe->type == MLX4_EVENT_TYPE_CMD) {
+		++event_eq->token;
+		eqe->event.cmd.token = cpu_to_be16(event_eq->token);
+	}
+
+	memcpy(mailbox->buf, (u8 *) eqe, 28);
+
+	in_modifier = (slave & 0xff) | ((event_eq->eqn & 0xff) << 16);
+
+	err = mlx4_cmd(dev, mailbox->dma, in_modifier, 0,
+		       MLX4_CMD_GEN_EQE, MLX4_CMD_TIME_CLASS_B);
+
+       mlx4_free_cmd_mailbox(dev, mailbox);
+       return err;
+}
+
 static int mlx4_ACCESS_MEM(struct mlx4_dev *dev, u64 master_addr,
 			   int slave, u64 slave_addr,
 			   int size, int is_read)
@@ -597,12 +694,21 @@ static struct mlx4_cmd_info {
 	},
 
 	{
+		.opcode = MLX4_CMD_COMM_INT,
+		.has_inbox = false,
+		.has_outbox = false,
+		.out_is_imm = false,
+		.verify = NULL,
+		.wrapper = mlx4_COMM_INT_wrapper
+	},
+	{
 		.opcode = MLX4_CMD_INIT_PORT,
 		.has_inbox = false,
 		.has_outbox = false,
 		.out_is_imm = false,
 		.verify = NULL,
-		.wrapper = mlx4_INIT_PORT_wrapper},
+		.wrapper = mlx4_INIT_PORT_wrapper
+	},
 	{
 		.opcode = MLX4_CMD_CLOSE_PORT,
 		.has_inbox = false,
@@ -629,6 +735,14 @@ static struct mlx4_cmd_info {
 	},
 
 	{
+		.opcode = MLX4_CMD_MAP_EQ,
+		.has_inbox = false,
+		.has_outbox = false,
+		.out_is_imm = false,
+		.verify = NULL,
+		.wrapper = mlx4_MAP_EQ_wrapper
+	},
+	{
 		.opcode = MLX4_CMD_SW2HW_EQ,
 		.has_inbox = true,
 		.has_outbox = false,
@@ -1108,6 +1222,7 @@ static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd, u16 para
 
 	if (cmd == MLX4_COMM_CMD_RESET) {
 		mlx4_warn(dev, "Received reset from slave:%d\n", slave);
+		slave_state[slave].active = false;
 		goto reset_slave;
 	}
 
@@ -1146,6 +1261,7 @@ static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd, u16 para
 				      "number for slave %d\n", slave);
 			goto reset_slave;
 		}
+		slave_state[slave].active = true;
 		break;
 	case MLX4_COMM_CMD_VHCR_POST:
 		if ((slave_state[slave].last_cmd != MLX4_COMM_CMD_VHCR_EN) &&
@@ -1167,45 +1283,59 @@ static void mlx4_master_do_cmd(struct mlx4_dev *dev, int slave, u8 cmd, u16 para
 	__raw_writel((__force u32) cpu_to_be32(reply),
 		     &priv->mfunc.comm[slave].slave_read);
 	wmb();
+	if (mlx4_GEN_EQE(dev, slave, &priv->mfunc.master.cmd_eqe))
+		mlx4_warn(dev, "Failed to generate command completion eqe "
+			       "for slave %d\n", slave);
+
 	return;
 
 reset_slave:
 	/* FIXME: cleanup any slave resources */
 	slave_state[slave].last_cmd = MLX4_COMM_CMD_RESET;
 	slave_state[slave].comm_toggle = 0;
+	memset(&slave_state[slave].event_eq, 0,
+	       sizeof(struct mlx4_slave_event_eq_info));
 	__raw_writel((__force u32) 0, &priv->mfunc.comm[slave].slave_write);
 	__raw_writel((__force u32) 0, &priv->mfunc.comm[slave].slave_read);
 	wmb();
 }
 
 /* master command processing */
-static void mlx4_master_poll_comm(struct work_struct *work)
+void mlx4_master_comm_channel(struct work_struct *work)
 {
-	struct delayed_work *delay = container_of(work, struct delayed_work, work);
-	struct mlx4_mfunc *mfunc = container_of(delay, struct mlx4_mfunc, comm_work);
+	struct mlx4_mfunc_master_ctx *master = container_of(work,
+							   struct mlx4_mfunc_master_ctx,
+							   comm_work);
+	struct mlx4_mfunc *mfunc = container_of(master, struct mlx4_mfunc, master);
 	struct mlx4_priv *priv = container_of(mfunc, struct mlx4_priv, mfunc);
 	struct mlx4_dev *dev = &priv->dev;
+	u32 *bit_vec;
 	u32 comm_cmd;
-	int polled = 0;
-	int i;
-
-	/* Give each slave a chance for one command */
-	for (i = 0; i < dev->num_slaves; i++) {
-		comm_cmd = swab32(readl(&priv->mfunc.comm[i].slave_write));
-		if (comm_cmd >> 30 != priv->mfunc.master.slave_state[i].comm_toggle) {
-			mlx4_master_do_cmd(dev, i, comm_cmd >> 16, comm_cmd, comm_cmd >> 30);
-			polled = 1;
+	u32 vec;
+	int i, j, slave;
+
+	bit_vec = master->comm_arm_bit_vector;
+	for (i = 0; i < COMM_CHANNEL_BIT_ARRAY_SIZE; i++) {
+		vec = be32_to_cpu(bit_vec[i]);
+		for (j = 0; j < 32; j++) {
+			if (!(vec & (1 << j)))
+				continue;
+			slave = (i * 32) + j;
+			comm_cmd = swab32(readl(&mfunc->comm[slave].slave_write));
+			if (comm_cmd >> 30 != master->slave_state[slave].comm_toggle)
+				mlx4_master_do_cmd(dev, slave, comm_cmd >> 16, comm_cmd, comm_cmd >> 30);
 		}
 	}
-	queue_delayed_work(priv->mfunc.comm_wq, &priv->mfunc.comm_work,
-						polled ? 0 : HZ / 10);
+
+	if (mlx4_ARM_COMM_CHANNEL(dev))
+		mlx4_warn(dev, "Failed to arm comm channel events");
 }
 
 int mlx4_multi_func_init(struct mlx4_dev *dev)
 {
 	struct mlx4_priv *priv = mlx4_priv(dev);
 	struct mlx4_slave_state *s_state;
-	int i, port;
+	int i, err, port;
 
 	priv->mfunc.vhcr = dma_alloc_coherent(&(dev->pdev->dev), PAGE_SIZE,
 					    &priv->mfunc.vhcr_dma,
@@ -1253,20 +1383,30 @@ int mlx4_multi_func_init(struct mlx4_dev *dev)
 			spin_lock_init(&s_state->lock);
 		}
 
-		INIT_DELAYED_WORK(&priv->mfunc.comm_work, mlx4_master_poll_comm);
-		priv->mfunc.comm_wq = create_singlethread_workqueue("mlx4_comm");
-		if (!priv->mfunc.comm_wq)
+		memset(&priv->mfunc.master.cmd_eqe, 0, sizeof(struct mlx4_eqe));
+		priv->mfunc.master.cmd_eqe.type = MLX4_EVENT_TYPE_CMD;
+		INIT_WORK(&priv->mfunc.master.comm_work, mlx4_master_comm_channel);
+		INIT_WORK(&priv->mfunc.master.slave_event_work, mlx4_gen_slave_eqe);
+		priv->mfunc.master.comm_wq = create_singlethread_workqueue("mlx4_comm");
+		if (!priv->mfunc.master.comm_wq)
 			goto err_slaves;
 
+		err = mlx4_ARM_COMM_CHANNEL(dev);
+		if (err) {
+			mlx4_err(dev, " Failed to arm comm channel eq: %x\n", err);
+			goto err_thread;
+		}
+
 	} else {
+		sema_init(&priv->cmd.slave_sem, 1);
 		priv->cmd.comm_toggle = 0;
-		INIT_DELAYED_WORK(&priv->mfunc.comm_work, mlx4_slave_async_eq_poll);
-		priv->mfunc.comm_wq = create_singlethread_workqueue("mlx4_event");
-		if (!priv->mfunc.comm_wq)
 			goto err_comm;
 	}
 	return 0;
 
+err_thread:
+	flush_workqueue(priv->mfunc.master.comm_wq);
+	destroy_workqueue(priv->mfunc.master.comm_wq);
 err_slaves:
 	while (--i) {
 		for (port = 1; port <= MLX4_MAX_PORTS; port++)
@@ -1323,8 +1463,9 @@ void mlx4_multi_func_cleanup(struct mlx4_dev *dev)
 	struct mlx4_priv *priv = mlx4_priv(dev);
 	int i, port;
 
-	if (priv->mfunc.vhcr) {
-		destroy_workqueue(priv->mfunc.comm_wq);
+	if (mlx4_is_master(dev)) {
+		flush_workqueue(priv->mfunc.master.comm_wq);
+		destroy_workqueue(priv->mfunc.master.comm_wq);
 		for (i = 0; i < dev->num_slaves; i++) {
 			for (port = 1; port <= MLX4_MAX_PORTS; port++)
 				kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]);
@@ -1356,6 +1497,7 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
 {
 	struct mlx4_priv *priv = mlx4_priv(dev);
 	int i;
+	int err = 0;
 
 	priv->cmd.context = kmalloc(priv->cmd.max_cmds *
 				   sizeof (struct mlx4_cmd_context),
@@ -1382,9 +1524,17 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
 
 	priv->cmd.use_events = 1;
 
+	if (mlx4_is_slave(dev)) {
+		err = mlx4_cmd(dev, 0, 1, 0, MLX4_CMD_COMM_INT, MLX4_CMD_TIME_CLASS_A);
+		if (err) {
+			mlx4_err(dev, "Failed to move to events for the slave\n");
+			priv->cmd.use_events = 0;
+		}
+	}
+
 	down(&priv->cmd.poll_sem);
 
-	return 0;
+	return err;
 }
 
 /*
@@ -1403,6 +1553,9 @@ void mlx4_cmd_use_polling(struct mlx4_dev *dev)
 	kfree(priv->cmd.context);
 
 	up(&priv->cmd.poll_sem);
+
+	if (mlx4_is_slave(dev))
+		mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_COMM_INT, MLX4_CMD_TIME_CLASS_A);
 }
 
 struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct mlx4_dev *dev)
@@ -1433,3 +1586,20 @@ void mlx4_free_cmd_mailbox(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbo
 	kfree(mailbox);
 }
 EXPORT_SYMBOL_GPL(mlx4_free_cmd_mailbox);
+
+int mlx4_COMM_INT_wrapper(struct mlx4_dev *dev, int slave, struct mlx4_vhcr *vhcr,
+			  struct mlx4_cmd_mailbox *inbox,
+			  struct mlx4_cmd_mailbox *outbox)
+{
+	struct mlx4_priv *priv = mlx4_priv(dev);
+	struct mlx4_slave_event_eq_info *event_eq =
+		&priv->mfunc.master.slave_state[slave].event_eq;
+
+	if (vhcr->in_modifier)
+		event_eq->use_int = true;
+	else
+		event_eq->use_int = false;
+
+	return 0;
+}
+
drivers/net/mlx4/eq.c +132 -164

406 lines not on this page · raw message

drivers/net/mlx4/main.c +19 -31

123 lines not on this page · raw message

drivers/net/mlx4/mlx4.h +87 -10

161 lines not on this page · raw message

include/linux/mlx4/cmd.h +6 -1
index 9225791..a6901c3 100644
@@ -125,6 +125,10 @@ enum {
 	MLX4_CMD_SET_MCAST_FLTR	 = 0x48,
 	MLX4_CMD_DUMP_ETH_STATS	 = 0x49,
 
+	/* Communication channel commands */
+	MLX4_CMD_ARM_COMM_CHANNEL = 0x57,
+	MLX4_CMD_GEN_EQE	 = 0x58,
+
 	/* virtual commands */
 	MLX4_CMD_ALLOC_RES	 = 0xf00,
 	MLX4_CMD_FREE_RES	 = 0xf01,
@@ -132,7 +136,8 @@ enum {
 	MLX4_CMD_GET_EVENT	 = 0xf03,
 	MLX4_CMD_QUERY_SLAVE_CAP = 0xf04,
 	MLX4_CMD_MCAST_ATTACH    = 0xf05,
-	MLX4_CMD_PROMISC         = 0xf07,
+	MLX4_CMD_COMM_INT        = 0xf07,
+	MLX4_CMD_PROMISC         = 0xf08,
 
 	/* debug commands */
 	MLX4_CMD_QUERY_DEBUG_MSG = 0x2a,
include/linux/mlx4/device.h +1 -0
index c03a176..1b553b0 100644
@@ -101,6 +101,7 @@ enum mlx4_event {
 	MLX4_EVENT_TYPE_EQ_OVERFLOW	   = 0x0f,
 	MLX4_EVENT_TYPE_ECC_DETECT	   = 0x0e,
 	MLX4_EVENT_TYPE_CMD		   = 0x0a,
+	MLX4_EVENT_TYPE_COMM_CHANNEL       = 0x18,
 	MLX4_EVENT_TYPE_NONE		   = 0xff,
 };
 
Signature · 6 lines
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html