blob: ba888da005f5c331bb17071b118db55968f2c80f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andreas Noever3364f0c2014-06-03 22:04:08 +02002/*
Mika Westerberg93f36ad2017-02-19 13:48:29 +02003 * Thunderbolt driver - Tunneling support
Andreas Noever3364f0c2014-06-03 22:04:08 +02004 *
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
Mika Westerberg93f36ad2017-02-19 13:48:29 +02006 * Copyright (C) 2019, Intel Corporation
Andreas Noever3364f0c2014-06-03 22:04:08 +02007 */
8
Mika Westerberg1752b9f2017-02-19 10:58:35 +02009#ifndef TB_TUNNEL_H_
10#define TB_TUNNEL_H_
Andreas Noever3364f0c2014-06-03 22:04:08 +020011
12#include "tb.h"
13
Mika Westerberg4f807e42018-09-17 16:30:49 +030014enum tb_tunnel_type {
15 TB_TUNNEL_PCI,
16 TB_TUNNEL_DP,
Mika Westerberg44242d62018-09-28 16:35:32 +030017 TB_TUNNEL_DMA,
Mika Westerberg4f807e42018-09-17 16:30:49 +030018};
19
Mika Westerberg93f36ad2017-02-19 13:48:29 +020020/**
21 * struct tb_tunnel - Tunnel between two ports
22 * @tb: Pointer to the domain
23 * @src_port: Source port of the tunnel
Mika Westerberg0414bec2017-02-19 23:43:26 +020024 * @dst_port: Destination port of the tunnel. For discovered incomplete
25 * tunnels may be %NULL or null adapter port instead.
Mika Westerberg93f36ad2017-02-19 13:48:29 +020026 * @paths: All paths required by the tunnel
27 * @npaths: Number of paths in @paths
Mika Westerberg4f807e42018-09-17 16:30:49 +030028 * @init: Optional tunnel specific initialization
Mika Westerberg93f36ad2017-02-19 13:48:29 +020029 * @activate: Optional tunnel specific activation/deactivation
Mika Westerberga11b88a2019-03-26 16:03:48 +030030 * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
Mika Westerberg93f36ad2017-02-19 13:48:29 +020031 * @list: Tunnels are linked using this field
Mika Westerberg4f807e42018-09-17 16:30:49 +030032 * @type: Type of the tunnel
Mika Westerberga11b88a2019-03-26 16:03:48 +030033 * @max_bw: Maximum bandwidth (Mb/s) available for the tunnel (only for DP).
34 * Only set if the bandwidth needs to be limited.
Mika Westerberg93f36ad2017-02-19 13:48:29 +020035 */
36struct tb_tunnel {
Andreas Noever3364f0c2014-06-03 22:04:08 +020037 struct tb *tb;
Mika Westerberg93f36ad2017-02-19 13:48:29 +020038 struct tb_port *src_port;
39 struct tb_port *dst_port;
40 struct tb_path **paths;
41 size_t npaths;
Mika Westerberg4f807e42018-09-17 16:30:49 +030042 int (*init)(struct tb_tunnel *tunnel);
Mika Westerberg93f36ad2017-02-19 13:48:29 +020043 int (*activate)(struct tb_tunnel *tunnel, bool activate);
Mika Westerberga11b88a2019-03-26 16:03:48 +030044 int (*consumed_bandwidth)(struct tb_tunnel *tunnel);
Andreas Noever3364f0c2014-06-03 22:04:08 +020045 struct list_head list;
Mika Westerberg4f807e42018-09-17 16:30:49 +030046 enum tb_tunnel_type type;
Mika Westerberga11b88a2019-03-26 16:03:48 +030047 unsigned int max_bw;
Andreas Noever3364f0c2014-06-03 22:04:08 +020048};
49
Mika Westerberg0414bec2017-02-19 23:43:26 +020050struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
Mika Westerberg93f36ad2017-02-19 13:48:29 +020051struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
52 struct tb_port *down);
Mika Westerberg4f807e42018-09-17 16:30:49 +030053struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
54struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
Mika Westerberga11b88a2019-03-26 16:03:48 +030055 struct tb_port *out, int max_bw);
Mika Westerberg44242d62018-09-28 16:35:32 +030056struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
57 struct tb_port *dst, int transmit_ring,
58 int transmit_path, int receive_ring,
59 int receive_path);
Mika Westerberg4f807e42018-09-17 16:30:49 +030060
Mika Westerberg93f36ad2017-02-19 13:48:29 +020061void tb_tunnel_free(struct tb_tunnel *tunnel);
62int tb_tunnel_activate(struct tb_tunnel *tunnel);
63int tb_tunnel_restart(struct tb_tunnel *tunnel);
64void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
65bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
Mika Westerberga11b88a2019-03-26 16:03:48 +030066bool tb_tunnel_switch_on_path(const struct tb_tunnel *tunnel,
67 const struct tb_switch *sw);
68int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel);
Andreas Noever3364f0c2014-06-03 22:04:08 +020069
Mika Westerberg4f807e42018-09-17 16:30:49 +030070static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
71{
72 return tunnel->type == TB_TUNNEL_PCI;
73}
74
75static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
76{
77 return tunnel->type == TB_TUNNEL_DP;
78}
79
Mika Westerberg44242d62018-09-28 16:35:32 +030080static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
81{
82 return tunnel->type == TB_TUNNEL_DMA;
83}
84
Andreas Noever3364f0c2014-06-03 22:04:08 +020085#endif
86