summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/common/modules/fctl/fctl.c
blob: 26a2f948c836dc872b2d23388d6d23c2ae7371af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright 2019 Joyent, Inc.
 */

#include <sys/mdb_modapi.h>
#include <sys/mutex.h>
#include <sys/modctl.h>
#include <time.h>
#include <sys/fibre-channel/fc.h>
#include <sys/fibre-channel/impl/fctl_private.h>
#include <sys/fibre-channel/impl/fc_ulpif.h>
#include <sys/fibre-channel/impl/fc_portif.h>
#include <sys/fibre-channel/impl/fc_fcaif.h>


/*
 * If we #include <string.h> then other definitions fail. This is
 * the easiest way of getting access to the function
 */
extern char *strtok(char *string, const char *sepset);

/* we need 26 bytes for the cftime() call */
#define	TIMESTAMPSIZE	26 * sizeof (char)

/* for backward compatibility */
typedef struct fc_trace_dmsgv1 {
	int			id_size;
	int			id_flag;
	time_t			id_time;
	caddr_t			id_buf;
	struct fc_trace_dmsgv1	*id_next;
} fc_trace_dmsgv1_t;

static struct pwwn_hash *fp_pwwn_table;
static struct d_id_hash *fp_did_table;
static uint32_t pd_hash_index;
struct fc_local_port port;

/*
 * Leadville port walker/dcmd code
 */

/*
 * Initialize the fc_fca_port_t walker by either using the given starting
 * address, or reading the value of the kernel's fctl_fca_portlist pointer.
 * We also allocate a fc_fca_port_t for storage, and save this using the
 * walk_data pointer.
 */
static int
port_walk_i(mdb_walk_state_t *wsp)
{
	if (wsp->walk_addr == 0 &&
	    mdb_readvar(&wsp->walk_addr, "fctl_fca_portlist") == -1) {
		mdb_warn("failed to read 'fctl_fca_portlist'");
		return (WALK_ERR);
	}

	wsp->walk_data = mdb_alloc(sizeof (fc_fca_port_t), UM_SLEEP);
	return (WALK_NEXT);
}

/*
 * At each step, read a fc_fca_port_t into our private storage, and then invoke
 * the callback function.  We terminate when we reach a NULL p_next pointer.
 */
static int
port_walk_s(mdb_walk_state_t *wsp)
{
	int status;

	if (wsp->walk_addr == 0)
		return (WALK_DONE);

	if (mdb_vread(wsp->walk_data, sizeof (fc_fca_port_t), wsp->walk_addr)
	    == -1) {
		mdb_warn("failed to read fc_fca_port_t at %p", wsp->walk_addr);
		return (WALK_DONE);
	}

	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
	    wsp->walk_cbdata);

	wsp->walk_addr =
	    (uintptr_t)(((fc_fca_port_t *)wsp->walk_data)->port_next);

	return (status);
}

/*
 * The walker's fini function is invoked at the end of each walk.  Since we
 * dynamically allocated a fc_fca_port_t in port_walk_i, we must free it now.
 */
static void
port_walk_f(mdb_walk_state_t *wsp)
{
	mdb_free(wsp->walk_data, sizeof (fc_fca_port_t));
}


static int
ports(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	fc_fca_port_t	portlist;
	fc_local_port_t port;
	int		longlist = FALSE;

	if (argc > 1) {
		return (DCMD_USAGE);
	}

	if (mdb_getopts(argc, argv,
	    'l', MDB_OPT_SETBITS, TRUE, &longlist, NULL) != argc) {
		return (DCMD_USAGE);
	}


	if (!(flags & DCMD_ADDRSPEC)) {
		if (longlist == 0) {
			if (mdb_walk_dcmd("ports", "ports",
			    argc, argv) == -1) {
				mdb_warn("failed to walk 'fctl_fca_portlist'");
				return (DCMD_ERR);
			}
		} else {
			if (mdb_walk_dcmd("ports", "fcport",
			    argc, argv) == -1) {
				mdb_warn("failed to walk 'fctl_fca_portlist'");
				return (DCMD_ERR);
			}
		}

		return (DCMD_OK);
	}

	/*
	 * If this is the first invocation of the command, print a nice
	 * header line for the output that will follow.
	 */
	if (DCMD_HDRSPEC(flags))
		mdb_printf("%16s %-2s %4s %-4s%16s %16s %16s\n",
		    "Port", "I#", "State", "Soft", "FCA Handle",
		    "Port DIP", "FCA Port DIP");

	/*
	 * For each port, we just need to read the fc_fca_port_t struct, read
	 * the port_handle
	 */
	if (mdb_vread(&portlist, sizeof (fc_fca_port_t), addr) ==
	    sizeof (fc_fca_port_t)) {
		/*
		 * Now read that port in
		 */

		if (mdb_vread(&port, sizeof (fc_local_port_t), (uintptr_t)
		    portlist.port_handle) == sizeof (fc_local_port_t)) {
			mdb_printf("%16p %2d %4x %4x %16p %16p %16p\n",
			    portlist.port_handle, port.fp_instance,
			    port.fp_state, port.fp_soft_state,
			    port.fp_fca_handle, port.fp_port_dip,
			    port.fp_fca_dip);
		} else
			mdb_warn("failed to read port at %p",
			    portlist.port_handle);

	} else
		mdb_warn("failed to read port info at %p", addr);

	return (DCMD_OK);
}


/*
 * Leadville ULP walker/dcmd code
 */

