From ffd36865cf3e66a57f5b1c5e938d53bdbd1c9933 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 9 Jul 2018 21:51:08 -0400 Subject: [PATCH] sata_request: Cargo-cult some behaviors from FreeBSD. See 13778#comment:3 for information on FreeBSD behaviors. I didn't manage to locate where the specification talks about this (but my specification-fu is rather poor), and it didn't fix the check_sense syslog spamming on my machine. But it seems to continue to function as before on my hardware as well as VirtualBox and VMware, so perhaps it might fix something else. Signed-off-by: Alexander von Gluck IV --- .../kernel/busses/scsi/ahci/sata_request.cpp | 16 +++++++++++----- .../kernel/busses/scsi/ahci/sata_request.h | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp b/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp index 9e06dceab6..65d22917e3 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp @@ -1,6 +1,7 @@ /* * Copyright 2008, Marcus Overhagen. All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2009-2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. */ @@ -12,6 +13,9 @@ #define FIS_TYPE_REGISTER_HOST_TO_DEVICE 0x27 +#define ATA_D_LBA 0x40 /* use LBA addressing */ +#define ATA_A_4BIT 0x08 /* 4 head bits */ + sata_request::sata_request() : @@ -60,7 +64,10 @@ sata_request::SetATACommand(uint8 command) fFis[0] = FIS_TYPE_REGISTER_HOST_TO_DEVICE; fFis[1] = 0x80; // This is a command + if (fCcb != NULL) + fFis[1] |= fCcb->target_id & 0x0f; fFis[2] = command; + fFis[15] = ATA_A_4BIT; } @@ -71,8 +78,7 @@ sata_request::SetATA28Command(uint8 command, uint32 lba, uint8 sectorCount) fFis[4] = lba & 0xff; fFis[5] = (lba >> 8) & 0xff; fFis[6] = (lba >> 16) & 0xff; - fFis[7] = 0x40 | ((lba >> 24) & 0x0f); - // device + fFis[7] = ATA_D_LBA | ((lba >> 24) & 0x0f); fFis[12] = sectorCount & 0xff; } @@ -84,8 +90,7 @@ sata_request::SetATA48Command(uint8 command, uint64 lba, uint16 sectorCount) fFis[4] = lba & 0xff; fFis[5] = (lba >> 8) & 0xff; fFis[6] = (lba >> 16) & 0xff; - fFis[7] = 0x40; - // device + fFis[7] = ATA_D_LBA; fFis[8] = (lba >> 24) & 0xff; fFis[9] = (lba >> 32) & 0xff; fFis[10] = (lba >> 40) & 0xff; @@ -107,6 +112,7 @@ sata_request::SetATAPICommand(size_t transferLength) { fIsATAPI = true; SetATACommand(0xa0); + fFis[7] = ATA_D_LBA; if (1 /* isPIO */) { if (transferLength == 0) transferLength = 2; diff --git a/src/add-ons/kernel/busses/scsi/ahci/sata_request.h b/src/add-ons/kernel/busses/scsi/ahci/sata_request.h index 5686530fa0..5e6afad1ed 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/sata_request.h +++ b/src/add-ons/kernel/busses/scsi/ahci/sata_request.h @@ -1,6 +1,7 @@ /* * Copyright 2008, Marcus Overhagen. All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2009-2018, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. */ #ifndef _SATA_REQUEST_H #define _SATA_REQUEST_H