Deleted Added
full compact
aic7xxx.c (74434) aic7xxx.c (74972)
1/*
2 * Core routines and tables shareable across OS platforms.
3 *
4 * Copyright (c) 1994-2001 Justin T. Gibbs.
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

--- 14 unchanged lines hidden (view full) ---

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
29 * SUCH DAMAGE.
30 *
1/*
2 * Core routines and tables shareable across OS platforms.
3 *
4 * Copyright (c) 1994-2001 Justin T. Gibbs.
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

--- 14 unchanged lines hidden (view full) ---

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
29 * SUCH DAMAGE.
30 *
31 * $Id: //depot/src/aic7xxx/aic7xxx.c#34 $
31 * $Id: //depot/src/aic7xxx/aic7xxx.c#35 $
32 *
32 *
33 * $FreeBSD: head/sys/dev/aic7xxx/aic7xxx.c 74434 2001-03-19 04:40:35Z gibbs $
33 * $FreeBSD: head/sys/dev/aic7xxx/aic7xxx.c 74972 2001-03-29 00:36:35Z gibbs $
34 */
35
36#ifdef __linux__
37#include "aic7xxx_linux.h"
38#include "aic7xxx_inline.h"
39#include "aicasm/aicasm_insformat.h"
40#endif
41

--- 90 unchanged lines hidden (view full) ---

132 { 0x00, 0x070, 68, "3.6" },
133 { 0x00, 0x000, 0, NULL }
134};
135
136/* Our Sequencer Program */
137#include "aic7xxx_seq.h"
138
139/**************************** Function Declarations ***************************/
34 */
35
36#ifdef __linux__
37#include "aic7xxx_linux.h"
38#include "aic7xxx_inline.h"
39#include "aicasm/aicasm_insformat.h"
40#endif
41

--- 90 unchanged lines hidden (view full) ---

132 { 0x00, 0x070, 68, "3.6" },
133 { 0x00, 0x000, 0, NULL }
134};
135
136/* Our Sequencer Program */
137#include "aic7xxx_seq.h"
138
139/**************************** Function Declarations ***************************/
140static struct tmode_tstate*
140static struct ahc_tmode_tstate*
141 ahc_alloc_tstate(struct ahc_softc *ahc,
142 u_int scsi_id, char channel);
143#ifdef AHC_TARGET_MODE
144static void ahc_free_tstate(struct ahc_softc *ahc,
145 u_int scsi_id, char channel, int force);
146#endif
147static struct ahc_syncrate*
148 ahc_devlimited_syncrate(struct ahc_softc *ahc,
149 struct ahc_initiator_tinfo *,
150 u_int *period,
151 u_int *ppr_options,
152 role_t role);
141 ahc_alloc_tstate(struct ahc_softc *ahc,
142 u_int scsi_id, char channel);
143#ifdef AHC_TARGET_MODE
144static void ahc_free_tstate(struct ahc_softc *ahc,
145 u_int scsi_id, char channel, int force);
146#endif
147static struct ahc_syncrate*
148 ahc_devlimited_syncrate(struct ahc_softc *ahc,
149 struct ahc_initiator_tinfo *,
150 u_int *period,
151 u_int *ppr_options,
152 role_t role);
153static void ahc_update_pending_syncrates(struct ahc_softc *ahc);
153static void ahc_update_pending_scbs(struct ahc_softc *ahc);
154static void ahc_fetch_devinfo(struct ahc_softc *ahc,
155 struct ahc_devinfo *devinfo);
156static void ahc_scb_devinfo(struct ahc_softc *ahc,
157 struct ahc_devinfo *devinfo,
158 struct scb *scb);
159static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
160 struct ahc_devinfo *devinfo,
161 struct scb *scb);

--- 23 unchanged lines hidden (view full) ---

185static int ahc_handle_msg_reject(struct ahc_softc *ahc,
186 struct ahc_devinfo *devinfo);
187static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
188 struct ahc_devinfo *devinfo);
189static void ahc_handle_devreset(struct ahc_softc *ahc,
190 struct ahc_devinfo *devinfo,
191 cam_status status, char *message,
192 int verbose_level);
154static void ahc_fetch_devinfo(struct ahc_softc *ahc,
155 struct ahc_devinfo *devinfo);
156static void ahc_scb_devinfo(struct ahc_softc *ahc,
157 struct ahc_devinfo *devinfo,
158 struct scb *scb);
159static void ahc_setup_initiator_msgout(struct ahc_softc *ahc,
160 struct ahc_devinfo *devinfo,
161 struct scb *scb);

--- 23 unchanged lines hidden (view full) ---

185static int ahc_handle_msg_reject(struct ahc_softc *ahc,
186 struct ahc_devinfo *devinfo);
187static void ahc_handle_ign_wide_residue(struct ahc_softc *ahc,
188 struct ahc_devinfo *devinfo);
189static void ahc_handle_devreset(struct ahc_softc *ahc,
190 struct ahc_devinfo *devinfo,
191 cam_status status, char *message,
192 int verbose_level);
193static void ahc_setup_target_msgin(struct ahc_softc *ahc,
194 struct ahc_devinfo *devinfo,
195 struct scb *scb);
193
194static bus_dmamap_callback_t ahc_dmamap_cb;
195static void ahc_build_free_scb_list(struct ahc_softc *ahc);
196static int ahc_init_scbdata(struct ahc_softc *ahc);
197static void ahc_fini_scbdata(struct ahc_softc *ahc);
198static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
199 struct scb *prev_scb,
200 struct scb *scb);

--- 14 unchanged lines hidden (view full) ---

