blob: cc952b2be7929ea0ddb1239cb7e73f66847fdfde [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,
Rajmohan Manie6f81852019-12-17 15:33:44 +030018 TB_TUNNEL_USB3,
Mika Westerberg4f807e42018-09-17 16:30:49 +030019};
20
Mika Westerberg93f36ad2017-02-19 13:48:29 +020021/**
22 * struct tb_tunnel - Tunnel between two ports
23 * @tb: Pointer to the domain
24 * @src_port: Source port of the tunnel
Mika Westerberg0414bec2017-02-19 23:43:26 +020025 * @dst_port: Destination port of the tunnel. For discovered incomplete
26 * tunnels may be %NULL or null adapter port instead.
Mika Westerberg93f36ad2017-02-19 13:48:29 +020027 * @paths: All paths required by the tunnel
28 * @npaths: Number of paths in @paths
Mika Westerberg4f807e42018-09-17 16:30:49 +030029 * @init: Optional tunnel specific initialization
Mika Westerberg93f36ad2017-02-19 13:48:29 +020030 * @activate: Optional tunnel specific activation/deactivation
Mika Westerberga11b88a2019-03-26 16:03:48 +030031 * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
Mika Westerberg93f36ad2017-02-19 13:48:29 +020032 * @list: Tunnels are linked using this field
Mika Westerberg4f807e42018-09-17 16:30:49 +030033 * @type: Type of the tunnel
Mika Westerberga11b88a2019-03-26 16:03:48 +030034 * @max_bw: Maximum bandwidth (Mb/s) available for the tunnel (only for DP).
35 * Only set if the bandwidth needs to be limited.
Mika Westerberg93f36ad2017-02-19 13:48:29 +020036 */
37struct tb_tunnel {
Andreas Noever3364f0c2014-06-03 22:04:08 +020038 struct tb *tb;
Mika Westerberg93f36ad2017-02-19 13:48:29 +020039 struct tb_port *src_port;
40 struct tb_port *dst_port;
41 struct tb_path **paths;
42 size_t npaths;
Mika Westerberg4f807e42018-09-17 16:30:49 +030043 int (*init)(struct tb_tunnel *tunnel);
Mika Westerberg93f36ad2017-02-19 13:48:29 +020044 int (*activate)(struct tb_tunnel *tunnel, bool activate);
Mika Westerberg7c0ee8f2020-03-28 12:52:31 +020045 int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
46 int *consumed_down);
Andreas Noever3364f0c2014-06-03 22:04:08 +020047 struct list_head list;
Mika Westerberg4f807e42018-09-17 16:30:49 +030048 enum tb_tunnel_type type;
Mika Westerberga11b88a2019-03-26 16:03:48 +030049 unsigned int max_bw;
Andreas Noever3364f0c2014-06-03 22:04:08 +020050};
51
Mika Westerberg0414bec2017-02-19 23:43:26 +020052struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down);
Mika Westerberg93f36ad2017-02-19 13:48:29 +020053struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
54 struct tb_port *down);
Mika Westerberg4f807e42018-09-17 16:30:49 +030055struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in);
56struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
Mika Westerberga11b88a2019-03-26 16:03:48 +030057 struct tb_port *out, int max_bw);
Mika Westerberg44242d62018-09-28 16:35:32 +030058struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
59 struct tb_port *dst, int transmit_ring,
60 int transmit_path, int receive_ring,
61 int receive_path);
Rajmohan Manie6f81852019-12-17 15:33:44 +030062struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down);
63struct tb_tunnel *tb_tunnel_alloc_usb3(struct tb *tb, struct tb_port *up,
64 struct tb_port *down);
Mika Westerberg4f807e42018-09-17 16:30:49 +030065
Mika Westerberg93f36ad2017-02-19 13:48:29 +020066void tb_tunnel_free(struct tb_tunnel *tunnel);
67int tb_tunnel_activate(struct tb_tunnel *tunnel);
68int tb_tunnel_restart(struct tb_tunnel *tunnel);
69void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
70bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
Mika Westerberga11b88a2019-03-26 16:03:48 +030071bool tb_tunnel_switch_on_path(const struct tb_tunnel *tunnel,
72 const struct tb_switch *sw);
Mika Westerberg7c0ee8f2020-03-28 12:52:31 +020073int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
74 int *consumed_down);
Andreas Noever3364f0c2014-06-03 22:04:08 +020075
Mika Westerberg4f807e42018-09-17 16:30:49 +030076static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
77{
78 return tunnel->type == TB_TUNNEL_PCI;
79}
80
81static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
82{
83 return tunnel->type == TB_TUNNEL_DP;
84}
85
Mika Westerberg44242d62018-09-28 16:35:32 +030086static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
87{
88 return tunnel->type == TB_TUNNEL_DMA;
89}
90
Rajmohan Manie6f81852019-12-17 15:33:44 +030091static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
92{
93 return tunnel->type == TB_TUNNEL_USB3;
94}
95
Andreas Noever3364f0c2014-06-03 22:04:08 +020096#endif
97