static int
ulp_walk_i(mdb_walk_state_t *wsp)
{
	if (wsp->walk_addr == 0 &&
	    mdb_readvar(&wsp->walk_addr, "fctl_ulp_list") == -1) {
		mdb_warn("failed to read 'fctl_ulp_list'");
		return (WALK_ERR);
	}

	wsp->walk_data = mdb_alloc(sizeof (fc_ulp_list_t), UM_SLEEP);
	return (WALK_NEXT);
}



static int
ulp_walk_s(mdb_walk_state_t *wsp)
{
	int status;

	if (wsp->walk_addr == 0)
		return (WALK_DONE);

	if (mdb_vread(wsp->walk_data, sizeof (fc_ulp_list_t), wsp->walk_addr)
	    == -1) {
		mdb_warn("failed to read fctl_ulp_list %p", wsp->walk_addr);
		return (WALK_DONE);
	}

	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
	    wsp->walk_cbdata);

	wsp->walk_addr =
	    (uintptr_t)(((fc_ulp_list_t *)wsp->walk_data)->ulp_next);

	return (status);
}


static void
ulp_walk_f(mdb_walk_state_t *wsp)
{
	mdb_free(wsp->walk_data, sizeof (fc_ulp_list_t));
}


static int
ulps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	fc_ulp_list_t		ulplist;
	fc_ulp_modinfo_t	ulp;
	char			ulp_name[30];

	if (argc != 0) {
		return (DCMD_USAGE);
	}

	/*
	 * If no fc_ulp_list_t address was specified on the command line, we can
	 * print out all processes by invoking the walker, using this
	 * dcmd itself as the callback.
	 */
	if (!(flags & DCMD_ADDRSPEC)) {
		if (mdb_walk_dcmd("ulps", "ulps", argc, argv) == -1) {
			mdb_warn("failed to walk 'fc_ulp_list_t'");
			return (DCMD_ERR);
		}
		return (DCMD_OK);
	}

	/*
	 * If this is the first invocation of the command, print a nice
	 * header line for the output that will follow.
	 */
	if (DCMD_HDRSPEC(flags))
		mdb_printf("%30s %4s %8s\n", "ULP Name", "Type", "Revision");

	/*
	 * For each port, we just need to read the fc_fca_port_t struct, read
	 * the port_handle
	 */
	if (mdb_vread(&ulplist, sizeof (fc_ulp_list_t), addr) ==
	    sizeof (fc_ulp_list_t)) {
		/*
		 * Now read that port in
		 */

		if (mdb_vread(&ulp, sizeof (fc_ulp_modinfo_t),
		    (uintptr_t)ulplist.ulp_info) == sizeof (fc_ulp_modinfo_t)) {
			if (mdb_vread(&ulp_name, 30,
			    (uintptr_t)ulp.ulp_name) > 0) {
				mdb_printf("%30s %4x %8x\n",
				    ulp_name, ulp.ulp_type, ulp.ulp_rev);
			}
		} else
			mdb_warn("failed to read ulp at %p",
			    ulplist.ulp_info);

	} else
		mdb_warn("failed to read ulplist at %p", addr);

	return (DCMD_OK);
}



/*
 * Leadville ULP module walker/dcmd code
 */

static int
ulpmod_walk_i(mdb_walk_state_t *wsp)
{
	if (wsp->walk_addr == 0 &&
	    mdb_readvar(&wsp->walk_addr, "fctl_ulp_modules") == -1) {
		mdb_warn("failed to read 'fctl_ulp_modules'");
		return (WALK_ERR);
	}

	wsp->walk_data = mdb_alloc(sizeof (fc_ulp_module_t), UM_SLEEP);
	return (WALK_NEXT);
}



static int
ulpmod_walk_s(mdb_walk_state_t *wsp)
{
	int status;

	if (wsp->walk_addr == 0)
		return (WALK_DONE);

	if (mdb_vread(wsp->walk_data, sizeof (fc_ulp_module_t), wsp->walk_addr)
	    == -1) {
		mdb_warn("failed to read fctl_ulp_modules %p", wsp->walk_addr);
		return (WALK_DONE);
	}

	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
	    wsp->walk_cbdata);

	wsp->walk_addr =
	    (uintptr_t)(((fc_ulp_module_t *)wsp->walk_data)->mod_next);

	return (status);
}


static void
ulpmod_walk_f(mdb_walk_state_t *wsp)
{
	mdb_free(wsp->walk_data, sizeof (fc_ulp_module_t));
}


