1*11194Ssam /* if_hyreg.h 4.1 83/02/20 */ 2*11194Ssam 3*11194Ssam /* 4*11194Ssam * Network Systems Corporation Hyperchannel interface 5*11194Ssam * 6*11194Ssam * supports A410 adapter interfaced via a DEC DR-11B, NSC PI-13 or PI-14 7*11194Ssam * (PI-14 is a PI-13 with different line drivers, software is 8*11194Ssam * identical to a PI-13) 9*11194Ssam * 10*11194Ssam * Written by Steve Glaser, Tektronix Inc., July 1982 11*11194Ssam * 12*11194Ssam * NOTE: 13*11194Ssam * 14*11194Ssam * DR11B code has not been fully checked out with 4.1a. 15*11194Ssam * The first adapters at Tek came with DR11Bs, and the code once worked, 16*11194Ssam * but those have been upgraded to PI-13s. 17*11194Ssam */ 18*11194Ssam 19*11194Ssam #define PI13 1 /* PI13 vs. DR11B device depandant code */ 20*11194Ssam #ifndef DEBUG 21*11194Ssam /* #define DEBUG 1 /* enable debugging code */ 22*11194Ssam #endif 23*11194Ssam #ifndef HYLOG 24*11194Ssam #define HYLOG 1 /* enable logging of errors */ 25*11194Ssam #endif 26*11194Ssam 27*11194Ssam /* 28*11194Ssam * Structure of a HYPERchannel adapter header 29*11194Ssam */ 30*11194Ssam 31*11194Ssam struct hy_hdr { 32*11194Ssam short hyh_ctl; /* control */ 33*11194Ssam short hyh_access; /* access code */ 34*11194Ssam union { /* to/from addresses */ 35*11194Ssam short hyh_addr; /* full address */ 36*11194Ssam char hyh_baddr[2]; /* adapter/port number from address */ 37*11194Ssam } hyhu_to, hyhu_from; 38*11194Ssam #define hyh_to hyhu_to.hyh_addr 39*11194Ssam #define hyh_from hyhu_from.hyh_addr 40*11194Ssam 41*11194Ssam #define hyh_to_adapter hyhu_to.hyh_baddr[0] 42*11194Ssam #define hyh_to_port hyhu_to.hyh_baddr[1] 43*11194Ssam #define hyh_from_adapter hyhu_from.hyh_baddr[0] 44*11194Ssam #define hyh_from_port hyhu_from.hyh_baddr[1] 45*11194Ssam 46*11194Ssam short hyh_param; /* parameter (for loopback) */ 47*11194Ssam char hyh_type; /* record type */ 48*11194Ssam char hyh_off; /* offset from end of hy_hdr to ip data */ 49*11194Ssam }; 50*11194Ssam 51*11194Ssam /* 52*11194Ssam * Structure of a HYPERchannel message header (from software) 53*11194Ssam */ 54*11194Ssam 55*11194Ssam struct hym_data { /* data on the head of software versions of packets */ 56*11194Ssam short hymd_mplen; /* message proper length, if associated data, else 0 */ 57*11194Ssam }; 58*11194Ssam 59*11194Ssam #define hym_mplen hym_d.hymd_mplen 60*11194Ssam 61*11194Ssam struct hym_hdr { 62*11194Ssam struct hym_data hym_d; 63*11194Ssam struct hy_hdr hym_hdr; /* hardware header, MUST BE LAST */ 64*11194Ssam }; 65*11194Ssam 66*11194Ssam 67*11194Ssam /* 68*11194Ssam * HYPERchannel header word control bits 69*11194Ssam */ 70*11194Ssam 71*11194Ssam #define H_XTRUNKS 0x00F0 /* transmit trunks */ 72*11194Ssam #define H_RTRUNKS 0x000F /* remote trunks to transmit on for loopback */ 73*11194Ssam #define H_ASSOC 0x0100 /* has associated data */ 74*11194Ssam #define H_LOOPBK 0x00FF /* loopback command */ 75*11194Ssam 76*11194Ssam /* 77*11194Ssam * Structure of Statistics Record (counters) 78*11194Ssam */ 79*11194Ssam struct hy_stat { 80*11194Ssam u_long hyc_msgcnt; /* # messages transmitted */ 81*11194Ssam u_long hyc_dbcnt; /* # data buffers transmitted */ 82*11194Ssam u_long hyc_tbusy; /* # available trunks busy */ 83*11194Ssam u_long hyc_hwret; /* # hardware retransmits */ 84*11194Ssam u_long hyc_crcbad; /* # crc errors on trunk */ 85*11194Ssam u_long hyc_mcret; /* # microcode retransmits */ 86*11194Ssam u_long hyc_tdabort; /* # trunk driver aborts */ 87*11194Ssam u_char hyc_atype[3]; /* adapter type and revision level */ 88*11194Ssam u_char hyc_uaddr; /* adapter unit number */ 89*11194Ssam }; 90*11194Ssam 91*11194Ssam /* 92*11194Ssam * Structure of the Status Record 93*11194Ssam */ 94*11194Ssam struct hy_status { 95*11194Ssam u_char hys_gen_status; /* general status byte */ 96*11194Ssam u_char hys_last_fcn; /* last function code issued */ 97*11194Ssam u_char hys_resp_trunk; /* trunk response byte */ 98*11194Ssam u_char hys_status_trunk; /* trunk status byte */ 99*11194Ssam u_char hys_recd_resp; /* recieved response byte */ 100*11194Ssam u_char hys_error; /* error code */ 101*11194Ssam u_char hys_caddr; /* compressed addr of 1st msg on chain */ 102*11194Ssam u_char hys_pad; /* not used */ 103*11194Ssam }; 104*11194Ssam 105*11194Ssam /* 106*11194Ssam * get port number from status record 107*11194Ssam */ 108*11194Ssam #define PORTNUM(p) (((p)->hys_gen_status >> 6) & 0x03) 109*11194Ssam 110*11194Ssam /* 111*11194Ssam * The HYPERchannel driver sends and receives messages formatted: 112*11194Ssam * 113*11194Ssam * +---------------------------------------+ --- 114*11194Ssam * | | /|\ 115*11194Ssam * | HYPERchannel adapter header (hy_hdr) | | 116*11194Ssam * | | | 117*11194Ssam * +---------------------------------------+ | 118*11194Ssam * | | | 119*11194Ssam * | Internet Protocol header (ip) | message proper 120*11194Ssam * | | (64 bytes max) 121*11194Ssam * +---------------------------------------+ | 122*11194Ssam * | | | 123*11194Ssam * | TCP header + user data | | 124*11194Ssam * | (if it all fits here) | | 125*11194Ssam * | | \|/ 126*11194Ssam * +---------------------------------------+ --- 127*11194Ssam * 128*11194Ssam * +---------------------------------------+ --- 129*11194Ssam * | | /|\ 130*11194Ssam * | | | 131*11194Ssam * | TCP header + user data | associated data 132*11194Ssam * | | | 133*11194Ssam * | | \|/ 134*11194Ssam * +---------------------------------------+ --- 135*11194Ssam * 136*11194Ssam * If all of the datagram will fit in the message proper (including 137*11194Ssam * the TCP header and user data) the entire datagram is passed in 138*11194Ssam * the message proper and the associated data feature of the HYPERchannel 139*11194Ssam * is not used. 140*11194Ssam * 141*11194Ssam * The mapping from internet addresses to HYPERchannel addresses is: 142*11194Ssam * 143*11194Ssam * 0 7 8 15 16 31 144*11194Ssam * +---------+---------+-----------------------+ 145*11194Ssam * | network | special | HYPERchannel address | 146*11194Ssam * +---------+---------+-----------------------+ 147*11194Ssam * 148*11194Ssam * |<------------ internet address ----------->| 149*11194Ssam * 150*11194Ssam * The hyperchannel address is decoded as follows: 151*11194Ssam * 152*11194Ssam * 0 7 8 13 14 15 153*11194Ssam * +-------------------+----------------+------+ 154*11194Ssam * | adapter number | zero | port | 155*11194Ssam * +-------------------+----------------+------+ 156*11194Ssam * 157*11194Ssam * The low 2 bits are port number (interpreted by hyperchannel hardware). 158*11194Ssam * 159*11194Ssam * The encoding of special bits is: 160*11194Ssam * 161*11194Ssam * 00 normal packet 162*11194Ssam * 163*11194Ssam * 01 loop this packet back to the sender at the 164*11194Ssam * specified adapter (ip header source/destination addresses 165*11194Ssam * swapped before sending, command bits added to tell the 166*11194Ssam * remote HYPERchannel adapter debug & performance studies] 167*11194Ssam * this code acts like 02 (below) if the ip destination (before 168*11194Ssam * any swapping) and the destination address don't match (e.g. 169*11194Ssam * this packet is being routed through a gateway) 170*11194Ssam * 171*11194Ssam * 02 loop this packet back to the sender at the 172*11194Ssam * specified adapter, but go through the specified adapter's 173*11194Ssam * IP. This is for testing IP's store and forward mechanism. 174*11194Ssam * 175*11194Ssam * other undefined, currently treated as normal packet 176*11194Ssam * 177*11194Ssam */ 178*11194Ssam 179*11194Ssam #define MPSIZE 64 /* "Message Proper" size */ 180*11194Ssam 181*11194Ssam #define MAXRETRY 4 182*11194Ssam 183*11194Ssam /* 184*11194Ssam * device registers 185*11194Ssam */ 186*11194Ssam 187*11194Ssam struct hydevice { 188*11194Ssam short hyd_wcr; /* word count (negated) */ 189*11194Ssam unsigned short hyd_bar; /* bus address bits 15-0 */ 190*11194Ssam unsigned short hyd_csr; /* control and status */ 191*11194Ssam unsigned short hyd_dbuf; /* data buffer */ 192*11194Ssam }; 193*11194Ssam 194*11194Ssam 195*11194Ssam /* 196*11194Ssam * hyd_csr bit layout 197*11194Ssam */ 198*11194Ssam 199*11194Ssam #define S_ERROR 0100000 /* error */ 200*11194Ssam #define S_NEX 0040000 /* non-existent memory error */ 201*11194Ssam #define S_ATTN 0020000 /* attn (always zero) */ 202*11194Ssam #ifdef PI13 203*11194Ssam #define S_STKINTR 0010000 /* stacked interrupt */ 204*11194Ssam #else 205*11194Ssam #define S_MAINT 0010000 /* maintenance (not used) */ 206*11194Ssam #endif 207*11194Ssam #define S_A 0004000 /* device status A (recieve data available) */ 208*11194Ssam #define S_B 0002000 /* device status B (normal termination) */ 209*11194Ssam #define S_C 0001000 /* device status C (abnormal termination) */ 210*11194Ssam #ifdef PI13 211*11194Ssam #define S_POWEROFF 0000400 /* power off indicator */ 212*11194Ssam #else 213*11194Ssam #define S_CYCLE 0000400 /* cycle (not used) */ 214*11194Ssam #endif 215*11194Ssam #define S_READY 0000200 /* ready */ 216*11194Ssam #define S_IE 0000100 /* interrupt enable */ 217*11194Ssam #define S_XBA 0000060 /* bus address bit bits 17 and 16 */ 218*11194Ssam #define S_CLRINT 0000014 /* clear stacked interrupt */ 219*11194Ssam #define S_IATTN 0000010 /* interrupt on attention only */ 220*11194Ssam #define S_WC 0000004 /* interrupt on word count == 0 only */ 221*11194Ssam #define S_IATTNWC 0000000 /* interrupt on word count == 0 and attention */ 222*11194Ssam #define S_BURST 0000002 /* burst mode DMA (not used) */ 223*11194Ssam #define S_GO 0000001 /* go */ 224*11194Ssam 225*11194Ssam #define XBASHIFT 12 /* # bits to shift down to put unibus address bits 16/17 in right place in hyd_csr */ 226*11194Ssam 227*11194Ssam #define HY_CSR_BITS "\20\20ERROR\17NEX\16ATTN\15STKINTR\14RECV_DATA\13NORMAL\12ABNORMAL\11POWER\10READY\07IENABLE\06XBA17\05XBA16\04IATTN\03IWC\02BURST\01GO" 228*11194Ssam 229*11194Ssam /* 230*11194Ssam * PI13 status conditions 231*11194Ssam */ 232*11194Ssam 233*11194Ssam #define RECV_DATA(x) (((x)->hyd_csr & S_A) != 0) /* recieve data in adapter */ 234*11194Ssam #define NORMAL(x) (((x)->hyd_csr & S_B) != 0) /* normal termination */ 235*11194Ssam #define ABNORMAL(x) (((x)->hyd_csr & S_C) != 0) /* abnormal termination */ 236*11194Ssam #define ERROR(x) (((x)->hyd_csr & S_ERROR) != 0) /* error condition */ 237*11194Ssam #define DONE(x) (((x)->hyd_csr & (S_ERROR|S_B|S_C)) != 0) /* operation done */ 238*11194Ssam 239*11194Ssam /* 240*11194Ssam * Function Codes for the Hyperchannel Adapter 241*11194Ssam * The codes are offset so they can be "or"ed into 242*11194Ssam * the reg data buffer 243*11194Ssam */ 244*11194Ssam 245*11194Ssam #define HYF_XMITMSG 0x04 /* transmit message */ 246*11194Ssam #define HYF_XMITDATA 0x08 /* transmit associated data */ 247*11194Ssam #define HYF_XMITLSTDATA 0x0C /* transmit last associated data */ 248*11194Ssam #define HYF_XMITLOCMSG 0x10 /* transmit local message */ 249*11194Ssam #define HYF_INPUTMSG 0x24 /* input message proper */ 250*11194Ssam #define HYF_INPUTDATA 0x28 /* input assiciated data */ 251*11194Ssam #define HYF_STATUS 0x40 /* request status */ 252*11194Ssam #define HYF_DUMPREGS 0x50 /* dump extention registers */ 253*11194Ssam #define HYF_MARKP0 0x60 /* mark down port 0 */ 254*11194Ssam #define HYF_MARKP1 0x64 /* mark down port 1 */ 255*11194Ssam #define HYF_MARKP2 0x68 /* mark down port 2 */ 256*11194Ssam #define HYF_MARKP3 0x6C /* mark down port 3 */ 257*11194Ssam #define HYF_MP0RR 0x70 /* mark down port 0 and reroute messages */ 258*11194Ssam #define HYF_MP1RR 0x74 /* mark down port 1 and reroute messages */ 259*11194Ssam #define HYF_MP2RR 0x78 /* mark down port 2 and reroute messages */ 260*11194Ssam #define HYF_MP3RR 0x7C /* mark down port 3 and reroute messages */ 261*11194Ssam #define HYF_RSTATS 0xA0 /* read statistics */ 262*11194Ssam #define HYF_RCSTATS 0xA4 /* read and clear statistics */ 263*11194Ssam #define HYF_SETTEST 0xC0 /* enable test operations *set test mode) */ 264*11194Ssam #define HYF_SADDR_LEN 0xC4 /* test mode: set address and length */ 265*11194Ssam #define HYF_WBUFF 0xC8 /* test mode: write buffer */ 266*11194Ssam #define HYF_RBUFF 0xCC /* test mode: read buffer */ 267*11194Ssam #define HYF_CLRADAPTER 0xE0 /* clear adapter */ 268*11194Ssam #define HYF_END_OP 0xE4 /* end operation */ 269*11194Ssam #define HYF_CLRWFMSG 0xE6 /* clear wait for mwssage */ 270*11194Ssam #define HYF_WAITFORMSG 0xE8 /* wait for message */ 271*11194Ssam 272*11194Ssam /* 273*11194Ssam * Hyperchannel record types 274*11194Ssam */ 275*11194Ssam #define HYLINK_IP 0 /* Internet Protocol Packet */ 276*11194Ssam 277*11194Ssam #ifdef HYLOG 278*11194Ssam 279*11194Ssam #define HYL_SIZE 16*1024 280*11194Ssam 281*11194Ssam struct hy_log { 282*11194Ssam struct hy_log *hyl_self; 283*11194Ssam unsigned char hyl_enable; /* logging enabled? */ 284*11194Ssam unsigned char hyl_onerr; /* state to enter on error */ 285*11194Ssam unsigned char *hyl_eptr; /* &hy_log.hyl_buf[HYL_SIZE] */ 286*11194Ssam unsigned char *hyl_ptr; /* pointer into hyl_buf */ 287*11194Ssam unsigned char hyl_buf[HYL_SIZE]; /* log buffer space */ 288*11194Ssam }; 289*11194Ssam 290*11194Ssam #ifdef KERNEL 291*11194Ssam struct hy_log hy_log; 292*11194Ssam #endif 293*11194Ssam 294*11194Ssam #define HYL_NOP 0 295*11194Ssam #define HYL_UP 1 /* markup */ 296*11194Ssam #define HYL_STATUS 2 /* status results (struct hy_status) */ 297*11194Ssam #define HYL_STATISTICS 3 /* statistics (struct hy_stat) */ 298*11194Ssam #define HYL_XMIT 4 /* packed being send (struct hym_hdr) */ 299*11194Ssam #define HYL_RECV 5 /* recieved packet (short len; struct hy_hdr) */ 300*11194Ssam #define HYL_CMD 6 /* cmd issued (uchar cmd, state; short count) */ 301*11194Ssam #define HYL_INT 7 /* interrupt (short csr, wcr) */ 302*11194Ssam 303*11194Ssam #define HYL_DISABLED 0 /* logging disabled */ 304*11194Ssam #define HYL_CONTINUOUS 1 /* continuous logging */ 305*11194Ssam #define HYL_CAUGHT1 2 /* one buffer full captured */ 306*11194Ssam #define HYL_CATCH1 3 /* one buffer full being captured */ 307*11194Ssam #define HYL_CAUGHTSTATUS 4 /* one buffer of status captured */ 308*11194Ssam #define HYL_CATCHSTATUS 5 /* one buffer fill of status being captured */ 309*11194Ssam 310*11194Ssam #endif 311