aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thunderbolt/eeprom.c
diff options
context:
space:
mode:
authorMika Westerberg <mika.westerberg@linux.intel.com>2017-06-06 08:25:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-06-09 05:42:42 -0400
commit72ee33907b629355d8fd1980140a467041a9f519 (patch)
tree3f5242955d986d7f22137d02582566a047c821b2 /drivers/thunderbolt/eeprom.c
parent02b17a41ad102934a3772ffc82f345345c232ee4 (diff)
thunderbolt: Read vendor and device name from DROM
The device DROM contains name of the vendor and device among other things. Extract this information and expose it to the userspace via two new attributes. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Yehezkel Bernat <yehezkel.bernat@intel.com> Reviewed-by: Michael Jamet <michael.jamet@intel.com> Signed-off-by: Andreas Noever <andreas.noever@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/thunderbolt/eeprom.c')
-rw-r--r--drivers/thunderbolt/eeprom.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
index 5c7d80a109b1..d40a5f07fc4c 100644
--- a/drivers/thunderbolt/eeprom.c
+++ b/drivers/thunderbolt/eeprom.c
@@ -204,6 +204,11 @@ struct tb_drom_entry_header {
204 enum tb_drom_entry_type type:1; 204 enum tb_drom_entry_type type:1;
205} __packed; 205} __packed;
206 206
207struct tb_drom_entry_generic {
208 struct tb_drom_entry_header header;
209 u8 data[0];
210} __packed;
211
207struct tb_drom_entry_port { 212struct tb_drom_entry_port {
208 /* BYTES 0-1 */ 213 /* BYTES 0-1 */
209 struct tb_drom_entry_header header; 214 struct tb_drom_entry_header header;
@@ -295,6 +300,32 @@ int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid)
295 return 0; 300 return 0;
296} 301}
297 302
303static int tb_drom_parse_entry_generic(struct tb_switch *sw,
304 struct tb_drom_entry_header *header)
305{
306 const struct tb_drom_entry_generic *entry =
307 (const struct tb_drom_entry_generic *)header;
308
309 switch (header->index) {
310 case 1:
311 /* Length includes 2 bytes header so remove it before copy */
312 sw->vendor_name = kstrndup(entry->data,
313 header->len - sizeof(*header), GFP_KERNEL);
314 if (!sw->vendor_name)
315 return -ENOMEM;
316 break;
317
318 case 2:
319 sw->device_name = kstrndup(entry->data,
320 header->len - sizeof(*header), GFP_KERNEL);
321 if (!sw->device_name)
322 return -ENOMEM;
323 break;
324 }
325
326 return 0;
327}
328
298static int tb_drom_parse_entry_port(struct tb_switch *sw, 329static int tb_drom_parse_entry_port(struct tb_switch *sw,
299 struct tb_drom_entry_header *header) 330 struct tb_drom_entry_header *header)
300{ 331{
@@ -350,6 +381,7 @@ static int tb_drom_parse_entries(struct tb_switch *sw)
350 381
351 switch (entry->type) { 382 switch (entry->type) {
352 case TB_DROM_ENTRY_GENERIC: 383 case TB_DROM_ENTRY_GENERIC:
384 res = tb_drom_parse_entry_generic(sw, entry);
353 break; 385 break;
354 case TB_DROM_ENTRY_PORT: 386 case TB_DROM_ENTRY_PORT:
355 res = tb_drom_parse_entry_port(sw, entry); 387 res = tb_drom_parse_entry_port(sw, entry);