Fully revert f83f5d5839 for the sys/dev/usb/serial

folder, only keeping the zero length packet API introduced in sys/dev/usb
after more reports of USB serial devices not supporting ZLPs.

Reported by:	mav@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
This commit is contained in:
Hans Petter Selasky 2021-08-20 17:59:29 +02:00
parent e3c5965c25
commit ec97e9ca1f
16 changed files with 70 additions and 92 deletions

View File

@ -978,7 +978,8 @@ u3g_attach(device_t dev)
/* set stall by default */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[nports][U3G_BULK_WR]);
usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]);
usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]);
mtx_unlock(&sc->sc_mtx);
nports++; /* found one port */
@ -1099,9 +1100,6 @@ u3g_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_TRANSFERRED:
case USB_ST_SETUP:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
for (frame = 0; frame != U3G_TXFRAMES; frame++) {
usbd_xfer_set_frame_offset(xfer, frame * U3G_TXSIZE, frame);

View File

@ -219,7 +219,8 @@ uark_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UARK_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UARK_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UARK_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -280,16 +281,13 @@ uark_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UARK_BUF_SIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -297,7 +295,7 @@ uark_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -320,7 +320,8 @@ ubsa_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UBSA_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -582,16 +583,13 @@ ubsa_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UBSA_BSIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -599,7 +597,7 @@ ubsa_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -293,7 +293,8 @@ ubser_attach(device_t dev)
ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev);
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UBSER_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_RD]);
usbd_transfer_start(sc->sc_xfer[UBSER_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
@ -409,9 +410,6 @@ ubser_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
do {
if (ucom_get_data(sc->sc_ucom + sc->sc_curr_tx_unit,
@ -432,7 +430,7 @@ ubser_write_callback(struct usb_xfer *xfer, usb_error_t error)
} while (sc->sc_curr_tx_unit != first_unit);
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -440,7 +438,7 @@ ubser_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -350,7 +350,8 @@ uchcom_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UCHCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -827,9 +828,6 @@ uchcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
usbd_xfer_max_len(xfer), &actlen)) {

View File

@ -438,7 +438,8 @@ ufoma_attach(device_t dev)
/* clear stall at first run, if any */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_WRITE]);
usbd_xfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_WRITE]);
usbd_xfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_READ]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -790,16 +791,13 @@ ufoma_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UFOMA_BULK_BUF_SIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -807,7 +805,7 @@ ufoma_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -1118,6 +1118,7 @@ uftdi_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
/* set a valid "lcr" value */

View File

