thunderbolt: Rename tunnel_pci to tunnel
authorMika Westerberg <mika.westerberg@linux.intel.com>
Sun, 19 Feb 2017 08:58:35 +0000 (10:58 +0200)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 18 Apr 2019 08:18:52 +0000 (11:18 +0300)
In order to tunnel non-PCIe traffic as well rename tunnel_pci.[ch] to
tunnel.[ch] to reflect this fact. No functional changes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/Makefile
drivers/thunderbolt/tb.c
drivers/thunderbolt/tunnel.c [new file with mode: 0644]
drivers/thunderbolt/tunnel.h [new file with mode: 0644]
drivers/thunderbolt/tunnel_pci.c [deleted file]
drivers/thunderbolt/tunnel_pci.h [deleted file]

index 8531f15..833bdee 100644 (file)
@@ -1,3 +1,3 @@
 obj-${CONFIG_THUNDERBOLT} := thunderbolt.o
-thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o path.o tunnel_pci.o eeprom.o
+thunderbolt-objs := nhi.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o
 thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o
index e71530d..8de43a2 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "tb.h"
 #include "tb_regs.h"
-#include "tunnel_pci.h"
+#include "tunnel.h"
 
 /**
  * struct tb_cm - Simple Thunderbolt connection manager
diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
new file mode 100644 (file)
index 0000000..1e47056
--- /dev/null
@@ -0,0 +1,223 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Thunderbolt Cactus Ridge driver - Tunneling support
+ *
+ * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
+ */
+
+#include <linux/slab.h>
+#include <linux/list.h>
+
+#include "tunnel.h"
+#include "tb.h"
+
+#define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...)                   \
+       do {                                                            \
+               struct tb_pci_tunnel *__tunnel = (tunnel);              \
+               level(__tunnel->tb, "%llx:%x <-> %llx:%x (PCI): " fmt,  \
+                     tb_route(__tunnel->down_port->sw),                \
+                     __tunnel->down_port->port,                        \
+                     tb_route(__tunnel->up_port->sw),                  \
+                     __tunnel->up_port->port,                          \
+                     ## arg);                                          \
+       } while (0)
+
+#define tb_tunnel_WARN(tunnel, fmt, arg...) \
+       __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg)
+#define tb_tunnel_warn(tunnel, fmt, arg...) \
+       __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg)
+#define tb_tunnel_info(tunnel, fmt, arg...) \
+       __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg)
+
+static void tb_pci_init_path(struct tb_path *path)
+{
+       path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL;
+       path->egress_shared_buffer = TB_PATH_NONE;
+       path->ingress_fc_enable = TB_PATH_ALL;
+       path->ingress_shared_buffer = TB_PATH_NONE;
+       path->priority = 3;
+       path->weight = 1;
+       path->drop_packages = 0;
+       path->nfc_credits = 0;
+}
+
+/**
+ * tb_pci_alloc() - allocate a pci tunnel
+ *
+ * Allocate a PCI tunnel. The ports must be of type TB_TYPE_PCIE_UP and
+ * TB_TYPE_PCIE_DOWN.
+ *
+ * Currently only paths consisting of two hops are supported (that is the
+ * ports must be on "adjacent" switches).
+ *
+ * The paths are hard-coded to use hop 8 (the only working hop id available on
+ * my thunderbolt devices). Therefore at most ONE path per device may be
+ * activated.
+ *
+ * Return: Returns a tb_pci_tunnel on success or NULL on failure.
+ */
+struct tb_pci_tunnel *tb_pci_alloc(struct tb *tb, struct tb_port *up,
+                                  struct tb_port *down)
+{
+       struct tb_pci_tunnel *tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL);
+       if (!tunnel)
+               goto err;
+       tunnel->tb = tb;
+       tunnel->down_port = down;
+       tunnel->up_port = up;
+       INIT_LIST_HEAD(&tunnel->list);
+       tunnel->path_to_up = tb_path_alloc(up->sw->tb, 2);
+       if (!tunnel->path_to_up)
+               goto err;
+       tunnel->path_to_down = tb_path_alloc(up->sw->tb, 2);
+       if (!tunnel->path_to_down)
+               goto err;
+       tb_pci_init_path(tunnel->path_to_up);
+       tb_pci_init_path(tunnel->path_to_down);
+
+       tunnel->path_to_up->hops[0].in_port = down;
+       tunnel->path_to_up->hops[0].in_hop_index = 8;
+       tunnel->path_to_up->hops[0].in_counter_index = -1;
+       tunnel->path_to_up->hops[0].out_port = tb_upstream_port(up->sw)->remote;
+       tunnel->path_to_up->hops[0].next_hop_index = 8;
+
+       tunnel->path_to_up->hops[1].in_port = tb_upstream_port(up->sw);
+       tunnel->path_to_up->hops[1].in_hop_index = 8;
+       tunnel->path_to_up->hops[1].in_counter_index = -1;
+       tunnel->path_to_up->hops[1].out_port = up;
+       tunnel->path_to_up->hops[1].next_hop_index = 8;
+
+       tunnel->path_to_down->hops[0].in_port = up;
+       tunnel->path_to_down->hops[0].in_hop_index = 8;
+       tunnel->path_to_down->hops[0].in_counter_index = -1;
+       tunnel->path_to_down->hops[0].out_port = tb_upstream_port(up->sw);
+       tunnel->path_to_down->hops[0].next_hop_index = 8;
+
+       tunnel->path_to_down->hops[1].in_port =
+               tb_upstream_port(up->sw)->remote;
+       tunnel->path_to_down->hops[1].in_hop_index = 8;
+       tunnel->path_to_down->hops[1].in_counter_index = -1;
+       tunnel->path_to_down->hops[1].out_port = down;
+       tunnel->path_to_down->hops[1].next_hop_index = 8;
+       return tunnel;
+
+err:
+       if (tunnel) {
+               if (tunnel->path_to_down)
+                       tb_path_free(tunnel->path_to_down);
+               if (tunnel->path_to_up)
+                       tb_path_free(tunnel->path_to_up);
+               kfree(tunnel);
+       }
+       return NULL;
+}
+
+/**
+ * tb_pci_free() - free a tunnel
+ *
+ * The tunnel must have been deactivated.
+ */
+void tb_pci_free(struct tb_pci_tunnel *tunnel)
+{
+       if (tunnel->path_to_up->activated || tunnel->path_to_down->activated) {
+               tb_tunnel_WARN(tunnel, "trying to free an activated tunnel\n");
+               return;
+       }
+       tb_path_free(tunnel->path_to_up);
+       tb_path_free(tunnel->path_to_down);
+       kfree(tunnel);
+}
+
+/**
+ * tb_pci_is_invalid - check whether an activated path is still valid
+ */
+bool tb_pci_is_invalid(struct tb_pci_tunnel *tunnel)
+{
+       WARN_ON(!tunnel->path_to_up->activated);
+       WARN_ON(!tunnel->path_to_down->activated);
+
+       return tb_path_is_invalid(tunnel->path_to_up)
+              || tb_path_is_invalid(tunnel->path_to_down);
+}
+
+/**
+ * tb_pci_port_active() - activate/deactivate PCI capability
+ *
+ * Return: Returns 0 on success or an error code on failure.
+ */
+static int tb_pci_port_active(struct tb_port *port, bool active)
+{
+       u32 word = active ? 0x80000000 : 0x0;
+       if (!port->cap_adap)
+               return -ENXIO;
+       return tb_port_write(port, &word, TB_CFG_PORT, port->cap_adap, 1);
+}
+
+/**
+ * tb_pci_restart() - activate a tunnel after a hardware reset
+ */
+int tb_pci_restart(struct tb_pci_tunnel *tunnel)
+{
+       int res;
+       tunnel->path_to_up->activated = false;
+       tunnel->path_to_down->activated = false;
+
+       tb_tunnel_info(tunnel, "activating\n");
+
+       res = tb_path_activate(tunnel->path_to_up);
+       if (res)
+               goto err;
+       res = tb_path_activate(tunnel->path_to_down);
+       if (res)
+               goto err;
+
+       res = tb_pci_port_active(tunnel->down_port, true);
+       if (res)
+               goto err;
+
+       res = tb_pci_port_active(tunnel->up_port, true);
+       if (res)
+               goto err;
+       return 0;
+err:
+       tb_tunnel_warn(tunnel, "activation failed\n");
+       tb_pci_deactivate(tunnel);
+       return res;
+}
+
+/**
+ * tb_pci_activate() - activate a tunnel
+ *
+ * Return: Returns 0 on success or an error code on failure.
+ */
+int tb_pci_activate(struct tb_pci_tunnel *tunnel)
+{
+       if (tunnel->path_to_up->activated || tunnel->path_to_down->activated) {
+               tb_tunnel_WARN(tunnel,
+                              "trying to activate an already activated tunnel\n");
+               return -EINVAL;
+       }
+
+       return tb_pci_restart(tunnel);
+}
+
+
+
+/**
+ * tb_pci_deactivate() - deactivate a tunnel
+ */
+void tb_pci_deactivate(struct tb_pci_tunnel *tunnel)
+{
+       tb_tunnel_info(tunnel, "deactivating\n");
+       /*
+        * TODO: enable reset by writing 0x04000000 to TB_CAP_PCIE + 1 on up
+        * port. Seems to have no effect?
+        */
+       tb_pci_port_active(tunnel->up_port, false);
+       tb_pci_port_active(tunnel->down_port, false);
+       if (tunnel->path_to_down->activated)
+               tb_path_deactivate(tunnel->path_to_down);
+       if (tunnel->path_to_up->activated)
+               tb_path_deactivate(tunnel->path_to_up);
+}
+
diff --git a/drivers/thunderbolt/tunnel.h b/drivers/thunderbolt/tunnel.h
new file mode 100644 (file)
index 0000000..dff0f27
--- /dev/null
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Thunderbolt Cactus Ridge driver - Tunneling support
+ *
+ * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
+ */
+
+#ifndef TB_TUNNEL_H_
+#define TB_TUNNEL_H_
+
+#include "tb.h"
+
+struct tb_pci_tunnel {
+       struct tb *tb;
+       struct tb_port *up_port;
+       struct tb_port *down_port;
+       struct tb_path *path_to_up;
+       struct tb_path *path_to_down;
+       struct list_head list;
+};
+
+struct tb_pci_tunnel *tb_pci_alloc(struct tb *tb, struct tb_port *up,
+                                  struct tb_port *down);
+void tb_pci_free(struct tb_pci_tunnel *tunnel);
+int tb_pci_activate(struct tb_pci_tunnel *tunnel);
+int tb_pci_restart(struct tb_pci_tunnel *tunnel);
+void tb_pci_deactivate(struct tb_pci_tunnel *tunnel);
+bool tb_pci_is_invalid(struct tb_pci_tunnel *tunnel);
+
+#endif
+
diff --git a/drivers/thunderbolt/tunnel_pci.c b/drivers/thunderbolt/tunnel_pci.c
deleted file mode 100644 (file)
index 2de4edc..0000000
+++ /dev/null
@@ -1,223 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Thunderbolt Cactus Ridge driver - PCIe tunnel
- *
- * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
- */
-
-#include <linux/slab.h>
-#include <linux/list.h>
-
-#include "tunnel_pci.h"
-#include "tb.h"
-
-#define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...)                   \
-       do {                                                            \
-               struct tb_pci_tunnel *__tunnel = (tunnel);              \
-               level(__tunnel->tb, "%llx:%x <-> %llx:%x (PCI): " fmt,  \
-                     tb_route(__tunnel->down_port->sw),                \
-                     __tunnel->down_port->port,                        \
-                     tb_route(__tunnel->up_port->sw),                  \
-                     __tunnel->up_port->port,                          \
-                     ## arg);                                          \
-       } while (0)
-
-#define tb_tunnel_WARN(tunnel, fmt, arg...) \
-       __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg)
-#define tb_tunnel_warn(tunnel, fmt, arg...) \
-       __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg)
-#define tb_tunnel_info(tunnel, fmt, arg...) \
-       __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg)
-
-static void tb_pci_init_path(struct tb_path *path)
-{
-       path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL;
-       path->egress_shared_buffer = TB_PATH_NONE;
-       path->ingress_fc_enable = TB_PATH_ALL;
-       path->ingress_shared_buffer = TB_PATH_NONE;
-       path->priority = 3;
-       path->weight = 1;
-       path->drop_packages = 0;
-       path->nfc_credits = 0;
-}
-
-/**
- * tb_pci_alloc() - allocate a pci tunnel
- *
- * Allocate a PCI tunnel. The ports must be of type TB_TYPE_PCIE_UP and
- * TB_TYPE_PCIE_DOWN.
- *
- * Currently only paths consisting of two hops are supported (that is the
- * ports must be on "adjacent" switches).
- *
- * The paths are hard-coded to use hop 8 (the only working hop id available on
- * my thunderbolt devices). Therefore at most ONE path per device may be
- * activated.
- *
- * Return: Returns a tb_pci_tunnel on success or NULL on failure.
- */
-struct tb_pci_tunnel *tb_pci_alloc(struct tb *tb, struct tb_port *up,
-                                  struct tb_port *down)
-{
-       struct tb_pci_tunnel *tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL);
-       if (!tunnel)
-               goto err;
-       tunnel->tb = tb;
-       tunnel->down_port = down;
-       tunnel->up_port = up;
-       INIT_LIST_HEAD(&tunnel->list);
-       tunnel->path_to_up = tb_path_alloc(up->sw->tb, 2);
-       if (!tunnel->path_to_up)
-               goto err;
-       tunnel->path_to_down = tb_path_alloc(up->sw->tb, 2);
-       if (!tunnel->path_to_down)
-               goto err;
-       tb_pci_init_path(tunnel->path_to_up);
-       tb_pci_init_path(tunnel->path_to_down);
-
-       tunnel->path_to_up->hops[0].in_port = down;
-       tunnel->path_to_up->hops[0].in_hop_index = 8;
-       tunnel->path_to_up->hops[0].in_counter_index = -1;
-       tunnel->path_to_up->hops[0].out_port = tb_upstream_port(up->sw)->remote;
-       tunnel->path_to_up->hops[0].next_hop_index = 8;
-
-       tunnel->path_to_up->hops[1].in_port = tb_upstream_port(up->sw);
-       tunnel->path_to_up->hops[1].in_hop_index = 8;
-       tunnel->path_to_up->hops[1].in_counter_index = -1;
-       tunnel->path_to_up->hops[1].out_port = up;
-       tunnel->path_to_up->hops[1].next_hop_index = 8;
-
-       tunnel->path_to_down->hops[0].in_port = up;
-       tunnel->path_to_down->hops[0].in_hop_index = 8;
-       tunnel->path_to_down->hops[0].in_counter_index = -1;
-       tunnel->path_to_down->hops[0].out_port = tb_upstream_port(up->sw);
-       tunnel->path_to_down->hops[0].next_hop_index = 8;
-
-       tunnel->path_to_down->hops[1].in_port =
-               tb_upstream_port(up->sw)->remote;
-       tunnel->path_to_down->hops[1].in_hop_index = 8;
-       tunnel->path_to_down->hops[1].in_counter_index = -1;
-       tunnel->path_to_down->hops[1].out_port = down;
-       tunnel->path_to_down->hops[1].next_hop_index = 8;
-       return tunnel;
-
-err:
-       if (tunnel) {
-               if (tunnel->path_to_down)
-                       tb_path_free(tunnel->path_to_down);
-               if (tunnel->path_to_up)
-                       tb_path_free(tunnel->path_to_up);
-               kfree(tunnel);
-       }
-       return NULL;
-}
-
-/**
- * tb_pci_free() - free a tunnel
- *
- * The tunnel must have been deactivated.
- */
-void tb_pci_free(struct tb_pci_tunnel *tunnel)
-{
-       if (tunnel->path_to_up->activated || tunnel->path_to_down->activated) {
-               tb_tunnel_WARN(tunnel, "trying to free an activated tunnel\n");
-               return;
-       }
-       tb_path_free(tunnel->path_to_up);
-       tb_path_free(tunnel->path_to_down);
-       kfree(tunnel);
-}
-
-/**
- * tb_pci_is_invalid - check whether an activated path is still valid
- */
-bool tb_pci_is_invalid(struct tb_pci_tunnel *tunnel)
-{
-       WARN_ON(!tunnel->path_to_up->activated);
-       WARN_ON(!tunnel->path_to_down->activated);
-
-       return tb_path_is_invalid(tunnel->path_to_up)
-              || tb_path_is_invalid(tunnel->path_to_down);
-}
-
-/**
- * tb_pci_port_active() - activate/deactivate PCI capability
- *
- * Return: Returns 0 on success or an error code on failure.
- */
-static int tb_pci_port_active(struct tb_port *port, bool active)
-{
-       u32 word = active ? 0x80000000 : 0x0;
-       if (!port->cap_adap)
-               return -ENXIO;
-       return tb_port_write(port, &word, TB_CFG_PORT, port->cap_adap, 1);
-}
-
-/**
- * tb_pci_restart() - activate a tunnel after a hardware reset
- */
-int tb_pci_restart(struct tb_pci_tunnel *tunnel)
-{
-       int res;
-       tunnel->path_to_up->activated = false;
-       tunnel->path_to_down->activated = false;
-
-       tb_tunnel_info(tunnel, "activating\n");
-
-       res = tb_path_activate(tunnel->path_to_up);
-       if (res)
-               goto err;
-       res = tb_path_activate(tunnel->path_to_down);
-       if (res)
-               goto err;
-
-       res = tb_pci_port_active(tunnel->down_port, true);
-       if (res)
-               goto err;
-
-       res = tb_pci_port_active(tunnel->up_port, true);
-       if (res)
-               goto err;
-       return 0;
-err:
-       tb_tunnel_warn(tunnel, "activation failed\n");
-       tb_pci_deactivate(tunnel);
-       return res;
-}
-
-/**
- * tb_pci_activate() - activate a tunnel
- *
- * Return: Returns 0 on success or an error code on failure.
- */
-int tb_pci_activate(struct tb_pci_tunnel *tunnel)
-{
-       if (tunnel->path_to_up->activated || tunnel->path_to_down->activated) {
-               tb_tunnel_WARN(tunnel,
-                              "trying to activate an already activated tunnel\n");
-               return -EINVAL;
-       }
-
-       return tb_pci_restart(tunnel);
-}
-
-
-
-/**
- * tb_pci_deactivate() - deactivate a tunnel
- */
-void tb_pci_deactivate(struct tb_pci_tunnel *tunnel)
-{
-       tb_tunnel_info(tunnel, "deactivating\n");
-       /*
-        * TODO: enable reset by writing 0x04000000 to TB_CAP_PCIE + 1 on up
-        * port. Seems to have no effect?
-        */
-       tb_pci_port_active(tunnel->up_port, false);
-       tb_pci_port_active(tunnel->down_port, false);
-       if (tunnel->path_to_down->activated)
-               tb_path_deactivate(tunnel->path_to_down);
-       if (tunnel->path_to_up->activated)
-               tb_path_deactivate(tunnel->path_to_up);
-}
-
diff --git a/drivers/thunderbolt/tunnel_pci.h b/drivers/thunderbolt/tunnel_pci.h
deleted file mode 100644 (file)
index f9b65fa..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Thunderbolt Cactus Ridge driver - PCIe tunnel
- *
- * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
- */
-
-#ifndef TB_PCI_H_
-#define TB_PCI_H_
-
-#include "tb.h"
-
-struct tb_pci_tunnel {
-       struct tb *tb;
-       struct tb_port *up_port;
-       struct tb_port *down_port;
-       struct tb_path *path_to_up;
-       struct tb_path *path_to_down;
-       struct list_head list;
-};
-
-struct tb_pci_tunnel *tb_pci_alloc(struct tb *tb, struct tb_port *up,
-                                  struct tb_port *down);
-void tb_pci_free(struct tb_pci_tunnel *tunnel);
-int tb_pci_activate(struct tb_pci_tunnel *tunnel);
-int tb_pci_restart(struct tb_pci_tunnel *tunnel);
-void tb_pci_deactivate(struct tb_pci_tunnel *tunnel);
-bool tb_pci_is_invalid(struct tb_pci_tunnel *tunnel);
-
-#endif
-