i7core_edac: Better describe the supported devices
[pandora-kernel.git] / drivers / edac / i7core_edac.c
index cd51709..6b8b7b4 100644 (file)
@@ -1,9 +1,14 @@
-/* Intel 7 core  Memory Controller kernel module (Nehalem)
+/* Intel i7 core/Nehalem Memory Controller kernel module
+ *
+ * This driver supports yhe memory controllers found on the Intel
+ * processor families i7core, i7core 7xx/8xx, i5core, Xeon 35xx,
+ * Xeon 55xx and Xeon 56xx also known as Nehalem, Nehalem-EP, Lynnfield
+ * and Westmere-EP.
  *
  * This file may be distributed under the terms of the
  * GNU General Public License version 2 only.
  *
- * Copyright (c) 2009 by:
+ * Copyright (c) 2009-2010 by:
  *      Mauro Carvalho Chehab <mchehab@redhat.com>
  *
  * Red Hat Inc. http://www.redhat.com
@@ -206,6 +211,11 @@ struct pci_id_descr {
        int                     optional;
 };
 
+struct pci_id_table {
+       struct pci_id_descr     *descr;
+       int                     n_devs;
+};
+
 struct i7core_dev {
        struct list_head        list;
        u8                      socket;
@@ -262,7 +272,7 @@ static DEFINE_MUTEX(i7core_edac_lock);
        .func = (function),                     \
        .dev_id = (device_id)
 
-struct pci_id_descr pci_dev_descr_i7core[] = {
+struct pci_id_descr pci_dev_descr_i7core_nehalem[] = {
                /* Memory controller */
        { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR)     },
        { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD)  },
@@ -321,6 +331,44 @@ struct pci_id_descr pci_dev_descr_lynnfield[] = {
        { PCI_DESCR( 0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE)     },
 };
 
+struct pci_id_descr pci_dev_descr_i7core_westmere[] = {
+               /* Memory controller */
+       { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MCR_REV2)     },
+       { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TAD_REV2)  },
+                       /* Exists only for RDIMM */
+       { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_RAS_REV2), .optional = 1  },
+       { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_TEST_REV2) },
+
+               /* Channel 0 */
+       { PCI_DESCR(4, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_CTRL_REV2) },
+       { PCI_DESCR(4, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_ADDR_REV2) },
+       { PCI_DESCR(4, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_RANK_REV2) },
+       { PCI_DESCR(4, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH0_TC_REV2)   },
+
+               /* Channel 1 */
+       { PCI_DESCR(5, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_CTRL_REV2) },
+       { PCI_DESCR(5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR_REV2) },
+       { PCI_DESCR(5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK_REV2) },
+       { PCI_DESCR(5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC_REV2)   },
+
+               /* Channel 2 */
+       { PCI_DESCR(6, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_CTRL_REV2) },
+       { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_ADDR_REV2) },
+       { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_RANK_REV2) },
+       { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_TC_REV2)   },
+
+               /* Generic Non-core registers */
+       { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2)  },
+
+};
+
+#define PCI_ID_TABLE_ENTRY(A) { A, ARRAY_SIZE(A) }
+struct pci_id_table pci_dev_table[] = {
+       PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_nehalem),
+       PCI_ID_TABLE_ENTRY(pci_dev_descr_lynnfield),
+       PCI_ID_TABLE_ENTRY(pci_dev_descr_i7core_westmere),
+};
+
 /*
  *     pci_device_id   table for which devices we are looking for
  */
@@ -1170,7 +1218,7 @@ static void i7core_put_all_devices(void)
                i7core_put_devices(i7core_dev);
 }
 
