Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp591208ima; Wed, 6 Feb 2019 05:19:54 -0800 (PST) X-Google-Smtp-Source: AHgI3IYcN88o7pUokgxQEAaStzrHOSXm2/N64teB4IW1+XyoIVrbs60n+lDZBuFx1u5UfECyOXPO X-Received: by 2002:a62:8c11:: with SMTP id m17mr10491428pfd.224.1549459194388; Wed, 06 Feb 2019 05:19:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549459194; cv=none; d=google.com; s=arc-20160816; b=z8lRE8yeHUntR8MiLNquy8F9hpAtc34O7AY9ppyhIfFdEVImJbtNyJnV1kWbpErnrU imLe12Hhm0kgd7shb1wTKd2RVxiEUP0BXxeZfyK5rB6sg8+JJnmlVermoc1OxShq6QLN MVnPe/aCC9g/Iza/1qwDv+S8vB17sV7byaxQRsuF1X6ux2NL/1tbsyGnAOBc1HnUKEg6 SpZwBafEGA50SzFqo/16JVzeJXr5MYjzl6GsV62WNtW2c8v3mKXrrJe6Wj+jnUOIrE6o +65t2FlnZ/ODEsurB1qQJW4YCN9XxyM1EGIGm15B193MPvZKYr1HNLkLqROic5ayHCWU NE5A== 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=TZKXmT4gUOZRsQNF7OujvFciUnXqzWKwq9OsyWfltfg=; b=KX3k79GUmJJ3zv/ZoFj0QuUk+ebV9D/CoGi8Y1TKlnd/HUOB+zfzhIzxdgCtbN2MKB U8eh0bxiUqJw3DfLKxWF/CNzXBl/ZUoV8qrwaJVGRop4XFPtBglYe+0a67SBZk3gAtiJ p2ph0ytgkKsizcmVWtiM+UD9XyocA1rC6Z/SN9tJwOxoypm98emb7PxR9YHI2z4Ttyc2 cUMBuskqNI2xoXvEeihGGiOLqbasEVytt5hsqos//SiNs8Rz7T8ynM948SvMP/V+l7Lj LM7LS44Q8zRnTRvlz7S2U6AZHwGre9tRvxWt45c3Trb/dMmdb7dtwfnU3D7J3rU2I8d/ +QVQ== 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 ce14si6380793plb.423.2019.02.06.05.19.38; Wed, 06 Feb 2019 05:19:54 -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 S1730868AbfBFNTB (ORCPT + 99 others); Wed, 6 Feb 2019 08:19:01 -0500 Received: from mga17.intel.com ([192.55.52.151]:45138 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730616AbfBFNRt (ORCPT ); Wed, 6 Feb 2019 08:17:49 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2019 05:17:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,340,1544515200"; d="scan'208";a="131998016" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 06 Feb 2019 05:17:45 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id 4C454884; Wed, 6 Feb 2019 15:17:39 +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 v2 19/28] thunderbolt: Generalize port finding routines to support all port types Date: Wed, 6 Feb 2019 16:17:29 +0300 Message-Id: <20190206131738.43696-20-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190206131738.43696-1-mika.westerberg@linux.intel.com> References: <20190206131738.43696-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 c6cb6c44a571..29bf9119e0ae 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 a450bebfeb92..98c993259759 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) + 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]; } @@ -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 8906ee0a8a6a..d16a67898a34 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -462,6 +462,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