Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/iface.c

    rc61338a r92d6868  
    3636
    3737#include <usb/debug.h>
     38#include <usb/host/endpoint.h>
    3839
    3940#include "iface.h"
     
    5455        usb_device_keeper_reserve_default_address(&hc->manager, speed);
    5556        return EOK;
     57#if 0
     58        endpoint_t *ep = malloc(sizeof(endpoint_t));
     59        if (ep == NULL)
     60                return ENOMEM;
     61        const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64;
     62        endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size);
     63        int ret;
     64try_retgister:
     65        ret = usb_endpoint_manager_register_ep(&hc->ep_manager,
     66            USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0);
     67        if (ret == EEXISTS) {
     68                async_usleep(1000);
     69                goto try_retgister;
     70        }
     71        if (ret != EOK) {
     72                endpoint_destroy(ep);
     73        }
     74        return ret;
     75#endif
    5676}
    5777/*----------------------------------------------------------------------------*/
     
    6787        assert(hc);
    6888        usb_log_debug("Default address release.\n");
     89//      return usb_endpoint_manager_unregister_ep(&hc->ep_manager,
     90//          USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH);
    6991        usb_device_keeper_release_default_address(&hc->manager);
    7092        return EOK;
     
    128150}
    129151/*----------------------------------------------------------------------------*/
     152static int register_endpoint(
     153    ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
     154    usb_transfer_type_t transfer_type, usb_direction_t direction,
     155    size_t max_packet_size, unsigned int interval)
     156{
     157        hc_t *hc = fun_to_hc(fun);
     158        assert(hc);
     159        const usb_speed_t speed =
     160            usb_device_keeper_get_speed(&hc->manager, address);
     161        const size_t size =
     162            (transfer_type == USB_TRANSFER_INTERRUPT
     163            || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
     164            max_packet_size : 0;
     165        int ret;
     166
     167        endpoint_t *ep = malloc(sizeof(endpoint_t));
     168        if (ep == NULL)
     169                return ENOMEM;
     170        ret = endpoint_init(ep, address, endpoint, direction,
     171            transfer_type, speed, max_packet_size);
     172        if (ret != EOK) {
     173                free(ep);
     174                return ret;
     175        }
     176
     177        usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
     178            address, endpoint, usb_str_transfer_type(transfer_type),
     179            usb_str_speed(speed), direction, size, max_packet_size, interval);
     180
     181        ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
     182        if (ret != EOK) {
     183                endpoint_destroy(ep);
     184        } else {
     185                usb_device_keeper_add_ep(&hc->manager, address, ep);
     186        }
     187        return ret;
     188}
     189/*----------------------------------------------------------------------------*/
     190static int unregister_endpoint(
     191    ddf_fun_t *fun, usb_address_t address,
     192    usb_endpoint_t endpoint, usb_direction_t direction)
     193{
     194        hc_t *hc = fun_to_hc(fun);
     195        assert(hc);
     196        usb_log_debug("Unregister endpoint %d:%d %d.\n",
     197            address, endpoint, direction);
     198        return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
     199            endpoint, direction);
     200}
     201/*----------------------------------------------------------------------------*/
    130202/** Interrupt out transaction interface function
    131203 *
     
    146218        hc_t *hc = fun_to_hc(fun);
    147219        assert(hc);
    148         usb_speed_t speed =
    149             usb_device_keeper_get_speed(&hc->manager, target.address);
    150220
    151221        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    152222            target.address, target.endpoint, size, max_packet_size);
    153223
     224        size_t res_bw;
     225        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     226            target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw);
     227        if (ep == NULL) {
     228                usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n",
     229                        target.address, target.endpoint);
     230                return ENOENT;
     231        }
     232        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     233            size, ep->max_packet_size);
     234        if (res_bw < bw)
     235        {
     236                usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
     237                    "but only %zu is reserved.\n",
     238                    target.address, target.endpoint, bw, res_bw);
     239                return ENOENT;
     240        }
     241        assert(ep->speed ==
     242            usb_device_keeper_get_speed(&hc->manager, target.address));
     243        assert(ep->max_packet_size == max_packet_size);
     244        assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
     245
    154246        usb_transfer_batch_t *batch =
    155             batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
    156                 speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     247            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     248                ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
    157249        if (!batch)
    158250                return ENOMEM;
     
    183275        hc_t *hc = fun_to_hc(fun);
    184276        assert(hc);
    185         usb_speed_t speed =
    186             usb_device_keeper_get_speed(&hc->manager, target.address);
     277
    187278        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    188279            target.address, target.endpoint, size, max_packet_size);
    189280
     281        size_t res_bw;
     282        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     283            target.address, target.endpoint, USB_DIRECTION_IN, &res_bw);
     284        if (ep == NULL) {
     285                usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n",
     286                    target.address, target.endpoint);
     287                return ENOENT;
     288        }
     289        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     290            size, ep->max_packet_size);
     291        if (res_bw < bw)
     292        {
     293                usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
     294                    "but only %zu bw is reserved.\n",
     295                    target.address, target.endpoint, bw, res_bw);
     296                return ENOENT;
     297        }
     298
     299        assert(ep->speed ==
     300            usb_device_keeper_get_speed(&hc->manager, target.address));
     301        assert(ep->max_packet_size == max_packet_size);
     302        assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
     303
    190304        usb_transfer_batch_t *batch =
    191             batch_get(fun, target, USB_TRANSFER_INTERRUPT, max_packet_size,
    192                 speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     305            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     306                ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
    193307        if (!batch)
    194308                return ENOMEM;
     
    219333        hc_t *hc = fun_to_hc(fun);
    220334        assert(hc);
    221         usb_speed_t speed =
    222             usb_device_keeper_get_speed(&hc->manager, target.address);
    223335
    224336        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    225337            target.address, target.endpoint, size, max_packet_size);
    226338
     339        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     340            target.address, target.endpoint, USB_DIRECTION_OUT, NULL);
     341        if (ep == NULL) {
     342                usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n",
     343                        target.address, target.endpoint);
     344                return ENOENT;
     345        }
     346        assert(ep->speed ==
     347            usb_device_keeper_get_speed(&hc->manager, target.address));
     348        assert(ep->max_packet_size == max_packet_size);
     349        assert(ep->transfer_type == USB_TRANSFER_BULK);
     350
    227351        usb_transfer_batch_t *batch =
    228             batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
    229                 data, size, NULL, 0, NULL, callback, arg, &hc->manager);
     352            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     353                ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
    230354        if (!batch)
    231355                return ENOMEM;
     
    256380        hc_t *hc = fun_to_hc(fun);
    257381        assert(hc);
    258         usb_speed_t speed =
    259             usb_device_keeper_get_speed(&hc->manager, target.address);
    260382        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    261383            target.address, target.endpoint, size, max_packet_size);
    262384
     385        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     386            target.address, target.endpoint, USB_DIRECTION_IN, NULL);
     387        if (ep == NULL) {
     388                usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n",
     389                        target.address, target.endpoint);
     390                return ENOENT;
     391        }
     392        assert(ep->speed ==
     393            usb_device_keeper_get_speed(&hc->manager, target.address));
     394        assert(ep->max_packet_size == max_packet_size);
     395        assert(ep->transfer_type == USB_TRANSFER_BULK);
     396
    263397        usb_transfer_batch_t *batch =
    264             batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,
    265                 data, size, NULL, 0, callback, NULL, arg, &hc->manager);
     398            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     399                ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
    266400        if (!batch)
    267401                return ENOMEM;
     
    299433        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    300434            speed, target.address, target.endpoint, size, max_packet_size);
     435        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     436            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
     437        if (ep == NULL) {
     438                usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
     439                        target.address, target.endpoint);
     440        }
    301441
    302442        if (setup_size != 8)
     
    305445        usb_transfer_batch_t *batch =
    306446            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
    307                 data, size, setup_data, setup_size, NULL, callback, arg,
    308                 &hc->manager);
     447                data, size, setup_data, setup_size, NULL, callback, arg, ep);
    309448        if (!batch)
    310449                return ENOMEM;
     
    344483        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    345484            speed, target.address, target.endpoint, size, max_packet_size);
     485        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     486            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
     487        if (ep == NULL) {
     488                usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
     489                        target.address, target.endpoint);
     490        }
    346491        usb_transfer_batch_t *batch =
    347492            batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed,
    348                 data, size, setup_data, setup_size, callback, NULL, arg,
    349                 &hc->manager);
     493                data, size, setup_data, setup_size, callback, NULL, arg, ep);
    350494        if (!batch)
    351495                return ENOMEM;
     
    365509        .release_address = release_address,
    366510
     511        .register_endpoint = register_endpoint,
     512        .unregister_endpoint = unregister_endpoint,
     513
    367514        .interrupt_out = interrupt_out,
    368515        .interrupt_in = interrupt_in,
Note: See TracChangeset for help on using the changeset viewer.