blob: 200da36caa781c9dfa05fa8e07906e6aeec9f302 [file] [log] [blame]
Lidza Louina0b99d582013-08-01 17:00:20 -04001/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
21 *
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
26 *
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
28 * Thank you.
29 *
30 */
31
32/************************************************************************
33 *
34 * This file implements the mgmt functionality for the
35 * Neo and ClassicBoard based product lines.
36 *
37 ************************************************************************
38 * $Id: dgnc_mgmt.c,v 1.2 2010/12/14 20:08:29 markh Exp $
39 */
40#include <linux/kernel.h>
Lidza Louina0b99d582013-08-01 17:00:20 -040041#include <linux/ctype.h>
42#include <linux/sched.h> /* For jiffies, task states */
43#include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
44#include <linux/serial_reg.h>
45#include <linux/termios.h>
46#include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
47
48#include "dgnc_driver.h"
49#include "dgnc_pci.h"
Lidza Louina0b99d582013-08-01 17:00:20 -040050#include "dgnc_kcompat.h" /* Kernel 2.4/2.6 compat includes */
51#include "dgnc_mgmt.h"
52#include "dpacompat.h"
53
54
55/* Our "in use" variables, to enforce 1 open only */
56static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
57
58
59/*
60 * dgnc_mgmt_open()
61 *
62 * Open the mgmt/downld/dpa device
63 */
64int dgnc_mgmt_open(struct inode *inode, struct file *file)
65{
66 unsigned long lock_flags;
67 unsigned int minor = iminor(inode);
68
69 DPR_MGMT(("dgnc_mgmt_open start.\n"));
70
71 DGNC_LOCK(dgnc_global_lock, lock_flags);
72
73 /* mgmt device */
74 if (minor < MAXMGMTDEVICES) {
75 /* Only allow 1 open at a time on mgmt device */
76 if (dgnc_mgmt_in_use[minor]) {
77 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
78 return (-EBUSY);
79 }
80 dgnc_mgmt_in_use[minor]++;
81 }
82 else {
83 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
84 return (-ENXIO);
85 }
86
87 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
88
89 DPR_MGMT(("dgnc_mgmt_open finish.\n"));
90
91 return 0;
92}
93
94
95/*
96 * dgnc_mgmt_close()
97 *
98 * Open the mgmt/dpa device
99 */
100int dgnc_mgmt_close(struct inode *inode, struct file *file)
101{
102 unsigned long lock_flags;
103 unsigned int minor = iminor(inode);
104
105 DPR_MGMT(("dgnc_mgmt_close start.\n"));
106
107 DGNC_LOCK(dgnc_global_lock, lock_flags);
108
109 /* mgmt device */
110 if (minor < MAXMGMTDEVICES) {
111 if (dgnc_mgmt_in_use[minor]) {
112 dgnc_mgmt_in_use[minor] = 0;
113 }
114 }
115 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
116
117 DPR_MGMT(("dgnc_mgmt_close finish.\n"));
118
119 return 0;
120}
121
122
123/*
124 * dgnc_mgmt_ioctl()
125 *
126 * ioctl the mgmt/dpa device
127 */
Lidza Louina62a86e52013-08-20 14:15:36 -0400128
Lidza Louina0b99d582013-08-01 17:00:20 -0400129long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
130{
Lidza Louina0b99d582013-08-01 17:00:20 -0400131 unsigned long lock_flags;
132 void __user *uarg = (void __user *) arg;
133
134 DPR_MGMT(("dgnc_mgmt_ioctl start.\n"));
135
136 switch (cmd) {
137
138 case DIGI_GETDD:
139 {
140 /*
141 * This returns the total number of boards
142 * in the system, as well as driver version
143 * and has space for a reserved entry
144 */
145 struct digi_dinfo ddi;
146
147 DGNC_LOCK(dgnc_global_lock, lock_flags);
148
149 ddi.dinfo_nboards = dgnc_NumBoards;
150 sprintf(ddi.dinfo_version, "%s", DG_PART);
151
152 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
153
154 DPR_MGMT(("DIGI_GETDD returning numboards: %d version: %s\n",
155 ddi.dinfo_nboards, ddi.dinfo_version));
156
157 if (copy_to_user(uarg, &ddi, sizeof (ddi)))
158 return(-EFAULT);
159
160 break;
161 }
162
163 case DIGI_GETBD:
164 {
165 int brd;
166
167 struct digi_info di;
168
169 if (copy_from_user(&brd, uarg, sizeof(int))) {
170 return(-EFAULT);
171 }
172
173 DPR_MGMT(("DIGI_GETBD asking about board: %d\n", brd));
174
175 if ((brd < 0) || (brd > dgnc_NumBoards) || (dgnc_NumBoards == 0))
176 return (-ENODEV);
177
178 memset(&di, 0, sizeof(di));
179
180 di.info_bdnum = brd;
181
182 DGNC_LOCK(dgnc_Board[brd]->bd_lock, lock_flags);
183
184 di.info_bdtype = dgnc_Board[brd]->dpatype;
185 di.info_bdstate = dgnc_Board[brd]->dpastatus;
186 di.info_ioport = 0;
187 di.info_physaddr = (ulong) dgnc_Board[brd]->membase;
188 di.info_physsize = (ulong) dgnc_Board[brd]->membase - dgnc_Board[brd]->membase_end;
189 if (dgnc_Board[brd]->state != BOARD_FAILED)
190 di.info_nports = dgnc_Board[brd]->nasync;
191 else
192 di.info_nports = 0;
193
194 DGNC_UNLOCK(dgnc_Board[brd]->bd_lock, lock_flags);
195
196 DPR_MGMT(("DIGI_GETBD returning type: %x state: %x ports: %x size: %x\n",
197 di.info_bdtype, di.info_bdstate, di.info_nports, di.info_physsize));
198
199 if (copy_to_user(uarg, &di, sizeof (di)))
200 return (-EFAULT);
201
202 break;
203 }
204
205 case DIGI_GET_NI_INFO:
206 {
207 struct channel_t *ch;
208 struct ni_info ni;
209 uchar mstat = 0;
210 uint board = 0;
211 uint channel = 0;
212
213 if (copy_from_user(&ni, uarg, sizeof(struct ni_info))) {
214 return(-EFAULT);
215 }
216
217 DPR_MGMT(("DIGI_GETBD asking about board: %d channel: %d\n",
218 ni.board, ni.channel));
219
220 board = ni.board;
221 channel = ni.channel;
222
223 /* Verify boundaries on board */
224 if ((board < 0) || (board > dgnc_NumBoards) || (dgnc_NumBoards == 0))
225 return (-ENODEV);
226
227 /* Verify boundaries on channel */
228 if ((channel < 0) || (channel > dgnc_Board[board]->nasync))
229 return (-ENODEV);
230
231 ch = dgnc_Board[board]->channels[channel];
232
233 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
234 return (-ENODEV);
235
236 memset(&ni, 0, sizeof(ni));
237 ni.board = board;
238 ni.channel = channel;
239
240 DGNC_LOCK(ch->ch_lock, lock_flags);
241
242 mstat = (ch->ch_mostat | ch->ch_mistat);
243
244 if (mstat & UART_MCR_DTR) {
245 ni.mstat |= TIOCM_DTR;
246 ni.dtr = TIOCM_DTR;
247 }
248 if (mstat & UART_MCR_RTS) {
249 ni.mstat |= TIOCM_RTS;
250 ni.rts = TIOCM_RTS;
251 }
252 if (mstat & UART_MSR_CTS) {
253 ni.mstat |= TIOCM_CTS;
254 ni.cts = TIOCM_CTS;
255 }
256 if (mstat & UART_MSR_RI) {
257 ni.mstat |= TIOCM_RI;
258 ni.ri = TIOCM_RI;
259 }
260 if (mstat & UART_MSR_DCD) {
261 ni.mstat |= TIOCM_CD;
262 ni.dcd = TIOCM_CD;
263 }
264 if (mstat & UART_MSR_DSR)
265 ni.mstat |= TIOCM_DSR;
266
267 ni.iflag = ch->ch_c_iflag;
268 ni.oflag = ch->ch_c_oflag;
269 ni.cflag = ch->ch_c_cflag;
270 ni.lflag = ch->ch_c_lflag;
271
272 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS)
273 ni.hflow = 1;
274 else
275 ni.hflow = 0;
276
277 if ((ch->ch_flags & CH_STOPI) || (ch->ch_flags & CH_FORCED_STOPI))
278 ni.recv_stopped = 1;
279 else
280 ni.recv_stopped = 0;
281
282 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
283 ni.xmit_stopped = 1;
284 else
285 ni.xmit_stopped = 0;
286
287 ni.curtx = ch->ch_txcount;
288 ni.currx = ch->ch_rxcount;
289
290 ni.baud = ch->ch_old_baud;
291
292 DGNC_UNLOCK(ch->ch_lock, lock_flags);
293
294 if (copy_to_user(uarg, &ni, sizeof(ni)))
295 return (-EFAULT);
296
297 break;
298 }
299
300
301 }
302
303 DPR_MGMT(("dgnc_mgmt_ioctl finish.\n"));
304
305 return 0;
306}