cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

spider_net_ethtool.c (4733B)


      1// SPDX-License-Identifier: GPL-2.0-or-later
      2/*
      3 * Network device driver for Cell Processor-Based Blade
      4 *
      5 * (C) Copyright IBM Corp. 2005
      6 *
      7 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
      8 *           Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
      9 */
     10
     11#include <linux/netdevice.h>
     12#include <linux/ethtool.h>
     13#include <linux/pci.h>
     14
     15#include "spider_net.h"
     16
     17
     18static struct {
     19	const char str[ETH_GSTRING_LEN];
     20} ethtool_stats_keys[] = {
     21	{ "tx_packets" },
     22	{ "tx_bytes" },
     23	{ "rx_packets" },
     24	{ "rx_bytes" },
     25	{ "tx_errors" },
     26	{ "tx_dropped" },
     27	{ "rx_dropped" },
     28	{ "rx_descriptor_error" },
     29	{ "tx_timeouts" },
     30	{ "alloc_rx_skb_error" },
     31	{ "rx_iommu_map_error" },
     32	{ "tx_iommu_map_error" },
     33	{ "rx_desc_unk_state" },
     34};
     35
     36static int
     37spider_net_ethtool_get_link_ksettings(struct net_device *netdev,
     38				      struct ethtool_link_ksettings *cmd)
     39{
     40	struct spider_net_card *card;
     41	card = netdev_priv(netdev);
     42
     43	ethtool_link_ksettings_zero_link_mode(cmd, supported);
     44	ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full);
     45	ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
     46
     47	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
     48	ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full);
     49	ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
     50
     51	cmd->base.port = PORT_FIBRE;
     52	cmd->base.speed = card->phy.speed;
     53	cmd->base.duplex = DUPLEX_FULL;
     54
     55	return 0;
     56}
     57
     58static void
     59spider_net_ethtool_get_drvinfo(struct net_device *netdev,
     60			       struct ethtool_drvinfo *drvinfo)
     61{
     62	struct spider_net_card *card;
     63	card = netdev_priv(netdev);
     64
     65	/* clear and fill out info */
     66	strlcpy(drvinfo->driver, spider_net_driver_name,
     67		sizeof(drvinfo->driver));
     68	strlcpy(drvinfo->version, VERSION, sizeof(drvinfo->version));
     69	strlcpy(drvinfo->fw_version, "no information",
     70		sizeof(drvinfo->fw_version));
     71	strlcpy(drvinfo->bus_info, pci_name(card->pdev),
     72		sizeof(drvinfo->bus_info));
     73}
     74
     75static void
     76spider_net_ethtool_get_wol(struct net_device *netdev,
     77			   struct ethtool_wolinfo *wolinfo)
     78{
     79	/* no support for wol */
     80	wolinfo->supported = 0;
     81	wolinfo->wolopts = 0;
     82}
     83
     84static u32
     85spider_net_ethtool_get_msglevel(struct net_device *netdev)
     86{
     87	struct spider_net_card *card;
     88	card = netdev_priv(netdev);
     89	return card->msg_enable;
     90}
     91
     92static void
     93spider_net_ethtool_set_msglevel(struct net_device *netdev,
     94				u32 level)
     95{
     96	struct spider_net_card *card;
     97	card = netdev_priv(netdev);
     98	card->msg_enable = level;
     99}
    100
    101static int
    102spider_net_ethtool_nway_reset(struct net_device *netdev)
    103{
    104	if (netif_running(netdev)) {
    105		spider_net_stop(netdev);
    106		spider_net_open(netdev);
    107	}
    108	return 0;
    109}
    110
    111static void
    112spider_net_ethtool_get_ringparam(struct net_device *netdev,
    113				 struct ethtool_ringparam *ering,
    114				 struct kernel_ethtool_ringparam *kernel_ering,
    115				 struct netlink_ext_ack *extack)
    116{
    117	struct spider_net_card *card = netdev_priv(netdev);
    118
    119	ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX;
    120	ering->tx_pending = card->tx_chain.num_desc;
    121	ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX;
    122	ering->rx_pending = card->rx_chain.num_desc;
    123}
    124
    125static int spider_net_get_sset_count(struct net_device *netdev, int sset)
    126{
    127	switch (sset) {
    128	case ETH_SS_STATS:
    129		return ARRAY_SIZE(ethtool_stats_keys);
    130	default:
    131		return -EOPNOTSUPP;
    132	}
    133}
    134
    135static void spider_net_get_ethtool_stats(struct net_device *netdev,
    136		struct ethtool_stats *stats, u64 *data)
    137{
    138	struct spider_net_card *card = netdev_priv(netdev);
    139
    140	data[0] = netdev->stats.tx_packets;
    141	data[1] = netdev->stats.tx_bytes;
    142	data[2] = netdev->stats.rx_packets;
    143	data[3] = netdev->stats.rx_bytes;
    144	data[4] = netdev->stats.tx_errors;
    145	data[5] = netdev->stats.tx_dropped;
    146	data[6] = netdev->stats.rx_dropped;
    147	data[7] = card->spider_stats.rx_desc_error;
    148	data[8] = card->spider_stats.tx_timeouts;
    149	data[9] = card->spider_stats.alloc_rx_skb_error;
    150	data[10] = card->spider_stats.rx_iommu_map_error;
    151	data[11] = card->spider_stats.tx_iommu_map_error;
    152	data[12] = card->spider_stats.rx_desc_unk_state;
    153}
    154
    155static void spider_net_get_strings(struct net_device *netdev, u32 stringset,
    156				   u8 *data)
    157{
    158	memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
    159}
    160
    161const struct ethtool_ops spider_net_ethtool_ops = {
    162	.get_drvinfo		= spider_net_ethtool_get_drvinfo,
    163	.get_wol		= spider_net_ethtool_get_wol,
    164	.get_msglevel		= spider_net_ethtool_get_msglevel,
    165	.set_msglevel		= spider_net_ethtool_set_msglevel,
    166	.get_link		= ethtool_op_get_link,
    167	.nway_reset		= spider_net_ethtool_nway_reset,
    168	.get_ringparam          = spider_net_ethtool_get_ringparam,
    169	.get_strings		= spider_net_get_strings,
    170	.get_sset_count		= spider_net_get_sset_count,
    171	.get_ethtool_stats	= spider_net_get_ethtool_stats,
    172	.get_link_ksettings	= spider_net_ethtool_get_link_ksettings,
    173};
    174