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