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