2 * Copyright (C) 2006-2007 PA Semi, Inc
4 * Author: Egor Martovetsky <egor@pasemi.com>
5 * Maintained by: Olof Johansson <olof@lixom.net>
7 * Driver for the PWRficient onchip memory controllers
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/pci.h>
27 #include <linux/pci_ids.h>
28 #include <linux/edac.h>
29 #include "edac_core.h"
31 #define MODULE_NAME "pasemi_edac"
33 #define MCCFG_MCEN 0x300
34 #define MCCFG_MCEN_MMC_EN 0x00000001
35 #define MCCFG_ERRCOR 0x388
36 #define MCCFG_ERRCOR_RNK_FAIL_DET_EN 0x00000100
37 #define MCCFG_ERRCOR_ECC_GEN_EN 0x00000010
38 #define MCCFG_ERRCOR_ECC_CRR_EN 0x00000001
39 #define MCCFG_SCRUB 0x384
40 #define MCCFG_SCRUB_RGLR_SCRB_EN 0x00000001
41 #define MCDEBUG_ERRCTL1 0x728
42 #define MCDEBUG_ERRCTL1_RFL_LOG_EN 0x00080000
43 #define MCDEBUG_ERRCTL1_MBE_LOG_EN 0x00040000
44 #define MCDEBUG_ERRCTL1_SBE_LOG_EN 0x00020000
45 #define MCDEBUG_ERRSTA 0x730
46 #define MCDEBUG_ERRSTA_RFL_STATUS 0x00000004
47 #define MCDEBUG_ERRSTA_MBE_STATUS 0x00000002
48 #define MCDEBUG_ERRSTA_SBE_STATUS 0x00000001
49 #define MCDEBUG_ERRCNT1 0x734
50 #define MCDEBUG_ERRCNT1_SBE_CNT_OVRFLO 0x00000080
51 #define MCDEBUG_ERRLOG1A 0x738
52 #define MCDEBUG_ERRLOG1A_MERR_TYPE_M 0x30000000
53 #define MCDEBUG_ERRLOG1A_MERR_TYPE_NONE 0x00000000
54 #define MCDEBUG_ERRLOG1A_MERR_TYPE_SBE 0x10000000
55 #define MCDEBUG_ERRLOG1A_MERR_TYPE_MBE 0x20000000
56 #define MCDEBUG_ERRLOG1A_MERR_TYPE_RFL 0x30000000
57 #define MCDEBUG_ERRLOG1A_MERR_BA_M 0x00700000
58 #define MCDEBUG_ERRLOG1A_MERR_BA_S 20
59 #define MCDEBUG_ERRLOG1A_MERR_CS_M 0x00070000
60 #define MCDEBUG_ERRLOG1A_MERR_CS_S 16
61 #define MCDEBUG_ERRLOG1A_SYNDROME_M 0x0000ffff
62 #define MCDRAM_RANKCFG 0x114
63 #define MCDRAM_RANKCFG_EN 0x00000001
64 #define MCDRAM_RANKCFG_TYPE_SIZE_M 0x000001c0
65 #define MCDRAM_RANKCFG_TYPE_SIZE_S 6
67 #define PASEMI_EDAC_NR_CSROWS 8
68 #define PASEMI_EDAC_NR_CHANS 1
69 #define PASEMI_EDAC_ERROR_GRAIN 64
71 static int last_page_in_mmc;
72 static int system_mmc_id;
75 static u32 pasemi_edac_get_error_info(struct mem_ctl_info *mci)
77 struct pci_dev *pdev = to_pci_dev(mci->dev);
80 pci_read_config_dword(pdev, MCDEBUG_ERRSTA,
83 tmp &= (MCDEBUG_ERRSTA_RFL_STATUS | MCDEBUG_ERRSTA_MBE_STATUS
84 | MCDEBUG_ERRSTA_SBE_STATUS);
87 if (tmp & MCDEBUG_ERRSTA_SBE_STATUS)
88 pci_write_config_dword(pdev, MCDEBUG_ERRCNT1,
89 MCDEBUG_ERRCNT1_SBE_CNT_OVRFLO);
90 pci_write_config_dword(pdev, MCDEBUG_ERRSTA, tmp);
96 static void pasemi_edac_process_error_info(struct mem_ctl_info *mci, u32 errsta)
98 struct pci_dev *pdev = to_pci_dev(mci->dev);
105 pci_read_config_dword(pdev, MCDEBUG_ERRLOG1A, &errlog1a);
107 cs = (errlog1a & MCDEBUG_ERRLOG1A_MERR_CS_M) >>
108 MCDEBUG_ERRLOG1A_MERR_CS_S;
110 /* uncorrectable/multi-bit errors */
111 if (errsta & (MCDEBUG_ERRSTA_MBE_STATUS |
112 MCDEBUG_ERRSTA_RFL_STATUS)) {
113 edac_mc_handle_ue(mci, mci->csrows[cs].first_page, 0,
117 /* correctable/single-bit errors */
118 if (errsta & MCDEBUG_ERRSTA_SBE_STATUS) {
119 edac_mc_handle_ce(mci, mci->csrows[cs].first_page, 0,
120 0, cs, 0, mci->ctl_name);
124 static void pasemi_edac_check(struct mem_ctl_info *mci)
128 errsta = pasemi_edac_get_error_info(mci);
130 pasemi_edac_process_error_info(mci, errsta);
133 static int pasemi_edac_init_csrows(struct mem_ctl_info *mci,
134 struct pci_dev *pdev,
135 enum edac_type edac_mode)
137 struct csrow_info *csrow;
138 struct dimm_info *dimm;
142 for (index = 0; index < mci->nr_csrows; index++) {
143 csrow = &mci->csrows[index];
144 dimm = csrow->channels[0].dimm;
146 pci_read_config_dword(pdev,
147 MCDRAM_RANKCFG + (index * 12),
150 if (!(rankcfg & MCDRAM_RANKCFG_EN))
153 switch ((rankcfg & MCDRAM_RANKCFG_TYPE_SIZE_M) >>
154 MCDRAM_RANKCFG_TYPE_SIZE_S) {
156 csrow->nr_pages = 128 << (20 - PAGE_SHIFT);
159 csrow->nr_pages = 256 << (20 - PAGE_SHIFT);
163 csrow->nr_pages = 512 << (20 - PAGE_SHIFT);
166 csrow->nr_pages = 1024 << (20 - PAGE_SHIFT);
169 csrow->nr_pages = 2048 << (20 - PAGE_SHIFT);
172 edac_mc_printk(mci, KERN_ERR,
173 "Unrecognized Rank Config. rankcfg=%u\n",
178 csrow->first_page = last_page_in_mmc;
179 csrow->last_page = csrow->first_page + csrow->nr_pages - 1;
180 last_page_in_mmc += csrow->nr_pages;
181 csrow->page_mask = 0;
182 dimm->grain = PASEMI_EDAC_ERROR_GRAIN;
183 dimm->mtype = MEM_DDR;
184 dimm->dtype = DEV_UNKNOWN;
185 dimm->edac_mode = edac_mode;
190 static int __devinit pasemi_edac_probe(struct pci_dev *pdev,
191 const struct pci_device_id *ent)
193 struct mem_ctl_info *mci = NULL;
194 u32 errctl1, errcor, scrub, mcen;
196 pci_read_config_dword(pdev, MCCFG_MCEN, &mcen);
197 if (!(mcen & MCCFG_MCEN_MMC_EN))
201 * We should think about enabling other error detection later on
204 pci_read_config_dword(pdev, MCDEBUG_ERRCTL1, &errctl1);
205 errctl1 |= MCDEBUG_ERRCTL1_SBE_LOG_EN |
206 MCDEBUG_ERRCTL1_MBE_LOG_EN |
207 MCDEBUG_ERRCTL1_RFL_LOG_EN;
208 pci_write_config_dword(pdev, MCDEBUG_ERRCTL1, errctl1);
210 mci = edac_mc_alloc(0, PASEMI_EDAC_NR_CSROWS, PASEMI_EDAC_NR_CHANS,
216 pci_read_config_dword(pdev, MCCFG_ERRCOR, &errcor);
217 errcor |= MCCFG_ERRCOR_RNK_FAIL_DET_EN |
218 MCCFG_ERRCOR_ECC_GEN_EN |
219 MCCFG_ERRCOR_ECC_CRR_EN;
221 mci->dev = &pdev->dev;
222 mci->mtype_cap = MEM_FLAG_DDR | MEM_FLAG_RDDR;
223 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
224 mci->edac_cap = (errcor & MCCFG_ERRCOR_ECC_GEN_EN) ?
225 ((errcor & MCCFG_ERRCOR_ECC_CRR_EN) ?
226 (EDAC_FLAG_EC | EDAC_FLAG_SECDED) : EDAC_FLAG_EC) :
228 mci->mod_name = MODULE_NAME;
229 mci->dev_name = pci_name(pdev);
230 mci->ctl_name = "pasemi,pwrficient-mc";
231 mci->edac_check = pasemi_edac_check;
232 mci->ctl_page_to_phys = NULL;
233 pci_read_config_dword(pdev, MCCFG_SCRUB, &scrub);
234 mci->scrub_cap = SCRUB_FLAG_HW_PROG | SCRUB_FLAG_HW_SRC;
236 ((errcor & MCCFG_ERRCOR_ECC_CRR_EN) ? SCRUB_FLAG_HW_SRC : 0) |
237 ((scrub & MCCFG_SCRUB_RGLR_SCRB_EN) ? SCRUB_FLAG_HW_PROG : 0);
239 if (pasemi_edac_init_csrows(mci, pdev,
240 (mci->edac_cap & EDAC_FLAG_SECDED) ?
242 ((mci->edac_cap & EDAC_FLAG_EC) ?
243 EDAC_EC : EDAC_NONE)))
249 pasemi_edac_get_error_info(mci);
251 if (edac_mc_add_mc(mci))
254 /* get this far and it's successful */
262 static void __devexit pasemi_edac_remove(struct pci_dev *pdev)
264 struct mem_ctl_info *mci = edac_mc_del_mc(&pdev->dev);
273 static const struct pci_device_id pasemi_edac_pci_tbl[] = {
274 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa00a) },
278 MODULE_DEVICE_TABLE(pci, pasemi_edac_pci_tbl);
280 static struct pci_driver pasemi_edac_driver = {
282 .probe = pasemi_edac_probe,
283 .remove = __devexit_p(pasemi_edac_remove),
284 .id_table = pasemi_edac_pci_tbl,
287 static int __init pasemi_edac_init(void)
289 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
292 return pci_register_driver(&pasemi_edac_driver);
295 static void __exit pasemi_edac_exit(void)
297 pci_unregister_driver(&pasemi_edac_driver);
300 module_init(pasemi_edac_init);
301 module_exit(pasemi_edac_exit);
303 MODULE_LICENSE("GPL");
304 MODULE_AUTHOR("Egor Martovetsky <egor@pasemi.com>");
305 MODULE_DESCRIPTION("MC support for PA Semi PWRficient memory controller");
306 module_param(edac_op_state, int, 0444);
307 MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");