18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Intel 5400 class Memory Controllers kernel module (Seaburg) 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This file may be distributed under the terms of the 58c2ecf20Sopenharmony_ci * GNU General Public License. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2008 by: 88c2ecf20Sopenharmony_ci * Ben Woodard <woodard@redhat.com> 98c2ecf20Sopenharmony_ci * Mauro Carvalho Chehab 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Red Hat Inc. https://www.redhat.com 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * Forked and adapted from the i5000_edac driver which was 148c2ecf20Sopenharmony_ci * written by Douglas Thompson Linux Networx <norsk5@xmission.com> 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * This module is based on the following document: 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * Intel 5400 Chipset Memory Controller Hub (MCH) - Datasheet 198c2ecf20Sopenharmony_ci * http://developer.intel.com/design/chipsets/datashts/313070.htm 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * This Memory Controller manages DDR2 FB-DIMMs. It has 2 branches, each with 228c2ecf20Sopenharmony_ci * 2 channels operating in lockstep no-mirror mode. Each channel can have up to 238c2ecf20Sopenharmony_ci * 4 dimm's, each with up to 8GB. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include <linux/module.h> 288c2ecf20Sopenharmony_ci#include <linux/init.h> 298c2ecf20Sopenharmony_ci#include <linux/pci.h> 308c2ecf20Sopenharmony_ci#include <linux/pci_ids.h> 318c2ecf20Sopenharmony_ci#include <linux/slab.h> 328c2ecf20Sopenharmony_ci#include <linux/edac.h> 338c2ecf20Sopenharmony_ci#include <linux/mmzone.h> 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include "edac_module.h" 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* 388c2ecf20Sopenharmony_ci * Alter this version for the I5400 module when modifications are made 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci#define I5400_REVISION " Ver: 1.0.0" 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define EDAC_MOD_STR "i5400_edac" 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define i5400_printk(level, fmt, arg...) \ 458c2ecf20Sopenharmony_ci edac_printk(level, "i5400", fmt, ##arg) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define i5400_mc_printk(mci, level, fmt, arg...) \ 488c2ecf20Sopenharmony_ci edac_mc_chipset_printk(mci, level, "i5400", fmt, ##arg) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* Limits for i5400 */ 518c2ecf20Sopenharmony_ci#define MAX_BRANCHES 2 528c2ecf20Sopenharmony_ci#define CHANNELS_PER_BRANCH 2 538c2ecf20Sopenharmony_ci#define DIMMS_PER_CHANNEL 4 548c2ecf20Sopenharmony_ci#define MAX_CHANNELS (MAX_BRANCHES * CHANNELS_PER_BRANCH) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* Device 16, 578c2ecf20Sopenharmony_ci * Function 0: System Address 588c2ecf20Sopenharmony_ci * Function 1: Memory Branch Map, Control, Errors Register 598c2ecf20Sopenharmony_ci * Function 2: FSB Error Registers 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci * All 3 functions of Device 16 (0,1,2) share the SAME DID and 628c2ecf20Sopenharmony_ci * uses PCI_DEVICE_ID_INTEL_5400_ERR for device 16 (0,1,2), 638c2ecf20Sopenharmony_ci * PCI_DEVICE_ID_INTEL_5400_FBD0 and PCI_DEVICE_ID_INTEL_5400_FBD1 648c2ecf20Sopenharmony_ci * for device 21 (0,1). 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci /* OFFSETS for Function 0 */ 688c2ecf20Sopenharmony_ci#define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */ 698c2ecf20Sopenharmony_ci#define MAXCH 0x56 /* Max Channel Number */ 708c2ecf20Sopenharmony_ci#define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */ 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci /* OFFSETS for Function 1 */ 738c2ecf20Sopenharmony_ci#define TOLM 0x6C 748c2ecf20Sopenharmony_ci#define REDMEMB 0x7C 758c2ecf20Sopenharmony_ci#define REC_ECC_LOCATOR_ODD(x) ((x) & 0x3fe00) /* bits [17:9] indicate ODD, [8:0] indicate EVEN */ 768c2ecf20Sopenharmony_ci#define MIR0 0x80 778c2ecf20Sopenharmony_ci#define MIR1 0x84 788c2ecf20Sopenharmony_ci#define AMIR0 0x8c 798c2ecf20Sopenharmony_ci#define AMIR1 0x90 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci /* Fatal error registers */ 828c2ecf20Sopenharmony_ci#define FERR_FAT_FBD 0x98 /* also called as FERR_FAT_FB_DIMM at datasheet */ 838c2ecf20Sopenharmony_ci#define FERR_FAT_FBDCHAN (3<<28) /* channel index where the highest-order error occurred */ 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define NERR_FAT_FBD 0x9c 868c2ecf20Sopenharmony_ci#define FERR_NF_FBD 0xa0 /* also called as FERR_NFAT_FB_DIMM at datasheet */ 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci /* Non-fatal error register */ 898c2ecf20Sopenharmony_ci#define NERR_NF_FBD 0xa4 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci /* Enable error mask */ 928c2ecf20Sopenharmony_ci#define EMASK_FBD 0xa8 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#define ERR0_FBD 0xac 958c2ecf20Sopenharmony_ci#define ERR1_FBD 0xb0 968c2ecf20Sopenharmony_ci#define ERR2_FBD 0xb4 978c2ecf20Sopenharmony_ci#define MCERR_FBD 0xb8 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci /* No OFFSETS for Device 16 Function 2 */ 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* 1028c2ecf20Sopenharmony_ci * Device 21, 1038c2ecf20Sopenharmony_ci * Function 0: Memory Map Branch 0 1048c2ecf20Sopenharmony_ci * 1058c2ecf20Sopenharmony_ci * Device 22, 1068c2ecf20Sopenharmony_ci * Function 0: Memory Map Branch 1 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci /* OFFSETS for Function 0 */ 1108c2ecf20Sopenharmony_ci#define AMBPRESENT_0 0x64 1118c2ecf20Sopenharmony_ci#define AMBPRESENT_1 0x66 1128c2ecf20Sopenharmony_ci#define MTR0 0x80 1138c2ecf20Sopenharmony_ci#define MTR1 0x82 1148c2ecf20Sopenharmony_ci#define MTR2 0x84 1158c2ecf20Sopenharmony_ci#define MTR3 0x86 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci /* OFFSETS for Function 1 */ 1188c2ecf20Sopenharmony_ci#define NRECFGLOG 0x74 1198c2ecf20Sopenharmony_ci#define RECFGLOG 0x78 1208c2ecf20Sopenharmony_ci#define NRECMEMA 0xbe 1218c2ecf20Sopenharmony_ci#define NRECMEMB 0xc0 1228c2ecf20Sopenharmony_ci#define NRECFB_DIMMA 0xc4 1238c2ecf20Sopenharmony_ci#define NRECFB_DIMMB 0xc8 1248c2ecf20Sopenharmony_ci#define NRECFB_DIMMC 0xcc 1258c2ecf20Sopenharmony_ci#define NRECFB_DIMMD 0xd0 1268c2ecf20Sopenharmony_ci#define NRECFB_DIMME 0xd4 1278c2ecf20Sopenharmony_ci#define NRECFB_DIMMF 0xd8 1288c2ecf20Sopenharmony_ci#define REDMEMA 0xdC 1298c2ecf20Sopenharmony_ci#define RECMEMA 0xf0 1308c2ecf20Sopenharmony_ci#define RECMEMB 0xf4 1318c2ecf20Sopenharmony_ci#define RECFB_DIMMA 0xf8 1328c2ecf20Sopenharmony_ci#define RECFB_DIMMB 0xec 1338c2ecf20Sopenharmony_ci#define RECFB_DIMMC 0xf0 1348c2ecf20Sopenharmony_ci#define RECFB_DIMMD 0xf4 1358c2ecf20Sopenharmony_ci#define RECFB_DIMME 0xf8 1368c2ecf20Sopenharmony_ci#define RECFB_DIMMF 0xfC 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/* 1398c2ecf20Sopenharmony_ci * Error indicator bits and masks 1408c2ecf20Sopenharmony_ci * Error masks are according with Table 5-17 of i5400 datasheet 1418c2ecf20Sopenharmony_ci */ 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cienum error_mask { 1448c2ecf20Sopenharmony_ci EMASK_M1 = 1<<0, /* Memory Write error on non-redundant retry */ 1458c2ecf20Sopenharmony_ci EMASK_M2 = 1<<1, /* Memory or FB-DIMM configuration CRC read error */ 1468c2ecf20Sopenharmony_ci EMASK_M3 = 1<<2, /* Reserved */ 1478c2ecf20Sopenharmony_ci EMASK_M4 = 1<<3, /* Uncorrectable Data ECC on Replay */ 1488c2ecf20Sopenharmony_ci EMASK_M5 = 1<<4, /* Aliased Uncorrectable Non-Mirrored Demand Data ECC */ 1498c2ecf20Sopenharmony_ci EMASK_M6 = 1<<5, /* Unsupported on i5400 */ 1508c2ecf20Sopenharmony_ci EMASK_M7 = 1<<6, /* Aliased Uncorrectable Resilver- or Spare-Copy Data ECC */ 1518c2ecf20Sopenharmony_ci EMASK_M8 = 1<<7, /* Aliased Uncorrectable Patrol Data ECC */ 1528c2ecf20Sopenharmony_ci EMASK_M9 = 1<<8, /* Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC */ 1538c2ecf20Sopenharmony_ci EMASK_M10 = 1<<9, /* Unsupported on i5400 */ 1548c2ecf20Sopenharmony_ci EMASK_M11 = 1<<10, /* Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC */ 1558c2ecf20Sopenharmony_ci EMASK_M12 = 1<<11, /* Non-Aliased Uncorrectable Patrol Data ECC */ 1568c2ecf20Sopenharmony_ci EMASK_M13 = 1<<12, /* Memory Write error on first attempt */ 1578c2ecf20Sopenharmony_ci EMASK_M14 = 1<<13, /* FB-DIMM Configuration Write error on first attempt */ 1588c2ecf20Sopenharmony_ci EMASK_M15 = 1<<14, /* Memory or FB-DIMM configuration CRC read error */ 1598c2ecf20Sopenharmony_ci EMASK_M16 = 1<<15, /* Channel Failed-Over Occurred */ 1608c2ecf20Sopenharmony_ci EMASK_M17 = 1<<16, /* Correctable Non-Mirrored Demand Data ECC */ 1618c2ecf20Sopenharmony_ci EMASK_M18 = 1<<17, /* Unsupported on i5400 */ 1628c2ecf20Sopenharmony_ci EMASK_M19 = 1<<18, /* Correctable Resilver- or Spare-Copy Data ECC */ 1638c2ecf20Sopenharmony_ci EMASK_M20 = 1<<19, /* Correctable Patrol Data ECC */ 1648c2ecf20Sopenharmony_ci EMASK_M21 = 1<<20, /* FB-DIMM Northbound parity error on FB-DIMM Sync Status */ 1658c2ecf20Sopenharmony_ci EMASK_M22 = 1<<21, /* SPD protocol Error */ 1668c2ecf20Sopenharmony_ci EMASK_M23 = 1<<22, /* Non-Redundant Fast Reset Timeout */ 1678c2ecf20Sopenharmony_ci EMASK_M24 = 1<<23, /* Refresh error */ 1688c2ecf20Sopenharmony_ci EMASK_M25 = 1<<24, /* Memory Write error on redundant retry */ 1698c2ecf20Sopenharmony_ci EMASK_M26 = 1<<25, /* Redundant Fast Reset Timeout */ 1708c2ecf20Sopenharmony_ci EMASK_M27 = 1<<26, /* Correctable Counter Threshold Exceeded */ 1718c2ecf20Sopenharmony_ci EMASK_M28 = 1<<27, /* DIMM-Spare Copy Completed */ 1728c2ecf20Sopenharmony_ci EMASK_M29 = 1<<28, /* DIMM-Isolation Completed */ 1738c2ecf20Sopenharmony_ci}; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci/* 1768c2ecf20Sopenharmony_ci * Names to translate bit error into something useful 1778c2ecf20Sopenharmony_ci */ 1788c2ecf20Sopenharmony_cistatic const char *error_name[] = { 1798c2ecf20Sopenharmony_ci [0] = "Memory Write error on non-redundant retry", 1808c2ecf20Sopenharmony_ci [1] = "Memory or FB-DIMM configuration CRC read error", 1818c2ecf20Sopenharmony_ci /* Reserved */ 1828c2ecf20Sopenharmony_ci [3] = "Uncorrectable Data ECC on Replay", 1838c2ecf20Sopenharmony_ci [4] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC", 1848c2ecf20Sopenharmony_ci /* M6 Unsupported on i5400 */ 1858c2ecf20Sopenharmony_ci [6] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC", 1868c2ecf20Sopenharmony_ci [7] = "Aliased Uncorrectable Patrol Data ECC", 1878c2ecf20Sopenharmony_ci [8] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC", 1888c2ecf20Sopenharmony_ci /* M10 Unsupported on i5400 */ 1898c2ecf20Sopenharmony_ci [10] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC", 1908c2ecf20Sopenharmony_ci [11] = "Non-Aliased Uncorrectable Patrol Data ECC", 1918c2ecf20Sopenharmony_ci [12] = "Memory Write error on first attempt", 1928c2ecf20Sopenharmony_ci [13] = "FB-DIMM Configuration Write error on first attempt", 1938c2ecf20Sopenharmony_ci [14] = "Memory or FB-DIMM configuration CRC read error", 1948c2ecf20Sopenharmony_ci [15] = "Channel Failed-Over Occurred", 1958c2ecf20Sopenharmony_ci [16] = "Correctable Non-Mirrored Demand Data ECC", 1968c2ecf20Sopenharmony_ci /* M18 Unsupported on i5400 */ 1978c2ecf20Sopenharmony_ci [18] = "Correctable Resilver- or Spare-Copy Data ECC", 1988c2ecf20Sopenharmony_ci [19] = "Correctable Patrol Data ECC", 1998c2ecf20Sopenharmony_ci [20] = "FB-DIMM Northbound parity error on FB-DIMM Sync Status", 2008c2ecf20Sopenharmony_ci [21] = "SPD protocol Error", 2018c2ecf20Sopenharmony_ci [22] = "Non-Redundant Fast Reset Timeout", 2028c2ecf20Sopenharmony_ci [23] = "Refresh error", 2038c2ecf20Sopenharmony_ci [24] = "Memory Write error on redundant retry", 2048c2ecf20Sopenharmony_ci [25] = "Redundant Fast Reset Timeout", 2058c2ecf20Sopenharmony_ci [26] = "Correctable Counter Threshold Exceeded", 2068c2ecf20Sopenharmony_ci [27] = "DIMM-Spare Copy Completed", 2078c2ecf20Sopenharmony_ci [28] = "DIMM-Isolation Completed", 2088c2ecf20Sopenharmony_ci}; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* Fatal errors */ 2118c2ecf20Sopenharmony_ci#define ERROR_FAT_MASK (EMASK_M1 | \ 2128c2ecf20Sopenharmony_ci EMASK_M2 | \ 2138c2ecf20Sopenharmony_ci EMASK_M23) 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci/* Correctable errors */ 2168c2ecf20Sopenharmony_ci#define ERROR_NF_CORRECTABLE (EMASK_M27 | \ 2178c2ecf20Sopenharmony_ci EMASK_M20 | \ 2188c2ecf20Sopenharmony_ci EMASK_M19 | \ 2198c2ecf20Sopenharmony_ci EMASK_M18 | \ 2208c2ecf20Sopenharmony_ci EMASK_M17 | \ 2218c2ecf20Sopenharmony_ci EMASK_M16) 2228c2ecf20Sopenharmony_ci#define ERROR_NF_DIMM_SPARE (EMASK_M29 | \ 2238c2ecf20Sopenharmony_ci EMASK_M28) 2248c2ecf20Sopenharmony_ci#define ERROR_NF_SPD_PROTOCOL (EMASK_M22) 2258c2ecf20Sopenharmony_ci#define ERROR_NF_NORTH_CRC (EMASK_M21) 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci/* Recoverable errors */ 2288c2ecf20Sopenharmony_ci#define ERROR_NF_RECOVERABLE (EMASK_M26 | \ 2298c2ecf20Sopenharmony_ci EMASK_M25 | \ 2308c2ecf20Sopenharmony_ci EMASK_M24 | \ 2318c2ecf20Sopenharmony_ci EMASK_M15 | \ 2328c2ecf20Sopenharmony_ci EMASK_M14 | \ 2338c2ecf20Sopenharmony_ci EMASK_M13 | \ 2348c2ecf20Sopenharmony_ci EMASK_M12 | \ 2358c2ecf20Sopenharmony_ci EMASK_M11 | \ 2368c2ecf20Sopenharmony_ci EMASK_M9 | \ 2378c2ecf20Sopenharmony_ci EMASK_M8 | \ 2388c2ecf20Sopenharmony_ci EMASK_M7 | \ 2398c2ecf20Sopenharmony_ci EMASK_M5) 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci/* uncorrectable errors */ 2428c2ecf20Sopenharmony_ci#define ERROR_NF_UNCORRECTABLE (EMASK_M4) 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/* mask to all non-fatal errors */ 2458c2ecf20Sopenharmony_ci#define ERROR_NF_MASK (ERROR_NF_CORRECTABLE | \ 2468c2ecf20Sopenharmony_ci ERROR_NF_UNCORRECTABLE | \ 2478c2ecf20Sopenharmony_ci ERROR_NF_RECOVERABLE | \ 2488c2ecf20Sopenharmony_ci ERROR_NF_DIMM_SPARE | \ 2498c2ecf20Sopenharmony_ci ERROR_NF_SPD_PROTOCOL | \ 2508c2ecf20Sopenharmony_ci ERROR_NF_NORTH_CRC) 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci/* 2538c2ecf20Sopenharmony_ci * Define error masks for the several registers 2548c2ecf20Sopenharmony_ci */ 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci/* Enable all fatal and non fatal errors */ 2578c2ecf20Sopenharmony_ci#define ENABLE_EMASK_ALL (ERROR_FAT_MASK | ERROR_NF_MASK) 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* mask for fatal error registers */ 2608c2ecf20Sopenharmony_ci#define FERR_FAT_MASK ERROR_FAT_MASK 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci/* masks for non-fatal error register */ 2638c2ecf20Sopenharmony_cistatic inline int to_nf_mask(unsigned int mask) 2648c2ecf20Sopenharmony_ci{ 2658c2ecf20Sopenharmony_ci return (mask & EMASK_M29) | (mask >> 3); 2668c2ecf20Sopenharmony_ci}; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_cistatic inline int from_nf_ferr(unsigned int mask) 2698c2ecf20Sopenharmony_ci{ 2708c2ecf20Sopenharmony_ci return (mask & EMASK_M29) | /* Bit 28 */ 2718c2ecf20Sopenharmony_ci (mask & ((1 << 28) - 1) << 3); /* Bits 0 to 27 */ 2728c2ecf20Sopenharmony_ci}; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci#define FERR_NF_MASK to_nf_mask(ERROR_NF_MASK) 2758c2ecf20Sopenharmony_ci#define FERR_NF_CORRECTABLE to_nf_mask(ERROR_NF_CORRECTABLE) 2768c2ecf20Sopenharmony_ci#define FERR_NF_DIMM_SPARE to_nf_mask(ERROR_NF_DIMM_SPARE) 2778c2ecf20Sopenharmony_ci#define FERR_NF_SPD_PROTOCOL to_nf_mask(ERROR_NF_SPD_PROTOCOL) 2788c2ecf20Sopenharmony_ci#define FERR_NF_NORTH_CRC to_nf_mask(ERROR_NF_NORTH_CRC) 2798c2ecf20Sopenharmony_ci#define FERR_NF_RECOVERABLE to_nf_mask(ERROR_NF_RECOVERABLE) 2808c2ecf20Sopenharmony_ci#define FERR_NF_UNCORRECTABLE to_nf_mask(ERROR_NF_UNCORRECTABLE) 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci/* Defines to extract the vaious fields from the 2838c2ecf20Sopenharmony_ci * MTRx - Memory Technology Registers 2848c2ecf20Sopenharmony_ci */ 2858c2ecf20Sopenharmony_ci#define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 10)) 2868c2ecf20Sopenharmony_ci#define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 9)) 2878c2ecf20Sopenharmony_ci#define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 8)) ? 8 : 4) 2888c2ecf20Sopenharmony_ci#define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 6)) ? 8 : 4) 2898c2ecf20Sopenharmony_ci#define MTR_DRAM_BANKS_ADDR_BITS(mtr) ((MTR_DRAM_BANKS(mtr) == 8) ? 3 : 2) 2908c2ecf20Sopenharmony_ci#define MTR_DIMM_RANK(mtr) (((mtr) >> 5) & 0x1) 2918c2ecf20Sopenharmony_ci#define MTR_DIMM_RANK_ADDR_BITS(mtr) (MTR_DIMM_RANK(mtr) ? 2 : 1) 2928c2ecf20Sopenharmony_ci#define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3) 2938c2ecf20Sopenharmony_ci#define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13) 2948c2ecf20Sopenharmony_ci#define MTR_DIMM_COLS(mtr) ((mtr) & 0x3) 2958c2ecf20Sopenharmony_ci#define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10) 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci/* This applies to FERR_NF_FB-DIMM as well as FERR_FAT_FB-DIMM */ 2988c2ecf20Sopenharmony_cistatic inline int extract_fbdchan_indx(u32 x) 2998c2ecf20Sopenharmony_ci{ 3008c2ecf20Sopenharmony_ci return (x>>28) & 0x3; 3018c2ecf20Sopenharmony_ci} 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci/* Device name and register DID (Device ID) */ 3048c2ecf20Sopenharmony_cistruct i5400_dev_info { 3058c2ecf20Sopenharmony_ci const char *ctl_name; /* name for this device */ 3068c2ecf20Sopenharmony_ci u16 fsb_mapping_errors; /* DID for the branchmap,control */ 3078c2ecf20Sopenharmony_ci}; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci/* Table of devices attributes supported by this driver */ 3108c2ecf20Sopenharmony_cistatic const struct i5400_dev_info i5400_devs[] = { 3118c2ecf20Sopenharmony_ci { 3128c2ecf20Sopenharmony_ci .ctl_name = "I5400", 3138c2ecf20Sopenharmony_ci .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_5400_ERR, 3148c2ecf20Sopenharmony_ci }, 3158c2ecf20Sopenharmony_ci}; 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_cistruct i5400_dimm_info { 3188c2ecf20Sopenharmony_ci int megabytes; /* size, 0 means not present */ 3198c2ecf20Sopenharmony_ci}; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/* driver private data structure */ 3228c2ecf20Sopenharmony_cistruct i5400_pvt { 3238c2ecf20Sopenharmony_ci struct pci_dev *system_address; /* 16.0 */ 3248c2ecf20Sopenharmony_ci struct pci_dev *branchmap_werrors; /* 16.1 */ 3258c2ecf20Sopenharmony_ci struct pci_dev *fsb_error_regs; /* 16.2 */ 3268c2ecf20Sopenharmony_ci struct pci_dev *branch_0; /* 21.0 */ 3278c2ecf20Sopenharmony_ci struct pci_dev *branch_1; /* 22.0 */ 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci u16 tolm; /* top of low memory */ 3308c2ecf20Sopenharmony_ci union { 3318c2ecf20Sopenharmony_ci u64 ambase; /* AMB BAR */ 3328c2ecf20Sopenharmony_ci struct { 3338c2ecf20Sopenharmony_ci u32 ambase_bottom; 3348c2ecf20Sopenharmony_ci u32 ambase_top; 3358c2ecf20Sopenharmony_ci } u __packed; 3368c2ecf20Sopenharmony_ci }; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci u16 mir0, mir1; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci u16 b0_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */ 3418c2ecf20Sopenharmony_ci u16 b0_ambpresent0; /* Branch 0, Channel 0 */ 3428c2ecf20Sopenharmony_ci u16 b0_ambpresent1; /* Brnach 0, Channel 1 */ 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci u16 b1_mtr[DIMMS_PER_CHANNEL]; /* Memory Technlogy Reg */ 3458c2ecf20Sopenharmony_ci u16 b1_ambpresent0; /* Branch 1, Channel 8 */ 3468c2ecf20Sopenharmony_ci u16 b1_ambpresent1; /* Branch 1, Channel 1 */ 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci /* DIMM information matrix, allocating architecture maximums */ 3498c2ecf20Sopenharmony_ci struct i5400_dimm_info dimm_info[DIMMS_PER_CHANNEL][MAX_CHANNELS]; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci /* Actual values for this controller */ 3528c2ecf20Sopenharmony_ci int maxch; /* Max channels */ 3538c2ecf20Sopenharmony_ci int maxdimmperch; /* Max DIMMs per channel */ 3548c2ecf20Sopenharmony_ci}; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci/* I5400 MCH error information retrieved from Hardware */ 3578c2ecf20Sopenharmony_cistruct i5400_error_info { 3588c2ecf20Sopenharmony_ci /* These registers are always read from the MC */ 3598c2ecf20Sopenharmony_ci u32 ferr_fat_fbd; /* First Errors Fatal */ 3608c2ecf20Sopenharmony_ci u32 nerr_fat_fbd; /* Next Errors Fatal */ 3618c2ecf20Sopenharmony_ci u32 ferr_nf_fbd; /* First Errors Non-Fatal */ 3628c2ecf20Sopenharmony_ci u32 nerr_nf_fbd; /* Next Errors Non-Fatal */ 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci /* These registers are input ONLY if there was a Recoverable Error */ 3658c2ecf20Sopenharmony_ci u32 redmemb; /* Recoverable Mem Data Error log B */ 3668c2ecf20Sopenharmony_ci u16 recmema; /* Recoverable Mem Error log A */ 3678c2ecf20Sopenharmony_ci u32 recmemb; /* Recoverable Mem Error log B */ 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci /* These registers are input ONLY if there was a Non-Rec Error */ 3708c2ecf20Sopenharmony_ci u16 nrecmema; /* Non-Recoverable Mem log A */ 3718c2ecf20Sopenharmony_ci u32 nrecmemb; /* Non-Recoverable Mem log B */ 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci}; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci/* note that nrec_rdwr changed from NRECMEMA to NRECMEMB between the 5000 and 3768c2ecf20Sopenharmony_ci 5400 better to use an inline function than a macro in this case */ 3778c2ecf20Sopenharmony_cistatic inline int nrec_bank(struct i5400_error_info *info) 3788c2ecf20Sopenharmony_ci{ 3798c2ecf20Sopenharmony_ci return ((info->nrecmema) >> 12) & 0x7; 3808c2ecf20Sopenharmony_ci} 3818c2ecf20Sopenharmony_cistatic inline int nrec_rank(struct i5400_error_info *info) 3828c2ecf20Sopenharmony_ci{ 3838c2ecf20Sopenharmony_ci return ((info->nrecmema) >> 8) & 0xf; 3848c2ecf20Sopenharmony_ci} 3858c2ecf20Sopenharmony_cistatic inline int nrec_buf_id(struct i5400_error_info *info) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci return ((info->nrecmema)) & 0xff; 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_cistatic inline int nrec_rdwr(struct i5400_error_info *info) 3908c2ecf20Sopenharmony_ci{ 3918c2ecf20Sopenharmony_ci return (info->nrecmemb) >> 31; 3928c2ecf20Sopenharmony_ci} 3938c2ecf20Sopenharmony_ci/* This applies to both NREC and REC string so it can be used with nrec_rdwr 3948c2ecf20Sopenharmony_ci and rec_rdwr */ 3958c2ecf20Sopenharmony_cistatic inline const char *rdwr_str(int rdwr) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci return rdwr ? "Write" : "Read"; 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_cistatic inline int nrec_cas(struct i5400_error_info *info) 4008c2ecf20Sopenharmony_ci{ 4018c2ecf20Sopenharmony_ci return ((info->nrecmemb) >> 16) & 0x1fff; 4028c2ecf20Sopenharmony_ci} 4038c2ecf20Sopenharmony_cistatic inline int nrec_ras(struct i5400_error_info *info) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci return (info->nrecmemb) & 0xffff; 4068c2ecf20Sopenharmony_ci} 4078c2ecf20Sopenharmony_cistatic inline int rec_bank(struct i5400_error_info *info) 4088c2ecf20Sopenharmony_ci{ 4098c2ecf20Sopenharmony_ci return ((info->recmema) >> 12) & 0x7; 4108c2ecf20Sopenharmony_ci} 4118c2ecf20Sopenharmony_cistatic inline int rec_rank(struct i5400_error_info *info) 4128c2ecf20Sopenharmony_ci{ 4138c2ecf20Sopenharmony_ci return ((info->recmema) >> 8) & 0xf; 4148c2ecf20Sopenharmony_ci} 4158c2ecf20Sopenharmony_cistatic inline int rec_rdwr(struct i5400_error_info *info) 4168c2ecf20Sopenharmony_ci{ 4178c2ecf20Sopenharmony_ci return (info->recmemb) >> 31; 4188c2ecf20Sopenharmony_ci} 4198c2ecf20Sopenharmony_cistatic inline int rec_cas(struct i5400_error_info *info) 4208c2ecf20Sopenharmony_ci{ 4218c2ecf20Sopenharmony_ci return ((info->recmemb) >> 16) & 0x1fff; 4228c2ecf20Sopenharmony_ci} 4238c2ecf20Sopenharmony_cistatic inline int rec_ras(struct i5400_error_info *info) 4248c2ecf20Sopenharmony_ci{ 4258c2ecf20Sopenharmony_ci return (info->recmemb) & 0xffff; 4268c2ecf20Sopenharmony_ci} 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_cistatic struct edac_pci_ctl_info *i5400_pci; 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci/* 4318c2ecf20Sopenharmony_ci * i5400_get_error_info Retrieve the hardware error information from 4328c2ecf20Sopenharmony_ci * the hardware and cache it in the 'info' 4338c2ecf20Sopenharmony_ci * structure 4348c2ecf20Sopenharmony_ci */ 4358c2ecf20Sopenharmony_cistatic void i5400_get_error_info(struct mem_ctl_info *mci, 4368c2ecf20Sopenharmony_ci struct i5400_error_info *info) 4378c2ecf20Sopenharmony_ci{ 4388c2ecf20Sopenharmony_ci struct i5400_pvt *pvt; 4398c2ecf20Sopenharmony_ci u32 value; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci pvt = mci->pvt_info; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci /* read in the 1st FATAL error register */ 4448c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, FERR_FAT_FBD, &value); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci /* Mask only the bits that the doc says are valid 4478c2ecf20Sopenharmony_ci */ 4488c2ecf20Sopenharmony_ci value &= (FERR_FAT_FBDCHAN | FERR_FAT_MASK); 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci /* If there is an error, then read in the 4518c2ecf20Sopenharmony_ci NEXT FATAL error register and the Memory Error Log Register A 4528c2ecf20Sopenharmony_ci */ 4538c2ecf20Sopenharmony_ci if (value & FERR_FAT_MASK) { 4548c2ecf20Sopenharmony_ci info->ferr_fat_fbd = value; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci /* harvest the various error data we need */ 4578c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, 4588c2ecf20Sopenharmony_ci NERR_FAT_FBD, &info->nerr_fat_fbd); 4598c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branchmap_werrors, 4608c2ecf20Sopenharmony_ci NRECMEMA, &info->nrecmema); 4618c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, 4628c2ecf20Sopenharmony_ci NRECMEMB, &info->nrecmemb); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci /* Clear the error bits, by writing them back */ 4658c2ecf20Sopenharmony_ci pci_write_config_dword(pvt->branchmap_werrors, 4668c2ecf20Sopenharmony_ci FERR_FAT_FBD, value); 4678c2ecf20Sopenharmony_ci } else { 4688c2ecf20Sopenharmony_ci info->ferr_fat_fbd = 0; 4698c2ecf20Sopenharmony_ci info->nerr_fat_fbd = 0; 4708c2ecf20Sopenharmony_ci info->nrecmema = 0; 4718c2ecf20Sopenharmony_ci info->nrecmemb = 0; 4728c2ecf20Sopenharmony_ci } 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci /* read in the 1st NON-FATAL error register */ 4758c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, FERR_NF_FBD, &value); 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci /* If there is an error, then read in the 1st NON-FATAL error 4788c2ecf20Sopenharmony_ci * register as well */ 4798c2ecf20Sopenharmony_ci if (value & FERR_NF_MASK) { 4808c2ecf20Sopenharmony_ci info->ferr_nf_fbd = value; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci /* harvest the various error data we need */ 4838c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, 4848c2ecf20Sopenharmony_ci NERR_NF_FBD, &info->nerr_nf_fbd); 4858c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branchmap_werrors, 4868c2ecf20Sopenharmony_ci RECMEMA, &info->recmema); 4878c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, 4888c2ecf20Sopenharmony_ci RECMEMB, &info->recmemb); 4898c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, 4908c2ecf20Sopenharmony_ci REDMEMB, &info->redmemb); 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci /* Clear the error bits, by writing them back */ 4938c2ecf20Sopenharmony_ci pci_write_config_dword(pvt->branchmap_werrors, 4948c2ecf20Sopenharmony_ci FERR_NF_FBD, value); 4958c2ecf20Sopenharmony_ci } else { 4968c2ecf20Sopenharmony_ci info->ferr_nf_fbd = 0; 4978c2ecf20Sopenharmony_ci info->nerr_nf_fbd = 0; 4988c2ecf20Sopenharmony_ci info->recmema = 0; 4998c2ecf20Sopenharmony_ci info->recmemb = 0; 5008c2ecf20Sopenharmony_ci info->redmemb = 0; 5018c2ecf20Sopenharmony_ci } 5028c2ecf20Sopenharmony_ci} 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci/* 5058c2ecf20Sopenharmony_ci * i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci, 5068c2ecf20Sopenharmony_ci * struct i5400_error_info *info, 5078c2ecf20Sopenharmony_ci * int handle_errors); 5088c2ecf20Sopenharmony_ci * 5098c2ecf20Sopenharmony_ci * handle the Intel FATAL and unrecoverable errors, if any 5108c2ecf20Sopenharmony_ci */ 5118c2ecf20Sopenharmony_cistatic void i5400_proccess_non_recoverable_info(struct mem_ctl_info *mci, 5128c2ecf20Sopenharmony_ci struct i5400_error_info *info, 5138c2ecf20Sopenharmony_ci unsigned long allErrors) 5148c2ecf20Sopenharmony_ci{ 5158c2ecf20Sopenharmony_ci char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80]; 5168c2ecf20Sopenharmony_ci int branch; 5178c2ecf20Sopenharmony_ci int channel; 5188c2ecf20Sopenharmony_ci int bank; 5198c2ecf20Sopenharmony_ci int buf_id; 5208c2ecf20Sopenharmony_ci int rank; 5218c2ecf20Sopenharmony_ci int rdwr; 5228c2ecf20Sopenharmony_ci int ras, cas; 5238c2ecf20Sopenharmony_ci int errnum; 5248c2ecf20Sopenharmony_ci char *type = NULL; 5258c2ecf20Sopenharmony_ci enum hw_event_mc_err_type tp_event = HW_EVENT_ERR_UNCORRECTED; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci if (!allErrors) 5288c2ecf20Sopenharmony_ci return; /* if no error, return now */ 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci if (allErrors & ERROR_FAT_MASK) { 5318c2ecf20Sopenharmony_ci type = "FATAL"; 5328c2ecf20Sopenharmony_ci tp_event = HW_EVENT_ERR_FATAL; 5338c2ecf20Sopenharmony_ci } else if (allErrors & FERR_NF_UNCORRECTABLE) 5348c2ecf20Sopenharmony_ci type = "NON-FATAL uncorrected"; 5358c2ecf20Sopenharmony_ci else 5368c2ecf20Sopenharmony_ci type = "NON-FATAL recoverable"; 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci /* ONLY ONE of the possible error bits will be set, as per the docs */ 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci branch = extract_fbdchan_indx(info->ferr_fat_fbd); 5418c2ecf20Sopenharmony_ci channel = branch; 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci /* Use the NON-Recoverable macros to extract data */ 5448c2ecf20Sopenharmony_ci bank = nrec_bank(info); 5458c2ecf20Sopenharmony_ci rank = nrec_rank(info); 5468c2ecf20Sopenharmony_ci buf_id = nrec_buf_id(info); 5478c2ecf20Sopenharmony_ci rdwr = nrec_rdwr(info); 5488c2ecf20Sopenharmony_ci ras = nrec_ras(info); 5498c2ecf20Sopenharmony_ci cas = nrec_cas(info); 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci edac_dbg(0, "\t\t%s DIMM= %d Channels= %d,%d (Branch= %d DRAM Bank= %d Buffer ID = %d rdwr= %s ras= %d cas= %d)\n", 5528c2ecf20Sopenharmony_ci type, rank, channel, channel + 1, branch >> 1, bank, 5538c2ecf20Sopenharmony_ci buf_id, rdwr_str(rdwr), ras, cas); 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci /* Only 1 bit will be on */ 5568c2ecf20Sopenharmony_ci errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name)); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci /* Form out message */ 5598c2ecf20Sopenharmony_ci snprintf(msg, sizeof(msg), 5608c2ecf20Sopenharmony_ci "Bank=%d Buffer ID = %d RAS=%d CAS=%d Err=0x%lx (%s)", 5618c2ecf20Sopenharmony_ci bank, buf_id, ras, cas, allErrors, error_name[errnum]); 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci edac_mc_handle_error(tp_event, mci, 1, 0, 0, 0, 5648c2ecf20Sopenharmony_ci branch >> 1, -1, rank, 5658c2ecf20Sopenharmony_ci rdwr ? "Write error" : "Read error", 5668c2ecf20Sopenharmony_ci msg); 5678c2ecf20Sopenharmony_ci} 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci/* 5708c2ecf20Sopenharmony_ci * i5400_process_fatal_error_info(struct mem_ctl_info *mci, 5718c2ecf20Sopenharmony_ci * struct i5400_error_info *info, 5728c2ecf20Sopenharmony_ci * int handle_errors); 5738c2ecf20Sopenharmony_ci * 5748c2ecf20Sopenharmony_ci * handle the Intel NON-FATAL errors, if any 5758c2ecf20Sopenharmony_ci */ 5768c2ecf20Sopenharmony_cistatic void i5400_process_nonfatal_error_info(struct mem_ctl_info *mci, 5778c2ecf20Sopenharmony_ci struct i5400_error_info *info) 5788c2ecf20Sopenharmony_ci{ 5798c2ecf20Sopenharmony_ci char msg[EDAC_MC_LABEL_LEN + 1 + 90 + 80]; 5808c2ecf20Sopenharmony_ci unsigned long allErrors; 5818c2ecf20Sopenharmony_ci int branch; 5828c2ecf20Sopenharmony_ci int channel; 5838c2ecf20Sopenharmony_ci int bank; 5848c2ecf20Sopenharmony_ci int rank; 5858c2ecf20Sopenharmony_ci int rdwr; 5868c2ecf20Sopenharmony_ci int ras, cas; 5878c2ecf20Sopenharmony_ci int errnum; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci /* mask off the Error bits that are possible */ 5908c2ecf20Sopenharmony_ci allErrors = from_nf_ferr(info->ferr_nf_fbd & FERR_NF_MASK); 5918c2ecf20Sopenharmony_ci if (!allErrors) 5928c2ecf20Sopenharmony_ci return; /* if no error, return now */ 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci /* ONLY ONE of the possible error bits will be set, as per the docs */ 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci if (allErrors & (ERROR_NF_UNCORRECTABLE | ERROR_NF_RECOVERABLE)) { 5978c2ecf20Sopenharmony_ci i5400_proccess_non_recoverable_info(mci, info, allErrors); 5988c2ecf20Sopenharmony_ci return; 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci /* Correctable errors */ 6028c2ecf20Sopenharmony_ci if (allErrors & ERROR_NF_CORRECTABLE) { 6038c2ecf20Sopenharmony_ci edac_dbg(0, "\tCorrected bits= 0x%lx\n", allErrors); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci branch = extract_fbdchan_indx(info->ferr_nf_fbd); 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci channel = 0; 6088c2ecf20Sopenharmony_ci if (REC_ECC_LOCATOR_ODD(info->redmemb)) 6098c2ecf20Sopenharmony_ci channel = 1; 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci /* Convert channel to be based from zero, instead of 6128c2ecf20Sopenharmony_ci * from branch base of 0 */ 6138c2ecf20Sopenharmony_ci channel += branch; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci bank = rec_bank(info); 6168c2ecf20Sopenharmony_ci rank = rec_rank(info); 6178c2ecf20Sopenharmony_ci rdwr = rec_rdwr(info); 6188c2ecf20Sopenharmony_ci ras = rec_ras(info); 6198c2ecf20Sopenharmony_ci cas = rec_cas(info); 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci /* Only 1 bit will be on */ 6228c2ecf20Sopenharmony_ci errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name)); 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci edac_dbg(0, "\t\tDIMM= %d Channel= %d (Branch %d DRAM Bank= %d rdwr= %s ras= %d cas= %d)\n", 6258c2ecf20Sopenharmony_ci rank, channel, branch >> 1, bank, 6268c2ecf20Sopenharmony_ci rdwr_str(rdwr), ras, cas); 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci /* Form out message */ 6298c2ecf20Sopenharmony_ci snprintf(msg, sizeof(msg), 6308c2ecf20Sopenharmony_ci "Corrected error (Branch=%d DRAM-Bank=%d RDWR=%s " 6318c2ecf20Sopenharmony_ci "RAS=%d CAS=%d, CE Err=0x%lx (%s))", 6328c2ecf20Sopenharmony_ci branch >> 1, bank, rdwr_str(rdwr), ras, cas, 6338c2ecf20Sopenharmony_ci allErrors, error_name[errnum]); 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0, 0, 6368c2ecf20Sopenharmony_ci branch >> 1, channel % 2, rank, 6378c2ecf20Sopenharmony_ci rdwr ? "Write error" : "Read error", 6388c2ecf20Sopenharmony_ci msg); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci return; 6418c2ecf20Sopenharmony_ci } 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci /* Miscellaneous errors */ 6448c2ecf20Sopenharmony_ci errnum = find_first_bit(&allErrors, ARRAY_SIZE(error_name)); 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci branch = extract_fbdchan_indx(info->ferr_nf_fbd); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci i5400_mc_printk(mci, KERN_EMERG, 6498c2ecf20Sopenharmony_ci "Non-Fatal misc error (Branch=%d Err=%#lx (%s))", 6508c2ecf20Sopenharmony_ci branch >> 1, allErrors, error_name[errnum]); 6518c2ecf20Sopenharmony_ci} 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci/* 6548c2ecf20Sopenharmony_ci * i5400_process_error_info Process the error info that is 6558c2ecf20Sopenharmony_ci * in the 'info' structure, previously retrieved from hardware 6568c2ecf20Sopenharmony_ci */ 6578c2ecf20Sopenharmony_cistatic void i5400_process_error_info(struct mem_ctl_info *mci, 6588c2ecf20Sopenharmony_ci struct i5400_error_info *info) 6598c2ecf20Sopenharmony_ci{ u32 allErrors; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci /* First handle any fatal errors that occurred */ 6628c2ecf20Sopenharmony_ci allErrors = (info->ferr_fat_fbd & FERR_FAT_MASK); 6638c2ecf20Sopenharmony_ci i5400_proccess_non_recoverable_info(mci, info, allErrors); 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci /* now handle any non-fatal errors that occurred */ 6668c2ecf20Sopenharmony_ci i5400_process_nonfatal_error_info(mci, info); 6678c2ecf20Sopenharmony_ci} 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci/* 6708c2ecf20Sopenharmony_ci * i5400_clear_error Retrieve any error from the hardware 6718c2ecf20Sopenharmony_ci * but do NOT process that error. 6728c2ecf20Sopenharmony_ci * Used for 'clearing' out of previous errors 6738c2ecf20Sopenharmony_ci * Called by the Core module. 6748c2ecf20Sopenharmony_ci */ 6758c2ecf20Sopenharmony_cistatic void i5400_clear_error(struct mem_ctl_info *mci) 6768c2ecf20Sopenharmony_ci{ 6778c2ecf20Sopenharmony_ci struct i5400_error_info info; 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci i5400_get_error_info(mci, &info); 6808c2ecf20Sopenharmony_ci} 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci/* 6838c2ecf20Sopenharmony_ci * i5400_check_error Retrieve and process errors reported by the 6848c2ecf20Sopenharmony_ci * hardware. Called by the Core module. 6858c2ecf20Sopenharmony_ci */ 6868c2ecf20Sopenharmony_cistatic void i5400_check_error(struct mem_ctl_info *mci) 6878c2ecf20Sopenharmony_ci{ 6888c2ecf20Sopenharmony_ci struct i5400_error_info info; 6898c2ecf20Sopenharmony_ci edac_dbg(4, "MC%d\n", mci->mc_idx); 6908c2ecf20Sopenharmony_ci i5400_get_error_info(mci, &info); 6918c2ecf20Sopenharmony_ci i5400_process_error_info(mci, &info); 6928c2ecf20Sopenharmony_ci} 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci/* 6958c2ecf20Sopenharmony_ci * i5400_put_devices 'put' all the devices that we have 6968c2ecf20Sopenharmony_ci * reserved via 'get' 6978c2ecf20Sopenharmony_ci */ 6988c2ecf20Sopenharmony_cistatic void i5400_put_devices(struct mem_ctl_info *mci) 6998c2ecf20Sopenharmony_ci{ 7008c2ecf20Sopenharmony_ci struct i5400_pvt *pvt; 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci pvt = mci->pvt_info; 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci /* Decrement usage count for devices */ 7058c2ecf20Sopenharmony_ci pci_dev_put(pvt->branch_1); 7068c2ecf20Sopenharmony_ci pci_dev_put(pvt->branch_0); 7078c2ecf20Sopenharmony_ci pci_dev_put(pvt->fsb_error_regs); 7088c2ecf20Sopenharmony_ci pci_dev_put(pvt->branchmap_werrors); 7098c2ecf20Sopenharmony_ci} 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci/* 7128c2ecf20Sopenharmony_ci * i5400_get_devices Find and perform 'get' operation on the MCH's 7138c2ecf20Sopenharmony_ci * device/functions we want to reference for this driver 7148c2ecf20Sopenharmony_ci * 7158c2ecf20Sopenharmony_ci * Need to 'get' device 16 func 1 and func 2 7168c2ecf20Sopenharmony_ci */ 7178c2ecf20Sopenharmony_cistatic int i5400_get_devices(struct mem_ctl_info *mci, int dev_idx) 7188c2ecf20Sopenharmony_ci{ 7198c2ecf20Sopenharmony_ci struct i5400_pvt *pvt; 7208c2ecf20Sopenharmony_ci struct pci_dev *pdev; 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci pvt = mci->pvt_info; 7238c2ecf20Sopenharmony_ci pvt->branchmap_werrors = NULL; 7248c2ecf20Sopenharmony_ci pvt->fsb_error_regs = NULL; 7258c2ecf20Sopenharmony_ci pvt->branch_0 = NULL; 7268c2ecf20Sopenharmony_ci pvt->branch_1 = NULL; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci /* Attempt to 'get' the MCH register we want */ 7298c2ecf20Sopenharmony_ci pdev = NULL; 7308c2ecf20Sopenharmony_ci while (1) { 7318c2ecf20Sopenharmony_ci pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 7328c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_5400_ERR, pdev); 7338c2ecf20Sopenharmony_ci if (!pdev) { 7348c2ecf20Sopenharmony_ci /* End of list, leave */ 7358c2ecf20Sopenharmony_ci i5400_printk(KERN_ERR, 7368c2ecf20Sopenharmony_ci "'system address,Process Bus' " 7378c2ecf20Sopenharmony_ci "device not found:" 7388c2ecf20Sopenharmony_ci "vendor 0x%x device 0x%x ERR func 1 " 7398c2ecf20Sopenharmony_ci "(broken BIOS?)\n", 7408c2ecf20Sopenharmony_ci PCI_VENDOR_ID_INTEL, 7418c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_5400_ERR); 7428c2ecf20Sopenharmony_ci return -ENODEV; 7438c2ecf20Sopenharmony_ci } 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci /* Store device 16 func 1 */ 7468c2ecf20Sopenharmony_ci if (PCI_FUNC(pdev->devfn) == 1) 7478c2ecf20Sopenharmony_ci break; 7488c2ecf20Sopenharmony_ci } 7498c2ecf20Sopenharmony_ci pvt->branchmap_werrors = pdev; 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci pdev = NULL; 7528c2ecf20Sopenharmony_ci while (1) { 7538c2ecf20Sopenharmony_ci pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 7548c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_5400_ERR, pdev); 7558c2ecf20Sopenharmony_ci if (!pdev) { 7568c2ecf20Sopenharmony_ci /* End of list, leave */ 7578c2ecf20Sopenharmony_ci i5400_printk(KERN_ERR, 7588c2ecf20Sopenharmony_ci "'system address,Process Bus' " 7598c2ecf20Sopenharmony_ci "device not found:" 7608c2ecf20Sopenharmony_ci "vendor 0x%x device 0x%x ERR func 2 " 7618c2ecf20Sopenharmony_ci "(broken BIOS?)\n", 7628c2ecf20Sopenharmony_ci PCI_VENDOR_ID_INTEL, 7638c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_5400_ERR); 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci pci_dev_put(pvt->branchmap_werrors); 7668c2ecf20Sopenharmony_ci return -ENODEV; 7678c2ecf20Sopenharmony_ci } 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci /* Store device 16 func 2 */ 7708c2ecf20Sopenharmony_ci if (PCI_FUNC(pdev->devfn) == 2) 7718c2ecf20Sopenharmony_ci break; 7728c2ecf20Sopenharmony_ci } 7738c2ecf20Sopenharmony_ci pvt->fsb_error_regs = pdev; 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n", 7768c2ecf20Sopenharmony_ci pci_name(pvt->system_address), 7778c2ecf20Sopenharmony_ci pvt->system_address->vendor, pvt->system_address->device); 7788c2ecf20Sopenharmony_ci edac_dbg(1, "Branchmap, control and errors - PCI Bus ID: %s %x:%x\n", 7798c2ecf20Sopenharmony_ci pci_name(pvt->branchmap_werrors), 7808c2ecf20Sopenharmony_ci pvt->branchmap_werrors->vendor, 7818c2ecf20Sopenharmony_ci pvt->branchmap_werrors->device); 7828c2ecf20Sopenharmony_ci edac_dbg(1, "FSB Error Regs - PCI Bus ID: %s %x:%x\n", 7838c2ecf20Sopenharmony_ci pci_name(pvt->fsb_error_regs), 7848c2ecf20Sopenharmony_ci pvt->fsb_error_regs->vendor, pvt->fsb_error_regs->device); 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci pvt->branch_0 = pci_get_device(PCI_VENDOR_ID_INTEL, 7878c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_5400_FBD0, NULL); 7888c2ecf20Sopenharmony_ci if (!pvt->branch_0) { 7898c2ecf20Sopenharmony_ci i5400_printk(KERN_ERR, 7908c2ecf20Sopenharmony_ci "MC: 'BRANCH 0' device not found:" 7918c2ecf20Sopenharmony_ci "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n", 7928c2ecf20Sopenharmony_ci PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_FBD0); 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci pci_dev_put(pvt->fsb_error_regs); 7958c2ecf20Sopenharmony_ci pci_dev_put(pvt->branchmap_werrors); 7968c2ecf20Sopenharmony_ci return -ENODEV; 7978c2ecf20Sopenharmony_ci } 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci /* If this device claims to have more than 2 channels then 8008c2ecf20Sopenharmony_ci * fetch Branch 1's information 8018c2ecf20Sopenharmony_ci */ 8028c2ecf20Sopenharmony_ci if (pvt->maxch < CHANNELS_PER_BRANCH) 8038c2ecf20Sopenharmony_ci return 0; 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci pvt->branch_1 = pci_get_device(PCI_VENDOR_ID_INTEL, 8068c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_5400_FBD1, NULL); 8078c2ecf20Sopenharmony_ci if (!pvt->branch_1) { 8088c2ecf20Sopenharmony_ci i5400_printk(KERN_ERR, 8098c2ecf20Sopenharmony_ci "MC: 'BRANCH 1' device not found:" 8108c2ecf20Sopenharmony_ci "vendor 0x%x device 0x%x Func 0 " 8118c2ecf20Sopenharmony_ci "(broken BIOS?)\n", 8128c2ecf20Sopenharmony_ci PCI_VENDOR_ID_INTEL, 8138c2ecf20Sopenharmony_ci PCI_DEVICE_ID_INTEL_5400_FBD1); 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci pci_dev_put(pvt->branch_0); 8168c2ecf20Sopenharmony_ci pci_dev_put(pvt->fsb_error_regs); 8178c2ecf20Sopenharmony_ci pci_dev_put(pvt->branchmap_werrors); 8188c2ecf20Sopenharmony_ci return -ENODEV; 8198c2ecf20Sopenharmony_ci } 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci return 0; 8228c2ecf20Sopenharmony_ci} 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci/* 8258c2ecf20Sopenharmony_ci * determine_amb_present 8268c2ecf20Sopenharmony_ci * 8278c2ecf20Sopenharmony_ci * the information is contained in DIMMS_PER_CHANNEL different 8288c2ecf20Sopenharmony_ci * registers determining which of the DIMMS_PER_CHANNEL requires 8298c2ecf20Sopenharmony_ci * knowing which channel is in question 8308c2ecf20Sopenharmony_ci * 8318c2ecf20Sopenharmony_ci * 2 branches, each with 2 channels 8328c2ecf20Sopenharmony_ci * b0_ambpresent0 for channel '0' 8338c2ecf20Sopenharmony_ci * b0_ambpresent1 for channel '1' 8348c2ecf20Sopenharmony_ci * b1_ambpresent0 for channel '2' 8358c2ecf20Sopenharmony_ci * b1_ambpresent1 for channel '3' 8368c2ecf20Sopenharmony_ci */ 8378c2ecf20Sopenharmony_cistatic int determine_amb_present_reg(struct i5400_pvt *pvt, int channel) 8388c2ecf20Sopenharmony_ci{ 8398c2ecf20Sopenharmony_ci int amb_present; 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci if (channel < CHANNELS_PER_BRANCH) { 8428c2ecf20Sopenharmony_ci if (channel & 0x1) 8438c2ecf20Sopenharmony_ci amb_present = pvt->b0_ambpresent1; 8448c2ecf20Sopenharmony_ci else 8458c2ecf20Sopenharmony_ci amb_present = pvt->b0_ambpresent0; 8468c2ecf20Sopenharmony_ci } else { 8478c2ecf20Sopenharmony_ci if (channel & 0x1) 8488c2ecf20Sopenharmony_ci amb_present = pvt->b1_ambpresent1; 8498c2ecf20Sopenharmony_ci else 8508c2ecf20Sopenharmony_ci amb_present = pvt->b1_ambpresent0; 8518c2ecf20Sopenharmony_ci } 8528c2ecf20Sopenharmony_ci 8538c2ecf20Sopenharmony_ci return amb_present; 8548c2ecf20Sopenharmony_ci} 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_ci/* 8578c2ecf20Sopenharmony_ci * determine_mtr(pvt, dimm, channel) 8588c2ecf20Sopenharmony_ci * 8598c2ecf20Sopenharmony_ci * return the proper MTR register as determine by the dimm and desired channel 8608c2ecf20Sopenharmony_ci */ 8618c2ecf20Sopenharmony_cistatic int determine_mtr(struct i5400_pvt *pvt, int dimm, int channel) 8628c2ecf20Sopenharmony_ci{ 8638c2ecf20Sopenharmony_ci int mtr; 8648c2ecf20Sopenharmony_ci int n; 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci /* There is one MTR for each slot pair of FB-DIMMs, 8678c2ecf20Sopenharmony_ci Each slot pair may be at branch 0 or branch 1. 8688c2ecf20Sopenharmony_ci */ 8698c2ecf20Sopenharmony_ci n = dimm; 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci if (n >= DIMMS_PER_CHANNEL) { 8728c2ecf20Sopenharmony_ci edac_dbg(0, "ERROR: trying to access an invalid dimm: %d\n", 8738c2ecf20Sopenharmony_ci dimm); 8748c2ecf20Sopenharmony_ci return 0; 8758c2ecf20Sopenharmony_ci } 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci if (channel < CHANNELS_PER_BRANCH) 8788c2ecf20Sopenharmony_ci mtr = pvt->b0_mtr[n]; 8798c2ecf20Sopenharmony_ci else 8808c2ecf20Sopenharmony_ci mtr = pvt->b1_mtr[n]; 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci return mtr; 8838c2ecf20Sopenharmony_ci} 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci/* 8868c2ecf20Sopenharmony_ci */ 8878c2ecf20Sopenharmony_cistatic void decode_mtr(int slot_row, u16 mtr) 8888c2ecf20Sopenharmony_ci{ 8898c2ecf20Sopenharmony_ci int ans; 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci ans = MTR_DIMMS_PRESENT(mtr); 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ci edac_dbg(2, "\tMTR%d=0x%x: DIMMs are %sPresent\n", 8948c2ecf20Sopenharmony_ci slot_row, mtr, ans ? "" : "NOT "); 8958c2ecf20Sopenharmony_ci if (!ans) 8968c2ecf20Sopenharmony_ci return; 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr)); 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tELECTRICAL THROTTLING is %s\n", 9018c2ecf20Sopenharmony_ci MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled"); 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr)); 9048c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tNUMRANK: %s\n", 9058c2ecf20Sopenharmony_ci MTR_DIMM_RANK(mtr) ? "double" : "single"); 9068c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tNUMROW: %s\n", 9078c2ecf20Sopenharmony_ci MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" : 9088c2ecf20Sopenharmony_ci MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" : 9098c2ecf20Sopenharmony_ci MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" : 9108c2ecf20Sopenharmony_ci "65,536 - 16 rows"); 9118c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tNUMCOL: %s\n", 9128c2ecf20Sopenharmony_ci MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" : 9138c2ecf20Sopenharmony_ci MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" : 9148c2ecf20Sopenharmony_ci MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" : 9158c2ecf20Sopenharmony_ci "reserved"); 9168c2ecf20Sopenharmony_ci} 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_cistatic void handle_channel(struct i5400_pvt *pvt, int dimm, int channel, 9198c2ecf20Sopenharmony_ci struct i5400_dimm_info *dinfo) 9208c2ecf20Sopenharmony_ci{ 9218c2ecf20Sopenharmony_ci int mtr; 9228c2ecf20Sopenharmony_ci int amb_present_reg; 9238c2ecf20Sopenharmony_ci int addrBits; 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci mtr = determine_mtr(pvt, dimm, channel); 9268c2ecf20Sopenharmony_ci if (MTR_DIMMS_PRESENT(mtr)) { 9278c2ecf20Sopenharmony_ci amb_present_reg = determine_amb_present_reg(pvt, channel); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci /* Determine if there is a DIMM present in this DIMM slot */ 9308c2ecf20Sopenharmony_ci if (amb_present_reg & (1 << dimm)) { 9318c2ecf20Sopenharmony_ci /* Start with the number of bits for a Bank 9328c2ecf20Sopenharmony_ci * on the DRAM */ 9338c2ecf20Sopenharmony_ci addrBits = MTR_DRAM_BANKS_ADDR_BITS(mtr); 9348c2ecf20Sopenharmony_ci /* Add thenumber of ROW bits */ 9358c2ecf20Sopenharmony_ci addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr); 9368c2ecf20Sopenharmony_ci /* add the number of COLUMN bits */ 9378c2ecf20Sopenharmony_ci addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr); 9388c2ecf20Sopenharmony_ci /* add the number of RANK bits */ 9398c2ecf20Sopenharmony_ci addrBits += MTR_DIMM_RANK(mtr); 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_ci addrBits += 6; /* add 64 bits per DIMM */ 9428c2ecf20Sopenharmony_ci addrBits -= 20; /* divide by 2^^20 */ 9438c2ecf20Sopenharmony_ci addrBits -= 3; /* 8 bits per bytes */ 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci dinfo->megabytes = 1 << addrBits; 9468c2ecf20Sopenharmony_ci } 9478c2ecf20Sopenharmony_ci } 9488c2ecf20Sopenharmony_ci} 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_ci/* 9518c2ecf20Sopenharmony_ci * calculate_dimm_size 9528c2ecf20Sopenharmony_ci * 9538c2ecf20Sopenharmony_ci * also will output a DIMM matrix map, if debug is enabled, for viewing 9548c2ecf20Sopenharmony_ci * how the DIMMs are populated 9558c2ecf20Sopenharmony_ci */ 9568c2ecf20Sopenharmony_cistatic void calculate_dimm_size(struct i5400_pvt *pvt) 9578c2ecf20Sopenharmony_ci{ 9588c2ecf20Sopenharmony_ci struct i5400_dimm_info *dinfo; 9598c2ecf20Sopenharmony_ci int dimm, max_dimms; 9608c2ecf20Sopenharmony_ci char *p, *mem_buffer; 9618c2ecf20Sopenharmony_ci int space, n; 9628c2ecf20Sopenharmony_ci int channel, branch; 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci /* ================= Generate some debug output ================= */ 9658c2ecf20Sopenharmony_ci space = PAGE_SIZE; 9668c2ecf20Sopenharmony_ci mem_buffer = p = kmalloc(space, GFP_KERNEL); 9678c2ecf20Sopenharmony_ci if (p == NULL) { 9688c2ecf20Sopenharmony_ci i5400_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n", 9698c2ecf20Sopenharmony_ci __FILE__, __func__); 9708c2ecf20Sopenharmony_ci return; 9718c2ecf20Sopenharmony_ci } 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci /* Scan all the actual DIMMS 9748c2ecf20Sopenharmony_ci * and calculate the information for each DIMM 9758c2ecf20Sopenharmony_ci * Start with the highest dimm first, to display it first 9768c2ecf20Sopenharmony_ci * and work toward the 0th dimm 9778c2ecf20Sopenharmony_ci */ 9788c2ecf20Sopenharmony_ci max_dimms = pvt->maxdimmperch; 9798c2ecf20Sopenharmony_ci for (dimm = max_dimms - 1; dimm >= 0; dimm--) { 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci /* on an odd dimm, first output a 'boundary' marker, 9828c2ecf20Sopenharmony_ci * then reset the message buffer */ 9838c2ecf20Sopenharmony_ci if (dimm & 0x1) { 9848c2ecf20Sopenharmony_ci n = snprintf(p, space, "---------------------------" 9858c2ecf20Sopenharmony_ci "-------------------------------"); 9868c2ecf20Sopenharmony_ci p += n; 9878c2ecf20Sopenharmony_ci space -= n; 9888c2ecf20Sopenharmony_ci edac_dbg(2, "%s\n", mem_buffer); 9898c2ecf20Sopenharmony_ci p = mem_buffer; 9908c2ecf20Sopenharmony_ci space = PAGE_SIZE; 9918c2ecf20Sopenharmony_ci } 9928c2ecf20Sopenharmony_ci n = snprintf(p, space, "dimm %2d ", dimm); 9938c2ecf20Sopenharmony_ci p += n; 9948c2ecf20Sopenharmony_ci space -= n; 9958c2ecf20Sopenharmony_ci 9968c2ecf20Sopenharmony_ci for (channel = 0; channel < pvt->maxch; channel++) { 9978c2ecf20Sopenharmony_ci dinfo = &pvt->dimm_info[dimm][channel]; 9988c2ecf20Sopenharmony_ci handle_channel(pvt, dimm, channel, dinfo); 9998c2ecf20Sopenharmony_ci n = snprintf(p, space, "%4d MB | ", dinfo->megabytes); 10008c2ecf20Sopenharmony_ci p += n; 10018c2ecf20Sopenharmony_ci space -= n; 10028c2ecf20Sopenharmony_ci } 10038c2ecf20Sopenharmony_ci edac_dbg(2, "%s\n", mem_buffer); 10048c2ecf20Sopenharmony_ci p = mem_buffer; 10058c2ecf20Sopenharmony_ci space = PAGE_SIZE; 10068c2ecf20Sopenharmony_ci } 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci /* Output the last bottom 'boundary' marker */ 10098c2ecf20Sopenharmony_ci n = snprintf(p, space, "---------------------------" 10108c2ecf20Sopenharmony_ci "-------------------------------"); 10118c2ecf20Sopenharmony_ci p += n; 10128c2ecf20Sopenharmony_ci space -= n; 10138c2ecf20Sopenharmony_ci edac_dbg(2, "%s\n", mem_buffer); 10148c2ecf20Sopenharmony_ci p = mem_buffer; 10158c2ecf20Sopenharmony_ci space = PAGE_SIZE; 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci /* now output the 'channel' labels */ 10188c2ecf20Sopenharmony_ci n = snprintf(p, space, " "); 10198c2ecf20Sopenharmony_ci p += n; 10208c2ecf20Sopenharmony_ci space -= n; 10218c2ecf20Sopenharmony_ci for (channel = 0; channel < pvt->maxch; channel++) { 10228c2ecf20Sopenharmony_ci n = snprintf(p, space, "channel %d | ", channel); 10238c2ecf20Sopenharmony_ci p += n; 10248c2ecf20Sopenharmony_ci space -= n; 10258c2ecf20Sopenharmony_ci } 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_ci space -= n; 10288c2ecf20Sopenharmony_ci edac_dbg(2, "%s\n", mem_buffer); 10298c2ecf20Sopenharmony_ci p = mem_buffer; 10308c2ecf20Sopenharmony_ci space = PAGE_SIZE; 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci n = snprintf(p, space, " "); 10338c2ecf20Sopenharmony_ci p += n; 10348c2ecf20Sopenharmony_ci for (branch = 0; branch < MAX_BRANCHES; branch++) { 10358c2ecf20Sopenharmony_ci n = snprintf(p, space, " branch %d | ", branch); 10368c2ecf20Sopenharmony_ci p += n; 10378c2ecf20Sopenharmony_ci space -= n; 10388c2ecf20Sopenharmony_ci } 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci /* output the last message and free buffer */ 10418c2ecf20Sopenharmony_ci edac_dbg(2, "%s\n", mem_buffer); 10428c2ecf20Sopenharmony_ci kfree(mem_buffer); 10438c2ecf20Sopenharmony_ci} 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci/* 10468c2ecf20Sopenharmony_ci * i5400_get_mc_regs read in the necessary registers and 10478c2ecf20Sopenharmony_ci * cache locally 10488c2ecf20Sopenharmony_ci * 10498c2ecf20Sopenharmony_ci * Fills in the private data members 10508c2ecf20Sopenharmony_ci */ 10518c2ecf20Sopenharmony_cistatic void i5400_get_mc_regs(struct mem_ctl_info *mci) 10528c2ecf20Sopenharmony_ci{ 10538c2ecf20Sopenharmony_ci struct i5400_pvt *pvt; 10548c2ecf20Sopenharmony_ci u32 actual_tolm; 10558c2ecf20Sopenharmony_ci u16 limit; 10568c2ecf20Sopenharmony_ci int slot_row; 10578c2ecf20Sopenharmony_ci int way0, way1; 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci pvt = mci->pvt_info; 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->system_address, AMBASE, 10628c2ecf20Sopenharmony_ci &pvt->u.ambase_bottom); 10638c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->system_address, AMBASE + sizeof(u32), 10648c2ecf20Sopenharmony_ci &pvt->u.ambase_top); 10658c2ecf20Sopenharmony_ci 10668c2ecf20Sopenharmony_ci edac_dbg(2, "AMBASE= 0x%lx MAXCH= %d MAX-DIMM-Per-CH= %d\n", 10678c2ecf20Sopenharmony_ci (long unsigned int)pvt->ambase, pvt->maxch, pvt->maxdimmperch); 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci /* Get the Branch Map regs */ 10708c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branchmap_werrors, TOLM, &pvt->tolm); 10718c2ecf20Sopenharmony_ci pvt->tolm >>= 12; 10728c2ecf20Sopenharmony_ci edac_dbg(2, "\nTOLM (number of 256M regions) =%u (0x%x)\n", 10738c2ecf20Sopenharmony_ci pvt->tolm, pvt->tolm); 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28)); 10768c2ecf20Sopenharmony_ci edac_dbg(2, "Actual TOLM byte addr=%u.%03u GB (0x%x)\n", 10778c2ecf20Sopenharmony_ci actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28); 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branchmap_werrors, MIR0, &pvt->mir0); 10808c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branchmap_werrors, MIR1, &pvt->mir1); 10818c2ecf20Sopenharmony_ci 10828c2ecf20Sopenharmony_ci /* Get the MIR[0-1] regs */ 10838c2ecf20Sopenharmony_ci limit = (pvt->mir0 >> 4) & 0x0fff; 10848c2ecf20Sopenharmony_ci way0 = pvt->mir0 & 0x1; 10858c2ecf20Sopenharmony_ci way1 = pvt->mir0 & 0x2; 10868c2ecf20Sopenharmony_ci edac_dbg(2, "MIR0: limit= 0x%x WAY1= %u WAY0= %x\n", 10878c2ecf20Sopenharmony_ci limit, way1, way0); 10888c2ecf20Sopenharmony_ci limit = (pvt->mir1 >> 4) & 0xfff; 10898c2ecf20Sopenharmony_ci way0 = pvt->mir1 & 0x1; 10908c2ecf20Sopenharmony_ci way1 = pvt->mir1 & 0x2; 10918c2ecf20Sopenharmony_ci edac_dbg(2, "MIR1: limit= 0x%x WAY1= %u WAY0= %x\n", 10928c2ecf20Sopenharmony_ci limit, way1, way0); 10938c2ecf20Sopenharmony_ci 10948c2ecf20Sopenharmony_ci /* Get the set of MTR[0-3] regs by each branch */ 10958c2ecf20Sopenharmony_ci for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++) { 10968c2ecf20Sopenharmony_ci int where = MTR0 + (slot_row * sizeof(u16)); 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci /* Branch 0 set of MTR registers */ 10998c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branch_0, where, 11008c2ecf20Sopenharmony_ci &pvt->b0_mtr[slot_row]); 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci edac_dbg(2, "MTR%d where=0x%x B0 value=0x%x\n", 11038c2ecf20Sopenharmony_ci slot_row, where, pvt->b0_mtr[slot_row]); 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_ci if (pvt->maxch < CHANNELS_PER_BRANCH) { 11068c2ecf20Sopenharmony_ci pvt->b1_mtr[slot_row] = 0; 11078c2ecf20Sopenharmony_ci continue; 11088c2ecf20Sopenharmony_ci } 11098c2ecf20Sopenharmony_ci 11108c2ecf20Sopenharmony_ci /* Branch 1 set of MTR registers */ 11118c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branch_1, where, 11128c2ecf20Sopenharmony_ci &pvt->b1_mtr[slot_row]); 11138c2ecf20Sopenharmony_ci edac_dbg(2, "MTR%d where=0x%x B1 value=0x%x\n", 11148c2ecf20Sopenharmony_ci slot_row, where, pvt->b1_mtr[slot_row]); 11158c2ecf20Sopenharmony_ci } 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci /* Read and dump branch 0's MTRs */ 11188c2ecf20Sopenharmony_ci edac_dbg(2, "Memory Technology Registers:\n"); 11198c2ecf20Sopenharmony_ci edac_dbg(2, " Branch 0:\n"); 11208c2ecf20Sopenharmony_ci for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++) 11218c2ecf20Sopenharmony_ci decode_mtr(slot_row, pvt->b0_mtr[slot_row]); 11228c2ecf20Sopenharmony_ci 11238c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branch_0, AMBPRESENT_0, 11248c2ecf20Sopenharmony_ci &pvt->b0_ambpresent0); 11258c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tAMB-Branch 0-present0 0x%x:\n", pvt->b0_ambpresent0); 11268c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branch_0, AMBPRESENT_1, 11278c2ecf20Sopenharmony_ci &pvt->b0_ambpresent1); 11288c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tAMB-Branch 0-present1 0x%x:\n", pvt->b0_ambpresent1); 11298c2ecf20Sopenharmony_ci 11308c2ecf20Sopenharmony_ci /* Only if we have 2 branchs (4 channels) */ 11318c2ecf20Sopenharmony_ci if (pvt->maxch < CHANNELS_PER_BRANCH) { 11328c2ecf20Sopenharmony_ci pvt->b1_ambpresent0 = 0; 11338c2ecf20Sopenharmony_ci pvt->b1_ambpresent1 = 0; 11348c2ecf20Sopenharmony_ci } else { 11358c2ecf20Sopenharmony_ci /* Read and dump branch 1's MTRs */ 11368c2ecf20Sopenharmony_ci edac_dbg(2, " Branch 1:\n"); 11378c2ecf20Sopenharmony_ci for (slot_row = 0; slot_row < DIMMS_PER_CHANNEL; slot_row++) 11388c2ecf20Sopenharmony_ci decode_mtr(slot_row, pvt->b1_mtr[slot_row]); 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branch_1, AMBPRESENT_0, 11418c2ecf20Sopenharmony_ci &pvt->b1_ambpresent0); 11428c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tAMB-Branch 1-present0 0x%x:\n", 11438c2ecf20Sopenharmony_ci pvt->b1_ambpresent0); 11448c2ecf20Sopenharmony_ci pci_read_config_word(pvt->branch_1, AMBPRESENT_1, 11458c2ecf20Sopenharmony_ci &pvt->b1_ambpresent1); 11468c2ecf20Sopenharmony_ci edac_dbg(2, "\t\tAMB-Branch 1-present1 0x%x:\n", 11478c2ecf20Sopenharmony_ci pvt->b1_ambpresent1); 11488c2ecf20Sopenharmony_ci } 11498c2ecf20Sopenharmony_ci 11508c2ecf20Sopenharmony_ci /* Go and determine the size of each DIMM and place in an 11518c2ecf20Sopenharmony_ci * orderly matrix */ 11528c2ecf20Sopenharmony_ci calculate_dimm_size(pvt); 11538c2ecf20Sopenharmony_ci} 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci/* 11568c2ecf20Sopenharmony_ci * i5400_init_dimms Initialize the 'dimms' table within 11578c2ecf20Sopenharmony_ci * the mci control structure with the 11588c2ecf20Sopenharmony_ci * addressing of memory. 11598c2ecf20Sopenharmony_ci * 11608c2ecf20Sopenharmony_ci * return: 11618c2ecf20Sopenharmony_ci * 0 success 11628c2ecf20Sopenharmony_ci * 1 no actual memory found on this MC 11638c2ecf20Sopenharmony_ci */ 11648c2ecf20Sopenharmony_cistatic int i5400_init_dimms(struct mem_ctl_info *mci) 11658c2ecf20Sopenharmony_ci{ 11668c2ecf20Sopenharmony_ci struct i5400_pvt *pvt; 11678c2ecf20Sopenharmony_ci struct dimm_info *dimm; 11688c2ecf20Sopenharmony_ci int ndimms; 11698c2ecf20Sopenharmony_ci int mtr; 11708c2ecf20Sopenharmony_ci int size_mb; 11718c2ecf20Sopenharmony_ci int channel, slot; 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_ci pvt = mci->pvt_info; 11748c2ecf20Sopenharmony_ci 11758c2ecf20Sopenharmony_ci ndimms = 0; 11768c2ecf20Sopenharmony_ci 11778c2ecf20Sopenharmony_ci /* 11788c2ecf20Sopenharmony_ci * FIXME: remove pvt->dimm_info[slot][channel] and use the 3 11798c2ecf20Sopenharmony_ci * layers here. 11808c2ecf20Sopenharmony_ci */ 11818c2ecf20Sopenharmony_ci for (channel = 0; channel < mci->layers[0].size * mci->layers[1].size; 11828c2ecf20Sopenharmony_ci channel++) { 11838c2ecf20Sopenharmony_ci for (slot = 0; slot < mci->layers[2].size; slot++) { 11848c2ecf20Sopenharmony_ci mtr = determine_mtr(pvt, slot, channel); 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci /* if no DIMMS on this slot, continue */ 11878c2ecf20Sopenharmony_ci if (!MTR_DIMMS_PRESENT(mtr)) 11888c2ecf20Sopenharmony_ci continue; 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci dimm = edac_get_dimm(mci, channel / 2, channel % 2, slot); 11918c2ecf20Sopenharmony_ci 11928c2ecf20Sopenharmony_ci size_mb = pvt->dimm_info[slot][channel].megabytes; 11938c2ecf20Sopenharmony_ci 11948c2ecf20Sopenharmony_ci edac_dbg(2, "dimm (branch %d channel %d slot %d): %d.%03d GB\n", 11958c2ecf20Sopenharmony_ci channel / 2, channel % 2, slot, 11968c2ecf20Sopenharmony_ci size_mb / 1000, size_mb % 1000); 11978c2ecf20Sopenharmony_ci 11988c2ecf20Sopenharmony_ci dimm->nr_pages = size_mb << 8; 11998c2ecf20Sopenharmony_ci dimm->grain = 8; 12008c2ecf20Sopenharmony_ci dimm->dtype = MTR_DRAM_WIDTH(mtr) == 8 ? 12018c2ecf20Sopenharmony_ci DEV_X8 : DEV_X4; 12028c2ecf20Sopenharmony_ci dimm->mtype = MEM_FB_DDR2; 12038c2ecf20Sopenharmony_ci /* 12048c2ecf20Sopenharmony_ci * The eccc mechanism is SDDC (aka SECC), with 12058c2ecf20Sopenharmony_ci * is similar to Chipkill. 12068c2ecf20Sopenharmony_ci */ 12078c2ecf20Sopenharmony_ci dimm->edac_mode = MTR_DRAM_WIDTH(mtr) == 8 ? 12088c2ecf20Sopenharmony_ci EDAC_S8ECD8ED : EDAC_S4ECD4ED; 12098c2ecf20Sopenharmony_ci ndimms++; 12108c2ecf20Sopenharmony_ci } 12118c2ecf20Sopenharmony_ci } 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_ci /* 12148c2ecf20Sopenharmony_ci * When just one memory is provided, it should be at location (0,0,0). 12158c2ecf20Sopenharmony_ci * With such single-DIMM mode, the SDCC algorithm degrades to SECDEC+. 12168c2ecf20Sopenharmony_ci */ 12178c2ecf20Sopenharmony_ci if (ndimms == 1) 12188c2ecf20Sopenharmony_ci mci->dimms[0]->edac_mode = EDAC_SECDED; 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci return (ndimms == 0); 12218c2ecf20Sopenharmony_ci} 12228c2ecf20Sopenharmony_ci 12238c2ecf20Sopenharmony_ci/* 12248c2ecf20Sopenharmony_ci * i5400_enable_error_reporting 12258c2ecf20Sopenharmony_ci * Turn on the memory reporting features of the hardware 12268c2ecf20Sopenharmony_ci */ 12278c2ecf20Sopenharmony_cistatic void i5400_enable_error_reporting(struct mem_ctl_info *mci) 12288c2ecf20Sopenharmony_ci{ 12298c2ecf20Sopenharmony_ci struct i5400_pvt *pvt; 12308c2ecf20Sopenharmony_ci u32 fbd_error_mask; 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_ci pvt = mci->pvt_info; 12338c2ecf20Sopenharmony_ci 12348c2ecf20Sopenharmony_ci /* Read the FBD Error Mask Register */ 12358c2ecf20Sopenharmony_ci pci_read_config_dword(pvt->branchmap_werrors, EMASK_FBD, 12368c2ecf20Sopenharmony_ci &fbd_error_mask); 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci /* Enable with a '0' */ 12398c2ecf20Sopenharmony_ci fbd_error_mask &= ~(ENABLE_EMASK_ALL); 12408c2ecf20Sopenharmony_ci 12418c2ecf20Sopenharmony_ci pci_write_config_dword(pvt->branchmap_werrors, EMASK_FBD, 12428c2ecf20Sopenharmony_ci fbd_error_mask); 12438c2ecf20Sopenharmony_ci} 12448c2ecf20Sopenharmony_ci 12458c2ecf20Sopenharmony_ci/* 12468c2ecf20Sopenharmony_ci * i5400_probe1 Probe for ONE instance of device to see if it is 12478c2ecf20Sopenharmony_ci * present. 12488c2ecf20Sopenharmony_ci * return: 12498c2ecf20Sopenharmony_ci * 0 for FOUND a device 12508c2ecf20Sopenharmony_ci * < 0 for error code 12518c2ecf20Sopenharmony_ci */ 12528c2ecf20Sopenharmony_cistatic int i5400_probe1(struct pci_dev *pdev, int dev_idx) 12538c2ecf20Sopenharmony_ci{ 12548c2ecf20Sopenharmony_ci struct mem_ctl_info *mci; 12558c2ecf20Sopenharmony_ci struct i5400_pvt *pvt; 12568c2ecf20Sopenharmony_ci struct edac_mc_layer layers[3]; 12578c2ecf20Sopenharmony_ci 12588c2ecf20Sopenharmony_ci if (dev_idx >= ARRAY_SIZE(i5400_devs)) 12598c2ecf20Sopenharmony_ci return -EINVAL; 12608c2ecf20Sopenharmony_ci 12618c2ecf20Sopenharmony_ci edac_dbg(0, "MC: pdev bus %u dev=0x%x fn=0x%x\n", 12628c2ecf20Sopenharmony_ci pdev->bus->number, 12638c2ecf20Sopenharmony_ci PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); 12648c2ecf20Sopenharmony_ci 12658c2ecf20Sopenharmony_ci /* We only are looking for func 0 of the set */ 12668c2ecf20Sopenharmony_ci if (PCI_FUNC(pdev->devfn) != 0) 12678c2ecf20Sopenharmony_ci return -ENODEV; 12688c2ecf20Sopenharmony_ci 12698c2ecf20Sopenharmony_ci /* 12708c2ecf20Sopenharmony_ci * allocate a new MC control structure 12718c2ecf20Sopenharmony_ci * 12728c2ecf20Sopenharmony_ci * This drivers uses the DIMM slot as "csrow" and the rest as "channel". 12738c2ecf20Sopenharmony_ci */ 12748c2ecf20Sopenharmony_ci layers[0].type = EDAC_MC_LAYER_BRANCH; 12758c2ecf20Sopenharmony_ci layers[0].size = MAX_BRANCHES; 12768c2ecf20Sopenharmony_ci layers[0].is_virt_csrow = false; 12778c2ecf20Sopenharmony_ci layers[1].type = EDAC_MC_LAYER_CHANNEL; 12788c2ecf20Sopenharmony_ci layers[1].size = CHANNELS_PER_BRANCH; 12798c2ecf20Sopenharmony_ci layers[1].is_virt_csrow = false; 12808c2ecf20Sopenharmony_ci layers[2].type = EDAC_MC_LAYER_SLOT; 12818c2ecf20Sopenharmony_ci layers[2].size = DIMMS_PER_CHANNEL; 12828c2ecf20Sopenharmony_ci layers[2].is_virt_csrow = true; 12838c2ecf20Sopenharmony_ci mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt)); 12848c2ecf20Sopenharmony_ci if (mci == NULL) 12858c2ecf20Sopenharmony_ci return -ENOMEM; 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci edac_dbg(0, "MC: mci = %p\n", mci); 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ci mci->pdev = &pdev->dev; /* record ptr to the generic device */ 12908c2ecf20Sopenharmony_ci 12918c2ecf20Sopenharmony_ci pvt = mci->pvt_info; 12928c2ecf20Sopenharmony_ci pvt->system_address = pdev; /* Record this device in our private */ 12938c2ecf20Sopenharmony_ci pvt->maxch = MAX_CHANNELS; 12948c2ecf20Sopenharmony_ci pvt->maxdimmperch = DIMMS_PER_CHANNEL; 12958c2ecf20Sopenharmony_ci 12968c2ecf20Sopenharmony_ci /* 'get' the pci devices we want to reserve for our use */ 12978c2ecf20Sopenharmony_ci if (i5400_get_devices(mci, dev_idx)) 12988c2ecf20Sopenharmony_ci goto fail0; 12998c2ecf20Sopenharmony_ci 13008c2ecf20Sopenharmony_ci /* Time to get serious */ 13018c2ecf20Sopenharmony_ci i5400_get_mc_regs(mci); /* retrieve the hardware registers */ 13028c2ecf20Sopenharmony_ci 13038c2ecf20Sopenharmony_ci mci->mc_idx = 0; 13048c2ecf20Sopenharmony_ci mci->mtype_cap = MEM_FLAG_FB_DDR2; 13058c2ecf20Sopenharmony_ci mci->edac_ctl_cap = EDAC_FLAG_NONE; 13068c2ecf20Sopenharmony_ci mci->edac_cap = EDAC_FLAG_NONE; 13078c2ecf20Sopenharmony_ci mci->mod_name = "i5400_edac.c"; 13088c2ecf20Sopenharmony_ci mci->ctl_name = i5400_devs[dev_idx].ctl_name; 13098c2ecf20Sopenharmony_ci mci->dev_name = pci_name(pdev); 13108c2ecf20Sopenharmony_ci mci->ctl_page_to_phys = NULL; 13118c2ecf20Sopenharmony_ci 13128c2ecf20Sopenharmony_ci /* Set the function pointer to an actual operation function */ 13138c2ecf20Sopenharmony_ci mci->edac_check = i5400_check_error; 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci /* initialize the MC control structure 'dimms' table 13168c2ecf20Sopenharmony_ci * with the mapping and control information */ 13178c2ecf20Sopenharmony_ci if (i5400_init_dimms(mci)) { 13188c2ecf20Sopenharmony_ci edac_dbg(0, "MC: Setting mci->edac_cap to EDAC_FLAG_NONE because i5400_init_dimms() returned nonzero value\n"); 13198c2ecf20Sopenharmony_ci mci->edac_cap = EDAC_FLAG_NONE; /* no dimms found */ 13208c2ecf20Sopenharmony_ci } else { 13218c2ecf20Sopenharmony_ci edac_dbg(1, "MC: Enable error reporting now\n"); 13228c2ecf20Sopenharmony_ci i5400_enable_error_reporting(mci); 13238c2ecf20Sopenharmony_ci } 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci /* add this new MC control structure to EDAC's list of MCs */ 13268c2ecf20Sopenharmony_ci if (edac_mc_add_mc(mci)) { 13278c2ecf20Sopenharmony_ci edac_dbg(0, "MC: failed edac_mc_add_mc()\n"); 13288c2ecf20Sopenharmony_ci /* FIXME: perhaps some code should go here that disables error 13298c2ecf20Sopenharmony_ci * reporting if we just enabled it 13308c2ecf20Sopenharmony_ci */ 13318c2ecf20Sopenharmony_ci goto fail1; 13328c2ecf20Sopenharmony_ci } 13338c2ecf20Sopenharmony_ci 13348c2ecf20Sopenharmony_ci i5400_clear_error(mci); 13358c2ecf20Sopenharmony_ci 13368c2ecf20Sopenharmony_ci /* allocating generic PCI control info */ 13378c2ecf20Sopenharmony_ci i5400_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR); 13388c2ecf20Sopenharmony_ci if (!i5400_pci) { 13398c2ecf20Sopenharmony_ci printk(KERN_WARNING 13408c2ecf20Sopenharmony_ci "%s(): Unable to create PCI control\n", 13418c2ecf20Sopenharmony_ci __func__); 13428c2ecf20Sopenharmony_ci printk(KERN_WARNING 13438c2ecf20Sopenharmony_ci "%s(): PCI error report via EDAC not setup\n", 13448c2ecf20Sopenharmony_ci __func__); 13458c2ecf20Sopenharmony_ci } 13468c2ecf20Sopenharmony_ci 13478c2ecf20Sopenharmony_ci return 0; 13488c2ecf20Sopenharmony_ci 13498c2ecf20Sopenharmony_ci /* Error exit unwinding stack */ 13508c2ecf20Sopenharmony_cifail1: 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ci i5400_put_devices(mci); 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_cifail0: 13558c2ecf20Sopenharmony_ci edac_mc_free(mci); 13568c2ecf20Sopenharmony_ci return -ENODEV; 13578c2ecf20Sopenharmony_ci} 13588c2ecf20Sopenharmony_ci 13598c2ecf20Sopenharmony_ci/* 13608c2ecf20Sopenharmony_ci * i5400_init_one constructor for one instance of device 13618c2ecf20Sopenharmony_ci * 13628c2ecf20Sopenharmony_ci * returns: 13638c2ecf20Sopenharmony_ci * negative on error 13648c2ecf20Sopenharmony_ci * count (>= 0) 13658c2ecf20Sopenharmony_ci */ 13668c2ecf20Sopenharmony_cistatic int i5400_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 13678c2ecf20Sopenharmony_ci{ 13688c2ecf20Sopenharmony_ci int rc; 13698c2ecf20Sopenharmony_ci 13708c2ecf20Sopenharmony_ci edac_dbg(0, "MC:\n"); 13718c2ecf20Sopenharmony_ci 13728c2ecf20Sopenharmony_ci /* wake up device */ 13738c2ecf20Sopenharmony_ci rc = pci_enable_device(pdev); 13748c2ecf20Sopenharmony_ci if (rc) 13758c2ecf20Sopenharmony_ci return rc; 13768c2ecf20Sopenharmony_ci 13778c2ecf20Sopenharmony_ci /* now probe and enable the device */ 13788c2ecf20Sopenharmony_ci return i5400_probe1(pdev, id->driver_data); 13798c2ecf20Sopenharmony_ci} 13808c2ecf20Sopenharmony_ci 13818c2ecf20Sopenharmony_ci/* 13828c2ecf20Sopenharmony_ci * i5400_remove_one destructor for one instance of device 13838c2ecf20Sopenharmony_ci * 13848c2ecf20Sopenharmony_ci */ 13858c2ecf20Sopenharmony_cistatic void i5400_remove_one(struct pci_dev *pdev) 13868c2ecf20Sopenharmony_ci{ 13878c2ecf20Sopenharmony_ci struct mem_ctl_info *mci; 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_ci edac_dbg(0, "\n"); 13908c2ecf20Sopenharmony_ci 13918c2ecf20Sopenharmony_ci if (i5400_pci) 13928c2ecf20Sopenharmony_ci edac_pci_release_generic_ctl(i5400_pci); 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_ci mci = edac_mc_del_mc(&pdev->dev); 13958c2ecf20Sopenharmony_ci if (!mci) 13968c2ecf20Sopenharmony_ci return; 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci /* retrieve references to resources, and free those resources */ 13998c2ecf20Sopenharmony_ci i5400_put_devices(mci); 14008c2ecf20Sopenharmony_ci 14018c2ecf20Sopenharmony_ci pci_disable_device(pdev); 14028c2ecf20Sopenharmony_ci 14038c2ecf20Sopenharmony_ci edac_mc_free(mci); 14048c2ecf20Sopenharmony_ci} 14058c2ecf20Sopenharmony_ci 14068c2ecf20Sopenharmony_ci/* 14078c2ecf20Sopenharmony_ci * pci_device_id table for which devices we are looking for 14088c2ecf20Sopenharmony_ci * 14098c2ecf20Sopenharmony_ci * The "E500P" device is the first device supported. 14108c2ecf20Sopenharmony_ci */ 14118c2ecf20Sopenharmony_cistatic const struct pci_device_id i5400_pci_tbl[] = { 14128c2ecf20Sopenharmony_ci {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)}, 14138c2ecf20Sopenharmony_ci {0,} /* 0 terminated list. */ 14148c2ecf20Sopenharmony_ci}; 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, i5400_pci_tbl); 14178c2ecf20Sopenharmony_ci 14188c2ecf20Sopenharmony_ci/* 14198c2ecf20Sopenharmony_ci * i5400_driver pci_driver structure for this module 14208c2ecf20Sopenharmony_ci * 14218c2ecf20Sopenharmony_ci */ 14228c2ecf20Sopenharmony_cistatic struct pci_driver i5400_driver = { 14238c2ecf20Sopenharmony_ci .name = "i5400_edac", 14248c2ecf20Sopenharmony_ci .probe = i5400_init_one, 14258c2ecf20Sopenharmony_ci .remove = i5400_remove_one, 14268c2ecf20Sopenharmony_ci .id_table = i5400_pci_tbl, 14278c2ecf20Sopenharmony_ci}; 14288c2ecf20Sopenharmony_ci 14298c2ecf20Sopenharmony_ci/* 14308c2ecf20Sopenharmony_ci * i5400_init Module entry function 14318c2ecf20Sopenharmony_ci * Try to initialize this module for its devices 14328c2ecf20Sopenharmony_ci */ 14338c2ecf20Sopenharmony_cistatic int __init i5400_init(void) 14348c2ecf20Sopenharmony_ci{ 14358c2ecf20Sopenharmony_ci int pci_rc; 14368c2ecf20Sopenharmony_ci 14378c2ecf20Sopenharmony_ci edac_dbg(2, "MC:\n"); 14388c2ecf20Sopenharmony_ci 14398c2ecf20Sopenharmony_ci /* Ensure that the OPSTATE is set correctly for POLL or NMI */ 14408c2ecf20Sopenharmony_ci opstate_init(); 14418c2ecf20Sopenharmony_ci 14428c2ecf20Sopenharmony_ci pci_rc = pci_register_driver(&i5400_driver); 14438c2ecf20Sopenharmony_ci 14448c2ecf20Sopenharmony_ci return (pci_rc < 0) ? pci_rc : 0; 14458c2ecf20Sopenharmony_ci} 14468c2ecf20Sopenharmony_ci 14478c2ecf20Sopenharmony_ci/* 14488c2ecf20Sopenharmony_ci * i5400_exit() Module exit function 14498c2ecf20Sopenharmony_ci * Unregister the driver 14508c2ecf20Sopenharmony_ci */ 14518c2ecf20Sopenharmony_cistatic void __exit i5400_exit(void) 14528c2ecf20Sopenharmony_ci{ 14538c2ecf20Sopenharmony_ci edac_dbg(2, "MC:\n"); 14548c2ecf20Sopenharmony_ci pci_unregister_driver(&i5400_driver); 14558c2ecf20Sopenharmony_ci} 14568c2ecf20Sopenharmony_ci 14578c2ecf20Sopenharmony_cimodule_init(i5400_init); 14588c2ecf20Sopenharmony_cimodule_exit(i5400_exit); 14598c2ecf20Sopenharmony_ci 14608c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 14618c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ben Woodard <woodard@redhat.com>"); 14628c2ecf20Sopenharmony_ciMODULE_AUTHOR("Mauro Carvalho Chehab"); 14638c2ecf20Sopenharmony_ciMODULE_AUTHOR("Red Hat Inc. (https://www.redhat.com)"); 14648c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MC Driver for Intel I5400 memory controllers - " 14658c2ecf20Sopenharmony_ci I5400_REVISION); 14668c2ecf20Sopenharmony_ci 14678c2ecf20Sopenharmony_cimodule_param(edac_op_state, int, 0444); 14688c2ecf20Sopenharmony_ciMODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); 1469