From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Andreas Noever <andreas.noever@gmail.com>,
Michael Jamet <michael.jamet@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
Rajmohan Mani <rajmohan.mani@intel.com>,
Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>,
Lukas Wunner <lukas@wunner.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>,
Mario.Limonciello@dell.com,
Anthony Wong <anthony.wong@canonical.com>,
Oliver Neukum <oneukum@suse.com>,
Christian Kellner <ckellner@redhat.com>,
"David S . Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/9] thunderbolt: Call tb_eeprom_get_drom_offset() from tb_eeprom_read_n()
Date: Tue, 17 Dec 2019 15:33:38 +0300 [thread overview]
Message-ID: <20191217123345.31850-3-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20191217123345.31850-1-mika.westerberg@linux.intel.com>
We are going to re-use tb_drom_read() for USB4 DROM reading as well.
USB4 has separate router operations for this which does not need the
drom_offset. Therefore we move call to tb_eeprom_get_drom_offset() into
tb_eeprom_read_n() where it is needed.
While there change return -ENOSYS to -ENODEV because the former is only
supposed to be used with system calls (invalid syscall nr).
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
drivers/thunderbolt/eeprom.c | 88 ++++++++++++++++++------------------
1 file changed, 43 insertions(+), 45 deletions(-)
diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
index 8dd7de0cc826..540e0105bcc0 100644
--- a/drivers/thunderbolt/eeprom.c
+++ b/drivers/thunderbolt/eeprom.c
@@ -130,13 +130,52 @@ static int tb_eeprom_in(struct tb_switch *sw, u8 *val)
return 0;
}
+/**
+ * tb_eeprom_get_drom_offset - get drom offset within eeprom
+ */
+static int tb_eeprom_get_drom_offset(struct tb_switch *sw, u16 *offset)
+{
+ struct tb_cap_plug_events cap;
+ int res;
+
+ if (!sw->cap_plug_events) {
+ tb_sw_warn(sw, "no TB_CAP_PLUG_EVENTS, cannot read eeprom\n");
+ return -ENODEV;
+ }
+ res = tb_sw_read(sw, &cap, TB_CFG_SWITCH, sw->cap_plug_events,
+ sizeof(cap) / 4);
+ if (res)
+ return res;
+
+ if (!cap.eeprom_ctl.present || cap.eeprom_ctl.not_present) {
+ tb_sw_warn(sw, "no NVM\n");
+ return -ENODEV;
+ }
+
+ if (cap.drom_offset > 0xffff) {
+ tb_sw_warn(sw, "drom offset is larger than 0xffff: %#x\n",
+ cap.drom_offset);
+ return -ENXIO;
+ }
+ *offset = cap.drom_offset;
+ return 0;
+}
+
/**
* tb_eeprom_read_n - read count bytes from offset into val
*/
static int tb_eeprom_read_n(struct tb_switch *sw, u16 offset, u8 *val,
size_t count)
{
+ u16 drom_offset;
int i, res;
+
+ res = tb_eeprom_get_drom_offset(sw, &drom_offset);
+ if (res)
+ return res;
+
+ offset += drom_offset;
+
res = tb_eeprom_active(sw, true);
if (res)
return res;
@@ -238,36 +277,6 @@ struct tb_drom_entry_port {
} __packed;
-/**
- * tb_eeprom_get_drom_offset - get drom offset within eeprom
- */
-static int tb_eeprom_get_drom_offset(struct tb_switch *sw, u16 *offset)
-{
- struct tb_cap_plug_events cap;
- int res;
- if (!sw->cap_plug_events) {
- tb_sw_warn(sw, "no TB_CAP_PLUG_EVENTS, cannot read eeprom\n");
- return -ENOSYS;
- }
- res = tb_sw_read(sw, &cap, TB_CFG_SWITCH, sw->cap_plug_events,
- sizeof(cap) / 4);
- if (res)
- return res;
-
- if (!cap.eeprom_ctl.present || cap.eeprom_ctl.not_present) {
- tb_sw_warn(sw, "no NVM\n");
- return -ENOSYS;
- }
-
- if (cap.drom_offset > 0xffff) {
- tb_sw_warn(sw, "drom offset is larger than 0xffff: %#x\n",
- cap.drom_offset);
- return -ENXIO;
- }
- *offset = cap.drom_offset;
- return 0;
-}
-
/**
* tb_drom_read_uid_only - read uid directly from drom
*
@@ -277,17 +286,11 @@ static int tb_eeprom_get_drom_offset(struct tb_switch *sw, u16 *offset)
int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid)
{
u8 data[9];
- u16 drom_offset;
u8 crc;
- int res = tb_eeprom_get_drom_offset(sw, &drom_offset);
- if (res)
- return res;
-
- if (drom_offset == 0)
- return -ENODEV;
+ int res;
/* read uid */
- res = tb_eeprom_read_n(sw, drom_offset, data, 9);
+ res = tb_eeprom_read_n(sw, 0, data, 9);
if (res)
return res;
@@ -489,7 +492,6 @@ static int tb_drom_copy_nvm(struct tb_switch *sw, u16 *size)
*/
int tb_drom_read(struct tb_switch *sw)
{
- u16 drom_offset;
u16 size;
u32 crc;
struct tb_drom_header *header;
@@ -517,11 +519,7 @@ int tb_drom_read(struct tb_switch *sw)
return 0;
}
- res = tb_eeprom_get_drom_offset(sw, &drom_offset);
- if (res)
- return res;
-
- res = tb_eeprom_read_n(sw, drom_offset + 14, (u8 *) &size, 2);
+ res = tb_eeprom_read_n(sw, 14, (u8 *) &size, 2);
if (res)
return res;
size &= 0x3ff;
@@ -535,7 +533,7 @@ int tb_drom_read(struct tb_switch *sw)
sw->drom = kzalloc(size, GFP_KERNEL);
if (!sw->drom)
return -ENOMEM;
- res = tb_eeprom_read_n(sw, drom_offset, sw->drom, size);
+ res = tb_eeprom_read_n(sw, 0, sw->drom, size);
if (res)
goto err;
--
2.24.0
next prev parent reply other threads:[~2019-12-17 12:34 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-17 12:33 [PATCH v2 0/9] thunderbolt: Add support for USB4 Mika Westerberg
2019-12-17 12:33 ` [PATCH v2 1/9] thunderbolt: Make tb_find_port() available to other files Mika Westerberg
2019-12-17 12:33 ` Mika Westerberg [this message]
2019-12-17 12:33 ` [PATCH v2 3/9] thunderbolt: Populate PG field in hot plug acknowledgment packet Mika Westerberg
2019-12-17 12:46 ` Greg Kroah-Hartman
2019-12-17 14:55 ` Mika Westerberg
2019-12-17 12:47 ` Greg Kroah-Hartman
2019-12-17 14:56 ` Mika Westerberg
2019-12-18 14:35 ` Greg Kroah-Hartman
2019-12-17 12:33 ` [PATCH v2 4/9] thunderbolt: Add initial support for USB4 Mika Westerberg
2019-12-18 9:34 ` Nicholas Johnson
2019-12-18 14:36 ` Greg Kroah-Hartman
2019-12-17 12:33 ` [PATCH v2 5/9] thunderbolt: Update Kconfig entries to USB4 Mika Westerberg
2019-12-18 9:36 ` Nicholas Johnson
2019-12-17 12:33 ` [PATCH v2 6/9] thunderbolt: Make tb_switch_find_cap() available to other files Mika Westerberg
2019-12-17 12:33 ` [PATCH v2 7/9] thunderbolt: Add support for Time Management Unit Mika Westerberg
2019-12-18 9:38 ` Nicholas Johnson
2019-12-17 12:33 ` [PATCH v2 8/9] thunderbolt: Add support for USB 3.x tunnels Mika Westerberg
2019-12-17 12:33 ` [PATCH v2 9/9] thunderbolt: Update documentation with the USB4 information Mika Westerberg
2019-12-18 14:43 ` [PATCH v2 0/9] thunderbolt: Add support for USB4 Greg Kroah-Hartman
2019-12-18 15:30 ` 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=20191217123345.31850-3-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=Mario.Limonciello@dell.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=anthony.wong@canonical.com \
--cc=ckellner@redhat.com \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=michael.jamet@intel.com \
--cc=netdev@vger.kernel.org \
--cc=nicholas.johnson-opensource@outlook.com.au \
--cc=oneukum@suse.com \
--cc=rajmohan.mani@intel.com \
--cc=stern@rowland.harvard.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.