xref: /freebsd/sys/dev/ice/ice_strings.c (revision f377a0c7dfa97035844e58c2aec810001bebce17)
171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2015f8cc5SEric Joyner /*  Copyright (c) 2024, Intel Corporation
371d10453SEric Joyner  *  All rights reserved.
471d10453SEric Joyner  *
571d10453SEric Joyner  *  Redistribution and use in source and binary forms, with or without
671d10453SEric Joyner  *  modification, are permitted provided that the following conditions are met:
771d10453SEric Joyner  *
871d10453SEric Joyner  *   1. Redistributions of source code must retain the above copyright notice,
971d10453SEric Joyner  *      this list of conditions and the following disclaimer.
1071d10453SEric Joyner  *
1171d10453SEric Joyner  *   2. Redistributions in binary form must reproduce the above copyright
1271d10453SEric Joyner  *      notice, this list of conditions and the following disclaimer in the
1371d10453SEric Joyner  *      documentation and/or other materials provided with the distribution.
1471d10453SEric Joyner  *
1571d10453SEric Joyner  *   3. Neither the name of the Intel Corporation nor the names of its
1671d10453SEric Joyner  *      contributors may be used to endorse or promote products derived from
1771d10453SEric Joyner  *      this software without specific prior written permission.
1871d10453SEric Joyner  *
1971d10453SEric Joyner  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2071d10453SEric Joyner  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171d10453SEric Joyner  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2271d10453SEric Joyner  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2371d10453SEric Joyner  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471d10453SEric Joyner  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571d10453SEric Joyner  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671d10453SEric Joyner  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771d10453SEric Joyner  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871d10453SEric Joyner  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971d10453SEric Joyner  *  POSSIBILITY OF SUCH DAMAGE.
3071d10453SEric Joyner  */
3171d10453SEric Joyner 
3271d10453SEric Joyner /**
3371d10453SEric Joyner  * @file ice_strings.c
3471d10453SEric Joyner  * @brief functions to convert enumerated values to human readable strings
3571d10453SEric Joyner  *
3671d10453SEric Joyner  * Contains various functions which convert enumerated values into human
3771d10453SEric Joyner  * readable strings. Primarily this is used for error values, such as the
3871d10453SEric Joyner  * ice_status enum, the ice_aq_err values, or standard sys/errno.h values.
3971d10453SEric Joyner  *
4071d10453SEric Joyner  * Additionally, various other driver enumerations which are displayed via
4171d10453SEric Joyner  * sysctl have converter functions.
4271d10453SEric Joyner  *
4371d10453SEric Joyner  * Some of the functions return struct ice_str_buf, instead of a character
4471d10453SEric Joyner  * string pointer. This is a trick to allow the function to create a struct
4571d10453SEric Joyner  * with space to convert unknown numeric values into a string, and return the
4671d10453SEric Joyner  * contents via copying the struct memory back. The functions then have an
4771d10453SEric Joyner  * associated macro to access the string value immediately. This allows the
4871d10453SEric Joyner  * functions to return static strings for known values, and convert unknown
4971d10453SEric Joyner  * values into a numeric representation. It also does not require
5071d10453SEric Joyner  * pre-allocating storage at each callsite, or using a local static value
5171d10453SEric Joyner  * which wouldn't be re-entrant, and could collide if multiple threads call
5271d10453SEric Joyner  * the function. The extra copies are somewhat annoying, but generally the
5371d10453SEric Joyner  * error functions aren't expected to be in a hot path so this is an
5471d10453SEric Joyner  * acceptable trade off.
5571d10453SEric Joyner  */
5671d10453SEric Joyner 
5771d10453SEric Joyner #include "ice_lib.h"
5871d10453SEric Joyner 
5971d10453SEric Joyner /**
6071d10453SEric Joyner  * ice_aq_str - Convert an AdminQ error into a string
6171d10453SEric Joyner  * @aq_err: the AQ error code to convert
6271d10453SEric Joyner  *
6371d10453SEric Joyner  * Convert the AdminQ status into its string name, if known. Otherwise, format
6471d10453SEric Joyner  * the error as an integer.
6571d10453SEric Joyner  */
6671d10453SEric Joyner struct ice_str_buf
6771d10453SEric Joyner _ice_aq_str(enum ice_aq_err aq_err)
6871d10453SEric Joyner {
6971d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
7071d10453SEric Joyner 	const char *str = NULL;
7171d10453SEric Joyner 
7271d10453SEric Joyner 	switch (aq_err) {
7371d10453SEric Joyner 	case ICE_AQ_RC_OK:
7471d10453SEric Joyner 		str = "OK";
7571d10453SEric Joyner 		break;
7671d10453SEric Joyner 	case ICE_AQ_RC_EPERM:
7771d10453SEric Joyner 		str = "AQ_RC_EPERM";
7871d10453SEric Joyner 		break;
7971d10453SEric Joyner 	case ICE_AQ_RC_ENOENT:
8071d10453SEric Joyner 		str = "AQ_RC_ENOENT";
8171d10453SEric Joyner 		break;
8271d10453SEric Joyner 	case ICE_AQ_RC_ESRCH:
8371d10453SEric Joyner 		str = "AQ_RC_ESRCH";
8471d10453SEric Joyner 		break;
8571d10453SEric Joyner 	case ICE_AQ_RC_EINTR:
8671d10453SEric Joyner 		str = "AQ_RC_EINTR";
8771d10453SEric Joyner 		break;
8871d10453SEric Joyner 	case ICE_AQ_RC_EIO:
8971d10453SEric Joyner 		str = "AQ_RC_EIO";
9071d10453SEric Joyner 		break;
9171d10453SEric Joyner 	case ICE_AQ_RC_ENXIO:
9271d10453SEric Joyner 		str = "AQ_RC_ENXIO";
9371d10453SEric Joyner 		break;
9471d10453SEric Joyner 	case ICE_AQ_RC_E2BIG:
9571d10453SEric Joyner 		str = "AQ_RC_E2BIG";
9671d10453SEric Joyner 		break;
9771d10453SEric Joyner 	case ICE_AQ_RC_EAGAIN:
9871d10453SEric Joyner 		str = "AQ_RC_EAGAIN";
9971d10453SEric Joyner 		break;
10071d10453SEric Joyner 	case ICE_AQ_RC_ENOMEM:
10171d10453SEric Joyner 		str = "AQ_RC_ENOMEM";
10271d10453SEric Joyner 		break;
10371d10453SEric Joyner 	case ICE_AQ_RC_EACCES:
10471d10453SEric Joyner 		str = "AQ_RC_EACCES";
10571d10453SEric Joyner 		break;
10671d10453SEric Joyner 	case ICE_AQ_RC_EFAULT:
10771d10453SEric Joyner 		str = "AQ_RC_EFAULT";
10871d10453SEric Joyner 		break;
10971d10453SEric Joyner 	case ICE_AQ_RC_EBUSY:
11071d10453SEric Joyner 		str = "AQ_RC_EBUSY";
11171d10453SEric Joyner 		break;
11271d10453SEric Joyner 	case ICE_AQ_RC_EEXIST:
11371d10453SEric Joyner 		str = "AQ_RC_EEXIST";
11471d10453SEric Joyner 		break;
11571d10453SEric Joyner 	case ICE_AQ_RC_EINVAL:
11671d10453SEric Joyner 		str = "AQ_RC_EINVAL";
11771d10453SEric Joyner 		break;
11871d10453SEric Joyner 	case ICE_AQ_RC_ENOTTY:
11971d10453SEric Joyner 		str = "AQ_RC_ENOTTY";
12071d10453SEric Joyner 		break;
12171d10453SEric Joyner 	case ICE_AQ_RC_ENOSPC:
12271d10453SEric Joyner 		str = "AQ_RC_ENOSPC";
12371d10453SEric Joyner 		break;
12471d10453SEric Joyner 	case ICE_AQ_RC_ENOSYS:
12571d10453SEric Joyner 		str = "AQ_RC_ENOSYS";
12671d10453SEric Joyner 		break;
12771d10453SEric Joyner 	case ICE_AQ_RC_ERANGE:
12871d10453SEric Joyner 		str = "AQ_RC_ERANGE";
12971d10453SEric Joyner 		break;
13071d10453SEric Joyner 	case ICE_AQ_RC_EFLUSHED:
13171d10453SEric Joyner 		str = "AQ_RC_EFLUSHED";
13271d10453SEric Joyner 		break;
13371d10453SEric Joyner 	case ICE_AQ_RC_BAD_ADDR:
13471d10453SEric Joyner 		str = "AQ_RC_BAD_ADDR";
13571d10453SEric Joyner 		break;
13671d10453SEric Joyner 	case ICE_AQ_RC_EMODE:
13771d10453SEric Joyner 		str = "AQ_RC_EMODE";
13871d10453SEric Joyner 		break;
13971d10453SEric Joyner 	case ICE_AQ_RC_EFBIG:
14071d10453SEric Joyner 		str = "AQ_RC_EFBIG";
14171d10453SEric Joyner 		break;
14271d10453SEric Joyner 	case ICE_AQ_RC_ESBCOMP:
14371d10453SEric Joyner 		str = "AQ_RC_ESBCOMP";
14471d10453SEric Joyner 		break;
14571d10453SEric Joyner 	case ICE_AQ_RC_ENOSEC:
14671d10453SEric Joyner 		str = "AQ_RC_ENOSEC";
14771d10453SEric Joyner 		break;
14871d10453SEric Joyner 	case ICE_AQ_RC_EBADSIG:
14971d10453SEric Joyner 		str = "AQ_RC_EBADSIG";
15071d10453SEric Joyner 		break;
15171d10453SEric Joyner 	case ICE_AQ_RC_ESVN:
15271d10453SEric Joyner 		str = "AQ_RC_ESVN";
15371d10453SEric Joyner 		break;
15471d10453SEric Joyner 	case ICE_AQ_RC_EBADMAN:
15571d10453SEric Joyner 		str = "AQ_RC_EBADMAN";
15671d10453SEric Joyner 		break;
15771d10453SEric Joyner 	case ICE_AQ_RC_EBADBUF:
15871d10453SEric Joyner 		str = "AQ_RC_EBADBUF";
15971d10453SEric Joyner 		break;
16071d10453SEric Joyner 	case ICE_AQ_RC_EACCES_BMCU:
16171d10453SEric Joyner 		str = "AQ_RC_EACCES_BMCU";
16271d10453SEric Joyner 		break;
16371d10453SEric Joyner 	}
16471d10453SEric Joyner 
16571d10453SEric Joyner 	if (str)
16671d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
16771d10453SEric Joyner 	else
16871d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%d", aq_err);
16971d10453SEric Joyner 
17071d10453SEric Joyner 	return buf;
17171d10453SEric Joyner }
17271d10453SEric Joyner 
17371d10453SEric Joyner /**
17471d10453SEric Joyner  * ice_status_str - convert status err code to a string
17571d10453SEric Joyner  * @status: the status error code to convert
17671d10453SEric Joyner  *
17771d10453SEric Joyner  * Convert the status code into its string name if known.
17871d10453SEric Joyner  *
17971d10453SEric Joyner  * Otherwise, use the scratch space to format the status code into a number.
18071d10453SEric Joyner  */
18171d10453SEric Joyner struct ice_str_buf
182f2635e84SEric Joyner _ice_status_str(int status)
18371d10453SEric Joyner {
18471d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
18571d10453SEric Joyner 	const char *str = NULL;
18671d10453SEric Joyner 
18771d10453SEric Joyner 	switch (status) {
188f2635e84SEric Joyner 	case 0:
18971d10453SEric Joyner 		str = "OK";
19071d10453SEric Joyner 		break;
19171d10453SEric Joyner 	case ICE_ERR_PARAM:
19271d10453SEric Joyner 		str = "ICE_ERR_PARAM";
19371d10453SEric Joyner 		break;
19471d10453SEric Joyner 	case ICE_ERR_NOT_IMPL:
19571d10453SEric Joyner 		str = "ICE_ERR_NOT_IMPL";
19671d10453SEric Joyner 		break;
19771d10453SEric Joyner 	case ICE_ERR_NOT_READY:
19871d10453SEric Joyner 		str = "ICE_ERR_NOT_READY";
19971d10453SEric Joyner 		break;
20071d10453SEric Joyner 	case ICE_ERR_NOT_SUPPORTED:
20171d10453SEric Joyner 		str = "ICE_ERR_NOT_SUPPORTED";
20271d10453SEric Joyner 		break;
20371d10453SEric Joyner 	case ICE_ERR_BAD_PTR:
20471d10453SEric Joyner 		str = "ICE_ERR_BAD_PTR";
20571d10453SEric Joyner 		break;
20671d10453SEric Joyner 	case ICE_ERR_INVAL_SIZE:
20771d10453SEric Joyner 		str = "ICE_ERR_INVAL_SIZE";
20871d10453SEric Joyner 		break;
20971d10453SEric Joyner 	case ICE_ERR_DEVICE_NOT_SUPPORTED:
21071d10453SEric Joyner 		str = "ICE_ERR_DEVICE_NOT_SUPPORTED";
21171d10453SEric Joyner 		break;
21271d10453SEric Joyner 	case ICE_ERR_RESET_FAILED:
21371d10453SEric Joyner 		str = "ICE_ERR_RESET_FAILED";
21471d10453SEric Joyner 		break;
21571d10453SEric Joyner 	case ICE_ERR_FW_API_VER:
21671d10453SEric Joyner 		str = "ICE_ERR_FW_API_VER";
21771d10453SEric Joyner 		break;
21871d10453SEric Joyner 	case ICE_ERR_NO_MEMORY:
21971d10453SEric Joyner 		str = "ICE_ERR_NO_MEMORY";
22071d10453SEric Joyner 		break;
22171d10453SEric Joyner 	case ICE_ERR_CFG:
22271d10453SEric Joyner 		str = "ICE_ERR_CFG";
22371d10453SEric Joyner 		break;
22471d10453SEric Joyner 	case ICE_ERR_OUT_OF_RANGE:
22571d10453SEric Joyner 		str = "ICE_ERR_OUT_OF_RANGE";
22671d10453SEric Joyner 		break;
22771d10453SEric Joyner 	case ICE_ERR_ALREADY_EXISTS:
22871d10453SEric Joyner 		str = "ICE_ERR_ALREADY_EXISTS";
22971d10453SEric Joyner 		break;
23071d10453SEric Joyner 	case ICE_ERR_NVM:
23171d10453SEric Joyner 		str = "ICE_ERR_NVM";
23271d10453SEric Joyner 		break;
23371d10453SEric Joyner 	case ICE_ERR_NVM_CHECKSUM:
23471d10453SEric Joyner 		str = "ICE_ERR_NVM_CHECKSUM";
23571d10453SEric Joyner 		break;
23671d10453SEric Joyner 	case ICE_ERR_BUF_TOO_SHORT:
23771d10453SEric Joyner 		str = "ICE_ERR_BUF_TOO_SHORT";
23871d10453SEric Joyner 		break;
23971d10453SEric Joyner 	case ICE_ERR_NVM_BLANK_MODE:
24071d10453SEric Joyner 		str = "ICE_ERR_NVM_BLANK_MODE";
24171d10453SEric Joyner 		break;
24271d10453SEric Joyner 	case ICE_ERR_IN_USE:
24371d10453SEric Joyner 		str = "ICE_ERR_IN_USE";
24471d10453SEric Joyner 		break;
24571d10453SEric Joyner 	case ICE_ERR_MAX_LIMIT:
24671d10453SEric Joyner 		str = "ICE_ERR_MAX_LIMIT";
24771d10453SEric Joyner 		break;
24871d10453SEric Joyner 	case ICE_ERR_RESET_ONGOING:
24971d10453SEric Joyner 		str = "ICE_ERR_RESET_ONGOING";
25071d10453SEric Joyner 		break;
25171d10453SEric Joyner 	case ICE_ERR_HW_TABLE:
25271d10453SEric Joyner 		str = "ICE_ERR_HW_TABLE";
25371d10453SEric Joyner 		break;
2547d7af7f8SEric Joyner 	case ICE_ERR_FW_DDP_MISMATCH:
2557d7af7f8SEric Joyner 		str = "ICE_ERR_FW_DDP_MISMATCH";
2567d7af7f8SEric Joyner 		break;
25771d10453SEric Joyner 	case ICE_ERR_DOES_NOT_EXIST:
25871d10453SEric Joyner 		str = "ICE_ERR_DOES_NOT_EXIST";
25971d10453SEric Joyner 		break;
26071d10453SEric Joyner 	case ICE_ERR_AQ_ERROR:
26171d10453SEric Joyner 		str = "ICE_ERR_AQ_ERROR";
26271d10453SEric Joyner 		break;
26371d10453SEric Joyner 	case ICE_ERR_AQ_TIMEOUT:
26471d10453SEric Joyner 		str = "ICE_ERR_AQ_TIMEOUT";
26571d10453SEric Joyner 		break;
26671d10453SEric Joyner 	case ICE_ERR_AQ_FULL:
26771d10453SEric Joyner 		str = "ICE_ERR_AQ_FULL";
26871d10453SEric Joyner 		break;
26971d10453SEric Joyner 	case ICE_ERR_AQ_NO_WORK:
27071d10453SEric Joyner 		str = "ICE_ERR_AQ_NO_WORK";
27171d10453SEric Joyner 		break;
27271d10453SEric Joyner 	case ICE_ERR_AQ_EMPTY:
27371d10453SEric Joyner 		str = "ICE_ERR_AQ_EMPTY";
27471d10453SEric Joyner 		break;
2757d7af7f8SEric Joyner 	case ICE_ERR_AQ_FW_CRITICAL:
2767d7af7f8SEric Joyner 		str = "ICE_ERR_AQ_FW_CRITICAL";
27771d10453SEric Joyner 		break;
27871d10453SEric Joyner 	}
27971d10453SEric Joyner 
28071d10453SEric Joyner 	if (str)
28171d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
28271d10453SEric Joyner 	else
28371d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%d", status);
28471d10453SEric Joyner 
28571d10453SEric Joyner 	return buf;
28671d10453SEric Joyner }
28771d10453SEric Joyner 
28871d10453SEric Joyner /**
28971d10453SEric Joyner  * ice_err_str - convert error code to a string
29071d10453SEric Joyner  * @err: the error code to convert
29171d10453SEric Joyner  *
29271d10453SEric Joyner  * Convert an error code into its string/macro name if known. Note, it doesn't
29371d10453SEric Joyner  * handle negated errors.
29471d10453SEric Joyner  *
29571d10453SEric Joyner  * Otherwise, use the scratch space to format the error into a number.
29671d10453SEric Joyner  */
29771d10453SEric Joyner struct ice_str_buf
29871d10453SEric Joyner _ice_err_str(int err)
29971d10453SEric Joyner {
30071d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
30171d10453SEric Joyner 	const char *str = NULL;
30271d10453SEric Joyner 
30371d10453SEric Joyner 	switch (err) {
30471d10453SEric Joyner 	case 0:
30571d10453SEric Joyner 		str = "OK";
30671d10453SEric Joyner 		break;
30771d10453SEric Joyner 	case EPERM:
30871d10453SEric Joyner 		str = "EPERM";
30971d10453SEric Joyner 		break;
31071d10453SEric Joyner 	case ENOENT:
31171d10453SEric Joyner 		str = "ENOENT";
31271d10453SEric Joyner 		break;
31371d10453SEric Joyner 	case ESRCH:
31471d10453SEric Joyner 		str = "ESRCH";
31571d10453SEric Joyner 		break;
31671d10453SEric Joyner 	case EINTR:
31771d10453SEric Joyner 		str = "EINTR";
31871d10453SEric Joyner 		break;
31971d10453SEric Joyner 	case EIO:
32071d10453SEric Joyner 		str = "EIO";
32171d10453SEric Joyner 		break;
32271d10453SEric Joyner 	case ENXIO:
32371d10453SEric Joyner 		str = "ENXIO";
32471d10453SEric Joyner 		break;
32571d10453SEric Joyner 	case E2BIG:
32671d10453SEric Joyner 		str = "E2BIG";
32771d10453SEric Joyner 		break;
32871d10453SEric Joyner 	case ENOEXEC:
32971d10453SEric Joyner 		str = "ENOEXEC";
33071d10453SEric Joyner 		break;
33171d10453SEric Joyner 	case EBADF:
33271d10453SEric Joyner 		str = "EBADF";
33371d10453SEric Joyner 		break;
33471d10453SEric Joyner 	case ECHILD:
33571d10453SEric Joyner 		str = "ECHILD";
33671d10453SEric Joyner 		break;
33771d10453SEric Joyner 	case EDEADLK:
33871d10453SEric Joyner 		str = "EDEADLK";
33971d10453SEric Joyner 		break;
34071d10453SEric Joyner 	case ENOMEM:
34171d10453SEric Joyner 		str = "ENOMEM";
34271d10453SEric Joyner 		break;
34371d10453SEric Joyner 	case EACCES:
34471d10453SEric Joyner 		str = "EACCES";
34571d10453SEric Joyner 		break;
34671d10453SEric Joyner 	case EFAULT:
34771d10453SEric Joyner 		str = "EFAULT";
34871d10453SEric Joyner 		break;
34971d10453SEric Joyner 	case ENOTBLK:
35071d10453SEric Joyner 		str = "ENOTBLK";
35171d10453SEric Joyner 		break;
35271d10453SEric Joyner 	case EBUSY:
35371d10453SEric Joyner 		str = "EBUSY";
35471d10453SEric Joyner 		break;
35571d10453SEric Joyner 	case EEXIST:
35671d10453SEric Joyner 		str = "EEXIST";
35771d10453SEric Joyner 		break;
35871d10453SEric Joyner 	case EXDEV:
35971d10453SEric Joyner 		str = "EXDEV";
36071d10453SEric Joyner 		break;
36171d10453SEric Joyner 	case ENODEV:
36271d10453SEric Joyner 		str = "ENODEV";
36371d10453SEric Joyner 		break;
36471d10453SEric Joyner 	case ENOTDIR:
36571d10453SEric Joyner 		str = "ENOTDIR";
36671d10453SEric Joyner 		break;
36771d10453SEric Joyner 	case EISDIR:
36871d10453SEric Joyner 		str = "EISDIR";
36971d10453SEric Joyner 		break;
37071d10453SEric Joyner 	case EINVAL:
37171d10453SEric Joyner 		str = "EINVAL";
37271d10453SEric Joyner 		break;
37371d10453SEric Joyner 	case ENFILE:
37471d10453SEric Joyner 		str = "ENFILE";
37571d10453SEric Joyner 		break;
37671d10453SEric Joyner 	case EMFILE:
37771d10453SEric Joyner 		str = "EMFILE";
37871d10453SEric Joyner 		break;
37971d10453SEric Joyner 	case ENOTTY:
38071d10453SEric Joyner 		str = "ENOTTY";
38171d10453SEric Joyner 		break;
38271d10453SEric Joyner 	case ETXTBSY:
38371d10453SEric Joyner 		str = "ETXTBSY";
38471d10453SEric Joyner 		break;
38571d10453SEric Joyner 	case EFBIG:
38671d10453SEric Joyner 		str = "EFBIG";
38771d10453SEric Joyner 		break;
38871d10453SEric Joyner 	case ENOSPC:
38971d10453SEric Joyner 		str = "ENOSPC";
39071d10453SEric Joyner 		break;
39171d10453SEric Joyner 	case ESPIPE:
39271d10453SEric Joyner 		str = "ESPIPE";
39371d10453SEric Joyner 		break;
39471d10453SEric Joyner 	case EROFS:
39571d10453SEric Joyner 		str = "EROFS";
39671d10453SEric Joyner 		break;
39771d10453SEric Joyner 	case EMLINK:
39871d10453SEric Joyner 		str = "EMLINK";
39971d10453SEric Joyner 		break;
40071d10453SEric Joyner 	case EPIPE:
40171d10453SEric Joyner 		str = "EPIPE";
40271d10453SEric Joyner 		break;
40371d10453SEric Joyner 	case EDOM:
40471d10453SEric Joyner 		str = "EDOM";
40571d10453SEric Joyner 		break;
40671d10453SEric Joyner 	case ERANGE:
40771d10453SEric Joyner 		str = "ERANGE";
40871d10453SEric Joyner 		break;
40971d10453SEric Joyner 	case EAGAIN:
41071d10453SEric Joyner 		/* EWOULDBLOCK */
41171d10453SEric Joyner 		str = "EAGAIN";
41271d10453SEric Joyner 		break;
41371d10453SEric Joyner 	case EINPROGRESS:
41471d10453SEric Joyner 		str = "EINPROGRESS";
41571d10453SEric Joyner 		break;
41671d10453SEric Joyner 	case EALREADY:
41771d10453SEric Joyner 		str = "EALREADY";
41871d10453SEric Joyner 		break;
41971d10453SEric Joyner 	case ENOTSOCK:
42071d10453SEric Joyner 		str = "ENOTSOCK";
42171d10453SEric Joyner 		break;
42271d10453SEric Joyner 	case EDESTADDRREQ:
42371d10453SEric Joyner 		str = "EDESTADDRREQ";
42471d10453SEric Joyner 		break;
42571d10453SEric Joyner 	case EMSGSIZE:
42671d10453SEric Joyner 		str = "EMSGSIZE";
42771d10453SEric Joyner 		break;
42871d10453SEric Joyner 	case EPROTOTYPE:
42971d10453SEric Joyner 		str = "EPROTOTYPE";
43071d10453SEric Joyner 		break;
43171d10453SEric Joyner 	case ENOPROTOOPT:
43271d10453SEric Joyner 		str = "ENOPROTOOPT";
43371d10453SEric Joyner 		break;
43471d10453SEric Joyner 	case EPROTONOSUPPORT:
43571d10453SEric Joyner 		str = "EPROTONOSUPPORT";
43671d10453SEric Joyner 		break;
43771d10453SEric Joyner 	case ESOCKTNOSUPPORT:
43871d10453SEric Joyner 		str = "ESOCKTNOSUPPORT";
43971d10453SEric Joyner 		break;
44071d10453SEric Joyner 	case EOPNOTSUPP:
44171d10453SEric Joyner 		str = "EOPNOTSUPP";
44271d10453SEric Joyner 		break;
44371d10453SEric Joyner 	case EPFNOSUPPORT:
44471d10453SEric Joyner 		/* ENOTSUP */
44571d10453SEric Joyner 		str = "EPFNOSUPPORT";
44671d10453SEric Joyner 		break;
44771d10453SEric Joyner 	case EAFNOSUPPORT:
44871d10453SEric Joyner 		str = "EAFNOSUPPORT";
44971d10453SEric Joyner 		break;
45071d10453SEric Joyner 	case EADDRINUSE:
45171d10453SEric Joyner 		str = "EADDRINUSE";
45271d10453SEric Joyner 		break;
45371d10453SEric Joyner 	case EADDRNOTAVAIL:
45471d10453SEric Joyner 		str = "EADDRNOTAVAIL";
45571d10453SEric Joyner 		break;
45671d10453SEric Joyner 	case ENETDOWN:
45771d10453SEric Joyner 		str = "ENETDOWN";
45871d10453SEric Joyner 		break;
45971d10453SEric Joyner 	case ENETUNREACH:
46071d10453SEric Joyner 		str = "ENETUNREACH";
46171d10453SEric Joyner 		break;
46271d10453SEric Joyner 	case ENETRESET:
46371d10453SEric Joyner 		str = "ENETRESET";
46471d10453SEric Joyner 		break;
46571d10453SEric Joyner 	case ECONNABORTED:
46671d10453SEric Joyner 		str = "ECONNABORTED";
46771d10453SEric Joyner 		break;
46871d10453SEric Joyner 	case ECONNRESET:
46971d10453SEric Joyner 		str = "ECONNRESET";
47071d10453SEric Joyner 		break;
47171d10453SEric Joyner 	case ENOBUFS:
47271d10453SEric Joyner 		str = "ENOBUFS";
47371d10453SEric Joyner 		break;
47471d10453SEric Joyner 	case EISCONN:
47571d10453SEric Joyner 		str = "EISCONN";
47671d10453SEric Joyner 		break;
47771d10453SEric Joyner 	case ENOTCONN:
47871d10453SEric Joyner 		str = "ENOTCONN";
47971d10453SEric Joyner 		break;
48071d10453SEric Joyner 	case ESHUTDOWN:
48171d10453SEric Joyner 		str = "ESHUTDOWN";
48271d10453SEric Joyner 		break;
48371d10453SEric Joyner 	case ETOOMANYREFS:
48471d10453SEric Joyner 		str = "ETOOMANYREFS";
48571d10453SEric Joyner 		break;
48671d10453SEric Joyner 	case ETIMEDOUT:
48771d10453SEric Joyner 		str = "ETIMEDOUT";
48871d10453SEric Joyner 		break;
48971d10453SEric Joyner 	case ECONNREFUSED:
49071d10453SEric Joyner 		str = "ECONNREFUSED";
49171d10453SEric Joyner 		break;
49271d10453SEric Joyner 	case ELOOP:
49371d10453SEric Joyner 		str = "ELOOP";
49471d10453SEric Joyner 		break;
49571d10453SEric Joyner 	case ENAMETOOLONG:
49671d10453SEric Joyner 		str = "ENAMETOOLONG";
49771d10453SEric Joyner 		break;
49871d10453SEric Joyner 	case EHOSTDOWN:
49971d10453SEric Joyner 		str = "EHOSTDOWN";
50071d10453SEric Joyner 		break;
50171d10453SEric Joyner 	case EHOSTUNREACH:
50271d10453SEric Joyner 		str = "EHOSTUNREACH";
50371d10453SEric Joyner 		break;
50471d10453SEric Joyner 	case ENOTEMPTY:
50571d10453SEric Joyner 		str = "ENOTEMPTY";
50671d10453SEric Joyner 		break;
50771d10453SEric Joyner 	case EPROCLIM:
50871d10453SEric Joyner 		str = "EPROCLIM";
50971d10453SEric Joyner 		break;
51071d10453SEric Joyner 	case EUSERS:
51171d10453SEric Joyner 		str = "EUSERS";
51271d10453SEric Joyner 		break;
51371d10453SEric Joyner 	case EDQUOT:
51471d10453SEric Joyner 		str = "EDQUOT";
51571d10453SEric Joyner 		break;
51671d10453SEric Joyner 	case ESTALE:
51771d10453SEric Joyner 		str = "ESTALE";
51871d10453SEric Joyner 		break;
51971d10453SEric Joyner 	case EREMOTE:
52071d10453SEric Joyner 		str = "EREMOTE";
52171d10453SEric Joyner 		break;
52271d10453SEric Joyner 	case EBADRPC:
52371d10453SEric Joyner 		str = "EBADRPC";
52471d10453SEric Joyner 		break;
52571d10453SEric Joyner 	case ERPCMISMATCH:
52671d10453SEric Joyner 		str = "ERPCMISMATCH";
52771d10453SEric Joyner 		break;
52871d10453SEric Joyner 	case EPROGUNAVAIL:
52971d10453SEric Joyner 		str = "EPROGUNAVAIL";
53071d10453SEric Joyner 		break;
53171d10453SEric Joyner 	case EPROGMISMATCH:
53271d10453SEric Joyner 		str = "EPROGMISMATCH";
53371d10453SEric Joyner 		break;
53471d10453SEric Joyner 	case EPROCUNAVAIL:
53571d10453SEric Joyner 		str = "EPROCUNAVAIL";
53671d10453SEric Joyner 		break;
53771d10453SEric Joyner 	case ENOLCK:
53871d10453SEric Joyner 		str = "ENOLCK";
53971d10453SEric Joyner 		break;
54071d10453SEric Joyner 	case ENOSYS:
54171d10453SEric Joyner 		str = "ENOSYS";
54271d10453SEric Joyner 		break;
54371d10453SEric Joyner 	case EFTYPE:
54471d10453SEric Joyner 		str = "EFTYPE";
54571d10453SEric Joyner 		break;
54671d10453SEric Joyner 	case EAUTH:
54771d10453SEric Joyner 		str = "EAUTH";
54871d10453SEric Joyner 		break;
54971d10453SEric Joyner 	case ENEEDAUTH:
55071d10453SEric Joyner 		str = "ENEEDAUTH";
55171d10453SEric Joyner 		break;
55271d10453SEric Joyner 	case EIDRM:
55371d10453SEric Joyner 		str = "EIDRM";
55471d10453SEric Joyner 		break;
55571d10453SEric Joyner 	case ENOMSG:
55671d10453SEric Joyner 		str = "ENOMSG";
55771d10453SEric Joyner 		break;
55871d10453SEric Joyner 	case EOVERFLOW:
55971d10453SEric Joyner 		str = "EOVERFLOW";
56071d10453SEric Joyner 		break;
56171d10453SEric Joyner 	case ECANCELED:
56271d10453SEric Joyner 		str = "ECANCELED";
56371d10453SEric Joyner 		break;
56471d10453SEric Joyner 	case EILSEQ:
56571d10453SEric Joyner 		str = "EILSEQ";
56671d10453SEric Joyner 		break;
56771d10453SEric Joyner 	case ENOATTR:
56871d10453SEric Joyner 		str = "ENOATTR";
56971d10453SEric Joyner 		break;
57071d10453SEric Joyner 	case EDOOFUS:
57171d10453SEric Joyner 		str = "EDOOFUS";
57271d10453SEric Joyner 		break;
57371d10453SEric Joyner 	case EBADMSG:
57471d10453SEric Joyner 		str = "EBADMSG";
57571d10453SEric Joyner 		break;
57671d10453SEric Joyner 	case EMULTIHOP:
57771d10453SEric Joyner 		str = "EMULTIHOP";
57871d10453SEric Joyner 		break;
57971d10453SEric Joyner 	case ENOLINK:
58071d10453SEric Joyner 		str = "ENOLINK";
58171d10453SEric Joyner 		break;
58271d10453SEric Joyner 	case EPROTO:
58371d10453SEric Joyner 		str = "EPROTO";
58471d10453SEric Joyner 		break;
58571d10453SEric Joyner 	case ENOTCAPABLE:
58671d10453SEric Joyner 		str = "ENOTCAPABLE";
58771d10453SEric Joyner 		break;
58871d10453SEric Joyner 	case ECAPMODE:
58971d10453SEric Joyner 		str = "ECAPMODE";
59071d10453SEric Joyner 		break;
59171d10453SEric Joyner 	case ENOTRECOVERABLE:
59271d10453SEric Joyner 		str = "ENOTRECOVERABLE";
59371d10453SEric Joyner 		break;
59471d10453SEric Joyner 	case EOWNERDEAD:
59571d10453SEric Joyner 		str = "EOWNERDEAD";
59671d10453SEric Joyner 		break;
59771d10453SEric Joyner 	}
59871d10453SEric Joyner 
59971d10453SEric Joyner 	if (str)
60071d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
60171d10453SEric Joyner 	else
60271d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%d", err);
60371d10453SEric Joyner 
60471d10453SEric Joyner 	return buf;
60571d10453SEric Joyner }
60671d10453SEric Joyner 
60771d10453SEric Joyner /**
60871d10453SEric Joyner  * ice_fec_str - convert fec mode enum to a string
60971d10453SEric Joyner  * @mode: the enum value to convert
61071d10453SEric Joyner  *
61171d10453SEric Joyner  * Convert an FEC mode enum to a string for display in a sysctl or log message.
61271d10453SEric Joyner  * Returns "Unknown" if the mode is not one of currently known FEC modes.
61371d10453SEric Joyner  */
61471d10453SEric Joyner const char *
61571d10453SEric Joyner ice_fec_str(enum ice_fec_mode mode)
61671d10453SEric Joyner {
61771d10453SEric Joyner 	switch (mode) {
61871d10453SEric Joyner 	case ICE_FEC_AUTO:
61971d10453SEric Joyner 		return ICE_FEC_STRING_AUTO;
62071d10453SEric Joyner 	case ICE_FEC_RS:
62171d10453SEric Joyner 		return ICE_FEC_STRING_RS;
62271d10453SEric Joyner 	case ICE_FEC_BASER:
62371d10453SEric Joyner 		return ICE_FEC_STRING_BASER;
62471d10453SEric Joyner 	case ICE_FEC_NONE:
62571d10453SEric Joyner 		return ICE_FEC_STRING_NONE;
6268923de59SPiotr Kubaj 	case ICE_FEC_DIS_AUTO:
6278923de59SPiotr Kubaj 		return ICE_FEC_STRING_DIS_AUTO;
62871d10453SEric Joyner 	}
62971d10453SEric Joyner 
63071d10453SEric Joyner 	/* The compiler generates errors on unhandled enum values if we omit
63171d10453SEric Joyner 	 * the default case.
63271d10453SEric Joyner 	 */
63371d10453SEric Joyner 	return "Unknown";
63471d10453SEric Joyner }
63571d10453SEric Joyner 
63671d10453SEric Joyner /**
63771d10453SEric Joyner  * ice_fc_str - convert flow control mode enum to a string
63871d10453SEric Joyner  * @mode: the enum value to convert
63971d10453SEric Joyner  *
64071d10453SEric Joyner  * Convert a flow control mode enum to a string for display in a sysctl or log
64171d10453SEric Joyner  * message. Returns "Unknown" if the mode is not one of currently supported or
64271d10453SEric Joyner  * known flow control modes.
64371d10453SEric Joyner  */
64471d10453SEric Joyner const char *
64571d10453SEric Joyner ice_fc_str(enum ice_fc_mode mode)
64671d10453SEric Joyner {
64771d10453SEric Joyner 	switch (mode) {
64871d10453SEric Joyner 	case ICE_FC_FULL:
64971d10453SEric Joyner 		return ICE_FC_STRING_FULL;
65071d10453SEric Joyner 	case ICE_FC_TX_PAUSE:
65171d10453SEric Joyner 		return ICE_FC_STRING_TX;
65271d10453SEric Joyner 	case ICE_FC_RX_PAUSE:
65371d10453SEric Joyner 		return ICE_FC_STRING_RX;
65471d10453SEric Joyner 	case ICE_FC_NONE:
65571d10453SEric Joyner 		return ICE_FC_STRING_NONE;
65671d10453SEric Joyner 	case ICE_FC_AUTO:
65771d10453SEric Joyner 	case ICE_FC_PFC:
65871d10453SEric Joyner 	case ICE_FC_DFLT:
65971d10453SEric Joyner 		break;
66071d10453SEric Joyner 	}
66171d10453SEric Joyner 
66271d10453SEric Joyner 	/* The compiler generates errors on unhandled enum values if we omit
66371d10453SEric Joyner 	 * the default case.
66471d10453SEric Joyner 	 */
66571d10453SEric Joyner 	return "Unknown";
66671d10453SEric Joyner }
66771d10453SEric Joyner 
66871d10453SEric Joyner /**
66971d10453SEric Joyner  * ice_fltr_flag_str - Convert filter flags to a string
67071d10453SEric Joyner  * @flag: the filter flags to convert
67171d10453SEric Joyner  *
67271d10453SEric Joyner  * Convert the u16 flag value of a filter into a readable string for
67371d10453SEric Joyner  * outputting in a sysctl.
67471d10453SEric Joyner  */
67571d10453SEric Joyner struct ice_str_buf
67671d10453SEric Joyner _ice_fltr_flag_str(u16 flag)
67771d10453SEric Joyner {
67871d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
67971d10453SEric Joyner 	const char *str = NULL;
68071d10453SEric Joyner 
68171d10453SEric Joyner 	switch (flag) {
68271d10453SEric Joyner 	case ICE_FLTR_RX:
68371d10453SEric Joyner 		str = "RX";
68471d10453SEric Joyner 		break;
68571d10453SEric Joyner 	case ICE_FLTR_TX:
68671d10453SEric Joyner 		str = "TX";
68771d10453SEric Joyner 		break;
68871d10453SEric Joyner 	case ICE_FLTR_TX_RX:
68971d10453SEric Joyner 		str = "TX_RX";
69071d10453SEric Joyner 		break;
69171d10453SEric Joyner 	default:
69271d10453SEric Joyner 		break;
69371d10453SEric Joyner 	}
69471d10453SEric Joyner 
69571d10453SEric Joyner 	if (str)
69671d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
69771d10453SEric Joyner 	else
69871d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%u", flag);
69971d10453SEric Joyner 
70071d10453SEric Joyner 	return buf;
70171d10453SEric Joyner }
70271d10453SEric Joyner 
70371d10453SEric Joyner /**
70456429daeSEric Joyner  * ice_log_sev_str - Convert log level to a string
70556429daeSEric Joyner  * @log_level: the log level to convert
70656429daeSEric Joyner  *
70756429daeSEric Joyner  * Convert the u8 log level of a FW logging module into a readable
70856429daeSEric Joyner  * string for outputting in a sysctl.
70956429daeSEric Joyner  */
71056429daeSEric Joyner struct ice_str_buf
71156429daeSEric Joyner _ice_log_sev_str(u8 log_level)
71256429daeSEric Joyner {
71356429daeSEric Joyner 	struct ice_str_buf buf = { .str = "" };
71456429daeSEric Joyner 	const char *str = NULL;
71556429daeSEric Joyner 
71656429daeSEric Joyner 	switch (log_level) {
71756429daeSEric Joyner 	case ICE_FWLOG_LEVEL_NONE:
71856429daeSEric Joyner 		str = "none";
71956429daeSEric Joyner 		break;
72056429daeSEric Joyner 	case ICE_FWLOG_LEVEL_ERROR:
72156429daeSEric Joyner 		str = "error";
72256429daeSEric Joyner 		break;
72356429daeSEric Joyner 	case ICE_FWLOG_LEVEL_WARNING:
72456429daeSEric Joyner 		str = "warning";
72556429daeSEric Joyner 		break;
72656429daeSEric Joyner 	case ICE_FWLOG_LEVEL_NORMAL:
72756429daeSEric Joyner 		str = "normal";
72856429daeSEric Joyner 		break;
72956429daeSEric Joyner 	case ICE_FWLOG_LEVEL_VERBOSE:
73056429daeSEric Joyner 		str = "verbose";
73156429daeSEric Joyner 		break;
73256429daeSEric Joyner 	default:
73356429daeSEric Joyner 		break;
73456429daeSEric Joyner 	}
73556429daeSEric Joyner 
73656429daeSEric Joyner 	if (str)
73756429daeSEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
73856429daeSEric Joyner 	else
73956429daeSEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%u", log_level);
74056429daeSEric Joyner 
74156429daeSEric Joyner 	return buf;
74256429daeSEric Joyner }
74356429daeSEric Joyner 
74456429daeSEric Joyner /**
74571d10453SEric Joyner  * ice_fwd_act_str - convert filter action enum to a string
74671d10453SEric Joyner  * @action: the filter action to convert
74771d10453SEric Joyner  *
74871d10453SEric Joyner  * Convert an enum value of type enum ice_sw_fwd_act_type into a string, for
74971d10453SEric Joyner  * display in a sysctl filter list. Returns "UNKNOWN" for actions outside the
75071d10453SEric Joyner  * enumeration type.
75171d10453SEric Joyner  */
75271d10453SEric Joyner const char *
75371d10453SEric Joyner ice_fwd_act_str(enum ice_sw_fwd_act_type action)
75471d10453SEric Joyner {
75571d10453SEric Joyner 	switch (action) {
75671d10453SEric Joyner 	case ICE_FWD_TO_VSI:
75771d10453SEric Joyner 		return "FWD_TO_VSI";
75871d10453SEric Joyner 	case ICE_FWD_TO_VSI_LIST:
75971d10453SEric Joyner 		return "FWD_TO_VSI_LIST";
76071d10453SEric Joyner 	case ICE_FWD_TO_Q:
76171d10453SEric Joyner 		return "FWD_TO_Q";
76271d10453SEric Joyner 	case ICE_FWD_TO_QGRP:
76371d10453SEric Joyner 		return "FWD_TO_QGRP";
76471d10453SEric Joyner 	case ICE_DROP_PACKET:
76571d10453SEric Joyner 		return "DROP_PACKET";
7668923de59SPiotr Kubaj 	case ICE_LG_ACTION:
7678923de59SPiotr Kubaj 		return "LG_ACTION";
76871d10453SEric Joyner 	case ICE_INVAL_ACT:
76971d10453SEric Joyner 		return "INVAL_ACT";
77071d10453SEric Joyner 	}
77171d10453SEric Joyner 
77271d10453SEric Joyner 	/* The compiler generates errors on unhandled enum values if we omit
77371d10453SEric Joyner 	 * the default case.
77471d10453SEric Joyner 	 */
77571d10453SEric Joyner 	return "Unknown";
77671d10453SEric Joyner }
77771d10453SEric Joyner 
77871d10453SEric Joyner /**
77971d10453SEric Joyner  * ice_mdd_tx_tclan_str - Convert MDD Tx TCLAN event to a string
78071d10453SEric Joyner  * @event: the MDD event number to convert
78171d10453SEric Joyner  *
78271d10453SEric Joyner  * Convert the Tx TCLAN event value from the GL_MDET_TX_TCLAN register into
78371d10453SEric Joyner  * a human readable string for logging of MDD events.
78471d10453SEric Joyner  */
78571d10453SEric Joyner struct ice_str_buf
78671d10453SEric Joyner _ice_mdd_tx_tclan_str(u8 event)
78771d10453SEric Joyner {
78871d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
78971d10453SEric Joyner 	const char *str = NULL;
79071d10453SEric Joyner 
79171d10453SEric Joyner 	switch (event) {
79271d10453SEric Joyner 	case 0:
79371d10453SEric Joyner 		str = "Wrong descriptor format/order";
79471d10453SEric Joyner 		break;
79571d10453SEric Joyner 	case 1:
79671d10453SEric Joyner 		str = "Descriptor fetch failed";
79771d10453SEric Joyner 		break;
79871d10453SEric Joyner 	case 2:
79971d10453SEric Joyner 		str = "Tail descriptor not EOP/NOP";
80071d10453SEric Joyner 		break;
80171d10453SEric Joyner 	case 3:
80271d10453SEric Joyner 		str = "False scheduling error";
80371d10453SEric Joyner 		break;
80471d10453SEric Joyner 	case 4:
80571d10453SEric Joyner 		str = "Tail value larger than ring len";
80671d10453SEric Joyner 		break;
80771d10453SEric Joyner 	case 5:
80871d10453SEric Joyner 		str = "Too many data commands";
80971d10453SEric Joyner 		break;
81071d10453SEric Joyner 	case 6:
81171d10453SEric Joyner 		str = "Zero packets sent in quanta";
81271d10453SEric Joyner 		break;
81371d10453SEric Joyner 	case 7:
81471d10453SEric Joyner 		str = "Packet too small or too big";
81571d10453SEric Joyner 		break;
81671d10453SEric Joyner 	case 8:
81771d10453SEric Joyner 		str = "TSO length doesn't match sum";
81871d10453SEric Joyner 		break;
81971d10453SEric Joyner 	case 9:
82071d10453SEric Joyner 		str = "TSO tail reached before TLEN";
82171d10453SEric Joyner 		break;
82271d10453SEric Joyner 	case 10:
82371d10453SEric Joyner 		str = "TSO max 3 descs for headers";
82471d10453SEric Joyner 		break;
82571d10453SEric Joyner 	case 11:
82671d10453SEric Joyner 		str = "EOP on header descriptor";
82771d10453SEric Joyner 		break;
82871d10453SEric Joyner 	case 12:
82971d10453SEric Joyner 		str = "MSS is 0 or TLEN is 0";
83071d10453SEric Joyner 		break;
83171d10453SEric Joyner 	case 13:
83271d10453SEric Joyner 		str = "CTX desc invalid IPSec fields";
83371d10453SEric Joyner 		break;
83471d10453SEric Joyner 	case 14:
83571d10453SEric Joyner 		str = "Quanta invalid # of SSO packets";
83671d10453SEric Joyner 		break;
83771d10453SEric Joyner 	case 15:
83871d10453SEric Joyner 		str = "Quanta bytes exceeds pkt_len*64";
83971d10453SEric Joyner 		break;
84071d10453SEric Joyner 	case 16:
84171d10453SEric Joyner 		str = "Quanta exceeds max_cmds_in_sq";
84271d10453SEric Joyner 		break;
84371d10453SEric Joyner 	case 17:
84471d10453SEric Joyner 		str = "incoherent last_lso_quanta";
84571d10453SEric Joyner 		break;
84671d10453SEric Joyner 	case 18:
84771d10453SEric Joyner 		str = "incoherent TSO TLEN";
84871d10453SEric Joyner 		break;
84971d10453SEric Joyner 	case 19:
85071d10453SEric Joyner 		str = "Quanta: too many descriptors";
85171d10453SEric Joyner 		break;
85271d10453SEric Joyner 	case 20:
85371d10453SEric Joyner 		str = "Quanta: # of packets mismatch";
85471d10453SEric Joyner 		break;
85571d10453SEric Joyner 	default:
85671d10453SEric Joyner 		break;
85771d10453SEric Joyner 	}
85871d10453SEric Joyner 
85971d10453SEric Joyner 	if (str)
86071d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
86171d10453SEric Joyner 	else
86271d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx TCLAN event %u", event);
86371d10453SEric Joyner 
86471d10453SEric Joyner 	return buf;
86571d10453SEric Joyner }
86671d10453SEric Joyner 
86771d10453SEric Joyner /**
86871d10453SEric Joyner  * ice_mdd_tx_pqm_str - Convert MDD Tx PQM event to a string
86971d10453SEric Joyner  * @event: the MDD event number to convert
87071d10453SEric Joyner  *
87171d10453SEric Joyner  * Convert the Tx PQM event value from the GL_MDET_TX_PQM register into
87271d10453SEric Joyner  * a human readable string for logging of MDD events.
87371d10453SEric Joyner  */
87471d10453SEric Joyner struct ice_str_buf
87571d10453SEric Joyner _ice_mdd_tx_pqm_str(u8 event)
87671d10453SEric Joyner {
87771d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
87871d10453SEric Joyner 	const char *str = NULL;
87971d10453SEric Joyner 
88071d10453SEric Joyner 	switch (event) {
88171d10453SEric Joyner 	case 0:
88271d10453SEric Joyner 		str = "PCI_DUMMY_COMP";
88371d10453SEric Joyner 		break;
88471d10453SEric Joyner 	case 1:
88571d10453SEric Joyner 		str = "PCI_UR_COMP";
88671d10453SEric Joyner 		break;
88771d10453SEric Joyner 	/* Index 2 is unused */
88871d10453SEric Joyner 	case 3:
88971d10453SEric Joyner 		str = "RCV_SH_BE_LSO";
89071d10453SEric Joyner 		break;
89171d10453SEric Joyner 	case 4:
89271d10453SEric Joyner 		str = "Q_FL_MNG_EPY_CH";
89371d10453SEric Joyner 		break;
89471d10453SEric Joyner 	case 5:
89571d10453SEric Joyner 		str = "Q_EPY_MNG_FL_CH";
89671d10453SEric Joyner 		break;
89771d10453SEric Joyner 	case 6:
89871d10453SEric Joyner 		str = "LSO_NUMDESCS_ZERO";
89971d10453SEric Joyner 		break;
90071d10453SEric Joyner 	case 7:
90171d10453SEric Joyner 		str = "LSO_LENGTH_ZERO";
90271d10453SEric Joyner 		break;
90371d10453SEric Joyner 	case 8:
90471d10453SEric Joyner 		str = "LSO_MSS_BELOW_MIN";
90571d10453SEric Joyner 		break;
90671d10453SEric Joyner 	case 9:
90771d10453SEric Joyner 		str = "LSO_MSS_ABOVE_MAX";
90871d10453SEric Joyner 		break;
90971d10453SEric Joyner 	case 10:
91071d10453SEric Joyner 		str = "LSO_HDR_SIZE_ZERO";
91171d10453SEric Joyner 		break;
91271d10453SEric Joyner 	case 11:
91371d10453SEric Joyner 		str = "RCV_CNT_BE_LSO";
91471d10453SEric Joyner 		break;
91571d10453SEric Joyner 	case 12:
91671d10453SEric Joyner 		str = "SKIP_ONE_QT_ONLY";
91771d10453SEric Joyner 		break;
91871d10453SEric Joyner 	case 13:
91971d10453SEric Joyner 		str = "LSO_PKTCNT_ZERO";
92071d10453SEric Joyner 		break;
92171d10453SEric Joyner 	case 14:
92271d10453SEric Joyner 		str = "SSO_LENGTH_ZERO";
92371d10453SEric Joyner 		break;
92471d10453SEric Joyner 	case 15:
92571d10453SEric Joyner 		str = "SSO_LENGTH_EXCEED";
92671d10453SEric Joyner 		break;
92771d10453SEric Joyner 	case 16:
92871d10453SEric Joyner 		str = "SSO_PKTCNT_ZERO";
92971d10453SEric Joyner 		break;
93071d10453SEric Joyner 	case 17:
93171d10453SEric Joyner 		str = "SSO_PKTCNT_EXCEED";
93271d10453SEric Joyner 		break;
93371d10453SEric Joyner 	case 18:
93471d10453SEric Joyner 		str = "SSO_NUMDESCS_ZERO";
93571d10453SEric Joyner 		break;
93671d10453SEric Joyner 	case 19:
93771d10453SEric Joyner 		str = "SSO_NUMDESCS_EXCEED";
93871d10453SEric Joyner 		break;
93971d10453SEric Joyner 	case 20:
94071d10453SEric Joyner 		str = "TAIL_GT_RING_LENGTH";
94171d10453SEric Joyner 		break;
94271d10453SEric Joyner 	case 21:
94371d10453SEric Joyner 		str = "RESERVED_DBL_TYPE";
94471d10453SEric Joyner 		break;
94571d10453SEric Joyner 	case 22:
94671d10453SEric Joyner 		str = "ILLEGAL_HEAD_DROP_DBL";
94771d10453SEric Joyner 		break;
94871d10453SEric Joyner 	case 23:
94971d10453SEric Joyner 		str = "LSO_OVER_COMMS_Q";
95071d10453SEric Joyner 		break;
95171d10453SEric Joyner 	case 24:
95271d10453SEric Joyner 		str = "ILLEGAL_VF_QNUM";
95371d10453SEric Joyner 		break;
95471d10453SEric Joyner 	case 25:
95571d10453SEric Joyner 		str = "QTAIL_GT_RING_LENGTH";
95671d10453SEric Joyner 		break;
95771d10453SEric Joyner 	default:
95871d10453SEric Joyner 		break;
95971d10453SEric Joyner 	}
96071d10453SEric Joyner 
96171d10453SEric Joyner 	if (str)
96271d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
96371d10453SEric Joyner 	else
96471d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx PQM event %u", event);
96571d10453SEric Joyner 
96671d10453SEric Joyner 	return buf;
96771d10453SEric Joyner }
96871d10453SEric Joyner 
96971d10453SEric Joyner /**
97071d10453SEric Joyner  * ice_mdd_rx_str - Convert MDD Rx queue event to a string
97171d10453SEric Joyner  * @event: the MDD event number to convert
97271d10453SEric Joyner  *
97371d10453SEric Joyner  * Convert the Rx queue event value from the GL_MDET_RX register into a human
97471d10453SEric Joyner  * readable string for logging of MDD events.
97571d10453SEric Joyner  */
97671d10453SEric Joyner struct ice_str_buf
97771d10453SEric Joyner _ice_mdd_rx_str(u8 event)
97871d10453SEric Joyner {
97971d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
98071d10453SEric Joyner 	const char *str = NULL;
98171d10453SEric Joyner 
98271d10453SEric Joyner 	switch (event) {
98371d10453SEric Joyner 	case 1:
98471d10453SEric Joyner 		str = "Descriptor fetch failed";
98571d10453SEric Joyner 		break;
98671d10453SEric Joyner 	default:
98771d10453SEric Joyner 		break;
98871d10453SEric Joyner 	}
98971d10453SEric Joyner 
99071d10453SEric Joyner 	if (str)
99171d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
99271d10453SEric Joyner 	else
99371d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Rx event %u", event);
99471d10453SEric Joyner 
99571d10453SEric Joyner 	return buf;
99671d10453SEric Joyner }
99771d10453SEric Joyner 
99871d10453SEric Joyner /**
99971d10453SEric Joyner  * ice_state_to_str - Convert the state enum to a string value
100071d10453SEric Joyner  * @state: the state bit to convert
100171d10453SEric Joyner  *
100271d10453SEric Joyner  * Converts a given state bit to its human readable string name. If the enum
100371d10453SEric Joyner  * value is unknown, returns NULL;
100471d10453SEric Joyner  */
100571d10453SEric Joyner const char *
100671d10453SEric Joyner ice_state_to_str(enum ice_state state)
100771d10453SEric Joyner {
100871d10453SEric Joyner 	switch (state) {
100971d10453SEric Joyner 	case ICE_STATE_CONTROLQ_EVENT_PENDING:
101071d10453SEric Joyner 		return "CONTROLQ_EVENT_PENDING";
101171d10453SEric Joyner 	case ICE_STATE_VFLR_PENDING:
101271d10453SEric Joyner 		return "VFLR_PENDING";
101371d10453SEric Joyner 	case ICE_STATE_MDD_PENDING:
101471d10453SEric Joyner 		return "MDD_PENDING";
101571d10453SEric Joyner 	case ICE_STATE_RESET_OICR_RECV:
101671d10453SEric Joyner 		return "RESET_OICR_RECV";
101771d10453SEric Joyner 	case ICE_STATE_RESET_PFR_REQ:
101871d10453SEric Joyner 		return "RESET_PFR_REQ";
101971d10453SEric Joyner 	case ICE_STATE_PREPARED_FOR_RESET:
102071d10453SEric Joyner 		return "PREPARED_FOR_RESET";
10219e54973fSEric Joyner 	case ICE_STATE_SUBIF_NEEDS_REINIT:
10229e54973fSEric Joyner 		return "SUBIF_NEEDS_REINIT";
102371d10453SEric Joyner 	case ICE_STATE_RESET_FAILED:
102471d10453SEric Joyner 		return "RESET_FAILED";
102571d10453SEric Joyner 	case ICE_STATE_DRIVER_INITIALIZED:
102671d10453SEric Joyner 		return "DRIVER_INITIALIZED";
102771d10453SEric Joyner 	case ICE_STATE_NO_MEDIA:
102871d10453SEric Joyner 		return "NO_MEDIA";
102971d10453SEric Joyner 	case ICE_STATE_RECOVERY_MODE:
103071d10453SEric Joyner 		return "RECOVERY_MODE";
103171d10453SEric Joyner 	case ICE_STATE_ROLLBACK_MODE:
103271d10453SEric Joyner 		return "ROLLBACK_MODE";
103371d10453SEric Joyner 	case ICE_STATE_LINK_STATUS_REPORTED:
103471d10453SEric Joyner 		return "LINK_STATUS_REPORTED";
103556429daeSEric Joyner 	case ICE_STATE_ATTACHING:
103656429daeSEric Joyner 		return "ATTACHING";
103771d10453SEric Joyner 	case ICE_STATE_DETACHING:
103871d10453SEric Joyner 		return "DETACHING";
103971d10453SEric Joyner 	case ICE_STATE_LINK_DEFAULT_OVERRIDE_PENDING:
104071d10453SEric Joyner 		return "LINK_DEFAULT_OVERRIDE_PENDING";
10417d7af7f8SEric Joyner 	case ICE_STATE_LLDP_RX_FLTR_FROM_DRIVER:
10427d7af7f8SEric Joyner 		return "LLDP_RX_FLTR_FROM_DRIVER";
104356429daeSEric Joyner 	case ICE_STATE_MULTIPLE_TCS:
104456429daeSEric Joyner 		return "MULTIPLE_TCS";
10458923de59SPiotr Kubaj 	case ICE_STATE_DO_FW_DEBUG_DUMP:
10468923de59SPiotr Kubaj 		return "DO_FW_DEBUG_DUMP";
10479c30461dSEric Joyner 	case ICE_STATE_LINK_ACTIVE_ON_DOWN:
10489c30461dSEric Joyner 		return "LINK_ACTIVE_ON_DOWN";
10499c30461dSEric Joyner 	case ICE_STATE_FIRST_INIT_LINK:
10509c30461dSEric Joyner 		return "FIRST_INIT_LINK";
10519e54973fSEric Joyner 	case ICE_STATE_DO_CREATE_MIRR_INTFC:
10529e54973fSEric Joyner 		return "DO_CREATE_MIRR_INTFC";
10539e54973fSEric Joyner 	case ICE_STATE_DO_DESTROY_MIRR_INTFC:
10549e54973fSEric Joyner 		return "DO_DESTROY_MIRR_INTFC";
1055*f377a0c7SEric Joyner 	case ICE_STATE_PHY_FW_INIT_PENDING:
1056*f377a0c7SEric Joyner 		return "PHY_FW_INIT_PENDING";
105771d10453SEric Joyner 	case ICE_STATE_LAST:
105871d10453SEric Joyner 		return NULL;
105971d10453SEric Joyner 	}
106071d10453SEric Joyner 
106171d10453SEric Joyner 	return NULL;
106271d10453SEric Joyner }
106371d10453SEric Joyner 
106471d10453SEric Joyner /**
106556429daeSEric Joyner  * ice_fw_module_str - Convert a FW logging module to a string name
106656429daeSEric Joyner  * @module: the module to convert
106756429daeSEric Joyner  *
106856429daeSEric Joyner  * Given a FW logging module id, convert it to a shorthand human readable
106956429daeSEric Joyner  * name, for generating sysctl tunables.
107056429daeSEric Joyner  */
107156429daeSEric Joyner const char *
107256429daeSEric Joyner ice_fw_module_str(enum ice_aqc_fw_logging_mod module)
107356429daeSEric Joyner {
107456429daeSEric Joyner 	switch (module) {
107556429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_GENERAL:
107656429daeSEric Joyner 		return "general";
107756429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_CTRL:
107856429daeSEric Joyner 		return "ctrl";
107956429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_LINK:
108056429daeSEric Joyner 		return "link";
108156429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_LINK_TOPO:
108256429daeSEric Joyner 		return "link_topo";
108356429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_DNL:
108456429daeSEric Joyner 		return "dnl";
108556429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_I2C:
108656429daeSEric Joyner 		return "i2c";
108756429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_SDP:
108856429daeSEric Joyner 		return "sdp";
108956429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_MDIO:
109056429daeSEric Joyner 		return "mdio";
109156429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_ADMINQ:
109256429daeSEric Joyner 		return "adminq";
109356429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_HDMA:
109456429daeSEric Joyner 		return "hdma";
109556429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_LLDP:
109656429daeSEric Joyner 		return "lldp";
109756429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_DCBX:
109856429daeSEric Joyner 		return "dcbx";
109956429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_DCB:
110056429daeSEric Joyner 		return "dcb";
110156429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_XLR:
110256429daeSEric Joyner 		return "xlr";
110356429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_NVM:
110456429daeSEric Joyner 		return "nvm";
110556429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_AUTH:
110656429daeSEric Joyner 		return "auth";
110756429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_VPD:
110856429daeSEric Joyner 		return "vpd";
110956429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_IOSF:
111056429daeSEric Joyner 		return "iosf";
111156429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_PARSER:
111256429daeSEric Joyner 		return "parser";
111356429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_SW:
111456429daeSEric Joyner 		return "sw";
111556429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_SCHEDULER:
111656429daeSEric Joyner 		return "scheduler";
111756429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_TXQ:
111856429daeSEric Joyner 		return "txq";
111956429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_RSVD:
112056429daeSEric Joyner 		return "acl";
112156429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_POST:
112256429daeSEric Joyner 		return "post";
112356429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_WATCHDOG:
112456429daeSEric Joyner 		return "watchdog";
112556429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_TASK_DISPATCH:
112656429daeSEric Joyner 		return "task_dispatch";
112756429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_MNG:
112856429daeSEric Joyner 		return "mng";
112956429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_SYNCE:
113056429daeSEric Joyner 		return "synce";
113156429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_HEALTH:
113256429daeSEric Joyner 		return "health";
113356429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_TSDRV:
113456429daeSEric Joyner 		return "tsdrv";
113556429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_PFREG:
113656429daeSEric Joyner 		return "pfreg";
113756429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_MDLVER:
113856429daeSEric Joyner 		return "mdlver";
113956429daeSEric Joyner 	case ICE_AQC_FW_LOG_ID_MAX:
114056429daeSEric Joyner 		return "unknown";
114156429daeSEric Joyner 	}
114256429daeSEric Joyner 
114356429daeSEric Joyner 	/* The compiler generates errors on unhandled enum values if we omit
114456429daeSEric Joyner 	 * the default case.
114556429daeSEric Joyner 	 */
114656429daeSEric Joyner 	return "unknown";
114756429daeSEric Joyner }
114856429daeSEric Joyner 
114956429daeSEric Joyner /**
115071d10453SEric Joyner  * ice_fw_lldp_status - Convert FW LLDP status to a string
115171d10453SEric Joyner  * @lldp_status: firmware LLDP status value to convert
115271d10453SEric Joyner  *
115371d10453SEric Joyner  * Given the FW LLDP status, convert it to a human readable string.
115471d10453SEric Joyner  */
115571d10453SEric Joyner struct ice_str_buf
115671d10453SEric Joyner _ice_fw_lldp_status(u32 lldp_status)
115771d10453SEric Joyner {
115871d10453SEric Joyner 	struct ice_str_buf buf = { .str = "" };
115971d10453SEric Joyner 	const char *str = NULL;
116071d10453SEric Joyner 
116171d10453SEric Joyner 	switch (lldp_status)
116271d10453SEric Joyner 	{
116371d10453SEric Joyner 	case ICE_LLDP_ADMINSTATUS_DIS:
116471d10453SEric Joyner 		str = "DISABLED";
116571d10453SEric Joyner 		break;
116671d10453SEric Joyner 	case ICE_LLDP_ADMINSTATUS_ENA_RX:
116771d10453SEric Joyner 		str = "ENA_RX";
116871d10453SEric Joyner 		break;
116971d10453SEric Joyner 	case ICE_LLDP_ADMINSTATUS_ENA_TX:
117071d10453SEric Joyner 		str = "ENA_TX";
117171d10453SEric Joyner 		break;
117271d10453SEric Joyner 	case ICE_LLDP_ADMINSTATUS_ENA_RXTX:
117371d10453SEric Joyner 		str = "ENA_RXTX";
117471d10453SEric Joyner 		break;
117571d10453SEric Joyner 	case 0xF:
117671d10453SEric Joyner 		str = "NVM_DEFAULT";
117771d10453SEric Joyner 		break;
117871d10453SEric Joyner 	}
117971d10453SEric Joyner 
118071d10453SEric Joyner 	if (str)
118171d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
118271d10453SEric Joyner 	else
118371d10453SEric Joyner 		snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown LLDP status %u", lldp_status);
118471d10453SEric Joyner 
118571d10453SEric Joyner 	return buf;
118671d10453SEric Joyner }
1187