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

EDAC, sb_edac: Add Knights Landing (Xeon Phi gen 2) support

Knights Landing is the next generation architecture for HPC market.

KNL introduces concept of a tile and CHA - Cache/Home Agent for memory
accesses.

Some things are fixed in KNL:
() There's single DIMM slot per channel
() There's 2 memory controllers with 3 channels each, however,
from EDAC standpoint, it is presented as single memory controller
with 6 channels. In order to represent 2 MCs w/ 3 CH, it would
require major redesign of EDAC core driver.

Basically, two functionalities are added/extended:
() during driver initialization KNL topology is being recognized, i.e.
which channels are populated with what DIMM sizes
(knl_get_dimm_capacity function)
() handle MCE errors - channel swizzling

Reviewed-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Jim Snow <jim.m.snow@intel.com>
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Cc: lukasz.anaczkowski@intel.com
Link: http://lkml.kernel.org/r/1449136134-23706-5-git-send-email-hubert.chrzaniuk@intel.com
[ Rebase to 4.4-rc3. ]
Signed-off-by: Hubert Chrzaniuk <hubert.chrzaniuk@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>

authored by

Jim Snow and committed by
Borislav Petkov
d0cdf900 c1979ba2

+922 -46
+922 -46
drivers/edac/sb_edac.c
··· 65 65 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, 66 66 }; 67 67 68 + static const u32 knl_dram_rule[] = { 69 + 0x60, 0x68, 0x70, 0x78, 0x80, /* 0-4 */ 70 + 0x88, 0x90, 0x98, 0xa0, 0xa8, /* 5-9 */ 71 + 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, /* 10-14 */ 72 + 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, /* 15-19 */ 73 + 0x100, 0x108, 0x110, 0x118, /* 20-23 */ 74 + }; 75 + 68 76 #define DRAM_RULE_ENABLE(reg) GET_BITFIELD(reg, 0, 0) 69 77 #define A7MODE(reg) GET_BITFIELD(reg, 26, 26) 70 78 ··· 100 92 0x8c, 0x94, 0x9c, 0xa4, 0xac, 101 93 0xb4, 0xbc, 0xc4, 0xcc, 0xd4, 102 94 0xdc, 0xe4, 0xec, 0xf4, 0xfc, 95 + }; 96 + 97 + static const u32 knl_interleave_list[] = { 98 + 0x64, 0x6c, 0x74, 0x7c, 0x84, /* 0-4 */ 99 + 0x8c, 0x94, 0x9c, 0xa4, 0xac, /* 5-9 */ 100 + 0xb4, 0xbc, 0xc4, 0xcc, 0xd4, /* 10-14 */ 101 + 0xdc, 0xe4, 0xec, 0xf4, 0xfc, /* 15-19 */ 102 + 0x104, 0x10c, 0x114, 0x11c, /* 20-23 */ 103 103 }; 104 104 105 105 struct interleave_pkg { ··· 147 131 /* Devices 12 Function 7 */ 148 132 149 133 #define TOLM 0x80 150 - #define TOHM 0x84 134 + #define TOHM 0x84 151 135 #define HASWELL_TOLM 0xd0 152 136 #define HASWELL_TOHM_0 0xd4 153 137 #define HASWELL_TOHM_1 0xd8 138 + #define KNL_TOLM 0xd0 139 + #define KNL_TOHM_0 0xd4 140 + #define KNL_TOHM_1 0xd8 154 141 155 142 #define GET_TOLM(reg) ((GET_BITFIELD(reg, 0, 3) << 28) | 0x3ffffff) 156 143 #define GET_TOHM(reg) ((GET_BITFIELD(reg, 0, 20) << 25) | 0x3ffffff) ··· 163 144 #define SAD_TARGET 0xf0 164 145 165 146 #define SOURCE_ID(reg) GET_BITFIELD(reg, 9, 11) 147 + 148 + #define SOURCE_ID_KNL(reg) GET_BITFIELD(reg, 12, 14) 166 149 167 150 #define SAD_CONTROL 0xf4 168 151 ··· 188 167 /* Device 15, function 0 */ 189 168 190 169 #define MCMTR 0x7c 170 + #define KNL_MCMTR 0x624 191 171 192 172 #define IS_ECC_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 2, 2) 193 173 #define IS_LOCKSTEP_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 1, 1) ··· 204 182 static const int mtr_regs[] = { 205 183 0x80, 0x84, 0x88, 206 184 }; 185 + 186 + static const int knl_mtr_reg = 0xb60; 207 187 208 188 #define RANK_DISABLE(mtr) GET_BITFIELD(mtr, 16, 19) 209 189 #define IS_DIMM_PRESENT(mtr) GET_BITFIELD(mtr, 14, 14) ··· 277 253 278 254 #define NUM_CHANNELS 8 /* 2MC per socket, four chan per MC */ 279 255 #define MAX_DIMMS 3 /* Max DIMMS per channel */ 256 + #define KNL_MAX_CHAS 38 /* KNL max num. of Cache Home Agents */ 257 + #define KNL_MAX_CHANNELS 6 /* KNL max num. of PCI channels */ 258 + #define KNL_MAX_EDCS 8 /* Embedded DRAM controllers */ 280 259 #define CHANNEL_UNSPECIFIED 0xf /* Intel IA32 SDM 15-14 */ 281 260 282 261 enum type { ··· 287 260 IVY_BRIDGE, 288 261 HASWELL, 289 262 BROADWELL, 263 + KNIGHTS_LANDING, 290 264 }; 291 265 292 266 struct sbridge_pvt; ··· 337 309 struct mem_ctl_info *mci; 338 310 }; 339 311 312 + struct knl_pvt { 313 + struct pci_dev *pci_cha[KNL_MAX_CHAS]; 314 + struct pci_dev *pci_channel[KNL_MAX_CHANNELS]; 315 + struct pci_dev *pci_mc0; 316 + struct pci_dev *pci_mc1; 317 + struct pci_dev *pci_mc0_misc; 318 + struct pci_dev *pci_mc1_misc; 319 + struct pci_dev *pci_mc_info; /* tolm, tohm */ 320 + }; 321 + 340 322 struct sbridge_pvt { 341 323 struct pci_dev *pci_ta, *pci_ddrio, *pci_ras; 342 324 struct pci_dev *pci_sad0, *pci_sad1; ··· 375 337 376 338 /* Memory description */ 377 339 u64 tolm, tohm; 340 + struct knl_pvt knl; 378 341 }; 379 342 380 343 #define PCI_DESCR(device_id, opt) \ ··· 549 510 {0,} /* 0 terminated list. */ 550 511 }; 551 512 513 + /* Knight's Landing Support */ 514 + /* 515 + * KNL's memory channels are swizzled between memory controllers. 516 + * MC0 is mapped to CH3,5,6 and MC1 is mapped to CH0,1,2 517 + */ 518 + #define knl_channel_remap(channel) ((channel + 3) % 6) 519 + 520 + /* Memory controller, TAD tables, error injection - 2-8-0, 2-9-0 (2 of these) */ 521 + #define PCI_DEVICE_ID_INTEL_KNL_IMC_MC 0x7840 522 + /* DRAM channel stuff; bank addrs, dimmmtr, etc.. 2-8-2 - 2-9-4 (6 of these) */ 523 + #define PCI_DEVICE_ID_INTEL_KNL_IMC_CHANNEL 0x7843 524 + /* kdrwdbu TAD limits/offsets, MCMTR - 2-10-1, 2-11-1 (2 of these) */ 525 + #define PCI_DEVICE_ID_INTEL_KNL_IMC_TA 0x7844 526 + /* CHA broadcast registers, dram rules - 1-29-0 (1 of these) */ 527 + #define PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0 0x782a 528 + /* SAD target - 1-29-1 (1 of these) */ 529 + #define PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1 0x782b 530 + /* Caching / Home Agent */ 531 + #define PCI_DEVICE_ID_INTEL_KNL_IMC_CHA 0x782c 532 + /* Device with TOLM and TOHM, 0-5-0 (1 of these) */ 533 + #define PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM 0x7810 534 + 535 + /* 536 + * KNL differs from SB, IB, and Haswell in that it has multiple 537 + * instances of the same device with the same device ID, so we handle that 538 + * by creating as many copies in the table as we expect to find. 539 + * (Like device ID must be grouped together.) 540 + */ 541 + 542 + static const struct pci_id_descr pci_dev_descr_knl[] = { 543 + [0] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0, 0) }, 544 + [1] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1, 0) }, 545 + [2 ... 3] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_MC, 0)}, 546 + [4 ... 41] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_CHA, 0) }, 547 + [42 ... 47] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_CHANNEL, 0) }, 548 + [48] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_TA, 0) }, 549 + [49] = { PCI_DESCR(PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM, 0) }, 550 + }; 551 + 552 + static const struct pci_id_table pci_dev_descr_knl_table[] = { 553 + PCI_ID_TABLE_ENTRY(pci_dev_descr_knl), 554 + {0,} 555 + }; 556 + 552 557 /* 553 558 * Broadwell support 554 559 * ··· 669 586 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA)}, 670 587 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0)}, 671 588 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0)}, 589 + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0)}, 672 590 {0,} /* 0 terminated list. */ 673 591 }; 674 592 ··· 683 599 int ranks = (1 << RANK_CNT_BITS(mtr)); 684 600 int max = 4; 685 601 686 - if (type == HASWELL || type == BROADWELL) 602 + if (type == HASWELL || type == BROADWELL || type == KNIGHTS_LANDING) 687 603 max = 8; 688 604 689 605 if (ranks > max) { ··· 832 748 return GET_BITFIELD(reg, 2, 3); 833 749 } 834 750 751 + static u64 knl_sad_limit(u32 reg) 752 + { 753 + return (GET_BITFIELD(reg, 7, 26) << 26) | 0x3ffffff; 754 + } 755 + 756 + static u32 knl_interleave_mode(u32 reg) 757 + { 758 + return GET_BITFIELD(reg, 1, 2); 759 + } 760 + 761 + static char *knl_show_interleave_mode(u32 reg) 762 + { 763 + char *s; 764 + 765 + switch (knl_interleave_mode(reg)) { 766 + case 0: 767 + s = "use address bits [8:6]"; 768 + break; 769 + case 1: 770 + s = "use address bits [10:8]"; 771 + break; 772 + case 2: 773 + s = "use address bits [14:12]"; 774 + break; 775 + case 3: 776 + s = "use address bits [32:30]"; 777 + break; 778 + default: 779 + WARN_ON(1); 780 + break; 781 + } 782 + 783 + return s; 784 + } 785 + 786 + static u32 dram_attr_knl(u32 reg) 787 + { 788 + return GET_BITFIELD(reg, 3, 4); 789 + } 790 + 791 + 835 792 static enum mem_type get_memory_type(struct sbridge_pvt *pvt) 836 793 { 837 794 u32 reg; ··· 967 842 return __ibridge_get_width(GET_BITFIELD(mtr, 8, 9)); 968 843 } 969 844 845 + static enum mem_type knl_get_memory_type(struct sbridge_pvt *pvt) 846 + { 847 + /* DDR4 RDIMMS and LRDIMMS are supported */ 848 + return MEM_RDDR4; 849 + } 850 + 970 851 static u8 get_node_id(struct sbridge_pvt *pvt) 971 852 { 972 853 u32 reg; ··· 987 856 pci_read_config_dword(pvt->pci_sad1, SAD_CONTROL, &reg); 988 857 return GET_BITFIELD(reg, 0, 3); 989 858 } 859 + 860 + static u8 knl_get_node_id(struct sbridge_pvt *pvt) 861 + { 862 + u32 reg; 863 + 864 + pci_read_config_dword(pvt->pci_sad1, SAD_CONTROL, &reg); 865 + return GET_BITFIELD(reg, 0, 2); 866 + } 867 + 990 868 991 869 static u64 haswell_get_tolm(struct sbridge_pvt *pvt) 992 870 { ··· 1017 877 1018 878 return rc | 0x1ffffff; 1019 879 } 880 + 881 + static u64 knl_get_tolm(struct sbridge_pvt *pvt) 882 + { 883 + u32 reg; 884 + 885 + pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOLM, &reg); 886 + return (GET_BITFIELD(reg, 26, 31) << 26) | 0x3ffffff; 887 + } 888 + 889 + static u64 knl_get_tohm(struct sbridge_pvt *pvt) 890 + { 891 + u64 rc; 892 + u32 reg_lo, reg_hi; 893 + 894 + pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOHM_0, &reg_lo); 895 + pci_read_config_dword(pvt->knl.pci_mc_info, KNL_TOHM_1, &reg_hi); 896 + rc = ((u64)reg_hi << 32) | reg_lo; 897 + return rc | 0x3ffffff; 898 + } 899 + 1020 900 1021 901 static u64 haswell_rir_limit(u32 reg) 1022 902 { ··· 1095 935 case BROADWELL: 1096 936 id = PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0_TA; 1097 937 break; 938 + case KNIGHTS_LANDING: 939 + /* 940 + * KNL doesn't group things by bus the same way 941 + * SB/IB/Haswell does. 942 + */ 943 + id = PCI_DEVICE_ID_INTEL_KNL_IMC_TA; 944 + break; 1098 945 default: 1099 946 return -ENODEV; 1100 947 } 1101 948 1102 - pdev = get_pdev_same_bus(bus, id); 949 + if (type != KNIGHTS_LANDING) 950 + pdev = get_pdev_same_bus(bus, id); 951 + else 952 + pdev = pci_get_device(PCI_VENDOR_ID_INTEL, id, 0); 953 + 1103 954 if (!pdev) { 1104 955 sbridge_printk(KERN_ERR, "Couldn't find PCI device " 1105 956 "%04x:%04x! on bus %02d\n", ··· 1118 947 return -ENODEV; 1119 948 } 1120 949 1121 - pci_read_config_dword(pdev, MCMTR, &mcmtr); 950 + pci_read_config_dword(pdev, 951 + type == KNIGHTS_LANDING ? KNL_MCMTR : MCMTR, &mcmtr); 1122 952 if (!IS_ECC_ENABLED(mcmtr)) { 1123 953 sbridge_printk(KERN_ERR, "ECC is disabled. Aborting\n"); 1124 954 return -ENODEV; 1125 955 } 956 + return 0; 957 + } 958 + 959 + /* Low bits of TAD limit, and some metadata. */ 960 + static const u32 knl_tad_dram_limit_lo[] = { 961 + 0x400, 0x500, 0x600, 0x700, 962 + 0x800, 0x900, 0xa00, 0xb00, 963 + }; 964 + 965 + /* Low bits of TAD offset. */ 966 + static const u32 knl_tad_dram_offset_lo[] = { 967 + 0x404, 0x504, 0x604, 0x704, 968 + 0x804, 0x904, 0xa04, 0xb04, 969 + }; 970 + 971 + /* High 16 bits of TAD limit and offset. */ 972 + static const u32 knl_tad_dram_hi[] = { 973 + 0x408, 0x508, 0x608, 0x708, 974 + 0x808, 0x908, 0xa08, 0xb08, 975 + }; 976 + 977 + /* Number of ways a tad entry is interleaved. */ 978 + static const u32 knl_tad_ways[] = { 979 + 8, 6, 4, 3, 2, 1, 980 + }; 981 + 982 + /* 983 + * Retrieve the n'th Target Address Decode table entry 984 + * from the memory controller's TAD table. 985 + * 986 + * @pvt: driver private data 987 + * @entry: which entry you want to retrieve 988 + * @mc: which memory controller (0 or 1) 989 + * @offset: output tad range offset 990 + * @limit: output address of first byte above tad range 991 + * @ways: output number of interleave ways 992 + * 993 + * The offset value has curious semantics. It's a sort of running total 994 + * of the sizes of all the memory regions that aren't mapped in this 995 + * tad table. 996 + */ 997 + static int knl_get_tad(const struct sbridge_pvt *pvt, 998 + const int entry, 999 + const int mc, 1000 + u64 *offset, 1001 + u64 *limit, 1002 + int *ways) 1003 + { 1004 + u32 reg_limit_lo, reg_offset_lo, reg_hi; 1005 + struct pci_dev *pci_mc; 1006 + int way_id; 1007 + 1008 + switch (mc) { 1009 + case 0: 1010 + pci_mc = pvt->knl.pci_mc0; 1011 + break; 1012 + case 1: 1013 + pci_mc = pvt->knl.pci_mc1; 1014 + break; 1015 + default: 1016 + WARN_ON(1); 1017 + return -EINVAL; 1018 + } 1019 + 1020 + pci_read_config_dword(pci_mc, 1021 + knl_tad_dram_limit_lo[entry], &reg_limit_lo); 1022 + pci_read_config_dword(pci_mc, 1023 + knl_tad_dram_offset_lo[entry], &reg_offset_lo); 1024 + pci_read_config_dword(pci_mc, 1025 + knl_tad_dram_hi[entry], &reg_hi); 1026 + 1027 + /* Is this TAD entry enabled? */ 1028 + if (!GET_BITFIELD(reg_limit_lo, 0, 0)) 1029 + return -ENODEV; 1030 + 1031 + way_id = GET_BITFIELD(reg_limit_lo, 3, 5); 1032 + 1033 + if (way_id < ARRAY_SIZE(knl_tad_ways)) { 1034 + *ways = knl_tad_ways[way_id]; 1035 + } else { 1036 + *ways = 0; 1037 + sbridge_printk(KERN_ERR, 1038 + "Unexpected value %d in mc_tad_limit_lo wayness field\n", 1039 + way_id); 1040 + return -ENODEV; 1041 + } 1042 + 1043 + /* 1044 + * The least significant 6 bits of base and limit are truncated. 1045 + * For limit, we fill the missing bits with 1s. 1046 + */ 1047 + *offset = ((u64) GET_BITFIELD(reg_offset_lo, 6, 31) << 6) | 1048 + ((u64) GET_BITFIELD(reg_hi, 0, 15) << 32); 1049 + *limit = ((u64) GET_BITFIELD(reg_limit_lo, 6, 31) << 6) | 63 | 1050 + ((u64) GET_BITFIELD(reg_hi, 16, 31) << 32); 1051 + 1052 + return 0; 1053 + } 1054 + 1055 + /* Determine which memory controller is responsible for a given channel. */ 1056 + static int knl_channel_mc(int channel) 1057 + { 1058 + WARN_ON(channel < 0 || channel >= 6); 1059 + 1060 + return channel < 3 ? 1 : 0; 1061 + } 1062 + 1063 + /* 1064 + * Get the Nth entry from EDC_ROUTE_TABLE register. 1065 + * (This is the per-tile mapping of logical interleave targets to 1066 + * physical EDC modules.) 1067 + * 1068 + * entry 0: 0:2 1069 + * 1: 3:5 1070 + * 2: 6:8 1071 + * 3: 9:11 1072 + * 4: 12:14 1073 + * 5: 15:17 1074 + * 6: 18:20 1075 + * 7: 21:23 1076 + * reserved: 24:31 1077 + */ 1078 + static u32 knl_get_edc_route(int entry, u32 reg) 1079 + { 1080 + WARN_ON(entry >= KNL_MAX_EDCS); 1081 + return GET_BITFIELD(reg, entry*3, (entry*3)+2); 1082 + } 1083 + 1084 + /* 1085 + * Get the Nth entry from MC_ROUTE_TABLE register. 1086 + * (This is the per-tile mapping of logical interleave targets to 1087 + * physical DRAM channels modules.) 1088 + * 1089 + * entry 0: mc 0:2 channel 18:19 1090 + * 1: mc 3:5 channel 20:21 1091 + * 2: mc 6:8 channel 22:23 1092 + * 3: mc 9:11 channel 24:25 1093 + * 4: mc 12:14 channel 26:27 1094 + * 5: mc 15:17 channel 28:29 1095 + * reserved: 30:31 1096 + * 1097 + * Though we have 3 bits to identify the MC, we should only see 1098 + * the values 0 or 1. 1099 + */ 1100 + 1101 + static u32 knl_get_mc_route(int entry, u32 reg) 1102 + { 1103 + int mc, chan; 1104 + 1105 + WARN_ON(entry >= KNL_MAX_CHANNELS); 1106 + 1107 + mc = GET_BITFIELD(reg, entry*3, (entry*3)+2); 1108 + chan = GET_BITFIELD(reg, (entry*2) + 18, (entry*2) + 18 + 1); 1109 + 1110 + return knl_channel_remap(mc*3 + chan); 1111 + } 1112 + 1113 + /* 1114 + * Render the EDC_ROUTE register in human-readable form. 1115 + * Output string s should be at least KNL_MAX_EDCS*2 bytes. 1116 + */ 1117 + static void knl_show_edc_route(u32 reg, char *s) 1118 + { 1119 + int i; 1120 + 1121 + for (i = 0; i < KNL_MAX_EDCS; i++) { 1122 + s[i*2] = knl_get_edc_route(i, reg) + '0'; 1123 + s[i*2+1] = '-'; 1124 + } 1125 + 1126 + s[KNL_MAX_EDCS*2 - 1] = '\0'; 1127 + } 1128 + 1129 + /* 1130 + * Render the MC_ROUTE register in human-readable form. 1131 + * Output string s should be at least KNL_MAX_CHANNELS*2 bytes. 1132 + */ 1133 + static void knl_show_mc_route(u32 reg, char *s) 1134 + { 1135 + int i; 1136 + 1137 + for (i = 0; i < KNL_MAX_CHANNELS; i++) { 1138 + s[i*2] = knl_get_mc_route(i, reg) + '0'; 1139 + s[i*2+1] = '-'; 1140 + } 1141 + 1142 + s[KNL_MAX_CHANNELS*2 - 1] = '\0'; 1143 + } 1144 + 1145 + #define KNL_EDC_ROUTE 0xb8 1146 + #define KNL_MC_ROUTE 0xb4 1147 + 1148 + /* Is this dram rule backed by regular DRAM in flat mode? */ 1149 + #define KNL_EDRAM(reg) GET_BITFIELD(reg, 29, 29) 1150 + 1151 + /* Is this dram rule cached? */ 1152 + #define KNL_CACHEABLE(reg) GET_BITFIELD(reg, 28, 28) 1153 + 1154 + /* Is this rule backed by edc ? */ 1155 + #define KNL_EDRAM_ONLY(reg) GET_BITFIELD(reg, 29, 29) 1156 + 1157 + /* Is this rule backed by DRAM, cacheable in EDRAM? */ 1158 + #define KNL_CACHEABLE(reg) GET_BITFIELD(reg, 28, 28) 1159 + 1160 + /* Is this rule mod3? */ 1161 + #define KNL_MOD3(reg) GET_BITFIELD(reg, 27, 27) 1162 + 1163 + /* 1164 + * Figure out how big our RAM modules are. 1165 + * 1166 + * The DIMMMTR register in KNL doesn't tell us the size of the DIMMs, so we 1167 + * have to figure this out from the SAD rules, interleave lists, route tables, 1168 + * and TAD rules. 1169 + * 1170 + * SAD rules can have holes in them (e.g. the 3G-4G hole), so we have to 1171 + * inspect the TAD rules to figure out how large the SAD regions really are. 1172 + * 1173 + * When we know the real size of a SAD region and how many ways it's 1174 + * interleaved, we know the individual contribution of each channel to 1175 + * TAD is size/ways. 1176 + * 1177 + * Finally, we have to check whether each channel participates in each SAD 1178 + * region. 1179 + * 1180 + * Fortunately, KNL only supports one DIMM per channel, so once we know how 1181 + * much memory the channel uses, we know the DIMM is at least that large. 1182 + * (The BIOS might possibly choose not to map all available memory, in which 1183 + * case we will underreport the size of the DIMM.) 1184 + * 1185 + * In theory, we could try to determine the EDC sizes as well, but that would 1186 + * only work in flat mode, not in cache mode. 1187 + * 1188 + * @mc_sizes: Output sizes of channels (must have space for KNL_MAX_CHANNELS 1189 + * elements) 1190 + */ 1191 + static int knl_get_dimm_capacity(struct sbridge_pvt *pvt, u64 *mc_sizes) 1192 + { 1193 + u64 sad_base, sad_size, sad_limit = 0; 1194 + u64 tad_base, tad_size, tad_limit, tad_deadspace, tad_livespace; 1195 + int sad_rule = 0; 1196 + int tad_rule = 0; 1197 + int intrlv_ways, tad_ways; 1198 + u32 first_pkg, pkg; 1199 + int i; 1200 + u64 sad_actual_size[2]; /* sad size accounting for holes, per mc */ 1201 + u32 dram_rule, interleave_reg; 1202 + u32 mc_route_reg[KNL_MAX_CHAS]; 1203 + u32 edc_route_reg[KNL_MAX_CHAS]; 1204 + int edram_only; 1205 + char edc_route_string[KNL_MAX_EDCS*2]; 1206 + char mc_route_string[KNL_MAX_CHANNELS*2]; 1207 + int cur_reg_start; 1208 + int mc; 1209 + int channel; 1210 + int way; 1211 + int participants[KNL_MAX_CHANNELS]; 1212 + int participant_count = 0; 1213 + 1214 + for (i = 0; i < KNL_MAX_CHANNELS; i++) 1215 + mc_sizes[i] = 0; 1216 + 1217 + /* Read the EDC route table in each CHA. */ 1218 + cur_reg_start = 0; 1219 + for (i = 0; i < KNL_MAX_CHAS; i++) { 1220 + pci_read_config_dword(pvt->knl.pci_cha[i], 1221 + KNL_EDC_ROUTE, &edc_route_reg[i]); 1222 + 1223 + if (i > 0 && edc_route_reg[i] != edc_route_reg[i-1]) { 1224 + knl_show_edc_route(edc_route_reg[i-1], 1225 + edc_route_string); 1226 + if (cur_reg_start == i-1) 1227 + edac_dbg(0, "edc route table for CHA %d: %s\n", 1228 + cur_reg_start, edc_route_string); 1229 + else 1230 + edac_dbg(0, "edc route table for CHA %d-%d: %s\n", 1231 + cur_reg_start, i-1, edc_route_string); 1232 + cur_reg_start = i; 1233 + } 1234 + } 1235 + knl_show_edc_route(edc_route_reg[i-1], edc_route_string); 1236 + if (cur_reg_start == i-1) 1237 + edac_dbg(0, "edc route table for CHA %d: %s\n", 1238 + cur_reg_start, edc_route_string); 1239 + else 1240 + edac_dbg(0, "edc route table for CHA %d-%d: %s\n", 1241 + cur_reg_start, i-1, edc_route_string); 1242 + 1243 + /* Read the MC route table in each CHA. */ 1244 + cur_reg_start = 0; 1245 + for (i = 0; i < KNL_MAX_CHAS; i++) { 1246 + pci_read_config_dword(pvt->knl.pci_cha[i], 1247 + KNL_MC_ROUTE, &mc_route_reg[i]); 1248 + 1249 + if (i > 0 && mc_route_reg[i] != mc_route_reg[i-1]) { 1250 + knl_show_mc_route(mc_route_reg[i-1], mc_route_string); 1251 + if (cur_reg_start == i-1) 1252 + edac_dbg(0, "mc route table for CHA %d: %s\n", 1253 + cur_reg_start, mc_route_string); 1254 + else 1255 + edac_dbg(0, "mc route table for CHA %d-%d: %s\n", 1256 + cur_reg_start, i-1, mc_route_string); 1257 + cur_reg_start = i; 1258 + } 1259 + } 1260 + knl_show_mc_route(mc_route_reg[i-1], mc_route_string); 1261 + if (cur_reg_start == i-1) 1262 + edac_dbg(0, "mc route table for CHA %d: %s\n", 1263 + cur_reg_start, mc_route_string); 1264 + else 1265 + edac_dbg(0, "mc route table for CHA %d-%d: %s\n", 1266 + cur_reg_start, i-1, mc_route_string); 1267 + 1268 + /* Process DRAM rules */ 1269 + for (sad_rule = 0; sad_rule < pvt->info.max_sad; sad_rule++) { 1270 + /* previous limit becomes the new base */ 1271 + sad_base = sad_limit; 1272 + 1273 + pci_read_config_dword(pvt->pci_sad0, 1274 + pvt->info.dram_rule[sad_rule], &dram_rule); 1275 + 1276 + if (!DRAM_RULE_ENABLE(dram_rule)) 1277 + break; 1278 + 1279 + edram_only = KNL_EDRAM_ONLY(dram_rule); 1280 + 1281 + sad_limit = pvt->info.sad_limit(dram_rule)+1; 1282 + sad_size = sad_limit - sad_base; 1283 + 1284 + pci_read_config_dword(pvt->pci_sad0, 1285 + pvt->info.interleave_list[sad_rule], &interleave_reg); 1286 + 1287 + /* 1288 + * Find out how many ways this dram rule is interleaved. 1289 + * We stop when we see the first channel again. 1290 + */ 1291 + first_pkg = sad_pkg(pvt->info.interleave_pkg, 1292 + interleave_reg, 0); 1293 + for (intrlv_ways = 1; intrlv_ways < 8; intrlv_ways++) { 1294 + pkg = sad_pkg(pvt->info.interleave_pkg, 1295 + interleave_reg, intrlv_ways); 1296 + 1297 + if ((pkg & 0x8) == 0) { 1298 + /* 1299 + * 0 bit means memory is non-local, 1300 + * which KNL doesn't support 1301 + */ 1302 + edac_dbg(0, "Unexpected interleave target %d\n", 1303 + pkg); 1304 + return -1; 1305 + } 1306 + 1307 + if (pkg == first_pkg) 1308 + break; 1309 + } 1310 + if (KNL_MOD3(dram_rule)) 1311 + intrlv_ways *= 3; 1312 + 1313 + edac_dbg(3, "dram rule %d (base 0x%llx, limit 0x%llx), %d way interleave%s\n", 1314 + sad_rule, 1315 + sad_base, 1316 + sad_limit, 1317 + intrlv_ways, 1318 + edram_only ? ", EDRAM" : ""); 1319 + 1320 + /* 1321 + * Find out how big the SAD region really is by iterating 1322 + * over TAD tables (SAD regions may contain holes). 1323 + * Each memory controller might have a different TAD table, so 1324 + * we have to look at both. 1325 + * 1326 + * Livespace is the memory that's mapped in this TAD table, 1327 + * deadspace is the holes (this could be the MMIO hole, or it 1328 + * could be memory that's mapped by the other TAD table but 1329 + * not this one). 1330 + */ 1331 + for (mc = 0; mc < 2; mc++) { 1332 + sad_actual_size[mc] = 0; 1333 + tad_livespace = 0; 1334 + for (tad_rule = 0; 1335 + tad_rule < ARRAY_SIZE( 1336 + knl_tad_dram_limit_lo); 1337 + tad_rule++) { 1338 + if (knl_get_tad(pvt, 1339 + tad_rule, 1340 + mc, 1341 + &tad_deadspace, 1342 + &tad_limit, 1343 + &tad_ways)) 1344 + break; 1345 + 1346 + tad_size = (tad_limit+1) - 1347 + (tad_livespace + tad_deadspace); 1348 + tad_livespace += tad_size; 1349 + tad_base = (tad_limit+1) - tad_size; 1350 + 1351 + if (tad_base < sad_base) { 1352 + if (tad_limit > sad_base) 1353 + edac_dbg(0, "TAD region overlaps lower SAD boundary -- TAD tables may be configured incorrectly.\n"); 1354 + } else if (tad_base < sad_limit) { 1355 + if (tad_limit+1 > sad_limit) { 1356 + edac_dbg(0, "TAD region overlaps upper SAD boundary -- TAD tables may be configured incorrectly.\n"); 1357 + } else { 1358 + /* TAD region is completely inside SAD region */ 1359 + edac_dbg(3, "TAD region %d 0x%llx - 0x%llx (%lld bytes) table%d\n", 1360 + tad_rule, tad_base, 1361 + tad_limit, tad_size, 1362 + mc); 1363 + sad_actual_size[mc] += tad_size; 1364 + } 1365 + } 1366 + tad_base = tad_limit+1; 1367 + } 1368 + } 1369 + 1370 + for (mc = 0; mc < 2; mc++) { 1371 + edac_dbg(3, " total TAD DRAM footprint in table%d : 0x%llx (%lld bytes)\n", 1372 + mc, sad_actual_size[mc], sad_actual_size[mc]); 1373 + } 1374 + 1375 + /* Ignore EDRAM rule */ 1376 + if (edram_only) 1377 + continue; 1378 + 1379 + /* Figure out which channels participate in interleave. */ 1380 + for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) 1381 + participants[channel] = 0; 1382 + 1383 + /* For each channel, does at least one CHA have 1384 + * this channel mapped to the given target? 1385 + */ 1386 + for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) { 1387 + for (way = 0; way < intrlv_ways; way++) { 1388 + int target; 1389 + int cha; 1390 + 1391 + if (KNL_MOD3(dram_rule)) 1392 + target = way; 1393 + else 1394 + target = 0x7 & sad_pkg( 1395 + pvt->info.interleave_pkg, interleave_reg, way); 1396 + 1397 + for (cha = 0; cha < KNL_MAX_CHAS; cha++) { 1398 + if (knl_get_mc_route(target, 1399 + mc_route_reg[cha]) == channel 1400 + && participants[channel]) { 1401 + participant_count++; 1402 + participants[channel] = 1; 1403 + break; 1404 + } 1405 + } 1406 + } 1407 + } 1408 + 1409 + if (participant_count != intrlv_ways) 1410 + edac_dbg(0, "participant_count (%d) != interleave_ways (%d): DIMM size may be incorrect\n", 1411 + participant_count, intrlv_ways); 1412 + 1413 + for (channel = 0; channel < KNL_MAX_CHANNELS; channel++) { 1414 + mc = knl_channel_mc(channel); 1415 + if (participants[channel]) { 1416 + edac_dbg(4, "mc channel %d contributes %lld bytes via sad entry %d\n", 1417 + channel, 1418 + sad_actual_size[mc]/intrlv_ways, 1419 + sad_rule); 1420 + mc_sizes[channel] += 1421 + sad_actual_size[mc]/intrlv_ways; 1422 + } 1423 + } 1424 + } 1425 + 1126 1426 return 0; 1127 1427 } 1128 1428 ··· 1606 964 u32 reg; 1607 965 enum edac_type mode; 1608 966 enum mem_type mtype; 967 + int channels = pvt->info.type == KNIGHTS_LANDING ? 968 + KNL_MAX_CHANNELS : NUM_CHANNELS; 969 + u64 knl_mc_sizes[KNL_MAX_CHANNELS]; 1609 970 1610 - if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL) 971 + if (pvt->info.type == HASWELL || pvt->info.type == BROADWELL || 972 + pvt->info.type == KNIGHTS_LANDING) 1611 973 pci_read_config_dword(pvt->pci_sad1, SAD_TARGET, &reg); 1612 974 else 1613 975 pci_read_config_dword(pvt->pci_br0, SAD_TARGET, &reg); 1614 976 1615 - pvt->sbridge_dev->source_id = SOURCE_ID(reg); 977 + if (pvt->info.type == KNIGHTS_LANDING) 978 + pvt->sbridge_dev->source_id = SOURCE_ID_KNL(reg); 979 + else 980 + pvt->sbridge_dev->source_id = SOURCE_ID(reg); 1616 981 1617 982 pvt->sbridge_dev->node_id = pvt->info.get_node_id(pvt); 1618 983 edac_dbg(0, "mc#%d: Node ID: %d, source ID: %d\n", ··· 1627 978 pvt->sbridge_dev->node_id, 1628 979 pvt->sbridge_dev->source_id); 1629 980 1630 - pci_read_config_dword(pvt->pci_ras, RASENABLES, &reg); 1631 - if (IS_MIRROR_ENABLED(reg)) { 1632 - edac_dbg(0, "Memory mirror is enabled\n"); 1633 - pvt->is_mirrored = true; 1634 - } else { 1635 - edac_dbg(0, "Memory mirror is disabled\n"); 1636 - pvt->is_mirrored = false; 1637 - } 1638 - 1639 - pci_read_config_dword(pvt->pci_ta, MCMTR, &pvt->info.mcmtr); 1640 - if (IS_LOCKSTEP_ENABLED(pvt->info.mcmtr)) { 1641 - edac_dbg(0, "Lockstep is enabled\n"); 1642 - mode = EDAC_S8ECD8ED; 1643 - pvt->is_lockstep = true; 1644 - } else { 1645 - edac_dbg(0, "Lockstep is disabled\n"); 981 + /* KNL doesn't support mirroring or lockstep, 982 + * and is always closed page 983 + */ 984 + if (pvt->info.type == KNIGHTS_LANDING) { 1646 985 mode = EDAC_S4ECD4ED; 1647 - pvt->is_lockstep = false; 1648 - } 1649 - if (IS_CLOSE_PG(pvt->info.mcmtr)) { 1650 - edac_dbg(0, "address map is on closed page mode\n"); 1651 - pvt->is_close_pg = true; 986 + pvt->is_mirrored = false; 987 + 988 + if (knl_get_dimm_capacity(pvt, knl_mc_sizes) != 0) 989 + return -1; 1652 990 } else { 1653 - edac_dbg(0, "address map is on open page mode\n"); 1654 - pvt->is_close_pg = false; 991 + pci_read_config_dword(pvt->pci_ras, RASENABLES, &reg); 992 + if (IS_MIRROR_ENABLED(reg)) { 993 + edac_dbg(0, "Memory mirror is enabled\n"); 994 + pvt->is_mirrored = true; 995 + } else { 996 + edac_dbg(0, "Memory mirror is disabled\n"); 997 + pvt->is_mirrored = false; 998 + } 999 + 1000 + pci_read_config_dword(pvt->pci_ta, MCMTR, &pvt->info.mcmtr); 1001 + if (IS_LOCKSTEP_ENABLED(pvt->info.mcmtr)) { 1002 + edac_dbg(0, "Lockstep is enabled\n"); 1003 + mode = EDAC_S8ECD8ED; 1004 + pvt->is_lockstep = true; 1005 + } else { 1006 + edac_dbg(0, "Lockstep is disabled\n"); 1007 + mode = EDAC_S4ECD4ED; 1008 + pvt->is_lockstep = false; 1009 + } 1010 + if (IS_CLOSE_PG(pvt->info.mcmtr)) { 1011 + edac_dbg(0, "address map is on closed page mode\n"); 1012 + pvt->is_close_pg = true; 1013 + } else { 1014 + edac_dbg(0, "address map is on open page mode\n"); 1015 + pvt->is_close_pg = false; 1016 + } 1655 1017 } 1656 1018 1657 1019 mtype = pvt->info.get_memory_type(pvt); ··· 1678 1018 else 1679 1019 banks = 8; 1680 1020 1681 - for (i = 0; i < NUM_CHANNELS; i++) { 1021 + for (i = 0; i < channels; i++) { 1682 1022 u32 mtr; 1683 1023 1684 - if (!pvt->pci_tad[i]) 1685 - continue; 1686 - for (j = 0; j < ARRAY_SIZE(mtr_regs); j++) { 1024 + int max_dimms_per_channel; 1025 + 1026 + if (pvt->info.type == KNIGHTS_LANDING) { 1027 + max_dimms_per_channel = 1; 1028 + if (!pvt->knl.pci_channel[i]) 1029 + continue; 1030 + } else { 1031 + max_dimms_per_channel = ARRAY_SIZE(mtr_regs); 1032 + if (!pvt->pci_tad[i]) 1033 + continue; 1034 + } 1035 + 1036 + for (j = 0; j < max_dimms_per_channel; j++) { 1687 1037 dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, mci->n_layers, 1688 1038 i, j, 0); 1689 - pci_read_config_dword(pvt->pci_tad[i], 1690 - mtr_regs[j], &mtr); 1039 + if (pvt->info.type == KNIGHTS_LANDING) { 1040 + pci_read_config_dword(pvt->knl.pci_channel[i], 1041 + knl_mtr_reg, &mtr); 1042 + } else { 1043 + pci_read_config_dword(pvt->pci_tad[i], 1044 + mtr_regs[j], &mtr); 1045 + } 1691 1046 edac_dbg(4, "Channel #%d MTR%d = %x\n", i, j, mtr); 1692 1047 if (IS_DIMM_PRESENT(mtr)) { 1693 1048 pvt->channel[i].dimms++; 1694 1049 1695 1050 ranks = numrank(pvt->info.type, mtr); 1696 - rows = numrow(mtr); 1697 - cols = numcol(mtr); 1051 + 1052 + if (pvt->info.type == KNIGHTS_LANDING) { 1053 + /* For DDR4, this is fixed. */ 1054 + cols = 1 << 10; 1055 + rows = knl_mc_sizes[i] / 1056 + ((u64) cols * ranks * banks * 8); 1057 + } else { 1058 + rows = numrow(mtr); 1059 + cols = numcol(mtr); 1060 + } 1698 1061 1699 1062 size = ((u64)rows * cols * banks * ranks) >> (20 - 3); 1700 1063 npages = MiB_TO_PAGES(size); ··· 1813 1130 n_sads, j, pkg); 1814 1131 } 1815 1132 } 1133 + 1134 + if (pvt->info.type == KNIGHTS_LANDING) 1135 + return; 1816 1136 1817 1137 /* 1818 1138 * Step 3) Get TAD range ··· 2413 1727 2414 1728 #define sbridge_get_all_devices(num_mc, table) \ 2415 1729 sbridge_get_all_devices_full(num_mc, table, 0, 0) 1730 + #define sbridge_get_all_devices_knl(num_mc, table) \ 1731 + sbridge_get_all_devices_full(num_mc, table, 1, 1) 2416 1732 2417 1733 static int sbridge_mci_bind_devs(struct mem_ctl_info *mci, 2418 1734 struct sbridge_dev *sbridge_dev) ··· 2771 2083 return -ENODEV; 2772 2084 } 2773 2085 2086 + static int knl_mci_bind_devs(struct mem_ctl_info *mci, 2087 + struct sbridge_dev *sbridge_dev) 2088 + { 2089 + struct sbridge_pvt *pvt = mci->pvt_info; 2090 + struct pci_dev *pdev; 2091 + int dev, func; 2092 + 2093 + int i; 2094 + int devidx; 2095 + 2096 + for (i = 0; i < sbridge_dev->n_devs; i++) { 2097 + pdev = sbridge_dev->pdev[i]; 2098 + if (!pdev) 2099 + continue; 2100 + 2101 + /* Extract PCI device and function. */ 2102 + dev = (pdev->devfn >> 3) & 0x1f; 2103 + func = pdev->devfn & 0x7; 2104 + 2105 + switch (pdev->device) { 2106 + case PCI_DEVICE_ID_INTEL_KNL_IMC_MC: 2107 + if (dev == 8) 2108 + pvt->knl.pci_mc0 = pdev; 2109 + else if (dev == 9) 2110 + pvt->knl.pci_mc1 = pdev; 2111 + else { 2112 + sbridge_printk(KERN_ERR, 2113 + "Memory controller in unexpected place! (dev %d, fn %d)\n", 2114 + dev, func); 2115 + continue; 2116 + } 2117 + break; 2118 + 2119 + case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0: 2120 + pvt->pci_sad0 = pdev; 2121 + break; 2122 + 2123 + case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD1: 2124 + pvt->pci_sad1 = pdev; 2125 + break; 2126 + 2127 + case PCI_DEVICE_ID_INTEL_KNL_IMC_CHA: 2128 + /* There are one of these per tile, and range from 2129 + * 1.14.0 to 1.18.5. 2130 + */ 2131 + devidx = ((dev-14)*8)+func; 2132 + 2133 + if (devidx < 0 || devidx >= KNL_MAX_CHAS) { 2134 + sbridge_printk(KERN_ERR, 2135 + "Caching and Home Agent in unexpected place! (dev %d, fn %d)\n", 2136 + dev, func); 2137 + continue; 2138 + } 2139 + 2140 + WARN_ON(pvt->knl.pci_cha[devidx] != NULL); 2141 + 2142 + pvt->knl.pci_cha[devidx] = pdev; 2143 + break; 2144 + 2145 + case PCI_DEVICE_ID_INTEL_KNL_IMC_CHANNEL: 2146 + devidx = -1; 2147 + 2148 + /* 2149 + * MC0 channels 0-2 are device 9 function 2-4, 2150 + * MC1 channels 3-5 are device 8 function 2-4. 2151 + */ 2152 + 2153 + if (dev == 9) 2154 + devidx = func-2; 2155 + else if (dev == 8) 2156 + devidx = 3 + (func-2); 2157 + 2158 + if (devidx < 0 || devidx >= KNL_MAX_CHANNELS) { 2159 + sbridge_printk(KERN_ERR, 2160 + "DRAM Channel Registers in unexpected place! (dev %d, fn %d)\n", 2161 + dev, func); 2162 + continue; 2163 + } 2164 + 2165 + WARN_ON(pvt->knl.pci_channel[devidx] != NULL); 2166 + pvt->knl.pci_channel[devidx] = pdev; 2167 + break; 2168 + 2169 + case PCI_DEVICE_ID_INTEL_KNL_IMC_TOLHM: 2170 + pvt->knl.pci_mc_info = pdev; 2171 + break; 2172 + 2173 + case PCI_DEVICE_ID_INTEL_KNL_IMC_TA: 2174 + pvt->pci_ta = pdev; 2175 + break; 2176 + 2177 + default: 2178 + sbridge_printk(KERN_ERR, "Unexpected device %d\n", 2179 + pdev->device); 2180 + break; 2181 + } 2182 + } 2183 + 2184 + if (!pvt->knl.pci_mc0 || !pvt->knl.pci_mc1 || 2185 + !pvt->pci_sad0 || !pvt->pci_sad1 || 2186 + !pvt->pci_ta) { 2187 + goto enodev; 2188 + } 2189 + 2190 + for (i = 0; i < KNL_MAX_CHANNELS; i++) { 2191 + if (!pvt->knl.pci_channel[i]) { 2192 + sbridge_printk(KERN_ERR, "Missing channel %d\n", i); 2193 + goto enodev; 2194 + } 2195 + } 2196 + 2197 + for (i = 0; i < KNL_MAX_CHAS; i++) { 2198 + if (!pvt->knl.pci_cha[i]) { 2199 + sbridge_printk(KERN_ERR, "Missing CHA %d\n", i); 2200 + goto enodev; 2201 + } 2202 + } 2203 + 2204 + return 0; 2205 + 2206 + enodev: 2207 + sbridge_printk(KERN_ERR, "Some needed devices are missing\n"); 2208 + return -ENODEV; 2209 + } 2210 + 2774 2211 /**************************************************************************** 2775 2212 Error check routines 2776 2213 ****************************************************************************/ ··· 2985 2172 if (!GET_BITFIELD(m->status, 58, 58)) 2986 2173 return; 2987 2174 2988 - rc = get_memory_error_data(mci, m->addr, &socket, &ha, 2989 - &channel_mask, &rank, &area_type, msg); 2175 + if (pvt->info.type == KNIGHTS_LANDING) { 2176 + if (channel == 14) { 2177 + edac_dbg(0, "%s%s err_code:%04x:%04x EDRAM bank %d\n", 2178 + overflow ? " OVERFLOW" : "", 2179 + (uncorrected_error && recoverable) 2180 + ? " recoverable" : "", 2181 + mscod, errcode, 2182 + m->bank); 2183 + } else { 2184 + char A = *("A"); 2185 + 2186 + channel = knl_channel_remap(channel); 2187 + channel_mask = 1 << channel; 2188 + snprintf(msg, sizeof(msg), 2189 + "%s%s err_code:%04x:%04x channel:%d (DIMM_%c)", 2190 + overflow ? " OVERFLOW" : "", 2191 + (uncorrected_error && recoverable) 2192 + ? " recoverable" : " ", 2193 + mscod, errcode, channel, A + channel); 2194 + edac_mc_handle_error(tp_event, mci, core_err_cnt, 2195 + m->addr >> PAGE_SHIFT, m->addr & ~PAGE_MASK, 0, 2196 + channel, 0, -1, 2197 + optype, msg); 2198 + } 2199 + return; 2200 + } else { 2201 + rc = get_memory_error_data(mci, m->addr, &socket, &ha, 2202 + &channel_mask, &rank, &area_type, msg); 2203 + } 2204 + 2990 2205 if (rc < 0) 2991 2206 goto err_parsing; 2992 2207 new_mci = get_mci_for_node_id(socket); ··· 3245 2404 3246 2405 /* allocate a new MC control structure */ 3247 2406 layers[0].type = EDAC_MC_LAYER_CHANNEL; 3248 - layers[0].size = NUM_CHANNELS; 2407 + layers[0].size = type == KNIGHTS_LANDING ? 2408 + KNL_MAX_CHANNELS : NUM_CHANNELS; 3249 2409 layers[0].is_virt_csrow = false; 3250 2410 layers[1].type = EDAC_MC_LAYER_SLOT; 3251 - layers[1].size = MAX_DIMMS; 2411 + layers[1].size = type == KNIGHTS_LANDING ? 1 : MAX_DIMMS; 3252 2412 layers[1].is_virt_csrow = true; 3253 2413 mci = edac_mc_alloc(sbridge_dev->mc, ARRAY_SIZE(layers), layers, 3254 2414 sizeof(*pvt)); ··· 3267 2425 pvt->sbridge_dev = sbridge_dev; 3268 2426 sbridge_dev->mci = mci; 3269 2427 3270 - mci->mtype_cap = MEM_FLAG_DDR3; 2428 + mci->mtype_cap = type == KNIGHTS_LANDING ? 2429 + MEM_FLAG_DDR4 : MEM_FLAG_DDR3; 3271 2430 mci->edac_ctl_cap = EDAC_FLAG_NONE; 3272 2431 mci->edac_cap = EDAC_FLAG_NONE; 3273 2432 mci->mod_name = "sbridge_edac.c"; ··· 3377 2534 if (unlikely(rc < 0)) 3378 2535 goto fail0; 3379 2536 break; 2537 + case KNIGHTS_LANDING: 2538 + /* pvt->info.rankcfgr == ??? */ 2539 + pvt->info.get_tolm = knl_get_tolm; 2540 + pvt->info.get_tohm = knl_get_tohm; 2541 + pvt->info.dram_rule = knl_dram_rule; 2542 + pvt->info.get_memory_type = knl_get_memory_type; 2543 + pvt->info.get_node_id = knl_get_node_id; 2544 + pvt->info.rir_limit = NULL; 2545 + pvt->info.sad_limit = knl_sad_limit; 2546 + pvt->info.interleave_mode = knl_interleave_mode; 2547 + pvt->info.show_interleave_mode = knl_show_interleave_mode; 2548 + pvt->info.dram_attr = dram_attr_knl; 2549 + pvt->info.max_sad = ARRAY_SIZE(knl_dram_rule); 2550 + pvt->info.interleave_list = knl_interleave_list; 2551 + pvt->info.max_interleave = ARRAY_SIZE(knl_interleave_list); 2552 + pvt->info.interleave_pkg = ibridge_interleave_pkg; 2553 + pvt->info.get_width = ibridge_get_width; 2554 + mci->ctl_name = kasprintf(GFP_KERNEL, 2555 + "Knights Landing Socket#%d", mci->mc_idx); 2556 + 2557 + rc = knl_mci_bind_devs(mci, sbridge_dev); 2558 + if (unlikely(rc < 0)) 2559 + goto fail0; 2560 + break; 3380 2561 } 3381 2562 3382 2563 /* Get dimm basic config and the memory layout */ ··· 3455 2588 3456 2589 switch (pdev->device) { 3457 2590 case PCI_DEVICE_ID_INTEL_IBRIDGE_IMC_HA0_TA: 3458 - rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_ibridge_table); 2591 + rc = sbridge_get_all_devices(&num_mc, 2592 + pci_dev_descr_ibridge_table); 3459 2593 type = IVY_BRIDGE; 3460 2594 break; 3461 2595 case PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0: 3462 - rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_sbridge_table); 2596 + rc = sbridge_get_all_devices(&num_mc, 2597 + pci_dev_descr_sbridge_table); 3463 2598 type = SANDY_BRIDGE; 3464 2599 break; 3465 2600 case PCI_DEVICE_ID_INTEL_HASWELL_IMC_HA0: 3466 - rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_haswell_table); 2601 + rc = sbridge_get_all_devices(&num_mc, 2602 + pci_dev_descr_haswell_table); 3467 2603 type = HASWELL; 3468 2604 break; 3469 2605 case PCI_DEVICE_ID_INTEL_BROADWELL_IMC_HA0: 3470 - rc = sbridge_get_all_devices(&num_mc, pci_dev_descr_broadwell_table); 2606 + rc = sbridge_get_all_devices(&num_mc, 2607 + pci_dev_descr_broadwell_table); 3471 2608 type = BROADWELL; 2609 + break; 2610 + case PCI_DEVICE_ID_INTEL_KNL_IMC_SAD0: 2611 + rc = sbridge_get_all_devices_knl(&num_mc, 2612 + pci_dev_descr_knl_table); 2613 + type = KNIGHTS_LANDING; 3472 2614 break; 3473 2615 } 3474 2616 if (unlikely(rc < 0)) {