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.
34 * @brief functions to convert enumerated values to human readable strings
36 * Contains various functions which convert enumerated values into human
37 * readable strings. Primarily this is used for error values, such as the
38 * ice_status enum, the ice_aq_err values, or standard sys/errno.h values.
40 * Additionally, various other driver enumerations which are displayed via
41 * sysctl have converter functions.
43 * Some of the functions return struct ice_str_buf, instead of a character
44 * string pointer. This is a trick to allow the function to create a struct
45 * with space to convert unknown numeric values into a string, and return the
46 * contents via copying the struct memory back. The functions then have an
47 * associated macro to access the string value immediately. This allows the
48 * functions to return static strings for known values, and convert unknown
49 * values into a numeric representation. It also does not require
50 * pre-allocating storage at each callsite, or using a local static value
51 * which wouldn't be re-entrant, and could collide if multiple threads call
52 * the function. The extra copies are somewhat annoying, but generally the
53 * error functions aren't expected to be in a hot path so this is an
54 * acceptable trade off.
60 * ice_aq_str - Convert an AdminQ error into a string
61 * @aq_err: the AQ error code to convert
63 * Convert the AdminQ status into its string name, if known. Otherwise, format
64 * the error as an integer.
67 _ice_aq_str(enum ice_aq_err aq_err)
69 struct ice_str_buf buf = { .str = "" };
70 const char *str = NULL;
79 case ICE_AQ_RC_ENOENT:
97 case ICE_AQ_RC_EAGAIN:
100 case ICE_AQ_RC_ENOMEM:
101 str = "AQ_RC_ENOMEM";
103 case ICE_AQ_RC_EACCES:
104 str = "AQ_RC_EACCES";
106 case ICE_AQ_RC_EFAULT:
107 str = "AQ_RC_EFAULT";
109 case ICE_AQ_RC_EBUSY:
112 case ICE_AQ_RC_EEXIST:
113 str = "AQ_RC_EEXIST";
115 case ICE_AQ_RC_EINVAL:
116 str = "AQ_RC_EINVAL";
118 case ICE_AQ_RC_ENOTTY:
119 str = "AQ_RC_ENOTTY";
121 case ICE_AQ_RC_ENOSPC:
122 str = "AQ_RC_ENOSPC";
124 case ICE_AQ_RC_ENOSYS:
125 str = "AQ_RC_ENOSYS";
127 case ICE_AQ_RC_ERANGE:
128 str = "AQ_RC_ERANGE";
130 case ICE_AQ_RC_EFLUSHED:
131 str = "AQ_RC_EFLUSHED";
133 case ICE_AQ_RC_BAD_ADDR:
134 str = "AQ_RC_BAD_ADDR";
136 case ICE_AQ_RC_EMODE:
139 case ICE_AQ_RC_EFBIG:
142 case ICE_AQ_RC_ESBCOMP:
143 str = "AQ_RC_ESBCOMP";
145 case ICE_AQ_RC_ENOSEC:
146 str = "AQ_RC_ENOSEC";
148 case ICE_AQ_RC_EBADSIG:
149 str = "AQ_RC_EBADSIG";
154 case ICE_AQ_RC_EBADMAN:
155 str = "AQ_RC_EBADMAN";
157 case ICE_AQ_RC_EBADBUF:
158 str = "AQ_RC_EBADBUF";
160 case ICE_AQ_RC_EACCES_BMCU:
161 str = "AQ_RC_EACCES_BMCU";
166 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
168 snprintf(buf.str, ICE_STR_BUF_LEN, "%d", aq_err);
174 * ice_status_str - convert status err code to a string
175 * @status: the status error code to convert
177 * Convert the status code into its string name if known.
179 * Otherwise, use the scratch space to format the status code into a number.
182 _ice_status_str(enum ice_status status)
184 struct ice_str_buf buf = { .str = "" };
185 const char *str = NULL;
192 str = "ICE_ERR_PARAM";
194 case ICE_ERR_NOT_IMPL:
195 str = "ICE_ERR_NOT_IMPL";
197 case ICE_ERR_NOT_READY:
198 str = "ICE_ERR_NOT_READY";
200 case ICE_ERR_NOT_SUPPORTED:
201 str = "ICE_ERR_NOT_SUPPORTED";
203 case ICE_ERR_BAD_PTR:
204 str = "ICE_ERR_BAD_PTR";
206 case ICE_ERR_INVAL_SIZE:
207 str = "ICE_ERR_INVAL_SIZE";
209 case ICE_ERR_DEVICE_NOT_SUPPORTED:
210 str = "ICE_ERR_DEVICE_NOT_SUPPORTED";
212 case ICE_ERR_RESET_FAILED:
213 str = "ICE_ERR_RESET_FAILED";
215 case ICE_ERR_FW_API_VER:
216 str = "ICE_ERR_FW_API_VER";
218 case ICE_ERR_NO_MEMORY:
219 str = "ICE_ERR_NO_MEMORY";
224 case ICE_ERR_OUT_OF_RANGE:
225 str = "ICE_ERR_OUT_OF_RANGE";
227 case ICE_ERR_ALREADY_EXISTS:
228 str = "ICE_ERR_ALREADY_EXISTS";
233 case ICE_ERR_NVM_CHECKSUM:
234 str = "ICE_ERR_NVM_CHECKSUM";
236 case ICE_ERR_BUF_TOO_SHORT:
237 str = "ICE_ERR_BUF_TOO_SHORT";
239 case ICE_ERR_NVM_BLANK_MODE:
240 str = "ICE_ERR_NVM_BLANK_MODE";
243 str = "ICE_ERR_IN_USE";
245 case ICE_ERR_MAX_LIMIT:
246 str = "ICE_ERR_MAX_LIMIT";
248 case ICE_ERR_RESET_ONGOING:
249 str = "ICE_ERR_RESET_ONGOING";
251 case ICE_ERR_HW_TABLE:
252 str = "ICE_ERR_HW_TABLE";
254 case ICE_ERR_FW_DDP_MISMATCH:
255 str = "ICE_ERR_FW_DDP_MISMATCH";
257 case ICE_ERR_DOES_NOT_EXIST:
258 str = "ICE_ERR_DOES_NOT_EXIST";
260 case ICE_ERR_AQ_ERROR:
261 str = "ICE_ERR_AQ_ERROR";
263 case ICE_ERR_AQ_TIMEOUT:
264 str = "ICE_ERR_AQ_TIMEOUT";
266 case ICE_ERR_AQ_FULL:
267 str = "ICE_ERR_AQ_FULL";
269 case ICE_ERR_AQ_NO_WORK:
270 str = "ICE_ERR_AQ_NO_WORK";
272 case ICE_ERR_AQ_EMPTY:
273 str = "ICE_ERR_AQ_EMPTY";
275 case ICE_ERR_AQ_FW_CRITICAL:
276 str = "ICE_ERR_AQ_FW_CRITICAL";
281 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
283 snprintf(buf.str, ICE_STR_BUF_LEN, "%d", status);
289 * ice_err_str - convert error code to a string
290 * @err: the error code to convert
292 * Convert an error code into its string/macro name if known. Note, it doesn't
293 * handle negated errors.
295 * Otherwise, use the scratch space to format the error into a number.
298 _ice_err_str(int err)
300 struct ice_str_buf buf = { .str = "" };
301 const char *str = NULL;
423 str = "EDESTADDRREQ";
434 case EPROTONOSUPPORT:
435 str = "EPROTONOSUPPORT";
437 case ESOCKTNOSUPPORT:
438 str = "ESOCKTNOSUPPORT";
445 str = "EPFNOSUPPORT";
448 str = "EAFNOSUPPORT";
454 str = "EADDRNOTAVAIL";
466 str = "ECONNABORTED";
484 str = "ETOOMANYREFS";
490 str = "ECONNREFUSED";
496 str = "ENAMETOOLONG";
502 str = "EHOSTUNREACH";
526 str = "ERPCMISMATCH";
529 str = "EPROGUNAVAIL";
532 str = "EPROGMISMATCH";
535 str = "EPROCUNAVAIL";
591 case ENOTRECOVERABLE:
592 str = "ENOTRECOVERABLE";
600 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
602 snprintf(buf.str, ICE_STR_BUF_LEN, "%d", err);
608 * ice_fec_str - convert fec mode enum to a string
609 * @mode: the enum value to convert
611 * Convert an FEC mode enum to a string for display in a sysctl or log message.
612 * Returns "Unknown" if the mode is not one of currently known FEC modes.
615 ice_fec_str(enum ice_fec_mode mode)
619 return ICE_FEC_STRING_AUTO;
621 return ICE_FEC_STRING_RS;
623 return ICE_FEC_STRING_BASER;
625 return ICE_FEC_STRING_NONE;
626 case ICE_FEC_DIS_AUTO:
627 return ICE_FEC_STRING_DIS_AUTO;
630 /* The compiler generates errors on unhandled enum values if we omit
637 * ice_fc_str - convert flow control mode enum to a string
638 * @mode: the enum value to convert
640 * Convert a flow control mode enum to a string for display in a sysctl or log
641 * message. Returns "Unknown" if the mode is not one of currently supported or
642 * known flow control modes.
645 ice_fc_str(enum ice_fc_mode mode)
649 return ICE_FC_STRING_FULL;
650 case ICE_FC_TX_PAUSE:
651 return ICE_FC_STRING_TX;
652 case ICE_FC_RX_PAUSE:
653 return ICE_FC_STRING_RX;
655 return ICE_FC_STRING_NONE;
662 /* The compiler generates errors on unhandled enum values if we omit
669 * ice_fltr_flag_str - Convert filter flags to a string
670 * @flag: the filter flags to convert
672 * Convert the u16 flag value of a filter into a readable string for
673 * outputting in a sysctl.
676 _ice_fltr_flag_str(u16 flag)
678 struct ice_str_buf buf = { .str = "" };
679 const char *str = NULL;
696 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
698 snprintf(buf.str, ICE_STR_BUF_LEN, "%u", flag);
704 * ice_log_sev_str - Convert log level to a string
705 * @log_level: the log level to convert
707 * Convert the u8 log level of a FW logging module into a readable
708 * string for outputting in a sysctl.
711 _ice_log_sev_str(u8 log_level)
713 struct ice_str_buf buf = { .str = "" };
714 const char *str = NULL;
717 case ICE_FWLOG_LEVEL_NONE:
720 case ICE_FWLOG_LEVEL_ERROR:
723 case ICE_FWLOG_LEVEL_WARNING:
726 case ICE_FWLOG_LEVEL_NORMAL:
729 case ICE_FWLOG_LEVEL_VERBOSE:
737 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
739 snprintf(buf.str, ICE_STR_BUF_LEN, "%u", log_level);
745 * ice_fwd_act_str - convert filter action enum to a string
746 * @action: the filter action to convert
748 * Convert an enum value of type enum ice_sw_fwd_act_type into a string, for
749 * display in a sysctl filter list. Returns "UNKNOWN" for actions outside the
753 ice_fwd_act_str(enum ice_sw_fwd_act_type action)
758 case ICE_FWD_TO_VSI_LIST:
759 return "FWD_TO_VSI_LIST";
762 case ICE_FWD_TO_QGRP:
763 return "FWD_TO_QGRP";
764 case ICE_DROP_PACKET:
765 return "DROP_PACKET";
772 /* The compiler generates errors on unhandled enum values if we omit
779 * ice_mdd_tx_tclan_str - Convert MDD Tx TCLAN event to a string
780 * @event: the MDD event number to convert
782 * Convert the Tx TCLAN event value from the GL_MDET_TX_TCLAN register into
783 * a human readable string for logging of MDD events.
786 _ice_mdd_tx_tclan_str(u8 event)
788 struct ice_str_buf buf = { .str = "" };
789 const char *str = NULL;
793 str = "Wrong descriptor format/order";
796 str = "Descriptor fetch failed";
799 str = "Tail descriptor not EOP/NOP";
802 str = "False scheduling error";
805 str = "Tail value larger than ring len";
808 str = "Too many data commands";
811 str = "Zero packets sent in quanta";
814 str = "Packet too small or too big";
817 str = "TSO length doesn't match sum";
820 str = "TSO tail reached before TLEN";
823 str = "TSO max 3 descs for headers";
826 str = "EOP on header descriptor";
829 str = "MSS is 0 or TLEN is 0";
832 str = "CTX desc invalid IPSec fields";
835 str = "Quanta invalid # of SSO packets";
838 str = "Quanta bytes exceeds pkt_len*64";
841 str = "Quanta exceeds max_cmds_in_sq";
844 str = "incoherent last_lso_quanta";
847 str = "incoherent TSO TLEN";
850 str = "Quanta: too many descriptors";
853 str = "Quanta: # of packets mismatch";
860 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
862 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx TCLAN event %u", event);
868 * ice_mdd_tx_pqm_str - Convert MDD Tx PQM event to a string
869 * @event: the MDD event number to convert
871 * Convert the Tx PQM event value from the GL_MDET_TX_PQM register into
872 * a human readable string for logging of MDD events.
875 _ice_mdd_tx_pqm_str(u8 event)
877 struct ice_str_buf buf = { .str = "" };
878 const char *str = NULL;
882 str = "PCI_DUMMY_COMP";
887 /* Index 2 is unused */
889 str = "RCV_SH_BE_LSO";
892 str = "Q_FL_MNG_EPY_CH";
895 str = "Q_EPY_MNG_FL_CH";
898 str = "LSO_NUMDESCS_ZERO";
901 str = "LSO_LENGTH_ZERO";
904 str = "LSO_MSS_BELOW_MIN";
907 str = "LSO_MSS_ABOVE_MAX";
910 str = "LSO_HDR_SIZE_ZERO";
913 str = "RCV_CNT_BE_LSO";
916 str = "SKIP_ONE_QT_ONLY";
919 str = "LSO_PKTCNT_ZERO";
922 str = "SSO_LENGTH_ZERO";
925 str = "SSO_LENGTH_EXCEED";
928 str = "SSO_PKTCNT_ZERO";
931 str = "SSO_PKTCNT_EXCEED";
934 str = "SSO_NUMDESCS_ZERO";
937 str = "SSO_NUMDESCS_EXCEED";
940 str = "TAIL_GT_RING_LENGTH";
943 str = "RESERVED_DBL_TYPE";
946 str = "ILLEGAL_HEAD_DROP_DBL";
949 str = "LSO_OVER_COMMS_Q";
952 str = "ILLEGAL_VF_QNUM";
955 str = "QTAIL_GT_RING_LENGTH";
962 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
964 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx PQM event %u", event);
970 * ice_mdd_rx_str - Convert MDD Rx queue event to a string
971 * @event: the MDD event number to convert
973 * Convert the Rx queue event value from the GL_MDET_RX register into a human
974 * readable string for logging of MDD events.
977 _ice_mdd_rx_str(u8 event)
979 struct ice_str_buf buf = { .str = "" };
980 const char *str = NULL;
984 str = "Descriptor fetch failed";
991 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
993 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Rx event %u", event);
999 * ice_state_to_str - Convert the state enum to a string value
1000 * @state: the state bit to convert
1002 * Converts a given state bit to its human readable string name. If the enum
1003 * value is unknown, returns NULL;
1006 ice_state_to_str(enum ice_state state)
1009 case ICE_STATE_CONTROLQ_EVENT_PENDING:
1010 return "CONTROLQ_EVENT_PENDING";
1011 case ICE_STATE_VFLR_PENDING:
1012 return "VFLR_PENDING";
1013 case ICE_STATE_MDD_PENDING:
1014 return "MDD_PENDING";
1015 case ICE_STATE_RESET_OICR_RECV:
1016 return "RESET_OICR_RECV";
1017 case ICE_STATE_RESET_PFR_REQ:
1018 return "RESET_PFR_REQ";
1019 case ICE_STATE_PREPARED_FOR_RESET:
1020 return "PREPARED_FOR_RESET";
1021 case ICE_STATE_RESET_FAILED:
1022 return "RESET_FAILED";
1023 case ICE_STATE_DRIVER_INITIALIZED:
1024 return "DRIVER_INITIALIZED";
1025 case ICE_STATE_NO_MEDIA:
1027 case ICE_STATE_RECOVERY_MODE:
1028 return "RECOVERY_MODE";
1029 case ICE_STATE_ROLLBACK_MODE:
1030 return "ROLLBACK_MODE";
1031 case ICE_STATE_LINK_STATUS_REPORTED:
1032 return "LINK_STATUS_REPORTED";
1033 case ICE_STATE_ATTACHING:
1035 case ICE_STATE_DETACHING:
1037 case ICE_STATE_LINK_DEFAULT_OVERRIDE_PENDING:
1038 return "LINK_DEFAULT_OVERRIDE_PENDING";
1039 case ICE_STATE_LLDP_RX_FLTR_FROM_DRIVER:
1040 return "LLDP_RX_FLTR_FROM_DRIVER";
1041 case ICE_STATE_MULTIPLE_TCS:
1042 return "MULTIPLE_TCS";
1043 case ICE_STATE_DO_FW_DEBUG_DUMP:
1044 return "DO_FW_DEBUG_DUMP";
1045 case ICE_STATE_LINK_ACTIVE_ON_DOWN:
1046 return "LINK_ACTIVE_ON_DOWN";
1047 case ICE_STATE_FIRST_INIT_LINK:
1048 return "FIRST_INIT_LINK";
1049 case ICE_STATE_LAST:
1057 * ice_fw_module_str - Convert a FW logging module to a string name
1058 * @module: the module to convert
1060 * Given a FW logging module id, convert it to a shorthand human readable
1061 * name, for generating sysctl tunables.
1064 ice_fw_module_str(enum ice_aqc_fw_logging_mod module)
1067 case ICE_AQC_FW_LOG_ID_GENERAL:
1069 case ICE_AQC_FW_LOG_ID_CTRL:
1071 case ICE_AQC_FW_LOG_ID_LINK:
1073 case ICE_AQC_FW_LOG_ID_LINK_TOPO:
1075 case ICE_AQC_FW_LOG_ID_DNL:
1077 case ICE_AQC_FW_LOG_ID_I2C:
1079 case ICE_AQC_FW_LOG_ID_SDP:
1081 case ICE_AQC_FW_LOG_ID_MDIO:
1083 case ICE_AQC_FW_LOG_ID_ADMINQ:
1085 case ICE_AQC_FW_LOG_ID_HDMA:
1087 case ICE_AQC_FW_LOG_ID_LLDP:
1089 case ICE_AQC_FW_LOG_ID_DCBX:
1091 case ICE_AQC_FW_LOG_ID_DCB:
1093 case ICE_AQC_FW_LOG_ID_XLR:
1095 case ICE_AQC_FW_LOG_ID_NVM:
1097 case ICE_AQC_FW_LOG_ID_AUTH:
1099 case ICE_AQC_FW_LOG_ID_VPD:
1101 case ICE_AQC_FW_LOG_ID_IOSF:
1103 case ICE_AQC_FW_LOG_ID_PARSER:
1105 case ICE_AQC_FW_LOG_ID_SW:
1107 case ICE_AQC_FW_LOG_ID_SCHEDULER:
1109 case ICE_AQC_FW_LOG_ID_TXQ:
1111 case ICE_AQC_FW_LOG_ID_RSVD:
1113 case ICE_AQC_FW_LOG_ID_POST:
1115 case ICE_AQC_FW_LOG_ID_WATCHDOG:
1117 case ICE_AQC_FW_LOG_ID_TASK_DISPATCH:
1118 return "task_dispatch";
1119 case ICE_AQC_FW_LOG_ID_MNG:
1121 case ICE_AQC_FW_LOG_ID_SYNCE:
1123 case ICE_AQC_FW_LOG_ID_HEALTH:
1125 case ICE_AQC_FW_LOG_ID_TSDRV:
1127 case ICE_AQC_FW_LOG_ID_PFREG:
1129 case ICE_AQC_FW_LOG_ID_MDLVER:
1131 case ICE_AQC_FW_LOG_ID_MAX:
1135 /* The compiler generates errors on unhandled enum values if we omit
1142 * ice_fw_lldp_status - Convert FW LLDP status to a string
1143 * @lldp_status: firmware LLDP status value to convert
1145 * Given the FW LLDP status, convert it to a human readable string.
1148 _ice_fw_lldp_status(u32 lldp_status)
1150 struct ice_str_buf buf = { .str = "" };
1151 const char *str = NULL;
1153 switch (lldp_status)
1155 case ICE_LLDP_ADMINSTATUS_DIS:
1158 case ICE_LLDP_ADMINSTATUS_ENA_RX:
1161 case ICE_LLDP_ADMINSTATUS_ENA_TX:
1164 case ICE_LLDP_ADMINSTATUS_ENA_RXTX:
1168 str = "NVM_DEFAULT";
1173 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
1175 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown LLDP status %u", lldp_status);