162306a36Sopenharmony_ci// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
262306a36Sopenharmony_ci/* Copyright (C) 2019 Netronome Systems, Inc. */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#include <linux/proc_fs.h>
562306a36Sopenharmony_ci#include <linux/seq_file.h>
662306a36Sopenharmony_ci#include <net/snmp.h>
762306a36Sopenharmony_ci#include <net/tls.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include "tls.h"
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifdef CONFIG_PROC_FS
1262306a36Sopenharmony_cistatic const struct snmp_mib tls_mib_list[] = {
1362306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrTxSw", LINUX_MIB_TLSCURRTXSW),
1462306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrRxSw", LINUX_MIB_TLSCURRRXSW),
1562306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrTxDevice", LINUX_MIB_TLSCURRTXDEVICE),
1662306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrRxDevice", LINUX_MIB_TLSCURRRXDEVICE),
1762306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsTxSw", LINUX_MIB_TLSTXSW),
1862306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsRxSw", LINUX_MIB_TLSRXSW),
1962306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsTxDevice", LINUX_MIB_TLSTXDEVICE),
2062306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsRxDevice", LINUX_MIB_TLSRXDEVICE),
2162306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsDecryptError", LINUX_MIB_TLSDECRYPTERROR),
2262306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsRxDeviceResync", LINUX_MIB_TLSRXDEVICERESYNC),
2362306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsDecryptRetry", LINUX_MIB_TLSDECRYPTRETRY),
2462306a36Sopenharmony_ci	SNMP_MIB_ITEM("TlsRxNoPadViolation", LINUX_MIB_TLSRXNOPADVIOL),
2562306a36Sopenharmony_ci	SNMP_MIB_SENTINEL
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_cistatic int tls_statistics_seq_show(struct seq_file *seq, void *v)
2962306a36Sopenharmony_ci{
3062306a36Sopenharmony_ci	unsigned long buf[LINUX_MIB_TLSMAX] = {};
3162306a36Sopenharmony_ci	struct net *net = seq->private;
3262306a36Sopenharmony_ci	int i;
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci	snmp_get_cpu_field_batch(buf, tls_mib_list, net->mib.tls_statistics);
3562306a36Sopenharmony_ci	for (i = 0; tls_mib_list[i].name; i++)
3662306a36Sopenharmony_ci		seq_printf(seq, "%-32s\t%lu\n", tls_mib_list[i].name, buf[i]);
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci	return 0;
3962306a36Sopenharmony_ci}
4062306a36Sopenharmony_ci#endif
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciint __net_init tls_proc_init(struct net *net)
4362306a36Sopenharmony_ci{
4462306a36Sopenharmony_ci#ifdef CONFIG_PROC_FS
4562306a36Sopenharmony_ci	if (!proc_create_net_single("tls_stat", 0444, net->proc_net,
4662306a36Sopenharmony_ci				    tls_statistics_seq_show, NULL))
4762306a36Sopenharmony_ci		return -ENOMEM;
4862306a36Sopenharmony_ci#endif /* CONFIG_PROC_FS */
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci	return 0;
5162306a36Sopenharmony_ci}
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_civoid __net_exit tls_proc_fini(struct net *net)
5462306a36Sopenharmony_ci{
5562306a36Sopenharmony_ci	remove_proc_entry("tls_stat", net->proc_net);
5662306a36Sopenharmony_ci}
57