1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci *
3f08c3bdfSopenharmony_ci *   Copyright (c) International Business Machines  Corp., 2001
4f08c3bdfSopenharmony_ci *
5f08c3bdfSopenharmony_ci *   This program is free software;  you can redistribute it and/or modify
6f08c3bdfSopenharmony_ci *   it under the terms of the GNU General Public License as published by
7f08c3bdfSopenharmony_ci *   the Free Software Foundation; either version 2 of the License, or
8f08c3bdfSopenharmony_ci *   (at your option) any later version.
9f08c3bdfSopenharmony_ci *
10f08c3bdfSopenharmony_ci *   This program is distributed in the hope that it will be useful,
11f08c3bdfSopenharmony_ci *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12f08c3bdfSopenharmony_ci *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13f08c3bdfSopenharmony_ci *   the GNU General Public License for more details.
14f08c3bdfSopenharmony_ci *
15f08c3bdfSopenharmony_ci *   You should have received a copy of the GNU General Public License
16f08c3bdfSopenharmony_ci *   along with this program;  if not, write to the Free Software
17f08c3bdfSopenharmony_ci *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18f08c3bdfSopenharmony_ci *
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci * This test is meant to hit
21f08c3bdfSopenharmony_ci * many of the inline functions
22f08c3bdfSopenharmony_ci * in various include files.
23f08c3bdfSopenharmony_ci *
24f08c3bdfSopenharmony_ci * Author: David Cruz <cruzd@us.ibm.com>
25f08c3bdfSopenharmony_ci * Module: includeTest
26f08c3bdfSopenharmony_ci *
27f08c3bdfSopenharmony_ci */
28f08c3bdfSopenharmony_ci
29f08c3bdfSopenharmony_ci#include <linux/types.h>
30f08c3bdfSopenharmony_ci#include <linux/kernel.h>
31f08c3bdfSopenharmony_ci#include <linux/fs.h>
32f08c3bdfSopenharmony_ci#include <linux/ioctl.h>
33f08c3bdfSopenharmony_ci#include <linux/module.h>
34f08c3bdfSopenharmony_ci#include <linux/init.h>
35f08c3bdfSopenharmony_ci#include <linux/pm.h>
36f08c3bdfSopenharmony_ci#include <linux/genhd.h>
37f08c3bdfSopenharmony_ci#include <linux/in.h>
38f08c3bdfSopenharmony_ci#include <asm/types.h>
39f08c3bdfSopenharmony_ci#include <linux/lockd/bind.h>
40f08c3bdfSopenharmony_ci#include <acpi/acpi_drivers.h>
41f08c3bdfSopenharmony_ci#include <linux/nfsd/nfsfh.h>
42f08c3bdfSopenharmony_ci#include <linux/sunrpc/auth.h>
43f08c3bdfSopenharmony_ci#include <linux/sunrpc/cache.h>
44f08c3bdfSopenharmony_ci#include <linux/sunrpc/svc.h>
45f08c3bdfSopenharmony_ci#include <linux/sunrpc/xdr.h>
46f08c3bdfSopenharmony_ci#include <linux/sunrpc/timer.h>
47f08c3bdfSopenharmony_ci#include <video/vga.h>
48f08c3bdfSopenharmony_ci#include <linux/errno.h>
49f08c3bdfSopenharmony_ci#include <linux/string.h>
50f08c3bdfSopenharmony_ci#include <linux/mm.h>
51f08c3bdfSopenharmony_ci#include <linux/slab.h>
52f08c3bdfSopenharmony_ci#include <linux/lockd/lockd.h>
53f08c3bdfSopenharmony_ci#include <linux/lockd/nlm.h>
54f08c3bdfSopenharmony_ci#include <linux/nfsd/export.h>
55f08c3bdfSopenharmony_ci#include <asm/uaccess.h>
56f08c3bdfSopenharmony_ci#include "includeTest.h"
57f08c3bdfSopenharmony_ci
58f08c3bdfSopenharmony_ciMODULE_AUTHOR("David Cruz <cruzd@us.ibm.com>");
59f08c3bdfSopenharmony_ciMODULE_DESCRIPTION(TEST_DRIVER_NAME);
60f08c3bdfSopenharmony_ciMODULE_LICENSE("GPL");
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_cistatic int test_ioctl(struct inode *, struct file *, unsigned int,
63f08c3bdfSopenharmony_ci		      unsigned long);
64f08c3bdfSopenharmony_cistatic int test_open(struct inode *, struct file *);
65f08c3bdfSopenharmony_cistatic int test_close(struct inode *, struct file *);
66f08c3bdfSopenharmony_cistatic void test_acpi(void);
67f08c3bdfSopenharmony_cistatic void test_vga(void);
68f08c3bdfSopenharmony_cistatic void test_sunrpc_auth(void);
69f08c3bdfSopenharmony_cistatic void test_nfsfh(void);
70f08c3bdfSopenharmony_cistatic void test_lockd(void);
71f08c3bdfSopenharmony_cistatic void test_sunrpc_cache(void);
72f08c3bdfSopenharmony_cistatic void test_sunrpc_svc(void);
73f08c3bdfSopenharmony_cistatic void test_sunrpc_timer(void);
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_cistatic int Major = 0;
76f08c3bdfSopenharmony_ci
77f08c3bdfSopenharmony_cistatic struct block_device_operations bdops = {
78f08c3bdfSopenharmony_ciopen:	test_open,
79f08c3bdfSopenharmony_cirelease:test_close,
80f08c3bdfSopenharmony_ciioctl:	test_ioctl,
81f08c3bdfSopenharmony_ci};
82f08c3bdfSopenharmony_ci
83f08c3bdfSopenharmony_cistatic char genhd_flags = 0;
84f08c3bdfSopenharmony_cistatic struct gendisk *gd_ptr;
85f08c3bdfSopenharmony_cistatic struct pm_dev *ltp_pm_dev = NULL;
86f08c3bdfSopenharmony_ci
87f08c3bdfSopenharmony_cistatic int test_open(struct inode *ino, struct file *f)
88f08c3bdfSopenharmony_ci{
89f08c3bdfSopenharmony_ci	printk("device open\n");
90f08c3bdfSopenharmony_ci	return 0;
91f08c3bdfSopenharmony_ci}
92f08c3bdfSopenharmony_ci
93f08c3bdfSopenharmony_cistatic int test_close(struct inode *ino, struct file *f)
94f08c3bdfSopenharmony_ci{
95f08c3bdfSopenharmony_ci	printk("device closed\n");
96f08c3bdfSopenharmony_ci	return 0;
97f08c3bdfSopenharmony_ci}
98f08c3bdfSopenharmony_ci
99f08c3bdfSopenharmony_cistatic int test_ioctl(struct inode *ino, struct file *f, unsigned int cmd,
100f08c3bdfSopenharmony_ci		      unsigned long l)
101f08c3bdfSopenharmony_ci{
102f08c3bdfSopenharmony_ci
103f08c3bdfSopenharmony_ci	int rc = 0;		//return code
104f08c3bdfSopenharmony_ci	int arg;
105f08c3bdfSopenharmony_ci
106f08c3bdfSopenharmony_ci	printk("Entered the ioctl call.\n");
107f08c3bdfSopenharmony_ci
108f08c3bdfSopenharmony_ci	if (copy_from_user(&arg, (void *)l, sizeof(int))) {
109f08c3bdfSopenharmony_ci		//bad address
110f08c3bdfSopenharmony_ci		return (-EFAULT);
111f08c3bdfSopenharmony_ci	}
112f08c3bdfSopenharmony_ci
113f08c3bdfSopenharmony_ci	switch (cmd) {
114f08c3bdfSopenharmony_ci
115f08c3bdfSopenharmony_ci	case OPTION1:
116f08c3bdfSopenharmony_ci		option1();
117f08c3bdfSopenharmony_ci		break;
118f08c3bdfSopenharmony_ci	default:
119f08c3bdfSopenharmony_ci		printk("Mismatching ioctl command\n");
120f08c3bdfSopenharmony_ci		break;
121f08c3bdfSopenharmony_ci	}
122f08c3bdfSopenharmony_ci
123f08c3bdfSopenharmony_ci	//0 by default
124f08c3bdfSopenharmony_ci	return rc;
125f08c3bdfSopenharmony_ci}
126f08c3bdfSopenharmony_ci
127f08c3bdfSopenharmony_cistatic void option1(void)
128f08c3bdfSopenharmony_ci{
129f08c3bdfSopenharmony_ci	printk("Module option 1 chosen\n");
130f08c3bdfSopenharmony_ci}
131f08c3bdfSopenharmony_ci
132f08c3bdfSopenharmony_cistatic int ltp_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
133f08c3bdfSopenharmony_ci{
134f08c3bdfSopenharmony_ci	return 0;
135f08c3bdfSopenharmony_ci}
136f08c3bdfSopenharmony_ci
137f08c3bdfSopenharmony_cistatic int test_init_module(void)
138f08c3bdfSopenharmony_ci{
139f08c3bdfSopenharmony_ci
140f08c3bdfSopenharmony_ci	int rc;
141f08c3bdfSopenharmony_ci
142f08c3bdfSopenharmony_ci	printk("starting module\n");
143f08c3bdfSopenharmony_ci
144f08c3bdfSopenharmony_ci	ltp_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, ltp_pm_callback);
145f08c3bdfSopenharmony_ci	rc = register_blkdev(INCLUDEMAJOR, DEVICE_NAME);
146f08c3bdfSopenharmony_ci
147f08c3bdfSopenharmony_ci	printk("BLK INC - result =%d major %d\n", rc, INCLUDEMAJOR);
148f08c3bdfSopenharmony_ci
149f08c3bdfSopenharmony_ci	if (rc < 0) {
150f08c3bdfSopenharmony_ci		printk("Failed to register device.\n");
151f08c3bdfSopenharmony_ci		return rc;
152f08c3bdfSopenharmony_ci	}
153f08c3bdfSopenharmony_ci
154f08c3bdfSopenharmony_ci	gd_ptr = kmalloc(sizeof(struct gendisk *), GFP_KERNEL);
155f08c3bdfSopenharmony_ci	if (!gd_ptr) {
156f08c3bdfSopenharmony_ci		printk(KERN_ALERT "ERROR getting memory !!!\n");
157f08c3bdfSopenharmony_ci		return 0;
158f08c3bdfSopenharmony_ci	}
159f08c3bdfSopenharmony_ci
160f08c3bdfSopenharmony_ci	printk("major = %d\n", Major);
161f08c3bdfSopenharmony_ci	gd_ptr = alloc_disk(1);
162f08c3bdfSopenharmony_ci	printk(KERN_ALERT "gd_ptr after alloc = %p \n", gd_ptr);
163f08c3bdfSopenharmony_ci	gd_ptr->major = INCLUDEMAJOR;
164f08c3bdfSopenharmony_ci	gd_ptr->first_minor = 0;
165f08c3bdfSopenharmony_ci	gd_ptr->fops = &bdops;
166f08c3bdfSopenharmony_ci//      gd_ptr->minor_shift= MINOR_SHIFT_BITS;
167f08c3bdfSopenharmony_ci	gd_ptr->driverfs_dev = NULL;
168f08c3bdfSopenharmony_ci	gd_ptr->capacity = MAX_NUM_DISKS;
169f08c3bdfSopenharmony_ci//      gd_ptr->disk_de = NULL;
170f08c3bdfSopenharmony_ci	gd_ptr->flags = genhd_flags;
171f08c3bdfSopenharmony_ci
172f08c3bdfSopenharmony_ci	sprintf(gd_ptr->disk_name, DEVICE_NAME);
173f08c3bdfSopenharmony_ci	add_disk(gd_ptr);
174f08c3bdfSopenharmony_ci
175f08c3bdfSopenharmony_ci	printk("major = %d\n", Major);
176f08c3bdfSopenharmony_ci
177f08c3bdfSopenharmony_ci	test_acpi();
178f08c3bdfSopenharmony_ci	test_vga();
179f08c3bdfSopenharmony_ci	test_lockd();
180f08c3bdfSopenharmony_ci	test_sunrpc_auth();
181f08c3bdfSopenharmony_ci	test_nfsfh();
182f08c3bdfSopenharmony_ci	test_sunrpc_cache();
183f08c3bdfSopenharmony_ci	test_sunrpc_svc();
184f08c3bdfSopenharmony_ci	test_sunrpc_timer();
185f08c3bdfSopenharmony_ci	printk("finished module\n");
186f08c3bdfSopenharmony_ci
187f08c3bdfSopenharmony_ci	return 0;
188f08c3bdfSopenharmony_ci}
189f08c3bdfSopenharmony_ci
190f08c3bdfSopenharmony_cistatic void test_exit_module(void)
191f08c3bdfSopenharmony_ci{
192f08c3bdfSopenharmony_ci
193f08c3bdfSopenharmony_ci	int rc;
194f08c3bdfSopenharmony_ci
195f08c3bdfSopenharmony_ci	pm_unregister(ltp_pm_dev);
196f08c3bdfSopenharmony_ci	put_disk(gd_ptr);
197f08c3bdfSopenharmony_ci	del_gendisk(gd_ptr);
198f08c3bdfSopenharmony_ci
199f08c3bdfSopenharmony_ci	rc = unregister_blkdev(INCLUDEMAJOR, DEVICE_NAME);
200f08c3bdfSopenharmony_ci
201f08c3bdfSopenharmony_ci	if (rc < 0) {
202f08c3bdfSopenharmony_ci		printk("unregister failed %d\n", rc);
203f08c3bdfSopenharmony_ci	} else {
204f08c3bdfSopenharmony_ci		printk("unregister success\n");
205f08c3bdfSopenharmony_ci	}
206f08c3bdfSopenharmony_ci}
207f08c3bdfSopenharmony_ci
208f08c3bdfSopenharmony_cistatic void test_acpi(void)
209f08c3bdfSopenharmony_ci{
210f08c3bdfSopenharmony_ci	u32 flag;
211f08c3bdfSopenharmony_ci
212f08c3bdfSopenharmony_ci	for (flag = 0; flag <= 4; flag++)
213f08c3bdfSopenharmony_ci		acpi_set_debug(flag);
214f08c3bdfSopenharmony_ci
215f08c3bdfSopenharmony_ci	printk("finished acpi test\n");
216f08c3bdfSopenharmony_ci}
217f08c3bdfSopenharmony_ci
218f08c3bdfSopenharmony_cistatic void test_sunrpc_auth(void)
219f08c3bdfSopenharmony_ci{
220f08c3bdfSopenharmony_ci	struct rpc_cred cred;
221f08c3bdfSopenharmony_ci
222f08c3bdfSopenharmony_ci	atomic_set(&(cred.cr_count), 0);
223f08c3bdfSopenharmony_ci	get_rpccred(&cred);
224f08c3bdfSopenharmony_ci	printk("finished auth test\n");
225f08c3bdfSopenharmony_ci}
226f08c3bdfSopenharmony_ci
227f08c3bdfSopenharmony_cistatic void test_vga(void)
228f08c3bdfSopenharmony_ci{
229f08c3bdfSopenharmony_ci
230f08c3bdfSopenharmony_ci	unsigned short vgaS = 0;
231f08c3bdfSopenharmony_ci	int i = 0;
232f08c3bdfSopenharmony_ci	vga_r((caddr_t) i, vgaS);
233f08c3bdfSopenharmony_ci	printk("finished vga test\n");
234f08c3bdfSopenharmony_ci}
235f08c3bdfSopenharmony_ci
236f08c3bdfSopenharmony_cistatic void test_nfsfh(void)
237f08c3bdfSopenharmony_ci{
238f08c3bdfSopenharmony_ci	dev_t dev = 0;
239f08c3bdfSopenharmony_ci	u32 unfs = 0, u32ptr[2];
240f08c3bdfSopenharmony_ci	ino_t ino = 0;
241f08c3bdfSopenharmony_ci	struct svc_fh A1;
242f08c3bdfSopenharmony_ci	int i = 20;
243f08c3bdfSopenharmony_ci
244f08c3bdfSopenharmony_ci	u32_to_dev_t((__u32) unfs);
245f08c3bdfSopenharmony_ci	ino_t_to_u32(ino);
246f08c3bdfSopenharmony_ci	u32_to_ino_t((__u32) unfs);
247f08c3bdfSopenharmony_ci	mk_fsid_v0(u32ptr, dev, ino);
248f08c3bdfSopenharmony_ci	mk_fsid_v1(u32ptr, unfs);
249f08c3bdfSopenharmony_ci	SVCFH_fmt(&A1);
250f08c3bdfSopenharmony_ci	fh_init(&A1, i);
251f08c3bdfSopenharmony_ci	fh_lock(&A1);
252f08c3bdfSopenharmony_ci	fh_unlock(&A1);
253f08c3bdfSopenharmony_ci	printk("finished nfsfh test\n");
254f08c3bdfSopenharmony_ci}
255f08c3bdfSopenharmony_ci
256f08c3bdfSopenharmony_cistatic void test_lockd(void)
257f08c3bdfSopenharmony_ci{
258f08c3bdfSopenharmony_ci
259f08c3bdfSopenharmony_ci	struct nlm_file file;
260f08c3bdfSopenharmony_ci	struct sockaddr_in sin1, sin2;
261f08c3bdfSopenharmony_ci	struct file_lock fl1, fl2;
262f08c3bdfSopenharmony_ci
263f08c3bdfSopenharmony_ci	nlm_compare_locks(&fl1, &fl2);
264f08c3bdfSopenharmony_ci	nlm_cmp_addr(&sin1, &sin2);
265f08c3bdfSopenharmony_ci	nlmsvc_file_inode(&file);
266f08c3bdfSopenharmony_ci	printk("finished lockd test\n");
267f08c3bdfSopenharmony_ci}
268f08c3bdfSopenharmony_ci
269f08c3bdfSopenharmony_cistatic void test_sunrpc_cache(void)
270f08c3bdfSopenharmony_ci{
271f08c3bdfSopenharmony_ci	struct cache_head head;
272f08c3bdfSopenharmony_ci	struct cache_detail detail;
273f08c3bdfSopenharmony_ci
274f08c3bdfSopenharmony_ci	cache_get(&head);
275f08c3bdfSopenharmony_ci	cache_put(&head, &detail);
276f08c3bdfSopenharmony_ci	printk("finished cache test\n");
277f08c3bdfSopenharmony_ci}
278f08c3bdfSopenharmony_ci
279f08c3bdfSopenharmony_cistatic void test_sunrpc_svc(void)
280f08c3bdfSopenharmony_ci{
281f08c3bdfSopenharmony_ci	u32 val;
282f08c3bdfSopenharmony_ci	struct svc_rqst rqstp;
283f08c3bdfSopenharmony_ci	char name[50];
284f08c3bdfSopenharmony_ci	struct iovec iov;
285f08c3bdfSopenharmony_ci	int bits = 0, bits2 = 0;
286f08c3bdfSopenharmony_ci	rqstp.rq_resused = 1;
287f08c3bdfSopenharmony_ci
288f08c3bdfSopenharmony_ci	svc_getu32(&iov);
289f08c3bdfSopenharmony_ci//      svc_putu32(&iov, val);
290f08c3bdfSopenharmony_ci
291f08c3bdfSopenharmony_ci	xdr_argsize_check(&rqstp, &val);
292f08c3bdfSopenharmony_ci	xdr_ressize_check(&rqstp, &val);
293f08c3bdfSopenharmony_ci	svc_take_page(&rqstp);
294f08c3bdfSopenharmony_ci	svc_pushback_allpages(&rqstp);
295f08c3bdfSopenharmony_ci	svc_pushback_unused_pages(&rqstp);
296f08c3bdfSopenharmony_ci	svc_free_allpages(&rqstp);
297f08c3bdfSopenharmony_ci	hash_str(name, bits);
298f08c3bdfSopenharmony_ci	hash_mem(name, bits, bits2);
299f08c3bdfSopenharmony_ci	printk("finished svc test\n");
300f08c3bdfSopenharmony_ci
301f08c3bdfSopenharmony_ci}
302f08c3bdfSopenharmony_ci
303f08c3bdfSopenharmony_cistatic void test_sunrpc_timer()
304f08c3bdfSopenharmony_ci{
305f08c3bdfSopenharmony_ci	struct rpc_rtt rt;
306f08c3bdfSopenharmony_ci
307f08c3bdfSopenharmony_ci	rpc_inc_timeo(&rt);
308f08c3bdfSopenharmony_ci	rpc_clear_timeo(&rt);
309f08c3bdfSopenharmony_ci	rpc_ntimeo(&rt);
310f08c3bdfSopenharmony_ci	printk("finished timer test\n");
311f08c3bdfSopenharmony_ci}
312f08c3bdfSopenharmony_ci
313f08c3bdfSopenharmony_cimodule_init(test_init_module)
314f08c3bdfSopenharmony_ci    module_exit(test_exit_module)
315