18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
28c2ecf20Sopenharmony_ci/* Copyright (C) 2019 Netronome Systems, Inc. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <linux/proc_fs.h>
58c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
68c2ecf20Sopenharmony_ci#include <net/snmp.h>
78c2ecf20Sopenharmony_ci#include <net/tls.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifdef CONFIG_PROC_FS
108c2ecf20Sopenharmony_cistatic const struct snmp_mib tls_mib_list[] = {
118c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrTxSw", LINUX_MIB_TLSCURRTXSW),
128c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrRxSw", LINUX_MIB_TLSCURRRXSW),
138c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrTxDevice", LINUX_MIB_TLSCURRTXDEVICE),
148c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsCurrRxDevice", LINUX_MIB_TLSCURRRXDEVICE),
158c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsTxSw", LINUX_MIB_TLSTXSW),
168c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsRxSw", LINUX_MIB_TLSRXSW),
178c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsTxDevice", LINUX_MIB_TLSTXDEVICE),
188c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsRxDevice", LINUX_MIB_TLSRXDEVICE),
198c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsDecryptError", LINUX_MIB_TLSDECRYPTERROR),
208c2ecf20Sopenharmony_ci	SNMP_MIB_ITEM("TlsRxDeviceResync", LINUX_MIB_TLSRXDEVICERESYNC),
218c2ecf20Sopenharmony_ci	SNMP_MIB_SENTINEL
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic int tls_statistics_seq_show(struct seq_file *seq, void *v)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	unsigned long buf[LINUX_MIB_TLSMAX] = {};
278c2ecf20Sopenharmony_ci	struct net *net = seq->private;
288c2ecf20Sopenharmony_ci	int i;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	snmp_get_cpu_field_batch(buf, tls_mib_list, net->mib.tls_statistics);
318c2ecf20Sopenharmony_ci	for (i = 0; tls_mib_list[i].name; i++)
328c2ecf20Sopenharmony_ci		seq_printf(seq, "%-32s\t%lu\n", tls_mib_list[i].name, buf[i]);
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	return 0;
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci#endif
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciint __net_init tls_proc_init(struct net *net)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci#ifdef CONFIG_PROC_FS
418c2ecf20Sopenharmony_ci	if (!proc_create_net_single("tls_stat", 0444, net->proc_net,
428c2ecf20Sopenharmony_ci				    tls_statistics_seq_show, NULL))
438c2ecf20Sopenharmony_ci		return -ENOMEM;
448c2ecf20Sopenharmony_ci#endif /* CONFIG_PROC_FS */
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	return 0;
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_civoid __net_exit tls_proc_fini(struct net *net)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	remove_proc_entry("tls_stat", net->proc_net);
528c2ecf20Sopenharmony_ci}
53