From owner-svn-src-head@freebsd.org Mon Mar 11 14:29:51 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 723A91544D55; Mon, 11 Mar 2019 14:29:51 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CB10169B98; Mon, 11 Mar 2019 14:29:50 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BAE11C136; Mon, 11 Mar 2019 14:29:50 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x2BETooD004546; Mon, 11 Mar 2019 14:29:50 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x2BEToX6004545; Mon, 11 Mar 2019 14:29:50 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201903111429.x2BEToX6004545@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 11 Mar 2019 14:29:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345010 - head/sys/dev/mlx4/mlx4_core X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/sys/dev/mlx4/mlx4_core X-SVN-Commit-Revision: 345010 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: CB10169B98 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.995,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.957,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Mar 2019 14:29:51 -0000 Author: hselasky Date: Mon Mar 11 14:29:50 2019 New Revision: 345010 URL: https://svnweb.freebsd.org/changeset/base/345010 Log: 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. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/dev/mlx4/mlx4_core/mlx4_cmd.c Modified: head/sys/dev/mlx4/mlx4_core/mlx4_cmd.c ============================================================================== --- head/sys/dev/mlx4/mlx4_core/mlx4_cmd.c Mon Mar 11 14:26:45 2019 (r345009) +++ head/sys/dev/mlx4/mlx4_core/mlx4_cmd.c Mon Mar 11 14:29:50 2019 (r345010) @@ -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); }