Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ata split off functions used by 'wd* at umass?' into...



details:   https://anonhg.NetBSD.org/src/rev/f8e13c9dbe9a
branches:  trunk
changeset: 827049:f8e13c9dbe9a
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Tue Oct 10 17:19:38 2017 +0000

description:
split off functions used by 'wd* at umass?' into separate file, unfortunately
the previous approach with NATABUS doesn't work for kernels which include
MODULAR, but not atabus - such as macppc and evbarm

diffstat:

 sys/dev/ata/ata.c      |  366 +------------------------------------------
 sys/dev/ata/ata_subr.c |  420 +++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ata/ataconf.h  |    3 +-
 sys/dev/ata/atavar.h   |    5 +-
 sys/dev/ata/files.ata  |    5 +-
 5 files changed, 430 insertions(+), 369 deletions(-)

diffs (truncated from 906 to 300 lines):

diff -r 7e3cbca19027 -r f8e13c9dbe9a sys/dev/ata/ata.c
--- a/sys/dev/ata/ata.c Tue Oct 10 16:44:24 2017 +0000
+++ b/sys/dev/ata/ata.c Tue Oct 10 17:19:38 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata.c,v 1.135 2017/10/08 19:00:29 jdolecek Exp $       */
+/*     $NetBSD: ata.c,v 1.136 2017/10/10 17:19:38 jdolecek Exp $       */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.135 2017/10/08 19:00:29 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.136 2017/10/10 17:19:38 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -83,7 +83,6 @@
 #define ATADEBUG_PRINT(args, level)
 #endif
 
-#if NATABUS
 static ONCE_DECL(ata_init_ctrl);
 
 /*
@@ -134,7 +133,6 @@
 static void ata_channel_thaw_locked(struct ata_channel *);
 static void ata_activate_xfer_locked(struct ata_channel *, struct ata_xfer *);
 static void ata_channel_freeze_locked(struct ata_channel *);
-static struct ata_xfer *ata_queue_get_active_xfer_locked(struct ata_channel *);
 static void ata_thread_wake_locked(struct ata_channel *);
 
 /*
@@ -186,177 +184,7 @@
 
        return (UNCONF);
 }
-#endif /* NATABUS */
 
-static void
-ata_queue_reset(struct ata_queue *chq)
-{
-       /* make sure that we can use polled commands */
-       TAILQ_INIT(&chq->queue_xfer);
-       TAILQ_INIT(&chq->active_xfers);
-       chq->queue_freeze = 0;
-       chq->queue_active = 0;
-       chq->active_xfers_used = 0;
-       chq->queue_xfers_avail = __BIT(chq->queue_openings) - 1;
-}
-
-struct ata_xfer *
-ata_queue_hwslot_to_xfer(struct ata_channel *chp, int hwslot)
-{
-       struct ata_queue *chq = chp->ch_queue;
-       struct ata_xfer *xfer = NULL;
-
-       ata_channel_lock(chp);
-
-       KASSERTMSG(hwslot < chq->queue_openings, "hwslot %d > openings %d",
-           hwslot, chq->queue_openings);
-       KASSERTMSG((chq->active_xfers_used & __BIT(hwslot)) != 0,
-           "hwslot %d not active", hwslot);
-
-       /* Usually the first entry will be the one */
-       TAILQ_FOREACH(xfer, &chq->active_xfers, c_activechain) {
-               if (xfer->c_slot == hwslot)
-                       break;
-       }
-
-       ata_channel_unlock(chp);
-
-       KASSERTMSG((xfer != NULL),
-           "%s: xfer with slot %d not found (active %x)", __func__,
-           hwslot, chq->active_xfers_used);
-
-       return xfer;
-}
-
-static struct ata_xfer *
-ata_queue_get_active_xfer_locked(struct ata_channel *chp)
-{
-       struct ata_xfer *xfer;
-
-       KASSERT(mutex_owned(&chp->ch_lock));
-       xfer = TAILQ_FIRST(&chp->ch_queue->active_xfers);
-
-       if (xfer && ISSET(xfer->c_flags, C_NCQ)) {
-               /* Spurious call, never return NCQ xfer from this interface */
-               xfer = NULL;
-       }
-
-       return xfer;
-}
-
-/*
- * This interface is supposed only to be used when there is exactly
- * one outstanding command, when there is no information about the slot,
- * which triggered the command. ata_queue_hwslot_to_xfer() interface
- * is preferred in all NCQ cases.
- */
-struct ata_xfer *
-ata_queue_get_active_xfer(struct ata_channel *chp)
-{
-       struct ata_xfer *xfer = NULL;
-
-       ata_channel_lock(chp);
-       xfer = ata_queue_get_active_xfer_locked(chp);
-       ata_channel_unlock(chp);
-
-       return xfer;
-}
-
-struct ata_xfer *
-ata_queue_drive_active_xfer(struct ata_channel *chp, int drive)
-{
-       struct ata_xfer *xfer = NULL;
-
-       ata_channel_lock(chp);
-
-       TAILQ_FOREACH(xfer, &chp->ch_queue->active_xfers, c_activechain) {
-               if (xfer->c_drive == drive)
-                       break;
-       }
-       KASSERT(xfer != NULL);
-
-       ata_channel_unlock(chp);
-
-       return xfer;
-}
-
-static void
-ata_xfer_init(struct ata_xfer *xfer, uint8_t slot)
-{
-       memset(xfer, 0, sizeof(*xfer));
-
-       xfer->c_slot = slot;
-
-       cv_init(&xfer->c_active, "ataact");
-       cv_init(&xfer->c_finish, "atafin");
-       callout_init(&xfer->c_timo_callout, 0);         /* XXX MPSAFE */
-       callout_init(&xfer->c_retry_callout, 0);        /* XXX MPSAFE */
-}
-
-static void
-ata_xfer_destroy(struct ata_xfer *xfer)
-{
-       callout_halt(&xfer->c_timo_callout, NULL);      /* XXX MPSAFE */
-       callout_destroy(&xfer->c_timo_callout);
-       callout_halt(&xfer->c_retry_callout, NULL);     /* XXX MPSAFE */
-       callout_destroy(&xfer->c_retry_callout);
-       cv_destroy(&xfer->c_active);
-       cv_destroy(&xfer->c_finish);
-}
-
-struct ata_queue *
-ata_queue_alloc(uint8_t openings)
-{
-       if (openings == 0)
-               openings = 1;
-
-       if (openings > ATA_MAX_OPENINGS)
-               openings = ATA_MAX_OPENINGS;
-
-       struct ata_queue *chq = malloc(offsetof(struct ata_queue, queue_xfers[openings]),
-           M_DEVBUF, M_WAITOK | M_ZERO);
-
-       chq->queue_openings = openings;
-       ata_queue_reset(chq);
-
-       cv_init(&chq->queue_busy, "ataqbusy");
-       cv_init(&chq->queue_drain, "atdrn");
-       cv_init(&chq->queue_idle, "qidl");
-
-       for (uint8_t i = 0; i < openings; i++)
-               ata_xfer_init(&chq->queue_xfers[i], i);
-
-       return chq;
-}
-
-void
-ata_queue_free(struct ata_queue *chq)
-{
-       for (uint8_t i = 0; i < chq->queue_openings; i++)
-               ata_xfer_destroy(&chq->queue_xfers[i]);
-
-       cv_destroy(&chq->queue_busy);
-       cv_destroy(&chq->queue_drain);
-       cv_destroy(&chq->queue_idle);
-
-       free(chq, M_DEVBUF);
-}
-
-void
-ata_channel_init(struct ata_channel *chp)
-{
-       mutex_init(&chp->ch_lock, MUTEX_DEFAULT, IPL_BIO);
-       cv_init(&chp->ch_thr_idle, "atath");
-}
-
-void
-ata_channel_destroy(struct ata_channel *chp)
-{
-       mutex_destroy(&chp->ch_lock);
-       cv_destroy(&chp->ch_thr_idle);
-}
-
-#if NATABUS
 /*
  * ata_channel_attach:
  *
@@ -1431,129 +1259,7 @@
 
        return rv;
 }
-#endif /* NATABUS */
 
