PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/usr/src/uts/sun4u/tazmo/io/envctrl.c

https://bitbucket.org/jimklimov/illumos-gate
C | 4101 lines | 2781 code | 595 blank | 725 comment | 655 complexity | 408a973f82f257af244f86a1b31441fd MD5 | raw file
Possible License(s): BSD-3-Clause-No-Nuclear-License-2014, AGPL-1.0, AGPL-3.0, GPL-2.0, GPL-3.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.1, LGPL-3.0, LGPL-2.0, 0BSD

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * CDDL HEADER START
  3. *
  4. * The contents of this file are subject to the terms of the
  5. * Common Development and Distribution License (the "License").
  6. * You may not use this file except in compliance with the License.
  7. *
  8. * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  9. * or http://www.opensolaris.org/os/licensing.
  10. * See the License for the specific language governing permissions
  11. * and limitations under the License.
  12. *
  13. * When distributing Covered Code, include this CDDL HEADER in each
  14. * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15. * If applicable, add the following below this CDDL HEADER, with the
  16. * fields enclosed by brackets "[]" replaced with your own identifying
  17. * information: Portions Copyright [yyyy] [name of copyright owner]
  18. *
  19. * CDDL HEADER END
  20. */
  21. /*
  22. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  23. * Use is subject to license terms.
  24. */
  25. /*
  26. * ENVCTRL_ Environment Monitoring driver for i2c
  27. *
  28. */
  29. #include <sys/param.h>
  30. #include <sys/types.h>
  31. #include <sys/signal.h>
  32. #include <sys/errno.h>
  33. #include <sys/file.h>
  34. #include <sys/termio.h>
  35. #include <sys/termios.h>
  36. #include <sys/cmn_err.h>
  37. #include <sys/stream.h>
  38. #include <sys/strsun.h>
  39. #include <sys/stropts.h>
  40. #include <sys/strtty.h>
  41. #include <sys/debug.h>
  42. #include <sys/eucioctl.h>
  43. #include <sys/cred.h>
  44. #include <sys/uio.h>
  45. #include <sys/stat.h>
  46. #include <sys/kmem.h>
  47. #include <sys/ddi.h>
  48. #include <sys/sunddi.h>
  49. #include <sys/obpdefs.h>
  50. #include <sys/conf.h> /* req. by dev_ops flags MTSAFE etc. */
  51. #include <sys/modctl.h> /* for modldrv */
  52. #include <sys/stat.h> /* ddi_create_minor_node S_IFCHR */
  53. #include <sys/open.h> /* for open params. */
  54. #include <sys/uio.h> /* for read/write */
  55. #include <sys/envctrl.h> /* Environment header */
  56. /* driver entry point fn definitions */
  57. static int envctrl_open(queue_t *, dev_t *, int, int, cred_t *);
  58. static int envctrl_close(queue_t *, int, cred_t *);
  59. static uint_t envctrl_bus_isr(caddr_t);
  60. static uint_t envctrl_dev_isr(caddr_t);
  61. /* configuration entry point fn definitions */
  62. static int envctrl_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
  63. static int envctrl_attach(dev_info_t *, ddi_attach_cmd_t);
  64. static int envctrl_detach(dev_info_t *, ddi_detach_cmd_t);
  65. /* Driver private routines */
  66. static void envctrl_init_bus(struct envctrlunit *);
  67. static int envctrl_xmit(struct envctrlunit *, caddr_t *, int);
  68. static void envctrl_recv(struct envctrlunit *, caddr_t *, int);
  69. static void envctrl_get_sys_temperatures(struct envctrlunit *, uint8_t *);
  70. static int envctrl_get_lm75_temp(struct envctrlunit *);
  71. static int envctrl_get_ps_temp(struct envctrlunit *, uint8_t);
  72. static int envctrl_get_cpu_temp(struct envctrlunit *, int);
  73. static void envctrl_fan_fail_service(struct envctrlunit *);
  74. static void envctrl_PS_intr_service(struct envctrlunit *, uint8_t);
  75. static void envctrl_ps_probe(struct envctrlunit *);
  76. static void envctrl_tempr_poll(void *);
  77. static void envctrl_pshotplug_poll(void *);
  78. static void envctrl_led_blink(void *);
  79. static void envctrl_reset_dflop(struct envctrlunit *);
  80. static void envctrl_enable_devintrs(struct envctrlunit *);
  81. static void envctrl_stop_clock(struct envctrlunit *);
  82. static void envctrl_reset_watchdog(struct envctrlunit *, uint8_t *);
  83. static void envctrl_abort_seq_handler(char *msg);
  84. static uint8_t envctrl_get_fpm_status(struct envctrlunit *);
  85. static void envctrl_set_fsp(struct envctrlunit *, uint8_t *);
  86. static int envctrl_set_dskled(struct envctrlunit *,
  87. struct envctrl_pcf8574_chip *);
  88. static int envctrl_get_dskled(struct envctrlunit *,
  89. struct envctrl_pcf8574_chip *);
  90. static void envctrl_probe_cpus(struct envctrlunit *);
  91. static int envctrl_match_cpu(dev_info_t *, void *);
  92. static int envctrl_isother_fault_led(struct envctrlunit *,
  93. uint8_t, uint8_t);
  94. /* Kstat routines */
  95. static void envctrl_add_kstats(struct envctrlunit *);
  96. static int envctrl_ps_kstat_update(kstat_t *, int);
  97. static int envctrl_fanstat_kstat_update(kstat_t *, int);
  98. static int envctrl_encl_kstat_update(kstat_t *, int);
  99. static void envctrl_init_fan_kstats(struct envctrlunit *);
  100. static void envctrl_init_encl_kstats(struct envctrlunit *);
  101. static void envctrl_add_encl_kstats(struct envctrlunit *, int, int,
  102. uint8_t);
  103. static void envctrl_mod_encl_kstats(struct envctrlunit *, int, int,
  104. uint8_t);
  105. /* Streams Routines */
  106. static int envctrl_wput(queue_t *, mblk_t *);
  107. /* External routines */
  108. extern void power_down(const char *);
  109. extern int prom_getprop();
  110. extern int prom_getproplen();
  111. extern void prom_printf(const char *fmt, ...);
  112. extern void (*abort_seq_handler)();
  113. static void *envctrlsoft_statep;
  114. /* Local Variables */
  115. /* Indicates whether or not the overtemp thread has been started */
  116. static int envctrl_debug_flags = 0;
  117. static int envctrl_afb_present = 0;
  118. static int envctrl_power_off_overide = 0;
  119. static int envctrl_max_retries = 100;
  120. static int envctrl_allow_detach = 0;
  121. static int envctrl_numcpus = 1;
  122. static int envctrl_p0_enclosure = 0; /* set to 1 if it is a P0 */
  123. static int envctrl_handler = 1; /* 1 is the default */
  124. static clock_t overtemp_timeout_hz;
  125. static clock_t blink_timeout_hz;
  126. static clock_t pshotplug_timeout_hz;
  127. static int controller_present[] = {-1, -1, -1};
  128. #ifdef MULTIFAN
  129. static int envctrl_fan_debug = 0;
  130. #endif
  131. static int eHc_debug = 0;
  132. static int power_supply_previous_state[] = {-1, -1, -1};
  133. extern void pci_thermal_rem_intr(dev_info_t *, uint_t);
  134. #define LOOP_TIMEOUT 25
  135. #define INIT_FAN_VAL 35
  136. #define DCMNERR if (eHc_debug & 0x1) cmn_err
  137. #define DCMN2ERR if (eHc_debug & 0x2) cmn_err
  138. #define MAX_FAN_FAIL_RETRY 3
  139. uint8_t backaddrs[] = {ENVCTRL_PCF8574_DEV0, ENVCTRL_PCF8574_DEV1,
  140. ENVCTRL_PCF8574_DEV2};
  141. struct module_info envctrlinfo = {
  142. /* id, name, min pkt siz, max pkt siz, hi water, low water */
  143. 42, "envctrl", 0, 2048, (1024 * 20), (1024 * 1)
  144. };
  145. static struct qinit envctrl_rinit = {
  146. putq, NULL, envctrl_open, envctrl_close, NULL, &envctrlinfo, NULL
  147. };
  148. static struct qinit envctrl_wint = {
  149. envctrl_wput, NULL, envctrl_open, envctrl_close,
  150. NULL, &envctrlinfo, NULL
  151. };
  152. struct streamtab envctrl_str_info = {
  153. &envctrl_rinit, &envctrl_wint, NULL, NULL
  154. };
  155. static struct cb_ops envctrl_cb_ops = {
  156. nodev, /* cb_open */
  157. nodev, /* cb_close */
  158. nodev, /* cb_strategy */
  159. nodev, /* cb_print */
  160. nodev, /* cb_dump */
  161. nodev, /* cb_read */
  162. nodev, /* cb_write */
  163. nodev, /* cb_ioctl */
  164. nodev, /* cb_devmap */
  165. nodev, /* cb_mmap */
  166. nodev, /* cb_segmap */
  167. nochpoll, /* cb_chpoll */
  168. ddi_prop_op, /* cb_prop_op */
  169. &envctrl_str_info, /* cb_stream */
  170. D_MP /* cb_flag */
  171. };
  172. /*
  173. * Declare ops vectors for auto configuration.
  174. */
  175. struct dev_ops envctrl_ops = {
  176. DEVO_REV, /* devo_rev */
  177. 0, /* devo_refcnt */
  178. envctrl_getinfo, /* devo_getinfo */
  179. nulldev, /* devo_identify */
  180. nulldev, /* devo_probe */
  181. envctrl_attach, /* devo_attach */
  182. envctrl_detach, /* devo_detach */
  183. nodev, /* devo_reset */
  184. &envctrl_cb_ops, /* devo_cb_ops */
  185. (struct bus_ops *)NULL, /* devo_bus_ops */
  186. nulldev, /* devo_power */
  187. ddi_quiesce_not_supported, /* devo_quiesce */
  188. };
  189. extern struct mod_ops mod_driverops;
  190. static struct modldrv envctrlmodldrv = {
  191. &mod_driverops, /* type of module - driver */
  192. "I2C ENVCTRL_driver",
  193. &envctrl_ops,
  194. };
  195. static struct modlinkage envctrlmodlinkage = {
  196. MODREV_1,
  197. &envctrlmodldrv,
  198. 0
  199. };
  200. /*
  201. * The following defines are for the i2c protocol routines.
  202. * This section of defines should be removed once the envctrl_targets.c
  203. * file is included.
  204. */
  205. #define EHC_SUCCESS 0
  206. #define EHC_FAILURE (-1)
  207. #define EHC_NO_SLAVE_ACK 3
  208. #define EHC_MAX_WAIT 7 /* decimal */
  209. #define EHC_S1_PIN 0x80
  210. #define EHC_S1_ES1 0x20
  211. #define EHC_S1_ES0 0x40
  212. #define EHC_S1_NBB 0x01
  213. #define EHC_S1_ACK 0x01
  214. #define EHC_S1_STA 0x04
  215. #define EHC_S1_STO 0x02
  216. #define EHC_S1_LRB 0x08
  217. #define EHC_S1_BER 0x10
  218. #define EHC_S1_LAB 0x02
  219. #define EHC_S0_OWN 0x55
  220. #define EHC_S0_CLK 0x1c
  221. #define EHC_BYTE_READ 0x01
  222. #define EHC_LONGEST_MSG 1000 /* decimal */
  223. /*
  224. * PCF8591 Chip Used for temperature sensors
  225. *
  226. * Addressing Register definition.
  227. * A0-A2 valid range is 0-7
  228. *
  229. * 7 6 5 4 3 2 1 0
  230. * ------------------------------------------------
  231. * | 1 | 0 | 0 | 1 | A2 | A1 | A0 | R/W |
  232. * ------------------------------------------------
  233. */
  234. #define EHC_PCF8591_MAX_DEVS 0x08
  235. #define EHC_DEV0 0x00
  236. #define EHC_DEV1 0x02
  237. #define EHC_DEV2 0x04
  238. #define EHC_DEV3 0x06
  239. #define EHC_DEV4 0x08
  240. #define EHC_DEV5 0x0A
  241. #define EHC_DEV6 0x0C
  242. #define EHC_DEV7 0x0E
  243. /*
  244. * CONTROL OF CHIP
  245. * PCF8591 Temp sensing control register definitions
  246. *
  247. * 7 6 5 4 3 2 1 0
  248. * ---------------------------------------------
  249. * | 0 | AOE | X | X | 0 | AIF | X | X |
  250. * ---------------------------------------------
  251. * AOE = Analog out enable.. not used on out implementation
  252. * 5 & 4 = Analog Input Programming.. see data sheet for bits..
  253. *
  254. * AIF = Auto increment flag
  255. * bits 1 & 0 are for the Chennel number.
  256. */
  257. #define EHC_PCF8591_ANALOG_OUTPUT_EN 0x40
  258. #define EHC_PCF8591_ANALOG_INPUT_EN 0x00
  259. #define EHC_PCF8591_READ_BIT 0x01
  260. #define EHC_PCF8591_AUTO_INCR 0x04
  261. #define EHC_PCF8591_OSCILATOR 0x40
  262. #define EHC_PCF8591_MAX_PORTS 0x04
  263. #define EHC_PCF8591_CH_0 0x00
  264. #define EHC_PCF8591_CH_1 0x01
  265. #define EHC_PCF8591_CH_2 0x02
  266. #define EHC_PCF8591_CH_3 0x03
  267. /*
  268. * PCF8574 Fan Fail, Power Supply Fail Detector
  269. * This device is driven by interrupts. Each time it interrupts
  270. * you must look at the CSR to see which ports caused the interrupt
  271. * they are indicated by a 1.
  272. *
  273. * Address map of this chip
  274. *
  275. * -------------------------------------------
  276. * | 0 | 1 | 1 | 1 | A2 | A1 | A0 | 0 |
  277. * -------------------------------------------
  278. *
  279. */
  280. #define EHC_PCF8574_PORT0 0x01
  281. #define EHC_PCF8574_PORT1 0x02
  282. #define EHC_PCF8574_PORT2 0x04
  283. #define EHC_PCF8574_PORT3 0x08
  284. #define EHC_PCF8574_PORT4 0x10
  285. #define EHC_PCF8574_PORT5 0x20
  286. #define EHC_PCF8574_PORT6 0x40
  287. #define EHC_PCF8574_PORT7 0x80
  288. /*
  289. * Defines for the PCF8583 Clock Calendar Chip.
  290. */
  291. #define EHC_PCF8583_READ_BIT 0x01
  292. #define ALARM_CTR_REG_MINS 0x03
  293. #define ALARM_REG_MINS 0x0B
  294. #define ALARM_TIMER_REG 0x0F
  295. struct eHc_pcd8584_regs {
  296. uint8_t s0; /* Own Address S0' */
  297. uint8_t s1; /* Control Status register */
  298. uint8_t clock_s2; /* Clock programming register */
  299. };
  300. struct eHc_envcunit {
  301. struct eHc_pcd8584_regs *bus_ctl_regs;
  302. ddi_acc_handle_t ctlr_handle;
  303. kmutex_t umutex;
  304. };
  305. /*
  306. * Prototypes for static routines
  307. */
  308. static int eHc_write_tda8444(struct eHc_envcunit *, int, int, int, uint8_t *,
  309. int);
  310. static int eHc_read_pcf8591(struct eHc_envcunit *, int, int, int, int, int,
  311. uint8_t *, int);
  312. static int eHc_read_pcf8574a(struct eHc_envcunit *, int, uint8_t *, int);
  313. static int eHc_write_pcf8574a(struct eHc_envcunit *, int, uint8_t *, int);
  314. static int eHc_read_pcf8574(struct eHc_envcunit *, int, uint8_t *, int);
  315. static int eHc_write_pcf8574(struct eHc_envcunit *, int, uint8_t *, int);
  316. static int eHc_read_lm75(struct eHc_envcunit *, int, uint8_t *, int);
  317. static int eHc_write_pcf8583(struct eHc_envcunit *, int, uint8_t *, int);
  318. static int eHc_start_pcf8584(struct eHc_envcunit *, uint8_t);
  319. static void eHc_stop_pcf8584(struct eHc_envcunit *);
  320. static int eHc_read_pcf8584(struct eHc_envcunit *, uint8_t *);
  321. static int eHc_write_pcf8584(struct eHc_envcunit *, uint8_t);
  322. static int eHc_after_read_pcf8584(struct eHc_envcunit *, uint8_t *);
  323. /*
  324. * End of i2c protocol definitions section
  325. */
  326. int
  327. _init(void)
  328. {
  329. int error;
  330. if ((error = mod_install(&envctrlmodlinkage)) == 0) {
  331. (void) ddi_soft_state_init(&envctrlsoft_statep,
  332. sizeof (struct envctrlunit), 1);
  333. }
  334. return (error);
  335. }
  336. int
  337. _fini(void)
  338. {
  339. int error;
  340. if ((error = mod_remove(&envctrlmodlinkage)) == 0)
  341. ddi_soft_state_fini(&envctrlsoft_statep);
  342. return (error);
  343. }
  344. int
  345. _info(struct modinfo *modinfop)
  346. {
  347. return (mod_info(&envctrlmodlinkage, modinfop));
  348. }
  349. static int
  350. envctrl_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
  351. {
  352. int instance;
  353. char name[16];
  354. uint8_t fspval;
  355. struct envctrlunit *unitp;
  356. struct ddi_device_acc_attr attr;
  357. int *reg_prop;
  358. uchar_t *creg_prop;
  359. uint_t len, tblsz;
  360. int i, cputemp, status;
  361. uint8_t buf[3];
  362. status = len = tblsz = 0;
  363. attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
  364. attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
  365. attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
  366. instance = ddi_get_instance(dip);
  367. switch (cmd) {
  368. case DDI_ATTACH:
  369. break;
  370. case DDI_RESUME:
  371. if (!(unitp = ddi_get_soft_state(envctrlsoft_statep, instance)))
  372. return (DDI_FAILURE);
  373. mutex_enter(&unitp->umutex);
  374. if (!unitp->suspended) {
  375. mutex_exit(&unitp->umutex);
  376. return (DDI_FAILURE);
  377. }
  378. unitp->suspended = 0;
  379. mutex_exit(&unitp->umutex);
  380. unitp->initting = B_TRUE;
  381. envctrl_init_bus(unitp);
  382. unitp->initting = B_FALSE;
  383. mutex_enter(&unitp->umutex);
  384. envctrl_ps_probe(unitp);
  385. envctrl_probe_cpus(unitp);
  386. mutex_exit(&unitp->umutex);
  387. return (DDI_SUCCESS);
  388. default:
  389. return (DDI_FAILURE);
  390. }
  391. /* Set up timer values */
  392. overtemp_timeout_hz = drv_usectohz(OVERTEMP_TIMEOUT_USEC);
  393. blink_timeout_hz = drv_usectohz(BLINK_TIMEOUT_USEC);
  394. pshotplug_timeout_hz = drv_usectohz(BLINK_TIMEOUT_USEC * 6);
  395. if (ddi_soft_state_zalloc(envctrlsoft_statep, instance) != 0) {
  396. cmn_err(CE_WARN, "envctrl failed to zalloc softstate\n");
  397. goto failed;
  398. }
  399. unitp = ddi_get_soft_state(envctrlsoft_statep, instance);
  400. if (ddi_regs_map_setup(dip, 0, (caddr_t *)&unitp->bus_ctl_regs, 0,
  401. sizeof (struct envctrl_pcd8584_regs), &attr,
  402. &unitp->ctlr_handle) != DDI_SUCCESS) {
  403. cmn_err(CE_WARN, "I2c failed to map in bus_control regs\n");
  404. return (DDI_FAILURE);
  405. }
  406. /*
  407. * If the PCI nexus has added a thermal interrupt, we first need
  408. * to remove that interrupt handler.
  409. *
  410. * WARNING: Removing another driver's interrupt handler is not
  411. * allowed. The pci_thermal_rem_intr() call below is needed to retain
  412. * the legacy behavior on Tazmo systems.
  413. */
  414. pci_thermal_rem_intr(dip, (uint_t)0);
  415. /* add interrupts */
  416. if (ddi_get_iblock_cookie(dip, 1,
  417. &unitp->ic_trap_cookie) != DDI_SUCCESS) {
  418. cmn_err(CE_WARN, "ddi_get_iblock_cookie FAILED \n");
  419. goto failed;
  420. }
  421. mutex_init(&unitp->umutex, NULL, MUTEX_DRIVER,
  422. (void *)unitp->ic_trap_cookie);
  423. if (ddi_add_intr(dip, 0, &unitp->ic_trap_cookie, NULL, envctrl_bus_isr,
  424. (caddr_t)unitp) != DDI_SUCCESS) {
  425. cmn_err(CE_WARN, "envctrl_attach failed to add hard intr %d\n",
  426. instance);
  427. goto remlock;
  428. }
  429. if (ddi_add_intr(dip, 1, &unitp->ic_trap_cookie, NULL, envctrl_dev_isr,
  430. (caddr_t)unitp) != DDI_SUCCESS) {
  431. cmn_err(CE_WARN, "envctrl_attach failed to add hard intr %d\n",
  432. instance);
  433. goto remhardintr;
  434. }
  435. (void) sprintf(name, "envctrl%d", instance);
  436. if (ddi_create_minor_node(dip, name, S_IFCHR, instance, DDI_PSEUDO,
  437. NULL) == DDI_FAILURE) {
  438. ddi_remove_minor_node(dip, NULL);
  439. goto remhardintr1;
  440. }
  441. mutex_enter(&unitp->umutex);
  442. switch (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
  443. ENVCTRL_LED_BLINK, -1)) {
  444. case 1:
  445. unitp->activity_led_blink = B_TRUE;
  446. break;
  447. case 0:
  448. default:
  449. unitp->activity_led_blink = B_FALSE;
  450. break;
  451. }
  452. unitp->shutdown = B_FALSE;
  453. unitp->num_ps_present = unitp->num_encl_present = 0;
  454. unitp->num_fans_present = MIN_FAN_BANKS;
  455. unitp->num_fans_failed = ENVCTRL_CHAR_ZERO;
  456. unitp->AFB_present = B_TRUE;
  457. unitp->dip = dip;
  458. #ifdef DEBUG
  459. if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
  460. DDI_PROP_DONTPASS, ENVCTRL_PANEL_LEDS_PR,
  461. &reg_prop, &len) == DDI_PROP_SUCCESS)
  462. ddi_prop_free((void *)reg_prop);
  463. ASSERT(len != 0);
  464. len = 0;
  465. if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
  466. DDI_PROP_DONTPASS, ENVCTRL_PANEL_LEDS_STA,
  467. &reg_prop, &len) == DDI_PROP_SUCCESS)
  468. ddi_prop_free((void *)reg_prop);
  469. ASSERT(len != 0);
  470. len = 0;
  471. if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
  472. DDI_PROP_DONTPASS, ENVCTRL_DISK_LEDS_STA,
  473. &reg_prop, &len) == DDI_PROP_SUCCESS)
  474. ddi_prop_free((void *)reg_prop);
  475. ASSERT(len != 0);
  476. #endif /* DEBUG */
  477. /*
  478. * if we have prom fan tables, overide the static tables in
  479. * header file.
  480. */
  481. if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip,
  482. DDI_PROP_DONTPASS, "cpu-fan-speeds",
  483. &creg_prop, &len) == DDI_PROP_SUCCESS) {
  484. tblsz = (sizeof (acme_cpu_fanspd) / sizeof (short));
  485. if (len <= tblsz) {
  486. for (i = 0; i < len; i++) {
  487. acme_cpu_fanspd[i] = creg_prop[i];
  488. }
  489. }
  490. ddi_prop_free((void *)creg_prop);
  491. }
  492. len = 0;
  493. if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip,
  494. DDI_PROP_DONTPASS, "ps-fan-speeds",
  495. &creg_prop, &len) == DDI_PROP_SUCCESS) {
  496. tblsz = (sizeof (acme_ps_fanspd) / sizeof (short));
  497. if (len <= tblsz) {
  498. for (i = 0; i < len; i++) {
  499. acme_ps_fanspd[i] = creg_prop[i];
  500. }
  501. }
  502. ddi_prop_free((void *)creg_prop);
  503. }
  504. switch (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
  505. "fan-override", -1)) {
  506. case 1:
  507. case 2:
  508. unitp->AFB_present = B_TRUE;
  509. break;
  510. case 0:
  511. default:
  512. unitp->AFB_present = B_FALSE;
  513. break;
  514. }
  515. /* For debug */
  516. if (envctrl_afb_present) {
  517. unitp->AFB_present = B_TRUE;
  518. }
  519. if (unitp->AFB_present == B_TRUE)
  520. unitp->num_fans_present++;
  521. /* initialize the envctrl bus controller */
  522. mutex_exit(&unitp->umutex);
  523. unitp->initting = B_TRUE;
  524. envctrl_init_bus(unitp);
  525. unitp->initting = B_FALSE;
  526. drv_usecwait(1000);
  527. mutex_enter(&unitp->umutex);
  528. /* Initialize the PCF8583 eggtimer registers */
  529. buf[0] = ALARM_CTR_REG_MINS;
  530. buf[1] = 0x0;
  531. status = eHc_write_pcf8583((struct eHc_envcunit *)unitp,
  532. PCF8583_BASE_ADDR | 0, buf, 2);
  533. if (status != DDI_SUCCESS)
  534. cmn_err(CE_WARN, "write to PCF8583 failed\n");
  535. buf[0] = ALARM_REG_MINS;
  536. buf[1] = 0x58;
  537. status = eHc_write_pcf8583((struct eHc_envcunit *)unitp,
  538. PCF8583_BASE_ADDR | 0, buf, 2);
  539. if (status != DDI_SUCCESS)
  540. cmn_err(CE_WARN, "write to PCF8583 failed\n");
  541. buf[0] = ALARM_TIMER_REG;
  542. buf[1] = 0x80;
  543. status = eHc_write_pcf8583((struct eHc_envcunit *)unitp,
  544. PCF8583_BASE_ADDR | 0, buf, 2);
  545. if (status != DDI_SUCCESS)
  546. cmn_err(CE_WARN, "write to PCF8583 failed\n");
  547. unitp->timeout_id = 0;
  548. unitp->blink_timeout_id = 0;
  549. if (envctrl_numcpus > 1) {
  550. unitp->num_cpus_present = envctrl_numcpus;
  551. }
  552. envctrl_probe_cpus(unitp);
  553. envctrl_ps_probe(unitp);
  554. /*
  555. * clear the fan failures, if any before we do
  556. * real work
  557. */
  558. unitp->initting = B_TRUE;
  559. envctrl_fan_fail_service(unitp);
  560. unitp->initting = B_FALSE;
  561. /*
  562. * we need to init the fan kstats before the tempr_poll
  563. */
  564. envctrl_add_kstats(unitp);
  565. envctrl_init_fan_kstats(unitp);
  566. envctrl_init_encl_kstats(unitp);
  567. if (unitp->activity_led_blink == B_TRUE) {
  568. unitp->present_led_state = B_FALSE;
  569. mutex_exit(&unitp->umutex);
  570. envctrl_led_blink((void *)unitp);
  571. mutex_enter(&unitp->umutex);
  572. } else {
  573. fspval = ENVCTRL_FSP_ACTIVE;
  574. envctrl_set_fsp(unitp, &fspval);
  575. }
  576. #ifndef TESTBED
  577. for (i = 0; i < ENVCTRL_MAX_CPUS; i++) {
  578. if (unitp->cpu_pr_location[i] == B_TRUE) {
  579. cputemp = envctrl_get_cpu_temp(unitp, i);
  580. envctrl_add_encl_kstats(unitp, ENVCTRL_ENCL_CPUTEMPR,
  581. i, cputemp);
  582. if (cputemp >= MAX_CPU_TEMP) {
  583. if (!(envctrl_power_off_overide)) {
  584. cmn_err(CE_WARN,
  585. "CPU %d OVERHEATING!!", i);
  586. unitp->shutdown = B_TRUE;
  587. } else {
  588. cmn_err(CE_WARN,
  589. "CPU %d OVERHEATING!!", i);
  590. }
  591. }
  592. }
  593. }
  594. #else
  595. cputemp = envctrl_get_cpu_temp(unitp, 0);
  596. envctrl_add_encl_kstats(unitp, ENVCTRL_ENCL_CPUTEMPR, INSTANCE_0,
  597. cputemp);
  598. #endif
  599. mutex_exit(&unitp->umutex);
  600. envctrl_tempr_poll((void *)unitp);
  601. /*
  602. * interpose envctrl's abort sequence handler
  603. */
  604. if (envctrl_handler) {
  605. abort_seq_handler = envctrl_abort_seq_handler;
  606. }
  607. ddi_report_dev(dip);
  608. return (DDI_SUCCESS);
  609. remhardintr1:
  610. ddi_remove_intr(dip, (uint_t)1, unitp->ic_trap_cookie);
  611. remhardintr:
  612. ddi_remove_intr(dip, (uint_t)0, unitp->ic_trap_cookie);
  613. remlock:
  614. mutex_destroy(&unitp->umutex);
  615. failed:
  616. if (unitp->ctlr_handle)
  617. ddi_regs_map_free(&unitp->ctlr_handle);
  618. cmn_err(CE_WARN, "envctrl_attach:failed.\n");
  619. return (DDI_FAILURE);
  620. }
  621. static int
  622. envctrl_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
  623. {
  624. int instance;
  625. struct envctrlunit *unitp;
  626. instance = ddi_get_instance(dip);
  627. unitp = ddi_get_soft_state(envctrlsoft_statep, instance);
  628. switch (cmd) {
  629. case DDI_DETACH:
  630. if (envctrl_allow_detach) {
  631. if (unitp->psksp != NULL) {
  632. kstat_delete(unitp->psksp);
  633. }
  634. if (unitp->fanksp != NULL) {
  635. kstat_delete(unitp->fanksp);
  636. }
  637. if (unitp->enclksp != NULL) {
  638. kstat_delete(unitp->enclksp);
  639. }
  640. if (unitp->timeout_id != 0) {
  641. (void) untimeout(unitp->timeout_id);
  642. unitp->timeout_id = 0;
  643. }
  644. if (unitp->blink_timeout_id != 0) {
  645. (void) untimeout(unitp->blink_timeout_id);
  646. unitp->blink_timeout_id = 0;
  647. }
  648. ddi_remove_minor_node(dip, NULL);
  649. ddi_remove_intr(dip, (uint_t)0, unitp->ic_trap_cookie);
  650. ddi_remove_intr(dip, (uint_t)1, unitp->ic_trap_cookie);
  651. ddi_regs_map_free(&unitp->ctlr_handle);
  652. mutex_destroy(&unitp->umutex);
  653. return (DDI_SUCCESS);
  654. } else {
  655. return (DDI_FAILURE);
  656. }
  657. case DDI_SUSPEND:
  658. if (!(unitp = ddi_get_soft_state(envctrlsoft_statep, instance)))
  659. return (DDI_FAILURE);
  660. mutex_enter(&unitp->umutex);
  661. if (unitp->suspended) {
  662. cmn_err(CE_WARN, "envctrl already suspended\n");
  663. mutex_exit(&unitp->umutex);
  664. return (DDI_FAILURE);
  665. }
  666. unitp->suspended = 1;
  667. mutex_exit(&unitp->umutex);
  668. return (DDI_SUCCESS);
  669. default:
  670. cmn_err(CE_WARN, "envctrl suspend general fault\n");
  671. return (DDI_FAILURE);
  672. }
  673. }
  674. /* ARGSUSED */
  675. int
  676. envctrl_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
  677. void **result)
  678. {
  679. dev_t dev = (dev_t)arg;
  680. struct envctrlunit *unitp;
  681. int ret;
  682. minor_t instance = getminor(dev);
  683. switch (infocmd) {
  684. case DDI_INFO_DEVT2DEVINFO:
  685. if ((unitp = (struct envctrlunit *)
  686. ddi_get_soft_state(envctrlsoft_statep,
  687. instance)) != NULL) {
  688. *result = unitp->dip;
  689. ret = DDI_SUCCESS;
  690. } else {
  691. *result = NULL;
  692. ret = DDI_FAILURE;
  693. }
  694. break;
  695. case DDI_INFO_DEVT2INSTANCE:
  696. *result = (void *)(uintptr_t)instance;
  697. ret = DDI_SUCCESS;
  698. break;
  699. default:
  700. ret = DDI_FAILURE;
  701. break;
  702. }
  703. return (ret);
  704. }
  705. /* ARGSUSED */
  706. static int
  707. envctrl_open(queue_t *q, dev_t *dev, int flag, int sflag, cred_t *credp)
  708. {
  709. struct envctrlunit *unitp;
  710. int status = 0;
  711. int instance;
  712. instance = getminor(*dev);
  713. if (instance < 0)
  714. return (ENXIO);
  715. unitp = (struct envctrlunit *)
  716. ddi_get_soft_state(envctrlsoft_statep, instance);
  717. if (unitp == NULL)
  718. return (ENXIO);
  719. mutex_enter(&unitp->umutex);
  720. if (flag & FWRITE) {
  721. if ((unitp->oflag & FWRITE)) {
  722. mutex_exit(&unitp->umutex);
  723. return (EBUSY);
  724. } else {
  725. unitp->oflag |= FWRITE;
  726. }
  727. }
  728. q->q_ptr = WR(q)->q_ptr = (caddr_t)unitp;
  729. /*
  730. * if device is open with O_NONBLOCK flag set, let read(2) return 0
  731. * if no data waiting to be read. Writes will block on flow control.
  732. */
  733. /* enable the stream */
  734. qprocson(q);
  735. unitp->readq = RD(q);
  736. unitp->writeq = WR(q);
  737. unitp->msg = (mblk_t *)NULL;
  738. mutex_exit(&unitp->umutex);
  739. return (status);
  740. }
  741. /* ARGSUSED */
  742. static int
  743. envctrl_close(queue_t *q, int flag, cred_t *cred_p)
  744. {
  745. struct envctrlunit *unitp;
  746. unitp = (struct envctrlunit *)q->q_ptr;
  747. mutex_enter(&unitp->umutex);
  748. unitp->oflag = B_FALSE;
  749. unitp->current_mode = ENVCTRL_NORMAL_MODE;
  750. /* disable the stream */
  751. q->q_ptr = WR(q)->q_ptr = NULL;
  752. qprocsoff(q);
  753. mutex_exit(&unitp->umutex);
  754. return (DDI_SUCCESS);
  755. }
  756. /*
  757. * standard put procedure for envctrl
  758. */
  759. static int
  760. envctrl_wput(queue_t *q, mblk_t *mp)
  761. {
  762. struct msgb *mp1;
  763. struct envctrlunit *unitp;
  764. struct iocblk *iocp;
  765. struct copyresp *csp;
  766. struct envctrl_tda8444t_chip *fanspeed;
  767. struct envctrl_pcf8574_chip *ledchip;
  768. struct envctrl_pcf8591_chip *temp, *a_fanspeed;
  769. struct copyreq *cqp;
  770. int cmd;
  771. unitp = (struct envctrlunit *)q->q_ptr;
  772. switch (DB_TYPE(mp)) {
  773. case M_DATA:
  774. while (mp) {
  775. DB_TYPE(mp) = M_DATA;
  776. mp1 = unlinkb(mp);
  777. mp->b_cont = NULL;
  778. if ((mp->b_wptr - mp->b_rptr) <= 0) {
  779. freemsg(mp);
  780. } else {
  781. (void) putq(q, mp);
  782. }
  783. mp = mp1;
  784. }
  785. break;
  786. case M_IOCTL:
  787. {
  788. iocp = (struct iocblk *)(void *)mp->b_rptr;
  789. cmd = iocp->ioc_cmd;
  790. switch (cmd) {
  791. case ENVCTRL_IOC_SETMODE:
  792. case ENVCTRL_IOC_GETMODE:
  793. if (iocp->ioc_count == TRANSPARENT) {
  794. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  795. sizeof (uchar_t), NULL);
  796. qreply(q, mp);
  797. } else {
  798. miocnak(q, mp, 0, EINVAL);
  799. }
  800. break;
  801. case ENVCTRL_IOC_RESETTMPR:
  802. /*
  803. * For diags, cancel the current temp poll
  804. * and reset it for a new one.
  805. */
  806. if (unitp->current_mode == ENVCTRL_DIAG_MODE) {
  807. if (unitp->timeout_id != 0) {
  808. (void) untimeout(unitp->timeout_id);
  809. unitp->timeout_id = 0;
  810. }
  811. envctrl_tempr_poll((void *)unitp);
  812. miocack(q, mp, 0, 0);
  813. } else {
  814. miocnak(q, mp, 0, EINVAL);
  815. }
  816. break;
  817. case ENVCTRL_IOC_GETTEMP:
  818. if (iocp->ioc_count == TRANSPARENT) {
  819. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  820. sizeof (struct envctrl_pcf8591_chip), NULL);
  821. qreply(q, mp);
  822. } else {
  823. miocnak(q, mp, 0, EINVAL);
  824. }
  825. break;
  826. case ENVCTRL_IOC_SETTEMP:
  827. if (unitp->current_mode == ENVCTRL_DIAG_MODE &&
  828. iocp->ioc_count == TRANSPARENT) {
  829. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  830. sizeof (uint8_t), NULL);
  831. qreply(q, mp);
  832. } else {
  833. miocnak(q, mp, 0, EINVAL);
  834. }
  835. break;
  836. case ENVCTRL_IOC_SETWDT:
  837. if (unitp->current_mode == ENVCTRL_DIAG_MODE &&
  838. iocp->ioc_count == TRANSPARENT) {
  839. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  840. sizeof (uint8_t), NULL);
  841. qreply(q, mp);
  842. } else {
  843. miocnak(q, mp, 0, EINVAL);
  844. }
  845. break;
  846. case ENVCTRL_IOC_SETFAN:
  847. /*
  848. * we must be in diag mode before we can
  849. * set any fan speeds.
  850. */
  851. if (unitp->current_mode == ENVCTRL_DIAG_MODE &&
  852. iocp->ioc_count == TRANSPARENT) {
  853. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  854. sizeof (struct envctrl_tda8444t_chip),
  855. NULL);
  856. qreply(q, mp);
  857. } else {
  858. miocnak(q, mp, 0, EINVAL);
  859. }
  860. break;
  861. case ENVCTRL_IOC_GETFAN:
  862. if (iocp->ioc_count == TRANSPARENT) {
  863. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  864. sizeof (struct envctrl_pcf8591_chip), NULL);
  865. qreply(q, mp);
  866. } else {
  867. miocnak(q, mp, 0, EINVAL);
  868. }
  869. break;
  870. case ENVCTRL_IOC_SETFSP:
  871. if (iocp->ioc_count == TRANSPARENT) {
  872. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  873. sizeof (uint8_t), NULL);
  874. qreply(q, mp);
  875. } else {
  876. miocnak(q, mp, 0, EINVAL);
  877. }
  878. break;
  879. case ENVCTRL_IOC_SETDSKLED:
  880. case ENVCTRL_IOC_GETDSKLED:
  881. if (iocp->ioc_count == TRANSPARENT) {
  882. mcopyin(mp, *(caddr_t *)mp->b_cont->b_rptr,
  883. sizeof (struct envctrl_pcf8574_chip), NULL);
  884. qreply(q, mp);
  885. } else {
  886. miocnak(q, mp, 0, EINVAL);
  887. }
  888. break;
  889. default:
  890. miocnak(q, mp, 0, EINVAL);
  891. break;
  892. }
  893. break;
  894. }
  895. case M_IOCDATA:
  896. {
  897. uint8_t *tempr, *wdval;
  898. long state;
  899. csp = (struct copyresp *)(void *)mp->b_rptr;
  900. /*
  901. * If copy request failed, quit now
  902. */
  903. if (csp->cp_rval != 0) {
  904. miocnak(q, mp, 0, EINVAL);
  905. return (0);
  906. }
  907. cqp = (struct copyreq *)(void *)mp->b_rptr;
  908. cmd = csp->cp_cmd;
  909. state = (long)cqp->cq_private;
  910. switch (cmd) {
  911. case ENVCTRL_IOC_SETFAN:
  912. fanspeed = (struct envctrl_tda8444t_chip *)
  913. (void *)mp->b_cont->b_rptr;
  914. mutex_enter(&unitp->umutex);
  915. if (envctrl_xmit(unitp, (caddr_t *)(void *)fanspeed,
  916. fanspeed->type) == DDI_FAILURE) {
  917. /*
  918. * Fix for a ADF bug
  919. * move mutex to after fan fail call
  920. * bugid 4016121
  921. */
  922. envctrl_fan_fail_service(unitp);
  923. mutex_exit(&unitp->umutex);
  924. miocnak(q, mp, 0, EINVAL);
  925. } else {
  926. mutex_exit(&unitp->umutex);
  927. miocack(q, mp, 0, 0);
  928. }
  929. break;
  930. case ENVCTRL_IOC_SETFSP:
  931. wdval = (uint8_t *)(void *)mp->b_cont->b_rptr;
  932. mutex_enter(&unitp->umutex);
  933. /*
  934. * If a user is in normal mode and they try
  935. * to set anything other than a disk fault or
  936. * a gen fault it is an invalid operation.
  937. * in diag mode we allow everything to be
  938. * twiddled.
  939. */
  940. if (unitp->current_mode == ENVCTRL_NORMAL_MODE) {
  941. if (*wdval & ~ENVCTRL_FSP_USRMASK) {
  942. mutex_exit(&unitp->umutex);
  943. miocnak(q, mp, 0, EINVAL);
  944. break;
  945. }
  946. }
  947. envctrl_set_fsp(unitp, wdval);
  948. mutex_exit(&unitp->umutex);
  949. miocack(q, mp, 0, 0);
  950. break;
  951. case ENVCTRL_IOC_SETDSKLED:
  952. ledchip = (struct envctrl_pcf8574_chip *)
  953. (void *)mp->b_cont->b_rptr;
  954. mutex_enter(&unitp->umutex);
  955. if (envctrl_set_dskled(unitp, ledchip)) {
  956. miocnak(q, mp, 0, EINVAL);
  957. } else {
  958. miocack(q, mp, 0, 0);
  959. }
  960. mutex_exit(&unitp->umutex);
  961. break;
  962. case ENVCTRL_IOC_GETDSKLED:
  963. if (state == -1) {
  964. miocack(q, mp, 0, 0);
  965. break;
  966. }
  967. ledchip = (struct envctrl_pcf8574_chip *)
  968. (void *)mp->b_cont->b_rptr;
  969. mutex_enter(&unitp->umutex);
  970. if (envctrl_get_dskled(unitp, ledchip)) {
  971. miocnak(q, mp, 0, EINVAL);
  972. } else {
  973. mcopyout(mp, (void *)-1,
  974. sizeof (struct envctrl_pcf8574_chip),
  975. csp->cp_private, NULL);
  976. qreply(q, mp);
  977. }
  978. mutex_exit(&unitp->umutex);
  979. break;
  980. case ENVCTRL_IOC_GETTEMP:
  981. /* Get the user buffer address */
  982. if (state == -1) {
  983. miocack(q, mp, 0, 0);
  984. break;
  985. }
  986. temp = (struct envctrl_pcf8591_chip *)
  987. (void *)mp->b_cont->b_rptr;
  988. mutex_enter(&unitp->umutex);
  989. envctrl_recv(unitp, (caddr_t *)(void *)temp, PCF8591);
  990. mutex_exit(&unitp->umutex);
  991. mcopyout(mp, (void *)-1,
  992. sizeof (struct envctrl_pcf8591_chip),
  993. csp->cp_private, NULL);
  994. qreply(q, mp);
  995. break;
  996. case ENVCTRL_IOC_GETFAN:
  997. /* Get the user buffer address */
  998. if (state == -1) {
  999. miocack(q, mp, 0, 0);
  1000. break;
  1001. }
  1002. a_fanspeed = (struct envctrl_pcf8591_chip *)
  1003. (void *)mp->b_cont->b_rptr;
  1004. mutex_enter(&unitp->umutex);
  1005. envctrl_recv(unitp, (caddr_t *)(void *)a_fanspeed,
  1006. PCF8591);
  1007. mutex_exit(&unitp->umutex);
  1008. mcopyout(mp, (void *)-1,
  1009. sizeof (struct envctrl_pcf8591_chip),
  1010. csp->cp_private, NULL);
  1011. qreply(q, mp);
  1012. break;
  1013. case ENVCTRL_IOC_SETTEMP:
  1014. tempr = (uint8_t *)(void *)mp->b_cont->b_rptr;
  1015. if (*tempr > MAX_DIAG_TEMPR) {
  1016. miocnak(q, mp, 0, EINVAL);
  1017. } else {
  1018. mutex_enter(&unitp->umutex);
  1019. envctrl_get_sys_temperatures(unitp, tempr);
  1020. mutex_exit(&unitp->umutex);
  1021. miocack(q, mp, 0, 0);
  1022. }
  1023. break;
  1024. case ENVCTRL_IOC_SETWDT:
  1025. /* reset watchdog timeout period */
  1026. wdval = (uint8_t *)(void *)mp->b_cont->b_rptr;
  1027. if (*wdval > MAX_CL_VAL) {
  1028. miocnak(q, mp, 0, EINVAL);
  1029. } else {
  1030. mutex_enter(&unitp->umutex);
  1031. envctrl_reset_watchdog(unitp, wdval);
  1032. mutex_exit(&unitp->umutex);
  1033. miocack(q, mp, 0, 0);
  1034. }
  1035. break;
  1036. case ENVCTRL_IOC_GETMODE:
  1037. /* Get the user buffer address */
  1038. if (state == -1) {
  1039. miocack(q, mp, 0, 0);
  1040. break;
  1041. }
  1042. tempr = (uchar_t *)(void *)mp->b_cont->b_rptr;
  1043. *tempr = unitp->current_mode;
  1044. mcopyout(mp, (void *)-1, sizeof (uchar_t),
  1045. csp->cp_private, NULL);
  1046. qreply(q, mp);
  1047. break;
  1048. case ENVCTRL_IOC_SETMODE:
  1049. /* Set mode */
  1050. wdval = (uint8_t *)(void *)mp->b_cont->b_rptr;
  1051. if (*wdval == ENVCTRL_DIAG_MODE || *wdval ==
  1052. ENVCTRL_NORMAL_MODE) {
  1053. mutex_enter(&unitp->umutex);
  1054. unitp->current_mode = *wdval;
  1055. if (unitp->timeout_id != 0 &&
  1056. *wdval == ENVCTRL_DIAG_MODE) {
  1057. (void) untimeout(unitp->timeout_id);
  1058. unitp->timeout_id =
  1059. (timeout(envctrl_tempr_poll,
  1060. (caddr_t)unitp,
  1061. overtemp_timeout_hz));
  1062. }
  1063. if (*wdval == ENVCTRL_NORMAL_MODE) {
  1064. envctrl_get_sys_temperatures(unitp,
  1065. (uint8_t *)NULL);
  1066. /*
  1067. * going to normal mode we
  1068. * need to go to diag mode
  1069. * just in case we have
  1070. * injected a fan fault. It
  1071. * may not be cleared and if
  1072. * we call fan_failsrvc it will
  1073. * power off the ystem if we are
  1074. * in NORMAL_MODE. Also we need
  1075. * to delay 1 bit of time here
  1076. * to allow the fans to rotate
  1077. * back up and clear the intr
  1078. * after we get the sys temps.
  1079. */
  1080. unitp->current_mode =
  1081. ENVCTRL_DIAG_MODE;
  1082. envctrl_fan_fail_service(unitp);
  1083. unitp->current_mode =
  1084. ENVCTRL_NORMAL_MODE;
  1085. }
  1086. mutex_exit(&unitp->umutex);
  1087. miocack(q, mp, 0, 0);
  1088. } else {
  1089. miocnak(q, mp, 0, EINVAL);
  1090. }
  1091. break;
  1092. default:
  1093. freemsg(mp);
  1094. break;
  1095. }
  1096. break;
  1097. }
  1098. case M_FLUSH:
  1099. if (*mp->b_rptr & FLUSHR) {
  1100. *mp->b_rptr &= ~FLUSHW;
  1101. qreply(q, mp);
  1102. } else {
  1103. freemsg(mp);
  1104. }
  1105. break;
  1106. default:
  1107. freemsg(mp);
  1108. break;
  1109. }
  1110. return (0);
  1111. }
  1112. uint_t
  1113. envctrl_bus_isr(caddr_t arg)
  1114. {
  1115. struct envctrlunit *unitp = (struct envctrlunit *)(void *)arg;
  1116. int ic = DDI_INTR_UNCLAIMED;
  1117. mutex_enter(&unitp->umutex);
  1118. /*
  1119. * NOT USED
  1120. */
  1121. mutex_exit(&unitp->umutex);
  1122. return (ic);
  1123. }
  1124. uint_t
  1125. envctrl_dev_isr(caddr_t arg)
  1126. {
  1127. struct envctrlunit *unitp = (struct envctrlunit *)(void *)arg;
  1128. uint8_t recv_data;
  1129. int ic;
  1130. int retrys = 0;
  1131. int status;
  1132. ic = DDI_INTR_UNCLAIMED;
  1133. mutex_enter(&unitp->umutex);
  1134. /*
  1135. * First check to see if it is an interrupt for us by
  1136. * looking at the "ganged" interrrupt and vector
  1137. * according to the major type
  1138. * 0x70 is the addr of the ganged interrupt controller.
  1139. * Address map for the port byte read is as follows
  1140. * MSB
  1141. * -------------------------
  1142. * | | | | | | | | |
  1143. * -------------------------
  1144. * P7 P6 P5 P4 P3 P2 P1 P0
  1145. * P0 = Power Supply 1 intr
  1146. * P1 = Power Supply 2 intr
  1147. * P2 = Power Supply 3 intr
  1148. * P3 = Dlfop enable for fan sped set
  1149. * P4 = ENVCTRL_ Fan Fail intr
  1150. * P5 = Front Panel Interrupt
  1151. * P6 = Power Fail Detect Low.
  1152. * P7 = Enable Interrupts to system
  1153. */
  1154. retry:
  1155. status = eHc_read_pcf8574a((struct eHc_envcunit *)unitp,
  1156. PCF8574A_BASE_ADDR | ENVCTRL_PCF8574_DEV0, &recv_data, 1);
  1157. /*
  1158. * This extra read is needed since the first read is discarded
  1159. * and the second read seems to return 0xFF.
  1160. */
  1161. if (recv_data == 0xFF) {
  1162. status = eHc_read_pcf8574a((struct eHc_envcunit *)unitp,
  1163. PCF8574A_BASE_ADDR | ENVCTRL_PCF8574_DEV0, &recv_data, 1);
  1164. }
  1165. if (envctrl_debug_flags)
  1166. cmn_err(CE_WARN, "envctrl_dev_isr: status= %d, data = %x\n",
  1167. status, recv_data);
  1168. /*
  1169. * if the i2c bus is hung it is imperative that this
  1170. * be cleared on an interrupt or else it will
  1171. * hang the system with continuous interrupts
  1172. */
  1173. if (status == DDI_FAILURE) {
  1174. drv_usecwait(1000);
  1175. if (retrys < envctrl_max_retries) {
  1176. retrys++;
  1177. goto retry;
  1178. } else {
  1179. if (envctrl_debug_flags)
  1180. cmn_err(CE_WARN,
  1181. "DEVISR FAILED received 0x%x\n", recv_data);
  1182. mutex_exit(&unitp->umutex);
  1183. envctrl_init_bus(unitp);
  1184. mutex_enter(&unitp->umutex);
  1185. envctrl_ps_probe(unitp);
  1186. mutex_exit(&unitp->umutex);
  1187. ic = DDI_INTR_CLAIMED;
  1188. return (ic);
  1189. }
  1190. }
  1191. /*
  1192. * Port 0 = PS1 interrupt
  1193. * Port 1 = PS2 Interrupt
  1194. * Port 2 = PS3 Interrupt
  1195. * Port 3 = SPARE
  1196. * Port 4 = Fan Fail Intr
  1197. * Port 5 = Front Panle Module intr
  1198. * Port 6 = Keyswitch Intr
  1199. * Port 7 = ESINTR ENABLE ???
  1200. */
  1201. if (!(recv_data & ENVCTRL_PCF8574_PORT0)) {
  1202. envctrl_PS_intr_service(unitp, PS1);
  1203. ic = DDI_INTR_CLAIMED;
  1204. }
  1205. if (!(recv_data & ENVCTRL_PCF8574_PORT1)) {
  1206. envctrl_PS_intr_service(unitp, PS2);
  1207. ic = DDI_INTR_CLAIMED;
  1208. }
  1209. if (!(recv_data & ENVCTRL_PCF8574_PORT2)) {
  1210. envctrl_PS_intr_service(unitp, PS3);
  1211. ic = DDI_INTR_CLAIMED;
  1212. }
  1213. if (!(recv_data & ENVCTRL_PCF8574_PORT3)) {
  1214. ic = DDI_INTR_CLAIMED;
  1215. }
  1216. if (!(recv_data & ENVCTRL_PCF8574_PORT4)) {
  1217. /*
  1218. * Check for a fan fail
  1219. * Single fan fail
  1220. * shutdown system
  1221. */
  1222. envctrl_fan_fail_service(unitp);
  1223. ic = DDI_INTR_CLAIMED;
  1224. }
  1225. if (!(recv_data & ENVCTRL_PCF8574_PORT5)) {
  1226. (void) envctrl_get_fpm_status(unitp);
  1227. ic = DDI_INTR_CLAIMED;
  1228. }
  1229. if (!(recv_data & ENVCTRL_PCF8574_PORT6)) {
  1230. ic = DDI_INTR_CLAIMED;
  1231. }
  1232. if (!(recv_data & ENVCTRL_PCF8574_PORT7)) {
  1233. ic = DDI_INTR_CLAIMED;
  1234. }
  1235. if ((recv_data == 0xFF)) {
  1236. ic = DDI_INTR_CLAIMED;
  1237. }
  1238. mutex_exit(&unitp->umutex);
  1239. return (ic);
  1240. }
  1241. static void
  1242. envctrl_init_bus(struct envctrlunit *unitp)
  1243. {
  1244. int i;
  1245. uint8_t noval = NULL;
  1246. struct envctrl_tda8444t_chip fan;
  1247. int fans[] = {ENVCTRL_CPU_FANS, ENVCTRL_PS_FANS, ENVCTRL_AFB_FANS};
  1248. mutex_enter(&unitp->umutex);
  1249. /* Sets the Mode to 808x type bus */
  1250. ddi_put8(unitp->ctlr_handle,
  1251. &unitp->bus_ctl_regs->s0, ENVCTRL_CHAR_ZERO);
  1252. /* SET UP SLAVE ADDR XXX Required..send 0x80 */
  1253. ddi_put8(unitp->ctlr_handle, &unitp->bus_ctl_regs->s1,
  1254. ENVCTRL_BUS_INIT0);
  1255. (void) ddi_put8(unitp->ctlr_handle, &unitp->bus_ctl_regs->s0,
  1256. ENVCTRL_BUS_INIT1);
  1257. /* Set the clock now */
  1258. ddi_put8(unitp->ctlr_handle,
  1259. &unitp->bus_ctl_regs->s1, ENVCTRL_BUS_CLOCK0);
  1260. /* S0 is now S2 necause of the previous write to S1 */
  1261. /* clock= 12MHz, SCL=90KHz */
  1262. ddi_put8(unitp->ctlr_handle,
  1263. &unitp->bus_ctl_regs->s0, ENVCTRL_BUS_CLOCK1);
  1264. /* Enable serial interface */
  1265. ddi_put8(unitp->ctlr_handle,
  1266. &unitp->bus_ctl_regs->s1, ENVCTRL_BUS_ESI);
  1267. envctrl_stop_clock(unitp);
  1268. /*
  1269. * This has been added here because the DAC is powered
  1270. * on at "0". When the reset_dflop routine is called
  1271. * this switched the fans from blast to DAC control.
  1272. * if the DAC is at "0", then the fans momentarily lose
  1273. * power until the temp polling and fan set routine is
  1274. * first called. If the fans lose power, then there is
  1275. * a fan fault generated and the system will power off.
  1276. * We only want to do this IF the bus is first being
  1277. * initted. This will cause errors in Sunvts if we reset
  1278. * the fan speed under normal operation. Sometimes we need
  1279. * to be able to induce fan faults. Init bus is a common
  1280. * routine to unwedge the i2c bus in some cases.
  1281. */
  1282. if (unitp->initting == B_TRUE) {
  1283. fan.chip_num = ENVCTRL_TDA8444T_DEV7;
  1284. fan.val = INIT_FAN_VAL;
  1285. for (i = 0; i < sizeof (fans)/sizeof (int); i++) {
  1286. fan.fan_num = fans[i];
  1287. if ((fans[i] == ENVCTRL_AFB_FANS) &&
  1288. (unitp->AFB_present == B_FALSE))
  1289. continue;
  1290. (void) envctrl_xmit(unitp, (caddr_t *)(void *)&fan,
  1291. TDA8444T);
  1292. }
  1293. }
  1294. envctrl_reset_dflop(unitp);
  1295. envctrl_enable_devintrs(unitp);
  1296. unitp->current_mode = ENVCTRL_NORMAL_MODE;
  1297. envctrl_reset_watchdog(unitp, &noval);
  1298. mutex_exit(&unitp->umutex);
  1299. }
  1300. static int
  1301. envctrl_xmit(struct envctrlunit *unitp, caddr_t *data, int chip_type)
  1302. {
  1303. struct envctrl_tda8444t_chip *fanspeed;
  1304. struct envctrl_pcf8574_chip *ioport;
  1305. uint8_t slave_addr;
  1306. uint8_t buf[2];
  1307. int retrys = 0;
  1308. int status;
  1309. ASSERT(MUTEX_HELD(&unitp->umutex));
  1310. switch (chip_type) {
  1311. case TDA8444T:
  1312. fanspeed = (struct envctrl_tda8444t_chip *)data;
  1313. if (fanspeed->chip_num > ENVCTRL_FAN_ADDR_MAX) {
  1314. return (DDI_FAILURE);
  1315. }
  1316. if (fanspeed->fan_num > ENVCTRL_PORT7) {
  1317. return (DDI_FAILURE);
  1318. }
  1319. if (fanspeed->val > MAX_FAN_VAL) {
  1320. return (DDI_FAILURE);
  1321. }
  1322. retry0:
  1323. slave_addr = (TDA8444T_BASE_ADDR | fanspeed->chip_num);
  1324. buf[0] = fanspeed->val;
  1325. status = eHc_write_tda8444((struct eHc_envcunit *)unitp,
  1326. TDA8444T_BASE_ADDR | fanspeed->chip_num, 0xF,
  1327. fanspeed->fan_num, buf, 1);
  1328. if (status != DDI_SUCCESS) {
  1329. drv_usecwait(1000);
  1330. if (retrys < envctrl_max_retries) {
  1331. retrys++;
  1332. goto retry0;
  1333. } else {
  1334. mutex_exit(&unitp->umutex);
  1335. envctrl_init_bus(unitp);
  1336. mutex_enter(&unitp->umutex);
  1337. if (envctrl_debug_flags)
  1338. cmn_err(CE_WARN,
  1339. "envctrl_xmit: Write to TDA8444 " \
  1340. "failed\n");
  1341. return (DDI_FAILURE);
  1342. }
  1343. }
  1344. /*
  1345. * Update the kstats.
  1346. */
  1347. switch (fanspeed->fan_num) {
  1348. case ENVCTRL_CPU_FANS:
  1349. unitp->fan_kstats[ENVCTRL_FAN_TYPE_CPU].fanspeed =
  1350. fanspeed->val;
  1351. break;
  1352. case ENVCTRL_PS_FANS:
  1353. unitp->fan_kstats[ENVCTRL_FAN_TYPE_PS].fanspeed =
  1354. fanspeed->val;
  1355. break;
  1356. case ENVCTRL_AFB_FANS:
  1357. unitp->fan_kstats[ENVCTRL_FAN_TYPE_AFB].fanspeed =
  1358. fanspeed->val;
  1359. break;
  1360. default:
  1361. break;
  1362. }
  1363. break;
  1364. case PCF8574:
  1365. ioport = (struct envctrl_pcf8574_chip *)data;
  1366. buf[0] = ioport->val;
  1367. if (ioport->chip_num > ENVCTRL_PCF8574_DEV7)
  1368. return (DDI_FAILURE);
  1369. retry:
  1370. if (ioport->type == PCF8574A) {
  1371. slave_addr = (PCF8574A_BASE_ADDR | ioport->chip_num);
  1372. status =
  1373. eHc_write_pcf8574a((struct eHc_envcunit *)unitp,
  1374. PCF8574A_BASE_ADDR | ioport->chip_num, buf, 1);
  1375. } else {
  1376. slave_addr = (PCF8574_BASE_ADDR | ioport->chip_num);
  1377. status = eHc_write_pcf8574((struct eHc_envcunit *)unitp,
  1378. PCF8574_BASE_ADDR | ioport->chip_num, buf, 1);
  1379. }
  1380. if (status != DDI_SUCCESS) {
  1381. drv_usecwait(1000);
  1382. if (retrys < envctrl_max_retries) {
  1383. retrys++;
  1384. goto retry;
  1385. } else {
  1386. mutex_exit(&unitp->umutex);
  1387. envctrl_init_bus(unitp);
  1388. mutex_enter(&unitp->umutex);
  1389. if (envctrl_debug_flags)
  1390. cmn_err(CE_WARN, "Write to PCF8574 " \
  1391. "failed, addr = %X\n", slave_addr);
  1392. if (envctrl_debug_flags)
  1393. cmn_err(CE_WARN, "envctrl_xmit: PCF8574\
  1394. dev = %d, port = %d\n",
  1395. ioport->chip_num, ioport->type);
  1396. return (DDI_FAILURE);
  1397. }
  1398. }
  1399. break;
  1400. default:
  1401. return (DDI_FAILURE);
  1402. }
  1403. return (DDI_SUCCESS);
  1404. }
  1405. static void
  1406. envctrl_recv(struct envctrlunit *unitp, caddr_t *data, int chip_type)
  1407. {
  1408. struct envctrl_pcf8591_chip *temp;
  1409. struct envctrl_pcf8574_chip *ioport;
  1410. uint8_t slave_addr, recv_data;
  1411. int retrys = 0;
  1412. int status;
  1413. uint8_t buf[1];
  1414. ASSERT(MUTEX_HELD(&unitp->umutex));
  1415. switch (chip_type) {
  1416. case PCF8591:
  1417. temp = (struct envctrl_pcf8591_chip *)data;
  1418. slave_addr = (PCF8591_BASE_ADDR | temp->chip_num);
  1419. retry:
  1420. status = eHc_read_pcf8591((struct eHc_envcunit *)unitp,
  1421. PCF8591_BASE_ADDR | temp->chip_num & 0xF,
  1422. temp->sensor_num, 0, 0, 1, &recv_data, 1);
  1423. /*
  1424. * another place to catch the i2c bus hang on an 8591 read
  1425. * In this instance we will just return the data that is read
  1426. * after the max_retry because this could be a valid value.
  1427. */
  1428. if (status != DDI_SUCCESS) {
  1429. drv_usecwait(1000);
  1430. if (retrys < envctrl_max_retries) {
  1431. retrys++;
  1432. goto retry;
  1433. } else {
  1434. mutex_exit(&unitp->umutex);
  1435. envctrl_init_bus(unitp);
  1436. mutex_enter(&unitp->umutex);
  1437. if (envctrl_debug_flags)
  1438. cmn_err(CE_WARN, "Read from PCF8591 " \
  1439. "failed, slave_addr = %x\n",
  1440. slave_addr);
  1441. }
  1442. }
  1443. temp->temp_val = recv_data;
  1444. break;
  1445. case TDA8444T:
  1446. printf("envctrl_recv: attempting to read TDA8444T\n");
  1447. return;
  1448. case PCF8574:
  1449. ioport = (struct envctrl_pcf8574_chip *)data;
  1450. retry1:
  1451. if (ioport->chip_num > ENVCTRL_PCF8574_DEV7)
  1452. cmn_err(CE_WARN, "envctrl: dev out of range 0x%x\n",
  1453. ioport->chip_num);
  1454. if (ioport->type == PCF8574A) {
  1455. slave_addr = (PCF8574_READ_BIT | PCF8574A_BASE_ADDR |
  1456. ioport->chip_num);
  1457. status = eHc_read_pcf8574a((struct eHc_envcunit *)unitp,
  1458. PCF8574A_BASE_ADDR | ioport->chip_num, buf, 1);
  1459. } else {
  1460. slave_addr = (PCF8574_READ_BIT | PCF8574_BASE_ADDR |
  1461. ioport->chip_num);
  1462. status = eHc_read_pcf8574((struct eHc_envcunit *)unitp,
  1463. PCF8574_BASE_ADDR | ioport->chip_num, buf, 1);
  1464. }
  1465. if (status != DDI_SUCCESS) {
  1466. drv_usecwait(1000);
  1467. if (retrys < envctrl_max_retries) {
  1468. retrys++;
  1469. goto retry1;
  1470. } else {
  1471. mutex_exit(&unitp->umutex);
  1472. envctrl_init_bus(unitp);
  1473. mutex_enter(&unitp->umutex);
  1474. if (envctrl_debug_flags)
  1475. cmn_err(CE_WARN, "Read from PCF8574 "\
  1476. "failed, addr = %X\n", slave_addr);
  1477. if (envctrl_debug_flags)
  1478. cmn_err(CE_WARN, "envctrl_recv: PCF8574\
  1479. dev = %d, port = %d\n",
  1480. ioport->chip_num, ioport->type);
  1481. }
  1482. }
  1483. ioport->val = buf[0];
  1484. break;
  1485. default:
  1486. break;
  1487. }
  1488. }
  1489. static int
  1490. envctrl_get_ps_temp(struct envctrlunit *unitp, uint8_t psaddr)
  1491. {
  1492. uint8_t tempr;
  1493. int i, retrys;
  1494. int status;
  1495. uint8_t buf[4];
  1496. ASSERT(MUTEX_HELD(&unitp->umutex));
  1497. tempr = 0;
  1498. retrys = 0;
  1499. retry:
  1500. status = eHc_read_pcf8591((struct eHc_envcunit *)unitp,
  1501. PCF8591_BASE_ADDR | psaddr & 0xF, 0, 1, 0, 1, buf, 4);
  1502. tempr = 0;
  1503. for (i = 0; i < PCF8591_MAX_PORTS; i++) {
  1504. /*
  1505. * The pcf8591 will return 0xff if no port
  1506. * is there.. this is bogus for setting temps.
  1507. * so just ignore it!
  1508. */
  1509. if (envctrl_debug_flags) {
  1510. cmn_err(CE_WARN, "PS addr 0x%x recvd 0x%x on port %d\n",
  1511. psaddr, buf[i], i);
  1512. }
  1513. if (buf[i] > tempr && buf[i] < MAX_PS_ADVAL) {
  1514. tempr = buf[i];
  1515. }
  1516. }
  1517. /*
  1518. * This routine is a safeguard to make sure that if the
  1519. * powersupply temps cannot be read that we do something
  1520. * to make sure that the system will notify the user and
  1521. * it will stay running with the fans at 100%. The calling
  1522. * routine should take care of that.
  1523. */
  1524. if (status != DDI_SUCCESS) {
  1525. drv_usecwait(1000);
  1526. if (retrys < envctrl_max_retries) {
  1527. retrys++;
  1528. goto retry;
  1529. } else {
  1530. mutex_exit(&unitp->umutex);
  1531. envctrl_init_bus(unitp);
  1532. mutex_enter(&unitp->umutex);
  1533. if (envctrl_debug_flags)
  1534. cmn_err(CE_WARN,
  1535. "Cannot read Power Supply Temps addr = %X",
  1536. psaddr);
  1537. return (PS_DEFAULT_VAL);
  1538. }
  1539. }
  1540. return (ps_temps[tempr]);
  1541. }
  1542. static int
  1543. envctrl_get_cpu_temp(struct envctrlunit *unitp, int cpunum)
  1544. {
  1545. uint8_t recv_data;
  1546. int retrys;
  1547. int status;
  1548. ASSERT(MUTEX_HELD(&unitp->umutex));
  1549. /*
  1550. * This routine takes in the number of the port that
  1551. * we want to read in the 8591. This should be the
  1552. * location of the COU thermistor for one of the 4
  1553. * cpu's. It will return the temperature in degrees C
  1554. * to the caller.
  1555. */
  1556. retrys = 0;
  1557. retry:
  1558. status = eHc_read_pcf8591((struct eHc_envcunit *)unitp,
  1559. PCF8591_BASE_ADDR | PCF8591_DEV7, cpunum, 0, 0, 0,
  1560. &recv_data, 1);
  1561. /*
  1562. * We need to take a sledge hammer to the bus if we get back
  1563. * value of the chip. This means that the i2c bus got wedged.
  1564. * On the 1.4 systems this happens sometimes while running
  1565. * sunvts. We will return the max cpu temp minus 10 to make
  1566. * the fans run at full speed so that we don;t cook the
  1567. * system.
  1568. * At this point this is a workaround for hardware glitch.
  1569. */
  1570. if (status == DDI_FAILURE) {
  1571. drv_usecwait(1000);
  1572. if (retrys < envctrl_max_retries) {
  1573. retrys++;
  1574. goto retry;
  1575. } else {
  1576. mutex_exit(&unitp->umutex);
  1577. envctrl_init_bus(unitp);
  1578. mutex_enter(&unitp->umutex);
  1579. if (envctrl_debug_flags)
  1580. cmn_err(CE_WARN, "envctrl CPU TEMP read " \
  1581. "failed\n");
  1582. /* we don't want to power off the system */
  1583. return (MAX_CPU_TEMP - 10);
  1584. }
  1585. }
  1586. return (cpu_temps[recv_data]);
  1587. }
  1588. static int
  1589. envctrl_get_lm75_temp(struct envctrlunit *unitp)
  1590. {
  1591. int k;
  1592. ushort_t lmval;
  1593. uint8_t tmp1;
  1594. uint8_t tmp2;
  1595. int status;
  1596. uint8_t buf[2];
  1597. ASSERT(MUTEX_HELD(&unitp->umutex));
  1598. status = eHc_read_lm75((struct eHc_envcunit *)unitp,
  1599. LM75_BASE_ADDR | LM75_CONFIG_ADDRA, buf, 2);
  1600. if (status != DDI_SUCCESS)
  1601. cmn_err(CE_WARN, "read of LM75 failed\n");
  1602. tmp1 = buf[0];
  1603. tmp2 = buf[1];
  1604. /*
  1605. * Store the forst 8 bits in the upper nibble of the
  1606. * short, then store the lower 8 bits in the lower nibble
  1607. * of the short, shift 7 to the right to get the 9 bit value
  1608. * that the lm75 is really sending.
  1609. */
  1610. lmval = tmp1 << 8;
  1611. lmval = (lmval | tmp2);
  1612. lmval = (lmval >> 7);
  1613. /*
  1614. * Check the 9th bit to see if it is a negative
  1615. * temperature. If so change into 2's compliment
  1616. * and divide by 2 since each value is equal to a
  1617. * half degree strp in degrees C
  1618. */
  1619. if (lmval & LM75_COMP_MASK) {
  1620. tmp1 = (lmval & LM75_COMP_MASK_UPPER);
  1621. tmp1 = -tmp1;
  1622. tmp1 = tmp1/2;
  1623. k = 0 - tmp1;
  1624. } else {
  1625. k = lmval /2;
  1626. }
  1627. return (k);
  1628. }
  1629. static void
  1630. envctrl_tempr_poll(void *arg)
  1631. {
  1632. int diag_flag = 0;
  1633. struct envctrlunit *unitp = (struct envctrlunit *)arg;
  1634. mutex_enter(&unitp->umutex);
  1635. if (unitp->shutdown == B_TRUE) {
  1636. (void) power_down("Fatal System Environmental Control Error");
  1637. }
  1638. /*
  1639. * if we are in diag mode and the temp poll thread goes off,
  1640. * this means that the system is too heavily loaded and the 60 second
  1641. * window to execute the test is failing. We will change the fanspeed
  1642. * but will not check for a fanfault. This will cause a system shutdown
  1643. * if the system has had a fanfault injected.
  1644. */
  1645. if (unitp->current_mode == ENVCTRL_DIAG_MODE) {
  1646. diag_flag++;
  1647. if (envctrl_debug_flags) {
  1648. cmn_err(CE_WARN,
  1649. "Tempr poll went off while in DIAG MODE");
  1650. }
  1651. }
  1652. unitp->current_mode = ENVCTRL_NORMAL_MODE;
  1653. envctrl_get_sys_temperatures(unitp, (uint8_t *)NULL);
  1654. if (diag_flag == 0) {
  1655. envctrl_fan_fail_service(unitp);
  1656. }
  1657. /* now have this thread sleep for a while */
  1658. unitp->timeout_id = (timeout(envctrl_tempr_poll,
  1659. (caddr_t)unitp, overtemp_timeout_hz));
  1660. mutex_exit(&unitp->umutex);
  1661. }
  1662. static void
  1663. envctrl_led_blink(void *arg)
  1664. {
  1665. struct envctrl_pcf8574_chip fspchip;
  1666. struct envctrlunit *unitp = (struct envctrlunit *)arg;
  1667. mutex_enter(&unitp->umutex);
  1668. fspchip.type = PCF8574A;
  1669. fspchip.chip_num = ENVCTRL_PCF8574_DEV6; /* 0x01 port 1 */
  1670. envctrl_recv(unitp, (caddr_t *)(void *)&fspchip, PCF8574);
  1671. if (unitp->present_led_state == B_TRUE) {
  1672. /*
  1673. * Now we need to "or" in fault bits of the FSP
  1674. * module for the mass storage fault led.
  1675. * and set it.
  1676. */
  1677. fspchip.val = (fspchip.val & ~(ENVCTRL_PCF8574_PORT4) |
  1678. 0xC0);
  1679. unitp->present_led_state = B_FALSE;
  1680. } else {
  1681. fspchip.val = (fspchip.val | ENVCTRL_PCF8574_PORT4 | 0xC0);
  1682. unitp->present_led_state = B_TRUE;
  1683. }
  1684. (void) envctrl_xmit(unitp, (caddr_t *)(void *)&fspchip, PCF8574);
  1685. /* now have this thread sleep for a while */
  1686. unitp->blink_timeout_id = (timeout(envctrl_led_blink,
  1687. (caddr_t)unitp, blink_timeout_hz));
  1688. mutex_exit(&unitp->umutex);
  1689. }
  1690. /* called with mutex held */
  1691. static void
  1692. envctrl_get_sys_temperatures(struct envctrlunit *unitp, uint8_t *diag_tempr)
  1693. {
  1694. int temperature, tmptemp, cputemp, hicputemp, ambtemp;
  1695. int i;
  1696. struct envctrl_tda8444t_chip fan;
  1697. uint8_t psaddr[] = {PSTEMP3, PSTEMP2, PSTEMP1, PSTEMP0};
  1698. uint8_t noval = NULL;
  1699. uint8_t fspval;
  1700. ASSERT(MUTEX_HELD(&unitp->umutex));
  1701. fan.fan_num = ENVCTRL_CPU_FANS;
  1702. fan.chip_num = ENVCTRL_TDA8444T_DEV7;
  1703. tmptemp = 0; /* Right init value ?? */
  1704. /*
  1705. * THis routine is caled once every minute
  1706. * we wil re-se the watchdog timer each time
  1707. * we poll the temps. The watchdog timer is
  1708. * set up for 3 minutes. Should the kernel thread
  1709. * wedge, for some reason the watchdog will go off
  1710. * and blast the fans.
  1711. */
  1712. if (

Large files files are truncated, but you can click here to view the full file