Changeset b357377 in mainline for uspace/lib/usbhost/src


Ignore:
Timestamp:
2018-01-25T02:05:57Z (7 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/lib/usbhost/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.