Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Intel e752x Memory Controller kernel module
0003  * (C) 2004 Linux Networx (http://lnxi.com)
0004  * This file may be distributed under the terms of the
0005  * GNU General Public License.
0006  *
0007  * Implement support for the e7520, E7525, e7320 and i3100 memory controllers.
0008  *
0009  * Datasheets:
0010  *  https://www.intel.in/content/www/in/en/chipsets/e7525-memory-controller-hub-datasheet.html
0011  *  ftp://download.intel.com/design/intarch/datashts/31345803.pdf
0012  *
0013  * Written by Tom Zimmerman
0014  *
0015  * Contributors:
0016  *  Thayne Harbaugh at realmsys.com (?)
0017  *  Wang Zhenyu at intel.com
0018  *  Dave Jiang at mvista.com
0019  *
0020  */
0021 
0022 #include <linux/module.h>
0023 #include <linux/init.h>
0024 #include <linux/pci.h>
0025 #include <linux/pci_ids.h>
0026 #include <linux/edac.h>
0027 #include "edac_module.h"
0028 
0029 #define EDAC_MOD_STR    "e752x_edac"
0030 
0031 static int report_non_memory_errors;
0032 static int force_function_unhide;
0033 static int sysbus_parity = -1;
0034 
0035 static struct edac_pci_ctl_info *e752x_pci;
0036 
0037 #define e752x_printk(level, fmt, arg...) \
0038     edac_printk(level, "e752x", fmt, ##arg)
0039 
0040 #define e752x_mc_printk(mci, level, fmt, arg...) \
0041     edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
0042 
0043 #ifndef PCI_DEVICE_ID_INTEL_7520_0
0044 #define PCI_DEVICE_ID_INTEL_7520_0      0x3590
0045 #endif              /* PCI_DEVICE_ID_INTEL_7520_0      */
0046 
0047 #ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
0048 #define PCI_DEVICE_ID_INTEL_7520_1_ERR  0x3591
0049 #endif              /* PCI_DEVICE_ID_INTEL_7520_1_ERR  */
0050 
0051 #ifndef PCI_DEVICE_ID_INTEL_7525_0
0052 #define PCI_DEVICE_ID_INTEL_7525_0      0x359E
0053 #endif              /* PCI_DEVICE_ID_INTEL_7525_0      */
0054 
0055 #ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
0056 #define PCI_DEVICE_ID_INTEL_7525_1_ERR  0x3593
0057 #endif              /* PCI_DEVICE_ID_INTEL_7525_1_ERR  */
0058 
0059 #ifndef PCI_DEVICE_ID_INTEL_7320_0
0060 #define PCI_DEVICE_ID_INTEL_7320_0  0x3592
0061 #endif              /* PCI_DEVICE_ID_INTEL_7320_0 */
0062 
0063 #ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
0064 #define PCI_DEVICE_ID_INTEL_7320_1_ERR  0x3593
0065 #endif              /* PCI_DEVICE_ID_INTEL_7320_1_ERR */
0066 
0067 #ifndef PCI_DEVICE_ID_INTEL_3100_0
0068 #define PCI_DEVICE_ID_INTEL_3100_0  0x35B0
0069 #endif              /* PCI_DEVICE_ID_INTEL_3100_0 */
0070 
0071 #ifndef PCI_DEVICE_ID_INTEL_3100_1_ERR
0072 #define PCI_DEVICE_ID_INTEL_3100_1_ERR  0x35B1
0073 #endif              /* PCI_DEVICE_ID_INTEL_3100_1_ERR */
0074 
0075 #define E752X_NR_CSROWS     8   /* number of csrows */
0076 
0077 /* E752X register addresses - device 0 function 0 */
0078 #define E752X_MCHSCRB       0x52    /* Memory Scrub register (16b) */
0079                     /*
0080                      * 6:5     Scrub Completion Count
0081                      * 3:2     Scrub Rate (i3100 only)
0082                      *      01=fast 10=normal
0083                      * 1:0     Scrub Mode enable
0084                      *      00=off 10=on
0085                      */
0086 #define E752X_DRB       0x60    /* DRAM row boundary register (8b) */
0087 #define E752X_DRA       0x70    /* DRAM row attribute register (8b) */
0088                     /*
0089                      * 31:30   Device width row 7
0090                      *      01=x8 10=x4 11=x8 DDR2
0091                      * 27:26   Device width row 6
0092                      * 23:22   Device width row 5
0093                      * 19:20   Device width row 4
0094                      * 15:14   Device width row 3
0095                      * 11:10   Device width row 2
0096                      *  7:6    Device width row 1
0097                      *  3:2    Device width row 0
0098                      */
0099 #define E752X_DRC       0x7C    /* DRAM controller mode reg (32b) */
0100                     /* FIXME:IS THIS RIGHT? */
0101                     /*
0102                      * 22    Number channels 0=1,1=2
0103                      * 19:18 DRB Granularity 32/64MB
0104                      */
0105 #define E752X_DRM       0x80    /* Dimm mapping register */
0106 #define E752X_DDRCSR        0x9A    /* DDR control and status reg (16b) */
0107                     /*
0108                      * 14:12 1 single A, 2 single B, 3 dual
0109                      */
0110 #define E752X_TOLM      0xC4    /* DRAM top of low memory reg (16b) */
0111 #define E752X_REMAPBASE     0xC6    /* DRAM remap base address reg (16b) */
0112 #define E752X_REMAPLIMIT    0xC8    /* DRAM remap limit address reg (16b) */
0113 #define E752X_REMAPOFFSET   0xCA    /* DRAM remap limit offset reg (16b) */
0114 
0115 /* E752X register addresses - device 0 function 1 */
0116 #define E752X_FERR_GLOBAL   0x40    /* Global first error register (32b) */
0117 #define E752X_NERR_GLOBAL   0x44    /* Global next error register (32b) */
0118 #define E752X_HI_FERR       0x50    /* Hub interface first error reg (8b) */
0119 #define E752X_HI_NERR       0x52    /* Hub interface next error reg (8b) */
0120 #define E752X_HI_ERRMASK    0x54    /* Hub interface error mask reg (8b) */
0121 #define E752X_HI_SMICMD     0x5A    /* Hub interface SMI command reg (8b) */
0122 #define E752X_SYSBUS_FERR   0x60    /* System buss first error reg (16b) */
0123 #define E752X_SYSBUS_NERR   0x62    /* System buss next error reg (16b) */
0124 #define E752X_SYSBUS_ERRMASK    0x64    /* System buss error mask reg (16b) */
0125 #define E752X_SYSBUS_SMICMD 0x6A    /* System buss SMI command reg (16b) */
0126 #define E752X_BUF_FERR      0x70    /* Memory buffer first error reg (8b) */
0127 #define E752X_BUF_NERR      0x72    /* Memory buffer next error reg (8b) */
0128 #define E752X_BUF_ERRMASK   0x74    /* Memory buffer error mask reg (8b) */
0129 #define E752X_BUF_SMICMD    0x7A    /* Memory buffer SMI cmd reg (8b) */
0130 #define E752X_DRAM_FERR     0x80    /* DRAM first error register (16b) */
0131 #define E752X_DRAM_NERR     0x82    /* DRAM next error register (16b) */
0132 #define E752X_DRAM_ERRMASK  0x84    /* DRAM error mask register (8b) */
0133 #define E752X_DRAM_SMICMD   0x8A    /* DRAM SMI command register (8b) */
0134 #define E752X_DRAM_RETR_ADD 0xAC    /* DRAM Retry address register (32b) */
0135 #define E752X_DRAM_SEC1_ADD 0xA0    /* DRAM first correctable memory */
0136                     /*     error address register (32b) */
0137                     /*
0138                      * 31    Reserved
0139                      * 30:2  CE address (64 byte block 34:6
0140                      * 1     Reserved
0141                      * 0     HiLoCS
0142                      */
0143 #define E752X_DRAM_SEC2_ADD 0xC8    /* DRAM first correctable memory */
0144                     /*     error address register (32b) */
0145                     /*
0146                      * 31    Reserved
0147                      * 30:2  CE address (64 byte block 34:6)
0148                      * 1     Reserved
0149                      * 0     HiLoCS
0150                      */
0151 #define E752X_DRAM_DED_ADD  0xA4    /* DRAM first uncorrectable memory */
0152                     /*     error address register (32b) */
0153                     /*
0154                      * 31    Reserved
0155                      * 30:2  CE address (64 byte block 34:6)
0156                      * 1     Reserved
0157                      * 0     HiLoCS
0158                      */
0159 #define E752X_DRAM_SCRB_ADD 0xA8    /* DRAM 1st uncorrectable scrub mem */
0160                     /*     error address register (32b) */
0161                     /*
0162                      * 31    Reserved
0163                      * 30:2  CE address (64 byte block 34:6
0164                      * 1     Reserved
0165                      * 0     HiLoCS
0166                      */
0167 #define E752X_DRAM_SEC1_SYNDROME 0xC4   /* DRAM first correctable memory */
0168                     /*     error syndrome register (16b) */
0169 #define E752X_DRAM_SEC2_SYNDROME 0xC6   /* DRAM second correctable memory */
0170                     /*     error syndrome register (16b) */
0171 #define E752X_DEVPRES1      0xF4    /* Device Present 1 register (8b) */
0172 
0173 /* 3100 IMCH specific register addresses - device 0 function 1 */
0174 #define I3100_NSI_FERR      0x48    /* NSI first error reg (32b) */
0175 #define I3100_NSI_NERR      0x4C    /* NSI next error reg (32b) */
0176 #define I3100_NSI_SMICMD    0x54    /* NSI SMI command register (32b) */
0177 #define I3100_NSI_EMASK     0x90    /* NSI error mask register (32b) */
0178 
0179 /* ICH5R register addresses - device 30 function 0 */
0180 #define ICH5R_PCI_STAT      0x06    /* PCI status register (16b) */
0181 #define ICH5R_PCI_2ND_STAT  0x1E    /* PCI status secondary reg (16b) */
0182 #define ICH5R_PCI_BRIDGE_CTL    0x3E    /* PCI bridge control register (16b) */
0183 
0184 enum e752x_chips {
0185     E7520 = 0,
0186     E7525 = 1,
0187     E7320 = 2,
0188     I3100 = 3
0189 };
0190 
0191 /*
0192  * Those chips Support single-rank and dual-rank memories only.
0193  *
0194  * On e752x chips, the odd rows are present only on dual-rank memories.
0195  * Dividing the rank by two will provide the dimm#
0196  *
0197  * i3100 MC has a different mapping: it supports only 4 ranks.
0198  *
0199  * The mapping is (from 1 to n):
0200  *  slot       single-ranked    double-ranked
0201  *  dimm #1 -> rank #4      NA
0202  *  dimm #2 -> rank #3      NA
0203  *  dimm #3 -> rank #2      Ranks 2 and 3
0204  *  dimm #4 -> rank $1      Ranks 1 and 4
0205  *
0206  * FIXME: The current mapping for i3100 considers that it supports up to 8
0207  *    ranks/chanel, but datasheet says that the MC supports only 4 ranks.
0208  */
0209 
0210 struct e752x_pvt {
0211     struct pci_dev *dev_d0f0;
0212     struct pci_dev *dev_d0f1;
0213     u32 tolm;
0214     u32 remapbase;
0215     u32 remaplimit;
0216     int mc_symmetric;
0217     u8 map[8];
0218     int map_type;
0219     const struct e752x_dev_info *dev_info;
0220 };
0221 
0222 struct e752x_dev_info {
0223     u16 err_dev;
0224     u16 ctl_dev;
0225     const char *ctl_name;
0226 };
0227 
0228 struct e752x_error_info {
0229     u32 ferr_global;
0230     u32 nerr_global;
0231     u32 nsi_ferr;   /* 3100 only */
0232     u32 nsi_nerr;   /* 3100 only */
0233     u8 hi_ferr; /* all but 3100 */
0234     u8 hi_nerr; /* all but 3100 */
0235     u16 sysbus_ferr;
0236     u16 sysbus_nerr;
0237     u8 buf_ferr;
0238     u8 buf_nerr;
0239     u16 dram_ferr;
0240     u16 dram_nerr;
0241     u32 dram_sec1_add;
0242     u32 dram_sec2_add;
0243     u16 dram_sec1_syndrome;
0244     u16 dram_sec2_syndrome;
0245     u32 dram_ded_add;
0246     u32 dram_scrb_add;
0247     u32 dram_retr_add;
0248 };
0249 
0250 static const struct e752x_dev_info e752x_devs[] = {
0251     [E7520] = {
0252         .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
0253         .ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
0254         .ctl_name = "E7520"},
0255     [E7525] = {
0256         .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
0257         .ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
0258         .ctl_name = "E7525"},
0259     [E7320] = {
0260         .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
0261         .ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
0262         .ctl_name = "E7320"},
0263     [I3100] = {
0264         .err_dev = PCI_DEVICE_ID_INTEL_3100_1_ERR,
0265         .ctl_dev = PCI_DEVICE_ID_INTEL_3100_0,
0266         .ctl_name = "3100"},
0267 };
0268 
0269 /* Valid scrub rates for the e752x/3100 hardware memory scrubber. We
0270  * map the scrubbing bandwidth to a hardware register value. The 'set'
0271  * operation finds the 'matching or higher value'.  Note that scrubbing
0272  * on the e752x can only be enabled/disabled.  The 3100 supports
0273  * a normal and fast mode.
0274  */
0275 
0276 #define SDRATE_EOT 0xFFFFFFFF
0277 
0278 struct scrubrate {
0279     u32 bandwidth;  /* bandwidth consumed by scrubbing in bytes/sec */
0280     u16 scrubval;   /* register value for scrub rate */
0281 };
0282 
0283 /* Rate below assumes same performance as i3100 using PC3200 DDR2 in
0284  * normal mode.  e752x bridges don't support choosing normal or fast mode,
0285  * so the scrubbing bandwidth value isn't all that important - scrubbing is
0286  * either on or off.
0287  */
0288 static const struct scrubrate scrubrates_e752x[] = {
0289     {0,     0x00},  /* Scrubbing Off */
0290     {500000,    0x02},  /* Scrubbing On */
0291     {SDRATE_EOT,    0x00}   /* End of Table */
0292 };
0293 
0294 /* Fast mode: 2 GByte PC3200 DDR2 scrubbed in 33s = 63161283 bytes/s
0295  * Normal mode: 125 (32000 / 256) times slower than fast mode.
0296  */
0297 static const struct scrubrate scrubrates_i3100[] = {
0298     {0,     0x00},  /* Scrubbing Off */
0299     {500000,    0x0a},  /* Normal mode - 32k clocks */
0300     {62500000,  0x06},  /* Fast mode - 256 clocks */
0301     {SDRATE_EOT,    0x00}   /* End of Table */
0302 };
0303 
0304 static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
0305                 unsigned long page)
0306 {
0307     u32 remap;
0308     struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
0309 
0310     edac_dbg(3, "\n");
0311 
0312     if (page < pvt->tolm)
0313         return page;
0314 
0315     if ((page >= 0x100000) && (page < pvt->remapbase))
0316         return page;
0317 
0318     remap = (page - pvt->tolm) + pvt->remapbase;
0319 
0320     if (remap < pvt->remaplimit)
0321         return remap;
0322 
0323     e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
0324     return pvt->tolm - 1;
0325 }
0326 
0327 static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
0328             u32 sec1_add, u16 sec1_syndrome)
0329 {
0330     u32 page;
0331     int row;
0332     int channel;
0333     int i;
0334     struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
0335 
0336     edac_dbg(3, "\n");
0337 
0338     /* convert the addr to 4k page */
0339     page = sec1_add >> (PAGE_SHIFT - 4);
0340 
0341     /* FIXME - check for -1 */
0342     if (pvt->mc_symmetric) {
0343         /* chip select are bits 14 & 13 */
0344         row = ((page >> 1) & 3);
0345         e752x_printk(KERN_WARNING,
0346             "Test row %d Table %d %d %d %d %d %d %d %d\n", row,
0347             pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
0348             pvt->map[4], pvt->map[5], pvt->map[6],
0349             pvt->map[7]);
0350 
0351         /* test for channel remapping */
0352         for (i = 0; i < 8; i++) {
0353             if (pvt->map[i] == row)
0354                 break;
0355         }
0356 
0357         e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
0358 
0359         if (i < 8)
0360             row = i;
0361         else
0362             e752x_mc_printk(mci, KERN_WARNING,
0363                     "row %d not found in remap table\n",
0364                     row);
0365     } else
0366         row = edac_mc_find_csrow_by_page(mci, page);
0367 
0368     /* 0 = channel A, 1 = channel B */
0369     channel = !(error_one & 1);
0370 
0371     /* e752x mc reads 34:6 of the DRAM linear address */
0372     edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
0373                  page, offset_in_page(sec1_add << 4), sec1_syndrome,
0374                  row, channel, -1,
0375                  "e752x CE", "");
0376 }
0377 
0378 static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
0379             u32 sec1_add, u16 sec1_syndrome, int *error_found,
0380             int handle_error)
0381 {
0382     *error_found = 1;
0383 
0384     if (handle_error)
0385         do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
0386 }
0387 
0388 static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
0389             u32 ded_add, u32 scrb_add)
0390 {
0391     u32 error_2b, block_page;
0392     int row;
0393     struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
0394 
0395     edac_dbg(3, "\n");
0396 
0397     if (error_one & 0x0202) {
0398         error_2b = ded_add;
0399 
0400         /* convert to 4k address */
0401         block_page = error_2b >> (PAGE_SHIFT - 4);
0402 
0403         row = pvt->mc_symmetric ?
0404         /* chip select are bits 14 & 13 */
0405             ((block_page >> 1) & 3) :
0406             edac_mc_find_csrow_by_page(mci, block_page);
0407 
0408         /* e752x mc reads 34:6 of the DRAM linear address */
0409         edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
0410                     block_page,
0411                     offset_in_page(error_2b << 4), 0,
0412                      row, -1, -1,
0413                     "e752x UE from Read", "");
0414 
0415     }
0416     if (error_one & 0x0404) {
0417         error_2b = scrb_add;
0418 
0419         /* convert to 4k address */
0420         block_page = error_2b >> (PAGE_SHIFT - 4);
0421 
0422         row = pvt->mc_symmetric ?
0423         /* chip select are bits 14 & 13 */
0424             ((block_page >> 1) & 3) :
0425             edac_mc_find_csrow_by_page(mci, block_page);
0426 
0427         /* e752x mc reads 34:6 of the DRAM linear address */
0428         edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
0429                     block_page,
0430                     offset_in_page(error_2b << 4), 0,
0431                     row, -1, -1,
0432                     "e752x UE from Scruber", "");
0433     }
0434 }
0435 
0436 static inline void process_ue(struct mem_ctl_info *mci, u16 error_one,
0437             u32 ded_add, u32 scrb_add, int *error_found,
0438             int handle_error)
0439 {
0440     *error_found = 1;
0441 
0442     if (handle_error)
0443         do_process_ue(mci, error_one, ded_add, scrb_add);
0444 }
0445 
0446 static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
0447                      int *error_found, int handle_error)
0448 {
0449     *error_found = 1;
0450 
0451     if (!handle_error)
0452         return;
0453 
0454     edac_dbg(3, "\n");
0455     edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
0456                  -1, -1, -1,
0457                  "e752x UE log memory write", "");
0458 }
0459 
0460 static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
0461                  u32 retry_add)
0462 {
0463     u32 error_1b, page;
0464     int row;
0465     struct e752x_pvt *pvt = (struct e752x_pvt *)mci->pvt_info;
0466 
0467     error_1b = retry_add;
0468     page = error_1b >> (PAGE_SHIFT - 4);  /* convert the addr to 4k page */
0469 
0470     /* chip select are bits 14 & 13 */
0471     row = pvt->mc_symmetric ? ((page >> 1) & 3) :
0472         edac_mc_find_csrow_by_page(mci, page);
0473 
0474     e752x_mc_printk(mci, KERN_WARNING,
0475             "CE page 0x%lx, row %d : Memory read retry\n",
0476             (long unsigned int)page, row);
0477 }
0478 
0479 static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
0480                 u32 retry_add, int *error_found,
0481                 int handle_error)
0482 {
0483     *error_found = 1;
0484 
0485     if (handle_error)
0486         do_process_ded_retry(mci, error, retry_add);
0487 }
0488 
0489 static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
0490                     int *error_found, int handle_error)
0491 {
0492     *error_found = 1;
0493 
0494     if (handle_error)
0495         e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
0496 }
0497 
0498 static char *global_message[11] = {
0499     "PCI Express C1",
0500     "PCI Express C",
0501     "PCI Express B1",
0502     "PCI Express B",
0503     "PCI Express A1",
0504     "PCI Express A",
0505     "DMA Controller",
0506     "HUB or NS Interface",
0507     "System Bus",
0508     "DRAM Controller",  /* 9th entry */
0509     "Internal Buffer"
0510 };
0511 
0512 #define DRAM_ENTRY  9
0513 
0514 static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
0515 
0516 static void do_global_error(int fatal, u32 errors)
0517 {
0518     int i;
0519 
0520     for (i = 0; i < 11; i++) {
0521         if (errors & (1 << i)) {
0522             /* If the error is from DRAM Controller OR
0523              * we are to report ALL errors, then
0524              * report the error
0525              */
0526             if ((i == DRAM_ENTRY) || report_non_memory_errors)
0527                 e752x_printk(KERN_WARNING, "%sError %s\n",
0528                     fatal_message[fatal],
0529                     global_message[i]);
0530         }
0531     }
0532 }
0533 
0534 static inline void global_error(int fatal, u32 errors, int *error_found,
0535                 int handle_error)
0536 {
0537     *error_found = 1;
0538 
0539     if (handle_error)
0540         do_global_error(fatal, errors);
0541 }
0542 
0543 static char *hub_message[7] = {
0544     "HI Address or Command Parity", "HI Illegal Access",
0545     "HI Internal Parity", "Out of Range Access",
0546     "HI Data Parity", "Enhanced Config Access",
0547     "Hub Interface Target Abort"
0548 };
0549 
0550 static void do_hub_error(int fatal, u8 errors)
0551 {
0552     int i;
0553 
0554     for (i = 0; i < 7; i++) {
0555         if (errors & (1 << i))
0556             e752x_printk(KERN_WARNING, "%sError %s\n",
0557                 fatal_message[fatal], hub_message[i]);
0558     }
0559 }
0560 
0561 static inline void hub_error(int fatal, u8 errors, int *error_found,
0562             int handle_error)
0563 {
0564     *error_found = 1;
0565 
0566     if (handle_error)
0567         do_hub_error(fatal, errors);
0568 }
0569 
0570 #define NSI_FATAL_MASK      0x0c080081
0571 #define NSI_NON_FATAL_MASK  0x23a0ba64
0572 #define NSI_ERR_MASK        (NSI_FATAL_MASK | NSI_NON_FATAL_MASK)
0573 
0574 static char *nsi_message[30] = {
0575     "NSI Link Down",    /* NSI_FERR/NSI_NERR bit 0, fatal error */
0576     "",                     /* reserved */
0577     "NSI Parity Error",             /* bit 2, non-fatal */
0578     "",                     /* reserved */
0579     "",                     /* reserved */
0580     "Correctable Error Message",            /* bit 5, non-fatal */
0581     "Non-Fatal Error Message",          /* bit 6, non-fatal */
0582     "Fatal Error Message",              /* bit 7, fatal */
0583     "",                     /* reserved */
0584     "Receiver Error",               /* bit 9, non-fatal */
0585     "",                     /* reserved */
0586     "Bad TLP",                  /* bit 11, non-fatal */
0587     "Bad DLLP",                 /* bit 12, non-fatal */
0588     "REPLAY_NUM Rollover",              /* bit 13, non-fatal */
0589     "",                     /* reserved */
0590     "Replay Timer Timeout",             /* bit 15, non-fatal */
0591     "",                     /* reserved */
0592     "",                     /* reserved */
0593     "",                     /* reserved */
0594     "Data Link Protocol Error",         /* bit 19, fatal */
0595     "",                     /* reserved */
0596     "Poisoned TLP",                 /* bit 21, non-fatal */
0597     "",                     /* reserved */
0598     "Completion Timeout",               /* bit 23, non-fatal */
0599     "Completer Abort",              /* bit 24, non-fatal */
0600     "Unexpected Completion",            /* bit 25, non-fatal */
0601     "Receiver Overflow",                /* bit 26, fatal */
0602     "Malformed TLP",                /* bit 27, fatal */
0603     "",                     /* reserved */
0604     "Unsupported Request"               /* bit 29, non-fatal */
0605 };
0606 
0607 static void do_nsi_error(int fatal, u32 errors)
0608 {
0609     int i;
0610 
0611     for (i = 0; i < 30; i++) {
0612         if (errors & (1 << i))
0613             printk(KERN_WARNING "%sError %s\n",
0614                    fatal_message[fatal], nsi_message[i]);
0615     }
0616 }
0617 
0618 static inline void nsi_error(int fatal, u32 errors, int *error_found,
0619         int handle_error)
0620 {
0621     *error_found = 1;
0622 
0623     if (handle_error)
0624         do_nsi_error(fatal, errors);
0625 }
0626 
0627 static char *membuf_message[4] = {
0628     "Internal PMWB to DRAM parity",
0629     "Internal PMWB to System Bus Parity",
0630     "Internal System Bus or IO to PMWB Parity",
0631     "Internal DRAM to PMWB Parity"
0632 };
0633 
0634 static void do_membuf_error(u8 errors)
0635 {
0636     int i;
0637 
0638     for (i = 0; i < 4; i++) {
0639         if (errors & (1 << i))
0640             e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
0641                 membuf_message[i]);
0642     }
0643 }
0644 
0645 static inline void membuf_error(u8 errors, int *error_found, int handle_error)
0646 {
0647     *error_found = 1;
0648 
0649     if (handle_error)
0650         do_membuf_error(errors);
0651 }
0652 
0653 static char *sysbus_message[10] = {
0654     "Addr or Request Parity",
0655     "Data Strobe Glitch",
0656     "Addr Strobe Glitch",
0657     "Data Parity",
0658     "Addr Above TOM",
0659     "Non DRAM Lock Error",
0660     "MCERR", "BINIT",
0661     "Memory Parity",
0662     "IO Subsystem Parity"
0663 };
0664 
0665 static void do_sysbus_error(int fatal, u32 errors)
0666 {
0667     int i;
0668 
0669     for (i = 0; i < 10; i++) {
0670         if (errors & (1 << i))
0671             e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
0672                 fatal_message[fatal], sysbus_message[i]);
0673     }
0674 }
0675 
0676 static inline void sysbus_error(int fatal, u32 errors, int *error_found,
0677                 int handle_error)
0678 {
0679     *error_found = 1;
0680 
0681     if (handle_error)
0682         do_sysbus_error(fatal, errors);
0683 }
0684 
0685 static void e752x_check_hub_interface(struct e752x_error_info *info,
0686                 int *error_found, int handle_error)
0687 {
0688     u8 stat8;
0689 
0690     //pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
0691 
0692     stat8 = info->hi_ferr;
0693 
0694     if (stat8 & 0x7f) { /* Error, so process */
0695         stat8 &= 0x7f;
0696 
0697         if (stat8 & 0x2b)
0698             hub_error(1, stat8 & 0x2b, error_found, handle_error);
0699 
0700         if (stat8 & 0x54)
0701             hub_error(0, stat8 & 0x54, error_found, handle_error);
0702     }
0703     //pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
0704 
0705     stat8 = info->hi_nerr;
0706 
0707     if (stat8 & 0x7f) { /* Error, so process */
0708         stat8 &= 0x7f;
0709 
0710         if (stat8 & 0x2b)
0711             hub_error(1, stat8 & 0x2b, error_found, handle_error);
0712 
0713         if (stat8 & 0x54)
0714             hub_error(0, stat8 & 0x54, error_found, handle_error);
0715     }
0716 }
0717 
0718 static void e752x_check_ns_interface(struct e752x_error_info *info,
0719                 int *error_found, int handle_error)
0720 {
0721     u32 stat32;
0722 
0723     stat32 = info->nsi_ferr;
0724     if (stat32 & NSI_ERR_MASK) { /* Error, so process */
0725         if (stat32 & NSI_FATAL_MASK)    /* check for fatal errors */
0726             nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
0727                   handle_error);
0728         if (stat32 & NSI_NON_FATAL_MASK) /* check for non-fatal ones */
0729             nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
0730                   handle_error);
0731     }
0732     stat32 = info->nsi_nerr;
0733     if (stat32 & NSI_ERR_MASK) {
0734         if (stat32 & NSI_FATAL_MASK)
0735             nsi_error(1, stat32 & NSI_FATAL_MASK, error_found,
0736                   handle_error);
0737         if (stat32 & NSI_NON_FATAL_MASK)
0738             nsi_error(0, stat32 & NSI_NON_FATAL_MASK, error_found,
0739                   handle_error);
0740     }
0741 }
0742 
0743 static void e752x_check_sysbus(struct e752x_error_info *info,
0744             int *error_found, int handle_error)
0745 {
0746     u32 stat32, error32;
0747 
0748     //pci_read_config_dword(dev,E752X_SYSBUS_FERR,&stat32);
0749     stat32 = info->sysbus_ferr + (info->sysbus_nerr << 16);
0750 
0751     if (stat32 == 0)
0752         return;     /* no errors */
0753 
0754     error32 = (stat32 >> 16) & 0x3ff;
0755     stat32 = stat32 & 0x3ff;
0756 
0757     if (stat32 & 0x087)
0758         sysbus_error(1, stat32 & 0x087, error_found, handle_error);
0759 
0760     if (stat32 & 0x378)
0761         sysbus_error(0, stat32 & 0x378, error_found, handle_error);
0762 
0763     if (error32 & 0x087)
0764         sysbus_error(1, error32 & 0x087, error_found, handle_error);
0765 
0766     if (error32 & 0x378)
0767         sysbus_error(0, error32 & 0x378, error_found, handle_error);
0768 }
0769 
0770 static void e752x_check_membuf(struct e752x_error_info *info,
0771             int *error_found, int handle_error)
0772 {
0773     u8 stat8;
0774 
0775     stat8 = info->buf_ferr;
0776 
0777     if (stat8 & 0x0f) { /* Error, so process */
0778         stat8 &= 0x0f;
0779         membuf_error(stat8, error_found, handle_error);
0780     }
0781 
0782     stat8 = info->buf_nerr;
0783 
0784     if (stat8 & 0x0f) { /* Error, so process */
0785         stat8 &= 0x0f;
0786         membuf_error(stat8, error_found, handle_error);
0787     }
0788 }
0789 
0790 static void e752x_check_dram(struct mem_ctl_info *mci,
0791             struct e752x_error_info *info, int *error_found,
0792             int handle_error)
0793 {
0794     u16 error_one, error_next;
0795 
0796     error_one = info->dram_ferr;
0797     error_next = info->dram_nerr;
0798 
0799     /* decode and report errors */
0800     if (error_one & 0x0101) /* check first error correctable */
0801         process_ce(mci, error_one, info->dram_sec1_add,
0802             info->dram_sec1_syndrome, error_found, handle_error);
0803 
0804     if (error_next & 0x0101)    /* check next error correctable */
0805         process_ce(mci, error_next, info->dram_sec2_add,
0806             info->dram_sec2_syndrome, error_found, handle_error);
0807 
0808     if (error_one & 0x4040)
0809         process_ue_no_info_wr(mci, error_found, handle_error);
0810 
0811     if (error_next & 0x4040)
0812         process_ue_no_info_wr(mci, error_found, handle_error);
0813 
0814     if (error_one & 0x2020)
0815         process_ded_retry(mci, error_one, info->dram_retr_add,
0816                 error_found, handle_error);
0817 
0818     if (error_next & 0x2020)
0819         process_ded_retry(mci, error_next, info->dram_retr_add,
0820                 error_found, handle_error);
0821 
0822     if (error_one & 0x0808)
0823         process_threshold_ce(mci, error_one, error_found, handle_error);
0824 
0825     if (error_next & 0x0808)
0826         process_threshold_ce(mci, error_next, error_found,
0827                 handle_error);
0828 
0829     if (error_one & 0x0606)
0830         process_ue(mci, error_one, info->dram_ded_add,
0831             info->dram_scrb_add, error_found, handle_error);
0832 
0833     if (error_next & 0x0606)
0834         process_ue(mci, error_next, info->dram_ded_add,
0835             info->dram_scrb_add, error_found, handle_error);
0836 }
0837 
0838 static void e752x_get_error_info(struct mem_ctl_info *mci,
0839                  struct e752x_error_info *info)
0840 {
0841     struct pci_dev *dev;
0842     struct e752x_pvt *pvt;
0843 
0844     memset(info, 0, sizeof(*info));
0845     pvt = (struct e752x_pvt *)mci->pvt_info;
0846     dev = pvt->dev_d0f1;
0847     pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);
0848 
0849     if (info->ferr_global) {
0850         if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
0851             pci_read_config_dword(dev, I3100_NSI_FERR,
0852                          &info->nsi_ferr);
0853             info->hi_ferr = 0;
0854         } else {
0855             pci_read_config_byte(dev, E752X_HI_FERR,
0856                          &info->hi_ferr);
0857             info->nsi_ferr = 0;
0858         }
0859         pci_read_config_word(dev, E752X_SYSBUS_FERR,
0860                 &info->sysbus_ferr);
0861         pci_read_config_byte(dev, E752X_BUF_FERR, &info->buf_ferr);
0862         pci_read_config_word(dev, E752X_DRAM_FERR, &info->dram_ferr);
0863         pci_read_config_dword(dev, E752X_DRAM_SEC1_ADD,
0864                 &info->dram_sec1_add);
0865         pci_read_config_word(dev, E752X_DRAM_SEC1_SYNDROME,
0866                 &info->dram_sec1_syndrome);
0867         pci_read_config_dword(dev, E752X_DRAM_DED_ADD,
0868                 &info->dram_ded_add);
0869         pci_read_config_dword(dev, E752X_DRAM_SCRB_ADD,
0870                 &info->dram_scrb_add);
0871         pci_read_config_dword(dev, E752X_DRAM_RETR_ADD,
0872                 &info->dram_retr_add);
0873 
0874         /* ignore the reserved bits just in case */
0875         if (info->hi_ferr & 0x7f)
0876             pci_write_config_byte(dev, E752X_HI_FERR,
0877                     info->hi_ferr);
0878 
0879         if (info->nsi_ferr & NSI_ERR_MASK)
0880             pci_write_config_dword(dev, I3100_NSI_FERR,
0881                     info->nsi_ferr);
0882 
0883         if (info->sysbus_ferr)
0884             pci_write_config_word(dev, E752X_SYSBUS_FERR,
0885                     info->sysbus_ferr);
0886 
0887         if (info->buf_ferr & 0x0f)
0888             pci_write_config_byte(dev, E752X_BUF_FERR,
0889                     info->buf_ferr);
0890 
0891         if (info->dram_ferr)
0892             pci_write_bits16(pvt->dev_d0f1, E752X_DRAM_FERR,
0893                      info->dram_ferr, info->dram_ferr);
0894 
0895         pci_write_config_dword(dev, E752X_FERR_GLOBAL,
0896                 info->ferr_global);
0897     }
0898 
0899     pci_read_config_dword(dev, E752X_NERR_GLOBAL, &info->nerr_global);
0900 
0901     if (info->nerr_global) {
0902         if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
0903             pci_read_config_dword(dev, I3100_NSI_NERR,
0904                          &info->nsi_nerr);
0905             info->hi_nerr = 0;
0906         } else {
0907             pci_read_config_byte(dev, E752X_HI_NERR,
0908                          &info->hi_nerr);
0909             info->nsi_nerr = 0;
0910         }
0911         pci_read_config_word(dev, E752X_SYSBUS_NERR,
0912                 &info->sysbus_nerr);
0913         pci_read_config_byte(dev, E752X_BUF_NERR, &info->buf_nerr);
0914         pci_read_config_word(dev, E752X_DRAM_NERR, &info->dram_nerr);
0915         pci_read_config_dword(dev, E752X_DRAM_SEC2_ADD,
0916                 &info->dram_sec2_add);
0917         pci_read_config_word(dev, E752X_DRAM_SEC2_SYNDROME,
0918                 &info->dram_sec2_syndrome);
0919 
0920         if (info->hi_nerr & 0x7f)
0921             pci_write_config_byte(dev, E752X_HI_NERR,
0922                     info->hi_nerr);
0923 
0924         if (info->nsi_nerr & NSI_ERR_MASK)
0925             pci_write_config_dword(dev, I3100_NSI_NERR,
0926                     info->nsi_nerr);
0927 
0928         if (info->sysbus_nerr)
0929             pci_write_config_word(dev, E752X_SYSBUS_NERR,
0930                     info->sysbus_nerr);
0931 
0932         if (info->buf_nerr & 0x0f)
0933             pci_write_config_byte(dev, E752X_BUF_NERR,
0934                     info->buf_nerr);
0935 
0936         if (info->dram_nerr)
0937             pci_write_bits16(pvt->dev_d0f1, E752X_DRAM_NERR,
0938                      info->dram_nerr, info->dram_nerr);
0939 
0940         pci_write_config_dword(dev, E752X_NERR_GLOBAL,
0941                 info->nerr_global);
0942     }
0943 }
0944 
0945 static int e752x_process_error_info(struct mem_ctl_info *mci,
0946                 struct e752x_error_info *info,
0947                 int handle_errors)
0948 {
0949     u32 error32, stat32;
0950     int error_found;
0951 
0952     error_found = 0;
0953     error32 = (info->ferr_global >> 18) & 0x3ff;
0954     stat32 = (info->ferr_global >> 4) & 0x7ff;
0955 
0956     if (error32)
0957         global_error(1, error32, &error_found, handle_errors);
0958 
0959     if (stat32)
0960         global_error(0, stat32, &error_found, handle_errors);
0961 
0962     error32 = (info->nerr_global >> 18) & 0x3ff;
0963     stat32 = (info->nerr_global >> 4) & 0x7ff;
0964 
0965     if (error32)
0966         global_error(1, error32, &error_found, handle_errors);
0967 
0968     if (stat32)
0969         global_error(0, stat32, &error_found, handle_errors);
0970 
0971     e752x_check_hub_interface(info, &error_found, handle_errors);
0972     e752x_check_ns_interface(info, &error_found, handle_errors);
0973     e752x_check_sysbus(info, &error_found, handle_errors);
0974     e752x_check_membuf(info, &error_found, handle_errors);
0975     e752x_check_dram(mci, info, &error_found, handle_errors);
0976     return error_found;
0977 }
0978 
0979 static void e752x_check(struct mem_ctl_info *mci)
0980 {
0981     struct e752x_error_info info;
0982 
0983     e752x_get_error_info(mci, &info);
0984     e752x_process_error_info(mci, &info, 1);
0985 }
0986 
0987 /* Program byte/sec bandwidth scrub rate to hardware */
0988 static int set_sdram_scrub_rate(struct mem_ctl_info *mci, u32 new_bw)
0989 {
0990     const struct scrubrate *scrubrates;
0991     struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
0992     struct pci_dev *pdev = pvt->dev_d0f0;
0993     int i;
0994 
0995     if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
0996         scrubrates = scrubrates_i3100;
0997     else
0998         scrubrates = scrubrates_e752x;
0999 
1000     /* Translate the desired scrub rate to a e752x/3100 register value.
1001      * Search for the bandwidth that is equal or greater than the
1002      * desired rate and program the cooresponding register value.
1003      */
1004     for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
1005         if (scrubrates[i].bandwidth >= new_bw)
1006             break;
1007 
1008     if (scrubrates[i].bandwidth == SDRATE_EOT)
1009         return -1;
1010 
1011     pci_write_config_word(pdev, E752X_MCHSCRB, scrubrates[i].scrubval);
1012 
1013     return scrubrates[i].bandwidth;
1014 }
1015 
1016 /* Convert current scrub rate value into byte/sec bandwidth */
1017 static int get_sdram_scrub_rate(struct mem_ctl_info *mci)
1018 {
1019     const struct scrubrate *scrubrates;
1020     struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
1021     struct pci_dev *pdev = pvt->dev_d0f0;
1022     u16 scrubval;
1023     int i;
1024 
1025     if (pvt->dev_info->ctl_dev == PCI_DEVICE_ID_INTEL_3100_0)
1026         scrubrates = scrubrates_i3100;
1027     else
1028         scrubrates = scrubrates_e752x;
1029 
1030     /* Find the bandwidth matching the memory scrubber configuration */
1031     pci_read_config_word(pdev, E752X_MCHSCRB, &scrubval);
1032     scrubval = scrubval & 0x0f;
1033 
1034     for (i = 0; scrubrates[i].bandwidth != SDRATE_EOT; i++)
1035         if (scrubrates[i].scrubval == scrubval)
1036             break;
1037 
1038     if (scrubrates[i].bandwidth == SDRATE_EOT) {
1039         e752x_printk(KERN_WARNING,
1040             "Invalid sdram scrub control value: 0x%x\n", scrubval);
1041         return -1;
1042     }
1043     return scrubrates[i].bandwidth;
1044 
1045 }
1046 
1047 /* Return 1 if dual channel mode is active.  Else return 0. */
1048 static inline int dual_channel_active(u16 ddrcsr)
1049 {
1050     return (((ddrcsr >> 12) & 3) == 3);
1051 }
1052 
1053 /* Remap csrow index numbers if map_type is "reverse"
1054  */
1055 static inline int remap_csrow_index(struct mem_ctl_info *mci, int index)
1056 {
1057     struct e752x_pvt *pvt = mci->pvt_info;
1058 
1059     if (!pvt->map_type)
1060         return (7 - index);
1061 
1062     return (index);
1063 }
1064 
1065 static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
1066             u16 ddrcsr)
1067 {
1068     struct csrow_info *csrow;
1069     enum edac_type edac_mode;
1070     unsigned long last_cumul_size;
1071     int index, mem_dev, drc_chan;
1072     int drc_drbg;       /* DRB granularity 0=64mb, 1=128mb */
1073     int drc_ddim;       /* DRAM Data Integrity Mode 0=none, 2=edac */
1074     u8 value;
1075     u32 dra, drc, cumul_size, i, nr_pages;
1076 
1077     dra = 0;
1078     for (index = 0; index < 4; index++) {
1079         u8 dra_reg;
1080         pci_read_config_byte(pdev, E752X_DRA + index, &dra_reg);
1081         dra |= dra_reg << (index * 8);
1082     }
1083     pci_read_config_dword(pdev, E752X_DRC, &drc);
1084     drc_chan = dual_channel_active(ddrcsr) ? 1 : 0;
1085     drc_drbg = drc_chan + 1;    /* 128 in dual mode, 64 in single */
1086     drc_ddim = (drc >> 20) & 0x3;
1087 
1088     /* The dram row boundary (DRB) reg values are boundary address for
1089      * each DRAM row with a granularity of 64 or 128MB (single/dual
1090      * channel operation).  DRB regs are cumulative; therefore DRB7 will
1091      * contain the total memory contained in all eight rows.
1092      */
1093     for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
1094         /* mem_dev 0=x8, 1=x4 */
1095         mem_dev = (dra >> (index * 4 + 2)) & 0x3;
1096         csrow = mci->csrows[remap_csrow_index(mci, index)];
1097 
1098         mem_dev = (mem_dev == 2);
1099         pci_read_config_byte(pdev, E752X_DRB + index, &value);
1100         /* convert a 128 or 64 MiB DRB to a page size. */
1101         cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
1102         edac_dbg(3, "(%d) cumul_size 0x%x\n", index, cumul_size);
1103         if (cumul_size == last_cumul_size)
1104             continue;   /* not populated */
1105 
1106         csrow->first_page = last_cumul_size;
1107         csrow->last_page = cumul_size - 1;
1108         nr_pages = cumul_size - last_cumul_size;
1109         last_cumul_size = cumul_size;
1110 
1111         /*
1112         * if single channel or x8 devices then SECDED
1113         * if dual channel and x4 then S4ECD4ED
1114         */
1115         if (drc_ddim) {
1116             if (drc_chan && mem_dev) {
1117                 edac_mode = EDAC_S4ECD4ED;
1118                 mci->edac_cap |= EDAC_FLAG_S4ECD4ED;
1119             } else {
1120                 edac_mode = EDAC_SECDED;
1121                 mci->edac_cap |= EDAC_FLAG_SECDED;
1122             }
1123         } else
1124             edac_mode = EDAC_NONE;
1125         for (i = 0; i < csrow->nr_channels; i++) {
1126             struct dimm_info *dimm = csrow->channels[i]->dimm;
1127 
1128             edac_dbg(3, "Initializing rank at (%i,%i)\n", index, i);
1129             dimm->nr_pages = nr_pages / csrow->nr_channels;
1130             dimm->grain = 1 << 12;  /* 4KiB - resolution of CELOG */
1131             dimm->mtype = MEM_RDDR; /* only one type supported */
1132             dimm->dtype = mem_dev ? DEV_X4 : DEV_X8;
1133             dimm->edac_mode = edac_mode;
1134         }
1135     }
1136 }
1137 
1138 static void e752x_init_mem_map_table(struct pci_dev *pdev,
1139                 struct e752x_pvt *pvt)
1140 {
1141     int index;
1142     u8 value, last, row;
1143 
1144     last = 0;
1145     row = 0;
1146 
1147     for (index = 0; index < 8; index += 2) {
1148         pci_read_config_byte(pdev, E752X_DRB + index, &value);
1149         /* test if there is a dimm in this slot */
1150         if (value == last) {
1151             /* no dimm in the slot, so flag it as empty */
1152             pvt->map[index] = 0xff;
1153             pvt->map[index + 1] = 0xff;
1154         } else {    /* there is a dimm in the slot */
1155             pvt->map[index] = row;
1156             row++;
1157             last = value;
1158             /* test the next value to see if the dimm is double
1159              * sided
1160              */
1161             pci_read_config_byte(pdev, E752X_DRB + index + 1,
1162                     &value);
1163 
1164             /* the dimm is single sided, so flag as empty */
1165             /* this is a double sided dimm to save the next row #*/
1166             pvt->map[index + 1] = (value == last) ? 0xff :  row;
1167             row++;
1168             last = value;
1169         }
1170     }
1171 }
1172 
1173 /* Return 0 on success or 1 on failure. */
1174 static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
1175             struct e752x_pvt *pvt)
1176 {
1177     pvt->dev_d0f1 = pci_get_device(PCI_VENDOR_ID_INTEL,
1178                 pvt->dev_info->err_dev, NULL);
1179 
1180     if (pvt->dev_d0f1 == NULL) {
1181         pvt->dev_d0f1 = pci_scan_single_device(pdev->bus,
1182                             PCI_DEVFN(0, 1));
1183         pci_dev_get(pvt->dev_d0f1);
1184     }
1185 
1186     if (pvt->dev_d0f1 == NULL) {
1187         e752x_printk(KERN_ERR, "error reporting device not found:"
1188             "vendor %x device 0x%x (broken BIOS?)\n",
1189             PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
1190         return 1;
1191     }
1192 
1193     pvt->dev_d0f0 = pci_get_device(PCI_VENDOR_ID_INTEL,
1194                 e752x_devs[dev_idx].ctl_dev,
1195                 NULL);
1196 
1197     if (pvt->dev_d0f0 == NULL)
1198         goto fail;
1199 
1200     return 0;
1201 
1202 fail:
1203     pci_dev_put(pvt->dev_d0f1);
1204     return 1;
1205 }
1206 
1207 /* Setup system bus parity mask register.
1208  * Sysbus parity supported on:
1209  * e7320/e7520/e7525 + Xeon
1210  */
1211 static void e752x_init_sysbus_parity_mask(struct e752x_pvt *pvt)
1212 {
1213     char *cpu_id = cpu_data(0).x86_model_id;
1214     struct pci_dev *dev = pvt->dev_d0f1;
1215     int enable = 1;
1216 
1217     /* Allow module parameter override, else see if CPU supports parity */
1218     if (sysbus_parity != -1) {
1219         enable = sysbus_parity;
1220     } else if (cpu_id[0] && !strstr(cpu_id, "Xeon")) {
1221         e752x_printk(KERN_INFO, "System Bus Parity not "
1222                  "supported by CPU, disabling\n");
1223         enable = 0;
1224     }
1225 
1226     if (enable)
1227         pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0000);
1228     else
1229         pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x0309);
1230 }
1231 
1232 static void e752x_init_error_reporting_regs(struct e752x_pvt *pvt)
1233 {
1234     struct pci_dev *dev;
1235 
1236     dev = pvt->dev_d0f1;
1237     /* Turn off error disable & SMI in case the BIOS turned it on */
1238     if (pvt->dev_info->err_dev == PCI_DEVICE_ID_INTEL_3100_1_ERR) {
1239         pci_write_config_dword(dev, I3100_NSI_EMASK, 0);
1240         pci_write_config_dword(dev, I3100_NSI_SMICMD, 0);
1241     } else {
1242         pci_write_config_byte(dev, E752X_HI_ERRMASK, 0x00);
1243         pci_write_config_byte(dev, E752X_HI_SMICMD, 0x00);
1244     }
1245 
1246     e752x_init_sysbus_parity_mask(pvt);
1247 
1248     pci_write_config_word(dev, E752X_SYSBUS_SMICMD, 0x00);
1249     pci_write_config_byte(dev, E752X_BUF_ERRMASK, 0x00);
1250     pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
1251     pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
1252     pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
1253 }
1254 
1255 static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
1256 {
1257     u16 pci_data;
1258     u8 stat8;
1259     struct mem_ctl_info *mci;
1260     struct edac_mc_layer layers[2];
1261     struct e752x_pvt *pvt;
1262     u16 ddrcsr;
1263     int drc_chan;       /* Number of channels 0=1chan,1=2chan */
1264     struct e752x_error_info discard;
1265 
1266     edac_dbg(0, "mci\n");
1267     edac_dbg(0, "Starting Probe1\n");
1268 
1269     /* check to see if device 0 function 1 is enabled; if it isn't, we
1270      * assume the BIOS has reserved it for a reason and is expecting
1271      * exclusive access, we take care not to violate that assumption and
1272      * fail the probe. */
1273     pci_read_config_byte(pdev, E752X_DEVPRES1, &stat8);
1274     if (!force_function_unhide && !(stat8 & (1 << 5))) {
1275         printk(KERN_INFO "Contact your BIOS vendor to see if the "
1276             "E752x error registers can be safely un-hidden\n");
1277         return -ENODEV;
1278     }
1279     stat8 |= (1 << 5);
1280     pci_write_config_byte(pdev, E752X_DEVPRES1, stat8);
1281 
1282     pci_read_config_word(pdev, E752X_DDRCSR, &ddrcsr);
1283     /* FIXME: should check >>12 or 0xf, true for all? */
1284     /* Dual channel = 1, Single channel = 0 */
1285     drc_chan = dual_channel_active(ddrcsr);
1286 
1287     layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
1288     layers[0].size = E752X_NR_CSROWS;
1289     layers[0].is_virt_csrow = true;
1290     layers[1].type = EDAC_MC_LAYER_CHANNEL;
1291     layers[1].size = drc_chan + 1;
1292     layers[1].is_virt_csrow = false;
1293     mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
1294     if (mci == NULL)
1295         return -ENOMEM;
1296 
1297     edac_dbg(3, "init mci\n");
1298     mci->mtype_cap = MEM_FLAG_RDDR;
1299     /* 3100 IMCH supports SECDEC only */
1300     mci->edac_ctl_cap = (dev_idx == I3100) ? EDAC_FLAG_SECDED :
1301         (EDAC_FLAG_NONE | EDAC_FLAG_SECDED | EDAC_FLAG_S4ECD4ED);
1302     /* FIXME - what if different memory types are in different csrows? */
1303     mci->mod_name = EDAC_MOD_STR;
1304     mci->pdev = &pdev->dev;
1305 
1306     edac_dbg(3, "init pvt\n");
1307     pvt = (struct e752x_pvt *)mci->pvt_info;
1308     pvt->dev_info = &e752x_devs[dev_idx];
1309     pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
1310 
1311     if (e752x_get_devs(pdev, dev_idx, pvt)) {
1312         edac_mc_free(mci);
1313         return -ENODEV;
1314     }
1315 
1316     edac_dbg(3, "more mci init\n");
1317     mci->ctl_name = pvt->dev_info->ctl_name;
1318     mci->dev_name = pci_name(pdev);
1319     mci->edac_check = e752x_check;
1320     mci->ctl_page_to_phys = ctl_page_to_phys;
1321     mci->set_sdram_scrub_rate = set_sdram_scrub_rate;
1322     mci->get_sdram_scrub_rate = get_sdram_scrub_rate;
1323 
1324     /* set the map type.  1 = normal, 0 = reversed
1325      * Must be set before e752x_init_csrows in case csrow mapping
1326      * is reversed.
1327      */
1328     pci_read_config_byte(pdev, E752X_DRM, &stat8);
1329     pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
1330 
1331     e752x_init_csrows(mci, pdev, ddrcsr);
1332     e752x_init_mem_map_table(pdev, pvt);
1333 
1334     if (dev_idx == I3100)
1335         mci->edac_cap = EDAC_FLAG_SECDED; /* the only mode supported */
1336     else
1337         mci->edac_cap |= EDAC_FLAG_NONE;
1338     edac_dbg(3, "tolm, remapbase, remaplimit\n");
1339 
1340     /* load the top of low memory, remap base, and remap limit vars */
1341     pci_read_config_word(pdev, E752X_TOLM, &pci_data);
1342     pvt->tolm = ((u32) pci_data) << 4;
1343     pci_read_config_word(pdev, E752X_REMAPBASE, &pci_data);
1344     pvt->remapbase = ((u32) pci_data) << 14;
1345     pci_read_config_word(pdev, E752X_REMAPLIMIT, &pci_data);
1346     pvt->remaplimit = ((u32) pci_data) << 14;
1347     e752x_printk(KERN_INFO,
1348             "tolm = %x, remapbase = %x, remaplimit = %x\n",
1349             pvt->tolm, pvt->remapbase, pvt->remaplimit);
1350 
1351     /* Here we assume that we will never see multiple instances of this
1352      * type of memory controller.  The ID is therefore hardcoded to 0.
1353      */
1354     if (edac_mc_add_mc(mci)) {
1355         edac_dbg(3, "failed edac_mc_add_mc()\n");
1356         goto fail;
1357     }
1358 
1359     e752x_init_error_reporting_regs(pvt);
1360     e752x_get_error_info(mci, &discard);    /* clear other MCH errors */
1361 
1362     /* allocating generic PCI control info */
1363     e752x_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
1364     if (!e752x_pci) {
1365         printk(KERN_WARNING
1366             "%s(): Unable to create PCI control\n", __func__);
1367         printk(KERN_WARNING
1368             "%s(): PCI error report via EDAC not setup\n",
1369             __func__);
1370     }
1371 
1372     /* get this far and it's successful */
1373     edac_dbg(3, "success\n");
1374     return 0;
1375 
1376 fail:
1377     pci_dev_put(pvt->dev_d0f0);
1378     pci_dev_put(pvt->dev_d0f1);
1379     edac_mc_free(mci);
1380 
1381     return -ENODEV;
1382 }
1383 
1384 /* returns count (>= 0), or negative on error */
1385 static int e752x_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1386 {
1387     edac_dbg(0, "\n");
1388 
1389     /* wake up and enable device */
1390     if (pci_enable_device(pdev) < 0)
1391         return -EIO;
1392 
1393     return e752x_probe1(pdev, ent->driver_data);
1394 }
1395 
1396 static void e752x_remove_one(struct pci_dev *pdev)
1397 {
1398     struct mem_ctl_info *mci;
1399     struct e752x_pvt *pvt;
1400 
1401     edac_dbg(0, "\n");
1402 
1403     if (e752x_pci)
1404         edac_pci_release_generic_ctl(e752x_pci);
1405 
1406     if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
1407         return;
1408 
1409     pvt = (struct e752x_pvt *)mci->pvt_info;
1410     pci_dev_put(pvt->dev_d0f0);
1411     pci_dev_put(pvt->dev_d0f1);
1412     edac_mc_free(mci);
1413 }
1414 
1415 static const struct pci_device_id e752x_pci_tbl[] = {
1416     {
1417      PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1418      E7520},
1419     {
1420      PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1421      E7525},
1422     {
1423      PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1424      E7320},
1425     {
1426      PCI_VEND_DEV(INTEL, 3100_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1427      I3100},
1428     {
1429      0,
1430      }          /* 0 terminated list. */
1431 };
1432 
1433 MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);
1434 
1435 static struct pci_driver e752x_driver = {
1436     .name = EDAC_MOD_STR,
1437     .probe = e752x_init_one,
1438     .remove = e752x_remove_one,
1439     .id_table = e752x_pci_tbl,
1440 };
1441 
1442 static int __init e752x_init(void)
1443 {
1444     int pci_rc;
1445 
1446     edac_dbg(3, "\n");
1447 
1448     /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1449     opstate_init();
1450 
1451     pci_rc = pci_register_driver(&e752x_driver);
1452     return (pci_rc < 0) ? pci_rc : 0;
1453 }
1454 
1455 static void __exit e752x_exit(void)
1456 {
1457     edac_dbg(3, "\n");
1458     pci_unregister_driver(&e752x_driver);
1459 }
1460 
1461 module_init(e752x_init);
1462 module_exit(e752x_exit);
1463 
1464 MODULE_LICENSE("GPL");
1465 MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
1466 MODULE_DESCRIPTION("MC support for Intel e752x/3100 memory controllers");
1467 
1468 module_param(force_function_unhide, int, 0444);
1469 MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
1470          " 1=force unhide and hope BIOS doesn't fight driver for "
1471         "Dev0:Fun1 access");
1472 
1473 module_param(edac_op_state, int, 0444);
1474 MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1475 
1476 module_param(sysbus_parity, int, 0444);
1477 MODULE_PARM_DESC(sysbus_parity, "0=disable system bus parity checking,"
1478         " 1=enable system bus parity checking, default=auto-detect");
1479 module_param(report_non_memory_errors, int, 0644);
1480 MODULE_PARM_DESC(report_non_memory_errors, "0=disable non-memory error "
1481         "reporting, 1=enable non-memory error reporting");