Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp592069ima; Wed, 6 Feb 2019 05:20:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IY4GQqfm5Tweoy7h5QYMGvTHhWWa8vAPXDiJes/l9GTxeCQJQ3grOgtthcbylCGMSf6s6j7 X-Received: by 2002:aa7:84d3:: with SMTP id x19mr10458395pfn.220.1549459240217; Wed, 06 Feb 2019 05:20:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549459240; cv=none; d=google.com; s=arc-20160816; b=y0ayn1GzS4dCMu2SnOgPokBRzjpUfvrm7Rzv2uxc1OM6Pq0ccA5OZLwA4HZ2bNHGaS wf754jSQdayTc3g++gjMaY1+na8khIJLPa/dxPE/9O4veYQcl/8ClzIAUfLSfnNhbbUi D0zYhBjO9gTtdmH9UKijHgMVbKK402pkCshllqPJNCkcDyihLvfHO+DYx9T3K4DkFTRl Xs9E2rP1obF8fUyvsCjFEeL2EYBDiapq6/0rIRmEhtcjg8UJc/vka5CKUvHNflvq86b0 /jUZpzw5BbMu7NmrbKCjKSUI1sl85ELbc2Bg6H8gtEjQaH6VrHDAeJltw98ogvm0XShM qYtg== 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=MKzCCRQIJdcfYAp7Rfp+fLSuwcSkxjfnNUuyYM68/Hg=; b=y8a6V1CK3OB8qxTiFOX3MFaeISdJj7jkYnjX8Ak+JzG7qrjMyBU5XV3iObIA5uVWnV 6Q4QbZxc4hXs+nXmB9awMeYIpsxeILg/LG+HGwfxXvhQkjwSvCFY+FM83uPoDWkdm/m7 s9eUaq0V184i2ePlCJaGRbf2LoIk3JvfZASh+H+4hU/xL2+rqykr8/ml+tP2KBF0nhOp t8A86UcippT3dktQ6wa/bAAIjoZWEGgIpObD09C6FuW93Dz24S7vVwBF0xnccAUoVBWm qCuf/CA1oKsZnVWhsq0GIfSNwS/JaYzRi8B+SfCp5D0DyhhPc3UWUT1Q1vkZfFxLoMsd AgFg== 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 u69si3853791pfj.219.2019.02.06.05.20.24; Wed, 06 Feb 2019 05:20:40 -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 S1730903AbfBFNTN (ORCPT + 99 others); Wed, 6 Feb 2019 08:19:13 -0500 Received: from mga11.intel.com ([192.55.52.93]:7185 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729596AbfBFNRt (ORCPT ); Wed, 6 Feb 2019 08:17:49 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2019 05:17:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,340,1544515200"; d="scan'208";a="297674117" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 06 Feb 2019 05:17:46 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 56D1589F; Wed, 6 Feb 2019 15:17:39 +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 v2 20/28] thunderbolt: Rework NFC credits handling Date: Wed, 6 Feb 2019 16:17:30 +0300 Message-Id: <20190206131738.43696-21-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206131738.43696-1-mika.westerberg@linux.intel.com> References: <20190206131738.43696-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 29bf9119e0ae..7cc1f534e776 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