2e1d89f5de35756662feade7e7f2d93f50809adb
[linux-2.6.git] / drivers / scsi / sym53c8xx_2 / sym_defs.h
1 /*
2  * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family 
3  * of PCI-SCSI IO processors.
4  *
5  * Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
6  *
7  * This driver is derived from the Linux sym53c8xx driver.
8  * Copyright (C) 1998-2000  Gerard Roudier
9  *
10  * The sym53c8xx driver is derived from the ncr53c8xx driver that had been 
11  * a port of the FreeBSD ncr driver to Linux-1.2.13.
12  *
13  * The original ncr driver has been written for 386bsd and FreeBSD by
14  *         Wolfgang Stanglmeier        <wolf@cologne.de>
15  *         Stefan Esser                <se@mi.Uni-Koeln.de>
16  * Copyright (C) 1994  Wolfgang Stanglmeier
17  *
18  * Other major contributions:
19  *
20  * NVRAM detection and reading.
21  * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
22  *
23  *-----------------------------------------------------------------------------
24  *
25  * This program is free software; you can redistribute it and/or modify
26  * it under the terms of the GNU General Public License as published by
27  * the Free Software Foundation; either version 2 of the License, or
28  * (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License
36  * along with this program; if not, write to the Free Software
37  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38  */
39
40 #ifndef SYM_DEFS_H
41 #define SYM_DEFS_H
42
43 #define SYM_VERSION "2.1.18m"
44 #define SYM_DRIVER_NAME "sym-" SYM_VERSION
45
46 /*
47  *  PCI device identifier of SYMBIOS chips.
48  */
49 #define PCI_ID_SYM53C810        PCI_DEVICE_ID_NCR_53C810
50 #define PCI_ID_SYM53C810AP      PCI_DEVICE_ID_LSI_53C810AP
51 #define PCI_ID_SYM53C815        PCI_DEVICE_ID_NCR_53C815
52 #define PCI_ID_SYM53C820        PCI_DEVICE_ID_NCR_53C820
53 #define PCI_ID_SYM53C825        PCI_DEVICE_ID_NCR_53C825
54 #define PCI_ID_SYM53C860        PCI_DEVICE_ID_NCR_53C860
55 #define PCI_ID_SYM53C875        PCI_DEVICE_ID_NCR_53C875
56 #define PCI_ID_SYM53C875_2      PCI_DEVICE_ID_NCR_53C875J
57 #define PCI_ID_SYM53C885        PCI_DEVICE_ID_NCR_53C885
58 #define PCI_ID_SYM53C895        PCI_DEVICE_ID_NCR_53C895
59 #define PCI_ID_SYM53C896        PCI_DEVICE_ID_NCR_53C896
60 #define PCI_ID_SYM53C895A       PCI_DEVICE_ID_LSI_53C895A
61 #define PCI_ID_SYM53C875A       PCI_DEVICE_ID_LSI_53C875A
62 #define PCI_ID_LSI53C1010_33    PCI_DEVICE_ID_LSI_53C1010_33
63 #define PCI_ID_LSI53C1010_66    PCI_DEVICE_ID_LSI_53C1010_66
64 #define PCI_ID_LSI53C1510D      PCI_DEVICE_ID_LSI_53C1510
65
66 /*
67  *      SYM53C8XX device features descriptor.
68  */
69 struct sym_pci_chip {
70         u_short device_id;
71         u_short revision_id;
72         char    *name;
73         u_char  burst_max;      /* log-base-2 of max burst */
74         u_char  offset_max;
75         u_char  nr_divisor;
76         u_char  lp_probe_bit;
77         u_int   features;
78 #define FE_LED0         (1<<0)
79 #define FE_WIDE         (1<<1)    /* Wide data transfers */
80 #define FE_ULTRA        (1<<2)    /* Ultra speed 20Mtrans/sec */
81 #define FE_ULTRA2       (1<<3)    /* Ultra 2 - 40 Mtrans/sec */
82 #define FE_DBLR         (1<<4)    /* Clock doubler present */
83 #define FE_QUAD         (1<<5)    /* Clock quadrupler present */
84 #define FE_ERL          (1<<6)    /* Enable read line */
85 #define FE_CLSE         (1<<7)    /* Cache line size enable */
86 #define FE_WRIE         (1<<8)    /* Write & Invalidate enable */
87 #define FE_ERMP         (1<<9)    /* Enable read multiple */
88 #define FE_BOF          (1<<10)   /* Burst opcode fetch */
89 #define FE_DFS          (1<<11)   /* DMA fifo size */
90 #define FE_PFEN         (1<<12)   /* Prefetch enable */
91 #define FE_LDSTR        (1<<13)   /* Load/Store supported */
92 #define FE_RAM          (1<<14)   /* On chip RAM present */
93 #define FE_VARCLK       (1<<15)   /* Clock frequency may vary */
94 #define FE_RAM8K        (1<<16)   /* On chip RAM sized 8Kb */
95 #define FE_64BIT        (1<<17)   /* 64-bit PCI BUS interface */
96 #define FE_IO256        (1<<18)   /* Requires full 256 bytes in PCI space */
97 #define FE_NOPM         (1<<19)   /* Scripts handles phase mismatch */
98 #define FE_LEDC         (1<<20)   /* Hardware control of LED */
99 #define FE_ULTRA3       (1<<21)   /* Ultra 3 - 80 Mtrans/sec DT */
100 #define FE_66MHZ        (1<<22)   /* 66MHz PCI support */
101 #define FE_CRC          (1<<23)   /* CRC support */
102 #define FE_DIFF         (1<<24)   /* SCSI HVD support */
103 #define FE_DFBC         (1<<25)   /* Have DFBC register */
104 #define FE_LCKFRQ       (1<<26)   /* Have LCKFRQ */
105 #define FE_C10          (1<<27)   /* Various C10 core (mis)features */
106 #define FE_U3EN         (1<<28)   /* U3EN bit usable */
107 #define FE_DAC          (1<<29)   /* Support PCI DAC (64 bit addressing) */
108 #define FE_ISTAT1       (1<<30)   /* Have ISTAT1, MBOX0, MBOX1 registers */
109
110 #define FE_CACHE_SET    (FE_ERL|FE_CLSE|FE_WRIE|FE_ERMP)
111 #define FE_CACHE0_SET   (FE_CACHE_SET & ~FE_ERL)
112 };
113
114 /*
115  *      SYM53C8XX IO register data structure.
116  */
117 struct sym_reg {
118 /*00*/  u8      nc_scntl0;      /* full arb., ena parity, par->ATN  */
119
120 /*01*/  u8      nc_scntl1;      /* no reset                         */
121         #define   ISCON   0x10  /* connected to scsi                */
122         #define   CRST    0x08  /* force reset                      */
123         #define   IARB    0x02  /* immediate arbitration            */
124
125 /*02*/  u8      nc_scntl2;      /* no disconnect expected           */
126         #define   SDU     0x80  /* cmd: disconnect will raise error */
127         #define   CHM     0x40  /* sta: chained mode                */
128         #define   WSS     0x08  /* sta: wide scsi send           [W]*/
129         #define   WSR     0x01  /* sta: wide scsi received       [W]*/
130
131 /*03*/  u8      nc_scntl3;      /* cnf system clock dependent       */
132         #define   EWS     0x08  /* cmd: enable wide scsi         [W]*/
133         #define   ULTRA   0x80  /* cmd: ULTRA enable                */
134                                 /* bits 0-2, 7 rsvd for C1010       */
135
136 /*04*/  u8      nc_scid;        /* cnf host adapter scsi address    */
137         #define   RRE     0x40  /* r/w:e enable response to resel.  */
138         #define   SRE     0x20  /* r/w:e enable response to select  */
139
140 /*05*/  u8      nc_sxfer;       /* ### Sync speed and count         */
141                                 /* bits 6-7 rsvd for C1010          */
142
143 /*06*/  u8      nc_sdid;        /* ### Destination-ID               */
144
145 /*07*/  u8      nc_gpreg;       /* ??? IO-Pins                      */
146
147 /*08*/  u8      nc_sfbr;        /* ### First byte received          */
148
149 /*09*/  u8      nc_socl;
150         #define   CREQ    0x80  /* r/w: SCSI-REQ                    */
151         #define   CACK    0x40  /* r/w: SCSI-ACK                    */
152         #define   CBSY    0x20  /* r/w: SCSI-BSY                    */
153         #define   CSEL    0x10  /* r/w: SCSI-SEL                    */
154         #define   CATN    0x08  /* r/w: SCSI-ATN                    */
155         #define   CMSG    0x04  /* r/w: SCSI-MSG                    */
156         #define   CC_D    0x02  /* r/w: SCSI-C_D                    */
157         #define   CI_O    0x01  /* r/w: SCSI-I_O                    */
158
159 /*0a*/  u8      nc_ssid;
160
161 /*0b*/  u8      nc_sbcl;
162
163 /*0c*/  u8      nc_dstat;
164         #define   DFE     0x80  /* sta: dma fifo empty              */
165         #define   MDPE    0x40  /* int: master data parity error    */
166         #define   BF      0x20  /* int: script: bus fault           */
167         #define   ABRT    0x10  /* int: script: command aborted     */
168         #define   SSI     0x08  /* int: script: single step         */
169         #define   SIR     0x04  /* int: script: interrupt instruct. */
170         #define   IID     0x01  /* int: script: illegal instruct.   */
171
172 /*0d*/  u8      nc_sstat0;
173         #define   ILF     0x80  /* sta: data in SIDL register lsb   */
174         #define   ORF     0x40  /* sta: data in SODR register lsb   */
175         #define   OLF     0x20  /* sta: data in SODL register lsb   */
176         #define   AIP     0x10  /* sta: arbitration in progress     */
177         #define   LOA     0x08  /* sta: arbitration lost            */
178         #define   WOA     0x04  /* sta: arbitration won             */
179         #define   IRST    0x02  /* sta: scsi reset signal           */
180         #define   SDP     0x01  /* sta: scsi parity signal          */
181
182 /*0e*/  u8      nc_sstat1;
183         #define   FF3210  0xf0  /* sta: bytes in the scsi fifo      */
184
185 /*0f*/  u8      nc_sstat2;
186         #define   ILF1    0x80  /* sta: data in SIDL register msb[W]*/
187         #define   ORF1    0x40  /* sta: data in SODR register msb[W]*/
188         #define   OLF1    0x20  /* sta: data in SODL register msb[W]*/
189         #define   DM      0x04  /* sta: DIFFSENS mismatch (895/6 only) */
190         #define   LDSC    0x02  /* sta: disconnect & reconnect      */
191
192 /*10*/  u8      nc_dsa;         /* --> Base page                    */
193 /*11*/  u8      nc_dsa1;
194 /*12*/  u8      nc_dsa2;
195 /*13*/  u8      nc_dsa3;
196
197 /*14*/  u8      nc_istat;       /* --> Main Command and status      */
198         #define   CABRT   0x80  /* cmd: abort current operation     */
199         #define   SRST    0x40  /* mod: reset chip                  */
200         #define   SIGP    0x20  /* r/w: message from host to script */
201         #define   SEM     0x10  /* r/w: message between host + script  */
202         #define   CON     0x08  /* sta: connected to scsi           */
203         #define   INTF    0x04  /* sta: int on the fly (reset by wr)*/
204         #define   SIP     0x02  /* sta: scsi-interrupt              */
205         #define   DIP     0x01  /* sta: host/script interrupt       */
206
207 /*15*/  u8      nc_istat1;      /* 896 only */
208         #define   FLSH    0x04  /* sta: chip is flushing            */
209         #define   SCRUN   0x02  /* sta: scripts are running         */
210         #define   SIRQD   0x01  /* r/w: disable INT pin             */
211
212 /*16*/  u8      nc_mbox0;       /* 896 only */
213 /*17*/  u8      nc_mbox1;       /* 896 only */
214
215 /*18*/  u8      nc_ctest0;
216 /*19*/  u8      nc_ctest1;
217
218 /*1a*/  u8      nc_ctest2;
219         #define   CSIGP   0x40
220                                 /* bits 0-2,7 rsvd for C1010        */
221
222 /*1b*/  u8      nc_ctest3;
223         #define   FLF     0x08  /* cmd: flush dma fifo              */
224         #define   CLF     0x04  /* cmd: clear dma fifo              */
225         #define   FM      0x02  /* mod: fetch pin mode              */
226         #define   WRIE    0x01  /* mod: write and invalidate enable */
227                                 /* bits 4-7 rsvd for C1010          */
228
229 /*1c*/  u32     nc_temp;        /* ### Temporary stack              */
230
231 /*20*/  u8      nc_dfifo;
232 /*21*/  u8      nc_ctest4;
233         #define   BDIS    0x80  /* mod: burst disable               */
234         #define   MPEE    0x08  /* mod: master parity error enable  */
235
236 /*22*/  u8      nc_ctest5;
237         #define   DFS     0x20  /* mod: dma fifo size               */
238                                 /* bits 0-1, 3-7 rsvd for C1010     */
239
240 /*23*/  u8      nc_ctest6;
241
242 /*24*/  u32     nc_dbc;         /* ### Byte count and command       */
243 /*28*/  u32     nc_dnad;        /* ### Next command register        */
244 /*2c*/  u32     nc_dsp;         /* --> Script Pointer               */
245 /*30*/  u32     nc_dsps;        /* --> Script pointer save/opcode#2 */
246
247 /*34*/  u8      nc_scratcha;    /* Temporary register a            */
248 /*35*/  u8      nc_scratcha1;
249 /*36*/  u8      nc_scratcha2;
250 /*37*/  u8      nc_scratcha3;
251
252 /*38*/  u8      nc_dmode;
253         #define   BL_2    0x80  /* mod: burst length shift value +2 */
254         #define   BL_1    0x40  /* mod: burst length shift value +1 */
255         #define   ERL     0x08  /* mod: enable read line            */
256         #define   ERMP    0x04  /* mod: enable read multiple        */
257         #define   BOF     0x02  /* mod: burst op code fetch         */
258
259 /*39*/  u8      nc_dien;
260 /*3a*/  u8      nc_sbr;
261
262 /*3b*/  u8      nc_dcntl;       /* --> Script execution control     */
263         #define   CLSE    0x80  /* mod: cache line size enable      */
264         #define   PFF     0x40  /* cmd: pre-fetch flush             */
265         #define   PFEN    0x20  /* mod: pre-fetch enable            */
266         #define   SSM     0x10  /* mod: single step mode            */
267         #define   IRQM    0x08  /* mod: irq mode (1 = totem pole !) */
268         #define   STD     0x04  /* cmd: start dma mode              */
269         #define   IRQD    0x02  /* mod: irq disable                 */
270         #define   NOCOM   0x01  /* cmd: protect sfbr while reselect */
271                                 /* bits 0-1 rsvd for C1010          */
272
273 /*3c*/  u32     nc_adder;
274
275 /*40*/  u16     nc_sien;        /* -->: interrupt enable            */
276 /*42*/  u16     nc_sist;        /* <--: interrupt status            */
277         #define   SBMC    0x1000/* sta: SCSI Bus Mode Change (895/6 only) */
278         #define   STO     0x0400/* sta: timeout (select)            */
279         #define   GEN     0x0200/* sta: timeout (general)           */
280         #define   HTH     0x0100/* sta: timeout (handshake)         */
281         #define   MA      0x80  /* sta: phase mismatch              */
282         #define   CMP     0x40  /* sta: arbitration complete        */
283         #define   SEL     0x20  /* sta: selected by another device  */
284         #define   RSL     0x10  /* sta: reselected by another device*/
285         #define   SGE     0x08  /* sta: gross error (over/underflow)*/
286         #define   UDC     0x04  /* sta: unexpected disconnect       */
287         #define   RST     0x02  /* sta: scsi bus reset detected     */
288         #define   PAR     0x01  /* sta: scsi parity error           */
289
290 /*44*/  u8      nc_slpar;
291 /*45*/  u8      nc_swide;
292 /*46*/  u8      nc_macntl;
293 /*47*/  u8      nc_gpcntl;
294 /*48*/  u8      nc_stime0;      /* cmd: timeout for select&handshake*/
295 /*49*/  u8      nc_stime1;      /* cmd: timeout user defined        */
296 /*4a*/  u16     nc_respid;      /* sta: Reselect-IDs                */
297
298 /*4c*/  u8      nc_stest0;
299
300 /*4d*/  u8      nc_stest1;
301         #define   SCLK    0x80  /* Use the PCI clock as SCSI clock      */
302         #define   DBLEN   0x08  /* clock doubler running                */
303         #define   DBLSEL  0x04  /* clock doubler selected               */
304   
305
306 /*4e*/  u8      nc_stest2;
307         #define   ROF     0x40  /* reset scsi offset (after gross error!) */
308         #define   EXT     0x02  /* extended filtering                     */
309
310 /*4f*/  u8      nc_stest3;
311         #define   TE     0x80   /* c: tolerAnt enable */
312         #define   HSC    0x20   /* c: Halt SCSI Clock */
313         #define   CSF    0x02   /* c: clear scsi fifo */
314
315 /*50*/  u16     nc_sidl;        /* Lowlevel: latched from scsi data */
316 /*52*/  u8      nc_stest4;
317         #define   SMODE  0xc0   /* SCSI bus mode      (895/6 only) */
318         #define    SMODE_HVD 0x40       /* High Voltage Differential       */
319         #define    SMODE_SE  0x80       /* Single Ended                    */
320         #define    SMODE_LVD 0xc0       /* Low Voltage Differential        */
321         #define   LCKFRQ 0x20   /* Frequency Lock (895/6 only)     */
322                                 /* bits 0-5 rsvd for C1010         */
323
324 /*53*/  u8      nc_53_;
325 /*54*/  u16     nc_sodl;        /* Lowlevel: data out to scsi data  */
326 /*56*/  u8      nc_ccntl0;      /* Chip Control 0 (896)             */
327         #define   ENPMJ  0x80   /* Enable Phase Mismatch Jump       */
328         #define   PMJCTL 0x40   /* Phase Mismatch Jump Control      */
329         #define   ENNDJ  0x20   /* Enable Non Data PM Jump          */
330         #define   DISFC  0x10   /* Disable Auto FIFO Clear          */
331         #define   DILS   0x02   /* Disable Internal Load/Store      */
332         #define   DPR    0x01   /* Disable Pipe Req                 */
333
334 /*57*/  u8      nc_ccntl1;      /* Chip Control 1 (896)             */
335         #define   ZMOD   0x80   /* High Impedance Mode              */
336         #define   DDAC   0x08   /* Disable Dual Address Cycle       */
337         #define   XTIMOD 0x04   /* 64-bit Table Ind. Indexing Mode  */
338         #define   EXTIBMV 0x02  /* Enable 64-bit Table Ind. BMOV    */
339         #define   EXDBMV 0x01   /* Enable 64-bit Direct BMOV        */
340
341 /*58*/  u16     nc_sbdl;        /* Lowlevel: data from scsi data    */
342 /*5a*/  u16     nc_5a_;
343
344 /*5c*/  u8      nc_scr0;        /* Working register B               */
345 /*5d*/  u8      nc_scr1;
346 /*5e*/  u8      nc_scr2;
347 /*5f*/  u8      nc_scr3;
348
349 /*60*/  u8      nc_scrx[64];    /* Working register C-R             */
350 /*a0*/  u32     nc_mmrs;        /* Memory Move Read Selector        */
351 /*a4*/  u32     nc_mmws;        /* Memory Move Write Selector       */
352 /*a8*/  u32     nc_sfs;         /* Script Fetch Selector            */
353 /*ac*/  u32     nc_drs;         /* DSA Relative Selector            */
354 /*b0*/  u32     nc_sbms;        /* Static Block Move Selector       */
355 /*b4*/  u32     nc_dbms;        /* Dynamic Block Move Selector      */
356 /*b8*/  u32     nc_dnad64;      /* DMA Next Address 64              */
357 /*bc*/  u16     nc_scntl4;      /* C1010 only                       */
358         #define   U3EN    0x80  /* Enable Ultra 3                   */
359         #define   AIPCKEN 0x40  /* AIP checking enable              */
360                                 /* Also enable AIP generation on C10-33*/
361         #define   XCLKH_DT 0x08 /* Extra clock of data hold on DT edge */
362         #define   XCLKH_ST 0x04 /* Extra clock of data hold on ST edge */
363         #define   XCLKS_DT 0x02 /* Extra clock of data set  on DT edge */
364         #define   XCLKS_ST 0x01 /* Extra clock of data set  on ST edge */
365 /*be*/  u8      nc_aipcntl0;    /* AIP Control 0 C1010 only         */
366 /*bf*/  u8      nc_aipcntl1;    /* AIP Control 1 C1010 only         */
367         #define DISAIP  0x08    /* Disable AIP generation C10-66 only  */
368 /*c0*/  u32     nc_pmjad1;      /* Phase Mismatch Jump Address 1    */
369 /*c4*/  u32     nc_pmjad2;      /* Phase Mismatch Jump Address 2    */
370 /*c8*/  u8      nc_rbc;         /* Remaining Byte Count             */
371 /*c9*/  u8      nc_rbc1;
372 /*ca*/  u8      nc_rbc2;
373 /*cb*/  u8      nc_rbc3;
374
375 /*cc*/  u8      nc_ua;          /* Updated Address                  */
376 /*cd*/  u8      nc_ua1;
377 /*ce*/  u8      nc_ua2;
378 /*cf*/  u8      nc_ua3;
379 /*d0*/  u32     nc_esa;         /* Entry Storage Address            */
380 /*d4*/  u8      nc_ia;          /* Instruction Address              */
381 /*d5*/  u8      nc_ia1;
382 /*d6*/  u8      nc_ia2;
383 /*d7*/  u8      nc_ia3;
384 /*d8*/  u32     nc_sbc;         /* SCSI Byte Count (3 bytes only)   */
385 /*dc*/  u32     nc_csbc;        /* Cumulative SCSI Byte Count       */
386                                 /* Following for C1010 only         */
387 /*e0*/  u16    nc_crcpad;       /* CRC Value                        */
388 /*e2*/  u8     nc_crccntl0;     /* CRC control register             */
389         #define   SNDCRC  0x10  /* Send CRC Request                 */
390 /*e3*/  u8     nc_crccntl1;     /* CRC control register             */
391 /*e4*/  u32    nc_crcdata;      /* CRC data register                */
392 /*e8*/  u32    nc_e8_;
393 /*ec*/  u32    nc_ec_;
394 /*f0*/  u16    nc_dfbc;         /* DMA FIFO byte count              */ 
395 };
396
397 /*-----------------------------------------------------------
398  *
399  *      Utility macros for the script.
400  *
401  *-----------------------------------------------------------
402  */
403
404 #define REGJ(p,r) (offsetof(struct sym_reg, p ## r))
405 #define REG(r) REGJ (nc_, r)
406
407 /*-----------------------------------------------------------
408  *
409  *      SCSI phases
410  *
411  *-----------------------------------------------------------
412  */
413
414 #define SCR_DATA_OUT    0x00000000
415 #define SCR_DATA_IN     0x01000000
416 #define SCR_COMMAND     0x02000000
417 #define SCR_STATUS      0x03000000
418 #define SCR_DT_DATA_OUT 0x04000000
419 #define SCR_DT_DATA_IN  0x05000000
420 #define SCR_MSG_OUT     0x06000000
421 #define SCR_MSG_IN      0x07000000
422 /* DT phases are illegal for non Ultra3 mode */
423 #define SCR_ILG_OUT     0x04000000
424 #define SCR_ILG_IN      0x05000000
425
426 /*-----------------------------------------------------------
427  *
428  *      Data transfer via SCSI.
429  *
430  *-----------------------------------------------------------
431  *
432  *      MOVE_ABS (LEN)
433  *      <<start address>>
434  *
435  *      MOVE_IND (LEN)
436  *      <<dnad_offset>>
437  *
438  *      MOVE_TBL
439  *      <<dnad_offset>>
440  *
441  *-----------------------------------------------------------
442  */
443
444 #define OPC_MOVE          0x08000000
445
446 #define SCR_MOVE_ABS(l) ((0x00000000 | OPC_MOVE) | (l))
447 /* #define SCR_MOVE_IND(l) ((0x20000000 | OPC_MOVE) | (l)) */
448 #define SCR_MOVE_TBL     (0x10000000 | OPC_MOVE)
449
450 #define SCR_CHMOV_ABS(l) ((0x00000000) | (l))
451 /* #define SCR_CHMOV_IND(l) ((0x20000000) | (l)) */
452 #define SCR_CHMOV_TBL     (0x10000000)
453
454 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
455 /* We steal the `indirect addressing' flag for target mode MOVE in scripts */
456
457 #define OPC_TCHMOVE        0x08000000
458
459 #define SCR_TCHMOVE_ABS(l) ((0x20000000 | OPC_TCHMOVE) | (l))
460 #define SCR_TCHMOVE_TBL     (0x30000000 | OPC_TCHMOVE)
461
462 #define SCR_TMOV_ABS(l)    ((0x20000000) | (l))
463 #define SCR_TMOV_TBL        (0x30000000)
464 #endif
465
466 struct sym_tblmove {
467         u32  size;
468         u32  addr;
469 };
470
471 /*-----------------------------------------------------------
472  *
473  *      Selection
474  *
475  *-----------------------------------------------------------
476  *
477  *      SEL_ABS | SCR_ID (0..15)    [ | REL_JMP]
478  *      <<alternate_address>>
479  *
480  *      SEL_TBL | << dnad_offset>>  [ | REL_JMP]
481  *      <<alternate_address>>
482  *
483  *-----------------------------------------------------------
484  */
485
486 #define SCR_SEL_ABS     0x40000000
487 #define SCR_SEL_ABS_ATN 0x41000000
488 #define SCR_SEL_TBL     0x42000000
489 #define SCR_SEL_TBL_ATN 0x43000000
490
491 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
492 #define SCR_RESEL_ABS     0x40000000
493 #define SCR_RESEL_ABS_ATN 0x41000000
494 #define SCR_RESEL_TBL     0x42000000
495 #define SCR_RESEL_TBL_ATN 0x43000000
496 #endif
497
498 struct sym_tblsel {
499         u_char  sel_scntl4;     /* C1010 only */
500         u_char  sel_sxfer;
501         u_char  sel_id;
502         u_char  sel_scntl3;
503 };
504
505 #define SCR_JMP_REL     0x04000000
506 #define SCR_ID(id)      (((u32)(id)) << 16)
507
508 /*-----------------------------------------------------------
509  *
510  *      Waiting for Disconnect or Reselect
511  *
512  *-----------------------------------------------------------
513  *
514  *      WAIT_DISC
515  *      dummy: <<alternate_address>>
516  *
517  *      WAIT_RESEL
518  *      <<alternate_address>>
519  *
520  *-----------------------------------------------------------
521  */
522
523 #define SCR_WAIT_DISC   0x48000000
524 #define SCR_WAIT_RESEL  0x50000000
525
526 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
527 #define SCR_DISCONNECT  0x48000000
528 #endif
529
530 /*-----------------------------------------------------------
531  *
532  *      Bit Set / Reset
533  *
534  *-----------------------------------------------------------
535  *
536  *      SET (flags {|.. })
537  *
538  *      CLR (flags {|.. })
539  *
540  *-----------------------------------------------------------
541  */
542
543 #define SCR_SET(f)     (0x58000000 | (f))
544 #define SCR_CLR(f)     (0x60000000 | (f))
545
546 #define SCR_CARRY       0x00000400
547 #define SCR_TRG         0x00000200
548 #define SCR_ACK         0x00000040
549 #define SCR_ATN         0x00000008
550
551
552 /*-----------------------------------------------------------
553  *
554  *      Memory to memory move
555  *
556  *-----------------------------------------------------------
557  *
558  *      COPY (bytecount)
559  *      << source_address >>
560  *      << destination_address >>
561  *
562  *      SCR_COPY   sets the NO FLUSH option by default.
563  *      SCR_COPY_F does not set this option.
564  *
565  *      For chips which do not support this option,
566  *      sym_fw_bind_script() will remove this bit.
567  *
568  *-----------------------------------------------------------
569  */
570
571 #define SCR_NO_FLUSH 0x01000000
572
573 #define SCR_COPY(n) (0xc0000000 | SCR_NO_FLUSH | (n))
574 #define SCR_COPY_F(n) (0xc0000000 | (n))
575
576 /*-----------------------------------------------------------
577  *
578  *      Register move and binary operations
579  *
580  *-----------------------------------------------------------
581  *
582  *      SFBR_REG (reg, op, data)        reg  = SFBR op data
583  *      << 0 >>
584  *
585  *      REG_SFBR (reg, op, data)        SFBR = reg op data
586  *      << 0 >>
587  *
588  *      REG_REG  (reg, op, data)        reg  = reg op data
589  *      << 0 >>
590  *
591  *-----------------------------------------------------------
592  *
593  *      On 825A, 875, 895 and 896 chips the content 
594  *      of SFBR register can be used as data (SCR_SFBR_DATA).
595  *      The 896 has additionnal IO registers starting at 
596  *      offset 0x80. Bit 7 of register offset is stored in 
597  *      bit 7 of the SCRIPTS instruction first DWORD.
598  *
599  *-----------------------------------------------------------
600  */
601
602 #define SCR_REG_OFS(ofs) ((((ofs) & 0x7f) << 16ul) + ((ofs) & 0x80)) 
603
604 #define SCR_SFBR_REG(reg,op,data) \
605         (0x68000000 | (SCR_REG_OFS(REG(reg))) | (op) | (((data)&0xff)<<8ul))
606
607 #define SCR_REG_SFBR(reg,op,data) \
608         (0x70000000 | (SCR_REG_OFS(REG(reg))) | (op) | (((data)&0xff)<<8ul))
609
610 #define SCR_REG_REG(reg,op,data) \
611         (0x78000000 | (SCR_REG_OFS(REG(reg))) | (op) | (((data)&0xff)<<8ul))
612
613
614 #define      SCR_LOAD   0x00000000
615 #define      SCR_SHL    0x01000000
616 #define      SCR_OR     0x02000000
617 #define      SCR_XOR    0x03000000
618 #define      SCR_AND    0x04000000
619 #define      SCR_SHR    0x05000000
620 #define      SCR_ADD    0x06000000
621 #define      SCR_ADDC   0x07000000
622
623 #define      SCR_SFBR_DATA   (0x00800000>>8ul)  /* Use SFBR as data */
624
625 /*-----------------------------------------------------------
626  *
627  *      FROM_REG (reg)            SFBR = reg
628  *      << 0 >>
629  *
630  *      TO_REG   (reg)            reg  = SFBR
631  *      << 0 >>
632  *
633  *      LOAD_REG (reg, data)      reg  = <data>
634  *      << 0 >>
635  *
636  *      LOAD_SFBR(data)           SFBR = <data>
637  *      << 0 >>
638  *
639  *-----------------------------------------------------------
640  */
641
642 #define SCR_FROM_REG(reg) \
643         SCR_REG_SFBR(reg,SCR_OR,0)
644
645 #define SCR_TO_REG(reg) \
646         SCR_SFBR_REG(reg,SCR_OR,0)
647
648 #define SCR_LOAD_REG(reg,data) \
649         SCR_REG_REG(reg,SCR_LOAD,data)
650
651 #define SCR_LOAD_SFBR(data) \
652         (SCR_REG_SFBR (gpreg, SCR_LOAD, data))
653
654 /*-----------------------------------------------------------
655  *
656  *      LOAD  from memory   to register.
657  *      STORE from register to memory.
658  *
659  *      Only supported by 810A, 860, 825A, 875, 895 and 896.
660  *
661  *-----------------------------------------------------------
662  *
663  *      LOAD_ABS (LEN)
664  *      <<start address>>
665  *
666  *      LOAD_REL (LEN)        (DSA relative)
667  *      <<dsa_offset>>
668  *
669  *-----------------------------------------------------------
670  */
671
672 #define SCR_REG_OFS2(ofs) (((ofs) & 0xff) << 16ul)
673 #define SCR_NO_FLUSH2   0x02000000
674 #define SCR_DSA_REL2    0x10000000
675
676 #define SCR_LOAD_R(reg, how, n) \
677         (0xe1000000 | how | (SCR_REG_OFS2(REG(reg))) | (n))
678
679 #define SCR_STORE_R(reg, how, n) \
680         (0xe0000000 | how | (SCR_REG_OFS2(REG(reg))) | (n))
681
682 #define SCR_LOAD_ABS(reg, n)    SCR_LOAD_R(reg, SCR_NO_FLUSH2, n)
683 #define SCR_LOAD_REL(reg, n)    SCR_LOAD_R(reg, SCR_NO_FLUSH2|SCR_DSA_REL2, n)
684 #define SCR_LOAD_ABS_F(reg, n)  SCR_LOAD_R(reg, 0, n)
685 #define SCR_LOAD_REL_F(reg, n)  SCR_LOAD_R(reg, SCR_DSA_REL2, n)
686
687 #define SCR_STORE_ABS(reg, n)   SCR_STORE_R(reg, SCR_NO_FLUSH2, n)
688 #define SCR_STORE_REL(reg, n)   SCR_STORE_R(reg, SCR_NO_FLUSH2|SCR_DSA_REL2,n)
689 #define SCR_STORE_ABS_F(reg, n) SCR_STORE_R(reg, 0, n)
690 #define SCR_STORE_REL_F(reg, n) SCR_STORE_R(reg, SCR_DSA_REL2, n)
691
692
693 /*-----------------------------------------------------------
694  *
695  *      Waiting for Disconnect or Reselect
696  *
697  *-----------------------------------------------------------
698  *
699  *      JUMP            [ | IFTRUE/IFFALSE ( ... ) ]
700  *      <<address>>
701  *
702  *      JUMPR           [ | IFTRUE/IFFALSE ( ... ) ]
703  *      <<distance>>
704  *
705  *      CALL            [ | IFTRUE/IFFALSE ( ... ) ]
706  *      <<address>>
707  *
708  *      CALLR           [ | IFTRUE/IFFALSE ( ... ) ]
709  *      <<distance>>
710  *
711  *      RETURN          [ | IFTRUE/IFFALSE ( ... ) ]
712  *      <<dummy>>
713  *
714  *      INT             [ | IFTRUE/IFFALSE ( ... ) ]
715  *      <<ident>>
716  *
717  *      INT_FLY         [ | IFTRUE/IFFALSE ( ... ) ]
718  *      <<ident>>
719  *
720  *      Conditions:
721  *           WHEN (phase)
722  *           IF   (phase)
723  *           CARRYSET
724  *           DATA (data, mask)
725  *
726  *-----------------------------------------------------------
727  */
728
729 #define SCR_NO_OP       0x80000000
730 #define SCR_JUMP        0x80080000
731 #define SCR_JUMP64      0x80480000
732 #define SCR_JUMPR       0x80880000
733 #define SCR_CALL        0x88080000
734 #define SCR_CALLR       0x88880000
735 #define SCR_RETURN      0x90080000
736 #define SCR_INT         0x98080000
737 #define SCR_INT_FLY     0x98180000
738
739 #define IFFALSE(arg)   (0x00080000 | (arg))
740 #define IFTRUE(arg)    (0x00000000 | (arg))
741
742 #define WHEN(phase)    (0x00030000 | (phase))
743 #define IF(phase)      (0x00020000 | (phase))
744
745 #define DATA(D)        (0x00040000 | ((D) & 0xff))
746 #define MASK(D,M)      (0x00040000 | (((M ^ 0xff) & 0xff) << 8ul)|((D) & 0xff))
747
748 #define CARRYSET       (0x00200000)
749
750 /*-----------------------------------------------------------
751  *
752  *      SCSI  constants.
753  *
754  *-----------------------------------------------------------
755  */
756
757 /*
758  *      Messages
759  */
760
761 #define M_COMPLETE      COMMAND_COMPLETE
762 #define M_EXTENDED      EXTENDED_MESSAGE
763 #define M_SAVE_DP       SAVE_POINTERS
764 #define M_RESTORE_DP    RESTORE_POINTERS
765 #define M_DISCONNECT    DISCONNECT
766 #define M_ID_ERROR      INITIATOR_ERROR
767 #define M_ABORT         ABORT
768 #define M_REJECT        MESSAGE_REJECT
769 #define M_NOOP          NOP
770 #define M_PARITY        MSG_PARITY_ERROR
771 #define M_LCOMPLETE     LINKED_CMD_COMPLETE
772 #define M_FCOMPLETE     LINKED_FLG_CMD_COMPLETE
773 #define M_RESET         BUS_DEVICE_RESET
774 #define M_ABORT_TAG     (0x0d)
775 #define M_CLEAR_QUEUE   (0x0e)
776 #define M_INIT_REC      INITIATE_RECOVERY
777 #define M_REL_REC       RELEASE_RECOVERY
778 #define M_TERMINATE     (0x11)
779 #define M_SIMPLE_TAG    SIMPLE_QUEUE_TAG
780 #define M_HEAD_TAG      HEAD_OF_QUEUE_TAG
781 #define M_ORDERED_TAG   ORDERED_QUEUE_TAG
782 #define M_IGN_RESIDUE   (0x23)
783
784 #define M_X_MODIFY_DP   EXTENDED_MODIFY_DATA_POINTER
785 #define M_X_SYNC_REQ    EXTENDED_SDTR
786 #define M_X_WIDE_REQ    EXTENDED_WDTR
787 #define M_X_PPR_REQ     (0x04)
788
789 /*
790  *      PPR protocol options
791  */
792 #define PPR_OPT_IU      (0x01)
793 #define PPR_OPT_DT      (0x02)
794 #define PPR_OPT_QAS     (0x04)
795 #define PPR_OPT_MASK    (0x07)
796
797 /*
798  *      Status
799  */
800
801 #define S_GOOD          SAM_STAT_GOOD
802 #define S_CHECK_COND    SAM_STAT_CHECK_CONDITION
803 #define S_COND_MET      SAM_STAT_CONDITION_MET
804 #define S_BUSY          SAM_STAT_BUSY
805 #define S_INT           SAM_STAT_INTERMEDIATE
806 #define S_INT_COND_MET  SAM_STAT_INTERMEDIATE_CONDITION_MET
807 #define S_CONFLICT      SAM_STAT_RESERVATION_CONFLICT
808 #define S_TERMINATED    SAM_STAT_COMMAND_TERMINATED
809 #define S_QUEUE_FULL    SAM_STAT_TASK_SET_FULL
810 #define S_ILLEGAL       (0xff)
811
812 #endif /* defined SYM_DEFS_H */