blob: fa741f84c5b9b639b5bbadc1adf4893daa50d6e4 [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>
15#include <linux/slab.h>
16#include <linux/errno.h>
17#include <linux/kernel_stat.h>
18#include <linux/netdevice.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070019#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include "appldata.h"
22
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/*
25 * Network data
26 *
27 * This is accessed as binary data by z/VM. If changes to it can't be avoided,
28 * the structure version (product ID, see appldata_base.c) needs to be changed
29 * as well and all documentation and z/VM applications using it must be updated.
30 *
31 * The record layout is documented in the Linux for zSeries Device Drivers
32 * book:
33 * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml
34 */
Heiko Carstens2b67fc42007-02-05 21:16:47 +010035static struct appldata_net_sum_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 u64 timestamp;
37 u32 sync_count_1; /* after VM collected the record data, */
38 u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the
39 same. If not, the record has been updated on
40 the Linux side while VM was collecting the
41 (possibly corrupt) data */
42
43 u32 nr_interfaces; /* nr. of network interfaces being monitored */
44
45 u32 padding; /* next value is 64-bit aligned, so these */
46 /* 4 byte would be padded out by compiler */
47
48 u64 rx_packets; /* total packets received */
49 u64 tx_packets; /* total packets transmitted */
50 u64 rx_bytes; /* total bytes received */
51 u64 tx_bytes; /* total bytes transmitted */
52 u64 rx_errors; /* bad packets received */
53 u64 tx_errors; /* packet transmit problems */
54 u64 rx_dropped; /* no space in linux buffers */
55 u64 tx_dropped; /* no space available in linux */
56 u64 collisions; /* collisions while transmitting */
Gerald Schaeferf26d5832005-06-04 15:43:33 -070057} __attribute__((packed)) appldata_net_sum_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060/*
61 * appldata_get_net_sum_data()
62 *
63 * gather accumulated network statistics
64 */
65static void appldata_get_net_sum_data(void *data)
66{
67 int i;
68 struct appldata_net_sum_data *net_data;
69 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,
71 tx_errors, rx_dropped, tx_dropped, collisions;
72
73 net_data = data;
74 net_data->sync_count_1++;
75
76 i = 0;
77 rx_packets = 0;
78 tx_packets = 0;
79 rx_bytes = 0;
80 tx_bytes = 0;
81 rx_errors = 0;
82 tx_errors = 0;
83 rx_dropped = 0;
84 tx_dropped = 0;
85 collisions = 0;
86 read_lock(&dev_base_lock);
Eric W. Biederman881d9662007-09-17 11:56:21 -070087 for_each_netdev(&init_net, dev) {
Stephen Hemmingereeda3fd2008-11-19 21:40:23 -080088 const struct net_device_stats *stats = dev_get_stats(dev);
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 rx_packets += stats->rx_packets;
91 tx_packets += stats->tx_packets;
92 rx_bytes += stats->rx_bytes;
93 tx_bytes += stats->tx_bytes;
94 rx_errors += stats->rx_errors;
95 tx_errors += stats->tx_errors;
96 rx_dropped += stats->rx_dropped;
97 tx_dropped += stats->tx_dropped;
98 collisions += stats->collisions;
99 i++;
100 }
101 read_unlock(&dev_base_lock);
102 net_data->nr_interfaces = i;
103 net_data->rx_packets = rx_packets;
104 net_data->tx_packets = tx_packets;
105 net_data->rx_bytes = rx_bytes;
106 net_data->tx_bytes = tx_bytes;
107 net_data->rx_errors = rx_errors;
108 net_data->tx_errors = tx_errors;
109 net_data->rx_dropped = rx_dropped;
110 net_data->tx_dropped = tx_dropped;
111 net_data->collisions = collisions;
112
113 net_data->timestamp = get_clock();
114 net_data->sync_count_2++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115}
116
117
118static struct appldata_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .name = "net_sum",
120 .record_nr = APPLDATA_RECORD_NET_SUM_ID,
121 .size = sizeof(struct appldata_net_sum_data),
122 .callback = &appldata_get_net_sum_data,
123 .data = &appldata_net_sum_data,
124 .owner = THIS_MODULE,
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200125 .mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
128
129/*
130 * appldata_net_init()
131 *
132 * init data, register ops
133 */
134static int __init appldata_net_init(void)
135{
Gerald Schaeferd3ae9422008-07-14 09:59:34 +0200136 return appldata_register_ops(&ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
139/*
140 * appldata_net_exit()
141 *
142 * unregister ops
143 */
144static void __exit appldata_net_exit(void)
145{
146 appldata_unregister_ops(&ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
149
150module_init(appldata_net_init);
151module_exit(appldata_net_exit);
152
153MODULE_LICENSE("GPL");
154MODULE_AUTHOR("Gerald Schaefer");
155MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics");