/usr/src/uts/sun4u/tazmo/io/envctrl.c
C | 4101 lines | 2781 code | 595 blank | 725 comment | 655 complexity | 408a973f82f257af244f86a1b31441fd MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause, LGPL-2.0, 0BSD, AGPL-3.0, GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0, BSD-3-Clause-No-Nuclear-License-2014, MPL-2.0-no-copyleft-exception, AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- /*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
- /*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
- /*
- * ENVCTRL_ Environment Monitoring driver for i2c
- *
- */
- #include <sys/param.h>
- #include <sys/types.h>
- #include <sys/signal.h>
- #include <sys/errno.h>
- #include <sys/file.h>
- #include <sys/termio.h>
- #include <sys/termios.h>
- #include <sys/cmn_err.h>
- #include <sys/stream.h>
- #include <sys/strsun.h>
- #include <sys/stropts.h>
- #include <sys/strtty.h>
- #include <sys/debug.h>
- #include <sys/eucioctl.h>
- #include <sys/cred.h>
- #include <sys/uio.h>
- #include <sys/stat.h>
- #include <sys/kmem.h>
- #include <sys/ddi.h>
- #include <sys/sunddi.h>
- #include <sys/obpdefs.h>
- #include <sys/conf.h> /* req. by dev_ops flags MTSAFE etc. */
- #include <sys/modctl.h> /* for modldrv */
- #include <sys/stat.h> /* ddi_create_minor_node S_IFCHR */
- #include <sys/open.h> /* for open params. */
- #include <sys/uio.h> /* for read/write */
- #include <sys/envctrl.h> /* Environment header */
- /* driver entry point fn definitions */
- static int envctrl_open(queue_t *, dev_t *, int, int, cred_t *);
- static int envctrl_close(queue_t *, int, cred_t *);
- static uint_t envctrl_bus_isr(caddr_t);
- static uint_t envctrl_dev_isr(caddr_t);
- /* configuration entry point fn definitions */
- static int envctrl_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
- static int envctrl_attach(dev_info_t *, ddi_attach_cmd_t);
- static int envctrl_detach(dev_info_t *, ddi_detach_cmd_t);
- /* Driver private routines */
- static void envctrl_init_bus(struct envctrlunit *);
- static int envctrl_xmit(struct envctrlunit *, caddr_t *, int);
- static void envctrl_recv(struct envctrlunit *, caddr_t *, int);
- static void envctrl_get_sys_temperatures(struct envctrlunit *, uint8_t *);
- static int envctrl_get_lm75_temp(struct envctrlunit *);
- static int envctrl_get_ps_temp(struct envctrlunit *, uint8_t);
- static int envctrl_get_cpu_temp(struct envctrlunit *, int);
- static void envctrl_fan_fail_service(struct envctrlunit *);
- static void envctrl_PS_intr_service(struct envctrlunit *, uint8_t);
- static void envctrl_ps_probe(struct envctrlunit *);
- static void envctrl_tempr_poll(void *);
- static void envctrl_pshotplug_poll(void *);
- static void envctrl_led_blink(void *);
- static void envctrl_reset_dflop(struct envctrlunit *);
- static void envctrl_enable_devintrs(struct envctrlunit *);
- static void envctrl_stop_clock(struct envctrlunit *);
- static void envctrl_reset_watchdog(struct envctrlunit *, uint8_t *);
- static void envctrl_abort_seq_handler(char *msg);
- static uint8_t envctrl_get_fpm_status(struct envctrlunit *);
- static void envctrl_set_fsp(struct envctrlunit *, uint8_t *);
- static int envctrl_set_dskled(struct envctrlunit *,
- struct envctrl_pcf8574_chip *);
- static int envctrl_get_dskled(struct envctrlunit *,
- struct envctrl_pcf8574_chip *);
- static void envctrl_probe_cpus(struct envctrlunit *);
- static int envctrl_match_cpu(dev_info_t *, void *);
- static int envctrl_isother_fault_led(struct envctrlunit *,
- uint8_t, uint8_t);
- /* Kstat routines */
- static void envctrl_add_kstats(struct envctrlunit *);
- static int envctrl_ps_kstat_update(kstat_t *, int);
- static int envctrl_fanstat_kstat_update(kstat_t *, int);
- static int envctrl_encl_kstat_update(kstat_t *, int);
- static void envctrl_init_fan_kstats(struct envctrlunit *);
- static void envctrl_init_encl_kstats(struct envctrlunit *);
- static void envctrl_add_encl_kstats(struct envctrlunit *, int, int,
- uint8_t);
- static void envctrl_mod_encl_kstats(struct envctrlunit *, int, int,
- uint8_t);
- /* Streams Routines */
- static int envctrl_wput(queue_t *, mblk_t *);
- /* External routines */
- extern void power_down(const char *);
- extern int prom_getprop();
- extern int prom_getproplen();
- extern void prom_printf(const char *fmt, ...);
- extern void (*abort_seq_handler)();
- static void *envctrlsoft_statep;
- /* Local Variables */
- /* Indicates whether or not the overtemp thread has been started */
- static int envctrl_debug_flags = 0;
- static int envctrl_afb_present = 0;
- static int envctrl_power_off_overide = 0;
- static int envctrl_max_retries = 100;
- static int envctrl_allow_detach = 0;
- static int envctrl_numcpus = 1;
- static int envctrl_p0_enclosure = 0; /* set to 1 if it is a P0 */
- static int envctrl_handler = 1; /* 1 is the default */
- static clock_t overtemp_timeout_hz;
- static clock_t blink_timeout_hz;
- static clock_t pshotplug_timeout_hz;
- static int controller_present[] = {-1, -1, -1};
- #ifdef MULTIFAN
- static int envctrl_fan_debug = 0;
- #endif
- static int eHc_debug = 0;
- static int power_supply_previous_state[] = {-1, -1, -1};
- extern void pci_thermal_rem_intr(dev_info_t *, uint_t);
- #define LOOP_TIMEOUT 25
- #define INIT_FAN_VAL 35
- #define DCMNERR if (eHc_debug & 0x1) cmn_err
- #define DCMN2ERR if (eHc_debug & 0x2) cmn_err
- #define MAX_FAN_FAIL_RETRY 3
- uint8_t backaddrs[] = {ENVCTRL_PCF8574_DEV0, ENVCTRL_PCF8574_DEV1,
- ENVCTRL_PCF8574_DEV2};
- struct module_info envctrlinfo = {
- /* id, name, min pkt siz, max pkt siz, hi water, low water */
- 42, "envctrl", 0, 2048, (1024 * 20), (1024 * 1)
- };
- static struct qinit envctrl_rinit = {
- putq, NULL, envctrl_open, envctrl_close, NULL, &envctrlinfo, NULL
- };
- static struct qinit envctrl_wint = {
- envctrl_wput, NULL, envctrl_open, envctrl_close,
- NULL, &envctrlinfo, NULL
- };
- struct streamtab envctrl_str_info = {
- &envctrl_rinit, &envctrl_wint, NULL, NULL
- };
- static struct cb_ops envctrl_cb_ops = {
- nodev, /* cb_open */
- nodev, /* cb_close */
- nodev, /* cb_strategy */
- nodev, /* cb_print */
- nodev, /* cb_dump */
- nodev, /* cb_read */
- nodev, /* cb_write */
- nodev, /* cb_ioctl */
- nodev, /* cb_devmap */
- nodev, /* cb_mmap */
- nodev, /* cb_segmap */
- nochpoll, /* cb_chpoll */
- ddi_prop_op, /* cb_prop_op */
- &envctrl_str_info, /* cb_stream */
- D_MP /* cb_flag */
- };
- /*
- * Declare ops vectors for auto configuration.
- */
- struct dev_ops envctrl_ops = {
- DEVO_REV, /* devo_rev */
- 0, /* devo_refcnt */
- envctrl_getinfo, /* devo_getinfo */
- nulldev, /* devo_identify */
- nulldev, /* devo_probe */
- envctrl_attach, /* devo_attach */
- envctrl_detach, /* devo_detach */
- nodev, /* devo_reset */
- &envctrl_cb_ops, /* devo_cb_ops */
- (struct bus_ops *)NULL, /* devo_bus_ops */
- nulldev, /* devo_power */
- ddi_quiesce_not_supported, /* devo_quiesce */
- };
- extern struct mod_ops mod_driverops;
- static struct modldrv envctrlmodldrv = {
- &mod_driverops, /* type of module - driver */
- "I2C ENVCTRL_driver",
- &envctrl_ops,
- };
- static struct modlinkage envctrlmodlinkage = {
- MODREV_1,
- &envctrlmodldrv,
- 0
- };
- /*
- * The following defines are for the i2c protocol routines.
- * This section of defines should be removed once the envctrl_targets.c
- * file is included.
- */
- #define EHC_SUCCESS 0
- #define EHC_FAILURE (-1)
- #define EHC_NO_SLAVE_ACK 3
- #define EHC_MAX_WAIT 7 /* decimal */
- #define EHC_S1_PIN 0x80
- #define EHC_S1_ES1 0x20
- #define EHC_S1_ES0 0x40
- #define EHC_S1_NBB 0x01
- #define EHC_S1_ACK 0x01
- #define EHC_S1_STA 0x04
- #define EHC_S1_STO 0x02
- #define EHC_S1_LRB 0x08
- #define EHC_S1_BER 0x10
- #define EHC_S1_LAB 0x02
- #define EHC_S0_OWN 0x55
- #define EHC_S0_CLK 0x1c
- #define EHC_BYTE_READ 0x01
- #define EHC_LONGEST_MSG 1000 /* decimal */
- /*
- * PCF8591 Chip Used for temperature sensors
- *
- * Addressing Register definition.
- * A0-A2 valid range is 0-7
- *
- * 7 6 5 4 3 2 1 0
- * ------------------------------------------------
- * | 1 | 0 | 0 | 1 | A2 | A1 | A0 | R/W |
- * ------------------------------------------------
- */
- #define EHC_PCF8591_MAX_DEVS 0x08
- #define EHC_DEV0 0x00
- #define EHC_DEV1 0x02
- #define EHC_DEV2 0x04
- #define EHC_DEV3 0x06
- #define EHC_DEV4 0x08
- #define EHC_DEV5 0x0A
- #define EHC_DEV6 0x0C
- #define EHC_DEV7 0x0E
- /*
- * CONTROL OF CHIP
- * PCF8591 Temp sensing control register definitions
- *
- * 7 6 5 4 3 2 1 0
- * ---------------------------------------------
- * | 0 | AOE | X | X | 0 | AIF | X | X |
- * ---------------------------------------------
- * AOE = Analog out enable.. not used on out implementation
- * 5 & 4 = Analog Input Programming.. see data sheet for bits..
- *
- * AIF = Auto increment flag
- * bits 1 & 0 are for the Chennel number.
- */
- #define EHC_PCF8591_ANALOG_OUTPUT_EN 0x40
- #define EHC_PCF8591_ANALOG_INPUT_EN 0x00
- #define EHC_PCF8591_READ_BIT 0x01
- #define EHC_PCF8591_AUTO_INCR 0x04
- #define EHC_PCF8591_OSCILATOR 0x40
- #define EHC_PCF8591_MAX_PORTS 0x04
- #define EHC_PCF8591_CH_0 0x00
- #define EHC_PCF8591_CH_1 0x01
- #define EHC_PCF8591_CH_2 0x02
- #define EHC_PCF8591_CH_3 0x03
- /*
- * PCF8574 Fan Fail, Power Supply Fail Detector
- * This device is driven by interrupts. Each time it interrupts
- * you must look at the CSR to see which ports caused the interrupt
- * they are indicated by a 1.
- *
- * Address map of this chip
- *
- * -------------------------------------------
- * | 0 | 1 | 1 | 1 | A2 | A1 | A0 | 0 |
- * -------------------------------------------
- *
- */
- #define EHC_PCF8574_PORT0 0x01
- #define EHC_PCF8574_PORT1 0x02
- #define EHC_PCF8574_PORT2 0x04
- #define EHC_PCF8574_PORT3 0x08
- #define EHC_PCF8574_PORT4 0x10
- #define EHC_PCF8574_PORT5 0x20
- #define EHC_PCF8574_PORT6 0x40
- #define EHC_PCF8574_PORT7 0x80
- /*
- * Defines for the PCF8583 Clock Calendar Chip.
- */
- #define EHC_PCF8583_READ_BIT 0x01
- #define ALARM_CTR_REG_MINS 0x03
- #define ALARM_REG_MINS 0x0B
- #define ALARM_TIMER_REG 0x0F
- struct eHc_pcd8584_regs {
- uint8_t s0; /* Own Address S0' */
- uint8_t s1; /* Control Status register */
- uint8_t clock_s2; /* Clock programming register */
- };
- struct eHc_envcunit {
- struct eHc_pcd8584_regs *bus_ctl_regs;
- ddi_acc_handle_t ctlr_handle;
- kmutex_t umutex;
- };
- /*
- * Prototypes for static routines
- */
- static int eHc_write_tda8444(struct eHc_envcunit *, int, int, int, uint8_t *,
- int);
- static int eHc_read_pcf8591(struct eHc_envcunit *, int, int, int, int, int,
- uint8_t *, int);
- static int eHc_read_pcf8574a(struct eHc_envcunit *, int, uint8_t *, int);
- static int eHc_write_pcf8574a(struct eHc_envcunit *, int, uint8_t *, int);
- static int eHc_read_pcf8574(struct eHc_envcunit *, int, uint8_t *, int);
- static int eHc_write_pcf8574(struct eHc_envcunit *, int, uint8_t *, int);
- static int eHc_read_lm75(struct eHc_envcunit *, int, uint8_t *, int);
- static int eHc_write_pcf8583(struct eHc_envcunit *, int, uint8_t *, int);
- static int eHc_start_pcf8584(struct eHc_envcunit *, uint8_t);
- static void eHc_stop_pcf8584(struct eHc_envcunit *);
- static int eHc_read_pcf8584(struct eHc_envcunit *, uint8_t *);
- static int eHc_write_pcf8584(struct eHc_envcunit *, uint8_t);
- static int eHc_after_read_pcf8584(struct eHc_envcunit *, uint8_t *);
- /*
- * End of i2c protocol definitions section
- */
- int
- _init(void)
- {
- int error;
- if ((error = mod_install(&envctrlmodlinkage)) == 0) {
- (void) ddi_soft_state_init(&envctrlsoft_statep,
- sizeof (struct envctrlunit), 1);
- }
- return (error);
- }
- int
- _fini(void)
- {
- int error;
- if ((error = mod_remove(&envctrlmodlinkage)) == 0)
- ddi_soft_state_fini(&envctrlsoft_statep);
- return (error);
- }
- int
- _info(struct modinfo *modinfop)
- {
- return (mod_info(&envctrlmodlinkage, modinfop));
- }
- static int
- envctrl_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
- {
- int instance;
- char name[16];
- uint8_t fspval;
- struct envctrlunit *unitp;
- struct ddi_device_acc_attr attr;
- int *reg_prop;
- uchar_t *creg_prop;
- uint_t len, tblsz;
- int i, cputemp, status;
- uint8_t buf[3];
- status = len = tblsz = 0;
- attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
- attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
- attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
- instance = ddi_get_instance(dip);
- switch (cmd) {
- case DDI_ATTACH:
- break;
- case DDI_RESUME:
- if (!(unitp = ddi_get_soft_state(envctrlsoft_statep, instance)))
- return (DDI_FAILURE);
- mutex_enter(&unitp->umutex);
- if (!unitp->suspended) {
- mutex_exit(&unitp->umutex);
- return (DDI_FAILURE);
- }
- unitp->suspended = 0;
- mutex_exit(&unitp->umutex);
- unitp->initting = B_TRUE;
- envctrl_init_bus(unitp);
- unitp->initting = B_FALSE;
- mutex_enter(&unitp->umutex);
- envctrl_ps_probe(unitp);
- envctrl_probe_cpus(unitp);
- mutex_exit(&unitp->umutex);
- return (DDI_SUCCESS);
- default:
- return (DDI_FAILURE);
- }
- /* Set up timer values */
- overtemp_timeout_hz = drv_usectohz(OVERTEMP_TIMEOUT_USEC);
- blink_timeout_hz = drv_usectohz(BLINK_TIMEOUT_USEC);
- pshotplug_timeout_hz = drv_usectohz(BLINK_TIMEOUT_USEC * 6);
- if (ddi_soft_state_zalloc(envctrlsoft_statep, instance) != 0) {
- cmn_err(CE_WARN, "envctrl failed to zalloc softstate\n");
- goto failed;
- }
- unitp = ddi_get_soft_state(envctrlsoft_statep, instance);
- if (ddi_regs_map_setup(dip, 0, (caddr_t *)&unitp->bus_ctl_regs, 0,
- sizeof (struct envctrl_pcd8584_regs), &attr,
- &unitp->ctlr_handle) != DDI_SUCCESS) {
- cmn_err(CE_WARN, "I2c failed to map in bus_control regs\n");
- return (DDI_FAILURE);
- }
- /*
- * If the PCI nexus has added a thermal interrupt, we first need
- * to remove that interrupt handler.
- *
- * WARNING: Removing another driver's interrupt handler is not
- * allowed. The pci_thermal_rem_intr() call below is needed to retain
- * the legacy behavior on Tazmo systems.
- */
- pci_thermal_rem_intr(dip, (uint_t)0);
- /* add interrupts */
- if (ddi_get_iblock_cookie(dip, 1,
- &unitp->ic_trap_cookie) != DDI_SUCCESS) {
- cmn_err(CE_WARN, "ddi_get_iblock_cookie FAILED \n");
- goto failed;
- }
- mutex_init(&unitp->umutex, NULL, MUTEX_DRIVER,
- (void *)unitp->ic_trap_cookie);
- if (ddi_add_intr(dip, 0, &unitp->ic_trap_cookie, NULL, envctrl_bus_isr,
- (caddr_t)unitp) != DDI_SUCCESS) {
- cmn_err(CE_WARN, "envctrl_attach failed to add hard intr %d\n",
- instance);
- goto remlock;
- }
- if (ddi_add_intr(dip, 1, &unitp->ic_trap_cookie, NULL, envctrl_dev_isr,
- (caddr_t)unitp) != DDI_SUCCESS) {
- cmn_err(CE_WARN, "envctrl_attach failed to add hard intr %d\n",
- instance);
- goto remhardintr;
- }
- (void) sprintf(name, "envctrl%d", instance);
- if (ddi_create_minor_node(dip, name, S_IFCHR, instance, DDI_PSEUDO,
- NULL) == DDI_FAILURE) {
- ddi_remove_minor_node(dip, NULL);
- goto remhardintr1;
- }
- mutex_enter(&unitp->umutex);
- switch (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
- ENVCTRL_LED_BLINK, -1)) {
- case 1:
- unitp->activity_led_blink = B_TRUE;
- break;
- case 0:
- default:
- unitp->activity_led_blink = B_FALSE;
- break;
- }
- unitp->shutdown = B_FALSE;
- unitp->num_ps_present = unitp->num_encl_present = 0;
- unitp->num_fans_present = MIN_FAN_BANKS;
- unitp->num_fans_failed = ENVCTRL_CHAR_ZERO;
- unitp->AFB_present = B_TRUE;
- unitp->dip = dip;
- #ifdef DEBUG
- if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
- DDI_PROP_DONTPASS, ENVCTRL_PANEL_LEDS_PR,
- ®_prop, &len) == DDI_PROP_SUCCESS)
- ddi_prop_free((void *)reg_prop);
- ASSERT(len != 0);
- len = 0;
- if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
- DDI_PROP_DONTPASS, ENVCTRL_PANEL_LEDS_STA,
- ®_prop, &len) == DDI_PROP_SUCCESS)
- ddi_prop_free((void *)reg_prop);
- ASSERT(len != 0);
- len = 0;
- if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
- DDI_PROP_DONTPASS, ENVCTRL_DISK_LEDS_STA,
- ®_prop, &len) == DDI_PROP_SUCCESS)
- ddi_prop_free((void *)reg_prop);
- ASSERT(len != 0);
- #endif /* DEBUG */
- /*
- * if we have prom fan tables, overide the static tables in
- * header file.
- */
- if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip,
- DDI_PROP_DONTPASS, "cpu-fan-speeds",
- &creg_prop, &len) == DDI_PROP_SUCCESS) {
- tblsz = (sizeof (acme_cpu_fanspd) / sizeof (short));
- if (len <= tblsz) {
- for (i = 0; i < len; i++) {
- acme_cpu_fanspd[i] = creg_prop[i];
- }
- }
- ddi_prop_free((void *)creg_prop);
- }
- len = 0;
- if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip,
- DDI_PROP_DONTPASS, "ps-fan-speeds",
- &creg_prop, &len) == DDI_PROP_SUCCESS) {
- tblsz = (sizeof (acme_ps_fanspd) / sizeof (short));
- if (len <= tblsz) {
- for (i = 0; i < len; i++) {
- acme_ps_fanspd[i] = creg_prop[i];
- }
- }
- ddi_prop_free((void *)creg_prop);
- }
- switch (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
- "fan-override", -1)) {
- case 1:
- case 2:
- unitp->AFB_present = B_TRUE;
- break;
- case 0:
- default:
- unitp->AFB_present = B_FALSE;
- break;
- }
- /* For debug */
- if (envctrl_afb_present) {
- unitp->AFB_present = B_TRUE;
- }
- if (unitp->AFB_present == B_TRUE)
- unitp->num_fans_present++;
- /* initialize the envctrl bus controller */
- mutex_exit(&unitp->umutex);
- unitp->initting = B_TRUE;
- envctrl_init_bus(unitp);
- unitp->initting = B_FALSE;
- drv_usecwait(1000);
- mutex_enter(&unitp->umutex);
- /* Initialize the PCF8583 eggtimer registers */
- buf[0] = ALARM_CTR_REG_MINS;
- buf[1] = 0x0;
- status = eHc_write_pcf8583((struct eHc_envcunit *)unitp,
- PCF8583_BASE_ADDR | 0, buf, 2);
- if (status != DDI_SUCCESS)
- cmn_err(CE_WARN, "write to PCF8583 failed\n");
- buf[0] = ALARM_REG_MINS;
- buf[1] = 0x58;
- status = eHc_write_pcf8583((struct eHc_envcunit *)unitp,
- PCF8583_BASE_ADDR | 0, buf, 2);
- if (status != DDI_SUCCESS)
- cmn_err(CE_WARN, "write to PCF8583 failed\n");
- buf[0] = ALARM_TIMER_REG;
- buf[1] = 0x80;
- status = eHc_write_pcf8583((struct eHc_envcunit *)unitp,
- PCF8583_BASE_ADDR | 0, buf, 2);
- if (status != DDI_SUCCESS)
- cmn_err(CE_WARN, "write to PCF8583 failed\n");
- unitp->timeout_id = 0;
- unitp->blink_timeout_id = 0;
- if (envctrl_numcpus > 1) {
- unitp->num_cpus_present = envctrl_numcpus;
- }
- envctrl_probe_cpus(unitp);
- envctrl_ps_probe(unitp);
- /*
- * clear the fan failures, if any before we do
- * real work
- */
- unitp->initting = B_TRUE;
- envctrl_fan_fail_service(unitp);
- unitp->initting = B_FALSE;
- /*
- * we need to init the fan kstats before the tempr_poll
- */
- envctrl_add_kstats(unitp);
- envctrl_init_fan_kstats(unitp);
- envctrl_init_encl_kstats(unitp);
- if (unitp->activity_led_blink == B_TRUE) {
- unitp->present_led_state = B_FALSE;
- mutex_exit(&unitp->umutex);
- envctrl_led_blink((void *)unitp);
- mutex_enter(&unitp->umutex);
- } else {
- fspval = ENVCTRL_FSP_ACTIVE;
- envctrl_set_fsp(unitp, &fspval);
- }
- #ifndef TESTBED
- for (i = 0; i < ENVCTRL_MAX_CPUS; i++) {
- if (unitp->cpu_pr_location[i] == B_TRUE) {
- cputemp = envctrl_get_cpu_temp(unitp, i);
- envctrl_add_encl_kstats(unitp, ENVCTRL_ENCL_CPUTEMPR,
- i, cputemp);
- if (cputemp >= MAX_CPU_TEMP) {
- if (!(envctrl_power_off_overide)) {
- cmn_err(CE_WARN,
- "CPU %d OVERHEATING!!", i);
- unitp->shutdown = B_TRUE;
- } else {
- cmn_err(CE_WARN,
- "CPU %d OVERHEATING!!", i);
- }
- }
- }
- }
- #else
- cputemp = envctrl_get_cpu_temp(unitp, 0);
- envctrl_add_encl_kstats(unitp, ENVCTRL_ENCL_CPUTEMPR, INSTANCE_0,
- cputemp);
- #endif
- mutex_exit(&unitp->umutex);
- envctrl_tempr_poll((void *)unitp);
- /*
- * interpose envctrl's abort sequence handler
- */
- if (envctrl_handler) {
- abort_seq_handler = envctrl_abort_seq_handler;
- }
- ddi_report_dev(dip);
- return (DDI_SUCCESS);
- remhardintr1:
- ddi_remove_intr(dip, (uint_t)1, unitp->ic_trap_cookie);
- remhardintr:
- ddi_remove_intr(dip, (uint_t)0, unitp->ic_trap_cookie);
- remlock:
- mutex_destroy(&unitp->umutex);
- failed:
- if (unitp->ctlr_handle)
- ddi_regs_map_free(&unitp->ctlr_handle);
- cmn_err(CE_WARN, "envctrl_attach:failed.\n");
- return (DDI_FAILURE);
- }
- static int
- envctrl_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
- {
- int instance;
- struct envctrlunit *unitp;
- instance = ddi_get_instance(dip);
- unitp = ddi_get_soft_state(envctrlsoft_statep, instance);
- switch (cmd) {
- case DDI_DETACH:
- if (envctrl_allow_detach) {
- if (unitp->psksp != NULL) {
- kstat_delete(unitp->psksp);
- }
- if (unitp->fanksp != NULL) {
- kstat_delete(unitp->fanksp);
- }
- if (unitp->enclksp != NULL) {
- kstat_delete(unitp->enclksp);
- }
- if (unitp->timeout_id != 0) {
- (void) untimeout(unitp->timeout_id);
- unitp->timeout_id = 0;
- }
- if (unitp->blink_timeout_id != 0) {
- (void) untimeout(unitp->blink_timeout_id);
- unitp->blink_timeout_id = 0;
- }
- ddi_remove_minor_node(dip, NULL);
- ddi_remove_intr(dip, (uint_t)0, unitp->ic_trap_cookie);
- ddi_remove_intr(dip, (uint_t)1, unitp->ic_trap_cookie);
- ddi_regs_map_free(&unitp->ctlr_handle);
- mutex_destroy(&unitp->umutex);
- return (DDI_SUCCESS);
- } else {
- return (DDI_FAILURE);
- }
- case DDI_SUSPEND:
- if (!(unitp = ddi_get_soft_state(envctrlsoft_statep, instance)))
- return (DDI_FAILURE);
- mutex_enter(&unitp->umutex);
- if (unitp->suspended) {
- cmn_err(CE_WARN, "envctrl already suspended\n");
- mutex_exit(&unitp->umutex);
- return (DDI_FAILURE);
- }
- unitp->suspended = 1;
- mutex_exit(&unitp->umutex);
- return (DDI_SUCCESS);
- default:
- cmn_err(CE_WARN, "envctrl suspend general fault\n");
- return (DDI_FAILURE);
- }
- }
- /* ARGSUSED */
- int
- envctrl_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
- void **result)
- {
- dev_t dev = (dev_t)arg;
- struct envctrlunit *unitp;
- int ret;
- minor_t instance = getminor(dev);
- switch (infocmd) {
- case DDI_INFO_DEVT2DEVINFO:
- if ((unitp = (struct envctrlunit *)
- ddi_get_soft_state(envctrlsoft_statep,
- instance)) != NULL) {
- *result = unitp->dip;
- ret = DDI_SUCCESS;
- } else {
- *result = NULL;
- ret = DDI_FAILURE;
- }
- break;
- case DDI_INFO_DEVT2INSTANCE:
- *result = (void *)(uintptr_t)instance;
- ret = DDI_SUCCESS;
- break;
- default:
- ret = DDI_FAILURE;
- break;
- }
- return (ret);
- }
- /* ARGSUSED */
- static int
- envctrl_open(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *credp)
- {
- struct envctrlunit *unitp;
- int status = 0;
- int instance;
- instance = getminor(*dev);
- if (instance < 0)
- return (ENXIO);
- unitp = (struct envctrlunit *)
- ddi_get_soft_state(envctrlsoft_statep, instance);
- if (unitp == NULL)
- return (ENXIO);
- mutex_enter(&unitp->umutex);
- if (flag & FWRITE) {
- if ((unitp->oflag & FWRITE)) {
- mutex_exit(&unitp->umutex);
- return (EBUSY);
- } else {
- unitp->oflag |= FWRITE;
- }
- }
- q->q_ptr = WR(q)->q_ptr = (caddr_t)unitp;
- /*
- * if device is open with O_NONBLOCK flag set, let read(2) return 0
- * if no data waiting to be read. Writes will block on flow control.
- */
- /* enable the stream */
- qprocson(q);
- unitp->readq = RD(q);
- unitp->writeq = WR(q);
- unitp->msg = (mblk_t *)NULL;
- mutex_exit(&unitp->umutex);
- return (status);
- }
- /* ARGSUSED */
- static int
- envctrl_close(queue_t *q, int flag, cred_t *cred_p)
- {
- struct envctrlunit *unitp;
- unitp = (struct envctrlunit *)q->q_ptr;
- mutex_enter(&unitp->umutex);
- unitp->oflag = B_FALSE;
- unitp->current_mode = ENVCTRL_NORMAL_MODE;
- /* disable the stream */
- q->q_ptr = WR(q)->q_ptr = NULL;
- qprocsoff(q);
- mutex_exit(&unitp->umutex);
- return (DDI_SUCCESS);
- }
- /*
- * standard put procedure for envctrl
- */
- static int
- envctrl_wput(queue_t *q, mblk_t *mp)
- {
- struct msgb *mp1;
- struct envctrlunit *unitp;
- struct iocblk *iocp;
- struct copyresp *csp;
- struct envctrl_tda8444t_chip *fanspeed;
- struct envctrl_pcf8574_chip *ledchip;
- struct envctrl_pcf8591_chip *temp, *a_fanspeed;
- struct copyreq *cqp;
- int cmd;
- unitp = (struct envctrlunit *)q->q_ptr;
- switch (DB_TYPE(mp)) {
- case M_DATA:
- while (mp) {
- DB_TYPE(mp) = M_DATA;
- mp1 = unlinkb(mp);
- mp->b_cont = NULL;
- if ((mp->b_wptr - mp->b_rptr) <= 0) {
- freemsg(mp);
- } else {
- (void) putq(q, mp);
- }
- mp = mp1;
- }
- break;
- case M_IOCTL:
- {
- iocp = (struct iocblk *)(void *)mp->b_rptr;
- cmd = iocp->ioc_cmd;
- switch (cmd) {
- case ENVCTRL_IOC_SETMODE:
- case ENVCTRL_IOC_GETMODE:
- if (iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (uchar_t), NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_RESETTMPR:
- /*
- * For diags, cancel the current temp poll
- * and reset it for a new one.
- */
- if (unitp->current_mode == ENVCTRL_DIAG_MODE) {
- if (unitp->timeout_id != 0) {
- (void) untimeout(unitp->timeout_id);
- unitp->timeout_id = 0;
- }
- envctrl_tempr_poll((void *)unitp);
- miocack(q, mp, 0, 0);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_GETTEMP:
- if (iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (struct envctrl_pcf8591_chip), NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_SETTEMP:
- if (unitp->current_mode == ENVCTRL_DIAG_MODE &&
- iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (uint8_t), NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_SETWDT:
- if (unitp->current_mode == ENVCTRL_DIAG_MODE &&
- iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (uint8_t), NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_SETFAN:
- /*
- * we must be in diag mode before we can
- * set any fan speeds.
- */
- if (unitp->current_mode == ENVCTRL_DIAG_MODE &&
- iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (struct envctrl_tda8444t_chip),
- NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_GETFAN:
- if (iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (struct envctrl_pcf8591_chip), NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_SETFSP:
- if (iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (uint8_t), NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- case ENVCTRL_IOC_SETDSKLED:
- case ENVCTRL_IOC_GETDSKLED:
- if (iocp->ioc_count == TRANSPARENT) {
- mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
- sizeof (struct envctrl_pcf8574_chip), NULL);
- qreply(q, mp);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- default:
- miocnak(q, mp, 0, EINVAL);
- break;
- }
- break;
- }
- case M_IOCDATA:
- {
- uint8_t *tempr, *wdval;
- long state;
- csp = (struct copyresp *)(void *)mp->b_rptr;
- /*
- * If copy request failed, quit now
- */
- if (csp->cp_rval != 0) {
- miocnak(q, mp, 0, EINVAL);
- return (0);
- }
- cqp = (struct copyreq *)(void *)mp->b_rptr;
- cmd = csp->cp_cmd;
- state = (long)cqp->cq_private;
- switch (cmd) {
- case ENVCTRL_IOC_SETFAN:
- fanspeed = (struct envctrl_tda8444t_chip *)
- (void *)mp->b_cont->b_rptr;
- mutex_enter(&unitp->umutex);
- if (envctrl_xmit(unitp, (caddr_t *)(void *)fanspeed,
- fanspeed->type) == DDI_FAILURE) {
- /*
- * Fix for a ADF bug
- * move mutex to after fan fail call
- * bugid 4016121
- */
- envctrl_fan_fail_service(unitp);
- mutex_exit(&unitp->umutex);
- miocnak(q, mp, 0, EINVAL);
- } else {
- mutex_exit(&unitp->umutex);
- miocack(q, mp, 0, 0);
- }
- break;
- case ENVCTRL_IOC_SETFSP:
- wdval = (uint8_t *)(void *)mp->b_cont->b_rptr;
- mutex_enter(&unitp->umutex);
- /*
- * If a user is in normal mode and they try
- * to set anything other than a disk fault or
- * a gen fault it is an invalid operation.
- * in diag mode we allow everything to be
- * twiddled.
- */
- if (unitp->current_mode == ENVCTRL_NORMAL_MODE) {
- if (*wdval & ~ENVCTRL_FSP_USRMASK) {
- mutex_exit(&unitp->umutex);
- miocnak(q, mp, 0, EINVAL);
- break;
- }
- }
- envctrl_set_fsp(unitp, wdval);
- mutex_exit(&unitp->umutex);
- miocack(q, mp, 0, 0);
- break;
- case ENVCTRL_IOC_SETDSKLED:
- ledchip = (struct envctrl_pcf8574_chip *)
- (void *)mp->b_cont->b_rptr;
- mutex_enter(&unitp->umutex);
- if (envctrl_set_dskled(unitp, ledchip)) {
- miocnak(q, mp, 0, EINVAL);
- } else {
- miocack(q, mp, 0, 0);
- }
- mutex_exit(&unitp->umutex);
- break;
- case ENVCTRL_IOC_GETDSKLED:
- if (state == -1) {
- miocack(q, mp, 0, 0);
- break;
- }
- ledchip = (struct envctrl_pcf8574_chip *)
- (void *)mp->b_cont->b_rptr;
- mutex_enter(&unitp->umutex);
- if (envctrl_get_dskled(unitp, ledchip)) {
- miocnak(q, mp, 0, EINVAL);
- } else {
- mcopyout(mp, (void *)-1,
- sizeof (struct envctrl_pcf8574_chip),
- csp->cp_private, NULL);
- qreply(q, mp);
- }
- mutex_exit(&unitp->umutex);
- break;
- case ENVCTRL_IOC_GETTEMP:
- /* Get the user buffer address */
- if (state == -1) {
- miocack(q, mp, 0, 0);
- break;
- }
- temp = (struct envctrl_pcf8591_chip *)
- (void *)mp->b_cont->b_rptr;
- mutex_enter(&unitp->umutex);
- envctrl_recv(unitp, (caddr_t *)(void *)temp, PCF8591);
- mutex_exit(&unitp->umutex);
- mcopyout(mp, (void *)-1,
- sizeof (struct envctrl_pcf8591_chip),
- csp->cp_private, NULL);
- qreply(q, mp);
- break;
- case ENVCTRL_IOC_GETFAN:
- /* Get the user buffer address */
- if (state == -1) {
- miocack(q, mp, 0, 0);
- break;
- }
- a_fanspeed = (struct envctrl_pcf8591_chip *)
- (void *)mp->b_cont->b_rptr;
- mutex_enter(&unitp->umutex);
- envctrl_recv(unitp, (caddr_t *)(void *)a_fanspeed,
- PCF8591);
- mutex_exit(&unitp->umutex);
- mcopyout(mp, (void *)-1,
- sizeof (struct envctrl_pcf8591_chip),
- csp->cp_private, NULL);
- qreply(q, mp);
- break;
- case ENVCTRL_IOC_SETTEMP:
- tempr = (uint8_t *)(void *)mp->b_cont->b_rptr;
- if (*tempr > MAX_DIAG_TEMPR) {
- miocnak(q, mp, 0, EINVAL);
- } else {
- mutex_enter(&unitp->umutex);
- envctrl_get_sys_temperatures(unitp, tempr);
- mutex_exit(&unitp->umutex);
- miocack(q, mp, 0, 0);
- }
- break;
- case ENVCTRL_IOC_SETWDT:
- /* reset watchdog timeout period */
- wdval = (uint8_t *)(void *)mp->b_cont->b_rptr;
- if (*wdval > MAX_CL_VAL) {
- miocnak(q, mp, 0, EINVAL);
- } else {
- mutex_enter(&unitp->umutex);
- envctrl_reset_watchdog(unitp, wdval);
- mutex_exit(&unitp->umutex);
- miocack(q, mp, 0, 0);
- }
- break;
- case ENVCTRL_IOC_GETMODE:
- /* Get the user buffer address */
- if (state == -1) {
- miocack(q, mp, 0, 0);
- break;
- }
- tempr = (uchar_t *)(void *)mp->b_cont->b_rptr;
- *tempr = unitp->current_mode;
- mcopyout(mp, (void *)-1, sizeof (uchar_t),
- csp->cp_private, NULL);
- qreply(q, mp);
- break;
- case ENVCTRL_IOC_SETMODE:
- /* Set mode */
- wdval = (uint8_t *)(void *)mp->b_cont->b_rptr;
- if (*wdval == ENVCTRL_DIAG_MODE || *wdval ==
- ENVCTRL_NORMAL_MODE) {
- mutex_enter(&unitp->umutex);
- unitp->current_mode = *wdval;
- if (unitp->timeout_id != 0 &&
- *wdval == ENVCTRL_DIAG_MODE) {
- (void) untimeout(unitp->timeout_id);
- unitp->timeout_id =
- (timeout(envctrl_tempr_poll,
- (caddr_t)unitp,
- overtemp_timeout_hz));
- }
- if (*wdval == ENVCTRL_NORMAL_MODE) {
- envctrl_get_sys_temperatures(unitp,
- (uint8_t *)NULL);
- /*
- * going to normal mode we
- * need to go to diag mode
- * just in case we have
- * injected a fan fault. It
- * may not be cleared and if
- * we call fan_failsrvc it will
- * power off the ystem if we are
- * in NORMAL_MODE. Also we need
- * to delay 1 bit of time here
- * to allow the fans to rotate
- * back up and clear the intr
- * after we get the sys temps.
- */
- unitp->current_mode =
- ENVCTRL_DIAG_MODE;
- envctrl_fan_fail_service(unitp);
- unitp->current_mode =
- ENVCTRL_NORMAL_MODE;
- }
- mutex_exit(&unitp->umutex);
- miocack(q, mp, 0, 0);
- } else {
- miocnak(q, mp, 0, EINVAL);
- }
- break;
- default:
- freemsg(mp);
- break;
- }
- break;
- }
- case M_FLUSH:
- if (*mp->b_rptr & FLUSHR) {
- *mp->b_rptr &= ~FLUSHW;
- qreply(q, mp);
- } else {
- freemsg(mp);
- }
- break;
- default:
- freemsg(mp);
- break;
- }
- return (0);
- }
- uint_t
- envctrl_bus_isr(caddr_t arg)
- {
- struct envctrlunit *unitp = (struct envctrlunit *)(void *)arg;
- int ic = DDI_INTR_UNCLAIMED;
- mutex_enter(&unitp->umutex);
- /*
- * NOT USED
- */
- mutex_exit(&unitp->umutex);
- return (ic);
- }
- uint_t
- envctrl_dev_isr(caddr_t arg)
- {
- struct envctrlunit *unitp = (struct envctrlunit *)(void *)arg;
- uint8_t recv_data;
- int ic;
- int retrys = 0;
- int status;
- ic = DDI_INTR_UNCLAIMED;
- mutex_enter(&unitp->umutex);
- /*
- * First check to see if it is an interrupt for us by
- * looking at the "ganged" interrrupt and vector
- * according to the major type
- * 0x70 is the addr of the ganged interrupt controller.
- * Address map for the port byte read is as follows
- * MSB
- * -------------------------
- * | | | | | | | | |
- * -------------------------
- * P7 P6 P5 P4 P3 P2 P1 P0
- * P0 = Power Supply 1 intr
- * P1 = Power Supply 2 intr
- * P2 = Power Supply 3 intr
- * P3 = Dlfop enable for fan sped set
- * P4 = ENVCTRL_ Fan Fail intr
- * P5 = Front Panel Interrupt
- * P6 = Power Fail Detect Low.
- * P7 = Enable Interrupts to system
- */
- retry:
- status = eHc_read_pcf8574a((struct eHc_envcunit *)unitp,
- PCF8574A_BASE_ADDR | ENVCTRL_PCF8574_DEV0, &recv_data, 1);
- /*
- * This extra read is needed since the first read is discarded
- * and the second read seems to return 0xFF.
- */
- if (recv_data == 0xFF) {
- status = eHc_read_pcf8574a((struct eHc_envcunit *)unitp,
- PCF8574A_BASE_ADDR | ENVCTRL_PCF8574_DEV0, &recv_data, 1);
- }
- if (envctrl_debug_flags)
- cmn_err(CE_WARN, "envctrl_dev_isr: status= %d, data = %x\n",
- status, recv_data);
- /*
- * if the i2c bus is hung it is imperative that this
- * be cleared on an interrupt or else it will
- * hang the system with continuous interrupts
- */
- if (status == DDI_FAILURE) {
- drv_usecwait(1000);
- if (retrys < envctrl_max_retries) {
- retrys++;
- goto retry;
- } else {
- if (envctrl_debug_flags)
- cmn_err(CE_WARN,
- "DEVISR FAILED received 0x%x\n", recv_data);
- mutex_exit(&unitp->umutex);
- envctrl_init_bus(unitp);
- mutex_enter(&unitp->umutex);
- envctrl_ps_probe(unitp);
- mutex_exit(&unitp->umutex);
- ic = DDI_INTR_CLAIMED;
- return (ic);
- }
- }
- /*
- * Port 0 = PS1 interrupt
- * Port 1 = PS2 Interrupt
- * Port 2 = PS3 Interrupt
- * Port 3 = SPARE
- * Port 4 = Fan Fail Intr
- * Port 5 = Front Panle Module intr
- * Port 6 = Keyswitch Intr
- * Port 7 = ESINTR ENABLE ???
- */
- if (!(recv_data & ENVCTRL_PCF8574_PORT0)) {
- envctrl_PS_intr_service(unitp, PS1);
- ic = DDI_INTR_CLAIMED;
- }
- if (!(recv_data & ENVCTRL_PCF8574_PORT1)) {
- envctrl_PS_intr_service(unitp, PS2);
- ic = DDI_INTR_CLAIMED;
- }
- if (!(recv_data & ENVCTRL_PCF8574_PORT2)) {
- envctrl_PS_intr_service(unitp, PS3);
- ic = DDI_INTR_CLAIMED;
- }
- if (!(recv_data & ENVCTRL_PCF8574_PORT3)) {
- ic = DDI_INTR_CLAIMED;
- }
- if (!(recv_data & ENVCTRL_PCF8574_PORT4)) {
- /*
- * Check for a fan fail
- * Single fan fail
- * shutdown system
- */
- envctrl_fan_fail_service(unitp);
- ic = DDI_INTR_CLAIMED;
- }
- if (!(recv_data & ENVCTRL_PCF8574_PORT5)) {
- (void) envctrl_get_fpm_status(unitp);
- ic = DDI_INTR_CLAIMED;
- }
- if (!(recv_data & ENVCTRL_PCF8574_PORT6)) {
- ic = DDI_INTR_CLAIMED;
- }
- if (!(recv_data & ENVCTRL_PCF8574_PORT7)) {
- ic = DDI_INTR_CLAIMED;
- }
- if ((recv_data == 0xFF)) {
- ic = DDI_INTR_CLAIMED;
- }
- mutex_exit(&unitp->umutex);
- return (ic);
- }
- static void
- envctrl_init_bus(struct envctrlunit *unitp)
- {
- int i;
- uint8_t noval = NULL;
- struct envctrl_tda8444t_chip fan;
- int fans[] = {ENVCTRL_CPU_FANS, ENVCTRL_PS_FANS, ENVCTRL_AFB_FANS};
- mutex_enter(&unitp->umutex);
- /* Sets the Mode to 808x type bus */
- ddi_put8(unitp->ctlr_handle,
- &unitp->bus_ctl_regs->s0, ENVCTRL_CHAR_ZERO);
- /* SET UP SLAVE ADDR XXX Required..send 0x80 */
- ddi_put8(unitp->ctlr_handle, &unitp->bus_ctl_regs->s1,
- ENVCTRL_BUS_INIT0);
- (void) ddi_put8(unitp->ctlr_handle, &unitp->bus_ctl_regs->s0,
- ENVCTRL_BUS_INIT1);
- /* Set the clock now */
- ddi_put8(unitp->ctlr_handle,
- &unitp->bus_ctl_regs->s1, ENVCTRL_BUS_CLOCK0);
- /* S0 is now S2 necause of the previous write to S1 */
- /* clock= 12MHz, SCL=90KHz */
- ddi_put8(unitp->ctlr_handle,
- &unitp->bus_ctl_regs->s0, ENVCTRL_BUS_CLOCK1);
- /* Enable serial interface */
- ddi_put8(unitp->ctlr_handle,
- &unitp->bus_ctl_regs->s1, ENVCTRL_BUS_ESI);
- envctrl_stop_clock(unitp);
- /*
- * This has been added here because the DAC is powered
- * on at "0". When the reset_dflop routine is called
- * this switched the fans from blast to DAC control.
- * if the DAC is at "0", then the fans momentarily lose
- * power until the temp polling and fan set routine is
- * first called. If the fans lose power, then there is
- * a fan fault generated and the system will power off.
- * We only want to do this IF the bus is first being
- * initted. This will cause errors in Sunvts if we reset
- * the fan speed under normal operation. Sometimes we need
- * to be able to induce fan faults. Init bus is a common
- * routine to unwedge the i2c bus in some cases.
- */
- if (unitp->initting == B_TRUE) {
- fan.chip_num = ENVCTRL_TDA8444T_DEV7;
- fan.val = INIT_FAN_VAL;
- for (i = 0; i < sizeof (fans)/sizeof (int); i++) {
- fan.fan_num = fans[i];
- if ((fans[i] == ENVCTRL_AFB_FANS) &&
- (unitp->AFB_present == B_FALSE))
- continue;
- (void) envctrl_xmit(unitp, (caddr_t *)(void *)&fan,
- TDA8444T);
- }
- }
- envctrl_reset_dflop(unitp);
- envctrl_enable_devintrs(unitp);
- unitp->current_mode = ENVCTRL_NORMAL_MODE;
- envctrl_reset_watchdog(unitp, &noval);
- mutex_exit(&unitp->umutex);
- }
- static int
- envctrl_xmit(struct envctrlunit *unitp, caddr_t *data, int chip_type)
- {
- struct envctrl_tda8444t_chip *fanspeed;
- struct envctrl_pcf8574_chip *ioport;
- uint8_t slave_addr;
- uint8_t buf[2];
- int retrys = 0;
- int status;
- ASSERT(MUTEX_HELD(&unitp->umutex));
- switch (chip_type) {
- case TDA8444T:
- fanspeed = (struct envctrl_tda8444t_chip *)data;
- if (fanspeed->chip_num > ENVCTRL_FAN_ADDR_MAX) {
- return (DDI_FAILURE);
- }
- if (fanspeed->fan_num > ENVCTRL_PORT7) {
- return (DDI_FAILURE);
- }
- if (fanspeed->val > MAX_FAN_VAL) {
- return (DDI_FAILURE);
- }
- retry0:
- slave_addr = (TDA8444T_BASE_ADDR | fanspeed->chip_num);
- buf[0] = fanspeed->val;
- status = eHc_write_tda8444((struct eHc_envcunit *)unitp,
- TDA8444T_BASE_ADDR | fanspeed->chip_num, 0xF,
- fanspeed->fan_num, buf, 1);
- if (status != DDI_SUCCESS) {
- drv_usecwait(1000);
- if (retrys < envctrl_max_retries) {
- retrys++;
- goto retry0;
- } else {
- mutex_exit(&unitp->umutex);
- envctrl_init_bus(unitp);
- mutex_enter(&unitp->umutex);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN,
- "envctrl_xmit: Write to TDA8444 " \
- "failed\n");
- return (DDI_FAILURE);
- }
- }
- /*
- * Update the kstats.
- */
- switch (fanspeed->fan_num) {
- case ENVCTRL_CPU_FANS:
- unitp->fan_kstats[ENVCTRL_FAN_TYPE_CPU].fanspeed =
- fanspeed->val;
- break;
- case ENVCTRL_PS_FANS:
- unitp->fan_kstats[ENVCTRL_FAN_TYPE_PS].fanspeed =
- fanspeed->val;
- break;
- case ENVCTRL_AFB_FANS:
- unitp->fan_kstats[ENVCTRL_FAN_TYPE_AFB].fanspeed =
- fanspeed->val;
- break;
- default:
- break;
- }
- break;
- case PCF8574:
- ioport = (struct envctrl_pcf8574_chip *)data;
- buf[0] = ioport->val;
- if (ioport->chip_num > ENVCTRL_PCF8574_DEV7)
- return (DDI_FAILURE);
- retry:
- if (ioport->type == PCF8574A) {
- slave_addr = (PCF8574A_BASE_ADDR | ioport->chip_num);
- status =
- eHc_write_pcf8574a((struct eHc_envcunit *)unitp,
- PCF8574A_BASE_ADDR | ioport->chip_num, buf, 1);
- } else {
- slave_addr = (PCF8574_BASE_ADDR | ioport->chip_num);
- status = eHc_write_pcf8574((struct eHc_envcunit *)unitp,
- PCF8574_BASE_ADDR | ioport->chip_num, buf, 1);
- }
- if (status != DDI_SUCCESS) {
- drv_usecwait(1000);
- if (retrys < envctrl_max_retries) {
- retrys++;
- goto retry;
- } else {
- mutex_exit(&unitp->umutex);
- envctrl_init_bus(unitp);
- mutex_enter(&unitp->umutex);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN, "Write to PCF8574 " \
- "failed, addr = %X\n", slave_addr);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN, "envctrl_xmit: PCF8574\
- dev = %d, port = %d\n",
- ioport->chip_num, ioport->type);
- return (DDI_FAILURE);
- }
- }
- break;
- default:
- return (DDI_FAILURE);
- }
- return (DDI_SUCCESS);
- }
- static void
- envctrl_recv(struct envctrlunit *unitp, caddr_t *data, int chip_type)
- {
- struct envctrl_pcf8591_chip *temp;
- struct envctrl_pcf8574_chip *ioport;
- uint8_t slave_addr, recv_data;
- int retrys = 0;
- int status;
- uint8_t buf[1];
- ASSERT(MUTEX_HELD(&unitp->umutex));
- switch (chip_type) {
- case PCF8591:
- temp = (struct envctrl_pcf8591_chip *)data;
- slave_addr = (PCF8591_BASE_ADDR | temp->chip_num);
- retry:
- status = eHc_read_pcf8591((struct eHc_envcunit *)unitp,
- PCF8591_BASE_ADDR | temp->chip_num & 0xF,
- temp->sensor_num, 0, 0, 1, &recv_data, 1);
- /*
- * another place to catch the i2c bus hang on an 8591 read
- * In this instance we will just return the data that is read
- * after the max_retry because this could be a valid value.
- */
- if (status != DDI_SUCCESS) {
- drv_usecwait(1000);
- if (retrys < envctrl_max_retries) {
- retrys++;
- goto retry;
- } else {
- mutex_exit(&unitp->umutex);
- envctrl_init_bus(unitp);
- mutex_enter(&unitp->umutex);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN, "Read from PCF8591 " \
- "failed, slave_addr = %x\n",
- slave_addr);
- }
- }
- temp->temp_val = recv_data;
- break;
- case TDA8444T:
- printf("envctrl_recv: attempting to read TDA8444T\n");
- return;
- case PCF8574:
- ioport = (struct envctrl_pcf8574_chip *)data;
- retry1:
- if (ioport->chip_num > ENVCTRL_PCF8574_DEV7)
- cmn_err(CE_WARN, "envctrl: dev out of range 0x%x\n",
- ioport->chip_num);
- if (ioport->type == PCF8574A) {
- slave_addr = (PCF8574_READ_BIT | PCF8574A_BASE_ADDR |
- ioport->chip_num);
- status = eHc_read_pcf8574a((struct eHc_envcunit *)unitp,
- PCF8574A_BASE_ADDR | ioport->chip_num, buf, 1);
- } else {
- slave_addr = (PCF8574_READ_BIT | PCF8574_BASE_ADDR |
- ioport->chip_num);
- status = eHc_read_pcf8574((struct eHc_envcunit *)unitp,
- PCF8574_BASE_ADDR | ioport->chip_num, buf, 1);
- }
- if (status != DDI_SUCCESS) {
- drv_usecwait(1000);
- if (retrys < envctrl_max_retries) {
- retrys++;
- goto retry1;
- } else {
- mutex_exit(&unitp->umutex);
- envctrl_init_bus(unitp);
- mutex_enter(&unitp->umutex);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN, "Read from PCF8574 "\
- "failed, addr = %X\n", slave_addr);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN, "envctrl_recv: PCF8574\
- dev = %d, port = %d\n",
- ioport->chip_num, ioport->type);
- }
- }
- ioport->val = buf[0];
- break;
- default:
- break;
- }
- }
- static int
- envctrl_get_ps_temp(struct envctrlunit *unitp, uint8_t psaddr)
- {
- uint8_t tempr;
- int i, retrys;
- int status;
- uint8_t buf[4];
- ASSERT(MUTEX_HELD(&unitp->umutex));
- tempr = 0;
- retrys = 0;
- retry:
- status = eHc_read_pcf8591((struct eHc_envcunit *)unitp,
- PCF8591_BASE_ADDR | psaddr & 0xF, 0, 1, 0, 1, buf, 4);
- tempr = 0;
- for (i = 0; i < PCF8591_MAX_PORTS; i++) {
- /*
- * The pcf8591 will return 0xff if no port
- * is there.. this is bogus for setting temps.
- * so just ignore it!
- */
- if (envctrl_debug_flags) {
- cmn_err(CE_WARN, "PS addr 0x%x recvd 0x%x on port %d\n",
- psaddr, buf[i], i);
- }
- if (buf[i] > tempr && buf[i] < MAX_PS_ADVAL) {
- tempr = buf[i];
- }
- }
- /*
- * This routine is a safeguard to make sure that if the
- * powersupply temps cannot be read that we do something
- * to make sure that the system will notify the user and
- * it will stay running with the fans at 100%. The calling
- * routine should take care of that.
- */
- if (status != DDI_SUCCESS) {
- drv_usecwait(1000);
- if (retrys < envctrl_max_retries) {
- retrys++;
- goto retry;
- } else {
- mutex_exit(&unitp->umutex);
- envctrl_init_bus(unitp);
- mutex_enter(&unitp->umutex);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN,
- "Cannot read Power Supply Temps addr = %X",
- psaddr);
- return (PS_DEFAULT_VAL);
- }
- }
- return (ps_temps[tempr]);
- }
- static int
- envctrl_get_cpu_temp(struct envctrlunit *unitp, int cpunum)
- {
- uint8_t recv_data;
- int retrys;
- int status;
- ASSERT(MUTEX_HELD(&unitp->umutex));
- /*
- * This routine takes in the number of the port that
- * we want to read in the 8591. This should be the
- * location of the COU thermistor for one of the 4
- * cpu's. It will return the temperature in degrees C
- * to the caller.
- */
- retrys = 0;
- retry:
- status = eHc_read_pcf8591((struct eHc_envcunit *)unitp,
- PCF8591_BASE_ADDR | PCF8591_DEV7, cpunum, 0, 0, 0,
- &recv_data, 1);
- /*
- * We need to take a sledge hammer to the bus if we get back
- * value of the chip. This means that the i2c bus got wedged.
- * On the 1.4 systems this happens sometimes while running
- * sunvts. We will return the max cpu temp minus 10 to make
- * the fans run at full speed so that we don;t cook the
- * system.
- * At this point this is a workaround for hardware glitch.
- */
- if (status == DDI_FAILURE) {
- drv_usecwait(1000);
- if (retrys < envctrl_max_retries) {
- retrys++;
- goto retry;
- } else {
- mutex_exit(&unitp->umutex);
- envctrl_init_bus(unitp);
- mutex_enter(&unitp->umutex);
- if (envctrl_debug_flags)
- cmn_err(CE_WARN, "envctrl CPU TEMP read " \
- "failed\n");
- /* we don't want to power off the system */
- return (MAX_CPU_TEMP - 10);
- }
- }
- return (cpu_temps[recv_data]);
- }
- static int
- envctrl_get_lm75_temp(struct envctrlunit *unitp)
- {
- int k;
- ushort_t lmval;
- uint8_t tmp1;
- uint8_t tmp2;
- int status;
- uint8_t buf[2];
- ASSERT(MUTEX_HELD(&unitp->umutex));
- status = eHc_read_lm75((struct eHc_envcunit *)unitp,
- LM75_BASE_ADDR | LM75_CONFIG_ADDRA, buf, 2);
- if (status != DDI_SUCCESS)
- cmn_err(CE_WARN, "read of LM75 failed\n");
- tmp1 = buf[0];
- tmp2 = buf[1];
- /*
- * Store the forst 8 bits in the upper nibble of the
- * short, then store the lower 8 bits in the lower nibble
- * of the short, shift 7 to the right to get the 9 bit value
- * that the lm75 is really sending.
- */
- lmval = tmp1 << 8;
- lmval = (lmval | tmp2);
- lmval = (lmval >> 7);
- /*
- * Check the 9th bit to see if it is a negative
- * temperature. If so change into 2's compliment
- * and divide by 2 since each value is equal to a
- * half degree strp in degrees C
- */
- if (lmval & LM75_COMP_MASK) {
- tmp1 = (lmval & LM75_COMP_MASK_UPPER);
- tmp1 = -tmp1;
- tmp1 = tmp1/2;
- k = 0 - tmp1;
- } else {
- k = lmval /2;
- }
- return (k);
- }
- static void
- envctrl_tempr_poll(void *arg)
- {
- int diag_flag = 0;
- struct envctrlunit *unitp = (struct envctrlunit *)arg;
- mutex_enter(&unitp->umutex);
- if (unitp->shutdown == B_TRUE) {
- (void) power_down("Fatal System Environmental Control Error");
- }
- /*
- * if we are in diag mode and the temp poll thread goes off,
- * this means that the system is too heavily loaded and the 60 second
- * window to execute the test is failing. We will change the fanspeed
- * but will not check for a fanfault. This will cause a system shutdown
- * if the system has had a fanfault injected.
- */
- if (unitp->current_mode == ENVCTRL_DIAG_MODE) {
- diag_flag++;
- if (envctrl_debug_flags) {
- cmn_err(CE_WARN,
- "Tempr poll went off while in DIAG MODE");
- }
- }
- unitp->current_mode = ENVCTRL_NORMAL_MODE;
- envctrl_get_sys_temperatures(unitp, (uint8_t *)NULL);
- if (diag_flag == 0) {
- envctrl_fan_fail_service(unitp);
- }
- /* now have this thread sleep for a while */
- unitp->timeout_id = (timeout(envctrl_tempr_poll,
- (caddr_t)unitp, overtemp_timeout_hz));
- mutex_exit(&unitp->umutex);
- }
- static void
- envctrl_led_blink(void *arg)
- {
- struct envctrl_pcf8574_chip fspchip;
- struct envctrlunit *unitp = (struct envctrlunit *)arg;
- mutex_enter(&unitp->umutex);
- fspchip.type = PCF8574A;
- fspchip.chip_num = ENVCTRL_PCF8574_DEV6; /* 0x01 port 1 */
- envctrl_recv(unitp, (caddr_t *)(void *)&fspchip, PCF8574);
- if (unitp->present_led_state == B_TRUE) {
- /*
- * Now we need to "or" in fault bits of the FSP
- * module for the mass storage fault led.
- * and set it.
- */
- fspchip.val = (fspchip.val & ~(ENVCTRL_PCF8574_PORT4) |
- 0xC0);
- unitp->present_led_state = B_FALSE;
- } else {
- fspchip.val = (fspchip.val | ENVCTRL_PCF8574_PORT4 | 0xC0);
- unitp->present_led_state = B_TRUE;
- }
- (void) envctrl_xmit(unitp, (caddr_t *)(void *)&fspchip, PCF8574);
- /* now have this thread sleep for a while */
- unitp->blink_timeout_id = (timeout(envctrl_led_blink,
- (caddr_t)unitp, blink_timeout_hz));
- mutex_exit(&unitp->umutex);
- }
- /* called with mutex held */
- static void
- envctrl_get_sys_temperatures(struct envctrlunit *unitp, uint8_t *diag_tempr)
- {
- int temperature, tmptemp, cputemp, hicputemp, ambtemp;
- int i;
- struct envctrl_tda8444t_chip fan;
- uint8_t psaddr[] = {PSTEMP3, PSTEMP2, PSTEMP1, PSTEMP0};
- uint8_t noval = NULL;
- uint8_t fspval;
- ASSERT(MUTEX_HELD(&unitp->umutex));
- fan.fan_num = ENVCTRL_CPU_FANS;
- fan.chip_num = ENVCTRL_TDA8444T_DEV7;
- tmptemp = 0; /* Right init value ?? */
- /*
- * THis routine is caled once every minute
- * we wil re-se the watchdog timer each time
- * we poll the temps. The watchdog timer is
- * set up for 3 minutes. Should the kernel thread
- * wedge, for some reason the watchdog will go off
- * and blast the fans.
- */
- if (…
Large files files are truncated, but you can click here to view the full file