From patchwork Fri Dec 14 16:05:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 10731823 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E15C11399 for ; Fri, 14 Dec 2018 23:37:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87C612AD56 for ; Fri, 14 Dec 2018 23:37:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B97B2D562; Fri, 14 Dec 2018 23:37:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DATE_IN_PAST_06_12, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1467A2AD56 for ; Fri, 14 Dec 2018 23:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728077AbeLNXhe (ORCPT ); Fri, 14 Dec 2018 18:37:34 -0500 Received: from opengridcomputing.com ([72.48.214.68]:47346 "EHLO smtp.opengridcomputing.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726423AbeLNXhe (ORCPT ); Fri, 14 Dec 2018 18:37:34 -0500 Received: by smtp.opengridcomputing.com (Postfix, from userid 503) id 29785227A9; Fri, 14 Dec 2018 17:37:34 -0600 (CST) Message-Id: <8ee7efc93c47cb6186834d4e17196238223cd2e6.1544826079.git.swise@opengridcomputing.com> In-Reply-To: References: From: Yuval Shaia Date: Fri, 14 Dec 2018 08:05:49 -0800 Subject: [PATCH v7 2/5] IB/rxe: Reuse code which sets port state MIME-Version: 1.0 To: dledford@redhat.com, jgg@mellanox.com Cc: linux-rdma@vger.kernel.org, BMT@zurich.ibm.com, leon@kernel.org, markb@mellanox.com, yanjun.zhu@oracle.com Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Same code is executed in both rxe_param_set_add and rxe_notify functions. Make one function and call it from both places. Note that the code that checks validity of rxe object is omitted since both callers already make sure it is valid. Signed-off-by: Yuval Shaia Reviewed-by: Steve Wise   Reviewed-by: Bart Van Assche --- drivers/infiniband/sw/rxe/rxe.h | 1 + drivers/infiniband/sw/rxe/rxe_net.c | 13 +++++++++---- drivers/infiniband/sw/rxe/rxe_sysfs.c | 12 +----------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h index 75e7113a756d..4ff33d921865 100644 --- a/drivers/infiniband/sw/rxe/rxe.h +++ b/drivers/infiniband/sw/rxe/rxe.h @@ -112,5 +112,6 @@ static inline struct rxe_dev *rxe_get_dev_from_net(struct net_device *ndev) void rxe_port_up(struct rxe_dev *rxe); void rxe_port_down(struct rxe_dev *rxe); +void rxe_set_port_state(struct net_device *ndev, struct rxe_dev *rxe); #endif /* RXE_H */ diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c index c7637ad5e584..6a25b514d448 100644 --- a/drivers/infiniband/sw/rxe/rxe_net.c +++ b/drivers/infiniband/sw/rxe/rxe_net.c @@ -577,6 +577,14 @@ void rxe_port_down(struct rxe_dev *rxe) dev_info(&rxe->ib_dev.dev, "set down\n"); } +void rxe_set_port_state(struct net_device *ndev, struct rxe_dev *rxe) +{ + if (netif_running(ndev) && netif_carrier_ok(ndev)) + rxe_port_up(rxe); + else + rxe_port_down(rxe); +} + static int rxe_notify(struct notifier_block *not_blk, unsigned long event, void *arg) @@ -603,10 +611,7 @@ static int rxe_notify(struct notifier_block *not_blk, rxe_set_mtu(rxe, ndev->mtu); break; case NETDEV_CHANGE: - if (netif_running(ndev) && netif_carrier_ok(ndev)) - rxe_port_up(rxe); - else - rxe_port_down(rxe); + rxe_set_port_state(ndev, rxe); break; case NETDEV_REBOOT: case NETDEV_GOING_DOWN: diff --git a/drivers/infiniband/sw/rxe/rxe_sysfs.c b/drivers/infiniband/sw/rxe/rxe_sysfs.c index 87c17675cf9d..de9f51056f52 100644 --- a/drivers/infiniband/sw/rxe/rxe_sysfs.c +++ b/drivers/infiniband/sw/rxe/rxe_sysfs.c @@ -53,16 +53,6 @@ static int sanitize_arg(const char *val, char *intf, int intf_len) return len; } -static void rxe_set_port_state(struct rxe_dev *rxe, struct net_device *ndev) -{ - bool is_up = netif_running(ndev) && netif_carrier_ok(ndev); - - if (is_up) - rxe_port_up(rxe); - else - rxe_port_down(rxe); /* down for unknown state */ -} - static int rxe_param_set_add(const char *val, const struct kernel_param *kp) { int len; @@ -99,7 +89,7 @@ static int rxe_param_set_add(const char *val, const struct kernel_param *kp) goto err; } - rxe_set_port_state(rxe, ndev); + rxe_set_port_state(ndev, rxe); dev_info(&rxe->ib_dev.dev, "added %s\n", intf); err: