Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright(c) 2017 Intel Corporation.
0003  *
0004  * This file is provided under a dual BSD/GPLv2 license.  When using or
0005  * redistributing this file, you may do so under either license.
0006  *
0007  * GPL LICENSE SUMMARY
0008  *
0009  * This program is free software; you can redistribute it and/or modify
0010  * it under the terms of version 2 of the GNU General Public License as
0011  * published by the Free Software Foundation.
0012  *
0013  * This program is distributed in the hope that it will be useful, but
0014  * WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016  * General Public License for more details.
0017  *
0018  * BSD LICENSE
0019  *
0020  * Redistribution and use in source and binary forms, with or without
0021  * modification, are permitted provided that the following conditions
0022  * are met:
0023  *
0024  *  - Redistributions of source code must retain the above copyright
0025  *    notice, this list of conditions and the following disclaimer.
0026  *  - Redistributions in binary form must reproduce the above copyright
0027  *    notice, this list of conditions and the following disclaimer in
0028  *    the documentation and/or other materials provided with the
0029  *    distribution.
0030  *  - Neither the name of Intel Corporation nor the names of its
0031  *    contributors may be used to endorse or promote products derived
0032  *    from this software without specific prior written permission.
0033  *
0034  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0035  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0036  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0037  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0038  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0039  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0040  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0041  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0042  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0043  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0044  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0045  *
0046  */
0047 
0048 /*
0049  * This file contains OPA VNIC ethtool functions
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     /* NETDEV stats */
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     /* SUMMARY counters */
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     /* ERROR counters */
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 /* vnic_get_drvinfo - get driver info */
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 /* vnic_get_sset_count - get string set count */
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 /* vnic_get_ethtool_stats - get statistics */
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 /* vnic_get_strings - get strings */
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 /* ethtool ops */
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 /* opa_vnic_set_ethtool_ops - set ethtool ops */
0182 void opa_vnic_set_ethtool_ops(struct net_device *netdev)
0183 {
0184     netdev->ethtool_ops = &opa_vnic_ethtool_ops;
0185 }