Skip to content

Commit 4573add

Browse files
Rene Sapienswesteri
authored andcommitted
thunderbolt: Read router NVM version before applying quirks
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>
1 parent 11439c4 commit 4573add

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

drivers/thunderbolt/switch.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int nvm_write(void *priv, unsigned int offset, void *val, size_t bytes)
347347
return ret;
348348
}
349349

350-
static int tb_switch_nvm_add(struct tb_switch *sw)
350+
static int tb_switch_nvm_init(struct tb_switch *sw)
351351
{
352352
struct tb_nvm *nvm;
353353
int ret;
@@ -365,6 +365,26 @@ static int tb_switch_nvm_add(struct tb_switch *sw)
365365
if (ret)
366366
goto err_nvm;
367367

368+
sw->nvm = nvm;
369+
return 0;
370+
371+
err_nvm:
372+
tb_sw_dbg(sw, "NVM upgrade disabled\n");
373+
sw->no_nvm_upgrade = true;
374+
if (!IS_ERR(nvm))
375+
tb_nvm_free(nvm);
376+
377+
return ret;
378+
}
379+
380+
static int tb_switch_nvm_add(struct tb_switch *sw)
381+
{
382+
struct tb_nvm *nvm = sw->nvm;
383+
int ret;
384+
385+
if (!nvm)
386+
return 0;
387+
368388
/*
369389
* If the switch is in safe-mode the only accessible portion of
370390
* 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)
383403
goto err_nvm;
384404
}
385405

386-
sw->nvm = nvm;
387406
return 0;
388407

389408
err_nvm:
390409
tb_sw_dbg(sw, "NVM upgrade disabled\n");
391410
sw->no_nvm_upgrade = true;
392-
if (!IS_ERR(nvm))
393-
tb_nvm_free(nvm);
411+
tb_nvm_free(nvm);
394412

395413
return ret;
396414
}
@@ -3311,6 +3329,10 @@ int tb_switch_add(struct tb_switch *sw)
33113329
return ret;
33123330
}
33133331

3332+
ret = tb_switch_nvm_init(sw);
3333+
if (ret)
3334+
return ret;
3335+
33143336
if (!sw->safe_mode) {
33153337
tb_switch_credits_init(sw);
33163338

0 commit comments

Comments
 (0)