Changeset b357377 in mainline


Ignore:
Timestamp:
2018-01-25T02:05:57Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d369b3b
Parents:
5f0b366
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-25 01:23:20)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-25 02:05:57)
Message:

usbhost: make bandwidth accounting a usb2_bus-thing

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/ehci_bus.c

    r5f0b366 rb357377  
    163163        .endpoint_register = ehci_register_ep,
    164164        .endpoint_unregister = ehci_unregister_ep,
    165         .endpoint_count_bw = bandwidth_count_usb20,
    166165
    167166        .batch_create = ehci_create_batch,
     
    178177        bus_t *bus_base = (bus_t *) bus;
    179178
    180         usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB20);
     179        usb2_bus_init(usb2_bus, &bandwidth_accounting_usb2);
    181180        bus_base->ops = &ehci_bus_ops;
    182181
  • uspace/drv/bus/usb/ohci/ohci_bus.c

    r5f0b366 rb357377  
    171171        .endpoint_register = ohci_register_ep,
    172172        .endpoint_unregister = ohci_unregister_ep,
    173         .endpoint_count_bw = bandwidth_count_usb11,
    174173
    175174        .batch_create = ohci_create_batch,
     
    187186        bus_t *bus_base = (bus_t *) bus;
    188187
    189         usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB11);
     188        usb2_bus_init(usb2_bus, &bandwidth_accounting_usb11);
    190189        bus_base->ops = &ohci_bus_ops;
    191190
  • uspace/drv/bus/usb/uhci/hc.c

    r5f0b366 rb357377  
    418418        .endpoint_register = endpoint_register,
    419419        .endpoint_unregister = endpoint_unregister,
    420         .endpoint_count_bw = bandwidth_count_usb11,
    421420
    422421        .batch_create = create_transfer_batch,
     
    439438        assert(instance);
    440439
    441         usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);
     440        usb2_bus_init(&instance->bus, &bandwidth_accounting_usb11);
    442441
    443442        bus_t *bus = (bus_t *) &instance->bus;
  • uspace/drv/bus/usb/vhc/transfer.c

    r5f0b366 rb357377  
    166166        .parent = &usb2_bus_ops,
    167167
    168         .endpoint_count_bw = bandwidth_count_usb11,
    169168        .batch_create = batch_create,
    170169        .batch_schedule = vhc_schedule,
     
    176175        list_initialize(&instance->devices);
    177176        fibril_mutex_initialize(&instance->guard);
    178         usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);
     177        usb2_bus_init(&instance->bus, &bandwidth_accounting_usb11);
    179178        instance->bus.base.ops = &vhc_bus_ops;
    180179        return virthub_init(&instance->hub, "root hub");
  • uspace/lib/usbhost/include/usb/host/bandwidth.h

    r5f0b366 rb357377  
    4141#include <stddef.h>
    4242
    43 /** Bytes per second in FULL SPEED */
    44 #define BANDWIDTH_TOTAL_USB11 (12000000 / 8)
    45 /** 90% of total bandwidth is available for periodic transfers */
    46 #define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 * 9) / 10)
    47 
    48 /** Number of nanoseconds in one microframe */
    49 #define BANDWIDTH_TOTAL_USB20 (125000)
    50 /** 90% of total bandwidth is available for periodic transfers */
    51 #define BANDWIDTH_AVAILABLE_USB20  ((BANDWIDTH_TOTAL_USB20 * 9) / 10)
    52 
    5343typedef struct endpoint endpoint_t;
    5444
    55 extern ssize_t bandwidth_count_usb11(endpoint_t *, size_t);
     45typedef size_t (*endpoint_count_bw_t)(endpoint_t *);
    5646
    57 extern ssize_t bandwidth_count_usb20(endpoint_t *, size_t);
     47typedef struct {
     48        size_t available_bandwidth;
     49        endpoint_count_bw_t count_bw;
     50} bandwidth_accounting_t;
     51
     52extern const bandwidth_accounting_t bandwidth_accounting_usb11;
     53extern const bandwidth_accounting_t bandwidth_accounting_usb2;
    5854
    5955#endif
  • uspace/lib/usbhost/include/usb/host/bus.h

    r5f0b366 rb357377  
    120120        void (*endpoint_unregister)(endpoint_t *);
    121121        void (*endpoint_destroy)(endpoint_t *);                 /**< Optional */
    122         ssize_t (*endpoint_count_bw) (endpoint_t *, size_t);    /**< Optional */
    123122        usb_transfer_batch_t *(*batch_create)(endpoint_t *);    /**< Optional */
    124123
  • uspace/lib/usbhost/include/usb/host/usb2_bus.h

    r5f0b366 rb357377  
    4242
    4343#include <usb/host/bus.h>
     44#include <usb/host/bandwidth.h>
    4445
    4546typedef struct usb2_bus usb2_bus_t;
     
    5758        /** Size of the bandwidth pool */
    5859        size_t free_bw;
     60
     61        /* Configured bandwidth accounting */
     62        const bandwidth_accounting_t *bw_accounting;
    5963} usb2_bus_t;
    6064
    6165extern const bus_ops_t usb2_bus_ops;
    6266
    63 extern void usb2_bus_init(usb2_bus_t *, size_t);
     67extern void usb2_bus_init(usb2_bus_t *, const bandwidth_accounting_t *);
    6468
    6569#endif
  • uspace/lib/usbhost/src/bandwidth.c

    r5f0b366 rb357377  
    4242#include "bandwidth.h"
    4343
     44/** Bytes per second in FULL SPEED */
     45#define BANDWIDTH_TOTAL_USB11 (12000000 / 8)
     46/** 90% of total bandwidth is available for periodic transfers */
     47#define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 * 9) / 10)
     48
    4449/**
    4550 * Calculate bandwidth that needs to be reserved for communication with EP.
    4651 * Calculation follows USB 1.1 specification.
    47  * @param ep Registered endpoint
    48  * @param size Number of bytes to transfer.
    49  * @param max_packet_size Maximum bytes in one packet.
     52 *
     53 * @param ep An endpoint for which the bandwidth is to be counted
    5054 */
    51 ssize_t bandwidth_count_usb11(endpoint_t *ep, size_t size)
     55static size_t bandwidth_count_usb11(endpoint_t *ep)
    5256{
    5357        assert(ep);
     
    6367
    6468        const size_t max_packet_size = ep->max_packet_size;
     69        const size_t packet_count = ep->packets_per_uframe;
    6570
    66         const unsigned packet_count =
    67             (size + max_packet_size - 1) / max_packet_size;
    6871        /* TODO: It may be that ISO and INT transfers use only one packet per
    6972         * transaction, but I did not find text in USB spec to confirm this */
     
    9699}
    97100
    98 /**
     101const bandwidth_accounting_t bandwidth_accounting_usb11 = {
     102        .available_bandwidth = BANDWIDTH_AVAILABLE_USB11,
     103        .count_bw = &bandwidth_count_usb11,
     104};
     105
     106/** Number of nanoseconds in one microframe */
     107#define BANDWIDTH_TOTAL_USB2 (125000)
     108/** 90% of total bandwidth is available for periodic transfers */
     109#define BANDWIDTH_AVAILABLE_USB2  ((BANDWIDTH_TOTAL_USB2 * 9) / 10)
     110
     111/**
    99112 * Calculate bandwidth that needs to be reserved for communication with EP.
    100113 * Calculation follows USB 2.0 specification, chapter 5.11.3.
    101114 *
    102  * @param speed Device's speed.
    103  * @param type Type of the transfer.
    104  * @param size Number of byte to transfer.
    105  * @param max_packet_size Maximum bytes in one packet.
     115 * FIXME: Interrupt transfers shall be probably divided by their polling interval.
     116 *
     117 * @param ep An endpoint for which the bandwidth is to be counted
    106118 * @return Number of nanoseconds transaction with @c size bytes payload will
    107119 *         take.
    108120 */
    109 ssize_t bandwidth_count_usb20(endpoint_t *ep, size_t size)
     121static size_t bandwidth_count_usb2(endpoint_t *ep)
    110122{
    111123        assert(ep);
     124        assert(ep->device);
    112125
    113126        const usb_transfer_type_t type = ep->transfer_type;
     
    124137
    125138        // Approx. Floor(3.167 + BitStuffTime(Data_bc))
    126         const size_t base_time = (size * 8 + 19) / 6;
     139        const size_t base_time = (ep->max_transfer_size * 8 + 19) / 6;
    127140
    128141        switch (ep->device->speed) {
     
    152165        }
    153166}
     167
     168const bandwidth_accounting_t bandwidth_accounting_usb2 = {
     169        .available_bandwidth = BANDWIDTH_AVAILABLE_USB2,
     170        .count_bw = &bandwidth_count_usb2,
     171};
  • uspace/lib/usbhost/src/usb2_bus.c

    r5f0b366 rb357377  
    219219        assert(ep);
    220220
    221         bus_t *bus = ep->device->bus;
    222         const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, endpoint_count_bw);
    223         if (!ops)
    224                 return 0;
    225 
    226         return ops->endpoint_count_bw(ep, ep->max_transfer_size);
     221        usb2_bus_t *bus = bus_to_usb2_bus(ep->device->bus);
     222
     223        return bus->bw_accounting->count_bw(ep);
    227224}
    228225
     
    269266 * @param available_bandwidth Size of the bandwidth pool.
    270267 */
    271 void usb2_bus_init(usb2_bus_t *bus, size_t available_bandwidth)
     268void usb2_bus_init(usb2_bus_t *bus, const bandwidth_accounting_t *bw_accounting)
    272269{
    273270        assert(bus);
     271        assert(bw_accounting);
    274272
    275273        bus_init(&bus->base, sizeof(device_t));
    276274        bus->base.ops = &usb2_bus_ops;
    277275
    278         bus->free_bw = available_bandwidth;
     276        bus->bw_accounting = bw_accounting;
     277        bus->free_bw = bw_accounting->available_bandwidth;
    279278
    280279        /*
Note: See TracChangeset for help on using the changeset viewer.