Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4761825imu; Tue, 29 Jan 2019 07:07:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN7nJJNcDfa3m6axBAUZuwCEu2wlhRS/ZiiR8/J4UAZcUvEXcxBs9IV9Jc/mdWX9CGb84sb8 X-Received: by 2002:a63:e615:: with SMTP id g21mr24380901pgh.290.1548774463609; Tue, 29 Jan 2019 07:07:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548774463; cv=none; d=google.com; s=arc-20160816; b=zj12lblEO/kq6AyXU0kjYUGfdxheIDaoYJj+/MHhI68pBy1UEPJKapHUPmrkQt1Y1G T7fw2LWJwRMEo7du2/Oti0XtRVdBQBADV3IDbNYOB5wP0oZLIcW+HDAOxx1gvlK9Grz6 ZlkC+/cxymb3QLfROrgfcYdtnVH+DPD7M9HEWPETq0JsYH40d6TcYSUqt2/n7EFTXMbe VRMfdteo0qW0MTt+DCSjScR8OOvHBl+U7Lng1EtANDMJxXzPxIo2JJTFB4kAPxlIKTqf rorYlt02eLxgUBvRgNNk1SqBKnDdYDiK9BG3f2jXBx23cOh0oqS74EVpXURwNMmkO60A 8mSg== 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=93zgyUxHJ2HzUDTYHS6aWinmFv5IM7ND7lwnCdxfQtM=; b=fdOOU0NDFXlL1fQSNZPeSfMrcCRUV98YpDBQP57qK/mljbuzeI0yaUP2f4Ja7sUJHQ 8lk9DY33Z/2yC+FxYQ15k8uBmOlq1t9WIYzsjmEp+30MCy3Cf/EC1vNLSKiahX6C4Jco h5rZQo1+MMpud9VOPyc4ZuMlZ5Mc8iy1CcDnItskUSVOvlEEoDkeRkc3g+ntul6K9taP K9MJtZpkDk0k57sCaNWPjA29R1wja5UmHghug2MMQHVpMVBlkJnyzqZ72WKh0+XOMHVa R9b+wdnAhU8v1BRaUjcBh6cqb9wfJP33XFp4jYdQj4XLpuOS4HpeF+ufptagmYFI47CO K+uA== 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 128si5460278pfe.4.2019.01.29.07.07.26; Tue, 29 Jan 2019 07:07:43 -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 S1729260AbfA2PFp (ORCPT + 99 others); Tue, 29 Jan 2019 10:05:45 -0500 Received: from mga12.intel.com ([192.55.52.136]:8099 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728186AbfA2PBv (ORCPT ); Tue, 29 Jan 2019 10:01:51 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2019 07:01:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,537,1539673200"; d="scan'208";a="314531724" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 29 Jan 2019 07:01:48 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 97136570; 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 09/28] thunderbolt: Cache adapter specific capability offset into struct port Date: Tue, 29 Jan 2019 18:01:24 +0300 Message-Id: <20190129150143.12681-10-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 The adapter specific capability either is there or not if the port does not hold an adapter. Instead of always finding it on-demand we read the offset just once when the port is initialized. While there we update the struct port documentation to follow kernel-doc format. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/switch.c | 4 ++++ drivers/thunderbolt/tb.c | 4 ++-- drivers/thunderbolt/tb.h | 3 +++ drivers/thunderbolt/tunnel_pci.c | 9 +++------ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 1eee2502b5ba..fcafe4095de5 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -585,6 +585,8 @@ static int tb_init_port(struct tb_port *port) if (res) return res; + port->cap_adap = -ENOENT; + /* Port 0 is the switch itself and has no PHY. */ if (port->config.type == TB_TYPE_PORT && port->port != 0) { cap = tb_port_find_cap(port, TB_PORT_CAP_PHY); @@ -593,6 +595,8 @@ static int tb_init_port(struct tb_port *port) port->cap_phy = cap; else tb_port_WARN(port, "non switch port without a PHY\n"); + } else if (port->port != 0) { + port->cap_adap = tb_port_find_cap(port, TB_PORT_CAP_ADAP); } tb_dump_port(port->sw->tb, &port->config); diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 30e02c716f6c..8e9761d950d6 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -151,7 +151,7 @@ static struct tb_port *tb_find_unused_down_port(struct tb_switch *sw) continue; if (sw->ports[i].config.type != TB_TYPE_PCIE_DOWN) continue; - cap = tb_port_find_cap(&sw->ports[i], TB_PORT_CAP_ADAP); + cap = sw->ports[i].cap_adap; if (cap < 0) continue; res = tb_port_read(&sw->ports[i], &data, TB_CFG_PORT, cap, 1); @@ -197,7 +197,7 @@ static void tb_activate_pcie_devices(struct tb *tb) } /* check whether port is already activated */ - cap = tb_port_find_cap(up_port, TB_PORT_CAP_ADAP); + cap = up_port->cap_adap; if (cap < 0) continue; if (tb_port_read(up_port, &data, TB_CFG_PORT, cap, 1)) diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index 3160169389cc..43a1d7dfba73 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -124,6 +124,8 @@ struct tb_switch { * @remote: Remote port (%NULL if not connected) * @xdomain: Remote host (%NULL if not connected) * @cap_phy: Offset, zero if not found + * @cap_adap: Offset of the adapter specific capability. Negative if not + * present. * @port: Port number on switch * @disabled: Disabled by eeprom * @dual_link_port: If the switch is connected using two ports, points @@ -136,6 +138,7 @@ struct tb_port { struct tb_port *remote; struct tb_xdomain *xdomain; int cap_phy; + int cap_adap; u8 port; bool disabled; struct tb_port *dual_link_port; diff --git a/drivers/thunderbolt/tunnel_pci.c b/drivers/thunderbolt/tunnel_pci.c index 0637537ea53f..4fae236a4a39 100644 --- a/drivers/thunderbolt/tunnel_pci.c +++ b/drivers/thunderbolt/tunnel_pci.c @@ -148,12 +148,9 @@ bool tb_pci_is_invalid(struct tb_pci_tunnel *tunnel) static int tb_pci_port_active(struct tb_port *port, bool active) { u32 word = active ? 0x80000000 : 0x0; - int cap = tb_port_find_cap(port, TB_PORT_CAP_ADAP); - if (cap < 0) { - tb_port_warn(port, "TB_PORT_CAP_ADAP not found: %d\n", cap); - return cap; - } - return tb_port_write(port, &word, TB_CFG_PORT, cap, 1); + if (port->cap_adap < 0) + return -ENXIO; + return tb_port_write(port, &word, TB_CFG_PORT, port->cap_adap, 1); } /** -- 2.20.1