Source-Changes-HG archive

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

[src/jdolecek-ncqfixes]: src/sys/dev move low-level protocol handlers hooks f...



details:   https://anonhg.NetBSD.org/src/rev/6e46957d6492
branches:  jdolecek-ncqfixes
changeset: 1025073:6e46957d6492
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Mon Sep 17 18:36:13 2018 +0000

description:
move low-level protocol handlers hooks from ata_xfer to separate struct,
initialized statically

primarily to reduce ata_xfer struct size, but also improves readibility,
and enforces consistency

diffstat:

 sys/dev/ata/ata.c          |  20 +++++++-------
 sys/dev/ata/ata_subr.c     |   7 ++--
 sys/dev/ata/ata_wdc.c      |  18 ++++++++-----
 sys/dev/ata/atavar.h       |   7 ++++-
 sys/dev/ic/ahcisata_core.c |  62 +++++++++++++++++++++++++++------------------
 sys/dev/ic/mvsata.c        |  54 ++++++++++++++++++++++++---------------
 sys/dev/ic/siisata.c       |  56 +++++++++++++++++++++++++----------------
 sys/dev/ic/wdc.c           |  26 +++++++++++--------
 sys/dev/scsipi/atapi_wdc.c |  18 ++++++++-----
 9 files changed, 161 insertions(+), 107 deletions(-)

diffs (truncated from 753 to 300 lines):

diff -r 4a05488f7522 -r 6e46957d6492 sys/dev/ata/ata.c
--- a/sys/dev/ata/ata.c Sat Sep 01 10:13:41 2018 +0000
+++ b/sys/dev/ata/ata.c Mon Sep 17 18:36:13 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata.c,v 1.141.6.2 2018/09/01 09:48:32 jdolecek Exp $   */
+/*     $NetBSD: ata.c,v 1.141.6.3 2018/09/17 18:36:13 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.141.6.2 2018/09/01 09:48:32 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.141.6.3 2018/09/17 18:36:13 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -1238,7 +1238,7 @@
 
        KASSERT(mutex_owned(&chp->ch_lock));
 
-       rv = xfer->c_start(chp, xfer);
+       rv = xfer->ops->c_start(chp, xfer);
        switch (rv) {
        case ATASTART_STARTED:
                /* nothing to do */
@@ -1250,14 +1250,14 @@
        case ATASTART_POLL:
                /* can happen even in thread context for some ATAPI devices */
                ata_channel_unlock(chp);
-               KASSERT(xfer->c_poll != NULL);
-               xfer->c_poll(chp, xfer);
+               KASSERT(xfer->ops != NULL && xfer->ops->c_poll != NULL);
+               xfer->ops->c_poll(chp, xfer);
                ata_channel_lock(chp);
                break;
        case ATASTART_ABORT:
                ata_channel_unlock(chp);
-               KASSERT(xfer->c_abort != NULL);
-               xfer->c_abort(chp, xfer);
+               KASSERT(xfer->ops != NULL && xfer->ops->c_abort != NULL);
+               xfer->ops->c_abort(chp, xfer);
                ata_channel_lock(chp);
                break;
        }
@@ -1337,7 +1337,7 @@
        if (chp->ch_drive[drive].drive_flags & ATA_DRIVE_WAITDRAIN) {
                ata_channel_unlock(chp);
 
-               (*xfer->c_kill_xfer)(chp, xfer, KILL_GONE);
+               xfer->ops->c_kill_xfer(chp, xfer, KILL_GONE);
 
                ata_channel_lock(chp);
                chp->ch_drive[drive].drive_flags &= ~ATA_DRIVE_WAITDRAIN;
@@ -1404,7 +1404,7 @@
        KASSERT(mutex_owned(&chp->ch_lock));
 
        TAILQ_FOREACH_SAFE(xfer, &chq->active_xfers, c_activechain, xfernext) {
-               (*xfer->c_kill_xfer)(xfer->c_chp, xfer, reason);
+               xfer->ops->c_kill_xfer(xfer->c_chp, xfer, reason);
        }
 
        if (flags & AT_RST_EMERG)
@@ -1438,7 +1438,7 @@
                 * data corruption, if the hook tries to call back into
                 * middle layer for inactive xfer.
                 */
-               (*xfer->c_kill_xfer)(chp, xfer, KILL_GONE_INACTIVE);
+               xfer->ops->c_kill_xfer(chp, xfer, KILL_GONE_INACTIVE);
        }
 
        /* Wait until all active transfers on the drive finish */
diff -r 4a05488f7522 -r 6e46957d6492 sys/dev/ata/ata_subr.c
--- a/sys/dev/ata/ata_subr.c    Sat Sep 01 10:13:41 2018 +0000
+++ b/sys/dev/ata/ata_subr.c    Mon Sep 17 18:36:13 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata_subr.c,v 1.6.2.1 2018/08/31 19:08:03 jdolecek Exp $        */
+/*     $NetBSD: ata_subr.c,v 1.6.2.2 2018/09/17 18:36:13 jdolecek Exp $        */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata_subr.c,v 1.6.2.1 2018/08/31 19:08:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata_subr.c,v 1.6.2.2 2018/09/17 18:36:13 jdolecek Exp $");
 
 #include "opt_ata.h"
 
