ChorusOS 5.0 Board Support Package Developer's Guide

Logging

Driver errors and device failures will be logged using the Driver Framework logging mechanism. The DKI_ERR(), DKI_WARN() and DKI_MSG() macros should be used for that purpose.

Code Example 13-2, from the dec21x4x ethernet driver, illustrates how detected errors are turned into event notifications, and how they are logged. In the example, the Dec21Data structure contains driver instance specific data. In this structure, the failed field is the instance-wide flag indicating a device failure. The evtState field is used to record the current state of the driver instance, regarding propagated events.


Example 13-2 dec21x4x error handling

    /*
     * Enter failed mode (called on device failure).
     * On device failure, the REMOVAL event is propagated to clients, 
     * as the device should not be accessed any more.
     * However, internal state (dec21->evtState) is set to 
     * PCI_DEV_SHUTDOWN, as we may need to further access the device 
     * (to reset it for example). The dec21->failed flag is also set 
     * for next client down calls to return a K_EFAIL result.
     */
    static KnError
fail (Dec21Data* dec21)
{
    dec21->failed = TRUE;
    if (!dec21->evtState) {
        dec21->evtState = PCI_DEV_SHUTDOWN;
        DKI_MSG(("%s: entered into failed mode\n", dec21->path));    
        svDeviceEvent(dec21->devRegId, DEV_EVENT_REMOVAL, NULL);
    }
    return K_OK;
}

    /*
     * The I/O error handler is called by the parent bus driver
     * if a bus error occurs when accessing the device registers.
     * This is considered a device failure.
     */
    static void
ioErrHandler (void* cookie, PciBusError* error)
{
    DKI_ERR(("%s: error -- I/O (%d) at 0x%08x\n",
             ((Dec21Data*)cookie)->path, error->code, error->offset));
    fail(cookie);
}

    /*
     * DMA error handler.
     * This is considered a device failure.
     */
    static void
dmaErrHandler (void* cookie, PciBusError* error)
{
    DKI_ERR(("%s: error -- DMA (%d) at 0x%08x\n",
             ((Dec21Data*)cookie)->path, error->code, error->offset));
    fail(cookie);
}

Refer to Part III for details about these macros.