From owner-p4-projects@FreeBSD.ORG Sun Sep 21 14:45:27 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 47E6C106569D; Sun, 21 Sep 2008 14:45:27 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0A7FB1065689 for ; Sun, 21 Sep 2008 14:45:27 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id ED6258FC64 for ; Sun, 21 Sep 2008 14:45:26 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m8LEjPoH058951 for ; Sun, 21 Sep 2008 14:45:25 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m8LEjPTt058945 for perforce@freebsd.org; Sun, 21 Sep 2008 14:45:25 GMT (envelope-from hselasky@FreeBSD.org) Date: Sun, 21 Sep 2008 14:45:25 GMT Message-Id: <200809211445.m8LEjPTt058945@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 150210 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Sep 2008 14:45:27 -0000 http://perforce.freebsd.org/chv.cgi?CH=150210 Change 150210 by hselasky@hselasky_laptop001 on 2008/09/21 14:45:03 usb2_fifo_opened() returns the wrong value when the FIFOs are being flushed. Store a pointer to the last opened FIFO instead, because "ulpt" has two devices: /dev/ulptX and /dev/unlptX and only one can be opened at a time. Affected files ... .. //depot/projects/usb/src/sys/dev/usb2/serial/ulpt2.c#7 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb2/serial/ulpt2.c#7 (text+ko) ==== @@ -96,6 +96,7 @@ device_t sc_dev; struct usb2_device *sc_udev; + struct usb2_fifo *sc_fifo_open[2]; struct usb2_xfer *sc_xfer[ULPT_N_TRANSFER]; int sc_fflags; /* current open flags, FREAD and @@ -125,7 +126,6 @@ static void ulpt_reset(struct ulpt_softc *sc); static void ulpt_watchdog(void *arg); -static struct usb2_fifo *ulpt_find_fifo(struct ulpt_softc *sc, uint8_t dir); static usb2_fifo_close_t ulpt_close; static usb2_fifo_cmd_t ulpt_start_read; @@ -191,30 +191,26 @@ return; } -static struct usb2_fifo * -ulpt_find_fifo(struct ulpt_softc *sc, uint8_t dir) -{ - if (usb2_fifo_opened(sc->sc_fifo.fp[dir])) { - return (sc->sc_fifo.fp[dir]); - } - /* else we assume that the other FIFO is opened */ - return (sc->sc_fifo_noreset.fp[dir]); -} - - static void ulpt_write_callback(struct usb2_xfer *xfer) { struct ulpt_softc *sc = xfer->priv_sc; - struct usb2_fifo *f = ulpt_find_fifo(sc, USB_FIFO_TX); + struct usb2_fifo *f = sc->sc_fifo_open[USB_FIFO_TX]; uint32_t actlen; + if (f == NULL) { + /* should not happen */ + DPRINTF("no FIFO\n"); + return; + } + DPRINTF("state=0x%x\n", USB_GET_STATE(xfer)); + switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: case USB_ST_SETUP: if (sc->sc_flags & ULPT_FLAG_WRITE_STALL) { usb2_transfer_start(sc->sc_xfer[3]); - return; + break; } if (usb2_fifo_get_data(f, xfer->frbuffers, 0, xfer->max_data_length, &actlen, 0)) { @@ -222,7 +218,7 @@ xfer->frlengths[0] = actlen; usb2_start_hardware(xfer); } - return; + break; default: /* Error */ if (xfer->error != USB_ERR_CANCELLED) { @@ -230,8 +226,9 @@ sc->sc_flags |= ULPT_FLAG_WRITE_STALL; usb2_transfer_start(sc->sc_xfer[3]); } - return; + break; } + return; } static void @@ -252,7 +249,14 @@ ulpt_read_callback(struct usb2_xfer *xfer) { struct ulpt_softc *sc = xfer->priv_sc; - struct usb2_fifo *f = ulpt_find_fifo(sc, USB_FIFO_RX); + struct usb2_fifo *f = sc->sc_fifo_open[USB_FIFO_RX]; + + if (f == NULL) { + /* should not happen */ + DPRINTF("no FIFO\n"); + return; + } + DPRINTF("state=0x%x\n", USB_GET_STATE(xfer)); switch (USB_GET_STATE(xfer)) { case USB_ST_TRANSFERRED: @@ -278,13 +282,13 @@ case USB_ST_SETUP: if (sc->sc_flags & ULPT_FLAG_READ_STALL) { usb2_transfer_start(sc->sc_xfer[4]); - return; + break; } if (usb2_fifo_put_bytes_max(f) != 0) { xfer->frlengths[0] = xfer->max_data_length; usb2_start_hardware(xfer); } - return; + break; default: /* Error */ /* disable BULK throttle */ @@ -296,8 +300,9 @@ sc->sc_flags |= ULPT_FLAG_READ_STALL; usb2_transfer_start(sc->sc_xfer[4]); } - return; + break; } + return; } static void @@ -486,6 +491,8 @@ ULPT_IFQ_MAXLEN)) { return (ENOMEM); } + /* set which FIFO is opened */ + sc->sc_fifo_open[USB_FIFO_RX] = fifo; } if (fflags & FWRITE) { /* clear stall first */ @@ -497,6 +504,8 @@ ULPT_IFQ_MAXLEN)) { return (ENOMEM); } + /* set which FIFO is opened */ + sc->sc_fifo_open[USB_FIFO_TX] = fifo; } sc->sc_fflags |= fflags & (FREAD | FWRITE); return (0);