Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright (c) 2018 by Chelsio Communications, Inc.
  14  */
  15 




  16 #include <stdio.h>
  17 #include <stdlib.h>
  18 #include <unistd.h>
  19 #include <stropts.h>
  20 #include <sys/types.h>
  21 #include <sys/stat.h>
  22 #include <fcntl.h>
  23 #include <sys/socket.h>
  24 #include <strings.h>
  25 #include <sys/varargs.h>
  26 #include <errno.h>
  27 #include <sys/byteorder.h>
  28 #include <inttypes.h>
  29 #include <sys/sysmacros.h>
  30 
  31 #include "t4nex.h"
  32 #include "version.h"
  33 #include "osdep.h"
  34 #include "t4fw_interface.h"
  35 


  68         [FW_DEVLOG_FACILITY_OFLD]       = "OFLD",
  69         [FW_DEVLOG_FACILITY_RI]         = "RI",
  70         [FW_DEVLOG_FACILITY_ISCSI]      = "ISCSI",
  71         [FW_DEVLOG_FACILITY_FCOE]       = "FCOE",
  72         [FW_DEVLOG_FACILITY_FOISCSI]    = "FOISCSI",
  73         [FW_DEVLOG_FACILITY_FOFCOE]     = "FOFCOE",
  74         [FW_DEVLOG_FACILITY_CHNET]      = "CHNET",
  75 };
  76 
  77 static const char *progname;
  78 
  79 static void usage(FILE *fp)
  80 {
  81         fprintf(fp, "Usage: %s <path to t4nex#> [operation]\n", progname);
  82         fprintf(fp,
  83             "\tdevlog                              show device log\n"
  84             "\tloadfw <FW image>                   Flash the FW image\n");
  85         exit(fp == stderr ? 1 : 0);
  86 }
  87 
  88 static void
  89 err(int code, const char *fmt, ...)
  90 {
  91         va_list ap;
  92         int e = errno;
  93 
  94         va_start(ap, fmt);
  95         fprintf(stderr, "error: ");
  96         vfprintf(stderr, fmt, ap);
  97         fprintf(stderr, ": %s\n", strerror(e));
  98         va_end(ap);
  99         exit(code);
 100 }
 101 
 102 static int
 103 doit(const char *iff_name, unsigned long cmd, void *data)
 104 {
 105         int fd = 0;
 106         int rc = 0;
 107 
 108         if ((fd = open(iff_name, O_RDWR)) < 0)


   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright (c) 2018 by Chelsio Communications, Inc.
  14  */
  15 
  16 /*
  17  * Copyright 2019 Joyent, Inc.
  18  */
  19 
  20 #include <stdio.h>
  21 #include <stdlib.h>
  22 #include <unistd.h>
  23 #include <stropts.h>
  24 #include <sys/types.h>
  25 #include <sys/stat.h>
  26 #include <fcntl.h>
  27 #include <sys/socket.h>
  28 #include <strings.h>
  29 #include <sys/varargs.h>
  30 #include <errno.h>
  31 #include <sys/byteorder.h>
  32 #include <inttypes.h>
  33 #include <sys/sysmacros.h>
  34 
  35 #include "t4nex.h"
  36 #include "version.h"
  37 #include "osdep.h"
  38 #include "t4fw_interface.h"
  39 


  72         [FW_DEVLOG_FACILITY_OFLD]       = "OFLD",
  73         [FW_DEVLOG_FACILITY_RI]         = "RI",
  74         [FW_DEVLOG_FACILITY_ISCSI]      = "ISCSI",
  75         [FW_DEVLOG_FACILITY_FCOE]       = "FCOE",
  76         [FW_DEVLOG_FACILITY_FOISCSI]    = "FOISCSI",
  77         [FW_DEVLOG_FACILITY_FOFCOE]     = "FOFCOE",
  78         [FW_DEVLOG_FACILITY_CHNET]      = "CHNET",
  79 };
  80 
  81 static const char *progname;
  82 
  83 static void usage(FILE *fp)
  84 {
  85         fprintf(fp, "Usage: %s <path to t4nex#> [operation]\n", progname);
  86         fprintf(fp,
  87             "\tdevlog                              show device log\n"
  88             "\tloadfw <FW image>                   Flash the FW image\n");
  89         exit(fp == stderr ? 1 : 0);
  90 }
  91 
  92 __NORETURN static void
  93 err(int code, const char *fmt, ...)
  94 {
  95         va_list ap;
  96         int e = errno;
  97 
  98         va_start(ap, fmt);
  99         fprintf(stderr, "error: ");
 100         vfprintf(stderr, fmt, ap);
 101         fprintf(stderr, ": %s\n", strerror(e));
 102         va_end(ap);
 103         exit(code);
 104 }
 105 
 106 static int
 107 doit(const char *iff_name, unsigned long cmd, void *data)
 108 {
 109         int fd = 0;
 110         int rc = 0;
 111 
 112         if ((fd = open(iff_name, O_RDWR)) < 0)