xref: /freebsd/sys/dev/ida/idavar.h (revision 815308668ae3e9056e84b4b34f40ecc228f6d382)
1db57feb7SJonathan Lemon /*-
2ee7eb00eSJonathan Lemon  * Copyright (c) 1999,2000 Jonathan Lemon
3db57feb7SJonathan Lemon  * All rights reserved.
4db57feb7SJonathan Lemon  *
5db57feb7SJonathan Lemon  * Redistribution and use in source and binary forms, with or without
6db57feb7SJonathan Lemon  * modification, are permitted provided that the following conditions
7db57feb7SJonathan Lemon  * are met:
8db57feb7SJonathan Lemon  * 1. Redistributions of source code must retain the above copyright
9db57feb7SJonathan Lemon  *    notice, this list of conditions and the following disclaimer.
10db57feb7SJonathan Lemon  * 2. Redistributions in binary form must reproduce the above copyright
11db57feb7SJonathan Lemon  *    notice, this list of conditions and the following disclaimer in the
12db57feb7SJonathan Lemon  *    documentation and/or other materials provided with the distribution.
13db57feb7SJonathan Lemon  *
14db57feb7SJonathan Lemon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15db57feb7SJonathan Lemon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16db57feb7SJonathan Lemon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17db57feb7SJonathan Lemon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18db57feb7SJonathan Lemon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19db57feb7SJonathan Lemon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20db57feb7SJonathan Lemon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21db57feb7SJonathan Lemon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22db57feb7SJonathan Lemon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23db57feb7SJonathan Lemon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24db57feb7SJonathan Lemon  * SUCH DAMAGE.
25db57feb7SJonathan Lemon  *
26c3aac50fSPeter Wemm  * $FreeBSD$
27db57feb7SJonathan Lemon  */
28db57feb7SJonathan Lemon 
29db57feb7SJonathan Lemon /*
30db57feb7SJonathan Lemon  * software structures for the Compaq RAID controller
31db57feb7SJonathan Lemon  */
32db57feb7SJonathan Lemon 
33db57feb7SJonathan Lemon #ifndef _IDAVAR_H
34db57feb7SJonathan Lemon #define _IDAVAR_H
35db57feb7SJonathan Lemon 
36ee7eb00eSJonathan Lemon #define ida_inb(ida, port) \
37ee7eb00eSJonathan Lemon 	bus_space_read_1((ida)->tag, (ida)->bsh, port)
38ee7eb00eSJonathan Lemon #define ida_inw(ida, port) \
39ee7eb00eSJonathan Lemon 	bus_space_read_2((ida)->tag, (ida)->bsh, port)
40ee7eb00eSJonathan Lemon #define ida_inl(ida, port) \
41ee7eb00eSJonathan Lemon 	bus_space_read_4((ida)->tag, (ida)->bsh, port)
42ee7eb00eSJonathan Lemon 
43ee7eb00eSJonathan Lemon #define ida_outb(ida, port, val) \
44ee7eb00eSJonathan Lemon 	bus_space_write_1((ida)->tag, (ida)->bsh, port, val)
45ee7eb00eSJonathan Lemon #define ida_outw(ida, port, val) \
46ee7eb00eSJonathan Lemon 	bus_space_write_2((ida)->tag, (ida)->bsh, port, val)
47ee7eb00eSJonathan Lemon #define ida_outl(ida, port, val) \
48ee7eb00eSJonathan Lemon 	bus_space_write_4((ida)->tag, (ida)->bsh, port, val)
49ee7eb00eSJonathan Lemon 
50db57feb7SJonathan Lemon struct ida_hdr {
51db57feb7SJonathan Lemon 	u_int8_t	drive;		/* logical drive */
52db57feb7SJonathan Lemon 	u_int8_t	priority;	/* block priority */
53db57feb7SJonathan Lemon 	u_int16_t	size;		/* size of request, in words */
54db57feb7SJonathan Lemon };
55db57feb7SJonathan Lemon 
56db57feb7SJonathan Lemon struct ida_req {
57db57feb7SJonathan Lemon 	u_int16_t	next;		/* offset of next request */
58db57feb7SJonathan Lemon 	u_int8_t	command;	/* command */
59db57feb7SJonathan Lemon 	u_int8_t	error;		/* return error code */
60db57feb7SJonathan Lemon 	u_int32_t	blkno;		/* block number */
61db57feb7SJonathan Lemon 	u_int16_t	bcount;		/* block count */
62db57feb7SJonathan Lemon 	u_int8_t	sgcount;	/* number of scatter/gather entries */
63db57feb7SJonathan Lemon 	u_int8_t	spare;		/* reserved */
64db57feb7SJonathan Lemon };
65db57feb7SJonathan Lemon 
66db57feb7SJonathan Lemon struct ida_sgb {
67db57feb7SJonathan Lemon 	u_int32_t	length;		/* length of S/G segment */
68db57feb7SJonathan Lemon 	u_int32_t	addr;		/* physical address of block */
69db57feb7SJonathan Lemon };
70db57feb7SJonathan Lemon 
71db57feb7SJonathan Lemon #define IDA_NSEG	32		/* maximum number of segments */
72db57feb7SJonathan Lemon 
73db57feb7SJonathan Lemon /*
74db57feb7SJonathan Lemon  * right now, this structure totals 276 bytes.
75db57feb7SJonathan Lemon  */
76db57feb7SJonathan Lemon struct ida_hardware_qcb {
77db57feb7SJonathan Lemon 	struct 	ida_hdr hdr;			/*   4 */
78db57feb7SJonathan Lemon 	struct 	ida_req req;			/*  12 */
79db57feb7SJonathan Lemon 	struct 	ida_sgb seg[IDA_NSEG];		/* 256 */
80db57feb7SJonathan Lemon 	struct	ida_qcb *qcb;			/*   4 - qcb backpointer */
81db57feb7SJonathan Lemon };
82db57feb7SJonathan Lemon 
83db57feb7SJonathan Lemon typedef enum {
84db57feb7SJonathan Lemon 	QCB_FREE		= 0x0000,
85db57feb7SJonathan Lemon 	QCB_ACTIVE		= 0x0001,	/* waiting for completion */
86db57feb7SJonathan Lemon } qcb_state;
87db57feb7SJonathan Lemon 
88db57feb7SJonathan Lemon #define	DMA_DATA_IN	0x0001
89db57feb7SJonathan Lemon #define	DMA_DATA_OUT	0x0002
90db57feb7SJonathan Lemon #define IDA_COMMAND	0x0004
91db57feb7SJonathan Lemon #define DMA_DATA_TRANSFER	(DMA_DATA_IN | DMA_DATA_OUT)
92db57feb7SJonathan Lemon 
93db57feb7SJonathan Lemon #define IDA_QCB_MAX	256
94db57feb7SJonathan Lemon #define IDA_CONTROLLER	0		/* drive "number" for controller */
95db57feb7SJonathan Lemon 
96db57feb7SJonathan Lemon struct ida_qcb {
97db57feb7SJonathan Lemon 	struct		ida_hardware_qcb *hwqcb;
98db57feb7SJonathan Lemon 	qcb_state	state;
99db57feb7SJonathan Lemon 	short		flags;
100db57feb7SJonathan Lemon 	union {
101db57feb7SJonathan Lemon 		STAILQ_ENTRY(ida_qcb) stqe;
102db57feb7SJonathan Lemon 		SLIST_ENTRY(ida_qcb) sle;
103db57feb7SJonathan Lemon 	} link;
104db57feb7SJonathan Lemon 	bus_dmamap_t	dmamap;
105ee7eb00eSJonathan Lemon 	bus_addr_t	hwqcb_busaddr;
1068177437dSPoul-Henning Kamp 	struct		bio *buf;		/* bio associated with qcb */
107db57feb7SJonathan Lemon };
108db57feb7SJonathan Lemon 
109ee7eb00eSJonathan Lemon struct ida_softc;
110ee7eb00eSJonathan Lemon 
111ee7eb00eSJonathan Lemon struct ida_access {
112ee7eb00eSJonathan Lemon 	int		(*fifo_full)(struct ida_softc *);
113ee7eb00eSJonathan Lemon 	void		(*submit)(struct ida_softc *, struct ida_qcb *);
114ee7eb00eSJonathan Lemon 	bus_addr_t	(*done)(struct ida_softc *);
115ee7eb00eSJonathan Lemon 	int		(*int_pending)(struct ida_softc *);
116ee7eb00eSJonathan Lemon 	void		(*int_enable)(struct ida_softc *, int);
117ee7eb00eSJonathan Lemon };
118ee7eb00eSJonathan Lemon 
119db57feb7SJonathan Lemon /*
120db57feb7SJonathan Lemon  * flags for the controller
121db57feb7SJonathan Lemon  */
122db57feb7SJonathan Lemon #define IDA_ATTACHED	0x01			/* attached, interrupts okay */
123db57feb7SJonathan Lemon 
124db57feb7SJonathan Lemon struct ida_softc {
125db57feb7SJonathan Lemon 	device_t	dev;
126db57feb7SJonathan Lemon 	int		unit;
127db57feb7SJonathan Lemon 
128db57feb7SJonathan Lemon 	int		regs_res_type;
129db57feb7SJonathan Lemon 	int		regs_res_id;
130db57feb7SJonathan Lemon 	struct 		resource *regs;
131db57feb7SJonathan Lemon 
132db57feb7SJonathan Lemon 	int		irq_res_type;
133db57feb7SJonathan Lemon 	struct		resource *irq;
134db57feb7SJonathan Lemon 	void		*ih;
135db57feb7SJonathan Lemon 
136db57feb7SJonathan Lemon 	bus_space_tag_t		tag;
137db57feb7SJonathan Lemon 	bus_space_handle_t	bsh;
138db57feb7SJonathan Lemon 
139db57feb7SJonathan Lemon 	/* various DMA tags */
140db57feb7SJonathan Lemon 	bus_dma_tag_t	parent_dmat;
141db57feb7SJonathan Lemon 	bus_dma_tag_t	buffer_dmat;
142db57feb7SJonathan Lemon 
143db57feb7SJonathan Lemon 	bus_dma_tag_t	hwqcb_dmat;
144db57feb7SJonathan Lemon 	bus_dmamap_t	hwqcb_dmamap;
145db57feb7SJonathan Lemon 	bus_addr_t	hwqcb_busaddr;
146db57feb7SJonathan Lemon 
147db57feb7SJonathan Lemon 	bus_dma_tag_t	sg_dmat;
148db57feb7SJonathan Lemon 
149db57feb7SJonathan Lemon 	int		num_drives;
150db57feb7SJonathan Lemon 	int		num_qcbs;
151db57feb7SJonathan Lemon 	int		flags;
152db57feb7SJonathan Lemon 
153db57feb7SJonathan Lemon 	struct		ida_hardware_qcb *hwqcbs;	/* HW QCB array */
154db57feb7SJonathan Lemon 	struct		ida_qcb *qcbs;			/* kernel QCB array */
155db57feb7SJonathan Lemon 	SLIST_HEAD(, ida_qcb)	free_qcbs;
156db57feb7SJonathan Lemon 	STAILQ_HEAD(, ida_qcb) 	qcb_queue;
1578177437dSPoul-Henning Kamp 	struct		bio_queue_head bio_queue;
158ee7eb00eSJonathan Lemon 
159ee7eb00eSJonathan Lemon 	struct		ida_access cmd;
160db57feb7SJonathan Lemon };
161db57feb7SJonathan Lemon 
162db57feb7SJonathan Lemon /*
163db57feb7SJonathan Lemon  * drive flags
164db57feb7SJonathan Lemon  */
165db57feb7SJonathan Lemon #define DRV_WRITEPROT		0x0001
166db57feb7SJonathan Lemon 
16781530866SMatthew N. Dodd struct idad_softc {
168db57feb7SJonathan Lemon 	device_t	dev;
169db57feb7SJonathan Lemon 	struct 		ida_softc *controller;
170ee7eb00eSJonathan Lemon 	struct		disk disk;
171db57feb7SJonathan Lemon 	struct		devstat stats;
172db57feb7SJonathan Lemon 	int		unit;
173db57feb7SJonathan Lemon 	int		cylinders;
174db57feb7SJonathan Lemon 	int		heads;
175db57feb7SJonathan Lemon 	int		sectors;
176db57feb7SJonathan Lemon 	int		secsize;
177db57feb7SJonathan Lemon 	int		secperunit;
178db57feb7SJonathan Lemon 	int		flags;
179db57feb7SJonathan Lemon };
180db57feb7SJonathan Lemon 
181ee7eb00eSJonathan Lemon struct ida_board {
182ee7eb00eSJonathan Lemon 	u_int32_t	board;
183ee7eb00eSJonathan Lemon 	char 		*desc;
184ee7eb00eSJonathan Lemon 	struct		ida_access *accessor;
185ee7eb00eSJonathan Lemon };
186ee7eb00eSJonathan Lemon 
187ee7eb00eSJonathan Lemon extern int ida_detach(device_t dev);
188db57feb7SJonathan Lemon extern struct ida_softc *ida_alloc(device_t dev, struct resource *regs,
189db57feb7SJonathan Lemon 	int regs_type, int regs_id, bus_dma_tag_t parent_dmat);
190db57feb7SJonathan Lemon extern void ida_free(struct ida_softc *ida);
191db57feb7SJonathan Lemon extern int ida_init(struct ida_softc *ida);
192db57feb7SJonathan Lemon extern void ida_attach(struct ida_softc *ida);
193db57feb7SJonathan Lemon extern int ida_command(struct ida_softc *ida, int command, void *data,
194db57feb7SJonathan Lemon 	int datasize, int drive, int flags);
1958177437dSPoul-Henning Kamp extern void ida_submit_buf(struct ida_softc *ida, struct bio *bp);
196db57feb7SJonathan Lemon extern void ida_intr(void *data);
197db57feb7SJonathan Lemon 
19881530866SMatthew N. Dodd extern void idad_intr(struct bio *bp);
199db57feb7SJonathan Lemon 
200db57feb7SJonathan Lemon #endif /* _IDAVAR_H */
201