-static void __init i7core_xeon_pci_fixup(int dev_id)
+static void __init i7core_xeon_pci_fixup(struct pci_id_table *table)
 {
        struct pci_dev *pdev = NULL;
        int i;
@@ -1179,10 +1227,13 @@ static void __init i7core_xeon_pci_fixup(int dev_id)
         * aren't announced by acpi. So, we need to use a legacy scan probing
         * to detect them
         */
-       pdev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
-       if (unlikely(!pdev)) {
-               for (i = 0; i < MAX_SOCKET_BUSES; i++)
-                       pcibios_scan_specific_bus(255-i);
+       while (table && table->descr) {
+               pdev = pci_get_device(PCI_VENDOR_ID_INTEL, table->descr[0].dev_id, NULL);
+               if (unlikely(!pdev)) {
+                       for (i = 0; i < MAX_SOCKET_BUSES; i++)
+                               pcibios_scan_specific_bus(255-i);
+               }
+               table++;
        }
 }
 
@@ -1227,6 +1278,9 @@ int i7core_get_onedevice(struct pci_dev **prev, int devno,
                if (dev_descr->optional)
                        return 0;
 
+               if (devno == 0)
+                       return -ENODEV;
+
                i7core_printk(KERN_ERR,
                        "Device not found: dev %02x.%d PCI ID %04x:%04x\n",
                        dev_descr->dev, dev_descr->func,
@@ -1302,24 +1356,34 @@ int i7core_get_onedevice(struct pci_dev **prev, int devno,
        return 0;
 }
 
-static int i7core_get_devices(struct pci_id_descr dev_descr[], unsigned n_devs)
+static int i7core_get_devices(struct pci_id_table *table)
 {
        int i, rc;
        struct pci_dev *pdev = NULL;
-
-       for (i = 0; i < n_devs; i++) {
-               pdev = NULL;
-               do {
-                       rc = i7core_get_onedevice(&pdev, i, &dev_descr[i],
-                                                 n_devs);
-                       if (rc < 0) {
-                               i7core_put_all_devices();
-                               return -ENODEV;
-                       }
-               } while (pdev);
+       struct pci_id_descr *dev_descr;
+
+       while (table && table->descr) {
+               dev_descr = table->descr;
+               for (i = 0; i < table->n_devs; i++) {
+                       pdev = NULL;
+                       do {
+                               rc = i7core_get_onedevice(&pdev, i, &dev_descr[i],
+                                                         table->n_devs);
+                               if (rc < 0) {
+                                       if (i == 0) {
+                                               i = table->n_devs;
+                                               break;
+                                       }
+                                       i7core_put_all_devices();
+                                       return -ENODEV;
+                               }
+                       } while (pdev);
+               }
+               table++;
        }
 
        return 0;
+       return 0;
 }
 
 static int mci_bind_devs(struct mem_ctl_info *mci,
@@ -1851,7 +1915,8 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev,
        }
 
 fail:
-       edac_mc_free(mci);
+       if (rc < 0)
+               edac_mc_free(mci);
        return rc;
 }
 
@@ -1878,18 +1943,7 @@ static int __devinit i7core_probe(struct pci_dev *pdev,
        /* get the pci devices we want to reserve for our use */
        mutex_lock(&i7core_edac_lock);
 
-       if (pdev->device == PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0) {
-               printk(KERN_INFO "i7core_edac: detected a "
-                                "Lynnfield processor\n");
-               rc = i7core_get_devices(pci_dev_descr_lynnfield,
-                                       ARRAY_SIZE(pci_dev_descr_lynnfield));
-       } else {
-               printk(KERN_INFO "i7core_edac: detected a "
-                                "Nehalem/Nehalem-EP processor\n");
-               rc = i7core_get_devices(pci_dev_descr_i7core,
-                                       ARRAY_SIZE(pci_dev_descr_i7core));
-       }
-
+       rc = i7core_get_devices(pci_dev_table);
        if (unlikely(rc < 0))
                goto fail0;
 
@@ -1988,7 +2042,7 @@ static int __init i7core_init(void)
        /* Ensure that the OPSTATE is set correctly for POLL or NMI */
        opstate_init();
 
-       i7core_xeon_pci_fixup(pci_dev_descr_i7core[0].dev_id);
+       i7core_xeon_pci_fixup(pci_dev_table);
 
        pci_rc = pci_register_driver(&i7core_driver);