2 * Copyright (c) 1999 Luoqi Chen.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/dev/aic/aic.c,v 1.8 2000/01/14 23:42:35 imp Exp $
27 * $DragonFly: src/sys/dev/disk/aic/aic.c,v 1.9 2006/12/22 23:26:15 swildner Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/malloc.h>
34 #include <sys/kernel.h>
35 #include <sys/sysctl.h>
37 #include <sys/thread2.h>
39 #include <machine/clock.h>
41 #include <bus/cam/cam.h>
42 #include <bus/cam/cam_ccb.h>
43 #include <bus/cam/cam_sim.h>
44 #include <bus/cam/cam_xpt_sim.h>
45 #include <bus/cam/cam_debug.h>
47 #include <bus/cam/scsi/scsi_message.h>
49 #include "aic6360reg.h"
52 static void aic_action (struct cam_sim *sim, union ccb *ccb);
53 static void aic_execute_scb (void *arg, bus_dma_segment_t *dm_segs,
55 static void aic_start (struct aic_softc *aic);
56 static void aic_select (struct aic_softc *aic);
57 static void aic_selected (struct aic_softc *aic);
58 static void aic_reselected (struct aic_softc *aic);
59 static void aic_reconnect (struct aic_softc *aic, int tag);
60 static void aic_cmd (struct aic_softc *aic);
61 static void aic_msgin (struct aic_softc *aic);
62 static void aic_handle_msgin (struct aic_softc *aic);
63 static void aic_msgout (struct aic_softc *aic);
64 static void aic_datain (struct aic_softc *aic);
65 static void aic_dataout (struct aic_softc *aic);
66 static void aic_done (struct aic_softc *aic, struct aic_scb *scb);
67 static void aic_poll (struct cam_sim *sim);
68 static void aic_timeout (void *arg);
69 static void aic_scsi_reset (struct aic_softc *aic);
70 static void aic_chip_reset (struct aic_softc *aic);
71 static void aic_reset (struct aic_softc *aic, int initiate_reset);
73 devclass_t aic_devclass;
75 static struct aic_scb *free_scbs;
77 static struct aic_scb *
78 aic_get_scb(struct aic_softc *aic)
84 if ((scb = free_scbs) != NULL)
85 free_scbs = (struct aic_scb *)free_scbs->ccb;
92 aic_free_scb(struct aic_softc *aic, struct aic_scb *scb)
96 if ((aic->flags & AIC_RESOURCE_SHORTAGE) != 0 &&
97 (scb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
98 scb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
99 aic->flags &= ~AIC_RESOURCE_SHORTAGE;
102 scb->ccb = (union ccb *)free_scbs;
109 aic_action(struct cam_sim *sim, union ccb *ccb)
111 struct aic_softc *aic;
113 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("aic_action\n"));
115 aic = (struct aic_softc *)cam_sim_softc(sim);
117 switch (ccb->ccb_h.func_code) {
118 case XPT_SCSI_IO: /* Execute the requested I/O operation */
119 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
123 if ((scb = aic_get_scb(aic)) == NULL) {
125 aic->flags |= AIC_RESOURCE_SHORTAGE;
127 xpt_freeze_simq(aic->sim, /*count*/1);
128 ccb->ccb_h.status = CAM_REQUEUE_REQ;
134 ccb->ccb_h.ccb_scb_ptr = scb;
135 ccb->ccb_h.ccb_aic_ptr = aic;
137 scb->target = ccb->ccb_h.target_id;
138 scb->lun = ccb->ccb_h.target_lun;
140 if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
141 scb->cmd_len = ccb->csio.cdb_len;
142 if (ccb->ccb_h.flags & CAM_CDB_POINTER) {
143 if (ccb->ccb_h.flags & CAM_CDB_PHYS) {
144 ccb->ccb_h.status = CAM_REQ_INVALID;
145 aic_free_scb(aic, scb);
149 scb->cmd_ptr = ccb->csio.cdb_io.cdb_ptr;
151 scb->cmd_ptr = ccb->csio.cdb_io.cdb_bytes;
153 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
154 if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) ||
155 (ccb->ccb_h.flags & CAM_DATA_PHYS)) {
156 ccb->ccb_h.status = CAM_REQ_INVALID;
157 aic_free_scb(aic, scb);
161 scb->data_ptr = ccb->csio.data_ptr;
162 scb->data_len = ccb->csio.dxfer_len;
164 scb->data_ptr = NULL;
167 aic_execute_scb(scb, NULL, 0, 0);
169 scb->flags |= SCB_DEVICE_RESET;
170 aic_execute_scb(scb, NULL, 0, 0);
174 case XPT_SET_TRAN_SETTINGS:
176 struct ccb_trans_settings *cts;
177 struct aic_tinfo *ti;
180 ti = &aic->tinfo[ccb->ccb_h.target_id];
184 if ((cts->valid & CCB_TRANS_DISC_VALID) != 0 &&
185 (aic->flags & AIC_DISC_ENABLE) != 0) {
186 if ((cts->flags & CCB_TRANS_DISC_ENB) != 0)
187 ti->flags |= TINFO_DISC_ENB;
189 ti->flags &= ~TINFO_DISC_ENB;
192 if ((cts->valid & CCB_TRANS_TQ_VALID) != 0) {
193 if ((cts->flags & CCB_TRANS_TAG_ENB) != 0)
194 ti->flags |= TINFO_TAG_ENB;
196 ti->flags &= ~TINFO_TAG_ENB;
199 if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) != 0) {
200 ti->goal.period = cts->sync_period;
201 if (ti->goal.period != ti->current.period)
202 ti->flags |= TINFO_SDTR_NEGO;
205 if ((cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0) {
206 ti->goal.offset = cts->sync_offset;
207 if (ti->goal.offset != ti->current.offset)
208 ti->flags |= TINFO_SDTR_NEGO;
212 ccb->ccb_h.status = CAM_REQ_CMP;
216 case XPT_GET_TRAN_SETTINGS:
218 struct ccb_trans_settings *cts;
219 struct aic_tinfo *ti;
222 ti = &aic->tinfo[ccb->ccb_h.target_id];
226 cts->flags &= ~(CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB);
227 if ((ti->flags & TINFO_DISC_ENB) != 0)
228 cts->flags |= CCB_TRANS_DISC_ENB;
229 if ((ti->flags & TINFO_TAG_ENB) != 0)
230 cts->flags |= CCB_TRANS_TAG_ENB;
232 if ((cts->flags & CCB_TRANS_CURRENT_SETTINGS) != 0) {
233 cts->sync_period = ti->current.period;
234 cts->sync_offset = ti->current.offset;
236 cts->sync_period = ti->user.period;
237 cts->sync_offset = ti->user.offset;
239 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
243 cts->valid = CCB_TRANS_SYNC_RATE_VALID
244 | CCB_TRANS_SYNC_OFFSET_VALID
245 | CCB_TRANS_BUS_WIDTH_VALID
246 | CCB_TRANS_DISC_VALID
247 | CCB_TRANS_TQ_VALID;
249 ccb->ccb_h.status = CAM_REQ_CMP;
253 case XPT_CALC_GEOMETRY:
255 struct ccb_calc_geometry *ccg;
257 u_int32_t secs_per_cylinder;
261 size_mb = ccg->volume_size
262 / ((1024L * 1024L) / ccg->block_size);
264 if (size_mb >= 1024 && extended) {
266 ccg->secs_per_track = 63;
269 ccg->secs_per_track = 32;
271 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
272 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
273 ccb->ccb_h.status = CAM_REQ_CMP;
277 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
278 aic_reset(aic, /*initiate_reset*/TRUE);
279 ccb->ccb_h.status = CAM_REQ_CMP;
282 case XPT_PATH_INQ: /* Path routing inquiry */
284 struct ccb_pathinq *cpi = &ccb->cpi;
286 cpi->version_num = 1; /* XXX??? */
287 cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE;
288 cpi->target_sprt = 0;
290 cpi->hba_eng_cnt = 0;
293 cpi->initiator_id = aic->initiator;
294 cpi->bus_id = cam_sim_bus(sim);
295 cpi->base_transfer_speed = 3300;
296 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
297 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
298 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
299 cpi->unit_number = cam_sim_unit(sim);
300 cpi->ccb_h.status = CAM_REQ_CMP;
305 ccb->ccb_h.status = CAM_REQ_INVALID;
312 aic_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
314 struct aic_scb *scb = (struct aic_scb *)arg;
315 union ccb *ccb = scb->ccb;
316 struct aic_softc *aic = (struct aic_softc *)ccb->ccb_h.ccb_aic_ptr;
320 if (ccb->ccb_h.status != CAM_REQ_INPROG) {
322 aic_free_scb(aic, scb);
327 scb->flags |= SCB_ACTIVE;
328 ccb->ccb_h.status |= CAM_SIM_QUEUED;
329 TAILQ_INSERT_TAIL(&aic->pending_ccbs, &ccb->ccb_h, sim_links.tqe);
331 callout_reset(&ccb->ccb_h.timeout_ch, (ccb->ccb_h.timeout * hz) / 1000,
339 * Start another command if the controller is not busy.
342 aic_start(struct aic_softc *aic)
344 struct ccb_hdr *ccb_h;
345 struct aic_tinfo *ti;
347 if (aic->state != AIC_IDLE)
350 TAILQ_FOREACH(ccb_h, &aic->pending_ccbs, sim_links.tqe) {
351 ti = &aic->tinfo[ccb_h->target_id];
352 if ((ti->lubusy & (1 << ccb_h->target_lun)) == 0) {
353 TAILQ_REMOVE(&aic->pending_ccbs, ccb_h, sim_links.tqe);
354 aic->nexus = (struct aic_scb *)ccb_h->ccb_scb_ptr;
360 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_start: idle\n"));
362 aic_outb(aic, SIMODE0, ENSELDI);
363 aic_outb(aic, SIMODE1, ENSCSIRST);
364 aic_outb(aic, SCSISEQ, ENRESELI);
371 aic_select(struct aic_softc *aic)
373 struct aic_scb *scb = aic->nexus;
375 CAM_DEBUG(scb->ccb->ccb_h.path, CAM_DEBUG_TRACE,
376 ("aic_select - ccb %p\n", scb->ccb));
378 aic->state = AIC_SELECTING;
380 aic_outb(aic, DMACNTRL1, 0);
381 aic_outb(aic, SCSIID, aic->initiator << OID_S | scb->target);
382 aic_outb(aic, SXFRCTL1, STIMO_256ms | ENSTIMER |
383 (aic->flags & AIC_PARITY_ENABLE ? ENSPCHK : 0));
385 aic_outb(aic, SIMODE0, ENSELDI|ENSELDO);
386 aic_outb(aic, SIMODE1, ENSCSIRST|ENSELTIMO);
387 aic_outb(aic, SCSISEQ, ENRESELI|ENSELO|ENAUTOATNO);
391 * We have successfully selected a target, prepare for the information
395 aic_selected(struct aic_softc *aic)
397 struct aic_scb *scb = aic->nexus;
398 union ccb *ccb = scb->ccb;
399 struct aic_tinfo *ti = &aic->tinfo[scb->target];
401 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE,
402 ("aic_selected - ccb %p\n", ccb));
404 aic->state = AIC_HASNEXUS;
406 if (scb->flags & SCB_DEVICE_RESET) {
407 aic->msg_buf[0] = MSG_BUS_DEV_RESET;
409 aic->msg_outq = AIC_MSG_MSGBUF;
411 aic->msg_outq = AIC_MSG_IDENTIFY;
412 if ((ti->flags & TINFO_TAG_ENB) != 0 &&
413 (ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0)
414 aic->msg_outq |= AIC_MSG_TAG_Q;
416 ti->lubusy |= 1 << scb->lun;
417 if ((ti->flags & TINFO_SDTR_NEGO) != 0)
418 aic->msg_outq |= AIC_MSG_SDTR;
421 aic_outb(aic, CLRSINT0, CLRSELDO);
422 aic_outb(aic, CLRSINT1, CLRBUSFREE);
423 aic_outb(aic, SCSISEQ, ENAUTOATNP);
424 aic_outb(aic, SIMODE0, 0);
425 aic_outb(aic, SIMODE1, ENSCSIRST|ENBUSFREE|ENREQINIT);
426 aic_outb(aic, SCSIRATE, ti->scsirate);
430 * We are re-selected by a target, save the target id and wait for the
431 * target to further identify itself.
434 aic_reselected(struct aic_softc *aic)
438 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_reselected\n"));
441 * If we have started a selection, it must have lost out in
442 * the arbitration, put the command back to the pending queue.
445 TAILQ_INSERT_HEAD(&aic->pending_ccbs,
446 &aic->nexus->ccb->ccb_h, sim_links.tqe);
450 selid = aic_inb(aic, SELID) & ~(1 << aic->initiator);
451 if (selid & (selid - 1)) {
452 /* this should never have happened */
453 kprintf("aic_reselected: invalid selid %x\n", selid);
454 aic_reset(aic, /*initiate_reset*/TRUE);
458 aic->state = AIC_RESELECTED;
459 aic->target = ffs(selid) - 1;
462 aic_outb(aic, CLRSINT0, CLRSELDI);
463 aic_outb(aic, CLRSINT1, CLRBUSFREE);
464 aic_outb(aic, SIMODE0, 0);
465 aic_outb(aic, SIMODE1, ENSCSIRST|ENBUSFREE|ENREQINIT);
466 aic_outb(aic, SCSISEQ, ENAUTOATNP);
467 aic_outb(aic, SCSIRATE, aic->tinfo[aic->target].scsirate);
471 * Raise ATNO to signal the target that we have a message for it.
474 aic_sched_msgout(struct aic_softc *aic, u_int8_t msg)
477 aic->msg_buf[0] = msg;
480 aic->msg_outq |= AIC_MSG_MSGBUF;
481 aic_outb(aic, SCSISIGO, aic_inb(aic, SCSISIGI) | ATNO);
485 * Wait for SPIORDY (SCSI PIO ready) flag, or a phase change.
488 aic_spiordy(struct aic_softc *aic)
490 while (!(aic_inb(aic, DMASTAT) & INTSTAT) &&
491 !(aic_inb(aic, SSTAT0) & SPIORDY))
493 return !(aic_inb(aic, DMASTAT) & INTSTAT);
497 * Reestablish a disconnected nexus.
500 aic_reconnect(struct aic_softc *aic, int tag)
503 struct ccb_hdr *ccb_h;
505 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_reconnect\n"));
508 TAILQ_FOREACH(ccb_h, &aic->nexus_ccbs, sim_links.tqe) {
509 scb = (struct aic_scb *)ccb_h->ccb_scb_ptr;
510 if (scb->target == aic->target && scb->lun == aic->lun &&
511 (tag == -1 || scb->tag == tag))
515 /* ABORT if nothing is found */
518 aic_sched_msgout(aic, MSG_ABORT);
520 aic_sched_msgout(aic, MSG_ABORT_TAG);
521 xpt_async(AC_UNSOL_RESEL, aic->path, NULL);
525 /* Reestablish the nexus */
526 TAILQ_REMOVE(&aic->nexus_ccbs, ccb_h, sim_links.tqe);
528 scb->flags &= ~SCB_DISCONNECTED;
529 aic->state = AIC_HASNEXUS;
536 aic_msgin(struct aic_softc *aic)
540 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_msgin\n"));
542 aic_outb(aic, SIMODE1, ENSCSIRST|ENPHASEMIS|ENBUSFREE);
543 aic_outb(aic, SXFRCTL0, CHEN|SPIOEN);
545 aic->flags &= ~AIC_DROP_MSGIN;
549 * If a parity error is detected, drop the remaining
550 * bytes and inform the target so it could resend
553 if (aic_inb(aic, SSTAT1) & SCSIPERR) {
554 aic_outb(aic, CLRSINT1, CLRSCSIPERR);
555 aic->flags |= AIC_DROP_MSGIN;
556 aic_sched_msgout(aic, MSG_PARITY_ERROR);
558 if ((aic->flags & AIC_DROP_MSGIN)) {
559 aic_inb(aic, SCSIDAT);
562 /* read the message byte without ACKing on it */
563 aic->msg_buf[aic->msg_len++] = aic_inb(aic, SCSIBUS);
564 if (aic->msg_buf[0] == MSG_EXTENDED) {
565 if (aic->msg_len < 2) {
566 (void) aic_inb(aic, SCSIDAT);
569 switch (aic->msg_buf[2]) {
571 msglen = MSG_EXT_SDTR_LEN;
574 msglen = MSG_EXT_WDTR_LEN;
580 if (aic->msg_buf[1] != msglen) {
581 aic->flags |= AIC_DROP_MSGIN;
582 aic_sched_msgout(aic, MSG_MESSAGE_REJECT);
585 } else if (aic->msg_buf[0] >= 0x20 && aic->msg_buf[0] <= 0x2f)
590 * If we have a complete message, handle it before the final
591 * ACK (in case we decide to reject the message).
593 if (aic->msg_len == msglen) {
594 aic_handle_msgin(aic);
597 /* ACK on the message byte */
598 (void) aic_inb(aic, SCSIDAT);
599 } while (aic_spiordy(aic));
601 aic_outb(aic, SXFRCTL0, CHEN);
602 aic_outb(aic, SIMODE1, ENSCSIRST|ENBUSFREE|ENREQINIT);
609 aic_handle_msgin(struct aic_softc *aic)
612 struct ccb_hdr *ccb_h;
613 struct aic_tinfo *ti;
614 struct ccb_trans_settings neg;
616 if (aic->state == AIC_RESELECTED) {
617 if (!MSG_ISIDENTIFY(aic->msg_buf[0])) {
618 aic_sched_msgout(aic, MSG_MESSAGE_REJECT);
621 aic->lun = aic->msg_buf[0] & MSG_IDENTIFY_LUNMASK;
622 if (aic->tinfo[aic->target].lubusy & (1 << aic->lun))
623 aic_reconnect(aic, -1);
625 aic->state = AIC_RECONNECTING;
629 if (aic->state == AIC_RECONNECTING) {
630 if (aic->msg_buf[0] != MSG_SIMPLE_Q_TAG) {
631 aic_sched_msgout(aic, MSG_MESSAGE_REJECT);
634 aic_reconnect(aic, aic->msg_buf[1]);
638 switch (aic->msg_buf[0]) {
639 case MSG_CMDCOMPLETE: {
640 struct ccb_scsiio *csio;
642 ccb_h = &scb->ccb->ccb_h;
643 csio = &scb->ccb->csio;
644 if ((scb->flags & SCB_SENSE) != 0) {
645 /* auto REQUEST SENSE command */
646 scb->flags &= ~SCB_SENSE;
647 csio->sense_resid = scb->data_len;
648 if (scb->status == SCSI_STATUS_OK) {
650 CAM_SCSI_STATUS_ERROR|CAM_AUTOSNS_VALID;
651 /*scsi_sense_print(csio);*/
653 ccb_h->status |= CAM_AUTOSENSE_FAIL;
654 kprintf("ccb %p sense failed %x\n",
658 csio->scsi_status = scb->status;
659 csio->resid = scb->data_len;
660 if (scb->status == SCSI_STATUS_OK) {
661 /* everything goes well */
662 ccb_h->status |= CAM_REQ_CMP;
663 } else if ((ccb_h->flags & CAM_DIS_AUTOSENSE) == 0 &&
664 (csio->scsi_status == SCSI_STATUS_CHECK_COND ||
665 csio->scsi_status == SCSI_STATUS_CMD_TERMINATED)) {
666 /* try to retrieve sense information */
667 scb->flags |= SCB_SENSE;
668 aic->flags |= AIC_BUSFREE_OK;
671 ccb_h->status |= CAM_SCSI_STATUS_ERROR;
674 aic->flags |= AIC_BUSFREE_OK;
678 switch (aic->msg_buf[2]) {
681 ti = &aic->tinfo[scb->target];
682 if (ti->flags & TINFO_SDTR_SENT) {
683 ti->current.period = aic->msg_buf[3];
684 ti->current.offset = aic->msg_buf[4];
686 ti->current.period = aic->msg_buf[3] =
687 max(ti->goal.period, aic->msg_buf[3]);
688 ti->current.offset = aic->msg_buf[4] =
689 min(ti->goal.offset, aic->msg_buf[4]);
691 * The target initiated the negotiation,
692 * send back a response.
694 aic_sched_msgout(aic, 0);
696 ti->flags &= ~(TINFO_SDTR_SENT|TINFO_SDTR_NEGO);
697 ti->scsirate = ti->current.offset ? ti->current.offset |
698 ((ti->current.period * 4 + 49) / 50 - 2) << 4 : 0;
699 aic_outb(aic, SCSIRATE, ti->scsirate);
700 neg.sync_period = ti->goal.period = ti->current.period;
701 neg.sync_offset = ti->goal.offset = ti->current.offset;
702 neg.valid = CCB_TRANS_SYNC_RATE_VALID
703 | CCB_TRANS_SYNC_OFFSET_VALID;
704 ccb_h = &scb->ccb->ccb_h;
705 xpt_setup_ccb(&neg.ccb_h, ccb_h->path, 1);
706 xpt_async(AC_TRANSFER_NEG, ccb_h->path, &neg);
710 aic_sched_msgout(aic, MSG_MESSAGE_REJECT);
716 ccb_h = &scb->ccb->ccb_h;
717 TAILQ_INSERT_TAIL(&aic->nexus_ccbs, ccb_h, sim_links.tqe);
718 scb->flags |= SCB_DISCONNECTED;
719 aic->flags |= AIC_BUSFREE_OK;
721 CAM_DEBUG(ccb_h->path, CAM_DEBUG_TRACE, ("disconnected\n"));
723 case MSG_MESSAGE_REJECT:
724 switch (aic->msg_outq & -aic->msg_outq) {
727 ti = &aic->tinfo[scb->target];
728 ti->flags &= ~TINFO_TAG_ENB;
729 ti->lubusy |= 1 << scb->lun;
733 ti = &aic->tinfo[scb->target];
734 ti->current.period = ti->goal.period = 0;
735 ti->current.offset = ti->goal.offset = 0;
736 ti->flags &= ~(TINFO_SDTR_SENT|TINFO_SDTR_NEGO);
738 aic_outb(aic, SCSIRATE, ti->scsirate);
739 neg.sync_period = ti->current.period;
740 neg.sync_offset = ti->current.offset;
741 neg.valid = CCB_TRANS_SYNC_RATE_VALID
742 | CCB_TRANS_SYNC_OFFSET_VALID;
743 ccb_h = &scb->ccb->ccb_h;
744 xpt_setup_ccb(&neg.ccb_h, ccb_h->path, 1);
745 xpt_async(AC_TRANSFER_NEG, ccb_h->path, &neg);
751 case MSG_SAVEDATAPOINTER:
753 case MSG_RESTOREPOINTERS:
758 aic_sched_msgout(aic, MSG_MESSAGE_REJECT);
767 aic_msgout(struct aic_softc *aic)
771 struct aic_tinfo *ti;
774 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_msgout\n"));
776 aic_outb(aic, SIMODE1, ENSCSIRST|ENPHASEMIS|ENBUSFREE);
777 aic_outb(aic, SXFRCTL0, CHEN|SPIOEN);
780 * If the previous phase is also the message out phase,
781 * we need to retransmit all the messages, probably
782 * because the target has detected a parity error during
783 * the past transmission.
785 if (aic->prev_phase == PH_MSGOUT)
786 aic->msg_outq = aic->msg_sent;
789 int q = aic->msg_outq;
790 if (msgidx > 0 && msgidx == aic->msg_len) {
791 /* complete message sent, start the next one */
799 /* setup the message */
801 case AIC_MSG_IDENTIFY:
804 ti = &aic->tinfo[scb->target];
805 aic->msg_buf[0] = MSG_IDENTIFY(scb->lun,
806 (ti->flags & TINFO_DISC_ENB) &&
807 !(ccb->ccb_h.flags & CAM_DIS_DISCONNECT));
813 aic->msg_buf[0] = ccb->csio.tag_action;
814 aic->msg_buf[1] = scb->tag;
819 ti = &aic->tinfo[scb->target];
820 aic->msg_buf[0] = MSG_EXTENDED;
821 aic->msg_buf[1] = MSG_EXT_SDTR_LEN;
822 aic->msg_buf[2] = MSG_EXT_SDTR;
823 aic->msg_buf[3] = ti->goal.period;
824 aic->msg_buf[4] = ti->goal.offset;
825 aic->msg_len = MSG_EXT_SDTR_LEN + 2;
826 ti->flags |= TINFO_SDTR_SENT;
829 /* a single message already in the buffer */
830 if (aic->msg_buf[0] == MSG_BUS_DEV_RESET ||
831 aic->msg_buf[0] == MSG_ABORT ||
832 aic->msg_buf[0] == MSG_ABORT_TAG)
833 aic->flags |= AIC_BUSFREE_OK;
838 * If this is the last message byte of all messages,
839 * clear ATNO to signal transmission complete.
841 if ((q & (q - 1)) == 0 && msgidx == aic->msg_len - 1)
842 aic_outb(aic, CLRSINT1, CLRATNO);
843 /* transmit the message byte */
844 aic_outb(aic, SCSIDAT, aic->msg_buf[msgidx++]);
845 } while (aic_spiordy(aic));
847 aic_outb(aic, SXFRCTL0, CHEN);
848 aic_outb(aic, SIMODE1, ENSCSIRST|ENBUSFREE|ENREQINIT);
855 aic_datain(struct aic_softc *aic)
857 struct aic_scb *scb = aic->nexus;
858 u_int8_t dmastat, dmacntrl0;
861 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_datain\n"));
863 aic_outb(aic, SIMODE1, ENSCSIRST|ENPHASEMIS|ENBUSFREE);
864 aic_outb(aic, SXFRCTL0, SCSIEN|DMAEN|CHEN);
867 if (aic->flags & AIC_DWIO_ENABLE)
868 dmacntrl0 |= DWORDPIO;
869 aic_outb(aic, DMACNTRL0, dmacntrl0);
871 while (scb->data_len > 0) {
873 /* wait for the fifo to fill up or a phase change */
874 dmastat = aic_inb(aic, DMASTAT);
875 if (dmastat & (INTSTAT|DFIFOFULL))
878 if (dmastat & DFIFOFULL) {
882 * No more data, wait for the remaining bytes in
883 * the scsi fifo to be transfer to the host fifo.
885 while (!(aic_inb(aic, SSTAT2) & SEMPTY))
887 n = aic_inb(aic, FIFOSTAT);
889 n = imin(scb->data_len, n);
890 if (aic->flags & AIC_DWIO_ENABLE) {
892 aic_insl(aic, DMADATALONG, scb->data_ptr, n>>2);
893 scb->data_ptr += n & ~3;
894 scb->data_len -= n & ~3;
899 aic_insw(aic, DMADATA, scb->data_ptr, n >> 1);
900 scb->data_ptr += n & ~1;
901 scb->data_len -= n & ~1;
906 aic_outb(aic, DMACNTRL0, ENDMA|B8MODE);
907 aic_insb(aic, DMADATA, scb->data_ptr, n);
910 aic_outb(aic, DMACNTRL0, dmacntrl0);
913 if (dmastat & INTSTAT)
917 aic_outb(aic, SXFRCTL0, CHEN);
918 aic_outb(aic, SIMODE1, ENSCSIRST|ENBUSFREE|ENREQINIT);
925 aic_dataout(struct aic_softc *aic)
927 struct aic_scb *scb = aic->nexus;
928 u_int8_t dmastat, dmacntrl0, sstat2;
931 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_dataout\n"));
933 aic_outb(aic, SIMODE1, ENSCSIRST|ENPHASEMIS|ENBUSFREE);
934 aic_outb(aic, SXFRCTL0, SCSIEN|DMAEN|CHEN);
936 dmacntrl0 = ENDMA|WRITE;
937 if (aic->flags & AIC_DWIO_ENABLE)
938 dmacntrl0 |= DWORDPIO;
939 aic_outb(aic, DMACNTRL0, dmacntrl0);
941 while (scb->data_len > 0) {
943 /* wait for the fifo to clear up or a phase change */
944 dmastat = aic_inb(aic, DMASTAT);
945 if (dmastat & (INTSTAT|DFIFOEMP))
948 if (dmastat & INTSTAT)
950 n = imin(scb->data_len, FIFOSIZE);
951 if (aic->flags & AIC_DWIO_ENABLE) {
953 aic_outsl(aic, DMADATALONG, scb->data_ptr,n>>2);
954 scb->data_ptr += n & ~3;
955 scb->data_len -= n & ~3;
960 aic_outsw(aic, DMADATA, scb->data_ptr, n >> 1);
961 scb->data_ptr += n & ~1;
962 scb->data_len -= n & ~1;
967 aic_outb(aic, DMACNTRL0, ENDMA|WRITE|B8MODE);
968 aic_outsb(aic, DMADATA, scb->data_ptr, n);
971 aic_outb(aic, DMACNTRL0, dmacntrl0);
976 /* wait until all bytes in the fifos are transmitted */
977 dmastat = aic_inb(aic, DMASTAT);
978 sstat2 = aic_inb(aic, SSTAT2);
979 if ((dmastat & DFIFOEMP) && (sstat2 & SEMPTY))
981 if (dmastat & INTSTAT) {
982 /* adjust for untransmitted bytes */
983 n = aic_inb(aic, FIFOSTAT) + (sstat2 & 0xf);
987 aic_outb(aic, SXFRCTL0, CHEN|CLRCH);
988 aic_outb(aic, DMACNTRL0, RSTFIFO);
993 aic_outb(aic, SXFRCTL0, CHEN);
994 aic_outb(aic, SIMODE1, ENSCSIRST|ENBUSFREE|ENREQINIT);
998 * Send the scsi command.
1001 aic_cmd(struct aic_softc *aic)
1003 struct aic_scb *scb = aic->nexus;
1004 struct scsi_request_sense sense_cmd;
1006 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_cmd\n"));
1008 if (scb->flags & SCB_SENSE) {
1009 /* autosense request */
1010 sense_cmd.opcode = REQUEST_SENSE;
1011 sense_cmd.byte2 = scb->lun << 5;
1012 sense_cmd.length = scb->ccb->csio.sense_len;
1013 sense_cmd.control = 0;
1014 sense_cmd.unused[0] = 0;
1015 sense_cmd.unused[1] = 0;
1016 scb->cmd_ptr = (u_int8_t *)&sense_cmd;
1017 scb->cmd_len = sizeof(sense_cmd);
1018 scb->data_ptr = (u_int8_t *)&scb->ccb->csio.sense_data;
1019 scb->data_len = scb->ccb->csio.sense_len;
1022 aic_outb(aic, SIMODE1, ENSCSIRST|ENPHASEMIS|ENBUSFREE);
1023 aic_outb(aic, DMACNTRL0, ENDMA|WRITE);
1024 aic_outb(aic, SXFRCTL0, SCSIEN|DMAEN|CHEN);
1025 aic_outsw(aic, DMADATA, (u_int16_t *)scb->cmd_ptr, scb->cmd_len >> 1);
1026 while ((aic_inb(aic, SSTAT2) & SEMPTY) == 0 &&
1027 (aic_inb(aic, DMASTAT) & INTSTAT) == 0)
1029 aic_outb(aic, SXFRCTL0, CHEN);
1030 aic_outb(aic, SIMODE1, ENSCSIRST|ENBUSFREE|ENREQINIT);
1034 * Finish off a command. The caller is responsible to remove the ccb
1038 aic_done(struct aic_softc *aic, struct aic_scb *scb)
1040 union ccb *ccb = scb->ccb;
1042 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE,
1043 ("aic_done - ccb %p status %x resid %d\n",
1044 ccb, ccb->ccb_h.status, ccb->csio.resid));
1046 callout_stop(&ccb->ccb_h.timeout_ch);
1048 if ((scb->flags & SCB_DEVICE_RESET) != 0 &&
1049 ccb->ccb_h.func_code != XPT_RESET_DEV) {
1050 struct cam_path *path;
1051 struct ccb_hdr *ccb_h;
1054 error = xpt_create_path(&path, /*periph*/NULL,
1055 cam_sim_path(aic->sim),
1059 if (error == CAM_REQ_CMP) {
1060 xpt_async(AC_SENT_BDR, path, NULL);
1061 xpt_free_path(path);
1064 ccb_h = TAILQ_FIRST(&aic->pending_ccbs);
1065 while (ccb_h != NULL) {
1066 struct aic_scb *pending_scb;
1068 pending_scb = (struct aic_scb *)ccb_h->ccb_scb_ptr;
1069 if (ccb_h->target_id == scb->target) {
1070 ccb_h->status |= CAM_BDR_SENT;
1071 ccb_h = TAILQ_NEXT(ccb_h, sim_links.tqe);
1072 TAILQ_REMOVE(&aic->pending_ccbs,
1073 &pending_scb->ccb->ccb_h, sim_links.tqe);
1074 aic_done(aic, pending_scb);
1076 callout_reset(&ccb_h->timeout_ch,
1077 (ccb_h->timeout * hz) / 1000,
1078 aic_timeout, pending_scb);
1079 ccb_h = TAILQ_NEXT(ccb_h, sim_links.tqe);
1083 ccb_h = TAILQ_FIRST(&aic->nexus_ccbs);
1084 while (ccb_h != NULL) {
1085 struct aic_scb *nexus_scb;
1087 nexus_scb = (struct aic_scb *)ccb_h->ccb_scb_ptr;
1088 if (ccb_h->target_id == scb->target) {
1089 ccb_h->status |= CAM_BDR_SENT;
1090 ccb_h = TAILQ_NEXT(ccb_h, sim_links.tqe);
1091 TAILQ_REMOVE(&aic->nexus_ccbs,
1092 &nexus_scb->ccb->ccb_h, sim_links.tqe);
1093 aic_done(aic, nexus_scb);
1095 callout_reset(&ccb_h->timeout_ch,
1096 (ccb_h->timeout * hz) / 1000,
1097 aic_timeout, nexus_scb);
1098 ccb_h = TAILQ_NEXT(ccb_h, sim_links.tqe);
1103 if (aic->nexus == scb || scb->flags & SCB_DISCONNECTED)
1104 aic->tinfo[scb->target].lubusy &= ~(1 << scb->lun);
1106 if (aic->nexus == scb) {
1109 aic_free_scb(aic, scb);
1114 aic_poll(struct cam_sim *sim)
1116 aic_intr(cam_sim_softc(sim));
1120 aic_timeout(void *arg)
1122 struct aic_scb *scb = (struct aic_scb *)arg;
1123 union ccb *ccb = scb->ccb;
1124 struct aic_softc *aic = (struct aic_softc *)ccb->ccb_h.ccb_aic_ptr;
1126 xpt_print_path(ccb->ccb_h.path);
1127 kprintf("ccb %p - timed out", ccb);
1128 if (aic->nexus && aic->nexus != scb)
1129 kprintf(", nexus %p", aic->nexus->ccb);
1130 kprintf(", phase 0x%x, state %d\n", aic_inb(aic, SCSISIGI), aic->state);
1134 if ((scb->flags & SCB_ACTIVE) == 0) {
1136 xpt_print_path(ccb->ccb_h.path);
1137 kprintf("ccb %p - timed out already completed\n", ccb);
1141 if ((scb->flags & SCB_DEVICE_RESET) == 0 && aic->nexus == scb) {
1142 struct ccb_hdr *ccb_h = &scb->ccb->ccb_h;
1144 if ((ccb_h->status & CAM_RELEASE_SIMQ) == 0) {
1145 xpt_freeze_simq(aic->sim, /*count*/1);
1146 ccb_h->status |= CAM_RELEASE_SIMQ;
1149 TAILQ_FOREACH(ccb_h, &aic->pending_ccbs, sim_links.tqe)
1150 callout_stop(&ccb_h->timeout_ch);
1152 TAILQ_FOREACH(ccb_h, &aic->nexus_ccbs, sim_links.tqe)
1153 callout_stop(&ccb_h->timeout_ch);
1155 scb->flags |= SCB_DEVICE_RESET;
1156 callout_reset(&ccb->ccb_h.timeout_ch, 5 * hz, aic_timeout, scb);
1157 aic_sched_msgout(aic, MSG_BUS_DEV_RESET);
1159 if (aic->nexus == scb) {
1160 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
1163 aic_reset(aic, /*initiate_reset*/TRUE);
1172 struct aic_softc *aic = (struct aic_softc *)arg;
1173 u_int8_t sstat0, sstat1;
1175 struct aic_scb *scb;
1177 if (!(aic_inb(aic, DMASTAT) & INTSTAT))
1180 aic_outb(aic, DMACNTRL0, 0);
1182 sstat0 = aic_inb(aic, SSTAT0);
1183 sstat1 = aic_inb(aic, SSTAT1);
1185 if ((sstat1 & SCSIRSTI) != 0) {
1186 /* a device-initiated bus reset */
1187 aic_outb(aic, CLRSINT1, CLRSCSIRSTI);
1188 aic_reset(aic, /*initiate_reset*/FALSE);
1192 if ((sstat1 & SCSIPERR) != 0) {
1193 aic_outb(aic, CLRSINT1, CLRSCSIPERR);
1194 aic_sched_msgout(aic, MSG_PARITY_ERROR);
1195 aic_outb(aic, DMACNTRL0, INTEN);
1199 if (aic_inb(aic, SSTAT4)) {
1200 aic_outb(aic, CLRSERR, CLRSYNCERR|CLRFWERR|CLRFRERR);
1201 aic_reset(aic, /*initiate_reset*/TRUE);
1205 if (aic->state <= AIC_SELECTING) {
1206 if ((sstat0 & SELDI) != 0) {
1207 aic_reselected(aic);
1208 aic_outb(aic, DMACNTRL0, INTEN);
1212 if ((sstat0 & SELDO) != 0) {
1214 aic_outb(aic, DMACNTRL0, INTEN);
1218 if ((sstat1 & SELTO) != 0) {
1221 ccb->ccb_h.status = CAM_SEL_TIMEOUT;
1223 while ((sstat1 & BUSFREE) == 0)
1224 sstat1 = aic_inb(aic, SSTAT1);
1225 aic->flags |= AIC_BUSFREE_OK;
1229 if ((sstat1 & BUSFREE) != 0) {
1230 aic_outb(aic, SCSISEQ, 0);
1231 aic_outb(aic, CLRSINT0, sstat0);
1232 aic_outb(aic, CLRSINT1, sstat1);
1233 if ((scb = aic->nexus)) {
1234 if ((aic->flags & AIC_BUSFREE_OK) == 0) {
1236 ccb->ccb_h.status = CAM_UNEXP_BUSFREE;
1238 } else if (scb->flags & SCB_DEVICE_RESET) {
1240 if (ccb->ccb_h.func_code == XPT_RESET_DEV) {
1241 xpt_async(AC_SENT_BDR,
1242 ccb->ccb_h.path, NULL);
1243 ccb->ccb_h.status |= CAM_REQ_CMP;
1245 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
1247 } else if (scb->flags & SCB_SENSE) {
1248 /* autosense request */
1249 aic->flags &= ~AIC_BUSFREE_OK;
1250 aic->tinfo[scb->target].lubusy &=
1253 aic_outb(aic, DMACNTRL0, INTEN);
1257 aic->flags &= ~AIC_BUSFREE_OK;
1258 aic->state = AIC_IDLE;
1260 aic_outb(aic, DMACNTRL0, INTEN);
1264 if ((sstat1 & REQINIT) != 0) {
1265 u_int8_t phase = aic_inb(aic, SCSISIGI) & PH_MASK;
1266 aic_outb(aic, SCSISIGO, phase);
1267 aic_outb(aic, CLRSINT1, CLRPHASECHG);
1279 aic_outb(aic, DMACNTRL0, 0);
1280 aic_outb(aic, SXFRCTL0, CHEN|SPIOEN);
1281 scb->status = aic_inb(aic, SCSIDAT);
1282 aic_outb(aic, SXFRCTL0, CHEN);
1294 aic->prev_phase = phase;
1295 aic_outb(aic, DMACNTRL0, INTEN);
1299 kprintf("aic_intr: unexpected intr sstat0 %x sstat1 %x\n",
1301 aic_outb(aic, DMACNTRL0, INTEN);
1308 aic_chip_reset(struct aic_softc *aic)
1311 * Doc. recommends to clear these two registers before
1312 * operations commence
1314 aic_outb(aic, SCSITEST, 0);
1315 aic_outb(aic, TEST, 0);
1317 /* Reset SCSI-FIFO and abort any transfers */
1318 aic_outb(aic, SXFRCTL0, CHEN|CLRCH|CLRSTCNT);
1320 /* Reset HOST-FIFO */
1321 aic_outb(aic, DMACNTRL0, RSTFIFO);
1322 aic_outb(aic, DMACNTRL1, 0);
1324 /* Disable all selection features */
1325 aic_outb(aic, SCSISEQ, 0);
1326 aic_outb(aic, SXFRCTL1, 0);
1328 /* Disable interrupts */
1329 aic_outb(aic, SIMODE0, 0);
1330 aic_outb(aic, SIMODE1, 0);
1332 /* Clear interrupts */
1333 aic_outb(aic, CLRSINT0, 0x7f);
1334 aic_outb(aic, CLRSINT1, 0xef);
1336 /* Disable synchronous transfers */
1337 aic_outb(aic, SCSIRATE, 0);
1339 /* Haven't seen ant errors (yet) */
1340 aic_outb(aic, CLRSERR, 0x07);
1342 /* Set our SCSI-ID */
1343 aic_outb(aic, SCSIID, aic->initiator << OID_S);
1344 aic_outb(aic, BRSTCNTRL, EISA_BRST_TIM);
1348 * Reset the SCSI bus
1351 aic_scsi_reset(struct aic_softc *aic)
1353 aic_outb(aic, SCSISEQ, SCSIRSTO);
1355 aic_outb(aic, SCSISEQ, 0);
1360 * Reset. Abort all pending commands.
1363 aic_reset(struct aic_softc *aic, int initiate_reset)
1365 struct ccb_hdr *ccb_h;
1367 CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_reset\n"));
1370 aic_scsi_reset(aic);
1371 aic_chip_reset(aic);
1373 xpt_async(AC_BUS_RESET, aic->path, NULL);
1375 while ((ccb_h = TAILQ_FIRST(&aic->pending_ccbs)) != NULL) {
1376 TAILQ_REMOVE(&aic->pending_ccbs, ccb_h, sim_links.tqe);
1377 ccb_h->status |= CAM_SCSI_BUS_RESET;
1378 aic_done(aic, (struct aic_scb *)ccb_h->ccb_scb_ptr);
1381 while ((ccb_h = TAILQ_FIRST(&aic->nexus_ccbs)) != NULL) {
1382 TAILQ_REMOVE(&aic->nexus_ccbs, ccb_h, sim_links.tqe);
1383 ccb_h->status |= CAM_SCSI_BUS_RESET;
1384 aic_done(aic, (struct aic_scb *)ccb_h->ccb_scb_ptr);
1388 ccb_h = &aic->nexus->ccb->ccb_h;
1389 ccb_h->status |= CAM_SCSI_BUS_RESET;
1390 aic_done(aic, aic->nexus);
1393 aic->state = AIC_IDLE;
1394 aic_outb(aic, DMACNTRL0, INTEN);
1398 aic_init(struct aic_softc *aic)
1400 struct aic_scb *scb;
1401 struct aic_tinfo *ti;
1402 u_int8_t porta, portb;
1405 TAILQ_INIT(&aic->pending_ccbs);
1406 TAILQ_INIT(&aic->nexus_ccbs);
1408 aic->state = AIC_IDLE;
1409 aic->prev_phase = -1;
1412 aic_chip_reset(aic);
1413 aic_scsi_reset(aic);
1415 porta = aic_inb(aic, PORTA);
1416 portb = aic_inb(aic, PORTB);
1418 aic->initiator = PORTA_ID(porta);
1419 if (PORTA_PARITY(porta))
1420 aic->flags |= AIC_PARITY_ENABLE;
1421 if (PORTB_DISC(portb))
1422 aic->flags |= AIC_DISC_ENABLE;
1423 if (PORTB_DMA(portb))
1424 aic->flags |= AIC_DMA_ENABLE;
1425 if (aic_inb(aic, REV))
1426 aic->flags |= AIC_DWIO_ENABLE;
1429 for (i = 255; i >= 0; i--) {
1430 scb = &aic->scbs[i];
1432 aic_free_scb(aic, scb);
1435 for (i = 0; i < 8; i++) {
1436 if (i == aic->initiator)
1438 ti = &aic->tinfo[i];
1439 bzero(ti, sizeof(*ti));
1440 ti->flags = TINFO_TAG_ENB;
1441 if (aic->flags & AIC_DISC_ENABLE)
1442 ti->flags |= TINFO_DISC_ENB;
1443 ti->user.period = AIC_SYNC_PERIOD;
1444 ti->user.offset = AIC_SYNC_OFFSET;
1448 aic_outb(aic, DMACNTRL0, INTEN);
1452 aic_probe(struct aic_softc *aic)
1456 /* Remove aic6360 from possible powerdown mode */
1457 aic_outb(aic, DMACNTRL0, 0);
1460 aic_outb(aic, DMACNTRL1, 0); /* Reset stack pointer */
1461 for (i = 0; i < STSIZE; i++)
1462 aic_outb(aic, STACK, i);
1464 /* See if we can pull out the same sequence */
1465 aic_outb(aic, DMACNTRL1, 0);
1466 for (i = 0; i < STSIZE && aic_inb(aic, STACK) == i; i++)
1475 aic_attach(struct aic_softc *aic)
1478 * Construct our SIM entry
1480 aic->sim = cam_sim_alloc(aic_action, aic_poll, "aic", aic,
1481 aic->unit, 2, 256, NULL);
1482 if (aic->sim == NULL)
1485 if (xpt_bus_register(aic->sim, 0) != CAM_SUCCESS) {
1486 cam_sim_free(aic->sim);
1490 if (xpt_create_path(&aic->path, /*periph*/NULL,
1491 cam_sim_path(aic->sim), CAM_TARGET_WILDCARD,
1492 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
1493 xpt_bus_deregister(cam_sim_path(aic->sim));
1494 cam_sim_free(aic->sim);
1500 kprintf("aic%d: %s", aic->unit,
1501 aic_inb(aic, REV) > 0 ? "aic6360" : "aic6260");
1502 if (aic->flags & AIC_DMA_ENABLE)
1504 if (aic->flags & AIC_DISC_ENABLE)
1505 kprintf(", disconnection");
1506 if (aic->flags & AIC_PARITY_ENABLE)
1507 kprintf(", parity check");
1513 aic_detach(struct aic_softc *aic)
1515 xpt_async(AC_LOST_DEVICE, aic->path, NULL);
1516 xpt_free_path(aic->path);
1517 xpt_bus_deregister(cam_sim_path(aic->sim));
1518 cam_sim_free(aic->sim);