Deleted Added
full compact
umct.c (187176) umct.c (187259)
1#include <sys/cdefs.h>
1#include <sys/cdefs.h>
2__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/umct2.c 187176 2009-01-13 19:03:47Z thompsa $");
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
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
83#define UMCT_ENDPT_MAX 6 /* units */
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};
84
85struct umct_softc {
86 struct usb2_com_super_softc sc_super_ucom;
87 struct usb2_com_softc sc_ucom;
88
89 struct usb2_device *sc_udev;
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;
90 struct usb2_xfer *sc_xfer[UMCT_ENDPT_MAX];
98 struct usb2_xfer *sc_xfer[UMCT_N_TRANSFER];
91
92 uint32_t sc_unit;
93
94 uint16_t sc_obufsize;
95
96 uint8_t sc_lsr;
97 uint8_t sc_msr;
98 uint8_t sc_lcr;
99 uint8_t sc_mcr;
100
101 uint8_t sc_name[16];
102 uint8_t sc_flags;
103#define UMCT_FLAG_READ_STALL 0x01
104#define UMCT_FLAG_WRITE_STALL 0x02
105#define UMCT_FLAG_INTR_STALL 0x04
106 uint8_t sc_iface_no;
107};
108
109/* prototypes */
110
111static device_probe_t umct_probe;
112static device_attach_t umct_attach;
113static device_detach_t umct_detach;
114
115static usb2_callback_t umct_intr_clear_stall_callback;
116static usb2_callback_t umct_intr_callback;
117static usb2_callback_t umct_write_callback;
118static usb2_callback_t umct_write_clear_stall_callback;
119static usb2_callback_t umct_read_callback;
120static usb2_callback_t umct_read_clear_stall_callback;
121
122static void umct_cfg_do_request(struct umct_softc *, uint8_t, uint16_t,
123 uint32_t);
124static void umct_cfg_get_status(struct usb2_com_softc *, uint8_t *,
125 uint8_t *);
126static void umct_cfg_set_break(struct usb2_com_softc *, uint8_t);
127static void umct_cfg_set_dtr(struct usb2_com_softc *, uint8_t);
128static void umct_cfg_set_rts(struct usb2_com_softc *, uint8_t);
129static uint8_t umct_calc_baud(uint32_t);
130static int umct_pre_param(struct usb2_com_softc *, struct termios *);
131static void umct_cfg_param(struct usb2_com_softc *, struct termios *);
132static void umct_start_read(struct usb2_com_softc *);
133static void umct_stop_read(struct usb2_com_softc *);
134static void umct_start_write(struct usb2_com_softc *);
135static void umct_stop_write(struct usb2_com_softc *);
136
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
137static const struct usb2_config umct_config[UMCT_ENDPT_MAX] = {
145static const struct usb2_config umct_config[UMCT_N_TRANSFER] = {
138
146
139 [0] = {
147 [UMCT_BULK_DT_WR] = {
140 .type = UE_BULK,
141 .endpoint = UE_ADDR_ANY,
142 .direction = UE_DIR_OUT,
143 .mh.bufsize = 0, /* use wMaxPacketSize */
144 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
145 .mh.callback = &umct_write_callback,
146 },
147
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
148 [1] = {
156 [UMCT_BULK_DT_RD] = {
149 .type = UE_INTERRUPT,
150 .endpoint = UE_ADDR_ANY,
151 .direction = UE_DIR_IN,
152 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
153 .mh.bufsize = 0, /* use wMaxPacketSize */
154 .mh.callback = &umct_read_callback,
155 .ep_index = 0, /* first interrupt endpoint */
156 },
157
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
158 [2] = {
166 [UMCT_BULK_CS_WR] = {
159 .type = UE_CONTROL,
160 .endpoint = 0x00, /* Control pipe */
161 .direction = UE_DIR_ANY,
162 .mh.bufsize = sizeof(struct usb2_device_request),
163 .mh.flags = {},
164 .mh.callback = &umct_write_clear_stall_callback,
165 .mh.timeout = 1000, /* 1 second */
166 .mh.interval = 50, /* 50ms */
167 },
168
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
169 [3] = {
177 [UMCT_BULK_CS_RD] = {
170 .type = UE_CONTROL,
171 .endpoint = 0x00, /* Control pipe */
172 .direction = UE_DIR_ANY,
173 .mh.bufsize = sizeof(struct usb2_device_request),
174 .mh.flags = {},
175 .mh.callback = &umct_read_clear_stall_callback,
176 .mh.timeout = 1000, /* 1 second */
177 .mh.interval = 50, /* 50ms */
178 },
179
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
180 [4] = {
188 [UMCT_INTR_DT_RD] = {
181 .type = UE_INTERRUPT,
182 .endpoint = UE_ADDR_ANY,
183 .direction = UE_DIR_IN,
184 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
185 .mh.bufsize = 0, /* use wMaxPacketSize */
186 .mh.callback = &umct_intr_callback,
187 .ep_index = 1, /* second interrupt endpoint */
188 },
189
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
190 [5] = {
198 [UMCT_INTR_CS_RD] = {
191 .type = UE_CONTROL,
192 .endpoint = 0x00, /* Control pipe */
193 .direction = UE_DIR_ANY,
194 .mh.bufsize = sizeof(struct usb2_device_request),
195 .mh.flags = {},
196 .mh.callback = &umct_intr_clear_stall_callback,
197 .mh.timeout = 1000, /* 1 second */
198 .mh.interval = 50, /* 50ms */
199 },
200};
201
202static const struct usb2_com_callback umct_callback = {
203 .usb2_com_cfg_get_status = &umct_cfg_get_status,
204 .usb2_com_cfg_set_dtr = &umct_cfg_set_dtr,
205 .usb2_com_cfg_set_rts = &umct_cfg_set_rts,
206 .usb2_com_cfg_set_break = &umct_cfg_set_break,
207 .usb2_com_cfg_param = &umct_cfg_param,
208 .usb2_com_pre_param = &umct_pre_param,
209 .usb2_com_start_read = &umct_start_read,
210 .usb2_com_stop_read = &umct_stop_read,
211 .usb2_com_start_write = &umct_start_write,
212 .usb2_com_stop_write = &umct_stop_write,
213};
214
215static const struct usb2_device_id umct_devs[] = {
216 {USB_VPI(USB_VENDOR_MCT, USB_PRODUCT_MCT_USB232, 0)},
217 {USB_VPI(USB_VENDOR_MCT, USB_PRODUCT_MCT_SITECOM_USB232, 0)},
218 {USB_VPI(USB_VENDOR_MCT, USB_PRODUCT_MCT_DU_H3SP_USB232, 0)},
219 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U109, 0)},
220 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U409, 0)},
221};
222
223static device_method_t umct_methods[] = {
224 DEVMETHOD(device_probe, umct_probe),
225 DEVMETHOD(device_attach, umct_attach),
226 DEVMETHOD(device_detach, umct_detach),
227 {0, 0}
228};
229
230static devclass_t umct_devclass;
231
232static driver_t umct_driver = {
233 .name = "umct",
234 .methods = umct_methods,
235 .size = sizeof(struct umct_softc),
236};
237
238DRIVER_MODULE(umct, ushub, umct_driver, umct_devclass, NULL, 0);
239MODULE_DEPEND(umct, usb2_serial, 1, 1, 1);
240MODULE_DEPEND(umct, usb2_core, 1, 1, 1);
241
242static int
243umct_probe(device_t dev)
244{
245 struct usb2_attach_arg *uaa = device_get_ivars(dev);
246
247 if (uaa->usb2_mode != USB_MODE_HOST) {
248 return (ENXIO);
249 }
250 if (uaa->info.bConfigIndex != UMCT_CONFIG_INDEX) {
251 return (ENXIO);
252 }
253 if (uaa->info.bIfaceIndex != UMCT_IFACE_INDEX) {
254 return (ENXIO);
255 }
256 return (usb2_lookup_id_by_uaa(umct_devs, sizeof(umct_devs), uaa));
257}
258
259static int
260umct_attach(device_t dev)
261{
262 struct usb2_attach_arg *uaa = device_get_ivars(dev);
263 struct umct_softc *sc = device_get_softc(dev);
264 int32_t error;
265 uint16_t maxp;
266 uint8_t iface_index;
267
268 if (sc == NULL) {
269 return (ENOMEM);
270 }
271 sc->sc_udev = uaa->device;
272 sc->sc_unit = device_get_unit(dev);
273
274 device_set_usb2_desc(dev);
275
276 snprintf(sc->sc_name, sizeof(sc->sc_name),
277 "%s", device_get_nameunit(dev));
278
279 sc->sc_iface_no = uaa->info.bIfaceNum;
280
281 iface_index = UMCT_IFACE_INDEX;
282 error = usb2_transfer_setup(uaa->device, &iface_index,
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,
283 sc->sc_xfer, umct_config, UMCT_ENDPT_MAX, sc, &Giant);
291 sc->sc_xfer, umct_config, UMCT_N_TRANSFER, sc, &Giant);
284
285 if (error) {
286 device_printf(dev, "allocating USB "
287 "transfers failed!\n");
288 goto detach;
289 }
290 /*
291 * The real bulk-in endpoint is also marked as an interrupt.
292 * The only way to differentiate it from the real interrupt
293 * endpoint is to look at the wMaxPacketSize field.
294 */
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 */
295 maxp = UGETW(sc->sc_xfer[1]->pipe->edesc->wMaxPacketSize);
303 maxp = UGETW(sc->sc_xfer[UMCT_BULK_DT_RD]->pipe->edesc->wMaxPacketSize);
296 if (maxp == 0x2) {
297
298 /* guessed wrong - switch around endpoints */
299
304 if (maxp == 0x2) {
305
306 /* guessed wrong - switch around endpoints */
307
300 struct usb2_xfer *temp = sc->sc_xfer[4];
308 struct usb2_xfer *temp = sc->sc_xfer[UMCT_INTR_DT_RD];
301
309
302 sc->sc_xfer[4] = sc->sc_xfer[1];
303 sc->sc_xfer[1] = temp;
310 sc->sc_xfer[UMCT_INTR_DT_RD] = sc->sc_xfer[UMCT_BULK_DT_RD];
311 sc->sc_xfer[UMCT_BULK_DT_RD] = temp;
304
312
305 sc->sc_xfer[1]->callback = &umct_read_callback;
306 sc->sc_xfer[4]->callback = &umct_intr_callback;
313 sc->sc_xfer[UMCT_BULK_DT_RD]->callback = &umct_read_callback;
314 sc->sc_xfer[UMCT_INTR_DT_RD]->callback = &umct_intr_callback;
307 }
315 }
308 sc->sc_obufsize = sc->sc_xfer[0]->max_data_length;
316 sc->sc_obufsize = sc->sc_xfer[UMCT_BULK_DT_WR]->max_data_length;
309
310 if (uaa->info.idProduct == USB_PRODUCT_MCT_SITECOM_USB232) {
311 if (sc->sc_obufsize > 16) {
312 sc->sc_obufsize = 16;
313 }
314 }
315 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
316 &umct_callback, &Giant);
317 if (error) {
318 goto detach;
319 }
320 return (0); /* success */
321
322detach:
323 umct_detach(dev);
324 return (ENXIO); /* failure */
325}
326
327static int
328umct_detach(device_t dev)
329{
330 struct umct_softc *sc = device_get_softc(dev);
331
332 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1);
333
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
334 usb2_transfer_unsetup(sc->sc_xfer, UMCT_ENDPT_MAX);
342 usb2_transfer_unsetup(sc->sc_xfer, UMCT_N_TRANSFER);
335
336 return (0);
337}
338
339static void
340umct_cfg_do_request(struct umct_softc *sc, uint8_t request,
341 uint16_t len, uint32_t value)
342{
343 struct usb2_device_request req;
344 usb2_error_t err;
345 uint8_t temp[4];
346
347 if (usb2_com_cfg_is_gone(&sc->sc_ucom)) {
348 goto done;
349 }
350 if (len > 4) {
351 len = 4;
352 }
353 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
354 req.bRequest = request;
355 USETW(req.wValue, 0);
356 req.wIndex[0] = sc->sc_iface_no;
357 req.wIndex[1] = 0;
358 USETW(req.wLength, len);
359 USETDW(temp, value);
360
361 err = usb2_do_request_flags(sc->sc_udev, &Giant, &req,
362 temp, 0, NULL, 1000);
363
364 if (err) {
365 DPRINTFN(0, "device request failed, err=%s "
366 "(ignored)\n", usb2_errstr(err));
367 }
368done:
369 return;
370}
371
372static void
373umct_intr_clear_stall_callback(struct usb2_xfer *xfer)
374{
375 struct umct_softc *sc = xfer->priv_sc;
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;
376 struct usb2_xfer *xfer_other = sc->sc_xfer[4];
384 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_INTR_DT_RD];
377
378 if (usb2_clear_stall_callback(xfer, xfer_other)) {
379 DPRINTF("stall cleared\n");
380 sc->sc_flags &= ~UMCT_FLAG_INTR_STALL;
381 usb2_transfer_start(xfer_other);
382 }
383}
384
385static void
386umct_intr_callback(struct usb2_xfer *xfer)
387{
388 struct umct_softc *sc = xfer->priv_sc;
389 uint8_t buf[2];
390
391 switch (USB_GET_STATE(xfer)) {
392 case USB_ST_TRANSFERRED:
393 if (xfer->actlen < 2) {
394 DPRINTF("too short message\n");
395 goto tr_setup;
396 }
397 usb2_copy_out(xfer->frbuffers, 0, buf, sizeof(buf));
398
399 sc->sc_msr = buf[0];
400 sc->sc_lsr = buf[1];
401
402 usb2_com_status_change(&sc->sc_ucom);
403
404 case USB_ST_SETUP:
405tr_setup:
406 if (sc->sc_flags & UMCT_FLAG_INTR_STALL) {
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) {
407 usb2_transfer_start(sc->sc_xfer[5]);
415 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_CS_RD]);
408 } else {
409 xfer->frlengths[0] = xfer->max_data_length;
410 usb2_start_hardware(xfer);
411 }
412 return;
413
414 default: /* Error */
415 if (xfer->error != USB_ERR_CANCELLED) {
416 /* start clear stall */
417 sc->sc_flags |= UMCT_FLAG_INTR_STALL;
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;
418 usb2_transfer_start(sc->sc_xfer[5]);
426 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_CS_RD]);
419 }
420 return;
421
422 }
423}
424
425static void
426umct_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr)
427{
428 struct umct_softc *sc = ucom->sc_parent;
429
430 *lsr = sc->sc_lsr;
431 *msr = sc->sc_msr;
432}
433
434static void
435umct_cfg_set_break(struct usb2_com_softc *ucom, uint8_t onoff)
436{
437 struct umct_softc *sc = ucom->sc_parent;
438
439 if (onoff)
440 sc->sc_lcr |= 0x40;
441 else
442 sc->sc_lcr &= ~0x40;
443
444 umct_cfg_do_request(sc, UMCT_SET_LCR, UMCT_SET_LCR_SIZE, sc->sc_lcr);
445}
446
447static void
448umct_cfg_set_dtr(struct usb2_com_softc *ucom, uint8_t onoff)
449{
450 struct umct_softc *sc = ucom->sc_parent;
451
452 if (onoff)
453 sc->sc_mcr |= 0x01;
454 else
455 sc->sc_mcr &= ~0x01;
456
457 umct_cfg_do_request(sc, UMCT_SET_MCR, UMCT_SET_MCR_SIZE, sc->sc_mcr);
458}
459
460static void
461umct_cfg_set_rts(struct usb2_com_softc *ucom, uint8_t onoff)
462{
463 struct umct_softc *sc = ucom->sc_parent;
464
465 if (onoff)
466 sc->sc_mcr |= 0x02;
467 else
468 sc->sc_mcr &= ~0x02;
469
470 umct_cfg_do_request(sc, UMCT_SET_MCR, UMCT_SET_MCR_SIZE, sc->sc_mcr);
471}
472
473static uint8_t
474umct_calc_baud(uint32_t baud)
475{
476 switch (baud) {
477 case B300:return (0x1);
478 case B600:
479 return (0x2);
480 case B1200:
481 return (0x3);
482 case B2400:
483 return (0x4);
484 case B4800:
485 return (0x6);
486 case B9600:
487 return (0x8);
488 case B19200:
489 return (0x9);
490 case B38400:
491 return (0xa);
492 case B57600:
493 return (0xb);
494 case 115200:
495 return (0xc);
496 case B0:
497 default:
498 break;
499 }
500 return (0x0);
501}
502
503static int
504umct_pre_param(struct usb2_com_softc *ucom, struct termios *t)
505{
506 return (0); /* we accept anything */
507}
508
509static void
510umct_cfg_param(struct usb2_com_softc *ucom, struct termios *t)
511{
512 struct umct_softc *sc = ucom->sc_parent;
513 uint32_t value;
514
515 value = umct_calc_baud(t->c_ospeed);
516 umct_cfg_do_request(sc, UMCT_SET_BAUD, UMCT_SET_BAUD_SIZE, value);
517
518 value = (sc->sc_lcr & 0x40);
519
520 switch (t->c_cflag & CSIZE) {
521 case CS5:
522 value |= 0x0;
523 break;
524 case CS6:
525 value |= 0x1;
526 break;
527 case CS7:
528 value |= 0x2;
529 break;
530 default:
531 case CS8:
532 value |= 0x3;
533 break;
534 }
535
536 value |= (t->c_cflag & CSTOPB) ? 0x4 : 0;
537 if (t->c_cflag & PARENB) {
538 value |= 0x8;
539 value |= (t->c_cflag & PARODD) ? 0x0 : 0x10;
540 }
541 /*
542 * XXX There doesn't seem to be a way to tell the device
543 * to use flow control.
544 */
545
546 sc->sc_lcr = value;
547 umct_cfg_do_request(sc, UMCT_SET_LCR, UMCT_SET_LCR_SIZE, value);
548}
549
550static void
551umct_start_read(struct usb2_com_softc *ucom)
552{
553 struct umct_softc *sc = ucom->sc_parent;
554
555 /* start interrupt endpoint */
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 */
556 usb2_transfer_start(sc->sc_xfer[4]);
564 usb2_transfer_start(sc->sc_xfer[UMCT_INTR_DT_RD]);
557
558 /* start read endpoint */
565
566 /* start read endpoint */
559 usb2_transfer_start(sc->sc_xfer[1]);
567 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_DT_RD]);
560}
561
562static void
563umct_stop_read(struct usb2_com_softc *ucom)
564{
565 struct umct_softc *sc = ucom->sc_parent;
566
567 /* stop interrupt endpoint */
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 */
568 usb2_transfer_stop(sc->sc_xfer[5]);
569 usb2_transfer_stop(sc->sc_xfer[4]);
576 usb2_transfer_stop(sc->sc_xfer[UMCT_INTR_CS_RD]);
577 usb2_transfer_stop(sc->sc_xfer[UMCT_INTR_DT_RD]);
570
571 /* stop read endpoint */
578
579 /* stop read endpoint */
572 usb2_transfer_stop(sc->sc_xfer[3]);
573 usb2_transfer_stop(sc->sc_xfer[1]);
580 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_CS_RD]);
581 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_RD]);
574}
575
576static void
577umct_start_write(struct usb2_com_softc *ucom)
578{
579 struct umct_softc *sc = ucom->sc_parent;
580
582}
583
584static void
585umct_start_write(struct usb2_com_softc *ucom)
586{
587 struct umct_softc *sc = ucom->sc_parent;
588
581 usb2_transfer_start(sc->sc_xfer[0]);
589 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_DT_WR]);
582}
583
584static void
585umct_stop_write(struct usb2_com_softc *ucom)
586{
587 struct umct_softc *sc = ucom->sc_parent;
588
590}
591
592static void
593umct_stop_write(struct usb2_com_softc *ucom)
594{
595 struct umct_softc *sc = ucom->sc_parent;
596
589 usb2_transfer_stop(sc->sc_xfer[2]);
590 usb2_transfer_stop(sc->sc_xfer[0]);
597 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_CS_WR]);
598 usb2_transfer_stop(sc->sc_xfer[UMCT_BULK_DT_WR]);
591}
592
593static void
594umct_write_callback(struct usb2_xfer *xfer)
595{
596 struct umct_softc *sc = xfer->priv_sc;
597 uint32_t actlen;
598
599 switch (USB_GET_STATE(xfer)) {
600 case USB_ST_SETUP:
601 case USB_ST_TRANSFERRED:
602 if (sc->sc_flags & UMCT_FLAG_WRITE_STALL) {
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) {
603 usb2_transfer_start(sc->sc_xfer[2]);
611 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_WR]);
604 return;
605 }
606 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
607 sc->sc_obufsize, &actlen)) {
608
609 xfer->frlengths[0] = actlen;
610 usb2_start_hardware(xfer);
611 }
612 return;
613
614 default: /* Error */
615 if (xfer->error != USB_ERR_CANCELLED) {
616 sc->sc_flags |= UMCT_FLAG_WRITE_STALL;
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;
617 usb2_transfer_start(sc->sc_xfer[2]);
625 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_WR]);
618 }
619 return;
620
621 }
622}
623
624static void
625umct_write_clear_stall_callback(struct usb2_xfer *xfer)
626{
627 struct umct_softc *sc = xfer->priv_sc;
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;
628 struct usb2_xfer *xfer_other = sc->sc_xfer[0];
636 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_BULK_DT_WR];
629
630 if (usb2_clear_stall_callback(xfer, xfer_other)) {
631 DPRINTF("stall cleared\n");
632 sc->sc_flags &= ~UMCT_FLAG_WRITE_STALL;
633 usb2_transfer_start(xfer_other);
634 }
635}
636
637static void
638umct_read_callback(struct usb2_xfer *xfer)
639{
640 struct umct_softc *sc = xfer->priv_sc;
641
642 switch (USB_GET_STATE(xfer)) {
643 case USB_ST_TRANSFERRED:
644 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers,
645 0, xfer->actlen);
646
647 case USB_ST_SETUP:
648 if (sc->sc_flags & UMCT_FLAG_READ_STALL) {
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) {
649 usb2_transfer_start(sc->sc_xfer[3]);
657 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_RD]);
650 } else {
651 xfer->frlengths[0] = xfer->max_data_length;
652 usb2_start_hardware(xfer);
653 }
654 return;
655
656 default: /* Error */
657 if (xfer->error != USB_ERR_CANCELLED) {
658 sc->sc_flags |= UMCT_FLAG_READ_STALL;
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;
659 usb2_transfer_start(sc->sc_xfer[3]);
667 usb2_transfer_start(sc->sc_xfer[UMCT_BULK_CS_RD]);
660 }
661 return;
662
663 }
664}
665
666static void
667umct_read_clear_stall_callback(struct usb2_xfer *xfer)
668{
669 struct umct_softc *sc = xfer->priv_sc;
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;
670 struct usb2_xfer *xfer_other = sc->sc_xfer[1];
678 struct usb2_xfer *xfer_other = sc->sc_xfer[UMCT_BULK_DT_RD];
671
672 if (usb2_clear_stall_callback(xfer, xfer_other)) {
673 DPRINTF("stall cleared\n");
674 sc->sc_flags &= ~UMCT_FLAG_READ_STALL;
675 usb2_transfer_start(xfer_other);
676 }
677}
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}