linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup
@ 2012-11-30  8:44 Daniel J Blueman
  2012-11-30  8:44 ` [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges Daniel J Blueman
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Daniel J Blueman @ 2012-11-30  8:44 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Daniel J Blueman, Ingo Molnar, Thomas Gleixner, H Peter Anvin,
	Steffen Persvold, x86, linux-kernel

Fix locating sibling memory controller PCI functions by using the
correct PCI domain and use Northbridge only if found. Tested on
multi-socket server and multi-server, multi-socket NumaConnect setup.

v7: Refactor patches grouping changes
v8: Restructure searching for PCI function for clarity; use Northbridge
    only if found

Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>
---
 drivers/edac/amd64_edac.c |   43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 60e93fa..6c1005f 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -983,6 +983,22 @@ static u64 get_error_address(struct mce *m)
 	return addr;
 }
 
+static struct pci_dev *pci_get_related_function(unsigned int vendor,
+						unsigned int device,
+						struct pci_dev *related)
+{
+	struct pci_dev *dev = NULL;
+
+	while ((dev = pci_get_device(vendor, device, dev))) {
+		if (pci_domain_nr(dev->bus) == pci_domain_nr(related->bus) &&
+		    (dev->bus->number == related->bus->number) &&
+		    (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn)))
+			break;
+	}
+
+	return dev;
+}
+
 static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
 {
 	struct cpuinfo_x86 *c = &boot_cpu_data;
@@ -1002,11 +1018,17 @@ static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
 
 	/* Factor in CC6 save area by reading dst node's limit reg */
 	if (c->x86 == 0x15) {
-		struct pci_dev *f1 = NULL;
+		struct pci_dev *misc, *f1 = NULL;
 		u8 nid = dram_dst_node(pvt, range);
+		struct amd_northbridge *nb = node_to_amd_nb(nid);
 		u32 llim;
 
-		f1 = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0x18 + nid, 1));
+		/* If DRAM base/limit registers point to a non-AMD device, nb won't have been found */
+		if (!nb)
+			return;
+
+		misc = nb->misc;
+		f1 = pci_get_related_function(misc->vendor, PCI_DEVICE_ID_AMD_15H_NB_F1, misc);
 		if (WARN_ON(!f1))
 			return;
 
@@ -1713,23 +1735,6 @@ static struct amd64_family_type amd64_family_types[] = {
 	},
 };
 
-static struct pci_dev *pci_get_related_function(unsigned int vendor,
-						unsigned int device,
-						struct pci_dev *related)
-{
-	struct pci_dev *dev = NULL;
-
-	dev = pci_get_device(vendor, device, dev);
-	while (dev) {
-		if ((dev->bus->number == related->bus->number) &&
-		    (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn)))
-			break;
-		dev = pci_get_device(vendor, device, dev);
-	}
-
-	return dev;
-}
-
 /*
  * These are tables of eigenvectors (one per line) which can be used for the
  * construction of the syndrome tables. The modified syndrome search algorithm
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges
  2012-11-30  8:44 [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup Daniel J Blueman
@ 2012-11-30  8:44 ` Daniel J Blueman
  2012-11-30 17:17   ` Borislav Petkov
  2013-01-22 16:53   ` [tip:x86/platform] amd64_edac: " tip-bot for Daniel J Blueman
  2012-11-30 11:27 ` [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup Borislav Petkov
  2013-01-22 16:52 ` [tip:x86/platform] amd64_edac: " tip-bot for Daniel J Blueman
  2 siblings, 2 replies; 11+ messages in thread
From: Daniel J Blueman @ 2012-11-30  8:44 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Daniel J Blueman, Ingo Molnar, Thomas Gleixner, H Peter Anvin,
	Steffen Persvold, x86, linux-kernel

Use appropriate types for northbridge IDs and memory ranges. Mark immutable
data const and keep within compilation unit on related structures. Tested on
multi-socket server and multi-server, multi-socket NumaConnect setup.

v7: Refactor patches grouping changes
v8: Drop unneeded change; use const and static where appropriate

Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>
---
 arch/x86/include/asm/amd_nb.h |    2 +-
 drivers/edac/amd64_edac.c     |   26 +++++++++++++-------------
 drivers/edac/amd64_edac.h     |    6 +++---
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
index 417eb24..d2e703b 100644
--- a/arch/x86/include/asm/amd_nb.h
+++ b/arch/x86/include/asm/amd_nb.h
@@ -76,7 +76,7 @@ static inline bool amd_nb_has_feature(unsigned feature)
 	return ((amd_northbridges.flags & feature) == feature);
 }
 
-static inline struct amd_northbridge *node_to_amd_nb(int node)
+static inline struct amd_northbridge *node_to_amd_nb(u16 node)
 {
 	return (node < amd_northbridges.num) ? &amd_northbridges.nb[node] : NULL;
 }
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 6c1005f..30149e4 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -31,7 +31,7 @@ static struct ecc_settings **ecc_stngs;
  *
  *FIXME: Produce a better mapping/linearisation.
  */
