Deleted Added
full compact
usb_transfer.c (194227) usb_transfer.c (194228)
1/* $FreeBSD: head/sys/dev/usb/usb_transfer.c 194227 2009-06-15 00:33:18Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb/usb_transfer.c 194228 2009-06-15 01:02:43Z thompsa $ */
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 13 unchanged lines hidden (view full) ---

23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <dev/usb/usb_mfunc.h>
28#include <dev/usb/usb_error.h>
29#include <dev/usb/usb.h>
30
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 13 unchanged lines hidden (view full) ---

23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <dev/usb/usb_mfunc.h>
28#include <dev/usb/usb_error.h>
29#include <dev/usb/usb.h>
30
31#define USB_DEBUG_VAR usb2_debug
31#define USB_DEBUG_VAR usb_debug
32
33#include <dev/usb/usb_core.h>
34#include <dev/usb/usb_busdma.h>
35#include <dev/usb/usb_process.h>
36#include <dev/usb/usb_transfer.h>
37#include <dev/usb/usb_device.h>
38#include <dev/usb/usb_debug.h>
39#include <dev/usb/usb_util.h>
40
41#include <dev/usb/usb_controller.h>
42#include <dev/usb/usb_bus.h>
43
32
33#include <dev/usb/usb_core.h>
34#include <dev/usb/usb_busdma.h>
35#include <dev/usb/usb_process.h>
36#include <dev/usb/usb_transfer.h>
37#include <dev/usb/usb_device.h>
38#include <dev/usb/usb_debug.h>
39#include <dev/usb/usb_util.h>
40
41#include <dev/usb/usb_controller.h>
42#include <dev/usb/usb_bus.h>
43
44struct usb2_std_packet_size {
44struct usb_std_packet_size {
45 struct {
46 uint16_t min; /* inclusive */
47 uint16_t max; /* inclusive */
48 } range;
49
50 uint16_t fixed[4];
51};
52
45 struct {
46 uint16_t min; /* inclusive */
47 uint16_t max; /* inclusive */
48 } range;
49
50 uint16_t fixed[4];
51};
52
53static usb_callback_t usb2_request_callback;
53static usb_callback_t usb_request_callback;
54
54
55static const struct usb_config usb2_control_ep_cfg[USB_DEFAULT_XFER_MAX] = {
55static const struct usb_config usb_control_ep_cfg[USB_DEFAULT_XFER_MAX] = {
56
57 /* This transfer is used for generic control endpoint transfers */
58
59 [0] = {
60 .type = UE_CONTROL,
61 .endpoint = 0x00, /* Control endpoint */
62 .direction = UE_DIR_ANY,
63 .bufsize = USB_EP0_BUFSIZE, /* bytes */
64 .flags = {.proxy_buffer = 1,},
56
57 /* This transfer is used for generic control endpoint transfers */
58
59 [0] = {
60 .type = UE_CONTROL,
61 .endpoint = 0x00, /* Control endpoint */
62 .direction = UE_DIR_ANY,
63 .bufsize = USB_EP0_BUFSIZE, /* bytes */
64 .flags = {.proxy_buffer = 1,},
65 .callback = &usb2_request_callback,
65 .callback = &usb_request_callback,
66 .usb_mode = USB_MODE_DUAL, /* both modes */
67 },
68
69 /* This transfer is used for generic clear stall only */
70
71 [1] = {
72 .type = UE_CONTROL,
73 .endpoint = 0x00, /* Control pipe */
74 .direction = UE_DIR_ANY,
75 .bufsize = sizeof(struct usb_device_request),
66 .usb_mode = USB_MODE_DUAL, /* both modes */
67 },
68
69 /* This transfer is used for generic clear stall only */
70
71 [1] = {
72 .type = UE_CONTROL,
73 .endpoint = 0x00, /* Control pipe */
74 .direction = UE_DIR_ANY,
75 .bufsize = sizeof(struct usb_device_request),
76 .callback = &usb2_do_clear_stall_callback,
76 .callback = &usb_do_clear_stall_callback,
77 .timeout = 1000, /* 1 second */
78 .interval = 50, /* 50ms */
79 .usb_mode = USB_MODE_HOST,
80 },
81};
82
83/* function prototypes */
84
77 .timeout = 1000, /* 1 second */
78 .interval = 50, /* 50ms */
79 .usb_mode = USB_MODE_HOST,
80 },
81};
82
83/* function prototypes */
84
85static void usb2_update_max_frame_size(struct usb_xfer *);
86static void usb2_transfer_unsetup_sub(struct usb_xfer_root *, uint8_t);
87static void usb2_control_transfer_init(struct usb_xfer *);
88static uint8_t usb2_start_hardware_sub(struct usb_xfer *);
89static void usb2_callback_proc(struct usb_proc_msg *);
90static void usb2_callback_ss_done_defer(struct usb_xfer *);
91static void usb2_callback_wrapper(struct usb_xfer_queue *);
92static void usb2_dma_delay_done_cb(void *);
93static void usb2_transfer_start_cb(void *);
94static uint8_t usb2_callback_wrapper_sub(struct usb_xfer *);
95static void usb2_get_std_packet_size(struct usb2_std_packet_size *ptr,
85static void usbd_update_max_frame_size(struct usb_xfer *);
86static void usbd_transfer_unsetup_sub(struct usb_xfer_root *, uint8_t);
87static void usbd_control_transfer_init(struct usb_xfer *);
88static uint8_t usbd_start_hardware_sub(struct usb_xfer *);
89static void usb_callback_proc(struct usb_proc_msg *);
90static void usbd_callback_ss_done_defer(struct usb_xfer *);
91static void usbd_callback_wrapper(struct usb_xfer_queue *);
92static void usb_dma_delay_done_cb(void *);
93static void usbd_transfer_start_cb(void *);
94static uint8_t usbd_callback_wrapper_sub(struct usb_xfer *);
95static void usbd_get_std_packet_size(struct usb_std_packet_size *ptr,
96 uint8_t type, enum usb_dev_speed speed);
97
98/*------------------------------------------------------------------------*
96 uint8_t type, enum usb_dev_speed speed);
97
98/*------------------------------------------------------------------------*
99 * usb2_request_callback
99 * usb_request_callback
100 *------------------------------------------------------------------------*/
101static void
100 *------------------------------------------------------------------------*/
101static void
102usb2_request_callback(struct usb_xfer *xfer)
102usb_request_callback(struct usb_xfer *xfer)
103{
104 if (xfer->flags_int.usb_mode == USB_MODE_DEVICE)
103{
104 if (xfer->flags_int.usb_mode == USB_MODE_DEVICE)
105 usb2_handle_request_callback(xfer);
105 usb_handle_request_callback(xfer);
106 else
106 else
107 usb2_do_request_callback(xfer);
107 usbd_do_request_callback(xfer);
108}
109
110/*------------------------------------------------------------------------*
108}
109
110/*------------------------------------------------------------------------*
111 * usb2_update_max_frame_size
111 * usbd_update_max_frame_size
112 *
113 * This function updates the maximum frame size, hence high speed USB
114 * can transfer multiple consecutive packets.
115 *------------------------------------------------------------------------*/
116static void
112 *
113 * This function updates the maximum frame size, hence high speed USB
114 * can transfer multiple consecutive packets.
115 *------------------------------------------------------------------------*/
116static void
117usb2_update_max_frame_size(struct usb_xfer *xfer)
117usbd_update_max_frame_size(struct usb_xfer *xfer)
118{
119 /* compute maximum frame size */
120
121 if (xfer->max_packet_count == 2) {
122 xfer->max_frame_size = 2 * xfer->max_packet_size;
123 } else if (xfer->max_packet_count == 3) {
124 xfer->max_frame_size = 3 * xfer->max_packet_size;
125 } else {
126 xfer->max_frame_size = xfer->max_packet_size;
127 }
128}
129
130/*------------------------------------------------------------------------*
118{
119 /* compute maximum frame size */
120
121 if (xfer->max_packet_count == 2) {
122 xfer->max_frame_size = 2 * xfer->max_packet_size;
123 } else if (xfer->max_packet_count == 3) {
124 xfer->max_frame_size = 3 * xfer->max_packet_size;
125 } else {
126 xfer->max_frame_size = xfer->max_packet_size;
127 }
128}
129
130/*------------------------------------------------------------------------*
131 * usb2_get_dma_delay
131 * usbd_get_dma_delay
132 *
133 * The following function is called when we need to
134 * synchronize with DMA hardware.
135 *
136 * Returns:
137 * 0: no DMA delay required
138 * Else: milliseconds of DMA delay
139 *------------------------------------------------------------------------*/
140usb_timeout_t
132 *
133 * The following function is called when we need to
134 * synchronize with DMA hardware.
135 *
136 * Returns:
137 * 0: no DMA delay required
138 * Else: milliseconds of DMA delay
139 *------------------------------------------------------------------------*/
140usb_timeout_t
141usb2_get_dma_delay(struct usb_bus *bus)
141usbd_get_dma_delay(struct usb_bus *bus)
142{
143 uint32_t temp = 0;
144
145 if (bus->methods->get_dma_delay) {
146 (bus->methods->get_dma_delay) (bus, &temp);
147 /*
148 * Round up and convert to milliseconds. Note that we use
149 * 1024 milliseconds per second. to save a division.
150 */
151 temp += 0x3FF;
152 temp /= 0x400;
153 }
154 return (temp);
155}
156
157/*------------------------------------------------------------------------*
142{
143 uint32_t temp = 0;
144
145 if (bus->methods->get_dma_delay) {
146 (bus->methods->get_dma_delay) (bus, &temp);
147 /*
148 * Round up and convert to milliseconds. Note that we use
149 * 1024 milliseconds per second. to save a division.
150 */
151 temp += 0x3FF;
152 temp /= 0x400;
153 }
154 return (temp);
155}
156
157/*------------------------------------------------------------------------*
158 * usb2_transfer_setup_sub_malloc
158 * usbd_transfer_setup_sub_malloc
159 *
160 * This function will allocate one or more DMA'able memory chunks
161 * according to "size", "align" and "count" arguments. "ppc" is
162 * pointed to a linear array of USB page caches afterwards.
163 *
164 * Returns:
165 * 0: Success
166 * Else: Failure
167 *------------------------------------------------------------------------*/
168#if USB_HAVE_BUSDMA
169uint8_t
159 *
160 * This function will allocate one or more DMA'able memory chunks
161 * according to "size", "align" and "count" arguments. "ppc" is
162 * pointed to a linear array of USB page caches afterwards.
163 *
164 * Returns:
165 * 0: Success
166 * Else: Failure
167 *------------------------------------------------------------------------*/
168#if USB_HAVE_BUSDMA
169uint8_t
170usb2_transfer_setup_sub_malloc(struct usb_setup_params *parm,
170usbd_transfer_setup_sub_malloc(struct usb_setup_params *parm,
171 struct usb_page_cache **ppc, usb_size_t size, usb_size_t align,
172 usb_size_t count)
173{
174 struct usb_page_cache *pc;
175 struct usb_page *pg;
176 void *buf;
177 usb_size_t n_dma_pc;
178 usb_size_t n_obj;

--- 60 unchanged lines hidden (view full) ---

239
240 for (x = 0; x != n_dma_pc; x++) {
241
242 if (r < n_obj) {
243 /* compute last remainder */
244 z = r * size;
245 n_obj = r;
246 }
171 struct usb_page_cache **ppc, usb_size_t size, usb_size_t align,
172 usb_size_t count)
173{
174 struct usb_page_cache *pc;
175 struct usb_page *pg;
176 void *buf;
177 usb_size_t n_dma_pc;
178 usb_size_t n_obj;

--- 60 unchanged lines hidden (view full) ---

239
240 for (x = 0; x != n_dma_pc; x++) {
241
242 if (r < n_obj) {
243 /* compute last remainder */
244 z = r * size;
245 n_obj = r;
246 }
247 if (usb2_pc_alloc_mem(parm->dma_page_cache_ptr,
247 if (usb_pc_alloc_mem(parm->dma_page_cache_ptr,
248 pg, z, align)) {
249 return (1); /* failure */
250 }
251 /* Set beginning of current buffer */
252 buf = parm->dma_page_cache_ptr->buffer;
253 /* Make room for one DMA page cache and one page */
254 parm->dma_page_cache_ptr++;
255 pg++;
256
257 for (y = 0; (y != n_obj); y++, r--, pc++, pg++) {
258
259 /* Load sub-chunk into DMA */
248 pg, z, align)) {
249 return (1); /* failure */
250 }
251 /* Set beginning of current buffer */
252 buf = parm->dma_page_cache_ptr->buffer;
253 /* Make room for one DMA page cache and one page */
254 parm->dma_page_cache_ptr++;
255 pg++;
256
257 for (y = 0; (y != n_obj); y++, r--, pc++, pg++) {
258
259 /* Load sub-chunk into DMA */
260 if (usb2_pc_dmamap_create(pc, size)) {
260 if (usb_pc_dmamap_create(pc, size)) {
261 return (1); /* failure */
262 }
263 pc->buffer = USB_ADD_BYTES(buf, y * size);
264 pc->page_start = pg;
265
266 mtx_lock(pc->tag_parent->mtx);
261 return (1); /* failure */
262 }
263 pc->buffer = USB_ADD_BYTES(buf, y * size);
264 pc->page_start = pg;
265
266 mtx_lock(pc->tag_parent->mtx);
267 if (usb2_pc_load_mem(pc, size, 1 /* synchronous */ )) {
267 if (usb_pc_load_mem(pc, size, 1 /* synchronous */ )) {
268 mtx_unlock(pc->tag_parent->mtx);
269 return (1); /* failure */
270 }
271 mtx_unlock(pc->tag_parent->mtx);
272 }
273 }
274
275 parm->xfer_page_cache_ptr = pc;
276 parm->dma_page_ptr = pg;
277 return (0);
278}
279#endif
280
281/*------------------------------------------------------------------------*
268 mtx_unlock(pc->tag_parent->mtx);
269 return (1); /* failure */
270 }
271 mtx_unlock(pc->tag_parent->mtx);
272 }
273 }
274
275 parm->xfer_page_cache_ptr = pc;
276 parm->dma_page_ptr = pg;
277 return (0);
278}
279#endif
280
281/*------------------------------------------------------------------------*
282 * usb2_transfer_setup_sub - transfer setup subroutine
282 * usbd_transfer_setup_sub - transfer setup subroutine
283 *
284 * This function must be called from the "xfer_setup" callback of the
285 * USB Host or Device controller driver when setting up an USB
286 * transfer. This function will setup correct packet sizes, buffer
287 * sizes, flags and more, that are stored in the "usb_xfer"
288 * structure.
289 *------------------------------------------------------------------------*/
290void
283 *
284 * This function must be called from the "xfer_setup" callback of the
285 * USB Host or Device controller driver when setting up an USB
286 * transfer. This function will setup correct packet sizes, buffer
287 * sizes, flags and more, that are stored in the "usb_xfer"
288 * structure.
289 *------------------------------------------------------------------------*/
290void
291usb2_transfer_setup_sub(struct usb_setup_params *parm)
291usbd_transfer_setup_sub(struct usb_setup_params *parm)
292{
293 enum {
294 REQ_SIZE = 8,
295 MIN_PKT = 8,
296 };
297 struct usb_xfer *xfer = parm->curr_xfer;
298 const struct usb_config *setup = parm->curr_setup;
299 struct usb_endpoint_descriptor *edesc;
292{
293 enum {
294 REQ_SIZE = 8,
295 MIN_PKT = 8,
296 };
297 struct usb_xfer *xfer = parm->curr_xfer;
298 const struct usb_config *setup = parm->curr_setup;
299 struct usb_endpoint_descriptor *edesc;
300 struct usb2_std_packet_size std_size;
300 struct usb_std_packet_size std_size;
301 usb_frcount_t n_frlengths;
302 usb_frcount_t n_frbuffers;
303 usb_frcount_t x;
304 uint8_t type;
305 uint8_t zmps;
306
307 /*
308 * Sanity check. The following parameters must be initialized before

--- 34 unchanged lines hidden (view full) ---

343 /* filter "wMaxPacketSize" according to HC capabilities */
344
345 if ((xfer->max_packet_size > parm->hc_max_packet_size) ||
346 (xfer->max_packet_size == 0)) {
347 xfer->max_packet_size = parm->hc_max_packet_size;
348 }
349 /* filter "wMaxPacketSize" according to standard sizes */
350
301 usb_frcount_t n_frlengths;
302 usb_frcount_t n_frbuffers;
303 usb_frcount_t x;
304 uint8_t type;
305 uint8_t zmps;
306
307 /*
308 * Sanity check. The following parameters must be initialized before

--- 34 unchanged lines hidden (view full) ---

343 /* filter "wMaxPacketSize" according to HC capabilities */
344
345 if ((xfer->max_packet_size > parm->hc_max_packet_size) ||
346 (xfer->max_packet_size == 0)) {
347 xfer->max_packet_size = parm->hc_max_packet_size;
348 }
349 /* filter "wMaxPacketSize" according to standard sizes */
350
351 usb2_get_std_packet_size(&std_size, type, parm->speed);
351 usbd_get_std_packet_size(&std_size, type, parm->speed);
352
353 if (std_size.range.min || std_size.range.max) {
354
355 if (xfer->max_packet_size < std_size.range.min) {
356 xfer->max_packet_size = std_size.range.min;
357 }
358 if (xfer->max_packet_size > std_size.range.max) {
359 xfer->max_packet_size = std_size.range.max;

--- 9 unchanged lines hidden (view full) ---

369 } else {
370 /* only one possibility left */
371 xfer->max_packet_size = std_size.fixed[0];
372 }
373 }
374
375 /* compute "max_frame_size" */
376
352
353 if (std_size.range.min || std_size.range.max) {
354
355 if (xfer->max_packet_size < std_size.range.min) {
356 xfer->max_packet_size = std_size.range.min;
357 }
358 if (xfer->max_packet_size > std_size.range.max) {
359 xfer->max_packet_size = std_size.range.max;

--- 9 unchanged lines hidden (view full) ---

369 } else {
370 /* only one possibility left */
371 xfer->max_packet_size = std_size.fixed[0];
372 }
373 }
374
375 /* compute "max_frame_size" */
376
377 usb2_update_max_frame_size(xfer);
377 usbd_update_max_frame_size(xfer);
378
379 /* check interrupt interval and transfer pre-delay */
380
381 if (type == UE_ISOCHRONOUS) {
382
383 uint16_t frame_limit;
384
385 xfer->interval = 0; /* not used, must be zero */

--- 87 unchanged lines hidden (view full) ---

473 if ((parm->bufsize <= MIN_PKT) &&
474 (type != UE_CONTROL) &&
475 (type != UE_BULK)) {
476
477 /* workaround */
478 xfer->max_packet_size = MIN_PKT;
479 xfer->max_packet_count = 1;
480 parm->bufsize = 0; /* automatic setup length */
378
379 /* check interrupt interval and transfer pre-delay */
380
381 if (type == UE_ISOCHRONOUS) {
382
383 uint16_t frame_limit;
384
385 xfer->interval = 0; /* not used, must be zero */

--- 87 unchanged lines hidden (view full) ---

473 if ((parm->bufsize <= MIN_PKT) &&
474 (type != UE_CONTROL) &&
475 (type != UE_BULK)) {
476
477 /* workaround */
478 xfer->max_packet_size = MIN_PKT;
479 xfer->max_packet_count = 1;
480 parm->bufsize = 0; /* automatic setup length */
481 usb2_update_max_frame_size(xfer);
481 usbd_update_max_frame_size(xfer);
482
483 } else {
484 parm->err = USB_ERR_ZERO_MAXP;
485 goto done;
486 }
487
488 } else {
489 zmps = 0;

--- 106 unchanged lines hidden (view full) ---

596 /* align data */
597 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
598
599 if (parm->buf) {
600
601 xfer->local_buffer =
602 USB_ADD_BYTES(parm->buf, parm->size[0]);
603
482
483 } else {
484 parm->err = USB_ERR_ZERO_MAXP;
485 goto done;
486 }
487
488 } else {
489 zmps = 0;

--- 106 unchanged lines hidden (view full) ---

596 /* align data */
597 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
598
599 if (parm->buf) {
600
601 xfer->local_buffer =
602 USB_ADD_BYTES(parm->buf, parm->size[0]);
603
604 usb2_set_frame_offset(xfer, 0, 0);
604 usbd_set_frame_offset(xfer, 0, 0);
605
606 if ((type == UE_CONTROL) && (n_frbuffers > 1)) {
605
606 if ((type == UE_CONTROL) && (n_frbuffers > 1)) {
607 usb2_set_frame_offset(xfer, REQ_SIZE, 1);
607 usbd_set_frame_offset(xfer, REQ_SIZE, 1);
608 }
609 }
610 parm->size[0] += parm->bufsize;
611
612 /* align data again */
613 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
614 }
615 /*

--- 55 unchanged lines hidden (view full) ---

671 if (parm->buf) {
672 for (x = 0; x != n_frbuffers; x++) {
673 xfer->frbuffers[x].tag_parent =
674 &xfer->xroot->dma_parent_tag;
675#if USB_HAVE_BUSDMA
676 if (xfer->flags_int.bdma_enable &&
677 (parm->bufsize_max > 0)) {
678
608 }
609 }
610 parm->size[0] += parm->bufsize;
611
612 /* align data again */
613 parm->size[0] += ((-parm->size[0]) & (USB_HOST_ALIGN - 1));
614 }
615 /*

--- 55 unchanged lines hidden (view full) ---

671 if (parm->buf) {
672 for (x = 0; x != n_frbuffers; x++) {
673 xfer->frbuffers[x].tag_parent =
674 &xfer->xroot->dma_parent_tag;
675#if USB_HAVE_BUSDMA
676 if (xfer->flags_int.bdma_enable &&
677 (parm->bufsize_max > 0)) {
678
679 if (usb2_pc_dmamap_create(
679 if (usb_pc_dmamap_create(
680 xfer->frbuffers + x,
681 parm->bufsize_max)) {
682 parm->err = USB_ERR_NOMEM;
683 goto done;
684 }
685 }
686#endif
687 }

--- 8 unchanged lines hidden (view full) ---

696 xfer->max_packet_size = 1;
697 xfer->max_data_length = 0;
698 xfer->nframes = 0;
699 xfer->max_frame_count = 0;
700 }
701}
702
703/*------------------------------------------------------------------------*
680 xfer->frbuffers + x,
681 parm->bufsize_max)) {
682 parm->err = USB_ERR_NOMEM;
683 goto done;
684 }
685 }
686#endif
687 }

--- 8 unchanged lines hidden (view full) ---

696 xfer->max_packet_size = 1;
697 xfer->max_data_length = 0;
698 xfer->nframes = 0;
699 xfer->max_frame_count = 0;
700 }
701}
702
703/*------------------------------------------------------------------------*
704 * usb2_transfer_setup - setup an array of USB transfers
704 * usbd_transfer_setup - setup an array of USB transfers
705 *
705 *
706 * NOTE: You must always call "usb2_transfer_unsetup" after calling
707 * "usb2_transfer_setup" if success was returned.
706 * NOTE: You must always call "usbd_transfer_unsetup" after calling
707 * "usbd_transfer_setup" if success was returned.
708 *
709 * The idea is that the USB device driver should pre-allocate all its
710 * transfers by one call to this function.
711 *
712 * Return values:
713 * 0: Success
714 * Else: Failure
715 *------------------------------------------------------------------------*/
716usb_error_t
708 *
709 * The idea is that the USB device driver should pre-allocate all its
710 * transfers by one call to this function.
711 *
712 * Return values:
713 * 0: Success
714 * Else: Failure
715 *------------------------------------------------------------------------*/
716usb_error_t
717usb2_transfer_setup(struct usb_device *udev,
717usbd_transfer_setup(struct usb_device *udev,
718 const uint8_t *ifaces, struct usb_xfer **ppxfer,
719 const struct usb_config *setup_start, uint16_t n_setup,
720 void *priv_sc, struct mtx *xfer_mtx)
721{
722 struct usb_xfer dummy;
723 struct usb_setup_params parm;
724 const struct usb_config *setup_end = setup_start + n_setup;
725 const struct usb_config *setup;

--- 4 unchanged lines hidden (view full) ---

730 uint16_t n;
731 uint16_t refcount;
732
733 parm.err = 0;
734 refcount = 0;
735 info = NULL;
736
737 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
718 const uint8_t *ifaces, struct usb_xfer **ppxfer,
719 const struct usb_config *setup_start, uint16_t n_setup,
720 void *priv_sc, struct mtx *xfer_mtx)
721{
722 struct usb_xfer dummy;
723 struct usb_setup_params parm;
724 const struct usb_config *setup_end = setup_start + n_setup;
725 const struct usb_config *setup;

--- 4 unchanged lines hidden (view full) ---

730 uint16_t n;
731 uint16_t refcount;
732
733 parm.err = 0;
734 refcount = 0;
735 info = NULL;
736
737 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
738 "usb2_transfer_setup can sleep!");
738 "usbd_transfer_setup can sleep!");
739
740 /* do some checking first */
741
742 if (n_setup == 0) {
743 DPRINTFN(6, "setup array has zero length!\n");
744 return (USB_ERR_INVAL);
745 }
746 if (ifaces == 0) {

--- 19 unchanged lines hidden (view full) ---

766 }
767
768 if (parm.err) {
769 goto done;
770 }
771 bzero(&parm, sizeof(parm));
772
773 parm.udev = udev;
739
740 /* do some checking first */
741
742 if (n_setup == 0) {
743 DPRINTFN(6, "setup array has zero length!\n");
744 return (USB_ERR_INVAL);
745 }
746 if (ifaces == 0) {

--- 19 unchanged lines hidden (view full) ---

766 }
767
768 if (parm.err) {
769 goto done;
770 }
771 bzero(&parm, sizeof(parm));
772
773 parm.udev = udev;
774 parm.speed = usb2_get_speed(udev);
774 parm.speed = usbd_get_speed(udev);
775 parm.hc_max_packet_count = 1;
776
777 if (parm.speed >= USB_SPEED_MAX) {
778 parm.err = USB_ERR_INVAL;
779 goto done;
780 }
781 /* setup all transfers */
782

--- 15 unchanged lines hidden (view full) ---

798#endif
799 info->xfer_page_cache_start = USB_ADD_BYTES(buf, parm.size[5]);
800 info->xfer_page_cache_end = USB_ADD_BYTES(buf, parm.size[2]);
801
802 cv_init(&info->cv_drain, "WDRAIN");
803
804 info->xfer_mtx = xfer_mtx;
805#if USB_HAVE_BUSDMA
775 parm.hc_max_packet_count = 1;
776
777 if (parm.speed >= USB_SPEED_MAX) {
778 parm.err = USB_ERR_INVAL;
779 goto done;
780 }
781 /* setup all transfers */
782

--- 15 unchanged lines hidden (view full) ---

798#endif
799 info->xfer_page_cache_start = USB_ADD_BYTES(buf, parm.size[5]);
800 info->xfer_page_cache_end = USB_ADD_BYTES(buf, parm.size[2]);
801
802 cv_init(&info->cv_drain, "WDRAIN");
803
804 info->xfer_mtx = xfer_mtx;
805#if USB_HAVE_BUSDMA
806 usb2_dma_tag_setup(&info->dma_parent_tag,
806 usb_dma_tag_setup(&info->dma_parent_tag,
807 parm.dma_tag_p, udev->bus->dma_parent_tag[0].tag,
807 parm.dma_tag_p, udev->bus->dma_parent_tag[0].tag,
808 xfer_mtx, &usb2_bdma_done_event, 32, parm.dma_tag_max);
808 xfer_mtx, &usb_bdma_done_event, 32, parm.dma_tag_max);
809#endif
810
811 info->bus = udev->bus;
812 info->udev = udev;
813
814 TAILQ_INIT(&info->done_q.head);
809#endif
810
811 info->bus = udev->bus;
812 info->udev = udev;
813
814 TAILQ_INIT(&info->done_q.head);
815 info->done_q.command = &usb2_callback_wrapper;
815 info->done_q.command = &usbd_callback_wrapper;
816#if USB_HAVE_BUSDMA
817 TAILQ_INIT(&info->dma_q.head);
816#if USB_HAVE_BUSDMA
817 TAILQ_INIT(&info->dma_q.head);
818 info->dma_q.command = &usb2_bdma_work_loop;
818 info->dma_q.command = &usb_bdma_work_loop;
819#endif
819#endif
820 info->done_m[0].hdr.pm_callback = &usb2_callback_proc;
820 info->done_m[0].hdr.pm_callback = &usb_callback_proc;
821 info->done_m[0].xroot = info;
821 info->done_m[0].xroot = info;
822 info->done_m[1].hdr.pm_callback = &usb2_callback_proc;
822 info->done_m[1].hdr.pm_callback = &usb_callback_proc;
823 info->done_m[1].xroot = info;
824
825 /*
826 * In device side mode control endpoint
827 * requests need to run from a separate
828 * context, else there is a chance of
829 * deadlock!
830 */
823 info->done_m[1].xroot = info;
824
825 /*
826 * In device side mode control endpoint
827 * requests need to run from a separate
828 * context, else there is a chance of
829 * deadlock!
830 */
831 if (setup_start == usb2_control_ep_cfg)
831 if (setup_start == usb_control_ep_cfg)
832 info->done_p =
833 &udev->bus->control_xfer_proc;
834 else if (xfer_mtx == &Giant)
835 info->done_p =
836 &udev->bus->giant_callback_proc;
837 else
838 info->done_p =
839 &udev->bus->non_giant_callback_proc;

--- 7 unchanged lines hidden (view full) ---

847 for (setup = setup_start, n = 0;
848 setup != setup_end; setup++, n++) {
849
850 /* skip USB transfers without callbacks: */
851 if (setup->callback == NULL) {
852 continue;
853 }
854 /* see if there is a matching endpoint */
832 info->done_p =
833 &udev->bus->control_xfer_proc;
834 else if (xfer_mtx == &Giant)
835 info->done_p =
836 &udev->bus->giant_callback_proc;
837 else
838 info->done_p =
839 &udev->bus->non_giant_callback_proc;

--- 7 unchanged lines hidden (view full) ---

847 for (setup = setup_start, n = 0;
848 setup != setup_end; setup++, n++) {
849
850 /* skip USB transfers without callbacks: */
851 if (setup->callback == NULL) {
852 continue;
853 }
854 /* see if there is a matching endpoint */
855 ep = usb2_get_endpoint(udev,
855 ep = usbd_get_endpoint(udev,
856 ifaces[setup->if_index], setup);
857
858 if ((ep == NULL) || (ep->methods == NULL)) {
859 if (setup->flags.no_pipe_ok)
860 continue;
861 if ((setup->usb_mode != USB_MODE_DUAL) &&
862 (setup->usb_mode != udev->flags.usb_mode))
863 continue;

--- 12 unchanged lines hidden (view full) ---

876 * Common initialization of the
877 * "usb_xfer" structure.
878 */
879 xfer = USB_ADD_BYTES(buf, parm.size[0]);
880 xfer->address = udev->address;
881 xfer->priv_sc = priv_sc;
882 xfer->xroot = info;
883
856 ifaces[setup->if_index], setup);
857
858 if ((ep == NULL) || (ep->methods == NULL)) {
859 if (setup->flags.no_pipe_ok)
860 continue;
861 if ((setup->usb_mode != USB_MODE_DUAL) &&
862 (setup->usb_mode != udev->flags.usb_mode))
863 continue;

--- 12 unchanged lines hidden (view full) ---

876 * Common initialization of the
877 * "usb_xfer" structure.
878 */
879 xfer = USB_ADD_BYTES(buf, parm.size[0]);
880 xfer->address = udev->address;
881 xfer->priv_sc = priv_sc;
882 xfer->xroot = info;
883
884 usb2_callout_init_mtx(&xfer->timeout_handle,
884 usb_callout_init_mtx(&xfer->timeout_handle,
885 &udev->bus->bus_mtx, 0);
886 } else {
887 /*
888 * Setup a dummy xfer, hence we are
889 * writing to the "usb_xfer"
890 * structure pointed to by "xfer"
891 * before we have allocated any
892 * memory:

--- 133 unchanged lines hidden (view full) ---

1026 parm.xfer_page_cache_ptr = USB_ADD_BYTES(buf, parm.size[5]);
1027 parm.xfer_length_ptr = USB_ADD_BYTES(buf, parm.size[6]);
1028 }
1029
1030done:
1031 if (buf) {
1032 if (info->setup_refcount == 0) {
1033 /*
885 &udev->bus->bus_mtx, 0);
886 } else {
887 /*
888 * Setup a dummy xfer, hence we are
889 * writing to the "usb_xfer"
890 * structure pointed to by "xfer"
891 * before we have allocated any
892 * memory:

--- 133 unchanged lines hidden (view full) ---

1026 parm.xfer_page_cache_ptr = USB_ADD_BYTES(buf, parm.size[5]);
1027 parm.xfer_length_ptr = USB_ADD_BYTES(buf, parm.size[6]);
1028 }
1029
1030done:
1031 if (buf) {
1032 if (info->setup_refcount == 0) {
1033 /*
1034 * "usb2_transfer_unsetup_sub" will unlock
1034 * "usbd_transfer_unsetup_sub" will unlock
1035 * the bus mutex before returning !
1036 */
1037 USB_BUS_LOCK(info->bus);
1038
1039 /* something went wrong */
1035 * the bus mutex before returning !
1036 */
1037 USB_BUS_LOCK(info->bus);
1038
1039 /* something went wrong */
1040 usb2_transfer_unsetup_sub(info, 0);
1040 usbd_transfer_unsetup_sub(info, 0);
1041 }
1042 }
1043 if (parm.err) {
1041 }
1042 }
1043 if (parm.err) {
1044 usb2_transfer_unsetup(ppxfer, n_setup);
1044 usbd_transfer_unsetup(ppxfer, n_setup);
1045 }
1046 return (parm.err);
1047}
1048
1049/*------------------------------------------------------------------------*
1045 }
1046 return (parm.err);
1047}
1048
1049/*------------------------------------------------------------------------*
1050 * usb2_transfer_unsetup_sub - factored out code
1050 * usbd_transfer_unsetup_sub - factored out code
1051 *------------------------------------------------------------------------*/
1052static void
1051 *------------------------------------------------------------------------*/
1052static void
1053usb2_transfer_unsetup_sub(struct usb_xfer_root *info, uint8_t needs_delay)
1053usbd_transfer_unsetup_sub(struct usb_xfer_root *info, uint8_t needs_delay)
1054{
1055 struct usb_page_cache *pc;
1056
1057 USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
1058
1059 /* wait for any outstanding DMA operations */
1060
1061 if (needs_delay) {
1062 usb_timeout_t temp;
1054{
1055 struct usb_page_cache *pc;
1056
1057 USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
1058
1059 /* wait for any outstanding DMA operations */
1060
1061 if (needs_delay) {
1062 usb_timeout_t temp;
1063 temp = usb2_get_dma_delay(info->bus);
1064 usb2_pause_mtx(&info->bus->bus_mtx,
1063 temp = usbd_get_dma_delay(info->bus);
1064 usb_pause_mtx(&info->bus->bus_mtx,
1065 USB_MS_TO_TICKS(temp));
1066 }
1067
1068 /* make sure that our done messages are not queued anywhere */
1065 USB_MS_TO_TICKS(temp));
1066 }
1067
1068 /* make sure that our done messages are not queued anywhere */
1069 usb2_proc_mwait(info->done_p, &info->done_m[0], &info->done_m[1]);
1069 usb_proc_mwait(info->done_p, &info->done_m[0], &info->done_m[1]);
1070
1071 USB_BUS_UNLOCK(info->bus);
1072
1073#if USB_HAVE_BUSDMA
1074 /* free DMA'able memory, if any */
1075 pc = info->dma_page_cache_start;
1076 while (pc != info->dma_page_cache_end) {
1070
1071 USB_BUS_UNLOCK(info->bus);
1072
1073#if USB_HAVE_BUSDMA
1074 /* free DMA'able memory, if any */
1075 pc = info->dma_page_cache_start;
1076 while (pc != info->dma_page_cache_end) {
1077 usb2_pc_free_mem(pc);
1077 usb_pc_free_mem(pc);
1078 pc++;
1079 }
1080
1081 /* free DMA maps in all "xfer->frbuffers" */
1082 pc = info->xfer_page_cache_start;
1083 while (pc != info->xfer_page_cache_end) {
1078 pc++;
1079 }
1080
1081 /* free DMA maps in all "xfer->frbuffers" */
1082 pc = info->xfer_page_cache_start;
1083 while (pc != info->xfer_page_cache_end) {
1084 usb2_pc_dmamap_destroy(pc);
1084 usb_pc_dmamap_destroy(pc);
1085 pc++;
1086 }
1087
1088 /* free all DMA tags */
1085 pc++;
1086 }
1087
1088 /* free all DMA tags */
1089 usb2_dma_tag_unsetup(&info->dma_parent_tag);
1089 usb_dma_tag_unsetup(&info->dma_parent_tag);
1090#endif
1091
1092 cv_destroy(&info->cv_drain);
1093
1094 /*
1095 * free the "memory_base" last, hence the "info" structure is
1096 * contained within the "memory_base"!
1097 */
1098 free(info->memory_base, M_USB);
1099}
1100
1101/*------------------------------------------------------------------------*
1090#endif
1091
1092 cv_destroy(&info->cv_drain);
1093
1094 /*
1095 * free the "memory_base" last, hence the "info" structure is
1096 * contained within the "memory_base"!
1097 */
1098 free(info->memory_base, M_USB);
1099}
1100
1101/*------------------------------------------------------------------------*
1102 * usb2_transfer_unsetup - unsetup/free an array of USB transfers
1102 * usbd_transfer_unsetup - unsetup/free an array of USB transfers
1103 *
1104 * NOTE: All USB transfers in progress will get called back passing
1105 * the error code "USB_ERR_CANCELLED" before this function
1106 * returns.
1107 *------------------------------------------------------------------------*/
1108void
1103 *
1104 * NOTE: All USB transfers in progress will get called back passing
1105 * the error code "USB_ERR_CANCELLED" before this function
1106 * returns.
1107 *------------------------------------------------------------------------*/
1108void
1109usb2_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
1109usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup)
1110{
1111 struct usb_xfer *xfer;
1112 struct usb_xfer_root *info;
1113 uint8_t needs_delay = 0;
1114
1115 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1110{
1111 struct usb_xfer *xfer;
1112 struct usb_xfer_root *info;
1113 uint8_t needs_delay = 0;
1114
1115 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1116 "usb2_transfer_unsetup can sleep!");
1116 "usbd_transfer_unsetup can sleep!");
1117
1118 while (n_setup--) {
1119 xfer = pxfer[n_setup];
1120
1121 if (xfer == NULL)
1122 continue;
1123
1124 info = xfer->xroot;
1125
1126 USB_XFER_LOCK(xfer);
1127 USB_BUS_LOCK(info->bus);
1128
1129 /*
1130 * HINT: when you start/stop a transfer, it might be a
1131 * good idea to directly use the "pxfer[]" structure:
1132 *
1117
1118 while (n_setup--) {
1119 xfer = pxfer[n_setup];
1120
1121 if (xfer == NULL)
1122 continue;
1123
1124 info = xfer->xroot;
1125
1126 USB_XFER_LOCK(xfer);
1127 USB_BUS_LOCK(info->bus);
1128
1129 /*
1130 * HINT: when you start/stop a transfer, it might be a
1131 * good idea to directly use the "pxfer[]" structure:
1132 *
1133 * usb2_transfer_start(sc->pxfer[0]);
1134 * usb2_transfer_stop(sc->pxfer[0]);
1133 * usbd_transfer_start(sc->pxfer[0]);
1134 * usbd_transfer_stop(sc->pxfer[0]);
1135 *
1136 * That way, if your code has many parts that will not
1137 * stop running under the same lock, in other words
1135 *
1136 * That way, if your code has many parts that will not
1137 * stop running under the same lock, in other words
1138 * "xfer_mtx", the usb2_transfer_start and
1139 * usb2_transfer_stop functions will simply return
1138 * "xfer_mtx", the usbd_transfer_start and
1139 * usbd_transfer_stop functions will simply return
1140 * when they detect a NULL pointer argument.
1141 *
1142 * To avoid any races we clear the "pxfer[]" pointer
1143 * while holding the private mutex of the driver:
1144 */
1145 pxfer[n_setup] = NULL;
1146
1147 USB_BUS_UNLOCK(info->bus);
1148 USB_XFER_UNLOCK(xfer);
1149
1140 * when they detect a NULL pointer argument.
1141 *
1142 * To avoid any races we clear the "pxfer[]" pointer
1143 * while holding the private mutex of the driver:
1144 */
1145 pxfer[n_setup] = NULL;
1146
1147 USB_BUS_UNLOCK(info->bus);
1148 USB_XFER_UNLOCK(xfer);
1149
1150 usb2_transfer_drain(xfer);
1150 usbd_transfer_drain(xfer);
1151
1152#if USB_HAVE_BUSDMA
1153 if (xfer->flags_int.bdma_enable)
1154 needs_delay = 1;
1155#endif
1156 /*
1157 * NOTE: default endpoint does not have an
1158 * interface, even if endpoint->iface_index == 0
1159 */
1160 xfer->endpoint->refcount--;
1161
1151
1152#if USB_HAVE_BUSDMA
1153 if (xfer->flags_int.bdma_enable)
1154 needs_delay = 1;
1155#endif
1156 /*
1157 * NOTE: default endpoint does not have an
1158 * interface, even if endpoint->iface_index == 0
1159 */
1160 xfer->endpoint->refcount--;
1161
1162 usb2_callout_drain(&xfer->timeout_handle);
1162 usb_callout_drain(&xfer->timeout_handle);
1163
1164 USB_BUS_LOCK(info->bus);
1165
1166 USB_ASSERT(info->setup_refcount != 0, ("Invalid setup "
1167 "reference count!\n"));
1168
1169 info->setup_refcount--;
1170
1171 if (info->setup_refcount == 0) {
1163
1164 USB_BUS_LOCK(info->bus);
1165
1166 USB_ASSERT(info->setup_refcount != 0, ("Invalid setup "
1167 "reference count!\n"));
1168
1169 info->setup_refcount--;
1170
1171 if (info->setup_refcount == 0) {
1172 usb2_transfer_unsetup_sub(info,
1172 usbd_transfer_unsetup_sub(info,
1173 needs_delay);
1174 } else {
1175 USB_BUS_UNLOCK(info->bus);
1176 }
1177 }
1178}
1179
1180/*------------------------------------------------------------------------*
1173 needs_delay);
1174 } else {
1175 USB_BUS_UNLOCK(info->bus);
1176 }
1177 }
1178}
1179
1180/*------------------------------------------------------------------------*
1181 * usb2_control_transfer_init - factored out code
1181 * usbd_control_transfer_init - factored out code
1182 *
1183 * In USB Device Mode we have to wait for the SETUP packet which
1184 * containst the "struct usb_device_request" structure, before we can
1185 * transfer any data. In USB Host Mode we already have the SETUP
1186 * packet at the moment the USB transfer is started. This leads us to
1187 * having to setup the USB transfer at two different places in
1188 * time. This function just contains factored out control transfer
1189 * initialisation code, so that we don't duplicate the code.
1190 *------------------------------------------------------------------------*/
1191static void
1182 *
1183 * In USB Device Mode we have to wait for the SETUP packet which
1184 * containst the "struct usb_device_request" structure, before we can
1185 * transfer any data. In USB Host Mode we already have the SETUP
1186 * packet at the moment the USB transfer is started. This leads us to
1187 * having to setup the USB transfer at two different places in
1188 * time. This function just contains factored out control transfer
1189 * initialisation code, so that we don't duplicate the code.
1190 *------------------------------------------------------------------------*/
1191static void
1192usb2_control_transfer_init(struct usb_xfer *xfer)
1192usbd_control_transfer_init(struct usb_xfer *xfer)
1193{
1194 struct usb_device_request req;
1195
1196 /* copy out the USB request header */
1197
1193{
1194 struct usb_device_request req;
1195
1196 /* copy out the USB request header */
1197
1198 usb2_copy_out(xfer->frbuffers, 0, &req, sizeof(req));
1198 usbd_copy_out(xfer->frbuffers, 0, &req, sizeof(req));
1199
1200 /* setup remainder */
1201
1202 xfer->flags_int.control_rem = UGETW(req.wLength);
1203
1204 /* copy direction to endpoint variable */
1205
1206 xfer->endpointno &= ~(UE_DIR_IN | UE_DIR_OUT);
1207 xfer->endpointno |=
1208 (req.bmRequestType & UT_READ) ? UE_DIR_IN : UE_DIR_OUT;
1209}
1210
1211/*------------------------------------------------------------------------*
1199
1200 /* setup remainder */
1201
1202 xfer->flags_int.control_rem = UGETW(req.wLength);
1203
1204 /* copy direction to endpoint variable */
1205
1206 xfer->endpointno &= ~(UE_DIR_IN | UE_DIR_OUT);
1207 xfer->endpointno |=
1208 (req.bmRequestType & UT_READ) ? UE_DIR_IN : UE_DIR_OUT;
1209}
1210
1211/*------------------------------------------------------------------------*
1212 * usb2_start_hardware_sub
1212 * usbd_start_hardware_sub
1213 *
1214 * This function handles initialisation of control transfers. Control
1215 * transfers are special in that regard that they can both transmit
1216 * and receive data.
1217 *
1218 * Return values:
1219 * 0: Success
1220 * Else: Failure
1221 *------------------------------------------------------------------------*/
1222static uint8_t
1213 *
1214 * This function handles initialisation of control transfers. Control
1215 * transfers are special in that regard that they can both transmit
1216 * and receive data.
1217 *
1218 * Return values:
1219 * 0: Success
1220 * Else: Failure
1221 *------------------------------------------------------------------------*/
1222static uint8_t
1223usb2_start_hardware_sub(struct usb_xfer *xfer)
1223usbd_start_hardware_sub(struct usb_xfer *xfer)
1224{
1225 usb_frlength_t len;
1226
1227 /* Check for control endpoint stall */
1228 if (xfer->flags.stall_pipe && xfer->flags_int.control_act) {
1229 /* the control transfer is no longer active */
1230 xfer->flags_int.control_stall = 1;
1231 xfer->flags_int.control_act = 0;

--- 24 unchanged lines hidden (view full) ---

1256 if (xfer->flags_int.control_hdr) {
1257
1258 /* clear send header flag */
1259
1260 xfer->flags_int.control_hdr = 0;
1261
1262 /* setup control transfer */
1263 if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) {
1224{
1225 usb_frlength_t len;
1226
1227 /* Check for control endpoint stall */
1228 if (xfer->flags.stall_pipe && xfer->flags_int.control_act) {
1229 /* the control transfer is no longer active */
1230 xfer->flags_int.control_stall = 1;
1231 xfer->flags_int.control_act = 0;

--- 24 unchanged lines hidden (view full) ---

1256 if (xfer->flags_int.control_hdr) {
1257
1258 /* clear send header flag */
1259
1260 xfer->flags_int.control_hdr = 0;
1261
1262 /* setup control transfer */
1263 if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) {
1264 usb2_control_transfer_init(xfer);
1264 usbd_control_transfer_init(xfer);
1265 }
1266 }
1267 /* get data length */
1268
1269 len = xfer->sumlen;
1270
1271 } else {
1272

--- 16 unchanged lines hidden (view full) ---

1289 * data direction!
1290 */
1291 DPRINTF("Misconfigured transfer\n");
1292 goto error;
1293 }
1294 /*
1295 * Set a dummy "control_rem" value. This
1296 * variable will be overwritten later by a
1265 }
1266 }
1267 /* get data length */
1268
1269 len = xfer->sumlen;
1270
1271 } else {
1272

--- 16 unchanged lines hidden (view full) ---

1289 * data direction!
1290 */
1291 DPRINTF("Misconfigured transfer\n");
1292 goto error;
1293 }
1294 /*
1295 * Set a dummy "control_rem" value. This
1296 * variable will be overwritten later by a
1297 * call to "usb2_control_transfer_init()" !
1297 * call to "usbd_control_transfer_init()" !
1298 */
1299 xfer->flags_int.control_rem = 0xFFFF;
1300 } else {
1301
1302 /* setup "endpoint" and "control_rem" */
1303
1298 */
1299 xfer->flags_int.control_rem = 0xFFFF;
1300 } else {
1301
1302 /* setup "endpoint" and "control_rem" */
1303
1304 usb2_control_transfer_init(xfer);
1304 usbd_control_transfer_init(xfer);
1305 }
1306
1307 /* set transfer-header flag */
1308
1309 xfer->flags_int.control_hdr = 1;
1310
1311 /* get data length */
1312

--- 44 unchanged lines hidden (view full) ---

1357 }
1358 return (0); /* success */
1359
1360error:
1361 return (1); /* failure */
1362}
1363
1364/*------------------------------------------------------------------------*
1305 }
1306
1307 /* set transfer-header flag */
1308
1309 xfer->flags_int.control_hdr = 1;
1310
1311 /* get data length */
1312

--- 44 unchanged lines hidden (view full) ---

1357 }
1358 return (0); /* success */
1359
1360error:
1361 return (1); /* failure */
1362}
1363
1364/*------------------------------------------------------------------------*
1365 * usb2_start_hardware - start USB hardware for the given transfer
1365 * usbd_transfer_submit - start USB hardware for the given transfer
1366 *
1367 * This function should only be called from the USB callback.
1368 *------------------------------------------------------------------------*/
1369void
1366 *
1367 * This function should only be called from the USB callback.
1368 *------------------------------------------------------------------------*/
1369void
1370usb2_start_hardware(struct usb_xfer *xfer)
1370usbd_transfer_submit(struct usb_xfer *xfer)
1371{
1372 struct usb_xfer_root *info;
1373 struct usb_bus *bus;
1374 usb_frcount_t x;
1375
1376 info = xfer->xroot;
1377 bus = info->bus;
1378
1379 DPRINTF("xfer=%p, endpoint=%p, nframes=%d, dir=%s\n",
1380 xfer, xfer->endpoint, xfer->nframes, USB_GET_DATA_ISREAD(xfer) ?
1381 "read" : "write");
1382
1383#if USB_DEBUG
1384 if (USB_DEBUG_VAR > 0) {
1385 USB_BUS_LOCK(bus);
1386
1371{
1372 struct usb_xfer_root *info;
1373 struct usb_bus *bus;
1374 usb_frcount_t x;
1375
1376 info = xfer->xroot;
1377 bus = info->bus;
1378
1379 DPRINTF("xfer=%p, endpoint=%p, nframes=%d, dir=%s\n",
1380 xfer, xfer->endpoint, xfer->nframes, USB_GET_DATA_ISREAD(xfer) ?
1381 "read" : "write");
1382
1383#if USB_DEBUG
1384 if (USB_DEBUG_VAR > 0) {
1385 USB_BUS_LOCK(bus);
1386
1387 usb2_dump_endpoint(xfer->endpoint);
1387 usb_dump_endpoint(xfer->endpoint);
1388
1389 USB_BUS_UNLOCK(bus);
1390 }
1391#endif
1392
1393 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
1394 USB_BUS_LOCK_ASSERT(bus, MA_NOTOWNED);
1395

--- 7 unchanged lines hidden (view full) ---

1403 (xfer->endpoint->methods->open) (xfer);
1404 USB_BUS_UNLOCK(bus);
1405 }
1406 /* set "transferring" flag */
1407 xfer->flags_int.transferring = 1;
1408
1409#if USB_HAVE_POWERD
1410 /* increment power reference */
1388
1389 USB_BUS_UNLOCK(bus);
1390 }
1391#endif
1392
1393 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
1394 USB_BUS_LOCK_ASSERT(bus, MA_NOTOWNED);
1395

--- 7 unchanged lines hidden (view full) ---

1403 (xfer->endpoint->methods->open) (xfer);
1404 USB_BUS_UNLOCK(bus);
1405 }
1406 /* set "transferring" flag */
1407 xfer->flags_int.transferring = 1;
1408
1409#if USB_HAVE_POWERD
1410 /* increment power reference */
1411 usb2_transfer_power_ref(xfer, 1);
1411 usbd_transfer_power_ref(xfer, 1);
1412#endif
1413 /*
1414 * Check if the transfer is waiting on a queue, most
1415 * frequently the "done_q":
1416 */
1417 if (xfer->wait_queue) {
1418 USB_BUS_LOCK(bus);
1412#endif
1413 /*
1414 * Check if the transfer is waiting on a queue, most
1415 * frequently the "done_q":
1416 */
1417 if (xfer->wait_queue) {
1418 USB_BUS_LOCK(bus);
1419 usb2_transfer_dequeue(xfer);
1419 usbd_transfer_dequeue(xfer);
1420 USB_BUS_UNLOCK(bus);
1421 }
1422 /* clear "did_dma_delay" flag */
1423 xfer->flags_int.did_dma_delay = 0;
1424
1425 /* clear "did_close" flag */
1426 xfer->flags_int.did_close = 0;
1427

--- 14 unchanged lines hidden (view full) ---

1442
1443 /* Check if the device is still alive */
1444 if (info->udev->state < USB_STATE_POWERED) {
1445 USB_BUS_LOCK(bus);
1446 /*
1447 * Must return cancelled error code else
1448 * device drivers can hang.
1449 */
1420 USB_BUS_UNLOCK(bus);
1421 }
1422 /* clear "did_dma_delay" flag */
1423 xfer->flags_int.did_dma_delay = 0;
1424
1425 /* clear "did_close" flag */
1426 xfer->flags_int.did_close = 0;
1427

--- 14 unchanged lines hidden (view full) ---

1442
1443 /* Check if the device is still alive */
1444 if (info->udev->state < USB_STATE_POWERED) {
1445 USB_BUS_LOCK(bus);
1446 /*
1447 * Must return cancelled error code else
1448 * device drivers can hang.
1449 */
1450 usb2_transfer_done(xfer, USB_ERR_CANCELLED);
1450 usbd_transfer_done(xfer, USB_ERR_CANCELLED);
1451 USB_BUS_UNLOCK(bus);
1452 return;
1453 }
1454
1455 /* sanity check */
1456 if (xfer->nframes == 0) {
1457 if (xfer->flags.stall_pipe) {
1458 /*
1459 * Special case - want to stall without transferring
1460 * any data:
1461 */
1462 DPRINTF("xfer=%p nframes=0: stall "
1463 "or clear stall!\n", xfer);
1464 USB_BUS_LOCK(bus);
1465 xfer->flags_int.can_cancel_immed = 1;
1466 /* start the transfer */
1451 USB_BUS_UNLOCK(bus);
1452 return;
1453 }
1454
1455 /* sanity check */
1456 if (xfer->nframes == 0) {
1457 if (xfer->flags.stall_pipe) {
1458 /*
1459 * Special case - want to stall without transferring
1460 * any data:
1461 */
1462 DPRINTF("xfer=%p nframes=0: stall "
1463 "or clear stall!\n", xfer);
1464 USB_BUS_LOCK(bus);
1465 xfer->flags_int.can_cancel_immed = 1;
1466 /* start the transfer */
1467 usb2_command_wrapper(&xfer->endpoint->endpoint_q, xfer);
1467 usb_command_wrapper(&xfer->endpoint->endpoint_q, xfer);
1468 USB_BUS_UNLOCK(bus);
1469 return;
1470 }
1471 USB_BUS_LOCK(bus);
1468 USB_BUS_UNLOCK(bus);
1469 return;
1470 }
1471 USB_BUS_LOCK(bus);
1472 usb2_transfer_done(xfer, USB_ERR_INVAL);
1472 usbd_transfer_done(xfer, USB_ERR_INVAL);
1473 USB_BUS_UNLOCK(bus);
1474 return;
1475 }
1476 /* compute total transfer length */
1477
1478 for (x = 0; x != xfer->nframes; x++) {
1479 xfer->sumlen += xfer->frlengths[x];
1480 if (xfer->sumlen < xfer->frlengths[x]) {
1481 /* length wrapped around */
1482 USB_BUS_LOCK(bus);
1473 USB_BUS_UNLOCK(bus);
1474 return;
1475 }
1476 /* compute total transfer length */
1477
1478 for (x = 0; x != xfer->nframes; x++) {
1479 xfer->sumlen += xfer->frlengths[x];
1480 if (xfer->sumlen < xfer->frlengths[x]) {
1481 /* length wrapped around */
1482 USB_BUS_LOCK(bus);
1483 usb2_transfer_done(xfer, USB_ERR_INVAL);
1483 usbd_transfer_done(xfer, USB_ERR_INVAL);
1484 USB_BUS_UNLOCK(bus);
1485 return;
1486 }
1487 }
1488
1489 /* clear some internal flags */
1490
1491 xfer->flags_int.short_xfer_ok = 0;
1492 xfer->flags_int.short_frames_ok = 0;
1493
1494 /* check if this is a control transfer */
1495
1496 if (xfer->flags_int.control_xfr) {
1497
1484 USB_BUS_UNLOCK(bus);
1485 return;
1486 }
1487 }
1488
1489 /* clear some internal flags */
1490
1491 xfer->flags_int.short_xfer_ok = 0;
1492 xfer->flags_int.short_frames_ok = 0;
1493
1494 /* check if this is a control transfer */
1495
1496 if (xfer->flags_int.control_xfr) {
1497
1498 if (usb2_start_hardware_sub(xfer)) {
1498 if (usbd_start_hardware_sub(xfer)) {
1499 USB_BUS_LOCK(bus);
1499 USB_BUS_LOCK(bus);
1500 usb2_transfer_done(xfer, USB_ERR_STALLED);
1500 usbd_transfer_done(xfer, USB_ERR_STALLED);
1501 USB_BUS_UNLOCK(bus);
1502 return;
1503 }
1504 }
1505 /*
1506 * Setup filtered version of some transfer flags,
1507 * in case of data read direction
1508 */

--- 26 unchanged lines hidden (view full) ---

1535 }
1536 /*
1537 * Check if BUS-DMA support is enabled and try to load virtual
1538 * buffers into DMA, if any:
1539 */
1540#if USB_HAVE_BUSDMA
1541 if (xfer->flags_int.bdma_enable) {
1542 /* insert the USB transfer last in the BUS-DMA queue */
1501 USB_BUS_UNLOCK(bus);
1502 return;
1503 }
1504 }
1505 /*
1506 * Setup filtered version of some transfer flags,
1507 * in case of data read direction
1508 */

--- 26 unchanged lines hidden (view full) ---

1535 }
1536 /*
1537 * Check if BUS-DMA support is enabled and try to load virtual
1538 * buffers into DMA, if any:
1539 */
1540#if USB_HAVE_BUSDMA
1541 if (xfer->flags_int.bdma_enable) {
1542 /* insert the USB transfer last in the BUS-DMA queue */
1543 usb2_command_wrapper(&xfer->xroot->dma_q, xfer);
1543 usb_command_wrapper(&xfer->xroot->dma_q, xfer);
1544 return;
1545 }
1546#endif
1547 /*
1548 * Enter the USB transfer into the Host Controller or
1549 * Device Controller schedule:
1550 */
1544 return;
1545 }
1546#endif
1547 /*
1548 * Enter the USB transfer into the Host Controller or
1549 * Device Controller schedule:
1550 */
1551 usb2_pipe_enter(xfer);
1551 usbd_pipe_enter(xfer);
1552}
1553
1554/*------------------------------------------------------------------------*
1552}
1553
1554/*------------------------------------------------------------------------*
1555 * usb2_pipe_enter - factored out code
1555 * usbd_pipe_enter - factored out code
1556 *------------------------------------------------------------------------*/
1557void
1556 *------------------------------------------------------------------------*/
1557void
1558usb2_pipe_enter(struct usb_xfer *xfer)
1558usbd_pipe_enter(struct usb_xfer *xfer)
1559{
1560 struct usb_endpoint *ep;
1561
1562 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
1563
1564 USB_BUS_LOCK(xfer->xroot->bus);
1565
1566 ep = xfer->endpoint;
1567
1568 DPRINTF("enter\n");
1569
1570 /* enter the transfer */
1571 (ep->methods->enter) (xfer);
1572
1573 xfer->flags_int.can_cancel_immed = 1;
1574
1575 /* check for transfer error */
1576 if (xfer->error) {
1577 /* some error has happened */
1559{
1560 struct usb_endpoint *ep;
1561
1562 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
1563
1564 USB_BUS_LOCK(xfer->xroot->bus);
1565
1566 ep = xfer->endpoint;
1567
1568 DPRINTF("enter\n");
1569
1570 /* enter the transfer */
1571 (ep->methods->enter) (xfer);
1572
1573 xfer->flags_int.can_cancel_immed = 1;
1574
1575 /* check for transfer error */
1576 if (xfer->error) {
1577 /* some error has happened */
1578 usb2_transfer_done(xfer, 0);
1578 usbd_transfer_done(xfer, 0);
1579 USB_BUS_UNLOCK(xfer->xroot->bus);
1580 return;
1581 }
1582
1583 /* start the transfer */
1579 USB_BUS_UNLOCK(xfer->xroot->bus);
1580 return;
1581 }
1582
1583 /* start the transfer */
1584 usb2_command_wrapper(&ep->endpoint_q, xfer);
1584 usb_command_wrapper(&ep->endpoint_q, xfer);
1585 USB_BUS_UNLOCK(xfer->xroot->bus);
1586}
1587
1588/*------------------------------------------------------------------------*
1585 USB_BUS_UNLOCK(xfer->xroot->bus);
1586}
1587
1588/*------------------------------------------------------------------------*
1589 * usb2_transfer_start - start an USB transfer
1589 * usbd_transfer_start - start an USB transfer
1590 *
1591 * NOTE: Calling this function more than one time will only
1592 * result in a single transfer start, until the USB transfer
1593 * completes.
1594 *------------------------------------------------------------------------*/
1595void
1590 *
1591 * NOTE: Calling this function more than one time will only
1592 * result in a single transfer start, until the USB transfer
1593 * completes.
1594 *------------------------------------------------------------------------*/
1595void
1596usb2_transfer_start(struct usb_xfer *xfer)
1596usbd_transfer_start(struct usb_xfer *xfer)
1597{
1598 if (xfer == NULL) {
1599 /* transfer is gone */
1600 return;
1601 }
1602 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
1603
1604 /* mark the USB transfer started */
1605
1606 if (!xfer->flags_int.started) {
1607 xfer->flags_int.started = 1;
1608 }
1609 /* check if the USB transfer callback is already transferring */
1610
1611 if (xfer->flags_int.transferring) {
1612 return;
1613 }
1614 USB_BUS_LOCK(xfer->xroot->bus);
1615 /* call the USB transfer callback */
1597{
1598 if (xfer == NULL) {
1599 /* transfer is gone */
1600 return;
1601 }
1602 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
1603
1604 /* mark the USB transfer started */
1605
1606 if (!xfer->flags_int.started) {
1607 xfer->flags_int.started = 1;
1608 }
1609 /* check if the USB transfer callback is already transferring */
1610
1611 if (xfer->flags_int.transferring) {
1612 return;
1613 }
1614 USB_BUS_LOCK(xfer->xroot->bus);
1615 /* call the USB transfer callback */
1616 usb2_callback_ss_done_defer(xfer);
1616 usbd_callback_ss_done_defer(xfer);
1617 USB_BUS_UNLOCK(xfer->xroot->bus);
1618}
1619
1620/*------------------------------------------------------------------------*
1617 USB_BUS_UNLOCK(xfer->xroot->bus);
1618}
1619
1620/*------------------------------------------------------------------------*
1621 * usb2_transfer_stop - stop an USB transfer
1621 * usbd_transfer_stop - stop an USB transfer
1622 *
1623 * NOTE: Calling this function more than one time will only
1624 * result in a single transfer stop.
1625 * NOTE: When this function returns it is not safe to free nor
1622 *
1623 * NOTE: Calling this function more than one time will only
1624 * result in a single transfer stop.
1625 * NOTE: When this function returns it is not safe to free nor
1626 * reuse any DMA buffers. See "usb2_transfer_drain()".
1626 * reuse any DMA buffers. See "usbd_transfer_drain()".
1627 *------------------------------------------------------------------------*/
1628void
1627 *------------------------------------------------------------------------*/
1628void
1629usb2_transfer_stop(struct usb_xfer *xfer)
1629usbd_transfer_stop(struct usb_xfer *xfer)
1630{
1631 struct usb_endpoint *ep;
1632
1633 if (xfer == NULL) {
1634 /* transfer is gone */
1635 return;
1636 }
1637 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);

--- 36 unchanged lines hidden (view full) ---

1674 } else {
1675 DPRINTF("close\n");
1676
1677 /* close here and now */
1678 (xfer->endpoint->methods->close) (xfer);
1679
1680 /*
1681 * Any additional DMA delay is done by
1630{
1631 struct usb_endpoint *ep;
1632
1633 if (xfer == NULL) {
1634 /* transfer is gone */
1635 return;
1636 }
1637 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);

