From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Michael Jamet <michael.jamet@intel.com>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
Andreas Noever <andreas.noever@gmail.com>,
Isaac Hazan <isaac.hazan@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Lukas Wunner <lukas@wunner.de>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org
Subject: [PATCH 18/18] thunderbolt: Add support for USB4 DROM
Date: Thu, 4 Mar 2021 15:31:25 +0300 [thread overview]
Message-ID: <20210304123125.43630-19-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20210304123125.43630-1-mika.westerberg@linux.intel.com>
USB4 router DROM differs sligthly from Thunderbolt 1-3 DROM. For
instance it does not include UID and CRC8 in the header section, and it
has product descriptor genereric entry to describe the product IDs and
related information. If the "Version" field in the DROM header section
reads 3 it means the router only has USB4 DROM and if it reads 1 it
means the router supports TBT3 compatible DROM.
For this reason, update the DROM parsing code to support "pure" USB4
DROMs too.
While there drop the extra empty line at the end of tb_drom_read().
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/thunderbolt/eeprom.c | 104 +++++++++++++++++++++++++++--------
1 file changed, 80 insertions(+), 24 deletions(-)
diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
index aecb0b9f0c75..46d0906a3070 100644
--- a/drivers/thunderbolt/eeprom.c
+++ b/drivers/thunderbolt/eeprom.c
@@ -277,6 +277,16 @@ struct tb_drom_entry_port {
u8 unknown4:2;
} __packed;
+/* USB4 product descriptor */
+struct tb_drom_entry_desc {
+ struct tb_drom_entry_header header;
+ u16 bcdUSBSpec;
+ u16 idVendor;
+ u16 idProduct;
+ u16 bcdProductFWRevision;
+ u32 TID;
+ u8 productHWRevision;
+};
/**
* tb_drom_read_uid_only() - Read UID directly from DROM
@@ -329,6 +339,16 @@ static int tb_drom_parse_entry_generic(struct tb_switch *sw,
if (!sw->device_name)
return -ENOMEM;
break;
+ case 9: {
+ const struct tb_drom_entry_desc *desc =
+ (const struct tb_drom_entry_desc *)entry;
+
+ if (!sw->vendor && !sw->device) {
+ sw->vendor = desc->idVendor;
+ sw->device = desc->idProduct;
+ }
+ break;
+ }
}
return 0;
@@ -521,6 +541,51 @@ static int tb_drom_read_n(struct tb_switch *sw, u16 offset, u8 *val,
return tb_eeprom_read_n(sw, offset, val, count);
}
+static int tb_drom_parse(struct tb_switch *sw)
+{
+ const struct tb_drom_header *header =
+ (const struct tb_drom_header *)sw->drom;
+ u32 crc;
+
+ crc = tb_crc8((u8 *) &header->uid, 8);
+ if (crc != header->uid_crc8) {
+ tb_sw_warn(sw,
+ "DROM UID CRC8 mismatch (expected: %#x, got: %#x), aborting\n",
+ header->uid_crc8, crc);
+ return -EINVAL;
+ }
+ if (!sw->uid)
+ sw->uid = header->uid;
+ sw->vendor = header->vendor_id;
+ sw->device = header->model_id;
+
+ crc = tb_crc32(sw->drom + TB_DROM_DATA_START, header->data_len);
+ if (crc != header->data_crc32) {
+ tb_sw_warn(sw,
+ "DROM data CRC32 mismatch (expected: %#x, got: %#x), continuing\n",
+ header->data_crc32, crc);
+ }
+
+ return tb_drom_parse_entries(sw);
+}
+
+static int usb4_drom_parse(struct tb_switch *sw)
+{
+ const struct tb_drom_header *header =
+ (const struct tb_drom_header *)sw->drom;
+ u32 crc;
+
+ crc = tb_crc32(sw->drom + TB_DROM_DATA_START, header->data_len);
+ if (crc != header->data_crc32) {
+ tb_sw_warn(sw,
+ "DROM data CRC32 mismatch (expected: %#x, got: %#x), aborting\n",
+ header->data_crc32, crc);
+ return -EINVAL;
+ }
+
+ return tb_drom_parse_entries(sw);
+}
+
/**
* tb_drom_read() - Copy DROM to sw->drom and parse it
* @sw: Router whose DROM to read and parse
@@ -534,7 +599,6 @@ static int tb_drom_read_n(struct tb_switch *sw, u16 offset, u8 *val,
int tb_drom_read(struct tb_switch *sw)
{
u16 size;
- u32 crc;
struct tb_drom_header *header;
int res, retries = 1;
@@ -599,30 +663,21 @@ int tb_drom_read(struct tb_switch *sw)
goto err;
}
- crc = tb_crc8((u8 *) &header->uid, 8);
- if (crc != header->uid_crc8) {
- tb_sw_warn(sw,
- "drom uid crc8 mismatch (expected: %#x, got: %#x), aborting\n",
- header->uid_crc8, crc);
- goto err;
- }
- if (!sw->uid)
- sw->uid = header->uid;
- sw->vendor = header->vendor_id;
- sw->device = header->model_id;
+ tb_sw_dbg(sw, "DROM version: %d\n", header->device_rom_revision);
- crc = tb_crc32(sw->drom + TB_DROM_DATA_START, header->data_len);
- if (crc != header->data_crc32) {
- tb_sw_warn(sw,
- "drom data crc32 mismatch (expected: %#x, got: %#x), continuing\n",
- header->data_crc32, crc);
+ switch (header->device_rom_revision) {
+ case 3:
+ res = usb4_drom_parse(sw);
+ break;
+ default:
+ tb_sw_warn(sw, "DROM device_rom_revision %#x unknown\n",
+ header->device_rom_revision);
+ fallthrough;
+ case 1:
+ res = tb_drom_parse(sw);
+ break;
}
- if (header->device_rom_revision > 2)
- tb_sw_warn(sw, "drom device_rom_revision %#x unknown\n",
- header->device_rom_revision);
-
- res = tb_drom_parse_entries(sw);
/* If the DROM parsing fails, wait a moment and retry once */
if (res == -EILSEQ && retries--) {
tb_sw_warn(sw, "parsing DROM failed, retrying\n");
@@ -632,10 +687,11 @@ int tb_drom_read(struct tb_switch *sw)
goto parse;
}
- return res;
+ if (!res)
+ return 0;
+
err:
kfree(sw->drom);
sw->drom = NULL;
return -EIO;
-
}
--
2.30.1
next prev parent reply other threads:[~2021-03-04 12:35 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-04 12:31 [PATCH 00/18] thunderbolt: Align with USB4 inter-domain and DROM specs Mika Westerberg
2021-03-04 12:31 ` [PATCH 01/18] thunderbolt: Disable retry logic for intra-domain control packets Mika Westerberg
2021-03-04 12:31 ` [PATCH 02/18] thunderbolt: Do not pass timeout for tb_cfg_reset() Mika Westerberg
2021-03-04 12:31 ` [PATCH 03/18] thunderbolt: Decrease control channel timeout for software connection manager Mika Westerberg
2021-03-04 12:31 ` [PATCH 04/18] Documentation / thunderbolt: Drop speed/lanes entries for XDomain Mika Westerberg
2021-03-04 12:31 ` [PATCH 05/18] thunderbolt: Add more logging to XDomain connections Mika Westerberg
2021-03-04 12:31 ` [PATCH 06/18] thunderbolt: Do not re-establish XDomain DMA paths automatically Mika Westerberg
2021-03-04 12:31 ` [PATCH 07/18] thunderbolt: Use pseudo-random number as initial property block generation Mika Westerberg
2021-03-04 12:31 ` [PATCH 08/18] thunderbolt: Align XDomain protocol timeouts with the spec Mika Westerberg
2021-03-04 12:31 ` [PATCH 09/18] thunderbolt: Add tb_property_copy_dir() Mika Westerberg
2021-03-04 12:31 ` [PATCH 10/18] thunderbolt: Add support for maxhopid XDomain property Mika Westerberg
2021-03-04 12:31 ` [PATCH 11/18] thunderbolt: Use dedicated flow control for DMA tunnels Mika Westerberg
2021-03-04 12:31 ` [PATCH 12/18] thunderbolt: Drop unused tb_port_set_initial_credits() Mika Westerberg
2021-03-04 12:31 ` [PATCH 13/18] thunderbolt: Allow multiple DMA tunnels over a single XDomain connection Mika Westerberg
2021-03-04 12:31 ` [PATCH 14/18] net: thunderbolt: Align the driver to the USB4 networking spec Mika Westerberg
2021-03-04 12:31 ` [PATCH 15/18] thunderbolt: Add KUnit tests for XDomain properties Mika Westerberg
2021-03-04 12:31 ` [PATCH 16/18] thunderbolt: Add KUnit tests for DMA tunnels Mika Westerberg
2021-03-04 12:31 ` [PATCH 17/18] thunderbolt: Check quirks in tb_switch_add() Mika Westerberg
2021-03-04 12:31 ` Mika Westerberg [this message]
2021-03-18 15:30 ` [PATCH 00/18] thunderbolt: Align with USB4 inter-domain and DROM specs Mika Westerberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210304123125.43630-19-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=davem@davemloft.net \
--cc=isaac.hazan@intel.com \
--cc=kuba@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=michael.jamet@intel.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).