Changeset 17873ac7 in mainline for uspace/drv
- Timestamp:
- 2017-10-31T19:06:57Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 479e32d
- Parents:
- a312d8f
- Location:
- uspace/drv/bus/usb
- Files:
-
- 8 edited
-
uhci/hc.c (modified) (1 diff)
-
uhci/transfer_list.c (modified) (2 diffs)
-
uhci/uhci_batch.c (modified) (7 diffs)
-
uhci/uhci_batch.h (modified) (1 diff)
-
xhci/bus.c (modified) (2 diffs)
-
xhci/endpoint.h (modified) (1 diff)
-
xhci/transfers.c (modified) (6 diffs)
-
xhci/transfers.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/uhci/hc.c
ra312d8f r17873ac7 177 177 uhci_transfer_batch_t *batch = 178 178 uhci_transfer_batch_from_link(current); 179 u hci_transfer_batch_finish(batch);179 usb_transfer_batch_finish(&batch->base); 180 180 } 181 181 } -
uspace/drv/bus/usb/uhci/transfer_list.c
ra312d8f r17873ac7 115 115 assert(instance); 116 116 assert(uhci_batch); 117 118 endpoint_t *ep = uhci_batch->base.ep; 119 120 /* First, wait until the endpoint is free to use */ 121 fibril_mutex_lock(&ep->guard); 122 endpoint_activate_locked(ep, &uhci_batch->base); 123 fibril_mutex_unlock(&ep->guard); 124 117 125 usb_log_debug2("Batch %p adding to queue %s.\n", 118 126 uhci_batch, instance->name); … … 189 197 uhci_transfer_batch_from_link(current); 190 198 transfer_list_remove_batch(instance, batch); 191 uhci_transfer_batch_abort(batch);199 endpoint_abort(batch->base.ep); 192 200 } 193 201 fibril_mutex_unlock(&instance->guard); -
uspace/drv/bus/usb/uhci/uhci_batch.c
ra312d8f r17873ac7 64 64 } 65 65 66 void uhci_transfer_batch_finish(uhci_transfer_batch_t *batch)67 {68 if (batch->base.dir == USB_DIRECTION_IN) {69 assert(batch->base.transfered_size <= batch->base.buffer_size);70 memcpy(batch->base.buffer, uhci_transfer_batch_data_buffer(batch), batch->base.transfered_size);71 }72 usb_transfer_batch_finish(&batch->base);73 }74 75 66 /** Allocate memory and initialize internal data structure. 76 67 * … … 113 104 } 114 105 115 const size_t setup_size = (u hci_batch->base.ep->transfer_type == USB_TRANSFER_CONTROL)106 const size_t setup_size = (usb_batch->ep->transfer_type == USB_TRANSFER_CONTROL) 116 107 ? USB_SETUP_PACKET_SIZE 117 108 : 0; … … 165 156 { 166 157 assert(uhci_batch); 158 usb_transfer_batch_t *batch = &uhci_batch->base; 167 159 168 160 usb_log_debug2("Batch %p " USB_TRANSFER_BATCH_FMT 169 161 " checking %zu transfer(s) for completion.\n", 170 uhci_batch, USB_TRANSFER_BATCH_ARGS( uhci_batch->base),162 uhci_batch, USB_TRANSFER_BATCH_ARGS(*batch), 171 163 uhci_batch->td_count); 172 uhci_batch->base.transfered_size = 0;164 batch->transfered_size = 0; 173 165 174 166 for (size_t i = 0;i < uhci_batch->td_count; ++i) { … … 177 169 } 178 170 179 uhci_batch->base.error = td_status(&uhci_batch->tds[i]);180 if ( uhci_batch->base.error != EOK) {181 assert( uhci_batch->base.ep != NULL);171 batch->error = td_status(&uhci_batch->tds[i]); 172 if (batch->error != EOK) { 173 assert(batch->ep != NULL); 182 174 183 175 usb_log_debug("Batch %p found error TD(%zu->%p):%" … … 186 178 td_print_status(&uhci_batch->tds[i]); 187 179 188 endpoint_toggle_set( uhci_batch->base.ep,180 endpoint_toggle_set(batch->ep, 189 181 td_toggle(&uhci_batch->tds[i])); 190 182 if (i > 0) … … 193 185 } 194 186 195 uhci_batch->base.transfered_size187 batch->transfered_size 196 188 += td_act_size(&uhci_batch->tds[i]); 197 189 if (td_is_short(&uhci_batch->tds[i])) … … 199 191 } 200 192 substract_ret: 201 if (uhci_batch->base.ep->transfer_type == USB_TRANSFER_CONTROL) 202 uhci_batch->base.transfered_size -= USB_SETUP_PACKET_SIZE; 193 if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) 194 batch->transfered_size -= USB_SETUP_PACKET_SIZE; 195 196 fibril_mutex_lock(&batch->ep->guard); 197 usb_transfer_batch_reset_toggle(batch); 198 endpoint_deactivate_locked(batch->ep); 199 fibril_mutex_unlock(&batch->ep->guard); 200 201 if (batch->dir == USB_DIRECTION_IN) { 202 assert(batch->transfered_size <= batch->buffer_size); 203 memcpy(batch->buffer, 204 uhci_transfer_batch_data_buffer(uhci_batch), 205 batch->transfered_size); 206 } 207 203 208 return true; 204 209 } -
uspace/drv/bus/usb/uhci/uhci_batch.h
ra312d8f r17873ac7 98 98 } 99 99 100 /** Aborts the batch.101 * Sets error to EINTR and size off transferd data to 0, before finishing the102 * batch.103 * @param uhci_batch Batch to abort.104 */105 static inline void uhci_transfer_batch_abort(uhci_transfer_batch_t *uhci_batch)106 {107 assert(uhci_batch);108 uhci_batch->base.error = EINTR;109 uhci_batch->base.transfered_size = 0;110 usb_transfer_batch_finish(&uhci_batch->base);111 }112 113 100 /** Linked list conversion wrapper. 114 101 * @param l Linked list link. -
uspace/drv/bus/usb/xhci/bus.c
ra312d8f r17873ac7 198 198 for (size_t i = 0; i < ARRAY_SIZE(xhci_dev->endpoints); ++i) { 199 199 xhci_endpoint_t *ep = xhci_dev->endpoints[i]; 200 if (!ep || !ep->base.active)200 if (!ep) 201 201 continue; 202 202 203 /* FIXME: This is racy. */ 204 if ((err = xhci_transfer_abort(&ep->active_transfer))) { 205 usb_log_warning("Failed to abort active transfer to " 206 " endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep), 207 str_error(err)); 208 } 203 endpoint_abort(&ep->base); 209 204 } 210 205 … … 454 449 } 455 450 456 static int reset_toggle(bus_t *bus_base, usb_target_t target, bool all)451 static int reset_toggle(bus_t *bus_base, usb_target_t target, toggle_reset_mode_t mode) 457 452 { 458 453 // TODO: Implement me! -
uspace/drv/bus/usb/xhci/endpoint.h
ra312d8f r17873ac7 68 68 /** Main transfer ring (unused if streams are enabled) */ 69 69 xhci_trb_ring_t ring; 70 71 /** There shall be only one transfer active on an endpoint. The72 * synchronization is performed using the active flag in base73 * endpoint_t */74 xhci_transfer_t active_transfer;75 70 76 71 /** Primary stream context array (or NULL if endpoint doesn't use streams). */ -
uspace/drv/bus/usb/xhci/transfers.c
ra312d8f r17873ac7 101 101 xhci_transfer_t* xhci_transfer_create(endpoint_t* ep) 102 102 { 103 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep); 104 xhci_transfer_t *transfer = &xhci_ep->active_transfer; 105 106 /* Do not access the transfer yet, it may be still in use. */ 103 xhci_transfer_t *transfer = calloc(1, sizeof(xhci_transfer_t)); 104 if (!transfer) 105 return NULL; 107 106 108 107 usb_transfer_batch_init(&transfer->batch, ep); 109 assert(ep->active);110 111 /* Clean just our data. */112 memset(((void *) transfer) + sizeof(usb_transfer_batch_t), 0,113 sizeof(xhci_transfer_t) - sizeof(usb_transfer_batch_t));114 115 108 return transfer; 116 109 } … … 246 239 usb_log_error("Isochronous transfers are not yet implemented!"); 247 240 return ENOTSUP; 248 }249 250 int xhci_transfer_abort(xhci_transfer_t *transfer)251 {252 usb_transfer_batch_t *batch = &transfer->batch;253 batch->error = EAGAIN;254 batch->transfered_size = 0;255 usb_transfer_batch_finish(batch);256 return EOK;257 241 } 258 242 … … 277 261 } 278 262 279 xhci_transfer_t *transfer = &ep->active_transfer; 280 281 /** FIXME: This is racy. Do we care? */ 263 /* FIXME: This is racy. Do we care? */ 282 264 ep->ring.dequeue = addr; 283 265 284 usb_transfer_batch_t *batch = &transfer->batch; 266 fibril_mutex_lock(&ep->base.guard); 267 usb_transfer_batch_t *batch = ep->base.active_batch; 268 if (!batch) { 269 fibril_mutex_unlock(&ep->base.guard); 270 return ENOENT; 271 } 285 272 286 273 batch->error = (TRB_COMPLETION_CODE(*trb) == XHCI_TRBC_SUCCESS) ? EOK : ENAK; 287 274 batch->transfered_size = batch->buffer_size - TRB_TRANSFER_LENGTH(*trb); 275 usb_transfer_batch_reset_toggle(batch); 276 endpoint_deactivate_locked(&ep->base); 277 fibril_mutex_unlock(&ep->base.guard); 278 279 xhci_transfer_t *transfer = xhci_transfer_from_batch(batch); 288 280 289 281 if (batch->dir == USB_DIRECTION_IN) { … … 309 301 { 310 302 assert(hc); 303 endpoint_t *ep = batch->ep; 311 304 312 305 xhci_transfer_t *transfer = xhci_transfer_from_batch(batch); 313 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(batch->ep); 314 assert(xhci_ep); 315 306 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep); 316 307 xhci_device_t *xhci_dev = xhci_ep_to_dev(xhci_ep); 317 308 318 309 /* Offline devices don't schedule transfers other than on EP0. */ 319 if (!xhci_dev->online && xhci_ep->base.endpoint) {310 if (!xhci_dev->online && ep->endpoint > 0) { 320 311 return EAGAIN; 321 312 } … … 334 325 if (batch->buffer_size > 0) { 335 326 transfer->hc_buffer = malloc32(batch->buffer_size); 336 } 337 327 if (!transfer->hc_buffer) 328 return ENOMEM; 329 } 338 330 339 331 if (batch->dir != USB_DIRECTION_IN) { … … 342 334 } 343 335 336 fibril_mutex_lock(&ep->guard); 337 endpoint_activate_locked(ep, batch); 344 338 const int err = transfer_handlers[batch->ep->transfer_type](hc, transfer); 345 if (err) 339 340 if (err) { 341 endpoint_deactivate_locked(ep); 342 fibril_mutex_unlock(&ep->guard); 346 343 return err; 344 } 345 346 /* After the critical section, the transfer can already be finished or aborted. */ 347 transfer = NULL; batch = NULL; 348 fibril_mutex_unlock(&ep->guard); 347 349 348 350 const uint8_t slot_id = xhci_dev->slot_id; -
uspace/drv/bus/usb/xhci/transfers.h
ra312d8f r17873ac7 58 58 xhci_transfer_t* xhci_transfer_create(endpoint_t *); 59 59 int xhci_transfer_schedule(xhci_hc_t *, usb_transfer_batch_t *); 60 int xhci_transfer_abort(xhci_transfer_t *);61 60 int xhci_handle_transfer_event(xhci_hc_t *, xhci_trb_t *); 62 61 void xhci_transfer_destroy(xhci_transfer_t *);
Note:
See TracChangeset
for help on using the changeset viewer.