--- 36 unchanged lines hidden (view full) ---

1674 } else {
1675 DPRINTF("close\n");
1676
1677 /* close here and now */
1678 (xfer->endpoint->methods->close) (xfer);
1679
1680 /*
1681 * Any additional DMA delay is done by
1682 * "usb2_transfer_unsetup()".
1682 * "usbd_transfer_unsetup()".
1683 */
1684
1685 /*
1686 * Special case. Check if we need to restart a blocked
1687 * endpoint.
1688 */
1689 ep = xfer->endpoint;
1690
1691 /*
1692 * If the current USB transfer is completing we need
1693 * to start the next one:
1694 */
1695 if (ep->endpoint_q.curr == xfer) {
1683 */
1684
1685 /*
1686 * Special case. Check if we need to restart a blocked
1687 * endpoint.
1688 */
1689 ep = xfer->endpoint;
1690
1691 /*
1692 * If the current USB transfer is completing we need
1693 * to start the next one:
1694 */
1695 if (ep->endpoint_q.curr == xfer) {
1696 usb2_command_wrapper(&ep->endpoint_q, NULL);
1696 usb_command_wrapper(&ep->endpoint_q, NULL);
1697 }
1698 }
1699
1700 USB_BUS_UNLOCK(xfer->xroot->bus);
1701}
1702
1703/*------------------------------------------------------------------------*
1697 }
1698 }
1699
1700 USB_BUS_UNLOCK(xfer->xroot->bus);
1701}
1702
1703/*------------------------------------------------------------------------*
1704 * usb2_transfer_pending
1704 * usbd_transfer_pending
1705 *
1706 * This function will check if an USB transfer is pending which is a
1707 * little bit complicated!
1708 * Return values:
1709 * 0: Not pending
1710 * 1: Pending: The USB transfer will receive a callback in the future.
1711 *------------------------------------------------------------------------*/
1712uint8_t
1705 *
1706 * This function will check if an USB transfer is pending which is a
1707 * little bit complicated!
1708 * Return values:
1709 * 0: Not pending
1710 * 1: Pending: The USB transfer will receive a callback in the future.
1711 *------------------------------------------------------------------------*/
1712uint8_t
1713usb2_transfer_pending(struct usb_xfer *xfer)
1713usbd_transfer_pending(struct usb_xfer *xfer)
1714{
1715 struct usb_xfer_root *info;
1716 struct usb_xfer_queue *pq;
1717
1718 if (xfer == NULL) {
1719 /* transfer is gone */
1720 return (0);
1721 }

--- 18 unchanged lines hidden (view full) ---

1740 return (1);
1741 }
1742 /* we are not pending */
1743 USB_BUS_UNLOCK(xfer->xroot->bus);
1744 return (0);
1745}
1746
1747/*------------------------------------------------------------------------*
1714{
1715 struct usb_xfer_root *info;
1716 struct usb_xfer_queue *pq;
1717
1718 if (xfer == NULL) {
1719 /* transfer is gone */
1720 return (0);
1721 }

