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