1 /**	$MirOS: src/sys/dev/ic/siopvar_common.h,v 1.2 2005/03/06 21:27:40 tg Exp $ */
2 /*	$OpenBSD: siopvar_common.h,v 1.18 2003/11/16 20:30:06 avsm Exp $ */
3 /*	$NetBSD: siopvar_common.h,v 1.22 2002/10/23 02:32:36 christos Exp $ */
4 
5 /*
6  * Copyright (c) 2000 Manuel Bouyer.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by Manuel Bouyer.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 /* common struct and routines used by siop and esiop */
36 
37 #ifndef SIOP_DEFAULT_TARGET
38 #define SIOP_DEFAULT_TARGET 7
39 #endif
40 
41 /* tables used by SCRIPT */
42 #pragma pack(1)
43 typedef struct scr_table {
44 	u_int32_t count;
45 	u_int32_t addr;
46 } scr_table_t;
47 #pragma pack(0)
48 
49 /* Number of scatter/gather entries */
50 /* XXX Ensure alignment of siop_xfer's. */
51 #define SIOP_NSG	17	/* XXX (MAXPHYS/NBPG + 1) */
52 
53 /*
54  * This structure interfaces the SCRIPT with the driver; it describes a full
55  * transfer. If you change something here, don't forget to update offsets in
56  * {s,es}iop.ss
57  */
58 struct siop_common_xfer {
59 	u_int8_t msg_out[16];		/*   0 */
60 	u_int8_t msg_in[16];		/*  16 */
61 	u_int32_t status;		/*  32 */
62 	u_int32_t pad1;			/*  36 */
63 	u_int32_t id;			/*  40 */
64 	struct scsi_generic xscmd; 	/*  44 */
65 	scr_table_t t_msgin;		/*  56 */
66 	scr_table_t t_extmsgin;		/*  64 */
67 	scr_table_t t_extmsgdata; 	/*  72 */
68 	scr_table_t t_msgout;		/*  80 */
69 	scr_table_t cmd;		/*  88 */
70 	scr_table_t t_status;		/*  96 */
71 	scr_table_t data[SIOP_NSG]; 	/* 104 */
72 } __packed;
73 
74 /* status can hold the SCSI_* status values, and 2 additional values: */
75 #define SCSI_SIOP_NOCHECK	0xfe	/* don't check the scsi status */
76 #define SCSI_SIOP_NOSTATUS	0xff	/* device didn't report status */
77 
78 /*
79  * This describes a command handled by the SCSI controller
80  */
81 struct siop_common_cmd {
82 	struct siop_common_softc *siop_sc; /* points back to our adapter */
83 	struct siop_common_target *siop_target; /* pointer to our target def */
84 	struct scsi_xfer *xs; /* xfer from the upper level */
85 	struct siop_common_xfer *siop_tables; /* tables for this cmd */
86 	bus_addr_t	dsa; /* DSA value to load */
87 	bus_dmamap_t	dmamap_data;
88 	int status;
89 	int flags;
90 	int tag;	/* tag used for tagged command queuing */
91 };
92 
93 /* status defs */
94 #define CMDST_FREE		0 /* cmd slot is free */
95 #define CMDST_READY		1 /* cmd slot is waiting for processing */
96 #define CMDST_ACTIVE		2 /* cmd slot is being processed */
97 #define CMDST_SENSE		3 /* cmd slot is requesting sense */
98 #define CMDST_SENSE_ACTIVE	4 /* request sense active */
99 #define CMDST_SENSE_DONE 	5 /* request sense done */
100 #define CMDST_DONE		6 /* cmd slot has been processed */
101 /* flags defs */
102 #define CMDFL_TIMEOUT	0x0001 /* cmd timed out */
103 #define CMDFL_TAG	0x0002 /* tagged cmd */
104 
105 /* per-target struct */
106 struct siop_common_target {
107 	int status;	/* target status, see below */
108 	int flags;	/* target flags, see below */
109 	u_int32_t id;	/* for SELECT FROM */
110 	int period;
111 	int offset;
112 };
113 
114 /* target status */
115 #define TARST_PROBING	0 /* target is being probed */
116 #define TARST_ASYNC	1 /* target needs sync/wide negotiation */
117 #define TARST_WIDE_NEG	2 /* target is doing wide negotiation */
118 #define TARST_SYNC_NEG	3 /* target is doing sync negotiation */
119 #define TARST_PPR_NEG	4 /* target is doing sync negotiation */
120 #define TARST_OK	5 /* sync/wide agreement is valid */
121 
122 /* target flags */
123 #define TARF_SYNC	0x01 /* target can do sync */
124 #define TARF_WIDE	0x02 /* target can do wide */
125 #define TARF_TAG	0x04 /* target can do tags */
126 #define TARF_DT		0x08 /* target can do DT clocking */
127 #define TARF_ISWIDE	0x10 /* target is wide */
128 #define TARF_ISDT	0x20 /* target is doing DT clocking */
129 
130 /* Driver internal state */
131 struct siop_common_softc {
132 	struct device sc_dev;
133 	struct scsi_link sc_link;	/* link to upper level */
134 	int features;			/* chip's features */
135 	int ram_size;
136 	int maxburst;
137 	int maxoff;
138 	int clock_div;			/* async. clock divider (scntl3) */
139 	int clock_period;		/* clock period (ns * 10) */
140 	int st_minsync;			/* min and max sync period, */
141 	int dt_minsync;
142 	int st_maxsync;			/* as sent in or PPR messages */
143 	int dt_maxsync;
144 	int mode;			/* current SE/LVD/HVD mode */
145 	bus_space_tag_t sc_rt;		/* bus_space registers tag */
146 	bus_space_handle_t sc_rh;	/* bus_space registers handle */
147 	bus_addr_t sc_raddr;		/* register addresses */
148 	bus_space_tag_t sc_ramt;	/* bus_space ram tag */
149 	bus_space_handle_t sc_ramh;	/* bus_space ram handle */
150 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
151 	void (*sc_reset)(struct siop_common_softc*); /* reset callback */
152 	bus_dmamap_t  sc_scriptdma;	/* DMA map for script */
153 	bus_addr_t sc_scriptaddr;	/* on-board ram or physical address */
154 	u_int32_t *sc_script;		/* script location in memory */
155 	struct siop_common_target *targets[16]; /* per-target states */
156 };
157 
158 /* features */
159 #define SF_BUS_WIDE	0x00000001 /* wide bus */
160 #define SF_BUS_ULTRA	0x00000002 /* Ultra (20MHz) bus */
161 #define SF_BUS_ULTRA2	0x00000004 /* Ultra2 (40MHz) bus */
162 #define SF_BUS_ULTRA3	0x00000008 /* Ultra3 (80MHz) bus */
163 #define SF_BUS_DIFF	0x00000010 /* differential bus */
164 
165 #define SF_CHIP_LED0	0x00000100 /* led on GPIO0 */
166 #define SF_CHIP_LEDC	0x00000200 /* led on GPIO0 with hardware control */
167 #define SF_CHIP_DBLR	0x00000400 /* clock doubler or quadrupler */
168 #define SF_CHIP_QUAD	0x00000800 /* clock quadrupler, with PPL */
169 #define SF_CHIP_FIFO	0x00001000 /* large fifo */
170 #define SF_CHIP_PF	0x00002000 /* Instructions prefetch */
171 #define SF_CHIP_RAM	0x00004000 /* on-board RAM */
172 #define SF_CHIP_LS	0x00008000 /* load/store instruction */
173 #define SF_CHIP_10REGS	0x00010000 /* 10 scratch registers */
174 #define SF_CHIP_DFBC	0x00020000 /* Use DFBC register */
175 #define SF_CHIP_DT	0x00040000 /* DT clocking */
176 #define SF_CHIP_GEBUG	0x00080000 /* SCSI gross error bug */
177 
178 #define SF_PCI_RL	0x01000000 /* PCI read line */
179 #define SF_PCI_RM	0x02000000 /* PCI read multiple */
180 #define SF_PCI_BOF	0x04000000 /* PCI burst opcode fetch */
181 #define SF_PCI_CLS	0x08000000 /* PCI cache line size */
182 #define SF_PCI_WRI	0x10000000 /* PCI write and invalidate */
183 
184 int	siop_common_attach(struct siop_common_softc *);
185 void	siop_common_reset(struct siop_common_softc *);
186 void	siop_setuptables(struct siop_common_cmd *);
187 int	siop_modechange(struct siop_common_softc *);
188 
189 int	siop_wdtr_neg(struct siop_common_cmd *);
190 int	siop_sdtr_neg(struct siop_common_cmd *);
191 int     siop_ppr_neg(struct siop_common_cmd *);
192 void	siop_sdtr_msg(struct siop_common_cmd *, int, int, int);
193 void	siop_wdtr_msg(struct siop_common_cmd *, int, int);
194 void    siop_ppr_msg(struct siop_common_cmd *, int, int, int);
195 void	siop_update_xfer_mode(struct siop_common_softc *, int);
196 /* actions to take at return of siop_wdtr_neg() and siop_sdtr_neg() */
197 #define SIOP_NEG_NOP	0x0
198 #define SIOP_NEG_MSGOUT	0x1
199 #define SIOP_NEG_ACK	0x2
200 
201 void	siop_minphys(struct buf *);
202 void 	siop_sdp(struct siop_common_cmd *);
203 void	siop_clearfifo(struct siop_common_softc *);
204 void	siop_resetbus(struct siop_common_softc *);
205