xref: /openbmc/linux/net/rxrpc/proc.c (revision a00ce28b)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
28c3e34a4SDavid Howells /* /proc/net/ support for AF_RXRPC
38c3e34a4SDavid Howells  *
48c3e34a4SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
58c3e34a4SDavid Howells  * Written by David Howells (dhowells@redhat.com)
68c3e34a4SDavid Howells  */
78c3e34a4SDavid Howells 
88c3e34a4SDavid Howells #include <linux/module.h>
98c3e34a4SDavid Howells #include <net/sock.h>
108c3e34a4SDavid Howells #include <net/af_rxrpc.h>
118c3e34a4SDavid Howells #include "ar-internal.h"
128c3e34a4SDavid Howells 
13bba304dbSDavid Howells static const char *const rxrpc_conn_states[RXRPC_CONN__NR_STATES] = {
148c3e34a4SDavid Howells 	[RXRPC_CONN_UNUSED]			= "Unused  ",
158c3e34a4SDavid Howells 	[RXRPC_CONN_CLIENT]			= "Client  ",
1600e90712SDavid Howells 	[RXRPC_CONN_SERVICE_PREALLOC]		= "SvPrealc",
17bba304dbSDavid Howells 	[RXRPC_CONN_SERVICE_UNSECURED]		= "SvUnsec ",
18bba304dbSDavid Howells 	[RXRPC_CONN_SERVICE_CHALLENGING]	= "SvChall ",
19bba304dbSDavid Howells 	[RXRPC_CONN_SERVICE]			= "SvSecure",
20*a00ce28bSDavid Howells 	[RXRPC_CONN_ABORTED]			= "Aborted ",
218c3e34a4SDavid Howells };
228c3e34a4SDavid Howells 
238c3e34a4SDavid Howells /*
248c3e34a4SDavid Howells  * generate a list of extant and dead calls in /proc/net/rxrpc_calls
258c3e34a4SDavid Howells  */
268c3e34a4SDavid Howells static void *rxrpc_call_seq_start(struct seq_file *seq, loff_t *_pos)
2788f2a825SDavid Howells 	__acquires(rcu)
288c3e34a4SDavid Howells {
292baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
302baec2c3SDavid Howells 
318d94aa38SDavid Howells 	rcu_read_lock();
32ad25f5cbSDavid Howells 	return seq_list_start_head_rcu(&rxnet->calls, *_pos);
338c3e34a4SDavid Howells }
348c3e34a4SDavid Howells 
358c3e34a4SDavid Howells static void *rxrpc_call_seq_next(struct seq_file *seq, void *v, loff_t *pos)
368c3e34a4SDavid Howells {
372baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
382baec2c3SDavid Howells 
39ad25f5cbSDavid Howells 	return seq_list_next_rcu(v, &rxnet->calls, pos);
408c3e34a4SDavid Howells }
418c3e34a4SDavid Howells 
428c3e34a4SDavid Howells static void rxrpc_call_seq_stop(struct seq_file *seq, void *v)
4388f2a825SDavid Howells 	__releases(rcu)
448c3e34a4SDavid Howells {
458d94aa38SDavid Howells 	rcu_read_unlock();
468c3e34a4SDavid Howells }
478c3e34a4SDavid Howells 
488c3e34a4SDavid Howells static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
498c3e34a4SDavid Howells {
50df5d8bf7SDavid Howells 	struct rxrpc_local *local;
518c3e34a4SDavid Howells 	struct rxrpc_call *call;
522baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
53770b26deSWei Yongjun 	unsigned long timeout = 0;
54a4ea4c47SDavid Howells 	rxrpc_seq_t acks_hard_ack;
5575b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
565d7edbc9SDavid Howells 	u64 wtmp;
578c3e34a4SDavid Howells 
582baec2c3SDavid Howells 	if (v == &rxnet->calls) {
598c3e34a4SDavid Howells 		seq_puts(seq,
6075b54cb5SDavid Howells 			 "Proto Local                                          "
6175b54cb5SDavid Howells 			 " Remote                                         "
628c3e34a4SDavid Howells 			 " SvID ConnID   CallID   End Use State    Abort   "
635086d9a9SDavid Howells 			 " DebugId  TxSeq    TW RxSeq    RW RxSerial CW RxTimo\n");
648c3e34a4SDavid Howells 		return 0;
658c3e34a4SDavid Howells 	}
668c3e34a4SDavid Howells 
678c3e34a4SDavid Howells 	call = list_entry(v, struct rxrpc_call, link);
688c3e34a4SDavid Howells 
69f3441d41SDavid Howells 	local = call->local;
70df5d8bf7SDavid Howells 	if (local)
7175b54cb5SDavid Howells 		sprintf(lbuff, "%pISpc", &local->srx.transport);
72df5d8bf7SDavid Howells 	else
73df5d8bf7SDavid Howells 		strcpy(lbuff, "no_local");
748c3e34a4SDavid Howells 
75f3441d41SDavid Howells 	sprintf(rbuff, "%pISpc", &call->dest_srx.transport);
768c3e34a4SDavid Howells 
77887763bbSDavid Howells 	if (call->state != RXRPC_CALL_SERVER_PREALLOC) {
78887763bbSDavid Howells 		timeout = READ_ONCE(call->expect_rx_by);
79887763bbSDavid Howells 		timeout -= jiffies;
80887763bbSDavid Howells 	}
81887763bbSDavid Howells 
82a4ea4c47SDavid Howells 	acks_hard_ack = READ_ONCE(call->acks_hard_ack);
835d7edbc9SDavid Howells 	wtmp   = atomic64_read_acquire(&call->ackr_window);
848c3e34a4SDavid Howells 	seq_printf(seq,
8575b54cb5SDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %08x %s %3u"
865086d9a9SDavid Howells 		   " %-8.8s %08x %08x %08x %02x %08x %02x %08x %02x %06lx\n",
878c3e34a4SDavid Howells 		   lbuff,
888c3e34a4SDavid Howells 		   rbuff,
89f3441d41SDavid Howells 		   call->dest_srx.srx_service,
908c3e34a4SDavid Howells 		   call->cid,
918c3e34a4SDavid Howells 		   call->call_id,
92dabe5a79SDavid Howells 		   rxrpc_is_service_call(call) ? "Svc" : "Clt",
93a0575429SDavid Howells 		   refcount_read(&call->ref),
948c3e34a4SDavid Howells 		   rxrpc_call_states[call->state],
95f5c17aaeSDavid Howells 		   call->abort_code,
9632f71aa4SDavid Howells 		   call->debug_id,
97a4ea4c47SDavid Howells 		   acks_hard_ack, READ_ONCE(call->tx_top) - acks_hard_ack,
985d7edbc9SDavid Howells 		   lower_32_bits(wtmp), upper_32_bits(wtmp) - lower_32_bits(wtmp),
996b97bd7aSDavid Howells 		   call->rx_serial,
1005086d9a9SDavid Howells 		   call->cong_cwnd,
101887763bbSDavid Howells 		   timeout);
1028c3e34a4SDavid Howells 
1038c3e34a4SDavid Howells 	return 0;
1048c3e34a4SDavid Howells }
1058c3e34a4SDavid Howells 
106c3506372SChristoph Hellwig const struct seq_operations rxrpc_call_seq_ops = {
1078c3e34a4SDavid Howells 	.start  = rxrpc_call_seq_start,
1088c3e34a4SDavid Howells 	.next   = rxrpc_call_seq_next,
1098c3e34a4SDavid Howells 	.stop   = rxrpc_call_seq_stop,
1108c3e34a4SDavid Howells 	.show   = rxrpc_call_seq_show,
1118c3e34a4SDavid Howells };
1128c3e34a4SDavid Howells 
1138c3e34a4SDavid Howells /*
1148c3e34a4SDavid Howells  * generate a list of extant virtual connections in /proc/net/rxrpc_conns
1158c3e34a4SDavid Howells  */
1168c3e34a4SDavid Howells static void *rxrpc_connection_seq_start(struct seq_file *seq, loff_t *_pos)
11788f2a825SDavid Howells 	__acquires(rxnet->conn_lock)
1188c3e34a4SDavid Howells {
1192baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1202baec2c3SDavid Howells 
1212baec2c3SDavid Howells 	read_lock(&rxnet->conn_lock);
1222baec2c3SDavid Howells 	return seq_list_start_head(&rxnet->conn_proc_list, *_pos);
1238c3e34a4SDavid Howells }
1248c3e34a4SDavid Howells 
1258c3e34a4SDavid Howells static void *rxrpc_connection_seq_next(struct seq_file *seq, void *v,
1268c3e34a4SDavid Howells 				       loff_t *pos)
1278c3e34a4SDavid Howells {
1282baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1292baec2c3SDavid Howells 
1302baec2c3SDavid Howells 	return seq_list_next(v, &rxnet->conn_proc_list, pos);
1318c3e34a4SDavid Howells }
1328c3e34a4SDavid Howells 
1338c3e34a4SDavid Howells static void rxrpc_connection_seq_stop(struct seq_file *seq, void *v)
13488f2a825SDavid Howells 	__releases(rxnet->conn_lock)
1358c3e34a4SDavid Howells {
1362baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
1372baec2c3SDavid Howells 
1382baec2c3SDavid Howells 	read_unlock(&rxnet->conn_lock);
1398c3e34a4SDavid Howells }
1408c3e34a4SDavid Howells 
1418c3e34a4SDavid Howells static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
1428c3e34a4SDavid Howells {
1438c3e34a4SDavid Howells 	struct rxrpc_connection *conn;
1442baec2c3SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
145*a00ce28bSDavid Howells 	const char *state;
14675b54cb5SDavid Howells 	char lbuff[50], rbuff[50];
1478c3e34a4SDavid Howells 
1482baec2c3SDavid Howells 	if (v == &rxnet->conn_proc_list) {
1498c3e34a4SDavid Howells 		seq_puts(seq,
15075b54cb5SDavid Howells 			 "Proto Local                                          "
15175b54cb5SDavid Howells 			 " Remote                                         "
1523cec055cSDavid Howells 			 " SvID ConnID   End Ref Act State    Key     "
153245500d8SDavid Howells 			 " Serial   ISerial  CallId0  CallId1  CallId2  CallId3\n"
1548c3e34a4SDavid Howells 			 );
1558c3e34a4SDavid Howells 		return 0;
1568c3e34a4SDavid Howells 	}
1578c3e34a4SDavid Howells 
1584d028b2cSDavid Howells 	conn = list_entry(v, struct rxrpc_connection, proc_link);
15900e90712SDavid Howells 	if (conn->state == RXRPC_CONN_SERVICE_PREALLOC) {
16000e90712SDavid Howells 		strcpy(lbuff, "no_local");
16100e90712SDavid Howells 		strcpy(rbuff, "no_connection");
16200e90712SDavid Howells 		goto print;
16300e90712SDavid Howells 	}
1648c3e34a4SDavid Howells 
1652cc80086SDavid Howells 	sprintf(lbuff, "%pISpc", &conn->local->srx.transport);
1662cc80086SDavid Howells 	sprintf(rbuff, "%pISpc", &conn->peer->srx.transport);
16700e90712SDavid Howells print:
168*a00ce28bSDavid Howells 	state = rxrpc_is_conn_aborted(conn) ?
169*a00ce28bSDavid Howells 		rxrpc_call_completions[conn->completion] :
170*a00ce28bSDavid Howells 		rxrpc_conn_states[conn->state];
1718c3e34a4SDavid Howells 	seq_printf(seq,
1723cec055cSDavid Howells 		   "UDP   %-47.47s %-47.47s %4x %08x %s %3u %3d"
1736b97bd7aSDavid Howells 		   " %s %08x %08x %08x %08x %08x %08x %08x\n",
1748c3e34a4SDavid Howells 		   lbuff,
1758c3e34a4SDavid Howells 		   rbuff,
17668d6d1aeSDavid Howells 		   conn->service_id,
17719ffa01cSDavid Howells 		   conn->proto.cid,
17819ffa01cSDavid Howells 		   rxrpc_conn_is_service(conn) ? "Svc" : "Clt",
179a0575429SDavid Howells 		   refcount_read(&conn->ref),
1803cec055cSDavid Howells 		   atomic_read(&conn->active),
181*a00ce28bSDavid Howells 		   state,
1822cc80086SDavid Howells 		   key_serial(conn->key),
1838c3e34a4SDavid Howells 		   atomic_read(&conn->serial),
1846b97bd7aSDavid Howells 		   conn->hi_serial,
1856b97bd7aSDavid Howells 		   conn->channels[0].call_id,
1866b97bd7aSDavid Howells 		   conn->channels[1].call_id,
1876b97bd7aSDavid Howells 		   conn->channels[2].call_id,
1886b97bd7aSDavid Howells 		   conn->channels[3].call_id);
1898c3e34a4SDavid Howells 
1908c3e34a4SDavid Howells 	return 0;
1918c3e34a4SDavid Howells }
1928c3e34a4SDavid Howells 
193c3506372SChristoph Hellwig const struct seq_operations rxrpc_connection_seq_ops = {
1948c3e34a4SDavid Howells 	.start  = rxrpc_connection_seq_start,
1958c3e34a4SDavid Howells 	.next   = rxrpc_connection_seq_next,
1968c3e34a4SDavid Howells 	.stop   = rxrpc_connection_seq_stop,
1978c3e34a4SDavid Howells 	.show   = rxrpc_connection_seq_show,
1988c3e34a4SDavid Howells };
199bc0e7cf4SDavid Howells 
200bc0e7cf4SDavid Howells /*
201bc0e7cf4SDavid Howells  * generate a list of extant virtual peers in /proc/net/rxrpc/peers
202bc0e7cf4SDavid Howells  */
203bc0e7cf4SDavid Howells static int rxrpc_peer_seq_show(struct seq_file *seq, void *v)
204bc0e7cf4SDavid Howells {
205bc0e7cf4SDavid Howells 	struct rxrpc_peer *peer;
206bc0e7cf4SDavid Howells 	time64_t now;
207bc0e7cf4SDavid Howells 	char lbuff[50], rbuff[50];
208bc0e7cf4SDavid Howells 
209bc0e7cf4SDavid Howells 	if (v == SEQ_START_TOKEN) {
210bc0e7cf4SDavid Howells 		seq_puts(seq,
211bc0e7cf4SDavid Howells 			 "Proto Local                                          "
212bc0e7cf4SDavid Howells 			 " Remote                                         "
2131fc4fa2aSDavid Howells 			 " Use SST   MTU LastUse      RTT      RTO\n"
214bc0e7cf4SDavid Howells 			 );
215bc0e7cf4SDavid Howells 		return 0;
216bc0e7cf4SDavid Howells 	}
217bc0e7cf4SDavid Howells 
218bc0e7cf4SDavid Howells 	peer = list_entry(v, struct rxrpc_peer, hash_link);
219bc0e7cf4SDavid Howells 
220bc0e7cf4SDavid Howells 	sprintf(lbuff, "%pISpc", &peer->local->srx.transport);
221bc0e7cf4SDavid Howells 
222bc0e7cf4SDavid Howells 	sprintf(rbuff, "%pISpc", &peer->srx.transport);
223bc0e7cf4SDavid Howells 
224bc0e7cf4SDavid Howells 	now = ktime_get_seconds();
225bc0e7cf4SDavid Howells 	seq_printf(seq,
226bc0e7cf4SDavid Howells 		   "UDP   %-47.47s %-47.47s %3u"
227c410bf01SDavid Howells 		   " %3u %5u %6llus %8u %8u\n",
228bc0e7cf4SDavid Howells 		   lbuff,
229bc0e7cf4SDavid Howells 		   rbuff,
230a0575429SDavid Howells 		   refcount_read(&peer->ref),
2311fc4fa2aSDavid Howells 		   peer->cong_ssthresh,
232bc0e7cf4SDavid Howells 		   peer->mtu,
233bc0e7cf4SDavid Howells 		   now - peer->last_tx_at,
234c410bf01SDavid Howells 		   peer->srtt_us >> 3,
235c410bf01SDavid Howells 		   jiffies_to_usecs(peer->rto_j));
236bc0e7cf4SDavid Howells 
237bc0e7cf4SDavid Howells 	return 0;
238bc0e7cf4SDavid Howells }
239bc0e7cf4SDavid Howells 
240bc0e7cf4SDavid Howells static void *rxrpc_peer_seq_start(struct seq_file *seq, loff_t *_pos)
241bc0e7cf4SDavid Howells 	__acquires(rcu)
242bc0e7cf4SDavid Howells {
243bc0e7cf4SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
244bc0e7cf4SDavid Howells 	unsigned int bucket, n;
245bc0e7cf4SDavid Howells 	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
246bc0e7cf4SDavid Howells 	void *p;
247bc0e7cf4SDavid Howells 
248bc0e7cf4SDavid Howells 	rcu_read_lock();
249bc0e7cf4SDavid Howells 
250bc0e7cf4SDavid Howells 	if (*_pos >= UINT_MAX)
251bc0e7cf4SDavid Howells 		return NULL;
252bc0e7cf4SDavid Howells 
253bc0e7cf4SDavid Howells 	n = *_pos & ((1U << shift) - 1);
254bc0e7cf4SDavid Howells 	bucket = *_pos >> shift;
255bc0e7cf4SDavid Howells 	for (;;) {
256bc0e7cf4SDavid Howells 		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
257bc0e7cf4SDavid Howells 			*_pos = UINT_MAX;
258bc0e7cf4SDavid Howells 			return NULL;
259bc0e7cf4SDavid Howells 		}
260bc0e7cf4SDavid Howells 		if (n == 0) {
261bc0e7cf4SDavid Howells 			if (bucket == 0)
262bc0e7cf4SDavid Howells 				return SEQ_START_TOKEN;
263bc0e7cf4SDavid Howells 			*_pos += 1;
264bc0e7cf4SDavid Howells 			n++;
265bc0e7cf4SDavid Howells 		}
266bc0e7cf4SDavid Howells 
267bc0e7cf4SDavid Howells 		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
268bc0e7cf4SDavid Howells 		if (p)
269bc0e7cf4SDavid Howells 			return p;
270bc0e7cf4SDavid Howells 		bucket++;
271bc0e7cf4SDavid Howells 		n = 1;
272bc0e7cf4SDavid Howells 		*_pos = (bucket << shift) | n;
273bc0e7cf4SDavid Howells 	}
274bc0e7cf4SDavid Howells }
275bc0e7cf4SDavid Howells 
276bc0e7cf4SDavid Howells static void *rxrpc_peer_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
277bc0e7cf4SDavid Howells {
278bc0e7cf4SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
279bc0e7cf4SDavid Howells 	unsigned int bucket, n;
280bc0e7cf4SDavid Howells 	unsigned int shift = 32 - HASH_BITS(rxnet->peer_hash);
281bc0e7cf4SDavid Howells 	void *p;
282bc0e7cf4SDavid Howells 
283bc0e7cf4SDavid Howells 	if (*_pos >= UINT_MAX)
284bc0e7cf4SDavid Howells 		return NULL;
285bc0e7cf4SDavid Howells 
286bc0e7cf4SDavid Howells 	bucket = *_pos >> shift;
287bc0e7cf4SDavid Howells 
288bc0e7cf4SDavid Howells 	p = seq_hlist_next_rcu(v, &rxnet->peer_hash[bucket], _pos);
289bc0e7cf4SDavid Howells 	if (p)
290bc0e7cf4SDavid Howells 		return p;
291bc0e7cf4SDavid Howells 
292bc0e7cf4SDavid Howells 	for (;;) {
293bc0e7cf4SDavid Howells 		bucket++;
294bc0e7cf4SDavid Howells 		n = 1;
295bc0e7cf4SDavid Howells 		*_pos = (bucket << shift) | n;
296bc0e7cf4SDavid Howells 
297bc0e7cf4SDavid Howells 		if (bucket >= HASH_SIZE(rxnet->peer_hash)) {
298bc0e7cf4SDavid Howells 			*_pos = UINT_MAX;
299bc0e7cf4SDavid Howells 			return NULL;
300bc0e7cf4SDavid Howells 		}
301bc0e7cf4SDavid Howells 		if (n == 0) {
302bc0e7cf4SDavid Howells 			*_pos += 1;
303bc0e7cf4SDavid Howells 			n++;
304bc0e7cf4SDavid Howells 		}
305bc0e7cf4SDavid Howells 
306bc0e7cf4SDavid Howells 		p = seq_hlist_start_rcu(&rxnet->peer_hash[bucket], n - 1);
307bc0e7cf4SDavid Howells 		if (p)
308bc0e7cf4SDavid Howells 			return p;
309bc0e7cf4SDavid Howells 	}
310bc0e7cf4SDavid Howells }
311bc0e7cf4SDavid Howells 
312bc0e7cf4SDavid Howells static void rxrpc_peer_seq_stop(struct seq_file *seq, void *v)
313bc0e7cf4SDavid Howells 	__releases(rcu)
314bc0e7cf4SDavid Howells {
315bc0e7cf4SDavid Howells 	rcu_read_unlock();
316bc0e7cf4SDavid Howells }
317bc0e7cf4SDavid Howells 
318bc0e7cf4SDavid Howells 
319bc0e7cf4SDavid Howells const struct seq_operations rxrpc_peer_seq_ops = {
320bc0e7cf4SDavid Howells 	.start  = rxrpc_peer_seq_start,
321bc0e7cf4SDavid Howells 	.next   = rxrpc_peer_seq_next,
322bc0e7cf4SDavid Howells 	.stop   = rxrpc_peer_seq_stop,
323bc0e7cf4SDavid Howells 	.show   = rxrpc_peer_seq_show,
324bc0e7cf4SDavid Howells };
32533912c26SDavid Howells 
32633912c26SDavid Howells /*
32733912c26SDavid Howells  * Generate a list of extant virtual local endpoints in /proc/net/rxrpc/locals
32833912c26SDavid Howells  */
32933912c26SDavid Howells static int rxrpc_local_seq_show(struct seq_file *seq, void *v)
33033912c26SDavid Howells {
33133912c26SDavid Howells 	struct rxrpc_local *local;
33233912c26SDavid Howells 	char lbuff[50];
33333912c26SDavid Howells 
33433912c26SDavid Howells 	if (v == SEQ_START_TOKEN) {
33533912c26SDavid Howells 		seq_puts(seq,
33633912c26SDavid Howells 			 "Proto Local                                          "
337a275da62SDavid Howells 			 " Use Act RxQ\n");
33833912c26SDavid Howells 		return 0;
33933912c26SDavid Howells 	}
34033912c26SDavid Howells 
34133912c26SDavid Howells 	local = hlist_entry(v, struct rxrpc_local, link);
34233912c26SDavid Howells 
34333912c26SDavid Howells 	sprintf(lbuff, "%pISpc", &local->srx.transport);
34433912c26SDavid Howells 
34533912c26SDavid Howells 	seq_printf(seq,
346a275da62SDavid Howells 		   "UDP   %-47.47s %3u %3u %3u\n",
34733912c26SDavid Howells 		   lbuff,
348a0575429SDavid Howells 		   refcount_read(&local->ref),
349a275da62SDavid Howells 		   atomic_read(&local->active_users),
350a275da62SDavid Howells 		   local->rx_queue.qlen);
35133912c26SDavid Howells 
35233912c26SDavid Howells 	return 0;
35333912c26SDavid Howells }
35433912c26SDavid Howells 
35533912c26SDavid Howells static void *rxrpc_local_seq_start(struct seq_file *seq, loff_t *_pos)
35633912c26SDavid Howells 	__acquires(rcu)
35733912c26SDavid Howells {
35833912c26SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
35933912c26SDavid Howells 	unsigned int n;
36033912c26SDavid Howells 
36133912c26SDavid Howells 	rcu_read_lock();
36233912c26SDavid Howells 
36333912c26SDavid Howells 	if (*_pos >= UINT_MAX)
36433912c26SDavid Howells 		return NULL;
36533912c26SDavid Howells 
36633912c26SDavid Howells 	n = *_pos;
36733912c26SDavid Howells 	if (n == 0)
36833912c26SDavid Howells 		return SEQ_START_TOKEN;
36933912c26SDavid Howells 
37033912c26SDavid Howells 	return seq_hlist_start_rcu(&rxnet->local_endpoints, n - 1);
37133912c26SDavid Howells }
37233912c26SDavid Howells 
37333912c26SDavid Howells static void *rxrpc_local_seq_next(struct seq_file *seq, void *v, loff_t *_pos)
37433912c26SDavid Howells {
37533912c26SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
37633912c26SDavid Howells 
37733912c26SDavid Howells 	if (*_pos >= UINT_MAX)
37833912c26SDavid Howells 		return NULL;
37933912c26SDavid Howells 
38033912c26SDavid Howells 	return seq_hlist_next_rcu(v, &rxnet->local_endpoints, _pos);
38133912c26SDavid Howells }
38233912c26SDavid Howells 
38333912c26SDavid Howells static void rxrpc_local_seq_stop(struct seq_file *seq, void *v)
38433912c26SDavid Howells 	__releases(rcu)
38533912c26SDavid Howells {
38633912c26SDavid Howells 	rcu_read_unlock();
38733912c26SDavid Howells }
38833912c26SDavid Howells 
38933912c26SDavid Howells const struct seq_operations rxrpc_local_seq_ops = {
39033912c26SDavid Howells 	.start  = rxrpc_local_seq_start,
39133912c26SDavid Howells 	.next   = rxrpc_local_seq_next,
39233912c26SDavid Howells 	.stop   = rxrpc_local_seq_stop,
39333912c26SDavid Howells 	.show   = rxrpc_local_seq_show,
39433912c26SDavid Howells };
395b0154246SDavid Howells 
396b0154246SDavid Howells /*
397b0154246SDavid Howells  * Display stats in /proc/net/rxrpc/stats
398b0154246SDavid Howells  */
399b0154246SDavid Howells int rxrpc_stats_show(struct seq_file *seq, void *v)
400b0154246SDavid Howells {
401b0154246SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(seq));
402b0154246SDavid Howells 
403b0154246SDavid Howells 	seq_printf(seq,
40432cf8edbSDavid Howells 		   "Data     : send=%u sendf=%u fail=%u\n",
405b0154246SDavid Howells 		   atomic_read(&rxnet->stat_tx_data_send),
40632cf8edbSDavid Howells 		   atomic_read(&rxnet->stat_tx_data_send_frag),
40732cf8edbSDavid Howells 		   atomic_read(&rxnet->stat_tx_data_send_fail));
408b0154246SDavid Howells 	seq_printf(seq,
40932cf8edbSDavid Howells 		   "Data-Tx  : nr=%u retrans=%u uf=%u cwr=%u\n",
410b0154246SDavid Howells 		   atomic_read(&rxnet->stat_tx_data),
41132cf8edbSDavid Howells 		   atomic_read(&rxnet->stat_tx_data_retrans),
41232cf8edbSDavid Howells 		   atomic_read(&rxnet->stat_tx_data_underflow),
41332cf8edbSDavid Howells 		   atomic_read(&rxnet->stat_tx_data_cwnd_reset));
414b0154246SDavid Howells 	seq_printf(seq,
415b0154246SDavid Howells 		   "Data-Rx  : nr=%u reqack=%u jumbo=%u\n",
416b0154246SDavid Howells 		   atomic_read(&rxnet->stat_rx_data),
417b0154246SDavid Howells 		   atomic_read(&rxnet->stat_rx_data_reqack),
418b0154246SDavid Howells 		   atomic_read(&rxnet->stat_rx_data_jumbo));
419b0154246SDavid Howells 	seq_printf(seq,
420f2a676d1SDavid Howells 		   "Ack      : fill=%u send=%u skip=%u\n",
421f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_ack_fill),
422f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_ack_send),
423f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_ack_skip));
424f2a676d1SDavid Howells 	seq_printf(seq,
425f2a676d1SDavid Howells 		   "Ack-Tx   : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
426f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_REQUESTED]),
427f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DUPLICATE]),
428f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
429f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
430f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_NOSPACE]),
431f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING]),
432f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_PING_RESPONSE]),
433f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_DELAY]),
434f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_tx_acks[RXRPC_ACK_IDLE]));
435f2a676d1SDavid Howells 	seq_printf(seq,
436f2a676d1SDavid Howells 		   "Ack-Rx   : req=%u dup=%u oos=%u exw=%u nos=%u png=%u prs=%u dly=%u idl=%u\n",
437f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_REQUESTED]),
438f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DUPLICATE]),
439f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_OUT_OF_SEQUENCE]),
440f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_EXCEEDS_WINDOW]),
441f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_NOSPACE]),
442f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING]),
443f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_PING_RESPONSE]),
444f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_DELAY]),
445f2a676d1SDavid Howells 		   atomic_read(&rxnet->stat_rx_acks[RXRPC_ACK_IDLE]));
446f2a676d1SDavid Howells 	seq_printf(seq,
447f7fa5242SDavid Howells 		   "Why-Req-A: acklost=%u already=%u mrtt=%u ortt=%u\n",
448f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_ack_lost]),
449f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_already_on]),
450f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_more_rtt]),
451f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_old_rtt]));
452f7fa5242SDavid Howells 	seq_printf(seq,
453f7fa5242SDavid Howells 		   "Why-Req-A: nolast=%u retx=%u slows=%u smtxw=%u\n",
454f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_no_srv_last]),
455f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_retrans]),
456f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_slow_start]),
457f7fa5242SDavid Howells 		   atomic_read(&rxnet->stat_why_req_ack[rxrpc_reqack_small_txwin]));
458f7fa5242SDavid Howells 	seq_printf(seq,
459a4ea4c47SDavid Howells 		   "Buffers  : txb=%u rxb=%u\n",
46002a19356SDavid Howells 		   atomic_read(&rxrpc_nr_txbuf),
461b0154246SDavid Howells 		   atomic_read(&rxrpc_n_rx_skbs));
462a275da62SDavid Howells 	seq_printf(seq,
463a275da62SDavid Howells 		   "IO-thread: loops=%u\n",
464a275da62SDavid Howells 		   atomic_read(&rxnet->stat_io_loop));
465b0154246SDavid Howells 	return 0;
466b0154246SDavid Howells }
467b0154246SDavid Howells 
468b0154246SDavid Howells /*
469b0154246SDavid Howells  * Clear stats if /proc/net/rxrpc/stats is written to.
470b0154246SDavid Howells  */
471b0154246SDavid Howells int rxrpc_stats_clear(struct file *file, char *buf, size_t size)
472b0154246SDavid Howells {
473b0154246SDavid Howells 	struct seq_file *m = file->private_data;
474b0154246SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_single_net(m));
475b0154246SDavid Howells 
476b0154246SDavid Howells 	if (size > 1 || (size == 1 && buf[0] != '\n'))
477b0154246SDavid Howells 		return -EINVAL;
478b0154246SDavid Howells 
479b0154246SDavid Howells 	atomic_set(&rxnet->stat_tx_data, 0);
480b0154246SDavid Howells 	atomic_set(&rxnet->stat_tx_data_retrans, 0);
48132cf8edbSDavid Howells 	atomic_set(&rxnet->stat_tx_data_underflow, 0);
48232cf8edbSDavid Howells 	atomic_set(&rxnet->stat_tx_data_cwnd_reset, 0);
483b0154246SDavid Howells 	atomic_set(&rxnet->stat_tx_data_send, 0);
484b0154246SDavid Howells 	atomic_set(&rxnet->stat_tx_data_send_frag, 0);
48532cf8edbSDavid Howells 	atomic_set(&rxnet->stat_tx_data_send_fail, 0);
486b0154246SDavid Howells 	atomic_set(&rxnet->stat_rx_data, 0);
487b0154246SDavid Howells 	atomic_set(&rxnet->stat_rx_data_reqack, 0);
488b0154246SDavid Howells 	atomic_set(&rxnet->stat_rx_data_jumbo, 0);
489f2a676d1SDavid Howells 
490f2a676d1SDavid Howells 	atomic_set(&rxnet->stat_tx_ack_fill, 0);
491f2a676d1SDavid Howells 	atomic_set(&rxnet->stat_tx_ack_send, 0);
492f2a676d1SDavid Howells 	atomic_set(&rxnet->stat_tx_ack_skip, 0);
493f2a676d1SDavid Howells 	memset(&rxnet->stat_tx_acks, 0, sizeof(rxnet->stat_tx_acks));
494f2a676d1SDavid Howells 	memset(&rxnet->stat_rx_acks, 0, sizeof(rxnet->stat_rx_acks));
495f7fa5242SDavid Howells 
496f7fa5242SDavid Howells 	memset(&rxnet->stat_why_req_ack, 0, sizeof(rxnet->stat_why_req_ack));
497a275da62SDavid Howells 
498a275da62SDavid Howells 	atomic_set(&rxnet->stat_io_loop, 0);
499b0154246SDavid Howells 	return size;
500b0154246SDavid Howells }
501