summaryrefslogtreecommitdiffstats
path: root/sys/dev/ata
diff options
context:
space:
mode:
authorthompsa <thompsa@FreeBSD.org>2009-06-23 02:19:59 +0000
committerthompsa <thompsa@FreeBSD.org>2009-06-23 02:19:59 +0000
commit74c6c20b93f0513a453c6544f8b98ad55cbdc741 (patch)
treeee5c9acfe716a9835136731811e9e1a68751e278 /sys/dev/ata
parent52922c0742bc8545734b2903d6407b99664e84ed (diff)
downloadFreeBSD-src-74c6c20b93f0513a453c6544f8b98ad55cbdc741.zip
FreeBSD-src-74c6c20b93f0513a453c6544f8b98ad55cbdc741.tar.gz
- Make struct usb_xfer opaque so that drivers can not access the internals
- Reduce the number of headers needed for a usb driver, the common case is just usb.h and usbdi.h
Diffstat (limited to 'sys/dev/ata')
-rw-r--r--sys/dev/ata/ata-usb.c170
1 files changed, 99 insertions, 71 deletions
diff --git a/sys/dev/ata/ata-usb.c b/sys/dev/ata/ata-usb.c
index 289d4a7..a08b80a 100644
--- a/sys/dev/ata/ata-usb.c
+++ b/sys/dev/ata/ata-usb.c
@@ -30,18 +30,30 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#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 <machine/bus.h>
+
#include "usbdevs.h"
#include <dev/usb/usb.h>
-#include <dev/usb/usb_mfunc.h>
-#include <dev/usb/usb_error.h>
-
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
+#include <dev/usb/usbdi.h>
#include <sys/ata.h>
#include <sys/bio.h>
@@ -145,7 +157,8 @@ static usb_callback_t atausb2_tr_error;
static void atausb2_cancel_request(struct atausb2_softc *sc);
static void atausb2_transfer_start(struct atausb2_softc *sc, uint8_t xfer_no);
-static void atausb2_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer, uint8_t next_xfer, uint8_t stall_xfer);
+static void atausb2_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer,
+ uint8_t next_xfer, uint8_t stall_xfer, usb_error_t error);
static int ata_usbchannel_begin_transaction(struct ata_request *request);
static int ata_usbchannel_end_transaction(struct ata_request *request);
@@ -467,10 +480,11 @@ atausb2_transfer_start(struct atausb2_softc *sc, uint8_t xfer_no)
}
static void
-atausb2_t_bbb_reset1_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_reset1_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct atausb2_softc *sc = xfer->priv_sc;
+ struct atausb2_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
+ struct usb_page_cache *pc;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@@ -485,40 +499,40 @@ atausb2_t_bbb_reset1_callback(struct usb_xfer *xfer)
req.wIndex[1] = 0;
USETW(req.wLength, 0);
- 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->nframes = 1;
+ usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
+ usbd_xfer_set_frames(xfer, 1);
usbd_transfer_submit(xfer);
return;
default: /* Error */
- atausb2_tr_error(xfer);
+ atausb2_tr_error(xfer, error);
return;
}
}
static void
-atausb2_t_bbb_reset2_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_reset2_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_RESET3,
- ATAUSB_T_BBB_DATA_READ);
+ ATAUSB_T_BBB_DATA_READ, error);
}
static void
-atausb2_t_bbb_reset3_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_reset3_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_COMMAND,
- ATAUSB_T_BBB_DATA_WRITE);
+ ATAUSB_T_BBB_DATA_WRITE, error);
}
static void
atausb2_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer,
- uint8_t next_xfer,
- uint8_t stall_xfer)
+ uint8_t next_xfer, uint8_t stall_xfer, usb_error_t error)
{
- struct atausb2_softc *sc = xfer->priv_sc;
+ struct atausb2_softc *sc = usbd_xfer_softc(xfer);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@@ -533,18 +547,19 @@ tr_transferred:
return;
default: /* Error */
- atausb2_tr_error(xfer);
+ atausb2_tr_error(xfer, error);
return;
}
}
static void
-atausb2_t_bbb_command_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_command_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct atausb2_softc *sc = xfer->priv_sc;
+ struct atausb2_softc *sc = usbd_xfer_softc(xfer);
struct ata_request *request = sc->ata_request;
struct ata_channel *ch;
+ struct usb_page_cache *pc;
uint32_t tag;
switch (USB_GET_STATE(xfer)) {
@@ -575,37 +590,42 @@ atausb2_t_bbb_command_callback(struct usb_xfer *xfer)
bzero(sc->cbw.cdb, 16);
bcopy(request->u.atapi.ccb, sc->cbw.cdb, 12); /* XXX SOS */
- usbd_copy_in(xfer->frbuffers, 0, &sc->cbw, sizeof(sc->cbw));
+ pc = usbd_xfer_get_frame(xfer, 0);
+ usbd_copy_in(pc, 0, &sc->cbw, sizeof(sc->cbw));
- xfer->frlengths[0] = sizeof(sc->cbw);
+ usbd_xfer_set_frame_len(xfer, 0, sizeof(sc->cbw));
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
- atausb2_tr_error(xfer);
+ atausb2_tr_error(xfer, error);
return;
}
}
static void
-atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct atausb2_softc *sc = xfer->priv_sc;
- uint32_t max_bulk = xfer->max_data_length;
+ struct atausb2_softc *sc = usbd_xfer_softc(xfer);
+ uint32_t max_bulk = usbd_xfer_max_len(xfer);
+ struct usb_page_cache *pc;
+ int actlen, sumlen;
+
+ usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
- usbd_copy_out(xfer->frbuffers, 0,
- sc->ata_data, xfer->actlen);
+ pc = usbd_xfer_get_frame(xfer, 0);
+ usbd_copy_out(pc, 0, sc->ata_data, actlen);
- sc->ata_bytecount -= xfer->actlen;
- sc->ata_data += xfer->actlen;
- sc->ata_donecount += xfer->actlen;
+ sc->ata_bytecount -= actlen;
+ sc->ata_data += actlen;
+ sc->ata_donecount += actlen;
- if (xfer->actlen < xfer->sumlen) {
+ if (actlen < sumlen) {
/* short transfer */
sc->ata_bytecount = 0;
}
@@ -622,15 +642,15 @@ atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer)
if (max_bulk > sc->ata_bytecount) {
max_bulk = sc->ata_bytecount;
}
- xfer->timeout = sc->timeout;
- xfer->frlengths[0] = max_bulk;
+ usbd_xfer_set_timeout(xfer, sc->timeout);
+ usbd_xfer_set_frame_len(xfer, 0, max_bulk);
usbd_transfer_submit(xfer);
return;
default: /* Error */
- if (xfer->error == USB_ERR_CANCELLED) {
- atausb2_tr_error(xfer);
+ if (error == USB_ERR_CANCELLED) {
+ atausb2_tr_error(xfer, error);
} else {
atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_RD_CS);
}
@@ -640,24 +660,28 @@ atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer)
}
static void
-atausb2_t_bbb_data_rd_cs_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_data_rd_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_STATUS,
- ATAUSB_T_BBB_DATA_READ);
+ ATAUSB_T_BBB_DATA_READ, error);
}
static void
-atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct atausb2_softc *sc = xfer->priv_sc;
- uint32_t max_bulk = xfer->max_data_length;
+ struct atausb2_softc *sc = usbd_xfer_softc(xfer);
+ struct usb_page_cache *pc;
+ uint32_t max_bulk = usbd_xfer_max_len(xfer);
+ int actlen;
+
+ usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
- sc->ata_bytecount -= xfer->actlen;
- sc->ata_data += xfer->actlen;
- sc->ata_donecount += xfer->actlen;
+ sc->ata_bytecount -= actlen;
+ sc->ata_data += actlen;
+ sc->ata_donecount += actlen;
case USB_ST_SETUP:
@@ -672,18 +696,18 @@ atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer)
if (max_bulk > sc->ata_bytecount) {
max_bulk = sc->ata_bytecount;
}
- xfer->timeout = sc->timeout;
- xfer->frlengths[0] = max_bulk;
- usbd_copy_in(xfer->frbuffers, 0,
- sc->ata_data, max_bulk);
+ pc = usbd_xfer_get_frame(xfer, 0);
+ usbd_copy_in(pc, 0, sc->ata_data, max_bulk);
+ usbd_xfer_set_frame_len(xfer, 0, max_bulk);
+ usbd_xfer_set_timeout(xfer, sc->timeout);
usbd_transfer_submit(xfer);
return;
default: /* Error */
- if (xfer->error == USB_ERR_CANCELLED) {
- atausb2_tr_error(xfer);
+ if (error == USB_ERR_CANCELLED) {
+ atausb2_tr_error(xfer, error);
} else {
atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_WR_CS);
}
@@ -693,26 +717,31 @@ atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer)
}
static void
-atausb2_t_bbb_data_wr_cs_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_data_wr_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_STATUS,
- ATAUSB_T_BBB_DATA_WRITE);
+ ATAUSB_T_BBB_DATA_WRITE, error);
}
static void
-atausb2_t_bbb_status_callback(struct usb_xfer *xfer)
+atausb2_t_bbb_status_callback(struct usb_xfer *xfer, usb_error_t error)
{
- struct atausb2_softc *sc = xfer->priv_sc;
+ struct atausb2_softc *sc = usbd_xfer_softc(xfer);
struct ata_request *request = sc->ata_request;
+ struct usb_page_cache *pc;
uint32_t residue;
+ int actlen;
+
+ usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
- if (xfer->actlen < sizeof(sc->csw)) {
+ if (actlen < sizeof(sc->csw)) {
bzero(&sc->csw, sizeof(sc->csw));
}
- usbd_copy_out(xfer->frbuffers, 0, &sc->csw, xfer->actlen);
+ pc = usbd_xfer_get_frame(xfer, 0);
+ usbd_copy_out(pc, 0, &sc->csw, actlen);
if (request->flags & (ATA_R_READ | ATA_R_WRITE)) {
request->donecount = sc->ata_donecount;
@@ -779,15 +808,14 @@ atausb2_t_bbb_status_callback(struct usb_xfer *xfer)
return;
case USB_ST_SETUP:
- xfer->frlengths[0] = xfer->max_data_length;
+ usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default:
tr_error:
- if ((xfer->error == USB_ERR_CANCELLED) ||
- (sc->status_try)) {
- atausb2_tr_error(xfer);
+ if (error == USB_ERR_CANCELLED || sc->status_try) {
+ atausb2_tr_error(xfer, error);
} else {
sc->status_try = 1;
atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_RD_CS);
@@ -820,15 +848,15 @@ atausb2_cancel_request(struct atausb2_softc *sc)
}
static void
-atausb2_tr_error(struct usb_xfer *xfer)
+atausb2_tr_error(struct usb_xfer *xfer, usb_error_t error)
{
- struct atausb2_softc *sc = xfer->priv_sc;
+ struct atausb2_softc *sc = usbd_xfer_softc(xfer);
- if (xfer->error != USB_ERR_CANCELLED) {
+ if (error != USB_ERR_CANCELLED) {
if (atausbdebug) {
device_printf(sc->dev, "transfer failed, %s, in state %d "
- "-> BULK reset\n", usbd_errstr(xfer->error),
+ "-> BULK reset\n", usbd_errstr(error),
sc->last_xfer_no);
}
}
OpenPOWER on IntegriCloud