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 /*
22585995d5SYu Renia Miao * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23fcf3ce44SJohn Forte * Use is subject to license terms.
24fcf3ce44SJohn Forte */
25fcf3ce44SJohn Forte
26d75f3745SJohn Levon /*
27*3b442230SJordan Paige Hendricks * Copyright 2019 Joyent, Inc.
28d75f3745SJohn Levon */
29fcf3ce44SJohn Forte
30fcf3ce44SJohn Forte #include <sys/mdb_modapi.h>
31fcf3ce44SJohn Forte #include <sys/mutex.h>
32fcf3ce44SJohn Forte #include <sys/modctl.h>
33fcf3ce44SJohn Forte #include <time.h>
34fcf3ce44SJohn Forte #include <sys/fibre-channel/fc.h>
35fcf3ce44SJohn Forte #include <sys/fibre-channel/impl/fctl_private.h>
36fcf3ce44SJohn Forte #include <sys/fibre-channel/impl/fc_ulpif.h>
37fcf3ce44SJohn Forte #include <sys/fibre-channel/impl/fc_portif.h>
38fcf3ce44SJohn Forte #include <sys/fibre-channel/impl/fc_fcaif.h>
39fcf3ce44SJohn Forte
40fcf3ce44SJohn Forte
41fcf3ce44SJohn Forte /*
42fcf3ce44SJohn Forte * If we #include <string.h> then other definitions fail. This is
43fcf3ce44SJohn Forte * the easiest way of getting access to the function
44fcf3ce44SJohn Forte */
45fcf3ce44SJohn Forte extern char *strtok(char *string, const char *sepset);
46fcf3ce44SJohn Forte
47fcf3ce44SJohn Forte /* we need 26 bytes for the cftime() call */
48fcf3ce44SJohn Forte #define TIMESTAMPSIZE 26 * sizeof (char)
49fcf3ce44SJohn Forte
50fcf3ce44SJohn Forte /* for backward compatibility */
51fcf3ce44SJohn Forte typedef struct fc_trace_dmsgv1 {
52fcf3ce44SJohn Forte int id_size;
53fcf3ce44SJohn Forte int id_flag;
54fcf3ce44SJohn Forte time_t id_time;
55fcf3ce44SJohn Forte caddr_t id_buf;
56fcf3ce44SJohn Forte struct fc_trace_dmsgv1 *id_next;
57fcf3ce44SJohn Forte } fc_trace_dmsgv1_t;
58fcf3ce44SJohn Forte
59fcf3ce44SJohn Forte static struct pwwn_hash *fp_pwwn_table;
60fcf3ce44SJohn Forte static struct d_id_hash *fp_did_table;
61fcf3ce44SJohn Forte static uint32_t pd_hash_index;
62fcf3ce44SJohn Forte struct fc_local_port port;
63fcf3ce44SJohn Forte
64fcf3ce44SJohn Forte /*
65fcf3ce44SJohn Forte * Leadville port walker/dcmd code
66fcf3ce44SJohn Forte */
67fcf3ce44SJohn Forte
68fcf3ce44SJohn Forte /*
69fcf3ce44SJohn Forte * Initialize the fc_fca_port_t walker by either using the given starting
70fcf3ce44SJohn Forte * address, or reading the value of the kernel's fctl_fca_portlist pointer.
71fcf3ce44SJohn Forte * We also allocate a fc_fca_port_t for storage, and save this using the
72fcf3ce44SJohn Forte * walk_data pointer.
73fcf3ce44SJohn Forte */
74fcf3ce44SJohn Forte static int
port_walk_i(mdb_walk_state_t * wsp)75fcf3ce44SJohn Forte port_walk_i(mdb_walk_state_t *wsp)
76fcf3ce44SJohn Forte {
77892ad162SToomas Soome if (wsp->walk_addr == 0 &&
78fcf3ce44SJohn Forte mdb_readvar(&wsp->walk_addr, "fctl_fca_portlist") == -1) {
79fcf3ce44SJohn Forte mdb_warn("failed to read 'fctl_fca_portlist'");
80fcf3ce44SJohn Forte return (WALK_ERR);
81fcf3ce44SJohn Forte }
82fcf3ce44SJohn Forte
83fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (fc_fca_port_t), UM_SLEEP);
84fcf3ce44SJohn Forte return (WALK_NEXT);
85fcf3ce44SJohn Forte }
86fcf3ce44SJohn Forte
87fcf3ce44SJohn Forte /*
88fcf3ce44SJohn Forte * At each step, read a fc_fca_port_t into our private storage, and then invoke
89fcf3ce44SJohn Forte * the callback function. We terminate when we reach a NULL p_next pointer.
90fcf3ce44SJohn Forte */
91fcf3ce44SJohn Forte static int
port_walk_s(mdb_walk_state_t * wsp)92fcf3ce44SJohn Forte port_walk_s(mdb_walk_state_t *wsp)
93fcf3ce44SJohn Forte {
94fcf3ce44SJohn Forte int status;
95fcf3ce44SJohn Forte
96892ad162SToomas Soome if (wsp->walk_addr == 0)
97fcf3ce44SJohn Forte return (WALK_DONE);
98fcf3ce44SJohn Forte
99fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (fc_fca_port_t), wsp->walk_addr)
100fcf3ce44SJohn Forte == -1) {
101fcf3ce44SJohn Forte mdb_warn("failed to read fc_fca_port_t at %p", wsp->walk_addr);
102fcf3ce44SJohn Forte return (WALK_DONE);
103fcf3ce44SJohn Forte }
104fcf3ce44SJohn Forte
105fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
106fcf3ce44SJohn Forte wsp->walk_cbdata);
107fcf3ce44SJohn Forte
108fcf3ce44SJohn Forte wsp->walk_addr =
109fcf3ce44SJohn Forte (uintptr_t)(((fc_fca_port_t *)wsp->walk_data)->port_next);
110fcf3ce44SJohn Forte
111fcf3ce44SJohn Forte return (status);
112fcf3ce44SJohn Forte }
113fcf3ce44SJohn Forte
114fcf3ce44SJohn Forte /*
115fcf3ce44SJohn Forte * The walker's fini function is invoked at the end of each walk. Since we
116fcf3ce44SJohn Forte * dynamically allocated a fc_fca_port_t in port_walk_i, we must free it now.
117fcf3ce44SJohn Forte */
118fcf3ce44SJohn Forte static void
port_walk_f(mdb_walk_state_t * wsp)119fcf3ce44SJohn Forte port_walk_f(mdb_walk_state_t *wsp)
120fcf3ce44SJohn Forte {
121fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (fc_fca_port_t));
122fcf3ce44SJohn Forte }
123fcf3ce44SJohn Forte
124fcf3ce44SJohn Forte
125fcf3ce44SJohn Forte static int
ports(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)126fcf3ce44SJohn Forte ports(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
127fcf3ce44SJohn Forte {
128fcf3ce44SJohn Forte fc_fca_port_t portlist;
129fcf3ce44SJohn Forte fc_local_port_t port;
130fcf3ce44SJohn Forte int longlist = FALSE;
131fcf3ce44SJohn Forte
132fcf3ce44SJohn Forte if (argc > 1) {
133fcf3ce44SJohn Forte return (DCMD_USAGE);
134fcf3ce44SJohn Forte }
135fcf3ce44SJohn Forte
136fcf3ce44SJohn Forte if (mdb_getopts(argc, argv,
137*3b442230SJordan Paige Hendricks 'l', MDB_OPT_SETBITS, TRUE, &longlist, NULL) != argc) {
138fcf3ce44SJohn Forte return (DCMD_USAGE);
139fcf3ce44SJohn Forte }
140fcf3ce44SJohn Forte
141fcf3ce44SJohn Forte
142fcf3ce44SJohn Forte if (!(flags & DCMD_ADDRSPEC)) {
143fcf3ce44SJohn Forte if (longlist == 0) {
144fcf3ce44SJohn Forte if (mdb_walk_dcmd("ports", "ports",
145fcf3ce44SJohn Forte argc, argv) == -1) {
146fcf3ce44SJohn Forte mdb_warn("failed to walk 'fctl_fca_portlist'");
147fcf3ce44SJohn Forte return (DCMD_ERR);
148fcf3ce44SJohn Forte }
149fcf3ce44SJohn Forte } else {
150fcf3ce44SJohn Forte if (mdb_walk_dcmd("ports", "fcport",
151fcf3ce44SJohn Forte argc, argv) == -1) {
152fcf3ce44SJohn Forte mdb_warn("failed to walk 'fctl_fca_portlist'");
153fcf3ce44SJohn Forte return (DCMD_ERR);
154fcf3ce44SJohn Forte }
155fcf3ce44SJohn Forte }
156fcf3ce44SJohn Forte
157fcf3ce44SJohn Forte return (DCMD_OK);
158fcf3ce44SJohn Forte }
159fcf3ce44SJohn Forte
160fcf3ce44SJohn Forte /*
161fcf3ce44SJohn Forte * If this is the first invocation of the command, print a nice
162fcf3ce44SJohn Forte * header line for the output that will follow.
163fcf3ce44SJohn Forte */
164fcf3ce44SJohn Forte if (DCMD_HDRSPEC(flags))
165fcf3ce44SJohn Forte mdb_printf("%16s %-2s %4s %-4s%16s %16s %16s\n",
166fcf3ce44SJohn Forte "Port", "I#", "State", "Soft", "FCA Handle",
167fcf3ce44SJohn Forte "Port DIP", "FCA Port DIP");
168fcf3ce44SJohn Forte
169fcf3ce44SJohn Forte /*
170fcf3ce44SJohn Forte * For each port, we just need to read the fc_fca_port_t struct, read
171fcf3ce44SJohn Forte * the port_handle
172fcf3ce44SJohn Forte */
173fcf3ce44SJohn Forte if (mdb_vread(&portlist, sizeof (fc_fca_port_t), addr) ==
174fcf3ce44SJohn Forte sizeof (fc_fca_port_t)) {
175fcf3ce44SJohn Forte /*
176fcf3ce44SJohn Forte * Now read that port in
177fcf3ce44SJohn Forte */
178fcf3ce44SJohn Forte
179fcf3ce44SJohn Forte if (mdb_vread(&port, sizeof (fc_local_port_t), (uintptr_t)
180fcf3ce44SJohn Forte portlist.port_handle) == sizeof (fc_local_port_t)) {
181fcf3ce44SJohn Forte mdb_printf("%16p %2d %4x %4x %16p %16p %16p\n",
182fcf3ce44SJohn Forte portlist.port_handle, port.fp_instance,
183fcf3ce44SJohn Forte port.fp_state, port.fp_soft_state,
184fcf3ce44SJohn Forte port.fp_fca_handle, port.fp_port_dip,
185fcf3ce44SJohn Forte port.fp_fca_dip);
186fcf3ce44SJohn Forte } else
187fcf3ce44SJohn Forte mdb_warn("failed to read port at %p",
188fcf3ce44SJohn Forte portlist.port_handle);
189fcf3ce44SJohn Forte
190fcf3ce44SJohn Forte } else
191fcf3ce44SJohn Forte mdb_warn("failed to read port info at %p", addr);
192fcf3ce44SJohn Forte
193fcf3ce44SJohn Forte return (DCMD_OK);
194fcf3ce44SJohn Forte }
195fcf3ce44SJohn Forte
196fcf3ce44SJohn Forte
197fcf3ce44SJohn Forte /*
198fcf3ce44SJohn Forte * Leadville ULP walker/dcmd code
199fcf3ce44SJohn Forte */
200fcf3ce44SJohn Forte
201fcf3ce44SJohn Forte static int
ulp_walk_i(mdb_walk_state_t * wsp)202fcf3ce44SJohn Forte ulp_walk_i(mdb_walk_state_t *wsp)
203fcf3ce44SJohn Forte {
204892ad162SToomas Soome if (wsp->walk_addr == 0 &&
205fcf3ce44SJohn Forte mdb_readvar(&wsp->walk_addr, "fctl_ulp_list") == -1) {
206fcf3ce44SJohn Forte mdb_warn("failed to read 'fctl_ulp_list'");
207fcf3ce44SJohn Forte return (WALK_ERR);
208fcf3ce44SJohn Forte }
209fcf3ce44SJohn Forte
210fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (fc_ulp_list_t), UM_SLEEP);
211fcf3ce44SJohn Forte return (WALK_NEXT);
212fcf3ce44SJohn Forte }
213fcf3ce44SJohn Forte
214fcf3ce44SJohn Forte
215fcf3ce44SJohn Forte
216fcf3ce44SJohn Forte static int
ulp_walk_s(mdb_walk_state_t * wsp)217fcf3ce44SJohn Forte ulp_walk_s(mdb_walk_state_t *wsp)
218fcf3ce44SJohn Forte {
219fcf3ce44SJohn Forte int status;
220fcf3ce44SJohn Forte
221892ad162SToomas Soome if (wsp->walk_addr == 0)
222fcf3ce44SJohn Forte return (WALK_DONE);
223fcf3ce44SJohn Forte
224fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (fc_ulp_list_t), wsp->walk_addr)
225fcf3ce44SJohn Forte == -1) {
226fcf3ce44SJohn Forte mdb_warn("failed to read fctl_ulp_list %p", wsp->walk_addr);
227fcf3ce44SJohn Forte return (WALK_DONE);
228fcf3ce44SJohn Forte }
229fcf3ce44SJohn Forte
230fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
231fcf3ce44SJohn Forte wsp->walk_cbdata);
232fcf3ce44SJohn Forte
233fcf3ce44SJohn Forte wsp->walk_addr =
234fcf3ce44SJohn Forte (uintptr_t)(((fc_ulp_list_t *)wsp->walk_data)->ulp_next);
235fcf3ce44SJohn Forte
236fcf3ce44SJohn Forte return (status);
237fcf3ce44SJohn Forte }
238fcf3ce44SJohn Forte
239fcf3ce44SJohn Forte
240fcf3ce44SJohn Forte static void
ulp_walk_f(mdb_walk_state_t * wsp)241fcf3ce44SJohn Forte ulp_walk_f(mdb_walk_state_t *wsp)
242fcf3ce44SJohn Forte {
243fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (fc_ulp_list_t));
244fcf3ce44SJohn Forte }
245fcf3ce44SJohn Forte
246fcf3ce44SJohn Forte
247fcf3ce44SJohn Forte static int
ulps(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)248fcf3ce44SJohn Forte ulps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
249fcf3ce44SJohn Forte {
250fcf3ce44SJohn Forte fc_ulp_list_t ulplist;
251fcf3ce44SJohn Forte fc_ulp_modinfo_t ulp;
252fcf3ce44SJohn Forte char ulp_name[30];
253fcf3ce44SJohn Forte
254fcf3ce44SJohn Forte if (argc != 0) {
255fcf3ce44SJohn Forte return (DCMD_USAGE);
256fcf3ce44SJohn Forte }
257fcf3ce44SJohn Forte
258fcf3ce44SJohn Forte /*
259fcf3ce44SJohn Forte * If no fc_ulp_list_t address was specified on the command line, we can
260fcf3ce44SJohn Forte * print out all processes by invoking the walker, using this
261fcf3ce44SJohn Forte * dcmd itself as the callback.
262fcf3ce44SJohn Forte */
263fcf3ce44SJohn Forte if (!(flags & DCMD_ADDRSPEC)) {
264fcf3ce44SJohn Forte if (mdb_walk_dcmd("ulps", "ulps", argc, argv) == -1) {
265fcf3ce44SJohn Forte mdb_warn("failed to walk 'fc_ulp_list_t'");
266fcf3ce44SJohn Forte return (DCMD_ERR);
267fcf3ce44SJohn Forte }
268fcf3ce44SJohn Forte return (DCMD_OK);
269fcf3ce44SJohn Forte }
270fcf3ce44SJohn Forte
271fcf3ce44SJohn Forte /*
272fcf3ce44SJohn Forte * If this is the first invocation of the command, print a nice
273fcf3ce44SJohn Forte * header line for the output that will follow.
274fcf3ce44SJohn Forte */
275fcf3ce44SJohn Forte if (DCMD_HDRSPEC(flags))
276fcf3ce44SJohn Forte mdb_printf("%30s %4s %8s\n", "ULP Name", "Type", "Revision");
277fcf3ce44SJohn Forte
278fcf3ce44SJohn Forte /*
279fcf3ce44SJohn Forte * For each port, we just need to read the fc_fca_port_t struct, read
280fcf3ce44SJohn Forte * the port_handle
281fcf3ce44SJohn Forte */
282fcf3ce44SJohn Forte if (mdb_vread(&ulplist, sizeof (fc_ulp_list_t), addr) ==
283fcf3ce44SJohn Forte sizeof (fc_ulp_list_t)) {
284fcf3ce44SJohn Forte /*
285fcf3ce44SJohn Forte * Now read that port in
286fcf3ce44SJohn Forte */
287fcf3ce44SJohn Forte
288fcf3ce44SJohn Forte if (mdb_vread(&ulp, sizeof (fc_ulp_modinfo_t),
289fcf3ce44SJohn Forte (uintptr_t)ulplist.ulp_info) == sizeof (fc_ulp_modinfo_t)) {
290fcf3ce44SJohn Forte if (mdb_vread(&ulp_name, 30,
291fcf3ce44SJohn Forte (uintptr_t)ulp.ulp_name) > 0) {
292fcf3ce44SJohn Forte mdb_printf("%30s %4x %8x\n",
293fcf3ce44SJohn Forte ulp_name, ulp.ulp_type, ulp.ulp_rev);
294fcf3ce44SJohn Forte }
295fcf3ce44SJohn Forte } else
296fcf3ce44SJohn Forte mdb_warn("failed to read ulp at %p",
297fcf3ce44SJohn Forte ulplist.ulp_info);
298fcf3ce44SJohn Forte
299fcf3ce44SJohn Forte } else
300fcf3ce44SJohn Forte mdb_warn("failed to read ulplist at %p", addr);
301fcf3ce44SJohn Forte
302fcf3ce44SJohn Forte return (DCMD_OK);
303fcf3ce44SJohn Forte }
304fcf3ce44SJohn Forte
305fcf3ce44SJohn Forte
306fcf3ce44SJohn Forte
307fcf3ce44SJohn Forte /*
308fcf3ce44SJohn Forte * Leadville ULP module walker/dcmd code
309fcf3ce44SJohn Forte */
310fcf3ce44SJohn Forte
311fcf3ce44SJohn Forte static int
ulpmod_walk_i(mdb_walk_state_t * wsp)312fcf3ce44SJohn Forte ulpmod_walk_i(mdb_walk_state_t *wsp)
313fcf3ce44SJohn Forte {
314892ad162SToomas Soome if (wsp->walk_addr == 0 &&
315fcf3ce44SJohn Forte mdb_readvar(&wsp->walk_addr, "fctl_ulp_modules") == -1) {
316fcf3ce44SJohn Forte mdb_warn("failed to read 'fctl_ulp_modules'");
317fcf3ce44SJohn Forte return (WALK_ERR);
318fcf3ce44SJohn Forte }
319fcf3ce44SJohn Forte
320fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (fc_ulp_module_t), UM_SLEEP);
321fcf3ce44SJohn Forte return (WALK_NEXT);
322fcf3ce44SJohn Forte }
323fcf3ce44SJohn Forte
324fcf3ce44SJohn Forte
325fcf3ce44SJohn Forte
326fcf3ce44SJohn Forte static int
ulpmod_walk_s(mdb_walk_state_t * wsp)327fcf3ce44SJohn Forte ulpmod_walk_s(mdb_walk_state_t *wsp)
328fcf3ce44SJohn Forte {
329fcf3ce44SJohn Forte int status;
330fcf3ce44SJohn Forte
331892ad162SToomas Soome if (wsp->walk_addr == 0)
332fcf3ce44SJohn Forte return (WALK_DONE);
333fcf3ce44SJohn Forte
334fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (fc_ulp_module_t), wsp->walk_addr)
335fcf3ce44SJohn Forte == -1) {
336fcf3ce44SJohn Forte mdb_warn("failed to read fctl_ulp_modules %p", wsp->walk_addr);
337fcf3ce44SJohn Forte return (WALK_DONE);
338fcf3ce44SJohn Forte }
339fcf3ce44SJohn Forte
340fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
341fcf3ce44SJohn Forte wsp->walk_cbdata);
342fcf3ce44SJohn Forte
343fcf3ce44SJohn Forte wsp->walk_addr =
344fcf3ce44SJohn Forte (uintptr_t)(((fc_ulp_module_t *)wsp->walk_data)->mod_next);
345fcf3ce44SJohn Forte
346fcf3ce44SJohn Forte return (status);
347fcf3ce44SJohn Forte }
348fcf3ce44SJohn Forte
349fcf3ce44SJohn Forte
350fcf3ce44SJohn Forte static void
ulpmod_walk_f(mdb_walk_state_t * wsp)351fcf3ce44SJohn Forte ulpmod_walk_f(mdb_walk_state_t *wsp)
352fcf3ce44SJohn Forte {
353fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (fc_ulp_module_t));
354fcf3ce44SJohn Forte }
355fcf3ce44SJohn Forte
356fcf3ce44SJohn Forte
357fcf3ce44SJohn Forte static int
ulpmods(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)358fcf3ce44SJohn Forte ulpmods(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
359fcf3ce44SJohn Forte {
360fcf3ce44SJohn Forte fc_ulp_module_t modlist;
361fcf3ce44SJohn Forte fc_ulp_modinfo_t modinfo;
362fcf3ce44SJohn Forte fc_ulp_ports_t ulp_port;
363fcf3ce44SJohn Forte
364fcf3ce44SJohn Forte if (argc != 0) {
365fcf3ce44SJohn Forte return (DCMD_USAGE);
366fcf3ce44SJohn Forte }
367fcf3ce44SJohn Forte
368fcf3ce44SJohn Forte if (!(flags & DCMD_ADDRSPEC)) {
369fcf3ce44SJohn Forte if (mdb_walk_dcmd("ulpmods", "ulpmods", argc, argv)
370fcf3ce44SJohn Forte == -1) {
371fcf3ce44SJohn Forte mdb_warn("failed to walk 'fc_ulp_module_t'");
372fcf3ce44SJohn Forte return (DCMD_ERR);
373fcf3ce44SJohn Forte }
374fcf3ce44SJohn Forte return (DCMD_OK);
375fcf3ce44SJohn Forte }
376fcf3ce44SJohn Forte
377fcf3ce44SJohn Forte /*
378fcf3ce44SJohn Forte * If this is the first invocation of the command, print a nice
379fcf3ce44SJohn Forte * header line for the output that will follow.
380fcf3ce44SJohn Forte */
381fcf3ce44SJohn Forte if (DCMD_HDRSPEC(flags))
382fcf3ce44SJohn Forte mdb_printf("%4s %16s %8s %8s\n",
383fcf3ce44SJohn Forte "Type", "Port Handle", "dstate", "statec");
384fcf3ce44SJohn Forte
385fcf3ce44SJohn Forte /*
386fcf3ce44SJohn Forte * For each port, we just need to read the fc_fca_port_t struct, read
387fcf3ce44SJohn Forte * the port_handle
388fcf3ce44SJohn Forte */
389fcf3ce44SJohn Forte if (mdb_vread(&modlist, sizeof (fc_ulp_module_t), addr) ==
390fcf3ce44SJohn Forte sizeof (fc_ulp_module_t)) {
391fcf3ce44SJohn Forte /*
392fcf3ce44SJohn Forte * Now read that module info in
393fcf3ce44SJohn Forte */
394fcf3ce44SJohn Forte
395fcf3ce44SJohn Forte if (mdb_vread(&modinfo, sizeof (fc_ulp_modinfo_t),
396fcf3ce44SJohn Forte (uintptr_t)modlist.mod_info) == sizeof (fc_ulp_modinfo_t)) {
397fcf3ce44SJohn Forte /* Now read all the ports for this module */
398fcf3ce44SJohn Forte if (mdb_vread(&ulp_port, sizeof (fc_ulp_ports_t),
399fcf3ce44SJohn Forte (uintptr_t)modlist.mod_ports) ==
400fcf3ce44SJohn Forte sizeof (fc_ulp_ports_t)) {
401fcf3ce44SJohn Forte while (ulp_port.port_handle != NULL) {
402fcf3ce44SJohn Forte mdb_printf("%4x %16p %8x %8x\n",
403fcf3ce44SJohn Forte modinfo.ulp_type,
404fcf3ce44SJohn Forte ulp_port.port_handle,
405fcf3ce44SJohn Forte ulp_port.port_dstate,
406fcf3ce44SJohn Forte ulp_port.port_statec);
407fcf3ce44SJohn Forte
408fcf3ce44SJohn Forte if (ulp_port.port_next == NULL)
409fcf3ce44SJohn Forte break;
410fcf3ce44SJohn Forte
411fcf3ce44SJohn Forte mdb_vread(&ulp_port,
412fcf3ce44SJohn Forte sizeof (fc_ulp_ports_t),
413fcf3ce44SJohn Forte (uintptr_t)ulp_port.port_next);
414fcf3ce44SJohn Forte }
415fcf3ce44SJohn Forte }
416fcf3ce44SJohn Forte } else
417fcf3ce44SJohn Forte mdb_warn("failed to read modinfo at %p",
418fcf3ce44SJohn Forte modlist.mod_info);
419fcf3ce44SJohn Forte
420fcf3ce44SJohn Forte } else
421fcf3ce44SJohn Forte mdb_warn("failed to read modlist at %p", addr);
422fcf3ce44SJohn Forte
423fcf3ce44SJohn Forte return (DCMD_OK);
424fcf3ce44SJohn Forte }
425fcf3ce44SJohn Forte
426fcf3ce44SJohn Forte
427fcf3ce44SJohn Forte /*
428fcf3ce44SJohn Forte * Display an fc_local_port_t struct
429fcf3ce44SJohn Forte */
430fcf3ce44SJohn Forte static int
fcport(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)431fcf3ce44SJohn Forte fcport(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
432fcf3ce44SJohn Forte {
433fcf3ce44SJohn Forte fc_fca_port_t portlist;
434fcf3ce44SJohn Forte fc_local_port_t port;
435fcf3ce44SJohn Forte int idx;
436fcf3ce44SJohn Forte int first = 1;
437fcf3ce44SJohn Forte int walking_fc_fca_portlist = 0;
438fcf3ce44SJohn Forte
439fcf3ce44SJohn Forte if (argc != 0) {
440fcf3ce44SJohn Forte int result;
441fcf3ce44SJohn Forte
442fcf3ce44SJohn Forte if (argc != 1)
443fcf3ce44SJohn Forte return (DCMD_USAGE);
444fcf3ce44SJohn Forte
445fcf3ce44SJohn Forte if (argv->a_type != MDB_TYPE_STRING)
446fcf3ce44SJohn Forte return (DCMD_USAGE);
447fcf3ce44SJohn Forte
448fcf3ce44SJohn Forte walking_fc_fca_portlist = 1;
449fcf3ce44SJohn Forte }
450fcf3ce44SJohn Forte
451fcf3ce44SJohn Forte if (!(flags & DCMD_ADDRSPEC)) {
452fcf3ce44SJohn Forte mdb_printf("Sorry, you must provide an address\n");
453fcf3ce44SJohn Forte return (DCMD_ERR);
454fcf3ce44SJohn Forte }
455fcf3ce44SJohn Forte
456fcf3ce44SJohn Forte if (walking_fc_fca_portlist) {
457fcf3ce44SJohn Forte /*
458fcf3ce44SJohn Forte * Must read the fc_fca_portlist to get the fc_local_port addr
459fcf3ce44SJohn Forte */
460fcf3ce44SJohn Forte if (mdb_vread(&portlist, sizeof (fc_fca_port_t), addr) ==
461fcf3ce44SJohn Forte sizeof (fc_fca_port_t)) {
462fcf3ce44SJohn Forte addr = (uintptr_t)portlist.port_handle;
463fcf3ce44SJohn Forte }
464fcf3ce44SJohn Forte }
465fcf3ce44SJohn Forte
466fcf3ce44SJohn Forte mdb_printf("Reading fc_local_port_t at %p:\n", addr);
467fcf3ce44SJohn Forte
468fcf3ce44SJohn Forte /*
469fcf3ce44SJohn Forte * For each port, we just need to read the fc_local_port_t struct
470fcf3ce44SJohn Forte */
471fcf3ce44SJohn Forte
472fcf3ce44SJohn Forte if (mdb_vread(&port, sizeof (fc_local_port_t),
473fcf3ce44SJohn Forte addr) == sizeof (fc_local_port_t)) {
474fcf3ce44SJohn Forte mdb_printf(" fp_mutex : 0x%p\n", port.fp_mutex);
475fcf3ce44SJohn Forte mdb_printf(" fp_state : 0x%-8x\n", port.fp_state);
476fcf3ce44SJohn Forte mdb_printf(" fp_port_id : 0x%-06x\n",
477fcf3ce44SJohn Forte port.fp_port_id.port_id);
478fcf3ce44SJohn Forte mdb_printf(" fp_fca_handle : 0x%p\n", port.fp_fca_handle);
479fcf3ce44SJohn Forte mdb_printf(" fp_fca_tran : 0x%p\n", port.fp_fca_tran);
480fcf3ce44SJohn Forte mdb_printf(" fp_job_head : 0x%p\n", port.fp_job_head);
481fcf3ce44SJohn Forte mdb_printf(" fp_job_tail : 0x%p\n", port.fp_job_tail);
482fcf3ce44SJohn Forte mdb_printf(" fp_wait_head : 0x%p\n", port.fp_wait_head);
483fcf3ce44SJohn Forte mdb_printf(" fp_wait_tail : 0x%p\n", port.fp_wait_tail);
484fcf3ce44SJohn Forte mdb_printf(" fp_topology : %u\n", port.fp_topology);
485fcf3ce44SJohn Forte mdb_printf(" fp_task : %d\n", port.fp_task);
486fcf3ce44SJohn Forte mdb_printf(" fp_last_task : %d\n", port.fp_last_task);
487fcf3ce44SJohn Forte mdb_printf(" fp_soft_state : 0x%-4x\n",
488fcf3ce44SJohn Forte port.fp_soft_state);
489fcf3ce44SJohn Forte mdb_printf(" fp_flag : 0x%-2x\n", port.fp_flag);
490fcf3ce44SJohn Forte mdb_printf(" fp_statec_busy : 0x%-8x\n",
491fcf3ce44SJohn Forte port.fp_statec_busy);
492fcf3ce44SJohn Forte mdb_printf(" fp_port_num : %d\n", port.fp_port_num);
493fcf3ce44SJohn Forte mdb_printf(" fp_instance : %d\n", port.fp_instance);
494fcf3ce44SJohn Forte mdb_printf(" fp_ulp_attach : %d\n", port.fp_ulp_attach);
495fcf3ce44SJohn Forte mdb_printf(" fp_dev_count : %d\n", port.fp_dev_count);
496fcf3ce44SJohn Forte mdb_printf(" fp_total_devices : %d\n", port.fp_total_devices);
497fcf3ce44SJohn Forte mdb_printf(" fp_bind_state : 0x%-8x\n",
498fcf3ce44SJohn Forte port.fp_bind_state);
499fcf3ce44SJohn Forte mdb_printf(" fp_options : 0x%-8x\n", port.fp_options);
500fcf3ce44SJohn Forte mdb_printf(" fp_port_type : 0x%-2x\n",
501fcf3ce44SJohn Forte port.fp_port_type.port_type);
502fcf3ce44SJohn Forte mdb_printf(" fp_ub_count : %d\n", port.fp_ub_count);
503fcf3ce44SJohn Forte mdb_printf(" fp_active_ubs : %d\n", port.fp_active_ubs);
504fcf3ce44SJohn Forte mdb_printf(" fp_port_dip : 0x%p\n", port.fp_port_dip);
505fcf3ce44SJohn Forte mdb_printf(" fp_fca_dip : 0x%p\n", port.fp_fca_dip);
506fcf3ce44SJohn Forte
507fcf3ce44SJohn Forte for (idx = 0; idx < 16; idx++) {
508fcf3ce44SJohn Forte if (port.fp_ip_addr[idx] != 0)
509fcf3ce44SJohn Forte break;
510fcf3ce44SJohn Forte }
511fcf3ce44SJohn Forte
512fcf3ce44SJohn Forte if (idx != 16) {
513fcf3ce44SJohn Forte mdb_printf(" fp_ip_addr : %-2x:%-2x:%-2x:%-2x:"
514fcf3ce44SJohn Forte "%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x"
515fcf3ce44SJohn Forte ":%-2x:%-2x\n",
516fcf3ce44SJohn Forte port.fp_ip_addr[0], port.fp_ip_addr[1],
517fcf3ce44SJohn Forte port.fp_ip_addr[2], port.fp_ip_addr[3],
518fcf3ce44SJohn Forte port.fp_ip_addr[4], port.fp_ip_addr[5],
519fcf3ce44SJohn Forte port.fp_ip_addr[6], port.fp_ip_addr[7],
520fcf3ce44SJohn Forte port.fp_ip_addr[8], port.fp_ip_addr[9],
521fcf3ce44SJohn Forte port.fp_ip_addr[10], port.fp_ip_addr[11],
522fcf3ce44SJohn Forte port.fp_ip_addr[12], port.fp_ip_addr[13],
523fcf3ce44SJohn Forte port.fp_ip_addr[14], port.fp_ip_addr[15]);
524fcf3ce44SJohn Forte } else {
525fcf3ce44SJohn Forte mdb_printf(" fp_ip_addr : N/A\n");
526fcf3ce44SJohn Forte }
527fcf3ce44SJohn Forte
528fcf3ce44SJohn Forte mdb_printf(" fp_fc4_types : ");
529fcf3ce44SJohn Forte
530fcf3ce44SJohn Forte for (idx = 0; idx < 8; idx++) {
531fcf3ce44SJohn Forte if (port.fp_fc4_types[idx] != 0) {
532fcf3ce44SJohn Forte if (first) {
533fcf3ce44SJohn Forte mdb_printf("%d",
534fcf3ce44SJohn Forte port.fp_fc4_types[idx]);
535fcf3ce44SJohn Forte first = 0;
536fcf3ce44SJohn Forte } else {
537fcf3ce44SJohn Forte mdb_printf(", %d",
538fcf3ce44SJohn Forte port.fp_fc4_types[idx]);
539fcf3ce44SJohn Forte }
540fcf3ce44SJohn Forte }
541fcf3ce44SJohn Forte }
542fcf3ce44SJohn Forte
543fcf3ce44SJohn Forte if (first) {
544fcf3ce44SJohn Forte mdb_printf("None\n");
545fcf3ce44SJohn Forte } else {
546fcf3ce44SJohn Forte mdb_printf("\n");
547fcf3ce44SJohn Forte }
548fcf3ce44SJohn Forte
549fcf3ce44SJohn Forte mdb_printf(" fp_pm_level : %d\n", port.fp_pm_level);
550fcf3ce44SJohn Forte mdb_printf(" fp_pm_busy : %d\n", port.fp_pm_busy);
551fcf3ce44SJohn Forte mdb_printf(" fp_pm_busy_nocomp : 0x%-8x\n",
552fcf3ce44SJohn Forte port.fp_pm_busy_nocomp);
553fcf3ce44SJohn Forte mdb_printf(" fp_hard_addr : 0x%-6x\n",
554fcf3ce44SJohn Forte port.fp_hard_addr.hard_addr);
555fcf3ce44SJohn Forte mdb_printf(" fp_sym_port_name : \"%s\"\n",
556fcf3ce44SJohn Forte port.fp_sym_port_name);
557fcf3ce44SJohn Forte mdb_printf(" fp_sym_node_name : \"%s\"\n",
558fcf3ce44SJohn Forte port.fp_sym_node_name);
559fcf3ce44SJohn Forte mdb_printf(" fp_rscn_count : %d\n", port.fp_rscn_count);
560fcf3ce44SJohn Forte } else {
561fcf3ce44SJohn Forte mdb_warn("failed to read fc_local_port_t at 0x%p", addr);
562fcf3ce44SJohn Forte }
563fcf3ce44SJohn Forte
564fcf3ce44SJohn Forte mdb_printf("\n");
565fcf3ce44SJohn Forte
566fcf3ce44SJohn Forte return (DCMD_OK);
567fcf3ce44SJohn Forte }
568fcf3ce44SJohn Forte
569fcf3ce44SJohn Forte
570fcf3ce44SJohn Forte /*
571fcf3ce44SJohn Forte * Leadville remote_port walker/dcmd code
572fcf3ce44SJohn Forte */
573fcf3ce44SJohn Forte
574fcf3ce44SJohn Forte /*
575fcf3ce44SJohn Forte * We need to be given the address of a port structure in order to start
576fcf3ce44SJohn Forte * walking. From that, we can read the pwwn table.
577fcf3ce44SJohn Forte */
578fcf3ce44SJohn Forte static int
pd_by_pwwn_walk_i(mdb_walk_state_t * wsp)579fcf3ce44SJohn Forte pd_by_pwwn_walk_i(mdb_walk_state_t *wsp)
580fcf3ce44SJohn Forte {
581fcf3ce44SJohn Forte fc_local_port_t port;
582fcf3ce44SJohn Forte
583892ad162SToomas Soome if (wsp->walk_addr == 0) {
584fcf3ce44SJohn Forte mdb_warn("pd_by_pwwn walk doesn't support global walks\n");
585fcf3ce44SJohn Forte return (WALK_ERR);
586fcf3ce44SJohn Forte }
587fcf3ce44SJohn Forte
588fcf3ce44SJohn Forte /*
589fcf3ce44SJohn Forte * Allocate space for the pwwn_hash table
590fcf3ce44SJohn Forte */
591fcf3ce44SJohn Forte
592fcf3ce44SJohn Forte fp_pwwn_table = mdb_alloc(sizeof (struct pwwn_hash) *
593fcf3ce44SJohn Forte PWWN_HASH_TABLE_SIZE, UM_SLEEP);
594fcf3ce44SJohn Forte
595fcf3ce44SJohn Forte /*
596fcf3ce44SJohn Forte * Input should be an fc_local_port_t, so read it to get the pwwn
597fcf3ce44SJohn Forte * table's head
598fcf3ce44SJohn Forte */
599fcf3ce44SJohn Forte
600fcf3ce44SJohn Forte if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
601fcf3ce44SJohn Forte sizeof (fc_local_port_t)) {
602fcf3ce44SJohn Forte mdb_warn("Unable to read in the port structure address\n");
603fcf3ce44SJohn Forte return (WALK_ERR);
604fcf3ce44SJohn Forte }
605fcf3ce44SJohn Forte
606fcf3ce44SJohn Forte if (mdb_vread(fp_pwwn_table, sizeof (struct pwwn_hash) *
607fcf3ce44SJohn Forte PWWN_HASH_TABLE_SIZE, (uintptr_t)port.fp_pwwn_table) == -1) {
608fcf3ce44SJohn Forte mdb_warn("Unable to read in the pwwn hash table\n");
609fcf3ce44SJohn Forte return (WALK_ERR);
610fcf3ce44SJohn Forte }
611fcf3ce44SJohn Forte
612fcf3ce44SJohn Forte pd_hash_index = 0;
613fcf3ce44SJohn Forte
614fcf3ce44SJohn Forte while ((fp_pwwn_table[pd_hash_index].pwwn_head == NULL) &&
615fcf3ce44SJohn Forte (pd_hash_index < PWWN_HASH_TABLE_SIZE)) {
616fcf3ce44SJohn Forte pd_hash_index++;
617fcf3ce44SJohn Forte }
618fcf3ce44SJohn Forte
619fcf3ce44SJohn Forte wsp->walk_addr = (uintptr_t)fp_pwwn_table[pd_hash_index].pwwn_head;
620fcf3ce44SJohn Forte
621fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (fc_remote_port_t), UM_SLEEP);
622fcf3ce44SJohn Forte return (WALK_NEXT);
623fcf3ce44SJohn Forte }
624fcf3ce44SJohn Forte
625fcf3ce44SJohn Forte /*
626fcf3ce44SJohn Forte * At each step, read a fc_remote_port_t into our private storage, and then
627fcf3ce44SJohn Forte * invoke the callback function. We terminate when we reach a NULL p_next
628fcf3ce44SJohn Forte * pointer.
629fcf3ce44SJohn Forte */
630fcf3ce44SJohn Forte static int
pd_by_pwwn_walk_s(mdb_walk_state_t * wsp)631fcf3ce44SJohn Forte pd_by_pwwn_walk_s(mdb_walk_state_t *wsp)
632fcf3ce44SJohn Forte {
633fcf3ce44SJohn Forte int status;
634fcf3ce44SJohn Forte
635892ad162SToomas Soome if ((wsp->walk_addr == 0) &&
636fcf3ce44SJohn Forte (pd_hash_index >= (PWWN_HASH_TABLE_SIZE - 1))) {
637fcf3ce44SJohn Forte return (WALK_DONE);
638fcf3ce44SJohn Forte }
639fcf3ce44SJohn Forte
640fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (fc_remote_port_t), wsp->walk_addr)
641fcf3ce44SJohn Forte == -1) {
642fcf3ce44SJohn Forte mdb_warn("failed to read fc_remote_port at %p", wsp->walk_addr);
643fcf3ce44SJohn Forte return (WALK_DONE);
644fcf3ce44SJohn Forte }
645fcf3ce44SJohn Forte
646fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
647fcf3ce44SJohn Forte wsp->walk_cbdata);
648fcf3ce44SJohn Forte
649fcf3ce44SJohn Forte wsp->walk_addr =
650fcf3ce44SJohn Forte (uintptr_t)(((fc_remote_port_t *)wsp->walk_data)->pd_wwn_hnext);
651fcf3ce44SJohn Forte
652892ad162SToomas Soome if (wsp->walk_addr == 0) {
653fcf3ce44SJohn Forte /*
654fcf3ce44SJohn Forte * Try the next hash list, if there is one.
655fcf3ce44SJohn Forte */
656fcf3ce44SJohn Forte
657fcf3ce44SJohn Forte pd_hash_index++;
658fcf3ce44SJohn Forte
659fcf3ce44SJohn Forte while ((fp_pwwn_table[pd_hash_index].pwwn_head == NULL) &&
660fcf3ce44SJohn Forte (pd_hash_index < PWWN_HASH_TABLE_SIZE)) {
661fcf3ce44SJohn Forte pd_hash_index++;
662fcf3ce44SJohn Forte }
663fcf3ce44SJohn Forte
664fcf3ce44SJohn Forte if (pd_hash_index == PWWN_HASH_TABLE_SIZE) {
665fcf3ce44SJohn Forte /* We're done */
666fcf3ce44SJohn Forte return (status);
667fcf3ce44SJohn Forte }
668fcf3ce44SJohn Forte
669fcf3ce44SJohn Forte wsp->walk_addr =
670fcf3ce44SJohn Forte (uintptr_t)fp_pwwn_table[pd_hash_index].pwwn_head;
671fcf3ce44SJohn Forte }
672fcf3ce44SJohn Forte
673fcf3ce44SJohn Forte return (status);
674fcf3ce44SJohn Forte }
675fcf3ce44SJohn Forte
676fcf3ce44SJohn Forte /*
677fcf3ce44SJohn Forte * The walker's fini function is invoked at the end of each walk.
678fcf3ce44SJohn Forte */
679fcf3ce44SJohn Forte static void
pd_by_pwwn_walk_f(mdb_walk_state_t * wsp)680fcf3ce44SJohn Forte pd_by_pwwn_walk_f(mdb_walk_state_t *wsp)
681fcf3ce44SJohn Forte {
682fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (fc_remote_port_t));
683fcf3ce44SJohn Forte mdb_free(fp_pwwn_table, sizeof (struct pwwn_hash) *
684fcf3ce44SJohn Forte PWWN_HASH_TABLE_SIZE);
685fcf3ce44SJohn Forte fp_pwwn_table = NULL;
686fcf3ce44SJohn Forte }
687fcf3ce44SJohn Forte
688fcf3ce44SJohn Forte /*
689fcf3ce44SJohn Forte * This is the same walker as pd_by_pwwn, but we walk the D_ID hash table
690fcf3ce44SJohn Forte */
691fcf3ce44SJohn Forte
692fcf3ce44SJohn Forte static int
pd_by_did_walk_i(mdb_walk_state_t * wsp)693fcf3ce44SJohn Forte pd_by_did_walk_i(mdb_walk_state_t *wsp)
694fcf3ce44SJohn Forte {
695fcf3ce44SJohn Forte fc_local_port_t port;
696fcf3ce44SJohn Forte
697892ad162SToomas Soome if (wsp->walk_addr == 0) {
698fcf3ce44SJohn Forte mdb_warn("pd_by_did walk doesn't support global walks\n");
699fcf3ce44SJohn Forte return (WALK_ERR);
700fcf3ce44SJohn Forte }
701fcf3ce44SJohn Forte
702fcf3ce44SJohn Forte /*
703fcf3ce44SJohn Forte * Allocate space for the did_hash table
704fcf3ce44SJohn Forte */
705fcf3ce44SJohn Forte
706fcf3ce44SJohn Forte fp_did_table = mdb_alloc(sizeof (struct d_id_hash) *
707fcf3ce44SJohn Forte D_ID_HASH_TABLE_SIZE, UM_SLEEP);
708fcf3ce44SJohn Forte
709fcf3ce44SJohn Forte /*
710fcf3ce44SJohn Forte * Input should be an fc_local_port_t, so read it to get the d_id
711fcf3ce44SJohn Forte * table's head
712fcf3ce44SJohn Forte */
713fcf3ce44SJohn Forte
714fcf3ce44SJohn Forte if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
715fcf3ce44SJohn Forte sizeof (fc_local_port_t)) {
716fcf3ce44SJohn Forte mdb_warn("Unable to read in the port structure address\n");
717fcf3ce44SJohn Forte return (WALK_ERR);
718fcf3ce44SJohn Forte }
719fcf3ce44SJohn Forte
720fcf3ce44SJohn Forte if (mdb_vread(fp_did_table, sizeof (struct d_id_hash) *
721fcf3ce44SJohn Forte D_ID_HASH_TABLE_SIZE, (uintptr_t)port.fp_did_table) == -1) {
722fcf3ce44SJohn Forte mdb_warn("Unable to read in the D_ID hash table\n");
723fcf3ce44SJohn Forte return (WALK_ERR);
724fcf3ce44SJohn Forte }
725fcf3ce44SJohn Forte pd_hash_index = 0;
726fcf3ce44SJohn Forte
727fcf3ce44SJohn Forte while ((fp_did_table[pd_hash_index].d_id_head == NULL) &&
728fcf3ce44SJohn Forte (pd_hash_index < D_ID_HASH_TABLE_SIZE)) {
729fcf3ce44SJohn Forte pd_hash_index++;
730fcf3ce44SJohn Forte }
731fcf3ce44SJohn Forte
732fcf3ce44SJohn Forte wsp->walk_addr = (uintptr_t)fp_did_table[pd_hash_index].d_id_head;
733fcf3ce44SJohn Forte
734fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (fc_remote_port_t), UM_SLEEP);
735fcf3ce44SJohn Forte return (WALK_NEXT);
736fcf3ce44SJohn Forte }
737fcf3ce44SJohn Forte
738fcf3ce44SJohn Forte /*
739fcf3ce44SJohn Forte * At each step, read a fc_remote_port_t into our private storage, and then
740fcf3ce44SJohn Forte * invoke the callback function. We terminate when we reach a NULL p_next
741fcf3ce44SJohn Forte * pointer.
742fcf3ce44SJohn Forte */
743fcf3ce44SJohn Forte static int
pd_by_did_walk_s(mdb_walk_state_t * wsp)744fcf3ce44SJohn Forte pd_by_did_walk_s(mdb_walk_state_t *wsp)
745fcf3ce44SJohn Forte {
746fcf3ce44SJohn Forte int status;
747fcf3ce44SJohn Forte
748892ad162SToomas Soome if ((wsp->walk_addr == 0) &&
749fcf3ce44SJohn Forte (pd_hash_index >= (D_ID_HASH_TABLE_SIZE - 1))) {
750fcf3ce44SJohn Forte return (WALK_DONE);
751fcf3ce44SJohn Forte }
752fcf3ce44SJohn Forte
753fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (fc_remote_port_t), wsp->walk_addr)
754fcf3ce44SJohn Forte == -1) {
755fcf3ce44SJohn Forte mdb_warn("failed to read fc_remote_port at %p", wsp->walk_addr);
756fcf3ce44SJohn Forte return (WALK_DONE);
757fcf3ce44SJohn Forte }
758fcf3ce44SJohn Forte
759fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
760fcf3ce44SJohn Forte wsp->walk_cbdata);
761fcf3ce44SJohn Forte
762fcf3ce44SJohn Forte wsp->walk_addr =
763fcf3ce44SJohn Forte (uintptr_t)(((fc_remote_port_t *)wsp->walk_data)->pd_did_hnext);
764fcf3ce44SJohn Forte
765892ad162SToomas Soome if (wsp->walk_addr == 0) {
766fcf3ce44SJohn Forte /*
767fcf3ce44SJohn Forte * Try the next hash list, if there is one.
768fcf3ce44SJohn Forte */
769fcf3ce44SJohn Forte
770fcf3ce44SJohn Forte pd_hash_index++;
771fcf3ce44SJohn Forte
772fcf3ce44SJohn Forte while ((fp_did_table[pd_hash_index].d_id_head == NULL) &&
773fcf3ce44SJohn Forte (pd_hash_index < D_ID_HASH_TABLE_SIZE)) {
774fcf3ce44SJohn Forte pd_hash_index++;
775fcf3ce44SJohn Forte }
776fcf3ce44SJohn Forte
777fcf3ce44SJohn Forte if (pd_hash_index == D_ID_HASH_TABLE_SIZE) {
778fcf3ce44SJohn Forte /* We're done */
779fcf3ce44SJohn Forte return (status);
780fcf3ce44SJohn Forte }
781fcf3ce44SJohn Forte
782fcf3ce44SJohn Forte wsp->walk_addr =
783fcf3ce44SJohn Forte (uintptr_t)fp_did_table[pd_hash_index].d_id_head;
784fcf3ce44SJohn Forte }
785fcf3ce44SJohn Forte
786fcf3ce44SJohn Forte return (status);
787fcf3ce44SJohn Forte }
788fcf3ce44SJohn Forte
789fcf3ce44SJohn Forte /*
790fcf3ce44SJohn Forte * The walker's fini function is invoked at the end of each walk.
791fcf3ce44SJohn Forte */
792fcf3ce44SJohn Forte static void
pd_by_did_walk_f(mdb_walk_state_t * wsp)793fcf3ce44SJohn Forte pd_by_did_walk_f(mdb_walk_state_t *wsp)
794fcf3ce44SJohn Forte {
795fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (fc_remote_port_t));
796fcf3ce44SJohn Forte mdb_free(fp_did_table, sizeof (struct d_id_hash) *
797fcf3ce44SJohn Forte D_ID_HASH_TABLE_SIZE);
798fcf3ce44SJohn Forte fp_did_table = NULL;
799fcf3ce44SJohn Forte }
800fcf3ce44SJohn Forte
801fcf3ce44SJohn Forte
802fcf3ce44SJohn Forte /*
803fcf3ce44SJohn Forte * Display a remote_port structure
804fcf3ce44SJohn Forte */
805fcf3ce44SJohn Forte static int
remote_port(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)806fcf3ce44SJohn Forte remote_port(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
807fcf3ce44SJohn Forte {
808fcf3ce44SJohn Forte fc_remote_port_t pd;
809fcf3ce44SJohn Forte int idx;
810fcf3ce44SJohn Forte int first = 1;
811fcf3ce44SJohn Forte
812fcf3ce44SJohn Forte if (argc > 0) {
813fcf3ce44SJohn Forte return (DCMD_USAGE);
814fcf3ce44SJohn Forte }
815fcf3ce44SJohn Forte
816fcf3ce44SJohn Forte if (!(flags & DCMD_ADDRSPEC)) {
817fcf3ce44SJohn Forte mdb_printf("Sorry, you must provide an address\n");
818fcf3ce44SJohn Forte return (DCMD_ERR);
819fcf3ce44SJohn Forte }
820fcf3ce44SJohn Forte
821fcf3ce44SJohn Forte if (mdb_vread(&pd, sizeof (fc_remote_port_t), addr) !=
822fcf3ce44SJohn Forte sizeof (fc_remote_port_t)) {
823fcf3ce44SJohn Forte mdb_warn("Error reading pd at 0x%x\n", addr);
824fcf3ce44SJohn Forte return (DCMD_ERR);
825fcf3ce44SJohn Forte }
826fcf3ce44SJohn Forte
827fcf3ce44SJohn Forte mdb_printf("Reading remote_port at 0x%p\n", addr);
828fcf3ce44SJohn Forte mdb_printf(" mutex : 0x%p\n", pd.pd_mutex);
829fcf3ce44SJohn Forte mdb_printf(" port_id : 0x%-8x\n", pd.pd_port_id);
830fcf3ce44SJohn Forte mdb_printf(" port_name : 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
831fcf3ce44SJohn Forte pd.pd_port_name.raw_wwn[0], pd.pd_port_name.raw_wwn[1],
832fcf3ce44SJohn Forte pd.pd_port_name.raw_wwn[2], pd.pd_port_name.raw_wwn[3],
833fcf3ce44SJohn Forte pd.pd_port_name.raw_wwn[4], pd.pd_port_name.raw_wwn[5],
834fcf3ce44SJohn Forte pd.pd_port_name.raw_wwn[6], pd.pd_port_name.raw_wwn[7]);
835fcf3ce44SJohn Forte mdb_printf(" login_count : %d\n", pd.pd_login_count);
836fcf3ce44SJohn Forte mdb_printf(" state : 0x%x ", pd.pd_state);
837fcf3ce44SJohn Forte
838fcf3ce44SJohn Forte switch (pd.pd_state) {
839fcf3ce44SJohn Forte case PORT_DEVICE_INVALID:
840fcf3ce44SJohn Forte mdb_printf("(invalid)\n");
841fcf3ce44SJohn Forte break;
842fcf3ce44SJohn Forte case PORT_DEVICE_VALID:
843fcf3ce44SJohn Forte mdb_printf("(valid)\n");
844fcf3ce44SJohn Forte break;
845fcf3ce44SJohn Forte case PORT_DEVICE_LOGGED_IN:
846fcf3ce44SJohn Forte mdb_printf("(logged in)\n");
847fcf3ce44SJohn Forte break;
848fcf3ce44SJohn Forte default:
849fcf3ce44SJohn Forte mdb_printf("(Unknown state)\n");
850fcf3ce44SJohn Forte }
851fcf3ce44SJohn Forte
852fcf3ce44SJohn Forte mdb_printf(" remote node : 0x%p\n", pd.pd_remote_nodep);
853fcf3ce44SJohn Forte mdb_printf(" hard_addr : 0x%x\n", pd.pd_hard_addr);
854fcf3ce44SJohn Forte mdb_printf(" local port : 0x%p\n", pd.pd_port);
855fcf3ce44SJohn Forte mdb_printf(" type : %d ", pd.pd_type);
856fcf3ce44SJohn Forte
857fcf3ce44SJohn Forte switch (pd.pd_type) {
858fcf3ce44SJohn Forte case PORT_DEVICE_NOCHANGE:
859fcf3ce44SJohn Forte mdb_printf("(No change)\n");
860fcf3ce44SJohn Forte break;
861fcf3ce44SJohn Forte case PORT_DEVICE_NEW:
862fcf3ce44SJohn Forte mdb_printf("(New)\n");
863fcf3ce44SJohn Forte break;
864fcf3ce44SJohn Forte case PORT_DEVICE_OLD:
865fcf3ce44SJohn Forte mdb_printf("(Old)\n");
866fcf3ce44SJohn Forte break;
867fcf3ce44SJohn Forte case PORT_DEVICE_CHANGED:
868fcf3ce44SJohn Forte mdb_printf("(Changed)\n");
869fcf3ce44SJohn Forte break;
870fcf3ce44SJohn Forte case PORT_DEVICE_DELETE:
871fcf3ce44SJohn Forte mdb_printf("(Delete)\n");
872fcf3ce44SJohn Forte break;
873fcf3ce44SJohn Forte case PORT_DEVICE_USER_LOGIN:
874fcf3ce44SJohn Forte mdb_printf("(User login)\n");
875fcf3ce44SJohn Forte break;
876fcf3ce44SJohn Forte case PORT_DEVICE_USER_LOGOUT:
877fcf3ce44SJohn Forte mdb_printf("(User logout)\n");
878fcf3ce44SJohn Forte break;
879fcf3ce44SJohn Forte case PORT_DEVICE_USER_CREATE:
880fcf3ce44SJohn Forte mdb_printf("(User create)\n");
881fcf3ce44SJohn Forte break;
882fcf3ce44SJohn Forte case PORT_DEVICE_USER_DELETE:
883fcf3ce44SJohn Forte mdb_printf("(User delete)\n");
884fcf3ce44SJohn Forte break;
885fcf3ce44SJohn Forte default:
886fcf3ce44SJohn Forte mdb_printf("(Unknown type)\n");
887fcf3ce44SJohn Forte }
888fcf3ce44SJohn Forte
889fcf3ce44SJohn Forte mdb_printf(" flags : 0x%x ", pd.pd_flags);
890fcf3ce44SJohn Forte
891fcf3ce44SJohn Forte switch (pd.pd_flags) {
892fcf3ce44SJohn Forte case PD_IDLE:
893fcf3ce44SJohn Forte mdb_printf("(Idle)\n");
894fcf3ce44SJohn Forte break;
895fcf3ce44SJohn Forte case PD_ELS_IN_PROGRESS:
896fcf3ce44SJohn Forte mdb_printf("(ELS in progress)\n");
897fcf3ce44SJohn Forte break;
898fcf3ce44SJohn Forte case PD_ELS_MARK:
899fcf3ce44SJohn Forte mdb_printf("(Mark)\n");
900fcf3ce44SJohn Forte break;
901fcf3ce44SJohn Forte default:
902fcf3ce44SJohn Forte mdb_printf("(Unknown flag value)\n");
903fcf3ce44SJohn Forte }
904fcf3ce44SJohn Forte
905fcf3ce44SJohn Forte mdb_printf(" login_class : 0x%x\n", pd.pd_login_class);
906fcf3ce44SJohn Forte mdb_printf(" recipient : %d\n", pd.pd_recepient);
907fcf3ce44SJohn Forte mdb_printf(" ref_count : %d\n", pd.pd_ref_count);
908fcf3ce44SJohn Forte mdb_printf(" aux_flags : 0x%x ", pd.pd_aux_flags);
909fcf3ce44SJohn Forte
910fcf3ce44SJohn Forte first = 1;
911fcf3ce44SJohn Forte if (pd.pd_aux_flags & PD_IN_DID_QUEUE) {
912fcf3ce44SJohn Forte mdb_printf("(IN_DID_QUEUE");
913fcf3ce44SJohn Forte first = 0;
914fcf3ce44SJohn Forte }
915fcf3ce44SJohn Forte
916fcf3ce44SJohn Forte if (pd.pd_aux_flags & PD_DISABLE_RELOGIN) {
917fcf3ce44SJohn Forte if (first) {
918fcf3ce44SJohn Forte mdb_printf("(DISABLE_RELOGIN");
919fcf3ce44SJohn Forte } else {
920fcf3ce44SJohn Forte mdb_printf(", DISABLE_RELOGIN");
921fcf3ce44SJohn Forte }
922fcf3ce44SJohn Forte first = 0;
923fcf3ce44SJohn Forte }
924fcf3ce44SJohn Forte
925fcf3ce44SJohn Forte if (pd.pd_aux_flags & PD_NEEDS_REMOVAL) {
926fcf3ce44SJohn Forte if (first) {
927fcf3ce44SJohn Forte mdb_printf("(NEEDS_REMOVAL");
928fcf3ce44SJohn Forte } else {
929fcf3ce44SJohn Forte mdb_printf(", NEEDS_REMOVAL");
930fcf3ce44SJohn Forte }
931fcf3ce44SJohn Forte first = 0;
932fcf3ce44SJohn Forte }
933fcf3ce44SJohn Forte
934fcf3ce44SJohn Forte if (pd.pd_aux_flags & PD_LOGGED_OUT) {
935fcf3ce44SJohn Forte if (first) {
936fcf3ce44SJohn Forte mdb_printf("(LOGGED_OUT");
937fcf3ce44SJohn Forte } else {
938fcf3ce44SJohn Forte mdb_printf(", LOGGED_OUT");
939fcf3ce44SJohn Forte }
940fcf3ce44SJohn Forte first = 0;
941fcf3ce44SJohn Forte }
942fcf3ce44SJohn Forte
943fcf3ce44SJohn Forte if (pd.pd_aux_flags & PD_GIVEN_TO_ULPS) {
944fcf3ce44SJohn Forte if (first) {
945fcf3ce44SJohn Forte mdb_printf("(GIVEN_TO_ULPS");
946fcf3ce44SJohn Forte } else {
947fcf3ce44SJohn Forte mdb_printf(", GIVEN_TO_ULPS");
948fcf3ce44SJohn Forte }
949fcf3ce44SJohn Forte first = 0;
950fcf3ce44SJohn Forte }
951fcf3ce44SJohn Forte
952fcf3ce44SJohn Forte if (first == 0) {
953fcf3ce44SJohn Forte mdb_printf(")\n");
954fcf3ce44SJohn Forte } else {
955fcf3ce44SJohn Forte mdb_printf("\n");
956fcf3ce44SJohn Forte }
957fcf3ce44SJohn Forte
958fcf3ce44SJohn Forte mdb_printf(" sig : %p\n", pd.pd_logo_tc.sig);
959fcf3ce44SJohn Forte mdb_printf(" active : %d\n", pd.pd_logo_tc.active);
960fcf3ce44SJohn Forte mdb_printf(" counter : %d\n", pd.pd_logo_tc.counter);
961fcf3ce44SJohn Forte mdb_printf(" max_value : %d\n", pd.pd_logo_tc.max_value);
962fcf3ce44SJohn Forte mdb_printf(" timer : %d\n", pd.pd_logo_tc.timer);
963fcf3ce44SJohn Forte mdb_printf("\n");
964fcf3ce44SJohn Forte
965fcf3ce44SJohn Forte return (DCMD_OK);
966fcf3ce44SJohn Forte }
967fcf3ce44SJohn Forte
968fcf3ce44SJohn Forte int
fc_dump_logmsg(fc_trace_dmsg_t * addr,uint_t pktstart,uint_t pktend,uint_t * printed)969fcf3ce44SJohn Forte fc_dump_logmsg(fc_trace_dmsg_t *addr, uint_t pktstart, uint_t pktend,
970fcf3ce44SJohn Forte uint_t *printed)
971fcf3ce44SJohn Forte {
972fcf3ce44SJohn Forte fc_trace_dmsg_t msg;
973fcf3ce44SJohn Forte caddr_t buf;
974fcf3ce44SJohn Forte char merge[1024];
975fcf3ce44SJohn Forte caddr_t tmppkt;
976fcf3ce44SJohn Forte char *tmpbuf; /* for tokenising the buffer */
977fcf3ce44SJohn Forte uint_t pktnum = 0;
978fcf3ce44SJohn Forte
979fcf3ce44SJohn Forte while (addr != NULL) {
980fcf3ce44SJohn Forte if (mdb_vread(&msg, sizeof (msg), (uintptr_t)addr) !=
981fcf3ce44SJohn Forte sizeof (msg)) {
982fcf3ce44SJohn Forte mdb_warn("failed to read message pointer in kernel");
983fcf3ce44SJohn Forte return (DCMD_ERR);
984fcf3ce44SJohn Forte }
985fcf3ce44SJohn Forte
986fcf3ce44SJohn Forte if (msg.id_size) {
987fcf3ce44SJohn Forte
988fcf3ce44SJohn Forte buf = mdb_alloc(msg.id_size + 1, UM_SLEEP);
989fcf3ce44SJohn Forte tmppkt = mdb_alloc(msg.id_size + 1, UM_SLEEP);
990fcf3ce44SJohn Forte
991fcf3ce44SJohn Forte if (mdb_vread(buf, msg.id_size,
992fcf3ce44SJohn Forte (uintptr_t)msg.id_buf) != msg.id_size) {
993fcf3ce44SJohn Forte mdb_warn("failed to read buffer contents"
994fcf3ce44SJohn Forte " in kernel");
995fcf3ce44SJohn Forte mdb_free(buf, msg.id_size + 1);
996fcf3ce44SJohn Forte return (DCMD_ERR);
997fcf3ce44SJohn Forte }
998fcf3ce44SJohn Forte
999fcf3ce44SJohn Forte if (buf[0] == '\n') {
1000fcf3ce44SJohn Forte mdb_printf("There is a problem in"
1001fcf3ce44SJohn Forte "the buffer\n");
1002fcf3ce44SJohn Forte }
1003fcf3ce44SJohn Forte /* funky packet processing stuff */
1004fcf3ce44SJohn Forte bcopy(buf, tmppkt, msg.id_size + 1);
1005fcf3ce44SJohn Forte
1006fcf3ce44SJohn Forte /* find the equals sign, and put a null there */
1007fcf3ce44SJohn Forte tmpbuf = strchr(tmppkt, '=');
1008fcf3ce44SJohn Forte *tmpbuf = 0;
1009fcf3ce44SJohn Forte pktnum = (uint_t)mdb_strtoull(tmppkt);
1010fcf3ce44SJohn Forte
1011fcf3ce44SJohn Forte if ((pktnum >= pktstart) && (pktnum <= pktend)) {
1012fcf3ce44SJohn Forte (void) mdb_snprintf(merge, sizeof (merge),
1013585995d5SYu Renia Miao "[%Y:%03d:%03d:%03d] %s",
1014585995d5SYu Renia Miao msg.id_time.tv_sec,
1015fcf3ce44SJohn Forte (int)msg.id_time.tv_nsec/1000000,
1016fcf3ce44SJohn Forte (int)(msg.id_time.tv_nsec/1000)%1000,
1017585995d5SYu Renia Miao (int)msg.id_time.tv_nsec%1000, buf);
1018fcf3ce44SJohn Forte mdb_printf("%s", merge);
1019fcf3ce44SJohn Forte if (printed != NULL)
1020fcf3ce44SJohn Forte (*printed) ++;
1021fcf3ce44SJohn Forte }
1022fcf3ce44SJohn Forte mdb_free(buf, msg.id_size + 1);
1023fcf3ce44SJohn Forte mdb_free(tmppkt, msg.id_size + 1);
1024fcf3ce44SJohn Forte }
1025fcf3ce44SJohn Forte addr = msg.id_next;
1026fcf3ce44SJohn Forte }
1027fcf3ce44SJohn Forte
1028fcf3ce44SJohn Forte return (DCMD_OK);
1029fcf3ce44SJohn Forte }
1030fcf3ce44SJohn Forte
1031fcf3ce44SJohn Forte int
fc_dump_old_logmsg(fc_trace_dmsgv1_t * addr,uint_t pktstart,uint_t pktend,uint_t * printed)1032fcf3ce44SJohn Forte fc_dump_old_logmsg(fc_trace_dmsgv1_t *addr, uint_t pktstart, uint_t pktend,
1033fcf3ce44SJohn Forte uint_t *printed)
1034fcf3ce44SJohn Forte {
1035fcf3ce44SJohn Forte fc_trace_dmsgv1_t msg;
1036fcf3ce44SJohn Forte caddr_t buf;
1037fcf3ce44SJohn Forte char merge[1024];
1038fcf3ce44SJohn Forte caddr_t tmppkt;
1039fcf3ce44SJohn Forte char *tmpbuf; /* for tokenising the buffer */
1040fcf3ce44SJohn Forte uint_t pktnum = 0;
1041fcf3ce44SJohn Forte
1042fcf3ce44SJohn Forte while (addr != NULL) {
1043fcf3ce44SJohn Forte if (mdb_vread(&msg, sizeof (msg), (uintptr_t)addr) !=
1044fcf3ce44SJohn Forte sizeof (msg)) {
1045fcf3ce44SJohn Forte mdb_warn("failed to read message pointer in kernel");
1046fcf3ce44SJohn Forte return (DCMD_ERR);
1047fcf3ce44SJohn Forte }
1048fcf3ce44SJohn Forte
1049fcf3ce44SJohn Forte if (msg.id_size) {
1050fcf3ce44SJohn Forte
1051fcf3ce44SJohn Forte buf = mdb_alloc(msg.id_size + 1, UM_SLEEP);
1052fcf3ce44SJohn Forte tmppkt = mdb_alloc(msg.id_size + 1, UM_SLEEP);
1053fcf3ce44SJohn Forte
1054fcf3ce44SJohn Forte if (mdb_vread(buf, msg.id_size,
1055fcf3ce44SJohn Forte (uintptr_t)msg.id_buf) != msg.id_size) {
1056fcf3ce44SJohn Forte mdb_warn("failed to read buffer contents"
1057fcf3ce44SJohn Forte " in kernel");
1058fcf3ce44SJohn Forte mdb_free(buf, msg.id_size + 1);
1059fcf3ce44SJohn Forte return (DCMD_ERR);
1060fcf3ce44SJohn Forte }
1061fcf3ce44SJohn Forte
1062fcf3ce44SJohn Forte if (buf[0] == '\n') {
1063fcf3ce44SJohn Forte mdb_printf("There is a problem in"
1064fcf3ce44SJohn Forte "the buffer\n");
1065fcf3ce44SJohn Forte }
1066fcf3ce44SJohn Forte /* funky packet processing stuff */
1067fcf3ce44SJohn Forte bcopy(buf, tmppkt, msg.id_size + 1);
1068fcf3ce44SJohn Forte
1069fcf3ce44SJohn Forte tmpbuf = strchr(tmppkt, '=');
1070fcf3ce44SJohn Forte *tmpbuf = 0;
1071fcf3ce44SJohn Forte pktnum = (uint_t)mdb_strtoull(tmppkt);
1072fcf3ce44SJohn Forte
1073fcf3ce44SJohn Forte if ((pktnum >= pktstart) && (pktnum <= pktend)) {
1074fcf3ce44SJohn Forte (void) mdb_snprintf(merge, sizeof (merge),
1075585995d5SYu Renia Miao "[%Y] %s", msg.id_time, buf);
1076fcf3ce44SJohn Forte mdb_printf("%s", merge);
1077fcf3ce44SJohn Forte if (printed != NULL)
1078fcf3ce44SJohn Forte (*printed) ++;
1079fcf3ce44SJohn Forte }
1080fcf3ce44SJohn Forte mdb_free(buf, msg.id_size + 1);
1081fcf3ce44SJohn Forte mdb_free(tmppkt, msg.id_size + 1);
1082fcf3ce44SJohn Forte }
1083fcf3ce44SJohn Forte addr = msg.id_next;
1084fcf3ce44SJohn Forte }
1085fcf3ce44SJohn Forte
1086fcf3ce44SJohn Forte return (DCMD_OK);
1087fcf3ce44SJohn Forte }
1088fcf3ce44SJohn Forte
1089fcf3ce44SJohn Forte int
fc_trace_dump(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1090fcf3ce44SJohn Forte fc_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1091fcf3ce44SJohn Forte {
1092fcf3ce44SJohn Forte fc_trace_logq_t logq;
1093fcf3ce44SJohn Forte uint_t pktnum = 0;
1094fcf3ce44SJohn Forte uint_t printed = 0; /* have we printed anything? */
1095fcf3ce44SJohn Forte
1096fcf3ce44SJohn Forte uintptr_t pktstart = 0;
1097fcf3ce44SJohn Forte uintptr_t pktend = UINT_MAX;
1098fcf3ce44SJohn Forte int rval = DCMD_OK;
1099fcf3ce44SJohn Forte
1100fcf3ce44SJohn Forte if (mdb_vread(&logq, sizeof (logq), addr) != sizeof (logq)) {
1101fcf3ce44SJohn Forte mdb_warn("Failed to read log queue in kernel");
1102fcf3ce44SJohn Forte return (DCMD_ERR);
1103fcf3ce44SJohn Forte }
1104fcf3ce44SJohn Forte
1105fcf3ce44SJohn Forte if (mdb_getopts(argc, argv,
1106fcf3ce44SJohn Forte 's', MDB_OPT_UINTPTR, &pktstart,
1107*3b442230SJordan Paige Hendricks 'e', MDB_OPT_UINTPTR, &pktend,
1108*3b442230SJordan Paige Hendricks NULL) != argc) {
1109fcf3ce44SJohn Forte return (DCMD_USAGE);
1110fcf3ce44SJohn Forte }
1111fcf3ce44SJohn Forte
1112fcf3ce44SJohn Forte if (pktstart > pktend) {
1113fcf3ce44SJohn Forte return (DCMD_USAGE);
1114fcf3ce44SJohn Forte }
1115fcf3ce44SJohn Forte
1116d75f3745SJohn Levon if ((logq.il_flags & FC_TRACE_LOGQ_V2) != 0) {
1117fcf3ce44SJohn Forte rval = fc_dump_logmsg((fc_trace_dmsg_t *)logq.il_msgh, pktstart,
1118fcf3ce44SJohn Forte pktend, &printed);
1119fcf3ce44SJohn Forte } else {
1120fcf3ce44SJohn Forte rval = fc_dump_old_logmsg((fc_trace_dmsgv1_t *)logq.il_msgh,
1121fcf3ce44SJohn Forte pktstart, pktend, &printed);
1122fcf3ce44SJohn Forte }
1123fcf3ce44SJohn Forte
1124fcf3ce44SJohn Forte if (rval != DCMD_OK) {
1125fcf3ce44SJohn Forte return (rval);
1126fcf3ce44SJohn Forte }
1127fcf3ce44SJohn Forte
1128fcf3ce44SJohn Forte if (printed == 0) {
1129fcf3ce44SJohn Forte mdb_printf("No packets in the buffer match the"
1130fcf3ce44SJohn Forte " criteria given");
1131fcf3ce44SJohn Forte }
1132fcf3ce44SJohn Forte
1133fcf3ce44SJohn Forte return (rval);
1134fcf3ce44SJohn Forte }
1135fcf3ce44SJohn Forte
1136fcf3ce44SJohn Forte int
fp_trace_dump(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1137fcf3ce44SJohn Forte fp_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1138fcf3ce44SJohn Forte {
1139fcf3ce44SJohn Forte if (mdb_readvar(&addr, "fp_logq") == -1) {
1140fcf3ce44SJohn Forte mdb_warn("failed to read fp_logq");
1141fcf3ce44SJohn Forte return (DCMD_ERR);
1142fcf3ce44SJohn Forte }
1143fcf3ce44SJohn Forte
1144fcf3ce44SJohn Forte if (DCMD_HDRSPEC(flags)) {
1145fcf3ce44SJohn Forte mdb_printf("fp trace buffer contents\n");
1146fcf3ce44SJohn Forte }
1147fcf3ce44SJohn Forte
1148fcf3ce44SJohn Forte return (fc_trace_dump(addr, flags, argc, argv));
1149fcf3ce44SJohn Forte }
1150fcf3ce44SJohn Forte
1151fcf3ce44SJohn Forte
1152fcf3ce44SJohn Forte int
fcp_trace_dump(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1153fcf3ce44SJohn Forte fcp_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1154fcf3ce44SJohn Forte {
1155fcf3ce44SJohn Forte if (mdb_readvar(&addr, "fcp_logq") == -1) {
1156fcf3ce44SJohn Forte mdb_warn("failed to read fcp_logq");
1157fcf3ce44SJohn Forte return (DCMD_ERR);
1158fcf3ce44SJohn Forte }
1159fcf3ce44SJohn Forte
1160fcf3ce44SJohn Forte if (DCMD_HDRSPEC(flags)) {
1161fcf3ce44SJohn Forte mdb_printf("fcp trace buffer contents\n");
1162fcf3ce44SJohn Forte }
1163fcf3ce44SJohn Forte
1164fcf3ce44SJohn Forte return (fc_trace_dump(addr, flags, argc, argv));
1165fcf3ce44SJohn Forte }
1166fcf3ce44SJohn Forte
1167fcf3ce44SJohn Forte /*
1168fcf3ce44SJohn Forte * Leadville job_request walker/dcmd code
1169fcf3ce44SJohn Forte */
1170fcf3ce44SJohn Forte
1171fcf3ce44SJohn Forte /*
1172fcf3ce44SJohn Forte * We need to be given the address of a local port structure in order to start
1173fcf3ce44SJohn Forte * walking. From that, we can read the job_request list.
1174fcf3ce44SJohn Forte */
1175fcf3ce44SJohn Forte
1176fcf3ce44SJohn Forte static int
job_request_walk_i(mdb_walk_state_t * wsp)1177fcf3ce44SJohn Forte job_request_walk_i(mdb_walk_state_t *wsp)
1178fcf3ce44SJohn Forte {
1179892ad162SToomas Soome if (wsp->walk_addr == 0) {
1180fcf3ce44SJohn Forte mdb_warn("The address of a fc_local_port"
1181fcf3ce44SJohn Forte " structure must be given\n");
1182fcf3ce44SJohn Forte return (WALK_ERR);
1183fcf3ce44SJohn Forte }
1184fcf3ce44SJohn Forte
1185fcf3ce44SJohn Forte /*
1186fcf3ce44SJohn Forte * Input should be a fc_local_port_t, so read it to get the job_request
1187fcf3ce44SJohn Forte * lists's head
1188fcf3ce44SJohn Forte */
1189fcf3ce44SJohn Forte
1190fcf3ce44SJohn Forte if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
1191fcf3ce44SJohn Forte sizeof (fc_local_port_t)) {
1192fcf3ce44SJohn Forte mdb_warn("Failed to read in the fc_local_port"
1193fcf3ce44SJohn Forte " at 0x%p\n", wsp->walk_addr);
1194fcf3ce44SJohn Forte return (WALK_ERR);
1195fcf3ce44SJohn Forte }
1196fcf3ce44SJohn Forte
1197fcf3ce44SJohn Forte wsp->walk_addr = (uintptr_t)(port.fp_job_head);
1198fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (struct job_request), UM_SLEEP);
1199fcf3ce44SJohn Forte
1200fcf3ce44SJohn Forte return (WALK_NEXT);
1201fcf3ce44SJohn Forte }
1202fcf3ce44SJohn Forte
1203fcf3ce44SJohn Forte static int
job_request_walk_s(mdb_walk_state_t * wsp)1204fcf3ce44SJohn Forte job_request_walk_s(mdb_walk_state_t *wsp)
1205fcf3ce44SJohn Forte {
1206fcf3ce44SJohn Forte int status;
1207fcf3ce44SJohn Forte
1208892ad162SToomas Soome if (wsp->walk_addr == 0)
1209fcf3ce44SJohn Forte return (WALK_DONE);
1210fcf3ce44SJohn Forte
1211fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (struct job_request),
1212fcf3ce44SJohn Forte wsp->walk_addr) == -1) {
1213fcf3ce44SJohn Forte mdb_warn("Failed to read in the job_request at 0x%p\n",
1214fcf3ce44SJohn Forte wsp->walk_addr);
1215fcf3ce44SJohn Forte return (WALK_DONE);
1216fcf3ce44SJohn Forte }
1217fcf3ce44SJohn Forte
1218fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
1219fcf3ce44SJohn Forte wsp->walk_cbdata);
1220fcf3ce44SJohn Forte
1221fcf3ce44SJohn Forte wsp->walk_addr =
1222fcf3ce44SJohn Forte (uintptr_t)(((struct job_request *)wsp->walk_data)->job_next);
1223fcf3ce44SJohn Forte
1224fcf3ce44SJohn Forte return (status);
1225fcf3ce44SJohn Forte }
1226fcf3ce44SJohn Forte
1227fcf3ce44SJohn Forte /*
1228fcf3ce44SJohn Forte * The walker's fini function is invoked at the end of each walk.
1229fcf3ce44SJohn Forte */
1230fcf3ce44SJohn Forte static void
job_request_walk_f(mdb_walk_state_t * wsp)1231fcf3ce44SJohn Forte job_request_walk_f(mdb_walk_state_t *wsp)
1232fcf3ce44SJohn Forte {
1233fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (struct job_request));
1234fcf3ce44SJohn Forte }
1235fcf3ce44SJohn Forte
1236fcf3ce44SJohn Forte
1237fcf3ce44SJohn Forte /*
1238fcf3ce44SJohn Forte * Leadville fc_orphan walker/dcmd code
1239fcf3ce44SJohn Forte */
1240fcf3ce44SJohn Forte
1241fcf3ce44SJohn Forte /*
1242fcf3ce44SJohn Forte * We need to be given the address of a port structure in order to start
1243fcf3ce44SJohn Forte * walking. From that, we can read the orphan list.
1244fcf3ce44SJohn Forte */
1245fcf3ce44SJohn Forte
1246fcf3ce44SJohn Forte static int
orphan_walk_i(mdb_walk_state_t * wsp)1247fcf3ce44SJohn Forte orphan_walk_i(mdb_walk_state_t *wsp)
1248fcf3ce44SJohn Forte {
1249892ad162SToomas Soome if (wsp->walk_addr == 0) {
1250fcf3ce44SJohn Forte mdb_warn("The address of a fc_local_port"
1251fcf3ce44SJohn Forte " structure must be given\n");
1252fcf3ce44SJohn Forte return (WALK_ERR);
1253fcf3ce44SJohn Forte }
1254fcf3ce44SJohn Forte
1255fcf3ce44SJohn Forte /*
1256fcf3ce44SJohn Forte * Input should be a fc_local_port_t, so read it to get the orphan
1257fcf3ce44SJohn Forte * lists's head
1258fcf3ce44SJohn Forte */
1259fcf3ce44SJohn Forte
1260fcf3ce44SJohn Forte if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
1261fcf3ce44SJohn Forte sizeof (fc_local_port_t)) {
1262fcf3ce44SJohn Forte mdb_warn("Failed to read in the fc_local_port"
1263fcf3ce44SJohn Forte " at 0x%p\n", wsp->walk_addr);
1264fcf3ce44SJohn Forte return (WALK_ERR);
1265fcf3ce44SJohn Forte }
1266fcf3ce44SJohn Forte
1267fcf3ce44SJohn Forte wsp->walk_addr = (uintptr_t)(port.fp_orphan_list);
1268fcf3ce44SJohn Forte wsp->walk_data = mdb_alloc(sizeof (struct fc_orphan), UM_SLEEP);
1269fcf3ce44SJohn Forte
1270fcf3ce44SJohn Forte return (WALK_NEXT);
1271fcf3ce44SJohn Forte }
1272fcf3ce44SJohn Forte
1273fcf3ce44SJohn Forte static int
orphan_walk_s(mdb_walk_state_t * wsp)1274fcf3ce44SJohn Forte orphan_walk_s(mdb_walk_state_t *wsp)
1275fcf3ce44SJohn Forte {
1276fcf3ce44SJohn Forte int status;
1277fcf3ce44SJohn Forte
1278892ad162SToomas Soome if (wsp->walk_addr == 0)
1279fcf3ce44SJohn Forte return (WALK_DONE);
1280fcf3ce44SJohn Forte
1281fcf3ce44SJohn Forte if (mdb_vread(wsp->walk_data, sizeof (struct fc_orphan),
1282fcf3ce44SJohn Forte wsp->walk_addr) == -1) {
1283fcf3ce44SJohn Forte mdb_warn("Failed to read in the fc_orphan at 0x%p\n",
1284fcf3ce44SJohn Forte wsp->walk_addr);
1285fcf3ce44SJohn Forte return (WALK_DONE);
1286fcf3ce44SJohn Forte }
1287fcf3ce44SJohn Forte
1288fcf3ce44SJohn Forte status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
1289fcf3ce44SJohn Forte wsp->walk_cbdata);
1290fcf3ce44SJohn Forte
1291fcf3ce44SJohn Forte wsp->walk_addr =
1292fcf3ce44SJohn Forte (uintptr_t)(((struct fc_orphan *)wsp->walk_data)->orp_next);
1293fcf3ce44SJohn Forte
1294fcf3ce44SJohn Forte return (status);
1295fcf3ce44SJohn Forte }
1296fcf3ce44SJohn Forte
1297fcf3ce44SJohn Forte /*
1298fcf3ce44SJohn Forte * The walker's fini function is invoked at the end of each walk.
1299fcf3ce44SJohn Forte */
1300fcf3ce44SJohn Forte static void
orphan_walk_f(mdb_walk_state_t * wsp)1301fcf3ce44SJohn Forte orphan_walk_f(mdb_walk_state_t *wsp)
1302fcf3ce44SJohn Forte {
1303fcf3ce44SJohn Forte mdb_free(wsp->walk_data, sizeof (struct fc_orphan));
1304fcf3ce44SJohn Forte }
1305fcf3ce44SJohn Forte
1306fcf3ce44SJohn Forte
1307fcf3ce44SJohn Forte /*
1308fcf3ce44SJohn Forte * MDB module linkage information:
1309fcf3ce44SJohn Forte *
1310fcf3ce44SJohn Forte * We declare a list of structures describing our dcmds, a list of structures
1311fcf3ce44SJohn Forte * describing our walkers, and a function named _mdb_init to return a pointer
1312fcf3ce44SJohn Forte * to our module information.
1313fcf3ce44SJohn Forte */
1314fcf3ce44SJohn Forte
1315fcf3ce44SJohn Forte static const mdb_dcmd_t dcmds[] = {
1316fcf3ce44SJohn Forte { "ports", "[-l]", "Leadville port list", ports },
1317fcf3ce44SJohn Forte { "ulps", NULL, "Leadville ULP list", ulps },
1318fcf3ce44SJohn Forte { "ulpmods", NULL, "Leadville ULP module list", ulpmods },
1319fcf3ce44SJohn Forte { "fcport", NULL, "Display a Leadville fc_local_port structure",
1320fcf3ce44SJohn Forte fcport },
1321fcf3ce44SJohn Forte { "remote_port", NULL, "Display fc_remote_port structures",
1322fcf3ce44SJohn Forte remote_port },
1323fcf3ce44SJohn Forte { "fcptrace", "[-s m][-e n] (m < n)", "Dump the fcp trace buffer, "
1324fcf3ce44SJohn Forte "optionally supplying starting and ending packet numbers.",
1325fcf3ce44SJohn Forte fcp_trace_dump, NULL },
1326fcf3ce44SJohn Forte { "fptrace", "[-s m][-e n] (m < n)", "Dump the fp trace buffer, "
1327fcf3ce44SJohn Forte "optionally supplying starting and ending packet numbers.",
1328fcf3ce44SJohn Forte fp_trace_dump, NULL },
1329fcf3ce44SJohn Forte { NULL }
1330fcf3ce44SJohn Forte };
1331fcf3ce44SJohn Forte
1332fcf3ce44SJohn Forte static const mdb_walker_t walkers[] = {
1333fcf3ce44SJohn Forte { "ports", "walk list of Leadville port structures",
1334fcf3ce44SJohn Forte port_walk_i, port_walk_s, port_walk_f },
1335fcf3ce44SJohn Forte { "ulps", "walk list of Leadville ULP structures",
1336fcf3ce44SJohn Forte ulp_walk_i, ulp_walk_s, ulp_walk_f },
1337fcf3ce44SJohn Forte { "ulpmods", "walk list of Leadville ULP module structures",
1338fcf3ce44SJohn Forte ulpmod_walk_i, ulpmod_walk_s, ulpmod_walk_f },
1339fcf3ce44SJohn Forte { "pd_by_pwwn", "walk list of fc_remote_port structures hashed by PWWN",
1340fcf3ce44SJohn Forte pd_by_pwwn_walk_i, pd_by_pwwn_walk_s, pd_by_pwwn_walk_f },
1341fcf3ce44SJohn Forte { "pd_by_did", "walk list of fc_remote_port structures hashed by D_ID",
1342fcf3ce44SJohn Forte pd_by_did_walk_i, pd_by_did_walk_s, pd_by_did_walk_f },
1343fcf3ce44SJohn Forte { "job_request", "walk list of job_request structures for a local port",
1344fcf3ce44SJohn Forte job_request_walk_i, job_request_walk_s, job_request_walk_f },
1345fcf3ce44SJohn Forte { "orphan", "walk list of orphan structures for a local port",
1346fcf3ce44SJohn Forte orphan_walk_i, orphan_walk_s, orphan_walk_f },
1347fcf3ce44SJohn Forte { NULL }
1348fcf3ce44SJohn Forte };
1349fcf3ce44SJohn Forte
1350fcf3ce44SJohn Forte static const mdb_modinfo_t modinfo = {
1351fcf3ce44SJohn Forte MDB_API_VERSION, dcmds, walkers
1352fcf3ce44SJohn Forte };
1353fcf3ce44SJohn Forte
1354fcf3ce44SJohn Forte const mdb_modinfo_t *
_mdb_init(void)1355fcf3ce44SJohn Forte _mdb_init(void)
1356fcf3ce44SJohn Forte {
1357fcf3ce44SJohn Forte return (&modinfo);
1358fcf3ce44SJohn Forte }
1359