[haiku-commits] BRANCH axeld-github.trim [306ca44] src/add-ons/kernel/busses/scsi/ahci

  • From: axeld-github.trim <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 28 Oct 2013 23:45:34 +0100 (CET)

added 2 changesets to branch 'refs/remotes/axeld-github/trim'
old head: f5191e6485e5f9fc835aa94e5b0195ec0df4b3fe
new head: 306ca4458e6fde7c1e8d2b126ae9c6f9617cb88e
overview: https://github.com/axeld/haiku/compare/f5191e6...306ca44

----------------------------------------------------------------------------

8a47ab6: ahci: Added missing wait_for_completion().
  
  * Thanks Marcus!
  * That made the return code for ExecuteSataRequest() pretty much useless,
    so I removed it again.
  * Also, a delete sreq was missing; I now allocate it on the stack instead.

306ca44: ahci: Set the command bits as required.
  
  * The trim command should be functional now, but it's completely untested
    at this point.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

2 files changed, 16 insertions(+), 17 deletions(-)
.../kernel/busses/scsi/ahci/ahci_port.cpp        | 31 ++++++++++----------
src/add-ons/kernel/busses/scsi/ahci/ahci_port.h  |  2 +-

############################################################################

Commit:      8a47ab6e67308590afb1a1e0570a9c5c1e5bea1d
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Oct 28 22:24:21 2013 UTC

ahci: Added missing wait_for_completion().

* Thanks Marcus!
* That made the return code for ExecuteSataRequest() pretty much useless,
  so I removed it again.
* Also, a delete sreq was missing; I now allocate it on the stack instead.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 
b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp
index 99d2da6..45ebc9c 100644
--- a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp
+++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp
@@ -802,14 +802,6 @@ AHCIPort::ScsiUnmap(scsi_ccb* request, 
scsi_unmap_parameter_list* unmapBlocks)
 {
        TRACE("%s unimplemented: TRIM call\n", __func__);
 
-       sata_request* sreq = new(std::nothrow) sata_request();
-       if (sreq == NULL) {
-               TRACE("out of memory when allocating unmap request\n");
-               request->subsys_status = SCSI_REQ_ABORTED;
-               gSCSI->finished(request, 1);
-               return;
-       }
-
        // Determine how many ranges we'll need
        // We assume that the SCSI unmap ranges cannot be merged together
        uint32 scsiRangeCount = unmapBlocks->block_data_length
@@ -846,19 +838,26 @@ AHCIPort::ScsiUnmap(scsi_ccb* request, 
scsi_unmap_parameter_list* unmapBlocks)
                }
        }
 
-       sreq->set_ata_cmd(ATA_COMMAND_DATA_SET_MANAGEMENT);
-       sreq->set_data(lbaRanges, lbaRangesSize);
+       sata_request sreq;
+       sreq.set_ata_cmd(ATA_COMMAND_DATA_SET_MANAGEMENT);
+       sreq.set_data(lbaRanges, lbaRangesSize);
+
+       ExecuteSataRequest(&sreq);
+       sreq.wait_for_completion();
 
-       bool success = ExecuteSataRequest(sreq);
+       if ((sreq.completion_status() & ATA_ERR) != 0) {
+               TRACE("trim failed (%" B_PRIu32 " ranges)!", lbaRangeCount);
+               request->subsys_status = SCSI_REQ_CMP_ERR;
+       } else
+               request->subsys_status = SCSI_REQ_CMP;
 
        request->data_resid = 0;
        request->device_status = SCSI_STATUS_GOOD;
-       request->subsys_status = success ? SCSI_REQ_CMP : SCSI_REQ_CMP_ERR;
        gSCSI->finished(request, 1);
 }
 
 
-bool
+void
 AHCIPort::ExecuteSataRequest(sata_request *request, bool isWrite)
 {
        FLOW("ExecuteAtaRequest port %d\n", fIndex);
@@ -902,7 +901,7 @@ AHCIPort::ExecuteSataRequest(sata_request *request, bool 
isWrite)
                ResetPort();
                FinishTransfer();
                request->abort();
-               return false;
+               return;
        }
 
        cpu_status cpu = disable_interrupts();
@@ -946,11 +945,10 @@ AHCIPort::ExecuteSataRequest(sata_request *request, bool 
isWrite)
        if (status == B_TIMED_OUT) {
                TRACE("ExecuteAtaRequest port %d: device timeout\n", fIndex);
                request->abort();
-               return false;
+               return;
        }
 
        request->finish(tfd, bytesTransfered);
-       return true;
 }
 
 
diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h 
b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h
index 7ac542c..f89a622 100644
--- a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h
+++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h
@@ -39,7 +39,7 @@ private:
        void            ScsiUnmap(scsi_ccb* request,
                                        struct scsi_unmap_parameter_list* 
unmapBlocks);
 
-       bool            ExecuteSataRequest(sata_request *request, bool isWrite 
= false);
+       void            ExecuteSataRequest(sata_request *request, bool isWrite 
= false);
 
        void            ResetDevice();
        status_t        ResetPort(bool forceDeviceReset = false);

############################################################################

Commit:      306ca4458e6fde7c1e8d2b126ae9c6f9617cb88e
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Oct 28 22:36:27 2013 UTC

ahci: Set the command bits as required.

* The trim command should be functional now, but it's completely untested
  at this point.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 
b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp
index 45ebc9c..d50ce71 100644
--- a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp
+++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp
@@ -839,7 +839,8 @@ AHCIPort::ScsiUnmap(scsi_ccb* request, 
scsi_unmap_parameter_list* unmapBlocks)
        }
 
        sata_request sreq;
-       sreq.set_ata_cmd(ATA_COMMAND_DATA_SET_MANAGEMENT);
+       sreq.set_ata48_cmd(ATA_COMMAND_DATA_SET_MANAGEMENT, 0,
+               (lbaRangesSize + 511) / 512);
        sreq.set_data(lbaRanges, lbaRangesSize);
 
        ExecuteSataRequest(&sreq);


Other related posts:

  • » [haiku-commits] BRANCH axeld-github.trim [306ca44] src/add-ons/kernel/busses/scsi/ahci - axeld-github . trim