1 /*
2  * Intel MIC Platform Software Stack (MPSS)
3  *
4  * Copyright(c) 2013 Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 2, as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * The full GNU General Public License is included in this distribution in
16  * the file called "COPYING".
17  *
18  * Disclaimer: The codes contained in these modules may be specific to
19  * the Intel Software Development Platform codenamed: Knights Ferry, and
20  * the Intel product codenamed: Knights Corner, and are not backward
21  * compatible with other Intel products. Additionally, Intel will NOT
22  * support the codes or instruction set in future products.
23  *
24  * Intel MIC Card driver.
25  *
26  */
27 #include <linux/debugfs.h>
28 #include <linux/delay.h>
29 #include <linux/seq_file.h>
30 #include <linux/interrupt.h>
31 #include <linux/device.h>
32 
33 #include "../common/mic_dev.h"
34 #include "mic_device.h"
35 
36 /* Debugfs parent dir */
37 static struct dentry *mic_dbg;
38 
39 /**
40  * mic_intr_test - Send interrupts to host.
41  */
mic_intr_test(struct seq_file * s,void * unused)42 static int mic_intr_test(struct seq_file *s, void *unused)
43 {
44 	struct mic_driver *mdrv = s->private;
45 	struct mic_device *mdev = &mdrv->mdev;
46 
47 	mic_send_intr(mdev, 0);
48 	msleep(1000);
49 	mic_send_intr(mdev, 1);
50 	msleep(1000);
51 	mic_send_intr(mdev, 2);
52 	msleep(1000);
53 	mic_send_intr(mdev, 3);
54 	msleep(1000);
55 
56 	return 0;
57 }
58 
mic_intr_test_open(struct inode * inode,struct file * file)59 static int mic_intr_test_open(struct inode *inode, struct file *file)
60 {
61 	return single_open(file, mic_intr_test, inode->i_private);
62 }
63 
mic_intr_test_release(struct inode * inode,struct file * file)64 static int mic_intr_test_release(struct inode *inode, struct file *file)
65 {
66 	return single_release(inode, file);
67 }
68 
69 static const struct file_operations intr_test_ops = {
70 	.owner   = THIS_MODULE,
71 	.open    = mic_intr_test_open,
72 	.read    = seq_read,
73 	.llseek  = seq_lseek,
74 	.release = mic_intr_test_release
75 };
76 
77 /**
78  * mic_create_card_debug_dir - Initialize MIC debugfs entries.
79  */
mic_create_card_debug_dir(struct mic_driver * mdrv)80 void __init mic_create_card_debug_dir(struct mic_driver *mdrv)
81 {
82 	struct dentry *d;
83 
84 	if (!mic_dbg)
85 		return;
86 
87 	mdrv->dbg_dir = debugfs_create_dir(mdrv->name, mic_dbg);
88 	if (!mdrv->dbg_dir) {
89 		dev_err(mdrv->dev, "Cant create dbg_dir %s\n", mdrv->name);
90 		return;
91 	}
92 
93 	d = debugfs_create_file("intr_test", 0444, mdrv->dbg_dir,
94 		mdrv, &intr_test_ops);
95 
96 	if (!d) {
97 		dev_err(mdrv->dev,
98 			"Cant create dbg intr_test %s\n", mdrv->name);
99 		return;
100 	}
101 }
102 
103 /**
104  * mic_delete_card_debug_dir - Uninitialize MIC debugfs entries.
105  */
mic_delete_card_debug_dir(struct mic_driver * mdrv)106 void mic_delete_card_debug_dir(struct mic_driver *mdrv)
107 {
108 	if (!mdrv->dbg_dir)
109 		return;
110 
111 	debugfs_remove_recursive(mdrv->dbg_dir);
112 }
113 
114 /**
115  * mic_init_card_debugfs - Initialize global debugfs entry.
116  */
mic_init_card_debugfs(void)117 void __init mic_init_card_debugfs(void)
118 {
119 	mic_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
120 	if (!mic_dbg)
121 		pr_err("can't create debugfs dir\n");
122 }
123 
124 /**
125  * mic_exit_card_debugfs - Uninitialize global debugfs entry
126  */
mic_exit_card_debugfs(void)127 void mic_exit_card_debugfs(void)
128 {
129 	debugfs_remove(mic_dbg);
130 }
131