i7300_edac.c 36 KB

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