trm.c revision 1.6.2.2 1 1.6.2.2 thorpej /* $NetBSD: trm.c,v 1.6.2.2 2002/01/10 19:57:07 thorpej Exp $ */
2 1.6.2.2 thorpej /*
3 1.6.2.2 thorpej * Device Driver for Tekram DC395U/UW/F, DC315/U
4 1.6.2.2 thorpej * PCI SCSI Bus Master Host Adapter
5 1.6.2.2 thorpej * (SCSI chip set used Tekram ASIC TRM-S1040)
6 1.6.2.2 thorpej *
7 1.6.2.2 thorpej * Copyright (c) 2001 Rui-Xiang Guo
8 1.6.2.2 thorpej * All rights reserved.
9 1.6.2.2 thorpej *
10 1.6.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.6.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.6.2.2 thorpej * are met:
13 1.6.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.6.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.6.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.6.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.6.2.2 thorpej * 3. The name of the author may not be used to endorse or promote products
19 1.6.2.2 thorpej * derived from this software without specific prior written permission.
20 1.6.2.2 thorpej *
21 1.6.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.6.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.6.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.6.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.6.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.6.2.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.6.2.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.6.2.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.6.2.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.6.2.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.6.2.2 thorpej */
32 1.6.2.2 thorpej /*
33 1.6.2.2 thorpej * Ported from
34 1.6.2.2 thorpej * dc395x_trm.c
35 1.6.2.2 thorpej *
36 1.6.2.2 thorpej * Written for NetBSD 1.4.x by
37 1.6.2.2 thorpej * Erich Chen (erich (at) tekram.com.tw)
38 1.6.2.2 thorpej *
39 1.6.2.2 thorpej * Provided by
40 1.6.2.2 thorpej * (C)Copyright 1995-1999 Tekram Technology Co., Ltd. All rights reserved.
41 1.6.2.2 thorpej */
42 1.6.2.2 thorpej
43 1.6.2.2 thorpej #include <sys/cdefs.h>
44 1.6.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: trm.c,v 1.6.2.2 2002/01/10 19:57:07 thorpej Exp $");
45 1.6.2.2 thorpej
46 1.6.2.2 thorpej /* #define TRM_DEBUG */
47 1.6.2.2 thorpej
48 1.6.2.2 thorpej #include <sys/param.h>
49 1.6.2.2 thorpej #include <sys/systm.h>
50 1.6.2.2 thorpej #include <sys/malloc.h>
51 1.6.2.2 thorpej #include <sys/buf.h>
52 1.6.2.2 thorpej #include <sys/kernel.h>
53 1.6.2.2 thorpej #include <sys/device.h>
54 1.6.2.2 thorpej
55 1.6.2.2 thorpej #include <machine/bus.h>
56 1.6.2.2 thorpej #include <machine/intr.h>
57 1.6.2.2 thorpej
58 1.6.2.2 thorpej #include <uvm/uvm_extern.h>
59 1.6.2.2 thorpej
60 1.6.2.2 thorpej #include <dev/scsipi/scsi_all.h>
61 1.6.2.2 thorpej #include <dev/scsipi/scsi_message.h>
62 1.6.2.2 thorpej #include <dev/scsipi/scsipi_all.h>
63 1.6.2.2 thorpej #include <dev/scsipi/scsiconf.h>
64 1.6.2.2 thorpej
65 1.6.2.2 thorpej #include <dev/pci/pcidevs.h>
66 1.6.2.2 thorpej #include <dev/pci/pcireg.h>
67 1.6.2.2 thorpej #include <dev/pci/pcivar.h>
68 1.6.2.2 thorpej #include <dev/pci/trmreg.h>
69 1.6.2.2 thorpej
70 1.6.2.2 thorpej /*
71 1.6.2.2 thorpej * feature of chip set MAX value
72 1.6.2.2 thorpej */
73 1.6.2.2 thorpej #define TRM_MAX_TARGETS 16
74 1.6.2.2 thorpej #define TRM_MAX_SG_ENTRIES (MAXPHYS / PAGE_SIZE + 1)
75 1.6.2.2 thorpej #define TRM_MAX_SRB 32
76 1.6.2.2 thorpej
77 1.6.2.2 thorpej /*
78 1.6.2.2 thorpej * Segment Entry
79 1.6.2.2 thorpej */
80 1.6.2.2 thorpej struct trm_sg_entry {
81 1.6.2.2 thorpej u_int32_t address;
82 1.6.2.2 thorpej u_int32_t length;
83 1.6.2.2 thorpej };
84 1.6.2.2 thorpej
85 1.6.2.2 thorpej #define TRM_SG_SIZE (sizeof(struct trm_sg_entry) * TRM_MAX_SG_ENTRIES)
86 1.6.2.2 thorpej
87 1.6.2.2 thorpej /*
88 1.6.2.2 thorpej **********************************************************************
89 1.6.2.2 thorpej * The SEEPROM structure for TRM_S1040
90 1.6.2.2 thorpej **********************************************************************
91 1.6.2.2 thorpej */
92 1.6.2.2 thorpej struct nvram_target {
93 1.6.2.2 thorpej u_int8_t config0; /* Target configuration byte 0 */
94 1.6.2.2 thorpej #define NTC_DO_WIDE_NEGO 0x20 /* Wide negotiate */
95 1.6.2.2 thorpej #define NTC_DO_TAG_QUEUING 0x10 /* Enable SCSI tag queuing */
96 1.6.2.2 thorpej #define NTC_DO_SEND_START 0x08 /* Send start command SPINUP */
97 1.6.2.2 thorpej #define NTC_DO_DISCONNECT 0x04 /* Enable SCSI disconnect */
98 1.6.2.2 thorpej #define NTC_DO_SYNC_NEGO 0x02 /* Sync negotiation */
99 1.6.2.2 thorpej #define NTC_DO_PARITY_CHK 0x01 /* Parity check enable */
100 1.6.2.2 thorpej u_int8_t period; /* Target period */
101 1.6.2.2 thorpej u_int8_t config2; /* Target configuration byte 2 */
102 1.6.2.2 thorpej u_int8_t config3; /* Target configuration byte 3 */
103 1.6.2.2 thorpej };
104 1.6.2.2 thorpej
105 1.6.2.2 thorpej struct trm_nvram {
106 1.6.2.2 thorpej u_int8_t subvendor_id[2]; /* 0,1 Sub Vendor ID */
107 1.6.2.2 thorpej u_int8_t subsys_id[2]; /* 2,3 Sub System ID */
108 1.6.2.2 thorpej u_int8_t subclass; /* 4 Sub Class */
109 1.6.2.2 thorpej u_int8_t vendor_id[2]; /* 5,6 Vendor ID */
110 1.6.2.2 thorpej u_int8_t device_id[2]; /* 7,8 Device ID */
111 1.6.2.2 thorpej u_int8_t reserved0; /* 9 Reserved */
112 1.6.2.2 thorpej struct nvram_target target[TRM_MAX_TARGETS];
113 1.6.2.2 thorpej /* 10,11,12,13
114 1.6.2.2 thorpej * 14,15,16,17
115 1.6.2.2 thorpej * ....
116 1.6.2.2 thorpej * 70,71,72,73 */
117 1.6.2.2 thorpej u_int8_t scsi_id; /* 74 Host Adapter SCSI ID */
118 1.6.2.2 thorpej u_int8_t channel_cfg; /* 75 Channel configuration */
119 1.6.2.2 thorpej #define NAC_SCANLUN 0x20 /* Include LUN as BIOS device */
120 1.6.2.2 thorpej #define NAC_DO_PARITY_CHK 0x08 /* Parity check enable */
121 1.6.2.2 thorpej #define NAC_POWERON_SCSI_RESET 0x04 /* Power on reset enable */
122 1.6.2.2 thorpej #define NAC_GREATER_1G 0x02 /* > 1G support enable */
123 1.6.2.2 thorpej #define NAC_GT2DRIVES 0x01 /* Support more than 2 drives */
124 1.6.2.2 thorpej u_int8_t delay_time; /* 76 Power on delay time */
125 1.6.2.2 thorpej u_int8_t max_tag; /* 77 Maximum tags */
126 1.6.2.2 thorpej u_int8_t reserved1; /* 78 */
127 1.6.2.2 thorpej u_int8_t boot_target; /* 79 */
128 1.6.2.2 thorpej u_int8_t boot_lun; /* 80 */
129 1.6.2.2 thorpej u_int8_t reserved2; /* 81 */
130 1.6.2.2 thorpej u_int8_t reserved3[44]; /* 82,..125 */
131 1.6.2.2 thorpej u_int8_t checksum0; /* 126 */
132 1.6.2.2 thorpej u_int8_t checksum1; /* 127 */
133 1.6.2.2 thorpej #define TRM_NVRAM_CKSUM 0x1234
134 1.6.2.2 thorpej };
135 1.6.2.2 thorpej
136 1.6.2.2 thorpej /* Nvram Initiater bits definition */
137 1.6.2.2 thorpej #define MORE2_DRV 0x00000001
138 1.6.2.2 thorpej #define GREATER_1G 0x00000002
139 1.6.2.2 thorpej #define RST_SCSI_BUS 0x00000004
140 1.6.2.2 thorpej #define ACTIVE_NEGATION 0x00000008
141 1.6.2.2 thorpej #define NO_SEEK 0x00000010
142 1.6.2.2 thorpej #define LUN_CHECK 0x00000020
143 1.6.2.2 thorpej
144 1.6.2.2 thorpej #define trm_wait_30us() DELAY(30)
145 1.6.2.2 thorpej
146 1.6.2.2 thorpej /*
147 1.6.2.2 thorpej *-----------------------------------------------------------------------
148 1.6.2.2 thorpej * SCSI Request Block
149 1.6.2.2 thorpej *-----------------------------------------------------------------------
150 1.6.2.2 thorpej */
151 1.6.2.2 thorpej struct trm_srb {
152 1.6.2.2 thorpej struct trm_srb *next;
153 1.6.2.2 thorpej struct trm_dcb *dcb;
154 1.6.2.2 thorpej
155 1.6.2.2 thorpej struct trm_sg_entry *sgentry;
156 1.6.2.2 thorpej struct scsipi_xfer *xs; /* scsipi_xfer for this cmd */
157 1.6.2.2 thorpej bus_dmamap_t dmap;
158 1.6.2.2 thorpej bus_size_t sgoffset; /* Xfer buf offset */
159 1.6.2.2 thorpej
160 1.6.2.2 thorpej u_int32_t buflen; /* Total xfer length */
161 1.6.2.2 thorpej u_int32_t sgaddr; /* SGList physical starting address */
162 1.6.2.2 thorpej
163 1.6.2.2 thorpej u_int state; /* SRB State */
164 1.6.2.2 thorpej #define SRB_FREE 0x0000
165 1.6.2.2 thorpej #define SRB_WAIT 0x0001
166 1.6.2.2 thorpej #define SRB_READY 0x0002
167 1.6.2.2 thorpej #define SRB_MSGOUT 0x0004 /* arbitration+msg_out 1st byte */
168 1.6.2.2 thorpej #define SRB_MSGIN 0x0008
169 1.6.2.2 thorpej #define SRB_EXTEND_MSGIN 0x0010
170 1.6.2.2 thorpej #define SRB_COMMAND 0x0020
171 1.6.2.2 thorpej #define SRB_START_ 0x0040 /* arbitration+msg_out+command_out */
172 1.6.2.2 thorpej #define SRB_DISCONNECT 0x0080
173 1.6.2.2 thorpej #define SRB_DATA_XFER 0x0100
174 1.6.2.2 thorpej #define SRB_XFERPAD 0x0200
175 1.6.2.2 thorpej #define SRB_STATUS 0x0400
176 1.6.2.2 thorpej #define SRB_COMPLETED 0x0800
177 1.6.2.2 thorpej #define SRB_ABORT_SENT 0x1000
178 1.6.2.2 thorpej #define SRB_DO_SYNC_NEGO 0x2000
179 1.6.2.2 thorpej #define SRB_DO_WIDE_NEGO 0x4000
180 1.6.2.2 thorpej #define SRB_UNEXPECT_RESEL 0x8000
181 1.6.2.2 thorpej u_int8_t *msg;
182 1.6.2.2 thorpej
183 1.6.2.2 thorpej int sgcnt;
184 1.6.2.2 thorpej int sgindex;
185 1.6.2.2 thorpej
186 1.6.2.2 thorpej int phase; /* SCSI phase */
187 1.6.2.2 thorpej int hastat; /* Host Adapter Status */
188 1.6.2.2 thorpej #define H_STATUS_GOOD 0x00
189 1.6.2.2 thorpej #define H_SEL_TIMEOUT 0x11
190 1.6.2.2 thorpej #define H_OVER_UNDER_RUN 0x12
191 1.6.2.2 thorpej #define H_UNEXP_BUS_FREE 0x13
192 1.6.2.2 thorpej #define H_TARGET_PHASE_F 0x14
193 1.6.2.2 thorpej #define H_INVALID_CCB_OP 0x16
194 1.6.2.2 thorpej #define H_LINK_CCB_BAD 0x17
195 1.6.2.2 thorpej #define H_BAD_TARGET_DIR 0x18
196 1.6.2.2 thorpej #define H_DUPLICATE_CCB 0x19
197 1.6.2.2 thorpej #define H_BAD_CCB_OR_SG 0x1A
198 1.6.2.2 thorpej #define H_ABORT 0xFF
199 1.6.2.2 thorpej int tastat; /* Target SCSI Status Byte */
200 1.6.2.2 thorpej int flag; /* SRBFlag */
201 1.6.2.2 thorpej #define DATAOUT 0x0080
202 1.6.2.2 thorpej #define DATAIN 0x0040
203 1.6.2.2 thorpej #define RESIDUAL_VALID 0x0020
204 1.6.2.2 thorpej #define ENABLE_TIMER 0x0010
205 1.6.2.2 thorpej #define RESET_DEV0 0x0004
206 1.6.2.2 thorpej #define ABORT_DEV 0x0002
207 1.6.2.2 thorpej #define AUTO_REQSENSE 0x0001
208 1.6.2.2 thorpej int srbstat; /* SRB Status */
209 1.6.2.2 thorpej #define SRB_OK 0x01
210 1.6.2.2 thorpej #define ABORTION 0x02
211 1.6.2.2 thorpej #define OVER_RUN 0x04
212 1.6.2.2 thorpej #define UNDER_RUN 0x08
213 1.6.2.2 thorpej #define PARITY_ERROR 0x10
214 1.6.2.2 thorpej #define SRB_ERROR 0x20
215 1.6.2.2 thorpej int tagnum; /* Tag number */
216 1.6.2.2 thorpej int msgcnt;
217 1.6.2.2 thorpej
218 1.6.2.2 thorpej int cmdlen; /* SCSI command length */
219 1.6.2.2 thorpej u_int8_t cmd[12]; /* SCSI command */
220 1.6.2.2 thorpej
221 1.6.2.2 thorpej u_int8_t msgin[6];
222 1.6.2.2 thorpej u_int8_t msgout[6];
223 1.6.2.2 thorpej };
224 1.6.2.2 thorpej
225 1.6.2.2 thorpej /*
226 1.6.2.2 thorpej *-----------------------------------------------------------------------
227 1.6.2.2 thorpej * Device Control Block
228 1.6.2.2 thorpej *-----------------------------------------------------------------------
229 1.6.2.2 thorpej */
230 1.6.2.2 thorpej struct trm_dcb {
231 1.6.2.2 thorpej struct trm_dcb *next;
232 1.6.2.2 thorpej
233 1.6.2.2 thorpej struct trm_srb *waitsrb;
234 1.6.2.2 thorpej struct trm_srb *last_waitsrb;
235 1.6.2.2 thorpej
236 1.6.2.2 thorpej struct trm_srb *gosrb;
237 1.6.2.2 thorpej struct trm_srb *last_gosrb;
238 1.6.2.2 thorpej
239 1.6.2.2 thorpej struct trm_srb *actsrb;
240 1.6.2.2 thorpej
241 1.6.2.2 thorpej int gosrb_cnt;
242 1.6.2.2 thorpej u_int maxcmd; /* Max command */
243 1.6.2.2 thorpej
244 1.6.2.2 thorpej int id; /* SCSI Target ID (SCSI Only) */
245 1.6.2.2 thorpej int lun; /* SCSI Log. Unit (SCSI Only) */
246 1.6.2.2 thorpej
247 1.6.2.2 thorpej u_int8_t tagmask; /* Tag mask */
248 1.6.2.2 thorpej
249 1.6.2.2 thorpej u_int8_t tacfg; /* Target Config */
250 1.6.2.2 thorpej u_int8_t idmsg; /* Identify Msg */
251 1.6.2.2 thorpej u_int8_t period; /* Max Period for nego. */
252 1.6.2.2 thorpej
253 1.6.2.2 thorpej u_int8_t synctl; /* Sync control for reg. */
254 1.6.2.2 thorpej u_int8_t offset; /* Sync offset for reg. and nego.(low nibble) */
255 1.6.2.2 thorpej u_int8_t mode; /* Sync mode ? (1 sync):(0 async) */
256 1.6.2.2 thorpej #define SYNC_NEGO_ENABLE 0x01
257 1.6.2.2 thorpej #define SYNC_NEGO_DONE 0x02
258 1.6.2.2 thorpej #define WIDE_NEGO_ENABLE 0x04
259 1.6.2.2 thorpej #define WIDE_NEGO_DONE 0x08
260 1.6.2.2 thorpej #define EN_TAG_QUEUING 0x10
261 1.6.2.2 thorpej #define EN_ATN_STOP 0x20
262 1.6.2.2 thorpej #define SYNC_NEGO_OFFSET 15
263 1.6.2.2 thorpej u_int8_t flag;
264 1.6.2.2 thorpej #define ABORT_DEV_ 0x01
265 1.6.2.2 thorpej #define SHOW_MESSAGE_ 0x02
266 1.6.2.2 thorpej };
267 1.6.2.2 thorpej
268 1.6.2.2 thorpej /*
269 1.6.2.2 thorpej *-----------------------------------------------------------------------
270 1.6.2.2 thorpej * Adapter Control Block
271 1.6.2.2 thorpej *-----------------------------------------------------------------------
272 1.6.2.2 thorpej */
273 1.6.2.2 thorpej struct trm_softc {
274 1.6.2.2 thorpej struct device sc_dev;
275 1.6.2.2 thorpej
276 1.6.2.2 thorpej bus_space_tag_t sc_iot;
277 1.6.2.2 thorpej bus_space_handle_t sc_ioh;
278 1.6.2.2 thorpej bus_dma_tag_t sc_dmat;
279 1.6.2.2 thorpej bus_dmamap_t sc_dmamap; /* Map the control structures */
280 1.6.2.2 thorpej
281 1.6.2.2 thorpej struct trm_dcb *sc_linkdcb;
282 1.6.2.2 thorpej struct trm_dcb *sc_roundcb;
283 1.6.2.2 thorpej
284 1.6.2.2 thorpej struct trm_dcb *sc_actdcb;
285 1.6.2.2 thorpej struct trm_dcb *sc_dcb[TRM_MAX_TARGETS][8];
286 1.6.2.2 thorpej
287 1.6.2.2 thorpej struct trm_srb *sc_freesrb;
288 1.6.2.2 thorpej struct trm_srb *sc_srb; /* SRB array */
289 1.6.2.2 thorpej struct trm_srb sc_tempsrb;
290 1.6.2.2 thorpej
291 1.6.2.2 thorpej struct trm_sg_entry *sc_sglist;
292 1.6.2.2 thorpej
293 1.6.2.2 thorpej int maxid;
294 1.6.2.2 thorpej int maxtag; /* Max Tag number */
295 1.6.2.2 thorpej /*
296 1.6.2.2 thorpej * Link to the generic SCSI driver
297 1.6.2.2 thorpej */
298 1.6.2.2 thorpej struct scsipi_channel sc_channel;
299 1.6.2.2 thorpej struct scsipi_adapter sc_adapter;
300 1.6.2.2 thorpej
301 1.6.2.2 thorpej int sc_id; /* Adapter SCSI Target ID */
302 1.6.2.2 thorpej
303 1.6.2.2 thorpej int devcnt; /* Device Count */
304 1.6.2.2 thorpej
305 1.6.2.2 thorpej int devflag[TRM_MAX_TARGETS][8]; /* flag of initDCB for device */
306 1.6.2.2 thorpej
307 1.6.2.2 thorpej int devscan[TRM_MAX_TARGETS][8];
308 1.6.2.2 thorpej int devscan_end;
309 1.6.2.2 thorpej int cur_offset; /* Current Sync offset */
310 1.6.2.2 thorpej
311 1.6.2.2 thorpej struct trm_nvram sc_eeprom;
312 1.6.2.2 thorpej int sc_config;
313 1.6.2.2 thorpej #define HCC_WIDE_CARD 0x20
314 1.6.2.2 thorpej #define HCC_SCSI_RESET 0x10
315 1.6.2.2 thorpej #define HCC_PARITY 0x08
316 1.6.2.2 thorpej #define HCC_AUTOTERM 0x04
317 1.6.2.2 thorpej #define HCC_LOW8TERM 0x02
318 1.6.2.2 thorpej #define HCC_UP8TERM 0x01
319 1.6.2.2 thorpej int sc_flag;
320 1.6.2.2 thorpej #define RESET_DEV 0x01
321 1.6.2.2 thorpej #define RESET_DETECT 0x02
322 1.6.2.2 thorpej #define RESET_DONE 0x04
323 1.6.2.2 thorpej };
324 1.6.2.2 thorpej
325 1.6.2.2 thorpej /*
326 1.6.2.2 thorpej * SCSI Status codes not defined in scsi_all.h
327 1.6.2.2 thorpej */
328 1.6.2.2 thorpej #define SCSI_COND_MET 0x04 /* Condition Met */
329 1.6.2.2 thorpej #define SCSI_INTERM_COND_MET 0x14 /* Intermediate condition met */
330 1.6.2.2 thorpej #define SCSI_UNEXP_BUS_FREE 0xFD /* Unexpect Bus Free */
331 1.6.2.2 thorpej #define SCSI_BUS_RST_DETECT 0xFE /* Scsi Bus Reset detected */
332 1.6.2.2 thorpej #define SCSI_SEL_TIMEOUT 0xFF /* Selection Time out */
333 1.6.2.2 thorpej
334 1.6.2.2 thorpej static void trm_rewait_srb(struct trm_dcb *, struct trm_srb *);
335 1.6.2.2 thorpej static void trm_wait_srb(struct trm_softc *);
336 1.6.2.2 thorpej static void trm_reset_device(struct trm_softc *);
337 1.6.2.2 thorpej static void trm_recover_srb(struct trm_softc *);
338 1.6.2.2 thorpej static int trm_start_scsi(struct trm_softc *, struct trm_dcb *,
339 1.6.2.2 thorpej struct trm_srb *);
340 1.6.2.2 thorpej static int trm_intr(void *);
341 1.6.2.2 thorpej
342 1.6.2.2 thorpej static void trm_dataout_phase0(struct trm_softc *, struct trm_srb *, int *);
343 1.6.2.2 thorpej static void trm_datain_phase0(struct trm_softc *, struct trm_srb *, int *);
344 1.6.2.2 thorpej static void trm_command_phase0(struct trm_softc *, struct trm_srb *, int *);
345 1.6.2.2 thorpej static void trm_status_phase0(struct trm_softc *, struct trm_srb *, int *);
346 1.6.2.2 thorpej static void trm_msgout_phase0(struct trm_softc *, struct trm_srb *, int *);
347 1.6.2.2 thorpej static void trm_msgin_phase0(struct trm_softc *, struct trm_srb *, int *);
348 1.6.2.2 thorpej static void trm_dataout_phase1(struct trm_softc *, struct trm_srb *, int *);
349 1.6.2.2 thorpej static void trm_datain_phase1(struct trm_softc *, struct trm_srb *, int *);
350 1.6.2.2 thorpej static void trm_command_phase1(struct trm_softc *, struct trm_srb *, int *);
351 1.6.2.2 thorpej static void trm_status_phase1(struct trm_softc *, struct trm_srb *, int *);
352 1.6.2.2 thorpej static void trm_msgout_phase1(struct trm_softc *, struct trm_srb *, int *);
353 1.6.2.2 thorpej static void trm_msgin_phase1(struct trm_softc *, struct trm_srb *, int *);
354 1.6.2.2 thorpej static void trm_nop0(struct trm_softc *, struct trm_srb *, int *);
355 1.6.2.2 thorpej static void trm_nop1(struct trm_softc *, struct trm_srb *, int *);
356 1.6.2.2 thorpej
357 1.6.2.2 thorpej static void trm_set_xfer_rate(struct trm_softc *, struct trm_srb *,
358 1.6.2.2 thorpej struct trm_dcb *);
359 1.6.2.2 thorpej static void trm_dataio_xfer(struct trm_softc *, struct trm_srb *, int);
360 1.6.2.2 thorpej static void trm_disconnect(struct trm_softc *);
361 1.6.2.2 thorpej static void trm_reselect(struct trm_softc *);
362 1.6.2.2 thorpej static void trm_srb_done(struct trm_softc *, struct trm_dcb *,
363 1.6.2.2 thorpej struct trm_srb *);
364 1.6.2.2 thorpej static void trm_doing_srb_done(struct trm_softc *);
365 1.6.2.2 thorpej static void trm_scsi_reset_detect(struct trm_softc *);
366 1.6.2.2 thorpej static void trm_reset_scsi_bus(struct trm_softc *);
367 1.6.2.2 thorpej static int trm_request_sense(struct trm_softc *, struct trm_dcb *,
368 1.6.2.2 thorpej struct trm_srb *);
369 1.6.2.2 thorpej static void trm_msgout_abort(struct trm_softc *, struct trm_srb *);
370 1.6.2.2 thorpej static void trm_timeout(void *);
371 1.6.2.2 thorpej static void trm_reset(struct trm_softc *);
372 1.6.2.2 thorpej static void trm_send_srb(struct scsipi_xfer *, struct trm_softc *,
373 1.6.2.2 thorpej struct trm_srb *);
374 1.6.2.2 thorpej static int trm_init(struct trm_softc *);
375 1.6.2.2 thorpej static void trm_init_adapter(struct trm_softc *);
376 1.6.2.2 thorpej static void trm_init_dcb(struct trm_softc *, struct trm_dcb *,
377 1.6.2.2 thorpej struct scsipi_xfer *);
378 1.6.2.2 thorpej static void trm_link_srb(struct trm_softc *);
379 1.6.2.2 thorpej static void trm_init_sc(struct trm_softc *);
380 1.6.2.2 thorpej static void trm_check_eeprom(struct trm_softc *, struct trm_nvram *);
381 1.6.2.2 thorpej static void trm_release_srb(struct trm_softc *, struct trm_dcb *,
382 1.6.2.2 thorpej struct trm_srb *);
383 1.6.2.2 thorpej void trm_scsipi_request(struct scsipi_channel *, scsipi_adapter_req_t, void *);
384 1.6.2.2 thorpej
385 1.6.2.2 thorpej static void trm_eeprom_read_all(struct trm_softc *, struct trm_nvram *);
386 1.6.2.2 thorpej static void trm_eeprom_write_all(struct trm_softc *, struct trm_nvram *);
387 1.6.2.2 thorpej static void trm_eeprom_set_data(struct trm_softc *, u_int8_t, u_int8_t);
388 1.6.2.2 thorpej static void trm_eeprom_write_cmd(struct trm_softc *, u_int8_t, u_int8_t);
389 1.6.2.2 thorpej static u_int8_t trm_eeprom_get_data(struct trm_softc *, u_int8_t);
390 1.6.2.2 thorpej
391 1.6.2.2 thorpej static int trm_probe(struct device *, struct cfdata *, void *);
392 1.6.2.2 thorpej static void trm_attach(struct device *, struct device *, void *);
393 1.6.2.2 thorpej
394 1.6.2.2 thorpej struct cfattach trm_ca = {
395 1.6.2.2 thorpej sizeof(struct trm_softc), trm_probe, trm_attach
396 1.6.2.2 thorpej };
397 1.6.2.2 thorpej
398 1.6.2.2 thorpej
399 1.6.2.2 thorpej /*
400 1.6.2.2 thorpej * state_v = (void *) trm_scsi_phase0[phase]
401 1.6.2.2 thorpej */
402 1.6.2.2 thorpej static void *trm_scsi_phase0[] = {
403 1.6.2.2 thorpej trm_dataout_phase0, /* phase:0 */
404 1.6.2.2 thorpej trm_datain_phase0, /* phase:1 */
405 1.6.2.2 thorpej trm_command_phase0, /* phase:2 */
406 1.6.2.2 thorpej trm_status_phase0, /* phase:3 */
407 1.6.2.2 thorpej trm_nop0, /* phase:4 */
408 1.6.2.2 thorpej trm_nop1, /* phase:5 */
409 1.6.2.2 thorpej trm_msgout_phase0, /* phase:6 */
410 1.6.2.2 thorpej trm_msgin_phase0, /* phase:7 */
411 1.6.2.2 thorpej };
412 1.6.2.2 thorpej
413 1.6.2.2 thorpej /*
414 1.6.2.2 thorpej * state_v = (void *) trm_scsi_phase1[phase]
415 1.6.2.2 thorpej */
416 1.6.2.2 thorpej static void *trm_scsi_phase1[] = {
417 1.6.2.2 thorpej trm_dataout_phase1, /* phase:0 */
418 1.6.2.2 thorpej trm_datain_phase1, /* phase:1 */
419 1.6.2.2 thorpej trm_command_phase1, /* phase:2 */
420 1.6.2.2 thorpej trm_status_phase1, /* phase:3 */
421 1.6.2.2 thorpej trm_nop0, /* phase:4 */
422 1.6.2.2 thorpej trm_nop1, /* phase:5 */
423 1.6.2.2 thorpej trm_msgout_phase1, /* phase:6 */
424 1.6.2.2 thorpej trm_msgin_phase1, /* phase:7 */
425 1.6.2.2 thorpej };
426 1.6.2.2 thorpej
427 1.6.2.2 thorpej /* real period: */
428 1.6.2.2 thorpej static const u_int8_t trm_clock_period[] = {
429 1.6.2.2 thorpej 12, /* 48 ns 20.0 MB/sec */
430 1.6.2.2 thorpej 18, /* 72 ns 13.3 MB/sec */
431 1.6.2.2 thorpej 25, /* 100 ns 10.0 MB/sec */
432 1.6.2.2 thorpej 31, /* 124 ns 8.0 MB/sec */
433 1.6.2.2 thorpej 37, /* 148 ns 6.6 MB/sec */
434 1.6.2.2 thorpej 43, /* 172 ns 5.7 MB/sec */
435 1.6.2.2 thorpej 50, /* 200 ns 5.0 MB/sec */
436 1.6.2.2 thorpej 62 /* 248 ns 4.0 MB/sec */
437 1.6.2.2 thorpej };
438 1.6.2.2 thorpej
439 1.6.2.2 thorpej /*
440 1.6.2.2 thorpej * Q back to pending Q
441 1.6.2.2 thorpej */
442 1.6.2.2 thorpej static void
443 1.6.2.2 thorpej trm_rewait_srb(dcb, srb)
444 1.6.2.2 thorpej struct trm_dcb *dcb;
445 1.6.2.2 thorpej struct trm_srb *srb;
446 1.6.2.2 thorpej {
447 1.6.2.2 thorpej struct trm_srb *psrb1;
448 1.6.2.2 thorpej int s;
449 1.6.2.2 thorpej
450 1.6.2.2 thorpej s = splbio();
451 1.6.2.2 thorpej
452 1.6.2.2 thorpej dcb->gosrb_cnt--;
453 1.6.2.2 thorpej psrb1 = dcb->gosrb;
454 1.6.2.2 thorpej if (srb == psrb1)
455 1.6.2.2 thorpej dcb->gosrb = psrb1->next;
456 1.6.2.2 thorpej else {
457 1.6.2.2 thorpej while (srb != psrb1->next)
458 1.6.2.2 thorpej psrb1 = psrb1->next;
459 1.6.2.2 thorpej
460 1.6.2.2 thorpej psrb1->next = srb->next;
461 1.6.2.2 thorpej if (srb == dcb->last_gosrb)
462 1.6.2.2 thorpej dcb->last_gosrb = psrb1;
463 1.6.2.2 thorpej }
464 1.6.2.2 thorpej if (dcb->waitsrb) {
465 1.6.2.2 thorpej srb->next = dcb->waitsrb;
466 1.6.2.2 thorpej dcb->waitsrb = srb;
467 1.6.2.2 thorpej } else {
468 1.6.2.2 thorpej srb->next = NULL;
469 1.6.2.2 thorpej dcb->waitsrb = srb;
470 1.6.2.2 thorpej dcb->last_waitsrb = srb;
471 1.6.2.2 thorpej }
472 1.6.2.2 thorpej dcb->tagmask &= ~(1 << srb->tagnum); /* Free TAG number */
473 1.6.2.2 thorpej
474 1.6.2.2 thorpej splx(s);
475 1.6.2.2 thorpej }
476 1.6.2.2 thorpej
477 1.6.2.2 thorpej static void
478 1.6.2.2 thorpej trm_wait_srb(sc)
479 1.6.2.2 thorpej struct trm_softc *sc;
480 1.6.2.2 thorpej {
481 1.6.2.2 thorpej struct trm_dcb *ptr, *ptr1;
482 1.6.2.2 thorpej struct trm_srb *srb;
483 1.6.2.2 thorpej int s;
484 1.6.2.2 thorpej
485 1.6.2.2 thorpej s = splbio();
486 1.6.2.2 thorpej
487 1.6.2.2 thorpej if (sc->sc_actdcb == NULL &&
488 1.6.2.2 thorpej (sc->sc_flag & (RESET_DETECT | RESET_DONE | RESET_DEV)) == 0) {
489 1.6.2.2 thorpej ptr = sc->sc_roundcb;
490 1.6.2.2 thorpej if (ptr == NULL) {
491 1.6.2.2 thorpej ptr = sc->sc_linkdcb;
492 1.6.2.2 thorpej sc->sc_roundcb = ptr;
493 1.6.2.2 thorpej }
494 1.6.2.2 thorpej for (ptr1 = ptr; ptr1 != NULL;) {
495 1.6.2.2 thorpej sc->sc_roundcb = ptr1->next;
496 1.6.2.2 thorpej if (ptr1->maxcmd <= ptr1->gosrb_cnt ||
497 1.6.2.2 thorpej (srb = ptr1->waitsrb) == NULL) {
498 1.6.2.2 thorpej if (sc->sc_roundcb == ptr)
499 1.6.2.2 thorpej break;
500 1.6.2.2 thorpej ptr1 = ptr1->next;
501 1.6.2.2 thorpej } else {
502 1.6.2.2 thorpej if (trm_start_scsi(sc, ptr1, srb) == 0) {
503 1.6.2.2 thorpej /*
504 1.6.2.2 thorpej * If trm_start_scsi return 0 :
505 1.6.2.2 thorpej * current interrupt status is
506 1.6.2.2 thorpej * interrupt enable. It's said that
507 1.6.2.2 thorpej * SCSI processor is unoccupied
508 1.6.2.2 thorpej */
509 1.6.2.2 thorpej ptr1->gosrb_cnt++;
510 1.6.2.2 thorpej if (ptr1->last_waitsrb == srb) {
511 1.6.2.2 thorpej ptr1->waitsrb = NULL;
512 1.6.2.2 thorpej ptr1->last_waitsrb = NULL;
513 1.6.2.2 thorpej } else
514 1.6.2.2 thorpej ptr1->waitsrb = srb->next;
515 1.6.2.2 thorpej
516 1.6.2.2 thorpej srb->next = NULL;
517 1.6.2.2 thorpej if (ptr1->gosrb != NULL)
518 1.6.2.2 thorpej ptr1->last_gosrb->next = srb;
519 1.6.2.2 thorpej else
520 1.6.2.2 thorpej ptr1->gosrb = srb;
521 1.6.2.2 thorpej
522 1.6.2.2 thorpej ptr1->last_gosrb = srb;
523 1.6.2.2 thorpej }
524 1.6.2.2 thorpej break;
525 1.6.2.2 thorpej }
526 1.6.2.2 thorpej }
527 1.6.2.2 thorpej }
528 1.6.2.2 thorpej splx(s);
529 1.6.2.2 thorpej }
530 1.6.2.2 thorpej
531 1.6.2.2 thorpej static void
532 1.6.2.2 thorpej trm_send_srb(xs, sc, srb)
533 1.6.2.2 thorpej struct scsipi_xfer *xs;
534 1.6.2.2 thorpej struct trm_softc *sc;
535 1.6.2.2 thorpej struct trm_srb *srb;
536 1.6.2.2 thorpej {
537 1.6.2.2 thorpej struct trm_dcb *dcb;
538 1.6.2.2 thorpej int s;
539 1.6.2.2 thorpej
540 1.6.2.2 thorpej #ifdef TRM_DEBUG
541 1.6.2.2 thorpej printf("trm_send_srb..........\n");
542 1.6.2.2 thorpej #endif
543 1.6.2.2 thorpej s = splbio();
544 1.6.2.2 thorpej
545 1.6.2.2 thorpej /*
546 1.6.2.2 thorpej * now get the DCB from upper layer( OS )
547 1.6.2.2 thorpej */
548 1.6.2.2 thorpej dcb = srb->dcb;
549 1.6.2.2 thorpej
550 1.6.2.2 thorpej if (dcb->maxcmd <= dcb->gosrb_cnt ||
551 1.6.2.2 thorpej sc->sc_actdcb != NULL ||
552 1.6.2.2 thorpej (sc->sc_flag & (RESET_DETECT | RESET_DONE | RESET_DEV))) {
553 1.6.2.2 thorpej if (dcb->waitsrb != NULL) {
554 1.6.2.2 thorpej dcb->last_waitsrb->next = srb;
555 1.6.2.2 thorpej dcb->last_waitsrb = srb;
556 1.6.2.2 thorpej srb->next = NULL;
557 1.6.2.2 thorpej } else {
558 1.6.2.2 thorpej dcb->waitsrb = srb;
559 1.6.2.2 thorpej dcb->last_waitsrb = srb;
560 1.6.2.2 thorpej }
561 1.6.2.2 thorpej splx(s);
562 1.6.2.2 thorpej return;
563 1.6.2.2 thorpej }
564 1.6.2.2 thorpej if (dcb->waitsrb != NULL) {
565 1.6.2.2 thorpej dcb->last_waitsrb->next = srb;
566 1.6.2.2 thorpej dcb->last_waitsrb = srb;
567 1.6.2.2 thorpej srb->next = NULL;
568 1.6.2.2 thorpej /* srb = GetWaitingSRB(dcb); */
569 1.6.2.2 thorpej srb = dcb->waitsrb;
570 1.6.2.2 thorpej dcb->waitsrb = srb->next;
571 1.6.2.2 thorpej srb->next = NULL;
572 1.6.2.2 thorpej }
573 1.6.2.2 thorpej if (trm_start_scsi(sc, dcb, srb) == 0) {
574 1.6.2.2 thorpej /*
575 1.6.2.2 thorpej * If trm_start_scsi return 0: current interrupt status
576 1.6.2.2 thorpej * is interrupt enable. It's said that SCSI processor is
577 1.6.2.2 thorpej * unoccupied.
578 1.6.2.2 thorpej */
579 1.6.2.2 thorpej dcb->gosrb_cnt++; /* stack waiting SRB */
580 1.6.2.2 thorpej if (dcb->gosrb != NULL) {
581 1.6.2.2 thorpej dcb->last_gosrb->next = srb;
582 1.6.2.2 thorpej dcb->last_gosrb = srb;
583 1.6.2.2 thorpej } else {
584 1.6.2.2 thorpej dcb->gosrb = srb;
585 1.6.2.2 thorpej dcb->last_gosrb = srb;
586 1.6.2.2 thorpej }
587 1.6.2.2 thorpej } else {
588 1.6.2.2 thorpej /*
589 1.6.2.2 thorpej * If trm_start_scsi return 1: current interrupt status
590 1.6.2.2 thorpej * is interrupt disreenable. It's said that SCSI processor
591 1.6.2.2 thorpej * has more one SRB need to do we need reQ back SRB.
592 1.6.2.2 thorpej */
593 1.6.2.2 thorpej if (dcb->waitsrb != NULL) {
594 1.6.2.2 thorpej srb->next = dcb->waitsrb;
595 1.6.2.2 thorpej dcb->waitsrb = srb;
596 1.6.2.2 thorpej } else {
597 1.6.2.2 thorpej srb->next = NULL;
598 1.6.2.2 thorpej dcb->waitsrb = srb;
599 1.6.2.2 thorpej dcb->last_waitsrb = srb;
600 1.6.2.2 thorpej }
601 1.6.2.2 thorpej }
602 1.6.2.2 thorpej
603 1.6.2.2 thorpej splx(s);
604 1.6.2.2 thorpej }
605 1.6.2.2 thorpej
606 1.6.2.2 thorpej /*
607 1.6.2.2 thorpej * Called by GENERIC SCSI driver
608 1.6.2.2 thorpej * enqueues a SCSI command
609 1.6.2.2 thorpej */
610 1.6.2.2 thorpej void
611 1.6.2.2 thorpej trm_scsipi_request(chan, req, arg)
612 1.6.2.2 thorpej struct scsipi_channel *chan;
613 1.6.2.2 thorpej scsipi_adapter_req_t req;
614 1.6.2.2 thorpej void *arg;
615 1.6.2.2 thorpej {
616 1.6.2.2 thorpej bus_space_tag_t iot;
617 1.6.2.2 thorpej bus_space_handle_t ioh;
618 1.6.2.2 thorpej struct trm_softc *sc;
619 1.6.2.2 thorpej struct trm_dcb *dcb = NULL;
620 1.6.2.2 thorpej struct trm_srb *srb;
621 1.6.2.2 thorpej struct scsipi_xfer *xs;
622 1.6.2.2 thorpej int error, i, id, lun, s;
623 1.6.2.2 thorpej
624 1.6.2.2 thorpej sc = (struct trm_softc *)chan->chan_adapter->adapt_dev;
625 1.6.2.2 thorpej iot = sc->sc_iot;
626 1.6.2.2 thorpej ioh = sc->sc_ioh;
627 1.6.2.2 thorpej
628 1.6.2.2 thorpej switch (req) {
629 1.6.2.2 thorpej case ADAPTER_REQ_RUN_XFER:
630 1.6.2.2 thorpej xs = arg;
631 1.6.2.2 thorpej id = xs->xs_periph->periph_target;
632 1.6.2.2 thorpej lun = xs->xs_periph->periph_lun;
633 1.6.2.2 thorpej #ifdef TRM_DEBUG
634 1.6.2.2 thorpej printf("trm_scsipi_request.....\n");
635 1.6.2.2 thorpej printf("%s: id= %d lun= %d\n", sc->sc_dev.dv_xname, id, lun);
636 1.6.2.2 thorpej printf("sc->devscan[id][lun]= %d\n", sc->devscan[id][lun]);
637 1.6.2.2 thorpej #endif
638 1.6.2.2 thorpej if ((id > sc->maxid) || (lun > 7)) {
639 1.6.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
640 1.6.2.2 thorpej return;
641 1.6.2.2 thorpej }
642 1.6.2.2 thorpej dcb = sc->sc_dcb[id][lun];
643 1.6.2.2 thorpej if (sc->devscan[id][lun] != 0 && sc->devflag[id][lun] == 0) {
644 1.6.2.2 thorpej /*
645 1.6.2.2 thorpej * Scan SCSI BUS => trm_init_dcb
646 1.6.2.2 thorpej */
647 1.6.2.2 thorpej if (sc->devcnt < TRM_MAX_TARGETS) {
648 1.6.2.2 thorpej #ifdef TRM_DEBUG
649 1.6.2.2 thorpej printf("trm_init_dcb: dcb=%8x, ", (int) dcb);
650 1.6.2.2 thorpej printf("ID=%2x, LUN=%2x\n", id, lun);
651 1.6.2.2 thorpej #endif
652 1.6.2.2 thorpej sc->devflag[id][lun] = 1;
653 1.6.2.2 thorpej trm_init_dcb(sc, dcb, xs);
654 1.6.2.2 thorpej } else {
655 1.6.2.2 thorpej printf("%s: ", sc->sc_dev.dv_xname);
656 1.6.2.2 thorpej printf("sc->devcnt >= TRM_MAX_TARGETS\n");
657 1.6.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
658 1.6.2.2 thorpej return;
659 1.6.2.2 thorpej }
660 1.6.2.2 thorpej }
661 1.6.2.2 thorpej
662 1.6.2.2 thorpej if (xs->xs_control & XS_CTL_RESET) {
663 1.6.2.2 thorpej trm_reset(sc);
664 1.6.2.2 thorpej xs->error = XS_NOERROR | XS_RESET;
665 1.6.2.2 thorpej return;
666 1.6.2.2 thorpej }
667 1.6.2.2 thorpej if (xs->xs_status & XS_STS_DONE) {
668 1.6.2.2 thorpej printf("%s: Is it done?\n", sc->sc_dev.dv_xname);
669 1.6.2.2 thorpej xs->xs_status &= ~XS_STS_DONE;
670 1.6.2.2 thorpej }
671 1.6.2.2 thorpej xs->error = 0;
672 1.6.2.2 thorpej xs->status = 0;
673 1.6.2.2 thorpej xs->resid = 0;
674 1.6.2.2 thorpej
675 1.6.2.2 thorpej s = splbio();
676 1.6.2.2 thorpej
677 1.6.2.2 thorpej /* Get SRB */
678 1.6.2.2 thorpej srb = sc->sc_freesrb;
679 1.6.2.2 thorpej if (srb != NULL) {
680 1.6.2.2 thorpej sc->sc_freesrb = srb->next;
681 1.6.2.2 thorpej srb->next = NULL;
682 1.6.2.2 thorpej #ifdef TRM_DEBUG
683 1.6.2.2 thorpej printf("srb = %8p sc->sc_freesrb= %8p\n",
684 1.6.2.2 thorpej srb, sc->sc_freesrb);
685 1.6.2.2 thorpej #endif
686 1.6.2.2 thorpej } else {
687 1.6.2.2 thorpej xs->error = XS_RESOURCE_SHORTAGE;
688 1.6.2.2 thorpej scsipi_done(xs);
689 1.6.2.2 thorpej splx(s);
690 1.6.2.2 thorpej return;
691 1.6.2.2 thorpej }
692 1.6.2.2 thorpej /*
693 1.6.2.2 thorpej * XXX BuildSRB(srb ,dcb); XXX
694 1.6.2.2 thorpej */
695 1.6.2.2 thorpej srb->dcb = dcb;
696 1.6.2.2 thorpej srb->xs = xs;
697 1.6.2.2 thorpej srb->cmdlen = xs->cmdlen;
698 1.6.2.2 thorpej /*
699 1.6.2.2 thorpej * Move layer of CAM command block to layer of SCSI
700 1.6.2.2 thorpej * Request Block for SCSI processor command doing.
701 1.6.2.2 thorpej */
702 1.6.2.2 thorpej memcpy(srb->cmd, xs->cmd, xs->cmdlen);
703 1.6.2.2 thorpej if (xs->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT)) {
704 1.6.2.2 thorpej #ifdef TRM_DEBUG
705 1.6.2.2 thorpej printf("xs->datalen...\n");
706 1.6.2.2 thorpej printf("sc->sc_dmat=%x\n", (int) sc->sc_dmat);
707 1.6.2.2 thorpej printf("srb->dmap=%x\n", (int) srb->dmap);
708 1.6.2.2 thorpej printf("xs->data=%x\n", (int) xs->data);
709 1.6.2.2 thorpej printf("xs->datalen=%x\n", (int) xs->datalen);
710 1.6.2.2 thorpej #endif
711 1.6.2.2 thorpej if ((error = bus_dmamap_load(sc->sc_dmat, srb->dmap,
712 1.6.2.2 thorpej xs->data, xs->datalen, NULL,
713 1.6.2.2 thorpej ((xs->xs_control & XS_CTL_NOSLEEP) ?
714 1.6.2.2 thorpej BUS_DMA_NOWAIT : BUS_DMA_WAITOK) |
715 1.6.2.2 thorpej BUS_DMA_STREAMING |
716 1.6.2.2 thorpej ((xs->xs_control & XS_CTL_DATA_IN) ?
717 1.6.2.2 thorpej BUS_DMA_READ : BUS_DMA_WRITE))) != 0) {
718 1.6.2.2 thorpej printf("%s: DMA transfer map unable to load, "
719 1.6.2.2 thorpej "error = %d\n", sc->sc_dev.dv_xname, error);
720 1.6.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
721 1.6.2.2 thorpej /*
722 1.6.2.2 thorpej * free SRB
723 1.6.2.2 thorpej */
724 1.6.2.2 thorpej srb->next = sc->sc_freesrb;
725 1.6.2.2 thorpej sc->sc_freesrb = srb;
726 1.6.2.2 thorpej splx(s);
727 1.6.2.2 thorpej return;
728 1.6.2.2 thorpej }
729 1.6.2.2 thorpej bus_dmamap_sync(sc->sc_dmat, srb->dmap, 0,
730 1.6.2.2 thorpej srb->dmap->dm_mapsize,
731 1.6.2.2 thorpej (xs->xs_control & XS_CTL_DATA_IN) ?
732 1.6.2.2 thorpej BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
733 1.6.2.2 thorpej
734 1.6.2.2 thorpej /* Set up the scatter gather list */
735 1.6.2.2 thorpej for (i = 0; i < srb->dmap->dm_nsegs; i++) {
736 1.6.2.2 thorpej srb->sgentry[i].address =
737 1.6.2.2 thorpej htole32(srb->dmap->dm_segs[i].ds_addr);
738 1.6.2.2 thorpej srb->sgentry[i].length =
739 1.6.2.2 thorpej htole32(srb->dmap->dm_segs[i].ds_len);
740 1.6.2.2 thorpej }
741 1.6.2.2 thorpej srb->buflen = xs->datalen;
742 1.6.2.2 thorpej srb->sgcnt = srb->dmap->dm_nsegs;
743 1.6.2.2 thorpej } else {
744 1.6.2.2 thorpej srb->sgentry[0].address = 0;
745 1.6.2.2 thorpej srb->sgentry[0].length = 0;
746 1.6.2.2 thorpej srb->buflen = 0;
747 1.6.2.2 thorpej srb->sgcnt = 0;
748 1.6.2.2 thorpej }
749 1.6.2.2 thorpej bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
750 1.6.2.2 thorpej srb->sgoffset, TRM_SG_SIZE, BUS_DMASYNC_PREWRITE);
751 1.6.2.2 thorpej
752 1.6.2.2 thorpej srb->sgindex = 0;
753 1.6.2.2 thorpej srb->hastat = 0;
754 1.6.2.2 thorpej srb->tastat = 0;
755 1.6.2.2 thorpej srb->msgcnt = 0;
756 1.6.2.2 thorpej srb->srbstat = 0;
757 1.6.2.2 thorpej srb->flag = 0;
758 1.6.2.2 thorpej srb->state = 0;
759 1.6.2.2 thorpej srb->phase = PH_BUS_FREE; /* SCSI bus free Phase */
760 1.6.2.2 thorpej
761 1.6.2.2 thorpej trm_send_srb(xs, sc, srb);
762 1.6.2.2 thorpej splx(s);
763 1.6.2.2 thorpej
764 1.6.2.2 thorpej if ((xs->xs_control & XS_CTL_POLL) == 0) {
765 1.6.2.2 thorpej int timeout = xs->timeout;
766 1.6.2.2 thorpej timeout = (timeout > 100000) ?
767 1.6.2.2 thorpej timeout / 1000 * hz : timeout * hz / 1000;
768 1.6.2.2 thorpej callout_reset(&xs->xs_callout, timeout,
769 1.6.2.2 thorpej trm_timeout, srb);
770 1.6.2.2 thorpej } else {
771 1.6.2.2 thorpej s = splbio();
772 1.6.2.2 thorpej do {
773 1.6.2.2 thorpej while (--xs->timeout) {
774 1.6.2.2 thorpej DELAY(1000);
775 1.6.2.2 thorpej if (bus_space_read_2(iot, ioh,
776 1.6.2.2 thorpej TRM_SCSI_STATUS) & SCSIINTERRUPT)
777 1.6.2.2 thorpej break;
778 1.6.2.2 thorpej }
779 1.6.2.2 thorpej if (xs->timeout == 0) {
780 1.6.2.2 thorpej trm_timeout(srb);
781 1.6.2.2 thorpej break;
782 1.6.2.2 thorpej } else
783 1.6.2.2 thorpej trm_intr(sc);
784 1.6.2.2 thorpej } while ((xs->xs_status & XS_STS_DONE) == 0);
785 1.6.2.2 thorpej splx(s);
786 1.6.2.2 thorpej }
787 1.6.2.2 thorpej return;
788 1.6.2.2 thorpej
789 1.6.2.2 thorpej case ADAPTER_REQ_GROW_RESOURCES:
790 1.6.2.2 thorpej /* XXX Not supported. */
791 1.6.2.2 thorpej return;
792 1.6.2.2 thorpej
793 1.6.2.2 thorpej case ADAPTER_REQ_SET_XFER_MODE:
794 1.6.2.2 thorpej /* XXX XXX XXX */
795 1.6.2.2 thorpej return;
796 1.6.2.2 thorpej }
797 1.6.2.2 thorpej }
798 1.6.2.2 thorpej
799 1.6.2.2 thorpej static void
800 1.6.2.2 thorpej trm_reset_device(sc)
801 1.6.2.2 thorpej struct trm_softc *sc;
802 1.6.2.2 thorpej {
803 1.6.2.2 thorpej struct trm_dcb *dcb, *pdcb;
804 1.6.2.2 thorpej struct trm_nvram *eeprom;
805 1.6.2.2 thorpej int index;
806 1.6.2.2 thorpej
807 1.6.2.2 thorpej dcb = sc->sc_linkdcb;
808 1.6.2.2 thorpej if (dcb == NULL)
809 1.6.2.2 thorpej return;
810 1.6.2.2 thorpej
811 1.6.2.2 thorpej pdcb = dcb;
812 1.6.2.2 thorpej do {
813 1.6.2.2 thorpej dcb->mode &= ~(SYNC_NEGO_DONE | WIDE_NEGO_DONE);
814 1.6.2.2 thorpej dcb->synctl = 0;
815 1.6.2.2 thorpej dcb->offset = 0;
816 1.6.2.2 thorpej eeprom = &sc->sc_eeprom;
817 1.6.2.2 thorpej dcb->tacfg = eeprom->target[dcb->id].config0;
818 1.6.2.2 thorpej index = eeprom->target[dcb->id].period & 0x07;
819 1.6.2.2 thorpej dcb->period = trm_clock_period[index];
820 1.6.2.2 thorpej if ((dcb->tacfg & NTC_DO_WIDE_NEGO) &&
821 1.6.2.2 thorpej (sc->sc_config & HCC_WIDE_CARD))
822 1.6.2.2 thorpej dcb->mode |= WIDE_NEGO_ENABLE;
823 1.6.2.2 thorpej
824 1.6.2.2 thorpej dcb = dcb->next;
825 1.6.2.2 thorpej }
826 1.6.2.2 thorpej while (pdcb != dcb);
827 1.6.2.2 thorpej }
828 1.6.2.2 thorpej
829 1.6.2.2 thorpej static void
830 1.6.2.2 thorpej trm_recover_srb(sc)
831 1.6.2.2 thorpej struct trm_softc *sc;
832 1.6.2.2 thorpej {
833 1.6.2.2 thorpej struct trm_dcb *dcb, *pdcb;
834 1.6.2.2 thorpej struct trm_srb *psrb, *psrb2;
835 1.6.2.2 thorpej int i;
836 1.6.2.2 thorpej
837 1.6.2.2 thorpej dcb = sc->sc_linkdcb;
838 1.6.2.2 thorpej if (dcb == NULL)
839 1.6.2.2 thorpej return;
840 1.6.2.2 thorpej
841 1.6.2.2 thorpej pdcb = dcb;
842 1.6.2.2 thorpej do {
843 1.6.2.2 thorpej psrb = pdcb->gosrb;
844 1.6.2.2 thorpej for (i = 0; i < pdcb->gosrb_cnt; i++) {
845 1.6.2.2 thorpej psrb2 = psrb;
846 1.6.2.2 thorpej psrb = psrb->next;
847 1.6.2.2 thorpej if (pdcb->waitsrb) {
848 1.6.2.2 thorpej psrb2->next = pdcb->waitsrb;
849 1.6.2.2 thorpej pdcb->waitsrb = psrb2;
850 1.6.2.2 thorpej } else {
851 1.6.2.2 thorpej pdcb->waitsrb = psrb2;
852 1.6.2.2 thorpej pdcb->last_waitsrb = psrb2;
853 1.6.2.2 thorpej psrb2->next = NULL;
854 1.6.2.2 thorpej }
855 1.6.2.2 thorpej }
856 1.6.2.2 thorpej pdcb->gosrb_cnt = 0;
857 1.6.2.2 thorpej pdcb->gosrb = NULL;
858 1.6.2.2 thorpej pdcb->tagmask = 0;
859 1.6.2.2 thorpej pdcb = pdcb->next;
860 1.6.2.2 thorpej }
861 1.6.2.2 thorpej while (pdcb != dcb);
862 1.6.2.2 thorpej }
863 1.6.2.2 thorpej
864 1.6.2.2 thorpej /*
865 1.6.2.2 thorpej * perform a hard reset on the SCSI bus (and TRM_S1040 chip).
866 1.6.2.2 thorpej */
867 1.6.2.2 thorpej static void
868 1.6.2.2 thorpej trm_reset(sc)
869 1.6.2.2 thorpej struct trm_softc *sc;
870 1.6.2.2 thorpej {
871 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
872 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
873 1.6.2.2 thorpej int s;
874 1.6.2.2 thorpej
875 1.6.2.2 thorpej #ifdef TRM_DEBUG
876 1.6.2.2 thorpej printf("%s: SCSI RESET.........", sc->sc_dev.dv_xname);
877 1.6.2.2 thorpej #endif
878 1.6.2.2 thorpej s = splbio();
879 1.6.2.2 thorpej
880 1.6.2.2 thorpej /* disable SCSI and DMA interrupt */
881 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_INTEN, 0);
882 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_INTEN, 0);
883 1.6.2.2 thorpej
884 1.6.2.2 thorpej trm_reset_scsi_bus(sc);
885 1.6.2.2 thorpej DELAY(500000);
886 1.6.2.2 thorpej
887 1.6.2.2 thorpej /* Enable SCSI interrupt */
888 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_INTEN,
889 1.6.2.2 thorpej EN_SELECT | EN_SELTIMEOUT | EN_DISCONNECT | EN_RESELECTED |
890 1.6.2.2 thorpej EN_SCSIRESET | EN_BUSSERVICE | EN_CMDDONE);
891 1.6.2.2 thorpej
892 1.6.2.2 thorpej /* Enable DMA interrupt */
893 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_INTEN, EN_SCSIINTR);
894 1.6.2.2 thorpej
895 1.6.2.2 thorpej /* Clear DMA FIFO */
896 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_CONTROL, CLRXFIFO);
897 1.6.2.2 thorpej
898 1.6.2.2 thorpej /* Clear SCSI FIFO */
899 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_CLRFIFO);
900 1.6.2.2 thorpej
901 1.6.2.2 thorpej trm_reset_device(sc);
902 1.6.2.2 thorpej trm_doing_srb_done(sc);
903 1.6.2.2 thorpej sc->sc_actdcb = NULL;
904 1.6.2.2 thorpej sc->sc_flag = 0; /* RESET_DETECT, RESET_DONE, RESET_DEV */
905 1.6.2.2 thorpej trm_wait_srb(sc);
906 1.6.2.2 thorpej
907 1.6.2.2 thorpej splx(s);
908 1.6.2.2 thorpej }
909 1.6.2.2 thorpej
910 1.6.2.2 thorpej static void
911 1.6.2.2 thorpej trm_timeout(arg)
912 1.6.2.2 thorpej void *arg;
913 1.6.2.2 thorpej {
914 1.6.2.2 thorpej struct trm_srb *srb = (struct trm_srb *)arg;
915 1.6.2.2 thorpej struct scsipi_xfer *xs = srb->xs;
916 1.6.2.2 thorpej struct scsipi_periph *periph = xs->xs_periph;
917 1.6.2.2 thorpej struct trm_softc *sc;
918 1.6.2.2 thorpej int s;
919 1.6.2.2 thorpej
920 1.6.2.2 thorpej if (xs == NULL)
921 1.6.2.2 thorpej printf("trm_timeout called with xs == NULL\n");
922 1.6.2.2 thorpej
923 1.6.2.2 thorpej else {
924 1.6.2.2 thorpej scsipi_printaddr(xs->xs_periph);
925 1.6.2.2 thorpej printf("SCSI OpCode 0x%02x timed out\n", xs->cmd->opcode);
926 1.6.2.2 thorpej }
927 1.6.2.2 thorpej
928 1.6.2.2 thorpej sc = (void *)periph->periph_channel->chan_adapter->adapt_dev;
929 1.6.2.2 thorpej
930 1.6.2.2 thorpej s = splbio();
931 1.6.2.2 thorpej trm_reset_scsi_bus(sc);
932 1.6.2.2 thorpej callout_stop(&xs->xs_callout);
933 1.6.2.2 thorpej splx(s);
934 1.6.2.2 thorpej }
935 1.6.2.2 thorpej
936 1.6.2.2 thorpej static int
937 1.6.2.2 thorpej trm_start_scsi(sc, dcb, srb)
938 1.6.2.2 thorpej struct trm_softc *sc;
939 1.6.2.2 thorpej struct trm_dcb *dcb;
940 1.6.2.2 thorpej struct trm_srb *srb;
941 1.6.2.2 thorpej {
942 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
943 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
944 1.6.2.2 thorpej int tagnum;
945 1.6.2.2 thorpej u_int32_t tagmask;
946 1.6.2.2 thorpej u_int8_t scsicmd, idmsg;
947 1.6.2.2 thorpej
948 1.6.2.2 thorpej srb->tagnum = 31;
949 1.6.2.2 thorpej
950 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_HOSTID, sc->sc_id);
951 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_TARGETID, dcb->id);
952 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_SYNC, dcb->synctl);
953 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_OFFSET, dcb->offset);
954 1.6.2.2 thorpej srb->phase = PH_BUS_FREE; /* initial phase */
955 1.6.2.2 thorpej /* Flush FIFO */
956 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_CLRFIFO);
957 1.6.2.2 thorpej
958 1.6.2.2 thorpej idmsg = dcb->idmsg;
959 1.6.2.2 thorpej
960 1.6.2.2 thorpej if ((srb->cmd[0] == INQUIRY) ||
961 1.6.2.2 thorpej (srb->cmd[0] == REQUEST_SENSE)) {
962 1.6.2.2 thorpej if (((dcb->mode & WIDE_NEGO_ENABLE) &&
963 1.6.2.2 thorpej (dcb->mode & WIDE_NEGO_DONE) == 0) ||
964 1.6.2.2 thorpej ((dcb->mode & SYNC_NEGO_ENABLE) &&
965 1.6.2.2 thorpej (dcb->mode & SYNC_NEGO_DONE) == 0)) {
966 1.6.2.2 thorpej if ((dcb->idmsg & 7) == 0 || srb->cmd[0] != INQUIRY) {
967 1.6.2.2 thorpej scsicmd = SCMD_SEL_ATNSTOP;
968 1.6.2.2 thorpej srb->state = SRB_MSGOUT;
969 1.6.2.2 thorpej goto polling;
970 1.6.2.2 thorpej }
971 1.6.2.2 thorpej }
972 1.6.2.2 thorpej /* Send identify message */
973 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
974 1.6.2.2 thorpej idmsg & ~MSG_IDENTIFY_DISCFLAG);
975 1.6.2.2 thorpej scsicmd = SCMD_SEL_ATN;
976 1.6.2.2 thorpej srb->state = SRB_START_;
977 1.6.2.2 thorpej } else { /* not inquiry,request sense,auto request sense */
978 1.6.2.2 thorpej /* Send identify message */
979 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO, idmsg);
980 1.6.2.2 thorpej DELAY(30);
981 1.6.2.2 thorpej scsicmd = SCMD_SEL_ATN;
982 1.6.2.2 thorpej srb->state = SRB_START_;
983 1.6.2.2 thorpej if (dcb->mode & EN_TAG_QUEUING) {
984 1.6.2.2 thorpej /* Send Tag message, get tag id */
985 1.6.2.2 thorpej tagmask = 1;
986 1.6.2.2 thorpej tagnum = 0;
987 1.6.2.2 thorpej while (tagmask & dcb->tagmask) {
988 1.6.2.2 thorpej tagmask = tagmask << 1;
989 1.6.2.2 thorpej tagnum++;
990 1.6.2.2 thorpej }
991 1.6.2.2 thorpej /* Send Tag id */
992 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
993 1.6.2.2 thorpej MSG_SIMPLE_Q_TAG);
994 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO, tagnum);
995 1.6.2.2 thorpej
996 1.6.2.2 thorpej dcb->tagmask |= tagmask;
997 1.6.2.2 thorpej srb->tagnum = tagnum;
998 1.6.2.2 thorpej
999 1.6.2.2 thorpej scsicmd = SCMD_SEL_ATN3;
1000 1.6.2.2 thorpej srb->state = SRB_START_;
1001 1.6.2.2 thorpej }
1002 1.6.2.2 thorpej }
1003 1.6.2.2 thorpej polling:
1004 1.6.2.2 thorpej /*
1005 1.6.2.2 thorpej * Send CDB ..command block...
1006 1.6.2.2 thorpej */
1007 1.6.2.2 thorpej bus_space_write_multi_1(iot, ioh, TRM_SCSI_FIFO, srb->cmd, srb->cmdlen);
1008 1.6.2.2 thorpej
1009 1.6.2.2 thorpej if (bus_space_read_2(iot, ioh, TRM_SCSI_STATUS) & SCSIINTERRUPT) {
1010 1.6.2.2 thorpej /*
1011 1.6.2.2 thorpej * If trm_start_scsi return 1: current interrupt status
1012 1.6.2.2 thorpej * is interrupt disreenable. It's said that SCSI processor
1013 1.6.2.2 thorpej * has more one SRB need to do, SCSI processor has been
1014 1.6.2.2 thorpej * occupied by one SRB.
1015 1.6.2.2 thorpej */
1016 1.6.2.2 thorpej srb->state = SRB_READY;
1017 1.6.2.2 thorpej dcb->tagmask &= ~(1 << srb->tagnum);
1018 1.6.2.2 thorpej return (1);
1019 1.6.2.2 thorpej } else {
1020 1.6.2.2 thorpej /*
1021 1.6.2.2 thorpej * If trm_start_scsi return 0: current interrupt status
1022 1.6.2.2 thorpej * is interrupt enable. It's said that SCSI processor is
1023 1.6.2.2 thorpej * unoccupied.
1024 1.6.2.2 thorpej */
1025 1.6.2.2 thorpej srb->phase = PH_BUS_FREE; /* SCSI bus free Phase */
1026 1.6.2.2 thorpej sc->sc_actdcb = dcb;
1027 1.6.2.2 thorpej dcb->actsrb = srb;
1028 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
1029 1.6.2.2 thorpej DO_DATALATCH | DO_HWRESELECT);
1030 1.6.2.2 thorpej /* it's important for atn stop */
1031 1.6.2.2 thorpej /*
1032 1.6.2.2 thorpej * SCSI command
1033 1.6.2.2 thorpej */
1034 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, scsicmd);
1035 1.6.2.2 thorpej return (0);
1036 1.6.2.2 thorpej }
1037 1.6.2.2 thorpej }
1038 1.6.2.2 thorpej
1039 1.6.2.2 thorpej /*
1040 1.6.2.2 thorpej * Catch an interrupt from the adapter
1041 1.6.2.2 thorpej * Process pending device interrupts.
1042 1.6.2.2 thorpej */
1043 1.6.2.2 thorpej static int
1044 1.6.2.2 thorpej trm_intr(vsc)
1045 1.6.2.2 thorpej void *vsc;
1046 1.6.2.2 thorpej {
1047 1.6.2.2 thorpej bus_space_tag_t iot;
1048 1.6.2.2 thorpej bus_space_handle_t ioh;
1049 1.6.2.2 thorpej struct trm_softc *sc;
1050 1.6.2.2 thorpej struct trm_dcb *dcb;
1051 1.6.2.2 thorpej struct trm_srb *srb;
1052 1.6.2.2 thorpej void (*state_v) (struct trm_softc *, struct trm_srb *, int *);
1053 1.6.2.2 thorpej int phase, intstat, stat = 0;
1054 1.6.2.2 thorpej
1055 1.6.2.2 thorpej #ifdef TRM_DEBUG
1056 1.6.2.2 thorpej printf("trm_intr......\n");
1057 1.6.2.2 thorpej #endif
1058 1.6.2.2 thorpej sc = (struct trm_softc *)vsc;
1059 1.6.2.2 thorpej iot = sc->sc_iot;
1060 1.6.2.2 thorpej ioh = sc->sc_ioh;
1061 1.6.2.2 thorpej
1062 1.6.2.2 thorpej if (sc == NULL)
1063 1.6.2.2 thorpej return (0);
1064 1.6.2.2 thorpej
1065 1.6.2.2 thorpej stat = bus_space_read_2(iot, ioh, TRM_SCSI_STATUS);
1066 1.6.2.2 thorpej if ((stat & SCSIINTERRUPT) == 0)
1067 1.6.2.2 thorpej return (0);
1068 1.6.2.2 thorpej
1069 1.6.2.2 thorpej #ifdef TRM_DEBUG
1070 1.6.2.2 thorpej printf("stat=%2x,", stat);
1071 1.6.2.2 thorpej #endif
1072 1.6.2.2 thorpej intstat = bus_space_read_1(iot, ioh, TRM_SCSI_INTSTATUS);
1073 1.6.2.2 thorpej
1074 1.6.2.2 thorpej #ifdef TRM_DEBUG
1075 1.6.2.2 thorpej printf("intstat=%2x,", intstat);
1076 1.6.2.2 thorpej #endif
1077 1.6.2.2 thorpej if (intstat & (INT_SELTIMEOUT | INT_DISCONNECT)) {
1078 1.6.2.2 thorpej trm_disconnect(sc);
1079 1.6.2.2 thorpej return (1);
1080 1.6.2.2 thorpej }
1081 1.6.2.2 thorpej if (intstat & INT_RESELECTED) {
1082 1.6.2.2 thorpej trm_reselect(sc);
1083 1.6.2.2 thorpej return (1);
1084 1.6.2.2 thorpej }
1085 1.6.2.2 thorpej if (intstat & INT_SCSIRESET) {
1086 1.6.2.2 thorpej trm_scsi_reset_detect(sc);
1087 1.6.2.2 thorpej return (1);
1088 1.6.2.2 thorpej }
1089 1.6.2.2 thorpej if (intstat & (INT_BUSSERVICE | INT_CMDDONE)) {
1090 1.6.2.2 thorpej dcb = sc->sc_actdcb;
1091 1.6.2.2 thorpej srb = dcb->actsrb;
1092 1.6.2.2 thorpej if (dcb != NULL)
1093 1.6.2.2 thorpej if (dcb->flag & ABORT_DEV_) {
1094 1.6.2.2 thorpej srb->msgout[0] = MSG_ABORT;
1095 1.6.2.2 thorpej trm_msgout_abort(sc, srb);
1096 1.6.2.2 thorpej }
1097 1.6.2.2 thorpej /*
1098 1.6.2.2 thorpej * software sequential machine
1099 1.6.2.2 thorpej */
1100 1.6.2.2 thorpej phase = srb->phase; /* phase: */
1101 1.6.2.2 thorpej
1102 1.6.2.2 thorpej /*
1103 1.6.2.2 thorpej * 62037 or 62137 call trm_scsi_phase0[]... "phase
1104 1.6.2.2 thorpej * entry" handle every phase before start transfer
1105 1.6.2.2 thorpej */
1106 1.6.2.2 thorpej state_v = (void *)trm_scsi_phase0[phase];
1107 1.6.2.2 thorpej state_v(sc, srb, &stat);
1108 1.6.2.2 thorpej
1109 1.6.2.2 thorpej /*
1110 1.6.2.2 thorpej * if there were any exception occured
1111 1.6.2.2 thorpej * stat will be modify to bus free phase new
1112 1.6.2.2 thorpej * stat transfer out from ... prvious state_v
1113 1.6.2.2 thorpej *
1114 1.6.2.2 thorpej */
1115 1.6.2.2 thorpej /* phase:0,1,2,3,4,5,6,7 */
1116 1.6.2.2 thorpej srb->phase = stat & PHASEMASK;
1117 1.6.2.2 thorpej phase = stat & PHASEMASK;
1118 1.6.2.2 thorpej
1119 1.6.2.2 thorpej /*
1120 1.6.2.2 thorpej * call trm_scsi_phase1[]... "phase entry" handle every
1121 1.6.2.2 thorpej * phase do transfer
1122 1.6.2.2 thorpej */
1123 1.6.2.2 thorpej state_v = (void *)trm_scsi_phase1[phase];
1124 1.6.2.2 thorpej state_v(sc, srb, &stat);
1125 1.6.2.2 thorpej return (1);
1126 1.6.2.2 thorpej }
1127 1.6.2.2 thorpej return (0);
1128 1.6.2.2 thorpej }
1129 1.6.2.2 thorpej
1130 1.6.2.2 thorpej static void
1131 1.6.2.2 thorpej trm_msgout_phase0(sc, srb, pstat)
1132 1.6.2.2 thorpej struct trm_softc *sc;
1133 1.6.2.2 thorpej struct trm_srb *srb;
1134 1.6.2.2 thorpej int *pstat;
1135 1.6.2.2 thorpej {
1136 1.6.2.2 thorpej
1137 1.6.2.2 thorpej if (srb->state & (SRB_UNEXPECT_RESEL | SRB_ABORT_SENT))
1138 1.6.2.2 thorpej *pstat = PH_BUS_FREE; /* .. initial phase */
1139 1.6.2.2 thorpej }
1140 1.6.2.2 thorpej
1141 1.6.2.2 thorpej static void
1142 1.6.2.2 thorpej trm_msgout_phase1(sc, srb, pstat)
1143 1.6.2.2 thorpej struct trm_softc *sc;
1144 1.6.2.2 thorpej struct trm_srb *srb;
1145 1.6.2.2 thorpej int *pstat;
1146 1.6.2.2 thorpej {
1147 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1148 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1149 1.6.2.2 thorpej struct trm_dcb *dcb;
1150 1.6.2.2 thorpej
1151 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_CLRFIFO);
1152 1.6.2.2 thorpej dcb = sc->sc_actdcb;
1153 1.6.2.2 thorpej if ((srb->state & SRB_MSGOUT) == 0) {
1154 1.6.2.2 thorpej if (srb->msgcnt > 0) {
1155 1.6.2.2 thorpej bus_space_write_multi_1(iot, ioh, TRM_SCSI_FIFO,
1156 1.6.2.2 thorpej srb->msgout, srb->msgcnt);
1157 1.6.2.2 thorpej srb->msgcnt = 0;
1158 1.6.2.2 thorpej if ((dcb->flag & ABORT_DEV_) &&
1159 1.6.2.2 thorpej (srb->msgout[0] == MSG_ABORT))
1160 1.6.2.2 thorpej srb->state = SRB_ABORT_SENT;
1161 1.6.2.2 thorpej } else {
1162 1.6.2.2 thorpej if ((srb->cmd[0] == INQUIRY) ||
1163 1.6.2.2 thorpej (srb->cmd[0] == REQUEST_SENSE))
1164 1.6.2.2 thorpej if (dcb->mode & SYNC_NEGO_ENABLE)
1165 1.6.2.2 thorpej goto mop1;
1166 1.6.2.2 thorpej
1167 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO, MSG_ABORT);
1168 1.6.2.2 thorpej }
1169 1.6.2.2 thorpej } else {
1170 1.6.2.2 thorpej mop1: /* message out phase */
1171 1.6.2.2 thorpej if ((srb->state & SRB_DO_WIDE_NEGO) == 0 &&
1172 1.6.2.2 thorpej (dcb->mode & WIDE_NEGO_ENABLE)) {
1173 1.6.2.2 thorpej /*
1174 1.6.2.2 thorpej * WIDE DATA TRANSFER REQUEST code (03h)
1175 1.6.2.2 thorpej */
1176 1.6.2.2 thorpej dcb->mode &= ~(SYNC_NEGO_DONE | EN_ATN_STOP);
1177 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1178 1.6.2.2 thorpej dcb->idmsg & ~MSG_IDENTIFY_DISCFLAG);
1179 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1180 1.6.2.2 thorpej MSG_EXTENDED); /* (01h) */
1181 1.6.2.2 thorpej
1182 1.6.2.2 thorpej /* Message length (02h) */
1183 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1184 1.6.2.2 thorpej MSG_EXT_WDTR_LEN);
1185 1.6.2.2 thorpej
1186 1.6.2.2 thorpej /* wide data xfer (03h) */
1187 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1188 1.6.2.2 thorpej MSG_EXT_WDTR);
1189 1.6.2.2 thorpej
1190 1.6.2.2 thorpej /* width: 0(8bit), 1(16bit) ,2(32bit) */
1191 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1192 1.6.2.2 thorpej MSG_EXT_WDTR_BUS_16_BIT);
1193 1.6.2.2 thorpej
1194 1.6.2.2 thorpej srb->state |= SRB_DO_WIDE_NEGO;
1195 1.6.2.2 thorpej } else if ((srb->state & SRB_DO_SYNC_NEGO) == 0 &&
1196 1.6.2.2 thorpej (dcb->mode & SYNC_NEGO_ENABLE)) {
1197 1.6.2.2 thorpej /*
1198 1.6.2.2 thorpej * SYNCHRONOUS DATA TRANSFER REQUEST code (01h)
1199 1.6.2.2 thorpej */
1200 1.6.2.2 thorpej if ((dcb->mode & WIDE_NEGO_DONE) == 0)
1201 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1202 1.6.2.2 thorpej dcb->idmsg & ~MSG_IDENTIFY_DISCFLAG);
1203 1.6.2.2 thorpej
1204 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1205 1.6.2.2 thorpej MSG_EXTENDED); /* (01h) */
1206 1.6.2.2 thorpej
1207 1.6.2.2 thorpej /* Message length (03h) */
1208 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1209 1.6.2.2 thorpej MSG_EXT_SDTR_LEN);
1210 1.6.2.2 thorpej
1211 1.6.2.2 thorpej /* SYNCHRONOUS DATA TRANSFER REQUEST code (01h) */
1212 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1213 1.6.2.2 thorpej MSG_EXT_SDTR);
1214 1.6.2.2 thorpej
1215 1.6.2.2 thorpej /* Transfer peeriod factor */
1216 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO, dcb->period);
1217 1.6.2.2 thorpej
1218 1.6.2.2 thorpej /* REQ/ACK offset */
1219 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_FIFO,
1220 1.6.2.2 thorpej SYNC_NEGO_OFFSET);
1221 1.6.2.2 thorpej srb->state |= SRB_DO_SYNC_NEGO;
1222 1.6.2.2 thorpej }
1223 1.6.2.2 thorpej }
1224 1.6.2.2 thorpej /* it's important for atn stop */
1225 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_DATALATCH);
1226 1.6.2.2 thorpej
1227 1.6.2.2 thorpej /*
1228 1.6.2.2 thorpej * SCSI cammand
1229 1.6.2.2 thorpej */
1230 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, SCMD_FIFO_OUT);
1231 1.6.2.2 thorpej }
1232 1.6.2.2 thorpej
1233 1.6.2.2 thorpej static void
1234 1.6.2.2 thorpej trm_command_phase0(sc, srb, pstat)
1235 1.6.2.2 thorpej struct trm_softc *sc;
1236 1.6.2.2 thorpej struct trm_srb *srb;
1237 1.6.2.2 thorpej int *pstat;
1238 1.6.2.2 thorpej {
1239 1.6.2.2 thorpej
1240 1.6.2.2 thorpej }
1241 1.6.2.2 thorpej
1242 1.6.2.2 thorpej static void
1243 1.6.2.2 thorpej trm_command_phase1(sc, srb, pstat)
1244 1.6.2.2 thorpej struct trm_softc *sc;
1245 1.6.2.2 thorpej struct trm_srb *srb;
1246 1.6.2.2 thorpej int *pstat;
1247 1.6.2.2 thorpej {
1248 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1249 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1250 1.6.2.2 thorpej
1251 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_CLRATN | DO_CLRFIFO);
1252 1.6.2.2 thorpej bus_space_write_multi_1(iot, ioh, TRM_SCSI_FIFO, srb->cmd, srb->cmdlen);
1253 1.6.2.2 thorpej
1254 1.6.2.2 thorpej srb->state = SRB_COMMAND;
1255 1.6.2.2 thorpej /* it's important for atn stop */
1256 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_DATALATCH);
1257 1.6.2.2 thorpej
1258 1.6.2.2 thorpej /*
1259 1.6.2.2 thorpej * SCSI cammand
1260 1.6.2.2 thorpej */
1261 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, SCMD_FIFO_OUT);
1262 1.6.2.2 thorpej }
1263 1.6.2.2 thorpej
1264 1.6.2.2 thorpej static void
1265 1.6.2.2 thorpej trm_dataout_phase0(sc, srb, pstat)
1266 1.6.2.2 thorpej struct trm_softc *sc;
1267 1.6.2.2 thorpej struct trm_srb *srb;
1268 1.6.2.2 thorpej int *pstat;
1269 1.6.2.2 thorpej {
1270 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1271 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1272 1.6.2.2 thorpej struct trm_dcb *dcb;
1273 1.6.2.2 thorpej struct trm_sg_entry *sg;
1274 1.6.2.2 thorpej int sgindex;
1275 1.6.2.2 thorpej u_int32_t xferlen, leftcnt = 0;
1276 1.6.2.2 thorpej
1277 1.6.2.2 thorpej dcb = srb->dcb;
1278 1.6.2.2 thorpej
1279 1.6.2.2 thorpej if ((srb->state & SRB_XFERPAD) == 0) {
1280 1.6.2.2 thorpej if (*pstat & PARITYERROR)
1281 1.6.2.2 thorpej srb->srbstat |= PARITY_ERROR;
1282 1.6.2.2 thorpej
1283 1.6.2.2 thorpej if ((*pstat & SCSIXFERDONE) == 0) {
1284 1.6.2.2 thorpej /*
1285 1.6.2.2 thorpej * when data transfer from DMA FIFO to SCSI FIFO
1286 1.6.2.2 thorpej * if there was some data left in SCSI FIFO
1287 1.6.2.2 thorpej */
1288 1.6.2.2 thorpej leftcnt = bus_space_read_1(iot, ioh, TRM_SCSI_FIFOCNT) &
1289 1.6.2.2 thorpej SCSI_FIFOCNT_MASK;
1290 1.6.2.2 thorpej if (dcb->synctl & WIDE_SYNC)
1291 1.6.2.2 thorpej /*
1292 1.6.2.2 thorpej * if WIDE scsi SCSI FIFOCNT unit is word
1293 1.6.2.2 thorpej * so need to * 2
1294 1.6.2.2 thorpej */
1295 1.6.2.2 thorpej leftcnt <<= 1;
1296 1.6.2.2 thorpej }
1297 1.6.2.2 thorpej /*
1298 1.6.2.2 thorpej * caculate all the residue data that not yet tranfered
1299 1.6.2.2 thorpej * SCSI transfer counter + left in SCSI FIFO data
1300 1.6.2.2 thorpej *
1301 1.6.2.2 thorpej * .....TRM_SCSI_XCNT (24bits)
1302 1.6.2.2 thorpej * The counter always decrement by one for every SCSI
1303 1.6.2.2 thorpej * byte transfer.
1304 1.6.2.2 thorpej * .....TRM_SCSI_FIFOCNT ( 5bits)
1305 1.6.2.2 thorpej * The counter is SCSI FIFO offset counter
1306 1.6.2.2 thorpej */
1307 1.6.2.2 thorpej leftcnt += bus_space_read_4(iot, ioh, TRM_SCSI_XCNT);
1308 1.6.2.2 thorpej if (leftcnt == 1) {
1309 1.6.2.2 thorpej leftcnt = 0;
1310 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
1311 1.6.2.2 thorpej DO_CLRFIFO);
1312 1.6.2.2 thorpej }
1313 1.6.2.2 thorpej if ((leftcnt == 0) || (*pstat & SCSIXFERCNT_2_ZERO)) {
1314 1.6.2.2 thorpej while ((bus_space_read_1(iot, ioh, TRM_DMA_STATUS) &
1315 1.6.2.2 thorpej DMAXFERCOMP) == 0)
1316 1.6.2.2 thorpej ;
1317 1.6.2.2 thorpej
1318 1.6.2.2 thorpej srb->buflen = 0;
1319 1.6.2.2 thorpej } else { /* Update SG list */
1320 1.6.2.2 thorpej /*
1321 1.6.2.2 thorpej * if transfer not yet complete
1322 1.6.2.2 thorpej * there were some data residue in SCSI FIFO or
1323 1.6.2.2 thorpej * SCSI transfer counter not empty
1324 1.6.2.2 thorpej */
1325 1.6.2.2 thorpej if (srb->buflen != leftcnt) {
1326 1.6.2.2 thorpej /* data that had transferred length */
1327 1.6.2.2 thorpej xferlen = srb->buflen - leftcnt;
1328 1.6.2.2 thorpej
1329 1.6.2.2 thorpej /* next time to be transferred length */
1330 1.6.2.2 thorpej srb->buflen = leftcnt;
1331 1.6.2.2 thorpej
1332 1.6.2.2 thorpej /*
1333 1.6.2.2 thorpej * parsing from last time disconnect sgindex
1334 1.6.2.2 thorpej */
1335 1.6.2.2 thorpej sg = srb->sgentry + srb->sgindex;
1336 1.6.2.2 thorpej for (sgindex = srb->sgindex;
1337 1.6.2.2 thorpej sgindex < srb->sgcnt;
1338 1.6.2.2 thorpej sgindex++, sg++) {
1339 1.6.2.2 thorpej /*
1340 1.6.2.2 thorpej * find last time which SG transfer
1341 1.6.2.2 thorpej * be disconnect
1342 1.6.2.2 thorpej */
1343 1.6.2.2 thorpej if (xferlen >= le32toh(sg->length))
1344 1.6.2.2 thorpej xferlen -= le32toh(sg->length);
1345 1.6.2.2 thorpej else {
1346 1.6.2.2 thorpej /*
1347 1.6.2.2 thorpej * update last time
1348 1.6.2.2 thorpej * disconnected SG list
1349 1.6.2.2 thorpej */
1350 1.6.2.2 thorpej /* residue data length */
1351 1.6.2.2 thorpej sg->length = htole32(
1352 1.6.2.2 thorpej le32toh(sg->length)
1353 1.6.2.2 thorpej - xferlen);
1354 1.6.2.2 thorpej /* residue data pointer */
1355 1.6.2.2 thorpej sg->address = htole32(
1356 1.6.2.2 thorpej le32toh(sg->address)
1357 1.6.2.2 thorpej + xferlen);
1358 1.6.2.2 thorpej srb->sgindex = sgindex;
1359 1.6.2.2 thorpej break;
1360 1.6.2.2 thorpej }
1361 1.6.2.2 thorpej }
1362 1.6.2.2 thorpej bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1363 1.6.2.2 thorpej srb->sgoffset, TRM_SG_SIZE,
1364 1.6.2.2 thorpej BUS_DMASYNC_PREWRITE);
1365 1.6.2.2 thorpej }
1366 1.6.2.2 thorpej }
1367 1.6.2.2 thorpej }
1368 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_CONTROL, STOPDMAXFER);
1369 1.6.2.2 thorpej }
1370 1.6.2.2 thorpej
1371 1.6.2.2 thorpej static void
1372 1.6.2.2 thorpej trm_dataout_phase1(sc, srb, pstat)
1373 1.6.2.2 thorpej struct trm_softc *sc;
1374 1.6.2.2 thorpej struct trm_srb *srb;
1375 1.6.2.2 thorpej int *pstat;
1376 1.6.2.2 thorpej {
1377 1.6.2.2 thorpej
1378 1.6.2.2 thorpej /*
1379 1.6.2.2 thorpej * do prepare befor transfer when data out phase
1380 1.6.2.2 thorpej */
1381 1.6.2.2 thorpej trm_dataio_xfer(sc, srb, XFERDATAOUT);
1382 1.6.2.2 thorpej }
1383 1.6.2.2 thorpej
1384 1.6.2.2 thorpej static void
1385 1.6.2.2 thorpej trm_datain_phase0(sc, srb, pstat)
1386 1.6.2.2 thorpej struct trm_softc *sc;
1387 1.6.2.2 thorpej struct trm_srb *srb;
1388 1.6.2.2 thorpej int *pstat;
1389 1.6.2.2 thorpej {
1390 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1391 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1392 1.6.2.2 thorpej struct trm_sg_entry *sg;
1393 1.6.2.2 thorpej int sgindex;
1394 1.6.2.2 thorpej u_int32_t xferlen, leftcnt = 0;
1395 1.6.2.2 thorpej
1396 1.6.2.2 thorpej if ((srb->state & SRB_XFERPAD) == 0) {
1397 1.6.2.2 thorpej if (*pstat & PARITYERROR)
1398 1.6.2.2 thorpej srb->srbstat |= PARITY_ERROR;
1399 1.6.2.2 thorpej
1400 1.6.2.2 thorpej leftcnt += bus_space_read_4(iot, ioh, TRM_SCSI_XCNT);
1401 1.6.2.2 thorpej if ((leftcnt == 0) || (*pstat & SCSIXFERCNT_2_ZERO)) {
1402 1.6.2.2 thorpej while ((bus_space_read_1(iot, ioh, TRM_DMA_STATUS) &
1403 1.6.2.2 thorpej DMAXFERCOMP) == 0)
1404 1.6.2.2 thorpej ;
1405 1.6.2.2 thorpej
1406 1.6.2.2 thorpej srb->buflen = 0;
1407 1.6.2.2 thorpej } else { /* phase changed */
1408 1.6.2.2 thorpej /*
1409 1.6.2.2 thorpej * parsing the case:
1410 1.6.2.2 thorpej * when a transfer not yet complete
1411 1.6.2.2 thorpej * but be disconnected by uper layer
1412 1.6.2.2 thorpej * if transfer not yet complete
1413 1.6.2.2 thorpej * there were some data residue in SCSI FIFO or
1414 1.6.2.2 thorpej * SCSI transfer counter not empty
1415 1.6.2.2 thorpej */
1416 1.6.2.2 thorpej if (srb->buflen != leftcnt) {
1417 1.6.2.2 thorpej /*
1418 1.6.2.2 thorpej * data that had transferred length
1419 1.6.2.2 thorpej */
1420 1.6.2.2 thorpej xferlen = srb->buflen - leftcnt;
1421 1.6.2.2 thorpej
1422 1.6.2.2 thorpej /*
1423 1.6.2.2 thorpej * next time to be transferred length
1424 1.6.2.2 thorpej */
1425 1.6.2.2 thorpej srb->buflen = leftcnt;
1426 1.6.2.2 thorpej
1427 1.6.2.2 thorpej /*
1428 1.6.2.2 thorpej * parsing from last time disconnect sgindex
1429 1.6.2.2 thorpej */
1430 1.6.2.2 thorpej sg = srb->sgentry + srb->sgindex;
1431 1.6.2.2 thorpej for (sgindex = srb->sgindex;
1432 1.6.2.2 thorpej sgindex < srb->sgcnt;
1433 1.6.2.2 thorpej sgindex++, sg++) {
1434 1.6.2.2 thorpej /*
1435 1.6.2.2 thorpej * find last time which SG transfer
1436 1.6.2.2 thorpej * be disconnect
1437 1.6.2.2 thorpej */
1438 1.6.2.2 thorpej if (xferlen >= le32toh(sg->length))
1439 1.6.2.2 thorpej xferlen -= le32toh(sg->length);
1440 1.6.2.2 thorpej else {
1441 1.6.2.2 thorpej /*
1442 1.6.2.2 thorpej * update last time
1443 1.6.2.2 thorpej * disconnected SG list
1444 1.6.2.2 thorpej */
1445 1.6.2.2 thorpej /* residue data length */
1446 1.6.2.2 thorpej sg->length = htole32(
1447 1.6.2.2 thorpej le32toh(sg->length)
1448 1.6.2.2 thorpej - xferlen);
1449 1.6.2.2 thorpej /* residue data pointer */
1450 1.6.2.2 thorpej sg->address = htole32(
1451 1.6.2.2 thorpej le32toh(sg->address)
1452 1.6.2.2 thorpej + xferlen);
1453 1.6.2.2 thorpej srb->sgindex = sgindex;
1454 1.6.2.2 thorpej break;
1455 1.6.2.2 thorpej }
1456 1.6.2.2 thorpej }
1457 1.6.2.2 thorpej bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
1458 1.6.2.2 thorpej srb->sgoffset, TRM_SG_SIZE,
1459 1.6.2.2 thorpej BUS_DMASYNC_PREWRITE);
1460 1.6.2.2 thorpej }
1461 1.6.2.2 thorpej }
1462 1.6.2.2 thorpej }
1463 1.6.2.2 thorpej }
1464 1.6.2.2 thorpej
1465 1.6.2.2 thorpej static void
1466 1.6.2.2 thorpej trm_datain_phase1(sc, srb, pstat)
1467 1.6.2.2 thorpej struct trm_softc *sc;
1468 1.6.2.2 thorpej struct trm_srb *srb;
1469 1.6.2.2 thorpej int *pstat;
1470 1.6.2.2 thorpej {
1471 1.6.2.2 thorpej
1472 1.6.2.2 thorpej /*
1473 1.6.2.2 thorpej * do prepare befor transfer when data in phase
1474 1.6.2.2 thorpej */
1475 1.6.2.2 thorpej trm_dataio_xfer(sc, srb, XFERDATAIN);
1476 1.6.2.2 thorpej }
1477 1.6.2.2 thorpej
1478 1.6.2.2 thorpej static void
1479 1.6.2.2 thorpej trm_dataio_xfer(sc, srb, iodir)
1480 1.6.2.2 thorpej struct trm_softc *sc;
1481 1.6.2.2 thorpej struct trm_srb *srb;
1482 1.6.2.2 thorpej int iodir;
1483 1.6.2.2 thorpej {
1484 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1485 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1486 1.6.2.2 thorpej struct trm_dcb *dcb = srb->dcb;
1487 1.6.2.2 thorpej
1488 1.6.2.2 thorpej if (srb->sgindex < srb->sgcnt) {
1489 1.6.2.2 thorpej if (srb->buflen > 0) {
1490 1.6.2.2 thorpej /*
1491 1.6.2.2 thorpej * load what physical address of Scatter/Gather
1492 1.6.2.2 thorpej * list table want to be transfer
1493 1.6.2.2 thorpej */
1494 1.6.2.2 thorpej srb->state = SRB_DATA_XFER;
1495 1.6.2.2 thorpej bus_space_write_4(iot, ioh, TRM_DMA_XHIGHADDR, 0);
1496 1.6.2.2 thorpej bus_space_write_4(iot, ioh, TRM_DMA_XLOWADDR,
1497 1.6.2.2 thorpej srb->sgaddr +
1498 1.6.2.2 thorpej srb->sgindex * sizeof(struct trm_sg_entry));
1499 1.6.2.2 thorpej /*
1500 1.6.2.2 thorpej * load how many bytes in the Scatter/Gather list table
1501 1.6.2.2 thorpej */
1502 1.6.2.2 thorpej bus_space_write_4(iot, ioh, TRM_DMA_XCNT,
1503 1.6.2.2 thorpej (srb->sgcnt - srb->sgindex)
1504 1.6.2.2 thorpej * sizeof(struct trm_sg_entry));
1505 1.6.2.2 thorpej /*
1506 1.6.2.2 thorpej * load total xfer length (24bits) max value 16Mbyte
1507 1.6.2.2 thorpej */
1508 1.6.2.2 thorpej bus_space_write_4(iot, ioh, TRM_SCSI_XCNT, srb->buflen);
1509 1.6.2.2 thorpej /* Start DMA transfer */
1510 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_COMMAND,
1511 1.6.2.2 thorpej iodir | SGXFER);
1512 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_CONTROL,
1513 1.6.2.2 thorpej STARTDMAXFER);
1514 1.6.2.2 thorpej
1515 1.6.2.2 thorpej /* Start SCSI transfer */
1516 1.6.2.2 thorpej /* it's important for atn stop */
1517 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
1518 1.6.2.2 thorpej DO_DATALATCH);
1519 1.6.2.2 thorpej
1520 1.6.2.2 thorpej /*
1521 1.6.2.2 thorpej * SCSI cammand
1522 1.6.2.2 thorpej */
1523 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND,
1524 1.6.2.2 thorpej (iodir == XFERDATAOUT) ?
1525 1.6.2.2 thorpej SCMD_DMA_OUT : SCMD_DMA_IN);
1526 1.6.2.2 thorpej } else { /* xfer pad */
1527 1.6.2.2 thorpej if (srb->sgcnt) {
1528 1.6.2.2 thorpej srb->hastat = H_OVER_UNDER_RUN;
1529 1.6.2.2 thorpej srb->srbstat |= OVER_RUN;
1530 1.6.2.2 thorpej }
1531 1.6.2.2 thorpej bus_space_write_4(iot, ioh, TRM_SCSI_XCNT,
1532 1.6.2.2 thorpej (dcb->synctl & WIDE_SYNC) ? 2 : 1);
1533 1.6.2.2 thorpej
1534 1.6.2.2 thorpej if (iodir == XFERDATAOUT)
1535 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_FIFO, 0);
1536 1.6.2.2 thorpej else
1537 1.6.2.2 thorpej bus_space_read_2(iot, ioh, TRM_SCSI_FIFO);
1538 1.6.2.2 thorpej
1539 1.6.2.2 thorpej srb->state |= SRB_XFERPAD;
1540 1.6.2.2 thorpej /* it's important for atn stop */
1541 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
1542 1.6.2.2 thorpej DO_DATALATCH);
1543 1.6.2.2 thorpej
1544 1.6.2.2 thorpej /*
1545 1.6.2.2 thorpej * SCSI cammand
1546 1.6.2.2 thorpej */
1547 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND,
1548 1.6.2.2 thorpej (iodir == XFERDATAOUT) ?
1549 1.6.2.2 thorpej SCMD_FIFO_OUT : SCMD_FIFO_IN);
1550 1.6.2.2 thorpej }
1551 1.6.2.2 thorpej }
1552 1.6.2.2 thorpej }
1553 1.6.2.2 thorpej
1554 1.6.2.2 thorpej static void
1555 1.6.2.2 thorpej trm_status_phase0(sc, srb, pstat)
1556 1.6.2.2 thorpej struct trm_softc *sc;
1557 1.6.2.2 thorpej struct trm_srb *srb;
1558 1.6.2.2 thorpej int *pstat;
1559 1.6.2.2 thorpej {
1560 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1561 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1562 1.6.2.2 thorpej
1563 1.6.2.2 thorpej srb->tastat = bus_space_read_1(iot, ioh, TRM_SCSI_FIFO);
1564 1.6.2.2 thorpej srb->state = SRB_COMPLETED;
1565 1.6.2.2 thorpej *pstat = PH_BUS_FREE; /* .. initial phase */
1566 1.6.2.2 thorpej /* it's important for atn stop */
1567 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_DATALATCH);
1568 1.6.2.2 thorpej
1569 1.6.2.2 thorpej /*
1570 1.6.2.2 thorpej * SCSI cammand
1571 1.6.2.2 thorpej */
1572 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, SCMD_MSGACCEPT);
1573 1.6.2.2 thorpej }
1574 1.6.2.2 thorpej
1575 1.6.2.2 thorpej static void
1576 1.6.2.2 thorpej trm_status_phase1(sc, srb, pstat)
1577 1.6.2.2 thorpej struct trm_softc *sc;
1578 1.6.2.2 thorpej struct trm_srb *srb;
1579 1.6.2.2 thorpej int *pstat;
1580 1.6.2.2 thorpej {
1581 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1582 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1583 1.6.2.2 thorpej
1584 1.6.2.2 thorpej if (bus_space_read_1(iot, ioh, TRM_DMA_COMMAND) & XFERDATAIN) {
1585 1.6.2.2 thorpej if ((bus_space_read_1(iot, ioh, TRM_SCSI_FIFOCNT)
1586 1.6.2.2 thorpej & SCSI_FIFO_EMPTY) == 0)
1587 1.6.2.2 thorpej bus_space_write_2(iot, ioh,
1588 1.6.2.2 thorpej TRM_SCSI_CONTROL, DO_CLRFIFO);
1589 1.6.2.2 thorpej if ((bus_space_read_1(iot, ioh, TRM_DMA_FIFOSTATUS)
1590 1.6.2.2 thorpej & DMA_FIFO_EMPTY) == 0)
1591 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_CONTROL, CLRXFIFO);
1592 1.6.2.2 thorpej } else {
1593 1.6.2.2 thorpej if ((bus_space_read_1(iot, ioh, TRM_DMA_FIFOSTATUS)
1594 1.6.2.2 thorpej & DMA_FIFO_EMPTY) == 0)
1595 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_CONTROL, CLRXFIFO);
1596 1.6.2.2 thorpej if ((bus_space_read_1(iot, ioh, TRM_SCSI_FIFOCNT)
1597 1.6.2.2 thorpej & SCSI_FIFO_EMPTY) == 0)
1598 1.6.2.2 thorpej bus_space_write_2(iot, ioh,
1599 1.6.2.2 thorpej TRM_SCSI_CONTROL, DO_CLRFIFO);
1600 1.6.2.2 thorpej }
1601 1.6.2.2 thorpej srb->state = SRB_STATUS;
1602 1.6.2.2 thorpej /* it's important for atn stop */
1603 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_DATALATCH);
1604 1.6.2.2 thorpej
1605 1.6.2.2 thorpej /*
1606 1.6.2.2 thorpej * SCSI cammand
1607 1.6.2.2 thorpej */
1608 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, SCMD_COMP);
1609 1.6.2.2 thorpej }
1610 1.6.2.2 thorpej
1611 1.6.2.2 thorpej static void
1612 1.6.2.2 thorpej trm_msgin_phase0(sc, srb, pstat)
1613 1.6.2.2 thorpej struct trm_softc *sc;
1614 1.6.2.2 thorpej struct trm_srb *srb;
1615 1.6.2.2 thorpej int *pstat;
1616 1.6.2.2 thorpej {
1617 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1618 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1619 1.6.2.2 thorpej struct trm_dcb *dcb = sc->sc_actdcb;
1620 1.6.2.2 thorpej struct trm_srb *tempsrb;
1621 1.6.2.2 thorpej int syncxfer, tagid, index;
1622 1.6.2.2 thorpej u_int8_t msgin_code;
1623 1.6.2.2 thorpej
1624 1.6.2.2 thorpej msgin_code = bus_space_read_1(iot, ioh, TRM_SCSI_FIFO);
1625 1.6.2.2 thorpej if ((srb->state & SRB_EXTEND_MSGIN) == 0) {
1626 1.6.2.2 thorpej if (msgin_code == MSG_DISCONNECT) {
1627 1.6.2.2 thorpej srb->state = SRB_DISCONNECT;
1628 1.6.2.2 thorpej goto min6;
1629 1.6.2.2 thorpej } else if (msgin_code == MSG_SAVEDATAPOINTER) {
1630 1.6.2.2 thorpej goto min6;
1631 1.6.2.2 thorpej } else if ((msgin_code == MSG_EXTENDED) ||
1632 1.6.2.2 thorpej ((msgin_code >= MSG_SIMPLE_Q_TAG) &&
1633 1.6.2.2 thorpej (msgin_code <= MSG_ORDERED_Q_TAG))) {
1634 1.6.2.2 thorpej srb->state |= SRB_EXTEND_MSGIN;
1635 1.6.2.2 thorpej /* extended message (01h) */
1636 1.6.2.2 thorpej srb->msgin[0] = msgin_code;
1637 1.6.2.2 thorpej
1638 1.6.2.2 thorpej srb->msgcnt = 1;
1639 1.6.2.2 thorpej /* extended message length (n) */
1640 1.6.2.2 thorpej srb->msg = &srb->msgin[1];
1641 1.6.2.2 thorpej
1642 1.6.2.2 thorpej goto min6;
1643 1.6.2.2 thorpej } else if (msgin_code == MSG_MESSAGE_REJECT) {
1644 1.6.2.2 thorpej /* Reject message */
1645 1.6.2.2 thorpej /* do wide nego reject */
1646 1.6.2.2 thorpej if (dcb->mode & WIDE_NEGO_ENABLE) {
1647 1.6.2.2 thorpej dcb = srb->dcb;
1648 1.6.2.2 thorpej dcb->mode |= WIDE_NEGO_DONE;
1649 1.6.2.2 thorpej dcb->mode &= ~(SYNC_NEGO_DONE | EN_ATN_STOP |
1650 1.6.2.2 thorpej WIDE_NEGO_ENABLE);
1651 1.6.2.2 thorpej srb->state &= ~(SRB_DO_WIDE_NEGO | SRB_MSGIN);
1652 1.6.2.2 thorpej if ((dcb->mode & SYNC_NEGO_ENABLE) &&
1653 1.6.2.2 thorpej (dcb->mode & SYNC_NEGO_DONE) == 0) {
1654 1.6.2.2 thorpej /* Set ATN, in case ATN was clear */
1655 1.6.2.2 thorpej srb->state |= SRB_MSGOUT;
1656 1.6.2.2 thorpej bus_space_write_2(iot, ioh,
1657 1.6.2.2 thorpej TRM_SCSI_CONTROL, DO_SETATN);
1658 1.6.2.2 thorpej } else
1659 1.6.2.2 thorpej /* Clear ATN */
1660 1.6.2.2 thorpej bus_space_write_2(iot, ioh,
1661 1.6.2.2 thorpej TRM_SCSI_CONTROL, DO_CLRATN);
1662 1.6.2.2 thorpej } else if (dcb->mode & SYNC_NEGO_ENABLE) {
1663 1.6.2.2 thorpej /* do sync nego reject */
1664 1.6.2.2 thorpej bus_space_write_2(iot, ioh,
1665 1.6.2.2 thorpej TRM_SCSI_CONTROL, DO_CLRATN);
1666 1.6.2.2 thorpej if (srb->state & SRB_DO_SYNC_NEGO) {
1667 1.6.2.2 thorpej dcb = srb->dcb;
1668 1.6.2.2 thorpej dcb->mode &= ~(SYNC_NEGO_ENABLE |
1669 1.6.2.2 thorpej SYNC_NEGO_DONE);
1670 1.6.2.2 thorpej dcb->synctl = 0;
1671 1.6.2.2 thorpej dcb->offset = 0;
1672 1.6.2.2 thorpej goto re_prog;
1673 1.6.2.2 thorpej }
1674 1.6.2.2 thorpej }
1675 1.6.2.2 thorpej goto min6;
1676 1.6.2.2 thorpej } else if (msgin_code == MSG_IGN_WIDE_RESIDUE) {
1677 1.6.2.2 thorpej bus_space_write_4(iot, ioh, TRM_SCSI_XCNT, 1);
1678 1.6.2.2 thorpej bus_space_read_1(iot, ioh, TRM_SCSI_FIFO);
1679 1.6.2.2 thorpej goto min6;
1680 1.6.2.2 thorpej } else {
1681 1.6.2.2 thorpej /*
1682 1.6.2.2 thorpej * Restore data pointer message
1683 1.6.2.2 thorpej * Save data pointer message
1684 1.6.2.2 thorpej * Completion message
1685 1.6.2.2 thorpej * NOP message
1686 1.6.2.2 thorpej */
1687 1.6.2.2 thorpej goto min6;
1688 1.6.2.2 thorpej }
1689 1.6.2.2 thorpej } else {
1690 1.6.2.2 thorpej /*
1691 1.6.2.2 thorpej * when extend message in:srb->state = SRB_EXTEND_MSGIN
1692 1.6.2.2 thorpej * Parsing incomming extented messages
1693 1.6.2.2 thorpej */
1694 1.6.2.2 thorpej *srb->msg = msgin_code;
1695 1.6.2.2 thorpej srb->msgcnt++;
1696 1.6.2.2 thorpej srb->msg++;
1697 1.6.2.2 thorpej #ifdef TRM_DEBUG
1698 1.6.2.2 thorpej printf("srb->msgin[0]=%2x\n", srb->msgin[0]);
1699 1.6.2.2 thorpej printf("srb->msgin[1]=%2x\n", srb->msgin[1]);
1700 1.6.2.2 thorpej printf("srb->msgin[2]=%2x\n", srb->msgin[2]);
1701 1.6.2.2 thorpej printf("srb->msgin[3]=%2x\n", srb->msgin[3]);
1702 1.6.2.2 thorpej printf("srb->msgin[4]=%2x\n", srb->msgin[4]);
1703 1.6.2.2 thorpej #endif
1704 1.6.2.2 thorpej if ((srb->msgin[0] >= MSG_SIMPLE_Q_TAG) &&
1705 1.6.2.2 thorpej (srb->msgin[0] <= MSG_ORDERED_Q_TAG)) {
1706 1.6.2.2 thorpej /*
1707 1.6.2.2 thorpej * is QUEUE tag message :
1708 1.6.2.2 thorpej *
1709 1.6.2.2 thorpej * byte 0:
1710 1.6.2.2 thorpej * HEAD QUEUE TAG (20h)
1711 1.6.2.2 thorpej * ORDERED QUEUE TAG (21h)
1712 1.6.2.2 thorpej * SIMPLE QUEUE TAG (22h)
1713 1.6.2.2 thorpej * byte 1:
1714 1.6.2.2 thorpej * Queue tag (00h - FFh)
1715 1.6.2.2 thorpej */
1716 1.6.2.2 thorpej if (srb->msgcnt == 2) {
1717 1.6.2.2 thorpej srb->state = 0;
1718 1.6.2.2 thorpej tagid = srb->msgin[1];
1719 1.6.2.2 thorpej srb = dcb->gosrb;
1720 1.6.2.2 thorpej tempsrb = dcb->last_gosrb;
1721 1.6.2.2 thorpej if (srb) {
1722 1.6.2.2 thorpej for (;;) {
1723 1.6.2.2 thorpej if (srb->tagnum != tagid) {
1724 1.6.2.2 thorpej if (srb == tempsrb)
1725 1.6.2.2 thorpej goto mingx0;
1726 1.6.2.2 thorpej
1727 1.6.2.2 thorpej srb = srb->next;
1728 1.6.2.2 thorpej } else
1729 1.6.2.2 thorpej break;
1730 1.6.2.2 thorpej }
1731 1.6.2.2 thorpej if (dcb->flag & ABORT_DEV_) {
1732 1.6.2.2 thorpej srb->state = SRB_ABORT_SENT;
1733 1.6.2.2 thorpej srb->msgout[0] = MSG_ABORT;
1734 1.6.2.2 thorpej trm_msgout_abort(sc, srb);
1735 1.6.2.2 thorpej }
1736 1.6.2.2 thorpej if ((srb->state & SRB_DISCONNECT) == 0)
1737 1.6.2.2 thorpej goto mingx0;
1738 1.6.2.2 thorpej
1739 1.6.2.2 thorpej dcb->actsrb = srb;
1740 1.6.2.2 thorpej srb->state = SRB_DATA_XFER;
1741 1.6.2.2 thorpej } else {
1742 1.6.2.2 thorpej mingx0:
1743 1.6.2.2 thorpej srb = &sc->sc_tempsrb;
1744 1.6.2.2 thorpej srb->state = SRB_UNEXPECT_RESEL;
1745 1.6.2.2 thorpej dcb->actsrb = srb;
1746 1.6.2.2 thorpej srb->msgout[0] = MSG_ABORT_TAG;
1747 1.6.2.2 thorpej trm_msgout_abort(sc, srb);
1748 1.6.2.2 thorpej }
1749 1.6.2.2 thorpej }
1750 1.6.2.2 thorpej } else if ((srb->msgin[0] == MSG_EXTENDED) &&
1751 1.6.2.2 thorpej (srb->msgin[2] == MSG_EXT_WDTR) &&
1752 1.6.2.2 thorpej (srb->msgcnt == 4)) {
1753 1.6.2.2 thorpej /*
1754 1.6.2.2 thorpej * is Wide data xfer Extended message :
1755 1.6.2.2 thorpej * ======================================
1756 1.6.2.2 thorpej * WIDE DATA TRANSFER REQUEST
1757 1.6.2.2 thorpej * ======================================
1758 1.6.2.2 thorpej * byte 0 : Extended message (01h)
1759 1.6.2.2 thorpej * byte 1 : Extended message length (02h)
1760 1.6.2.2 thorpej * byte 2 : WIDE DATA TRANSFER code (03h)
1761 1.6.2.2 thorpej * byte 3 : Transfer width exponent
1762 1.6.2.2 thorpej */
1763 1.6.2.2 thorpej dcb = srb->dcb;
1764 1.6.2.2 thorpej srb->state &= ~(SRB_EXTEND_MSGIN | SRB_DO_WIDE_NEGO);
1765 1.6.2.2 thorpej if ((srb->msgin[1] != MSG_EXT_WDTR_LEN)) {
1766 1.6.2.2 thorpej /* Length is wrong, reject it */
1767 1.6.2.2 thorpej dcb->mode &=
1768 1.6.2.2 thorpej ~(WIDE_NEGO_ENABLE | WIDE_NEGO_DONE);
1769 1.6.2.2 thorpej srb->msgcnt = 1;
1770 1.6.2.2 thorpej srb->msgin[0] = MSG_MESSAGE_REJECT;
1771 1.6.2.2 thorpej bus_space_write_2(iot, ioh,
1772 1.6.2.2 thorpej TRM_SCSI_CONTROL, DO_SETATN);
1773 1.6.2.2 thorpej goto min6;
1774 1.6.2.2 thorpej }
1775 1.6.2.2 thorpej if (dcb->mode & WIDE_NEGO_ENABLE) {
1776 1.6.2.2 thorpej /* Do wide negoniation */
1777 1.6.2.2 thorpej if (srb->msgin[3] > MSG_EXT_WDTR_BUS_32_BIT) {
1778 1.6.2.2 thorpej /* reject_msg: */
1779 1.6.2.2 thorpej dcb->mode &= ~(WIDE_NEGO_ENABLE |
1780 1.6.2.2 thorpej WIDE_NEGO_DONE);
1781 1.6.2.2 thorpej srb->msgcnt = 1;
1782 1.6.2.2 thorpej srb->msgin[0] = MSG_MESSAGE_REJECT;
1783 1.6.2.2 thorpej bus_space_write_2(iot, ioh,
1784 1.6.2.2 thorpej TRM_SCSI_CONTROL, DO_SETATN);
1785 1.6.2.2 thorpej goto min6;
1786 1.6.2.2 thorpej }
1787 1.6.2.2 thorpej if (srb->msgin[3] == MSG_EXT_WDTR_BUS_32_BIT)
1788 1.6.2.2 thorpej /* do 16 bits */
1789 1.6.2.2 thorpej srb->msgin[3] = MSG_EXT_WDTR_BUS_16_BIT;
1790 1.6.2.2 thorpej else {
1791 1.6.2.2 thorpej if ((dcb->mode & WIDE_NEGO_DONE) == 0) {
1792 1.6.2.2 thorpej srb->state &=
1793 1.6.2.2 thorpej ~(SRB_DO_WIDE_NEGO |
1794 1.6.2.2 thorpej SRB_MSGIN);
1795 1.6.2.2 thorpej dcb->mode |= WIDE_NEGO_DONE;
1796 1.6.2.2 thorpej dcb->mode &=
1797 1.6.2.2 thorpej ~(SYNC_NEGO_DONE |
1798 1.6.2.2 thorpej EN_ATN_STOP |
1799 1.6.2.2 thorpej WIDE_NEGO_ENABLE);
1800 1.6.2.2 thorpej if (srb->msgin[3] !=
1801 1.6.2.2 thorpej MSG_EXT_WDTR_BUS_8_BIT)
1802 1.6.2.2 thorpej /* is Wide data xfer */
1803 1.6.2.2 thorpej dcb->synctl |=
1804 1.6.2.2 thorpej WIDE_SYNC;
1805 1.6.2.2 thorpej }
1806 1.6.2.2 thorpej }
1807 1.6.2.2 thorpej } else
1808 1.6.2.2 thorpej srb->msgin[3] = MSG_EXT_WDTR_BUS_8_BIT;
1809 1.6.2.2 thorpej
1810 1.6.2.2 thorpej srb->state |= SRB_MSGOUT;
1811 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
1812 1.6.2.2 thorpej DO_SETATN);
1813 1.6.2.2 thorpej goto min6;
1814 1.6.2.2 thorpej } else if ((srb->msgin[0] == MSG_EXTENDED) &&
1815 1.6.2.2 thorpej (srb->msgin[2] == MSG_EXT_SDTR) &&
1816 1.6.2.2 thorpej (srb->msgcnt == 5)) {
1817 1.6.2.2 thorpej /*
1818 1.6.2.2 thorpej * is 8bit transfer Extended message :
1819 1.6.2.2 thorpej * =================================
1820 1.6.2.2 thorpej * SYNCHRONOUS DATA TRANSFER REQUEST
1821 1.6.2.2 thorpej * =================================
1822 1.6.2.2 thorpej * byte 0 : Extended message (01h)
1823 1.6.2.2 thorpej * byte 1 : Extended message length (03)
1824 1.6.2.2 thorpej * byte 2 : SYNCHRONOUS DATA TRANSFER code (01h)
1825 1.6.2.2 thorpej * byte 3 : Transfer period factor
1826 1.6.2.2 thorpej * byte 4 : REQ/ACK offset
1827 1.6.2.2 thorpej */
1828 1.6.2.2 thorpej srb->state &= ~(SRB_EXTEND_MSGIN | SRB_DO_SYNC_NEGO);
1829 1.6.2.2 thorpej if (srb->msgin[1] != MSG_EXT_SDTR_LEN) {
1830 1.6.2.2 thorpej /* reject_msg: */
1831 1.6.2.2 thorpej srb->msgcnt = 1;
1832 1.6.2.2 thorpej srb->msgin[0] = MSG_MESSAGE_REJECT;
1833 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
1834 1.6.2.2 thorpej DO_SETATN);
1835 1.6.2.2 thorpej } else if (srb->msgin[3] == 0 || srb->msgin[4] == 0) {
1836 1.6.2.2 thorpej /* set async */
1837 1.6.2.2 thorpej dcb = srb->dcb;
1838 1.6.2.2 thorpej /* disable sync & sync nego */
1839 1.6.2.2 thorpej dcb->mode &=
1840 1.6.2.2 thorpej ~(SYNC_NEGO_ENABLE | SYNC_NEGO_DONE);
1841 1.6.2.2 thorpej dcb->synctl = 0;
1842 1.6.2.2 thorpej dcb->offset = 0;
1843 1.6.2.2 thorpej if (((dcb->flag & SHOW_MESSAGE_) == 0) &&
1844 1.6.2.2 thorpej (dcb->lun == 0)) {
1845 1.6.2.2 thorpej printf("%s: target %d, Sync period=0 "
1846 1.6.2.2 thorpej "or Sync offset=0 to be "
1847 1.6.2.2 thorpej "asynchronous transfer\n",
1848 1.6.2.2 thorpej sc->sc_dev.dv_xname, dcb->id);
1849 1.6.2.2 thorpej dcb->flag |= SHOW_MESSAGE_;
1850 1.6.2.2 thorpej }
1851 1.6.2.2 thorpej goto re_prog;
1852 1.6.2.2 thorpej } else { /* set sync */
1853 1.6.2.2 thorpej dcb = srb->dcb;
1854 1.6.2.2 thorpej dcb->mode |= SYNC_NEGO_ENABLE | SYNC_NEGO_DONE;
1855 1.6.2.2 thorpej
1856 1.6.2.2 thorpej /* Transfer period factor */
1857 1.6.2.2 thorpej dcb->period = srb->msgin[3];
1858 1.6.2.2 thorpej
1859 1.6.2.2 thorpej /* REQ/ACK offset */
1860 1.6.2.2 thorpej dcb->offset = srb->msgin[4];
1861 1.6.2.2 thorpej for (index = 0; index < 7; index++)
1862 1.6.2.2 thorpej if (srb->msgin[3] <=
1863 1.6.2.2 thorpej trm_clock_period[index])
1864 1.6.2.2 thorpej break;
1865 1.6.2.2 thorpej
1866 1.6.2.2 thorpej dcb->synctl |= (index | ALT_SYNC);
1867 1.6.2.2 thorpej /*
1868 1.6.2.2 thorpej * show negotiation message
1869 1.6.2.2 thorpej */
1870 1.6.2.2 thorpej if (((dcb->flag & SHOW_MESSAGE_) == 0) &&
1871 1.6.2.2 thorpej (dcb->lun == 0)) {
1872 1.6.2.2 thorpej syncxfer = 100000 /
1873 1.6.2.2 thorpej (trm_clock_period[index] * 4);
1874 1.6.2.2 thorpej if (dcb->synctl & WIDE_SYNC) {
1875 1.6.2.2 thorpej printf("%s: target %d, "
1876 1.6.2.2 thorpej "16bits Wide transfer\n",
1877 1.6.2.2 thorpej sc->sc_dev.dv_xname,
1878 1.6.2.2 thorpej dcb->id);
1879 1.6.2.2 thorpej syncxfer = syncxfer * 2;
1880 1.6.2.2 thorpej } else
1881 1.6.2.2 thorpej printf("%s: target %d, "
1882 1.6.2.2 thorpej "8bits Narrow transfer\n",
1883 1.6.2.2 thorpej sc->sc_dev.dv_xname,
1884 1.6.2.2 thorpej dcb->id);
1885 1.6.2.2 thorpej
1886 1.6.2.2 thorpej printf("%s: target %d, "
1887 1.6.2.2 thorpej "Sync transfer %d.%01d MB/sec, "
1888 1.6.2.2 thorpej "Offset %d\n", sc->sc_dev.dv_xname,
1889 1.6.2.2 thorpej dcb->id, syncxfer / 100,
1890 1.6.2.2 thorpej syncxfer % 100, dcb->offset);
1891 1.6.2.2 thorpej dcb->flag |= SHOW_MESSAGE_;
1892 1.6.2.2 thorpej }
1893 1.6.2.2 thorpej re_prog:
1894 1.6.2.2 thorpej /*
1895 1.6.2.2 thorpej * program SCSI control register
1896 1.6.2.2 thorpej */
1897 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_SYNC,
1898 1.6.2.2 thorpej dcb->synctl);
1899 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_OFFSET,
1900 1.6.2.2 thorpej dcb->offset);
1901 1.6.2.2 thorpej trm_set_xfer_rate(sc, srb, dcb);
1902 1.6.2.2 thorpej }
1903 1.6.2.2 thorpej }
1904 1.6.2.2 thorpej }
1905 1.6.2.2 thorpej min6:
1906 1.6.2.2 thorpej *pstat = PH_BUS_FREE; /* .. initial phase */
1907 1.6.2.2 thorpej /* it's important for atn stop */
1908 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_DATALATCH);
1909 1.6.2.2 thorpej
1910 1.6.2.2 thorpej /*
1911 1.6.2.2 thorpej * SCSI cammand
1912 1.6.2.2 thorpej */
1913 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, SCMD_MSGACCEPT);
1914 1.6.2.2 thorpej }
1915 1.6.2.2 thorpej
1916 1.6.2.2 thorpej static void
1917 1.6.2.2 thorpej trm_msgin_phase1(sc, srb, pstat)
1918 1.6.2.2 thorpej struct trm_softc *sc;
1919 1.6.2.2 thorpej struct trm_srb *srb;
1920 1.6.2.2 thorpej int *pstat;
1921 1.6.2.2 thorpej {
1922 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1923 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1924 1.6.2.2 thorpej
1925 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_CLRFIFO);
1926 1.6.2.2 thorpej bus_space_write_4(iot, ioh, TRM_SCSI_XCNT, 1);
1927 1.6.2.2 thorpej if ((srb->state & SRB_MSGIN) == 0) {
1928 1.6.2.2 thorpej srb->state &= SRB_DISCONNECT;
1929 1.6.2.2 thorpej srb->state |= SRB_MSGIN;
1930 1.6.2.2 thorpej }
1931 1.6.2.2 thorpej /* it's important for atn stop */
1932 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_DATALATCH);
1933 1.6.2.2 thorpej
1934 1.6.2.2 thorpej /*
1935 1.6.2.2 thorpej * SCSI cammand
1936 1.6.2.2 thorpej */
1937 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, SCMD_FIFO_IN);
1938 1.6.2.2 thorpej }
1939 1.6.2.2 thorpej
1940 1.6.2.2 thorpej static void
1941 1.6.2.2 thorpej trm_nop0(sc, srb, pstat)
1942 1.6.2.2 thorpej struct trm_softc *sc;
1943 1.6.2.2 thorpej struct trm_srb *srb;
1944 1.6.2.2 thorpej int *pstat;
1945 1.6.2.2 thorpej {
1946 1.6.2.2 thorpej
1947 1.6.2.2 thorpej }
1948 1.6.2.2 thorpej
1949 1.6.2.2 thorpej static void
1950 1.6.2.2 thorpej trm_nop1(sc, srb, pstat)
1951 1.6.2.2 thorpej struct trm_softc *sc;
1952 1.6.2.2 thorpej struct trm_srb *srb;
1953 1.6.2.2 thorpej int *pstat;
1954 1.6.2.2 thorpej {
1955 1.6.2.2 thorpej
1956 1.6.2.2 thorpej }
1957 1.6.2.2 thorpej
1958 1.6.2.2 thorpej static void
1959 1.6.2.2 thorpej trm_set_xfer_rate(sc, srb, dcb)
1960 1.6.2.2 thorpej struct trm_softc *sc;
1961 1.6.2.2 thorpej struct trm_srb *srb;
1962 1.6.2.2 thorpej struct trm_dcb *dcb;
1963 1.6.2.2 thorpej {
1964 1.6.2.2 thorpej struct trm_dcb *tempdcb;
1965 1.6.2.2 thorpej int i;
1966 1.6.2.2 thorpej
1967 1.6.2.2 thorpej /*
1968 1.6.2.2 thorpej * set all lun device's (period, offset)
1969 1.6.2.2 thorpej */
1970 1.6.2.2 thorpej #ifdef TRM_DEBUG
1971 1.6.2.2 thorpej printf("trm_set_xfer_rate............\n");
1972 1.6.2.2 thorpej #endif
1973 1.6.2.2 thorpej if ((dcb->idmsg & 0x07) == 0) {
1974 1.6.2.2 thorpej if (sc->devscan_end == 0)
1975 1.6.2.2 thorpej sc->cur_offset = dcb->offset;
1976 1.6.2.2 thorpej else {
1977 1.6.2.2 thorpej tempdcb = sc->sc_linkdcb;
1978 1.6.2.2 thorpej for (i = 0; i < sc->devcnt; i++) {
1979 1.6.2.2 thorpej /*
1980 1.6.2.2 thorpej * different LUN but had same target ID
1981 1.6.2.2 thorpej */
1982 1.6.2.2 thorpej if (tempdcb->id == dcb->id) {
1983 1.6.2.2 thorpej tempdcb->synctl = dcb->synctl;
1984 1.6.2.2 thorpej tempdcb->offset = dcb->offset;
1985 1.6.2.2 thorpej tempdcb->mode = dcb->mode;
1986 1.6.2.2 thorpej }
1987 1.6.2.2 thorpej tempdcb = tempdcb->next;
1988 1.6.2.2 thorpej }
1989 1.6.2.2 thorpej }
1990 1.6.2.2 thorpej }
1991 1.6.2.2 thorpej }
1992 1.6.2.2 thorpej
1993 1.6.2.2 thorpej static void
1994 1.6.2.2 thorpej trm_disconnect(sc)
1995 1.6.2.2 thorpej struct trm_softc *sc;
1996 1.6.2.2 thorpej {
1997 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
1998 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
1999 1.6.2.2 thorpej struct trm_dcb *dcb;
2000 1.6.2.2 thorpej struct trm_srb *srb, *psrb;
2001 1.6.2.2 thorpej int i, s;
2002 1.6.2.2 thorpej
2003 1.6.2.2 thorpej #ifdef TRM_DEBUG
2004 1.6.2.2 thorpej printf("trm_disconnect...............\n");
2005 1.6.2.2 thorpej #endif
2006 1.6.2.2 thorpej s = splbio();
2007 1.6.2.2 thorpej
2008 1.6.2.2 thorpej dcb = sc->sc_actdcb;
2009 1.6.2.2 thorpej if (dcb == NULL) {
2010 1.6.2.2 thorpej DELAY(1000); /* 1 msec */
2011 1.6.2.2 thorpej
2012 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
2013 1.6.2.2 thorpej DO_CLRFIFO | DO_HWRESELECT);
2014 1.6.2.2 thorpej return;
2015 1.6.2.2 thorpej }
2016 1.6.2.2 thorpej srb = dcb->actsrb;
2017 1.6.2.2 thorpej sc->sc_actdcb = 0;
2018 1.6.2.2 thorpej srb->phase = PH_BUS_FREE; /* SCSI bus free Phase */
2019 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL,
2020 1.6.2.2 thorpej DO_CLRFIFO | DO_HWRESELECT);
2021 1.6.2.2 thorpej DELAY(100);
2022 1.6.2.2 thorpej if (srb->state & SRB_UNEXPECT_RESEL) {
2023 1.6.2.2 thorpej srb->state = 0;
2024 1.6.2.2 thorpej trm_wait_srb(sc);
2025 1.6.2.2 thorpej } else if (srb->state & SRB_ABORT_SENT) {
2026 1.6.2.2 thorpej dcb->tagmask = 0;
2027 1.6.2.2 thorpej dcb->flag &= ~ABORT_DEV_;
2028 1.6.2.2 thorpej srb = dcb->gosrb;
2029 1.6.2.2 thorpej for (i = 0; i < dcb->gosrb_cnt; i++) {
2030 1.6.2.2 thorpej psrb = srb->next;
2031 1.6.2.2 thorpej srb->next = sc->sc_freesrb;
2032 1.6.2.2 thorpej sc->sc_freesrb = srb;
2033 1.6.2.2 thorpej srb = psrb;
2034 1.6.2.2 thorpej }
2035 1.6.2.2 thorpej dcb->gosrb_cnt = 0;
2036 1.6.2.2 thorpej dcb->gosrb = 0;
2037 1.6.2.2 thorpej trm_wait_srb(sc);
2038 1.6.2.2 thorpej } else {
2039 1.6.2.2 thorpej if ((srb->state & (SRB_START_ | SRB_MSGOUT)) ||
2040 1.6.2.2 thorpej (srb->state & (SRB_DISCONNECT | SRB_COMPLETED)) == 0) {
2041 1.6.2.2 thorpej /* Selection time out */
2042 1.6.2.2 thorpej if (sc->devscan_end) {
2043 1.6.2.2 thorpej srb->state = SRB_READY;
2044 1.6.2.2 thorpej trm_rewait_srb(dcb, srb);
2045 1.6.2.2 thorpej } else {
2046 1.6.2.2 thorpej srb->tastat = SCSI_SEL_TIMEOUT;
2047 1.6.2.2 thorpej goto disc1;
2048 1.6.2.2 thorpej }
2049 1.6.2.2 thorpej } else if (srb->state & SRB_DISCONNECT) {
2050 1.6.2.2 thorpej /*
2051 1.6.2.2 thorpej * SRB_DISCONNECT
2052 1.6.2.2 thorpej */
2053 1.6.2.2 thorpej trm_wait_srb(sc);
2054 1.6.2.2 thorpej } else if (srb->state & SRB_COMPLETED) {
2055 1.6.2.2 thorpej disc1:
2056 1.6.2.2 thorpej /*
2057 1.6.2.2 thorpej * SRB_COMPLETED
2058 1.6.2.2 thorpej */
2059 1.6.2.2 thorpej if (dcb->maxcmd > 1) {
2060 1.6.2.2 thorpej /* free tag mask */
2061 1.6.2.2 thorpej dcb->tagmask &= ~(1 << srb->tagnum);
2062 1.6.2.2 thorpej }
2063 1.6.2.2 thorpej dcb->actsrb = 0;
2064 1.6.2.2 thorpej srb->state = SRB_FREE;
2065 1.6.2.2 thorpej trm_srb_done(sc, dcb, srb);
2066 1.6.2.2 thorpej }
2067 1.6.2.2 thorpej }
2068 1.6.2.2 thorpej splx(s);
2069 1.6.2.2 thorpej }
2070 1.6.2.2 thorpej
2071 1.6.2.2 thorpej static void
2072 1.6.2.2 thorpej trm_reselect(sc)
2073 1.6.2.2 thorpej struct trm_softc *sc;
2074 1.6.2.2 thorpej {
2075 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2076 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2077 1.6.2.2 thorpej struct trm_dcb *dcb;
2078 1.6.2.2 thorpej struct trm_srb *srb;
2079 1.6.2.2 thorpej int id, lun;
2080 1.6.2.2 thorpej
2081 1.6.2.2 thorpej #ifdef TRM_DEBUG
2082 1.6.2.2 thorpej printf("trm_reselect.................\n");
2083 1.6.2.2 thorpej #endif
2084 1.6.2.2 thorpej dcb = sc->sc_actdcb;
2085 1.6.2.2 thorpej if (dcb != NULL) { /* Arbitration lost but Reselection win */
2086 1.6.2.2 thorpej srb = dcb->actsrb;
2087 1.6.2.2 thorpej srb->state = SRB_READY;
2088 1.6.2.2 thorpej trm_rewait_srb(dcb, srb);
2089 1.6.2.2 thorpej }
2090 1.6.2.2 thorpej /* Read Reselected Target Id and LUN */
2091 1.6.2.2 thorpej id = bus_space_read_1(iot, ioh, TRM_SCSI_TARGETID);
2092 1.6.2.2 thorpej lun = bus_space_read_1(iot, ioh, TRM_SCSI_IDMSG) & 0x07;
2093 1.6.2.2 thorpej dcb = sc->sc_linkdcb;
2094 1.6.2.2 thorpej while (id != dcb->id && lun != dcb->lun)
2095 1.6.2.2 thorpej /* get dcb of the reselect id */
2096 1.6.2.2 thorpej dcb = dcb->next;
2097 1.6.2.2 thorpej
2098 1.6.2.2 thorpej sc->sc_actdcb = dcb;
2099 1.6.2.2 thorpej if (dcb->mode & EN_TAG_QUEUING) {
2100 1.6.2.2 thorpej srb = &sc->sc_tempsrb;
2101 1.6.2.2 thorpej dcb->actsrb = srb;
2102 1.6.2.2 thorpej } else {
2103 1.6.2.2 thorpej srb = dcb->actsrb;
2104 1.6.2.2 thorpej if (srb == NULL || (srb->state & SRB_DISCONNECT) == 0) {
2105 1.6.2.2 thorpej /*
2106 1.6.2.2 thorpej * abort command
2107 1.6.2.2 thorpej */
2108 1.6.2.2 thorpej srb = &sc->sc_tempsrb;
2109 1.6.2.2 thorpej srb->state = SRB_UNEXPECT_RESEL;
2110 1.6.2.2 thorpej dcb->actsrb = srb;
2111 1.6.2.2 thorpej srb->msgout[0] = MSG_ABORT;
2112 1.6.2.2 thorpej trm_msgout_abort(sc, srb);
2113 1.6.2.2 thorpej } else {
2114 1.6.2.2 thorpej if (dcb->flag & ABORT_DEV_) {
2115 1.6.2.2 thorpej srb->state = SRB_ABORT_SENT;
2116 1.6.2.2 thorpej srb->msgout[0] = MSG_ABORT;
2117 1.6.2.2 thorpej trm_msgout_abort(sc, srb);
2118 1.6.2.2 thorpej } else
2119 1.6.2.2 thorpej srb->state = SRB_DATA_XFER;
2120 1.6.2.2 thorpej }
2121 1.6.2.2 thorpej }
2122 1.6.2.2 thorpej srb->phase = PH_BUS_FREE; /* SCSI bus free Phase */
2123 1.6.2.2 thorpej /*
2124 1.6.2.2 thorpej * Program HA ID, target ID, period and offset
2125 1.6.2.2 thorpej */
2126 1.6.2.2 thorpej /* target ID */
2127 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_TARGETID, id);
2128 1.6.2.2 thorpej
2129 1.6.2.2 thorpej /* host ID */
2130 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_HOSTID, sc->sc_id);
2131 1.6.2.2 thorpej
2132 1.6.2.2 thorpej /* period */
2133 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_SYNC, dcb->synctl);
2134 1.6.2.2 thorpej
2135 1.6.2.2 thorpej /* offset */
2136 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_OFFSET, dcb->offset);
2137 1.6.2.2 thorpej
2138 1.6.2.2 thorpej /* it's important for atn stop */
2139 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_DATALATCH);
2140 1.6.2.2 thorpej DELAY(30);
2141 1.6.2.2 thorpej /*
2142 1.6.2.2 thorpej * SCSI cammand
2143 1.6.2.2 thorpej */
2144 1.6.2.2 thorpej /* to rls the /ACK signal */
2145 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_COMMAND, SCMD_MSGACCEPT);
2146 1.6.2.2 thorpej }
2147 1.6.2.2 thorpej
2148 1.6.2.2 thorpej /*
2149 1.6.2.2 thorpej * Complete execution of a SCSI command
2150 1.6.2.2 thorpej * Signal completion to the generic SCSI driver
2151 1.6.2.2 thorpej */
2152 1.6.2.2 thorpej static void
2153 1.6.2.2 thorpej trm_srb_done(sc, dcb, srb)
2154 1.6.2.2 thorpej struct trm_softc *sc;
2155 1.6.2.2 thorpej struct trm_dcb *dcb;
2156 1.6.2.2 thorpej struct trm_srb *srb;
2157 1.6.2.2 thorpej {
2158 1.6.2.2 thorpej struct scsipi_xfer *xs = srb->xs;
2159 1.6.2.2 thorpej struct scsipi_inquiry_data *ptr;
2160 1.6.2.2 thorpej struct trm_dcb *tempdcb;
2161 1.6.2.2 thorpej int i, j, id, lun, s;
2162 1.6.2.2 thorpej u_int8_t bval;
2163 1.6.2.2 thorpej
2164 1.6.2.2 thorpej #ifdef TRM_DEBUG
2165 1.6.2.2 thorpej printf("trm_srb_done..................\n");
2166 1.6.2.2 thorpej #endif
2167 1.6.2.2 thorpej
2168 1.6.2.2 thorpej if (xs == NULL)
2169 1.6.2.2 thorpej return;
2170 1.6.2.2 thorpej
2171 1.6.2.2 thorpej if ((xs->xs_control & XS_CTL_POLL) == 0)
2172 1.6.2.2 thorpej callout_stop(&xs->xs_callout);
2173 1.6.2.2 thorpej
2174 1.6.2.2 thorpej if (xs->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT) ||
2175 1.6.2.2 thorpej srb->flag & AUTO_REQSENSE) {
2176 1.6.2.2 thorpej bus_dmamap_sync(sc->sc_dmat, srb->dmap, 0,
2177 1.6.2.2 thorpej srb->dmap->dm_mapsize,
2178 1.6.2.2 thorpej ((xs->xs_control & XS_CTL_DATA_IN) ||
2179 1.6.2.2 thorpej (srb->flag & AUTO_REQSENSE)) ?
2180 1.6.2.2 thorpej BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
2181 1.6.2.2 thorpej bus_dmamap_unload(sc->sc_dmat, srb->dmap);
2182 1.6.2.2 thorpej }
2183 1.6.2.2 thorpej
2184 1.6.2.2 thorpej /*
2185 1.6.2.2 thorpej * target status
2186 1.6.2.2 thorpej */
2187 1.6.2.2 thorpej xs->status = srb->tastat;
2188 1.6.2.2 thorpej
2189 1.6.2.2 thorpej switch (xs->status) {
2190 1.6.2.2 thorpej case SCSI_OK:
2191 1.6.2.2 thorpej /*
2192 1.6.2.2 thorpej * process initiator status......
2193 1.6.2.2 thorpej * Adapter (initiator) status
2194 1.6.2.2 thorpej */
2195 1.6.2.2 thorpej if (srb->hastat & H_OVER_UNDER_RUN) {
2196 1.6.2.2 thorpej srb->tastat = 0;
2197 1.6.2.2 thorpej /* Illegal length (over/under run) */
2198 1.6.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
2199 1.6.2.2 thorpej } else if (srb->srbstat & PARITY_ERROR) {
2200 1.6.2.2 thorpej #ifdef TRM_DEBUG
2201 1.6.2.2 thorpej printf("%s: driver stuffup at %s %d\n",
2202 1.6.2.2 thorpej sc->sc_dev.dv_xname, __FILE__, __LINE__);
2203 1.6.2.2 thorpej #endif
2204 1.6.2.2 thorpej /* Driver failed to perform operation */
2205 1.6.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
2206 1.6.2.2 thorpej } else {
2207 1.6.2.2 thorpej /* No error */
2208 1.6.2.2 thorpej srb->hastat = 0;
2209 1.6.2.2 thorpej if (srb->flag & AUTO_REQSENSE) {
2210 1.6.2.2 thorpej /* there is no error, (sense is invalid) */
2211 1.6.2.2 thorpej xs->error = XS_SENSE;
2212 1.6.2.2 thorpej } else {
2213 1.6.2.2 thorpej srb->tastat = 0;
2214 1.6.2.2 thorpej xs->error = XS_NOERROR;
2215 1.6.2.2 thorpej }
2216 1.6.2.2 thorpej }
2217 1.6.2.2 thorpej break;
2218 1.6.2.2 thorpej case SCSI_CHECK:
2219 1.6.2.2 thorpej if ((srb->flag & AUTO_REQSENSE) != 0 ||
2220 1.6.2.2 thorpej trm_request_sense(sc, dcb, srb) != 0) {
2221 1.6.2.2 thorpej printf("%s: request sense failed\n",
2222 1.6.2.2 thorpej sc->sc_dev.dv_xname);
2223 1.6.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
2224 1.6.2.2 thorpej break;
2225 1.6.2.2 thorpej }
2226 1.6.2.2 thorpej xs->error = XS_SENSE;
2227 1.6.2.2 thorpej return;
2228 1.6.2.2 thorpej case SCSI_QUEUE_FULL:
2229 1.6.2.2 thorpej dcb->maxcmd = dcb->gosrb_cnt - 1;
2230 1.6.2.2 thorpej trm_rewait_srb(dcb, srb);
2231 1.6.2.2 thorpej srb->hastat = 0;
2232 1.6.2.2 thorpej srb->tastat = 0;
2233 1.6.2.2 thorpej break;
2234 1.6.2.2 thorpej case SCSI_SEL_TIMEOUT:
2235 1.6.2.2 thorpej srb->hastat = H_SEL_TIMEOUT;
2236 1.6.2.2 thorpej srb->tastat = 0;
2237 1.6.2.2 thorpej xs->error = XS_TIMEOUT;
2238 1.6.2.2 thorpej break;
2239 1.6.2.2 thorpej case SCSI_BUSY:
2240 1.6.2.2 thorpej xs->error = XS_BUSY;
2241 1.6.2.2 thorpej break;
2242 1.6.2.2 thorpej case SCSI_RESV_CONFLICT:
2243 1.6.2.2 thorpej #ifdef TRM_DEBUG
2244 1.6.2.2 thorpej printf("%s: target reserved at ", sc->sc_dev.dv_xname);
2245 1.6.2.2 thorpej printf("%s %d\n", __FILE__, __LINE__);
2246 1.6.2.2 thorpej #endif
2247 1.6.2.2 thorpej xs->error = XS_BUSY;
2248 1.6.2.2 thorpej break;
2249 1.6.2.2 thorpej default:
2250 1.6.2.2 thorpej srb->hastat = 0;
2251 1.6.2.2 thorpej #ifdef TRM_DEBUG
2252 1.6.2.2 thorpej printf("%s: driver stuffup at %s %d\n",
2253 1.6.2.2 thorpej sc->sc_dev.dv_xname, __FILE__, __LINE__);
2254 1.6.2.2 thorpej #endif
2255 1.6.2.2 thorpej xs->error = XS_DRIVER_STUFFUP;
2256 1.6.2.2 thorpej break;
2257 1.6.2.2 thorpej }
2258 1.6.2.2 thorpej
2259 1.6.2.2 thorpej id = srb->xs->xs_periph->periph_target;
2260 1.6.2.2 thorpej lun = srb->xs->xs_periph->periph_lun;
2261 1.6.2.2 thorpej if (sc->devscan[id][lun]) {
2262 1.6.2.2 thorpej /*
2263 1.6.2.2 thorpej * if SCSI command in "scan devices" duty
2264 1.6.2.2 thorpej * XXX XXX XXX should not be done here! XXX XXX XXX
2265 1.6.2.2 thorpej */
2266 1.6.2.2 thorpej if (srb->cmd[0] == INQUIRY) {
2267 1.6.2.2 thorpej /*
2268 1.6.2.2 thorpej * SCSI command phase: inquiry scsi device data
2269 1.6.2.2 thorpej * (type,capacity,manufacture....
2270 1.6.2.2 thorpej */
2271 1.6.2.2 thorpej if (xs->error == XS_TIMEOUT)
2272 1.6.2.2 thorpej goto NO_DEV;
2273 1.6.2.2 thorpej
2274 1.6.2.2 thorpej ptr = (struct scsipi_inquiry_data *)xs->data;
2275 1.6.2.2 thorpej bval = ptr->device & SID_TYPE;
2276 1.6.2.2 thorpej
2277 1.6.2.2 thorpej if (bval == T_NODEVICE) {
2278 1.6.2.2 thorpej NO_DEV:
2279 1.6.2.2 thorpej #ifdef TRM_DEBUG
2280 1.6.2.2 thorpej printf("trm_srb_done NO Device: ");
2281 1.6.2.2 thorpej printf("id= %d ,lun= %d\n", id, lun);
2282 1.6.2.2 thorpej #endif
2283 1.6.2.2 thorpej s = splbio();
2284 1.6.2.2 thorpej /*
2285 1.6.2.2 thorpej * dcb Q link
2286 1.6.2.2 thorpej * move the head of DCB to temdcb
2287 1.6.2.2 thorpej */
2288 1.6.2.2 thorpej tempdcb = sc->sc_linkdcb;
2289 1.6.2.2 thorpej
2290 1.6.2.2 thorpej /*
2291 1.6.2.2 thorpej * search current DCB for pass link
2292 1.6.2.2 thorpej */
2293 1.6.2.2 thorpej while (tempdcb->next != dcb)
2294 1.6.2.2 thorpej tempdcb = tempdcb->next;
2295 1.6.2.2 thorpej
2296 1.6.2.2 thorpej /*
2297 1.6.2.2 thorpej * when the current DCB been found
2298 1.6.2.2 thorpej * than connect current DCB tail
2299 1.6.2.2 thorpej * to the DCB tail that before current DCB
2300 1.6.2.2 thorpej */
2301 1.6.2.2 thorpej tempdcb->next = dcb->next;
2302 1.6.2.2 thorpej
2303 1.6.2.2 thorpej /*
2304 1.6.2.2 thorpej * if there was only one DCB ,connect his
2305 1.6.2.2 thorpej * tail to his head
2306 1.6.2.2 thorpej */
2307 1.6.2.2 thorpej if (sc->sc_linkdcb == dcb)
2308 1.6.2.2 thorpej sc->sc_linkdcb = tempdcb->next;
2309 1.6.2.2 thorpej
2310 1.6.2.2 thorpej if (sc->sc_roundcb == dcb)
2311 1.6.2.2 thorpej sc->sc_roundcb = tempdcb->next;
2312 1.6.2.2 thorpej
2313 1.6.2.2 thorpej /*
2314 1.6.2.2 thorpej * if no device than free this device DCB
2315 1.6.2.2 thorpej * free( dcb, M_DEVBUF);
2316 1.6.2.2 thorpej */
2317 1.6.2.2 thorpej sc->devcnt--;
2318 1.6.2.2 thorpej #ifdef TRM_DEBUG
2319 1.6.2.2 thorpej printf("sc->devcnt=%d\n", sc->devcnt);
2320 1.6.2.2 thorpej #endif
2321 1.6.2.2 thorpej if (sc->devcnt == 0) {
2322 1.6.2.2 thorpej sc->sc_linkdcb = NULL;
2323 1.6.2.2 thorpej sc->sc_roundcb = NULL;
2324 1.6.2.2 thorpej }
2325 1.6.2.2 thorpej /* no device set scan device flag=0 */
2326 1.6.2.2 thorpej sc->devscan[id][lun] = 0;
2327 1.6.2.2 thorpej i = 0;
2328 1.6.2.2 thorpej j = 0;
2329 1.6.2.2 thorpej while (i <= sc->maxid) {
2330 1.6.2.2 thorpej while (j < 8) {
2331 1.6.2.2 thorpej if (sc->devscan[i][j] == 1) {
2332 1.6.2.2 thorpej sc->devscan_end = 0;
2333 1.6.2.2 thorpej splx(s);
2334 1.6.2.2 thorpej goto exit;
2335 1.6.2.2 thorpej } else
2336 1.6.2.2 thorpej sc->devscan_end = 1;
2337 1.6.2.2 thorpej
2338 1.6.2.2 thorpej j++;
2339 1.6.2.2 thorpej }
2340 1.6.2.2 thorpej j = 0;
2341 1.6.2.2 thorpej i++;
2342 1.6.2.2 thorpej }
2343 1.6.2.2 thorpej splx(s);
2344 1.6.2.2 thorpej } else {
2345 1.6.2.2 thorpej if (bval == T_DIRECT || bval == T_OPTICAL) {
2346 1.6.2.2 thorpej if ((((ptr->version & 0x07) >= 2) ||
2347 1.6.2.2 thorpej ((ptr->response_format & 0x0F)
2348 1.6.2.2 thorpej == 2)) &&
2349 1.6.2.2 thorpej (ptr->flags3 & SID_CmdQue) &&
2350 1.6.2.2 thorpej (dcb->tacfg & NTC_DO_TAG_QUEUING) &&
2351 1.6.2.2 thorpej (dcb->tacfg & NTC_DO_DISCONNECT)) {
2352 1.6.2.2 thorpej dcb->maxcmd = sc->maxtag;
2353 1.6.2.2 thorpej dcb->mode |= EN_TAG_QUEUING;
2354 1.6.2.2 thorpej dcb->tagmask = 0;
2355 1.6.2.2 thorpej } else
2356 1.6.2.2 thorpej dcb->mode |= EN_ATN_STOP;
2357 1.6.2.2 thorpej }
2358 1.6.2.2 thorpej }
2359 1.6.2.2 thorpej }
2360 1.6.2.2 thorpej }
2361 1.6.2.2 thorpej exit:
2362 1.6.2.2 thorpej trm_release_srb(sc, dcb, srb);
2363 1.6.2.2 thorpej trm_wait_srb(sc);
2364 1.6.2.2 thorpej xs->xs_status |= XS_STS_DONE;
2365 1.6.2.2 thorpej /* Notify cmd done */
2366 1.6.2.2 thorpej scsipi_done(xs);
2367 1.6.2.2 thorpej }
2368 1.6.2.2 thorpej
2369 1.6.2.2 thorpej static void
2370 1.6.2.2 thorpej trm_release_srb(sc, dcb, srb)
2371 1.6.2.2 thorpej struct trm_softc *sc;
2372 1.6.2.2 thorpej struct trm_dcb *dcb;
2373 1.6.2.2 thorpej struct trm_srb *srb;
2374 1.6.2.2 thorpej {
2375 1.6.2.2 thorpej struct trm_srb *psrb;
2376 1.6.2.2 thorpej int s;
2377 1.6.2.2 thorpej
2378 1.6.2.2 thorpej s = splbio();
2379 1.6.2.2 thorpej if (srb == dcb->gosrb)
2380 1.6.2.2 thorpej dcb->gosrb = srb->next;
2381 1.6.2.2 thorpej else {
2382 1.6.2.2 thorpej psrb = dcb->gosrb;
2383 1.6.2.2 thorpej while (psrb->next != srb)
2384 1.6.2.2 thorpej psrb = psrb->next;
2385 1.6.2.2 thorpej
2386 1.6.2.2 thorpej psrb->next = srb->next;
2387 1.6.2.2 thorpej if (srb == dcb->last_gosrb)
2388 1.6.2.2 thorpej dcb->last_gosrb = psrb;
2389 1.6.2.2 thorpej }
2390 1.6.2.2 thorpej srb->next = sc->sc_freesrb;
2391 1.6.2.2 thorpej sc->sc_freesrb = srb;
2392 1.6.2.2 thorpej dcb->gosrb_cnt--;
2393 1.6.2.2 thorpej splx(s);
2394 1.6.2.2 thorpej return;
2395 1.6.2.2 thorpej }
2396 1.6.2.2 thorpej
2397 1.6.2.2 thorpej static void
2398 1.6.2.2 thorpej trm_doing_srb_done(sc)
2399 1.6.2.2 thorpej struct trm_softc *sc;
2400 1.6.2.2 thorpej {
2401 1.6.2.2 thorpej struct trm_dcb *dcb, *pdcb;
2402 1.6.2.2 thorpej struct trm_srb *psrb, *psrb2;
2403 1.6.2.2 thorpej struct scsipi_xfer *xs;
2404 1.6.2.2 thorpej int i;
2405 1.6.2.2 thorpej
2406 1.6.2.2 thorpej dcb = sc->sc_linkdcb;
2407 1.6.2.2 thorpej if (dcb == NULL)
2408 1.6.2.2 thorpej return;
2409 1.6.2.2 thorpej
2410 1.6.2.2 thorpej pdcb = dcb;
2411 1.6.2.2 thorpej do {
2412 1.6.2.2 thorpej psrb = pdcb->gosrb;
2413 1.6.2.2 thorpej for (i = 0; i < pdcb->gosrb_cnt; i++) {
2414 1.6.2.2 thorpej psrb2 = psrb->next;
2415 1.6.2.2 thorpej xs = psrb->xs;
2416 1.6.2.2 thorpej xs->error = XS_TIMEOUT;
2417 1.6.2.2 thorpej /* ReleaseSRB( dcb, srb ); */
2418 1.6.2.2 thorpej psrb->next = sc->sc_freesrb;
2419 1.6.2.2 thorpej sc->sc_freesrb = psrb;
2420 1.6.2.2 thorpej scsipi_done(xs);
2421 1.6.2.2 thorpej psrb = psrb2;
2422 1.6.2.2 thorpej }
2423 1.6.2.2 thorpej pdcb->gosrb_cnt = 0;;
2424 1.6.2.2 thorpej pdcb->gosrb = NULL;
2425 1.6.2.2 thorpej pdcb->tagmask = 0;
2426 1.6.2.2 thorpej pdcb = pdcb->next;
2427 1.6.2.2 thorpej }
2428 1.6.2.2 thorpej while (pdcb != dcb);
2429 1.6.2.2 thorpej }
2430 1.6.2.2 thorpej
2431 1.6.2.2 thorpej static void
2432 1.6.2.2 thorpej trm_reset_scsi_bus(sc)
2433 1.6.2.2 thorpej struct trm_softc *sc;
2434 1.6.2.2 thorpej {
2435 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2436 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2437 1.6.2.2 thorpej int s;
2438 1.6.2.2 thorpej
2439 1.6.2.2 thorpej s = splbio();
2440 1.6.2.2 thorpej
2441 1.6.2.2 thorpej sc->sc_flag |= RESET_DEV;
2442 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_RSTSCSI);
2443 1.6.2.2 thorpej while ((bus_space_read_2(iot, ioh, TRM_SCSI_INTSTATUS) &
2444 1.6.2.2 thorpej INT_SCSIRESET) == 0)
2445 1.6.2.2 thorpej ;
2446 1.6.2.2 thorpej
2447 1.6.2.2 thorpej splx(s);
2448 1.6.2.2 thorpej }
2449 1.6.2.2 thorpej
2450 1.6.2.2 thorpej static void
2451 1.6.2.2 thorpej trm_scsi_reset_detect(sc)
2452 1.6.2.2 thorpej struct trm_softc *sc;
2453 1.6.2.2 thorpej {
2454 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2455 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2456 1.6.2.2 thorpej int s;
2457 1.6.2.2 thorpej
2458 1.6.2.2 thorpej #ifdef TRM_DEBUG
2459 1.6.2.2 thorpej printf("trm_scsi_reset_detect...............\n");
2460 1.6.2.2 thorpej #endif
2461 1.6.2.2 thorpej DELAY(1000000); /* delay 1 sec */
2462 1.6.2.2 thorpej
2463 1.6.2.2 thorpej s = splbio();
2464 1.6.2.2 thorpej
2465 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_CONTROL, STOPDMAXFER);
2466 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_CLRFIFO);
2467 1.6.2.2 thorpej
2468 1.6.2.2 thorpej if (sc->sc_flag & RESET_DEV) {
2469 1.6.2.2 thorpej sc->sc_flag |= RESET_DONE;
2470 1.6.2.2 thorpej } else {
2471 1.6.2.2 thorpej sc->sc_flag |= RESET_DETECT;
2472 1.6.2.2 thorpej trm_reset_device(sc);
2473 1.6.2.2 thorpej /* trm_doing_srb_done( sc ); ???? */
2474 1.6.2.2 thorpej trm_recover_srb(sc);
2475 1.6.2.2 thorpej sc->sc_actdcb = NULL;
2476 1.6.2.2 thorpej sc->sc_flag = 0;
2477 1.6.2.2 thorpej trm_wait_srb(sc);
2478 1.6.2.2 thorpej }
2479 1.6.2.2 thorpej splx(s);
2480 1.6.2.2 thorpej }
2481 1.6.2.2 thorpej
2482 1.6.2.2 thorpej static int
2483 1.6.2.2 thorpej trm_request_sense(sc, dcb, srb)
2484 1.6.2.2 thorpej struct trm_softc *sc;
2485 1.6.2.2 thorpej struct trm_dcb *dcb;
2486 1.6.2.2 thorpej struct trm_srb *srb;
2487 1.6.2.2 thorpej {
2488 1.6.2.2 thorpej struct scsipi_xfer *xs = srb->xs;
2489 1.6.2.2 thorpej struct scsipi_sense *ss;
2490 1.6.2.2 thorpej int error, lun = xs->xs_periph->periph_lun;
2491 1.6.2.2 thorpej
2492 1.6.2.2 thorpej srb->flag |= AUTO_REQSENSE;
2493 1.6.2.2 thorpej
2494 1.6.2.2 thorpej /* Status of initiator/target */
2495 1.6.2.2 thorpej srb->hastat = 0;
2496 1.6.2.2 thorpej srb->tastat = 0;
2497 1.6.2.2 thorpej
2498 1.6.2.2 thorpej ss = (struct scsipi_sense *)srb->cmd;
2499 1.6.2.2 thorpej ss->opcode = REQUEST_SENSE;
2500 1.6.2.2 thorpej ss->byte2 = lun << SCSI_CMD_LUN_SHIFT;
2501 1.6.2.2 thorpej ss->unused[0] = ss->unused[1] = 0;
2502 1.6.2.2 thorpej ss->length = sizeof(struct scsipi_sense_data);
2503 1.6.2.2 thorpej ss->control = 0;
2504 1.6.2.2 thorpej
2505 1.6.2.2 thorpej srb->buflen = sizeof(struct scsipi_sense_data);
2506 1.6.2.2 thorpej srb->sgcnt = 1;
2507 1.6.2.2 thorpej srb->sgindex = 0;
2508 1.6.2.2 thorpej srb->cmdlen = sizeof(struct scsipi_sense);
2509 1.6.2.2 thorpej
2510 1.6.2.2 thorpej if ((error = bus_dmamap_load(sc->sc_dmat, srb->dmap,
2511 1.6.2.2 thorpej &xs->sense.scsi_sense, srb->buflen, NULL,
2512 1.6.2.2 thorpej BUS_DMA_READ|BUS_DMA_NOWAIT)) != 0) {
2513 1.6.2.2 thorpej return error;
2514 1.6.2.2 thorpej }
2515 1.6.2.2 thorpej bus_dmamap_sync(sc->sc_dmat, srb->dmap, 0,
2516 1.6.2.2 thorpej srb->buflen, BUS_DMASYNC_PREREAD);
2517 1.6.2.2 thorpej
2518 1.6.2.2 thorpej srb->sgentry[0].address = htole32(srb->dmap->dm_segs[0].ds_addr);
2519 1.6.2.2 thorpej srb->sgentry[0].length = htole32(sizeof(struct scsipi_sense_data));
2520 1.6.2.2 thorpej bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, srb->sgoffset,
2521 1.6.2.2 thorpej TRM_SG_SIZE, BUS_DMASYNC_PREWRITE);
2522 1.6.2.2 thorpej
2523 1.6.2.2 thorpej if (trm_start_scsi(sc, dcb, srb))
2524 1.6.2.2 thorpej /*
2525 1.6.2.2 thorpej * If trm_start_scsi return 1: current interrupt status
2526 1.6.2.2 thorpej * is interrupt disreenable. It's said that SCSI processor
2527 1.6.2.2 thorpej * has more one SRB need to do.
2528 1.6.2.2 thorpej */
2529 1.6.2.2 thorpej trm_rewait_srb(dcb, srb);
2530 1.6.2.2 thorpej return 0;
2531 1.6.2.2 thorpej }
2532 1.6.2.2 thorpej
2533 1.6.2.2 thorpej static void
2534 1.6.2.2 thorpej trm_msgout_abort(sc, srb)
2535 1.6.2.2 thorpej struct trm_softc *sc;
2536 1.6.2.2 thorpej struct trm_srb *srb;
2537 1.6.2.2 thorpej {
2538 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2539 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2540 1.6.2.2 thorpej
2541 1.6.2.2 thorpej srb->msgcnt = 1;
2542 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_SETATN);
2543 1.6.2.2 thorpej srb->dcb->flag &= ~ABORT_DEV_;
2544 1.6.2.2 thorpej }
2545 1.6.2.2 thorpej
2546 1.6.2.2 thorpej /*
2547 1.6.2.2 thorpej * initialize the internal structures for a given DCB
2548 1.6.2.2 thorpej */
2549 1.6.2.2 thorpej static void
2550 1.6.2.2 thorpej trm_init_dcb(sc, dcb, xs)
2551 1.6.2.2 thorpej struct trm_softc *sc;
2552 1.6.2.2 thorpej struct trm_dcb *dcb;
2553 1.6.2.2 thorpej struct scsipi_xfer *xs;
2554 1.6.2.2 thorpej {
2555 1.6.2.2 thorpej struct trm_nvram *eeprom;
2556 1.6.2.2 thorpej struct trm_dcb *tempdcb;
2557 1.6.2.2 thorpej int index, id, lun, s;
2558 1.6.2.2 thorpej
2559 1.6.2.2 thorpej id = xs->xs_periph->periph_target;
2560 1.6.2.2 thorpej lun = xs->xs_periph->periph_lun;
2561 1.6.2.2 thorpej
2562 1.6.2.2 thorpej s = splbio();
2563 1.6.2.2 thorpej if (sc->sc_linkdcb == 0) {
2564 1.6.2.2 thorpej sc->sc_linkdcb = dcb;
2565 1.6.2.2 thorpej /*
2566 1.6.2.2 thorpej * RunRobin impersonate the role that let each device had
2567 1.6.2.2 thorpej * good proportion about SCSI command proceeding.
2568 1.6.2.2 thorpej */
2569 1.6.2.2 thorpej sc->sc_roundcb = dcb;
2570 1.6.2.2 thorpej dcb->next = dcb;
2571 1.6.2.2 thorpej } else {
2572 1.6.2.2 thorpej tempdcb = sc->sc_linkdcb;
2573 1.6.2.2 thorpej /* search the last nod of DCB link */
2574 1.6.2.2 thorpej while (tempdcb->next != sc->sc_linkdcb)
2575 1.6.2.2 thorpej tempdcb = tempdcb->next;
2576 1.6.2.2 thorpej
2577 1.6.2.2 thorpej /* connect current DCB with last DCB tail */
2578 1.6.2.2 thorpej tempdcb->next = dcb;
2579 1.6.2.2 thorpej /* connect current DCB tail to this DCB Q head */
2580 1.6.2.2 thorpej dcb->next = sc->sc_linkdcb;
2581 1.6.2.2 thorpej }
2582 1.6.2.2 thorpej splx(s);
2583 1.6.2.2 thorpej
2584 1.6.2.2 thorpej sc->devcnt++;
2585 1.6.2.2 thorpej dcb->id = id;
2586 1.6.2.2 thorpej dcb->lun = lun;
2587 1.6.2.2 thorpej dcb->waitsrb = NULL;
2588 1.6.2.2 thorpej dcb->gosrb = NULL;
2589 1.6.2.2 thorpej dcb->gosrb_cnt = 0;
2590 1.6.2.2 thorpej dcb->actsrb = NULL;
2591 1.6.2.2 thorpej dcb->tagmask = 0;
2592 1.6.2.2 thorpej dcb->maxcmd = 1;
2593 1.6.2.2 thorpej dcb->flag = 0;
2594 1.6.2.2 thorpej
2595 1.6.2.2 thorpej eeprom = &sc->sc_eeprom;
2596 1.6.2.2 thorpej dcb->tacfg = eeprom->target[id].config0;
2597 1.6.2.2 thorpej /*
2598 1.6.2.2 thorpej * disconnect enable?
2599 1.6.2.2 thorpej */
2600 1.6.2.2 thorpej dcb->idmsg = MSG_IDENTIFY(lun, dcb->tacfg & NTC_DO_DISCONNECT);
2601 1.6.2.2 thorpej /*
2602 1.6.2.2 thorpej * tag Qing enable?
2603 1.6.2.2 thorpej * wide nego, sync nego enable?
2604 1.6.2.2 thorpej */
2605 1.6.2.2 thorpej dcb->synctl = 0;
2606 1.6.2.2 thorpej dcb->offset = 0;
2607 1.6.2.2 thorpej index = eeprom->target[id].period & 0x07;
2608 1.6.2.2 thorpej dcb->period = trm_clock_period[index];
2609 1.6.2.2 thorpej dcb->mode = 0;
2610 1.6.2.2 thorpej if ((dcb->tacfg & NTC_DO_WIDE_NEGO) && (sc->sc_config & HCC_WIDE_CARD))
2611 1.6.2.2 thorpej /* enable wide nego */
2612 1.6.2.2 thorpej dcb->mode |= WIDE_NEGO_ENABLE;
2613 1.6.2.2 thorpej
2614 1.6.2.2 thorpej if ((dcb->tacfg & NTC_DO_SYNC_NEGO) && (lun == 0 || sc->cur_offset > 0))
2615 1.6.2.2 thorpej /* enable sync nego */
2616 1.6.2.2 thorpej dcb->mode |= SYNC_NEGO_ENABLE;
2617 1.6.2.2 thorpej }
2618 1.6.2.2 thorpej
2619 1.6.2.2 thorpej static void
2620 1.6.2.2 thorpej trm_link_srb(sc)
2621 1.6.2.2 thorpej struct trm_softc *sc;
2622 1.6.2.2 thorpej {
2623 1.6.2.2 thorpej struct trm_srb *srb;
2624 1.6.2.2 thorpej int i;
2625 1.6.2.2 thorpej
2626 1.6.2.2 thorpej sc->sc_srb = malloc(sizeof(struct trm_srb) * TRM_MAX_SRB,
2627 1.6.2.2 thorpej M_DEVBUF, M_NOWAIT|M_ZERO);
2628 1.6.2.2 thorpej if (sc->sc_srb == NULL) {
2629 1.6.2.2 thorpej printf("%s: can not allocate SRB\n", sc->sc_dev.dv_xname);
2630 1.6.2.2 thorpej return;
2631 1.6.2.2 thorpej }
2632 1.6.2.2 thorpej
2633 1.6.2.2 thorpej for (i = 0, srb = sc->sc_srb; i < TRM_MAX_SRB; i++, srb++) {
2634 1.6.2.2 thorpej srb->sgentry = sc->sc_sglist + TRM_MAX_SG_ENTRIES * i;
2635 1.6.2.2 thorpej srb->sgoffset = TRM_SG_SIZE * i;
2636 1.6.2.2 thorpej srb->sgaddr = sc->sc_dmamap->dm_segs[0].ds_addr + srb->sgoffset;
2637 1.6.2.2 thorpej /*
2638 1.6.2.2 thorpej * map all SRB space to SRB_array
2639 1.6.2.2 thorpej */
2640 1.6.2.2 thorpej if (bus_dmamap_create(sc->sc_dmat,
2641 1.6.2.2 thorpej MAXPHYS, TRM_MAX_SG_ENTRIES, MAXPHYS, 0,
2642 1.6.2.2 thorpej BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &srb->dmap)) {
2643 1.6.2.2 thorpej printf("%s: unable to create DMA transfer map...\n",
2644 1.6.2.2 thorpej sc->sc_dev.dv_xname);
2645 1.6.2.2 thorpej free(sc->sc_srb, M_DEVBUF);
2646 1.6.2.2 thorpej return;
2647 1.6.2.2 thorpej }
2648 1.6.2.2 thorpej if (i != TRM_MAX_SRB - 1) {
2649 1.6.2.2 thorpej /*
2650 1.6.2.2 thorpej * link all SRB
2651 1.6.2.2 thorpej */
2652 1.6.2.2 thorpej srb->next = srb + 1;
2653 1.6.2.2 thorpej #ifdef TRM_DEBUG
2654 1.6.2.2 thorpej printf("srb->next = %8x ", (int) (srb + 1));
2655 1.6.2.2 thorpej #endif
2656 1.6.2.2 thorpej } else {
2657 1.6.2.2 thorpej /*
2658 1.6.2.2 thorpej * load NULL to NextSRB of the last SRB
2659 1.6.2.2 thorpej */
2660 1.6.2.2 thorpej srb->next = NULL;
2661 1.6.2.2 thorpej }
2662 1.6.2.2 thorpej #ifdef TRM_DEBUG
2663 1.6.2.2 thorpej printf("srb = %8x\n", (int) srb);
2664 1.6.2.2 thorpej #endif
2665 1.6.2.2 thorpej }
2666 1.6.2.2 thorpej return;
2667 1.6.2.2 thorpej }
2668 1.6.2.2 thorpej
2669 1.6.2.2 thorpej /*
2670 1.6.2.2 thorpej * initialize the internal structures for a given SCSI host
2671 1.6.2.2 thorpej */
2672 1.6.2.2 thorpej static void
2673 1.6.2.2 thorpej trm_init_sc(sc)
2674 1.6.2.2 thorpej struct trm_softc *sc;
2675 1.6.2.2 thorpej {
2676 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2677 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2678 1.6.2.2 thorpej struct trm_nvram *eeprom;
2679 1.6.2.2 thorpej int i, j;
2680 1.6.2.2 thorpej
2681 1.6.2.2 thorpej eeprom = &sc->sc_eeprom;
2682 1.6.2.2 thorpej sc->maxid = 7;
2683 1.6.2.2 thorpej sc->sc_config = HCC_AUTOTERM | HCC_PARITY;
2684 1.6.2.2 thorpej if (bus_space_read_1(iot, ioh, TRM_GEN_STATUS) & WIDESCSI) {
2685 1.6.2.2 thorpej sc->sc_config |= HCC_WIDE_CARD;
2686 1.6.2.2 thorpej sc->maxid = 15;
2687 1.6.2.2 thorpej }
2688 1.6.2.2 thorpej if (eeprom->channel_cfg & NAC_POWERON_SCSI_RESET)
2689 1.6.2.2 thorpej sc->sc_config |= HCC_SCSI_RESET;
2690 1.6.2.2 thorpej
2691 1.6.2.2 thorpej sc->sc_linkdcb = NULL;
2692 1.6.2.2 thorpej sc->sc_roundcb = NULL;
2693 1.6.2.2 thorpej sc->sc_actdcb = NULL;
2694 1.6.2.2 thorpej sc->sc_id = eeprom->scsi_id;
2695 1.6.2.2 thorpej sc->devcnt = 0;
2696 1.6.2.2 thorpej sc->maxtag = 2 << eeprom->max_tag;
2697 1.6.2.2 thorpej sc->sc_flag = 0;
2698 1.6.2.2 thorpej sc->devscan_end = 0;
2699 1.6.2.2 thorpej /*
2700 1.6.2.2 thorpej * link all device's SRB Q of this adapter
2701 1.6.2.2 thorpej */
2702 1.6.2.2 thorpej trm_link_srb(sc);
2703 1.6.2.2 thorpej sc->sc_freesrb = sc->sc_srb;
2704 1.6.2.2 thorpej /* allocate DCB array for scan device */
2705 1.6.2.2 thorpej for (i = 0; i <= sc->maxid; i++)
2706 1.6.2.2 thorpej if (sc->sc_id != i)
2707 1.6.2.2 thorpej for (j = 0; j < 8; j++) {
2708 1.6.2.2 thorpej sc->devscan[i][j] = 1;
2709 1.6.2.2 thorpej sc->devflag[i][j] = 0;
2710 1.6.2.2 thorpej sc->sc_dcb[i][j] =
2711 1.6.2.2 thorpej malloc(sizeof(struct trm_dcb),
2712 1.6.2.2 thorpej M_DEVBUF, M_WAITOK);
2713 1.6.2.2 thorpej }
2714 1.6.2.2 thorpej
2715 1.6.2.2 thorpej #ifdef TRM_DEBUG
2716 1.6.2.2 thorpej printf("sizeof(struct trm_dcb)= %8x\n", sizeof(struct trm_dcb));
2717 1.6.2.2 thorpej printf("sizeof(struct trm_softc)= %8x\n", sizeof(struct trm_softc));
2718 1.6.2.2 thorpej printf("sizeof(struct trm_srb)= %8x\n", sizeof(struct trm_srb));
2719 1.6.2.2 thorpej #endif
2720 1.6.2.2 thorpej sc->sc_adapter.adapt_dev = &sc->sc_dev;
2721 1.6.2.2 thorpej sc->sc_adapter.adapt_nchannels = 1;
2722 1.6.2.2 thorpej sc->sc_adapter.adapt_openings = TRM_MAX_SRB;
2723 1.6.2.2 thorpej sc->sc_adapter.adapt_max_periph = TRM_MAX_SRB;
2724 1.6.2.2 thorpej sc->sc_adapter.adapt_request = trm_scsipi_request;
2725 1.6.2.2 thorpej sc->sc_adapter.adapt_minphys = minphys;
2726 1.6.2.2 thorpej
2727 1.6.2.2 thorpej sc->sc_channel.chan_adapter = &sc->sc_adapter;
2728 1.6.2.2 thorpej sc->sc_channel.chan_bustype = &scsi_bustype;
2729 1.6.2.2 thorpej sc->sc_channel.chan_channel = 0;
2730 1.6.2.2 thorpej sc->sc_channel.chan_ntargets = sc->maxid + 1;
2731 1.6.2.2 thorpej sc->sc_channel.chan_nluns = 8;
2732 1.6.2.2 thorpej sc->sc_channel.chan_id = sc->sc_id;
2733 1.6.2.2 thorpej }
2734 1.6.2.2 thorpej
2735 1.6.2.2 thorpej /*
2736 1.6.2.2 thorpej * write sc_eeprom 128 bytes to seeprom
2737 1.6.2.2 thorpej */
2738 1.6.2.2 thorpej static void
2739 1.6.2.2 thorpej trm_eeprom_write_all(sc, eeprom)
2740 1.6.2.2 thorpej struct trm_softc *sc;
2741 1.6.2.2 thorpej struct trm_nvram *eeprom;
2742 1.6.2.2 thorpej {
2743 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2744 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2745 1.6.2.2 thorpej u_int8_t *buf = (u_int8_t *)eeprom;
2746 1.6.2.2 thorpej u_int8_t addr;
2747 1.6.2.2 thorpej
2748 1.6.2.2 thorpej /* Enable SEEPROM */
2749 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_CONTROL,
2750 1.6.2.2 thorpej bus_space_read_1(iot, ioh, TRM_GEN_CONTROL) | EN_EEPROM);
2751 1.6.2.2 thorpej
2752 1.6.2.2 thorpej /*
2753 1.6.2.2 thorpej * Write enable
2754 1.6.2.2 thorpej */
2755 1.6.2.2 thorpej trm_eeprom_write_cmd(sc, 0x04, 0xFF);
2756 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, 0);
2757 1.6.2.2 thorpej trm_wait_30us();
2758 1.6.2.2 thorpej
2759 1.6.2.2 thorpej for (addr = 0; addr < 128; addr++, buf++)
2760 1.6.2.2 thorpej trm_eeprom_set_data(sc, addr, *buf);
2761 1.6.2.2 thorpej
2762 1.6.2.2 thorpej /*
2763 1.6.2.2 thorpej * Write disable
2764 1.6.2.2 thorpej */
2765 1.6.2.2 thorpej trm_eeprom_write_cmd(sc, 0x04, 0x00);
2766 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, 0);
2767 1.6.2.2 thorpej trm_wait_30us();
2768 1.6.2.2 thorpej
2769 1.6.2.2 thorpej /* Disable SEEPROM */
2770 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_CONTROL,
2771 1.6.2.2 thorpej bus_space_read_1(iot, ioh, TRM_GEN_CONTROL) & ~EN_EEPROM);
2772 1.6.2.2 thorpej }
2773 1.6.2.2 thorpej
2774 1.6.2.2 thorpej /*
2775 1.6.2.2 thorpej * write one byte to seeprom
2776 1.6.2.2 thorpej */
2777 1.6.2.2 thorpej static void
2778 1.6.2.2 thorpej trm_eeprom_set_data(sc, addr, data)
2779 1.6.2.2 thorpej struct trm_softc *sc;
2780 1.6.2.2 thorpej u_int8_t addr;
2781 1.6.2.2 thorpej u_int8_t data;
2782 1.6.2.2 thorpej {
2783 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2784 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2785 1.6.2.2 thorpej int i;
2786 1.6.2.2 thorpej u_int8_t send;
2787 1.6.2.2 thorpej
2788 1.6.2.2 thorpej /*
2789 1.6.2.2 thorpej * Send write command & address
2790 1.6.2.2 thorpej */
2791 1.6.2.2 thorpej trm_eeprom_write_cmd(sc, 0x05, addr);
2792 1.6.2.2 thorpej /*
2793 1.6.2.2 thorpej * Write data
2794 1.6.2.2 thorpej */
2795 1.6.2.2 thorpej for (i = 0; i < 8; i++, data <<= 1) {
2796 1.6.2.2 thorpej send = NVR_SELECT;
2797 1.6.2.2 thorpej if (data & 0x80) /* Start from bit 7 */
2798 1.6.2.2 thorpej send |= NVR_BITOUT;
2799 1.6.2.2 thorpej
2800 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, send);
2801 1.6.2.2 thorpej trm_wait_30us();
2802 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, send | NVR_CLOCK);
2803 1.6.2.2 thorpej trm_wait_30us();
2804 1.6.2.2 thorpej }
2805 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, NVR_SELECT);
2806 1.6.2.2 thorpej trm_wait_30us();
2807 1.6.2.2 thorpej /*
2808 1.6.2.2 thorpej * Disable chip select
2809 1.6.2.2 thorpej */
2810 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, 0);
2811 1.6.2.2 thorpej trm_wait_30us();
2812 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, NVR_SELECT);
2813 1.6.2.2 thorpej trm_wait_30us();
2814 1.6.2.2 thorpej /*
2815 1.6.2.2 thorpej * Wait for write ready
2816 1.6.2.2 thorpej */
2817 1.6.2.2 thorpej for (;;) {
2818 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM,
2819 1.6.2.2 thorpej NVR_SELECT | NVR_CLOCK);
2820 1.6.2.2 thorpej trm_wait_30us();
2821 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, NVR_SELECT);
2822 1.6.2.2 thorpej trm_wait_30us();
2823 1.6.2.2 thorpej if (bus_space_read_1(iot, ioh, TRM_GEN_NVRAM) & NVR_BITIN)
2824 1.6.2.2 thorpej break;
2825 1.6.2.2 thorpej }
2826 1.6.2.2 thorpej /*
2827 1.6.2.2 thorpej * Disable chip select
2828 1.6.2.2 thorpej */
2829 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, 0);
2830 1.6.2.2 thorpej }
2831 1.6.2.2 thorpej
2832 1.6.2.2 thorpej /*
2833 1.6.2.2 thorpej * read seeprom 128 bytes to sc_eeprom
2834 1.6.2.2 thorpej */
2835 1.6.2.2 thorpej static void
2836 1.6.2.2 thorpej trm_eeprom_read_all(sc, eeprom)
2837 1.6.2.2 thorpej struct trm_softc *sc;
2838 1.6.2.2 thorpej struct trm_nvram *eeprom;
2839 1.6.2.2 thorpej {
2840 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2841 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2842 1.6.2.2 thorpej u_int8_t *buf = (u_int8_t *)eeprom;
2843 1.6.2.2 thorpej u_int8_t addr;
2844 1.6.2.2 thorpej
2845 1.6.2.2 thorpej /*
2846 1.6.2.2 thorpej * Enable SEEPROM
2847 1.6.2.2 thorpej */
2848 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_CONTROL,
2849 1.6.2.2 thorpej bus_space_read_1(iot, ioh, TRM_GEN_CONTROL) | EN_EEPROM);
2850 1.6.2.2 thorpej
2851 1.6.2.2 thorpej for (addr = 0; addr < 128; addr++, buf++)
2852 1.6.2.2 thorpej *buf = trm_eeprom_get_data(sc, addr);
2853 1.6.2.2 thorpej
2854 1.6.2.2 thorpej /*
2855 1.6.2.2 thorpej * Disable SEEPROM
2856 1.6.2.2 thorpej */
2857 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_CONTROL,
2858 1.6.2.2 thorpej bus_space_read_1(iot, ioh, TRM_GEN_CONTROL) & ~EN_EEPROM);
2859 1.6.2.2 thorpej }
2860 1.6.2.2 thorpej
2861 1.6.2.2 thorpej /*
2862 1.6.2.2 thorpej * read one byte from seeprom
2863 1.6.2.2 thorpej */
2864 1.6.2.2 thorpej static u_int8_t
2865 1.6.2.2 thorpej trm_eeprom_get_data(sc, addr)
2866 1.6.2.2 thorpej struct trm_softc *sc;
2867 1.6.2.2 thorpej u_int8_t addr;
2868 1.6.2.2 thorpej {
2869 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2870 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2871 1.6.2.2 thorpej int i;
2872 1.6.2.2 thorpej u_int8_t read, data = 0;
2873 1.6.2.2 thorpej
2874 1.6.2.2 thorpej /*
2875 1.6.2.2 thorpej * Send read command & address
2876 1.6.2.2 thorpej */
2877 1.6.2.2 thorpej trm_eeprom_write_cmd(sc, 0x06, addr);
2878 1.6.2.2 thorpej
2879 1.6.2.2 thorpej for (i = 0; i < 8; i++) { /* Read data */
2880 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM,
2881 1.6.2.2 thorpej NVR_SELECT | NVR_CLOCK);
2882 1.6.2.2 thorpej trm_wait_30us();
2883 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, NVR_SELECT);
2884 1.6.2.2 thorpej /*
2885 1.6.2.2 thorpej * Get data bit while falling edge
2886 1.6.2.2 thorpej */
2887 1.6.2.2 thorpej read = bus_space_read_1(iot, ioh, TRM_GEN_NVRAM);
2888 1.6.2.2 thorpej data <<= 1;
2889 1.6.2.2 thorpej if (read & NVR_BITIN)
2890 1.6.2.2 thorpej data |= 1;
2891 1.6.2.2 thorpej
2892 1.6.2.2 thorpej trm_wait_30us();
2893 1.6.2.2 thorpej }
2894 1.6.2.2 thorpej /*
2895 1.6.2.2 thorpej * Disable chip select
2896 1.6.2.2 thorpej */
2897 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, 0);
2898 1.6.2.2 thorpej return (data);
2899 1.6.2.2 thorpej }
2900 1.6.2.2 thorpej
2901 1.6.2.2 thorpej /*
2902 1.6.2.2 thorpej * write SB and Op Code into seeprom
2903 1.6.2.2 thorpej */
2904 1.6.2.2 thorpej static void
2905 1.6.2.2 thorpej trm_eeprom_write_cmd(sc, cmd, addr)
2906 1.6.2.2 thorpej struct trm_softc *sc;
2907 1.6.2.2 thorpej u_int8_t cmd;
2908 1.6.2.2 thorpej u_int8_t addr;
2909 1.6.2.2 thorpej {
2910 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
2911 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
2912 1.6.2.2 thorpej int i;
2913 1.6.2.2 thorpej u_int8_t send;
2914 1.6.2.2 thorpej
2915 1.6.2.2 thorpej /* Program SB+OP code */
2916 1.6.2.2 thorpej for (i = 0; i < 3; i++, cmd <<= 1) {
2917 1.6.2.2 thorpej send = NVR_SELECT;
2918 1.6.2.2 thorpej if (cmd & 0x04) /* Start from bit 2 */
2919 1.6.2.2 thorpej send |= NVR_BITOUT;
2920 1.6.2.2 thorpej
2921 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, send);
2922 1.6.2.2 thorpej trm_wait_30us();
2923 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, send | NVR_CLOCK);
2924 1.6.2.2 thorpej trm_wait_30us();
2925 1.6.2.2 thorpej }
2926 1.6.2.2 thorpej
2927 1.6.2.2 thorpej /* Program address */
2928 1.6.2.2 thorpej for (i = 0; i < 7; i++, addr <<= 1) {
2929 1.6.2.2 thorpej send = NVR_SELECT;
2930 1.6.2.2 thorpej if (addr & 0x40) /* Start from bit 6 */
2931 1.6.2.2 thorpej send |= NVR_BITOUT;
2932 1.6.2.2 thorpej
2933 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, send);
2934 1.6.2.2 thorpej trm_wait_30us();
2935 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, send | NVR_CLOCK);
2936 1.6.2.2 thorpej trm_wait_30us();
2937 1.6.2.2 thorpej }
2938 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_GEN_NVRAM, NVR_SELECT);
2939 1.6.2.2 thorpej trm_wait_30us();
2940 1.6.2.2 thorpej }
2941 1.6.2.2 thorpej
2942 1.6.2.2 thorpej /*
2943 1.6.2.2 thorpej * read seeprom 128 bytes to sc_eeprom and check checksum.
2944 1.6.2.2 thorpej * If it is wrong, updated with default value.
2945 1.6.2.2 thorpej */
2946 1.6.2.2 thorpej static void
2947 1.6.2.2 thorpej trm_check_eeprom(sc, eeprom)
2948 1.6.2.2 thorpej struct trm_softc *sc;
2949 1.6.2.2 thorpej struct trm_nvram *eeprom;
2950 1.6.2.2 thorpej {
2951 1.6.2.2 thorpej struct nvram_target *target;
2952 1.6.2.2 thorpej u_int16_t *ep;
2953 1.6.2.2 thorpej u_int16_t chksum;
2954 1.6.2.2 thorpej int i;
2955 1.6.2.2 thorpej
2956 1.6.2.2 thorpej #ifdef TRM_DEBUG
2957 1.6.2.2 thorpej printf("\n trm_check_eeprom......\n");
2958 1.6.2.2 thorpej #endif
2959 1.6.2.2 thorpej trm_eeprom_read_all(sc, eeprom);
2960 1.6.2.2 thorpej ep = (u_int16_t *)eeprom;
2961 1.6.2.2 thorpej chksum = 0;
2962 1.6.2.2 thorpej for (i = 0; i < 64; i++)
2963 1.6.2.2 thorpej chksum += le16toh(*ep++);
2964 1.6.2.2 thorpej
2965 1.6.2.2 thorpej if (chksum != TRM_NVRAM_CKSUM) {
2966 1.6.2.2 thorpej #ifdef TRM_DEBUG
2967 1.6.2.2 thorpej printf("TRM_S1040 EEPROM Check Sum ERROR (load default).\n");
2968 1.6.2.2 thorpej #endif
2969 1.6.2.2 thorpej /*
2970 1.6.2.2 thorpej * Checksum error, load default
2971 1.6.2.2 thorpej */
2972 1.6.2.2 thorpej eeprom->subvendor_id[0] = PCI_VENDOR_TEKRAM2 & 0xFF;
2973 1.6.2.2 thorpej eeprom->subvendor_id[1] = PCI_VENDOR_TEKRAM2 >> 8;
2974 1.6.2.2 thorpej eeprom->subsys_id[0] = PCI_PRODUCT_TEKRAM2_DC315 & 0xFF;
2975 1.6.2.2 thorpej eeprom->subsys_id[1] = PCI_PRODUCT_TEKRAM2_DC315 >> 8;
2976 1.6.2.2 thorpej eeprom->subclass = 0x00;
2977 1.6.2.2 thorpej eeprom->vendor_id[0] = PCI_VENDOR_TEKRAM2 & 0xFF;
2978 1.6.2.2 thorpej eeprom->vendor_id[1] = PCI_VENDOR_TEKRAM2 >> 8;
2979 1.6.2.2 thorpej eeprom->device_id[0] = PCI_PRODUCT_TEKRAM2_DC315 & 0xFF;
2980 1.6.2.2 thorpej eeprom->device_id[1] = PCI_PRODUCT_TEKRAM2_DC315 >> 8;
2981 1.6.2.2 thorpej eeprom->reserved0 = 0x00;
2982 1.6.2.2 thorpej
2983 1.6.2.2 thorpej for (i = 0, target = eeprom->target;
2984 1.6.2.2 thorpej i < TRM_MAX_TARGETS;
2985 1.6.2.2 thorpej i++, target++) {
2986 1.6.2.2 thorpej target->config0 = 0x77;
2987 1.6.2.2 thorpej target->period = 0x00;
2988 1.6.2.2 thorpej target->config2 = 0x00;
2989 1.6.2.2 thorpej target->config3 = 0x00;
2990 1.6.2.2 thorpej }
2991 1.6.2.2 thorpej
2992 1.6.2.2 thorpej eeprom->scsi_id = 7;
2993 1.6.2.2 thorpej eeprom->channel_cfg = 0x0F;
2994 1.6.2.2 thorpej eeprom->delay_time = 0;
2995 1.6.2.2 thorpej eeprom->max_tag = 4;
2996 1.6.2.2 thorpej eeprom->reserved1 = 0x15;
2997 1.6.2.2 thorpej eeprom->boot_target = 0;
2998 1.6.2.2 thorpej eeprom->boot_lun = 0;
2999 1.6.2.2 thorpej eeprom->reserved2 = 0;
3000 1.6.2.2 thorpej memset(eeprom->reserved3, 0, sizeof(eeprom->reserved3));
3001 1.6.2.2 thorpej
3002 1.6.2.2 thorpej chksum = 0;
3003 1.6.2.2 thorpej ep = (u_int16_t *)eeprom;
3004 1.6.2.2 thorpej for (i = 0; i < 63; i++)
3005 1.6.2.2 thorpej chksum += le16toh(*ep++);
3006 1.6.2.2 thorpej
3007 1.6.2.2 thorpej chksum = TRM_NVRAM_CKSUM - chksum;
3008 1.6.2.2 thorpej eeprom->checksum0 = chksum & 0xFF;
3009 1.6.2.2 thorpej eeprom->checksum1 = chksum >> 8;
3010 1.6.2.2 thorpej
3011 1.6.2.2 thorpej trm_eeprom_write_all(sc, eeprom);
3012 1.6.2.2 thorpej }
3013 1.6.2.2 thorpej }
3014 1.6.2.2 thorpej
3015 1.6.2.2 thorpej /*
3016 1.6.2.2 thorpej * initialize the SCSI chip ctrl registers
3017 1.6.2.2 thorpej */
3018 1.6.2.2 thorpej static void
3019 1.6.2.2 thorpej trm_init_adapter(sc)
3020 1.6.2.2 thorpej struct trm_softc *sc;
3021 1.6.2.2 thorpej {
3022 1.6.2.2 thorpej bus_space_tag_t iot = sc->sc_iot;
3023 1.6.2.2 thorpej bus_space_handle_t ioh = sc->sc_ioh;
3024 1.6.2.2 thorpej u_int8_t bval;
3025 1.6.2.2 thorpej
3026 1.6.2.2 thorpej /* program configuration 0 */
3027 1.6.2.2 thorpej bval = PHASELATCH | INITIATOR | BLOCKRST;
3028 1.6.2.2 thorpej if (sc->sc_config & HCC_PARITY)
3029 1.6.2.2 thorpej bval |= PARITYCHECK;
3030 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_CONFIG0, bval);
3031 1.6.2.2 thorpej
3032 1.6.2.2 thorpej /* program configuration 1 */
3033 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_CONFIG1,
3034 1.6.2.2 thorpej ACTIVE_NEG | ACTIVE_NEGPLUS);
3035 1.6.2.2 thorpej
3036 1.6.2.2 thorpej /* 250ms selection timeout */
3037 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_TIMEOUT, SEL_TIMEOUT);
3038 1.6.2.2 thorpej
3039 1.6.2.2 thorpej /* Mask all the interrupt */
3040 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_INTEN, 0);
3041 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_INTEN, 0);
3042 1.6.2.2 thorpej
3043 1.6.2.2 thorpej /* Reset SCSI module */
3044 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_SCSI_CONTROL, DO_RSTMODULE);
3045 1.6.2.2 thorpej
3046 1.6.2.2 thorpej /* program Host ID */
3047 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_HOSTID, sc->sc_id);
3048 1.6.2.2 thorpej
3049 1.6.2.2 thorpej /* set ansynchronous transfer */
3050 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_OFFSET, 0);
3051 1.6.2.2 thorpej
3052 1.6.2.2 thorpej /* Trun LED control off */
3053 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_GEN_CONTROL,
3054 1.6.2.2 thorpej bus_space_read_2(iot, ioh, TRM_GEN_CONTROL) & ~EN_LED);
3055 1.6.2.2 thorpej
3056 1.6.2.2 thorpej /* DMA config */
3057 1.6.2.2 thorpej bus_space_write_2(iot, ioh, TRM_DMA_CONFIG,
3058 1.6.2.2 thorpej bus_space_read_2(iot, ioh, TRM_DMA_CONFIG) | DMA_ENHANCE);
3059 1.6.2.2 thorpej
3060 1.6.2.2 thorpej /* Clear pending interrupt status */
3061 1.6.2.2 thorpej bus_space_read_1(iot, ioh, TRM_SCSI_INTSTATUS);
3062 1.6.2.2 thorpej
3063 1.6.2.2 thorpej /* Enable SCSI interrupt */
3064 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_SCSI_INTEN,
3065 1.6.2.2 thorpej EN_SELECT | EN_SELTIMEOUT | EN_DISCONNECT | EN_RESELECTED |
3066 1.6.2.2 thorpej EN_SCSIRESET | EN_BUSSERVICE | EN_CMDDONE);
3067 1.6.2.2 thorpej bus_space_write_1(iot, ioh, TRM_DMA_INTEN, EN_SCSIINTR);
3068 1.6.2.2 thorpej }
3069 1.6.2.2 thorpej
3070 1.6.2.2 thorpej /*
3071 1.6.2.2 thorpej * initialize the internal structures for a given SCSI host
3072 1.6.2.2 thorpej */
3073 1.6.2.2 thorpej static int
3074 1.6.2.2 thorpej trm_init(sc)
3075 1.6.2.2 thorpej struct trm_softc *sc;
3076 1.6.2.2 thorpej {
3077 1.6.2.2 thorpej bus_dma_segment_t seg;
3078 1.6.2.2 thorpej int error, rseg, all_sgsize;
3079 1.6.2.2 thorpej
3080 1.6.2.2 thorpej /*
3081 1.6.2.2 thorpej * EEPROM CHECKSUM
3082 1.6.2.2 thorpej */
3083 1.6.2.2 thorpej trm_check_eeprom(sc, &sc->sc_eeprom);
3084 1.6.2.2 thorpej /*
3085 1.6.2.2 thorpej * MEMORY ALLOCATE FOR ADAPTER CONTROL BLOCK
3086 1.6.2.2 thorpej * allocate the space for all SCSI control blocks (SRB) for DMA memory
3087 1.6.2.2 thorpej */
3088 1.6.2.2 thorpej all_sgsize = TRM_MAX_SRB * TRM_SG_SIZE;
3089 1.6.2.2 thorpej if ((error = bus_dmamem_alloc(sc->sc_dmat, all_sgsize, PAGE_SIZE,
3090 1.6.2.2 thorpej 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
3091 1.6.2.2 thorpej printf("%s: unable to allocate SCSI REQUEST BLOCKS, "
3092 1.6.2.2 thorpej "error = %d\n", sc->sc_dev.dv_xname, error);
3093 1.6.2.2 thorpej return (-1);
3094 1.6.2.2 thorpej }
3095 1.6.2.2 thorpej if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
3096 1.6.2.2 thorpej all_sgsize, (caddr_t *) &sc->sc_sglist,
3097 1.6.2.2 thorpej BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
3098 1.6.2.2 thorpej printf("%s: unable to map SCSI REQUEST BLOCKS, "
3099 1.6.2.2 thorpej "error = %d\n", sc->sc_dev.dv_xname, error);
3100 1.6.2.2 thorpej return (-1);
3101 1.6.2.2 thorpej }
3102 1.6.2.2 thorpej if ((error = bus_dmamap_create(sc->sc_dmat, all_sgsize, 1,
3103 1.6.2.2 thorpej all_sgsize, 0, BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
3104 1.6.2.2 thorpej printf("%s: unable to create SRB DMA maps, "
3105 1.6.2.2 thorpej "error = %d\n", sc->sc_dev.dv_xname, error);
3106 1.6.2.2 thorpej return (-1);
3107 1.6.2.2 thorpej }
3108 1.6.2.2 thorpej if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap,
3109 1.6.2.2 thorpej sc->sc_sglist, all_sgsize, NULL, BUS_DMA_NOWAIT)) != 0) {
3110 1.6.2.2 thorpej printf("%s: unable to load SRB DMA maps, "
3111 1.6.2.2 thorpej "error = %d\n", sc->sc_dev.dv_xname, error);
3112 1.6.2.2 thorpej return (-1);
3113 1.6.2.2 thorpej }
3114 1.6.2.2 thorpej #ifdef TRM_DEBUG
3115 1.6.2.2 thorpej printf("\n\n%s: all_sgsize=%x\n", sc->sc_dev.dv_xname, all_sgsize);
3116 1.6.2.2 thorpej #endif
3117 1.6.2.2 thorpej memset(sc->sc_sglist, 0, all_sgsize);
3118 1.6.2.2 thorpej trm_init_sc(sc);
3119 1.6.2.2 thorpej trm_init_adapter(sc);
3120 1.6.2.2 thorpej trm_reset(sc);
3121 1.6.2.2 thorpej return (0);
3122 1.6.2.2 thorpej }
3123 1.6.2.2 thorpej
3124 1.6.2.2 thorpej /*
3125 1.6.2.2 thorpej * attach and init a host adapter
3126 1.6.2.2 thorpej */
3127 1.6.2.2 thorpej static void
3128 1.6.2.2 thorpej trm_attach(parent, self, aux)
3129 1.6.2.2 thorpej struct device *parent;
3130 1.6.2.2 thorpej struct device *self;
3131 1.6.2.2 thorpej void *aux;
3132 1.6.2.2 thorpej {
3133 1.6.2.2 thorpej struct pci_attach_args *const pa = aux;
3134 1.6.2.2 thorpej struct trm_softc *sc = (void *) self;
3135 1.6.2.2 thorpej bus_space_tag_t iot; /* bus space tag */
3136 1.6.2.2 thorpej bus_space_handle_t ioh; /* bus space handle */
3137 1.6.2.2 thorpej pci_intr_handle_t ih;
3138 1.6.2.2 thorpej pcireg_t command;
3139 1.6.2.2 thorpej const char *intrstr;
3140 1.6.2.2 thorpej
3141 1.6.2.2 thorpej /*
3142 1.6.2.2 thorpej * These cards do not allow memory mapped accesses
3143 1.6.2.2 thorpej * pa_pc: chipset tag
3144 1.6.2.2 thorpej * pa_tag: pci tag
3145 1.6.2.2 thorpej */
3146 1.6.2.2 thorpej command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
3147 1.6.2.2 thorpej if ((command & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE)) !=
3148 1.6.2.2 thorpej (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE)) {
3149 1.6.2.2 thorpej command |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MASTER_ENABLE;
3150 1.6.2.2 thorpej pci_conf_write(pa->pa_pc, pa->pa_tag,
3151 1.6.2.2 thorpej PCI_COMMAND_STATUS_REG, command);
3152 1.6.2.2 thorpej }
3153 1.6.2.2 thorpej /*
3154 1.6.2.2 thorpej * mask for get correct base address of pci IO port
3155 1.6.2.2 thorpej */
3156 1.6.2.2 thorpej if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
3157 1.6.2.2 thorpej &iot, &ioh, NULL, NULL)) {
3158 1.6.2.2 thorpej printf("%s: unable to map registers\n", sc->sc_dev.dv_xname);
3159 1.6.2.2 thorpej return;
3160 1.6.2.2 thorpej }
3161 1.6.2.2 thorpej /*
3162 1.6.2.2 thorpej * test checksum of eeprom..& initial "ACB" adapter control block...
3163 1.6.2.2 thorpej */
3164 1.6.2.2 thorpej sc->sc_iot = iot;
3165 1.6.2.2 thorpej sc->sc_ioh = ioh;
3166 1.6.2.2 thorpej sc->sc_dmat = pa->pa_dmat;
3167 1.6.2.2 thorpej if (trm_init(sc)) {
3168 1.6.2.2 thorpej /*
3169 1.6.2.2 thorpej * Error during initialization!
3170 1.6.2.2 thorpej */
3171 1.6.2.2 thorpej printf(": Error during initialization\n");
3172 1.6.2.2 thorpej return;
3173 1.6.2.2 thorpej }
3174 1.6.2.2 thorpej /*
3175 1.6.2.2 thorpej * Now try to attach all the sub-devices
3176 1.6.2.2 thorpej */
3177 1.6.2.2 thorpej if (sc->sc_config & HCC_WIDE_CARD)
3178 1.6.2.2 thorpej printf(": Tekram DC395UW/F (TRM-S1040) Fast40 "
3179 1.6.2.2 thorpej "Ultra Wide SCSI Adapter\n");
3180 1.6.2.2 thorpej else
3181 1.6.2.2 thorpej printf(": Tekram DC395U, DC315/U (TRM-S1040) Fast20 "
3182 1.6.2.2 thorpej "Ultra SCSI Adapter\n");
3183 1.6.2.2 thorpej
3184 1.6.2.2 thorpej printf("%s: Adapter ID=%d, Max tag number=%d, %d SCBs\n",
3185 1.6.2.2 thorpej sc->sc_dev.dv_xname, sc->sc_id, sc->maxtag, TRM_MAX_SRB);
3186 1.6.2.2 thorpej /*
3187 1.6.2.2 thorpej * Now tell the generic SCSI layer about our bus.
3188 1.6.2.2 thorpej * map and establish interrupt
3189 1.6.2.2 thorpej */
3190 1.6.2.2 thorpej if (pci_intr_map(pa, &ih)) {
3191 1.6.2.2 thorpej printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
3192 1.6.2.2 thorpej return;
3193 1.6.2.2 thorpej }
3194 1.6.2.2 thorpej intrstr = pci_intr_string(pa->pa_pc, ih);
3195 1.6.2.2 thorpej
3196 1.6.2.2 thorpej if (pci_intr_establish(pa->pa_pc, ih, IPL_BIO, trm_intr, sc) == NULL) {
3197 1.6.2.2 thorpej printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
3198 1.6.2.2 thorpej if (intrstr != NULL)
3199 1.6.2.2 thorpej printf(" at %s", intrstr);
3200 1.6.2.2 thorpej printf("\n");
3201 1.6.2.2 thorpej return;
3202 1.6.2.2 thorpej }
3203 1.6.2.2 thorpej if (intrstr != NULL)
3204 1.6.2.2 thorpej printf("%s: interrupting at %s\n",
3205 1.6.2.2 thorpej sc->sc_dev.dv_xname, intrstr);
3206 1.6.2.2 thorpej config_found(&sc->sc_dev, &sc->sc_channel, scsiprint);
3207 1.6.2.2 thorpej }
3208 1.6.2.2 thorpej
3209 1.6.2.2 thorpej /*
3210 1.6.2.2 thorpej * match pci device
3211 1.6.2.2 thorpej */
3212 1.6.2.2 thorpej static int
3213 1.6.2.2 thorpej trm_probe(parent, match, aux)
3214 1.6.2.2 thorpej struct device *parent;
3215 1.6.2.2 thorpej struct cfdata *match;
3216 1.6.2.2 thorpej void *aux;
3217 1.6.2.2 thorpej {
3218 1.6.2.2 thorpej struct pci_attach_args *pa = aux;
3219 1.6.2.2 thorpej
3220 1.6.2.2 thorpej if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TEKRAM2)
3221 1.6.2.2 thorpej switch (PCI_PRODUCT(pa->pa_id)) {
3222 1.6.2.2 thorpej case PCI_PRODUCT_TEKRAM2_DC315:
3223 1.6.2.2 thorpej return (1);
3224 1.6.2.2 thorpej }
3225 1.6.2.2 thorpej return (0);
3226 1.6.2.2 thorpej }
3227