Changeset 612af1a0 in mainline


Ignore:
Timestamp:
2011-10-13T10:23:50Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fb422312
Parents:
0d103aef
Message:

uhcirh: Improve error handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhcirh/port.c

    r0d103aef r612af1a0  
    4444#include "port.h"
    4545
     46#define MAX_ERROR_COUNT 5
     47
    4648static int uhci_port_check(void *port);
    4749static int uhci_port_reset_enable(void *arg);
     
    151153        assert(instance);
    152154
     155        unsigned allowed_failures = MAX_ERROR_COUNT;
     156#define CHECK_RET_FAIL(ret, msg...) \
     157        if (ret != EOK) { \
     158                usb_log_error(msg); \
     159                if (!(allowed_failures-- > 0)) { \
     160                        usb_log_fatal( \
     161                           "Maximum number of failures reached, " \
     162                           "bailing out.\n"); \
     163                        return ret; \
     164                } \
     165                continue; \
     166        } else (void)0
     167
    153168        while (1) {
    154169                async_usleep(instance->wait_period_usec);
     
    165180                        continue;
    166181
    167                 int ret =
    168                     usb_hc_connection_open(&instance->hc_connection);
    169                 if (ret != EOK) {
    170                         usb_log_error("%s: Failed to connect to HC.",
    171                             instance->id_string);
    172                         continue;
    173                 }
    174 
    175182                usb_log_debug("%s: Connected change detected: %x.\n",
    176183                    instance->id_string, port_status);
    177184
     185                int ret = usb_hc_connection_open(&instance->hc_connection);
     186                CHECK_RET_FAIL(ret, "%s: Failed to connect to HC %s.\n",
     187                    instance->id_string, str_error(ret));
     188
    178189                /* Remove any old device */
    179190                if (instance->attached_device.fun) {
    180                         usb_log_debug2("%s: Removing device.\n",
    181                             instance->id_string);
    182191                        uhci_port_remove_device(instance);
    183192                }
    184193
    185 
    186194                if ((port_status & STATUS_CONNECTED) != 0) {
    187                         /* New device */
     195                        /* New device, this will take care of WC bits */
    188196                        const usb_speed_t speed =
    189197                            ((port_status & STATUS_LOW_SPEED) != 0) ?
     
    198206
    199207                ret = usb_hc_connection_close(&instance->hc_connection);
    200                 if (ret != EOK) {
    201                         usb_log_error("%s: Failed to disconnect.",
    202                             instance->id_string);
    203                 }
     208                CHECK_RET_FAIL(ret, "%s: Failed to disconnect from hc: %s.\n",
     209                    instance->id_string, str_error(ret));
    204210        }
    205211        return EOK;
     
    258264        usb_log_debug("%s: Detected new device.\n", port->id_string);
    259265
    260         int ret, count = 0;
     266        int ret, count = MAX_ERROR_COUNT;
    261267        do {
    262268                ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
     
    264270                    &port->attached_device.address, NULL, NULL,
    265271                    &port->attached_device.fun);
    266         } while (ret != EOK && ++count < 4);
     272        } while (ret != EOK && count-- > 0);
    267273
    268274        if (ret != EOK) {
     
    273279        }
    274280
    275         usb_log_info("New device at port %u, address %d (handle %" PRIun ").\n",
    276             port->number, port->attached_device.address,
     281        usb_log_info("%s: New device, address %d (handle %" PRIun ").\n",
     282            port->id_string, port->attached_device.address,
    277283            port->attached_device.fun->handle);
    278284        return EOK;
Note: See TracChangeset for help on using the changeset viewer.