Ignore:
File:
1 edited

Legend:

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

    rcccd60c3 r68e5406  
    481481        }};
    482482
    483         const usb_address_t address = hcd_request_address(hcd, speed);
    484         if (address < 0) {
     483        usb_address_t address;
     484        ret = hcd_request_address(hcd, speed, &address);
     485        if (ret != EOK) {
    485486                usb_log_error("Failed to reserve new address: %s.",
    486                     str_error(address));
    487                 return address;
     487                    str_error(ret));
     488                return ret;
    488489        }
    489490
     
    518519        usb_log_debug("Device(%d): Requesting first 8B of device descriptor.",
    519520            address);
    520         ssize_t got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_IN,
     521        size_t got;
     522        ret = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_IN,
    521523            &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
    522             "read first 8 bytes of dev descriptor");
    523 
    524         if (got != CTRL_PIPE_MIN_PACKET_SIZE) {
    525                 ret = got < 0 ? got : EOVERFLOW;
     524            "read first 8 bytes of dev descriptor", &got);
     525
     526        if (ret == EOK && got != CTRL_PIPE_MIN_PACKET_SIZE) {
     527                ret = EOVERFLOW;
     528        }
     529
     530        if (ret != EOK) {
    526531                usb_log_error("Device(%d): Failed to get 8B of dev descr: %s.",
    527532                    address, str_error(ret));
     
    552557
    553558        usb_log_debug("Device(%d): Setting USB address.", address);
    554         got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
    555             NULL, 0, *(uint64_t *)&set_address, "set address");
     559        ret = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
     560            NULL, 0, *(uint64_t *)&set_address, "set address", &got);
    556561
    557562        usb_log_debug("Device(%d): Removing default (0:0) EP.", address);
    558563        hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
    559564
    560         if (got != 0) {
     565        if (ret != EOK) {
    561566                usb_log_error("Device(%d): Failed to set new address: %s.",
    562                     address, str_error(got));
     567                    address, str_error(ret));
    563568                hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
    564569                hcd_release_address(hcd, address);
    565                 return got;
     570                return ret;
    566571        }
    567572
     
    572577        usb_log_debug("Device(%d): Requesting full device descriptor.",
    573578            address);
    574         got = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN,
     579        ret = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN,
    575580            &desc, sizeof(desc), *(uint64_t *)&get_device_desc,
    576             "read device descriptor");
     581            "read device descriptor", &got);
    577582        if (ret != EOK) {
    578583                usb_log_error("Device(%d): Failed to set get dev descriptor: %s",
     
    742747 * @param[in] gen_irq_code IRQ code generator.
    743748 *
    744  * @return IRQ capability handle on success.
    745  * @return Negative error code.
     749 * @param[out] handle  IRQ capability handle on success.
     750 *
     751 * @return Error code.
    746752 */
    747753int hcd_ddf_setup_interrupts(ddf_dev_t *device,
    748754    const hw_res_list_parsed_t *hw_res,
    749755    interrupt_handler_t handler,
    750     int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *hw_res))
     756    int (*gen_irq_code)(irq_code_t *, const hw_res_list_parsed_t *, int *),
     757    cap_handle_t *handle)
    751758{
    752759
     
    757764        irq_code_t irq_code = {0};
    758765
    759         const int irq = gen_irq_code(&irq_code, hw_res);
    760         if (irq < 0) {
     766        int irq;
     767        int ret = gen_irq_code(&irq_code, hw_res, &irq);
     768        if (ret != EOK) {
    761769                usb_log_error("Failed to generate IRQ code: %s.\n",
    762                     str_error(irq));
    763                 return irq;
     770                    str_error(ret));
     771                return ret;
    764772        }
    765773
    766774        /* Register handler to avoid interrupt lockup */
    767         const int irq_cap = register_interrupt_handler(device, irq, handler,
    768             &irq_code);
     775        ret = register_interrupt_handler(device, irq, handler,
     776            &irq_code, handle);
    769777        irq_code_clean(&irq_code);
    770         if (irq_cap < 0) {
    771                 usb_log_error("Failed to register interrupt handler: %s.\n",
    772                     str_error(irq_cap));
    773                 return irq_cap;
    774         }
    775 
    776         /* Enable interrupts */
    777         int ret = hcd_ddf_enable_interrupt(device, irq);
    778778        if (ret != EOK) {
    779779                usb_log_error("Failed to register interrupt handler: %s.\n",
    780780                    str_error(ret));
    781                 unregister_interrupt_handler(device, irq_cap);
    782                 return ret;
    783         }
    784         return irq_cap;
     781                return ret;
     782        }
     783
     784        /* Enable interrupts */
     785        ret = hcd_ddf_enable_interrupt(device, irq);
     786        if (ret != EOK) {
     787                usb_log_error("Failed to register interrupt handler: %s.\n",
     788                    str_error(ret));
     789                unregister_interrupt_handler(device, *handle);
     790        }
     791        return ret;
    785792}
    786793
     
    788795 *
    789796 * @param[in] dev DDF instance of the device to use.
    790  * @param[in] iid (Unused).
    791797 * @param[in] call Pointer to the call from kernel.
    792798 */
    793 void ddf_hcd_gen_irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev)
     799void ddf_hcd_gen_irq_handler(ipc_call_t *call, ddf_dev_t *dev)
    794800{
    795801        assert(dev);
     
    877883        interrupt_handler_t *irq_handler =
    878884            driver->irq_handler ? driver->irq_handler : ddf_hcd_gen_irq_handler;
    879         const int irq_cap = hcd_ddf_setup_interrupts(device, &hw_res,
    880             irq_handler, driver->irq_code_gen);
    881         bool irqs_enabled = !(irq_cap < 0);
     885        int irq_cap;
     886        ret = hcd_ddf_setup_interrupts(device, &hw_res,
     887            irq_handler, driver->irq_code_gen, &irq_cap);
     888        bool irqs_enabled = (ret == EOK);
    882889        if (irqs_enabled) {
    883890                usb_log_debug("Hw interrupts enabled.\n");
    884891        }
    885892
    886         if (driver->claim)
     893        if (driver->claim) {
    887894                ret = driver->claim(device);
    888         if (ret != EOK) {
    889                 usb_log_error("Failed to claim `%s' for driver `%s'",
    890                     ddf_dev_get_name(device), driver->name);
    891                 return ret;
     895                if (ret != EOK) {
     896                        usb_log_error("Failed to claim `%s' for driver `%s'",
     897                            ddf_dev_get_name(device), driver->name);
     898                        return ret;
     899                }
    892900        }
    893901
Note: See TracChangeset for help on using the changeset viewer.