Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Mar 2019 13:41:28 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r345536 - stable/11/sys/dev/mlx4/mlx4_core
Message-ID:  <201903261341.x2QDfSUq033124@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue Mar 26 13:41:27 2019
New Revision: 345536
URL: https://svnweb.freebsd.org/changeset/base/345536

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/11/sys/dev/mlx4/mlx4_core/mlx4_cmd.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/mlx4/mlx4_core/mlx4_cmd.c
==============================================================================
--- stable/11/sys/dev/mlx4/mlx4_core/mlx4_cmd.c	Tue Mar 26 13:40:33 2019	(r345535)
+++ stable/11/sys/dev/mlx4/mlx4_core/mlx4_cmd.c	Tue Mar 26 13:41:27 2019	(r345536)
@@ -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);
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903261341.x2QDfSUq033124>