Lines 113-119
Link Here
|
113 |
int sc_in; |
113 |
int sc_in; |
114 |
usbd_pipe_handle sc_in_pipe; /* bulk in pipe */ |
114 |
usbd_pipe_handle sc_in_pipe; /* bulk in pipe */ |
115 |
usbd_xfer_handle sc_in_xfer; |
115 |
usbd_xfer_handle sc_in_xfer; |
116 |
void *sc_in_buf; |
116 |
char *sc_in_buf; /* start of bulk read buffer */ |
|
|
117 |
char *sc_in_bp; /* start of valid data in sc_in_buf */ |
118 |
int sc_in_len; /* length of valid data at sc_in_bp */ |
117 |
|
119 |
|
118 |
usb_callout_t sc_read_callout; |
120 |
usb_callout_t sc_read_callout; |
119 |
int sc_has_callout; |
121 |
int sc_has_callout; |
Lines 584-589
Link Here
|
584 |
usb_callout(sc->sc_read_callout, hz/5, ulpt_tick, sc); |
586 |
usb_callout(sc->sc_read_callout, hz/5, ulpt_tick, sc); |
585 |
sc->sc_has_callout = 1; |
587 |
sc->sc_has_callout = 1; |
586 |
} |
588 |
} |
|
|
589 |
sc->sc_in_bp = NULL; |
590 |
sc->sc_in_len = 0; |
587 |
} |
591 |
} |
588 |
|
592 |
|
589 |
sc->sc_state = ULPT_OPEN; |
593 |
sc->sc_state = ULPT_OPEN; |
Lines 726-758
Link Here
|
726 |
{ |
730 |
{ |
727 |
u_int32_t n, on; |
731 |
u_int32_t n, on; |
728 |
int error = 0; |
732 |
int error = 0; |
729 |
void *bufp; |
733 |
char *bufp; |
730 |
usbd_xfer_handle xfer; |
734 |
usbd_xfer_handle xfer; |
731 |
usbd_status err; |
735 |
usbd_status err; |
732 |
|
736 |
|
733 |
DPRINTF(("ulptread\n")); |
737 |
DPRINTF(("ulptread request %d\n", uio->uio_resid)); |
734 |
|
738 |
|
735 |
if (sc->sc_in_pipe == NULL) |
739 |
if (sc->sc_in_pipe == NULL) |
736 |
return 0; |
740 |
return 0; |
|
|
741 |
if (sc->sc_in_len != 0) { |
742 |
n = min(sc->sc_in_len, uio->uio_resid); |
743 |
error = uiomove(sc->sc_in_bp, n, uio); |
744 |
if (error) |
745 |
return (error); |
746 |
sc->sc_in_len -= n; |
747 |
sc->sc_in_bp += n; |
748 |
if (uio->uio_resid == 0) /* read satisfied */ |
749 |
return (error); |
750 |
} |
737 |
|
751 |
|
738 |
xfer = sc->sc_in_xfer; |
752 |
xfer = sc->sc_in_xfer; |
739 |
bufp = sc->sc_in_buf; |
753 |
bufp = sc->sc_in_buf; |
740 |
while ((n = min(ULPT_BSIZE, uio->uio_resid)) != 0) { |
754 |
|
741 |
DPRINTFN(1, ("ulptread: transfer %d bytes\n", n)); |
755 |
while (1) { |
742 |
on = n; |
756 |
n = ULPT_BSIZE; |
743 |
err = usbd_bulk_transfer(xfer, sc->sc_in_pipe, |
757 |
err = usbd_bulk_transfer(xfer, sc->sc_in_pipe, |
744 |
USBD_NO_COPY | USBD_SHORT_XFER_OK, |
758 |
USBD_NO_COPY | USBD_SHORT_XFER_OK, |
745 |
USBD_NO_TIMEOUT, bufp, &n, "ulptrd"); |
759 |
USBD_NO_TIMEOUT, bufp, &n, "ulptrd"); |
746 |
if (err) { |
760 |
if (err) { |
747 |
DPRINTF(("ulptread: error=%d\n", err)); |
761 |
DPRINTF(("ulptread: error=%d\n", err)); |
748 |
error = EIO; |
762 |
return (EIO); |
749 |
break; |
|
|
750 |
} |
763 |
} |
751 |
error = uiomove(bufp, n, uio); |
764 |
DPRINTFN(1, ("ulptread: got %d bytes\n", n)); |
752 |
if (error) |
765 |
on = min(n, uio->uio_resid); |
|
|
766 |
error = uiomove(bufp, on, uio); |
767 |
if (error) { |
768 |
sc->sc_in_bp = bufp; |
769 |
sc->sc_in_len = n; |
753 |
break; |
770 |
break; |
754 |
if (on != n) |
771 |
} |
|
|
772 |
if (uio->uio_resid == 0 || n != ULPT_BSIZE) { |
773 |
/* read satisfied or short read from printer */ |
774 |
sc->sc_in_bp = bufp + on; |
775 |
sc->sc_in_len = n - on; |
755 |
break; |
776 |
break; |
|
|
777 |
} |
756 |
} |
778 |
} |
757 |
|
779 |
|
758 |
return (error); |
780 |
return (error); |