xref: /openbsd-src/sys/dev/ic/aic79xx_openbsd.c (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1 /*	$OpenBSD: aic79xx_openbsd.c,v 1.50 2020/02/15 18:02:00 krw Exp $	*/
2 
3 /*
4  * Copyright (c) 2004 Milos Urbanek, Kenneth R. Westerback & Marco Peereboom
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  */
29 
30 /*
31  * Bus independent OpenBSD shim for the aic79xx based Adaptec SCSI controllers
32  *
33  * Copyright (c) 1994-2002 Justin T. Gibbs.
34  * Copyright (c) 2001-2002 Adaptec Inc.
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions, and the following disclaimer,
42  *    without modification.
43  * 2. The name of the author may not be used to endorse or promote products
44  *    derived from this software without specific prior written permission.
45  *
46  * Alternatively, this software may be distributed under the terms of the
47  * GNU Public License ("GPL").
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
53  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59  * SUCH DAMAGE.
60  *
61  */
62 
63 #include <dev/ic/aic79xx_openbsd.h>
64 #include <dev/ic/aic79xx_inline.h>
65 #include <dev/ic/aic79xx.h>
66 
67 #ifndef AHD_TMODE_ENABLE
68 #define AHD_TMODE_ENABLE 0
69 #endif
70 
71 /* XXX milos add ahd_ioctl */
72 void	ahd_action(struct scsi_xfer *);
73 void	ahd_execute_scb(void *, bus_dma_segment_t *, int);
74 int	ahd_poll(struct ahd_softc *, int);
75 void	ahd_setup_data(struct ahd_softc *, struct scsi_xfer *,
76 		    struct scb *);
77 
78 void	ahd_adapter_req_set_xfer_mode(struct ahd_softc *, struct scb *);
79 
80 struct cfdriver ahd_cd = {
81 	NULL, "ahd", DV_DULL
82 };
83 
84 static struct scsi_adapter ahd_switch = {
85 	ahd_action, NULL, NULL, NULL, NULL
86 };
87 
88 /*
89  * Attach all the sub-devices we can find
90  */
91 int
92 ahd_attach(struct ahd_softc *ahd)
93 {
94 	struct scsibus_attach_args saa;
95 	char   ahd_info[256];
96 	int	s;
97 
98 	ahd_controller_info(ahd, ahd_info, sizeof ahd_info);
99 	printf("%s\n", ahd_info);
100 	ahd_lock(ahd, &s);
101 
102 	/*
103 	 * fill in the prototype scsi_links.
104 	 */
105 	ahd->sc_channel.adapter_target = ahd->our_id;
106 	if (ahd->features & AHD_WIDE)
107 		ahd->sc_channel.adapter_buswidth = 16;
108 	ahd->sc_channel.adapter_softc = ahd;
109 	ahd->sc_channel.adapter = &ahd_switch;
110 	ahd->sc_channel.openings = 16; /* Must ALWAYS be < 256!! */
111 	ahd->sc_channel.pool = &ahd->sc_iopool;
112 
113 	if (bootverbose) {
114 		ahd_controller_info(ahd, ahd_info, sizeof ahd_info);
115 		printf("%s: %s\n", ahd->sc_dev.dv_xname, ahd_info);
116 	}
117 
118 	ahd_intr_enable(ahd, TRUE);
119 
120 	if (ahd->flags & AHD_RESET_BUS_A)
121 		ahd_reset_channel(ahd, 'A', TRUE);
122 
123 	bzero(&saa, sizeof(saa));
124 	saa.saa_sc_link = &ahd->sc_channel;
125 
126 	ahd->sc_child = config_found((void *)&ahd->sc_dev, &saa, scsiprint);
127 
128 	ahd_unlock(ahd, &s);
129 
130 	return (1);
131 
132 }
133 
134 /*
135  * Catch an interrupt from the adapter
136  */
137 int
138 ahd_platform_intr(void *arg)
139 {
140 	struct	ahd_softc *ahd;
141 
142 	/* XXX in ahc there is some bus_dmamap_sync(PREREAD|PREWRITE); */
143 
144 	ahd = (struct ahd_softc *)arg;
145 	return ahd_intr(ahd);
146 }
147 
148 /*
149  * We have an scb which has been processed by the
150  * adaptor, now we look to see how the operation
151  * went.
152  */
153 void
154 ahd_done(struct ahd_softc *ahd, struct scb *scb)
155 {
156 	struct scsi_xfer *xs = scb->xs;
157 
158 	/* XXX in ahc there is some bus_dmamap_sync(PREREAD|PREWRITE); */
159 
160 	TAILQ_REMOVE(&ahd->pending_scbs, scb, next);
161 
162 	timeout_del(&xs->stimeout);
163 
164 	if (xs->datalen) {
165 		int op;
166 
167 		if ((xs->flags & SCSI_DATA_IN) != 0)
168 			op = BUS_DMASYNC_POSTREAD;
169 		else
170 			op = BUS_DMASYNC_POSTWRITE;
171 		bus_dmamap_sync(ahd->parent_dmat, scb->dmamap, 0,
172 		    scb->dmamap->dm_mapsize, op);
173 		bus_dmamap_unload(ahd->parent_dmat, scb->dmamap);
174 	}
175 
176 	/* Translate the CAM status code to a SCSI error code. */
177 	switch (xs->error) {
178 	case CAM_SCSI_STATUS_ERROR:
179 	case CAM_REQ_INPROG:
180 	case CAM_REQ_CMP:
181 		switch (xs->status) {
182 		case SCSI_TASKSET_FULL:
183 		case SCSI_BUSY:
184 			xs->error = XS_BUSY;
185 			break;
186 		case SCSI_CHECK:
187 		case SCSI_TERMINATED:
188 			if ((scb->flags & SCB_SENSE) == 0) {
189 				/* CHECK on CHECK? */
190 				xs->error = XS_DRIVER_STUFFUP;
191 			} else
192 				xs->error = XS_NOERROR;
193 			break;
194 		default:
195 			xs->error = XS_NOERROR;
196 			break;
197 		}
198 		break;
199 	case CAM_BUSY:
200 	case CAM_REQUEUE_REQ:
201 		xs->error = XS_BUSY;
202 		break;
203 	case CAM_CMD_TIMEOUT:
204 		xs->error = XS_TIMEOUT;
205 		break;
206 	case CAM_BDR_SENT:
207 	case CAM_SCSI_BUS_RESET:
208 		xs->error = XS_RESET;
209 		break;
210 	case CAM_SEL_TIMEOUT:
211 		xs->error = XS_SELTIMEOUT;
212 		break;
213 	default:
214 		xs->error = XS_DRIVER_STUFFUP;
215 		break;
216 	}
217 
218 	if (xs->error != XS_NOERROR) {
219 		/* Don't clobber any existing error state */
220 	} else if ((scb->flags & SCB_SENSE) != 0) {
221 		/*
222 		 * We performed autosense retrieval.
223 		 *
224 		 * Zero any sense not transferred by the
225 		 * device.  The SCSI spec mandates that any
226 		 * untransferred data should be assumed to be
227 		 * zero.  Complete the 'bounce' of sense information
228 		 * through buffers accessible via bus-space by
229 		 * copying it into the clients csio.
230 		 */
231 		memset(&xs->sense, 0, sizeof(struct scsi_sense_data));
232 		memcpy(&xs->sense, ahd_get_sense_buf(ahd, scb),
233 		    sizeof(struct scsi_sense_data));
234 		xs->error = XS_SENSE;
235 	} else if ((scb->flags & SCB_PKT_SENSE) != 0) {
236 		struct scsi_status_iu_header *siu;
237 		u_int32_t len;
238 
239 		siu = (struct scsi_status_iu_header *)scb->sense_data;
240 		len = SIU_SENSE_LENGTH(siu);
241 		memset(&xs->sense, 0, sizeof(xs->sense));
242 		memcpy(&xs->sense, SIU_SENSE_DATA(siu),
243 		    ulmin(len, sizeof(xs->sense)));
244 		xs->error = XS_SENSE;
245 	}
246 
247 	scsi_done(xs);
248 }
249 
250 void
251 ahd_action(struct scsi_xfer *xs)
252 {
253 	struct	ahd_softc *ahd;
254 	struct scb *scb;
255 	struct hardware_scb *hscb;
256 	u_int	target_id;
257 	u_int	our_id;
258 	int	s;
259 	struct	ahd_initiator_tinfo *tinfo;
260 	struct	ahd_tmode_tstate *tstate;
261 	u_int16_t quirks;
262 
263 	SC_DEBUG(xs->sc_link, SDEV_DB3, ("ahd_action\n"));
264 	ahd = (struct ahd_softc *)xs->sc_link->adapter_softc;
265 
266 	target_id = xs->sc_link->target;
267 	our_id = SCSI_SCSI_ID(ahd, xs->sc_link);
268 
269 	ahd_lock(ahd, &s);
270 	if ((ahd->flags & AHD_INITIATORROLE) == 0) {
271 		xs->error = XS_DRIVER_STUFFUP;
272 		scsi_done(xs);
273 		ahd_unlock(ahd, &s);
274 		return;
275 	}
276 	/*
277 	 * get an scb to use.
278 	 */
279 	tinfo = ahd_fetch_transinfo(ahd, 'A', our_id, target_id, &tstate);
280 
281 	quirks = xs->sc_link->quirks;
282 
283 	ahd_unlock(ahd, &s);
284 
285 	scb = xs->io;
286 	hscb = scb->hscb;
287 	scb->flags = SCB_FLAG_NONE;
288 	scb->hscb->control = 0;
289 	ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = NULL;
290 
291 	SC_DEBUG(xs->sc_link, SDEV_DB3, ("start scb(%p)\n", scb));
292 
293 	scb->xs = xs;
294 	timeout_set(&xs->stimeout, ahd_timeout, scb);
295 
296 	/*
297 	 * Put all the arguments for the xfer in the scb
298 	 */
299 	hscb->control = 0;
300 	hscb->scsiid = BUILD_SCSIID(ahd, xs->sc_link, target_id, our_id);
301 	hscb->lun = xs->sc_link->lun;
302 	if (xs->xs_control & XS_CTL_RESET) {
303 		hscb->cdb_len = 0;
304 		scb->flags |= SCB_DEVICE_RESET;
305 		hscb->control |= MK_MESSAGE;
306 		hscb->task_management = SIU_TASKMGMT_LUN_RESET;
307 		ahd_execute_scb(scb, NULL, 0);
308 	} else {
309 		hscb->task_management = 0;
310 		ahd_setup_data(ahd, xs, scb);
311 	}
312 }
313 
314 void
315 ahd_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments)
316 {
317 	struct	scb *scb;
318 	struct	scsi_xfer *xs;
319 	struct	ahd_softc *ahd;
320 	struct	ahd_initiator_tinfo *tinfo;
321 	struct	ahd_tmode_tstate *tstate;
322 	u_int	mask;
323 	int	s;
324 
325 	scb = (struct scb *)arg;
326 	xs = scb->xs;
327 	xs->error = CAM_REQ_INPROG;
328 	xs->status = 0;
329 	ahd = (struct ahd_softc *)xs->sc_link->adapter_softc;
330 
331 	if (nsegments != 0) {
332 		void *sg;
333 		int op;
334 		u_int i;
335 
336 		ahd_setup_data_scb(ahd, scb);
337 
338 		/* Copy the segments into our SG list */
339 		for (i = nsegments, sg = scb->sg_list; i > 0; i--) {
340 
341 			sg = ahd_sg_setup(ahd, scb, sg, dm_segs->ds_addr,
342 					  dm_segs->ds_len,
343 					  /*last*/i == 1);
344 			dm_segs++;
345 		}
346 
347 		if ((xs->flags & SCSI_DATA_IN) != 0)
348 			op = BUS_DMASYNC_PREREAD;
349 		else
350 			op = BUS_DMASYNC_PREWRITE;
351 
352 		bus_dmamap_sync(ahd->parent_dmat, scb->dmamap, 0,
353 				scb->dmamap->dm_mapsize, op);
354 
355 	}
356 
357 	ahd_lock(ahd, &s);
358 
359 	/*
360 	 * Last time we need to check if this SCB needs to
361 	 * be aborted.
362 	 */
363 	if (xs->flags & ITSDONE) {
364 		if (nsegments != 0)
365 			bus_dmamap_unload(ahd->parent_dmat,
366 					  scb->dmamap);
367 		ahd_unlock(ahd, &s);
368 		return;
369 	}
370 
371 	tinfo = ahd_fetch_transinfo(ahd, SCSIID_CHANNEL(ahd, scb->hscb->scsiid),
372 				    SCSIID_OUR_ID(scb->hscb->scsiid),
373 				    SCSIID_TARGET(ahd, scb->hscb->scsiid),
374 				    &tstate);
375 
376 	mask = SCB_GET_TARGET_MASK(ahd, scb);
377 
378 	if ((tstate->discenable & mask) != 0)
379 		scb->hscb->control |= DISCENB;
380 
381 	if ((tstate->tagenable & mask) != 0)
382 		scb->hscb->control |= TAG_ENB;
383 
384 	if ((tinfo->curr.ppr_options & MSG_EXT_PPR_PROT_IUS) != 0) {
385 		scb->flags |= SCB_PACKETIZED;
386 		if (scb->hscb->task_management != 0)
387 			scb->hscb->control &= ~MK_MESSAGE;
388 	}
389 
390 	if ((tstate->auto_negotiate & mask) != 0) {
391 		scb->flags |= SCB_AUTO_NEGOTIATE;
392 		scb->hscb->control |= MK_MESSAGE;
393 	}
394 
395 	/* XXX with ahc there was some bus_dmamap_sync(PREREAD|PREWRITE); */
396 
397 	TAILQ_INSERT_HEAD(&ahd->pending_scbs, scb, next);
398 
399 	if (!(xs->flags & SCSI_POLL))
400 		timeout_add_msec(&xs->stimeout, xs->timeout);
401 
402 	scb->flags |= SCB_ACTIVE;
403 
404 	if ((scb->flags & SCB_TARGET_IMMEDIATE) != 0) {
405 		/* Define a mapping from our tag to the SCB. */
406 		ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb;
407 		ahd_pause(ahd);
408 		ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
409 		ahd_outb(ahd, RETURN_1, CONT_MSG_LOOP_TARG);
410 		ahd_unpause(ahd);
411 	} else {
412 		ahd_queue_scb(ahd, scb);
413 	}
414 
415 	if (!(xs->flags & SCSI_POLL)) {
416 		int target = xs->sc_link->target;
417 		int lun = SCB_GET_LUN(scb);
418 
419 		if (ahd->inited_target[target] == 0) {
420 			struct  ahd_devinfo devinfo;
421 
422 			ahd_adapter_req_set_xfer_mode(ahd, scb);
423 			ahd_compile_devinfo(&devinfo, ahd->our_id, target, lun,
424 			    'A', /*XXX milos*/ROLE_UNKNOWN);
425 			ahd_scb_devinfo(ahd, &devinfo, scb);
426 			ahd_update_neg_request(ahd, &devinfo, tstate, tinfo,
427 				AHD_NEG_IF_NON_ASYNC);
428 			ahd->inited_target[target] = 1;
429 		}
430 
431 		ahd_unlock(ahd, &s);
432 		return;
433 	}
434 
435 	/*
436 	 * If we can't use interrupts, poll for completion
437 	 */
438 	SC_DEBUG(xs->sc_link, SDEV_DB3, ("cmd_poll\n"));
439 
440 	do {
441 		if (ahd_poll(ahd, xs->timeout)) {
442 			if (!(xs->flags & SCSI_SILENT))
443 				printf("cmd fail\n");
444 			ahd_timeout(scb);
445 			break;
446 		}
447 	} while (!(xs->flags & ITSDONE));
448 
449 	ahd_unlock(ahd, &s);
450 }
451 
452 int
453 ahd_poll(struct ahd_softc *ahd, int wait)
454 {
455 	while (--wait) {
456 		DELAY(1000);
457 		if (ahd_inb(ahd, INTSTAT) & INT_PEND)
458 			break;
459 	}
460 
461 	if (wait == 0) {
462 		printf("%s: board is not responding\n", ahd_name(ahd));
463 		return (EIO);
464 	}
465 
466 	ahd_intr((void *)ahd);
467 	return (0);
468 }
469 
470 void
471 ahd_setup_data(struct ahd_softc *ahd, struct scsi_xfer *xs,
472 	       struct scb *scb)
473 {
474 	struct hardware_scb *hscb;
475 
476 	hscb = scb->hscb;
477 	xs->resid = xs->status = 0;
478 	xs->error = CAM_REQ_INPROG;
479 
480 	hscb->cdb_len = xs->cmdlen;
481 	if (hscb->cdb_len > MAX_CDB_LEN) {
482 		xs->error = XS_DRIVER_STUFFUP;
483 		scsi_done(xs);
484 		return;
485 	}
486 
487 	memcpy(hscb->shared_data.idata.cdb, xs->cmd, hscb->cdb_len);
488 
489 	/* Only use S/G if there is a transfer */
490 	if (xs->datalen) {
491 		int error;
492 
493 		error = bus_dmamap_load(ahd->parent_dmat,
494 					scb->dmamap, xs->data,
495 					xs->datalen, NULL,
496 					((xs->flags & SCSI_NOSLEEP) ?
497 					BUS_DMA_NOWAIT : BUS_DMA_WAITOK) |
498 					BUS_DMA_STREAMING |
499 					((xs->flags & XS_CTL_DATA_IN) ?
500 					BUS_DMA_READ : BUS_DMA_WRITE));
501 		if (error) {
502 #ifdef AHD_DEBUG
503 			printf("%s: in ahd_setup_data(): bus_dmamap_load() "
504 			    "= %d\n", ahd_name(ahd), error);
505 #endif
506 			xs->error = XS_DRIVER_STUFFUP;
507 			scsi_done(xs);
508 			return;
509 		}
510 		ahd_execute_scb(scb, scb->dmamap->dm_segs,
511 		    scb->dmamap->dm_nsegs);
512 	} else {
513 		ahd_execute_scb(scb, NULL, 0);
514 	}
515 }
516 
517 void
518 ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
519     ahd_queue_alg alg)
520 {
521 	struct ahd_tmode_tstate *tstate;
522 
523 	ahd_fetch_transinfo(ahd, devinfo->channel, devinfo->our_scsiid,
524 	    devinfo->target, &tstate);
525 
526 	if (alg != AHD_QUEUE_NONE)
527 		tstate->tagenable |= devinfo->target_mask;
528 	else
529 		tstate->tagenable &= ~devinfo->target_mask;
530 }
531 
532 int
533 ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
534 {
535 	/* We don't sort softcs under OpenBSD so report equal always */
536 	return (0);
537 }
538 
539 int
540 ahd_detach(struct device *self, int flags)
541 {
542 	int rv = 0;
543 
544 	struct ahd_softc *ahd = (struct ahd_softc*)self;
545 
546 	if (ahd->sc_child != NULL)
547 		rv = config_detach((void *)ahd->sc_child, flags);
548 
549 	ahd_free(ahd);
550 
551 	return rv;
552 }
553 
554 void
555 ahd_adapter_req_set_xfer_mode(struct ahd_softc *ahd, struct scb *scb)
556 {
557 	struct ahd_initiator_tinfo *tinfo;
558 	struct ahd_tmode_tstate *tstate;
559 	int target_id, our_id;
560 	struct ahd_devinfo devinfo;
561 	u_int16_t quirks;
562 	u_int width, ppr_options, period, offset;
563 	int s;
564 
565 	target_id = scb->xs->sc_link->target;
566 	our_id = SCSI_SCSI_ID(ahd, scb->xs->sc_link);
567 
568 	s = splbio();
569 
570 	quirks = scb->xs->sc_link->quirks;
571 	tinfo = ahd_fetch_transinfo(ahd, 'A', our_id, target_id, &tstate);
572 	ahd_compile_devinfo(&devinfo, our_id, target_id, 0, 'A',
573 	    ROLE_INITIATOR);
574 
575 	tstate->discenable |= (ahd->user_discenable & devinfo.target_mask);
576 
577 	if (quirks & SDEV_NOTAGS)
578 		tstate->tagenable &= ~devinfo.target_mask;
579 	else if (ahd->user_tagenable & devinfo.target_mask)
580 		tstate->tagenable |= devinfo.target_mask;
581 
582 	if (quirks & SDEV_NOWIDE)
583 		width = MSG_EXT_WDTR_BUS_8_BIT;
584 	else
585 		width = MSG_EXT_WDTR_BUS_16_BIT;
586 
587 	ahd_validate_width(ahd, NULL, &width, ROLE_UNKNOWN);
588 	if (width > tinfo->user.width)
589 		width = tinfo->user.width;
590 	ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
591 
592 	if (quirks & SDEV_NOSYNC) {
593 		period = 0;
594 		offset = 0;
595 	} else {
596 		period = tinfo->user.period;
597 		offset = tinfo->user.offset;
598 	}
599 
600 	/* XXX Look at saved INQUIRY flags for PPR capabilities XXX */
601 	ppr_options = tinfo->user.ppr_options;
602 	/* XXX Other reasons to avoid ppr? XXX */
603 	if (width < MSG_EXT_WDTR_BUS_16_BIT)
604 		ppr_options = 0;
605 
606 	if ((tstate->discenable & devinfo.target_mask) == 0 ||
607 	    (tstate->tagenable & devinfo.target_mask) == 0)
608 		ppr_options &= ~MSG_EXT_PPR_PROT_IUS;
609 
610 	ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX);
611 	ahd_validate_offset(ahd, NULL, period, &offset, width, ROLE_UNKNOWN);
612 
613 	if (offset == 0) {
614 		period = 0;
615 		ppr_options = 0;
616 	}
617 
618 	if (ppr_options != 0 && tinfo->user.transport_version >= 3) {
619 		tinfo->goal.transport_version = tinfo->user.transport_version;
620 		tinfo->curr.transport_version = tinfo->user.transport_version;
621 	}
622 
623 	ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options,
624 		AHD_TRANS_GOAL, FALSE);
625 
626 	splx(s);
627 }
628 
629 void
630 aic_timer_reset(aic_timer_t *timer, u_int msec, ahd_callback_t *func,
631     void *arg)
632 {
633 	uint64_t nticks;
634 
635 	nticks = msec;
636 	nticks *= hz;
637 	nticks /= 1000;
638 	callout_reset(timer, nticks, func, arg);
639 }
640 
641 void
642 aic_scb_timer_reset(struct scb *scb, u_int msec)
643 {
644 	uint64_t nticks;
645 
646 	nticks = msec;
647 	nticks *= hz;
648 	nticks /= 1000;
649 	if (!(scb->xs->xs_control & XS_CTL_POLL))
650 		callout_reset(&scb->xs->xs_callout, nticks, ahd_timeout, scb);
651 }
652 
653 void
654 ahd_flush_device_writes(struct ahd_softc *ahd)
655 {
656 	/* XXX Is this sufficient for all architectures??? */
657 	ahd_inb(ahd, INTSTAT);
658 }
659 
660 void
661 aic_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
662 {
663 	int s;
664 
665 	ahd_lock(ahd, &s);
666 
667 	if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0) {
668 		ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
669 	}
670 
671 	if (!cold) {
672 		/* we are no longer in autoconf */
673 		timeout_del(&scb->xs->stimeout);
674 	}
675 
676 	ahd_unlock(ahd, &s);
677 }
678 
679 void
680 ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
681 {
682 	sc_print_addr(scb->xs->sc_link);
683 }
684 
685 void
686 ahd_platform_dump_card_state(struct ahd_softc *ahd)
687 {
688 	/* Nothing to do here for OpenBSD */
689 	printf("FEATURES = 0x%x, FLAGS = 0x%x, CHIP = 0x%x BUGS =0x%x\n",
690 		ahd->features, ahd->flags, ahd->chip, ahd->bugs);
691 }
692 
693