Loading drivers/thunderbolt/retimer.c +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading drivers/thunderbolt/tb.h +17 −4 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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, Loading drivers/thunderbolt/usb4.c +45 −67 Original line number Diff line number Diff line Loading @@ -17,12 +17,6 @@ #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) Loading Loading @@ -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; Loading Loading @@ -1329,7 +1335,19 @@ 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, /** * 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); Loading Loading @@ -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 Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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); } /** Loading Loading
drivers/thunderbolt/retimer.c +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading
drivers/thunderbolt/tb.h +17 −4 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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, Loading
drivers/thunderbolt/usb4.c +45 −67 Original line number Diff line number Diff line Loading @@ -17,12 +17,6 @@ #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) Loading Loading @@ -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; Loading Loading @@ -1329,7 +1335,19 @@ 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, /** * 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); Loading Loading @@ -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 Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading @@ -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); } /** Loading