Blame view
net/6lowpan/debugfs.c
6.67 KB
1802d0bee treewide: Replace... |
1 2 |
// SPDX-License-Identifier: GPL-2.0-only /* |
b1815fd94 6lowpan: add debu... |
3 4 5 6 7 8 9 10 11 |
* * Authors: * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de> * Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. */ #include <net/6lowpan.h> #include "6lowpan_i.h" |
5609c185f 6lowpan: iphc: ad... |
12 |
#define LOWPAN_DEBUGFS_CTX_PFX_NUM_ARGS 8 |
b1815fd94 6lowpan: add debu... |
13 |
static struct dentry *lowpan_debugfs; |
5609c185f 6lowpan: iphc: ad... |
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
static int lowpan_ctx_flag_active_set(void *data, u64 val) { struct lowpan_iphc_ctx *ctx = data; if (val != 0 && val != 1) return -EINVAL; if (val) set_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE, &ctx->flags); else clear_bit(LOWPAN_IPHC_CTX_FLAG_ACTIVE, &ctx->flags); return 0; } static int lowpan_ctx_flag_active_get(void *data, u64 *val) { *val = lowpan_iphc_ctx_is_active(data); return 0; } |
5e053534b 6lowpan: fix debu... |
34 35 36 37 |
DEFINE_DEBUGFS_ATTRIBUTE(lowpan_ctx_flag_active_fops, lowpan_ctx_flag_active_get, lowpan_ctx_flag_active_set, "%llu "); |
5609c185f 6lowpan: iphc: ad... |
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
static int lowpan_ctx_flag_c_set(void *data, u64 val) { struct lowpan_iphc_ctx *ctx = data; if (val != 0 && val != 1) return -EINVAL; if (val) set_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags); else clear_bit(LOWPAN_IPHC_CTX_FLAG_COMPRESSION, &ctx->flags); return 0; } static int lowpan_ctx_flag_c_get(void *data, u64 *val) { *val = lowpan_iphc_ctx_is_compression(data); return 0; } |
5e053534b 6lowpan: fix debu... |
59 60 61 |
DEFINE_DEBUGFS_ATTRIBUTE(lowpan_ctx_flag_c_fops, lowpan_ctx_flag_c_get, lowpan_ctx_flag_c_set, "%llu "); |
5609c185f 6lowpan: iphc: ad... |
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
static int lowpan_ctx_plen_set(void *data, u64 val) { struct lowpan_iphc_ctx *ctx = data; struct lowpan_iphc_ctx_table *t = container_of(ctx, struct lowpan_iphc_ctx_table, table[ctx->id]); if (val > 128) return -EINVAL; spin_lock_bh(&t->lock); ctx->plen = val; spin_unlock_bh(&t->lock); return 0; } static int lowpan_ctx_plen_get(void *data, u64 *val) { struct lowpan_iphc_ctx *ctx = data; struct lowpan_iphc_ctx_table *t = container_of(ctx, struct lowpan_iphc_ctx_table, table[ctx->id]); spin_lock_bh(&t->lock); *val = ctx->plen; spin_unlock_bh(&t->lock); return 0; } |
5e053534b 6lowpan: fix debu... |
90 91 92 |
DEFINE_DEBUGFS_ATTRIBUTE(lowpan_ctx_plen_fops, lowpan_ctx_plen_get, lowpan_ctx_plen_set, "%llu "); |
5609c185f 6lowpan: iphc: ad... |
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
static int lowpan_ctx_pfx_show(struct seq_file *file, void *offset) { struct lowpan_iphc_ctx *ctx = file->private; struct lowpan_iphc_ctx_table *t = container_of(ctx, struct lowpan_iphc_ctx_table, table[ctx->id]); spin_lock_bh(&t->lock); seq_printf(file, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", be16_to_cpu(ctx->pfx.s6_addr16[0]), be16_to_cpu(ctx->pfx.s6_addr16[1]), be16_to_cpu(ctx->pfx.s6_addr16[2]), be16_to_cpu(ctx->pfx.s6_addr16[3]), be16_to_cpu(ctx->pfx.s6_addr16[4]), be16_to_cpu(ctx->pfx.s6_addr16[5]), be16_to_cpu(ctx->pfx.s6_addr16[6]), be16_to_cpu(ctx->pfx.s6_addr16[7])); spin_unlock_bh(&t->lock); return 0; } static int lowpan_ctx_pfx_open(struct inode *inode, struct file *file) { return single_open(file, lowpan_ctx_pfx_show, inode->i_private); } static ssize_t lowpan_ctx_pfx_write(struct file *fp, const char __user *user_buf, size_t count, loff_t *ppos) { char buf[128] = {}; struct seq_file *file = fp->private_data; struct lowpan_iphc_ctx *ctx = file->private; struct lowpan_iphc_ctx_table *t = container_of(ctx, struct lowpan_iphc_ctx_table, table[ctx->id]); int status = count, n, i; unsigned int addr[8]; if (copy_from_user(&buf, user_buf, min_t(size_t, sizeof(buf) - 1, count))) { status = -EFAULT; goto out; } n = sscanf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5], &addr[6], &addr[7]); if (n != LOWPAN_DEBUGFS_CTX_PFX_NUM_ARGS) { status = -EINVAL; goto out; } spin_lock_bh(&t->lock); for (i = 0; i < 8; i++) ctx->pfx.s6_addr16[i] = cpu_to_be16(addr[i] & 0xffff); spin_unlock_bh(&t->lock); out: return status; } |
6aaf37b41 6lowpan: debugfs:... |
155 |
static const struct file_operations lowpan_ctx_pfx_fops = { |
5609c185f 6lowpan: iphc: ad... |
156 157 158 159 160 161 |
.open = lowpan_ctx_pfx_open, .read = seq_read, .write = lowpan_ctx_pfx_write, .llseek = seq_lseek, .release = single_release, }; |
db50450d0 6lowpan: no need ... |
162 163 |
static void lowpan_dev_debugfs_ctx_init(struct net_device *dev, struct dentry *ctx, u8 id) |
5609c185f 6lowpan: iphc: ad... |
164 |
{ |
2e4d60cbc 6lowpan: change n... |
165 |
struct lowpan_dev *ldev = lowpan_dev(dev); |
db50450d0 6lowpan: no need ... |
166 |
struct dentry *root; |
5609c185f 6lowpan: iphc: ad... |
167 168 169 170 171 172 173 |
char buf[32]; WARN_ON_ONCE(id > LOWPAN_IPHC_CTX_TABLE_SIZE); sprintf(buf, "%d", id); root = debugfs_create_dir(buf, ctx); |
5609c185f 6lowpan: iphc: ad... |
174 |
|
db50450d0 6lowpan: no need ... |
175 176 |
debugfs_create_file("active", 0644, root, &ldev->ctx.table[id], &lowpan_ctx_flag_active_fops); |
5609c185f 6lowpan: iphc: ad... |
177 |
|
db50450d0 6lowpan: no need ... |
178 179 |
debugfs_create_file("compression", 0644, root, &ldev->ctx.table[id], &lowpan_ctx_flag_c_fops); |
5609c185f 6lowpan: iphc: ad... |
180 |
|
db50450d0 6lowpan: no need ... |
181 182 |
debugfs_create_file("prefix", 0644, root, &ldev->ctx.table[id], &lowpan_ctx_pfx_fops); |
5609c185f 6lowpan: iphc: ad... |
183 |
|
db50450d0 6lowpan: no need ... |
184 185 |
debugfs_create_file("prefix_len", 0644, root, &ldev->ctx.table[id], &lowpan_ctx_plen_fops); |
5609c185f 6lowpan: iphc: ad... |
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
} static int lowpan_context_show(struct seq_file *file, void *offset) { struct lowpan_iphc_ctx_table *t = file->private; int i; seq_printf(file, "%3s|%-43s|%c ", "cid", "prefix", 'C'); seq_puts(file, "------------------------------------------------- "); spin_lock_bh(&t->lock); for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++) { if (!lowpan_iphc_ctx_is_active(&t->table[i])) continue; seq_printf(file, "%3d|%39pI6c/%-3d|%d ", t->table[i].id, &t->table[i].pfx, t->table[i].plen, lowpan_iphc_ctx_is_compression(&t->table[i])); } spin_unlock_bh(&t->lock); return 0; } |
f79ba4300 6lowpan: convert ... |
212 |
DEFINE_SHOW_ATTRIBUTE(lowpan_context); |
5609c185f 6lowpan: iphc: ad... |
213 |
|
cfce94653 6lowpan: add supp... |
214 215 216 217 218 219 220 221 222 223 |
static int lowpan_short_addr_get(void *data, u64 *val) { struct wpan_dev *wdev = data; rtnl_lock(); *val = le16_to_cpu(wdev->short_addr); rtnl_unlock(); return 0; } |
5e053534b 6lowpan: fix debu... |
224 225 226 |
DEFINE_DEBUGFS_ATTRIBUTE(lowpan_short_addr_fops, lowpan_short_addr_get, NULL, "0x%04llx "); |
cfce94653 6lowpan: add supp... |
227 |
|
db50450d0 6lowpan: no need ... |
228 |
static void lowpan_dev_debugfs_802154_init(const struct net_device *dev, |
cfce94653 6lowpan: add supp... |
229 230 |
struct lowpan_dev *ldev) { |
db50450d0 6lowpan: no need ... |
231 |
struct dentry *root; |
cfce94653 6lowpan: add supp... |
232 233 |
if (!lowpan_is_ll(dev, LOWPAN_LLTYPE_IEEE802154)) |
db50450d0 6lowpan: no need ... |
234 |
return; |
cfce94653 6lowpan: add supp... |
235 236 |
root = debugfs_create_dir("ieee802154", ldev->iface_debugfs); |
cfce94653 6lowpan: add supp... |
237 |
|
db50450d0 6lowpan: no need ... |
238 239 240 |
debugfs_create_file("short_addr", 0444, root, lowpan_802154_dev(dev)->wdev->ieee802154_ptr, &lowpan_short_addr_fops); |
cfce94653 6lowpan: add supp... |
241 |
} |
db50450d0 6lowpan: no need ... |
242 |
void lowpan_dev_debugfs_init(struct net_device *dev) |
b1815fd94 6lowpan: add debu... |
243 |
{ |
2e4d60cbc 6lowpan: change n... |
244 |
struct lowpan_dev *ldev = lowpan_dev(dev); |
db50450d0 6lowpan: no need ... |
245 246 |
struct dentry *contexts; int i; |
b1815fd94 6lowpan: add debu... |
247 248 |
/* creating the root */ |
2e4d60cbc 6lowpan: change n... |
249 |
ldev->iface_debugfs = debugfs_create_dir(dev->name, lowpan_debugfs); |
b1815fd94 6lowpan: add debu... |
250 |
|
2e4d60cbc 6lowpan: change n... |
251 |
contexts = debugfs_create_dir("contexts", ldev->iface_debugfs); |
5609c185f 6lowpan: iphc: ad... |
252 |
|
db50450d0 6lowpan: no need ... |
253 254 |
debugfs_create_file("show", 0644, contexts, &lowpan_dev(dev)->ctx, &lowpan_context_fops); |
cfce94653 6lowpan: add supp... |
255 |
|
db50450d0 6lowpan: no need ... |
256 257 |
for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++) lowpan_dev_debugfs_ctx_init(dev, contexts, i); |
b1815fd94 6lowpan: add debu... |
258 |
|
db50450d0 6lowpan: no need ... |
259 |
lowpan_dev_debugfs_802154_init(dev, ldev); |
b1815fd94 6lowpan: add debu... |
260 261 262 263 |
} void lowpan_dev_debugfs_exit(struct net_device *dev) { |
2e4d60cbc 6lowpan: change n... |
264 |
debugfs_remove_recursive(lowpan_dev(dev)->iface_debugfs); |
b1815fd94 6lowpan: add debu... |
265 |
} |
db50450d0 6lowpan: no need ... |
266 |
void __init lowpan_debugfs_init(void) |
b1815fd94 6lowpan: add debu... |
267 268 |
{ lowpan_debugfs = debugfs_create_dir("6lowpan", NULL); |
b1815fd94 6lowpan: add debu... |
269 270 271 272 273 274 |
} void lowpan_debugfs_exit(void) { debugfs_remove_recursive(lowpan_debugfs); } |