1*55139Storek /* 2*55139Storek * Copyright (c) 1992 The Regents of the University of California. 3*55139Storek * All rights reserved. 4*55139Storek * 5*55139Storek * This software was developed by the Computer Systems Engineering group 6*55139Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7*55139Storek * contributed to Berkeley. 8*55139Storek * 9*55139Storek * %sccs.include.redist.c% 10*55139Storek * 11*55139Storek * @(#)espreg.h 7.1 (Berkeley) 07/13/92 12*55139Storek * 13*55139Storek * from: $Header: espreg.h,v 1.6 92/06/17 06:59:35 torek Exp $ (LBL) 14*55139Storek * 15*55139Storek * Derived from Mary Baker's devSCSIC90.c from the Berkeley 16*55139Storek * Sprite project, which is: 17*55139Storek * 18*55139Storek * Copyright 1988 Regents of the University of California 19*55139Storek * Permission to use, copy, modify, and distribute this 20*55139Storek * software and its documentation for any purpose and without 21*55139Storek * fee is hereby granted, provided that the above copyright 22*55139Storek * notice appear in all copies. The University of California 23*55139Storek * makes no representations about the suitability of this 24*55139Storek * software for any purpose. It is provided "as is" without 25*55139Storek * express or implied warranty. 26*55139Storek */ 27*55139Storek 28*55139Storek /* 29*55139Storek * Emulex ESP100, ESP100A, and ESP200 registers, as found on the 30*55139Storek * Sun-4c Sbus. 31*55139Storek * 32*55139Storek * The registers are all bytes, and all on longword boundaries. 33*55139Storek * Grody to the max! 34*55139Storek */ 35*55139Storek struct espreg { 36*55139Storek u_char esp_tcl; /* transfer count low (byte 0) (rw) */ 37*55139Storek u_char esp_xxx0[3]; 38*55139Storek u_char esp_tch; /* transfer count high (byte 1) (rw) */ 39*55139Storek u_char esp_xxx1[3]; 40*55139Storek u_char esp_fifo; /* fifo data register (rw) */ 41*55139Storek u_char esp_xxx2[3]; 42*55139Storek u_char esp_cmd; /* command (rw) */ 43*55139Storek u_char esp_xxx3[3]; 44*55139Storek u_char esp_stat; /* status (ro); scsi id (wo) */ 45*55139Storek #define esp_id esp_stat 46*55139Storek u_char esp_xxx4[3]; 47*55139Storek u_char esp_intr; /* interrupt (ro); timeout (wo) */ 48*55139Storek #define esp_timeout esp_intr 49*55139Storek u_char esp_xxx5[3]; 50*55139Storek u_char esp_step; /* sequence step (ro); sync period (wo) */ 51*55139Storek #define esp_syncperiod esp_step 52*55139Storek u_char esp_xxx6[3]; 53*55139Storek u_char esp_fflags; /* fifo flags (ro); sync offset (wo) */ 54*55139Storek #define esp_syncoff esp_fflags 55*55139Storek u_char esp_xxx7[3]; 56*55139Storek u_char esp_conf1; /* configuration #1 (rw) */ 57*55139Storek u_char esp_xxx8[3]; 58*55139Storek u_char esp_ccf; /* clock conversion factor (wo) */ 59*55139Storek u_char esp_xxx9[3]; 60*55139Storek u_char esp_test; /* test (do not use) */ 61*55139Storek u_char esp_xxxA[3]; 62*55139Storek u_char esp_conf2; /* configuration #2 (rw) */ 63*55139Storek u_char esp_xxxB[3]; 64*55139Storek u_char esp_conf3; /* configuration #3 (rw, ESP-236) */ 65*55139Storek u_char esp_xxxC[3]; 66*55139Storek }; 67*55139Storek 68*55139Storek /* THE REST OF THESE NAMES COULD STAND TO BE SHORTENED */ 69*55139Storek 70*55139Storek /* 71*55139Storek * Bits in esp_cmd. Note that the cmd register is two levels deep (see 72*55139Storek * Emulex documentation, p. 4-3); our typical usage is to set the command, 73*55139Storek * then set it again with DMA. 74*55139Storek * 75*55139Storek * Targets will use disconnected and target mode commands; initiators will use 76*55139Storek * disconnected and initiator mode commands. Bit 0x40 indicates disconnected 77*55139Storek * mode, 0x20 target mode, and 0x10 initiator mode. (However, everyone can 78*55139Storek * use the miscellaneous commands, which have none of those bits set.) 79*55139Storek */ 80*55139Storek #define ESPCMD_DMA 0x80 /* flag => do DMA */ 81*55139Storek 82*55139Storek /* miscellaneous */ 83*55139Storek #define ESPCMD_NOP 0x00 /* do nothing */ 84*55139Storek #define ESPCMD_FLUSH_FIFO 0x01 /* flush FIFO */ 85*55139Storek #define ESPCMD_RESET_CHIP 0x02 /* reset ESP chip */ 86*55139Storek #define ESPCMD_RESET_BUS 0x03 /* reset SCSI bus */ 87*55139Storek 88*55139Storek /* disconnected */ 89*55139Storek #define ESPCMD_RESEL_SEQ 0x40 /* reselect sequence */ 90*55139Storek #define ESPCMD_SEL_NATN 0x41 /* select without ATN sequence */ 91*55139Storek #define ESPCMD_SEL_ATN 0x42 /* select with ATN sequence */ 92*55139Storek #define ESPCMD_SEL_ATNS 0x43 /* select with ATN & stop seq */ 93*55139Storek #define ESPCMD_SEL_ENA 0x44 /* enable selection/reselection */ 94*55139Storek #define ESPCMD_SEL_DIS 0x45 /* disable selection/reselection */ 95*55139Storek #define ESPCMD_SEL_ATN3 0x46 /* select with ATN3 sequence */ 96*55139Storek 97*55139Storek /* target state */ 98*55139Storek #define ESPCMD_SEND_MSG 0x20 /* send message */ 99*55139Storek #define ESPCMD_SEND_STATUS 0x21 /* send status */ 100*55139Storek #define ESPCMD_SEND_DATA 0x22 /* send data */ 101*55139Storek #define ESPCMD_DIS_SEQ 0x23 /* disconnect sequence */ 102*55139Storek #define ESPCMD_TERM_SEQ 0x24 /* terminate sequence */ 103*55139Storek #define ESPCMD_TARG_COMP 0x25 /* target command complete sequence */ 104*55139Storek #define ESPCMD_DISCONNECT 0x27 /* disconnect */ 105*55139Storek #define ESPCMD_RCV_MSG 0x28 /* receive message sequence */ 106*55139Storek #define ESPCMD_RCV_CMD 0x29 /* receive command */ 107*55139Storek #define ESPCMD_RCV_DATA 0x2a /* receive data */ 108*55139Storek #define ESPCMD_REC_CMD_SEQ 0x2b /* receive command sequence */ 109*55139Storek #define ESPCMD_STOP_DMA 0x04 /* stop DMA (see p. 4-6) */ 110*55139Storek /* ESPCMD_TARG_ABORT 0x06 target abort sequence */ 111*55139Storek 112*55139Storek /* initiator state */ 113*55139Storek #define ESPCMD_XFER_INFO 0x10 /* transfer information */ 114*55139Storek #define ESPCMD_INIT_COMP 0x11 /* initiator command complete seq */ 115*55139Storek #define ESPCMD_MSG_ACCEPT 0x12 /* message accepted */ 116*55139Storek #define ESPCMD_XFER_PAD 0x18 /* transfer pad (use only w/ DMA) */ 117*55139Storek #define ESPCMD_SET_ATN 0x1a /* set ATN */ 118*55139Storek #define ESPCMD_RESET_ATN 0x1b /* reset ATN */ 119*55139Storek 120*55139Storek /* 121*55139Storek * Bits in esp_stat. 122*55139Storek * Bits 3 through 7 are latched until esp_intr is read; 123*55139Storek * bits 0 through 2 (the phase) are not normally latched. 124*55139Storek * The interrupt bit is set even if interrupts are disabled. 125*55139Storek * Hardware or software reset, or reading esp_intr, will 126*55139Storek * clear the interrupt and turn off ESPSTAT_INT. 127*55139Storek */ 128*55139Storek #ifdef notdef 129*55139Storek #define ESPSTAT_INT 0x80 /* ASC interrupting processor */ 130*55139Storek #else 131*55139Storek #define ESPSTAT_XXX 0x80 /* rumored unreliable: use dma IP */ 132*55139Storek #endif 133*55139Storek #define ESPSTAT_GE 0x40 /* gross error */ 134*55139Storek #define ESPSTAT_PE 0x20 /* parity error */ 135*55139Storek #define ESPSTAT_ERR 0x60 /* pseudo composite */ 136*55139Storek #define ESPSTAT_TC 0x10 /* terminal count */ 137*55139Storek #define ESPSTAT_VGC 0x08 /* valid group code */ 138*55139Storek #define ESPSTAT_MSG 0x04 /* MSG line from SCSI bus */ 139*55139Storek #define ESPSTAT_CD 0x02 /* CD line from SCSI bus */ 140*55139Storek #define ESPSTAT_IO 0x01 /* IO line from SCSI bus */ 141*55139Storek #define ESPSTAT_PHASE 7 /* phase mask */ 142*55139Storek #define ESPPHASE_DATA_OUT 0 /* data out */ 143*55139Storek #define ESPPHASE_DATA_IN 1 /* data in */ 144*55139Storek #define ESPPHASE_CMD 2 /* command */ 145*55139Storek #define ESPPHASE_STATUS 3 /* status */ 146*55139Storek #define ESPPHASE_MSG_OUT 6 /* message out (w.r.t. initiator) */ 147*55139Storek #define ESPPHASE_MSG_IN 7 /* message in */ 148*55139Storek 149*55139Storek #ifdef ESP_PHASE_NAMES 150*55139Storek /* printed as `... during %s phase' */ 151*55139Storek char *espphases[] = 152*55139Storek { "data out", "data in", "command", "status", 153*55139Storek "impossible(4)", "impossible(5)", "message out", "message in" }; 154*55139Storek #endif 155*55139Storek 156*55139Storek #define ESPSTAT_BITS "\20\10INT\7GE\6PE\5TC\4VGC\3MSG\2CD\1IO" 157*55139Storek 158*55139Storek /* 159*55139Storek * Bits in esp_intr. 160*55139Storek */ 161*55139Storek #define ESPINTR_SBR 0x80 /* SCSI bus reset detected */ 162*55139Storek #define ESPINTR_ILC 0x40 /* illegal command */ 163*55139Storek #define ESPINTR_DSC 0x20 /* target disconnected, or timeout */ 164*55139Storek #define ESPINTR_SVC 0x10 /* a device wants bus service */ 165*55139Storek #define ESPINTR_CMP 0x08 /* function complete */ 166*55139Storek #define ESPINTR_RSL 0x04 /* reselected */ 167*55139Storek #define ESPINTR_SAT 0x02 /* selected with ATN */ 168*55139Storek #define ESPINTR_SEL 0x01 /* selected (no ATN) */ 169*55139Storek 170*55139Storek #define ESPINTR_BITS "\20\10SBR\7ILC\6DSC\5SVC\4CMP\3RSL\2SAT\1SEL" 171*55139Storek 172*55139Storek /* 173*55139Storek * Formula for select/reselect timeout (esp_timeout). 174*55139Storek * TU = 7682 * CCF * TCP 175*55139Storek * T / TU = register value 176*55139Storek * CCF = clock conversion factor 177*55139Storek * TCP = input clock period (in same units as T) 178*55139Storek * TU = time unit (i.e., the esp_timeout register counts in TUs) 179*55139Storek * T = desired timeout 180*55139Storek * (i.e., we want ceil(timeout / (7682*ccf*tcp))). If timeout is in ms., 181*55139Storek * and tcp is in MHz, then (ccf * 7682)/tcp gives us 1000*TU, and 182*55139Storek * 1000*timeout/(1000*TU) gives us our result (but remember to round up). 183*55139Storek * 184*55139Storek * N.B.: The register value 0 gives a TU of 256. 185*55139Storek */ 186*55139Storek #define ESPTIMO_REGVAL(timo_ms, ccf, mhz) \ 187*55139Storek howmany(1000 * (timo_ms), ((ccf) * 7682) / (mhz)) 188*55139Storek 189*55139Storek /* 190*55139Storek * Value in esp_step. These tell us how much of a `sequence' completed, 191*55139Storek * and apply to the following sequenced operations: 192*55139Storek * [initiator] 193*55139Storek * select without ATN 194*55139Storek * select with ATN 195*55139Storek * select with ATN3 196*55139Storek * select with ATN and stop 197*55139Storek * [target] 198*55139Storek * bus-initiated select with ATN 199*55139Storek * bus-initiated select 200*55139Storek * receive command sequence 201*55139Storek * command complete sequence 202*55139Storek * disconnect sequence 203*55139Storek * terminate sequence 204*55139Storek * The actual values are too complicated to define here, except that 205*55139Storek * code 4 always means `everything worked and the command went out' 206*55139Storek * (and is thus typical for everything except ATN-and-stop). 207*55139Storek */ 208*55139Storek #define ESPSTEP_MASK 0x07 /* only these bits are valid */ 209*55139Storek #define ESPSTEP_DONE 4 /* command went out */ 210*55139Storek 211*55139Storek /* 212*55139Storek * Synchronous transfer period (esp_syncper, 5 bits). 213*55139Storek * The minimum clocks-per-period is 5 and the max is 35; 214*55139Storek * the default on reset is 5. Note that a period value of 4 215*55139Storek * actually gives 5 clocks. 216*55139Storek */ 217*55139Storek #define ESP_CLOCKS_TO_PERIOD(nclocks) ((nclocks) & 31) 218*55139Storek 219*55139Storek /* 220*55139Storek * Bits in fifo flags (esp_fflags) register. The FIFO itself 221*55139Storek * is only 16 bytes, so the byte count fits in 5 bits. Normally 222*55139Storek * a copy of the sequence step register appears in the top 3 bits, 223*55139Storek * but in test mode the chip re-uses one of those for a synchronous 224*55139Storek * offset bit. 225*55139Storek */ 226*55139Storek #define ESP_NFIFO(esp) ((esp)->esp_fflags & 0x1f) 227*55139Storek #define ESP_FFSTEP(esp) (((esp)->esp_fflags >> 5) & 3) 228*55139Storek 229*55139Storek #define ESPFFLAGS_TM_SOFFNZ 0x20 /* nonzero sync offset (test mode) */ 230*55139Storek 231*55139Storek /* 232*55139Storek * Bits in esp_conf1. 233*55139Storek */ 234*55139Storek #define ESPCONF1_SLOW_CABLE 0x80 /* ``slow cable'' mode */ 235*55139Storek #define ESPCONF1_REPORT 0x40 /* disable reporting of interrupts 236*55139Storek from scsi bus reset command */ 237*55139Storek #define ESPCONF1_PARTST 0x20 /* parity test mode */ 238*55139Storek #define ESPCONF1_PARENB 0x10 /* enable parity */ 239*55139Storek #define ESPCONF1_TEST 0x08 /* chip test mode */ 240*55139Storek #define ESPCONF1_ID_MASK 0x07 /* SCSI bus ID field */ 241*55139Storek 242*55139Storek #define ESPCONF1_BITS "\20\10SLOW_CABLE\7REPORT\6PARTST\5PARENB\4TEST" 243*55139Storek 244*55139Storek /* 245*55139Storek * Values for clock conversion factor (esp_ccf). 246*55139Storek */ 247*55139Storek #define ESPCCF_FROMMHZ(mhz) (((mhz) + 4) / 5) 248*55139Storek #define ESPCCF_MIN 2 /* minimum CCF value */ 249*55139Storek 250*55139Storek /* 251*55139Storek * Bits in esp_test (for board testing only; can only be used in test mode). 252*55139Storek */ 253*55139Storek #define ESPTEST_MBZ 0xf8 /* reserved; must be 0 */ 254*55139Storek #define ESPTEST_TRISTATE 0x04 /* all output pins tristated */ 255*55139Storek #define ESPTEST_INITIATOR 0x02 /* operate as initiator */ 256*55139Storek #define ESPTEST_TARGET 0x01 /* operate as target */ 257*55139Storek 258*55139Storek /* 259*55139Storek * Bits in esp_conf2. 260*55139Storek */ 261*55139Storek #define ESPCONF2_RSVD 0xe0 /* reserved */ 262*55139Storek #define ESPCONF2_TRISTATE_DMA 0x10 /* tristate the DMA REQ pin */ 263*55139Storek #define ESPCONF2_SCSI2 0x08 /* enable SCSI 2 (see p. 4-18) */ 264*55139Storek #define ESPCONF2_TBPA 0x04 /* enable target bad parity abort */ 265*55139Storek #define ESPCONF2_RPE 0x02 /* register parity ena (ESP2xx only) */ 266*55139Storek #define ESPCONF2_DPE 0x01 /* DMA parity enable (ESP2xx only) */ 267