Changes in uspace/lib/usbhost/src/iface.c [6b6fc232:8b54fe6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/iface.c
r6b6fc232 r8b54fe6 49 49 assert(hcd); 50 50 51 endpoint_t *ep = usb_endpoint_manager_find_ep(&hcd->ep_manager, 52 target.address, target.endpoint, direction); 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); 53 56 if (ep == NULL) { 54 57 usb_log_error("Endpoint(%d:%d) not registered for %s.\n", … … 62 65 const size_t bw = bandwidth_count_usb11( 63 66 ep->speed, ep->transfer_type, size, ep->max_packet_size); 64 /* Check if we have enough bandwidth reserved */ 65 if (ep->bandwidth < bw) { 67 if (res_bw < bw) { 66 68 usb_log_error("Endpoint(%d:%d) %s needs %zu bw " 67 69 "but only %zu is reserved.\n", 68 ep->address, ep->endpoint, name, bw, ep->bandwidth);70 target.address, target.endpoint, name, bw, res_bw); 69 71 return ENOSPC; 70 72 } … … 76 78 /* No private data and no private data dtor */ 77 79 usb_transfer_batch_t *batch = 78 usb_transfer_batch_ create(ep, data, size, setup_data,80 usb_transfer_batch_get(ep, data, size, setup_data, 79 81 in, out, arg, fun, NULL, NULL); 80 82 if (!batch) { … … 82 84 } 83 85 84 const intret = hcd->schedule(hcd, batch);86 ret = hcd->schedule(hcd, batch); 85 87 if (ret != EOK) 86 usb_transfer_batch_d estroy(batch);88 usb_transfer_batch_dispose(batch); 87 89 88 90 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);119 91 } 120 92 /*----------------------------------------------------------------------------*/ … … 127 99 */ 128 100 static int request_address( 129 ddf_fun_t *fun, usb_ address_t *address, bool strict, usb_speed_t speed)101 ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address) 130 102 { 131 103 assert(fun); … … 134 106 assert(address); 135 107 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); 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; 140 115 } 141 116 /*----------------------------------------------------------------------------*/ … … 155 130 156 131 usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle); 157 return usb_device_manager_bind_address(158 &hcd->dev_manager, address, handle);132 usb_device_manager_bind(&hcd->dev_manager, address, handle); 133 return EOK; 159 134 } 160 135 /*----------------------------------------------------------------------------*/ … … 172 147 hcd_t *hcd = fun_to_hcd(fun); 173 148 assert(hcd); 174 return usb_device_manager_get_info_by_address( 175 &hcd->dev_manager, address, handle, NULL); 149 const bool found = 150 usb_device_manager_find_by_address(&hcd->dev_manager, address, handle); 151 return found ? EOK : ENOENT; 176 152 } 177 153 /*----------------------------------------------------------------------------*/ … … 188 164 assert(hcd); 189 165 usb_log_debug("Address release %d.\n", 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); 166 usb_device_manager_release(&hcd->dev_manager, address); 193 167 return EOK; 194 168 } 195 169 /*----------------------------------------------------------------------------*/ 196 170 static int register_endpoint( 197 ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint, 171 ddf_fun_t *fun, usb_address_t address, usb_speed_t ep_speed, 172 usb_endpoint_t endpoint, 198 173 usb_transfer_type_t transfer_type, usb_direction_t direction, 199 174 size_t max_packet_size, unsigned int interval) … … 203 178 assert(hcd); 204 179 const size_t size = max_packet_size; 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 } 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); 211 184 212 185 usb_log_debug("Register endpoint %d:%d %s-%s %s %zuB %ums.\n", … … 215 188 max_packet_size, interval); 216 189 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); 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; 220 209 } 221 210 /*----------------------------------------------------------------------------*/ … … 229 218 usb_log_debug("Unregister endpoint %d:%d %s.\n", 230 219 address, endpoint, usb_str_direction(direction)); 231 return usb_endpoint_manager_ remove_ep(&hcd->ep_manager, address,232 endpoint, direction , unregister_helper, hcd);220 return usb_endpoint_manager_unregister_ep(&hcd->ep_manager, address, 221 endpoint, direction); 233 222 } 234 223 /*----------------------------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.