/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
static uint8_t asc_attached; /* can't have more than one asc */
static int
asc_vsbus_match(device_t parent, cfdata_t cf, void *aux)
{
struct vsbus_attach_args * const va = aux;
volatile uint8_t *ncr_regs;
int dummy;
if (asc_attached)
return 0;
if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
if (cf->cf_loc[VSBUSCF_CSR] != 0x200c0080)
return 0;
} else if (vax_boardtype == VAX_BTYP_49 ||
vax_boardtype == VAX_BTYP_53) {
if (cf->cf_loc[VSBUSCF_CSR] != 0x26000080)
return 0;
} else {
return 0;
}
ncr_regs = (volatile uint8_t *) va->va_addr;
/* *** need to generate an interrupt here
* From trial and error, I've determined that an INT is generated
* only when the following sequence of events occurs:
* 1) The interrupt status register (0x05) must be read.
* 2) SCSI bus reset interrupt must be enabled
* 3) SCSI bus reset command must be sent
* 4) NOP command must be sent
*/
dummy = ncr_regs[NCR_INTR << 2] & 0xFF;
ncr_regs[NCR_CFG1 << 2] = 0x06; /* we're ID 6, turn on INT for SCSI reset */
ncr_regs[NCR_CMD << 2] = NCRCMD_RSTSCSI; /* send the reset */
ncr_regs[NCR_CMD << 2] = NCRCMD_NOP; /* send a NOP */
DELAY(10000);
error = bus_space_map(asc->sc_bst, va->va_paddr - ASC_REG_NCR,
ASC_REG_END, 0, &asc->sc_bsh);
if (error) {
aprint_error(": failed to map registers: error=%d\n", error);
return;
}
error = bus_space_subregion(asc->sc_bst, asc->sc_bsh, ASC_REG_NCR,
ASC_REG_END - ASC_REG_NCR, &asc->sc_ncrh);
if (error) {
aprint_error(": failed to map ncr registers: error=%d\n",
error);
return;
}
if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
ASC_REG_KA46_ADR, sizeof(uint32_t), &asc->sc_adrh);
if (error) {
aprint_error(": failed to map adr register: error=%d\n",
error);
return;
}
error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
ASC_REG_KA46_DIR, sizeof(uint32_t), &asc->sc_dirh);
if (error) {
aprint_error(": failed to map dir register: error=%d\n",
error);
return;
}
} else {
/* This is a gross and disgusting kludge but it'll
* save a bunch of ugly code. Unlike the VS4000/60,
* the SCSI Address and direction registers are not
* near the SCSI NCR registers and are inside the
* block of general VAXstation registers. So we grab
* them from there and knowing the internals of the
* bus_space implementation, we cast to bus_space_handles.
*/
struct vsbus_softc *vsc = device_private(parent);
asc->sc_adrh =
(bus_space_handle_t)(vsc->sc_vsregs + ASC_REG_KA49_ADR);
asc->sc_dirh =
(bus_space_handle_t)(vsc->sc_vsregs + ASC_REG_KA49_DIR);
#if 0
printf("\n%s: adrh=0x%08lx dirh=0x%08lx", device_xname(self),
asc->sc_adrh, asc->sc_dirh);
ncr53c9x_debug = NCR_SHOWDMA | NCR_SHOWINTS | NCR_SHOWCMDS |
NCR_SHOWPHASE | NCR_SHOWSTART | NCR_SHOWMSGS;
#endif
}
error = bus_dmamap_create(asc->sc_dmat, ASC_MAXXFERSIZE, 1,
ASC_MAXXFERSIZE, 0, BUS_DMA_NOWAIT, &asc->sc_dmamap);
#if defined(VAX46) || defined(VAX48) || defined(VAX49) || defined(VAXANY)
if(vax_boardtype != VAX_BTYP_53)
/* SCSI ID is store in the clock NVRAM at magic address 0xbc */
sc->sc_id = (clk_page[0xbc / 2] >> clk_tweak) & 7;
else
#endif
sc->sc_id = 6; /* XXX need to get this from VMB */
sc->sc_freq = ASC_FREQUENCY;
/*
* XXX More of this should be in ncr53c9x_attach(), but
* XXX should we really poke around the chip that much in
* XXX the MI code? Think about this more...
*/
/*
* XXX minsync and maxxfer _should_ be set up in MI code,
* XXX but it appears to have some dependency on what sort
* XXX of DMA we're hooked up to, etc.
*/
/*
* This is the value used to start sync negotiations
* Note that the NCR register "SYNCTP" is programmed
* in "clocks per byte", and has a minimum value of 4.
* The SCSI period used in negotiation is one-fourth
* of the time (in nanoseconds) needed to transfer one byte.
* Since the chip's clock is given in MHz, we have the following
* formula: 4 * period = (1000 / freq) * 4
*/
sc->sc_minsync = (1000 / sc->sc_freq);
sc->sc_maxxfer = 64 * 1024;
/* Do the common parts of attachment. */
sc->sc_adapter.adapt_minphys = minphys;
sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
ncr53c9x_attach(sc);
}