Deleted Added
full compact
logpage.c (328723) logpage.c (328725)
1/*-
2 * Copyright (c) 2013 EMC Corp.
3 * All rights reserved.
4 *
5 * Copyright (C) 2012-2013 Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2013 EMC Corp.
3 * All rights reserved.
4 *
5 * Copyright (C) 2012-2013 Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/11/sbin/nvmecontrol/logpage.c 328723 2018-02-01 19:43:18Z mav $");
31__FBSDID("$FreeBSD: stable/11/sbin/nvmecontrol/logpage.c 328725 2018-02-01 19:44:24Z mav $");
32
33#include <sys/param.h>
34#include <sys/ioccom.h>
35
36#include <ctype.h>
37#include <err.h>
38#include <fcntl.h>
39#include <stdbool.h>

--- 324 unchanged lines hidden (view full) ---

364{
365
366 printf("Intel Write Latency Log\n");
367 printf("=======================\n");
368 print_intel_read_write_lat_log(buf, size);
369}
370
371/*
32
33#include <sys/param.h>
34#include <sys/ioccom.h>
35
36#include <ctype.h>
37#include <err.h>
38#include <fcntl.h>
39#include <stdbool.h>

--- 324 unchanged lines hidden (view full) ---

364{
365
366 printf("Intel Write Latency Log\n");
367 printf("=======================\n");
368 print_intel_read_write_lat_log(buf, size);
369}
370
371/*
372 * Table 19. 5.4 SMART Attributes
372 * Table 19. 5.4 SMART Attributes. Samsung also implements this and some extra data not documented.
373 */
374static void
375print_intel_add_smart(void *buf, uint32_t size __unused)
376{
377 uint8_t *walker = buf;
378 uint8_t *end = walker + 150;
379 const char *name;
380 uint64_t raw;

--- 449 unchanged lines hidden (view full) ---

830 }
831 kv_indirect(subpage, subtype, res, len, hgst_subpage, nitems(hgst_subpage));
832 }
833}
834
835/*
836 * Table of log page printer / sizing.
837 *
373 */
374static void
375print_intel_add_smart(void *buf, uint32_t size __unused)
376{
377 uint8_t *walker = buf;
378 uint8_t *end = walker + 150;
379 const char *name;
380 uint64_t raw;

--- 449 unchanged lines hidden (view full) ---

830 }
831 kv_indirect(subpage, subtype, res, len, hgst_subpage, nitems(hgst_subpage));
832 }
833}
834
835/*
836 * Table of log page printer / sizing.
837 *
838 * This includes Intel specific pages that are widely implemented. Not
839 * sure how best to switch between different vendors.
838 * This includes Intel specific pages that are widely implemented.
839 * Make sure you keep all the pages of one vendor together so -v help
840 * lists all the vendors pages.
840 */
841static struct logpage_function {
842 uint8_t log_page;
843 const char *vendor;
841 */
842static struct logpage_function {
843 uint8_t log_page;
844 const char *vendor;
845 const char *name;
844 print_fn_t print_fn;
845 size_t size;
846} logfuncs[] = {
846 print_fn_t print_fn;
847 size_t size;
848} logfuncs[] = {
847 {NVME_LOG_ERROR, NULL, print_log_error,
848 0},
849 {NVME_LOG_HEALTH_INFORMATION, NULL, print_log_health,
850 sizeof(struct nvme_health_information_page)},
851 {NVME_LOG_FIRMWARE_SLOT, NULL, print_log_firmware,
852 sizeof(struct nvme_firmware_page)},
853 {HGST_INFO_LOG, "hgst", print_hgst_info_log,
854 DEFAULT_SIZE},
855 {HGST_INFO_LOG, "wdc", print_hgst_info_log,
856 DEFAULT_SIZE},
857 {INTEL_LOG_TEMP_STATS, "intel", print_intel_temp_stats,
858 sizeof(struct intel_log_temp_stats)},
859 {INTEL_LOG_READ_LAT_LOG, "intel", print_intel_read_lat_log,
860 DEFAULT_SIZE},
861 {INTEL_LOG_WRITE_LAT_LOG, "intel", print_intel_write_lat_log,
862 DEFAULT_SIZE},
863 {INTEL_LOG_ADD_SMART, "intel", print_intel_add_smart,
864 DEFAULT_SIZE},
865 {0, NULL, NULL, 0},
849 {NVME_LOG_ERROR, NULL, "Drive Error Log",
850 print_log_error, 0},
851 {NVME_LOG_HEALTH_INFORMATION, NULL, "Health/SMART Data",
852 print_log_health, sizeof(struct nvme_health_information_page)},
853 {NVME_LOG_FIRMWARE_SLOT, NULL, "Firmware Information",
854 print_log_firmware, sizeof(struct nvme_firmware_page)},
855 {HGST_INFO_LOG, "hgst", "Detailed Health/SMART",
856 print_hgst_info_log, DEFAULT_SIZE},
857 {HGST_INFO_LOG, "wds", "Detailed Health/SMART",
858 print_hgst_info_log, DEFAULT_SIZE},
859 {INTEL_LOG_TEMP_STATS, "intel", "Temperature Stats",
860 print_intel_temp_stats, sizeof(struct intel_log_temp_stats)},
861 {INTEL_LOG_READ_LAT_LOG, "intel", "Read Latencies",
862 print_intel_read_lat_log, DEFAULT_SIZE},
863 {INTEL_LOG_WRITE_LAT_LOG, "intel", "Write Latencies",
864 print_intel_write_lat_log, DEFAULT_SIZE},
865 {INTEL_LOG_ADD_SMART, "intel", "Extra Health/SMART Data",
866 print_intel_add_smart, DEFAULT_SIZE},
867 {INTEL_LOG_ADD_SMART, "samsung", "Extra Health/SMART Data",
868 print_intel_add_smart, DEFAULT_SIZE},
869
870 {0, NULL, NULL, NULL, 0},
866};
867
868static void
869logpage_usage(void)
870{
871 fprintf(stderr, "usage:\n");
872 fprintf(stderr, LOGPAGE_USAGE);
873 exit(1);
874}
875
871};
872
873static void
874logpage_usage(void)
875{
876 fprintf(stderr, "usage:\n");
877 fprintf(stderr, LOGPAGE_USAGE);
878 exit(1);
879}
880
881static void
882logpage_help(void)
883{
884 struct logpage_function *f;
885 const char *v;
886
887 fprintf(stderr, "\n");
888 fprintf(stderr, "%-8s %-10s %s\n", "Page", "Vendor","Page Name");
889 fprintf(stderr, "-------- ---------- ----------\n");
890 for (f = logfuncs; f->log_page > 0; f++) {
891 v = f->vendor == NULL ? "-" : f->vendor;
892 fprintf(stderr, "0x%02x %-10s %s\n", f->log_page, v, f->name);
893 }
894
895 exit(1);
896}
897
876void
877logpage(int argc, char *argv[])
878{
879 int fd, nsid;
880 int log_page = 0, pageflag = false;
881 int binflag = false, hexflag = false, ns_specified;
882 char ch, *p;
883 char cname[64];

--- 5 unchanged lines hidden (view full) ---

889 print_fn_t print_fn;
890
891 while ((ch = getopt(argc, argv, "bp:xv:")) != -1) {
892 switch (ch) {
893 case 'b':
894 binflag = true;
895 break;
896 case 'p':
898void
899logpage(int argc, char *argv[])
900{
901 int fd, nsid;
902 int log_page = 0, pageflag = false;
903 int binflag = false, hexflag = false, ns_specified;
904 char ch, *p;
905 char cname[64];

--- 5 unchanged lines hidden (view full) ---

911 print_fn_t print_fn;
912
913 while ((ch = getopt(argc, argv, "bp:xv:")) != -1) {
914 switch (ch) {
915 case 'b':
916 binflag = true;
917 break;
918 case 'p':
919 if (strcmp(optarg, "help") == 0)
920 logpage_help();
921
897 /* TODO: Add human-readable ASCII page IDs */
898 log_page = strtol(optarg, &p, 0);
899 if (p != NULL && *p != '\0') {
900 fprintf(stderr,
901 "\"%s\" not valid log page id.\n",
902 optarg);
903 logpage_usage();
904 }
905 pageflag = true;
906 break;
907 case 'x':
908 hexflag = true;
909 break;
910 case 'v':
922 /* TODO: Add human-readable ASCII page IDs */
923 log_page = strtol(optarg, &p, 0);
924 if (p != NULL && *p != '\0') {
925 fprintf(stderr,
926 "\"%s\" not valid log page id.\n",
927 optarg);
928 logpage_usage();
929 }
930 pageflag = true;
931 break;
932 case 'x':
933 hexflag = true;
934 break;
935 case 'v':
936 if (strcmp(optarg, "help") == 0)
937 logpage_help();
911 vendor = optarg;
912 break;
913 }
914 }
915
916 if (!pageflag) {
917 printf("Missing page_id (-p).\n");
918 logpage_usage();

--- 70 unchanged lines hidden ---
938 vendor = optarg;
939 break;
940 }
941 }
942
943 if (!pageflag) {
944 printf("Missing page_id (-p).\n");
945 logpage_usage();

--- 70 unchanged lines hidden ---