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 * FCIP mdb module
26*fcf3ce44SJohn Forte */
27*fcf3ce44SJohn Forte
28*fcf3ce44SJohn Forte
29*fcf3ce44SJohn Forte #include <sys/mdb_modapi.h>
30*fcf3ce44SJohn Forte #include <sys/mutex.h>
31*fcf3ce44SJohn Forte #include <sys/modctl.h>
32*fcf3ce44SJohn Forte #include <sys/ethernet.h>
33*fcf3ce44SJohn Forte #include <sys/fibre-channel/fc.h>
34*fcf3ce44SJohn Forte #include <sys/fibre-channel/impl/fc_ulpif.h>
35*fcf3ce44SJohn Forte #include <sys/fibre-channel/impl/fctl_private.h>
36*fcf3ce44SJohn Forte #include <sys/fibre-channel/ulp/fcip.h>
37*fcf3ce44SJohn Forte
38*fcf3ce44SJohn Forte /*
39*fcf3ce44SJohn Forte * Leadville fcip walker/dcmd code
40*fcf3ce44SJohn Forte */
41*fcf3ce44SJohn Forte
42*fcf3ce44SJohn Forte static int
fcip_walk_i(mdb_walk_state_t * wsp)43*fcf3ce44SJohn Forte fcip_walk_i(mdb_walk_state_t *wsp)
44*fcf3ce44SJohn Forte {
45*fcf3ce44SJohn Forte if (wsp->walk_addr == NULL &&
46*fcf3ce44SJohn Forte mdb_readvar(&wsp->walk_addr, "fcip_port_head") == -1) {
47*fcf3ce44SJohn Forte mdb_warn("failed to read 'fcip_port_head'");
48*fcf3ce44SJohn Forte return (WALK_ERR);
49*fcf3ce44SJohn Forte }
50*fcf3ce44SJohn Forte
51*fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (fcip_port_info_t), UM_SLEEP);
52*fcf3ce44SJohn Forte return (WALK_NEXT);
53*fcf3ce44SJohn Forte }
54*fcf3ce44SJohn Forte
55*fcf3ce44SJohn Forte static int
fcip_walk_s(mdb_walk_state_t * wsp)56*fcf3ce44SJohn Forte fcip_walk_s(mdb_walk_state_t *wsp)
57*fcf3ce44SJohn Forte {
58*fcf3ce44SJohn Forte int status;
59*fcf3ce44SJohn Forte
60*fcf3ce44SJohn Forte if (wsp->walk_addr == NULL)
61*fcf3ce44SJohn Forte return (WALK_DONE);
62*fcf3ce44SJohn Forte
63*fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (fcip_port_info_t),
64*fcf3ce44SJohn Forte wsp->walk_addr) == -1) {
65*fcf3ce44SJohn Forte mdb_warn("failed to read fcip_port_info at %p", wsp->walk_addr);
66*fcf3ce44SJohn Forte return (WALK_DONE);
67*fcf3ce44SJohn Forte }
68*fcf3ce44SJohn Forte
69*fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
70*fcf3ce44SJohn Forte wsp->walk_cbdata);
71*fcf3ce44SJohn Forte
72*fcf3ce44SJohn Forte wsp->walk_addr =
73*fcf3ce44SJohn Forte (uintptr_t)(((fcip_port_info_t *)wsp->walk_data)->fcipp_next);
74*fcf3ce44SJohn Forte
75*fcf3ce44SJohn Forte return (status);
76*fcf3ce44SJohn Forte }
77*fcf3ce44SJohn Forte
78*fcf3ce44SJohn Forte /*
79*fcf3ce44SJohn Forte * The walker's fini function is invoked at the end of each walk. Since we
80*fcf3ce44SJohn Forte * dynamically allocated a fc_fca_port_t in port_walk_i, we must free it now.
81*fcf3ce44SJohn Forte */
82*fcf3ce44SJohn Forte static void
fcip_walk_f(mdb_walk_state_t * wsp)83*fcf3ce44SJohn Forte fcip_walk_f(mdb_walk_state_t *wsp)
84*fcf3ce44SJohn Forte {
85*fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (fc_fca_port_t));
86*fcf3ce44SJohn Forte }
87*fcf3ce44SJohn Forte
88*fcf3ce44SJohn Forte
89*fcf3ce44SJohn Forte static int
fcip(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)90*fcf3ce44SJohn Forte fcip(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
91*fcf3ce44SJohn Forte {
92*fcf3ce44SJohn Forte fcip_port_info_t pinfo;
93*fcf3ce44SJohn Forte
94*fcf3ce44SJohn Forte if (argc != 0) {
95*fcf3ce44SJohn Forte return (DCMD_USAGE);
96*fcf3ce44SJohn Forte }
97*fcf3ce44SJohn Forte
98*fcf3ce44SJohn Forte if (!(flags & DCMD_ADDRSPEC)) {
99*fcf3ce44SJohn Forte if (mdb_walk_dcmd("fcip", "fcip",
100*fcf3ce44SJohn Forte argc, argv) == -1) {
101*fcf3ce44SJohn Forte mdb_warn("failed to walk 'fcip_port_head'");
102*fcf3ce44SJohn Forte return (DCMD_ERR);
103*fcf3ce44SJohn Forte }
104*fcf3ce44SJohn Forte return (DCMD_OK);
105*fcf3ce44SJohn Forte }
106*fcf3ce44SJohn Forte
107*fcf3ce44SJohn Forte if (DCMD_HDRSPEC(flags))
108*fcf3ce44SJohn Forte mdb_printf("%12s %12s %12s %16s %16s\n",
109*fcf3ce44SJohn Forte "FCIP Struct", "Handle", "DIP", "Port WWN", "Node WWN");
110*fcf3ce44SJohn Forte
111*fcf3ce44SJohn Forte /*
112*fcf3ce44SJohn Forte * For each port, we just need to read the fc_fca_port_t struct, read
113*fcf3ce44SJohn Forte * the port_handle
114*fcf3ce44SJohn Forte */
115*fcf3ce44SJohn Forte if (mdb_vread(&pinfo, sizeof (fcip_port_info_t), addr) ==
116*fcf3ce44SJohn Forte sizeof (fcip_port_info_t)) {
117*fcf3ce44SJohn Forte mdb_printf("%12p %12p %12p %02x%02x%02x%02x%02x%02x%02x%02x "
118*fcf3ce44SJohn Forte "%02x%02x%02x%02x%02x%02x%02x%02x\n",
119*fcf3ce44SJohn Forte pinfo.fcipp_fcip, pinfo.fcipp_handle, pinfo.fcipp_dip,
120*fcf3ce44SJohn Forte pinfo.fcipp_pwwn.raw_wwn[0], pinfo.fcipp_pwwn.raw_wwn[1],
121*fcf3ce44SJohn Forte pinfo.fcipp_pwwn.raw_wwn[2], pinfo.fcipp_pwwn.raw_wwn[3],
122*fcf3ce44SJohn Forte pinfo.fcipp_pwwn.raw_wwn[4], pinfo.fcipp_pwwn.raw_wwn[5],
123*fcf3ce44SJohn Forte pinfo.fcipp_pwwn.raw_wwn[6], pinfo.fcipp_pwwn.raw_wwn[7],
124*fcf3ce44SJohn Forte pinfo.fcipp_nwwn.raw_wwn[0], pinfo.fcipp_nwwn.raw_wwn[1],
125*fcf3ce44SJohn Forte pinfo.fcipp_nwwn.raw_wwn[2], pinfo.fcipp_nwwn.raw_wwn[3],
126*fcf3ce44SJohn Forte pinfo.fcipp_nwwn.raw_wwn[4], pinfo.fcipp_nwwn.raw_wwn[5],
127*fcf3ce44SJohn Forte pinfo.fcipp_nwwn.raw_wwn[6], pinfo.fcipp_nwwn.raw_wwn[7]);
128*fcf3ce44SJohn Forte
129*fcf3ce44SJohn Forte } else
130*fcf3ce44SJohn Forte mdb_warn("failed to read port info at %p", addr);
131*fcf3ce44SJohn Forte
132*fcf3ce44SJohn Forte return (DCMD_OK);
133*fcf3ce44SJohn Forte }
134*fcf3ce44SJohn Forte
135*fcf3ce44SJohn Forte
136*fcf3ce44SJohn Forte /*
137*fcf3ce44SJohn Forte * MDB module linkage information:
138*fcf3ce44SJohn Forte *
139*fcf3ce44SJohn Forte * We declare a list of structures describing our dcmds, a list of structures
140*fcf3ce44SJohn Forte * describing our walkers, and a function named _mdb_init to return a pointer
141*fcf3ce44SJohn Forte * to our module information.
142*fcf3ce44SJohn Forte */
143*fcf3ce44SJohn Forte
144*fcf3ce44SJohn Forte static const mdb_dcmd_t dcmds[] = {
145*fcf3ce44SJohn Forte { "fcip", NULL, "Leadville fcip instances", fcip },
146*fcf3ce44SJohn Forte { NULL }
147*fcf3ce44SJohn Forte };
148*fcf3ce44SJohn Forte
149*fcf3ce44SJohn Forte static const mdb_walker_t walkers[] = {
150*fcf3ce44SJohn Forte { "fcip", "walk list of Leadville fcip instances",
151*fcf3ce44SJohn Forte fcip_walk_i, fcip_walk_s, fcip_walk_f },
152*fcf3ce44SJohn Forte { NULL }
153*fcf3ce44SJohn Forte };
154*fcf3ce44SJohn Forte
155*fcf3ce44SJohn Forte static const mdb_modinfo_t modinfo = {
156*fcf3ce44SJohn Forte MDB_API_VERSION, dcmds, walkers
157*fcf3ce44SJohn Forte };
158*fcf3ce44SJohn Forte
159*fcf3ce44SJohn Forte const mdb_modinfo_t *
_mdb_init(void)160*fcf3ce44SJohn Forte _mdb_init(void)
161*fcf3ce44SJohn Forte {
162*fcf3ce44SJohn Forte return (&modinfo);
163*fcf3ce44SJohn Forte }
164