xref: /linux/drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2012 Broadcom Corporation
4  */
5 #include <linux/debugfs.h>
6 #include <linux/netdevice.h>
7 #include <linux/module.h>
8 #include <linux/devcoredump.h>
9 
10 #include <brcmu_wifi.h>
11 #include <brcmu_utils.h>
12 #include "core.h"
13 #include "bus.h"
14 #include "fweh.h"
15 #include "debug.h"
16 
17 int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
18 			       size_t len)
19 {
20 	void *dump;
21 	size_t ramsize;
22 	int err;
23 
24 	ramsize = brcmf_bus_get_ramsize(bus);
25 	if (!ramsize)
26 		return -ENOTSUPP;
27 
28 	dump = vzalloc(len + ramsize);
29 	if (!dump)
30 		return -ENOMEM;
31 
32 	if (data && len > 0)
33 		memcpy(dump, data, len);
34 	err = brcmf_bus_get_memdump(bus, dump + len, ramsize);
35 	if (err) {
36 		vfree(dump);
37 		return err;
38 	}
39 
40 	dev_coredumpv(bus->dev, dump, len + ramsize, GFP_KERNEL);
41 
42 	return 0;
43 }
44 
45 struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr)
46 {
47 	return drvr->wiphy->debugfsdir;
48 }
49 
50 void brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
51 			    int (*read_fn)(struct seq_file *seq, void *data))
52 {
53 	WARN(!drvr->wiphy->debugfsdir, "wiphy not (yet) registered\n");
54 	debugfs_create_devm_seqfile(drvr->bus_if->dev, fn,
55 				    drvr->wiphy->debugfsdir, read_fn);
56 }
57