]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
thunderbolt: Make usb4_port_sb_read/write() available outside of usb4.c
authorMika Westerberg <mika.westerberg@linux.intel.com>
Tue, 16 Apr 2024 06:41:14 +0000 (09:41 +0300)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Mon, 17 Jun 2024 09:47:11 +0000 (12:47 +0300)
We need to call these from other files too so make them available
outside of usb4.c.

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

index 6eaaa5074ce82013d1322b0f69de7b316c88e5af..9b66bff98f7eca69d37492586eda27620d3e86fe 100644 (file)
@@ -372,16 +372,16 @@ static int tb_retimer_add(struct tb_port *port, u8 index, u32 auth_status)
        u32 vendor, device;
        int ret;
 
-       ret = usb4_port_retimer_read(port, index, USB4_SB_VENDOR_ID, &vendor,
-                                    sizeof(vendor));
+       ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index,
+                               USB4_SB_VENDOR_ID, &vendor, sizeof(vendor));
        if (ret) {
                if (ret != -ENODEV)
                        tb_port_warn(port, "failed read retimer VendorId: %d\n", ret);
                return ret;
        }
 
-       ret = usb4_port_retimer_read(port, index, USB4_SB_PRODUCT_ID, &device,
-                                    sizeof(device));
+       ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index,
+                               USB4_SB_PRODUCT_ID, &device, sizeof(device));
        if (ret) {
                if (ret != -ENODEV)
                        tb_port_warn(port, "failed read retimer ProductId: %d\n", ret);
index ac9368c7a513fabf50e8de2a4eabb547ddc88117..ab3366fcb0a35fccc7ced640f132b62437016c99 100644 (file)
@@ -1332,6 +1332,23 @@ bool usb4_port_asym_supported(struct tb_port *port);
 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width);
 int usb4_port_asym_start(struct tb_port *port);
 
+/**
+ * enum tb_sb_target - Sideband transaction target
+ * @USB4_SB_TARGET_ROUTER: Target is the router itself
+ * @USB4_SB_TARGET_PARTNER: Target is partner
+ * @USB4_SB_TARGET_RETIMER: Target is retimer
+ */
+enum usb4_sb_target {
+       USB4_SB_TARGET_ROUTER,
+       USB4_SB_TARGET_PARTNER,
+       USB4_SB_TARGET_RETIMER,
+};
+
+int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index,
+                     u8 reg, void *buf, u8 size);
+int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target,
+                      u8 index, u8 reg, const void *buf, u8 size);
+
 int usb4_port_margining_caps(struct tb_port *port, u32 *caps);
 int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes,
                        unsigned int ber_level, bool timing, bool right_high,
@@ -1342,10 +1359,6 @@ int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors);
 
 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index);
 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index);
-int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf,
-                          u8 size);
-int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg,
-                           const void *buf, u8 size);
 int usb4_port_retimer_is_last(struct tb_port *port, u8 index);
 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index);
 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index,
index de480bf2a53def9813ccb5f54a7e99f759ea558f..140e0da3a8decedf033f2704a18ed61e8c8f9f71 100644 (file)
 #define USB4_DATA_RETRIES              3
 #define USB4_DATA_DWORDS               16
 
-enum usb4_sb_target {
-       USB4_SB_TARGET_ROUTER,
-       USB4_SB_TARGET_PARTNER,
-       USB4_SB_TARGET_RETIMER,
-};
-
 #define USB4_NVM_READ_OFFSET_MASK      GENMASK(23, 2)
 #define USB4_NVM_READ_OFFSET_SHIFT     2
 #define USB4_NVM_READ_LENGTH_MASK      GENMASK(27, 24)
@@ -1289,8 +1283,20 @@ static int usb4_port_write_data(struct tb_port *port, const void *data,
                             dwords);
 }
 
-static int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target,
-                            u8 index, u8 reg, void *buf, u8 size)
+/**
+ * usb4_port_sb_read() - Read from sideband register
+ * @port: USB4 port to read
+ * @target: Sideband target
+ * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER
+ * @reg: Sideband register index
+ * @buf: Buffer where the sideband data is copied
+ * @size: Size of @buf
+ *
+ * Reads data from sideband register @reg and copies it into @buf.
+ * Returns %0 in case of success and negative errno in case of failure.
+ */
+int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index,
+                     u8 reg, void *buf, u8 size)
 {
        size_t dwords = DIV_ROUND_UP(size, 4);
        int ret;
@@ -1329,8 +1335,20 @@ static int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target,
        return buf ? usb4_port_read_data(port, buf, dwords) : 0;
 }
 
