1 /* 2 * Copyright (c) 2018 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ETH_STATS_H__ 8 #define __ETH_STATS_H__ 9 10 #if defined(CONFIG_NET_STATISTICS_ETHERNET) 11 12 #include <zephyr/net/net_ip.h> 13 #include <zephyr/net/net_stats.h> 14 #include <zephyr/net/net_if.h> 15 #include <zephyr/net/ethernet.h> 16 eth_stats_update_bytes_rx(struct net_if * iface,uint32_t bytes)17static inline void eth_stats_update_bytes_rx(struct net_if *iface, 18 uint32_t bytes) 19 { 20 const struct ethernet_api *api = (const struct ethernet_api *) 21 net_if_get_device(iface)->api; 22 struct net_stats_eth *stats; 23 24 if (!api->get_stats) { 25 return; 26 } 27 28 stats = api->get_stats(net_if_get_device(iface)); 29 if (!stats) { 30 return; 31 } 32 33 stats->bytes.received += bytes; 34 } 35 eth_stats_update_bytes_tx(struct net_if * iface,uint32_t bytes)36static inline void eth_stats_update_bytes_tx(struct net_if *iface, 37 uint32_t bytes) 38 { 39 const struct ethernet_api *api = (const struct ethernet_api *) 40 net_if_get_device(iface)->api; 41 struct net_stats_eth *stats; 42 43 if (!api->get_stats) { 44 return; 45 } 46 47 stats = api->get_stats(net_if_get_device(iface)); 48 if (!stats) { 49 return; 50 } 51 52 stats->bytes.sent += bytes; 53 } 54 eth_stats_update_pkts_rx(struct net_if * iface)55static inline void eth_stats_update_pkts_rx(struct net_if *iface) 56 { 57 const struct ethernet_api *api = (const struct ethernet_api *) 58 net_if_get_device(iface)->api; 59 struct net_stats_eth *stats; 60 61 if (!api->get_stats) { 62 return; 63 } 64 65 stats = api->get_stats(net_if_get_device(iface)); 66 if (!stats) { 67 return; 68 } 69 70 stats->pkts.rx++; 71 } 72 eth_stats_update_pkts_tx(struct net_if * iface)73static inline void eth_stats_update_pkts_tx(struct net_if *iface) 74 { 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 } 82 83 stats = api->get_stats(net_if_get_device(iface)); 84 if (!stats) { 85 return; 86 } 87 88 stats->pkts.tx++; 89 } 90 eth_stats_update_broadcast_rx(struct net_if * iface)91static inline void eth_stats_update_broadcast_rx(struct net_if *iface) 92 { 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 } 100 101 stats = api->get_stats(net_if_get_device(iface)); 102 if (!stats) { 103 return; 104 } 105 106 stats->broadcast.rx++; 107 } 108 eth_stats_update_broadcast_tx(struct net_if * iface)109static inline void eth_stats_update_broadcast_tx(struct net_if *iface) 110 { 111 const struct ethernet_api *api = (const struct ethernet_api *) 112 net_if_get_device(iface)->api; 113 struct net_stats_eth *stats; 114 115 if (!api->get_stats) { 116 return; 117 } 118 119 stats = api->get_stats(net_if_get_device(iface)); 120 if (!stats) { 121 return; 122 } 123 124 stats->broadcast.tx++; 125 } 126 eth_stats_update_multicast_rx(struct net_if * iface)127static inline void eth_stats_update_multicast_rx(struct net_if *iface) 128 { 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 } 136 137 stats = api->get_stats(net_if_get_device(iface)); 138 if (!stats) { 139 return; 140 } 141 142 stats->multicast.rx++; 143 } 144 eth_stats_update_multicast_tx(struct net_if * iface)145static inline void eth_stats_update_multicast_tx(struct net_if *iface) 146 { 147 const struct ethernet_api *api = (const struct ethernet_api *) 148 net_if_get_device(iface)->api; 149 struct net_stats_eth *stats; 150 151 if (!api->get_stats) { 152 return; 153 } 154 155 stats = api->get_stats(net_if_get_device(iface)); 156 if (!stats) { 157 return; 158 } 159 160 stats->multicast.tx++; 161 } 162 163 eth_stats_update_errors_rx(struct net_if * iface)164static inline void eth_stats_update_errors_rx(struct net_if *iface) 165 { 166 struct net_stats_eth *stats; 167 const struct ethernet_api *api; 168 169 if (!iface) { 170 return; 171 } 172 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; 183 } 184 185 stats->errors.rx++; 186 } 187 eth_stats_update_errors_tx(struct net_if * iface)188static inline void eth_stats_update_errors_tx(struct net_if *iface) 189 { 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 } 197 198 stats = api->get_stats(net_if_get_device(iface)); 199 if (!stats) { 200 return; 201 } 202 203 stats->errors.tx++; 204 } 205 eth_stats_update_unknown_protocol(struct net_if * iface)206static inline void eth_stats_update_unknown_protocol(struct net_if *iface) 207 { 208 struct net_stats_eth *stats; 209 const struct ethernet_api *api = ((const struct ethernet_api *) 210 net_if_get_device(iface)->api); 211 212 if (!api->get_stats) { 213 return; 214 } 215 216 stats = api->get_stats(net_if_get_device(iface)); 217 if (!stats) { 218 return; 219 } 220 221 stats->unknown_protocol++; 222 } 223 224 #else /* CONFIG_NET_STATISTICS_ETHERNET */ 225 226 #define eth_stats_update_bytes_rx(iface, bytes) 227 #define eth_stats_update_bytes_tx(iface, bytes) 228 #define eth_stats_update_pkts_rx(iface) 229 #define eth_stats_update_pkts_tx(iface) 230 #define eth_stats_update_broadcast_rx(iface) 231 #define eth_stats_update_broadcast_tx(iface) 232 #define eth_stats_update_multicast_rx(iface) 233 #define eth_stats_update_multicast_tx(iface) 234 #define eth_stats_update_errors_rx(iface) 235 #define eth_stats_update_errors_tx(iface) 236 #define eth_stats_update_unknown_protocol(iface) 237 238 #endif /* CONFIG_NET_STATISTICS_ETHERNET */ 239 240 #endif /* __ETH_STATS_H__ */ 241