2 * Bus independent FreeBSD shim for the aic7xxx based Adaptec SCSI controllers
4 * Copyright (c) 1994-2001 Justin T. Gibbs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * Alternatively, this software may be distributed under the terms of the
17 * GNU Public License ("GPL").
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.c#20 $
33 * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_osm.c,v 1.44 2005/12/04 02:12:40 ru Exp $
34 * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx_osm.c,v 1.18 2007/07/07 01:06:07 pavalos Exp $
37 #include "aic7xxx_osm.h"
38 #include "aic7xxx_inline.h"
40 #include <sys/kthread.h>
42 #ifndef AHC_TMODE_ENABLE
43 #define AHC_TMODE_ENABLE 0
46 #include "aic_osm_lib.c"
48 #define ccb_scb_ptr spriv_ptr0
50 devclass_t ahc_devclass;
53 static void ahc_dump_targcmd(struct target_cmd *cmd);
55 static int ahc_modevent(module_t mod, int type, void *data);
56 static void ahc_action(struct cam_sim *sim, union ccb *ccb);
57 static void ahc_get_tran_settings(struct ahc_softc *ahc,
58 int our_id, char channel,
59 struct ccb_trans_settings *cts);
60 static void ahc_async(void *callback_arg, uint32_t code,
61 struct cam_path *path, void *arg);
62 static void ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs,
63 int nsegments, int error);
64 static void ahc_poll(struct cam_sim *sim);
65 static void ahc_setup_data(struct ahc_softc *ahc, struct cam_sim *sim,
66 struct ccb_scsiio *csio, struct scb *scb);
67 static void ahc_abort_ccb(struct ahc_softc *ahc, struct cam_sim *sim,
69 static int ahc_create_path(struct ahc_softc *ahc,
70 char channel, u_int target, u_int lun,
71 struct cam_path **path);
75 ahc_create_path(struct ahc_softc *ahc, char channel, u_int target,
76 u_int lun, struct cam_path **path)
81 path_id = cam_sim_path(ahc->platform_data->sim_b);
83 path_id = cam_sim_path(ahc->platform_data->sim);
85 return (xpt_create_path(path, /*periph*/NULL,
86 path_id, target, lun));
90 ahc_map_int(struct ahc_softc *ahc)
97 shareable = (ahc->flags & AHC_EDGE_INTERRUPT) ? 0: RF_SHAREABLE;
98 ahc->platform_data->irq =
99 bus_alloc_resource_any(ahc->dev_softc, SYS_RES_IRQ, &zero,
100 RF_ACTIVE | shareable);
101 if (ahc->platform_data->irq == NULL) {
102 device_printf(ahc->dev_softc,
103 "bus_alloc_resource() failed to allocate IRQ\n");
106 ahc->platform_data->irq_res_type = SYS_RES_IRQ;
108 /* Hook up our interrupt handler */
109 error = bus_setup_intr(ahc->dev_softc, ahc->platform_data->irq,
110 0, ahc_platform_intr, ahc,
111 &ahc->platform_data->ih, NULL);
114 device_printf(ahc->dev_softc, "bus_setup_intr() failed: %d\n",
120 aic7770_map_registers(struct ahc_softc *ahc, u_int unused_ioport_arg)
122 struct resource *regs;
126 regs = bus_alloc_resource_any(ahc->dev_softc, SYS_RES_IOPORT, &rid,
129 device_printf(ahc->dev_softc, "Unable to map I/O space?!\n");
132 ahc->platform_data->regs_res_type = SYS_RES_IOPORT;
133 ahc->platform_data->regs_res_id = rid,
134 ahc->platform_data->regs = regs;
135 ahc->tag = rman_get_bustag(regs);
136 ahc->bsh = rman_get_bushandle(regs);
141 * Attach all the sub-devices we can find
144 ahc_attach(struct ahc_softc *ahc)
147 struct ccb_setasync csa;
151 struct cam_sim *sim2;
152 struct cam_path *path;
153 struct cam_path *path2;
161 * Create a thread to perform all recovery.
163 if (ahc_spawn_recovery_thread(ahc) != 0)
166 ahc_controller_info(ahc, ahc_info);
167 kprintf("%s\n", ahc_info);
171 * Attach secondary channel first if the user has
172 * declared it the primary channel.
174 if ((ahc->features & AHC_TWIN) != 0
175 && (ahc->flags & AHC_PRIMARY_CHANNEL) != 0) {
184 * Construct our first channel SIM entry
186 sim = cam_sim_alloc(ahc_action, ahc_poll, "ahc", ahc,
187 device_get_unit(ahc->dev_softc),
188 1, AHC_MAX_QUEUE, NULL);
192 if (xpt_bus_register(sim, bus_id) != CAM_SUCCESS) {
198 if (xpt_create_path(&path, /*periph*/NULL,
199 cam_sim_path(sim), CAM_TARGET_WILDCARD,
200 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
201 xpt_bus_deregister(cam_sim_path(sim));
207 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
208 csa.ccb_h.func_code = XPT_SASYNC_CB;
209 csa.event_enable = AC_LOST_DEVICE;
210 csa.callback = ahc_async;
211 csa.callback_arg = sim;
212 xpt_action((union ccb *)&csa);
215 if (ahc->features & AHC_TWIN) {
216 sim2 = cam_sim_alloc(ahc_action, ahc_poll, "ahc",
217 ahc, device_get_unit(ahc->dev_softc), 1,
218 AHC_MAX_QUEUE, NULL);
221 kprintf("ahc_attach: Unable to attach second "
222 "bus due to resource shortage");
226 if (xpt_bus_register(sim2, bus_id2) != CAM_SUCCESS) {
227 kprintf("ahc_attach: Unable to attach second "
228 "bus due to resource shortage");
230 * We do not want to destroy the device queue
231 * because the first bus is using it.
237 if (xpt_create_path(&path2, /*periph*/NULL,
240 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
241 xpt_bus_deregister(cam_sim_path(sim2));
246 xpt_setup_ccb(&csa.ccb_h, path2, /*priority*/5);
247 csa.ccb_h.func_code = XPT_SASYNC_CB;
248 csa.event_enable = AC_LOST_DEVICE;
249 csa.callback = ahc_async;
250 csa.callback_arg = sim2;
251 xpt_action((union ccb *)&csa);
256 if ((ahc->features & AHC_TWIN) != 0
257 && (ahc->flags & AHC_PRIMARY_CHANNEL) != 0) {
258 ahc->platform_data->sim_b = sim;
259 ahc->platform_data->path_b = path;
260 ahc->platform_data->sim = sim2;
261 ahc->platform_data->path = path2;
263 ahc->platform_data->sim = sim;
264 ahc->platform_data->path = path;
265 ahc->platform_data->sim_b = sim2;
266 ahc->platform_data->path_b = path2;
270 /* We have to wait until after any system dumps... */
271 ahc->platform_data->eh =
272 EVENTHANDLER_REGISTER(shutdown_post_sync, ahc_shutdown,
273 ahc, SHUTDOWN_PRI_DEFAULT);
274 ahc_intr_enable(ahc, TRUE);
282 * Catch an interrupt from the adapter
285 ahc_platform_intr(void *arg)
287 struct ahc_softc *ahc;
289 ahc = (struct ahc_softc *)arg;
294 * We have an scb which has been processed by the
295 * adaptor, now we look to see how the operation
299 ahc_done(struct ahc_softc *ahc, struct scb *scb)
303 CAM_DEBUG(scb->io_ctx->ccb_h.path, CAM_DEBUG_TRACE,
304 ("ahc_done - scb %d\n", scb->hscb->tag));
307 LIST_REMOVE(scb, pending_links);
308 if ((scb->flags & SCB_TIMEDOUT) != 0)
309 LIST_REMOVE(scb, timedout_links);
310 if ((scb->flags & SCB_UNTAGGEDQ) != 0) {
311 struct scb_tailq *untagged_q;
314 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
315 untagged_q = &ahc->untagged_queues[target_offset];
316 TAILQ_REMOVE(untagged_q, scb, links.tqe);
317 scb->flags &= ~SCB_UNTAGGEDQ;
318 ahc_run_untagged_queue(ahc, untagged_q);
321 callout_stop(&ccb->ccb_h.timeout_ch);
323 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
326 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
327 op = BUS_DMASYNC_POSTREAD;
329 op = BUS_DMASYNC_POSTWRITE;
330 bus_dmamap_sync(ahc->buffer_dmat, scb->dmamap, op);
331 bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap);
334 if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) {
335 struct cam_path *ccb_path;
338 * If we have finally disconnected, clean up our
339 * pending device state.
340 * XXX - There may be error states that cause where
341 * we will remain connected.
343 ccb_path = ccb->ccb_h.path;
344 if (ahc->pending_device != NULL
345 && xpt_path_comp(ahc->pending_device->path, ccb_path) == 0) {
347 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
348 ahc->pending_device = NULL;
351 xpt_print_path(ccb->ccb_h.path);
352 kprintf("Still connected\n");
358 if (aic_get_transaction_status(scb) == CAM_REQ_INPROG)
359 ccb->ccb_h.status |= CAM_REQ_CMP;
360 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
361 ahc_free_scb(ahc, scb);
367 * If the recovery SCB completes, we have to be
368 * out of our timeout.
370 if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
371 struct scb *list_scb;
373 ahc->scb_data->recovery_scbs--;
375 if (aic_get_transaction_status(scb) == CAM_BDR_SENT
376 || aic_get_transaction_status(scb) == CAM_REQ_ABORTED)
377 aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
379 if (ahc->scb_data->recovery_scbs == 0) {
381 * All recovery actions have completed successfully,
382 * so reinstate the timeouts for all other pending
385 LIST_FOREACH(list_scb, &ahc->pending_scbs,
388 aic_scb_timer_reset(list_scb,
389 aic_get_timeout(scb));
392 ahc_print_path(ahc, scb);
393 kprintf("no longer in timeout, status = %x\n",
398 /* Don't clobber any existing error state */
399 if (aic_get_transaction_status(scb) == CAM_REQ_INPROG) {
400 ccb->ccb_h.status |= CAM_REQ_CMP;
401 } else if ((scb->flags & SCB_SENSE) != 0) {
403 * We performed autosense retrieval.
405 * Zero any sense not transferred by the
406 * device. The SCSI spec mandates that any
407 * untransfered data should be assumed to be
408 * zero. Complete the 'bounce' of sense information
409 * through buffers accessible via bus-space by
410 * copying it into the clients csio.
412 memset(&ccb->csio.sense_data, 0, sizeof(ccb->csio.sense_data));
413 memcpy(&ccb->csio.sense_data,
414 ahc_get_sense_buf(ahc, scb),
415 (aic_le32toh(scb->sg_list->len) & AHC_SG_LEN_MASK)
416 - ccb->csio.sense_resid);
417 scb->io_ctx->ccb_h.status |= CAM_AUTOSNS_VALID;
419 ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
420 ahc_free_scb(ahc, scb);
425 ahc_action(struct cam_sim *sim, union ccb *ccb)
427 struct ahc_softc *ahc;
428 struct ahc_tmode_lstate *lstate;
432 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("ahc_action\n"));
434 ahc = (struct ahc_softc *)cam_sim_softc(sim);
436 target_id = ccb->ccb_h.target_id;
437 our_id = SIM_SCSI_ID(ahc, sim);
439 switch (ccb->ccb_h.func_code) {
440 /* Common cases first */
441 case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */
442 case XPT_CONT_TARGET_IO:/* Continue Host Target I/O Connection*/
444 struct ahc_tmode_tstate *tstate;
447 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate,
450 if (status != CAM_REQ_CMP) {
451 if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) {
452 /* Response from the black hole device */
454 lstate = ahc->black_hole;
456 ccb->ccb_h.status = status;
461 if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
464 SLIST_INSERT_HEAD(&lstate->accept_tios, &ccb->ccb_h,
466 ccb->ccb_h.status = CAM_REQ_INPROG;
467 if ((ahc->flags & AHC_TQINFIFO_BLOCKED) != 0)
468 ahc_run_tqinfifo(ahc, /*paused*/FALSE);
474 * The target_id represents the target we attempt to
475 * select. In target mode, this is the initiator of
476 * the original command.
479 target_id = ccb->csio.init_id;
482 case XPT_SCSI_IO: /* Execute the requested I/O operation */
483 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
486 struct hardware_scb *hscb;
488 if ((ahc->flags & AHC_INITIATORROLE) == 0
489 && (ccb->ccb_h.func_code == XPT_SCSI_IO
490 || ccb->ccb_h.func_code == XPT_RESET_DEV)) {
491 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
500 if ((scb = ahc_get_scb(ahc)) == NULL) {
502 xpt_freeze_simq(sim, /*count*/1);
503 ahc->flags |= AHC_RESOURCE_SHORTAGE;
505 ccb->ccb_h.status = CAM_REQUEUE_REQ;
513 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_SUBTRACE,
514 ("start scb(%p)\n", scb));
517 * So we can find the SCB when an abort is requested
519 ccb->ccb_h.ccb_scb_ptr = scb;
522 * Put all the arguments for the xfer in the scb
525 hscb->scsiid = BUILD_SCSIID(ahc, sim, target_id, our_id);
526 hscb->lun = ccb->ccb_h.target_lun;
527 if (ccb->ccb_h.func_code == XPT_RESET_DEV) {
529 scb->flags |= SCB_DEVICE_RESET;
530 hscb->control |= MK_MESSAGE;
531 ahc_execute_scb(scb, NULL, 0, 0);
533 if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) {
534 struct target_data *tdata;
536 tdata = &hscb->shared_data.tdata;
537 if (ahc->pending_device == lstate)
538 scb->flags |= SCB_TARGET_IMMEDIATE;
539 hscb->control |= TARGET_SCB;
540 scb->flags |= SCB_TARGET_SCB;
541 tdata->target_phases = 0;
542 if ((ccb->ccb_h.flags & CAM_SEND_STATUS) != 0) {
543 tdata->target_phases |= SPHASE_PENDING;
545 ccb->csio.scsi_status;
547 if (ccb->ccb_h.flags & CAM_DIS_DISCONNECT)
548 tdata->target_phases |= NO_DISCONNECT;
550 tdata->initiator_tag = ccb->csio.tag_id;
552 if (ccb->ccb_h.flags & CAM_TAG_ACTION_VALID)
553 hscb->control |= ccb->csio.tag_action;
555 ahc_setup_data(ahc, sim, &ccb->csio, scb);
560 case XPT_IMMED_NOTIFY:
562 struct ahc_tmode_tstate *tstate;
563 struct ahc_tmode_lstate *lstate;
566 status = ahc_find_tmode_devs(ahc, sim, ccb, &tstate,
569 if (status != CAM_REQ_CMP) {
570 ccb->ccb_h.status = status;
574 SLIST_INSERT_HEAD(&lstate->immed_notifies, &ccb->ccb_h,
576 ccb->ccb_h.status = CAM_REQ_INPROG;
577 ahc_send_lstate_events(ahc, lstate);
580 case XPT_EN_LUN: /* Enable LUN as a target */
581 ahc_handle_en_lun(ahc, sim, ccb);
584 case XPT_ABORT: /* Abort the specified CCB */
586 ahc_abort_ccb(ahc, sim, ccb);
589 case XPT_SET_TRAN_SETTINGS:
591 #ifdef AHC_NEW_TRAN_SETTINGS
592 struct ahc_devinfo devinfo;
593 struct ccb_trans_settings *cts;
594 struct ccb_trans_settings_scsi *scsi;
595 struct ccb_trans_settings_spi *spi;
596 struct ahc_initiator_tinfo *tinfo;
597 struct ahc_tmode_tstate *tstate;
598 uint16_t *discenable;
603 scsi = &cts->proto_specific.scsi;
604 spi = &cts->xport_specific.spi;
605 ahc_compile_devinfo(&devinfo, SIM_SCSI_ID(ahc, sim),
606 cts->ccb_h.target_id,
607 cts->ccb_h.target_lun,
608 SIM_CHANNEL(ahc, sim),
610 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
612 devinfo.target, &tstate);
614 if (cts->type == CTS_TYPE_CURRENT_SETTINGS) {
615 update_type |= AHC_TRANS_GOAL;
616 discenable = &tstate->discenable;
617 tagenable = &tstate->tagenable;
618 tinfo->curr.protocol_version =
619 cts->protocol_version;
620 tinfo->curr.transport_version =
621 cts->transport_version;
622 tinfo->goal.protocol_version =
623 cts->protocol_version;
624 tinfo->goal.transport_version =
625 cts->transport_version;
626 } else if (cts->type == CTS_TYPE_USER_SETTINGS) {
627 update_type |= AHC_TRANS_USER;
628 discenable = &ahc->user_discenable;
629 tagenable = &ahc->user_tagenable;
630 tinfo->user.protocol_version =
631 cts->protocol_version;
632 tinfo->user.transport_version =
633 cts->transport_version;
635 ccb->ccb_h.status = CAM_REQ_INVALID;
642 if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
643 if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
644 *discenable |= devinfo.target_mask;
646 *discenable &= ~devinfo.target_mask;
649 if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
650 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
651 *tagenable |= devinfo.target_mask;
653 *tagenable &= ~devinfo.target_mask;
656 if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) {
657 ahc_validate_width(ahc, /*tinfo limit*/NULL,
658 &spi->bus_width, ROLE_UNKNOWN);
659 ahc_set_width(ahc, &devinfo, spi->bus_width,
660 update_type, /*paused*/FALSE);
663 if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0) {
664 if (update_type == AHC_TRANS_USER)
665 spi->ppr_options = tinfo->user.ppr_options;
667 spi->ppr_options = tinfo->goal.ppr_options;
670 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0) {
671 if (update_type == AHC_TRANS_USER)
672 spi->sync_offset = tinfo->user.offset;
674 spi->sync_offset = tinfo->goal.offset;
677 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
678 if (update_type == AHC_TRANS_USER)
679 spi->sync_period = tinfo->user.period;
681 spi->sync_period = tinfo->goal.period;
684 if (((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0)
685 || ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)) {
686 struct ahc_syncrate *syncrate;
689 if ((ahc->features & AHC_ULTRA2) != 0)
690 maxsync = AHC_SYNCRATE_DT;
691 else if ((ahc->features & AHC_ULTRA) != 0)
692 maxsync = AHC_SYNCRATE_ULTRA;
694 maxsync = AHC_SYNCRATE_FAST;
696 if (spi->bus_width != MSG_EXT_WDTR_BUS_16_BIT)
697 spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ;
699 syncrate = ahc_find_syncrate(ahc, &spi->sync_period,
702 ahc_validate_offset(ahc, /*tinfo limit*/NULL,
703 syncrate, &spi->sync_offset,
704 spi->bus_width, ROLE_UNKNOWN);
706 /* We use a period of 0 to represent async */
707 if (spi->sync_offset == 0) {
708 spi->sync_period = 0;
709 spi->ppr_options = 0;
712 ahc_set_syncrate(ahc, &devinfo, syncrate,
713 spi->sync_period, spi->sync_offset,
714 spi->ppr_options, update_type,
718 ccb->ccb_h.status = CAM_REQ_CMP;
721 struct ahc_devinfo devinfo;
722 struct ccb_trans_settings *cts;
723 struct ahc_initiator_tinfo *tinfo;
724 struct ahc_tmode_tstate *tstate;
725 uint16_t *discenable;
730 ahc_compile_devinfo(&devinfo, SIM_SCSI_ID(ahc, sim),
731 cts->ccb_h.target_id,
732 cts->ccb_h.target_lun,
733 SIM_CHANNEL(ahc, sim),
735 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
737 devinfo.target, &tstate);
739 if ((cts->flags & CCB_TRANS_CURRENT_SETTINGS) != 0) {
740 update_type |= AHC_TRANS_GOAL;
741 discenable = &tstate->discenable;
742 tagenable = &tstate->tagenable;
743 } else if ((cts->flags & CCB_TRANS_USER_SETTINGS) != 0) {
744 update_type |= AHC_TRANS_USER;
745 discenable = &ahc->user_discenable;
746 tagenable = &ahc->user_tagenable;
748 ccb->ccb_h.status = CAM_REQ_INVALID;
755 if ((cts->valid & CCB_TRANS_DISC_VALID) != 0) {
756 if ((cts->flags & CCB_TRANS_DISC_ENB) != 0)
757 *discenable |= devinfo.target_mask;
759 *discenable &= ~devinfo.target_mask;
762 if ((cts->valid & CCB_TRANS_TQ_VALID) != 0) {
763 if ((cts->flags & CCB_TRANS_TAG_ENB) != 0)
764 *tagenable |= devinfo.target_mask;
766 *tagenable &= ~devinfo.target_mask;
769 if ((cts->valid & CCB_TRANS_BUS_WIDTH_VALID) != 0) {
770 ahc_validate_width(ahc, /*tinfo limit*/NULL,
771 &cts->bus_width, ROLE_UNKNOWN);
772 ahc_set_width(ahc, &devinfo, cts->bus_width,
773 update_type, /*paused*/FALSE);
776 if ((cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) == 0) {
777 if (update_type == AHC_TRANS_USER)
778 cts->sync_offset = tinfo->user.offset;
780 cts->sync_offset = tinfo->goal.offset;
783 if ((cts->valid & CCB_TRANS_SYNC_RATE_VALID) == 0) {
784 if (update_type == AHC_TRANS_USER)
785 cts->sync_period = tinfo->user.period;
787 cts->sync_period = tinfo->goal.period;
790 if (((cts->valid & CCB_TRANS_SYNC_RATE_VALID) != 0)
791 || ((cts->valid & CCB_TRANS_SYNC_OFFSET_VALID) != 0)) {
792 struct ahc_syncrate *syncrate;
796 if ((ahc->features & AHC_ULTRA2) != 0)
797 maxsync = AHC_SYNCRATE_DT;
798 else if ((ahc->features & AHC_ULTRA) != 0)
799 maxsync = AHC_SYNCRATE_ULTRA;
801 maxsync = AHC_SYNCRATE_FAST;
804 if (cts->sync_period <= 9
805 && cts->bus_width == MSG_EXT_WDTR_BUS_16_BIT)
806 ppr_options = MSG_EXT_PPR_DT_REQ;
808 syncrate = ahc_find_syncrate(ahc, &cts->sync_period,
811 ahc_validate_offset(ahc, /*tinfo limit*/NULL,
812 syncrate, &cts->sync_offset,
813 MSG_EXT_WDTR_BUS_8_BIT,
816 /* We use a period of 0 to represent async */
817 if (cts->sync_offset == 0) {
818 cts->sync_period = 0;
822 if (ppr_options == MSG_EXT_PPR_DT_REQ
823 && tinfo->user.transport_version >= 3) {
824 tinfo->goal.transport_version =
825 tinfo->user.transport_version;
826 tinfo->curr.transport_version =
827 tinfo->user.transport_version;
830 ahc_set_syncrate(ahc, &devinfo, syncrate,
831 cts->sync_period, cts->sync_offset,
832 ppr_options, update_type,
836 ccb->ccb_h.status = CAM_REQ_CMP;
841 case XPT_GET_TRAN_SETTINGS:
842 /* Get default/user set transfer settings for the target */
846 ahc_get_tran_settings(ahc, SIM_SCSI_ID(ahc, sim),
847 SIM_CHANNEL(ahc, sim), &ccb->cts);
852 case XPT_CALC_GEOMETRY:
856 extended = SIM_IS_SCSIBUS_B(ahc, sim)
857 ? ahc->flags & AHC_EXTENDED_TRANS_B
858 : ahc->flags & AHC_EXTENDED_TRANS_A;
859 cam_calc_geometry(&ccb->ccg, extended);
863 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
868 found = ahc_reset_channel(ahc, SIM_CHANNEL(ahc, sim),
869 /*initiate reset*/TRUE);
872 xpt_print_path(SIM_PATH(ahc, sim));
873 kprintf("SCSI bus reset delivered. "
874 "%d SCBs aborted.\n", found);
876 ccb->ccb_h.status = CAM_REQ_CMP;
880 case XPT_TERM_IO: /* Terminate the I/O process */
882 ccb->ccb_h.status = CAM_REQ_INVALID;
885 case XPT_PATH_INQ: /* Path routing inquiry */
887 struct ccb_pathinq *cpi = &ccb->cpi;
889 cpi->version_num = 1; /* XXX??? */
890 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE;
891 if ((ahc->features & AHC_WIDE) != 0)
892 cpi->hba_inquiry |= PI_WIDE_16;
893 if ((ahc->features & AHC_TARGETMODE) != 0) {
894 cpi->target_sprt = PIT_PROCESSOR
898 cpi->target_sprt = 0;
901 cpi->hba_eng_cnt = 0;
902 cpi->max_target = (ahc->features & AHC_WIDE) ? 15 : 7;
903 cpi->max_lun = AHC_NUM_LUNS - 1;
904 if (SIM_IS_SCSIBUS_B(ahc, sim)) {
905 cpi->initiator_id = ahc->our_id_b;
906 if ((ahc->flags & AHC_RESET_BUS_B) == 0)
907 cpi->hba_misc |= PIM_NOBUSRESET;
909 cpi->initiator_id = ahc->our_id;
910 if ((ahc->flags & AHC_RESET_BUS_A) == 0)
911 cpi->hba_misc |= PIM_NOBUSRESET;
913 cpi->bus_id = cam_sim_bus(sim);
914 cpi->base_transfer_speed = 3300;
915 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
916 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
917 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
918 cpi->unit_number = cam_sim_unit(sim);
919 #ifdef AHC_NEW_TRAN_SETTINGS
920 cpi->protocol = PROTO_SCSI;
921 cpi->protocol_version = SCSI_REV_2;
922 cpi->transport = XPORT_SPI;
923 cpi->transport_version = 2;
924 cpi->xport_specific.spi.ppr_options = SID_SPI_CLOCK_ST;
925 if ((ahc->features & AHC_DT) != 0) {
926 cpi->transport_version = 3;
927 cpi->xport_specific.spi.ppr_options =
931 cpi->ccb_h.status = CAM_REQ_CMP;
936 ccb->ccb_h.status = CAM_PROVIDE_FAIL;
943 ahc_get_tran_settings(struct ahc_softc *ahc, int our_id, char channel,
944 struct ccb_trans_settings *cts)
946 #ifdef AHC_NEW_TRAN_SETTINGS
947 struct ahc_devinfo devinfo;
948 struct ccb_trans_settings_scsi *scsi;
949 struct ccb_trans_settings_spi *spi;
950 struct ahc_initiator_tinfo *targ_info;
951 struct ahc_tmode_tstate *tstate;
952 struct ahc_transinfo *tinfo;
954 scsi = &cts->proto_specific.scsi;
955 spi = &cts->xport_specific.spi;
956 ahc_compile_devinfo(&devinfo, our_id,
957 cts->ccb_h.target_id,
958 cts->ccb_h.target_lun,
959 channel, ROLE_UNKNOWN);
960 targ_info = ahc_fetch_transinfo(ahc, devinfo.channel,
962 devinfo.target, &tstate);
964 if (cts->type == CTS_TYPE_CURRENT_SETTINGS)
965 tinfo = &targ_info->curr;
967 tinfo = &targ_info->user;
969 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
970 spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
971 if (cts->type == CTS_TYPE_USER_SETTINGS) {
972 if ((ahc->user_discenable & devinfo.target_mask) != 0)
973 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
975 if ((ahc->user_tagenable & devinfo.target_mask) != 0)
976 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
978 if ((tstate->discenable & devinfo.target_mask) != 0)
979 spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
981 if ((tstate->tagenable & devinfo.target_mask) != 0)
982 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
984 cts->protocol_version = tinfo->protocol_version;
985 cts->transport_version = tinfo->transport_version;
987 spi->sync_period = tinfo->period;
988 spi->sync_offset = tinfo->offset;
989 spi->bus_width = tinfo->width;
990 spi->ppr_options = tinfo->ppr_options;
992 cts->protocol = PROTO_SCSI;
993 cts->transport = XPORT_SPI;
994 spi->valid = CTS_SPI_VALID_SYNC_RATE
995 | CTS_SPI_VALID_SYNC_OFFSET
996 | CTS_SPI_VALID_BUS_WIDTH
997 | CTS_SPI_VALID_PPR_OPTIONS;
999 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) {
1000 scsi->valid = CTS_SCSI_VALID_TQ;
1001 spi->valid |= CTS_SPI_VALID_DISC;
1006 cts->ccb_h.status = CAM_REQ_CMP;
1008 struct ahc_devinfo devinfo;
1009 struct ahc_initiator_tinfo *targ_info;
1010 struct ahc_tmode_tstate *tstate;
1011 struct ahc_transinfo *tinfo;
1013 ahc_compile_devinfo(&devinfo, our_id,
1014 cts->ccb_h.target_id,
1015 cts->ccb_h.target_lun,
1016 channel, ROLE_UNKNOWN);
1017 targ_info = ahc_fetch_transinfo(ahc, devinfo.channel,
1019 devinfo.target, &tstate);
1021 if ((cts->flags & CCB_TRANS_CURRENT_SETTINGS) != 0)
1022 tinfo = &targ_info->curr;
1024 tinfo = &targ_info->user;
1026 cts->flags &= ~(CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB);
1027 if ((cts->flags & CCB_TRANS_CURRENT_SETTINGS) == 0) {
1028 if ((ahc->user_discenable & devinfo.target_mask) != 0)
1029 cts->flags |= CCB_TRANS_DISC_ENB;
1031 if ((ahc->user_tagenable & devinfo.target_mask) != 0)
1032 cts->flags |= CCB_TRANS_TAG_ENB;
1034 if ((tstate->discenable & devinfo.target_mask) != 0)
1035 cts->flags |= CCB_TRANS_DISC_ENB;
1037 if ((tstate->tagenable & devinfo.target_mask) != 0)
1038 cts->flags |= CCB_TRANS_TAG_ENB;
1040 cts->sync_period = tinfo->period;
1041 cts->sync_offset = tinfo->offset;
1042 cts->bus_width = tinfo->width;
1044 cts->valid = CCB_TRANS_SYNC_RATE_VALID
1045 | CCB_TRANS_SYNC_OFFSET_VALID
1046 | CCB_TRANS_BUS_WIDTH_VALID;
1048 if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD)
1049 cts->valid |= CCB_TRANS_DISC_VALID|CCB_TRANS_TQ_VALID;
1051 cts->ccb_h.status = CAM_REQ_CMP;
1056 ahc_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
1058 struct ahc_softc *ahc;
1059 struct cam_sim *sim;
1061 sim = (struct cam_sim *)callback_arg;
1062 ahc = (struct ahc_softc *)cam_sim_softc(sim);
1064 case AC_LOST_DEVICE:
1066 struct ahc_devinfo devinfo;
1068 ahc_compile_devinfo(&devinfo, SIM_SCSI_ID(ahc, sim),
1069 xpt_path_target_id(path),
1070 xpt_path_lun_id(path),
1071 SIM_CHANNEL(ahc, sim),
1075 * Revert to async/narrow transfers
1076 * for the next device.
1079 ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
1080 AHC_TRANS_GOAL|AHC_TRANS_CUR, /*paused*/FALSE);
1081 ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL,
1082 /*period*/0, /*offset*/0, /*ppr_options*/0,
1083 AHC_TRANS_GOAL|AHC_TRANS_CUR,
1094 ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
1099 struct ahc_softc *ahc;
1100 struct ahc_initiator_tinfo *tinfo;
1101 struct ahc_tmode_tstate *tstate;
1104 scb = (struct scb *)arg;
1106 ahc = scb->ahc_softc;
1110 aic_set_transaction_status(scb, CAM_REQ_TOO_BIG);
1112 aic_set_transaction_status(scb, CAM_REQ_CMP_ERR);
1114 bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap);
1116 ahc_free_scb(ahc, scb);
1121 if (nsegments != 0) {
1122 struct ahc_dma_seg *sg;
1123 bus_dma_segment_t *end_seg;
1124 bus_dmasync_op_t op;
1126 end_seg = dm_segs + nsegments;
1128 /* Copy the segments into our SG list */
1130 while (dm_segs < end_seg) {
1133 sg->addr = aic_htole32(dm_segs->ds_addr);
1134 len = dm_segs->ds_len
1135 | ((dm_segs->ds_addr >> 8) & 0x7F000000);
1136 sg->len = aic_htole32(len);
1142 * Note where to find the SG entries in bus space.
1143 * We also set the full residual flag which the
1144 * sequencer will clear as soon as a data transfer
1147 scb->hscb->sgptr = aic_htole32(scb->sg_list_phys|SG_FULL_RESID);
1149 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
1150 op = BUS_DMASYNC_PREREAD;
1152 op = BUS_DMASYNC_PREWRITE;
1154 bus_dmamap_sync(ahc->buffer_dmat, scb->dmamap, op);
1156 if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) {
1157 struct target_data *tdata;
1159 tdata = &scb->hscb->shared_data.tdata;
1160 tdata->target_phases |= DPHASE_PENDING;
1162 * CAM data direction is relative to the initiator.
1164 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
1165 tdata->data_phase = P_DATAOUT;
1167 tdata->data_phase = P_DATAIN;
1170 * If the transfer is of an odd length and in the
1171 * "in" direction (scsi->HostBus), then it may
1172 * trigger a bug in the 'WideODD' feature of
1173 * non-Ultra2 chips. Force the total data-length
1174 * to be even by adding an extra, 1 byte, SG,
1175 * element. We do this even if we are not currently
1176 * negotiated wide as negotiation could occur before
1177 * this command is executed.
1179 if ((ahc->bugs & AHC_TMODE_WIDEODD_BUG) != 0
1180 && (ccb->csio.dxfer_len & 0x1) != 0
1181 && (ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1184 if (nsegments > AHC_NSEG) {
1186 aic_set_transaction_status(scb,
1188 bus_dmamap_unload(ahc->buffer_dmat,
1191 ahc_free_scb(ahc, scb);
1196 sg->addr = aic_htole32(ahc->dma_bug_buf);
1197 sg->len = aic_htole32(1);
1202 sg->len |= aic_htole32(AHC_DMA_LAST_SEG);
1204 /* Copy the first SG into the "current" data pointer area */
1205 scb->hscb->dataptr = scb->sg_list->addr;
1206 scb->hscb->datacnt = scb->sg_list->len;
1208 scb->hscb->sgptr = aic_htole32(SG_LIST_NULL);
1209 scb->hscb->dataptr = 0;
1210 scb->hscb->datacnt = 0;
1213 scb->sg_count = nsegments;
1218 * Last time we need to check if this SCB needs to
1221 if (aic_get_transaction_status(scb) != CAM_REQ_INPROG) {
1223 bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap);
1224 ahc_free_scb(ahc, scb);
1230 tinfo = ahc_fetch_transinfo(ahc, SCSIID_CHANNEL(ahc, scb->hscb->scsiid),
1231 SCSIID_OUR_ID(scb->hscb->scsiid),
1232 SCSIID_TARGET(ahc, scb->hscb->scsiid),
1235 mask = SCB_GET_TARGET_MASK(ahc, scb);
1236 scb->hscb->scsirate = tinfo->scsirate;
1237 scb->hscb->scsioffset = tinfo->curr.offset;
1238 if ((tstate->ultraenb & mask) != 0)
1239 scb->hscb->control |= ULTRAENB;
1241 if ((tstate->discenable & mask) != 0
1242 && (ccb->ccb_h.flags & CAM_DIS_DISCONNECT) == 0)
1243 scb->hscb->control |= DISCENB;
1245 if ((ccb->ccb_h.flags & CAM_NEGOTIATE) != 0
1246 && (tinfo->goal.width != 0
1247 || tinfo->goal.offset != 0
1248 || tinfo->goal.ppr_options != 0)) {
1249 scb->flags |= SCB_NEGOTIATE;
1250 scb->hscb->control |= MK_MESSAGE;
1251 } else if ((tstate->auto_negotiate & mask) != 0) {
1252 scb->flags |= SCB_AUTO_NEGOTIATE;
1253 scb->hscb->control |= MK_MESSAGE;
1256 LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);
1258 ccb->ccb_h.status |= CAM_SIM_QUEUED;
1261 * We only allow one untagged transaction
1262 * per target in the initiator role unless
1263 * we are storing a full busy target *lun*
1264 * table in SCB space.
1266 if ((scb->hscb->control & (TARGET_SCB|TAG_ENB)) == 0
1267 && (ahc->flags & AHC_SCB_BTT) == 0) {
1268 struct scb_tailq *untagged_q;
1271 target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
1272 untagged_q = &(ahc->untagged_queues[target_offset]);
1273 TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
1274 scb->flags |= SCB_UNTAGGEDQ;
1275 if (TAILQ_FIRST(untagged_q) != scb) {
1280 scb->flags |= SCB_ACTIVE;
1283 * Timers are disabled while recovery is in progress.
1285 aic_scb_timer_start(scb);
1287 if ((scb->flags & SCB_TARGET_IMMEDIATE) != 0) {
1288 /* Define a mapping from our tag to the SCB. */
1289 ahc->scb_data->scbindex[scb->hscb->tag] = scb;
1291 if ((ahc->flags & AHC_PAGESCBS) == 0)
1292 ahc_outb(ahc, SCBPTR, scb->hscb->tag);
1293 ahc_outb(ahc, TARG_IMMEDIATE_SCB, scb->hscb->tag);
1296 ahc_queue_scb(ahc, scb);
1303 ahc_poll(struct cam_sim *sim)
1305 struct ahc_softc *ahc;
1307 ahc = (struct ahc_softc *)cam_sim_softc(sim);
1312 ahc_setup_data(struct ahc_softc *ahc, struct cam_sim *sim,
1313 struct ccb_scsiio *csio, struct scb *scb)
1315 struct hardware_scb *hscb;
1316 struct ccb_hdr *ccb_h;
1319 ccb_h = &csio->ccb_h;
1322 csio->sense_resid = 0;
1323 if (ccb_h->func_code == XPT_SCSI_IO) {
1324 hscb->cdb_len = csio->cdb_len;
1325 if ((ccb_h->flags & CAM_CDB_POINTER) != 0) {
1327 if (hscb->cdb_len > sizeof(hscb->cdb32)
1328 || (ccb_h->flags & CAM_CDB_PHYS) != 0) {
1329 aic_set_transaction_status(scb,
1332 ahc_free_scb(ahc, scb);
1334 xpt_done((union ccb *)csio);
1337 if (hscb->cdb_len > 12) {
1339 csio->cdb_io.cdb_ptr,
1341 scb->flags |= SCB_CDB32_PTR;
1343 memcpy(hscb->shared_data.cdb,
1344 csio->cdb_io.cdb_ptr,
1348 if (hscb->cdb_len > 12) {
1349 memcpy(hscb->cdb32, csio->cdb_io.cdb_bytes,
1351 scb->flags |= SCB_CDB32_PTR;
1353 memcpy(hscb->shared_data.cdb,
1354 csio->cdb_io.cdb_bytes,
1360 /* Only use S/G if there is a transfer */
1361 if ((ccb_h->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
1362 if ((ccb_h->flags & CAM_SCATTER_VALID) == 0) {
1363 /* We've been given a pointer to a single buffer */
1364 if ((ccb_h->flags & CAM_DATA_PHYS) == 0) {
1368 error = bus_dmamap_load(ahc->buffer_dmat,
1374 if (error == EINPROGRESS) {
1376 * So as to maintain ordering,
1377 * freeze the controller queue
1378 * until our mapping is
1381 xpt_freeze_simq(sim,
1383 scb->io_ctx->ccb_h.status |=
1388 struct bus_dma_segment seg;
1390 /* Pointer to physical buffer */
1391 if (csio->dxfer_len > AHC_MAXTRANSFER_SIZE)
1392 panic("ahc_setup_data - Transfer size "
1393 "larger than can device max");
1396 (bus_addr_t)(vm_offset_t)csio->data_ptr;
1397 seg.ds_len = csio->dxfer_len;
1398 ahc_execute_scb(scb, &seg, 1, 0);
1401 struct bus_dma_segment *segs;
1403 if ((ccb_h->flags & CAM_DATA_PHYS) != 0)
1404 panic("ahc_setup_data - Physical segment "
1405 "pointers unsupported");
1407 if ((ccb_h->flags & CAM_SG_LIST_PHYS) == 0)
1408 panic("ahc_setup_data - Virtual segment "
1409 "addresses unsupported");
1411 /* Just use the segments provided */
1412 segs = (struct bus_dma_segment *)csio->data_ptr;
1413 ahc_execute_scb(scb, segs, csio->sglist_cnt, 0);
1416 ahc_execute_scb(scb, NULL, 0, 0);
1421 ahc_abort_ccb(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
1423 union ccb *abort_ccb;
1425 abort_ccb = ccb->cab.abort_ccb;
1426 switch (abort_ccb->ccb_h.func_code) {
1427 case XPT_ACCEPT_TARGET_IO:
1428 case XPT_IMMED_NOTIFY:
1429 case XPT_CONT_TARGET_IO:
1431 struct ahc_tmode_tstate *tstate;
1432 struct ahc_tmode_lstate *lstate;
1433 struct ccb_hdr_slist *list;
1436 status = ahc_find_tmode_devs(ahc, sim, abort_ccb, &tstate,
1439 if (status != CAM_REQ_CMP) {
1440 ccb->ccb_h.status = status;
1444 if (abort_ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO)
1445 list = &lstate->accept_tios;
1446 else if (abort_ccb->ccb_h.func_code == XPT_IMMED_NOTIFY)
1447 list = &lstate->immed_notifies;
1452 struct ccb_hdr *curelm;
1455 curelm = SLIST_FIRST(list);
1457 if (curelm == &abort_ccb->ccb_h) {
1459 SLIST_REMOVE_HEAD(list, sim_links.sle);
1461 while(curelm != NULL) {
1462 struct ccb_hdr *nextelm;
1465 SLIST_NEXT(curelm, sim_links.sle);
1467 if (nextelm == &abort_ccb->ccb_h) {
1480 abort_ccb->ccb_h.status = CAM_REQ_ABORTED;
1481 xpt_done(abort_ccb);
1482 ccb->ccb_h.status = CAM_REQ_CMP;
1484 xpt_print_path(abort_ccb->ccb_h.path);
1485 kprintf("Not found\n");
1486 ccb->ccb_h.status = CAM_PATH_INVALID;
1493 /* XXX Fully implement the hard ones */
1494 ccb->ccb_h.status = CAM_UA_ABORT;
1497 ccb->ccb_h.status = CAM_REQ_INVALID;
1504 ahc_send_async(struct ahc_softc *ahc, char channel, u_int target,
1505 u_int lun, ac_code code, void *opt_arg)
1507 struct ccb_trans_settings cts;
1508 struct cam_path *path;
1513 error = ahc_create_path(ahc, channel, target, lun, &path);
1515 if (error != CAM_REQ_CMP)
1519 case AC_TRANSFER_NEG:
1521 #ifdef AHC_NEW_TRAN_SETTINGS
1522 struct ccb_trans_settings_scsi *scsi;
1524 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1525 scsi = &cts.proto_specific.scsi;
1527 cts.flags = CCB_TRANS_CURRENT_SETTINGS;
1529 cts.ccb_h.path = path;
1530 cts.ccb_h.target_id = target;
1531 cts.ccb_h.target_lun = lun;
1532 ahc_get_tran_settings(ahc, channel == 'A' ? ahc->our_id
1536 #ifdef AHC_NEW_TRAN_SETTINGS
1537 scsi->valid &= ~CTS_SCSI_VALID_TQ;
1538 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1540 cts.valid &= ~CCB_TRANS_TQ_VALID;
1541 cts.flags &= ~CCB_TRANS_TAG_ENB;
1543 if (opt_arg == NULL)
1545 if (*((ahc_queue_alg *)opt_arg) == AHC_QUEUE_TAGGED)
1546 #ifdef AHC_NEW_TRAN_SETTINGS
1547 scsi->flags |= ~CTS_SCSI_FLAGS_TAG_ENB;
1548 scsi->valid |= CTS_SCSI_VALID_TQ;
1550 cts.flags |= CCB_TRANS_TAG_ENB;
1551 cts.valid |= CCB_TRANS_TQ_VALID;
1559 panic("ahc_send_async: Unexpected async event");
1561 xpt_async(code, path, arg);
1562 xpt_free_path(path);
1566 ahc_platform_set_tags(struct ahc_softc *ahc,
1567 struct ahc_devinfo *devinfo, int enable)
1572 ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
1574 ahc->platform_data = kmalloc(sizeof(struct ahc_platform_data), M_DEVBUF,
1575 M_INTWAIT | M_ZERO);
1580 ahc_platform_free(struct ahc_softc *ahc)
1582 struct ahc_platform_data *pdata;
1584 pdata = ahc->platform_data;
1585 if (pdata != NULL) {
1586 if (pdata->regs != NULL)
1587 bus_release_resource(ahc->dev_softc,
1588 pdata->regs_res_type,
1592 if (pdata->irq != NULL)
1593 bus_release_resource(ahc->dev_softc,
1594 pdata->irq_res_type,
1597 if (pdata->sim_b != NULL) {
1598 xpt_async(AC_LOST_DEVICE, pdata->path_b, NULL);
1599 xpt_free_path(pdata->path_b);
1600 xpt_bus_deregister(cam_sim_path(pdata->sim_b));
1601 cam_sim_free(pdata->sim_b);
1603 if (pdata->sim != NULL) {
1604 xpt_async(AC_LOST_DEVICE, pdata->path, NULL);
1605 xpt_free_path(pdata->path);
1606 xpt_bus_deregister(cam_sim_path(pdata->sim));
1607 cam_sim_free(pdata->sim);
1609 if (pdata->eh != NULL)
1610 EVENTHANDLER_DEREGISTER(shutdown_post_sync, pdata->eh);
1611 kfree(ahc->platform_data, M_DEVBUF);
1616 ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc)
1618 /* We don't sort softcs under FreeBSD so report equal always */
1623 ahc_detach(device_t dev)
1625 struct ahc_softc *ahc;
1627 device_printf(dev, "detaching device\n");
1628 ahc = device_get_softc(dev);
1629 ahc = ahc_find_softc(ahc);
1631 device_printf(dev, "aic7xxx already detached\n");
1634 TAILQ_REMOVE(&ahc_tailq, ahc, links);
1636 ahc_intr_enable(ahc, FALSE);
1637 bus_teardown_intr(dev, ahc->platform_data->irq, ahc->platform_data->ih);
1645 ahc_dump_targcmd(struct target_cmd *cmd)
1651 byte = &cmd->initiator_channel;
1652 /* Debugging info for received commands */
1653 last_byte = &cmd[1].initiator_channel;
1656 while (byte < last_byte) {
1659 kprintf("%#x", *byte++);
1672 ahc_modevent(module_t mod, int type, void *data)
1674 /* XXX Deal with busy status on unload. */
1678 static moduledata_t ahc_mod = {
1684 DECLARE_MODULE(ahc, ahc_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1685 MODULE_DEPEND(ahc, cam, 1, 1, 1);
1686 MODULE_VERSION(ahc, 1);