xref: /freebsd/sys/dev/ice/ice_strings.c (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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 /*$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 	case ICE_FEC_DIS_AUTO:
628 		return ICE_FEC_STRING_DIS_AUTO;
629 	}
630 
631 	/* The compiler generates errors on unhandled enum values if we omit
632 	 * the default case.
633 	 */
634 	return "Unknown";
635 }
636 
637 /**
638  * ice_fc_str - convert flow control mode enum to a string
639  * @mode: the enum value to convert
640  *
641  * Convert a flow control mode enum to a string for display in a sysctl or log
642  * message. Returns "Unknown" if the mode is not one of currently supported or
643  * known flow control modes.
644  */
645 const char *
646 ice_fc_str(enum ice_fc_mode mode)
647 {
648 	switch (mode) {
649 	case ICE_FC_FULL:
650 		return ICE_FC_STRING_FULL;
651 	case ICE_FC_TX_PAUSE:
652 		return ICE_FC_STRING_TX;
653 	case ICE_FC_RX_PAUSE:
654 		return ICE_FC_STRING_RX;
655 	case ICE_FC_NONE:
656 		return ICE_FC_STRING_NONE;
657 	case ICE_FC_AUTO:
658 	case ICE_FC_PFC:
659 	case ICE_FC_DFLT:
660 		break;
661 	}
662 
663 	/* The compiler generates errors on unhandled enum values if we omit
664 	 * the default case.
665 	 */
666 	return "Unknown";
667 }
668 
669 /**
670  * ice_fltr_flag_str - Convert filter flags to a string
671  * @flag: the filter flags to convert
672  *
673  * Convert the u16 flag value of a filter into a readable string for
674  * outputting in a sysctl.
675  */
676 struct ice_str_buf
677 _ice_fltr_flag_str(u16 flag)
678 {
679 	struct ice_str_buf buf = { .str = "" };
680 	const char *str = NULL;
681 
682 	switch (flag) {
683 	case ICE_FLTR_RX:
684 		str = "RX";
685 		break;
686 	case ICE_FLTR_TX:
687 		str = "TX";
688 		break;
689 	case ICE_FLTR_TX_RX:
690 		str = "TX_RX";
691 		break;
692 	default:
693 		break;
694 	}
695 
696 	if (str)
697 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
698 	else
699 		snprintf(buf.str, ICE_STR_BUF_LEN, "%u", flag);
700 
701 	return buf;
702 }
703 
704 /**
705  * ice_log_sev_str - Convert log level to a string
706  * @log_level: the log level to convert
707  *
708  * Convert the u8 log level of a FW logging module into a readable
709  * string for outputting in a sysctl.
710  */
711 struct ice_str_buf
712 _ice_log_sev_str(u8 log_level)
713 {
714 	struct ice_str_buf buf = { .str = "" };
715 	const char *str = NULL;
716 
717 	switch (log_level) {
718 	case ICE_FWLOG_LEVEL_NONE:
719 		str = "none";
720 		break;
721 	case ICE_FWLOG_LEVEL_ERROR:
722 		str = "error";
723 		break;
724 	case ICE_FWLOG_LEVEL_WARNING:
725 		str = "warning";
726 		break;
727 	case ICE_FWLOG_LEVEL_NORMAL:
728 		str = "normal";
729 		break;
730 	case ICE_FWLOG_LEVEL_VERBOSE:
731 		str = "verbose";
732 		break;
733 	default:
734 		break;
735 	}
736 
737 	if (str)
738 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
739 	else
740 		snprintf(buf.str, ICE_STR_BUF_LEN, "%u", log_level);
741 
742 	return buf;
743 }
744 
745 /**
746  * ice_fwd_act_str - convert filter action enum to a string
747  * @action: the filter action to convert
748  *
749  * Convert an enum value of type enum ice_sw_fwd_act_type into a string, for
750  * display in a sysctl filter list. Returns "UNKNOWN" for actions outside the
751  * enumeration type.
752  */
753 const char *
754 ice_fwd_act_str(enum ice_sw_fwd_act_type action)
755 {
756 	switch (action) {
757 	case ICE_FWD_TO_VSI:
758 		return "FWD_TO_VSI";
759 	case ICE_FWD_TO_VSI_LIST:
760 		return "FWD_TO_VSI_LIST";
761 	case ICE_FWD_TO_Q:
762 		return "FWD_TO_Q";
763 	case ICE_FWD_TO_QGRP:
764 		return "FWD_TO_QGRP";
765 	case ICE_DROP_PACKET:
766 		return "DROP_PACKET";
767 	case ICE_LG_ACTION:
768 		return "LG_ACTION";
769 	case ICE_INVAL_ACT:
770 		return "INVAL_ACT";
771 	}
772 
773 	/* The compiler generates errors on unhandled enum values if we omit
774 	 * the default case.
775 	 */
776 	return "Unknown";
777 }
778 
779 /**
780  * ice_mdd_tx_tclan_str - Convert MDD Tx TCLAN event to a string
781  * @event: the MDD event number to convert
782  *
783  * Convert the Tx TCLAN event value from the GL_MDET_TX_TCLAN register into
784  * a human readable string for logging of MDD events.
785  */
786 struct ice_str_buf
787 _ice_mdd_tx_tclan_str(u8 event)
788 {
789 	struct ice_str_buf buf = { .str = "" };
790 	const char *str = NULL;
791 
792 	switch (event) {
793 	case 0:
794 		str = "Wrong descriptor format/order";
795 		break;
796 	case 1:
797 		str = "Descriptor fetch failed";
798 		break;
799 	case 2:
800 		str = "Tail descriptor not EOP/NOP";
801 		break;
802 	case 3:
803 		str = "False scheduling error";
804 		break;
805 	case 4:
806 		str = "Tail value larger than ring len";
807 		break;
808 	case 5:
809 		str = "Too many data commands";
810 		break;
811 	case 6:
812 		str = "Zero packets sent in quanta";
813 		break;
814 	case 7:
815 		str = "Packet too small or too big";
816 		break;
817 	case 8:
818 		str = "TSO length doesn't match sum";
819 		break;
820 	case 9:
821 		str = "TSO tail reached before TLEN";
822 		break;
823 	case 10:
824 		str = "TSO max 3 descs for headers";
825 		break;
826 	case 11:
827 		str = "EOP on header descriptor";
828 		break;
829 	case 12:
830 		str = "MSS is 0 or TLEN is 0";
831 		break;
832 	case 13:
833 		str = "CTX desc invalid IPSec fields";
834 		break;
835 	case 14:
836 		str = "Quanta invalid # of SSO packets";
837 		break;
838 	case 15:
839 		str = "Quanta bytes exceeds pkt_len*64";
840 		break;
841 	case 16:
842 		str = "Quanta exceeds max_cmds_in_sq";
843 		break;
844 	case 17:
845 		str = "incoherent last_lso_quanta";
846 		break;
847 	case 18:
848 		str = "incoherent TSO TLEN";
849 		break;
850 	case 19:
851 		str = "Quanta: too many descriptors";
852 		break;
853 	case 20:
854 		str = "Quanta: # of packets mismatch";
855 		break;
856 	default:
857 		break;
858 	}
859 
860 	if (str)
861 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
862 	else
863 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx TCLAN event %u", event);
864 
865 	return buf;
866 }
867 
868 /**
869  * ice_mdd_tx_pqm_str - Convert MDD Tx PQM event to a string
870  * @event: the MDD event number to convert
871  *
872  * Convert the Tx PQM event value from the GL_MDET_TX_PQM register into
873  * a human readable string for logging of MDD events.
874  */
875 struct ice_str_buf
876 _ice_mdd_tx_pqm_str(u8 event)
877 {
878 	struct ice_str_buf buf = { .str = "" };
879 	const char *str = NULL;
880 
881 	switch (event) {
882 	case 0:
883 		str = "PCI_DUMMY_COMP";
884 		break;
885 	case 1:
886 		str = "PCI_UR_COMP";
887 		break;
888 	/* Index 2 is unused */
889 	case 3:
890 		str = "RCV_SH_BE_LSO";
891 		break;
892 	case 4:
893 		str = "Q_FL_MNG_EPY_CH";
894 		break;
895 	case 5:
896 		str = "Q_EPY_MNG_FL_CH";
897 		break;
898 	case 6:
899 		str = "LSO_NUMDESCS_ZERO";
900 		break;
901 	case 7:
902 		str = "LSO_LENGTH_ZERO";
903 		break;
904 	case 8:
905 		str = "LSO_MSS_BELOW_MIN";
906 		break;
907 	case 9:
908 		str = "LSO_MSS_ABOVE_MAX";
909 		break;
910 	case 10:
911 		str = "LSO_HDR_SIZE_ZERO";
912 		break;
913 	case 11:
914 		str = "RCV_CNT_BE_LSO";
915 		break;
916 	case 12:
917 		str = "SKIP_ONE_QT_ONLY";
918 		break;
919 	case 13:
920 		str = "LSO_PKTCNT_ZERO";
921 		break;
922 	case 14:
923 		str = "SSO_LENGTH_ZERO";
924 		break;
925 	case 15:
926 		str = "SSO_LENGTH_EXCEED";
927 		break;
928 	case 16:
929 		str = "SSO_PKTCNT_ZERO";
930 		break;
931 	case 17:
932 		str = "SSO_PKTCNT_EXCEED";
933 		break;
934 	case 18:
935 		str = "SSO_NUMDESCS_ZERO";
936 		break;
937 	case 19:
938 		str = "SSO_NUMDESCS_EXCEED";
939 		break;
940 	case 20:
941 		str = "TAIL_GT_RING_LENGTH";
942 		break;
943 	case 21:
944 		str = "RESERVED_DBL_TYPE";
945 		break;
946 	case 22:
947 		str = "ILLEGAL_HEAD_DROP_DBL";
948 		break;
949 	case 23:
950 		str = "LSO_OVER_COMMS_Q";
951 		break;
952 	case 24:
953 		str = "ILLEGAL_VF_QNUM";
954 		break;
955 	case 25:
956 		str = "QTAIL_GT_RING_LENGTH";
957 		break;
958 	default:
959 		break;
960 	}
961 
962 	if (str)
963 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
964 	else
965 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx PQM event %u", event);
966 
967 	return buf;
968 }
969 
970 /**
971  * ice_mdd_rx_str - Convert MDD Rx queue event to a string
972  * @event: the MDD event number to convert
973  *
974  * Convert the Rx queue event value from the GL_MDET_RX register into a human
975  * readable string for logging of MDD events.
976  */
977 struct ice_str_buf
978 _ice_mdd_rx_str(u8 event)
979 {
980 	struct ice_str_buf buf = { .str = "" };
981 	const char *str = NULL;
982 
983 	switch (event) {
984 	case 1:
985 		str = "Descriptor fetch failed";
986 		break;
987 	default:
988 		break;
989 	}
990 
991 	if (str)
992 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
993 	else
994 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Rx event %u", event);
995 
996 	return buf;
997 }
998 
999 /**
1000  * ice_state_to_str - Convert the state enum to a string value
1001  * @state: the state bit to convert
1002  *
1003  * Converts a given state bit to its human readable string name. If the enum
1004  * value is unknown, returns NULL;
1005  */
1006 const char *
1007 ice_state_to_str(enum ice_state state)
1008 {
1009 	switch (state) {
1010 	case ICE_STATE_CONTROLQ_EVENT_PENDING:
1011 		return "CONTROLQ_EVENT_PENDING";
1012 	case ICE_STATE_VFLR_PENDING:
1013 		return "VFLR_PENDING";
1014 	case ICE_STATE_MDD_PENDING:
1015 		return "MDD_PENDING";
1016 	case ICE_STATE_RESET_OICR_RECV:
1017 		return "RESET_OICR_RECV";
1018 	case ICE_STATE_RESET_PFR_REQ:
1019 		return "RESET_PFR_REQ";
1020 	case ICE_STATE_PREPARED_FOR_RESET:
1021 		return "PREPARED_FOR_RESET";
1022 	case ICE_STATE_RESET_FAILED:
1023 		return "RESET_FAILED";
1024 	case ICE_STATE_DRIVER_INITIALIZED:
1025 		return "DRIVER_INITIALIZED";
1026 	case ICE_STATE_NO_MEDIA:
1027 		return "NO_MEDIA";
1028 	case ICE_STATE_RECOVERY_MODE:
1029 		return "RECOVERY_MODE";
1030 	case ICE_STATE_ROLLBACK_MODE:
1031 		return "ROLLBACK_MODE";
1032 	case ICE_STATE_LINK_STATUS_REPORTED:
1033 		return "LINK_STATUS_REPORTED";
1034 	case ICE_STATE_ATTACHING:
1035 		return "ATTACHING";
1036 	case ICE_STATE_DETACHING:
1037 		return "DETACHING";
1038 	case ICE_STATE_LINK_DEFAULT_OVERRIDE_PENDING:
1039 		return "LINK_DEFAULT_OVERRIDE_PENDING";
1040 	case ICE_STATE_LLDP_RX_FLTR_FROM_DRIVER:
1041 		return "LLDP_RX_FLTR_FROM_DRIVER";
1042 	case ICE_STATE_MULTIPLE_TCS:
1043 		return "MULTIPLE_TCS";
1044 	case ICE_STATE_DO_FW_DEBUG_DUMP:
1045 		return "DO_FW_DEBUG_DUMP";
1046 	case ICE_STATE_LAST:
1047 		return NULL;
1048 	}
1049 
1050 	return NULL;
1051 }
1052 
1053 /**
1054  * ice_fw_module_str - Convert a FW logging module to a string name
1055  * @module: the module to convert
1056  *
1057  * Given a FW logging module id, convert it to a shorthand human readable
1058  * name, for generating sysctl tunables.
1059  */
1060 const char *
1061 ice_fw_module_str(enum ice_aqc_fw_logging_mod module)
1062 {
1063 	switch (module) {
1064 	case ICE_AQC_FW_LOG_ID_GENERAL:
1065 		return "general";
1066 	case ICE_AQC_FW_LOG_ID_CTRL:
1067 		return "ctrl";
1068 	case ICE_AQC_FW_LOG_ID_LINK:
1069 		return "link";
1070 	case ICE_AQC_FW_LOG_ID_LINK_TOPO:
1071 		return "link_topo";
1072 	case ICE_AQC_FW_LOG_ID_DNL:
1073 		return "dnl";
1074 	case ICE_AQC_FW_LOG_ID_I2C:
1075 		return "i2c";
1076 	case ICE_AQC_FW_LOG_ID_SDP:
1077 		return "sdp";
1078 	case ICE_AQC_FW_LOG_ID_MDIO:
1079 		return "mdio";
1080 	case ICE_AQC_FW_LOG_ID_ADMINQ:
1081 		return "adminq";
1082 	case ICE_AQC_FW_LOG_ID_HDMA:
1083 		return "hdma";
1084 	case ICE_AQC_FW_LOG_ID_LLDP:
1085 		return "lldp";
1086 	case ICE_AQC_FW_LOG_ID_DCBX:
1087 		return "dcbx";
1088 	case ICE_AQC_FW_LOG_ID_DCB:
1089 		return "dcb";
1090 	case ICE_AQC_FW_LOG_ID_XLR:
1091 		return "xlr";
1092 	case ICE_AQC_FW_LOG_ID_NVM:
1093 		return "nvm";
1094 	case ICE_AQC_FW_LOG_ID_AUTH:
1095 		return "auth";
1096 	case ICE_AQC_FW_LOG_ID_VPD:
1097 		return "vpd";
1098 	case ICE_AQC_FW_LOG_ID_IOSF:
1099 		return "iosf";
1100 	case ICE_AQC_FW_LOG_ID_PARSER:
1101 		return "parser";
1102 	case ICE_AQC_FW_LOG_ID_SW:
1103 		return "sw";
1104 	case ICE_AQC_FW_LOG_ID_SCHEDULER:
1105 		return "scheduler";
1106 	case ICE_AQC_FW_LOG_ID_TXQ:
1107 		return "txq";
1108 	case ICE_AQC_FW_LOG_ID_RSVD:
1109 		return "acl";
1110 	case ICE_AQC_FW_LOG_ID_POST:
1111 		return "post";
1112 	case ICE_AQC_FW_LOG_ID_WATCHDOG:
1113 		return "watchdog";
1114 	case ICE_AQC_FW_LOG_ID_TASK_DISPATCH:
1115 		return "task_dispatch";
1116 	case ICE_AQC_FW_LOG_ID_MNG:
1117 		return "mng";
1118 	case ICE_AQC_FW_LOG_ID_SYNCE:
1119 		return "synce";
1120 	case ICE_AQC_FW_LOG_ID_HEALTH:
1121 		return "health";
1122 	case ICE_AQC_FW_LOG_ID_TSDRV:
1123 		return "tsdrv";
1124 	case ICE_AQC_FW_LOG_ID_PFREG:
1125 		return "pfreg";
1126 	case ICE_AQC_FW_LOG_ID_MDLVER:
1127 		return "mdlver";
1128 	case ICE_AQC_FW_LOG_ID_MAX:
1129 		return "unknown";
1130 	}
1131 
1132 	/* The compiler generates errors on unhandled enum values if we omit
1133 	 * the default case.
1134 	 */
1135 	return "unknown";
1136 }
1137 
1138 /**
1139  * ice_fw_lldp_status - Convert FW LLDP status to a string
1140  * @lldp_status: firmware LLDP status value to convert
1141  *
1142  * Given the FW LLDP status, convert it to a human readable string.
1143  */
1144 struct ice_str_buf
1145 _ice_fw_lldp_status(u32 lldp_status)
1146 {
1147 	struct ice_str_buf buf = { .str = "" };
1148 	const char *str = NULL;
1149 
1150 	switch (lldp_status)
1151 	{
1152 	case ICE_LLDP_ADMINSTATUS_DIS:
1153 		str = "DISABLED";
1154 		break;
1155 	case ICE_LLDP_ADMINSTATUS_ENA_RX:
1156 		str = "ENA_RX";
1157 		break;
1158 	case ICE_LLDP_ADMINSTATUS_ENA_TX:
1159 		str = "ENA_TX";
1160 		break;
1161 	case ICE_LLDP_ADMINSTATUS_ENA_RXTX:
1162 		str = "ENA_RXTX";
1163 		break;
1164 	case 0xF:
1165 		str = "NVM_DEFAULT";
1166 		break;
1167 	}
1168 
1169 	if (str)
1170 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
1171 	else
1172 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown LLDP status %u", lldp_status);
1173 
1174 	return buf;
1175 }
1176