Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Define a new structure to store wire specific co...



details:   https://anonhg.NetBSD.org/src/rev/139647a8fc1b
branches:  trunk
changeset: 519273:139647a8fc1b
user:      gehenna <gehenna%NetBSD.org@localhost>
date:      Fri Dec 14 08:46:19 2001 +0000

description:
Define a new structure to store wire specific control methods.
The basic BBB/CBI functions are stored as members of constant structure.
When attached device, softc holds one of that constant structures.

diffstat:

 sys/dev/usb/umass.c    |  63 +++++++++++++++++++++++++------------------------
 sys/dev/usb/umassbus.c |  28 ++++++++++++---------
 sys/dev/usb/umassvar.h |  38 +++++++++++------------------
 3 files changed, 63 insertions(+), 66 deletions(-)

diffs (266 lines):

diff -r 6ffa6f8f489f -r 139647a8fc1b sys/dev/usb/umass.c
--- a/sys/dev/usb/umass.c       Fri Dec 14 08:39:11 2001 +0000
+++ b/sys/dev/usb/umass.c       Fri Dec 14 08:46:19 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umass.c,v 1.74 2001/12/14 06:21:56 gehenna Exp $       */
+/*     $NetBSD: umass.c,v 1.75 2001/12/14 08:46:19 gehenna Exp $       */
 /*-
  * Copyright (c) 1999 MAEKAWA Masahide <bishop%rr.iij4u.or.jp@localhost>,
  *                   Nick Hibma <n_hibma%freebsd.org@localhost>
@@ -94,7 +94,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.74 2001/12/14 06:21:56 gehenna Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.75 2001/12/14 08:46:19 gehenna Exp $");
 
 #include "atapibus.h"
 
@@ -177,27 +177,32 @@
 #endif
 
 /* Bulk-Only related functions */
-Static void umass_bbb_reset(struct umass_softc *sc, int status);
-Static void umass_bbb_transfer(struct umass_softc *sc, int lun,
-                              void *cmd, int cmdlen,
-                              void *data, int datalen, int dir,
-                              u_int timeout, transfer_cb_f cb, void *priv);
-Static void umass_bbb_state(usbd_xfer_handle xfer,
-                           usbd_private_handle priv,
-                           usbd_status err);
-usbd_status umass_bbb_get_max_lun(struct umass_softc *sc, u_int8_t *maxlun);
+Static void umass_bbb_transfer(struct umass_softc *, int, void *, int, void *,
+                              int, int, u_int, umass_callback, void *);
+Static void umass_bbb_reset(struct umass_softc *, int);
+Static void umass_bbb_state(usbd_xfer_handle, usbd_private_handle, usbd_status);
 
+usbd_status umass_bbb_get_max_lun(struct umass_softc *, u_int8_t *);
 
 /* CBI related functions */
-Static int umass_cbi_adsc(struct umass_softc *sc, char *buffer,int buflen,
-                               usbd_xfer_handle xfer);
-Static void umass_cbi_reset(struct umass_softc *sc, int status);
-Static void umass_cbi_transfer(struct umass_softc *sc, int lun,
-                              void *cmd, int cmdlen,
-                              void *data, int datalen, int dir,
-                              u_int timeout, transfer_cb_f cb, void *priv);
-Static void umass_cbi_state(usbd_xfer_handle xfer,
-                               usbd_private_handle priv, usbd_status err);
+Static void umass_cbi_transfer(struct umass_softc *, int, void *, int, void *,  
+                              int, int, u_int, umass_callback, void *);
+Static void umass_cbi_reset(struct umass_softc *, int);
+Static void umass_cbi_state(usbd_xfer_handle, usbd_private_handle, usbd_status);
+
+Static int umass_cbi_adsc(struct umass_softc *, char *, int, usbd_xfer_handle);
+
+const struct umass_wire_methods umass_bbb_methods = {
+       umass_bbb_transfer,
+       umass_bbb_reset,
+       umass_bbb_state
+};
+
+const struct umass_wire_methods umass_cbi_methods = {
+       umass_cbi_transfer,
+       umass_cbi_reset,
+       umass_cbi_state
+};
 
 #ifdef UMASS_DEBUG
 /* General debugging functions */
