aic79xx_osm.c revision 1.29 1 1.29 tsutsui /* $NetBSD: aic79xx_osm.c,v 1.29 2009/09/26 14:44:10 tsutsui Exp $ */
2 1.1 fvdl
3 1.1 fvdl /*
4 1.1 fvdl * Bus independent NetBSD shim for the aic7xxx based adaptec SCSI controllers
5 1.1 fvdl *
6 1.1 fvdl * Copyright (c) 1994-2002 Justin T. Gibbs.
7 1.1 fvdl * Copyright (c) 2001-2002 Adaptec Inc.
8 1.1 fvdl * All rights reserved.
9 1.1 fvdl *
10 1.1 fvdl * Redistribution and use in source and binary forms, with or without
11 1.1 fvdl * modification, are permitted provided that the following conditions
12 1.1 fvdl * are met:
13 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
14 1.1 fvdl * notice, this list of conditions, and the following disclaimer,
15 1.1 fvdl * without modification.
16 1.1 fvdl * 2. The name of the author may not be used to endorse or promote products
17 1.1 fvdl * derived from this software without specific prior written permission.
18 1.1 fvdl *
19 1.1 fvdl * Alternatively, this software may be distributed under the terms of the
20 1.1 fvdl * GNU Public License ("GPL").
21 1.1 fvdl *
22 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 1.1 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 1.1 fvdl * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 fvdl * SUCH DAMAGE.
33 1.1 fvdl *
34 1.1 fvdl * //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.c#26 $
35 1.1 fvdl *
36 1.5 thorpej * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.c,v 1.11 2003/05/04 00:20:07 gibbs Exp $
37 1.1 fvdl */
38 1.1 fvdl /*
39 1.1 fvdl * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc.
40 1.1 fvdl * - April 2003
41 1.1 fvdl */
42 1.4 lukem
43 1.4 lukem #include <sys/cdefs.h>
44 1.29 tsutsui __KERNEL_RCSID(0, "$NetBSD: aic79xx_osm.c,v 1.29 2009/09/26 14:44:10 tsutsui Exp $");
45 1.1 fvdl
46 1.1 fvdl #include <dev/ic/aic79xx_osm.h>
47 1.1 fvdl #include <dev/ic/aic79xx_inline.h>
48 1.1 fvdl
49 1.1 fvdl #ifndef AHD_TMODE_ENABLE
50 1.1 fvdl #define AHD_TMODE_ENABLE 0
51 1.1 fvdl #endif
52 1.1 fvdl
53 1.12 perry static int ahd_ioctl(struct scsipi_channel *channel, u_long cmd,
54 1.18 christos void *addr, int flag, struct proc *p);
55 1.12 perry static void ahd_action(struct scsipi_channel *chan,
56 1.1 fvdl scsipi_adapter_req_t req, void *arg);
57 1.1 fvdl static void ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs,
58 1.1 fvdl int nsegments);
59 1.1 fvdl static int ahd_poll(struct ahd_softc *ahd, int wait);
60 1.1 fvdl static void ahd_setup_data(struct ahd_softc *ahd, struct scsipi_xfer *xs,
61 1.1 fvdl struct scb *scb);
62 1.1 fvdl
63 1.1 fvdl #if NOT_YET
64 1.1 fvdl static void ahd_set_recoveryscb(struct ahd_softc *ahd, struct scb *scb);
65 1.1 fvdl #endif
66 1.1 fvdl
67 1.22 tsutsui static bool ahd_pmf_suspend(device_t PMF_FN_PROTO);
68 1.22 tsutsui static bool ahd_pmf_resume(device_t PMF_FN_PROTO);
69 1.22 tsutsui static bool ahd_pmf_shutdown(device_t, int);
70 1.22 tsutsui
71 1.1 fvdl /*
72 1.1 fvdl * Attach all the sub-devices we can find
73 1.1 fvdl */
74 1.1 fvdl int
75 1.1 fvdl ahd_attach(struct ahd_softc *ahd)
76 1.1 fvdl {
77 1.23 tsutsui int s;
78 1.1 fvdl char ahd_info[256];
79 1.1 fvdl
80 1.8 itojun ahd_controller_info(ahd, ahd_info, sizeof(ahd_info));
81 1.26 tsutsui printf("%s: %s\n", ahd_name(ahd), ahd_info);
82 1.1 fvdl
83 1.23 tsutsui ahd_lock(ahd, &s);
84 1.1 fvdl
85 1.29 tsutsui ahd->sc_adapter.adapt_dev = ahd->sc_dev;
86 1.1 fvdl ahd->sc_adapter.adapt_nchannels = 1;
87 1.12 perry
88 1.13 bouyer ahd->sc_adapter.adapt_openings = ahd->scb_data.numscbs - 1;
89 1.1 fvdl ahd->sc_adapter.adapt_max_periph = 32;
90 1.1 fvdl
91 1.1 fvdl ahd->sc_adapter.adapt_ioctl = ahd_ioctl;
92 1.1 fvdl ahd->sc_adapter.adapt_minphys = ahd_minphys;
93 1.1 fvdl ahd->sc_adapter.adapt_request = ahd_action;
94 1.1 fvdl
95 1.1 fvdl ahd->sc_channel.chan_adapter = &ahd->sc_adapter;
96 1.23 tsutsui ahd->sc_channel.chan_bustype = &scsi_bustype;
97 1.23 tsutsui ahd->sc_channel.chan_channel = 0;
98 1.23 tsutsui ahd->sc_channel.chan_ntargets = AHD_NUM_TARGETS;
99 1.23 tsutsui ahd->sc_channel.chan_nluns = 8 /*AHD_NUM_LUNS*/;
100 1.23 tsutsui ahd->sc_channel.chan_id = ahd->our_id;
101 1.23 tsutsui ahd->sc_channel.chan_flags |= SCSIPI_CHAN_CANGROW;
102 1.1 fvdl
103 1.29 tsutsui ahd->sc_child = config_found(ahd->sc_dev, &ahd->sc_channel, scsiprint);
104 1.1 fvdl
105 1.1 fvdl ahd_intr_enable(ahd, TRUE);
106 1.1 fvdl
107 1.3 fvdl if (ahd->flags & AHD_RESET_BUS_A)
108 1.3 fvdl ahd_reset_channel(ahd, 'A', TRUE);
109 1.3 fvdl
110 1.29 tsutsui if (!pmf_device_register1(ahd->sc_dev,
111 1.22 tsutsui ahd_pmf_suspend, ahd_pmf_resume, ahd_pmf_shutdown))
112 1.29 tsutsui aprint_error_dev(ahd->sc_dev,
113 1.22 tsutsui "couldn't establish power handler\n");
114 1.22 tsutsui
115 1.23 tsutsui ahd_unlock(ahd, &s);
116 1.1 fvdl
117 1.1 fvdl return (1);
118 1.1 fvdl }
119 1.1 fvdl
120 1.22 tsutsui static bool
121 1.22 tsutsui ahd_pmf_suspend(device_t dev PMF_FN_ARGS)
122 1.22 tsutsui {
123 1.22 tsutsui struct ahd_softc *sc = device_private(dev);
124 1.22 tsutsui #if 0
125 1.22 tsutsui return (ahd_suspend(sc) == 0);
126 1.22 tsutsui #else
127 1.22 tsutsui ahd_shutdown(sc);
128 1.22 tsutsui return true;
129 1.22 tsutsui #endif
130 1.22 tsutsui }
131 1.22 tsutsui
132 1.22 tsutsui static bool
133 1.22 tsutsui ahd_pmf_resume(device_t dev PMF_FN_ARGS)
134 1.22 tsutsui {
135 1.22 tsutsui #if 0
136 1.22 tsutsui struct ahd_softc *sc = device_private(dev);
137 1.22 tsutsui
138 1.22 tsutsui return (ahd_resume(sc) == 0);
139 1.22 tsutsui #else
140 1.22 tsutsui return true;
141 1.22 tsutsui #endif
142 1.22 tsutsui }
143 1.22 tsutsui
144 1.22 tsutsui static bool
145 1.22 tsutsui ahd_pmf_shutdown(device_t dev, int howto)
146 1.22 tsutsui {
147 1.22 tsutsui struct ahd_softc *sc = device_private(dev);
148 1.22 tsutsui
149 1.22 tsutsui /* Disable all interrupt sources by resetting the controller */
150 1.22 tsutsui ahd_shutdown(sc);
151 1.22 tsutsui
152 1.22 tsutsui return true;
153 1.22 tsutsui }
154 1.22 tsutsui
155 1.1 fvdl static int
156 1.12 perry ahd_ioctl(struct scsipi_channel *channel, u_long cmd,
157 1.18 christos void *addr, int flag, struct proc *p)
158 1.1 fvdl {
159 1.27 tsutsui struct ahd_softc *ahd;
160 1.23 tsutsui int s, ret = ENOTTY;
161 1.1 fvdl
162 1.27 tsutsui ahd = device_private(channel->chan_adapter->adapt_dev);
163 1.27 tsutsui
164 1.23 tsutsui switch (cmd) {
165 1.23 tsutsui case SCBUSIORESET:
166 1.23 tsutsui s = splbio();
167 1.23 tsutsui ahd_reset_channel(ahd, channel->chan_channel == 1 ? 'B' : 'A', TRUE);
168 1.23 tsutsui splx(s);
169 1.23 tsutsui ret = 0;
170 1.23 tsutsui break;
171 1.23 tsutsui default:
172 1.23 tsutsui break;
173 1.23 tsutsui }
174 1.1 fvdl
175 1.23 tsutsui return ret;
176 1.1 fvdl }
177 1.1 fvdl
178 1.1 fvdl /*
179 1.1 fvdl * Catch an interrupt from the adapter
180 1.1 fvdl */
181 1.1 fvdl void
182 1.1 fvdl ahd_platform_intr(void *arg)
183 1.1 fvdl {
184 1.1 fvdl struct ahd_softc *ahd;
185 1.12 perry
186 1.25 tsutsui ahd = arg;
187 1.1 fvdl
188 1.1 fvdl printf("%s; ahd_platform_intr\n", ahd_name(ahd));
189 1.1 fvdl
190 1.1 fvdl ahd_intr(ahd);
191 1.1 fvdl }
192 1.1 fvdl
193 1.1 fvdl /*
194 1.1 fvdl * We have an scb which has been processed by the
195 1.1 fvdl * adaptor, now we look to see how the operation * went.
196 1.1 fvdl */
197 1.1 fvdl void
198 1.1 fvdl ahd_done(struct ahd_softc *ahd, struct scb *scb)
199 1.1 fvdl {
200 1.1 fvdl struct scsipi_xfer *xs;
201 1.1 fvdl struct scsipi_periph *periph;
202 1.1 fvdl int s;
203 1.1 fvdl
204 1.1 fvdl LIST_REMOVE(scb, pending_links);
205 1.1 fvdl
206 1.1 fvdl xs = scb->xs;
207 1.1 fvdl periph = xs->xs_periph;
208 1.1 fvdl
209 1.1 fvdl callout_stop(&scb->xs->xs_callout);
210 1.1 fvdl
211 1.1 fvdl if (xs->datalen) {
212 1.1 fvdl int op;
213 1.1 fvdl
214 1.1 fvdl if (xs->xs_control & XS_CTL_DATA_IN)
215 1.23 tsutsui op = BUS_DMASYNC_POSTREAD;
216 1.1 fvdl else
217 1.23 tsutsui op = BUS_DMASYNC_POSTWRITE;
218 1.1 fvdl
219 1.1 fvdl bus_dmamap_sync(ahd->parent_dmat, scb->dmamap, 0,
220 1.1 fvdl scb->dmamap->dm_mapsize, op);
221 1.23 tsutsui bus_dmamap_unload(ahd->parent_dmat, scb->dmamap);
222 1.23 tsutsui }
223 1.1 fvdl
224 1.1 fvdl /*
225 1.1 fvdl * If the recovery SCB completes, we have to be
226 1.1 fvdl * out of our timeout.
227 1.1 fvdl */
228 1.1 fvdl if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
229 1.1 fvdl struct scb *list_scb;
230 1.1 fvdl
231 1.1 fvdl /*
232 1.1 fvdl * We were able to complete the command successfully,
233 1.1 fvdl * so reinstate the timeouts for all other pending
234 1.1 fvdl * commands.
235 1.1 fvdl */
236 1.1 fvdl LIST_FOREACH(list_scb, &ahd->pending_scbs, pending_links) {
237 1.1 fvdl struct scsipi_xfer *txs = list_scb->xs;
238 1.12 perry
239 1.1 fvdl if (!(txs->xs_control & XS_CTL_POLL)) {
240 1.23 tsutsui callout_reset(&txs->xs_callout,
241 1.23 tsutsui (txs->timeout > 1000000) ?
242 1.23 tsutsui (txs->timeout / 1000) * hz :
243 1.23 tsutsui (txs->timeout * hz) / 1000,
244 1.23 tsutsui ahd_timeout, list_scb);
245 1.23 tsutsui }
246 1.1 fvdl }
247 1.1 fvdl
248 1.1 fvdl if (ahd_get_transaction_status(scb) != XS_NOERROR)
249 1.23 tsutsui ahd_set_transaction_status(scb, XS_TIMEOUT);
250 1.23 tsutsui scsipi_printaddr(xs->xs_periph);
251 1.12 perry printf("%s: no longer in timeout, status = %x\n",
252 1.1 fvdl ahd_name(ahd), xs->status);
253 1.1 fvdl }
254 1.1 fvdl
255 1.1 fvdl if (xs->error != XS_NOERROR) {
256 1.23 tsutsui /* Don't clobber any existing error state */
257 1.1 fvdl } else if ((xs->status == SCSI_STATUS_BUSY) ||
258 1.1 fvdl (xs->status == SCSI_STATUS_QUEUE_FULL)) {
259 1.23 tsutsui ahd_set_transaction_status(scb, XS_BUSY);
260 1.12 perry printf("%s: drive (ID %d, LUN %d) queue full (SCB 0x%x)\n",
261 1.1 fvdl ahd_name(ahd), SCB_GET_TARGET(ahd,scb), SCB_GET_LUN(scb), SCB_GET_TAG(scb));
262 1.23 tsutsui } else if ((scb->flags & SCB_SENSE) != 0) {
263 1.23 tsutsui /*
264 1.23 tsutsui * We performed autosense retrieval.
265 1.23 tsutsui *
266 1.23 tsutsui * zero the sense data before having
267 1.23 tsutsui * the drive fill it. The SCSI spec mandates
268 1.23 tsutsui * that any untransferred data should be
269 1.23 tsutsui * assumed to be zero. Complete the 'bounce'
270 1.23 tsutsui * of sense information through buffers accessible
271 1.23 tsutsui * via bus-space by copying it into the clients
272 1.23 tsutsui * csio.
273 1.23 tsutsui */
274 1.23 tsutsui memset(&xs->sense.scsi_sense, 0, sizeof(xs->sense.scsi_sense));
275 1.23 tsutsui memcpy(&xs->sense.scsi_sense, ahd_get_sense_buf(ahd, scb),
276 1.11 thorpej sizeof(struct scsi_sense_data));
277 1.12 perry
278 1.23 tsutsui ahd_set_transaction_status(scb, XS_SENSE);
279 1.23 tsutsui } else if ((scb->flags & SCB_PKT_SENSE) != 0) {
280 1.1 fvdl struct scsi_status_iu_header *siu;
281 1.1 fvdl u_int sense_len;
282 1.9 fvdl #ifdef AHD_DEBUG
283 1.1 fvdl int i;
284 1.9 fvdl #endif
285 1.1 fvdl /*
286 1.1 fvdl * Copy only the sense data into the provided buffer.
287 1.1 fvdl */
288 1.1 fvdl siu = (struct scsi_status_iu_header *)scb->sense_data;
289 1.1 fvdl sense_len = MIN(scsi_4btoul(siu->sense_length),
290 1.10 fvdl sizeof(xs->sense.scsi_sense));
291 1.1 fvdl memset(&xs->sense.scsi_sense, 0, sizeof(xs->sense.scsi_sense));
292 1.12 perry memcpy(&xs->sense.scsi_sense,
293 1.1 fvdl scb->sense_data + SIU_SENSE_OFFSET(siu), sense_len);
294 1.9 fvdl #ifdef AHD_DEBUG
295 1.1 fvdl printf("Copied %d bytes of sense data offset %d:", sense_len,
296 1.1 fvdl SIU_SENSE_OFFSET(siu));
297 1.1 fvdl for (i = 0; i < sense_len; i++)
298 1.1 fvdl printf(" 0x%x", ((uint8_t *)&xs->sense.scsi_sense)[i]);
299 1.1 fvdl printf("\n");
300 1.9 fvdl #endif
301 1.23 tsutsui ahd_set_transaction_status(scb, XS_SENSE);
302 1.1 fvdl }
303 1.1 fvdl
304 1.1 fvdl if (scb->flags & SCB_FREEZE_QUEUE) {
305 1.23 tsutsui scsipi_periph_thaw(periph, 1);
306 1.23 tsutsui scb->flags &= ~SCB_FREEZE_QUEUE;
307 1.23 tsutsui }
308 1.1 fvdl
309 1.23 tsutsui if (scb->flags & SCB_REQUEUE)
310 1.23 tsutsui ahd_set_transaction_status(scb, XS_REQUEUE);
311 1.23 tsutsui
312 1.23 tsutsui ahd_lock(ahd, &s);
313 1.23 tsutsui ahd_free_scb(ahd, scb);
314 1.23 tsutsui ahd_unlock(ahd, &s);
315 1.23 tsutsui
316 1.23 tsutsui scsipi_done(xs);
317 1.1 fvdl }
318 1.1 fvdl
319 1.1 fvdl static void
320 1.1 fvdl ahd_action(struct scsipi_channel *chan, scsipi_adapter_req_t req, void *arg)
321 1.1 fvdl {
322 1.23 tsutsui struct ahd_softc *ahd;
323 1.1 fvdl struct ahd_initiator_tinfo *tinfo;
324 1.1 fvdl struct ahd_tmode_tstate *tstate;
325 1.1 fvdl
326 1.27 tsutsui ahd = device_private(chan->chan_adapter->adapt_dev);
327 1.1 fvdl
328 1.1 fvdl switch(req) {
329 1.1 fvdl
330 1.1 fvdl case ADAPTER_REQ_RUN_XFER:
331 1.1 fvdl {
332 1.1 fvdl struct scsipi_xfer *xs;
333 1.23 tsutsui struct scsipi_periph *periph;
334 1.23 tsutsui struct scb *scb;
335 1.23 tsutsui struct hardware_scb *hscb;
336 1.1 fvdl u_int target_id;
337 1.1 fvdl u_int our_id;
338 1.1 fvdl u_int col_idx;
339 1.1 fvdl char channel;
340 1.1 fvdl int s;
341 1.1 fvdl
342 1.23 tsutsui xs = arg;
343 1.23 tsutsui periph = xs->xs_periph;
344 1.1 fvdl
345 1.23 tsutsui SC_DEBUG(periph, SCSIPI_DB3, ("ahd_action\n"));
346 1.1 fvdl
347 1.1 fvdl target_id = periph->periph_target;
348 1.23 tsutsui our_id = ahd->our_id;
349 1.23 tsutsui channel = (chan->chan_channel == 1) ? 'B' : 'A';
350 1.1 fvdl
351 1.23 tsutsui /*
352 1.1 fvdl * get an scb to use.
353 1.1 fvdl */
354 1.1 fvdl ahd_lock(ahd, &s);
355 1.1 fvdl tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
356 1.1 fvdl target_id, &tstate);
357 1.1 fvdl
358 1.6 fvdl if (xs->xs_tag_type != 0 ||
359 1.6 fvdl (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
360 1.6 fvdl col_idx = AHD_NEVER_COL_IDX;
361 1.6 fvdl else
362 1.6 fvdl col_idx = AHD_BUILD_COL_IDX(target_id,
363 1.6 fvdl periph->periph_lun);
364 1.1 fvdl
365 1.1 fvdl if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
366 1.1 fvdl xs->error = XS_RESOURCE_SHORTAGE;
367 1.1 fvdl ahd_unlock(ahd, &s);
368 1.1 fvdl scsipi_done(xs);
369 1.1 fvdl return;
370 1.1 fvdl }
371 1.1 fvdl ahd_unlock(ahd, &s);
372 1.1 fvdl
373 1.1 fvdl hscb = scb->hscb;
374 1.1 fvdl
375 1.1 fvdl SC_DEBUG(periph, SCSIPI_DB3, ("start scb(%p)\n", scb));
376 1.1 fvdl scb->xs = xs;
377 1.1 fvdl
378 1.1 fvdl /*
379 1.1 fvdl * Put all the arguments for the xfer in the scb
380 1.1 fvdl */
381 1.1 fvdl hscb->control = 0;
382 1.1 fvdl hscb->scsiid = BUILD_SCSIID(ahd, sim, target_id, our_id);
383 1.1 fvdl hscb->lun = periph->periph_lun;
384 1.1 fvdl if (xs->xs_control & XS_CTL_RESET) {
385 1.1 fvdl hscb->cdb_len = 0;
386 1.1 fvdl scb->flags |= SCB_DEVICE_RESET;
387 1.1 fvdl hscb->control |= MK_MESSAGE;
388 1.1 fvdl hscb->task_management = SIU_TASKMGMT_LUN_RESET;
389 1.1 fvdl ahd_execute_scb(scb, NULL, 0);
390 1.1 fvdl } else {
391 1.1 fvdl hscb->task_management = 0;
392 1.1 fvdl }
393 1.1 fvdl
394 1.1 fvdl ahd_setup_data(ahd, xs, scb);
395 1.1 fvdl break;
396 1.1 fvdl }
397 1.1 fvdl
398 1.1 fvdl case ADAPTER_REQ_GROW_RESOURCES:
399 1.14 bouyer #ifdef AHC_DEBUG
400 1.1 fvdl printf("%s: ADAPTER_REQ_GROW_RESOURCES\n", ahd_name(ahd));
401 1.14 bouyer #endif
402 1.13 bouyer chan->chan_adapter->adapt_openings += ahd_alloc_scbs(ahd);
403 1.13 bouyer if (ahd->scb_data.numscbs >= AHD_SCB_MAX_ALLOC)
404 1.13 bouyer chan->chan_flags &= ~SCSIPI_CHAN_CANGROW;
405 1.1 fvdl break;
406 1.1 fvdl
407 1.1 fvdl case ADAPTER_REQ_SET_XFER_MODE:
408 1.1 fvdl {
409 1.1 fvdl struct scsipi_xfer_mode *xm = arg;
410 1.1 fvdl struct ahd_devinfo devinfo;
411 1.1 fvdl int target_id, our_id, first;
412 1.1 fvdl u_int width;
413 1.1 fvdl int s;
414 1.1 fvdl char channel;
415 1.15 bouyer u_int ppr_options = 0, period, offset;
416 1.6 fvdl uint16_t old_autoneg;
417 1.1 fvdl
418 1.12 perry target_id = xm->xm_target;
419 1.1 fvdl our_id = chan->chan_id;
420 1.1 fvdl channel = 'A';
421 1.1 fvdl s = splbio();
422 1.1 fvdl tinfo = ahd_fetch_transinfo(ahd, channel, our_id, target_id,
423 1.1 fvdl &tstate);
424 1.1 fvdl ahd_compile_devinfo(&devinfo, our_id, target_id,
425 1.1 fvdl 0, channel, ROLE_INITIATOR);
426 1.1 fvdl
427 1.6 fvdl old_autoneg = tstate->auto_negotiate;
428 1.6 fvdl
429 1.1 fvdl /*
430 1.1 fvdl * XXX since the period and offset are not provided here,
431 1.1 fvdl * fake things by forcing a renegotiation using the user
432 1.1 fvdl * settings if this is called for the first time (i.e.
433 1.1 fvdl * during probe). Also, cap various values at the user
434 1.1 fvdl * values, assuming that the user set it up that way.
435 1.1 fvdl */
436 1.1 fvdl if (ahd->inited_target[target_id] == 0) {
437 1.6 fvdl period = tinfo->user.period;
438 1.6 fvdl offset = tinfo->user.offset;
439 1.6 fvdl ppr_options = tinfo->user.ppr_options;
440 1.6 fvdl width = tinfo->user.width;
441 1.1 fvdl tstate->tagenable |=
442 1.1 fvdl (ahd->user_tagenable & devinfo.target_mask);
443 1.1 fvdl tstate->discenable |=
444 1.1 fvdl (ahd->user_discenable & devinfo.target_mask);
445 1.1 fvdl ahd->inited_target[target_id] = 1;
446 1.1 fvdl first = 1;
447 1.1 fvdl } else
448 1.1 fvdl first = 0;
449 1.1 fvdl
450 1.2 fvdl if (xm->xm_mode & (PERIPH_CAP_WIDE16 | PERIPH_CAP_DT))
451 1.1 fvdl width = MSG_EXT_WDTR_BUS_16_BIT;
452 1.1 fvdl else
453 1.1 fvdl width = MSG_EXT_WDTR_BUS_8_BIT;
454 1.1 fvdl
455 1.1 fvdl ahd_validate_width(ahd, NULL, &width, ROLE_UNKNOWN);
456 1.1 fvdl if (width > tinfo->user.width)
457 1.1 fvdl width = tinfo->user.width;
458 1.6 fvdl ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
459 1.1 fvdl
460 1.2 fvdl if (!(xm->xm_mode & (PERIPH_CAP_SYNC | PERIPH_CAP_DT))) {
461 1.6 fvdl period = 0;
462 1.6 fvdl offset = 0;
463 1.6 fvdl ppr_options = 0;
464 1.1 fvdl }
465 1.1 fvdl
466 1.1 fvdl if ((xm->xm_mode & PERIPH_CAP_DT) &&
467 1.1 fvdl (tinfo->user.ppr_options & MSG_EXT_PPR_DT_REQ))
468 1.6 fvdl ppr_options |= MSG_EXT_PPR_DT_REQ;
469 1.1 fvdl else
470 1.6 fvdl ppr_options &= ~MSG_EXT_PPR_DT_REQ;
471 1.6 fvdl
472 1.6 fvdl if ((tstate->discenable & devinfo.target_mask) == 0 ||
473 1.6 fvdl (tstate->tagenable & devinfo.target_mask) == 0)
474 1.6 fvdl ppr_options &= ~MSG_EXT_PPR_IU_REQ;
475 1.1 fvdl
476 1.1 fvdl if ((xm->xm_mode & PERIPH_CAP_TQING) &&
477 1.1 fvdl (ahd->user_tagenable & devinfo.target_mask))
478 1.1 fvdl tstate->tagenable |= devinfo.target_mask;
479 1.1 fvdl else
480 1.1 fvdl tstate->tagenable &= ~devinfo.target_mask;
481 1.1 fvdl
482 1.6 fvdl ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX);
483 1.6 fvdl ahd_validate_offset(ahd, NULL, period, &offset,
484 1.6 fvdl MSG_EXT_WDTR_BUS_8_BIT, ROLE_UNKNOWN);
485 1.6 fvdl if (offset == 0) {
486 1.6 fvdl period = 0;
487 1.6 fvdl ppr_options = 0;
488 1.6 fvdl }
489 1.6 fvdl if (ppr_options != 0
490 1.6 fvdl && tinfo->user.transport_version >= 3) {
491 1.6 fvdl tinfo->goal.transport_version =
492 1.6 fvdl tinfo->user.transport_version;
493 1.6 fvdl tinfo->curr.transport_version =
494 1.6 fvdl tinfo->user.transport_version;
495 1.6 fvdl }
496 1.6 fvdl
497 1.6 fvdl ahd_set_syncrate(ahd, &devinfo, period, offset,
498 1.6 fvdl ppr_options, AHD_TRANS_GOAL, FALSE);
499 1.6 fvdl
500 1.1 fvdl /*
501 1.1 fvdl * If this is the first request, and no negotiation is
502 1.1 fvdl * needed, just confirm the state to the scsipi layer,
503 1.1 fvdl * so that it can print a message.
504 1.1 fvdl */
505 1.6 fvdl if (old_autoneg == tstate->auto_negotiate && first) {
506 1.6 fvdl xm->xm_mode = 0;
507 1.6 fvdl xm->xm_period = tinfo->curr.period;
508 1.6 fvdl xm->xm_offset = tinfo->curr.offset;
509 1.6 fvdl if (tinfo->curr.width == MSG_EXT_WDTR_BUS_16_BIT)
510 1.6 fvdl xm->xm_mode |= PERIPH_CAP_WIDE16;
511 1.6 fvdl if (tinfo->curr.period)
512 1.6 fvdl xm->xm_mode |= PERIPH_CAP_SYNC;
513 1.6 fvdl if (tstate->tagenable & devinfo.target_mask)
514 1.6 fvdl xm->xm_mode |= PERIPH_CAP_TQING;
515 1.6 fvdl if (tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ)
516 1.6 fvdl xm->xm_mode |= PERIPH_CAP_DT;
517 1.1 fvdl scsipi_async_event(chan, ASYNC_EVENT_XFER_MODE, xm);
518 1.6 fvdl }
519 1.1 fvdl splx(s);
520 1.1 fvdl }
521 1.1 fvdl }
522 1.12 perry
523 1.1 fvdl return;
524 1.1 fvdl }
525 1.1 fvdl
526 1.1 fvdl static void
527 1.1 fvdl ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments)
528 1.1 fvdl {
529 1.1 fvdl struct scb *scb;
530 1.1 fvdl struct scsipi_xfer *xs;
531 1.23 tsutsui struct ahd_softc *ahd;
532 1.1 fvdl struct ahd_initiator_tinfo *tinfo;
533 1.1 fvdl struct ahd_tmode_tstate *tstate;
534 1.1 fvdl u_int mask;
535 1.23 tsutsui int s;
536 1.1 fvdl
537 1.25 tsutsui scb = arg;
538 1.1 fvdl xs = scb->xs;
539 1.1 fvdl xs->error = 0;
540 1.1 fvdl xs->status = 0;
541 1.1 fvdl xs->xs_status = 0;
542 1.27 tsutsui ahd = device_private(
543 1.27 tsutsui xs->xs_periph->periph_channel->chan_adapter->adapt_dev);
544 1.1 fvdl
545 1.1 fvdl scb->sg_count = 0;
546 1.1 fvdl if (nsegments != 0) {
547 1.1 fvdl void *sg;
548 1.1 fvdl int op;
549 1.1 fvdl u_int i;
550 1.1 fvdl
551 1.1 fvdl ahd_setup_data_scb(ahd, scb);
552 1.1 fvdl
553 1.1 fvdl /* Copy the segments into our SG list */
554 1.1 fvdl for (i = nsegments, sg = scb->sg_list; i > 0; i--) {
555 1.1 fvdl
556 1.1 fvdl sg = ahd_sg_setup(ahd, scb, sg, dm_segs->ds_addr,
557 1.1 fvdl dm_segs->ds_len,
558 1.1 fvdl /*last*/i == 1);
559 1.1 fvdl dm_segs++;
560 1.1 fvdl }
561 1.12 perry
562 1.1 fvdl if (xs->xs_control & XS_CTL_DATA_IN)
563 1.1 fvdl op = BUS_DMASYNC_PREREAD;
564 1.1 fvdl else
565 1.1 fvdl op = BUS_DMASYNC_PREWRITE;
566 1.1 fvdl
567 1.12 perry bus_dmamap_sync(ahd->parent_dmat, scb->dmamap, 0,
568 1.1 fvdl scb->dmamap->dm_mapsize, op);
569 1.1 fvdl }
570 1.1 fvdl
571 1.1 fvdl ahd_lock(ahd, &s);
572 1.1 fvdl
573 1.1 fvdl /*
574 1.1 fvdl * Last time we need to check if this SCB needs to
575 1.1 fvdl * be aborted.
576 1.1 fvdl */
577 1.1 fvdl if (ahd_get_scsi_status(scb) == XS_STS_DONE) {
578 1.1 fvdl if (nsegments != 0)
579 1.1 fvdl bus_dmamap_unload(ahd->parent_dmat,
580 1.1 fvdl scb->dmamap);
581 1.1 fvdl ahd_free_scb(ahd, scb);
582 1.1 fvdl ahd_unlock(ahd, &s);
583 1.1 fvdl return;
584 1.1 fvdl }
585 1.1 fvdl
586 1.1 fvdl tinfo = ahd_fetch_transinfo(ahd, SCSIID_CHANNEL(ahd, scb->hscb->scsiid),
587 1.1 fvdl SCSIID_OUR_ID(scb->hscb->scsiid),
588 1.1 fvdl SCSIID_TARGET(ahd, scb->hscb->scsiid),
589 1.1 fvdl &tstate);
590 1.1 fvdl
591 1.1 fvdl mask = SCB_GET_TARGET_MASK(ahd, scb);
592 1.1 fvdl
593 1.1 fvdl if ((tstate->discenable & mask) != 0)
594 1.1 fvdl scb->hscb->control |= DISCENB;
595 1.1 fvdl
596 1.1 fvdl if ((tstate->tagenable & mask) != 0)
597 1.1 fvdl scb->hscb->control |= xs->xs_tag_type|TAG_ENB;
598 1.1 fvdl
599 1.1 fvdl if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU) != 0) {
600 1.1 fvdl scb->flags |= SCB_PACKETIZED;
601 1.1 fvdl if (scb->hscb->task_management != 0)
602 1.1 fvdl scb->hscb->control &= ~MK_MESSAGE;
603 1.1 fvdl }
604 1.1 fvdl
605 1.6 fvdl #if 0 /* This looks like it makes sense at first, but it can loop */
606 1.1 fvdl if ((xs->xs_control & XS_CTL_DISCOVERY) &&
607 1.1 fvdl (tinfo->goal.width != 0
608 1.1 fvdl || tinfo->goal.period != 0
609 1.1 fvdl || tinfo->goal.ppr_options != 0)) {
610 1.1 fvdl scb->flags |= SCB_NEGOTIATE;
611 1.1 fvdl scb->hscb->control |= MK_MESSAGE;
612 1.6 fvdl } else
613 1.6 fvdl #endif
614 1.6 fvdl if ((tstate->auto_negotiate & mask) != 0) {
615 1.23 tsutsui scb->flags |= SCB_AUTO_NEGOTIATE;
616 1.1 fvdl scb->hscb->control |= MK_MESSAGE;
617 1.1 fvdl }
618 1.1 fvdl
619 1.1 fvdl LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
620 1.1 fvdl
621 1.1 fvdl scb->flags |= SCB_ACTIVE;
622 1.1 fvdl
623 1.1 fvdl if (!(xs->xs_control & XS_CTL_POLL)) {
624 1.1 fvdl callout_reset(&scb->xs->xs_callout, xs->timeout > 1000000 ?
625 1.1 fvdl (xs->timeout / 1000) * hz : (xs->timeout * hz) / 1000,
626 1.1 fvdl ahd_timeout, scb);
627 1.1 fvdl }
628 1.1 fvdl
629 1.1 fvdl if ((scb->flags & SCB_TARGET_IMMEDIATE) != 0) {
630 1.1 fvdl /* Define a mapping from our tag to the SCB. */
631 1.1 fvdl ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb;
632 1.1 fvdl ahd_pause(ahd);
633 1.1 fvdl ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
634 1.1 fvdl ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
635 1.1 fvdl ahd_unpause(ahd);
636 1.1 fvdl } else {
637 1.1 fvdl ahd_queue_scb(ahd, scb);
638 1.1 fvdl }
639 1.1 fvdl
640 1.1 fvdl if (!(xs->xs_control & XS_CTL_POLL)) {
641 1.23 tsutsui ahd_unlock(ahd, &s);
642 1.23 tsutsui return;
643 1.23 tsutsui }
644 1.23 tsutsui /*
645 1.23 tsutsui * If we can't use interrupts, poll for completion
646 1.23 tsutsui */
647 1.23 tsutsui SC_DEBUG(xs->xs_periph, SCSIPI_DB3, ("cmd_poll\n"));
648 1.23 tsutsui do {
649 1.23 tsutsui if (ahd_poll(ahd, xs->timeout)) {
650 1.23 tsutsui if (!(xs->xs_control & XS_CTL_SILENT))
651 1.23 tsutsui printf("cmd fail\n");
652 1.23 tsutsui ahd_timeout(scb);
653 1.23 tsutsui break;
654 1.23 tsutsui }
655 1.23 tsutsui } while (!(xs->xs_status & XS_STS_DONE));
656 1.1 fvdl
657 1.1 fvdl ahd_unlock(ahd, &s);
658 1.1 fvdl }
659 1.1 fvdl
660 1.1 fvdl static int
661 1.1 fvdl ahd_poll(struct ahd_softc *ahd, int wait)
662 1.1 fvdl {
663 1.1 fvdl
664 1.1 fvdl while (--wait) {
665 1.23 tsutsui DELAY(1000);
666 1.23 tsutsui if (ahd_inb(ahd, INTSTAT) & INT_PEND)
667 1.23 tsutsui break;
668 1.23 tsutsui }
669 1.23 tsutsui
670 1.23 tsutsui if (wait == 0) {
671 1.23 tsutsui printf("%s: board is not responding\n", ahd_name(ahd));
672 1.23 tsutsui return (EIO);
673 1.23 tsutsui }
674 1.1 fvdl
675 1.25 tsutsui ahd_intr(ahd);
676 1.23 tsutsui return (0);
677 1.1 fvdl }
678 1.1 fvdl
679 1.1 fvdl
680 1.1 fvdl static void
681 1.1 fvdl ahd_setup_data(struct ahd_softc *ahd, struct scsipi_xfer *xs,
682 1.1 fvdl struct scb *scb)
683 1.1 fvdl {
684 1.1 fvdl struct hardware_scb *hscb;
685 1.1 fvdl
686 1.1 fvdl hscb = scb->hscb;
687 1.1 fvdl xs->resid = xs->status = 0;
688 1.1 fvdl
689 1.1 fvdl hscb->cdb_len = xs->cmdlen;
690 1.1 fvdl if (hscb->cdb_len > MAX_CDB_LEN) {
691 1.1 fvdl int s;
692 1.1 fvdl /*
693 1.1 fvdl * Should CAM start to support CDB sizes
694 1.1 fvdl * greater than 16 bytes, we could use
695 1.1 fvdl * the sense buffer to store the CDB.
696 1.1 fvdl */
697 1.12 perry ahd_set_transaction_status(scb,
698 1.1 fvdl XS_DRIVER_STUFFUP);
699 1.1 fvdl
700 1.1 fvdl ahd_lock(ahd, &s);
701 1.1 fvdl ahd_free_scb(ahd, scb);
702 1.1 fvdl ahd_unlock(ahd, &s);
703 1.1 fvdl scsipi_done(xs);
704 1.1 fvdl }
705 1.1 fvdl memcpy(hscb->shared_data.idata.cdb, xs->cmd, hscb->cdb_len);
706 1.12 perry
707 1.1 fvdl /* Only use S/G if there is a transfer */
708 1.23 tsutsui if (xs->datalen) {
709 1.23 tsutsui int error;
710 1.1 fvdl
711 1.23 tsutsui error = bus_dmamap_load(ahd->parent_dmat,
712 1.1 fvdl scb->dmamap, xs->data,
713 1.1 fvdl xs->datalen, NULL,
714 1.1 fvdl ((xs->xs_control & XS_CTL_NOSLEEP) ?
715 1.1 fvdl BUS_DMA_NOWAIT : BUS_DMA_WAITOK) |
716 1.1 fvdl BUS_DMA_STREAMING |
717 1.1 fvdl ((xs->xs_control & XS_CTL_DATA_IN) ?
718 1.1 fvdl BUS_DMA_READ : BUS_DMA_WRITE));
719 1.23 tsutsui if (error) {
720 1.1 fvdl #ifdef AHD_DEBUG
721 1.24 tsutsui printf("%s: in ahd_setup_data(): bus_dmamap_load() "
722 1.1 fvdl "= %d\n",
723 1.1 fvdl ahd_name(ahd), error);
724 1.1 fvdl #endif
725 1.23 tsutsui xs->error = XS_RESOURCE_SHORTAGE;
726 1.23 tsutsui scsipi_done(xs);
727 1.23 tsutsui return;
728 1.23 tsutsui }
729 1.23 tsutsui ahd_execute_scb(scb,
730 1.1 fvdl scb->dmamap->dm_segs,
731 1.1 fvdl scb->dmamap->dm_nsegs);
732 1.23 tsutsui } else {
733 1.23 tsutsui ahd_execute_scb(scb, NULL, 0);
734 1.23 tsutsui }
735 1.1 fvdl }
736 1.1 fvdl
737 1.1 fvdl void
738 1.1 fvdl ahd_timeout(void *arg)
739 1.1 fvdl {
740 1.1 fvdl struct scb *scb;
741 1.1 fvdl struct ahd_softc *ahd;
742 1.1 fvdl ahd_mode_state saved_modes;
743 1.1 fvdl int s;
744 1.1 fvdl
745 1.25 tsutsui scb = arg;
746 1.25 tsutsui ahd = scb->ahd_softc;
747 1.1 fvdl
748 1.1 fvdl printf("%s: ahd_timeout\n", ahd_name(ahd));
749 1.1 fvdl
750 1.1 fvdl ahd_lock(ahd, &s);
751 1.1 fvdl
752 1.1 fvdl ahd_pause_and_flushwork(ahd);
753 1.1 fvdl saved_modes = ahd_save_modes(ahd);
754 1.1 fvdl #if 0
755 1.1 fvdl ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
756 1.1 fvdl ahd_outb(ahd, SCSISIGO, ACKO);
757 1.1 fvdl printf("set ACK\n");
758 1.1 fvdl ahd_outb(ahd, SCSISIGO, 0);
759 1.1 fvdl printf("clearing Ack\n");
760 1.1 fvdl ahd_restore_modes(ahd, saved_modes);
761 1.1 fvdl #endif
762 1.1 fvdl if ((scb->flags & SCB_ACTIVE) == 0) {
763 1.1 fvdl /* Previous timeout took care of me already */
764 1.1 fvdl printf("%s: Timedout SCB already complete. "
765 1.1 fvdl "Interrupts may not be functioning.\n", ahd_name(ahd));
766 1.1 fvdl ahd_unpause(ahd);
767 1.1 fvdl ahd_unlock(ahd, &s);
768 1.1 fvdl return;
769 1.1 fvdl }
770 1.1 fvdl
771 1.1 fvdl ahd_print_path(ahd, scb);
772 1.1 fvdl printf("SCB 0x%x - timed out\n", SCB_GET_TAG(scb));
773 1.1 fvdl ahd_dump_card_state(ahd);
774 1.1 fvdl ahd_reset_channel(ahd, SIM_CHANNEL(ahd, sim),
775 1.1 fvdl /*initiate reset*/TRUE);
776 1.1 fvdl ahd_unlock(ahd, &s);
777 1.1 fvdl return;
778 1.1 fvdl }
779 1.1 fvdl
780 1.1 fvdl int
781 1.17 christos ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
782 1.1 fvdl {
783 1.1 fvdl ahd->platform_data = malloc(sizeof(struct ahd_platform_data), M_DEVBUF,
784 1.1 fvdl M_NOWAIT /*| M_ZERO*/);
785 1.1 fvdl if (ahd->platform_data == NULL)
786 1.1 fvdl return (ENOMEM);
787 1.1 fvdl
788 1.1 fvdl memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
789 1.1 fvdl
790 1.1 fvdl return (0);
791 1.1 fvdl }
792 1.1 fvdl
793 1.1 fvdl void
794 1.1 fvdl ahd_platform_free(struct ahd_softc *ahd)
795 1.1 fvdl {
796 1.1 fvdl free(ahd->platform_data, M_DEVBUF);
797 1.1 fvdl }
798 1.1 fvdl
799 1.1 fvdl int
800 1.17 christos ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
801 1.1 fvdl {
802 1.1 fvdl /* We don't sort softcs under NetBSD so report equal always */
803 1.1 fvdl return (0);
804 1.1 fvdl }
805 1.1 fvdl
806 1.1 fvdl int
807 1.28 tsutsui ahd_detach(struct ahd_softc *ahd, int flags)
808 1.1 fvdl {
809 1.1 fvdl int rv = 0;
810 1.1 fvdl
811 1.1 fvdl if (ahd->sc_child != NULL)
812 1.26 tsutsui rv = config_detach(ahd->sc_child, flags);
813 1.1 fvdl
814 1.29 tsutsui pmf_device_deregister(ahd->sc_dev);
815 1.1 fvdl
816 1.1 fvdl ahd_free(ahd);
817 1.1 fvdl
818 1.1 fvdl return rv;
819 1.1 fvdl }
820 1.1 fvdl
821 1.1 fvdl void
822 1.1 fvdl ahd_platform_set_tags(struct ahd_softc *ahd,
823 1.1 fvdl struct ahd_devinfo *devinfo, ahd_queue_alg alg)
824 1.1 fvdl {
825 1.23 tsutsui struct ahd_tmode_tstate *tstate;
826 1.1 fvdl
827 1.23 tsutsui ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
828 1.23 tsutsui devinfo->target, &tstate);
829 1.1 fvdl
830 1.23 tsutsui if (alg != AHD_QUEUE_NONE)
831 1.23 tsutsui tstate->tagenable |= devinfo->target_mask;
832 1.1 fvdl else
833 1.23 tsutsui tstate->tagenable &= ~devinfo->target_mask;
834 1.1 fvdl }
835 1.1 fvdl
836 1.1 fvdl void
837 1.24 tsutsui ahd_send_async(struct ahd_softc *ahd, char channel, u_int target, u_int lun,
838 1.17 christos ac_code code, void *opt_arg)
839 1.1 fvdl {
840 1.1 fvdl struct ahd_tmode_tstate *tstate;
841 1.1 fvdl struct ahd_initiator_tinfo *tinfo;
842 1.1 fvdl struct ahd_devinfo devinfo;
843 1.1 fvdl struct scsipi_channel *chan;
844 1.1 fvdl struct scsipi_xfer_mode xm;
845 1.1 fvdl
846 1.1 fvdl #ifdef DIAGNOSTIC
847 1.1 fvdl if (channel != 'A')
848 1.1 fvdl panic("ahd_send_async: not channel A");
849 1.1 fvdl #endif
850 1.24 tsutsui chan = &ahd->sc_channel;
851 1.1 fvdl switch (code) {
852 1.1 fvdl case AC_TRANSFER_NEG:
853 1.24 tsutsui tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id, target,
854 1.1 fvdl &tstate);
855 1.24 tsutsui ahd_compile_devinfo(&devinfo, ahd->our_id, target, lun,
856 1.1 fvdl channel, ROLE_UNKNOWN);
857 1.1 fvdl /*
858 1.1 fvdl * Don't bother if negotiating. XXX?
859 1.1 fvdl */
860 1.1 fvdl if (tinfo->curr.period != tinfo->goal.period
861 1.1 fvdl || tinfo->curr.width != tinfo->goal.width
862 1.1 fvdl || tinfo->curr.offset != tinfo->goal.offset
863 1.1 fvdl || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
864 1.1 fvdl break;
865 1.1 fvdl xm.xm_target = target;
866 1.1 fvdl xm.xm_mode = 0;
867 1.1 fvdl xm.xm_period = tinfo->curr.period;
868 1.1 fvdl xm.xm_offset = tinfo->curr.offset;
869 1.1 fvdl if (tinfo->goal.ppr_options & MSG_EXT_PPR_DT_REQ)
870 1.1 fvdl xm.xm_mode |= PERIPH_CAP_DT;
871 1.1 fvdl if (tinfo->curr.width == MSG_EXT_WDTR_BUS_16_BIT)
872 1.1 fvdl xm.xm_mode |= PERIPH_CAP_WIDE16;
873 1.1 fvdl if (tinfo->curr.period)
874 1.1 fvdl xm.xm_mode |= PERIPH_CAP_SYNC;
875 1.1 fvdl if (tstate->tagenable & devinfo.target_mask)
876 1.1 fvdl xm.xm_mode |= PERIPH_CAP_TQING;
877 1.1 fvdl scsipi_async_event(chan, ASYNC_EVENT_XFER_MODE, &xm);
878 1.1 fvdl break;
879 1.1 fvdl case AC_BUS_RESET:
880 1.1 fvdl scsipi_async_event(chan, ASYNC_EVENT_RESET, NULL);
881 1.1 fvdl case AC_SENT_BDR:
882 1.1 fvdl default:
883 1.1 fvdl break;
884 1.1 fvdl }
885 1.1 fvdl }
886