Merge tag 'for_v5.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
[linux-2.6-microblaze.git] / drivers / thunderbolt / tunnel.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Thunderbolt driver - Tunneling support
4  *
5  * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6  * Copyright (C) 2019, Intel Corporation
7  */
8
9 #ifndef TB_TUNNEL_H_
10 #define TB_TUNNEL_H_
11
12 #include "tb.h"
13
14 enum tb_tunnel_type {
15         TB_TUNNEL_PCI,
16         TB_TUNNEL_DP,
17         TB_TUNNEL_DMA,
18         TB_TUNNEL_USB3,
19 };
20
21 /**
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  * @activate: Optional tunnel specific activation/deactivation
31  * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
32  * @release_unused_bandwidth: Release all unused bandwidth
33  * @reclaim_available_bandwidth: Reclaim back available bandwidth
34  * @list: Tunnels are linked using this field
35  * @type: Type of the tunnel
36  * @max_up: Maximum upstream bandwidth (Mb/s) available for the tunnel.
37  *          Only set if the bandwidth needs to be limited.
38  * @max_down: Maximum downstream bandwidth (Mb/s) available for the tunnel.
39  *            Only set if the bandwidth needs to be limited.
40  * @allocated_up: Allocated upstream bandwidth (only for USB3)
41  * @allocated_down: Allocated downstream bandwidth (only for USB3)
42  */
43 struct tb_tunnel {
44         struct tb *tb;
45         struct tb_port *src_port;
46         struct tb_port *dst_port;
47         struct tb_path **paths;
48         size_t npaths;
49         int (*init)(struct tb_tunnel *tunnel);
50         int (*activate)(struct tb_tunnel *tunnel, bool activate);
51         int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
52                                   int *consumed_down);
53         int (*release_unused_bandwidth)(struct tb_tunnel *tunnel);
54         void (*reclaim_available_bandwidth)(struct tb_tunnel *tunnel,
55                                             int *available_up,
56                                             int *available_down);
57         struct list_head list;
58         enum tb_tunnel_type type;
59         int max_up;
60         int max_down;
61         int allocated_up;
62         int allocated_down;
63 };
64
65 struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
66 struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
67                                       struct tb_port *down);
68 struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
69 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
70                                      struct tb_port *out, int max_up,
71                                      int max_down);
72 struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
73                                       struct tb_port *dst, int transmit_path,
74                                       int transmit_ring, int receive_path,
75                                       int receive_ring);
76 bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path,
77                          int transmit_ring, int receive_path, int receive_ring);
78 struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down);
79 struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
80                                        struct tb_port *down, int max_up,
81                                        int max_down);
82
83 void tb_tunnel_free(struct tb_tunnel *tunnel);
84 int tb_tunnel_activate(struct tb_tunnel *tunnel);
85 int tb_tunnel_restart(struct tb_tunnel *tunnel);
86 void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
87 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
88 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
89                             const struct tb_port *port);
90 int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
91                                  int *consumed_down);
92 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel);
93 void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
94                                            int *available_up,
95                                            int *available_down);
96
97 static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
98 {
99         return tunnel->type == TB_TUNNEL_PCI;
100 }
101
102 static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
103 {
104         return tunnel->type == TB_TUNNEL_DP;
105 }
106
107 static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
108 {
109         return tunnel->type == TB_TUNNEL_DMA;
110 }
111
112 static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
113 {
114         return tunnel->type == TB_TUNNEL_USB3;
115 }
116
117 #endif
118