Changeset 83c3123 in mainline


Ignore:
Timestamp:
2011-10-27T11:40:06Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7265558
Parents:
4267908
Message:

libusbhost: Store bandwidth in endpoint structure.

Remove redundant node_t tructure and use endpoint_t directly.

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/vhc/connhost.c

    r4267908 r83c3123  
    143143        VHC_DATA(vhc, fun);
    144144
    145         endpoint_t *ep = endpoint_get(
    146             address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1);
     145        endpoint_t *ep = endpoint_create(
     146            address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1, 0);
    147147        if (ep == NULL) {
    148148                return ENOMEM;
     
    414414
    415415        endpoint_t *ep = usb_endpoint_manager_get_ep(&vhc->ep_manager,
    416             target.address, target.endpoint, USB_DIRECTION_IN, NULL);
     416            target.address, target.endpoint, USB_DIRECTION_IN);
    417417        if (ep == NULL) {
    418418                return ENOENT;
     
    456456
    457457        endpoint_t *ep = usb_endpoint_manager_get_ep(&vhc->ep_manager,
    458             target.address, target.endpoint, USB_DIRECTION_OUT, NULL);
     458            target.address, target.endpoint, USB_DIRECTION_OUT);
    459459        if (ep == NULL) {
    460460                return ENOENT;
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r4267908 r83c3123  
    3636#define LIBUSBHOST_HOST_ENDPOINT_H
    3737
    38 #include <assert.h>
    3938#include <bool.h>
    4039#include <adt/list.h>
    4140#include <fibril_synch.h>
    42 
    4341#include <usb/usb.h>
    4442
    4543typedef struct endpoint {
     44        link_t link;
    4645        usb_address_t address;
    4746        usb_endpoint_t endpoint;
     
    5049        usb_speed_t speed;
    5150        size_t max_packet_size;
     51        size_t bandwidth;
    5252        unsigned toggle:1;
    5353        fibril_mutex_t guard;
     
    6262} endpoint_t;
    6363
    64 endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint,
     64endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
    6565    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    66     size_t max_packet_size);
    67 
     66    size_t max_packet_size, size_t bw);
    6867void endpoint_destroy(endpoint_t *instance);
    6968
     
    7170    void *data, void (*destroy_hook)(endpoint_t *),
    7271    int (*toggle_get)(void *), void (*toggle_set)(void *, int));
    73 
    7472void endpoint_clear_hc_data(endpoint_t *instance);
    7573
    7674void endpoint_use(endpoint_t *instance);
    77 
    7875void endpoint_release(endpoint_t *instance);
    7976
    8077int endpoint_toggle_get(endpoint_t *instance);
    81 
    8278void endpoint_toggle_set(endpoint_t *instance, int toggle);
    83 
    8479void endpoint_toggle_reset_filtered(endpoint_t *instance, usb_target_t target);
    8580#endif
  • uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h

    r4267908 r83c3123  
    7272
    7373endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
    74     usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,
    75     size_t *bw);
     74    usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
    7675
    7776void usb_endpoint_manager_reset_if_need(
     
    8483    size_t data_size)
    8584{
    86         endpoint_t *ep = endpoint_get(
    87             address, endpoint, direction, type, speed, max_packet_size);
     85        assert(instance);
     86        const size_t bw =
     87            instance->bw_count(speed, type, data_size, max_packet_size);
     88
     89        endpoint_t *ep = endpoint_create(
     90            address, endpoint, direction, type, speed, max_packet_size, bw);
    8891        if (!ep)
    8992                return ENOMEM;
  • uspace/lib/usbhost/src/endpoint.c

    r4267908 r83c3123  
    3939#include <usb/host/endpoint.h>
    4040
    41 endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint,
     41endpoint_t * endpoint_create(usb_address_t address, usb_endpoint_t endpoint,
    4242    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    43     size_t max_packet_size)
     43    size_t max_packet_size, size_t bw)
    4444{
    4545        endpoint_t *instance = malloc(sizeof(endpoint_t));
     
    5151                instance->speed = speed;
    5252                instance->max_packet_size = max_packet_size;
     53                instance->bandwidth = bw;
    5354                instance->toggle = 0;
    5455                instance->active = false;
     
    5758                instance->hc_data.toggle_get = NULL;
    5859                instance->hc_data.toggle_set = NULL;
     60                link_initialize(&instance->link);
    5961                fibril_mutex_initialize(&instance->guard);
    6062                fibril_condvar_initialize(&instance->avail);
  • uspace/lib/usbhost/src/iface.c

    r4267908 r83c3123  
    4949        assert(hcd);
    5050
    51         int ret;
    52 
    53         size_t res_bw;
    5451        endpoint_t *ep = usb_endpoint_manager_get_ep(&hcd->ep_manager,
    55             target.address, target.endpoint, direction, &res_bw);
     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        }
     
    8482        }
    8583
    86         ret = hcd->schedule(hcd, batch);
     84        const int ret = hcd->schedule(hcd, batch);
    8785        if (ret != EOK)
    8886                usb_transfer_batch_dispose(batch);
     
    190188            max_packet_size, interval);
    191189
    192         endpoint_t *ep = endpoint_get(
    193             address, endpoint, direction, transfer_type, speed, max_packet_size);
     190        endpoint_t *ep =
     191            endpoint_create(address, endpoint, direction, transfer_type,
     192                speed, max_packet_size, 0);
    194193        if (!ep)
    195194                return ENOMEM;
  • uspace/lib/usbhost/src/usb_endpoint_manager.c

    r4267908 r83c3123  
    3535
    3636#define BUCKET_COUNT 7
    37 
    3837#define MAX_KEYS (3)
    39 typedef struct {
    40         link_t link;
    41         size_t bw;
    42         endpoint_t *ep;
    43 } node_t;
    44 /*----------------------------------------------------------------------------*/
    45 static hash_index_t node_hash(unsigned long key[])
     38
     39static hash_index_t usb_hash(unsigned long key[])
    4640{
    4741        /* USB endpoints use 4 bits, thus ((key[0] << 4) | key[1])
     
    5044}
    5145/*----------------------------------------------------------------------------*/
    52 static int node_compare(unsigned long key[], hash_count_t keys, link_t *item)
     46static int ep_compare(unsigned long key[], hash_count_t keys, link_t *item)
    5347{
    5448        assert(item);
    55         node_t *node = hash_table_get_instance(item, node_t, link);
    56         assert(node);
    57         assert(node->ep);
     49        endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link);
     50        assert(ep);
    5851        bool match = true;
    5952        switch (keys) {
    6053        case 3:
    6154                match = match &&
    62                     ((key[2] == node->ep->direction)
    63                     || (node->ep->direction == USB_DIRECTION_BOTH));
     55                    ((key[2] == ep->direction)
     56                    || (ep->direction == USB_DIRECTION_BOTH)
     57                    || (key[2] == USB_DIRECTION_BOTH));
    6458        case 2:
    65                 match = match && (key[1] == (unsigned long)node->ep->endpoint);
     59                match = match && (key[1] == (unsigned long)ep->endpoint);
    6660        case 1:
    67                 match = match && (key[0] == (unsigned long)node->ep->address);
     61                match = match && (key[0] == (unsigned long)ep->address);
    6862                break;
    6963        default:
     
    7367}
    7468/*----------------------------------------------------------------------------*/
    75 static void node_remove(link_t *item)
     69static void ep_remove(link_t *item)
    7670{
    7771        assert(item);
    78         node_t *node = hash_table_get_instance(item, node_t, link);
    79         endpoint_destroy(node->ep);
    80         free(node);
    81 }
    82 /*----------------------------------------------------------------------------*/
    83 static void node_toggle_reset_filtered(link_t *item, void *arg)
     72        endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link);
     73        endpoint_destroy(ep);
     74}
     75/*----------------------------------------------------------------------------*/
     76static void toggle_reset_filtered(link_t *item, void *arg)
    8477{
    8578        assert(item);
    86         node_t *node = hash_table_get_instance(item, node_t, link);
    87         usb_target_t *target = arg;
    88         endpoint_toggle_reset_filtered(node->ep, *target);
     79        endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link);
     80        const usb_target_t *target = arg;
     81        endpoint_toggle_reset_filtered(ep, *target);
    8982}
    9083/*----------------------------------------------------------------------------*/
    9184static hash_table_operations_t op = {
    92         .hash = node_hash,
    93         .compare = node_compare,
    94         .remove_callback = node_remove,
     85        .hash = usb_hash,
     86        .compare = ep_compare,
     87        .remove_callback = ep_remove,
    9588};
    9689/*----------------------------------------------------------------------------*/
     
    161154        assert(instance->bw_count);
    162155        assert(ep);
    163         const size_t bw = instance->bw_count(ep->speed, ep->transfer_type,
     156        ep->bandwidth = instance->bw_count(ep->speed, ep->transfer_type,
    164157            data_size, ep->max_packet_size);
    165158
    166159        fibril_mutex_lock(&instance->guard);
    167160
    168         if (bw > instance->free_bw) {
     161        if (ep->bandwidth > instance->free_bw) {
    169162                fibril_mutex_unlock(&instance->guard);
    170163                return ENOSPC;
     
    181174        }
    182175
    183         node_t *node = malloc(sizeof(node_t));
    184         if (node == NULL) {
    185                 fibril_mutex_unlock(&instance->guard);
    186                 return ENOMEM;
    187         }
    188 
    189         node->bw = bw;
    190         node->ep = ep;
    191         link_initialize(&node->link);
    192 
    193         hash_table_insert(&instance->ep_table, key, &node->link);
    194         instance->free_bw -= bw;
     176        hash_table_insert(&instance->ep_table, key, &ep->link);
     177        instance->free_bw -= ep->bandwidth;
    195178        fibril_mutex_unlock(&instance->guard);
    196179        return EOK;
     
    210193        }
    211194
    212         node_t *node = hash_table_get_instance(item, node_t, link);
    213         if (node->ep->active) {
     195        endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link);
     196        if (ep->active) {
    214197                fibril_mutex_unlock(&instance->guard);
    215198                return EBUSY;
    216199        }
    217200
    218         instance->free_bw += node->bw;
     201        instance->free_bw += ep->bandwidth;
    219202        hash_table_remove(&instance->ep_table, key, MAX_KEYS);
    220203
     
    224207/*----------------------------------------------------------------------------*/
    225208endpoint_t * usb_endpoint_manager_get_ep(usb_endpoint_manager_t *instance,
    226     usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
    227     size_t *bw)
     209    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction)
    228210{
    229211        assert(instance);
     
    236218                return NULL;
    237219        }
    238         const node_t *node = hash_table_get_instance(item, node_t, link);
    239         if (bw)
    240                 *bw = node->bw;
     220        endpoint_t *ep = hash_table_get_instance(item, endpoint_t, link);
    241221
    242222        fibril_mutex_unlock(&instance->guard);
    243         return node->ep;
     223        return ep;
    244224}
    245225/*----------------------------------------------------------------------------*/
     
    272252                        fibril_mutex_lock(&instance->guard);
    273253                        hash_table_apply(&instance->ep_table,
    274                             node_toggle_reset_filtered, &reset_target);
     254                            toggle_reset_filtered, &reset_target);
    275255                        fibril_mutex_unlock(&instance->guard);
    276256                }
     
    285265                        fibril_mutex_lock(&instance->guard);
    286266                        hash_table_apply(&instance->ep_table,
    287                             node_toggle_reset_filtered, &reset_target);
     267                            toggle_reset_filtered, &reset_target);
    288268                        fibril_mutex_unlock(&instance->guard);
    289269                }
Note: See TracChangeset for help on using the changeset viewer.