-struct scrubrate {
+static const struct scrubrate {
        u32 scrubval;           /* bit pattern for scrub rate */
        u32 bandwidth;          /* bandwidth consumed (bytes/sec) */
 } scrubrates[] = {
@@ -239,7 +239,7 @@ static int amd64_get_scrub_rate(struct mem_ctl_info *mci)
  * DRAM base/limit associated with node_id
  */
 static bool amd64_base_limit_match(struct amd64_pvt *pvt, u64 sys_addr,
-				   unsigned nid)
+				   u8 nid)
 {
 	u64 addr;
 
@@ -265,7 +265,7 @@ static struct mem_ctl_info *find_mc_by_sys_addr(struct mem_ctl_info *mci,
 						u64 sys_addr)
 {
 	struct amd64_pvt *pvt;
-	unsigned node_id;
+	u8 node_id;
 	u32 intlv_en, bits;
 
 	/*
@@ -1351,7 +1351,7 @@ static u8 f1x_determine_channel(struct amd64_pvt *pvt, u64 sys_addr,
 }
 
 /* Convert the sys_addr to the normalized DCT address */
-static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, unsigned range,
+static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range,
 				 u64 sys_addr, bool hi_rng,
 				 u32 dct_sel_base_addr)
 {
@@ -1427,7 +1427,7 @@ static int f10_process_possible_spare(struct amd64_pvt *pvt, u8 dct, int csrow)
  *	-EINVAL:  NOT FOUND
  *	0..csrow = Chip-Select Row
  */
-static int f1x_lookup_addr_in_dct(u64 in_addr, u32 nid, u8 dct)
+static int f1x_lookup_addr_in_dct(u64 in_addr, u8 nid, u8 dct)
 {
 	struct mem_ctl_info *mci;
 	struct amd64_pvt *pvt;
@@ -1742,7 +1742,7 @@ static struct amd64_family_type amd64_family_types[] = {
  *
  * Algorithm courtesy of Ross LaFetra from AMD.
  */
-static u16 x4_vectors[] = {
+static const u16 x4_vectors[] = {
 	0x2f57, 0x1afe, 0x66cc, 0xdd88,
 	0x11eb, 0x3396, 0x7f4c, 0xeac8,
 	0x0001, 0x0002, 0x0004, 0x0008,
@@ -1781,7 +1781,7 @@ static u16 x4_vectors[] = {
 	0x19a9, 0x2efe, 0xb5cc, 0x6f88,
 };
 
-static u16 x8_vectors[] = {
+static const u16 x8_vectors[] = {
 	0x0145, 0x028a, 0x2374, 0x43c8, 0xa1f0, 0x0520, 0x0a40, 0x1480,
 	0x0211, 0x0422, 0x0844, 0x1088, 0x01b0, 0x44e0, 0x23c0, 0xed80,
 	0x1011, 0x0116, 0x022c, 0x0458, 0x08b0, 0x8c60, 0x2740, 0x4e80,
@@ -1803,7 +1803,7 @@ static u16 x8_vectors[] = {
 	0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000,
 };
 
-static int decode_syndrome(u16 syndrome, u16 *vectors, unsigned num_vecs,
+static int decode_syndrome(u16 syndrome, const u16 *vectors, unsigned num_vecs,
 			   unsigned v_dim)
 {
 	unsigned int i, err_sym;
@@ -2269,7 +2269,7 @@ static void get_cpus_on_this_dct_cpumask(struct cpumask *mask, u16 nid)
 }
 
 /* check MCG_CTL on all the cpus on this node */
-static bool amd64_nb_mce_bank_enabled_on_node(unsigned nid)
+static bool amd64_nb_mce_bank_enabled_on_node(u16 nid)
 {
 	cpumask_var_t mask;
 	int cpu, nbe;
@@ -2302,7 +2302,7 @@ out:
 	return ret;
 }
 
-static int toggle_ecc_err_reporting(struct ecc_settings *s, u8 nid, bool on)
+static int toggle_ecc_err_reporting(struct ecc_settings *s, u16 nid, bool on)
 {
 	cpumask_var_t cmask;
 	int cpu;
@@ -2340,7 +2340,7 @@ static int toggle_ecc_err_reporting(struct ecc_settings *s, u8 nid, bool on)
 	return 0;
 }
 
-static bool enable_ecc_error_reporting(struct ecc_settings *s, u8 nid,
+static bool enable_ecc_error_reporting(struct ecc_settings *s, u16 nid,
 				       struct pci_dev *F3)
 {
 	bool ret = true;
@@ -2392,7 +2392,7 @@ static bool enable_ecc_error_reporting(struct ecc_settings *s, u8 nid,
 	return ret;
 }
 
-static void restore_ecc_error_reporting(struct ecc_settings *s, u8 nid,
+static void restore_ecc_error_reporting(struct ecc_settings *s, u16 nid,
 					struct pci_dev *F3)
 {
 	u32 value, mask = 0x3;		/* UECC/CECC enable */
@@ -2431,7 +2431,7 @@ static const char *ecc_msg =
 	"'ecc_enable_override'.\n"
 	" (Note that use of the override may cause unknown side effects.)\n";
 
-static bool ecc_enabled(struct pci_dev *F3, u8 nid)
+static bool ecc_enabled(struct pci_dev *F3, u16 nid)
 {
 	u32 value;
 	u8 ecc_en = 0;
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index cecd0c4..a558084 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -332,7 +332,7 @@ struct amd64_pvt {
 	/* pci_device handles which we utilize */
 	struct pci_dev *F1, *F2, *F3;
 
-	unsigned mc_node_id;	/* MC index of this MC node */
+	u16 mc_node_id;		/* MC index of this MC node */
 	int ext_model;		/* extended model value of this node */
 	int channel_count;
 
@@ -368,7 +368,7 @@ struct amd64_pvt {
 	struct error_injection injection;
 };
 
-static inline u64 get_dram_base(struct amd64_pvt *pvt, unsigned i)
+static inline u64 get_dram_base(struct amd64_pvt *pvt, u8 i)
 {
 	u64 addr = ((u64)pvt->ranges[i].base.lo & 0xffff0000) << 8;
 
@@ -378,7 +378,7 @@ static inline u64 get_dram_base(struct amd64_pvt *pvt, unsigned i)
 	return (((u64)pvt->ranges[i].base.hi & 0x000000ff) << 40) | addr;
 }
 
-static inline u64 get_dram_limit(struct amd64_pvt *pvt, unsigned i)
+static inline u64 get_dram_limit(struct amd64_pvt *pvt, u8 i)
 {
 	u64 lim = (((u64)pvt->ranges[i].lim.lo & 0xffff0000) << 8) | 0x00ffffff;
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup
  2012-11-30  8:44 [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup Daniel J Blueman
  2012-11-30  8:44 ` [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges Daniel J Blueman
@ 2012-11-30 11:27 ` Borislav Petkov
  2013-01-22 16:52 ` [tip:x86/platform] amd64_edac: " tip-bot for Daniel J Blueman
  2 siblings, 0 replies; 11+ messages in thread
From: Borislav Petkov @ 2012-11-30 11:27 UTC (permalink / raw)
  To: Daniel J Blueman
  Cc: Ingo Molnar, Thomas Gleixner, H Peter Anvin, Steffen Persvold,
	x86, linux-kernel

On Fri, Nov 30, 2012 at 04:44:19PM +0800, Daniel J Blueman wrote:
> Fix locating sibling memory controller PCI functions by using the
> correct PCI domain and use Northbridge only if found. Tested on
> multi-socket server and multi-server, multi-socket NumaConnect setup.
> 
> v7: Refactor patches grouping changes
> v8: Restructure searching for PCI function for clarity; use Northbridge
>     only if found
> 
> Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>

Ok, looks good. I ended up cleaning it up the code for F15h a bit and
fixing it up. Here's the final version:

--
commit 75cdc74742bbf368dfc52bb5041274c95d85a68f
Author: Daniel J Blueman <daniel@numascale-asia.com>
Date:   Fri Nov 30 16:44:19 2012 +0800

    amd64_edac: Fix PCI function lookup
    
    Fix locating sibling memory controller PCI functions by using the
    correct PCI domain and use a northbridge descriptor only if found. We
    need to at least warn if it wasn't found so that it gets fixed and we
    don't go off with wrong results.
    
    Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>
    [Boris: remove wrong comment, sanitize code and warn if NB desc lookup fails]
    Signed-off-by: Borislav Petkov <bp@alien8.de>

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 60e93faaea18..e22a35224841 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -983,10 +983,29 @@ static u64 get_error_address(struct mce *m)
 	return addr;
 }
 
+static struct pci_dev *pci_get_related_function(unsigned int vendor,
+						unsigned int device,
+						struct pci_dev *related)
+{
+	struct pci_dev *dev = NULL;
+
+	while ((dev = pci_get_device(vendor, device, dev))) {
+		if (pci_domain_nr(dev->bus) == pci_domain_nr(related->bus) &&
+		    (dev->bus->number == related->bus->number) &&
+		    (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn)))
+			break;
+	}
+
+	return dev;
+}
+
 static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
 {
+	struct amd_northbridge *nb;
+	struct pci_dev *misc, *f1 = NULL;
 	struct cpuinfo_x86 *c = &boot_cpu_data;
 	int off = range << 3;
+	u32 llim;
 
 	amd64_read_pci_cfg(pvt->F1, DRAM_BASE_LO + off,  &pvt->ranges[range].base.lo);
 	amd64_read_pci_cfg(pvt->F1, DRAM_LIMIT_LO + off, &pvt->ranges[range].lim.lo);
@@ -1000,30 +1019,32 @@ static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
 	amd64_read_pci_cfg(pvt->F1, DRAM_BASE_HI + off,  &pvt->ranges[range].base.hi);
 	amd64_read_pci_cfg(pvt->F1, DRAM_LIMIT_HI + off, &pvt->ranges[range].lim.hi);
 
-	/* Factor in CC6 save area by reading dst node's limit reg */
-	if (c->x86 == 0x15) {
-		struct pci_dev *f1 = NULL;
-		u8 nid = dram_dst_node(pvt, range);
-		u32 llim;
+	/* F15h: factor in CC6 save area by reading dst node's limit reg */
+	if (c->x86 != 0x15)
+		return;
 
-		f1 = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0x18 + nid, 1));
-		if (WARN_ON(!f1))
-			return;
+	nb = node_to_amd_nb(dram_dst_node(pvt, range));
+	if (WARN_ON(!nb))
+		return;
 
-		amd64_read_pci_cfg(f1, DRAM_LOCAL_NODE_LIM, &llim);
+	misc = nb->misc;
+	f1 = pci_get_related_function(misc->vendor, PCI_DEVICE_ID_AMD_15H_NB_F1, misc);
+	if (WARN_ON(!f1))
+		return;
 
-		pvt->ranges[range].lim.lo &= GENMASK(0, 15);
+	amd64_read_pci_cfg(f1, DRAM_LOCAL_NODE_LIM, &llim);
 
-					    /* {[39:27],111b} */
-		pvt->ranges[range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16;
+	pvt->ranges[range].lim.lo &= GENMASK(0, 15);
 
-		pvt->ranges[range].lim.hi &= GENMASK(0, 7);
+				    /* {[39:27],111b} */
+	pvt->ranges[range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16;
 
-					    /* [47:40] */
-		pvt->ranges[range].lim.hi |= llim >> 13;
+	pvt->ranges[range].lim.hi &= GENMASK(0, 7);
 
-		pci_dev_put(f1);
-	}
+				    /* [47:40] */
+	pvt->ranges[range].lim.hi |= llim >> 13;
+
+	pci_dev_put(f1);
 }
 
 static void k8_map_sysaddr_to_csrow(struct mem_ctl_info *mci, u64 sys_addr,
@@ -1713,23 +1734,6 @@ static struct amd64_family_type amd64_family_types[] = {
 	},
 };
 
-static struct pci_dev *pci_get_related_function(unsigned int vendor,
-						unsigned int device,
-						struct pci_dev *related)
-{
-	struct pci_dev *dev = NULL;
-
-	dev = pci_get_device(vendor, device, dev);
-	while (dev) {
-		if ((dev->bus->number == related->bus->number) &&
-		    (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn)))
-			break;
-		dev = pci_get_device(vendor, device, dev);
-	}
-
-	return dev;
-}
-
 /*
  * These are tables of eigenvectors (one per line) which can be used for the
  * construction of the syndrome tables. The modified syndrome search algorithm

-- 
Regards/Gruss,
    Boris.

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges
  2012-11-30  8:44 ` [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges Daniel J Blueman
@ 2012-11-30 17:17   ` Borislav Petkov
  2012-12-04  9:24     ` Daniel J Blueman
  2013-01-22 16:53   ` [tip:x86/platform] amd64_edac: " tip-bot for Daniel J Blueman
  1 sibling, 1 reply; 11+ messages in thread
From: Borislav Petkov @ 2012-11-30 17:17 UTC (permalink / raw)
  To: Daniel J Blueman
  Cc: Ingo Molnar, Thomas Gleixner, H Peter Anvin, Steffen Persvold,
	x86, linux-kernel

On Fri, Nov 30, 2012 at 04:44:20PM +0800, Daniel J Blueman wrote:
> Use appropriate types for northbridge IDs and memory ranges. Mark immutable
> data const and keep within compilation unit on related structures. Tested on
> multi-socket server and multi-server, multi-socket NumaConnect setup.
> 
> v7: Refactor patches grouping changes
> v8: Drop unneeded change; use const and static where appropriate
> 
> Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>
> ---
>  arch/x86/include/asm/amd_nb.h |    2 +-
>  drivers/edac/amd64_edac.c     |   26 +++++++++++++-------------
>  drivers/edac/amd64_edac.h     |    6 +++---
>  3 files changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
> index 417eb24..d2e703b 100644
> --- a/arch/x86/include/asm/amd_nb.h
> +++ b/arch/x86/include/asm/amd_nb.h
> @@ -76,7 +76,7 @@ static inline bool amd_nb_has_feature(unsigned feature)
>  	return ((amd_northbridges.flags & feature) == feature);
>  }
>  
> -static inline struct amd_northbridge *node_to_amd_nb(int node)
> +static inline struct amd_northbridge *node_to_amd_nb(u16 node)

I'm dropping this change from this patch because if we go with it,
we'll have to change all callsites of node_to_amd_nb which would cause
unnecessary churn.

So, I've applied the final patchset and uploaded a branch here:

git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git numascale

Please give it a run on both configurations and let me know if something
is still amiss.

Thanks.

-- 
Regards/Gruss,
    Boris.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges
  2012-11-30 17:17   ` Borislav Petkov
@ 2012-12-04  9:24     ` Daniel J Blueman
  2012-12-04 16:01       ` Borislav Petkov
  0 siblings, 1 reply; 11+ messages in thread
From: Daniel J Blueman @ 2012-12-04  9:24 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Ingo Molnar, Thomas Gleixner, H Peter Anvin, Steffen Persvold,
	x86, linux-kernel

On 01/12/2012 01:17, Borislav Petkov wrote:
> On Fri, Nov 30, 2012 at 04:44:20PM +0800, Daniel J Blueman wrote:
>> Use appropriate types for northbridge IDs and memory ranges. Mark immutable
>> data const and keep within compilation unit on related structures. Tested on
>> multi-socket server and multi-server, multi-socket NumaConnect setup.
>>
>> v7: Refactor patches grouping changes
>> v8: Drop unneeded change; use const and static where appropriate
>>
>> Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>
>> ---
>>   arch/x86/include/asm/amd_nb.h |    2 +-
>>   drivers/edac/amd64_edac.c     |   26 +++++++++++++-------------
>>   drivers/edac/amd64_edac.h     |    6 +++---
>>   3 files changed, 17 insertions(+), 17 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
>> index 417eb24..d2e703b 100644
>> --- a/arch/x86/include/asm/amd_nb.h
>> +++ b/arch/x86/include/asm/amd_nb.h
>> @@ -76,7 +76,7 @@ static inline bool amd_nb_has_feature(unsigned feature)
>>   	return ((amd_northbridges.flags & feature) == feature);
>>   }
>>
>> -static inline struct amd_northbridge *node_to_amd_nb(int node)
>> +static inline struct amd_northbridge *node_to_amd_nb(u16 node)
>
> I'm dropping this change from this patch because if we go with it,
> we'll have to change all callsites of node_to_amd_nb which would cause
> unnecessary churn.

> So, I've applied the final patchset and uploaded a branch here:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git numascale
>
> Please give it a run on both configurations and let me know if something
> is still amiss.

It works well on fam10h and fam15h boxes, with and without Numaconnect.

Thanks,
   Daniel
-- 
Daniel J Blueman
Principal Software Engineer, Numascale Asia

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges
  2012-12-04  9:24     ` Daniel J Blueman
@ 2012-12-04 16:01       ` Borislav Petkov
  2013-02-19 14:40         ` Daniel J Blueman
  0 siblings, 1 reply; 11+ messages in thread
From: Borislav Petkov @ 2012-12-04 16:01 UTC (permalink / raw)
  To: Daniel J Blueman
  Cc: Ingo Molnar, Thomas Gleixner, H Peter Anvin, Steffen Persvold,
	x86, linux-kernel

On Tue, Dec 04, 2012 at 05:24:16PM +0800, Daniel J Blueman wrote:
> It works well on fam10h and fam15h boxes, with and without Numaconnect.

Good, thanks for testing.

I will send it upstream after the upcoming merge window closes since it
is too late for this one now and I wouldn't want to rush it if it is not
necessary to do so and it hasn't seen enough testing in linux-next and
-tip trees. Which means that it will end up in 3.9; I hope that is OK
with you guys.

Thanks.

-- 
Regards/Gruss,
    Boris.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tip:x86/platform] amd64_edac: Fix PCI function lookup
  2012-11-30  8:44 [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup Daniel J Blueman
  2012-11-30  8:44 ` [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges Daniel J Blueman
  2012-11-30 11:27 ` [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup Borislav Petkov
@ 2013-01-22 16:52 ` tip-bot for Daniel J Blueman
  2 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Daniel J Blueman @ 2013-01-22 16:52 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, bp, daniel

Commit-ID:  e2c0bffea2574c088d86a9f1f661a84bc8fea2fd
Gitweb:     http://git.kernel.org/tip/e2c0bffea2574c088d86a9f1f661a84bc8fea2fd
Author:     Daniel J Blueman <daniel@numascale-asia.com>
AuthorDate: Fri, 30 Nov 2012 16:44:19 +0800
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Thu, 10 Jan 2013 16:17:59 +0100

amd64_edac: Fix PCI function lookup

Fix locating sibling memory controller PCI functions by using the
correct PCI domain and use a northbridge descriptor only if found. We
need to at least warn if it wasn't found so that it gets fixed and we
don't go off with wrong results.

Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>
Link: http://lkml.kernel.org/r/1354265060-22956-1-git-send-email-daniel@numascale-asia.com
[Boris: remove wrong comment, sanitize code and warn if NB desc lookup fails]
Signed-off-by: Borislav Petkov <bp@alien8.de>
---
 drivers/edac/amd64_edac.c | 72 +++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 34 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 29be39d..da76912 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -980,10 +980,29 @@ static u64 get_error_address(struct mce *m)
 	return addr;
 }
 
+static struct pci_dev *pci_get_related_function(unsigned int vendor,
+						unsigned int device,
+						struct pci_dev *related)
+{
+	struct pci_dev *dev = NULL;
+
+	while ((dev = pci_get_device(vendor, device, dev))) {
+		if (pci_domain_nr(dev->bus) == pci_domain_nr(related->bus) &&
+		    (dev->bus->number == related->bus->number) &&
+		    (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn)))
+			break;
+	}
+
+	return dev;
+}
+
 static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
 {
+	struct amd_northbridge *nb;
+	struct pci_dev *misc, *f1 = NULL;
 	struct cpuinfo_x86 *c = &boot_cpu_data;
 	int off = range << 3;
+	u32 llim;
 
 	amd64_read_pci_cfg(pvt->F1, DRAM_BASE_LO + off,  &pvt->ranges[range].base.lo);
 	amd64_read_pci_cfg(pvt->F1, DRAM_LIMIT_LO + off, &pvt->ranges[range].lim.lo);
@@ -997,30 +1016,32 @@ static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
 	amd64_read_pci_cfg(pvt->F1, DRAM_BASE_HI + off,  &pvt->ranges[range].base.hi);
 	amd64_read_pci_cfg(pvt->F1, DRAM_LIMIT_HI + off, &pvt->ranges[range].lim.hi);
 
-	/* Factor in CC6 save area by reading dst node's limit reg */
-	if (c->x86 == 0x15) {
-		struct pci_dev *f1 = NULL;
-		u8 nid = dram_dst_node(pvt, range);
-		u32 llim;
+	/* F15h: factor in CC6 save area by reading dst node's limit reg */
+	if (c->x86 != 0x15)
+		return;
 
-		f1 = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0x18 + nid, 1));
-		if (WARN_ON(!f1))
-			return;
+	nb = node_to_amd_nb(dram_dst_node(pvt, range));
+	if (WARN_ON(!nb))
+		return;
 
-		amd64_read_pci_cfg(f1, DRAM_LOCAL_NODE_LIM, &llim);
+	misc = nb->misc;
+	f1 = pci_get_related_function(misc->vendor, PCI_DEVICE_ID_AMD_15H_NB_F1, misc);
+	if (WARN_ON(!f1))
+		return;
 
-		pvt->ranges[range].lim.lo &= GENMASK(0, 15);
+	amd64_read_pci_cfg(f1, DRAM_LOCAL_NODE_LIM, &llim);
 
-					    /* {[39:27],111b} */
-		pvt->ranges[range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16;
+	pvt->ranges[range].lim.lo &= GENMASK(0, 15);
 
-		pvt->ranges[range].lim.hi &= GENMASK(0, 7);
+				    /* {[39:27],111b} */
+	pvt->ranges[range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16;
 
-					    /* [47:40] */
-		pvt->ranges[range].lim.hi |= llim >> 13;
+	pvt->ranges[range].lim.hi &= GENMASK(0, 7);
 
-		pci_dev_put(f1);
-	}
+				    /* [47:40] */
+	pvt->ranges[range].lim.hi |= llim >> 13;
+
+	pci_dev_put(f1);
 }
 
 static void k8_map_sysaddr_to_csrow(struct mem_ctl_info *mci, u64 sys_addr,
@@ -1673,23 +1694,6 @@ static struct amd64_family_type amd64_family_types[] = {
 	},
 };
 
-static struct pci_dev *pci_get_related_function(unsigned int vendor,
-						unsigned int device,
-						struct pci_dev *related)
-{
-	struct pci_dev *dev = NULL;
-
-	dev = pci_get_device(vendor, device, dev);
-	while (dev) {
-		if ((dev->bus->number == related->bus->number) &&
-		    (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn)))
-			break;
-		dev = pci_get_device(vendor, device, dev);
-	}
-
-	return dev;
-}
-
 /*
  * These are tables of eigenvectors (one per line) which can be used for the
  * construction of the syndrome tables. The modified syndrome search algorithm

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:x86/platform] amd64_edac: Fix type usage in NB IDs and memory ranges
  2012-11-30  8:44 ` [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges Daniel J Blueman
  2012-11-30 17:17   ` Borislav Petkov
@ 2013-01-22 16:53   ` tip-bot for Daniel J Blueman
  1 sibling, 0 replies; 11+ messages in thread
From: tip-bot for Daniel J Blueman @ 2013-01-22 16:53 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, bp, daniel

Commit-ID:  c7e5301a1b7c3f47af635a8b1b14480b81426025
Gitweb:     http://git.kernel.org/tip/c7e5301a1b7c3f47af635a8b1b14480b81426025
Author:     Daniel J Blueman <daniel@numascale-asia.com>
AuthorDate: Fri, 30 Nov 2012 16:44:20 +0800
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Thu, 10 Jan 2013 16:18:00 +0100

amd64_edac: Fix type usage in NB IDs and memory ranges

Use appropriate types for northbridge IDs and memory ranges. Mark
immutable data const and keep within compilation unit on related
structures.

Signed-off-by: Daniel J Blueman <daniel@numascale-asia.com>
Link: http://lkml.kernel.org/r/1354265060-22956-2-git-send-email-daniel@numascale-asia.com
[Boris: Drop arg change to node_to_amd_nb]
Signed-off-by: Borislav Petkov <bp@alien8.de>
---
 drivers/edac/amd64_edac.c | 26 +++++++++++++-------------
 drivers/edac/amd64_edac.h |  6 +++---
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index da76912..2d3f882 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -31,7 +31,7 @@ static struct ecc_settings **ecc_stngs;
  *
  *FIXME: Produce a better mapping/linearisation.
  */
-struct scrubrate {
+static const struct scrubrate {
        u32 scrubval;           /* bit pattern for scrub rate */
        u32 bandwidth;          /* bandwidth consumed (bytes/sec) */
 } scrubrates[] = {
@@ -239,7 +239,7 @@ static int amd64_get_scrub_rate(struct mem_ctl_info *mci)
  * DRAM base/limit associated with node_id
  */
 static bool amd64_base_limit_match(struct amd64_pvt *pvt, u64 sys_addr,
-				   unsigned nid)
+				   u8 nid)
 {
 	u64 addr;
 
@@ -265,7 +265,7 @@ static struct mem_ctl_info *find_mc_by_sys_addr(struct mem_ctl_info *mci,
 						u64 sys_addr)
 {
 	struct amd64_pvt *pvt;
-	unsigned node_id;
+	u8 node_id;
 	u32 intlv_en, bits;
 
 	/*
@@ -1327,7 +1327,7 @@ static u8 f1x_determine_channel(struct amd64_pvt *pvt, u64 sys_addr,
 }
 
 /* Convert the sys_addr to the normalized DCT address */
-static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, unsigned range,
+static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range,
 				 u64 sys_addr, bool hi_rng,
 				 u32 dct_sel_base_addr)
 {
@@ -1403,7 +1403,7 @@ static int f10_process_possible_spare(struct amd64_pvt *pvt, u8 dct, int csrow)
  *	-EINVAL:  NOT FOUND
  *	0..csrow = Chip-Select Row
  */
-static int f1x_lookup_addr_in_dct(u64 in_addr, u32 nid, u8 dct)
+static int f1x_lookup_addr_in_dct(u64 in_addr, u8 nid, u8 dct)
 {
 	struct mem_ctl_info *mci;
 	struct amd64_pvt *pvt;
@@ -1701,7 +1701,7 @@ static struct amd64_family_type amd64_family_types[] = {
  *
  * Algorithm courtesy of Ross LaFetra from AMD.
  */
-static u16 x4_vectors[] = {
+static const u16 x4_vectors[] = {
 	0x2f57, 0x1afe, 0x66cc, 0xdd88,
 	0x11eb, 0x3396, 0x7f4c, 0xeac8,
 	0x0001, 0x0002, 0x0004, 0x0008,
@@ -1740,7 +1740,7 @@ static u16 x4_vectors[] = {
 	0x19a9, 0x2efe, 0xb5cc, 0x6f88,
 };
 
-static u16 x8_vectors[] = {
+static const u16 x8_vectors[] = {
 	0x0145, 0x028a, 0x2374, 0x43c8, 0xa1f0, 0x0520, 0x0a40, 0x1480,
 	0x0211, 0x0422, 0x0844, 0x1088, 0x01b0, 0x44e0, 0x23c0, 0xed80,
 	0x1011, 0x0116, 0x022c, 0x0458, 0x08b0, 0x8c60, 0x2740, 0x4e80,
@@ -1762,7 +1762,7 @@ static u16 x8_vectors[] = {
 	0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000,
 };
 
-static int decode_syndrome(u16 syndrome, u16 *vectors, unsigned num_vecs,
+static int decode_syndrome(u16 syndrome, const u16 *vectors, unsigned num_vecs,
 			   unsigned v_dim)
 {
 	unsigned int i, err_sym;
@@ -2196,7 +2196,7 @@ static void get_cpus_on_this_dct_cpumask(struct cpumask *mask, u16 nid)
 }
 
 /* check MCG_CTL on all the cpus on this node */
-static bool amd64_nb_mce_bank_enabled_on_node(unsigned nid)
+static bool amd64_nb_mce_bank_enabled_on_node(u16 nid)
 {
 	cpumask_var_t mask;
 	int cpu, nbe;
@@ -2229,7 +2229,7 @@ out:
 	return ret;
 }
 
-static int toggle_ecc_err_reporting(struct ecc_settings *s, u8 nid, bool on)
+static int toggle_ecc_err_reporting(struct ecc_settings *s, u16 nid, bool on)
 {
 	cpumask_var_t cmask;
 	int cpu;
@@ -2267,7 +2267,7 @@ static int toggle_ecc_err_reporting(struct ecc_settings *s, u8 nid, bool on)
 	return 0;
 }
 
-static bool enable_ecc_error_reporting(struct ecc_settings *s, u8 nid,
+static bool enable_ecc_error_reporting(struct ecc_settings *s, u16 nid,
 				       struct pci_dev *F3)
 {
 	bool ret = true;
@@ -2319,7 +2319,7 @@ static bool enable_ecc_error_reporting(struct ecc_settings *s, u8 nid,
 	return ret;
 }
 
-static void restore_ecc_error_reporting(struct ecc_settings *s, u8 nid,
+static void restore_ecc_error_reporting(struct ecc_settings *s, u16 nid,
 					struct pci_dev *F3)
 {
 	u32 value, mask = 0x3;		/* UECC/CECC enable */
@@ -2358,7 +2358,7 @@ static const char *ecc_msg =
 	"'ecc_enable_override'.\n"
 	" (Note that use of the override may cause unknown side effects.)\n";
 
-static bool ecc_enabled(struct pci_dev *F3, u8 nid)
+static bool ecc_enabled(struct pci_dev *F3, u16 nid)
 {
 	u32 value;
 	u8 ecc_en = 0;
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index cd7845f..35637d8 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -334,7 +334,7 @@ struct amd64_pvt {
 	/* pci_device handles which we utilize */
 	struct pci_dev *F1, *F2, *F3;
 
-	unsigned mc_node_id;	/* MC index of this MC node */
+	u16 mc_node_id;		/* MC index of this MC node */
 	int ext_model;		/* extended model value of this node */
 	int channel_count;
 
@@ -387,7 +387,7 @@ struct err_info {
 	u32 offset;
 };
 
-static inline u64 get_dram_base(struct amd64_pvt *pvt, unsigned i)
+static inline u64 get_dram_base(struct amd64_pvt *pvt, u8 i)
 {
 	u64 addr = ((u64)pvt->ranges[i].base.lo & 0xffff0000) << 8;
 
@@ -397,7 +397,7 @@ static inline u64 get_dram_base(struct amd64_pvt *pvt, unsigned i)
 	return (((u64)pvt->ranges[i].base.hi & 0x000000ff) << 40) | addr;
 }
 
-static inline u64 get_dram_limit(struct amd64_pvt *pvt, unsigned i)
+static inline u64 get_dram_limit(struct amd64_pvt *pvt, u8 i)
 {
 	u64 lim = (((u64)pvt->ranges[i].lim.lo & 0xffff0000) << 8) | 0x00ffffff;
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges
  2012-12-04 16:01       ` Borislav Petkov
@ 2013-02-19 14:40         ` Daniel J Blueman
  2013-02-19 14:59           ` Borislav Petkov
  0 siblings, 1 reply; 11+ messages in thread
From: Daniel J Blueman @ 2013-02-19 14:40 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Ingo Molnar, Thomas Gleixner, H Peter Anvin, Steffen Persvold,
	x86, linux-kernel

Hi Boris,

On 05/12/2012 00:01, Borislav Petkov wrote:
> On Tue, Dec 04, 2012 at 05:24:16PM +0800, Daniel J Blueman wrote:
>> It works well on fam10h and fam15h boxes, with and without Numaconnect.
>
> Good, thanks for testing.
>
> I will send it upstream after the upcoming merge window closes since it
> is too late for this one now and I wouldn't want to rush it if it is not
> necessary to do so and it hasn't seen enough testing in linux-next and
> -tip trees. Which means that it will end up in 3.9; I hope that is OK
> with you guys.

Alas your merges missed the v3.8 merge window, but it looks like your 
v3.9 pull request has dropped these patches [1].

Any chance you can get them in during this merge window?

Many thanks,
   Daniel

[1] 
https://groups.google.com/forum/?fromgroups=#!topic/linux.kernel/2DLVw1Rv8bQ
-- 
Daniel J Blueman
Principal Software Engineer, Numascale Asia

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges
  2013-02-19 14:40         ` Daniel J Blueman
@ 2013-02-19 14:59           ` Borislav Petkov
  2013-02-19 15:08             ` Daniel J Blueman
  0 siblings, 1 reply; 11+ messages in thread
From: Borislav Petkov @ 2013-02-19 14:59 UTC (permalink / raw)
  To: Daniel J Blueman
  Cc: Ingo Molnar, Thomas Gleixner, H Peter Anvin, Steffen Persvold,
	x86, linux-kernel

On Tue, Feb 19, 2013 at 10:40:26PM +0800, Daniel J Blueman wrote:
> Alas your merges missed the v3.8 merge window, but it looks like your
> v3.9 pull request has dropped these patches [1].
>
> Any chance you can get them in during this merge window?

They should go in anytime now. They're in tip:x86/platform and Ingo is
sending pull requests to Linus as we speak. Since they touch x86 code I
asked x86 guys to send them upstream instead of me.

HTH.

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges
  2013-02-19 14:59           ` Borislav Petkov
@ 2013-02-19 15:08             ` Daniel J Blueman
  0 siblings, 0 replies; 11+ messages in thread
From: Daniel J Blueman @ 2013-02-19 15:08 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Ingo Molnar, Thomas Gleixner, H Peter Anvin, Steffen Persvold,
	x86, linux-kernel

On 19/02/2013 22:59, Borislav Petkov wrote:
> On Tue, Feb 19, 2013 at 10:40:26PM +0800, Daniel J Blueman wrote:
>> Alas your merges missed the v3.8 merge window, but it looks like your
>> v3.9 pull request has dropped these patches [1].
>>
>> Any chance you can get them in during this merge window?
>
> They should go in anytime now. They're in tip:x86/platform and Ingo is
> sending pull requests to Linus as we speak. Since they touch x86 code I
> asked x86 guys to send them upstream instead of me.

Superb; thanks for your help Boris and Ingo!

Daniel
-- 
Daniel J Blueman
Principal Software Engineer, Numascale Asia

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-02-19 15:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-30  8:44 [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup Daniel J Blueman
2012-11-30  8:44 ` [PATCH 4/4 v8] AMD64 EDAC: Fix type usage in NB IDs and memory ranges Daniel J Blueman
2012-11-30 17:17   ` Borislav Petkov
2012-12-04  9:24     ` Daniel J Blueman
2012-12-04 16:01       ` Borislav Petkov
2013-02-19 14:40         ` Daniel J Blueman
2013-02-19 14:59           ` Borislav Petkov
2013-02-19 15:08             ` Daniel J Blueman
2013-01-22 16:53   ` [tip:x86/platform] amd64_edac: " tip-bot for Daniel J Blueman
2012-11-30 11:27 ` [PATCH 3/4 v8] AMD64 EDAC: Fix PCI function lookup Borislav Petkov
2013-01-22 16:52 ` [tip:x86/platform] amd64_edac: " tip-bot for Daniel J Blueman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).