~ubuntu-branches/debian/stretch/sg3-utils/stretch

« back to all changes in this revision

Viewing changes to src/sg_logs.c

  • Committer: Bazaar Package Importer
  • Author(s): Ritesh Raj Sarraf
  • Date: 2011-08-09 16:36:28 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110809163628-yh8okvhe20j5rekq
Tags: 1.32-1
* [06cef8d] Use kfreebsd-any as the build-dep.
  Thanks to Robert Millan (Closes: 634362)
* [850586d] separate build-arch and build-indep targets
* [a432747] Drop duplicate changelog
* [ec2bbd8] Update Standards Version to 3.9.2. No changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "sg_cmds_basic.h"
16
16
 
17
17
/* A utility program originally written for the Linux OS SCSI subsystem.
18
 
*  Copyright (C) 2000-2010 D. Gilbert
 
18
*  Copyright (C) 2000-2011 D. Gilbert
19
19
*  This program is free software; you can redistribute it and/or modify
20
20
*  it under the terms of the GNU General Public License as published by
21
21
*  the Free Software Foundation; either version 2, or (at your option)
25
25
 
26
26
*/
27
27
 
28
 
static char * version_str = "0.98 20101102";    /* spc4r27 + sbc3r25 */
 
28
static char * version_str = "1.04 20110731";    /* spc4r30 + sbc3r27 */
29
29
 
30
30
#define MX_ALLOC_LEN (0xfffc)
31
31
#define SHORT_RESP_LEN 128
61
61
 
62
62
#define LOG_SENSE_PROBE_ALLOC_LEN 4
63
63
 
64
 
static unsigned char rsp_buff[MX_ALLOC_LEN];
 
64
static unsigned char rsp_buff[MX_ALLOC_LEN + 4];
65
65
 
66
66
static struct option long_options[] = {
67
67
        {"all", no_argument, 0, 'a'},
228
228
        usage_old();
229
229
}
230
230
 
 
231
/* Processes command line options according to new option format. Returns
 
232
 * 0 is ok, else SG_LIB_SYNTAX_ERROR is returned. */
231
233
static int
232
234
process_cl_new(struct opts_t * optsp, int argc, char * argv[])
233
235
{
276
278
            break;
277
279
        case 'm':
278
280
            n = sg_get_num(optarg);
279
 
            if ((n < 0) || (1 == n)) {
280
 
                fprintf(stderr, "bad argument to '--maxlen='\n");
 
281
            if ((n < 0) || (1 == n) || (n > 0xffff)) {
 
282
                fprintf(stderr, "bad argument to '--maxlen=', from 2 to "
 
283
                        "65535 (inclusive) expected\n");
281
284
                usage();
282
285
                return SG_LIB_SYNTAX_ERROR;
283
286
            }
376
379
    return 0;
377
380
}
378
381
 
 
382
/* Processes command line options according to old option format. Returns
 
383
 * 0 is ok, else SG_LIB_SYNTAX_ERROR is returned. */
379
384
static int
380
385
process_cl_old(struct opts_t * optsp, int argc, char * argv[])
381
386
{
526
531
    return 0;
527
532
}
528
533
 
 
534
/* Process command line options. First check using new option format unless
 
535
 * the SG3_UTILS_OLD_OPTS environment variable is defined which causes the
 
536
 * old option format to be checked first. Both new and old format can be
 
537
 * countermanded by a '-O' and '-N' options respectively. As soon as either
 
538
 * of these options is detected (when processing the other format), processing
 
539
 * stops and is restarted using the other format. Clear? */
529
540
static int
530
541
process_cl(struct opts_t * optsp, int argc, char * argv[])
531
542
{
568
579
do_logs(int sg_fd, unsigned char * resp, int mx_resp_len, int noisy,
569
580
        const struct opts_t * optsp)
570
581
{
571
 
    int actual_len;
572
 
    int res;
 
582
    int actual_len, res, vb;
573
583
 
574
584
    memset(resp, 0, mx_resp_len);
 
585
    vb = optsp->do_verbose;
575
586
    if (optsp->maxlen > 1)
576
587
        actual_len = mx_resp_len;
577
588
    else {
579
590
                                   optsp->page_control, optsp->pg_code,
580
591
                                   optsp->subpg_code, optsp->paramp,
581
592
                                   resp, LOG_SENSE_PROBE_ALLOC_LEN,
582
 
                                   noisy, optsp->do_verbose))) {
 
593
                                   noisy, vb))) {
583
594
            switch (res) {
584
595
            case SG_LIB_CAT_NOT_READY:
585
596
            case SG_LIB_CAT_INVALID_OP:
592
603
            }
593
604
        }
