2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
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)
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.
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.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
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.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
32 /************************************************************************
34 * This file implements the mgmt functionality for the
35 * Neo and ClassicBoard based product lines.
37 ************************************************************************
39 #include <linux/kernel.h>
40 #include <linux/ctype.h>
41 #include <linux/sched.h> /* For jiffies, task states */
42 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
43 #include <linux/serial_reg.h>
44 #include <linux/termios.h>
45 #include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
47 #include "dgnc_driver.h"
49 #include "dgnc_kcompat.h" /* Kernel 2.4/2.6 compat includes */
50 #include "dgnc_mgmt.h"
51 #include "dpacompat.h"
54 /* Our "in use" variables, to enforce 1 open only */
55 static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
61 * Open the mgmt/downld/dpa device
63 int dgnc_mgmt_open(struct inode *inode, struct file *file)
66 unsigned int minor = iminor(inode);
68 spin_lock_irqsave(&dgnc_global_lock, flags);
71 if (minor < MAXMGMTDEVICES) {
72 /* Only allow 1 open at a time on mgmt device */
73 if (dgnc_mgmt_in_use[minor]) {
74 spin_unlock_irqrestore(&dgnc_global_lock, flags);
77 dgnc_mgmt_in_use[minor]++;
79 spin_unlock_irqrestore(&dgnc_global_lock, flags);
83 spin_unlock_irqrestore(&dgnc_global_lock, flags);
92 * Open the mgmt/dpa device
94 int dgnc_mgmt_close(struct inode *inode, struct file *file)
97 unsigned int minor = iminor(inode);
99 spin_lock_irqsave(&dgnc_global_lock, flags);
102 if (minor < MAXMGMTDEVICES) {
103 if (dgnc_mgmt_in_use[minor])
104 dgnc_mgmt_in_use[minor] = 0;
106 spin_unlock_irqrestore(&dgnc_global_lock, flags);
115 * ioctl the mgmt/dpa device
118 long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
121 void __user *uarg = (void __user *) arg;
128 * This returns the total number of boards
129 * in the system, as well as driver version
130 * and has space for a reserved entry
132 struct digi_dinfo ddi;
134 spin_lock_irqsave(&dgnc_global_lock, flags);
136 ddi.dinfo_nboards = dgnc_NumBoards;
137 sprintf(ddi.dinfo_version, "%s", DG_PART);
139 spin_unlock_irqrestore(&dgnc_global_lock, flags);
141 if (copy_to_user(uarg, &ddi, sizeof(ddi)))
153 if (copy_from_user(&brd, uarg, sizeof(int)))
156 if ((brd < 0) || (brd > dgnc_NumBoards) ||
157 (dgnc_NumBoards == 0))
160 memset(&di, 0, sizeof(di));
164 spin_lock_irqsave(&dgnc_Board[brd]->bd_lock, flags);
166 di.info_bdtype = dgnc_Board[brd]->dpatype;
167 di.info_bdstate = dgnc_Board[brd]->dpastatus;
169 di.info_physaddr = (ulong) dgnc_Board[brd]->membase;
170 di.info_physsize = (ulong) dgnc_Board[brd]->membase - dgnc_Board[brd]->membase_end;
171 if (dgnc_Board[brd]->state != BOARD_FAILED)
172 di.info_nports = dgnc_Board[brd]->nasync;
176 spin_unlock_irqrestore(&dgnc_Board[brd]->bd_lock, flags);
178 if (copy_to_user(uarg, &di, sizeof(di)))
184 case DIGI_GET_NI_INFO:
186 struct channel_t *ch;
188 unsigned char mstat = 0;
192 if (copy_from_user(&ni, uarg, sizeof(ni)))
196 channel = ni.channel;
198 /* Verify boundaries on board */
199 if ((board > dgnc_NumBoards) || (dgnc_NumBoards == 0))
202 /* Verify boundaries on channel */
203 if ((channel < 0) || (channel > dgnc_Board[board]->nasync))
206 ch = dgnc_Board[board]->channels[channel];
208 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
211 memset(&ni, 0, sizeof(ni));
213 ni.channel = channel;
215 spin_lock_irqsave(&ch->ch_lock, flags);
217 mstat = (ch->ch_mostat | ch->ch_mistat);
219 if (mstat & UART_MCR_DTR) {
220 ni.mstat |= TIOCM_DTR;
223 if (mstat & UART_MCR_RTS) {
224 ni.mstat |= TIOCM_RTS;
227 if (mstat & UART_MSR_CTS) {
228 ni.mstat |= TIOCM_CTS;
231 if (mstat & UART_MSR_RI) {
232 ni.mstat |= TIOCM_RI;
235 if (mstat & UART_MSR_DCD) {
236 ni.mstat |= TIOCM_CD;
239 if (mstat & UART_MSR_DSR)
240 ni.mstat |= TIOCM_DSR;
242 ni.iflag = ch->ch_c_iflag;
243 ni.oflag = ch->ch_c_oflag;
244 ni.cflag = ch->ch_c_cflag;
245 ni.lflag = ch->ch_c_lflag;
247 if (ch->ch_digi.digi_flags & CTSPACE ||
248 ch->ch_c_cflag & CRTSCTS)
253 if ((ch->ch_flags & CH_STOPI) ||
254 (ch->ch_flags & CH_FORCED_STOPI))
259 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
264 ni.curtx = ch->ch_txcount;
265 ni.currx = ch->ch_rxcount;
267 ni.baud = ch->ch_old_baud;
269 spin_unlock_irqrestore(&ch->ch_lock, flags);
271 if (copy_to_user(uarg, &ni, sizeof(ni)))