Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4762657imu; Tue, 29 Jan 2019 07:08:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN4urqH1yhPgFmg7GsHQfnpTV0iz+CdsnWwOH78Cn4IRqLXQqDxdyQ34REaEhEN2QWxv0pY0 X-Received: by 2002:a62:178f:: with SMTP id 137mr26305435pfx.226.1548774503863; Tue, 29 Jan 2019 07:08:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548774503; cv=none; d=google.com; s=arc-20160816; b=jSOrrrdZAdBDRM78+o+qUJ/FGUKUGV0Z89KeCLgyYQyUv1WBTjbDZ1mHBpmXmDCGCK B61dCNzxmH2sNzqAGR0edwYjTnRCWhN+N3ABn2pyT78Iodg9gpHXAYUHaIpZkeX3+f10 /py09WMj7q1B10aaZs/pLLIrcQxkK0KJVxcHPWNUUi2gPG5eKg0NFrrJTxLrcSl8a+Pd mWc7bvGi638WUcr5AV3APR2l4d1RW/ybZqo/IBh+B5p2Yb+SC5aZWyN6odh/N4ge/xZs jO4kbnUOuiKgPb6+BDB8luPAk0sLPk4rY+MepgV1CIVu7Cf3nK0Z2cUJgJORW6IOk2Ub mw+w== 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=MmuPq6egWmFbfi8Apz1IDci6HNLEfncQ6R4R0/Qd2OM=; b=BbZa5c43JSWur6FkM+nbZ5C0QMQBoBpXJSYzTgiZdnn5Yf1nKnORKfjBCVuJ25GQMn mSJAjeMwJyrI8r+Bgl5hBcNuoX0sXEk2e+LUS/YLqJdPk75XJxSMP7YgGt1sF9u/H98e 3REnZxF1DP7+Wq44UAy5NVD9GxneCDCwxaORPepCW8N0vhcpTB+PzRhbS2/H0lCxYpWu 0yrEmamfcOEUxt5pc19dWr2qQTTVxGhHbE+VS8oN/peiGUkBLL5BBaAimKMA+ui/BEbK yblEXKg1mIVVdydsP1NhMx7aksy7lSBEDKsxHn7QJ6vvpmNhgYu6I98NXXC1teIk0pcD Nv5A== 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 y22si30961308pfa.6.2019.01.29.07.08.08; Tue, 29 Jan 2019 07:08:23 -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 S1728113AbfA2PBu (ORCPT + 99 others); Tue, 29 Jan 2019 10:01:50 -0500 Received: from mga09.intel.com ([134.134.136.24]:12289 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727772AbfA2PBs (ORCPT ); Tue, 29 Jan 2019 10:01:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2019 07:01:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,537,1539673200"; d="scan'208";a="118367165" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 29 Jan 2019 07:01:45 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 41632323; Tue, 29 Jan 2019 17:01:44 +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 03/28] thunderbolt: Enable TMU access when accessing port space on legacy devices Date: Tue, 29 Jan 2019 18:01:18 +0300 Message-Id: <20190129150143.12681-4-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 Light Ridge and Eagle Ridge both need to have TMU access enabled before port space can be fully accessed so make sure it happens on those. This allows us to get rid of the offset quirk in tb_port_find_cap(). Signed-off-by: Mika Westerberg --- drivers/thunderbolt/cap.c | 73 ++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/drivers/thunderbolt/cap.c b/drivers/thunderbolt/cap.c index 9553305c63ea..94a507f12b71 100644 --- a/drivers/thunderbolt/cap.c +++ b/drivers/thunderbolt/cap.c @@ -22,28 +22,43 @@ struct tb_cap_any { }; } __packed; -/** - * tb_port_find_cap() - Find port capability - * @port: Port to find the capability for - * @cap: Capability to look - * - * Returns offset to start of capability or %-ENOENT if no such - * capability was found. Negative errno is returned if there was an - * error. - */ -int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) +static int tb_port_enable_tmu(struct tb_port *port, bool enable) { - u32 offset; + struct tb_switch *sw = port->sw; + u32 value, offset; + int ret; /* - * DP out adapters claim to implement TMU capability but in - * reality they do not so we hard code the adapter specific - * capability offset here. + * Legacy devices need to have TMU access enabled before port + * space can be fully accessed. */ - if (port->config.type == TB_TYPE_DP_HDMI_OUT) - offset = 0x39; + switch (sw->config.device_id) { + case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE: + offset = 0x26; + break; + case PCI_DEVICE_ID_INTEL_EAGLE_RIDGE: + offset = 0x2a; + break; + + default: + return 0; + } + + ret = tb_sw_read(sw, &value, TB_CFG_SWITCH, offset, 1); + if (ret) + return ret; + + if (enable) + value |= BIT(20); else - offset = 0x1; + value &= ~BIT(20); + + return tb_sw_write(sw, &value, TB_CFG_SWITCH, offset, 1); +} + +static int __tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) +{ + u32 offset = 1; do { struct tb_cap_any header; @@ -62,6 +77,30 @@ int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) return -ENOENT; } +/** + * tb_port_find_cap() - Find port capability + * @port: Port to find the capability for + * @cap: Capability to look + * + * Returns offset to start of capability or %-ENOENT if no such + * capability was found. Negative errno is returned if there was an + * error. + */ +int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap) +{ + int ret; + + ret = tb_port_enable_tmu(port, true); + if (ret) + return ret; + + ret = __tb_port_find_cap(port, cap); + + tb_port_enable_tmu(port, false); + + return ret; +} + static int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap) { int offset = sw->config.first_cap_offset; -- 2.20.1