594
605
        actual_len = (resp[2] << 8) + resp[3] + 4;
595
 
        if ((0 == optsp->do_raw) && (optsp->do_verbose > 1)) {
 
606
        if ((0 == optsp->do_raw) && (vb > 1)) {
596
607
            fprintf(stderr, "  Log sense (find length) response:\n");
597
608
            dStrHex((const char *)resp, LOG_SENSE_PROBE_ALLOC_LEN, 1);
598
609
            fprintf(stderr, "  hence calculated response length=%d\n",
599
610
                    actual_len);
600
611
        }
 
612
        if (optsp->pg_code != (0x3f & resp[0])) {
 
613
            if (vb)
 
614
                fprintf(stderr, "Page code does not appear in first byte "
 
615
                        "of response so it's suspect\n");
 
616
            if (actual_len > 0x40) {
 
617
                actual_len = 0x40;
 
618
                if (vb)
 
619
                    fprintf(stderr, "Trim response length to 64 bytes due "
 
620
                            "to suspect response format\n");
 
621
            }
 
622
        }
601
623
        /* Some HBAs don't like odd transfer lengths */
602
624
        if (actual_len % 2)
603
625
            actual_len += 1;
607
629
    if ((res = sg_ll_log_sense(sg_fd, optsp->do_ppc, optsp->do_sp,
608
630
                               optsp->page_control, optsp->pg_code,
609
631
                               optsp->subpg_code, optsp->paramp,
610
 
                               resp, actual_len, noisy, optsp->do_verbose))) {
 
632
                               resp, actual_len, noisy, vb))) {
611
633
        switch (res) {
612
634
        case SG_LIB_CAT_NOT_READY:
613
635
        case SG_LIB_CAT_INVALID_OP:
619
641
            return -1;
620
642
        }
621
643
    }
622
 
    if ((0 == optsp->do_raw) && (optsp->do_verbose > 1)) {
 
644
    if ((0 == optsp->do_raw) && (vb > 1)) {
623
645
        fprintf(stderr, "  Log sense response:\n");
624
646
        dStrHex((const char *)resp, actual_len, 1);
625
647
    }
1693
1715
 
1694
1716
/* from sas2r15 */
1695
1717
static void
1696
 
show_sas_phy_event_info(int peis, unsigned int val, unsigned thresh_val)
 
1718
show_sas_phy_event_info(int pes, unsigned int val, unsigned int thresh_val)
1697
1719
{
1698
1720
    unsigned int u;
1699
1721
 
1700
 
    switch (peis) {
 
1722
    switch (pes) {
1701
1723
    case 0:
1702
1724
        printf("     No event\n");
1703
1725
        break;
1819
1841
        printf("     Received SMP frame error count: %u\n", val);
1820
1842
        break;
1821
1843
    default:
 
1844
        printf("     Unknown phy event source: %d, val=%u, thresh_val=%u\n",
 
1845
               pes, val, thresh_val);
1822
1846
        break;
1823
1847
    }
1824
1848
}
1896
1920
            printf("      sas_addr=0x%" PRIx64 "\n", ull);
1897
1921
        } else {
1898
1922
            t = ((0x70 & vcp[4]) >> 4);
 
1923
            /* attached device type. In SAS-1.1 case 2 was an edge expander;
 
1924
             * in SAS-2 case 3 is marked as obsolete. */
1899
1925
            switch (t) {
1900
1926
            case 0: snprintf(s, sz, "no device attached"); break;
1901
1927
            case 1: snprintf(s, sz, "end device"); break;
1956
1982
            case 8: snprintf(s, sz, "phy enabled; 1.5 Gbps"); break;
1957
1983
            case 9: snprintf(s, sz, "phy enabled; 3 Gbps"); break;
1958
1984
            case 0xa: snprintf(s, sz, "phy enabled; 6 Gbps"); break;
 
1985
            case 0xb: snprintf(s, sz, "phy enabled; 12 Gbps"); break;
1959
1986
            default: snprintf(s, sz, "reserved [%d]", t); break;
1960
1987
            }
1961
1988
            printf("    negotiated logical link rate: %s\n", s);
1982
2009
            printf("    Phy reset problem = %u\n", ui);
1983
2010
        }
1984
2011
        if (spld_len > 51) {
1985
 
            int num_ped, peis;
 
2012
            int num_ped, pes;
1986
2013
            unsigned char * xcp;
1987
2014
            unsigned int pvdt;
1988
2015
 
2000
2027
            }
2001
2028
            xcp = vcp + 52;
2002
2029
            for (m = 0; m < (num_ped * 12); m += 12, xcp += 12) {
2003
 
                peis = xcp[3];
 
2030
                pes = xcp[3];
2004
2031
                ui = (xcp[4] << 24) | (xcp[5] << 16) | (xcp[6] << 8) |
2005
2032
                     xcp[7];
2006
2033
                pvdt = (xcp[8] << 24) | (xcp[9] << 16) | (xcp[10] << 8) |
2007
2034
                       xcp[11];
2008
 
                show_sas_phy_event_info(peis, ui, pvdt);
 
2035
                show_sas_phy_event_info(pes, ui, pvdt);
2009
2036
            }
2010
2037
        } else if (optsp->do_verbose)
