Browse Source

net/mlx5: Expose command polling interface

Add a new interface for commands execution that allows the
caller to wait for the command's completion in a busy-wait
loop (polling mode).

This is useful if we want to execute a command in a polling mode
while the driver is working in events mode for the rest of
the commands.
This interface will be used in the downstream patches.

Signed-off-by: Majd Dibbiny <majd@mellanox.com>
Signed-off-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Majd Dibbiny 8 years ago
parent
commit
4525abeaae
2 changed files with 26 additions and 7 deletions
  1. 23 7
      drivers/net/ethernet/mellanox/mlx5/core/cmd.c
  2. 3 0
      include/linux/mlx5/driver.h

+ 23 - 7
drivers/net/ethernet/mellanox/mlx5/core/cmd.c

@@ -785,6 +785,8 @@ static void cmd_work_handler(struct work_struct *work)
 	struct mlx5_cmd_layout *lay;
 	struct mlx5_cmd_layout *lay;
 	struct semaphore *sem;
 	struct semaphore *sem;
 	unsigned long flags;
 	unsigned long flags;
+	bool poll_cmd = ent->polling;
+
 
 
 	sem = ent->page_queue ? &cmd->pages_sem : &cmd->sem;
 	sem = ent->page_queue ? &cmd->pages_sem : &cmd->sem;
 	down(sem);
 	down(sem);
@@ -845,7 +847,7 @@ static void cmd_work_handler(struct work_struct *work)
 	iowrite32be(1 << ent->idx, &dev->iseg->cmd_dbell);
 	iowrite32be(1 << ent->idx, &dev->iseg->cmd_dbell);
 	mmiowb();
 	mmiowb();
 	/* if not in polling don't use ent after this point */
 	/* if not in polling don't use ent after this point */
-	if (cmd->mode == CMD_MODE_POLLING) {
+	if (cmd->mode == CMD_MODE_POLLING || poll_cmd) {
 		poll_timeout(ent);
 		poll_timeout(ent);
 		/* make sure we read the descriptor after ownership is SW */
 		/* make sure we read the descriptor after ownership is SW */
 		rmb();
 		rmb();
@@ -889,7 +891,7 @@ static int wait_func(struct mlx5_core_dev *dev, struct mlx5_cmd_work_ent *ent)
 	struct mlx5_cmd *cmd = &dev->cmd;
 	struct mlx5_cmd *cmd = &dev->cmd;
 	int err;
 	int err;
 
 
-	if (cmd->mode == CMD_MODE_POLLING) {
+	if (cmd->mode == CMD_MODE_POLLING || ent->polling) {
 		wait_for_completion(&ent->done);
 		wait_for_completion(&ent->done);
 	} else if (!wait_for_completion_timeout(&ent->done, timeout)) {
 	} else if (!wait_for_completion_timeout(&ent->done, timeout)) {
 		ent->ret = -ETIMEDOUT;
 		ent->ret = -ETIMEDOUT;
@@ -917,7 +919,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
 			   struct mlx5_cmd_msg *out, void *uout, int uout_size,
 			   struct mlx5_cmd_msg *out, void *uout, int uout_size,
 			   mlx5_cmd_cbk_t callback,
 			   mlx5_cmd_cbk_t callback,
 			   void *context, int page_queue, u8 *status,
 			   void *context, int page_queue, u8 *status,
-			   u8 token)
+			   u8 token, bool force_polling)
 {
 {
 	struct mlx5_cmd *cmd = &dev->cmd;
 	struct mlx5_cmd *cmd = &dev->cmd;
 	struct mlx5_cmd_work_ent *ent;
 	struct mlx5_cmd_work_ent *ent;
@@ -935,6 +937,7 @@ static int mlx5_cmd_invoke(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *in,
 		return PTR_ERR(ent);
 		return PTR_ERR(ent);
 
 
 	ent->token = token;
 	ent->token = token;
+	ent->polling = force_polling;
 
 
 	if (!callback)
 	if (!callback)
 		init_completion(&ent->done);
 		init_completion(&ent->done);
@@ -1535,7 +1538,8 @@ static int is_manage_pages(void *in)
 }
 }
 
 
 static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
 static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
-		    int out_size, mlx5_cmd_cbk_t callback, void *context)
+		    int out_size, mlx5_cmd_cbk_t callback, void *context,
+		    bool force_polling)
 {
 {
 	struct mlx5_cmd_msg *inb;
 	struct mlx5_cmd_msg *inb;
 	struct mlx5_cmd_msg *outb;
 	struct mlx5_cmd_msg *outb;
@@ -1580,7 +1584,7 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
 	}
 	}
 
 
 	err = mlx5_cmd_invoke(dev, inb, outb, out, out_size, callback, context,
 	err = mlx5_cmd_invoke(dev, inb, outb, out, out_size, callback, context,
-			      pages_queue, &status, token);
+			      pages_queue, &status, token, force_polling);
 	if (err)
 	if (err)
 		goto out_out;
 		goto out_out;
 
 
@@ -1608,7 +1612,7 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
 {
 {
 	int err;
 	int err;
 
 
-	err = cmd_exec(dev, in, in_size, out, out_size, NULL, NULL);
+	err = cmd_exec(dev, in, in_size, out, out_size, NULL, NULL, false);
 	return err ? : mlx5_cmd_check(dev, in, out);
 	return err ? : mlx5_cmd_check(dev, in, out);
 }
 }
 EXPORT_SYMBOL(mlx5_cmd_exec);
 EXPORT_SYMBOL(mlx5_cmd_exec);
@@ -1617,10 +1621,22 @@ int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
 		     void *out, int out_size, mlx5_cmd_cbk_t callback,
 		     void *out, int out_size, mlx5_cmd_cbk_t callback,
 		     void *context)
 		     void *context)
 {
 {
-	return cmd_exec(dev, in, in_size, out, out_size, callback, context);
+	return cmd_exec(dev, in, in_size, out, out_size, callback, context,
+			false);
 }
 }
 EXPORT_SYMBOL(mlx5_cmd_exec_cb);
 EXPORT_SYMBOL(mlx5_cmd_exec_cb);
 
 
+int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
+			  void *out, int out_size)
+{
+	int err;
+
+	err = cmd_exec(dev, in, in_size, out, out_size, NULL, NULL, true);
+
+	return err ? : mlx5_cmd_check(dev, in, out);
+}
+EXPORT_SYMBOL(mlx5_cmd_exec_polling);
+
 static void destroy_msg_cache(struct mlx5_core_dev *dev)
 static void destroy_msg_cache(struct mlx5_core_dev *dev)
 {
 {
 	struct cmd_msg_cache *ch;
 	struct cmd_msg_cache *ch;

+ 3 - 0
include/linux/mlx5/driver.h

@@ -817,6 +817,7 @@ struct mlx5_cmd_work_ent {
 	u64			ts1;
 	u64			ts1;
 	u64			ts2;
 	u64			ts2;
 	u16			op;
 	u16			op;
+	bool			polling;
 };
 };
 
 
 struct mlx5_pas {
 struct mlx5_pas {
@@ -915,6 +916,8 @@ int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
 int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
 int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
 		     void *out, int out_size, mlx5_cmd_cbk_t callback,
 		     void *out, int out_size, mlx5_cmd_cbk_t callback,
 		     void *context);
 		     void *context);
+int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
+			  void *out, int out_size);
 void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
 void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
 
 
 int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
 int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);