Ignore:
File:
1 edited

Legend:

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

    r8b54fe6 r6b6fc232  
    4949        assert(hcd);
    5050
    51         int ret;
    52 
    53         size_t res_bw;
    54         endpoint_t *ep = usb_endpoint_manager_get_ep(&hcd->ep_manager,
    55             target.address, target.endpoint, direction, &res_bw);
     51        endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,
     52            target.address, target.endpoint, direction);
    5653        if (ep == NULL) {
    5754                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
     
    6562        const size_t bw = bandwidth_count_usb11(
    6663            ep->speed, ep->transfer_type, size, ep->max_packet_size);
    67         if (res_bw < bw) {
     64        /* Check if we have enough bandwidth reserved */
     65        if (ep->bandwidth < bw) {
    6866                usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
    6967                    "but only %zu is reserved.\n",
    70                     target.address, target.endpoint, name, bw, res_bw);
     68                    ep->address, ep->endpoint, name, bw, ep->bandwidth);
    7169                return ENOSPC;
    7270        }
     
    7876        /* No private data and no private data dtor */
    7977        usb_transfer_batch_t *batch =
    80             usb_transfer_batch_get(ep, data, size, setup_data,
     78            usb_transfer_batch_create(ep, data, size, setup_data,
    8179            in, out, arg, fun, NULL, NULL);
    8280        if (!batch) {
     
    8482        }
    8583
    86         ret = hcd->schedule(hcd, batch);
     84        const int ret = hcd->schedule(hcd, batch);
    8785        if (ret != EOK)
    88                 usb_transfer_batch_dispose(batch);
     86                usb_transfer_batch_destroy(batch);
    8987
    9088        return ret;
     89}
     90/*----------------------------------------------------------------------------*/
     91static int register_helper(endpoint_t *ep, void *arg)
     92{
     93        hcd_t *hcd = arg;
     94        assert(ep);
     95        assert(hcd);
     96        if (hcd->ep_add_hook)
     97                return hcd->ep_add_hook(hcd, ep);
     98        return EOK;
     99}
     100/*----------------------------------------------------------------------------*/
     101static void unregister_helper(endpoint_t *ep, void *arg)
     102{
     103        hcd_t *hcd = arg;
     104        assert(ep);
     105        assert(hcd);
     106        if (hcd->ep_remove_hook)
     107                hcd->ep_remove_hook(hcd, ep);
     108}
     109/*----------------------------------------------------------------------------*/
     110static void unregister_helper_warn(endpoint_t *ep, void *arg)
     111{
     112        hcd_t *hcd = arg;
     113        assert(ep);
     114        assert(hcd);
     115        usb_log_warning("Endpoint %d:%d %s was left behind, removing.\n",
     116            ep->address, ep->endpoint, usb_str_direction(ep->direction));
     117        if (hcd->ep_remove_hook)
     118                hcd->ep_remove_hook(hcd, ep);
    91119}
    92120/*----------------------------------------------------------------------------*/
     
    99127 */
    100128static int request_address(
    101     ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
     129    ddf_fun_t *fun, usb_address_t *address, bool strict, usb_speed_t speed)
    102130{
    103131        assert(fun);
     
    106134        assert(address);
    107135
    108         usb_log_debug("Address request speed: %s.\n", usb_str_speed(speed));
    109         *address =
    110             usb_device_manager_get_free_address(&hcd->dev_manager, speed);
    111         usb_log_debug("Address request with result: %d.\n", *address);
    112         if (*address <= 0)
    113                 return *address;
    114         return EOK;
     136        usb_log_debug("Address request: speed: %s, address: %d, strict: %s.\n",
     137            usb_str_speed(speed), *address, strict ? "YES" : "NO");
     138        return usb_device_manager_request_address(
     139            &hcd->dev_manager, address, strict, speed);
    115140}
    116141/*----------------------------------------------------------------------------*/
     
    130155
    131156        usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle);
    132         usb_device_manager_bind(&hcd->dev_manager, address, handle);
    133         return EOK;
     157        return usb_device_manager_bind_address(
     158            &hcd->dev_manager, address, handle);
    134159}
    135160/*----------------------------------------------------------------------------*/
     
    147172        hcd_t *hcd = fun_to_hcd(fun);
    148173        assert(hcd);
    149         const bool found =
    150             usb_device_manager_find_by_address(&hcd->dev_manager, address, handle);
    151         return found ? EOK : ENOENT;
     174        return usb_device_manager_get_info_by_address(
     175            &hcd->dev_manager, address, handle, NULL);
    152176}
    153177/*----------------------------------------------------------------------------*/
     
    164188        assert(hcd);
    165189        usb_log_debug("Address release %d.\n", address);
    166         usb_device_manager_release(&hcd->dev_manager, address);
     190        usb_device_manager_release_address(&hcd->dev_manager, address);
     191        usb_endpoint_manager_remove_address(&hcd->ep_manager, address,
     192            unregister_helper_warn, hcd);
    167193        return EOK;
    168194}
    169195/*----------------------------------------------------------------------------*/
    170196static int register_endpoint(
    171     ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed,
    172     usb_endpoint_t endpoint,
     197    ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
    173198    usb_transfer_type_t transfer_type, usb_direction_t direction,
    174199    size_t max_packet_size, unsigned int interval)
     
    178203        assert(hcd);
    179204        const size_t size = max_packet_size;
    180         /* Default address is not bound or registered,
    181          * thus it does not provide speed info. */
    182         const usb_speed_t speed = (address == 0) ? ep_speed :
    183             usb_device_manager_get_speed(&hcd->dev_manager, address);
     205        usb_speed_t speed = USB_SPEED_MAX;
     206        const int ret = usb_device_manager_get_info_by_address(
     207            &hcd->dev_manager, address, NULL, &speed);
     208        if (ret != EOK) {
     209                return ret;
     210        }
    184211
    185212        usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n",
     
    188215            max_packet_size, interval);
    189216
    190         endpoint_t *ep = endpoint_get(
    191             address, endpoint, direction, transfer_type, speed, max_packet_size);
    192         if (!ep)
    193                 return ENOMEM;
    194         int ret = EOK;
    195 
    196         if (hcd->ep_add_hook) {
    197                 ret = hcd->ep_add_hook(hcd, ep);
    198         }
    199         if (ret != EOK) {
    200                 endpoint_destroy(ep);
    201                 return ret;
    202         }
    203 
    204         ret = usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size);
    205         if (ret != EOK) {
    206                 endpoint_destroy(ep);
    207         }
    208         return ret;
     217        return usb_endpoint_manager_add_ep(&hcd->ep_manager, address, endpoint,
     218            direction, transfer_type, speed, max_packet_size, size,
     219            register_helper, hcd);
    209220}
    210221/*----------------------------------------------------------------------------*/
     
    218229        usb_log_debug("Unregister endpoint %d:%d %s.\n",
    219230            address, endpoint, usb_str_direction(direction));
    220         return usb_endpoint_manager_unregister_ep(&hcd->ep_manager, address,
    221             endpoint, direction);
     231        return usb_endpoint_manager_remove_ep(&hcd->ep_manager, address,
     232            endpoint, direction, unregister_helper, hcd);
    222233}
    223234/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.