static int
ulpmods(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	fc_ulp_module_t		modlist;
	fc_ulp_modinfo_t	modinfo;
	fc_ulp_ports_t		ulp_port;

	if (argc != 0) {
		return (DCMD_USAGE);
	}

	if (!(flags & DCMD_ADDRSPEC)) {
		if (mdb_walk_dcmd("ulpmods", "ulpmods", argc, argv)
		    == -1) {
			mdb_warn("failed to walk 'fc_ulp_module_t'");
			return (DCMD_ERR);
		}
		return (DCMD_OK);
	}

	/*
	 * If this is the first invocation of the command, print a nice
	 * header line for the output that will follow.
	 */
	if (DCMD_HDRSPEC(flags))
		mdb_printf("%4s %16s %8s %8s\n",
		    "Type", "Port Handle", "dstate", "statec");

	/*
	 * For each port, we just need to read the fc_fca_port_t struct, read
	 * the port_handle
	 */
	if (mdb_vread(&modlist, sizeof (fc_ulp_module_t), addr) ==
	    sizeof (fc_ulp_module_t)) {
		/*
		 * Now read that module info in
		 */

		if (mdb_vread(&modinfo, sizeof (fc_ulp_modinfo_t),
		    (uintptr_t)modlist.mod_info) == sizeof (fc_ulp_modinfo_t)) {
			/* Now read all the ports for this module */
			if (mdb_vread(&ulp_port, sizeof (fc_ulp_ports_t),
			    (uintptr_t)modlist.mod_ports) ==
			    sizeof (fc_ulp_ports_t)) {
				while (ulp_port.port_handle != NULL) {
					mdb_printf("%4x %16p %8x %8x\n",
					    modinfo.ulp_type,
					    ulp_port.port_handle,
					    ulp_port.port_dstate,
					    ulp_port.port_statec);

					if (ulp_port.port_next == NULL)
						break;

					mdb_vread(&ulp_port,
					    sizeof (fc_ulp_ports_t),
					    (uintptr_t)ulp_port.port_next);
				}
			}
		} else
			mdb_warn("failed to read modinfo at %p",
			    modlist.mod_info);

	} else
		mdb_warn("failed to read modlist at %p", addr);

	return (DCMD_OK);
}


/*
 * Display an fc_local_port_t struct
 */
static int
fcport(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	fc_fca_port_t	portlist;
	fc_local_port_t	port;
	int		idx;
	int		first = 1;
	int		walking_fc_fca_portlist = 0;

	if (argc != 0) {
		int result;

		if (argc != 1)
			return (DCMD_USAGE);

		if (argv->a_type != MDB_TYPE_STRING)
			return (DCMD_USAGE);

		walking_fc_fca_portlist = 1;
	}

	if (!(flags & DCMD_ADDRSPEC)) {
		mdb_printf("Sorry, you must provide an address\n");
		return (DCMD_ERR);
	}

	if (walking_fc_fca_portlist) {
		/*
		 * Must read the fc_fca_portlist to get the fc_local_port addr
		 */
		if (mdb_vread(&portlist, sizeof (fc_fca_port_t), addr) ==
		    sizeof (fc_fca_port_t)) {
			addr = (uintptr_t)portlist.port_handle;
		}
	}

	mdb_printf("Reading fc_local_port_t at %p:\n", addr);

	/*
	 * For each port, we just need to read the fc_local_port_t struct
	 */

	if (mdb_vread(&port, sizeof (fc_local_port_t),
	    addr) == sizeof (fc_local_port_t)) {
		mdb_printf("  fp_mutex          : 0x%p\n", port.fp_mutex);
		mdb_printf("  fp_state          : 0x%-8x\n", port.fp_state);
		mdb_printf("  fp_port_id        : 0x%-06x\n",
		    port.fp_port_id.port_id);
		mdb_printf("  fp_fca_handle     : 0x%p\n", port.fp_fca_handle);
		mdb_printf("  fp_fca_tran       : 0x%p\n", port.fp_fca_tran);
		mdb_printf("  fp_job_head       : 0x%p\n", port.fp_job_head);
		mdb_printf("  fp_job_tail       : 0x%p\n", port.fp_job_tail);
		mdb_printf("  fp_wait_head      : 0x%p\n", port.fp_wait_head);
		mdb_printf("  fp_wait_tail      : 0x%p\n", port.fp_wait_tail);
		mdb_printf("  fp_topology       : %u\n", port.fp_topology);
		mdb_printf("  fp_task           : %d\n", port.fp_task);
		mdb_printf("  fp_last_task      : %d\n", port.fp_last_task);
		mdb_printf("  fp_soft_state     : 0x%-4x\n",
		    port.fp_soft_state);
		mdb_printf("  fp_flag           : 0x%-2x\n", port.fp_flag);
		mdb_printf("  fp_statec_busy    : 0x%-8x\n",
		    port.fp_statec_busy);
		mdb_printf("  fp_port_num       : %d\n", port.fp_port_num);
		mdb_printf("  fp_instance       : %d\n", port.fp_instance);
		mdb_printf("  fp_ulp_attach     : %d\n", port.fp_ulp_attach);
		mdb_printf("  fp_dev_count      : %d\n", port.fp_dev_count);
		mdb_printf("  fp_total_devices  : %d\n", port.fp_total_devices);
		mdb_printf("  fp_bind_state     : 0x%-8x\n",
		    port.fp_bind_state);
		mdb_printf("  fp_options        : 0x%-8x\n", port.fp_options);
		mdb_printf("  fp_port_type      : 0x%-2x\n",
		    port.fp_port_type.port_type);
		mdb_printf("  fp_ub_count       : %d\n", port.fp_ub_count);
		mdb_printf("  fp_active_ubs     : %d\n", port.fp_active_ubs);
		mdb_printf("  fp_port_dip       : 0x%p\n", port.fp_port_dip);
		mdb_printf("  fp_fca_dip        : 0x%p\n", port.fp_fca_dip);

		for (idx = 0; idx < 16; idx++) {
			if (port.fp_ip_addr[idx] != 0)
				break;
		}

		if (idx != 16) {
			mdb_printf("  fp_ip_addr        : %-2x:%-2x:%-2x:%-2x:"
			    "%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x:%-2x"
			    ":%-2x:%-2x\n",
			    port.fp_ip_addr[0], port.fp_ip_addr[1],
			    port.fp_ip_addr[2], port.fp_ip_addr[3],
			    port.fp_ip_addr[4], port.fp_ip_addr[5],
			    port.fp_ip_addr[6], port.fp_ip_addr[7],
			    port.fp_ip_addr[8], port.fp_ip_addr[9],
			    port.fp_ip_addr[10], port.fp_ip_addr[11],
			    port.fp_ip_addr[12], port.fp_ip_addr[13],
			    port.fp_ip_addr[14], port.fp_ip_addr[15]);
		} else {
			mdb_printf("  fp_ip_addr        : N/A\n");
		}

		mdb_printf("  fp_fc4_types      : ");

		for (idx = 0; idx < 8; idx++) {
			if (port.fp_fc4_types[idx] != 0) {
				if (first) {
					mdb_printf("%d",
					    port.fp_fc4_types[idx]);
					first = 0;
				} else {
					mdb_printf(", %d",
					    port.fp_fc4_types[idx]);
				}
			}
		}

		if (first) {
			mdb_printf("None\n");
		} else {
			mdb_printf("\n");
		}

		mdb_printf("  fp_pm_level       : %d\n", port.fp_pm_level);
		mdb_printf("  fp_pm_busy        : %d\n", port.fp_pm_busy);
		mdb_printf("  fp_pm_busy_nocomp : 0x%-8x\n",
		    port.fp_pm_busy_nocomp);
		mdb_printf("  fp_hard_addr      : 0x%-6x\n",
		    port.fp_hard_addr.hard_addr);
		mdb_printf("  fp_sym_port_name  : \"%s\"\n",
		    port.fp_sym_port_name);
		mdb_printf("  fp_sym_node_name  : \"%s\"\n",
		    port.fp_sym_node_name);
		mdb_printf("  fp_rscn_count     : %d\n", port.fp_rscn_count);
	} else {
		mdb_warn("failed to read fc_local_port_t at 0x%p", addr);
	}

	mdb_printf("\n");

	return (DCMD_OK);
}


