xref: /freebsd/sys/dev/ida/idavar.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1db57feb7SJonathan Lemon /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4ee7eb00eSJonathan Lemon  * Copyright (c) 1999,2000 Jonathan Lemon
5db57feb7SJonathan Lemon  * All rights reserved.
6db57feb7SJonathan Lemon  *
7db57feb7SJonathan Lemon  * Redistribution and use in source and binary forms, with or without
8db57feb7SJonathan Lemon  * modification, are permitted provided that the following conditions
9db57feb7SJonathan Lemon  * are met:
10db57feb7SJonathan Lemon  * 1. Redistributions of source code must retain the above copyright
11db57feb7SJonathan Lemon  *    notice, this list of conditions and the following disclaimer.
12db57feb7SJonathan Lemon  * 2. Redistributions in binary form must reproduce the above copyright
13db57feb7SJonathan Lemon  *    notice, this list of conditions and the following disclaimer in the
14db57feb7SJonathan Lemon  *    documentation and/or other materials provided with the distribution.
15db57feb7SJonathan Lemon  *
16db57feb7SJonathan Lemon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17db57feb7SJonathan Lemon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18db57feb7SJonathan Lemon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19db57feb7SJonathan Lemon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20db57feb7SJonathan Lemon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21db57feb7SJonathan Lemon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22db57feb7SJonathan Lemon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23db57feb7SJonathan Lemon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24db57feb7SJonathan Lemon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25db57feb7SJonathan Lemon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26db57feb7SJonathan Lemon  * SUCH DAMAGE.
27db57feb7SJonathan Lemon  *
28c3aac50fSPeter Wemm  * $FreeBSD$
29db57feb7SJonathan Lemon  */
30db57feb7SJonathan Lemon 
31db57feb7SJonathan Lemon /*
32db57feb7SJonathan Lemon  * software structures for the Compaq RAID controller
33db57feb7SJonathan Lemon  */
34db57feb7SJonathan Lemon 
35db57feb7SJonathan Lemon #ifndef _IDAVAR_H
36db57feb7SJonathan Lemon #define	_IDAVAR_H
37db57feb7SJonathan Lemon 
38ee7eb00eSJonathan Lemon #define	ida_inb(ida, port) \
396b5b57aeSJohn Baldwin 	bus_read_1((ida)->regs, port)
40ee7eb00eSJonathan Lemon #define	ida_inw(ida, port) \
416b5b57aeSJohn Baldwin 	bus_read_2((ida)->regs, port)
42ee7eb00eSJonathan Lemon #define	ida_inl(ida, port) \
436b5b57aeSJohn Baldwin 	bus_read_4((ida)->regs, port)
44ee7eb00eSJonathan Lemon 
45ee7eb00eSJonathan Lemon #define	ida_outb(ida, port, val) \
466b5b57aeSJohn Baldwin 	bus_write_1((ida)->regs, port, val)
47ee7eb00eSJonathan Lemon #define	ida_outw(ida, port, val) \
486b5b57aeSJohn Baldwin 	bus_write_2((ida)->regs, port, val)
49ee7eb00eSJonathan Lemon #define	ida_outl(ida, port, val) \
506b5b57aeSJohn Baldwin 	bus_write_4((ida)->regs, port, val)
51ee7eb00eSJonathan Lemon 
52db57feb7SJonathan Lemon struct ida_hdr {
53db57feb7SJonathan Lemon 	u_int8_t	drive;		/* logical drive */
54db57feb7SJonathan Lemon 	u_int8_t	priority;	/* block priority */
55db57feb7SJonathan Lemon 	u_int16_t	size;		/* size of request, in words */
56db57feb7SJonathan Lemon };
57db57feb7SJonathan Lemon 
58db57feb7SJonathan Lemon struct ida_req {
59db57feb7SJonathan Lemon 	u_int16_t	next;		/* offset of next request */
60db57feb7SJonathan Lemon 	u_int8_t	command;	/* command */
61db57feb7SJonathan Lemon 	u_int8_t	error;		/* return error code */
62db57feb7SJonathan Lemon 	u_int32_t	blkno;		/* block number */
63db57feb7SJonathan Lemon 	u_int16_t	bcount;		/* block count */
64db57feb7SJonathan Lemon 	u_int8_t	sgcount;	/* number of scatter/gather entries */
65db57feb7SJonathan Lemon 	u_int8_t	spare;		/* reserved */
66db57feb7SJonathan Lemon };
67db57feb7SJonathan Lemon 
68db57feb7SJonathan Lemon struct ida_sgb {
69db57feb7SJonathan Lemon 	u_int32_t	length;		/* length of S/G segment */
70db57feb7SJonathan Lemon 	u_int32_t	addr;		/* physical address of block */
71db57feb7SJonathan Lemon };
72db57feb7SJonathan Lemon 
73db57feb7SJonathan Lemon #define	IDA_NSEG	32		/* maximum number of segments */
74db57feb7SJonathan Lemon 
75db57feb7SJonathan Lemon /*
76db57feb7SJonathan Lemon  * right now, this structure totals 276 bytes.
77db57feb7SJonathan Lemon  */
78db57feb7SJonathan Lemon struct ida_hardware_qcb {
79db57feb7SJonathan Lemon 	struct 	ida_hdr hdr;			/*   4 */
80db57feb7SJonathan Lemon 	struct 	ida_req req;			/*  12 */
81db57feb7SJonathan Lemon 	struct 	ida_sgb seg[IDA_NSEG];		/* 256 */
82db57feb7SJonathan Lemon 	struct	ida_qcb *qcb;			/*   4 - qcb backpointer */
83db57feb7SJonathan Lemon };
84db57feb7SJonathan Lemon 
85db57feb7SJonathan Lemon typedef enum {
86db57feb7SJonathan Lemon 	QCB_FREE		= 0x0000,
87db57feb7SJonathan Lemon 	QCB_ACTIVE		= 0x0001,	/* waiting for completion */
886b5b57aeSJohn Baldwin 	QCB_TIMEDOUT		= 0x0002,
89db57feb7SJonathan Lemon } qcb_state;
90db57feb7SJonathan Lemon 
91db57feb7SJonathan Lemon #define	DMA_DATA_IN	0x0001
92db57feb7SJonathan Lemon #define	DMA_DATA_OUT	0x0002
93db57feb7SJonathan Lemon #define	IDA_COMMAND	0x0004
94db57feb7SJonathan Lemon #define	DMA_DATA_TRANSFER	(DMA_DATA_IN | DMA_DATA_OUT)
95db57feb7SJonathan Lemon 
96db57feb7SJonathan Lemon #define	IDA_QCB_MAX	256
97db57feb7SJonathan Lemon #define	IDA_CONTROLLER	0		/* drive "number" for controller */
98db57feb7SJonathan Lemon 
996b5b57aeSJohn Baldwin struct ida_softc;
1006b5b57aeSJohn Baldwin 
101db57feb7SJonathan Lemon struct ida_qcb {
102db57feb7SJonathan Lemon 	struct		ida_hardware_qcb *hwqcb;
1036b5b57aeSJohn Baldwin 	struct		ida_softc *ida;
104db57feb7SJonathan Lemon 	qcb_state	state;
105db57feb7SJonathan Lemon 	short		flags;
106db57feb7SJonathan Lemon 	union {
107e3975643SJake Burkholder 		STAILQ_ENTRY(ida_qcb) stqe;
108e3975643SJake Burkholder 		SLIST_ENTRY(ida_qcb) sle;
109db57feb7SJonathan Lemon 	} link;
110db57feb7SJonathan Lemon 	bus_dmamap_t	dmamap;
111ee7eb00eSJonathan Lemon 	bus_addr_t	hwqcb_busaddr;
1128177437dSPoul-Henning Kamp 	struct		bio *buf;		/* bio associated with qcb */
1136b5b57aeSJohn Baldwin 	int		error;
114db57feb7SJonathan Lemon };
115db57feb7SJonathan Lemon 
116ee7eb00eSJonathan Lemon struct ida_access {
117ee7eb00eSJonathan Lemon 	int		(*fifo_full)(struct ida_softc *);
118ee7eb00eSJonathan Lemon 	void		(*submit)(struct ida_softc *, struct ida_qcb *);
119ee7eb00eSJonathan Lemon 	bus_addr_t	(*done)(struct ida_softc *);
120ee7eb00eSJonathan Lemon 	int		(*int_pending)(struct ida_softc *);
121ee7eb00eSJonathan Lemon 	void		(*int_enable)(struct ida_softc *, int);
122ee7eb00eSJonathan Lemon };
123ee7eb00eSJonathan Lemon 
124db57feb7SJonathan Lemon /*
125db57feb7SJonathan Lemon  * flags for the controller
126db57feb7SJonathan Lemon  */
12755d782fcSJonathan Lemon #define	IDA_ATTACHED	0x01		/* attached */
1281277c3baSJonathan Lemon #define	IDA_FIRMWARE	0x02		/* firmware must be started */
12955d782fcSJonathan Lemon #define	IDA_INTERRUPTS	0x04		/* interrupts enabled */
1306b5b57aeSJohn Baldwin #define	IDA_QFROZEN	0x08		/* request queue frozen */
131db57feb7SJonathan Lemon 
132db57feb7SJonathan Lemon struct ida_softc {
133db57feb7SJonathan Lemon 	device_t	dev;
13484339b16SMatthew N. Dodd 
13584339b16SMatthew N. Dodd 	struct callout	ch;
13689c9c53dSPoul-Henning Kamp 	struct cdev *ida_dev_t;
137db57feb7SJonathan Lemon 
138db57feb7SJonathan Lemon 	int		regs_res_type;
139db57feb7SJonathan Lemon 	int		regs_res_id;
140db57feb7SJonathan Lemon 	struct 		resource *regs;
141db57feb7SJonathan Lemon 
142db57feb7SJonathan Lemon 	int		irq_res_type;
143db57feb7SJonathan Lemon 	struct		resource *irq;
144db57feb7SJonathan Lemon 	void		*ih;
145db57feb7SJonathan Lemon 
1466b5b57aeSJohn Baldwin 	struct mtx	lock;
1476b5b57aeSJohn Baldwin 	struct intr_config_hook ich;
148db57feb7SJonathan Lemon 
149db57feb7SJonathan Lemon 	/* various DMA tags */
150db57feb7SJonathan Lemon 	bus_dma_tag_t	parent_dmat;
151db57feb7SJonathan Lemon 	bus_dma_tag_t	buffer_dmat;
152db57feb7SJonathan Lemon 
153db57feb7SJonathan Lemon 	bus_dma_tag_t	hwqcb_dmat;
154db57feb7SJonathan Lemon 	bus_dmamap_t	hwqcb_dmamap;
155db57feb7SJonathan Lemon 	bus_addr_t	hwqcb_busaddr;
156db57feb7SJonathan Lemon 
157db57feb7SJonathan Lemon 	bus_dma_tag_t	sg_dmat;
158db57feb7SJonathan Lemon 
159db57feb7SJonathan Lemon 	int		flags;
160db57feb7SJonathan Lemon 
16184339b16SMatthew N. Dodd 	int		qactive;
16284339b16SMatthew N. Dodd 
163db57feb7SJonathan Lemon 	struct		ida_hardware_qcb *hwqcbs;	/* HW QCB array */
164db57feb7SJonathan Lemon 	struct		ida_qcb *qcbs;			/* kernel QCB array */
165e3975643SJake Burkholder 	SLIST_HEAD(, ida_qcb)	free_qcbs;
166e3975643SJake Burkholder 	STAILQ_HEAD(, ida_qcb) 	qcb_queue;
1678177437dSPoul-Henning Kamp 	struct		bio_queue_head bio_queue;
168ee7eb00eSJonathan Lemon 
169ee7eb00eSJonathan Lemon 	struct		ida_access cmd;
170db57feb7SJonathan Lemon };
171db57feb7SJonathan Lemon 
172db57feb7SJonathan Lemon /*
173db57feb7SJonathan Lemon  * drive flags
174db57feb7SJonathan Lemon  */
175db57feb7SJonathan Lemon #define	DRV_WRITEPROT		0x0001
176db57feb7SJonathan Lemon 
17781530866SMatthew N. Dodd struct idad_softc {
178db57feb7SJonathan Lemon 	device_t	dev;
179db57feb7SJonathan Lemon 	struct 		ida_softc *controller;
1800b7ed341SPoul-Henning Kamp 	struct		disk *disk;
1811277c3baSJonathan Lemon 	int		drive;			/* per controller */
1821277c3baSJonathan Lemon 	int		unit;			/* global */
183db57feb7SJonathan Lemon 	int		cylinders;
184db57feb7SJonathan Lemon 	int		heads;
185db57feb7SJonathan Lemon 	int		sectors;
186db57feb7SJonathan Lemon 	int		secsize;
187db57feb7SJonathan Lemon 	int		secperunit;
188db57feb7SJonathan Lemon 	int		flags;
189db57feb7SJonathan Lemon };
190db57feb7SJonathan Lemon 
191ee7eb00eSJonathan Lemon struct ida_board {
192ee7eb00eSJonathan Lemon 	u_int32_t	board;
193ee7eb00eSJonathan Lemon 	char 		*desc;
194ee7eb00eSJonathan Lemon 	struct		ida_access *accessor;
1957c258c0eSJonathan Lemon 	int		flags;
196ee7eb00eSJonathan Lemon };
197ee7eb00eSJonathan Lemon 
198ee7eb00eSJonathan Lemon extern int ida_detach(device_t dev);
199db57feb7SJonathan Lemon extern struct ida_softc *ida_alloc(device_t dev, struct resource *regs,
200db57feb7SJonathan Lemon 	int regs_type, int regs_id, bus_dma_tag_t parent_dmat);
201db57feb7SJonathan Lemon extern void ida_free(struct ida_softc *ida);
202a7f3dd6fSHans Petter Selasky extern int ida_setup(struct ida_softc *ida);
203db57feb7SJonathan Lemon extern int ida_command(struct ida_softc *ida, int command, void *data,
20455d782fcSJonathan Lemon 	int datasize, int drive, u_int32_t pblkno, int flags);
2058177437dSPoul-Henning Kamp extern void ida_submit_buf(struct ida_softc *ida, struct bio *bp);
206db57feb7SJonathan Lemon extern void ida_intr(void *data);
207db57feb7SJonathan Lemon 
20881530866SMatthew N. Dodd extern void idad_intr(struct bio *bp);
209db57feb7SJonathan Lemon 
210db57feb7SJonathan Lemon #endif /* _IDAVAR_H */
211