Merge branch 'next/cleanup' into HEAD
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / dgrp / dgrp_common.h
CommitLineData
0b52b749
BP
1/*
2 *
3 * Copyright 1999 Digi International (www.digi.com)
4 * James Puzzo <jamesp at digi dot com>
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 as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 */
17
18#ifndef __DGRP_COMMON_H
19#define __DGRP_COMMON_H
20
21#define DIGI_VERSION "1.9-29"
22
23#include <linux/fs.h>
24#include <linux/timer.h>
25#include "drp.h"
26
27#define DGRP_TTIME 100
28#define DGRP_RTIME 100
29
30/************************************************************************
31 * All global storage allocation.
32 ************************************************************************/
33
34extern int dgrp_rawreadok; /* Allow raw writing of input */
35extern int dgrp_register_cudevices; /* enable legacy cu devices */
36extern int dgrp_register_prdevices; /* enable transparent print devices */
37extern int dgrp_poll_tick; /* Poll interval - in ms */
38
39extern struct list_head nd_struct_list;
40
41struct dgrp_poll_data {
42 spinlock_t poll_lock;
43 struct timer_list timer;
44 int poll_tick;
45 ulong poll_round; /* Timer rouding factor */
46 long node_active_count;
47};
48
49extern struct dgrp_poll_data dgrp_poll_data;
50extern void dgrp_poll_handler(unsigned long arg);
51
52/* from dgrp_mon_ops.c */
53extern void dgrp_register_mon_hook(struct proc_dir_entry *de);
54
55/* from dgrp_tty.c */
56extern int dgrp_tty_init(struct nd_struct *nd);
57extern void dgrp_tty_uninit(struct nd_struct *nd);
58
59/* from dgrp_ports_ops.c */
60extern void dgrp_register_ports_hook(struct proc_dir_entry *de);
61
62/* from dgrp_net_ops.c */
63extern void dgrp_register_net_hook(struct proc_dir_entry *de);
64
65/* from dgrp_dpa_ops.c */
66extern void dgrp_register_dpa_hook(struct proc_dir_entry *de);
67extern void dgrp_dpa_data(struct nd_struct *, int, u8 *, int);
68
69/* from dgrp_sysfs.c */
70extern void dgrp_create_class_sysfs_files(void);
71extern void dgrp_remove_class_sysfs_files(void);
72
73extern void dgrp_create_node_class_sysfs_files(struct nd_struct *nd);
74extern void dgrp_remove_node_class_sysfs_files(struct nd_struct *nd);
75
76extern void dgrp_create_tty_sysfs(struct un_struct *un, struct device *c);
77extern void dgrp_remove_tty_sysfs(struct device *c);
78
79/* from dgrp_specproc.c */
80/*
81 * The list of DGRP entries with r/w capabilities. These
82 * magic numbers are used for identification purposes.
83 */
84enum {
85 DGRP_CONFIG = 1, /* Configure portservers */
86 DGRP_NETDIR = 2, /* Directory for "net" devices */
87 DGRP_MONDIR = 3, /* Directory for "mon" devices */
88 DGRP_PORTSDIR = 4, /* Directory for "ports" devices */
89 DGRP_INFO = 5, /* Get info. about the running module */
90 DGRP_NODEINFO = 6, /* Get info. about the configured nodes */
91 DGRP_DPADIR = 7, /* Directory for the "dpa" devices */
92};
93
94/*
95 * Directions for proc handlers
96 */
97enum {
98 INBOUND = 1, /* Data being written to kernel */
99 OUTBOUND = 2, /* Data being read from the kernel */
100};
101
102/**
103 * dgrp_proc_entry: structure for dgrp proc dirs
104 * @id: ID number associated with this particular entry. Should be
105 * unique across all of DGRP.
106 * @name: text name associated with the /proc entry
107 * @mode: file access permisssions for the /proc entry
108 * @child: pointer to table describing a subdirectory for this entry
109 * @de: pointer to directory entry for this object once registered. Used
110 * to grab the handle of the object for unregistration
111 * @excl_sem: semaphore to provide exclusive to struct
112 * @excl_cnt: counter of current accesses
113 *
114 * Each entry in a DGRP proc directory is described with a
115 * dgrp_proc_entry structure. A collection of these
116 * entries (in an array) represents the members associated
117 * with a particular /proc directory, and is referred to
118 * as a table. All tables are terminated by an entry with
119 * zeros for every member.
120 */
121struct dgrp_proc_entry {
122 int id; /* Integer identifier */
123 const char *name; /* ASCII identifier */
124 mode_t mode; /* File access permissions */
125 struct dgrp_proc_entry *child; /* Child pointer */
126
127 /* file ops to use, pass NULL to use default */
128 struct file_operations *proc_file_ops;
129
130 struct proc_dir_entry *de; /* proc entry pointer */
131 struct semaphore excl_sem; /* Protects exclusive access var */
132 int excl_cnt; /* Counts number of curr accesses */
133};
134
135extern void dgrp_unregister_proc(void);
136extern void dgrp_register_proc(void);
137
138/*-----------------------------------------------------------------------*
139 *
140 * Declarations for common operations:
141 *
142 * (either used by more than one of net, mon, or tty,
143 * or in interrupt context (i.e. the poller))
144 *
145 *-----------------------------------------------------------------------*/
146
147void dgrp_carrier(struct ch_struct *ch);
148extern int dgrp_inode_permission(struct inode *inode, int op);
149extern int dgrp_chk_perm(int mode, int op);
150
151
152/*
153 * ID manipulation macros (where c1 & c2 are characters, i is
154 * a long integer, and s is a character array of at least three members
155 */
156
157static inline void ID_TO_CHAR(long i, char *s)
158{
159 s[0] = ((i & 0xff00)>>8);
160 s[1] = (i & 0xff);
161 s[2] = 0;
162}
163
164static inline long CHAR_TO_ID(char *s)
165{
166 return ((s[0] & 0xff) << 8) | (s[1] & 0xff);
167}
168
169static inline struct nd_struct *nd_struct_get(long major)
170{
171 struct nd_struct *nd;
172
173 list_for_each_entry(nd, &nd_struct_list, list) {
174 if (major == nd->nd_major)
175 return nd;
176 }
177
178 return NULL;
179}
180
181static inline int nd_struct_add(struct nd_struct *entry)
182{
183 struct nd_struct *ptr;
184
185 ptr = nd_struct_get(entry->nd_major);
186
187 if (ptr)
188 return -EBUSY;
189
190 list_add_tail(&entry->list, &nd_struct_list);
191
192 return 0;
193}
194
195static inline int nd_struct_del(struct nd_struct *entry)
196{
197 struct nd_struct *nd;
198
199 nd = nd_struct_get(entry->nd_major);
200
201 if (!nd)
202 return -ENODEV;
203
204 list_del(&nd->list);
205 return 0;
206}
207
208#endif /* __DGRP_COMMON_H */