/*
 * Leadville remote_port walker/dcmd code
 */

/*
 * We need to be given the address of a port structure in order to start
 * walking.  From that, we can read the pwwn table.
 */
static int
pd_by_pwwn_walk_i(mdb_walk_state_t *wsp)
{
	fc_local_port_t port;

	if (wsp->walk_addr == 0) {
		mdb_warn("pd_by_pwwn walk doesn't support global walks\n");
		return (WALK_ERR);
	}

	/*
	 * Allocate space for the pwwn_hash table
	 */

	fp_pwwn_table = mdb_alloc(sizeof (struct pwwn_hash) *
	    PWWN_HASH_TABLE_SIZE, UM_SLEEP);

	/*
	 * Input should be an fc_local_port_t, so read it to get the pwwn
	 * table's head
	 */

	if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
	    sizeof (fc_local_port_t)) {
		mdb_warn("Unable to read in the port structure address\n");
		return (WALK_ERR);
	}

	if (mdb_vread(fp_pwwn_table, sizeof (struct pwwn_hash) *
	    PWWN_HASH_TABLE_SIZE, (uintptr_t)port.fp_pwwn_table) == -1) {
		mdb_warn("Unable to read in the pwwn hash table\n");
		return (WALK_ERR);
	}

	pd_hash_index = 0;

	while ((fp_pwwn_table[pd_hash_index].pwwn_head == NULL) &&
	    (pd_hash_index < PWWN_HASH_TABLE_SIZE)) {
		pd_hash_index++;
	}

	wsp->walk_addr = (uintptr_t)fp_pwwn_table[pd_hash_index].pwwn_head;

	wsp->walk_data = mdb_alloc(sizeof (fc_remote_port_t), UM_SLEEP);
	return (WALK_NEXT);
}

/*
 * At each step, read a fc_remote_port_t into our private storage, and then
 * invoke the callback function.  We terminate when we reach a NULL p_next
 * pointer.
 */
static int
pd_by_pwwn_walk_s(mdb_walk_state_t *wsp)
{
	int status;

	if ((wsp->walk_addr == 0) &&
	    (pd_hash_index >= (PWWN_HASH_TABLE_SIZE - 1))) {
		return (WALK_DONE);
	}

	if (mdb_vread(wsp->walk_data, sizeof (fc_remote_port_t), wsp->walk_addr)
	    == -1) {
		mdb_warn("failed to read fc_remote_port at %p", wsp->walk_addr);
		return (WALK_DONE);
	}

	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
	    wsp->walk_cbdata);

	wsp->walk_addr =
	    (uintptr_t)(((fc_remote_port_t *)wsp->walk_data)->pd_wwn_hnext);

	if (wsp->walk_addr == 0) {
		/*
		 * Try the next hash list, if there is one.
		 */

		pd_hash_index++;

		while ((fp_pwwn_table[pd_hash_index].pwwn_head == NULL) &&
		    (pd_hash_index < PWWN_HASH_TABLE_SIZE)) {
			pd_hash_index++;
		}

		if (pd_hash_index == PWWN_HASH_TABLE_SIZE) {
			/* We're done */
			return (status);
		}

		wsp->walk_addr =
		    (uintptr_t)fp_pwwn_table[pd_hash_index].pwwn_head;
	}

	return (status);
}

/*
 * The walker's fini function is invoked at the end of each walk.
 */
static void
pd_by_pwwn_walk_f(mdb_walk_state_t *wsp)
{
	mdb_free(wsp->walk_data, sizeof (fc_remote_port_t));
	mdb_free(fp_pwwn_table, sizeof (struct pwwn_hash) *
	    PWWN_HASH_TABLE_SIZE);
	fp_pwwn_table = NULL;
}

