Home | History | Annotate | Line # | Download | only in ic
      1  1.5  christos #	$NetBSD: ncr5380.doc,v 1.5 2005/12/11 12:21:28 christos Exp $
      2  1.2     perry 
      3  1.1   thorpej MI 5380 driver
      4  1.1   thorpej ==============
      5  1.1   thorpej 
      6  1.1   thorpej (What?  Documentation?  Is this guy nuts? :-)
      7  1.1   thorpej 
      8  1.1   thorpej Reselection
      9  1.1   thorpej -----------
     10  1.1   thorpej 
     11  1.1   thorpej This driver will permit reselection on non-polled commands if
     12  1.1   thorpej sc->sc_flags & NCR5380_PERMIT_RESELECT is 1.  This permits enabling of
     13  1.1   thorpej reselection on a per-device basis.
     14  1.1   thorpej 
     15  1.1   thorpej Disconnect/reselect is never permitted for polled commands.
     16  1.1   thorpej 
     17  1.1   thorpej 
     18  1.1   thorpej 
     19  1.1   thorpej Interfacing the driver to MD code
     20  1.1   thorpej ---------------------------------
     21  1.1   thorpej 
     22  1.1   thorpej /sys/dev/ic/ncr5380.c is now stand-alone.  DON'T include it after your
     23  1.1   thorpej MD stuff!
     24  1.1   thorpej 
     25  1.1   thorpej This allows for more than one 5380-based SCSI board in your system.  This is
     26  1.1   thorpej a real possibility for Amiga generic kernels.
     27  1.1   thorpej 
     28  1.1   thorpej Your driver's softc structure must have an instance of struct ncr5380_softc
     29  1.1   thorpej as the first thing in the structure.  The MD code must initialize the
     30  1.1   thorpej following:
     31  1.1   thorpej 
     32  1.1   thorpej sci_*: pointers to the 5380 registers.  All accesses are done through
     33  1.1   thorpej   these pointers.  This indirection allows the driver to work with
     34  1.1   thorpej   boards that map the 5380 on even addresses only or do other
     35  1.3       wiz   weirdnesses.
     36  1.1   thorpej 
     37  1.1   thorpej int (*sc_pio_out)(sc, phase, datalen, data)
     38  1.1   thorpej int (*sc_pio_in)(sc, phase, datalen, data)
     39  1.1   thorpej   These point to functions that do programmed I/O transfers to the bus and
     40  1.1   thorpej   from the bus, respectively.  Arguments:
     41  1.1   thorpej 
     42  1.1   thorpej   sc            points to the softc
     43  1.1   thorpej   phase         the current SCSI bus phase
     44  1.1   thorpej   datalen       length of data to transfer
     45  1.1   thorpej   data          pointer to the buffer
     46  1.1   thorpej 
     47  1.1   thorpej   Both functions must return the number of bytes successfully transferred.
     48  1.1   thorpej   A transfer operation must be aborted if the target requests a different
     49  1.1   thorpej   phase before the transfer completes.
     50  1.1   thorpej 
     51  1.1   thorpej   If you have no special requirements, you can point these to
     52  1.1   thorpej   ncr5380_pio_out() and ncr5380_pio_in() respectively.  If your board
     53  1.1   thorpej   can do pseudo-DMA, then you might want to point these to functions
     54  1.1   thorpej   that use this feature.
     55  1.1   thorpej 
     56  1.1   thorpej void (*sc_dma_alloc)(sc)
     57  1.1   thorpej   This function is called to set up a DMA transfer.  You must create and
     58  1.1   thorpej   return a "DMA handle" in sc->sc_dma_hand which identifies the DMA transfer.
     59  1.1   thorpej   The driver will pass you your DMA handle in sc->sc_dma_hand for future
     60  1.1   thorpej   operations.  The contents of the DMA handle are immaterial to the MI
     61  1.1   thorpej   code - the DMA handle is for your bookkeeping only.  Usually, you
     62  1.1   thorpej   create a structure and point to it here.
     63  1.1   thorpej 
     64  1.1   thorpej   For example, you can record the mapped and unmapped addresses of the
     65  1.1   thorpej   buffer.  The Sun driver places an Am9516 UDC control block in the DMA
     66  1.1   thorpej   handle.
     67  1.1   thorpej 
     68  1.1   thorpej   If for some reason you decide not to do DMA for the transfer, make
     69  1.1   thorpej   sc->sc_dma_hand NULL.  This might happen if the proposed transfer is
     70  1.1   thorpej   misaligned, or in the wrong type of memory, or...
     71  1.1   thorpej 
     72  1.1   thorpej void (*sc_dma_start)(sc)
     73  1.1   thorpej   This function starts the transfer.
     74  1.1   thorpej 
     75  1.1   thorpej void (*sc_dma_stop)(sc)
     76  1.1   thorpej   This function stops a transfer.  sc->sc_datalen and sc->sc_dataptr must
     77  1.1   thorpej   be updated to reflect the portion of the DMA already done.
     78  1.1   thorpej 
     79  1.1   thorpej void (*sc_dma_eop)(sc)
     80  1.1   thorpej   This function is called when the 5380 signals EOP.  Either continue
     81  1.1   thorpej   the DMA or stop the DMA.
     82  1.1   thorpej 
     83  1.1   thorpej void (*sc_dma_free)(sc)
     84  1.1   thorpej   This function frees the current DMA handle.
     85  1.1   thorpej 
     86  1.1   thorpej u_char *sc_dataptr;
     87  1.1   thorpej int sc_datalen;
     88  1.1   thorpej   These variables form the active SCSI data pointer.  DMA code must start
     89  1.1   thorpej   DMA at the location given, and update the pointer/length in response to
     90  1.1   thorpej   DMA operations.
     91  1.1   thorpej 
     92  1.1   thorpej u_short sc_dma_flags;
     93  1.1   thorpej   See ncr5380var.h
     94  1.1   thorpej 
     95  1.1   thorpej 
     96  1.1   thorpej 
     97  1.1   thorpej Writing your DMA code
     98  1.1   thorpej ---------------------
     99  1.1   thorpej 
    100  1.1   thorpej DMA on a system with protected or virtual memory is always a problem.  Even
    101  1.1   thorpej though a disk transfer may be logically contiguous, the physical pages backing
    102  1.1   thorpej the transfer may not be.  There are two common solutions to this problem:
    103  1.1   thorpej 
    104  1.1   thorpej DMA chains: the DMA is broken up into a list of contiguous segments.  The first
    105  1.1   thorpej segment is submitted to the DMA controller, and when it completes, the second
    106  1.1   thorpej segment is submitted, without stopping the 5380.  This is what the sc_dma_eop()
    107  1.1   thorpej function can do efficiently - if you have a DMA chain, it can quickly load up
    108  1.1   thorpej the next link in the chain.  The sc_dma_alloc() function builds the chain and
    109  1.1   thorpej sc_dma_free() releases any resources you used to build it.
    110  1.1   thorpej 
    111  1.1   thorpej DVMA: Direct Virtual Memory Access.  In this scheme, DMA requests go through
    112  1.1   thorpej the MMU.  Although you can't page fault, you can program the MMU to remap
    113  1.1   thorpej things so the DMA controller sees contiguous data.  In this mode, sc_dma_alloc()
    114  1.1   thorpej is used to map the transfer into the address space reserved for DVMA and
    115  1.1   thorpej sc_dma_free() is used to unmap it.
    116  1.1   thorpej 
    117  1.1   thorpej 
    118  1.1   thorpej Interrupts
    119  1.1   thorpej ----------
    120  1.1   thorpej 
    121  1.1   thorpej ncr5380_sbc_intr() must be called when the 5380 interrupts the host.
    122  1.1   thorpej 
    123  1.1   thorpej You must write an interrupt routine pretty much from scratch to check for
    124  1.1   thorpej things generated by MD hardware.
    125  1.1   thorpej 
    126  1.1   thorpej 
    127  1.1   thorpej Known problems
    128  1.1   thorpej --------------
    129  1.1   thorpej 
    130  1.1   thorpej I'm getting this out now so that other ports can hack on it and integrate it.
    131  1.1   thorpej 
    132  1.1   thorpej The sun3, DMA/Interrupt appears to be working now, but needs testing.
    133  1.1   thorpej 
    134  1.1   thorpej Polled commands submitted while non-polled commands are in progress are not
    135  1.1   thorpej handled correctly.  This can happen if reselection is enabled and a new disk
    136  1.4     perry is mounted while an I/O is in progress on another disk.
    137  1.1   thorpej 
    138  1.1   thorpej The problem is: what to do if you get reselected while doing the selection
    139  1.1   thorpej for the polled command?  Currently, the driver busy waits for the non-polled
    140  1.1   thorpej command to complete, but this is bogus.  I need to complete the non-polled
    141  1.1   thorpej command in polled mode, then do the polled command.
    142  1.1   thorpej 
    143  1.1   thorpej 
    144  1.1   thorpej Timeouts in the driver are EXTREMELY sensitive to the characteristics of the
    145  1.1   thorpej local implementation of delay().  The Sun3 version delays for a minimum of 5us.
    146  1.1   thorpej However, the driver must assume that delay(1) will delay only 1us.  For this
    147  1.1   thorpej reason, performance on the Sun3 sucks in some places.
    148  1.1   thorpej 
    149