|
| 1 | +/* |
| 2 | + * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This program is free software; you may redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; version 2 of the License. |
| 7 | + * |
| 8 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 9 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 10 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 11 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 12 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 13 | + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 14 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 15 | + * SOFTWARE. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +#include <linux/debugfs.h> |
| 20 | +#include <linux/module.h> |
| 21 | + |
| 22 | +#include "usnic.h" |
| 23 | +#include "usnic_log.h" |
| 24 | +#include "usnic_debugfs.h" |
| 25 | + |
| 26 | +static struct dentry *debugfs_root; |
| 27 | + |
| 28 | +static ssize_t usnic_debugfs_buildinfo_read(struct file *f, char __user *data, |
| 29 | + size_t count, loff_t *ppos) |
| 30 | +{ |
| 31 | + char buf[500]; |
| 32 | + int res; |
| 33 | + |
| 34 | + if (*ppos > 0) |
| 35 | + return 0; |
| 36 | + |
| 37 | + res = scnprintf(buf, sizeof(buf), |
| 38 | + "version: %s\n" |
| 39 | + "build date: %s\n", |
| 40 | + DRV_VERSION, DRV_RELDATE); |
| 41 | + |
| 42 | + return simple_read_from_buffer(data, count, ppos, buf, res); |
| 43 | +} |
| 44 | + |
| 45 | +static const struct file_operations usnic_debugfs_buildinfo_ops = { |
| 46 | + .owner = THIS_MODULE, |
| 47 | + .open = simple_open, |
| 48 | + .read = usnic_debugfs_buildinfo_read |
| 49 | +}; |
| 50 | + |
| 51 | +void usnic_debugfs_init(void) |
| 52 | +{ |
| 53 | + debugfs_root = debugfs_create_dir(DRV_NAME, NULL); |
| 54 | + if (IS_ERR(debugfs_root)) { |
| 55 | + usnic_err("Failed to create debugfs root dir, check if debugfs is enabled in kernel configuration\n"); |
| 56 | + debugfs_root = NULL; |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + debugfs_create_file("build-info", S_IRUGO, debugfs_root, |
| 61 | + NULL, &usnic_debugfs_buildinfo_ops); |
| 62 | +} |
| 63 | + |
| 64 | +void usnic_debugfs_exit(void) |
| 65 | +{ |
| 66 | + if (!debugfs_root) |
| 67 | + return; |
| 68 | + |
| 69 | + debugfs_remove_recursive(debugfs_root); |
| 70 | + debugfs_root = NULL; |
| 71 | +} |
0 commit comments