summaryrefslogtreecommitdiff
path: root/drivers/thunderbolt/usb4.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-19 11:42:44 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-19 11:42:44 +0200
commitced7c981f382fc34b941ee3b861d49bdd9180af4 (patch)
tree4992380b86c6f172aec9dea46a3bbfbe2f475e16 /drivers/thunderbolt/usb4.c
parent8e86652e3e7152bba80c3b4d03814e40ede1abc7 (diff)
parent1f15af76784cc902a1fe85e864c7ddf3d74b4130 (diff)
Merge tag 'thunderbolt-for-v6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-next
Mika writes: thunderbolt: Changes for v6.4 merge window This includes following Thunderbolt/USB4 changes for the v6.4 merge window: - Refactoring of DROM read code paths - Convert to use SI units from units.h - A couple of cleanups All these have been in linux-next with no reported issues. * tag 'thunderbolt-for-v6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt: thunderbolt: Introduce usb4_port_sb_opcode_err_to_errno() helper thunderbolt: Make use of SI units from units.h thunderbolt: Get rid of redundant 'else' thunderbolt: Refactor DROM reading thunderbolt: use `tb_eeprom_get_drom_offset` to discover DROM offset
Diffstat (limited to 'drivers/thunderbolt/usb4.c')
-rw-r--r--drivers/thunderbolt/usb4.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c
index a0996cb2893c..485b6e430686 100644
--- a/drivers/thunderbolt/usb4.c
+++ b/drivers/thunderbolt/usb4.c
@@ -9,6 +9,7 @@
#include <linux/delay.h>
#include <linux/ktime.h>
+#include <linux/units.h>
#include "sb_regs.h"
#include "tb.h"
@@ -851,7 +852,7 @@ bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in)
*/
if (ret == -EOPNOTSUPP)
return true;
- else if (ret)
+ if (ret)
return false;
return !status;
@@ -877,7 +878,7 @@ int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in)
&status);
if (ret == -EOPNOTSUPP)
return 0;
- else if (ret)
+ if (ret)
return ret;
return status ? -EBUSY : 0;
@@ -900,7 +901,7 @@ int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in)
&status);
if (ret == -EOPNOTSUPP)
return 0;
- else if (ret)
+ if (ret)
return ret;
return status ? -EIO : 0;
@@ -1302,6 +1303,20 @@ static int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target,
return 0;
}
+static int usb4_port_sb_opcode_err_to_errno(u32 val)
+{
+ switch (val) {
+ case 0:
+ return 0;
+ case USB4_SB_OPCODE_ERR:
+ return -EAGAIN;
+ case USB4_SB_OPCODE_ONS:
+ return -EOPNOTSUPP;
+ default:
+ return -EIO;
+ }
+}
+
static int usb4_port_sb_op(struct tb_port *port, enum usb4_sb_target target,
u8 index, enum usb4_sb_opcode opcode, int timeout_msec)
{
@@ -1324,21 +1339,8 @@ static int usb4_port_sb_op(struct tb_port *port, enum usb4_sb_target target,
if (ret)
return ret;
- switch (val) {
- case 0:
- return 0;
-
- case USB4_SB_OPCODE_ERR:
- return -EAGAIN;
-
- case USB4_SB_OPCODE_ONS:
- return -EOPNOTSUPP;
-
- default:
- if (val != opcode)
- return -EIO;
- break;
- }
+ if (val != opcode)
+ return usb4_port_sb_opcode_err_to_errno(val);
} while (ktime_before(ktime_get(), timeout));
return -ETIMEDOUT;
@@ -1813,12 +1815,13 @@ int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
if (ret)
return ret;
- switch (val) {
+ ret = usb4_port_sb_opcode_err_to_errno(val);
+ switch (ret) {
case 0:
*status = 0;
return 0;
- case USB4_SB_OPCODE_ERR:
+ case -EAGAIN:
ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA,
&metadata, sizeof(metadata));
if (ret)
@@ -1827,11 +1830,8 @@ int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
*status = metadata & USB4_SB_METADATA_NVM_AUTH_WRITE_MASK;
return 0;
- case USB4_SB_OPCODE_ONS:
- return -EOPNOTSUPP;
-
default:
- return -EIO;
+ return ret;
}
}
@@ -1995,7 +1995,7 @@ static unsigned int usb3_bw_to_mbps(u32 bw, u8 scale)
unsigned long uframes;
uframes = bw * 512UL << scale;
- return DIV_ROUND_CLOSEST(uframes * 8000, 1000 * 1000);
+ return DIV_ROUND_CLOSEST(uframes * 8000, MEGA);
}
static u32 mbps_to_usb3_bw(unsigned int mbps, u8 scale)
@@ -2003,7 +2003,7 @@ static u32 mbps_to_usb3_bw(unsigned int mbps, u8 scale)
unsigned long uframes;
/* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */
- uframes = ((unsigned long)mbps * 1000 * 1000) / 8000;
+ uframes = ((unsigned long)mbps * MEGA) / 8000;
return DIV_ROUND_UP(uframes, 512UL << scale);
}