diff options
Diffstat (limited to 'sys/dev/usb')
41 files changed, 422 insertions, 279 deletions
diff --git a/sys/dev/usb/FILES b/sys/dev/usb/FILES index 170b931889b..fbe2393b40e 100644 --- a/sys/dev/usb/FILES +++ b/sys/dev/usb/FILES @@ -8,11 +8,23 @@ devlist2h.awk script to generate usbdevs*.h files.usb config include file hid.c subroutines to parse and access HID data hid.h API for hid.c +if_aue.c USB Pegasus Ethernet driver +if_auereg.h and definitions for it +if_cue.c USB CATC Ethernet driver +if_cuereg.h and definitions for it +if_kue.c USB Kawasaki Ethernet driver +if_kuereg.h and definitions for it +if_upl.c USB Prolofic host-to-host driver +kue_fw.h Kawasaki Ethernet firmware ohci.c Host controller driver for OHCI ohcireg.h Hardware definitions for OHCI ohcivar.h API for ohci.c uaudio.c USB audio class driver uaudioreg.h and definitions for it +ucom.c TTY emulation for two bulk pipes +ucomvar.h TTY emulation interface +uftdi.c USB FTDI serial driver +uftdireg.h and definitions for it ugen.c generic driver that can handle access to any USB device uhci.c Host controller driver for UHCI uhcireg.h Hardware definitions for UHCI @@ -26,6 +38,8 @@ ulpt.c USB printer class driver umass.c USB mass storage driver (bulk only for now) umodem.c USB modem (CDC ACM) driver ums.c USB mouse driver +urio.c USB Diamond Rio500 driver +urio.h USB Diamond Rio500 defines usb.c usb (bus) device driver usb.h general USB defines usb_mem.c memory allocation for DMAable memory @@ -44,3 +58,4 @@ usbdi_util.c utilities built on top of usbdi.h usbdi_util.h API for usbdi_util.c usbdivar.h internal defines and structures for usbdi.c usbhid.h USB HID class definitions +uvisor.c USB Handsping Visor driver diff --git a/sys/dev/usb/TODO b/sys/dev/usb/TODO index 103ee72d726..fdd8eb79a8a 100644 --- a/sys/dev/usb/TODO +++ b/sys/dev/usb/TODO @@ -1,18 +1,39 @@ -Some things that need to be done in no particular order: --------------------------------------------------------- +Some things that need to be done: +--------------------------------- Before 1.5: ----------- -Reset toggle on SET_INTERFACE (USB 1.1) - Allow interrupt out endpoints. (USB 1.1) ------------ +Fix flow control in ucom (copy from com driver). + +Use some encapsulation in the upl driver to allow multiple protocols. + +Get the uezcom driver (with Doug Ambrisko's firmware) running. + + +Bug reports: +------------ + +Bernd Ernesti's problem: host controller halted with umodem -Make flow control work in ucom. +umass problem with Ricoh flash reader + +wskbd for X + +mel kravitz's problem, lockups with disk and printer + +Aaron's problem: Test aue with ohci. + +Y-E data floppy doesn't work. + + +General: +-------- Figure out why uvisor is so slow. +Try to get specs, and check if Linux driver is really right. Translate UFI commands? @@ -31,6 +52,7 @@ Some hubs change the number of available ports on this transition. :( Handle overcurrent conditions. Make it possible to open any device in a "generic" way, i.e., like ugen. +Perhaps usbdevfs? Rotate the QHs for bulk transport to get fairer scheduling. @@ -42,19 +64,13 @@ Do memory deallocation when HC driver is detached. uaudio problems: mixer names are awful, use some heuristics. implement selector units - implement input + debug input test with more devices Stylistic changes: use usb_ and usbd_ consistently rearrange the contents and names of some files (Nick) -Document device driver API. - -Document HC driver API. - -Handle CLEAR_ENDPOINT_STALL centrally. - Use splsoftusb() or a thread to deliver callbacks. Add threads to the Ethernet drivers. @@ -68,3 +84,17 @@ Rewrite HID driver to handle report IDs properly. Perhaps there should be a hiddev to which hid with different IDs can attach? Get rid of hcpriv. + +Keyspan serial driver + +Factor out comon code in network drivers. + + +Documentation: +-------------- + +Document device driver API. + +Document HC driver API. + +Update ugen(4) diff --git a/sys/dev/usb/files.usb b/sys/dev/usb/files.usb index 7ff0fc7b7ae..36429e5ee61 100644 --- a/sys/dev/usb/files.usb +++ b/sys/dev/usb/files.usb @@ -1,4 +1,4 @@ -# $OpenBSD: files.usb,v 1.11 2000/04/15 17:36:29 jakob Exp $ +# $OpenBSD: files.usb,v 1.12 2000/07/04 11:44:20 fgsch Exp $ # $NetBSD: files.usb,v 1.16 2000/02/14 20:29:54 augustss Exp $ # # Config file and device description for machine-independent USB code. @@ -66,6 +66,11 @@ device urio attach urio at uhub file dev/usb/urio.c urio needs-flag +# Handspring Visor +device uvisor: ucombus +attach uvisor at uhub +file dev/usb/uvisor.c uvisor + # Ethernet adapters # ADMtek AN986 Pegasus device aue: ether, ifnet, mii, ifmedia @@ -81,3 +86,14 @@ file dev/usb/if_cue.c cue device kue: ether, ifnet, ifmedia attach kue at uhub file dev/usb/if_kue.c kue + +# Prolific PL2302 host-host +#device upl: ifnet +#attach upl at uhub +#file dev/usb/if_upl.c upl + +# Serial drivers +# FTDI serial driver +#device uftdi: ucombus +#attach uftdi at uhub +#file dev/usb/uftdi.c uftdi diff --git a/sys/dev/usb/hid.c b/sys/dev/usb/hid.c index 603f3d49597..1907b6ca708 100644 --- a/sys/dev/usb/hid.c +++ b/sys/dev/usb/hid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hid.c,v 1.7 2000/04/14 22:50:24 aaron Exp $ */ +/* $OpenBSD: hid.c,v 1.8 2000/07/04 11:44:21 fgsch Exp $ */ /* $NetBSD: hid.c,v 1.14 2000/04/06 22:58:32 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/hid.c,v 1.11 1999/11/17 22:33:39 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -80,6 +80,7 @@ Static void hid_clear_local(c) struct hid_item *c; { + c->usage = 0; c->usage_minimum = 0; c->usage_maximum = 0; @@ -112,6 +113,7 @@ void hid_end_parse(s) struct hid_data *s; { + while (s->cur.next != NULL) { struct hid_item *hi = s->cur.next->next; free(s->cur.next, M_TEMP); diff --git a/sys/dev/usb/hid.h b/sys/dev/usb/hid.h index bf12b0406b7..022a8f795bd 100644 --- a/sys/dev/usb/hid.h +++ b/sys/dev/usb/hid.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hid.h,v 1.2 2000/03/28 19:37:46 aaron Exp $ */ +/* $OpenBSD: hid.h,v 1.3 2000/07/04 11:44:21 fgsch Exp $ */ /* $NetBSD: hid.h,v 1.4 1999/11/18 23:32:26 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/hid.h,v 1.7 1999/11/17 22:33:40 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/if_aue.c b/sys/dev/usb/if_aue.c index 2f4d4801ded..eadfa9c6296 100644 --- a/sys/dev/usb/if_aue.c +++ b/sys/dev/usb/if_aue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_aue.c,v 1.5 2000/04/23 17:33:47 maja Exp $ */ +/* $OpenBSD: if_aue.c,v 1.6 2000/07/04 11:44:21 fgsch Exp $ */ /* $NetBSD: if_aue.c,v 1.38 2000/04/04 20:16:19 augustss Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000 @@ -179,21 +179,30 @@ int auedebug = 0; /* * Various supported device vendors/products. */ +struct aue_type { + u_int16_t aue_vid; + u_int16_t aue_did; + char aue_linksys; +}; + Static struct aue_type aue_devs[] = { - { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100 }, - { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX }, - { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX }, - { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS }, - { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX }, - { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA }, - { USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB }, - { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX }, - { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX }, - { 0, 0 } + { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, 0 }, + { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX, 0 }, + { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX, 1 }, + { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1, 1 }, + { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA, 1 }, + { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, 0 }, + { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX, 1 }, + { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA, 0 }, + { USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB, 0 }, + { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX, 0 }, + { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX, 0 }, + { 0, 0, 0 } }; USB_DECLARE_DRIVER(aue); +Static struct aue_type *aue_lookup __P((u_int16_t, u_int16_t)); Static int aue_tx_list_init __P((struct aue_softc *)); Static int aue_rx_list_init __P((struct aue_softc *)); Static int aue_newbuf __P((struct aue_softc *, struct aue_chain *, @@ -584,11 +593,8 @@ aue_miibus_statchg(dev) * This turns on the 'dual link LED' bin in the auxmode * register of the Broadcom PHY. */ - if ((sc->aue_vendor == USB_VENDOR_LINKSYS && - sc->aue_product == USB_PRODUCT_LINKSYS_USB100TX) || - (sc->aue_vendor == USB_VENDOR_DLINK && - sc->aue_product == USB_PRODUCT_DLINK_DSB650TX)) { - u_int16_t auxmode; + if (sc->aue_linksys) { + u_int16_t auxmode; auxmode = aue_miibus_readreg(dev, 0, 0x1b); aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04); } @@ -706,10 +712,7 @@ aue_reset(sc) AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1); /* Grrr. LinkSys has to be different from everyone else. */ - if ((sc->aue_vendor == USB_VENDOR_LINKSYS && - sc->aue_product == USB_PRODUCT_LINKSYS_USB100TX) || - (sc->aue_vendor == USB_VENDOR_DLINK && - sc->aue_product == USB_PRODUCT_DLINK_DSB650TX)) { + if (sc->aue_linksys) { aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0 | AUE_GPIO_SEL1); aue_csr_write_1(sc, AUE_GPIO0, @@ -720,22 +723,30 @@ aue_reset(sc) delay(10000); /* XXX */ } +Static struct aue_type * +aue_lookup(vendor, product) + u_int16_t vendor, product; +{ + struct aue_type *t; + + for (t = aue_devs; t->aue_vid != 0; t++) + if (vendor == t->aue_vid && product == t->aue_did) + return (t); + return (NULL); +} + /* * Probe for a Pegasus chip. */ USB_MATCH(aue) { USB_MATCH_START(aue, uaa); - struct aue_type *t; if (uaa->iface != NULL) return (UMATCH_NONE); - for (t = aue_devs; t->aue_vid != 0; t++) - if (uaa->vendor == t->aue_vid && uaa->product == t->aue_did) - return (UMATCH_VENDOR_PRODUCT); - - return (UMATCH_NONE); + return (aue_lookup(uaa->vendor, uaa->product) != NULL ? + UMATCH_VENDOR_PRODUCT : UMATCH_NONE); } /* @@ -781,6 +792,8 @@ USB_ATTACH(aue) USB_ATTACH_ERROR_RETURN; } + sc->aue_linksys = aue_lookup(uaa->vendor, uaa->product)->aue_linksys; + sc->aue_udev = dev; sc->aue_iface = iface; sc->aue_product = uaa->product; @@ -1601,7 +1614,7 @@ aue_openpipes(sc) USBDEVNAME(sc->aue_dev), usbd_errstr(err)); return (EIO); } - usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX], + err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX], USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]); if (err) { printf("%s: open tx pipe failed: %s\n", diff --git a/sys/dev/usb/if_auereg.h b/sys/dev/usb/if_auereg.h index 444866ab213..6b3e5bc1110 100644 --- a/sys/dev/usb/if_auereg.h +++ b/sys/dev/usb/if_auereg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_auereg.h,v 1.2 2000/04/14 22:50:25 aaron Exp $ */ +/* $OpenBSD: if_auereg.h,v 1.3 2000/07/04 11:44:21 fgsch Exp $ */ /* $NetBSD: if_auereg.h,v 1.12 2000/04/04 20:16:19 augustss Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -198,11 +198,6 @@ struct aue_rxpkt { /*************** The rest belongs in if_auevar.h *************/ -struct aue_type { - u_int16_t aue_vid; - u_int16_t aue_did; -}; - #define AUE_TX_LIST_CNT 1 #define AUE_RX_LIST_CNT 1 @@ -264,6 +259,8 @@ struct aue_softc { int aue_if_flags; struct aue_cdata aue_cdata; + char aue_linksys; + char aue_dying; char aue_attached; u_int aue_rx_errs; diff --git a/sys/dev/usb/if_cue.c b/sys/dev/usb/if_cue.c index 221e0ee716f..1da4fabf14a 100644 --- a/sys/dev/usb/if_cue.c +++ b/sys/dev/usb/if_cue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_cue.c,v 1.4 2000/04/23 17:33:47 maja Exp $ */ +/* $OpenBSD: if_cue.c,v 1.5 2000/07/04 11:44:21 fgsch Exp $ */ /* $NetBSD: if_cue.c,v 1.21 2000/04/02 21:25:41 augustss Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000 @@ -162,6 +162,7 @@ int cuedebug = 0; Static struct cue_type cue_devs[] = { { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE }, { USB_VENDOR_CATC, USB_PRODUCT_CATC_NETMATE2 }, + { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTLINK }, /* Belkin F5U111 adapter covered by NETMATE entry */ { 0, 0 } }; diff --git a/sys/dev/usb/if_cuereg.h b/sys/dev/usb/if_cuereg.h index aa4715add9a..f6977df6484 100644 --- a/sys/dev/usb/if_cuereg.h +++ b/sys/dev/usb/if_cuereg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_cuereg.h,v 1.2 2000/04/14 22:50:25 aaron Exp $ */ +/* $OpenBSD: if_cuereg.h,v 1.3 2000/07/04 11:44:21 fgsch Exp $ */ /* $NetBSD: if_cuereg.h,v 1.11 2000/04/08 20:54:38 augustss Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2000 @@ -42,11 +42,11 @@ /* * Vendor specific control commands. */ -#define CUE_CMD_RESET 0xF4 +#define CUE_CMD_READSRAM 0xF1 #define CUE_CMD_GET_MACADDR 0xF2 +#define CUE_CMD_RESET 0xF4 #define CUE_CMD_WRITEREG 0xFA #define CUE_CMD_READREG 0xFB -#define CUE_CMD_READSRAM 0xF1 #define CUE_CMD_WRITESRAM 0xFC /* diff --git a/sys/dev/usb/ohci.c b/sys/dev/usb/ohci.c index 549f3fc6bf1..b1df74e3b4d 100644 --- a/sys/dev/usb/ohci.c +++ b/sys/dev/usb/ohci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ohci.c,v 1.12 2000/06/29 13:48:31 aaron Exp $ */ +/* $OpenBSD: ohci.c,v 1.13 2000/07/04 11:44:21 fgsch Exp $ */ /* $NetBSD: ohci.c,v 1.85 2000/04/01 09:27:35 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/ohci.c,v 1.22 1999/11/17 22:33:40 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -1439,6 +1439,7 @@ ohci_rhsc(sc, xfer) m = min(sc->sc_noport, xfer->length * 8 - 1); memset(p, 0, xfer->length); for (i = 1; i <= m; i++) { + /* Pick out CHANGE bits from the status reg. */ if (OREAD4(sc, OHCI_RH_PORT_STATUS(i)) >> 16) p[i/8] |= 1 << (i%8); } @@ -1885,6 +1886,9 @@ ohci_open(pipe) DPRINTFN(1, ("ohci_open: pipe=%p, addr=%d, endpt=%d (%d)\n", pipe, addr, ed->bEndpointAddress, sc->sc_addr)); + std = NULL; + sed = NULL; + if (addr == sc->sc_addr) { switch (ed->bEndpointAddress) { case USB_CONTROL_ENDPOINT: @@ -1963,9 +1967,11 @@ ohci_open(pipe) return (USBD_NORMAL_COMPLETION); bad: - ohci_free_std(sc, std); + if (std != NULL) + ohci_free_std(sc, std); bad1: - ohci_free_sed(sc, sed); + if (sed != NULL) + ohci_free_sed(sc, sed); bad0: return (USBD_NOMEM); @@ -2357,6 +2363,7 @@ ohci_root_ctrl_start(xfer) OWRITE4(sc, port, UPS_OVERCURRENT_INDICATOR); break; case UHF_PORT_POWER: + /* Yes, writing to the LOW_SPEED bit clears power. */ OWRITE4(sc, port, UPS_LOW_SPEED); break; case UHF_C_PORT_CONNECTION: diff --git a/sys/dev/usb/ohcireg.h b/sys/dev/usb/ohcireg.h index ad74fd3b6fa..0616ddfc6e7 100644 --- a/sys/dev/usb/ohcireg.h +++ b/sys/dev/usb/ohcireg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ohcireg.h,v 1.7 2000/04/01 19:11:36 aaron Exp $ */ +/* $OpenBSD: ohcireg.h,v 1.8 2000/07/04 11:44:22 fgsch Exp $ */ /* $NetBSD: ohcireg.h,v 1.17 2000/04/01 09:27:35 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/ohcireg.h,v 1.8 1999/11/17 22:33:40 n_hibma Exp $ */ @@ -8,7 +8,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/ohcivar.h b/sys/dev/usb/ohcivar.h index 0a0f09d4b0e..95ef02f6981 100644 --- a/sys/dev/usb/ohcivar.h +++ b/sys/dev/usb/ohcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ohcivar.h,v 1.9 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: ohcivar.h,v 1.10 2000/07/04 11:44:22 fgsch Exp $ */ /* $NetBSD: ohcivar.h,v 1.21 2000/03/29 01:46:27 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/ohcivar.h,v 1.13 1999/11/17 22:33:41 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -88,6 +88,7 @@ typedef struct ohci_softc { struct usbd_bus sc_bus; /* base device */ bus_space_tag_t iot; bus_space_handle_t ioh; + bus_size_t sc_size; usb_dma_t sc_hccadma; struct ohci_hcca *sc_hcca; diff --git a/sys/dev/usb/uaudio.c b/sys/dev/usb/uaudio.c index c802b22f301..31bdd8ee56b 100644 --- a/sys/dev/usb/uaudio.c +++ b/sys/dev/usb/uaudio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uaudio.c,v 1.5 2000/05/24 13:44:18 ho Exp $ */ +/* $OpenBSD: uaudio.c,v 1.6 2000/07/04 11:44:22 fgsch Exp $ */ /* $NetBSD: uaudio.c,v 1.23 2000/03/29 18:24:53 augustss Exp $ */ /* @@ -6,7 +6,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/uaudioreg.h b/sys/dev/usb/uaudioreg.h index d1ee2ef1cd4..45ce629a443 100644 --- a/sys/dev/usb/uaudioreg.h +++ b/sys/dev/usb/uaudioreg.h @@ -1,12 +1,13 @@ -/* $OpenBSD: uaudioreg.h,v 1.3 2000/03/28 19:37:49 aaron Exp $ */ +/* $OpenBSD: uaudioreg.h,v 1.4 2000/07/04 11:44:22 fgsch Exp $ */ /* $NetBSD: uaudioreg.h,v 1.4 2000/01/16 09:32:56 augustss Exp $ */ /* * Copyright (c) 1999 The NetBSD Foundation, Inc. * All rights reserved. * - * Author: Lennart Augustsson <augustss@carlstedt.se> - * Carlstedt Research & Technology + * This code is derived from software contributed to The NetBSD Foundation + * by Lennart Augustsson (lennart@augustsson.net) at + * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -71,7 +72,7 @@ typedef struct { */ uByte bRefresh; uByte bSynchAddress; -} usb_endpoint_descriptor_audio_t; +} UPACKED usb_endpoint_descriptor_audio_t; struct usb_audio_control_descriptor { uByte bLength; @@ -81,7 +82,7 @@ struct usb_audio_control_descriptor { uWord wTotalLength; uByte bInCollection; uByte baInterfaceNr[1]; -}; +} UPACKED; struct usb_audio_streaming_interface_descriptor { uByte bLength; @@ -90,7 +91,7 @@ struct usb_audio_streaming_interface_descriptor { uByte bTerminalLink; uByte bDelay; uWord wFormatTag; -}; +} UPACKED; struct usb_audio_streaming_endpoint_descriptor { uByte bLength; @@ -99,7 +100,7 @@ struct usb_audio_streaming_endpoint_descriptor { uByte bmAttributes; uByte bLockDelayUnits; uWord wLockDelay; -}; +} UPACKED; struct usb_audio_streaming_type1_descriptor { uByte bLength; @@ -115,13 +116,13 @@ struct usb_audio_streaming_type1_descriptor { #define UA_GETSAMP(p, n) ((p)->tSamFreq[(n)*3+0] | ((p)->tSamFreq[(n)*3+1] << 8) | ((p)->tSamFreq[(n)*3+2] << 16)) #define UA_SAMP_LO(p) UA_GETSAMP(p, 0) #define UA_SAMP_HI(p) UA_GETSAMP(p, 1) -}; +} UPACKED; struct usb_audio_cluster { uByte bNrChannels; uWord wChannelConfig; uByte iChannelNames; -}; +} UPACKED; /* UDESCSUB_AC_INPUT */ struct usb_audio_input_terminal { @@ -135,7 +136,7 @@ struct usb_audio_input_terminal { uWord wChannelConfig; uByte iChannelNames; uByte iTerminal; -}; +} UPACKED; /* UDESCSUB_AC_OUTPUT */ struct usb_audio_output_terminal { @@ -147,7 +148,7 @@ struct usb_audio_output_terminal { uByte bAssocTerminal; uByte bSourceId; uByte iTerminal; -}; +} UPACKED; /* UDESCSUB_AC_MIXER */ struct usb_audio_mixer_unit { @@ -158,14 +159,14 @@ struct usb_audio_mixer_unit { uByte bNrInPins; uByte baSourceId[255]; /* [bNrInPins] */ /* struct usb_audio_mixer_unit_1 */ -}; +} UPACKED; struct usb_audio_mixer_unit_1 { uByte bNrChannels; uWord wChannelConfig; uByte iChannelNames; uByte bmControls[255]; /* [bNrChannels] */ /*uByte iMixer;*/ -}; +} UPACKED; /* UDESCSUB_AC_SELECTOR */ struct usb_audio_selector_unit { @@ -176,7 +177,7 @@ struct usb_audio_selector_unit { uByte bNrInPins; uByte baSourceId[255]; /* [bNrInPins] */ /* uByte iSelector; */ -}; +} UPACKED; /* UDESCSUB_AC_FEATURE */ struct usb_audio_feature_unit { @@ -188,7 +189,7 @@ struct usb_audio_feature_unit { uByte bControlSize; uByte bmaControls[255]; /* size for more than enough */ /* uByte iFeature; */ -}; +} UPACKED; /* UDESCSUB_AC_PROCESSING */ struct usb_audio_processing_unit { @@ -200,7 +201,7 @@ struct usb_audio_processing_unit { uByte bNrInPins; uByte baSourceId[255]; /* [bNrInPins] */ /* struct usb_audio_processing_unit_1 */ -}; +} UPACKED; struct usb_audio_processing_unit_1{ uByte bNrChannels; uWord wChannelConfig; @@ -208,13 +209,13 @@ struct usb_audio_processing_unit_1{ uByte bControlSize; uByte bmControls[255]; /* [bControlSize] */ #define UA_PROC_ENABLE_MASK 1 -}; +} UPACKED; struct usb_audio_processing_unit_updown { uByte iProcessing; uByte bNrModes; uWord waModes[255]; /* [bNrModes] */ -}; +} UPACKED; /* UDESCSUB_AC_EXTENSION */ struct usb_audio_extension_unit { @@ -226,7 +227,7 @@ struct usb_audio_extension_unit { uByte bNrInPins; uByte baSourceId[255]; /* [bNrInPins] */ /* struct usb_audio_extension_unit_1 */ -}; +} UPACKED; struct usb_audio_extension_unit_1 { uByte bNrChannels; uWord wChannelConfig; @@ -236,7 +237,7 @@ struct usb_audio_extension_unit_1 { #define UA_EXT_ENABLE_MASK 1 #define UA_EXT_ENABLE 1 /*uByte iExtension;*/ -}; +} UPACKED; #define UAT_STREAM 0x0101 diff --git a/sys/dev/usb/ucom.c b/sys/dev/usb/ucom.c index df1b17926d4..5d79eddcef9 100644 --- a/sys/dev/usb/ucom.c +++ b/sys/dev/usb/ucom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ucom.c,v 1.3 2000/04/14 22:50:25 aaron Exp $ */ +/* $OpenBSD: ucom.c,v 1.4 2000/07/04 11:44:22 fgsch Exp $ */ /* $NetBSD: ucom.c,v 1.22 2000/04/14 14:21:55 augustss Exp $ */ /* @@ -6,7 +6,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/ucomvar.h b/sys/dev/usb/ucomvar.h index 20b7f162690..bd34d061f4b 100644 --- a/sys/dev/usb/ucomvar.h +++ b/sys/dev/usb/ucomvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ucomvar.h,v 1.3 2000/04/14 22:50:25 aaron Exp $ */ +/* $OpenBSD: ucomvar.h,v 1.4 2000/07/04 11:44:22 fgsch Exp $ */ /* $NetBSD: ucomvar.h,v 1.5 2000/04/14 14:21:55 augustss Exp $ */ /* @@ -6,7 +6,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/ugen.c b/sys/dev/usb/ugen.c index 4b391760f82..6f3221bfe73 100644 --- a/sys/dev/usb/ugen.c +++ b/sys/dev/usb/ugen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ugen.c,v 1.10 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: ugen.c,v 1.11 2000/07/04 11:44:23 fgsch Exp $ */ /* $NetBSD: ugen.c,v 1.37 2000/03/27 12:33:55 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/ugen.c,v 1.26 1999/11/17 22:33:41 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -758,6 +758,7 @@ ugen_set_interface(sc, ifaceidx, altno) err = usbd_endpoint_count(iface, &nendpt); if (err) return (err); + /* XXX should only do this after setting new altno has succeeded */ for (endptno = 0; endptno < nendpt; endptno++) { ed = usbd_interface2endpoint_descriptor(iface,endptno); endpt = ed->bEndpointAddress; @@ -835,7 +836,7 @@ ugen_get_alt_index(sc, ifaceidx) err = usbd_device2interface_handle(sc->sc_udev, ifaceidx, &iface); if (err) - return (-1); + return (-1); return (usbd_get_interface_altindex(iface)); } diff --git a/sys/dev/usb/uhci.c b/sys/dev/usb/uhci.c index e28400a8034..aae1039dcee 100644 --- a/sys/dev/usb/uhci.c +++ b/sys/dev/usb/uhci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhci.c,v 1.12 2000/04/14 22:50:25 aaron Exp $ */ +/* $OpenBSD: uhci.c,v 1.13 2000/07/04 11:44:23 fgsch Exp $ */ /* $NetBSD: uhci.c,v 1.110 2000/04/14 14:11:36 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhci.c,v 1.33 1999/11/17 22:33:41 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -1038,6 +1038,12 @@ uhci_intr(arg) } #endif + if (sc->sc_suspend != PWR_RESUME) { + printf("%s: interrupt while not operating ignored\n", + USBDEVNAME(sc->sc_bus.bdev)); + return (0); + } + status = UREAD2(sc, UHCI_STS); if (status == 0) /* The interrupt was not for us. */ return (0); @@ -2551,7 +2557,7 @@ uhci_add_intr(sc, sqh) vf->bandwidth++; } -/* Remove interrupt QH, called with vflock. */ +/* Remove interrupt QH. */ void uhci_remove_intr(sc, sqh) uhci_softc_t *sc; @@ -3112,12 +3118,15 @@ uhci_root_ctrl_start(xfer) index, UREAD2(sc, port))); sc->sc_isreset = 1; break; + case UHF_PORT_POWER: + /* Pretend we turned on power */ + err = USBD_NORMAL_COMPLETION; + goto ret; case UHF_C_PORT_CONNECTION: case UHF_C_PORT_ENABLE: case UHF_C_PORT_OVER_CURRENT: case UHF_PORT_CONNECTION: case UHF_PORT_OVER_CURRENT: - case UHF_PORT_POWER: case UHF_PORT_LOW_SPEED: case UHF_C_PORT_SUSPEND: case UHF_C_PORT_RESET: diff --git a/sys/dev/usb/uhcireg.h b/sys/dev/usb/uhcireg.h index 3fca982be06..0777e92b468 100644 --- a/sys/dev/usb/uhcireg.h +++ b/sys/dev/usb/uhcireg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uhcireg.h,v 1.5 2000/04/14 22:50:26 aaron Exp $ */ +/* $OpenBSD: uhcireg.h,v 1.6 2000/07/04 11:44:23 fgsch Exp $ */ /* $NetBSD: uhcireg.h,v 1.10 2000/04/06 23:44:21 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhcireg.h,v 1.12 1999/11/17 22:33:42 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/uhcivar.h b/sys/dev/usb/uhcivar.h index 07c704cbbab..d461973ae73 100644 --- a/sys/dev/usb/uhcivar.h +++ b/sys/dev/usb/uhcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uhcivar.h,v 1.8 2000/04/14 22:50:26 aaron Exp $ */ +/* $OpenBSD: uhcivar.h,v 1.9 2000/07/04 11:44:23 fgsch Exp $ */ /* $NetBSD: uhcivar.h,v 1.28 2000/04/06 23:44:21 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.14 1999/11/17 22:33:42 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -135,6 +135,7 @@ typedef struct uhci_softc { struct usbd_bus sc_bus; /* base device */ bus_space_tag_t iot; bus_space_handle_t ioh; + bus_size_t sc_size; uhci_physaddr_t *sc_pframes; usb_dma_t sc_dma; diff --git a/sys/dev/usb/uhid.c b/sys/dev/usb/uhid.c index a5f7eecdbe4..41459b39e88 100644 --- a/sys/dev/usb/uhid.c +++ b/sys/dev/usb/uhid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhid.c,v 1.10 2000/04/14 22:50:26 aaron Exp $ */ +/* $OpenBSD: uhid.c,v 1.11 2000/07/04 11:44:23 fgsch Exp $ */ /* $NetBSD: uhid.c,v 1.37 2000/04/14 14:12:47 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhid.c,v 1.22 1999/11/17 22:33:43 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c index 7dddc87bdce..9d45b72d556 100644 --- a/sys/dev/usb/uhub.c +++ b/sys/dev/usb/uhub.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhub.c,v 1.9 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: uhub.c,v 1.10 2000/07/04 11:44:23 fgsch Exp $ */ /* $NetBSD: uhub.c,v 1.41 2000/03/27 12:33:56 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ */ /* - * USB spec: http://www.usb.org/cgi-usb/mailmerge.cgi/home/usb/docs/developers/cgiform.tpl + * USB spec: http://www.usb.org/developers/docs.htm */ #include <sys/param.h> @@ -63,6 +63,8 @@ #include <dev/usb/usbdi_util.h> #include <dev/usb/usbdivar.h> +#define UHUB_INTR_INTERVAL 255 /* ms */ + #ifdef UHUB_DEBUG #define DPRINTF(x) if (uhubdebug) logprintf x #define DPRINTFN(n,x) if (uhubdebug>(n)) logprintf x @@ -80,7 +82,6 @@ struct uhub_softc { u_char sc_running; }; -Static usbd_status uhub_init_port __P((struct usbd_port *)); Static usbd_status uhub_explore __P((usbd_device_handle hub)); Static void uhub_intr __P((usbd_xfer_handle, usbd_private_handle,usbd_status)); @@ -149,7 +150,7 @@ USB_ATTACH(uhub) struct usbd_hub *hub; usb_device_request_t req; usb_hub_descriptor_t hubdesc; - int p, port, nports, nremov; + int p, port, nports, nremov, pwrdly; usbd_interface_handle iface; usb_endpoint_descriptor_t *ed; @@ -238,7 +239,7 @@ USB_ATTACH(uhub) err = usbd_open_pipe_intr(iface, ed->bEndpointAddress, USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_status, - sizeof(sc->sc_status), uhub_intr, USBD_DEFAULT_INTERVAL); + sizeof(sc->sc_status), uhub_intr, UHUB_INTR_INTERVAL); if (err) { printf("%s: cannot open interrupt pipe\n", USBDEVNAME(sc->sc_dev)); @@ -250,16 +251,61 @@ USB_ATTACH(uhub) usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, USBDEV(sc->sc_dev)); + /* + * To have the best chance of success we do things in the exact same + * order as Windoze98. This should not be necessary, but some + * devices do not follow the USB specs to the letter. + * + * These are the events on the bus when a hub is attached: + * Get device and config descriptors (see attach code) + * Get hub descriptor (see above) + * For all ports + * turn on power + * wait for power to become stable + * (all below happens in explore code) + * For all ports + * clear C_PORT_CONNECTION + * For all ports + * get port status + * if device connected + * turn on reset + * wait + * clear C_PORT_RESET + * get port status + * proceed with device attachment + */ + + /* Set up data structures */ for (p = 0; p < nports; p++) { struct usbd_port *up = &hub->ports[p]; up->device = 0; up->parent = dev; up->portno = p+1; - err = uhub_init_port(up); + if (dev->self_powered) + /* Self powered hub, give ports maximum current. */ + up->power = USB_MAX_POWER; + else + up->power = USB_MIN_POWER; + } + + /* XXX should check for none, individual, or ganged power? */ + + pwrdly = dev->hub->hubdesc.bPwrOn2PwrGood * UHD_PWRON_FACTOR + + USB_EXTRA_POWER_UP_TIME; + for (port = 1; port <= nports; port++) { + /* Turn the power on. */ + err = usbd_set_port_feature(dev, port, UHF_PORT_POWER); if (err) - printf("%s: init of port %d failed\n", - USBDEVNAME(sc->sc_dev), up->portno); + printf("%s: port %d power on failed, %s\n", + USBDEVNAME(sc->sc_dev), port, + usbd_errstr(err)); + DPRINTF(("usb_init_port: turn on port %d power\n", port)); + /* Wait for stable power. */ + usbd_delay_ms(dev, pwrdly); } + + /* The usual exploration will finish the setup. */ + sc->sc_running = 1; USB_ATTACH_SUCCESS_RETURN; @@ -271,68 +317,6 @@ USB_ATTACH(uhub) } usbd_status -uhub_init_port(up) - struct usbd_port *up; -{ - int port = up->portno; - usbd_device_handle dev = up->parent; - usbd_status err; - u_int16_t pstatus; - - err = usbd_get_port_status(dev, port, &up->status); - if (err) - return (err); - pstatus = UGETW(up->status.wPortStatus); - DPRINTF(("usbd_init_port: adding hub port=%d status=0x%04x " - "change=0x%04x\n", - port, pstatus, UGETW(up->status.wPortChange))); - if ((pstatus & UPS_PORT_POWER) == 0) { - /* Port lacks power, turn it on */ - - /* First let the device go through a good power cycle, */ - usbd_delay_ms(dev, USB_PORT_POWER_DOWN_TIME); - - /* then turn the power on. */ - err = usbd_set_port_feature(dev, port, UHF_PORT_POWER); - if (err) - return (err); - DPRINTF(("usb_init_port: turn on port %d power status=0x%04x " - "change=0x%04x\n", - port, UGETW(up->status.wPortStatus), - UGETW(up->status.wPortChange))); - /* Wait for stable power. */ - usbd_delay_ms(dev, dev->hub->hubdesc.bPwrOn2PwrGood * - UHD_PWRON_FACTOR); - /* Get the port status again. */ - err = usbd_get_port_status(dev, port, &up->status); - if (err) - return (err); - DPRINTF(("usb_init_port: after power on status=0x%04x " - "change=0x%04x\n", - UGETW(up->status.wPortStatus), - UGETW(up->status.wPortChange))); - -#if 0 -usbd_clear_hub_feature(dev, UHF_C_HUB_OVER_CURRENT); -usbd_clear_port_feature(dev, port, UHF_C_PORT_OVER_CURRENT); -usbd_get_port_status(dev, port, &up->status); -#endif - - pstatus = UGETW(up->status.wPortStatus); - if ((pstatus & UPS_PORT_POWER) == 0) - printf("%s: port %d did not power up\n", - USBDEVNAME(((struct uhub_softc *)dev->hub->hubsoftc)->sc_dev), port); - - } - if (dev->self_powered) - /* Self powered hub, give ports maximum current. */ - up->power = USB_MAX_POWER; - else - up->power = USB_MIN_POWER; - return (USBD_NORMAL_COMPLETION); -} - -usbd_status uhub_explore(dev) usbd_device_handle dev; { @@ -392,10 +376,13 @@ uhub_explore(dev) up->device->hub->explore(up->device); continue; } + + /* We have a connect status change, handle it. */ + DPRINTF(("uhub_explore: status change hub=%d port=%d\n", dev->address, port)); usbd_clear_port_feature(dev, port, UHF_C_PORT_CONNECTION); - usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE); + /*usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE);*/ /* * If there is already a device on the port the change status * must mean that is has disconnected. Looking at the @@ -413,12 +400,18 @@ uhub_explore(dev) UHF_C_PORT_CONNECTION); } if (!(status & UPS_CURRENT_CONNECT_STATUS)) { + /* Nothing connected, just ignore it. */ DPRINTFN(3,("uhub_explore: port=%d !CURRENT_CONNECT" "_STATUS\n", port)); continue; } /* Connected */ + + if (!(status & UPS_PORT_POWER)) + printf("%s: strange, connected port %d has no power\n", + USBDEVNAME(sc->sc_dev), port); + up->restartcnt = 0; /* Wait for maximum device power up time. */ @@ -426,8 +419,8 @@ uhub_explore(dev) /* Reset port, which implies enabling it. */ if (usbd_reset_port(dev, port, &up->status)) { - DPRINTF(("uhub_explore: port=%d reset failed\n", - port)); + printf("uhub_explore: port=%d reset failed\n", + port); continue; } diff --git a/sys/dev/usb/ulpt.c b/sys/dev/usb/ulpt.c index 547de7c2da2..04d874e6be9 100644 --- a/sys/dev/usb/ulpt.c +++ b/sys/dev/usb/ulpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ulpt.c,v 1.3 2000/04/14 22:50:27 aaron Exp $ */ +/* $OpenBSD: ulpt.c,v 1.4 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: ulpt.c,v 1.36 2000/04/14 14:12:11 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/ulpt.c,v 1.24 1999/11/17 22:33:44 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/umodem.c b/sys/dev/usb/umodem.c index 9e1df7f8509..b3d5c738197 100644 --- a/sys/dev/usb/umodem.c +++ b/sys/dev/usb/umodem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umodem.c,v 1.3 2000/04/14 22:50:28 aaron Exp $ */ +/* $OpenBSD: umodem.c,v 1.4 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: umodem.c,v 1.27 2000/04/14 14:21:55 augustss Exp $ */ /* @@ -6,7 +6,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/urio.c b/sys/dev/usb/urio.c index 2649fb5cb47..ff54d78d31d 100644 --- a/sys/dev/usb/urio.c +++ b/sys/dev/usb/urio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: urio.c,v 1.1 2000/04/15 17:36:28 jakob Exp $ */ +/* $OpenBSD: urio.c,v 1.2 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: urio.c,v 1.1 2000/04/14 14:20:02 augustss Exp $ */ /* @@ -6,7 +6,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/urio.h b/sys/dev/usb/urio.h index 2847759314b..c885b6ff5a2 100644 --- a/sys/dev/usb/urio.h +++ b/sys/dev/usb/urio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: urio.h,v 1.1 2000/04/15 17:36:28 jakob Exp $ */ +/* $OpenBSD: urio.h,v 1.2 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: urio.h,v 1.1 2000/04/14 18:15:47 augustss Exp $ */ /* @@ -6,7 +6,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index 78ca7a5acdb..78f98668b31 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb.c,v 1.11 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: usb.c,v 1.12 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: usb.c,v 1.43 2000/03/29 18:24:53 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb.c,v 1.20 1999/11/17 22:33:46 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -296,12 +296,13 @@ usb_event_thread(arg) config_pending_decr(); first = 0; } - (void)tsleep(&sc->sc_bus->needs_explore, PWAIT, "usbevt", #ifdef USB_DEBUG - usb_noexplore ? 0 : + (void)tsleep(&sc->sc_bus->needs_explore, PWAIT, "usbevt", + usb_noexplore ? 0 : hz * 60); +#else + (void)tsleep(&sc->sc_bus->needs_explore, PWAIT, "usbevt", + hz * 60); #endif - hz*60 - ); DPRINTFN(2,("usb_event_thread: woke up\n")); } sc->sc_event_thread = 0; diff --git a/sys/dev/usb/usb.h b/sys/dev/usb/usb.h index 6830d1fd673..97ae2b8c702 100644 --- a/sys/dev/usb/usb.h +++ b/sys/dev/usb/usb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usb.h,v 1.9 2000/04/04 22:52:30 aaron Exp $ */ +/* $OpenBSD: usb.h,v 1.10 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: usb.h,v 1.44 2000/04/03 13:40:05 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb.h,v 1.14 1999/11/17 22:33:46 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -77,36 +77,43 @@ MALLOC_DECLARE(M_USBHC); /* * The USB records contain some unaligned little-endian word * components. The U[SG]ETW macros take care of both the alignment - * and endian problem and should always be used to access 16 bit + * and endian problem and should always be used to access non-byte * values. */ typedef u_int8_t uByte; typedef u_int8_t uWord[2]; +typedef u_int8_t uDWord[4]; + +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h)) + +#if 1 #define UGETW(w) ((w)[0] | ((w)[1] << 8)) #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8)) -#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h)) -typedef u_int8_t uDWord[4]; #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24)) #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \ (w)[1] = (u_int8_t)((v) >> 8), \ (w)[2] = (u_int8_t)((v) >> 16), \ (w)[3] = (u_int8_t)((v) >> 24)) +#else /* * On little-endian machines that can handle unanliged accesses * (e.g. i386) these macros can be replaced by the following. */ -#if 0 #define UGETW(w) (*(u_int16_t *)(w)) #define USETW(w,v) (*(u_int16_t *)(w) = (v)) +#define UGETDW(w) (*(u_int32_t *)(w)) +#define USETDW(w,v) (*(u_int32_t *)(w) = (v)) #endif +#define UPACKED __attribute__((__packed__)) + typedef struct { uByte bmRequestType; uByte bRequest; uWord wValue; uWord wIndex; uWord wLength; -} usb_device_request_t; +} UPACKED usb_device_request_t; #define UT_WRITE 0x00 #define UT_READ 0x80 @@ -175,7 +182,7 @@ typedef struct { uByte bLength; uByte bDescriptorType; uByte bDescriptorSubtype; -} usb_descriptor_t; +} UPACKED usb_descriptor_t; typedef struct { uByte bLength; @@ -193,7 +200,7 @@ typedef struct { uByte iProduct; uByte iSerialNumber; uByte bNumConfigurations; -} usb_device_descriptor_t; +} UPACKED usb_device_descriptor_t; #define USB_DEVICE_DESCRIPTOR_SIZE 18 typedef struct { @@ -209,7 +216,7 @@ typedef struct { #define UC_REMOTE_WAKEUP 0x20 uByte bMaxPower; /* max current in 2 mA units */ #define UC_POWER_FACTOR 2 -} usb_config_descriptor_t; +} UPACKED usb_config_descriptor_t; #define USB_CONFIG_DESCRIPTOR_SIZE 9 typedef struct { @@ -222,7 +229,7 @@ typedef struct { uByte bInterfaceSubClass; uByte bInterfaceProtocol; uByte iInterface; -} usb_interface_descriptor_t; +} UPACKED usb_interface_descriptor_t; #define USB_INTERFACE_DESCRIPTOR_SIZE 9 typedef struct { @@ -249,14 +256,14 @@ typedef struct { #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE) uWord wMaxPacketSize; uByte bInterval; -} usb_endpoint_descriptor_t; +} UPACKED usb_endpoint_descriptor_t; #define USB_ENDPOINT_DESCRIPTOR_SIZE 7 typedef struct { uByte bLength; uByte bDescriptorType; uWord bString[127]; -} usb_string_descriptor_t; +} UPACKED usb_string_descriptor_t; #define USB_MAX_STRING_LEN 128 #define USB_LANGUAGE_TABLE 0 /* # of the string language id table */ @@ -299,9 +306,9 @@ typedef struct { uByte DeviceRemovable[32]; /* max 255 ports */ #define UHD_NOT_REMOV(desc, i) \ (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1) - /* deprecated uByte PortPowerCtrlMask[]; */ -} usb_hub_descriptor_t; -#define USB_HUB_DESCRIPTOR_SIZE 8 + /* deprecated */ uByte PortPowerCtrlMask[1]; +} UPACKED usb_hub_descriptor_t; +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */ typedef struct { uWord wStatus; @@ -310,14 +317,14 @@ typedef struct { #define UDS_REMOTE_WAKEUP 0x0002 /* Endpoint status flags */ #define UES_HALT 0x0001 -} usb_status_t; +} UPACKED usb_status_t; typedef struct { uWord wHubStatus; #define UHS_LOCAL_POWER 0x0001 #define UHS_OVER_CURRENT 0x0002 uWord wHubChange; -} usb_hub_status_t; +} UPACKED usb_hub_status_t; typedef struct { uWord wPortStatus; @@ -334,7 +341,7 @@ typedef struct { #define UPS_C_SUSPEND 0x0004 #define UPS_C_OVERCURRENT_INDICATOR 0x0008 #define UPS_C_PORT_RESET 0x0010 -} usb_port_status_t; +} UPACKED usb_port_status_t; /* Device class codes */ #define UDCLASS_AUDIO 0x00 @@ -428,6 +435,7 @@ typedef struct { #define USB_RESUME_DELAY (20*5) /* ms */ #define USB_RESUME_WAIT 10 /* ms */ #define USB_RESUME_RECOVERY 10 /* ms */ +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */ #else /* Allow for marginal (i.e. non-conforming) devices. */ #define USB_PORT_RESET_DELAY 50 /* ms */ @@ -437,6 +445,7 @@ typedef struct { #define USB_RESUME_DELAY (50*5) /* ms */ #define USB_RESUME_WAIT 50 /* ms */ #define USB_RESUME_RECOVERY 50 /* ms */ +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */ #endif #define USB_MIN_POWER 100 /* mA */ @@ -444,6 +453,10 @@ typedef struct { #define USB_BUS_RESET_DELAY 100 /* ms XXX?*/ + +#define USB_UNCONFIG_NO 0 +#define USB_UNCONFIG_INDEX (-1) + /*** ioctl() related stuff ***/ struct usb_ctl_request { diff --git a/sys/dev/usb/usb_mem.c b/sys/dev/usb/usb_mem.c index 2856ce3545d..8b97d677c56 100644 --- a/sys/dev/usb/usb_mem.c +++ b/sys/dev/usb/usb_mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_mem.c,v 1.9 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: usb_mem.c,v 1.10 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: usb_mem.c,v 1.19 2000/03/27 12:33:58 augustss Exp $ */ /* @@ -6,7 +6,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/usb_mem.h b/sys/dev/usb/usb_mem.h index bf9017b9ba9..c44ad09e1b8 100644 --- a/sys/dev/usb/usb_mem.h +++ b/sys/dev/usb/usb_mem.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_mem.h,v 1.6 2000/03/28 19:37:50 aaron Exp $ */ +/* $OpenBSD: usb_mem.h,v 1.7 2000/07/04 11:44:24 fgsch Exp $ */ /* $NetBSD: usb_mem.h,v 1.12 2000/03/12 23:10:29 nathanw Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.9 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/usb_port.h b/sys/dev/usb/usb_port.h index 1d21a7544a1..5fd97ead99f 100644 --- a/sys/dev/usb/usb_port.h +++ b/sys/dev/usb/usb_port.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_port.h,v 1.15 2000/06/29 13:48:31 aaron Exp $ */ +/* $OpenBSD: usb_port.h,v 1.16 2000/07/04 11:44:25 fgsch Exp $ */ /* $NetBSD: usb_port.h,v 1.28 2000/03/30 08:53:31 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.21 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -65,7 +65,10 @@ #define CUE_DEBUG 1 #define KUE_DEBUG 1 #define UMASS_DEBUG 1 -#define UVISOR_DEBUG 1 +#define UPL_DEBUG 1 +#define UZCOM_DEBUG 1 +#define URIO_DEBUG 1 +#define UFTDI_DEBUG 1 #define Static #else #define Static static @@ -94,6 +97,8 @@ typedef struct callout usb_callout_t; #define usb_kthread_create1 kthread_create1 #define usb_kthread_create kthread_create +typedef int usb_malloc_type; + #define Ether_ifattach ether_ifattach #define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m)) @@ -185,6 +190,10 @@ __CONCAT(dname,_detach)(self, flags) \ #define KUE_DEBUG 1 #define UMASS_DEBUG 1 #define UVISOR_DEBUG 1 +#define UPL_DEBUG 1 +#define UZCOM_DEBUG 1 +#define URIO_DEBUG 1 +#define UFTDI_DEBUG 1 #endif #define Static @@ -218,6 +227,8 @@ __CONCAT(dname,_detach)(self, flags) \ #define config_pending_incr() #define config_pending_decr() +typedef int usb_malloc_type; + #define mii_attach(x1,x2,x3,x4,x5,x6) mii_phy_probe(x1,x2,x3) #define Ether_ifattach(ifp, eaddr) ether_ifattach(ifp) #define if_deactivate(x) @@ -380,6 +391,8 @@ typedef struct callout_handle usb_callout_t; #define powerhook_disestablish(hdl) #define PWR_RESUME 0 +typedef struct malloc_type *usb_malloc_type; + #define USB_DECLARE_DRIVER_INIT(dname, init) \ Static device_probe_t __CONCAT(dname,_match); \ Static device_attach_t __CONCAT(dname,_attach); \ diff --git a/sys/dev/usb/usb_quirks.c b/sys/dev/usb/usb_quirks.c index bcc821a2ab3..e7494e750fc 100644 --- a/sys/dev/usb/usb_quirks.c +++ b/sys/dev/usb/usb_quirks.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_quirks.c,v 1.5 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: usb_quirks.c,v 1.6 2000/07/04 11:44:25 fgsch Exp $ */ /* $NetBSD: usb_quirks.c,v 1.24 2000/03/27 12:33:58 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_quirks.c,v 1.13 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -68,6 +68,8 @@ Static struct usbd_quirk_entry { { USB_VENDOR_ALTEC, USB_PRODUCT_ALTEC_ADA70, 0x103, { UQ_BAD_ADC }}, { USB_VENDOR_ALTEC, USB_PRODUCT_ALTEC_ASC495, 0x000, { UQ_BAD_AUDIO }}, { USB_VENDOR_QTRONIX, USB_PRODUCT_QTRONIX_980N, 0x110, { UQ_SPUR_BUT_UP }}, + { USB_VENDOR_MCT, USB_PRODUCT_MCT_HUB0100, 0x102, { UQ_BUS_POWERED }}, + { USB_VENDOR_MCT, USB_PRODUCT_MCT_USB232, 0x102, { UQ_BUS_POWERED }}, { 0, 0, 0, { 0 } } }; diff --git a/sys/dev/usb/usb_quirks.h b/sys/dev/usb/usb_quirks.h index 6ee1e4a826f..a8611a68f09 100644 --- a/sys/dev/usb/usb_quirks.h +++ b/sys/dev/usb/usb_quirks.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_quirks.h,v 1.4 2000/03/28 19:37:51 aaron Exp $ */ +/* $OpenBSD: usb_quirks.h,v 1.5 2000/07/04 11:44:25 fgsch Exp $ */ /* $NetBSD: usb_quirks.h,v 1.10 1999/11/18 23:32:31 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_quirks.h,v 1.9 1999/11/12 23:31:03 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index 984750fcbeb..b7c1f8a867c 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_subr.c,v 1.11 2000/04/14 22:50:28 aaron Exp $ */ +/* $OpenBSD: usb_subr.c,v 1.12 2000/07/04 11:44:25 fgsch Exp $ */ /* $NetBSD: usb_subr.c,v 1.72 2000/04/14 14:13:56 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -283,7 +283,7 @@ usbd_devinfo(dev, showclass, cp) int bcdDevice, bcdUSB; usbd_devinfo_vp(dev, vendor, product); - cp += sprintf(cp, "%s%s%s", vendor, *vendor ? " " : "", product); + cp += sprintf(cp, "%s %s", vendor, product); if (showclass) cp += sprintf(cp, ", class %d/%d", udd->bDeviceClass, udd->bDeviceSubClass); @@ -303,8 +303,6 @@ usb_delay_ms(bus, ms) usbd_bus_handle bus; u_int ms; { - extern int cold; - /* Wait at least two clock ticks so we know the time has passed. */ if (bus->use_polling || cold) delay((ms+1) * 1000); @@ -352,10 +350,8 @@ usbd_reset_port(dev, port, ps) return (err); } } while ((UGETW(ps->wPortChange) & UPS_C_PORT_RESET) == 0 && --n > 0); - if (n == 0) { - printf("usbd_reset_port: timeout\n"); - return (USBD_IOERROR); - } + if (n == 0) + return (USBD_TIMEOUT); err = usbd_clear_port_feature(dev, port, UHF_C_PORT_RESET); #ifdef USB_DEBUG if (err) @@ -445,15 +441,17 @@ usbd_fill_iface_data(dev, ifaceidx, altidx) int altidx; { usbd_interface_handle ifc = &dev->ifaces[ifaceidx]; + usb_interface_descriptor_t *idesc; char *p, *end; int endpt, nendpt; DPRINTFN(4,("usbd_fill_iface_data: ifaceidx=%d altidx=%d\n", ifaceidx, altidx)); - ifc->device = dev; - ifc->idesc = usbd_find_idesc(dev->cdesc, ifaceidx, altidx); - if (ifc->idesc == 0) + idesc = usbd_find_idesc(dev->cdesc, ifaceidx, altidx); + if (idesc == NULL) return (USBD_INVAL); + ifc->device = dev; + ifc->idesc = idesc; ifc->index = ifaceidx; ifc->altindex = altidx; nendpt = ifc->idesc->bNumEndpoints; @@ -499,8 +497,10 @@ usbd_fill_iface_data(dev, ifaceidx, altidx) return (USBD_NORMAL_COMPLETION); bad: - if (ifc->endpoints != NULL) + if (ifc->endpoints != NULL) { free(ifc->endpoints, M_USB); + ifc->endpoints = NULL; + } return (USBD_INVAL); } @@ -539,6 +539,9 @@ usbd_set_config_no(dev, no, msg) usb_config_descriptor_t cd; usbd_status err; + if (no == USB_UNCONFIG_NO) + return (usbd_set_config_index(dev, USB_UNCONFIG_INDEX, msg)); + DPRINTFN(5,("usbd_set_config_no: %d\n", no)); /* Figure out what config index to use. */ for (index = 0; index < dev->ddesc.bNumConfigurations; index++) { @@ -565,7 +568,7 @@ usbd_set_config_index(dev, index, msg) DPRINTFN(5,("usbd_set_config_index: dev=%p index=%d\n", dev, index)); /* XXX check that all interfaces are idle */ - if (dev->config != 0) { + if (dev->config != USB_UNCONFIG_NO) { DPRINTF(("usbd_set_config_index: free old config\n")); /* Free all configuration data structures. */ nifc = dev->cdesc->bNumInterface; @@ -575,10 +578,20 @@ usbd_set_config_index(dev, index, msg) free(dev->cdesc, M_USB); dev->ifaces = NULL; dev->cdesc = NULL; - dev->config = 0; + dev->config = USB_UNCONFIG_NO; } - /* Figure out what config number to use. */ + if (index == USB_UNCONFIG_INDEX) { + /* We are unconfiguring the device, so leave unallocated. */ + DPRINTF(("usbd_set_config_index: set config 0\n")); + err = usbd_set_config(dev, USB_UNCONFIG_NO); + if (err) + DPRINTF(("usbd_set_config_index: setting config=0 " + "failed, error=%s\n", usbd_errstr(err))); + return (err); + } + + /* Get the short descriptor. */ err = usbd_get_config_desc(dev, index, &cd); if (err) return (err); @@ -586,6 +599,7 @@ usbd_set_config_index(dev, index, msg) cdp = malloc(len, M_USB, M_NOWAIT); if (cdp == NULL) return (USBD_NOMEM); + /* Get the full descriptor. */ err = usbd_get_desc(dev, UDESC_CONFIG, index, len, cdp); if (err) goto bad; @@ -595,9 +609,11 @@ usbd_set_config_index(dev, index, msg) err = USBD_INVAL; goto bad; } + + /* Figure out if the device is self or bus powered. */ selfpowered = 0; if (!(dev->quirks->uq_flags & UQ_BUS_POWERED) && - cdp->bmAttributes & UC_SELF_POWERED) { + (cdp->bmAttributes & UC_SELF_POWERED)) { /* May be self powered. */ if (cdp->bmAttributes & UC_BUS_POWERED) { /* Must ask device. */ @@ -614,6 +630,8 @@ usbd_set_config_index(dev, index, msg) "selfpowered=%d, power=%d\n", dev->address, cdp->bmAttributes, selfpowered, cdp->bMaxPower * 2)); + + /* Check if we have enough power. */ #ifdef USB_DEBUG if (dev->powersrc == NULL) { DPRINTF(("usbd_set_config_index: No power source?\n")); @@ -635,6 +653,7 @@ usbd_set_config_index(dev, index, msg) dev->power = power; dev->self_powered = selfpowered; + /* Set the actual configuration value. */ DPRINTF(("usbd_set_config_index: set config %d\n", cdp->bConfigurationValue)); err = usbd_set_config(dev, cdp->bConfigurationValue); @@ -644,8 +663,8 @@ usbd_set_config_index(dev, index, msg) cdp->bConfigurationValue, usbd_errstr(err))); goto bad; } - DPRINTF(("usbd_set_config_index: setting new config %d\n", - cdp->bConfigurationValue)); + + /* Allocate and fill interface data. */ nifc = cdp->bNumInterface; dev->ifaces = malloc(nifc * sizeof(struct usbd_interface), M_USB, M_NOWAIT); diff --git a/sys/dev/usb/usbcdc.h b/sys/dev/usb/usbcdc.h index a370d642cfe..35242e979c6 100644 --- a/sys/dev/usb/usbcdc.h +++ b/sys/dev/usb/usbcdc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbcdc.h,v 1.2 2000/03/28 19:37:51 aaron Exp $ */ +/* $OpenBSD: usbcdc.h,v 1.3 2000/07/04 11:44:25 fgsch Exp $ */ /* $NetBSD: usbcdc.h,v 1.5 1999/11/18 23:32:32 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbcdc.h,v 1.7 1999/11/17 22:33:48 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -58,7 +58,7 @@ typedef struct { uByte bDescriptorType; uByte bDescriptorSubtype; uWord bcdCDC; -} usb_cdc_header_descriptor_t; +} UPACKED usb_cdc_header_descriptor_t; typedef struct { uByte bLength; @@ -68,7 +68,7 @@ typedef struct { #define USB_CDC_CM_DOES_CM 0x01 #define USB_CDC_CM_OVER_DATA 0x02 uByte bDataInterface; -} usb_cdc_cm_descriptor_t; +} UPACKED usb_cdc_cm_descriptor_t; typedef struct { uByte bLength; @@ -79,7 +79,7 @@ typedef struct { #define USB_CDC_ACM_HAS_LINE 0x02 #define USB_CDC_ACM_HAS_BREAK 0x04 #define USB_CDC_ACM_HAS_NETWORK_CONN 0x08 -} usb_cdc_acm_descriptor_t; +} UPACKED usb_cdc_acm_descriptor_t; typedef struct { uByte bLength; @@ -87,7 +87,7 @@ typedef struct { uByte bDescriptorSubtype; uByte bMasterInterface; uByte bSlaveInterface[1]; -} usb_cdc_union_descriptor_t; +} UPACKED usb_cdc_union_descriptor_t; #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00 #define UCDC_GET_ENCAPSULATED_RESPONSE 0x01 @@ -109,7 +109,7 @@ typedef struct { uWord wState; #define UCDC_IDLE_SETTING 0x0001 #define UCDC_DATA_MULTIPLEXED 0x0002 -} usb_cdc_abstract_state_t; +} UPACKED usb_cdc_abstract_state_t; #define UCDC_ABSTRACT_STATE_LENGTH 2 typedef struct { @@ -125,7 +125,7 @@ typedef struct { #define UCDC_PARITY_MARK 3 #define UCDC_PARITY_SPACE 4 uByte bDataBits; -} usb_cdc_line_state_t; +} UPACKED usb_cdc_line_state_t; #define UCDC_LINE_STATE_LENGTH 7 typedef struct { @@ -144,7 +144,7 @@ typedef struct { uWord wIndex; uWord wLength; uByte data[16]; -} usb_cdc_notification_t; +} UPACKED usb_cdc_notification_t; #define UCDC_NOTIFICATION_LENGTH 8 #endif /* _USBCDC_H_ */ diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c index c88d33d87ae..bf37703bb65 100644 --- a/sys/dev/usb/usbdi.c +++ b/sys/dev/usb/usbdi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi.c,v 1.10 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: usbdi.c,v 1.11 2000/07/04 11:44:25 fgsch Exp $ */ /* $NetBSD: usbdi.c,v 1.71 2000/03/29 01:45:21 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -640,6 +640,12 @@ usbd_endpoint_count(iface, count) usbd_interface_handle iface; u_int8_t *count; { +#ifdef DIAGNOSTIC + if (iface == NULL || iface->idesc == NULL) { + printf("usbd_endpoint_count: NULL pointer\n"); + return (USBD_INVAL); + } +#endif *count = iface->idesc->bNumEndpoints; return (USBD_NORMAL_COMPLETION); } @@ -693,19 +699,27 @@ usbd_set_interface(iface, altidx) { usb_device_request_t req; usbd_status err; + void *endpoints; if (LIST_FIRST(&iface->pipes) != 0) return (USBD_IN_USE); - if (iface->endpoints) - free(iface->endpoints, M_USB); - iface->endpoints = 0; - iface->idesc = 0; - + endpoints = iface->endpoints; err = usbd_fill_iface_data(iface->device, iface->index, altidx); if (err) return (err); + /* new setting works, we can free old endpoints */ + if (endpoints != NULL) + free(endpoints, M_USB); + +#ifdef DIAGNOSTIC + if (iface->idesc == NULL) { + printf("usbd_set_interface: NULL pointer\n"); + return (USBD_INVAL); + } +#endif + req.bmRequestType = UT_WRITE_INTERFACE; req.bRequest = UR_SET_INTERFACE; USETW(req.wValue, iface->idesc->bAlternateSetting); diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h index 8447a6b4fdc..e253ffdeab9 100644 --- a/sys/dev/usb/usbdi.h +++ b/sys/dev/usb/usbdi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi.h,v 1.8 2000/03/28 19:37:52 aaron Exp $ */ +/* $OpenBSD: usbdi.h,v 1.9 2000/07/04 11:44:25 fgsch Exp $ */ /* $NetBSD: usbdi.h,v 1.41 2000/03/02 12:37:51 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/usb/usbdi_util.c b/sys/dev/usb/usbdi_util.c index cf91d15bdf8..ec96641e4c1 100644 --- a/sys/dev/usb/usbdi_util.c +++ b/sys/dev/usb/usbdi_util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi_util.c,v 1.8 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: usbdi_util.c,v 1.9 2000/07/04 11:44:26 fgsch Exp $ */ /* $NetBSD: usbdi_util.c,v 1.29 2000/03/27 12:33:59 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi_util.c,v 1.14 1999/11/17 22:33:50 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -435,12 +435,7 @@ usbd_alloc_report_desc(ifc, descp, sizep, mem) usbd_interface_handle ifc; void **descp; int *sizep; -#if defined(__NetBSD__) || defined(__OpenBSD__) - int mem; -#elif defined(__FreeBSD__) - struct malloc_type *mem; -#endif - + usb_malloc_type mem; { usb_interface_descriptor_t *id; usb_hid_descriptor_t *hid; diff --git a/sys/dev/usb/usbdi_util.h b/sys/dev/usb/usbdi_util.h index d5dab901244..fa98b7197d8 100644 --- a/sys/dev/usb/usbdi_util.h +++ b/sys/dev/usb/usbdi_util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi_util.h,v 1.5 2000/03/28 19:37:53 aaron Exp $ */ +/* $OpenBSD: usbdi_util.h,v 1.6 2000/07/04 11:44:26 fgsch Exp $ */ /* $NetBSD: usbdi_util.h,v 1.19 1999/11/18 23:32:37 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi_util.h,v 1.9 1999/11/17 22:33:50 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -70,13 +70,9 @@ usbd_status usbd_get_report __P((usbd_interface_handle iface,int type,int id,void *data,int len)); usbd_status usbd_set_idle __P((usbd_interface_handle iface, int duration, int id)); -#if defined(__NetBSD__) || defined(__OpenBSD__) usbd_status usbd_alloc_report_desc - __P((usbd_interface_handle ifc, void **descp, int *sizep, int mem)); -#elif defined(__FreeBSD__) -usbd_status usbd_alloc_report_desc - __P((usbd_interface_handle ifc, void **descp, int *sizep, struct malloc_type * mem)); -#endif + __P((usbd_interface_handle ifc, void **descp, int *sizep, + usb_malloc_type mem)); usbd_status usbd_get_config __P((usbd_device_handle dev, u_int8_t *conf)); usbd_status usbd_get_string_desc diff --git a/sys/dev/usb/usbdivar.h b/sys/dev/usb/usbdivar.h index 61c3f316fde..56166c21ac1 100644 --- a/sys/dev/usb/usbdivar.h +++ b/sys/dev/usb/usbdivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdivar.h,v 1.9 2000/03/30 16:19:33 aaron Exp $ */ +/* $OpenBSD: usbdivar.h,v 1.10 2000/07/04 11:44:26 fgsch Exp $ */ /* $NetBSD: usbdivar.h,v 1.55 2000/03/30 00:18:18 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdivar.h,v 1.11 1999/11/17 22:33:51 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -247,7 +247,10 @@ void usb_disconnect_port __P((struct usbd_port *up, device_ptr_t)); void usb_needs_explore __P((usbd_bus_handle)); void usb_schedsoftintr __P((struct usbd_bus *)); -#ifdef DIAGNOSTIC +/* + * XXX This check is extremely bogus. Bad Bad Bad. + */ +#if defined(DIAGNOSTIC) && 0 #define SPLUSBCHECK \ do { int _s = splusb(), _su = splusb(); \ if (!cold && _s != _su) printf("SPLUSBCHECK failed 0x%x!=0x%x, %s:%d\n", \ diff --git a/sys/dev/usb/usbhid.h b/sys/dev/usb/usbhid.h index 945fa76ccd4..9a802ec1c9a 100644 --- a/sys/dev/usb/usbhid.h +++ b/sys/dev/usb/usbhid.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbhid.h,v 1.2 2000/03/28 19:37:53 aaron Exp $ */ +/* $OpenBSD: usbhid.h,v 1.3 2000/07/04 11:44:26 fgsch Exp $ */ /* $NetBSD: usbhid.h,v 1.6 1999/11/18 23:32:37 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbhid.h,v 1.7 1999/11/17 22:33:51 n_hibma Exp $ */ @@ -7,7 +7,7 @@ * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Lennart Augustsson (augustss@carlstedt.se) at + * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * Redistribution and use in source and binary forms, with or without @@ -65,7 +65,7 @@ typedef struct usb_hid_descriptor { uByte bDescriptorType; uWord wDescriptorLength; } descrs[1]; -} usb_hid_descriptor_t; +} UPACKED usb_hid_descriptor_t; #define USB_HID_DESCRIPTOR_SIZE(n) (9+(n)*3) /* Usage pages */ |