1/*
2 * Sun3 SCSI stuff by Erik Verbruggen (erik@bigmama.xtdnet.nl)
3 *
4 * Sun3 DMA additions by Sam Creasey (sammy@sammy.net)
5 *
6 * Adapted from mac_scsinew.h:
7 */
8/*
9 * Cumana Generic NCR5380 driver defines
10 *
11 * Copyright 1993, Drew Eckhardt
12 *	Visionary Computing
13 *	(Unix and Linux consulting and custom programming)
14 *	drew@colorado.edu
15 *      +1 (303) 440-4894
16 *
17 * ALPHA RELEASE 1.
18 *
19 * For more information, please consult
20 *
21 * NCR 5380 Family
22 * SCSI Protocol Controller
23 * Databook
24 *
25 * NCR Microelectronics
26 * 1635 Aeroplaza Drive
27 * Colorado Springs, CO 80916
28 * 1+ (719) 578-3400
29 * 1+ (800) 334-5454
30 */
31
32/*
33 * $Log: sun3_scsi.h,v $
34 * Revision 1.1.1.1  2007/08/03 18:52:57  rnuti
35 * Importing Linux MIPS Kernel 2.6.22
36 *
37 */
38
39#ifndef SUN3_NCR5380_H
40#define SUN3_NCR5380_H
41
42#define SUN3SCSI_PUBLIC_RELEASE 1
43
44/*
45 * Int: level 2 autovector
46 * IO: type 1, base 0x00140000, 5 bits phys space: A<4..0>
47 */
48#define IRQ_SUN3_SCSI 2
49#define IOBASE_SUN3_SCSI 0x00140000
50
51#define IOBASE_SUN3_VMESCSI 0xff200000
52
53static int sun3scsi_abort(struct scsi_cmnd *);
54static int sun3scsi_detect (struct scsi_host_template *);
55static const char *sun3scsi_info (struct Scsi_Host *);
56static int sun3scsi_bus_reset(struct scsi_cmnd *);
57static int sun3scsi_queue_command(struct scsi_cmnd *,
58				  void (*done)(struct scsi_cmnd *));
59static int sun3scsi_release (struct Scsi_Host *);
60
61#ifndef CMD_PER_LUN
62#define CMD_PER_LUN 2
63#endif
64
65#ifndef CAN_QUEUE
66#define CAN_QUEUE 16
67#endif
68
69#ifndef SG_TABLESIZE
70#define SG_TABLESIZE SG_NONE
71#endif
72
73#ifndef MAX_TAGS
74#define MAX_TAGS 32
75#endif
76
77#ifndef USE_TAGGED_QUEUING
78#define	USE_TAGGED_QUEUING 1
79#endif
80
81#include <scsi/scsicam.h>
82
83#ifdef SUN3_SCSI_VME
84#define SUN3_SCSI_NAME "Sun3 NCR5380 VME SCSI"
85#else
86#define SUN3_SCSI_NAME "Sun3 NCR5380 SCSI"
87#endif
88
89#ifndef HOSTS_C
90
91#define NCR5380_implementation_fields \
92    int port, ctrl
93
94#define NCR5380_local_declare() \
95        struct Scsi_Host *_instance
96
97#define NCR5380_setup(instance) \
98        _instance = instance
99
100#define NCR5380_read(reg) sun3scsi_read(reg)
101#define NCR5380_write(reg, value) sun3scsi_write(reg, value)
102
103#define NCR5380_intr sun3scsi_intr
104#define NCR5380_queue_command sun3scsi_queue_command
105#define NCR5380_bus_reset sun3scsi_bus_reset
106#define NCR5380_abort sun3scsi_abort
107#define NCR5380_proc_info sun3scsi_proc_info
108#define NCR5380_dma_xfer_len(i, cmd, phase) \
109        sun3scsi_dma_xfer_len(cmd->SCp.this_residual,cmd,((phase) & SR_IO) ? 0 : 1)
110
111#define NCR5380_dma_write_setup(instance, data, count) sun3scsi_dma_setup(data, count, 1)
112#define NCR5380_dma_read_setup(instance, data, count) sun3scsi_dma_setup(data, count, 0)
113#define NCR5380_dma_residual sun3scsi_dma_residual
114
115#define BOARD_NORMAL	0
116#define BOARD_NCR53C400	1
117
118/* additional registers - mainly DMA control regs */
119/* these start at regbase + 8 -- directly after the NCR regs */
120struct sun3_dma_regs {
121	unsigned short dma_addr_hi; /* vme only */
122	unsigned short dma_addr_lo; /* vme only */
123	unsigned short dma_count_hi; /* vme only */
124	unsigned short dma_count_lo; /* vme only */
125	unsigned short udc_data; /* udc dma data reg (obio only) */
126	unsigned short udc_addr; /* uda dma addr reg (obio only) */
127	unsigned short fifo_data; /* fifo data reg, holds extra byte on
128				     odd dma reads */
129	unsigned short fifo_count;
130	unsigned short csr; /* control/status reg */
131	unsigned short bpack_hi; /* vme only */
132	unsigned short bpack_lo; /* vme only */
133	unsigned short ivect; /* vme only */
134	unsigned short fifo_count_hi; /* vme only */
135};
136
137/* ucd chip specific regs - live in dvma space */
138struct sun3_udc_regs {
139     unsigned short rsel; /* select regs to load */
140     unsigned short addr_hi; /* high word of addr */
141     unsigned short addr_lo; /* low word */
142     unsigned short count; /* words to be xfer'd */
143     unsigned short mode_hi; /* high word of channel mode */
144     unsigned short mode_lo; /* low word of channel mode */
145};
146
147/* addresses of the udc registers */
148#define UDC_MODE 0x38
149#define UDC_CSR 0x2e /* command/status */
150#define UDC_CHN_HI 0x26 /* chain high word */
151#define UDC_CHN_LO 0x22 /* chain lo word */
152#define UDC_CURA_HI 0x1a /* cur reg A high */
153#define UDC_CURA_LO 0x0a /* cur reg A low */
154#define UDC_CURB_HI 0x12 /* cur reg B high */
155#define UDC_CURB_LO 0x02 /* cur reg B low */
156#define UDC_MODE_HI 0x56 /* mode reg high */
157#define UDC_MODE_LO 0x52 /* mode reg low */
158#define UDC_COUNT 0x32 /* words to xfer */
159
160/* some udc commands */
161#define UDC_RESET 0
162#define UDC_CHN_START 0xa0 /* start chain */
163#define UDC_INT_ENABLE 0x32 /* channel 1 int on */
164
165/* udc mode words */
166#define UDC_MODE_HIWORD 0x40
167#define UDC_MODE_LSEND 0xc2
168#define UDC_MODE_LRECV 0xd2
169
170/* udc reg selections */
171#define UDC_RSEL_SEND 0x282
172#define UDC_RSEL_RECV 0x182
173
174/* bits in csr reg */
175#define CSR_DMA_ACTIVE 0x8000
176#define CSR_DMA_CONFLICT 0x4000
177#define CSR_DMA_BUSERR 0x2000
178
179#define CSR_FIFO_EMPTY 0x400 /* fifo flushed? */
180#define CSR_SDB_INT 0x200 /* sbc interrupt pending */
181#define CSR_DMA_INT 0x100 /* dma interrupt pending */
182
183#define CSR_LEFT 0xc0
184#define CSR_LEFT_3 0xc0
185#define CSR_LEFT_2 0x80
186#define CSR_LEFT_1 0x40
187#define CSR_PACK_ENABLE 0x20
188
189#define CSR_DMA_ENABLE 0x10
190
191#define CSR_SEND 0x8 /* 1 = send  0 = recv */
192#define CSR_FIFO 0x2 /* reset fifo */
193#define CSR_INTR 0x4 /* interrupt enable */
194#define CSR_SCSI 0x1
195
196#define VME_DATA24 0x3d00
197
198// debugging printk's, taken from atari_scsi.h
199/* Debugging printk definitions:
200 *
201 *  ARB  -> arbitration
202 *  ASEN -> auto-sense
203 *  DMA  -> DMA
204 *  HSH  -> PIO handshake
205 *  INF  -> information transfer
206 *  INI  -> initialization
207 *  INT  -> interrupt
208 *  LNK  -> linked commands
209 *  MAIN -> NCR5380_main() control flow
210 *  NDAT -> no data-out phase
211 *  NWR  -> no write commands
212 *  PIO  -> PIO transfers
213 *  PDMA -> pseudo DMA (unused on Atari)
214 *  QU   -> queues
215 *  RSL  -> reselections
216 *  SEL  -> selections
217 *  USL  -> usleep cpde (unused on Atari)
218 *  LBS  -> last byte sent (unused on Atari)
219 *  RSS  -> restarting of selections
220 *  EXT  -> extended messages
221 *  ABRT -> aborting and resetting
222 *  TAG  -> queue tag handling
223 *  MER  -> merging of consec. buffers
224 *
225 */
226
227#include "NCR5380.h"
228
229#if NDEBUG & NDEBUG_ARBITRATION
230#define ARB_PRINTK(format, args...) \
231	printk(KERN_DEBUG format , ## args)
232#else
233#define ARB_PRINTK(format, args...)
234#endif
235#if NDEBUG & NDEBUG_AUTOSENSE
236#define ASEN_PRINTK(format, args...) \
237	printk(KERN_DEBUG format , ## args)
238#else
239#define ASEN_PRINTK(format, args...)
240#endif
241#if NDEBUG & NDEBUG_DMA
242#define DMA_PRINTK(format, args...) \
243	printk(KERN_DEBUG format , ## args)
244#else
245#define DMA_PRINTK(format, args...)
246#endif
247#if NDEBUG & NDEBUG_HANDSHAKE
248#define HSH_PRINTK(format, args...) \
249	printk(KERN_DEBUG format , ## args)
250#else
251#define HSH_PRINTK(format, args...)
252#endif
253#if NDEBUG & NDEBUG_INFORMATION
254#define INF_PRINTK(format, args...) \
255	printk(KERN_DEBUG format , ## args)
256#else
257#define INF_PRINTK(format, args...)
258#endif
259#if NDEBUG & NDEBUG_INIT
260#define INI_PRINTK(format, args...) \
261	printk(KERN_DEBUG format , ## args)
262#else
263#define INI_PRINTK(format, args...)
264#endif
265#if NDEBUG & NDEBUG_INTR
266#define INT_PRINTK(format, args...) \
267	printk(KERN_DEBUG format , ## args)
268#else
269#define INT_PRINTK(format, args...)
270#endif
271#if NDEBUG & NDEBUG_LINKED
272#define LNK_PRINTK(format, args...) \
273	printk(KERN_DEBUG format , ## args)
274#else
275#define LNK_PRINTK(format, args...)
276#endif
277#if NDEBUG & NDEBUG_MAIN
278#define MAIN_PRINTK(format, args...) \
279	printk(KERN_DEBUG format , ## args)
280#else
281#define MAIN_PRINTK(format, args...)
282#endif
283#if NDEBUG & NDEBUG_NO_DATAOUT
284#define NDAT_PRINTK(format, args...) \
285	printk(KERN_DEBUG format , ## args)
286#else
287#define NDAT_PRINTK(format, args...)
288#endif
289#if NDEBUG & NDEBUG_NO_WRITE
290#define NWR_PRINTK(format, args...) \
291	printk(KERN_DEBUG format , ## args)
292#else
293#define NWR_PRINTK(format, args...)
294#endif
295#if NDEBUG & NDEBUG_PIO
296#define PIO_PRINTK(format, args...) \
297	printk(KERN_DEBUG format , ## args)
298#else
299#define PIO_PRINTK(format, args...)
300#endif
301#if NDEBUG & NDEBUG_PSEUDO_DMA
302#define PDMA_PRINTK(format, args...) \
303	printk(KERN_DEBUG format , ## args)
304#else
305#define PDMA_PRINTK(format, args...)
306#endif
307#if NDEBUG & NDEBUG_QUEUES
308#define QU_PRINTK(format, args...) \
309	printk(KERN_DEBUG format , ## args)
310#else
311#define QU_PRINTK(format, args...)
312#endif
313#if NDEBUG & NDEBUG_RESELECTION
314#define RSL_PRINTK(format, args...) \
315	printk(KERN_DEBUG format , ## args)
316#else
317#define RSL_PRINTK(format, args...)
318#endif
319#if NDEBUG & NDEBUG_SELECTION
320#define SEL_PRINTK(format, args...) \
321	printk(KERN_DEBUG format , ## args)
322#else
323#define SEL_PRINTK(format, args...)
324#endif
325#if NDEBUG & NDEBUG_USLEEP
326#define USL_PRINTK(format, args...) \
327	printk(KERN_DEBUG format , ## args)
328#else
329#define USL_PRINTK(format, args...)
330#endif
331#if NDEBUG & NDEBUG_LAST_BYTE_SENT
332#define LBS_PRINTK(format, args...) \
333	printk(KERN_DEBUG format , ## args)
334#else
335#define LBS_PRINTK(format, args...)
336#endif
337#if NDEBUG & NDEBUG_RESTART_SELECT
338#define RSS_PRINTK(format, args...) \
339	printk(KERN_DEBUG format , ## args)
340#else
341#define RSS_PRINTK(format, args...)
342#endif
343#if NDEBUG & NDEBUG_EXTENDED
344#define EXT_PRINTK(format, args...) \
345	printk(KERN_DEBUG format , ## args)
346#else
347#define EXT_PRINTK(format, args...)
348#endif
349#if NDEBUG & NDEBUG_ABORT
350#define ABRT_PRINTK(format, args...) \
351	printk(KERN_DEBUG format , ## args)
352#else
353#define ABRT_PRINTK(format, args...)
354#endif
355#if NDEBUG & NDEBUG_TAGS
356#define TAG_PRINTK(format, args...) \
357	printk(KERN_DEBUG format , ## args)
358#else
359#define TAG_PRINTK(format, args...)
360#endif
361#if NDEBUG & NDEBUG_MERGING
362#define MER_PRINTK(format, args...) \
363	printk(KERN_DEBUG format , ## args)
364#else
365#define MER_PRINTK(format, args...)
366#endif
367
368/* conditional macros for NCR5380_print_{,phase,status} */
369
370#define NCR_PRINT(mask)	\
371	((NDEBUG & (mask)) ? NCR5380_print(instance) : (void)0)
372
373#define NCR_PRINT_PHASE(mask) \
374	((NDEBUG & (mask)) ? NCR5380_print_phase(instance) : (void)0)
375
376#define NCR_PRINT_STATUS(mask) \
377	((NDEBUG & (mask)) ? NCR5380_print_status(instance) : (void)0)
378
379
380
381#endif /* ndef HOSTS_C */
382#endif /* SUN3_NCR5380_H */
383