Changeset b357377 in mainline
- Timestamp:
- 2018-01-25T02:05:57Z (7 years ago)
- 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)
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ehci/ehci_bus.c
r5f0b366 rb357377 163 163 .endpoint_register = ehci_register_ep, 164 164 .endpoint_unregister = ehci_unregister_ep, 165 .endpoint_count_bw = bandwidth_count_usb20,166 165 167 166 .batch_create = ehci_create_batch, … … 178 177 bus_t *bus_base = (bus_t *) bus; 179 178 180 usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB20);179 usb2_bus_init(usb2_bus, &bandwidth_accounting_usb2); 181 180 bus_base->ops = &ehci_bus_ops; 182 181 -
uspace/drv/bus/usb/ohci/ohci_bus.c
r5f0b366 rb357377 171 171 .endpoint_register = ohci_register_ep, 172 172 .endpoint_unregister = ohci_unregister_ep, 173 .endpoint_count_bw = bandwidth_count_usb11,174 173 175 174 .batch_create = ohci_create_batch, … … 187 186 bus_t *bus_base = (bus_t *) bus; 188 187 189 usb2_bus_init(usb2_bus, BANDWIDTH_AVAILABLE_USB11);188 usb2_bus_init(usb2_bus, &bandwidth_accounting_usb11); 190 189 bus_base->ops = &ohci_bus_ops; 191 190 -
uspace/drv/bus/usb/uhci/hc.c
r5f0b366 rb357377 418 418 .endpoint_register = endpoint_register, 419 419 .endpoint_unregister = endpoint_unregister, 420 .endpoint_count_bw = bandwidth_count_usb11,421 420 422 421 .batch_create = create_transfer_batch, … … 439 438 assert(instance); 440 439 441 usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);440 usb2_bus_init(&instance->bus, &bandwidth_accounting_usb11); 442 441 443 442 bus_t *bus = (bus_t *) &instance->bus; -
uspace/drv/bus/usb/vhc/transfer.c
r5f0b366 rb357377 166 166 .parent = &usb2_bus_ops, 167 167 168 .endpoint_count_bw = bandwidth_count_usb11,169 168 .batch_create = batch_create, 170 169 .batch_schedule = vhc_schedule, … … 176 175 list_initialize(&instance->devices); 177 176 fibril_mutex_initialize(&instance->guard); 178 usb2_bus_init(&instance->bus, BANDWIDTH_AVAILABLE_USB11);177 usb2_bus_init(&instance->bus, &bandwidth_accounting_usb11); 179 178 instance->bus.base.ops = &vhc_bus_ops; 180 179 return virthub_init(&instance->hub, "root hub"); -
uspace/lib/usbhost/include/usb/host/bandwidth.h
r5f0b366 rb357377 41 41 #include <stddef.h> 42 42 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 53 43 typedef struct endpoint endpoint_t; 54 44 55 extern ssize_t bandwidth_count_usb11(endpoint_t *, size_t);45 typedef size_t (*endpoint_count_bw_t)(endpoint_t *); 56 46 57 extern ssize_t bandwidth_count_usb20(endpoint_t *, size_t); 47 typedef struct { 48 size_t available_bandwidth; 49 endpoint_count_bw_t count_bw; 50 } bandwidth_accounting_t; 51 52 extern const bandwidth_accounting_t bandwidth_accounting_usb11; 53 extern const bandwidth_accounting_t bandwidth_accounting_usb2; 58 54 59 55 #endif -
uspace/lib/usbhost/include/usb/host/bus.h
r5f0b366 rb357377 120 120 void (*endpoint_unregister)(endpoint_t *); 121 121 void (*endpoint_destroy)(endpoint_t *); /**< Optional */ 122 ssize_t (*endpoint_count_bw) (endpoint_t *, size_t); /**< Optional */123 122 usb_transfer_batch_t *(*batch_create)(endpoint_t *); /**< Optional */ 124 123 -
uspace/lib/usbhost/include/usb/host/usb2_bus.h
r5f0b366 rb357377 42 42 43 43 #include <usb/host/bus.h> 44 #include <usb/host/bandwidth.h> 44 45 45 46 typedef struct usb2_bus usb2_bus_t; … … 57 58 /** Size of the bandwidth pool */ 58 59 size_t free_bw; 60 61 /* Configured bandwidth accounting */ 62 const bandwidth_accounting_t *bw_accounting; 59 63 } usb2_bus_t; 60 64 61 65 extern const bus_ops_t usb2_bus_ops; 62 66 63 extern void usb2_bus_init(usb2_bus_t *, size_t);67 extern void usb2_bus_init(usb2_bus_t *, const bandwidth_accounting_t *); 64 68 65 69 #endif -
uspace/lib/usbhost/src/bandwidth.c
r5f0b366 rb357377 42 42 #include "bandwidth.h" 43 43 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 44 49 /** 45 50 * Calculate bandwidth that needs to be reserved for communication with EP. 46 51 * 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 50 54 */ 51 s size_t bandwidth_count_usb11(endpoint_t *ep, size_t size)55 static size_t bandwidth_count_usb11(endpoint_t *ep) 52 56 { 53 57 assert(ep); … … 63 67 64 68 const size_t max_packet_size = ep->max_packet_size; 69 const size_t packet_count = ep->packets_per_uframe; 65 70 66 const unsigned packet_count =67 (size + max_packet_size - 1) / max_packet_size;68 71 /* TODO: It may be that ISO and INT transfers use only one packet per 69 72 * transaction, but I did not find text in USB spec to confirm this */ … … 96 99 } 97 100 98 /** 101 const 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 /** 99 112 * Calculate bandwidth that needs to be reserved for communication with EP. 100 113 * Calculation follows USB 2.0 specification, chapter 5.11.3. 101 114 * 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 106 118 * @return Number of nanoseconds transaction with @c size bytes payload will 107 119 * take. 108 120 */ 109 s size_t bandwidth_count_usb20(endpoint_t *ep, size_t size)121 static size_t bandwidth_count_usb2(endpoint_t *ep) 110 122 { 111 123 assert(ep); 124 assert(ep->device); 112 125 113 126 const usb_transfer_type_t type = ep->transfer_type; … … 124 137 125 138 // 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; 127 140 128 141 switch (ep->device->speed) { … … 152 165 } 153 166 } 167 168 const 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 219 219 assert(ep); 220 220 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); 227 224 } 228 225 … … 269 266 * @param available_bandwidth Size of the bandwidth pool. 270 267 */ 271 void usb2_bus_init(usb2_bus_t *bus, size_t available_bandwidth)268 void usb2_bus_init(usb2_bus_t *bus, const bandwidth_accounting_t *bw_accounting) 272 269 { 273 270 assert(bus); 271 assert(bw_accounting); 274 272 275 273 bus_init(&bus->base, sizeof(device_t)); 276 274 bus->base.ops = &usb2_bus_ops; 277 275 278 bus->free_bw = available_bandwidth; 276 bus->bw_accounting = bw_accounting; 277 bus->free_bw = bw_accounting->available_bandwidth; 279 278 280 279 /*
Note:
See TracChangeset
for help on using the changeset viewer.