From owner-svn-src-stable-10@freebsd.org Mon Aug 7 12:29:42 2017 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CAD0DDD01D1; Mon, 7 Aug 2017 12:29:42 +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 mx1.freebsd.org (Postfix) with ESMTPS id A626C68547; Mon, 7 Aug 2017 12:29:42 +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 v77CTfx9082108; Mon, 7 Aug 2017 12:29:41 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v77CTf8f082107; Mon, 7 Aug 2017 12:29:41 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201708071229.v77CTf8f082107@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 7 Aug 2017 12:29:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r322141 - stable/10/sys/dev/mlx5/mlx5_core X-SVN-Group: stable-10 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/10/sys/dev/mlx5/mlx5_core X-SVN-Commit-Revision: 322141 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Aug 2017 12:29:42 -0000 Author: hselasky Date: Mon Aug 7 12:29:41 2017 New Revision: 322141 URL: https://svnweb.freebsd.org/changeset/base/322141 Log: MFC r312877 and r312878: Minor code refactor as a preparation step for suprise removal of CX-4 PCI device(s), changes: - alloc_entry() now clears bit for page slot entry aswell - update of cmd->ent_arr[] is now under cmd->alloc_lock - complete command if alloc_entry() fails Sponsored by: Mellanox Technologies Modified: stable/10/sys/dev/mlx5/mlx5_core/mlx5_cmd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/mlx5/mlx5_core/mlx5_cmd.c ============================================================================== --- stable/10/sys/dev/mlx5/mlx5_core/mlx5_cmd.c Mon Aug 7 12:27:59 2017 (r322140) +++ stable/10/sys/dev/mlx5/mlx5_core/mlx5_cmd.c Mon Aug 7 12:29:41 2017 (r322141) @@ -39,6 +39,11 @@ #include "mlx5_core.h" +static int mlx5_copy_from_msg(void *to, struct mlx5_cmd_msg *from, int size); +static void mlx5_free_cmd_msg(struct mlx5_core_dev *dev, + struct mlx5_cmd_msg *msg); +static void free_msg(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *msg); + enum { CMD_IF_REV = 5, }; @@ -110,18 +115,27 @@ static u8 alloc_token(struct mlx5_cmd *cmd) return token; } -static int alloc_ent(struct mlx5_cmd *cmd) +static int alloc_ent(struct mlx5_cmd_work_ent *ent) { unsigned long flags; - int ret; + struct mlx5_cmd *cmd = ent->cmd; + int ret = cmd->max_reg_cmds; spin_lock_irqsave(&cmd->alloc_lock, flags); - ret = find_first_bit(&cmd->bitmask, cmd->max_reg_cmds); - if (ret < cmd->max_reg_cmds) - clear_bit(ret, &cmd->bitmask); + if (!ent->page_queue) { + ret = find_first_bit(&cmd->bitmask, cmd->max_reg_cmds); + if (ret >= cmd->max_reg_cmds) + ret = -1; + } + + if (ret != -1) { + ent->idx = ret; + clear_bit(ent->idx, &cmd->bitmask); + cmd->ent_arr[ent->idx] = ent; + } spin_unlock_irqrestore(&cmd->alloc_lock, flags); - return ret < cmd->max_reg_cmds ? ret : -1; + return ret; } static void free_ent(struct mlx5_cmd *cmd, int idx) @@ -704,6 +718,54 @@ static void dump_command(struct mlx5_core_dev *dev, pr_debug("\n"); } +static void complete_command(struct mlx5_cmd_work_ent *ent) +{ + struct mlx5_cmd *cmd = ent->cmd; + struct mlx5_core_dev *dev = container_of(cmd, struct mlx5_core_dev, + cmd); + mlx5_cmd_cbk_t callback; + void *context; + + s64 ds; + struct mlx5_cmd_stats *stats; + unsigned long flags; + int err; + struct semaphore *sem; + + if (ent->page_queue) + sem = &cmd->pages_sem; + else + sem = &cmd->sem; + + if (ent->callback) { + ds = ent->ts2 - ent->ts1; + if (ent->op < ARRAY_SIZE(cmd->stats)) { + stats = &cmd->stats[ent->op]; + spin_lock_irqsave(&stats->lock, flags); + stats->sum += ds; + ++stats->n; + spin_unlock_irqrestore(&stats->lock, flags); + } + + callback = ent->callback; + context = ent->context; + err = ent->ret; + if (!err) + err = mlx5_copy_from_msg(ent->uout, + ent->out, + ent->uout_size); + + mlx5_free_cmd_msg(dev, ent->out); + free_msg(dev, ent->in); + + free_cmd(ent); + callback(err, context); + } else { + complete(&ent->done); + } + up(sem); +} + static void cmd_work_handler(struct work_struct *work) { struct mlx5_cmd_work_ent *ent = container_of(work, struct mlx5_cmd_work_ent, work); @@ -719,19 +781,13 @@ static void cmd_work_handler(struct work_struct *work) } down(sem); - if (!ent->page_queue) { - ent->idx = alloc_ent(cmd); - if (ent->idx < 0) { - mlx5_core_err(dev, "failed to allocate command entry\n"); - up(sem); - return; - } - } else { - ent->idx = cmd->max_reg_cmds; + + if (alloc_ent(ent) < 0) { + complete_command(ent); + return; } ent->token = alloc_token(cmd); - cmd->ent_arr[ent->idx] = ent; lay = get_inst(cmd, ent->idx); ent->lay = lay; memset(lay, 0, sizeof(*lay)); @@ -1108,23 +1164,12 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, { struct mlx5_cmd *cmd = &dev->cmd; struct mlx5_cmd_work_ent *ent; - mlx5_cmd_cbk_t callback; - void *context; - int err; int i; - struct semaphore *sem; - s64 ds; - struct mlx5_cmd_stats *stats; - unsigned long flags; while (vector != 0) { i = ffs(vector) - 1; vector &= ~(1U << i); ent = cmd->ent_arr[i]; - if (ent->page_queue) - sem = &cmd->pages_sem; - else - sem = &cmd->sem; ent->ts2 = ktime_get_ns(); memcpy(ent->out->first.data, ent->lay->out, sizeof(ent->lay->out)); @@ -1142,33 +1187,7 @@ void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, ent->status); } free_ent(cmd, ent->idx); - if (ent->callback) { - ds = ent->ts2 - ent->ts1; - if (ent->op < ARRAY_SIZE(cmd->stats)) { - stats = &cmd->stats[ent->op]; - spin_lock_irqsave(&stats->lock, flags); - stats->sum += ds; - ++stats->n; - spin_unlock_irqrestore(&stats->lock, flags); - } - - callback = ent->callback; - context = ent->context; - err = ent->ret; - if (!err) - err = mlx5_copy_from_msg(ent->uout, - ent->out, - ent->uout_size); - - mlx5_free_cmd_msg(dev, ent->out); - free_msg(dev, ent->in); - - free_cmd(ent); - callback(err, context); - } else { - complete(&ent->done); - } - up(sem); + complete_command(ent); } } EXPORT_SYMBOL(mlx5_cmd_comp_handler);