|
14 | 14 | #include <zephyr/net/net_if.h> |
15 | 15 | #include <zephyr/net/ethernet.h> |
16 | 16 |
|
17 | | -static inline void eth_stats_update_bytes_rx(struct net_if *iface, |
18 | | - uint32_t bytes) |
| 17 | +static inline struct net_stats_eth *eth_stats_get_common(struct net_if *iface) |
19 | 18 | { |
20 | 19 | const struct ethernet_api *api = (const struct ethernet_api *) |
21 | 20 | net_if_get_device(iface)->api; |
22 | | - struct net_stats_eth *stats; |
23 | | - |
24 | | - if (!api->get_stats) { |
25 | | - return; |
26 | | - } |
27 | 21 |
|
28 | | - stats = api->get_stats(net_if_get_device(iface)); |
29 | | - if (!stats) { |
30 | | - return; |
| 22 | + if (api->get_stats_type != NULL) { |
| 23 | + return api->get_stats_type(net_if_get_device(iface), |
| 24 | + ETHERNET_STATS_TYPE_COMMON); |
| 25 | + } else if (api->get_stats != NULL) { |
| 26 | + return api->get_stats(net_if_get_device(iface)); |
31 | 27 | } |
32 | 28 |
|
33 | | - stats->bytes.received += bytes; |
| 29 | + return NULL; |
34 | 30 | } |
35 | 31 |
|
36 | | -static inline void eth_stats_update_bytes_tx(struct net_if *iface, |
37 | | - uint32_t bytes) |
| 32 | +static inline void eth_stats_update_bytes_rx(struct net_if *iface, uint32_t bytes) |
38 | 33 | { |
39 | | - const struct ethernet_api *api = (const struct ethernet_api *) |
40 | | - net_if_get_device(iface)->api; |
41 | | - struct net_stats_eth *stats; |
| 34 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
42 | 35 |
|
43 | | - if (!api->get_stats) { |
44 | | - return; |
| 36 | + if (stats != NULL) { |
| 37 | + stats->bytes.received += bytes; |
45 | 38 | } |
| 39 | +} |
46 | 40 |
|
47 | | - stats = api->get_stats(net_if_get_device(iface)); |
48 | | - if (!stats) { |
49 | | - return; |
50 | | - } |
| 41 | +static inline void eth_stats_update_bytes_tx(struct net_if *iface, uint32_t bytes) |
| 42 | +{ |
| 43 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
51 | 44 |
|
52 | | - stats->bytes.sent += bytes; |
| 45 | + if (stats != NULL) { |
| 46 | + stats->bytes.sent += bytes; |
| 47 | + } |
53 | 48 | } |
54 | 49 |
|
55 | 50 | static inline void eth_stats_update_pkts_rx(struct net_if *iface) |
56 | 51 | { |
57 | | - const struct ethernet_api *api = (const struct ethernet_api *) |
58 | | - net_if_get_device(iface)->api; |
59 | | - struct net_stats_eth *stats; |
| 52 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
60 | 53 |
|
61 | | - if (!api->get_stats) { |
62 | | - return; |
63 | | - } |
64 | | - |
65 | | - stats = api->get_stats(net_if_get_device(iface)); |
66 | | - if (!stats) { |
67 | | - return; |
| 54 | + if (stats != NULL) { |
| 55 | + stats->pkts.rx++; |
68 | 56 | } |
69 | | - |
70 | | - stats->pkts.rx++; |
71 | 57 | } |
72 | 58 |
|
73 | 59 | static inline void eth_stats_update_pkts_tx(struct net_if *iface) |
74 | 60 | { |
75 | | - const struct ethernet_api *api = (const struct ethernet_api *) |
76 | | - net_if_get_device(iface)->api; |
77 | | - struct net_stats_eth *stats; |
78 | | - |
79 | | - if (!api->get_stats) { |
80 | | - return; |
81 | | - } |
| 61 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
82 | 62 |
|
83 | | - stats = api->get_stats(net_if_get_device(iface)); |
84 | | - if (!stats) { |
85 | | - return; |
| 63 | + if (stats != NULL) { |
| 64 | + stats->pkts.tx++; |
86 | 65 | } |
87 | | - |
88 | | - stats->pkts.tx++; |
89 | 66 | } |
90 | 67 |
|
91 | 68 | static inline void eth_stats_update_broadcast_rx(struct net_if *iface) |
92 | 69 | { |
93 | | - const struct ethernet_api *api = (const struct ethernet_api *) |
94 | | - net_if_get_device(iface)->api; |
95 | | - struct net_stats_eth *stats; |
96 | | - |
97 | | - if (!api->get_stats) { |
98 | | - return; |
99 | | - } |
| 70 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
100 | 71 |
|
101 | | - stats = api->get_stats(net_if_get_device(iface)); |
102 | | - if (!stats) { |
103 | | - return; |
| 72 | + if (stats != NULL) { |
| 73 | + stats->broadcast.rx++; |
104 | 74 | } |
105 | | - |
106 | | - stats->broadcast.rx++; |
107 | 75 | } |
108 | 76 |
|
109 | 77 | static inline void eth_stats_update_broadcast_tx(struct net_if *iface) |
110 | 78 | { |
111 | | - const struct ethernet_api *api = (const struct ethernet_api *) |
112 | | - net_if_get_device(iface)->api; |
113 | | - struct net_stats_eth *stats; |
| 79 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
114 | 80 |
|
115 | | - if (!api->get_stats) { |
116 | | - return; |
| 81 | + if (stats != NULL) { |
| 82 | + stats->broadcast.tx++; |
117 | 83 | } |
118 | | - |
119 | | - stats = api->get_stats(net_if_get_device(iface)); |
120 | | - if (!stats) { |
121 | | - return; |
122 | | - } |
123 | | - |
124 | | - stats->broadcast.tx++; |
125 | 84 | } |
126 | 85 |
|
127 | 86 | static inline void eth_stats_update_multicast_rx(struct net_if *iface) |
128 | 87 | { |
129 | | - const struct ethernet_api *api = (const struct ethernet_api *) |
130 | | - net_if_get_device(iface)->api; |
131 | | - struct net_stats_eth *stats; |
132 | | - |
133 | | - if (!api->get_stats) { |
134 | | - return; |
135 | | - } |
| 88 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
136 | 89 |
|
137 | | - stats = api->get_stats(net_if_get_device(iface)); |
138 | | - if (!stats) { |
139 | | - return; |
| 90 | + if (stats != NULL) { |
| 91 | + stats->multicast.rx++; |
140 | 92 | } |
141 | | - |
142 | | - stats->multicast.rx++; |
143 | 93 | } |
144 | 94 |
|
145 | 95 | static inline void eth_stats_update_multicast_tx(struct net_if *iface) |
146 | 96 | { |
147 | | - const struct ethernet_api *api = (const struct ethernet_api *) |
148 | | - net_if_get_device(iface)->api; |
149 | | - struct net_stats_eth *stats; |
| 97 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
150 | 98 |
|
151 | | - if (!api->get_stats) { |
152 | | - return; |
153 | | - } |
154 | | - |
155 | | - stats = api->get_stats(net_if_get_device(iface)); |
156 | | - if (!stats) { |
157 | | - return; |
| 99 | + if (stats != NULL) { |
| 100 | + stats->multicast.tx++; |
158 | 101 | } |
159 | | - |
160 | | - stats->multicast.tx++; |
161 | 102 | } |
162 | 103 |
|
163 | | - |
164 | 104 | static inline void eth_stats_update_errors_rx(struct net_if *iface) |
165 | 105 | { |
166 | 106 | struct net_stats_eth *stats; |
167 | | - const struct ethernet_api *api; |
168 | 107 |
|
169 | 108 | if (!iface) { |
170 | 109 | return; |
171 | 110 | } |
172 | 111 |
|
173 | | - api = ((const struct ethernet_api *) |
174 | | - net_if_get_device(iface)->api); |
175 | | - |
176 | | - if (!api->get_stats) { |
177 | | - return; |
178 | | - } |
179 | | - |
180 | | - stats = api->get_stats(net_if_get_device(iface)); |
181 | | - if (!stats) { |
182 | | - return; |
| 112 | + stats = eth_stats_get_common(iface); |
| 113 | + if (stats != NULL) { |
| 114 | + stats->errors.rx++; |
183 | 115 | } |
184 | | - |
185 | | - stats->errors.rx++; |
186 | 116 | } |
187 | 117 |
|
188 | 118 | static inline void eth_stats_update_errors_tx(struct net_if *iface) |
189 | 119 | { |
190 | | - struct net_stats_eth *stats; |
191 | | - const struct ethernet_api *api = ((const struct ethernet_api *) |
192 | | - net_if_get_device(iface)->api); |
193 | | - |
194 | | - if (!api->get_stats) { |
195 | | - return; |
196 | | - } |
| 120 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
197 | 121 |
|
198 | | - stats = api->get_stats(net_if_get_device(iface)); |
199 | | - if (!stats) { |
200 | | - return; |
| 122 | + if (stats != NULL) { |
| 123 | + stats->errors.tx++; |
201 | 124 | } |
202 | | - |
203 | | - stats->errors.tx++; |
204 | 125 | } |
205 | 126 |
|
206 | 127 | static inline void eth_stats_update_unknown_protocol(struct net_if *iface) |
207 | 128 | { |
208 | | - struct net_stats_eth *stats; |
209 | | - const struct ethernet_api *api = ((const struct ethernet_api *) |
210 | | - net_if_get_device(iface)->api); |
| 129 | + struct net_stats_eth *stats = eth_stats_get_common(iface); |
211 | 130 |
|
212 | | - if (!api->get_stats) { |
213 | | - return; |
| 131 | + if (stats != NULL) { |
| 132 | + stats->unknown_protocol++; |
214 | 133 | } |
215 | | - |
216 | | - stats = api->get_stats(net_if_get_device(iface)); |
217 | | - if (!stats) { |
218 | | - return; |
219 | | - } |
220 | | - |
221 | | - stats->unknown_protocol++; |
222 | 134 | } |
223 | 135 |
|
224 | 136 | #else /* CONFIG_NET_STATISTICS_ETHERNET */ |
|
0 commit comments