From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: Andreas Noever <andreas.noever@gmail.com>,
Michael Jamet <michael.jamet@intel.com>,
Yehezkel Bernat <yehezkel.bernat@intel.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Mario.Limonciello@dell.com,
Radion Mirchevsky <radion.mirchevsky@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 08/18] thunderbolt: Factor common ICM add and update operations out
Date: Tue, 13 Feb 2018 20:00:08 +0300 [thread overview]
Message-ID: <20180213170018.9780-9-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20180213170018.9780-1-mika.westerberg@linux.intel.com>
The newer ICM will not use link and depth to address devices. Instead it
uses route strings. In order to take advantage of the existing code
factor out common operations so that we can use the same functions with
the new ICM as well.
No functional changes intended.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/thunderbolt/icm.c | 136 +++++++++++++++++++++++++++++-----------------
1 file changed, 87 insertions(+), 49 deletions(-)
diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
index 34d7740d1cbd..55006994b517 100644
--- a/drivers/thunderbolt/icm.c
+++ b/drivers/thunderbolt/icm.c
@@ -374,6 +374,57 @@ static int icm_fr_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd)
return 0;
}
+static void add_switch(struct tb_switch *parent_sw, u64 route,
+ const uuid_t *uuid, u8 connection_id, u8 connection_key,
+ u8 link, u8 depth, enum tb_security_level security_level,
+ bool authorized)
+{
+ struct tb_switch *sw;
+
+ sw = tb_switch_alloc(parent_sw->tb, &parent_sw->dev, route);
+ if (!sw)
+ return;
+
+ sw->uuid = kmemdup(uuid, sizeof(*uuid), GFP_KERNEL);
+ sw->connection_id = connection_id;
+ sw->connection_key = connection_key;
+ sw->link = link;
+ sw->depth = depth;
+ sw->authorized = authorized;
+ sw->security_level = security_level;
+
+ /* Link the two switches now */
+ tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw);
+ tb_upstream_port(sw)->remote = tb_port_at(route, parent_sw);
+
+ if (tb_switch_add(sw)) {
+ tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
+ tb_switch_put(sw);
+ return;
+ }
+}
+
+static void update_switch(struct tb_switch *parent_sw, struct tb_switch *sw,
+ u64 route, u8 connection_id, u8 connection_key,
+ u8 link, u8 depth)
+{
+ /* Disconnect from parent */
+ tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
+ /* Re-connect via updated port*/
+ tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw);
+
+ /* Update with the new addressing information */
+ sw->config.route_hi = upper_32_bits(route);
+ sw->config.route_lo = lower_32_bits(route);
+ sw->connection_id = connection_id;
+ sw->connection_key = connection_key;
+ sw->link = link;
+ sw->depth = depth;
+
+ /* This switch still exists */
+ sw->is_unplugged = false;
+}
+
static void remove_switch(struct tb_switch *sw)
{
struct tb_switch *parent_sw;
@@ -383,6 +434,31 @@ static void remove_switch(struct tb_switch *sw)
tb_switch_remove(sw);
}
+static void add_xdomain(struct tb_switch *sw, u64 route,
+ const uuid_t *local_uuid, const uuid_t *remote_uuid,
+ u8 link, u8 depth)
+{
+ struct tb_xdomain *xd;
+
+ xd = tb_xdomain_alloc(sw->tb, &sw->dev, route, local_uuid, remote_uuid);
+ if (!xd)
+ return;
+
+ xd->link = link;
+ xd->depth = depth;
+
+ tb_port_at(route, sw)->xdomain = xd;
+
+ tb_xdomain_add(xd);
+}
+
+static void update_xdomain(struct tb_xdomain *xd, u64 route, u8 link)
+{
+ xd->link = link;
+ xd->route = route;
+ xd->is_unplugged = false;
+}
+
static void remove_xdomain(struct tb_xdomain *xd)
{
struct tb_switch *sw;
@@ -397,6 +473,7 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
{
const struct icm_fr_event_device_connected *pkg =
(const struct icm_fr_event_device_connected *)hdr;
+ enum tb_security_level security_level;
struct tb_switch *sw, *parent_sw;
struct icm *icm = tb_priv(tb);
bool authorized = false;
@@ -409,6 +486,8 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
depth = (pkg->link_info & ICM_LINK_INFO_DEPTH_MASK) >>
ICM_LINK_INFO_DEPTH_SHIFT;
authorized = pkg->link_info & ICM_LINK_INFO_APPROVED;
+ security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >>
+ ICM_FLAGS_SLEVEL_SHIFT;
if (pkg->link_info & ICM_LINK_INFO_REJECTED) {
tb_info(tb, "switch at %u.%u was rejected by ICM firmware\n",
@@ -441,16 +520,8 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
*/
if (sw->depth == depth && sw_phy_port == phy_port &&
!!sw->authorized == authorized) {
- tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
- tb_port_at(route, parent_sw)->remote =
- tb_upstream_port(sw);
- sw->config.route_hi = upper_32_bits(route);
- sw->config.route_lo = lower_32_bits(route);
- sw->connection_id = pkg->connection_id;
- sw->connection_key = pkg->connection_key;
- sw->link = link;
- sw->depth = depth;
- sw->is_unplugged = false;
+ update_switch(parent_sw, sw, route, pkg->connection_id,
+ pkg->connection_key, link, depth);
tb_switch_put(sw);
return;
}
@@ -497,30 +568,10 @@ icm_fr_device_connected(struct tb *tb, const struct icm_pkg_header *hdr)
return;
}
- sw = tb_switch_alloc(tb, &parent_sw->dev, route);
- if (!sw) {
- tb_switch_put(parent_sw);
- return;
- }
+ add_switch(parent_sw, route, &pkg->ep_uuid, pkg->connection_id,
+ pkg->connection_key, link, depth, security_level,
+ authorized);
- sw->uuid = kmemdup(&pkg->ep_uuid, sizeof(pkg->ep_uuid), GFP_KERNEL);
- sw->connection_id = pkg->connection_id;
- sw->connection_key = pkg->connection_key;
- sw->link = link;
- sw->depth = depth;
- sw->authorized = authorized;
- sw->security_level = (pkg->hdr.flags & ICM_FLAGS_SLEVEL_MASK) >>
- ICM_FLAGS_SLEVEL_SHIFT;
-
- /* Link the two switches now */
- tb_port_at(route, parent_sw)->remote = tb_upstream_port(sw);
- tb_upstream_port(sw)->remote = tb_port_at(route, parent_sw);
-
- ret = tb_switch_add(sw);
- if (ret) {
- tb_port_at(tb_route(sw), parent_sw)->remote = NULL;
- tb_switch_put(sw);
- }
tb_switch_put(parent_sw);
}
@@ -591,9 +642,7 @@ icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
phy_port = phy_port_from_route(route, depth);
if (xd->depth == depth && xd_phy_port == phy_port) {
- xd->link = link;
- xd->route = route;
- xd->is_unplugged = false;
+ update_xdomain(xd, route, link);
tb_xdomain_put(xd);
return;
}
@@ -643,19 +692,8 @@ icm_fr_xdomain_connected(struct tb *tb, const struct icm_pkg_header *hdr)
return;
}
- xd = tb_xdomain_alloc(sw->tb, &sw->dev, route,
- &pkg->local_uuid, &pkg->remote_uuid);
- if (!xd) {
- tb_switch_put(sw);
- return;
- }
-
- xd->link = link;
- xd->depth = depth;
-
- tb_port_at(route, sw)->xdomain = xd;
-
- tb_xdomain_add(xd);
+ add_xdomain(sw, route, &pkg->local_uuid, &pkg->remote_uuid, link,
+ depth);
tb_switch_put(sw);
}
--
2.15.1
next prev parent reply other threads:[~2018-02-13 17:13 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-13 17:00 [PATCH 00/18] thunderbolt: Add support for Intel Titan Ridge Mika Westerberg
2018-02-13 17:00 ` [PATCH 01/18] thunderbolt: Resume control channel after hibernation image is created Mika Westerberg
2018-02-13 17:00 ` [PATCH 02/18] thunderbolt: Serialize PCIe tunnel creation with PCI rescan Mika Westerberg
2018-02-13 17:00 ` [PATCH 03/18] thunderbolt: Handle connecting device in place of host properly Mika Westerberg
2018-02-13 17:00 ` [PATCH 04/18] thunderbolt: Do not overwrite error code when domain adding fails Mika Westerberg
2018-02-13 17:00 ` [PATCH 05/18] thunderbolt: Wait a bit longer for root switch config space Mika Westerberg
2018-02-13 17:00 ` [PATCH 06/18] thunderbolt: Wait a bit longer for ICM to authenticate the active NVM Mika Westerberg
2018-02-13 17:21 ` Mario.Limonciello
2018-02-14 10:03 ` Mika Westerberg
2018-02-13 17:00 ` [PATCH 07/18] thunderbolt: Handle rejected Thunderbolt devices Mika Westerberg
2018-02-22 23:17 ` [07/18] " Jeremy McNicoll
2018-02-26 10:20 ` Mika Westerberg
2018-02-26 13:38 ` Mika Westerberg
2018-02-26 19:28 ` Jeremy McNicoll
2018-02-26 19:46 ` Mika Westerberg
2018-02-26 20:15 ` Jeremy McNicoll
2018-02-27 9:26 ` Mika Westerberg
2018-02-27 22:27 ` Jeremy McNicoll
2018-02-13 17:00 ` Mika Westerberg [this message]
2018-02-13 17:00 ` [PATCH 09/18] thunderbolt: Correct function name in kernel-doc comment Mika Westerberg
2018-02-13 17:00 ` [PATCH 10/18] thunderbolt: Add tb_switch_get() Mika Westerberg
2018-02-13 17:00 ` [PATCH 11/18] thunderbolt: Add tb_switch_find_by_route() Mika Westerberg
2018-02-13 17:00 ` [PATCH 12/18] thunderbolt: Add tb_xdomain_find_by_route() Mika Westerberg
2018-02-13 17:51 ` Andy Shevchenko
2018-02-14 10:25 ` Mika Westerberg
2018-02-13 17:00 ` [PATCH 13/18] thunderbolt: Add constant for approval timeout Mika Westerberg
2018-02-13 17:00 ` [PATCH 14/18] thunderbolt: Move driver ready handling to struct icm Mika Westerberg
2018-02-13 17:00 ` [PATCH 15/18] thunderbolt: Add 'boot' attribute for devices Mika Westerberg
2018-02-13 17:00 ` [PATCH 16/18] thunderbolt: Add support for preboot ACL Mika Westerberg
2018-02-13 18:19 ` Andy Shevchenko
2018-02-14 10:22 ` Mika Westerberg
2018-02-13 17:00 ` [PATCH 17/18] thunderbolt: Introduce USB only (SL4) security level Mika Westerberg
2018-02-14 0:29 ` Randy Dunlap
2018-02-14 10:09 ` Mika Westerberg
2018-02-13 17:00 ` [PATCH 18/18] thunderbolt: Add support for Intel Titan Ridge Mika Westerberg
2018-02-14 14:23 ` Andy Shevchenko
2018-02-14 14:28 ` Mika Westerberg
2018-02-14 14:29 ` Andy Shevchenko
2018-02-14 15:52 ` Mika Westerberg
2018-02-14 13:58 ` [PATCH 00/18] " Andy Shevchenko
2018-02-14 16:43 ` Mika Westerberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180213170018.9780-9-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=Mario.Limonciello@dell.com \
--cc=andreas.noever@gmail.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.jamet@intel.com \
--cc=radion.mirchevsky@intel.com \
--cc=yehezkel.bernat@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).