0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 #include <linux/ethtool.h>
0053
0054 #include "opa_vnic_internal.h"
0055
0056 enum {NETDEV_STATS, VNIC_STATS};
0057
0058 struct vnic_stats {
0059 char stat_string[ETH_GSTRING_LEN];
0060 struct {
0061 int sizeof_stat;
0062 int stat_offset;
0063 };
0064 };
0065
0066 #define VNIC_STAT(m) { sizeof_field(struct opa_vnic_stats, m), \
0067 offsetof(struct opa_vnic_stats, m) }
0068
0069 static struct vnic_stats vnic_gstrings_stats[] = {
0070
0071 {"rx_packets", VNIC_STAT(netstats.rx_packets)},
0072 {"tx_packets", VNIC_STAT(netstats.tx_packets)},
0073 {"rx_bytes", VNIC_STAT(netstats.rx_bytes)},
0074 {"tx_bytes", VNIC_STAT(netstats.tx_bytes)},
0075 {"rx_errors", VNIC_STAT(netstats.rx_errors)},
0076 {"tx_errors", VNIC_STAT(netstats.tx_errors)},
0077 {"rx_dropped", VNIC_STAT(netstats.rx_dropped)},
0078 {"tx_dropped", VNIC_STAT(netstats.tx_dropped)},
0079
0080
0081 {"tx_unicast", VNIC_STAT(tx_grp.unicast)},
0082 {"tx_mcastbcast", VNIC_STAT(tx_grp.mcastbcast)},
0083 {"tx_untagged", VNIC_STAT(tx_grp.untagged)},
0084 {"tx_vlan", VNIC_STAT(tx_grp.vlan)},
0085
0086 {"tx_64_size", VNIC_STAT(tx_grp.s_64)},
0087 {"tx_65_127", VNIC_STAT(tx_grp.s_65_127)},
0088 {"tx_128_255", VNIC_STAT(tx_grp.s_128_255)},
0089 {"tx_256_511", VNIC_STAT(tx_grp.s_256_511)},
0090 {"tx_512_1023", VNIC_STAT(tx_grp.s_512_1023)},
0091 {"tx_1024_1518", VNIC_STAT(tx_grp.s_1024_1518)},
0092 {"tx_1519_max", VNIC_STAT(tx_grp.s_1519_max)},
0093
0094 {"rx_unicast", VNIC_STAT(rx_grp.unicast)},
0095 {"rx_mcastbcast", VNIC_STAT(rx_grp.mcastbcast)},
0096 {"rx_untagged", VNIC_STAT(rx_grp.untagged)},
0097 {"rx_vlan", VNIC_STAT(rx_grp.vlan)},
0098
0099 {"rx_64_size", VNIC_STAT(rx_grp.s_64)},
0100 {"rx_65_127", VNIC_STAT(rx_grp.s_65_127)},
0101 {"rx_128_255", VNIC_STAT(rx_grp.s_128_255)},
0102 {"rx_256_511", VNIC_STAT(rx_grp.s_256_511)},
0103 {"rx_512_1023", VNIC_STAT(rx_grp.s_512_1023)},
0104 {"rx_1024_1518", VNIC_STAT(rx_grp.s_1024_1518)},
0105 {"rx_1519_max", VNIC_STAT(rx_grp.s_1519_max)},
0106
0107
0108 {"rx_fifo_errors", VNIC_STAT(netstats.rx_fifo_errors)},
0109 {"rx_length_errors", VNIC_STAT(netstats.rx_length_errors)},
0110
0111 {"tx_fifo_errors", VNIC_STAT(netstats.tx_fifo_errors)},
0112 {"tx_carrier_errors", VNIC_STAT(netstats.tx_carrier_errors)},
0113
0114 {"tx_dlid_zero", VNIC_STAT(tx_dlid_zero)},
0115 {"tx_drop_state", VNIC_STAT(tx_drop_state)},
0116 {"rx_drop_state", VNIC_STAT(rx_drop_state)},
0117 {"rx_oversize", VNIC_STAT(rx_oversize)},
0118 {"rx_runt", VNIC_STAT(rx_runt)},
0119 };
0120
0121 #define VNIC_STATS_LEN ARRAY_SIZE(vnic_gstrings_stats)
0122
0123
0124 static void vnic_get_drvinfo(struct net_device *netdev,
0125 struct ethtool_drvinfo *drvinfo)
0126 {
0127 strlcpy(drvinfo->driver, opa_vnic_driver_name, sizeof(drvinfo->driver));
0128 strlcpy(drvinfo->bus_info, dev_name(netdev->dev.parent),
0129 sizeof(drvinfo->bus_info));
0130 }
0131
0132
0133 static int vnic_get_sset_count(struct net_device *netdev, int sset)
0134 {
0135 return (sset == ETH_SS_STATS) ? VNIC_STATS_LEN : -EOPNOTSUPP;
0136 }
0137
0138
0139 static void vnic_get_ethtool_stats(struct net_device *netdev,
0140 struct ethtool_stats *stats, u64 *data)
0141 {
0142 struct opa_vnic_adapter *adapter = opa_vnic_priv(netdev);
0143 struct opa_vnic_stats vstats;
0144 int i;
0145
0146 memset(&vstats, 0, sizeof(vstats));
0147 spin_lock(&adapter->stats_lock);
0148 adapter->rn_ops->ndo_get_stats64(netdev, &vstats.netstats);
0149 spin_unlock(&adapter->stats_lock);
0150 for (i = 0; i < VNIC_STATS_LEN; i++) {
0151 char *p = (char *)&vstats + vnic_gstrings_stats[i].stat_offset;
0152
0153 data[i] = (vnic_gstrings_stats[i].sizeof_stat ==
0154 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
0155 }
0156 }
0157
0158
0159 static void vnic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
0160 {
0161 int i;
0162
0163 if (stringset != ETH_SS_STATS)
0164 return;
0165
0166 for (i = 0; i < VNIC_STATS_LEN; i++)
0167 memcpy(data + i * ETH_GSTRING_LEN,
0168 vnic_gstrings_stats[i].stat_string,
0169 ETH_GSTRING_LEN);
0170 }
0171
0172
0173 static const struct ethtool_ops opa_vnic_ethtool_ops = {
0174 .get_drvinfo = vnic_get_drvinfo,
0175 .get_link = ethtool_op_get_link,
0176 .get_strings = vnic_get_strings,
0177 .get_sset_count = vnic_get_sset_count,
0178 .get_ethtool_stats = vnic_get_ethtool_stats,
0179 };
0180
0181
0182 void opa_vnic_set_ethtool_ops(struct net_device *netdev)
0183 {
0184 netdev->ethtool_ops = &opa_vnic_ethtool_ops;
0185 }