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.
16 /************************************************************************
18 * This file implements the mgmt functionality for the
19 * Neo and ClassicBoard based product lines.
21 ************************************************************************
23 #include <linux/kernel.h>
24 #include <linux/ctype.h>
25 #include <linux/sched.h> /* For jiffies, task states */
26 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
27 #include <linux/serial_reg.h>
28 #include <linux/termios.h>
29 #include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
31 #include "dgnc_driver.h"
33 #include "dgnc_mgmt.h"
36 /* Our "in use" variables, to enforce 1 open only */
37 static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
43 * Open the mgmt/downld/dpa device
45 int dgnc_mgmt_open(struct inode *inode, struct file *file)
48 unsigned int minor = iminor(inode);
50 spin_lock_irqsave(&dgnc_global_lock, flags);
53 if (minor < MAXMGMTDEVICES) {
54 /* Only allow 1 open at a time on mgmt device */
55 if (dgnc_mgmt_in_use[minor]) {
56 spin_unlock_irqrestore(&dgnc_global_lock, flags);
59 dgnc_mgmt_in_use[minor]++;
61 spin_unlock_irqrestore(&dgnc_global_lock, flags);
65 spin_unlock_irqrestore(&dgnc_global_lock, flags);
74 * Open the mgmt/dpa device
76 int dgnc_mgmt_close(struct inode *inode, struct file *file)
79 unsigned int minor = iminor(inode);
81 spin_lock_irqsave(&dgnc_global_lock, flags);
84 if (minor < MAXMGMTDEVICES) {
85 if (dgnc_mgmt_in_use[minor])
86 dgnc_mgmt_in_use[minor] = 0;
88 spin_unlock_irqrestore(&dgnc_global_lock, flags);
97 * ioctl the mgmt/dpa device
100 long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
103 void __user *uarg = (void __user *) arg;
110 * This returns the total number of boards
111 * in the system, as well as driver version
112 * and has space for a reserved entry
114 struct digi_dinfo ddi;
116 spin_lock_irqsave(&dgnc_global_lock, flags);
118 ddi.dinfo_nboards = dgnc_NumBoards;
119 sprintf(ddi.dinfo_version, "%s", DG_PART);
121 spin_unlock_irqrestore(&dgnc_global_lock, flags);
123 if (copy_to_user(uarg, &ddi, sizeof(ddi)))
135 if (copy_from_user(&brd, uarg, sizeof(int)))
138 if (brd < 0 || brd >= dgnc_NumBoards)
141 memset(&di, 0, sizeof(di));
145 spin_lock_irqsave(&dgnc_Board[brd]->bd_lock, flags);
147 di.info_bdtype = dgnc_Board[brd]->dpatype;
148 di.info_bdstate = dgnc_Board[brd]->dpastatus;
150 di.info_physaddr = (ulong) dgnc_Board[brd]->membase;
151 di.info_physsize = (ulong) dgnc_Board[brd]->membase - dgnc_Board[brd]->membase_end;
152 if (dgnc_Board[brd]->state != BOARD_FAILED)
153 di.info_nports = dgnc_Board[brd]->nasync;
157 spin_unlock_irqrestore(&dgnc_Board[brd]->bd_lock, flags);
159 if (copy_to_user(uarg, &di, sizeof(di)))
165 case DIGI_GET_NI_INFO:
167 struct channel_t *ch;
169 unsigned char mstat = 0;
173 if (copy_from_user(&ni, uarg, sizeof(ni)))
177 channel = ni.channel;
179 /* Verify boundaries on board */
180 if (board >= dgnc_NumBoards)
183 /* Verify boundaries on channel */
184 if (channel >= dgnc_Board[board]->nasync)
187 ch = dgnc_Board[board]->channels[channel];
189 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
192 memset(&ni, 0, sizeof(ni));
194 ni.channel = channel;
196 spin_lock_irqsave(&ch->ch_lock, flags);
198 mstat = (ch->ch_mostat | ch->ch_mistat);
200 if (mstat & UART_MCR_DTR) {
201 ni.mstat |= TIOCM_DTR;
204 if (mstat & UART_MCR_RTS) {
205 ni.mstat |= TIOCM_RTS;
208 if (mstat & UART_MSR_CTS) {
209 ni.mstat |= TIOCM_CTS;
212 if (mstat & UART_MSR_RI) {
213 ni.mstat |= TIOCM_RI;
216 if (mstat & UART_MSR_DCD) {
217 ni.mstat |= TIOCM_CD;
220 if (mstat & UART_MSR_DSR)
221 ni.mstat |= TIOCM_DSR;
223 ni.iflag = ch->ch_c_iflag;
224 ni.oflag = ch->ch_c_oflag;
225 ni.cflag = ch->ch_c_cflag;
226 ni.lflag = ch->ch_c_lflag;
228 if (ch->ch_digi.digi_flags & CTSPACE ||
229 ch->ch_c_cflag & CRTSCTS)
234 if ((ch->ch_flags & CH_STOPI) ||
235 (ch->ch_flags & CH_FORCED_STOPI))
240 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
245 ni.curtx = ch->ch_txcount;
246 ni.currx = ch->ch_rxcount;
248 ni.baud = ch->ch_old_baud;
250 spin_unlock_irqrestore(&ch->ch_lock, flags);
252 if (copy_to_user(uarg, &ni, sizeof(ni)))