Changeset cdc8a391 in mainline for uspace/drv/bus/usb/ohci/hc.c


Ignore:
Timestamp:
2013-07-12T14:08:06Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
322ac35c
Parents:
98abd40 (diff), b66ffb1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/hc.c

    r98abd40 rcdc8a391  
    3535
    3636#include <errno.h>
     37#include <stdbool.h>
    3738#include <str_error.h>
    3839#include <adt/list.h>
     
    183184int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun)
    184185{
     186        bool addr_reqd = false;
     187        bool ep_added = false;
     188        bool fun_bound = false;
     189        int rc;
     190
    185191        assert(instance);
    186192        assert(hub_fun);
     
    188194        /* Try to get address 1 for root hub. */
    189195        instance->rh.address = 1;
    190         int ret = usb_device_manager_request_address(
     196        rc = usb_device_manager_request_address(
    191197            &instance->generic.dev_manager, &instance->rh.address, false,
    192198            USB_SPEED_FULL);
    193         if (ret != EOK) {
     199        if (rc != EOK) {
    194200                usb_log_error("Failed to get OHCI root hub address: %s\n",
    195                     str_error(ret));
    196                 return ret;
    197         }
    198 
    199 #define CHECK_RET_UNREG_RETURN(ret, message...) \
    200 if (ret != EOK) { \
    201         usb_log_error(message); \
    202         usb_endpoint_manager_remove_ep( \
    203             &instance->generic.ep_manager, instance->rh.address, 0, \
    204             USB_DIRECTION_BOTH, NULL, NULL); \
    205         usb_device_manager_release_address( \
    206             &instance->generic.dev_manager, instance->rh.address); \
    207         return ret; \
    208 } else (void)0
    209 
    210         ret = usb_endpoint_manager_add_ep(
     201                    str_error(rc));
     202                goto error;
     203        }
     204
     205        addr_reqd = true;
     206
     207        rc = usb_endpoint_manager_add_ep(
    211208            &instance->generic.ep_manager, instance->rh.address, 0,
    212209            USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64,
    213210            0, NULL, NULL);
    214         CHECK_RET_UNREG_RETURN(ret,
    215             "Failed to register root hub control endpoint: %s.\n",
    216             str_error(ret));
    217 
    218         ret = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
    219         CHECK_RET_UNREG_RETURN(ret,
    220             "Failed to add root hub match-id: %s.\n", str_error(ret));
    221 
    222         ret = ddf_fun_bind(hub_fun);
    223         CHECK_RET_UNREG_RETURN(ret,
    224             "Failed to bind root hub function: %s.\n", str_error(ret));
    225 
    226         ret = usb_device_manager_bind_address(&instance->generic.dev_manager,
     211        if (rc != EOK) {
     212                usb_log_error("Failed to register root hub control endpoint: %s.\n",
     213                    str_error(rc));
     214                goto error;
     215        }
     216
     217        ep_added = true;
     218
     219        rc = ddf_fun_add_match_id(hub_fun, "usb&class=hub", 100);
     220        if (rc != EOK) {
     221                usb_log_error("Failed to add root hub match-id: %s.\n",
     222                    str_error(rc));
     223                goto error;
     224        }
     225
     226        rc = ddf_fun_bind(hub_fun);
     227        if (rc != EOK) {
     228                usb_log_error("Failed to bind root hub function: %s.\n",
     229                    str_error(rc));
     230                goto error;
     231        }
     232
     233        fun_bound = true;
     234
     235        rc = usb_device_manager_bind_address(&instance->generic.dev_manager,
    227236            instance->rh.address, ddf_fun_get_handle(hub_fun));
    228         if (ret != EOK)
     237        if (rc != EOK) {
    229238                usb_log_warning("Failed to bind root hub address: %s.\n",
    230                     str_error(ret));
    231 
    232         return EOK;
    233 #undef CHECK_RET_RELEASE
     239                    str_error(rc));
     240        }
     241
     242        return EOK;
     243error:
     244        if (fun_bound)
     245                ddf_fun_unbind(hub_fun);
     246        if (ep_added) {
     247                usb_endpoint_manager_remove_ep(
     248                    &instance->generic.ep_manager, instance->rh.address, 0,
     249                    USB_DIRECTION_BOTH, NULL, NULL);
     250        }
     251        if (addr_reqd) {
     252                usb_device_manager_release_address(
     253                    &instance->generic.dev_manager, instance->rh.address);
     254        }
     255        return rc;
    234256}
    235257
     
    246268        assert(instance);
    247269
    248 #define CHECK_RET_RETURN(ret, message...) \
    249 if (ret != EOK) { \
    250         usb_log_error(message); \
    251         return ret; \
    252 } else (void)0
    253 
    254         int ret =
     270        int rc =
    255271            pio_enable((void*)regs, reg_size, (void**)&instance->registers);
    256         CHECK_RET_RETURN(ret,
    257             "Failed to gain access to device registers: %s.\n", str_error(ret));
     272        if (rc != EOK) {
     273                usb_log_error("Failed to gain access to device registers: %s.\n",
     274                    str_error(rc));
     275                return rc;
     276        }
    258277
    259278        list_initialize(&instance->pending_batches);
     
    266285        instance->generic.ep_remove_hook = ohci_endpoint_fini;
    267286
    268         ret = hc_init_memory(instance);
    269         CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n",
    270             str_error(ret));
    271 #undef CHECK_RET_RETURN
     287        rc = hc_init_memory(instance);
     288        if (rc != EOK) {
     289                usb_log_error("Failed to create OHCI memory structures: %s.\n",
     290                    str_error(rc));
     291                return rc;
     292        }
    272293
    273294        fibril_mutex_initialize(&instance->guard);
Note: See TracChangeset for help on using the changeset viewer.