xref: /titanic_44/usr/src/cmd/luxadm/diag.c (revision 5c51f1241dbbdf2656d0e10011981411ed0c9673)
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 
27 
28 /*LINTLIBRARY*/
29 
30 
31 /*
32  *	This module is part of the photon library
33  */
34 
35 /*
36  * I18N message number ranges
37  *  This file: 3500 - 3999
38  *  Shared common messages: 1 - 1999
39  */
40 
41 /*	Includes	*/
42 #include	<stdlib.h>
43 #include	<stdio.h>
44 #include	<sys/file.h>
45 #include	<sys/errno.h>
46 #include	<sys/types.h>
47 #include	<sys/param.h>
48 #include	<fcntl.h>
49 #include	<unistd.h>
50 #include	<errno.h>
51 #include	<string.h>
52 #include	<sys/scsi/scsi.h>
53 #include	<nl_types.h>
54 #include	<strings.h>
55 #include	<sys/ddi.h>	/* for max */
56 #include	<libdevice.h>
57 #include	<sys/fibre-channel/fcio.h>
58 #define	_SYS_FC4_FCAL_LINKAPP_H
59 #include	<sys/fc4/fcio.h>
60 #include	<sys/devctl.h>
61 #include	<sys/scsi/targets/sesio.h>
62 #include	<l_common.h>
63 #include	<l_error.h>
64 #include	<a_state.h>
65 #include	<a5k.h>
66 #include	<stgcom.h>
67 #include	"luxadm.h"
68 
69 
70 /*	Defines		*/
71 #define	VERBPRINT	if (verbose) (void) printf
72 
73 
74 
75 static int
76 print_ssd_in_box(char *ses_path, uchar_t *box_name, int verbose)
77 {
78 L_state		l_state;
79 int		err, i;
80 struct	dlist	*ml;
81 WWN_list	*wwn_list, *wwn_list_ptr;
82 char		*s;
83 L_inquiry	inq;
84 int		enc_type = 0;
85 
86 	wwn_list = wwn_list_ptr = NULL;
87 	if (err = l_get_status(ses_path, &l_state, verbose)) {
88 		return (err);
89 	}
90 
91 	if (err = g_get_wwn_list(&wwn_list, verbose)) {
92 		return (err);
93 
94 	}
95 
96 	/* Need to find out whether this device is a daktari */
97 	if (g_get_inquiry(ses_path, &inq)) {
98 		return (L_SCSI_ERROR);
99 	}
100 	if ((strncmp((char *)&inq.inq_pid[0], DAK_OFF_NAME,
101 						strlen(DAK_OFF_NAME)) == 0) ||
102 			(strncmp((char *)&inq.inq_pid[0], DAK_PROD_STR,
103 						strlen(DAK_PROD_STR)) == 0)) {
104 		enc_type = DAK_ENC_TYPE;
105 	}
106 	for (i = 0; i < (int)l_state.total_num_drv/2; i++) {
107 		if (l_state.drv_front[i].ib_status.code != S_NOT_INSTALLED) {
108 
109 		ml = l_state.drv_front[i].g_disk_state.multipath_list;
110 		while (ml) {
111 			for (wwn_list_ptr = wwn_list; wwn_list_ptr != NULL;
112 					wwn_list_ptr = wwn_list_ptr->wwn_next) {
113 				s = wwn_list_ptr->physical_path;
114 				if (strcmp((char *)s,
115 					ml->dev_path) == 0) {
116 				(void) fprintf(stdout, MSGSTR(3500,
117 					"%-80.80s %-17.17s %-17.17s %-22.22s "),
118 					wwn_list_ptr->physical_path,
119 					wwn_list_ptr->node_wwn_s,
120 					wwn_list_ptr->port_wwn_s,
121 					wwn_list_ptr->logical_path);
122 					if (enc_type == DAK_ENC_TYPE) {
123 						(void) fprintf(stdout,
124 						MSGSTR(3513, "%s,s%d\n"),
125 						box_name, i);
126 					} else {
127 						(void) fprintf(stdout,
128 						MSGSTR(3501, "%s,f%d\n"),
129 						box_name, i);
130 					}
131 				}
132 			}
133 			ml = ml->next;
134 		}
135 
136 		}
137 	}
138 	for (i = 0; i < (int)l_state.total_num_drv/2; i++) {
139 		if (l_state.drv_rear[i].ib_status.code != S_NOT_INSTALLED) {
140 
141 		ml = l_state.drv_rear[i].g_disk_state.multipath_list;
142 		while (ml) {
143 			wwn_list_ptr = wwn_list;
144 			for (wwn_list_ptr = wwn_list; wwn_list_ptr != NULL;
145 					wwn_list_ptr = wwn_list_ptr->wwn_next) {
146 				s = wwn_list_ptr->physical_path;
147 				if (strcmp((char *)s,
148 					ml->dev_path) == 0) {
149 				(void) fprintf(stdout, MSGSTR(3502,
150 					"%-80.80s %-17.17s %-17.17s %-22.22s "),
151 					wwn_list_ptr->physical_path,
152 					wwn_list_ptr->node_wwn_s,
153 					wwn_list_ptr->port_wwn_s,
154 					wwn_list_ptr->logical_path);
155 					if (enc_type == DAK_ENC_TYPE) {
156 						(void) fprintf(stdout,
157 						MSGSTR(3513, "%s,s%d\n"),
158 							box_name,
159 						(int)l_state.total_num_drv/2+i);
160 					} else {
161 						(void) fprintf(stdout,
162 						MSGSTR(3503, "%s,r%d\n"),
163 								box_name, i);
164 					}
165 				}
166 			}
167 			ml = ml->next;
168 		}
169 
170 		}
171 	}
172 	g_free_wwn_list(&wwn_list);
173 	return (0);
174 }
175 
176 
177 
178 int
179 sysdump(int verbose)
180 {
181 int		err;
182 
183 Box_list	*b_list = NULL;
184 Box_list	*o_list = NULL;
185 Box_list	*c_list = NULL;
186 int		multi_print_flag;
187 
188 	if (err = l_get_box_list(&b_list, verbose)) {
189 		return (err);
190 	}
191 	if (b_list == NULL) {
192 		(void) fprintf(stdout,
193 			MSGSTR(93, "No %s enclosures found "
194 			"in /dev/es\n"), ENCLOSURE_PROD_NAME);
195 	} else {
196 		o_list = b_list;
197 		while (b_list != NULL) {
198 			/* Don't re-print multiple paths */
199 			c_list = o_list;
200 			multi_print_flag = 0;
201 			while (c_list != b_list) {
202 				if (strcmp(c_list->b_node_wwn_s,
203 					b_list->b_node_wwn_s) == 0) {
204 					multi_print_flag = 1;
205 					break;
206 				}
207 				c_list = c_list->box_next;
208 			}
209 			if (multi_print_flag) {
210 				b_list = b_list->box_next;
211 				continue;
212 			}
213 			/* Found enclosure */
214 
215 			(void) fprintf(stdout,
216 			MSGSTR(3504, "Enclosure name:%s   Node WWN:%s\n"),
217 			b_list->b_name, b_list->b_node_wwn_s);
218 
219 			(void) fprintf(stdout, MSGSTR(3505,
220 			"%-80.80s %-17.17s %-17.17s %-22.22s %-20.20s \n"),
221 			MSGSTR(3506, "Physical"),
222 			MSGSTR(3507, "Node_WWN"),
223 			MSGSTR(3508, "Port_WWN"),
224 			MSGSTR(3509, "Logical"),
225 			MSGSTR(3510, "Name"));
226 
227 			(void) fprintf(stdout, MSGSTR(3511,
228 			"%-80.80s %-17.17s %-17.17s %-22.22s %-20.20s\n"),
229 			b_list->b_physical_path,
230 			b_list->b_node_wwn_s,
231 			b_list->b_port_wwn_s,
232 			b_list->logical_path,
233 			b_list->b_name);
234 
235 			c_list = o_list;
236 			while (c_list != NULL) {
237 				if ((c_list != b_list) &&
238 				(strcmp(c_list->b_node_wwn_s,
239 					b_list->b_node_wwn_s) == 0)) {
240 					(void) fprintf(stdout, MSGSTR(3512,
241 			"%-80.80s %-17.17s %-17.17s %-22.22s %-20.20s\n"),
242 					c_list->b_physical_path,
243 					c_list->b_node_wwn_s,
244 					c_list->b_port_wwn_s,
245 					c_list->logical_path,
246 					c_list->b_name);
247 				}
248 				c_list = c_list->box_next;
249 			}
250 			/*
251 			 * Print the individual disk information for each box.
252 			 */
253 			if (err = print_ssd_in_box(b_list->b_physical_path,
254 				b_list->b_name, verbose)) {
255 				return (err);
256 			}
257 			b_list = b_list->box_next;
258 		}
259 	}
260 	(void) l_free_box_list(&b_list);
261 	return (0);
262 }
263