Home | History | Annotate | Line # | Download | only in dev
flsc.c revision 1.5.4.1
      1  1.5.4.1       is /*	$NetBSD: flsc.c,v 1.5.4.1 1996/06/03 19:35:40 is Exp $	*/
      2      1.5    veego 
      3      1.1   chopps /*
      4      1.1   chopps  * Copyright (c) 1995 Daniel Widenfalk
      5      1.1   chopps  * Copyright (c) 1994 Christian E. Hopps
      6      1.1   chopps  * Copyright (c) 1982, 1990 The Regents of the University of California.
      7      1.1   chopps  * All rights reserved.
      8      1.1   chopps  *
      9      1.1   chopps  * Redistribution and use in source and binary forms, with or without
     10      1.1   chopps  * modification, are permitted provided that the following conditions
     11      1.1   chopps  * are met:
     12      1.1   chopps  * 1. Redistributions of source code must retain the above copyright
     13      1.1   chopps  *    notice, this list of conditions and the following disclaimer.
     14      1.1   chopps  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1   chopps  *    notice, this list of conditions and the following disclaimer in the
     16      1.1   chopps  *    documentation and/or other materials provided with the distribution.
     17      1.1   chopps  * 3. All advertising materials mentioning features or use of this software
     18      1.1   chopps  *    must display the following acknowledgement:
     19      1.1   chopps  *	This product includes software developed by the University of
     20      1.1   chopps  *	California, Berkeley and its contributors.
     21      1.1   chopps  * 4. Neither the name of the University nor the names of its contributors
     22      1.1   chopps  *    may be used to endorse or promote products derived from this software
     23      1.1   chopps  *    without specific prior written permission.
     24      1.1   chopps  *
     25      1.1   chopps  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26      1.1   chopps  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27      1.1   chopps  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28      1.1   chopps  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29      1.1   chopps  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30      1.1   chopps  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31      1.1   chopps  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32      1.1   chopps  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33      1.1   chopps  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34      1.1   chopps  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35      1.1   chopps  * SUCH DAMAGE.
     36      1.1   chopps  *
     37      1.1   chopps  *	@(#)dma.c
     38      1.1   chopps  */
     39      1.1   chopps 
     40      1.1   chopps #include <sys/param.h>
     41      1.1   chopps #include <sys/systm.h>
     42      1.1   chopps #include <sys/kernel.h>
     43      1.1   chopps #include <sys/device.h>
     44      1.1   chopps #include <scsi/scsi_all.h>
     45      1.1   chopps #include <scsi/scsiconf.h>
     46      1.1   chopps #include <vm/vm.h>
     47      1.1   chopps #include <vm/vm_kern.h>
     48      1.1   chopps #include <vm/vm_page.h>
     49      1.1   chopps #include <machine/pmap.h>
     50      1.1   chopps #include <amiga/amiga/custom.h>
     51      1.1   chopps #include <amiga/amiga/cc.h>
     52      1.1   chopps #include <amiga/amiga/device.h>
     53      1.1   chopps #include <amiga/amiga/isr.h>
     54      1.1   chopps #include <amiga/dev/sfasreg.h>
     55      1.1   chopps #include <amiga/dev/sfasvar.h>
     56      1.1   chopps #include <amiga/dev/zbusvar.h>
     57      1.1   chopps #include <amiga/dev/flscreg.h>
     58      1.1   chopps #include <amiga/dev/flscvar.h>
     59      1.1   chopps 
     60      1.1   chopps int  flscprint  __P((void *auxp, char *));
     61      1.1   chopps void flscattach __P((struct device *, struct device *, void *));
     62      1.3  thorpej int  flscmatch  __P((struct device *, void *, void *));
     63      1.1   chopps 
     64      1.1   chopps struct scsi_adapter flsc_scsiswitch = {
     65      1.1   chopps 	sfas_scsicmd,
     66      1.1   chopps 	sfas_minphys,
     67      1.1   chopps 	0,			/* no lun support */
     68      1.1   chopps 	0,			/* no lun support */
     69      1.1   chopps };
     70      1.1   chopps 
     71      1.1   chopps struct scsi_device flsc_scsidev = {
     72      1.1   chopps 	NULL,		/* use default error handler */
     73      1.1   chopps 	NULL,		/* do not have a start functio */
     74      1.1   chopps 	NULL,		/* have no async handler */
     75      1.1   chopps 	NULL,		/* Use default done routine */
     76      1.1   chopps };
     77      1.1   chopps 
     78      1.3  thorpej struct cfattach flsc_ca = {
     79      1.3  thorpej 	sizeof(struct flsc_softc), flscmatch, flscattach
     80      1.3  thorpej };
     81      1.1   chopps 
     82      1.3  thorpej struct cfdriver flsc_cd = {
     83      1.3  thorpej 	NULL, "flsc", DV_DULL, NULL, 0
     84      1.3  thorpej };
     85      1.1   chopps 
     86      1.5    veego int flsc_intr		 __P((void *));
     87      1.5    veego void flsc_set_dma_adr	 __P((struct sfas_softc *sc, vm_offset_t ptr));
     88      1.5    veego void flsc_set_dma_tc	 __P((struct sfas_softc *sc, unsigned int len));
     89      1.5    veego void flsc_set_dma_mode	 __P((struct sfas_softc *sc, int mode));
     90      1.5    veego int flsc_setup_dma	 __P((struct sfas_softc *sc, vm_offset_t ptr, int len,
     91      1.1   chopps 			      int mode));
     92      1.1   chopps int flsc_build_dma_chain __P((struct sfas_softc *sc,
     93      1.1   chopps 			      struct sfas_dma_chain *chain, void *p, int l));
     94      1.5    veego int flsc_need_bump	 __P((struct sfas_softc *sc, vm_offset_t ptr, int len));
     95      1.1   chopps void flsc_led		 __P((struct sfas_softc *sc, int mode));
     96      1.1   chopps 
     97      1.1   chopps /*
     98      1.1   chopps  * if we are an Advanced Systems & Software FastlaneZ3
     99      1.1   chopps  */
    100      1.1   chopps int
    101      1.4   mhitch flscmatch(pdp, match, auxp)
    102      1.1   chopps 	struct device	*pdp;
    103      1.3  thorpej 	void		*match, *auxp;
    104      1.1   chopps {
    105      1.1   chopps 	struct zbus_args *zap;
    106      1.1   chopps 
    107      1.1   chopps 	if (!is_a4000() && !is_a3000())
    108      1.1   chopps 		return(0);
    109      1.1   chopps 
    110      1.1   chopps 	zap = auxp;
    111  1.5.4.1       is 	if (zap->manid == 0x2140 && zap->prodid == 11
    112  1.5.4.1       is 	    && iszthreepa(zap->pa))
    113      1.1   chopps 		return(1);
    114      1.1   chopps 
    115      1.1   chopps 	return(0);
    116      1.1   chopps }
    117      1.1   chopps 
    118      1.1   chopps void
    119      1.1   chopps flscattach(pdp, dp, auxp)
    120      1.1   chopps 	struct device	*pdp;
    121      1.1   chopps 	struct device	*dp;
    122      1.1   chopps 	void		*auxp;
    123      1.1   chopps {
    124      1.1   chopps 	struct flsc_softc *sc;
    125      1.1   chopps 	struct zbus_args  *zap;
    126      1.1   chopps 	flsc_regmap_p	   rp;
    127      1.1   chopps 	vu_char		  *fas;
    128      1.1   chopps 
    129      1.1   chopps 	zap = auxp;
    130      1.1   chopps 	fas = &((vu_char *)zap->va)[0x1000001];
    131      1.1   chopps 
    132      1.1   chopps 	sc = (struct flsc_softc *)dp;
    133      1.1   chopps 	rp = &sc->sc_regmap;
    134      1.1   chopps 
    135      1.1   chopps 	rp->FAS216.sfas_tc_low	= &fas[0x00];
    136      1.1   chopps 	rp->FAS216.sfas_tc_mid	= &fas[0x04];
    137      1.1   chopps 	rp->FAS216.sfas_fifo	= &fas[0x08];
    138      1.1   chopps 	rp->FAS216.sfas_command	= &fas[0x0C];
    139      1.1   chopps 	rp->FAS216.sfas_dest_id	= &fas[0x10];
    140      1.1   chopps 	rp->FAS216.sfas_timeout	= &fas[0x14];
    141      1.1   chopps 	rp->FAS216.sfas_syncper	= &fas[0x18];
    142      1.1   chopps 	rp->FAS216.sfas_syncoff	= &fas[0x1C];
    143      1.1   chopps 	rp->FAS216.sfas_config1	= &fas[0x20];
    144      1.1   chopps 	rp->FAS216.sfas_clkconv	= &fas[0x24];
    145      1.1   chopps 	rp->FAS216.sfas_test	= &fas[0x28];
    146      1.1   chopps 	rp->FAS216.sfas_config2	= &fas[0x2C];
    147      1.1   chopps 	rp->FAS216.sfas_config3	= &fas[0x30];
    148      1.1   chopps 	rp->FAS216.sfas_tc_high	= &fas[0x38];
    149      1.1   chopps 	rp->FAS216.sfas_fifo_bot = &fas[0x3C];
    150      1.1   chopps 	rp->hardbits		= &fas[0x40];
    151      1.1   chopps 	rp->clear		= &fas[0x80];
    152      1.1   chopps 	rp->dmabase		= zap->va;
    153      1.1   chopps 
    154      1.1   chopps 	sc->sc_softc.sc_fas	= (sfas_regmap_p)rp;
    155      1.1   chopps 	sc->sc_softc.sc_spec	= &sc->sc_specific;
    156      1.1   chopps 
    157      1.1   chopps 	sc->sc_softc.sc_led	= flsc_led;
    158      1.1   chopps 
    159      1.1   chopps 	sc->sc_softc.sc_setup_dma	= flsc_setup_dma;
    160      1.1   chopps 	sc->sc_softc.sc_build_dma_chain = flsc_build_dma_chain;
    161      1.1   chopps 	sc->sc_softc.sc_need_bump	= flsc_need_bump;
    162      1.1   chopps 
    163      1.1   chopps 	sc->sc_softc.sc_clock_freq   = 40;   /* FastlaneZ3 runs at 40MHz */
    164      1.1   chopps 	sc->sc_softc.sc_timeout      = 250;  /* Set default timeout to 250ms */
    165      1.1   chopps 	sc->sc_softc.sc_config_flags = 0;    /* No config flags yet */
    166      1.1   chopps 	sc->sc_softc.sc_host_id      = 7;    /* Should check the jumpers */
    167      1.1   chopps 
    168      1.1   chopps 	sc->sc_specific.portbits = 0xA0 | FLSC_PB_EDI | FLSC_PB_ESI;
    169      1.1   chopps 	sc->sc_specific.hardbits = *rp->hardbits;
    170      1.1   chopps 
    171      1.1   chopps 	sc->sc_softc.sc_bump_sz = NBPG;
    172      1.1   chopps 	sc->sc_softc.sc_bump_pa = 0x0;
    173      1.1   chopps 
    174      1.1   chopps 	sfasinitialize((struct sfas_softc *)sc);
    175      1.1   chopps 
    176      1.1   chopps 	sc->sc_softc.sc_link.adapter_softc  = sc;
    177      1.1   chopps 	sc->sc_softc.sc_link.adapter_target = sc->sc_softc.sc_host_id;
    178      1.1   chopps 	sc->sc_softc.sc_link.adapter	    = &flsc_scsiswitch;
    179      1.1   chopps 	sc->sc_softc.sc_link.device	    = &flsc_scsidev;
    180      1.1   chopps 	sc->sc_softc.sc_link.openings	    = 1;
    181      1.1   chopps 
    182      1.1   chopps 	sc->sc_softc.sc_isr.isr_intr = flsc_intr;
    183      1.1   chopps 	sc->sc_softc.sc_isr.isr_arg  = &sc->sc_softc;
    184      1.1   chopps 	sc->sc_softc.sc_isr.isr_ipl  = 2;
    185      1.1   chopps 	add_isr(&sc->sc_softc.sc_isr);
    186      1.1   chopps 
    187      1.1   chopps /* We don't want interrupt until we're initialized! */
    188      1.1   chopps 	*rp->hardbits = sc->sc_specific.portbits;
    189      1.1   chopps 
    190      1.1   chopps 	printf("\n");
    191      1.1   chopps 
    192      1.1   chopps /* attach all scsi units on us */
    193      1.1   chopps 	config_found(dp, &sc->sc_softc.sc_link, flscprint);
    194      1.1   chopps }
    195      1.1   chopps 
    196      1.1   chopps /* print diag if pnp is NULL else just extra */
    197      1.1   chopps int
    198      1.1   chopps flscprint(auxp, pnp)
    199      1.1   chopps 	void *auxp;
    200      1.1   chopps 	char *pnp;
    201      1.1   chopps {
    202      1.1   chopps 	if (pnp == NULL)
    203      1.1   chopps 		return(UNCONF);
    204      1.1   chopps 
    205      1.1   chopps 	return(QUIET);
    206      1.1   chopps }
    207      1.1   chopps 
    208      1.1   chopps int
    209      1.5    veego flsc_intr(arg)
    210      1.5    veego 	void *arg;
    211      1.1   chopps {
    212      1.5    veego 	struct sfas_softc *dev = arg;
    213      1.1   chopps 	flsc_regmap_p	      rp;
    214      1.1   chopps 	struct flsc_specific *flspec;
    215      1.1   chopps 	int		      quickints;
    216      1.1   chopps 	u_char		      hb;
    217      1.1   chopps 
    218      1.1   chopps 	flspec = dev->sc_spec;
    219      1.1   chopps 	rp = (flsc_regmap_p)dev->sc_fas;
    220      1.1   chopps 	hb = *rp->hardbits;
    221      1.1   chopps 
    222      1.1   chopps 	if (hb & FLSC_HB_IACT)
    223      1.1   chopps 		return(0);
    224      1.1   chopps 
    225      1.1   chopps 	flspec->hardbits = hb;
    226      1.1   chopps 	if ((hb & FLSC_HB_CREQ) &&
    227      1.1   chopps 	    !(hb & FLSC_HB_MINT) &&
    228      1.1   chopps 	    (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)) {
    229      1.1   chopps 		quickints = 16;
    230      1.1   chopps 		do {
    231      1.1   chopps 			dev->sc_status = *rp->FAS216.sfas_status;
    232      1.1   chopps 			dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
    233      1.1   chopps 
    234      1.1   chopps 			if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
    235      1.1   chopps 				dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
    236      1.1   chopps 				dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
    237      1.1   chopps 			}
    238      1.1   chopps 			sfasintr(dev);
    239      1.1   chopps 
    240      1.1   chopps 		} while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
    241      1.1   chopps 			&& --quickints);
    242      1.1   chopps 	}
    243      1.1   chopps 
    244      1.1   chopps 	/* Reset fastlane interrupt bits */
    245      1.1   chopps 	*rp->hardbits = flspec->portbits & ~FLSC_PB_INT_BITS;
    246      1.1   chopps 	*rp->hardbits = flspec->portbits;
    247      1.1   chopps 
    248      1.1   chopps 	return(1);
    249      1.1   chopps }
    250      1.1   chopps 
    251      1.1   chopps /* Load transfer adress into dma register */
    252      1.1   chopps void
    253      1.1   chopps flsc_set_dma_adr(sc, ptr)
    254      1.1   chopps 	struct sfas_softc *sc;
    255      1.5    veego 	vm_offset_t	  ptr;
    256      1.1   chopps {
    257      1.1   chopps 	flsc_regmap_p	rp;
    258      1.1   chopps 	unsigned int   *p;
    259      1.1   chopps 	unsigned int	d;
    260      1.1   chopps 
    261      1.1   chopps 	rp = (flsc_regmap_p)sc->sc_fas;
    262      1.1   chopps 
    263      1.1   chopps 	d = (unsigned int)ptr;
    264      1.1   chopps 	p = (unsigned int *)((d & 0xFFFFFF) + (int)rp->dmabase);
    265      1.1   chopps 
    266      1.1   chopps 	*rp->clear=0;
    267      1.1   chopps 	*p = d;
    268      1.1   chopps }
    269      1.1   chopps 
    270      1.1   chopps /* Set DMA transfer counter */
    271      1.1   chopps void
    272      1.1   chopps flsc_set_dma_tc(sc, len)
    273      1.1   chopps 	struct sfas_softc *sc;
    274      1.1   chopps 	unsigned int	  len;
    275      1.1   chopps {
    276      1.1   chopps 	*sc->sc_fas->sfas_tc_low  = len; len >>= 8;
    277      1.1   chopps 	*sc->sc_fas->sfas_tc_mid  = len; len >>= 8;
    278      1.1   chopps 	*sc->sc_fas->sfas_tc_high = len;
    279      1.1   chopps }
    280      1.1   chopps 
    281      1.1   chopps /* Set DMA mode */
    282      1.1   chopps void
    283      1.1   chopps flsc_set_dma_mode(sc, mode)
    284      1.1   chopps 	struct sfas_softc *sc;
    285      1.1   chopps 	int		  mode;
    286      1.1   chopps {
    287      1.1   chopps 	struct flsc_specific *spec;
    288      1.1   chopps 
    289      1.1   chopps 	spec = sc->sc_spec;
    290      1.1   chopps 
    291      1.1   chopps 	spec->portbits = (spec->portbits & ~FLSC_PB_DMA_BITS) | mode;
    292      1.1   chopps 	*((flsc_regmap_p)sc->sc_fas)->hardbits = spec->portbits;
    293      1.1   chopps }
    294      1.1   chopps 
    295      1.1   chopps /* Initialize DMA for transfer */
    296      1.1   chopps int
    297      1.1   chopps flsc_setup_dma(sc, ptr, len, mode)
    298      1.1   chopps 	struct sfas_softc *sc;
    299      1.5    veego 	vm_offset_t	  ptr;
    300      1.1   chopps 	int		  len;
    301      1.1   chopps 	int		  mode;
    302      1.1   chopps {
    303      1.1   chopps 	int	retval;
    304      1.1   chopps 
    305      1.1   chopps 	retval = 0;
    306      1.1   chopps 
    307      1.1   chopps 	switch(mode) {
    308      1.1   chopps 	case SFAS_DMA_READ:
    309      1.1   chopps 	case SFAS_DMA_WRITE:
    310      1.1   chopps 		flsc_set_dma_adr(sc, ptr);
    311      1.1   chopps 		if (mode == SFAS_DMA_READ)
    312      1.1   chopps 		  flsc_set_dma_mode(sc,FLSC_PB_ENABLE_DMA | FLSC_PB_DMA_READ);
    313      1.1   chopps 		else
    314      1.1   chopps 		  flsc_set_dma_mode(sc,FLSC_PB_ENABLE_DMA | FLSC_PB_DMA_WRITE);
    315      1.1   chopps 
    316      1.1   chopps 		flsc_set_dma_tc(sc, len);
    317      1.1   chopps 		break;
    318      1.1   chopps 
    319      1.1   chopps 	case SFAS_DMA_CLEAR:
    320      1.1   chopps 	default:
    321      1.1   chopps 		flsc_set_dma_mode(sc, FLSC_PB_DISABLE_DMA);
    322      1.1   chopps 		flsc_set_dma_adr(sc, 0);
    323      1.1   chopps 
    324      1.1   chopps 		retval = (*sc->sc_fas->sfas_tc_high << 16) |
    325      1.1   chopps 			 (*sc->sc_fas->sfas_tc_mid  <<  8) |
    326      1.1   chopps 			  *sc->sc_fas->sfas_tc_low;
    327      1.1   chopps 
    328      1.1   chopps 		flsc_set_dma_tc(sc, 0);
    329      1.1   chopps 		break;
    330      1.1   chopps 	}
    331      1.1   chopps 
    332      1.1   chopps 	return(retval);
    333      1.1   chopps }
    334      1.1   chopps 
    335      1.1   chopps /* Check if address and len is ok for DMA transfer */
    336      1.1   chopps int
    337      1.1   chopps flsc_need_bump(sc, ptr, len)
    338      1.1   chopps 	struct sfas_softc *sc;
    339      1.5    veego 	vm_offset_t	  ptr;
    340      1.1   chopps 	int		  len;
    341      1.1   chopps {
    342      1.1   chopps 	int	p;
    343      1.1   chopps 
    344      1.1   chopps 	p = (int)ptr & 0x03;
    345      1.1   chopps 
    346      1.1   chopps 	if (p) {
    347      1.1   chopps 		p = 4-p;
    348      1.1   chopps 
    349      1.1   chopps 		if (len < 256)
    350      1.1   chopps 			p = len;
    351      1.1   chopps 	}
    352      1.1   chopps 
    353      1.1   chopps 	return(p);
    354      1.1   chopps }
    355      1.1   chopps 
    356      1.1   chopps /* Interrupt driven routines */
    357      1.1   chopps int
    358      1.1   chopps flsc_build_dma_chain(sc, chain, p, l)
    359      1.1   chopps 	struct sfas_softc	*sc;
    360      1.1   chopps 	struct sfas_dma_chain	*chain;
    361      1.1   chopps 	void			*p;
    362      1.1   chopps 	int			 l;
    363      1.1   chopps {
    364      1.1   chopps 	vm_offset_t  pa, lastpa;
    365      1.1   chopps 	char	    *ptr;
    366      1.5    veego 	int	     len, prelen, max_t, n;
    367      1.1   chopps 
    368      1.1   chopps 	if (l == 0)
    369      1.1   chopps 		return(0);
    370      1.1   chopps 
    371      1.1   chopps #define set_link(n, p, l, f)\
    372      1.1   chopps do { chain[n].ptr = (p); chain[n].len = (l); chain[n++].flg = (f); } while(0)
    373      1.1   chopps 
    374      1.1   chopps 	n = 0;
    375      1.1   chopps 
    376      1.1   chopps 	if (l < 512)
    377      1.1   chopps 		set_link(n, (vm_offset_t)p, l, SFAS_CHAIN_BUMP);
    378      1.1   chopps 	else if ((p >= (void *)0xFF000000)
    379      1.1   chopps #if M68040
    380      1.2   chopps 		 && ((mmutype == MMU_68040) && (p >= (void *)0xFFFC0000))
    381      1.1   chopps #endif
    382      1.1   chopps 		 ) {
    383      1.1   chopps 		while(l != 0) {
    384      1.1   chopps 			len = ((l > sc->sc_bump_sz) ? sc->sc_bump_sz : l);
    385      1.1   chopps 
    386      1.1   chopps 			set_link(n, (vm_offset_t)p, len, SFAS_CHAIN_BUMP);
    387      1.1   chopps 
    388      1.1   chopps 			p += len;
    389      1.1   chopps 			l -= len;
    390      1.1   chopps 		}
    391      1.1   chopps 	} else {
    392      1.1   chopps 		ptr = p;
    393      1.1   chopps 		len = l;
    394      1.1   chopps 
    395      1.1   chopps 		pa = kvtop(ptr);
    396      1.1   chopps 		prelen = ((int)ptr & 0x03);
    397      1.1   chopps 
    398      1.1   chopps 		if (prelen) {
    399      1.1   chopps 			prelen = 4-prelen;
    400      1.1   chopps 			set_link(n, (vm_offset_t)ptr, prelen, SFAS_CHAIN_BUMP);
    401      1.1   chopps 			ptr += prelen;
    402      1.1   chopps 			len -= prelen;
    403      1.1   chopps 		}
    404      1.1   chopps 
    405      1.1   chopps 		lastpa = 0;
    406      1.1   chopps 		while(len > 3) {
    407      1.1   chopps 			pa = kvtop(ptr);
    408      1.1   chopps 			max_t = NBPG - (pa & PGOFSET);
    409      1.1   chopps 			if (max_t > len)
    410      1.1   chopps 			  max_t = len;
    411      1.1   chopps 
    412      1.1   chopps 			max_t &= ~3;
    413      1.1   chopps 
    414      1.1   chopps 			if (lastpa == pa)
    415      1.1   chopps 				sc->sc_chain[n-1].len += max_t;
    416      1.1   chopps 			else
    417      1.1   chopps 				set_link(n, pa, max_t, SFAS_CHAIN_DMA);
    418      1.1   chopps 
    419      1.1   chopps 			lastpa = pa+max_t;
    420      1.1   chopps 
    421      1.1   chopps 			ptr += max_t;
    422      1.1   chopps 			len -= max_t;
    423      1.1   chopps 		}
    424      1.1   chopps 
    425      1.1   chopps 		if (len)
    426      1.1   chopps 			set_link(n, (vm_offset_t)ptr, len, SFAS_CHAIN_BUMP);
    427      1.1   chopps 	}
    428      1.1   chopps 
    429      1.1   chopps 	return(n);
    430      1.1   chopps }
    431      1.1   chopps 
    432      1.1   chopps /* Turn on/off led */
    433      1.1   chopps void
    434      1.1   chopps flsc_led(sc, mode)
    435      1.1   chopps 	struct sfas_softc *sc;
    436      1.1   chopps 	int		  mode;
    437      1.1   chopps {
    438      1.1   chopps 	struct flsc_specific   *spec;
    439      1.1   chopps 	flsc_regmap_p		rp;
    440      1.1   chopps 
    441      1.1   chopps 	spec = sc->sc_spec;
    442      1.1   chopps 	rp = (flsc_regmap_p)sc->sc_fas;
    443      1.1   chopps 
    444      1.1   chopps 	if (mode) {
    445      1.1   chopps 		sc->sc_led_status++;
    446      1.1   chopps 
    447      1.1   chopps 		spec->portbits |= FLSC_PB_LED;
    448      1.1   chopps 		*rp->hardbits = spec->portbits;
    449      1.1   chopps 	} else {
    450      1.1   chopps 		if (sc->sc_led_status)
    451      1.1   chopps 			sc->sc_led_status--;
    452      1.1   chopps 
    453      1.1   chopps 		if (!sc->sc_led_status) {
    454      1.1   chopps 			spec->portbits &= ~FLSC_PB_LED;
    455      1.1   chopps 			*rp->hardbits = spec->portbits;
    456      1.1   chopps 		}
    457      1.1   chopps 	}
    458      1.1   chopps }
    459