1*1708Sstevel /* 2*1708Sstevel * CDDL HEADER START 3*1708Sstevel * 4*1708Sstevel * The contents of this file are subject to the terms of the 5*1708Sstevel * Common Development and Distribution License (the "License"). 6*1708Sstevel * You may not use this file except in compliance with the License. 7*1708Sstevel * 8*1708Sstevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1708Sstevel * or http://www.opensolaris.org/os/licensing. 10*1708Sstevel * See the License for the specific language governing permissions 11*1708Sstevel * and limitations under the License. 12*1708Sstevel * 13*1708Sstevel * When distributing Covered Code, include this CDDL HEADER in each 14*1708Sstevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1708Sstevel * If applicable, add the following below this CDDL HEADER, with the 16*1708Sstevel * fields enclosed by brackets "[]" replaced with your own identifying 17*1708Sstevel * information: Portions Copyright [yyyy] [name of copyright owner] 18*1708Sstevel * 19*1708Sstevel * CDDL HEADER END 20*1708Sstevel */ 21*1708Sstevel 22*1708Sstevel /* 23*1708Sstevel * Copyright 2000 Sun Microsystems, Inc. All rights reserved. 24*1708Sstevel * Use is subject to license terms. 25*1708Sstevel */ 26*1708Sstevel 27*1708Sstevel #ifndef _SYS_IOSRAMVAR_H 28*1708Sstevel #define _SYS_IOSRAMVAR_H 29*1708Sstevel 30*1708Sstevel #pragma ident "%Z%%M% %I% %E% SMI" 31*1708Sstevel 32*1708Sstevel #ifdef __cplusplus 33*1708Sstevel extern "C" { 34*1708Sstevel #endif 35*1708Sstevel 36*1708Sstevel 37*1708Sstevel /* 38*1708Sstevel * Data sizes used by the original author 39*1708Sstevel */ 40*1708Sstevel #ifndef UINT32SZ 41*1708Sstevel #define UINT32SZ sizeof (uint32_t) 42*1708Sstevel #define UINT64SZ sizeof (uint64_t) 43*1708Sstevel #endif 44*1708Sstevel 45*1708Sstevel /* 46*1708Sstevel * Values used for tunnel switching 47*1708Sstevel */ 48*1708Sstevel #define OBP_TSWITCH_REQREPLY 0 /* request reply from SSC */ 49*1708Sstevel #define OBP_TSWITCH_NOREPLY 1 /* don't wait for reply */ 50*1708Sstevel #define IOSRAM_TSWITCH_RETRY 20 /* # of times to wait for */ 51*1708Sstevel /* current tunnel switch to */ 52*1708Sstevel /* end when starting a new */ 53*1708Sstevel /* one */ 54*1708Sstevel /* 55*1708Sstevel * When performing back-to-back tunnel switches, we have to make sure that 56*1708Sstevel * HWAD (the SC-side implementation) has time to find the new tunnel from 57*1708Sstevel * one switch before we invalidate it for the next switch. To ensure that, 58*1708Sstevel * we make sure that the time between consecutive tunnel switches is at 59*1708Sstevel * least twice the polling rate HWAD uses to detect the new tunnel. 60*1708Sstevel */ 61*1708Sstevel #define IOSRAM_TSWITCH_DELAY_US 100000 62*1708Sstevel 63*1708Sstevel /* 64*1708Sstevel * Values used for hash table maintenance 65*1708Sstevel */ 66*1708Sstevel #define IOSRAM_HASHSZ 0x20 /* # hash entries */ 67*1708Sstevel #define IOSRAM_HASH(key) ((((key) >> 24) ^ ((key) >> 16) ^\ 68*1708Sstevel ((key) >> 9) ^ (key)) & (IOSRAM_HASHSZ - 1)) 69*1708Sstevel 70*1708Sstevel /* 71*1708Sstevel * A pair of flags is associated with each IOSRAM chunk in the IOSRAM TOC. 72*1708Sstevel * These flags are stored sequentially in the "SC Domain Communication Data" 73*1708Sstevel * ('SDCD') IOSRAM chunk. The data-valid/int-pending flags are one byte each 74*1708Sstevel * and stored sequentially with data-valid flag being the first. The following 75*1708Sstevel * macros define the offset of the flags for each IOSRAM chunk based upon its 76*1708Sstevel * location (index) in the IOSRAM TOC. 77*1708Sstevel */ 78*1708Sstevel #define IOSRAM_DATAVALID_FLAGOFF(index) (2 * (index)) 79*1708Sstevel #define IOSRAM_INTPENDING_FLAGOFF(index) (2 * (index) + 1) 80*1708Sstevel 81*1708Sstevel /* 82*1708Sstevel * IOSRAM node properties (per IOSRAM node) 83*1708Sstevel */ 84*1708Sstevel #define IOSRAM_REG_PROP "reg" 85*1708Sstevel #define IOSRAM_TUNNELOK_PROP "tunnel-capable" 86*1708Sstevel 87*1708Sstevel /* 88*1708Sstevel * Other IOSRAM properties (on chosen node and parent hierarchy) 89*1708Sstevel */ 90*1708Sstevel #define IOSRAM_CHOSEN_PROP "iosram" 91*1708Sstevel #define IOSRAM_PORTID_PROP "portid" 92*1708Sstevel 93*1708Sstevel /* 94*1708Sstevel * Interrupt priority (PIL) used for IOSRAM interrupts. The value 5 was 95*1708Sstevel * chosen somewhat arbitrarily based on the fact that it is higher than 96*1708Sstevel * disks and lower than networks. 97*1708Sstevel */ 98*1708Sstevel #define IOSRAM_PIL 5 99*1708Sstevel 100*1708Sstevel /* 101*1708Sstevel * IOSRAM header structure, located at the beginning of IOSRAM. 102*1708Sstevel * 103*1708Sstevel * NOTE - New fields may be appended to this structure, but no existing fields 104*1708Sstevel * may be altered in any way!!! 105*1708Sstevel */ 106*1708Sstevel typedef struct { 107*1708Sstevel uint32_t status; 108*1708Sstevel uint32_t version; 109*1708Sstevel uint32_t toc_offset; 110*1708Sstevel uint32_t sms_mbox_version; 111*1708Sstevel uint32_t os_mbox_version; 112*1708Sstevel uint32_t obp_mbox_version; 113*1708Sstevel uint32_t sms_change_mask; 114*1708Sstevel uint32_t os_change_mask; 115*1708Sstevel } iosram_hdr_t; 116*1708Sstevel 117*1708Sstevel /* 118*1708Sstevel * Values for the status field 119*1708Sstevel */ 120*1708Sstevel #define IOSRAM_INVALID 0x494e5644 /* 'INVD' */ 121*1708Sstevel #define IOSRAM_VALID 0x56414c44 /* 'VALD' */ 122*1708Sstevel #define IOSRAM_INTRANSIT 0x494e5452 /* 'INTR' */ 123*1708Sstevel 124*1708Sstevel /* 125*1708Sstevel * Maximum IOSRAM Protocol version understood by this implementation 126*1708Sstevel */ 127*1708Sstevel #define IOSRAM_MAX_PROTOCOL_VERSION 1 128*1708Sstevel 129*1708Sstevel /* 130*1708Sstevel * Bit definitions for *_change_mask fields 131*1708Sstevel */ 132*1708Sstevel #define IOSRAM_HDRFIELD_SMS_MBOX_VER 0x00000001 133*1708Sstevel #define IOSRAM_HDRFIELD_OS_MBOX_VER 0x00000002 134*1708Sstevel #define IOSRAM_HDRFIELD_TOC_INDEX 0x00000004 135*1708Sstevel 136*1708Sstevel /* 137*1708Sstevel * Macros used to access fields in the header 138*1708Sstevel */ 139*1708Sstevel #define IOSRAM_GET_HDRFIELD32(softp, field) \ 140*1708Sstevel (ddi_get32((softp)->handle, &((iosram_hdr_t *)(softp)->iosramp)->field)) 141*1708Sstevel #define IOSRAM_SET_HDRFIELD32(softp, field, val) \ 142*1708Sstevel (ddi_put32((softp)->handle, &((iosram_hdr_t *)(softp)->iosramp)->field,\ 143*1708Sstevel (val))) 144*1708Sstevel 145*1708Sstevel /* 146*1708Sstevel * IOSRAM contains various data chunks and the key, location and size of 147*1708Sstevel * each IOSRAM chunk is communicated to the IOSRAM driver in the form of a 148*1708Sstevel * Table of Contents. This structre contains one entry for each IOSRAM 149*1708Sstevel * chunk, as well as an initial index entry. Each entry has the following 150*1708Sstevel * structure. 151*1708Sstevel * 152*1708Sstevel * NOTE - Although the unused field may be renamed for some use in the future, 153*1708Sstevel * no other modification to this structure is allowed!!! 154*1708Sstevel */ 155*1708Sstevel 156*1708Sstevel typedef struct { 157*1708Sstevel uint32_t key; /* IOSRAM chunk key */ 158*1708Sstevel uint32_t off; /* IOSRAM chunk starting offset */ 159*1708Sstevel uint32_t len; /* IOSRAM chunk length */ 160*1708Sstevel uint32_t unused; /* currently unused */ 161*1708Sstevel } iosram_toc_entry_t; 162*1708Sstevel 163*1708Sstevel /* 164*1708Sstevel * Special values used in some TOC entries 165*1708Sstevel */ 166*1708Sstevel #define IOSRAM_FLAGS_KEY 0x53444344 /* 'SDCD' - flags chunk key */ 167*1708Sstevel #define IOSRAM_INDEX_KEY 0x494e4458 /* 'INDX' - index entry key */ 168*1708Sstevel #define IOSRAM_INDEX_OFF 0xFFFFFFFF /* index entry offset */ 169*1708Sstevel 170*1708Sstevel 171*1708Sstevel /* 172*1708Sstevel * IOSRAM flags structure. An array of these - one for every IOSRAM chunk - is 173*1708Sstevel * stored in the SDCD chunk. 174*1708Sstevel */ 175*1708Sstevel typedef struct { 176*1708Sstevel uint8_t data_valid; 177*1708Sstevel uint8_t int_pending; 178*1708Sstevel } iosram_flags_t; 179*1708Sstevel 180*1708Sstevel /* 181*1708Sstevel * IOSRAM callback data structure 182*1708Sstevel */ 183*1708Sstevel typedef struct { 184*1708Sstevel uchar_t busy; /* cback handler is active/busy */ 185*1708Sstevel uchar_t unregister; /* delayed callback unregistration */ 186*1708Sstevel void (*handler)(); /* cback handler */ 187*1708Sstevel void *arg; /* cback handler arg */ 188*1708Sstevel } iosram_cback_t; 189*1708Sstevel 190*1708Sstevel 191*1708Sstevel /* 192*1708Sstevel * IOSRAM per chunk state 193*1708Sstevel */ 194*1708Sstevel typedef struct iosram_chunk { 195*1708Sstevel iosram_toc_entry_t toc_data; /* Data from TOC entry */ 196*1708Sstevel iosram_cback_t cback; /* callback info */ 197*1708Sstevel uint8_t *basep; /* kvaddr for this IOSRAM chunk */ 198*1708Sstevel iosram_flags_t *flagsp; 199*1708Sstevel struct iosram_chunk *hash; /* next entry in the hash list */ 200*1708Sstevel } iosram_chunk_t; 201*1708Sstevel 202*1708Sstevel 203*1708Sstevel /* 204*1708Sstevel * IOSRAM per instance state 205*1708Sstevel */ 206*1708Sstevel 207*1708Sstevel typedef struct iosramsoft { 208*1708Sstevel struct iosramsoft *prev; /* ptr for linked list */ 209*1708Sstevel struct iosramsoft *next; /* ptr for linked list */ 210*1708Sstevel 211*1708Sstevel boolean_t suspended; /* TRUE if driver suspended */ 212*1708Sstevel int instance; /* driver instance number */ 213*1708Sstevel dev_info_t *dip; /* device information */ 214*1708Sstevel 215*1708Sstevel uchar_t *iosramp; /* IOSRAM mapped vaddr */ 216*1708Sstevel int iosramlen; /* IOSRAM length */ 217*1708Sstevel int nchunks; /* # IOSRAM chunks */ 218*1708Sstevel iosram_chunk_t *chunks; /* ptr to iosram_chunk array */ 219*1708Sstevel iosram_chunk_t *flags_chunk; /* ptr to flags chunk */ 220*1708Sstevel ddi_acc_handle_t handle; /* IOSRAM map handle */ 221*1708Sstevel 222*1708Sstevel ddi_iblock_cookie_t real_iblk; /* real intr iblock cookie */ 223*1708Sstevel ddi_iblock_cookie_t soft_iblk; /* soft intr iblock cookie */ 224*1708Sstevel ddi_softintr_t softintr_id; /* soft interrupt ID */ 225*1708Sstevel ushort_t intr_busy; /* softintr handler busy */ 226*1708Sstevel ushort_t intr_pending; /* interrupt pending */ 227*1708Sstevel 228*1708Sstevel int state; /* IOSRAM state (see below) */ 229*1708Sstevel int portid; /* Card port ID for tswitch */ 230*1708Sstevel uint32_t tswitch_ok; /* # successful tunnel switch */ 231*1708Sstevel uint32_t tswitch_fail; /* # failed tunnel switch */ 232*1708Sstevel 233*1708Sstevel ddi_acc_handle_t sbbc_handle; /* SBBC regs map handle */ 234*1708Sstevel iosram_sbbc_region_t *sbbc_region; /* region of SBBC registers */ 235*1708Sstevel uint32_t int_enable_sav; /* save int enable reg. on suspend */ 236*1708Sstevel kmutex_t intr_mutex; /* real interrupt handler mutex */ 237*1708Sstevel } iosramsoft_t; 238*1708Sstevel 239*1708Sstevel 240*1708Sstevel /* IOSRAM state value */ 241*1708Sstevel #define IOSRAM_STATE_INIT 0x0001 /* initialization */ 242*1708Sstevel #define IOSRAM_STATE_SLAVE 0x0002 /* SLAVE IOSRAM */ 243*1708Sstevel #define IOSRAM_STATE_MASTER 0x0004 /* MASTER IOSRAM */ 244*1708Sstevel #define IOSRAM_STATE_MAPPED 0x0008 /* IOSRAM mapped */ 245*1708Sstevel 246*1708Sstevel #define IOSRAM_STATE_TSWITCH 0x0010 /* tunnel switch source/target */ 247*1708Sstevel #define IOSRAM_STATE_DETACH 0x0020 /* IOSRAM instance being detached */ 248*1708Sstevel 249*1708Sstevel 250*1708Sstevel #if DEBUG 251*1708Sstevel #define IOSRAM_STATS 1 /* enable IOSRAM statistics */ 252*1708Sstevel #define IOSRAM_LOG 1 /* enable IOSRAM logging */ 253*1708Sstevel #endif 254*1708Sstevel 255*1708Sstevel #if IOSRAM_STATS 256*1708Sstevel 257*1708Sstevel /* 258*1708Sstevel * IOSRAM statistics 259*1708Sstevel */ 260*1708Sstevel struct iosram_stat { 261*1708Sstevel uint32_t read; /* calls to iosram_read */ 262*1708Sstevel uint32_t write; /* calls to iosram_{force_}write */ 263*1708Sstevel uint32_t getflag; /* calls to iosram_getflag */ 264*1708Sstevel uint32_t setflag; /* calls to iosram_getflag */ 265*1708Sstevel uint32_t tswitch; /* # tunnel switch */ 266*1708Sstevel uint32_t callbacks; /* # callbacks invoked */ 267*1708Sstevel uint32_t intr_recv; /* # interrupts received */ 268*1708Sstevel uint32_t sintr_recv; /* # softintr received */ 269*1708Sstevel uint32_t intr_send; /* # interrupts sent */ 270*1708Sstevel uint64_t bread; /* # bytes read */ 271*1708Sstevel uint64_t bwrite; /* # bytes written */ 272*1708Sstevel }; 273*1708Sstevel 274*1708Sstevel #define IOSRAM_STAT(field) iosram_stats.field++ 275*1708Sstevel #define IOSRAM_STAT_ADD(field, amount) iosram_stats.field += (uint64_t)amount 276*1708Sstevel #define IOSRAM_STAT_SET(field, count) iosram_stats.field = (uint64_t)count 277*1708Sstevel 278*1708Sstevel #else /* !IOSRAM_STATS */ 279*1708Sstevel 280*1708Sstevel #define IOSRAM_STAT(field) 281*1708Sstevel #define IOSRAM_STAT_ADD(field, amount) 282*1708Sstevel #define IOSRAM_STAT_SET(field, count) 283*1708Sstevel 284*1708Sstevel #endif /* !IOSRAM_STATS */ 285*1708Sstevel 286*1708Sstevel 287*1708Sstevel #if IOSRAM_LOG 288*1708Sstevel 289*1708Sstevel /* 290*1708Sstevel * IOSRAM log related structures and extern declarations 291*1708Sstevel */ 292*1708Sstevel 293*1708Sstevel #define IOSRAM_MAXLOG 64 294*1708Sstevel 295*1708Sstevel typedef struct { 296*1708Sstevel uint32_t seq; /* logseg# */ 297*1708Sstevel clock_t tstamp; /* time stamp */ 298*1708Sstevel caddr_t fmt; /* format ptr */ 299*1708Sstevel intptr_t arg1; /* first arg */ 300*1708Sstevel intptr_t arg2; /* second arg */ 301*1708Sstevel intptr_t arg3; /* third arg */ 302*1708Sstevel intptr_t arg4; /* fourth arg */ 303*1708Sstevel } iosram_log_t; 304*1708Sstevel 305*1708Sstevel #define IOSRAMLOG(level, fmt, a1, a2, a3, a4) \ 306*1708Sstevel if (iosram_log_level >= level) { \ 307*1708Sstevel iosram_log(fmt, (intptr_t)a1, (intptr_t)a2, \ 308*1708Sstevel (intptr_t)a3, (intptr_t)a4); \ 309*1708Sstevel } 310*1708Sstevel 311*1708Sstevel extern int iosram_log_level; 312*1708Sstevel extern uint32_t iosram_logseq; 313*1708Sstevel extern iosram_log_t iosram_logbuf[IOSRAM_MAXLOG]; 314*1708Sstevel extern void iosram_log(caddr_t, intptr_t, intptr_t, intptr_t, intptr_t); 315*1708Sstevel 316*1708Sstevel #else /* !IOSRAM_LOG */ 317*1708Sstevel 318*1708Sstevel #define IOSRAMLOG(level, fmt, a1, a2, a3, a4) 319*1708Sstevel 320*1708Sstevel #endif /* !IOSRAM_LOG */ 321*1708Sstevel 322*1708Sstevel 323*1708Sstevel #ifdef __cplusplus 324*1708Sstevel } 325*1708Sstevel #endif 326*1708Sstevel 327*1708Sstevel #endif /* _SYS_IOSRAMVAR_H */ 328