1.. include:: <isonum.txt>
2
3============================================
4Reliability, Availability and Serviceability
5============================================
6
7RAS concepts
8************
9
10Reliability, Availability and Serviceability (RAS) is a concept used on
11servers meant to measure their robustness.
12
13Reliability
14  is the probability that a system will produce correct outputs.
15
16  * Generally measured as Mean Time Between Failures (MTBF)
17  * Enhanced by features that help to avoid, detect and repair hardware faults
18
19Availability
20  is the probability that a system is operational at a given time
21
22  * Generally measured as a percentage of downtime per a period of time
23  * Often uses mechanisms to detect and correct hardware faults in
24    runtime;
25
26Serviceability (or maintainability)
27  is the simplicity and speed with which a system can be repaired or
28  maintained
29
30  * Generally measured on Mean Time Between Repair (MTBR)
31
32Improving RAS
33-------------
34
35In order to reduce systems downtime, a system should be capable of detecting
36hardware errors, and, when possible correcting them in runtime. It should
37also provide mechanisms to detect hardware degradation, in order to warn
38the system administrator to take the action of replacing a component before
39it causes data loss or system downtime.
40
41Among the monitoring measures, the most usual ones include:
42
43* CPU – detect errors at instruction execution and at L1/L2/L3 caches;
44* Memory – add error correction logic (ECC) to detect and correct errors;
45* I/O – add CRC checksums for transferred data;
46* Storage – RAID, journal file systems, checksums,
47  Self-Monitoring, Analysis and Reporting Technology (SMART).
48
49By monitoring the number of occurrences of error detections, it is possible
50to identify if the probability of hardware errors is increasing, and, on such
51case, do a preventive maintenance to replace a degraded component while
52those errors are correctable.
53
54Types of errors
55---------------
56
57Most mechanisms used on modern systems use technologies like Hamming
58Codes that allow error correction when the number of errors on a bit packet
59is below a threshold. If the number of errors is above, those mechanisms
60can indicate with a high degree of confidence that an error happened, but
61they can't correct.
62
63Also, sometimes an error occur on a component that it is not used. For
64example, a part of the memory that it is not currently allocated.
65
66That defines some categories of errors:
67
68* **Correctable Error (CE)** - the error detection mechanism detected and
69  corrected the error. Such errors are usually not fatal, although some
70  Kernel mechanisms allow the system administrator to consider them as fatal.
71
72* **Uncorrected Error (UE)** - the amount of errors happened above the error
73  correction threshold, and the system was unable to auto-correct.
74
75* **Fatal Error** - when an UE error happens on a critical component of the
76  system (for example, a piece of the Kernel got corrupted by an UE), the
77  only reliable way to avoid data corruption is to hang or reboot the machine.
78
79* **Non-fatal Error** - when an UE error happens on an unused component,
80  like a CPU in power down state or an unused memory bank, the system may
81  still run, eventually replacing the affected hardware by a hot spare,
82  if available.
83
84  Also, when an error happens on a userspace process, it is also possible to
85  kill such process and let userspace restart it.
86
87The mechanism for handling non-fatal errors is usually complex and may
88require the help of some userspace application, in order to apply the
89policy desired by the system administrator.
90
91Identifying a bad hardware component
92------------------------------------
93
94Just detecting a hardware flaw is usually not enough, as the system needs
95to pinpoint to the minimal replaceable unit (MRU) that should be exchanged
96to make the hardware reliable again.
97
98So, it requires not only error logging facilities, but also mechanisms that
99will translate the error message to the silkscreen or component label for
100the MRU.
101
102Typically, it is very complex for memory, as modern CPUs interlace memory
103from different memory modules, in order to provide a better performance. The
104DMI BIOS usually have a list of memory module labels, with can be obtained
105using the ``dmidecode`` tool. For example, on a desktop machine, it shows::
106
107	Memory Device
108		Total Width: 64 bits
109		Data Width: 64 bits
110		Size: 16384 MB
111		Form Factor: SODIMM
112		Set: None
113		Locator: ChannelA-DIMM0
114		Bank Locator: BANK 0
115		Type: DDR4
116		Type Detail: Synchronous
117		Speed: 2133 MHz
118		Rank: 2
119		Configured Clock Speed: 2133 MHz
120
121On the above example, a DDR4 SO-DIMM memory module is located at the
122system's memory labeled as "BANK 0", as given by the *bank locator* field.
123Please notice that, on such system, the *total width* is equal to the
124*data width*. It means that such memory module doesn't have error
125detection/correction mechanisms.
126
127Unfortunately, not all systems use the same field to specify the memory
128bank. On this example, from an older server, ``dmidecode`` shows::
129
130	Memory Device
131		Array Handle: 0x1000
132		Error Information Handle: Not Provided
133		Total Width: 72 bits
134		Data Width: 64 bits
135		Size: 8192 MB
136		Form Factor: DIMM
137		Set: 1
138		Locator: DIMM_A1
139		Bank Locator: Not Specified
140		Type: DDR3
141		Type Detail: Synchronous Registered (Buffered)
142		Speed: 1600 MHz
143		Rank: 2
144		Configured Clock Speed: 1600 MHz
145
146There, the DDR3 RDIMM memory module is located at the system's memory labeled
147as "DIMM_A1", as given by the *locator* field. Please notice that this
148memory module has 64 bits of *data width* and 72 bits of *total width*. So,
149it has 8 extra bits to be used by error detection and correction mechanisms.
150Such kind of memory is called Error-correcting code memory (ECC memory).
151
152To make things even worse, it is not uncommon that systems with different
153labels on their system's board to use exactly the same BIOS, meaning that
154the labels provided by the BIOS won't match the real ones.
155
156ECC memory
157----------
158
159As mentioned on the previous section, ECC memory has extra bits to be
160used for error correction. So, on 64 bit systems, a memory module
161has 64 bits of *data width*, and 74 bits of *total width*. So, there are
1628 bits extra bits to be used for the error detection and correction
163mechanisms. Those extra bits are called *syndrome*\ [#f1]_\ [#f2]_.
164
165So, when the cpu requests the memory controller to write a word with
166*data width*, the memory controller calculates the *syndrome* in real time,
167using Hamming code, or some other error correction code, like SECDED+,
168producing a code with *total width* size. Such code is then written
169on the memory modules.
170
171At read, the *total width* bits code is converted back, using the same
172ECC code used on write, producing a word with *data width* and a *syndrome*.
173The word with *data width* is sent to the CPU, even when errors happen.
174
175The memory controller also looks at the *syndrome* in order to check if
176there was an error, and if the ECC code was able to fix such error.
177If the error was corrected, a Corrected Error (CE) happened. If not, an
178Uncorrected Error (UE) happened.
179
180The information about the CE/UE errors is stored on some special registers
181at the memory controller and can be accessed by reading such registers,
182either by BIOS, by some special CPUs or by Linux EDAC driver. On x86 64
183bit CPUs, such errors can also be retrieved via the Machine Check
184Architecture (MCA)\ [#f3]_.
185
186.. [#f1] Please notice that several memory controllers allow operation on a
187  mode called "Lock-Step", where it groups two memory modules together,
188  doing 128-bit reads/writes. That gives 16 bits for error correction, with
189  significantly improves the error correction mechanism, at the expense
190  that, when an error happens, there's no way to know what memory module is
191  to blame. So, it has to blame both memory modules.
192
193.. [#f2] Some memory controllers also allow using memory in mirror mode.
194  On such mode, the same data is written to two memory modules. At read,
195  the system checks both memory modules, in order to check if both provide
196  identical data. On such configuration, when an error happens, there's no
197  way to know what memory module is to blame. So, it has to blame both
198  memory modules (or 4 memory modules, if the system is also on Lock-step
199  mode).
200
201.. [#f3] For more details about the Machine Check Architecture (MCA),
202  please read Documentation/x86/x86_64/machinecheck.rst at the Kernel tree.
203
204EDAC - Error Detection And Correction
205*************************************
206
207.. note::
208
209   "bluesmoke" was the name for this device driver subsystem when it
210   was "out-of-tree" and maintained at http://bluesmoke.sourceforge.net.
211   That site is mostly archaic now and can be used only for historical
212   purposes.
213
214   When the subsystem was pushed upstream for the first time, on
215   Kernel 2.6.16, for the first time, it was renamed to ``EDAC``.
216
217Purpose
218-------
219
220The ``edac`` kernel module's goal is to detect and report hardware errors
221that occur within the computer system running under linux.
222
223Memory
224------
225
226Memory Correctable Errors (CE) and Uncorrectable Errors (UE) are the
227primary errors being harvested. These types of errors are harvested by
228the ``edac_mc`` device.
229
230Detecting CE events, then harvesting those events and reporting them,
231**can** but must not necessarily be a predictor of future UE events. With
232CE events only, the system can and will continue to operate as no data
233has been damaged yet.
234
235However, preventive maintenance and proactive part replacement of memory
236modules exhibiting CEs can reduce the likelihood of the dreaded UE events
237and system panics.
238
239Other hardware elements
240-----------------------
241
242A new feature for EDAC, the ``edac_device`` class of device, was added in
243the 2.6.23 version of the kernel.
244
245This new device type allows for non-memory type of ECC hardware detectors
246to have their states harvested and presented to userspace via the sysfs
247interface.
248
249Some architectures have ECC detectors for L1, L2 and L3 caches,
250along with DMA engines, fabric switches, main data path switches,
251interconnections, and various other hardware data paths. If the hardware
252reports it, then a edac_device device probably can be constructed to
253harvest and present that to userspace.
254
255
256PCI bus scanning
257----------------
258
259In addition, PCI devices are scanned for PCI Bus Parity and SERR Errors
260in order to determine if errors are occurring during data transfers.
261
262The presence of PCI Parity errors must be examined with a grain of salt.
263There are several add-in adapters that do **not** follow the PCI specification
264with regards to Parity generation and reporting. The specification says
265the vendor should tie the parity status bits to 0 if they do not intend
266to generate parity.  Some vendors do not do this, and thus the parity bit
267can "float" giving false positives.
268
269There is a PCI device attribute located in sysfs that is checked by
270the EDAC PCI scanning code. If that attribute is set, PCI parity/error
271scanning is skipped for that device. The attribute is::
272
273	broken_parity_status
274
275and is located in ``/sys/devices/pci<XXX>/0000:XX:YY.Z`` directories for
276PCI devices.
277
278
279Versioning
280----------
281
282EDAC is composed of a "core" module (``edac_core.ko``) and several Memory
283Controller (MC) driver modules. On a given system, the CORE is loaded
284and one MC driver will be loaded. Both the CORE and the MC driver (or
285``edac_device`` driver) have individual versions that reflect current
286release level of their respective modules.
287
288Thus, to "report" on what version a system is running, one must report
289both the CORE's and the MC driver's versions.
290
291
292Loading
293-------
294
295If ``edac`` was statically linked with the kernel then no loading
296is necessary. If ``edac`` was built as modules then simply modprobe
297the ``edac`` pieces that you need. You should be able to modprobe
298hardware-specific modules and have the dependencies load the necessary
299core modules.
300
301Example::
302
303	$ modprobe amd76x_edac
304
305loads both the ``amd76x_edac.ko`` memory controller module and the
306``edac_mc.ko`` core module.
307
308
309Sysfs interface
310---------------
311
312EDAC presents a ``sysfs`` interface for control and reporting purposes. It
313lives in the /sys/devices/system/edac directory.
314
315Within this directory there currently reside 2 components:
316
317	======= ==============================
318	mc	memory controller(s) system
319	pci	PCI control and status system
320	======= ==============================
321
322
323
324Memory Controller (mc) Model
325----------------------------
326
327Each ``mc`` device controls a set of memory modules [#f4]_. These modules
328are laid out in a Chip-Select Row (``csrowX``) and Channel table (``chX``).
329There can be multiple csrows and multiple channels.
330
331.. [#f4] Nowadays, the term DIMM (Dual In-line Memory Module) is widely
332  used to refer to a memory module, although there are other memory
333  packaging alternatives, like SO-DIMM, SIMM, etc. The UEFI
334  specification (Version 2.7) defines a memory module in the Common
335  Platform Error Record (CPER) section to be an SMBIOS Memory Device
336  (Type 17). Along this document, and inside the EDAC subsystem, the term
337  "dimm" is used for all memory modules, even when they use a
338  different kind of packaging.
339
340Memory controllers allow for several csrows, with 8 csrows being a
341typical value. Yet, the actual number of csrows depends on the layout of
342a given motherboard, memory controller and memory module characteristics.
343
344Dual channels allow for dual data length (e. g. 128 bits, on 64 bit systems)
345data transfers to/from the CPU from/to memory. Some newer chipsets allow
346for more than 2 channels, like Fully Buffered DIMMs (FB-DIMMs) memory
347controllers. The following example will assume 2 channels:
348
349	+------------+-----------------------+
350	| CS Rows    |       Channels        |
351	+------------+-----------+-----------+
352	|            |  ``ch0``  |  ``ch1``  |
353	+============+===========+===========+
354	| ``csrow0`` |  DIMM_A0  |  DIMM_B0  |
355	|            |   rank0   |   rank0   |
356	+------------+     -     |     -     |
357	| ``csrow1`` |   rank1   |   rank1   |
358	+------------+-----------+-----------+
359	| ``csrow2`` |  DIMM_A1  | DIMM_B1   |
360	|            |   rank0   |   rank0   |
361	+------------+     -     |     -     |
362	| ``csrow3`` |   rank1   |   rank1   |
363	+------------+-----------+-----------+
364
365In the above example, there are 4 physical slots on the motherboard
366for memory DIMMs:
367
368	+---------+---------+
369	| DIMM_A0 | DIMM_B0 |
370	+---------+---------+
371	| DIMM_A1 | DIMM_B1 |
372	+---------+---------+
373
374Labels for these slots are usually silk-screened on the motherboard.
375Slots labeled ``A`` are channel 0 in this example. Slots labeled ``B`` are
376channel 1. Notice that there are two csrows possible on a physical DIMM.
377These csrows are allocated their csrow assignment based on the slot into
378which the memory DIMM is placed. Thus, when 1 DIMM is placed in each
379Channel, the csrows cross both DIMMs.
380
381Memory DIMMs come single or dual "ranked". A rank is a populated csrow.
382In the example above 2 dual ranked DIMMs are similarly placed. Thus,
383both csrow0 and csrow1 are populated. On the other hand, when 2 single
384ranked DIMMs are placed in slots DIMM_A0 and DIMM_B0, then they will
385have just one csrow (csrow0) and csrow1 will be empty. The pattern
386repeats itself for csrow2 and csrow3. Also note that some memory
387controllers don't have any logic to identify the memory module, see
388``rankX`` directories below.
389
390The representation of the above is reflected in the directory
391tree in EDAC's sysfs interface. Starting in directory
392``/sys/devices/system/edac/mc``, each memory controller will be
393represented by its own ``mcX`` directory, where ``X`` is the
394index of the MC::
395
396	..../edac/mc/
397		   |
398		   |->mc0
399		   |->mc1
400		   |->mc2
401		   ....
402
403Under each ``mcX`` directory each ``csrowX`` is again represented by a
404``csrowX``, where ``X`` is the csrow index::
405
406	.../mc/mc0/
407		|
408		|->csrow0
409		|->csrow2
410		|->csrow3
411		....
412
413Notice that there is no csrow1, which indicates that csrow0 is composed
414of a single ranked DIMMs. This should also apply in both Channels, in
415order to have dual-channel mode be operational. Since both csrow2 and
416csrow3 are populated, this indicates a dual ranked set of DIMMs for
417channels 0 and 1.
418
419Within each of the ``mcX`` and ``csrowX`` directories are several EDAC
420control and attribute files.
421
422``mcX`` directories
423-------------------
424
425In ``mcX`` directories are EDAC control and attribute files for
426this ``X`` instance of the memory controllers.
427
428For a description of the sysfs API, please see:
429
430	Documentation/ABI/testing/sysfs-devices-edac
431
432
433``dimmX`` or ``rankX`` directories
434----------------------------------
435
436The recommended way to use the EDAC subsystem is to look at the information
437provided by the ``dimmX`` or ``rankX`` directories [#f5]_.
438
439A typical EDAC system has the following structure under
440``/sys/devices/system/edac/``\ [#f6]_::
441
442	/sys/devices/system/edac/
443	├── mc
444	│   ├── mc0
445	│   │   ├── ce_count
446	│   │   ├── ce_noinfo_count
447	│   │   ├── dimm0
448	│   │   │   ├── dimm_ce_count
449	│   │   │   ├── dimm_dev_type
450	│   │   │   ├── dimm_edac_mode
451	│   │   │   ├── dimm_label
452	│   │   │   ├── dimm_location
453	│   │   │   ├── dimm_mem_type
454	│   │   │   ├── dimm_ue_count
455	│   │   │   ├── size
456	│   │   │   └── uevent
457	│   │   ├── max_location
458	│   │   ├── mc_name
459	│   │   ├── reset_counters
460	│   │   ├── seconds_since_reset
461	│   │   ├── size_mb
462	│   │   ├── ue_count
463	│   │   ├── ue_noinfo_count
464	│   │   └── uevent
465	│   ├── mc1
466	│   │   ├── ce_count
467	│   │   ├── ce_noinfo_count
468	│   │   ├── dimm0
469	│   │   │   ├── dimm_ce_count
470	│   │   │   ├── dimm_dev_type
471	│   │   │   ├── dimm_edac_mode
472	│   │   │   ├── dimm_label
473	│   │   │   ├── dimm_location
474	│   │   │   ├── dimm_mem_type
475	│   │   │   ├── dimm_ue_count
476	│   │   │   ├── size
477	│   │   │   └── uevent
478	│   │   ├── max_location
479	│   │   ├── mc_name
480	│   │   ├── reset_counters
481	│   │   ├── seconds_since_reset
482	│   │   ├── size_mb
483	│   │   ├── ue_count
484	│   │   ├── ue_noinfo_count
485	│   │   └── uevent
486	│   └── uevent
487	└── uevent
488
489In the ``dimmX`` directories are EDAC control and attribute files for
490this ``X`` memory module:
491
492- ``size`` - Total memory managed by this csrow attribute file
493
494	This attribute file displays, in count of megabytes, the memory
495	that this csrow contains.
496
497- ``dimm_ue_count`` - Uncorrectable Errors count attribute file
498
499	This attribute file displays the total count of uncorrectable
500	errors that have occurred on this DIMM. If panic_on_ue is set
501	this counter will not have a chance to increment, since EDAC
502	will panic the system.
503
504- ``dimm_ce_count`` - Correctable Errors count attribute file
505
506	This attribute file displays the total count of correctable
507	errors that have occurred on this DIMM. This count is very
508	important to examine. CEs provide early indications that a
509	DIMM is beginning to fail. This count field should be
510	monitored for non-zero values and report such information
511	to the system administrator.
512
513- ``dimm_dev_type``  - Device type attribute file
514
515	This attribute file will display what type of DRAM device is
516	being utilized on this DIMM.
517	Examples:
518
519		- x1
520		- x2
521		- x4
522		- x8
523
524- ``dimm_edac_mode`` - EDAC Mode of operation attribute file
525
526	This attribute file will display what type of Error detection
527	and correction is being utilized.
528
529- ``dimm_label`` - memory module label control file
530
531	This control file allows this DIMM to have a label assigned
532	to it. With this label in the module, when errors occur
533	the output can provide the DIMM label in the system log.
534	This becomes vital for panic events to isolate the
535	cause of the UE event.
536
537	DIMM Labels must be assigned after booting, with information
538	that correctly identifies the physical slot with its
539	silk screen label. This information is currently very
540	motherboard specific and determination of this information
541	must occur in userland at this time.
542
543- ``dimm_location`` - location of the memory module
544
545	The location can have up to 3 levels, and describe how the
546	memory controller identifies the location of a memory module.
547	Depending on the type of memory and memory controller, it
548	can be:
549
550		- *csrow* and *channel* - used when the memory controller
551		  doesn't identify a single DIMM - e. g. in ``rankX`` dir;
552		- *branch*, *channel*, *slot* - typically used on FB-DIMM memory
553		  controllers;
554		- *channel*, *slot* - used on Nehalem and newer Intel drivers.
555
556- ``dimm_mem_type`` - Memory Type attribute file
557
558	This attribute file will display what type of memory is currently
559	on this csrow. Normally, either buffered or unbuffered memory.
560	Examples:
561
562		- Registered-DDR
563		- Unbuffered-DDR
564
565.. [#f5] On some systems, the memory controller doesn't have any logic
566  to identify the memory module. On such systems, the directory is called ``rankX`` and works on a similar way as the ``csrowX`` directories.
567  On modern Intel memory controllers, the memory controller identifies the
568  memory modules directly. On such systems, the directory is called ``dimmX``.
569
570.. [#f6] There are also some ``power`` directories and ``subsystem``
571  symlinks inside the sysfs mapping that are automatically created by
572  the sysfs subsystem. Currently, they serve no purpose.
573
574``csrowX`` directories
575----------------------
576
577When CONFIG_EDAC_LEGACY_SYSFS is enabled, sysfs will contain the ``csrowX``
578directories. As this API doesn't work properly for Rambus, FB-DIMMs and
579modern Intel Memory Controllers, this is being deprecated in favor of
580``dimmX`` directories.
581
582In the ``csrowX`` directories are EDAC control and attribute files for
583this ``X`` instance of csrow:
584
585
586- ``ue_count`` - Total Uncorrectable Errors count attribute file
587
588	This attribute file displays the total count of uncorrectable
589	errors that have occurred on this csrow. If panic_on_ue is set
590	this counter will not have a chance to increment, since EDAC
591	will panic the system.
592
593
594- ``ce_count`` - Total Correctable Errors count attribute file
595
596	This attribute file displays the total count of correctable
597	errors that have occurred on this csrow. This count is very
598	important to examine. CEs provide early indications that a
599	DIMM is beginning to fail. This count field should be
600	monitored for non-zero values and report such information
601	to the system administrator.
602
603
604- ``size_mb`` - Total memory managed by this csrow attribute file
605
606	This attribute file displays, in count of megabytes, the memory
607	that this csrow contains.
608
609
610- ``mem_type`` - Memory Type attribute file
611
612	This attribute file will display what type of memory is currently
613	on this csrow. Normally, either buffered or unbuffered memory.
614	Examples:
615
616		- Registered-DDR
617		- Unbuffered-DDR
618
619
620- ``edac_mode`` - EDAC Mode of operation attribute file
621
622	This attribute file will display what type of Error detection
623	and correction is being utilized.
624
625
626- ``dev_type`` - Device type attribute file
627
628	This attribute file will display what type of DRAM device is
629	being utilized on this DIMM.
630	Examples:
631
632		- x1
633		- x2
634		- x4
635		- x8
636
637
638- ``ch0_ce_count`` - Channel 0 CE Count attribute file
639
640	This attribute file will display the count of CEs on this
641	DIMM located in channel 0.
642
643
644- ``ch0_ue_count`` - Channel 0 UE Count attribute file
645
646	This attribute file will display the count of UEs on this
647	DIMM located in channel 0.
648
649
650- ``ch0_dimm_label`` - Channel 0 DIMM Label control file
651
652
653	This control file allows this DIMM to have a label assigned
654	to it. With this label in the module, when errors occur
655	the output can provide the DIMM label in the system log.
656	This becomes vital for panic events to isolate the
657	cause of the UE event.
658
659	DIMM Labels must be assigned after booting, with information
660	that correctly identifies the physical slot with its
661	silk screen label. This information is currently very
662	motherboard specific and determination of this information
663	must occur in userland at this time.
664
665
666- ``ch1_ce_count`` - Channel 1 CE Count attribute file
667
668
669	This attribute file will display the count of CEs on this
670	DIMM located in channel 1.
671
672
673- ``ch1_ue_count`` - Channel 1 UE Count attribute file
674
675
676	This attribute file will display the count of UEs on this
677	DIMM located in channel 0.
678
679
680- ``ch1_dimm_label`` - Channel 1 DIMM Label control file
681
682	This control file allows this DIMM to have a label assigned
683	to it. With this label in the module, when errors occur
684	the output can provide the DIMM label in the system log.
685	This becomes vital for panic events to isolate the
686	cause of the UE event.
687
688	DIMM Labels must be assigned after booting, with information
689	that correctly identifies the physical slot with its
690	silk screen label. This information is currently very
691	motherboard specific and determination of this information
692	must occur in userland at this time.
693
694
695System Logging
696--------------
697
698If logging for UEs and CEs is enabled, then system logs will contain
699information indicating that errors have been detected::
700
701  EDAC MC0: CE page 0x283, offset 0xce0, grain 8, syndrome 0x6ec3, row 0, channel 1 "DIMM_B1": amd76x_edac
702  EDAC MC0: CE page 0x1e5, offset 0xfb0, grain 8, syndrome 0xb741, row 0, channel 1 "DIMM_B1": amd76x_edac
703
704
705The structure of the message is:
706
707	+---------------------------------------+-------------+
708	| Content                               | Example     |
709	+=======================================+=============+
710	| The memory controller                 | MC0         |
711	+---------------------------------------+-------------+
712	| Error type                            | CE          |
713	+---------------------------------------+-------------+
714	| Memory page                           | 0x283       |
715	+---------------------------------------+-------------+
716	| Offset in the page                    | 0xce0       |
717	+---------------------------------------+-------------+
718	| The byte granularity                  | grain 8     |
719	| or resolution of the error            |             |
720	+---------------------------------------+-------------+
721	| The error syndrome                    | 0xb741      |
722	+---------------------------------------+-------------+
723	| Memory row                            | row 0       |
724	+---------------------------------------+-------------+
725	| Memory channel                        | channel 1   |
726	+---------------------------------------+-------------+
727	| DIMM label, if set prior              | DIMM B1     |
728	+---------------------------------------+-------------+
729	| And then an optional, driver-specific |             |
730	| message that may have additional      |             |
731	| information.                          |             |
732	+---------------------------------------+-------------+
733
734Both UEs and CEs with no info will lack all but memory controller, error
735type, a notice of "no info" and then an optional, driver-specific error
736message.
737
738
739PCI Bus Parity Detection
740------------------------
741
742On Header Type 00 devices, the primary status is looked at for any
743parity error regardless of whether parity is enabled on the device or
744not. (The spec indicates parity is generated in some cases). On Header
745Type 01 bridges, the secondary status register is also looked at to see
746if parity occurred on the bus on the other side of the bridge.
747
748
749Sysfs configuration
750-------------------
751
752Under ``/sys/devices/system/edac/pci`` are control and attribute files as
753follows:
754
755
756- ``check_pci_parity`` - Enable/Disable PCI Parity checking control file
757
758	This control file enables or disables the PCI Bus Parity scanning
759	operation. Writing a 1 to this file enables the scanning. Writing
760	a 0 to this file disables the scanning.
761
762	Enable::
763
764		echo "1" >/sys/devices/system/edac/pci/check_pci_parity
765
766	Disable::
767
768		echo "0" >/sys/devices/system/edac/pci/check_pci_parity
769
770
771- ``pci_parity_count`` - Parity Count
772
773	This attribute file will display the number of parity errors that
774	have been detected.
775
776
777Module parameters
778-----------------
779
780- ``edac_mc_panic_on_ue`` - Panic on UE control file
781
782	An uncorrectable error will cause a machine panic.  This is usually
783	desirable.  It is a bad idea to continue when an uncorrectable error
784	occurs - it is indeterminate what was uncorrected and the operating
785	system context might be so mangled that continuing will lead to further
786	corruption. If the kernel has MCE configured, then EDAC will never
787	notice the UE.
788
789	LOAD TIME::
790
791		module/kernel parameter: edac_mc_panic_on_ue=[0|1]
792
793	RUN TIME::
794
795		echo "1" > /sys/module/edac_core/parameters/edac_mc_panic_on_ue
796
797
798- ``edac_mc_log_ue`` - Log UE control file
799
800
801	Generate kernel messages describing uncorrectable errors.  These errors
802	are reported through the system message log system.  UE statistics
803	will be accumulated even when UE logging is disabled.
804
805	LOAD TIME::
806
807		module/kernel parameter: edac_mc_log_ue=[0|1]
808
809	RUN TIME::
810
811		echo "1" > /sys/module/edac_core/parameters/edac_mc_log_ue
812
813
814- ``edac_mc_log_ce`` - Log CE control file
815
816
817	Generate kernel messages describing correctable errors.  These
818	errors are reported through the system message log system.
819	CE statistics will be accumulated even when CE logging is disabled.
820
821	LOAD TIME::
822
823		module/kernel parameter: edac_mc_log_ce=[0|1]
824
825	RUN TIME::
826
827		echo "1" > /sys/module/edac_core/parameters/edac_mc_log_ce
828
829
830- ``edac_mc_poll_msec`` - Polling period control file
831
832
833	The time period, in milliseconds, for polling for error information.
834	Too small a value wastes resources.  Too large a value might delay
835	necessary handling of errors and might loose valuable information for
836	locating the error.  1000 milliseconds (once each second) is the current
837	default. Systems which require all the bandwidth they can get, may
838	increase this.
839
840	LOAD TIME::
841
842		module/kernel parameter: edac_mc_poll_msec=[0|1]
843
844	RUN TIME::
845
846		echo "1000" > /sys/module/edac_core/parameters/edac_mc_poll_msec
847
848
849- ``panic_on_pci_parity`` - Panic on PCI PARITY Error
850
851
852	This control file enables or disables panicking when a parity
853	error has been detected.
854
855
856	module/kernel parameter::
857
858			edac_panic_on_pci_pe=[0|1]
859
860	Enable::
861
862		echo "1" > /sys/module/edac_core/parameters/edac_panic_on_pci_pe
863
864	Disable::
865
866		echo "0" > /sys/module/edac_core/parameters/edac_panic_on_pci_pe
867
868
869
870EDAC device type
871----------------
872
873In the header file, edac_pci.h, there is a series of edac_device structures
874and APIs for the EDAC_DEVICE.
875
876User space access to an edac_device is through the sysfs interface.
877
878At the location ``/sys/devices/system/edac`` (sysfs) new edac_device devices
879will appear.
880
881There is a three level tree beneath the above ``edac`` directory. For example,
882the ``test_device_edac`` device (found at the http://bluesmoke.sourceforget.net
883website) installs itself as::
884
885	/sys/devices/system/edac/test-instance
886
887in this directory are various controls, a symlink and one or more ``instance``
888directories.
889
890The standard default controls are:
891
892	==============	=======================================================
893	log_ce		boolean to log CE events
894	log_ue		boolean to log UE events
895	panic_on_ue	boolean to ``panic`` the system if an UE is encountered
896			(default off, can be set true via startup script)
897	poll_msec	time period between POLL cycles for events
898	==============	=======================================================
899
900The test_device_edac device adds at least one of its own custom control:
901
902	==============	==================================================
903	test_bits	which in the current test driver does nothing but
904			show how it is installed. A ported driver can
905			add one or more such controls and/or attributes
906			for specific uses.
907			One out-of-tree driver uses controls here to allow
908			for ERROR INJECTION operations to hardware
909			injection registers
910	==============	==================================================
911
912The symlink points to the 'struct dev' that is registered for this edac_device.
913
914Instances
915---------
916
917One or more instance directories are present. For the ``test_device_edac``
918case:
919
920	+----------------+
921	| test-instance0 |
922	+----------------+
923
924
925In this directory there are two default counter attributes, which are totals of
926counter in deeper subdirectories.
927
928	==============	====================================
929	ce_count	total of CE events of subdirectories
930	ue_count	total of UE events of subdirectories
931	==============	====================================
932
933Blocks
934------
935
936At the lowest directory level is the ``block`` directory. There can be 0, 1
937or more blocks specified in each instance:
938
939	+-------------+
940	| test-block0 |
941	+-------------+
942
943In this directory the default attributes are:
944
945	==============	================================================
946	ce_count	which is counter of CE events for this ``block``
947			of hardware being monitored
948	ue_count	which is counter of UE events for this ``block``
949			of hardware being monitored
950	==============	================================================
951
952
953The ``test_device_edac`` device adds 4 attributes and 1 control:
954
955	================== ====================================================
956	test-block-bits-0	for every POLL cycle this counter
957				is incremented
958	test-block-bits-1	every 10 cycles, this counter is bumped once,
959				and test-block-bits-0 is set to 0
960	test-block-bits-2	every 100 cycles, this counter is bumped once,
961				and test-block-bits-1 is set to 0
962	test-block-bits-3	every 1000 cycles, this counter is bumped once,
963				and test-block-bits-2 is set to 0
964	================== ====================================================
965
966
967	================== ====================================================
968	reset-counters		writing ANY thing to this control will
969				reset all the above counters.
970	================== ====================================================
971
972
973Use of the ``test_device_edac`` driver should enable any others to create their own
974unique drivers for their hardware systems.
975
976The ``test_device_edac`` sample driver is located at the
977http://bluesmoke.sourceforge.net project site for EDAC.
978
979
980Usage of EDAC APIs on Nehalem and newer Intel CPUs
981--------------------------------------------------
982
983On older Intel architectures, the memory controller was part of the North
984Bridge chipset. Nehalem, Sandy Bridge, Ivy Bridge, Haswell, Sky Lake and
985newer Intel architectures integrated an enhanced version of the memory
986controller (MC) inside the CPUs.
987
988This chapter will cover the differences of the enhanced memory controllers
989found on newer Intel CPUs, such as ``i7core_edac``, ``sb_edac`` and
990``sbx_edac`` drivers.
991
992.. note::
993
994   The Xeon E7 processor families use a separate chip for the memory
995   controller, called Intel Scalable Memory Buffer. This section doesn't
996   apply for such families.
997
9981) There is one Memory Controller per Quick Patch Interconnect
999   (QPI). At the driver, the term "socket" means one QPI. This is
1000   associated with a physical CPU socket.
1001
1002   Each MC have 3 physical read channels, 3 physical write channels and
1003   3 logic channels. The driver currently sees it as just 3 channels.
1004   Each channel can have up to 3 DIMMs.
1005
1006   The minimum known unity is DIMMs. There are no information about csrows.
1007   As EDAC API maps the minimum unity is csrows, the driver sequentially
1008   maps channel/DIMM into different csrows.
1009
1010   For example, supposing the following layout::
1011
1012	Ch0 phy rd0, wr0 (0x063f4031): 2 ranks, UDIMMs
1013	  dimm 0 1024 Mb offset: 0, bank: 8, rank: 1, row: 0x4000, col: 0x400
1014	  dimm 1 1024 Mb offset: 4, bank: 8, rank: 1, row: 0x4000, col: 0x400
1015        Ch1 phy rd1, wr1 (0x063f4031): 2 ranks, UDIMMs
1016	  dimm 0 1024 Mb offset: 0, bank: 8, rank: 1, row: 0x4000, col: 0x400
1017	Ch2 phy rd3, wr3 (0x063f4031): 2 ranks, UDIMMs
1018	  dimm 0 1024 Mb offset: 0, bank: 8, rank: 1, row: 0x4000, col: 0x400
1019
1020   The driver will map it as::
1021
1022	csrow0: channel 0, dimm0
1023	csrow1: channel 0, dimm1
1024	csrow2: channel 1, dimm0
1025	csrow3: channel 2, dimm0
1026
1027   exports one DIMM per csrow.
1028
1029   Each QPI is exported as a different memory controller.
1030
10312) The MC has the ability to inject errors to test drivers. The drivers
1032   implement this functionality via some error injection nodes:
1033
1034   For injecting a memory error, there are some sysfs nodes, under
1035   ``/sys/devices/system/edac/mc/mc?/``:
1036
1037   - ``inject_addrmatch/*``:
1038      Controls the error injection mask register. It is possible to specify
1039      several characteristics of the address to match an error code::
1040
1041         dimm = the affected dimm. Numbers are relative to a channel;
1042         rank = the memory rank;
1043         channel = the channel that will generate an error;
1044         bank = the affected bank;
1045         page = the page address;
1046         column (or col) = the address column.
1047
1048      each of the above values can be set to "any" to match any valid value.
1049
1050      At driver init, all values are set to any.
1051
1052      For example, to generate an error at rank 1 of dimm 2, for any channel,
1053      any bank, any page, any column::
1054
1055		echo 2 >/sys/devices/system/edac/mc/mc0/inject_addrmatch/dimm
1056		echo 1 >/sys/devices/system/edac/mc/mc0/inject_addrmatch/rank
1057
1058	To return to the default behaviour of matching any, you can do::
1059
1060		echo any >/sys/devices/system/edac/mc/mc0/inject_addrmatch/dimm
1061		echo any >/sys/devices/system/edac/mc/mc0/inject_addrmatch/rank
1062
1063   - ``inject_eccmask``:
1064          specifies what bits will have troubles,
1065
1066   - ``inject_section``:
1067       specifies what ECC cache section will get the error::
1068
1069		3 for both
1070		2 for the highest
1071		1 for the lowest
1072
1073   - ``inject_type``:
1074       specifies the type of error, being a combination of the following bits::
1075
1076		bit 0 - repeat
1077		bit 1 - ecc
1078		bit 2 - parity
1079
1080   - ``inject_enable``:
1081       starts the error generation when something different than 0 is written.
1082
1083   All inject vars can be read. root permission is needed for write.
1084
1085   Datasheet states that the error will only be generated after a write on an
1086   address that matches inject_addrmatch. It seems, however, that reading will
1087   also produce an error.
1088
1089   For example, the following code will generate an error for any write access
1090   at socket 0, on any DIMM/address on channel 2::
1091
1092	echo 2 >/sys/devices/system/edac/mc/mc0/inject_addrmatch/channel
1093	echo 2 >/sys/devices/system/edac/mc/mc0/inject_type
1094	echo 64 >/sys/devices/system/edac/mc/mc0/inject_eccmask
1095	echo 3 >/sys/devices/system/edac/mc/mc0/inject_section
1096	echo 1 >/sys/devices/system/edac/mc/mc0/inject_enable
1097	dd if=/dev/mem of=/dev/null seek=16k bs=4k count=1 >& /dev/null
1098
1099   For socket 1, it is needed to replace "mc0" by "mc1" at the above
1100   commands.
1101
1102   The generated error message will look like::
1103
1104	EDAC MC0: UE row 0, channel-a= 0 channel-b= 0 labels "-": NON_FATAL (addr = 0x0075b980, socket=0, Dimm=0, Channel=2, syndrome=0x00000040, count=1, Err=8c0000400001009f:4000080482 (read error: read ECC error))
1105
11063) Corrected Error memory register counters
1107
1108   Those newer MCs have some registers to count memory errors. The driver
1109   uses those registers to report Corrected Errors on devices with Registered
1110   DIMMs.
1111
1112   However, those counters don't work with Unregistered DIMM. As the chipset
1113   offers some counters that also work with UDIMMs (but with a worse level of
1114   granularity than the default ones), the driver exposes those registers for
1115   UDIMM memories.
1116
1117   They can be read by looking at the contents of ``all_channel_counts/``::
1118
1119     $ for i in /sys/devices/system/edac/mc/mc0/all_channel_counts/*; do echo $i; cat $i; done
1120	/sys/devices/system/edac/mc/mc0/all_channel_counts/udimm0
1121	0
1122	/sys/devices/system/edac/mc/mc0/all_channel_counts/udimm1
1123	0
1124	/sys/devices/system/edac/mc/mc0/all_channel_counts/udimm2
1125	0
1126
1127   What happens here is that errors on different csrows, but at the same
1128   dimm number will increment the same counter.
1129   So, in this memory mapping::
1130
1131	csrow0: channel 0, dimm0
1132	csrow1: channel 0, dimm1
1133	csrow2: channel 1, dimm0
1134	csrow3: channel 2, dimm0
1135
1136   The hardware will increment udimm0 for an error at the first dimm at either
1137   csrow0, csrow2  or csrow3;
1138
1139   The hardware will increment udimm1 for an error at the second dimm at either
1140   csrow0, csrow2  or csrow3;
1141
1142   The hardware will increment udimm2 for an error at the third dimm at either
1143   csrow0, csrow2  or csrow3;
1144
11454) Standard error counters
1146
1147   The standard error counters are generated when an mcelog error is received
1148   by the driver. Since, with UDIMM, this is counted by software, it is
1149   possible that some errors could be lost. With RDIMM's, they display the
1150   contents of the registers
1151
1152Reference documents used on ``amd64_edac``
1153------------------------------------------
1154
1155``amd64_edac`` module is based on the following documents
1156(available from http://support.amd.com/en-us/search/tech-docs):
1157
11581. :Title:  BIOS and Kernel Developer's Guide for AMD Athlon 64 and AMD
1159	   Opteron Processors
1160   :AMD publication #: 26094
1161   :Revision: 3.26
1162   :Link: http://support.amd.com/TechDocs/26094.PDF
1163
11642. :Title:  BIOS and Kernel Developer's Guide for AMD NPT Family 0Fh
1165	   Processors
1166   :AMD publication #: 32559
1167   :Revision: 3.00
1168   :Issue Date: May 2006
1169   :Link: http://support.amd.com/TechDocs/32559.pdf
1170
11713. :Title:  BIOS and Kernel Developer's Guide (BKDG) For AMD Family 10h
1172	   Processors
1173   :AMD publication #: 31116
1174   :Revision: 3.00
1175   :Issue Date: September 07, 2007
1176   :Link: http://support.amd.com/TechDocs/31116.pdf
1177
11784. :Title: BIOS and Kernel Developer's Guide (BKDG) for AMD Family 15h
1179	  Models 30h-3Fh Processors
1180   :AMD publication #: 49125
1181   :Revision: 3.06
1182   :Issue Date: 2/12/2015 (latest release)
1183   :Link: http://support.amd.com/TechDocs/49125_15h_Models_30h-3Fh_BKDG.pdf
1184
11855. :Title: BIOS and Kernel Developer's Guide (BKDG) for AMD Family 15h
1186	  Models 60h-6Fh Processors
1187   :AMD publication #: 50742
1188   :Revision: 3.01
1189   :Issue Date: 7/23/2015 (latest release)
1190   :Link: http://support.amd.com/TechDocs/50742_15h_Models_60h-6Fh_BKDG.pdf
1191
11926. :Title: BIOS and Kernel Developer's Guide (BKDG) for AMD Family 16h
1193	  Models 00h-0Fh Processors
1194   :AMD publication #: 48751
1195   :Revision: 3.03
1196   :Issue Date: 2/23/2015 (latest release)
1197   :Link: http://support.amd.com/TechDocs/48751_16h_bkdg.pdf
1198
1199Credits
1200=======
1201
1202* Written by Doug Thompson <dougthompson@xmission.com>
1203
1204  - 7 Dec 2005
1205  - 17 Jul 2007	Updated
1206
1207* |copy| Mauro Carvalho Chehab
1208
1209  - 05 Aug 2009	Nehalem interface
1210  - 26 Oct 2016 Converted to ReST and cleanups at the Nehalem section
1211
1212* EDAC authors/maintainers:
1213
1214  - Doug Thompson, Dave Jiang, Dave Peterson et al,
1215  - Mauro Carvalho Chehab
1216  - Borislav Petkov
1217  - original author: Thayne Harbaugh
1218