usb_serial.c (186885) | usb_serial.c (187176) |
---|---|
1/* $NetBSD: ucom.c,v 1.40 2001/11/13 06:24:54 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 2001-2003, 2005, 2008 5 * Shunsuke Akiyama <akiyama@jp.FreeBSD.org>. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 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#include <sys/cdefs.h> | 1/* $NetBSD: ucom.c,v 1.40 2001/11/13 06:24:54 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 2001-2003, 2005, 2008 5 * Shunsuke Akiyama <akiyama@jp.FreeBSD.org>. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 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#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/usb2_serial.c 186885 2009-01-08 05:10:03Z takawata $"); | 31__FBSDID("$FreeBSD: head/sys/dev/usb2/serial/usb2_serial.c 187176 2009-01-13 19:03:47Z thompsa $"); |
32 33/*- 34 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. 35 * All rights reserved. 36 * 37 * This code is derived from software contributed to The NetBSD Foundation 38 * by Lennart Augustsson (lennart@augustsson.net) at 39 * Carlstedt Research & Technology. --- 33 unchanged lines hidden (view full) --- 73 */ 74 75#include <dev/usb2/include/usb2_standard.h> 76#include <dev/usb2/include/usb2_mfunc.h> 77#include <dev/usb2/include/usb2_error.h> 78#include <dev/usb2/include/usb2_cdc.h> 79 80#define USB_DEBUG_VAR usb2_com_debug | 32 33/*- 34 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. 35 * All rights reserved. 36 * 37 * This code is derived from software contributed to The NetBSD Foundation 38 * by Lennart Augustsson (lennart@augustsson.net) at 39 * Carlstedt Research & Technology. --- 33 unchanged lines hidden (view full) --- 73 */ 74 75#include <dev/usb2/include/usb2_standard.h> 76#include <dev/usb2/include/usb2_mfunc.h> 77#include <dev/usb2/include/usb2_error.h> 78#include <dev/usb2/include/usb2_cdc.h> 79 80#define USB_DEBUG_VAR usb2_com_debug |
81#define usb2_config_td_cc usb2_com_config_copy 82#define usb2_config_td_softc usb2_com_softc | |
83 84#include <dev/usb2/core/usb2_core.h> 85#include <dev/usb2/core/usb2_debug.h> 86#include <dev/usb2/core/usb2_process.h> | 81 82#include <dev/usb2/core/usb2_core.h> 83#include <dev/usb2/core/usb2_debug.h> 84#include <dev/usb2/core/usb2_process.h> |
87#include <dev/usb2/core/usb2_config_td.h> | |
88#include <dev/usb2/core/usb2_request.h> 89#include <dev/usb2/core/usb2_busdma.h> 90#include <dev/usb2/core/usb2_util.h> 91 92#include <dev/usb2/serial/usb2_serial.h> 93 94#if USB_DEBUG 95static int usb2_com_debug = 0; 96 97SYSCTL_NODE(_hw_usb2, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom"); 98SYSCTL_INT(_hw_usb2_ucom, OID_AUTO, debug, CTLFLAG_RW, 99 &usb2_com_debug, 0, "ucom debug level"); 100#endif 101 | 85#include <dev/usb2/core/usb2_request.h> 86#include <dev/usb2/core/usb2_busdma.h> 87#include <dev/usb2/core/usb2_util.h> 88 89#include <dev/usb2/serial/usb2_serial.h> 90 91#if USB_DEBUG 92static int usb2_com_debug = 0; 93 94SYSCTL_NODE(_hw_usb2, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom"); 95SYSCTL_INT(_hw_usb2_ucom, OID_AUTO, debug, CTLFLAG_RW, 96 &usb2_com_debug, 0, "ucom debug level"); 97#endif 98 |
102struct usb2_com_config_copy { 103 struct usb2_com_softc *cc_softc; 104 uint8_t cc_flag0; 105 uint8_t cc_flag1; 106 uint8_t cc_flag2; 107 uint8_t cc_flag3; 108}; | 99static usb2_proc_callback_t usb2_com_cfg_start_transfers; 100static usb2_proc_callback_t usb2_com_cfg_open; 101static usb2_proc_callback_t usb2_com_cfg_close; 102static usb2_proc_callback_t usb2_com_cfg_break_on; 103static usb2_proc_callback_t usb2_com_cfg_break_off; 104static usb2_proc_callback_t usb2_com_cfg_dtr_on; 105static usb2_proc_callback_t usb2_com_cfg_dtr_off; 106static usb2_proc_callback_t usb2_com_cfg_rts_on; 107static usb2_proc_callback_t usb2_com_cfg_rts_off; 108static usb2_proc_callback_t usb2_com_cfg_status_change; 109static usb2_proc_callback_t usb2_com_cfg_param; |
109 | 110 |
110static usb2_config_td_command_t usb2_com_config_copy; 111static usb2_config_td_command_t usb2_com_cfg_start_transfers; 112static usb2_config_td_command_t usb2_com_cfg_open; 113static usb2_config_td_command_t usb2_com_cfg_close; 114static usb2_config_td_command_t usb2_com_cfg_break; 115static usb2_config_td_command_t usb2_com_cfg_dtr; 116static usb2_config_td_command_t usb2_com_cfg_rts; 117static usb2_config_td_command_t usb2_com_cfg_status_change; 118static usb2_config_td_command_t usb2_com_cfg_param; 119 | |
120static uint8_t usb2_com_units_alloc(uint32_t, uint32_t *); 121static void usb2_com_units_free(uint32_t, uint32_t); 122static int usb2_com_attach_sub(struct usb2_com_softc *); 123static void usb2_com_detach_sub(struct usb2_com_softc *); | 111static uint8_t usb2_com_units_alloc(uint32_t, uint32_t *); 112static void usb2_com_units_free(uint32_t, uint32_t); 113static int usb2_com_attach_sub(struct usb2_com_softc *); 114static void usb2_com_detach_sub(struct usb2_com_softc *); |
124static void usb2_com_queue_command(struct usb2_com_softc *, 125 usb2_config_td_command_t *, int); | 115static void usb2_com_queue_command(struct usb2_com_softc *sc, 116 uint8_t cmd); 117static void usb2_com_wait_command(struct usb2_com_softc *sc, 118 uint8_t cmd); |
126static void usb2_com_shutdown(struct usb2_com_softc *); 127static void usb2_com_start_transfers(struct usb2_com_softc *); 128static void usb2_com_break(struct usb2_com_softc *, uint8_t); 129static void usb2_com_dtr(struct usb2_com_softc *, uint8_t); 130static void usb2_com_rts(struct usb2_com_softc *, uint8_t); 131 132static tsw_open_t usb2_com_open; 133static tsw_close_t usb2_com_close; --- 112 unchanged lines hidden (view full) --- 246 (sub_units == 0) || 247 (sub_units > UCOM_SUB_UNIT_MAX) || 248 (callback == NULL)) { 249 return (EINVAL); 250 } 251 if (usb2_com_units_alloc(sub_units, &root_unit)) { 252 return (ENOMEM); 253 } | 119static void usb2_com_shutdown(struct usb2_com_softc *); 120static void usb2_com_start_transfers(struct usb2_com_softc *); 121static void usb2_com_break(struct usb2_com_softc *, uint8_t); 122static void usb2_com_dtr(struct usb2_com_softc *, uint8_t); 123static void usb2_com_rts(struct usb2_com_softc *, uint8_t); 124 125static tsw_open_t usb2_com_open; 126static tsw_close_t usb2_com_close; --- 112 unchanged lines hidden (view full) --- 239 (sub_units == 0) || 240 (sub_units > UCOM_SUB_UNIT_MAX) || 241 (callback == NULL)) { 242 return (EINVAL); 243 } 244 if (usb2_com_units_alloc(sub_units, &root_unit)) { 245 return (ENOMEM); 246 } |
254 if (usb2_config_td_setup 255 (&ssc->sc_config_td, sc, p_mtx, NULL, 256 sizeof(struct usb2_com_config_copy), 24 * sub_units)) { | 247 if (usb2_proc_setup(&ssc->sc_config_td, p_mtx, USB_PRI_MED)) { |
257 usb2_com_units_free(root_unit, sub_units); 258 return (ENOMEM); 259 } 260 for (n = 0; n < sub_units; n++, sc++) { 261 sc->sc_unit = root_unit + n; 262 sc->sc_local_unit = n; 263 sc->sc_super = ssc; 264 sc->sc_parent_mtx = p_mtx; --- 15 unchanged lines hidden (view full) --- 280 * the structure pointed to by "ssc" and "sc" is zero. 281 */ 282void 283usb2_com_detach(struct usb2_com_super_softc *ssc, struct usb2_com_softc *sc, 284 uint32_t sub_units) 285{ 286 uint32_t n; 287 | 248 usb2_com_units_free(root_unit, sub_units); 249 return (ENOMEM); 250 } 251 for (n = 0; n < sub_units; n++, sc++) { 252 sc->sc_unit = root_unit + n; 253 sc->sc_local_unit = n; 254 sc->sc_super = ssc; 255 sc->sc_parent_mtx = p_mtx; --- 15 unchanged lines hidden (view full) --- 271 * the structure pointed to by "ssc" and "sc" is zero. 272 */ 273void 274usb2_com_detach(struct usb2_com_super_softc *ssc, struct usb2_com_softc *sc, 275 uint32_t sub_units) 276{ 277 uint32_t n; 278 |
288 usb2_config_td_drain(&ssc->sc_config_td); | 279 usb2_proc_drain(&ssc->sc_config_td); |
289 290 for (n = 0; n < sub_units; n++, sc++) { 291 if (sc->sc_flag & UCOM_FLAG_ATTACHED) { 292 293 usb2_com_detach_sub(sc); 294 295 usb2_com_units_free(sc->sc_unit, 1); 296 297 /* avoid duplicate detach: */ 298 sc->sc_flag &= ~UCOM_FLAG_ATTACHED; 299 } 300 } | 280 281 for (n = 0; n < sub_units; n++, sc++) { 282 if (sc->sc_flag & UCOM_FLAG_ATTACHED) { 283 284 usb2_com_detach_sub(sc); 285 286 usb2_com_units_free(sc->sc_unit, 1); 287 288 /* avoid duplicate detach: */ 289 sc->sc_flag &= ~UCOM_FLAG_ATTACHED; 290 } 291 } |
301 302 usb2_config_td_unsetup(&ssc->sc_config_td); | 292 usb2_proc_unsetup(&ssc->sc_config_td); |
303} 304 305static int 306usb2_com_attach_sub(struct usb2_com_softc *sc) 307{ 308 struct tty *tp; 309 int error = 0; | 293} 294 295static int 296usb2_com_attach_sub(struct usb2_com_softc *sc) 297{ 298 struct tty *tp; 299 int error = 0; |
300 uint8_t n; |
|
310 char buf[32]; /* temporary TTY device name buffer */ 311 312 tp = tty_alloc(&usb2_com_class, sc, sc->sc_parent_mtx); 313 if (tp == NULL) { 314 error = ENOMEM; 315 goto done; 316 } 317 DPRINTF("tp = %p, unit = %d\n", tp, sc->sc_unit); --- 13 unchanged lines hidden (view full) --- 331 } 332 tty_makedev(tp, NULL, "%s", buf); 333 334 sc->sc_tty = tp; 335 336 DPRINTF("ttycreate: %s\n", buf); 337 usb2_cv_init(&sc->sc_cv, "usb2_com"); 338 | 301 char buf[32]; /* temporary TTY device name buffer */ 302 303 tp = tty_alloc(&usb2_com_class, sc, sc->sc_parent_mtx); 304 if (tp == NULL) { 305 error = ENOMEM; 306 goto done; 307 } 308 DPRINTF("tp = %p, unit = %d\n", tp, sc->sc_unit); --- 13 unchanged lines hidden (view full) --- 322 } 323 tty_makedev(tp, NULL, "%s", buf); 324 325 sc->sc_tty = tp; 326 327 DPRINTF("ttycreate: %s\n", buf); 328 usb2_cv_init(&sc->sc_cv, "usb2_com"); 329 |
330 /* 331 * Set all function callback pointers for deferred COM 332 * operations: 333 */ 334 for (n = 0; n != 2; n++) { 335 sc->sc_cmds[(2*USB_COM_CFG_START_TRANSFERS) + n].hdr.pm_callback = 336 &usb2_com_cfg_start_transfers; 337 sc->sc_cmds[(2*USB_COM_CFG_OPEN) + n].hdr.pm_callback = 338 &usb2_com_cfg_open; 339 sc->sc_cmds[(2*USB_COM_CFG_CLOSE) + n].hdr.pm_callback = 340 &usb2_com_cfg_close; 341 sc->sc_cmds[(2*USB_COM_CFG_BREAK_ON) + n].hdr.pm_callback = 342 &usb2_com_cfg_break_on; 343 sc->sc_cmds[(2*USB_COM_CFG_BREAK_OFF) + n].hdr.pm_callback = 344 &usb2_com_cfg_break_off; 345 sc->sc_cmds[(2*USB_COM_CFG_DTR_ON) + n].hdr.pm_callback = 346 &usb2_com_cfg_dtr_on; 347 sc->sc_cmds[(2*USB_COM_CFG_DTR_OFF) + n].hdr.pm_callback = 348 &usb2_com_cfg_dtr_off; 349 sc->sc_cmds[(2*USB_COM_CFG_RTS_ON) + n].hdr.pm_callback = 350 &usb2_com_cfg_rts_on; 351 sc->sc_cmds[(2*USB_COM_CFG_RTS_OFF) + n].hdr.pm_callback = 352 &usb2_com_cfg_rts_off; 353 sc->sc_cmds[(2*USB_COM_CFG_STATUS_CHANGE) + n].hdr.pm_callback = 354 &usb2_com_cfg_status_change; 355 sc->sc_cmds[(2*USB_COM_CFG_PARAM) + n].hdr.pm_callback = 356 &usb2_com_cfg_param; 357 } 358 359 /* initialise all callback pointer arguments */ 360 for (n = 0; n != (2*USB_COM_CFG_MAX); n++) { 361 sc->sc_cmds[n].cc_softc = sc; 362 } |
|
339done: 340 return (error); 341} 342 343static void 344usb2_com_detach_sub(struct usb2_com_softc *sc) 345{ 346 struct tty *tp = sc->sc_tty; --- 27 unchanged lines hidden (view full) --- 374 if (sc->sc_callback->usb2_com_stop_write) { 375 (sc->sc_callback->usb2_com_stop_write) (sc); 376 } 377 mtx_unlock(sc->sc_parent_mtx); 378 } 379 usb2_cv_destroy(&sc->sc_cv); 380} 381 | 363done: 364 return (error); 365} 366 367static void 368usb2_com_detach_sub(struct usb2_com_softc *sc) 369{ 370 struct tty *tp = sc->sc_tty; --- 27 unchanged lines hidden (view full) --- 398 if (sc->sc_callback->usb2_com_stop_write) { 399 (sc->sc_callback->usb2_com_stop_write) (sc); 400 } 401 mtx_unlock(sc->sc_parent_mtx); 402 } 403 usb2_cv_destroy(&sc->sc_cv); 404} 405 |
406/* 407 * The following function queues a command for deferred execution. 408 * The following function must be called locked. 409 */ |
|
382static void | 410static void |
383usb2_com_config_copy(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 384 uint16_t refcount) | 411usb2_com_queue_command(struct usb2_com_softc *sc, uint8_t cmd) |
385{ | 412{ |
386 cc->cc_softc = sc + (refcount % UCOM_SUB_UNIT_MAX); 387 cc->cc_flag0 = (refcount / (1 * UCOM_SUB_UNIT_MAX)) % 2; 388 cc->cc_flag1 = (refcount / (2 * UCOM_SUB_UNIT_MAX)) % 2; 389 cc->cc_flag2 = (refcount / (4 * UCOM_SUB_UNIT_MAX)) % 2; 390 cc->cc_flag3 = (refcount / (8 * UCOM_SUB_UNIT_MAX)) % 2; | 413 struct usb2_com_super_softc *ssc = sc->sc_super; 414 415 if (usb2_proc_is_gone(&ssc->sc_config_td)) { 416 DPRINTF("proc is gone\n"); 417 return; /* nothing to do */ 418 } 419 420 if (usb2_proc_msignal(&ssc->sc_config_td, 421 &sc->sc_cmds[2*cmd], &sc->sc_cmds[(2*cmd)+1])) { 422 /* ignore */ 423 } |
391} 392 | 424} 425 |
426/* 427 * The following function waits until a command has been executed. 428 * The following function must be called locked. 429 */ |
|
393static void | 430static void |
394usb2_com_queue_command(struct usb2_com_softc *sc, usb2_config_td_command_t *cmd, int flag) | 431usb2_com_wait_command(struct usb2_com_softc *sc, uint8_t cmd) |
395{ 396 struct usb2_com_super_softc *ssc = sc->sc_super; 397 | 432{ 433 struct usb2_com_super_softc *ssc = sc->sc_super; 434 |
398 usb2_config_td_queue_command 399 (&ssc->sc_config_td, &usb2_com_config_copy, 400 cmd, (cmd == &usb2_com_cfg_status_change) ? 1 : 0, 401 ((sc->sc_local_unit % UCOM_SUB_UNIT_MAX) + 402 (flag ? UCOM_SUB_UNIT_MAX : 0))); | 435 if (usb2_proc_is_gone(&ssc->sc_config_td)) { 436 DPRINTF("proc is gone\n"); 437 return; /* nothing to do */ 438 } 439 usb2_proc_mwait(&ssc->sc_config_td, 440 &sc->sc_cmds[2*cmd], &sc->sc_cmds[(2*cmd)+1]); |
403} 404 405static void 406usb2_com_shutdown(struct usb2_com_softc *sc) 407{ 408 struct tty *tp = sc->sc_tty; 409 410 mtx_assert(sc->sc_parent_mtx, MA_OWNED); --- 4 unchanged lines hidden (view full) --- 415 * Hang up if necessary: 416 */ 417 if (tp->t_termios.c_cflag & HUPCL) { 418 usb2_com_modem(tp, 0, SER_DTR); 419 } 420} 421 422/* | 441} 442 443static void 444usb2_com_shutdown(struct usb2_com_softc *sc) 445{ 446 struct tty *tp = sc->sc_tty; 447 448 mtx_assert(sc->sc_parent_mtx, MA_OWNED); --- 4 unchanged lines hidden (view full) --- 453 * Hang up if necessary: 454 */ 455 if (tp->t_termios.c_cflag & HUPCL) { 456 usb2_com_modem(tp, 0, SER_DTR); 457 } 458} 459 460/* |
461 * This function will sleep "timeout" system ticks. 462 * |
|
423 * Return values: 424 * 0: normal delay 425 * else: config thread is gone 426 */ 427uint8_t 428usb2_com_cfg_sleep(struct usb2_com_softc *sc, uint32_t timeout) 429{ 430 struct usb2_com_super_softc *ssc = sc->sc_super; | 463 * Return values: 464 * 0: normal delay 465 * else: config thread is gone 466 */ 467uint8_t 468usb2_com_cfg_sleep(struct usb2_com_softc *sc, uint32_t timeout) 469{ 470 struct usb2_com_super_softc *ssc = sc->sc_super; |
471 uint8_t is_gone; |
|
431 | 472 |
432 return (usb2_config_td_sleep(&ssc->sc_config_td, timeout)); | 473 is_gone = usb2_proc_is_gone(&ssc->sc_config_td); 474 if (is_gone) 475 goto done; /* we are detaching */ 476 if (timeout == 0) 477 timeout = 1; /* one tick is the least timeout */ 478 479 mtx_unlock(sc->sc_parent_mtx); 480 481 if (pause("UCOMWAIT", timeout)) { 482 /* ignore */ 483 } 484 485 mtx_lock(sc->sc_parent_mtx); 486 487 /* refresh gone status */ 488 is_gone = usb2_proc_is_gone(&ssc->sc_config_td); 489done: 490 return (is_gone); |
433} 434 435/* 436 * Return values: 437 * 0: normal 438 * else: config thread is gone 439 */ 440uint8_t 441usb2_com_cfg_is_gone(struct usb2_com_softc *sc) 442{ 443 struct usb2_com_super_softc *ssc = sc->sc_super; 444 | 491} 492 493/* 494 * Return values: 495 * 0: normal 496 * else: config thread is gone 497 */ 498uint8_t 499usb2_com_cfg_is_gone(struct usb2_com_softc *sc) 500{ 501 struct usb2_com_super_softc *ssc = sc->sc_super; 502 |
445 return (usb2_config_td_is_gone(&ssc->sc_config_td)); | 503 return (usb2_proc_is_gone(&ssc->sc_config_td)); |
446} 447 448static void | 504} 505 506static void |
449usb2_com_cfg_start_transfers(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 450 uint16_t refcount) | 507usb2_com_cfg_start_transfers(struct usb2_proc_msg *_cc) |
451{ | 508{ |
509 struct usb2_com_command_msg *cc = (void *)_cc; 510 struct usb2_com_softc *sc; 511 |
|
452 sc = cc->cc_softc; 453 454 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 455 return; 456 } 457 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 458 /* TTY device closed */ 459 return; --- 20 unchanged lines hidden (view full) --- 480 481 if (sc->sc_callback->usb2_com_start_read) { 482 (sc->sc_callback->usb2_com_start_read) (sc); 483 } 484 if (sc->sc_callback->usb2_com_start_write) { 485 (sc->sc_callback->usb2_com_start_write) (sc); 486 } 487 if (!(sc->sc_flag & UCOM_FLAG_GP_DATA)) { | 512 sc = cc->cc_softc; 513 514 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 515 return; 516 } 517 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 518 /* TTY device closed */ 519 return; --- 20 unchanged lines hidden (view full) --- 540 541 if (sc->sc_callback->usb2_com_start_read) { 542 (sc->sc_callback->usb2_com_start_read) (sc); 543 } 544 if (sc->sc_callback->usb2_com_start_write) { 545 (sc->sc_callback->usb2_com_start_write) (sc); 546 } 547 if (!(sc->sc_flag & UCOM_FLAG_GP_DATA)) { |
488 usb2_com_queue_command(sc, &usb2_com_cfg_start_transfers, 0); | 548 usb2_com_queue_command(sc, USB_COM_CFG_START_TRANSFERS); |
489 } 490} 491 492static void | 549 } 550} 551 552static void |
493usb2_com_cfg_open(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 494 uint16_t refcount) | 553usb2_com_cfg_open(struct usb2_proc_msg *_cc) |
495{ | 554{ |
555 struct usb2_com_command_msg *cc = (void *)_cc; 556 struct usb2_com_softc *sc; 557 |
|
496 sc = cc->cc_softc; 497 498 DPRINTF("\n"); 499 500 if (sc->sc_flag & UCOM_FLAG_LL_READY) { 501 502 /* already opened */ 503 --- 41 unchanged lines hidden (view full) --- 545 546 /* Disable transfers */ 547 sc->sc_flag &= ~UCOM_FLAG_GP_DATA; 548 549 sc->sc_lsr = 0; 550 sc->sc_msr = 0; 551 sc->sc_mcr = 0; 552 | 558 sc = cc->cc_softc; 559 560 DPRINTF("\n"); 561 562 if (sc->sc_flag & UCOM_FLAG_LL_READY) { 563 564 /* already opened */ 565 --- 41 unchanged lines hidden (view full) --- 607 608 /* Disable transfers */ 609 sc->sc_flag &= ~UCOM_FLAG_GP_DATA; 610 611 sc->sc_lsr = 0; 612 sc->sc_msr = 0; 613 sc->sc_mcr = 0; 614 |
553 usb2_com_queue_command(sc, &usb2_com_cfg_open, 0); | 615 usb2_com_queue_command(sc, USB_COM_CFG_OPEN); |
554 555 usb2_com_start_transfers(sc); 556 557 usb2_com_modem(tp, SER_DTR | SER_RTS, 0); 558 559 usb2_com_break(sc, 0); 560 561 usb2_com_status_change(sc); 562 563 return (0); 564} 565 566static void | 616 617 usb2_com_start_transfers(sc); 618 619 usb2_com_modem(tp, SER_DTR | SER_RTS, 0); 620 621 usb2_com_break(sc, 0); 622 623 usb2_com_status_change(sc); 624 625 return (0); 626} 627 628static void |
567usb2_com_cfg_close(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 568 uint16_t refcount) | 629usb2_com_cfg_close(struct usb2_proc_msg *_cc) |
569{ | 630{ |
631 struct usb2_com_command_msg *cc = (void *)_cc; 632 struct usb2_com_softc *sc; 633 |
|
570 sc = cc->cc_softc; 571 572 DPRINTF("\n"); 573 574 if (sc->sc_flag & UCOM_FLAG_LL_READY) { 575 576 sc->sc_flag &= ~(UCOM_FLAG_LL_READY | 577 UCOM_FLAG_GP_DATA); --- 5 unchanged lines hidden (view full) --- 583 /* already closed */ 584 } 585} 586 587static void 588usb2_com_close(struct tty *tp) 589{ 590 struct usb2_com_softc *sc = tty_softc(tp); | 634 sc = cc->cc_softc; 635 636 DPRINTF("\n"); 637 638 if (sc->sc_flag & UCOM_FLAG_LL_READY) { 639 640 sc->sc_flag &= ~(UCOM_FLAG_LL_READY | 641 UCOM_FLAG_GP_DATA); --- 5 unchanged lines hidden (view full) --- 647 /* already closed */ 648 } 649} 650 651static void 652usb2_com_close(struct tty *tp) 653{ 654 struct usb2_com_softc *sc = tty_softc(tp); |
591 struct usb2_com_super_softc *ssc = sc->sc_super; | |
592 593 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 594 595 DPRINTF("tp=%p\n", tp); 596 597 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 598 DPRINTF("tp=%p already closed\n", tp); 599 return; 600 } 601 usb2_com_shutdown(sc); 602 | 655 656 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 657 658 DPRINTF("tp=%p\n", tp); 659 660 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 661 DPRINTF("tp=%p already closed\n", tp); 662 return; 663 } 664 usb2_com_shutdown(sc); 665 |
603 usb2_com_queue_command(sc, &usb2_com_cfg_close, 0); 604 usb2_config_td_sync(&ssc->sc_config_td); | 666 /* Queue and wait for close command to complete */ 667 usb2_com_queue_command(sc, USB_COM_CFG_CLOSE); 668 usb2_com_wait_command(sc, USB_COM_CFG_CLOSE); |
605 606 sc->sc_flag &= ~(UCOM_FLAG_HL_READY | 607 UCOM_FLAG_WR_START | 608 UCOM_FLAG_RTS_IFLOW); 609 610 if (sc->sc_callback->usb2_com_stop_read) { 611 (sc->sc_callback->usb2_com_stop_read) (sc); 612 } --- 86 unchanged lines hidden (view full) --- 699 700 onoff = (sc->sc_mcr & SER_RTS) ? 1 : 0; 701 usb2_com_rts(sc, onoff); 702 703 return (0); 704} 705 706static void | 669 670 sc->sc_flag &= ~(UCOM_FLAG_HL_READY | 671 UCOM_FLAG_WR_START | 672 UCOM_FLAG_RTS_IFLOW); 673 674 if (sc->sc_callback->usb2_com_stop_read) { 675 (sc->sc_callback->usb2_com_stop_read) (sc); 676 } --- 86 unchanged lines hidden (view full) --- 763 764 onoff = (sc->sc_mcr & SER_RTS) ? 1 : 0; 765 usb2_com_rts(sc, onoff); 766 767 return (0); 768} 769 770static void |
707usb2_com_cfg_break(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 708 uint16_t refcount) | 771usb2_com_cfg_break(struct usb2_com_command_msg *cc, uint8_t onoff) |
709{ | 772{ |
773 struct usb2_com_softc *sc; 774 |
|
710 sc = cc->cc_softc; 711 712 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 713 return; 714 } | 775 sc = cc->cc_softc; 776 777 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 778 return; 779 } |
715 DPRINTF("onoff=%d\n", cc->cc_flag0); | 780 DPRINTF("onoff=%d\n", onoff); |
716 717 if (sc->sc_callback->usb2_com_cfg_set_break) { | 781 782 if (sc->sc_callback->usb2_com_cfg_set_break) { |
718 (sc->sc_callback->usb2_com_cfg_set_break) (sc, cc->cc_flag0); | 783 (sc->sc_callback->usb2_com_cfg_set_break) (sc, onoff); |
719 } 720} 721 722static void | 784 } 785} 786 787static void |
788usb2_com_cfg_break_on(struct usb2_proc_msg *_cc) 789{ 790 usb2_com_cfg_break((void *)_cc, 1); 791} 792 793static void 794usb2_com_cfg_break_off(struct usb2_proc_msg *_cc) 795{ 796 usb2_com_cfg_break((void *)_cc, 0); 797} 798 799static void |
|
723usb2_com_break(struct usb2_com_softc *sc, uint8_t onoff) 724{ 725 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 726 727 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 728 return; 729 } 730 DPRINTF("onoff = %d\n", onoff); 731 | 800usb2_com_break(struct usb2_com_softc *sc, uint8_t onoff) 801{ 802 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 803 804 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 805 return; 806 } 807 DPRINTF("onoff = %d\n", onoff); 808 |
732 usb2_com_queue_command(sc, &usb2_com_cfg_break, onoff); | 809 usb2_com_queue_command(sc, onoff ? 810 USB_COM_CFG_BREAK_ON : USB_COM_CFG_BREAK_OFF); |
733} 734 735static void | 811} 812 813static void |
736usb2_com_cfg_dtr(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 737 uint16_t refcount) | 814usb2_com_cfg_dtr(struct usb2_com_command_msg *cc, uint8_t onoff) |
738{ | 815{ |
816 struct usb2_com_softc *sc; 817 |
|
739 sc = cc->cc_softc; 740 741 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 742 return; 743 } | 818 sc = cc->cc_softc; 819 820 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 821 return; 822 } |
744 DPRINTF("onoff=%d\n", cc->cc_flag0); | 823 DPRINTF("onoff=%d\n", onoff); |
745 746 if (sc->sc_callback->usb2_com_cfg_set_dtr) { | 824 825 if (sc->sc_callback->usb2_com_cfg_set_dtr) { |
747 (sc->sc_callback->usb2_com_cfg_set_dtr) (sc, cc->cc_flag0); | 826 (sc->sc_callback->usb2_com_cfg_set_dtr) (sc, onoff); |
748 } 749} 750 751static void | 827 } 828} 829 830static void |
831usb2_com_cfg_dtr_on(struct usb2_proc_msg *_cc) 832{ 833 usb2_com_cfg_dtr((void *)_cc, 1); 834} 835 836static void 837usb2_com_cfg_dtr_off(struct usb2_proc_msg *_cc) 838{ 839 usb2_com_cfg_dtr((void *)_cc, 0); 840} 841 842static void |
|
752usb2_com_dtr(struct usb2_com_softc *sc, uint8_t onoff) 753{ 754 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 755 756 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 757 return; 758 } 759 DPRINTF("onoff = %d\n", onoff); 760 | 843usb2_com_dtr(struct usb2_com_softc *sc, uint8_t onoff) 844{ 845 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 846 847 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 848 return; 849 } 850 DPRINTF("onoff = %d\n", onoff); 851 |
761 usb2_com_queue_command(sc, &usb2_com_cfg_dtr, onoff); | 852 usb2_com_queue_command(sc, onoff ? 853 USB_COM_CFG_DTR_ON : USB_COM_CFG_DTR_OFF); |
762} 763 764static void | 854} 855 856static void |
765usb2_com_cfg_rts(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 766 uint16_t refcount) | 857usb2_com_cfg_rts(struct usb2_com_command_msg *cc, uint8_t onoff) |
767{ | 858{ |
859 struct usb2_com_softc *sc; 860 |
|
768 sc = cc->cc_softc; 769 | 861 sc = cc->cc_softc; 862 |
770 DPRINTF("onoff=%d\n", cc->cc_flag0); | 863 DPRINTF("onoff=%d\n", onoff); |
771 772 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 773 return; 774 } 775 if (sc->sc_callback->usb2_com_cfg_set_rts) { | 864 865 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 866 return; 867 } 868 if (sc->sc_callback->usb2_com_cfg_set_rts) { |
776 (sc->sc_callback->usb2_com_cfg_set_rts) (sc, cc->cc_flag0); | 869 (sc->sc_callback->usb2_com_cfg_set_rts) (sc, onoff); |
777 } 778} 779 780static void | 870 } 871} 872 873static void |
874usb2_com_cfg_rts_on(struct usb2_proc_msg *_cc) 875{ 876 usb2_com_cfg_rts((void *)_cc, 1); 877} 878 879static void 880usb2_com_cfg_rts_off(struct usb2_proc_msg *_cc) 881{ 882 usb2_com_cfg_rts((void *)_cc, 0); 883} 884 885static void |
|
781usb2_com_rts(struct usb2_com_softc *sc, uint8_t onoff) 782{ 783 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 784 785 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 786 return; 787 } 788 DPRINTF("onoff = %d\n", onoff); 789 | 886usb2_com_rts(struct usb2_com_softc *sc, uint8_t onoff) 887{ 888 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 889 890 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 891 return; 892 } 893 DPRINTF("onoff = %d\n", onoff); 894 |
790 usb2_com_queue_command(sc, &usb2_com_cfg_rts, onoff); | 895 usb2_com_queue_command(sc, onoff ? 896 USB_COM_CFG_RTS_ON : USB_COM_CFG_RTS_OFF); |
791} 792 793static void | 897} 898 899static void |
794usb2_com_cfg_status_change(struct usb2_com_softc *sc, 795 struct usb2_com_config_copy *cc, uint16_t refcount) | 900usb2_com_cfg_status_change(struct usb2_proc_msg *_cc) |
796{ | 901{ |
902 struct usb2_com_command_msg *cc = (void *)_cc; 903 struct usb2_com_softc *sc; |
|
797 struct tty *tp; 798 799 uint8_t new_msr; 800 uint8_t new_lsr; 801 uint8_t onoff; 802 803 sc = cc->cc_softc; 804 tp = sc->sc_tty; --- 37 unchanged lines hidden (view full) --- 842{ 843 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 844 845 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 846 return; 847 } 848 DPRINTF("\n"); 849 | 904 struct tty *tp; 905 906 uint8_t new_msr; 907 uint8_t new_lsr; 908 uint8_t onoff; 909 910 sc = cc->cc_softc; 911 tp = sc->sc_tty; --- 37 unchanged lines hidden (view full) --- 949{ 950 mtx_assert(sc->sc_parent_mtx, MA_OWNED); 951 952 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) { 953 return; 954 } 955 DPRINTF("\n"); 956 |
850 usb2_com_queue_command(sc, &usb2_com_cfg_status_change, 0); | 957 usb2_com_queue_command(sc, USB_COM_CFG_STATUS_CHANGE); |
851} 852 853static void | 958} 959 960static void |
854usb2_com_cfg_param(struct usb2_com_softc *sc, struct usb2_com_config_copy *cc, 855 uint16_t refcount) | 961usb2_com_cfg_param(struct usb2_proc_msg *_cc) |
856{ | 962{ |
963 struct usb2_com_command_msg *cc = (void *)_cc; 964 struct usb2_com_softc *sc; |
|
857 struct termios t_copy; 858 859 sc = cc->cc_softc; 860 861 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 862 return; 863 } 864 if (sc->sc_callback->usb2_com_cfg_param == NULL) { --- 54 unchanged lines hidden (view full) --- 919 } 920 /* Make a copy of the termios parameters */ 921 sc->sc_termios_copy = *t; 922 923 /* Disable transfers */ 924 sc->sc_flag &= ~UCOM_FLAG_GP_DATA; 925 926 /* Queue baud rate programming command first */ | 965 struct termios t_copy; 966 967 sc = cc->cc_softc; 968 969 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { 970 return; 971 } 972 if (sc->sc_callback->usb2_com_cfg_param == NULL) { --- 54 unchanged lines hidden (view full) --- 1027 } 1028 /* Make a copy of the termios parameters */ 1029 sc->sc_termios_copy = *t; 1030 1031 /* Disable transfers */ 1032 sc->sc_flag &= ~UCOM_FLAG_GP_DATA; 1033 1034 /* Queue baud rate programming command first */ |
927 usb2_com_queue_command(sc, &usb2_com_cfg_param, 0); | 1035 usb2_com_queue_command(sc, USB_COM_CFG_PARAM); |
928 929 /* Queue transfer enable command last */ 930 usb2_com_start_transfers(sc); 931 932 if (t->c_cflag & CRTS_IFLOW) { 933 sc->sc_flag |= UCOM_FLAG_RTS_IFLOW; 934 } else if (sc->sc_flag & UCOM_FLAG_RTS_IFLOW) { 935 sc->sc_flag &= ~UCOM_FLAG_RTS_IFLOW; --- 152 unchanged lines hidden --- | 1036 1037 /* Queue transfer enable command last */ 1038 usb2_com_start_transfers(sc); 1039 1040 if (t->c_cflag & CRTS_IFLOW) { 1041 sc->sc_flag |= UCOM_FLAG_RTS_IFLOW; 1042 } else if (sc->sc_flag & UCOM_FLAG_RTS_IFLOW) { 1043 sc->sc_flag &= ~UCOM_FLAG_RTS_IFLOW; --- 152 unchanged lines hidden --- |