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>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/cxgbetool/cxgbetool.c
+++ new/usr/src/cmd/cxgbetool/cxgbetool.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright (c) 2018 by Chelsio Communications, Inc.
14 14 */
15 15
16 +/*
17 + * Copyright 2019 Joyent, Inc.
18 + */
19 +
16 20 #include <stdio.h>
17 21 #include <stdlib.h>
18 22 #include <unistd.h>
19 23 #include <stropts.h>
20 24 #include <sys/types.h>
21 25 #include <sys/stat.h>
22 26 #include <fcntl.h>
23 27 #include <sys/socket.h>
24 28 #include <strings.h>
25 29 #include <sys/varargs.h>
26 30 #include <errno.h>
27 31 #include <sys/byteorder.h>
28 32 #include <inttypes.h>
29 33 #include <sys/sysmacros.h>
30 34
31 35 #include "t4nex.h"
32 36 #include "version.h"
33 37 #include "osdep.h"
34 38 #include "t4fw_interface.h"
35 39
36 40 /*
37 41 * Firmware Device Log Dumping
38 42 */
39 43
40 44 static const char * const devlog_level_strings[] = {
41 45 [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
42 46 [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
43 47 [FW_DEVLOG_LEVEL_ERR] = "ERR",
44 48 [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
45 49 [FW_DEVLOG_LEVEL_INFO] = "INFO",
46 50 [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
47 51 };
48 52
49 53 static const char * const devlog_facility_strings[] = {
50 54 [FW_DEVLOG_FACILITY_CORE] = "CORE",
51 55 [FW_DEVLOG_FACILITY_CF] = "CF",
52 56 [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
53 57 [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
54 58 [FW_DEVLOG_FACILITY_RES] = "RES",
55 59 [FW_DEVLOG_FACILITY_HW] = "HW",
56 60 [FW_DEVLOG_FACILITY_FLR] = "FLR",
57 61 [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
58 62 [FW_DEVLOG_FACILITY_PHY] = "PHY",
59 63 [FW_DEVLOG_FACILITY_MAC] = "MAC",
60 64 [FW_DEVLOG_FACILITY_PORT] = "PORT",
61 65 [FW_DEVLOG_FACILITY_VI] = "VI",
62 66 [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
63 67 [FW_DEVLOG_FACILITY_ACL] = "ACL",
64 68 [FW_DEVLOG_FACILITY_TM] = "TM",
65 69 [FW_DEVLOG_FACILITY_QFC] = "QFC",
66 70 [FW_DEVLOG_FACILITY_DCB] = "DCB",
67 71 [FW_DEVLOG_FACILITY_ETH] = "ETH",
68 72 [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
69 73 [FW_DEVLOG_FACILITY_RI] = "RI",
70 74 [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
71 75 [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
72 76 [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
73 77 [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE",
74 78 [FW_DEVLOG_FACILITY_CHNET] = "CHNET",
75 79 };
76 80
77 81 static const char *progname;
↓ open down ↓ |
52 lines elided |
↑ open up ↑ |
78 82
79 83 static void usage(FILE *fp)
80 84 {
81 85 fprintf(fp, "Usage: %s <path to t4nex#> [operation]\n", progname);
82 86 fprintf(fp,
83 87 "\tdevlog show device log\n"
84 88 "\tloadfw <FW image> Flash the FW image\n");
85 89 exit(fp == stderr ? 1 : 0);
86 90 }
87 91
88 -static void
92 +__NORETURN static void
89 93 err(int code, const char *fmt, ...)
90 94 {
91 95 va_list ap;
92 96 int e = errno;
93 97
94 98 va_start(ap, fmt);
95 99 fprintf(stderr, "error: ");
96 100 vfprintf(stderr, fmt, ap);
97 101 fprintf(stderr, ": %s\n", strerror(e));
98 102 va_end(ap);
99 103 exit(code);
100 104 }
101 105
102 106 static int
103 107 doit(const char *iff_name, unsigned long cmd, void *data)
104 108 {
105 109 int fd = 0;
106 110 int rc = 0;
107 111
108 112 if ((fd = open(iff_name, O_RDWR)) < 0)
109 113 return (-1);
110 114
111 115 rc = (ioctl(fd, cmd, data) < 0) ? errno : rc;
112 116 close(fd);
113 117 return (rc);
114 118 }
115 119
116 120 static void
117 121 get_devlog(int argc, char *argv[], int start_arg, const char *iff_name)
118 122 {
119 123 struct t4_devlog *devlog;
120 124 struct fw_devlog_e *entry, *buf;
121 125 int rc = 0, first = 0, nentries, i, j, len;
122 126 uint64_t ftstamp = UINT64_MAX;
123 127
124 128 devlog = malloc(T4_DEVLOG_SIZE + sizeof (struct t4_devlog));
125 129 if (!devlog)
126 130 err(1, "%s: can't allocate devlog buffer", __func__);
127 131
128 132 devlog->len = T4_DEVLOG_SIZE;
129 133 /* Get device log */
130 134 rc = doit(iff_name, T4_IOCTL_DEVLOG, devlog);
131 135 if (rc == ENOBUFS) {
132 136 /*
133 137 * Default buffer size is not sufficient to hold device log.
134 138 * Driver has updated the devlog.len to indicate the expected
135 139 * size. Free the currently allocated devlog.data, allocate
136 140 * again with right size and retry.
137 141 */
138 142 len = devlog->len;
139 143 free(devlog);
140 144
141 145 if ((devlog = malloc(len + sizeof (struct t4_devlog))) == NULL)
142 146 err(1, "%s: can't reallocate devlog buffer", __func__);
143 147
144 148 rc = doit(iff_name, T4_IOCTL_DEVLOG, devlog);
145 149 }
146 150 if (rc) {
147 151 free(devlog);
148 152 err(1, "%s: can't get device log", __func__);
149 153 }
150 154
151 155 /* There are nentries number of entries in the buffer */
152 156 nentries = (devlog->len / sizeof (struct fw_devlog_e));
153 157
154 158 buf = (struct fw_devlog_e *)devlog->data;
155 159
156 160 /* Find the first entry */
157 161 for (i = 0; i < nentries; i++) {
158 162 entry = &buf[i];
159 163
160 164 if (entry->timestamp == 0)
161 165 break;
162 166
163 167 entry->timestamp = BE_64(entry->timestamp);
164 168 entry->seqno = BE_32(entry->seqno);
165 169 for (j = 0; j < 8; j++)
166 170 entry->params[j] = BE_32(entry->params[j]);
167 171
168 172 if (entry->timestamp < ftstamp) {
169 173 ftstamp = entry->timestamp;
170 174 first = i;
171 175 }
172 176 }
173 177
174 178 printf("%10s %15s %8s %8s %s\n", "Seq#", "Tstamp", "Level",
175 179 "Facility", "Message");
176 180
177 181 i = first;
178 182
179 183 do {
180 184 entry = &buf[i];
181 185
182 186 if (entry->timestamp == 0)
183 187 break;
184 188
185 189 printf("%10d %15llu %8s %8s ", entry->seqno,
186 190 entry->timestamp,
187 191 (entry->level < ARRAY_SIZE(devlog_level_strings) ?
188 192 devlog_level_strings[entry->level] : "UNKNOWN"),
189 193 (entry->facility < ARRAY_SIZE(devlog_facility_strings) ?
190 194 devlog_facility_strings[entry->facility] : "UNKNOWN"));
191 195
192 196 printf((const char *)entry->fmt, entry->params[0],
193 197 entry->params[1], entry->params[2], entry->params[3],
194 198 entry->params[4], entry->params[5], entry->params[6],
195 199 entry->params[7]);
196 200
197 201 if (++i == nentries)
198 202 i = 0;
199 203
200 204 } while (i != first);
201 205
202 206 free(devlog);
203 207 }
204 208
205 209 static void
206 210 load_fw(int argc, char *argv[], int start_arg, const char *iff_name)
207 211 {
208 212 const char *fname = argv[start_arg];
209 213 struct t4_ldfw *fw;
210 214 struct stat sb;
211 215 size_t len;
212 216 int fd;
213 217
214 218 if (argc != 4)
215 219 err(1, "incorrect number of arguments.");
216 220
217 221 fd = open(fname, O_RDONLY);
218 222 if (fd < 0)
219 223 err(1, "%s: opening %s failed", __func__, fname);
220 224 if (fstat(fd, &sb) < 0) {
221 225 close(fd);
222 226 err(1, "%s: fstat %s failed", __func__, fname);
223 227 }
224 228 len = (size_t)sb.st_size;
225 229
226 230 fw = malloc(sizeof (struct t4_ldfw) + len);
227 231 if (!fw) {
228 232 close(fd);
229 233 err(1, "%s: %s allocate %ld bytes failed",
230 234 __func__, fname, sizeof (struct t4_ldfw) + len);
231 235 }
232 236
233 237 if (read(fd, fw->data, len) < len) {
234 238 close(fd);
235 239 free(fw);
236 240 err(1, "%s: %s read failed", __func__, fname);
237 241 }
238 242
239 243 close(fd);
240 244
241 245 fw->len = len;
242 246
243 247 if (doit(iff_name, T4_IOCTL_LOAD_FW, fw)) {
244 248 free(fw);
245 249 err(1, "%s: IOCTL failed", __func__);
246 250 } else {
247 251 printf("FW flash success, reload driver/reboot to take "
248 252 "effect\n");
249 253 }
250 254
251 255 free(fw);
252 256 }
253 257
254 258 static void
255 259 run_cmd(int argc, char *argv[], const char *iff_name)
256 260 {
257 261 if (strcmp(argv[2], "devlog") == 0)
258 262 get_devlog(argc, argv, 3, iff_name);
259 263 else if (strcmp(argv[2], "loadfw") == 0)
260 264 load_fw(argc, argv, 3, iff_name);
261 265 else
262 266 usage(stderr);
263 267 }
264 268
265 269 int
266 270 main(int argc, char *argv[])
267 271 {
268 272 const char *iff_name;
269 273
270 274 progname = argv[0];
271 275
272 276 if (argc == 2) {
273 277 if (strcmp(argv[1], "-h") == 0 ||
274 278 strcmp(argv[1], "--help") == 0) {
275 279 usage(stdout);
276 280 }
277 281
278 282 if (strcmp(argv[1], "-v") == 0 ||
279 283 strcmp(argv[1], "--version") == 0) {
280 284 printf("cxgbetool version %s\n", DRV_VERSION);
281 285 exit(0);
282 286 }
283 287 }
284 288
285 289 if (argc < 3)
286 290 usage(stderr);
287 291
288 292 iff_name = argv[1];
289 293
290 294 run_cmd(argc, argv, iff_name);
291 295
292 296 return (0);
293 297 }
↓ open down ↓ |
195 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX