2 * amd8131_edac.c, AMD8131 hypertransport chip EDAC kernel module
4 * Copyright (c) 2008 Wind River Systems, Inc.
6 * Authors: Cao Qingtao <qingtao.cao@windriver.com>
7 * Benjamin Walsh <benjamin.walsh@windriver.com>
8 * Hu Yongqi <yongqi.hu@windriver.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * 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/interrupt.h>
28 #include <linux/bitops.h>
29 #include <linux/edac.h>
30 #include <linux/pci_ids.h>
32 #include "edac_module.h"
33 #include "amd8131_edac.h"
35 #define AMD8131_EDAC_REVISION " Ver: 1.0.0"
36 #define AMD8131_EDAC_MOD_STR "amd8131_edac"
38 /* Wrapper functions for accessing PCI configuration space */
39 static void edac_pci_read_dword(struct pci_dev *dev, int reg, u32 *val32)
43 ret = pci_read_config_dword(dev, reg, val32);
45 printk(KERN_ERR AMD8131_EDAC_MOD_STR
46 " PCI Access Read Error at 0x%x\n", reg);
49 static void edac_pci_write_dword(struct pci_dev *dev, int reg, u32 val32)
53 ret = pci_write_config_dword(dev, reg, val32);
55 printk(KERN_ERR AMD8131_EDAC_MOD_STR
56 " PCI Access Write Error at 0x%x\n", reg);
59 static char * const bridge_str[] = {
60 [NORTH_A] = "NORTH A",
61 [NORTH_B] = "NORTH B",
62 [SOUTH_A] = "SOUTH A",
63 [SOUTH_B] = "SOUTH B",
64 [NO_BRIDGE] = "NO BRIDGE",
67 /* Support up to two AMD8131 chipsets on a platform */
68 static struct amd8131_dev_info amd8131_devices[] = {
71 .devfn = DEVFN_PCIX_BRIDGE_NORTH_A,
72 .ctl_name = "AMD8131_PCIX_NORTH_A",
76 .devfn = DEVFN_PCIX_BRIDGE_NORTH_B,
77 .ctl_name = "AMD8131_PCIX_NORTH_B",
81 .devfn = DEVFN_PCIX_BRIDGE_SOUTH_A,
82 .ctl_name = "AMD8131_PCIX_SOUTH_A",
86 .devfn = DEVFN_PCIX_BRIDGE_SOUTH_B,
87 .ctl_name = "AMD8131_PCIX_SOUTH_B",
92 static void amd8131_pcix_init(struct amd8131_dev_info *dev_info)
95 struct pci_dev *dev = dev_info->dev;
97 /* First clear error detection flags */
98 edac_pci_read_dword(dev, REG_MEM_LIM, &val32);
99 if (val32 & MEM_LIMIT_MASK)
100 edac_pci_write_dword(dev, REG_MEM_LIM, val32);
102 /* Clear Discard Timer Timedout flag */
103 edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
104 if (val32 & INT_CTLR_DTS)
105 edac_pci_write_dword(dev, REG_INT_CTLR, val32);
107 /* Clear CRC Error flag on link side A */
108 edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
109 if (val32 & LNK_CTRL_CRCERR_A)
110 edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
112 /* Clear CRC Error flag on link side B */
113 edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
114 if (val32 & LNK_CTRL_CRCERR_B)
115 edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
118 * Then enable all error detections.
120 * Setup Discard Timer Sync Flood Enable,
121 * System Error Enable and Parity Error Enable.
123 edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
124 val32 |= INT_CTLR_PERR | INT_CTLR_SERR | INT_CTLR_DTSE;
125 edac_pci_write_dword(dev, REG_INT_CTLR, val32);
127 /* Enable overall SERR Error detection */
128 edac_pci_read_dword(dev, REG_STS_CMD, &val32);
129 val32 |= STS_CMD_SERREN;
130 edac_pci_write_dword(dev, REG_STS_CMD, val32);
132 /* Setup CRC Flood Enable for link side A */
133 edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
134 val32 |= LNK_CTRL_CRCFEN;
135 edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
137 /* Setup CRC Flood Enable for link side B */
138 edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
139 val32 |= LNK_CTRL_CRCFEN;
140 edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
143 static void amd8131_pcix_exit(struct amd8131_dev_info *dev_info)
146 struct pci_dev *dev = dev_info->dev;
148 /* Disable SERR, PERR and DTSE Error detection */
149 edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
150 val32 &= ~(INT_CTLR_PERR | INT_CTLR_SERR | INT_CTLR_DTSE);
151 edac_pci_write_dword(dev, REG_INT_CTLR, val32);
153 /* Disable overall System Error detection */
154 edac_pci_read_dword(dev, REG_STS_CMD, &val32);
155 val32 &= ~STS_CMD_SERREN;
156 edac_pci_write_dword(dev, REG_STS_CMD, val32);
158 /* Disable CRC Sync Flood on link side A */
159 edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
160 val32 &= ~LNK_CTRL_CRCFEN;
161 edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
163 /* Disable CRC Sync Flood on link side B */
164 edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
165 val32 &= ~LNK_CTRL_CRCFEN;
166 edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
169 static void amd8131_pcix_check(struct edac_pci_ctl_info *edac_dev)
171 struct amd8131_dev_info *dev_info = edac_dev->pvt_info;
172 struct pci_dev *dev = dev_info->dev;
175 /* Check PCI-X Bridge Memory Base-Limit Register for errors */
176 edac_pci_read_dword(dev, REG_MEM_LIM, &val32);
177 if (val32 & MEM_LIMIT_MASK) {
178 printk(KERN_INFO "Error(s) in mem limit register "
179 "on %s bridge\n", dev_info->ctl_name);
180 printk(KERN_INFO "DPE: %d, RSE: %d, RMA: %d\n"
181 "RTA: %d, STA: %d, MDPE: %d\n",
182 val32 & MEM_LIMIT_DPE,
183 val32 & MEM_LIMIT_RSE,
184 val32 & MEM_LIMIT_RMA,
185 val32 & MEM_LIMIT_RTA,
186 val32 & MEM_LIMIT_STA,
187 val32 & MEM_LIMIT_MDPE);
189 val32 |= MEM_LIMIT_MASK;
190 edac_pci_write_dword(dev, REG_MEM_LIM, val32);
192 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
195 /* Check if Discard Timer timed out */
196 edac_pci_read_dword(dev, REG_INT_CTLR, &val32);
197 if (val32 & INT_CTLR_DTS) {
198 printk(KERN_INFO "Error(s) in interrupt and control register "
199 "on %s bridge\n", dev_info->ctl_name);
200 printk(KERN_INFO "DTS: %d\n", val32 & INT_CTLR_DTS);
202 val32 |= INT_CTLR_DTS;
203 edac_pci_write_dword(dev, REG_INT_CTLR, val32);
205 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
208 /* Check if CRC error happens on link side A */
209 edac_pci_read_dword(dev, REG_LNK_CTRL_A, &val32);
210 if (val32 & LNK_CTRL_CRCERR_A) {
211 printk(KERN_INFO "Error(s) in link conf and control register "
212 "on %s bridge\n", dev_info->ctl_name);
213 printk(KERN_INFO "CRCERR: %d\n", val32 & LNK_CTRL_CRCERR_A);
215 val32 |= LNK_CTRL_CRCERR_A;
216 edac_pci_write_dword(dev, REG_LNK_CTRL_A, val32);
218 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
221 /* Check if CRC error happens on link side B */
222 edac_pci_read_dword(dev, REG_LNK_CTRL_B, &val32);
223 if (val32 & LNK_CTRL_CRCERR_B) {
224 printk(KERN_INFO "Error(s) in link conf and control register "
225 "on %s bridge\n", dev_info->ctl_name);
226 printk(KERN_INFO "CRCERR: %d\n", val32 & LNK_CTRL_CRCERR_B);
228 val32 |= LNK_CTRL_CRCERR_B;
229 edac_pci_write_dword(dev, REG_LNK_CTRL_B, val32);
231 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
235 static struct amd8131_info amd8131_chipset = {
236 .err_dev = PCI_DEVICE_ID_AMD_8131_APIC,
237 .devices = amd8131_devices,
238 .init = amd8131_pcix_init,
239 .exit = amd8131_pcix_exit,
240 .check = amd8131_pcix_check,
244 * There are 4 PCIX Bridges on ATCA-6101 that share the same PCI Device ID,
245 * so amd8131_probe() would be called by kernel 4 times, with different
246 * address of pci_dev for each of them each time.
248 static int amd8131_probe(struct pci_dev *dev, const struct pci_device_id *id)
250 struct amd8131_dev_info *dev_info;
252 for (dev_info = amd8131_chipset.devices; dev_info->inst != NO_BRIDGE;
254 if (dev_info->devfn == dev->devfn)
257 if (dev_info->inst == NO_BRIDGE) /* should never happen */
261 * We can't call pci_get_device() as we are used to do because
262 * there are 4 of them but pci_dev_get() instead.
264 dev_info->dev = pci_dev_get(dev);
266 if (pci_enable_device(dev_info->dev)) {
267 pci_dev_put(dev_info->dev);
268 printk(KERN_ERR "failed to enable:"
269 "vendor %x, device %x, devfn %x, name %s\n",
270 PCI_VENDOR_ID_AMD, amd8131_chipset.err_dev,
271 dev_info->devfn, dev_info->ctl_name);
276 * we do not allocate extra private structure for
277 * edac_pci_ctl_info, but make use of existing
280 dev_info->edac_idx = edac_pci_alloc_index();
281 dev_info->edac_dev = edac_pci_alloc_ctl_info(0, dev_info->ctl_name);
282 if (!dev_info->edac_dev)
285 dev_info->edac_dev->pvt_info = dev_info;
286 dev_info->edac_dev->dev = &dev_info->dev->dev;
287 dev_info->edac_dev->mod_name = AMD8131_EDAC_MOD_STR;
288 dev_info->edac_dev->ctl_name = dev_info->ctl_name;
289 dev_info->edac_dev->dev_name = dev_name(&dev_info->dev->dev);
291 if (edac_op_state == EDAC_OPSTATE_POLL)
292 dev_info->edac_dev->edac_check = amd8131_chipset.check;
294 if (amd8131_chipset.init)
295 amd8131_chipset.init(dev_info);
297 if (edac_pci_add_device(dev_info->edac_dev, dev_info->edac_idx) > 0) {
298 printk(KERN_ERR "failed edac_pci_add_device() for %s\n",
300 edac_pci_free_ctl_info(dev_info->edac_dev);
304 printk(KERN_INFO "added one device on AMD8131 "
305 "vendor %x, device %x, devfn %x, name %s\n",
306 PCI_VENDOR_ID_AMD, amd8131_chipset.err_dev,
307 dev_info->devfn, dev_info->ctl_name);
312 static void amd8131_remove(struct pci_dev *dev)
314 struct amd8131_dev_info *dev_info;
316 for (dev_info = amd8131_chipset.devices; dev_info->inst != NO_BRIDGE;
318 if (dev_info->devfn == dev->devfn)
321 if (dev_info->inst == NO_BRIDGE) /* should never happen */
324 if (dev_info->edac_dev) {
325 edac_pci_del_device(dev_info->edac_dev->dev);
326 edac_pci_free_ctl_info(dev_info->edac_dev);
329 if (amd8131_chipset.exit)
330 amd8131_chipset.exit(dev_info);
332 pci_dev_put(dev_info->dev);
335 static const struct pci_device_id amd8131_edac_pci_tbl[] = {
337 PCI_VEND_DEV(AMD, 8131_BRIDGE),
338 .subvendor = PCI_ANY_ID,
339 .subdevice = PCI_ANY_ID,
346 } /* table is NULL-terminated */
348 MODULE_DEVICE_TABLE(pci, amd8131_edac_pci_tbl);
350 static struct pci_driver amd8131_edac_driver = {
351 .name = AMD8131_EDAC_MOD_STR,
352 .probe = amd8131_probe,
353 .remove = amd8131_remove,
354 .id_table = amd8131_edac_pci_tbl,
357 static int __init amd8131_edac_init(void)
359 printk(KERN_INFO "AMD8131 EDAC driver " AMD8131_EDAC_REVISION "\n");
360 printk(KERN_INFO "\t(c) 2008 Wind River Systems, Inc.\n");
362 /* Only POLL mode supported so far */
363 edac_op_state = EDAC_OPSTATE_POLL;
365 return pci_register_driver(&amd8131_edac_driver);
368 static void __exit amd8131_edac_exit(void)
370 pci_unregister_driver(&amd8131_edac_driver);
373 module_init(amd8131_edac_init);
374 module_exit(amd8131_edac_exit);
376 MODULE_LICENSE("GPL");
377 MODULE_AUTHOR("Cao Qingtao <qingtao.cao@windriver.com>\n");
378 MODULE_DESCRIPTION("AMD8131 HyperTransport PCI-X Tunnel EDAC kernel module");