dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / pmcs / pmcs.c
blob5e3cfd1f0675ed311d3aeeaca0202d336676f8da
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Milan Jurik. All rights reserved.
26 #include <limits.h>
27 #include <sys/mdb_modapi.h>
28 #include <mdb/mdb_ctf.h>
29 #include <sys/sysinfo.h>
30 #include <sys/byteorder.h>
31 #include <sys/nvpair.h>
32 #include <sys/damap.h>
33 #include <sys/scsi/scsi.h>
34 #include <sys/scsi/adapters/pmcs/pmcs.h>
35 #ifndef _KMDB
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <fcntl.h>
39 #include <unistd.h>
40 #endif /* _KMDB */
43 * We need use this to pass the settings when display_iport
45 typedef struct per_iport_setting {
46 uint_t pis_damap_info; /* -m: DAM/damap */
47 uint_t pis_dtc_info; /* -d: device tree children: dev_info/path_info */
48 } per_iport_setting_t;
51 * This structure is used for sorting work structures by the wserno
53 typedef struct wserno_list {
54 int serno;
55 int idx;
56 struct wserno_list *next;
57 struct wserno_list *prev;
58 } wserno_list_t;
60 #define MDB_RD(a, b, c) mdb_vread(a, b, (uintptr_t)c)
61 #define NOREAD(a, b) mdb_warn("could not read " #a " at 0x%p", b)
63 static pmcs_hw_t ss;
64 static pmcs_xscsi_t **targets = NULL;
65 static int target_idx;
67 static uint32_t sas_phys, sata_phys, exp_phys, num_expanders, empty_phys;
69 static pmcs_phy_t *pmcs_next_sibling(pmcs_phy_t *phyp);
70 static void display_one_work(pmcwork_t *wp, int verbose, int idx);
72 static void
73 print_sas_address(pmcs_phy_t *phy)
75 int idx;
77 for (idx = 0; idx < 8; idx++) {
78 mdb_printf("%02x", phy->sas_address[idx]);
82 static void
83 pmcs_fwtime_to_systime(struct pmcs_hw ss, uint32_t fw_hi, uint32_t fw_lo,
84 struct timespec *stime)
86 uint64_t fwtime;
87 time_t secs;
88 long nsecs;
89 boolean_t backward_time = B_FALSE;
91 fwtime = ((uint64_t)fw_hi << 32) | fw_lo;
94 * If fwtime < ss.fw_timestamp, then we need to adjust the clock
95 * time backwards from ss.sys_timestamp. Otherwise, the adjustment
96 * goes forward in time
98 if (fwtime >= ss.fw_timestamp) {
99 fwtime -= ss.fw_timestamp;
100 } else {
101 fwtime = ss.fw_timestamp - fwtime;
102 backward_time = B_TRUE;
105 secs = ((time_t)fwtime / NSECS_PER_SEC);
106 nsecs = ((long)fwtime % NSECS_PER_SEC);
108 stime->tv_sec = ss.sys_timestamp.tv_sec;
109 stime->tv_nsec = ss.sys_timestamp.tv_nsec;
111 if (backward_time) {
112 if (stime->tv_nsec < nsecs) {
113 stime->tv_sec--;
114 stime->tv_nsec = stime->tv_nsec + NSECS_PER_SEC - nsecs;
115 } else {
116 stime->tv_nsec -= nsecs;
118 stime->tv_sec -= secs;
119 } else {
120 if (stime->tv_nsec + nsecs > NSECS_PER_SEC) {
121 stime->tv_sec++;
123 stime->tv_nsec = (stime->tv_nsec + nsecs) % NSECS_PER_SEC;
124 stime->tv_sec += secs;
128 /*ARGSUSED*/
129 static void
130 display_ic(struct pmcs_hw m, int verbose)
132 int msec_per_tick;
134 if (mdb_readvar(&msec_per_tick, "msec_per_tick") == -1) {
135 mdb_warn("can't read msec_per_tick");
136 msec_per_tick = 0;
139 mdb_printf("\n");
140 mdb_printf("Interrupt coalescing timer info\n");
141 mdb_printf("-------------------------------\n");
142 if (msec_per_tick == 0) {
143 mdb_printf("Quantum : ?? ms\n");
144 } else {
145 mdb_printf("Quantum : %d ms\n",
146 m.io_intr_coal.quantum * msec_per_tick);
148 mdb_printf("Timer enabled : ");
149 if (m.io_intr_coal.timer_on) {
150 mdb_printf("Yes\n");
151 mdb_printf("Coalescing timer value : %d us\n",
152 m.io_intr_coal.intr_coal_timer);
153 } else {
154 mdb_printf("No\n");
156 mdb_printf("Total nsecs between interrupts: %ld\n",
157 m.io_intr_coal.nsecs_between_intrs);
158 mdb_printf("Time of last I/O interrupt : %ld\n",
159 m.io_intr_coal.last_io_comp);
160 mdb_printf("Number of I/O interrupts : %d\n",
161 m.io_intr_coal.num_intrs);
162 mdb_printf("Number of I/O completions : %d\n",
163 m.io_intr_coal.num_io_completions);
164 mdb_printf("Max I/O completion interrupts : %d\n",
165 m.io_intr_coal.max_io_completions);
166 mdb_printf("Measured ECHO int latency : %d ns\n",
167 m.io_intr_coal.intr_latency);
168 mdb_printf("Interrupt threshold : %d\n",
169 m.io_intr_coal.intr_threshold);
172 /*ARGSUSED*/
173 static int
174 pmcs_iport_phy_walk_cb(uintptr_t addr, const void *wdata, void *priv)
176 struct pmcs_phy phy;
178 if (mdb_vread(&phy, sizeof (struct pmcs_phy), addr) !=
179 sizeof (struct pmcs_phy)) {
180 return (DCMD_ERR);
183 mdb_printf("%16p %2d\n", addr, phy.phynum);
185 return (0);
188 static int
189 display_iport_damap(dev_info_t *pdip)
191 int rval = DCMD_ERR;
192 struct dev_info dip;
193 scsi_hba_tran_t sht;
194 mdb_ctf_id_t istm_ctfid; /* impl_scsi_tgtmap_t ctf_id */
195 ulong_t tmd_offset = 0; /* tgtmap_dam offset to impl_scsi_tgtmap_t */
196 uintptr_t dam0;
197 uintptr_t dam1;
199 if (mdb_vread(&dip, sizeof (struct dev_info), (uintptr_t)pdip) !=
200 sizeof (struct dev_info)) {
201 return (rval);
204 if (dip.devi_driver_data == NULL) {
205 return (rval);
208 if (mdb_vread(&sht, sizeof (scsi_hba_tran_t),
209 (uintptr_t)dip.devi_driver_data) != sizeof (scsi_hba_tran_t)) {
210 return (rval);
213 if (sht.tran_tgtmap == NULL) {
214 return (rval);
217 if (mdb_ctf_lookup_by_name("impl_scsi_tgtmap_t", &istm_ctfid) != 0) {
218 return (rval);
221 if (mdb_ctf_offsetof(istm_ctfid, "tgtmap_dam", &tmd_offset) != 0) {
222 return (rval);
225 tmd_offset /= NBBY;
226 mdb_vread(&dam0, sizeof (dam0),
227 (uintptr_t)(tmd_offset + (char *)sht.tran_tgtmap));
228 mdb_vread(&dam1, sizeof (dam1),
229 (uintptr_t)(sizeof (dam0) + tmd_offset + (char *)sht.tran_tgtmap));
231 if (dam0 != (uintptr_t)NULL) {
232 rval = mdb_call_dcmd("damap", dam0, DCMD_ADDRSPEC, 0, NULL);
233 mdb_printf("\n");
234 if (rval != DCMD_OK) {
235 return (rval);
239 if (dam1 != (uintptr_t)NULL) {
240 rval = mdb_call_dcmd("damap", dam1, DCMD_ADDRSPEC, 0, NULL);
241 mdb_printf("\n");
244 return (rval);
247 /* ARGSUSED */
248 static int
249 display_iport_di_cb(uintptr_t addr, const void *wdata, void *priv)
251 uint_t *idx = (uint_t *)priv;
252 struct dev_info dip;
253 char devi_name[MAXNAMELEN];
254 char devi_addr[MAXNAMELEN];
256 if (mdb_vread(&dip, sizeof (struct dev_info), (uintptr_t)addr) !=
257 sizeof (struct dev_info)) {
258 return (DCMD_ERR);
261 if (mdb_readstr(devi_name, sizeof (devi_name),
262 (uintptr_t)dip.devi_node_name) == -1) {
263 devi_name[0] = '?';
264 devi_name[1] = '\0';
267 if (mdb_readstr(devi_addr, sizeof (devi_addr),
268 (uintptr_t)dip.devi_addr) == -1) {
269 devi_addr[0] = '?';
270 devi_addr[1] = '\0';
273 mdb_printf(" %3d: @%-21s%10s@\t%p::devinfo -s\n",
274 (*idx)++, devi_addr, devi_name, addr);
275 return (DCMD_OK);
278 /* ARGSUSED */
279 static int
280 display_iport_pi_cb(uintptr_t addr, const void *wdata, void *priv)
282 uint_t *idx = (uint_t *)priv;
283 struct mdi_pathinfo mpi;
284 char pi_addr[MAXNAMELEN];
286 if (mdb_vread(&mpi, sizeof (struct mdi_pathinfo), (uintptr_t)addr) !=
287 sizeof (struct mdi_pathinfo)) {
288 return (DCMD_ERR);
291 if (mdb_readstr(pi_addr, sizeof (pi_addr),
292 (uintptr_t)mpi.pi_addr) == -1) {
293 pi_addr[0] = '?';
294 pi_addr[1] = '\0';
297 mdb_printf(" %3d: @%-21s %p::print struct mdi_pathinfo\n",
298 (*idx)++, pi_addr, addr);
299 return (DCMD_OK);
302 static int
303 display_iport_dtc(dev_info_t *pdip)
305 int rval = DCMD_ERR;
306 struct dev_info dip;
307 struct mdi_phci phci;
308 uint_t didx = 1;
309 uint_t pidx = 1;
311 if (mdb_vread(&dip, sizeof (struct dev_info), (uintptr_t)pdip) !=
312 sizeof (struct dev_info)) {
313 return (rval);
316 mdb_printf("Device tree children - dev_info:\n");
317 if (dip.devi_child == NULL) {
318 mdb_printf("\tdevi_child is NULL, no dev_info\n\n");
319 goto skip_di;
323 * First, we dump the iport's children dev_info node information.
324 * use existing walker: devinfo_siblings
326 mdb_printf("\t#: @unit-address name@\tdrill-down\n");
327 rval = mdb_pwalk("devinfo_siblings", display_iport_di_cb,
328 (void *)&didx, (uintptr_t)dip.devi_child);
329 mdb_printf("\n");
331 skip_di:
333 * Then we try to dump the iport's path_info node information.
334 * use existing walker: mdipi_phci_list
336 mdb_printf("Device tree children - path_info:\n");
337 if (mdb_vread(&phci, sizeof (struct mdi_phci),
338 (uintptr_t)dip.devi_mdi_xhci) != sizeof (struct mdi_phci)) {
339 mdb_printf("\tdevi_mdi_xhci is NULL, no path_info\n\n");
340 return (rval);
343 if (phci.ph_path_head == NULL) {
344 mdb_printf("\tph_path_head is NULL, no path_info\n\n");
345 return (rval);
348 mdb_printf("\t#: @unit-address drill-down\n");
349 rval = mdb_pwalk("mdipi_phci_list", display_iport_pi_cb,
350 (void *)&pidx, (uintptr_t)phci.ph_path_head);
351 mdb_printf("\n");
352 return (rval);
355 static void
356 display_iport_more(dev_info_t *dip, per_iport_setting_t *pis)
358 if (pis->pis_damap_info) {
359 (void) display_iport_damap(dip);
362 if (pis->pis_dtc_info) {
363 (void) display_iport_dtc(dip);
367 /*ARGSUSED*/
368 static int
369 pmcs_iport_walk_cb(uintptr_t addr, const void *wdata, void *priv)
371 struct pmcs_iport iport;
372 uintptr_t list_addr;
373 char *ua_state;
374 char portid[4];
375 char unit_address[34];
376 per_iport_setting_t *pis = (per_iport_setting_t *)priv;
378 if (mdb_vread(&iport, sizeof (struct pmcs_iport), addr) !=
379 sizeof (struct pmcs_iport)) {
380 return (DCMD_ERR);
383 if (mdb_readstr(unit_address, sizeof (unit_address),
384 (uintptr_t)(iport.ua)) == -1) {
385 strncpy(unit_address, "Unset", sizeof (unit_address));
388 if (iport.portid == 0xffff) {
389 mdb_snprintf(portid, sizeof (portid), "%s", "-");
390 } else if (iport.portid == PMCS_IPORT_INVALID_PORT_ID) {
391 mdb_snprintf(portid, sizeof (portid), "%s", "N/A");
392 } else {
393 mdb_snprintf(portid, sizeof (portid), "%d", iport.portid);
396 switch (iport.ua_state) {
397 case UA_INACTIVE:
398 ua_state = "Inactive";
399 break;
400 case UA_PEND_ACTIVATE:
401 ua_state = "PendActivate";
402 break;
403 case UA_ACTIVE:
404 ua_state = "Active";
405 break;
406 case UA_PEND_DEACTIVATE:
407 ua_state = "PendDeactivate";
408 break;
409 default:
410 ua_state = "Unknown";
413 if (strlen(unit_address) < 3) {
414 /* Standard iport unit address */
415 mdb_printf("UA %-16s %16s %8s %8s %16s", "Iport", "UA State",
416 "PortID", "NumPhys", "DIP\n");
417 mdb_printf("%2s %16p %16s %8s %8d %16p\n", unit_address, addr,
418 ua_state, portid, iport.nphy, iport.dip);
419 } else {
420 /* Temporary iport unit address */
421 mdb_printf("%-32s %16s %20s %8s %8s %16s", "UA", "Iport",
422 "UA State", "PortID", "NumPhys", "DIP\n");
423 mdb_printf("%32s %16p %20s %8s %8d %16p\n", unit_address, addr,
424 ua_state, portid, iport.nphy, iport.dip);
427 if (iport.nphy > 0) {
428 mdb_inc_indent(4);
429 mdb_printf("%-18s %8s", "Phy", "PhyNum\n");
430 mdb_inc_indent(2);
431 list_addr =
432 (uintptr_t)(addr + offsetof(struct pmcs_iport, phys));
433 if (mdb_pwalk("list", pmcs_iport_phy_walk_cb, NULL,
434 list_addr) == -1) {
435 mdb_warn("pmcs iport walk failed");
437 mdb_dec_indent(6);
438 mdb_printf("\n");
442 * See if we need to show more information based on 'd' or 'm' options
444 display_iport_more(iport.dip, pis);
446 return (0);
449 /*ARGSUSED*/
450 static void
451 display_iport(struct pmcs_hw m, uintptr_t addr, int verbose,
452 per_iport_setting_t *pis)
454 uintptr_t list_addr;
456 if (m.iports_attached) {
457 mdb_printf("Iport information:\n");
458 mdb_printf("-----------------\n");
459 } else {
460 mdb_printf("No Iports found.\n\n");
461 return;
464 list_addr = (uintptr_t)(addr + offsetof(struct pmcs_hw, iports));
466 if (mdb_pwalk("list", pmcs_iport_walk_cb, pis, list_addr) == -1) {
467 mdb_warn("pmcs iport walk failed");
470 mdb_printf("\n");
473 /* ARGSUSED */
474 static int
475 pmcs_utarget_walk_cb(uintptr_t addr, const void *wdata, void *priv)
477 pmcs_phy_t phy;
479 if (mdb_vread(&phy, sizeof (pmcs_phy_t), (uintptr_t)addr) == -1) {
480 mdb_warn("pmcs_utarget_walk_cb: Failed to read PHY at %p",
481 (void *)addr);
482 return (DCMD_ERR);
485 if (phy.configured && (phy.target == NULL)) {
486 mdb_printf("SAS address: ");
487 print_sas_address(&phy);
488 mdb_printf(" DType: ");
489 switch (phy.dtype) {
490 case SAS:
491 mdb_printf("%4s", "SAS");
492 break;
493 case SATA:
494 mdb_printf("%4s", "SATA");
495 break;
496 case EXPANDER:
497 mdb_printf("%4s", "SMP");
498 break;
499 default:
500 mdb_printf("%4s", "N/A");
501 break;
503 mdb_printf(" Path: %s\n", phy.path);
506 return (0);
509 static void
510 display_unconfigured_targets(uintptr_t addr)
512 mdb_printf("Unconfigured target SAS address:\n\n");
514 if (mdb_pwalk("pmcs_phys", pmcs_utarget_walk_cb, NULL, addr) == -1) {
515 mdb_warn("pmcs phys walk failed");
519 static void
520 display_completion_queue(struct pmcs_hw ss)
522 pmcs_iocomp_cb_t ccb, *ccbp;
523 pmcwork_t work;
525 if (ss.iocomp_cb_head == NULL) {
526 mdb_printf("Completion queue is empty.\n");
527 return;
530 ccbp = ss.iocomp_cb_head;
531 mdb_printf("%8s %10s %20s %8s %8s O D\n",
532 "HTag", "State", "Phy Path", "Target", "Timer");
534 while (ccbp) {
535 if (mdb_vread(&ccb, sizeof (pmcs_iocomp_cb_t),
536 (uintptr_t)ccbp) != sizeof (pmcs_iocomp_cb_t)) {
537 mdb_warn("Unable to read completion queue entry\n");
538 return;
541 if (mdb_vread(&work, sizeof (pmcwork_t), (uintptr_t)ccb.pwrk)
542 != sizeof (pmcwork_t)) {
543 mdb_warn("Unable to read work structure\n");
544 return;
548 * Only print the work structure if it's still active. If
549 * it's not, it's been completed since we started looking at
550 * it.
552 if (work.state != PMCS_WORK_STATE_NIL) {
553 display_one_work(&work, 0, 0);
555 ccbp = ccb.next;
559 static void
560 display_event_log(struct pmcs_hw ss)
562 pmcs_fw_event_hdr_t fwhdr;
563 char *header_id, *entry, *fwlogp;
564 uint32_t total_size = PMCS_FWLOG_SIZE, log_size, index, *swapp, sidx;
565 pmcs_fw_event_entry_t *fw_entryp;
566 struct timespec systime;
568 if (ss.fwlogp == NULL) {
569 mdb_printf("There is no firmware event log.\n");
570 return;
573 fwlogp = (char *)ss.fwlogp;
575 while (total_size != 0) {
576 if (mdb_vread(&fwhdr, sizeof (pmcs_fw_event_hdr_t),
577 (uintptr_t)fwlogp) != sizeof (pmcs_fw_event_hdr_t)) {
578 mdb_warn("Unable to read firmware event log header\n");
579 return;
583 * Firmware event log is little-endian
585 swapp = (uint32_t *)&fwhdr;
586 for (sidx = 0; sidx < (sizeof (pmcs_fw_event_hdr_t) /
587 sizeof (uint32_t)); sidx++) {
588 *swapp = LE_32(*swapp);
589 swapp++;
592 if (fwhdr.fw_el_signature == PMCS_FWLOG_AAP1_SIG) {
593 header_id = "AAP1";
594 } else if (fwhdr.fw_el_signature == PMCS_FWLOG_IOP_SIG) {
595 header_id = "IOP";
596 } else {
597 mdb_warn("Invalid firmware event log signature\n");
598 return;
601 mdb_printf("Event Log: %s\n", header_id);
602 mdb_printf("Oldest entry: %d\n", fwhdr.fw_el_oldest_idx);
603 mdb_printf("Latest entry: %d\n", fwhdr.fw_el_latest_idx);
605 entry = mdb_alloc(fwhdr.fw_el_entry_size, UM_SLEEP);
606 fw_entryp = (pmcs_fw_event_entry_t *)((void *)entry);
607 total_size -= sizeof (pmcs_fw_event_hdr_t);
608 log_size = fwhdr.fw_el_buf_size;
609 fwlogp += fwhdr.fw_el_entry_start_offset;
610 swapp = (uint32_t *)((void *)entry);
611 index = 0;
613 mdb_printf("%8s %16s %32s %8s %3s %8s %8s %8s %8s",
614 "Index", "Timestamp", "Time", "Seq Num", "Sev", "Word 0",
615 "Word 1", "Word 2", "Word 3");
616 mdb_printf("\n");
618 while (log_size != 0) {
619 if (mdb_vread(entry, fwhdr.fw_el_entry_size,
620 (uintptr_t)fwlogp) != fwhdr.fw_el_entry_size) {
621 mdb_warn("Unable to read event log entry\n");
622 goto bail_out;
625 for (sidx = 0; sidx < (fwhdr.fw_el_entry_size /
626 sizeof (uint32_t)); sidx++) {
627 *(swapp + sidx) = LE_32(*(swapp + sidx));
630 if (fw_entryp->ts_upper || fw_entryp->ts_lower) {
631 pmcs_fwtime_to_systime(ss, fw_entryp->ts_upper,
632 fw_entryp->ts_lower, &systime);
633 mdb_printf("%8d %08x%08x [%Y.%09ld] %8d %3d "
634 "%08x %08x %08x %08x\n", index,
635 fw_entryp->ts_upper, fw_entryp->ts_lower,
636 systime, fw_entryp->seq_num,
637 fw_entryp->severity, fw_entryp->logw0,
638 fw_entryp->logw1, fw_entryp->logw2,
639 fw_entryp->logw3);
642 fwlogp += fwhdr.fw_el_entry_size;
643 total_size -= fwhdr.fw_el_entry_size;
644 log_size -= fwhdr.fw_el_entry_size;
645 index++;
648 mdb_printf("\n");
651 bail_out:
652 mdb_free(entry, fwhdr.fw_el_entry_size);
655 /*ARGSUSED*/
656 static void
657 display_hwinfo(struct pmcs_hw m, int verbose)
659 struct pmcs_hw *mp = &m;
660 char *fwsupport;
662 switch (PMCS_FW_TYPE(mp)) {
663 case PMCS_FW_TYPE_RELEASED:
664 fwsupport = "Released";
665 break;
666 case PMCS_FW_TYPE_DEVELOPMENT:
667 fwsupport = "Development";
668 break;
669 case PMCS_FW_TYPE_ALPHA:
670 fwsupport = "Alpha";
671 break;
672 case PMCS_FW_TYPE_BETA:
673 fwsupport = "Beta";
674 break;
675 default:
676 fwsupport = "Special";
677 break;
680 mdb_printf("\nHardware information:\n");
681 mdb_printf("---------------------\n");
683 mdb_printf("Chip revision: %c\n", 'A' + m.chiprev);
684 mdb_printf("SAS WWID: %"PRIx64"\n", m.sas_wwns[0]);
685 mdb_printf("Firmware version: %x.%x.%x (%s)\n",
686 PMCS_FW_MAJOR(mp), PMCS_FW_MINOR(mp), PMCS_FW_MICRO(mp),
687 fwsupport);
688 mdb_printf("ILA version: %08x\n", m.ila_ver);
689 mdb_printf("Active f/w img: %c\n", (m.fw_active_img) ? 'A' : 'B');
691 mdb_printf("Number of PHYs: %d\n", m.nphy);
692 mdb_printf("Maximum commands: %d\n", m.max_cmd);
693 mdb_printf("Maximum devices: %d\n", m.max_dev);
694 mdb_printf("I/O queue depth: %d\n", m.ioq_depth);
695 mdb_printf("Open retry intvl: %d usecs\n", m.open_retry_interval);
696 if (m.fwlog == 0) {
697 mdb_printf("Firmware logging: Disabled\n");
698 } else {
699 mdb_printf("Firmware logging: Enabled (%d)\n", m.fwlog);
701 if (m.fwlog_file == 0) {
702 mdb_printf("Firmware logfile: Not configured\n");
703 } else {
704 mdb_printf("Firmware logfile: Configured\n");
705 mdb_inc_indent(2);
706 mdb_printf("AAP1 log file: %s\n", m.fwlogfile_aap1);
707 mdb_printf("IOP logfile: %s\n", m.fwlogfile_iop);
708 mdb_dec_indent(2);
712 static void
713 display_targets(struct pmcs_hw m, int verbose, int totals_only)
715 char *dtype;
716 pmcs_xscsi_t xs;
717 pmcs_phy_t phy;
718 uint16_t max_dev, idx;
719 uint32_t sas_targets = 0, smp_targets = 0, sata_targets = 0;
721 max_dev = m.max_dev;
723 if (targets == NULL) {
724 targets = mdb_alloc(sizeof (targets) * max_dev, UM_SLEEP);
727 if (MDB_RD(targets, sizeof (targets) * max_dev, m.targets) == -1) {
728 NOREAD(targets, m.targets);
729 return;
732 if (!totals_only) {
733 mdb_printf("\nTarget information:\n");
734 mdb_printf("---------------------------------------\n");
735 mdb_printf("VTGT %-16s %-16s %-5s %4s %6s %s", "SAS Address",
736 "PHY Address", "DType", "Actv", "OnChip", "DS");
737 mdb_printf("\n");
740 for (idx = 0; idx < max_dev; idx++) {
741 if (targets[idx] == NULL) {
742 continue;
745 if (MDB_RD(&xs, sizeof (xs), targets[idx]) == -1) {
746 NOREAD(pmcs_xscsi_t, targets[idx]);
747 continue;
751 * It has to be new or assigned to be of interest.
753 if (xs.new == 0 && xs.assigned == 0) {
754 continue;
757 switch (xs.dtype) {
758 case NOTHING:
759 dtype = "None";
760 break;
761 case SATA:
762 dtype = "SATA";
763 sata_targets++;
764 break;
765 case SAS:
766 dtype = "SAS";
767 sas_targets++;
768 break;
769 case EXPANDER:
770 dtype = "SMP";
771 smp_targets++;
772 break;
775 if (totals_only) {
776 continue;
779 if (xs.phy) {
780 if (MDB_RD(&phy, sizeof (phy), xs.phy) == -1) {
781 NOREAD(pmcs_phy_t, xs.phy);
782 continue;
784 mdb_printf("%4d ", idx);
785 print_sas_address(&phy);
786 mdb_printf(" %16p", xs.phy);
787 } else {
788 mdb_printf("%4d %16s", idx, "<no phy avail>");
790 mdb_printf(" %5s", dtype);
791 mdb_printf(" %4d", xs.actv_pkts);
792 mdb_printf(" %6d", xs.actv_cnt);
793 mdb_printf(" %2d", xs.dev_state);
795 if (verbose) {
796 if (xs.new) {
797 mdb_printf(" new");
799 if (xs.assigned) {
800 mdb_printf(" assigned");
802 if (xs.draining) {
803 mdb_printf(" draining");
805 if (xs.reset_wait) {
806 mdb_printf(" reset_wait");
808 if (xs.resetting) {
809 mdb_printf(" resetting");
811 if (xs.recover_wait) {
812 mdb_printf(" recover_wait");
814 if (xs.recovering) {
815 mdb_printf(" recovering");
817 if (xs.event_recovery) {
818 mdb_printf(" event recovery");
820 if (xs.special_running) {
821 mdb_printf(" special_active");
823 if (xs.ncq) {
824 mdb_printf(" ncq_tagmap=0x%x qdepth=%d",
825 xs.tagmap, xs.qdepth);
826 } else if (xs.pio) {
827 mdb_printf(" pio");
831 mdb_printf("\n");
834 if (!totals_only) {
835 mdb_printf("\n");
838 mdb_printf("%19s %d (%d SAS + %d SATA + %d SMP)\n",
839 "Configured targets:", (sas_targets + sata_targets + smp_targets),
840 sas_targets, sata_targets, smp_targets);
843 static char *
844 work_state_to_string(uint32_t state)
846 char *state_string;
848 switch (state) {
849 case PMCS_WORK_STATE_NIL:
850 state_string = "Free";
851 break;
852 case PMCS_WORK_STATE_READY:
853 state_string = "Ready";
854 break;
855 case PMCS_WORK_STATE_ONCHIP:
856 state_string = "On Chip";
857 break;
858 case PMCS_WORK_STATE_INTR:
859 state_string = "In Intr";
860 break;
861 case PMCS_WORK_STATE_IOCOMPQ:
862 state_string = "I/O Comp";
863 break;
864 case PMCS_WORK_STATE_ABORTED:
865 state_string = "I/O Aborted";
866 break;
867 case PMCS_WORK_STATE_TIMED_OUT:
868 state_string = "I/O Timed Out";
869 break;
870 default:
871 state_string = "INVALID";
872 break;
875 return (state_string);
878 static void
879 display_one_work(pmcwork_t *wp, int verbose, int idx)
881 char *state, *last_state;
882 char *path;
883 pmcs_xscsi_t xs;
884 pmcs_phy_t phy;
885 int tgt;
887 state = work_state_to_string(wp->state);
888 last_state = work_state_to_string(wp->last_state);
890 if (wp->ssp_event && wp->ssp_event != 0xffffffff) {
891 mdb_printf("SSP event 0x%x", wp->ssp_event);
894 tgt = -1;
895 if (wp->xp) {
896 if (MDB_RD(&xs, sizeof (xs), wp->xp) == -1) {
897 NOREAD(pmcs_xscsi_t, wp->xp);
898 } else {
899 tgt = xs.target_num;
902 if (wp->phy) {
903 if (MDB_RD(&phy, sizeof (phy), wp->phy) == -1) {
904 NOREAD(pmcs_phy_t, wp->phy);
906 path = phy.path;
907 } else {
908 path = "N/A";
911 if (verbose) {
912 mdb_printf("%4d ", idx);
914 if (tgt == -1) {
915 mdb_printf("%08x %10s %20s N/A %8u %1d %1d ",
916 wp->htag, state, path, wp->timer,
917 wp->onwire, wp->dead);
918 } else {
919 mdb_printf("%08x %10s %20s %8d %8u %1d %1d ",
920 wp->htag, state, path, tgt, wp->timer,
921 wp->onwire, wp->dead);
923 if (verbose) {
924 mdb_printf("%08x %10s 0x%016p 0x%016p 0x%016p\n",
925 wp->last_htag, last_state, wp->last_phy, wp->last_xp,
926 wp->last_arg);
927 } else {
928 mdb_printf("\n");
932 static void
933 display_work(struct pmcs_hw m, int verbose, int wserno)
935 int idx;
936 boolean_t header_printed = B_FALSE;
937 pmcwork_t *wp;
938 wserno_list_t *sernop, *sp, *newsp, *sphead = NULL;
939 uintptr_t _wp;
940 int serno;
942 wp = mdb_alloc(sizeof (pmcwork_t) * m.max_cmd, UM_SLEEP);
943 _wp = (uintptr_t)m.work;
944 sernop = mdb_alloc(sizeof (wserno_list_t) * m.max_cmd, UM_SLEEP);
945 bzero(sernop, sizeof (wserno_list_t) * m.max_cmd);
947 mdb_printf("\nActive Work structure information:\n");
948 mdb_printf("----------------------------------\n");
951 * Read in all the work structures
953 for (idx = 0; idx < m.max_cmd; idx++, _wp += sizeof (pmcwork_t)) {
954 if (MDB_RD(wp + idx, sizeof (pmcwork_t), _wp) == -1) {
955 NOREAD(pmcwork_t, _wp);
956 continue;
961 * Sort by serial number?
963 if (wserno) {
964 for (idx = 0; idx < m.max_cmd; idx++) {
965 if ((wp + idx)->htag == 0) {
966 serno = PMCS_TAG_SERNO((wp + idx)->last_htag);
967 } else {
968 serno = PMCS_TAG_SERNO((wp + idx)->htag);
971 /* Start at the beginning of the list */
972 sp = sphead;
973 newsp = sernop + idx;
974 /* If this is the first entry, just add it */
975 if (sphead == NULL) {
976 sphead = sernop;
977 sphead->serno = serno;
978 sphead->idx = idx;
979 sphead->next = NULL;
980 sphead->prev = NULL;
981 continue;
984 newsp->serno = serno;
985 newsp->idx = idx;
987 /* Find out where in the list this goes */
988 while (sp) {
989 /* This item goes before sp */
990 if (serno < sp->serno) {
991 newsp->next = sp;
992 newsp->prev = sp->prev;
993 if (newsp->prev == NULL) {
994 sphead = newsp;
995 } else {
996 newsp->prev->next = newsp;
998 sp->prev = newsp;
999 break;
1003 * If sp->next is NULL, this entry goes at the
1004 * end of the list
1006 if (sp->next == NULL) {
1007 sp->next = newsp;
1008 newsp->next = NULL;
1009 newsp->prev = sp;
1010 break;
1013 sp = sp->next;
1018 * Now print the sorted list
1020 mdb_printf(" Idx %8s %10s %20s %8s %8s O D ",
1021 "HTag", "State", "Phy Path", "Target", "Timer");
1022 mdb_printf("%8s %10s %18s %18s %18s\n", "LastHTAG",
1023 "LastState", "LastPHY", "LastTgt", "LastArg");
1025 sp = sphead;
1026 while (sp) {
1027 display_one_work(wp + sp->idx, 1, sp->idx);
1028 sp = sp->next;
1031 goto out;
1035 * Now print the list, sorted by index
1037 for (idx = 0; idx < m.max_cmd; idx++) {
1038 if (!verbose && ((wp + idx)->htag == PMCS_TAG_TYPE_FREE)) {
1039 continue;
1042 if (header_printed == B_FALSE) {
1043 if (verbose) {
1044 mdb_printf("%4s ", "Idx");
1046 mdb_printf("%8s %10s %20s %8s %8s O D ",
1047 "HTag", "State", "Phy Path", "Target", "Timer");
1048 if (verbose) {
1049 mdb_printf("%8s %10s %18s %18s %18s\n",
1050 "LastHTAG", "LastState", "LastPHY",
1051 "LastTgt", "LastArg");
1052 } else {
1053 mdb_printf("\n");
1055 header_printed = B_TRUE;
1058 display_one_work(wp + idx, verbose, idx);
1061 out:
1062 mdb_free(wp, sizeof (pmcwork_t) * m.max_cmd);
1063 mdb_free(sernop, sizeof (wserno_list_t) * m.max_cmd);
1066 static void
1067 print_spcmd(pmcs_cmd_t *sp, void *kaddr, int printhdr, int verbose)
1069 int cdb_size, idx;
1070 struct scsi_pkt pkt;
1071 uchar_t cdb[256];
1073 if (printhdr) {
1074 if (verbose) {
1075 mdb_printf("%16s %16s %16s %8s %s CDB\n", "Command",
1076 "SCSA pkt", "DMA Chunks", "HTAG", "SATL Tag");
1077 } else {
1078 mdb_printf("%16s %16s %16s %8s %s\n", "Command",
1079 "SCSA pkt", "DMA Chunks", "HTAG", "SATL Tag");
1083 mdb_printf("%16p %16p %16p %08x %08x ",
1084 kaddr, sp->cmd_pkt, sp->cmd_clist, sp->cmd_tag, sp->cmd_satltag);
1087 * If we're printing verbose, dump the CDB as well.
1089 if (verbose) {
1090 if (sp->cmd_pkt) {
1091 if (mdb_vread(&pkt, sizeof (struct scsi_pkt),
1092 (uintptr_t)sp->cmd_pkt) !=
1093 sizeof (struct scsi_pkt)) {
1094 mdb_warn("Unable to read SCSI pkt\n");
1095 return;
1097 cdb_size = pkt.pkt_cdblen;
1098 if (mdb_vread(&cdb[0], cdb_size,
1099 (uintptr_t)pkt.pkt_cdbp) != cdb_size) {
1100 mdb_warn("Unable to read CDB\n");
1101 return;
1104 for (idx = 0; idx < cdb_size; idx++) {
1105 mdb_printf("%02x ", cdb[idx]);
1107 } else {
1108 mdb_printf("N/A");
1111 mdb_printf("\n");
1112 } else {
1113 mdb_printf("\n");
1117 /*ARGSUSED1*/
1118 static void
1119 display_waitqs(struct pmcs_hw m, int verbose)
1121 pmcs_cmd_t *sp, s;
1122 pmcs_xscsi_t xs;
1123 int first, i;
1124 int max_dev = m.max_dev;
1126 sp = m.dq.stqh_first;
1127 first = 1;
1128 while (sp) {
1129 if (first) {
1130 mdb_printf("\nDead Command Queue:\n");
1131 mdb_printf("---------------------------\n");
1133 if (MDB_RD(&s, sizeof (s), sp) == -1) {
1134 NOREAD(pmcs_cmd_t, sp);
1135 break;
1137 print_spcmd(&s, sp, first, verbose);
1138 sp = s.cmd_next.stqe_next;
1139 first = 0;
1142 sp = m.cq.stqh_first;
1143 first = 1;
1144 while (sp) {
1145 if (first) {
1146 mdb_printf("\nCompletion Command Queue:\n");
1147 mdb_printf("---------------------------\n");
1149 if (MDB_RD(&s, sizeof (s), sp) == -1) {
1150 NOREAD(pmcs_cmd_t, sp);
1151 break;
1153 print_spcmd(&s, sp, first, verbose);
1154 sp = s.cmd_next.stqe_next;
1155 first = 0;
1159 if (targets == NULL) {
1160 targets = mdb_alloc(sizeof (targets) * max_dev, UM_SLEEP);
1163 if (MDB_RD(targets, sizeof (targets) * max_dev, m.targets) == -1) {
1164 NOREAD(targets, m.targets);
1165 return;
1168 for (i = 0; i < max_dev; i++) {
1169 if (targets[i] == NULL) {
1170 continue;
1172 if (MDB_RD(&xs, sizeof (xs), targets[i]) == -1) {
1173 NOREAD(pmcs_xscsi_t, targets[i]);
1174 continue;
1176 sp = xs.wq.stqh_first;
1177 first = 1;
1178 while (sp) {
1179 if (first) {
1180 mdb_printf("\nTarget %u Wait Queue:\n",
1181 xs.target_num);
1182 mdb_printf("---------------------------\n");
1184 if (MDB_RD(&s, sizeof (s), sp) == -1) {
1185 NOREAD(pmcs_cmd_t, sp);
1186 break;
1188 print_spcmd(&s, sp, first, verbose);
1189 sp = s.cmd_next.stqe_next;
1190 first = 0;
1192 sp = xs.aq.stqh_first;
1193 first = 1;
1194 while (sp) {
1195 if (first) {
1196 mdb_printf("\nTarget %u Active Queue:\n",
1197 xs.target_num);
1198 mdb_printf("---------------------------\n");
1200 if (MDB_RD(&s, sizeof (s), sp) == -1) {
1201 NOREAD(pmcs_cmd_t, sp);
1202 break;
1204 print_spcmd(&s, sp, first, verbose);
1205 sp = s.cmd_next.stqe_next;
1206 first = 0;
1208 sp = xs.sq.stqh_first;
1209 first = 1;
1210 while (sp) {
1211 if (first) {
1212 mdb_printf("\nTarget %u Special Queue:\n",
1213 xs.target_num);
1214 mdb_printf("---------------------------\n");
1216 if (MDB_RD(&s, sizeof (s), sp) == -1) {
1217 NOREAD(pmcs_cmd_t, sp);
1218 break;
1220 print_spcmd(&s, sp, first, verbose);
1221 sp = s.cmd_next.stqe_next;
1222 first = 0;
1227 static char *
1228 ibq_type(int qnum)
1230 if (qnum < 0 || qnum >= PMCS_NIQ) {
1231 return ("UNKNOWN");
1234 if (qnum < PMCS_IQ_OTHER) {
1235 return ("I/O");
1238 return ("Other");
1241 static char *
1242 obq_type(int qnum)
1244 switch (qnum) {
1245 case PMCS_OQ_IODONE:
1246 return ("I/O");
1247 case PMCS_OQ_GENERAL:
1248 return ("General");
1249 case PMCS_OQ_EVENTS:
1250 return ("Events");
1251 default:
1252 return ("UNKNOWN");
1256 static char *
1257 iomb_cat(uint32_t cat)
1259 switch (cat) {
1260 case PMCS_IOMB_CAT_NET:
1261 return ("NET");
1262 case PMCS_IOMB_CAT_FC:
1263 return ("FC");
1264 case PMCS_IOMB_CAT_SAS:
1265 return ("SAS");
1266 case PMCS_IOMB_CAT_SCSI:
1267 return ("SCSI");
1268 default:
1269 return ("???");
1273 static char *
1274 iomb_event(uint8_t event)
1276 switch (event) {
1277 case IOP_EVENT_PHY_STOP_STATUS:
1278 return ("PHY STOP");
1279 case IOP_EVENT_SAS_PHY_UP:
1280 return ("PHY UP");
1281 case IOP_EVENT_SATA_PHY_UP:
1282 return ("SATA PHY UP");
1283 case IOP_EVENT_SATA_SPINUP_HOLD:
1284 return ("SATA SPINUP HOLD");
1285 case IOP_EVENT_PHY_DOWN:
1286 return ("PHY DOWN");
1287 case IOP_EVENT_BROADCAST_CHANGE:
1288 return ("BROADCAST CHANGE");
1289 case IOP_EVENT_BROADCAST_SES:
1290 return ("BROADCAST SES");
1291 case IOP_EVENT_PHY_ERR_INBOUND_CRC:
1292 return ("INBOUND CRC ERROR");
1293 case IOP_EVENT_HARD_RESET_RECEIVED:
1294 return ("HARD RESET");
1295 case IOP_EVENT_EVENT_ID_FRAME_TIMO:
1296 return ("IDENTIFY FRAME TIMEOUT");
1297 case IOP_EVENT_BROADCAST_EXP:
1298 return ("BROADCAST EXPANDER");
1299 case IOP_EVENT_PHY_START_STATUS:
1300 return ("PHY START");
1301 case IOP_EVENT_PHY_ERR_INVALID_DWORD:
1302 return ("INVALID DWORD");
1303 case IOP_EVENT_PHY_ERR_DISPARITY_ERROR:
1304 return ("DISPARITY ERROR");
1305 case IOP_EVENT_PHY_ERR_CODE_VIOLATION:
1306 return ("CODE VIOLATION");
1307 case IOP_EVENT_PHY_ERR_LOSS_OF_DWORD_SYN:
1308 return ("LOSS OF DWORD SYNC");
1309 case IOP_EVENT_PHY_ERR_PHY_RESET_FAILD:
1310 return ("PHY RESET FAILED");
1311 case IOP_EVENT_PORT_RECOVERY_TIMER_TMO:
1312 return ("PORT RECOVERY TIMEOUT");
1313 case IOP_EVENT_PORT_RECOVER:
1314 return ("PORT RECOVERY");
1315 case IOP_EVENT_PORT_RESET_TIMER_TMO:
1316 return ("PORT RESET TIMEOUT");
1317 case IOP_EVENT_PORT_RESET_COMPLETE:
1318 return ("PORT RESET COMPLETE");
1319 case IOP_EVENT_BROADCAST_ASYNC_EVENT:
1320 return ("BROADCAST ASYNC");
1321 case IOP_EVENT_IT_NEXUS_LOSS:
1322 return ("I/T NEXUS LOSS");
1323 default:
1324 return ("Unknown Event");
1328 static char *
1329 inbound_iomb_opcode(uint32_t opcode)
1331 switch (opcode) {
1332 case PMCIN_ECHO:
1333 return ("ECHO");
1334 case PMCIN_GET_INFO:
1335 return ("GET_INFO");
1336 case PMCIN_GET_VPD:
1337 return ("GET_VPD");
1338 case PMCIN_PHY_START:
1339 return ("PHY_START");
1340 case PMCIN_PHY_STOP:
1341 return ("PHY_STOP");
1342 case PMCIN_SSP_INI_IO_START:
1343 return ("INI_IO_START");
1344 case PMCIN_SSP_INI_TM_START:
1345 return ("INI_TM_START");
1346 case PMCIN_SSP_INI_EXT_IO_START:
1347 return ("INI_EXT_IO_START");
1348 case PMCIN_DEVICE_HANDLE_ACCEPT:
1349 return ("DEVICE_HANDLE_ACCEPT");
1350 case PMCIN_SSP_TGT_IO_START:
1351 return ("TGT_IO_START");
1352 case PMCIN_SSP_TGT_RESPONSE_START:
1353 return ("TGT_RESPONSE_START");
1354 case PMCIN_SSP_INI_EDC_EXT_IO_START:
1355 return ("INI_EDC_EXT_IO_START");
1356 case PMCIN_SSP_INI_EDC_EXT_IO_START1:
1357 return ("INI_EDC_EXT_IO_START1");
1358 case PMCIN_SSP_TGT_EDC_IO_START:
1359 return ("TGT_EDC_IO_START");
1360 case PMCIN_SSP_ABORT:
1361 return ("SSP_ABORT");
1362 case PMCIN_DEREGISTER_DEVICE_HANDLE:
1363 return ("DEREGISTER_DEVICE_HANDLE");
1364 case PMCIN_GET_DEVICE_HANDLE:
1365 return ("GET_DEVICE_HANDLE");
1366 case PMCIN_SMP_REQUEST:
1367 return ("SMP_REQUEST");
1368 case PMCIN_SMP_RESPONSE:
1369 return ("SMP_RESPONSE");
1370 case PMCIN_SMP_ABORT:
1371 return ("SMP_ABORT");
1372 case PMCIN_ASSISTED_DISCOVERY:
1373 return ("ASSISTED_DISCOVERY");
1374 case PMCIN_REGISTER_DEVICE:
1375 return ("REGISTER_DEVICE");
1376 case PMCIN_SATA_HOST_IO_START:
1377 return ("SATA_HOST_IO_START");
1378 case PMCIN_SATA_ABORT:
1379 return ("SATA_ABORT");
1380 case PMCIN_LOCAL_PHY_CONTROL:
1381 return ("LOCAL_PHY_CONTROL");
1382 case PMCIN_GET_DEVICE_INFO:
1383 return ("GET_DEVICE_INFO");
1384 case PMCIN_TWI:
1385 return ("TWI");
1386 case PMCIN_FW_FLASH_UPDATE:
1387 return ("FW_FLASH_UPDATE");
1388 case PMCIN_SET_VPD:
1389 return ("SET_VPD");
1390 case PMCIN_GPIO:
1391 return ("GPIO");
1392 case PMCIN_SAS_DIAG_MODE_START_END:
1393 return ("SAS_DIAG_MODE_START_END");
1394 case PMCIN_SAS_DIAG_EXECUTE:
1395 return ("SAS_DIAG_EXECUTE");
1396 case PMCIN_SAS_HW_EVENT_ACK:
1397 return ("SAS_HW_EVENT_ACK");
1398 case PMCIN_GET_TIME_STAMP:
1399 return ("GET_TIME_STAMP");
1400 case PMCIN_PORT_CONTROL:
1401 return ("PORT_CONTROL");
1402 case PMCIN_GET_NVMD_DATA:
1403 return ("GET_NVMD_DATA");
1404 case PMCIN_SET_NVMD_DATA:
1405 return ("SET_NVMD_DATA");
1406 case PMCIN_SET_DEVICE_STATE:
1407 return ("SET_DEVICE_STATE");
1408 case PMCIN_GET_DEVICE_STATE:
1409 return ("GET_DEVICE_STATE");
1410 default:
1411 return ("UNKNOWN");
1415 static char *
1416 outbound_iomb_opcode(uint32_t opcode)
1418 switch (opcode) {
1419 case PMCOUT_ECHO:
1420 return ("ECHO");
1421 case PMCOUT_GET_INFO:
1422 return ("GET_INFO");
1423 case PMCOUT_GET_VPD:
1424 return ("GET_VPD");
1425 case PMCOUT_SAS_HW_EVENT:
1426 return ("SAS_HW_EVENT");
1427 case PMCOUT_SSP_COMPLETION:
1428 return ("SSP_COMPLETION");
1429 case PMCOUT_SMP_COMPLETION:
1430 return ("SMP_COMPLETION");
1431 case PMCOUT_LOCAL_PHY_CONTROL:
1432 return ("LOCAL_PHY_CONTROL");
1433 case PMCOUT_SAS_ASSISTED_DISCOVERY_EVENT:
1434 return ("SAS_ASSISTED_DISCOVERY_SENT");
1435 case PMCOUT_SATA_ASSISTED_DISCOVERY_EVENT:
1436 return ("SATA_ASSISTED_DISCOVERY_SENT");
1437 case PMCOUT_DEVICE_REGISTRATION:
1438 return ("DEVICE_REGISTRATION");
1439 case PMCOUT_DEREGISTER_DEVICE_HANDLE:
1440 return ("DEREGISTER_DEVICE_HANDLE");
1441 case PMCOUT_GET_DEVICE_HANDLE:
1442 return ("GET_DEVICE_HANDLE");
1443 case PMCOUT_SATA_COMPLETION:
1444 return ("SATA_COMPLETION");
1445 case PMCOUT_SATA_EVENT:
1446 return ("SATA_EVENT");
1447 case PMCOUT_SSP_EVENT:
1448 return ("SSP_EVENT");
1449 case PMCOUT_DEVICE_HANDLE_ARRIVED:
1450 return ("DEVICE_HANDLE_ARRIVED");
1451 case PMCOUT_SSP_REQUEST_RECEIVED:
1452 return ("SSP_REQUEST_RECEIVED");
1453 case PMCOUT_DEVICE_INFO:
1454 return ("DEVICE_INFO");
1455 case PMCOUT_FW_FLASH_UPDATE:
1456 return ("FW_FLASH_UPDATE");
1457 case PMCOUT_SET_VPD:
1458 return ("SET_VPD");
1459 case PMCOUT_GPIO:
1460 return ("GPIO");
1461 case PMCOUT_GPIO_EVENT:
1462 return ("GPIO_EVENT");
1463 case PMCOUT_GENERAL_EVENT:
1464 return ("GENERAL_EVENT");
1465 case PMCOUT_TWI:
1466 return ("TWI");
1467 case PMCOUT_SSP_ABORT:
1468 return ("SSP_ABORT");
1469 case PMCOUT_SATA_ABORT:
1470 return ("SATA_ABORT");
1471 case PMCOUT_SAS_DIAG_MODE_START_END:
1472 return ("SAS_DIAG_MODE_START_END");
1473 case PMCOUT_SAS_DIAG_EXECUTE:
1474 return ("SAS_DIAG_EXECUTE");
1475 case PMCOUT_GET_TIME_STAMP:
1476 return ("GET_TIME_STAMP");
1477 case PMCOUT_SAS_HW_EVENT_ACK_ACK:
1478 return ("SAS_HW_EVENT_ACK_ACK");
1479 case PMCOUT_PORT_CONTROL:
1480 return ("PORT_CONTROL");
1481 case PMCOUT_SKIP_ENTRIES:
1482 return ("SKIP_ENTRIES");
1483 case PMCOUT_SMP_ABORT:
1484 return ("SMP_ABORT");
1485 case PMCOUT_GET_NVMD_DATA:
1486 return ("GET_NVMD_DATA");
1487 case PMCOUT_SET_NVMD_DATA:
1488 return ("SET_NVMD_DATA");
1489 case PMCOUT_DEVICE_HANDLE_REMOVED:
1490 return ("DEVICE_HANDLE_REMOVED");
1491 case PMCOUT_SET_DEVICE_STATE:
1492 return ("SET_DEVICE_STATE");
1493 case PMCOUT_GET_DEVICE_STATE:
1494 return ("GET_DEVICE_STATE");
1495 case PMCOUT_SET_DEVICE_INFO:
1496 return ("SET_DEVICE_INFO");
1497 default:
1498 return ("UNKNOWN");
1502 static uint32_t
1503 get_devid_from_ob_iomb(struct pmcs_hw ss, uint32_t *qentryp, uint16_t opcode)
1505 uint32_t devid = PMCS_INVALID_DEVICE_ID;
1507 switch (opcode) {
1509 * These are obtained via the HTAG which is in word 1
1511 case PMCOUT_SSP_COMPLETION:
1512 case PMCOUT_SMP_COMPLETION:
1513 case PMCOUT_DEREGISTER_DEVICE_HANDLE:
1514 case PMCOUT_GET_DEVICE_HANDLE:
1515 case PMCOUT_SATA_COMPLETION:
1516 case PMCOUT_SSP_ABORT:
1517 case PMCOUT_SATA_ABORT:
1518 case PMCOUT_SMP_ABORT:
1519 case PMCOUT_SAS_HW_EVENT_ACK_ACK: {
1520 uint32_t htag;
1521 pmcwork_t *wp;
1522 pmcs_phy_t *phy;
1523 uintptr_t _wp, _phy;
1524 uint16_t index;
1526 htag = LE_32(*(qentryp + 1));
1527 index = htag & PMCS_TAG_INDEX_MASK;
1529 wp = mdb_alloc(sizeof (pmcwork_t), UM_SLEEP);
1530 _wp = (uintptr_t)ss.work + (sizeof (pmcwork_t) * index);
1532 if (MDB_RD(wp, sizeof (pmcwork_t), _wp) == -1) {
1533 NOREAD(pmcwork_t, _wp);
1534 mdb_free(wp, sizeof (pmcwork_t));
1535 break;
1538 phy = mdb_alloc(sizeof (pmcs_phy_t), UM_SLEEP);
1539 if (wp->phy == NULL) {
1540 _phy = (uintptr_t)wp->last_phy;
1541 } else {
1542 _phy = (uintptr_t)wp->phy;
1546 * If we have a PHY, read it in and get it's handle
1548 if (_phy != (uintptr_t)NULL) {
1549 if (MDB_RD(phy, sizeof (*phy), _phy) == -1) {
1550 NOREAD(pmcs_phy_t, phy);
1551 } else {
1552 devid = phy->device_id;
1556 mdb_free(phy, sizeof (pmcs_phy_t));
1557 mdb_free(wp, sizeof (pmcwork_t));
1558 break;
1562 * The device ID is in the outbound IOMB at word 1
1564 case PMCOUT_SSP_REQUEST_RECEIVED:
1565 devid = LE_32(*(qentryp + 1)) & PMCS_DEVICE_ID_MASK;
1566 break;
1569 * The device ID is in the outbound IOMB at word 2
1571 case PMCOUT_DEVICE_HANDLE_ARRIVED:
1572 case PMCOUT_DEVICE_HANDLE_REMOVED:
1573 devid = LE_32(*(qentryp + 2)) & PMCS_DEVICE_ID_MASK;
1574 break;
1577 * In this (very rare - never seen it) state, the device ID
1578 * comes from the HTAG in the inbound IOMB, which would be word
1579 * 3 in the outbound IOMB
1581 case PMCOUT_GENERAL_EVENT:
1583 * The device ID is in the outbound IOMB at word 3
1585 case PMCOUT_DEVICE_REGISTRATION:
1586 case PMCOUT_DEVICE_INFO:
1587 case PMCOUT_SET_DEVICE_STATE:
1588 case PMCOUT_GET_DEVICE_STATE:
1589 case PMCOUT_SET_DEVICE_INFO:
1590 devid = LE_32(*(qentryp + 3)) & PMCS_DEVICE_ID_MASK;
1591 break;
1594 * Device ID is in the outbound IOMB at word 4
1596 case PMCOUT_SATA_EVENT:
1597 case PMCOUT_SSP_EVENT:
1598 devid = LE_32(*(qentryp + 4)) & PMCS_DEVICE_ID_MASK;
1599 break;
1602 return (devid);
1605 static boolean_t
1606 iomb_is_dev_hdl_specific(uint32_t word0, boolean_t inbound)
1608 uint16_t opcode = word0 & PMCS_IOMB_OPCODE_MASK;
1610 if (inbound) {
1611 switch (opcode) {
1612 case PMCIN_SSP_INI_IO_START:
1613 case PMCIN_SSP_INI_TM_START:
1614 case PMCIN_SSP_INI_EXT_IO_START:
1615 case PMCIN_SSP_TGT_IO_START:
1616 case PMCIN_SSP_TGT_RESPONSE_START:
1617 case PMCIN_SSP_ABORT:
1618 case PMCIN_DEREGISTER_DEVICE_HANDLE:
1619 case PMCIN_SMP_REQUEST:
1620 case PMCIN_SMP_RESPONSE:
1621 case PMCIN_SMP_ABORT:
1622 case PMCIN_ASSISTED_DISCOVERY:
1623 case PMCIN_SATA_HOST_IO_START:
1624 case PMCIN_SATA_ABORT:
1625 case PMCIN_GET_DEVICE_INFO:
1626 case PMCIN_SET_DEVICE_STATE:
1627 case PMCIN_GET_DEVICE_STATE:
1628 return (B_TRUE);
1631 return (B_FALSE);
1634 switch (opcode) {
1635 case PMCOUT_SSP_COMPLETION:
1636 case PMCOUT_SMP_COMPLETION:
1637 case PMCOUT_DEVICE_REGISTRATION:
1638 case PMCOUT_DEREGISTER_DEVICE_HANDLE:
1639 case PMCOUT_GET_DEVICE_HANDLE:
1640 case PMCOUT_SATA_COMPLETION:
1641 case PMCOUT_SATA_EVENT:
1642 case PMCOUT_SSP_EVENT:
1643 case PMCOUT_DEVICE_HANDLE_ARRIVED:
1644 case PMCOUT_SSP_REQUEST_RECEIVED:
1645 case PMCOUT_DEVICE_INFO:
1646 case PMCOUT_FW_FLASH_UPDATE:
1647 case PMCOUT_GENERAL_EVENT:
1648 case PMCOUT_SSP_ABORT:
1649 case PMCOUT_SATA_ABORT:
1650 case PMCOUT_SAS_HW_EVENT_ACK_ACK:
1651 case PMCOUT_SMP_ABORT:
1652 case PMCOUT_DEVICE_HANDLE_REMOVED:
1653 case PMCOUT_SET_DEVICE_STATE:
1654 case PMCOUT_GET_DEVICE_STATE:
1655 case PMCOUT_SET_DEVICE_INFO:
1656 return (B_TRUE);
1659 return (B_FALSE);
1662 static void
1663 dump_one_qentry_outbound(struct pmcs_hw ss, uint32_t *qentryp, int idx,
1664 uint64_t devid_filter)
1666 int qeidx;
1667 uint32_t word0 = LE_32(*qentryp);
1668 uint32_t word1 = LE_32(*(qentryp + 1));
1669 uint8_t iop_event;
1670 uint32_t devid;
1673 * Check to see if we're filtering on a device ID
1675 if (devid_filter != PMCS_INVALID_DEVICE_ID) {
1676 if (!iomb_is_dev_hdl_specific(word0, B_FALSE)) {
1677 return;
1681 * Go find the device id. It might be in the outbound
1682 * IOMB or we may have to go find the work structure and
1683 * get it from there.
1685 devid = get_devid_from_ob_iomb(ss, qentryp,
1686 word0 & PMCS_IOMB_OPCODE_MASK);
1687 if ((devid == PMCS_INVALID_DEVICE_ID) ||
1688 (devid_filter != devid)) {
1689 return;
1693 mdb_printf("Entry #%02d\n", idx);
1694 mdb_inc_indent(2);
1696 mdb_printf("Header: 0x%08x (", word0);
1697 if (word0 & PMCS_IOMB_VALID) {
1698 mdb_printf("VALID, ");
1700 if (word0 & PMCS_IOMB_HIPRI) {
1701 mdb_printf("HIPRI, ");
1703 mdb_printf("OBID=%d, ",
1704 (word0 & PMCS_IOMB_OBID_MASK) >> PMCS_IOMB_OBID_SHIFT);
1705 mdb_printf("CAT=%s, ",
1706 iomb_cat((word0 & PMCS_IOMB_CAT_MASK) >> PMCS_IOMB_CAT_SHIFT));
1707 mdb_printf("OPCODE=%s",
1708 outbound_iomb_opcode(word0 & PMCS_IOMB_OPCODE_MASK));
1709 if ((word0 & PMCS_IOMB_OPCODE_MASK) == PMCOUT_SAS_HW_EVENT) {
1710 iop_event = IOP_EVENT_EVENT(word1);
1711 mdb_printf(" <%s>", iomb_event(iop_event));
1713 mdb_printf(")\n");
1715 mdb_printf("Remaining Payload:\n");
1717 mdb_inc_indent(2);
1718 for (qeidx = 1; qeidx < (PMCS_QENTRY_SIZE / 4); qeidx++) {
1719 mdb_printf("%08x ", LE_32(*(qentryp + qeidx)));
1721 mdb_printf("\n");
1722 mdb_dec_indent(4);
1725 static void
1726 display_outbound_queues(struct pmcs_hw ss, uint64_t devid_filter,
1727 uint_t verbose)
1729 int idx, qidx;
1730 uintptr_t obqp;
1731 uint32_t *cip;
1732 uint32_t *qentryp = mdb_alloc(PMCS_QENTRY_SIZE, UM_SLEEP);
1733 uint32_t last_consumed, oqpi;
1735 mdb_printf("\n");
1736 mdb_printf("Outbound Queues\n");
1737 mdb_printf("---------------\n");
1739 mdb_inc_indent(2);
1741 for (qidx = 0; qidx < PMCS_NOQ; qidx++) {
1742 obqp = (uintptr_t)ss.oqp[qidx];
1744 if (obqp == (uintptr_t)NULL) {
1745 mdb_printf("No outbound queue ptr for queue #%d\n",
1746 qidx);
1747 continue;
1750 mdb_printf("Outbound Queue #%d (Queue Type = %s)\n", qidx,
1751 obq_type(qidx));
1753 * Chip is the producer, so read the actual producer index
1754 * and not the driver's version
1756 cip = (uint32_t *)((void *)ss.cip);
1757 if (MDB_RD(&oqpi, 4, cip + OQPI_BASE_OFFSET +
1758 (qidx * 4)) == -1) {
1759 mdb_warn("Couldn't read oqpi\n");
1760 break;
1763 mdb_printf("Producer index: %d Consumer index: %d\n\n",
1764 LE_32(oqpi), ss.oqci[qidx]);
1765 mdb_inc_indent(2);
1767 if (ss.oqci[qidx] == 0) {
1768 last_consumed = ss.ioq_depth - 1;
1769 } else {
1770 last_consumed = ss.oqci[qidx] - 1;
1774 if (!verbose) {
1775 mdb_printf("Last processed entry:\n");
1776 if (MDB_RD(qentryp, PMCS_QENTRY_SIZE,
1777 (obqp + (PMCS_QENTRY_SIZE * last_consumed)))
1778 == -1) {
1779 mdb_warn("Couldn't read queue entry at 0x%p\n",
1780 (obqp + (PMCS_QENTRY_SIZE *
1781 last_consumed)));
1782 break;
1784 dump_one_qentry_outbound(ss, qentryp, last_consumed,
1785 devid_filter);
1786 mdb_printf("\n");
1787 mdb_dec_indent(2);
1788 continue;
1791 for (idx = 0; idx < ss.ioq_depth; idx++) {
1792 if (MDB_RD(qentryp, PMCS_QENTRY_SIZE,
1793 (obqp + (PMCS_QENTRY_SIZE * idx))) == -1) {
1794 mdb_warn("Couldn't read queue entry at 0x%p\n",
1795 (obqp + (PMCS_QENTRY_SIZE * idx)));
1796 break;
1798 dump_one_qentry_outbound(ss, qentryp, idx,
1799 devid_filter);
1802 mdb_printf("\n");
1803 mdb_dec_indent(2);
1806 mdb_dec_indent(2);
1807 mdb_free(qentryp, PMCS_QENTRY_SIZE);
1810 static void
1811 dump_one_qentry_inbound(uint32_t *qentryp, int idx, uint64_t devid_filter)
1813 int qeidx;
1814 uint32_t word0 = LE_32(*qentryp);
1815 uint32_t devid = LE_32(*(qentryp + 2));
1818 * Check to see if we're filtering on a device ID
1820 if (devid_filter != PMCS_INVALID_DEVICE_ID) {
1821 if (iomb_is_dev_hdl_specific(word0, B_TRUE)) {
1822 if (devid_filter != devid) {
1823 return;
1825 } else {
1826 return;
1830 mdb_printf("Entry #%02d\n", idx);
1831 mdb_inc_indent(2);
1833 mdb_printf("Header: 0x%08x (", word0);
1834 if (word0 & PMCS_IOMB_VALID) {
1835 mdb_printf("VALID, ");
1837 if (word0 & PMCS_IOMB_HIPRI) {
1838 mdb_printf("HIPRI, ");
1840 mdb_printf("OBID=%d, ",
1841 (word0 & PMCS_IOMB_OBID_MASK) >> PMCS_IOMB_OBID_SHIFT);
1842 mdb_printf("CAT=%s, ",
1843 iomb_cat((word0 & PMCS_IOMB_CAT_MASK) >> PMCS_IOMB_CAT_SHIFT));
1844 mdb_printf("OPCODE=%s",
1845 inbound_iomb_opcode(word0 & PMCS_IOMB_OPCODE_MASK));
1846 mdb_printf(")\n");
1848 mdb_printf("HTAG: 0x%08x\n", LE_32(*(qentryp + 1)));
1849 mdb_printf("Remaining Payload:\n");
1851 mdb_inc_indent(2);
1852 for (qeidx = 2; qeidx < (PMCS_QENTRY_SIZE / 4); qeidx++) {
1853 mdb_printf("%08x ", LE_32(*(qentryp + qeidx)));
1855 mdb_printf("\n");
1856 mdb_dec_indent(4);
1859 static void
1860 display_inbound_queues(struct pmcs_hw ss, uint64_t devid_filter, uint_t verbose)
1862 int idx, qidx, iqci, last_consumed;
1863 uintptr_t ibqp;
1864 uint32_t *qentryp = mdb_alloc(PMCS_QENTRY_SIZE, UM_SLEEP);
1865 uint32_t *cip;
1867 mdb_printf("\n");
1868 mdb_printf("Inbound Queues\n");
1869 mdb_printf("--------------\n");
1871 mdb_inc_indent(2);
1873 for (qidx = 0; qidx < PMCS_NIQ; qidx++) {
1874 ibqp = (uintptr_t)ss.iqp[qidx];
1876 if (ibqp == (uintptr_t)NULL) {
1877 mdb_printf("No inbound queue ptr for queue #%d\n",
1878 qidx);
1879 continue;
1882 mdb_printf("Inbound Queue #%d (Queue Type = %s)\n", qidx,
1883 ibq_type(qidx));
1885 cip = (uint32_t *)((void *)ss.cip);
1886 if (MDB_RD(&iqci, 4, cip + (qidx * 4)) == -1) {
1887 mdb_warn("Couldn't read iqci\n");
1888 break;
1890 iqci = LE_32(iqci);
1892 mdb_printf("Producer index: %d Consumer index: %d\n\n",
1893 ss.shadow_iqpi[qidx], iqci);
1894 mdb_inc_indent(2);
1896 if (iqci == 0) {
1897 last_consumed = ss.ioq_depth - 1;
1898 } else {
1899 last_consumed = iqci - 1;
1902 if (!verbose) {
1903 mdb_printf("Last processed entry:\n");
1904 if (MDB_RD(qentryp, PMCS_QENTRY_SIZE,
1905 (ibqp + (PMCS_QENTRY_SIZE * last_consumed)))
1906 == -1) {
1907 mdb_warn("Couldn't read queue entry at 0x%p\n",
1908 (ibqp + (PMCS_QENTRY_SIZE *
1909 last_consumed)));
1910 break;
1912 dump_one_qentry_inbound(qentryp, last_consumed,
1913 devid_filter);
1914 mdb_printf("\n");
1915 mdb_dec_indent(2);
1916 continue;
1919 for (idx = 0; idx < ss.ioq_depth; idx++) {
1920 if (MDB_RD(qentryp, PMCS_QENTRY_SIZE,
1921 (ibqp + (PMCS_QENTRY_SIZE * idx))) == -1) {
1922 mdb_warn("Couldn't read queue entry at 0x%p\n",
1923 (ibqp + (PMCS_QENTRY_SIZE * idx)));
1924 break;
1926 dump_one_qentry_inbound(qentryp, idx, devid_filter);
1929 mdb_printf("\n");
1930 mdb_dec_indent(2);
1933 mdb_dec_indent(2);
1934 mdb_free(qentryp, PMCS_QENTRY_SIZE);
1938 * phy is our copy of the PHY structure. phyp is the pointer to the actual
1939 * kernel PHY data structure
1941 static void
1942 display_phy(struct pmcs_phy phy, struct pmcs_phy *phyp, int verbose,
1943 int totals_only)
1945 char *dtype, *speed;
1946 char *yes = "Yes";
1947 char *no = "No";
1948 char *cfgd = no;
1949 char *apend = no;
1950 char *asent = no;
1951 char *dead = no;
1952 char *changed = no;
1953 char route_attr, route_method;
1955 switch (phy.dtype) {
1956 case NOTHING:
1957 dtype = "None";
1958 break;
1959 case SATA:
1960 dtype = "SATA";
1961 if (phy.configured) {
1962 ++sata_phys;
1964 break;
1965 case SAS:
1966 dtype = "SAS";
1967 if (phy.configured) {
1968 ++sas_phys;
1970 break;
1971 case EXPANDER:
1972 dtype = "EXP";
1973 if (phy.configured) {
1974 ++exp_phys;
1976 break;
1979 if (phy.dtype == NOTHING) {
1980 empty_phys++;
1981 } else if ((phy.dtype == EXPANDER) && phy.configured) {
1982 num_expanders++;
1985 if (totals_only) {
1986 return;
1989 switch (phy.link_rate) {
1990 case SAS_LINK_RATE_1_5GBIT:
1991 speed = "1.5Gb/s";
1992 break;
1993 case SAS_LINK_RATE_3GBIT:
1994 speed = "3 Gb/s";
1995 break;
1996 case SAS_LINK_RATE_6GBIT:
1997 speed = "6 Gb/s";
1998 break;
1999 default:
2000 speed = "N/A";
2001 break;
2004 if ((phy.dtype != NOTHING) || verbose) {
2005 print_sas_address(&phy);
2007 if (phy.device_id != PMCS_INVALID_DEVICE_ID) {
2008 mdb_printf(" %3d %4d %6s %4s ",
2009 phy.device_id, phy.phynum, speed, dtype);
2010 } else {
2011 mdb_printf(" N/A %4d %6s %4s ",
2012 phy.phynum, speed, dtype);
2015 if (verbose) {
2016 if (phy.abort_sent) {
2017 asent = yes;
2019 if (phy.abort_pending) {
2020 apend = yes;
2022 if (phy.configured) {
2023 cfgd = yes;
2025 if (phy.dead) {
2026 dead = yes;
2028 if (phy.changed) {
2029 changed = yes;
2032 switch (phy.routing_attr) {
2033 case SMP_ROUTING_DIRECT:
2034 route_attr = 'D';
2035 break;
2036 case SMP_ROUTING_SUBTRACTIVE:
2037 route_attr = 'S';
2038 break;
2039 case SMP_ROUTING_TABLE:
2040 route_attr = 'T';
2041 break;
2042 default:
2043 route_attr = '?';
2044 break;
2047 switch (phy.routing_method) {
2048 case SMP_ROUTING_DIRECT:
2049 route_method = 'D';
2050 break;
2051 case SMP_ROUTING_SUBTRACTIVE:
2052 route_method = 'S';
2053 break;
2054 case SMP_ROUTING_TABLE:
2055 route_method = 'T';
2056 break;
2057 default:
2058 route_attr = '?';
2059 break;
2062 mdb_printf("%-4s %-4s %-4s %-4s %-4s %3d %3c/%1c %3d "
2063 "%1d 0x%p ", cfgd, apend, asent, changed, dead,
2064 phy.ref_count, route_attr, route_method,
2065 phy.enum_attempts, phy.reenumerate, phy.phy_lock);
2068 mdb_printf("Path: %s\n", phy.path);
2071 * In verbose mode, on the next line print the drill down
2072 * info to see either the DISCOVER response or the REPORT
2073 * GENERAL response depending on the PHY's dtype
2075 if (verbose) {
2076 uintptr_t tphyp = (uintptr_t)phyp;
2078 mdb_inc_indent(4);
2079 switch (phy.dtype) {
2080 case EXPANDER:
2081 if (!phy.configured) {
2082 break;
2084 mdb_printf("REPORT GENERAL response: %p::"
2085 "print smp_report_general_resp_t\n",
2086 (tphyp + offsetof(struct pmcs_phy,
2087 rg_resp)));
2088 break;
2089 case SAS:
2090 case SATA:
2091 mdb_printf("DISCOVER response: %p::"
2092 "print smp_discover_resp_t\n",
2093 (tphyp + offsetof(struct pmcs_phy,
2094 disc_resp)));
2095 break;
2096 default:
2097 break;
2099 mdb_dec_indent(4);
2104 static void
2105 display_phys(struct pmcs_hw ss, int verbose, struct pmcs_phy *parent, int level,
2106 int totals_only)
2108 pmcs_phy_t phy;
2109 pmcs_phy_t *pphy = parent;
2111 mdb_inc_indent(3);
2113 if (parent == NULL) {
2114 pphy = (pmcs_phy_t *)ss.root_phys;
2115 } else {
2116 pphy = (pmcs_phy_t *)parent;
2119 if (level == 0) {
2120 sas_phys = 0;
2121 sata_phys = 0;
2122 exp_phys = 0;
2123 num_expanders = 0;
2124 empty_phys = 0;
2127 if (!totals_only) {
2128 if (level == 0) {
2129 mdb_printf("PHY information\n");
2131 mdb_printf("--------\n");
2132 mdb_printf("Level %2d\n", level);
2133 mdb_printf("--------\n");
2134 mdb_printf("SAS Address Hdl Phy# Speed Type ");
2136 if (verbose) {
2137 mdb_printf("Cfgd AbtP AbtS Chgd Dead Ref RtA/M Enm R "
2138 "Lock\n");
2139 } else {
2140 mdb_printf("\n");
2144 while (pphy) {
2145 if (MDB_RD(&phy, sizeof (phy), (uintptr_t)pphy) == -1) {
2146 NOREAD(pmcs_phy_t, phy);
2147 break;
2150 display_phy(phy, pphy, verbose, totals_only);
2152 if (phy.children) {
2153 display_phys(ss, verbose, phy.children, level + 1,
2154 totals_only);
2155 if (!totals_only) {
2156 mdb_printf("\n");
2160 pphy = phy.sibling;
2163 mdb_dec_indent(3);
2165 if (level == 0) {
2166 if (verbose) {
2167 mdb_printf("%19s %d (%d SAS + %d SATA + %d SMP) "
2168 "(+%d subsidiary + %d empty)\n", "Occupied PHYs:",
2169 (sas_phys + sata_phys + num_expanders),
2170 sas_phys, sata_phys, num_expanders,
2171 (exp_phys - num_expanders), empty_phys);
2172 } else {
2173 mdb_printf("%19s %d (%d SAS + %d SATA + %d SMP)\n",
2174 "Occupied PHYs:",
2175 (sas_phys + sata_phys + num_expanders),
2176 sas_phys, sata_phys, num_expanders);
2182 * filter is used to indicate whether we are filtering log messages based
2183 * on "instance". The other filtering (based on options) depends on the
2184 * values that are passed in for "sas_addr" and "phy_path".
2186 * MAX_INST_STRLEN is the largest string size from which we will attempt
2187 * to convert to an instance number. The string will be formed up as
2188 * "0t<inst>\0" so that mdb_strtoull can parse it properly.
2190 #define MAX_INST_STRLEN 8
2192 static int
2193 pmcs_dump_tracelog(boolean_t filter, int instance, uint64_t tail_lines,
2194 const char *phy_path, uint64_t sas_address, uint64_t verbose)
2196 pmcs_tbuf_t *tbuf_addr;
2197 uint_t tbuf_idx;
2198 pmcs_tbuf_t tbuf;
2199 boolean_t wrap, elem_filtered;
2200 uint_t start_idx, elems_to_print, idx, tbuf_num_elems;
2201 char *bufp;
2202 char elem_inst[MAX_INST_STRLEN], ei_idx;
2203 uint64_t sas_addr;
2204 uint8_t *sas_addressp;
2206 /* Get the address of the first element */
2207 if (mdb_readvar(&tbuf_addr, "pmcs_tbuf") == -1) {
2208 mdb_warn("can't read pmcs_tbuf");
2209 return (DCMD_ERR);
2212 /* Get the total number */
2213 if (mdb_readvar(&tbuf_num_elems, "pmcs_tbuf_num_elems") == -1) {
2214 mdb_warn("can't read pmcs_tbuf_num_elems");
2215 return (DCMD_ERR);
2218 /* Get the current index */
2219 if (mdb_readvar(&tbuf_idx, "pmcs_tbuf_idx") == -1) {
2220 mdb_warn("can't read pmcs_tbuf_idx");
2221 return (DCMD_ERR);
2224 /* Indicator as to whether the buffer has wrapped */
2225 if (mdb_readvar(&wrap, "pmcs_tbuf_wrap") == -1) {
2226 mdb_warn("can't read pmcs_tbuf_wrap");
2227 return (DCMD_ERR);
2231 * On little-endian systems, the SAS address passed in will be
2232 * byte swapped. Take care of that here.
2234 #if defined(_LITTLE_ENDIAN)
2235 sas_addr = ((sas_address << 56) |
2236 ((sas_address << 40) & 0xff000000000000ULL) |
2237 ((sas_address << 24) & 0xff0000000000ULL) |
2238 ((sas_address << 8) & 0xff00000000ULL) |
2239 ((sas_address >> 8) & 0xff000000ULL) |
2240 ((sas_address >> 24) & 0xff0000ULL) |
2241 ((sas_address >> 40) & 0xff00ULL) |
2242 (sas_address >> 56));
2243 #else
2244 sas_addr = sas_address;
2245 #endif
2246 sas_addressp = (uint8_t *)&sas_addr;
2248 /* Ensure the tail number isn't greater than the size of the log */
2249 if (tail_lines > tbuf_num_elems) {
2250 tail_lines = tbuf_num_elems;
2253 /* Figure out where we start and stop */
2254 if (wrap) {
2255 if (tail_lines) {
2256 /* Do we need to wrap backwards? */
2257 if (tail_lines > tbuf_idx) {
2258 start_idx = tbuf_num_elems - (tail_lines -
2259 tbuf_idx);
2260 } else {
2261 start_idx = tbuf_idx - tail_lines;
2263 elems_to_print = tail_lines;
2264 } else {
2265 start_idx = tbuf_idx;
2266 elems_to_print = tbuf_num_elems;
2268 } else {
2269 if (tail_lines > tbuf_idx) {
2270 tail_lines = tbuf_idx;
2272 if (tail_lines) {
2273 start_idx = tbuf_idx - tail_lines;
2274 elems_to_print = tail_lines;
2275 } else {
2276 start_idx = 0;
2277 elems_to_print = tbuf_idx;
2281 idx = start_idx;
2283 /* Dump the buffer contents */
2284 while (elems_to_print != 0) {
2285 if (MDB_RD(&tbuf, sizeof (pmcs_tbuf_t), (tbuf_addr + idx))
2286 == -1) {
2287 NOREAD(tbuf, (tbuf_addr + idx));
2288 return (DCMD_ERR);
2292 * Check for filtering on HBA instance
2294 elem_filtered = B_FALSE;
2296 if (filter) {
2297 bufp = tbuf.buf;
2298 /* Skip the driver name */
2299 while (*bufp < '0' || *bufp > '9') {
2300 bufp++;
2303 ei_idx = 0;
2304 elem_inst[ei_idx++] = '0';
2305 elem_inst[ei_idx++] = 't';
2306 while (*bufp != ':' && ei_idx < (MAX_INST_STRLEN - 1)) {
2307 elem_inst[ei_idx++] = *bufp;
2308 bufp++;
2310 elem_inst[ei_idx] = 0;
2312 /* Get the instance */
2313 if ((int)mdb_strtoull(elem_inst) != instance) {
2314 elem_filtered = B_TRUE;
2318 if (!elem_filtered && (phy_path || sas_address)) {
2320 * This message is not being filtered by HBA instance.
2321 * Now check to see if we're filtering based on
2322 * PHY path or SAS address.
2323 * Filtering is an "OR" operation. So, if any of the
2324 * criteria matches, this message will be printed.
2326 elem_filtered = B_TRUE;
2328 if (phy_path != NULL) {
2329 if (strncmp(phy_path, tbuf.phy_path,
2330 PMCS_TBUF_UA_MAX_SIZE) == 0) {
2331 elem_filtered = B_FALSE;
2334 if (sas_address != 0) {
2335 if (memcmp(sas_addressp, tbuf.phy_sas_address,
2336 8) == 0) {
2337 elem_filtered = B_FALSE;
2342 if (!elem_filtered) {
2344 * If the -v flag was given, print the firmware
2345 * timestamp along with the clock time
2347 mdb_printf("%Y.%09ld ", tbuf.timestamp);
2348 if (verbose) {
2349 mdb_printf("(0x%" PRIx64 ") ",
2350 tbuf.fw_timestamp);
2352 mdb_printf("%s\n", tbuf.buf);
2355 --elems_to_print;
2356 if (++idx == tbuf_num_elems) {
2357 idx = 0;
2361 return (DCMD_OK);
2365 * Walkers
2367 static int
2368 targets_walk_i(mdb_walk_state_t *wsp)
2370 if (wsp->walk_addr == (uintptr_t)NULL) {
2371 mdb_warn("Can not perform global walk\n");
2372 return (WALK_ERR);
2376 * Address provided belongs to HBA softstate. Get the targets pointer
2377 * to begin the walk.
2379 if (mdb_vread(&ss, sizeof (pmcs_hw_t), wsp->walk_addr) !=
2380 sizeof (pmcs_hw_t)) {
2381 mdb_warn("Unable to read HBA softstate\n");
2382 return (WALK_ERR);
2385 if (targets == NULL) {
2386 targets = mdb_alloc(sizeof (targets) * ss.max_dev, UM_SLEEP);
2389 if (MDB_RD(targets, sizeof (targets) * ss.max_dev, ss.targets) == -1) {
2390 NOREAD(targets, ss.targets);
2391 return (WALK_ERR);
2394 target_idx = 0;
2395 wsp->walk_addr = (uintptr_t)(targets[0]);
2396 wsp->walk_data = mdb_alloc(sizeof (pmcs_xscsi_t), UM_SLEEP);
2398 return (WALK_NEXT);
2401 static int
2402 targets_walk_s(mdb_walk_state_t *wsp)
2404 int status;
2406 if (target_idx == ss.max_dev) {
2407 return (WALK_DONE);
2410 if (mdb_vread(wsp->walk_data, sizeof (pmcs_xscsi_t),
2411 wsp->walk_addr) == -1) {
2412 mdb_warn("Failed to read target at %p", (void *)wsp->walk_addr);
2413 return (WALK_DONE);
2416 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
2417 wsp->walk_cbdata);
2419 do {
2420 wsp->walk_addr = (uintptr_t)(targets[++target_idx]);
2421 } while ((wsp->walk_addr == (uintptr_t)NULL) &&
2422 (target_idx < ss.max_dev));
2424 if (target_idx == ss.max_dev) {
2425 return (WALK_DONE);
2428 return (status);
2431 static void
2432 targets_walk_f(mdb_walk_state_t *wsp)
2434 mdb_free(wsp->walk_data, sizeof (pmcs_xscsi_t));
2438 static pmcs_phy_t *
2439 pmcs_next_sibling(pmcs_phy_t *phyp)
2441 pmcs_phy_t parent;
2444 * First, if this is a root PHY, there are no more siblings
2446 if (phyp->level == 0) {
2447 return (NULL);
2451 * Otherwise, next sibling is the parent's sibling
2453 while (phyp->level > 0) {
2454 if (mdb_vread(&parent, sizeof (pmcs_phy_t),
2455 (uintptr_t)phyp->parent) == -1) {
2456 mdb_warn("pmcs_next_sibling: Failed to read PHY at %p",
2457 (void *)phyp->parent);
2458 return (NULL);
2461 if (parent.sibling != NULL) {
2462 break;
2466 * If this PHY's sibling is NULL and it's a root phy,
2467 * we're done.
2469 if (parent.level == 0) {
2470 return (NULL);
2473 phyp = phyp->parent;
2476 return (parent.sibling);
2479 static int
2480 phy_walk_i(mdb_walk_state_t *wsp)
2482 if (wsp->walk_addr == (uintptr_t)NULL) {
2483 mdb_warn("Can not perform global walk\n");
2484 return (WALK_ERR);
2488 * Address provided belongs to HBA softstate. Get the targets pointer
2489 * to begin the walk.
2491 if (mdb_vread(&ss, sizeof (pmcs_hw_t), wsp->walk_addr) !=
2492 sizeof (pmcs_hw_t)) {
2493 mdb_warn("Unable to read HBA softstate\n");
2494 return (WALK_ERR);
2497 wsp->walk_addr = (uintptr_t)(ss.root_phys);
2498 wsp->walk_data = mdb_alloc(sizeof (pmcs_phy_t), UM_SLEEP);
2500 return (WALK_NEXT);
2503 static int
2504 phy_walk_s(mdb_walk_state_t *wsp)
2506 pmcs_phy_t *phyp, *nphyp;
2507 int status;
2509 if (mdb_vread(wsp->walk_data, sizeof (pmcs_phy_t),
2510 wsp->walk_addr) == -1) {
2511 mdb_warn("phy_walk_s: Failed to read PHY at %p",
2512 (void *)wsp->walk_addr);
2513 return (WALK_DONE);
2516 status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
2517 wsp->walk_cbdata);
2519 phyp = (pmcs_phy_t *)wsp->walk_data;
2520 if (phyp->children) {
2521 wsp->walk_addr = (uintptr_t)(phyp->children);
2522 } else {
2523 wsp->walk_addr = (uintptr_t)(phyp->sibling);
2526 if (wsp->walk_addr == (uintptr_t)NULL) {
2528 * We reached the end of this sibling list. Trudge back up
2529 * to the parent and find the next sibling after the expander
2530 * we just finished traversing, if there is one.
2532 nphyp = pmcs_next_sibling(phyp);
2534 if (nphyp == NULL) {
2535 return (WALK_DONE);
2538 wsp->walk_addr = (uintptr_t)nphyp;
2541 return (status);
2544 static void
2545 phy_walk_f(mdb_walk_state_t *wsp)
2547 mdb_free(wsp->walk_data, sizeof (pmcs_phy_t));
2550 static void
2551 display_matching_work(struct pmcs_hw ss, uintmax_t index, uintmax_t snum,
2552 uintmax_t tag_type)
2554 int idx;
2555 pmcwork_t work, *wp = &work;
2556 uintptr_t _wp;
2557 boolean_t printed_header = B_FALSE;
2558 uint32_t mask, mask_val, match_val;
2559 char *match_type;
2561 if (index != UINT_MAX) {
2562 match_type = "index";
2563 mask = PMCS_TAG_INDEX_MASK;
2564 mask_val = index << PMCS_TAG_INDEX_SHIFT;
2565 match_val = index;
2566 } else if (snum != UINT_MAX) {
2567 match_type = "serial number";
2568 mask = PMCS_TAG_SERNO_MASK;
2569 mask_val = snum << PMCS_TAG_SERNO_SHIFT;
2570 match_val = snum;
2571 } else {
2572 switch (tag_type) {
2573 case PMCS_TAG_TYPE_NONE:
2574 match_type = "tag type NONE";
2575 break;
2576 case PMCS_TAG_TYPE_CBACK:
2577 match_type = "tag type CBACK";
2578 break;
2579 case PMCS_TAG_TYPE_WAIT:
2580 match_type = "tag type WAIT";
2581 break;
2583 mask = PMCS_TAG_TYPE_MASK;
2584 mask_val = tag_type << PMCS_TAG_TYPE_SHIFT;
2585 match_val = tag_type;
2588 _wp = (uintptr_t)ss.work;
2590 for (idx = 0; idx < ss.max_cmd; idx++, _wp += sizeof (pmcwork_t)) {
2591 if (MDB_RD(&work, sizeof (pmcwork_t), _wp) == -1) {
2592 NOREAD(pmcwork_t, _wp);
2593 continue;
2596 if ((work.htag & mask) != mask_val) {
2597 continue;
2600 if (printed_header == B_FALSE) {
2601 if (tag_type) {
2602 mdb_printf("\nWork structures matching %s\n\n",
2603 match_type, match_val);
2604 } else {
2605 mdb_printf("\nWork structures matching %s of "
2606 "0x%x\n\n", match_type, match_val);
2608 mdb_printf("%8s %10s %20s %8s %8s O D\n",
2609 "HTag", "State", "Phy Path", "Target", "Timer");
2610 printed_header = B_TRUE;
2613 display_one_work(wp, 0, 0);
2616 if (!printed_header) {
2617 mdb_printf("No work structure matches found\n");
2621 static int
2622 pmcs_tag(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2624 struct pmcs_hw ss;
2625 uintmax_t tag_type = UINT_MAX;
2626 uintmax_t snum = UINT_MAX;
2627 uintmax_t index = UINT_MAX;
2628 int args = 0;
2629 void *pmcs_state;
2630 char *state_str;
2631 struct dev_info dip;
2633 if (!(flags & DCMD_ADDRSPEC)) {
2634 pmcs_state = NULL;
2635 if (mdb_readvar(&pmcs_state, "pmcs_softc_state") == -1) {
2636 mdb_warn("can't read pmcs_softc_state");
2637 return (DCMD_ERR);
2639 if (mdb_pwalk_dcmd("genunix`softstate", "pmcs`pmcs_tag", argc,
2640 argv, (uintptr_t)pmcs_state) == -1) {
2641 mdb_warn("mdb_pwalk_dcmd failed");
2642 return (DCMD_ERR);
2644 return (DCMD_OK);
2647 if (mdb_getopts(argc, argv,
2648 'i', MDB_OPT_UINT64, &index,
2649 's', MDB_OPT_UINT64, &snum,
2650 't', MDB_OPT_UINT64, &tag_type) != argc)
2651 return (DCMD_USAGE);
2654 * Count the number of supplied options and make sure they are
2655 * within appropriate ranges. If they're set to UINT_MAX, that means
2656 * they were not supplied, in which case reset them to 0.
2658 if (index != UINT_MAX) {
2659 args++;
2660 if (index > PMCS_TAG_INDEX_MASK) {
2661 mdb_warn("Index is out of range\n");
2662 return (DCMD_USAGE);
2666 if (tag_type != UINT_MAX) {
2667 args++;
2668 switch (tag_type) {
2669 case PMCS_TAG_TYPE_NONE:
2670 case PMCS_TAG_TYPE_CBACK:
2671 case PMCS_TAG_TYPE_WAIT:
2672 break;
2673 default:
2674 mdb_warn("Invalid tag type\n");
2675 return (DCMD_USAGE);
2679 if (snum != UINT_MAX) {
2680 args++;
2681 if (snum > (PMCS_TAG_SERNO_MASK >> PMCS_TAG_SERNO_SHIFT)) {
2682 mdb_warn("Serial number is out of range\n");
2683 return (DCMD_USAGE);
2688 * Make sure 1 and only 1 option is specified
2690 if ((args == 0) || (args > 1)) {
2691 mdb_warn("Exactly one of -i, -s and -t must be specified\n");
2692 return (DCMD_USAGE);
2695 if (MDB_RD(&ss, sizeof (ss), addr) == -1) {
2696 NOREAD(pmcs_hw_t, addr);
2697 return (DCMD_ERR);
2700 if (MDB_RD(&dip, sizeof (struct dev_info), ss.dip) == -1) {
2701 NOREAD(pmcs_hw_t, addr);
2702 return (DCMD_ERR);
2705 /* processing completed */
2707 if (((flags & DCMD_ADDRSPEC) && !(flags & DCMD_LOOP)) ||
2708 (flags & DCMD_LOOPFIRST)) {
2709 if ((flags & DCMD_LOOP) && !(flags & DCMD_LOOPFIRST))
2710 mdb_printf("\n");
2711 mdb_printf("%16s %9s %4s B C WorkFlags wserno DbgMsk %16s\n",
2712 "Address", "State", "Inst", "DIP");
2713 mdb_printf("================================="
2714 "============================================\n");
2717 switch (ss.state) {
2718 case STATE_NIL:
2719 state_str = "Invalid";
2720 break;
2721 case STATE_PROBING:
2722 state_str = "Probing";
2723 break;
2724 case STATE_RUNNING:
2725 state_str = "Running";
2726 break;
2727 case STATE_UNPROBING:
2728 state_str = "Unprobing";
2729 break;
2730 case STATE_DEAD:
2731 state_str = "Dead";
2732 break;
2733 case STATE_IN_RESET:
2734 state_str = "In Reset";
2735 break;
2738 mdb_printf("%16p %9s %4d %1d %1d 0x%08x 0x%04x 0x%04x %16p\n", addr,
2739 state_str, dip.devi_instance, ss.blocked, ss.configuring,
2740 ss.work_flags, ss.wserno, ss.debug_mask, ss.dip);
2741 mdb_printf("\n");
2743 mdb_inc_indent(4);
2744 display_matching_work(ss, index, snum, tag_type);
2745 mdb_dec_indent(4);
2746 mdb_printf("\n");
2748 return (DCMD_OK);
2751 #ifndef _KMDB
2752 static int
2753 pmcs_dump_fwlog(struct pmcs_hw *ss, int instance, const char *ofile)
2755 uint8_t *fwlogp;
2756 int ofilefd = -1;
2757 char ofilename[MAXPATHLEN];
2758 int rval = DCMD_OK;
2760 if (ss->fwlogp == NULL) {
2761 mdb_warn("Firmware event log disabled for instance %d",
2762 instance);
2763 return (DCMD_OK);
2766 if (snprintf(ofilename, MAXPATHLEN, "%s%d", ofile, instance) >
2767 MAXPATHLEN) {
2768 mdb_warn("Output filename is too long for instance %d",
2769 instance);
2770 return (DCMD_ERR);
2773 fwlogp = mdb_alloc(PMCS_FWLOG_SIZE, UM_SLEEP);
2775 if (MDB_RD(fwlogp, PMCS_FWLOG_SIZE, ss->fwlogp) == -1) {
2776 NOREAD(fwlogp, ss->fwlogp);
2777 rval = DCMD_ERR;
2778 goto cleanup;
2781 ofilefd = open(ofilename, O_WRONLY | O_CREAT,
2782 S_IRUSR | S_IRGRP | S_IROTH);
2783 if (ofilefd < 0) {
2784 mdb_warn("Unable to open '%s' to dump instance %d event log",
2785 ofilename, instance);
2786 rval = DCMD_ERR;
2787 goto cleanup;
2790 if (write(ofilefd, fwlogp, PMCS_FWLOG_SIZE) != PMCS_FWLOG_SIZE) {
2791 mdb_warn("Failed to write %d bytes to output file: instance %d",
2792 PMCS_FWLOG_SIZE, instance);
2793 rval = DCMD_ERR;
2794 goto cleanup;
2797 mdb_printf("Event log for instance %d written to %s\n", instance,
2798 ofilename);
2800 cleanup:
2801 if (ofilefd >= 0) {
2802 close(ofilefd);
2804 mdb_free(fwlogp, PMCS_FWLOG_SIZE);
2805 return (rval);
2808 static int
2809 pmcs_fwlog(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2811 void *pmcs_state;
2812 const char *ofile = NULL;
2813 struct pmcs_hw ss;
2814 struct dev_info dip;
2816 if (mdb_getopts(argc, argv, 'o', MDB_OPT_STR, &ofile, NULL) != argc) {
2817 return (DCMD_USAGE);
2820 if (ofile == NULL) {
2821 mdb_printf("No output file specified\n");
2822 return (DCMD_USAGE);
2825 if (!(flags & DCMD_ADDRSPEC)) {
2826 pmcs_state = NULL;
2827 if (mdb_readvar(&pmcs_state, "pmcs_softc_state") == -1) {
2828 mdb_warn("can't read pmcs_softc_state");
2829 return (DCMD_ERR);
2831 if (mdb_pwalk_dcmd("genunix`softstate", "pmcs`pmcs_fwlog", argc,
2832 argv, (uintptr_t)pmcs_state) == -1) {
2833 mdb_warn("mdb_pwalk_dcmd failed for pmcs_log");
2834 return (DCMD_ERR);
2836 return (DCMD_OK);
2839 if (MDB_RD(&ss, sizeof (ss), addr) == -1) {
2840 NOREAD(pmcs_hw_t, addr);
2841 return (DCMD_ERR);
2844 if (MDB_RD(&dip, sizeof (struct dev_info), ss.dip) == -1) {
2845 NOREAD(pmcs_hw_t, addr);
2846 return (DCMD_ERR);
2849 return (pmcs_dump_fwlog(&ss, dip.devi_instance, ofile));
2851 #endif /* _KMDB */
2853 static int
2854 pmcs_log(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2856 void *pmcs_state;
2857 struct pmcs_hw ss;
2858 struct dev_info dip;
2859 const char *match_phy_path = NULL;
2860 uint64_t match_sas_address = 0, tail_lines = 0;
2861 uint_t verbose = 0;
2863 if (!(flags & DCMD_ADDRSPEC)) {
2864 pmcs_state = NULL;
2865 if (mdb_readvar(&pmcs_state, "pmcs_softc_state") == -1) {
2866 mdb_warn("can't read pmcs_softc_state");
2867 return (DCMD_ERR);
2869 if (mdb_pwalk_dcmd("genunix`softstate", "pmcs`pmcs_log", argc,
2870 argv, (uintptr_t)pmcs_state) == -1) {
2871 mdb_warn("mdb_pwalk_dcmd failed for pmcs_log");
2872 return (DCMD_ERR);
2874 return (DCMD_OK);
2877 if (mdb_getopts(argc, argv,
2878 'l', MDB_OPT_UINT64, &tail_lines,
2879 'p', MDB_OPT_STR, &match_phy_path,
2880 's', MDB_OPT_UINT64, &match_sas_address,
2881 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2882 NULL) != argc) {
2883 return (DCMD_USAGE);
2886 if (MDB_RD(&ss, sizeof (ss), addr) == -1) {
2887 NOREAD(pmcs_hw_t, addr);
2888 return (DCMD_ERR);
2891 if (MDB_RD(&dip, sizeof (struct dev_info), ss.dip) == -1) {
2892 NOREAD(pmcs_hw_t, addr);
2893 return (DCMD_ERR);
2896 if (!(flags & DCMD_LOOP)) {
2897 return (pmcs_dump_tracelog(B_TRUE, dip.devi_instance,
2898 tail_lines, match_phy_path, match_sas_address, verbose));
2899 } else if (flags & DCMD_LOOPFIRST) {
2900 return (pmcs_dump_tracelog(B_FALSE, 0, tail_lines,
2901 match_phy_path, match_sas_address, verbose));
2902 } else {
2903 return (DCMD_OK);
2907 static int
2908 pmcs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2910 struct pmcs_hw ss;
2911 uint_t verbose = FALSE;
2912 uint_t phy_info = FALSE;
2913 uint_t hw_info = FALSE;
2914 uint_t target_info = FALSE;
2915 uint_t work_info = FALSE;
2916 uint_t ic_info = FALSE;
2917 uint_t iport_info = FALSE;
2918 uint_t waitqs_info = FALSE;
2919 uint_t ibq = FALSE;
2920 uint_t obq = FALSE;
2921 uint_t tgt_phy_count = FALSE;
2922 uint_t compq = FALSE;
2923 uint_t unconfigured = FALSE;
2924 uint_t damap_info = FALSE;
2925 uint_t dtc_info = FALSE;
2926 uint_t wserno = FALSE;
2927 uint_t fwlog = FALSE;
2928 boolean_t devid_filter = FALSE;
2929 uintptr_t pdevid;
2930 uint32_t devid;
2931 int rv = DCMD_OK;
2932 void *pmcs_state;
2933 char *state_str;
2934 struct dev_info dip;
2935 per_iport_setting_t pis;
2937 if (!(flags & DCMD_ADDRSPEC)) {
2938 pmcs_state = NULL;
2939 if (mdb_readvar(&pmcs_state, "pmcs_softc_state") == -1) {
2940 mdb_warn("can't read pmcs_softc_state");
2941 return (DCMD_ERR);
2943 if (mdb_pwalk_dcmd("genunix`softstate", "pmcs`pmcs", argc, argv,
2944 (uintptr_t)pmcs_state) == -1) {
2945 mdb_warn("mdb_pwalk_dcmd failed");
2946 return (DCMD_ERR);
2948 return (DCMD_OK);
2951 if (mdb_getopts(argc, argv,
2952 'c', MDB_OPT_SETBITS, TRUE, &compq,
2953 'd', MDB_OPT_SETBITS, TRUE, &dtc_info,
2954 'D', MDB_OPT_UINTPTR_SET, &devid_filter, &pdevid,
2955 'e', MDB_OPT_SETBITS, TRUE, &fwlog,
2956 'h', MDB_OPT_SETBITS, TRUE, &hw_info,
2957 'i', MDB_OPT_SETBITS, TRUE, &ic_info,
2958 'I', MDB_OPT_SETBITS, TRUE, &iport_info,
2959 'm', MDB_OPT_SETBITS, TRUE, &damap_info,
2960 'p', MDB_OPT_SETBITS, TRUE, &phy_info,
2961 'q', MDB_OPT_SETBITS, TRUE, &ibq,
2962 'Q', MDB_OPT_SETBITS, TRUE, &obq,
2963 's', MDB_OPT_SETBITS, TRUE, &wserno,
2964 't', MDB_OPT_SETBITS, TRUE, &target_info,
2965 'T', MDB_OPT_SETBITS, TRUE, &tgt_phy_count,
2966 'u', MDB_OPT_SETBITS, TRUE, &unconfigured,
2967 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2968 'w', MDB_OPT_SETBITS, TRUE, &work_info,
2969 'W', MDB_OPT_SETBITS, TRUE, &waitqs_info,
2970 NULL) != argc)
2971 return (DCMD_USAGE);
2974 * The 'd' and 'm' options implicitly enable the 'I' option
2976 pis.pis_damap_info = damap_info;
2977 pis.pis_dtc_info = dtc_info;
2978 if (damap_info || dtc_info) {
2979 iport_info = TRUE;
2983 * The -D option is meaningless without -q and/or -Q, and implies
2984 * verbosity.
2986 if (devid_filter) {
2987 devid = (uint64_t)pdevid & 0xffffffff;
2988 if (!ibq && !obq) {
2989 mdb_printf("-D requires either -q or -Q\n");
2990 return (DCMD_USAGE);
2992 if (devid > PMCS_DEVICE_ID_MASK) {
2993 mdb_printf("Device ID invalid\n");
2994 return (DCMD_USAGE);
2996 verbose = TRUE;
2999 if (MDB_RD(&ss, sizeof (ss), addr) == -1) {
3000 NOREAD(pmcs_hw_t, addr);
3001 return (DCMD_ERR);
3004 if (MDB_RD(&dip, sizeof (struct dev_info), ss.dip) == -1) {
3005 NOREAD(pmcs_hw_t, addr);
3006 return (DCMD_ERR);
3009 /* processing completed */
3011 if (((flags & DCMD_ADDRSPEC) && !(flags & DCMD_LOOP)) ||
3012 (flags & DCMD_LOOPFIRST) || phy_info || target_info || hw_info ||
3013 work_info || waitqs_info || ibq || obq || tgt_phy_count || compq ||
3014 unconfigured || fwlog) {
3015 if ((flags & DCMD_LOOP) && !(flags & DCMD_LOOPFIRST))
3016 mdb_printf("\n");
3017 mdb_printf("%16s %9s %4s B C WorkFlags wserno DbgMsk %16s\n",
3018 "Address", "State", "Inst", "DIP");
3019 mdb_printf("================================="
3020 "============================================\n");
3023 switch (ss.state) {
3024 case STATE_NIL:
3025 state_str = "Invalid";
3026 break;
3027 case STATE_PROBING:
3028 state_str = "Probing";
3029 break;
3030 case STATE_RUNNING:
3031 state_str = "Running";
3032 break;
3033 case STATE_UNPROBING:
3034 state_str = "Unprobing";
3035 break;
3036 case STATE_DEAD:
3037 state_str = "Dead";
3038 break;
3039 case STATE_IN_RESET:
3040 state_str = "In Reset";
3041 break;
3044 mdb_printf("%16p %9s %4d %1d %1d 0x%08x 0x%04x 0x%04x %16p\n", addr,
3045 state_str, dip.devi_instance, ss.blocked, ss.configuring,
3046 ss.work_flags, ss.wserno, ss.debug_mask, ss.dip);
3047 mdb_printf("\n");
3049 mdb_inc_indent(4);
3051 if (waitqs_info)
3052 display_waitqs(ss, verbose);
3054 if (hw_info)
3055 display_hwinfo(ss, verbose);
3057 if (phy_info || tgt_phy_count)
3058 display_phys(ss, verbose, NULL, 0, tgt_phy_count);
3060 if (target_info || tgt_phy_count)
3061 display_targets(ss, verbose, tgt_phy_count);
3063 if (work_info || wserno)
3064 display_work(ss, verbose, wserno);
3066 if (ic_info)
3067 display_ic(ss, verbose);
3069 if (ibq)
3070 display_inbound_queues(ss, devid, verbose);
3072 if (obq)
3073 display_outbound_queues(ss, devid, verbose);
3075 if (iport_info)
3076 display_iport(ss, addr, verbose, &pis);
3078 if (compq)
3079 display_completion_queue(ss);
3081 if (unconfigured)
3082 display_unconfigured_targets(addr);
3084 if (fwlog)
3085 display_event_log(ss);
3087 mdb_dec_indent(4);
3089 return (rv);
3092 void
3093 pmcs_help()
3095 mdb_printf("Prints summary information about each pmcs instance.\n"
3096 " -c: Dump the completion queue\n"
3097 " -d: Print per-iport information about device tree children\n"
3098 " -D <device ID>: With -q/-Q, filter by device handle\n"
3099 " -e: Display the in-memory firmware event log\n"
3100 " -h: Print more detailed hardware information\n"
3101 " -i: Print interrupt coalescing information\n"
3102 " -I: Print information about each iport\n"
3103 " -m: Print per-iport information about DAM/damap state\n"
3104 " -p: Print information about each attached PHY\n"
3105 " -q: Dump inbound queues\n"
3106 " -Q: Dump outbound queues\n"
3107 " -s: Dump all work structures sorted by serial number\n"
3108 " -t: Print information about each configured target\n"
3109 " -T: Print target and PHY count summary\n"
3110 " -u: Show SAS address of all unconfigured targets\n"
3111 " -w: Dump work structures\n"
3112 " -W: List pmcs cmds waiting on various queues\n"
3113 " -v: Add verbosity to the above options\n");
3116 void
3117 pmcs_log_help()
3119 mdb_printf("Dump the pmcs log buffer, possibly with filtering.\n"
3120 " -l TAIL_LINES: Dump the last TAIL_LINES messages\n"
3121 " -p PHY_PATH: Dump messages matching PHY_PATH\n"
3122 " -s SAS_ADDRESS: Dump messages matching SAS_ADDRESS\n\n"
3123 "Where: PHY_PATH can be found with ::pmcs -p (e.g. pp04.18.18.01)\n"
3124 " SAS_ADDRESS can be found with ::pmcs -t "
3125 "(e.g. 5000c5000358c221)\n");
3127 void
3128 pmcs_tag_help()
3130 mdb_printf("Print all work structures by matching the tag.\n"
3131 " -i index: Match tag index (0x000 - 0xfff)\n"
3132 " -s serialnumber: Match serial number (0x0000 - 0xffff)\n"
3133 " -t tagtype: Match tag type [NONE(1), CBACK(2), "
3134 "WAIT(3)]\n");
3137 static const mdb_dcmd_t dcmds[] = {
3138 { "pmcs", "?[-cdehiImpQqtTuwWv] [-D <device ID>]",
3139 "print pmcs information", pmcs_dcmd, pmcs_help
3141 { "pmcs_log",
3142 "?[-v] [-p PHY_PATH | -s SAS_ADDRESS | -l TAIL_LINES]",
3143 "dump pmcs log file", pmcs_log, pmcs_log_help
3145 { "pmcs_tag", "?[-t tagtype|-s serialnum|-i index]",
3146 "Find work structures by tag type, serial number or index",
3147 pmcs_tag, pmcs_tag_help
3149 #ifndef _KMDB
3150 { "pmcs_fwlog",
3151 "?-o output_file",
3152 "dump pmcs firmware event log to output_file", pmcs_fwlog, NULL
3154 #endif /* _KMDB */
3155 { NULL }
3158 static const mdb_walker_t walkers[] = {
3159 { "pmcs_targets", "walk target structures",
3160 targets_walk_i, targets_walk_s, targets_walk_f },
3161 { "pmcs_phys", "walk PHY structures",
3162 phy_walk_i, phy_walk_s, phy_walk_f },
3163 { NULL }
3166 static const mdb_modinfo_t modinfo = {
3167 MDB_API_VERSION, dcmds, walkers
3170 const mdb_modinfo_t *
3171 _mdb_init(void)
3173 return (&modinfo);