thunderbolt: Use tb_tunnel_dbg() where possible to make logging more consistent
[linux-2.6-block.git] / drivers / thunderbolt / tunnel.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
3364f0c1 2/*
93f36ade 3 * Thunderbolt driver - Tunneling support
3364f0c1
AN
4 *
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
93f36ade 6 * Copyright (C) 2019, Intel Corporation
3364f0c1
AN
7 */
8
1752b9f7
MW
9#ifndef TB_TUNNEL_H_
10#define TB_TUNNEL_H_
3364f0c1
AN
11
12#include "tb.h"
13
4f807e47
MW
14enum tb_tunnel_type {
15 TB_TUNNEL_PCI,
16 TB_TUNNEL_DP,
44242d6c 17 TB_TUNNEL_DMA,
e6f81858 18 TB_TUNNEL_USB3,
4f807e47
MW
19};
20
93f36ade
MW
21/**
22 * struct tb_tunnel - Tunnel between two ports
23 * @tb: Pointer to the domain
24 * @src_port: Source port of the tunnel
0414bec5
MW
25 * @dst_port: Destination port of the tunnel. For discovered incomplete
26 * tunnels may be %NULL or null adapter port instead.
93f36ade
MW
27 * @paths: All paths required by the tunnel
28 * @npaths: Number of paths in @paths
4f807e47 29 * @init: Optional tunnel specific initialization
6ed541c5 30 * @deinit: Optional tunnel specific de-initialization
93f36ade 31 * @activate: Optional tunnel specific activation/deactivation
06cbcbfa 32 * @maximum_bandwidth: Returns maximum possible bandwidth for this tunnel
6ce35635
MW
33 * @allocated_bandwidth: Return how much bandwidth is allocated for the tunnel
34 * @alloc_bandwidth: Change tunnel bandwidth allocation
a11b88ad 35 * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
0bd680cd
MW
36 * @release_unused_bandwidth: Release all unused bandwidth
37 * @reclaim_available_bandwidth: Reclaim back available bandwidth
93f36ade 38 * @list: Tunnels are linked using this field
4f807e47 39 * @type: Type of the tunnel
0bd680cd 40 * @max_up: Maximum upstream bandwidth (Mb/s) available for the tunnel.
a11b88ad 41 * Only set if the bandwidth needs to be limited.
0bd680cd
MW
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)
6ce35635
MW
46 * @bw_mode: DP bandwidth allocation mode registers can be used to
47 * determine consumed and allocated bandwidth
93f36ade
MW
48 */
49struct tb_tunnel {
3364f0c1 50 struct tb *tb;
93f36ade
MW
51 struct tb_port *src_port;
52 struct tb_port *dst_port;
53 struct tb_path **paths;
54 size_t npaths;
4f807e47 55 int (*init)(struct tb_tunnel *tunnel);
6ed541c5 56 void (*deinit)(struct tb_tunnel *tunnel);
93f36ade 57 int (*activate)(struct tb_tunnel *tunnel, bool activate);
6ce35635
MW
58 int (*maximum_bandwidth)(struct tb_tunnel *tunnel, int *max_up,
59 int *max_down);
60 int (*allocated_bandwidth)(struct tb_tunnel *tunnel, int *allocated_up,
61 int *allocated_down);
62 int (*alloc_bandwidth)(struct tb_tunnel *tunnel, int *alloc_up,
63 int *alloc_down);
7c0ee8fd
MW
64 int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
65 int *consumed_down);
0bd680cd
MW
66 int (*release_unused_bandwidth)(struct tb_tunnel *tunnel);
67 void (*reclaim_available_bandwidth)(struct tb_tunnel *tunnel,
68 int *available_up,
69 int *available_down);
3364f0c1 70 struct list_head list;
4f807e47 71 enum tb_tunnel_type type;
0bd680cd
MW
72 int max_up;
73 int max_down;
74 int allocated_up;
75 int allocated_down;
6ce35635 76 bool bw_mode;
3364f0c1
AN
77};
78
43bddb26
MW
79struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down,
80 bool alloc_hopid);
93f36ade
MW
81struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
82 struct tb_port *down);
43bddb26
MW
83struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
84 bool alloc_hopid);
4f807e47 85struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
9d2d0a5c
MW
86 struct tb_port *out, int link_nr,
87 int max_up, int max_down);
44242d6c 88struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
180b0689
MW
89 struct tb_port *dst, int transmit_path,
90 int transmit_ring, int receive_path,
91 int receive_ring);
92bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path,
93 int transmit_ring, int receive_path, int receive_ring);
43bddb26
MW
94struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down,
95 bool alloc_hopid);
e6f81858 96struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
0bd680cd
MW
97 struct tb_port *down, int max_up,
98 int max_down);
4f807e47 99
93f36ade
MW
100void tb_tunnel_free(struct tb_tunnel *tunnel);
101int tb_tunnel_activate(struct tb_tunnel *tunnel);
102int tb_tunnel_restart(struct tb_tunnel *tunnel);
103void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
104bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
0bd680cd
MW
105bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
106 const struct tb_port *port);
6ce35635
MW
107int tb_tunnel_maximum_bandwidth(struct tb_tunnel *tunnel, int *max_up,
108 int *max_down);
109int tb_tunnel_allocated_bandwidth(struct tb_tunnel *tunnel, int *allocated_up,
110 int *allocated_down);
111int tb_tunnel_alloc_bandwidth(struct tb_tunnel *tunnel, int *alloc_up,
112 int *alloc_down);
7c0ee8fd
MW
113int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
114 int *consumed_down);
0bd680cd
MW
115int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel);
116void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
117 int *available_up,
118 int *available_down);
3364f0c1 119
4f807e47
MW
120static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
121{
122 return tunnel->type == TB_TUNNEL_PCI;
123}
124
125static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
126{
127 return tunnel->type == TB_TUNNEL_DP;
128}
129
44242d6c
MW
130static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
131{
132 return tunnel->type == TB_TUNNEL_DMA;
133}
134
e6f81858
RM
135static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
136{
137 return tunnel->type == TB_TUNNEL_USB3;
138}
139
3364f0c1
AN
140#endif
141