aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/soft-interface.c
diff options
context:
space:
mode:
authorMartin Hundebøll <martin@hundeboll.net>2012-04-20 11:02:45 -0400
committerAntonio Quartulli <ordex@autistici.org>2012-06-18 12:00:58 -0400
commitf8214865a55f805e65c33350bc0f1eb46dd8433d (patch)
tree0fb4582b2ec3b045a094acd6063f5559e6d4dcb5 /net/batman-adv/soft-interface.c
parent66a1b2bcb34b0c74a3422968b15a7ea853ea5a2d (diff)
batman-adv: Add get_ethtool_stats() support
Added additional counters in a bat_stats structure, which are exported through the ethtool api. The counters are specific to batman-adv and includes: forwarded packets and bytes management packets and bytes (aggregated OGMs at this point) translation table packets New counters are added by extending "enum bat_counters" in types.h and adding corresponding descriptive string(s) to bat_counters_strings in soft-iface.c. Counters are increased by calling batadv_add_counter() and incremented by one by calling batadv_inc_counter(). Signed-off-by: Martin Hundebøll <martin@hundeboll.net> Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/soft-interface.c')
-rw-r--r--net/batman-adv/soft-interface.c66
1 files changed, 64 insertions, 2 deletions
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 6e2530b02043..304a7ba09e03 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -45,6 +45,10 @@ static void bat_get_drvinfo(struct net_device *dev,
45static u32 bat_get_msglevel(struct net_device *dev); 45static u32 bat_get_msglevel(struct net_device *dev);
46static void bat_set_msglevel(struct net_device *dev, u32 value); 46static void bat_set_msglevel(struct net_device *dev, u32 value);
47static u32 bat_get_link(struct net_device *dev); 47static u32 bat_get_link(struct net_device *dev);
48static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data);
49static void batadv_get_ethtool_stats(struct net_device *dev,
50 struct ethtool_stats *stats, u64 *data);
51static int batadv_get_sset_count(struct net_device *dev, int stringset);
48 52
49static const struct ethtool_ops bat_ethtool_ops = { 53static const struct ethtool_ops bat_ethtool_ops = {
50 .get_settings = bat_get_settings, 54 .get_settings = bat_get_settings,
@@ -52,6 +56,9 @@ static const struct ethtool_ops bat_ethtool_ops = {
52 .get_msglevel = bat_get_msglevel, 56 .get_msglevel = bat_get_msglevel,
53 .set_msglevel = bat_set_msglevel, 57 .set_msglevel = bat_set_msglevel,
54 .get_link = bat_get_link, 58 .get_link = bat_get_link,
59 .get_strings = batadv_get_strings,
60 .get_ethtool_stats = batadv_get_ethtool_stats,
61 .get_sset_count = batadv_get_sset_count,
55}; 62};
56 63
57int my_skb_head_push(struct sk_buff *skb, unsigned int len) 64int my_skb_head_push(struct sk_buff *skb, unsigned int len)
@@ -399,13 +406,18 @@ struct net_device *softif_create(const char *name)
399 bat_priv->primary_if = NULL; 406 bat_priv->primary_if = NULL;
400 bat_priv->num_ifaces = 0; 407 bat_priv->num_ifaces = 0;
401 408
409 bat_priv->bat_counters = __alloc_percpu(sizeof(uint64_t) * BAT_CNT_NUM,
410 __alignof__(uint64_t));
411 if (!bat_priv->bat_counters)
412 goto unreg_soft_iface;
413
402 ret = bat_algo_select(bat_priv, bat_routing_algo); 414 ret = bat_algo_select(bat_priv, bat_routing_algo);
403 if (ret < 0) 415 if (ret < 0)
404 goto unreg_soft_iface; 416 goto free_bat_counters;
405 417
406 ret = sysfs_add_meshif(soft_iface); 418 ret = sysfs_add_meshif(soft_iface);
407 if (ret < 0) 419 if (ret < 0)
408 goto unreg_soft_iface; 420 goto free_bat_counters;
409 421
410 ret = debugfs_add_meshif(soft_iface); 422 ret = debugfs_add_meshif(soft_iface);
411 if (ret < 0) 423 if (ret < 0)
@@ -421,6 +433,8 @@ unreg_debugfs:
421 debugfs_del_meshif(soft_iface); 433 debugfs_del_meshif(soft_iface);
422unreg_sysfs: 434unreg_sysfs:
423 sysfs_del_meshif(soft_iface); 435 sysfs_del_meshif(soft_iface);
436free_bat_counters:
437 free_percpu(bat_priv->bat_counters);
424unreg_soft_iface: 438unreg_soft_iface:
425 unregister_netdevice(soft_iface); 439 unregister_netdevice(soft_iface);
426 return NULL; 440 return NULL;
@@ -486,3 +500,51 @@ static u32 bat_get_link(struct net_device *dev)
486{ 500{
487 return 1; 501 return 1;
488} 502}
503
504/* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
505 * Declare each description string in struct.name[] to get fixed sized buffer
506 * and compile time checking for strings longer than ETH_GSTRING_LEN.
507 */
508static const struct {
509 const char name[ETH_GSTRING_LEN];
510} bat_counters_strings[] = {
511 { "forward" },
512 { "forward_bytes" },
513 { "mgmt_tx" },
514 { "mgmt_tx_bytes" },
515 { "mgmt_rx" },
516 { "mgmt_rx_bytes" },
517 { "tt_request_tx" },
518 { "tt_request_rx" },
519 { "tt_response_tx" },
520 { "tt_response_rx" },
521 { "tt_roam_adv_tx" },
522 { "tt_roam_adv_rx" },
523};
524
525static void batadv_get_strings(struct net_device *dev, uint32_t stringset,
526 uint8_t *data)
527{
528 if (stringset == ETH_SS_STATS)
529 memcpy(data, bat_counters_strings,
530 sizeof(bat_counters_strings));
531}
532
533static void batadv_get_ethtool_stats(struct net_device *dev,
534 struct ethtool_stats *stats,
535 uint64_t *data)
536{
537 struct bat_priv *bat_priv = netdev_priv(dev);
538 int i;
539
540 for (i = 0; i < BAT_CNT_NUM; i++)
541 data[i] = batadv_sum_counter(bat_priv, i);
542}
543
544static int batadv_get_sset_count(struct net_device *dev, int stringset)
545{
546 if (stringset == ETH_SS_STATS)
547 return BAT_CNT_NUM;
548
549 return -EOPNOTSUPP;
550}