thunderbolt: Get rid of usb4_usb3_port_actual_link_rate()
authorMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 31 Aug 2023 11:15:26 +0000 (14:15 +0300)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Fri, 13 Oct 2023 05:49:13 +0000 (08:49 +0300)
It turns out there is no need to use the actual link rate when
reclaiming bandwidth for USB 3.x. The reason is that we use consumed
bandwidth which is coming from xHCI when releasing bandwidth (for
example for DisplayPort tunneling) and this can be anything between
1000 Mb/s to maximum, so when reclaiming we can just bump it up back to
maximum instead of actual link rate (which is always <= maximum).

This allows us to get rid of couple of unnecessary lines of code.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/tb.h
drivers/thunderbolt/tb_regs.h
drivers/thunderbolt/tunnel.c
drivers/thunderbolt/usb4.c

index d2a55ad2fd3e698045db391c14ae79d8a8d3f71e..06046f8ce50ce5d53d20c93b9bf223473399920a 100644 (file)
@@ -1283,7 +1283,6 @@ int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index,
                               unsigned int address, void *buf, size_t size);
 
 int usb4_usb3_port_max_link_rate(struct tb_port *port);
-int usb4_usb3_port_actual_link_rate(struct tb_port *port);
 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw,
                                       int *downstream_bw);
 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
index cf9f2370878a8e027ef4c5fba659d2e7e82f411f..b6893a5093a57aba581bab922539ad3cd19578a0 100644 (file)
@@ -484,9 +484,6 @@ struct tb_regs_port_header {
 #define ADP_USB3_CS_3                          0x03
 #define ADP_USB3_CS_3_SCALE_MASK               GENMASK(5, 0)
 #define ADP_USB3_CS_4                          0x04
-#define ADP_USB3_CS_4_ALR_MASK                 GENMASK(6, 0)
-#define ADP_USB3_CS_4_ALR_20G                  0x1
-#define ADP_USB3_CS_4_ULV                      BIT(7)
 #define ADP_USB3_CS_4_MSLR_MASK                        GENMASK(18, 12)
 #define ADP_USB3_CS_4_MSLR_SHIFT               12
 #define ADP_USB3_CS_4_MSLR_20G                 0x1
index a6810fb368600f15009aa5a8d4f0249d06160ef8..bc82872c84a8c967a8f6dbd6d8dd7a0b46bd236e 100644 (file)
@@ -1790,17 +1790,10 @@ static void tb_usb3_reclaim_available_bandwidth(struct tb_tunnel *tunnel,
 {
        int ret, max_rate, allocate_up, allocate_down;
 
-       ret = usb4_usb3_port_actual_link_rate(tunnel->src_port);
+       ret = tb_usb3_max_link_rate(tunnel->dst_port, tunnel->src_port);
        if (ret < 0) {
-               tb_tunnel_warn(tunnel, "failed to read actual link rate\n");
+               tb_tunnel_warn(tunnel, "failed to read maximum link rate\n");
                return;
-       } else if (!ret) {
-               /* Use maximum link rate if the link valid is not set */
-               ret = tb_usb3_max_link_rate(tunnel->dst_port, tunnel->src_port);
-               if (ret < 0) {
-                       tb_tunnel_warn(tunnel, "failed to read maximum link rate\n");
-                       return;
-               }
        }
 
        /*
index 05ddb224c4649171a20319fb2de1b6bad822ed17..86d6b7b5471b6a8faddec5b0fd3936c168735936 100644 (file)
@@ -1946,35 +1946,6 @@ int usb4_usb3_port_max_link_rate(struct tb_port *port)
        return usb4_usb3_port_max_bandwidth(port, ret);
 }
 
-/**
- * usb4_usb3_port_actual_link_rate() - Established USB3 link rate
- * @port: USB3 adapter port
- *
- * Return actual established link rate of a USB3 adapter in Mb/s. If the
- * link is not up returns %0 and negative errno in case of failure.
- */
-int usb4_usb3_port_actual_link_rate(struct tb_port *port)
-{
-       int ret, lr;
-       u32 val;
-
-       if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port))
-               return -EINVAL;
-
-       ret = tb_port_read(port, &val, TB_CFG_PORT,
-                          port->cap_adap + ADP_USB3_CS_4, 1);
-       if (ret)
-               return ret;
-
-       if (!(val & ADP_USB3_CS_4_ULV))
-               return 0;
-
-       lr = val & ADP_USB3_CS_4_ALR_MASK;
-       ret = lr == ADP_USB3_CS_4_ALR_20G ? 20000 : 10000;
-
-       return usb4_usb3_port_max_bandwidth(port, ret);
-}
-
 static int usb4_usb3_port_cm_request(struct tb_port *port, bool request)
 {
        int ret;