Driver modifications consistent with my other drivers to facilitate

the use of a single set of sources across 4.x and 5.x branches.

No significant code changes.
This commit is contained in:
Mike Smith 2001-06-25 04:32:31 +00:00
parent 9ae6dc2e12
commit 15fd5d220f
5 changed files with 115 additions and 41 deletions

View File

@ -35,7 +35,6 @@
#include <sys/malloc.h> #include <sys/malloc.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/bio.h>
#include <sys/bus.h> #include <sys/bus.h>
#include <sys/conf.h> #include <sys/conf.h>
#include <sys/devicestat.h> #include <sys/devicestat.h>
@ -49,6 +48,7 @@
#include <machine/clock.h> #include <machine/clock.h>
#include <sys/rman.h> #include <sys/rman.h>
#include <dev/mlx/mlx_compat.h>
#include <dev/mlx/mlxio.h> #include <dev/mlx/mlxio.h>
#include <dev/mlx/mlxvar.h> #include <dev/mlx/mlxvar.h>
#include <dev/mlx/mlxreg.h> #include <dev/mlx/mlxreg.h>
@ -296,7 +296,7 @@ mlx_attach(struct mlx_softc *sc)
*/ */
TAILQ_INIT(&sc->mlx_work); TAILQ_INIT(&sc->mlx_work);
TAILQ_INIT(&sc->mlx_freecmds); TAILQ_INIT(&sc->mlx_freecmds);
bioq_init(&sc->mlx_bioq); MLX_BIO_QINIT(sc->mlx_bioq);
/* /*
* Select accessor methods based on controller interface type. * Select accessor methods based on controller interface type.
@ -696,14 +696,14 @@ mlx_intr(void *arg)
* disk resource, then poke the disk resource to start as much work as it can. * disk resource, then poke the disk resource to start as much work as it can.
*/ */
int int
mlx_submit_buf(struct mlx_softc *sc, struct bio *bp) mlx_submit_buf(struct mlx_softc *sc, mlx_bio *bp)
{ {
int s; int s;
debug_called(1); debug_called(1);
s = splbio(); s = splbio();
bioq_insert_tail(&sc->mlx_bioq, bp); MLX_BIO_QINSERT(sc->mlx_bioq, bp);
sc->mlx_waitbufs++; sc->mlx_waitbufs++;
splx(s); splx(s);
mlx_startio(sc); mlx_startio(sc);
@ -1725,7 +1725,7 @@ mlx_startio(struct mlx_softc *sc)
{ {
struct mlx_command *mc; struct mlx_command *mc;
struct mlxd_softc *mlxd; struct mlxd_softc *mlxd;
struct bio *bp; mlx_bio *bp;
int blkcount; int blkcount;
int driveno; int driveno;
int cmd; int cmd;
@ -1740,7 +1740,7 @@ mlx_startio(struct mlx_softc *sc)
for (;;) { for (;;) {
/* see if there's work to be done */ /* see if there's work to be done */
if ((bp = bioq_first(&sc->mlx_bioq)) == NULL) if ((bp = MLX_BIO_QFIRST(sc->mlx_bioq)) == NULL)
break; break;
/* get a command */ /* get a command */
if ((mc = mlx_alloccmd(sc)) == NULL) if ((mc = mlx_alloccmd(sc)) == NULL)
@ -1751,16 +1751,16 @@ mlx_startio(struct mlx_softc *sc)
break; break;
} }
/* get the buf containing our work */ /* get the buf containing our work */
bioq_remove(&sc->mlx_bioq, bp); MLX_BIO_QREMOVE(sc->mlx_bioq, bp);
sc->mlx_waitbufs--; sc->mlx_waitbufs--;
splx(s); splx(s);
/* connect the buf to the command */ /* connect the buf to the command */
mc->mc_complete = mlx_completeio; mc->mc_complete = mlx_completeio;
mc->mc_private = bp; mc->mc_private = bp;
mc->mc_data = bp->bio_data; mc->mc_data = MLX_BIO_DATA(bp);
mc->mc_length = bp->bio_bcount; mc->mc_length = MLX_BIO_LENGTH(bp);
if (bp->bio_cmd == BIO_READ) { if (MLX_BIO_IS_READ(bp)) {
mc->mc_flags |= MLX_CMD_DATAIN; mc->mc_flags |= MLX_CMD_DATAIN;
cmd = MLX_CMD_READSG; cmd = MLX_CMD_READSG;
} else { } else {
@ -1772,13 +1772,13 @@ mlx_startio(struct mlx_softc *sc)
mlx_mapcmd(mc); mlx_mapcmd(mc);
/* build a suitable I/O command (assumes 512-byte rounded transfers) */ /* build a suitable I/O command (assumes 512-byte rounded transfers) */
mlxd = (struct mlxd_softc *)bp->bio_dev->si_drv1; mlxd = (struct mlxd_softc *)MLX_BIO_SOFTC(bp);
driveno = mlxd->mlxd_drive - sc->mlx_sysdrive; driveno = mlxd->mlxd_drive - sc->mlx_sysdrive;
blkcount = (bp->bio_bcount + MLX_BLKSIZE - 1) / MLX_BLKSIZE; blkcount = (MLX_BIO_LENGTH(bp) + MLX_BLKSIZE - 1) / MLX_BLKSIZE;
if ((bp->bio_pblkno + blkcount) > sc->mlx_sysdrive[driveno].ms_size) if ((MLX_BIO_LBA(bp) + blkcount) > sc->mlx_sysdrive[driveno].ms_size)
device_printf(sc->mlx_dev, "I/O beyond end of unit (%u,%d > %u)\n", device_printf(sc->mlx_dev, "I/O beyond end of unit (%u,%d > %u)\n",
bp->bio_pblkno, blkcount, sc->mlx_sysdrive[driveno].ms_size); MLX_BIO_LBA(bp), blkcount, sc->mlx_sysdrive[driveno].ms_size);
/* /*
* Build the I/O command. Note that the SG list type bits are set to zero, * Build the I/O command. Note that the SG list type bits are set to zero,
@ -1787,7 +1787,7 @@ mlx_startio(struct mlx_softc *sc)
if (sc->mlx_iftype == MLX_IFTYPE_2) { if (sc->mlx_iftype == MLX_IFTYPE_2) {
mlx_make_type1(mc, (cmd == MLX_CMD_WRITESG) ? MLX_CMD_WRITESG_OLD : MLX_CMD_READSG_OLD, mlx_make_type1(mc, (cmd == MLX_CMD_WRITESG) ? MLX_CMD_WRITESG_OLD : MLX_CMD_READSG_OLD,
blkcount & 0xff, /* xfer length low byte */ blkcount & 0xff, /* xfer length low byte */
bp->bio_pblkno, /* physical block number */ MLX_BIO_LBA(bp), /* physical block number */
driveno, /* target drive number */ driveno, /* target drive number */
mc->mc_sgphys, /* location of SG list */ mc->mc_sgphys, /* location of SG list */
mc->mc_nsgent & 0x3f); /* size of SG list (top 3 bits clear) */ mc->mc_nsgent & 0x3f); /* size of SG list (top 3 bits clear) */
@ -1795,7 +1795,7 @@ mlx_startio(struct mlx_softc *sc)
mlx_make_type5(mc, cmd, mlx_make_type5(mc, cmd,
blkcount & 0xff, /* xfer length low byte */ blkcount & 0xff, /* xfer length low byte */
(driveno << 3) | ((blkcount >> 8) & 0x07), /* target and length high 3 bits */ (driveno << 3) | ((blkcount >> 8) & 0x07), /* target and length high 3 bits */
bp->bio_pblkno, /* physical block number */ MLX_BIO_LBA(bp), /* physical block number */
mc->mc_sgphys, /* location of SG list */ mc->mc_sgphys, /* location of SG list */
mc->mc_nsgent & 0x3f); /* size of SG list (top 3 bits clear) */ mc->mc_nsgent & 0x3f); /* size of SG list (top 3 bits clear) */
} }
@ -1819,12 +1819,11 @@ static void
mlx_completeio(struct mlx_command *mc) mlx_completeio(struct mlx_command *mc)
{ {
struct mlx_softc *sc = mc->mc_sc; struct mlx_softc *sc = mc->mc_sc;
struct bio *bp = (struct bio *)mc->mc_private; mlx_bio *bp = (mlx_bio *)mc->mc_private;
struct mlxd_softc *mlxd = (struct mlxd_softc *)bp->bio_dev->si_drv1; struct mlxd_softc *mlxd = (struct mlxd_softc *)MLX_BIO_SOFTC(bp);
if (mc->mc_status != MLX_STATUS_OK) { /* could be more verbose here? */ if (mc->mc_status != MLX_STATUS_OK) { /* could be more verbose here? */
bp->bio_error = EIO; MLX_BIO_SET_ERROR(bp, EIO);
bp->bio_flags |= BIO_ERROR;
switch(mc->mc_status) { switch(mc->mc_status) {
case MLX_STATUS_RDWROFFLINE: /* system drive has gone offline */ case MLX_STATUS_RDWROFFLINE: /* system drive has gone offline */
@ -1837,7 +1836,7 @@ mlx_completeio(struct mlx_command *mc)
device_printf(sc->mlx_dev, "I/O error - %s\n", mlx_diagnose_command(mc)); device_printf(sc->mlx_dev, "I/O error - %s\n", mlx_diagnose_command(mc));
#if 0 #if 0
device_printf(sc->mlx_dev, " b_bcount %ld blkcount %ld b_pblkno %d\n", device_printf(sc->mlx_dev, " b_bcount %ld blkcount %ld b_pblkno %d\n",
bp->bio_bcount, bp->bio_bcount / MLX_BLKSIZE, bp->bio_pblkno); MLX_BIO_LENGTH(bp), MLX_BIO_LENGTH(bp) / MLX_BLKSIZE, MLX_BIO_LBA(bp));
device_printf(sc->mlx_dev, " %13D\n", mc->mc_mailbox, " "); device_printf(sc->mlx_dev, " %13D\n", mc->mc_mailbox, " ");
#endif #endif
break; break;

77
sys/dev/mlx/mlx_compat.h Normal file
View File

@ -0,0 +1,77 @@
/*-
* Copyright (c) 2000, 2001 Michael Smith
* Copyright (c) 2000 BSDi
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/*
* Portability and compatibility interfaces.
*/
#if __FreeBSD_version < 500003
# include <machine/clock.h>
# define INTR_ENTROPY 0
# include <sys/buf.h> /* old buf style */
typedef struct buf mlx_bio;
typedef struct buf_queue_head mlx_bioq;
# define MLX_BIO_QINIT(bq) bufq_init(&bq);
# define MLX_BIO_QINSERT(bq, bp) bufq_insert_tail(&bq, bp)
# define MLX_BIO_QFIRST(bq) bufq_first(&bq)
# define MLX_BIO_QREMOVE(bq, bp) bufq_remove(&bq, bp)
# define MLX_BIO_IS_READ(bp) ((bp)->b_flags & B_READ)
# define MLX_BIO_DATA(bp) (bp)->b_data
# define MLX_BIO_LENGTH(bp) (bp)->b_bcount
# define MLX_BIO_LBA(bp) (bp)->b_pblkno
# define MLX_BIO_SOFTC(bp) (bp)->b_dev->si_drv1
# define MLX_BIO_UNIT(bp) *(int *)((bp)->b_dev->si_drv2)
# define MLX_BIO_SET_ERROR(bp, err) do { (bp)->b_error = err; (bp)->b_flags |= B_ERROR;} while(0)
# define MLX_BIO_HAS_ERROR(bp) ((bp)->b_flags & B_ERROR)
# define MLX_BIO_RESID(bp) (bp)->b_resid
# define MLX_BIO_DONE(bp) biodone(bp)
# define MLX_BIO_STATS_START(bp) devstat_start_transaction(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats)
# define MLX_BIO_STATS_END(bp) devstat_end_transaction_buf(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats, bp)
#else
# include <sys/bio.h>
typedef struct bio mlx_bio;
typedef struct bio_queue_head mlx_bioq;
# define MLX_BIO_QINIT(bq) bioq_init(&bq);
# define MLX_BIO_QINSERT(bq, bp) bioq_insert_tail(&bq, bp)
# define MLX_BIO_QFIRST(bq) bioq_first(&bq)
# define MLX_BIO_QREMOVE(bq, bp) bioq_remove(&bq, bp)
# define MLX_BIO_IS_READ(bp) ((bp)->bio_cmd == BIO_READ)
# define MLX_BIO_DATA(bp) (bp)->bio_data
# define MLX_BIO_LENGTH(bp) (bp)->bio_bcount
# define MLX_BIO_LBA(bp) (bp)->bio_pblkno
# define MLX_BIO_SOFTC(bp) (bp)->bio_dev->si_drv1
# define MLX_BIO_UNIT(bp) *(int *)((bp)->bio_dev->si_drv2)
# define MLX_BIO_SET_ERROR(bp, err) do { (bp)->bio_error = err; (bp)->bio_flags |= BIO_ERROR;} while(0)
# define MLX_BIO_HAS_ERROR(bp) ((bp)->bio_flags & BIO_ERROR)
# define MLX_BIO_RESID(bp) (bp)->bio_resid
# define MLX_BIO_DONE(bp) biodone(bp) /* XXX nice to integrate bio_finish here */
# define MLX_BIO_STATS_START(bp) devstat_start_transaction(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats)
# define MLX_BIO_STATS_END(bp) devstat_end_transaction_bio(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats, bp)
#endif

View File

@ -35,7 +35,6 @@
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/bio.h>
#include <sys/bus.h> #include <sys/bus.h>
#include <sys/conf.h> #include <sys/conf.h>
#include <sys/devicestat.h> #include <sys/devicestat.h>
@ -44,6 +43,7 @@
#include <machine/bus.h> #include <machine/bus.h>
#include <sys/rman.h> #include <sys/rman.h>
#include <dev/mlx/mlx_compat.h>
#include <dev/mlx/mlxio.h> #include <dev/mlx/mlxio.h>
#include <dev/mlx/mlxvar.h> #include <dev/mlx/mlxvar.h>
#include <dev/mlx/mlxreg.h> #include <dev/mlx/mlxreg.h>
@ -161,53 +161,51 @@ mlxd_ioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct proc *p)
* be a multiple of a sector in length. * be a multiple of a sector in length.
*/ */
static void static void
mlxd_strategy(struct bio *bp) mlxd_strategy(mlx_bio *bp)
{ {
struct mlxd_softc *sc = (struct mlxd_softc *)bp->bio_dev->si_drv1; struct mlxd_softc *sc = (struct mlxd_softc *)MLX_BIO_SOFTC(bp);
debug_called(1); debug_called(1);
/* bogus disk? */ /* bogus disk? */
if (sc == NULL) { if (sc == NULL) {
bp->bio_error = EINVAL; MLX_BIO_SET_ERROR(bp, EINVAL);
goto bad; goto bad;
} }
/* XXX may only be temporarily offline - sleep? */ /* XXX may only be temporarily offline - sleep? */
if (sc->mlxd_drive->ms_state == MLX_SYSD_OFFLINE) { if (sc->mlxd_drive->ms_state == MLX_SYSD_OFFLINE) {
bp->bio_error = ENXIO; MLX_BIO_SET_ERROR(bp, ENXIO);
goto bad; goto bad;
} }
devstat_start_transaction(&sc->mlxd_stats); MLX_BIO_STATS_START(bp);
mlx_submit_buf(sc->mlxd_controller, bp); mlx_submit_buf(sc->mlxd_controller, bp);
return; return;
bad: bad:
bp->bio_flags |= BIO_ERROR;
/* /*
* Correctly set the buf to indicate a completed transfer * Correctly set the bio to indicate a failed tranfer.
*/ */
bp->bio_resid = bp->bio_bcount; MLX_BIO_RESID(bp) = MLX_BIO_LENGTH(bp);
biodone(bp); MLX_BIO_DONE(bp);
return; return;
} }
void void
mlxd_intr(void *data) mlxd_intr(void *data)
{ {
struct bio *bp = (struct bio *)data; mlx_bio *bp = (mlx_bio *)data;
struct mlxd_softc *sc = (struct mlxd_softc *)bp->bio_dev->si_drv1;
debug_called(1); debug_called(1);
if (bp->bio_flags & BIO_ERROR) if (MLX_BIO_HAS_ERROR(bp))
bp->bio_error = EIO; MLX_BIO_SET_ERROR(bp, EIO);
else else
bp->bio_resid = 0; MLX_BIO_RESID(bp) = 0;
biofinish(bp, &sc->mlxd_stats, 0); MLX_BIO_STATS_END(bp);
MLX_BIO_DONE(bp);
} }
static int static int

View File

@ -31,7 +31,6 @@
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/bus.h> #include <sys/bus.h>
#include <sys/bio.h>
#include <sys/conf.h> #include <sys/conf.h>
#include <sys/devicestat.h> #include <sys/devicestat.h>
#include <sys/disk.h> #include <sys/disk.h>
@ -45,6 +44,7 @@
#include <pci/pcireg.h> #include <pci/pcireg.h>
#include <pci/pcivar.h> #include <pci/pcivar.h>
#include <dev/mlx/mlx_compat.h>
#include <dev/mlx/mlxio.h> #include <dev/mlx/mlxio.h>
#include <dev/mlx/mlxvar.h> #include <dev/mlx/mlxvar.h>
#include <dev/mlx/mlxreg.h> #include <dev/mlx/mlxreg.h>

View File

@ -135,7 +135,7 @@ struct mlx_softc
struct mlx_command *mlx_busycmd[MLX_NSLOTS]; /* busy commands */ struct mlx_command *mlx_busycmd[MLX_NSLOTS]; /* busy commands */
int mlx_busycmds; /* count of busy commands */ int mlx_busycmds; /* count of busy commands */
struct mlx_sysdrive mlx_sysdrive[MLX_MAXDRIVES]; /* system drives */ struct mlx_sysdrive mlx_sysdrive[MLX_MAXDRIVES]; /* system drives */
struct bio_queue_head mlx_bioq; /* outstanding I/O operations */ mlx_bioq mlx_bioq; /* outstanding I/O operations */
int mlx_waitbufs; /* number of bufs awaiting commands */ int mlx_waitbufs; /* number of bufs awaiting commands */
/* controller status */ /* controller status */
@ -239,7 +239,7 @@ struct mlxd_softc
/* /*
* Interface between driver core and disk driver (should be using a bus?) * Interface between driver core and disk driver (should be using a bus?)
*/ */
extern int mlx_submit_buf(struct mlx_softc *sc, struct bio *bp); extern int mlx_submit_buf(struct mlx_softc *sc, mlx_bio *bp);
extern int mlx_submit_ioctl(struct mlx_softc *sc, struct mlx_sysdrive *drive, u_long cmd, extern int mlx_submit_ioctl(struct mlx_softc *sc, struct mlx_sysdrive *drive, u_long cmd,
caddr_t addr, int32_t flag, struct proc *p); caddr_t addr, int32_t flag, struct proc *p);
extern void mlxd_intr(void *data); extern void mlxd_intr(void *data);