Deleted Added
sdiff udiff text old ( 187176 ) new ( 187259 )
full compact
1#include <sys/cdefs.h>
2__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/umct2.c 187259 2009-01-15 02:35:40Z thompsa $");
3
4/*-
5 * Copyright (c) 2003 Scott Long
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31/*
32 * Driver for the MCT (Magic Control Technology) USB-RS232 Converter.
33 * Based on the superb documentation from the linux mct_u232 driver by
34 * Wolfgang Grandeggar <wolfgang@cec.ch>.
35 * This device smells a lot like the Belkin F5U103, except that it has
36 * suffered some mild brain-damage. This driver is based off of the ubsa.c
37 * driver from Alexander Kabaev <kan@freebsd.org>. Merging the two together
38 * might be useful, though the subtle differences might lead to lots of
39 * #ifdef's.
40 */
41
42/*
43 * NOTE: all function names beginning like "umct_cfg_" can only
44 * be called from within the config thread function !
45 */
46
47#include <dev/usb2/include/usb2_devid.h>
48#include <dev/usb2/include/usb2_standard.h>
49#include <dev/usb2/include/usb2_mfunc.h>
50#include <dev/usb2/include/usb2_error.h>
51#include <dev/usb2/include/usb2_cdc.h>
52#include <dev/usb2/include/usb2_defs.h>
53
54#define USB_DEBUG_VAR usb2_debug
55
56#include <dev/usb2/core/usb2_core.h>
57#include <dev/usb2/core/usb2_debug.h>
58#include <dev/usb2/core/usb2_process.h>
59#include <dev/usb2/core/usb2_request.h>
60#include <dev/usb2/core/usb2_lookup.h>
61#include <dev/usb2/core/usb2_util.h>
62#include <dev/usb2/core/usb2_busdma.h>
63#include <dev/usb2/core/usb2_device.h>
64
65#include <dev/usb2/serial/usb2_serial.h>
66
67/* The UMCT advertises the standard 8250 UART registers */
68#define UMCT_GET_MSR 2 /* Get Modem Status Register */
69#define UMCT_GET_MSR_SIZE 1
70#define UMCT_GET_LCR 6 /* Get Line Control Register */
71#define UMCT_GET_LCR_SIZE 1
72#define UMCT_SET_BAUD 5 /* Set the Baud Rate Divisor */
73#define UMCT_SET_BAUD_SIZE 4
74#define UMCT_SET_LCR 7 /* Set Line Control Register */
75#define UMCT_SET_LCR_SIZE 1
76#define UMCT_SET_MCR 10 /* Set Modem Control Register */
77#define UMCT_SET_MCR_SIZE 1
78
79#define UMCT_INTR_INTERVAL 100
80#define UMCT_IFACE_INDEX 0
81#define UMCT_CONFIG_INDEX 1
82
83enum {
84 UMCT_BULK_DT_WR,
85 UMCT_BULK_DT_RD,
86 UMCT_BULK_CS_WR,
87 UMCT_BULK_CS_RD,
88 UMCT_INTR_DT_RD,
89 UMCT_INTR_CS_RD,
90 UMCT_N_TRANSFER = 6,
91};
92
93struct umct_softc {
94 struct usb2_com_super_softc sc_super_ucom;
95 struct usb2_com_softc sc_ucom;
96
97 struct usb2_device *sc_udev;
98 struct usb2_xfer *sc_xfer[UMCT_N_TRANSFER];
99
100 uint32_t sc_unit;
101
102 uint16_t sc_obufsize;
103
104 uint8_t sc_lsr;
105 uint8_t sc_msr;
106 uint8_t sc_lcr;
107 uint8_t sc_mcr;
108
109 uint8_t sc_name[16];
110 uint8_t sc_flags;
111#define UMCT_FLAG_READ_STALL 0x01
112#define UMCT_FLAG_WRITE_STALL 0x02
113#define UMCT_FLAG_INTR_STALL 0x04
114 uint8_t sc_iface_no;
115};
116
117/* prototypes */
118
119static device_probe_t umct_probe;
120static device_attach_t umct_attach;
121static device_detach_t umct_detach;
122
123static usb2_callback_t umct_intr_clear_stall_callback;
124static usb2_callback_t umct_intr_callback;
125static usb2_callback_t umct_write_callback;
126static usb2_callback_t umct_write_clear_stall_callback;
127static usb2_callback_t umct_read_callback;
128static usb2_callback_t umct_read_clear_stall_callback;
129
130static void umct_cfg_do_request(struct umct_softc *, uint8_t, uint16_t,
131 uint32_t);
132static void umct_cfg_get_status(struct usb2_com_softc *, uint8_t *,
133 uint8_t *);
134static void umct_cfg_set_break(struct usb2_com_softc *, uint8_t);
135static void umct_cfg_set_dtr(struct usb2_com_softc *, uint8_t);
136static void umct_cfg_set_rts(struct usb2_com_softc *, uint8_t);
137static uint8_t umct_calc_baud(uint32_t);
138static int umct_pre_param(struct usb2_com_softc *, struct termios *);
139static void umct_cfg_param(struct usb2_com_softc *, struct termios *);
140static void umct_start_read(struct usb2_com_softc *);
141static void umct_stop_read(struct usb2_com_softc *);
142static void umct_start_write(struct usb2_com_softc *);
143static void umct_stop_write(struct usb2_com_softc *);
144
145static const struct usb2_config umct_config[UMCT_N_TRANSFER] = {
146
147 [UMCT_BULK_DT_WR] = {
148 .type = UE_BULK,
149 .endpoint = UE_ADDR_ANY,
150 .direction = UE_DIR_OUT,
151 .mh.bufsize = 0, /* use wMaxPacketSize */
152 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
153 .mh.callback = &umct_write_callback,
154 },
155
156 [UMCT_BULK_DT_RD] = {
157 .type = UE_INTERRUPT,
158 .endpoint = UE_ADDR_ANY,
159 .direction = UE_DIR_IN,
160 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
161 .mh.bufsize = 0, /* use wMaxPacketSize */
162 .mh.callback = &umct_read_callback,
163 .ep_index = 0, /* first interrupt endpoint */
164 },
165
166 [UMCT_BULK_CS_WR] = {
167 .type = UE_CONTROL,
168 .endpoint = 0x00, /* Control pipe */
169 .direction = UE_DIR_ANY,
170 .mh.bufsize = sizeof(struct usb2_device_request),
171 .mh.flags = {},
172 .mh.callback = &umct_write_clear_stall_callback,
173 .mh.timeout = 1000, /* 1 second */
174 .mh.interval = 50, /* 50ms */
175 },
176
177 [UMCT_BULK_CS_RD] = {
178 .type = UE_CONTROL,
179 .endpoint = 0x00, /* Control pipe */
180 .direction = UE_DIR_ANY,
181 .mh.bufsize = sizeof(struct usb2_device_request),
182 .mh.flags = {},
183 .mh.callback = &umct_read_clear_stall_callback,
184 .mh.timeout = 1000, /* 1 second */
185 .mh.interval = 50, /* 50ms */
186 },
187
188 [UMCT_INTR_DT_RD] = {
189 .type = UE_INTERRUPT,
190 .endpoint = UE_ADDR_ANY,
191 .direction = UE_DIR_IN,
192 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
193 .mh.bufsize = 0, /* use wMaxPacketSize */
194 .mh.callback = &umct_intr_callback,
195 .ep_index = 1, /* second interrupt endpoint */
196 },
197
198 [UMCT_INTR_CS_RD] = {
199 .type = UE_CONTROL,
200 .endpoint = 0x00, /* Control pipe */
201 .direction = UE_DIR_ANY,
202 .mh.bufsize = sizeof(struct usb2_device_request),
203 .mh.flags = {},
204 .mh.callback = &umct_intr_clear_stall_callback,
205 .mh.timeout = 1000, /* 1 second */
206 .mh.interval = 50, /* 50ms */
207 },
208};
209
210static const struct usb2_com_callback umct_callback = {
211 .usb2_com_cfg_get_status = &umct_cfg_get_status,
212 .usb2_com_cfg_set_dtr = &umct_cfg_set_dtr,
213 .usb2_com_cfg_set_rts = &umct_cfg_set_rts,
214 .usb2_com_cfg_set_break = &umct_cfg_set_break,
215 .usb2_com_cfg_param = &umct_cfg_param,
216 .usb2_com_pre_param = &umct_pre_param,
217 .usb2_com_start_read = &umct_start_read,
218 .usb2_com_stop_read = &umct_stop_read,
219 .usb2_com_start_write = &umct_start_write,
220 .usb2_com_stop_write = &umct_stop_write,
221};
222
223static const struct usb2_device_id umct_devs[] = {
224 {USB_VPI(USB_VENDOR_MCT, USB_PRODUCT_MCT_USB232, 0)},
225 {USB_VPI(USB_VENDOR_MCT, USB_PRODUCT_MCT_SITECOM_USB232, 0)},
226 {USB_VPI(USB_VENDOR_MCT, USB_PRODUCT_MCT_DU_H3SP_USB232, 0)},
227 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U109, 0)},
228 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U409, 0)},
229};
230
231static device_method_t umct_methods[] = {
232 DEVMETHOD(device_probe, umct_probe),
233 DEVMETHOD(device_attach, umct_attach),
234 DEVMETHOD(device_detach, umct_detach),
235 {0, 0}
236};
237
238static devclass_t umct_devclass;
239
240static driver_t umct_driver = {
241 .name = "umct",
242 .methods = umct_methods,
243 .size = sizeof(struct umct_softc),
244};
245
246DRIVER_MODULE(umct, ushub, umct_driver, umct_devclass, NULL, 0);
247MODULE_DEPEND(umct, usb2_serial, 1, 1, 1);
248MODULE_DEPEND(umct, usb2_core, 1, 1, 1);
249
250static int
251umct_probe(device_t dev)
252{
253 struct usb2_attach_arg *uaa = device_get_ivars(dev);
254
255 if (uaa->usb2_mode != USB_MODE_HOST) {
256 return (ENXIO);
257 }
258 if (uaa->info.bConfigIndex != UMCT_CONFIG_INDEX) {
259 return (ENXIO);
260 }
261 if (uaa->info.bIfaceIndex != UMCT_IFACE_INDEX) {
262 return (ENXIO);
263 }
264 return (usb2_lookup_id_by_uaa(umct_devs, sizeof(umct_devs), uaa));
265}
266
267static int
268umct_attach(device_t dev)
269{
270 struct usb2_attach_arg *uaa = device_get_ivars(dev);
271 struct umct_softc *sc = device_get_softc(dev);
272 int32_t error;
273 uint16_t maxp;
274 uint8_t iface_index;
275
276 if (sc == NULL) {
277 return (ENOMEM);
278 }
279 sc->sc_udev = uaa->device;
280 sc->sc_unit = device_get_unit(dev);
281
282 device_set_usb2_desc(dev);
283
284 snprintf(sc->sc_name, sizeof(sc->sc_name),
285 "%s", device_get_nameunit(dev));
286
287 sc->sc_iface_no = uaa->info.bIfaceNum;
288
289 iface_index = UMCT_IFACE_INDEX;
290 error = usb2_transfer_setup(uaa->device, &iface_index,
291 sc->sc_xfer, umct_config, UMCT_N_TRANSFER, sc, &Giant);
292
293 if (error) {
294 device_printf(dev, "allocating USB "
295 "transfers failed!\n");
296 goto detach;
297 }
298 /*
299 * The real bulk-in endpoint is also marked as an interrupt.
300 * The only way to differentiate it from the real interrupt
301 * endpoint is to look at the wMaxPacketSize field.
302 */
303 maxp = UGETW(sc->sc_xfer[UMCT_BULK_DT_RD]->pipe->edesc->wMaxPacketSize);
304 if (maxp == 0x2) {
305
306 /* guessed wrong - switch around endpoints */
307
308 struct usb2_xfer *temp = sc->sc_xfer[UMCT_INTR_DT_RD];
309
310 sc->sc_xfer[UMCT_INTR_DT_RD] = sc->sc_xfer[UMCT_BULK_DT_RD];
311 sc->sc_xfer[UMCT_BULK_DT_RD] = temp;
312
313 sc->sc_xfer[UMCT_BULK_DT_RD]->callback = &umct_read_callback;
314 sc->sc_xfer[UMCT_INTR_DT_RD]->callback = &umct_intr_callback;
315 }
316 sc->sc_obufsize = sc->sc_xfer[UMCT_BULK_DT_WR]->max_data_length;
317
318 if (uaa->info.idProduct == USB_PRODUCT_MCT_SITECOM_USB232) {
319 if (sc->sc_obufsize > 16) {
320 sc->sc_obufsize = 16;
321 }
322 }
323 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
324 &umct_callback, &Giant);
325 if (error) {
326 goto detach;
327 }
328 return (0); /* success */
329
330detach:
331 umct_detach(dev);
332 return (ENXIO); /* failure */
333}
334
335static int
336umct_detach(device_t dev)
337{
338 struct umct_softc *sc = device_get_softc(dev);
339
340 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1);
341
342 usb2_transfer_unsetup(sc->sc_xfer, UMCT_N_TRANSFER);
343
344 return (0);
345}
346
347static void
348umct_cfg_do_request(struct umct_softc *sc, uint8_t request,
349 uint16_t len, uint32_t value)
350{
351 struct usb2_device_request req;
352 usb2_error_t err;
353 uint8_t temp[4];
354
355 if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
356 goto done;
357 }
358 if (len > 4) {
359 len = 4;
360 }
361 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
362 req.bRequest = request;
363 USETW(req.wValue, 0);
364 req.wIndex[0] = sc->sc_iface_no;
365 req.wIndex[1] = 0;
366 USETW(req.wLength, len);
367 USETDW(temp, value);
368
369 err = usb2_do_request_flags(sc->sc_udev, &Giant, &req,
370 temp, 0, NULL, 1000);
371
372 if (err) {
373 DPRINTFN(0, "device request failed, err=%s "
374 "(ignored)\n", usb2_errstr(err));
375 }
376done:
377 return;
378}
379
380static void
381umct_intr_clear_stall_callback(struct usb2_xfer *xfer)
382{
383 struct umct_softc *sc = xfer->priv_sc;
384 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_INTR_DT_RD];
385
386 if (usb2_clear_stall_callback(xfer, xfer_other)) {
387 DPRINTF("stall cleared\n");
388 sc->sc_flags &= ~UMCT_FLAG_INTR_STALL;
389 usb2_transfer_start(xfer_other);
390 }
391}
392
393static void
394umct_intr_callback(struct usb2_xfer *xfer)
395{
396 struct umct_softc *sc = xfer->priv_sc;
397 uint8_t buf[2];
398
399 switch (USB_GET_STATE(xfer)) {
400 case USB_ST_TRANSFERRED:
401 if (xfer->actlen < 2) {
402 DPRINTF("too short message\n");
403 goto tr_setup;
404 }
405 usb2_copy_out(xfer->frbuffers, 0, buf, sizeof(buf));
406
407 sc->sc_msr = buf[0];
408 sc->sc_lsr = buf[1];
409
410 usb2_com_status_change(&sc->sc_ucom);
411
412 case USB_ST_SETUP:
413tr_setup:
414 if (sc->sc_flags & UMCT_FLAG_INTR_STALL) {
415 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_CS_RD]);
416 } else {
417 xfer->frlengths[0] = xfer->max_data_length;
418 usb2_start_hardware(xfer);
419 }
420 return;
421
422 default: /* Error */
423 if (xfer->error != USB_ERR_CANCELLED) {
424 /* start clear stall */
425 sc->sc_flags |= UMCT_FLAG_INTR_STALL;
426 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_CS_RD]);
427 }
428 return;
429
430 }
431}
432
433static void
434umct_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr)
435{
436 struct umct_softc *sc = ucom->sc_parent;
437
438 *lsr = sc->sc_lsr;
439 *msr = sc->sc_msr;
440}
441
442static void
443umct_cfg_set_break(struct usb2_com_softc *ucom, uint8_t onoff)
444{
445 struct umct_softc *sc = ucom->sc_parent;
446
447 if (onoff)
448 sc->sc_lcr |= 0x40;
449 else
450 sc->sc_lcr &= ~0x40;
451
452 umct_cfg_do_request(sc, UMCT_SET_LCR, UMCT_SET_LCR_SIZE, sc->sc_lcr);
453}
454
455static void
456umct_cfg_set_dtr(struct usb2_com_softc *ucom, uint8_t onoff)
457{
458 struct umct_softc *sc = ucom->sc_parent;
459
460 if (onoff)
461 sc->sc_mcr |= 0x01;
462 else
463 sc->sc_mcr &= ~0x01;
464
465 umct_cfg_do_request(sc, UMCT_SET_MCR, UMCT_SET_MCR_SIZE, sc->sc_mcr);
466}
467
468static void
469umct_cfg_set_rts(struct usb2_com_softc *ucom, uint8_t onoff)
470{
471 struct umct_softc *sc = ucom->sc_parent;
472
473 if (onoff)
474 sc->sc_mcr |= 0x02;
475 else
476 sc->sc_mcr &= ~0x02;
477
478 umct_cfg_do_request(sc, UMCT_SET_MCR, UMCT_SET_MCR_SIZE, sc->sc_mcr);
479}
480
481static uint8_t
482umct_calc_baud(uint32_t baud)
483{
484 switch (baud) {
485 case B300:return (0x1);
486 case B600:
487 return (0x2);
488 case B1200:
489 return (0x3);
490 case B2400:
491 return (0x4);
492 case B4800:
493 return (0x6);
494 case B9600:
495 return (0x8);
496 case B19200:
497 return (0x9);
498 case B38400:
499 return (0xa);
500 case B57600:
501 return (0xb);
502 case 115200:
503 return (0xc);
504 case B0:
505 default:
506 break;
507 }
508 return (0x0);
509}
510
511static int
512umct_pre_param(struct usb2_com_softc *ucom, struct termios *t)
513{
514 return (0); /* we accept anything */
515}
516
517static void
518umct_cfg_param(struct usb2_com_softc *ucom, struct termios *t)
519{
520 struct umct_softc *sc = ucom->sc_parent;
521 uint32_t value;
522
523 value = umct_calc_baud(t->c_ospeed);
524 umct_cfg_do_request(sc, UMCT_SET_BAUD, UMCT_SET_BAUD_SIZE, value);
525
526 value = (sc->sc_lcr & 0x40);
527
528 switch (t->c_cflag & CSIZE) {
529 case CS5:
530 value |= 0x0;
531 break;
532 case CS6:
533 value |= 0x1;
534 break;
535 case CS7:
536 value |= 0x2;
537 break;
538 default:
539 case CS8:
540 value |= 0x3;
541 break;
542 }
543
544 value |= (t->c_cflag & CSTOPB) ? 0x4 : 0;
545 if (t->c_cflag & PARENB) {
546 value |= 0x8;
547 value |= (t->c_cflag & PARODD) ? 0x0 : 0x10;
548 }
549 /*
550 * XXX There doesn't seem to be a way to tell the device
551 * to use flow control.
552 */
553
554 sc->sc_lcr = value;
555 umct_cfg_do_request(sc, UMCT_SET_LCR, UMCT_SET_LCR_SIZE, value);
556}
557
558static void
559umct_start_read(struct usb2_com_softc *ucom)
560{
561 struct umct_softc *sc = ucom->sc_parent;
562
563 /* start interrupt endpoint */
564 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_DT_RD]);
565
566 /* start read endpoint */
567 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_DT_RD]);
568}
569
570static void
571umct_stop_read(struct usb2_com_softc *ucom)
572{
573 struct umct_softc *sc = ucom->sc_parent;
574
575 /* stop interrupt endpoint */
576 usb2_transfer_stop(sc->sc_xfer[UMCT_INTR_CS_RD]);
577 usb2_transfer_stop(sc->sc_xfer[UMCT_INTR_DT_RD]);
578
579 /* stop read endpoint */
580 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_CS_RD]);
581 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_RD]);
582}
583
584static void
585umct_start_write(struct usb2_com_softc *ucom)
586{
587 struct umct_softc *sc = ucom->sc_parent;
588
589 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_DT_WR]);
590}
591
592static void
593umct_stop_write(struct usb2_com_softc *ucom)
594{
595 struct umct_softc *sc = ucom->sc_parent;
596
597 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_CS_WR]);
598 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_WR]);
599}
600
601static void
602umct_write_callback(struct usb2_xfer *xfer)
603{
604 struct umct_softc *sc = xfer->priv_sc;
605 uint32_t actlen;
606
607 switch (USB_GET_STATE(xfer)) {
608 case USB_ST_SETUP:
609 case USB_ST_TRANSFERRED:
610 if (sc->sc_flags & UMCT_FLAG_WRITE_STALL) {
611 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_WR]);
612 return;
613 }
614 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
615 sc->sc_obufsize, &actlen)) {
616
617 xfer->frlengths[0] = actlen;
618 usb2_start_hardware(xfer);
619 }
620 return;
621
622 default: /* Error */
623 if (xfer->error != USB_ERR_CANCELLED) {
624 sc->sc_flags |= UMCT_FLAG_WRITE_STALL;
625 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_WR]);
626 }
627 return;
628
629 }
630}
631
632static void
633umct_write_clear_stall_callback(struct usb2_xfer *xfer)
634{
635 struct umct_softc *sc = xfer->priv_sc;
636 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_BULK_DT_WR];
637
638 if (usb2_clear_stall_callback(xfer, xfer_other)) {
639 DPRINTF("stall cleared\n");
640 sc->sc_flags &= ~UMCT_FLAG_WRITE_STALL;
641 usb2_transfer_start(xfer_other);
642 }
643}
644
645static void
646umct_read_callback(struct usb2_xfer *xfer)
647{
648 struct umct_softc *sc = xfer->priv_sc;
649
650 switch (USB_GET_STATE(xfer)) {
651 case USB_ST_TRANSFERRED:
652 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers,
653 0, xfer->actlen);
654
655 case USB_ST_SETUP:
656 if (sc->sc_flags & UMCT_FLAG_READ_STALL) {
657 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_RD]);
658 } else {
659 xfer->frlengths[0] = xfer->max_data_length;
660 usb2_start_hardware(xfer);
661 }
662 return;
663
664 default: /* Error */
665 if (xfer->error != USB_ERR_CANCELLED) {
666 sc->sc_flags |= UMCT_FLAG_READ_STALL;
667 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_RD]);
668 }
669 return;
670
671 }
672}
673
674static void
675umct_read_clear_stall_callback(struct usb2_xfer *xfer)
676{
677 struct umct_softc *sc = xfer->priv_sc;
678 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_BULK_DT_RD];
679
680 if (usb2_clear_stall_callback(xfer, xfer_other)) {
681 DPRINTF("stall cleared\n");
682 sc->sc_flags &= ~UMCT_FLAG_READ_STALL;
683 usb2_transfer_start(xfer_other);
684 }
685}