-
Notifications
You must be signed in to change notification settings - Fork 3
/
neuron_module.c
86 lines (68 loc) · 2.17 KB
/
neuron_module.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
56
57
58
59
60
61
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
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2020, Amazon.com, Inc. or its affiliates. All Rights Reserved
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fault-inject.h>
/* Only this file should create trace points, anywhere else just include neuron_trace.h*/
#define CREATE_TRACE_POINTS
#include "neuron_trace.h"
MODULE_DESCRIPTION("Neuron Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0");
MODULE_ALIAS("pci:v00001d0fd00007064sv*sd*bc*sc*i*");
const char driver_version[] = "local-build";
extern int ncdev_module_init(void);
extern void ncdev_module_exit(void);
extern int neuron_pci_module_init(void);
extern void neuron_pci_module_exit(void);
#ifdef CONFIG_FAULT_INJECTION
extern struct fault_attr neuron_fail_nc_mmap;
extern struct fault_attr neuron_fail_dma_wait;
extern struct fault_attr neuron_fail_mc_alloc;
extern struct fault_attr neuron_fail_fwio_read;
extern struct fault_attr neuron_fail_fwio_post_metric;
static struct dentry *dbgfs_root;
static void neuron_module_init_debugfs(void)
{
dbgfs_root = debugfs_create_dir("neuron", NULL);
fault_create_debugfs_attr("fail_nc_mmap", dbgfs_root, &neuron_fail_nc_mmap);
fault_create_debugfs_attr("fail_dma_wait", dbgfs_root, &neuron_fail_dma_wait);
fault_create_debugfs_attr("fail_mc_alloc", dbgfs_root, &neuron_fail_mc_alloc);
fault_create_debugfs_attr("fail_fwio_read", dbgfs_root, &neuron_fail_fwio_read);
fault_create_debugfs_attr("fail_fwio_post_metric", dbgfs_root,
&neuron_fail_fwio_post_metric);
}
static void neuron_module_free_debugfs(void)
{
debugfs_remove_recursive(dbgfs_root);
dbgfs_root = NULL;
}
#endif
static int __init neuron_module_init(void)
{
int ret;
printk(KERN_INFO "Neuron Driver Started with Version:%s", driver_version);
#ifdef CONFIG_FAULT_INJECTION
neuron_module_init_debugfs();
#endif
ret = ncdev_module_init();
if (ret)
return ret;
ret = neuron_pci_module_init();
if (ret)
return ret;
return 0;
}
static void __exit neuron_module_exit(void)
{
#ifdef CONFIG_FAULT_INJECTION
neuron_module_free_debugfs();
#endif
neuron_pci_module_exit();
ncdev_module_exit();
}
module_init(neuron_module_init);
module_exit(neuron_module_exit);