i7300_edac.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. * FIXME: 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 Single Device Data correction,
  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. p_csrow->edac_mode = EDAC_S8ECD8ED;
  389. /* ask what device type on this row */
  390. if (MTR_DRAM_WIDTH(mtr)) {
  391. debugf0("Scrub algorithm for x8 is on %s mode\n",
  392. IS_SCRBALGO_ENHANCED(pvt->mc_settings) ?
  393. "enhanced" : "normal");
  394. p_csrow->dtype = DEV_X8;
  395. } else
  396. p_csrow->dtype = DEV_X4;
  397. return mtr;
  398. }
  399. /*
  400. * print_dimm_size
  401. *
  402. * also will output a DIMM matrix map, if debug is enabled, for viewing
  403. * how the DIMMs are populated
  404. */
  405. static void print_dimm_size(struct i7300_pvt *pvt)
  406. {
  407. struct i7300_dimm_info *dinfo;
  408. char *p, *mem_buffer;
  409. int space, n;
  410. int channel, slot;
  411. space = PAGE_SIZE;
  412. mem_buffer = p = kmalloc(space, GFP_KERNEL);
  413. if (p == NULL) {
  414. i7300_printk(KERN_ERR, "MC: %s:%s() kmalloc() failed\n",
  415. __FILE__, __func__);
  416. return;
  417. }
  418. n = snprintf(p, space, " ");
  419. p += n;
  420. space -= n;
  421. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  422. n = snprintf(p, space, "channel %d | ", channel);
  423. p += n;
  424. space -= n;
  425. }
  426. debugf2("%s\n", mem_buffer);
  427. p = mem_buffer;
  428. space = PAGE_SIZE;
  429. n = snprintf(p, space, "-------------------------------"
  430. "------------------------------");
  431. p += n;
  432. space -= n;
  433. debugf2("%s\n", mem_buffer);
  434. p = mem_buffer;
  435. space = PAGE_SIZE;
  436. for (slot = 0; slot < MAX_SLOTS; slot++) {
  437. n = snprintf(p, space, "csrow/SLOT %d ", slot);
  438. p += n;
  439. space -= n;
  440. for (channel = 0; channel < MAX_CHANNELS; channel++) {
  441. dinfo = &pvt->dimm_info[slot][channel];
  442. n = snprintf(p, space, "%4d MB | ", dinfo->megabytes);
  443. p += n;
  444. space -= n;
  445. }
  446. debugf2("%s\n", mem_buffer);
  447. p = mem_buffer;
  448. space = PAGE_SIZE;
  449. }
  450. n = snprintf(p, space, "-------------------------------"
  451. "------------------------------");
  452. p += n;
  453. space -= n;
  454. debugf2("%s\n", mem_buffer);
  455. p = mem_buffer;
  456. space = PAGE_SIZE;
  457. kfree(mem_buffer);
  458. }
  459. /*
  460. * i7300_init_csrows Initialize the 'csrows' table within
  461. * the mci control structure with the
  462. * addressing of memory.
  463. *
  464. * return:
  465. * 0 success
  466. * 1 no actual memory found on this MC
  467. */
  468. static int i7300_init_csrows(struct mem_ctl_info *mci)
  469. {
  470. struct i7300_pvt *pvt;
  471. struct i7300_dimm_info *dinfo;
  472. struct csrow_info *p_csrow;
  473. int empty;
  474. int mtr;
  475. int ch, branch, slot, channel;
  476. pvt = mci->pvt_info;
  477. empty = 1; /* Assume NO memory */
  478. debugf2("Memory Technology Registers:\n");
  479. /* Get the AMB present registers for the four channels */
  480. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  481. /* Read and dump branch 0's MTRs */
  482. channel = to_channel(0, branch);
  483. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_0,
  484. &pvt->ambpresent[channel]);
  485. debugf2("\t\tAMB-present CH%d = 0x%x:\n",
  486. channel, pvt->ambpresent[channel]);
  487. channel = to_channel(1, branch);
  488. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch], AMBPRESENT_1,
  489. &pvt->ambpresent[channel]);
  490. debugf2("\t\tAMB-present CH%d = 0x%x:\n",
  491. channel, pvt->ambpresent[channel]);
  492. }
  493. /* Get the set of MTR[0-7] regs by each branch */
  494. for (slot = 0; slot < MAX_SLOTS; slot++) {
  495. int where = mtr_regs[slot];
  496. for (branch = 0; branch < MAX_BRANCHES; branch++) {
  497. pci_read_config_word(pvt->pci_dev_2x_0_fbd_branch[branch],
  498. where,
  499. &pvt->mtr[slot][branch]);
  500. for (ch = 0; ch < MAX_BRANCHES; ch++) {
  501. int channel = to_channel(ch, branch);
  502. dinfo = &pvt->dimm_info[slot][channel];
  503. p_csrow = &mci->csrows[slot];
  504. mtr = decode_mtr(pvt, slot, ch, branch,
  505. dinfo, p_csrow);
  506. /* if no DIMMS on this row, continue */
  507. if (!MTR_DIMMS_PRESENT(mtr))
  508. continue;
  509. p_csrow->csrow_idx = slot;
  510. /* FAKE OUT VALUES, FIXME */
  511. p_csrow->first_page = 0 + slot * 20;
  512. p_csrow->last_page = 9 + slot * 20;
  513. p_csrow->page_mask = 0xfff;
  514. empty = 0;
  515. }
  516. }
  517. }
  518. return empty;
  519. }
  520. static void decode_mir(int mir_no, u16 mir[MAX_MIR])
  521. {
  522. if (mir[mir_no] & 3)
  523. debugf2("MIR%d: limit= 0x%x Branch(es) that participate: %s %s\n",
  524. mir_no,
  525. (mir[mir_no] >> 4) & 0xfff,
  526. (mir[mir_no] & 1) ? "B0" : "",
  527. (mir[mir_no] & 2) ? "B1": "");
  528. }
  529. /*
  530. * i7300_get_mc_regs read in the necessary registers and
  531. * cache locally
  532. *
  533. * Fills in the private data members
  534. */
  535. static int i7300_get_mc_regs(struct mem_ctl_info *mci)
  536. {
  537. struct i7300_pvt *pvt;
  538. u32 actual_tolm;
  539. int i, rc;
  540. pvt = mci->pvt_info;
  541. pci_read_config_dword(pvt->pci_dev_16_0_fsb_ctlr, AMBASE,
  542. (u32 *) &pvt->ambase);
  543. debugf2("AMBASE= 0x%lx\n", (long unsigned int)pvt->ambase);
  544. /* Get the Branch Map regs */
  545. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, TOLM, &pvt->tolm);
  546. pvt->tolm >>= 12;
  547. debugf2("TOLM (number of 256M regions) =%u (0x%x)\n", pvt->tolm,
  548. pvt->tolm);
  549. actual_tolm = (u32) ((1000l * pvt->tolm) >> (30 - 28));
  550. debugf2("Actual TOLM byte addr=%u.%03u GB (0x%x)\n",
  551. actual_tolm/1000, actual_tolm % 1000, pvt->tolm << 28);
  552. /* Get memory controller settings */
  553. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS,
  554. &pvt->mc_settings);
  555. pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, MC_SETTINGS_A,
  556. &pvt->mc_settings_a);
  557. if (IS_SINGLE_MODE(pvt->mc_settings_a))
  558. debugf0("Memory controller operating on single mode\n");
  559. else
  560. debugf0("Memory controller operating on %s mode\n",
  561. IS_MIRRORED(pvt->mc_settings) ? "mirrored" : "non-mirrored");
  562. debugf0("Error detection is %s\n",
  563. IS_ECC_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
  564. debugf0("Retry is %s\n",
  565. IS_RETRY_ENABLED(pvt->mc_settings) ? "enabled" : "disabled");
  566. /* Get Memory Interleave Range registers */
  567. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR0, &pvt->mir[0]);
  568. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR1, &pvt->mir[1]);
  569. pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, MIR2, &pvt->mir[2]);
  570. /* Decode the MIR regs */
  571. for (i = 0; i < MAX_MIR; i++)
  572. decode_mir(i, pvt->mir);
  573. rc = i7300_init_csrows(mci);
  574. if (rc < 0)
  575. return rc;
  576. /* Go and determine the size of each DIMM and place in an
  577. * orderly matrix */
  578. print_dimm_size(pvt);
  579. return 0;
  580. }
  581. /*************************************************
  582. * i7300 Functions related to device probe/release
  583. *************************************************/
  584. /*
  585. * i7300_put_devices 'put' all the devices that we have
  586. * reserved via 'get'
  587. */
  588. static void i7300_put_devices(struct mem_ctl_info *mci)
  589. {
  590. struct i7300_pvt *pvt;
  591. int branch;
  592. pvt = mci->pvt_info;
  593. /* Decrement usage count for devices */
  594. for (branch = 0; branch < MAX_CH_PER_BRANCH; branch++)
  595. pci_dev_put(pvt->pci_dev_2x_0_fbd_branch[branch]);
  596. pci_dev_put(pvt->pci_dev_16_2_fsb_err_regs);
  597. pci_dev_put(pvt->pci_dev_16_1_fsb_addr_map);
  598. }
  599. /*
  600. * i7300_get_devices Find and perform 'get' operation on the MCH's
  601. * device/functions we want to reference for this driver
  602. *
  603. * Need to 'get' device 16 func 1 and func 2
  604. */
  605. static int i7300_get_devices(struct mem_ctl_info *mci, int dev_idx)
  606. {
  607. struct i7300_pvt *pvt;
  608. struct pci_dev *pdev;
  609. pvt = mci->pvt_info;
  610. /* Attempt to 'get' the MCH register we want */
  611. pdev = NULL;
  612. while (!pvt->pci_dev_16_1_fsb_addr_map || !pvt->pci_dev_16_2_fsb_err_regs) {
  613. pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  614. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
  615. if (!pdev) {
  616. /* End of list, leave */
  617. i7300_printk(KERN_ERR,
  618. "'system address,Process Bus' "
  619. "device not found:"
  620. "vendor 0x%x device 0x%x ERR funcs "
  621. "(broken BIOS?)\n",
  622. PCI_VENDOR_ID_INTEL,
  623. PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
  624. goto error;
  625. }
  626. /* Store device 16 funcs 1 and 2 */
  627. switch (PCI_FUNC(pdev->devfn)) {
  628. case 1:
  629. pvt->pci_dev_16_1_fsb_addr_map = pdev;
  630. break;
  631. case 2:
  632. pvt->pci_dev_16_2_fsb_err_regs = pdev;
  633. break;
  634. }
  635. }
  636. debugf1("System Address, processor bus- PCI Bus ID: %s %x:%x\n",
  637. pci_name(pvt->pci_dev_16_0_fsb_ctlr),
  638. pvt->pci_dev_16_0_fsb_ctlr->vendor, pvt->pci_dev_16_0_fsb_ctlr->device);
  639. debugf1("Branchmap, control and errors - PCI Bus ID: %s %x:%x\n",
  640. pci_name(pvt->pci_dev_16_1_fsb_addr_map),
  641. pvt->pci_dev_16_1_fsb_addr_map->vendor, pvt->pci_dev_16_1_fsb_addr_map->device);
  642. debugf1("FSB Error Regs - PCI Bus ID: %s %x:%x\n",
  643. pci_name(pvt->pci_dev_16_2_fsb_err_regs),
  644. pvt->pci_dev_16_2_fsb_err_regs->vendor, pvt->pci_dev_16_2_fsb_err_regs->device);
  645. pvt->pci_dev_2x_0_fbd_branch[0] = pci_get_device(PCI_VENDOR_ID_INTEL,
  646. PCI_DEVICE_ID_INTEL_I7300_MCH_FB0,
  647. NULL);
  648. if (!pvt->pci_dev_2x_0_fbd_branch[0]) {
  649. i7300_printk(KERN_ERR,
  650. "MC: 'BRANCH 0' device not found:"
  651. "vendor 0x%x device 0x%x Func 0 (broken BIOS?)\n",
  652. PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_FB0);
  653. goto error;
  654. }
  655. pvt->pci_dev_2x_0_fbd_branch[1] = pci_get_device(PCI_VENDOR_ID_INTEL,
  656. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1,
  657. NULL);
  658. if (!pvt->pci_dev_2x_0_fbd_branch[1]) {
  659. i7300_printk(KERN_ERR,
  660. "MC: 'BRANCH 1' device not found:"
  661. "vendor 0x%x device 0x%x Func 0 "
  662. "(broken BIOS?)\n",
  663. PCI_VENDOR_ID_INTEL,
  664. PCI_DEVICE_ID_INTEL_I7300_MCH_FB1);
  665. goto error;
  666. }
  667. return 0;
  668. error:
  669. i7300_put_devices(mci);
  670. return -ENODEV;
  671. }
  672. /*
  673. * i7300_probe1 Probe for ONE instance of device to see if it is
  674. * present.
  675. * return:
  676. * 0 for FOUND a device
  677. * < 0 for error code
  678. */
  679. static int i7300_probe1(struct pci_dev *pdev, int dev_idx)
  680. {
  681. struct mem_ctl_info *mci;
  682. struct i7300_pvt *pvt;
  683. int num_channels;
  684. int num_dimms_per_channel;
  685. int num_csrows;
  686. if (dev_idx >= ARRAY_SIZE(i7300_devs))
  687. return -EINVAL;
  688. debugf0("MC: " __FILE__ ": %s(), pdev bus %u dev=0x%x fn=0x%x\n",
  689. __func__,
  690. pdev->bus->number,
  691. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
  692. /* We only are looking for func 0 of the set */
  693. if (PCI_FUNC(pdev->devfn) != 0)
  694. return -ENODEV;
  695. /* As we don't have a motherboard identification routine to determine
  696. * actual number of slots/dimms per channel, we thus utilize the
  697. * resource as specified by the chipset. Thus, we might have
  698. * have more DIMMs per channel than actually on the mobo, but this
  699. * allows the driver to support upto the chipset max, without
  700. * some fancy mobo determination.
  701. */
  702. num_dimms_per_channel = MAX_SLOTS;
  703. num_channels = MAX_CHANNELS;
  704. num_csrows = MAX_SLOTS * MAX_CHANNELS;
  705. debugf0("MC: %s(): Number of - Channels= %d DIMMS= %d CSROWS= %d\n",
  706. __func__, num_channels, num_dimms_per_channel, num_csrows);
  707. /* allocate a new MC control structure */
  708. mci = edac_mc_alloc(sizeof(*pvt), num_csrows, num_channels, 0);
  709. if (mci == NULL)
  710. return -ENOMEM;
  711. debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
  712. mci->dev = &pdev->dev; /* record ptr to the generic device */
  713. pvt = mci->pvt_info;
  714. pvt->pci_dev_16_0_fsb_ctlr = pdev; /* Record this device in our private */
  715. /* 'get' the pci devices we want to reserve for our use */
  716. if (i7300_get_devices(mci, dev_idx))
  717. goto fail0;
  718. mci->mc_idx = 0;
  719. mci->mtype_cap = MEM_FLAG_FB_DDR2;
  720. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  721. mci->edac_cap = EDAC_FLAG_NONE;
  722. mci->mod_name = "i7300_edac.c";
  723. mci->mod_ver = I7300_REVISION;
  724. mci->ctl_name = i7300_devs[dev_idx].ctl_name;
  725. mci->dev_name = pci_name(pdev);
  726. mci->ctl_page_to_phys = NULL;
  727. /* Set the function pointer to an actual operation function */
  728. mci->edac_check = i7300_check_error;
  729. /* initialize the MC control structure 'csrows' table
  730. * with the mapping and control information */
  731. if (i7300_get_mc_regs(mci)) {
  732. debugf0("MC: Setting mci->edac_cap to EDAC_FLAG_NONE\n"
  733. " because i7300_init_csrows() returned nonzero "
  734. "value\n");
  735. mci->edac_cap = EDAC_FLAG_NONE; /* no csrows found */
  736. } else {
  737. debugf1("MC: Enable error reporting now\n");
  738. i7300_enable_error_reporting(mci);
  739. }
  740. /* add this new MC control structure to EDAC's list of MCs */
  741. if (edac_mc_add_mc(mci)) {
  742. debugf0("MC: " __FILE__
  743. ": %s(): failed edac_mc_add_mc()\n", __func__);
  744. /* FIXME: perhaps some code should go here that disables error
  745. * reporting if we just enabled it
  746. */
  747. goto fail1;
  748. }
  749. i7300_clear_error(mci);
  750. /* allocating generic PCI control info */
  751. i7300_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  752. if (!i7300_pci) {
  753. printk(KERN_WARNING
  754. "%s(): Unable to create PCI control\n",
  755. __func__);
  756. printk(KERN_WARNING
  757. "%s(): PCI error report via EDAC not setup\n",
  758. __func__);
  759. }
  760. return 0;
  761. /* Error exit unwinding stack */
  762. fail1:
  763. i7300_put_devices(mci);
  764. fail0:
  765. edac_mc_free(mci);
  766. return -ENODEV;
  767. }
  768. /*
  769. * i7300_init_one constructor for one instance of device
  770. *
  771. * returns:
  772. * negative on error
  773. * count (>= 0)
  774. */
  775. static int __devinit i7300_init_one(struct pci_dev *pdev,
  776. const struct pci_device_id *id)
  777. {
  778. int rc;
  779. debugf0("MC: " __FILE__ ": %s()\n", __func__);
  780. /* wake up device */
  781. rc = pci_enable_device(pdev);
  782. if (rc == -EIO)
  783. return rc;
  784. /* now probe and enable the device */
  785. return i7300_probe1(pdev, id->driver_data);
  786. }
  787. /*
  788. * i7300_remove_one destructor for one instance of device
  789. *
  790. */
  791. static void __devexit i7300_remove_one(struct pci_dev *pdev)
  792. {
  793. struct mem_ctl_info *mci;
  794. debugf0(__FILE__ ": %s()\n", __func__);
  795. if (i7300_pci)
  796. edac_pci_release_generic_ctl(i7300_pci);
  797. mci = edac_mc_del_mc(&pdev->dev);
  798. if (!mci)
  799. return;
  800. /* retrieve references to resources, and free those resources */
  801. i7300_put_devices(mci);
  802. edac_mc_free(mci);
  803. }
  804. /*
  805. * pci_device_id table for which devices we are looking for
  806. *
  807. * The "E500P" device is the first device supported.
  808. */
  809. static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
  810. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
  811. {0,} /* 0 terminated list. */
  812. };
  813. MODULE_DEVICE_TABLE(pci, i7300_pci_tbl);
  814. /*
  815. * i7300_driver pci_driver structure for this module
  816. *
  817. */
  818. static struct pci_driver i7300_driver = {
  819. .name = "i7300_edac",
  820. .probe = i7300_init_one,
  821. .remove = __devexit_p(i7300_remove_one),
  822. .id_table = i7300_pci_tbl,
  823. };
  824. /*
  825. * i7300_init Module entry function
  826. * Try to initialize this module for its devices
  827. */
  828. static int __init i7300_init(void)
  829. {
  830. int pci_rc;
  831. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  832. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  833. opstate_init();
  834. pci_rc = pci_register_driver(&i7300_driver);
  835. return (pci_rc < 0) ? pci_rc : 0;
  836. }
  837. /*
  838. * i7300_exit() Module exit function
  839. * Unregister the driver
  840. */
  841. static void __exit i7300_exit(void)
  842. {
  843. debugf2("MC: " __FILE__ ": %s()\n", __func__);
  844. pci_unregister_driver(&i7300_driver);
  845. }
  846. module_init(i7300_init);
  847. module_exit(i7300_exit);
  848. MODULE_LICENSE("GPL");
  849. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  850. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
  851. MODULE_DESCRIPTION("MC Driver for Intel I7300 memory controllers - "
  852. I7300_REVISION);
  853. module_param(edac_op_state, int, 0444);
  854. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");