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