1050
1054
if (iop->cmnd[0] == 0x00)
1053
if (iop->cmnd[0] == 0xa1 || iop->cmnd[0] == 0x85) { // SAT_ATA_PASSTHROUGH_12/16
1057
if (iop->cmnd[0] == SAT_ATA_PASSTHROUGH_12 || iop->cmnd[0] == SAT_ATA_PASSTHROUGH_16) {
1054
1058
// Controller does not return ATA output registers in SAT sense data
1055
1059
if (iop->cmnd[2] & (1 << 5)) // chk_cond
1056
1060
return set_err(ENOSYS, "ATA return descriptor not supported by controller firmware");
1062
// SMART WRITE LOG SECTOR causing media errors
1063
if ((iop->cmnd[0] == SAT_ATA_PASSTHROUGH_16 && iop->cmnd[14] == ATA_SMART_CMD
1064
&& iop->cmnd[3]==0 && iop->cmnd[4] == ATA_SMART_WRITE_LOG_SECTOR) ||
1065
(iop->cmnd[0] == SAT_ATA_PASSTHROUGH_12 && iop->cmnd[9] == ATA_SMART_CMD &&
1066
iop->cmnd[3] == ATA_SMART_WRITE_LOG_SECTOR))
1067
return set_err(ENOSYS, "SMART WRITE LOG SECTOR command is not supported by controller firmware");
1059
1069
if (pt_cmd == NULL)
2041
2056
areca_packet[4] = (unsigned char)(((areca_packet_len - 6) >> 8) & 0xff);
2042
2057
areca_packet[5] = 0x1c; // areca defined code for ATA passthrough command
2045
2059
// ----- BEGIN TO SETUP PAYLOAD DATA -----
2047
2060
memcpy(&areca_packet[7], "SmrT", 4); // areca defined password
2049
2061
ata_cmd = (sATA_INPUT_REGISTERS *)&areca_packet[12];
2050
ata_cmd->cylinder_low = 0x4F;
2051
ata_cmd->cylinder_high = 0xC2;
2054
if ( command == READ_VALUES ||
2055
command == READ_THRESHOLDS ||
2056
command == READ_LOG ||
2057
command == IDENTIFY ||
2058
command == PIDENTIFY )
2065
const ata_in_regs_48bit & r = in.in_regs;
2066
ata_cmd->features = r.features_16;
2067
ata_cmd->sector_count = r.sector_count_16;
2068
ata_cmd->sector_number = r.lba_low_16;
2069
ata_cmd->cylinder_low = r.lba_mid_16;
2070
ata_cmd->cylinder_high = r.lba_high_16;
2071
ata_cmd->device_head = r.device;
2072
ata_cmd->command = r.command;
2074
bool readdata = false;
2075
if (in.direction == ata_cmd_in::data_in) {
2077
// the command will read data
2078
areca_packet[6] = 0x13;
2080
else if ( in.direction == ata_cmd_in::no_data )
2060
// the commands will return data
2061
areca_packet[6] = 0x13;
2062
ata_cmd->sector_count = 0x1;
2082
// the commands will return no data
2083
areca_packet[6] = 0x15;
2064
else if ( command == WRITE_LOG )
2085
else if (in.direction == ata_cmd_in::data_out)
2066
2087
// the commands will write data
2088
memcpy(ata_cmd->data, in.buffer, in.size);
2067
2089
areca_packet[6] = 0x14;
2071
// the commands will return no data
2072
areca_packet[6] = 0x15;
2092
// COMMAND NOT SUPPORTED VIA ARECA IOCTL INTERFACE
2093
return set_err(ENOTSUP, "DATA OUT not supported for this Areca controller type");
2076
ata_cmd->command = ATA_SMART_CMD;
2077
// Now set ATA registers depending upon command
2080
case CHECK_POWER_MODE:
2081
//printf("command = CHECK_POWER_MODE\n");
2082
ata_cmd->command = ATA_CHECK_POWER_MODE;
2085
//printf("command = READ_VALUES\n");
2086
ata_cmd->features = ATA_SMART_READ_VALUES;
2088
case READ_THRESHOLDS:
2089
//printf("command = READ_THRESHOLDS\n");
2090
ata_cmd->features = ATA_SMART_READ_THRESHOLDS;
2093
//printf("command = READ_LOG\n");
2094
ata_cmd->features = ATA_SMART_READ_LOG_SECTOR;
2095
ata_cmd->sector_number = select;
2098
//printf("command = WRITE_LOG\n");
2099
ata_cmd->features = ATA_SMART_WRITE_LOG_SECTOR;
2100
memcpy(ata_cmd->data, data, 512);
2101
ata_cmd->sector_count = 1;
2102
ata_cmd->sector_number = select;
2105
//printf("command = IDENTIFY\n");
2106
ata_cmd->command = ATA_IDENTIFY_DEVICE;
2109
//printf("command = PIDENTIFY\n");
2113
//printf("command = ENABLE\n");
2114
ata_cmd->features = ATA_SMART_ENABLE;
2117
//printf("command = DISABLE\n");
2118
ata_cmd->features = ATA_SMART_DISABLE;
2121
//printf("command = AUTO_OFFLINE\n");
2122
ata_cmd->features = ATA_SMART_AUTO_OFFLINE;
2123
// Enable or disable?
2124
ata_cmd->sector_count = select;
2127
//printf("command = AUTOSAVE\n");
2128
ata_cmd->features = ATA_SMART_AUTOSAVE;
2129
// Enable or disable?
2130
ata_cmd->sector_count = select;
2132
case IMMEDIATE_OFFLINE:
2133
//printf("command = IMMEDIATE_OFFLINE\n");
2134
ata_cmd->features = ATA_SMART_IMMEDIATE_OFFLINE;
2135
// What test type to run?
2136
ata_cmd->sector_number = select;
2139
//printf("command = STATUS_CHECK\n");
2140
ata_cmd->features = ATA_SMART_STATUS;
2143
//printf("command = STATUS\n");
2144
ata_cmd->features = ATA_SMART_STATUS;
2147
//printf("command = UNKNOWN\n");
2152
2096
areca_packet[11] = m_disknum - 1; // drive number
2154
2098
// ----- BEGIN TO SETUP CHECKSUM -----
2190
2134
if ( return_buff[expected - 1] != cs )
2136
return set_err(EIO);
2196
2139
sATA_OUTPUT_REGISTERS *ata_out = (sATA_OUTPUT_REGISTERS *)&return_buff[5] ;
2197
2140
if ( ata_out->status )
2199
if ( command == IDENTIFY )
2201
pout("The firmware of your Areca RAID controller appears to be outdated!\n" \
2202
"Please update your controller to firmware version 1.46 or later.\n" \
2203
"You may download it here: ftp://ftp.areca.com.tw/RaidCards/BIOS_Firmware\n\n");
2142
if ( in.in_regs.command == ATA_IDENTIFY_DEVICE
2143
&& !nonempty((unsigned char *)in.buffer, in.size))
2145
return set_err(ENODEV, "No drive on port %d", m_disknum);
2209
2149
// returns with data
2210
if ( command == READ_VALUES ||
2211
command == READ_THRESHOLDS ||
2212
command == READ_LOG ||
2213
command == IDENTIFY ||
2214
command == PIDENTIFY )
2216
memcpy(data, &return_buff[7], 512);
2219
if ( command == CHECK_POWER_MODE )
2221
data[0] = ata_out->sector_count;
2224
if ( command == STATUS_CHECK &&
2225
( ata_out->cylinder_low == 0xF4 && ata_out->cylinder_high == 0x2C ) )
2152
memcpy(in.buffer, &return_buff[7], in.size);
2155
// Return register values
2157
ata_out_regs_48bit & r = out.out_regs;
2158
r.error = ata_out->error;
2159
r.sector_count_16 = ata_out->sector_count;
2160
r.lba_low_16 = ata_out->sector_number;
2161
r.lba_mid_16 = ata_out->cylinder_low;
2162
r.lba_high_16 = ata_out->cylinder_high;
2163
r.status = ata_out->status;