uark.c (187970) | uark.c (188413) |
---|---|
1/* $OpenBSD: uark.c,v 1.1 2006/08/14 08:30:22 jsg Exp $ */ 2 3/* 4 * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * | 1/* $OpenBSD: uark.c,v 1.1 2006/08/14 08:30:22 jsg Exp $ */ 2 3/* 4 * Copyright (c) 2006 Jonathan Gray <jsg@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * |
18 * $FreeBSD: head/sys/dev/usb2/serial/uark2.c 187970 2009-02-01 00:51:25Z thompsa $ | 18 * $FreeBSD: head/sys/dev/usb2/serial/uark2.c 188413 2009-02-09 22:05:25Z thompsa $ |
19 */ 20 21/* 22 * NOTE: all function names beginning like "uark_cfg_" can only 23 * be called from within the config thread function ! 24 */ 25 26#include <dev/usb2/include/usb2_devid.h> --- 32 unchanged lines hidden (view full) --- 59#define UARK_REQUEST 0xfe 60 61#define UARK_CONFIG_INDEX 0 62#define UARK_IFACE_INDEX 0 63 64enum { 65 UARK_BULK_DT_WR, 66 UARK_BULK_DT_RD, | 19 */ 20 21/* 22 * NOTE: all function names beginning like "uark_cfg_" can only 23 * be called from within the config thread function ! 24 */ 25 26#include <dev/usb2/include/usb2_devid.h> --- 32 unchanged lines hidden (view full) --- 59#define UARK_REQUEST 0xfe 60 61#define UARK_CONFIG_INDEX 0 62#define UARK_IFACE_INDEX 0 63 64enum { 65 UARK_BULK_DT_WR, 66 UARK_BULK_DT_RD, |
67 UARK_BULK_CS_WR, 68 UARK_BULK_CS_RD, 69 UARK_N_TRANSFER = 4, | 67 UARK_N_TRANSFER, |
70}; 71 72struct uark_softc { 73 struct usb2_com_super_softc sc_super_ucom; 74 struct usb2_com_softc sc_ucom; 75 76 struct usb2_xfer *sc_xfer[UARK_N_TRANSFER]; 77 struct usb2_device *sc_udev; 78 | 68}; 69 70struct uark_softc { 71 struct usb2_com_super_softc sc_super_ucom; 72 struct usb2_com_softc sc_ucom; 73 74 struct usb2_xfer *sc_xfer[UARK_N_TRANSFER]; 75 struct usb2_device *sc_udev; 76 |
79 uint8_t sc_flags; 80#define UARK_FLAG_BULK_READ_STALL 0x01 81#define UARK_FLAG_BULK_WRITE_STALL 0x02 | |
82 uint8_t sc_msr; 83 uint8_t sc_lsr; 84}; 85 86/* prototypes */ 87 88static device_probe_t uark_probe; 89static device_attach_t uark_attach; 90static device_detach_t uark_detach; 91 92static usb2_callback_t uark_bulk_write_callback; | 77 uint8_t sc_msr; 78 uint8_t sc_lsr; 79}; 80 81/* prototypes */ 82 83static device_probe_t uark_probe; 84static device_attach_t uark_attach; 85static device_detach_t uark_detach; 86 87static usb2_callback_t uark_bulk_write_callback; |
93static usb2_callback_t uark_bulk_write_clear_stall_callback; | |
94static usb2_callback_t uark_bulk_read_callback; | 88static usb2_callback_t uark_bulk_read_callback; |
95static usb2_callback_t uark_bulk_read_clear_stall_callback; | |
96 97static void uark_start_read(struct usb2_com_softc *); 98static void uark_stop_read(struct usb2_com_softc *); 99static void uark_start_write(struct usb2_com_softc *); 100static void uark_stop_write(struct usb2_com_softc *); 101static int uark_pre_param(struct usb2_com_softc *, struct termios *); 102static void uark_cfg_param(struct usb2_com_softc *, struct termios *); 103static void uark_cfg_get_status(struct usb2_com_softc *, uint8_t *, --- 16 unchanged lines hidden (view full) --- 120 [UARK_BULK_DT_RD] = { 121 .type = UE_BULK, 122 .endpoint = UE_ADDR_ANY, 123 .direction = UE_DIR_IN, 124 .mh.bufsize = UARK_BUF_SIZE, 125 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 126 .mh.callback = &uark_bulk_read_callback, 127 }, | 89 90static void uark_start_read(struct usb2_com_softc *); 91static void uark_stop_read(struct usb2_com_softc *); 92static void uark_start_write(struct usb2_com_softc *); 93static void uark_stop_write(struct usb2_com_softc *); 94static int uark_pre_param(struct usb2_com_softc *, struct termios *); 95static void uark_cfg_param(struct usb2_com_softc *, struct termios *); 96static void uark_cfg_get_status(struct usb2_com_softc *, uint8_t *, --- 16 unchanged lines hidden (view full) --- 113 [UARK_BULK_DT_RD] = { 114 .type = UE_BULK, 115 .endpoint = UE_ADDR_ANY, 116 .direction = UE_DIR_IN, 117 .mh.bufsize = UARK_BUF_SIZE, 118 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 119 .mh.callback = &uark_bulk_read_callback, 120 }, |
128 129 [UARK_BULK_CS_WR] = { 130 .type = UE_CONTROL, 131 .endpoint = 0x00, /* Control pipe */ 132 .direction = UE_DIR_ANY, 133 .mh.bufsize = sizeof(struct usb2_device_request), 134 .mh.flags = {}, 135 .mh.callback = &uark_bulk_write_clear_stall_callback, 136 .mh.timeout = 1000, /* 1 second */ 137 .mh.interval = 50, /* 50ms */ 138 }, 139 140 [UARK_BULK_CS_RD] = { 141 .type = UE_CONTROL, 142 .endpoint = 0x00, /* Control pipe */ 143 .direction = UE_DIR_ANY, 144 .mh.bufsize = sizeof(struct usb2_device_request), 145 .mh.flags = {}, 146 .mh.callback = &uark_bulk_read_clear_stall_callback, 147 .mh.timeout = 1000, /* 1 second */ 148 .mh.interval = 50, /* 50ms */ 149 }, | |
150}; 151 152static const struct usb2_com_callback uark_callback = { 153 .usb2_com_cfg_get_status = &uark_cfg_get_status, 154 .usb2_com_cfg_set_break = &uark_cfg_set_break, 155 .usb2_com_cfg_param = &uark_cfg_param, 156 .usb2_com_pre_param = &uark_pre_param, 157 .usb2_com_start_read = &uark_start_read, --- 61 unchanged lines hidden (view full) --- 219 uark_xfer_config, UARK_N_TRANSFER, sc, &Giant); 220 221 if (error) { 222 device_printf(dev, "allocating control USB " 223 "transfers failed!\n"); 224 goto detach; 225 } 226 /* clear stall at first run */ | 121}; 122 123static const struct usb2_com_callback uark_callback = { 124 .usb2_com_cfg_get_status = &uark_cfg_get_status, 125 .usb2_com_cfg_set_break = &uark_cfg_set_break, 126 .usb2_com_cfg_param = &uark_cfg_param, 127 .usb2_com_pre_param = &uark_pre_param, 128 .usb2_com_start_read = &uark_start_read, --- 61 unchanged lines hidden (view full) --- 190 uark_xfer_config, UARK_N_TRANSFER, sc, &Giant); 191 192 if (error) { 193 device_printf(dev, "allocating control USB " 194 "transfers failed!\n"); 195 goto detach; 196 } 197 /* clear stall at first run */ |
227 sc->sc_flags |= (UARK_FLAG_BULK_WRITE_STALL | 228 UARK_FLAG_BULK_READ_STALL); | 198 usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_WR]); 199 usb2_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_RD]); |
229 230 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 231 &uark_callback, &Giant); 232 if (error) { 233 DPRINTF("usb2_com_attach failed\n"); 234 goto detach; 235 } 236 return (0); /* success */ --- 19 unchanged lines hidden (view full) --- 256uark_bulk_write_callback(struct usb2_xfer *xfer) 257{ 258 struct uark_softc *sc = xfer->priv_sc; 259 uint32_t actlen; 260 261 switch (USB_GET_STATE(xfer)) { 262 case USB_ST_SETUP: 263 case USB_ST_TRANSFERRED: | 200 201 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 202 &uark_callback, &Giant); 203 if (error) { 204 DPRINTF("usb2_com_attach failed\n"); 205 goto detach; 206 } 207 return (0); /* success */ --- 19 unchanged lines hidden (view full) --- 227uark_bulk_write_callback(struct usb2_xfer *xfer) 228{ 229 struct uark_softc *sc = xfer->priv_sc; 230 uint32_t actlen; 231 232 switch (USB_GET_STATE(xfer)) { 233 case USB_ST_SETUP: 234 case USB_ST_TRANSFERRED: |
264 if (sc->sc_flags & UARK_FLAG_BULK_WRITE_STALL) { 265 usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_WR]); 266 return; 267 } | 235tr_setup: |
268 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0, 269 UARK_BUF_SIZE, &actlen)) { 270 xfer->frlengths[0] = actlen; 271 usb2_start_hardware(xfer); 272 } 273 return; 274 275 default: /* Error */ 276 if (xfer->error != USB_ERR_CANCELLED) { | 236 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0, 237 UARK_BUF_SIZE, &actlen)) { 238 xfer->frlengths[0] = actlen; 239 usb2_start_hardware(xfer); 240 } 241 return; 242 243 default: /* Error */ 244 if (xfer->error != USB_ERR_CANCELLED) { |
277 sc->sc_flags |= UARK_FLAG_BULK_WRITE_STALL; 278 usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_WR]); | 245 /* try to clear stall first */ 246 xfer->flags.stall_pipe = 1; 247 goto tr_setup; |
279 } 280 return; 281 282 } 283} 284 285static void | 248 } 249 return; 250 251 } 252} 253 254static void |
286uark_bulk_write_clear_stall_callback(struct usb2_xfer *xfer) 287{ 288 struct uark_softc *sc = xfer->priv_sc; 289 struct usb2_xfer *xfer_other = sc->sc_xfer[UARK_BULK_DT_WR]; 290 291 if (usb2_clear_stall_callback(xfer, xfer_other)) { 292 DPRINTF("stall cleared\n"); 293 sc->sc_flags &= ~UARK_FLAG_BULK_WRITE_STALL; 294 usb2_transfer_start(xfer_other); 295 } 296} 297 298static void | |
299uark_bulk_read_callback(struct usb2_xfer *xfer) 300{ 301 struct uark_softc *sc = xfer->priv_sc; 302 303 switch (USB_GET_STATE(xfer)) { 304 case USB_ST_TRANSFERRED: 305 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, 306 xfer->actlen); 307 308 case USB_ST_SETUP: | 255uark_bulk_read_callback(struct usb2_xfer *xfer) 256{ 257 struct uark_softc *sc = xfer->priv_sc; 258 259 switch (USB_GET_STATE(xfer)) { 260 case USB_ST_TRANSFERRED: 261 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, 262 xfer->actlen); 263 264 case USB_ST_SETUP: |
309 if (sc->sc_flags & UARK_FLAG_BULK_READ_STALL) { 310 usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_RD]); 311 } else { 312 xfer->frlengths[0] = xfer->max_data_length; 313 usb2_start_hardware(xfer); 314 } | 265tr_setup: 266 xfer->frlengths[0] = xfer->max_data_length; 267 usb2_start_hardware(xfer); |
315 return; 316 317 default: /* Error */ 318 if (xfer->error != USB_ERR_CANCELLED) { | 268 return; 269 270 default: /* Error */ 271 if (xfer->error != USB_ERR_CANCELLED) { |
319 sc->sc_flags |= UARK_FLAG_BULK_READ_STALL; 320 usb2_transfer_start(sc->sc_xfer[UARK_BULK_CS_RD]); | 272 /* try to clear stall first */ 273 xfer->flags.stall_pipe = 1; 274 goto tr_setup; |
321 } 322 return; | 275 } 276 return; |
323 | |
324 } 325} 326 327static void | 277 } 278} 279 280static void |
328uark_bulk_read_clear_stall_callback(struct usb2_xfer *xfer) 329{ 330 struct uark_softc *sc = xfer->priv_sc; 331 struct usb2_xfer *xfer_other = sc->sc_xfer[UARK_BULK_DT_RD]; 332 333 if (usb2_clear_stall_callback(xfer, xfer_other)) { 334 DPRINTF("stall cleared\n"); 335 sc->sc_flags &= ~UARK_FLAG_BULK_READ_STALL; 336 usb2_transfer_start(xfer_other); 337 } 338} 339 340static void | |
341uark_start_read(struct usb2_com_softc *ucom) 342{ 343 struct uark_softc *sc = ucom->sc_parent; 344 345 usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_RD]); 346} 347 348static void 349uark_stop_read(struct usb2_com_softc *ucom) 350{ 351 struct uark_softc *sc = ucom->sc_parent; 352 | 281uark_start_read(struct usb2_com_softc *ucom) 282{ 283 struct uark_softc *sc = ucom->sc_parent; 284 285 usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_RD]); 286} 287 288static void 289uark_stop_read(struct usb2_com_softc *ucom) 290{ 291 struct uark_softc *sc = ucom->sc_parent; 292 |
353 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_CS_RD]); | |
354 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_RD]); 355} 356 357static void 358uark_start_write(struct usb2_com_softc *ucom) 359{ 360 struct uark_softc *sc = ucom->sc_parent; 361 362 usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_WR]); 363} 364 365static void 366uark_stop_write(struct usb2_com_softc *ucom) 367{ 368 struct uark_softc *sc = ucom->sc_parent; 369 | 293 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_RD]); 294} 295 296static void 297uark_start_write(struct usb2_com_softc *ucom) 298{ 299 struct uark_softc *sc = ucom->sc_parent; 300 301 usb2_transfer_start(sc->sc_xfer[UARK_BULK_DT_WR]); 302} 303 304static void 305uark_stop_write(struct usb2_com_softc *ucom) 306{ 307 struct uark_softc *sc = ucom->sc_parent; 308 |
370 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_CS_WR]); | |
371 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_WR]); 372} 373 374static int 375uark_pre_param(struct usb2_com_softc *ucom, struct termios *t) 376{ 377 if ((t->c_ospeed < 300) || (t->c_ospeed > 115200)) 378 return (EINVAL); --- 70 unchanged lines hidden (view full) --- 449} 450 451static void 452uark_cfg_write(struct uark_softc *sc, uint16_t index, uint16_t value) 453{ 454 struct usb2_device_request req; 455 usb2_error_t err; 456 | 309 usb2_transfer_stop(sc->sc_xfer[UARK_BULK_DT_WR]); 310} 311 312static int 313uark_pre_param(struct usb2_com_softc *ucom, struct termios *t) 314{ 315 if ((t->c_ospeed < 300) || (t->c_ospeed > 115200)) 316 return (EINVAL); --- 70 unchanged lines hidden (view full) --- 387} 388 389static void 390uark_cfg_write(struct uark_softc *sc, uint16_t index, uint16_t value) 391{ 392 struct usb2_device_request req; 393 usb2_error_t err; 394 |
457 if (usb2_com_cfg_is_gone(&sc->sc_ucom)) { 458 return; 459 } | |
460 req.bmRequestType = UARK_WRITE; 461 req.bRequest = UARK_REQUEST; 462 USETW(req.wValue, value); 463 USETW(req.wIndex, index); 464 USETW(req.wLength, 0); 465 | 395 req.bmRequestType = UARK_WRITE; 396 req.bRequest = UARK_REQUEST; 397 USETW(req.wValue, value); 398 USETW(req.wIndex, index); 399 USETW(req.wLength, 0); 400 |
466 err = usb2_do_request_flags 467 (sc->sc_udev, &Giant, &req, NULL, 0, NULL, 1000); 468 | 401 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 402 &req, NULL, 0, 1000); |
469 if (err) { 470 DPRINTFN(0, "device request failed, err=%s " 471 "(ignored)\n", usb2_errstr(err)); 472 } 473} | 403 if (err) { 404 DPRINTFN(0, "device request failed, err=%s " 405 "(ignored)\n", usb2_errstr(err)); 406 } 407} |