xref: /titanic_52/usr/src/cmd/scadm/sparc/mpxu/common/wrappers.c (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
1*03831d35Sstevel /*
2*03831d35Sstevel  * CDDL HEADER START
3*03831d35Sstevel  *
4*03831d35Sstevel  * The contents of this file are subject to the terms of the
5*03831d35Sstevel  * Common Development and Distribution License (the "License").
6*03831d35Sstevel  * You may not use this file except in compliance with the License.
7*03831d35Sstevel  *
8*03831d35Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*03831d35Sstevel  * or http://www.opensolaris.org/os/licensing.
10*03831d35Sstevel  * See the License for the specific language governing permissions
11*03831d35Sstevel  * and limitations under the License.
12*03831d35Sstevel  *
13*03831d35Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
14*03831d35Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*03831d35Sstevel  * If applicable, add the following below this CDDL HEADER, with the
16*03831d35Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
17*03831d35Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
18*03831d35Sstevel  *
19*03831d35Sstevel  * CDDL HEADER END
20*03831d35Sstevel  */
21*03831d35Sstevel 
22*03831d35Sstevel /*
23*03831d35Sstevel  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*03831d35Sstevel  * Use is subject to license terms.
25*03831d35Sstevel  */
26*03831d35Sstevel 
27*03831d35Sstevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*03831d35Sstevel 
29*03831d35Sstevel /*
30*03831d35Sstevel  * wrappers.c: utility for scadm command processing functions
31*03831d35Sstevel  */
32*03831d35Sstevel 
33*03831d35Sstevel #include <libintl.h>
34*03831d35Sstevel #include <stdio.h>
35*03831d35Sstevel #include <errno.h>
36*03831d35Sstevel #include <time.h>  /* required by rsc.h */
37*03831d35Sstevel 
38*03831d35Sstevel #include "librsc.h"
39*03831d35Sstevel #include "adm.h"
40*03831d35Sstevel 
41*03831d35Sstevel 
42*03831d35Sstevel void
43*03831d35Sstevel ADM_Start()
44*03831d35Sstevel {
45*03831d35Sstevel 	if (rscp_start() != 0) {
46*03831d35Sstevel 
47*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
48*03831d35Sstevel 		    gettext("scadm: SC firmware not responding"));
49*03831d35Sstevel 		exit(-1);
50*03831d35Sstevel 	}
51*03831d35Sstevel }
52*03831d35Sstevel 
53*03831d35Sstevel 
54*03831d35Sstevel void
55*03831d35Sstevel ADM_Send(rscp_msg_t *msg)
56*03831d35Sstevel {
57*03831d35Sstevel 	int err;
58*03831d35Sstevel 
59*03831d35Sstevel 	err = rscp_send(msg);
60*03831d35Sstevel 
61*03831d35Sstevel 	if (err == ENOTSUP) {
62*03831d35Sstevel 
63*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
64*03831d35Sstevel 		    gettext("scadm: command/option not supported"));
65*03831d35Sstevel 		exit(-1);
66*03831d35Sstevel 
67*03831d35Sstevel 	} else if (err != 0) {
68*03831d35Sstevel 
69*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
70*03831d35Sstevel 		    gettext("scadm: unable to send data to SC"));
71*03831d35Sstevel 		exit(-1);
72*03831d35Sstevel 	}
73*03831d35Sstevel }
74*03831d35Sstevel 
75*03831d35Sstevel 
76*03831d35Sstevel int
77*03831d35Sstevel ADM_Send_ret(rscp_msg_t *msg)
78*03831d35Sstevel {
79*03831d35Sstevel 	return (rscp_send(msg));
80*03831d35Sstevel }
81*03831d35Sstevel 
82*03831d35Sstevel 
83*03831d35Sstevel void
84*03831d35Sstevel ADM_Recv(rscp_msg_t *msg, struct timespec *timeout, int expectType,
85*03831d35Sstevel     int expectSize)
86*03831d35Sstevel {
87*03831d35Sstevel 	if (rscp_recv(msg, timeout) != 0) {
88*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
89*03831d35Sstevel 		    gettext("scadm: SC not responding to requests"));
90*03831d35Sstevel 		exit(-1);
91*03831d35Sstevel 	}
92*03831d35Sstevel 
93*03831d35Sstevel 	if ((msg->type != expectType) || (msg->len < expectSize)) {
94*03831d35Sstevel 		(void) fprintf(stderr, "\n%s: 0x%08x:0x%08lx\n\n",
95*03831d35Sstevel 		    gettext("scadm: SC returned garbage"),
96*03831d35Sstevel 		    msg->type, msg->len);
97*03831d35Sstevel 		exit(-1);
98*03831d35Sstevel 	}
99*03831d35Sstevel 
100*03831d35Sstevel }
101*03831d35Sstevel 
102*03831d35Sstevel 
103*03831d35Sstevel void
104*03831d35Sstevel ADM_Free(rscp_msg_t *msg)
105*03831d35Sstevel {
106*03831d35Sstevel 	if (rscp_free_msg(msg) != 0) {
107*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
108*03831d35Sstevel 		    gettext("scadm: SC unable to free up memory"));
109*03831d35Sstevel 		exit(-1);
110*03831d35Sstevel 	}
111*03831d35Sstevel }
112