tunnel.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Thunderbolt driver - Tunneling support
  4. *
  5. * Copyright (c) 2014 Andreas Noever <[email protected]>
  6. * Copyright (C) 2019, Intel Corporation
  7. */
  8. #ifndef TB_TUNNEL_H_
  9. #define TB_TUNNEL_H_
  10. #include "tb.h"
  11. enum tb_tunnel_type {
  12. TB_TUNNEL_PCI,
  13. TB_TUNNEL_DP,
  14. TB_TUNNEL_DMA,
  15. TB_TUNNEL_USB3,
  16. };
  17. /**
  18. * struct tb_tunnel - Tunnel between two ports
  19. * @tb: Pointer to the domain
  20. * @src_port: Source port of the tunnel
  21. * @dst_port: Destination port of the tunnel. For discovered incomplete
  22. * tunnels may be %NULL or null adapter port instead.
  23. * @paths: All paths required by the tunnel
  24. * @npaths: Number of paths in @paths
  25. * @init: Optional tunnel specific initialization
  26. * @deinit: Optional tunnel specific de-initialization
  27. * @activate: Optional tunnel specific activation/deactivation
  28. * @consumed_bandwidth: Return how much bandwidth the tunnel consumes
  29. * @release_unused_bandwidth: Release all unused bandwidth
  30. * @reclaim_available_bandwidth: Reclaim back available bandwidth
  31. * @list: Tunnels are linked using this field
  32. * @type: Type of the tunnel
  33. * @max_up: Maximum upstream bandwidth (Mb/s) available for the tunnel.
  34. * Only set if the bandwidth needs to be limited.
  35. * @max_down: Maximum downstream bandwidth (Mb/s) available for the tunnel.
  36. * Only set if the bandwidth needs to be limited.
  37. * @allocated_up: Allocated upstream bandwidth (only for USB3)
  38. * @allocated_down: Allocated downstream bandwidth (only for USB3)
  39. */
  40. struct tb_tunnel {
  41. struct tb *tb;
  42. struct tb_port *src_port;
  43. struct tb_port *dst_port;
  44. struct tb_path **paths;
  45. size_t npaths;
  46. int (*init)(struct tb_tunnel *tunnel);
  47. void (*deinit)(struct tb_tunnel *tunnel);
  48. int (*activate)(struct tb_tunnel *tunnel, bool activate);
  49. int (*consumed_bandwidth)(struct tb_tunnel *tunnel, int *consumed_up,
  50. int *consumed_down);
  51. int (*release_unused_bandwidth)(struct tb_tunnel *tunnel);
  52. void (*reclaim_available_bandwidth)(struct tb_tunnel *tunnel,
  53. int *available_up,
  54. int *available_down);
  55. struct list_head list;
  56. enum tb_tunnel_type type;
  57. int max_up;
  58. int max_down;
  59. int allocated_up;
  60. int allocated_down;
  61. };
  62. struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down,
  63. bool alloc_hopid);
  64. struct tb_tunnel *tb_tunnel_alloc_pci(struct tb *tb, struct tb_port *up,
  65. struct tb_port *down);
  66. struct tb_tunnel *tb_tunnel_discover_dp(struct tb *tb, struct tb_port *in,
  67. bool alloc_hopid);
  68. struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in,
  69. struct tb_port *out, int link_nr,
  70. int max_up, int max_down);
  71. struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi,
  72. struct tb_port *dst, int transmit_path,
  73. int transmit_ring, int receive_path,
  74. int receive_ring);
  75. bool tb_tunnel_match_dma(const struct tb_tunnel *tunnel, int transmit_path,
  76. int transmit_ring, int receive_path, int receive_ring);
  77. struct tb_tunnel *tb_tunnel_discover_usb3(struct tb *tb, struct tb_port *down,
  78. bool alloc_hopid);
  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. void tb_tunnel_free(struct tb_tunnel *tunnel);
  83. int tb_tunnel_activate(struct tb_tunnel *tunnel);
  84. int tb_tunnel_restart(struct tb_tunnel *tunnel);
  85. void tb_tunnel_deactivate(struct tb_tunnel *tunnel);
  86. bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel);
  87. bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel,
  88. const struct tb_port *port);
  89. int tb_tunnel_consumed_bandwidth(struct tb_tunnel *tunnel, int *consumed_up,
  90. int *consumed_down);
  91. int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel);
  92. void tb_tunnel_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
  93. int *available_up,
  94. int *available_down);
  95. static inline bool tb_tunnel_is_pci(const struct tb_tunnel *tunnel)
  96. {
  97. return tunnel->type == TB_TUNNEL_PCI;
  98. }
  99. static inline bool tb_tunnel_is_dp(const struct tb_tunnel *tunnel)
  100. {
  101. return tunnel->type == TB_TUNNEL_DP;
  102. }
  103. static inline bool tb_tunnel_is_dma(const struct tb_tunnel *tunnel)
  104. {
  105. return tunnel->type == TB_TUNNEL_DMA;
  106. }
  107. static inline bool tb_tunnel_is_usb3(const struct tb_tunnel *tunnel)
  108. {
  109. return tunnel->type == TB_TUNNEL_USB3;
  110. }
  111. #endif