Hardware/HDD/SSDSandforce.cs
author moel.mich
Tue, 14 Feb 2012 23:07:55 +0000
changeset 340 600962f8a298
parent 339 07a6126a4796
child 343 46b6b567f14f
permissions -rw-r--r--
Added a new sensor type "Factor" for dimensionless values (and similar) that are not to be shown as percent ("Level" type). Changed the write amplification sensor to use the new "Factor" sensor type. Added the temperature SMART attribute for Sandforce SSDs as hidden sensor (as it may show fake results on some hardware).
     1 /*
     2   
     3   Version: MPL 1.1/GPL 2.0/LGPL 2.1
     4 
     5   The contents of this file are subject to the Mozilla Public License Version
     6   1.1 (the "License"); you may not use this file except in compliance with
     7   the License. You may obtain a copy of the License at
     8  
     9   http://www.mozilla.org/MPL/
    10 
    11   Software distributed under the License is distributed on an "AS IS" basis,
    12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
    13   for the specific language governing rights and limitations under the License.
    14 
    15   The Original Code is the Open Hardware Monitor code.
    16 
    17   The Initial Developer of the Original Code is 
    18   Michael Möller <m.moeller@gmx.ch>.
    19   Portions created by the Initial Developer are Copyright (C) 2009-2012
    20   the Initial Developer. All Rights Reserved.
    21 
    22   Contributor(s):
    23     Paul Werelds
    24  
    25   Alternatively, the contents of this file may be used under the terms of
    26   either the GNU General Public License Version 2 or later (the "GPL"), or
    27   the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
    28   in which case the provisions of the GPL or the LGPL are applicable instead
    29   of those above. If you wish to allow use of your version of this file only
    30   under the terms of either the GPL or the LGPL, and not to allow others to
    31   use your version of this file under the terms of the MPL, indicate your
    32   decision by deleting the provisions above and replace them with the notice
    33   and other provisions required by the GPL or the LGPL. If you do not delete
    34   the provisions above, a recipient may use your version of this file under
    35   the terms of any one of the MPL, the GPL or the LGPL.
    36  
    37 */
    38 
    39 namespace OpenHardwareMonitor.Hardware.HDD {
    40   using System.Collections.Generic;
    41 
    42   [NamePrefix(""), RequireSmart(0xAB), RequireSmart(0xB1)]
    43   internal class SSDSandforce : AbstractHarddrive {
    44 
    45     private static readonly IEnumerable<SmartAttribute> smartAttributes =
    46       new List<SmartAttribute> {
    47       new SmartAttribute(0x01, SmartNames.RawReadErrorRate),
    48       new SmartAttribute(0x05, SmartNames.RetiredBlockCount, RawToInt),
    49       new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt),
    50       new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt),
    51       new SmartAttribute(0xAB, SmartNames.ProgramFailCount, RawToInt),
    52       new SmartAttribute(0xAC, SmartNames.EraseFailCount, RawToInt),
    53       new SmartAttribute(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt),
    54       new SmartAttribute(0xB1, SmartNames.WearRangeDelta, RawToInt),
    55       new SmartAttribute(0xB5, SmartNames.AlternativeProgramFailCount, RawToInt),
    56       new SmartAttribute(0xB6, SmartNames.AlternativeEraseFailCount, RawToInt),
    57       new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt),
    58       new SmartAttribute(0xC2, SmartNames.Temperature, (byte[] raw, byte value) 
    59         => { return value; }, SensorType.Temperature, 0, true), 
    60       new SmartAttribute(0xC3, SmartNames.UnrecoverableEcc), 
    61       new SmartAttribute(0xC4, SmartNames.ReallocationEventCount, RawToInt),
    62       new SmartAttribute(0xE7, SmartNames.RemainingLife, null, 
    63         SensorType.Level, 0),
    64       new SmartAttribute(0xE9, SmartNames.ControllerWritesToNAND, RawToInt,
    65         SensorType.Data, 0),
    66       new SmartAttribute(0xEA, SmartNames.HostWritesToController, RawToInt, 
    67         SensorType.Data, 1),
    68       new SmartAttribute(0xF1, SmartNames.HostWrites, RawToInt, 
    69         SensorType.Data, 1),
    70       new SmartAttribute(0xF2, SmartNames.HostReads, RawToInt, 
    71         SensorType.Data, 2)
    72     };
    73 
    74     private Sensor writeAmplification;
    75 
    76     public SSDSandforce(ISmart smart, string name, string firmwareRevision, 
    77       int index, ISettings settings) 
    78       : base(smart, name, firmwareRevision,  index, smartAttributes, settings) 
    79     {
    80       this.writeAmplification = new Sensor("Write Amplification", 1, 
    81         SensorType.Factor, this, settings);    
    82     }
    83 
    84     public override void UpdateAdditionalSensors(DriveAttributeValue[] values) {
    85       float? controllerWritesToNAND = null;
    86       float? hostWritesToController = null;
    87       foreach (DriveAttributeValue value in values) {
    88         if (value.Identifier == 0xE9)
    89           controllerWritesToNAND = RawToInt(value.RawValue, value.AttrValue);
    90 
    91         if (value.Identifier == 0xEA)
    92           hostWritesToController = RawToInt(value.RawValue, value.AttrValue);
    93       }
    94       if (controllerWritesToNAND.HasValue && hostWritesToController.HasValue) {
    95         writeAmplification.Value = 
    96           controllerWritesToNAND.Value / hostWritesToController.Value;
    97         ActivateSensor(writeAmplification);
    98       }
    99     }
   100   }
   101 }