@@ -667,14 +672,10 @@
 
        /* Initialise the wire protocol specific methods */
        if (sc->wire_proto == WPROTO_BBB) {
-               sc->reset = umass_bbb_reset;
-               sc->transfer = umass_bbb_transfer;
-               sc->state = umass_bbb_state;
+               sc->sc_methods = &umass_bbb_methods;
        } else if (sc->wire_proto == WPROTO_CBI ||
                   sc->wire_proto == WPROTO_CBI_I) {
-               sc->reset = umass_cbi_reset;
-               sc->transfer = umass_cbi_transfer;
-               sc->state = umass_cbi_state;
+               sc->sc_methods = &umass_cbi_methods;
 #ifdef UMASS_DEBUG
        } else {
                panic("%s:%d: Unknown wire proto 0x%02x\n",
@@ -786,7 +787,7 @@
        /* Initialiase a USB transfer and then schedule it */
 
        usbd_setup_xfer(xfer, pipe, (void *)sc, buffer, buflen,
-           flags | sc->sc_xfer_flags, sc->timeout, sc->state);
+           flags | sc->sc_xfer_flags, sc->timeout, sc->sc_methods->wire_state);
 
        err = usbd_transfer(xfer);
        DPRINTF(UDMASS_XFER,("%s: start xfer buffer=%p buflen=%d flags=0x%x "
@@ -813,8 +814,8 @@
 
        /* Initialiase a USB control transfer and then schedule it */
 
-       usbd_setup_default_xfer(xfer, sc->sc_udev, (void *) sc,
-           sc->timeout, req, buffer, buflen, flags, sc->state);
+       usbd_setup_default_xfer(xfer, sc->sc_udev, (void *) sc, sc->timeout,
+               req, buffer, buflen, flags, sc->sc_methods->wire_state);
 
        err = usbd_transfer(xfer);
        if (err && err != USBD_IN_PROGRESS) {
@@ -908,7 +909,7 @@
 Static void
 umass_bbb_transfer(struct umass_softc *sc, int lun, void *cmd, int cmdlen,
                   void *data, int datalen, int dir, u_int timeout,
-                  transfer_cb_f cb, void *priv)
+                  umass_callback cb, void *priv)
 {
        static int dCBWtag = 42;        /* unique for CBW of transfer */
 
@@ -1394,7 +1395,7 @@
 Static void
 umass_cbi_transfer(struct umass_softc *sc, int lun,
                   void *cmd, int cmdlen, void *data, int datalen, int dir,
-                  u_int timeout, transfer_cb_f cb, void *priv)
+                  u_int timeout, umass_callback cb, void *priv)
 {
        DPRINTF(UDMASS_CBI,("%s: umass_cbi_transfer cmd=0x%02x, len=%d\n",
                USBDEVNAME(sc->sc_dev), *(u_char*)cmd, datalen));
diff -r 6ffa6f8f489f -r 139647a8fc1b sys/dev/usb/umassbus.c
--- a/sys/dev/usb/umassbus.c    Fri Dec 14 08:39:11 2001 +0000
+++ b/sys/dev/usb/umassbus.c    Fri Dec 14 08:46:19 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umassbus.c,v 1.15 2001/12/02 22:44:34 bouyer Exp $     */
+/*     $NetBSD: umassbus.c,v 1.16 2001/12/14 08:46:20 gehenna Exp $    */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umassbus.c,v 1.15 2001/12/02 22:44:34 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umassbus.c,v 1.16 2001/12/14 08:46:20 gehenna Exp $");
 
 #include "atapibus.h"
 #include "scsibus.h"
@@ -330,9 +330,10 @@
                            ("umass_scsi_cmd: sync dir=%d\n", dir));
                        sc->sc_xfer_flags = USBD_SYNCHRONOUS;
                        sc->bus.sc_sync_status = USBD_INVAL;
-                       sc->transfer(sc, periph->periph_lun, cmd, cmdlen,
-                                    xs->data, xs->datalen, dir, xs->timeout,
-                                    0, xs);
+                       sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd,
+                                                 cmdlen, xs->data,
+                                                 xs->datalen, dir,
+                                                 xs->timeout, 0, xs);
                        sc->sc_xfer_flags = 0;
                        DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: done err=%d\n", 
                                              sc->bus.sc_sync_status));
@@ -353,9 +354,11 @@
                            ("umass_scsi_cmd: async dir=%d, cmdlen=%d"
                                      " datalen=%d\n",
                                      dir, cmdlen, xs->datalen));
-                       sc->transfer(sc, periph->periph_lun, cmd, cmdlen,
-                           xs->data, xs->datalen, dir, xs->timeout,
-                           umass_scsipi_cb, xs);
+                       sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd,
+                                                 cmdlen, xs->data,
+                                                 xs->datalen, dir,
+                                                 xs->timeout,
+                                                 umass_scsipi_cb, xs);
                        return;
                }
 
@@ -467,10 +470,11 @@
                cmdlen = sizeof(sc->bus.sc_sense_cmd);
                if (sc->cmd_proto == CPROTO_UFI) /* XXX */
                        cmdlen = UFI_COMMAND_LENGTH;
