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