source: mainline/uspace/drv/bus/usb/ehci/ehci_rh.c@ ff0258f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ff0258f was f523daf, checked in by Jan Vesely <jano.vesely@…>, 10 years ago

ehci_rh: Flag reset status change even if we give up ownership

usbhub driver needs to see the change

  • Property mode set to 100644
File size: 20.0 KB
Line 
1/*
2 * Copyright (c) 2013 Jan Vesely
3 * 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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup drvusbehci
29 * @{
30 */
31/** @file
32 * @brief EHCI driver
33 */
34
35#include <assert.h>
36#include <errno.h>
37#include <mem.h>
38#include <str_error.h>
39#include <sys/types.h>
40
41#include <usb/classes/hub.h>
42#include <usb/debug.h>
43#include <usb/descriptor.h>
44#include <usb/request.h>
45#include <usb/usb.h>
46
47#include <usb/host/endpoint.h>
48#include <usbvirt/device.h>
49
50#include "ehci_rh.h"
51
52enum {
53 HUB_STATUS_CHANGE_PIPE = 1,
54};
55
56static usbvirt_device_ops_t ops;
57
58/** Initialize internal USB HUB class descriptor.
59 * @param instance EHCI root hub.
60 * Use register based info to create accurate descriptor.
61 */
62static void ehci_rh_hub_desc_init(ehci_rh_t *instance, unsigned hcs)
63{
64 assert(instance);
65 const unsigned dsize = sizeof(usb_hub_descriptor_header_t) +
66 STATUS_BYTES(instance->port_count) * 2;
67 assert(dsize <= sizeof(instance->hub_descriptor));
68
69 instance->hub_descriptor.header.length = dsize;
70 instance->hub_descriptor.header.descriptor_type = USB_DESCTYPE_HUB;
71 instance->hub_descriptor.header.port_count = instance->port_count;
72 /* Bits 0,1 indicate power switching mode
73 * Bit 2 indicates device type (compound device)
74 * Bits 3,4 indicate over-current protection mode */
75 instance->hub_descriptor.header.characteristics = 0 |
76 ((hcs & EHCI_CAPS_HCS_PPC_FLAG) ? 0x09 : 0x12) |
77 ((hcs & EHCI_CAPS_HCS_INDICATORS_FLAG) ? 0x80 : 0) |
78 (0x3 << 5); /* Need 32 FS bit times */ // TODO Implement
79 instance->hub_descriptor.header.characteristics_reserved = 0;
80 instance->hub_descriptor.header.power_good_time = 50;
81 /* bHubContrCurrent, root hubs don't need no power. */
82 instance->hub_descriptor.header.max_current = 0;
83
84 /* Device removable and some legacy 1.0 stuff*/
85 instance->hub_descriptor.rempow[0] = 0xff;
86 instance->hub_descriptor.rempow[1] = 0xff;
87 instance->hub_descriptor.rempow[2] = 0xff;
88 instance->hub_descriptor.rempow[3] = 0xff;
89
90}
91/** Initialize EHCI root hub.
92 * @param instance Place to initialize.
93 * @param regs EHCI device registers.
94 * @param name Device name.
95 * return Error code, EOK on success.
96 *
97 * Selects preconfigured port powering mode, sets up descriptor, and
98 * initializes internal virtual hub.
99 */
100int ehci_rh_init(ehci_rh_t *instance, ehci_caps_regs_t *caps, ehci_regs_t *regs,
101const char *name)
102{
103 assert(instance);
104 instance->registers = regs;
105 instance->port_count =
106 (EHCI_RD(caps->hcsparams) >> EHCI_CAPS_HCS_N_PORTS_SHIFT) &
107 EHCI_CAPS_HCS_N_PORTS_MASK;
108 usb_log_debug2("RH(%p): hcsparams: %x.\n", instance,
109 EHCI_RD(caps->hcsparams));
110 usb_log_info("RH(%p): Found %u ports.\n", instance,
111 instance->port_count);
112
113 if (EHCI_RD(caps->hcsparams) & EHCI_CAPS_HCS_PPC_FLAG) {
114 usb_log_info("RH(%p): Per-port power switching.", instance);
115 } else {
116 usb_log_info("RH(%p): No power switching.", instance);
117 }
118
119 for (unsigned i = 0; i < EHCI_MAX_PORTS; ++i) {
120 instance->reset_flag[i] = false;
121 instance->resume_flag[i] = false;
122 }
123
124 ehci_rh_hub_desc_init(instance, EHCI_RD(caps->hcsparams));
125 instance->unfinished_interrupt_transfer = NULL;
126
127 return virthub_base_init(&instance->base, name, &ops, instance,
128 NULL, &instance->hub_descriptor.header, HUB_STATUS_CHANGE_PIPE);
129}
130
131/** Schedule USB request.
132 * @param instance OCHI root hub instance.
133 * @param batch USB requst batch to schedule.
134 * @return Always EOK.
135 * Most requests complete even before this function returns,
136 * status change requests might be postponed until there is something to report.
137 */
138int ehci_rh_schedule(ehci_rh_t *instance, usb_transfer_batch_t *batch)
139{
140 assert(instance);
141 assert(batch);
142 const usb_target_t target = {{
143 .address = batch->ep->address,
144 .endpoint = batch->ep->endpoint,
145 }};
146 batch->error = virthub_base_request(&instance->base, target,
147 usb_transfer_batch_direction(batch), (void*)batch->setup_buffer,
148 batch->buffer, batch->buffer_size, &batch->transfered_size);
149 if (batch->error == ENAK) {
150 usb_log_debug("RH(%p): BATCH(%p) adding as unfinished",
151 instance, batch);
152 /* This is safe because only status change interrupt transfers
153 * return NAK. The assertion holds true because the batch
154 * existence prevents communication with that ep */
155 assert(instance->unfinished_interrupt_transfer == NULL);
156 instance->unfinished_interrupt_transfer = batch;
157 } else {
158 usb_transfer_batch_finish(batch, NULL);
159 usb_transfer_batch_destroy(batch);
160 usb_log_debug("RH(%p): BATCH(%p) virtual request complete: %s",
161 instance, batch, str_error(batch->error));
162 }
163 return EOK;
164}
165
166/** Handle EHCI RHSC interrupt.
167 * @param instance EHCI root hub isntance.
168 * @return Always EOK.
169 *
170 * Interrupt means there is a change of status to report. It may trigger
171 * processing of a postponed request.
172 */
173int ehci_rh_interrupt(ehci_rh_t *instance)
174{
175 //TODO atomic swap needed
176 usb_transfer_batch_t *batch = instance->unfinished_interrupt_transfer;
177 instance->unfinished_interrupt_transfer = NULL;
178 usb_log_debug2("RH(%p): Interrupt. Processing batch: %p",
179 instance, batch);
180 if (batch) {
181 const usb_target_t target = {{
182 .address = batch->ep->address,
183 .endpoint = batch->ep->endpoint,
184 }};
185 batch->error = virthub_base_request(&instance->base, target,
186 usb_transfer_batch_direction(batch),
187 (void*)batch->setup_buffer,
188 batch->buffer, batch->buffer_size, &batch->transfered_size);
189 usb_transfer_batch_finish(batch, NULL);
190 usb_transfer_batch_destroy(batch);
191 }
192 return EOK;
193}
194
195/* HUB ROUTINES IMPLEMENTATION */
196#define TEST_SIZE_INIT(size, port, hub) \
197do { \
198 hub = virthub_get_data(device); \
199 assert(hub);\
200 if (uint16_usb2host(setup_packet->length) != size) \
201 return ESTALL; \
202 port = uint16_usb2host(setup_packet->index) - 1; \
203 if (port > hub->port_count) \
204 return EINVAL; \
205} while (0)
206
207/** Hub status request handler.
208 * @param device Virtual hub device
209 * @param setup_packet USB setup stage data.
210 * @param[out] data destination data buffer, size must be at least
211 * setup_packet->length bytes
212 * @param[out] act_size Sized of the valid response part of the buffer.
213 * @return Error code.
214 */
215static int req_get_status(usbvirt_device_t *device,
216 const usb_device_request_setup_packet_t *setup_packet,
217 uint8_t *data, size_t *act_size)
218{
219 ehci_rh_t *hub = virthub_get_data(device);
220 assert(hub);
221 if (uint16_usb2host(setup_packet->length) != 4)
222 return ESTALL;
223 /* ECHI RH does not report global OC, and local power is always good */
224 const uint32_t val = 0;
225 memcpy(data, &val, sizeof(val));
226 *act_size = sizeof(val);
227 return EOK;
228}
229
230/** Hub set feature request handler.
231 * @param device Virtual hub device
232 * @param setup_packet USB setup stage data.
233 * @param[out] data destination data buffer, size must be at least
234 * setup_packet->length bytes
235 * @param[out] act_size Sized of the valid response part of the buffer.
236 * @return Error code.
237 */
238static int req_clear_hub_feature(usbvirt_device_t *device,
239 const usb_device_request_setup_packet_t *setup_packet,
240 uint8_t *data, size_t *act_size)
241{
242 ehci_rh_t *hub = virthub_get_data(device);
243 assert(hub);
244
245 /*
246 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
247 * C_HUB_OVER_CURRENT are supported.
248 * C_HUB_LOCAL_POWER is not supported because root hubs do not support
249 * local power status feature.
250 * EHCI RH does not report global OC condition either
251 */
252 return ESTALL;
253}
254
255#define BIT_VAL(val, bit) ((val & bit) ? 1 : 0)
256#define EHCI2USB(val, bit, feat) (BIT_VAL(val, bit) << feat)
257
258/** Port status request handler.
259 * @param device Virtual hub device
260 * @param setup_packet USB setup stage data.
261 * @param[out] data destination data buffer, size must be at least
262 * setup_packet->length bytes
263 * @param[out] act_size Sized of the valid response part of the buffer.
264 * @return Error code.
265 */
266static int req_get_port_status(usbvirt_device_t *device,
267 const usb_device_request_setup_packet_t *setup_packet,
268 uint8_t *data, size_t *act_size)
269{
270 ehci_rh_t *hub;
271 unsigned port;
272 TEST_SIZE_INIT(4, port, hub);
273 if (setup_packet->value != 0)
274 return EINVAL;
275
276 const uint32_t reg = EHCI_RD(hub->registers->portsc[port]);
277 const uint32_t status = uint32_host2usb(
278 EHCI2USB(reg, USB_PORTSC_CONNECT_FLAG, USB_HUB_FEATURE_PORT_CONNECTION) |
279 EHCI2USB(reg, USB_PORTSC_ENABLED_FLAG, USB_HUB_FEATURE_PORT_ENABLE) |
280 EHCI2USB(reg, USB_PORTSC_SUSPEND_FLAG, USB_HUB_FEATURE_PORT_SUSPEND) |
281 EHCI2USB(reg, USB_PORTSC_OC_ACTIVE_FLAG, USB_HUB_FEATURE_PORT_OVER_CURRENT) |
282 EHCI2USB(reg, USB_PORTSC_PORT_RESET_FLAG, USB_HUB_FEATURE_PORT_RESET) |
283 EHCI2USB(reg, USB_PORTSC_PORT_POWER_FLAG, USB_HUB_FEATURE_PORT_POWER) |
284 (((reg & USB_PORTSC_LINE_STATUS_MASK) == USB_PORTSC_LINE_STATUS_K) ?
285 (1 << USB_HUB_FEATURE_PORT_LOW_SPEED) : 0) |
286 ((reg & USB_PORTSC_PORT_OWNER_FLAG) ? 0 : (1 << USB_HUB_FEATURE_PORT_HIGH_SPEED)) |
287 EHCI2USB(reg, USB_PORTSC_PORT_TEST_MASK, 11) |
288 EHCI2USB(reg, USB_PORTSC_INDICATOR_MASK, 12) |
289 EHCI2USB(reg, USB_PORTSC_CONNECT_CH_FLAG, USB_HUB_FEATURE_C_PORT_CONNECTION) |
290 EHCI2USB(reg, USB_PORTSC_EN_CHANGE_FLAG, USB_HUB_FEATURE_C_PORT_ENABLE) |
291 (hub->resume_flag[port] ? (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) : 0) |
292 EHCI2USB(reg, USB_PORTSC_OC_CHANGE_FLAG, USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
293 (hub->reset_flag[port] ? (1 << USB_HUB_FEATURE_C_PORT_RESET): 0)
294 );
295 /* Note feature numbers for test and indicator feature do not
296 * correspond to the port status bit locations */
297 usb_log_debug2("RH(%p-%u) port status: %"PRIx32, hub, port, status);
298 memcpy(data, &status, sizeof(status));
299 *act_size = sizeof(status);
300 return EOK;
301}
302
303typedef struct {
304 ehci_rh_t *hub;
305 unsigned port;
306} ehci_rh_job_t;
307
308static int stop_reset(void *arg)
309{
310 ehci_rh_job_t *job = arg;
311 async_usleep(50000);
312 usb_log_debug("RH(%p-%u): Clearing reset", job->hub, job->port);
313 EHCI_CLR(job->hub->registers->portsc[job->port],
314 USB_PORTSC_PORT_RESET_FLAG);
315 /* wait for reset to complete */
316 while (EHCI_RD(job->hub->registers->portsc[job->port]) &
317 USB_PORTSC_PORT_RESET_FLAG) {
318 async_usleep(1);
319 };
320 usb_log_debug("RH(%p-%u): Reset complete", job->hub, job->port);
321 /* Handle port ownership, if the port is not enabled
322 * after reset it's a full speed device */
323 if (!(EHCI_RD(job->hub->registers->portsc[job->port]) &
324 USB_PORTSC_ENABLED_FLAG)) {
325 usb_log_info("RH(%p-%u): Port not enabled after reset (%"PRIX32
326 "), giving up ownership", job->hub, job->port,
327 EHCI_RD(job->hub->registers->portsc[job->port]));
328 EHCI_SET(job->hub->registers->portsc[job->port],
329 USB_PORTSC_PORT_OWNER_FLAG);
330 }
331 job->hub->reset_flag[job->port] = true;
332 ehci_rh_interrupt(job->hub);
333 free(job);
334 return 0;
335}
336
337static int stop_resume(void *arg)
338{
339 ehci_rh_job_t *job = arg;
340 async_usleep(20000);
341 usb_log_debug("RH(%p-%u): Stopping resume", job->hub, job->port);
342 EHCI_CLR(job->hub->registers->portsc[job->port],
343 USB_PORTSC_RESUME_FLAG);
344 job->hub->resume_flag[job->port] = true;
345 ehci_rh_interrupt(job->hub);
346 free(job);
347 return 0;
348}
349
350static int delayed_job(int (*func)(void*), ehci_rh_t *rh, unsigned port)
351{
352 ehci_rh_job_t *job = malloc(sizeof(*job));
353 if (!job)
354 return ENOMEM;
355 job->hub = rh;
356 job->port = port;
357 fid_t fib = fibril_create(func, job);
358 if (!fib) {
359 free(job);
360 return ENOMEM;
361 }
362 fibril_add_ready(fib);
363 usb_log_debug2("RH(%p-%u): Scheduled delayed stop job.", rh, port);
364 return EOK;
365}
366
367
368/** Port clear feature request handler.
369 * @param device Virtual hub device
370 * @param setup_packet USB setup stage data.
371 * @param[out] data destination data buffer, size must be at least
372 * setup_packet->length bytes
373 * @param[out] act_size Sized of the valid response part of the buffer.
374 * @return Error code.
375 */
376static int req_clear_port_feature(usbvirt_device_t *device,
377 const usb_device_request_setup_packet_t *setup_packet,
378 uint8_t *data, size_t *act_size)
379{
380 ehci_rh_t *hub;
381 unsigned port;
382 TEST_SIZE_INIT(0, port, hub);
383 const unsigned feature = uint16_usb2host(setup_packet->value);
384 /* Enabled features to clear: see page 269 of USB specs */
385 switch (feature)
386 {
387 case USB_HUB_FEATURE_PORT_POWER: /*8*/
388 usb_log_debug2("RH(%p-%u): Clear port power.", hub, port);
389 EHCI_CLR(hub->registers->portsc[port],
390 USB_PORTSC_PORT_POWER_FLAG);
391 return EOK;
392
393 case USB_HUB_FEATURE_PORT_ENABLE: /*1*/
394 usb_log_debug2("RH(%p-%u): Clear port enable.", hub, port);
395 EHCI_CLR(hub->registers->portsc[port],
396 USB_PORTSC_ENABLED_FLAG);
397 return EOK;
398
399 case USB_HUB_FEATURE_PORT_SUSPEND: /*2*/
400 usb_log_debug2("RH(%p-%u): Clear port suspend.", hub, port);
401 /* If not in suspend it's noop */
402 if ((EHCI_RD(hub->registers->portsc[port]) &
403 USB_PORTSC_SUSPEND_FLAG) == 0)
404 return EOK;
405 /* Host driven resume */
406 EHCI_SET(hub->registers->portsc[port],
407 USB_PORTSC_RESUME_FLAG);
408 //TODO: What if creating the delayed job fails?
409 return delayed_job(stop_resume, hub, port);
410
411 case USB_HUB_FEATURE_C_PORT_CONNECTION: /*16*/
412 usb_log_debug2("RH(%p-%u): Clear port connection change.",
413 hub, port);
414 EHCI_SET(hub->registers->portsc[port],
415 USB_PORTSC_CONNECT_CH_FLAG);
416 return EOK;
417 case USB_HUB_FEATURE_C_PORT_ENABLE: /*17*/
418 usb_log_debug2("RH(%p-%u): Clear port enable change.",
419 hub, port);
420 EHCI_SET(hub->registers->portsc[port],
421 USB_PORTSC_CONNECT_CH_FLAG);
422 return EOK;
423 case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: /*19*/
424 usb_log_debug2("RH(%p-%u): Clear port OC change.",
425 hub, port);
426 EHCI_SET(hub->registers->portsc[port],
427 USB_PORTSC_OC_CHANGE_FLAG);
428 return EOK;
429 case USB_HUB_FEATURE_C_PORT_SUSPEND: /*18*/
430 usb_log_debug2("RH(%p-%u): Clear port suspend change.",
431 hub, port);
432 hub->resume_flag[port] = false;
433 return EOK;
434 case USB_HUB_FEATURE_C_PORT_RESET: /*20*/
435 usb_log_debug2("RH(%p-%u): Clear port reset change.",
436 hub, port);
437 hub->reset_flag[port] = false;
438 return EOK;
439
440 default:
441 usb_log_warning("RH(%p-%u): Clear unknown feature: %u",
442 hub, port, feature);
443 return ENOTSUP;
444 }
445}
446
447/** Port set feature request handler.
448 * @param device Virtual hub device
449 * @param setup_packet USB setup stage data.
450 * @param[out] data destination data buffer, size must be at least
451 * setup_packet->length bytes
452 * @param[out] act_size Sized of the valid response part of the buffer.
453 * @return Error code.
454 */
455static int req_set_port_feature(usbvirt_device_t *device,
456 const usb_device_request_setup_packet_t *setup_packet,
457 uint8_t *data, size_t *act_size)
458{
459 ehci_rh_t *hub;
460 unsigned port;
461 TEST_SIZE_INIT(0, port, hub);
462 const unsigned feature = uint16_usb2host(setup_packet->value);
463 switch (feature) {
464 case USB_HUB_FEATURE_PORT_ENABLE: /*1*/
465 usb_log_debug2("RH(%p-%u): Set port enable.", hub, port);
466 EHCI_SET(hub->registers->portsc[port],
467 USB_PORTSC_ENABLED_FLAG);
468 return EOK;
469 case USB_HUB_FEATURE_PORT_SUSPEND: /*2*/
470 usb_log_debug2("RH(%p-%u): Set port suspend.", hub, port);
471 EHCI_SET(hub->registers->portsc[port],
472 USB_PORTSC_SUSPEND_FLAG);
473 return EOK;
474 case USB_HUB_FEATURE_PORT_RESET: /*4*/
475 usb_log_debug2("RH(%p-%u): Set port reset.", hub, port);
476 EHCI_SET(hub->registers->portsc[port],
477 USB_PORTSC_PORT_RESET_FLAG);
478 //TODO: What if creating the delayed job fails?
479 return delayed_job(stop_reset, hub, port);
480 case USB_HUB_FEATURE_PORT_POWER: /*8*/
481 usb_log_debug2("RH(%p-%u): Set port power.", hub, port);
482 EHCI_SET(hub->registers->portsc[port],
483 USB_PORTSC_PORT_POWER_FLAG);
484 return EOK;
485 default:
486 usb_log_warning("RH(%p-%u): Set unknown feature: %u",
487 hub, port, feature);
488 return ENOTSUP;
489 }
490}
491
492/** Status change handler.
493 * @param device Virtual hub device
494 * @param endpoint Endpoint number
495 * @param tr_type Transfer type
496 * @param buffer Response destination
497 * @param buffer_size Bytes available in buffer
498 * @param actual_size Size us the used part of the dest buffer.
499 *
500 * Produces status mask. Bit 0 indicates hub status change the other bits
501 * represent port status change. Endian does not matter as UHCI root hubs
502 * only need 1 byte.
503 */
504static int req_status_change_handler(usbvirt_device_t *device,
505 usb_endpoint_t endpoint, usb_transfer_type_t tr_type,
506 void *buffer, size_t buffer_size, size_t *actual_size)
507{
508 ehci_rh_t *hub = virthub_get_data(device);
509 assert(hub);
510
511 if (buffer_size < STATUS_BYTES(hub->port_count))
512 return ESTALL;
513
514 uint16_t mask = 0;
515 for (unsigned port = 0; port < hub->port_count; ++port) {
516 /* Write-clean bits are those that indicate change */
517 uint32_t status = EHCI_RD(hub->registers->portsc[port]);
518 if ((status & USB_PORTSC_WC_MASK)
519 || hub->reset_flag[port] || hub->reset_flag[port]) {
520 /* Ignore new LS device */
521 if ((status & USB_PORTSC_CONNECT_CH_FLAG) &&
522 (status & USB_PORTSC_LINE_STATUS_MASK) ==
523 USB_PORTSC_LINE_STATUS_K)
524 EHCI_SET(hub->registers->portsc[port],
525 USB_PORTSC_PORT_OWNER_FLAG);
526 else
527 mask |= (2 << port);
528 }
529 }
530
531 usb_log_debug2("RH(%p): root hub interrupt mask: %"PRIx16, hub, mask);
532
533 if (mask == 0)
534 return ENAK;
535 mask = uint16_host2usb(mask);
536 memcpy(buffer, &mask, STATUS_BYTES(hub->port_count));
537 *actual_size = STATUS_BYTES(hub->port_count);
538 return EOK;
539}
540
541/** EHCI root hub request handlers */
542static const usbvirt_control_request_handler_t control_transfer_handlers[] = {
543 {
544 STD_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
545 .name = "GetDescriptor",
546 .callback = virthub_base_get_hub_descriptor,
547 },
548 {
549 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_DEVREQ_GET_DESCRIPTOR),
550 .name = "GetDescriptor",
551 .callback = virthub_base_get_hub_descriptor,
552 },
553 {
554 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_DESCRIPTOR),
555 .name = "GetHubDescriptor",
556 .callback = virthub_base_get_hub_descriptor,
557 },
558 {
559 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
560 .name = "GetPortStatus",
561 .callback = req_get_port_status,
562 },
563 {
564 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_CLEAR_FEATURE),
565 .name = "ClearHubFeature",
566 .callback = req_clear_hub_feature,
567 },
568 {
569 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_CLEAR_FEATURE),
570 .name = "ClearPortFeature",
571 .callback = req_clear_port_feature,
572 },
573 {
574 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_GET_STATUS),
575 .name = "GetHubStatus",
576 .callback = req_get_status,
577 },
578 {
579 CLASS_REQ_IN(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_GET_STATUS),
580 .name = "GetPortStatus",
581 .callback = req_get_port_status,
582 },
583 {
584 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_DEVICE, USB_HUB_REQUEST_SET_FEATURE),
585 .name = "SetHubFeature",
586 .callback = req_nop,
587 },
588 {
589 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_OTHER, USB_HUB_REQUEST_SET_FEATURE),
590 .name = "SetPortFeature",
591 .callback = req_set_port_feature,
592 },
593 {
594 .callback = NULL
595 }
596};
597
598/** Virtual EHCI root hub ops */
599static usbvirt_device_ops_t ops = {
600 .control = control_transfer_handlers,
601 .data_in[HUB_STATUS_CHANGE_PIPE] = req_status_change_handler,
602};
Note: See TracBrowser for help on using the repository browser.