1
/* A utility program originally written for the Linux OS SCSI subsystem.
2
* Copyright (C) 2000-2013 D. Gilbert
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2, or (at your option)
8
This program outputs information provided by a SCSI LOG SENSE command.
14
25
#include "sg_lib.h"
15
26
#include "sg_cmds_basic.h"
17
/* A utility program originally written for the Linux OS SCSI subsystem.
18
* Copyright (C) 2000-2011 D. Gilbert
19
* This program is free software; you can redistribute it and/or modify
20
* it under the terms of the GNU General Public License as published by
21
* the Free Software Foundation; either version 2, or (at your option)
24
This program outputs information provided by a SCSI LOG SENSE command.
28
static char * version_str = "1.05 20111020"; /* spc4r30 + sbc3r28 */
28
static const char * version_str = "1.11 20130517"; /* spc4r35 + sbc3r30 */
30
30
#define MX_ALLOC_LEN (0xfffc)
31
31
#define SHORT_RESP_LEN 128
576
577
command, SG_LIB_CAT_NOT_READY, SG_LIB_CAT_UNIT_ATTENTION,
577
578
SG_LIB_CAT_ABORTED_COMMAND and -1 for other errors. */
579
do_logs(int sg_fd, unsigned char * resp, int mx_resp_len, int noisy,
580
do_logs(int sg_fd, unsigned char * resp, int mx_resp_len,
580
581
const struct opts_t * optsp)
582
583
int actual_len, res, vb;
590
591
optsp->page_control, optsp->pg_code,
591
592
optsp->subpg_code, optsp->paramp,
592
593
resp, LOG_SENSE_PROBE_ALLOC_LEN,
594
1 /* noisy */, vb))) {
595
596
case SG_LIB_CAT_NOT_READY:
596
597
case SG_LIB_CAT_INVALID_OP:
629
630
if ((res = sg_ll_log_sense(sg_fd, optsp->do_ppc, optsp->do_sp,
630
631
optsp->page_control, optsp->pg_code,
631
632
optsp->subpg_code, optsp->paramp,
632
resp, actual_len, noisy, vb))) {
633
resp, actual_len, 1 /* noisy */, vb))) {
634
635
case SG_LIB_CAT_NOT_READY:
635
636
case SG_LIB_CAT_INVALID_OP:
683
684
case START_STOP_LPAGE: printf("%sStart-stop cycle counter", b); break;
684
685
case APP_CLIENT_LPAGE: printf("%sApplication client", b); break;
685
686
case SELF_TEST_LPAGE: printf("%sSelf-test results", b); break;
686
case PROTO_SPECIFIC_LPAGE: printf("%sProtocol specific port", b); break;
687
case PROTO_SPECIFIC_LPAGE:
688
printf("%sProtocol specific port", b);
687
690
case STATS_LPAGE:
688
691
printf("%sGeneral statistics and performance", b);
1291
/* originally vendor specific 0x32, ssc4 standardizes at 0x1b */
1283
1293
show_data_compression_log_page(unsigned char * resp, int len, int show_pcb)
1285
int k, num, extra, pc, pcb;
1295
int k, j, pl, num, extra, pc, pcb;
1287
1297
unsigned char * ucp;
1288
1298
char pcb_str[PCB_STR_LEN];
1297
1307
for (k = num; k > 0; k -= extra, ucp += extra) {
1298
1308
pc = (ucp[0] << 8) + ucp[1];
1303
n = (ucp[4] << 8) | ucp[5];
1306
n = (ucp[4] << 24) | (ucp[5] << 16) | (ucp[6] << 8) | ucp[7];
1312
if ((0 == pl) || (pl > 8)) {
1313
printf("badly formed data compression log parameter\n");
1314
printf(" parameter code = 0x%x, contents in hex:\n", pc);
1315
dStrHex((const char *)ucp, extra, 1);
1318
for (j = 0, n = 0; j < pl; ++j) {
1314
printf(" Read compression ratio x100: %u", n);
1325
printf(" Read compression ratio x100: %" PRIu64 , n);
1318
printf(" Write compression ratio x100: %u", n);
1328
printf(" Write compression ratio x100: %" PRIu64 , n);
1322
printf(" Megabytes transferred to server: %u", n);
1331
printf(" Megabytes transferred to server: %" PRIu64 , n);
1326
printf(" Bytes transferred to server: %u", n);
1334
printf(" Bytes transferred to server: %" PRIu64 , n);
1330
printf(" Megabytes read from tape: %u", n);
1337
printf(" Megabytes read from tape: %" PRIu64 , n);
1334
printf(" Bytes read from tape: %u", n);
1340
printf(" Bytes read from tape: %" PRIu64 , n);
1338
printf(" Megabytes transferred from server: %u", n);
1343
printf(" Megabytes transferred from server: %" PRIu64 , n);
1342
printf(" Bytes transferred from server: %u", n);
1346
printf(" Bytes transferred from server: %" PRIu64 , n);
1346
printf(" Megabytes written to tape: %u", n);
1349
printf(" Megabytes written to tape: %" PRIu64 , n);
1350
printf(" Bytes written to tape: %u", n);
1352
printf(" Bytes written to tape: %" PRIu64 , n);
1355
printf(" Data compression enabled: 0x%" PRIx64, n);
1353
1358
printf(" unknown parameter code = 0x%x, contents in hex:\n", pc);
1354
1359
dStrHex((const char *)ucp, extra, 1);
1357
1363
if (show_pcb) {
1358
1364
get_pcb_str(pcb, pcb_str, sizeof(pcb_str));
1359
1365
printf("\n <%s>\n", pcb_str);
1966
1972
printf(" reason: %s\n", s);
1967
1973
t = (0xf & vcp[5]);
1969
case 0: snprintf(s, sz, "phy enabled; unknown");
1971
case 1: snprintf(s, sz, "phy disabled"); break;
1972
case 2: snprintf(s, sz, "phy enabled; speed negotiation failed");
1974
case 3: snprintf(s, sz, "phy enabled; SATA spinup hold state");
1976
case 4: snprintf(s, sz, "phy enabled; port selector");
1978
case 5: snprintf(s, sz, "phy enabled; reset in progress");
1980
case 6: snprintf(s, sz, "phy enabled; unsupported phy attached");
1982
case 8: snprintf(s, sz, "phy enabled; 1.5 Gbps"); break;
1983
case 9: snprintf(s, sz, "phy enabled; 3 Gbps"); break;
1984
case 0xa: snprintf(s, sz, "phy enabled; 6 Gbps"); break;
1985
case 0xb: snprintf(s, sz, "phy enabled; 12 Gbps"); break;
1986
default: snprintf(s, sz, "reserved [%d]", t); break;
1976
snprintf(s, sz, "phy enabled; unknown reason");
1979
snprintf(s, sz, "phy disabled");
1982
snprintf(s, sz, "phy enabled; speed negotiation failed");
1985
snprintf(s, sz, "phy enabled; SATA spinup hold state");
1988
snprintf(s, sz, "phy enabled; port selector");
1991
snprintf(s, sz, "phy enabled; reset in progress");
1994
snprintf(s, sz, "phy enabled; unsupported phy attached");
1997
snprintf(s, sz, "1.5 Gbps");
2000
snprintf(s, sz, "3 Gbps");
2003
snprintf(s, sz, "6 Gbps");
2006
snprintf(s, sz, "12 Gbps");
2009
snprintf(s, sz, "reserved [%d]", t);
1988
2012
printf(" negotiated logical link rate: %s\n", s);
1989
2013
printf(" attached initiator port: ssp=%d stp=%d smp=%d\n",
2066
2090
/* Returns 1 if processed page, 0 otherwise */
2067
/* STATS_LPAGE, 0x0 to 0x1f */
2091
/* STATS_LPAGE [0x19], subpages: 0x0 to 0x1f */
2069
2093
show_stats_perform_page(unsigned char * resp, int len,
2070
2094
const struct opts_t * optsp)
2393
2417
/* Returns 1 if processed page, 0 otherwise */
2394
/* STATS_LPAGE, CACHE_STATS_SUBPG */
2418
/* STATS_LPAGE [0x19], CACHE_STATS_SUBPG [0x20] */
2396
2420
show_cache_stats_page(unsigned char * resp, int len,
2397
2421
const struct opts_t * optsp)
2807
/* SAT_ATA_RESULTS_LPAGE (SAT-2) [0x16] */
2809
show_ata_pt_results_page(unsigned char * resp, int len, int show_pcb)
2811
int num, pl, pc, pcb;
2812
unsigned char * ucp;
2814
char str[PCB_STR_LEN];
2816
printf("ATA pass-through results page (sat-2) [0x16]\n");
2820
pc = (ucp[0] << 8) | ucp[1];
2823
if ((pc < 0xf) && (pl > 17)) {
2824
int extend, sector_count;
2827
printf(" Log_index=0x%x (parameter_code=0x%x)\n", pc + 1, pc);
2829
sector_count = dp[5] + (extend ? (dp[4] << 8) : 0);
2830
printf(" extend=%d error=0x%x sector_count=0x%x\n", extend,
2831
dp[3], sector_count);
2833
printf(" lba=0x%02x%02x%02x%02x%02x%02x\n", dp[10], dp[8],
2834
dp[6], dp[11], dp[9], dp[7]);
2836
printf(" lba=0x%02x%02x%02x\n", dp[11], dp[9], dp[7]);
2837
printf(" device=0x%x status=0x%x\n", dp[12], dp[13]);
2839
printf(" Reserved [parameter_code=0x%x]:", pc);
2840
dStrHex((const char *)ucp, ((pl < num) ? pl : num), 0);
2843
get_pcb_str(pcb, str, sizeof(str));
2844
printf("\n <%s>\n", str);
2782
2851
static const char * bms_status[] = {
2783
2852
"no background scans active",
2784
2853
"background medium scan is active",
2790
2859
"background scan halted due to temperature out of range",
2791
2860
"background scan enabled, none active (waiting for BMS interval timer "
2792
2861
"to expire)", /* 8 */
2862
"background scan halted - scan results list full",
2863
"background scan halted - pre-scan time limit timer expired" /* 10 */,
2795
2866
static const char * reassign_status[] = {
3486
3565
case 0: printf(" Blocks sent to initiator"); break;
3487
3566
case 1: printf(" Blocks received from initiator"); break;
3488
case 2: printf(" Blocks read from cache and sent to initiator"); break;
3489
case 3: printf(" Number of read and write commands whose size "
3490
"<= segment size"); break;
3491
case 4: printf(" Number of read and write commands whose size "
3492
"> segment size"); break;
3568
printf(" Blocks read from cache and sent to initiator");
3571
printf(" Number of read and write commands whose size "
3575
printf(" Number of read and write commands whose size "
3576
"> segment size"); break;
3493
3577
default: printf(" Unknown Seagate parameter code = 0x%x", pc); break;
3787
case SAT_ATA_RESULTS_LPAGE: /* 0x16 */
3704
3789
switch (inq_dat->peripheral_type) {
3790
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_RBC:
3791
/* disk (direct access) type devices */
3792
show_ata_pt_results_page(resp, len, optsp->do_pcb);
3705
3794
case PDT_MCHANGER: /* smc-3 */
3706
3795
show_mchanger_diag_data_page(resp, len, optsp->do_pcb);
3726
case PROTO_SPECIFIC_LPAGE:
3816
case PROTO_SPECIFIC_LPAGE: /* 0x18 */
3727
3817
done = show_protocol_specific_page(resp, len, optsp);
3729
case STATS_LPAGE: /* defined for subpages 0 to 32 inclusive */
3819
case STATS_LPAGE: /* 0x19, defined for subpages 0 to 32 inclusive */
3730
3820
if (subpg_code <= HIGH_GRP_STATS_SUBPG)
3731
3821
done = show_stats_perform_page(resp, len, optsp);
3732
3822
else if (subpg_code == CACHE_STATS_SUBPG)
3827
case PCT_LPAGE: /* 0x1a */
3738
3828
show_power_condition_transitions_page(resp, len, optsp->do_pcb);
3740
case TAPE_ALERT_LPAGE:
3831
show_data_compression_log_page(resp, len, optsp->do_pcb);
3833
case TAPE_ALERT_LPAGE: /* 0x2e */
3742
3835
switch (inq_dat->peripheral_type) {
3743
3836
case PDT_TAPE: /* ssc only */
3845
case 0x30: /* vendor specific: IBM */
3753
3846
show_tape_usage_log_page(resp, len, optsp->do_pcb);
3848
case 0x31: /* vendor specific: IBM */
3756
3849
show_tape_capacity_log_page(resp, len, optsp->do_pcb);
3851
case 0x32: /* vendor specific, now tweaked and standardized at 0x1b */
3759
3852
show_data_compression_log_page(resp, len, optsp->do_pcb);
3814
3907
optsp->pg_code = TEMPERATURE_LPAGE;
3815
3908
optsp->subpg_code = NOT_SPG_SUBPG;
3816
res = do_logs(sg_fd, resp, max_len, 0, optsp);
3909
res = do_logs(sg_fd, resp, max_len, optsp);
3817
3910
if (0 == res) {
3818
3911
len = (resp[2] << 8) + resp[3] + 4;
3819
3912
if (optsp->do_raw)
3826
3919
fprintf(stderr, "Device not ready\n");
3828
3921
optsp->pg_code = IE_LPAGE;
3829
res = do_logs(sg_fd, resp, max_len, 0, optsp);
3922
res = do_logs(sg_fd, resp, max_len, optsp);
3830
3923
if (0 == res) {
3831
3924
len = (resp[2] << 8) + resp[3] + 4;
3832
3925
if (optsp->do_raw)
3942
4035
return (k >= 0) ? k : SG_LIB_CAT_OTHER;
3944
4037
resp_len = (opts.maxlen > 0) ? opts.maxlen : MX_ALLOC_LEN;
3945
res = do_logs(sg_fd, rsp_buff, resp_len, 1, &opts);
4038
res = do_logs(sg_fd, rsp_buff, resp_len, &opts);
3946
4039
if (0 == res) {
3947
4040
pg_len = (rsp_buff[2] << 8) + rsp_buff[3];
3948
4041
if ((pg_len + 4) > resp_len) {
4005
4098
opts.subpg_code = NOT_SPG_SUBPG;
4007
res = do_logs(sg_fd, rsp_buff, resp_len, 1, &opts);
4100
res = do_logs(sg_fd, rsp_buff, resp_len, &opts);
4008
4101
if (0 == res) {
4009
4102
pg_len = (rsp_buff[2] << 8) + rsp_buff[3];
4010
4103
if ((pg_len + 4) > resp_len) {