0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <linux/ethtool.h>
0019 #include <linux/kernel.h>
0020 #include <linux/netdevice.h>
0021
0022 #include "dwc-xlgmac.h"
0023 #include "dwc-xlgmac-reg.h"
0024
0025 struct xlgmac_stats_desc {
0026 char stat_string[ETH_GSTRING_LEN];
0027 int stat_offset;
0028 };
0029
0030 #define XLGMAC_STAT(str, var) \
0031 { \
0032 str, \
0033 offsetof(struct xlgmac_pdata, stats.var), \
0034 }
0035
0036 static const struct xlgmac_stats_desc xlgmac_gstring_stats[] = {
0037
0038 XLGMAC_STAT("tx_bytes", txoctetcount_gb),
0039 XLGMAC_STAT("tx_bytes_good", txoctetcount_g),
0040 XLGMAC_STAT("tx_packets", txframecount_gb),
0041 XLGMAC_STAT("tx_packets_good", txframecount_g),
0042 XLGMAC_STAT("tx_unicast_packets", txunicastframes_gb),
0043 XLGMAC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
0044 XLGMAC_STAT("tx_broadcast_packets_good", txbroadcastframes_g),
0045 XLGMAC_STAT("tx_multicast_packets", txmulticastframes_gb),
0046 XLGMAC_STAT("tx_multicast_packets_good", txmulticastframes_g),
0047 XLGMAC_STAT("tx_vlan_packets_good", txvlanframes_g),
0048 XLGMAC_STAT("tx_64_byte_packets", tx64octets_gb),
0049 XLGMAC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
0050 XLGMAC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
0051 XLGMAC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
0052 XLGMAC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
0053 XLGMAC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
0054 XLGMAC_STAT("tx_underflow_errors", txunderflowerror),
0055 XLGMAC_STAT("tx_pause_frames", txpauseframes),
0056
0057
0058 XLGMAC_STAT("rx_bytes", rxoctetcount_gb),
0059 XLGMAC_STAT("rx_bytes_good", rxoctetcount_g),
0060 XLGMAC_STAT("rx_packets", rxframecount_gb),
0061 XLGMAC_STAT("rx_unicast_packets_good", rxunicastframes_g),
0062 XLGMAC_STAT("rx_broadcast_packets_good", rxbroadcastframes_g),
0063 XLGMAC_STAT("rx_multicast_packets_good", rxmulticastframes_g),
0064 XLGMAC_STAT("rx_vlan_packets", rxvlanframes_gb),
0065 XLGMAC_STAT("rx_64_byte_packets", rx64octets_gb),
0066 XLGMAC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
0067 XLGMAC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
0068 XLGMAC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
0069 XLGMAC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
0070 XLGMAC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
0071 XLGMAC_STAT("rx_undersize_packets_good", rxundersize_g),
0072 XLGMAC_STAT("rx_oversize_packets_good", rxoversize_g),
0073 XLGMAC_STAT("rx_crc_errors", rxcrcerror),
0074 XLGMAC_STAT("rx_crc_errors_small_packets", rxrunterror),
0075 XLGMAC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
0076 XLGMAC_STAT("rx_length_errors", rxlengtherror),
0077 XLGMAC_STAT("rx_out_of_range_errors", rxoutofrangetype),
0078 XLGMAC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
0079 XLGMAC_STAT("rx_watchdog_errors", rxwatchdogerror),
0080 XLGMAC_STAT("rx_pause_frames", rxpauseframes),
0081
0082
0083 XLGMAC_STAT("tx_tso_packets", tx_tso_packets),
0084 XLGMAC_STAT("rx_split_header_packets", rx_split_header_packets),
0085 XLGMAC_STAT("tx_process_stopped", tx_process_stopped),
0086 XLGMAC_STAT("rx_process_stopped", rx_process_stopped),
0087 XLGMAC_STAT("tx_buffer_unavailable", tx_buffer_unavailable),
0088 XLGMAC_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
0089 XLGMAC_STAT("fatal_bus_error", fatal_bus_error),
0090 XLGMAC_STAT("tx_vlan_packets", tx_vlan_packets),
0091 XLGMAC_STAT("rx_vlan_packets", rx_vlan_packets),
0092 XLGMAC_STAT("napi_poll_isr", napi_poll_isr),
0093 XLGMAC_STAT("napi_poll_txtimer", napi_poll_txtimer),
0094 };
0095
0096 #define XLGMAC_STATS_COUNT ARRAY_SIZE(xlgmac_gstring_stats)
0097
0098 static void xlgmac_ethtool_get_drvinfo(struct net_device *netdev,
0099 struct ethtool_drvinfo *drvinfo)
0100 {
0101 struct xlgmac_pdata *pdata = netdev_priv(netdev);
0102 u32 ver = pdata->hw_feat.version;
0103 u32 snpsver, devid, userver;
0104
0105 strlcpy(drvinfo->driver, pdata->drv_name, sizeof(drvinfo->driver));
0106 strlcpy(drvinfo->version, pdata->drv_ver, sizeof(drvinfo->version));
0107 strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
0108 sizeof(drvinfo->bus_info));
0109
0110
0111
0112
0113 snpsver = XLGMAC_GET_REG_BITS(ver, MAC_VR_SNPSVER_POS,
0114 MAC_VR_SNPSVER_LEN);
0115 devid = XLGMAC_GET_REG_BITS(ver, MAC_VR_DEVID_POS,
0116 MAC_VR_DEVID_LEN);
0117 userver = XLGMAC_GET_REG_BITS(ver, MAC_VR_USERVER_POS,
0118 MAC_VR_USERVER_LEN);
0119 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
0120 "S.D.U: %x.%x.%x", snpsver, devid, userver);
0121 }
0122
0123 static u32 xlgmac_ethtool_get_msglevel(struct net_device *netdev)
0124 {
0125 struct xlgmac_pdata *pdata = netdev_priv(netdev);
0126
0127 return pdata->msg_enable;
0128 }
0129
0130 static void xlgmac_ethtool_set_msglevel(struct net_device *netdev,
0131 u32 msglevel)
0132 {
0133 struct xlgmac_pdata *pdata = netdev_priv(netdev);
0134
0135 pdata->msg_enable = msglevel;
0136 }
0137
0138 static void xlgmac_ethtool_get_channels(struct net_device *netdev,
0139 struct ethtool_channels *channel)
0140 {
0141 struct xlgmac_pdata *pdata = netdev_priv(netdev);
0142
0143 channel->max_rx = XLGMAC_MAX_DMA_CHANNELS;
0144 channel->max_tx = XLGMAC_MAX_DMA_CHANNELS;
0145 channel->rx_count = pdata->rx_q_count;
0146 channel->tx_count = pdata->tx_q_count;
0147 }
0148
0149 static int
0150 xlgmac_ethtool_get_coalesce(struct net_device *netdev,
0151 struct ethtool_coalesce *ec,
0152 struct kernel_ethtool_coalesce *kernel_coal,
0153 struct netlink_ext_ack *extack)
0154 {
0155 struct xlgmac_pdata *pdata = netdev_priv(netdev);
0156
0157 ec->rx_coalesce_usecs = pdata->rx_usecs;
0158 ec->rx_max_coalesced_frames = pdata->rx_frames;
0159 ec->tx_max_coalesced_frames = pdata->tx_frames;
0160
0161 return 0;
0162 }
0163
0164 static int
0165 xlgmac_ethtool_set_coalesce(struct net_device *netdev,
0166 struct ethtool_coalesce *ec,
0167 struct kernel_ethtool_coalesce *kernel_coal,
0168 struct netlink_ext_ack *extack)
0169 {
0170 struct xlgmac_pdata *pdata = netdev_priv(netdev);
0171 struct xlgmac_hw_ops *hw_ops = &pdata->hw_ops;
0172 unsigned int rx_frames, rx_riwt, rx_usecs;
0173 unsigned int tx_frames;
0174
0175 rx_usecs = ec->rx_coalesce_usecs;
0176 rx_riwt = hw_ops->usec_to_riwt(pdata, rx_usecs);
0177 rx_frames = ec->rx_max_coalesced_frames;
0178 tx_frames = ec->tx_max_coalesced_frames;
0179
0180 if ((rx_riwt > XLGMAC_MAX_DMA_RIWT) ||
0181 (rx_riwt < XLGMAC_MIN_DMA_RIWT) ||
0182 (rx_frames > pdata->rx_desc_count))
0183 return -EINVAL;
0184
0185 if (tx_frames > pdata->tx_desc_count)
0186 return -EINVAL;
0187
0188 pdata->rx_riwt = rx_riwt;
0189 pdata->rx_usecs = rx_usecs;
0190 pdata->rx_frames = rx_frames;
0191 hw_ops->config_rx_coalesce(pdata);
0192
0193 pdata->tx_frames = tx_frames;
0194 hw_ops->config_tx_coalesce(pdata);
0195
0196 return 0;
0197 }
0198
0199 static void xlgmac_ethtool_get_strings(struct net_device *netdev,
0200 u32 stringset, u8 *data)
0201 {
0202 int i;
0203
0204 switch (stringset) {
0205 case ETH_SS_STATS:
0206 for (i = 0; i < XLGMAC_STATS_COUNT; i++) {
0207 memcpy(data, xlgmac_gstring_stats[i].stat_string,
0208 ETH_GSTRING_LEN);
0209 data += ETH_GSTRING_LEN;
0210 }
0211 break;
0212 default:
0213 WARN_ON(1);
0214 break;
0215 }
0216 }
0217
0218 static int xlgmac_ethtool_get_sset_count(struct net_device *netdev,
0219 int stringset)
0220 {
0221 int ret;
0222
0223 switch (stringset) {
0224 case ETH_SS_STATS:
0225 ret = XLGMAC_STATS_COUNT;
0226 break;
0227
0228 default:
0229 ret = -EOPNOTSUPP;
0230 }
0231
0232 return ret;
0233 }
0234
0235 static void xlgmac_ethtool_get_ethtool_stats(struct net_device *netdev,
0236 struct ethtool_stats *stats,
0237 u64 *data)
0238 {
0239 struct xlgmac_pdata *pdata = netdev_priv(netdev);
0240 u8 *stat;
0241 int i;
0242
0243 pdata->hw_ops.read_mmc_stats(pdata);
0244 for (i = 0; i < XLGMAC_STATS_COUNT; i++) {
0245 stat = (u8 *)pdata + xlgmac_gstring_stats[i].stat_offset;
0246 *data++ = *(u64 *)stat;
0247 }
0248 }
0249
0250 static const struct ethtool_ops xlgmac_ethtool_ops = {
0251 .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
0252 ETHTOOL_COALESCE_MAX_FRAMES,
0253 .get_drvinfo = xlgmac_ethtool_get_drvinfo,
0254 .get_link = ethtool_op_get_link,
0255 .get_msglevel = xlgmac_ethtool_get_msglevel,
0256 .set_msglevel = xlgmac_ethtool_set_msglevel,
0257 .get_channels = xlgmac_ethtool_get_channels,
0258 .get_coalesce = xlgmac_ethtool_get_coalesce,
0259 .set_coalesce = xlgmac_ethtool_set_coalesce,
0260 .get_strings = xlgmac_ethtool_get_strings,
0261 .get_sset_count = xlgmac_ethtool_get_sset_count,
0262 .get_ethtool_stats = xlgmac_ethtool_get_ethtool_stats,
0263 };
0264
0265 const struct ethtool_ops *xlgmac_get_ethtool_ops(void)
0266 {
0267 return &xlgmac_ethtool_ops;
0268 }