/*
 * This is the same walker as pd_by_pwwn, but we walk the D_ID hash table
 */

static int
pd_by_did_walk_i(mdb_walk_state_t *wsp)
{
	fc_local_port_t port;

	if (wsp->walk_addr == 0) {
		mdb_warn("pd_by_did walk doesn't support global walks\n");
		return (WALK_ERR);
	}

	/*
	 * Allocate space for the did_hash table
	 */

	fp_did_table = mdb_alloc(sizeof (struct d_id_hash) *
	    D_ID_HASH_TABLE_SIZE, UM_SLEEP);

	/*
	 * Input should be an fc_local_port_t, so read it to get the d_id
	 * table's head
	 */

	if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
	    sizeof (fc_local_port_t)) {
		mdb_warn("Unable to read in the port structure address\n");
		return (WALK_ERR);
	}

	if (mdb_vread(fp_did_table, sizeof (struct d_id_hash) *
	    D_ID_HASH_TABLE_SIZE, (uintptr_t)port.fp_did_table) == -1) {
		mdb_warn("Unable to read in the D_ID hash table\n");
		return (WALK_ERR);
	}
	pd_hash_index = 0;

	while ((fp_did_table[pd_hash_index].d_id_head == NULL) &&
	    (pd_hash_index < D_ID_HASH_TABLE_SIZE)) {
		pd_hash_index++;
	}

	wsp->walk_addr = (uintptr_t)fp_did_table[pd_hash_index].d_id_head;

	wsp->walk_data = mdb_alloc(sizeof (fc_remote_port_t), UM_SLEEP);
	return (WALK_NEXT);
}

/*
 * At each step, read a fc_remote_port_t into our private storage, and then
 * invoke the callback function.  We terminate when we reach a NULL p_next
 * pointer.
 */
static int
pd_by_did_walk_s(mdb_walk_state_t *wsp)
{
	int status;

	if ((wsp->walk_addr == 0) &&
	    (pd_hash_index >= (D_ID_HASH_TABLE_SIZE - 1))) {
		return (WALK_DONE);
	}

	if (mdb_vread(wsp->walk_data, sizeof (fc_remote_port_t), wsp->walk_addr)
	    == -1) {
		mdb_warn("failed to read fc_remote_port at %p", wsp->walk_addr);
		return (WALK_DONE);
	}

	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
	    wsp->walk_cbdata);

	wsp->walk_addr =
	    (uintptr_t)(((fc_remote_port_t *)wsp->walk_data)->pd_did_hnext);

	if (wsp->walk_addr == 0) {
		/*
		 * Try the next hash list, if there is one.
		 */

		pd_hash_index++;

		while ((fp_did_table[pd_hash_index].d_id_head == NULL) &&
		    (pd_hash_index < D_ID_HASH_TABLE_SIZE)) {
			pd_hash_index++;
		}

		if (pd_hash_index == D_ID_HASH_TABLE_SIZE) {
			/* We're done */
			return (status);
		}

		wsp->walk_addr =
		    (uintptr_t)fp_did_table[pd_hash_index].d_id_head;
	}

	return (status);
}

/*
 * The walker's fini function is invoked at the end of each walk.
 */
static void
pd_by_did_walk_f(mdb_walk_state_t *wsp)
{
	mdb_free(wsp->walk_data, sizeof (fc_remote_port_t));
	mdb_free(fp_did_table, sizeof (struct d_id_hash) *
	    D_ID_HASH_TABLE_SIZE);
	fp_did_table = NULL;
}


/*
 * Display a remote_port structure
 */
