]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
net/mlx4_en: Support ndo_get_vf_stats
authorEran Ben Elisha <eranbe@mellanox.com>
Mon, 15 Jun 2015 14:59:08 +0000 (17:59 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 16 Jun 2015 00:23:03 +0000 (17:23 -0700)
Implement the ndo to gather VF statistics through the PF.

All counters related to this VF are stored in a per slave
list, run over the slave's list and collect all statistics.

Signed-off-by: Eran Ben Elisha <eranbe@mellanox.com>
Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx4/cmd.c
drivers/net/ethernet/mellanox/mlx4/en_netdev.c
drivers/net/ethernet/mellanox/mlx4/mlx4.h
drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
include/linux/mlx4/cmd.h

index 44b8f7715ade5952ac26bebd0df72cbfdad6392e..82040137d7d9723a0ab027fe72bc25a3063368b3 100644 (file)
@@ -3223,6 +3223,36 @@ if_stat_out:
 }
 EXPORT_SYMBOL_GPL(mlx4_get_counter_stats);
 
+int mlx4_get_vf_stats(struct mlx4_dev *dev, int port, int vf_idx,
+                     struct ifla_vf_stats *vf_stats)
+{
+       struct mlx4_counter tmp_vf_stats;
+       int slave;
+       int err = 0;
+
+       if (!vf_stats)
+               return -EINVAL;
+
+       if (!mlx4_is_master(dev))
+               return -EPROTONOSUPPORT;
+
+       slave = mlx4_get_slave_indx(dev, vf_idx);
+       if (slave < 0)
+               return -EINVAL;
+
+       port = mlx4_slaves_closest_port(dev, slave, port);
+       err = mlx4_calc_vf_counters(dev, slave, port, &tmp_vf_stats);
+       if (!err && tmp_vf_stats.counter_mode == 0) {
+               vf_stats->rx_packets = be64_to_cpu(tmp_vf_stats.rx_frames);
+               vf_stats->tx_packets = be64_to_cpu(tmp_vf_stats.tx_frames);
+               vf_stats->rx_bytes = be64_to_cpu(tmp_vf_stats.rx_bytes);
+               vf_stats->tx_bytes = be64_to_cpu(tmp_vf_stats.tx_bytes);
+       }
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(mlx4_get_vf_stats);
+
 int mlx4_vf_smi_enabled(struct mlx4_dev *dev, int slave, int port)
 {
        struct mlx4_priv *priv = mlx4_priv(dev);
index f9142f22d630fb34ac75735d3d5eab50e62315b6..77179d7ae4cc786c9bc4bb4ea39763522da54d64 100644 (file)
@@ -2292,6 +2292,15 @@ static int mlx4_en_set_vf_link_state(struct net_device *dev, int vf, int link_st
        return mlx4_set_vf_link_state(mdev->dev, en_priv->port, vf, link_state);
 }
 
+static int mlx4_en_get_vf_stats(struct net_device *dev, int vf,
+                               struct ifla_vf_stats *vf_stats)
+{
+       struct mlx4_en_priv *en_priv = netdev_priv(dev);
+       struct mlx4_en_dev *mdev = en_priv->mdev;
+
+       return mlx4_get_vf_stats(mdev->dev, en_priv->port, vf, vf_stats);
+}
+
 #define PORT_ID_BYTE_LEN 8
 static int mlx4_en_get_phys_port_id(struct net_device *dev,
                                    struct netdev_phys_item_id *ppid)
@@ -2489,6 +2498,7 @@ static const struct net_device_ops mlx4_netdev_ops_master = {
        .ndo_set_vf_rate        = mlx4_en_set_vf_rate,
        .ndo_set_vf_spoofchk    = mlx4_en_set_vf_spoofchk,
        .ndo_set_vf_link_state  = mlx4_en_set_vf_link_state,
+       .ndo_get_vf_stats       = mlx4_en_get_vf_stats,
        .ndo_get_vf_config      = mlx4_en_get_vf_config,
 #ifdef CONFIG_NET_POLL_CONTROLLER
        .ndo_poll_controller    = mlx4_en_netpoll,
index e9e94bc0e75d173d486aedaa338881a9f2fe50a4..a092c5c34d4375df330c1f8fea2b01d2545580dd 100644 (file)
@@ -1010,6 +1010,8 @@ int __mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
                     int start_index, int npages, u64 *page_list);
 int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
 void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
+int mlx4_calc_vf_counters(struct mlx4_dev *dev, int slave, int port,
+                         struct mlx4_counter *data);
 int __mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
 void __mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
 
index 73db584bc240c5857717262e15425461ce4667c9..731423ca575da8583deb8c944a524f728a967bbe 100644 (file)
@@ -46,6 +46,7 @@
 
 #include "mlx4.h"
 #include "fw.h"
+#include "mlx4_stats.h"
 
 #define MLX4_MAC_VALID         (1ull << 63)
 #define MLX4_PF_COUNTERS_PER_PORT      2
@@ -1147,6 +1148,53 @@ static struct res_common *alloc_tr(u64 id, enum mlx4_resource type, int slave,
        return ret;
 }
 
+int mlx4_calc_vf_counters(struct mlx4_dev *dev, int slave, int port,
+                         struct mlx4_counter *data)
+{
+       struct mlx4_priv *priv = mlx4_priv(dev);
+       struct mlx4_resource_tracker *tracker = &priv->mfunc.master.res_tracker;
+       struct res_common *tmp;
+       struct res_counter *counter;
+       int *counters_arr;
+       int i = 0, err = 0;
+
+       memset(data, 0, sizeof(*data));
+
+       counters_arr = kmalloc_array(dev->caps.max_counters,
+                                    sizeof(*counters_arr), GFP_KERNEL);
+       if (!counters_arr)
+               return -ENOMEM;
+
+       spin_lock_irq(mlx4_tlock(dev));
+       list_for_each_entry(tmp,
+                           &tracker->slave_list[slave].res_list[RES_COUNTER],
+                           list) {
+               counter = container_of(tmp, struct res_counter, com);
+               if (counter->port == port) {
+                       counters_arr[i] = (int)tmp->res_id;
+                       i++;
+               }
+       }
+       spin_unlock_irq(mlx4_tlock(dev));
+       counters_arr[i] = -1;
+
+       i = 0;
+
+       while (counters_arr[i] != -1) {
+               err = mlx4_get_counter_stats(dev, counters_arr[i], data,
+                                            0);
+               if (err) {
+                       memset(data, 0, sizeof(*data));
+                       goto table_changed;
+               }
+               i++;
+       }
+
+table_changed:
+       kfree(counters_arr);
+       return 0;
+}
+
 static int add_res_range(struct mlx4_dev *dev, int slave, u64 base, int count,
                         enum mlx4_resource type, int extra)
 {
index 5dffc869988ba65b1a837f758496322877c0dd0a..58391f2e0414e0e2001fab4c002771798fad3d33 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/if_link.h>
 #include <linux/mlx4/device.h>
+#include <linux/netdevice.h>
 
 enum {
        /* initialization and general commands */
@@ -303,6 +304,8 @@ void mlx4_free_cmd_mailbox(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbo
 
 int mlx4_get_counter_stats(struct mlx4_dev *dev, int counter_index,
                           struct mlx4_counter *counter_stats, int reset);
+int mlx4_get_vf_stats(struct mlx4_dev *dev, int port, int vf_idx,
+                     struct ifla_vf_stats *vf_stats);
 u32 mlx4_comm_get_version(void);
 int mlx4_set_vf_mac(struct mlx4_dev *dev, int port, int vf, u64 mac);
 int mlx4_set_vf_vlan(struct mlx4_dev *dev, int port, int vf, u16 vlan, u8 qos);