@@ -326,6 +326,7 @@
                goto out;
        }
 
+       /* XXX move PIOBM and free_gw to deactivate? */
 #if NATA_PIOBM         /* XXX wdc dependent code */
        if (xfer->c_flags & C_PIOBM) {
                struct wdc_softc *wdc = CHAN_TO_WDC(chp);
@@ -386,7 +387,7 @@
 
                /* Mark as timed out. Do not print anything, wd(4) will. */
                xfer->c_flags |= C_TIMEOU;
-               xfer->c_intr(xfer->c_chp, xfer, 0);
+               xfer->ops->c_intr(xfer->c_chp, xfer, 0);
        }
 
        splx(s);
diff -r 4a05488f7522 -r 6e46957d6492 sys/dev/ata/ata_wdc.c
--- a/sys/dev/ata/ata_wdc.c     Sat Sep 01 10:13:41 2018 +0000
+++ b/sys/dev/ata/ata_wdc.c     Mon Sep 17 18:36:13 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ata_wdc.c,v 1.110.4.1 2018/08/31 19:08:03 jdolecek Exp $       */
+/*     $NetBSD: ata_wdc.c,v 1.110.4.2 2018/09/17 18:36:13 jdolecek Exp $       */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata_wdc.c,v 1.110.4.1 2018/08/31 19:08:03 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata_wdc.c,v 1.110.4.2 2018/09/17 18:36:13 jdolecek Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -131,6 +131,14 @@
        ata_kill_pending,
 };
 
+static const struct ata_xfer_ops wdc_bio_xfer_ops = {
+       .c_start = wdc_ata_bio_start,
+       .c_poll = wdc_ata_bio_poll,
+       .c_abort = wdc_ata_bio_done,
+       .c_intr = wdc_ata_bio_intr,
+       .c_kill_xfer = wdc_ata_bio_kill_xfer
+};
+
 /*
  * Handle block I/O operation. Return ATACMD_COMPLETE, ATACMD_QUEUED, or
  * ATACMD_TRY_AGAIN. Must be called at splbio().
@@ -161,11 +169,7 @@
        xfer->c_drive = drvp->drive;
        xfer->c_databuf = ata_bio->databuf;
        xfer->c_bcount = ata_bio->bcount;
-       xfer->c_start = wdc_ata_bio_start;
-       xfer->c_poll = wdc_ata_bio_poll;
-       xfer->c_abort = wdc_ata_bio_done;
-       xfer->c_intr = wdc_ata_bio_intr;
-       xfer->c_kill_xfer = wdc_ata_bio_kill_xfer;
+       xfer->ops = &wdc_bio_xfer_ops;
        ata_exec_xfer(chp, xfer);
        return (ata_bio->flags & ATA_ITSDONE) ? ATACMD_COMPLETE : ATACMD_QUEUED;
 }
diff -r 4a05488f7522 -r 6e46957d6492 sys/dev/ata/atavar.h
--- a/sys/dev/ata/atavar.h      Sat Sep 01 10:13:41 2018 +0000
+++ b/sys/dev/ata/atavar.h      Mon Sep 17 18:36:13 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atavar.h,v 1.99.2.1 2018/08/31 19:08:03 jdolecek Exp $ */
+/*     $NetBSD: atavar.h,v 1.99.2.2 2018/09/17 18:36:13 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -125,6 +125,7 @@
 
 /* Forward declaration for ata_xfer */
 struct scsipi_xfer;
+struct ata_xfer_ops;
 
 /*
  * Description of a command to be handled by an ATA controller.  These
@@ -166,6 +167,10 @@
        SLIST_ENTRY(ata_xfer) c_retrychain;
 
        /* Low-level protocol handlers. */