-static int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target,
-                             u8 index, u8 reg, const void *buf, u8 size)
+/**
+ * usb4_port_sb_write() - Write to sideband register
+ * @port: USB4 port to write
+ * @target: Sideband target
+ * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER
+ * @reg: Sideband register index
+ * @buf: Data to write
+ * @size: Size of @buf
+ *
+ * Writes @buf to sideband register @reg. Returns %0 in case of success
+ * and negative errno in case of failure.
+ */
+int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target,
+                      u8 index, u8 reg, const void *buf, u8 size)
 {
        size_t dwords = DIV_ROUND_UP(size, 4);
        int ret;
@@ -1776,47 +1794,6 @@ int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index)
                                    USB4_SB_OPCODE_UNSET_INBOUND_SBTX, 500);
 }
 
-/**
- * usb4_port_retimer_read() - Read from retimer sideband registers
- * @port: USB4 port
- * @index: Retimer index
- * @reg: Sideband register to read
- * @buf: Data from @reg is stored here
- * @size: Number of bytes to read
- *
- * Function reads retimer sideband registers starting from @reg. The
- * retimer is connected to @port at @index. Returns %0 in case of
- * success, and read data is copied to @buf. If there is no retimer
- * present at given @index returns %-ENODEV. In any other failure
- * returns negative errno.
- */
-int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf,
-                          u8 size)
-{
-       return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, reg, buf,
-                                size);
-}
-
-/**
- * usb4_port_retimer_write() - Write to retimer sideband registers
- * @port: USB4 port
- * @index: Retimer index
- * @reg: Sideband register to write
- * @buf: Data that is written starting from @reg
- * @size: Number of bytes to write
- *
- * Writes retimer sideband registers starting from @reg. The retimer is
- * connected to @port at @index. Returns %0 in case of success. If there
- * is no retimer present at given @index returns %-ENODEV. In any other
- * failure returns negative errno.
- */
-int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg,
-                           const void *buf, u8 size)
-{
-       return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, reg, buf,
-                                 size);
-}
-
 /**
  * usb4_port_retimer_is_last() - Is the retimer last on-board retimer
  * @port: USB4 port
@@ -1837,8 +1814,8 @@ int usb4_port_retimer_is_last(struct tb_port *port, u8 index)
        if (ret)
                return ret;
 
-       ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata,
-                                    sizeof(metadata));
+       ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index,
+                               USB4_SB_METADATA, &metadata, sizeof(metadata));
        return ret ? ret : metadata & 1;
 }
 
@@ -1863,8 +1840,8 @@ int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index)
        if (ret)
                return ret;
 
-       ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata,
-                                    sizeof(metadata));
+       ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index,
+                               USB4_SB_METADATA, &metadata, sizeof(metadata));
        return ret ? ret : metadata & USB4_NVM_SECTOR_SIZE_MASK;
 }
 
@@ -1889,8 +1866,8 @@ int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index,
        metadata = (dwaddress << USB4_NVM_SET_OFFSET_SHIFT) &
                  USB4_NVM_SET_OFFSET_MASK;
 
-       ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata,
-                                     sizeof(metadata));
+       ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index,
+                                USB4_SB_METADATA, &metadata, sizeof(metadata));
        if (ret)
                return ret;
 
@@ -1912,8 +1889,8 @@ static int usb4_port_retimer_nvm_write_next_block(void *data,
        u8 index = info->index;
        int ret;
 
-       ret = usb4_port_retimer_write(port, index, USB4_SB_DATA,
-                                     buf, dwords * 4);
+       ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index,
+                                USB4_SB_DATA, buf, dwords * 4);
        if (ret)
                return ret;
 
@@ -1992,8 +1969,8 @@ int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
        u32 metadata, val;
        int ret;
 
-       ret = usb4_port_retimer_read(port, index, USB4_SB_OPCODE, &val,
-                                    sizeof(val));
+       ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index,
+                               USB4_SB_OPCODE, &val, sizeof(val));
        if (ret)
                return ret;
 
@@ -2004,8 +1981,9 @@ int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
                return 0;
 
        case -EAGAIN:
-               ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA,
-                                            &metadata, sizeof(metadata));
+               ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index,
+                                       USB4_SB_METADATA, &metadata,
+                                       sizeof(metadata));
                if (ret)
                        return ret;
 
@@ -2030,8 +2008,8 @@ static int usb4_port_retimer_nvm_read_block(void *data, unsigned int dwaddress,
        if (dwords < USB4_DATA_DWORDS)
                metadata |= dwords << USB4_NVM_READ_LENGTH_SHIFT;
 
-       ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata,
-                                     sizeof(metadata));
+       ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index,
+                                USB4_SB_METADATA, &metadata, sizeof(metadata));
        if (ret)
                return ret;
 
@@ -2039,8 +2017,8 @@ static int usb4_port_retimer_nvm_read_block(void *data, unsigned int dwaddress,
        if (ret)
                return ret;
 
-       return usb4_port_retimer_read(port, index, USB4_SB_DATA, buf,
-                                     dwords * 4);
+       return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index,
+                                USB4_SB_DATA, buf, dwords * 4);
 }
 
 /**