blob: 5da7c562a90b5dc557524ed1ae6f41bce7258bac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/appldata/appldata_net_sum.c
3 *
4 * Data gathering module for Linux-VM Monitor Stream, Stage 1.
5 * Collects accumulated network statistics (Packets received/transmitted,
6 * dropped, errors, ...).
7 *
Gerald Schaefer5b5dd212006-06-29 15:08:35 +02008 * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
Gerald Schaefer5b5dd212006-06-29 15:08:35 +020010 * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
14#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/errno.h>
16#include <linux/kernel_stat.h>
17#include <linux/netdevice.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070018#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include "appldata.h"
21
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24 * Network data
25 *
26 * This is accessed as binary data by z/VM. If changes to it can't be avoided,
27 * the structure version (product ID, see appldata_base.c) needs to be changed
28 * as well and all documentation and z/VM applications using it must be updated.
29 *
30 * The record layout is documented in the Linux for zSeries Device Drivers
31 * book:
32 * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml
33 */
Heiko Carstens2b67fc42007-02-05 21:16:47 +010034static struct appldata_net_sum_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 u64 timestamp;
36 u32 sync_count_1; /* after VM collected the record data, */
37 u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the
38 same. If not, the record has been updated on
39 the Linux side while VM was collecting the
40 (possibly corrupt) data */
41
42 u32 nr_interfaces; /* nr. of network interfaces being monitored */
43
44 u32 padding; /* next value is 64-bit aligned, so these */
45 /* 4 byte would be padded out by compiler */
46
47 u64 rx_packets; /* total packets received */
48 u64 tx_packets; /* total packets transmitted */
49 u64 rx_bytes; /* total bytes received */
50 u64 tx_bytes; /* total bytes transmitted */
51 u64 rx_errors; /* bad packets received */
52 u64 tx_errors; /* packet transmit problems */
53 u64 rx_dropped; /* no space in linux buffers */
54 u64 tx_dropped; /* no space available in linux */
55 u64 collisions; /* collisions while transmitting */
Gerald Schaeferf26d5832005-06-04 15:43:33 -070056} __attribute__((packed)) appldata_net_sum_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059/*
60 * appldata_get_net_sum_data()
61 *
62 * gather accumulated network statistics
63 */
64static void appldata_get_net_sum_data(void *data)
65{
66 int i;
67 struct appldata_net_sum_data *net_data;
68 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,
70 tx_errors, rx_dropped, tx_dropped, collisions;
71
72 net_data = data;
73 net_data->sync_count_1++;
74
75 i = 0;
76 rx_packets = 0;
77 tx_packets = 0;
78 rx_bytes = 0;
79 tx_bytes = 0;
80 rx_errors = 0;
81 tx_errors = 0;
82 rx_dropped = 0;
83 tx_dropped = 0;
84 collisions = 0;
stephen hemmingere576b9e2009-11-10 07:54:52 +000085
86 rcu_read_lock();
87 for_each_netdev_rcu(&init_net, dev) {
Heiko Carstense402e382010-08-13 10:06:42 +020088 const struct rtnl_link_stats64 *stats;
Eric Dumazet28172732010-07-07 14:58:56 -070089 struct rtnl_link_stats64 temp;
Stephen Hemmingereeda3fd2008-11-19 21:40:23 -080090
Heiko Carstense402e382010-08-13 10:06:42 +020091 stats = dev_get_stats(dev, &temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 rx_packets += stats->rx_packets;
93 tx_packets += stats->tx_packets;
94 rx_bytes += stats->rx_bytes;
95 tx_bytes += stats->tx_bytes;
96 rx_errors += stats->rx_errors;
97 tx_errors += stats->tx_errors;
98 rx_dropped += stats->rx_dropped;
99 tx_dropped += stats->tx_dropped;
100 collisions += stats->collisions;
101 i++;
102 }
stephen hemmingere576b9e2009-11-10 07:54:52 +0000103 rcu_read_unlock();
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 net_data->nr_interfaces = i;
106 net_data->rx_packets = rx_packets;
107 net_data->tx_packets = tx_packets;
108 net_data->rx_bytes = rx_bytes;
109 net_data->tx_bytes = tx_bytes;
110 net_data->rx_errors = rx_errors;
111 net_data->tx_errors = tx_errors;
112 net_data->rx_dropped = rx_dropped;
113 net_data->tx_dropped = tx_dropped;
114 net_data->collisions = collisions;
115
116 net_data->timestamp = get_clock();
117 net_data->sync_count_2++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
120
121static struct appldata_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .name = "net_sum",
123 .record_nr = APPLDATA_RECORD_NET_SUM_ID,
124 .size = sizeof(struct appldata_net_sum_data),
125 .callback = &appldata_get_net_sum_data,
126 .data = &appldata_net_sum_data,
127 .owner = THIS_MODULE,
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200128 .mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
131
132/*
133 * appldata_net_init()
134 *
135 * init data, register ops
136 */
137static int __init appldata_net_init(void)
138{
Gerald Schaeferd3ae9422008-07-14 09:59:34 +0200139 return appldata_register_ops(&ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
142/*
143 * appldata_net_exit()
144 *
145 * unregister ops
146 */
147static void __exit appldata_net_exit(void)
148{
149 appldata_unregister_ops(&ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
152
153module_init(appldata_net_init);
154module_exit(appldata_net_exit);
155
156MODULE_LICENSE("GPL");
157MODULE_AUTHOR("Gerald Schaefer");
158MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics");