summaryrefslogtreecommitdiffstats
path: root/sys/dev/usb/serial/ulpt.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/usb/serial/ulpt.c')
-rw-r--r--sys/dev/usb/serial/ulpt.c134
1 files changed, 79 insertions, 55 deletions
diff --git a/sys/dev/usb/serial/ulpt.c b/sys/dev/usb/serial/ulpt.c
index b7b622d..fd21a1d 100644
--- a/sys/dev/usb/serial/ulpt.c
+++ b/sys/dev/usb/serial/ulpt.c
@@ -45,25 +45,39 @@ __FBSDID("$FreeBSD$");
* Printer Class spec: http://www.usb.org/developers/devclass_docs/usbprint11.pdf
*/
-#include "usbdevs.h"
+#include <sys/stdint.h>
+#include <sys/stddef.h>
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/linker_set.h>
+#include <sys/module.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/condvar.h>
+#include <sys/sysctl.h>
+#include <sys/sx.h>
+#include <sys/unistd.h>
+#include <sys/callout.h>
+#include <sys/malloc.h>
+#include <sys/priv.h>
+#include <sys/syslog.h>
+#include <sys/selinfo.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+
#include <dev/usb/usb.h>
-#include <dev/usb/usb_mfunc.h>
-#include <dev/usb/usb_error.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbhid.h>
+#include "usbdevs.h"
#define USB_DEBUG_VAR ulpt_debug
-
-#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_lookup.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_mbuf.h>
-#include <dev/usb/usb_dev.h>
-#include <dev/usb/usb_parse.h>
-
-#include <sys/syslog.h>
#if USB_DEBUG
static int ulpt_debug = 0;
@@ -189,35 +203,38 @@ ulpt_reset(struct ulpt_softc *sc)
}
static void
-ulpt_write_callback(struct usb_xfer *xfer)
+ulpt_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct ulpt_softc *sc = xfer->priv_sc;
+ struct ulpt_softc *sc = usbd_xfer_softc(xfer);
struct usb_fifo *f = sc->sc_fifo_open[USB_FIFO_TX];
- uint32_t actlen;
+ struct usb_page_cache *pc;
+ int actlen, max;
+
+ usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
if (f == NULL) {
/* should not happen */
DPRINTF("no FIFO\n");
return;
}
- DPRINTF("state=0x%x actlen=%u\n",
- USB_GET_STATE(xfer), xfer->actlen);
+ DPRINTF("state=0x%x actlen=%d\n", USB_GET_STATE(xfer), actlen);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
case USB_ST_SETUP:
tr_setup:
- if (usb_fifo_get_data(f, xfer->frbuffers,
- 0, xfer->max_data_length, &actlen, 0)) {
- xfer->frlengths[0] = actlen;
+ pc = usbd_xfer_get_frame(xfer, 0);
+ max = usbd_xfer_max_len(xfer);
+ if (usb_fifo_get_data(f, pc, 0, max, &actlen, 0)) {
+ usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
default: /* Error */
- if (xfer->error != USB_ERR_CANCELLED) {
+ if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
- xfer->flags.stall_pipe = 1;
+ usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@@ -225,10 +242,14 @@ tr_setup:
}
static void
-ulpt_read_callback(struct usb_xfer *xfer)
+ulpt_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct ulpt_softc *sc = xfer->priv_sc;
+ struct ulpt_softc *sc = usbd_xfer_softc(xfer);
struct usb_fifo *f = sc->sc_fifo_open[USB_FIFO_RX];
+ struct usb_page_cache *pc;
+ int actlen;
+
+ usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
if (f == NULL) {
/* should not happen */
@@ -240,40 +261,40 @@ ulpt_read_callback(struct usb_xfer *xfer)
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
- if (xfer->actlen == 0) {
+ if (actlen == 0) {
if (sc->sc_zlps == 4) {
/* enable BULK throttle */
- xfer->interval = 500; /* ms */
+ usbd_xfer_set_interval(xfer, 500); /* ms */
} else {
sc->sc_zlps++;
}
} else {
/* disable BULK throttle */
- xfer->interval = 0;
+ usbd_xfer_set_interval(xfer, 0);
sc->sc_zlps = 0;
}
- usb_fifo_put_data(f, xfer->frbuffers,
- 0, xfer->actlen, 1);
+ pc = usbd_xfer_get_frame(xfer, 0);
+ usb_fifo_put_data(f, pc, 0, actlen, 1);
case USB_ST_SETUP:
tr_setup:
if (usb_fifo_put_bytes_max(f) != 0) {
- xfer->frlengths[0] = xfer->max_data_length;
+ usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
}
break;
default: /* Error */
/* disable BULK throttle */
- xfer->interval = 0;
+ usbd_xfer_set_interval(xfer, 0);
sc->sc_zlps = 0;
- if (xfer->error != USB_ERR_CANCELLED) {
+ if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
- xfer->flags.stall_pipe = 1;
+ usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@@ -281,17 +302,19 @@ tr_setup:
}
static void
-ulpt_status_callback(struct usb_xfer *xfer)
+ulpt_status_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct ulpt_softc *sc = xfer->priv_sc;
+ struct ulpt_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
+ struct usb_page_cache *pc;
uint8_t cur_status;
uint8_t new_status;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
- usbd_copy_out(xfer->frbuffers + 1, 0, &cur_status, 1);
+ pc = usbd_xfer_get_frame(xfer, 1);
+ usbd_copy_out(pc, 0, &cur_status, 1);
cur_status = (cur_status ^ LPS_INVERT) & LPS_MASK;
new_status = cur_status & ~sc->sc_last_status;
@@ -316,17 +339,18 @@ ulpt_status_callback(struct usb_xfer *xfer)
req.wIndex[1] = 0;
USETW(req.wLength, 1);
- usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
+ pc = usbd_xfer_get_frame(xfer, 0);
+ usbd_copy_in(pc, 0, &req, sizeof(req));
- xfer->frlengths[0] = sizeof(req);
- xfer->frlengths[1] = 1;
- xfer->nframes = 2;
+ usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
+ usbd_xfer_set_frame_len(xfer, 1, 1);
+ usbd_xfer_set_frames(xfer, 2);
usbd_transfer_submit(xfer);
break;
default: /* Error */
- DPRINTF("error=%s\n", usbd_errstr(xfer->error));
- if (xfer->error != USB_ERR_CANCELLED) {
+ DPRINTF("error=%s\n", usbd_errstr(error));
+ if (error != USB_ERR_CANCELLED) {
/* wait for next watchdog timeout */
}
break;
@@ -365,7 +389,7 @@ static const struct usb_config ulpt_config[ULPT_N_TRANSFER] = {
static void
ulpt_start_read(struct usb_fifo *fifo)
{
- struct ulpt_softc *sc = fifo->priv_sc0;
+ struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[ULPT_BULK_DT_RD]);
}
@@ -373,7 +397,7 @@ ulpt_start_read(struct usb_fifo *fifo)
static void
ulpt_stop_read(struct usb_fifo *fifo)
{
- struct ulpt_softc *sc = fifo->priv_sc0;
+ struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[ULPT_BULK_DT_RD]);
}
@@ -381,7 +405,7 @@ ulpt_stop_read(struct usb_fifo *fifo)
static void
ulpt_start_write(struct usb_fifo *fifo)
{
- struct ulpt_softc *sc = fifo->priv_sc0;
+ struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[ULPT_BULK_DT_WR]);
}
@@ -389,7 +413,7 @@ ulpt_start_write(struct usb_fifo *fifo)
static void
ulpt_stop_write(struct usb_fifo *fifo)
{
- struct ulpt_softc *sc = fifo->priv_sc0;
+ struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[ULPT_BULK_DT_WR]);
}
@@ -397,7 +421,7 @@ ulpt_stop_write(struct usb_fifo *fifo)
static int
ulpt_open(struct usb_fifo *fifo, int fflags)
{
- struct ulpt_softc *sc = fifo->priv_sc0;
+ struct ulpt_softc *sc = usb_fifo_softc(fifo);
/* we assume that open is a serial process */
@@ -410,7 +434,7 @@ ulpt_open(struct usb_fifo *fifo, int fflags)
static int
unlpt_open(struct usb_fifo *fifo, int fflags)
{
- struct ulpt_softc *sc = fifo->priv_sc0;
+ struct ulpt_softc *sc = usb_fifo_softc(fifo);
if (sc->sc_fflags & fflags) {
return (EBUSY);
@@ -418,10 +442,10 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
if (fflags & FREAD) {
/* clear stall first */
mtx_lock(&sc->sc_mtx);
- usbd_transfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_RD]);
+ usbd_xfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
if (usb_fifo_alloc_buffer(fifo,
- sc->sc_xfer[ULPT_BULK_DT_RD]->max_data_length,
+ usbd_xfer_max_len(sc->sc_xfer[ULPT_BULK_DT_RD]),
ULPT_IFQ_MAXLEN)) {
return (ENOMEM);
}
@@ -431,10 +455,10 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
if (fflags & FWRITE) {
/* clear stall first */
mtx_lock(&sc->sc_mtx);
- usbd_transfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_WR]);
+ usbd_xfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_WR]);
mtx_unlock(&sc->sc_mtx);
if (usb_fifo_alloc_buffer(fifo,
- sc->sc_xfer[ULPT_BULK_DT_WR]->max_data_length,
+ usbd_xfer_max_len(sc->sc_xfer[ULPT_BULK_DT_WR]),
ULPT_IFQ_MAXLEN)) {
return (ENOMEM);
}
@@ -448,7 +472,7 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
static void
ulpt_close(struct usb_fifo *fifo, int fflags)
{
- struct ulpt_softc *sc = fifo->priv_sc0;
+ struct ulpt_softc *sc = usb_fifo_softc(fifo);
sc->sc_fflags &= ~(fflags & (FREAD | FWRITE));
OpenPOWER on IntegriCloud