Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2984890imm; Sun, 1 Jul 2018 09:42:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLH1TqUt3S8YsLalDapKKFIAOVDXZybe07/3chj2+njzjlAQNMV0830N/WIX3JtwhFGylSK X-Received: by 2002:a63:8f53:: with SMTP id r19-v6mr18692746pgn.17.1530463369037; Sun, 01 Jul 2018 09:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530463369; cv=none; d=google.com; s=arc-20160816; b=icbE+XIJAQZ/5zNMxfE2oiNTI30cGZDOqHVh3AMAH/zKnqYKOASlbYpqELADar9T3+ qvkRx1pn72oySMJyeLNe/AMj7cyu7uNuuoVOKcP4Jq+L0c8ks1LE/j0OpcAzAFEq6e8o flz2utkIAmgQYHrG40Jwk6W5yAERVTMAdKskpaayS1fZCzB2Ledb+tjl437Y4jBS3/Ul /KrOtFe4Nl8fu8EjNWGrasx6xlq0lQcwtRUgwnrU4kv4GCaU4Vz9nuq9dy4qvY9gOwBa 3ZEJlnVK6CRFnNjFEhYymLU61MV+ufLHrYGQ3v6WWZw0cLlCJbpxsxC/HROIir8yI3gI tLDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=j8Gtd4iYhLG4JRpRyGEJSfFyEC2k6+ZwrkVogNE3gR4=; b=Mh7DA60DA/xneBYNZPQWOPB1Eja0t6G4ecg361CQyd2mts9r8J41o043nxlcTD/Z4I dxvYdq7rfdQeIMwd7K/BjbPZrA8LTp/oJAA1meILhTNDL27tMMh/HY+WPjHHDlX4RVEz 3cDj2k8OjD7MRok30GsChvnWlquggfa32ay/Oa+uccir7cfhUGM5bZJFMnr1aip75I6x AWQQWChoEJbnbZI2lv+AT51JzfIxCKM1PdFwdPmZ5iZY/d/fXT4tUUB8F/iovAiOFlLd DdK2qeYYgAwhFLOOn3LvC1nVvzEXgwqGPNZwhxDPC2ITF/iK//Na/2DzqsOWLlmj3//e BStw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si12619207pgs.221.2018.07.01.09.42.34; Sun, 01 Jul 2018 09:42:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031973AbeGAQkw (ORCPT + 99 others); Sun, 1 Jul 2018 12:40:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37242 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031642AbeGAQkq (ORCPT ); Sun, 1 Jul 2018 12:40:46 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A1128AA6; Sun, 1 Jul 2018 16:40:45 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mitko Haralanov , Mike Marciniszyn , "Michael J. Ruhl" , Dennis Dalessandro , Doug Ledford Subject: [PATCH 4.17 092/220] IB/hfi1: Reorder incorrect send context disable Date: Sun, 1 Jul 2018 18:21:56 +0200 Message-Id: <20180701160912.254730412@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701160908.272447118@linuxfoundation.org> References: <20180701160908.272447118@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael J. Ruhl commit a93a0a31111231bb1949f4a83b17238f0fa32d6a upstream. User send context integrity bits are cleared before the context is disabled. If the send context is still processing data, any packets that need those integrity bits will cause an error and halt the send context. During the disable handling, the driver waits for the context to drain. If the context is halted, the driver will eventually timeout because the context won't drain and then incorrectly bounce the link. Reorder the bit clearing and the context disable. Examine the software state and send context status as well as the egress status to determine if a send context is in the halted state. Promote the check macros to static functions for consistency with the new check and to follow kernel style. Remove an unused define that refers to the egress timeout. Cc: # 4.9.x Reviewed-by: Mitko Haralanov Reviewed-by: Mike Marciniszyn Signed-off-by: Michael J. Ruhl Signed-off-by: Dennis Dalessandro Signed-off-by: Doug Ledford Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/hfi1/file_ops.c | 2 - drivers/infiniband/hw/hfi1/pio.c | 44 ++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -689,8 +689,8 @@ static int hfi1_file_close(struct inode * checks to default and disable the send context. */ if (uctxt->sc) { - set_pio_integrity(uctxt->sc); sc_disable(uctxt->sc); + set_pio_integrity(uctxt->sc); } hfi1_free_ctxt_rcv_groups(uctxt); --- a/drivers/infiniband/hw/hfi1/pio.c +++ b/drivers/infiniband/hw/hfi1/pio.c @@ -50,8 +50,6 @@ #include "qp.h" #include "trace.h" -#define SC_CTXT_PACKET_EGRESS_TIMEOUT 350 /* in chip cycles */ - #define SC(name) SEND_CTXT_##name /* * Send Context functions @@ -961,15 +959,40 @@ void sc_disable(struct send_context *sc) } /* return SendEgressCtxtStatus.PacketOccupancy */ -#define packet_occupancy(r) \ - (((r) & SEND_EGRESS_CTXT_STATUS_CTXT_EGRESS_PACKET_OCCUPANCY_SMASK)\ - >> SEND_EGRESS_CTXT_STATUS_CTXT_EGRESS_PACKET_OCCUPANCY_SHIFT) +static u64 packet_occupancy(u64 reg) +{ + return (reg & + SEND_EGRESS_CTXT_STATUS_CTXT_EGRESS_PACKET_OCCUPANCY_SMASK) + >> SEND_EGRESS_CTXT_STATUS_CTXT_EGRESS_PACKET_OCCUPANCY_SHIFT; +} /* is egress halted on the context? */ -#define egress_halted(r) \ - ((r) & SEND_EGRESS_CTXT_STATUS_CTXT_EGRESS_HALT_STATUS_SMASK) +static bool egress_halted(u64 reg) +{ + return !!(reg & SEND_EGRESS_CTXT_STATUS_CTXT_EGRESS_HALT_STATUS_SMASK); +} + +/* is the send context halted? */ +static bool is_sc_halted(struct hfi1_devdata *dd, u32 hw_context) +{ + return !!(read_kctxt_csr(dd, hw_context, SC(STATUS)) & + SC(STATUS_CTXT_HALTED_SMASK)); +} -/* wait for packet egress, optionally pause for credit return */ +/** + * sc_wait_for_packet_egress + * @sc: valid send context + * @pause: wait for credit return + * + * Wait for packet egress, optionally pause for credit return + * + * Egress halt and Context halt are not necessarily the same thing, so + * check for both. + * + * NOTE: The context halt bit may not be set immediately. Because of this, + * it is necessary to check the SW SFC_HALTED bit (set in the IRQ) and the HW + * context bit to determine if the context is halted. + */ static void sc_wait_for_packet_egress(struct send_context *sc, int pause) { struct hfi1_devdata *dd = sc->dd; @@ -981,8 +1004,9 @@ static void sc_wait_for_packet_egress(st reg_prev = reg; reg = read_csr(dd, sc->hw_context * 8 + SEND_EGRESS_CTXT_STATUS); - /* done if egress is stopped */ - if (egress_halted(reg)) + /* done if any halt bits, SW or HW are set */ + if (sc->flags & SCF_HALTED || + is_sc_halted(dd, sc->hw_context) || egress_halted(reg)) break; reg = packet_occupancy(reg); if (reg == 0)