i7300_edac.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Intel 7300 class Memory Controllers kernel module (Clarksboro)
  4. *
  5. * Copyright (c) 2010 by:
  6. * Mauro Carvalho Chehab
  7. *
  8. * Red Hat Inc. https://www.redhat.com
  9. *
  10. * Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet
  11. * http://www.intel.com/Assets/PDF/datasheet/318082.pdf
  12. *
  13. * TODO: The chipset allow checking for PCI Express errors also. Currently,
  14. * the driver covers only memory error errors
  15. *
  16. * This driver uses "csrows" EDAC attribute to represent DIMM slot#
  17. */
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/pci.h>
  21. #include <linux/pci_ids.h>
  22. #include <linux/slab.h>
  23. #include <linux/edac.h>
  24. #include <linux/mmzone.h>
  25. #include <linux/string_choices.h>
  26. #include "edac_module.h"
  27. /*
  28. * Alter this version for the I7300 module when modifications are made
  29. */
  30. #define I7300_REVISION " Ver: 1.0.0"
  31. #define EDAC_MOD_STR "i7300_edac"
  32. #define i7300_printk(level, fmt, arg...) \
  33. edac_printk(level, "i7300", fmt, ##arg)
  34. #define i7300_mc_printk(mci, level, fmt, arg...) \
  35. edac_mc_chipset_printk(mci, level, "i7300", fmt, ##arg)
  36. /***********************************************
  37. * i7300 Limit constants Structs and static vars
  38. ***********************************************/
  39. /*
  40. * Memory topology is organized as:
  41. * Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0)
  42. * Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0)
  43. * Each channel can have to 8 DIMM sets (called as SLOTS)
  44. * Slots should generally be filled in pairs
  45. * Except on Single Channel mode of operation
  46. * just slot 0/channel0 filled on this mode
  47. * On normal operation mode, the two channels on a branch should be
  48. * filled together for the same SLOT#
  49. * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four
  50. * channels on both branches should be filled
  51. */
  52. /* Limits for i7300 */
  53. #define MAX_SLOTS 8
  54. #define MAX_BRANCHES 2
  55. #define MAX_CH_PER_BRANCH 2
  56. #define MAX_CHANNELS (MAX_CH_PER_BRANCH * MAX_BRANCHES)
  57. #define MAX_MIR 3
  58. #define to_channel(ch, branch) ((((branch)) << 1) | (ch))
  59. #define to_csrow(slot, ch, branch) \
  60. (to_channel(ch, branch) | ((slot) << 2))
  61. /* Device name and register DID (Device ID) */
  62. struct i7300_dev_info {
  63. const char *ctl_name; /* name for this device */
  64. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  65. };
  66. /* Table of devices attributes supported by this driver */
  67. static const struct i7300_dev_info i7300_devs[] = {
  68. {
  69. .ctl_name = "I7300",
  70. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
  71. },
  72. };
  73. struct i7300_dimm_info {
  74. int megabytes; /* size, 0 means not present */
  75. };
  76. /* driver private data structure */
  77. struct i7300_pvt {
  78. struct pci_dev *pci_dev_16_0_fsb_ctlr; /* 16.0 */
  79. struct pci_dev *pci_dev_16_1_fsb_addr_map; /* 16.1 */
  80. struct pci_dev *pci_dev_16_2_fsb_err_regs; /* 16.2 */
  81. struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES]; /* 21.0 and 22.0 */
  82. u16 tolm; /* top of low memory */
  83. u64 ambase; /* AMB BAR */
  84. u32 mc_settings; /* Report several settings */
  85. u32 mc_settings_a;
  86. u16 mir[MAX_MIR]; /* Memory Interleave Reg*/
  87. u16 mtr[MAX_SLOTS][MAX_BRANCHES]; /* Memory Technlogy Reg */
  88. u16 ambpresent[MAX_CHANNELS]; /* AMB present regs */
  89. /* DIMM information matrix, allocating architecture maximums */
  90. struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
  91. /* Temporary buffer for use when preparing error messages */
  92. char *tmp_prt_buffer;
  93. };
  94. /* FIXME: Why do we need to have this static? */
  95. static struct edac_pci_ctl_info *i7300_pci;
  96. /***************************************************
  97. * i7300 Register definitions for memory enumeration
  98. ***************************************************/
  99. /*
  100. * Device 16,
  101. * Function 0: System Address (not documented)
  102. * Function 1: Memory Branch Map, Control, Errors Register
  103. */
  104. /* OFFSETS for Function 0 */
  105. #define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
  106. #define MAXCH 0x56 /* Max Channel Number */
  107. #define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
  108. /* OFFSETS for Function 1 */
  109. #define MC_SETTINGS 0x40
  110. #define IS_MIRRORED(mc) ((mc) & (1 << 16))
  111. #define IS_ECC_ENABLED(mc) ((mc) & (1 << 5))
  112. #define IS_RETRY_ENABLED(mc) ((mc) & (1 << 31))
  113. #define IS_SCRBALGO_ENHANCED(mc) ((mc) & (1 << 8))
  114. #define MC_SETTINGS_A 0x58
  115. #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14))
  116. #define TOLM 0x6C
  117. #define MIR0 0x80
  118. #define MIR1 0x84
  119. #define MIR2 0x88
  120. /*
  121. * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
  122. * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
  123. * seems that we cannot use this information directly for the same usage.
  124. * Each memory slot may have up to 2 AMB interfaces, one for income and another
  125. * for outcome interface to the next slot.
  126. * For now, the driver just stores the AMB present registers, but rely only at
  127. * the MTR info to detect memory.
  128. * Datasheet is also not clear about how to map each AMBPRESENT registers to
  129. * one of the 4 available channels.
  130. */
  131. #define AMBPRESENT_0 0x64
  132. #define AMBPRESENT_1 0x66
  133. static const u16 mtr_regs[MAX_SLOTS] = {
  134. 0x80, 0x84, 0x88, 0x8c,
  135. 0x82, 0x86, 0x8a, 0x8e
  136. };
  137. /*
  138. * Defines to extract the vaious fields from the
  139. * MTRx - Memory Technology Registers
  140. */
  141. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 8))
  142. #define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 7))
  143. #define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
  144. #define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 5)) ? 8 : 4)
  145. #define MTR_DIMM_RANKS(mtr) (((mtr) & (1 << 4)) ? 1 : 0)
  146. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  147. #define MTR_DRAM_BANKS_ADDR_BITS 2
  148. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  149. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  150. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  151. /************************************************
  152. * i7300 Register definitions for error detection
  153. ************************************************/
  154. /*
  155. * Device 16.1: FBD Error Registers
  156. */
  157. #define FERR_FAT_FBD 0x98
  158. static const char *ferr_fat_fbd_name[] = {
  159. [22] = "Non-Redundant Fast Reset Timeout",
  160. [2] = ">Tmid Thermal event with intelligent throttling disabled",
  161. [1] = "Memory or FBD configuration CRC read error",
  162. [0] = "Memory Write error on non-redundant retry or "
  163. "FBD configuration Write error on retry",
  164. };
  165. #define GET_FBD_FAT_IDX(fbderr) (((fbderr) >> 28) & 3)
  166. #define FERR_FAT_FBD_ERR_MASK ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 22))
  167. #define FERR_NF_FBD 0xa0
  168. static const char *ferr_nf_fbd_name[] = {
  169. [24] = "DIMM-Spare Copy Completed",
  170. [23] = "DIMM-Spare Copy Initiated",
  171. [22] = "Redundant Fast Reset Timeout",
  172. [21] = "Memory Write error on redundant retry",
  173. [18] = "SPD protocol Error",
  174. [17] = "FBD Northbound parity error on FBD Sync Status",
  175. [16] = "Correctable Patrol Data ECC",
  176. [15] = "Correctable Resilver- or Spare-Copy Data ECC",
  177. [14] = "Correctable Mirrored Demand Data ECC",
  178. [13] = "Correctable Non-Mirrored Demand Data ECC",
  179. [11] = "Memory or FBD configuration CRC read error",
  180. [10] = "FBD Configuration Write error on first attempt",
  181. [9] = "Memory Write error on first attempt",
  182. [8] = "Non-Aliased Uncorrectable Patrol Data ECC",
  183. [7] = "Non-Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  184. [6] = "Non-Aliased Uncorrectable Mirrored Demand Data ECC",
  185. [5] = "Non-Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  186. [4] = "Aliased Uncorrectable Patrol Data ECC",
  187. [3] = "Aliased Uncorrectable Resilver- or Spare-Copy Data ECC",
  188. [2] = "Aliased Uncorrectable Mirrored Demand Data ECC",
  189. [1] = "Aliased Uncorrectable Non-Mirrored Demand Data ECC",
  190. [0] = "Uncorrectable Data ECC on Replay",
  191. };
  192. #define GET_FBD_NF_IDX(fbderr) (((fbderr) >> 28) & 3)
  193. #define FERR_NF_FBD_ERR_MASK ((1 << 24) | (1 << 23) | (1 << 22) | (1 << 21) |\
  194. (1 << 18) | (1 << 17) | (1 << 16) | (1 << 15) |\
  195. (1 << 14) | (1 << 13) | (1 << 11) | (1 << 10) |\
  196. (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
  197. (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
  198. (1 << 1) | (1 << 0))
  199. #define EMASK_FBD 0xa8
  200. #define EMASK_FBD_ERR_MASK ((1 << 27) | (1 << 26) | (1 << 25) | (1 << 24) |\
  201. (1 << 22) | (1 << 21) | (1 << 20) | (1 << 19) |\
  202. (1 << 18) | (1 << 17) | (1 << 16) | (1 << 14) |\
  203. (1 << 13) | (1 << 12) | (1 << 11) | (1 << 10) |\
  204. (1 << 9) | (1 << 8) | (1 << 7) | (1 << 6) |\
  205. (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2) |\
  206. (1 << 1) | (1 << 0))
  207. /*
  208. * Device 16.2: Global Error Registers
  209. */
  210. #define FERR_GLOBAL_HI 0x48
  211. static const char *ferr_global_hi_name[] = {
  212. [3] = "FSB 3 Fatal Error",
  213. [2] = "FSB 2 Fatal Error",
  214. [1] = "FSB 1 Fatal Error",
  215. [0] = "FSB 0 Fatal Error",
  216. };
  217. #define ferr_global_hi_is_fatal(errno) 1
  218. #define FERR_GLOBAL_LO 0x40
  219. static const char *ferr_global_lo_name[] = {
  220. [31] = "Internal MCH Fatal Error",
  221. [30] = "Intel QuickData Technology Device Fatal Error",
  222. [29] = "FSB1 Fatal Error",
  223. [28] = "FSB0 Fatal Error",
  224. [27] = "FBD Channel 3 Fatal Error",
  225. [26] = "FBD Channel 2 Fatal Error",
  226. [25] = "FBD Channel 1 Fatal Error",
  227. [24] = "FBD Channel 0 Fatal Error",
  228. [23] = "PCI Express Device 7Fatal Error",
  229. [22] = "PCI Express Device 6 Fatal Error",
  230. [21] = "PCI Express Device 5 Fatal Error",
  231. [20] = "PCI Express Device 4 Fatal Error",
  232. [19] = "PCI Express Device 3 Fatal Error",
  233. [18] = "PCI Express Device 2 Fatal Error",
  234. [17] = "PCI Express Device 1 Fatal Error",
  235. [16] = "ESI Fatal Error",
  236. [15] = "Internal MCH Non-Fatal Error",
  237. [14] = "Intel QuickData Technology Device Non Fatal Error",
  238. [13] = "FSB1 Non-Fatal Error",
  239. [12] = "FSB 0 Non-Fatal Error",
  240. [11] = "FBD Channel 3 Non-Fatal Error",
  241. [10] = "FBD Channel 2 Non-Fatal Error",
  242. [9] = "FBD Channel 1 Non-Fatal Error",
  243. [8] = "FBD Channel 0 Non-Fatal Error",
  244. [7] = "PCI Express Device 7 Non-Fatal Error",
  245. [6] = "PCI Express Device 6 Non-Fatal Error",
  246. [5] = "PCI Express Device 5 Non-Fatal Error",
  247. [4] = "PCI Express Device 4 Non-Fatal Error",
  248. [3] = "PCI Express Device 3 Non-Fatal Error",
  249. [2] = "PCI Express Device 2 Non-Fatal Error",
  250. [1] = "PCI Express Device 1 Non-Fatal Error",
  251. [0] = "ESI Non-Fatal Error",
  252. };
  253. #define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1)
  254. #define NRECMEMA 0xbe
  255. #define NRECMEMA_BANK(v) (((v) >> 12) & 7)
  256. #define NRECMEMA_RANK(v) (((v) >> 8) & 15)
  257. #define NRECMEMB 0xc0
  258. #define NRECMEMB_IS_WR(v) ((v) & (1 << 31))
  259. #define NRECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
  260. #define NRECMEMB_RAS(v) ((v) & 0xffff)
  261. #define REDMEMA 0xdc
  262. #define REDMEMB 0x7c
  263. #define RECMEMA 0xe0
  264. #define RECMEMA_BANK(v) (((v) >> 12) & 7)
  265. #define RECMEMA_RANK(v) (((v) >> 8) & 15)
  266. #define RECMEMB 0xe4
  267. #define RECMEMB_IS_WR(v) ((v) & (1 << 31))
  268. #define RECMEMB_CAS(v) (((v) >> 16) & 0x1fff)
  269. #define RECMEMB_RAS(v) ((v) & 0xffff)
  270. /********************************************
  271. * i7300 Functions related to error detection
  272. ********************************************/
  273. /**
  274. * get_err_from_table() - Gets the error message from a table
  275. * @table: table name (array of char *)
  276. * @size: number of elements at the table
  277. * @pos: position of the element to be returned
  278. *
  279. * This is a small routine that gets the pos-th element of a table. If the
  280. * element doesn't exist (or it is empty), it returns "reserved".
  281. * Instead of calling it directly, the better is to call via the macro
  282. * GET_ERR_FROM_TABLE(), that automatically checks the table size via
  283. * ARRAY_SIZE() macro
  284. */
  285. static const char *get_err_from_table(const char *table[], int size, int pos)
  286. {
  287. if (unlikely(pos >= size))
  288. return "Reserved";
  289. if (unlikely(!table[pos]))
  290. return "Reserved";
  291. return table[pos];
  292. }
  293. #define GET_ERR_FROM_TABLE(table, pos) \
  294. get_err_from_table(table, ARRAY_SIZE(table), pos)
  295. /**
  296. * i7300_process_error_global() - Retrieve the hardware error information from
  297. * the hardware global error registers and
  298. * sends it to dmesg
  299. * @mci: struct mem_ctl_info pointer
  300. */
  301. static void i7300_process_error_global(struct mem_ctl_info *mci)
  302. {
  303. struct i7300_pvt *pvt;
  304. u32 errnum, error_reg;
  305. unsigned long errors;
  306. const char *specific;
  307. bool is_fatal;
  308. pvt = mci->pvt_info;
  309. /* read in the 1st FATAL error register */
  310. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  311. FERR_GLOBAL_HI, &error_reg);
  312. if (unlikely(error_reg)) {
  313. errors = error_reg;
  314. errnum = find_first_bit(&errors,
  315. ARRAY_SIZE(ferr_global_hi_name));
  316. specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
  317. is_fatal = ferr_global_hi_is_fatal(errnum);
  318. /* Clear the error bit */
  319. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  320. FERR_GLOBAL_HI, error_reg);
  321. goto error_global;
  322. }
  323. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  324. FERR_GLOBAL_LO, &error_reg);
  325. if (unlikely(error_reg)) {
  326. errors = error_reg;
  327. errnum = find_first_bit(&errors,
  328. ARRAY_SIZE(ferr_global_lo_name));
  329. specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
  330. is_fatal = ferr_global_lo_is_fatal(errnum);
  331. /* Clear the error bit */
  332. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  333. FERR_GLOBAL_LO, error_reg);
  334. goto error_global;
  335. }
  336. return;
  337. error_global:
  338. i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
  339. is_fatal ? "Fatal" : "NOT fatal", specific);
  340. }
  341. /**
  342. * i7300_process_fbd_error() - Retrieve the hardware error information from
  343. * the FBD error registers and sends it via
  344. * EDAC error API calls
  345. * @mci: struct mem_ctl_info pointer
  346. */
  347. static void i7300_process_fbd_error(struct mem_ctl_info *mci)
  348. {
  349. struct i7300_pvt *pvt;
  350. u32 errnum, value, error_reg;
  351. u16 val16;
  352. unsigned branch, channel, bank, rank, cas, ras;
  353. u32 syndrome;
  354. unsigned long errors;
  355. const char *specific;
  356. bool is_wr;
  357. pvt = mci->pvt_info;
  358. /* read in the 1st FATAL error register */
  359. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  360. FERR_FAT_FBD, &error_reg);
  361. if (unlikely(error_reg & FERR_FAT_FBD_ERR_MASK)) {
  362. errors = error_reg & FERR_FAT_FBD_ERR_MASK ;
  363. errnum = find_first_bit(&errors,
  364. ARRAY_SIZE(ferr_fat_fbd_name));
  365. specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
  366. branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
  367. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
  368. NRECMEMA, &val16);
  369. bank = NRECMEMA_BANK(val16);
  370. rank = NRECMEMA_RANK(val16);
  371. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  372. NRECMEMB, &value);
  373. is_wr = NRECMEMB_IS_WR(value);
  374. cas = NRECMEMB_CAS(value);
  375. ras = NRECMEMB_RAS(value);
  376. /* Clean the error register */
  377. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  378. FERR_FAT_FBD, error_reg);
  379. snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
  380. "Bank=%d RAS=%d CAS=%d Err=0x%lx (%s))",
  381. bank, ras, cas, errors, specific);
  382. edac_mc_handle_error(HW_EVENT_ERR_FATAL, mci, 1, 0, 0, 0,
  383. branch, -1, rank,
  384. is_wr ? "Write error" : "Read error",
  385. pvt->tmp_prt_buffer);
  386. }
  387. /* read in the 1st NON-FATAL error register */
  388. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  389. FERR_NF_FBD, &error_reg);
  390. if (unlikely(error_reg & FERR_NF_FBD_ERR_MASK)) {
  391. errors = error_reg & FERR_NF_FBD_ERR_MASK;
  392. errnum = find_first_bit(&errors,
  393. ARRAY_SIZE(ferr_nf_fbd_name));
  394. specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
  395. branch = (GET_FBD_NF_IDX(error_reg) == 2) ? 1 : 0;
  396. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  397. REDMEMA, &syndrome);
  398. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
  399. RECMEMA, &val16);
  400. bank = RECMEMA_BANK(val16);
  401. rank = RECMEMA_RANK(val16);
  402. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  403. RECMEMB, &value);
  404. is_wr = RECMEMB_IS_WR(value);
  405. cas = RECMEMB_CAS(value);
  406. ras = RECMEMB_RAS(value);
  407. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  408. REDMEMB, &value);
  409. channel = (branch << 1);
  410. /* Second channel ? */
  411. channel += !!(value & BIT(17));
  412. /* Clear the error bit */
  413. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  414. FERR_NF_FBD, error_reg);
  415. /* Form out message */
  416. snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
  417. "DRAM-Bank=%d RAS=%d CAS=%d, Err=0x%lx (%s))",
  418. bank, ras, cas, errors, specific);
  419. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1, 0, 0,
  420. syndrome,
  421. branch >> 1, channel % 2, rank,
  422. is_wr ? "Write error" : "Read error",
  423. pvt->tmp_prt_buffer);
  424. }
  425. return;
  426. }
  427. /**
  428. * i7300_check_error() - Calls the error checking subroutines
  429. * @mci: struct mem_ctl_info pointer
  430. */
  431. static void i7300_check_error(struct mem_ctl_info *mci)
  432. {
  433. i7300_process_error_global(mci);
  434. i7300_process_fbd_error(mci);
  435. };
  436. /**
  437. * i7300_clear_error() - Clears the error registers
  438. * @mci: struct mem_ctl_info pointer
  439. */
  440. static void i7300_clear_error(struct mem_ctl_info *mci)
  441. {
  442. struct i7300_pvt *pvt = mci->pvt_info;
  443. u32 value;
  444. /*
  445. * All error values are RWC - we need to read and write 1 to the
  446. * bit that we want to cleanup
  447. */
  448. /* Clear global error registers */
  449. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  450. FERR_GLOBAL_HI, &value);
  451. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  452. FERR_GLOBAL_HI, value);
  453. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  454. FERR_GLOBAL_LO, &value);
  455. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  456. FERR_GLOBAL_LO, value);
  457. /* Clear FBD error registers */
  458. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  459. FERR_FAT_FBD, &value);
  460. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  461. FERR_FAT_FBD, value);
  462. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  463. FERR_NF_FBD, &value);
  464. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  465. FERR_NF_FBD, value);
  466. }
  467. /**
  468. * i7300_enable_error_reporting() - Enable the memory reporting logic at the
  469. * hardware
  470. * @mci: struct mem_ctl_info pointer
  471. */
  472. static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
  473. {
  474. struct i7300_pvt *pvt = mci->pvt_info;
  475. u32 fbd_error_mask;
  476. /* Read the FBD Error Mask Register */
  477. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  478. EMASK_FBD, &fbd_error_mask);
  479. /* Enable with a '0' */
  480. fbd_error_mask &= ~(EMASK_FBD_ERR_MASK);
  481. pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
  482. EMASK_FBD, fbd_error_mask);
  483. }
  484. /************************************************
  485. * i7300 Functions related to memory enumberation
  486. ************************************************/
  487. /**
  488. * decode_mtr() - Decodes the MTR descriptor, filling the edac structs
  489. * @pvt: pointer to the private data struct used by i7300 driver
  490. * @slot: DIMM slot (0 to 7)
  491. * @ch: Channel number within the branch (0 or 1)
  492. * @branch: Branch number (0 or 1)
  493. * @dinfo: Pointer to DIMM info where dimm size is stored
  494. * @dimm: Pointer to the struct dimm_info that corresponds to that element
  495. */
  496. static int decode_mtr(struct i7300_pvt *pvt,
  497. int slot, int ch, int branch,
  498. struct i7300_dimm_info *dinfo,
  499. struct dimm_info *dimm)
  500. {
  501. int mtr, ans, addrBits, channel;
  502. channel = to_channel(ch, branch);
  503. mtr = pvt->mtr[slot][branch];
  504. ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
  505. edac_dbg(2, "\tMTR%d CH%d: DIMMs are %sPresent (mtr)\n",
  506. slot, channel, ans ? "" : "NOT ");
  507. /* Determine if there is a DIMM present in this DIMM slot */
  508. if (!ans)
  509. return 0;
  510. /* Start with the number of bits for a Bank
  511. * on the DRAM */
  512. addrBits = MTR_DRAM_BANKS_ADDR_BITS;
  513. /* Add thenumber of ROW bits */
  514. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  515. /* add the number of COLUMN bits */
  516. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  517. /* add the number of RANK bits */
  518. addrBits += MTR_DIMM_RANKS(mtr);
  519. addrBits += 6; /* add 64 bits per DIMM */
  520. addrBits -= 20; /* divide by 2^^20 */
  521. addrBits -= 3; /* 8 bits per bytes */
  522. dinfo->megabytes = 1 << addrBits;
  523. edac_dbg(2, "\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  524. edac_dbg(2, "\t\tELECTRICAL THROTTLING is %s\n",
  525. str_enabled_disabled(MTR_DIMMS_ETHROTTLE(mtr)));
  526. edac_dbg(2, "\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  527. edac_dbg(2, "\t\tNUMRANK: %s\n",
  528. MTR_DIMM_RANKS(mtr) ? "double" : "single");
  529. edac_dbg(2, "\t\tNUMROW: %s\n",
  530. MTR_DIMM_ROWS(mtr) == 0 ? "8,192 - 13 rows" :
  531. MTR_DIMM_ROWS(mtr) == 1 ? "16,384 - 14 rows" :
  532. MTR_DIMM_ROWS(mtr) == 2 ? "32,768 - 15 rows" :
  533. "65,536 - 16 rows");
  534. edac_dbg(2, "\t\tNUMCOL: %s\n",
  535. MTR_DIMM_COLS(mtr) == 0 ? "1,024 - 10 columns" :
  536. MTR_DIMM_COLS(mtr) == 1 ? "2,048 - 11 columns" :
  537. MTR_DIMM_COLS(mtr) == 2 ? "4,096 - 12 columns" :
  538. "reserved");
  539. edac_dbg(2, "\t\tSIZE: %d MB\n", dinfo->megabytes);
  540. /*
  541. * The type of error detection actually depends of the
  542. * mode of operation. When it is just one single memory chip, at
  543. * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code.
  544. * In normal or mirrored mode, it uses Lockstep mode,
  545. * with the possibility of using an extended algorithm for x8 memories
  546. * See datasheet Sections 7.3.6 to 7.3.8
  547. */
  548. dimm->nr_pages = MiB_TO_PAGES(dinfo->megabytes);
  549. dimm->grain = 8;
  550. dimm->mtype = MEM_FB_DDR2;
  551. if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
  552. dimm->edac_mode = EDAC_SECDED;
  553. edac_dbg(2, "\t\tECC code is 8-byte-over-32-byte SECDED+ code\n");
  554. } else {
  555. edac_dbg(2, "\t\tECC code is on Lockstep mode\n");
  556. if (MTR_DRAM_WIDTH(mtr) == 8)
  557. dimm->edac_mode = EDAC_S8ECD8ED;
  558. else
  559. dimm->edac_mode = EDAC_S4ECD4ED;
  560. }
  561. /* ask what device type on this row */
  562. if (MTR_DRAM_WIDTH(mtr) == 8) {
  563. edac_dbg(2, "\t\tScrub algorithm for x8 is on %s mode\n",
  564. IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
  565. "enhanced" : "normal");
  566. dimm->dtype = DEV_X8;
  567. } else
  568. dimm->dtype = DEV_X4;
  569. return mtr;
  570. }
  571. /**
  572. * print_dimm_size() - Prints dump of the memory organization
  573. * @pvt: pointer to the private data struct used by i7300 driver
  574. *
  575. * Useful for debug. If debug is disabled, this routine do nothing
  576. */
  577. static void print_dimm_size(struct i7300_pvt *pvt)
  578. {
  579. #ifdef CONFIG_EDAC_DEBUG
  580. struct i7300_dimm_info *dinfo;
  581. char *p;
  582. int space, n;
  583. int channel, slot;
  584. space = PAGE_SIZE;
  585. p = pvt->tmp_prt_buffer;
  586. n = snprintf(p, space, " ");
  587. p += n;
  588. space -= n;
  589. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  590. n = snprintf(p, space, "channel %d | ", channel);
  591. p += n;
  592. space -= n;
  593. }
  594. edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
  595. p = pvt->tmp_prt_buffer;
  596. space = PAGE_SIZE;
  597. n = snprintf(p, space, "-------------------------------"
  598. "------------------------------");
  599. p += n;
  600. space -= n;
  601. edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
  602. p = pvt->tmp_prt_buffer;
  603. space = PAGE_SIZE;
  604. for (slot = 0; slot < MAX_SLOTS; slot++) {
  605. n = snprintf(p, space, "csrow/SLOT %d ", slot);
  606. p += n;
  607. space -= n;
  608. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  609. dinfo = &pvt->dimm_info[slot][channel];
  610. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  611. p += n;
  612. space -= n;
  613. }
  614. edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
  615. p = pvt->tmp_prt_buffer;
  616. space = PAGE_SIZE;
  617. }
  618. n = snprintf(p, space, "-------------------------------"
  619. "------------------------------");
  620. p += n;
  621. space -= n;
  622. edac_dbg(2, "%s\n", pvt->tmp_prt_buffer);
  623. p = pvt->tmp_prt_buffer;
  624. space = PAGE_SIZE;
  625. #endif
  626. }
  627. /**
  628. * i7300_init_csrows() - Initialize the 'csrows' table within
  629. * the mci control structure with the
  630. * addressing of memory.
  631. * @mci: struct mem_ctl_info pointer
  632. */
  633. static int i7300_init_csrows(struct mem_ctl_info *mci)
  634. {
  635. struct i7300_pvt *pvt;
  636. struct i7300_dimm_info *dinfo;
  637. int rc = -ENODEV;
  638. int mtr;
  639. int ch, branch, slot, channel, max_channel, max_branch;
  640. struct dimm_info *dimm;
  641. pvt = mci->pvt_info;
  642. edac_dbg(2, "Memory Technology Registers:\n");
  643. if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
  644. max_branch = 1;
  645. max_channel = 1;
  646. } else {
  647. max_branch = MAX_BRANCHES;
  648. max_channel = MAX_CH_PER_BRANCH;
  649. }
  650. /* Get the AMB present registers for the four channels */
  651. for (branch = 0; branch < max_branch; branch++) {
  652. /* Read and dump branch 0's MTRs */
  653. channel = to_channel(0, branch);
  654. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  655. AMBPRESENT_0,
  656. &pvt->ambpresent[channel]);
  657. edac_dbg(2, "\t\tAMB-present CH%d = 0x%x:\n",
  658. channel, pvt->ambpresent[channel]);
  659. if (max_channel == 1)
  660. continue;
  661. channel = to_channel(1, branch);
  662. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  663. AMBPRESENT_1,
  664. &pvt->ambpresent[channel]);
  665. edac_dbg(2, "\t\tAMB-present CH%d = 0x%x:\n",
  666. channel, pvt->ambpresent[channel]);
  667. }
  668. /* Get the set of MTR[0-7] regs by each branch */
  669. for (slot = 0; slot < MAX_SLOTS; slot++) {
  670. int where = mtr_regs[slot];
  671. for (branch = 0; branch < max_branch; branch++) {
  672. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  673. where,
  674. &pvt->mtr[slot][branch]);
  675. for (ch = 0; ch < max_channel; ch++) {
  676. int channel = to_channel(ch, branch);
  677. dimm = edac_get_dimm(mci, branch, ch, slot);
  678. dinfo = &pvt->dimm_info[slot][channel];
  679. mtr = decode_mtr(pvt, slot, ch, branch,
  680. dinfo, dimm);
  681. /* if no DIMMS on this row, continue */
  682. if (!MTR_DIMMS_PRESENT(mtr))
  683. continue;
  684. rc = 0;
  685. }
  686. }
  687. }
  688. return rc;
  689. }
  690. /**
  691. * decode_mir() - Decodes Memory Interleave Register (MIR) info
  692. * @mir_no: number of the MIR register to decode
  693. * @mir: array with the MIR data cached on the driver
  694. */
  695. static void decode_mir(int mir_no, u16 mir[MAX_MIR])
  696. {
  697. if (mir[mir_no] & 3)
  698. edac_dbg(2, "MIR%d: limit= 0x%x Branch(es) that participate: %s %s\n",
  699. mir_no,
  700. (mir[mir_no] >> 4) & 0xfff,
  701. (mir[mir_no] & 1) ? "B0" : "",
  702. (mir[mir_no] & 2) ? "B1" : "");
  703. }
  704. /**
  705. * i7300_get_mc_regs() - Get the contents of the MC enumeration registers
  706. * @mci: struct mem_ctl_info pointer
  707. *
  708. * Data read is cached internally for its usage when needed
  709. */
  710. static int i7300_get_mc_regs(struct mem_ctl_info *mci)
  711. {
  712. struct i7300_pvt *pvt;
  713. u32 actual_tolm;
  714. int i, rc;
  715. pvt = mci->pvt_info;
  716. pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
  717. (u32 *) &pvt->ambase);
  718. edac_dbg(2, "AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
  719. /* Get the Branch Map regs */
  720. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
  721. pvt->tolm >>= 12;
  722. edac_dbg(2, "TOLM (number of 256M regions) =%u (0x%x)\n",
  723. pvt->tolm, pvt->tolm);
  724. actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
  725. edac_dbg(2, "Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
  726. actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
  727. /* Get memory controller settings */
  728. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
  729. &pvt->mc_settings);
  730. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
  731. &pvt->mc_settings_a);
  732. if (IS_SINGLE_MODE(pvt->mc_settings_a))
  733. edac_dbg(0, "Memory controller operating on single mode\n");
  734. else
  735. edac_dbg(0, "Memory controller operating on %smirrored mode\n",
  736. IS_MIRRORED(pvt->mc_settings) ? "" : "non-");
  737. edac_dbg(0, "Error detection is %s\n",
  738. str_enabled_disabled(IS_ECC_ENABLED(pvt->mc_settings)));
  739. edac_dbg(0, "Retry is %s\n",
  740. str_enabled_disabled(IS_RETRY_ENABLED(pvt->mc_settings)));
  741. /* Get Memory Interleave Range registers */
  742. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0,
  743. &pvt->mir[0]);
  744. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1,
  745. &pvt->mir[1]);
  746. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2,
  747. &pvt->mir[2]);
  748. /* Decode the MIR regs */
  749. for (i = 0; i < MAX_MIR; i++)
  750. decode_mir(i, pvt->mir);
  751. rc = i7300_init_csrows(mci);
  752. if (rc < 0)
  753. return rc;
  754. /* Go and determine the size of each DIMM and place in an
  755. * orderly matrix */
  756. print_dimm_size(pvt);
  757. return 0;
  758. }
  759. /*************************************************
  760. * i7300 Functions related to device probe/release
  761. *************************************************/
  762. /**
  763. * i7300_put_devices() - Release the PCI devices
  764. * @mci: struct mem_ctl_info pointer
  765. */
  766. static void i7300_put_devices(struct mem_ctl_info *mci)
  767. {
  768. struct i7300_pvt *pvt;
  769. int branch;
  770. pvt = mci->pvt_info;
  771. /* Decrement usage count for devices */
  772. for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
  773. pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
  774. pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
  775. pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
  776. }
  777. /**
  778. * i7300_get_devices() - Find and perform 'get' operation on the MCH's
  779. * device/functions we want to reference for this driver
  780. * @mci: struct mem_ctl_info pointer
  781. *
  782. * Access and prepare the several devices for usage:
  783. * I7300 devices used by this driver:
  784. * Device 16, functions 0,1 and 2: PCI_DEVICE_ID_INTEL_I7300_MCH_ERR
  785. * Device 21 function 0: PCI_DEVICE_ID_INTEL_I7300_MCH_FB0
  786. * Device 22 function 0: PCI_DEVICE_ID_INTEL_I7300_MCH_FB1
  787. */
  788. static int i7300_get_devices(struct mem_ctl_info *mci)
  789. {
  790. struct i7300_pvt *pvt;
  791. struct pci_dev *pdev;
  792. pvt = mci->pvt_info;
  793. /* Attempt to 'get' the MCH register we want */
  794. pdev = NULL;
  795. while ((pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  796. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
  797. pdev))) {
  798. /* Store device 16 funcs 1 and 2 */
  799. switch (PCI_FUNC(pdev->devfn)) {
  800. case 1:
  801. if (!pvt->pci_dev_16_1_fsb_addr_map)
  802. pvt->pci_dev_16_1_fsb_addr_map =
  803. pci_dev_get(pdev);
  804. break;
  805. case 2:
  806. if (!pvt->pci_dev_16_2_fsb_err_regs)
  807. pvt->pci_dev_16_2_fsb_err_regs =
  808. pci_dev_get(pdev);
  809. break;
  810. }
  811. }
  812. if (!pvt->pci_dev_16_1_fsb_addr_map ||
  813. !pvt->pci_dev_16_2_fsb_err_regs) {
  814. /* At least one device was not found */
  815. i7300_printk(KERN_ERR,
  816. "'system address,Process Bus' device not found:"
  817. "vendor 0x%x device 0x%x ERR funcs (broken BIOS?)\n",
  818. PCI_VENDOR_ID_INTEL,
  819. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
  820. goto error;
  821. }
  822. edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  823. pci_name(pvt->pci_dev_16_0_fsb_ctlr),
  824. pvt->pci_dev_16_0_fsb_ctlr->vendor,
  825. pvt->pci_dev_16_0_fsb_ctlr->device);
  826. edac_dbg(1, "Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  827. pci_name(pvt->pci_dev_16_1_fsb_addr_map),
  828. pvt->pci_dev_16_1_fsb_addr_map->vendor,
  829. pvt->pci_dev_16_1_fsb_addr_map->device);
  830. edac_dbg(1, "FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  831. pci_name(pvt->pci_dev_16_2_fsb_err_regs),
  832. pvt->pci_dev_16_2_fsb_err_regs->vendor,
  833. pvt->pci_dev_16_2_fsb_err_regs->device);
  834. pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
  835. PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
  836. NULL);
  837. if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
  838. i7300_printk(KERN_ERR,
  839. "MC: 'BRANCH 0' device not found:"
  840. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  841. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
  842. goto error;
  843. }
  844. pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
  845. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
  846. NULL);
  847. if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
  848. i7300_printk(KERN_ERR,
  849. "MC: 'BRANCH 1' device not found:"
  850. "vendor 0x%x device 0x%x Func 0 "
  851. "(broken BIOS?)\n",
  852. PCI_VENDOR_ID_INTEL,
  853. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
  854. goto error;
  855. }
  856. return 0;
  857. error:
  858. i7300_put_devices(mci);
  859. return -ENODEV;
  860. }
  861. /**
  862. * i7300_init_one() - Probe for one instance of the device
  863. * @pdev: struct pci_dev pointer
  864. * @id: struct pci_device_id pointer - currently unused
  865. */
  866. static int i7300_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  867. {
  868. struct mem_ctl_info *mci;
  869. struct edac_mc_layer layers[3];
  870. struct i7300_pvt *pvt;
  871. int rc;
  872. /* wake up device */
  873. rc = pci_enable_device(pdev);
  874. if (rc == -EIO)
  875. return rc;
  876. edac_dbg(0, "MC: pdev bus %u dev=0x%x fn=0x%x\n",
  877. pdev->bus->number,
  878. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  879. /* We only are looking for func 0 of the set */
  880. if (PCI_FUNC(pdev->devfn) != 0)
  881. return -ENODEV;
  882. /* allocate a new MC control structure */
  883. layers[0].type = EDAC_MC_LAYER_BRANCH;
  884. layers[0].size = MAX_BRANCHES;
  885. layers[0].is_virt_csrow = false;
  886. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  887. layers[1].size = MAX_CH_PER_BRANCH;
  888. layers[1].is_virt_csrow = true;
  889. layers[2].type = EDAC_MC_LAYER_SLOT;
  890. layers[2].size = MAX_SLOTS;
  891. layers[2].is_virt_csrow = true;
  892. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  893. if (mci == NULL)
  894. return -ENOMEM;
  895. edac_dbg(0, "MC: mci = %p\n", mci);
  896. mci->pdev = &pdev->dev; /* record ptr to the generic device */
  897. pvt = mci->pvt_info;
  898. pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */
  899. pvt->tmp_prt_buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
  900. if (!pvt->tmp_prt_buffer) {
  901. edac_mc_free(mci);
  902. return -ENOMEM;
  903. }
  904. /* 'get' the pci devices we want to reserve for our use */
  905. if (i7300_get_devices(mci))
  906. goto fail0;
  907. mci->mc_idx = 0;
  908. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  909. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  910. mci->edac_cap = EDAC_FLAG_NONE;
  911. mci->mod_name = "i7300_edac.c";
  912. mci->ctl_name = i7300_devs[0].ctl_name;
  913. mci->dev_name = pci_name(pdev);
  914. mci->ctl_page_to_phys = NULL;
  915. /* Set the function pointer to an actual operation function */
  916. mci->edac_check = i7300_check_error;
  917. /* initialize the MC control structure 'csrows' table
  918. * with the mapping and control information */
  919. if (i7300_get_mc_regs(mci)) {
  920. edac_dbg(0, "MC: Setting mci->edac_cap to EDAC_FLAG_NONE because i7300_init_csrows() returned nonzero value\n");
  921. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  922. } else {
  923. edac_dbg(1, "MC: Enable error reporting now\n");
  924. i7300_enable_error_reporting(mci);
  925. }
  926. /* add this new MC control structure to EDAC's list of MCs */
  927. if (edac_mc_add_mc(mci)) {
  928. edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
  929. /* FIXME: perhaps some code should go here that disables error
  930. * reporting if we just enabled it
  931. */
  932. goto fail1;
  933. }
  934. i7300_clear_error(mci);
  935. /* allocating generic PCI control info */
  936. i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  937. if (!i7300_pci) {
  938. printk(KERN_WARNING
  939. "%s(): Unable to create PCI control\n",
  940. __func__);
  941. printk(KERN_WARNING
  942. "%s(): PCI error report via EDAC not setup\n",
  943. __func__);
  944. }
  945. return 0;
  946. /* Error exit unwinding stack */
  947. fail1:
  948. i7300_put_devices(mci);
  949. fail0:
  950. kfree(pvt->tmp_prt_buffer);
  951. edac_mc_free(mci);
  952. return -ENODEV;
  953. }
  954. /**
  955. * i7300_remove_one() - Remove the driver
  956. * @pdev: struct pci_dev pointer
  957. */
  958. static void i7300_remove_one(struct pci_dev *pdev)
  959. {
  960. struct mem_ctl_info *mci;
  961. char *tmp;
  962. edac_dbg(0, "\n");
  963. if (i7300_pci)
  964. edac_pci_release_generic_ctl(i7300_pci);
  965. mci = edac_mc_del_mc(&pdev->dev);
  966. if (!mci)
  967. return;
  968. tmp = ((struct i7300_pvt *)mci->pvt_info)->tmp_prt_buffer;
  969. /* retrieve references to resources, and free those resources */
  970. i7300_put_devices(mci);
  971. kfree(tmp);
  972. edac_mc_free(mci);
  973. }
  974. /*
  975. * pci_device_id: table for which devices we are looking for
  976. *
  977. * Has only 8086:360c PCI ID
  978. */
  979. static const struct pci_device_id i7300_pci_tbl[] = {
  980. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
  981. {0,} /* 0 terminated list. */
  982. };
  983. MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
  984. /*
  985. * i7300_driver: pci_driver structure for this module
  986. */
  987. static struct pci_driver i7300_driver = {
  988. .name = "i7300_edac",
  989. .probe = i7300_init_one,
  990. .remove = i7300_remove_one,
  991. .id_table = i7300_pci_tbl,
  992. };
  993. /**
  994. * i7300_init() - Registers the driver
  995. */
  996. static int __init i7300_init(void)
  997. {
  998. int pci_rc;
  999. edac_dbg(2, "\n");
  1000. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  1001. opstate_init();
  1002. pci_rc = pci_register_driver(&i7300_driver);
  1003. return (pci_rc < 0) ? pci_rc : 0;
  1004. }
  1005. /**
  1006. * i7300_exit() - Unregisters the driver
  1007. */
  1008. static void __exit i7300_exit(void)
  1009. {
  1010. edac_dbg(2, "\n");
  1011. pci_unregister_driver(&i7300_driver);
  1012. }
  1013. module_init(i7300_init);
  1014. module_exit(i7300_exit);
  1015. MODULE_LICENSE("GPL");
  1016. MODULE_AUTHOR("Mauro Carvalho Chehab");
  1017. MODULE_AUTHOR("Red Hat Inc. (https://www.redhat.com)");
  1018. MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
  1019. I7300_REVISION);
  1020. module_param(edac_op_state, int, 0444);
  1021. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");