1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2014-2016 Freescale Semiconductor Inc.
6 #include <linux/net_tstamp.h>
8 #include "dpni.h" /* DPNI_LINK_OPT_* */
11 /* To be kept in sync with DPNI statistics */
12 static char dpaa2_ethtool_stats[][ETH_GSTRING_LEN] = {
15 "[hw] rx mcast frames",
16 "[hw] rx mcast bytes",
17 "[hw] rx bcast frames",
18 "[hw] rx bcast bytes",
21 "[hw] tx mcast frames",
22 "[hw] tx mcast bytes",
23 "[hw] tx bcast frames",
24 "[hw] tx bcast bytes",
25 "[hw] rx filtered frames",
26 "[hw] rx discarded frames",
27 "[hw] rx nobuffer discards",
28 "[hw] tx discarded frames",
29 "[hw] tx confirmed frames",
32 #define DPAA2_ETH_NUM_STATS ARRAY_SIZE(dpaa2_ethtool_stats)
34 static char dpaa2_ethtool_extras[][ETH_GSTRING_LEN] = {
36 "[drv] tx conf frames",
37 "[drv] tx conf bytes",
40 "[drv] tx realloc frames",
43 "[drv] enqueue portal busy",
45 "[drv] dequeue portal busy",
46 "[drv] channel pull errors",
50 #define DPAA2_ETH_NUM_EXTRA_STATS ARRAY_SIZE(dpaa2_ethtool_extras)
52 static void dpaa2_eth_get_drvinfo(struct net_device *net_dev,
53 struct ethtool_drvinfo *drvinfo)
55 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
57 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
59 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
60 "%u.%u", priv->dpni_ver_major, priv->dpni_ver_minor);
62 strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent),
63 sizeof(drvinfo->bus_info));
67 dpaa2_eth_get_link_ksettings(struct net_device *net_dev,
68 struct ethtool_link_ksettings *link_settings)
70 struct dpni_link_state state = {0};
72 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
74 err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state);
76 netdev_err(net_dev, "ERROR %d getting link state\n", err);
80 /* At the moment, we have no way of interrogating the DPMAC
81 * from the DPNI side - and for that matter there may exist
82 * no DPMAC at all. So for now we just don't report anything
83 * beyond the DPNI attributes.
85 if (state.options & DPNI_LINK_OPT_AUTONEG)
86 link_settings->base.autoneg = AUTONEG_ENABLE;
87 if (!(state.options & DPNI_LINK_OPT_HALF_DUPLEX))
88 link_settings->base.duplex = DUPLEX_FULL;
89 link_settings->base.speed = state.rate;
95 #define DPNI_DYNAMIC_LINK_SET_VER_MAJOR 7
96 #define DPNI_DYNAMIC_LINK_SET_VER_MINOR 1
98 dpaa2_eth_set_link_ksettings(struct net_device *net_dev,
99 const struct ethtool_link_ksettings *link_settings)
101 struct dpni_link_cfg cfg = {0};
102 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
105 /* If using an older MC version, the DPNI must be down
106 * in order to be able to change link settings. Taking steps to let
107 * the user know that.
109 if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_DYNAMIC_LINK_SET_VER_MAJOR,
110 DPNI_DYNAMIC_LINK_SET_VER_MINOR) < 0) {
111 if (netif_running(net_dev)) {
112 netdev_info(net_dev, "Interface must be brought down first.\n");
117 cfg.rate = link_settings->base.speed;
118 if (link_settings->base.autoneg == AUTONEG_ENABLE)
119 cfg.options |= DPNI_LINK_OPT_AUTONEG;
121 cfg.options &= ~DPNI_LINK_OPT_AUTONEG;
122 if (link_settings->base.duplex == DUPLEX_HALF)
123 cfg.options |= DPNI_LINK_OPT_HALF_DUPLEX;
125 cfg.options &= ~DPNI_LINK_OPT_HALF_DUPLEX;
127 err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &cfg);
129 /* ethtool will be loud enough if we return an error; no point
130 * in putting our own error message on the console by default
132 netdev_dbg(net_dev, "ERROR %d setting link cfg\n", err);
137 static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset,
145 for (i = 0; i < DPAA2_ETH_NUM_STATS; i++) {
146 strlcpy(p, dpaa2_ethtool_stats[i], ETH_GSTRING_LEN);
147 p += ETH_GSTRING_LEN;
149 for (i = 0; i < DPAA2_ETH_NUM_EXTRA_STATS; i++) {
150 strlcpy(p, dpaa2_ethtool_extras[i], ETH_GSTRING_LEN);
151 p += ETH_GSTRING_LEN;
157 static int dpaa2_eth_get_sset_count(struct net_device *net_dev, int sset)
160 case ETH_SS_STATS: /* ethtool_get_stats(), ethtool_get_drvinfo() */
161 return DPAA2_ETH_NUM_STATS + DPAA2_ETH_NUM_EXTRA_STATS;
167 /** Fill in hardware counters, as returned by MC.
169 static void dpaa2_eth_get_ethtool_stats(struct net_device *net_dev,
170 struct ethtool_stats *stats,
176 union dpni_statistics dpni_stats;
178 u64 portal_busy = 0, pull_err = 0;
179 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
180 struct dpaa2_eth_drv_stats *extras;
181 struct dpaa2_eth_ch_stats *ch_stats;
184 sizeof(u64) * (DPAA2_ETH_NUM_STATS + DPAA2_ETH_NUM_EXTRA_STATS));
186 /* Print standard counters, from DPNI statistics */
187 for (j = 0; j <= 2; j++) {
188 err = dpni_get_statistics(priv->mc_io, 0, priv->mc_token,
191 netdev_warn(net_dev, "dpni_get_stats(%d) failed\n", j);
194 num_cnt = sizeof(dpni_stats.page_0) / sizeof(u64);
197 num_cnt = sizeof(dpni_stats.page_1) / sizeof(u64);
200 num_cnt = sizeof(dpni_stats.page_2) / sizeof(u64);
203 for (k = 0; k < num_cnt; k++)
204 *(data + i++) = dpni_stats.raw.counter[k];
207 /* Print per-cpu extra stats */
208 for_each_online_cpu(k) {
209 extras = per_cpu_ptr(priv->percpu_extras, k);
210 for (j = 0; j < sizeof(*extras) / sizeof(__u64); j++)
211 *((__u64 *)data + i + j) += *((__u64 *)extras + j);
215 for (j = 0; j < priv->num_channels; j++) {
216 ch_stats = &priv->channel[j]->stats;
217 cdan += ch_stats->cdan;
218 portal_busy += ch_stats->dequeue_portal_busy;
219 pull_err += ch_stats->pull_err;
222 *(data + i++) = portal_busy;
223 *(data + i++) = pull_err;
224 *(data + i++) = cdan;
227 static int dpaa2_eth_get_rxnfc(struct net_device *net_dev,
228 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
230 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
232 switch (rxnfc->cmd) {
234 /* we purposely ignore cmd->flow_type for now, because the
235 * classifier only supports a single set of fields for all
238 rxnfc->data = priv->rx_hash_fields;
240 case ETHTOOL_GRXRINGS:
241 rxnfc->data = dpaa2_eth_queue_count(priv);
250 int dpaa2_phc_index = -1;
251 EXPORT_SYMBOL(dpaa2_phc_index);
253 static int dpaa2_eth_get_ts_info(struct net_device *dev,
254 struct ethtool_ts_info *info)
256 info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
257 SOF_TIMESTAMPING_RX_HARDWARE |
258 SOF_TIMESTAMPING_RAW_HARDWARE;
260 info->phc_index = dpaa2_phc_index;
262 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
263 (1 << HWTSTAMP_TX_ON);
265 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
266 (1 << HWTSTAMP_FILTER_ALL);
270 const struct ethtool_ops dpaa2_ethtool_ops = {
271 .get_drvinfo = dpaa2_eth_get_drvinfo,
272 .get_link = ethtool_op_get_link,
273 .get_link_ksettings = dpaa2_eth_get_link_ksettings,
274 .set_link_ksettings = dpaa2_eth_set_link_ksettings,
275 .get_sset_count = dpaa2_eth_get_sset_count,
276 .get_ethtool_stats = dpaa2_eth_get_ethtool_stats,
277 .get_strings = dpaa2_eth_get_strings,
278 .get_rxnfc = dpaa2_eth_get_rxnfc,
279 .get_ts_info = dpaa2_eth_get_ts_info,