xref: /illumos-gate/usr/src/cmd/sf880drd/sf880drd.c (revision 2a8bcb4e)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2000, 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
27*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
28*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
29*7c478bd9Sstevel@tonic-gate #include <sys/i2c/clients/i2c_client.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/hpc3130_events.h>
31*7c478bd9Sstevel@tonic-gate #include <values.h>		/* for BITSPERBYTE */
32*7c478bd9Sstevel@tonic-gate #include <unistd.h>
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
36*7c478bd9Sstevel@tonic-gate #include <strings.h>
37*7c478bd9Sstevel@tonic-gate #include <poll.h>
38*7c478bd9Sstevel@tonic-gate #include <libintl.h>
39*7c478bd9Sstevel@tonic-gate #include <errno.h>
40*7c478bd9Sstevel@tonic-gate #include <assert.h>
41*7c478bd9Sstevel@tonic-gate #include <config_admin.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/daktari.h>
43*7c478bd9Sstevel@tonic-gate #include "sf880drd.h"
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * Hotplug Controller addresses.
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate static const unsigned char controller_names[NUM_CONTROLLERS] =
49*7c478bd9Sstevel@tonic-gate 	{ 0xe2, 0xe6, 0xe8, 0xec };
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate #define	INDEX2SLOT(INDEX)	((INDEX)%4) /* cf init_poll_events() */
52*7c478bd9Sstevel@tonic-gate #define	INDEX2CONTROLLER(INDEX)	((INDEX)/4) /* cf init_poll_events() */
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /*
55*7c478bd9Sstevel@tonic-gate  *  Local variables.
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate static struct pollfd fds[NUM_FDS];
58*7c478bd9Sstevel@tonic-gate static unsigned int fault_leds[2];
59*7c478bd9Sstevel@tonic-gate static unsigned int ok2rem_leds[2];
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  *  Local prototypes.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate static void init_poll_events(void);
65*7c478bd9Sstevel@tonic-gate static void process_event(int);
66*7c478bd9Sstevel@tonic-gate static void report_cfgadm_error(int, char *);
67*7c478bd9Sstevel@tonic-gate static void set_front_panel_led(uint8_t, boolean_t);
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate static int i2c_set_bit(int, int, uint8_t);
70*7c478bd9Sstevel@tonic-gate static void report_syscall_error(char *);
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate static void pushbutton_event(char *);
73*7c478bd9Sstevel@tonic-gate static void fault_led_event(hpc3130_event_type_t, int);
74*7c478bd9Sstevel@tonic-gate static void removable_led_event(hpc3130_event_type_t, int);
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /*
77*7c478bd9Sstevel@tonic-gate  * main(): loops forever looking for events.
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate int
main()80*7c478bd9Sstevel@tonic-gate main()
81*7c478bd9Sstevel@tonic-gate {
82*7c478bd9Sstevel@tonic-gate 	int	i;
83*7c478bd9Sstevel@tonic-gate 	int	rv;
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 	init_poll_events();
86*7c478bd9Sstevel@tonic-gate 	for (;;) {
87*7c478bd9Sstevel@tonic-gate 		/* sleep in poll() waiting an event */
88*7c478bd9Sstevel@tonic-gate 		rv = poll(fds, NUM_FDS, -1);
89*7c478bd9Sstevel@tonic-gate 		if (rv < 0) {
90*7c478bd9Sstevel@tonic-gate 			report_syscall_error("poll");
91*7c478bd9Sstevel@tonic-gate 			continue;
92*7c478bd9Sstevel@tonic-gate 		}
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 		/* woken up from poll() process the event */
95*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < NUM_FDS; ++i) {
96*7c478bd9Sstevel@tonic-gate 			if (fds[i].revents == POLLIN)
97*7c478bd9Sstevel@tonic-gate 				process_event(i);
98*7c478bd9Sstevel@tonic-gate 		}
99*7c478bd9Sstevel@tonic-gate 	}
100*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
101*7c478bd9Sstevel@tonic-gate 	return (0);
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate /*
105*7c478bd9Sstevel@tonic-gate  * Set up poll fds.
106*7c478bd9Sstevel@tonic-gate  */
107*7c478bd9Sstevel@tonic-gate static void
init_poll_events()108*7c478bd9Sstevel@tonic-gate init_poll_events()
109*7c478bd9Sstevel@tonic-gate {
110*7c478bd9Sstevel@tonic-gate 	int c;
111*7c478bd9Sstevel@tonic-gate 	int p;
112*7c478bd9Sstevel@tonic-gate 	int i = 0;
113*7c478bd9Sstevel@tonic-gate 	char buf[sizeof (HPC3130_DEV_FMT)+8];
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	for (c = 0; c < NUM_CONTROLLERS; ++c) {
116*7c478bd9Sstevel@tonic-gate 		for (p = 0; p < SLOTS_PER_CONTROLLER; ++p) {
117*7c478bd9Sstevel@tonic-gate 			(void) sprintf(buf, HPC3130_DEV_FMT,
118*7c478bd9Sstevel@tonic-gate 			    controller_names[c], p);
119*7c478bd9Sstevel@tonic-gate 			fds[i].events = POLLIN;
120*7c478bd9Sstevel@tonic-gate 			fds[i].fd = open(buf, O_RDWR);
121*7c478bd9Sstevel@tonic-gate 			if (fds[i].fd == -1) {
122*7c478bd9Sstevel@tonic-gate 				report_syscall_error(buf);
123*7c478bd9Sstevel@tonic-gate 				exit(-1);
124*7c478bd9Sstevel@tonic-gate 			}
125*7c478bd9Sstevel@tonic-gate 			i++;
126*7c478bd9Sstevel@tonic-gate 		}
127*7c478bd9Sstevel@tonic-gate 	}
128*7c478bd9Sstevel@tonic-gate }
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate /*
131*7c478bd9Sstevel@tonic-gate  * Process poll events.
132*7c478bd9Sstevel@tonic-gate  */
133*7c478bd9Sstevel@tonic-gate static void
process_event(int fdi)134*7c478bd9Sstevel@tonic-gate process_event(int fdi)
135*7c478bd9Sstevel@tonic-gate {
136*7c478bd9Sstevel@tonic-gate 	struct hpc3130_event e;
137*7c478bd9Sstevel@tonic-gate 	int rv;
138*7c478bd9Sstevel@tonic-gate 	int slot = INDEX2SLOT(fdi);
139*7c478bd9Sstevel@tonic-gate 	int cntr = INDEX2CONTROLLER(fdi);
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	rv = ioctl(fds[fdi].fd, HPC3130_GET_EVENT, &e);
142*7c478bd9Sstevel@tonic-gate 	if (rv == -1) {
143*7c478bd9Sstevel@tonic-gate 		report_syscall_error("HPC3130_GET_EVENT");
144*7c478bd9Sstevel@tonic-gate 		return;
145*7c478bd9Sstevel@tonic-gate 	}
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	switch (e.id) {
148*7c478bd9Sstevel@tonic-gate 	case HPC3130_EVENT_INSERTION:
149*7c478bd9Sstevel@tonic-gate 	case HPC3130_EVENT_REMOVAL:
150*7c478bd9Sstevel@tonic-gate 	case HPC3130_EVENT_POWERON:
151*7c478bd9Sstevel@tonic-gate 	case HPC3130_EVENT_POWEROFF:
152*7c478bd9Sstevel@tonic-gate 		break;
153*7c478bd9Sstevel@tonic-gate 	case HPC3130_EVENT_BUTTON:
154*7c478bd9Sstevel@tonic-gate 		DPRINTF(("\nBUTTON EVENT slot (%s)\n", e.name));
155*7c478bd9Sstevel@tonic-gate 		pushbutton_event(e.name);
156*7c478bd9Sstevel@tonic-gate 		break;
157*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_FAULT_ON:
158*7c478bd9Sstevel@tonic-gate 		DPRINTF(("\nFAULT LED ON EVENT\n"));
159*7c478bd9Sstevel@tonic-gate 		fault_led_event(e.id, fdi);
160*7c478bd9Sstevel@tonic-gate 		break;
161*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_FAULT_OFF:
162*7c478bd9Sstevel@tonic-gate 		DPRINTF(("\nFAULT LED OFF EVENT\n"));
163*7c478bd9Sstevel@tonic-gate 		fault_led_event(e.id, fdi);
164*7c478bd9Sstevel@tonic-gate 		break;
165*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_REMOVABLE_ON:
166*7c478bd9Sstevel@tonic-gate 		DPRINTF(("\nREMOVABLE LED ON EVENT\n"));
167*7c478bd9Sstevel@tonic-gate 		removable_led_event(e.id, fdi);
168*7c478bd9Sstevel@tonic-gate 		break;
169*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_REMOVABLE_OFF:
170*7c478bd9Sstevel@tonic-gate 		DPRINTF(("\nREMOVABLE LED OFF EVENT\n"));
171*7c478bd9Sstevel@tonic-gate 		removable_led_event(e.id, fdi);
172*7c478bd9Sstevel@tonic-gate 		break;
173*7c478bd9Sstevel@tonic-gate 	default:
174*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "WARNING: bogus event: %x\n", e.id);
175*7c478bd9Sstevel@tonic-gate 	}
176*7c478bd9Sstevel@tonic-gate }
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate /*
179*7c478bd9Sstevel@tonic-gate  * Button Event handler.
180*7c478bd9Sstevel@tonic-gate  */
181*7c478bd9Sstevel@tonic-gate static void
pushbutton_event(char * ap_id)182*7c478bd9Sstevel@tonic-gate pushbutton_event(char *ap_id)
183*7c478bd9Sstevel@tonic-gate {
184*7c478bd9Sstevel@tonic-gate 	char			*errstr = NULL;
185*7c478bd9Sstevel@tonic-gate 	struct cfga_list_data	*stat = NULL;
186*7c478bd9Sstevel@tonic-gate 	int			nlist;
187*7c478bd9Sstevel@tonic-gate 	cfga_cmd_t		cmd;
188*7c478bd9Sstevel@tonic-gate 	cfga_err_t		rv;
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 	rv = config_list_ext(1, &ap_id, &stat, &nlist,
191*7c478bd9Sstevel@tonic-gate 	    NULL, NULL, &errstr, 0);
192*7c478bd9Sstevel@tonic-gate 	if (rv != CFGA_OK) {
193*7c478bd9Sstevel@tonic-gate 		report_cfgadm_error(rv, errstr);
194*7c478bd9Sstevel@tonic-gate 		goto out;
195*7c478bd9Sstevel@tonic-gate 	}
196*7c478bd9Sstevel@tonic-gate 	assert(nlist == 1);
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 	/* The only types of hotplug with buttons */
199*7c478bd9Sstevel@tonic-gate 	assert(!(strcmp(stat->ap_class, "pci")));
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 	switch (stat->ap_o_state) {
202*7c478bd9Sstevel@tonic-gate 	case CFGA_STAT_UNCONFIGURED:
203*7c478bd9Sstevel@tonic-gate 		cmd = CFGA_CMD_CONFIGURE;
204*7c478bd9Sstevel@tonic-gate 		break;
205*7c478bd9Sstevel@tonic-gate 	case CFGA_STAT_CONFIGURED:
206*7c478bd9Sstevel@tonic-gate 		cmd = CFGA_CMD_DISCONNECT;
207*7c478bd9Sstevel@tonic-gate 		break;
208*7c478bd9Sstevel@tonic-gate 	default:
209*7c478bd9Sstevel@tonic-gate 		/* Should never get here */
210*7c478bd9Sstevel@tonic-gate 		assert(0);
211*7c478bd9Sstevel@tonic-gate 	}
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate 	/*
214*7c478bd9Sstevel@tonic-gate 	 * confp & msgp are NULL: when using the pushbutton,
215*7c478bd9Sstevel@tonic-gate 	 * simply fail if prompting is required.
216*7c478bd9Sstevel@tonic-gate 	 */
217*7c478bd9Sstevel@tonic-gate 	rv = config_change_state(cmd, 1, &ap_id, NULL, NULL, NULL, &errstr, 0);
218*7c478bd9Sstevel@tonic-gate 	if (rv != CFGA_OK) {
219*7c478bd9Sstevel@tonic-gate 		report_cfgadm_error(rv, errstr);
220*7c478bd9Sstevel@tonic-gate 		/* FALLTHRU to "out" */
221*7c478bd9Sstevel@tonic-gate 	}
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate out:
224*7c478bd9Sstevel@tonic-gate 	if (errstr)
225*7c478bd9Sstevel@tonic-gate 		free(errstr);
226*7c478bd9Sstevel@tonic-gate 	if (stat)
227*7c478bd9Sstevel@tonic-gate 		free(stat);
228*7c478bd9Sstevel@tonic-gate }
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate static void
fault_led_event(hpc3130_event_type_t event,int fdi)231*7c478bd9Sstevel@tonic-gate fault_led_event(hpc3130_event_type_t event, int fdi)
232*7c478bd9Sstevel@tonic-gate {
233*7c478bd9Sstevel@tonic-gate 	int		side = 0;
234*7c478bd9Sstevel@tonic-gate 	unsigned int	old;
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	if (INDEX2CONTROLLER(fdi) != GPTWO_CONTROLLER) {
237*7c478bd9Sstevel@tonic-gate 		/* It's a PCI slot; left side of chassis */
238*7c478bd9Sstevel@tonic-gate 		side = 1;
239*7c478bd9Sstevel@tonic-gate 	}
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate 	old = fault_leds[side];
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate 	assert(fdi <= sizeof (fault_leds[side]) * BITSPERBYTE);
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 	switch (event) {
246*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_FAULT_ON:
247*7c478bd9Sstevel@tonic-gate 		fault_leds[side] |= (1<<fdi);
248*7c478bd9Sstevel@tonic-gate 		DPRINTF(("fault_led_event: HPC3130_LED_FAULT_ON\n"));
249*7c478bd9Sstevel@tonic-gate 		break;
250*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_FAULT_OFF:
251*7c478bd9Sstevel@tonic-gate 		fault_leds[side] &= ~(1<<fdi);
252*7c478bd9Sstevel@tonic-gate 		DPRINTF(("fault_led_event: HPC3130_LED_FAULT_OFF\n"));
253*7c478bd9Sstevel@tonic-gate 		break;
254*7c478bd9Sstevel@tonic-gate 	}
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 	DPRINTF(("fault_led_event: old(0x%x), fault_leds[%d](0x%x)\n",
257*7c478bd9Sstevel@tonic-gate 	    old, side, fault_leds[side]));
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 	if ((old == 0) != (fault_leds[side] == 0) && ok2rem_leds[side] == 0) {
260*7c478bd9Sstevel@tonic-gate 		/*
261*7c478bd9Sstevel@tonic-gate 		 * The first FAULT LED has come on, or the last one has gone
262*7c478bd9Sstevel@tonic-gate 		 * off on this side, and all the OK2REMOVE LEDS are off on this
263*7c478bd9Sstevel@tonic-gate 		 * side.  So we have to update the front panel ARROW LED.
264*7c478bd9Sstevel@tonic-gate 		 */
265*7c478bd9Sstevel@tonic-gate 		set_front_panel_led(side ? LEFT_DOOR_ATTEN_LED :
266*7c478bd9Sstevel@tonic-gate 		    RIGHT_DOOR_ATTEN_LED,
267*7c478bd9Sstevel@tonic-gate 		    fault_leds[side] ? LED_ON : LED_OFF);
268*7c478bd9Sstevel@tonic-gate 	}
269*7c478bd9Sstevel@tonic-gate }
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate static void
removable_led_event(hpc3130_event_type_t event,int fdi)272*7c478bd9Sstevel@tonic-gate removable_led_event(hpc3130_event_type_t event, int fdi)
273*7c478bd9Sstevel@tonic-gate {
274*7c478bd9Sstevel@tonic-gate 	int		side = 0;
275*7c478bd9Sstevel@tonic-gate 	unsigned int	old;
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate 	if (INDEX2CONTROLLER(fdi) != GPTWO_CONTROLLER) {
278*7c478bd9Sstevel@tonic-gate 		/* It's a PCI slot; left side of chassis */
279*7c478bd9Sstevel@tonic-gate 		side = 1;
280*7c478bd9Sstevel@tonic-gate 	}
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate 	old = ok2rem_leds[side];
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate 	assert(fdi <= sizeof (ok2rem_leds[side]) * BITSPERBYTE);
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 	switch (event) {
287*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_REMOVABLE_ON:
288*7c478bd9Sstevel@tonic-gate 		ok2rem_leds[side] |= (1<<fdi);
289*7c478bd9Sstevel@tonic-gate 		DPRINTF(("removable_led_event: HPC3130_LED_REMOVABLE_ON\n"));
290*7c478bd9Sstevel@tonic-gate 		break;
291*7c478bd9Sstevel@tonic-gate 	case HPC3130_LED_REMOVABLE_OFF:
292*7c478bd9Sstevel@tonic-gate 		ok2rem_leds[side] &= ~(1<<fdi);
293*7c478bd9Sstevel@tonic-gate 		DPRINTF(("removable_led_event: HPC3130_LED_REMOVABLE_OFF\n"));
294*7c478bd9Sstevel@tonic-gate 		break;
295*7c478bd9Sstevel@tonic-gate 	}
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	DPRINTF(("removable_led_event: old(0x%x), ok2rem_leds[%d](0x%x)\n",
298*7c478bd9Sstevel@tonic-gate 	    old, side, ok2rem_leds[side]));
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate 	if ((old == 0) != (ok2rem_leds[side] == 0)) {
301*7c478bd9Sstevel@tonic-gate 		/*
302*7c478bd9Sstevel@tonic-gate 		 * The first OKAY2REMOVE LED has come on, or the last
303*7c478bd9Sstevel@tonic-gate 		 * one has gone off (on this side).  We may have to update
304*7c478bd9Sstevel@tonic-gate 		 * the front panel LEDs.
305*7c478bd9Sstevel@tonic-gate 		 */
306*7c478bd9Sstevel@tonic-gate 		if (ok2rem_leds[!side] == 0) {
307*7c478bd9Sstevel@tonic-gate 			/*
308*7c478bd9Sstevel@tonic-gate 			 * The OK2REMOVE LEDs are all off on the other
309*7c478bd9Sstevel@tonic-gate 			 * side of the chassis, so this side determines
310*7c478bd9Sstevel@tonic-gate 			 * whether the front OK2REMOVE is on or off.
311*7c478bd9Sstevel@tonic-gate 			 */
312*7c478bd9Sstevel@tonic-gate 			set_front_panel_led(SYS_OK2REMOVE_LED,
313*7c478bd9Sstevel@tonic-gate 			    ok2rem_leds[side] ? LED_ON : LED_OFF);
314*7c478bd9Sstevel@tonic-gate 		}
315*7c478bd9Sstevel@tonic-gate 		if (fault_leds[side] == 0) {
316*7c478bd9Sstevel@tonic-gate 			/*
317*7c478bd9Sstevel@tonic-gate 			 * All the FAULT LEDs are off on this side.  So the
318*7c478bd9Sstevel@tonic-gate 			 * OK2REMOVE LEDs determine whether the ARROW LED is on.
319*7c478bd9Sstevel@tonic-gate 			 */
320*7c478bd9Sstevel@tonic-gate 		set_front_panel_led(side ? LEFT_DOOR_ATTEN_LED :
321*7c478bd9Sstevel@tonic-gate 		    RIGHT_DOOR_ATTEN_LED,
322*7c478bd9Sstevel@tonic-gate 		    ok2rem_leds[side] ? LED_ON : LED_OFF);
323*7c478bd9Sstevel@tonic-gate 		}
324*7c478bd9Sstevel@tonic-gate 	}
325*7c478bd9Sstevel@tonic-gate }
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate /*
328*7c478bd9Sstevel@tonic-gate  * Set front panel system leds either on or off.
329*7c478bd9Sstevel@tonic-gate  */
330*7c478bd9Sstevel@tonic-gate static void
set_front_panel_led(uint8_t bit_num,boolean_t on_off)331*7c478bd9Sstevel@tonic-gate set_front_panel_led(uint8_t bit_num, boolean_t on_off)
332*7c478bd9Sstevel@tonic-gate {
333*7c478bd9Sstevel@tonic-gate 	int		fd;
334*7c478bd9Sstevel@tonic-gate 	int		rv;
335*7c478bd9Sstevel@tonic-gate 	i2c_bit_t	arg;
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	fd = open(SSC050_LED_PORT, O_RDWR);
338*7c478bd9Sstevel@tonic-gate 	if (fd == -1) {
339*7c478bd9Sstevel@tonic-gate 		report_syscall_error("ssc050");
340*7c478bd9Sstevel@tonic-gate 		return;
341*7c478bd9Sstevel@tonic-gate 	}
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate 	arg.bit_num = bit_num;
344*7c478bd9Sstevel@tonic-gate 	arg.bit_value = on_off;
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 	rv = ioctl(fd, I2C_SET_BIT, &arg);
347*7c478bd9Sstevel@tonic-gate 	if (rv == -1)
348*7c478bd9Sstevel@tonic-gate 		report_syscall_error("LED I2C_SET_BIT");
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate 	(void) close(fd);
351*7c478bd9Sstevel@tonic-gate }
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate static int
i2c_set_bit(int fp,int bit,uint8_t value)354*7c478bd9Sstevel@tonic-gate i2c_set_bit(int fp, int bit, uint8_t value)
355*7c478bd9Sstevel@tonic-gate {
356*7c478bd9Sstevel@tonic-gate 	int		rv;
357*7c478bd9Sstevel@tonic-gate 	i2c_bit_t	passin;
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate 	passin.bit_num = (uchar_t)bit;
360*7c478bd9Sstevel@tonic-gate 	passin.bit_value = value;
361*7c478bd9Sstevel@tonic-gate 	rv = ioctl(fp, I2C_SET_BIT, &passin);
362*7c478bd9Sstevel@tonic-gate 	return (rv);
363*7c478bd9Sstevel@tonic-gate }
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate static void
report_cfgadm_error(int cfgerrnum,char * errstr)366*7c478bd9Sstevel@tonic-gate report_cfgadm_error(int cfgerrnum, char *errstr)
367*7c478bd9Sstevel@tonic-gate {
368*7c478bd9Sstevel@tonic-gate 	const char	*ep;
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate 	ep = config_strerror(cfgerrnum);
371*7c478bd9Sstevel@tonic-gate 
372*7c478bd9Sstevel@tonic-gate 	if (ep == NULL)
373*7c478bd9Sstevel@tonic-gate 		ep = gettext("configuration administration unknown error");
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate 	if (errstr != NULL && *errstr != '\0') {
376*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: %s\n", ep, errstr);
377*7c478bd9Sstevel@tonic-gate 	} else {
378*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s\n", ep);
379*7c478bd9Sstevel@tonic-gate 	}
380*7c478bd9Sstevel@tonic-gate }
381*7c478bd9Sstevel@tonic-gate 
382*7c478bd9Sstevel@tonic-gate static void
report_syscall_error(char * msg)383*7c478bd9Sstevel@tonic-gate report_syscall_error(char *msg)
384*7c478bd9Sstevel@tonic-gate {
385*7c478bd9Sstevel@tonic-gate 	if (errno != EINTR)
386*7c478bd9Sstevel@tonic-gate 		perror(msg);
387*7c478bd9Sstevel@tonic-gate }
388