aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorislav Petkov <bp@suse.de>2016-05-06 13:44:27 -0400
committerBorislav Petkov <bp@suse.de>2016-05-09 14:41:16 -0400
commit3f37a36b6282621d7c5a99b6911275f989766996 (patch)
tree17840f79d2ff81b6da553c06f55aaf7da531c460
parent953dee9bbd245f5515173126b9cc8b1a2c340797 (diff)
EDAC, amd64_edac: Drop pci_register_driver() use
- remove homegrown instances counting. - take F3 PCI device from amd_nb caching instead of F2 which was used with the PCI core. With those changes, the driver doesn't need to register a PCI driver and relies on the northbridges caching which we do anyway on AMD. Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Yazen Ghannam <yazen.ghannam@amd.com>
-rw-r--r--drivers/edac/amd64_edac.c125
-rw-r--r--drivers/edac/amd64_edac.h2
2 files changed, 44 insertions, 83 deletions
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 651d96c93f22..624e2f78339c 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -15,11 +15,6 @@ module_param(ecc_enable_override, int, 0644);
15 15
16static struct msr __percpu *msrs; 16static struct msr __percpu *msrs;
17 17
18/*
19 * count successfully initialized driver instances for setup_pci_device()
20 */
21static atomic_t drv_instances = ATOMIC_INIT(0);
22
23/* Per-node stuff */ 18/* Per-node stuff */
24static struct ecc_settings **ecc_stngs; 19static struct ecc_settings **ecc_stngs;
25 20
@@ -1918,7 +1913,7 @@ static struct amd64_family_type family_types[] = {
1918 [K8_CPUS] = { 1913 [K8_CPUS] = {
1919 .ctl_name = "K8", 1914 .ctl_name = "K8",
1920 .f1_id = PCI_DEVICE_ID_AMD_K8_NB_ADDRMAP, 1915 .f1_id = PCI_DEVICE_ID_AMD_K8_NB_ADDRMAP,
1921 .f3_id = PCI_DEVICE_ID_AMD_K8_NB_MISC, 1916 .f2_id = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
1922 .ops = { 1917 .ops = {
1923 .early_channel_count = k8_early_channel_count, 1918 .early_channel_count = k8_early_channel_count,
1924 .map_sysaddr_to_csrow = k8_map_sysaddr_to_csrow, 1919 .map_sysaddr_to_csrow = k8_map_sysaddr_to_csrow,
@@ -1928,7 +1923,7 @@ static struct amd64_family_type family_types[] = {
1928 [F10_CPUS] = { 1923 [F10_CPUS] = {
1929 .ctl_name = "F10h", 1924 .ctl_name = "F10h",
1930 .f1_id = PCI_DEVICE_ID_AMD_10H_NB_MAP, 1925 .f1_id = PCI_DEVICE_ID_AMD_10H_NB_MAP,
1931 .f3_id = PCI_DEVICE_ID_AMD_10H_NB_MISC, 1926 .f2_id = PCI_DEVICE_ID_AMD_10H_NB_DRAM,
1932 .ops = { 1927 .ops = {
1933 .early_channel_count = f1x_early_channel_count, 1928 .early_channel_count = f1x_early_channel_count,
1934 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, 1929 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
@@ -1938,7 +1933,7 @@ static struct amd64_family_type family_types[] = {
1938 [F15_CPUS] = { 1933 [F15_CPUS] = {
1939 .ctl_name = "F15h", 1934 .ctl_name = "F15h",
1940 .f1_id = PCI_DEVICE_ID_AMD_15H_NB_F1, 1935 .f1_id = PCI_DEVICE_ID_AMD_15H_NB_F1,
1941 .f3_id = PCI_DEVICE_ID_AMD_15H_NB_F3, 1936 .f2_id = PCI_DEVICE_ID_AMD_15H_NB_F2,
1942 .ops = { 1937 .ops = {
1943 .early_channel_count = f1x_early_channel_count, 1938 .early_channel_count = f1x_early_channel_count,
1944 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, 1939 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
@@ -1948,7 +1943,7 @@ static struct amd64_family_type family_types[] = {
1948 [F15_M30H_CPUS] = { 1943 [F15_M30H_CPUS] = {
1949 .ctl_name = "F15h_M30h", 1944 .ctl_name = "F15h_M30h",
1950 .f1_id = PCI_DEVICE_ID_AMD_15H_M30H_NB_F1, 1945 .f1_id = PCI_DEVICE_ID_AMD_15H_M30H_NB_F1,
1951 .f3_id = PCI_DEVICE_ID_AMD_15H_M30H_NB_F3, 1946 .f2_id = PCI_DEVICE_ID_AMD_15H_M30H_NB_F2,
1952 .ops = { 1947 .ops = {
1953 .early_channel_count = f1x_early_channel_count, 1948 .early_channel_count = f1x_early_channel_count,
1954 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, 1949 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
@@ -1958,7 +1953,7 @@ static struct amd64_family_type family_types[] = {
1958 [F15_M60H_CPUS] = { 1953 [F15_M60H_CPUS] = {
1959 .ctl_name = "F15h_M60h", 1954 .ctl_name = "F15h_M60h",
1960 .f1_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F1, 1955 .f1_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F1,
1961 .f3_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F3, 1956 .f2_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F2,
1962 .ops = { 1957 .ops = {
1963 .early_channel_count = f1x_early_channel_count, 1958 .early_channel_count = f1x_early_channel_count,
1964 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, 1959 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
@@ -1968,7 +1963,7 @@ static struct amd64_family_type family_types[] = {
1968 [F16_CPUS] = { 1963 [F16_CPUS] = {
1969 .ctl_name = "F16h", 1964 .ctl_name = "F16h",
1970 .f1_id = PCI_DEVICE_ID_AMD_16H_NB_F1, 1965 .f1_id = PCI_DEVICE_ID_AMD_16H_NB_F1,
1971 .f3_id = PCI_DEVICE_ID_AMD_16H_NB_F3, 1966 .f2_id = PCI_DEVICE_ID_AMD_16H_NB_F2,
1972 .ops = { 1967 .ops = {
1973 .early_channel_count = f1x_early_channel_count, 1968 .early_channel_count = f1x_early_channel_count,
1974 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, 1969 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
@@ -1978,7 +1973,7 @@ static struct amd64_family_type family_types[] = {
1978 [F16_M30H_CPUS] = { 1973 [F16_M30H_CPUS] = {
1979 .ctl_name = "F16h_M30h", 1974 .ctl_name = "F16h_M30h",
1980 .f1_id = PCI_DEVICE_ID_AMD_16H_M30H_NB_F1, 1975 .f1_id = PCI_DEVICE_ID_AMD_16H_M30H_NB_F1,
1981 .f3_id = PCI_DEVICE_ID_AMD_16H_M30H_NB_F3, 1976 .f2_id = PCI_DEVICE_ID_AMD_16H_M30H_NB_F2,
1982 .ops = { 1977 .ops = {
1983 .early_channel_count = f1x_early_channel_count, 1978 .early_channel_count = f1x_early_channel_count,
1984 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, 1979 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
@@ -2227,13 +2222,13 @@ static inline void decode_bus_error(int node_id, struct mce *m)
2227} 2222}
2228 2223
2229/* 2224/*
2230 * Use pvt->F2 which contains the F2 CPU PCI device to get the related 2225 * Use pvt->F3 which contains the F3 CPU PCI device to get the related
2231 * F1 (AddrMap) and F3 (Misc) devices. Return negative value on error. 2226 * F1 (AddrMap) and F2 (Dct) devices. Return negative value on error.
2232 */ 2227 */
2233static int reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 f1_id, u16 f3_id) 2228static int reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 f1_id, u16 f2_id)
2234{ 2229{
2235 /* Reserve the ADDRESS MAP Device */ 2230 /* Reserve the ADDRESS MAP Device */
2236 pvt->F1 = pci_get_related_function(pvt->F2->vendor, f1_id, pvt->F2); 2231 pvt->F1 = pci_get_related_function(pvt->F3->vendor, f1_id, pvt->F3);
2237 if (!pvt->F1) { 2232 if (!pvt->F1) {
2238 amd64_err("error address map device not found: " 2233 amd64_err("error address map device not found: "
2239 "vendor %x device 0x%x (broken BIOS?)\n", 2234 "vendor %x device 0x%x (broken BIOS?)\n",
@@ -2241,15 +2236,15 @@ static int reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 f1_id, u16 f3_id)
2241 return -ENODEV; 2236 return -ENODEV;
2242 } 2237 }
2243 2238
2244 /* Reserve the MISC Device */ 2239 /* Reserve the DCT Device */
2245 pvt->F3 = pci_get_related_function(pvt->F2->vendor, f3_id, pvt->F2); 2240 pvt->F2 = pci_get_related_function(pvt->F3->vendor, f2_id, pvt->F3);
2246 if (!pvt->F3) { 2241 if (!pvt->F2) {
2247 pci_dev_put(pvt->F1); 2242 pci_dev_put(pvt->F1);
2248 pvt->F1 = NULL; 2243 pvt->F1 = NULL;
2249 2244
2250 amd64_err("error F3 device not found: " 2245 amd64_err("error F2 device not found: "
2251 "vendor %x device 0x%x (broken BIOS?)\n", 2246 "vendor %x device 0x%x (broken BIOS?)\n",
2252 PCI_VENDOR_ID_AMD, f3_id); 2247 PCI_VENDOR_ID_AMD, f2_id);
2253 2248
2254 return -ENODEV; 2249 return -ENODEV;
2255 } 2250 }
@@ -2263,7 +2258,7 @@ static int reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 f1_id, u16 f3_id)
2263static void free_mc_sibling_devs(struct amd64_pvt *pvt) 2258static void free_mc_sibling_devs(struct amd64_pvt *pvt)
2264{ 2259{
2265 pci_dev_put(pvt->F1); 2260 pci_dev_put(pvt->F1);
2266 pci_dev_put(pvt->F3); 2261 pci_dev_put(pvt->F2);
2267} 2262}
2268 2263
2269/* 2264/*
@@ -2778,14 +2773,14 @@ static const struct attribute_group *amd64_edac_attr_groups[] = {
2778 NULL 2773 NULL
2779}; 2774};
2780 2775
2781static int init_one_instance(struct pci_dev *F2) 2776static int init_one_instance(unsigned int nid)
2782{ 2777{
2783 struct amd64_pvt *pvt = NULL; 2778 struct pci_dev *F3 = node_to_amd_nb(nid)->misc;
2784 struct amd64_family_type *fam_type = NULL; 2779 struct amd64_family_type *fam_type = NULL;
2785 struct mem_ctl_info *mci = NULL; 2780 struct mem_ctl_info *mci = NULL;
2786 struct edac_mc_layer layers[2]; 2781 struct edac_mc_layer layers[2];
2782 struct amd64_pvt *pvt = NULL;
2787 int err = 0, ret; 2783 int err = 0, ret;
2788 u16 nid = amd_pci_dev_to_node_id(F2);
2789 2784
2790 ret = -ENOMEM; 2785 ret = -ENOMEM;
2791 pvt = kzalloc(sizeof(struct amd64_pvt), GFP_KERNEL); 2786 pvt = kzalloc(sizeof(struct amd64_pvt), GFP_KERNEL);
@@ -2793,7 +2788,7 @@ static int init_one_instance(struct pci_dev *F2)
2793 goto err_ret; 2788 goto err_ret;
2794 2789
2795 pvt->mc_node_id = nid; 2790 pvt->mc_node_id = nid;
2796 pvt->F2 = F2; 2791 pvt->F3 = F3;
2797 2792
2798 ret = -EINVAL; 2793 ret = -EINVAL;
2799 fam_type = per_family_init(pvt); 2794 fam_type = per_family_init(pvt);
@@ -2801,7 +2796,7 @@ static int init_one_instance(struct pci_dev *F2)
2801 goto err_free; 2796 goto err_free;
2802 2797
2803 ret = -ENODEV; 2798 ret = -ENODEV;
2804 err = reserve_mc_sibling_devs(pvt, fam_type->f1_id, fam_type->f3_id); 2799 err = reserve_mc_sibling_devs(pvt, fam_type->f1_id, fam_type->f2_id);
2805 if (err) 2800 if (err)
2806 goto err_free; 2801 goto err_free;
2807 2802
@@ -2836,7 +2831,7 @@ static int init_one_instance(struct pci_dev *F2)
2836 goto err_siblings; 2831 goto err_siblings;
2837 2832
2838 mci->pvt_info = pvt; 2833 mci->pvt_info = pvt;
2839 mci->pdev = &pvt->F2->dev; 2834 mci->pdev = &pvt->F3->dev;
2840 2835
2841 setup_mci_misc_attrs(mci, fam_type); 2836 setup_mci_misc_attrs(mci, fam_type);
2842 2837
@@ -2855,8 +2850,6 @@ static int init_one_instance(struct pci_dev *F2)
2855 2850
2856 amd_register_ecc_decoder(decode_bus_error); 2851 amd_register_ecc_decoder(decode_bus_error);
2857 2852
2858 atomic_inc(&drv_instances);
2859
2860 return 0; 2853 return 0;
2861 2854
2862err_add_mc: 2855err_add_mc:
@@ -2872,19 +2865,11 @@ err_ret:
2872 return ret; 2865 return ret;
2873} 2866}
2874 2867
2875static int probe_one_instance(struct pci_dev *pdev, 2868static int probe_one_instance(unsigned int nid)
2876 const struct pci_device_id *mc_type)
2877{ 2869{
2878 u16 nid = amd_pci_dev_to_node_id(pdev);
2879 struct pci_dev *F3 = node_to_amd_nb(nid)->misc; 2870 struct pci_dev *F3 = node_to_amd_nb(nid)->misc;
2880 struct ecc_settings *s; 2871 struct ecc_settings *s;
2881 int ret = 0; 2872 int ret;
2882
2883 ret = pci_enable_device(pdev);
2884 if (ret < 0) {
2885 edac_dbg(0, "ret=%d\n", ret);
2886 return -EIO;
2887 }
2888 2873
2889 ret = -ENOMEM; 2874 ret = -ENOMEM;
2890 s = kzalloc(sizeof(struct ecc_settings), GFP_KERNEL); 2875 s = kzalloc(sizeof(struct ecc_settings), GFP_KERNEL);
@@ -2905,7 +2890,7 @@ static int probe_one_instance(struct pci_dev *pdev,
2905 goto err_enable; 2890 goto err_enable;
2906 } 2891 }
2907 2892
2908 ret = init_one_instance(pdev); 2893 ret = init_one_instance(nid);
2909 if (ret < 0) { 2894 if (ret < 0) {
2910 amd64_err("Error probing instance: %d\n", nid); 2895 amd64_err("Error probing instance: %d\n", nid);
2911 restore_ecc_error_reporting(s, nid, F3); 2896 restore_ecc_error_reporting(s, nid, F3);
@@ -2921,19 +2906,18 @@ err_out:
2921 return ret; 2906 return ret;
2922} 2907}
2923 2908
2924static void remove_one_instance(struct pci_dev *pdev) 2909static void remove_one_instance(unsigned int nid)
2925{ 2910{
2926 struct mem_ctl_info *mci;
2927 struct amd64_pvt *pvt;
2928 u16 nid = amd_pci_dev_to_node_id(pdev);
2929 struct pci_dev *F3 = node_to_amd_nb(nid)->misc; 2911 struct pci_dev *F3 = node_to_amd_nb(nid)->misc;
2930 struct ecc_settings *s = ecc_stngs[nid]; 2912 struct ecc_settings *s = ecc_stngs[nid];
2913 struct mem_ctl_info *mci;
2914 struct amd64_pvt *pvt;
2931 2915
2932 mci = find_mci_by_dev(&pdev->dev); 2916 mci = find_mci_by_dev(&F3->dev);
2933 WARN_ON(!mci); 2917 WARN_ON(!mci);
2934 2918
2935 /* Remove from EDAC CORE tracking list */ 2919 /* Remove from EDAC CORE tracking list */
2936 mci = edac_mc_del_mc(&pdev->dev); 2920 mci = edac_mc_del_mc(&F3->dev);
2937 if (!mci) 2921 if (!mci)
2938 return; 2922 return;
2939 2923
@@ -2957,31 +2941,6 @@ static void remove_one_instance(struct pci_dev *pdev)
2957 edac_mc_free(mci); 2941 edac_mc_free(mci);
2958} 2942}
2959 2943
2960/*
2961 * This table is part of the interface for loading drivers for PCI devices. The
2962 * PCI core identifies what devices are on a system during boot, and then
2963 * inquiry this table to see if this driver is for a given device found.
2964 */
2965static const struct pci_device_id amd64_pci_table[] = {
2966 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL) },
2967 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_10H_NB_DRAM) },
2968 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F2) },
2969 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F2) },
2970 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F2) },
2971 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F2) },
2972 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F2) },
2973 {0, }
2974};
2975MODULE_DEVICE_TABLE(pci, amd64_pci_table);
2976
2977static struct pci_driver amd64_pci_driver = {
2978 .name = EDAC_MOD_STR,
2979 .probe = probe_one_instance,
2980 .remove = remove_one_instance,
2981 .id_table = amd64_pci_table,
2982 .driver.probe_type = PROBE_FORCE_SYNCHRONOUS,
2983};
2984
2985static void setup_pci_device(void) 2944static void setup_pci_device(void)
2986{ 2945{
2987 struct mem_ctl_info *mci; 2946 struct mem_ctl_info *mci;
@@ -3005,6 +2964,7 @@ static void setup_pci_device(void)
3005static int __init amd64_edac_init(void) 2964static int __init amd64_edac_init(void)
3006{ 2965{
3007 int err = -ENODEV; 2966 int err = -ENODEV;
2967 int i;
3008 2968
3009 opstate_init(); 2969 opstate_init();
3010 2970
@@ -3020,13 +2980,14 @@ static int __init amd64_edac_init(void)
3020 if (!msrs) 2980 if (!msrs)
3021 goto err_free; 2981 goto err_free;
3022 2982
3023 err = pci_register_driver(&amd64_pci_driver); 2983 for (i = 0; i < amd_nb_num(); i++)
3024 if (err) 2984 if (probe_one_instance(i)) {
3025 goto err_pci; 2985 /* unwind properly */
2986 while (--i >= 0)
2987 remove_one_instance(i);
3026 2988
3027 err = -ENODEV; 2989 goto err_pci;
3028 if (!atomic_read(&drv_instances)) 2990 }
3029 goto err_no_instances;
3030 2991
3031 setup_pci_device(); 2992 setup_pci_device();
3032 2993
@@ -3038,9 +2999,6 @@ static int __init amd64_edac_init(void)
3038 2999
3039 return 0; 3000 return 0;
3040 3001
3041err_no_instances:
3042 pci_unregister_driver(&amd64_pci_driver);
3043
3044err_pci: 3002err_pci:
3045 msrs_free(msrs); 3003 msrs_free(msrs);
3046 msrs = NULL; 3004 msrs = NULL;
@@ -3055,10 +3013,13 @@ err_ret:
3055 3013
3056static void __exit amd64_edac_exit(void) 3014static void __exit amd64_edac_exit(void)
3057{ 3015{
3016 int i;
3017
3058 if (pci_ctl) 3018 if (pci_ctl)
3059 edac_pci_release_generic_ctl(pci_ctl); 3019 edac_pci_release_generic_ctl(pci_ctl);
3060 3020
3061 pci_unregister_driver(&amd64_pci_driver); 3021 for (i = 0; i < amd_nb_num(); i++)
3022 remove_one_instance(i);
3062 3023
3063 kfree(ecc_stngs); 3024 kfree(ecc_stngs);
3064 ecc_stngs = NULL; 3025 ecc_stngs = NULL;
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index c0f248f3aaf9..c08870479054 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -422,7 +422,7 @@ struct low_ops {
422 422
423struct amd64_family_type { 423struct amd64_family_type {
424 const char *ctl_name; 424 const char *ctl_name;
425 u16 f1_id, f3_id; 425 u16 f1_id, f2_id;
426 struct low_ops ops; 426 struct low_ops ops;
427}; 427};
428 428