1 /* 2 * Copyright 2009, Michael Lotz, mmlr@mlotz.ch. 3 * Copyright 2008, Marcus Overhagen. 4 * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. 5 * Copyright 2002-2003, Thomas Kurschel. 6 * 7 * Distributed under the terms of the MIT License. 8 */ 9 10 #include "ATAPrivate.h" 11 12 13 ATADevice::ATADevice(ATAChannel *channel, uint8 index) 14 : fChannel(channel), 15 fRegisterMask(0), 16 fUseDMA(channel->UseDMA()), 17 fDMAMode(0), 18 fDMAFailures(0), 19 fIndex(index), 20 fUseLBA(false), 21 fUse48Bits(false), 22 fTotalSectors(0) 23 { 24 memset(&fInfoBlock, 0, sizeof(fInfoBlock)); 25 memset(&fTaskFile, 0, sizeof(fTaskFile)); 26 } 27 28 29 ATADevice::~ATADevice() 30 { 31 } 32 33 34 status_t 35 ATADevice::TestUnitReady(ATARequest *request) 36 { 37 TRACE_FUNCTION("%p\n", request); 38 39 fRegisterMask = 0; 40 fTaskFile.write.command = ATA_COMMAND_GET_MEDIA_STATUS; 41 42 request->SetTimeout(15 * 1000 * 1000); 43 status_t result = fChannel->SendRequest(request, ATA_DEVICE_READY_REQUIRED); 44 if (result != B_OK) { 45 TRACE_ERROR("failed to send test unit ready request\n"); 46 return result; 47 } 48 49 return fChannel->FinishRequest(request, ATA_WAIT_FINISH 50 | ATA_DEVICE_READY_REQUIRED, ATA_ERROR_NO_MEDIA | ATA_ERROR_ABORTED 51 | ATA_ERROR_MEDIA_CHANGE_REQUESTED | ATA_ERROR_MEDIUM_CHANGED); 52 } 53 54 55 status_t 56 ATADevice::SynchronizeCache(ATARequest *request) 57 { 58 TRACE_FUNCTION("%p\n", request); 59 60 // we should also ask for FLUSH CACHE support, but everyone denies it 61 // (looks like they cheat to gain some performance advantage, but 62 // that's pretty useless: everyone does it...) 63 if (!fInfoBlock.write_cache_supported) 64 return B_OK; 65 66 fRegisterMask = 0; 67 fTaskFile.lba.command = fUse48Bits ? ATA_COMMAND_FLUSH_CACHE_EXT 68 : ATA_COMMAND_FLUSH_CACHE; 69 70 request->SetTimeout(60 * 1000 * 1000); 71 status_t result = fChannel->SendRequest(request, ATA_DEVICE_READY_REQUIRED); 72 if (result != B_OK) { 73 TRACE_ERROR("failed to send synchronize cache request\n"); 74 return result; 75 } 76 77 return fChannel->FinishRequest(request, ATA_WAIT_FINISH 78 | ATA_DEVICE_READY_REQUIRED, ATA_ERROR_ABORTED); 79 } 80 81 82 status_t 83 ATADevice::Eject(ATARequest *request) 84 { 85 TRACE_FUNCTION("%p\n", request); 86 87 fRegisterMask = 0; 88 fTaskFile.lba.command = ATA_COMMAND_MEDIA_EJECT; 89 90 request->SetTimeout(15 * 1000 * 1000); 91 status_t result = fChannel->SendRequest(request, ATA_DEVICE_READY_REQUIRED); 92 if (result != B_OK) { 93 TRACE_ERROR("failed to send eject request\n"); 94 return result; 95 } 96 97 return fChannel->FinishRequest(request, ATA_WAIT_FINISH 98 | ATA_DEVICE_READY_REQUIRED, ATA_ERROR_ABORTED | ATA_ERROR_NO_MEDIA); 99 } 100 101 102 status_t 103 ATADevice::Inquiry(ATARequest *request) 104 { 105 TRACE_FUNCTION("%p\n", request); 106 107 scsi_ccb *ccb = request->CCB(); 108 scsi_cmd_inquiry *command = (scsi_cmd_inquiry *)ccb->cdb; 109 if (command->evpd || command->page_code) { 110 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, SCSIS_ASC_INV_CDB_FIELD); 111 return B_ERROR; 112 } 113 114 scsi_res_inquiry data; 115 memset(&data, 0, sizeof(data)); 116 117 data.device_type = scsi_dev_direct_access; 118 data.device_qualifier = scsi_periph_qual_connected; 119 120 data.device_type_modifier = 0; 121 data.removable_medium = false; 122 123 data.ansi_version = 2; 124 data.ecma_version = 0; 125 data.iso_version = 0; 126 127 data.response_data_format = 2; 128 data.term_iop = false; 129 // to be changed if we support TERM I/O 130 131 data.additional_length = sizeof(scsi_res_inquiry) - 4; 132 133 data.soft_reset = false; 134 data.cmd_queue = 0; 135 data.linked = false; 136 137 // these values are free-style 138 data.sync = false; 139 data.write_bus16 = true; 140 data.write_bus32 = false; 141 142 data.relative_address = false; 143 144 // the following fields are *much* to small, sigh... 145 memcpy(data.vendor_ident, fInfoBlock.model_number, 146 sizeof(data.vendor_ident)); 147 memcpy(data.product_ident, fInfoBlock.model_number + 8, 148 sizeof(data.product_ident)); 149 memcpy(data.product_rev, " ", sizeof(data.product_rev)); 150 151 uint32 allocationLength = command->allocation_length; 152 copy_sg_data(ccb, 0, allocationLength, &data, sizeof(data), false); 153 ccb->data_resid = ccb->data_length - MIN(MIN(sizeof(data), 154 allocationLength), ccb->data_length); 155 return B_OK; 156 } 157 158 159 status_t 160 ATADevice::ReadCapacity(ATARequest *request) 161 { 162 TRACE_FUNCTION("%p\n", request); 163 164 scsi_ccb *ccb = request->CCB(); 165 scsi_cmd_read_capacity *command = (scsi_cmd_read_capacity *)ccb->cdb; 166 if (command->pmi || command->lba) { 167 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, SCSIS_ASC_INV_CDB_FIELD); 168 return B_ERROR; 169 } 170 171 scsi_res_read_capacity data; 172 data.block_size = B_HOST_TO_BENDIAN_INT32(ATA_BLOCK_SIZE); 173 174 uint32 lastBlock = fTotalSectors - 1; 175 data.lba = B_HOST_TO_BENDIAN_INT32(lastBlock); 176 TRACE("returning last block: %lu\n", B_BENDIAN_TO_HOST_INT32(data.lba)); 177 178 copy_sg_data(ccb, 0, ccb->data_length, &data, sizeof(data), false); 179 ccb->data_resid = MAX(ccb->data_length - sizeof(data), 0); 180 return B_OK; 181 } 182 183 184 status_t 185 ATADevice::ExecuteIO(ATARequest *request) 186 { 187 TRACE_FUNCTION("%p\n", request); 188 189 scsi_ccb *ccb = request->CCB(); 190 request->SetDevice(this); 191 192 // ATA devices have one LUN only 193 if (ccb->target_lun != 0) { 194 TRACE_ERROR("invalid target lun %d for ATA device\n", ccb->target_lun); 195 request->SetStatus(SCSI_SEL_TIMEOUT); 196 return B_BAD_INDEX; 197 } 198 199 TRACE("request: 0x%02x\n", ccb->cdb[0]); 200 201 switch (ccb->cdb[0]) { 202 case SCSI_OP_TEST_UNIT_READY: 203 return TestUnitReady(request); 204 205 case SCSI_OP_FORMAT: /* FORMAT UNIT */ 206 // we could forward ccb to disk, but modern disks cannot 207 // be formatted anyway, so we just refuse ccb 208 // (exceptions are removable media devices, but to my knowledge 209 // they don't have to be formatted as well) 210 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, SCSIS_ASC_INV_OPCODE); 211 return B_ERROR; 212 213 case SCSI_OP_INQUIRY: 214 return Inquiry(request); 215 216 case SCSI_OP_START_STOP: 217 { 218 scsi_cmd_ssu *command = (scsi_cmd_ssu *)ccb->cdb; 219 220 // with no LoEj bit set, we should only allow/deny further access 221 // we ignore that (unsupported for ATA) 222 // with LoEj bit set, we should additionally either load or eject 223 // the medium (start = 0 - eject; start = 1 - load) 224 225 if (!command->start) { 226 // we must always flush cache if start = 0 227 SynchronizeCache(request); 228 } 229 230 if (command->load_eject) { 231 if (!command->start) 232 return Eject(request); 233 else { 234 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, 235 SCSIS_ASC_PARAM_NOT_SUPPORTED); 236 return B_ERROR; 237 } 238 } 239 240 return B_OK; 241 } 242 243 case SCSI_OP_READ_CAPACITY: 244 return ReadCapacity(request); 245 246 case SCSI_OP_SYNCHRONIZE_CACHE: 247 // we ignore range and immediate bit, we always immediately 248 // flush everything 249 return SynchronizeCache(request); 250 251 // sadly, there are two possible read/write operation codes; 252 // at least, the third one, read/write(12), is not valid for DAS 253 case SCSI_OP_READ_6: 254 case SCSI_OP_WRITE_6: 255 { 256 scsi_cmd_rw_6 *command = (scsi_cmd_rw_6 *)ccb->cdb; 257 uint32 address = ((uint32)command->high_lba << 16) 258 | ((uint32)command->mid_lba << 8) | (uint32)command->low_lba; 259 260 request->SetIsWrite(command->opcode == SCSI_OP_WRITE_6); 261 return ExecuteReadWrite(request, address, command->length != 0 262 ? command->length : 256); 263 } 264 265 case SCSI_OP_READ_10: 266 case SCSI_OP_WRITE_10: 267 { 268 scsi_cmd_rw_10 *command = (scsi_cmd_rw_10 *)ccb->cdb; 269 uint32 address = B_BENDIAN_TO_HOST_INT32(command->lba); 270 uint32 sectorCount = B_BENDIAN_TO_HOST_INT16(command->length); 271 272 request->SetIsWrite(command->opcode == SCSI_OP_WRITE_10); 273 if (sectorCount > 0) 274 return ExecuteReadWrite(request, address, sectorCount); 275 else { 276 // we cannot transfer zero blocks (apart from LBA48) 277 request->SetStatus(SCSI_REQ_CMP); 278 return B_OK; 279 } 280 } 281 } 282 283 TRACE("command not implemented\n"); 284 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, SCSIS_ASC_INV_OPCODE); 285 return B_ERROR; 286 } 287 288 289 status_t 290 ATADevice::Select() 291 { 292 return fChannel->SelectDevice(fIndex); 293 } 294 295 296 status_t 297 ATADevice::SetFeature(int feature) 298 { 299 TRACE("device_set_feature: feature %d\n", feature); 300 301 ATARequest request(false); 302 request.SetDevice(this); 303 request.SetTimeout(1 * 1000 * 1000); 304 305 fTaskFile.write.features = feature; 306 fTaskFile.write.command = ATA_COMMAND_SET_FEATURES; 307 fRegisterMask = ATA_MASK_FEATURES; 308 309 status_t result = fChannel->SendRequest(&request, 310 ATA_DEVICE_READY_REQUIRED); 311 if (result != B_OK) { 312 TRACE_ERROR("sending set feature request failed\n"); 313 return result; 314 } 315 316 result = fChannel->FinishRequest(&request, ATA_WAIT_FINISH 317 | ATA_DEVICE_READY_REQUIRED, ATA_ERROR_ABORTED); 318 if (result != B_OK) { 319 TRACE_ERROR("set feature request failed\n"); 320 return result; 321 } 322 323 return B_OK; 324 } 325 326 327 status_t 328 ATADevice::DisableCommandQueueing() 329 { 330 if (!fInfoBlock.DMA_QUEUED_supported) 331 return B_OK; 332 333 if (fInfoBlock.RELEASE_irq_supported) { 334 status_t result = SetFeature( 335 ATA_COMMAND_SET_FEATURES_DISABLE_RELEASE_INT); 336 if (result != B_OK) { 337 TRACE_ERROR("failed to disable release interrupt\n"); 338 return result; 339 } 340 } 341 342 if (fInfoBlock.SERVICE_irq_supported) { 343 status_t result = SetFeature( 344 ATA_COMMAND_SET_FEATURES_DISABLE_SERVICE_INT); 345 if (result != B_OK) { 346 TRACE_ERROR("failed to disable service interrupt\n"); 347 return result; 348 } 349 } 350 351 return B_OK; 352 } 353 354 355 status_t 356 ATADevice::ConfigureDMA() 357 { 358 if (!fUseDMA) 359 return B_OK; 360 361 if (!fInfoBlock.DMA_supported) { 362 TRACE_ALWAYS("DMA not supported by device\n"); 363 fUseDMA = false; 364 return B_OK; 365 } 366 367 #define CHECK_DMA_MODE(element, mode) \ 368 if (fInfoBlock.element) { \ 369 fDMAMode = mode; \ 370 modeCount++; \ 371 } 372 373 uint32 modeCount = 0; 374 375 CHECK_DMA_MODE(MDMA0_selected, 0x00); 376 CHECK_DMA_MODE(MDMA1_selected, 0x01); 377 CHECK_DMA_MODE(MDMA2_selected, 0x02); 378 379 if (fInfoBlock._88_valid) { 380 CHECK_DMA_MODE(UDMA0_selected, 0x10); 381 CHECK_DMA_MODE(UDMA1_selected, 0x11); 382 CHECK_DMA_MODE(UDMA2_selected, 0x12); 383 CHECK_DMA_MODE(UDMA3_selected, 0x13); 384 CHECK_DMA_MODE(UDMA4_selected, 0x14); 385 CHECK_DMA_MODE(UDMA5_selected, 0x15); 386 CHECK_DMA_MODE(UDMA6_selected, 0x16); 387 } 388 389 #undef CHECK_DMA_MODE 390 391 if (modeCount != 1) { 392 TRACE_ERROR("more than on DMA mode selected, not using DMA\n"); 393 fUseDMA = false; 394 return B_OK; 395 } 396 397 TRACE_ALWAYS("using DMA mode 0x%02x\n", fDMAMode); 398 return B_OK; 399 } 400 401 402 status_t 403 ATADevice::Configure() 404 { 405 // warning: ata == 0 means "this is ata"... 406 if (fInfoBlock._0.ata.ATA != 0) { 407 // CF has either magic header or CFA bit set 408 // we merge it to "CFA bit set" for easier (later) testing 409 if (*(uint16 *)&fInfoBlock == 0x848a) 410 fInfoBlock.CFA_supported = true; 411 else 412 return B_ERROR; 413 } 414 415 if (!fInfoBlock._54_58_valid) { 416 // normally, current_xxx contains active CHS mapping, 417 // but if BIOS didn't call INITIALIZE DEVICE PARAMETERS 418 // the default mapping is used 419 fInfoBlock.current_sectors = fInfoBlock.sectors; 420 fInfoBlock.current_cylinders = fInfoBlock.cylinders; 421 fInfoBlock.current_heads = fInfoBlock.heads; 422 } 423 424 // just in case capacity_xxx isn't initialized - calculate it manually 425 // (seems that this information is really redundant; hopefully) 426 uint32 chsCapacity = fInfoBlock.current_sectors 427 * fInfoBlock.current_cylinders * fInfoBlock.current_heads; 428 429 fInfoBlock.capacity_low = chsCapacity & 0xff; 430 fInfoBlock.capacity_high = chsCapacity >> 8; 431 432 // checking LBA_supported flag should be sufficient, but it seems 433 // that checking LBA_total_sectors is a good idea 434 fUseLBA = fInfoBlock.LBA_supported && fInfoBlock.LBA_total_sectors != 0; 435 436 if (fUseLBA) { 437 fTotalSectors = fInfoBlock.LBA_total_sectors; 438 fTaskFile.lba.mode = ATA_MODE_LBA; 439 fTaskFile.lba.device = fIndex; 440 } else { 441 fTotalSectors = chsCapacity; 442 fTaskFile.chs.mode = ATA_MODE_CHS; 443 fTaskFile.chs.device = fIndex; 444 } 445 446 fUse48Bits = fInfoBlock._48_bit_addresses_supported; 447 if (fUse48Bits) 448 fTotalSectors = fInfoBlock.LBA48_total_sectors; 449 450 status_t result = ConfigureDMA(); 451 if (result != B_OK) 452 return result; 453 454 result = DisableCommandQueueing(); 455 if (result != B_OK) 456 return result; 457 458 return B_OK; 459 } 460 461 462 status_t 463 ATADevice::Identify() 464 { 465 snprintf(fDebugContext, sizeof(fDebugContext), "%s %lu-%u", 466 IsATAPI() ? "pi" : "", fChannel->ChannelID(), fIndex); 467 468 ATARequest request(false); 469 request.SetDevice(this); 470 request.SetTimeout(20 * 1000 * 1000); 471 472 fRegisterMask = 0; 473 fTaskFile.write.command = IsATAPI() ? ATA_COMMAND_IDENTIFY_PACKET_DEVICE 474 : ATA_COMMAND_IDENTIFY_DEVICE; 475 476 if (fChannel->SendRequest(&request, IsATAPI() ? 0 477 : ATA_DEVICE_READY_REQUIRED) != B_OK) { 478 TRACE_ERROR("sending identify request failed\n"); 479 return B_ERROR; 480 } 481 482 if (fChannel->Wait(ATA_STATUS_BUSY | ATA_STATUS_DATA_REQUEST, 0, 483 ATA_WAIT_ANY_BIT, 100 * 1000) != B_OK) { 484 TRACE_ALWAYS("no data request and not busy within 100ms, assuming " 485 "no device present\n"); 486 return B_TIMED_OUT; 487 } 488 489 if (fChannel->Wait(ATA_STATUS_DATA_REQUEST, ATA_STATUS_BUSY, 490 ATA_CHECK_ERROR_BIT | ATA_CHECK_DEVICE_FAULT, IsATAPI() 491 ? 20 * 1000 * 1000 : 500 * 1000) != B_OK) { 492 TRACE_ERROR("timeout waiting for identify request\n"); 493 return B_TIMED_OUT; 494 } 495 496 // get the infoblock 497 fChannel->ReadPIO((uint8 *)&fInfoBlock, sizeof(fInfoBlock)); 498 499 if (fChannel->WaitDataRequest(false) != B_OK) { 500 TRACE_ERROR("device disagrees on info block length\n"); 501 return B_ERROR; 502 } 503 504 if (fChannel->FinishRequest(&request, ATA_WAIT_FINISH | (IsATAPI() ? 0 505 : ATA_DEVICE_READY_REQUIRED), ATA_ERROR_ABORTED) != B_OK) { 506 TRACE_ERROR("failed to finish identify request\n"); 507 return B_ERROR; 508 } 509 510 return B_OK; 511 } 512 513 514 status_t 515 ATADevice::ExecuteReadWrite(ATARequest *request, uint64 address, 516 uint32 sectorCount) 517 { 518 request->SetUseDMA(fUseDMA && fChannel->PrepareDMA(request) == B_OK); 519 if (!request->UseDMA()) 520 request->PrepareSGInfo(); 521 522 request->SetBytesLeft(sectorCount * ATA_BLOCK_SIZE); 523 if (_FillTaskFile(request, address) != B_OK) { 524 TRACE_ERROR("failed to setup transfer request\n"); 525 if (request->UseDMA()) 526 fChannel->FinishDMA(); 527 return B_ERROR; 528 } 529 530 status_t result = fChannel->SendRequest(request, IsATAPI() 531 ? 0 : ATA_DEVICE_READY_REQUIRED); 532 if (result != B_OK) { 533 TRACE_ERROR("failed to send transfer request\n"); 534 if (request->UseDMA()) 535 fChannel->FinishDMA(); 536 return result; 537 } 538 539 if (fChannel->Wait(ATA_STATUS_DATA_REQUEST, 0, ATA_CHECK_ERROR_BIT 540 | ATA_CHECK_DEVICE_FAULT, request->Timeout()) != B_OK) { 541 TRACE_ERROR("timeout waiting for device to request data\n"); 542 request->SetStatus(SCSI_CMD_TIMEOUT); 543 return B_TIMED_OUT; 544 } 545 546 if (request->UseDMA()) { 547 fChannel->PrepareWaitingForInterrupt(); 548 fChannel->StartDMA(); 549 550 result = fChannel->WaitForInterrupt(request->Timeout()); 551 status_t dmaResult = fChannel->FinishDMA(); 552 if (result == B_OK && dmaResult == B_OK) { 553 fDMAFailures = 0; 554 request->CCB()->data_resid = 0; 555 } else { 556 if (dmaResult != B_OK) { 557 request->SetSense(SCSIS_KEY_HARDWARE_ERROR, 558 SCSIS_ASC_LUN_COM_FAILURE); 559 fDMAFailures++; 560 if (fDMAFailures >= ATA_MAX_DMA_FAILURES) { 561 TRACE_ALWAYS("disabling DMA after %u failures\n", 562 fDMAFailures); 563 fUseDMA = false; 564 } 565 } else { 566 // timeout 567 request->SetStatus(SCSI_CMD_TIMEOUT); 568 } 569 } 570 } else { 571 if (fChannel->ExecutePIOTransfer(request) != B_OK) { 572 TRACE_ERROR("executing pio transfer failed\n"); 573 request->SetStatus(SCSI_SEQUENCE_FAIL); 574 } 575 } 576 577 return fChannel->FinishRequest(request, ATA_WAIT_FINISH 578 | ATA_DEVICE_READY_REQUIRED, ATA_ERROR_ALL); 579 } 580 581 582 status_t 583 ATADevice::_FillTaskFile(ATARequest *request, uint64 address) 584 { 585 // list of LBA48 opcodes 586 static const uint8 s48BitCommands[2][2] = { 587 { ATA_COMMAND_READ_SECTORS_EXT, ATA_COMMAND_WRITE_SECTORS_EXT }, 588 { ATA_COMMAND_READ_DMA_EXT, ATA_COMMAND_WRITE_DMA_EXT } 589 }; 590 591 // list of normal LBA opcodes 592 static const uint8 s28BitCommands[2][2] = { 593 { ATA_COMMAND_READ_SECTORS, ATA_COMMAND_WRITE_SECTORS }, 594 { ATA_COMMAND_READ_DMA, ATA_COMMAND_WRITE_DMA } 595 }; 596 597 uint32 sectorCount = *request->BytesLeft() / ATA_BLOCK_SIZE; 598 TRACE("about to transfer %lu sectors\n", sectorCount); 599 600 if (fUseLBA) { 601 if (fUse48Bits 602 && (address + sectorCount > 0xfffffff || sectorCount > 0x100)) { 603 // use LBA48 only if necessary 604 if (sectorCount > 0xffff) { 605 TRACE_ERROR("invalid sector count %lu\n", sectorCount); 606 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, 607 SCSIS_ASC_INV_CDB_FIELD); 608 return B_ERROR; 609 } 610 611 fRegisterMask = ATA_MASK_SECTOR_COUNT_48 612 | ATA_MASK_LBA_LOW_48 613 | ATA_MASK_LBA_MID_48 614 | ATA_MASK_LBA_HIGH_48; 615 616 fTaskFile.lba48.sector_count_0_7 = sectorCount & 0xff; 617 fTaskFile.lba48.sector_count_8_15 = (sectorCount >> 8) & 0xff; 618 fTaskFile.lba48.lba_0_7 = address & 0xff; 619 fTaskFile.lba48.lba_8_15 = (address >> 8) & 0xff; 620 fTaskFile.lba48.lba_16_23 = (address >> 16) & 0xff; 621 fTaskFile.lba48.lba_24_31 = (address >> 24) & 0xff; 622 fTaskFile.lba48.lba_32_39 = (address >> 32) & 0xff; 623 fTaskFile.lba48.lba_40_47 = (address >> 40) & 0xff; 624 fTaskFile.lba48.command = s48BitCommands[request->UseDMA() 625 ? 1 : 0][request->IsWrite() ? 1 : 0]; 626 } else { 627 // normal LBA 628 if (sectorCount > 0x100) { 629 TRACE_ERROR("invalid sector count %lu\n", sectorCount); 630 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, 631 SCSIS_ASC_INV_CDB_FIELD); 632 return B_ERROR; 633 } 634 635 fRegisterMask = ATA_MASK_SECTOR_COUNT 636 | ATA_MASK_LBA_LOW 637 | ATA_MASK_LBA_MID 638 | ATA_MASK_LBA_HIGH 639 | ATA_MASK_DEVICE_HEAD; 640 641 fTaskFile.lba.sector_count = sectorCount & 0xff; 642 fTaskFile.lba.lba_0_7 = address & 0xff; 643 fTaskFile.lba.lba_8_15 = (address >> 8) & 0xff; 644 fTaskFile.lba.lba_16_23 = (address >> 16) & 0xff; 645 fTaskFile.lba.lba_24_27 = (address >> 24) & 0xf; 646 fTaskFile.lba.command = s28BitCommands[request->UseDMA() 647 ? 1 : 0][request->IsWrite() ? 1 : 0]; 648 } 649 } else { 650 // CHS mode - we do not support it anymore 651 TRACE_ERROR("chs mode not supported\n"); 652 request->SetSense(SCSIS_KEY_ILLEGAL_REQUEST, SCSIS_ASC_INV_CDB_FIELD); 653 return B_ERROR; 654 } 655 656 return B_OK; 657 } 658