From patchwork Tue Dec 20 09:13:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selvin Xavier X-Patchwork-Id: 9481291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4BDAF60820 for ; Tue, 20 Dec 2016 09:15:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35FFF283E5 for ; Tue, 20 Dec 2016 09:15:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AF5F28475; Tue, 20 Dec 2016 09:15:09 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 6B52D2845D for ; Tue, 20 Dec 2016 09:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933821AbcLTJPC (ORCPT ); Tue, 20 Dec 2016 04:15:02 -0500 Received: from mail-qt0-f182.google.com ([209.85.216.182]:34391 "EHLO mail-qt0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933816AbcLTJO7 (ORCPT ); Tue, 20 Dec 2016 04:14:59 -0500 Received: by mail-qt0-f182.google.com with SMTP id n6so171305825qtd.1 for ; Tue, 20 Dec 2016 01:14:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tQg8t3LAt4RZoZoHELh+QOu+ol8B7Flr/E5iXKL+rqw=; b=RZ49mQcJdVdl8Z2BiWMhHQ59OWhxgYmBgCFArVxA5wbYXFXXZqf2xn0vhnfHtoMdgB Awfc6am2qM3ve80XL9gVsOy+xRD79QG+puxWW64X4PFQser94bwCwCcSltDTnjsY4MuN vhOHXw6Nqq0XN7IKn8dCbukcNUsQhAfPWcSKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tQg8t3LAt4RZoZoHELh+QOu+ol8B7Flr/E5iXKL+rqw=; b=qIgpx1jEyX3qhLWVZnO8BrYGOGOG/L6sToMZONZQLgfDOtbKQbfh+lVfe9mtUdq2Ik hSjHrBwTJ6b/YmkKjueyimih1mY/W5nw/glMXmtTNUO1zEb8IQTj9pXemZxe0ZQbz3L5 epy33RHlCLgCP09TskPCvB+7NEfAFDp6cWiyAs4bskWZrUhSAIrPRqKChztufSdeAgBn s14jNAmIQEnkniEBP3tVHEvo8yXnBSF2rverHVpGy73pCsRU2AtKCXEjc3BeMCkwkiOQ 55QR/cEErffFmbVmbGP3a/du7Mic+3ToygRpaobNEMJDBH15OlNXvVFhQsC3fRReIm8t ok1g== X-Gm-Message-State: AIkVDXKknQnC6XtZ94Ig1E47uQ4KbVT5QQLAkGi4nEj0nVWkSDe5wy/ZkeOuw5mxQ97JTCik X-Received: by 10.200.42.232 with SMTP id c37mr20731211qta.145.1482225298711; Tue, 20 Dec 2016 01:14:58 -0800 (PST) Received: from dhcp-10-192-206-197.iig.avagotech.net ([192.19.239.250]) by smtp.gmail.com with ESMTPSA id b63sm12494452qka.39.2016.12.20.01.14.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Dec 2016 01:14:58 -0800 (PST) From: Selvin Xavier To: dledford@redhat.com, linux-rdma@vger.kernel.org Cc: netdev@vger.kernel.org, michael.chan@broadcom.com, Selvin Xavier , Eddie Wai , Devesh Sharma , Somnath Kotur , Sriharsha Basavapatna Subject: [PATCH for bnxt_re V3 17/21] bnxt_re: Handling dispatching of events to IB stack Date: Tue, 20 Dec 2016 01:13:27 -0800 Message-Id: <1482225211-22423-18-git-send-email-selvin.xavier@broadcom.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1482225211-22423-1-git-send-email-selvin.xavier@broadcom.com> References: <1482225211-22423-1-git-send-email-selvin.xavier@broadcom.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 This patch implements events dispatching to the IB stack based on NETDEV events received. v2: Removed cleanup of the resources during driver unload since we are calling unregister_netdevice_notifier first in the exit. v3: Fixes cocci warnings and some sparse warnings Signed-off-by: Eddie Wai Signed-off-by: Devesh Sharma Signed-off-by: Somnath Kotur Signed-off-by: Sriharsha Basavapatna Signed-off-by: Selvin Xavier --- drivers/infiniband/hw/bnxtre/bnxt_re_main.c | 65 +++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/infiniband/hw/bnxtre/bnxt_re_main.c b/drivers/infiniband/hw/bnxtre/bnxt_re_main.c index a44b360..3a45b53 100644 --- a/drivers/infiniband/hw/bnxtre/bnxt_re_main.c +++ b/drivers/infiniband/hw/bnxtre/bnxt_re_main.c @@ -729,6 +729,60 @@ static int bnxt_re_alloc_res(struct bnxt_re_dev *rdev) return rc; } +static void bnxt_re_dispatch_event(struct ib_device *ibdev, struct ib_qp *qp, + u8 port_num, enum ib_event_type event) +{ + struct ib_event ib_event; + + ib_event.device = ibdev; + if (qp) + ib_event.element.qp = qp; + else + ib_event.element.port_num = port_num; + ib_event.event = event; + ib_dispatch_event(&ib_event); +} + +static bool bnxt_re_is_qp1_or_shadow_qp(struct bnxt_re_dev *rdev, + struct bnxt_re_qp *qp) +{ + return (qp->ib_qp.qp_type == IB_QPT_GSI) || (qp == rdev->qp1_sqp); +} + +static void bnxt_re_dev_stop(struct bnxt_re_dev *rdev, bool qp_wait) +{ + int mask = IB_QP_STATE, qp_count, count = 1; + struct ib_qp_attr qp_attr; + struct bnxt_re_qp *qp; + + qp_attr.qp_state = IB_QPS_ERR; + mutex_lock(&rdev->qp_lock); + list_for_each_entry(qp, &rdev->qp_list, list) { + /* Modify the state of all QPs except QP1/Shadow QP */ + if (!bnxt_re_is_qp1_or_shadow_qp(rdev, qp)) { + if (qp->qplib_qp.state != + CMDQ_MODIFY_QP_NEW_STATE_RESET && + qp->qplib_qp.state != + CMDQ_MODIFY_QP_NEW_STATE_ERR) { + bnxt_re_dispatch_event(&rdev->ibdev, &qp->ib_qp, + 1, IB_EVENT_QP_FATAL); + bnxt_re_modify_qp(&qp->ib_qp, &qp_attr, mask, + NULL); + } + } + } + + mutex_unlock(&rdev->qp_lock); + if (qp_wait) { + /* Give the application some time to clean up */ + do { + qp_count = atomic_read(&rdev->qp_count); + msleep(100); + } while ((qp_count != atomic_read(&rdev->qp_count)) && + count--); + } +} + static void bnxt_re_ib_unreg(struct bnxt_re_dev *rdev, bool lock_wait) { int i, rc; @@ -888,6 +942,9 @@ static int bnxt_re_ib_reg(struct bnxt_re_dev *rdev) } } set_bit(BNXT_RE_FLAG_IBDEV_REGISTERED, &rdev->flags); + bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, IB_EVENT_PORT_ACTIVE); + bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, IB_EVENT_GID_CHANGE); + return 0; free_sctx: bnxt_re_net_stats_ctx_free(rdev, rdev->qplib_ctx.stats.fw_id, true); @@ -967,10 +1024,18 @@ static void bnxt_re_task(struct work_struct *work) "Failed to register with IB: %#x", rc); break; case NETDEV_UP: + bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, + IB_EVENT_PORT_ACTIVE); break; case NETDEV_DOWN: + bnxt_re_dev_stop(rdev, false); break; case NETDEV_CHANGE: + if (!netif_carrier_ok(rdev->netdev)) + bnxt_re_dev_stop(rdev, false); + else if (netif_carrier_ok(rdev->netdev)) + bnxt_re_dispatch_event(&rdev->ibdev, NULL, 1, + IB_EVENT_PORT_ACTIVE); break; default: break;