static int
remote_port(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	fc_remote_port_t	pd;
	int			idx;
	int			first = 1;

	if (argc > 0) {
		return (DCMD_USAGE);
	}

	if (!(flags & DCMD_ADDRSPEC)) {
		mdb_printf("Sorry, you must provide an address\n");
		return (DCMD_ERR);
	}

	if (mdb_vread(&pd, sizeof (fc_remote_port_t), addr) !=
	    sizeof (fc_remote_port_t)) {
		mdb_warn("Error reading pd at 0x%x\n", addr);
		return (DCMD_ERR);
	}

	mdb_printf("Reading remote_port at 0x%p\n", addr);
	mdb_printf("  mutex          : 0x%p\n", pd.pd_mutex);
	mdb_printf("  port_id        : 0x%-8x\n", pd.pd_port_id);
	mdb_printf("  port_name      : 0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
	    pd.pd_port_name.raw_wwn[0], pd.pd_port_name.raw_wwn[1],
	    pd.pd_port_name.raw_wwn[2], pd.pd_port_name.raw_wwn[3],
	    pd.pd_port_name.raw_wwn[4], pd.pd_port_name.raw_wwn[5],
	    pd.pd_port_name.raw_wwn[6], pd.pd_port_name.raw_wwn[7]);
	mdb_printf("  login_count    : %d\n", pd.pd_login_count);
	mdb_printf("  state          : 0x%x ", pd.pd_state);

	switch (pd.pd_state) {
	case PORT_DEVICE_INVALID:
		mdb_printf("(invalid)\n");
		break;
	case PORT_DEVICE_VALID:
		mdb_printf("(valid)\n");
		break;
	case PORT_DEVICE_LOGGED_IN:
		mdb_printf("(logged in)\n");
		break;
	default:
		mdb_printf("(Unknown state)\n");
	}

	mdb_printf("  remote node    : 0x%p\n", pd.pd_remote_nodep);
	mdb_printf("  hard_addr      : 0x%x\n", pd.pd_hard_addr);
	mdb_printf("  local port     : 0x%p\n", pd.pd_port);
	mdb_printf("  type           : %d ", pd.pd_type);

	switch (pd.pd_type) {
	case PORT_DEVICE_NOCHANGE:
		mdb_printf("(No change)\n");
		break;
	case PORT_DEVICE_NEW:
		mdb_printf("(New)\n");
		break;
	case PORT_DEVICE_OLD:
		mdb_printf("(Old)\n");
		break;
	case PORT_DEVICE_CHANGED:
		mdb_printf("(Changed)\n");
		break;
	case PORT_DEVICE_DELETE:
		mdb_printf("(Delete)\n");
		break;
	case PORT_DEVICE_USER_LOGIN:
		mdb_printf("(User login)\n");
		break;
	case PORT_DEVICE_USER_LOGOUT:
		mdb_printf("(User logout)\n");
		break;
	case PORT_DEVICE_USER_CREATE:
		mdb_printf("(User create)\n");
		break;
	case PORT_DEVICE_USER_DELETE:
		mdb_printf("(User delete)\n");
		break;
	default:
		mdb_printf("(Unknown type)\n");
	}

	mdb_printf("  flags          : 0x%x ", pd.pd_flags);

	switch (pd.pd_flags) {
	case PD_IDLE:
		mdb_printf("(Idle)\n");
		break;
	case PD_ELS_IN_PROGRESS:
		mdb_printf("(ELS in progress)\n");
		break;
	case PD_ELS_MARK:
		mdb_printf("(Mark)\n");
		break;
	default:
		mdb_printf("(Unknown flag value)\n");
	}

	mdb_printf("  login_class    : 0x%x\n", pd.pd_login_class);
	mdb_printf("  recipient      : %d\n", pd.pd_recepient);
	mdb_printf("  ref_count      : %d\n", pd.pd_ref_count);
	mdb_printf("  aux_flags      : 0x%x ", pd.pd_aux_flags);

	first = 1;
	if (pd.pd_aux_flags & PD_IN_DID_QUEUE) {
		mdb_printf("(IN_DID_QUEUE");
		first = 0;
	}

	if (pd.pd_aux_flags & PD_DISABLE_RELOGIN) {
		if (first) {
			mdb_printf("(DISABLE_RELOGIN");
		} else {
			mdb_printf(", DISABLE_RELOGIN");
		}
		first = 0;
	}

	if (pd.pd_aux_flags & PD_NEEDS_REMOVAL) {
		if (first) {
			mdb_printf("(NEEDS_REMOVAL");
		} else {
			mdb_printf(", NEEDS_REMOVAL");
		}
		first = 0;
	}

	if (pd.pd_aux_flags & PD_LOGGED_OUT) {
		if (first) {
			mdb_printf("(LOGGED_OUT");
		} else {
			mdb_printf(", LOGGED_OUT");
		}
		first = 0;
	}

	if (pd.pd_aux_flags & PD_GIVEN_TO_ULPS) {
		if (first) {
			mdb_printf("(GIVEN_TO_ULPS");
		} else {
			mdb_printf(", GIVEN_TO_ULPS");
		}
		first = 0;
	}

	if (first == 0) {
		mdb_printf(")\n");
	} else {
		mdb_printf("\n");
	}

	mdb_printf("  sig            : %p\n", pd.pd_logo_tc.sig);
	mdb_printf("  active         : %d\n", pd.pd_logo_tc.active);
	mdb_printf("  counter        : %d\n", pd.pd_logo_tc.counter);
	mdb_printf("  max_value      : %d\n", pd.pd_logo_tc.max_value);
	mdb_printf("  timer          : %d\n", pd.pd_logo_tc.timer);
	mdb_printf("\n");

	return (DCMD_OK);
}

int
fc_dump_logmsg(fc_trace_dmsg_t *addr, uint_t pktstart, uint_t pktend,
    uint_t *printed)
{
	fc_trace_dmsg_t	msg;
	caddr_t		buf;
	char		merge[1024];
	caddr_t		tmppkt;
	char		*tmpbuf; /* for tokenising the buffer */
	uint_t		pktnum = 0;

	while (addr != NULL) {
		if (mdb_vread(&msg, sizeof (msg), (uintptr_t)addr) !=
		    sizeof (msg)) {
			mdb_warn("failed to read message pointer in kernel");
			return (DCMD_ERR);
		}

		if (msg.id_size) {

			buf = mdb_alloc(msg.id_size + 1, UM_SLEEP);
			tmppkt = mdb_alloc(msg.id_size + 1, UM_SLEEP);

			if (mdb_vread(buf, msg.id_size,
			    (uintptr_t)msg.id_buf) != msg.id_size) {
				mdb_warn("failed to read buffer contents"
				    " in kernel");
				mdb_free(buf, msg.id_size + 1);
				return (DCMD_ERR);
			}

			if (buf[0] == '\n') {
				mdb_printf("There is a problem in"
				    "the buffer\n");
			}
			/* funky packet processing stuff */
			bcopy(buf, tmppkt, msg.id_size + 1);

			/* find the equals sign, and put a null there */
			tmpbuf = strchr(tmppkt, '=');
			*tmpbuf = 0;
			pktnum = (uint_t)mdb_strtoull(tmppkt);

			if ((pktnum >= pktstart) && (pktnum <= pktend)) {
				(void) mdb_snprintf(merge, sizeof (merge),
				    "[%Y:%03d:%03d:%03d] %s",
				    msg.id_time.tv_sec,
				    (int)msg.id_time.tv_nsec/1000000,
				    (int)(msg.id_time.tv_nsec/1000)%1000,
				    (int)msg.id_time.tv_nsec%1000, buf);
				mdb_printf("%s", merge);
				if (printed != NULL)
					(*printed) ++;
			}
			mdb_free(buf, msg.id_size + 1);
			mdb_free(tmppkt, msg.id_size + 1);
		}
		addr = msg.id_next;
	}

	return (DCMD_OK);
}

