1*40f7eaafSjdolecek /* $NetBSD: cbiisc.c,v 1.34 2019/01/08 19:41:09 jdolecek Exp $ */
266e9e901Smhitch
366e9e901Smhitch /*
466e9e901Smhitch * Copyright (c) 1997 Michael L. Hitch
566e9e901Smhitch * Copyright (c) 1982, 1990 The Regents of the University of California.
666e9e901Smhitch * All rights reserved.
766e9e901Smhitch *
866e9e901Smhitch * Redistribution and use in source and binary forms, with or without
966e9e901Smhitch * modification, are permitted provided that the following conditions
1066e9e901Smhitch * are met:
1166e9e901Smhitch * 1. Redistributions of source code must retain the above copyright
1266e9e901Smhitch * notice, this list of conditions and the following disclaimer.
1366e9e901Smhitch * 2. Redistributions in binary form must reproduce the above copyright
1466e9e901Smhitch * notice, this list of conditions and the following disclaimer in the
1566e9e901Smhitch * documentation and/or other materials provided with the distribution.
1678f74058Ssnj * 3. Neither the name of the University nor the names of its contributors
1766e9e901Smhitch * may be used to endorse or promote products derived from this software
1866e9e901Smhitch * without specific prior written permission.
1966e9e901Smhitch *
2066e9e901Smhitch * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2166e9e901Smhitch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2266e9e901Smhitch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2366e9e901Smhitch * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2466e9e901Smhitch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2566e9e901Smhitch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2666e9e901Smhitch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2766e9e901Smhitch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2866e9e901Smhitch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2966e9e901Smhitch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3066e9e901Smhitch * SUCH DAMAGE.
3166e9e901Smhitch *
3266e9e901Smhitch */
3366e9e901Smhitch
3423b820a8Sphx #ifdef __m68k__
35bd01b4a3Smrg #include "opt_m68k_arch.h"
3623b820a8Sphx #endif
37bd01b4a3Smrg
381ea4df81Saymeric #include <sys/cdefs.h>
39*40f7eaafSjdolecek __KERNEL_RCSID(0, "$NetBSD: cbiisc.c,v 1.34 2019/01/08 19:41:09 jdolecek Exp $");
401ea4df81Saymeric
4166e9e901Smhitch #include <sys/types.h>
4266e9e901Smhitch #include <sys/param.h>
4366e9e901Smhitch #include <sys/systm.h>
4466e9e901Smhitch #include <sys/kernel.h>
4566e9e901Smhitch #include <sys/errno.h>
4666e9e901Smhitch #include <sys/ioctl.h>
4766e9e901Smhitch #include <sys/device.h>
4866e9e901Smhitch #include <sys/buf.h>
4966e9e901Smhitch #include <sys/proc.h>
5066e9e901Smhitch #include <sys/queue.h>
5166e9e901Smhitch
5266e9e901Smhitch #include <dev/scsipi/scsi_all.h>
5366e9e901Smhitch #include <dev/scsipi/scsipi_all.h>
5466e9e901Smhitch #include <dev/scsipi/scsiconf.h>
5566e9e901Smhitch #include <dev/scsipi/scsi_message.h>
5666e9e901Smhitch
5766e9e901Smhitch #include <machine/cpu.h>
5866e9e901Smhitch
5966e9e901Smhitch #include <dev/ic/ncr53c9xreg.h>
6066e9e901Smhitch #include <dev/ic/ncr53c9xvar.h>
6166e9e901Smhitch
6266e9e901Smhitch #include <amiga/amiga/isr.h>
6366e9e901Smhitch #include <amiga/dev/cbiiscvar.h>
6466e9e901Smhitch #include <amiga/dev/zbusvar.h>
6566e9e901Smhitch
661ee8b50fSis #ifdef __powerpc__
671ee8b50fSis #define badaddr(a) badaddr_read(a, 2, NULL)
681ee8b50fSis #endif
691ee8b50fSis
7078a1d236Stsutsui int cbiiscmatch(device_t, cfdata_t, void *);
7178a1d236Stsutsui void cbiiscattach(device_t, device_t, void *);
7266e9e901Smhitch
7366e9e901Smhitch /* Linkup to the rest of the kernel */
7478a1d236Stsutsui CFATTACH_DECL_NEW(cbiisc, sizeof(struct cbiisc_softc),
75c5e91d44Sthorpej cbiiscmatch, cbiiscattach, NULL, NULL);
7666e9e901Smhitch
7766e9e901Smhitch /*
7866e9e901Smhitch * Functions and the switch for the MI code.
7966e9e901Smhitch */
8078a1d236Stsutsui uint8_t cbiisc_read_reg(struct ncr53c9x_softc *, int);
8178a1d236Stsutsui void cbiisc_write_reg(struct ncr53c9x_softc *, int, uint8_t);
829382c873Saymeric int cbiisc_dma_isintr(struct ncr53c9x_softc *);
839382c873Saymeric void cbiisc_dma_reset(struct ncr53c9x_softc *);
849382c873Saymeric int cbiisc_dma_intr(struct ncr53c9x_softc *);
8578a1d236Stsutsui int cbiisc_dma_setup(struct ncr53c9x_softc *, uint8_t **,
869382c873Saymeric size_t *, int, size_t *);
879382c873Saymeric void cbiisc_dma_go(struct ncr53c9x_softc *);
889382c873Saymeric void cbiisc_dma_stop(struct ncr53c9x_softc *);
899382c873Saymeric int cbiisc_dma_isactive(struct ncr53c9x_softc *);
9066e9e901Smhitch
9166e9e901Smhitch struct ncr53c9x_glue cbiisc_glue = {
9266e9e901Smhitch cbiisc_read_reg,
9366e9e901Smhitch cbiisc_write_reg,
9466e9e901Smhitch cbiisc_dma_isintr,
9566e9e901Smhitch cbiisc_dma_reset,
9666e9e901Smhitch cbiisc_dma_intr,
9766e9e901Smhitch cbiisc_dma_setup,
9866e9e901Smhitch cbiisc_dma_go,
9966e9e901Smhitch cbiisc_dma_stop,
10066e9e901Smhitch cbiisc_dma_isactive,
10178a1d236Stsutsui NULL,
10266e9e901Smhitch };
10366e9e901Smhitch
10466e9e901Smhitch /* Maximum DMA transfer length to reduce impact on high-speed serial input */
10566e9e901Smhitch u_long cbiisc_max_dma = 1024;
10666e9e901Smhitch extern int ser_open_speed;
10766e9e901Smhitch
10866e9e901Smhitch u_long cbiisc_cnt_pio = 0; /* number of PIO transfers */
10966e9e901Smhitch u_long cbiisc_cnt_dma = 0; /* number of DMA transfers */
11066e9e901Smhitch u_long cbiisc_cnt_dma2 = 0; /* number of DMA transfers broken up */
11166e9e901Smhitch u_long cbiisc_cnt_dma3 = 0; /* number of pages combined */
11266e9e901Smhitch
11366e9e901Smhitch #ifdef DEBUG
11466e9e901Smhitch struct {
11578a1d236Stsutsui uint8_t hardbits;
11678a1d236Stsutsui uint8_t status;
11778a1d236Stsutsui uint8_t xx;
11878a1d236Stsutsui uint8_t yy;
11966e9e901Smhitch } cbiisc_trace[128];
12066e9e901Smhitch int cbiisc_trace_ptr = 0;
12166e9e901Smhitch int cbiisc_trace_enable = 1;
1229382c873Saymeric void cbiisc_dump(void);
12366e9e901Smhitch #endif
12466e9e901Smhitch
12566e9e901Smhitch /*
12666e9e901Smhitch * if we are a Phase5 CyberSCSI II
12766e9e901Smhitch */
12866e9e901Smhitch int
cbiiscmatch(device_t parent,cfdata_t cf,void * aux)12978a1d236Stsutsui cbiiscmatch(device_t parent, cfdata_t cf, void *aux)
13066e9e901Smhitch {
13166e9e901Smhitch struct zbus_args *zap;
13278a1d236Stsutsui volatile uint8_t *regs;
13366e9e901Smhitch
13466e9e901Smhitch zap = aux;
1359bec32eeSmhitch if (zap->manid != 0x2140 || zap->prodid != 25)
13678a1d236Stsutsui return 0;
13778a1d236Stsutsui regs = &((volatile uint8_t *)zap->va)[0x1ff03];
13853524e44Schristos if (badaddr((void *)__UNVOLATILE(regs)))
13978a1d236Stsutsui return 0;
14066e9e901Smhitch regs[NCR_CFG1 * 4] = 0;
14166e9e901Smhitch regs[NCR_CFG1 * 4] = NCRCFG1_PARENB | 7;
14266e9e901Smhitch delay(5);
14366e9e901Smhitch if (regs[NCR_CFG1 * 4] != (NCRCFG1_PARENB | 7))
14478a1d236Stsutsui return 0;
14578a1d236Stsutsui return 1;
14666e9e901Smhitch }
14766e9e901Smhitch
14866e9e901Smhitch /*
14966e9e901Smhitch * Attach this instance, and then all the sub-devices
15066e9e901Smhitch */
15166e9e901Smhitch void
cbiiscattach(device_t parent,device_t self,void * aux)15278a1d236Stsutsui cbiiscattach(device_t parent, device_t self, void *aux)
15366e9e901Smhitch {
15478a1d236Stsutsui struct cbiisc_softc *csc = device_private(self);
15566e9e901Smhitch struct ncr53c9x_softc *sc = &csc->sc_ncr53c9x;
15666e9e901Smhitch struct zbus_args *zap;
15766e9e901Smhitch extern u_long scsi_nosync;
15866e9e901Smhitch extern int shift_nosync;
15966e9e901Smhitch extern int ncr53c9x_debug;
16066e9e901Smhitch
16166e9e901Smhitch /*
16266e9e901Smhitch * Set up the glue for MI code early; we use some of it here.
16366e9e901Smhitch */
16478a1d236Stsutsui sc->sc_dev = self;
16566e9e901Smhitch sc->sc_glue = &cbiisc_glue;
16666e9e901Smhitch
16766e9e901Smhitch /*
16866e9e901Smhitch * Save the regs
16966e9e901Smhitch */
17066e9e901Smhitch zap = aux;
17178a1d236Stsutsui csc->sc_reg = &((volatile uint8_t *)zap->va)[0x1ff03];
17266e9e901Smhitch csc->sc_dmabase = &csc->sc_reg[0x80];
17366e9e901Smhitch
174a1f606d3Slukem sc->sc_freq = 40; /* Clocked at 40 MHz */
17566e9e901Smhitch
17678a1d236Stsutsui aprint_normal(": address %p", csc->sc_reg);
17766e9e901Smhitch
17866e9e901Smhitch sc->sc_id = 7;
17966e9e901Smhitch
18066e9e901Smhitch /*
18166e9e901Smhitch * It is necessary to try to load the 2nd config register here,
18266e9e901Smhitch * to find out what rev the FAS chip is, else the ncr53c9x_reset
18366e9e901Smhitch * will not set up the defaults correctly.
18466e9e901Smhitch */
18566e9e901Smhitch sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
18666e9e901Smhitch sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_FE;
18766e9e901Smhitch sc->sc_cfg3 = 0x08 /*FCLK*/ | NCRESPCFG3_FSCSI | NCRESPCFG3_CDB;
18866e9e901Smhitch sc->sc_rev = NCR_VARIANT_FAS216;
18966e9e901Smhitch
19066e9e901Smhitch /*
19166e9e901Smhitch * This is the value used to start sync negotiations
19266e9e901Smhitch * Note that the NCR register "SYNCTP" is programmed
19366e9e901Smhitch * in "clocks per byte", and has a minimum value of 4.
19466e9e901Smhitch * The SCSI period used in negotiation is one-fourth
19566e9e901Smhitch * of the time (in nanoseconds) needed to transfer one byte.
19666e9e901Smhitch * Since the chip's clock is given in MHz, we have the following
19766e9e901Smhitch * formula: 4 * period = (1000 / freq) * 4
19866e9e901Smhitch */
19966e9e901Smhitch sc->sc_minsync = 1000 / sc->sc_freq;
20066e9e901Smhitch
20166e9e901Smhitch /*
20266e9e901Smhitch * get flags from -I argument and set cf_flags.
20366e9e901Smhitch * NOTE: low 8 bits are to disable disconnect, and the next
20466e9e901Smhitch * 8 bits are to disable sync.
20566e9e901Smhitch */
20678a1d236Stsutsui device_cfdata(self)->cf_flags |= (scsi_nosync >> shift_nosync)
20766e9e901Smhitch & 0xffff;
20866e9e901Smhitch shift_nosync += 16;
20966e9e901Smhitch
21066e9e901Smhitch /* Use next 16 bits of -I argument to set ncr53c9x_debug flags */
21166e9e901Smhitch ncr53c9x_debug |= (scsi_nosync >> shift_nosync) & 0xffff;
21266e9e901Smhitch shift_nosync += 16;
21366e9e901Smhitch
21466e9e901Smhitch #if 1
21566e9e901Smhitch if (((scsi_nosync >> shift_nosync) & 0xff00) == 0xff00)
21666e9e901Smhitch sc->sc_minsync = 0;
21766e9e901Smhitch #endif
21866e9e901Smhitch
21966e9e901Smhitch /* Really no limit, but since we want to fit into the TCR... */
22066e9e901Smhitch sc->sc_maxxfer = 64 * 1024;
22166e9e901Smhitch
22266e9e901Smhitch /*
22366e9e901Smhitch * Configure interrupts.
22466e9e901Smhitch */
2258c4d1bf1Stsutsui csc->sc_isr.isr_intr = ncr53c9x_intr;
22666e9e901Smhitch csc->sc_isr.isr_arg = sc;
22766e9e901Smhitch csc->sc_isr.isr_ipl = 2;
22866e9e901Smhitch add_isr(&csc->sc_isr);
22966e9e901Smhitch
23066e9e901Smhitch /*
23166e9e901Smhitch * Now try to attach all the sub-devices
23266e9e901Smhitch */
233937a7a3eSbouyer sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
234937a7a3eSbouyer sc->sc_adapter.adapt_minphys = minphys;
235937a7a3eSbouyer ncr53c9x_attach(sc);
23666e9e901Smhitch }
23766e9e901Smhitch
23866e9e901Smhitch /*
23966e9e901Smhitch * Glue functions.
24066e9e901Smhitch */
24166e9e901Smhitch
24278a1d236Stsutsui uint8_t
cbiisc_read_reg(struct ncr53c9x_softc * sc,int reg)2439382c873Saymeric cbiisc_read_reg(struct ncr53c9x_softc *sc, int reg)
24466e9e901Smhitch {
24566e9e901Smhitch struct cbiisc_softc *csc = (struct cbiisc_softc *)sc;
24666e9e901Smhitch
24766e9e901Smhitch return csc->sc_reg[reg * 4];
24866e9e901Smhitch }
24966e9e901Smhitch
25066e9e901Smhitch void
cbiisc_write_reg(struct ncr53c9x_softc * sc,int reg,uint8_t val)25178a1d236Stsutsui cbiisc_write_reg(struct ncr53c9x_softc *sc, int reg, uint8_t val)
25266e9e901Smhitch {
25366e9e901Smhitch struct cbiisc_softc *csc = (struct cbiisc_softc *)sc;
25478a1d236Stsutsui uint8_t v = val;
25566e9e901Smhitch
25666e9e901Smhitch csc->sc_reg[reg * 4] = v;
25766e9e901Smhitch #ifdef DEBUG
258e6c88a76Sthorpej if (cbiisc_trace_enable/* && sc->sc_nexus && sc->sc_nexus->xs->xs_control & XS_CTL_POLL*/ &&
25966e9e901Smhitch reg == NCR_CMD/* && csc->sc_active*/) {
26066e9e901Smhitch cbiisc_trace[(cbiisc_trace_ptr - 1) & 127].yy = v;
26166e9e901Smhitch /* printf(" cmd %x", v);*/
26266e9e901Smhitch }
26366e9e901Smhitch #endif
26466e9e901Smhitch }
26566e9e901Smhitch
26666e9e901Smhitch int
cbiisc_dma_isintr(struct ncr53c9x_softc * sc)2679382c873Saymeric cbiisc_dma_isintr(struct ncr53c9x_softc *sc)
26866e9e901Smhitch {
26966e9e901Smhitch struct cbiisc_softc *csc = (struct cbiisc_softc *)sc;
27066e9e901Smhitch
27166e9e901Smhitch if ((csc->sc_reg[NCR_STAT * 4] & NCRSTAT_INT) == 0)
27266e9e901Smhitch return 0;
27366e9e901Smhitch
27466e9e901Smhitch if (sc->sc_state == NCR_CONNECTED)
27566e9e901Smhitch csc->sc_reg[0x40] = CBIISC_PB_LED;
27666e9e901Smhitch else
27766e9e901Smhitch csc->sc_reg[0x40] = 0;
27866e9e901Smhitch
27966e9e901Smhitch #ifdef DEBUG
280e6c88a76Sthorpej if (/*sc->sc_nexus && sc->sc_nexus->xs->xs_control & XS_CTL_POLL &&*/ cbiisc_trace_enable) {
28166e9e901Smhitch cbiisc_trace[cbiisc_trace_ptr].status = csc->sc_reg[NCR_STAT * 4];
28266e9e901Smhitch cbiisc_trace[cbiisc_trace_ptr].xx = csc->sc_reg[NCR_CMD * 4];
28366e9e901Smhitch cbiisc_trace[cbiisc_trace_ptr].yy = csc->sc_active;
28466e9e901Smhitch cbiisc_trace_ptr = (cbiisc_trace_ptr + 1) & 127;
28566e9e901Smhitch }
28666e9e901Smhitch #endif
28766e9e901Smhitch return 1;
28866e9e901Smhitch }
28966e9e901Smhitch
29066e9e901Smhitch void
cbiisc_dma_reset(struct ncr53c9x_softc * sc)2919382c873Saymeric cbiisc_dma_reset(struct ncr53c9x_softc *sc)
29266e9e901Smhitch {
29366e9e901Smhitch struct cbiisc_softc *csc = (struct cbiisc_softc *)sc;
29466e9e901Smhitch
29566e9e901Smhitch csc->sc_active = 0;
29666e9e901Smhitch }
29766e9e901Smhitch
29866e9e901Smhitch int
cbiisc_dma_intr(struct ncr53c9x_softc * sc)2999382c873Saymeric cbiisc_dma_intr(struct ncr53c9x_softc *sc)
30066e9e901Smhitch {
30166e9e901Smhitch register struct cbiisc_softc *csc = (struct cbiisc_softc *)sc;
30266e9e901Smhitch register int cnt;
30366e9e901Smhitch
30466e9e901Smhitch NCR_DMA(("cbiisc_dma_intr: cnt %d int %x stat %x fifo %d ",
30566e9e901Smhitch csc->sc_dmasize, sc->sc_espintr, sc->sc_espstat,
30666e9e901Smhitch csc->sc_reg[NCR_FFLAG * 4] & NCRFIFO_FF));
30766e9e901Smhitch if (csc->sc_active == 0) {
30866e9e901Smhitch printf("cbiisc_intr--inactive DMA\n");
30966e9e901Smhitch return -1;
31066e9e901Smhitch }
31166e9e901Smhitch
31266e9e901Smhitch /* update sc_dmaaddr and sc_pdmalen */
31366e9e901Smhitch cnt = csc->sc_reg[NCR_TCL * 4];
31466e9e901Smhitch cnt += csc->sc_reg[NCR_TCM * 4] << 8;
31566e9e901Smhitch cnt += csc->sc_reg[NCR_TCH * 4] << 16;
31666e9e901Smhitch if (!csc->sc_datain) {
31766e9e901Smhitch cnt += csc->sc_reg[NCR_FFLAG * 4] & NCRFIFO_FF;
31866e9e901Smhitch csc->sc_reg[NCR_CMD * 4] = NCRCMD_FLUSH;
31966e9e901Smhitch }
32066e9e901Smhitch cnt = csc->sc_dmasize - cnt; /* number of bytes transferred */
32166e9e901Smhitch NCR_DMA(("DMA xferred %d\n", cnt));
32266e9e901Smhitch if (csc->sc_xfr_align) {
32378a1d236Stsutsui memcpy(*csc->sc_dmaaddr, csc->sc_alignbuf, cnt);
32466e9e901Smhitch csc->sc_xfr_align = 0;
32566e9e901Smhitch }
32666e9e901Smhitch *csc->sc_dmaaddr += cnt;
32766e9e901Smhitch *csc->sc_pdmalen -= cnt;
32866e9e901Smhitch csc->sc_active = 0;
32966e9e901Smhitch return 0;
33066e9e901Smhitch }
33166e9e901Smhitch
33266e9e901Smhitch int
cbiisc_dma_setup(struct ncr53c9x_softc * sc,uint8_t ** addr,size_t * len,int datain,size_t * dmasize)33378a1d236Stsutsui cbiisc_dma_setup(struct ncr53c9x_softc *sc, uint8_t **addr, size_t *len,
3349382c873Saymeric int datain, size_t *dmasize)
33566e9e901Smhitch {
33666e9e901Smhitch struct cbiisc_softc *csc = (struct cbiisc_softc *)sc;
337744246faSis paddr_t pa;
33878a1d236Stsutsui uint8_t *ptr;
33966e9e901Smhitch size_t xfer;
34066e9e901Smhitch
34178a1d236Stsutsui csc->sc_dmaaddr = addr;
34266e9e901Smhitch csc->sc_pdmalen = len;
34366e9e901Smhitch csc->sc_datain = datain;
34466e9e901Smhitch csc->sc_dmasize = *dmasize;
34566e9e901Smhitch /*
34666e9e901Smhitch * DMA can be nasty for high-speed serial input, so limit the
34766e9e901Smhitch * size of this DMA operation if the serial port is running at
34866e9e901Smhitch * a high speed (higher than 19200 for now - should be adjusted
349d20841bbSwiz * based on CPU type and speed?).
35066e9e901Smhitch * XXX - add serial speed check XXX
35166e9e901Smhitch */
35266e9e901Smhitch if (ser_open_speed > 19200 && cbiisc_max_dma != 0 &&
35366e9e901Smhitch csc->sc_dmasize > cbiisc_max_dma)
35466e9e901Smhitch csc->sc_dmasize = cbiisc_max_dma;
35566e9e901Smhitch ptr = *addr; /* Kernel virtual address */
35666e9e901Smhitch pa = kvtop(ptr); /* Physical address of DMA */
357d1579b2dSriastradh xfer = uimin(csc->sc_dmasize, PAGE_SIZE - (pa & (PAGE_SIZE - 1)));
35866e9e901Smhitch csc->sc_xfr_align = 0;
35966e9e901Smhitch /*
36066e9e901Smhitch * If output and unaligned, stuff odd byte into FIFO
36166e9e901Smhitch */
36266e9e901Smhitch if (datain == 0 && (int)ptr & 1) {
36366e9e901Smhitch NCR_DMA(("cbiisc_dma_setup: align byte written to fifo\n"));
36466e9e901Smhitch pa++;
36566e9e901Smhitch xfer--; /* XXXX CHECK THIS !!!! XXXX */
36666e9e901Smhitch csc->sc_reg[NCR_FIFO * 4] = *ptr++;
36766e9e901Smhitch }
36866e9e901Smhitch /*
36966e9e901Smhitch * If unaligned address, read unaligned bytes into alignment buffer
37066e9e901Smhitch */
37166e9e901Smhitch else if ((int)ptr & 1) {
37253524e44Schristos pa = kvtop((void *)&csc->sc_alignbuf);
373d1579b2dSriastradh xfer = csc->sc_dmasize = uimin(xfer, sizeof(csc->sc_alignbuf));
37466e9e901Smhitch NCR_DMA(("cbiisc_dma_setup: align read by %d bytes\n", xfer));
37566e9e901Smhitch csc->sc_xfr_align = 1;
37666e9e901Smhitch }
37766e9e901Smhitch ++cbiisc_cnt_dma; /* number of DMA operations */
37866e9e901Smhitch
37966e9e901Smhitch while (xfer < csc->sc_dmasize) {
38078a1d236Stsutsui if ((pa + xfer) != kvtop(*addr + xfer))
38166e9e901Smhitch break;
3828818afa4Sthorpej if ((csc->sc_dmasize - xfer) < PAGE_SIZE)
38366e9e901Smhitch xfer = csc->sc_dmasize;
38466e9e901Smhitch else
3858818afa4Sthorpej xfer += PAGE_SIZE;
38666e9e901Smhitch ++cbiisc_cnt_dma3;
38766e9e901Smhitch }
38866e9e901Smhitch if (xfer != *len)
38966e9e901Smhitch ++cbiisc_cnt_dma2;
39066e9e901Smhitch
39166e9e901Smhitch csc->sc_dmasize = xfer;
39266e9e901Smhitch *dmasize = csc->sc_dmasize;
39366e9e901Smhitch csc->sc_pa = pa;
39466e9e901Smhitch #if defined(M68040) || defined(M68060)
39566e9e901Smhitch if (mmutype == MMU_68040) {
39666e9e901Smhitch if (csc->sc_xfr_align) {
39766e9e901Smhitch dma_cachectl(csc->sc_alignbuf,
39866e9e901Smhitch sizeof(csc->sc_alignbuf));
39966e9e901Smhitch }
40066e9e901Smhitch else
40166e9e901Smhitch dma_cachectl(*csc->sc_dmaaddr, csc->sc_dmasize);
40266e9e901Smhitch }
40366e9e901Smhitch #endif
40466e9e901Smhitch
40566e9e901Smhitch if (csc->sc_datain)
40666e9e901Smhitch pa &= ~1;
40766e9e901Smhitch else
40866e9e901Smhitch pa |= 1;
40978a1d236Stsutsui csc->sc_dmabase[0] = (uint8_t)(pa >> 24);
41078a1d236Stsutsui csc->sc_dmabase[4] = (uint8_t)(pa >> 16);
41178a1d236Stsutsui csc->sc_dmabase[8] = (uint8_t)(pa >> 8);
41278a1d236Stsutsui csc->sc_dmabase[12] = (uint8_t)(pa);
41366e9e901Smhitch csc->sc_active = 1;
41466e9e901Smhitch return 0;
41566e9e901Smhitch }
41666e9e901Smhitch
41766e9e901Smhitch void
cbiisc_dma_go(struct ncr53c9x_softc * sc)4189382c873Saymeric cbiisc_dma_go(struct ncr53c9x_softc *sc)
41966e9e901Smhitch {
42066e9e901Smhitch }
42166e9e901Smhitch
42266e9e901Smhitch void
cbiisc_dma_stop(struct ncr53c9x_softc * sc)4239382c873Saymeric cbiisc_dma_stop(struct ncr53c9x_softc *sc)
42466e9e901Smhitch {
42566e9e901Smhitch }
42666e9e901Smhitch
42766e9e901Smhitch int
cbiisc_dma_isactive(struct ncr53c9x_softc * sc)4289382c873Saymeric cbiisc_dma_isactive(struct ncr53c9x_softc *sc)
42966e9e901Smhitch {
43066e9e901Smhitch struct cbiisc_softc *csc = (struct cbiisc_softc *)sc;
43166e9e901Smhitch
43266e9e901Smhitch return csc->sc_active;
43366e9e901Smhitch }
43466e9e901Smhitch
43566e9e901Smhitch #ifdef DEBUG
43666e9e901Smhitch void
cbiisc_dump(void)4379382c873Saymeric cbiisc_dump(void)
43866e9e901Smhitch {
43966e9e901Smhitch int i;
44066e9e901Smhitch
44166e9e901Smhitch i = cbiisc_trace_ptr;
44266e9e901Smhitch printf("cbiisc_trace dump: ptr %x\n", cbiisc_trace_ptr);
44366e9e901Smhitch do {
44466e9e901Smhitch if (cbiisc_trace[i].hardbits == 0) {
44566e9e901Smhitch i = (i + 1) & 127;
44666e9e901Smhitch continue;
44766e9e901Smhitch }
44866e9e901Smhitch printf("%02x%02x%02x%02x(", cbiisc_trace[i].hardbits,
44966e9e901Smhitch cbiisc_trace[i].status, cbiisc_trace[i].xx, cbiisc_trace[i].yy);
45066e9e901Smhitch if (cbiisc_trace[i].status & NCRSTAT_INT)
45166e9e901Smhitch printf("NCRINT/");
45266e9e901Smhitch if (cbiisc_trace[i].status & NCRSTAT_TC)
45366e9e901Smhitch printf("NCRTC/");
45466e9e901Smhitch switch(cbiisc_trace[i].status & NCRSTAT_PHASE) {
45566e9e901Smhitch case 0:
45666e9e901Smhitch printf("dataout"); break;
45766e9e901Smhitch case 1:
45866e9e901Smhitch printf("datain"); break;
45966e9e901Smhitch case 2:
46066e9e901Smhitch printf("cmdout"); break;
46166e9e901Smhitch case 3:
46266e9e901Smhitch printf("status"); break;
46366e9e901Smhitch case 6:
46466e9e901Smhitch printf("msgout"); break;
46566e9e901Smhitch case 7:
46666e9e901Smhitch printf("msgin"); break;
46766e9e901Smhitch default:
46866e9e901Smhitch printf("phase%d?", cbiisc_trace[i].status & NCRSTAT_PHASE);
46966e9e901Smhitch }
47066e9e901Smhitch printf(") ");
47166e9e901Smhitch i = (i + 1) & 127;
47266e9e901Smhitch } while (i != cbiisc_trace_ptr);
47366e9e901Smhitch printf("\n");
47466e9e901Smhitch }
47566e9e901Smhitch #endif
476