Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp435320ybb; Thu, 28 Mar 2019 05:38:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXfizcGl5JRGS+jxC8BDeODtnLNW7YhVHWZ9U9m/iKYCcuE9x/+RllUzhHqAZoGh8vDxNG X-Received: by 2002:a63:4542:: with SMTP id u2mr39221018pgk.291.1553776731538; Thu, 28 Mar 2019 05:38:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553776731; cv=none; d=google.com; s=arc-20160816; b=B4yhM/Eu9bQAG4c3Qwj6pRUpkeuxFZjJb+5KWH9mINQ3rA6dRjFEIqMxN3FLbgbGO/ jw4/A7cMqqwwNCJXnFI2nkZ9kTiX9GKAZMcCOMdtLD1wF/DAjr+80Yy0T9Rpd4Ku4xab KKVqZWPYLOvOUHIcZCVSiLApUg/3fxGZz4bVinnmsiCMevT+939cOY6p9FfAW93l7vPG hEVtYqa1MrwQYk2tzgM7XYQqZwVrjQdd8xleVxEOqIDqb4hRS32cAMfC3R6cM30PREEu ok09TE8Gc7OP1jRfLcdXYHhZBw/itQerUHbnmfhPzebgMadGNBLiviOCgWfiLToTCS5x hSwg== 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=8r2lPB1KvutM/kS28Wwfkir4SjTBjfwxQk+aa3EPM7Q=; b=PPQNIy50tzODETDNMpCLfx4dcXI/P0YKlXgbxK2/QznfTGEBTtaHmyK5xOVuilGiGp TZCfr8t8OYNJOR1uVJQZXgrqS1V0h0mTU9aZIiRx5kDpFwrvfCNNA6xWlnA8SF6DZxeR MPLBb8cX2DkIUxLSO88Z74r/m8wFEVtCAe0w4rHGcDwQ/5Ju+qByXTFhqmC2HR/oIWre hY55uCiNkrw37rZEYxza6GcVPsaDIDNGIaMU/1Ui0IiotX4Ub10XjM6dHB2jDo0fXXRH 2TS1uy/4jm2ikg0p11Wg0AzWQc5mDT+DZCe+cP3pogNpf4TnGWNkjHh7w+v7LN2BPMks n0SA== 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 cc19si23030140plb.422.2019.03.28.05.38.36; Thu, 28 Mar 2019 05:38:51 -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 S1727622AbfC1Mha (ORCPT + 99 others); Thu, 28 Mar 2019 08:37:30 -0400 Received: from mga09.intel.com ([134.134.136.24]:34158 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727247AbfC1Mgr (ORCPT ); Thu, 28 Mar 2019 08:36:47 -0400 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; 28 Mar 2019 05:36:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,280,1549958400"; d="scan'208";a="138136889" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 28 Mar 2019 05:36:42 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 9E18FC5A; 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 18/36] thunderbolt: Add helper function to iterate from one port to another Date: Thu, 28 Mar 2019 15:36:15 +0300 Message-Id: <20190328123633.42882-19-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 need to be able to walk from one port to another when we are creating paths where there are multiple switches between two ports. For this reason introduce a new function tb_next_port_on_path(). Signed-off-by: Mika Westerberg --- drivers/thunderbolt/switch.c | 54 ++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 6f98b3d6eb2a..ecd41f7b7649 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -676,6 +676,60 @@ void tb_port_release_out_hopid(struct tb_port *port, int hopid) ida_simple_remove(&port->out_hopids, hopid); } +/** + * tb_next_port_on_path() - Return next port for given port on a path + * @start: Start port of the walk + * @end: End port of the walk + * @prev: Previous port (%NULL if this is the first) + * + * This function can be used to walk from one port to another if they + * are connected through zero or more switches. If the @prev is dual + * link port, the function follows that link and returns another end on + * that same link. + * + * If the @end port has been reached, return %NULL. + * + * Domain tb->lock must be held when this function is called. + */ +struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end, + struct tb_port *prev) +{ + struct tb_port *next; + + if (!prev) + return start; + + if (prev->sw == end->sw) { + if (prev == end) + return NULL; + return end; + } + + if (start->sw->config.depth < end->sw->config.depth) { + if (prev->remote && + prev->remote->sw->config.depth > prev->sw->config.depth) + next = prev->remote; + else + next = tb_port_at(tb_route(end->sw), prev->sw); + } else { + if (tb_is_upstream_port(prev)) { + next = prev->remote; + } else { + next = tb_upstream_port(prev->sw); + /* + * Keep the same link if prev and next are both + * dual link ports. + */ + if (next->dual_link_port && + next->link_nr != prev->link_nr) { + next = next->dual_link_port; + } + } + } + + return next; +} + /** * tb_pci_port_enable() - Enable PCIe adapter port * @port: PCIe port to enable diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h index 5e317ca87786..c797512dfb05 100644 --- a/drivers/thunderbolt/tb.h +++ b/drivers/thunderbolt/tb.h @@ -496,6 +496,8 @@ int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid); void tb_port_release_in_hopid(struct tb_port *port, int hopid); int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid); void tb_port_release_out_hopid(struct tb_port *port, int hopid); +struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end, + struct tb_port *prev); 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); -- 2.20.1