]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
thunderbolt: Read router NVM version before applying quirks
authorRene Sapiens <rene.sapiens@linux.intel.com>
Sat, 7 Feb 2026 00:25:56 +0000 (16:25 -0800)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Mon, 2 Mar 2026 06:51:58 +0000 (07:51 +0100)
The router NVM version is currently only available after the NVMem devices
have been registered. This is too late for firmware-dependent quirks that
are evaluated during tb_switch_add() before device registration.

Split router NVM handling into two phases:
  - tb_switch_nvm_init() allocates the NVM object and reads the version
  - tb_switch_nvm_add() registers the NVMem devices using the pre-read NVM

This makes the NVM major/minor version available before tb_check_quirks()
without changing when the NVMem devices are registered.

Signed-off-by: Rene Sapiens <rene.sapiens@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/switch.c

index e5b48a331c5833a05b13eef1c9dde8b5b4c53eb0..c2ad58b19e7b1ae93101d5e09b634f220ba6ebf7 100644 (file)
@@ -347,7 +347,7 @@ static int nvm_write(void *priv, unsigned int offset, void *val, size_t bytes)
        return ret;
 }
 
-static int tb_switch_nvm_add(struct tb_switch *sw)
+static int tb_switch_nvm_init(struct tb_switch *sw)
 {
        struct tb_nvm *nvm;
        int ret;
@@ -365,6 +365,26 @@ static int tb_switch_nvm_add(struct tb_switch *sw)
        if (ret)
                goto err_nvm;
 
+       sw->nvm = nvm;
+       return 0;
+
+err_nvm:
+       tb_sw_dbg(sw, "NVM upgrade disabled\n");
+       sw->no_nvm_upgrade = true;
+       if (!IS_ERR(nvm))
+               tb_nvm_free(nvm);
+
+       return ret;
+}
+
+static int tb_switch_nvm_add(struct tb_switch *sw)
+{
+       struct tb_nvm *nvm = sw->nvm;
+       int ret;
+
+       if (!nvm)
+               return 0;
+
        /*
         * If the switch is in safe-mode the only accessible portion of
         * the NVM is the non-active one where userspace is expected to
@@ -383,14 +403,12 @@ static int tb_switch_nvm_add(struct tb_switch *sw)
                        goto err_nvm;
        }
 
-       sw->nvm = nvm;
        return 0;
 
 err_nvm:
        tb_sw_dbg(sw, "NVM upgrade disabled\n");
        sw->no_nvm_upgrade = true;
-       if (!IS_ERR(nvm))
-               tb_nvm_free(nvm);
+       tb_nvm_free(nvm);
 
        return ret;
 }
@@ -3311,6 +3329,10 @@ int tb_switch_add(struct tb_switch *sw)
                return ret;
        }
 
+       ret = tb_switch_nvm_init(sw);
+       if (ret)
+               return ret;
+
        if (!sw->safe_mode) {
                tb_switch_credits_init(sw);