Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp436524ybb; Thu, 28 Mar 2019 05:40:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZM5LwxDNWENB6dVtf4yFb2VtgGP0IPjUZIlrSClc5MSn8PESLvmST+hqf7V0BTVNS+hT3 X-Received: by 2002:a17:902:421:: with SMTP id 30mr42205499ple.142.1553776815464; Thu, 28 Mar 2019 05:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553776815; cv=none; d=google.com; s=arc-20160816; b=IVOwXLt26zJPlL5ePwDRs4e8jxjYIVBFzxMwXqV5dtcI75W0C+WYSVNen2OgaWxucv P9Im8PXS41oX8bqHv+zI3+MKP6ZjIp06bXyl0OI6yqQLi8L/mhYzNluxSijl9RO9uKbl FBKOuRGHv5XDIsE1eDd0KxvMy7Z3lgFzVuaFq+xJue2wL+9lcww9RbRYJltSasJb/jRH wC+wUo7SaON2njV6I5jX4Jt8QfT2jcHHHDiGW+tP8ECMyEm/DYDP7YDuocqPJ5Vbiocl S37OcPf7Xs+th2gO7jR1L4BTIXQ3sypVhHH/V4PbVMAFDiyom1kuscPJqWJ9TCKykkFC QBFg== 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=nHpJvDDRzOKVLNf8Ly3WC2KUOt6tCKUKce2X2DURn7I=; b=rP9I3Brq5Qgyhvhfz2tbzfsOD/BOJkzZux0GWpkHQtUaVCz+SvXbv7x3lXbTArFRqP vIvBpqQ9EsTlZVXMQpX8D/yECYiByFQ1YHQ0YcDPl99h5tPtDSLxSxUhA5/C5N6I9Zw3 T/Yp6OBjKhP7g5jBSPrysVR3S5ZGO15NZT9t9SVNT6GL01vUqNFs8bssmgLkA3A73puu X/9Krv3HCDhkwzYULx0q1VpMON309nVOcABlZ76S6KyRmGvSl4rmJC8eJdnkchcPcb+M ypAz9Vi4Came4Q1dHopLB0JkxxmSQ5mbi205w3sW/gcIbYouiw0z+FIvTTPPAVAXpS7r HpcQ== 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 j188si21619683pfb.75.2019.03.28.05.39.59; Thu, 28 Mar 2019 05:40:15 -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 S1727758AbfC1Mi3 (ORCPT + 99 others); Thu, 28 Mar 2019 08:38:29 -0400 Received: from mga06.intel.com ([134.134.136.31]:31892 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727221AbfC1Mgq (ORCPT ); Thu, 28 Mar 2019 08:36:46 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2019 05:36:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,280,1549958400"; d="scan'208";a="331504637" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 28 Mar 2019 05:36:42 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id EE170FC6; Thu, 28 Mar 2019 14:36:34 +0200 (EET) From: Mika Westerberg To: linux-kernel@vger.kernel.org Cc: Michael Jamet , Yehezkel Bernat , Andreas Noever , Lukas Wunner , "David S . Miller" , Andy Shevchenko , Christian Kellner , Mario.Limonciello@dell.com, Mika Westerberg , netdev@vger.kernel.org Subject: [PATCH v3 24/36] thunderbolt: Generalize port finding routines to support all port types Date: Thu, 28 Mar 2019 15:36:21 +0300 Message-Id: <20190328123633.42882-25-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190328123633.42882-1-mika.westerberg@linux.intel.com> References: <20190328123633.42882-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 00aec2124f79..028e9a293382 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -730,6 +730,22 @@ struct tb_port *tb_next_port_on_path(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 fb01396a62a9..903922a16d64 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -180,40 +180,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) + 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) continue; - if (data & 0x80000000) + if (tb_port_is_enabled(&sw->ports[i])) continue; return &sw->ports[i]; } @@ -255,7 +254,7 @@ static struct tb_port *tb_find_pcie_down(struct tb_switch *sw, } out: - return tb_find_unused_down_port(sw); + return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN); } static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) @@ -265,7 +264,7 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) struct tb_switch *parent_sw; struct tb_tunnel *tunnel; - up = tb_find_pci_up_port(sw); + up = tb_find_port(sw, TB_TYPE_PCIE_UP); if (!up) return 0; diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index 5ca8be0db310..d802d8c5a953 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -546,6 +546,7 @@ struct tb_port *tb_next_port_on_path(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