usb_request.c (184610) | usb_request.c (184824) |
---|---|
1/* $FreeBSD: head/sys/dev/usb2/core/usb2_request.c 184610 2008-11-04 02:31:03Z alfred $ */ | 1/* $FreeBSD: head/sys/dev/usb2/core/usb2_request.c 184824 2008-11-10 20:54:31Z thompsa $ */ |
2/*- 3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 30 unchanged lines hidden (view full) --- 40#include <dev/usb2/core/usb2_request.h> 41#include <dev/usb2/core/usb2_process.h> 42#include <dev/usb2/core/usb2_transfer.h> 43#include <dev/usb2/core/usb2_debug.h> 44#include <dev/usb2/core/usb2_device.h> 45#include <dev/usb2/core/usb2_util.h> 46#include <dev/usb2/core/usb2_dynamic.h> 47 | 2/*- 3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 30 unchanged lines hidden (view full) --- 40#include <dev/usb2/core/usb2_request.h> 41#include <dev/usb2/core/usb2_process.h> 42#include <dev/usb2/core/usb2_transfer.h> 43#include <dev/usb2/core/usb2_debug.h> 44#include <dev/usb2/core/usb2_device.h> 45#include <dev/usb2/core/usb2_util.h> 46#include <dev/usb2/core/usb2_dynamic.h> 47 |
48#include <dev/usb2/controller/usb2_controller.h> 49#include <dev/usb2/controller/usb2_bus.h> |
|
48#include <sys/ctype.h> 49 50#if USB_DEBUG 51static int usb2_pr_poll_delay = USB_PORT_RESET_DELAY; 52static int usb2_pr_recovery_delay = USB_PORT_RESET_RECOVERY; 53static int usb2_ss_delay = 0; 54 55SYSCTL_INT(_hw_usb2, OID_AUTO, pr_poll_delay, CTLFLAG_RW, --- 37 unchanged lines hidden (view full) --- 93usb2_do_clear_stall_callback(struct usb2_xfer *xfer) 94{ 95 struct usb2_device_request req; 96 struct usb2_pipe *pipe; 97 struct usb2_pipe *pipe_end; 98 struct usb2_pipe *pipe_first; 99 uint8_t to = USB_EP_MAX; 100 | 50#include <sys/ctype.h> 51 52#if USB_DEBUG 53static int usb2_pr_poll_delay = USB_PORT_RESET_DELAY; 54static int usb2_pr_recovery_delay = USB_PORT_RESET_RECOVERY; 55static int usb2_ss_delay = 0; 56 57SYSCTL_INT(_hw_usb2, OID_AUTO, pr_poll_delay, CTLFLAG_RW, --- 37 unchanged lines hidden (view full) --- 95usb2_do_clear_stall_callback(struct usb2_xfer *xfer) 96{ 97 struct usb2_device_request req; 98 struct usb2_pipe *pipe; 99 struct usb2_pipe *pipe_end; 100 struct usb2_pipe *pipe_first; 101 uint8_t to = USB_EP_MAX; 102 |
101 mtx_lock(xfer->usb2_mtx); | 103 USB_BUS_LOCK(xfer->udev->bus); |
102 103 /* round robin pipe clear stall */ 104 105 pipe = xfer->udev->pipe_curr; 106 pipe_end = xfer->udev->pipes + USB_EP_MAX; 107 pipe_first = xfer->udev->pipes; 108 if (pipe == NULL) { 109 pipe = pipe_first; --- 29 unchanged lines hidden (view full) --- 139 140 /* copy in the transfer */ 141 142 usb2_copy_in(xfer->frbuffers, 0, &req, sizeof(req)); 143 144 /* set length */ 145 xfer->frlengths[0] = sizeof(req); 146 xfer->nframes = 1; | 104 105 /* round robin pipe clear stall */ 106 107 pipe = xfer->udev->pipe_curr; 108 pipe_end = xfer->udev->pipes + USB_EP_MAX; 109 pipe_first = xfer->udev->pipes; 110 if (pipe == NULL) { 111 pipe = pipe_first; --- 29 unchanged lines hidden (view full) --- 141 142 /* copy in the transfer */ 143 144 usb2_copy_in(xfer->frbuffers, 0, &req, sizeof(req)); 145 146 /* set length */ 147 xfer->frlengths[0] = sizeof(req); 148 xfer->nframes = 1; |
147 mtx_unlock(xfer->usb2_mtx); | 149 USB_BUS_UNLOCK(xfer->udev->bus); |
148 149 usb2_start_hardware(xfer); 150 | 150 151 usb2_start_hardware(xfer); 152 |
151 mtx_lock(xfer->usb2_mtx); | 153 USB_BUS_LOCK(xfer->udev->bus); |
152 break; 153 } 154 pipe++; 155 if (--to) 156 goto tr_setup; 157 break; 158 159 default: 160 if (xfer->error == USB_ERR_CANCELLED) { 161 break; 162 } 163 goto tr_setup; 164 } 165 166 /* store current pipe */ 167 xfer->udev->pipe_curr = pipe; | 154 break; 155 } 156 pipe++; 157 if (--to) 158 goto tr_setup; 159 break; 160 161 default: 162 if (xfer->error == USB_ERR_CANCELLED) { 163 break; 164 } 165 goto tr_setup; 166 } 167 168 /* store current pipe */ 169 xfer->udev->pipe_curr = pipe; |
168 mtx_unlock(xfer->usb2_mtx); | 170 USB_BUS_UNLOCK(xfer->udev->bus); |
169 return; 170} 171 172/*------------------------------------------------------------------------* 173 * usb2_do_request_flags and usb2_do_request 174 * 175 * Description of arguments passed to these functions: 176 * --- 131 unchanged lines hidden (view full) --- 308 usb2_default_transfer_setup(udev); 309 310 xfer = udev->default_xfer[0]; 311 if (xfer == NULL) { 312 /* most likely out of memory */ 313 err = USB_ERR_NOMEM; 314 goto done; 315 } | 171 return; 172} 173 174/*------------------------------------------------------------------------* 175 * usb2_do_request_flags and usb2_do_request 176 * 177 * Description of arguments passed to these functions: 178 * --- 131 unchanged lines hidden (view full) --- 310 usb2_default_transfer_setup(udev); 311 312 xfer = udev->default_xfer[0]; 313 if (xfer == NULL) { 314 /* most likely out of memory */ 315 err = USB_ERR_NOMEM; 316 goto done; 317 } |
316 mtx_lock(xfer->priv_mtx); | 318 USB_XFER_LOCK(xfer); |
317 318 if (flags & USB_DELAY_STATUS_STAGE) { 319 xfer->flags.manual_status = 1; 320 } else { 321 xfer->flags.manual_status = 0; 322 } 323 324 xfer->timeout = timeout; --- 12 unchanged lines hidden (view full) --- 337 if (temp > xfer->max_data_length) { 338 temp = xfer->max_data_length; 339 } 340 xfer->frlengths[1] = temp; 341 342 if (temp > 0) { 343 if (!(req->bmRequestType & UT_READ)) { 344 if (flags & USB_USER_DATA_PTR) { | 319 320 if (flags & USB_DELAY_STATUS_STAGE) { 321 xfer->flags.manual_status = 1; 322 } else { 323 xfer->flags.manual_status = 0; 324 } 325 326 xfer->timeout = timeout; --- 12 unchanged lines hidden (view full) --- 339 if (temp > xfer->max_data_length) { 340 temp = xfer->max_data_length; 341 } 342 xfer->frlengths[1] = temp; 343 344 if (temp > 0) { 345 if (!(req->bmRequestType & UT_READ)) { 346 if (flags & USB_USER_DATA_PTR) { |
345 mtx_unlock(xfer->priv_mtx); | 347 USB_XFER_UNLOCK(xfer); |
346 err = usb2_copy_in_user(xfer->frbuffers + 1, 347 0, data, temp); | 348 err = usb2_copy_in_user(xfer->frbuffers + 1, 349 0, data, temp); |
348 mtx_lock(xfer->priv_mtx); | 350 USB_XFER_LOCK(xfer); |
349 if (err) { 350 err = USB_ERR_INVAL; 351 break; 352 } 353 } else { 354 usb2_copy_in(xfer->frbuffers + 1, 0, data, temp); 355 } 356 } --- 5 unchanged lines hidden (view full) --- 362 int temp; 363 364 temp = usb2_ss_delay; 365 if (temp > 5000) { 366 temp = 5000; 367 } 368 if (temp > 0) { 369 usb2_pause_mtx( | 351 if (err) { 352 err = USB_ERR_INVAL; 353 break; 354 } 355 } else { 356 usb2_copy_in(xfer->frbuffers + 1, 0, data, temp); 357 } 358 } --- 5 unchanged lines hidden (view full) --- 364 int temp; 365 366 temp = usb2_ss_delay; 367 if (temp > 5000) { 368 temp = 5000; 369 } 370 if (temp > 0) { 371 usb2_pause_mtx( |
370 xfer->priv_mtx, temp); | 372 xfer->xfer_mtx, temp); |
371 } 372#endif 373 xfer->flags.manual_status = 0; 374 } else { 375 break; 376 } 377 } 378 xfer->nframes = 1; 379 } 380 381 usb2_transfer_start(xfer); 382 383 while (usb2_transfer_pending(xfer)) { 384 if ((flags & USB_USE_POLLING) || cold) { 385 usb2_do_poll(udev->default_xfer, USB_DEFAULT_XFER_MAX); 386 } else { | 373 } 374#endif 375 xfer->flags.manual_status = 0; 376 } else { 377 break; 378 } 379 } 380 xfer->nframes = 1; 381 } 382 383 usb2_transfer_start(xfer); 384 385 while (usb2_transfer_pending(xfer)) { 386 if ((flags & USB_USE_POLLING) || cold) { 387 usb2_do_poll(udev->default_xfer, USB_DEFAULT_XFER_MAX); 388 } else { |
387 usb2_cv_wait(xfer->udev->default_cv, xfer->priv_mtx); | 389 usb2_cv_wait(xfer->udev->default_cv, 390 xfer->xfer_mtx); |
388 } 389 } 390 391 err = xfer->error; 392 393 if (err) { 394 break; 395 } --- 12 unchanged lines hidden (view full) --- 408 if (!(flags & USB_SHORT_XFER_OK)) { 409 err = USB_ERR_SHORT_XFER; 410 } 411 length = temp; 412 } 413 if (temp > 0) { 414 if (req->bmRequestType & UT_READ) { 415 if (flags & USB_USER_DATA_PTR) { | 391 } 392 } 393 394 err = xfer->error; 395 396 if (err) { 397 break; 398 } --- 12 unchanged lines hidden (view full) --- 411 if (!(flags & USB_SHORT_XFER_OK)) { 412 err = USB_ERR_SHORT_XFER; 413 } 414 length = temp; 415 } 416 if (temp > 0) { 417 if (req->bmRequestType & UT_READ) { 418 if (flags & USB_USER_DATA_PTR) { |
416 mtx_unlock(xfer->priv_mtx); | 419 USB_XFER_UNLOCK(xfer); |
417 err = usb2_copy_out_user(xfer->frbuffers + 1, 418 0, data, temp); | 420 err = usb2_copy_out_user(xfer->frbuffers + 1, 421 0, data, temp); |
419 mtx_lock(xfer->priv_mtx); | 422 USB_XFER_LOCK(xfer); |
420 if (err) { 421 err = USB_ERR_INVAL; 422 break; 423 } 424 } else { 425 usb2_copy_out(xfer->frbuffers + 1, 426 0, data, temp); 427 } --- 27 unchanged lines hidden (view full) --- 455 456 if (err) { 457 /* 458 * Make sure that the control endpoint is no longer 459 * blocked in case of a non-transfer related error: 460 */ 461 usb2_transfer_stop(xfer); 462 } | 423 if (err) { 424 err = USB_ERR_INVAL; 425 break; 426 } 427 } else { 428 usb2_copy_out(xfer->frbuffers + 1, 429 0, data, temp); 430 } --- 27 unchanged lines hidden (view full) --- 458 459 if (err) { 460 /* 461 * Make sure that the control endpoint is no longer 462 * blocked in case of a non-transfer related error: 463 */ 464 usb2_transfer_stop(xfer); 465 } |
463 mtx_unlock(xfer->priv_mtx); | 466 USB_XFER_UNLOCK(xfer); |
464 465done: 466 sx_xunlock(udev->default_sx); 467 468 if (mtx) { 469 mtx_lock(mtx); 470 } 471 return ((usb2_error_t)err); --- 902 unchanged lines hidden --- | 467 468done: 469 sx_xunlock(udev->default_sx); 470 471 if (mtx) { 472 mtx_lock(mtx); 473 } 474 return ((usb2_error_t)err); --- 902 unchanged lines hidden --- |