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.
17 * This file implements the mgmt functionality for the
18 * Neo and ClassicBoard based product lines.
21 #include <linux/kernel.h>
22 #include <linux/ctype.h>
23 #include <linux/sched.h>
24 #include <linux/interrupt.h>
25 #include <linux/serial_reg.h>
26 #include <linux/termios.h>
27 #include <linux/uaccess.h>
29 #include "dgnc_driver.h"
31 #include "dgnc_mgmt.h"
33 /* Our "in use" variables, to enforce 1 open only */
34 static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
37 * dgnc_mgmt_open() - Open the mgmt/downld/dpa device.
39 int dgnc_mgmt_open(struct inode *inode, struct file *file)
42 unsigned int minor = iminor(inode);
45 spin_lock_irqsave(&dgnc_global_lock, flags);
47 if (minor >= MAXMGMTDEVICES) {
51 /* Only allow 1 open at a time on mgmt device */
52 if (dgnc_mgmt_in_use[minor]) {
56 dgnc_mgmt_in_use[minor]++;
59 spin_unlock_irqrestore(&dgnc_global_lock, flags);
65 * dgnc_mgmt_close() - Close the mgmt/dpa device
67 int dgnc_mgmt_close(struct inode *inode, struct file *file)
70 unsigned int minor = iminor(inode);
73 spin_lock_irqsave(&dgnc_global_lock, flags);
75 if (minor >= MAXMGMTDEVICES) {
79 dgnc_mgmt_in_use[minor] = 0;
82 spin_unlock_irqrestore(&dgnc_global_lock, flags);
88 * dgnc_mgmt_ioctl() - Ioctl the mgmt/dpa device.
90 long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
93 void __user *uarg = (void __user *)arg;
99 * This returns the total number of boards
100 * in the system, as well as driver version
101 * and has space for a reserved entry
103 struct digi_dinfo ddi;
105 spin_lock_irqsave(&dgnc_global_lock, flags);
107 memset(&ddi, 0, sizeof(ddi));
108 ddi.dinfo_nboards = dgnc_num_boards;
109 sprintf(ddi.dinfo_version, "%s", DG_PART);
111 spin_unlock_irqrestore(&dgnc_global_lock, flags);
113 if (copy_to_user(uarg, &ddi, sizeof(ddi)))
125 if (copy_from_user(&brd, uarg, sizeof(int)))
128 if (brd < 0 || brd >= dgnc_num_boards)
131 memset(&di, 0, sizeof(di));
135 spin_lock_irqsave(&dgnc_board[brd]->bd_lock, flags);
137 di.info_bdtype = dgnc_board[brd]->dpatype;
138 di.info_bdstate = dgnc_board[brd]->dpastatus;
140 di.info_physaddr = (ulong)dgnc_board[brd]->membase;
141 di.info_physsize = (ulong)dgnc_board[brd]->membase
142 - dgnc_board[brd]->membase_end;
143 if (dgnc_board[brd]->state != BOARD_FAILED)
144 di.info_nports = dgnc_board[brd]->nasync;
148 spin_unlock_irqrestore(&dgnc_board[brd]->bd_lock, flags);
150 if (copy_to_user(uarg, &di, sizeof(di)))
156 case DIGI_GET_NI_INFO:
158 struct channel_t *ch;
160 unsigned char mstat = 0;
164 if (copy_from_user(&ni, uarg, sizeof(ni)))
168 channel = ni.channel;
170 if (board >= dgnc_num_boards)
173 if (channel >= dgnc_board[board]->nasync)
176 ch = dgnc_board[board]->channels[channel];
181 memset(&ni, 0, sizeof(ni));
183 ni.channel = channel;
185 spin_lock_irqsave(&ch->ch_lock, flags);
187 mstat = ch->ch_mostat | ch->ch_mistat;
189 if (mstat & UART_MCR_DTR) {
190 ni.mstat |= TIOCM_DTR;
193 if (mstat & UART_MCR_RTS) {
194 ni.mstat |= TIOCM_RTS;
197 if (mstat & UART_MSR_CTS) {
198 ni.mstat |= TIOCM_CTS;
201 if (mstat & UART_MSR_RI) {
202 ni.mstat |= TIOCM_RI;
205 if (mstat & UART_MSR_DCD) {
206 ni.mstat |= TIOCM_CD;
209 if (mstat & UART_MSR_DSR)
210 ni.mstat |= TIOCM_DSR;
212 ni.iflag = ch->ch_c_iflag;
213 ni.oflag = ch->ch_c_oflag;
214 ni.cflag = ch->ch_c_cflag;
215 ni.lflag = ch->ch_c_lflag;
217 if (ch->ch_digi.digi_flags & CTSPACE ||
218 ch->ch_c_cflag & CRTSCTS)
223 if ((ch->ch_flags & CH_STOPI) ||
224 (ch->ch_flags & CH_FORCED_STOPI))
229 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
234 ni.curtx = ch->ch_txcount;
235 ni.currx = ch->ch_rxcount;
237 ni.baud = ch->ch_old_baud;
239 spin_unlock_irqrestore(&ch->ch_lock, flags);
241 if (copy_to_user(uarg, &ni, sizeof(ni)))