Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * NFIT - Machine Check Handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright(c) 2013-2016 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/nd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <asm/mce.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "nfit.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static int nfit_handle_mce(struct notifier_block *nb, unsigned long val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 			void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct mce *mce = (struct mce *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct acpi_nfit_desc *acpi_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct nfit_spa *nfit_spa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	/* We only care about uncorrectable memory errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	if (!mce_is_memory_error(mce) || mce_is_correctable(mce))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	/* Verify the address reported in the MCE is valid. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	if (!mce_usable_address(mce))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	 * mce->addr contains the physical addr accessed that caused the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	 * machine check. We need to walk through the list of NFITs, and see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	 * if any of them matches that address, and only then start a scrub.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	mutex_lock(&acpi_desc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	list_for_each_entry(acpi_desc, &acpi_descs, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		struct device *dev = acpi_desc->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		int found_match = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		mutex_lock(&acpi_desc->init_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			struct acpi_nfit_system_address *spa = nfit_spa->spa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			if (nfit_spa_type(spa) != NFIT_SPA_PM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			/* find the spa that covers the mce addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			if (spa->address > mce->addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			if ((spa->address + spa->length - 1) < mce->addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			found_match = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			dev_dbg(dev, "addr in SPA %d (0x%llx, 0x%llx)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				spa->range_index, spa->address, spa->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			 * We can break at the first match because we're going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			 * to rescan all the SPA ranges. There shouldn't be any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			 * aliasing anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		mutex_unlock(&acpi_desc->init_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		if (!found_match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		/* If this fails due to an -ENOMEM, there is little we can do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		nvdimm_bus_add_badrange(acpi_desc->nvdimm_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				ALIGN(mce->addr, L1_CACHE_BYTES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				L1_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		nvdimm_region_notify(nfit_spa->nd_region,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				NVDIMM_REVALIDATE_POISON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		if (acpi_desc->scrub_mode == HW_ERROR_SCRUB_ON) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			 * We can ignore an -EBUSY here because if an ARS is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			 * already in progress, just let that be the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			 * authoritative one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			acpi_nfit_ars_rescan(acpi_desc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		mce->kflags |= MCE_HANDLED_NFIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	mutex_unlock(&acpi_desc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static struct notifier_block nfit_mce_dec = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.notifier_call	= nfit_handle_mce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.priority	= MCE_PRIO_NFIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) void nfit_mce_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	mce_register_decode_chain(&nfit_mce_dec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) void nfit_mce_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	mce_unregister_decode_chain(&nfit_mce_dec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }