Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thunderbolt: Expose active parts of NVM even if upgrade is not supported

Ice Lake Thunderbolt controller NVM firmware is part of the BIOS image
which means it is not writable through the DMA port anymore. However, we
can still read it so we can keep nvm_version and active parts of NVM.
This way users still can find out the active NVM version and other
potentially useful information directly from Linux.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Yehezkel Bernat <YehezkelShB@gmail.com>
Tested-by: Mario Limonciello <mario.limonciello@dell.com>

+19 -9
+19 -9
drivers/thunderbolt/switch.c
··· 364 364 nvm->active = nvm_dev; 365 365 } 366 366 367 - nvm_dev = register_nvmem(sw, nvm->id, NVM_MAX_SIZE, false); 368 - if (IS_ERR(nvm_dev)) { 369 - ret = PTR_ERR(nvm_dev); 370 - goto err_nvm_active; 367 + if (!sw->no_nvm_upgrade) { 368 + nvm_dev = register_nvmem(sw, nvm->id, NVM_MAX_SIZE, false); 369 + if (IS_ERR(nvm_dev)) { 370 + ret = PTR_ERR(nvm_dev); 371 + goto err_nvm_active; 372 + } 373 + nvm->non_active = nvm_dev; 371 374 } 372 - nvm->non_active = nvm_dev; 373 375 374 376 sw->nvm = nvm; 375 377 return 0; ··· 400 398 if (!nvm->authenticating) 401 399 nvm_clear_auth_status(sw); 402 400 403 - nvmem_unregister(nvm->non_active); 401 + if (nvm->non_active) 402 + nvmem_unregister(nvm->non_active); 404 403 if (nvm->active) 405 404 nvmem_unregister(nvm->active); 406 405 ida_simple_remove(&nvm_ida, nvm->id); ··· 1358 1355 sw->security_level == TB_SECURITY_SECURE) 1359 1356 return attr->mode; 1360 1357 return 0; 1361 - } else if (attr == &dev_attr_nvm_authenticate.attr || 1362 - attr == &dev_attr_nvm_version.attr) { 1358 + } else if (attr == &dev_attr_nvm_authenticate.attr) { 1359 + if (sw->dma_port && !sw->no_nvm_upgrade) 1360 + return attr->mode; 1361 + return 0; 1362 + } else if (attr == &dev_attr_nvm_version.attr) { 1363 1363 if (sw->dma_port) 1364 1364 return attr->mode; 1365 1365 return 0; ··· 1713 1707 break; 1714 1708 } 1715 1709 1716 - if (sw->no_nvm_upgrade) 1710 + /* Root switch DMA port requires running firmware */ 1711 + if (!tb_route(sw) && sw->config.enabled) 1717 1712 return 0; 1718 1713 1719 1714 sw->dma_port = dma_port_alloc(sw); 1720 1715 if (!sw->dma_port) 1716 + return 0; 1717 + 1718 + if (sw->no_nvm_upgrade) 1721 1719 return 0; 1722 1720 1723 1721 /*