i7core_edac: return -ENODEV when devices were already probed
[pandora-kernel.git] / drivers / edac / i7core_edac.c
index 795df30..362861c 100644 (file)
@@ -243,8 +243,6 @@ struct i7core_pvt {
        struct i7core_inject    inject;
        struct i7core_channel   channel[NUM_CHANS];
 
-       int             channels; /* Number of active channels */
-
        int             ce_count_available;
        int             csrow_map[NUM_CHANS][MAX_DIMMS];
 
@@ -283,7 +281,8 @@ static const 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)  },
-                       /* Exists only for RDIMM */
+
+               /* Exists only for RDIMM */
        { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS), .optional = 1  },
        { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) },
 
@@ -304,16 +303,6 @@ static const struct pci_id_descr pci_dev_descr_i7core_nehalem[] = {
        { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) },
        { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) },
        { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC)   },
-
-               /* Generic Non-core registers */
-       /*
-        * This is the PCI device on i7core and on Xeon 35xx (8086:2c41)
-        * On Xeon 55xx, however, it has a different id (8086:2c40). So,
-        * the probing code needs to test for the other address in case of
-        * failure of this one
-        */
-       { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_I7_NONCORE)  },
-
 };
 
 static const struct pci_id_descr pci_dev_descr_lynnfield[] = {
@@ -330,12 +319,6 @@ static const struct pci_id_descr pci_dev_descr_lynnfield[] = {
        { PCI_DESCR( 5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR) },
        { PCI_DESCR( 5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK) },
        { PCI_DESCR( 5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC)   },
-
-       /*
-        * This is the PCI device has an alternate address on some
-        * processors like Core i7 860
-        */
-       { PCI_DESCR( 0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE)     },
 };
 
 static const struct pci_id_descr pci_dev_descr_i7core_westmere[] = {
@@ -363,10 +346,6 @@ static const struct pci_id_descr pci_dev_descr_i7core_westmere[] = {
        { 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) { .descr=A, .n_devs = ARRAY_SIZE(A) }
@@ -374,6 +353,7 @@ static const 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),
+       {0,}                    /* 0 terminated list. */
 };
 
 /*
@@ -580,12 +560,13 @@ static int i7core_get_active_channels(const u8 socket, unsigned *channels,
        return 0;
 }
 
-static int get_dimm_config(const struct mem_ctl_info *mci, int *csrow)
+static int get_dimm_config(const struct mem_ctl_info *mci)
 {
        struct i7core_pvt *pvt = mci->pvt_info;
        struct csrow_info *csr;
        struct pci_dev *pdev;
        int i, j;
+       int csrow = 0;
        unsigned long last_page = 0;
        enum edac_type mode;
        enum mem_type mtype;
@@ -701,7 +682,7 @@ static int get_dimm_config(const struct mem_ctl_info *mci, int *csrow)
 
                        npages = MiB_TO_PAGES(size);
 
-                       csr = &mci->csrows[*csrow];
+                       csr = &mci->csrows[csrow];
                        csr->first_page = last_page + 1;
                        last_page += npages;
                        csr->last_page = last_page;
@@ -709,13 +690,13 @@ static int get_dimm_config(const struct mem_ctl_info *mci, int *csrow)
 
                        csr->page_mask = 0;
                        csr->grain = 8;
-                       csr->csrow_idx = *csrow;
+                       csr->csrow_idx = csrow;
                        csr->nr_channels = 1;
 
                        csr->channels[0].chan_idx = i;
                        csr->channels[0].ce_count = 0;
 
-                       pvt->csrow_map[i][j] = *csrow;
+                       pvt->csrow_map[i][j] = csrow;
 
                        switch (banks) {
                        case 4:
@@ -734,7 +715,7 @@ static int get_dimm_config(const struct mem_ctl_info *mci, int *csrow)
                        csr->edac_mode = mode;
                        csr->mtype = mtype;
 
-                       (*csrow)++;
+                       csrow++;
                }
 
                pci_read_config_dword(pdev, MC_SAG_CH_0, &value[0]);
@@ -1343,20 +1324,6 @@ static int i7core_get_onedevice(struct pci_dev **prev,
        pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
                              dev_descr->dev_id, *prev);
 
-       /*
-        * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core regs
-        * is at addr 8086:2c40, instead of 8086:2c41. So, we need
-        * to probe for the alternate address in case of failure
-        */
-       if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev)
-               pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                                     PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev);
-
-       if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE && !pdev)
-               pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
-                                     PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT,
-                                     *prev);
-
        if (!pdev) {
                if (*prev) {
                        *prev = pdev;
@@ -1429,6 +1396,13 @@ static int i7core_get_onedevice(struct pci_dev **prev,
                dev_descr->func,
                PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
 
+       /*
+        * As stated on drivers/pci/search.c, the reference count for
+        * @from is always decremented if it is not %NULL. So, as we need
+        * to get all devices up to null, we need to do a get for the device
+        */
+       pci_dev_get(pdev);
+
        *prev = pdev;
 
        return 0;
@@ -1436,14 +1410,13 @@ static int i7core_get_onedevice(struct pci_dev **prev,
 
 static int i7core_get_all_devices(void)
 {
-       int i, j, rc, last_bus;
+       int i, rc, last_bus;
        struct pci_dev *pdev = NULL;
-       const struct pci_id_table *table;
+       const struct pci_id_table *table = pci_dev_table;
 
        last_bus = i7core_pci_lastbus();
 
-       for (j = 0; j < ARRAY_SIZE(pci_dev_table); j++) {
-               table = &pci_dev_table[j];
+       while (table && table->descr) {
                for (i = 0; i < table->n_devs; i++) {
                        pdev = NULL;
                        do {
@@ -1459,6 +1432,7 @@ static int i7core_get_all_devices(void)
                                }
                        } while (pdev);
                }
+               table++;
        }
 
        return 0;
@@ -1951,7 +1925,6 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)
 {
        struct mem_ctl_info *mci;
        struct i7core_pvt *pvt;
-       int csrow = 0;
        int rc, channels, csrows;
 
        /* Check the number of active and not disabled channels */
@@ -1970,6 +1943,10 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)
        pvt = mci->pvt_info;
        memset(pvt, 0, sizeof(*pvt));
 
+       /* Associates i7core_dev and mci for future usage */
+       pvt->i7core_dev = i7core_dev;
+       i7core_dev->mci = mci;
+
        /*
         * FIXME: how to handle RDDR3 at MCI level? It is possible to have
         * Mixed RDDR3/UDDR3 with Nehalem, provided that they are on different
@@ -1996,7 +1973,7 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)
                mci->mc_driver_sysfs_attributes = i7core_sysfs_udimm_attrs;
 
        /* Get dimm basic config */
-       get_dimm_config(mci, &csrow);
+       get_dimm_config(mci);
        /* record ptr to the generic device */
        mci->dev = &i7core_dev->pdev[0]->dev;
        /* Set the function pointer to an actual operation function */
@@ -2035,10 +2012,6 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)
                goto fail1;
        }
 
-       /* Associates i7core_dev and mci for future usage */
-       pvt->i7core_dev = i7core_dev;
-       i7core_dev->mci = mci;
-
        return 0;
 
 fail1:
@@ -2073,7 +2046,7 @@ static int __devinit i7core_probe(struct pci_dev *pdev,
         */
        if (unlikely(probed >= 1)) {
                mutex_unlock(&i7core_edac_lock);
-               return -EINVAL;
+               return -ENODEV;
        }
        probed++;
 
@@ -2093,10 +2066,9 @@ static int __devinit i7core_probe(struct pci_dev *pdev,
        return 0;
 
 fail1:
-       list_for_each_entry(i7core_dev, &i7core_edac_list, list) {
-               if (i7core_dev->mci)
-                       i7core_unregister_mci(i7core_dev);
-       }
+       list_for_each_entry(i7core_dev, &i7core_edac_list, list)
+               i7core_unregister_mci(i7core_dev);
+
        i7core_put_all_devices();
 fail0:
        mutex_unlock(&i7core_edac_lock);
@@ -2128,10 +2100,8 @@ static void __devexit i7core_remove(struct pci_dev *pdev)
                return;
        }
 
-       list_for_each_entry(i7core_dev, &i7core_edac_list, list) {
-               if (i7core_dev->mci)
-                       i7core_unregister_mci(i7core_dev);
-       }
+       list_for_each_entry(i7core_dev, &i7core_edac_list, list)
+               i7core_unregister_mci(i7core_dev);
 
        /* Release PCI resources */
        i7core_put_all_devices();