thunderbolt: Make usb4_switch_map_pcie_down() also return enabled ports
[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
93f36ade 30 * @activate: Optional tunnel specific activation/deactivation
a11b88ad 31 * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
93f36ade 32 * @list: Tunnels are linked using this field
4f807e47 33 * @type: Type of the tunnel
a11b88ad
MW
34 * @max_bw: Maximum bandwidth (Mb/s) available for the tunnel (only for DP).
35 * Only set if the bandwidth needs to be limited.
93f36ade
MW
36 */
37struct tb_tunnel {
3364f0c1 38 struct tb *tb;
93f36ade
MW
39 struct tb_port *src_port;
40 struct tb_port *dst_port;
41 struct tb_path **paths;
42 size_t npaths;
4f807e47 43 int (*init)(struct tb_tunnel *tunnel);
93f36ade 44 int (*activate)(struct tb_tunnel *tunnel, bool activate);
a11b88ad 45 int (*consumed_bandwidth)(struct tb_tunnel *tunnel);
3364f0c1 46 struct list_head list;
4f807e47 47 enum tb_tunnel_type type;
a11b88ad 48 unsigned int max_bw;
3364f0c1
AN
49};
50
0414bec5 51struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
93f36ade
MW
52struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
53 struct tb_port *down);
4f807e47
MW
54struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
55struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
a11b88ad 56 struct tb_port *out, int max_bw);
44242d6c
MW
57struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
58 struct tb_port *dst, int transmit_ring,
59 int transmit_path, int receive_ring,
60 int receive_path);
e6f81858
RM
61struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down);
62struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
63 struct tb_port *down);
4f807e47 64
93f36ade
MW
65void tb_tunnel_free(struct tb_tunnel *tunnel);
66int tb_tunnel_activate(struct tb_tunnel *tunnel);
67int tb_tunnel_restart(struct tb_tunnel *tunnel);
68void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
69bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
a11b88ad
MW
70bool tb_tunnel_switch_on_path(const struct tb_tunnel *tunnel,
71 const struct tb_switch *sw);
72int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel);
3364f0c1 73
4f807e47
MW
74static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
75{
76 return tunnel->type == TB_TUNNEL_PCI;
77}
78
79static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
80{
81 return tunnel->type == TB_TUNNEL_DP;
82}
83
44242d6c
MW
84static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
85{
86 return tunnel->type == TB_TUNNEL_DMA;
87}
88
e6f81858
RM
89static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
90{
91 return tunnel->type == TB_TUNNEL_USB3;
92}
93
3364f0c1
AN
94#endif
95