@ -233,8 +233,10 @@ ugensa_attach(device_t dev)
break;
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
usbd_xfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
usbd_xfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
/* initialize port number */
@ -311,16 +313,13 @@ ugensa_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(ssc->sc_ucom_ptr, pc, 0,
UGENSA_BUF_SIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -328,7 +327,7 @@ ugensa_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -1157,7 +1157,8 @@ uipaq_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UIPAQ_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UIPAQ_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UIPAQ_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -1319,16 +1320,13 @@ uipaq_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UIPAQ_BUF_SIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -1336,7 +1334,7 @@ uipaq_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -218,9 +218,6 @@ ulpt_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_TRANSFERRED:
case USB_ST_SETUP:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
max = usbd_xfer_max_len(xfer);
if (usb_fifo_get_data(f, pc, 0, max, &actlen, 0)) {
@ -439,6 +436,10 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
return (EBUSY);
}
if (fflags & FREAD) {
/* clear stall first */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
if (usb_fifo_alloc_buffer(fifo,
usbd_xfer_max_len(sc->sc_xfer[ULPT_BULK_DT_RD]),
ULPT_IFQ_MAXLEN)) {
@ -450,7 +451,7 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
if (fflags & FWRITE) {
/* clear stall first */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(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,
usbd_xfer_max_len(sc->sc_xfer[ULPT_BULK_DT_WR]),

View File

@ -382,7 +382,8 @@ umcs7840_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
for (subunit = 0; subunit < sc->sc_numports; ++subunit) {
usbd_xfer_set_zlp(sc->sc_ports[sc->sc_ucom[subunit].sc_portno].sc_xfer[UMCS7840_BULK_WR_EP]);
usbd_xfer_set_stall(sc->sc_ports[sc->sc_ucom[subunit].sc_portno].sc_xfer[UMCS7840_BULK_RD_EP]);
usbd_xfer_set_stall(sc->sc_ports[sc->sc_ucom[subunit].sc_portno].sc_xfer[UMCS7840_BULK_WR_EP]);
}
mtx_unlock(&sc->sc_mtx);
@ -915,16 +916,13 @@ umcs7840_write_callbackN(struct usb_xfer *xfer, usb_error_t error, uint8_t subun
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(ucom, pc, 0, usbd_xfer_max_len(xfer), &actlen)) {
DPRINTF("Port %d write, has %d bytes\n", ucom->sc_portno, actlen);
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -932,7 +930,7 @@ umcs7840_write_callbackN(struct usb_xfer *xfer, usb_error_t error, uint8_t subun
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -447,10 +447,13 @@ umodem_attach(device_t dev)
goto detach;
}
/* send a ZLP at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UMODEM_BULK_WR]);
mtx_unlock(&sc->sc_mtx);
/* clear stall at first run, if USB host mode */
if (uaa->usb_mode == USB_MODE_HOST) {
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_stall(sc->sc_xfer[UMODEM_BULK_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UMODEM_BULK_RD]);
mtx_unlock(&sc->sc_mtx);
}
ucom_set_usb_mode(&sc->sc_super_ucom, uaa->usb_mode);
@ -860,16 +863,13 @@ umodem_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UMODEM_BUF_SIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -877,7 +877,7 @@ umodem_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -333,7 +333,8 @@ umoscom_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UMOSCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UMOSCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UMOSCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -638,16 +639,13 @@ umoscom_write_callback(struct usb_xfer *xfer, usb_error_t error)
tr_setup:
DPRINTF("\n");
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UMOSCOM_BUFSIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -656,7 +654,7 @@ umoscom_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -507,12 +507,14 @@ uplcom_attach(device_t dev)
goto detach;
}
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UPLCOM_BULK_DT_WR]);
mtx_unlock(&sc->sc_mtx);
if (sc->sc_chiptype == TYPE_PL2303HX ||
sc->sc_chiptype == TYPE_PL2303HXD) {
if (sc->sc_chiptype == TYPE_PL2303) {
/* HX variants seem to lock up after a clear stall request. */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
} else if (sc->sc_chiptype == TYPE_PL2303HX ||
sc->sc_chiptype == TYPE_PL2303HXD) {
/* reset upstream data pipes */
if (uplcom_pl2303_do(sc->sc_udev, UT_WRITE_VENDOR_DEVICE,
UPLCOM_SET_REQUEST, 8, 0, 0) ||
@ -1092,9 +1094,6 @@ uplcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UPLCOM_BULK_BUF_SIZE, &actlen)) {
@ -1103,7 +1102,7 @@ uplcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -1111,7 +1110,7 @@ uplcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -443,7 +443,8 @@ uslcom_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[USLCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
sc->sc_partnum = uslcom_get_partnum(sc);
@ -818,9 +819,6 @@ uslcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
USLCOM_BULK_BUF_SIZE, &actlen)) {
@ -829,7 +827,7 @@ uslcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -837,7 +835,7 @@ uslcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}

View File

@ -318,7 +318,8 @@ uvscom_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_xfer_set_zlp(sc->sc_xfer[UVSCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UVSCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UVSCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -390,16 +391,13 @@ uvscom_write_callback(struct usb_xfer *xfer, usb_error_t error)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (usbd_xfer_get_and_clr_zlp(xfer))
break;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UVSCOM_BULK_BUF_SIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
return;
default: /* Error */
if (error != USB_ERR_CANCELLED) {
@ -407,7 +405,7 @@ uvscom_write_callback(struct usb_xfer *xfer, usb_error_t error)
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
return;
}
}