aac(4): Sync with FreeBSD.
authorSascha Wildner <saw@online.de>
Fri, 20 Jul 2012 20:42:07 +0000 (22:42 +0200)
committerSascha Wildner <saw@online.de>
Fri, 20 Jul 2012 20:42:42 +0000 (22:42 +0200)
Nothing spectacular. Race fixes, some cleanup and a sysctl for displaying
the firmware version.

sys/dev/raid/aac/aac.c
sys/dev/raid/aac/aac_cam.c
sys/dev/raid/aac/aac_disk.c
sys/dev/raid/aac/aac_ioctl.h
sys/dev/raid/aac/aacvar.h

index 4523e04..34b871b 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/aac/aac.c,v 1.165 2010/09/29 14:22:00 emaste Exp $
+ * $FreeBSD: src/sys/dev/aac/aac.c,v 1.170 2012/02/13 16:48:49 emaste Exp $
  */
 
 /*
@@ -42,7 +42,6 @@
 #include <sys/malloc.h>
 #include <sys/kernel.h>
 #include <sys/kthread.h>
-#include <sys/sysctl.h>
 #include <sys/poll.h>
 
 #include <sys/bus.h>
@@ -218,10 +217,10 @@ static struct dev_ops aac_ops = {
        .d_kqfilter =   aac_kqfilter
 };
 
-MALLOC_DEFINE(M_AACBUF, "aacbuf", "Buffers for the AAC driver");
+static MALLOC_DEFINE(M_AACBUF, "aacbuf", "Buffers for the AAC driver");
 
 /* sysctl node */
-SYSCTL_NODE(_hw, OID_AUTO, aac, CTLFLAG_RD, 0, "AAC driver parameters");
+static SYSCTL_NODE(_hw, OID_AUTO, aac, CTLFLAG_RD, 0, "AAC driver parameters");
 
 /*
  * Device Interface
@@ -290,6 +289,23 @@ aac_attach(struct aac_softc *sc)
         */
        aac_describe_controller(sc);
 
+       /*
+        * Add sysctls.
+        */
+       sysctl_ctx_init(&sc->aac_sysctl_ctx);
+       sc->aac_sysctl_tree = SYSCTL_ADD_NODE(&sc->aac_sysctl_ctx,
+           SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO,
+           device_get_nameunit(sc->aac_dev), CTLFLAG_RD, 0, "");
+       if (sc->aac_sysctl_tree == NULL) {
+               device_printf(sc->aac_dev, "can't add sysctl node\n");
+               return (EINVAL);
+       }
+       SYSCTL_ADD_INT(&sc->aac_sysctl_ctx,
+           SYSCTL_CHILDREN(sc->aac_sysctl_tree),
+           OID_AUTO, "firmware_build", CTLFLAG_RD,
+           &sc->aac_revision.buildNumber, 0,
+           "firmware build number");
+
        /*
         * Register to probe our containers later.
         */
@@ -639,6 +655,8 @@ aac_free(struct aac_softc *sc)
                bus_release_resource(sc->aac_dev, SYS_RES_MEMORY,
                                     sc->aac_regs_rid1, sc->aac_regs_res1);
        dev_ops_remove_minor(&aac_ops, device_get_unit(sc->aac_dev));
+
+       sysctl_ctx_free(&sc->aac_sysctl_ctx);
 }
 
 /*
@@ -655,7 +673,21 @@ aac_detach(device_t dev)
        sc = device_get_softc(dev);
        fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
 
+#if 0 /* XXX swildner */
+       callout_drain(&sc->aac_daemontime);
+#else
        callout_stop(&sc->aac_daemontime);
