Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp435843ybb; Thu, 28 Mar 2019 05:39:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkVFqOVHlHB7JF4/HJLeRC4U32AN/uE1RoBM9F3Qs3XsbsyqM5WhxbIzJCK9Y5gacrqAA9 X-Received: by 2002:a17:902:9884:: with SMTP id s4mr42807417plp.110.1553776766613; Thu, 28 Mar 2019 05:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553776766; cv=none; d=google.com; s=arc-20160816; b=usyf+YFJKK+BT+8o5xz1s2JufhYnwrXfBcqiNBKgGpJ+Ce8wAimvwiPEX2N3EXvkmL LLlK/hmhEKf+2cNqPnds5fKCOJAzXcoM/iPdn0h27HfcUtTzEWPxh98pKVNhJeld3k9e RO6KIdIBsERw5hjfqackD5tgEmB6G41TEprmr9BLyXBWTMoaluUzEYwBOXNWWdtsoc6o euABaL9FZsGcaKuX9yZ8MQyufbAXDrg8a6NHpaWqqT+vRN8DooKnqIvg6wDSm8qUdYvS EMTIu42t9jwoyktEDCqxZcts4OgdialVDESIf9/8mW1rYjLhsgNBXLGU0+ZVkPVBymgn DzbA== 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=5loyWdTxtpdB7Tf1GjiShB0/LOHFYTCNcxq2VnubhKQ=; b=Of6un9EuJo75z2ac96LsBA8rKqUpZZVapdwQC1eMuNQVNMxXwQxyL7SVnvQ0DXfyD3 hHQSFxR8qSFmmMPOwVqmwHpuRbscyA4JrxvJRvJ99Abc37+tu16C1shmHTG8+r5SMbhv Ssu5cYIXuUY9mRUK8YlcYHFOFDFaHbHu/b7rzq1bcjRD/wOfVPv9kL1FpPT69oS5alTf yJ0UI7OYLW5xg2qhoOiqUUXsqOo3EacIIHvkELzkg+wXFL0O04W3aKl615/qvCNAq89R plFa1GlJdq8OnlfenEXuN3/r3oS6MftAcTFV9Ly9kCUlUXzvUdEpZqUILvSbKCgWGSMm TOkg== 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 q3si12551753pgp.40.2019.03.28.05.39.10; Thu, 28 Mar 2019 05:39:26 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727723AbfC1MiF (ORCPT + 99 others); Thu, 28 Mar 2019 08:38:05 -0400 Received: from mga04.intel.com ([192.55.52.120]:9523 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727225AbfC1Mgq (ORCPT ); Thu, 28 Mar 2019 08:36:46 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2019 05:36:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,280,1549958400"; d="scan'208";a="286671461" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 28 Mar 2019 05:36:42 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 063C410F5; Thu, 28 Mar 2019 14:36:35 +0200 (EET) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , Andy Shevchenko , Christian Kellner , Mario.Limonciello@dell.com, Mika Westerberg , netdev@vger.kernel.org Subject: [PATCH v3 25/36] thunderbolt: Rework NFC credits handling Date: Thu, 28 Mar 2019 15:36:22 +0300 Message-Id: <20190328123633.42882-26-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190328123633.42882-1-mika.westerberg@linux.intel.com> References: <20190328123633.42882-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 028e9a293382..9462e6982061 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -537,14 +537,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