18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2006-2008 PA Semi, Inc 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Ethtool hooks for the PA Semi PWRficient onchip 1G/10G Ethernet MACs 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 108c2ecf20Sopenharmony_ci#include <linux/ethtool.h> 118c2ecf20Sopenharmony_ci#include <linux/pci.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <asm/pasemi_dma.h> 148c2ecf20Sopenharmony_ci#include "pasemi_mac.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistatic struct { 178c2ecf20Sopenharmony_ci const char str[ETH_GSTRING_LEN]; 188c2ecf20Sopenharmony_ci} ethtool_stats_keys[] = { 198c2ecf20Sopenharmony_ci { "rx-drops" }, 208c2ecf20Sopenharmony_ci { "rx-bytes" }, 218c2ecf20Sopenharmony_ci { "rx-packets" }, 228c2ecf20Sopenharmony_ci { "rx-broadcast-packets" }, 238c2ecf20Sopenharmony_ci { "rx-multicast-packets" }, 248c2ecf20Sopenharmony_ci { "rx-crc-errors" }, 258c2ecf20Sopenharmony_ci { "rx-undersize-errors" }, 268c2ecf20Sopenharmony_ci { "rx-oversize-errors" }, 278c2ecf20Sopenharmony_ci { "rx-short-fragment-errors" }, 288c2ecf20Sopenharmony_ci { "rx-jabber-errors" }, 298c2ecf20Sopenharmony_ci { "rx-64-byte-packets" }, 308c2ecf20Sopenharmony_ci { "rx-65-127-byte-packets" }, 318c2ecf20Sopenharmony_ci { "rx-128-255-byte-packets" }, 328c2ecf20Sopenharmony_ci { "rx-256-511-byte-packets" }, 338c2ecf20Sopenharmony_ci { "rx-512-1023-byte-packets" }, 348c2ecf20Sopenharmony_ci { "rx-1024-1518-byte-packets" }, 358c2ecf20Sopenharmony_ci { "rx-pause-frames" }, 368c2ecf20Sopenharmony_ci { "tx-bytes" }, 378c2ecf20Sopenharmony_ci { "tx-packets" }, 388c2ecf20Sopenharmony_ci { "tx-broadcast-packets" }, 398c2ecf20Sopenharmony_ci { "tx-multicast-packets" }, 408c2ecf20Sopenharmony_ci { "tx-collisions" }, 418c2ecf20Sopenharmony_ci { "tx-late-collisions" }, 428c2ecf20Sopenharmony_ci { "tx-excessive-collisions" }, 438c2ecf20Sopenharmony_ci { "tx-crc-errors" }, 448c2ecf20Sopenharmony_ci { "tx-undersize-errors" }, 458c2ecf20Sopenharmony_ci { "tx-oversize-errors" }, 468c2ecf20Sopenharmony_ci { "tx-64-byte-packets" }, 478c2ecf20Sopenharmony_ci { "tx-65-127-byte-packets" }, 488c2ecf20Sopenharmony_ci { "tx-128-255-byte-packets" }, 498c2ecf20Sopenharmony_ci { "tx-256-511-byte-packets" }, 508c2ecf20Sopenharmony_ci { "tx-512-1023-byte-packets" }, 518c2ecf20Sopenharmony_ci { "tx-1024-1518-byte-packets" }, 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic u32 558c2ecf20Sopenharmony_cipasemi_mac_ethtool_get_msglevel(struct net_device *netdev) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci struct pasemi_mac *mac = netdev_priv(netdev); 588c2ecf20Sopenharmony_ci return mac->msg_enable; 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic void 628c2ecf20Sopenharmony_cipasemi_mac_ethtool_set_msglevel(struct net_device *netdev, 638c2ecf20Sopenharmony_ci u32 level) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci struct pasemi_mac *mac = netdev_priv(netdev); 668c2ecf20Sopenharmony_ci mac->msg_enable = level; 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic void 718c2ecf20Sopenharmony_cipasemi_mac_ethtool_get_ringparam(struct net_device *netdev, 728c2ecf20Sopenharmony_ci struct ethtool_ringparam *ering) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci struct pasemi_mac *mac = netdev_priv(netdev); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci ering->tx_max_pending = TX_RING_SIZE/2; 778c2ecf20Sopenharmony_ci ering->tx_pending = RING_USED(mac->tx)/2; 788c2ecf20Sopenharmony_ci ering->rx_max_pending = RX_RING_SIZE/4; 798c2ecf20Sopenharmony_ci ering->rx_pending = RING_USED(mac->rx)/4; 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic int pasemi_mac_get_sset_count(struct net_device *netdev, int sset) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci switch (sset) { 858c2ecf20Sopenharmony_ci case ETH_SS_STATS: 868c2ecf20Sopenharmony_ci return ARRAY_SIZE(ethtool_stats_keys); 878c2ecf20Sopenharmony_ci default: 888c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 898c2ecf20Sopenharmony_ci } 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic void pasemi_mac_get_ethtool_stats(struct net_device *netdev, 938c2ecf20Sopenharmony_ci struct ethtool_stats *stats, u64 *data) 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci struct pasemi_mac *mac = netdev_priv(netdev); 968c2ecf20Sopenharmony_ci int i; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if)) 998c2ecf20Sopenharmony_ci >> PAS_DMA_RXINT_RCMDSTA_DROPS_S; 1008c2ecf20Sopenharmony_ci for (i = 0; i < 32; i++) 1018c2ecf20Sopenharmony_ci data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i)); 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset, 1058c2ecf20Sopenharmony_ci u8 *data) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys)); 1088c2ecf20Sopenharmony_ci} 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ciconst struct ethtool_ops pasemi_mac_ethtool_ops = { 1118c2ecf20Sopenharmony_ci .get_msglevel = pasemi_mac_ethtool_get_msglevel, 1128c2ecf20Sopenharmony_ci .set_msglevel = pasemi_mac_ethtool_set_msglevel, 1138c2ecf20Sopenharmony_ci .get_link = ethtool_op_get_link, 1148c2ecf20Sopenharmony_ci .get_ringparam = pasemi_mac_ethtool_get_ringparam, 1158c2ecf20Sopenharmony_ci .get_strings = pasemi_mac_get_strings, 1168c2ecf20Sopenharmony_ci .get_sset_count = pasemi_mac_get_sset_count, 1178c2ecf20Sopenharmony_ci .get_ethtool_stats = pasemi_mac_get_ethtool_stats, 1188c2ecf20Sopenharmony_ci .get_link_ksettings = phy_ethtool_get_link_ksettings, 1198c2ecf20Sopenharmony_ci .set_link_ksettings = phy_ethtool_set_link_ksettings, 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 122