Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netdevsim: implement psp device stats

For now only tx/rx packets/bytes are reported. This is not compliant
with the PSP Architecture Specification.

Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20251106002608.1578518-6-daniel.zahka@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Daniel Zahka and committed by
Jakub Kicinski
178f0763 b1346219

+32
+5
drivers/net/netdevsim/netdevsim.h
··· 109 109 int rq_reset_mode; 110 110 111 111 struct { 112 + u64 rx_packets; 113 + u64 rx_bytes; 114 + u64 tx_packets; 115 + u64 tx_bytes; 116 + struct u64_stats_sync syncp; 112 117 struct psp_dev *dev; 113 118 u32 spi; 114 119 u32 assoc_cnt;
+27
drivers/net/netdevsim/psp.c
··· 70 70 *psp_ext = skb->extensions; 71 71 refcount_inc(&(*psp_ext)->refcnt); 72 72 skb->decrypted = 1; 73 + 74 + u64_stats_update_begin(&ns->psp.syncp); 75 + ns->psp.tx_packets++; 76 + ns->psp.rx_packets++; 77 + ns->psp.tx_bytes += skb->len - skb_inner_transport_offset(skb); 78 + ns->psp.rx_bytes += skb->len - skb_inner_transport_offset(skb); 79 + u64_stats_update_end(&ns->psp.syncp); 73 80 } else { 74 81 struct ipv6hdr *ip6h __maybe_unused; 75 82 struct iphdr *iph; ··· 171 164 ns->psp.assoc_cnt--; 172 165 } 173 166 167 + static void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats) 168 + { 169 + struct netdevsim *ns = psd->drv_priv; 170 + unsigned int start; 171 + 172 + /* WARNING: do *not* blindly zero stats in real drivers! 173 + * All required stats must be reported by the device! 174 + */ 175 + memset(stats, 0, sizeof(struct psp_dev_stats)); 176 + 177 + do { 178 + start = u64_stats_fetch_begin(&ns->psp.syncp); 179 + stats->rx_bytes = ns->psp.rx_bytes; 180 + stats->rx_packets = ns->psp.rx_packets; 181 + stats->tx_bytes = ns->psp.tx_bytes; 182 + stats->tx_packets = ns->psp.tx_packets; 183 + } while (u64_stats_fetch_retry(&ns->psp.syncp, start)); 184 + } 185 + 174 186 static struct psp_dev_ops nsim_psp_ops = { 175 187 .set_config = nsim_psp_set_config, 176 188 .rx_spi_alloc = nsim_rx_spi_alloc, 177 189 .tx_key_add = nsim_assoc_add, 178 190 .tx_key_del = nsim_assoc_del, 179 191 .key_rotate = nsim_key_rotate, 192 + .get_stats = nsim_get_stats, 180 193 }; 181 194 182 195 static struct psp_dev_caps nsim_psp_caps = {