int
fc_dump_old_logmsg(fc_trace_dmsgv1_t *addr, uint_t pktstart, uint_t pktend,
    uint_t *printed)
{
	fc_trace_dmsgv1_t	msg;
	caddr_t			buf;
	char			merge[1024];
	caddr_t			tmppkt;
	char			*tmpbuf; /* for tokenising the buffer */
	uint_t			pktnum = 0;

	while (addr != NULL) {
		if (mdb_vread(&msg, sizeof (msg), (uintptr_t)addr) !=
		    sizeof (msg)) {
			mdb_warn("failed to read message pointer in kernel");
			return (DCMD_ERR);
		}

		if (msg.id_size) {

			buf = mdb_alloc(msg.id_size + 1, UM_SLEEP);
			tmppkt = mdb_alloc(msg.id_size + 1, UM_SLEEP);

			if (mdb_vread(buf, msg.id_size,
			    (uintptr_t)msg.id_buf) != msg.id_size) {
				mdb_warn("failed to read buffer contents"
				    " in kernel");
				mdb_free(buf, msg.id_size + 1);
				return (DCMD_ERR);
			}

			if (buf[0] == '\n') {
				mdb_printf("There is a problem in"
				    "the buffer\n");
			}
			/* funky packet processing stuff */
			bcopy(buf, tmppkt, msg.id_size + 1);

			tmpbuf = strchr(tmppkt, '=');
			*tmpbuf = 0;
			pktnum = (uint_t)mdb_strtoull(tmppkt);

			if ((pktnum >= pktstart) && (pktnum <= pktend)) {
				(void) mdb_snprintf(merge, sizeof (merge),
				    "[%Y] %s", msg.id_time, buf);
				mdb_printf("%s", merge);
				if (printed != NULL)
					(*printed) ++;
			}
			mdb_free(buf, msg.id_size + 1);
			mdb_free(tmppkt, msg.id_size + 1);
		}
		addr = msg.id_next;
	}

	return (DCMD_OK);
}

int
fc_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	fc_trace_logq_t logq;
	uint_t		pktnum = 0;
	uint_t		printed = 0; /* have we printed anything? */

	uintptr_t	pktstart = 0;
	uintptr_t	pktend = UINT_MAX;
	int		rval = DCMD_OK;

	if (mdb_vread(&logq, sizeof (logq), addr) != sizeof (logq)) {
		mdb_warn("Failed to read log queue in kernel");
		return (DCMD_ERR);
	}

	if (mdb_getopts(argc, argv,
	    's', MDB_OPT_UINTPTR, &pktstart,
	    'e', MDB_OPT_UINTPTR, &pktend,
	    NULL) != argc) {
		return (DCMD_USAGE);
	}

	if (pktstart > pktend) {
		return (DCMD_USAGE);
	}

	if ((logq.il_flags & FC_TRACE_LOGQ_V2) != 0) {
		rval = fc_dump_logmsg((fc_trace_dmsg_t *)logq.il_msgh, pktstart,
		    pktend, &printed);
	} else {
		rval = fc_dump_old_logmsg((fc_trace_dmsgv1_t *)logq.il_msgh,
		    pktstart, pktend, &printed);
	}

	if (rval != DCMD_OK) {
		return (rval);
	}

	if (printed == 0) {
		mdb_printf("No packets in the buffer match the"
		    " criteria given");
	}

	return (rval);
}

int
fp_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	if (mdb_readvar(&addr, "fp_logq") == -1) {
		mdb_warn("failed to read fp_logq");
		return (DCMD_ERR);
	}

	if (DCMD_HDRSPEC(flags)) {
		mdb_printf("fp trace buffer contents\n");
	}

	return (fc_trace_dump(addr, flags, argc, argv));
}


int
fcp_trace_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	if (mdb_readvar(&addr, "fcp_logq") == -1) {
		mdb_warn("failed to read fcp_logq");
		return (DCMD_ERR);
	}

	if (DCMD_HDRSPEC(flags)) {
		mdb_printf("fcp trace buffer contents\n");
	}

	return (fc_trace_dump(addr, flags, argc, argv));
}

/*
 * Leadville job_request walker/dcmd code
 */

/*
 * We need to be given the address of a local port structure in order to start
 * walking.  From that, we can read the job_request list.
 */

static int
job_request_walk_i(mdb_walk_state_t *wsp)
{
	if (wsp->walk_addr == 0) {
		mdb_warn("The address of a fc_local_port"
		    " structure must be given\n");
		return (WALK_ERR);
	}

	/*
	 * Input should be a fc_local_port_t, so read it to get the job_request
	 * lists's head
	 */

	if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
	    sizeof (fc_local_port_t)) {
		mdb_warn("Failed to read in the fc_local_port"
		    " at 0x%p\n", wsp->walk_addr);
		return (WALK_ERR);
	}

	wsp->walk_addr = (uintptr_t)(port.fp_job_head);
	wsp->walk_data = mdb_alloc(sizeof (struct job_request), UM_SLEEP);

	return (WALK_NEXT);
}

