License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-06-04 04:04:11 +08:00
|
|
|
/*
|
2018-10-01 17:31:22 +08:00
|
|
|
* Thunderbolt driver - eeprom access
|
2014-06-04 04:04:11 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
|
2018-10-01 17:31:22 +08:00
|
|
|
* Copyright (C) 2018, Intel Corporation
|
2014-06-04 04:04:11 +08:00
|
|
|
*/
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
#include <linux/crc32.h>
|
2020-09-07 17:20:36 +08:00
|
|
|
#include <linux/delay.h>
|
thunderbolt: Use Device ROM retrieved from EFI
Macs with Thunderbolt 1 do not have a unit-specific DROM: The DROM is
empty with uid 0x1000000000000. (Apple started factory-burning a unit-
specific DROM with Thunderbolt 2.)
Instead, the NHI EFI driver supplies a DROM in a device property. Use
it if available. It's only available when booting with the efistub.
If it's not available, silently fall back to our hardcoded DROM.
The size of the DROM is always 256 bytes. The number is hardcoded into
the NHI EFI driver. This commit can deal with an arbitrary size however,
just in case they ever change that.
Background information: The EFI firmware volume contains ROM files for
the NHI, GMUX and several other chips as well as key material. This
strategy allows Apple to deploy ROM or key updates by simply publishing
an EFI firmware update on their website. Drivers do not access those
files directly but rather through a file server via EFI protocol
AC5E4829-A8FD-440B-AF33-9FFE013B12D8. Files are identified by GUID, the
NHI DROM has 339370BD-CFC6-4454-8EF7-704653120818.
The NHI EFI driver amends that file with a unit-specific uid. The uid
has 64 bit but its entropy is much lower: 24 bit represent the model,
24 bit are taken from a serial number, 16 bit are fixed. The NHI EFI
driver obtains the serial number via the DataHub protocol, copies it
into the DROM, calculates the CRC and submits the result as a device
property.
A modification is needed in the resume code where we currently read the
uid of all switches in the hierarchy to detect plug events that occurred
during sleep. On Thunderbolt 1 root switches this will now lead to a
mismatch between the uid of the empty DROM and the EFI DROM. Exempt the
root switch from this check: It's built in, so the uid should never
change. However we continue to *read* the uid of the root switch, this
seems like a good way to test its reachability after resume.
Tested-by: Lukas Wunner <lukas@wunner.de> [MacBookPro9,1]
Tested-by: Pierre Moreau <pierre.morrow@free.fr> [MacBookPro11,3]
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Acked-by: Andreas Noever <andreas.noever@gmail.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Pedro Vilaça <reverser@put.as>
Cc: Peter Jones <pjones@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20161112213237.8804-10-matt@codeblueprint.co.uk
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-11-13 05:32:37 +08:00
|
|
|
#include <linux/property.h>
|
2014-06-20 17:02:29 +08:00
|
|
|
#include <linux/slab.h>
|
2014-06-04 04:04:11 +08:00
|
|
|
#include "tb.h"
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-04 04:04:11 +08:00
|
|
|
* tb_eeprom_ctl_write() - write control word
|
|
|
|
*/
|
|
|
|
static int tb_eeprom_ctl_write(struct tb_switch *sw, struct tb_eeprom_ctl *ctl)
|
|
|
|
{
|
|
|
|
return tb_sw_write(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + 4, 1);
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-04 04:04:11 +08:00
|
|
|
* tb_eeprom_ctl_write() - read control word
|
|
|
|
*/
|
|
|
|
static int tb_eeprom_ctl_read(struct tb_switch *sw, struct tb_eeprom_ctl *ctl)
|
|
|
|
{
|
|
|
|
return tb_sw_read(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + 4, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum tb_eeprom_transfer {
|
|
|
|
TB_EEPROM_IN,
|
|
|
|
TB_EEPROM_OUT,
|
|
|
|
};
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-04 04:04:11 +08:00
|
|
|
* tb_eeprom_active - enable rom access
|
|
|
|
*
|
|
|
|
* WARNING: Always disable access after usage. Otherwise the controller will
|
|
|
|
* fail to reprobe.
|
|
|
|
*/
|
|
|
|
static int tb_eeprom_active(struct tb_switch *sw, bool enable)
|
|
|
|
{
|
|
|
|
struct tb_eeprom_ctl ctl;
|
|
|
|
int res = tb_eeprom_ctl_read(sw, &ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
if (enable) {
|
|
|
|
ctl.access_high = 1;
|
|
|
|
res = tb_eeprom_ctl_write(sw, &ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
ctl.access_low = 0;
|
|
|
|
return tb_eeprom_ctl_write(sw, &ctl);
|
|
|
|
} else {
|
|
|
|
ctl.access_low = 1;
|
|
|
|
res = tb_eeprom_ctl_write(sw, &ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
ctl.access_high = 0;
|
|
|
|
return tb_eeprom_ctl_write(sw, &ctl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-04 04:04:11 +08:00
|
|
|
* tb_eeprom_transfer - transfer one bit
|
|
|
|
*
|
|
|
|
* If TB_EEPROM_IN is passed, then the bit can be retrieved from ctl->data_in.
|
|
|
|
* If TB_EEPROM_OUT is passed, then ctl->data_out will be written.
|
|
|
|
*/
|
|
|
|
static int tb_eeprom_transfer(struct tb_switch *sw, struct tb_eeprom_ctl *ctl,
|
|
|
|
enum tb_eeprom_transfer direction)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
if (direction == TB_EEPROM_OUT) {
|
|
|
|
res = tb_eeprom_ctl_write(sw, ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
ctl->clock = 1;
|
|
|
|
res = tb_eeprom_ctl_write(sw, ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
if (direction == TB_EEPROM_IN) {
|
|
|
|
res = tb_eeprom_ctl_read(sw, ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
ctl->clock = 0;
|
|
|
|
return tb_eeprom_ctl_write(sw, ctl);
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-04 04:04:11 +08:00
|
|
|
* tb_eeprom_out - write one byte to the bus
|
|
|
|
*/
|
|
|
|
static int tb_eeprom_out(struct tb_switch *sw, u8 val)
|
|
|
|
{
|
|
|
|
struct tb_eeprom_ctl ctl;
|
|
|
|
int i;
|
|
|
|
int res = tb_eeprom_ctl_read(sw, &ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
ctl.data_out = val & 0x80;
|
|
|
|
res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_OUT);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
val <<= 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-04 04:04:11 +08:00
|
|
|
* tb_eeprom_in - read one byte from the bus
|
|
|
|
*/
|
|
|
|
static int tb_eeprom_in(struct tb_switch *sw, u8 *val)
|
|
|
|
{
|
|
|
|
struct tb_eeprom_ctl ctl;
|
|
|
|
int i;
|
|
|
|
int res = tb_eeprom_ctl_read(sw, &ctl);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
*val = 0;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
*val <<= 1;
|
|
|
|
res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_IN);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
*val |= ctl.data_in;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2019-12-17 20:33:38 +08:00
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-04 04:04:11 +08:00
|
|
|
* 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)
|
|
|
|
{
|
2019-12-17 20:33:38 +08:00
|
|
|
u16 drom_offset;
|
2014-06-04 04:04:11 +08:00
|
|
|
int i, res;
|
2019-12-17 20:33:38 +08:00
|
|
|
|
|
|
|
res = tb_eeprom_get_drom_offset(sw, &drom_offset);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
offset += drom_offset;
|
|
|
|
|
2014-06-04 04:04:11 +08:00
|
|
|
res = tb_eeprom_active(sw, true);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
res = tb_eeprom_out(sw, 3);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
res = tb_eeprom_out(sw, offset >> 8);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
res = tb_eeprom_out(sw, offset);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
res = tb_eeprom_in(sw, val + i);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return tb_eeprom_active(sw, false);
|
|
|
|
}
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
static u8 tb_crc8(u8 *data, int len)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
u8 val = 0xff;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
val ^= data[i];
|
|
|
|
for (j = 0; j < 8; j++)
|
|
|
|
val = (val << 1) ^ ((val & 0x80) ? 7 : 0);
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 tb_crc32(void *data, size_t len)
|
|
|
|
{
|
|
|
|
return ~__crc32c_le(~0, data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TB_DROM_DATA_START 13
|
|
|
|
struct tb_drom_header {
|
|
|
|
/* BYTE 0 */
|
|
|
|
u8 uid_crc8; /* checksum for uid */
|
|
|
|
/* BYTES 1-8 */
|
|
|
|
u64 uid;
|
|
|
|
/* BYTES 9-12 */
|
|
|
|
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 vendor_id;
|
|
|
|
u16 model_id;
|
|
|
|
u8 model_rev;
|
|
|
|
u8 eeprom_rev;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
enum tb_drom_entry_type {
|
2014-06-21 03:42:24 +08:00
|
|
|
/* force unsigned to prevent "one-bit signed bitfield" warning */
|
|
|
|
TB_DROM_ENTRY_GENERIC = 0U,
|
2014-06-13 05:11:46 +08:00
|
|
|
TB_DROM_ENTRY_PORT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tb_drom_entry_header {
|
|
|
|
u8 len;
|
|
|
|
u8 index:6;
|
|
|
|
bool port_disabled:1; /* only valid if type is TB_DROM_ENTRY_PORT */
|
|
|
|
enum tb_drom_entry_type type:1;
|
|
|
|
} __packed;
|
|
|
|
|
2017-06-06 20:25:05 +08:00
|
|
|
struct tb_drom_entry_generic {
|
|
|
|
struct tb_drom_entry_header header;
|
2020-02-12 07:19:11 +08:00
|
|
|
u8 data[];
|
2017-06-06 20:25:05 +08:00
|
|
|
} __packed;
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
struct tb_drom_entry_port {
|
|
|
|
/* BYTES 0-1 */
|
|
|
|
struct tb_drom_entry_header header;
|
|
|
|
/* BYTE 2 */
|
|
|
|
u8 dual_link_port_rid:4;
|
|
|
|
u8 link_nr:1;
|
|
|
|
u8 unknown1:2;
|
|
|
|
bool has_dual_link_port:1;
|
|
|
|
|
|
|
|
/* BYTE 3 */
|
|
|
|
u8 dual_link_port_nr:6;
|
|
|
|
u8 unknown2:2;
|
|
|
|
|
|
|
|
/* BYTES 4 - 5 TODO decode */
|
|
|
|
u8 micro2:4;
|
|
|
|
u8 micro1:4;
|
|
|
|
u8 micro3;
|
|
|
|
|
2016-03-20 20:57:20 +08:00
|
|
|
/* BYTES 6-7, TODO: verify (find hardware that has these set) */
|
2014-06-13 05:11:46 +08:00
|
|
|
u8 peer_port_rid:4;
|
|
|
|
u8 unknown3:3;
|
|
|
|
bool has_peer_port:1;
|
|
|
|
u8 peer_port_nr:6;
|
|
|
|
u8 unknown4:2;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-28 18:18:13 +08:00
|
|
|
* tb_drom_read_uid_only() - Read UID directly from DROM
|
|
|
|
* @sw: Router whose UID to read
|
|
|
|
* @uid: UID is placed here
|
2014-06-13 05:11:46 +08:00
|
|
|
*
|
|
|
|
* Does not use the cached copy in sw->drom. Used during resume to check switch
|
|
|
|
* identity.
|
|
|
|
*/
|
|
|
|
int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid)
|
|
|
|
{
|
|
|
|
u8 data[9];
|
|
|
|
u8 crc;
|
2019-12-17 20:33:38 +08:00
|
|
|
int res;
|
2017-06-06 20:24:55 +08:00
|
|
|
|
2014-06-04 04:04:11 +08:00
|
|
|
/* read uid */
|
2019-12-17 20:33:38 +08:00
|
|
|
res = tb_eeprom_read_n(sw, 0, data, 9);
|
2014-06-04 04:04:11 +08:00
|
|
|
if (res)
|
|
|
|
return res;
|
2014-06-13 05:11:46 +08:00
|
|
|
|
|
|
|
crc = tb_crc8(data + 1, 8);
|
|
|
|
if (crc != data[0]) {
|
2017-05-18 15:42:49 +08:00
|
|
|
tb_sw_warn(sw, "uid crc8 mismatch (expected: %#x, got: %#x)\n",
|
2014-06-13 05:11:46 +08:00
|
|
|
data[0], crc);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2014-06-04 04:04:11 +08:00
|
|
|
*uid = *(u64 *)(data+1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:25:05 +08:00
|
|
|
static int tb_drom_parse_entry_generic(struct tb_switch *sw,
|
|
|
|
struct tb_drom_entry_header *header)
|
|
|
|
{
|
|
|
|
const struct tb_drom_entry_generic *entry =
|
|
|
|
(const struct tb_drom_entry_generic *)header;
|
|
|
|
|
|
|
|
switch (header->index) {
|
|
|
|
case 1:
|
|
|
|
/* Length includes 2 bytes header so remove it before copy */
|
|
|
|
sw->vendor_name = kstrndup(entry->data,
|
|
|
|
header->len - sizeof(*header), GFP_KERNEL);
|
|
|
|
if (!sw->vendor_name)
|
|
|
|
return -ENOMEM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
sw->device_name = kstrndup(entry->data,
|
|
|
|
header->len - sizeof(*header), GFP_KERNEL);
|
|
|
|
if (!sw->device_name)
|
|
|
|
return -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:25:04 +08:00
|
|
|
static int tb_drom_parse_entry_port(struct tb_switch *sw,
|
|
|
|
struct tb_drom_entry_header *header)
|
2014-06-13 05:11:46 +08:00
|
|
|
{
|
|
|
|
struct tb_port *port;
|
|
|
|
int res;
|
|
|
|
enum tb_port_type type;
|
2014-06-04 04:04:11 +08:00
|
|
|
|
2017-07-25 22:41:58 +08:00
|
|
|
/*
|
|
|
|
* Some DROMs list more ports than the controller actually has
|
|
|
|
* so we skip those but allow the parser to continue.
|
|
|
|
*/
|
|
|
|
if (header->index > sw->config.max_port_number) {
|
|
|
|
dev_info_once(&sw->dev, "ignoring unnecessary extra entries in DROM\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
port = &sw->ports[header->index];
|
|
|
|
port->disabled = header->port_disabled;
|
|
|
|
if (port->disabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
res = tb_port_read(port, &type, TB_CFG_PORT, 2, 1);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
type &= 0xffffff;
|
|
|
|
|
|
|
|
if (type == TB_TYPE_PORT) {
|
|
|
|
struct tb_drom_entry_port *entry = (void *) header;
|
|
|
|
if (header->len != sizeof(*entry)) {
|
|
|
|
tb_sw_warn(sw,
|
2014-06-20 21:52:11 +08:00
|
|
|
"port entry has size %#x (expected %#zx)\n",
|
2014-06-13 05:11:46 +08:00
|
|
|
header->len, sizeof(struct tb_drom_entry_port));
|
|
|
|
return -EIO;
|
|
|
|
}
|
2017-06-06 20:25:04 +08:00
|
|
|
port->link_nr = entry->link_nr;
|
|
|
|
if (entry->has_dual_link_port)
|
|
|
|
port->dual_link_port =
|
|
|
|
&port->sw->ports[entry->dual_link_port_nr];
|
2014-06-13 05:11:46 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
2014-06-13 05:11:46 +08:00
|
|
|
* tb_drom_parse_entries - parse the linked list of drom entries
|
|
|
|
*
|
|
|
|
* Drom must have been copied to sw->drom.
|
|
|
|
*/
|
|
|
|
static int tb_drom_parse_entries(struct tb_switch *sw)
|
|
|
|
{
|
|
|
|
struct tb_drom_header *header = (void *) sw->drom;
|
|
|
|
u16 pos = sizeof(*header);
|
|
|
|
u16 drom_size = header->data_len + TB_DROM_DATA_START;
|
2017-06-06 20:25:04 +08:00
|
|
|
int res;
|
2014-06-13 05:11:46 +08:00
|
|
|
|
|
|
|
while (pos < drom_size) {
|
|
|
|
struct tb_drom_entry_header *entry = (void *) (sw->drom + pos);
|
|
|
|
if (pos + 1 == drom_size || pos + entry->len > drom_size
|
|
|
|
|| !entry->len) {
|
2020-09-07 17:20:36 +08:00
|
|
|
tb_sw_warn(sw, "DROM buffer overrun\n");
|
|
|
|
return -EILSEQ;
|
2014-06-13 05:11:46 +08:00
|
|
|
}
|
|
|
|
|
2017-06-06 20:25:04 +08:00
|
|
|
switch (entry->type) {
|
|
|
|
case TB_DROM_ENTRY_GENERIC:
|
2017-06-06 20:25:05 +08:00
|
|
|
res = tb_drom_parse_entry_generic(sw, entry);
|
2017-06-06 20:25:04 +08:00
|
|
|
break;
|
|
|
|
case TB_DROM_ENTRY_PORT:
|
|
|
|
res = tb_drom_parse_entry_port(sw, entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res)
|
|
|
|
return res;
|
2014-06-13 05:11:46 +08:00
|
|
|
|
|
|
|
pos += entry->len;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:25:46 +08:00
|
|
|
/*
|
thunderbolt: Use Device ROM retrieved from EFI
Macs with Thunderbolt 1 do not have a unit-specific DROM: The DROM is
empty with uid 0x1000000000000. (Apple started factory-burning a unit-
specific DROM with Thunderbolt 2.)
Instead, the NHI EFI driver supplies a DROM in a device property. Use
it if available. It's only available when booting with the efistub.
If it's not available, silently fall back to our hardcoded DROM.
The size of the DROM is always 256 bytes. The number is hardcoded into
the NHI EFI driver. This commit can deal with an arbitrary size however,
just in case they ever change that.
Background information: The EFI firmware volume contains ROM files for
the NHI, GMUX and several other chips as well as key material. This
strategy allows Apple to deploy ROM or key updates by simply publishing
an EFI firmware update on their website. Drivers do not access those
files directly but rather through a file server via EFI protocol
AC5E4829-A8FD-440B-AF33-9FFE013B12D8. Files are identified by GUID, the
NHI DROM has 339370BD-CFC6-4454-8EF7-704653120818.
The NHI EFI driver amends that file with a unit-specific uid. The uid
has 64 bit but its entropy is much lower: 24 bit represent the model,
24 bit are taken from a serial number, 16 bit are fixed. The NHI EFI
driver obtains the serial number via the DataHub protocol, copies it
into the DROM, calculates the CRC and submits the result as a device
property.
A modification is needed in the resume code where we currently read the
uid of all switches in the hierarchy to detect plug events that occurred
during sleep. On Thunderbolt 1 root switches this will now lead to a
mismatch between the uid of the empty DROM and the EFI DROM. Exempt the
root switch from this check: It's built in, so the uid should never
change. However we continue to *read* the uid of the root switch, this
seems like a good way to test its reachability after resume.
Tested-by: Lukas Wunner <lukas@wunner.de> [MacBookPro9,1]
Tested-by: Pierre Moreau <pierre.morrow@free.fr> [MacBookPro11,3]
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Acked-by: Andreas Noever <andreas.noever@gmail.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Pedro Vilaça <reverser@put.as>
Cc: Peter Jones <pjones@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20161112213237.8804-10-matt@codeblueprint.co.uk
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-11-13 05:32:37 +08:00
|
|
|
* tb_drom_copy_efi - copy drom supplied by EFI to sw->drom if present
|
|
|
|
*/
|
|
|
|
static int tb_drom_copy_efi(struct tb_switch *sw, u16 *size)
|
|
|
|
{
|
|
|
|
struct device *dev = &sw->tb->nhi->pdev->dev;
|
|
|
|
int len, res;
|
|
|
|
|
2019-07-24 03:21:54 +08:00
|
|
|
len = device_property_count_u8(dev, "ThunderboltDROM");
|
thunderbolt: Use Device ROM retrieved from EFI
Macs with Thunderbolt 1 do not have a unit-specific DROM: The DROM is
empty with uid 0x1000000000000. (Apple started factory-burning a unit-
specific DROM with Thunderbolt 2.)
Instead, the NHI EFI driver supplies a DROM in a device property. Use
it if available. It's only available when booting with the efistub.
If it's not available, silently fall back to our hardcoded DROM.
The size of the DROM is always 256 bytes. The number is hardcoded into
the NHI EFI driver. This commit can deal with an arbitrary size however,
just in case they ever change that.
Background information: The EFI firmware volume contains ROM files for
the NHI, GMUX and several other chips as well as key material. This
strategy allows Apple to deploy ROM or key updates by simply publishing
an EFI firmware update on their website. Drivers do not access those
files directly but rather through a file server via EFI protocol
AC5E4829-A8FD-440B-AF33-9FFE013B12D8. Files are identified by GUID, the
NHI DROM has 339370BD-CFC6-4454-8EF7-704653120818.
The NHI EFI driver amends that file with a unit-specific uid. The uid
has 64 bit but its entropy is much lower: 24 bit represent the model,
24 bit are taken from a serial number, 16 bit are fixed. The NHI EFI
driver obtains the serial number via the DataHub protocol, copies it
into the DROM, calculates the CRC and submits the result as a device
property.
A modification is needed in the resume code where we currently read the
uid of all switches in the hierarchy to detect plug events that occurred
during sleep. On Thunderbolt 1 root switches this will now lead to a
mismatch between the uid of the empty DROM and the EFI DROM. Exempt the
root switch from this check: It's built in, so the uid should never
change. However we continue to *read* the uid of the root switch, this
seems like a good way to test its reachability after resume.
Tested-by: Lukas Wunner <lukas@wunner.de> [MacBookPro9,1]
Tested-by: Pierre Moreau <pierre.morrow@free.fr> [MacBookPro11,3]
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Acked-by: Andreas Noever <andreas.noever@gmail.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Pedro Vilaça <reverser@put.as>
Cc: Peter Jones <pjones@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20161112213237.8804-10-matt@codeblueprint.co.uk
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-11-13 05:32:37 +08:00
|
|
|
if (len < 0 || len < sizeof(struct tb_drom_header))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sw->drom = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!sw->drom)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
res = device_property_read_u8_array(dev, "ThunderboltDROM", sw->drom,
|
|
|
|
len);
|
|
|
|
if (res)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
*size = ((struct tb_drom_header *)sw->drom)->data_len +
|
|
|
|
TB_DROM_DATA_START;
|
|
|
|
if (*size > len)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
kfree(sw->drom);
|
|
|
|
sw->drom = NULL;
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:25:14 +08:00
|
|
|
static int tb_drom_copy_nvm(struct tb_switch *sw, u16 *size)
|
|
|
|
{
|
|
|
|
u32 drom_offset;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!sw->dma_port)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = tb_sw_read(sw, &drom_offset, TB_CFG_SWITCH,
|
|
|
|
sw->cap_plug_events + 12, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!drom_offset)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = dma_port_flash_read(sw->dma_port, drom_offset + 14, size,
|
|
|
|
sizeof(*size));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Size includes CRC8 + UID + CRC32 */
|
|
|
|
*size += 1 + 8 + 4;
|
|
|
|
sw->drom = kzalloc(*size, GFP_KERNEL);
|
|
|
|
if (!sw->drom)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = dma_port_flash_read(sw->dma_port, drom_offset, sw->drom, *size);
|
|
|
|
if (ret)
|
|
|
|
goto err_free;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read UID from the minimal DROM because the one in NVM is just
|
|
|
|
* a placeholder.
|
|
|
|
*/
|
|
|
|
tb_drom_read_uid_only(sw, &sw->uid);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_free:
|
|
|
|
kfree(sw->drom);
|
|
|
|
sw->drom = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:33:40 +08:00
|
|
|
static int usb4_copy_host_drom(struct tb_switch *sw, u16 *size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = usb4_switch_drom_read(sw, 14, size, sizeof(*size));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Size includes CRC8 + UID + CRC32 */
|
|
|
|
*size += 1 + 8 + 4;
|
|
|
|
sw->drom = kzalloc(*size, GFP_KERNEL);
|
|
|
|
if (!sw->drom)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = usb4_switch_drom_read(sw, 0, sw->drom, *size);
|
|
|
|
if (ret) {
|
|
|
|
kfree(sw->drom);
|
|
|
|
sw->drom = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tb_drom_read_n(struct tb_switch *sw, u16 offset, u8 *val,
|
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
if (tb_switch_is_usb4(sw))
|
|
|
|
return usb4_switch_drom_read(sw, offset, val, count);
|
|
|
|
return tb_eeprom_read_n(sw, offset, val, count);
|
|
|
|
}
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
/**
|
2021-01-28 18:18:13 +08:00
|
|
|
* tb_drom_read() - Copy DROM to sw->drom and parse it
|
|
|
|
* @sw: Router whose DROM to read and parse
|
|
|
|
*
|
|
|
|
* This function reads router DROM and if successful parses the entries and
|
|
|
|
* populates the fields in @sw accordingly. Can be called for any router
|
|
|
|
* generation.
|
|
|
|
*
|
|
|
|
* Returns %0 in case of success and negative errno otherwise.
|
2014-06-13 05:11:46 +08:00
|
|
|
*/
|
|
|
|
int tb_drom_read(struct tb_switch *sw)
|
|
|
|
{
|
|
|
|
u16 size;
|
|
|
|
u32 crc;
|
|
|
|
struct tb_drom_header *header;
|
2020-09-07 17:20:36 +08:00
|
|
|
int res, retries = 1;
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
if (sw->drom)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (tb_route(sw) == 0) {
|
thunderbolt: Use Device ROM retrieved from EFI
Macs with Thunderbolt 1 do not have a unit-specific DROM: The DROM is
empty with uid 0x1000000000000. (Apple started factory-burning a unit-
specific DROM with Thunderbolt 2.)
Instead, the NHI EFI driver supplies a DROM in a device property. Use
it if available. It's only available when booting with the efistub.
If it's not available, silently fall back to our hardcoded DROM.
The size of the DROM is always 256 bytes. The number is hardcoded into
the NHI EFI driver. This commit can deal with an arbitrary size however,
just in case they ever change that.
Background information: The EFI firmware volume contains ROM files for
the NHI, GMUX and several other chips as well as key material. This
strategy allows Apple to deploy ROM or key updates by simply publishing
an EFI firmware update on their website. Drivers do not access those
files directly but rather through a file server via EFI protocol
AC5E4829-A8FD-440B-AF33-9FFE013B12D8. Files are identified by GUID, the
NHI DROM has 339370BD-CFC6-4454-8EF7-704653120818.
The NHI EFI driver amends that file with a unit-specific uid. The uid
has 64 bit but its entropy is much lower: 24 bit represent the model,
24 bit are taken from a serial number, 16 bit are fixed. The NHI EFI
driver obtains the serial number via the DataHub protocol, copies it
into the DROM, calculates the CRC and submits the result as a device
property.
A modification is needed in the resume code where we currently read the
uid of all switches in the hierarchy to detect plug events that occurred
during sleep. On Thunderbolt 1 root switches this will now lead to a
mismatch between the uid of the empty DROM and the EFI DROM. Exempt the
root switch from this check: It's built in, so the uid should never
change. However we continue to *read* the uid of the root switch, this
seems like a good way to test its reachability after resume.
Tested-by: Lukas Wunner <lukas@wunner.de> [MacBookPro9,1]
Tested-by: Pierre Moreau <pierre.morrow@free.fr> [MacBookPro11,3]
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Acked-by: Andreas Noever <andreas.noever@gmail.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Pedro Vilaça <reverser@put.as>
Cc: Peter Jones <pjones@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20161112213237.8804-10-matt@codeblueprint.co.uk
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-11-13 05:32:37 +08:00
|
|
|
/*
|
|
|
|
* Apple's NHI EFI driver supplies a DROM for the root switch
|
|
|
|
* in a device property. Use it if available.
|
|
|
|
*/
|
|
|
|
if (tb_drom_copy_efi(sw, &size) == 0)
|
|
|
|
goto parse;
|
|
|
|
|
2017-06-06 20:25:14 +08:00
|
|
|
/* Non-Apple hardware has the DROM as part of NVM */
|
|
|
|
if (tb_drom_copy_nvm(sw, &size) == 0)
|
|
|
|
goto parse;
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
/*
|
2019-12-17 20:33:40 +08:00
|
|
|
* USB4 hosts may support reading DROM through router
|
|
|
|
* operations.
|
2014-06-13 05:11:46 +08:00
|
|
|
*/
|
2019-12-17 20:33:40 +08:00
|
|
|
if (tb_switch_is_usb4(sw)) {
|
|
|
|
usb4_switch_read_uid(sw, &sw->uid);
|
|
|
|
if (!usb4_copy_host_drom(sw, &size))
|
|
|
|
goto parse;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The root switch contains only a dummy drom
|
|
|
|
* (header only, no entries). Hardcode the
|
|
|
|
* configuration here.
|
|
|
|
*/
|
|
|
|
tb_drom_read_uid_only(sw, &sw->uid);
|
|
|
|
}
|
|
|
|
|
2014-06-13 05:11:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-17 20:33:40 +08:00
|
|
|
res = tb_drom_read_n(sw, 14, (u8 *) &size, 2);
|
2014-06-13 05:11:46 +08:00
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
size &= 0x3ff;
|
|
|
|
size += TB_DROM_DATA_START;
|
2018-10-01 17:31:19 +08:00
|
|
|
tb_sw_dbg(sw, "reading drom (length: %#x)\n", size);
|
2014-06-13 05:11:46 +08:00
|
|
|
if (size < sizeof(*header)) {
|
|
|
|
tb_sw_warn(sw, "drom too small, aborting\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
sw->drom = kzalloc(size, GFP_KERNEL);
|
|
|
|
if (!sw->drom)
|
|
|
|
return -ENOMEM;
|
2019-12-17 20:33:40 +08:00
|
|
|
res = tb_drom_read_n(sw, 0, sw->drom, size);
|
2014-06-13 05:11:46 +08:00
|
|
|
if (res)
|
|
|
|
goto err;
|
|
|
|
|
thunderbolt: Use Device ROM retrieved from EFI
Macs with Thunderbolt 1 do not have a unit-specific DROM: The DROM is
empty with uid 0x1000000000000. (Apple started factory-burning a unit-
specific DROM with Thunderbolt 2.)
Instead, the NHI EFI driver supplies a DROM in a device property. Use
it if available. It's only available when booting with the efistub.
If it's not available, silently fall back to our hardcoded DROM.
The size of the DROM is always 256 bytes. The number is hardcoded into
the NHI EFI driver. This commit can deal with an arbitrary size however,
just in case they ever change that.
Background information: The EFI firmware volume contains ROM files for
the NHI, GMUX and several other chips as well as key material. This
strategy allows Apple to deploy ROM or key updates by simply publishing
an EFI firmware update on their website. Drivers do not access those
files directly but rather through a file server via EFI protocol
AC5E4829-A8FD-440B-AF33-9FFE013B12D8. Files are identified by GUID, the
NHI DROM has 339370BD-CFC6-4454-8EF7-704653120818.
The NHI EFI driver amends that file with a unit-specific uid. The uid
has 64 bit but its entropy is much lower: 24 bit represent the model,
24 bit are taken from a serial number, 16 bit are fixed. The NHI EFI
driver obtains the serial number via the DataHub protocol, copies it
into the DROM, calculates the CRC and submits the result as a device
property.
A modification is needed in the resume code where we currently read the
uid of all switches in the hierarchy to detect plug events that occurred
during sleep. On Thunderbolt 1 root switches this will now lead to a
mismatch between the uid of the empty DROM and the EFI DROM. Exempt the
root switch from this check: It's built in, so the uid should never
change. However we continue to *read* the uid of the root switch, this
seems like a good way to test its reachability after resume.
Tested-by: Lukas Wunner <lukas@wunner.de> [MacBookPro9,1]
Tested-by: Pierre Moreau <pierre.morrow@free.fr> [MacBookPro11,3]
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Acked-by: Andreas Noever <andreas.noever@gmail.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Pedro Vilaça <reverser@put.as>
Cc: Peter Jones <pjones@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20161112213237.8804-10-matt@codeblueprint.co.uk
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-11-13 05:32:37 +08:00
|
|
|
parse:
|
2014-06-13 05:11:46 +08:00
|
|
|
header = (void *) sw->drom;
|
|
|
|
|
|
|
|
if (header->data_len + TB_DROM_DATA_START != size) {
|
|
|
|
tb_sw_warn(sw, "drom size mismatch, aborting\n");
|
|
|
|
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;
|
|
|
|
}
|
2017-06-06 20:25:14 +08:00
|
|
|
if (!sw->uid)
|
|
|
|
sw->uid = header->uid;
|
2017-06-06 20:25:01 +08:00
|
|
|
sw->vendor = header->vendor_id;
|
|
|
|
sw->device = header->model_id;
|
2014-06-13 05:11:46 +08:00
|
|
|
|
|
|
|
crc = tb_crc32(sw->drom + TB_DROM_DATA_START, header->data_len);
|
|
|
|
if (crc != header->data_crc32) {
|
|
|
|
tb_sw_warn(sw,
|
2017-06-06 20:25:03 +08:00
|
|
|
"drom data crc32 mismatch (expected: %#x, got: %#x), continuing\n",
|
2014-06-13 05:11:46 +08:00
|
|
|
header->data_crc32, crc);
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:24:56 +08:00
|
|
|
if (header->device_rom_revision > 2)
|
2014-06-13 05:11:46 +08:00
|
|
|
tb_sw_warn(sw, "drom device_rom_revision %#x unknown\n",
|
|
|
|
header->device_rom_revision);
|
|
|
|
|
2020-09-07 17:20:36 +08:00
|
|
|
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");
|
|
|
|
msleep(100);
|
|
|
|
res = tb_drom_read_n(sw, 0, sw->drom, size);
|
|
|
|
if (!res)
|
|
|
|
goto parse;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2014-06-13 05:11:46 +08:00
|
|
|
err:
|
|
|
|
kfree(sw->drom);
|
2016-04-10 18:48:27 +08:00
|
|
|
sw->drom = NULL;
|
2014-06-13 05:11:46 +08:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
}
|