xref: /onnv-gate/usr/src/cmd/mdb/common/modules/fcip/fcip.c (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM  * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM  *
4*7836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM  *
8*7836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM  * and limitations under the License.
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM  *
19*7836SJohn.Forte@Sun.COM  * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM  */
21*7836SJohn.Forte@Sun.COM /*
22*7836SJohn.Forte@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7836SJohn.Forte@Sun.COM  * Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM  *
25*7836SJohn.Forte@Sun.COM  * FCIP mdb module
26*7836SJohn.Forte@Sun.COM  */
27*7836SJohn.Forte@Sun.COM 
28*7836SJohn.Forte@Sun.COM 
29*7836SJohn.Forte@Sun.COM #include <sys/mdb_modapi.h>
30*7836SJohn.Forte@Sun.COM #include <sys/mutex.h>
31*7836SJohn.Forte@Sun.COM #include <sys/modctl.h>
32*7836SJohn.Forte@Sun.COM #include <sys/ethernet.h>
33*7836SJohn.Forte@Sun.COM #include <sys/fibre-channel/fc.h>
34*7836SJohn.Forte@Sun.COM #include <sys/fibre-channel/impl/fc_ulpif.h>
35*7836SJohn.Forte@Sun.COM #include <sys/fibre-channel/impl/fctl_private.h>
36*7836SJohn.Forte@Sun.COM #include <sys/fibre-channel/ulp/fcip.h>
37*7836SJohn.Forte@Sun.COM 
38*7836SJohn.Forte@Sun.COM /*
39*7836SJohn.Forte@Sun.COM  * Leadville fcip walker/dcmd code
40*7836SJohn.Forte@Sun.COM  */
41*7836SJohn.Forte@Sun.COM 
42*7836SJohn.Forte@Sun.COM static int
fcip_walk_i(mdb_walk_state_t * wsp)43*7836SJohn.Forte@Sun.COM fcip_walk_i(mdb_walk_state_t *wsp)
44*7836SJohn.Forte@Sun.COM {
45*7836SJohn.Forte@Sun.COM 	if (wsp->walk_addr == NULL &&
46*7836SJohn.Forte@Sun.COM 	    mdb_readvar(&wsp->walk_addr, "fcip_port_head") == -1) {
47*7836SJohn.Forte@Sun.COM 		mdb_warn("failed to read 'fcip_port_head'");
48*7836SJohn.Forte@Sun.COM 		return (WALK_ERR);
49*7836SJohn.Forte@Sun.COM 	}
50*7836SJohn.Forte@Sun.COM 
51*7836SJohn.Forte@Sun.COM 	wsp->walk_data = mdb_alloc(sizeof (fcip_port_info_t), UM_SLEEP);
52*7836SJohn.Forte@Sun.COM 	return (WALK_NEXT);
53*7836SJohn.Forte@Sun.COM }
54*7836SJohn.Forte@Sun.COM 
55*7836SJohn.Forte@Sun.COM static int
fcip_walk_s(mdb_walk_state_t * wsp)56*7836SJohn.Forte@Sun.COM fcip_walk_s(mdb_walk_state_t *wsp)
57*7836SJohn.Forte@Sun.COM {
58*7836SJohn.Forte@Sun.COM 	int status;
59*7836SJohn.Forte@Sun.COM 
60*7836SJohn.Forte@Sun.COM 	if (wsp->walk_addr == NULL)
61*7836SJohn.Forte@Sun.COM 		return (WALK_DONE);
62*7836SJohn.Forte@Sun.COM 
63*7836SJohn.Forte@Sun.COM 	if (mdb_vread(wsp->walk_data, sizeof (fcip_port_info_t),
64*7836SJohn.Forte@Sun.COM 	    wsp->walk_addr) == -1) {
65*7836SJohn.Forte@Sun.COM 		mdb_warn("failed to read fcip_port_info at %p", wsp->walk_addr);
66*7836SJohn.Forte@Sun.COM 		return (WALK_DONE);
67*7836SJohn.Forte@Sun.COM 	}
68*7836SJohn.Forte@Sun.COM 
69*7836SJohn.Forte@Sun.COM 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
70*7836SJohn.Forte@Sun.COM 	    wsp->walk_cbdata);
71*7836SJohn.Forte@Sun.COM 
72*7836SJohn.Forte@Sun.COM 	wsp->walk_addr =
73*7836SJohn.Forte@Sun.COM 	    (uintptr_t)(((fcip_port_info_t *)wsp->walk_data)->fcipp_next);
74*7836SJohn.Forte@Sun.COM 
75*7836SJohn.Forte@Sun.COM 	return (status);
76*7836SJohn.Forte@Sun.COM }
77*7836SJohn.Forte@Sun.COM 
78*7836SJohn.Forte@Sun.COM /*
79*7836SJohn.Forte@Sun.COM  * The walker's fini function is invoked at the end of each walk.  Since we
80*7836SJohn.Forte@Sun.COM  * dynamically allocated a fc_fca_port_t in port_walk_i, we must free it now.
81*7836SJohn.Forte@Sun.COM  */
82*7836SJohn.Forte@Sun.COM static void
fcip_walk_f(mdb_walk_state_t * wsp)83*7836SJohn.Forte@Sun.COM fcip_walk_f(mdb_walk_state_t *wsp)
84*7836SJohn.Forte@Sun.COM {
85*7836SJohn.Forte@Sun.COM 	mdb_free(wsp->walk_data, sizeof (fc_fca_port_t));
86*7836SJohn.Forte@Sun.COM }
87*7836SJohn.Forte@Sun.COM 
88*7836SJohn.Forte@Sun.COM 
89*7836SJohn.Forte@Sun.COM static int
fcip(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)90*7836SJohn.Forte@Sun.COM fcip(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
91*7836SJohn.Forte@Sun.COM {
92*7836SJohn.Forte@Sun.COM 	fcip_port_info_t	pinfo;
93*7836SJohn.Forte@Sun.COM 
94*7836SJohn.Forte@Sun.COM 	if (argc != 0) {
95*7836SJohn.Forte@Sun.COM 		return (DCMD_USAGE);
96*7836SJohn.Forte@Sun.COM 	}
97*7836SJohn.Forte@Sun.COM 
98*7836SJohn.Forte@Sun.COM 	if (!(flags & DCMD_ADDRSPEC)) {
99*7836SJohn.Forte@Sun.COM 		if (mdb_walk_dcmd("fcip", "fcip",
100*7836SJohn.Forte@Sun.COM 		    argc, argv) == -1) {
101*7836SJohn.Forte@Sun.COM 			mdb_warn("failed to walk 'fcip_port_head'");
102*7836SJohn.Forte@Sun.COM 			return (DCMD_ERR);
103*7836SJohn.Forte@Sun.COM 		}
104*7836SJohn.Forte@Sun.COM 		return (DCMD_OK);
105*7836SJohn.Forte@Sun.COM 	}
106*7836SJohn.Forte@Sun.COM 
107*7836SJohn.Forte@Sun.COM 	if (DCMD_HDRSPEC(flags))
108*7836SJohn.Forte@Sun.COM 		mdb_printf("%12s %12s %12s %16s %16s\n",
109*7836SJohn.Forte@Sun.COM 		    "FCIP Struct", "Handle", "DIP", "Port WWN", "Node WWN");
110*7836SJohn.Forte@Sun.COM 
111*7836SJohn.Forte@Sun.COM 	/*
112*7836SJohn.Forte@Sun.COM 	 * For each port, we just need to read the fc_fca_port_t struct, read
113*7836SJohn.Forte@Sun.COM 	 * the port_handle
114*7836SJohn.Forte@Sun.COM 	 */
115*7836SJohn.Forte@Sun.COM 	if (mdb_vread(&pinfo, sizeof (fcip_port_info_t), addr) ==
116*7836SJohn.Forte@Sun.COM 	    sizeof (fcip_port_info_t)) {
117*7836SJohn.Forte@Sun.COM 		mdb_printf("%12p %12p %12p %02x%02x%02x%02x%02x%02x%02x%02x "
118*7836SJohn.Forte@Sun.COM 		    "%02x%02x%02x%02x%02x%02x%02x%02x\n",
119*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_fcip, pinfo.fcipp_handle, pinfo.fcipp_dip,
120*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_pwwn.raw_wwn[0], pinfo.fcipp_pwwn.raw_wwn[1],
121*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_pwwn.raw_wwn[2], pinfo.fcipp_pwwn.raw_wwn[3],
122*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_pwwn.raw_wwn[4], pinfo.fcipp_pwwn.raw_wwn[5],
123*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_pwwn.raw_wwn[6], pinfo.fcipp_pwwn.raw_wwn[7],
124*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_nwwn.raw_wwn[0], pinfo.fcipp_nwwn.raw_wwn[1],
125*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_nwwn.raw_wwn[2], pinfo.fcipp_nwwn.raw_wwn[3],
126*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_nwwn.raw_wwn[4], pinfo.fcipp_nwwn.raw_wwn[5],
127*7836SJohn.Forte@Sun.COM 		    pinfo.fcipp_nwwn.raw_wwn[6], pinfo.fcipp_nwwn.raw_wwn[7]);
128*7836SJohn.Forte@Sun.COM 
129*7836SJohn.Forte@Sun.COM 	} else
130*7836SJohn.Forte@Sun.COM 		mdb_warn("failed to read port info at %p", addr);
131*7836SJohn.Forte@Sun.COM 
132*7836SJohn.Forte@Sun.COM 	return (DCMD_OK);
133*7836SJohn.Forte@Sun.COM }
134*7836SJohn.Forte@Sun.COM 
135*7836SJohn.Forte@Sun.COM 
136*7836SJohn.Forte@Sun.COM /*
137*7836SJohn.Forte@Sun.COM  * MDB module linkage information:
138*7836SJohn.Forte@Sun.COM  *
139*7836SJohn.Forte@Sun.COM  * We declare a list of structures describing our dcmds, a list of structures
140*7836SJohn.Forte@Sun.COM  * describing our walkers, and a function named _mdb_init to return a pointer
141*7836SJohn.Forte@Sun.COM  * to our module information.
142*7836SJohn.Forte@Sun.COM  */
143*7836SJohn.Forte@Sun.COM 
144*7836SJohn.Forte@Sun.COM static const mdb_dcmd_t dcmds[] = {
145*7836SJohn.Forte@Sun.COM 	{ "fcip", NULL, "Leadville fcip instances", fcip },
146*7836SJohn.Forte@Sun.COM 	{ NULL }
147*7836SJohn.Forte@Sun.COM };
148*7836SJohn.Forte@Sun.COM 
149*7836SJohn.Forte@Sun.COM static const mdb_walker_t walkers[] = {
150*7836SJohn.Forte@Sun.COM 	{ "fcip", "walk list of Leadville fcip instances",
151*7836SJohn.Forte@Sun.COM 		fcip_walk_i, fcip_walk_s, fcip_walk_f },
152*7836SJohn.Forte@Sun.COM 	{ NULL }
153*7836SJohn.Forte@Sun.COM };
154*7836SJohn.Forte@Sun.COM 
155*7836SJohn.Forte@Sun.COM static const mdb_modinfo_t modinfo = {
156*7836SJohn.Forte@Sun.COM 	MDB_API_VERSION, dcmds, walkers
157*7836SJohn.Forte@Sun.COM };
158*7836SJohn.Forte@Sun.COM 
159*7836SJohn.Forte@Sun.COM const mdb_modinfo_t *
_mdb_init(void)160*7836SJohn.Forte@Sun.COM _mdb_init(void)
161*7836SJohn.Forte@Sun.COM {
162*7836SJohn.Forte@Sun.COM 	return (&modinfo);
163*7836SJohn.Forte@Sun.COM }
164