static int
job_request_walk_s(mdb_walk_state_t *wsp)
{
	int status;

	if (wsp->walk_addr == 0)
		return (WALK_DONE);

	if (mdb_vread(wsp->walk_data, sizeof (struct job_request),
	    wsp->walk_addr) == -1) {
		mdb_warn("Failed to read in the job_request at 0x%p\n",
		    wsp->walk_addr);
		return (WALK_DONE);
	}

	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
	    wsp->walk_cbdata);

	wsp->walk_addr =
	    (uintptr_t)(((struct job_request *)wsp->walk_data)->job_next);

	return (status);
}

/*
 * The walker's fini function is invoked at the end of each walk.
 */
static void
job_request_walk_f(mdb_walk_state_t *wsp)
{
	mdb_free(wsp->walk_data, sizeof (struct job_request));
}


/*
 * Leadville fc_orphan walker/dcmd code
 */

/*
 * We need to be given the address of a port structure in order to start
 * walking.  From that, we can read the orphan list.
 */

static int
orphan_walk_i(mdb_walk_state_t *wsp)
{
	if (wsp->walk_addr == 0) {
		mdb_warn("The address of a fc_local_port"
		    " structure must be given\n");
		return (WALK_ERR);
	}

	/*
	 * Input should be a fc_local_port_t, so read it to get the orphan
	 * lists's head
	 */

	if (mdb_vread(&port, sizeof (fc_local_port_t), wsp->walk_addr) !=
	    sizeof (fc_local_port_t)) {
		mdb_warn("Failed to read in the fc_local_port"
		    " at 0x%p\n", wsp->walk_addr);
		return (WALK_ERR);
	}

	wsp->walk_addr = (uintptr_t)(port.fp_orphan_list);
	wsp->walk_data = mdb_alloc(sizeof (struct fc_orphan), UM_SLEEP);

	return (WALK_NEXT);
}

static int
orphan_walk_s(mdb_walk_state_t *wsp)
{
	int status;

	if (wsp->walk_addr == 0)
		return (WALK_DONE);

	if (mdb_vread(wsp->walk_data, sizeof (struct fc_orphan),
	    wsp->walk_addr) == -1) {
		mdb_warn("Failed to read in the fc_orphan at 0x%p\n",
		    wsp->walk_addr);
		return (WALK_DONE);
	}

	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
	    wsp->walk_cbdata);

	wsp->walk_addr =
	    (uintptr_t)(((struct fc_orphan *)wsp->walk_data)->orp_next);

	return (status);
}

/*
 * The walker's fini function is invoked at the end of each walk.
 */
static void
orphan_walk_f(mdb_walk_state_t *wsp)
{
	mdb_free(wsp->walk_data, sizeof (struct fc_orphan));
}


/*
 * MDB module linkage information:
 *
 * We declare a list of structures describing our dcmds, a list of structures
 * describing our walkers, and a function named _mdb_init to return a pointer
 * to our module information.
 */

static const mdb_dcmd_t dcmds[] = {
	{ "ports", "[-l]", "Leadville port list", ports },
	{ "ulps", NULL, "Leadville ULP list", ulps },
	{ "ulpmods", NULL, "Leadville ULP module list", ulpmods },
	{ "fcport", NULL, "Display a Leadville fc_local_port structure",
	    fcport },
	{ "remote_port", NULL, "Display fc_remote_port structures",
	    remote_port },
	{ "fcptrace", "[-s m][-e n] (m < n)", "Dump the fcp trace buffer, "
	    "optionally supplying starting and ending packet numbers.",
	    fcp_trace_dump, NULL },
	{ "fptrace", "[-s m][-e n] (m < n)", "Dump the fp trace buffer, "
	    "optionally supplying starting and ending packet numbers.",
	    fp_trace_dump, NULL },
	{ NULL }
};

static const mdb_walker_t walkers[] = {
	{ "ports", "walk list of Leadville port structures",
	    port_walk_i, port_walk_s, port_walk_f },
	{ "ulps", "walk list of Leadville ULP structures",
	    ulp_walk_i, ulp_walk_s, ulp_walk_f },
	{ "ulpmods", "walk list of Leadville ULP module structures",
	    ulpmod_walk_i, ulpmod_walk_s, ulpmod_walk_f },
	{ "pd_by_pwwn", "walk list of fc_remote_port structures hashed by PWWN",
	    pd_by_pwwn_walk_i, pd_by_pwwn_walk_s, pd_by_pwwn_walk_f },
	{ "pd_by_did", "walk list of fc_remote_port structures hashed by D_ID",
	    pd_by_did_walk_i, pd_by_did_walk_s, pd_by_did_walk_f },
	{ "job_request", "walk list of job_request structures for a local port",
	    job_request_walk_i, job_request_walk_s, job_request_walk_f },
	{ "orphan", "walk list of orphan structures for a local port",
	    orphan_walk_i, orphan_walk_s, orphan_walk_f },
	{ NULL }
};

static const mdb_modinfo_t modinfo = {
	MDB_API_VERSION, dcmds, walkers
};

const mdb_modinfo_t *
_mdb_init(void)
{
	return (&modinfo);
}