--- 18 unchanged lines hidden (view full) ---

1740 return (1);
1741 }
1742 /* we are not pending */
1743 USB_BUS_UNLOCK(xfer->xroot->bus);
1744 return (0);
1745}
1746
1747/*------------------------------------------------------------------------*
1748 * usb2_transfer_drain
1748 * usbd_transfer_drain
1749 *
1750 * This function will stop the USB transfer and wait for any
1751 * additional BUS-DMA and HW-DMA operations to complete. Buffers that
1752 * are loaded into DMA can safely be freed or reused after that this
1753 * function has returned.
1754 *------------------------------------------------------------------------*/
1755void
1749 *
1750 * This function will stop the USB transfer and wait for any
1751 * additional BUS-DMA and HW-DMA operations to complete. Buffers that
1752 * are loaded into DMA can safely be freed or reused after that this
1753 * function has returned.
1754 *------------------------------------------------------------------------*/
1755void
1756usb2_transfer_drain(struct usb_xfer *xfer)
1756usbd_transfer_drain(struct usb_xfer *xfer)
1757{
1758 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1757{
1758 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1759 "usb2_transfer_drain can sleep!");
1759 "usbd_transfer_drain can sleep!");
1760
1761 if (xfer == NULL) {
1762 /* transfer is gone */
1763 return;
1764 }
1765 if (xfer->xroot->xfer_mtx != &Giant) {
1766 USB_XFER_LOCK_ASSERT(xfer, MA_NOTOWNED);
1767 }
1768 USB_XFER_LOCK(xfer);
1769
1760
1761 if (xfer == NULL) {
1762 /* transfer is gone */
1763 return;
1764 }
1765 if (xfer->xroot->xfer_mtx != &Giant) {
1766 USB_XFER_LOCK_ASSERT(xfer, MA_NOTOWNED);
1767 }
1768 USB_XFER_LOCK(xfer);
1769
1770 usb2_transfer_stop(xfer);
1770 usbd_transfer_stop(xfer);
1771
1771
1772 while (usb2_transfer_pending(xfer)) {
1772 while (usbd_transfer_pending(xfer)) {
1773 xfer->flags_int.draining = 1;
1774 /*
1775 * Wait until the current outstanding USB
1776 * transfer is complete !
1777 */
1778 cv_wait(&xfer->xroot->cv_drain, xfer->xroot->xfer_mtx);
1779 }
1780 USB_XFER_UNLOCK(xfer);
1781}
1782
1783/*------------------------------------------------------------------------*
1773 xfer->flags_int.draining = 1;
1774 /*
1775 * Wait until the current outstanding USB
1776 * transfer is complete !
1777 */
1778 cv_wait(&xfer->xroot->cv_drain, xfer->xroot->xfer_mtx);
1779 }
1780 USB_XFER_UNLOCK(xfer);
1781}
1782
1783/*------------------------------------------------------------------------*
1784 * usb2_set_frame_data
1784 * usbd_set_frame_data
1785 *
1786 * This function sets the pointer of the buffer that should
1787 * loaded directly into DMA for the given USB frame. Passing "ptr"
1788 * equal to NULL while the corresponding "frlength" is greater
1789 * than zero gives undefined results!
1790 *------------------------------------------------------------------------*/
1791void
1785 *
1786 * This function sets the pointer of the buffer that should
1787 * loaded directly into DMA for the given USB frame. Passing "ptr"
1788 * equal to NULL while the corresponding "frlength" is greater
1789 * than zero gives undefined results!
1790 *------------------------------------------------------------------------*/
1791void
1792usb2_set_frame_data(struct usb_xfer *xfer, void *ptr, usb_frcount_t frindex)
1792usbd_set_frame_data(struct usb_xfer *xfer, void *ptr, usb_frcount_t frindex)
1793{
1794 /* set virtual address to load and length */
1795 xfer->frbuffers[frindex].buffer = ptr;
1796}
1797
1798/*------------------------------------------------------------------------*
1793{
1794 /* set virtual address to load and length */
1795 xfer->frbuffers[frindex].buffer = ptr;
1796}
1797
1798/*------------------------------------------------------------------------*
1799 * usb2_set_frame_offset
1799 * usbd_set_frame_offset
1800 *
1801 * This function sets the frame data buffer offset relative to the beginning
1802 * of the USB DMA buffer allocated for this USB transfer.
1803 *------------------------------------------------------------------------*/
1804void
1800 *
1801 * This function sets the frame data buffer offset relative to the beginning
1802 * of the USB DMA buffer allocated for this USB transfer.
1803 *------------------------------------------------------------------------*/
1804void
1805usb2_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
1805usbd_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
1806 usb_frcount_t frindex)
1807{
1808 USB_ASSERT(!xfer->flags.ext_buffer, ("Cannot offset data frame "
1809 "when the USB buffer is external!\n"));
1810
1811 /* set virtual address to load */
1812 xfer->frbuffers[frindex].buffer =
1813 USB_ADD_BYTES(xfer->local_buffer, offset);
1814}
1815
1816/*------------------------------------------------------------------------*
1806 usb_frcount_t frindex)
1807{
1808 USB_ASSERT(!xfer->flags.ext_buffer, ("Cannot offset data frame "
1809 "when the USB buffer is external!\n"));
1810
1811 /* set virtual address to load */
1812 xfer->frbuffers[frindex].buffer =
1813 USB_ADD_BYTES(xfer->local_buffer, offset);
1814}
1815
1816/*------------------------------------------------------------------------*
1817 * usb2_callback_proc - factored out code
1817 * usb_callback_proc - factored out code
1818 *
1819 * This function performs USB callbacks.
1820 *------------------------------------------------------------------------*/
1821static void
1818 *
1819 * This function performs USB callbacks.
1820 *------------------------------------------------------------------------*/
1821static void
1822usb2_callback_proc(struct usb_proc_msg *_pm)
1822usb_callback_proc(struct usb_proc_msg *_pm)
1823{
1824 struct usb_done_msg *pm = (void *)_pm;
1825 struct usb_xfer_root *info = pm->xroot;
1826
1827 /* Change locking order */
1828 USB_BUS_UNLOCK(info->bus);
1829
1830 /*
1831 * We exploit the fact that the mutex is the same for all
1832 * callbacks that will be called from this thread:
1833 */
1834 mtx_lock(info->xfer_mtx);
1835 USB_BUS_LOCK(info->bus);
1836
1837 /* Continue where we lost track */
1823{
1824 struct usb_done_msg *pm = (void *)_pm;
1825 struct usb_xfer_root *info = pm->xroot;
1826
1827 /* Change locking order */
1828 USB_BUS_UNLOCK(info->bus);
1829
1830 /*
1831 * We exploit the fact that the mutex is the same for all
1832 * callbacks that will be called from this thread:
1833 */
1834 mtx_lock(info->xfer_mtx);
1835 USB_BUS_LOCK(info->bus);
1836
1837 /* Continue where we lost track */
1838 usb2_command_wrapper(&info->done_q,
1838 usb_command_wrapper(&info->done_q,
1839 info->done_q.curr);
1840
1841 mtx_unlock(info->xfer_mtx);
1842}
1843
1844/*------------------------------------------------------------------------*
1839 info->done_q.curr);
1840
1841 mtx_unlock(info->xfer_mtx);
1842}
1843
1844/*------------------------------------------------------------------------*
1845 * usb2_callback_ss_done_defer
1845 * usbd_callback_ss_done_defer
1846 *
1847 * This function will defer the start, stop and done callback to the
1848 * correct thread.
1849 *------------------------------------------------------------------------*/
1850static void
1846 *
1847 * This function will defer the start, stop and done callback to the
1848 * correct thread.
1849 *------------------------------------------------------------------------*/
1850static void
1851usb2_callback_ss_done_defer(struct usb_xfer *xfer)
1851usbd_callback_ss_done_defer(struct usb_xfer *xfer)
1852{
1853 struct usb_xfer_root *info = xfer->xroot;
1854 struct usb_xfer_queue *pq = &info->done_q;
1855
1856 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
1857
1858 if (pq->curr != xfer) {
1852{
1853 struct usb_xfer_root *info = xfer->xroot;
1854 struct usb_xfer_queue *pq = &info->done_q;
1855
1856 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
1857
1858 if (pq->curr != xfer) {
1859 usb2_transfer_enqueue(pq, xfer);
1859 usbd_transfer_enqueue(pq, xfer);
1860 }
1861 if (!pq->recurse_1) {
1862
1863 /*
1864 * We have to postpone the callback due to the fact we
1865 * will have a Lock Order Reversal, LOR, if we try to
1866 * proceed !
1867 */
1860 }
1861 if (!pq->recurse_1) {
1862
1863 /*
1864 * We have to postpone the callback due to the fact we
1865 * will have a Lock Order Reversal, LOR, if we try to
1866 * proceed !
1867 */
1868 if (usb2_proc_msignal(info->done_p,
1868 if (usb_proc_msignal(info->done_p,
1869 &info->done_m[0], &info->done_m[1])) {
1870 /* ignore */
1871 }
1872 } else {
1873 /* clear second recurse flag */
1874 pq->recurse_2 = 0;
1875 }
1876 return;
1877
1878}
1879
1880/*------------------------------------------------------------------------*
1869 &info->done_m[0], &info->done_m[1])) {
1870 /* ignore */
1871 }
1872 } else {
1873 /* clear second recurse flag */
1874 pq->recurse_2 = 0;
1875 }
1876 return;
1877
1878}
1879
1880/*------------------------------------------------------------------------*
1881 * usb2_callback_wrapper
1881 * usbd_callback_wrapper
1882 *
1883 * This is a wrapper for USB callbacks. This wrapper does some
1884 * auto-magic things like figuring out if we can call the callback
1885 * directly from the current context or if we need to wakeup the
1886 * interrupt process.
1887 *------------------------------------------------------------------------*/
1888static void
1882 *
1883 * This is a wrapper for USB callbacks. This wrapper does some
1884 * auto-magic things like figuring out if we can call the callback
1885 * directly from the current context or if we need to wakeup the
1886 * interrupt process.
1887 *------------------------------------------------------------------------*/
1888static void
1889usb2_callback_wrapper(struct usb_xfer_queue *pq)
1889usbd_callback_wrapper(struct usb_xfer_queue *pq)
1890{
1891 struct usb_xfer *xfer = pq->curr;
1892 struct usb_xfer_root *info = xfer->xroot;
1893
1894 USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
1895 if (!mtx_owned(info->xfer_mtx)) {
1896 /*
1897 * Cases that end up here:
1898 *
1899 * 5) HW interrupt done callback or other source.
1900 */
1901 DPRINTFN(3, "case 5\n");
1902
1903 /*
1904 * We have to postpone the callback due to the fact we
1905 * will have a Lock Order Reversal, LOR, if we try to
1906 * proceed !
1907 */
1890{
1891 struct usb_xfer *xfer = pq->curr;
1892 struct usb_xfer_root *info = xfer->xroot;
1893
1894 USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
1895 if (!mtx_owned(info->xfer_mtx)) {
1896 /*
1897 * Cases that end up here:
1898 *
1899 * 5) HW interrupt done callback or other source.
1900 */
1901 DPRINTFN(3, "case 5\n");
1902
1903 /*
1904 * We have to postpone the callback due to the fact we
1905 * will have a Lock Order Reversal, LOR, if we try to
1906 * proceed !
1907 */
1908 if (usb2_proc_msignal(info->done_p,
1908 if (usb_proc_msignal(info->done_p,
1909 &info->done_m[0], &info->done_m[1])) {
1910 /* ignore */
1911 }
1912 return;
1913 }
1914 /*
1915 * Cases that end up here:
1916 *

--- 6 unchanged lines hidden (view full) ---

1923 /* get next USB transfer in the queue */
1924 info->done_q.curr = NULL;
1925
1926 USB_BUS_UNLOCK(info->bus);
1927 USB_BUS_LOCK_ASSERT(info->bus, MA_NOTOWNED);
1928
1929 /* set correct USB state for callback */
1930 if (!xfer->flags_int.transferring) {
1909 &info->done_m[0], &info->done_m[1])) {
1910 /* ignore */
1911 }
1912 return;
1913 }
1914 /*
1915 * Cases that end up here:
1916 *

--- 6 unchanged lines hidden (view full) ---

1923 /* get next USB transfer in the queue */
1924 info->done_q.curr = NULL;
1925
1926 USB_BUS_UNLOCK(info->bus);
1927 USB_BUS_LOCK_ASSERT(info->bus, MA_NOTOWNED);
1928
1929 /* set correct USB state for callback */
1930 if (!xfer->flags_int.transferring) {
1931 xfer->usb2_state = USB_ST_SETUP;
1931 xfer->usb_state = USB_ST_SETUP;
1932 if (!xfer->flags_int.started) {
1933 /* we got stopped before we even got started */
1934 USB_BUS_LOCK(info->bus);
1935 goto done;
1936 }
1937 } else {
1938
1932 if (!xfer->flags_int.started) {
1933 /* we got stopped before we even got started */
1934 USB_BUS_LOCK(info->bus);
1935 goto done;
1936 }
1937 } else {
1938
1939 if (usb2_callback_wrapper_sub(xfer)) {
1939 if (usbd_callback_wrapper_sub(xfer)) {
1940 /* the callback has been deferred */
1941 USB_BUS_LOCK(info->bus);
1942 goto done;
1943 }
1944#if USB_HAVE_POWERD
1945 /* decrement power reference */
1940 /* the callback has been deferred */
1941 USB_BUS_LOCK(info->bus);
1942 goto done;
1943 }
1944#if USB_HAVE_POWERD
1945 /* decrement power reference */
1946 usb2_transfer_power_ref(xfer, -1);
1946 usbd_transfer_power_ref(xfer, -1);
1947#endif
1948 xfer->flags_int.transferring = 0;
1949
1950 if (xfer->error) {
1947#endif
1948 xfer->flags_int.transferring = 0;
1949
1950 if (xfer->error) {
1951 xfer->usb2_state = USB_ST_ERROR;
1951 xfer->usb_state = USB_ST_ERROR;
1952 } else {
1953 /* set transferred state */
1952 } else {
1953 /* set transferred state */
1954 xfer->usb2_state = USB_ST_TRANSFERRED;
1954 xfer->usb_state = USB_ST_TRANSFERRED;
1955#if USB_HAVE_BUSDMA
1956 /* sync DMA memory, if any */
1957 if (xfer->flags_int.bdma_enable &&
1958 (!xfer->flags_int.bdma_no_post_sync)) {
1955#if USB_HAVE_BUSDMA
1956 /* sync DMA memory, if any */
1957 if (xfer->flags_int.bdma_enable &&
1958 (!xfer->flags_int.bdma_no_post_sync)) {
1959 usb2_bdma_post_sync(xfer);
1959 usb_bdma_post_sync(xfer);
1960 }
1961#endif
1962 }
1963 }
1964
1965 /* call processing routine */
1966 (xfer->callback) (xfer);
1967
1968 /* pickup the USB mutex again */
1969 USB_BUS_LOCK(info->bus);
1970
1971 /*
1972 * Check if we got started after that we got cancelled, but
1973 * before we managed to do the callback.
1974 */
1975 if ((!xfer->flags_int.open) &&
1976 (xfer->flags_int.started) &&
1960 }
1961#endif
1962 }
1963 }
1964
1965 /* call processing routine */
1966 (xfer->callback) (xfer);
1967
1968 /* pickup the USB mutex again */
1969 USB_BUS_LOCK(info->bus);
1970
1971 /*
1972 * Check if we got started after that we got cancelled, but
1973 * before we managed to do the callback.
1974 */
1975 if ((!xfer->flags_int.open) &&
1976 (xfer->flags_int.started) &&
1977 (xfer->usb2_state == USB_ST_ERROR)) {
1977 (xfer->usb_state == USB_ST_ERROR)) {
1978 /* try to loop, but not recursivly */
1978 /* try to loop, but not recursivly */
1979 usb2_command_wrapper(&info->done_q, xfer);
1979 usb_command_wrapper(&info->done_q, xfer);
1980 return;
1981 }
1982
1983done:
1984 /*
1985 * Check if we are draining.
1986 */
1987 if (xfer->flags_int.draining &&
1988 (!xfer->flags_int.transferring)) {
1980 return;
1981 }
1982
1983done:
1984 /*
1985 * Check if we are draining.
1986 */
1987 if (xfer->flags_int.draining &&
1988 (!xfer->flags_int.transferring)) {
1989 /* "usb2_transfer_drain()" is waiting for end of transfer */
1989 /* "usbd_transfer_drain()" is waiting for end of transfer */
1990 xfer->flags_int.draining = 0;
1991 cv_broadcast(&info->cv_drain);
1992 }
1993
1994 /* do the next callback, if any */
1990 xfer->flags_int.draining = 0;
1991 cv_broadcast(&info->cv_drain);
1992 }
1993
1994 /* do the next callback, if any */
1995 usb2_command_wrapper(&info->done_q,
1995 usb_command_wrapper(&info->done_q,
1996 info->done_q.curr);
1997}
1998
1999/*------------------------------------------------------------------------*
1996 info->done_q.curr);
1997}
1998
1999/*------------------------------------------------------------------------*
2000 * usb2_dma_delay_done_cb
2000 * usb_dma_delay_done_cb
2001 *
2002 * This function is called when the DMA delay has been exectuded, and
2003 * will make sure that the callback is called to complete the USB
2004 * transfer. This code path is ususally only used when there is an USB
2005 * error like USB_ERR_CANCELLED.
2006 *------------------------------------------------------------------------*/
2007static void
2001 *
2002 * This function is called when the DMA delay has been exectuded, and
2003 * will make sure that the callback is called to complete the USB
2004 * transfer. This code path is ususally only used when there is an USB
2005 * error like USB_ERR_CANCELLED.
2006 *------------------------------------------------------------------------*/
2007static void
2008usb2_dma_delay_done_cb(void *arg)
2008usb_dma_delay_done_cb(void *arg)
2009{
2010 struct usb_xfer *xfer = arg;
2011
2012 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2013
2014 DPRINTFN(3, "Completed %p\n", xfer);
2015
2016 /* queue callback for execution, again */
2009{
2010 struct usb_xfer *xfer = arg;
2011
2012 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2013
2014 DPRINTFN(3, "Completed %p\n", xfer);
2015
2016 /* queue callback for execution, again */
2017 usb2_transfer_done(xfer, 0);
2017 usbd_transfer_done(xfer, 0);
2018}
2019
2020/*------------------------------------------------------------------------*
2018}
2019
2020/*------------------------------------------------------------------------*
2021 * usb2_transfer_dequeue
2021 * usbd_transfer_dequeue
2022 *
2023 * - This function is used to remove an USB transfer from a USB
2024 * transfer queue.
2025 *
2026 * - This function can be called multiple times in a row.
2027 *------------------------------------------------------------------------*/
2028void
2022 *
2023 * - This function is used to remove an USB transfer from a USB
2024 * transfer queue.
2025 *
2026 * - This function can be called multiple times in a row.
2027 *------------------------------------------------------------------------*/
2028void
2029usb2_transfer_dequeue(struct usb_xfer *xfer)
2029usbd_transfer_dequeue(struct usb_xfer *xfer)
2030{
2031 struct usb_xfer_queue *pq;
2032
2033 pq = xfer->wait_queue;
2034 if (pq) {
2035 TAILQ_REMOVE(&pq->head, xfer, wait_entry);
2036 xfer->wait_queue = NULL;
2037 }
2038}
2039
2040/*------------------------------------------------------------------------*
2030{
2031 struct usb_xfer_queue *pq;
2032
2033 pq = xfer->wait_queue;
2034 if (pq) {
2035 TAILQ_REMOVE(&pq->head, xfer, wait_entry);
2036 xfer->wait_queue = NULL;
2037 }
2038}
2039
2040/*------------------------------------------------------------------------*
2041 * usb2_transfer_enqueue
2041 * usbd_transfer_enqueue
2042 *
2043 * - This function is used to insert an USB transfer into a USB *
2044 * transfer queue.
2045 *
2046 * - This function can be called multiple times in a row.
2047 *------------------------------------------------------------------------*/
2048void
2042 *
2043 * - This function is used to insert an USB transfer into a USB *
2044 * transfer queue.
2045 *
2046 * - This function can be called multiple times in a row.
2047 *------------------------------------------------------------------------*/
2048void
2049usb2_transfer_enqueue(struct usb_xfer_queue *pq, struct usb_xfer *xfer)
2049usbd_transfer_enqueue(struct usb_xfer_queue *pq, struct usb_xfer *xfer)
2050{
2051 /*
2052 * Insert the USB transfer into the queue, if it is not
2053 * already on a USB transfer queue:
2054 */
2055 if (xfer->wait_queue == NULL) {
2056 xfer->wait_queue = pq;
2057 TAILQ_INSERT_TAIL(&pq->head, xfer, wait_entry);
2058 }
2059}
2060
2061/*------------------------------------------------------------------------*
2050{
2051 /*
2052 * Insert the USB transfer into the queue, if it is not
2053 * already on a USB transfer queue:
2054 */
2055 if (xfer->wait_queue == NULL) {
2056 xfer->wait_queue = pq;
2057 TAILQ_INSERT_TAIL(&pq->head, xfer, wait_entry);
2058 }
2059}
2060
2061/*------------------------------------------------------------------------*
2062 * usb2_transfer_done
2062 * usbd_transfer_done
2063 *
2064 * - This function is used to remove an USB transfer from the busdma,
2065 * pipe or interrupt queue.
2066 *
2067 * - This function is used to queue the USB transfer on the done
2068 * queue.
2069 *
2070 * - This function is used to stop any USB transfer timeouts.
2071 *------------------------------------------------------------------------*/
2072void
2063 *
2064 * - This function is used to remove an USB transfer from the busdma,
2065 * pipe or interrupt queue.
2066 *
2067 * - This function is used to queue the USB transfer on the done
2068 * queue.
2069 *
2070 * - This function is used to stop any USB transfer timeouts.
2071 *------------------------------------------------------------------------*/
2072void
2073usb2_transfer_done(struct usb_xfer *xfer, usb_error_t error)
2073usbd_transfer_done(struct usb_xfer *xfer, usb_error_t error)
2074{
2075 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2076
2074{
2075 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2076
2077 DPRINTF("err=%s\n", usb2_errstr(error));
2077 DPRINTF("err=%s\n", usbd_errstr(error));
2078
2079 /*
2080 * If we are not transferring then just return.
2081 * This can happen during transfer cancel.
2082 */
2083 if (!xfer->flags_int.transferring) {
2084 DPRINTF("not transferring\n");
2085 return;
2086 }
2087 /* only set transfer error if not already set */
2088 if (!xfer->error) {
2089 xfer->error = error;
2090 }
2091 /* stop any callouts */
2078
2079 /*
2080 * If we are not transferring then just return.
2081 * This can happen during transfer cancel.
2082 */
2083 if (!xfer->flags_int.transferring) {
2084 DPRINTF("not transferring\n");
2085 return;
2086 }
2087 /* only set transfer error if not already set */
2088 if (!xfer->error) {
2089 xfer->error = error;
2090 }
2091 /* stop any callouts */
2092 usb2_callout_stop(&xfer->timeout_handle);
2092 usb_callout_stop(&xfer->timeout_handle);
2093
2094 /*
2095 * If we are waiting on a queue, just remove the USB transfer
2096 * from the queue, if any. We should have the required locks
2097 * locked to do the remove when this function is called.
2098 */
2093
2094 /*
2095 * If we are waiting on a queue, just remove the USB transfer
2096 * from the queue, if any. We should have the required locks
2097 * locked to do the remove when this function is called.
2098 */
2099 usb2_transfer_dequeue(xfer);
2099 usbd_transfer_dequeue(xfer);
2100
2101#if USB_HAVE_BUSDMA
2102 if (mtx_owned(xfer->xroot->xfer_mtx)) {
2103 struct usb_xfer_queue *pq;
2104
2105 /*
2106 * If the private USB lock is not locked, then we assume
2107 * that the BUS-DMA load stage has been passed:
2108 */
2109 pq = &xfer->xroot->dma_q;
2110
2111 if (pq->curr == xfer) {
2112 /* start the next BUS-DMA load, if any */
2100
2101#if USB_HAVE_BUSDMA
2102 if (mtx_owned(xfer->xroot->xfer_mtx)) {
2103 struct usb_xfer_queue *pq;
2104
2105 /*
2106 * If the private USB lock is not locked, then we assume
2107 * that the BUS-DMA load stage has been passed:
2108 */
2109 pq = &xfer->xroot->dma_q;
2110
2111 if (pq->curr == xfer) {
2112 /* start the next BUS-DMA load, if any */
2113 usb2_command_wrapper(pq, NULL);
2113 usb_command_wrapper(pq, NULL);
2114 }
2115 }
2116#endif
2117 /* keep some statistics */
2118 if (xfer->error) {
2119 xfer->xroot->bus->stats_err.uds_requests
2120 [xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE]++;
2121 } else {
2122 xfer->xroot->bus->stats_ok.uds_requests
2123 [xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE]++;
2124 }
2125
2126 /* call the USB transfer callback */
2114 }
2115 }
2116#endif
2117 /* keep some statistics */
2118 if (xfer->error) {
2119 xfer->xroot->bus->stats_err.uds_requests
2120 [xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE]++;
2121 } else {
2122 xfer->xroot->bus->stats_ok.uds_requests
2123 [xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE]++;
2124 }
2125
2126 /* call the USB transfer callback */
2127 usb2_callback_ss_done_defer(xfer);
2127 usbd_callback_ss_done_defer(xfer);
2128}
2129
2130/*------------------------------------------------------------------------*
2128}
2129
2130/*------------------------------------------------------------------------*
2131 * usb2_transfer_start_cb
2131 * usbd_transfer_start_cb
2132 *
2133 * This function is called to start the USB transfer when
2134 * "xfer->interval" is greater than zero, and and the endpoint type is
2135 * BULK or CONTROL.
2136 *------------------------------------------------------------------------*/
2137static void
2132 *
2133 * This function is called to start the USB transfer when
2134 * "xfer->interval" is greater than zero, and and the endpoint type is
2135 * BULK or CONTROL.
2136 *------------------------------------------------------------------------*/
2137static void
2138usb2_transfer_start_cb(void *arg)
2138usbd_transfer_start_cb(void *arg)
2139{
2140 struct usb_xfer *xfer = arg;
2141 struct usb_endpoint *ep = xfer->endpoint;
2142
2143 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2144
2145 DPRINTF("start\n");
2146
2147 /* start the transfer */
2148 (ep->methods->start) (xfer);
2149
2150 xfer->flags_int.can_cancel_immed = 1;
2151
2152 /* check for error */
2153 if (xfer->error) {
2154 /* some error has happened */
2139{
2140 struct usb_xfer *xfer = arg;
2141 struct usb_endpoint *ep = xfer->endpoint;
2142
2143 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2144
2145 DPRINTF("start\n");
2146
2147 /* start the transfer */
2148 (ep->methods->start) (xfer);
2149
2150 xfer->flags_int.can_cancel_immed = 1;
2151
2152 /* check for error */
2153 if (xfer->error) {
2154 /* some error has happened */
2155 usb2_transfer_done(xfer, 0);
2155 usbd_transfer_done(xfer, 0);
2156 }
2157}
2158
2159/*------------------------------------------------------------------------*
2156 }
2157}
2158
2159/*------------------------------------------------------------------------*
2160 * usb2_transfer_set_stall
2160 * usbd_transfer_set_stall
2161 *
2162 * This function is used to set the stall flag outside the
2163 * callback. This function is NULL safe.
2164 *------------------------------------------------------------------------*/
2165void
2161 *
2162 * This function is used to set the stall flag outside the
2163 * callback. This function is NULL safe.
2164 *------------------------------------------------------------------------*/
2165void
2166usb2_transfer_set_stall(struct usb_xfer *xfer)
2166usbd_transfer_set_stall(struct usb_xfer *xfer)
2167{
2168 if (xfer == NULL) {
2169 /* tearing down */
2170 return;
2171 }
2172 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
2173
2174 /* avoid any races by locking the USB mutex */
2175 USB_BUS_LOCK(xfer->xroot->bus);
2176
2177 xfer->flags.stall_pipe = 1;
2178
2179 USB_BUS_UNLOCK(xfer->xroot->bus);
2180}
2181
2182/*------------------------------------------------------------------------*
2167{
2168 if (xfer == NULL) {
2169 /* tearing down */
2170 return;
2171 }
2172 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
2173
2174 /* avoid any races by locking the USB mutex */
2175 USB_BUS_LOCK(xfer->xroot->bus);
2176
2177 xfer->flags.stall_pipe = 1;
2178
2179 USB_BUS_UNLOCK(xfer->xroot->bus);
2180}
2181
2182/*------------------------------------------------------------------------*
2183 * usb2_transfer_clear_stall
2183 * usbd_transfer_clear_stall
2184 *
2185 * This function is used to clear the stall flag outside the
2186 * callback. This function is NULL safe.
2187 *------------------------------------------------------------------------*/
2188void
2184 *
2185 * This function is used to clear the stall flag outside the
2186 * callback. This function is NULL safe.
2187 *------------------------------------------------------------------------*/
2188void
2189usb2_transfer_clear_stall(struct usb_xfer *xfer)
2189usbd_transfer_clear_stall(struct usb_xfer *xfer)
2190{
2191 if (xfer == NULL) {
2192 /* tearing down */
2193 return;
2194 }
2195 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
2196
2197 /* avoid any races by locking the USB mutex */
2198 USB_BUS_LOCK(xfer->xroot->bus);
2199
2200 xfer->flags.stall_pipe = 0;
2201
2202 USB_BUS_UNLOCK(xfer->xroot->bus);
2203}
2204
2205/*------------------------------------------------------------------------*
2190{
2191 if (xfer == NULL) {
2192 /* tearing down */
2193 return;
2194 }
2195 USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
2196
2197 /* avoid any races by locking the USB mutex */
2198 USB_BUS_LOCK(xfer->xroot->bus);
2199
2200 xfer->flags.stall_pipe = 0;
2201
2202 USB_BUS_UNLOCK(xfer->xroot->bus);
2203}
2204
2205/*------------------------------------------------------------------------*
2206 * usb2_pipe_start
2206 * usbd_pipe_start
2207 *
2208 * This function is used to add an USB transfer to the pipe transfer list.
2209 *------------------------------------------------------------------------*/
2210void
2207 *
2208 * This function is used to add an USB transfer to the pipe transfer list.
2209 *------------------------------------------------------------------------*/
2210void
2211usb2_pipe_start(struct usb_xfer_queue *pq)
2211usbd_pipe_start(struct usb_xfer_queue *pq)
2212{
2213 struct usb_endpoint *ep;
2214 struct usb_xfer *xfer;
2215 uint8_t type;
2216
2217 xfer = pq->curr;
2218 ep = xfer->endpoint;
2219

--- 25 unchanged lines hidden (view full) ---

2245 udev = info->udev;
2246 ep->is_stalled = 1;
2247
2248 if (udev->flags.usb_mode == USB_MODE_DEVICE) {
2249 (udev->bus->methods->set_stall) (
2250 udev, NULL, ep);
2251 } else if (udev->default_xfer[1]) {
2252 info = udev->default_xfer[1]->xroot;
2212{
2213 struct usb_endpoint *ep;
2214 struct usb_xfer *xfer;
2215 uint8_t type;
2216
2217 xfer = pq->curr;
2218 ep = xfer->endpoint;
2219

--- 25 unchanged lines hidden (view full) ---

2245 udev = info->udev;
2246 ep->is_stalled = 1;
2247
2248 if (udev->flags.usb_mode == USB_MODE_DEVICE) {
2249 (udev->bus->methods->set_stall) (
2250 udev, NULL, ep);
2251 } else if (udev->default_xfer[1]) {
2252 info = udev->default_xfer[1]->xroot;
2253 if (usb2_proc_msignal(
2253 if (usb_proc_msignal(
2254 &info->bus->non_giant_callback_proc,
2255 &udev->cs_msg[0], &udev->cs_msg[1])) {
2256 /* ignore */
2257 }
2258 } else {
2259 /* should not happen */
2260 DPRINTFN(0, "No stall handler!\n");
2261 }
2262 /*
2263 * We get started again when the stall is cleared!
2264 */
2265 return;
2266 }
2267 }
2268 /* Set or clear stall complete - special case */
2269 if (xfer->nframes == 0) {
2270 /* we are complete */
2271 xfer->aframes = 0;
2254 &info->bus->non_giant_callback_proc,
2255 &udev->cs_msg[0], &udev->cs_msg[1])) {
2256 /* ignore */
2257 }
2258 } else {
2259 /* should not happen */
2260 DPRINTFN(0, "No stall handler!\n");
2261 }
2262 /*
2263 * We get started again when the stall is cleared!
2264 */
2265 return;
2266 }
2267 }
2268 /* Set or clear stall complete - special case */
2269 if (xfer->nframes == 0) {
2270 /* we are complete */
2271 xfer->aframes = 0;
2272 usb2_transfer_done(xfer, 0);
2272 usbd_transfer_done(xfer, 0);
2273 return;
2274 }
2275 /*
2276 * Handled cases:
2277 *
2278 * 1) Start the first transfer queued.
2279 *
2280 * 2) Re-start the current USB transfer.
2281 */
2282 /*
2283 * Check if there should be any
2284 * pre transfer start delay:
2285 */
2286 if (xfer->interval > 0) {
2287 type = (ep->edesc->bmAttributes & UE_XFERTYPE);
2288 if ((type == UE_BULK) ||
2289 (type == UE_CONTROL)) {
2273 return;
2274 }
2275 /*
2276 * Handled cases:
2277 *
2278 * 1) Start the first transfer queued.
2279 *
2280 * 2) Re-start the current USB transfer.
2281 */
2282 /*
2283 * Check if there should be any
2284 * pre transfer start delay:
2285 */
2286 if (xfer->interval > 0) {
2287 type = (ep->edesc->bmAttributes & UE_XFERTYPE);
2288 if ((type == UE_BULK) ||
2289 (type == UE_CONTROL)) {
2290 usb2_transfer_timeout_ms(xfer,
2291 &usb2_transfer_start_cb,
2290 usbd_transfer_timeout_ms(xfer,
2291 &usbd_transfer_start_cb,
2292 xfer->interval);
2293 return;
2294 }
2295 }
2296 DPRINTF("start\n");
2297
2298 /* start USB transfer */
2299 (ep->methods->start) (xfer);
2300
2301 xfer->flags_int.can_cancel_immed = 1;
2302
2303 /* check for error */
2304 if (xfer->error) {
2305 /* some error has happened */
2292 xfer->interval);
2293 return;
2294 }
2295 }
2296 DPRINTF("start\n");
2297
2298 /* start USB transfer */
2299 (ep->methods->start) (xfer);
2300
2301 xfer->flags_int.can_cancel_immed = 1;
2302
2303 /* check for error */
2304 if (xfer->error) {
2305 /* some error has happened */
2306 usb2_transfer_done(xfer, 0);
2306 usbd_transfer_done(xfer, 0);
2307 }
2308}
2309
2310/*------------------------------------------------------------------------*
2307 }
2308}
2309
2310/*------------------------------------------------------------------------*
2311 * usb2_transfer_timeout_ms
2311 * usbd_transfer_timeout_ms
2312 *
2313 * This function is used to setup a timeout on the given USB
2314 * transfer. If the timeout has been deferred the callback given by
2315 * "cb" will get called after "ms" milliseconds.
2316 *------------------------------------------------------------------------*/
2317void
2312 *
2313 * This function is used to setup a timeout on the given USB
2314 * transfer. If the timeout has been deferred the callback given by
2315 * "cb" will get called after "ms" milliseconds.
2316 *------------------------------------------------------------------------*/
2317void
2318usb2_transfer_timeout_ms(struct usb_xfer *xfer,
2318usbd_transfer_timeout_ms(struct usb_xfer *xfer,
2319 void (*cb) (void *arg), usb_timeout_t ms)
2320{
2321 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2322
2323 /* defer delay */
2319 void (*cb) (void *arg), usb_timeout_t ms)
2320{
2321 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
2322
2323 /* defer delay */
2324 usb2_callout_reset(&xfer->timeout_handle,
2324 usb_callout_reset(&xfer->timeout_handle,
2325 USB_MS_TO_TICKS(ms), cb, xfer);
2326}
2327
2328/*------------------------------------------------------------------------*
2325 USB_MS_TO_TICKS(ms), cb, xfer);
2326}
2327
2328/*------------------------------------------------------------------------*
2329 * usb2_callback_wrapper_sub
2329 * usbd_callback_wrapper_sub
2330 *
2331 * - This function will update variables in an USB transfer after
2332 * that the USB transfer is complete.
2333 *
2334 * - This function is used to start the next USB transfer on the
2335 * ep transfer queue, if any.
2336 *
2337 * NOTE: In some special cases the USB transfer will not be removed from
2338 * the pipe queue, but remain first. To enforce USB transfer removal call
2339 * this function passing the error code "USB_ERR_CANCELLED".
2340 *
2341 * Return values:
2342 * 0: Success.
2343 * Else: The callback has been deferred.
2344 *------------------------------------------------------------------------*/
2345static uint8_t
2330 *
2331 * - This function will update variables in an USB transfer after
2332 * that the USB transfer is complete.
2333 *
2334 * - This function is used to start the next USB transfer on the
2335 * ep transfer queue, if any.
2336 *
2337 * NOTE: In some special cases the USB transfer will not be removed from
2338 * the pipe queue, but remain first. To enforce USB transfer removal call
2339 * this function passing the error code "USB_ERR_CANCELLED".
2340 *
2341 * Return values:
2342 * 0: Success.
2343 * Else: The callback has been deferred.
2344 *------------------------------------------------------------------------*/
2345static uint8_t
2346usb2_callback_wrapper_sub(struct usb_xfer *xfer)
2346usbd_callback_wrapper_sub(struct usb_xfer *xfer)
2347{
2348 struct usb_endpoint *ep;
2349 usb_frcount_t x;
2350
2351 if ((!xfer->flags_int.open) &&
2352 (!xfer->flags_int.did_close)) {
2353 DPRINTF("close\n");
2354 USB_BUS_LOCK(xfer->xroot->bus);

--- 14 unchanged lines hidden (view full) ---

2369 usb_timeout_t temp;
2370
2371 /* only delay once */
2372 xfer->flags_int.did_dma_delay = 1;
2373
2374 /* we can not cancel this delay */
2375 xfer->flags_int.can_cancel_immed = 0;
2376
2347{
2348 struct usb_endpoint *ep;
2349 usb_frcount_t x;
2350
2351 if ((!xfer->flags_int.open) &&
2352 (!xfer->flags_int.did_close)) {
2353 DPRINTF("close\n");
2354 USB_BUS_LOCK(xfer->xroot->bus);

--- 14 unchanged lines hidden (view full) ---

2369 usb_timeout_t temp;
2370
2371 /* only delay once */
2372 xfer->flags_int.did_dma_delay = 1;
2373
2374 /* we can not cancel this delay */
2375 xfer->flags_int.can_cancel_immed = 0;
2376
2377 temp = usb2_get_dma_delay(xfer->xroot->bus);
2377 temp = usbd_get_dma_delay(xfer->xroot->bus);
2378
2379 DPRINTFN(3, "DMA delay, %u ms, "
2380 "on %p\n", temp, xfer);
2381
2382 if (temp != 0) {
2383 USB_BUS_LOCK(xfer->xroot->bus);
2378
2379 DPRINTFN(3, "DMA delay, %u ms, "
2380 "on %p\n", temp, xfer);
2381
2382 if (temp != 0) {
2383 USB_BUS_LOCK(xfer->xroot->bus);
2384 usb2_transfer_timeout_ms(xfer,
2385 &usb2_dma_delay_done_cb, temp);
2384 usbd_transfer_timeout_ms(xfer,
2385 &usb_dma_delay_done_cb, temp);
2386 USB_BUS_UNLOCK(xfer->xroot->bus);
2387 return (1); /* wait for new callback */
2388 }
2389 }
2390 /* check actual number of frames */
2391 if (xfer->aframes > xfer->nframes) {
2392 if (xfer->error == 0) {
2393 panic("%s: actual number of frames, %d, is "

--- 78 unchanged lines hidden (view full) ---

2472 ep = xfer->endpoint;
2473
2474 /*
2475 * If the current USB transfer is completing we need to start the
2476 * next one:
2477 */
2478 USB_BUS_LOCK(xfer->xroot->bus);
2479 if (ep->endpoint_q.curr == xfer) {
2386 USB_BUS_UNLOCK(xfer->xroot->bus);
2387 return (1); /* wait for new callback */
2388 }
2389 }
2390 /* check actual number of frames */
2391 if (xfer->aframes > xfer->nframes) {
2392 if (xfer->error == 0) {
2393 panic("%s: actual number of frames, %d, is "

--- 78 unchanged lines hidden (view full) ---

2472 ep = xfer->endpoint;
2473
2474 /*
2475 * If the current USB transfer is completing we need to start the
2476 * next one:
2477 */
2478 USB_BUS_LOCK(xfer->xroot->bus);
2479 if (ep->endpoint_q.curr == xfer) {
2480 usb2_command_wrapper(&ep->endpoint_q, NULL);
2480 usb_command_wrapper(&ep->endpoint_q, NULL);
2481
2482 if (ep->endpoint_q.curr || TAILQ_FIRST(&ep->endpoint_q.head)) {
2483 /* there is another USB transfer waiting */
2484 } else {
2485 /* this is the last USB transfer */
2486 /* clear isochronous sync flag */
2487 xfer->endpoint->is_synced = 0;
2488 }
2489 }
2490 USB_BUS_UNLOCK(xfer->xroot->bus);
2491done:
2492 return (0);
2493}
2494
2495/*------------------------------------------------------------------------*
2481
2482 if (ep->endpoint_q.curr || TAILQ_FIRST(&ep->endpoint_q.head)) {
2483 /* there is another USB transfer waiting */
2484 } else {
2485 /* this is the last USB transfer */
2486 /* clear isochronous sync flag */
2487 xfer->endpoint->is_synced = 0;
2488 }
2489 }
2490 USB_BUS_UNLOCK(xfer->xroot->bus);
2491done:
2492 return (0);
2493}
2494
2495/*------------------------------------------------------------------------*
2496 * usb2_command_wrapper
2496 * usb_command_wrapper
2497 *
2498 * This function is used to execute commands non-recursivly on an USB
2499 * transfer.
2500 *------------------------------------------------------------------------*/
2501void
2497 *
2498 * This function is used to execute commands non-recursivly on an USB
2499 * transfer.
2500 *------------------------------------------------------------------------*/
2501void
2502usb2_command_wrapper(struct usb_xfer_queue *pq, struct usb_xfer *xfer)
2502usb_command_wrapper(struct usb_xfer_queue *pq, struct usb_xfer *xfer)
2503{
2504 if (xfer) {
2505 /*
2506 * If the transfer is not already processing,
2507 * queue it!
2508 */
2509 if (pq->curr != xfer) {
2503{
2504 if (xfer) {
2505 /*
2506 * If the transfer is not already processing,
2507 * queue it!
2508 */
2509 if (pq->curr != xfer) {
2510 usb2_transfer_enqueue(pq, xfer);
2510 usbd_transfer_enqueue(pq, xfer);
2511 if (pq->curr != NULL) {
2512 /* something is already processing */
2513 DPRINTFN(6, "busy %p\n", pq->curr);
2514 return;
2515 }
2516 }
2517 } else {
2518 /* Get next element in queue */

--- 30 unchanged lines hidden (view full) ---

2549
2550 } else {
2551 /* clear second recurse flag */
2552 pq->recurse_2 = 0;
2553 }
2554}
2555
2556/*------------------------------------------------------------------------*
2511 if (pq->curr != NULL) {
2512 /* something is already processing */
2513 DPRINTFN(6, "busy %p\n", pq->curr);
2514 return;
2515 }
2516 }
2517 } else {
2518 /* Get next element in queue */

--- 30 unchanged lines hidden (view full) ---

2549
2550 } else {
2551 /* clear second recurse flag */
2552 pq->recurse_2 = 0;
2553 }
2554}
2555
2556/*------------------------------------------------------------------------*
2557 * usb2_default_transfer_setup
2557 * usbd_default_transfer_setup
2558 *
2559 * This function is used to setup the default USB control endpoint
2560 * transfer.
2561 *------------------------------------------------------------------------*/
2562void
2558 *
2559 * This function is used to setup the default USB control endpoint
2560 * transfer.
2561 *------------------------------------------------------------------------*/
2562void
2563usb2_default_transfer_setup(struct usb_device *udev)
2563usbd_default_transfer_setup(struct usb_device *udev)
2564{
2565 struct usb_xfer *xfer;
2566 uint8_t no_resetup;
2567 uint8_t iface_index;
2568
2569 /* check for root HUB */
2570 if (udev->parent_hub == NULL)
2571 return;

--- 8 unchanged lines hidden (view full) ---

2580 udev->ddesc.bMaxPacketSize));
2581 if (udev->flags.usb_mode == USB_MODE_DEVICE) {
2582 if (no_resetup) {
2583 /*
2584 * NOTE: checking "xfer->address" and
2585 * starting the USB transfer must be
2586 * atomic!
2587 */
2564{
2565 struct usb_xfer *xfer;
2566 uint8_t no_resetup;
2567 uint8_t iface_index;
2568
2569 /* check for root HUB */
2570 if (udev->parent_hub == NULL)
2571 return;

--- 8 unchanged lines hidden (view full) ---

2580 udev->ddesc.bMaxPacketSize));
2581 if (udev->flags.usb_mode == USB_MODE_DEVICE) {
2582 if (no_resetup) {
2583 /*
2584 * NOTE: checking "xfer->address" and
2585 * starting the USB transfer must be
2586 * atomic!
2587 */
2588 usb2_transfer_start(xfer);
2588 usbd_transfer_start(xfer);
2589 }
2590 }
2591 USB_XFER_UNLOCK(xfer);
2592 } else {
2593 no_resetup = 0;
2594 }
2595
2596 if (no_resetup) {

--- 7 unchanged lines hidden (view full) ---

2604 * Update wMaxPacketSize for the default control endpoint:
2605 */
2606 udev->default_ep_desc.wMaxPacketSize[0] =
2607 udev->ddesc.bMaxPacketSize;
2608
2609 /*
2610 * Unsetup any existing USB transfer:
2611 */
2589 }
2590 }
2591 USB_XFER_UNLOCK(xfer);
2592 } else {
2593 no_resetup = 0;
2594 }
2595
2596 if (no_resetup) {

--- 7 unchanged lines hidden (view full) ---

2604 * Update wMaxPacketSize for the default control endpoint:
2605 */
2606 udev->default_ep_desc.wMaxPacketSize[0] =
2607 udev->ddesc.bMaxPacketSize;
2608
2609 /*
2610 * Unsetup any existing USB transfer:
2611 */
2612 usb2_transfer_unsetup(udev->default_xfer, USB_DEFAULT_XFER_MAX);
2612 usbd_transfer_unsetup(udev->default_xfer, USB_DEFAULT_XFER_MAX);
2613
2614 /*
2615 * Try to setup a new USB transfer for the
2616 * default control endpoint:
2617 */
2618 iface_index = 0;
2613
2614 /*
2615 * Try to setup a new USB transfer for the
2616 * default control endpoint:
2617 */
2618 iface_index = 0;
2619 if (usb2_transfer_setup(udev, &iface_index,
2620 udev->default_xfer, usb2_control_ep_cfg, USB_DEFAULT_XFER_MAX, NULL,
2619 if (usbd_transfer_setup(udev, &iface_index,
2620 udev->default_xfer, usb_control_ep_cfg, USB_DEFAULT_XFER_MAX, NULL,
2621 udev->default_mtx)) {
2622 DPRINTFN(0, "could not setup default "
2623 "USB transfer!\n");
2624 } else {
2625 goto repeat;
2626 }
2627}
2628
2629/*------------------------------------------------------------------------*
2621 udev->default_mtx)) {
2622 DPRINTFN(0, "could not setup default "
2623 "USB transfer!\n");
2624 } else {
2625 goto repeat;
2626 }
2627}
2628
2629/*------------------------------------------------------------------------*
2630 * usb2_clear_data_toggle - factored out code
2630 * usbd_clear_data_toggle - factored out code
2631 *
2632 * NOTE: the intention of this function is not to reset the hardware
2633 * data toggle.
2634 *------------------------------------------------------------------------*/
2635void
2631 *
2632 * NOTE: the intention of this function is not to reset the hardware
2633 * data toggle.
2634 *------------------------------------------------------------------------*/
2635void
2636usb2_clear_data_toggle(struct usb_device *udev, struct usb_endpoint *ep)
2636usbd_clear_data_toggle(struct usb_device *udev, struct usb_endpoint *ep)
2637{
2638 DPRINTFN(5, "udev=%p endpoint=%p\n", udev, ep);
2639
2640 USB_BUS_LOCK(udev->bus);
2641 ep->toggle_next = 0;
2642 USB_BUS_UNLOCK(udev->bus);
2643}
2644
2645/*------------------------------------------------------------------------*
2637{
2638 DPRINTFN(5, "udev=%p endpoint=%p\n", udev, ep);
2639
2640 USB_BUS_LOCK(udev->bus);
2641 ep->toggle_next = 0;
2642 USB_BUS_UNLOCK(udev->bus);
2643}
2644
2645/*------------------------------------------------------------------------*
2646 * usb2_clear_stall_callback - factored out clear stall callback
2646 * usbd_clear_stall_callback - factored out clear stall callback
2647 *
2648 * Input parameters:
2649 * xfer1: Clear Stall Control Transfer
2650 * xfer2: Stalled USB Transfer
2651 *
2652 * This function is NULL safe.
2653 *
2654 * Return values:

--- 8 unchanged lines hidden (view full) ---

2663 * .direction = UE_DIR_ANY,
2664 * .interval = 50, //50 milliseconds
2665 * .bufsize = sizeof(struct usb_device_request),
2666 * .timeout = 1000, //1.000 seconds
2667 * .callback = &my_clear_stall_callback, // **
2668 * .usb_mode = USB_MODE_HOST,
2669 * };
2670 *
2647 *
2648 * Input parameters:
2649 * xfer1: Clear Stall Control Transfer
2650 * xfer2: Stalled USB Transfer
2651 *
2652 * This function is NULL safe.
2653 *
2654 * Return values:

--- 8 unchanged lines hidden (view full) ---

2663 * .direction = UE_DIR_ANY,
2664 * .interval = 50, //50 milliseconds
2665 * .bufsize = sizeof(struct usb_device_request),
2666 * .timeout = 1000, //1.000 seconds
2667 * .callback = &my_clear_stall_callback, // **
2668 * .usb_mode = USB_MODE_HOST,
2669 * };
2670 *
2671 * ** "my_clear_stall_callback" calls "usb2_clear_stall_callback"
2671 * ** "my_clear_stall_callback" calls "usbd_clear_stall_callback"
2672 * passing the correct parameters.
2673 *------------------------------------------------------------------------*/
2674uint8_t
2672 * passing the correct parameters.
2673 *------------------------------------------------------------------------*/
2674uint8_t
2675usb2_clear_stall_callback(struct usb_xfer *xfer1,
2675usbd_clear_stall_callback(struct usb_xfer *xfer1,
2676 struct usb_xfer *xfer2)
2677{
2678 struct usb_device_request req;
2679
2680 if (xfer2 == NULL) {
2681 /* looks like we are tearing down */
2682 DPRINTF("NULL input parameter\n");
2683 return (0);

--- 4 unchanged lines hidden (view full) ---

2688 switch (USB_GET_STATE(xfer1)) {
2689 case USB_ST_SETUP:
2690
2691 /*
2692 * pre-clear the data toggle to DATA0 ("umass.c" and
2693 * "ata-usb.c" depends on this)
2694 */
2695
2676 struct usb_xfer *xfer2)
2677{
2678 struct usb_device_request req;
2679
2680 if (xfer2 == NULL) {
2681 /* looks like we are tearing down */
2682 DPRINTF("NULL input parameter\n");
2683 return (0);

--- 4 unchanged lines hidden (view full) ---

2688 switch (USB_GET_STATE(xfer1)) {
2689 case USB_ST_SETUP:
2690
2691 /*
2692 * pre-clear the data toggle to DATA0 ("umass.c" and
2693 * "ata-usb.c" depends on this)
2694 */
2695
2696 usb2_clear_data_toggle(xfer2->xroot->udev, xfer2->endpoint);
2696 usbd_clear_data_toggle(xfer2->xroot->udev, xfer2->endpoint);
2697
2698 /* setup a clear-stall packet */
2699
2700 req.bmRequestType = UT_WRITE_ENDPOINT;
2701 req.bRequest = UR_CLEAR_FEATURE;
2702 USETW(req.wValue, UF_ENDPOINT_HALT);
2703 req.wIndex[0] = xfer2->endpoint->edesc->bEndpointAddress;
2704 req.wIndex[1] = 0;
2705 USETW(req.wLength, 0);
2706
2707 /*
2697
2698 /* setup a clear-stall packet */
2699
2700 req.bmRequestType = UT_WRITE_ENDPOINT;
2701 req.bRequest = UR_CLEAR_FEATURE;
2702 USETW(req.wValue, UF_ENDPOINT_HALT);
2703 req.wIndex[0] = xfer2->endpoint->edesc->bEndpointAddress;
2704 req.wIndex[1] = 0;
2705 USETW(req.wLength, 0);
2706
2707 /*
2708 * "usb2_transfer_setup_sub()" will ensure that
2708 * "usbd_transfer_setup_sub()" will ensure that
2709 * we have sufficient room in the buffer for
2710 * the request structure!
2711 */
2712
2713 /* copy in the transfer */
2714
2709 * we have sufficient room in the buffer for
2710 * the request structure!
2711 */
2712
2713 /* copy in the transfer */
2714
2715 usb2_copy_in(xfer1->frbuffers, 0, &req, sizeof(req));
2715 usbd_copy_in(xfer1->frbuffers, 0, &req, sizeof(req));
2716
2717 /* set length */
2718 xfer1->frlengths[0] = sizeof(req);
2719 xfer1->nframes = 1;
2720
2716
2717 /* set length */
2718 xfer1->frlengths[0] = sizeof(req);
2719 xfer1->nframes = 1;
2720
2721 usb2_start_hardware(xfer1);
2721 usbd_transfer_submit(xfer1);
2722 return (0);
2723
2724 case USB_ST_TRANSFERRED:
2725 break;
2726
2727 default: /* Error */
2728 if (xfer1->error == USB_ERR_CANCELLED) {
2729 return (0);
2730 }
2731 break;
2732 }
2733 return (1); /* Clear Stall Finished */
2734}
2735
2736void
2722 return (0);
2723
2724 case USB_ST_TRANSFERRED:
2725 break;
2726
2727 default: /* Error */
2728 if (xfer1->error == USB_ERR_CANCELLED) {
2729 return (0);
2730 }
2731 break;
2732 }
2733 return (1); /* Clear Stall Finished */
2734}
2735
2736void
2737usb2_do_poll(struct usb_xfer **ppxfer, uint16_t max)
2737usbd_do_poll(struct usb_xfer **ppxfer, uint16_t max)
2738{
2739 static uint8_t once = 0;
2740 /* polling is currently not supported */
2741 if (!once) {
2742 once = 1;
2738{
2739 static uint8_t once = 0;
2740 /* polling is currently not supported */
2741 if (!once) {
2742 once = 1;
2743 printf("usb2_do_poll: USB polling is "
2743 printf("usbd_do_poll: USB polling is "
2744 "not supported!\n");
2745 }
2746}
2747
2748static void
2744 "not supported!\n");
2745 }
2746}
2747
2748static void
2749usb2_get_std_packet_size(struct usb2_std_packet_size *ptr,
2749usbd_get_std_packet_size(struct usb_std_packet_size *ptr,
2750 uint8_t type, enum usb_dev_speed speed)
2751{
2752 static const uint16_t intr_range_max[USB_SPEED_MAX] = {
2753 [USB_SPEED_LOW] = 8,
2754 [USB_SPEED_FULL] = 64,
2755 [USB_SPEED_HIGH] = 1024,
2756 [USB_SPEED_VARIABLE] = 1024,
2757 [USB_SPEED_SUPER] = 1024,

--- 64 unchanged lines hidden ---
2750 uint8_t type, enum usb_dev_speed speed)
2751{
2752 static const uint16_t intr_range_max[USB_SPEED_MAX] = {
2753 [USB_SPEED_LOW] = 8,
2754 [USB_SPEED_FULL] = 64,
2755 [USB_SPEED_HIGH] = 1024,
2756 [USB_SPEED_VARIABLE] = 1024,
2757 [USB_SPEED_SUPER] = 1024,

--- 64 unchanged lines hidden ---