xref: /csrg-svn/sys/sparc/sbus/espreg.h (revision 65144)
155139Storek /*
263322Sbostic  * Copyright (c) 1988, 1992, 1993
363322Sbostic  *	The Regents of the University of California.  All rights reserved.
455139Storek  *
555139Storek  * This software was developed by the Computer Systems Engineering group
655139Storek  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
755139Storek  * contributed to Berkeley.
855139Storek  *
955503Sbostic  * All advertising materials mentioning features or use of this software
1055503Sbostic  * must display the following acknowledgement:
1155503Sbostic  *	This product includes software developed by the University of
1259213Storek  *	California, Lawrence Berkeley Laboratory.
1355503Sbostic  *
1455139Storek  * %sccs.include.redist.c%
1555139Storek  *
16*65144Storek  *	@(#)espreg.h	8.2 (Berkeley) 12/14/93
1755139Storek  *
1859213Storek  * from: $Header: espreg.h,v 1.7 92/11/26 02:28:10 torek Exp $ (LBL)
1955139Storek  *
2055139Storek  * Derived from Mary Baker's devSCSIC90.c from the Berkeley
2155139Storek  * Sprite project, which is:
2255139Storek  *
2355139Storek  * Copyright 1988 Regents of the University of California
2455139Storek  * Permission to use, copy, modify, and distribute this
2555139Storek  * software and its documentation for any purpose and without
2655139Storek  * fee is hereby granted, provided that the above copyright
2755139Storek  * notice appear in all copies.  The University of California
2855139Storek  * makes no representations about the suitability of this
2955139Storek  * software for any purpose.  It is provided "as is" without
3055139Storek  * express or implied warranty.
3155139Storek  */
3255139Storek 
3355139Storek /*
3455139Storek  * Emulex ESP100, ESP100A, and ESP200 registers, as found on the
3555139Storek  * Sun-4c Sbus.
3655139Storek  *
3755139Storek  * The registers are all bytes, and all on longword boundaries.
3855139Storek  * Grody to the max!
3955139Storek  */
4055139Storek struct espreg {
4155139Storek 	u_char	esp_tcl;	/* transfer count low (byte 0) (rw) */
4255139Storek 	u_char	esp_xxx0[3];
4355139Storek 	u_char	esp_tch;	/* transfer count high (byte 1) (rw) */
4455139Storek 	u_char	esp_xxx1[3];
4555139Storek 	u_char	esp_fifo;	/* fifo data register (rw) */
4655139Storek 	u_char	esp_xxx2[3];
4755139Storek 	u_char	esp_cmd;	/* command (rw) */
4855139Storek 	u_char	esp_xxx3[3];
4955139Storek 	u_char	esp_stat;	/* status (ro); scsi id (wo) */
5055139Storek #define	esp_id	esp_stat
5155139Storek 	u_char	esp_xxx4[3];
5255139Storek 	u_char	esp_intr;	/* interrupt (ro); timeout (wo) */
5355139Storek #define	esp_timeout esp_intr
5455139Storek 	u_char	esp_xxx5[3];
5555139Storek 	u_char	esp_step;	/* sequence step (ro); sync period (wo) */
5655139Storek #define	esp_syncperiod esp_step
5755139Storek 	u_char	esp_xxx6[3];
5855139Storek 	u_char	esp_fflags;	/* fifo flags (ro); sync offset (wo) */
5955139Storek #define	esp_syncoff esp_fflags
6055139Storek 	u_char	esp_xxx7[3];
6155139Storek 	u_char	esp_conf1;	/* configuration #1 (rw) */
6255139Storek 	u_char	esp_xxx8[3];
6355139Storek 	u_char	esp_ccf;	/* clock conversion factor (wo) */
6455139Storek 	u_char	esp_xxx9[3];
6555139Storek 	u_char	esp_test;	/* test (do not use) */
6655139Storek 	u_char	esp_xxxA[3];
67*65144Storek 	u_char	esp_conf2;	/* configuration #2 (rw, ESP100A/2xx) */
6855139Storek 	u_char	esp_xxxB[3];
6955139Storek 	u_char	esp_conf3;	/* configuration #3 (rw, ESP-236) */
7055139Storek 	u_char	esp_xxxC[3];
7155139Storek };
7255139Storek 
7355139Storek /* THE REST OF THESE NAMES COULD STAND TO BE SHORTENED */
7455139Storek 
7555139Storek /*
7655139Storek  * Bits in esp_cmd.  Note that the cmd register is two levels deep (see
7755139Storek  * Emulex documentation, p. 4-3); our typical usage is to set the command,
7855139Storek  * then set it again with DMA.
7955139Storek  *
8055139Storek  * Targets will use disconnected and target mode commands; initiators will use
8155139Storek  * disconnected and initiator mode commands. Bit 0x40 indicates disconnected
8255139Storek  * mode, 0x20 target mode, and 0x10 initiator mode.  (However, everyone can
8355139Storek  * use the miscellaneous commands, which have none of those bits set.)
8455139Storek  */
8555139Storek #define	ESPCMD_DMA		0x80	/* flag => do DMA */
8655139Storek 
8755139Storek /* miscellaneous */
8855139Storek #define	ESPCMD_NOP		0x00	/* do nothing */
8955139Storek #define	ESPCMD_FLUSH_FIFO	0x01	/* flush FIFO */
9055139Storek #define	ESPCMD_RESET_CHIP	0x02	/* reset ESP chip */
9155139Storek #define	ESPCMD_RESET_BUS	0x03	/* reset SCSI bus */
92*65144Storek /* NB: fifo flush takes time, may need delay or NOP to allow completion */
9355139Storek 
9455139Storek /* disconnected */
9555139Storek #define	ESPCMD_RESEL_SEQ	0x40	/* reselect sequence */
9655139Storek #define	ESPCMD_SEL_NATN		0x41	/* select without ATN sequence */
9755139Storek #define	ESPCMD_SEL_ATN		0x42	/* select with ATN sequence */
9855139Storek #define	ESPCMD_SEL_ATNS		0x43	/* select with ATN & stop seq */
9955139Storek #define	ESPCMD_SEL_ENA		0x44	/* enable selection/reselection */
10055139Storek #define	ESPCMD_SEL_DIS		0x45	/* disable selection/reselection */
10155139Storek #define	ESPCMD_SEL_ATN3		0x46	/* select with ATN3 sequence */
10255139Storek 
10355139Storek /* target state */
10455139Storek #define	ESPCMD_SEND_MSG		0x20	/* send message */
10555139Storek #define	ESPCMD_SEND_STATUS	0x21	/* send status */
10655139Storek #define	ESPCMD_SEND_DATA	0x22	/* send data */
10755139Storek #define	ESPCMD_DIS_SEQ		0x23	/* disconnect sequence */
10855139Storek #define	ESPCMD_TERM_SEQ		0x24	/* terminate sequence */
10955139Storek #define	ESPCMD_TARG_COMP	0x25	/* target command complete sequence */
11055139Storek #define	ESPCMD_DISCONNECT	0x27	/* disconnect */
11155139Storek #define	ESPCMD_RCV_MSG		0x28	/* receive message sequence */
11255139Storek #define	ESPCMD_RCV_CMD		0x29	/* receive command */
11355139Storek #define	ESPCMD_RCV_DATA		0x2a	/* receive data */
11455139Storek #define	ESPCMD_REC_CMD_SEQ	0x2b	/* receive command sequence */
11555139Storek #define	ESPCMD_STOP_DMA		0x04	/* stop DMA (see p. 4-6) */
11655139Storek /*	ESPCMD_TARG_ABORT	0x06	   target abort sequence */
11755139Storek 
11855139Storek /* initiator state */
11955139Storek #define	ESPCMD_XFER_INFO	0x10	/* transfer information */
12055139Storek #define	ESPCMD_INIT_COMP	0x11	/* initiator command complete seq */
12155139Storek #define	ESPCMD_MSG_ACCEPT	0x12	/* message accepted */
12255139Storek #define	ESPCMD_XFER_PAD		0x18	/* transfer pad (use only w/ DMA) */
12355139Storek #define	ESPCMD_SET_ATN		0x1a	/* set ATN */
12455139Storek #define	ESPCMD_RESET_ATN	0x1b	/* reset ATN */
12555139Storek 
12655139Storek /*
12755139Storek  * Bits in esp_stat.
12855139Storek  * Bits 3 through 7 are latched until esp_intr is read;
12955139Storek  * bits 0 through 2 (the phase) are not normally latched.
13055139Storek  * The interrupt bit is set even if interrupts are disabled.
13155139Storek  * Hardware or software reset, or reading esp_intr, will
13255139Storek  * clear the interrupt and turn off ESPSTAT_INT.
13355139Storek  */
13455139Storek #ifdef notdef
13555139Storek #define	ESPSTAT_INT		0x80	/* ASC interrupting processor */
13655139Storek #else
13755139Storek #define	ESPSTAT_XXX		0x80	/* rumored unreliable: use dma IP */
13855139Storek #endif
13955139Storek #define	ESPSTAT_GE		0x40	/* gross error */
14055139Storek #define	ESPSTAT_PE		0x20	/* parity error */
14155139Storek #define	ESPSTAT_ERR		0x60	/* pseudo composite */
14255139Storek #define	ESPSTAT_TC		0x10	/* terminal count */
14355139Storek #define	ESPSTAT_VGC		0x08	/* valid group code */
14455139Storek #define	ESPSTAT_MSG		0x04	/* MSG line from SCSI bus */
14555139Storek #define	ESPSTAT_CD		0x02	/* CD line from SCSI bus */
14655139Storek #define	ESPSTAT_IO		0x01	/* IO line from SCSI bus */
14755139Storek #define	ESPSTAT_PHASE		7	/* phase mask */
14855139Storek #define	ESPPHASE_DATA_OUT	0	/* data out */
14955139Storek #define	ESPPHASE_DATA_IN	1	/* data in */
15055139Storek #define	ESPPHASE_CMD		2	/* command */
15155139Storek #define	ESPPHASE_STATUS		3	/* status */
15255139Storek #define	ESPPHASE_MSG_OUT	6	/* message out (w.r.t. initiator) */
15355139Storek #define	ESPPHASE_MSG_IN		7	/* message in */
15455139Storek 
15555139Storek #ifdef ESP_PHASE_NAMES
15655139Storek /* printed as `... during %s phase' */
15755139Storek char	*espphases[] =
15855139Storek     { "data out", "data in", "command", "status",
15955139Storek       "impossible(4)", "impossible(5)", "message out", "message in" };
16055139Storek #endif
16155139Storek 
16255139Storek #define	ESPSTAT_BITS	"\20\10INT\7GE\6PE\5TC\4VGC\3MSG\2CD\1IO"
16355139Storek 
16455139Storek /*
16555139Storek  * Bits in esp_intr.
16655139Storek  */
16755139Storek #define	ESPINTR_SBR	0x80	/* SCSI bus reset detected */
16855139Storek #define	ESPINTR_ILC	0x40	/* illegal command */
16955139Storek #define	ESPINTR_DSC	0x20	/* target disconnected, or timeout */
17055139Storek #define	ESPINTR_SVC	0x10	/* a device wants bus service */
17155139Storek #define	ESPINTR_CMP	0x08	/* function complete */
17255139Storek #define	ESPINTR_RSL	0x04	/* reselected */
17355139Storek #define	ESPINTR_SAT	0x02	/* selected with ATN */
17455139Storek #define	ESPINTR_SEL	0x01	/* selected (no ATN) */
17555139Storek 
17655139Storek #define	ESPINTR_BITS "\20\10SBR\7ILC\6DSC\5SVC\4CMP\3RSL\2SAT\1SEL"
17755139Storek 
17855139Storek /*
17955139Storek  * Formula for select/reselect timeout (esp_timeout).
18055139Storek  *	TU = 7682 * CCF * TCP
18155139Storek  *	T / TU = register value
18255139Storek  *	CCF = clock conversion factor
18355139Storek  *	TCP = input clock period (in same units as T)
18455139Storek  *	TU = time unit (i.e., the esp_timeout register counts in TUs)
18555139Storek  *	T = desired timeout
18655139Storek  * (i.e., we want ceil(timeout / (7682*ccf*tcp))).  If timeout is in ms.,
18755139Storek  * and tcp is in MHz, then (ccf * 7682)/tcp gives us 1000*TU, and
18855139Storek  * 1000*timeout/(1000*TU) gives us our result (but remember to round up).
18955139Storek  *
19055139Storek  * N.B.: The register value 0 gives a TU of 256.
19155139Storek  */
19255139Storek #define	ESPTIMO_REGVAL(timo_ms, ccf, mhz) \
19355139Storek 	howmany(1000 * (timo_ms), ((ccf) * 7682) / (mhz))
19455139Storek 
19555139Storek /*
19655139Storek  * Value in esp_step.  These tell us how much of a `sequence' completed,
19755139Storek  * and apply to the following sequenced operations:
19855139Storek  *  [initiator]
19955139Storek  *	select without ATN
20055139Storek  *	select with ATN
20155139Storek  *	select with ATN3
20255139Storek  *	select with ATN and stop
20355139Storek  *  [target]
20455139Storek  *	bus-initiated select with ATN
20555139Storek  *	bus-initiated select
20655139Storek  *	receive command sequence
20755139Storek  *	command complete sequence
20855139Storek  *	disconnect sequence
20955139Storek  *	terminate sequence
21055139Storek  * The actual values are too complicated to define here, except that
21155139Storek  * code 4 always means `everything worked and the command went out'
21255139Storek  * (and is thus typical for everything except ATN-and-stop).
21355139Storek  */
21455139Storek #define	ESPSTEP_MASK		0x07	/* only these bits are valid */
21555139Storek #define	ESPSTEP_DONE		4	/* command went out */
21655139Storek 
21755139Storek /*
218*65144Storek  * Synchronous transfer period (esp_syncperiod, 5 bits).
21955139Storek  * The minimum clocks-per-period is 5 and the max is 35;
22055139Storek  * the default on reset is 5.  Note that a period value of 4
22155139Storek  * actually gives 5 clocks.
22255139Storek  */
22355139Storek #define	ESP_CLOCKS_TO_PERIOD(nclocks) ((nclocks) & 31)
22455139Storek 
22555139Storek /*
22655139Storek  * Bits in fifo flags (esp_fflags) register.  The FIFO itself
22755139Storek  * is only 16 bytes, so the byte count fits in 5 bits.  Normally
22855139Storek  * a copy of the sequence step register appears in the top 3 bits,
22955139Storek  * but in test mode the chip re-uses one of those for a synchronous
230*65144Storek  * offset bit; in any case, they are pretty much worthless.
231*65144Storek  *
232*65144Storek  * Note that the fifo flags register must not be read while the
233*65144Storek  * fifo is changing.
23455139Storek  */
235*65144Storek #define	ESP_NFIFO(fflags)	((fflags) & 0x1f)
23655139Storek 
23755139Storek #define	ESPFFLAGS_TM_SOFFNZ	0x20	/* nonzero sync offset (test mode) */
23855139Storek 
23955139Storek /*
24055139Storek  * Bits in esp_conf1.
24155139Storek  */
24255139Storek #define	ESPCONF1_SLOW_CABLE	0x80	/* ``slow cable'' mode */
24355139Storek #define	ESPCONF1_REPORT		0x40	/* disable reporting of interrupts
24455139Storek 					   from scsi bus reset command */
24555139Storek #define	ESPCONF1_PARTST		0x20	/* parity test mode */
24655139Storek #define	ESPCONF1_PARENB		0x10	/* enable parity */
24755139Storek #define	ESPCONF1_TEST		0x08	/* chip test mode */
24855139Storek #define	ESPCONF1_ID_MASK	0x07	/* SCSI bus ID field */
24955139Storek 
25055139Storek #define	ESPCONF1_BITS	"\20\10SLOW_CABLE\7REPORT\6PARTST\5PARENB\4TEST"
25155139Storek 
25255139Storek /*
25355139Storek  * Values for clock conversion factor (esp_ccf).
25455139Storek  */
25555139Storek #define	ESPCCF_FROMMHZ(mhz)	(((mhz) + 4) / 5)
25655139Storek #define	ESPCCF_MIN		2	/* minimum CCF value */
25755139Storek 
25855139Storek /*
25955139Storek  * Bits in esp_test (for board testing only; can only be used in test mode).
26055139Storek  */
26155139Storek #define	ESPTEST_MBZ		0xf8	/* reserved; must be 0 */
26255139Storek #define	ESPTEST_TRISTATE	0x04	/* all output pins tristated */
26355139Storek #define	ESPTEST_INITIATOR	0x02	/* operate as initiator */
26455139Storek #define	ESPTEST_TARGET		0x01	/* operate as target */
26555139Storek 
26655139Storek /*
26755139Storek  * Bits in esp_conf2.
26855139Storek  */
26955139Storek #define	ESPCONF2_RSVD		0xe0	/* reserved */
27055139Storek #define	ESPCONF2_TRISTATE_DMA	0x10	/* tristate the DMA REQ pin */
27155139Storek #define	ESPCONF2_SCSI2		0x08	/* enable SCSI 2 (see p. 4-18) */
27255139Storek #define	ESPCONF2_TBPA		0x04	/* enable target bad parity abort */
27355139Storek #define	ESPCONF2_RPE		0x02	/* register parity ena (ESP2xx only) */
27455139Storek #define	ESPCONF2_DPE		0x01	/* DMA parity enable (ESP2xx only) */
275