1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - Tunneling support
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6 * Copyright (C) 2019, Intel Corporation
22 * struct tb_tunnel - Tunnel between two ports
23 * @tb: Pointer to the domain
24 * @src_port: Source port of the tunnel
25 * @dst_port: Destination port of the tunnel. For discovered incomplete
26 * tunnels may be %NULL or null adapter port instead.
27 * @paths: All paths required by the tunnel
28 * @npaths: Number of paths in @paths
29 * @init: Optional tunnel specific initialization
30 * @deinit: Optional tunnel specific de-initialization
31 * @activate: Optional tunnel specific activation/deactivation
32 * @maximum_bandwidth: Returns maximum possible bandwidth for this tunnel
33 * @allocated_bandwidth: Return how much bandwidth is allocated for the tunnel
34 * @alloc_bandwidth: Change tunnel bandwidth allocation
35 * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
36 * @release_unused_bandwidth: Release all unused bandwidth
37 * @reclaim_available_bandwidth: Reclaim back available bandwidth
38 * @list: Tunnels are linked using this field
39 * @type: Type of the tunnel
40 * @max_up: Maximum upstream bandwidth (Mb/s) available for the tunnel.
41 * Only set if the bandwidth needs to be limited.
42 * @max_down: Maximum downstream bandwidth (Mb/s) available for the tunnel.
43 * Only set if the bandwidth needs to be limited.
44 * @allocated_up: Allocated upstream bandwidth (only for USB3)
45 * @allocated_down: Allocated downstream bandwidth (only for USB3)
46 * @bw_mode: DP bandwidth allocation mode registers can be used to
47 * determine consumed and allocated bandwidth
51 struct tb_port *src_port;
52 struct tb_port *dst_port;
53 struct tb_path **paths;
55 int (*init)(struct tb_tunnel *tunnel);
56 void (*deinit)(struct tb_tunnel *tunnel);
57 int (*activate)(struct tb_tunnel *tunnel, bool activate);
58 int (*maximum_bandwidth)(struct tb_tunnel *tunnel, int *max_up,
60 int (*allocated_bandwidth)(struct tb_tunnel *tunnel, int *allocated_up,
62 int (*alloc_bandwidth)(struct tb_tunnel *tunnel, int *alloc_up,
64 int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
66 int (*release_unused_bandwidth)(struct tb_tunnel *tunnel);
67 void (*reclaim_available_bandwidth)(struct tb_tunnel *tunnel,
70 struct list_head list;
71 enum tb_tunnel_type type;
79 struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down,
81 struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
82 struct tb_port *down);
83 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
85 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
86 struct tb_port *out, int link_nr,
87 int max_up, int max_down);
88 struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
89 struct tb_port *dst, int transmit_path,
90 int transmit_ring, int receive_path,
92 bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path,
93 int transmit_ring, int receive_path, int receive_ring);
94 struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down,
96 struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
97 struct tb_port *down, int max_up,
100 void tb_tunnel_free(struct tb_tunnel *tunnel);
101 int tb_tunnel_activate(struct tb_tunnel *tunnel);
102 int tb_tunnel_restart(struct tb_tunnel *tunnel);
103 void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
104 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
105 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
106 const struct tb_port *port);
107 int tb_tunnel_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up,
109 int tb_tunnel_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up,
110 int *allocated_down);
111 int tb_tunnel_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,
113 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
115 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel);
116 void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
118 int *available_down);
120 static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
122 return tunnel->type == TB_TUNNEL_PCI;
125 static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
127 return tunnel->type == TB_TUNNEL_DP;
130 static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
132 return tunnel->type == TB_TUNNEL_DMA;
135 static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
137 return tunnel->type == TB_TUNNEL_USB3;