+       const struct ata_xfer_ops *ops;
+};
+
+struct ata_xfer_ops {
        int     (*c_start)(struct ata_channel *, struct ata_xfer *);
 #define ATASTART_STARTED       0       /* xfer started, waiting for intr */
 #define ATASTART_TH            1       /* xfer needs to be run in thread */
diff -r 4a05488f7522 -r 6e46957d6492 sys/dev/ic/ahcisata_core.c
--- a/sys/dev/ic/ahcisata_core.c        Sat Sep 01 10:13:41 2018 +0000
+++ b/sys/dev/ic/ahcisata_core.c        Mon Sep 17 18:36:13 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ahcisata_core.c,v 1.62.2.2 2018/09/01 10:13:41 jdolecek Exp $  */
+/*     $NetBSD: ahcisata_core.c,v 1.62.2.3 2018/09/17 18:36:13 jdolecek Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.2 2018/09/01 10:13:41 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.62.2.3 2018/09/17 18:36:13 jdolecek Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -647,7 +647,7 @@
                if ((achp->ahcic_cmds_active & __BIT(slot)) != 0 &&
                    (sact & __BIT(slot)) == 0) {
                        xfer = ata_queue_hwslot_to_xfer(chp, slot);
-                       xfer->c_intr(chp, xfer, tfd);
+                       xfer->ops->c_intr(chp, xfer, tfd);
                }
        } else {
                /*
@@ -665,7 +665,7 @@
                        if ((aslots & __BIT(slot)) != 0 &&
                            (sact & __BIT(slot)) == 0) {
                                xfer = ata_queue_hwslot_to_xfer(chp, slot);
-                               xfer->c_intr(chp, xfer, tfd);
+                               xfer->ops->c_intr(chp, xfer, tfd);
                        }
                }
        }
@@ -1003,6 +1003,14 @@
        return;
 }
 
+static const struct ata_xfer_ops ahci_cmd_xfer_ops = {
+       .c_start = ahci_cmd_start,
+       .c_poll = ahci_cmd_poll,
+       .c_abort = ahci_cmd_abort,
+       .c_intr = ahci_cmd_complete,
+       .c_kill_xfer = ahci_cmd_kill_xfer,
+};
+
 static int
 ahci_exec_command(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
 {
@@ -1022,11 +1030,7 @@
        xfer->c_drive = drvp->drive;
        xfer->c_databuf = ata_c->data;
        xfer->c_bcount = ata_c->bcount;
-       xfer->c_start = ahci_cmd_start;
-       xfer->c_poll = ahci_cmd_poll;
-       xfer->c_abort = ahci_cmd_abort;
-       xfer->c_intr = ahci_cmd_complete;
-       xfer->c_kill_xfer = ahci_cmd_kill_xfer;
+       xfer->ops = &ahci_cmd_xfer_ops;
        s = splbio();
        ata_exec_xfer(chp, xfer);
 #ifdef DIAGNOSTIC
@@ -1142,7 +1146,7 @@
 
        if ((xfer->c_ata_c.flags & AT_DONE) == 0) {
                xfer->c_ata_c.flags |= AT_TIMEOU;
-               xfer->c_intr(chp, xfer, 0);
+               xfer->ops->c_intr(chp, xfer, 0);
        }
        /* reenable interrupts */
        AHCI_WRITE(sc, AHCI_GHC, AHCI_READ(sc, AHCI_GHC) | AHCI_GHC_IE);
@@ -1279,6 +1283,14 @@
        ata_c->flags |= AT_DONE;
 }
 
+static const struct ata_xfer_ops ahci_bio_xfer_ops = {
+       .c_start = ahci_bio_start,
+       .c_poll = ahci_bio_poll,
+       .c_abort = ahci_bio_abort,
+       .c_intr = ahci_bio_complete,
+       .c_kill_xfer = ahci_bio_kill_xfer,
+};
+
 static int
 ahci_ata_bio(struct ata_drive_datas *drvp, struct ata_xfer *xfer)
 {
@@ -1294,11 +1306,7 @@
        xfer->c_drive = drvp->drive;
        xfer->c_databuf = ata_bio->databuf;
        xfer->c_bcount = ata_bio->bcount;
-       xfer->c_start = ahci_bio_start;
-       xfer->c_poll = ahci_bio_poll;
-       xfer->c_abort = ahci_bio_abort;
-       xfer->c_intr = ahci_bio_complete;
-       xfer->c_kill_xfer = ahci_bio_kill_xfer;
+       xfer->ops = &ahci_bio_xfer_ops;
        ata_exec_xfer(chp, xfer);
        return (ata_bio->flags & ATA_ITSDONE) ? ATACMD_COMPLETE : ATACMD_QUEUED;
 }
@@ -1386,7 +1394,7 @@
            DEBUG_XFERS);
        if ((xfer->c_bio.flags & ATA_ITSDONE) == 0) {
                xfer->c_bio.error = TIMEOUT;
-               xfer->c_intr(chp, xfer, 0);
+               xfer->ops->c_intr(chp, xfer, 0);
        }
        /* reenable interrupts */
        AHCI_WRITE(sc, AHCI_GHC, AHCI_READ(sc, AHCI_GHC) | AHCI_GHC_IE);
@@ -1671,7 +1679,7 @@
                if ((achp->ahcic_cmds_active & (1U << eslot)) != 0) {
                        xfer = ata_queue_hwslot_to_xfer(chp, eslot);
                        xfer->c_flags |= C_RECOVERED;
-                       xfer->c_intr(chp, xfer,
+                       xfer->ops->c_intr(chp, xfer,
                            (err << AHCI_P_TFD_ERR_SHIFT) | st);
                }



Home | Main Index | Thread Index | Old Index