xref: /freebsd/sys/dev/ice/ice_strings.c (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2023, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @file ice_strings.c
34  * @brief functions to convert enumerated values to human readable strings
35  *
36  * Contains various functions which convert enumerated values into human
37  * readable strings. Primarily this is used for error values, such as the
38  * ice_status enum, the ice_aq_err values, or standard sys/errno.h values.
39  *
40  * Additionally, various other driver enumerations which are displayed via
41  * sysctl have converter functions.
42  *
43  * Some of the functions return struct ice_str_buf, instead of a character
44  * string pointer. This is a trick to allow the function to create a struct
45  * with space to convert unknown numeric values into a string, and return the
46  * contents via copying the struct memory back. The functions then have an
47  * associated macro to access the string value immediately. This allows the
48  * functions to return static strings for known values, and convert unknown
49  * values into a numeric representation. It also does not require
50  * pre-allocating storage at each callsite, or using a local static value
51  * which wouldn't be re-entrant, and could collide if multiple threads call
52  * the function. The extra copies are somewhat annoying, but generally the
53  * error functions aren't expected to be in a hot path so this is an
54  * acceptable trade off.
55  */
56 
57 #include "ice_lib.h"
58 
59 /**
60  * ice_aq_str - Convert an AdminQ error into a string
61  * @aq_err: the AQ error code to convert
62  *
63  * Convert the AdminQ status into its string name, if known. Otherwise, format
64  * the error as an integer.
65  */
66 struct ice_str_buf
67 _ice_aq_str(enum ice_aq_err aq_err)
68 {
69 	struct ice_str_buf buf = { .str = "" };
70 	const char *str = NULL;
71 
72 	switch (aq_err) {
73 	case ICE_AQ_RC_OK:
74 		str = "OK";
75 		break;
76 	case ICE_AQ_RC_EPERM:
77 		str = "AQ_RC_EPERM";
78 		break;
79 	case ICE_AQ_RC_ENOENT:
80 		str = "AQ_RC_ENOENT";
81 		break;
82 	case ICE_AQ_RC_ESRCH:
83 		str = "AQ_RC_ESRCH";
84 		break;
85 	case ICE_AQ_RC_EINTR:
86 		str = "AQ_RC_EINTR";
87 		break;
88 	case ICE_AQ_RC_EIO:
89 		str = "AQ_RC_EIO";
90 		break;
91 	case ICE_AQ_RC_ENXIO:
92 		str = "AQ_RC_ENXIO";
93 		break;
94 	case ICE_AQ_RC_E2BIG:
95 		str = "AQ_RC_E2BIG";
96 		break;
97 	case ICE_AQ_RC_EAGAIN:
98 		str = "AQ_RC_EAGAIN";
99 		break;
100 	case ICE_AQ_RC_ENOMEM:
101 		str = "AQ_RC_ENOMEM";
102 		break;
103 	case ICE_AQ_RC_EACCES:
104 		str = "AQ_RC_EACCES";
105 		break;
106 	case ICE_AQ_RC_EFAULT:
107 		str = "AQ_RC_EFAULT";
108 		break;
109 	case ICE_AQ_RC_EBUSY:
110 		str = "AQ_RC_EBUSY";
111 		break;
112 	case ICE_AQ_RC_EEXIST:
113 		str = "AQ_RC_EEXIST";
114 		break;
115 	case ICE_AQ_RC_EINVAL:
116 		str = "AQ_RC_EINVAL";
117 		break;
118 	case ICE_AQ_RC_ENOTTY:
119 		str = "AQ_RC_ENOTTY";
120 		break;
121 	case ICE_AQ_RC_ENOSPC:
122 		str = "AQ_RC_ENOSPC";
123 		break;
124 	case ICE_AQ_RC_ENOSYS:
125 		str = "AQ_RC_ENOSYS";
126 		break;
127 	case ICE_AQ_RC_ERANGE:
128 		str = "AQ_RC_ERANGE";
129 		break;
130 	case ICE_AQ_RC_EFLUSHED:
131 		str = "AQ_RC_EFLUSHED";
132 		break;
133 	case ICE_AQ_RC_BAD_ADDR:
134 		str = "AQ_RC_BAD_ADDR";
135 		break;
136 	case ICE_AQ_RC_EMODE:
137 		str = "AQ_RC_EMODE";
138 		break;
139 	case ICE_AQ_RC_EFBIG:
140 		str = "AQ_RC_EFBIG";
141 		break;
142 	case ICE_AQ_RC_ESBCOMP:
143 		str = "AQ_RC_ESBCOMP";
144 		break;
145 	case ICE_AQ_RC_ENOSEC:
146 		str = "AQ_RC_ENOSEC";
147 		break;
148 	case ICE_AQ_RC_EBADSIG:
149 		str = "AQ_RC_EBADSIG";
150 		break;
151 	case ICE_AQ_RC_ESVN:
152 		str = "AQ_RC_ESVN";
153 		break;
154 	case ICE_AQ_RC_EBADMAN:
155 		str = "AQ_RC_EBADMAN";
156 		break;
157 	case ICE_AQ_RC_EBADBUF:
158 		str = "AQ_RC_EBADBUF";
159 		break;
160 	case ICE_AQ_RC_EACCES_BMCU:
161 		str = "AQ_RC_EACCES_BMCU";
162 		break;
163 	}
164 
165 	if (str)
166 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
167 	else
168 		snprintf(buf.str, ICE_STR_BUF_LEN, "%d", aq_err);
169 
170 	return buf;
171 }
172 
173 /**
174  * ice_status_str - convert status err code to a string
175  * @status: the status error code to convert
176  *
177  * Convert the status code into its string name if known.
178  *
179  * Otherwise, use the scratch space to format the status code into a number.
180  */
181 struct ice_str_buf
182 _ice_status_str(enum ice_status status)
183 {
184 	struct ice_str_buf buf = { .str = "" };
185 	const char *str = NULL;
186 
187 	switch (status) {
188 	case ICE_SUCCESS:
189 		str = "OK";
190 		break;
191 	case ICE_ERR_PARAM:
192 		str = "ICE_ERR_PARAM";
193 		break;
194 	case ICE_ERR_NOT_IMPL:
195 		str = "ICE_ERR_NOT_IMPL";
196 		break;
197 	case ICE_ERR_NOT_READY:
198 		str = "ICE_ERR_NOT_READY";
199 		break;
200 	case ICE_ERR_NOT_SUPPORTED:
201 		str = "ICE_ERR_NOT_SUPPORTED";
202 		break;
203 	case ICE_ERR_BAD_PTR:
204 		str = "ICE_ERR_BAD_PTR";
205 		break;
206 	case ICE_ERR_INVAL_SIZE:
207 		str = "ICE_ERR_INVAL_SIZE";
208 		break;
209 	case ICE_ERR_DEVICE_NOT_SUPPORTED:
210 		str = "ICE_ERR_DEVICE_NOT_SUPPORTED";
211 		break;
212 	case ICE_ERR_RESET_FAILED:
213 		str = "ICE_ERR_RESET_FAILED";
214 		break;
215 	case ICE_ERR_FW_API_VER:
216 		str = "ICE_ERR_FW_API_VER";
217 		break;
218 	case ICE_ERR_NO_MEMORY:
219 		str = "ICE_ERR_NO_MEMORY";
220 		break;
221 	case ICE_ERR_CFG:
222 		str = "ICE_ERR_CFG";
223 		break;
224 	case ICE_ERR_OUT_OF_RANGE:
225 		str = "ICE_ERR_OUT_OF_RANGE";
226 		break;
227 	case ICE_ERR_ALREADY_EXISTS:
228 		str = "ICE_ERR_ALREADY_EXISTS";
229 		break;
230 	case ICE_ERR_NVM:
231 		str = "ICE_ERR_NVM";
232 		break;
233 	case ICE_ERR_NVM_CHECKSUM:
234 		str = "ICE_ERR_NVM_CHECKSUM";
235 		break;
236 	case ICE_ERR_BUF_TOO_SHORT:
237 		str = "ICE_ERR_BUF_TOO_SHORT";
238 		break;
239 	case ICE_ERR_NVM_BLANK_MODE:
240 		str = "ICE_ERR_NVM_BLANK_MODE";
241 		break;
242 	case ICE_ERR_IN_USE:
243 		str = "ICE_ERR_IN_USE";
244 		break;
245 	case ICE_ERR_MAX_LIMIT:
246 		str = "ICE_ERR_MAX_LIMIT";
247 		break;
248 	case ICE_ERR_RESET_ONGOING:
249 		str = "ICE_ERR_RESET_ONGOING";
250 		break;
251 	case ICE_ERR_HW_TABLE:
252 		str = "ICE_ERR_HW_TABLE";
253 		break;
254 	case ICE_ERR_FW_DDP_MISMATCH:
255 		str = "ICE_ERR_FW_DDP_MISMATCH";
256 		break;
257 	case ICE_ERR_DOES_NOT_EXIST:
258 		str = "ICE_ERR_DOES_NOT_EXIST";
259 		break;
260 	case ICE_ERR_AQ_ERROR:
261 		str = "ICE_ERR_AQ_ERROR";
262 		break;
263 	case ICE_ERR_AQ_TIMEOUT:
264 		str = "ICE_ERR_AQ_TIMEOUT";
265 		break;
266 	case ICE_ERR_AQ_FULL:
267 		str = "ICE_ERR_AQ_FULL";
268 		break;
269 	case ICE_ERR_AQ_NO_WORK:
270 		str = "ICE_ERR_AQ_NO_WORK";
271 		break;
272 	case ICE_ERR_AQ_EMPTY:
273 		str = "ICE_ERR_AQ_EMPTY";
274 		break;
275 	case ICE_ERR_AQ_FW_CRITICAL:
276 		str = "ICE_ERR_AQ_FW_CRITICAL";
277 		break;
278 	}
279 
280 	if (str)
281 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
282 	else
283 		snprintf(buf.str, ICE_STR_BUF_LEN, "%d", status);
284 
285 	return buf;
286 }
287 
288 /**
289  * ice_err_str - convert error code to a string
290  * @err: the error code to convert
291  *
292  * Convert an error code into its string/macro name if known. Note, it doesn't
293  * handle negated errors.
294  *
295  * Otherwise, use the scratch space to format the error into a number.
296  */
297 struct ice_str_buf
298 _ice_err_str(int err)
299 {
300 	struct ice_str_buf buf = { .str = "" };
301 	const char *str = NULL;
302 
303 	switch (err) {
304 	case 0:
305 		str = "OK";
306 		break;
307 	case EPERM:
308 		str = "EPERM";
309 		break;
310 	case ENOENT:
311 		str = "ENOENT";
312 		break;
313 	case ESRCH:
314 		str = "ESRCH";
315 		break;
316 	case EINTR:
317 		str = "EINTR";
318 		break;
319 	case EIO:
320 		str = "EIO";
321 		break;
322 	case ENXIO:
323 		str = "ENXIO";
324 		break;
325 	case E2BIG:
326 		str = "E2BIG";
327 		break;
328 	case ENOEXEC:
329 		str = "ENOEXEC";
330 		break;
331 	case EBADF:
332 		str = "EBADF";
333 		break;
334 	case ECHILD:
335 		str = "ECHILD";
336 		break;
337 	case EDEADLK:
338 		str = "EDEADLK";
339 		break;
340 	case ENOMEM:
341 		str = "ENOMEM";
342 		break;
343 	case EACCES:
344 		str = "EACCES";
345 		break;
346 	case EFAULT:
347 		str = "EFAULT";
348 		break;
349 	case ENOTBLK:
350 		str = "ENOTBLK";
351 		break;
352 	case EBUSY:
353 		str = "EBUSY";
354 		break;
355 	case EEXIST:
356 		str = "EEXIST";
357 		break;
358 	case EXDEV:
359 		str = "EXDEV";
360 		break;
361 	case ENODEV:
362 		str = "ENODEV";
363 		break;
364 	case ENOTDIR:
365 		str = "ENOTDIR";
366 		break;
367 	case EISDIR:
368 		str = "EISDIR";
369 		break;
370 	case EINVAL:
371 		str = "EINVAL";
372 		break;
373 	case ENFILE:
374 		str = "ENFILE";
375 		break;
376 	case EMFILE:
377 		str = "EMFILE";
378 		break;
379 	case ENOTTY:
380 		str = "ENOTTY";
381 		break;
382 	case ETXTBSY:
383 		str = "ETXTBSY";
384 		break;
385 	case EFBIG:
386 		str = "EFBIG";
387 		break;
388 	case ENOSPC:
389 		str = "ENOSPC";
390 		break;
391 	case ESPIPE:
392 		str = "ESPIPE";
393 		break;
394 	case EROFS:
395 		str = "EROFS";
396 		break;
397 	case EMLINK:
398 		str = "EMLINK";
399 		break;
400 	case EPIPE:
401 		str = "EPIPE";
402 		break;
403 	case EDOM:
404 		str = "EDOM";
405 		break;
406 	case ERANGE:
407 		str = "ERANGE";
408 		break;
409 	case EAGAIN:
410 		/* EWOULDBLOCK */
411 		str = "EAGAIN";
412 		break;
413 	case EINPROGRESS:
414 		str = "EINPROGRESS";
415 		break;
416 	case EALREADY:
417 		str = "EALREADY";
418 		break;
419 	case ENOTSOCK:
420 		str = "ENOTSOCK";
421 		break;
422 	case EDESTADDRREQ:
423 		str = "EDESTADDRREQ";
424 		break;
425 	case EMSGSIZE:
426 		str = "EMSGSIZE";
427 		break;
428 	case EPROTOTYPE:
429 		str = "EPROTOTYPE";
430 		break;
431 	case ENOPROTOOPT:
432 		str = "ENOPROTOOPT";
433 		break;
434 	case EPROTONOSUPPORT:
435 		str = "EPROTONOSUPPORT";
436 		break;
437 	case ESOCKTNOSUPPORT:
438 		str = "ESOCKTNOSUPPORT";
439 		break;
440 	case EOPNOTSUPP:
441 		str = "EOPNOTSUPP";
442 		break;
443 	case EPFNOSUPPORT:
444 		/* ENOTSUP */
445 		str = "EPFNOSUPPORT";
446 		break;
447 	case EAFNOSUPPORT:
448 		str = "EAFNOSUPPORT";
449 		break;
450 	case EADDRINUSE:
451 		str = "EADDRINUSE";
452 		break;
453 	case EADDRNOTAVAIL:
454 		str = "EADDRNOTAVAIL";
455 		break;
456 	case ENETDOWN:
457 		str = "ENETDOWN";
458 		break;
459 	case ENETUNREACH:
460 		str = "ENETUNREACH";
461 		break;
462 	case ENETRESET:
463 		str = "ENETRESET";
464 		break;
465 	case ECONNABORTED:
466 		str = "ECONNABORTED";
467 		break;
468 	case ECONNRESET:
469 		str = "ECONNRESET";
470 		break;
471 	case ENOBUFS:
472 		str = "ENOBUFS";
473 		break;
474 	case EISCONN:
475 		str = "EISCONN";
476 		break;
477 	case ENOTCONN:
478 		str = "ENOTCONN";
479 		break;
480 	case ESHUTDOWN:
481 		str = "ESHUTDOWN";
482 		break;
483 	case ETOOMANYREFS:
484 		str = "ETOOMANYREFS";
485 		break;
486 	case ETIMEDOUT:
487 		str = "ETIMEDOUT";
488 		break;
489 	case ECONNREFUSED:
490 		str = "ECONNREFUSED";
491 		break;
492 	case ELOOP:
493 		str = "ELOOP";
494 		break;
495 	case ENAMETOOLONG:
496 		str = "ENAMETOOLONG";
497 		break;
498 	case EHOSTDOWN:
499 		str = "EHOSTDOWN";
500 		break;
501 	case EHOSTUNREACH:
502 		str = "EHOSTUNREACH";
503 		break;
504 	case ENOTEMPTY:
505 		str = "ENOTEMPTY";
506 		break;
507 	case EPROCLIM:
508 		str = "EPROCLIM";
509 		break;
510 	case EUSERS:
511 		str = "EUSERS";
512 		break;
513 	case EDQUOT:
514 		str = "EDQUOT";
515 		break;
516 	case ESTALE:
517 		str = "ESTALE";
518 		break;
519 	case EREMOTE:
520 		str = "EREMOTE";
521 		break;
522 	case EBADRPC:
523 		str = "EBADRPC";
524 		break;
525 	case ERPCMISMATCH:
526 		str = "ERPCMISMATCH";
527 		break;
528 	case EPROGUNAVAIL:
529 		str = "EPROGUNAVAIL";
530 		break;
531 	case EPROGMISMATCH:
532 		str = "EPROGMISMATCH";
533 		break;
534 	case EPROCUNAVAIL:
535 		str = "EPROCUNAVAIL";
536 		break;
537 	case ENOLCK:
538 		str = "ENOLCK";
539 		break;
540 	case ENOSYS:
541 		str = "ENOSYS";
542 		break;
543 	case EFTYPE:
544 		str = "EFTYPE";
545 		break;
546 	case EAUTH:
547 		str = "EAUTH";
548 		break;
549 	case ENEEDAUTH:
550 		str = "ENEEDAUTH";
551 		break;
552 	case EIDRM:
553 		str = "EIDRM";
554 		break;
555 	case ENOMSG:
556 		str = "ENOMSG";
557 		break;
558 	case EOVERFLOW:
559 		str = "EOVERFLOW";
560 		break;
561 	case ECANCELED:
562 		str = "ECANCELED";
563 		break;
564 	case EILSEQ:
565 		str = "EILSEQ";
566 		break;
567 	case ENOATTR:
568 		str = "ENOATTR";
569 		break;
570 	case EDOOFUS:
571 		str = "EDOOFUS";
572 		break;
573 	case EBADMSG:
574 		str = "EBADMSG";
575 		break;
576 	case EMULTIHOP:
577 		str = "EMULTIHOP";
578 		break;
579 	case ENOLINK:
580 		str = "ENOLINK";
581 		break;
582 	case EPROTO:
583 		str = "EPROTO";
584 		break;
585 	case ENOTCAPABLE:
586 		str = "ENOTCAPABLE";
587 		break;
588 	case ECAPMODE:
589 		str = "ECAPMODE";
590 		break;
591 	case ENOTRECOVERABLE:
592 		str = "ENOTRECOVERABLE";
593 		break;
594 	case EOWNERDEAD:
595 		str = "EOWNERDEAD";
596 		break;
597 	}
598 
599 	if (str)
600 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
601 	else
602 		snprintf(buf.str, ICE_STR_BUF_LEN, "%d", err);
603 
604 	return buf;
605 }
606 
607 /**
608  * ice_fec_str - convert fec mode enum to a string
609  * @mode: the enum value to convert
610  *
611  * Convert an FEC mode enum to a string for display in a sysctl or log message.
612  * Returns "Unknown" if the mode is not one of currently known FEC modes.
613  */
614 const char *
615 ice_fec_str(enum ice_fec_mode mode)
616 {
617 	switch (mode) {
618 	case ICE_FEC_AUTO:
619 		return ICE_FEC_STRING_AUTO;
620 	case ICE_FEC_RS:
621 		return ICE_FEC_STRING_RS;
622 	case ICE_FEC_BASER:
623 		return ICE_FEC_STRING_BASER;
624 	case ICE_FEC_NONE:
625 		return ICE_FEC_STRING_NONE;
626 	case ICE_FEC_DIS_AUTO:
627 		return ICE_FEC_STRING_DIS_AUTO;
628 	}
629 
630 	/* The compiler generates errors on unhandled enum values if we omit
631 	 * the default case.
632 	 */
633 	return "Unknown";
634 }
635 
636 /**
637  * ice_fc_str - convert flow control mode enum to a string
638  * @mode: the enum value to convert
639  *
640  * Convert a flow control mode enum to a string for display in a sysctl or log
641  * message. Returns "Unknown" if the mode is not one of currently supported or
642  * known flow control modes.
643  */
644 const char *
645 ice_fc_str(enum ice_fc_mode mode)
646 {
647 	switch (mode) {
648 	case ICE_FC_FULL:
649 		return ICE_FC_STRING_FULL;
650 	case ICE_FC_TX_PAUSE:
651 		return ICE_FC_STRING_TX;
652 	case ICE_FC_RX_PAUSE:
653 		return ICE_FC_STRING_RX;
654 	case ICE_FC_NONE:
655 		return ICE_FC_STRING_NONE;
656 	case ICE_FC_AUTO:
657 	case ICE_FC_PFC:
658 	case ICE_FC_DFLT:
659 		break;
660 	}
661 
662 	/* The compiler generates errors on unhandled enum values if we omit
663 	 * the default case.
664 	 */
665 	return "Unknown";
666 }
667 
668 /**
669  * ice_fltr_flag_str - Convert filter flags to a string
670  * @flag: the filter flags to convert
671  *
672  * Convert the u16 flag value of a filter into a readable string for
673  * outputting in a sysctl.
674  */
675 struct ice_str_buf
676 _ice_fltr_flag_str(u16 flag)
677 {
678 	struct ice_str_buf buf = { .str = "" };
679 	const char *str = NULL;
680 
681 	switch (flag) {
682 	case ICE_FLTR_RX:
683 		str = "RX";
684 		break;
685 	case ICE_FLTR_TX:
686 		str = "TX";
687 		break;
688 	case ICE_FLTR_TX_RX:
689 		str = "TX_RX";
690 		break;
691 	default:
692 		break;
693 	}
694 
695 	if (str)
696 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
697 	else
698 		snprintf(buf.str, ICE_STR_BUF_LEN, "%u", flag);
699 
700 	return buf;
701 }
702 
703 /**
704  * ice_log_sev_str - Convert log level to a string
705  * @log_level: the log level to convert
706  *
707  * Convert the u8 log level of a FW logging module into a readable
708  * string for outputting in a sysctl.
709  */
710 struct ice_str_buf
711 _ice_log_sev_str(u8 log_level)
712 {
713 	struct ice_str_buf buf = { .str = "" };
714 	const char *str = NULL;
715 
716 	switch (log_level) {
717 	case ICE_FWLOG_LEVEL_NONE:
718 		str = "none";
719 		break;
720 	case ICE_FWLOG_LEVEL_ERROR:
721 		str = "error";
722 		break;
723 	case ICE_FWLOG_LEVEL_WARNING:
724 		str = "warning";
725 		break;
726 	case ICE_FWLOG_LEVEL_NORMAL:
727 		str = "normal";
728 		break;
729 	case ICE_FWLOG_LEVEL_VERBOSE:
730 		str = "verbose";
731 		break;
732 	default:
733 		break;
734 	}
735 
736 	if (str)
737 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
738 	else
739 		snprintf(buf.str, ICE_STR_BUF_LEN, "%u", log_level);
740 
741 	return buf;
742 }
743 
744 /**
745  * ice_fwd_act_str - convert filter action enum to a string
746  * @action: the filter action to convert
747  *
748  * Convert an enum value of type enum ice_sw_fwd_act_type into a string, for
749  * display in a sysctl filter list. Returns "UNKNOWN" for actions outside the
750  * enumeration type.
751  */
752 const char *
753 ice_fwd_act_str(enum ice_sw_fwd_act_type action)
754 {
755 	switch (action) {
756 	case ICE_FWD_TO_VSI:
757 		return "FWD_TO_VSI";
758 	case ICE_FWD_TO_VSI_LIST:
759 		return "FWD_TO_VSI_LIST";
760 	case ICE_FWD_TO_Q:
761 		return "FWD_TO_Q";
762 	case ICE_FWD_TO_QGRP:
763 		return "FWD_TO_QGRP";
764 	case ICE_DROP_PACKET:
765 		return "DROP_PACKET";
766 	case ICE_LG_ACTION:
767 		return "LG_ACTION";
768 	case ICE_INVAL_ACT:
769 		return "INVAL_ACT";
770 	}
771 
772 	/* The compiler generates errors on unhandled enum values if we omit
773 	 * the default case.
774 	 */
775 	return "Unknown";
776 }
777 
778 /**
779  * ice_mdd_tx_tclan_str - Convert MDD Tx TCLAN event to a string
780  * @event: the MDD event number to convert
781  *
782  * Convert the Tx TCLAN event value from the GL_MDET_TX_TCLAN register into
783  * a human readable string for logging of MDD events.
784  */
785 struct ice_str_buf
786 _ice_mdd_tx_tclan_str(u8 event)
787 {
788 	struct ice_str_buf buf = { .str = "" };
789 	const char *str = NULL;
790 
791 	switch (event) {
792 	case 0:
793 		str = "Wrong descriptor format/order";
794 		break;
795 	case 1:
796 		str = "Descriptor fetch failed";
797 		break;
798 	case 2:
799 		str = "Tail descriptor not EOP/NOP";
800 		break;
801 	case 3:
802 		str = "False scheduling error";
803 		break;
804 	case 4:
805 		str = "Tail value larger than ring len";
806 		break;
807 	case 5:
808 		str = "Too many data commands";
809 		break;
810 	case 6:
811 		str = "Zero packets sent in quanta";
812 		break;
813 	case 7:
814 		str = "Packet too small or too big";
815 		break;
816 	case 8:
817 		str = "TSO length doesn't match sum";
818 		break;
819 	case 9:
820 		str = "TSO tail reached before TLEN";
821 		break;
822 	case 10:
823 		str = "TSO max 3 descs for headers";
824 		break;
825 	case 11:
826 		str = "EOP on header descriptor";
827 		break;
828 	case 12:
829 		str = "MSS is 0 or TLEN is 0";
830 		break;
831 	case 13:
832 		str = "CTX desc invalid IPSec fields";
833 		break;
834 	case 14:
835 		str = "Quanta invalid # of SSO packets";
836 		break;
837 	case 15:
838 		str = "Quanta bytes exceeds pkt_len*64";
839 		break;
840 	case 16:
841 		str = "Quanta exceeds max_cmds_in_sq";
842 		break;
843 	case 17:
844 		str = "incoherent last_lso_quanta";
845 		break;
846 	case 18:
847 		str = "incoherent TSO TLEN";
848 		break;
849 	case 19:
850 		str = "Quanta: too many descriptors";
851 		break;
852 	case 20:
853 		str = "Quanta: # of packets mismatch";
854 		break;
855 	default:
856 		break;
857 	}
858 
859 	if (str)
860 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
861 	else
862 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx TCLAN event %u", event);
863 
864 	return buf;
865 }
866 
867 /**
868  * ice_mdd_tx_pqm_str - Convert MDD Tx PQM event to a string
869  * @event: the MDD event number to convert
870  *
871  * Convert the Tx PQM event value from the GL_MDET_TX_PQM register into
872  * a human readable string for logging of MDD events.
873  */
874 struct ice_str_buf
875 _ice_mdd_tx_pqm_str(u8 event)
876 {
877 	struct ice_str_buf buf = { .str = "" };
878 	const char *str = NULL;
879 
880 	switch (event) {
881 	case 0:
882 		str = "PCI_DUMMY_COMP";
883 		break;
884 	case 1:
885 		str = "PCI_UR_COMP";
886 		break;
887 	/* Index 2 is unused */
888 	case 3:
889 		str = "RCV_SH_BE_LSO";
890 		break;
891 	case 4:
892 		str = "Q_FL_MNG_EPY_CH";
893 		break;
894 	case 5:
895 		str = "Q_EPY_MNG_FL_CH";
896 		break;
897 	case 6:
898 		str = "LSO_NUMDESCS_ZERO";
899 		break;
900 	case 7:
901 		str = "LSO_LENGTH_ZERO";
902 		break;
903 	case 8:
904 		str = "LSO_MSS_BELOW_MIN";
905 		break;
906 	case 9:
907 		str = "LSO_MSS_ABOVE_MAX";
908 		break;
909 	case 10:
910 		str = "LSO_HDR_SIZE_ZERO";
911 		break;
912 	case 11:
913 		str = "RCV_CNT_BE_LSO";
914 		break;
915 	case 12:
916 		str = "SKIP_ONE_QT_ONLY";
917 		break;
918 	case 13:
919 		str = "LSO_PKTCNT_ZERO";
920 		break;
921 	case 14:
922 		str = "SSO_LENGTH_ZERO";
923 		break;
924 	case 15:
925 		str = "SSO_LENGTH_EXCEED";
926 		break;
927 	case 16:
928 		str = "SSO_PKTCNT_ZERO";
929 		break;
930 	case 17:
931 		str = "SSO_PKTCNT_EXCEED";
932 		break;
933 	case 18:
934 		str = "SSO_NUMDESCS_ZERO";
935 		break;
936 	case 19:
937 		str = "SSO_NUMDESCS_EXCEED";
938 		break;
939 	case 20:
940 		str = "TAIL_GT_RING_LENGTH";
941 		break;
942 	case 21:
943 		str = "RESERVED_DBL_TYPE";
944 		break;
945 	case 22:
946 		str = "ILLEGAL_HEAD_DROP_DBL";
947 		break;
948 	case 23:
949 		str = "LSO_OVER_COMMS_Q";
950 		break;
951 	case 24:
952 		str = "ILLEGAL_VF_QNUM";
953 		break;
954 	case 25:
955 		str = "QTAIL_GT_RING_LENGTH";
956 		break;
957 	default:
958 		break;
959 	}
960 
961 	if (str)
962 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
963 	else
964 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx PQM event %u", event);
965 
966 	return buf;
967 }
968 
969 /**
970  * ice_mdd_rx_str - Convert MDD Rx queue event to a string
971  * @event: the MDD event number to convert
972  *
973  * Convert the Rx queue event value from the GL_MDET_RX register into a human
974  * readable string for logging of MDD events.
975  */
976 struct ice_str_buf
977 _ice_mdd_rx_str(u8 event)
978 {
979 	struct ice_str_buf buf = { .str = "" };
980 	const char *str = NULL;
981 
982 	switch (event) {
983 	case 1:
984 		str = "Descriptor fetch failed";
985 		break;
986 	default:
987 		break;
988 	}
989 
990 	if (str)
991 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
992 	else
993 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Rx event %u", event);
994 
995 	return buf;
996 }
997 
998 /**
999  * ice_state_to_str - Convert the state enum to a string value
1000  * @state: the state bit to convert
1001  *
1002  * Converts a given state bit to its human readable string name. If the enum
1003  * value is unknown, returns NULL;
1004  */
1005 const char *
1006 ice_state_to_str(enum ice_state state)
1007 {
1008 	switch (state) {
1009 	case ICE_STATE_CONTROLQ_EVENT_PENDING:
1010 		return "CONTROLQ_EVENT_PENDING";
1011 	case ICE_STATE_VFLR_PENDING:
1012 		return "VFLR_PENDING";
1013 	case ICE_STATE_MDD_PENDING:
1014 		return "MDD_PENDING";
1015 	case ICE_STATE_RESET_OICR_RECV:
1016 		return "RESET_OICR_RECV";
1017 	case ICE_STATE_RESET_PFR_REQ:
1018 		return "RESET_PFR_REQ";
1019 	case ICE_STATE_PREPARED_FOR_RESET:
1020 		return "PREPARED_FOR_RESET";
1021 	case ICE_STATE_RESET_FAILED:
1022 		return "RESET_FAILED";
1023 	case ICE_STATE_DRIVER_INITIALIZED:
1024 		return "DRIVER_INITIALIZED";
1025 	case ICE_STATE_NO_MEDIA:
1026 		return "NO_MEDIA";
1027 	case ICE_STATE_RECOVERY_MODE:
1028 		return "RECOVERY_MODE";
1029 	case ICE_STATE_ROLLBACK_MODE:
1030 		return "ROLLBACK_MODE";
1031 	case ICE_STATE_LINK_STATUS_REPORTED:
1032 		return "LINK_STATUS_REPORTED";
1033 	case ICE_STATE_ATTACHING:
1034 		return "ATTACHING";
1035 	case ICE_STATE_DETACHING:
1036 		return "DETACHING";
1037 	case ICE_STATE_LINK_DEFAULT_OVERRIDE_PENDING:
1038 		return "LINK_DEFAULT_OVERRIDE_PENDING";
1039 	case ICE_STATE_LLDP_RX_FLTR_FROM_DRIVER:
1040 		return "LLDP_RX_FLTR_FROM_DRIVER";
1041 	case ICE_STATE_MULTIPLE_TCS:
1042 		return "MULTIPLE_TCS";
1043 	case ICE_STATE_DO_FW_DEBUG_DUMP:
1044 		return "DO_FW_DEBUG_DUMP";
1045 	case ICE_STATE_LINK_ACTIVE_ON_DOWN:
1046 		return "LINK_ACTIVE_ON_DOWN";
1047 	case ICE_STATE_FIRST_INIT_LINK:
1048 		return "FIRST_INIT_LINK";
1049 	case ICE_STATE_LAST:
1050 		return NULL;
1051 	}
1052 
1053 	return NULL;
1054 }
1055 
1056 /**
1057  * ice_fw_module_str - Convert a FW logging module to a string name
1058  * @module: the module to convert
1059  *
1060  * Given a FW logging module id, convert it to a shorthand human readable
1061  * name, for generating sysctl tunables.
1062  */
1063 const char *
1064 ice_fw_module_str(enum ice_aqc_fw_logging_mod module)
1065 {
1066 	switch (module) {
1067 	case ICE_AQC_FW_LOG_ID_GENERAL:
1068 		return "general";
1069 	case ICE_AQC_FW_LOG_ID_CTRL:
1070 		return "ctrl";
1071 	case ICE_AQC_FW_LOG_ID_LINK:
1072 		return "link";
1073 	case ICE_AQC_FW_LOG_ID_LINK_TOPO:
1074 		return "link_topo";
1075 	case ICE_AQC_FW_LOG_ID_DNL:
1076 		return "dnl";
1077 	case ICE_AQC_FW_LOG_ID_I2C:
1078 		return "i2c";
1079 	case ICE_AQC_FW_LOG_ID_SDP:
1080 		return "sdp";
1081 	case ICE_AQC_FW_LOG_ID_MDIO:
1082 		return "mdio";
1083 	case ICE_AQC_FW_LOG_ID_ADMINQ:
1084 		return "adminq";
1085 	case ICE_AQC_FW_LOG_ID_HDMA:
1086 		return "hdma";
1087 	case ICE_AQC_FW_LOG_ID_LLDP:
1088 		return "lldp";
1089 	case ICE_AQC_FW_LOG_ID_DCBX:
1090 		return "dcbx";
1091 	case ICE_AQC_FW_LOG_ID_DCB:
1092 		return "dcb";
1093 	case ICE_AQC_FW_LOG_ID_XLR:
1094 		return "xlr";
1095 	case ICE_AQC_FW_LOG_ID_NVM:
1096 		return "nvm";
1097 	case ICE_AQC_FW_LOG_ID_AUTH:
1098 		return "auth";
1099 	case ICE_AQC_FW_LOG_ID_VPD:
1100 		return "vpd";
1101 	case ICE_AQC_FW_LOG_ID_IOSF:
1102 		return "iosf";
1103 	case ICE_AQC_FW_LOG_ID_PARSER:
1104 		return "parser";
1105 	case ICE_AQC_FW_LOG_ID_SW:
1106 		return "sw";
1107 	case ICE_AQC_FW_LOG_ID_SCHEDULER:
1108 		return "scheduler";
1109 	case ICE_AQC_FW_LOG_ID_TXQ:
1110 		return "txq";
1111 	case ICE_AQC_FW_LOG_ID_RSVD:
1112 		return "acl";
1113 	case ICE_AQC_FW_LOG_ID_POST:
1114 		return "post";
1115 	case ICE_AQC_FW_LOG_ID_WATCHDOG:
1116 		return "watchdog";
1117 	case ICE_AQC_FW_LOG_ID_TASK_DISPATCH:
1118 		return "task_dispatch";
1119 	case ICE_AQC_FW_LOG_ID_MNG:
1120 		return "mng";
1121 	case ICE_AQC_FW_LOG_ID_SYNCE:
1122 		return "synce";
1123 	case ICE_AQC_FW_LOG_ID_HEALTH:
1124 		return "health";
1125 	case ICE_AQC_FW_LOG_ID_TSDRV:
1126 		return "tsdrv";
1127 	case ICE_AQC_FW_LOG_ID_PFREG:
1128 		return "pfreg";
1129 	case ICE_AQC_FW_LOG_ID_MDLVER:
1130 		return "mdlver";
1131 	case ICE_AQC_FW_LOG_ID_MAX:
1132 		return "unknown";
1133 	}
1134 
1135 	/* The compiler generates errors on unhandled enum values if we omit
1136 	 * the default case.
1137 	 */
1138 	return "unknown";
1139 }
1140 
1141 /**
1142  * ice_fw_lldp_status - Convert FW LLDP status to a string
1143  * @lldp_status: firmware LLDP status value to convert
1144  *
1145  * Given the FW LLDP status, convert it to a human readable string.
1146  */
1147 struct ice_str_buf
1148 _ice_fw_lldp_status(u32 lldp_status)
1149 {
1150 	struct ice_str_buf buf = { .str = "" };
1151 	const char *str = NULL;
1152 
1153 	switch (lldp_status)
1154 	{
1155 	case ICE_LLDP_ADMINSTATUS_DIS:
1156 		str = "DISABLED";
1157 		break;
1158 	case ICE_LLDP_ADMINSTATUS_ENA_RX:
1159 		str = "ENA_RX";
1160 		break;
1161 	case ICE_LLDP_ADMINSTATUS_ENA_TX:
1162 		str = "ENA_TX";
1163 		break;
1164 	case ICE_LLDP_ADMINSTATUS_ENA_RXTX:
1165 		str = "ENA_RXTX";
1166 		break;
1167 	case 0xF:
1168 		str = "NVM_DEFAULT";
1169 		break;
1170 	}
1171 
1172 	if (str)
1173 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
1174 	else
1175 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown LLDP status %u", lldp_status);
1176 
1177 	return buf;
1178 }
1179