-/*
- * Does it's own locking, does not require splbio().
- * flags - whether to block waiting for free xfer
- * openings - limit of openings supported by device, <= 0 means tag not
- *     relevant, and any available xfer can be returned
- */
-struct ata_xfer *
-ata_get_xfer_ext(struct ata_channel *chp, int flags, uint8_t openings)
-{
-       struct ata_queue *chq = chp->ch_queue;
-       struct ata_xfer *xfer = NULL;
-       uint32_t avail, slot, mask;
-       int error;
-
-       ATADEBUG_PRINT(("%s: channel %d flags %x openings %d\n",
-           __func__, chp->ch_channel, flags, openings),
-           DEBUG_XFERS);
-
-       ata_channel_lock(chp);
-
-       /*
-        * When openings is just 1, can't reserve anything for
-        * recovery. KASSERT() here is to catch code which naively
-        * relies on C_RECOVERY to work under this condition.
-        */
-       KASSERT((flags & C_RECOVERY) == 0 || chq->queue_openings > 1);
-
-       if (flags & C_RECOVERY) {
-               mask = UINT32_MAX;
-       } else {
-               if (openings <= 0 || openings > chq->queue_openings)
-                       openings = chq->queue_openings;
-
-               if (openings > 1) {
-                       mask = __BIT(openings - 1) - 1;
-               } else {
-                       mask = UINT32_MAX;
-               }
-       }
-
-retry:
-       avail = ffs32(chq->queue_xfers_avail & mask);
-       if (avail == 0) {
-               /*
-                * Catch code which tries to get another recovery xfer while
-                * already holding one (wrong recursion).
-                */
-               KASSERTMSG((flags & C_RECOVERY) == 0,
-                   "recovery xfer busy openings %d mask %x avail %x",
-                   openings, mask, chq->queue_xfers_avail);
-
-               if (flags & C_WAIT) {
-                       chq->queue_flags |= QF_NEED_XFER;
-                       error = cv_wait_sig(&chq->queue_busy, &chp->ch_lock);
-                       if (error == 0)
-                               goto retry;
-               }
-
-               goto out;
-       }
-
-       slot = avail - 1;
-       xfer = &chq->queue_xfers[slot];
-       chq->queue_xfers_avail &= ~__BIT(slot);
-
-       KASSERT((chq->active_xfers_used & __BIT(slot)) == 0);
-
-       /* zero everything after the callout member */
-       memset(&xfer->c_startzero, 0,
-           sizeof(struct ata_xfer) - offsetof(struct ata_xfer, c_startzero));
-
-out:
-       ata_channel_unlock(chp);
-       return xfer;
-}
-
-/*
- * ata_deactivate_xfer() must be always called prior to ata_free_xfer()
- */
-void
-ata_free_xfer(struct ata_channel *chp, struct ata_xfer *xfer)
-{



Home | Main Index | Thread Index | Old Index