Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4758990imu; Tue, 29 Jan 2019 07:05:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN5o9gqGJ7aX+8eMSJTFuANdL0k4gIJ1RnXpTeGnW6sRYIRePTYE33OnotsVTHEu9KfkarK4 X-Received: by 2002:a62:c101:: with SMTP id i1mr26499782pfg.80.1548774327556; Tue, 29 Jan 2019 07:05:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548774327; cv=none; d=google.com; s=arc-20160816; b=rClUq0c1Z0oYfeLgmlcHlEtDdpqn0pbM5Sj+jOPrnsFjBUxDHPL+9e2AU1thH6PZrp /xbK5Lf+YBb+ATmGh+4aHy3wAMqbzRkMO0ny0WDV3LouV22H27dxyvNReGeuMl3PEYFp dRJ5zOso48PstdWhqF8wtj+sEKfiBDfRTj9URTEyZsykJpGU9ZPspxxfOoE9pEVI7T0W nPe6pbuABC0Ipr0CnJTvQ+lFWBRc82/MwDXy7b38BmLZ2+bDxdhpFCZY2xhyqcaCnZdx sU5X4IzanzY/MXZC0kGGpy1haC6wsUespxazGuEzcKkhQwj41COKy5sPEeU4xrqRHj07 kVhQ== 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=T13LC7tWyJL+7sVo5v9RgRtZERKzLR8uODMZDpBncC0=; b=c/AV0yxGlRko0Svwjc4eiwcmZu2MDwPewwHKHXTrVWQ2u/FqflT6A0UHw6kK2q2mtF GoZZJyUTfxFh9GLZhDwjyXh7D78gHpx+k/Zc6XcmzGOidvKYZvOrohwr3R8PTaCcucYZ BdbLG/RL29y/c8ohF2BYcyigC7MjJ1nc5HnyASt3qhcDmbRVjaiqi/b7dyNg7oI14YC0 txg3pr5ra9cVOavvMhB1whmezA+2KaFlCOJTRgXHBCqobxOCLhPQ6T2c2srWdjttkKNq 6Z/6ELpninl5XZhQtKb4T/W1mSVwP9ESLeSkdO08GPwfMbpbtSbVWnZfxhZs0iY0xMIH M0DA== 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 k5si10167837plt.111.2019.01.29.07.05.10; Tue, 29 Jan 2019 07:05:27 -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 S1729092AbfA2PEG (ORCPT + 99 others); Tue, 29 Jan 2019 10:04:06 -0500 Received: from mga06.intel.com ([134.134.136.31]:3065 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728376AbfA2PBy (ORCPT ); Tue, 29 Jan 2019 10:01:54 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2019 07:01:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,537,1539673200"; d="scan'208";a="110723799" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 29 Jan 2019 07:01:51 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 213D6A4F; Tue, 29 Jan 2019 17:01:45 +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 19/28] thunderbolt: Generalize port finding routines to support all port types Date: Tue, 29 Jan 2019 18:01:34 +0300 Message-Id: <20190129150143.12681-20-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 We will be needing these routines to find Display Port adapters as well so modify them to take port type as the second parameter. Signed-off-by: Mika Westerberg --- drivers/thunderbolt/switch.c | 16 ++++++++++++++++ drivers/thunderbolt/tb.c | 35 +++++++++++++++++------------------ drivers/thunderbolt/tb.h | 1 + 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index c1bab1bc7150..de69ada9a2f7 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -743,6 +743,22 @@ struct tb_port *tb_port_get_next(struct tb_port *start, struct tb_port *end, return next; } +/** + * tb_port_is_enabled() - Is the adapter port enabled + * @port: Port to check + */ +bool tb_port_is_enabled(struct tb_port *port) +{ + switch (port->config.type) { + case TB_TYPE_PCIE_UP: + case TB_TYPE_PCIE_DOWN: + return tb_pci_port_is_enabled(port); + + default: + return false; + } +} + /** * tb_pci_port_is_enabled() - Is the PCIe adapter port enabled * @port: PCIe port to check diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 1dcdf619d0f1..0df1d96e46f5 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -188,40 +188,39 @@ static void tb_free_unplugged_children(struct tb_switch *sw) } } - /** - * find_pci_up_port() - return the first PCIe up port on @sw or NULL + * tb_find_port() - return the first port of @type on @sw or NULL + * @sw: Switch to find the port from + * @type: Port type to look for */ -static struct tb_port *tb_find_pci_up_port(struct tb_switch *sw) +static struct tb_port *tb_find_port(struct tb_switch *sw, + enum tb_port_type type) { int i; for (i = 1; i <= sw->config.max_port_number; i++) - if (sw->ports[i].config.type == TB_TYPE_PCIE_UP) + if (sw->ports[i].config.type == type) return &sw->ports[i]; return NULL; } /** - * find_unused_down_port() - return the first inactive PCIe down port on @sw + * tb_find_unused_port() - return the first inactive port on @sw + * @sw: Switch to find the port on + * @type: Port type to look for */ -static struct tb_port *tb_find_unused_down_port(struct tb_switch *sw) +static struct tb_port *tb_find_unused_port(struct tb_switch *sw, + enum tb_port_type type) { int i; - int cap; - int res; - int data; + for (i = 1; i <= sw->config.max_port_number; i++) { if (tb_is_upstream_port(&sw->ports[i])) continue; - if (sw->ports[i].config.type != TB_TYPE_PCIE_DOWN) - continue; - cap = sw->ports[i].cap_adap; - if (cap < 0) + if (sw->ports[i].config.type != type) continue; - res = tb_port_read(&sw->ports[i], &data, TB_CFG_PORT, cap, 1); - if (res < 0) + if (sw->ports[i].cap_adap < 0) continue; - if (data & 0x80000000) + if (tb_port_is_enabled(&sw->ports[i])) continue; return &sw->ports[i]; } @@ -235,7 +234,7 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) struct tb_port *up, *down; struct tb_tunnel *tunnel; - up = tb_find_pci_up_port(sw); + up = tb_find_port(sw, TB_TYPE_PCIE_UP); if (!up) return 0; @@ -246,7 +245,7 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) down = NULL; parent_sw = tb_to_switch(sw->dev.parent); while (parent_sw) { - down = tb_find_unused_down_port(parent_sw); + down = tb_find_unused_port(parent_sw, TB_TYPE_PCIE_DOWN); if (down) break; parent_sw = tb_to_switch(parent_sw->dev.parent); diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index b3a422ab4b4e..bf5bc0fb0f8e 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -463,6 +463,7 @@ struct tb_port *tb_port_get_next(struct tb_port *start, struct tb_port *end, int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec); int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap); +bool tb_port_is_enabled(struct tb_port *port); bool tb_pci_port_is_enabled(struct tb_port *port); int tb_pci_port_enable(struct tb_port *port, bool enable); -- 2.20.1