amrvar.h revision 51974
1/*-
2 * Copyright (c) 1999 Michael Smith
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 *      $FreeBSD: head/sys/dev/amr/amrvar.h 51974 1999-10-07 02:23:12Z msmith $
27 */
28
29/*
30 * We could actually use all 17 segments, but using only 16 means that
31 * each scatter/gather map is 128 bytes in size, and thus we don't have to worry about
32 * maps crossing page boundaries.
33 */
34#define AMR_NSEG	16
35
36#define AMR_CFG_BASE	0x10
37#define AMR_CFG_SIG	0xa0
38#define AMR_SIGNATURE	0x3344
39
40#define AMR_MAXCMD	255		/* ident = 0 not allowed */
41#define AMR_MAXLD      	40
42
43#define AMR_BLKSIZE	512
44
45struct amr_softc;
46
47/*
48 * Per-logical-drive datastructure
49 */
50struct amr_logdrive
51{
52    u_int32_t	al_size;
53    int		al_state;
54    int		al_properties;
55
56    /* synthetic geometry */
57    int		al_cylinders;
58    int		al_heads;
59    int		al_sectors;
60
61    /* driver */
62    device_t	al_disk;
63};
64
65
66/*
67 * Per-command control structure.
68 */
69struct amr_command
70{
71    TAILQ_ENTRY(amr_command)	ac_link;
72
73    struct amr_softc		*ac_sc;
74    u_int8_t			ac_slot;
75    int				ac_status;
76#define AMR_STATUS_BUSY		0xffff
77#define AMR_STATUS_WEDGED	0xdead
78    struct amr_mailbox		ac_mailbox;
79    u_int32_t			ac_sgphys;
80    int				ac_nsgent;
81    int				ac_flags;
82#define AMR_CMD_DATAIN		(1<<0)
83#define AMR_CMD_DATAOUT		(1<<1)
84#define AMR_CMD_PRIORITY	(1<<2)
85    time_t			ac_stamp;
86
87    void			*ac_data;
88    size_t			ac_length;
89    bus_dmamap_t		ac_dmamap;
90    u_int32_t			ac_dataphys;
91
92    void			(* ac_complete)(struct amr_command *ac);
93    void			*ac_private;
94};
95
96struct amr_softc
97{
98    /* bus attachments */
99    device_t			amr_dev;
100    struct resource		*amr_reg;		/* control registers */
101    bus_space_handle_t		amr_bhandle;
102    bus_space_tag_t		amr_btag;
103    bus_dma_tag_t		amr_parent_dmat;	/* parent DMA tag */
104    bus_dma_tag_t		amr_buffer_dmat;	/* data buffer DMA tag */
105    struct resource		*amr_irq;		/* interrupt */
106    void			*amr_intr;
107
108    /* mailbox */
109    struct amr_mailbox		*amr_mailbox;
110    struct amr_mailbox64	*amr_mailbox64;
111    u_int32_t			amr_mailboxphys;
112    bus_dma_tag_t		amr_mailbox_dmat;
113    bus_dmamap_t		amr_mailbox_dmamap;
114
115    /* scatter/gather lists and their controller-visible mappings */
116    struct amr_sgentry		*amr_sgtable;		/* s/g lists */
117    u_int32_t			amr_sgbusaddr;		/* s/g table base address in bus space */
118    bus_dma_tag_t		amr_sg_dmat;		/* s/g buffer DMA tag */
119    bus_dmamap_t		amr_sg_dmamap;		/* map for s/g buffers */
120
121    /* controller limits and features */
122    int				amr_maxio;		/* maximum number of I/O transactions */
123    int				amr_maxdrives;		/* max number of logical drives */
124
125    /* connected logical drives */
126    struct amr_logdrive		amr_drive[AMR_MAXLD];
127
128    /* controller status */
129    int				amr_state;
130#define AMR_STATE_OPEN		(1<<0)
131#define AMR_STATE_SUSPEND	(1<<1)
132#define AMR_STATE_INTEN		(1<<2)
133#define AMR_STATE_SHUTDOWN	(1<<3)
134
135    /* per-controller queues */
136    struct buf_queue_head 	amr_bufq;		/* pending I/O */
137    int				amr_waitbufs;
138    struct amr_command		*amr_busycmd[AMR_MAXCMD];
139    int				amr_busycmdcount;
140    TAILQ_HEAD(,amr_command)	amr_donecmds;
141    int				amr_donecmdcount;
142    TAILQ_HEAD(,amr_command)	amr_freecmds;
143
144    /* controller type-specific support */
145    int				amr_type;
146#define AMR_TYPE_STD		0
147#define AMR_TYPE_QUARTZ		1
148    void			(* amr_submit_command)(struct amr_softc *sc);
149    int				(* amr_get_work)(struct amr_softc *sc, struct amr_mailbox *mbsave);
150    void			(* amr_attach_mailbox)(struct amr_softc *sc);
151};
152
153/*
154 * I/O primitives
155 */
156/* Quartz */
157#define AMR_QPUT_IDB(sc, val)	bus_space_write_4(sc->amr_btag, sc->amr_bhandle, AMR_QIDB, val)
158#define AMR_QGET_IDB(sc)	bus_space_read_4 (sc->amr_btag, sc->amr_bhandle, AMR_QIDB)
159#define AMR_QPUT_ODB(sc, val)	bus_space_write_4(sc->amr_btag, sc->amr_bhandle, AMR_QODB, val)
160#define AMR_QGET_ODB(sc)	bus_space_read_4 (sc->amr_btag, sc->amr_bhandle, AMR_QODB)
161
162/* Standard */
163#define AMR_SPUT_ISTAT(sc, val)	bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SINTR, val)
164#define AMR_SGET_ISTAT(sc)	bus_space_read_1 (sc->amr_btag, sc->amr_bhandle, AMR_SINTR)
165#define AMR_SACK_INTERRUPT(sc)	bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SCMD, AMR_SCMD_ACKINTR)
166#define AMR_SPOST_COMMAND(sc)	bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_SCMD, AMR_SCMD_POST)
167#define AMR_SGET_MBSTAT(sc)	bus_space_read_1 (sc->amr_btag, sc->amr_bhandle, AMR_SMBOX_BUSY)
168#define AMR_SENABLE_INTR(sc)											\
169	bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE, 						\
170			  bus_space_read_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE) | AMR_STOGL_IENABLE)
171#define AMR_SDISABLE_INTR(sc)											\
172	bus_space_write_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE, 						\
173			  bus_space_read_1(sc->amr_btag, sc->amr_bhandle, AMR_STOGGLE) & ~AMR_STOGL_IENABLE)
174#define AMR_SBYTE_SET(sc, reg, val)	bus_space_write_1(sc->amr_btag, sc->amr_bhandle, reg, val)
175
176/*
177 * Interface between bus connections and driver core.
178 */
179extern void             amr_free(struct amr_softc *sc);
180extern int              amr_attach(struct amr_softc *sc);
181extern void             amr_startup(struct amr_softc *sc);
182extern void             amr_intr(void *data);
183extern int              amr_detach(device_t dev);
184extern int              amr_shutdown(device_t dev);
185extern int              amr_suspend(device_t dev);
186extern int              amr_resume(device_t dev);
187extern d_open_t         amr_open;
188extern d_close_t        amr_close;
189extern d_ioctl_t        amr_ioctl;
190
191extern devclass_t       amr_devclass;
192
193/*
194 * MegaRAID logical disk driver
195 */
196struct amrd_softc
197{
198    device_t		amrd_dev;
199    struct amr_softc	*amrd_controller;
200    struct amr_logdrive	*amrd_drive;
201    struct disk		amrd_disk;
202    struct devstat	amrd_stats;
203    struct disklabel	amrd_label;
204    int			amrd_unit;
205    int			amrd_flags;
206#define AMRD_OPEN	(1<<0)		/* drive is open (can't shut down) */
207};
208
209/*
210 * Interface between driver core and disk driver (should be using a bus?)
211 */
212extern int	amr_submit_buf(struct amr_softc *sc, struct buf *bp);
213extern int	amr_submit_ioctl(struct amr_softc *sc, struct amr_logdrive *drive, u_long cmd,
214				 caddr_t addr, int32_t flag, struct proc *p);
215extern void	amrd_intr(void *data);
216
217