Changeset f29643d5 in mainline


Ignore:
Timestamp:
2015-07-05T09:25:02Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ff0258f
Parents:
f523daf
Message:

libusbhost: Make sure interrupts are registered before touching hw.

rework error reporting in device enumration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    rf523daf rf29643d5  
    470470        int ret = usb_bus_get_speed(&hcd->bus, USB_ADDRESS_DEFAULT, &speed);
    471471        if (ret != EOK) {
    472                 return ret;
    473         }
    474 
    475         usb_log_debug("Found new %s speed USB device\n", usb_str_speed(speed));
     472                usb_log_error("Failed to verify speed: %s.", str_error(ret));
     473                return ret;
     474        }
     475
     476        usb_log_debug("Found new %s speed USB device.", usb_str_speed(speed));
    476477
    477478        static const usb_target_t default_target = {{
     
    481482
    482483        const usb_address_t address = hcd_request_address(hcd, speed);
    483         if (address < 0)
     484        if (address < 0) {
     485                usb_log_error("Failed to reserve new address: %s.",
     486                    str_error(address));
    484487                return address;
     488        }
    485489
    486490        usb_log_debug("Reserved new address: %d\n", address);
     
    500504            tt_address, port);
    501505        if (ret != EOK) {
     506                usb_log_error("Device(%d): Failed to add default target: %s.",
     507                    address, str_error(ret));
    502508                hcd_release_address(hcd, address);
    503509                return ret;
     
    510516
    511517        // TODO CALLBACKS
    512         usb_log_debug("Device(%d): Requesting first 8B of device descriptor\n",
     518        usb_log_debug("Device(%d): Requesting first 8B of device descriptor.",
    513519            address);
    514520        ssize_t got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_IN,
     
    517523
    518524        if (got != CTRL_PIPE_MIN_PACKET_SIZE) {
     525                ret = got < 0 ? got : EOVERFLOW;
     526                usb_log_error("Device(%d): Failed to get 8B of dev descr: %s.",
     527                    address, str_error(ret));
    519528                hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
    520529                hcd_release_address(hcd, address);
    521                 return got < 0 ? got : EOVERFLOW;
     530                return ret;
    522531        }
    523532
    524533        /* Register EP on the new address */
    525         usb_log_debug("Device(%d): Registering control EP\n", address);
     534        usb_log_debug("Device(%d): Registering control EP.", address);
    526535        ret = hcd_add_ep(hcd, target, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
    527536            ED_MPS_PACKET_SIZE_GET(uint16_usb2host(desc.max_packet_size)),
     
    530539            tt_address, port);
    531540        if (ret != EOK) {
     541                usb_log_error("Device(%d): Failed to register EP0: %s",
     542                    address, str_error(ret));
    532543                hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
    533544                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
     
    540551            SET_ADDRESS(target.address);
    541552
    542         usb_log_debug("Device(%d): Setting USB address.\n", address);
     553        usb_log_debug("Device(%d): Setting USB address.", address);
    543554        got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
    544555            NULL, 0, *(uint64_t *)&set_address, "set address");
    545556
    546         usb_log_debug("Device(%d): Removing default (0:0) EP\n", address);
     557        usb_log_debug("Device(%d): Removing default (0:0) EP.", address);
    547558        hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
    548559
    549560        if (got != 0) {
     561                usb_log_error("Device(%d): Failed to set new address: %s.",
     562                    address, str_error(got));
    550563                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
    551564                hcd_release_address(hcd, address);
     
    557570            GET_DEVICE_DESC(sizeof(desc));
    558571
    559         usb_log_debug("Device(%d): Requesting full device descriptor\n",
     572        usb_log_debug("Device(%d): Requesting full device descriptor.",
    560573            address);
    561574        got = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN,
     
    563576            "read device descriptor");
    564577        if (ret != EOK) {
     578                usb_log_error("Device(%d): Failed to set get dev descriptor: %s",
     579                    address, str_error(ret));
    565580                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
    566581                hcd_release_address(hcd, target.address);
    567                 return got < 0 ? got : EOVERFLOW;
     582                return ret;
    568583        }
    569584
     
    572587        init_match_ids(&mids);
    573588
    574         usb_log_debug("Device(%d): Creating match IDs\n", address);
     589        usb_log_debug("Device(%d): Creating match IDs.", address);
    575590        ret = create_match_ids(&mids, &desc);
    576591        if (ret != EOK) {
     592                usb_log_error("Device(%d): Failed to create match ids: %s",
     593                    address, str_error(ret));
    577594                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
    578595                hcd_release_address(hcd, target.address);
     
    581598
    582599        /* Register device */
    583         usb_log_debug("Device(%d): Registering DDF device\n", address);
     600        usb_log_debug("Device(%d): Registering DDF device.", address);
    584601        ret = hcd_ddf_add_device(device, hub, port, address, speed, NULL, &mids);
    585602        clean_match_ids(&mids);
    586603        if (ret != EOK) {
     604                usb_log_error("Device(%d): Failed to register: %s.",
     605                    address, str_error(ret));
    587606                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
    588607                hcd_release_address(hcd, target.address);
     
    844863        }
    845864
    846         if (driver->claim)
    847                 ret = driver->claim(device);
    848         if (ret != EOK) {
    849                 usb_log_error("Failed to claim `%s' for driver `%s'",
    850                     ddf_dev_get_name(device), driver->name);
    851                 return ret;
    852         }
    853 
    854865        hw_res_list_parsed_t hw_res;
    855866        ret = hcd_ddf_get_registers(device, &hw_res);
     
    875886                usb_log_debug("Hw interrupts enabled.\n");
    876887        }
     888
     889        if (driver->claim)
     890                ret = driver->claim(device);
     891        if (ret != EOK) {
     892                usb_log_error("Failed to claim `%s' for driver `%s'",
     893                    ddf_dev_get_name(device), driver->name);
     894                return ret;
     895        }
     896
    877897
    878898        /* Init hw driver */
Note: See TracChangeset for help on using the changeset viewer.