Changeset ecbad17 in mainline


Ignore:
Timestamp:
2018-01-07T17:13: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:
eb928c4
Parents:
3dc3f99
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-07 17:12:35)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-07 17:13:57)
Message:

usbhost: Implemented bandwidth accounting for USB 2.0

Location:
uspace
Files:
3 edited

Legend:

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

    r3dc3f99 recbad17  
    149149        .endpoint_unregister = ehci_unregister_ep,
    150150        .endpoint_toggle_reset = ehci_ep_toggle_reset,
    151         .endpoint_count_bw = bandwidth_count_usb11,
     151        .endpoint_count_bw = bandwidth_count_usb20,
    152152        .batch_create = ehci_create_batch,
    153153        .batch_destroy = ehci_destroy_batch,
     
    163163        bus_t *bus_base = (bus_t *) bus;
    164164
    165         usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB11);
     165        usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB20);
    166166        bus_base->ops = &ehci_bus_ops;
    167167
  • uspace/lib/usbhost/include/usb/host/bandwidth.h

    r3dc3f99 recbad17  
    4444#define BANDWIDTH_TOTAL_USB11 (12000000 / 8)
    4545/** 90% of total bandwidth is available for periodic transfers */
    46 #define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 / 10) * 9)
     46#define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 * 9) / 10)
    4747
    48 //TODO: Implement
    49 #define BANDWIDTH_AVAILABLE_USB20  1
     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)
    5052
    5153typedef struct endpoint endpoint_t;
  • uspace/lib/usbhost/src/bandwidth.c

    r3dc3f99 recbad17  
    9696
    9797/** Calculate bandwidth that needs to be reserved for communication with EP.
    98  * Calculation follows USB 2.0 specification.
     98 * Calculation follows USB 2.0 specification, chapter 5.11.3.
     99 *
    99100 * @param speed Device's speed.
    100101 * @param type Type of the transfer.
    101102 * @param size Number of byte to transfer.
    102103 * @param max_packet_size Maximum bytes in one packet.
     104 * @return Number of nanoseconds transaction with @c size bytes payload will
     105 *         take.
    103106 */
    104107ssize_t bandwidth_count_usb20(endpoint_t *ep, size_t size)
     
    113116                return 0;
    114117        }
    115         //TODO Implement
    116         return 0;
     118
     119        // FIXME: Come up with some upper bound for these (in ns).
     120        const size_t host_delay = 0;
     121        const size_t hub_ls_setup = 0;
     122
     123        // Approx. Floor(3.167 + BitStuffTime(Data_bc))
     124        const size_t base_time = (size * 8 + 19) / 6;
     125
     126        switch (ep->device->speed) {
     127        case USB_SPEED_LOW:
     128                if (ep->direction == USB_DIRECTION_IN)
     129                        return 64060 + (2 * hub_ls_setup) + (677 * base_time) + host_delay;
     130                else
     131                        return 64107 + (2 * hub_ls_setup) + (667 * base_time) + host_delay;
     132
     133        case USB_SPEED_FULL:
     134                if (ep->transfer_type == USB_TRANSFER_INTERRUPT)
     135                        return 9107 + 84 * base_time + host_delay;
     136
     137                if (ep->direction == USB_DIRECTION_IN)
     138                        return 7268 + 84 * base_time + host_delay;
     139                else
     140                        return 6265 + 84 * base_time + host_delay;
     141
     142        case USB_SPEED_HIGH:
     143                if (ep->transfer_type == USB_TRANSFER_INTERRUPT)
     144                        return (3648 + 25 * base_time + 11) / 12 + host_delay;
     145                else
     146                        return (5280 + 25 * base_time + 11) / 12 + host_delay;
     147
     148        default:
     149                return 0;
     150        }
    117151}
Note: See TracChangeset for help on using the changeset viewer.