1 /* $NetBSD: ulpt.c,v 1.60 2003/10/04 21:19:50 augustss Exp $ */
4 * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
44 * Printer Class spec: http://www.usb.org/developers/data/devclass/usbprint109.PDF
47 #include <sys/param.h>
48 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/fcntl.h>
52 #if defined(__NetBSD__) || defined(__OpenBSD__)
53 #include <sys/device.h>
54 #include <sys/ioctl.h>
55 #elif defined(__FreeBSD__)
56 #include <sys/ioccom.h>
57 #include <sys/module.h>
62 #include <sys/syslog.h>
63 #include <sys/sysctl.h>
65 #include <dev/usb/usb.h>
66 #include <dev/usb/usbdi.h>
67 #include <dev/usb/usbdi_util.h>
69 #include <dev/usb/usb_quirks.h>
71 #define TIMEOUT hz*16 /* wait up to 16 seconds for a ready */
74 #define LPTPRI (PZERO+8)
75 #define ULPT_BSIZE PAGE_SIZE
77 #define ULPT_READS_PER_SEC 5
78 #define ULPT_READ_TIMO 10
81 #define DPRINTF(x) if (ulptdebug) logprintf x
82 #define DPRINTFN(n,x) if (ulptdebug>(n)) logprintf x
84 SYSCTL_NODE(_hw_usb, OID_AUTO, ulpt, CTLFLAG_RW, 0, "USB ulpt");
85 SYSCTL_INT(_hw_usb_ulpt, OID_AUTO, debug, CTLFLAG_RW,
86 &ulptdebug, 0, "ulpt debug level");
92 #define UR_GET_DEVICE_ID 0
93 #define UR_GET_PORT_STATUS 1
94 #define UR_SOFT_RESET 2
96 #define LPS_NERR 0x08 /* printer no error */
97 #define LPS_SELECT 0x10 /* printer selected */
98 #define LPS_NOPAPER 0x20 /* printer out of paper */
99 #define LPS_INVERT (LPS_SELECT|LPS_NERR)
100 #define LPS_MASK (LPS_SELECT|LPS_NERR|LPS_NOPAPER)
104 usbd_device_handle sc_udev; /* device */
105 usbd_interface_handle sc_iface; /* interface */
109 usbd_pipe_handle sc_out_pipe; /* bulk out pipe */
110 usbd_xfer_handle sc_out_xfer;
114 usbd_pipe_handle sc_in_pipe; /* bulk in pipe */
115 usbd_xfer_handle sc_in_xfer;
118 usb_callout_t sc_read_callout;
122 #define ULPT_OPEN 0x01 /* device is open */
123 #define ULPT_OBUSY 0x02 /* printer is busy doing output */
124 #define ULPT_INIT 0x04 /* waiting to initialize for open */
126 #define ULPT_NOPRIME 0x40 /* don't prime on open */
127 u_char sc_laststatus;
132 #if defined(__FreeBSD__)
134 struct cdev *dev_noprime;
138 #if defined(__NetBSD__)
139 dev_type_open(ulptopen);
140 dev_type_close(ulptclose);
141 dev_type_write(ulptwrite);
142 dev_type_read(ulptread);
143 dev_type_ioctl(ulptioctl);
145 const struct cdevsw ulpt_cdevsw = {
146 ulptopen, ulptclose, ulptread, ulptwrite, ulptioctl,
147 nostop, notty, nopoll, nommap, nokqfilter,
149 #elif defined(__OpenBSD__)
151 #elif defined(__FreeBSD__)
152 static d_open_t ulptopen;
153 static d_close_t ulptclose;
154 static d_write_t ulptwrite;
155 static d_read_t ulptread;
156 static d_ioctl_t ulptioctl;
159 static struct cdevsw ulpt_cdevsw = {
160 .d_version = D_VERSION,
161 .d_flags = D_NEEDGIANT,
163 .d_close = ulptclose,
164 .d_write = ulptwrite,
166 .d_ioctl = ulptioctl,
168 #if __FreeBSD_version < 500014
174 void ulpt_disco(void *);
176 int ulpt_do_write(struct ulpt_softc *, struct uio *uio, int);
177 int ulpt_do_read(struct ulpt_softc *, struct uio *uio, int);
178 int ulpt_status(struct ulpt_softc *);
179 void ulpt_reset(struct ulpt_softc *);
180 int ulpt_statusmsg(u_char, struct ulpt_softc *);
181 void ulpt_read_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
183 void ulpt_tick(void *xsc);
186 void ieee1284_print_id(char *);
189 #define ULPTUNIT(s) (minor(s) & 0x1f)
190 #define ULPTFLAGS(s) (minor(s) & 0xe0)
193 USB_DECLARE_DRIVER(ulpt);
197 USB_MATCH_START(ulpt, uaa);
198 usb_interface_descriptor_t *id;
200 DPRINTFN(10,("ulpt_match\n"));
201 if (uaa->iface == NULL)
202 return (UMATCH_NONE);
203 id = usbd_get_interface_descriptor(uaa->iface);
205 id->bInterfaceClass == UICLASS_PRINTER &&
206 id->bInterfaceSubClass == UISUBCLASS_PRINTER &&
207 (id->bInterfaceProtocol == UIPROTO_PRINTER_UNI ||
208 id->bInterfaceProtocol == UIPROTO_PRINTER_BI ||
209 id->bInterfaceProtocol == UIPROTO_PRINTER_1284))
210 return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
211 return (UMATCH_NONE);
216 USB_ATTACH_START(ulpt, sc, uaa);
217 usbd_device_handle dev = uaa->device;
218 usbd_interface_handle iface = uaa->iface;
219 usb_interface_descriptor_t *ifcd = usbd_get_interface_descriptor(iface);
220 usb_interface_descriptor_t *id, *iend;
221 usb_config_descriptor_t *cdesc;
224 usb_endpoint_descriptor_t *ed;
228 DPRINTFN(10,("ulpt_attach: sc=%p\n", sc));
229 usbd_devinfo(uaa->device, USBD_SHOW_INTERFACE_CLASS, devinfo);
233 * Stepping through the alternate settings needs to be abstracted out.
235 cdesc = usbd_get_config_descriptor(dev);
237 printf("%s: failed to get configuration descriptor\n",
238 device_get_nameunit(sc->sc_dev));
239 USB_ATTACH_ERROR_RETURN;
241 iend = (usb_interface_descriptor_t *)
242 ((char *)cdesc + UGETW(cdesc->wTotalLength));
244 if (ifcd < (usb_interface_descriptor_t *)cdesc ||
246 panic("ulpt: iface desc out of range");
248 /* Step through all the descriptors looking for bidir mode */
249 for (id = ifcd, altno = 0;
251 id = (void *)((char *)id + id->bLength)) {
252 if (id->bDescriptorType == UDESC_INTERFACE &&
253 id->bInterfaceNumber == ifcd->bInterfaceNumber) {
254 if (id->bInterfaceClass == UICLASS_PRINTER &&
255 id->bInterfaceSubClass == UISUBCLASS_PRINTER &&
256 (id->bInterfaceProtocol == UIPROTO_PRINTER_BI /* ||
257 id->bInterfaceProtocol == UIPROTO_PRINTER_1284 */))
262 id = ifcd; /* not found, use original */
265 /* Found a new bidir setting */
266 DPRINTF(("ulpt_attach: set altno = %d\n", altno));
267 err = usbd_set_interface(iface, altno);
269 printf("%s: setting alternate interface failed\n",
270 device_get_nameunit(sc->sc_dev));
272 USB_ATTACH_ERROR_RETURN;
277 (void)usbd_endpoint_count(iface, &epcount);
281 for (i = 0; i < epcount; i++) {
282 ed = usbd_interface2endpoint_descriptor(iface, i);
284 printf("%s: couldn't get ep %d\n",
285 device_get_nameunit(sc->sc_dev), i);
286 USB_ATTACH_ERROR_RETURN;
288 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
289 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
290 sc->sc_in = ed->bEndpointAddress;
291 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
292 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
293 sc->sc_out = ed->bEndpointAddress;
296 if (sc->sc_out == -1) {
297 printf("%s: could not find bulk out endpoint\n",
298 device_get_nameunit(sc->sc_dev));
300 USB_ATTACH_ERROR_RETURN;
303 if (usbd_get_quirks(dev)->uq_flags & UQ_BROKEN_BIDIR) {
304 /* This device doesn't handle reading properly. */
308 printf("%s: using %s-directional mode\n", device_get_nameunit(sc->sc_dev),
309 sc->sc_in >= 0 ? "bi" : "uni");
311 DPRINTFN(10, ("ulpt_attach: bulk=%d\n", sc->sc_out));
313 sc->sc_iface = iface;
314 sc->sc_ifaceno = id->bInterfaceNumber;
319 * This code is disabled because for some mysterious reason it causes
320 * printing not to work. But only sometimes, and mostly with
321 * UHCI and less often with OHCI. *sigh*
324 usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev);
325 usb_device_request_t req;
328 req.bmRequestType = UT_READ_CLASS_INTERFACE;
329 req.bRequest = UR_GET_DEVICE_ID;
330 USETW(req.wValue, cd->bConfigurationValue);
331 USETW2(req.wIndex, id->bInterfaceNumber, id->bAlternateSetting);
332 USETW(req.wLength, sizeof devinfo - 1);
333 err = usbd_do_request_flags(dev, &req, devinfo, USBD_SHORT_XFER_OK,
334 &alen, USBD_DEFAULT_TIMEOUT);
336 printf("%s: cannot get device id\n", device_get_nameunit(sc->sc_dev));
337 } else if (alen <= 2) {
338 printf("%s: empty device id, no printer connected?\n",
339 device_get_nameunit(sc->sc_dev));
341 /* devinfo now contains an IEEE-1284 device ID */
342 len = ((devinfo[0] & 0xff) << 8) | (devinfo[1] & 0xff);
343 if (len > sizeof devinfo - 3)
344 len = sizeof devinfo - 3;
346 printf("%s: device id <", device_get_nameunit(sc->sc_dev));
347 ieee1284_print_id(devinfo+2);
353 #if defined(__FreeBSD__)
354 sc->dev = make_dev(&ulpt_cdevsw, device_get_unit(self),
355 UID_ROOT, GID_OPERATOR, 0644, "ulpt%d", device_get_unit(self));
356 sc->dev_noprime = make_dev(&ulpt_cdevsw,
357 device_get_unit(self)|ULPT_NOPRIME,
358 UID_ROOT, GID_OPERATOR, 0644, "unlpt%d", device_get_unit(self));
361 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
364 USB_ATTACH_SUCCESS_RETURN;
367 #if defined(__NetBSD__) || defined(__OpenBSD__)
369 ulpt_activate(device_t self, enum devact act)
371 struct ulpt_softc *sc = (struct ulpt_softc *)self;
377 case DVACT_DEACTIVATE:
387 USB_DETACH_START(ulpt, sc);
389 #if defined(__NetBSD__) || defined(__OpenBSD__)
393 #if defined(__NetBSD__) || defined(__OpenBSD__)
394 DPRINTF(("ulpt_detach: sc=%p flags=%d\n", sc, flags));
395 #elif defined(__FreeBSD__)
396 DPRINTF(("ulpt_detach: sc=%p\n", sc));
400 if (sc->sc_out_pipe != NULL)
401 usbd_abort_pipe(sc->sc_out_pipe);
402 if (sc->sc_in_pipe != NULL)
403 usbd_abort_pipe(sc->sc_in_pipe);
406 if (--sc->sc_refcnt >= 0) {
407 /* There is noone to wake, aborting the pipe is enough */
408 /* Wait for processes to go away. */
409 usb_detach_wait(USBDEV(sc->sc_dev));
413 #if defined(__NetBSD__) || defined(__OpenBSD__)
414 /* locate the major number */
415 #if defined(__NetBSD__)
416 maj = cdevsw_lookup_major(&ulpt_cdevsw);
417 #elif defined(__OpenBSD__)
418 for (maj = 0; maj < nchrdev; maj++)
419 if (cdevsw[maj].d_open == ulptopen)
423 /* Nuke the vnodes for any open instances (calls close). */
425 vdevgone(maj, mn, mn, VCHR);
426 #elif defined(__FreeBSD__)
427 destroy_dev(sc->dev);
428 destroy_dev(sc->dev_noprime);
431 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
438 ulpt_status(struct ulpt_softc *sc)
440 usb_device_request_t req;
444 req.bmRequestType = UT_READ_CLASS_INTERFACE;
445 req.bRequest = UR_GET_PORT_STATUS;
446 USETW(req.wValue, 0);
447 USETW(req.wIndex, sc->sc_ifaceno);
448 USETW(req.wLength, 1);
449 err = usbd_do_request(sc->sc_udev, &req, &status);
450 DPRINTFN(1, ("ulpt_status: status=0x%02x err=%d\n", status, err));
458 ulpt_reset(struct ulpt_softc *sc)
460 usb_device_request_t req;
462 DPRINTFN(1, ("ulpt_reset\n"));
463 req.bRequest = UR_SOFT_RESET;
464 USETW(req.wValue, 0);
465 USETW(req.wIndex, sc->sc_ifaceno);
466 USETW(req.wLength, 0);
469 * There was a mistake in the USB printer 1.0 spec that gave the
470 * request type as UT_WRITE_CLASS_OTHER; it should have been
471 * UT_WRITE_CLASS_INTERFACE. Many printers use the old one,
474 req.bmRequestType = UT_WRITE_CLASS_OTHER;
475 if (usbd_do_request(sc->sc_udev, &req, 0)) { /* 1.0 */
476 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
477 (void)usbd_do_request(sc->sc_udev, &req, 0); /* 1.1 */
482 ulpt_input(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
484 struct ulpt_softc *sc = priv;
487 /* Don't loop on errors or 0-length input. */
488 usbd_get_xfer_status(xfer, NULL, NULL, &count, NULL);
489 if (status != USBD_NORMAL_COMPLETION || count == 0)
492 DPRINTFN(2,("ulpt_input: got some data\n"));
494 if (xfer == sc->sc_in_xfer1)
495 usbd_transfer(sc->sc_in_xfer2);
497 usbd_transfer(sc->sc_in_xfer1);
504 * Reset the printer, then wait until it's selected and not busy.
507 ulptopen(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
509 u_char flags = ULPTFLAGS(dev);
510 struct ulpt_softc *sc;
514 USB_GET_SC_OPEN(ulpt, ULPTUNIT(dev), sc);
516 if (sc == NULL || sc->sc_iface == NULL || sc->sc_dying)
522 sc->sc_state = ULPT_INIT;
523 sc->sc_flags = flags;
524 DPRINTF(("ulptopen: flags=0x%x\n", (unsigned)flags));
526 #if defined(USB_DEBUG) && defined(__FreeBSD__)
527 /* Ignoring these flags might not be a good idea */
528 if ((flags & ~ULPT_NOPRIME) != 0)
529 printf("ulptopen: flags ignored: %b\n", flags,
530 "\20\3POS_INIT\4POS_ACK\6PRIME_OPEN\7AUTOLF\10BYPASS");
537 if ((flags & ULPT_NOPRIME) == 0) {
546 err = usbd_open_pipe(sc->sc_iface, sc->sc_out, 0, &sc->sc_out_pipe);
551 sc->sc_out_xfer = usbd_alloc_xfer(sc->sc_udev);
552 if (sc->sc_out_xfer == NULL) {
556 sc->sc_out_buf = usbd_alloc_buffer(sc->sc_out_xfer, ULPT_BSIZE);
557 if (sc->sc_out_buf == NULL) {
562 if (ulptusein && sc->sc_in != -1) {
563 DPRINTF(("ulpt_open: open input pipe\n"));
564 err = usbd_open_pipe(sc->sc_iface, sc->sc_in,0,&sc->sc_in_pipe);
569 sc->sc_in_xfer = usbd_alloc_xfer(sc->sc_udev);
570 if (sc->sc_in_xfer == NULL) {
574 sc->sc_in_buf = usbd_alloc_buffer(sc->sc_in_xfer, ULPT_BSIZE);
575 if (sc->sc_in_buf == NULL) {
580 /* If it's not opened for read the set up a reader. */
581 if (!(flag & FREAD)) {
582 DPRINTF(("ulpt_open: start read callout\n"));
583 usb_callout_init(sc->sc_read_callout);
584 usb_callout(sc->sc_read_callout, hz/5, ulpt_tick, sc);
585 sc->sc_has_callout = 1;
589 sc->sc_state = ULPT_OPEN;
593 usbd_free_xfer(sc->sc_in_xfer);
594 sc->sc_in_xfer = NULL;
596 usbd_close_pipe(sc->sc_in_pipe);
597 sc->sc_in_pipe = NULL;
599 usbd_free_xfer(sc->sc_out_xfer);
600 sc->sc_out_xfer = NULL;
602 usbd_close_pipe(sc->sc_out_pipe);
603 sc->sc_out_pipe = NULL;
608 if (--sc->sc_refcnt < 0)
609 usb_detach_wakeup(USBDEV(sc->sc_dev));
611 DPRINTF(("ulptopen: done, error=%d\n", error));
616 ulpt_statusmsg(u_char status, struct ulpt_softc *sc)
620 status = (status ^ LPS_INVERT) & LPS_MASK;
621 new = status & ~sc->sc_laststatus;
622 sc->sc_laststatus = status;
624 if (new & LPS_SELECT)
625 log(LOG_NOTICE, "%s: offline\n", device_get_nameunit(sc->sc_dev));
626 else if (new & LPS_NOPAPER)
627 log(LOG_NOTICE, "%s: out of paper\n", device_get_nameunit(sc->sc_dev));
628 else if (new & LPS_NERR)
629 log(LOG_NOTICE, "%s: output error\n", device_get_nameunit(sc->sc_dev));
635 ulptclose(struct cdev *dev, int flag, int mode, usb_proc_ptr p)
637 struct ulpt_softc *sc;
639 USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
641 if (sc->sc_state != ULPT_OPEN)
642 /* We are being forced to close before the open completed. */
645 if (sc->sc_has_callout) {
646 usb_uncallout(sc->sc_read_callout, ulpt_tick, sc);
647 sc->sc_has_callout = 0;
650 if (sc->sc_out_pipe != NULL) {
651 usbd_abort_pipe(sc->sc_out_pipe);
652 usbd_close_pipe(sc->sc_out_pipe);
653 sc->sc_out_pipe = NULL;
655 if (sc->sc_out_xfer != NULL) {
656 usbd_free_xfer(sc->sc_out_xfer);
657 sc->sc_out_xfer = NULL;
660 if (sc->sc_in_pipe != NULL) {
661 usbd_abort_pipe(sc->sc_in_pipe);
662 usbd_close_pipe(sc->sc_in_pipe);
663 sc->sc_in_pipe = NULL;
665 if (sc->sc_in_xfer != NULL) {
666 usbd_free_xfer(sc->sc_in_xfer);
667 sc->sc_in_xfer = NULL;
672 DPRINTF(("ulptclose: closed\n"));
677 ulpt_do_write(struct ulpt_softc *sc, struct uio *uio, int flags)
682 usbd_xfer_handle xfer;
685 DPRINTF(("ulptwrite\n"));
686 xfer = sc->sc_out_xfer;
687 bufp = sc->sc_out_buf;
688 while ((n = min(ULPT_BSIZE, uio->uio_resid)) != 0) {
689 ulpt_statusmsg(ulpt_status(sc), sc);
690 error = uiomove(bufp, n, uio);
693 DPRINTFN(1, ("ulptwrite: transfer %d bytes\n", n));
694 err = usbd_bulk_transfer(xfer, sc->sc_out_pipe, USBD_NO_COPY,
695 USBD_NO_TIMEOUT, bufp, &n, "ulptwr");
697 DPRINTF(("ulptwrite: error=%d\n", err));
707 ulptwrite(struct cdev *dev, struct uio *uio, int flags)
709 struct ulpt_softc *sc;
712 USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
718 error = ulpt_do_write(sc, uio, flags);
719 if (--sc->sc_refcnt < 0)
720 usb_detach_wakeup(USBDEV(sc->sc_dev));
725 ulpt_do_read(struct ulpt_softc *sc, struct uio *uio, int flags)
730 usbd_xfer_handle xfer;
733 DPRINTF(("ulptread\n"));
735 if (sc->sc_in_pipe == NULL)
738 xfer = sc->sc_in_xfer;
739 bufp = sc->sc_in_buf;
740 while ((n = min(ULPT_BSIZE, uio->uio_resid)) != 0) {
741 DPRINTFN(1, ("ulptread: transfer %d bytes\n", n));
743 err = usbd_bulk_transfer(xfer, sc->sc_in_pipe,
744 USBD_NO_COPY | USBD_SHORT_XFER_OK,
745 USBD_NO_TIMEOUT, bufp, &n, "ulptrd");
747 DPRINTF(("ulptread: error=%d\n", err));
751 error = uiomove(bufp, n, uio);
762 ulptread(struct cdev *dev, struct uio *uio, int flags)
764 struct ulpt_softc *sc;
767 USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
773 error = ulpt_do_read(sc, uio, flags);
774 if (--sc->sc_refcnt < 0)
775 usb_detach_wakeup(USBDEV(sc->sc_dev));
780 ulpt_read_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
785 usbd_private_handle xsc;
786 struct ulpt_softc *sc;
788 usbd_get_xfer_status(xfer, &xsc, NULL, &n, &err);
791 DPRINTFN(1,("ulpt_read_cb: start sc=%p, err=%d n=%d\n", sc, err, n));
795 DPRINTF(("ulpt_tick: discarding %d bytes\n", n));
797 if (!err || err == USBD_TIMEOUT)
798 usb_callout(sc->sc_read_callout, hz / ULPT_READS_PER_SEC,
805 struct ulpt_softc *sc = xsc;
808 if (sc == NULL || sc->sc_dying)
811 DPRINTFN(1,("ulpt_tick: start sc=%p\n", sc));
813 usbd_setup_xfer(sc->sc_in_xfer, sc->sc_in_pipe, sc, sc->sc_in_buf,
814 ULPT_BSIZE, USBD_NO_COPY | USBD_SHORT_XFER_OK,
815 ULPT_READ_TIMO, ulpt_read_cb);
816 err = usbd_transfer(sc->sc_in_xfer);
817 DPRINTFN(1,("ulpt_tick: err=%d\n", err));
821 ulptioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
834 /* XXX This does not belong here. */
836 * Print select parts of an IEEE 1284 device ID.
839 ieee1284_print_id(char *str)
843 for (p = str-1; p; p = strchr(p, ';')) {
845 if (strncmp(p, "MFG:", 4) == 0 ||
846 strncmp(p, "MANUFACTURER:", 14) == 0 ||
847 strncmp(p, "MDL:", 4) == 0 ||
848 strncmp(p, "MODEL:", 6) == 0) {
851 printf("%.*s", (int)(q - p + 1), p);
857 #if defined(__FreeBSD__)
858 DRIVER_MODULE(ulpt, uhub, ulpt_driver, ulpt_devclass, usbd_driver_load, 0);