xref: /freebsd/sys/dev/ida/idavar.h (revision 89c9c53da05197f657dfe8e0bdda6941a2e9a0d4)
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 {
101e3975643SJake Burkholder 		STAILQ_ENTRY(ida_qcb) stqe;
102e3975643SJake Burkholder 		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  */
12255d782fcSJonathan Lemon #define	IDA_ATTACHED	0x01		/* attached */
1231277c3baSJonathan Lemon #define	IDA_FIRMWARE	0x02		/* firmware must be started */
12455d782fcSJonathan Lemon #define	IDA_INTERRUPTS	0x04		/* interrupts enabled */
125db57feb7SJonathan Lemon 
126db57feb7SJonathan Lemon struct ida_softc {
127db57feb7SJonathan Lemon 	device_t	dev;
128db57feb7SJonathan Lemon 	int		unit;
12989c9c53dSPoul-Henning Kamp 	struct cdev *ida_dev_t;
130db57feb7SJonathan Lemon 
131db57feb7SJonathan Lemon 	int		regs_res_type;
132db57feb7SJonathan Lemon 	int		regs_res_id;
133db57feb7SJonathan Lemon 	struct 		resource *regs;
134db57feb7SJonathan Lemon 
135db57feb7SJonathan Lemon 	int		irq_res_type;
136db57feb7SJonathan Lemon 	struct		resource *irq;
137db57feb7SJonathan Lemon 	void		*ih;
138db57feb7SJonathan Lemon 
139db57feb7SJonathan Lemon 	bus_space_tag_t		tag;
140db57feb7SJonathan Lemon 	bus_space_handle_t	bsh;
141db57feb7SJonathan Lemon 
142db57feb7SJonathan Lemon 	/* various DMA tags */
143db57feb7SJonathan Lemon 	bus_dma_tag_t	parent_dmat;
144db57feb7SJonathan Lemon 	bus_dma_tag_t	buffer_dmat;
145db57feb7SJonathan Lemon 
146db57feb7SJonathan Lemon 	bus_dma_tag_t	hwqcb_dmat;
147db57feb7SJonathan Lemon 	bus_dmamap_t	hwqcb_dmamap;
148db57feb7SJonathan Lemon 	bus_addr_t	hwqcb_busaddr;
149db57feb7SJonathan Lemon 
150db57feb7SJonathan Lemon 	bus_dma_tag_t	sg_dmat;
151db57feb7SJonathan Lemon 
152db57feb7SJonathan Lemon 	int		num_drives;
153db57feb7SJonathan Lemon 	int		num_qcbs;
154db57feb7SJonathan Lemon 	int		flags;
155db57feb7SJonathan Lemon 
156db57feb7SJonathan Lemon 	struct		ida_hardware_qcb *hwqcbs;	/* HW QCB array */
157db57feb7SJonathan Lemon 	struct		ida_qcb *qcbs;			/* kernel QCB array */
158e3975643SJake Burkholder 	SLIST_HEAD(, ida_qcb)	free_qcbs;
159e3975643SJake Burkholder 	STAILQ_HEAD(, ida_qcb) 	qcb_queue;
1608177437dSPoul-Henning Kamp 	struct		bio_queue_head bio_queue;
161ee7eb00eSJonathan Lemon 
162ee7eb00eSJonathan Lemon 	struct		ida_access cmd;
163db57feb7SJonathan Lemon };
164db57feb7SJonathan Lemon 
165db57feb7SJonathan Lemon /*
166db57feb7SJonathan Lemon  * drive flags
167db57feb7SJonathan Lemon  */
168db57feb7SJonathan Lemon #define	DRV_WRITEPROT		0x0001
169db57feb7SJonathan Lemon 
17081530866SMatthew N. Dodd struct idad_softc {
171db57feb7SJonathan Lemon 	device_t	dev;
172db57feb7SJonathan Lemon 	struct 		ida_softc *controller;
1730b7ed341SPoul-Henning Kamp 	struct		disk *disk;
1741277c3baSJonathan Lemon 	int		drive;			/* per controller */
1751277c3baSJonathan Lemon 	int		unit;			/* global */
176db57feb7SJonathan Lemon 	int		cylinders;
177db57feb7SJonathan Lemon 	int		heads;
178db57feb7SJonathan Lemon 	int		sectors;
179db57feb7SJonathan Lemon 	int		secsize;
180db57feb7SJonathan Lemon 	int		secperunit;
181db57feb7SJonathan Lemon 	int		flags;
182db57feb7SJonathan Lemon };
183db57feb7SJonathan Lemon 
184ee7eb00eSJonathan Lemon struct ida_board {
185ee7eb00eSJonathan Lemon 	u_int32_t	board;
186ee7eb00eSJonathan Lemon 	char 		*desc;
187ee7eb00eSJonathan Lemon 	struct		ida_access *accessor;
1887c258c0eSJonathan Lemon 	int		flags;
189ee7eb00eSJonathan Lemon };
190ee7eb00eSJonathan Lemon 
191ee7eb00eSJonathan Lemon extern int ida_detach(device_t dev);
192db57feb7SJonathan Lemon extern struct ida_softc *ida_alloc(device_t dev, struct resource *regs,
193db57feb7SJonathan Lemon 	int regs_type, int regs_id, bus_dma_tag_t parent_dmat);
194db57feb7SJonathan Lemon extern void ida_free(struct ida_softc *ida);
195db57feb7SJonathan Lemon extern int ida_init(struct ida_softc *ida);
196db57feb7SJonathan Lemon extern void ida_attach(struct ida_softc *ida);
197db57feb7SJonathan Lemon extern int ida_command(struct ida_softc *ida, int command, void *data,
19855d782fcSJonathan Lemon 	int datasize, int drive, u_int32_t pblkno, int flags);
1998177437dSPoul-Henning Kamp extern void ida_submit_buf(struct ida_softc *ida, struct bio *bp);
200db57feb7SJonathan Lemon extern void ida_intr(void *data);
201db57feb7SJonathan Lemon 
20281530866SMatthew N. Dodd extern void idad_intr(struct bio *bp);
203db57feb7SJonathan Lemon 
204db57feb7SJonathan Lemon #endif /* _IDAVAR_H */
205