aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/dgrp/dgrp_common.h
blob: 05ff338471ac6b8379c2430ed05a6df2000f4571 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 *
 * Copyright 1999 Digi International (www.digi.com)
 *     James Puzzo <jamesp at digi dot com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 */

#ifndef __DGRP_COMMON_H
#define __DGRP_COMMON_H

#define DIGI_VERSION "1.9-29"

#include <linux/fs.h>
#include <linux/timer.h>
#include "drp.h"

#define DGRP_TTIME 100
#define DGRP_RTIME 100

/************************************************************************
 * All global storage allocation.
 ************************************************************************/

extern int dgrp_rawreadok;  /* Allow raw writing of input */
extern int dgrp_register_cudevices; /* enable legacy cu devices */
extern int dgrp_register_prdevices; /* enable transparent print devices */
extern int dgrp_poll_tick;          /* Poll interval - in ms */

extern struct list_head nd_struct_list;

struct dgrp_poll_data {
	spinlock_t poll_lock;
	struct timer_list timer;
	int poll_tick;
	ulong poll_round;	/* Timer rouding factor */
	long node_active_count;
};

extern struct dgrp_poll_data dgrp_poll_data;
extern void dgrp_poll_handler(unsigned long arg);

/* from dgrp_mon_ops.c */
extern void dgrp_register_mon_hook(struct proc_dir_entry *de);

/* from dgrp_tty.c */
extern int dgrp_tty_init(struct nd_struct *nd);
extern void dgrp_tty_uninit(struct nd_struct *nd);

/* from dgrp_ports_ops.c */
extern void dgrp_register_ports_hook(struct proc_dir_entry *de);

/* from dgrp_net_ops.c */
extern void dgrp_register_net_hook(struct proc_dir_entry *de);

/* from dgrp_dpa_ops.c */
extern void dgrp_register_dpa_hook(struct proc_dir_entry *de);
extern void dgrp_dpa_data(struct nd_struct *, int, u8 *, int);

/* from dgrp_sysfs.c */
extern void dgrp_create_class_sysfs_files(void);
extern void dgrp_remove_class_sysfs_files(void);

extern void dgrp_create_node_class_sysfs_files(struct nd_struct *nd);
extern void dgrp_remove_node_class_sysfs_files(struct nd_struct *nd);

extern void dgrp_create_tty_sysfs(struct un_struct *un, struct device *c);
extern void dgrp_remove_tty_sysfs(struct device *c);

/* from dgrp_specproc.c */
/*
 *  The list of DGRP entries with r/w capabilities.  These
 *  magic numbers are used for identification purposes.
 */
enum {
	DGRP_CONFIG = 1,	/* Configure portservers */
	DGRP_NETDIR = 2,	/* Directory for "net" devices */
	DGRP_MONDIR = 3,	/* Directory for "mon" devices */
	DGRP_PORTSDIR = 4,	/* Directory for "ports" devices */
	DGRP_INFO = 5,		/* Get info. about the running module */
	DGRP_NODEINFO = 6,	/* Get info. about the configured nodes */
	DGRP_DPADIR = 7,	/* Directory for the "dpa" devices */
};

/*
 *  Directions for proc handlers
 */
enum {
	INBOUND = 1,		/* Data being written to kernel */
	OUTBOUND = 2,		/* Data being read from the kernel */
};

/**
 * dgrp_proc_entry: structure for dgrp proc dirs
 * @id: ID number associated with this particular entry.  Should be
 *    unique across all of DGRP.
 * @name: text name associated with the /proc entry
 * @mode: file access permisssions for the /proc entry
 * @child: pointer to table describing a subdirectory for this entry
 * @de: pointer to directory entry for this object once registered.  Used
 *    to grab the handle of the object for unregistration
 * @excl_sem: semaphore to provide exclusive to struct
 * @excl_cnt: counter of current accesses
 *
 *  Each entry in a DGRP proc directory is described with a
 *  dgrp_proc_entry structure.  A collection of these
 *  entries (in an array) represents the members associated
 *  with a particular /proc directory, and is referred to
 *  as a table.  All tables are terminated by an entry with
 *  zeros for every member.
 */
struct dgrp_proc_entry {
	int                  id;          /* Integer identifier */
	const char        *name;          /* ASCII identifier */
	mode_t             mode;          /* File access permissions */
	struct dgrp_proc_entry *child;    /* Child pointer */

	/* file ops to use, pass NULL to use default */
	struct file_operations *proc_file_ops;

	struct proc_dir_entry *de;        /* proc entry pointer */
	struct semaphore   excl_sem;      /* Protects exclusive access var */
	int                excl_cnt;      /* Counts number of curr accesses */
};

extern void dgrp_unregister_proc(void);
extern void dgrp_register_proc(void);

/*-----------------------------------------------------------------------*
 *
 *  Declarations for common operations:
 *
 *      (either used by more than one of net, mon, or tty,
 *       or in interrupt context (i.e. the poller))
 *
 *-----------------------------------------------------------------------*/

void dgrp_carrier(struct ch_struct *ch);
extern int dgrp_inode_permission(struct inode *inode, int op);
extern int dgrp_chk_perm(int mode, int op);


/*
 *  ID manipulation macros (where c1 & c2 are characters, i is
 *  a long integer, and s is a character array of at least three members
 */

static inline void ID_TO_CHAR(long i, char *s)
{
	s[0] = ((i & 0xff00)>>8);
	s[1] = (i & 0xff);
	s[2] = 0;
}

static inline long CHAR_TO_ID(char *s)
{
	return ((s[0] & 0xff) << 8) | (s[1] & 0xff);
}

static inline struct nd_struct *nd_struct_get(long major)
{
	struct nd_struct *nd;

	list_for_each_entry(nd, &nd_struct_list, list) {
		if (major == nd->nd_major)
			return nd;
	}

	return NULL;
}

static inline int nd_struct_add(struct nd_struct *entry)
{
	struct nd_struct *ptr;

	ptr = nd_struct_get(entry->nd_major);

	if (ptr)
		return -EBUSY;

	list_add_tail(&entry->list, &nd_struct_list);

	return 0;
}

static inline int nd_struct_del(struct nd_struct *entry)
{
	struct nd_struct *nd;

	nd = nd_struct_get(entry->nd_major);

	if (!nd)
		return -ENODEV;

	list_del(&nd->list);
	return 0;
}

#endif /* __DGRP_COMMON_H */