aicvar.h revision 241591
1269257Sdes/*-
2269257Sdes * Copyright (c) 1999 Luoqi Chen.
3269257Sdes * All rights reserved.
4269257Sdes *
5269257Sdes * Redistribution and use in source and binary forms, with or without
6269257Sdes * modification, are permitted provided that the following conditions
7269257Sdes * are met:
8269257Sdes * 1. Redistributions of source code must retain the above copyright
9269257Sdes *    notice, this list of conditions and the following disclaimer.
10269257Sdes * 2. Redistributions in binary form must reproduce the above copyright
11269257Sdes *    notice, this list of conditions and the following disclaimer in the
12269257Sdes *    documentation and/or other materials provided with the distribution.
13269257Sdes *
14269257Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15269257Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16269257Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17269257Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18269257Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19269257Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20269257Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21269257Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22269257Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23269257Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24269257Sdes * SUCH DAMAGE.
25269257Sdes *
26269257Sdes * $FreeBSD: head/sys/dev/aic/aicvar.h 241591 2012-10-15 16:09:59Z jhb $
27269257Sdes */
28269257Sdes
29269257Sdesstruct aic_transinfo {
30269257Sdes	u_int8_t period;
31269257Sdes	u_int8_t offset;
32269257Sdes};
33269257Sdes
34269257Sdesstruct aic_tinfo {
35238104Sdes	u_int16_t lubusy;
36269257Sdes	u_int8_t flags;
37238104Sdes	u_int8_t scsirate;
38269257Sdes	struct aic_transinfo current;
39269257Sdes	struct aic_transinfo goal;
40269257Sdes	struct aic_transinfo user;
41269257Sdes};
42269257Sdes
43269257Sdes#define	TINFO_DISC_ENB		0x01
44269257Sdes#define	TINFO_TAG_ENB		0x02
45238104Sdes#define	TINFO_SDTR_NEGO		0x04
46269257Sdes#define	TINFO_SDTR_SENT		0x08
47269257Sdes
48269257Sdesstruct aic_scb {
49269257Sdes	union ccb	*ccb;
50269257Sdes	SLIST_ENTRY(aic_scb) link;
51269257Sdes	struct callout	timer;
52238104Sdes	u_int8_t	flags;
53269257Sdes	u_int8_t	tag;
54269257Sdes	u_int8_t	target;
55238104Sdes	u_int8_t	lun;
56269257Sdes	u_int8_t	status;
57269257Sdes	u_int8_t	cmd_len;
58269257Sdes	u_int8_t	*cmd_ptr;
59269257Sdes	u_int32_t	data_len;
60238104Sdes	u_int8_t	*data_ptr;
61269257Sdes};
62269257Sdes
63269257Sdes#define ccb_scb_ptr	spriv_ptr0
64269257Sdes#define ccb_aic_ptr	spriv_ptr1
65269257Sdes
66269257Sdes#define	SCB_ACTIVE		0x01
67269257Sdes#define	SCB_DISCONNECTED	0x02
68269257Sdes#define	SCB_DEVICE_RESET	0x04
69269257Sdes#define	SCB_SENSE		0x08
70269257Sdes
71269257Sdesenum { AIC6260, AIC6360, AIC6370, GM82C700 };
72269257Sdes
73269257Sdesstruct aic_softc {
74269257Sdes	device_t		dev;
75238104Sdes	struct mtx		lock;
76269257Sdes	struct resource		*res;
77269257Sdes	bus_dma_tag_t		dmat;
78269257Sdes
79269257Sdes	struct cam_sim		*sim;
80269257Sdes	struct cam_path		*path;
81269257Sdes	TAILQ_HEAD(,ccb_hdr)	pending_ccbs, nexus_ccbs;
82269257Sdes	SLIST_HEAD(,aic_scb)	free_scbs;
83269257Sdes	struct aic_scb		*nexus;
84269257Sdes
85269257Sdes	u_int32_t		flags;
86269257Sdes	u_int8_t		initiator;
87269257Sdes	u_int8_t		state;
88238104Sdes	u_int8_t		target;
89269257Sdes	u_int8_t		lun;
90269257Sdes	u_int8_t		prev_phase;
91269257Sdes
92269257Sdes	u_int8_t		msg_outq;
93269257Sdes	u_int8_t		msg_sent;
94269257Sdes	int			msg_len;
95269257Sdes	char			msg_buf[8];
96269257Sdes
97269257Sdes	struct aic_tinfo	tinfo[8];
98269257Sdes	struct aic_scb		scbs[256];
99269257Sdes
100269257Sdes	int			min_period;
101238104Sdes	int			max_period;
102269257Sdes	int			chip_type;
103269257Sdes};
104269257Sdes
105269257Sdes#define	AIC_DISC_ENABLE		0x01
106269257Sdes#define	AIC_DMA_ENABLE		0x02
107269257Sdes#define	AIC_PARITY_ENABLE	0x04
108269257Sdes#define	AIC_DWIO_ENABLE		0x08
109269257Sdes#define	AIC_RESOURCE_SHORTAGE	0x10
110269257Sdes#define	AIC_DROP_MSGIN		0x20
111269257Sdes#define	AIC_BUSFREE_OK		0x40
112269257Sdes#define	AIC_FAST_ENABLE		0x80
113269257Sdes
114269257Sdes#define	AIC_IDLE		0x00
115269257Sdes#define	AIC_SELECTING		0x01
116269257Sdes#define	AIC_RESELECTED		0x02
117269257Sdes#define	AIC_RECONNECTING	0x03
118269257Sdes#define	AIC_HASNEXUS		0x04
119238104Sdes
120269257Sdes#define	AIC_MSG_IDENTIFY	0x01
121269257Sdes#define	AIC_MSG_TAG_Q		0x02
122269257Sdes#define	AIC_MSG_SDTR		0x04
123269257Sdes#define	AIC_MSG_WDTR		0x08
124269257Sdes#define	AIC_MSG_MSGBUF		0x80
125269257Sdes
126269257Sdes#define	AIC_SYNC_PERIOD		(200 / 4)
127269257Sdes#define	AIC_FAST_SYNC_PERIOD	(100 / 4)
128269257Sdes#define	AIC_MIN_SYNC_PERIOD	112
129269257Sdes#define	AIC_SYNC_OFFSET		8
130269257Sdes
131269257Sdes#define	aic_inb(aic, port) \
132269257Sdes	bus_read_1((aic)->res, (port))
133269257Sdes
134269257Sdes#define	aic_outb(aic, port, value) \
135269257Sdes	bus_write_1((aic)->res, (port), (value))
136238104Sdes
137269257Sdes#define	aic_insb(aic, port, addr, count) \
138269257Sdes	bus_read_multi_1((aic)->res, (port), (addr), (count))
139269257Sdes
140269257Sdes#define	aic_outsb(aic, port, addr, count) \
141269257Sdes	bus_write_multi_1((aic)->res, (port), (addr), (count))
142269257Sdes
143269257Sdes#define	aic_insw(aic, port, addr, count) \
144269257Sdes	bus_read_multi_2((aic)->res, (port), (u_int16_t *)(addr), (count))
145269257Sdes
146269257Sdes#define	aic_outsw(aic, port, addr, count) \
147269257Sdes	bus_write_multi_2((aic)->res, (port), (u_int16_t *)(addr), (count))
148269257Sdes
149269257Sdes#define	aic_insl(aic, port, addr, count) \
150269257Sdes	bus_read_multi_4((aic)->res, (port), (u_int32_t *)(addr), (count))
151269257Sdes
152269257Sdes#define	aic_outsl(aic, port, addr, count) \
153238104Sdes	bus_write_multi_4((aic)->res, (port), (u_int32_t *)(addr), (count))
154269257Sdes
155269257Sdesextern int aic_probe(struct aic_softc *);
156269257Sdesextern int aic_attach(struct aic_softc *);
157238104Sdesextern int aic_detach(struct aic_softc *);
158269257Sdesextern void aic_intr(void *);
159269257Sdes