1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2021, 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;
629 /* The compiler generates errors on unhandled enum values if we omit
636 * ice_fc_str - convert flow control mode enum to a string
637 * @mode: the enum value to convert
639 * Convert a flow control mode enum to a string for display in a sysctl or log
640 * message. Returns "Unknown" if the mode is not one of currently supported or
641 * known flow control modes.
644 ice_fc_str(enum ice_fc_mode mode)
648 return ICE_FC_STRING_FULL;
649 case ICE_FC_TX_PAUSE:
650 return ICE_FC_STRING_TX;
651 case ICE_FC_RX_PAUSE:
652 return ICE_FC_STRING_RX;
654 return ICE_FC_STRING_NONE;
661 /* The compiler generates errors on unhandled enum values if we omit
668 * ice_fltr_flag_str - Convert filter flags to a string
669 * @flag: the filter flags to convert
671 * Convert the u16 flag value of a filter into a readable string for
672 * outputting in a sysctl.
675 _ice_fltr_flag_str(u16 flag)
677 struct ice_str_buf buf = { .str = "" };
678 const char *str = NULL;
695 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
697 snprintf(buf.str, ICE_STR_BUF_LEN, "%u", flag);
703 * ice_fwd_act_str - convert filter action enum to a string
704 * @action: the filter action to convert
706 * Convert an enum value of type enum ice_sw_fwd_act_type into a string, for
707 * display in a sysctl filter list. Returns "UNKNOWN" for actions outside the
711 ice_fwd_act_str(enum ice_sw_fwd_act_type action)
716 case ICE_FWD_TO_VSI_LIST:
717 return "FWD_TO_VSI_LIST";
720 case ICE_FWD_TO_QGRP:
721 return "FWD_TO_QGRP";
722 case ICE_DROP_PACKET:
723 return "DROP_PACKET";
728 /* The compiler generates errors on unhandled enum values if we omit
735 * ice_mdd_tx_tclan_str - Convert MDD Tx TCLAN event to a string
736 * @event: the MDD event number to convert
738 * Convert the Tx TCLAN event value from the GL_MDET_TX_TCLAN register into
739 * a human readable string for logging of MDD events.
742 _ice_mdd_tx_tclan_str(u8 event)
744 struct ice_str_buf buf = { .str = "" };
745 const char *str = NULL;
749 str = "Wrong descriptor format/order";
752 str = "Descriptor fetch failed";
755 str = "Tail descriptor not EOP/NOP";
758 str = "False scheduling error";
761 str = "Tail value larger than ring len";
764 str = "Too many data commands";
767 str = "Zero packets sent in quanta";
770 str = "Packet too small or too big";
773 str = "TSO length doesn't match sum";
776 str = "TSO tail reached before TLEN";
779 str = "TSO max 3 descs for headers";
782 str = "EOP on header descriptor";
785 str = "MSS is 0 or TLEN is 0";
788 str = "CTX desc invalid IPSec fields";
791 str = "Quanta invalid # of SSO packets";
794 str = "Quanta bytes exceeds pkt_len*64";
797 str = "Quanta exceeds max_cmds_in_sq";
800 str = "incoherent last_lso_quanta";
803 str = "incoherent TSO TLEN";
806 str = "Quanta: too many descriptors";
809 str = "Quanta: # of packets mismatch";
816 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
818 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx TCLAN event %u", event);
824 * ice_mdd_tx_pqm_str - Convert MDD Tx PQM event to a string
825 * @event: the MDD event number to convert
827 * Convert the Tx PQM event value from the GL_MDET_TX_PQM register into
828 * a human readable string for logging of MDD events.
831 _ice_mdd_tx_pqm_str(u8 event)
833 struct ice_str_buf buf = { .str = "" };
834 const char *str = NULL;
838 str = "PCI_DUMMY_COMP";
843 /* Index 2 is unused */
845 str = "RCV_SH_BE_LSO";
848 str = "Q_FL_MNG_EPY_CH";
851 str = "Q_EPY_MNG_FL_CH";
854 str = "LSO_NUMDESCS_ZERO";
857 str = "LSO_LENGTH_ZERO";
860 str = "LSO_MSS_BELOW_MIN";
863 str = "LSO_MSS_ABOVE_MAX";
866 str = "LSO_HDR_SIZE_ZERO";
869 str = "RCV_CNT_BE_LSO";
872 str = "SKIP_ONE_QT_ONLY";
875 str = "LSO_PKTCNT_ZERO";
878 str = "SSO_LENGTH_ZERO";
881 str = "SSO_LENGTH_EXCEED";
884 str = "SSO_PKTCNT_ZERO";
887 str = "SSO_PKTCNT_EXCEED";
890 str = "SSO_NUMDESCS_ZERO";
893 str = "SSO_NUMDESCS_EXCEED";
896 str = "TAIL_GT_RING_LENGTH";
899 str = "RESERVED_DBL_TYPE";
902 str = "ILLEGAL_HEAD_DROP_DBL";
905 str = "LSO_OVER_COMMS_Q";
908 str = "ILLEGAL_VF_QNUM";
911 str = "QTAIL_GT_RING_LENGTH";
918 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
920 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Tx PQM event %u", event);
926 * ice_mdd_rx_str - Convert MDD Rx queue event to a string
927 * @event: the MDD event number to convert
929 * Convert the Rx queue event value from the GL_MDET_RX register into a human
930 * readable string for logging of MDD events.
933 _ice_mdd_rx_str(u8 event)
935 struct ice_str_buf buf = { .str = "" };
936 const char *str = NULL;
940 str = "Descriptor fetch failed";
947 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
949 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown Rx event %u", event);
955 * ice_state_to_str - Convert the state enum to a string value
956 * @state: the state bit to convert
958 * Converts a given state bit to its human readable string name. If the enum
959 * value is unknown, returns NULL;
962 ice_state_to_str(enum ice_state state)
965 case ICE_STATE_CONTROLQ_EVENT_PENDING:
966 return "CONTROLQ_EVENT_PENDING";
967 case ICE_STATE_VFLR_PENDING:
968 return "VFLR_PENDING";
969 case ICE_STATE_MDD_PENDING:
970 return "MDD_PENDING";
971 case ICE_STATE_RESET_OICR_RECV:
972 return "RESET_OICR_RECV";
973 case ICE_STATE_RESET_PFR_REQ:
974 return "RESET_PFR_REQ";
975 case ICE_STATE_PREPARED_FOR_RESET:
976 return "PREPARED_FOR_RESET";
977 case ICE_STATE_RESET_FAILED:
978 return "RESET_FAILED";
979 case ICE_STATE_DRIVER_INITIALIZED:
980 return "DRIVER_INITIALIZED";
981 case ICE_STATE_NO_MEDIA:
983 case ICE_STATE_RECOVERY_MODE:
984 return "RECOVERY_MODE";
985 case ICE_STATE_ROLLBACK_MODE:
986 return "ROLLBACK_MODE";
987 case ICE_STATE_LINK_STATUS_REPORTED:
988 return "LINK_STATUS_REPORTED";
989 case ICE_STATE_DETACHING:
991 case ICE_STATE_LINK_DEFAULT_OVERRIDE_PENDING:
992 return "LINK_DEFAULT_OVERRIDE_PENDING";
993 case ICE_STATE_LLDP_RX_FLTR_FROM_DRIVER:
994 return "LLDP_RX_FLTR_FROM_DRIVER";
1003 * ice_fw_lldp_status - Convert FW LLDP status to a string
1004 * @lldp_status: firmware LLDP status value to convert
1006 * Given the FW LLDP status, convert it to a human readable string.
1009 _ice_fw_lldp_status(u32 lldp_status)
1011 struct ice_str_buf buf = { .str = "" };
1012 const char *str = NULL;
1014 switch (lldp_status)
1016 case ICE_LLDP_ADMINSTATUS_DIS:
1019 case ICE_LLDP_ADMINSTATUS_ENA_RX:
1022 case ICE_LLDP_ADMINSTATUS_ENA_TX:
1025 case ICE_LLDP_ADMINSTATUS_ENA_RXTX:
1029 str = "NVM_DEFAULT";
1034 snprintf(buf.str, ICE_STR_BUF_LEN, "%s", str);
1036 snprintf(buf.str, ICE_STR_BUF_LEN, "Unknown LLDP status %u", lldp_status);