Ignore:
File:
1 edited

Legend:

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

    r6b6fc232 r8b54fe6  
    4949        assert(hcd);
    5050
    51         endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager,
    52             target.address, target.endpoint, direction);
     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);
    5356        if (ep == NULL) {
    5457                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
     
    6265        const size_t bw = bandwidth_count_usb11(
    6366            ep->speed, ep->transfer_type, size, ep->max_packet_size);
    64         /* Check if we have enough bandwidth reserved */
    65         if (ep->bandwidth < bw) {
     67        if (res_bw < bw) {
    6668                usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
    6769                    "but only %zu is reserved.\n",
    68                     ep->address, ep->endpoint, name, bw, ep->bandwidth);
     70                    target.address, target.endpoint, name, bw, res_bw);
    6971                return ENOSPC;
    7072        }
     
    7678        /* No private data and no private data dtor */
    7779        usb_transfer_batch_t *batch =
    78             usb_transfer_batch_create(ep, data, size, setup_data,
     80            usb_transfer_batch_get(ep, data, size, setup_data,
    7981            in, out, arg, fun, NULL, NULL);
    8082        if (!batch) {
     
    8284        }
    8385
    84         const int ret = hcd->schedule(hcd, batch);
     86        ret = hcd->schedule(hcd, batch);
    8587        if (ret != EOK)
    86                 usb_transfer_batch_destroy(batch);
     88                usb_transfer_batch_dispose(batch);
    8789
    8890        return ret;
    89 }
    90 /*----------------------------------------------------------------------------*/
    91 static 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 /*----------------------------------------------------------------------------*/
    101 static 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 /*----------------------------------------------------------------------------*/
    110 static 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);
    11991}
    12092/*----------------------------------------------------------------------------*/
     
    12799 */
    128100static int request_address(
    129     ddf_fun_t *fun, usb_address_t *address, bool strict, usb_speed_t speed)
     101    ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
    130102{
    131103        assert(fun);
     
    134106        assert(address);
    135107
    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);
     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;
    140115}
    141116/*----------------------------------------------------------------------------*/
     
    155130
    156131        usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle);
    157         return usb_device_manager_bind_address(
    158             &hcd->dev_manager, address, handle);
     132        usb_device_manager_bind(&hcd->dev_manager, address, handle);
     133        return EOK;
    159134}
    160135/*----------------------------------------------------------------------------*/
     
    172147        hcd_t *hcd = fun_to_hcd(fun);
    173148        assert(hcd);
    174         return usb_device_manager_get_info_by_address(
    175             &hcd->dev_manager, address, handle, NULL);
     149        const bool found =
     150            usb_device_manager_find_by_address(&hcd->dev_manager, address, handle);
     151        return found ? EOK : ENOENT;
    176152}
    177153/*----------------------------------------------------------------------------*/
     
    188164        assert(hcd);
    189165        usb_log_debug("Address release %d.\n", 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);
     166        usb_device_manager_release(&hcd->dev_manager, address);
    193167        return EOK;
    194168}
    195169/*----------------------------------------------------------------------------*/
    196170static int register_endpoint(
    197     ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
     171    ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed,
     172    usb_endpoint_t endpoint,
    198173    usb_transfer_type_t transfer_type, usb_direction_t direction,
    199174    size_t max_packet_size, unsigned int interval)
     
    203178        assert(hcd);
    204179        const size_t size = max_packet_size;
    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         }
     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);
    211184
    212185        usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n",
     
    215188            max_packet_size, interval);
    216189
    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);
     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;
    220209}
    221210/*----------------------------------------------------------------------------*/
     
    229218        usb_log_debug("Unregister endpoint %d:%d %s.\n",
    230219            address, endpoint, usb_str_direction(direction));
    231         return usb_endpoint_manager_remove_ep(&hcd->ep_manager, address,
    232             endpoint, direction, unregister_helper, hcd);
     220        return usb_endpoint_manager_unregister_ep(&hcd->ep_manager, address,
     221            endpoint, direction);
    233222}
    234223/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.