14135Sgd78059 /* 24135Sgd78059 * CDDL HEADER START 34135Sgd78059 * 44135Sgd78059 * The contents of this file are subject to the terms of the 54135Sgd78059 * Common Development and Distribution License (the "License"). 64135Sgd78059 * You may not use this file except in compliance with the License. 74135Sgd78059 * 84135Sgd78059 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 94135Sgd78059 * or http://www.opensolaris.org/os/licensing. 104135Sgd78059 * See the License for the specific language governing permissions 114135Sgd78059 * and limitations under the License. 124135Sgd78059 * 134135Sgd78059 * When distributing Covered Code, include this CDDL HEADER in each 144135Sgd78059 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 154135Sgd78059 * If applicable, add the following below this CDDL HEADER, with the 164135Sgd78059 * fields enclosed by brackets "[]" replaced with your own identifying 174135Sgd78059 * information: Portions Copyright [yyyy] [name of copyright owner] 184135Sgd78059 * 194135Sgd78059 * CDDL HEADER END 204135Sgd78059 */ 214135Sgd78059 /* 22*5107Seota * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 234135Sgd78059 * Use is subject to license terms. 244135Sgd78059 */ 254135Sgd78059 264135Sgd78059 #ifndef _SYS_BSCV_IMPL_H 274135Sgd78059 #define _SYS_BSCV_IMPL_H 284135Sgd78059 294135Sgd78059 #pragma ident "%Z%%M% %I% %E% SMI" 304135Sgd78059 314135Sgd78059 /* 324135Sgd78059 * Implementation private header file for bscv driver. 334135Sgd78059 */ 344135Sgd78059 354135Sgd78059 #ifdef __cplusplus 364135Sgd78059 extern "C" { 374135Sgd78059 #endif 384135Sgd78059 394135Sgd78059 #include <sys/lom_priv.h> 404135Sgd78059 414135Sgd78059 424135Sgd78059 /* 434135Sgd78059 * Local #defines 444135Sgd78059 */ 454135Sgd78059 464135Sgd78059 #define BSCV_SUCCESS DDI_SUCCESS 474135Sgd78059 #define BSCV_FAILURE DDI_FAILURE 484135Sgd78059 494135Sgd78059 /* 504135Sgd78059 * The following are used as progress indicators in bscv_attach() 514135Sgd78059 */ 524135Sgd78059 534135Sgd78059 #define BSCV_LOCKS 0x01 544135Sgd78059 #define BSCV_MAPPED_REGS 0x02 554135Sgd78059 #define BSCV_NODES 0x04 564135Sgd78059 #define BSCV_THREAD 0x08 574135Sgd78059 #define BSCV_HOSTNAME_DONE 0x10 584135Sgd78059 #define BSCV_WDOG_CFG 0x20 594135Sgd78059 #define BSCV_SIG_SENT 0x40 604135Sgd78059 614135Sgd78059 /* 624135Sgd78059 * macros to encode device minors and provide mapping to device instances. 634135Sgd78059 * The following is designed to get around the problem of a 32-bit app not 644135Sgd78059 * supporting a 32-bit minor number on an LP64 model system. 654135Sgd78059 */ 664135Sgd78059 674135Sgd78059 #ifdef NBITSMINOR 684135Sgd78059 #undef NBITSMINOR 694135Sgd78059 #define NBITSMINOR 18 704135Sgd78059 #endif 714135Sgd78059 724135Sgd78059 #define BSCV_MONITOR_NODE 0 734135Sgd78059 #define BSCV_CONTROL_NODE (1 << (NBITSMINOR - 1)) 744135Sgd78059 754135Sgd78059 #define DEVICETOINSTANCE(x) ((getminor(x)) & (~BSCV_CONTROL_NODE)); 764135Sgd78059 774135Sgd78059 /* 784135Sgd78059 * The maximum number of leds which are supported by this lom implementation. 794135Sgd78059 */ 804135Sgd78059 #define MAX_LED_ID 7 814135Sgd78059 824135Sgd78059 /* 834135Sgd78059 * general driver configuration constants which may be changed to improve 844135Sgd78059 * performance/efficiency. 854135Sgd78059 */ 864135Sgd78059 874135Sgd78059 #define INIT_BUSY_WAIT 10 /* 10 microsecs */ 884135Sgd78059 894135Sgd78059 #define MAX_WDOGTIMEOUT 127 /* maximum wdog timout - 127s */ 904135Sgd78059 914135Sgd78059 924135Sgd78059 /* 934135Sgd78059 * Event processing task status flags. 944135Sgd78059 */ 954135Sgd78059 #define TASK_ALIVE_FLG 0x01 964135Sgd78059 #define TASK_STOP_FLG 0x02 974135Sgd78059 #define TASK_SLEEPING_FLG 0x04 984135Sgd78059 #define TASK_PAUSE_FLG 0x08 994135Sgd78059 #define TASK_EVENT_PENDING_FLG 0x10 1004135Sgd78059 #define TASK_EVENT_CONSUMER_FLG 0x20 1014135Sgd78059 1024135Sgd78059 /* 1034135Sgd78059 * strace(1M) prints out the debug data once the debug value is set in 1044135Sgd78059 * the bscv.conf file and the debug driver is installed. 1054135Sgd78059 * 1064135Sgd78059 * Debug flags 1074135Sgd78059 * 1084135Sgd78059 * '@' - Register (@)ccess 1094135Sgd78059 * 'A' - (A)ttach 1104135Sgd78059 * 'B' - (B)lom1 attach extra 1114135Sgd78059 * 'C' - lom1 (C)allback 1124135Sgd78059 * 'D' - (D)aemon 1134135Sgd78059 * 'E' - (E)vents 1144135Sgd78059 * 'F' - Sel(F)test 1154135Sgd78059 * 'I' - (I)octl 1164135Sgd78059 * 'L' - TSa(L)arms 1174135Sgd78059 * 'M' - (M)odel parameters 1184135Sgd78059 * 'N' - I(N)terrupt Service Routine 1194135Sgd78059 * 'O' - (O)pen/Close 1204135Sgd78059 * 'P' - (P)rogramming 1214135Sgd78059 * 'Q' - (Q)ueue things 1224135Sgd78059 * 'R' - Read/Write (R)etry summary. 1234135Sgd78059 * 'S' - Event (S)trings 1244135Sgd78059 * 'U' - Programming ioctls 1254135Sgd78059 * 'V' - ??? 1264135Sgd78059 * 'W' - (W)atchdog 1274135Sgd78059 * 'X' - additional X86 functional calls 1284135Sgd78059 * 'Z' - Temporary - just log things 1294135Sgd78059 */ 1304135Sgd78059 1314135Sgd78059 /* 1324135Sgd78059 * Debug tips : 1334135Sgd78059 * 1344135Sgd78059 * strace(1M) prints out the debug data. 1354135Sgd78059 * A nice way to work out the debug value set in bscv.conf is to use mdb 1364135Sgd78059 * Say we want to show 'D' Daemon and 'I' IOCTL processing, 1374135Sgd78059 * you calculate the debug value with the following mdb session : 1384135Sgd78059 * # mdb 1394135Sgd78059 * > 1<<('D'-'@') | 1<<('I'-'@') = X 1404135Sgd78059 * 210 1414135Sgd78059 * > $q 1424135Sgd78059 * When you insert "debug=0x210;" into bscv.conf, it causes the next 1434135Sgd78059 * reboot with the debug driver to trace Daemon and IOCTL functionality. 1444135Sgd78059 */ 1454135Sgd78059 1464135Sgd78059 /* 1474135Sgd78059 * Xbus channel access data 1484135Sgd78059 */ 1494135Sgd78059 1504135Sgd78059 struct xbus_channel { 1514135Sgd78059 ddi_acc_handle_t handle; 1524135Sgd78059 uint8_t *regs; 1534135Sgd78059 }; 1544135Sgd78059 1554135Sgd78059 #define BSCV_MINCHANNELS 2 1564135Sgd78059 #define BSCV_MAXCHANNELS 16 1574135Sgd78059 1584135Sgd78059 /* 1594135Sgd78059 * soft state structure 1604135Sgd78059 */ 1614135Sgd78059 1624135Sgd78059 typedef 1634135Sgd78059 struct { 1644135Sgd78059 /* 1654135Sgd78059 * Hardware instance variables 1664135Sgd78059 */ 1674135Sgd78059 uint64_t debug; /* debugging turned on */ 1684135Sgd78059 major_t majornum; /* debugging - major number */ 1694135Sgd78059 minor_t minornum; /* debugging - minor number */ 1704135Sgd78059 1714135Sgd78059 dev_info_t *dip; /* pointer to device info tree */ 1724135Sgd78059 int instance; /* instance number for the device */ 1734135Sgd78059 ddi_device_acc_attr_t attr; /* device access attributes */ 1744135Sgd78059 1754135Sgd78059 struct xbus_channel channel[BSCV_MAXCHANNELS]; 1764135Sgd78059 int nchannels; 1774135Sgd78059 1784135Sgd78059 int progress; /* progress indicator for attach */ 1794135Sgd78059 1804135Sgd78059 int bad_resync; /* Number of bad resyncs */ 1814135Sgd78059 1824135Sgd78059 /* 1834135Sgd78059 * lom data variables/arrays 1844135Sgd78059 */ 1854135Sgd78059 uint8_t lom_regs[0x80]; /* registers on the lomlite */ 1864135Sgd78059 int serial_reporting; 1874135Sgd78059 int reporting_level; 1884135Sgd78059 1894135Sgd78059 /* 1904135Sgd78059 * lom2 static information. 1914135Sgd78059 * setup at driver attach and restart after programming. 1924135Sgd78059 */ 1934135Sgd78059 int num_fans; 1944135Sgd78059 char fan_names[MAX_FANS][MAX_LOM2_NAME_STR]; 1954135Sgd78059 uint8_t fanspeed[MAX_FANS]; 1964135Sgd78059 char led_names[MAX_LED_ID][MAX_LOM2_NAME_STR]; 1974135Sgd78059 lom_volts_t volts; /* keep a static copy of this so */ 1984135Sgd78059 /* dont have to re-read names */ 1994135Sgd78059 lom_temp_t temps; /* keep a static copy of this so */ 2004135Sgd78059 /* dont have to re-read names */ 2014135Sgd78059 lom_sflags_t sflags; /* keep a static copy of this so */ 2024135Sgd78059 /* dont have to re-read names */ 2034135Sgd78059 char escape_chars[6]; /* local copy */ 2044135Sgd78059 2054135Sgd78059 uint_t watchdog_timeout; 2064135Sgd78059 uint8_t watchdog_reset_on_timeout; 2074135Sgd78059 2084135Sgd78059 /* 2094135Sgd78059 * lom2 firmware communication 2104135Sgd78059 */ 2114135Sgd78059 2124135Sgd78059 /* 2134135Sgd78059 * cmd_mutex protects the lom2 command progress variables. 2144135Sgd78059 * These should only be read/updated with the mutex held. 2154135Sgd78059 * 2164135Sgd78059 * command_error - acts as a return code and may be read 2174135Sgd78059 * without the mutex held if a command is not in progress. 2184135Sgd78059 * Note a read only returns failure if the lom does not respond. 2194135Sgd78059 * So you might need to check the error code to see if things really 2204135Sgd78059 * did work! 2214135Sgd78059 * 2224135Sgd78059 * addr_mu is used to protect stopping and starting of the queue. 2234135Sgd78059 * BUT when programming it has different semantics and relies 2244135Sgd78059 * on only the programming thread being in the ioctl routine 2254135Sgd78059 * whilst programming is in progress. The event queue must also 2264135Sgd78059 * be paused at this time. 2274135Sgd78059 */ 2284135Sgd78059 kmutex_t cmd_mutex; /* LOM command mutual exclusion */ 2294135Sgd78059 2304135Sgd78059 int command_error; /* error code from last command */ 2314135Sgd78059 /* valid until the next command */ 2324135Sgd78059 /* starts. */ 2334135Sgd78059 2344135Sgd78059 boolean_t had_fault; /* Current command sequence faulted */ 2354135Sgd78059 boolean_t had_session_error; /* Current session had error */ 2364135Sgd78059 2374135Sgd78059 uint8_t pat_seq; /* Watchdog patting sequence number */ 2384135Sgd78059 uint8_t cap0; /* capability byte */ 2394135Sgd78059 uint8_t cap1; /* capability byte */ 2404135Sgd78059 uint8_t cap2; /* capability byte */ 2414135Sgd78059 2424135Sgd78059 /* 2434135Sgd78059 * Programming variables 2444135Sgd78059 */ 2454135Sgd78059 kmutex_t prog_mu; /* Programming mutex. - lom 2 */ 2464135Sgd78059 boolean_t prog_mode_only; /* If true we can only reprogram */ 2474135Sgd78059 /* the lom */ 2484135Sgd78059 boolean_t programming; /* TRUE is actually programming */ 2494135Sgd78059 /* the BSC */ 2504135Sgd78059 boolean_t cssp_prog; /* TRUE is CSSP programming the BSC */ 2514135Sgd78059 2524135Sgd78059 int prog_index; /* data buffer number - bit */ 2534135Sgd78059 /* 0x8000 set if last buffer */ 2544135Sgd78059 int image_ptr; /* ptr to next byte in image buffer */ 2554135Sgd78059 /* for programming */ 2564135Sgd78059 uint8_t *image; /* ptr to image buffer for */ 2574135Sgd78059 /* programming */ 2584135Sgd78059 boolean_t image2_processing; /* boolean to say which of */ 2594135Sgd78059 /* 2 BSC images being processed */ 2604135Sgd78059 boolean_t loader_running; /* Still have the loader running */ 2614135Sgd78059 2624135Sgd78059 /* 2634135Sgd78059 * LOM eeprom window access state 2644135Sgd78059 * Access under bscv_enter/bscv_exit protection. 2654135Sgd78059 */ 2664135Sgd78059 boolean_t eeinfo_valid; 2674135Sgd78059 uint32_t eeprom_size; 2684135Sgd78059 uint32_t eventlog_start; 2694135Sgd78059 uint32_t eventlog_size; 2704135Sgd78059 boolean_t oldeeptr_valid; 2714135Sgd78059 uint16_t oldeeptr; 2724135Sgd78059 2734135Sgd78059 /* 2744135Sgd78059 * Communication with the event processing thread 2754135Sgd78059 * 2764135Sgd78059 * Change these variables with task_mu held and signal task_cv 2774135Sgd78059 * if an event/task needs processing. 2784135Sgd78059 */ 2794135Sgd78059 kmutex_t task_mu; /* mutex for wait on event thread */ 2804135Sgd78059 kcondvar_t task_cv; /* cv for wait on event thread */ 2814135Sgd78059 kcondvar_t task_evnt_cv; /* cv for lom2 wait on event */ 2824135Sgd78059 int task_flags; /* To monitor/stop the event thread */ 2834135Sgd78059 volatile int event_active_count; /* Count of event thread runs */ 2844135Sgd78059 boolean_t event_waiting; /* New events are waiting in the lom */ 2854135Sgd78059 boolean_t status_change; /* A status change is waiting */ 2864135Sgd78059 boolean_t nodename_change; /* Nodename has changed */ 2874135Sgd78059 boolean_t event_sleep; /* Error reading events - wait a bit */ 2884135Sgd78059 boolean_t event_fault_reported; /* Event fault reported */ 2894135Sgd78059 boolean_t watchdog_change; /* Watchdog config has changed */ 2904135Sgd78059 #ifdef __sparc 2914135Sgd78059 bscv_sig_t last_sig; /* Record of last signature sent */ 2924135Sgd78059 #endif /* __sparc */ 2934135Sgd78059 uint8_t last_event[8]; /* last event read and reported */ 2944135Sgd78059 #if defined(__i386) || defined(__amd64) 295*5107Seota ddi_periodic_t periodic_id; /* watchdog patter periodical callback */ 2964135Sgd78059 callb_id_t callb_id; /* Need to store the ID so we can */ 2974135Sgd78059 /* unschedule the panic callback */ 2984135Sgd78059 char last_nodename[128]; /* copy of last utsname.nodename */ 2994135Sgd78059 #endif /* __i386 || __amd64 */ 3004135Sgd78059 } bscv_soft_state_t; 3014135Sgd78059 3024135Sgd78059 struct bscv_idi_callout { 3034135Sgd78059 enum bscv_idi_type type; /* Type of service */ 3044135Sgd78059 boolean_t (*fn)(struct bscv_idi_info); /* Function's address */ 3054135Sgd78059 }; 3064135Sgd78059 3074135Sgd78059 #define BSCV_IDI_CALLOUT_MAGIC 0xb5c1ca11 3084135Sgd78059 #define BSCV_IDI_ERR_MSG_THRESHOLD 10 3094135Sgd78059 struct bscv_idi_callout_mgr { 3104135Sgd78059 /* 3114135Sgd78059 * To allow for sanity check. 3124135Sgd78059 */ 3134135Sgd78059 uint32_t magic; 3144135Sgd78059 3154135Sgd78059 /* 3164135Sgd78059 * The instance number of "an" instance of the driver. This is assigned 3174135Sgd78059 * during driver attach. 3184135Sgd78059 */ 3194135Sgd78059 uint32_t valid_inst; 3204135Sgd78059 3214135Sgd78059 /* 3224135Sgd78059 * Table of services offered via the idi interface. 3234135Sgd78059 */ 3244135Sgd78059 struct bscv_idi_callout *tbl; 3254135Sgd78059 3264135Sgd78059 /* 3274135Sgd78059 * Error message count since last successful use of the idi interface. 3284135Sgd78059 */ 3294135Sgd78059 uint64_t errs; 3304135Sgd78059 }; 3314135Sgd78059 3324135Sgd78059 3334135Sgd78059 3344135Sgd78059 #define BSC_IMAGE_MAX_SIZE (0x20000 + sizeof (lom_prog_data_t)) 3354135Sgd78059 3364135Sgd78059 #define BSC_PROBE_FAULT_LIMIT 8 /* Tries before declaring lom dead */ 3374135Sgd78059 #define BSC_EVENT_POLL_NORMAL (drv_usectohz(1000000)) /* 1 second */ 3384135Sgd78059 #define BSC_EVENT_POLL_FAULTY (drv_usectohz(10000000)) /* 10 second */ 3394135Sgd78059 3404135Sgd78059 #define BSC_FAILURE_RETRY_LIMIT 5 /* Access retries before giving up */ 3414135Sgd78059 #define BSC_ERASE_RETRY_LIMIT 5 /* Erase retries */ 3424135Sgd78059 #define BSC_PAGE_RETRY_LIMIT 5 /* Page write retries */ 3434135Sgd78059 3444135Sgd78059 #define BSC_ADDR_CACHE_LIMIT \ 3454135Sgd78059 (sizeof (((bscv_soft_state_t *)NULL)->lom_regs)) 3464135Sgd78059 #define BSC_INFORM_ONLINE 0x4f530100 3474135Sgd78059 #define BSC_INFORM_OFFLINE 0x4f530201 3484135Sgd78059 #define BSC_INFORM_PANIC 0x4f530204 3494135Sgd78059 3504135Sgd78059 #include <sys/lom_ebuscodes.h> 3514135Sgd78059 3524135Sgd78059 typedef uint32_t bscv_addr_t; 3534135Sgd78059 3544135Sgd78059 #define BSC_NEXUS_ADDR(ssp, chan, as, index) \ 3554135Sgd78059 (&((ssp)->channel[chan].regs[((as) * 256) + (index)])) 3564135Sgd78059 3574135Sgd78059 #define BSC_NEXUS_OFFSET(as, index) (((as) * 256) + (index)) 3584135Sgd78059 3594135Sgd78059 #define BSCVA(as, index) (((as) * 256) + (index)) 3604135Sgd78059 3614135Sgd78059 #define PSR_SUCCESS(status) (((status) & EBUS_PROGRAM_PSR_STATUS_MASK) == \ 3624135Sgd78059 EBUS_PROGRAM_PSR_SUCCESS) 3634135Sgd78059 3644135Sgd78059 #define PSR_PROG(status) (((status) & EBUS_PROGRAM_PSR_PROG_MODE) != 0) 3654135Sgd78059 #ifdef __cplusplus 3664135Sgd78059 } 3674135Sgd78059 #endif 3684135Sgd78059 3694135Sgd78059 #endif /* _SYS_BSCV_IMPL_H */ 370