Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4759446imu; Tue, 29 Jan 2019 07:05:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN7oBg5Y6DnAoBxOFUPuTHNA9qAAFsZiQWtytK2UbiRfaQ78STUQIVII0J0n7cwmUOaXduOd X-Received: by 2002:a17:902:9a81:: with SMTP id w1mr25321729plp.19.1548774349948; Tue, 29 Jan 2019 07:05:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548774349; cv=none; d=google.com; s=arc-20160816; b=bZQvB8s+1CX4/NG6/USSUn3+CuigQYuY0oF/MN3jculabUh7imPBZ49k7EcBWzFnIl Ly4j+yXEumVNKfL8S9BmAPO3UUXRy3w5Q0b360I4uzGY31aVVf/aCI9WjBoIBuwm8/eQ y6VL/4hn5pU33O/sciRNHvkVGu6JSqRhjVTLkHGhMJUIXUfql7km0A3i9fJ/ktZiMkU8 /pA9L49rr5izI9LLFZVxlc3LVfzySrqVYjQXcSlJO+llFEYp7KgzHKB1yQbgFao5oHC9 sN/i8u6Vz+V0lW3mSC2EMPweQROHV8hzpeFvhcEBSmOH6HQbO/bO3AKt8/WhfGPw62t5 0IuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lhbm8l6k0WjmHMg/3cWlkhb9WYsvSQFwqsSzo9sFTrw=; b=K40nHtJ0910pBXWhN1G7LLoTrxs0prt/+hPW70DTwjaHrEvvY61qmUX+oFMUfcTFoF 5Y4MNP/2MATcr860ZcgVrJu4LLnLiCnzZoBHrhphzC5q72ZSTHFbUHW5v2kdSMIZ5Gjk 62Wv92tjX7JHuB6ZjNRq6Wt6sp3kFa2uQGf0QR4BKH6Jrh1ttLPNM0B8yloTAHWJwOyu y79EScgtBbt2nLIPXMVIOiXFGK9dMs5ImiIrTAZLgRs4a8YbXDKzm40/vjjDg7RTzekB jcse8DhUAVXR0hykmlEGx77nd9kZx5bK5hD0cDVHLTR52mSrBou/8BekQZ2DndcGRiJT XACA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i39si37652332plb.256.2019.01.29.07.05.28; Tue, 29 Jan 2019 07:05:49 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729104AbfA2PES (ORCPT + 99 others); Tue, 29 Jan 2019 10:04:18 -0500 Received: from mga06.intel.com ([134.134.136.31]:3058 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728347AbfA2PBy (ORCPT ); Tue, 29 Jan 2019 10:01:54 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2019 07:01:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,537,1539673200"; d="scan'208";a="110723796" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 29 Jan 2019 07:01:51 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 2D270ABF; Tue, 29 Jan 2019 17:01:45 +0200 (EET) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , Mika Westerberg , Andy Shevchenko , netdev@vger.kernel.org Subject: [PATCH 20/28] thunderbolt: Rework NFC credits handling Date: Tue, 29 Jan 2019 18:01:35 +0300 Message-Id: <20190129150143.12681-21-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129150143.12681-1-mika.westerberg@linux.intel.com> References: <20190129150143.12681-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org NFC (non flow control) credits is actually 20-bit field so update tb_port_add_nfc_credits() to handle this properly. This allows us to set NFC credits for Display Port path in subsequent patches. Also make sure the function does not update the hardware if the underlying switch is already unplugged. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/switch.c | 20 +++++++++++++------- drivers/thunderbolt/tb_regs.h | 3 +++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index de69ada9a2f7..42681431eb7e 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -544,14 +544,20 @@ int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged) */ int tb_port_add_nfc_credits(struct tb_port *port, int credits) { - if (credits == 0) + u32 nfc_credits; + + if (credits == 0 || port->sw->is_unplugged) return 0; - tb_port_info(port, - "adding %#x NFC credits (%#x -> %#x)", - credits, - port->config.nfc_credits, - port->config.nfc_credits + credits); - port->config.nfc_credits += credits; + + nfc_credits = port->config.nfc_credits & TB_PORT_NFC_CREDITS_MASK; + nfc_credits += credits; + + tb_port_dbg(port, "adding %d NFC credits to %lu", + credits, port->config.nfc_credits & TB_PORT_NFC_CREDITS_MASK); + + port->config.nfc_credits &= ~TB_PORT_NFC_CREDITS_MASK; + port->config.nfc_credits |= nfc_credits; + return tb_port_write(port, &port->config.nfc_credits, TB_CFG_PORT, 4, 1); } diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h index 75e935acade5..74c0f4a5606d 100644 --- a/drivers/thunderbolt/tb_regs.h +++ b/drivers/thunderbolt/tb_regs.h @@ -211,6 +211,9 @@ struct tb_regs_port_header { } __packed; +/* DWORD 4 */ +#define TB_PORT_NFC_CREDITS_MASK GENMASK(19, 0) + /* PCIe adapter registers */ #define TB_PCI_EN BIT(31) -- 2.20.1