+#endif
+
+       lockmgr(&sc->aac_io_lock, LK_EXCLUSIVE);
+       while (sc->aifflags & AAC_AIFFLAGS_RUNNING) {
+               sc->aifflags |= AAC_AIFFLAGS_EXIT;
+               wakeup(sc->aifthread);
+               lksleep(sc->aac_dev, &sc->aac_io_lock, 0, "aacdch", 0);
+       }
+       lockmgr(&sc->aac_io_lock, LK_RELEASE);
+       KASSERT((sc->aifflags & AAC_AIFFLAGS_RUNNING) == 0,
+           ("%s: invalid detach state", __func__));
 
        /* Remove the child containers */
        while ((co = TAILQ_FIRST(&sc->aac_container_tqh)) != NULL) {
@@ -675,15 +707,6 @@ aac_detach(device_t dev)
                kfree(sim, M_AACBUF);
        }
 
-       if (sc->aifflags & AAC_AIFFLAGS_RUNNING) {
-               sc->aifflags |= AAC_AIFFLAGS_EXIT;
-               wakeup(sc->aifthread);
-               tsleep(sc->aac_dev, PCATCH, "aacdch", 30 * hz);
-       }
-
-       if (sc->aifflags & AAC_AIFFLAGS_RUNNING)
-               panic("Cannot shutdown AIF thread");
-
        if ((error = aac_shutdown(dev)))
                return(error);
 