215static void ahc_loadseq(struct ahc_softc *ahc);
216static int ahc_check_patch(struct ahc_softc *ahc,
217 struct patch **start_patch,
218 u_int start_instr, u_int *skip_addr);
219static void ahc_download_instr(struct ahc_softc *ahc,
220 u_int instrptr, uint8_t *dconsts);
221#ifdef AHC_TARGET_MODE
222static void ahc_queue_lstate_event(struct ahc_softc *ahc,
196
197static bus_dmamap_callback_t ahc_dmamap_cb;
198static void ahc_build_free_scb_list(struct ahc_softc *ahc);
199static int ahc_init_scbdata(struct ahc_softc *ahc);
200static void ahc_fini_scbdata(struct ahc_softc *ahc);
201static void ahc_qinfifo_requeue(struct ahc_softc *ahc,
202 struct scb *prev_scb,
203 struct scb *scb);

--- 14 unchanged lines hidden (view full) ---

218static void ahc_loadseq(struct ahc_softc *ahc);
219static int ahc_check_patch(struct ahc_softc *ahc,
220 struct patch **start_patch,
221 u_int start_instr, u_int *skip_addr);
222static void ahc_download_instr(struct ahc_softc *ahc,
223 u_int instrptr, uint8_t *dconsts);
224#ifdef AHC_TARGET_MODE
225static void ahc_queue_lstate_event(struct ahc_softc *ahc,
223 struct tmode_lstate *lstate,
226 struct ahc_tmode_lstate *lstate,
224 u_int initiator_id,
225 u_int event_type,
226 u_int event_arg);
227static void ahc_update_scsiid(struct ahc_softc *ahc,
228 u_int targid_mask);
229static int ahc_handle_target_cmd(struct ahc_softc *ahc,
230 struct target_cmd *cmd);
231#endif

--- 215 unchanged lines hidden (view full) ---

447 ahc_set_scsi_status(scb, hscb->shared_data.status.scsi_status);
448 switch (hscb->shared_data.status.scsi_status) {
449 case SCSI_STATUS_OK:
450 printf("%s: Interrupted for staus of 0???\n",
451 ahc_name(ahc));
452 break;
453 case SCSI_STATUS_CMD_TERMINATED:
454 case SCSI_STATUS_CHECK_COND:
227 u_int initiator_id,
228 u_int event_type,
229 u_int event_arg);
230static void ahc_update_scsiid(struct ahc_softc *ahc,
231 u_int targid_mask);
232static int ahc_handle_target_cmd(struct ahc_softc *ahc,
233 struct target_cmd *cmd);
234#endif

--- 215 unchanged lines hidden (view full) ---

450 ahc_set_scsi_status(scb, hscb->shared_data.status.scsi_status);
451 switch (hscb->shared_data.status.scsi_status) {
452 case SCSI_STATUS_OK:
453 printf("%s: Interrupted for staus of 0???\n",
454 ahc_name(ahc));
455 break;
456 case SCSI_STATUS_CMD_TERMINATED:
457 case SCSI_STATUS_CHECK_COND:
458 {
459 struct ahc_dma_seg *sg;
460 struct scsi_sense *sc;
461 struct ahc_initiator_tinfo *targ_info;
462 struct ahc_tmode_tstate *tstate;
463 struct ahc_transinfo *tinfo;
455#ifdef AHC_DEBUG
456 if (ahc_debug & AHC_SHOWSENSE) {
457 ahc_print_path(ahc, scb);
458 printf("SCB %d: requests Check Status\n",
459 scb->hscb->tag);
460 }
461#endif
462
464#ifdef AHC_DEBUG
465 if (ahc_debug & AHC_SHOWSENSE) {
466 ahc_print_path(ahc, scb);
467 printf("SCB %d: requests Check Status\n",
468 scb->hscb->tag);
469 }
470#endif
471
463 if (ahc_perform_autosense(scb)) {
464 struct ahc_dma_seg *sg;
465 struct scsi_sense *sc;
466 struct ahc_initiator_tinfo *targ_info;
467 struct tmode_tstate *tstate;
468 struct ahc_transinfo *tinfo;
472 if (ahc_perform_autosense(scb) == 0)
473 break;
469
474
470 targ_info =
471 ahc_fetch_transinfo(ahc,
475 targ_info = ahc_fetch_transinfo(ahc,
472 devinfo.channel,
473 devinfo.our_scsiid,
474 devinfo.target,
475 &tstate);
476 devinfo.channel,
477 devinfo.our_scsiid,
478 devinfo.target,
479 &tstate);
476 tinfo = &targ_info->current;
477 sg = scb->sg_list;
478 sc = (struct scsi_sense *)
479 (&hscb->shared_data.cdb);
480 /*
481 * Save off the residual if there is one.
482 */
483 if (ahc_check_residual(scb))
484 ahc_calc_residual(scb);
485 else
486 ahc_set_residual(scb, 0);
480 tinfo = &targ_info->current;
481 sg = scb->sg_list;
482 sc = (struct scsi_sense *)(&hscb->shared_data.cdb);
483 /*
484 * Save off the residual if there is one.
485 */
486 if (ahc_check_residual(scb))
487 ahc_calc_residual(scb);
488 else
489 ahc_set_residual(scb, 0);
487#ifdef AHC_DEBUG
490#ifdef AHC_DEBUG
488 if (ahc_debug & AHC_SHOWSENSE) {
489 ahc_print_path(ahc, scb);
490 printf("Sending Sense\n");
491 }
491 if (ahc_debug & AHC_SHOWSENSE) {
492 ahc_print_path(ahc, scb);
493 printf("Sending Sense\n");
494 }
492#endif
495#endif
493 sg->addr = ahc_get_sense_bufaddr(ahc, scb);
494 sg->len = ahc_get_sense_bufsize(ahc, scb);
495 sg->len |= AHC_DMA_LAST_SEG;
496 sg->addr = ahc_get_sense_bufaddr(ahc, scb);
497 sg->len = ahc_get_sense_bufsize(ahc, scb);
498 sg->len |= AHC_DMA_LAST_SEG;
496
499
497 /* Fixup byte order */
498 sg->addr = ahc_htole32(sg->addr);
499 sg->len = ahc_htole32(sg->len);
500 /* Fixup byte order */
501 sg->addr = ahc_htole32(sg->addr);
502 sg->len = ahc_htole32(sg->len);
500
503
501 sc->opcode = REQUEST_SENSE;
502 sc->byte2 = 0;
503 if (tinfo->protocol_version <= SCSI_REV_2
504 && SCB_GET_LUN(scb) < 8)
505 sc->byte2 = SCB_GET_LUN(scb) << 5;
506 sc->unused[0] = 0;
507 sc->unused[1] = 0;
508 sc->length = sg->len;
509 sc->control = 0;
504 sc->opcode = REQUEST_SENSE;
505 sc->byte2 = 0;
506 if (tinfo->protocol_version <= SCSI_REV_2
507 && SCB_GET_LUN(scb) < 8)
508 sc->byte2 = SCB_GET_LUN(scb) << 5;
509 sc->unused[0] = 0;
510 sc->unused[1] = 0;
511 sc->length = sg->len;
512 sc->control = 0;
510
513
511 /*
512 * XXX Still true???
513 * Would be nice to preserve DISCENB here,
514 * but due to the way we manage busy targets,
515 * we can't.
516 */
517 hscb->control = 0;
514 /*
515 * We can't allow the target to disconnect.
516 * This will be an untagged transaction and
517 * having the target disconnect will make this
518 * transaction indestinguishable from outstanding
519 * tagged transactions.
520 */
521 hscb->control = 0;
518
522
519 /*
520 * This request sense could be because the
521 * the device lost power or in some other
522 * way has lost our transfer negotiations.
523 * Renegotiate if appropriate. Unit attention
524 * errors will be reported before any data
525 * phases occur.
526 */
527 if (ahc_get_residual(scb)
528 == ahc_get_transfer_length(scb)) {
529 ahc_update_target_msg_request(ahc,
530 &devinfo,
531 targ_info,
532 /*force*/TRUE,
533 /*paused*/TRUE);
534 }
535 hscb->cdb_len = sizeof(*sc);
536 hscb->dataptr = sg->addr;
537 hscb->datacnt = sg->len;
538 hscb->sgptr = scb->sg_list_phys | SG_FULL_RESID;
539 hscb->sgptr = ahc_htole32(hscb->sgptr);
540 scb->sg_count = 1;
541 scb->flags |= SCB_SENSE;
542 ahc_qinfifo_requeue_tail(ahc, scb);
543 ahc_outb(ahc, RETURN_1, SEND_SENSE);
523 /*
524 * This request sense could be because the
525 * the device lost power or in some other
526 * way has lost our transfer negotiations.
527 * Renegotiate if appropriate. Unit attention
528 * errors will be reported before any data
529 * phases occur.
530 */
531 if (ahc_get_residual(scb)
532 == ahc_get_transfer_length(scb)) {
533 ahc_update_neg_request(ahc, &devinfo,
534 tstate, targ_info,
535 /*force*/TRUE);
536 }
537 if (tstate->auto_negotiate & devinfo.target_mask) {
538 hscb->control |= MK_MESSAGE;
539 scb->flags &= ~SCB_NEGOTIATE;
540 scb->flags |= SCB_AUTO_NEGOTIATE;
541 }
542 hscb->cdb_len = sizeof(*sc);
543 hscb->dataptr = sg->addr;
544 hscb->datacnt = sg->len;
545 hscb->sgptr = scb->sg_list_phys | SG_FULL_RESID;
546 hscb->sgptr = ahc_htole32(hscb->sgptr);
547 scb->sg_count = 1;
548 scb->flags |= SCB_SENSE;
549 ahc_qinfifo_requeue_tail(ahc, scb);
550 ahc_outb(ahc, RETURN_1, SEND_SENSE);
544#ifdef __FreeBSD__
551#ifdef __FreeBSD__
545 /*
546 * Ensure we have enough time to actually
547 * retrieve the sense.
548 */
549 untimeout(ahc_timeout, (caddr_t)scb,
550 scb->io_ctx->ccb_h.timeout_ch);
551 scb->io_ctx->ccb_h.timeout_ch =
552 timeout(ahc_timeout, (caddr_t)scb, 5 * hz);
552 /*
553 * Ensure we have enough time to actually
554 * retrieve the sense.
555 */
556 untimeout(ahc_timeout, (caddr_t)scb,
557 scb->io_ctx->ccb_h.timeout_ch);
558 scb->io_ctx->ccb_h.timeout_ch =
559 timeout(ahc_timeout, (caddr_t)scb, 5 * hz);
553#endif
560#endif
554 }
555 break;
561 break;
562 }
556 default:
557 break;
558 }
559 break;
560 }
561 case NO_MATCH:
562 {
563 /* Ensure we don't leave the selection hardware on */

--- 97 unchanged lines hidden (view full) ---

661 * notified by the sequencer after each byte is
662 * transfered so we can track bus phase changes.
663 *
664 * If this is the first time we've seen a HOST_MSG_LOOP
665 * interrupt, initialize the state of the host message
666 * loop.
667 */
668 if (ahc->msg_type == MSG_TYPE_NONE) {
563 default:
564 break;
565 }
566 break;
567 }
568 case NO_MATCH:
569 {
570 /* Ensure we don't leave the selection hardware on */

--- 97 unchanged lines hidden (view full) ---

668 * notified by the sequencer after each byte is
669 * transfered so we can track bus phase changes.
670 *
671 * If this is the first time we've seen a HOST_MSG_LOOP
672 * interrupt, initialize the state of the host message
673 * loop.
674 */
675 if (ahc->msg_type == MSG_TYPE_NONE) {
676 struct scb *scb;
677 u_int scb_index;
669 u_int bus_phase;
670
671 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
672 if (bus_phase != P_MESGIN
673 && bus_phase != P_MESGOUT) {
674 printf("ahc_intr: HOST_MSG_LOOP bad "
675 "phase 0x%x\n",
676 bus_phase);
677 /*
678 * Probably transitioned to bus free before
679 * we got here. Just punt the message.
680 */
681 ahc_clear_intstat(ahc);
682 ahc_restart(ahc);
683 return;
684 }
685
678 u_int bus_phase;
679
680 bus_phase = ahc_inb(ahc, SCSISIGI) & PHASE_MASK;
681 if (bus_phase != P_MESGIN
682 && bus_phase != P_MESGOUT) {
683 printf("ahc_intr: HOST_MSG_LOOP bad "
684 "phase 0x%x\n",
685 bus_phase);
686 /*
687 * Probably transitioned to bus free before
688 * we got here. Just punt the message.
689 */
690 ahc_clear_intstat(ahc);
691 ahc_restart(ahc);
692 return;
693 }
694
695 scb_index = ahc_inb(ahc, SCB_TAG);
696 scb = ahc_lookup_scb(ahc, scb_index);
686 if (devinfo.role == ROLE_INITIATOR) {
697 if (devinfo.role == ROLE_INITIATOR) {
687 struct scb *scb;
688 u_int scb_index;
689
690 scb_index = ahc_inb(ahc, SCB_TAG);
691 scb = ahc_lookup_scb(ahc, scb_index);
692
693 if (scb == NULL)
694 panic("HOST_MSG_LOOP with "
695 "invalid SCB %x\n", scb_index);
696
697 if (bus_phase == P_MESGOUT)
698 ahc_setup_initiator_msgout(ahc,
699 &devinfo,
700 scb);

--- 5 unchanged lines hidden (view full) ---

706 } else {
707 if (bus_phase == P_MESGOUT) {
708 ahc->msg_type =
709 MSG_TYPE_TARGET_MSGOUT;
710 ahc->msgin_index = 0;
711 }
712#if AHC_TARGET_MODE
713 else
698 if (scb == NULL)
699 panic("HOST_MSG_LOOP with "
700 "invalid SCB %x\n", scb_index);
701
702 if (bus_phase == P_MESGOUT)
703 ahc_setup_initiator_msgout(ahc,
704 &devinfo,
705 scb);

--- 5 unchanged lines hidden (view full) ---

711 } else {
712 if (bus_phase == P_MESGOUT) {
713 ahc->msg_type =
714 MSG_TYPE_TARGET_MSGOUT;
715 ahc->msgin_index = 0;
716 }
717#if AHC_TARGET_MODE
718 else
714 ahc_setup_target_msgin(ahc, &devinfo);
719 ahc_setup_target_msgin(ahc,
720 &devinfo,
721 scb);
715#endif
716 }
717 }
718
719 ahc_handle_message_phase(ahc);
720 break;
721 }
722 case PERR_DETECTED:

--- 401 unchanged lines hidden (view full) ---

1124 ahc_handle_devreset(ahc, &devinfo,
1125 CAM_BDR_SENT,
1126 "Bus Device Reset",
1127 /*verbose_level*/0);
1128 printerror = 0;
1129 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1130 MSG_EXT_PPR, FALSE)) {
1131 struct ahc_initiator_tinfo *tinfo;
722#endif
723 }
724 }
725
726 ahc_handle_message_phase(ahc);
727 break;
728 }
729 case PERR_DETECTED:

