155139Storek /* 255139Storek * Copyright (c) 1992 The Regents of the University of California. 355139Storek * 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 * 9*55503Sbostic * All advertising materials mentioning features or use of this software 10*55503Sbostic * must display the following acknowledgement: 11*55503Sbostic * This product includes software developed by the University of 12*55503Sbostic * California, Lawrence Berkeley Laboratories. 13*55503Sbostic * 1455139Storek * %sccs.include.redist.c% 1555139Storek * 16*55503Sbostic * @(#)espreg.h 7.2 (Berkeley) 07/21/92 1755139Storek * 1855139Storek * from: $Header: espreg.h,v 1.6 92/06/17 06:59:35 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]; 6755139Storek u_char esp_conf2; /* configuration #2 (rw) */ 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 */ 9255139Storek 9355139Storek /* disconnected */ 9455139Storek #define ESPCMD_RESEL_SEQ 0x40 /* reselect sequence */ 9555139Storek #define ESPCMD_SEL_NATN 0x41 /* select without ATN sequence */ 9655139Storek #define ESPCMD_SEL_ATN 0x42 /* select with ATN sequence */ 9755139Storek #define ESPCMD_SEL_ATNS 0x43 /* select with ATN & stop seq */ 9855139Storek #define ESPCMD_SEL_ENA 0x44 /* enable selection/reselection */ 9955139Storek #define ESPCMD_SEL_DIS 0x45 /* disable selection/reselection */ 10055139Storek #define ESPCMD_SEL_ATN3 0x46 /* select with ATN3 sequence */ 10155139Storek 10255139Storek /* target state */ 10355139Storek #define ESPCMD_SEND_MSG 0x20 /* send message */ 10455139Storek #define ESPCMD_SEND_STATUS 0x21 /* send status */ 10555139Storek #define ESPCMD_SEND_DATA 0x22 /* send data */ 10655139Storek #define ESPCMD_DIS_SEQ 0x23 /* disconnect sequence */ 10755139Storek #define ESPCMD_TERM_SEQ 0x24 /* terminate sequence */ 10855139Storek #define ESPCMD_TARG_COMP 0x25 /* target command complete sequence */ 10955139Storek #define ESPCMD_DISCONNECT 0x27 /* disconnect */ 11055139Storek #define ESPCMD_RCV_MSG 0x28 /* receive message sequence */ 11155139Storek #define ESPCMD_RCV_CMD 0x29 /* receive command */ 11255139Storek #define ESPCMD_RCV_DATA 0x2a /* receive data */ 11355139Storek #define ESPCMD_REC_CMD_SEQ 0x2b /* receive command sequence */ 11455139Storek #define ESPCMD_STOP_DMA 0x04 /* stop DMA (see p. 4-6) */ 11555139Storek /* ESPCMD_TARG_ABORT 0x06 target abort sequence */ 11655139Storek 11755139Storek /* initiator state */ 11855139Storek #define ESPCMD_XFER_INFO 0x10 /* transfer information */ 11955139Storek #define ESPCMD_INIT_COMP 0x11 /* initiator command complete seq */ 12055139Storek #define ESPCMD_MSG_ACCEPT 0x12 /* message accepted */ 12155139Storek #define ESPCMD_XFER_PAD 0x18 /* transfer pad (use only w/ DMA) */ 12255139Storek #define ESPCMD_SET_ATN 0x1a /* set ATN */ 12355139Storek #define ESPCMD_RESET_ATN 0x1b /* reset ATN */ 12455139Storek 12555139Storek /* 12655139Storek * Bits in esp_stat. 12755139Storek * Bits 3 through 7 are latched until esp_intr is read; 12855139Storek * bits 0 through 2 (the phase) are not normally latched. 12955139Storek * The interrupt bit is set even if interrupts are disabled. 13055139Storek * Hardware or software reset, or reading esp_intr, will 13155139Storek * clear the interrupt and turn off ESPSTAT_INT. 13255139Storek */ 13355139Storek #ifdef notdef 13455139Storek #define ESPSTAT_INT 0x80 /* ASC interrupting processor */ 13555139Storek #else 13655139Storek #define ESPSTAT_XXX 0x80 /* rumored unreliable: use dma IP */ 13755139Storek #endif 13855139Storek #define ESPSTAT_GE 0x40 /* gross error */ 13955139Storek #define ESPSTAT_PE 0x20 /* parity error */ 14055139Storek #define ESPSTAT_ERR 0x60 /* pseudo composite */ 14155139Storek #define ESPSTAT_TC 0x10 /* terminal count */ 14255139Storek #define ESPSTAT_VGC 0x08 /* valid group code */ 14355139Storek #define ESPSTAT_MSG 0x04 /* MSG line from SCSI bus */ 14455139Storek #define ESPSTAT_CD 0x02 /* CD line from SCSI bus */ 14555139Storek #define ESPSTAT_IO 0x01 /* IO line from SCSI bus */ 14655139Storek #define ESPSTAT_PHASE 7 /* phase mask */ 14755139Storek #define ESPPHASE_DATA_OUT 0 /* data out */ 14855139Storek #define ESPPHASE_DATA_IN 1 /* data in */ 14955139Storek #define ESPPHASE_CMD 2 /* command */ 15055139Storek #define ESPPHASE_STATUS 3 /* status */ 15155139Storek #define ESPPHASE_MSG_OUT 6 /* message out (w.r.t. initiator) */ 15255139Storek #define ESPPHASE_MSG_IN 7 /* message in */ 15355139Storek 15455139Storek #ifdef ESP_PHASE_NAMES 15555139Storek /* printed as `... during %s phase' */ 15655139Storek char *espphases[] = 15755139Storek { "data out", "data in", "command", "status", 15855139Storek "impossible(4)", "impossible(5)", "message out", "message in" }; 15955139Storek #endif 16055139Storek 16155139Storek #define ESPSTAT_BITS "\20\10INT\7GE\6PE\5TC\4VGC\3MSG\2CD\1IO" 16255139Storek 16355139Storek /* 16455139Storek * Bits in esp_intr. 16555139Storek */ 16655139Storek #define ESPINTR_SBR 0x80 /* SCSI bus reset detected */ 16755139Storek #define ESPINTR_ILC 0x40 /* illegal command */ 16855139Storek #define ESPINTR_DSC 0x20 /* target disconnected, or timeout */ 16955139Storek #define ESPINTR_SVC 0x10 /* a device wants bus service */ 17055139Storek #define ESPINTR_CMP 0x08 /* function complete */ 17155139Storek #define ESPINTR_RSL 0x04 /* reselected */ 17255139Storek #define ESPINTR_SAT 0x02 /* selected with ATN */ 17355139Storek #define ESPINTR_SEL 0x01 /* selected (no ATN) */ 17455139Storek 17555139Storek #define ESPINTR_BITS "\20\10SBR\7ILC\6DSC\5SVC\4CMP\3RSL\2SAT\1SEL" 17655139Storek 17755139Storek /* 17855139Storek * Formula for select/reselect timeout (esp_timeout). 17955139Storek * TU = 7682 * CCF * TCP 18055139Storek * T / TU = register value 18155139Storek * CCF = clock conversion factor 18255139Storek * TCP = input clock period (in same units as T) 18355139Storek * TU = time unit (i.e., the esp_timeout register counts in TUs) 18455139Storek * T = desired timeout 18555139Storek * (i.e., we want ceil(timeout / (7682*ccf*tcp))). If timeout is in ms., 18655139Storek * and tcp is in MHz, then (ccf * 7682)/tcp gives us 1000*TU, and 18755139Storek * 1000*timeout/(1000*TU) gives us our result (but remember to round up). 18855139Storek * 18955139Storek * N.B.: The register value 0 gives a TU of 256. 19055139Storek */ 19155139Storek #define ESPTIMO_REGVAL(timo_ms, ccf, mhz) \ 19255139Storek howmany(1000 * (timo_ms), ((ccf) * 7682) / (mhz)) 19355139Storek 19455139Storek /* 19555139Storek * Value in esp_step. These tell us how much of a `sequence' completed, 19655139Storek * and apply to the following sequenced operations: 19755139Storek * [initiator] 19855139Storek * select without ATN 19955139Storek * select with ATN 20055139Storek * select with ATN3 20155139Storek * select with ATN and stop 20255139Storek * [target] 20355139Storek * bus-initiated select with ATN 20455139Storek * bus-initiated select 20555139Storek * receive command sequence 20655139Storek * command complete sequence 20755139Storek * disconnect sequence 20855139Storek * terminate sequence 20955139Storek * The actual values are too complicated to define here, except that 21055139Storek * code 4 always means `everything worked and the command went out' 21155139Storek * (and is thus typical for everything except ATN-and-stop). 21255139Storek */ 21355139Storek #define ESPSTEP_MASK 0x07 /* only these bits are valid */ 21455139Storek #define ESPSTEP_DONE 4 /* command went out */ 21555139Storek 21655139Storek /* 21755139Storek * Synchronous transfer period (esp_syncper, 5 bits). 21855139Storek * The minimum clocks-per-period is 5 and the max is 35; 21955139Storek * the default on reset is 5. Note that a period value of 4 22055139Storek * actually gives 5 clocks. 22155139Storek */ 22255139Storek #define ESP_CLOCKS_TO_PERIOD(nclocks) ((nclocks) & 31) 22355139Storek 22455139Storek /* 22555139Storek * Bits in fifo flags (esp_fflags) register. The FIFO itself 22655139Storek * is only 16 bytes, so the byte count fits in 5 bits. Normally 22755139Storek * a copy of the sequence step register appears in the top 3 bits, 22855139Storek * but in test mode the chip re-uses one of those for a synchronous 22955139Storek * offset bit. 23055139Storek */ 23155139Storek #define ESP_NFIFO(esp) ((esp)->esp_fflags & 0x1f) 23255139Storek #define ESP_FFSTEP(esp) (((esp)->esp_fflags >> 5) & 3) 23355139Storek 23455139Storek #define ESPFFLAGS_TM_SOFFNZ 0x20 /* nonzero sync offset (test mode) */ 23555139Storek 23655139Storek /* 23755139Storek * Bits in esp_conf1. 23855139Storek */ 23955139Storek #define ESPCONF1_SLOW_CABLE 0x80 /* ``slow cable'' mode */ 24055139Storek #define ESPCONF1_REPORT 0x40 /* disable reporting of interrupts 24155139Storek from scsi bus reset command */ 24255139Storek #define ESPCONF1_PARTST 0x20 /* parity test mode */ 24355139Storek #define ESPCONF1_PARENB 0x10 /* enable parity */ 24455139Storek #define ESPCONF1_TEST 0x08 /* chip test mode */ 24555139Storek #define ESPCONF1_ID_MASK 0x07 /* SCSI bus ID field */ 24655139Storek 24755139Storek #define ESPCONF1_BITS "\20\10SLOW_CABLE\7REPORT\6PARTST\5PARENB\4TEST" 24855139Storek 24955139Storek /* 25055139Storek * Values for clock conversion factor (esp_ccf). 25155139Storek */ 25255139Storek #define ESPCCF_FROMMHZ(mhz) (((mhz) + 4) / 5) 25355139Storek #define ESPCCF_MIN 2 /* minimum CCF value */ 25455139Storek 25555139Storek /* 25655139Storek * Bits in esp_test (for board testing only; can only be used in test mode). 25755139Storek */ 25855139Storek #define ESPTEST_MBZ 0xf8 /* reserved; must be 0 */ 25955139Storek #define ESPTEST_TRISTATE 0x04 /* all output pins tristated */ 26055139Storek #define ESPTEST_INITIATOR 0x02 /* operate as initiator */ 26155139Storek #define ESPTEST_TARGET 0x01 /* operate as target */ 26255139Storek 26355139Storek /* 26455139Storek * Bits in esp_conf2. 26555139Storek */ 26655139Storek #define ESPCONF2_RSVD 0xe0 /* reserved */ 26755139Storek #define ESPCONF2_TRISTATE_DMA 0x10 /* tristate the DMA REQ pin */ 26855139Storek #define ESPCONF2_SCSI2 0x08 /* enable SCSI 2 (see p. 4-18) */ 26955139Storek #define ESPCONF2_TBPA 0x04 /* enable target bad parity abort */ 27055139Storek #define ESPCONF2_RPE 0x02 /* register parity ena (ESP2xx only) */ 27155139Storek #define ESPCONF2_DPE 0x01 /* DMA parity enable (ESP2xx only) */ 272