Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / raid / mlx / mlx_compat.h
1 /*-
2  * Copyright (c) 2000, 2001 Michael Smith
3  * Copyright (c) 2000 BSDi
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: src/sys/dev/mlx/mlx_compat.h,v 1.1.2.1 2001/06/25 04:37:51 msmith Exp $
28  */
29 /*
30  * Portability and compatibility interfaces.
31  */
32
33 #if __FreeBSD_version < 500003
34 # include <machine/clock.h>
35 # define INTR_ENTROPY                   0
36
37 # include <sys/buf.h>                   /* old buf style */
38 typedef struct buf                      mlx_bio;
39 typedef struct buf_queue_head           mlx_bioq;
40 # define MLX_BIO_QINIT(bq)              bufq_init(&bq);
41 # define MLX_BIO_QINSERT(bq, bp)        bufq_insert_tail(&bq, bp)
42 # define MLX_BIO_QFIRST(bq)             bufq_first(&bq)
43 # define MLX_BIO_QREMOVE(bq, bp)        bufq_remove(&bq, bp)
44 # define MLX_BIO_IS_READ(bp)            ((bp)->b_flags & B_READ)
45 # define MLX_BIO_DATA(bp)               (bp)->b_data
46 # define MLX_BIO_LENGTH(bp)             (bp)->b_bcount
47 # define MLX_BIO_LBA(bp)                (bp)->b_pblkno
48 # define MLX_BIO_SOFTC(bp)              (bp)->b_dev->si_drv1
49 # define MLX_BIO_UNIT(bp)               *(int *)((bp)->b_dev->si_drv2)
50 # define MLX_BIO_SET_ERROR(bp, err)     do { (bp)->b_error = err; (bp)->b_flags |= B_ERROR;} while(0)
51 # define MLX_BIO_HAS_ERROR(bp)          ((bp)->b_flags & B_ERROR)
52 # define MLX_BIO_RESID(bp)              (bp)->b_resid
53 # define MLX_BIO_DONE(bp)               biodone(bp)
54 # define MLX_BIO_STATS_START(bp)        devstat_start_transaction(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats)
55 # define MLX_BIO_STATS_END(bp)          devstat_end_transaction_buf(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats, bp)
56 #else
57 # include <sys/bio.h>
58 typedef struct bio                      mlx_bio;
59 typedef struct bio_queue_head           mlx_bioq;
60 # define MLX_BIO_QINIT(bq)              bioq_init(&bq);
61 # define MLX_BIO_QINSERT(bq, bp)        bioq_insert_tail(&bq, bp)
62 # define MLX_BIO_QFIRST(bq)             bioq_first(&bq)
63 # define MLX_BIO_QREMOVE(bq, bp)        bioq_remove(&bq, bp)
64 # define MLX_BIO_IS_READ(bp)            ((bp)->bio_cmd == BIO_READ)
65 # define MLX_BIO_DATA(bp)               (bp)->bio_data
66 # define MLX_BIO_LENGTH(bp)             (bp)->bio_bcount
67 # define MLX_BIO_LBA(bp)                (bp)->bio_pblkno
68 # define MLX_BIO_SOFTC(bp)              (bp)->bio_dev->si_drv1
69 # define MLX_BIO_UNIT(bp)               *(int *)((bp)->bio_dev->si_drv2)
70 # define MLX_BIO_SET_ERROR(bp, err)     do { (bp)->bio_error = err; (bp)->bio_flags |= BIO_ERROR;} while(0)
71 # define MLX_BIO_HAS_ERROR(bp)          ((bp)->bio_flags & BIO_ERROR)
72 # define MLX_BIO_RESID(bp)              (bp)->bio_resid
73 # define MLX_BIO_DONE(bp)               biodone(bp)     /* XXX nice to integrate bio_finish here */
74 # define MLX_BIO_STATS_START(bp)        devstat_start_transaction(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats)
75 # define MLX_BIO_STATS_END(bp)          devstat_end_transaction_bio(&((struct mlxd_softc *)MLX_BIO_SOFTC(bp))->mlxd_stats, bp)
76 #endif
77