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, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 #include <picl.h>
29 #include <picldefs.h>
30 #include "fru_access_impl.h"
31
32 #define SNOWBIRD "SUNW,Netra-CP2300"
33
34 /*
35 * check if the code is running on correct chassis or not.
36 * return :
37 * 0 - if we are on Snowbird
38 * -1 - if we are on wrong system
39 * if there is any error
40 */
41 int
fruaccess_platmod_check_chassis()42 fruaccess_platmod_check_chassis()
43 {
44 picl_nodehdl_t chassish;
45 char chassis_type[PICL_PROPNAMELEN_MAX];
46
47 if (ptree_get_node_by_path(PICL_FRUTREE_CHASSIS,
48 &chassish) != PICL_SUCCESS) {
49 return (-1);
50 }
51
52 if (ptree_get_propval_by_name(chassish, PICL_PROP_CHASSIS_TYPE,
53 chassis_type, sizeof (chassis_type)) != PICL_SUCCESS) {
54 return (-1);
55 }
56
57 if (strcmp(chassis_type, SNOWBIRD) == 0) {
58 return (0);
59 } else {
60 return (-1);
61 }
62 }
63
64 /*
65 * intialize the format structure, fill in src and dest addresses
66 */
67 picl_errno_t
fruaccess_platmod_init_format(uint8_t slot_no,format_t * fru_format)68 fruaccess_platmod_init_format(uint8_t slot_no, format_t *fru_format)
69 {
70 /* initialize src and dest addresses */
71 fru_format->src = IPMB_ADDR(slot_no);
72 fru_format->dest = fru_format->src;
73 return (PICL_SUCCESS);
74 }
75
76 /*
77 * do all valid checks for fru
78 * return : 0 if we can probe for fru
79 * -1 if probing is not required
80 */
81 int
fruaccess_platmod_check_fru(picl_nodehdl_t parenth)82 fruaccess_platmod_check_fru(picl_nodehdl_t parenth)
83 {
84 int retval;
85 char type[PICL_PROPSIZE_MAX];
86 picl_nodehdl_t chassish, loc_parenth;
87
88 retval = ptree_get_propval_by_name(parenth, PICL_PROP_SLOT_TYPE,
89 (void *)type, PICL_PROPSIZE_MAX);
90 if (retval != PICL_SUCCESS) {
91 return (-1);
92 }
93
94 /* check only for pci and cpci slots */
95 if ((strcmp(type, PICL_SLOT_CPCI) != 0) &&
96 (strcmp(type, PICL_SLOT_PCI) != 0)) {
97 return (-1);
98 }
99
100 /* check if location is direct parent of chassis or not */
101 if (ptree_get_node_by_path(PICL_FRUTREE_CHASSIS,
102 &chassish) != PICL_SUCCESS) {
103 return (-1);
104 }
105
106 retval = ptree_get_propval_by_name(parenth, PICL_PROP_PARENT,
107 (void *)&loc_parenth, sizeof (loc_parenth));
108 if (retval != PICL_SUCCESS) {
109 return (-1);
110 }
111
112 if (chassish != loc_parenth) {
113 return (-1);
114 }
115 return (0);
116 }
117