1 // SPDX-License-Identifier: GPL-2.0
6 static const char tsnep_stats_strings[][ETH_GSTRING_LEN] = {
13 "rx_forwarded_phy_errors",
14 "rx_invalid_frame_errors",
27 u64 rx_forwarded_phy_errors;
28 u64 rx_invalid_frame_errors;
34 #define TSNEP_STATS_COUNT (sizeof(struct tsnep_stats) / sizeof(u64))
36 static const char tsnep_rx_queue_stats_strings[][ETH_GSTRING_LEN] = {
42 "rx_%d_no_descriptor_errors",
43 "rx_%d_buffer_too_small_errors",
44 "rx_%d_fifo_overflow_errors",
45 "rx_%d_invalid_frame_errors",
48 struct tsnep_rx_queue_stats {
54 u64 rx_no_descriptor_errors;
55 u64 rx_buffer_too_small_errors;
56 u64 rx_fifo_overflow_errors;
57 u64 rx_invalid_frame_errors;
60 #define TSNEP_RX_QUEUE_STATS_COUNT (sizeof(struct tsnep_rx_queue_stats) / \
63 static const char tsnep_tx_queue_stats_strings[][ETH_GSTRING_LEN] = {
69 struct tsnep_tx_queue_stats {
75 #define TSNEP_TX_QUEUE_STATS_COUNT (sizeof(struct tsnep_tx_queue_stats) / \
78 static void tsnep_ethtool_get_drvinfo(struct net_device *netdev,
79 struct ethtool_drvinfo *drvinfo)
81 struct tsnep_adapter *adapter = netdev_priv(netdev);
83 strscpy(drvinfo->driver, TSNEP, sizeof(drvinfo->driver));
84 strscpy(drvinfo->bus_info, dev_name(&adapter->pdev->dev),
85 sizeof(drvinfo->bus_info));
88 static int tsnep_ethtool_get_regs_len(struct net_device *netdev)
90 struct tsnep_adapter *adapter = netdev_priv(netdev);
92 int num_additional_queues;
96 /* first queue pair is within TSNEP_MAC_SIZE, only queues additional to
97 * the first queue pair extend the register length by TSNEP_QUEUE_SIZE
99 num_additional_queues =
100 max(adapter->num_tx_queues, adapter->num_rx_queues) - 1;
101 len += TSNEP_QUEUE_SIZE * num_additional_queues;
106 static void tsnep_ethtool_get_regs(struct net_device *netdev,
107 struct ethtool_regs *regs,
110 struct tsnep_adapter *adapter = netdev_priv(netdev);
114 memcpy_fromio(p, adapter->addr, regs->len);
117 static u32 tsnep_ethtool_get_msglevel(struct net_device *netdev)
119 struct tsnep_adapter *adapter = netdev_priv(netdev);
121 return adapter->msg_enable;
124 static void tsnep_ethtool_set_msglevel(struct net_device *netdev, u32 data)
126 struct tsnep_adapter *adapter = netdev_priv(netdev);
128 adapter->msg_enable = data;
131 static void tsnep_ethtool_get_strings(struct net_device *netdev, u32 stringset,
134 struct tsnep_adapter *adapter = netdev_priv(netdev);
135 int rx_count = adapter->num_rx_queues;
136 int tx_count = adapter->num_tx_queues;
141 memcpy(data, tsnep_stats_strings, sizeof(tsnep_stats_strings));
142 data += sizeof(tsnep_stats_strings);
144 for (i = 0; i < rx_count; i++) {
145 for (j = 0; j < TSNEP_RX_QUEUE_STATS_COUNT; j++) {
146 snprintf(data, ETH_GSTRING_LEN,
147 tsnep_rx_queue_stats_strings[j], i);
148 data += ETH_GSTRING_LEN;
152 for (i = 0; i < tx_count; i++) {
153 for (j = 0; j < TSNEP_TX_QUEUE_STATS_COUNT; j++) {
154 snprintf(data, ETH_GSTRING_LEN,
155 tsnep_tx_queue_stats_strings[j], i);
156 data += ETH_GSTRING_LEN;
161 tsnep_ethtool_get_test_strings(data);
166 static void tsnep_ethtool_get_ethtool_stats(struct net_device *netdev,
167 struct ethtool_stats *stats,
170 struct tsnep_adapter *adapter = netdev_priv(netdev);
171 int rx_count = adapter->num_rx_queues;
172 int tx_count = adapter->num_tx_queues;
173 struct tsnep_stats tsnep_stats;
174 struct tsnep_rx_queue_stats tsnep_rx_queue_stats;
175 struct tsnep_tx_queue_stats tsnep_tx_queue_stats;
179 memset(&tsnep_stats, 0, sizeof(tsnep_stats));
180 for (i = 0; i < adapter->num_rx_queues; i++) {
181 tsnep_stats.rx_packets += adapter->rx[i].packets;
182 tsnep_stats.rx_bytes += adapter->rx[i].bytes;
183 tsnep_stats.rx_dropped += adapter->rx[i].dropped;
184 tsnep_stats.rx_multicast += adapter->rx[i].multicast;
185 tsnep_stats.rx_alloc_failed += adapter->rx[i].alloc_failed;
187 reg = ioread32(adapter->addr + ECM_STAT);
188 tsnep_stats.rx_phy_errors =
189 (reg & ECM_STAT_RX_ERR_MASK) >> ECM_STAT_RX_ERR_SHIFT;
190 tsnep_stats.rx_forwarded_phy_errors =
191 (reg & ECM_STAT_FWD_RX_ERR_MASK) >> ECM_STAT_FWD_RX_ERR_SHIFT;
192 tsnep_stats.rx_invalid_frame_errors =
193 (reg & ECM_STAT_INV_FRM_MASK) >> ECM_STAT_INV_FRM_SHIFT;
194 for (i = 0; i < adapter->num_tx_queues; i++) {
195 tsnep_stats.tx_packets += adapter->tx[i].packets;
196 tsnep_stats.tx_bytes += adapter->tx[i].bytes;
197 tsnep_stats.tx_dropped += adapter->tx[i].dropped;
199 memcpy(data, &tsnep_stats, sizeof(tsnep_stats));
200 data += TSNEP_STATS_COUNT;
202 for (i = 0; i < rx_count; i++) {
203 memset(&tsnep_rx_queue_stats, 0, sizeof(tsnep_rx_queue_stats));
204 tsnep_rx_queue_stats.rx_packets = adapter->rx[i].packets;
205 tsnep_rx_queue_stats.rx_bytes = adapter->rx[i].bytes;
206 tsnep_rx_queue_stats.rx_dropped = adapter->rx[i].dropped;
207 tsnep_rx_queue_stats.rx_multicast = adapter->rx[i].multicast;
208 tsnep_rx_queue_stats.rx_alloc_failed =
209 adapter->rx[i].alloc_failed;
210 reg = ioread32(adapter->addr + TSNEP_QUEUE(i) +
212 tsnep_rx_queue_stats.rx_no_descriptor_errors =
213 (reg & TSNEP_RX_STATISTIC_NO_DESC_MASK) >>
214 TSNEP_RX_STATISTIC_NO_DESC_SHIFT;
215 tsnep_rx_queue_stats.rx_buffer_too_small_errors =
216 (reg & TSNEP_RX_STATISTIC_BUFFER_TOO_SMALL_MASK) >>
217 TSNEP_RX_STATISTIC_BUFFER_TOO_SMALL_SHIFT;
218 tsnep_rx_queue_stats.rx_fifo_overflow_errors =
219 (reg & TSNEP_RX_STATISTIC_FIFO_OVERFLOW_MASK) >>
220 TSNEP_RX_STATISTIC_FIFO_OVERFLOW_SHIFT;
221 tsnep_rx_queue_stats.rx_invalid_frame_errors =
222 (reg & TSNEP_RX_STATISTIC_INVALID_FRAME_MASK) >>
223 TSNEP_RX_STATISTIC_INVALID_FRAME_SHIFT;
224 memcpy(data, &tsnep_rx_queue_stats,
225 sizeof(tsnep_rx_queue_stats));
226 data += TSNEP_RX_QUEUE_STATS_COUNT;
229 for (i = 0; i < tx_count; i++) {
230 memset(&tsnep_tx_queue_stats, 0, sizeof(tsnep_tx_queue_stats));
231 tsnep_tx_queue_stats.tx_packets += adapter->tx[i].packets;
232 tsnep_tx_queue_stats.tx_bytes += adapter->tx[i].bytes;
233 tsnep_tx_queue_stats.tx_dropped += adapter->tx[i].dropped;
234 memcpy(data, &tsnep_tx_queue_stats,
235 sizeof(tsnep_tx_queue_stats));
236 data += TSNEP_TX_QUEUE_STATS_COUNT;
240 static int tsnep_ethtool_get_sset_count(struct net_device *netdev, int sset)
242 struct tsnep_adapter *adapter = netdev_priv(netdev);
248 rx_count = adapter->num_rx_queues;
249 tx_count = adapter->num_tx_queues;
250 return TSNEP_STATS_COUNT +
251 TSNEP_RX_QUEUE_STATS_COUNT * rx_count +
252 TSNEP_TX_QUEUE_STATS_COUNT * tx_count;
254 return tsnep_ethtool_get_test_count();
260 static int tsnep_ethtool_get_rxnfc(struct net_device *netdev,
261 struct ethtool_rxnfc *cmd, u32 *rule_locs)
263 struct tsnep_adapter *adapter = netdev_priv(netdev);
266 case ETHTOOL_GRXRINGS:
267 cmd->data = adapter->num_rx_queues;
269 case ETHTOOL_GRXCLSRLCNT:
270 cmd->rule_cnt = adapter->rxnfc_count;
271 cmd->data = adapter->rxnfc_max;
272 cmd->data |= RX_CLS_LOC_SPECIAL;
274 case ETHTOOL_GRXCLSRULE:
275 return tsnep_rxnfc_get_rule(adapter, cmd);
276 case ETHTOOL_GRXCLSRLALL:
277 return tsnep_rxnfc_get_all(adapter, cmd, rule_locs);
283 static int tsnep_ethtool_set_rxnfc(struct net_device *netdev,
284 struct ethtool_rxnfc *cmd)
286 struct tsnep_adapter *adapter = netdev_priv(netdev);
289 case ETHTOOL_SRXCLSRLINS:
290 return tsnep_rxnfc_add_rule(adapter, cmd);
291 case ETHTOOL_SRXCLSRLDEL:
292 return tsnep_rxnfc_del_rule(adapter, cmd);
298 static void tsnep_ethtool_get_channels(struct net_device *netdev,
299 struct ethtool_channels *ch)
301 struct tsnep_adapter *adapter = netdev_priv(netdev);
303 ch->max_combined = adapter->num_queues;
304 ch->combined_count = adapter->num_queues;
307 static int tsnep_ethtool_get_ts_info(struct net_device *netdev,
308 struct kernel_ethtool_ts_info *info)
310 struct tsnep_adapter *adapter = netdev_priv(netdev);
312 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
313 SOF_TIMESTAMPING_TX_HARDWARE |
314 SOF_TIMESTAMPING_RX_HARDWARE |
315 SOF_TIMESTAMPING_RAW_HARDWARE;
317 if (adapter->ptp_clock)
318 info->phc_index = ptp_clock_index(adapter->ptp_clock);
320 info->tx_types = BIT(HWTSTAMP_TX_OFF) |
322 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
323 BIT(HWTSTAMP_FILTER_ALL);
328 static struct tsnep_queue *tsnep_get_queue_with_tx(struct tsnep_adapter *adapter,
333 for (i = 0; i < adapter->num_queues; i++) {
334 if (adapter->queue[i].tx) {
336 return &adapter->queue[i];
345 static struct tsnep_queue *tsnep_get_queue_with_rx(struct tsnep_adapter *adapter,
350 for (i = 0; i < adapter->num_queues; i++) {
351 if (adapter->queue[i].rx) {
353 return &adapter->queue[i];
362 static int tsnep_ethtool_get_coalesce(struct net_device *netdev,
363 struct ethtool_coalesce *ec,
364 struct kernel_ethtool_coalesce *kernel_coal,
365 struct netlink_ext_ack *extack)
367 struct tsnep_adapter *adapter = netdev_priv(netdev);
368 struct tsnep_queue *queue;
370 queue = tsnep_get_queue_with_rx(adapter, 0);
372 ec->rx_coalesce_usecs = tsnep_get_irq_coalesce(queue);
374 queue = tsnep_get_queue_with_tx(adapter, 0);
376 ec->tx_coalesce_usecs = tsnep_get_irq_coalesce(queue);
381 static int tsnep_ethtool_set_coalesce(struct net_device *netdev,
382 struct ethtool_coalesce *ec,
383 struct kernel_ethtool_coalesce *kernel_coal,
384 struct netlink_ext_ack *extack)
386 struct tsnep_adapter *adapter = netdev_priv(netdev);
390 for (i = 0; i < adapter->num_queues; i++) {
391 /* RX coalesce has priority for queues with TX and RX */
392 if (adapter->queue[i].rx)
393 retval = tsnep_set_irq_coalesce(&adapter->queue[i],
394 ec->rx_coalesce_usecs);
396 retval = tsnep_set_irq_coalesce(&adapter->queue[i],
397 ec->tx_coalesce_usecs);
405 static int tsnep_ethtool_get_per_queue_coalesce(struct net_device *netdev,
407 struct ethtool_coalesce *ec)
409 struct tsnep_adapter *adapter = netdev_priv(netdev);
410 struct tsnep_queue *queue_with_rx;
411 struct tsnep_queue *queue_with_tx;
413 if (queue >= max(adapter->num_tx_queues, adapter->num_rx_queues))
416 queue_with_rx = tsnep_get_queue_with_rx(adapter, queue);
418 ec->rx_coalesce_usecs = tsnep_get_irq_coalesce(queue_with_rx);
420 queue_with_tx = tsnep_get_queue_with_tx(adapter, queue);
422 ec->tx_coalesce_usecs = tsnep_get_irq_coalesce(queue_with_tx);
427 static int tsnep_ethtool_set_per_queue_coalesce(struct net_device *netdev,
429 struct ethtool_coalesce *ec)
431 struct tsnep_adapter *adapter = netdev_priv(netdev);
432 struct tsnep_queue *queue_with_rx;
433 struct tsnep_queue *queue_with_tx;
436 if (queue >= max(adapter->num_tx_queues, adapter->num_rx_queues))
439 queue_with_rx = tsnep_get_queue_with_rx(adapter, queue);
441 retval = tsnep_set_irq_coalesce(queue_with_rx, ec->rx_coalesce_usecs);
446 /* RX coalesce has priority for queues with TX and RX */
447 queue_with_tx = tsnep_get_queue_with_tx(adapter, queue);
448 if (queue_with_tx && !queue_with_tx->rx) {
449 retval = tsnep_set_irq_coalesce(queue_with_tx, ec->tx_coalesce_usecs);
457 const struct ethtool_ops tsnep_ethtool_ops = {
458 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
459 .get_drvinfo = tsnep_ethtool_get_drvinfo,
460 .get_regs_len = tsnep_ethtool_get_regs_len,
461 .get_regs = tsnep_ethtool_get_regs,
462 .get_msglevel = tsnep_ethtool_get_msglevel,
463 .set_msglevel = tsnep_ethtool_set_msglevel,
464 .nway_reset = phy_ethtool_nway_reset,
465 .get_link = ethtool_op_get_link,
466 .self_test = tsnep_ethtool_self_test,
467 .get_strings = tsnep_ethtool_get_strings,
468 .get_ethtool_stats = tsnep_ethtool_get_ethtool_stats,
469 .get_sset_count = tsnep_ethtool_get_sset_count,
470 .get_rxnfc = tsnep_ethtool_get_rxnfc,
471 .set_rxnfc = tsnep_ethtool_set_rxnfc,
472 .get_channels = tsnep_ethtool_get_channels,
473 .get_ts_info = tsnep_ethtool_get_ts_info,
474 .get_coalesce = tsnep_ethtool_get_coalesce,
475 .set_coalesce = tsnep_ethtool_set_coalesce,
476 .get_per_queue_coalesce = tsnep_ethtool_get_per_queue_coalesce,
477 .set_per_queue_coalesce = tsnep_ethtool_set_per_queue_coalesce,
478 .get_link_ksettings = phy_ethtool_get_link_ksettings,
479 .set_link_ksettings = phy_ethtool_set_link_ksettings,