Ticket #12357: ahci-rework-v2c.diff

File ahci-rework-v2c.diff, 7.5 KB (added by kallisti5, 5 years ago)

Undoing more TRACE changes to improve readibiltiy.

  • src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h

    diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h b/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h
    index b9c8c03..456bdaf 100644
    a b enum {  
    9797#define IPM_TRANSITIONS_TO_PARTIAL_DISABLED 0x1
    9898#define IPM_TRANSITIONS_TO_SLUMBER_DISABLED 0x2
    9999
     100// Device signatures
     101#define SATA_SIG_ATA            0x00000101 // SATA drive
     102#define SATA_SIG_ATAPI          0xEB140101 // ATAPI drive
     103#define SATA_SIG_SEMB           0xC33C0101 // Enclosure management bridge
     104#define SATA_SIG_PM             0x96690101 // Port multiplier
    100105
    101106typedef struct {
    102107    uint32      clb;            // Command List Base Address
    enum {  
    130135    PORT_CMD_ATAPI  = (1 << 24),    // Device is ATAPI
    131136    PORT_CMD_CR     = (1 << 15),    // Command List Running (DMA active)
    132137    PORT_CMD_FR     = (1 << 14),    // FIS Receive Running
    133     PORT_CMD_FER    = (1 << 4),     // FIS Receive Enable
     138    PORT_CMD_FRE    = (1 << 4),     // FIS Receive Enable
    134139    PORT_CMD_CLO    = (1 << 3),     // Command List Override
    135140    PORT_CMD_POD    = (1 << 2),     // Power On Device
    136141    PORT_CMD_SUD    = (1 << 1),     // Spin-up Device
  • src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp

    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 94a0034..dac9644 100644
    a b AHCIPort::Init1()  
    120120    fRegs->is = fRegs->is;
    121121
    122122    // clear error bits
    123     fRegs->serr = fRegs->serr;
     123    _ClearErrorRegister();
    124124
    125125    // power up device
    126126    fRegs->cmd |= PORT_CMD_POD;
    AHCIPort::Init1()  
    132132    fRegs->cmd = (fRegs->cmd & ~PORT_CMD_ICC_MASK) | PORT_CMD_ICC_ACTIVE;
    133133
    134134    // enable FIS receive
    135     fRegs->cmd |= PORT_CMD_FER;
     135    fRegs->cmd |= PORT_CMD_FRE;
    136136
    137137    FlushPostedWrites();
    138138
    AHCIPort::Init2()  
    146146{
    147147    TRACE("AHCIPort::Init2 port %d\n", fIndex);
    148148
    149     // start DMA engine
    150     fRegs->cmd |= PORT_CMD_ST;
     149    // enable port
     150    Enable();
    151151
    152152    // enable interrupts
    153153    fRegs->ie = PORT_INT_MASK;
    154154
    155155    FlushPostedWrites();
    156156
     157    // reset port and probe info
    157158    ResetPort(true);
    158159
    159160    TRACE("ie   0x%08" B_PRIx32 "\n", fRegs->ie);
    AHCIPort::Init2()  
    172173
    173174    fDevicePresent = (fRegs->ssts & 0xf) == 0x3;
    174175
     176    TRACE("%s: port %d, device %s\n", __func__, fIndex,
     177        fDevicePresent ? "present" : "absent");
     178
    175179    return B_OK;
    176180}
    177181
    AHCIPort::Uninit()  
    181185{
    182186    TRACE("AHCIPort::Uninit port %d\n", fIndex);
    183187
    184     // disable FIS receive
    185     fRegs->cmd &= ~PORT_CMD_FER;
    186 
    187     // wait for receive completion, up to 500ms
    188     if (wait_until_clear(&fRegs->cmd, PORT_CMD_FR, 500000) < B_OK) {
    189         TRACE("AHCIPort::Uninit port %d error FIS rx still running\n", fIndex);
    190     }
    191 
    192     // stop DMA engine
    193     fRegs->cmd &= ~PORT_CMD_ST;
     188    // Clear FRE and wait for completion
     189    fRegs->cmd &= ~PORT_CMD_FRE;
     190    if (wait_until_clear(&fRegs->cmd, PORT_CMD_FR, 500000) < B_OK)
     191        TRACE("%s: port %d error FIS rx still running\n", __func__, fIndex);
    194192
    195     // wait for DMA completion
    196     if (wait_until_clear(&fRegs->cmd, PORT_CMD_CR, 500000) < B_OK) {
    197         TRACE("AHCIPort::Uninit port %d error DMA engine still running\n",
    198             fIndex);
    199     }
     193    // shutdown the port
     194    Disable();
    200195
    201196    // disable interrupts
    202197    fRegs->ie = 0;
    void  
    218213AHCIPort::ResetDevice()
    219214{
    220215    // perform a hard reset
    221     if (!_HardReset())
     216    if (!_HardReset()) {
     217        ERROR("%s: port %d unable to hard reset device\n", __func__, fIndex);
    222218        return;
     219    }
    223220
    224221    if (wait_until_set(&fRegs->ssts, 0x1, 100000) < B_OK)
    225222        TRACE("AHCIPort::ResetDevice port %d no device detected\n", fIndex);
    AHCIPort::ResetPort(bool forceDeviceReset)  
    243240    if (!fTestUnitReadyActive)
    244241        TRACE("AHCIPort::ResetPort port %d\n", fIndex);
    245242
    246     // stop DMA engine
    247     fRegs->cmd &= ~PORT_CMD_ST;
    248     FlushPostedWrites();
    249 
    250     if (wait_until_clear(&fRegs->cmd, PORT_CMD_CR, 500000) < B_OK) {
    251         TRACE("AHCIPort::ResetPort port %d error DMA engine doesn't stop\n",
    252             fIndex);
    253     }
     243    // stop port, flush transactions
     244    Disable();
    254245
    255246    bool deviceBusy = fRegs->tfd & (ATA_BSY | ATA_DRQ);
    256247
    AHCIPort::ResetPort(bool forceDeviceReset)  
    262253    if (deviceBusy || forceDeviceReset)
    263254        ResetDevice();
    264255
    265     // start DMA engine
    266     fRegs->cmd |= PORT_CMD_ST;
    267     FlushPostedWrites();
     256    // start port
     257    Enable();
    268258
    269259    return PostReset();
    270260}
    AHCIPort::PostReset()  
    292282
    293283    wait_until_clear(&fRegs->tfd, ATA_BSY, 31000000);
    294284
    295     fIsATAPI = fRegs->sig == 0xeb140101;
    296 
     285    fIsATAPI = fRegs->sig == SATA_SIG_ATAPI;
    297286    if (fIsATAPI)
    298287        fRegs->cmd |= PORT_CMD_ATAPI;
    299288    else
    AHCIPort::PostReset()  
    302291
    303292    if (!fTestUnitReadyActive) {
    304293        TRACE("device signature 0x%08" B_PRIx32 " (%s)\n", fRegs->sig,
    305             fRegs->sig == 0xeb140101 ? "ATAPI" : fRegs->sig == 0x00000101
     294            fRegs->sig == SATA_SIG_ATAPI ? "ATAPI" : fRegs->sig == SATA_SIG_ATA
    306295                ? "ATA" : "unknown");
    307296    }
    308297
    AHCIPort::InterruptErrorHandler(uint32 is)  
    374363    }
    375364
    376365    // read and clear SError
    377     uint32 serr = fRegs->serr;
    378     fRegs->serr = serr;
     366    _ClearErrorRegister();
    379367
    380368    if (is & PORT_INT_TFE) {
    381369        if (!fTestUnitReadyActive)
    AHCIPort::InterruptErrorHandler(uint32 is)  
    417405    if (is & PORT_INT_PC) {
    418406        TRACE("Port Connect Change\n");
    419407        // Spec v1.3, §6.2.2.3 Recovery of Unsolicited COMINIT
    420 
    421         // perform a hard reset
    422         if (!_HardReset())
    423             return;
    424 
    425         // clear error bits to clear PxSERR.DIAG.X
     408        // Spec v1.3.1, §7.4 Interaction of command list and port change status
     409        ResetPort(true);
    426410        _ClearErrorRegister();
    427411    }
    428412    if (is & PORT_INT_UF) {
    AHCIPort::FillPrdTable(volatile prd* prdTable, int* prdCount, int prdMax,  
    452436    status_t status = get_memory_map_etc(B_CURRENT_TEAM, data, dataSize,
    453437        entries, &entriesUsed);
    454438    if (status != B_OK) {
    455         TRACE("AHCIPort::FillPrdTable get_memory_map() failed: %s\n",
    456             strerror(status));
     439        TRACE("%s: get_memory_map() failed: %s\n", __func__, strerror(status));
    457440        return B_ERROR;
    458441    }
    459442
    AHCIPort::FillPrdTable(volatile prd* prdTable, int* prdCount, int prdMax,  
    500483        sgCount--;
    501484    }
    502485    if (*prdCount == 0) {
    503         TRACE("AHCIPort::FillPrdTable: count is 0\n");
     486        TRACE("%s: count is 0\n", __func__);
    504487        return B_ERROR;
    505488    }
    506489    if (dataSize > 0) {
    AHCIPort::ScsiGetRestrictions(bool* isATAPI, bool* noAutoSense,  
    13221305
    13231306
    13241307bool
     1308AHCIPort::Enable()
     1309{
     1310    TRACE("%s: port %d\n", __func__, fIndex);
     1311    if ((fRegs->cmd & PORT_CMD_ST) != 0) {
     1312        TRACE("%s: Starting port already running!\n", __func__);
     1313        return false;
     1314    }
     1315    // Start port
     1316    fRegs->cmd |= PORT_CMD_ST;
     1317    FlushPostedWrites();
     1318    return true;
     1319}
     1320
     1321
     1322bool
     1323AHCIPort::Disable()
     1324{
     1325    TRACE("%s: port %d\n", __func__, fIndex);
     1326
     1327    if ((fRegs->cmd & PORT_CMD_ST) == 0) {
     1328        TRACE("%s: port %d attempting to disable stopped port.\n",
     1329            __func__, fIndex);
     1330    }
     1331
     1332    // Disable port
     1333    fRegs->cmd &= ~PORT_CMD_ST;
     1334    FlushPostedWrites();
     1335
     1336    // Clear DMA engine and wait for completion
     1337    if (wait_until_clear(&fRegs->cmd, PORT_CMD_CR, 500000) < B_OK) {
     1338        TRACE("%s: port %d error DMA engine still running\n", __func__,
     1339            fIndex);
     1340        return false;
     1341    }
     1342
     1343    return true;
     1344}
     1345
     1346
     1347bool
    13251348AHCIPort::_HardReset()
    13261349{
    13271350    if ((fRegs->cmd & PORT_CMD_ST) != 0) {
  • src/add-ons/kernel/busses/scsi/ahci/ahci_port.h

    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 0bc4e67..2127478 100644
    a b private:  
    5050    void        ResetDevice();
    5151    status_t    ResetPort(bool forceDeviceReset = false);
    5252    status_t    PostReset();
     53    bool        Enable();
     54    bool        Disable();
     55
    5356    void        FlushPostedWrites();
    5457    void        DumpD2HFis();
    5558