1 /* $NetBSD: sfas.c,v 1.19 2009/03/18 17:06:41 cegger Exp $ */
4 * Copyright (c) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
8 * Van Jacobson of Lawrence Berkeley Laboratory.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)scsi.c 7.5 (Berkeley) 5/4/91
38 * Copyright (c) 1995 Scott Stevens
39 * Copyright (c) 1995 Daniel Widenfalk
40 * Copyright (c) 1994 Christian E. Hopps
42 * This code is derived from software contributed to Berkeley by
43 * Van Jacobson of Lawrence Berkeley Laboratory.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Berkeley and its contributors.
57 * 4. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * @(#)scsi.c 7.5 (Berkeley) 5/4/91
77 * Emulex FAS216 scsi adaptor driver
81 * Modified for NetBSD/arm32 by Scott Stevens
84 #include <sys/cdefs.h>
85 __KERNEL_RCSID(0, "$NetBSD: sfas.c,v 1.19 2009/03/18 17:06:41 cegger Exp $");
87 #include <sys/param.h>
88 #include <sys/systm.h>
89 #include <sys/device.h>
93 #include <dev/scsipi/scsi_all.h>
94 #include <dev/scsipi/scsipi_all.h>
95 #include <dev/scsipi/scsiconf.h>
97 #include <uvm/uvm_extern.h>
99 #include <machine/pmap.h>
100 #include <machine/cpu.h>
101 #include <machine/io.h>
102 #include <machine/intr.h>
103 #include <arm/arm32/katelib.h>
104 #include <acorn32/podulebus/podulebus.h>
105 #include <acorn32/podulebus/sfasreg.h>
106 #include <acorn32/podulebus/sfasvar.h>
108 void sfas_minphys(struct buf
*);
109 void sfas_init_nexus(struct sfas_softc
*, struct nexus
*);
110 void sfasinitialize(struct sfas_softc
*);
111 void sfas_scsi_request(struct scsipi_channel
*, scsipi_adapter_req_t
, void *);
112 void sfas_donextcmd(struct sfas_softc
*, struct sfas_pending
*);
113 void sfas_scsidone(struct sfas_softc
*, struct scsipi_xfer
*, int);
114 void sfasintr(struct sfas_softc
*);
115 void sfasiwait(struct sfas_softc
*);
116 void sfas_ixfer(void *, int);
117 void sfasreset(struct sfas_softc
*, int);
118 int sfasselect(struct sfas_softc
*, struct sfas_pending
*, unsigned char *,
119 int, unsigned char *, int, int);
120 void sfasicmd(struct sfas_softc
*, struct sfas_pending
*);
121 void sfasgo(struct sfas_softc
*, struct sfas_pending
*);
122 void sfas_save_pointers(struct sfas_softc
*);
123 void sfas_restore_pointers(struct sfas_softc
*);
124 void sfas_build_sdtrm(struct sfas_softc
*, int, int);
125 int sfas_select_unit(struct sfas_softc
*, short);
126 struct nexus
*sfas_arbitate_target(struct sfas_softc
*, int);
127 void sfas_setup_nexus(struct sfas_softc
*, struct nexus
*,
128 struct sfas_pending
*, unsigned char *, int,
129 unsigned char *, int, int);
130 int sfas_pretests(struct sfas_softc
*, sfas_regmap_p
);
131 int sfas_midaction(struct sfas_softc
*, sfas_regmap_p
, struct nexus
*);
132 int sfas_postaction(struct sfas_softc
*, sfas_regmap_p
, struct nexus
*);
135 * Initialize these to make 'em patchable. Defaults to enable sync and discon.
137 u_char sfas_inhibit_sync
[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
138 u_char sfas_inhibit_disc
[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
142 #define QPRINTF(a) if (sfas_debug > 1) printf a
149 * default minphys routine for sfas based controllers
152 sfas_minphys(struct buf
*bp
)
156 * No max transfer at this level.
162 * Initialize the nexus structs.
165 sfas_init_nexus(struct sfas_softc
*dev
, struct nexus
*nexus
)
167 memset(nexus
, 0, sizeof(struct nexus
));
169 nexus
->state
= SFAS_NS_IDLE
;
174 nexus
->config3
= dev
->sc_config3
& ~SFAS_CFG3_FASTSCSI
;
178 sfasinitialize(struct sfas_softc
*dev
)
183 dev
->sc_led_status
= 0;
185 TAILQ_INIT(&dev
->sc_xs_pending
);
186 TAILQ_INIT(&dev
->sc_xs_free
);
189 * Initialize the sfas_pending structs and link them into the free list. We
190 * have to set vm_link_data.pages to 0 or the vm FIX won't work.
192 for(i
=0; i
<MAXPENDING
; i
++) {
193 TAILQ_INSERT_TAIL(&dev
->sc_xs_free
, &dev
->sc_xs_store
[i
],
198 * Calculate the correct clock conversion factor 2 <= factor <= 8, i.e. set
199 * the factor to clock_freq / 5 (int).
201 if (dev
->sc_clock_freq
<= 10)
202 dev
->sc_clock_conv_fact
= 2;
203 if (dev
->sc_clock_freq
<= 40)
204 dev
->sc_clock_conv_fact
= 2+((dev
->sc_clock_freq
-10)/5);
206 panic("sfasinitialize: Clock frequence too high");
208 /* Setup and save the basic configuration registers */
209 dev
->sc_config1
= (dev
->sc_host_id
& SFAS_CFG1_BUS_ID_MASK
);
210 dev
->sc_config2
= SFAS_CFG2_FEATURES_ENABLE
;
211 dev
->sc_config3
= (dev
->sc_clock_freq
> 25 ? SFAS_CFG3_FASTCLK
: 0);
213 /* Precalculate timeout value and clock period. */
214 /* Ekkk ... floating point in the kernel !!!! */
215 /* dev->sc_timeout_val = 1+dev->sc_timeout*dev->sc_clock_freq/
216 (7.682*dev->sc_clock_conv_fact);*/
217 dev
->sc_timeout_val
= 1+dev
->sc_timeout
*dev
->sc_clock_freq
/
218 ((7682*dev
->sc_clock_conv_fact
)/1000);
219 dev
->sc_clock_period
= 1000/dev
->sc_clock_freq
;
221 sfasreset(dev
, 1 | 2); /* Reset Chip and Bus */
223 dev
->sc_units_disconnected
= 0;
224 dev
->sc_msg_in_len
= 0;
225 dev
->sc_msg_out_len
= 0;
230 sfas_init_nexus(dev
, &dev
->sc_nexus
[i
]);
232 if (dev
->sc_ixfer
== NULL
)
233 dev
->sc_ixfer
= sfas_ixfer
;
238 dev
->sc_bump_va
= (u_char
*)uvm_km_alloc(kernel_map
, dev
->sc_bump_sz
, 0,
239 UVM_KMF_WIRED
| UVM_KMF_ZERO
);
240 (void) pmap_extract(pmap_kernel(), (vaddr_t
)dev
->sc_bump_va
,
241 (paddr_t
*)&dev
->sc_bump_pa
);
244 * Setup pages to noncachable, that way we don't have to flush the cache
245 * every time we need "bumped" transfer.
247 pte
= vtopte((vaddr_t
) dev
->sc_bump_va
);
248 *pte
&= ~(L2_C
| L2_B
);
251 cpu_dcache_wbinv_range((vm_offset_t
)dev
->sc_bump_va
, PAGE_SIZE
);
253 printf(" dmabuf V0x%08x P0x%08x", (u_int
)dev
->sc_bump_va
, (u_int
)dev
->sc_bump_pa
);
258 * used by specific sfas controller
261 sfas_scsi_request(struct scsipi_channel
*chan
, scsipi_adapter_req_t req
,
264 struct scsipi_xfer
*xs
;
265 struct sfas_softc
*dev
= (void *)chan
->chan_adapter
->adapt_dev
;
266 struct scsipi_periph
*periph
;
267 struct sfas_pending
*pendp
;
268 int flags
, s
, target
;
271 case ADAPTER_REQ_RUN_XFER
:
273 periph
= xs
->xs_periph
;
274 flags
= xs
->xs_control
;
275 target
= periph
->periph_target
;
277 if (flags
& XS_CTL_DATA_UIO
)
278 panic("sfas: scsi data uio requested");
280 if ((flags
& XS_CTL_POLL
) && (dev
->sc_flags
& SFAS_ACTIVE
))
281 panic("sfas_scsicmd: busy");
283 /* Get hold of a sfas_pending block. */
285 pendp
= dev
->sc_xs_free
.tqh_first
;
287 xs
->error
= XS_RESOURCE_SHORTAGE
;
292 TAILQ_REMOVE(&dev
->sc_xs_free
, pendp
, link
);
297 /* If the chip if busy OR the unit is busy, we have to wait for out turn. */
298 if ((dev
->sc_flags
& SFAS_ACTIVE
) ||
299 (dev
->sc_nexus
[target
].flags
& SFAS_NF_UNIT_BUSY
)) {
301 TAILQ_INSERT_TAIL(&dev
->sc_xs_pending
, pendp
, link
);
304 sfas_donextcmd(dev
, pendp
);
308 case ADAPTER_REQ_GROW_RESOURCES
:
309 case ADAPTER_REQ_SET_XFER_MODE
:
310 /* XXX Not supported. */
316 * Actually select the unit, whereby the whole scsi-process is started.
319 sfas_donextcmd(struct sfas_softc
*dev
, struct sfas_pending
*pendp
)
324 * Special case for scsi unit reset. I think this is waterproof. We first
325 * select the unit during splbio. We then cycle through the generated
326 * interrupts until the interrupt routine signals that the unit has
327 * acknowledged the reset. After that we have to wait a reset to select
328 * delay before anything else can happend.
330 if (pendp
->xs
->xs_control
& XS_CTL_RESET
) {
334 while(!sfasselect(dev
, pendp
, 0, 0, 0, 0, SFAS_SELECT_K
)) {
340 nexus
= dev
->sc_cur_nexus
;
341 while(nexus
->flags
& SFAS_NF_UNIT_BUSY
) {
346 nexus
->flags
|= SFAS_NF_UNIT_BUSY
;
352 nexus
->flags
&= ~SFAS_NF_UNIT_BUSY
;
357 * If we are polling, go to splbio and perform the command, else we poke
358 * the scsi-bus via sfasgo to get the interrupt machine going.
360 if (pendp
->xs
->xs_control
& XS_CTL_POLL
) {
362 sfasicmd(dev
, pendp
);
363 TAILQ_INSERT_TAIL(&dev
->sc_xs_free
, pendp
, link
);
371 sfas_scsidone(struct sfas_softc
*dev
, struct scsipi_xfer
*xs
, int stat
)
373 struct sfas_pending
*pendp
;
387 xs
->error
= XS_DRIVER_STUFFUP
;
388 QPRINTF(("sfas_scsicmd() bad %x\n", stat
));
391 xs
->error
= XS_TIMEOUT
;
396 /* Steal the next command from the queue so that one unit can't hog the bus. */
398 pendp
= dev
->sc_xs_pending
.tqh_first
;
400 if (!(dev
->sc_nexus
[pendp
->xs
->xs_periph
->periph_target
].flags
&
403 pendp
= pendp
->link
.tqe_next
;
407 TAILQ_REMOVE(&dev
->sc_xs_pending
, pendp
, link
);
414 sfas_donextcmd(dev
, pendp
);
418 * There are two kinds of reset:
419 * 1) CHIP-bus reset. This also implies a SCSI-bus reset.
421 * After the appropriate resets have been performed we wait a reset to select
425 sfasreset(struct sfas_softc
*dev
, int how
)
434 sfas_init_nexus(dev
, &dev
->sc_nexus
[i
]);
436 *rp
->sfas_command
= SFAS_CMD_RESET_CHIP
;
438 *rp
->sfas_command
= SFAS_CMD_NOP
;
440 *rp
->sfas_config1
= dev
->sc_config1
;
441 *rp
->sfas_config2
= dev
->sc_config2
;
442 *rp
->sfas_config3
= dev
->sc_config3
;
443 *rp
->sfas_timeout
= dev
->sc_timeout_val
;
444 *rp
->sfas_clkconv
= dev
->sc_clock_conv_fact
&
445 SFAS_CLOCK_CONVERSION_MASK
;
450 sfas_init_nexus(dev
, &dev
->sc_nexus
[i
]);
454 *rp
->sfas_command
= SFAS_CMD_RESET_SCSI_BUS
;
457 /* Skip interrupt generated by RESET_SCSI_BUS */
458 while(*rp
->sfas_status
& SFAS_STAT_INTERRUPT_PENDING
) {
459 dev
->sc_status
= *rp
->sfas_status
;
460 dev
->sc_interrupt
= *rp
->sfas_interrupt
;
465 dev
->sc_status
= *rp
->sfas_status
;
466 dev
->sc_interrupt
= *rp
->sfas_interrupt
;
471 if (dev
->sc_config_flags
& SFAS_SLOW_START
)
472 delay(4*250000); /* RESET to SELECT DELAY*4 for slow devices */
474 delay(250000); /* RESET to SELECT DELAY */
478 * Save active data pointers to the nexus block currently active.
481 sfas_save_pointers(struct sfas_softc
*dev
)
485 nx
= dev
->sc_cur_nexus
;
487 nx
->cur_link
= dev
->sc_cur_link
;
488 nx
->max_link
= dev
->sc_max_link
;
489 nx
->buf
= dev
->sc_buf
;
490 nx
->len
= dev
->sc_len
;
491 nx
->dma_len
= dev
->sc_dma_len
;
492 nx
->dma_buf
= dev
->sc_dma_buf
;
493 nx
->dma_blk_flg
= dev
->sc_dma_blk_flg
;
494 nx
->dma_blk_len
= dev
->sc_dma_blk_len
;
495 nx
->dma_blk_ptr
= dev
->sc_dma_blk_ptr
;
500 * Restore data pointers from the currently active nexus block.
503 sfas_restore_pointers(struct sfas_softc
*dev
)
507 nx
= dev
->sc_cur_nexus
;
509 dev
->sc_cur_link
= nx
->cur_link
;
510 dev
->sc_max_link
= nx
->max_link
;
511 dev
->sc_buf
= nx
->buf
;
512 dev
->sc_len
= nx
->len
;
513 dev
->sc_dma_len
= nx
->dma_len
;
514 dev
->sc_dma_buf
= nx
->dma_buf
;
515 dev
->sc_dma_blk_flg
= nx
->dma_blk_flg
;
516 dev
->sc_dma_blk_len
= nx
->dma_blk_len
;
517 dev
->sc_dma_blk_ptr
= nx
->dma_blk_ptr
;
518 dev
->sc_chain
= nx
->dma
;
519 dev
->sc_unit
= (nx
->lun_unit
& 0x0F);
520 dev
->sc_lun
= (nx
->lun_unit
& 0xF0) >> 4;
525 * sfasiwait is used during interrupt and polled IO to wait for an event from
526 * the FAS chip. This function MUST NOT BE CALLED without interrupt disabled.
529 sfasiwait(struct sfas_softc
*dev
)
534 * If SFAS_DONT_WAIT is set, we have already grabbed the interrupt info
535 * elsewhere. So we don't have to wait for it.
537 if (dev
->sc_flags
& SFAS_DONT_WAIT
) {
538 dev
->sc_flags
&= ~SFAS_DONT_WAIT
;
544 /* Wait for FAS chip to signal an interrupt. */
545 while(!(*rp
->sfas_status
& SFAS_STAT_INTERRUPT_PENDING
))
548 /* Grab interrupt info from chip. */
549 dev
->sc_status
= *rp
->sfas_status
;
550 dev
->sc_interrupt
= *rp
->sfas_interrupt
;
551 if (dev
->sc_interrupt
& SFAS_INT_RESELECTED
) {
552 dev
->sc_resel
[0] = *rp
->sfas_fifo
;
553 dev
->sc_resel
[1] = *rp
->sfas_fifo
;
558 * Transfer info to/from device. sfas_ixfer uses polled IO+sfasiwait so the
559 * rules that apply to sfasiwait also applies here.
562 sfas_ixfer(void *v
, int polling
)
564 struct sfas_softc
*dev
= v
;
567 int len
, mode
, phase
;
574 * Decode the scsi phase to determine whether we are reading or writing.
575 * mode == 1 => READ, mode == 0 => WRITE
577 phase
= dev
->sc_status
& SFAS_STAT_PHASE_MASK
;
578 mode
= (phase
== SFAS_PHASE_DATA_IN
);
580 while(len
&& ((dev
->sc_status
& SFAS_STAT_PHASE_MASK
) == phase
))
582 *rp
->sfas_command
= SFAS_CMD_TRANSFER_INFO
;
586 *buf
++ = *rp
->sfas_fifo
;
590 *rp
->sfas_fifo
= *buf
++;
591 *rp
->sfas_command
= SFAS_CMD_TRANSFER_INFO
;
596 /* Update buffer pointers to reflect the sent/received data. */
601 * Since the last sfasiwait will be a phase-change, we can't wait for it
602 * again later, so we have to signal that.
603 * Since this may be called from an interrupt initiated routine then we
604 * must call sfasintr again to avoid losing an interrupt. Phew!
607 dev
->sc_flags
|= SFAS_DONT_WAIT
;
613 * Build a Synchronous Data Transfer Request message
616 sfas_build_sdtrm(struct sfas_softc
*dev
, int period
, int offset
)
618 dev
->sc_msg_out
[0] = 0x01;
619 dev
->sc_msg_out
[1] = 0x03;
620 dev
->sc_msg_out
[2] = 0x01;
621 dev
->sc_msg_out
[3] = period
/4;
622 dev
->sc_msg_out
[4] = offset
;
623 dev
->sc_msg_out_len
= 5;
627 * Arbitate the scsi bus and select the unit
630 sfas_select_unit(struct sfas_softc
*dev
, short target
)
637 s
= splbio(); /* Do this at splbio so that we won't be disturbed. */
641 nexus
= &dev
->sc_nexus
[target
];
644 * Check if the chip is busy. If not the we mark it as so and hope that nobody
645 * reselects us until we have grabbed the bus.
647 if (!(dev
->sc_flags
& SFAS_ACTIVE
) && !dev
->sc_sel_nexus
) {
648 dev
->sc_flags
|= SFAS_ACTIVE
;
652 *rp
->sfas_syncper
= nexus
->syncper
;
653 *rp
->sfas_syncoff
= nexus
->syncoff
;
654 *rp
->sfas_config3
= nexus
->config3
;
656 *rp
->sfas_config1
= dev
->sc_config1
;
657 *rp
->sfas_timeout
= dev
->sc_timeout_val
;
658 *rp
->sfas_dest_id
= target
;
660 /* If nobody has stolen the bus, we can send a select command to the chip. */
661 if (!(*rp
->sfas_status
& SFAS_STAT_INTERRUPT_PENDING
)) {
662 *rp
->sfas_fifo
= nexus
->ID
;
663 if ((nexus
->flags
& (SFAS_NF_DO_SDTR
| SFAS_NF_RESET
))
664 || (dev
->sc_msg_out_len
!= 0))
665 cmd
= SFAS_CMD_SEL_ATN_STOP
;
667 for(i
=0; i
<nexus
->clen
; i
++)
668 *rp
->sfas_fifo
= nexus
->cbuf
[i
];
670 cmd
= SFAS_CMD_SEL_ATN
;
673 dev
->sc_sel_nexus
= nexus
;
675 *rp
->sfas_command
= cmd
;
677 nexus
->flags
&= ~SFAS_NF_RETRY_SELECT
;
679 nexus
->flags
|= SFAS_NF_RETRY_SELECT
;
681 nexus
->flags
|= SFAS_NF_RETRY_SELECT
;
688 * Grab the nexus if available else return 0.
691 sfas_arbitate_target(struct sfas_softc
*dev
, int target
)
697 * This is realy simple. Raise interrupt level to splbio. Grab the nexus and
700 nexus
= &dev
->sc_nexus
[target
];
704 if (nexus
->flags
& SFAS_NF_UNIT_BUSY
)
707 nexus
->flags
|= SFAS_NF_UNIT_BUSY
;
714 * Setup a nexus for use. Initializes command, buffer pointers and DMA chain.
717 sfas_setup_nexus(struct sfas_softc
*dev
, struct nexus
*nexus
, struct sfas_pending
*pendp
, unsigned char *cbuf
, int clen
, unsigned char *buf
, int len
, int mode
)
719 char sync
, target
, lun
;
721 target
= pendp
->xs
->xs_periph
->periph_target
;
722 lun
= pendp
->xs
->xs_periph
->periph_lun
;
725 * Adopt mode to reflect the config flags.
726 * If we can't use DMA we can't use synch transfer. Also check the
727 * sfas_inhibit_xxx[target] flags.
729 if ((dev
->sc_config_flags
& (SFAS_NO_SYNCH
| SFAS_NO_DMA
)) ||
730 sfas_inhibit_sync
[(int)target
])
731 mode
&= ~SFAS_SELECT_S
;
733 if ((dev
->sc_config_flags
& SFAS_NO_RESELECT
) ||
734 sfas_inhibit_disc
[(int)target
])
735 mode
&= ~SFAS_SELECT_R
;
737 nexus
->xs
= pendp
->xs
;
739 /* Setup the nexus struct. */
740 nexus
->ID
= ((mode
& SFAS_SELECT_R
) ? 0xC0 : 0x80) | lun
;
742 memcpy(nexus
->cbuf
, cbuf
, nexus
->clen
);
743 nexus
->cbuf
[1] |= lun
<< 5; /* Fix the lun bits */
747 nexus
->dma_blk_len
= 0;
748 nexus
->dma_blk_ptr
= 0;
751 nexus
->lun_unit
= (lun
<< 4) | target
;
752 nexus
->state
= SFAS_NS_SELECTED
;
754 /* We must keep these flags. All else must be zero. */
755 nexus
->flags
&= SFAS_NF_UNIT_BUSY
756 | SFAS_NF_SYNC_TESTED
| SFAS_NF_SELECT_ME
;
758 if (mode
& SFAS_SELECT_I
)
759 nexus
->flags
|= SFAS_NF_IMMEDIATE
;
760 if (mode
& SFAS_SELECT_K
)
761 nexus
->flags
|= SFAS_NF_RESET
;
763 sync
= ((mode
& SFAS_SELECT_S
) ? 1 : 0);
765 /* We can't use sync during polled IO. */
766 if (sync
&& (mode
& SFAS_SELECT_I
))
770 ((nexus
->flags
& SFAS_NF_SYNC_TESTED
) && (nexus
->offset
!= 0))) {
772 * If the scsi unit is set to synch transfer and we don't want
773 * that, we have to renegotiate.
776 nexus
->flags
|= SFAS_NF_DO_SDTR
;
779 } else if (sync
&& !(nexus
->flags
& SFAS_NF_SYNC_TESTED
)) {
781 * If the scsi unit is not set to synch transfer and we want
782 * that, we have to negotiate. This should realy base the
783 * period on the clock frequence rather than just check if
787 nexus
->flags
|= SFAS_NF_DO_SDTR
;
788 nexus
->period
= ((dev
->sc_clock_freq
>25) ? 100 : 200);
791 /* If the user has a long cable, we want to limit the period */
792 if ((nexus
->period
== 100) &&
793 (dev
->sc_config_flags
& SFAS_SLOW_CABLE
))
798 * Fake a DMA-block for polled IO. This way we can use the same code to handle
799 * reselection. Much nicer this way.
801 if ((mode
& SFAS_SELECT_I
) || (dev
->sc_config_flags
& SFAS_NO_DMA
)) {
802 nexus
->dma
[0].ptr
= buf
;
803 nexus
->dma
[0].len
= len
;
804 nexus
->dma
[0].flg
= SFAS_CHAIN_PRG
;
807 nexus
->max_link
= dev
->sc_build_dma_chain(dev
, nexus
->dma
,
811 /* Flush the caches. */
813 if (len
&& !(mode
& SFAS_SELECT_I
))
814 cpu_dcache_wbinv_range((vm_offset_t
)buf
, len
);
818 sfasselect(struct sfas_softc
*dev
, struct sfas_pending
*pendp
, unsigned char *cbuf
, int clen
, unsigned char *buf
, int len
, int mode
)
822 /* Get the nexus struct. */
823 nexus
= sfas_arbitate_target(dev
, pendp
->xs
->xs_periph
->periph_target
);
827 /* Setup the nexus struct. */
828 sfas_setup_nexus(dev
, nexus
, pendp
, cbuf
, clen
, buf
, len
, mode
);
830 /* Post it to the interrupt machine. */
831 sfas_select_unit(dev
, pendp
->xs
->xs_periph
->periph_target
);
837 sfasgo(struct sfas_softc
*dev
, struct sfas_pending
*pendp
)
842 buf
= pendp
->xs
->data
;
844 if (sfasselect(dev
, pendp
, (char *)pendp
->xs
->cmd
, pendp
->xs
->cmdlen
,
845 buf
, pendp
->xs
->datalen
, SFAS_SELECT_RS
)) {
847 * We got the command going so the sfas_pending struct is now
852 TAILQ_INSERT_TAIL(&dev
->sc_xs_free
, pendp
, link
);
856 * We couldn't make the command fly so we have to wait. The
857 * struct MUST be inserted at the head to keep the order of
862 TAILQ_INSERT_HEAD(&dev
->sc_xs_pending
, pendp
, link
);
870 * Part one of the interrupt machine. Error checks and reselection test.
871 * We don't know if we have an active nexus here!
874 sfas_pretests(struct sfas_softc
*dev
, sfas_regmap_p rp
)
879 if (dev
->sc_interrupt
& SFAS_INT_SCSI_RESET_DETECTED
) {
881 * Cleanup and notify user. Lets hope that this is all we
886 if (dev
->sc_nexus
[i
].xs
)
887 sfas_scsidone(dev
, dev
->sc_nexus
[i
].xs
, -2);
889 sfas_init_nexus(dev
, &dev
->sc_nexus
[i
]);
891 printf("sfasintr: SCSI-RESET detected!");
895 if (dev
->sc_interrupt
& SFAS_INT_ILLEGAL_COMMAND
) {
896 /* Something went terrible wrong! Dump some data and panic! */
899 while(*rp
->sfas_fifo_flags
& SFAS_FIFO_COUNT_MASK
)
900 printf(" %x", *rp
->sfas_fifo
);
903 printf("CMD: %x\n", *rp
->sfas_command
);
904 panic("sfasintr: ILLEGAL COMMAND!");
907 if (dev
->sc_interrupt
& SFAS_INT_RESELECTED
) {
908 /* We were reselected. Set the chip as busy */
911 dev
->sc_flags
|= SFAS_ACTIVE
;
912 if (dev
->sc_sel_nexus
) {
913 dev
->sc_sel_nexus
->flags
|= SFAS_NF_SELECT_ME
;
914 dev
->sc_sel_nexus
= 0;
918 if (dev
->sc_units_disconnected
) {
919 /* Find out who reselected us. */
921 dev
->sc_resel
[0] &= ~(1<<dev
->sc_host_id
);
924 if (dev
->sc_resel
[0] & (1<<i
))
928 panic("Illegal reselection!");
930 if (dev
->sc_nexus
[i
].state
== SFAS_NS_DISCONNECTED
) {
932 * This unit had disconnected, so we reconnect
936 dev
->sc_cur_nexus
= &dev
->sc_nexus
[i
];
937 nexus
= dev
->sc_cur_nexus
;
939 *rp
->sfas_syncper
= nexus
->syncper
;
940 *rp
->sfas_syncoff
= nexus
->syncoff
;
941 *rp
->sfas_config3
= nexus
->config3
;
943 *rp
->sfas_dest_id
= i
& 7;
945 dev
->sc_units_disconnected
--;
946 dev
->sc_msg_in_len
= 0;
948 /* Restore active pointers. */
949 sfas_restore_pointers(dev
);
951 nexus
->state
= SFAS_NS_RESELECTED
;
953 *rp
->sfas_command
= SFAS_CMD_MESSAGE_ACCEPTED
;
959 /* Somehow we got an illegal reselection. Dump and panic. */
960 printf("sfasintr: resel[0] %x resel[1] %x disconnected %d\n",
961 dev
->sc_resel
[0], dev
->sc_resel
[1],
962 dev
->sc_units_disconnected
);
963 panic("sfasintr: Unexpected reselection!");
970 * Part two of the interrupt machine. Handle disconnection and post command
971 * processing. We know that we have an active nexus here.
974 sfas_midaction(struct sfas_softc
*dev
, sfas_regmap_p rp
, struct nexus
*nexus
)
979 if (dev
->sc_interrupt
& SFAS_INT_DISCONNECT
) {
981 dev
->sc_cur_nexus
= 0;
983 /* Mark chip as busy and clean up the chip FIFO. */
984 dev
->sc_flags
&= ~SFAS_ACTIVE
;
985 *rp
->sfas_command
= SFAS_CMD_FLUSH_FIFO
;
987 /* Let the nexus state reflect what we have to do. */
988 switch(nexus
->state
) {
989 case SFAS_NS_SELECTED
:
990 dev
->sc_sel_nexus
= 0;
991 nexus
->flags
&= ~SFAS_NF_SELECT_ME
;
994 * We were trying to select the unit. Probably no unit
997 nexus
->xs
->resid
= dev
->sc_len
;
1000 nexus
->flags
&= ~SFAS_NF_UNIT_BUSY
;
1001 nexus
->state
= SFAS_NS_FINISHED
;
1006 nexus
->xs
->resid
= dev
->sc_len
;
1008 nexus
->flags
&= ~SFAS_NF_UNIT_BUSY
;
1009 nexus
->state
= SFAS_NS_FINISHED
;
1010 dev
->sc_led(dev
, 0);
1013 case SFAS_NS_DISCONNECTING
:
1015 * We have received a DISCONNECT message, so we are
1016 * doing a normal disconnection.
1018 nexus
->state
= SFAS_NS_DISCONNECTED
;
1020 dev
->sc_units_disconnected
++;
1025 * We were reseting this SCSI-unit. Clean up the
1028 dev
->sc_led(dev
, 0);
1029 sfas_init_nexus(dev
, nexus
);
1034 * Unexpected disconnection! Cleanup and exit. This
1035 * shouldn't cause any problems.
1037 printf("sfasintr: Unexpected disconnection\n");
1038 printf("sfasintr: u %x s %d p %d f %x c %x\n",
1039 nexus
->lun_unit
, nexus
->state
,
1040 dev
->sc_status
& SFAS_STAT_PHASE_MASK
,
1041 nexus
->flags
, nexus
->cbuf
[0]);
1043 nexus
->xs
->resid
= dev
->sc_len
;
1045 nexus
->flags
&= ~SFAS_NF_UNIT_BUSY
;
1046 nexus
->state
= SFAS_NS_FINISHED
;
1049 dev
->sc_led(dev
, 0);
1054 * If we have disconnected units, we MUST enable reselection
1057 if (dev
->sc_units_disconnected
&&
1058 !(dev
->sc_flags
& SFAS_ACTIVE
))
1059 *rp
->sfas_command
= SFAS_CMD_ENABLE_RESEL
;
1063 /* Select the first pre-initialized nexus we find. */
1065 if (dev
->sc_nexus
[i
].flags
& (SFAS_NF_SELECT_ME
| SFAS_NF_RETRY_SELECT
))
1066 if (sfas_select_unit(dev
, i
) == 2)
1069 /* We are done with this nexus! */
1070 if (nexus
->state
== SFAS_NS_FINISHED
)
1071 sfas_scsidone(dev
, nexus
->xs
, nexus
->status
);
1076 switch(nexus
->state
) {
1077 case SFAS_NS_SELECTED
:
1078 dev
->sc_cur_nexus
= nexus
;
1079 dev
->sc_sel_nexus
= 0;
1081 nexus
->flags
&= ~SFAS_NF_SELECT_ME
;
1084 * We have selected a unit. Setup chip, restore pointers and
1087 *rp
->sfas_syncper
= nexus
->syncper
;
1088 *rp
->sfas_syncoff
= nexus
->syncoff
;
1089 *rp
->sfas_config3
= nexus
->config3
;
1091 sfas_restore_pointers(dev
);
1093 nexus
->status
= 0xFF;
1094 dev
->sc_msg_in
[0] = 0xFF;
1095 dev
->sc_msg_in_len
= 0;
1097 dev
->sc_led(dev
, 1);
1101 case SFAS_NS_DATA_IN
:
1102 case SFAS_NS_DATA_OUT
:
1103 /* We have transfered data. */
1104 if (dev
->sc_dma_len
)
1105 if (dev
->sc_cur_link
< dev
->sc_max_link
) {
1107 * Clean up DMA and at the same time get how
1108 * many bytes that were NOT transfered.
1110 left
= dev
->sc_setup_dma(dev
, 0, 0, SFAS_DMA_CLEAR
);
1111 len
= dev
->sc_dma_len
;
1113 if (nexus
->state
== SFAS_NS_DATA_IN
) {
1115 * If we were bumping we may have had an odd length
1116 * which means that there may be bytes left in the
1117 * fifo. We also need to move the data from the
1118 * bump buffer to the actual memory.
1120 if (dev
->sc_dma_buf
== dev
->sc_bump_pa
)
1122 while((*rp
->sfas_fifo_flags
&SFAS_FIFO_COUNT_MASK
)
1124 dev
->sc_bump_va
[len
-(left
--)] = *rp
->sfas_fifo
;
1126 memcpy(dev
->sc_buf
, dev
->sc_bump_va
, len
-left
);
1129 /* Count any unsent bytes and flush them. */
1130 left
+= *rp
->sfas_fifo_flags
& SFAS_FIFO_COUNT_MASK
;
1131 *rp
->sfas_command
= SFAS_CMD_FLUSH_FIFO
;
1135 * Update pointers/length to reflect the transfered
1138 dev
->sc_len
-= len
-left
;
1139 dev
->sc_buf
+= len
-left
;
1141 dev
->sc_dma_buf
= (char *)dev
->sc_dma_buf
+ len
-left
;
1142 dev
->sc_dma_len
= left
;
1144 dev
->sc_dma_blk_ptr
= (char *)dev
->sc_dma_blk_ptr
+
1146 dev
->sc_dma_blk_len
-= len
-left
;
1149 * If it was the end of a DMA block, we select the
1150 * next to begin with.
1152 if (!dev
->sc_dma_blk_len
)
1157 case SFAS_NS_STATUS
:
1159 * If we were not sensing, grab the status byte. If we were
1160 * sensing and we got a bad status, let the user know.
1163 status
= *rp
->sfas_fifo
;
1164 msg
= *rp
->sfas_fifo
;
1166 nexus
->status
= status
;
1171 * Preload the command complete message. Handeled in
1174 dev
->sc_msg_in
[0] = msg
;
1175 dev
->sc_msg_in_len
= 1;
1176 nexus
->flags
|= SFAS_NF_HAS_MSG
;
1187 * Part three of the interrupt machine. Handle phase changes (and repeated
1188 * phase passes). We know that we have an active nexus here.
1191 sfas_postaction(struct sfas_softc
*dev
, sfas_regmap_p rp
, struct nexus
*nexus
)
1195 short offset
, period
;
1199 switch(dev
->sc_status
& SFAS_STAT_PHASE_MASK
) {
1200 case SFAS_PHASE_DATA_OUT
:
1201 case SFAS_PHASE_DATA_IN
:
1202 if ((dev
->sc_status
& SFAS_STAT_PHASE_MASK
) ==
1203 SFAS_PHASE_DATA_OUT
)
1204 nexus
->state
= SFAS_NS_DATA_OUT
;
1206 nexus
->state
= SFAS_NS_DATA_IN
;
1208 /* Make DMA ready to accept new data. Load active pointers
1209 * from the DMA block. */
1210 dev
->sc_setup_dma(dev
, 0, 0, SFAS_DMA_CLEAR
);
1211 if (dev
->sc_cur_link
< dev
->sc_max_link
) {
1212 if (!dev
->sc_dma_blk_len
) {
1213 dev
->sc_dma_blk_ptr
= dev
->sc_chain
[dev
->sc_cur_link
].ptr
;
1214 dev
->sc_dma_blk_len
= dev
->sc_chain
[dev
->sc_cur_link
].len
;
1215 dev
->sc_dma_blk_flg
= dev
->sc_chain
[dev
->sc_cur_link
].flg
;
1218 /* We should use polled IO here. */
1219 if (dev
->sc_dma_blk_flg
== SFAS_CHAIN_PRG
) {
1220 dev
->sc_ixfer(dev
, nexus
->xs
->xs_control
& XS_CTL_POLL
);
1222 dev
->sc_dma_len
= 0;
1225 else if (dev
->sc_dma_blk_flg
== SFAS_CHAIN_BUMP
)
1226 len
= dev
->sc_dma_blk_len
;
1228 len
= dev
->sc_need_bump(dev
, dev
->sc_dma_blk_ptr
,
1229 dev
->sc_dma_blk_len
);
1232 * If len != 0 we must bump the data, else we just DMA it
1233 * straight into memory.
1236 dev
->sc_dma_buf
= dev
->sc_bump_pa
;
1237 dev
->sc_dma_len
= len
;
1239 if (nexus
->state
== SFAS_NS_DATA_OUT
)
1240 memcpy(dev
->sc_bump_va
, dev
->sc_buf
, dev
->sc_dma_len
);
1242 dev
->sc_dma_buf
= dev
->sc_dma_blk_ptr
;
1243 dev
->sc_dma_len
= dev
->sc_dma_blk_len
;
1246 /* Load DMA with address and length of transfer. */
1247 dev
->sc_setup_dma(dev
, dev
->sc_dma_buf
, dev
->sc_dma_len
,
1248 ((nexus
->state
== SFAS_NS_DATA_OUT
) ?
1249 SFAS_DMA_WRITE
: SFAS_DMA_READ
));
1251 /* printf("Using DMA !!!!\n");*/
1252 cmd
= SFAS_CMD_TRANSFER_INFO
| SFAS_CMD_DMA
;
1255 * Hmmm, the unit wants more info than we have or has
1256 * more than we want. Let the chip handle that.
1259 *rp
->sfas_tc_low
= 0; /* was 256 but this does not make sense */
1260 *rp
->sfas_tc_mid
= 1;
1261 *rp
->sfas_tc_high
= 0;
1262 cmd
= SFAS_CMD_TRANSFER_PAD
;
1266 case SFAS_PHASE_COMMAND
:
1267 /* The scsi unit wants the command, send it. */
1268 nexus
->state
= SFAS_NS_SVC
;
1270 *rp
->sfas_command
= SFAS_CMD_FLUSH_FIFO
;
1273 for(i
=0; i
<nexus
->clen
; i
++)
1274 *rp
->sfas_fifo
= nexus
->cbuf
[i
];
1275 cmd
= SFAS_CMD_TRANSFER_INFO
;
1278 case SFAS_PHASE_STATUS
:
1280 * We've got status phase. Request status and command
1283 nexus
->state
= SFAS_NS_STATUS
;
1284 cmd
= SFAS_CMD_COMMAND_COMPLETE
;
1287 case SFAS_PHASE_MESSAGE_OUT
:
1289 * Either the scsi unit wants us to send a message or we have
1290 * asked for it by seting the ATN bit.
1292 nexus
->state
= SFAS_NS_MSG_OUT
;
1294 *rp
->sfas_command
= SFAS_CMD_FLUSH_FIFO
;
1296 if (nexus
->flags
& SFAS_NF_DO_SDTR
) {
1297 /* Send a Synchronous Data Transfer Request. */
1299 sfas_build_sdtrm(dev
, nexus
->period
, nexus
->offset
);
1300 nexus
->flags
|= SFAS_NF_SDTR_SENT
;
1301 nexus
->flags
&= ~SFAS_NF_DO_SDTR
;
1302 } else if (nexus
->flags
& SFAS_NF_RESET
) {
1303 /* Send a reset scsi unit message. */
1305 dev
->sc_msg_out
[0] = 0x0C;
1306 dev
->sc_msg_out_len
= 1;
1307 nexus
->state
= SFAS_NS_RESET
;
1308 nexus
->flags
&= ~SFAS_NF_RESET
;
1309 } else if (dev
->sc_msg_out_len
== 0) {
1310 /* Don't know what to send so we send a NOP message. */
1312 dev
->sc_msg_out
[0] = 0x08;
1313 dev
->sc_msg_out_len
= 1;
1316 cmd
= SFAS_CMD_TRANSFER_INFO
;
1318 for(i
=0; i
<dev
->sc_msg_out_len
; i
++)
1319 *rp
->sfas_fifo
= dev
->sc_msg_out
[i
];
1320 dev
->sc_msg_out_len
= 0;
1324 case SFAS_PHASE_MESSAGE_IN
:
1325 /* Receive a message from the scsi unit. */
1326 nexus
->state
= SFAS_NS_MSG_IN
;
1328 while(!(nexus
->flags
& SFAS_NF_HAS_MSG
)) {
1329 *rp
->sfas_command
= SFAS_CMD_TRANSFER_INFO
;
1332 dev
->sc_msg_in
[dev
->sc_msg_in_len
++] = *rp
->sfas_fifo
;
1334 /* Check if we got all the bytes in the message. */
1335 if (dev
->sc_msg_in
[0] >= 0x80) ;
1336 else if (dev
->sc_msg_in
[0] >= 0x30) ;
1337 else if (((dev
->sc_msg_in
[0] >= 0x20) &&
1338 (dev
->sc_msg_in_len
== 2)) ||
1339 ((dev
->sc_msg_in
[0] != 0x01) &&
1340 (dev
->sc_msg_in_len
== 1))) {
1341 nexus
->flags
|= SFAS_NF_HAS_MSG
;
1344 if (dev
->sc_msg_in_len
>= 2)
1345 if ((dev
->sc_msg_in
[1]+2) == dev
->sc_msg_in_len
) {
1346 nexus
->flags
|= SFAS_NF_HAS_MSG
;
1351 *rp
->sfas_command
= SFAS_CMD_MESSAGE_ACCEPTED
;
1354 if ((dev
->sc_status
& SFAS_STAT_PHASE_MASK
) !=
1355 SFAS_PHASE_MESSAGE_IN
)
1359 cmd
= SFAS_CMD_MESSAGE_ACCEPTED
;
1360 if (nexus
->flags
& SFAS_NF_HAS_MSG
) {
1361 /* We have a message. Decode it. */
1363 switch(dev
->sc_msg_in
[0]) {
1364 case 0x00: /* COMMAND COMPLETE */
1365 nexus
->state
= SFAS_NS_DONE
;
1367 case 0x04: /* DISCONNECT */
1368 nexus
->state
= SFAS_NS_DISCONNECTING
;
1370 case 0x02: /* SAVE DATA POINTER */
1371 sfas_save_pointers(dev
);
1373 case 0x03: /* RESTORE DATA POINTERS */
1374 sfas_restore_pointers(dev
);
1376 case 0x07: /* MESSAGE REJECT */
1378 * If we had sent a SDTR and we got a message
1379 * reject, the scsi docs say that we must go
1380 * to async transfer.
1382 if (nexus
->flags
& SFAS_NF_SDTR_SENT
) {
1383 nexus
->flags
&= ~SFAS_NF_SDTR_SENT
;
1385 nexus
->config3
&= ~SFAS_CFG3_FASTSCSI
;
1389 *rp
->sfas_syncper
= nexus
->syncper
;
1390 *rp
->sfas_syncoff
= nexus
->syncoff
;
1391 *rp
->sfas_config3
= nexus
->config3
;
1394 * Something was rejected but we don't know
1397 panic("sfasintr: Unknown message rejected!");
1399 case 0x08: /* MO OPERATION */
1401 case 0x01: /* EXTENDED MESSAGE */
1402 switch(dev
->sc_msg_in
[2]) {
1403 case 0x01:/* SYNC. DATA TRANSFER REQUEST */
1404 /* Decode the SDTR message. */
1405 period
= 4*dev
->sc_msg_in
[3];
1406 offset
= dev
->sc_msg_in
[4];
1409 * Make sure that the specs are within
1410 * chip limits. Note that if we
1411 * initiated the negotiation the specs
1412 * WILL be withing chip limits. If it
1413 * was the scsi unit that initiated
1414 * the negotiation, the specs may be
1419 if ((period
< 200) &&
1420 (dev
->sc_clock_freq
<= 25))
1424 period
= 5*dev
->sc_clock_period
;
1426 nexus
->syncper
= period
/
1427 dev
->sc_clock_period
;
1428 nexus
->syncoff
= offset
;
1431 nexus
->config3
|= SFAS_CFG3_FASTSCSI
;
1433 nexus
->config3
&=~SFAS_CFG3_FASTSCSI
;
1435 nexus
->flags
|= SFAS_NF_SYNC_TESTED
;
1437 *rp
->sfas_syncper
= nexus
->syncper
;
1438 *rp
->sfas_syncoff
= nexus
->syncoff
;
1439 *rp
->sfas_config3
= nexus
->config3
;
1442 * Hmmm, it seems that the scsi unit
1443 * initiated sync negotiation, so lets
1444 * reply acording to scsi-2 standard.
1446 if (!(nexus
->flags
& SFAS_NF_SDTR_SENT
))
1448 if ((dev
->sc_config_flags
&
1450 (dev
->sc_config_flags
&
1453 nexus
->lun_unit
& 7]) {
1458 nexus
->offset
= offset
;
1459 nexus
->period
= period
;
1460 nexus
->flags
|= SFAS_NF_DO_SDTR
;
1461 *rp
->sfas_command
= SFAS_CMD_SET_ATN
;
1464 nexus
->flags
&= ~SFAS_NF_SDTR_SENT
;
1467 case 0x00: /* MODIFY DATA POINTERS */
1468 case 0x02: /* EXTENDED IDENTIFY (SCSI-1) */
1469 case 0x03: /* WIDE DATA TRANSFER REQUEST */
1471 /* Reject any unhandeled messages. */
1473 dev
->sc_msg_out
[0] = 0x07;
1474 dev
->sc_msg_out_len
= 1;
1475 *rp
->sfas_command
= SFAS_CMD_SET_ATN
;
1476 cmd
= SFAS_CMD_MESSAGE_ACCEPTED
;
1482 /* Reject any unhandeled messages. */
1484 dev
->sc_msg_out
[0] = 0x07;
1485 dev
->sc_msg_out_len
= 1;
1486 *rp
->sfas_command
= SFAS_CMD_SET_ATN
;
1487 cmd
= SFAS_CMD_MESSAGE_ACCEPTED
;
1490 nexus
->flags
&= ~SFAS_NF_HAS_MSG
;
1491 dev
->sc_msg_in_len
= 0;
1495 printf("SFASINTR: UNKNOWN PHASE! phase: %d\n",
1496 dev
->sc_status
& SFAS_STAT_PHASE_MASK
);
1497 dev
->sc_led(dev
, 0);
1498 sfas_scsidone(dev
, nexus
->xs
, -4);
1504 *rp
->sfas_command
= cmd
;
1510 * Stub for interrupt machine.
1513 sfasintr(struct sfas_softc
*dev
)
1516 struct nexus
*nexus
;
1520 if (!sfas_pretests(dev
, rp
)) {
1522 nexus
= dev
->sc_cur_nexus
;
1524 nexus
= dev
->sc_sel_nexus
;
1527 if (!sfas_midaction(dev
, rp
, nexus
))
1528 sfas_postaction(dev
, rp
, nexus
);
1533 * sfasicmd is used to perform IO when we can't use interrupts. sfasicmd
1534 * emulates the normal environment by waiting for the chip and calling
1538 sfasicmd(struct sfas_softc
*dev
, struct sfas_pending
*pendp
)
1541 struct nexus
*nexus
;
1543 nexus
= &dev
->sc_nexus
[pendp
->xs
->xs_periph
->periph_target
];
1546 if (!sfasselect(dev
, pendp
, (char *)pendp
->xs
->cmd
, pendp
->xs
->cmdlen
,
1547 (char *)pendp
->xs
->data
, pendp
->xs
->datalen
,
1549 panic("sfasicmd: Couldn't select unit");
1551 while(nexus
->state
!= SFAS_NS_FINISHED
) {
1556 nexus
->flags
&= ~SFAS_NF_SYNC_TESTED
;
1563 dump_nexus(struct nexus
*nexus
)
1567 printf("nexus=%08x\n", (u_int
)nexus
);
1568 printf("scsi_fer=%08x\n", (u_int
)nexus
->xs
);
1569 printf("ID=%02x\n", nexus
->ID
);
1570 printf("clen=%02x\n", nexus
->clen
);
1572 for (loop
= 0; loop
< 14; ++loop
)
1573 printf(" %02x\n", nexus
->cbuf
[loop
]);
1576 for (loop
= 0; loop
< MAXCHAIN
; ++loop
)
1577 printf("dma_chain: %08x %04x %04x\n", nexus
->dma
[loop
].ptr
,
1578 nexus
->dma
[loop
].len
, nexus
->dma
[loop
].flg
);
1581 printf("max_link=%d\n", nexus
->max_link
);
1582 printf("cur_link=%d\n", nexus
->cur_link
);
1584 printf("buf=%08x\n", (u_int
)nexus
->buf
);
1585 printf("len=%08x\n", nexus
->len
);
1586 printf("dma_buf=%08x\n", (u_int
)nexus
->dma_buf
);
1587 printf("dma_len=%08x\n", nexus
->dma_len
);
1588 printf("dma_blk_ptr=%08x\n", (u_int
)nexus
->dma_blk_ptr
);
1589 printf("dma_blk_len=%08x\n", nexus
->dma_blk_len
);
1590 printf("dma_blk_flag=%08x\n", nexus
->dma_blk_flg
);
1591 printf("state=%02x\n", nexus
->state
);
1592 printf("flags=%04x\n", nexus
->flags
);
1593 printf("period=%d\n", nexus
->period
);
1594 printf("offset=%d\n", nexus
->offset
);
1595 printf("syncper=%d\n", nexus
->syncper
);
1596 printf("syncoff=%d\n", nexus
->syncoff
);
1597 printf("config3=%02x\n", nexus
->config3
);
1598 printf("lun_unit=%d\n", nexus
->lun_unit
);
1599 printf("status=%02x\n", nexus
->status
);
1604 dump_nexii(struct sfas_softc
*sc
)
1608 for (loop
= 0; loop
< 8; ++loop
) {
1609 dump_nexus(&sc
->sc_nexus
[loop
]);
1614 dump_sfassoftc(struct sfas_softc
*sc
)
1616 printf("sfassoftc @ 0x%08x\n", (u_int
)sc
);
1617 printf("clock_freq = %d\n", sc
->sc_clock_freq
);
1618 printf("timeout = %d\n", sc
->sc_timeout
);
1619 printf("host_id = %d\n", sc
->sc_host_id
);
1620 printf("config_flags = 0x%08x\n", sc
->sc_config_flags
);
1621 printf("led_status = %d\n", sc
->sc_led_status
);
1624 printf("cur_nexus = 0x%08x\n", (u_int
)sc
->sc_cur_nexus
);
1625 printf("sel_nexus = 0x%08x\n", (u_int
)sc
->sc_sel_nexus
);
1629 #endif /* SFAS_DEBUG */