@@ -1008,7 +1031,7 @@ aac_command_thread(void *arg)
                /*
                 * First see if any FIBs need to be allocated.  This needs
                 * to be called without the driver lock because contigmalloc
-                * will grab Giant, and would result in an LOR.
+                * can sleep.
                 */
                if ((sc->aifflags & AAC_AIFFLAGS_ALLOCFIBS) != 0) {
                        lockmgr(&sc->aac_io_lock, LK_RELEASE);
@@ -1362,7 +1385,9 @@ aac_alloc_command(struct aac_softc *sc, struct aac_command **cmp)
 
        if ((cm = aac_dequeue_free(sc)) == NULL) {
                if (sc->total_fibs < sc->aac_max_fibs) {
+                       lockmgr(&sc->aac_io_lock, LK_EXCLUSIVE);
                        sc->aifflags |= AAC_AIFFLAGS_ALLOCFIBS;
+                       lockmgr(&sc->aac_io_lock, LK_RELEASE);
                        wakeup(sc->aifthread);
                }
                return (EBUSY);
@@ -1405,11 +1430,7 @@ aac_release_command(struct aac_command *cm)
 
        aac_enqueue_free(cm);
 
-       /*
-        * Dequeue all events so that there's no risk of events getting
-        * stranded.
-        */
-       while ((event = TAILQ_FIRST(&sc->aac_ev_cmfree)) != NULL) {
+       if ((event = TAILQ_FIRST(&sc->aac_ev_cmfree)) != NULL) {
                TAILQ_REMOVE(&sc->aac_ev_cmfree, event, ev_links);
                event->ev_callback(sc, event, event->ev_arg);
        }
index e8574d6..f5de5a9 100644 (file)
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/aac/aac_cam.c,v 1.40 2010/12/06 17:06:21 jhb Exp $
+ * $FreeBSD: src/sys/dev/aac/aac_cam.c,v 1.42 2011/11/07 06:44:47 ed Exp $
  */
 
 /*
@@ -35,7 +35,6 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
-#include <sys/sysctl.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
@@ -103,7 +102,7 @@ static driver_t     aac_pass_driver = {
 DRIVER_MODULE(aacp, aac, aac_pass_driver, aac_pass_devclass, NULL, NULL);
 MODULE_DEPEND(aacp, cam, 1, 1, 1);
 
-MALLOC_DEFINE(M_AACCAM, "aaccam", "AAC CAM info");
+static MALLOC_DEFINE(M_AACCAM, "aaccam", "AAC CAM info");
 
 static void
 aac_cam_rescan(struct aac_softc *sc, uint32_t channel, uint32_t target_id)
@@ -539,6 +538,7 @@ aac_cam_complete(struct aac_command *cm)
        union   ccb *ccb;
        struct  aac_srb_response *srbr;
        struct  aac_softc *sc;
+       int     sense_returned;
 
        sc = cm->cm_sc;
        fwprintf(sc, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
@@ -563,16 +563,17 @@ aac_cam_complete(struct aac_command *cm)
 
                        /* Take care of autosense */
                        if (srbr->sense_len) {
-                               int sense_len, scsi_sense_len;
-
-                               scsi_sense_len = sizeof(struct scsi_sense_data);
-                               bzero(&ccb->csio.sense_data, scsi_sense_len);
-                               sense_len = (srbr->sense_len >
-                                   scsi_sense_len) ? scsi_sense_len :
-                                   srbr->sense_len;
+                               sense_returned = srbr->sense_len;
+                               if (sense_returned < ccb->csio.sense_len)
+                                       ccb->csio.sense_resid =
+                                          ccb->csio.sense_len -
+                                          sense_returned;
+                                       else
+                                           ccb->csio.sense_resid = 0;
+                               bzero(&ccb->csio.sense_data,
+                                   sizeof(struct scsi_sense_data));
                                bcopy(&srbr->sense[0], &ccb->csio.sense_data,
-                                   srbr->sense_len);
-                               ccb->csio.sense_len = sense_len;
+                                   min(ccb->csio.sense_len, sense_returned));
                                ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
                                // scsi_sense_print(&ccb->csio);
                        }
index ac1f203..e920887 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/aac/aac_disk.c,v 1.49 2010/09/16 23:33:24 emaste Exp $
+ * $FreeBSD: src/sys/dev/aac/aac_disk.c,v 1.50 2012/07/07 17:20:24 eadler Exp $
  */
 
 #include "opt_aac.h"
index 1c83a81..e266203 100644 (file)
@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $FreeBSD: src/sys/sys/aac_ioctl.h,v 1.14 2009/10/29 17:21:41 emaste Exp $
+ *     $FreeBSD: src/sys/sys/aac_ioctl.h,v 1.15 2011/02/21 09:01:34 brucec Exp $
  */
 
 #include <sys/ioccom.h>
@@ -119,7 +119,7 @@ union aac_statrequest {
 /* Do the native version of the ioctls.  Since the BSD encoding scheme
  * conflicts with the 'standard' AAC encoding scheme, the resulting numbers
  * will be different.  The '8' comes from the fact that the previous scheme
- * used 12 bits for the number, with the the 12th bit being the only set
+ * used 12 bits for the number, with the 12th bit being the only set
  * bit above bit 8.  Thus the value of 8, with the lower 8 bits holding the
  * command number.  9 is used for the odd overflow case.
  */
index 7fc77a8..20cb248 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.60 2010/09/29 14:22:00 emaste Exp $
+ *     $FreeBSD: src/sys/dev/aac/aacvar.h,v 1.63 2011/06/10 20:23:56 attilio Exp $
  */
 
 #include <sys/bio.h>
@@ -37,6 +37,7 @@
 #include <sys/devicestat.h>
 #include <sys/disk.h>
 #include <sys/eventhandler.h>
+#include <sys/sysctl.h>
 
 #define        AAC_TYPE_DEVO                   1
 #define        AAC_TYPE_ALPHA                  2
@@ -378,6 +379,9 @@ struct aac_softc
                                                         * task */
        struct intr_config_hook aac_ich;
 
+       struct sysctl_ctx_list  aac_sysctl_ctx;
+       struct sysctl_oid       *aac_sysctl_tree;
+
        /* management interface */
        struct cdev *aac_dev_t;
        struct lock             aac_aifq_lock;
@@ -389,13 +393,12 @@ struct aac_softc
        struct thread           *aifthread;
        int                     aifflags;
 #define AAC_AIFFLAGS_RUNNING   (1 << 0)
-#define AAC_AIFFLAGS_AIF       (1 << 1)
+#define AAC_AIFFLAGS_UNUSED0   (1 << 1)
 #define        AAC_AIFFLAGS_EXIT       (1 << 2)
 #define AAC_AIFFLAGS_EXITED    (1 << 3)
-#define AAC_AIFFLAGS_PRINTF    (1 << 4)
+#define AAC_AIFFLAGS_UNUSED1   (1 << 4)
 #define        AAC_AIFFLAGS_ALLOCFIBS  (1 << 5)
-#define AAC_AIFFLAGS_PENDING   (AAC_AIFFLAGS_AIF | AAC_AIFFLAGS_PRINTF | \
-                                AAC_AIFFLAGS_ALLOCFIBS)
+#define AAC_AIFFLAGS_PENDING   AAC_AIFFLAGS_ALLOCFIBS
        u_int32_t               flags;
 #define AAC_FLAGS_PERC2QC      (1 << 0)
 #define        AAC_FLAGS_ENABLE_CAM    (1 << 1)        /* No SCSI passthrough */
@@ -540,9 +543,8 @@ static __inline void                                                        \
 aac_enqueue_ ## name (struct aac_command *cm)                          \
 {                                                                      \
        if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) {                   \
-               kprintf("command %p is on another queue, flags = %#x\n", \
-                      cm, cm->cm_flags);                               \
-               panic("command is on another queue");                   \
+               panic("aac: command %p is on another queue, flags = %#x", \
+                   cm, cm->cm_flags);                                  \
        }                                                               \
        TAILQ_INSERT_TAIL(&cm->cm_sc->aac_ ## name, cm, cm_link);       \
        cm->cm_flags |= AAC_ON_ ## index;                               \
@@ -552,9 +554,8 @@ static __inline void                                                        \
 aac_requeue_ ## name (struct aac_command *cm)                          \
 {                                                                      \
        if ((cm->cm_flags & AAC_ON_AACQ_MASK) != 0) {                   \
-               kprintf("command %p is on another queue, flags = %#x\n", \
-                      cm, cm->cm_flags);                               \
-               panic("command is on another queue");                   \
+               panic("aac: command %p is on another queue, flags = %#x", \
+                   cm, cm->cm_flags);                                  \
        }                                                               \
        TAILQ_INSERT_HEAD(&cm->cm_sc->aac_ ## name, cm, cm_link);       \
        cm->cm_flags |= AAC_ON_ ## index;                               \
@@ -567,10 +568,8 @@ aac_dequeue_ ## name (struct aac_softc *sc)                                \
                                                                        \
        if ((cm = TAILQ_FIRST(&sc->aac_ ## name)) != NULL) {            \
                if ((cm->cm_flags & AAC_ON_ ## index) == 0) {           \
-                       kprintf("command %p not in queue, flags = %#x, " \
-                              "bit = %#x\n", cm, cm->cm_flags,         \
-                              AAC_ON_ ## index);                       \
-                       panic("command not in queue");                  \
+                       panic("aac: command %p not in queue, flags = %#x, bit = %#x", \
+                           cm, cm->cm_flags, AAC_ON_ ## index);        \
                }                                                       \
                TAILQ_REMOVE(&sc->aac_ ## name, cm, cm_link);           \
                cm->cm_flags &= ~AAC_ON_ ## index;                      \
@@ -582,10 +581,8 @@ static __inline void                                                       \
 aac_remove_ ## name (struct aac_command *cm)                           \
 {                                                                      \
        if ((cm->cm_flags & AAC_ON_ ## index) == 0) {                   \
-               kprintf("command %p not in queue, flags = %#x, "        \
-                      "bit = %#x\n", cm, cm->cm_flags,                 \
-                      AAC_ON_ ## index);                               \
-               panic("command not in queue");                          \
+               panic("aac: command %p not in queue, flags = %#x, bit = %#x", \
+                   cm, cm->cm_flags, AAC_ON_ ## index);                \
        }                                                               \
        TAILQ_REMOVE(&cm->cm_sc->aac_ ## name, cm, cm_link);            \
        cm->cm_flags &= ~AAC_ON_ ## index;                              \