thunderbolt: Fix DROM handling for USB4 DROM
Subsystems (2)
PATCH 1/1 thunderbolt: Fix DROM handling for USB4 DROM
DROM for USB4 host/device has a shorter header than Thunderbolt DROM header. This patch addresses host/device with USB4 DROM (According to spec:
Universal Serial Bus 4 (USB4) Device ROM Specification, Rev 1.0, Feb-2021).
--- drivers/thunderbolt/eeprom.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/thunderbolt/eeprom.c +11 -8
@@ -214,7 +214,10 @@ static u32 tb_crc32(void *data, size_t len)return ~__crc32c_le (~0 , data, len); } -#define TB_DROM_DATA_START 13 +#define TB_DROM_DATA_START 13 +#define TB_DROM_HEADER_LENGTH 22 +/* BYTES 16-21 - nonexistent in USB4 DROM */ +#define TB_DROM_USB4_HEADER_LENGTH 16struct tb_drom_header {/* BYTE 0 */ u8 uid_crc8;/* checksum for uid */
@@ -224,9 +227,9 @@ struct tb_drom_header {u32 data_crc32;/* checksum for data_len bytes starting at byte 13 */ /* BYTE 13 */ u8 device_rom_revision;/* should be <= 1 */ - u16 data_len:10; - u8 __unknown1:6; -/* BYTES 16-21 */ + u16 data_len:12; + u8 reserved:4; +/* BYTES 16-21 - Only for TBT DROM, nonexistent in USB4 DROM */ u16 vendor_id;u16 model_id;u8 model_rev;
@@ -401,10 +404,10 @@ static int tb_drom_parse_entry_port(struct tb_switch *sw,* * Drom must have been copied to sw->drom. */ -static int tb_drom_parse_entries (struct tb_switch *sw) +static int tb_drom_parse_entries (struct tb_switch *sw,size_t header_length) {struct tb_drom_header *header = (void *) sw->drom; -u16 pos =sizeof (*header); +u16 pos = header_length;u16 drom_size = header->data_len +TB_DROM_DATA_START ;int res;
@@ -566,7 +569,7 @@ static int tb_drom_parse(struct tb_switch *sw) header->data_crc32, crc); } -return tb_drom_parse_entries (sw); +return tb_drom_parse_entries (sw,TB_DROM_HEADER_LENGTH ); }static int usb4_drom_parse (struct tb_switch *sw)
@@ -583,7 +586,7 @@ static int usb4_drom_parse(struct tb_switch *sw)return -EINVAL ; } -return tb_drom_parse_entries (sw); +return tb_drom_parse_entries (sw,TB_DROM_USB4_HEADER_LENGTH ); }/**
Signature · 9 lines
2.17.1 --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Quoted 26 lines · Gil Fine
DROM for USB4 host/device has a shorter header than Thunderbolt DROM header. This patch addresses host/device with USB4 DROM (According to spec:
Universal Serial Bus 4 (USB4) Device ROM Specification, Rev 1.0, Feb-2021).Signed-off-by Gil Fine <[email protected]>--- drivers/thunderbolt/eeprom.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/thunderbolt/eeprom.c +4
-1@@ -214,7 +214,10 @@ static u32 tb_crc32(void *data, size_t len)return ~__crc32c_le (~0 , data, len); } -#define TB_DROM_DATA_START 13 +#define TB_DROM_DATA_START 13 +#define TB_DROM_HEADER_LENGTH 22 +/* BYTES 16-21 - nonexistent in USB4 DROM */ +#define TB_DROM_USB4_HEADER_LENGTH 16struct tb_drom_header {/* BYTE 0 */ u8 uid_crc8;/* checksum for uid */
drivers/thunderbolt/eeprom.c struct tb_drom_header { · line 232
Quoted 9 lines
drivers/thunderbolt/eeprom.c +3
-3@@ -224,9 +227,9 @@ struct tb_drom_header {u32 data_crc32;/* checksum for data_len bytes starting at byte 13 */ /* BYTE 13 */ u8 device_rom_revision;/* should be <= 1 */ - u16 data_len:10; - u8 __unknown1:6; -/* BYTES 16-21 */ + u16 data_len:12; + u8 reserved:4; +/* BYTES 16-21 - Only for TBT DROM, nonexistent in USB4 DROM */
What is the odds the above does not work properly for big endian systems?
And why put the comment after the area and not before?
thanks,
greg k-h
Hi Greg,
Quoted 31 lines · Greg KH
Quoted 30 lines · Gil Fine
DROM for USB4 host/device has a shorter header than Thunderbolt DROM header. This patch addresses host/device with USB4 DROM (According to spec:
Universal Serial Bus 4 (USB4) Device ROM Specification, Rev 1.0, Feb-2021).Signed-off-by Gil Fine <[email protected]>--- drivers/thunderbolt/eeprom.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/thunderbolt/eeprom.c +4
-2@@ -214,7 +214,10 @@ static u32 tb_crc32(void *data, size_t len)return ~__crc32c_le (~0 , data, len); } -#define TB_DROM_DATA_START 13 +#define TB_DROM_DATA_START 13 +#define TB_DROM_HEADER_LENGTH 22 +/* BYTES 16-21 - nonexistent in USB4 DROM */ +#define TB_DROM_USB4_HEADER_LENGTH 16struct tb_drom_header {/* BYTE 0 */ u8 uid_crc8;/* checksum for uid */ @@ -224,9 +227,9 @@ struct tb_drom_header {u32 data_crc32;/* checksum for data_len bytes starting at byte 13 */ /* BYTE 13 */ u8 device_rom_revision;/* should be <= 1 */ - u16 data_len:10;
Quoted 8 lines
drivers/thunderbolt/eeprom.c struct tb_drom_header { · line 232
Quoted 5 lines
drivers/thunderbolt/eeprom.c +3
-2- u8 __unknown1:6; -/* BYTES 16-21 */ + u16 data_len:12; + u8 reserved:4; +/* BYTES 16-21 - Only for TBT DROM, nonexistent in USB4 DROM */ What is the odds the above does not work properly for big endian systems?
If you mean the bitfields, we have been trying to get rid of them. Any new code is expected not to introduce new structures like this but it has been OK for existing structures (for now).
Quoted 1 line
And why put the comment after the area and not before?
The gap is there after the "reserved" field.
Thanks!
Quoted 43 lines · Mika Westerberg
Hi Greg,
Quoted 31 lines · Greg KH
Quoted 30 lines · Gil Fine
DROM for USB4 host/device has a shorter header than Thunderbolt DROM header. This patch addresses host/device with USB4 DROM (According to spec:
Universal Serial Bus 4 (USB4) Device ROM Specification, Rev 1.0, Feb-2021).Signed-off-by Gil Fine <[email protected]>--- drivers/thunderbolt/eeprom.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/thunderbolt/eeprom.c +4
-2@@ -214,7 +214,10 @@ static u32 tb_crc32(void *data, size_t len)return ~__crc32c_le (~0 , data, len); } -#define TB_DROM_DATA_START 13 +#define TB_DROM_DATA_START 13 +#define TB_DROM_HEADER_LENGTH 22 +/* BYTES 16-21 - nonexistent in USB4 DROM */ +#define TB_DROM_USB4_HEADER_LENGTH 16struct tb_drom_header {/* BYTE 0 */ u8 uid_crc8;/* checksum for uid */ @@ -224,9 +227,9 @@ struct tb_drom_header {u32 data_crc32;/* checksum for data_len bytes starting at byte 13 */ /* BYTE 13 */ u8 device_rom_revision;/* should be <= 1 */ - u16 data_len:10;Quoted 8 lines
drivers/thunderbolt/eeprom.c struct tb_drom_header { · line 232
Quoted 5 lines
drivers/thunderbolt/eeprom.c +3
-2- u8 __unknown1:6; -/* BYTES 16-21 */ + u16 data_len:12; + u8 reserved:4; +/* BYTES 16-21 - Only for TBT DROM, nonexistent in USB4 DROM */ What is the odds the above does not work properly for big endian systems?
Quoted 3 lines
If you mean the bitfields, we have been trying to get rid of them. Any new code is expected not to introduce new structures like this but it has been OK for existing structures (for now).
Ok, as long as you all realize this is broken :)
Quoted 3 lines
Quoted 1 line
And why put the comment after the area and not before?
The gap is there after the "reserved" field.
Ah, I read the patch wrong, sorry, my fault.
greg k-h
Quoted 44 lines · Greg KH
Quoted 43 lines · Mika Westerberg
Hi Greg,
Quoted 39 lines · Greg KH
Quoted 26 lines · Gil Fine
DROM for USB4 host/device has a shorter header than Thunderbolt DROM header. This patch addresses host/device with USB4 DROM (According to spec:
Universal Serial Bus 4 (USB4) Device ROM Specification, Rev 1.0, Feb-2021).Signed-off-by Gil Fine <[email protected]>--- drivers/thunderbolt/eeprom.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)drivers/thunderbolt/eeprom.c +4
-1@@ -214,7 +214,10 @@ static u32 tb_crc32(void *data, size_t len)return ~__crc32c_le (~0 , data, len); } -#define TB_DROM_DATA_START 13 +#define TB_DROM_DATA_START 13 +#define TB_DROM_HEADER_LENGTH 22 +/* BYTES 16-21 - nonexistent in USB4 DROM */ +#define TB_DROM_USB4_HEADER_LENGTH 16struct tb_drom_header {/* BYTE 0 */ u8 uid_crc8;/* checksum for uid */ drivers/thunderbolt/eeprom.c struct tb_drom_header { · line 232
Quoted 9 lines
drivers/thunderbolt/eeprom.c +3
-3@@ -224,9 +227,9 @@ struct tb_drom_header {u32 data_crc32;/* checksum for data_len bytes starting at byte 13 */ /* BYTE 13 */ u8 device_rom_revision;/* should be <= 1 */ - u16 data_len:10; - u8 __unknown1:6; -/* BYTES 16-21 */ + u16 data_len:12; + u8 reserved:4; +/* BYTES 16-21 - Only for TBT DROM, nonexistent in USB4 DROM */ What is the odds the above does not work properly for big endian systems?
Quoted 5 lines
Quoted 3 lines
If you mean the bitfields, we have been trying to get rid of them. Any new code is expected not to introduce new structures like this but it has been OK for existing structures (for now).
Ok, as long as you all realize this is broken :)
Yes we do :) This is one of the things that need to be sorted out once we have all the "features" in place.
Quoted 5 lines · Gil Fine
DROM for USB4 host/device has a shorter header than Thunderbolt DROM header. This patch addresses host/device with USB4 DROM (According to spec:
Universal Serial Bus 4 (USB4) Device ROM Specification, Rev 1.0, Feb-2021).Signed-off-by Gil Fine <[email protected]>
I did some minor tweaks and applied to thunderbolt.git/next, thanks!