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