--- 401 unchanged lines hidden (view full) ---

1131 ahc_handle_devreset(ahc, &devinfo,
1132 CAM_BDR_SENT,
1133 "Bus Device Reset",
1134 /*verbose_level*/0);
1135 printerror = 0;
1136 } else if (ahc_sent_msg(ahc, AHCMSG_EXT,
1137 MSG_EXT_PPR, FALSE)) {
1138 struct ahc_initiator_tinfo *tinfo;
1132 struct tmode_tstate *tstate;
1139 struct ahc_tmode_tstate *tstate;
1133
1134 /*
1135 * PPR Rejected. Try non-ppr negotiation
1136 * and retry command.
1137 */
1138 tinfo = ahc_fetch_transinfo(ahc,
1139 devinfo.channel,
1140 devinfo.our_scsiid,

--- 234 unchanged lines hidden (view full) ---

1375 }
1376}
1377
1378/************************* Transfer Negotiation *******************************/
1379/*
1380 * Allocate per target mode instance (ID we respond to as a target)
1381 * transfer negotiation data structures.
1382 */
1140
1141 /*
1142 * PPR Rejected. Try non-ppr negotiation
1143 * and retry command.
1144 */
1145 tinfo = ahc_fetch_transinfo(ahc,
1146 devinfo.channel,
1147 devinfo.our_scsiid,

--- 234 unchanged lines hidden (view full) ---

1382 }
1383}
1384
1385/************************* Transfer Negotiation *******************************/
1386/*
1387 * Allocate per target mode instance (ID we respond to as a target)
1388 * transfer negotiation data structures.
1389 */
1383static struct tmode_tstate *
1390static struct ahc_tmode_tstate *
1384ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
1385{
1391ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
1392{
1386 struct tmode_tstate *master_tstate;
1387 struct tmode_tstate *tstate;
1393 struct ahc_tmode_tstate *master_tstate;
1394 struct ahc_tmode_tstate *tstate;
1388 int i;
1389
1390 master_tstate = ahc->enabled_targets[ahc->our_id];
1391 if (channel == 'B') {
1392 scsi_id += 8;
1393 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
1394 }
1395 if (ahc->enabled_targets[scsi_id] != NULL

--- 29 unchanged lines hidden (view full) ---

1425#ifdef AHC_TARGET_MODE
1426/*
1427 * Free per target mode instance (ID we respond to as a target)
1428 * transfer negotiation data structures.
1429 */
1430static void
1431ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
1432{
1395 int i;
1396
1397 master_tstate = ahc->enabled_targets[ahc->our_id];
1398 if (channel == 'B') {
1399 scsi_id += 8;
1400 master_tstate = ahc->enabled_targets[ahc->our_id_b + 8];
1401 }
1402 if (ahc->enabled_targets[scsi_id] != NULL

--- 29 unchanged lines hidden (view full) ---

1432#ifdef AHC_TARGET_MODE
1433/*
1434 * Free per target mode instance (ID we respond to as a target)
1435 * transfer negotiation data structures.
1436 */
1437static void
1438ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
1439{
1433 struct tmode_tstate *tstate;
1440 struct ahc_tmode_tstate *tstate;
1434
1441
1435 /* Don't clean up the entry for our initiator role */
1436 if ((ahc->flags & AHC_INITIATORROLE) != 0
1437 && ((channel == 'B' && scsi_id == ahc->our_id_b)
1442 /*
1443 * Don't clean up our "master" tstate.
1444 * It has our default user settings.
1445 */
1446 if (((channel == 'B' && scsi_id == ahc->our_id_b)
1438 || (channel == 'A' && scsi_id == ahc->our_id))
1439 && force == FALSE)
1440 return;
1441
1442 if (channel == 'B')
1443 scsi_id += 8;
1444 tstate = ahc->enabled_targets[scsi_id];
1445 if (tstate != NULL)

--- 213 unchanged lines hidden (view full) ---

1659}
1660
1661/*
1662 * Update the bitmask of targets for which the controller should
1663 * negotiate with at the next convenient oportunity. This currently
1664 * means the next time we send the initial identify messages for
1665 * a new transaction.
1666 */
1447 || (channel == 'A' && scsi_id == ahc->our_id))
1448 && force == FALSE)
1449 return;
1450
1451 if (channel == 'B')
1452 scsi_id += 8;
1453 tstate = ahc->enabled_targets[scsi_id];
1454 if (tstate != NULL)

--- 213 unchanged lines hidden (view full) ---

1668}
1669
1670/*
1671 * Update the bitmask of targets for which the controller should
1672 * negotiate with at the next convenient oportunity. This currently
1673 * means the next time we send the initial identify messages for
1674 * a new transaction.
1675 */
1667void
1668ahc_update_target_msg_request(struct ahc_softc *ahc,
1669 struct ahc_devinfo *devinfo,
1670 struct ahc_initiator_tinfo *tinfo,
1671 int force, int paused)
1676int
1677ahc_update_neg_request(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1678 struct ahc_tmode_tstate *tstate,
1679 struct ahc_initiator_tinfo *tinfo, int force)
1672{
1680{
1673 u_int targ_msg_req_orig;
1681 u_int auto_negotiate_orig;
1674
1682
1675 targ_msg_req_orig = ahc->targ_msg_req;
1683 auto_negotiate_orig = tstate->auto_negotiate;
1676 if (tinfo->current.period != tinfo->goal.period
1677 || tinfo->current.width != tinfo->goal.width
1678 || tinfo->current.offset != tinfo->goal.offset
1679 || tinfo->current.ppr_options != tinfo->goal.ppr_options
1680 || (force
1681 && (tinfo->goal.period != 0
1682 || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT
1683 || tinfo->goal.ppr_options != 0)))
1684 if (tinfo->current.period != tinfo->goal.period
1685 || tinfo->current.width != tinfo->goal.width
1686 || tinfo->current.offset != tinfo->goal.offset
1687 || tinfo->current.ppr_options != tinfo->goal.ppr_options
1688 || (force
1689 && (tinfo->goal.period != 0
1690 || tinfo->goal.width != MSG_EXT_WDTR_BUS_8_BIT
1691 || tinfo->goal.ppr_options != 0)))
1684 ahc->targ_msg_req |= devinfo->target_mask;
1692 tstate->auto_negotiate |= devinfo->target_mask;
1685 else
1693 else
1686 ahc->targ_msg_req &= ~devinfo->target_mask;
1694 tstate->auto_negotiate &= ~devinfo->target_mask;
1687
1695
1688 if (ahc->targ_msg_req != targ_msg_req_orig) {
1689 /* Update the message request bit for this target */
1690 if (!paused)
1691 ahc_pause(ahc);
1692
1693 ahc_outb(ahc, TARGET_MSG_REQUEST,
1694 ahc->targ_msg_req & 0xFF);
1695 ahc_outb(ahc, TARGET_MSG_REQUEST + 1,
1696 (ahc->targ_msg_req >> 8) & 0xFF);
1697
1698 if (!paused)
1699 ahc_unpause(ahc);
1700 }
1696 return (auto_negotiate_orig != tstate->auto_negotiate);
1701}
1702
1703/*
1704 * Update the user/goal/current tables of synchronous negotiation
1705 * parameters as well as, in the case of a current or active update,
1706 * any data structures on the host controller. In the case of an
1707 * active update, the specified target is currently talking to us on
1708 * the bus, so the transfer parameter update must take effect
1709 * immediately.
1710 */
1711void
1712ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1713 struct ahc_syncrate *syncrate, u_int period,
1714 u_int offset, u_int ppr_options, u_int type, int paused)
1715{
1716 struct ahc_initiator_tinfo *tinfo;
1697}
1698
1699/*
1700 * Update the user/goal/current tables of synchronous negotiation
1701 * parameters as well as, in the case of a current or active update,
1702 * any data structures on the host controller. In the case of an
1703 * active update, the specified target is currently talking to us on
1704 * the bus, so the transfer parameter update must take effect
1705 * immediately.
1706 */
1707void
1708ahc_set_syncrate(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1709 struct ahc_syncrate *syncrate, u_int period,
1710 u_int offset, u_int ppr_options, u_int type, int paused)
1711{
1712 struct ahc_initiator_tinfo *tinfo;
1717 struct tmode_tstate *tstate;
1713 struct ahc_tmode_tstate *tstate;
1718 u_int old_period;
1719 u_int old_offset;
1720 u_int old_ppr;
1714 u_int old_period;
1715 u_int old_offset;
1716 u_int old_ppr;
1721 int active = (type & AHC_TRANS_ACTIVE) == AHC_TRANS_ACTIVE;
1717 int active;
1718 int update_needed;
1722
1719
1720 active = (type & AHC_TRANS_ACTIVE) == AHC_TRANS_ACTIVE;
1721 update_needed = 0;
1722
1723 if (syncrate == NULL) {
1724 period = 0;
1725 offset = 0;
1726 }
1727
1728 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1729 devinfo->target, &tstate);
1730

--- 14 unchanged lines hidden (view full) ---

1745 old_ppr = tinfo->current.ppr_options;
1746
1747 if ((type & AHC_TRANS_CUR) != 0
1748 && (old_period != period
1749 || old_offset != offset
1750 || old_ppr != ppr_options)) {
1751 u_int scsirate;
1752
1723 if (syncrate == NULL) {
1724 period = 0;
1725 offset = 0;
1726 }
1727
1728 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1729 devinfo->target, &tstate);
1730

--- 14 unchanged lines hidden (view full) ---

1745 old_ppr = tinfo->current.ppr_options;
1746
1747 if ((type & AHC_TRANS_CUR) != 0
1748 && (old_period != period
1749 || old_offset != offset
1750 || old_ppr != ppr_options)) {
1751 u_int scsirate;
1752
1753 update_needed++;
1753 scsirate = tinfo->scsirate;
1754 if ((ahc->features & AHC_ULTRA2) != 0) {
1755
1756 scsirate &= ~(SXFR_ULTRA2|SINGLE_EDGE|ENABLE_CRC);
1757 if (syncrate != NULL) {
1758 scsirate |= syncrate->sxfr_u2;
1759 if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0)
1760 scsirate |= ENABLE_CRC;

--- 32 unchanged lines hidden (view full) ---

1793 ahc_outb(ahc, SCSIOFFSET, offset);
1794 }
1795
1796 tinfo->scsirate = scsirate;
1797 tinfo->current.period = period;
1798 tinfo->current.offset = offset;
1799 tinfo->current.ppr_options = ppr_options;
1800
1754 scsirate = tinfo->scsirate;
1755 if ((ahc->features & AHC_ULTRA2) != 0) {
1756
1757 scsirate &= ~(SXFR_ULTRA2|SINGLE_EDGE|ENABLE_CRC);
1758 if (syncrate != NULL) {
1759 scsirate |= syncrate->sxfr_u2;
1760 if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0)
1761 scsirate |= ENABLE_CRC;

--- 32 unchanged lines hidden (view full) ---

1794 ahc_outb(ahc, SCSIOFFSET, offset);
1795 }
1796
1797 tinfo->scsirate = scsirate;
1798 tinfo->current.period = period;
1799 tinfo->current.offset = offset;
1800 tinfo->current.ppr_options = ppr_options;
1801
1801 /* Update the syncrates in any pending scbs */
1802 ahc_update_pending_syncrates(ahc);
1803
1804 ahc_send_async(ahc, devinfo->channel, devinfo->target,
1805 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
1806 if (bootverbose) {
1807 if (offset != 0) {
1808 printf("%s: target %d synchronous at %sMHz%s, "
1809 "offset = 0x%x\n", ahc_name(ahc),
1810 devinfo->target, syncrate->rate,
1811 (ppr_options & MSG_EXT_PPR_DT_REQ)
1812 ? " DT" : "", offset);
1813 } else {
1814 printf("%s: target %d using "
1815 "asynchronous transfers\n",
1816 ahc_name(ahc), devinfo->target);
1817 }
1818 }
1819 }
1820
1802 ahc_send_async(ahc, devinfo->channel, devinfo->target,
1803 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
1804 if (bootverbose) {
1805 if (offset != 0) {
1806 printf("%s: target %d synchronous at %sMHz%s, "
1807 "offset = 0x%x\n", ahc_name(ahc),
1808 devinfo->target, syncrate->rate,
1809 (ppr_options & MSG_EXT_PPR_DT_REQ)
1810 ? " DT" : "", offset);
1811 } else {
1812 printf("%s: target %d using "
1813 "asynchronous transfers\n",
1814 ahc_name(ahc), devinfo->target);
1815 }
1816 }
1817 }
1818
1821 ahc_update_target_msg_request(ahc, devinfo, tinfo,
1822 /*force*/FALSE,
1823 paused);
1819 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
1820 tinfo, /*force*/FALSE);
1821
1822 if (update_needed)
1823 ahc_update_pending_scbs(ahc);
1824}
1825
1826/*
1827 * Update the user/goal/current tables of wide negotiation
1828 * parameters as well as, in the case of a current or active update,
1829 * any data structures on the host controller. In the case of an
1830 * active update, the specified target is currently talking to us on
1831 * the bus, so the transfer parameter update must take effect
1832 * immediately.
1833 */
1834void
1835ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1836 u_int width, u_int type, int paused)
1837{
1824}
1825
1826/*
1827 * Update the user/goal/current tables of wide negotiation
1828 * parameters as well as, in the case of a current or active update,
1829 * any data structures on the host controller. In the case of an
1830 * active update, the specified target is currently talking to us on
1831 * the bus, so the transfer parameter update must take effect
1832 * immediately.
1833 */
1834void
1835ahc_set_width(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1836 u_int width, u_int type, int paused)
1837{
1838 struct ahc_initiator_tinfo *tinfo;
1839 struct tmode_tstate *tstate;
1840 u_int oldwidth;
1841 int active = (type & AHC_TRANS_ACTIVE) == AHC_TRANS_ACTIVE;
1838 struct ahc_initiator_tinfo *tinfo;
1839 struct ahc_tmode_tstate *tstate;
1840 u_int oldwidth;
1841 int active;
1842 int update_needed;
1842
1843
1844 active = (type & AHC_TRANS_ACTIVE) == AHC_TRANS_ACTIVE;
1845 update_needed = 0;
1843 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1844 devinfo->target, &tstate);
1845
1846 if ((type & AHC_TRANS_USER) != 0)
1847 tinfo->user.width = width;
1848
1849 if ((type & AHC_TRANS_GOAL) != 0)
1850 tinfo->goal.width = width;
1851
1852 oldwidth = tinfo->current.width;
1853 if ((type & AHC_TRANS_CUR) != 0 && oldwidth != width) {
1854 u_int scsirate;
1855
1846 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1847 devinfo->target, &tstate);
1848
1849 if ((type & AHC_TRANS_USER) != 0)
1850 tinfo->user.width = width;
1851
1852 if ((type & AHC_TRANS_GOAL) != 0)
1853 tinfo->goal.width = width;
1854
1855 oldwidth = tinfo->current.width;
1856 if ((type & AHC_TRANS_CUR) != 0 && oldwidth != width) {
1857 u_int scsirate;
1858
1859 update_needed++;
1856 scsirate = tinfo->scsirate;
1857 scsirate &= ~WIDEXFER;
1858 if (width == MSG_EXT_WDTR_BUS_16_BIT)
1859 scsirate |= WIDEXFER;
1860
1861 tinfo->scsirate = scsirate;
1862
1863 if (active)

--- 5 unchanged lines hidden (view full) ---

1869 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
1870 if (bootverbose) {
1871 printf("%s: target %d using %dbit transfers\n",
1872 ahc_name(ahc), devinfo->target,
1873 8 * (0x01 << width));
1874 }
1875 }
1876
1860 scsirate = tinfo->scsirate;
1861 scsirate &= ~WIDEXFER;
1862 if (width == MSG_EXT_WDTR_BUS_16_BIT)
1863 scsirate |= WIDEXFER;
1864
1865 tinfo->scsirate = scsirate;
1866
1867 if (active)

--- 5 unchanged lines hidden (view full) ---

1873 CAM_LUN_WILDCARD, AC_TRANSFER_NEG);
1874 if (bootverbose) {
1875 printf("%s: target %d using %dbit transfers\n",
1876 ahc_name(ahc), devinfo->target,
1877 8 * (0x01 << width));
1878 }
1879 }
1880
1877 ahc_update_target_msg_request(ahc, devinfo, tinfo,
1878 /*force*/FALSE, paused);
1881 update_needed += ahc_update_neg_request(ahc, devinfo, tstate,
1882 tinfo, /*force*/FALSE);
1883 if (update_needed)
1884 ahc_update_pending_scbs(ahc);
1879}
1880
1881/*
1882 * Update the current state of tagged queuing for a given target.
1883 */
1884void
1885ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, int enable)
1886{
1887 struct ahc_initiator_tinfo *tinfo;
1885}
1886
1887/*
1888 * Update the current state of tagged queuing for a given target.
1889 */
1890void
1891ahc_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, int enable)
1892{
1893 struct ahc_initiator_tinfo *tinfo;
1888 struct tmode_tstate *tstate;
1894 struct ahc_tmode_tstate *tstate;
1889 uint16_t orig_tagenable;
1890
1891 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1892 devinfo->target, &tstate);
1893
1894 orig_tagenable = tstate->tagenable;
1895 if (enable)
1896 tstate->tagenable |= devinfo->target_mask;

