i7300_edac.c 35 KB

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