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_kcompat.h" /* Kernel 2.4/2.6 compat includes */
34 #include "dgnc_mgmt.h"
35 #include "dpacompat.h"
38 /* Our "in use" variables, to enforce 1 open only */
39 static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
45 * Open the mgmt/downld/dpa device
47 int dgnc_mgmt_open(struct inode *inode, struct file *file)
50 unsigned int minor = iminor(inode);
52 spin_lock_irqsave(&dgnc_global_lock, flags);
55 if (minor < MAXMGMTDEVICES) {
56 /* Only allow 1 open at a time on mgmt device */
57 if (dgnc_mgmt_in_use[minor]) {
58 spin_unlock_irqrestore(&dgnc_global_lock, flags);
61 dgnc_mgmt_in_use[minor]++;
63 spin_unlock_irqrestore(&dgnc_global_lock, flags);
67 spin_unlock_irqrestore(&dgnc_global_lock, flags);
76 * Open the mgmt/dpa device
78 int dgnc_mgmt_close(struct inode *inode, struct file *file)
81 unsigned int minor = iminor(inode);
83 spin_lock_irqsave(&dgnc_global_lock, flags);
86 if (minor < MAXMGMTDEVICES) {
87 if (dgnc_mgmt_in_use[minor])
88 dgnc_mgmt_in_use[minor] = 0;
90 spin_unlock_irqrestore(&dgnc_global_lock, flags);
99 * ioctl the mgmt/dpa device
102 long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
105 void __user *uarg = (void __user *) arg;
112 * This returns the total number of boards
113 * in the system, as well as driver version
114 * and has space for a reserved entry
116 struct digi_dinfo ddi;
118 spin_lock_irqsave(&dgnc_global_lock, flags);
120 ddi.dinfo_nboards = dgnc_NumBoards;
121 sprintf(ddi.dinfo_version, "%s", DG_PART);
123 spin_unlock_irqrestore(&dgnc_global_lock, flags);
125 if (copy_to_user(uarg, &ddi, sizeof(ddi)))
137 if (copy_from_user(&brd, uarg, sizeof(int)))
140 if (brd < 0 || brd >= dgnc_NumBoards)
143 memset(&di, 0, sizeof(di));
147 spin_lock_irqsave(&dgnc_Board[brd]->bd_lock, flags);
149 di.info_bdtype = dgnc_Board[brd]->dpatype;
150 di.info_bdstate = dgnc_Board[brd]->dpastatus;
152 di.info_physaddr = (ulong) dgnc_Board[brd]->membase;
153 di.info_physsize = (ulong) dgnc_Board[brd]->membase - dgnc_Board[brd]->membase_end;
154 if (dgnc_Board[brd]->state != BOARD_FAILED)
155 di.info_nports = dgnc_Board[brd]->nasync;
159 spin_unlock_irqrestore(&dgnc_Board[brd]->bd_lock, flags);
161 if (copy_to_user(uarg, &di, sizeof(di)))
167 case DIGI_GET_NI_INFO:
169 struct channel_t *ch;
171 unsigned char mstat = 0;
175 if (copy_from_user(&ni, uarg, sizeof(ni)))
179 channel = ni.channel;
181 /* Verify boundaries on board */
182 if (board >= dgnc_NumBoards)
185 /* Verify boundaries on channel */
186 if (channel >= dgnc_Board[board]->nasync)
189 ch = dgnc_Board[board]->channels[channel];
191 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
194 memset(&ni, 0, sizeof(ni));
196 ni.channel = channel;
198 spin_lock_irqsave(&ch->ch_lock, flags);
200 mstat = (ch->ch_mostat | ch->ch_mistat);
202 if (mstat & UART_MCR_DTR) {
203 ni.mstat |= TIOCM_DTR;
206 if (mstat & UART_MCR_RTS) {
207 ni.mstat |= TIOCM_RTS;
210 if (mstat & UART_MSR_CTS) {
211 ni.mstat |= TIOCM_CTS;
214 if (mstat & UART_MSR_RI) {
215 ni.mstat |= TIOCM_RI;
218 if (mstat & UART_MSR_DCD) {
219 ni.mstat |= TIOCM_CD;
222 if (mstat & UART_MSR_DSR)
223 ni.mstat |= TIOCM_DSR;
225 ni.iflag = ch->ch_c_iflag;
226 ni.oflag = ch->ch_c_oflag;
227 ni.cflag = ch->ch_c_cflag;
228 ni.lflag = ch->ch_c_lflag;
230 if (ch->ch_digi.digi_flags & CTSPACE ||
231 ch->ch_c_cflag & CRTSCTS)
236 if ((ch->ch_flags & CH_STOPI) ||
237 (ch->ch_flags & CH_FORCED_STOPI))
242 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
247 ni.curtx = ch->ch_txcount;
248 ni.currx = ch->ch_rxcount;
250 ni.baud = ch->ch_old_baud;
252 spin_unlock_irqrestore(&ch->ch_lock, flags);
254 if (copy_to_user(uarg, &ni, sizeof(ni)))