1/* $NetBSD: umodem_common.c,v 1.21 2010/10/01 20:56:50 christos Exp $ */ 2 3/* 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Lennart Augustsson (lennart@augustsson.net) at 9 * Carlstedt Research & Technology. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33/* 34 * Comm Class spec: http://www.usb.org/developers/devclass_docs/usbccs10.pdf 35 * http://www.usb.org/developers/devclass_docs/usbcdc11.pdf 36 */ 37 38/* 39 * TODO: 40 * - Add error recovery in various places; the big problem is what 41 * to do in a callback if there is an error. 42 * - Implement a Call Device for modems without multiplexed commands. 43 * 44 */ 45 46#include <sys/cdefs.h> 47__KERNEL_RCSID(0, "$NetBSD: umodem_common.c,v 1.21 2010/10/01 20:56:50 christos Exp $"); 48 49#include <sys/param.h> 50#include <sys/systm.h> 51#include <sys/kernel.h> 52#include <sys/ioctl.h> 53#include <sys/conf.h> 54#include <sys/tty.h> 55#include <sys/file.h> 56#include <sys/select.h> 57#include <sys/proc.h> 58#include <sys/vnode.h> 59#include <sys/device.h> 60#include <sys/poll.h> 61 62#include <dev/usb/usb.h> 63#include <dev/usb/usbcdc.h> 64 65#include <dev/usb/usbdi.h> 66#include <dev/usb/usbdi_util.h> 67#include <dev/usb/usbdevs.h> 68#include <dev/usb/usb_quirks.h> 69 70#include <dev/usb/ucomvar.h> 71#include <dev/usb/umodemvar.h> 72 73#ifdef UMODEM_DEBUG 74#define DPRINTFN(n, x) if (umodemdebug > (n)) printf x 75int umodemdebug = 0; 76#else 77#define DPRINTFN(n, x) 78#endif 79#define DPRINTF(x) DPRINTFN(0, x) 80 81/* 82 * These are the maximum number of bytes transferred per frame. 83 * If some really high speed devices should use this driver they 84 * may need to be increased, but this is good enough for normal modems. 85 * 86 * Note: increased from 64/256, to better support EVDO wireless PPP. 87 * The sizes should not be increased further, or there 88 * will be problems with contiguous storage allocation. 89 */ 90#define UMODEMIBUFSIZE 4096 91#define UMODEMOBUFSIZE 4096 92 93Static usbd_status umodem_set_comm_feature(struct umodem_softc *sc, 94 int feature, int state); 95Static usbd_status umodem_set_line_coding(struct umodem_softc *sc, 96 usb_cdc_line_state_t *state); 97 98Static void umodem_dtr(struct umodem_softc *, int); 99Static void umodem_rts(struct umodem_softc *, int); 100Static void umodem_break(struct umodem_softc *, int); 101Static void umodem_set_line_state(struct umodem_softc *); 102Static void umodem_intr(usbd_xfer_handle, usbd_private_handle, usbd_status); 103 104int 105umodem_common_attach(device_t self, struct umodem_softc *sc, 106 struct usbif_attach_arg *uaa, struct ucom_attach_args *uca) 107{ 108 usbd_device_handle dev = uaa->device; 109 usb_interface_descriptor_t *id; 110 usb_endpoint_descriptor_t *ed; 111 char *devinfop; 112 usbd_status err; 113 int data_ifcno; 114 int i; 115 116 sc->sc_dev = self; 117 sc->sc_udev = dev; 118 sc->sc_ctl_iface = uaa->iface; 119 120 aprint_naive("\n"); 121 aprint_normal("\n"); 122 123 id = usbd_get_interface_descriptor(sc->sc_ctl_iface); 124 devinfop = usbd_devinfo_alloc(uaa->device, 0); 125 aprint_normal_dev(self, "%s, iclass %d/%d\n", 126 devinfop, id->bInterfaceClass, id->bInterfaceSubClass); 127 usbd_devinfo_free(devinfop); 128 129 sc->sc_ctl_iface_no = id->bInterfaceNumber; 130 131 /* Get the data interface no. */ 132 sc->sc_data_iface_no = data_ifcno = 133 umodem_get_caps(dev, &sc->sc_cm_cap, &sc->sc_acm_cap, id); 134 135 if (data_ifcno == -1) { 136 aprint_error_dev(self, "no pointer to data interface\n"); 137 goto bad; 138 } 139 140 aprint_normal_dev(self, 141 "data interface %d, has %sCM over data, has %sbreak\n", 142 data_ifcno, sc->sc_cm_cap & USB_CDC_CM_OVER_DATA ? "" : "no ", 143 sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK ? "" : "no "); 144 145 /* Get the data interface too. */ 146 for (i = 0; i < uaa->nifaces; i++) { 147 if (uaa->ifaces[i] != NULL) { 148 id = usbd_get_interface_descriptor(uaa->ifaces[i]); 149 if (id != NULL && id->bInterfaceNumber == data_ifcno) { 150 sc->sc_data_iface = uaa->ifaces[i]; 151 uaa->ifaces[i] = NULL; 152 } 153 } 154 } 155 if (sc->sc_data_iface == NULL) { 156 aprint_error_dev(self, "no data interface\n"); 157 goto bad; 158 } 159 160 /* 161 * Find the bulk endpoints. 162 * Iterate over all endpoints in the data interface and take note. 163 */ 164 uca->bulkin = uca->bulkout = -1; 165 166 id = usbd_get_interface_descriptor(sc->sc_data_iface); 167 for (i = 0; i < id->bNumEndpoints; i++) { 168 ed = usbd_interface2endpoint_descriptor(sc->sc_data_iface, i); 169 if (ed == NULL) { 170 aprint_error_dev(self, 171 "no endpoint descriptor for %d\n)", i); 172 goto bad; 173 } 174 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 175 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { 176 uca->bulkin = ed->bEndpointAddress; 177 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 178 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { 179 uca->bulkout = ed->bEndpointAddress; 180 } 181 } 182 183 if (uca->bulkin == -1) { 184 aprint_error_dev(self, "Could not find data bulk in\n"); 185 goto bad; 186 } 187 if (uca->bulkout == -1) { 188 aprint_error_dev(self, "Could not find data bulk out\n"); 189 goto bad; 190 } 191 192 if (usbd_get_quirks(sc->sc_udev)->uq_flags & UQ_ASSUME_CM_OVER_DATA) { 193 sc->sc_cm_over_data = 1; 194 } else { 195 if (sc->sc_cm_cap & USB_CDC_CM_OVER_DATA) { 196 if (sc->sc_acm_cap & USB_CDC_ACM_HAS_FEATURE) 197 err = umodem_set_comm_feature(sc, 198 UCDC_ABSTRACT_STATE, UCDC_DATA_MULTIPLEXED); 199 else 200 err = 0; 201 if (err) { 202 aprint_error_dev(self, 203 "could not set data multiplex mode\n"); 204 goto bad; 205 } 206 sc->sc_cm_over_data = 1; 207 } 208 } 209 210 /* 211 * The standard allows for notification messages (to indicate things 212 * like a modem hangup) to come in via an interrupt endpoint 213 * off of the control interface. Iterate over the endpoints on 214 * the control interface and see if there are any interrupt 215 * endpoints; if there are, then register it. 216 */ 217 218 sc->sc_ctl_notify = -1; 219 sc->sc_notify_pipe = NULL; 220 221 id = usbd_get_interface_descriptor(sc->sc_ctl_iface); 222 for (i = 0; i < id->bNumEndpoints; i++) { 223 ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i); 224 if (ed == NULL) 225 continue; 226 227 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 228 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { 229 aprint_error_dev(self, 230 "status change notification available\n"); 231 sc->sc_ctl_notify = ed->bEndpointAddress; 232 } 233 } 234 235 sc->sc_dtr = -1; 236 237 /* bulkin, bulkout set above */ 238 uca->ibufsize = UMODEMIBUFSIZE; 239 uca->obufsize = UMODEMOBUFSIZE; 240 uca->ibufsizepad = UMODEMIBUFSIZE; 241 uca->opkthdrlen = 0; 242 uca->device = sc->sc_udev; 243 uca->iface = sc->sc_data_iface; 244 uca->arg = sc; 245 246 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, 247 sc->sc_dev); 248 249 DPRINTF(("umodem_common_attach: sc=%p\n", sc)); 250 sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, uca, 251 ucomprint, ucomsubmatch); 252 253 return 0; 254 255 bad: 256 sc->sc_dying = 1; 257 return 1; 258} 259 260int 261umodem_open(void *addr, int portno) 262{ 263 struct umodem_softc *sc = addr; 264 int err; 265 266 DPRINTF(("umodem_open: sc=%p\n", sc)); 267 268 if (sc->sc_ctl_notify != -1 && sc->sc_notify_pipe == NULL) { 269 err = usbd_open_pipe_intr(sc->sc_ctl_iface, sc->sc_ctl_notify, 270 USBD_SHORT_XFER_OK, &sc->sc_notify_pipe, sc, 271 &sc->sc_notify_buf, sizeof(sc->sc_notify_buf), 272 umodem_intr, USBD_DEFAULT_INTERVAL); 273 274 if (err) { 275 DPRINTF(("Failed to establish notify pipe: %s\n", 276 usbd_errstr(err))); 277 return EIO; 278 } 279 } 280 281 return 0; 282} 283 284void 285umodem_close(void *addr, int portno) 286{ 287 struct umodem_softc *sc = addr; 288 int err; 289 290 DPRINTF(("umodem_close: sc=%p\n", sc)); 291 292 if (sc->sc_notify_pipe != NULL) { 293 err = usbd_abort_pipe(sc->sc_notify_pipe); 294 if (err) 295 printf("%s: abort notify pipe failed: %s\n", 296 device_xname(sc->sc_dev), usbd_errstr(err)); 297 err = usbd_close_pipe(sc->sc_notify_pipe); 298 if (err) 299 printf("%s: close notify pipe failed: %s\n", 300 device_xname(sc->sc_dev), usbd_errstr(err)); 301 sc->sc_notify_pipe = NULL; 302 } 303} 304 305Static void 306umodem_intr(usbd_xfer_handle xfer, usbd_private_handle priv, 307 usbd_status status) 308{ 309 struct umodem_softc *sc = priv; 310 u_char mstatus; 311 312 if (sc->sc_dying) 313 return; 314 315 if (status != USBD_NORMAL_COMPLETION) { 316 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) 317 return; 318 printf("%s: abnormal status: %s\n", device_xname(sc->sc_dev), 319 usbd_errstr(status)); 320 if (status == USBD_STALLED) 321 usbd_clear_endpoint_stall_async(sc->sc_notify_pipe); 322 return; 323 } 324 325 if (sc->sc_notify_buf.bmRequestType != UCDC_NOTIFICATION) { 326 DPRINTF(("%s: unknown message type (%02x) on notify pipe\n", 327 device_xname(sc->sc_dev), 328 sc->sc_notify_buf.bmRequestType)); 329 return; 330 } 331 332 switch (sc->sc_notify_buf.bNotification) { 333 case UCDC_N_SERIAL_STATE: 334 /* 335 * Set the serial state in ucom driver based on 336 * the bits from the notify message 337 */ 338 if (UGETW(sc->sc_notify_buf.wLength) != 2) { 339 printf("%s: Invalid notification length! (%d)\n", 340 device_xname(sc->sc_dev), 341 UGETW(sc->sc_notify_buf.wLength)); 342 break; 343 } 344 DPRINTF(("%s: notify bytes = %02x%02x\n", 345 device_xname(sc->sc_dev), 346 sc->sc_notify_buf.data[0], 347 sc->sc_notify_buf.data[1])); 348 /* Currently, lsr is always zero. */ 349 sc->sc_lsr = sc->sc_msr = 0; 350 mstatus = sc->sc_notify_buf.data[0]; 351 352 if (ISSET(mstatus, UCDC_N_SERIAL_RI)) 353 sc->sc_msr |= UMSR_RI; 354 if (ISSET(mstatus, UCDC_N_SERIAL_DSR)) 355 sc->sc_msr |= UMSR_DSR; 356 if (ISSET(mstatus, UCDC_N_SERIAL_DCD)) 357 sc->sc_msr |= UMSR_DCD; 358 ucom_status_change(device_private(sc->sc_subdev)); 359 break; 360 default: 361 DPRINTF(("%s: unknown notify message: %02x\n", 362 device_xname(sc->sc_dev), 363 sc->sc_notify_buf.bNotification)); 364 break; 365 } 366} 367 368int 369umodem_get_caps(usbd_device_handle dev, int *cm, int *acm, 370 usb_interface_descriptor_t *id) 371{ 372 const usb_cdc_cm_descriptor_t *cmd; 373 const usb_cdc_acm_descriptor_t *cad; 374 const usb_cdc_union_descriptor_t *cud; 375 u_int32_t uq_flags; 376 377 *cm = *acm = 0; 378 uq_flags = usbd_get_quirks(dev)->uq_flags; 379 380 if (uq_flags & UQ_NO_UNION_NRM) { 381 DPRINTF(("umodem_get_caps: NO_UNION_NRM quirk - returning 0\n")); 382 return 0; 383 } 384 385 if (uq_flags & UQ_LOST_CS_DESC) 386 id = NULL; 387 388 cmd = (const usb_cdc_cm_descriptor_t *)usb_find_desc_if(dev, 389 UDESC_CS_INTERFACE, 390 UDESCSUB_CDC_CM, id); 391 if (cmd == NULL) { 392 DPRINTF(("umodem_get_caps: no CM desc\n")); 393 } else { 394 *cm = cmd->bmCapabilities; 395 } 396 397 cad = (const usb_cdc_acm_descriptor_t *)usb_find_desc_if(dev, 398 UDESC_CS_INTERFACE, 399 UDESCSUB_CDC_ACM, 400 id); 401 if (cad == NULL) { 402 DPRINTF(("umodem_get_caps: no ACM desc\n")); 403 } else { 404 *acm = cad->bmCapabilities; 405 } 406 407 cud = (const usb_cdc_union_descriptor_t *)usb_find_desc_if(dev, 408 UDESC_CS_INTERFACE, 409 UDESCSUB_CDC_UNION, 410 id); 411 if (cud == NULL) { 412 DPRINTF(("umodem_get_caps: no UNION desc\n")); 413 } 414 415 return cmd ? cmd->bDataInterface : cud ? cud->bSlaveInterface[0] : -1; 416} 417 418void 419umodem_get_status(void *addr, int portno, u_char *lsr, u_char *msr) 420{ 421 struct umodem_softc *sc = addr; 422 423 DPRINTF(("umodem_get_status:\n")); 424 425 if (lsr != NULL) 426 *lsr = sc->sc_lsr; 427 if (msr != NULL) 428 *msr = sc->sc_msr; 429} 430 431int 432umodem_param(void *addr, int portno, struct termios *t) 433{ 434 struct umodem_softc *sc = addr; 435 usbd_status err; 436 usb_cdc_line_state_t ls; 437 438 DPRINTF(("umodem_param: sc=%p\n", sc)); 439 440 USETDW(ls.dwDTERate, t->c_ospeed); 441 if (ISSET(t->c_cflag, CSTOPB)) 442 ls.bCharFormat = UCDC_STOP_BIT_2; 443 else 444 ls.bCharFormat = UCDC_STOP_BIT_1; 445 if (ISSET(t->c_cflag, PARENB)) { 446 if (ISSET(t->c_cflag, PARODD)) 447 ls.bParityType = UCDC_PARITY_ODD; 448 else 449 ls.bParityType = UCDC_PARITY_EVEN; 450 } else 451 ls.bParityType = UCDC_PARITY_NONE; 452 switch (ISSET(t->c_cflag, CSIZE)) { 453 case CS5: 454 ls.bDataBits = 5; 455 break; 456 case CS6: 457 ls.bDataBits = 6; 458 break; 459 case CS7: 460 ls.bDataBits = 7; 461 break; 462 case CS8: 463 ls.bDataBits = 8; 464 break; 465 } 466 467 err = umodem_set_line_coding(sc, &ls); 468 if (err) { 469 DPRINTF(("umodem_param: err=%s\n", usbd_errstr(err))); 470 return (EPASSTHROUGH); 471 } 472 return (0); 473} 474 475int 476umodem_ioctl(void *addr, int portno, u_long cmd, void *data, 477 int flag, proc_t *p) 478{ 479 struct umodem_softc *sc = addr; 480 int error = 0; 481 482 if (sc->sc_dying) 483 return (EIO); 484 485 DPRINTF(("umodem_ioctl: cmd=0x%08lx\n", cmd)); 486 487 switch (cmd) { 488 case USB_GET_CM_OVER_DATA: 489 *(int *)data = sc->sc_cm_over_data; 490 break; 491 492 case USB_SET_CM_OVER_DATA: 493 if (*(int *)data != sc->sc_cm_over_data) { 494 /* XXX change it */ 495 } 496 break; 497 498 default: 499 DPRINTF(("umodem_ioctl: unknown\n")); 500 error = EPASSTHROUGH; 501 break; 502 } 503 504 return (error); 505} 506 507void 508umodem_dtr(struct umodem_softc *sc, int onoff) 509{ 510 DPRINTF(("umodem_dtr: onoff=%d\n", onoff)); 511 512 if (sc->sc_dtr == onoff) 513 return; 514 sc->sc_dtr = onoff; 515 516 umodem_set_line_state(sc); 517} 518 519void 520umodem_rts(struct umodem_softc *sc, int onoff) 521{ 522 DPRINTF(("umodem_rts: onoff=%d\n", onoff)); 523 524 if (sc->sc_rts == onoff) 525 return; 526 sc->sc_rts = onoff; 527 528 umodem_set_line_state(sc); 529} 530 531void 532umodem_set_line_state(struct umodem_softc *sc) 533{ 534 usb_device_request_t req; 535 int ls; 536 537 ls = (sc->sc_dtr ? UCDC_LINE_DTR : 0) | 538 (sc->sc_rts ? UCDC_LINE_RTS : 0); 539 req.bmRequestType = UT_WRITE_CLASS_INTERFACE; 540 req.bRequest = UCDC_SET_CONTROL_LINE_STATE; 541 USETW(req.wValue, ls); 542 USETW(req.wIndex, sc->sc_ctl_iface_no); 543 USETW(req.wLength, 0); 544 545 (void)usbd_do_request(sc->sc_udev, &req, 0); 546 547} 548 549void 550umodem_break(struct umodem_softc *sc, int onoff) 551{ 552 usb_device_request_t req; 553 554 DPRINTF(("umodem_break: onoff=%d\n", onoff)); 555 556 if (!(sc->sc_acm_cap & USB_CDC_ACM_HAS_BREAK)) 557 return; 558 559 req.bmRequestType = UT_WRITE_CLASS_INTERFACE; 560 req.bRequest = UCDC_SEND_BREAK; 561 USETW(req.wValue, onoff ? UCDC_BREAK_ON : UCDC_BREAK_OFF); 562 USETW(req.wIndex, sc->sc_ctl_iface_no); 563 USETW(req.wLength, 0); 564 565 (void)usbd_do_request(sc->sc_udev, &req, 0); 566} 567 568void 569umodem_set(void *addr, int portno, int reg, int onoff) 570{ 571 struct umodem_softc *sc = addr; 572 573 switch (reg) { 574 case UCOM_SET_DTR: 575 umodem_dtr(sc, onoff); 576 break; 577 case UCOM_SET_RTS: 578 umodem_rts(sc, onoff); 579 break; 580 case UCOM_SET_BREAK: 581 umodem_break(sc, onoff); 582 break; 583 default: 584 break; 585 } 586} 587 588usbd_status 589umodem_set_line_coding(struct umodem_softc *sc, usb_cdc_line_state_t *state) 590{ 591 usb_device_request_t req; 592 usbd_status err; 593 594 DPRINTF(("umodem_set_line_coding: rate=%d fmt=%d parity=%d bits=%d\n", 595 UGETDW(state->dwDTERate), state->bCharFormat, 596 state->bParityType, state->bDataBits)); 597 598 if (memcmp(state, &sc->sc_line_state, UCDC_LINE_STATE_LENGTH) == 0) { 599 DPRINTF(("umodem_set_line_coding: already set\n")); 600 return (USBD_NORMAL_COMPLETION); 601 } 602 603 req.bmRequestType = UT_WRITE_CLASS_INTERFACE; 604 req.bRequest = UCDC_SET_LINE_CODING; 605 USETW(req.wValue, 0); 606 USETW(req.wIndex, sc->sc_ctl_iface_no); 607 USETW(req.wLength, UCDC_LINE_STATE_LENGTH); 608 609 err = usbd_do_request(sc->sc_udev, &req, state); 610 if (err) { 611 DPRINTF(("umodem_set_line_coding: failed, err=%s\n", 612 usbd_errstr(err))); 613 return (err); 614 } 615 616 sc->sc_line_state = *state; 617 618 return (USBD_NORMAL_COMPLETION); 619} 620 621usbd_status 622umodem_set_comm_feature(struct umodem_softc *sc, int feature, int state) 623{ 624 usb_device_request_t req; 625 usbd_status err; 626 usb_cdc_abstract_state_t ast; 627 628 DPRINTF(("umodem_set_comm_feature: feature=%d state=%d\n", feature, 629 state)); 630 631 req.bmRequestType = UT_WRITE_CLASS_INTERFACE; 632 req.bRequest = UCDC_SET_COMM_FEATURE; 633 USETW(req.wValue, feature); 634 USETW(req.wIndex, sc->sc_ctl_iface_no); 635 USETW(req.wLength, UCDC_ABSTRACT_STATE_LENGTH); 636 USETW(ast.wState, state); 637 638 err = usbd_do_request(sc->sc_udev, &req, &ast); 639 if (err) { 640 DPRINTF(("umodem_set_comm_feature: feature=%d, err=%s\n", 641 feature, usbd_errstr(err))); 642 return (err); 643 } 644 645 return (USBD_NORMAL_COMPLETION); 646} 647 648int 649umodem_common_activate(struct umodem_softc *sc, enum devact act) 650{ 651 switch (act) { 652 case DVACT_DEACTIVATE: 653 sc->sc_dying = 1; 654 return 0; 655 default: 656 return EOPNOTSUPP; 657 } 658} 659 660void 661umodem_common_childdet(struct umodem_softc *sc, device_t child) 662{ 663 KASSERT(sc->sc_subdev == child); 664 sc->sc_subdev = NULL; 665} 666 667int 668umodem_common_detach(struct umodem_softc *sc, int flags) 669{ 670 int rv = 0; 671 672 DPRINTF(("umodem_common_detach: sc=%p flags=%d\n", sc, flags)); 673 674 sc->sc_dying = 1; 675 676 if (sc->sc_subdev != NULL) 677 rv = config_detach(sc->sc_subdev, flags); 678 679 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, 680 sc->sc_dev); 681 682 return (rv); 683} 684