--- 9 unchanged lines hidden (view full) ---

1906}
1907
1908/*
1909 * When the transfer settings for a connection change, update any
1910 * in-transit SCBs to contain the new data so the hardware will
1911 * be set correctly during future (re)selections.
1912 */
1913static void
1895 uint16_t orig_tagenable;
1896
1897 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel, devinfo->our_scsiid,
1898 devinfo->target, &tstate);
1899
1900 orig_tagenable = tstate->tagenable;
1901 if (enable)
1902 tstate->tagenable |= devinfo->target_mask;

--- 9 unchanged lines hidden (view full) ---

1912}
1913
1914/*
1915 * When the transfer settings for a connection change, update any
1916 * in-transit SCBs to contain the new data so the hardware will
1917 * be set correctly during future (re)selections.
1918 */
1919static void
1914ahc_update_pending_syncrates(struct ahc_softc *ahc)
1920ahc_update_pending_scbs(struct ahc_softc *ahc)
1915{
1916 struct scb *pending_scb;
1917 int pending_scb_count;
1918 int i;
1919 u_int saved_scbptr;
1920
1921 /*
1922 * Traverse the pending SCB list and ensure that all of the
1923 * SCBs there have the proper settings.
1924 */
1925 pending_scb_count = 0;
1926 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
1927 struct ahc_devinfo devinfo;
1928 struct hardware_scb *pending_hscb;
1929 struct ahc_initiator_tinfo *tinfo;
1921{
1922 struct scb *pending_scb;
1923 int pending_scb_count;
1924 int i;
1925 u_int saved_scbptr;
1926
1927 /*
1928 * Traverse the pending SCB list and ensure that all of the
1929 * SCBs there have the proper settings.
1930 */
1931 pending_scb_count = 0;
1932 LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
1933 struct ahc_devinfo devinfo;
1934 struct hardware_scb *pending_hscb;
1935 struct ahc_initiator_tinfo *tinfo;
1930 struct tmode_tstate *tstate;
1936 struct ahc_tmode_tstate *tstate;
1931
1932 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
1933 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
1934 devinfo.our_scsiid,
1935 devinfo.target, &tstate);
1936 pending_hscb = pending_scb->hscb;
1937 pending_hscb->control &= ~ULTRAENB;
1938 if ((tstate->ultraenb & devinfo.target_mask) != 0)
1939 pending_hscb->control |= ULTRAENB;
1940 pending_hscb->scsirate = tinfo->scsirate;
1941 pending_hscb->scsioffset = tinfo->current.offset;
1937
1938 ahc_scb_devinfo(ahc, &devinfo, pending_scb);
1939 tinfo = ahc_fetch_transinfo(ahc, devinfo.channel,
1940 devinfo.our_scsiid,
1941 devinfo.target, &tstate);
1942 pending_hscb = pending_scb->hscb;
1943 pending_hscb->control &= ~ULTRAENB;
1944 if ((tstate->ultraenb & devinfo.target_mask) != 0)
1945 pending_hscb->control |= ULTRAENB;
1946 pending_hscb->scsirate = tinfo->scsirate;
1947 pending_hscb->scsioffset = tinfo->current.offset;
1948 if ((tstate->auto_negotiate & devinfo.target_mask) == 0
1949 && (pending_scb->flags & SCB_AUTO_NEGOTIATE) != 0) {
1950 pending_scb->flags &= ~SCB_AUTO_NEGOTIATE;
1951 pending_hscb->control &= ~MK_MESSAGE;
1952 }
1942 pending_scb_count++;
1943 }
1944
1945 if (pending_scb_count == 0)
1946 return;
1947
1948 saved_scbptr = ahc_inb(ahc, SCBPTR);
1949 /* Ensure that the hscbs down on the card match the new information */

