]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
UBUNTU: SAUCE: thunderbolt: Pass metadata directly to usb4_switch_op()
authorMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 3 Dec 2020 08:18:46 +0000 (16:18 +0800)
committerPaolo Pisati <paolo.pisati@canonical.com>
Fri, 8 Jan 2021 12:07:16 +0000 (13:07 +0100)
BugLink: https://bugs.launchpad.net/bugs/1906236
We are going to make usb4_switch_op() to match better the corresponding
firmware (ICM) USB4 router operation proxy interface, so that we can use
either based on the connection manager implementation. For this reason
pass metadata directly to usb4_switch_op().

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
(cherry picked from commit fe265a06319bfa27cfbccd3305d93b33b78f48f2
git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt.git)
Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
Signed-off-by: Timo Aaltonen <timo.aaltonen@canonical.com>
(cherry picked from commit 2a54b99f323fcb578aca5c026fb188b54a6c7549)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
drivers/thunderbolt/usb4.c

index 7bedebfef4f647054bd490bed99cb0055c1e632b..28033731b57db37116dbec498a45bd8b31a9050b 100644 (file)
@@ -92,16 +92,6 @@ static int usb4_switch_op_write_data(struct tb_switch *sw, const void *data,
        return tb_sw_write(sw, data, TB_CFG_SWITCH, ROUTER_CS_9, dwords);
 }
 
-static int usb4_switch_op_read_metadata(struct tb_switch *sw, u32 *metadata)
-{
-       return tb_sw_read(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1);
-}
-
-static int usb4_switch_op_write_metadata(struct tb_switch *sw, u32 metadata)
-{
-       return tb_sw_write(sw, &metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1);
-}
-
 static int usb4_do_read_data(u16 address, void *buf, size_t size,
                             read_block_fn read_block, void *read_block_data)
 {
@@ -171,11 +161,18 @@ static int usb4_do_write_data(unsigned int address, const void *buf, size_t size
        return 0;
 }
 
-static int usb4_switch_op(struct tb_switch *sw, u16 opcode, u8 *status)
+static int usb4_switch_op(struct tb_switch *sw, u16 opcode, u32 *metadata,
+                         u8 *status)
 {
        u32 val;
        int ret;
 
+       if (metadata) {
+               ret = tb_sw_write(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1);
+               if (ret)
+                       return ret;
+       }
+
        val = opcode | ROUTER_CS_26_OV;
        ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1);
        if (ret)
@@ -195,7 +192,9 @@ static int usb4_switch_op(struct tb_switch *sw, u16 opcode, u8 *status)
        if (status)
                *status = (val & ROUTER_CS_26_STATUS_MASK) >>
                        ROUTER_CS_26_STATUS_SHIFT;
-       return 0;
+
+       return metadata ?
+               tb_sw_read(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1) : 0;
 }
 
 static void usb4_switch_check_wakes(struct tb_switch *sw)
@@ -350,11 +349,7 @@ static int usb4_switch_drom_read_block(void *data,
        metadata |= (dwaddress << USB4_DROM_ADDRESS_SHIFT) &
                USB4_DROM_ADDRESS_MASK;
 
-       ret = usb4_switch_op_write_metadata(sw, metadata);
-       if (ret)
-               return ret;
-
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_DROM_READ, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_DROM_READ, &metadata, &status);
        if (ret)
                return ret;
 
@@ -514,17 +509,14 @@ int usb4_switch_nvm_sector_size(struct tb_switch *sw)
        u8 status;
        int ret;
 
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_SECTOR_SIZE, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_SECTOR_SIZE, &metadata,
+                            &status);
        if (ret)
                return ret;
 
        if (status)
                return status == 0x2 ? -EOPNOTSUPP : -EIO;
 
-       ret = usb4_switch_op_read_metadata(sw, &metadata);
-       if (ret)
-               return ret;
-
        return metadata & USB4_NVM_SECTOR_SIZE_MASK;
 }
 
@@ -541,11 +533,7 @@ static int usb4_switch_nvm_read_block(void *data,
        metadata |= (dwaddress << USB4_NVM_READ_OFFSET_SHIFT) &
                   USB4_NVM_READ_OFFSET_MASK;
 
-       ret = usb4_switch_op_write_metadata(sw, metadata);
-       if (ret)
-               return ret;
-
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_READ, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_READ, &metadata, &status);
        if (ret)
                return ret;
 
@@ -583,11 +571,8 @@ static int usb4_switch_nvm_set_offset(struct tb_switch *sw,
        metadata = (dwaddress << USB4_NVM_SET_OFFSET_SHIFT) &
                   USB4_NVM_SET_OFFSET_MASK;
 
-       ret = usb4_switch_op_write_metadata(sw, metadata);
-       if (ret)
-               return ret;
-
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_SET_OFFSET, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_SET_OFFSET, &metadata,
+                            &status);
        if (ret)
                return ret;
 
@@ -605,7 +590,7 @@ static int usb4_switch_nvm_write_next_block(void *data, const void *buf,
        if (ret)
                return ret;
 
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_WRITE, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_WRITE, NULL, &status);
        if (ret)
                return ret;
 
@@ -652,7 +637,7 @@ int usb4_switch_nvm_authenticate(struct tb_switch *sw)
 {
        int ret;
 
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_AUTH, NULL);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_AUTH, NULL, NULL);
        switch (ret) {
        /*
         * The router is power cycled once NVM_AUTH is started so it is
@@ -718,14 +703,12 @@ int usb4_switch_nvm_authenticate_status(struct tb_switch *sw, u32 *status)
  */
 bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in)
 {
+       u32 metadata = in->port;
        u8 status;
        int ret;
 
-       ret = usb4_switch_op_write_metadata(sw, in->port);
-       if (ret)
-               return false;
-
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_QUERY_DP_RESOURCE, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_QUERY_DP_RESOURCE, &metadata,
+                            &status);
        /*
         * If DP resource allocation is not supported assume it is
         * always available.
@@ -750,14 +733,12 @@ bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in)
  */
 int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in)
 {
+       u32 metadata = in->port;
        u8 status;
        int ret;
 
-       ret = usb4_switch_op_write_metadata(sw, in->port);
-       if (ret)
-               return ret;
-
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_ALLOC_DP_RESOURCE, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_ALLOC_DP_RESOURCE, &metadata,
+                            &status);
        if (ret == -EOPNOTSUPP)
                return 0;
        else if (ret)
@@ -775,14 +756,12 @@ int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in)
  */
 int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in)
 {
+       u32 metadata = in->port;
        u8 status;
        int ret;
 
-       ret = usb4_switch_op_write_metadata(sw, in->port);
-       if (ret)
-               return ret;
-
-       ret = usb4_switch_op(sw, USB4_SWITCH_OP_DEALLOC_DP_RESOURCE, &status);
+       ret = usb4_switch_op(sw, USB4_SWITCH_OP_DEALLOC_DP_RESOURCE, &metadata,
+                            &status);
        if (ret == -EOPNOTSUPP)
                return 0;
        else if (ret)