2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-01-13 05:04:45 +00:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Adaptec.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Adaptec vendor commands.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Contains vendor commands for Adaptec ACB-4000A and
|
|
|
|
|
// ACB-4070 ST-506 to SCSI controllers.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2016-01-13 05:04:45 +00:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2016-01-13 05:04:45 +00:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2016-01-13 05:04:45 +00:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2016-01-13 05:04:45 +00:00
|
|
|
using System;
|
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Devices
|
|
|
|
|
{
|
|
|
|
|
public partial class Device
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Gets the underlying drive cylinder, head and index bytes for the specified SCSI LBA.
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
2016-01-13 05:57:35 +00:00
|
|
|
/// <param name="lba">SCSI Logical Block Address.</param>
|
2016-01-13 05:04:45 +00:00
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2017-12-19 20:33:03 +00:00
|
|
|
public bool AdaptecTranslate(out byte[] buffer, out byte[] senseBuffer, uint lba, uint timeout,
|
|
|
|
|
out double duration)
|
2016-01-13 05:04:45 +00:00
|
|
|
{
|
|
|
|
|
return AdaptecTranslate(out buffer, out senseBuffer, false, lba, timeout, out duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Gets the underlying drive cylinder, head and index bytes for the specified SCSI LBA.
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="drive1">If set to <c>true</c> request the data from drive 1.</param>
|
2016-01-13 05:57:35 +00:00
|
|
|
/// <param name="lba">SCSI Logical Block Address.</param>
|
2016-01-13 05:04:45 +00:00
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2017-12-19 20:33:03 +00:00
|
|
|
public bool AdaptecTranslate(out byte[] buffer, out byte[] senseBuffer, bool drive1, uint lba, uint timeout,
|
|
|
|
|
out double duration)
|
2016-01-13 05:04:45 +00:00
|
|
|
{
|
|
|
|
|
buffer = new byte[8];
|
|
|
|
|
byte[] cdb = new byte[6];
|
|
|
|
|
senseBuffer = new byte[32];
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecTranslate;
|
2016-01-13 05:04:45 +00:00
|
|
|
cdb[1] = (byte)((lba & 0x1F0000) >> 16);
|
|
|
|
|
cdb[2] = (byte)((lba & 0xFF00) >> 8);
|
|
|
|
|
cdb[3] = (byte)(lba & 0xFF);
|
2017-12-19 20:33:03 +00:00
|
|
|
if(drive1) cdb[1] += 0x20;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2017-12-21 07:19:46 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
2017-12-22 03:13:43 +00:00
|
|
|
out bool sense);
|
2017-12-21 07:19:46 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC TRANSLATE took {0} ms.", duration);
|
|
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Sets the error threshold
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <returns><c>true</c>, if set error threshold was adapteced, <c>false</c> otherwise.</returns>
|
|
|
|
|
/// <param name="threshold">Threshold. 0 to disable error reporting.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
|
|
|
|
public bool AdaptecSetErrorThreshold(byte threshold, out byte[] senseBuffer, uint timeout, out double duration)
|
|
|
|
|
{
|
|
|
|
|
return AdaptecSetErrorThreshold(threshold, out senseBuffer, false, timeout, out duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Sets the error threshold
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <returns><c>true</c>, if set error threshold was adapteced, <c>false</c> otherwise.</returns>
|
|
|
|
|
/// <param name="threshold">Threshold. 0 to disable error reporting.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="drive1">If set to <c>true</c> set the threshold from drive 1.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2017-12-19 20:33:03 +00:00
|
|
|
public bool AdaptecSetErrorThreshold(byte threshold, out byte[] senseBuffer, bool drive1, uint timeout,
|
|
|
|
|
out double duration)
|
2016-01-13 05:04:45 +00:00
|
|
|
{
|
|
|
|
|
byte[] buffer = new byte[1];
|
|
|
|
|
buffer[0] = threshold;
|
|
|
|
|
byte[] cdb = new byte[6];
|
|
|
|
|
senseBuffer = new byte[32];
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecSetErrorThreshold;
|
2017-12-19 20:33:03 +00:00
|
|
|
if(drive1) cdb[1] += 0x20;
|
2016-01-13 05:04:45 +00:00
|
|
|
cdb[4] = 1;
|
|
|
|
|
|
2017-12-21 07:19:46 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
|
2017-12-22 03:13:43 +00:00
|
|
|
out bool sense);
|
2017-12-21 07:19:46 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC SET ERROR THRESHOLD took {0} ms.", duration);
|
|
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Requests the usage, seek and error counters, and resets them
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2017-12-19 20:33:03 +00:00
|
|
|
public bool AdaptecReadUsageCounter(out byte[] buffer, out byte[] senseBuffer, uint timeout,
|
|
|
|
|
out double duration)
|
2016-01-13 05:04:45 +00:00
|
|
|
{
|
|
|
|
|
return AdaptecReadUsageCounter(out buffer, out senseBuffer, false, timeout, out duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Requests the usage, seek and error counters, and resets them
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="drive1">If set to <c>true</c> get the counters from drive 1.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
2017-12-19 20:33:03 +00:00
|
|
|
public bool AdaptecReadUsageCounter(out byte[] buffer, out byte[] senseBuffer, bool drive1, uint timeout,
|
|
|
|
|
out double duration)
|
2016-01-13 05:04:45 +00:00
|
|
|
{
|
|
|
|
|
buffer = new byte[9];
|
|
|
|
|
byte[] cdb = new byte[6];
|
|
|
|
|
senseBuffer = new byte[32];
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecTranslate;
|
2017-12-19 20:33:03 +00:00
|
|
|
if(drive1) cdb[1] += 0x20;
|
2016-01-13 05:04:45 +00:00
|
|
|
cdb[4] = (byte)buffer.Length;
|
|
|
|
|
|
2017-12-21 07:19:46 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
2017-12-22 03:13:43 +00:00
|
|
|
out bool sense);
|
2017-12-21 07:19:46 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC READ/RESET USAGE COUNTER took {0} ms.", duration);
|
|
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Fills the Adaptec controller RAM with 1K bytes of data
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Data to fill the buffer with.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
|
|
|
|
public bool AdaptecWriteBuffer(byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
|
|
|
|
{
|
|
|
|
|
byte[] oneKBuffer = new byte[1024];
|
2017-12-22 03:13:43 +00:00
|
|
|
Array.Copy(buffer, 0, oneKBuffer, 0, buffer.Length < 1024 ? buffer.Length : 1024);
|
2016-01-13 05:04:45 +00:00
|
|
|
|
|
|
|
|
byte[] cdb = new byte[6];
|
|
|
|
|
senseBuffer = new byte[32];
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecWriteBuffer;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2017-12-21 07:19:46 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref oneKBuffer, out senseBuffer, timeout, ScsiDirection.Out, out duration,
|
2017-12-22 03:13:43 +00:00
|
|
|
out bool sense);
|
2017-12-21 07:19:46 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC WRITE DATA BUFFER took {0} ms.", duration);
|
|
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-23 20:04:36 +00:00
|
|
|
/// Reads 1K bytes of data from the Adaptec controller RAM
|
2016-01-13 05:04:45 +00:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Buffer.</param>
|
|
|
|
|
/// <param name="senseBuffer">Sense buffer.</param>
|
|
|
|
|
/// <param name="timeout">Timeout.</param>
|
|
|
|
|
/// <param name="duration">Duration.</param>
|
|
|
|
|
public bool AdaptecReadBuffer(out byte[] buffer, out byte[] senseBuffer, uint timeout, out double duration)
|
|
|
|
|
{
|
|
|
|
|
buffer = new byte[1024];
|
|
|
|
|
byte[] cdb = new byte[6];
|
|
|
|
|
senseBuffer = new byte[32];
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
cdb[0] = (byte)ScsiCommands.AdaptecReadBuffer;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
2017-12-21 07:19:46 +00:00
|
|
|
LastError = SendScsiCommand(cdb, ref buffer, out senseBuffer, timeout, ScsiDirection.In, out duration,
|
2017-12-22 03:13:43 +00:00
|
|
|
out bool sense);
|
2017-12-21 07:19:46 +00:00
|
|
|
Error = LastError != 0;
|
2016-01-13 05:04:45 +00:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("SCSI Device", "ADAPTEC READ DATA BUFFER took {0} ms.", duration);
|
|
|
|
|
|
|
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|