]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/thunderbolt/eeprom.c
thunderbolt: Refactor and fix parsing of port drom entries
[mirror_ubuntu-bionic-kernel.git] / drivers / thunderbolt / eeprom.c
index 6392990c984dd1ca462219b70e515a5d75aca9af..5c7d80a109b152a9e4224857daf2d6baedc69a07 100644 (file)
@@ -276,6 +276,9 @@ int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid)
        if (res)
                return res;
 
+       if (drom_offset == 0)
+               return -ENODEV;
+
        /* read uid */
        res = tb_eeprom_read_n(sw, drom_offset, data, 9);
        if (res)
@@ -292,25 +295,13 @@ int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid)
        return 0;
 }
 
-static void tb_drom_parse_port_entry(struct tb_port *port,
-               struct tb_drom_entry_port *entry)
-{
-       port->link_nr = entry->link_nr;
-       if (entry->has_dual_link_port)
-               port->dual_link_port =
-                               &port->sw->ports[entry->dual_link_port_nr];
-}
-
-static int tb_drom_parse_entry(struct tb_switch *sw,
-               struct tb_drom_entry_header *header)
+static int tb_drom_parse_entry_port(struct tb_switch *sw,
+                                   struct tb_drom_entry_header *header)
 {
        struct tb_port *port;
        int res;
        enum tb_port_type type;
 
-       if (header->type != TB_DROM_ENTRY_PORT)
-               return 0;
-
        port = &sw->ports[header->index];
        port->disabled = header->port_disabled;
        if (port->disabled)
@@ -329,7 +320,10 @@ static int tb_drom_parse_entry(struct tb_switch *sw,
                                header->len, sizeof(struct tb_drom_entry_port));
                        return -EIO;
                }
-               tb_drom_parse_port_entry(port, entry);
+               port->link_nr = entry->link_nr;
+               if (entry->has_dual_link_port)
+                       port->dual_link_port =
+                               &port->sw->ports[entry->dual_link_port_nr];
        }
        return 0;
 }
@@ -344,6 +338,7 @@ 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;
+       int res;
 
        while (pos < drom_size) {
                struct tb_drom_entry_header *entry = (void *) (sw->drom + pos);
@@ -353,7 +348,15 @@ static int tb_drom_parse_entries(struct tb_switch *sw)
                        return -EIO;
                }
 
-               tb_drom_parse_entry(sw, entry);
+               switch (entry->type) {
+               case TB_DROM_ENTRY_GENERIC:
+                       break;
+               case TB_DROM_ENTRY_PORT:
+                       res = tb_drom_parse_entry_port(sw, entry);
+                       break;
+               }
+               if (res)
+                       return res;
 
                pos += entry->len;
        }
@@ -476,16 +479,17 @@ parse:
                goto err;
        }
        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), aborting\n",
+                       "drom data crc32 mismatch (expected: %#x, got: %#x), continuing\n",
                        header->data_crc32, crc);
-               goto err;
        }
 
-       if (header->device_rom_revision > 1)
+       if (header->device_rom_revision > 2)
                tb_sw_warn(sw, "drom device_rom_revision %#x unknown\n",
                        header->device_rom_revision);