blob: 6c1815a47714389e0f6664722e7c3563907a930a [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
24#define MY_PRINT_NAME "appldata_net_sum" /* for debug messages, etc. */
25
26
27/*
28 * Network data
29 *
30 * This is accessed as binary data by z/VM. If changes to it can't be avoided,
31 * the structure version (product ID, see appldata_base.c) needs to be changed
32 * as well and all documentation and z/VM applications using it must be updated.
33 *
34 * The record layout is documented in the Linux for zSeries Device Drivers
35 * book:
36 * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml
37 */
Heiko Carstens2b67fc42007-02-05 21:16:47 +010038static struct appldata_net_sum_data {
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 u64 timestamp;
40 u32 sync_count_1; /* after VM collected the record data, */
41 u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the
42 same. If not, the record has been updated on
43 the Linux side while VM was collecting the
44 (possibly corrupt) data */
45
46 u32 nr_interfaces; /* nr. of network interfaces being monitored */
47
48 u32 padding; /* next value is 64-bit aligned, so these */
49 /* 4 byte would be padded out by compiler */
50
51 u64 rx_packets; /* total packets received */
52 u64 tx_packets; /* total packets transmitted */
53 u64 rx_bytes; /* total bytes received */
54 u64 tx_bytes; /* total bytes transmitted */
55 u64 rx_errors; /* bad packets received */
56 u64 tx_errors; /* packet transmit problems */
57 u64 rx_dropped; /* no space in linux buffers */
58 u64 tx_dropped; /* no space available in linux */
59 u64 collisions; /* collisions while transmitting */
Gerald Schaeferf26d5832005-06-04 15:43:33 -070060} __attribute__((packed)) appldata_net_sum_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62
63static inline void appldata_print_debug(struct appldata_net_sum_data *net_data)
64{
65 P_DEBUG("--- NET - RECORD ---\n");
66
67 P_DEBUG("nr_interfaces = %u\n", net_data->nr_interfaces);
68 P_DEBUG("rx_packets = %8lu\n", net_data->rx_packets);
69 P_DEBUG("tx_packets = %8lu\n", net_data->tx_packets);
70 P_DEBUG("rx_bytes = %8lu\n", net_data->rx_bytes);
71 P_DEBUG("tx_bytes = %8lu\n", net_data->tx_bytes);
72 P_DEBUG("rx_errors = %8lu\n", net_data->rx_errors);
73 P_DEBUG("tx_errors = %8lu\n", net_data->tx_errors);
74 P_DEBUG("rx_dropped = %8lu\n", net_data->rx_dropped);
75 P_DEBUG("tx_dropped = %8lu\n", net_data->tx_dropped);
76 P_DEBUG("collisions = %8lu\n", net_data->collisions);
77
78 P_DEBUG("sync_count_1 = %u\n", net_data->sync_count_1);
79 P_DEBUG("sync_count_2 = %u\n", net_data->sync_count_2);
80 P_DEBUG("timestamp = %lX\n", net_data->timestamp);
81}
82
83/*
84 * appldata_get_net_sum_data()
85 *
86 * gather accumulated network statistics
87 */
88static void appldata_get_net_sum_data(void *data)
89{
90 int i;
91 struct appldata_net_sum_data *net_data;
92 struct net_device *dev;
93 struct net_device_stats *stats;
94 unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,
95 tx_errors, rx_dropped, tx_dropped, collisions;
96
97 net_data = data;
98 net_data->sync_count_1++;
99
100 i = 0;
101 rx_packets = 0;
102 tx_packets = 0;
103 rx_bytes = 0;
104 tx_bytes = 0;
105 rx_errors = 0;
106 tx_errors = 0;
107 rx_dropped = 0;
108 tx_dropped = 0;
109 collisions = 0;
110 read_lock(&dev_base_lock);
Eric W. Biederman881d9662007-09-17 11:56:21 -0700111 for_each_netdev(&init_net, dev) {
Rusty Russellc45d2862007-03-28 14:29:08 -0700112 stats = dev->get_stats(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 rx_packets += stats->rx_packets;
114 tx_packets += stats->tx_packets;
115 rx_bytes += stats->rx_bytes;
116 tx_bytes += stats->tx_bytes;
117 rx_errors += stats->rx_errors;
118 tx_errors += stats->tx_errors;
119 rx_dropped += stats->rx_dropped;
120 tx_dropped += stats->tx_dropped;
121 collisions += stats->collisions;
122 i++;
123 }
124 read_unlock(&dev_base_lock);
125 net_data->nr_interfaces = i;
126 net_data->rx_packets = rx_packets;
127 net_data->tx_packets = tx_packets;
128 net_data->rx_bytes = rx_bytes;
129 net_data->tx_bytes = tx_bytes;
130 net_data->rx_errors = rx_errors;
131 net_data->tx_errors = tx_errors;
132 net_data->rx_dropped = rx_dropped;
133 net_data->tx_dropped = tx_dropped;
134 net_data->collisions = collisions;
135
136 net_data->timestamp = get_clock();
137 net_data->sync_count_2++;
138#ifdef APPLDATA_DEBUG
139 appldata_print_debug(net_data);
140#endif
141}
142
143
144static struct appldata_ops ops = {
145 .ctl_nr = CTL_APPLDATA_NET_SUM,
146 .name = "net_sum",
147 .record_nr = APPLDATA_RECORD_NET_SUM_ID,
148 .size = sizeof(struct appldata_net_sum_data),
149 .callback = &appldata_get_net_sum_data,
150 .data = &appldata_net_sum_data,
151 .owner = THIS_MODULE,
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200152 .mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155
156/*
157 * appldata_net_init()
158 *
159 * init data, register ops
160 */
161static int __init appldata_net_init(void)
162{
163 int rc;
164
165 P_DEBUG("sizeof(net) = %lu\n", sizeof(struct appldata_net_sum_data));
166
167 rc = appldata_register_ops(&ops);
168 if (rc != 0) {
169 P_ERROR("Error registering ops, rc = %i\n", rc);
170 } else {
171 P_DEBUG("%s-ops registered!\n", ops.name);
172 }
173 return rc;
174}
175
176/*
177 * appldata_net_exit()
178 *
179 * unregister ops
180 */
181static void __exit appldata_net_exit(void)
182{
183 appldata_unregister_ops(&ops);
184 P_DEBUG("%s-ops unregistered!\n", ops.name);
185}
186
187
188module_init(appldata_net_init);
189module_exit(appldata_net_exit);
190
191MODULE_LICENSE("GPL");
192MODULE_AUTHOR("Gerald Schaefer");
193MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics");