ALSA: fix hda AZX_DCAPS_NO_TCSEL quirk check in driver_caps
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / net / snmp.h
blob479083a78b0c02fee92fa83430602269478517f7
1 /*
3 * SNMP MIB entries for the IP subsystem.
4 *
5 * Alan Cox <gw4pts@gw4pts.ampr.org>
7 * We don't chose to implement SNMP in the kernel (this would
8 * be silly as SNMP is a pain in the backside in places). We do
9 * however need to collect the MIB statistics and export them
10 * out of /proc (eventually)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
19 #ifndef _SNMP_H
20 #define _SNMP_H
22 #include <linux/cache.h>
23 #include <linux/snmp.h>
24 #include <linux/smp.h>
27 * Mibs are stored in array of unsigned long.
30 * struct snmp_mib{}
31 * - list of entries for particular API (such as /proc/net/snmp)
32 * - name of entries.
34 struct snmp_mib {
35 const char *name;
36 int entry;
39 #define SNMP_MIB_ITEM(_name,_entry) { \
40 .name = _name, \
41 .entry = _entry, \
44 #define SNMP_MIB_SENTINEL { \
45 .name = NULL, \
46 .entry = 0, \
50 * We use unsigned longs for most mibs but u64 for ipstats.
52 #include <linux/u64_stats_sync.h>
54 /* IPstats */
55 #define IPSTATS_MIB_MAX __IPSTATS_MIB_MAX
56 struct ipstats_mib {
57 /* mibs[] must be first field of struct ipstats_mib */
58 u64 mibs[IPSTATS_MIB_MAX];
59 struct u64_stats_sync syncp;
62 /* ICMP */
63 #define ICMP_MIB_MAX __ICMP_MIB_MAX
64 struct icmp_mib {
65 unsigned long mibs[ICMP_MIB_MAX];
68 #define ICMPMSG_MIB_MAX __ICMPMSG_MIB_MAX
69 struct icmpmsg_mib {
70 unsigned long mibs[ICMPMSG_MIB_MAX];
73 /* ICMP6 (IPv6-ICMP) */
74 #define ICMP6_MIB_MAX __ICMP6_MIB_MAX
75 /* per network ns counters */
76 struct icmpv6_mib {
77 unsigned long mibs[ICMP6_MIB_MAX];
79 /* per device counters, (shared on all cpus) */
80 struct icmpv6_mib_device {
81 atomic_long_t mibs[ICMP6_MIB_MAX];
84 #define ICMP6MSG_MIB_MAX __ICMP6MSG_MIB_MAX
85 /* per network ns counters */
86 struct icmpv6msg_mib {
87 unsigned long mibs[ICMP6MSG_MIB_MAX];
89 /* per device counters, (shared on all cpus) */
90 struct icmpv6msg_mib_device {
91 atomic_long_t mibs[ICMP6MSG_MIB_MAX];
95 /* TCP */
96 #define TCP_MIB_MAX __TCP_MIB_MAX
97 struct tcp_mib {
98 unsigned long mibs[TCP_MIB_MAX];
101 /* UDP */
102 #define UDP_MIB_MAX __UDP_MIB_MAX
103 struct udp_mib {
104 unsigned long mibs[UDP_MIB_MAX];
107 /* Linux */
108 #define LINUX_MIB_MAX __LINUX_MIB_MAX
109 struct linux_mib {
110 unsigned long mibs[LINUX_MIB_MAX];
113 /* Linux Xfrm */
114 #define LINUX_MIB_XFRMMAX __LINUX_MIB_XFRMMAX
115 struct linux_xfrm_mib {
116 unsigned long mibs[LINUX_MIB_XFRMMAX];
120 * FIXME: On x86 and some other CPUs the split into user and softirq parts
121 * is not needed because addl $1,memory is atomic against interrupts (but
122 * atomic_inc would be overkill because of the lock cycles). Wants new
123 * nonlocked_atomic_inc() primitives -AK
125 #define DEFINE_SNMP_STAT(type, name) \
126 __typeof__(type) __percpu *name[2]
127 #define DEFINE_SNMP_STAT_ATOMIC(type, name) \
128 __typeof__(type) *name
129 #define DECLARE_SNMP_STAT(type, name) \
130 extern __typeof__(type) __percpu *name[2]
132 #define SNMP_STAT_BHPTR(name) (name[0])
133 #define SNMP_STAT_USRPTR(name) (name[1])
135 #define SNMP_INC_STATS_BH(mib, field) \
136 __this_cpu_inc(mib[0]->mibs[field])
137 #define SNMP_INC_STATS_USER(mib, field) \
138 this_cpu_inc(mib[1]->mibs[field])
139 #define SNMP_INC_STATS_ATOMIC_LONG(mib, field) \
140 atomic_long_inc(&mib->mibs[field])
141 #define SNMP_INC_STATS(mib, field) \
142 this_cpu_inc(mib[!in_softirq()]->mibs[field])
143 #define SNMP_DEC_STATS(mib, field) \
144 this_cpu_dec(mib[!in_softirq()]->mibs[field])
145 #define SNMP_ADD_STATS_BH(mib, field, addend) \
146 __this_cpu_add(mib[0]->mibs[field], addend)
147 #define SNMP_ADD_STATS_USER(mib, field, addend) \
148 this_cpu_add(mib[1]->mibs[field], addend)
149 #define SNMP_ADD_STATS(mib, field, addend) \
150 this_cpu_add(mib[!in_softirq()]->mibs[field], addend)
152 * Use "__typeof__(*mib[0]) *ptr" instead of "__typeof__(mib[0]) ptr"
153 * to make @ptr a non-percpu pointer.
155 #define SNMP_UPD_PO_STATS(mib, basefield, addend) \
156 do { \
157 __typeof__(*mib[0]) *ptr; \
158 preempt_disable(); \
159 ptr = this_cpu_ptr((mib)[!in_softirq()]); \
160 ptr->mibs[basefield##PKTS]++; \
161 ptr->mibs[basefield##OCTETS] += addend;\
162 preempt_enable(); \
163 } while (0)
164 #define SNMP_UPD_PO_STATS_BH(mib, basefield, addend) \
165 do { \
166 __typeof__(*mib[0]) *ptr = \
167 __this_cpu_ptr((mib)[0]); \
168 ptr->mibs[basefield##PKTS]++; \
169 ptr->mibs[basefield##OCTETS] += addend;\
170 } while (0)
173 #if BITS_PER_LONG==32
175 #define SNMP_ADD_STATS64_BH(mib, field, addend) \
176 do { \
177 __typeof__(*mib[0]) *ptr = __this_cpu_ptr((mib)[0]); \
178 u64_stats_update_begin(&ptr->syncp); \
179 ptr->mibs[field] += addend; \
180 u64_stats_update_end(&ptr->syncp); \
181 } while (0)
182 #define SNMP_ADD_STATS64_USER(mib, field, addend) \
183 do { \
184 __typeof__(*mib[0]) *ptr; \
185 preempt_disable(); \
186 ptr = __this_cpu_ptr((mib)[1]); \
187 u64_stats_update_begin(&ptr->syncp); \
188 ptr->mibs[field] += addend; \
189 u64_stats_update_end(&ptr->syncp); \
190 preempt_enable(); \
191 } while (0)
192 #define SNMP_ADD_STATS64(mib, field, addend) \
193 do { \
194 __typeof__(*mib[0]) *ptr; \
195 preempt_disable(); \
196 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
197 u64_stats_update_begin(&ptr->syncp); \
198 ptr->mibs[field] += addend; \
199 u64_stats_update_end(&ptr->syncp); \
200 preempt_enable(); \
201 } while (0)
202 #define SNMP_INC_STATS64_BH(mib, field) SNMP_ADD_STATS64_BH(mib, field, 1)
203 #define SNMP_INC_STATS64_USER(mib, field) SNMP_ADD_STATS64_USER(mib, field, 1)
204 #define SNMP_INC_STATS64(mib, field) SNMP_ADD_STATS64(mib, field, 1)
205 #define SNMP_UPD_PO_STATS64(mib, basefield, addend) \
206 do { \
207 __typeof__(*mib[0]) *ptr; \
208 preempt_disable(); \
209 ptr = __this_cpu_ptr((mib)[!in_softirq()]); \
210 u64_stats_update_begin(&ptr->syncp); \
211 ptr->mibs[basefield##PKTS]++; \
212 ptr->mibs[basefield##OCTETS] += addend; \
213 u64_stats_update_end(&ptr->syncp); \
214 preempt_enable(); \
215 } while (0)
216 #define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) \
217 do { \
218 __typeof__(*mib[0]) *ptr; \
219 ptr = __this_cpu_ptr((mib)[0]); \
220 u64_stats_update_begin(&ptr->syncp); \
221 ptr->mibs[basefield##PKTS]++; \
222 ptr->mibs[basefield##OCTETS] += addend; \
223 u64_stats_update_end(&ptr->syncp); \
224 } while (0)
225 #else
226 #define SNMP_INC_STATS64_BH(mib, field) SNMP_INC_STATS_BH(mib, field)
227 #define SNMP_INC_STATS64_USER(mib, field) SNMP_INC_STATS_USER(mib, field)
228 #define SNMP_INC_STATS64(mib, field) SNMP_INC_STATS(mib, field)
229 #define SNMP_DEC_STATS64(mib, field) SNMP_DEC_STATS(mib, field)
230 #define SNMP_ADD_STATS64_BH(mib, field, addend) SNMP_ADD_STATS_BH(mib, field, addend)
231 #define SNMP_ADD_STATS64_USER(mib, field, addend) SNMP_ADD_STATS_USER(mib, field, addend)
232 #define SNMP_ADD_STATS64(mib, field, addend) SNMP_ADD_STATS(mib, field, addend)
233 #define SNMP_UPD_PO_STATS64(mib, basefield, addend) SNMP_UPD_PO_STATS(mib, basefield, addend)
234 #define SNMP_UPD_PO_STATS64_BH(mib, basefield, addend) SNMP_UPD_PO_STATS_BH(mib, basefield, addend)
235 #endif
237 #endif