-               sc->transfer(sc, periph->periph_lun,
-                            &sc->bus.sc_sense_cmd, cmdlen,
-                            &xs->sense, sizeof(xs->sense), DIR_IN,
-                            xs->timeout, umass_scsipi_sense_cb, xs);
+               sc->sc_methods->wire_xfer(sc, periph->periph_lun,
+                                         &sc->bus.sc_sense_cmd, cmdlen,
+                                         &xs->sense, sizeof(xs->sense),
+                                         DIR_IN, xs->timeout,
+                                         umass_scsipi_sense_cb, xs);
                return;
 
        case STATUS_WIRE_FAILED:
diff -r 6ffa6f8f489f -r 139647a8fc1b sys/dev/usb/umassvar.h
--- a/sys/dev/usb/umassvar.h    Fri Dec 14 08:39:11 2001 +0000
+++ b/sys/dev/usb/umassvar.h    Fri Dec 14 08:46:19 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umassvar.h,v 1.6 2001/12/14 05:58:14 gehenna Exp $     */
+/*     $NetBSD: umassvar.h,v 1.7 2001/12/14 08:46:21 gehenna Exp $     */
 /*-
  * Copyright (c) 1999 MAEKAWA Masahide <bishop%rr.iij4u.or.jp@localhost>,
  *                   Nick Hibma <n_hibma%freebsd.org@localhost>
@@ -135,21 +135,23 @@
 
 struct umass_softc;            /* see below */
 
-typedef void (*transfer_cb_f)(struct umass_softc *sc, void *priv,
-                             int residue, int status);
+typedef void (*umass_callback)(struct umass_softc *, void *, int, int);
 #define STATUS_CMD_OK          0       /* everything ok */
 #define STATUS_CMD_UNKNOWN     1       /* will have to fetch sense */
 #define STATUS_CMD_FAILED      2       /* transfer was ok, command failed */
 #define STATUS_WIRE_FAILED     3       /* couldn't even get command across */
 
-typedef void (*wire_reset_f)(struct umass_softc *sc, int status);
-typedef void (*wire_transfer_f)(struct umass_softc *sc, int lun,
-                               void *cmd, int cmdlen, void *data, int datalen, 
-                               int dir, u_int timeout, transfer_cb_f cb,
-                               void *priv);
-typedef void (*wire_state_f)(usbd_xfer_handle xfer,
-                            usbd_private_handle priv, usbd_status err);
+typedef void (*umass_wire_xfer)(struct umass_softc *, int, void *, int, void *,
+                               int, int, u_int, umass_callback, void *);
+typedef void (*umass_wire_reset)(struct umass_softc *, int);
+typedef void (*umass_wire_state)(usbd_xfer_handle, usbd_private_handle,
+                                usbd_status);
 
+struct umass_wire_methods {
+       umass_wire_xfer         wire_xfer;
+       umass_wire_reset        wire_reset;
+       umass_wire_state        wire_state;
+};
 
 /* the per device structure */
 struct umass_softc {
@@ -159,6 +161,8 @@
        u_int8_t                sc_epaddr[UMASS_NEP];
        usbd_pipe_handle        sc_pipe[UMASS_NEP];
 
+       const struct umass_wire_methods *sc_methods;
+
        unsigned char           drive;
 #define DRIVE_GENERIC          0       /* use defaults for this one */
 #define ZIP_100                        1       /* to be used for quirks */
@@ -207,18 +211,6 @@
        usbd_interface_handle   iface;          /* Mass Storage interface */
        int                     ifaceno;        /* MS iface number */
 
-       /* Reset the device in a wire protocol specific way */
-       wire_reset_f            reset;
-
-       /* The start of a wire transfer. It prepares the whole transfer (cmd,
-        * data, and status stage) and initiates it. It is up to the state
-        * machine (below) to handle the various stages and errors in these
-        */
-       wire_transfer_f         transfer;
-
-       /* The state machine, handling the various states during a transfer */
-       wire_state_f            state;
-
        /* Bulk specific variables for transfers in progress */
        umass_bbb_cbw_t         cbw;    /* command block wrapper */
        umass_bbb_csw_t         csw;    /* command status wrapper*/
@@ -265,7 +257,7 @@
        void                    *transfer_data;         /* data buffer */
        int                     transfer_datalen;       /* (maximum) length */
        int                     transfer_actlen;        /* actual length */ 
-       transfer_cb_f           transfer_cb;            /* callback */
+       umass_callback          transfer_cb;            /* callback */
        void                    *transfer_priv;         /* for callback */
        int                     transfer_status;
 



Home | Main Index | Thread Index | Old Index