Blame view

net/hsr/hsr_debugfs.c 3.97 KB
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
1
  /*
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
2
   * hsr_debugfs code
327127338   Murali Karicheri   net: hsr: fix deb...
3
   * Copyright (C) 2019 Texas Instruments Incorporated
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
4
5
   *
   * Author(s):
327127338   Murali Karicheri   net: hsr: fix deb...
6
   *	Murali Karicheri <m-karicheri2@ti.com>
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
   * published by the Free Software Foundation version 2.
   *
   * This program is distributed "as is" WITHOUT ANY WARRANTY of any
   * kind, whether express or implied; without even the implied warranty
   * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   */
  #include <linux/module.h>
  #include <linux/errno.h>
  #include <linux/debugfs.h>
  #include "hsr_main.h"
  #include "hsr_framereg.h"
0299f24a9   Taehee Yoo   hsr: add hsr root...
22
  static struct dentry *hsr_debugfs_root_dir;
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
23
24
25
26
27
  static void print_mac_address(struct seq_file *sfp, unsigned char *mac)
  {
  	seq_printf(sfp, "%02x:%02x:%02x:%02x:%02x:%02x:",
  		   mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  }
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
28
  /* hsr_node_table_show - Formats and prints node_table entries */
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
29
  static int
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
30
  hsr_node_table_show(struct seq_file *sfp, void *data)
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  {
  	struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
  	struct hsr_node *node;
  
  	seq_puts(sfp, "Node Table entries
  ");
  	seq_puts(sfp, "MAC-Address-A,   MAC-Address-B, time_in[A], ");
  	seq_puts(sfp, "time_in[B], Address-B port
  ");
  	rcu_read_lock();
  	list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
  		/* skip self node */
  		if (hsr_addr_is_self(priv, node->macaddress_A))
  			continue;
  		print_mac_address(sfp, &node->macaddress_A[0]);
  		seq_puts(sfp, " ");
  		print_mac_address(sfp, &node->macaddress_B[0]);
  		seq_printf(sfp, "0x%lx, ", node->time_in[HSR_PT_SLAVE_A]);
  		seq_printf(sfp, "0x%lx ", node->time_in[HSR_PT_SLAVE_B]);
  		seq_printf(sfp, "0x%x
  ", node->addr_B_port);
  	}
  	rcu_read_unlock();
  	return 0;
  }
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
56
  /* hsr_node_table_open - Open the node_table file
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
57
58
59
60
61
   *
   * Description:
   * This routine opens a debugfs file node_table of specific hsr device
   */
  static int
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
62
  hsr_node_table_open(struct inode *inode, struct file *filp)
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
63
  {
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
64
  	return single_open(filp, hsr_node_table_show, inode->i_private);
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
65
  }
5f3ff0681   Taehee Yoo   hsr: rename debug...
66
67
68
69
70
71
72
73
74
75
76
77
78
  void hsr_debugfs_rename(struct net_device *dev)
  {
  	struct hsr_priv *priv = netdev_priv(dev);
  	struct dentry *d;
  
  	d = debugfs_rename(hsr_debugfs_root_dir, priv->node_tbl_root,
  			   hsr_debugfs_root_dir, dev->name);
  	if (IS_ERR(d))
  		netdev_warn(dev, "failed to rename
  ");
  	else
  		priv->node_tbl_root = d;
  }
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
79
  static const struct file_operations hsr_fops = {
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
80
  	.open	= hsr_node_table_open,
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
81
82
83
84
  	.read	= seq_read,
  	.llseek = seq_lseek,
  	.release = single_release,
  };
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
85
  /* hsr_debugfs_init - create hsr node_table file for dumping
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
86
87
88
89
   * the node table
   *
   * Description:
   * When debugfs is configured this routine sets up the node_table file per
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
90
   * hsr device for dumping the node_table entries
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
91
   */
fe974fba4   Taehee Yoo   hsr: fix error ha...
92
  void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
93
  {
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
94
  	struct dentry *de = NULL;
0299f24a9   Taehee Yoo   hsr: add hsr root...
95
  	de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
fe974fba4   Taehee Yoo   hsr: fix error ha...
96
  	if (IS_ERR(de)) {
0299f24a9   Taehee Yoo   hsr: add hsr root...
97
98
  		pr_err("Cannot create hsr debugfs directory
  ");
fe974fba4   Taehee Yoo   hsr: fix error ha...
99
  		return;
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
100
101
102
103
104
105
  	}
  
  	priv->node_tbl_root = de;
  
  	de = debugfs_create_file("node_table", S_IFREG | 0444,
  				 priv->node_tbl_root, priv,
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
106
  				 &hsr_fops);
fe974fba4   Taehee Yoo   hsr: fix error ha...
107
  	if (IS_ERR(de)) {
0299f24a9   Taehee Yoo   hsr: add hsr root...
108
109
  		pr_err("Cannot create hsr node_table file
  ");
fe974fba4   Taehee Yoo   hsr: fix error ha...
110
111
112
  		debugfs_remove(priv->node_tbl_root);
  		priv->node_tbl_root = NULL;
  		return;
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
113
114
  	}
  	priv->node_tbl_file = de;
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
115
  }
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
116
  /* hsr_debugfs_term - Tear down debugfs intrastructure
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
117
118
119
   *
   * Description:
   * When Debufs is configured this routine removes debugfs file system
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
120
   * elements that are specific to hsr
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
121
122
   */
  void
9c5f8a19b   Murali Karicheri   net: hsr: fix nam...
123
  hsr_debugfs_term(struct hsr_priv *priv)
fc4ecaeeb   Murali Karicheri   net: hsr: add deb...
124
125
126
127
128
129
  {
  	debugfs_remove(priv->node_tbl_file);
  	priv->node_tbl_file = NULL;
  	debugfs_remove(priv->node_tbl_root);
  	priv->node_tbl_root = NULL;
  }
0299f24a9   Taehee Yoo   hsr: add hsr root...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  
  void hsr_debugfs_create_root(void)
  {
  	hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
  	if (IS_ERR(hsr_debugfs_root_dir)) {
  		pr_err("Cannot create hsr debugfs root directory
  ");
  		hsr_debugfs_root_dir = NULL;
  	}
  }
  
  void hsr_debugfs_remove_root(void)
  {
  	/* debugfs_remove() internally checks NULL and ERROR */
  	debugfs_remove(hsr_debugfs_root_dir);
  }