2011
2038
           printf("    <<No phy event descriptors>>\n");
2638
2665
    }
2639
2666
}
2640
2667
 
2641
 
/* LB_PROV_LPAGE */
 
2668
/* LB_PROV_LPAGE [0xc] */
2642
2669
static void
2643
2670
show_lb_provisioning_page(unsigned char * resp, int len, int show_pcb)
2644
2671
{
2668
2695
            }
2669
2696
            j = (ucp[4] << 24) + (ucp[5] << 16) + (ucp[6] << 8) + ucp[7];
2670
2697
            printf(" %d\n", j);
 
2698
            if (pl > 8) {
 
2699
                switch (ucp[8] & 0x3) {
 
2700
                case 0: cp = "not reported"; break;
 
2701
                case 1: cp = "dedicated to lu"; break;
 
2702
                case 2: cp = "not dedicated to lu"; break;
 
2703
                case 3: cp = "reserved"; break;
 
2704
                }
 
2705
                printf("    Scope: %s\n", cp);
 
2706
            }
2671
2707
        } else if ((pc >= 0xfff0) && (pc <= 0xffff)) {
2672
2708
            printf("  Vendor specific [0x%x]:", pc);
2673
2709
            dStrHex((const char *)ucp, ((pl < num) ? pl : num), 0);
3764
3800
        if (optsp->do_raw)
3765
3801
            dStrRaw((const char *)resp, len);
3766
3802
        else if (optsp->do_hex)
3767
 
            dStrHex((const char *)resp, len, 1);
 
3803
            dStrHex((const char *)resp, len, (1 == optsp->do_hex));
3768
3804
        else
3769
3805
            show_temperature_page(resp, len, optsp->do_pcb, 0, 0);
3770
3806
    }else if (SG_LIB_CAT_NOT_READY == res)
3777
3813
            if (optsp->do_raw)
3778
3814
                dStrRaw((const char *)resp, len);
3779
3815
            else if (optsp->do_hex)
3780
 
                dStrHex((const char *)resp, len, 1);
 
3816
                dStrHex((const char *)resp, len, (1 == optsp->do_hex));
3781
3817
            else
3782
3818
                show_ie_page(resp, len, 0, 0);
3783
3819
        } else
3910
3946
        if (opts.do_raw)
3911
3947
            dStrRaw((const char *)rsp_buff, pg_len + 4);
3912
3948
        else if (opts.do_hex > 1)
3913
 
            dStrHex((const char *)rsp_buff, pg_len + 4, 1);
 
3949
            dStrHex((const char *)rsp_buff, pg_len + 4, (2 == opts.do_hex));
3914
3950
        else if (pg_len > 1) {
3915
3951
            if (opts.do_hex) {
3916
3952
                if (rsp_buff[0] & 0x40)
3960
3996
                if (opts.do_raw)
3961
3997
                    dStrRaw((const char *)rsp_buff, pg_len + 4);
3962
3998
                else if (opts.do_hex > 1)
3963
 
                    dStrHex((const char *)rsp_buff, pg_len + 4, 1);
 
3999
                    dStrHex((const char *)rsp_buff, pg_len + 4,
 
4000
                            (2 == opts.do_hex));
3964
4001
                else if (opts.do_hex) {
3965
4002
                    if (rsp_buff[0] & 0x40)
3966
4003
                        printf("Log page code=0x%x,0x%x, DS=%d, SPF=1, page_"