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