i7300_edac.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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 " __DATE__
  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. * Memory topology is organized as:
  39. * Branch 0 - 2 channels: channels 0 and 1 (FDB0 PCI dev 21.0)
  40. * Branch 1 - 2 channels: channels 2 and 3 (FDB1 PCI dev 22.0)
  41. * Each channel can have to 8 DIMM sets (called as SLOTS)
  42. * Slots should generally be filled in pairs
  43. * Except on Single Channel mode of operation
  44. * just slot 0/channel0 filled on this mode
  45. * On normal operation mode, the two channels on a branch should be
  46. * filled together for the same SLOT#
  47. * When in mirrored mode, Branch 1 replicate memory at Branch 0, so, the four
  48. * channels on both branches should be filled
  49. */
  50. /* Limits for i7300 */
  51. #define MAX_SLOTS 8
  52. #define MAX_BRANCHES 2
  53. #define MAX_CH_PER_BRANCH 2
  54. #define MAX_CHANNELS (MAX_CH_PER_BRANCH * MAX_BRANCHES)
  55. #define MAX_MIR 3
  56. #define to_channel(ch, branch) ((((branch)) << 1) | (ch))
  57. #define to_csrow(slot, ch, branch) \
  58. (to_channel(ch, branch) | ((slot) << 2))
  59. /*
  60. * I7300 devices
  61. * All 3 functions of Device 16 (0,1,2) share the SAME DID and
  62. * uses PCI_DEVICE_ID_INTEL_I7300_MCH_ERR for device 16 (0,1,2),
  63. * PCI_DEVICE_ID_INTEL_I7300_MCH_FB0 and PCI_DEVICE_ID_INTEL_I7300_MCH_FB1
  64. * for device 21 (0,1).
  65. */
  66. /****************************************************
  67. * i7300 Register definitions for memory enumberation
  68. ****************************************************/
  69. /*
  70. * Device 16,
  71. * Function 0: System Address (not documented)
  72. * Function 1: Memory Branch Map, Control, Errors Register
  73. */
  74. /* OFFSETS for Function 0 */
  75. #define AMBASE 0x48 /* AMB Mem Mapped Reg Region Base */
  76. #define MAXCH 0x56 /* Max Channel Number */
  77. #define MAXDIMMPERCH 0x57 /* Max DIMM PER Channel Number */
  78. /* OFFSETS for Function 1 */
  79. #define MC_SETTINGS 0x40
  80. #define IS_MIRRORED(mc) ((mc) & (1 << 16))
  81. #define IS_ECC_ENABLED(mc) ((mc) & (1 << 5))
  82. #define IS_RETRY_ENABLED(mc) ((mc) & (1 << 31))
  83. #define IS_SCRBALGO_ENHANCED(mc) ((mc) & (1 << 8))
  84. #define MC_SETTINGS_A 0x58
  85. #define IS_SINGLE_MODE(mca) ((mca) & (1 << 14))
  86. #define TOLM 0x6C
  87. #define REDMEMB 0x7C
  88. #define MIR0 0x80
  89. #define MIR1 0x84
  90. #define MIR2 0x88
  91. /*
  92. * Note: Other Intel EDAC drivers use AMBPRESENT to identify if the available
  93. * memory. From datasheet item 7.3.1 (FB-DIMM technology & organization), it
  94. * seems that we cannot use this information directly for the same usage.
  95. * Each memory slot may have up to 2 AMB interfaces, one for income and another
  96. * for outcome interface to the next slot.
  97. * For now, the driver just stores the AMB present registers, but rely only at
  98. * the MTR info to detect memory.
  99. * Datasheet is also not clear about how to map each AMBPRESENT registers to
  100. * one of the 4 available channels.
  101. */
  102. #define AMBPRESENT_0 0x64
  103. #define AMBPRESENT_1 0x66
  104. const static u16 mtr_regs [MAX_SLOTS] = {
  105. 0x80, 0x84, 0x88, 0x8c,
  106. 0x82, 0x86, 0x8a, 0x8e
  107. };
  108. /* Defines to extract the vaious fields from the
  109. * MTRx - Memory Technology Registers
  110. */
  111. #define MTR_DIMMS_PRESENT(mtr) ((mtr) & (1 << 8))
  112. #define MTR_DIMMS_ETHROTTLE(mtr) ((mtr) & (1 << 7))
  113. #define MTR_DRAM_WIDTH(mtr) (((mtr) & (1 << 6)) ? 8 : 4)
  114. #define MTR_DRAM_BANKS(mtr) (((mtr) & (1 << 5)) ? 8 : 4)
  115. #define MTR_DIMM_RANKS(mtr) (((mtr) & (1 << 4)) ? 1 : 0)
  116. #define MTR_DIMM_ROWS(mtr) (((mtr) >> 2) & 0x3)
  117. #define MTR_DRAM_BANKS_ADDR_BITS 2
  118. #define MTR_DIMM_ROWS_ADDR_BITS(mtr) (MTR_DIMM_ROWS(mtr) + 13)
  119. #define MTR_DIMM_COLS(mtr) ((mtr) & 0x3)
  120. #define MTR_DIMM_COLS_ADDR_BITS(mtr) (MTR_DIMM_COLS(mtr) + 10)
  121. #ifdef CONFIG_EDAC_DEBUG
  122. /* MTR NUMROW */
  123. static const char *numrow_toString[] = {
  124. "8,192 - 13 rows",
  125. "16,384 - 14 rows",
  126. "32,768 - 15 rows",
  127. "65,536 - 16 rows"
  128. };
  129. /* MTR NUMCOL */
  130. static const char *numcol_toString[] = {
  131. "1,024 - 10 columns",
  132. "2,048 - 11 columns",
  133. "4,096 - 12 columns",
  134. "reserved"
  135. };
  136. #endif
  137. /************************************************
  138. * i7300 Register definitions for error detection
  139. ************************************************/
  140. /*
  141. * Device 16.2: Global Error Registers
  142. */
  143. #define FERR_GLOBAL_HI 0x48
  144. static const char *ferr_global_hi_name[] = {
  145. [3] = "FSB 3 Fatal Error",
  146. [2] = "FSB 2 Fatal Error",
  147. [1] = "FSB 1 Fatal Error",
  148. [0] = "FSB 0 Fatal Error",
  149. };
  150. #define ferr_global_hi_is_fatal(errno) 1
  151. #define FERR_GLOBAL_LO 0x40
  152. static const char *ferr_global_lo_name[] = {
  153. [31] = "Internal MCH Fatal Error",
  154. [30] = "Intel QuickData Technology Device Fatal Error",
  155. [29] = "FSB1 Fatal Error",
  156. [28] = "FSB0 Fatal Error",
  157. [27] = "FBD Channel 3 Fatal Error",
  158. [26] = "FBD Channel 2 Fatal Error",
  159. [25] = "FBD Channel 1 Fatal Error",
  160. [24] = "FBD Channel 0 Fatal Error",
  161. [23] = "PCI Express Device 7Fatal Error",
  162. [22] = "PCI Express Device 6 Fatal Error",
  163. [21] = "PCI Express Device 5 Fatal Error",
  164. [20] = "PCI Express Device 4 Fatal Error",
  165. [19] = "PCI Express Device 3 Fatal Error",
  166. [18] = "PCI Express Device 2 Fatal Error",
  167. [17] = "PCI Express Device 1 Fatal Error",
  168. [16] = "ESI Fatal Error",
  169. [15] = "Internal MCH Non-Fatal Error",
  170. [14] = "Intel QuickData Technology Device Non Fatal Error",
  171. [13] = "FSB1 Non-Fatal Error",
  172. [12] = "FSB 0 Non-Fatal Error",
  173. [11] = "FBD Channel 3 Non-Fatal Error",
  174. [10] = "FBD Channel 2 Non-Fatal Error",
  175. [9] = "FBD Channel 1 Non-Fatal Error",
  176. [8] = "FBD Channel 0 Non-Fatal Error",
  177. [7] = "PCI Express Device 7 Non-Fatal Error",
  178. [6] = "PCI Express Device 6 Non-Fatal Error",
  179. [5] = "PCI Express Device 5 Non-Fatal Error",
  180. [4] = "PCI Express Device 4 Non-Fatal Error",
  181. [3] = "PCI Express Device 3 Non-Fatal Error",
  182. [2] = "PCI Express Device 2 Non-Fatal Error",
  183. [1] = "PCI Express Device 1 Non-Fatal Error",
  184. [0] = "ESI Non-Fatal Error",
  185. };
  186. #define ferr_global_lo_is_fatal(errno) ((errno < 16) ? 0 : 1)
  187. /* Device name and register DID (Device ID) */
  188. struct i7300_dev_info {
  189. const char *ctl_name; /* name for this device */
  190. u16 fsb_mapping_errors; /* DID for the branchmap,control */
  191. };
  192. /* Table of devices attributes supported by this driver */
  193. static const struct i7300_dev_info i7300_devs[] = {
  194. {
  195. .ctl_name = "I7300",
  196. .fsb_mapping_errors = PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
  197. },
  198. };
  199. struct i7300_dimm_info {
  200. int megabytes; /* size, 0 means not present */
  201. };
  202. /* driver private data structure */
  203. struct i7300_pvt {
  204. struct pci_dev *pci_dev_16_0_fsb_ctlr; /* 16.0 */
  205. struct pci_dev *pci_dev_16_1_fsb_addr_map; /* 16.1 */
  206. struct pci_dev *pci_dev_16_2_fsb_err_regs; /* 16.2 */
  207. struct pci_dev *pci_dev_2x_0_fbd_branch[MAX_BRANCHES]; /* 21.0 and 22.0 */
  208. u16 tolm; /* top of low memory */
  209. u64 ambase; /* AMB BAR */
  210. u32 mc_settings; /* Report several settings */
  211. u32 mc_settings_a;
  212. u16 mir[MAX_MIR]; /* Memory Interleave Reg*/
  213. u16 mtr[MAX_SLOTS][MAX_BRANCHES]; /* Memory Technlogy Reg */
  214. u16 ambpresent[MAX_CHANNELS]; /* AMB present regs */
  215. /* DIMM information matrix, allocating architecture maximums */
  216. struct i7300_dimm_info dimm_info[MAX_SLOTS][MAX_CHANNELS];
  217. };
  218. /* FIXME: Why do we need to have this static? */
  219. static struct edac_pci_ctl_info *i7300_pci;
  220. /********************************************
  221. * i7300 Functions related to error detection
  222. ********************************************/
  223. struct i7300_error_info {
  224. int dummy; /* FIXME */
  225. };
  226. const char *get_err_from_table(const char *table[], int size, int pos)
  227. {
  228. if (pos >= size)
  229. return "Reserved";
  230. return table[pos];
  231. }
  232. #define GET_ERR_FROM_TABLE(table, pos) \
  233. get_err_from_table(table, ARRAY_SIZE(table), pos)
  234. /*
  235. * i7300_get_error_info Retrieve the hardware error information from
  236. * the hardware and cache it in the 'info'
  237. * structure
  238. */
  239. static void i7300_get_error_info(struct mem_ctl_info *mci,
  240. struct i7300_error_info *info)
  241. {
  242. }
  243. /*
  244. * i7300_process_error_global Retrieve the hardware error information from
  245. * the hardware and cache it in the 'info'
  246. * structure
  247. */
  248. static void i7300_process_error_global(struct mem_ctl_info *mci,
  249. struct i7300_error_info *info)
  250. {
  251. struct i7300_pvt *pvt;
  252. u32 errnum, value;
  253. unsigned long errors;
  254. const char *specific;
  255. bool is_fatal;
  256. pvt = mci->pvt_info;
  257. /* read in the 1st FATAL error register */
  258. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  259. FERR_GLOBAL_HI, &value);
  260. if (unlikely(value)) {
  261. errors = value;
  262. errnum = find_first_bit(&errors,
  263. ARRAY_SIZE(ferr_global_hi_name));
  264. specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
  265. is_fatal = ferr_global_hi_is_fatal(errnum);
  266. /* Clear the error bit */
  267. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  268. FERR_GLOBAL_HI, value);
  269. goto error_global;
  270. }
  271. pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  272. FERR_GLOBAL_LO, &value);
  273. if (unlikely(value)) {
  274. errors = value;
  275. errnum = find_first_bit(&errors,
  276. ARRAY_SIZE(ferr_global_lo_name));
  277. specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
  278. is_fatal = ferr_global_lo_is_fatal(errnum);
  279. /* Clear the error bit */
  280. pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
  281. FERR_GLOBAL_LO, value);
  282. goto error_global;
  283. }
  284. return;
  285. error_global:
  286. i7300_mc_printk(mci, KERN_EMERG, "%s misc error: %s\n",
  287. is_fatal ? "Fatal" : "NOT fatal", specific);
  288. }
  289. /*
  290. * i7300_process_error_info Retrieve the hardware error information from
  291. * the hardware and cache it in the 'info'
  292. * structure
  293. */
  294. static void i7300_process_error_info(struct mem_ctl_info *mci,
  295. struct i7300_error_info *info)
  296. {
  297. i7300_process_error_global(mci, info);
  298. };
  299. /*
  300. * i7300_clear_error Retrieve any error from the hardware
  301. * but do NOT process that error.
  302. * Used for 'clearing' out of previous errors
  303. * Called by the Core module.
  304. */
  305. static void i7300_clear_error(struct mem_ctl_info *mci)
  306. {
  307. struct i7300_error_info info;
  308. i7300_get_error_info(mci, &info);
  309. }
  310. /*
  311. * i7300_check_error Retrieve and process errors reported by the
  312. * hardware. Called by the Core module.
  313. */
  314. static void i7300_check_error(struct mem_ctl_info *mci)
  315. {
  316. struct i7300_error_info info;
  317. debugf4("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__);
  318. i7300_get_error_info(mci, &info);
  319. i7300_process_error_info(mci, &info);
  320. }
  321. /*
  322. * i7300_enable_error_reporting
  323. * Turn on the memory reporting features of the hardware
  324. */
  325. static void i7300_enable_error_reporting(struct mem_ctl_info *mci)
  326. {
  327. }
  328. /************************************************
  329. * i7300 Functions related to memory enumberation
  330. ************************************************/
  331. /*
  332. * determine_mtr(pvt, csrow, channel)
  333. *
  334. * return the proper MTR register as determine by the csrow and desired channel
  335. */
  336. static int decode_mtr(struct i7300_pvt *pvt,
  337. int slot, int ch, int branch,
  338. struct i7300_dimm_info *dinfo,
  339. struct csrow_info *p_csrow)
  340. {
  341. int mtr, ans, addrBits, channel;
  342. channel = to_channel(ch, branch);
  343. mtr = pvt->mtr[slot][branch];
  344. ans = MTR_DIMMS_PRESENT(mtr) ? 1 : 0;
  345. debugf2("\tMTR%d CH%d: DIMMs are %s (mtr)\n",
  346. slot, channel,
  347. ans ? "Present" : "NOT Present");
  348. /* Determine if there is a DIMM present in this DIMM slot */
  349. #if 0
  350. if (!amb_present || !ans)
  351. return 0;
  352. #else
  353. if (!ans)
  354. return 0;
  355. #endif
  356. /* Start with the number of bits for a Bank
  357. * on the DRAM */
  358. addrBits = MTR_DRAM_BANKS_ADDR_BITS;
  359. /* Add thenumber of ROW bits */
  360. addrBits += MTR_DIMM_ROWS_ADDR_BITS(mtr);
  361. /* add the number of COLUMN bits */
  362. addrBits += MTR_DIMM_COLS_ADDR_BITS(mtr);
  363. /* add the number of RANK bits */
  364. addrBits += MTR_DIMM_RANKS(mtr);
  365. addrBits += 6; /* add 64 bits per DIMM */
  366. addrBits -= 20; /* divide by 2^^20 */
  367. addrBits -= 3; /* 8 bits per bytes */
  368. dinfo->megabytes = 1 << addrBits;
  369. debugf2("\t\tWIDTH: x%d\n", MTR_DRAM_WIDTH(mtr));
  370. debugf2("\t\tELECTRICAL THROTTLING is %s\n",
  371. MTR_DIMMS_ETHROTTLE(mtr) ? "enabled" : "disabled");
  372. debugf2("\t\tNUMBANK: %d bank(s)\n", MTR_DRAM_BANKS(mtr));
  373. debugf2("\t\tNUMRANK: %s\n", MTR_DIMM_RANKS(mtr) ? "double" : "single");
  374. debugf2("\t\tNUMROW: %s\n", numrow_toString[MTR_DIMM_ROWS(mtr)]);
  375. debugf2("\t\tNUMCOL: %s\n", numcol_toString[MTR_DIMM_COLS(mtr)]);
  376. debugf2("\t\tSIZE: %d MB\n", dinfo->megabytes);
  377. p_csrow->grain = 8;
  378. p_csrow->nr_pages = dinfo->megabytes << 8;
  379. p_csrow->mtype = MEM_FB_DDR2;
  380. /*
  381. * The type of error detection actually depends of the
  382. * mode of operation. When it is just one single memory chip, at
  383. * socket 0, channel 0, it uses 8-byte-over-32-byte SECDED+ code.
  384. * In normal or mirrored mode, it uses Lockstep mode,
  385. * with the possibility of using an extended algorithm for x8 memories
  386. * See datasheet Sections 7.3.6 to 7.3.8
  387. */
  388. if (IS_SINGLE_MODE(pvt->mc_settings_a)) {
  389. p_csrow->edac_mode = EDAC_SECDED;
  390. debugf0("ECC code is 8-byte-over-32-byte SECDED+ code\n");
  391. } else {
  392. debugf0("ECC code is on Lockstep mode\n");
  393. if (MTR_DRAM_WIDTH(mtr))
  394. p_csrow->edac_mode = EDAC_S8ECD8ED;
  395. else
  396. p_csrow->edac_mode = EDAC_S4ECD4ED;
  397. }
  398. /* ask what device type on this row */
  399. if (MTR_DRAM_WIDTH(mtr)) {
  400. debugf0("Scrub algorithm for x8 is on %s mode\n",
  401. IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
  402. "enhanced" : "normal");
  403. p_csrow->dtype = DEV_X8;
  404. } else
  405. p_csrow->dtype = DEV_X4;
  406. return mtr;
  407. }
  408. /*
  409. * print_dimm_size
  410. *
  411. * also will output a DIMM matrix map, if debug is enabled, for viewing
  412. * how the DIMMs are populated
  413. */
  414. static void print_dimm_size(struct i7300_pvt *pvt)
  415. {
  416. struct i7300_dimm_info *dinfo;
  417. char *p, *mem_buffer;
  418. int space, n;
  419. int channel, slot;
  420. space = PAGE_SIZE;
  421. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  422. if (p == NULL) {
  423. i7300_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  424. __FILE__, __func__);
  425. return;
  426. }
  427. n = snprintf(p, space, " ");
  428. p += n;
  429. space -= n;
  430. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  431. n = snprintf(p, space, "channel %d | ", channel);
  432. p += n;
  433. space -= n;
  434. }
  435. debugf2("%s\n", mem_buffer);
  436. p = mem_buffer;
  437. space = PAGE_SIZE;
  438. n = snprintf(p, space, "-------------------------------"
  439. "------------------------------");
  440. p += n;
  441. space -= n;
  442. debugf2("%s\n", mem_buffer);
  443. p = mem_buffer;
  444. space = PAGE_SIZE;
  445. for (slot = 0; slot < MAX_SLOTS; slot++) {
  446. n = snprintf(p, space, "csrow/SLOT %d ", slot);
  447. p += n;
  448. space -= n;
  449. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  450. dinfo = &pvt->dimm_info[slot][channel];
  451. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  452. p += n;
  453. space -= n;
  454. }
  455. debugf2("%s\n", mem_buffer);
  456. p = mem_buffer;
  457. space = PAGE_SIZE;
  458. }
  459. n = snprintf(p, space, "-------------------------------"
  460. "------------------------------");
  461. p += n;
  462. space -= n;
  463. debugf2("%s\n", mem_buffer);
  464. p = mem_buffer;
  465. space = PAGE_SIZE;
  466. kfree(mem_buffer);
  467. }
  468. /*
  469. * i7300_init_csrows Initialize the 'csrows' table within
  470. * the mci control structure with the
  471. * addressing of memory.
  472. *
  473. * return:
  474. * 0 success
  475. * 1 no actual memory found on this MC
  476. */
  477. static int i7300_init_csrows(struct mem_ctl_info *mci)
  478. {
  479. struct i7300_pvt *pvt;
  480. struct i7300_dimm_info *dinfo;
  481. struct csrow_info *p_csrow;
  482. int empty;
  483. int mtr;
  484. int ch, branch, slot, channel;
  485. pvt = mci->pvt_info;
  486. empty = 1; /* Assume NO memory */
  487. debugf2("Memory Technology Registers:\n");
  488. /* Get the AMB present registers for the four channels */
  489. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  490. /* Read and dump branch 0's MTRs */
  491. channel = to_channel(0, branch);
  492. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_0,
  493. &pvt->ambpresent[channel]);
  494. debugf2("\t\tAMB-present CH%d = 0x%x:\n",
  495. channel, pvt->ambpresent[channel]);
  496. channel = to_channel(1, branch);
  497. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_1,
  498. &pvt->ambpresent[channel]);
  499. debugf2("\t\tAMB-present CH%d = 0x%x:\n",
  500. channel, pvt->ambpresent[channel]);
  501. }
  502. /* Get the set of MTR[0-7] regs by each branch */
  503. for (slot = 0; slot < MAX_SLOTS; slot++) {
  504. int where = mtr_regs[slot];
  505. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  506. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  507. where,
  508. &pvt->mtr[slot][branch]);
  509. for (ch = 0; ch < MAX_BRANCHES; ch++) {
  510. int channel = to_channel(ch, branch);
  511. dinfo = &pvt->dimm_info[slot][channel];
  512. p_csrow = &mci->csrows[slot];
  513. mtr = decode_mtr(pvt, slot, ch, branch,
  514. dinfo, p_csrow);
  515. /* if no DIMMS on this row, continue */
  516. if (!MTR_DIMMS_PRESENT(mtr))
  517. continue;
  518. p_csrow->csrow_idx = slot;
  519. /* FAKE OUT VALUES, FIXME */
  520. p_csrow->first_page = 0 + slot * 20;
  521. p_csrow->last_page = 9 + slot * 20;
  522. p_csrow->page_mask = 0xfff;
  523. empty = 0;
  524. }
  525. }
  526. }
  527. return empty;
  528. }
  529. static void decode_mir(int mir_no, u16 mir[MAX_MIR])
  530. {
  531. if (mir[mir_no] & 3)
  532. debugf2("MIR%d: limit= 0x%x Branch(es) that participate: %s %s\n",
  533. mir_no,
  534. (mir[mir_no] >> 4) & 0xfff,
  535. (mir[mir_no] & 1) ? "B0" : "",
  536. (mir[mir_no] & 2) ? "B1": "");
  537. }
  538. /*
  539. * i7300_get_mc_regs read in the necessary registers and
  540. * cache locally
  541. *
  542. * Fills in the private data members
  543. */
  544. static int i7300_get_mc_regs(struct mem_ctl_info *mci)
  545. {
  546. struct i7300_pvt *pvt;
  547. u32 actual_tolm;
  548. int i, rc;
  549. pvt = mci->pvt_info;
  550. pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
  551. (u32 *) &pvt->ambase);
  552. debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
  553. /* Get the Branch Map regs */
  554. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
  555. pvt->tolm >>= 12;
  556. debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
  557. pvt->tolm);
  558. actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
  559. debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
  560. actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
  561. /* Get memory controller settings */
  562. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
  563. &pvt->mc_settings);
  564. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
  565. &pvt->mc_settings_a);
  566. if (IS_SINGLE_MODE(pvt->mc_settings_a))
  567. debugf0("Memory controller operating on single mode\n");
  568. else
  569. debugf0("Memory controller operating on %s mode\n",
  570. IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored");
  571. debugf0("Error detection is %s\n",
  572. IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
  573. debugf0("Retry is %s\n",
  574. IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
  575. /* Get Memory Interleave Range registers */
  576. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0, &pvt->mir[0]);
  577. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1, &pvt->mir[1]);
  578. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2, &pvt->mir[2]);
  579. /* Decode the MIR regs */
  580. for (i = 0; i < MAX_MIR; i++)
  581. decode_mir(i, pvt->mir);
  582. rc = i7300_init_csrows(mci);
  583. if (rc < 0)
  584. return rc;
  585. /* Go and determine the size of each DIMM and place in an
  586. * orderly matrix */
  587. print_dimm_size(pvt);
  588. return 0;
  589. }
  590. /*************************************************
  591. * i7300 Functions related to device probe/release
  592. *************************************************/
  593. /*
  594. * i7300_put_devices 'put' all the devices that we have
  595. * reserved via 'get'
  596. */
  597. static void i7300_put_devices(struct mem_ctl_info *mci)
  598. {
  599. struct i7300_pvt *pvt;
  600. int branch;
  601. pvt = mci->pvt_info;
  602. /* Decrement usage count for devices */
  603. for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
  604. pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
  605. pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
  606. pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
  607. }
  608. /*
  609. * i7300_get_devices Find and perform 'get' operation on the MCH's
  610. * device/functions we want to reference for this driver
  611. *
  612. * Need to 'get' device 16 func 1 and func 2
  613. */
  614. static int i7300_get_devices(struct mem_ctl_info *mci, int dev_idx)
  615. {
  616. struct i7300_pvt *pvt;
  617. struct pci_dev *pdev;
  618. pvt = mci->pvt_info;
  619. /* Attempt to 'get' the MCH register we want */
  620. pdev = NULL;
  621. while (!pvt->pci_dev_16_1_fsb_addr_map || !pvt->pci_dev_16_2_fsb_err_regs) {
  622. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  623. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
  624. if (!pdev) {
  625. /* End of list, leave */
  626. i7300_printk(KERN_ERR,
  627. "'system address,Process Bus' "
  628. "device not found:"
  629. "vendor 0x%x device 0x%x ERR funcs "
  630. "(broken BIOS?)\n",
  631. PCI_VENDOR_ID_INTEL,
  632. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
  633. goto error;
  634. }
  635. /* Store device 16 funcs 1 and 2 */
  636. switch (PCI_FUNC(pdev->devfn)) {
  637. case 1:
  638. pvt->pci_dev_16_1_fsb_addr_map = pdev;
  639. break;
  640. case 2:
  641. pvt->pci_dev_16_2_fsb_err_regs = pdev;
  642. break;
  643. }
  644. }
  645. debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  646. pci_name(pvt->pci_dev_16_0_fsb_ctlr),
  647. pvt->pci_dev_16_0_fsb_ctlr->vendor, pvt->pci_dev_16_0_fsb_ctlr->device);
  648. debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  649. pci_name(pvt->pci_dev_16_1_fsb_addr_map),
  650. pvt->pci_dev_16_1_fsb_addr_map->vendor, pvt->pci_dev_16_1_fsb_addr_map->device);
  651. debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  652. pci_name(pvt->pci_dev_16_2_fsb_err_regs),
  653. pvt->pci_dev_16_2_fsb_err_regs->vendor, pvt->pci_dev_16_2_fsb_err_regs->device);
  654. pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
  655. PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
  656. NULL);
  657. if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
  658. i7300_printk(KERN_ERR,
  659. "MC: 'BRANCH 0' device not found:"
  660. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  661. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
  662. goto error;
  663. }
  664. pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
  665. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
  666. NULL);
  667. if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
  668. i7300_printk(KERN_ERR,
  669. "MC: 'BRANCH 1' device not found:"
  670. "vendor 0x%x device 0x%x Func 0 "
  671. "(broken BIOS?)\n",
  672. PCI_VENDOR_ID_INTEL,
  673. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
  674. goto error;
  675. }
  676. return 0;
  677. error:
  678. i7300_put_devices(mci);
  679. return -ENODEV;
  680. }
  681. /*
  682. * i7300_probe1 Probe for ONE instance of device to see if it is
  683. * present.
  684. * return:
  685. * 0 for FOUND a device
  686. * < 0 for error code
  687. */
  688. static int i7300_probe1(struct pci_dev *pdev, int dev_idx)
  689. {
  690. struct mem_ctl_info *mci;
  691. struct i7300_pvt *pvt;
  692. int num_channels;
  693. int num_dimms_per_channel;
  694. int num_csrows;
  695. if (dev_idx >= ARRAY_SIZE(i7300_devs))
  696. return -EINVAL;
  697. debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
  698. __func__,
  699. pdev->bus->number,
  700. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  701. /* We only are looking for func 0 of the set */
  702. if (PCI_FUNC(pdev->devfn) != 0)
  703. return -ENODEV;
  704. /* As we don't have a motherboard identification routine to determine
  705. * actual number of slots/dimms per channel, we thus utilize the
  706. * resource as specified by the chipset. Thus, we might have
  707. * have more DIMMs per channel than actually on the mobo, but this
  708. * allows the driver to support upto the chipset max, without
  709. * some fancy mobo determination.
  710. */
  711. num_dimms_per_channel = MAX_SLOTS;
  712. num_channels = MAX_CHANNELS;
  713. num_csrows = MAX_SLOTS * MAX_CHANNELS;
  714. debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
  715. __func__, num_channels, num_dimms_per_channel, num_csrows);
  716. /* allocate a new MC control structure */
  717. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  718. if (mci == NULL)
  719. return -ENOMEM;
  720. debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
  721. mci->dev = &pdev->dev; /* record ptr to the generic device */
  722. pvt = mci->pvt_info;
  723. pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */
  724. /* 'get' the pci devices we want to reserve for our use */
  725. if (i7300_get_devices(mci, dev_idx))
  726. goto fail0;
  727. mci->mc_idx = 0;
  728. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  729. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  730. mci->edac_cap = EDAC_FLAG_NONE;
  731. mci->mod_name = "i7300_edac.c";
  732. mci->mod_ver = I7300_REVISION;
  733. mci->ctl_name = i7300_devs[dev_idx].ctl_name;
  734. mci->dev_name = pci_name(pdev);
  735. mci->ctl_page_to_phys = NULL;
  736. /* Set the function pointer to an actual operation function */
  737. mci->edac_check = i7300_check_error;
  738. /* initialize the MC control structure 'csrows' table
  739. * with the mapping and control information */
  740. if (i7300_get_mc_regs(mci)) {
  741. debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
  742. " because i7300_init_csrows() returned nonzero "
  743. "value\n");
  744. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  745. } else {
  746. debugf1("MC: Enable error reporting now\n");
  747. i7300_enable_error_reporting(mci);
  748. }
  749. /* add this new MC control structure to EDAC's list of MCs */
  750. if (edac_mc_add_mc(mci)) {
  751. debugf0("MC: " __FILE__
  752. ": %s(): failed edac_mc_add_mc()\n", __func__);
  753. /* FIXME: perhaps some code should go here that disables error
  754. * reporting if we just enabled it
  755. */
  756. goto fail1;
  757. }
  758. i7300_clear_error(mci);
  759. /* allocating generic PCI control info */
  760. i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  761. if (!i7300_pci) {
  762. printk(KERN_WARNING
  763. "%s(): Unable to create PCI control\n",
  764. __func__);
  765. printk(KERN_WARNING
  766. "%s(): PCI error report via EDAC not setup\n",
  767. __func__);
  768. }
  769. return 0;
  770. /* Error exit unwinding stack */
  771. fail1:
  772. i7300_put_devices(mci);
  773. fail0:
  774. edac_mc_free(mci);
  775. return -ENODEV;
  776. }
  777. /*
  778. * i7300_init_one constructor for one instance of device
  779. *
  780. * returns:
  781. * negative on error
  782. * count (>= 0)
  783. */
  784. static int __devinit i7300_init_one(struct pci_dev *pdev,
  785. const struct pci_device_id *id)
  786. {
  787. int rc;
  788. debugf0("MC: " __FILE__ ": %s()\n", __func__);
  789. /* wake up device */
  790. rc = pci_enable_device(pdev);
  791. if (rc == -EIO)
  792. return rc;
  793. /* now probe and enable the device */
  794. return i7300_probe1(pdev, id->driver_data);
  795. }
  796. /*
  797. * i7300_remove_one destructor for one instance of device
  798. *
  799. */
  800. static void __devexit i7300_remove_one(struct pci_dev *pdev)
  801. {
  802. struct mem_ctl_info *mci;
  803. debugf0(__FILE__ ": %s()\n", __func__);
  804. if (i7300_pci)
  805. edac_pci_release_generic_ctl(i7300_pci);
  806. mci = edac_mc_del_mc(&pdev->dev);
  807. if (!mci)
  808. return;
  809. /* retrieve references to resources, and free those resources */
  810. i7300_put_devices(mci);
  811. edac_mc_free(mci);
  812. }
  813. /*
  814. * pci_device_id table for which devices we are looking for
  815. *
  816. * The "E500P" device is the first device supported.
  817. */
  818. static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
  819. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
  820. {0,} /* 0 terminated list. */
  821. };
  822. MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
  823. /*
  824. * i7300_driver pci_driver structure for this module
  825. *
  826. */
  827. static struct pci_driver i7300_driver = {
  828. .name = "i7300_edac",
  829. .probe = i7300_init_one,
  830. .remove = __devexit_p(i7300_remove_one),
  831. .id_table = i7300_pci_tbl,
  832. };
  833. /*
  834. * i7300_init Module entry function
  835. * Try to initialize this module for its devices
  836. */
  837. static int __init i7300_init(void)
  838. {
  839. int pci_rc;
  840. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  841. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  842. opstate_init();
  843. pci_rc = pci_register_driver(&i7300_driver);
  844. return (pci_rc < 0) ? pci_rc : 0;
  845. }
  846. /*
  847. * i7300_exit() Module exit function
  848. * Unregister the driver
  849. */
  850. static void __exit i7300_exit(void)
  851. {
  852. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  853. pci_unregister_driver(&i7300_driver);
  854. }
  855. module_init(i7300_init);
  856. module_exit(i7300_exit);
  857. MODULE_LICENSE("GPL");
  858. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  859. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  860. MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
  861. I7300_REVISION);
  862. module_param(edac_op_state, int, 0444);
  863. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");