--- 5 unchanged lines hidden (view full) ---

1955 ahc_outb(ahc, SCBPTR, i);
1956 scb_tag = ahc_inb(ahc, SCB_TAG);
1957 pending_scb = ahc_lookup_scb(ahc, scb_tag);
1958 if (pending_scb == NULL)
1959 continue;
1960
1961 pending_hscb = pending_scb->hscb;
1962 control = ahc_inb(ahc, SCB_CONTROL);
1953 pending_scb_count++;
1954 }
1955
1956 if (pending_scb_count == 0)
1957 return;
1958
1959 saved_scbptr = ahc_inb(ahc, SCBPTR);
1960 /* Ensure that the hscbs down on the card match the new information */

--- 5 unchanged lines hidden (view full) ---

1966 ahc_outb(ahc, SCBPTR, i);
1967 scb_tag = ahc_inb(ahc, SCB_TAG);
1968 pending_scb = ahc_lookup_scb(ahc, scb_tag);
1969 if (pending_scb == NULL)
1970 continue;
1971
1972 pending_hscb = pending_scb->hscb;
1973 control = ahc_inb(ahc, SCB_CONTROL);
1963 control &= ~ULTRAENB;
1964 if ((pending_hscb->control & ULTRAENB) != 0)
1965 control |= ULTRAENB;
1974 control &= ~(ULTRAENB|MK_MESSAGE);
1975 control |= pending_hscb->control & (ULTRAENB|MK_MESSAGE);
1966 ahc_outb(ahc, SCB_CONTROL, control);
1967 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
1968 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
1969 }
1970 ahc_outb(ahc, SCBPTR, saved_scbptr);
1971}
1972
1973/**************************** Pathing Information *****************************/

--- 139 unchanged lines hidden (view full) ---

2113 /*
2114 * Clear our selection hardware in advance of
2115 * the busfree. We may have an entry in the waiting
2116 * Q for this target, and we don't want to go about
2117 * selecting while we handle the busfree and blow it
2118 * away.
2119 */
2120 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
1976 ahc_outb(ahc, SCB_CONTROL, control);
1977 ahc_outb(ahc, SCB_SCSIRATE, pending_hscb->scsirate);
1978 ahc_outb(ahc, SCB_SCSIOFFSET, pending_hscb->scsioffset);
1979 }
1980 ahc_outb(ahc, SCBPTR, saved_scbptr);
1981}
1982
1983/**************************** Pathing Information *****************************/

--- 139 unchanged lines hidden (view full) ---

