Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8114687ybn; Tue, 1 Oct 2019 03:30:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2x8AVhZ5TOVYWSa/pzaz2l2T0iQ5IF0YbJJpX5HunRC0pvJLkGYIW6GkO0KrEOlxbYNOZ X-Received: by 2002:aa7:d816:: with SMTP id v22mr25364144edq.28.1569925819436; Tue, 01 Oct 2019 03:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569925819; cv=none; d=google.com; s=arc-20160816; b=awqsQx2Y/dHzhlsbWKz4VMi+BbvjkQq+zgtkFzLFqrrSC231kO7aEKqb/W1LbwQx9x sLz6xa9wozK6VwM9sx1gme3MMxxfWtEDULukLQsZbTkI1/Gf7SySoj/ezsYJugfoKCYS c7JMvhQCswGeTPArvvUrqXqQyZKjq38EI5hpFYVfSR6u63b9/pscELIPreUrIhD6YKkc arfGWIJ/VBCtcS89yBxtFytTQ3bWt0/57LvbAVRPLq0h6Anr8C7Q7gSctYLEcLukI4vo 2cwlxKuoFfvW05pTJ5RNTAwxADtRjKeOhhHJnMSniPiozpzvLCguEOgSNBnEEMJYh2Mk FR3g== 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=ayO6SWxjHQD+VE1PIxB20g4Dbp+Q+kWAdgCx4gXUcjg=; b=cCpDSsx7e9tDvEmEXnklmAJ5qHJyxXLXBgPH8GOr4mIcrs9OdH9eYH6lw4wEp8v0VR PeXcKK2MbDhcj0eaY0q2Tn9C0KZwcEeOWfj9WgcJG2fKN4bNTbKdH7p2nVEItezUAb5O rfPY2NkCNf41yII6W6WaqOcByMnvEmvqn47GlAD4wbCzk74O6XGeghCQbHv42k0rPkCn 97VBh9apgvpsPyv0+B6gQK64LAiQzjuK3BRbNDtecKST7Qq8XOyc5iBC74X1cBkrEqcj J4VmGy0ukjUZkWy7fMfrcWQ4+2CuaOYv1Q4tb+wh4METgHCl3lKMFufkB8nkgDX9HXyl wiTQ== 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 e22si8332086eda.300.2019.10.01.03.29.55; Tue, 01 Oct 2019 03:30:19 -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 S1730583AbfJAK3U (ORCPT + 99 others); Tue, 1 Oct 2019 06:29:20 -0400 Received: from mga17.intel.com ([192.55.52.151]:22449 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730006AbfJAK3T (ORCPT ); Tue, 1 Oct 2019 06:29:19 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Oct 2019 03:29:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,570,1559545200"; d="scan'208";a="194490173" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 01 Oct 2019 03:29:06 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 1214F130; Tue, 1 Oct 2019 13:29:06 +0300 (EEST) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Andreas Noever , Michael Jamet , Yehezkel Bernat , Mika Westerberg , Lukas Wunner , Brad Campbell , Dominik Brodowski , Bjorn Helgaas , Nicholas Johnson , linux-pci@vger.kernel.org Subject: [PATCH 1/3] thunderbolt: Read DP IN adapter first two dwords in one go Date: Tue, 1 Oct 2019 13:29:03 +0300 Message-Id: <20191001102905.21680-2-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191001102905.21680-1-mika.westerberg@linux.intel.com> References: <20191001102905.21680-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 When we discover existing DP tunnels the code checks whether DP IN adapter port is enabled by calling tb_dp_port_is_enabled() before it continues the discovery process. On Light Ridge (gen 1) controller reading only the first dword of the DP IN config space causes subsequent access to the same DP IN port path config space to fail or return invalid data as can be seen in the below splat: thunderbolt 0000:07:00.0: CFG_ERROR(0:d): Invalid config space or offset Call Trace: tb_cfg_read+0xb9/0xd0 __tb_path_deactivate_hop+0x98/0x210 tb_path_activate+0x228/0x7d0 tb_tunnel_restart+0x95/0x200 tb_handle_hotplug+0x30e/0x630 process_one_work+0x1b4/0x340 worker_thread+0x44/0x3d0 kthread+0xeb/0x120 ? process_one_work+0x340/0x340 ? kthread_park+0xa0/0xa0 ret_from_fork+0x1f/0x30 If both DP In adapter config dwords are read in one go the issue does not reproduce. This is likely firmware bug but we can work it around by always reading the two dwords in one go. There should be no harm for other controllers either so can do it unconditionally. Link: https://lkml.org/lkml/2019/8/28/160 Reported-by: Brad Campbell Signed-off-by: Mika Westerberg --- drivers/thunderbolt/switch.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 410bf1bceeee..8e712fbf8233 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -896,12 +896,13 @@ int tb_dp_port_set_hops(struct tb_port *port, unsigned int video, */ bool tb_dp_port_is_enabled(struct tb_port *port) { - u32 data; + u32 data[2]; - if (tb_port_read(port, &data, TB_CFG_PORT, port->cap_adap, 1)) + if (tb_port_read(port, data, TB_CFG_PORT, port->cap_adap, + ARRAY_SIZE(data))) return false; - return !!(data & (TB_DP_VIDEO_EN | TB_DP_AUX_EN)); + return !!(data[0] & (TB_DP_VIDEO_EN | TB_DP_AUX_EN)); } /** @@ -914,19 +915,21 @@ bool tb_dp_port_is_enabled(struct tb_port *port) */ int tb_dp_port_enable(struct tb_port *port, bool enable) { - u32 data; + u32 data[2]; int ret; - ret = tb_port_read(port, &data, TB_CFG_PORT, port->cap_adap, 1); + ret = tb_port_read(port, data, TB_CFG_PORT, port->cap_adap, + ARRAY_SIZE(data)); if (ret) return ret; if (enable) - data |= TB_DP_VIDEO_EN | TB_DP_AUX_EN; + data[0] |= TB_DP_VIDEO_EN | TB_DP_AUX_EN; else - data &= ~(TB_DP_VIDEO_EN | TB_DP_AUX_EN); + data[0] &= ~(TB_DP_VIDEO_EN | TB_DP_AUX_EN); - return tb_port_write(port, &data, TB_CFG_PORT, port->cap_adap, 1); + return tb_port_write(port, data, TB_CFG_PORT, port->cap_adap, + ARRAY_SIZE(data)); } /* switch utility functions */ -- 2.23.0