4 static struct edac_pci_ctl_info *amd64_ctl_pci;
6 static int report_gart_errors;
13 static int ecc_enable_override;
38 { 0x01, 1600000000
UL},
63 static int __amd64_read_pci_cfg_dword(
struct pci_dev *pdev,
int offset,
68 err = pci_read_config_dword(pdev, offset, val);
77 u32 val,
const char *func)
81 err = pci_write_config_dword(pdev, offset, val);
108 return __amd64_read_pci_cfg_dword(pvt->
F2, addr, val, func);
111 static int f10_read_dct_pci_cfg(
struct amd64_pvt *pvt,
int addr,
u32 *val,
114 return __amd64_read_pci_cfg_dword(pvt->
F2, addr, val, func);
120 static void f15h_select_dct(
struct amd64_pvt *pvt,
u8 dct)
130 static int f15_read_dct_pci_cfg(
struct amd64_pvt *pvt,
int addr,
u32 *val,
135 if (addr >= 0x140 && addr <= 0x1a0) {
140 f15h_select_dct(pvt, dct);
142 return __amd64_read_pci_cfg_dword(pvt->
F2, addr, val, func);
163 static int __amd64_set_scrub_rate(
struct pci_dev *
ctl,
u32 new_bw,
u32 min_rate)
191 pci_write_bits32(ctl,
SCRCTRL, scrubval, 0x001F);
202 u32 min_scrubrate = 0x5;
209 f15h_select_dct(pvt, 0);
211 return __amd64_set_scrub_rate(pvt->
F3, bw, min_scrubrate);
214 static int amd64_get_scrub_rate(
struct mem_ctl_info *mci)
222 f15h_select_dct(pvt, 0);
226 scrubval = scrubval & 0x001F;
241 static bool amd64_base_limit_match(
struct amd64_pvt *pvt,
u64 sys_addr,
252 addr = sys_addr & 0x000000ffffffffffull;
254 return ((addr >= get_dram_base(pvt, nid)) &&
255 (addr <= get_dram_limit(pvt, nid)));
285 for (node_id = 0; node_id <
DRAM_RANGES; node_id++) {
286 if (amd64_base_limit_match(pvt, sys_addr, node_id))
293 (intlv_en != 0x03) &&
294 (intlv_en != 0x07))) {
295 amd64_warn(
"DRAM Base[IntlvEn] junk value: 0x%x, BIOS bug?\n", intlv_en);
299 bits = (((
u32) sys_addr) >> 12) & intlv_en;
301 for (node_id = 0; ; ) {
305 if (++node_id >= DRAM_RANGES)
310 if (
unlikely(!amd64_base_limit_match(pvt, sys_addr, node_id))) {
311 amd64_warn(
"%s: sys_addr 0x%llx falls outside base/limit address"
312 "range for node %d with node interleaving enabled.\n",
313 __func__, sys_addr, node_id);
321 edac_dbg(2,
"sys_addr 0x%lx doesn't match any node\n",
322 (
unsigned long)sys_addr);
331 static void get_cs_base_and_mask(
struct amd64_pvt *pvt,
int csrow,
u8 dct,
338 csbase = pvt->
csels[dct].csbases[csrow];
339 csmask = pvt->
csels[dct].csmasks[csrow];
344 csbase = pvt->
csels[dct].csbases[csrow];
345 csmask = pvt->
csels[dct].csmasks[csrow >> 1];
354 *base = (csbase & base_bits) << addr_shift;
360 *mask |= (csmask &
mask_bits) << addr_shift;
363 #define for_each_chip_select(i, dct, pvt) \
364 for (i = 0; i < pvt->csels[dct].b_cnt; i++)
366 #define chip_select_base(i, dct, pvt) \
367 pvt->csels[dct].csbases[i]
369 #define for_each_chip_select_mask(i, dct, pvt) \
370 for (i = 0; i < pvt->csels[dct].m_cnt; i++)
376 static int input_addr_to_csrow(
struct mem_ctl_info *mci,
u64 input_addr)
388 get_cs_base_and_mask(pvt, csrow, 0, &base, &mask);
392 if ((input_addr & mask) == (base & mask)) {
393 edac_dbg(2,
"InputAddr 0x%lx matches csrow %d (node %d)\n",
394 (
unsigned long)input_addr, csrow,
400 edac_dbg(2,
"no matching csrow for InputAddr 0x%lx (MC node %d)\n",
423 u64 *hole_offset,
u64 *hole_size)
430 edac_dbg(1,
" revision %d for node %d does not support DHAR\n",
437 edac_dbg(1,
" Dram Memory Hoisting is DISABLED on this system\n");
442 edac_dbg(1,
" Dram Memory Hoisting is DISABLED on this node %d\n",
468 *hole_size = (0x1ull << 32) - base;
475 edac_dbg(1,
" DHAR info for node %d base 0x%lx offset 0x%lx size 0x%lx\n",
477 (
unsigned long)*hole_offset, (
unsigned long)*hole_size);
515 u64 dram_base, hole_base, hole_offset, hole_size, dram_addr;
518 dram_base = get_dram_base(pvt, pvt->
mc_node_id);
523 if ((sys_addr >= (1ull << 32)) &&
524 (sys_addr < ((1ull << 32) + hole_size))) {
526 dram_addr = sys_addr - hole_offset;
528 edac_dbg(2,
"using DHAR to translate SysAddr 0x%lx to DramAddr 0x%lx\n",
529 (
unsigned long)sys_addr,
530 (
unsigned long)dram_addr);
545 dram_addr = (sys_addr &
GENMASK(0, 39)) - dram_base;
547 edac_dbg(2,
"using DRAM Base register to translate SysAddr 0x%lx to DramAddr 0x%lx\n",
548 (
unsigned long)sys_addr, (
unsigned long)dram_addr);
557 static int num_node_interleave_bits(
unsigned intlv_en)
559 static const int intlv_shift_table[] = { 0, 1, 0, 2, 0, 0, 0, 3 };
563 n = intlv_shift_table[intlv_en];
580 intlv_shift = num_node_interleave_bits(
dram_intlv_en(pvt, 0));
581 input_addr = ((dram_addr >> intlv_shift) &
GENMASK(12, 35)) +
584 edac_dbg(2,
" Intlv Shift=%d DramAddr=0x%lx maps to InputAddr=0x%lx\n",
585 intlv_shift, (
unsigned long)dram_addr,
586 (
unsigned long)input_addr);
600 dram_addr_to_input_addr(mci, sys_addr_to_dram_addr(mci, sys_addr));
602 edac_dbg(2,
"SysAdddr 0x%lx translates to InputAddr 0x%lx\n",
603 (
unsigned long)sys_addr, (
unsigned long)input_addr);
633 intlv_shift = num_node_interleave_bits(
dram_intlv_en(pvt, 0));
634 if (intlv_shift == 0) {
635 edac_dbg(1,
" InputAddr 0x%lx translates to DramAddr of same value\n",
636 (
unsigned long)input_addr);
641 bits = ((input_addr &
GENMASK(12, 35)) << intlv_shift) +
642 (input_addr & 0xfff);
644 intlv_sel =
dram_intlv_sel(pvt, node_id) & ((1 << intlv_shift) - 1);
645 dram_addr = bits + (intlv_sel << 12);
647 edac_dbg(1,
"InputAddr 0x%lx translates to DramAddr 0x%lx (%d node interleave bits)\n",
648 (
unsigned long)input_addr,
649 (
unsigned long)dram_addr, intlv_shift);
661 u64 hole_base, hole_offset, hole_size, base, sys_addr;
667 if ((dram_addr >= hole_base) &&
668 (dram_addr < (hole_base + hole_size))) {
669 sys_addr = dram_addr + hole_offset;
671 edac_dbg(1,
"using DHAR to translate DramAddr 0x%lx to SysAddr 0x%lx\n",
672 (
unsigned long)dram_addr,
673 (
unsigned long)sys_addr);
680 sys_addr = dram_addr + base;
693 sys_addr |= ~((sys_addr & (1ull << 39)) - 1);
695 edac_dbg(1,
" Node %d, DramAddr 0x%lx to SysAddr 0x%lx\n",
697 (
unsigned long)sys_addr);
709 return dram_addr_to_sys_addr(mci,
710 input_addr_to_dram_addr(mci, input_addr));
714 static inline void error_address_to_page_and_offset(
u64 error_address,
733 csrow = input_addr_to_csrow(mci, sys_addr_to_input_addr(mci, sys_addr));
736 amd64_mc_err(mci,
"Failed to translate InputAddr to csrow for "
737 "address 0x%lx\n", (
unsigned long)sys_addr);
747 static unsigned long amd64_determine_edac_cap(
struct amd64_pvt *pvt)
762 static void amd64_debug_display_dimm_sizes(
struct amd64_pvt *,
u8);
764 static void amd64_dump_dramcfg_low(
u32 dclr,
int chan)
766 edac_dbg(1,
"F2x%d90 (DRAM Cfg Low): 0x%08x\n", chan, dclr);
768 edac_dbg(1,
" DIMM type: %sbuffered; all DIMMs support ECC: %s\n",
769 (dclr &
BIT(16)) ?
"un" :
"",
770 (dclr &
BIT(19)) ?
"yes" :
"no");
772 edac_dbg(1,
" PAR/ERR parity: %s\n",
773 (dclr &
BIT(8)) ?
"enabled" :
"disabled");
776 edac_dbg(1,
" DCT 128bit mode width: %s\n",
777 (dclr &
BIT(11)) ?
"128b" :
"64b");
779 edac_dbg(1,
" x4 logical DIMMs present: L0: %s L1: %s L2: %s L3: %s\n",
780 (dclr &
BIT(12)) ?
"yes" :
"no",
781 (dclr &
BIT(13)) ?
"yes" :
"no",
782 (dclr &
BIT(14)) ?
"yes" :
"no",
783 (dclr &
BIT(15)) ?
"yes" :
"no");
787 static void dump_misc_regs(
struct amd64_pvt *pvt)
791 edac_dbg(1,
" NB two channel DRAM capable: %s\n",
794 edac_dbg(1,
" ECC capable: %s, ChipKill ECC capable: %s\n",
798 amd64_dump_dramcfg_low(pvt->
dclr0, 0);
802 edac_dbg(1,
"F1xF0 (DRAM Hole Address): 0x%08x, base: 0x%08x, offset: 0x%08x\n",
809 amd64_debug_display_dimm_sizes(pvt, 0);
815 amd64_debug_display_dimm_sizes(pvt, 1);
821 amd64_dump_dramcfg_low(pvt->
dclr1, 1);
827 static void prep_chip_selects(
struct amd64_pvt *pvt)
830 pvt->
csels[0].b_cnt = pvt->
csels[1].b_cnt = 8;
831 pvt->
csels[0].m_cnt = pvt->
csels[1].m_cnt = 8;
833 pvt->
csels[0].b_cnt = pvt->
csels[1].b_cnt = 8;
834 pvt->
csels[0].m_cnt = pvt->
csels[1].m_cnt = 4;
841 static void read_dct_base_mask(
struct amd64_pvt *pvt)
845 prep_chip_selects(pvt);
854 edac_dbg(0,
" DCSB0[%d]=0x%08x reg: F2x%x\n",
861 edac_dbg(0,
" DCSB1[%d]=0x%08x reg: F2x%x\n",
866 int reg0 =
DCSM0 + (cs * 4);
867 int reg1 =
DCSM1 + (cs * 4);
872 edac_dbg(0,
" DCSM0[%d]=0x%08x reg: F2x%x\n",
879 edac_dbg(0,
" DCSM1[%d]=0x%08x reg: F2x%x\n",
906 static int k8_early_channel_count(
struct amd64_pvt *pvt)
920 return (flag) ? 2 : 1;
924 static u64 get_error_address(
struct mce *
m)
941 if (c->
x86 == 0x15) {
943 u64 cc6_base, tmp_addr;
945 u8 mce_nid, intlv_en;
947 if ((addr &
GENMASK(24, 47)) >> 24 != 0x00fdf7)
954 intlv_en = tmp >> 21 & 0x7;
957 cc6_base = (tmp &
GENMASK(0, 20)) << 3;
960 cc6_base |= intlv_en ^ 0x7;
966 return cc6_base | (addr &
GENMASK(0, 23));
971 tmp_addr = (addr &
GENMASK(12, 23)) <<
__fls(intlv_en + 1);
974 tmp_addr |= (tmp &
GENMASK(21, 23)) >> 9;
977 tmp_addr |= addr &
GENMASK(0, 11);
979 return cc6_base | tmp_addr;
985 static void read_dram_base_limit_regs(
struct amd64_pvt *pvt,
unsigned range)
988 int off = range << 3;
1003 if (c->
x86 == 0x15) {
1017 pvt->
ranges[
range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16;
1028 static void k8_map_sysaddr_to_csrow(
struct mem_ctl_info *mci,
u64 sys_addr,
1036 error_address_to_page_and_offset(sys_addr, &page, &offset);
1042 src_mci = find_mc_by_sys_addr(mci, sys_addr);
1044 amd64_mc_err(mci,
"failed to map error addr 0x%lx to a node\n",
1045 (
unsigned long)sys_addr);
1047 page, offset, syndrome,
1049 "failed to map error addr to a node",
1055 csrow = sys_addr_to_csrow(src_mci, sys_addr);
1058 page, offset, syndrome,
1060 "failed to map error addr to a csrow",
1067 channel = get_channel_from_ecc_syndrome(mci, syndrome);
1075 "possible error reporting race\n",
1078 page, offset, syndrome,
1080 "unknown syndrome - possible error reporting race",
1093 channel = ((sys_addr &
BIT(3)) != 0);
1097 page, offset, syndrome,
1102 static int ddr2_cs_size(
unsigned i,
bool dct_width)
1108 else if (!(i & 0x1))
1111 shift = (i + 1) >> 1;
1113 return 128 << (shift + !!dct_width);
1116 static int k8_dbam_to_chip_select(
struct amd64_pvt *pvt,
u8 dct,
1123 return ddr2_cs_size(cs_mode, dclr &
WIDTH_128);
1153 diff = cs_mode/3 + (unsigned)(cs_mode > 5);
1155 return 32 << (cs_mode - diff);
1159 return 32 << cs_mode;
1171 static int f1x_early_channel_count(
struct amd64_pvt *pvt)
1187 edac_dbg(0,
"Data width is not 128 bits - need more decoding\n");
1194 for (i = 0; i < 2; i++) {
1197 for (j = 0; j < 4; j++) {
1208 amd64_info(
"MCT channel count: %d\n", channels);
1213 static int ddr3_cs_size(
unsigned i,
bool dct_width)
1218 if (i == 0 || i == 3 || i == 4)
1224 else if (!(i & 0x1))
1227 shift = (i + 1) >> 1;
1230 cs_size = (128 * (1 << !!dct_width)) << shift;
1235 static int f10_dbam_to_chip_select(
struct amd64_pvt *pvt,
u8 dct,
1243 return ddr3_cs_size(cs_mode, dclr &
WIDTH_128);
1245 return ddr2_cs_size(cs_mode, dclr &
WIDTH_128);
1251 static int f15_dbam_to_chip_select(
struct amd64_pvt *pvt,
u8 dct,
1256 return ddr3_cs_size(cs_mode,
false);
1259 static void read_dram_ctl_register(
struct amd64_pvt *pvt)
1266 edac_dbg(0,
"F2x110 (DCTSelLow): 0x%08x, High range addrs at: 0x%x\n",
1269 edac_dbg(0,
" DCTs operate in %s mode\n",
1273 edac_dbg(0,
" Address range split per DCT: %s\n",
1276 edac_dbg(0,
" data interleave for ECC: %s, DRAM cleared since last warm reset: %s\n",
1280 edac_dbg(0,
" channel interleave: %s, "
1281 "interleave bits selector: 0x%x\n",
1293 static u8 f1x_determine_channel(
struct amd64_pvt *pvt,
u64 sys_addr,
1294 bool hi_range_sel,
u8 intlv_en)
1302 return dct_sel_high;
1312 return sys_addr >> 6 & 1;
1314 if (intlv_addr & 0x2) {
1315 u8 shift = intlv_addr & 0x1 ? 9 : 6;
1316 u32 temp = hweight_long((
u32) ((sys_addr >> 16) & 0x1F)) % 2;
1318 return ((sys_addr >> shift) & 1) ^
temp;
1321 return (sys_addr >> (12 +
hweight8(intlv_en))) & 1;
1325 return ~dct_sel_high & 1;
1331 static u64 f1x_get_norm_dct_addr(
struct amd64_pvt *pvt,
unsigned range,
1332 u64 sys_addr,
bool hi_rng,
1333 u32 dct_sel_base_addr)
1336 u64 dram_base = get_dram_base(pvt, range);
1338 u64 dct_sel_base_off = (pvt->
dct_sel_hi & 0xFFFFFC00) << 16;
1352 if ((!(dct_sel_base_addr >> 16) ||
1355 (sys_addr >=
BIT_64(32)))
1356 chan_off = hole_off;
1358 chan_off = dct_sel_base_off;
1370 chan_off = hole_off;
1372 chan_off = dram_base;
1382 static int f10_process_possible_spare(
struct amd64_pvt *pvt,
u8 dct,
int csrow)
1411 u64 cs_base, cs_mask;
1421 edac_dbg(1,
"input addr: 0x%llx, DCT: %d\n", in_addr, dct);
1427 get_cs_base_and_mask(pvt, csrow, dct, &cs_base, &cs_mask);
1429 edac_dbg(1,
" CSROW=%d CSBase=0x%llx CSMask=0x%llx\n",
1430 csrow, cs_base, cs_mask);
1434 edac_dbg(1,
" (InputAddr & ~CSMask)=0x%llx (CSBase & ~CSMask)=0x%llx\n",
1435 (in_addr & cs_mask), (cs_base & cs_mask));
1437 if ((in_addr & cs_mask) == (cs_base & cs_mask)) {
1438 cs_found = f10_process_possible_spare(pvt, dct, csrow);
1440 edac_dbg(1,
" MATCH csrow=%d\n", cs_found);
1452 static u64 f1x_swap_interleaved_region(
struct amd64_pvt *pvt,
u64 sys_addr)
1454 u32 swap_reg, swap_base, swap_limit, rgn_size, tmp_addr;
1466 if (!(swap_reg & 0x1))
1469 swap_base = (swap_reg >> 3) & 0x7f;
1470 swap_limit = (swap_reg >> 11) & 0x7f;
1471 rgn_size = (swap_reg >> 20) & 0x7f;
1472 tmp_addr = sys_addr >> 27;
1474 if (!(sys_addr >> 34) &&
1475 (((tmp_addr >= swap_base) &&
1476 (tmp_addr <= swap_limit)) ||
1477 (tmp_addr < rgn_size)))
1478 return sys_addr ^ (
u64)swap_base << 27;
1484 static int f1x_match_to_this_node(
struct amd64_pvt *pvt,
unsigned range,
1485 u64 sys_addr,
int *nid,
int *chan_sel)
1491 bool high_range =
false;
1497 edac_dbg(1,
"(range %d) SystemAddr= 0x%llx Limit=0x%llx\n",
1498 range, sys_addr, get_dram_limit(pvt, range));
1503 amd64_warn(
"Huh? Address is in the MMIO hole: 0x%016llx\n",
1508 if (intlv_en && (intlv_sel != ((sys_addr >> 12) & intlv_en)))
1511 sys_addr = f1x_swap_interleaved_region(pvt, sys_addr);
1521 ((sys_addr >> 27) >= (dct_sel_base >> 11)))
1524 channel = f1x_determine_channel(pvt, sys_addr, high_range, intlv_en);
1526 chan_addr = f1x_get_norm_dct_addr(pvt, range, sys_addr,
1527 high_range, dct_sel_base);
1531 chan_addr = ((chan_addr >> (12 +
hweight8(intlv_en))) << 12) |
1532 (chan_addr & 0xfff);
1542 chan_addr = ((chan_addr >> 10) << 9) |
1543 (chan_addr & 0x1ff);
1546 chan_addr = ((chan_addr >> 7) << 6) |
1550 chan_addr = ((chan_addr >> 13) << 12) |
1551 (chan_addr & 0xfff);
1554 edac_dbg(1,
" Normalized DCT addr: 0x%llx\n", chan_addr);
1556 cs_found = f1x_lookup_addr_in_dct(chan_addr, node_id, channel);
1558 if (cs_found >= 0) {
1565 static int f1x_translate_sysaddr_to_cs(
struct amd64_pvt *pvt,
u64 sys_addr,
1566 int *
node,
int *chan_sel)
1576 if ((get_dram_base(pvt, range) <= sys_addr) &&
1577 (get_dram_limit(pvt, range) >= sys_addr)) {
1579 cs_found = f1x_match_to_this_node(pvt, range,
1596 static void f1x_map_sysaddr_to_csrow(
struct mem_ctl_info *mci,
u64 sys_addr,
1601 int nid, csrow, chan = 0;
1603 error_address_to_page_and_offset(sys_addr, &page, &offset);
1605 csrow = f1x_translate_sysaddr_to_cs(pvt, sys_addr, &nid, &chan);
1609 page, offset, syndrome,
1611 "failed to map error addr to a csrow",
1622 chan = get_channel_from_ecc_syndrome(mci, syndrome);
1625 page, offset, syndrome,
1634 static void amd64_debug_display_dimm_sizes(
struct amd64_pvt *pvt,
u8 ctrl)
1636 int dimm, size0, size1, factor = 0;
1637 u32 *dcsb = ctrl ? pvt->
csels[1].csbases : pvt->
csels[0].csbases;
1653 : pvt->
csels[0].csbases;
1655 edac_dbg(1,
"F2x%d80 (DRAM Bank Address Mapping): 0x%08x\n",
1661 for (dimm = 0; dimm < 4; dimm++) {
1665 size0 = pvt->
ops->dbam_to_cs(pvt, ctrl,
1669 if (dcsb[dimm*2 + 1] & DCSB_CS_ENABLE)
1670 size1 = pvt->
ops->dbam_to_cs(pvt, ctrl,
1674 dimm * 2, size0 << factor,
1675 dimm * 2 + 1, size1 << factor);
1685 .early_channel_count = k8_early_channel_count,
1686 .map_sysaddr_to_csrow = k8_map_sysaddr_to_csrow,
1687 .dbam_to_cs = k8_dbam_to_chip_select,
1688 .read_dct_pci_cfg = k8_read_dct_pci_cfg,
1696 .early_channel_count = f1x_early_channel_count,
1697 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
1698 .dbam_to_cs = f10_dbam_to_chip_select,
1699 .read_dct_pci_cfg = f10_read_dct_pci_cfg,
1707 .early_channel_count = f1x_early_channel_count,
1708 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
1709 .dbam_to_cs = f15_dbam_to_chip_select,
1710 .read_dct_pci_cfg = f15_read_dct_pci_cfg,
1715 static struct pci_dev *pci_get_related_function(
unsigned int vendor,
1723 if ((dev->
bus->number == related->
bus->number) &&
1739 static u16 x4_vectors[] = {
1740 0x2f57, 0x1afe, 0x66cc, 0xdd88,
1741 0x11eb, 0x3396, 0x7f4c, 0xeac8,
1742 0x0001, 0x0002, 0x0004, 0x0008,
1743 0x1013, 0x3032, 0x4044, 0x8088,
1744 0x106b, 0x30d6, 0x70fc, 0xe0a8,
1745 0x4857, 0xc4fe, 0x13cc, 0x3288,
1746 0x1ac5, 0x2f4a, 0x5394, 0xa1e8,
1747 0x1f39, 0x251e, 0xbd6c, 0x6bd8,
1748 0x15c1, 0x2a42, 0x89ac, 0x4758,
1749 0x2b03, 0x1602, 0x4f0c, 0xca08,
1750 0x1f07, 0x3a0e, 0x6b04, 0xbd08,
1751 0x8ba7, 0x465e, 0x244c, 0x1cc8,
1752 0x2b87, 0x164e, 0x642c, 0xdc18,
1753 0x40b9, 0x80de, 0x1094, 0x20e8,
1754 0x27db, 0x1eb6, 0x9dac, 0x7b58,
1755 0x11c1, 0x2242, 0x84ac, 0x4c58,
1756 0x1be5, 0x2d7a, 0x5e34, 0xa718,
1757 0x4b39, 0x8d1e, 0x14b4, 0x28d8,
1758 0x4c97, 0xc87e, 0x11fc, 0x33a8,
1759 0x8e97, 0x497e, 0x2ffc, 0x1aa8,
1760 0x16b3, 0x3d62, 0x4f34, 0x8518,
1761 0x1e2f, 0x391a, 0x5cac, 0xf858,
1762 0x1d9f, 0x3b7a, 0x572c, 0xfe18,
1763 0x15f5, 0x2a5a, 0x5264, 0xa3b8,
1764 0x1dbb, 0x3b66, 0x715c, 0xe3f8,
1765 0x4397, 0xc27e, 0x17fc, 0x3ea8,
1766 0x1617, 0x3d3e, 0x6464, 0xb8b8,
1767 0x23ff, 0x12aa, 0xab6c, 0x56d8,
1768 0x2dfb, 0x1ba6, 0x913c, 0x7328,
1769 0x185d, 0x2ca6, 0x7914, 0x9e28,
1770 0x171b, 0x3e36, 0x7d7c, 0xebe8,
1771 0x4199, 0x82ee, 0x19f4, 0x2e58,
1772 0x4807, 0xc40e, 0x130c, 0x3208,
1773 0x1905, 0x2e0a, 0x5804, 0xac08,
1774 0x213f, 0x132a, 0xadfc, 0x5ba8,
1775 0x19a9, 0x2efe, 0xb5cc, 0x6f88,
1778 static u16 x8_vectors[] = {
1779 0x0145, 0x028a, 0x2374, 0x43c8, 0xa1f0, 0x0520, 0x0a40, 0x1480,
1780 0x0211, 0x0422, 0x0844, 0x1088, 0x01b0, 0x44e0, 0x23c0, 0xed80,
1781 0x1011, 0x0116, 0x022c, 0x0458, 0x08b0, 0x8c60, 0x2740, 0x4e80,
1782 0x0411, 0x0822, 0x1044, 0x0158, 0x02b0, 0x2360, 0x46c0, 0xab80,
1783 0x0811, 0x1022, 0x012c, 0x0258, 0x04b0, 0x4660, 0x8cc0, 0x2780,
1784 0x2071, 0x40e2, 0xa0c4, 0x0108, 0x0210, 0x0420, 0x0840, 0x1080,
1785 0x4071, 0x80e2, 0x0104, 0x0208, 0x0410, 0x0820, 0x1040, 0x2080,
1786 0x8071, 0x0102, 0x0204, 0x0408, 0x0810, 0x1020, 0x2040, 0x4080,
1787 0x019d, 0x03d6, 0x136c, 0x2198, 0x50b0, 0xb2e0, 0x0740, 0x0e80,
1788 0x0189, 0x03ea, 0x072c, 0x0e58, 0x1cb0, 0x56e0, 0x37c0, 0xf580,
1789 0x01fd, 0x0376, 0x06ec, 0x0bb8, 0x1110, 0x2220, 0x4440, 0x8880,
1790 0x0163, 0x02c6, 0x1104, 0x0758, 0x0eb0, 0x2be0, 0x6140, 0xc280,
1791 0x02fd, 0x01c6, 0x0b5c, 0x1108, 0x07b0, 0x25a0, 0x8840, 0x6180,
1792 0x0801, 0x012e, 0x025c, 0x04b8, 0x1370, 0x26e0, 0x57c0, 0xb580,
1793 0x0401, 0x0802, 0x015c, 0x02b8, 0x22b0, 0x13e0, 0x7140, 0xe280,
1794 0x0201, 0x0402, 0x0804, 0x01b8, 0x11b0, 0x31a0, 0x8040, 0x7180,
1795 0x0101, 0x0202, 0x0404, 0x0808, 0x1010, 0x2020, 0x4040, 0x8080,
1796 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
1797 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000,
1800 static int decode_syndrome(
u16 syndrome,
u16 *
vectors,
unsigned num_vecs,
1803 unsigned int i, err_sym;
1805 for (err_sym = 0; err_sym < num_vecs / v_dim; err_sym++) {
1807 unsigned v_idx = err_sym * v_dim;
1808 unsigned v_end = (err_sym + 1) * v_dim;
1811 for (i = 1; i < (1
U << 16); i <<= 1) {
1814 if (v_idx < v_end && vectors[v_idx] & i) {
1815 u16 ev_comp = vectors[v_idx++];
1832 edac_dbg(0,
"syndrome(%x) not found\n", syndrome);
1836 static int map_err_sym_to_channel(
int err_sym,
int sym_size)
1849 return err_sym >> 4;
1869 return err_sym >> 3;
1875 static int get_channel_from_ecc_syndrome(
struct mem_ctl_info *mci,
u16 syndrome)
1881 err_sym = decode_syndrome(syndrome, x8_vectors,
1885 err_sym = decode_syndrome(syndrome, x4_vectors,
1893 return map_err_sym_to_channel(err_sym, pvt->
ecc_sym_sz);
1908 amd64_mc_err(mci,
"HW has no ERROR_ADDRESS available\n");
1912 "HW has no ERROR_ADDRESS available",
1917 sys_addr = get_error_address(m);
1918 syndrome = extract_syndrome(m->
status);
1920 amd64_mc_err(mci,
"CE ERROR_ADDRESS= 0x%llx\n", sys_addr);
1922 pvt->
ops->map_sysaddr_to_csrow(mci, sys_addr, syndrome);
1936 amd64_mc_err(mci,
"HW has no ERROR_ADDRESS available\n");
1940 "HW has no ERROR_ADDRESS available",
1945 sys_addr = get_error_address(m);
1946 error_address_to_page_and_offset(sys_addr, &page, &offset);
1952 src_mci = find_mc_by_sys_addr(mci, sys_addr);
1954 amd64_mc_err(mci,
"ERROR ADDRESS (0x%lx) NOT mapped to a MC\n",
1955 (
unsigned long)sys_addr);
1959 "ERROR ADDRESS NOT mapped to a MC",
1966 csrow = sys_addr_to_csrow(log_mci, sys_addr);
1968 amd64_mc_err(mci,
"ERROR_ADDRESS (0x%lx) NOT mapped to CS\n",
1969 (
unsigned long)sys_addr);
1973 "ERROR ADDRESS NOT mapped to CS",
1983 static inline void __amd64_decode_bus_error(
struct mem_ctl_info *mci,
1988 u8 ecc_type = (m->
status >> 45) & 0x3;
1999 amd64_handle_ce(mci, m);
2000 else if (ecc_type == 1)
2001 amd64_handle_ue(mci, m);
2006 __amd64_decode_bus_error(mcis[node_id], m);
2013 static int reserve_mc_sibling_devs(
struct amd64_pvt *pvt,
u16 f1_id,
u16 f3_id)
2016 pvt->
F1 = pci_get_related_function(pvt->
F2->vendor, f1_id, pvt->
F2);
2018 amd64_err(
"error address map device not found: "
2019 "vendor %x device 0x%x (broken BIOS?)\n",
2025 pvt->
F3 = pci_get_related_function(pvt->
F2->vendor, f3_id, pvt->
F2);
2031 "vendor %x device 0x%x (broken BIOS?)\n",
2043 static void free_mc_sibling_devs(
struct amd64_pvt *pvt)
2053 static void read_mc_regs(
struct amd64_pvt *pvt)
2069 if (msr_val & (1
U << 21)) {
2073 edac_dbg(0,
" TOP_MEM2 disabled\n");
2077 read_dram_ctl_register(pvt);
2083 read_dram_base_limit_regs(pvt, range);
2089 edac_dbg(1,
" DRAM range[%d], base: 0x%016llx; limit: 0x%016llx\n",
2091 get_dram_base(pvt, range),
2092 get_dram_limit(pvt, range));
2094 edac_dbg(1,
" IntlvEn=%s; Range access: %s%s IntlvSel=%d DstNode=%d\n",
2096 (rw & 0x1) ?
"R" :
"-",
2097 (rw & 0x2) ?
"W" :
"-",
2102 read_dct_base_mask(pvt);
2119 if (c->
x86 >= 0x10) {
2127 dump_misc_regs(pvt);
2164 static u32 amd64_csrow_nr_pages(
struct amd64_pvt *pvt,
u8 dct,
int csrow_nr)
2166 u32 cs_mode, nr_pages;
2176 cs_mode = (dbam >> ((csrow_nr / 2) * 4)) & 0xF;
2178 nr_pages = pvt->
ops->dbam_to_cs(pvt, dct, cs_mode) << (20 -
PAGE_SHIFT);
2180 edac_dbg(0,
" (csrow=%d) DBAM map index= %d\n", csrow_nr, cs_mode);
2181 edac_dbg(0,
" nr_pages/channel= %u channel-count = %d\n",
2207 edac_dbg(0,
"node %d, NBCFG=0x%08x[ChipKillEccCap: %d|DramEccEn: %d]\n",
2215 edac_dbg(1,
"----CSROW %d VALID for MC node %d\n",
2222 nr_pages = amd64_csrow_nr_pages(pvt, 0, i);
2224 nr_pages += amd64_csrow_nr_pages(pvt, 1, i);
2226 get_cs_base_and_mask(pvt, i, 0, &base, &mask);
2229 mtype = amd64_determine_memory_type(pvt, i);
2246 dimm->
mtype = mtype;
2256 static void get_cpus_on_this_dct_cpumask(
struct cpumask *mask,
unsigned nid)
2262 cpumask_set_cpu(cpu, mask);
2266 static
bool amd64_nb_mce_bank_enabled_on_node(
unsigned nid)
2272 if (!zalloc_cpumask_var(&mask,
GFP_KERNEL)) {
2273 amd64_warn(
"%s: Error allocating mask\n", __func__);
2277 get_cpus_on_this_dct_cpumask(mask, nid);
2285 edac_dbg(0,
"core: %u, MCG_CTL: 0x%llx, NB MSR is %s\n",
2287 (nbe ?
"enabled" :
"disabled"));
2295 free_cpumask_var(mask);
2299 static int toggle_ecc_err_reporting(
struct ecc_settings *s,
u8 nid,
bool on)
2304 if (!zalloc_cpumask_var(&cmask,
GFP_KERNEL)) {
2305 amd64_warn(
"%s: error allocating mask\n", __func__);
2309 get_cpus_on_this_dct_cpumask(cmask, nid);
2319 s->
flags.nb_mce_enable = 1;
2326 if (!s->
flags.nb_mce_enable)
2332 free_cpumask_var(cmask);
2337 static bool enable_ecc_error_reporting(
struct ecc_settings *s,
u8 nid,
2343 if (toggle_ecc_err_reporting(s, nid,
ON)) {
2344 amd64_warn(
"Error enabling ECC reporting over MCGCTL!\n");
2358 edac_dbg(0,
"1: node %d, NBCFG=0x%08x[DramEccEn: %d]\n",
2362 amd64_warn(
"DRAM ECC disabled on this node, enabling...\n");
2364 s->
flags.nb_ecc_prev = 0;
2372 if (!(value & NBCFG_ECC_ENABLE)) {
2373 amd64_warn(
"Hardware rejected DRAM ECC enable,"
2374 "check memory DIMM configuration.\n");
2377 amd64_info(
"Hardware accepted DRAM ECC Enable\n");
2380 s->
flags.nb_ecc_prev = 1;
2383 edac_dbg(0,
"2: node %d, NBCFG=0x%08x[DramEccEn: %d]\n",
2384 nid, value, !!(value & NBCFG_ECC_ENABLE));
2389 static void restore_ecc_error_reporting(
struct ecc_settings *s,
u8 nid,
2405 if (!s->
flags.nb_ecc_prev) {
2407 value &= ~NBCFG_ECC_ENABLE;
2412 if (toggle_ecc_err_reporting(s, nid,
OFF))
2413 amd64_warn(
"Error restoring NB MCGCTL settings!\n");
2422 static const char *ecc_msg =
2423 "ECC disabled in the BIOS or no ECC capability, module will not load.\n"
2424 " Either enable ECC checking or force module loading by setting "
2425 "'ecc_enable_override'.\n"
2426 " (Note that use of the override may cause unknown side effects.)\n";
2428 static bool ecc_enabled(
struct pci_dev *F3,
u8 nid)
2432 bool nb_mce_en =
false;
2437 amd64_info(
"DRAM ECC %s.\n", (ecc_en ?
"enabled" :
"disabled"));
2439 nb_mce_en = amd64_nb_mce_bank_enabled_on_node(nid);
2442 "0x%08x[4] on node %d to enable.\n",
2445 if (!ecc_en || !nb_mce_en) {
2452 static int set_mc_sysfs_attrs(
struct mem_ctl_info *mci)
2469 static void del_mc_sysfs_attrs(
struct mem_ctl_info *mci)
2477 static void setup_mci_misc_attrs(
struct mem_ctl_info *mci,
2491 mci->
edac_cap = amd64_determine_edac_cap(pvt);
2513 fam_type = &amd64_family_types[
K8_CPUS];
2518 fam_type = &amd64_family_types[
F10_CPUS];
2523 fam_type = &amd64_family_types[
F15_CPUS];
2537 :
"revE or earlier ")
2542 static int amd64_init_one_instance(
struct pci_dev *
F2)
2549 u8 nid = get_node_id(F2);
2560 fam_type = amd64_per_family_init(pvt);
2565 err = reserve_mc_sibling_devs(pvt, fam_type->
f1_id, fam_type->
f3_id);
2584 layers[0].is_virt_csrow =
true;
2587 layers[1].is_virt_csrow =
false;
2593 mci->
pdev = &pvt->
F2->dev;
2595 setup_mci_misc_attrs(mci, fam_type);
2597 if (init_csrows(mci))
2602 edac_dbg(1,
"failed edac_mc_add_mc()\n");
2605 if (set_mc_sysfs_attrs(mci)) {
2606 edac_dbg(1,
"failed edac_mc_add_mc()\n");
2611 if (report_gart_errors)
2628 free_mc_sibling_devs(pvt);
2640 u8 nid = get_node_id(pdev);
2658 if (!ecc_enabled(F3, nid)) {
2661 if (!ecc_enable_override)
2666 if (!enable_ecc_error_reporting(s, nid, F3))
2670 ret = amd64_init_one_instance(pdev);
2672 amd64_err(
"Error probing instance: %d\n", nid);
2673 restore_ecc_error_reporting(s, nid, F3);
2680 ecc_stngs[nid] =
NULL;
2690 u8 nid = get_node_id(pdev);
2695 del_mc_sysfs_attrs(mci);
2703 restore_ecc_error_reporting(s, nid, F3);
2705 free_mc_sibling_devs(pvt);
2711 kfree(ecc_stngs[nid]);
2712 ecc_stngs[nid] =
NULL;
2757 static struct pci_driver amd64_pci_driver = {
2759 .probe = amd64_probe_one_instance,
2761 .id_table = amd64_pci_table,
2764 static void setup_pci_device(
void)
2779 if (!amd64_ctl_pci) {
2780 pr_warning(
"%s(): Unable to create PCI control\n",
2783 pr_warning(
"%s(): PCI error report via EDAC not set\n",
2789 static int __init amd64_edac_init(
void)
2803 if (!(mcis && ecc_stngs))
2810 err = pci_register_driver(&amd64_pci_driver);
2816 goto err_no_instances;
2839 static void __exit amd64_edac_exit(
void)
2861 "Dave Peterson, Thayne Harbaugh");