Changes in uspace/lib/usbhost/src/iface.c [8b54fe6:6b6fc232] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/iface.c
r8b54fe6 r6b6fc232 49 49 assert(hcd); 50 50 51 int ret; 52 53 size_t res_bw; 54 endpoint_t *ep = usb_endpoint_manager_get_ep(&hcd->ep_manager, 55 target.address, target.endpoint, direction, &res_bw); 51 endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager, 52 target.address, target.endpoint, direction); 56 53 if (ep == NULL) { 57 54 usb_log_error("Endpoint(%d:%d) not registered for %s.\n", … … 65 62 const size_t bw = bandwidth_count_usb11( 66 63 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) { 68 66 usb_log_error("Endpoint(%d:%d) %s needs %zu bw " 69 67 "but only %zu is reserved.\n", 70 target.address, target.endpoint, name, bw, res_bw);68 ep->address, ep->endpoint, name, bw, ep->bandwidth); 71 69 return ENOSPC; 72 70 } … … 78 76 /* No private data and no private data dtor */ 79 77 usb_transfer_batch_t *batch = 80 usb_transfer_batch_ get(ep, data, size, setup_data,78 usb_transfer_batch_create(ep, data, size, setup_data, 81 79 in, out, arg, fun, NULL, NULL); 82 80 if (!batch) { … … 84 82 } 85 83 86 ret = hcd->schedule(hcd, batch);84 const int ret = hcd->schedule(hcd, batch); 87 85 if (ret != EOK) 88 usb_transfer_batch_d ispose(batch);86 usb_transfer_batch_destroy(batch); 89 87 90 88 return ret; 89 } 90 /*----------------------------------------------------------------------------*/ 91 static int register_helper(endpoint_t *ep, void *arg) 92 { 93 hcd_t *hcd = arg; 94 assert(ep); 95 assert(hcd); 96 if (hcd->ep_add_hook) 97 return hcd->ep_add_hook(hcd, ep); 98 return EOK; 99 } 100 /*----------------------------------------------------------------------------*/ 101 static void unregister_helper(endpoint_t *ep, void *arg) 102 { 103 hcd_t *hcd = arg; 104 assert(ep); 105 assert(hcd); 106 if (hcd->ep_remove_hook) 107 hcd->ep_remove_hook(hcd, ep); 108 } 109 /*----------------------------------------------------------------------------*/ 110 static void unregister_helper_warn(endpoint_t *ep, void *arg) 111 { 112 hcd_t *hcd = arg; 113 assert(ep); 114 assert(hcd); 115 usb_log_warning("Endpoint %d:%d %s was left behind, removing.\n", 116 ep->address, ep->endpoint, usb_str_direction(ep->direction)); 117 if (hcd->ep_remove_hook) 118 hcd->ep_remove_hook(hcd, ep); 91 119 } 92 120 /*----------------------------------------------------------------------------*/ … … 99 127 */ 100 128 static int request_address( 101 ddf_fun_t *fun, usb_ speed_t speed, usb_address_t *address)129 ddf_fun_t *fun, usb_address_t *address, bool strict, usb_speed_t speed) 102 130 { 103 131 assert(fun); … … 106 134 assert(address); 107 135 108 usb_log_debug("Address request speed: %s.\n", usb_str_speed(speed)); 109 *address = 110 usb_device_manager_get_free_address(&hcd->dev_manager, speed); 111 usb_log_debug("Address request with result: %d.\n", *address); 112 if (*address <= 0) 113 return *address; 114 return EOK; 136 usb_log_debug("Address request: speed: %s, address: %d, strict: %s.\n", 137 usb_str_speed(speed), *address, strict ? "YES" : "NO"); 138 return usb_device_manager_request_address( 139 &hcd->dev_manager, address, strict, speed); 115 140 } 116 141 /*----------------------------------------------------------------------------*/ … … 130 155 131 156 usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle); 132 usb_device_manager_bind(&hcd->dev_manager, address, handle);133 return EOK;157 return usb_device_manager_bind_address( 158 &hcd->dev_manager, address, handle); 134 159 } 135 160 /*----------------------------------------------------------------------------*/ … … 147 172 hcd_t *hcd = fun_to_hcd(fun); 148 173 assert(hcd); 149 const bool found = 150 usb_device_manager_find_by_address(&hcd->dev_manager, address, handle); 151 return found ? EOK : ENOENT; 174 return usb_device_manager_get_info_by_address( 175 &hcd->dev_manager, address, handle, NULL); 152 176 } 153 177 /*----------------------------------------------------------------------------*/ … … 164 188 assert(hcd); 165 189 usb_log_debug("Address release %d.\n", address); 166 usb_device_manager_release(&hcd->dev_manager, address); 190 usb_device_manager_release_address(&hcd->dev_manager, address); 191 usb_endpoint_manager_remove_address(&hcd->ep_manager, address, 192 unregister_helper_warn, hcd); 167 193 return EOK; 168 194 } 169 195 /*----------------------------------------------------------------------------*/ 170 196 static int register_endpoint( 171 ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed, 172 usb_endpoint_t endpoint, 197 ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint, 173 198 usb_transfer_type_t transfer_type, usb_direction_t direction, 174 199 size_t max_packet_size, unsigned int interval) … … 178 203 assert(hcd); 179 204 const size_t size = max_packet_size; 180 /* Default address is not bound or registered, 181 * thus it does not provide speed info. */ 182 const usb_speed_t speed = (address == 0) ? ep_speed : 183 usb_device_manager_get_speed(&hcd->dev_manager, address); 205 usb_speed_t speed = USB_SPEED_MAX; 206 const int ret = usb_device_manager_get_info_by_address( 207 &hcd->dev_manager, address, NULL, &speed); 208 if (ret != EOK) { 209 return ret; 210 } 184 211 185 212 usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n", … … 188 215 max_packet_size, interval); 189 216 190 endpoint_t *ep = endpoint_get( 191 address, endpoint, direction, transfer_type, speed, max_packet_size); 192 if (!ep) 193 return ENOMEM; 194 int ret = EOK; 195 196 if (hcd->ep_add_hook) { 197 ret = hcd->ep_add_hook(hcd, ep); 198 } 199 if (ret != EOK) { 200 endpoint_destroy(ep); 201 return ret; 202 } 203 204 ret = usb_endpoint_manager_register_ep(&hcd->ep_manager, ep, size); 205 if (ret != EOK) { 206 endpoint_destroy(ep); 207 } 208 return ret; 217 return usb_endpoint_manager_add_ep(&hcd->ep_manager, address, endpoint, 218 direction, transfer_type, speed, max_packet_size, size, 219 register_helper, hcd); 209 220 } 210 221 /*----------------------------------------------------------------------------*/ … … 218 229 usb_log_debug("Unregister endpoint %d:%d %s.\n", 219 230 address, endpoint, usb_str_direction(direction)); 220 return usb_endpoint_manager_ unregister_ep(&hcd->ep_manager, address,221 endpoint, direction );231 return usb_endpoint_manager_remove_ep(&hcd->ep_manager, address, 232 endpoint, direction, unregister_helper, hcd); 222 233 } 223 234 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.