2123 /*
2124 * Clear our selection hardware in advance of
2125 * the busfree. We may have an entry in the waiting
2126 * Q for this target, and we don't want to go about
2127 * selecting while we handle the busfree and blow it
2128 * away.
2129 */
2130 ahc_outb(ahc, SCSISEQ, (ahc_inb(ahc, SCSISEQ) & ~ENSELO));
2121 } else if ((ahc->targ_msg_req & devinfo->target_mask) != 0
2122 || (scb->flags & SCB_NEGOTIATE) != 0) {
2131 } else if ((scb->flags & (SCB_AUTO_NEGOTIATE|SCB_NEGOTIATE)) != 0) {
2123 ahc_build_transfer_msg(ahc, devinfo);
2124 } else {
2125 printf("ahc_intr: AWAITING_MSG for an SCB that "
2126 "does not have a waiting message\n");
2127 printf("SCSIID = %x, target_mask = %x\n", scb->hscb->scsiid,
2128 devinfo->target_mask);
2129 panic("SCB = %d, SCB Control = %x, MSG_OUT = %x "
2130 "SCB flags = %x", scb->hscb->tag, scb->hscb->control,
2131 ahc_inb(ahc, MSG_OUT), scb->flags);
2132 }
2133
2134 /*
2135 * Clear the MK_MESSAGE flag from the SCB so we aren't
2136 * asked to send this message again.
2137 */
2138 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
2132 ahc_build_transfer_msg(ahc, devinfo);
2133 } else {
2134 printf("ahc_intr: AWAITING_MSG for an SCB that "
2135 "does not have a waiting message\n");
2136 printf("SCSIID = %x, target_mask = %x\n", scb->hscb->scsiid,
2137 devinfo->target_mask);
2138 panic("SCB = %d, SCB Control = %x, MSG_OUT = %x "
2139 "SCB flags = %x", scb->hscb->tag, scb->hscb->control,
2140 ahc_inb(ahc, MSG_OUT), scb->flags);
2141 }
2142
2143 /*
2144 * Clear the MK_MESSAGE flag from the SCB so we aren't
2145 * asked to send this message again.
2146 */
2147 ahc_outb(ahc, SCB_CONTROL, ahc_inb(ahc, SCB_CONTROL) & ~MK_MESSAGE);
2148 scb->hscb->control &= ~MK_MESSAGE;
2139 ahc->msgout_index = 0;
2140 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2141}
2142
2143/*
2144 * Build an appropriate transfer negotiation message for the
2145 * currently active target.
2146 */
2147static void
2148ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2149{
2150 /*
2151 * We need to initiate transfer negotiations.
2152 * If our current and goal settings are identical,
2153 * we want to renegotiate due to a check condition.
2154 */
2155 struct ahc_initiator_tinfo *tinfo;
2149 ahc->msgout_index = 0;
2150 ahc->msg_type = MSG_TYPE_INITIATOR_MSGOUT;
2151}
2152
2153/*
2154 * Build an appropriate transfer negotiation message for the
2155 * currently active target.
2156 */
2157static void
2158ahc_build_transfer_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2159{
2160 /*
2161 * We need to initiate transfer negotiations.
2162 * If our current and goal settings are identical,
2163 * we want to renegotiate due to a check condition.
2164 */
2165 struct ahc_initiator_tinfo *tinfo;
2156 struct tmode_tstate *tstate;
2166 struct ahc_tmode_tstate *tstate;
2157 struct ahc_syncrate *rate;
2158 int dowide;
2159 int dosync;
2160 int doppr;
2161 int use_ppr;
2162 u_int period;
2163 u_int ppr_options;
2164 u_int offset;

--- 440 unchanged lines hidden (view full) ---

2605
2606/*
2607 * Wait for a complete incomming message, parse it, and respond accordingly.
2608 */
2609static int
2610ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2611{
2612 struct ahc_initiator_tinfo *tinfo;
2167 struct ahc_syncrate *rate;
2168 int dowide;
2169 int dosync;
2170 int doppr;
2171 int use_ppr;
2172 u_int period;
2173 u_int ppr_options;
2174 u_int offset;

--- 440 unchanged lines hidden (view full) ---

2615
2616/*
2617 * Wait for a complete incomming message, parse it, and respond accordingly.
2618 */
2619static int
2620ahc_parse_msg(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
2621{
2622 struct ahc_initiator_tinfo *tinfo;
2613 struct tmode_tstate *tstate;
2623 struct ahc_tmode_tstate *tstate;
2614 int reject;
2615 int done;
2616 int response;
2617 u_int targ_scsirate;
2618
2619 done = MSGLOOP_IN_PROG;
2620 response = FALSE;
2621 reject = FALSE;

--- 82 unchanged lines hidden (view full) ---

2704 if (saved_offset != offset) {
2705 /* Went too low - force async */
2706 reject = TRUE;
2707 }
2708 } else {
2709 /*
2710 * Send our own SDTR in reply
2711 */
2624 int reject;
2625 int done;
2626 int response;
2627 u_int targ_scsirate;
2628
2629 done = MSGLOOP_IN_PROG;
2630 response = FALSE;
2631 reject = FALSE;

--- 82 unchanged lines hidden (view full) ---

2714 if (saved_offset != offset) {
2715 /* Went too low - force async */
2716 reject = TRUE;
2717 }
2718 } else {
2719 /*
2720 * Send our own SDTR in reply
2721 */
2712 if (bootverbose) {
2722 if (bootverbose
2723 && devinfo->role == ROLE_INITIATOR) {
2713 printf("(%s:%c:%d:%d): Target "
2714 "Initiated SDTR\n",
2715 ahc_name(ahc), devinfo->channel,
2716 devinfo->target, devinfo->lun);
2717 }
2718 ahc->msgout_index = 0;
2719 ahc->msgout_len = 0;
2720 ahc_construct_sdtr(ahc, devinfo,

--- 53 unchanged lines hidden (view full) ---

2774 devinfo->target, devinfo->lun,
2775 8 * (0x01 << bus_width));
2776 bus_width = 0;
2777 }
2778 } else {
2779 /*
2780 * Send our own WDTR in reply
2781 */
2724 printf("(%s:%c:%d:%d): Target "
2725 "Initiated SDTR\n",
2726 ahc_name(ahc), devinfo->channel,
2727 devinfo->target, devinfo->lun);
2728 }
2729 ahc->msgout_index = 0;
2730 ahc->msgout_len = 0;
2731 ahc_construct_sdtr(ahc, devinfo,

--- 53 unchanged lines hidden (view full) ---

2785 devinfo->target, devinfo->lun,
2786 8 * (0x01 << bus_width));
2787 bus_width = 0;
2788 }
2789 } else {
2790 /*
2791 * Send our own WDTR in reply
2792 */
2782 if (bootverbose) {
2793 if (bootverbose
2794 && devinfo->role == ROLE_INITIATOR) {
2783 printf("(%s:%c:%d:%d): Target "
2784 "Initiated WDTR\n",
2785 ahc_name(ahc), devinfo->channel,
2786 devinfo->target, devinfo->lun);
2787 }
2788 ahc->msgout_index = 0;
2789 ahc->msgout_len = 0;
2790 ahc_construct_wdtr(ahc, devinfo, bus_width);

--- 166 unchanged lines hidden (view full) ---

2957 devinfo->lun,
2958 ahc->msgin_buf[0] == MSG_ABORT_TAG
2959 ? SCB_LIST_NULL
2960 : ahc_inb(ahc, INITIATOR_TAG),
2961 ROLE_TARGET, CAM_REQ_ABORTED);
2962
2963 tstate = ahc->enabled_targets[devinfo->our_scsiid];
2964 if (tstate != NULL) {
2795 printf("(%s:%c:%d:%d): Target "
2796 "Initiated WDTR\n",
2797 ahc_name(ahc), devinfo->channel,
2798 devinfo->target, devinfo->lun);
2799 }
2800 ahc->msgout_index = 0;
2801 ahc->msgout_len = 0;
2802 ahc_construct_wdtr(ahc, devinfo, bus_width);

--- 166 unchanged lines hidden (view full) ---

2969 devinfo->lun,
2970 ahc->msgin_buf[0] == MSG_ABORT_TAG
2971 ? SCB_LIST_NULL
2972 : ahc_inb(ahc, INITIATOR_TAG),
2973 ROLE_TARGET, CAM_REQ_ABORTED);
2974
2975 tstate = ahc->enabled_targets[devinfo->our_scsiid];
2976 if (tstate != NULL) {
2965 struct tmode_lstate* lstate;
2977 struct ahc_tmode_lstate* lstate;
2966
2967 lstate = tstate->enabled_luns[devinfo->lun];
2968 if (lstate != NULL) {
2969 ahc_queue_lstate_event(ahc, lstate,
2970 devinfo->our_scsiid,
2971 ahc->msgin_buf[0],
2972 /*arg*/0);
2973 ahc_send_lstate_events(ahc, lstate);

--- 35 unchanged lines hidden (view full) ---

3009 /*
3010 * What we care about here is if we had an
3011 * outstanding SDTR or WDTR message for this
3012 * target. If we did, this is a signal that
3013 * the target is refusing negotiation.
3014 */
3015 struct scb *scb;
3016 struct ahc_initiator_tinfo *tinfo;
2978
2979 lstate = tstate->enabled_luns[devinfo->lun];
2980 if (lstate != NULL) {
2981 ahc_queue_lstate_event(ahc, lstate,
2982 devinfo->our_scsiid,
2983 ahc->msgin_buf[0],
2984 /*arg*/0);
2985 ahc_send_lstate_events(ahc, lstate);

--- 35 unchanged lines hidden (view full) ---

3021 /*
3022 * What we care about here is if we had an
3023 * outstanding SDTR or WDTR message for this
3024 * target. If we did, this is a signal that
3025 * the target is refusing negotiation.
3026 */
3027 struct scb *scb;
3028 struct ahc_initiator_tinfo *tinfo;
3017 struct tmode_tstate *tstate;
3029 struct ahc_tmode_tstate *tstate;
3018 u_int scb_index;
3019 u_int last_msg;
3020 int response = 0;
3021
3022 scb_index = ahc_inb(ahc, SCB_TAG);
3023 scb = ahc_lookup_scb(ahc, scb_index);
3024 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
3025 devinfo->our_scsiid,

--- 229 unchanged lines hidden (view full) ---

3255/*
3256 * Handle the effects of issuing a bus device reset message.
3257 */
3258static void
3259ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3260 cam_status status, char *message, int verbose_level)
3261{
3262#ifdef AHC_TARGET_MODE
3030 u_int scb_index;
3031 u_int last_msg;
3032 int response = 0;
3033
3034 scb_index = ahc_inb(ahc, SCB_TAG);
3035 scb = ahc_lookup_scb(ahc, scb_index);
3036 tinfo = ahc_fetch_transinfo(ahc, devinfo->channel,
3037 devinfo->our_scsiid,

--- 229 unchanged lines hidden (view full) ---

3267/*
3268 * Handle the effects of issuing a bus device reset message.
3269 */
3270static void
3271ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3272 cam_status status, char *message, int verbose_level)
3273{
3274#ifdef AHC_TARGET_MODE
3263 struct tmode_tstate* tstate;
3275 struct ahc_tmode_tstate* tstate;
3264 u_int lun;
3265#endif
3266 int found;
3267
3268 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3269 CAM_LUN_WILDCARD, SCB_LIST_NULL, devinfo->role,
3270 status);
3271
3272#ifdef AHC_TARGET_MODE
3273 /*
3274 * Send an immediate notify ccb to all target mord peripheral
3275 * drivers affected by this action.
3276 */
3277 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3278 if (tstate != NULL) {
3279 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
3276 u_int lun;
3277#endif
3278 int found;
3279
3280 found = ahc_abort_scbs(ahc, devinfo->target, devinfo->channel,
3281 CAM_LUN_WILDCARD, SCB_LIST_NULL, devinfo->role,
3282 status);
3283
3284#ifdef AHC_TARGET_MODE
3285 /*
3286 * Send an immediate notify ccb to all target mord peripheral
3287 * drivers affected by this action.
3288 */
3289 tstate = ahc->enabled_targets[devinfo->our_scsiid];
3290 if (tstate != NULL) {
3291 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
3280 struct tmode_lstate* lstate;
3292 struct ahc_tmode_lstate* lstate;
3281
3282 lstate = tstate->enabled_luns[lun];
3283 if (lstate == NULL)
3284 continue;
3285
3286 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
3287 MSG_BUS_DEV_RESET, /*arg*/0);
3288 ahc_send_lstate_events(ahc, lstate);

--- 15 unchanged lines hidden (view full) ---

3304
3305 if (message != NULL
3306 && (verbose_level <= bootverbose))
3307 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
3308 message, devinfo->channel, devinfo->target, found);
3309}
3310
3311#ifdef AHC_TARGET_MODE
3293
3294 lstate = tstate->enabled_luns[lun];
3295 if (lstate == NULL)
3296 continue;
3297
3298 ahc_queue_lstate_event(ahc, lstate, devinfo->our_scsiid,
3299 MSG_BUS_DEV_RESET, /*arg*/0);
3300 ahc_send_lstate_events(ahc, lstate);

--- 15 unchanged lines hidden (view full) ---

3316
3317 if (message != NULL
3318 && (verbose_level <= bootverbose))
3319 printf("%s: %s on %c:%d. %d SCBs aborted\n", ahc_name(ahc),
3320 message, devinfo->channel, devinfo->target, found);
3321}
3322
3323#ifdef AHC_TARGET_MODE
3312void
3313ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
3324static void
3325ahc_setup_target_msgin(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3326 struct scb *scb)
3314{
3327{
3328
3315 /*
3316 * To facilitate adding multiple messages together,
3317 * each routine should increment the index and len
3318 * variables instead of setting them explicitly.
3319 */
3320 ahc->msgout_index = 0;
3321 ahc->msgout_len = 0;
3322
3329 /*
3330 * To facilitate adding multiple messages together,
3331 * each routine should increment the index and len
3332 * variables instead of setting them explicitly.
3333 */
3334 ahc->msgout_index = 0;
3335 ahc->msgout_len = 0;
3336
3323 if ((ahc->targ_msg_req & devinfo->target_mask) != 0)
3337 if (scb != NULL && (scb->flags & SCB_AUTO_NEGOTIATE) != 0)
3324 ahc_build_transfer_msg(ahc, devinfo);
3325 else
3326 panic("ahc_intr: AWAITING target message with no message");
3327
3328 ahc->msgout_index = 0;
3329 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3330}
3331#endif

--- 17 unchanged lines hidden (view full) ---

3349 }
3350#else
3351 ahc = device_get_softc((device_t)platform_arg);
3352#endif
3353 memset(ahc, 0, sizeof(*ahc));
3354 LIST_INIT(&ahc->pending_scbs);
3355 /* We don't know our unit number until the OSM sets it */
3356 ahc->name = name;
3338 ahc_build_transfer_msg(ahc, devinfo);
3339 else
3340 panic("ahc_intr: AWAITING target message with no message");
3341
3342 ahc->msgout_index = 0;
3343 ahc->msg_type = MSG_TYPE_TARGET_MSGIN;
3344}
3345#endif

--- 17 unchanged lines hidden (view full) ---

3363 }
3364#else
3365 ahc = device_get_softc((device_t)platform_arg);
3366#endif
3367 memset(ahc, 0, sizeof(*ahc));
3368 LIST_INIT(&ahc->pending_scbs);
3369 /* We don't know our unit number until the OSM sets it */
3370 ahc->name = name;
3371 ahc->unit = -1;
3357 for (i = 0; i < 16; i++)
3358 TAILQ_INIT(&ahc->untagged_queues[i]);
3359 if (ahc_platform_alloc(ahc, platform_arg) != 0) {
3360 ahc_free(ahc);
3361 ahc = NULL;
3362 }
3363 return (ahc);
3364}
3365
3366int
3367ahc_softc_init(struct ahc_softc *ahc, struct ahc_probe_config *config)
3368{
3369
3370 ahc->chip = config->chip;
3371 ahc->features = config->features;
3372 ahc->bugs = config->bugs;
3373 ahc->flags = config->flags;
3374 ahc->channel = config->channel;
3372 for (i = 0; i < 16; i++)
3373 TAILQ_INIT(&ahc->untagged_queues[i]);
3374 if (ahc_platform_alloc(ahc, platform_arg) != 0) {
3375 ahc_free(ahc);
3376 ahc = NULL;
3377 }
3378 return (ahc);
3379}
3380
3381int
3382ahc_softc_init(struct ahc_softc *ahc, struct ahc_probe_config *config)
3383{
3384
3385 ahc->chip = config->chip;
3386 ahc->features = config->features;
3387 ahc->bugs = config->bugs;
3388 ahc->flags = config->flags;
3389 ahc->channel = config->channel;
3375 ahc->unpause = (ahc_inb(ahc, HCNTRL) & IRQMS) | INTEN;
3390 ahc->unpause = (ahc_inb(ahc, HCNTRL) & IRQMS);
3376 ahc->description = config->description;
3377 /* The IRQMS bit is only valid on VL and EISA chips */
3378 if ((ahc->chip & AHC_PCI) != 0)
3379 ahc->unpause &= ~IRQMS;
3380 ahc->pause = ahc->unpause | PAUSE;
3381 /* XXX The shared scb data stuff should be deprecated */
3382 if (ahc->scb_data == NULL) {
3383 ahc->scb_data = malloc(sizeof(*ahc->scb_data),

--- 109 unchanged lines hidden (view full) ---

3493 break;
3494 }
3495
3496#ifndef __linux__
3497 ahc_dma_tag_destroy(ahc, ahc->parent_dmat);
3498#endif
3499 ahc_platform_free(ahc);
3500 for (i = 0; i < AHC_NUM_TARGETS; i++) {
3391 ahc->description = config->description;
3392 /* The IRQMS bit is only valid on VL and EISA chips */
3393 if ((ahc->chip & AHC_PCI) != 0)
3394 ahc->unpause &= ~IRQMS;
3395 ahc->pause = ahc->unpause | PAUSE;
3396 /* XXX The shared scb data stuff should be deprecated */
3397 if (ahc->scb_data == NULL) {
3398 ahc->scb_data = malloc(sizeof(*ahc->scb_data),

--- 109 unchanged lines hidden (view full) ---

3508 break;
3509 }
3510
3511#ifndef __linux__
3512 ahc_dma_tag_destroy(ahc, ahc->parent_dmat);
3513#endif
3514 ahc_platform_free(ahc);
3515 for (i = 0; i < AHC_NUM_TARGETS; i++) {
3501 struct tmode_tstate *tstate;
3516 struct ahc_tmode_tstate *tstate;
3502
3503 tstate = ahc->enabled_targets[i];
3504 if (tstate != NULL) {
3505#if AHC_TARGET_MODE
3506 int j;
3507
3508 for (j = 0; j < AHC_NUM_LUNS; j++) {
3517
3518 tstate = ahc->enabled_targets[i];
3519 if (tstate != NULL) {
3520#if AHC_TARGET_MODE
3521 int j;
3522
3523 for (j = 0; j < AHC_NUM_LUNS; j++) {
3509 struct tmode_lstate *lstate;
3524 struct ahc_tmode_lstate *lstate;
3510
3511 lstate = tstate->enabled_luns[j];
3512 if (lstate != NULL) {
3513 xpt_free_path(lstate->path);
3514 free(lstate, M_DEVBUF);
3515 }
3516 }
3517#endif

--- 644 unchanged lines hidden (view full) ---

4162 return (ENOMEM);
4163
4164 /*
4165 * Allocate a tstate to house information for our
4166 * initiator presence on the bus as well as the user
4167 * data for any target mode initiator.
4168 */
4169 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
3525
3526 lstate = tstate->enabled_luns[j];
3527 if (lstate != NULL) {
3528 xpt_free_path(lstate->path);
3529 free(lstate, M_DEVBUF);
3530 }
3531 }
3532#endif

--- 644 unchanged lines hidden (view full) ---

4177 return (ENOMEM);
4178
4179 /*
4180 * Allocate a tstate to house information for our
4181 * initiator presence on the bus as well as the user
4182 * data for any target mode initiator.
4183 */
4184 if (ahc_alloc_tstate(ahc, ahc->our_id, 'A') == NULL) {
4170 printf("%s: unable to allocate tmode_tstate. "
4185 printf("%s: unable to allocate ahc_tmode_tstate. "
4171 "Failing attach\n", ahc_name(ahc));
4186 "Failing attach\n", ahc_name(ahc));
4172 return (-1);
4187 return (ENOMEM);
4173 }
4174
4175 if ((ahc->features & AHC_TWIN) != 0) {
4176 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
4188 }
4189
4190 if ((ahc->features & AHC_TWIN) != 0) {
4191 if (ahc_alloc_tstate(ahc, ahc->our_id_b, 'B') == NULL) {
4177 printf("%s: unable to allocate tmode_tstate. "
4192 printf("%s: unable to allocate ahc_tmode_tstate. "
4178 "Failing attach\n", ahc_name(ahc));
4193 "Failing attach\n", ahc_name(ahc));
4179 return (-1);
4194 return (ENOMEM);
4180 }
4181 }
4182
4183 ahc_outb(ahc, SEQ_FLAGS, 0);
4184 ahc_outb(ahc, SEQ_FLAGS2, 0);
4185
4186 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX) {
4187 ahc->flags |= AHC_PAGESCBS;

--- 81 unchanged lines hidden (view full) ---

4269 if ((ahc->flags & AHC_ULTRA_DISABLED) != 0)
4270 ultraenb = 0;
4271
4272 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
4273 max_targ = 7;
4274
4275 for (i = 0; i <= max_targ; i++) {
4276 struct ahc_initiator_tinfo *tinfo;
4195 }
4196 }
4197
4198 ahc_outb(ahc, SEQ_FLAGS, 0);
4199 ahc_outb(ahc, SEQ_FLAGS2, 0);
4200
4201 if (ahc->scb_data->maxhscbs < AHC_SCB_MAX) {
4202 ahc->flags |= AHC_PAGESCBS;

--- 81 unchanged lines hidden (view full) ---

4284 if ((ahc->flags & AHC_ULTRA_DISABLED) != 0)
4285 ultraenb = 0;
4286
4287 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
4288 max_targ = 7;
4289
4290 for (i = 0; i <= max_targ; i++) {
4291 struct ahc_initiator_tinfo *tinfo;
4277 struct tmode_tstate *tstate;
4292 struct ahc_tmode_tstate *tstate;
4278 u_int our_id;
4279 u_int target_id;
4280 char channel;
4281
4282 channel = 'A';
4283 our_id = ahc->our_id;
4284 target_id = i;
4285 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {

--- 147 unchanged lines hidden (view full) ---

4433 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
4434 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
4435
4436 /* Tell the sequencer of our initial queue positions */
4437 ahc_outb(ahc, KERNEL_QINPOS, 0);
4438 ahc_outb(ahc, QINPOS, 0);
4439 ahc_outb(ahc, QOUTPOS, 0);
4440
4293 u_int our_id;
4294 u_int target_id;
4295 char channel;
4296
4297 channel = 'A';
4298 our_id = ahc->our_id;
4299 target_id = i;
4300 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {

--- 147 unchanged lines hidden (view full) ---

4448 ahc_outb(ahc, CMDSIZE_TABLE + 6, 0);
4449 ahc_outb(ahc, CMDSIZE_TABLE + 7, 0);
4450
4451 /* Tell the sequencer of our initial queue positions */
4452 ahc_outb(ahc, KERNEL_QINPOS, 0);
4453 ahc_outb(ahc, QINPOS, 0);
4454 ahc_outb(ahc, QOUTPOS, 0);
4455
4441 /* Don't have any special messages to send to targets */
4442 ahc_outb(ahc, TARGET_MSG_REQUEST, 0);
4443 ahc_outb(ahc, TARGET_MSG_REQUEST + 1, 0);
4444
4445 /*
4446 * Use the built in queue management registers
4447 * if they are available.
4448 */
4449 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
4450 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
4451 ahc_outb(ahc, SDSCB_QOFF, 0);
4452 ahc_outb(ahc, SNSCB_QOFF, 0);

--- 45 unchanged lines hidden (view full) ---

4498 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
4499 wait--)
4500 ahc_delay(100);
4501 ahc_unpause(ahc);
4502 }
4503 return (0);
4504}
4505
4456 /*
4457 * Use the built in queue management registers
4458 * if they are available.
4459 */
4460 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
4461 ahc_outb(ahc, QOFF_CTLSTA, SCB_QSIZE_256);
4462 ahc_outb(ahc, SDSCB_QOFF, 0);
4463 ahc_outb(ahc, SNSCB_QOFF, 0);

--- 45 unchanged lines hidden (view full) ---

4509 (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
4510 wait--)
4511 ahc_delay(100);
4512 ahc_unpause(ahc);
4513 }
4514 return (0);
4515}
4516
4517void
4518ahc_intr_enable(struct ahc_softc *ahc, int enable)
4519{
4520 u_int hcntrl;
4521
4522 hcntrl = ahc_inb(ahc, HCNTRL);
4523 hcntrl &= ~INTEN;
4524 ahc->pause &= ~INTEN;
4525 ahc->unpause &= ~INTEN;
4526 if (enable) {
4527 hcntrl |= INTEN;
4528 ahc->pause |= INTEN;
4529 ahc->unpause |= INTEN;
4530 }
4531 ahc_outb(ahc, HCNTRL, hcntrl);
4532}
4533
4506/*
4507 * Ensure that the card is paused in a location
4508 * outside of all critical sections and that all
4509 * pending work is completed prior to returning.
4510 * This routine should only be called from outside
4511 * an interrupt context.
4512 */
4513void

--- 1002 unchanged lines hidden (view full) ---

5516 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
5517
5518#ifdef AHC_TARGET_MODE
5519 /*
5520 * Send an immediate notify ccb to all target more peripheral
5521 * drivers affected by this action.
5522 */
5523 for (target = 0; target <= max_scsiid; target++) {
4534/*
4535 * Ensure that the card is paused in a location
4536 * outside of all critical sections and that all
4537 * pending work is completed prior to returning.
4538 * This routine should only be called from outside
4539 * an interrupt context.
4540 */
4541void

--- 1002 unchanged lines hidden (view full) ---

5544 max_scsiid = (ahc->features & AHC_WIDE) ? 15 : 7;
5545
5546#ifdef AHC_TARGET_MODE
5547 /*
5548 * Send an immediate notify ccb to all target more peripheral
5549 * drivers affected by this action.
5550 */
5551 for (target = 0; target <= max_scsiid; target++) {
5524 struct tmode_tstate* tstate;
5552 struct ahc_tmode_tstate* tstate;
5525 u_int lun;
5526
5527 tstate = ahc->enabled_targets[target];
5528 if (tstate == NULL)
5529 continue;
5530 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
5553 u_int lun;
5554
5555 tstate = ahc->enabled_targets[target];
5556 if (tstate == NULL)
5557 continue;
5558 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
5531 struct tmode_lstate* lstate;
5559 struct ahc_tmode_lstate* lstate;
5532
5533 lstate = tstate->enabled_luns[lun];
5534 if (lstate == NULL)
5535 continue;
5536
5537 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD,
5538 EVENT_TYPE_BUS_RESET, /*arg*/0);
5539 ahc_send_lstate_events(ahc, lstate);

--- 121 unchanged lines hidden (view full) ---

5661}
5662
5663/******************************* Target Mode **********************************/
5664#ifdef AHC_TARGET_MODE
5665/*
5666 * Add a target mode event to this lun's queue
5667 */
5668static void
5560
5561 lstate = tstate->enabled_luns[lun];
5562 if (lstate == NULL)
5563 continue;
5564
5565 ahc_queue_lstate_event(ahc, lstate, CAM_TARGET_WILDCARD,
5566 EVENT_TYPE_BUS_RESET, /*arg*/0);
5567 ahc_send_lstate_events(ahc, lstate);

--- 121 unchanged lines hidden (view full) ---

5689}
5690
5691/******************************* Target Mode **********************************/
5692#ifdef AHC_TARGET_MODE
5693/*
5694 * Add a target mode event to this lun's queue
5695 */
5696static void
5669ahc_queue_lstate_event(struct ahc_softc *ahc, struct tmode_lstate *lstate,
5697ahc_queue_lstate_event(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate,
5670 u_int initiator_id, u_int event_type, u_int event_arg)
5671{
5672 struct ahc_tmode_event *event;
5673 int pending;
5674
5675 xpt_freeze_devq(lstate->path, /*count*/1);
5676 if (lstate->event_w_idx >= lstate->event_r_idx)
5677 pending = lstate->event_w_idx - lstate->event_r_idx;

--- 34 unchanged lines hidden (view full) ---

5712 lstate->event_w_idx = 0;
5713}
5714
5715/*
5716 * Send any target mode events queued up waiting
5717 * for immediate notify resources.
5718 */
5719void
5698 u_int initiator_id, u_int event_type, u_int event_arg)
5699{
5700 struct ahc_tmode_event *event;
5701 int pending;
5702
5703 xpt_freeze_devq(lstate->path, /*count*/1);
5704 if (lstate->event_w_idx >= lstate->event_r_idx)
5705 pending = lstate->event_w_idx - lstate->event_r_idx;

--- 34 unchanged lines hidden (view full) ---

5740 lstate->event_w_idx = 0;
5741}
5742
5743/*
5744 * Send any target mode events queued up waiting
5745 * for immediate notify resources.
5746 */
5747void
5720ahc_send_lstate_events(struct ahc_softc *ahc, struct tmode_lstate *lstate)
5748ahc_send_lstate_events(struct ahc_softc *ahc, struct ahc_tmode_lstate *lstate)
5721{
5722 struct ccb_hdr *ccbh;
5723 struct ccb_immed_notify *inot;
5724
5725 while (lstate->event_r_idx != lstate->event_w_idx
5726 && (ccbh = SLIST_FIRST(&lstate->immed_notifies)) != NULL) {
5727 struct ahc_tmode_event *event;
5728

--- 309 unchanged lines hidden (view full) ---

6038void
6039ahc_dump_card_state(struct ahc_softc *ahc)
6040{
6041 struct scb *scb;
6042 struct scb_tailq *untagged_q;
6043 int target;
6044 int maxtarget;
6045 int i;
5749{
5750 struct ccb_hdr *ccbh;
5751 struct ccb_immed_notify *inot;
5752
5753 while (lstate->event_r_idx != lstate->event_w_idx
5754 && (ccbh = SLIST_FIRST(&lstate->immed_notifies)) != NULL) {
5755 struct ahc_tmode_event *event;
5756

--- 309 unchanged lines hidden (view full) ---

6066void
6067ahc_dump_card_state(struct ahc_softc *ahc)
6068{
6069 struct scb *scb;
6070 struct scb_tailq *untagged_q;
6071 int target;
6072 int maxtarget;
6073 int i;
6074 uint8_t last_phase;
6046 uint8_t qinpos;
6047 uint8_t qintail;
6048 uint8_t qoutpos;
6049 uint8_t scb_index;
6050 uint8_t saved_scbptr;
6051
6052 saved_scbptr = ahc_inb(ahc, SCBPTR);
6053
6075 uint8_t qinpos;
6076 uint8_t qintail;
6077 uint8_t qoutpos;
6078 uint8_t scb_index;
6079 uint8_t saved_scbptr;
6080
6081 saved_scbptr = ahc_inb(ahc, SCBPTR);
6082
6054 printf("%s: Dumping Card State at SEQADDR 0x%x\n",
6055 ahc_name(ahc),
6083 last_phase = ahc_inb(ahc, LASTPHASE);
6084 printf("%s: Dumping Card State %s, at SEQADDR 0x%x\n",
6085 ahc_name(ahc), ahc_lookup_phase_entry(last_phase)->phasemsg,
6056 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
6086 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
6057
6058 printf("SCSISEQ = 0x%x, SBLKCTL = 0x%x, SSTAT0 0x%x\n",
6059 ahc_inb(ahc, SCSISEQ), ahc_inb(ahc, SBLKCTL),
6060 ahc_inb(ahc, SSTAT0));
6087 printf("SCSISEQ = 0x%x, SBLKCTL = 0x%x\n",
6088 ahc_inb(ahc, SCSISEQ), ahc_inb(ahc, SBLKCTL));
6089 printf(" DFCNTRL = 0x%x, DFSTATUS = 0x%x\n",
6090 ahc_inb(ahc, DFCNTRL), ahc_inb(ahc, DFSTATUS));
6091 printf("LASTPHASE = 0x%x, SCSISIGI = 0x%x, SXFRCTL0 = 0x%x\n",
6092 last_phase, ahc_inb(ahc, SCSISIGI), ahc_inb(ahc, SXFRCTL0));
6093 printf("SSTAT0 = 0x%x, SSTAT1 = 0x%x\n",
6094 ahc_inb(ahc, SSTAT0), ahc_inb(ahc, SSTAT1));
6095 if ((ahc->features & AHC_DT) != 0)
6096 printf("SCSIPHASE = 0x%x\n", ahc_inb(ahc, SCSIPHASE));
6097 printf("STACK == 0x%x, 0x%x, 0x%x, 0x%x\n",
6098 ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
6099 ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
6100 ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8),
6101 ahc_inb(ahc, STACK) | (ahc_inb(ahc, STACK) << 8));
6061 printf("SCB count = %d\n", ahc->scb_data->numscbs);
6062 printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
6063 printf("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
6064 /* QINFIFO */
6065 printf("QINFIFO entries: ");
6066 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
6067 qinpos = ahc_inb(ahc, SNSCB_QOFF);
6068 ahc_outb(ahc, SNSCB_QOFF, qinpos);

--- 81 unchanged lines hidden (view full) ---

6150 ahc_platform_dump_card_state(ahc);
6151 ahc_outb(ahc, SCBPTR, saved_scbptr);
6152}
6153
6154/************************* Target Mode ****************************************/
6155#ifdef AHC_TARGET_MODE
6156cam_status
6157ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
6102 printf("SCB count = %d\n", ahc->scb_data->numscbs);
6103 printf("Kernel NEXTQSCB = %d\n", ahc->next_queued_scb->hscb->tag);
6104 printf("Card NEXTQSCB = %d\n", ahc_inb(ahc, NEXT_QUEUED_SCB));
6105 /* QINFIFO */
6106 printf("QINFIFO entries: ");
6107 if ((ahc->features & AHC_QUEUE_REGS) != 0) {
6108 qinpos = ahc_inb(ahc, SNSCB_QOFF);
6109 ahc_outb(ahc, SNSCB_QOFF, qinpos);

--- 81 unchanged lines hidden (view full) ---

6191 ahc_platform_dump_card_state(ahc);
6192 ahc_outb(ahc, SCBPTR, saved_scbptr);
6193}
6194
6195/************************* Target Mode ****************************************/
6196#ifdef AHC_TARGET_MODE
6197cam_status
6198ahc_find_tmode_devs(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb,
6158 struct tmode_tstate **tstate, struct tmode_lstate **lstate,
6199 struct ahc_tmode_tstate **tstate,
6200 struct ahc_tmode_lstate **lstate,
6159 int notfound_failure)
6160{
6161
6162 if ((ahc->features & AHC_TARGETMODE) == 0)
6163 return (CAM_REQ_INVALID);
6164
6165 /*
6166 * Handle the 'black hole' device that sucks up

--- 24 unchanged lines hidden (view full) ---

6191 return (CAM_PATH_INVALID);
6192
6193 return (CAM_REQ_CMP);
6194}
6195
6196void
6197ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
6198{
6201 int notfound_failure)
6202{
6203
6204 if ((ahc->features & AHC_TARGETMODE) == 0)
6205 return (CAM_REQ_INVALID);
6206
6207 /*
6208 * Handle the 'black hole' device that sucks up

--- 24 unchanged lines hidden (view full) ---

6233 return (CAM_PATH_INVALID);
6234
6235 return (CAM_REQ_CMP);
6236}
6237
6238void
6239ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
6240{
6199 struct tmode_tstate *tstate;
6200 struct tmode_lstate *lstate;
6241 struct ahc_tmode_tstate *tstate;
6242 struct ahc_tmode_lstate *lstate;
6201 struct ccb_en_lun *cel;
6202 cam_status status;
6203 u_int target;
6204 u_int lun;
6205 u_int target_mask;
6206 u_long s;
6207 char channel;
6208

--- 391 unchanged lines hidden (view full) ---

6600 }
6601 }
6602 }
6603}
6604
6605static int
6606ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
6607{
6243 struct ccb_en_lun *cel;
6244 cam_status status;
6245 u_int target;
6246 u_int lun;
6247 u_int target_mask;
6248 u_long s;
6249 char channel;
6250

--- 391 unchanged lines hidden (view full) ---

6642 }
6643 }
6644 }
6645}
6646
6647static int
6648ahc_handle_target_cmd(struct ahc_softc *ahc, struct target_cmd *cmd)
6649{
6608 struct tmode_tstate *tstate;
6609 struct tmode_lstate *lstate;
6650 struct ahc_tmode_tstate *tstate;
6651 struct ahc_tmode_lstate *lstate;
6610 struct ccb_accept_tio *atio;
6611 uint8_t *byte;
6612 int initiator;
6613 int target;
6614 int lun;
6615
6616 initiator = SCSIID_TARGET(ahc, cmd->scsiid);
6617 target = SCSIID_OUR_ID(cmd->scsiid);

--- 99 unchanged lines hidden ---
6652 struct ccb_accept_tio *atio;
6653 uint8_t *byte;
6654 int initiator;
6655 int target;
6656 int lun;
6657
6658 initiator = SCSIID_TARGET(ahc, cmd->scsiid);
6659 target = SCSIID_OUR_ID(cmd->scsiid);

--- 99 unchanged lines hidden ---