1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2023, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
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.
35 * @brief functions to convert enumerated values to human readable strings
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.
41 * Additionally, various other driver enumerations which are displayed via
42 * sysctl have converter functions.
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.
61 * ice_aq_str - Convert an AdminQ error into a string
62 * @aq_err: the AQ error code to convert
64 * Convert the AdminQ status into its string name, if known. Otherwise, format
65 * the error as an integer.
68 _ice_aq_str(enum ice_aq_err aq_err)
70 struct ice_str_buf buf = { .str = "" };
71 const char *str = NULL;
80 case ICE_AQ_RC_ENOENT:
98 case ICE_AQ_RC_EAGAIN:
101 case ICE_AQ_RC_ENOMEM:
102 str = "AQ_RC_ENOMEM";
104 case ICE_AQ_RC_EACCES:
105 str = "AQ_RC_EACCES";
107 case ICE_AQ_RC_EFAULT:
108 str = "AQ_RC_EFAULT";
110 case ICE_AQ_RC_EBUSY:
113 case ICE_AQ_RC_EEXIST:
114 str = "AQ_RC_EEXIST";
116 case ICE_AQ_RC_EINVAL:
117 str = "AQ_RC_EINVAL";
119 case ICE_AQ_RC_ENOTTY:
120 str = "AQ_RC_ENOTTY";
122 case ICE_AQ_RC_ENOSPC:
123 str = "AQ_RC_ENOSPC";
125 case ICE_AQ_RC_ENOSYS:
126 str = "AQ_RC_ENOSYS";
128 case ICE_AQ_RC_ERANGE:
129 str = "AQ_RC_ERANGE";
131 case ICE_AQ_RC_EFLUSHED:
132 str = "AQ_RC_EFLUSHED";
134 case ICE_AQ_RC_BAD_ADDR:
135 str = "AQ_RC_BAD_ADDR";
137 case ICE_AQ_RC_EMODE:
140 case ICE_AQ_RC_EFBIG:
143 case ICE_AQ_RC_ESBCOMP:
144 str = "AQ_RC_ESBCOMP";
146 case ICE_AQ_RC_ENOSEC:
147 str = "AQ_RC_ENOSEC";
149 case ICE_AQ_RC_EBADSIG:
150 str = "AQ_RC_EBADSIG";
155 case ICE_AQ_RC_EBADMAN:
156 str = "AQ_RC_EBADMAN";
158 case ICE_AQ_RC_EBADBUF:
159 str = "AQ_RC_EBADBUF";
161 case ICE_AQ_RC_EACCES_BMCU:
162 str = "AQ_RC_EACCES_BMCU";
167 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
169 snprintf(buf.str, ICE_STR_BUF_LEN, "%d", aq_err);
175 * ice_status_str - convert status err code to a string
176 * @status: the status error code to convert
178 * Convert the status code into its string name if known.
180 * Otherwise, use the scratch space to format the status code into a number.
183 _ice_status_str(enum ice_status status)
185 struct ice_str_buf buf = { .str = "" };
186 const char *str = NULL;
193 str = "ICE_ERR_PARAM";
195 case ICE_ERR_NOT_IMPL:
196 str = "ICE_ERR_NOT_IMPL";
198 case ICE_ERR_NOT_READY:
199 str = "ICE_ERR_NOT_READY";
201 case ICE_ERR_NOT_SUPPORTED:
202 str = "ICE_ERR_NOT_SUPPORTED";
204 case ICE_ERR_BAD_PTR:
205 str = "ICE_ERR_BAD_PTR";
207 case ICE_ERR_INVAL_SIZE:
208 str = "ICE_ERR_INVAL_SIZE";
210 case ICE_ERR_DEVICE_NOT_SUPPORTED:
211 str = "ICE_ERR_DEVICE_NOT_SUPPORTED";
213 case ICE_ERR_RESET_FAILED:
214 str = "ICE_ERR_RESET_FAILED";
216 case ICE_ERR_FW_API_VER:
217 str = "ICE_ERR_FW_API_VER";
219 case ICE_ERR_NO_MEMORY:
220 str = "ICE_ERR_NO_MEMORY";
225 case ICE_ERR_OUT_OF_RANGE:
226 str = "ICE_ERR_OUT_OF_RANGE";
228 case ICE_ERR_ALREADY_EXISTS:
229 str = "ICE_ERR_ALREADY_EXISTS";
234 case ICE_ERR_NVM_CHECKSUM:
235 str = "ICE_ERR_NVM_CHECKSUM";
237 case ICE_ERR_BUF_TOO_SHORT:
238 str = "ICE_ERR_BUF_TOO_SHORT";
240 case ICE_ERR_NVM_BLANK_MODE:
241 str = "ICE_ERR_NVM_BLANK_MODE";
244 str = "ICE_ERR_IN_USE";
246 case ICE_ERR_MAX_LIMIT:
247 str = "ICE_ERR_MAX_LIMIT";
249 case ICE_ERR_RESET_ONGOING:
250 str = "ICE_ERR_RESET_ONGOING";
252 case ICE_ERR_HW_TABLE:
253 str = "ICE_ERR_HW_TABLE";
255 case ICE_ERR_FW_DDP_MISMATCH:
256 str = "ICE_ERR_FW_DDP_MISMATCH";
258 case ICE_ERR_DOES_NOT_EXIST:
259 str = "ICE_ERR_DOES_NOT_EXIST";
261 case ICE_ERR_AQ_ERROR:
262 str = "ICE_ERR_AQ_ERROR";
264 case ICE_ERR_AQ_TIMEOUT:
265 str = "ICE_ERR_AQ_TIMEOUT";
267 case ICE_ERR_AQ_FULL:
268 str = "ICE_ERR_AQ_FULL";
270 case ICE_ERR_AQ_NO_WORK:
271 str = "ICE_ERR_AQ_NO_WORK";
273 case ICE_ERR_AQ_EMPTY:
274 str = "ICE_ERR_AQ_EMPTY";
276 case ICE_ERR_AQ_FW_CRITICAL:
277 str = "ICE_ERR_AQ_FW_CRITICAL";
282 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
284 snprintf(buf.str, ICE_STR_BUF_LEN, "%d", status);
290 * ice_err_str - convert error code to a string
291 * @err: the error code to convert
293 * Convert an error code into its string/macro name if known. Note, it doesn't
294 * handle negated errors.
296 * Otherwise, use the scratch space to format the error into a number.
299 _ice_err_str(int err)
301 struct ice_str_buf buf = { .str = "" };
302 const char *str = NULL;
424 str = "EDESTADDRREQ";
435 case EPROTONOSUPPORT:
436 str = "EPROTONOSUPPORT";
438 case ESOCKTNOSUPPORT:
439 str = "ESOCKTNOSUPPORT";
446 str = "EPFNOSUPPORT";
449 str = "EAFNOSUPPORT";
455 str = "EADDRNOTAVAIL";
467 str = "ECONNABORTED";
485 str = "ETOOMANYREFS";
491 str = "ECONNREFUSED";
497 str = "ENAMETOOLONG";
503 str = "EHOSTUNREACH";
527 str = "ERPCMISMATCH";
530 str = "EPROGUNAVAIL";
533 str = "EPROGMISMATCH";
536 str = "EPROCUNAVAIL";
592 case ENOTRECOVERABLE:
593 str = "ENOTRECOVERABLE";
601 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
603 snprintf(buf.str, ICE_STR_BUF_LEN, "%d", err);
609 * ice_fec_str - convert fec mode enum to a string
610 * @mode: the enum value to convert
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.
616 ice_fec_str(enum ice_fec_mode mode)
620 return ICE_FEC_STRING_AUTO;
622 return ICE_FEC_STRING_RS;
624 return ICE_FEC_STRING_BASER;
626 return ICE_FEC_STRING_NONE;
627 case ICE_FEC_DIS_AUTO:
628 return ICE_FEC_STRING_DIS_AUTO;
631 /* The compiler generates errors on unhandled enum values if we omit
638 * ice_fc_str - convert flow control mode enum to a string
639 * @mode: the enum value to convert
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.
646 ice_fc_str(enum ice_fc_mode mode)
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;
656 return ICE_FC_STRING_NONE;
663 /* The compiler generates errors on unhandled enum values if we omit
670 * ice_fltr_flag_str - Convert filter flags to a string
671 * @flag: the filter flags to convert
673 * Convert the u16 flag value of a filter into a readable string for
674 * outputting in a sysctl.
677 _ice_fltr_flag_str(u16 flag)
679 struct ice_str_buf buf = { .str = "" };
680 const char *str = NULL;
697 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
699 snprintf(buf.str, ICE_STR_BUF_LEN, "%u", flag);
705 * ice_log_sev_str - Convert log level to a string
706 * @log_level: the log level to convert
708 * Convert the u8 log level of a FW logging module into a readable
709 * string for outputting in a sysctl.
712 _ice_log_sev_str(u8 log_level)
714 struct ice_str_buf buf = { .str = "" };
715 const char *str = NULL;
718 case ICE_FWLOG_LEVEL_NONE:
721 case ICE_FWLOG_LEVEL_ERROR:
724 case ICE_FWLOG_LEVEL_WARNING:
727 case ICE_FWLOG_LEVEL_NORMAL:
730 case ICE_FWLOG_LEVEL_VERBOSE:
738 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
740 snprintf(buf.str, ICE_STR_BUF_LEN, "%u", log_level);
746 * ice_fwd_act_str - convert filter action enum to a string
747 * @action: the filter action to convert
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
754 ice_fwd_act_str(enum ice_sw_fwd_act_type action)
759 case ICE_FWD_TO_VSI_LIST:
760 return "FWD_TO_VSI_LIST";
763 case ICE_FWD_TO_QGRP:
764 return "FWD_TO_QGRP";
765 case ICE_DROP_PACKET:
766 return "DROP_PACKET";
773 /* The compiler generates errors on unhandled enum values if we omit
780 * ice_mdd_tx_tclan_str - Convert MDD Tx TCLAN event to a string
781 * @event: the MDD event number to convert
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.
787 _ice_mdd_tx_tclan_str(u8 event)
789 struct ice_str_buf buf = { .str = "" };
790 const char *str = NULL;
794 str = "Wrong descriptor format/order";
797 str = "Descriptor fetch failed";
800 str = "Tail descriptor not EOP/NOP";
803 str = "False scheduling error";
806 str = "Tail value larger than ring len";
809 str = "Too many data commands";
812 str = "Zero packets sent in quanta";
815 str = "Packet too small or too big";
818 str = "TSO length doesn't match sum";
821 str = "TSO tail reached before TLEN";
824 str = "TSO max 3 descs for headers";
827 str = "EOP on header descriptor";
830 str = "MSS is 0 or TLEN is 0";
833 str = "CTX desc invalid IPSec fields";
836 str = "Quanta invalid # of SSO packets";
839 str = "Quanta bytes exceeds pkt_len*64";
842 str = "Quanta exceeds max_cmds_in_sq";
845 str = "incoherent last_lso_quanta";
848 str = "incoherent TSO TLEN";
851 str = "Quanta: too many descriptors";
854 str = "Quanta: # of packets mismatch";
861 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
863 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx TCLAN event %u", event);
869 * ice_mdd_tx_pqm_str - Convert MDD Tx PQM event to a string
870 * @event: the MDD event number to convert
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.
876 _ice_mdd_tx_pqm_str(u8 event)
878 struct ice_str_buf buf = { .str = "" };
879 const char *str = NULL;
883 str = "PCI_DUMMY_COMP";
888 /* Index 2 is unused */
890 str = "RCV_SH_BE_LSO";
893 str = "Q_FL_MNG_EPY_CH";
896 str = "Q_EPY_MNG_FL_CH";
899 str = "LSO_NUMDESCS_ZERO";
902 str = "LSO_LENGTH_ZERO";
905 str = "LSO_MSS_BELOW_MIN";
908 str = "LSO_MSS_ABOVE_MAX";
911 str = "LSO_HDR_SIZE_ZERO";
914 str = "RCV_CNT_BE_LSO";
917 str = "SKIP_ONE_QT_ONLY";
920 str = "LSO_PKTCNT_ZERO";
923 str = "SSO_LENGTH_ZERO";
926 str = "SSO_LENGTH_EXCEED";
929 str = "SSO_PKTCNT_ZERO";
932 str = "SSO_PKTCNT_EXCEED";
935 str = "SSO_NUMDESCS_ZERO";
938 str = "SSO_NUMDESCS_EXCEED";
941 str = "TAIL_GT_RING_LENGTH";
944 str = "RESERVED_DBL_TYPE";
947 str = "ILLEGAL_HEAD_DROP_DBL";
950 str = "LSO_OVER_COMMS_Q";
953 str = "ILLEGAL_VF_QNUM";
956 str = "QTAIL_GT_RING_LENGTH";
963 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
965 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx PQM event %u", event);
971 * ice_mdd_rx_str - Convert MDD Rx queue event to a string
972 * @event: the MDD event number to convert
974 * Convert the Rx queue event value from the GL_MDET_RX register into a human
975 * readable string for logging of MDD events.
978 _ice_mdd_rx_str(u8 event)
980 struct ice_str_buf buf = { .str = "" };
981 const char *str = NULL;
985 str = "Descriptor fetch failed";
992 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
994 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Rx event %u", event);
1000 * ice_state_to_str - Convert the state enum to a string value
1001 * @state: the state bit to convert
1003 * Converts a given state bit to its human readable string name. If the enum
1004 * value is unknown, returns NULL;
1007 ice_state_to_str(enum ice_state 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:
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:
1036 case ICE_STATE_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:
1054 * ice_fw_module_str - Convert a FW logging module to a string name
1055 * @module: the module to convert
1057 * Given a FW logging module id, convert it to a shorthand human readable
1058 * name, for generating sysctl tunables.
1061 ice_fw_module_str(enum ice_aqc_fw_logging_mod module)
1064 case ICE_AQC_FW_LOG_ID_GENERAL:
1066 case ICE_AQC_FW_LOG_ID_CTRL:
1068 case ICE_AQC_FW_LOG_ID_LINK:
1070 case ICE_AQC_FW_LOG_ID_LINK_TOPO:
1072 case ICE_AQC_FW_LOG_ID_DNL:
1074 case ICE_AQC_FW_LOG_ID_I2C:
1076 case ICE_AQC_FW_LOG_ID_SDP:
1078 case ICE_AQC_FW_LOG_ID_MDIO:
1080 case ICE_AQC_FW_LOG_ID_ADMINQ:
1082 case ICE_AQC_FW_LOG_ID_HDMA:
1084 case ICE_AQC_FW_LOG_ID_LLDP:
1086 case ICE_AQC_FW_LOG_ID_DCBX:
1088 case ICE_AQC_FW_LOG_ID_DCB:
1090 case ICE_AQC_FW_LOG_ID_XLR:
1092 case ICE_AQC_FW_LOG_ID_NVM:
1094 case ICE_AQC_FW_LOG_ID_AUTH:
1096 case ICE_AQC_FW_LOG_ID_VPD:
1098 case ICE_AQC_FW_LOG_ID_IOSF:
1100 case ICE_AQC_FW_LOG_ID_PARSER:
1102 case ICE_AQC_FW_LOG_ID_SW:
1104 case ICE_AQC_FW_LOG_ID_SCHEDULER:
1106 case ICE_AQC_FW_LOG_ID_TXQ:
1108 case ICE_AQC_FW_LOG_ID_RSVD:
1110 case ICE_AQC_FW_LOG_ID_POST:
1112 case ICE_AQC_FW_LOG_ID_WATCHDOG:
1114 case ICE_AQC_FW_LOG_ID_TASK_DISPATCH:
1115 return "task_dispatch";
1116 case ICE_AQC_FW_LOG_ID_MNG:
1118 case ICE_AQC_FW_LOG_ID_SYNCE:
1120 case ICE_AQC_FW_LOG_ID_HEALTH:
1122 case ICE_AQC_FW_LOG_ID_TSDRV:
1124 case ICE_AQC_FW_LOG_ID_PFREG:
1126 case ICE_AQC_FW_LOG_ID_MDLVER:
1128 case ICE_AQC_FW_LOG_ID_MAX:
1132 /* The compiler generates errors on unhandled enum values if we omit
1139 * ice_fw_lldp_status - Convert FW LLDP status to a string
1140 * @lldp_status: firmware LLDP status value to convert
1142 * Given the FW LLDP status, convert it to a human readable string.
1145 _ice_fw_lldp_status(u32 lldp_status)
1147 struct ice_str_buf buf = { .str = "" };
1148 const char *str = NULL;
1150 switch (lldp_status)
1152 case ICE_LLDP_ADMINSTATUS_DIS:
1155 case ICE_LLDP_ADMINSTATUS_ENA_RX:
1158 case ICE_LLDP_ADMINSTATUS_ENA_TX:
1161 case ICE_LLDP_ADMINSTATUS_ENA_RXTX:
1165 str = "NVM_DEFAULT";
1170 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
1172 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown LLDP status %u", lldp_status);