svn commit: r345535 - stable/12/sys/dev/mlx4/mlx4_core

Hans Petter Selasky hselasky at FreeBSD.org
Tue Mar 26 13:40:35 UTC 2019


Author: hselasky
Date: Tue Mar 26 13:40:33 2019
New Revision: 345535
URL: https://svnweb.freebsd.org/changeset/base/345535

Log:
  MFC r345010:
  Improve support for switching to and from command polling mode in mlx4core.
  
  Make sure the enter and leave polling routines can be called multiple times
  with same setting. Ignore setting polling or event mode twice. This fixes a
  deadlock during shutdown if polling mode was already selected.
  
  Sponsored by:		Mellanox Technologies

Modified:
  stable/12/sys/dev/mlx4/mlx4_core/mlx4_cmd.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/mlx4/mlx4_core/mlx4_cmd.c
==============================================================================
--- stable/12/sys/dev/mlx4/mlx4_core/mlx4_cmd.c	Tue Mar 26 13:38:49 2019	(r345534)
+++ stable/12/sys/dev/mlx4/mlx4_core/mlx4_cmd.c	Tue Mar 26 13:40:33 2019	(r345535)
@@ -2490,6 +2490,7 @@ int mlx4_cmd_init(struct mlx4_dev *dev)
 		init_rwsem(&priv->cmd.switch_sem);
 		mutex_init(&priv->cmd.slave_cmd_mutex);
 		sema_init(&priv->cmd.poll_sem, 1);
+		sema_init(&priv->cmd.event_sem, 0);
 		priv->cmd.use_events = 0;
 		priv->cmd.toggle     = 1;
 		priv->cmd.initialized = 1;
@@ -2617,8 +2618,10 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
 {
 	struct mlx4_priv *priv = mlx4_priv(dev);
 	int i;
-	int err = 0;
 
+	if (priv->cmd.use_events != 0)
+		return 0;
+
 	priv->cmd.context = kmalloc(priv->cmd.max_cmds *
 				   sizeof (struct mlx4_cmd_context),
 				   GFP_KERNEL);
@@ -2639,7 +2642,8 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
 	priv->cmd.context[priv->cmd.max_cmds - 1].next = -1;
 	priv->cmd.free_head = 0;
 
-	sema_init(&priv->cmd.event_sem, priv->cmd.max_cmds);
+	for (i = 0; i != priv->cmd.max_cmds; i++)
+		up(&priv->cmd.event_sem);
 
 	for (priv->cmd.token_mask = 1;
 	     priv->cmd.token_mask < priv->cmd.max_cmds;
@@ -2651,7 +2655,7 @@ int mlx4_cmd_use_events(struct mlx4_dev *dev)
 	priv->cmd.use_events = 1;
 	up_write(&priv->cmd.switch_sem);
 
-	return err;
+	return 0;
 }
 
 /*
@@ -2662,6 +2666,9 @@ void mlx4_cmd_use_polling(struct mlx4_dev *dev)
 	struct mlx4_priv *priv = mlx4_priv(dev);
 	int i;
 
+	if (priv->cmd.use_events == 0)
+		return;
+
 	down_write(&priv->cmd.switch_sem);
 	priv->cmd.use_events = 0;
 
@@ -2669,6 +2676,7 @@ void mlx4_cmd_use_polling(struct mlx4_dev *dev)
 		down(&priv->cmd.event_sem);
 
 	kfree(priv->cmd.context);
+	priv->cmd.context = NULL;
 
 	up(&priv->cmd.poll_sem);
 	up_write(&priv->cmd.switch_sem);
@@ -2740,11 +2748,11 @@ void mlx4_cmd_wake_completions(struct mlx4_dev *dev)
 	int i;
 
 	spin_lock(&priv->cmd.context_lock);
-	if (priv->cmd.context) {
+	if (priv->cmd.context != NULL) {
 		for (i = 0; i < priv->cmd.max_cmds; ++i) {
 			context = &priv->cmd.context[i];
 			context->fw_status = CMD_STAT_INTERNAL_ERR;
-			context->result    =
+			context->result =
 				mlx4_status_to_errno(CMD_STAT_INTERNAL_ERR);
 			complete(&context->done);
 		}


More information about the svn-src-all mailing list