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 ************************************************************************
38 * $Id: dgnc_mgmt.c,v 1.2 2010/12/14 20:08:29 markh Exp $
40 #include <linux/kernel.h>
41 #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 */
48 #include "dgnc_driver.h"
50 #include "dgnc_kcompat.h" /* Kernel 2.4/2.6 compat includes */
51 #include "dgnc_mgmt.h"
52 #include "dpacompat.h"
55 /* Our "in use" variables, to enforce 1 open only */
56 static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
62 * Open the mgmt/downld/dpa device
64 int dgnc_mgmt_open(struct inode *inode, struct file *file)
66 unsigned long lock_flags;
67 unsigned int minor = iminor(inode);
69 DPR_MGMT(("dgnc_mgmt_open start.\n"));
71 DGNC_LOCK(dgnc_global_lock, lock_flags);
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);
80 dgnc_mgmt_in_use[minor]++;
83 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
87 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
89 DPR_MGMT(("dgnc_mgmt_open finish.\n"));
98 * Open the mgmt/dpa device
100 int dgnc_mgmt_close(struct inode *inode, struct file *file)
102 unsigned long lock_flags;
103 unsigned int minor = iminor(inode);
105 DPR_MGMT(("dgnc_mgmt_close start.\n"));
107 DGNC_LOCK(dgnc_global_lock, lock_flags);
110 if (minor < MAXMGMTDEVICES) {
111 if (dgnc_mgmt_in_use[minor]) {
112 dgnc_mgmt_in_use[minor] = 0;
115 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
117 DPR_MGMT(("dgnc_mgmt_close finish.\n"));
126 * ioctl the mgmt/dpa device
128 #ifdef HAVE_UNLOCKED_IOCTL
129 long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
131 struct inode *inode = file->f_dentry->d_inode;
133 int dgnc_mgmt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
136 unsigned long lock_flags;
137 void __user *uarg = (void __user *) arg;
139 DPR_MGMT(("dgnc_mgmt_ioctl start.\n"));
146 * This returns the total number of boards
147 * in the system, as well as driver version
148 * and has space for a reserved entry
150 struct digi_dinfo ddi;
152 DGNC_LOCK(dgnc_global_lock, lock_flags);
154 ddi.dinfo_nboards = dgnc_NumBoards;
155 sprintf(ddi.dinfo_version, "%s", DG_PART);
157 DGNC_UNLOCK(dgnc_global_lock, lock_flags);
159 DPR_MGMT(("DIGI_GETDD returning numboards: %d version: %s\n",
160 ddi.dinfo_nboards, ddi.dinfo_version));
162 if (copy_to_user(uarg, &ddi, sizeof (ddi)))
174 if (copy_from_user(&brd, uarg, sizeof(int))) {
178 DPR_MGMT(("DIGI_GETBD asking about board: %d\n", brd));
180 if ((brd < 0) || (brd > dgnc_NumBoards) || (dgnc_NumBoards == 0))
183 memset(&di, 0, sizeof(di));
187 DGNC_LOCK(dgnc_Board[brd]->bd_lock, lock_flags);
189 di.info_bdtype = dgnc_Board[brd]->dpatype;
190 di.info_bdstate = dgnc_Board[brd]->dpastatus;
192 di.info_physaddr = (ulong) dgnc_Board[brd]->membase;
193 di.info_physsize = (ulong) dgnc_Board[brd]->membase - dgnc_Board[brd]->membase_end;
194 if (dgnc_Board[brd]->state != BOARD_FAILED)
195 di.info_nports = dgnc_Board[brd]->nasync;
199 DGNC_UNLOCK(dgnc_Board[brd]->bd_lock, lock_flags);
201 DPR_MGMT(("DIGI_GETBD returning type: %x state: %x ports: %x size: %x\n",
202 di.info_bdtype, di.info_bdstate, di.info_nports, di.info_physsize));
204 if (copy_to_user(uarg, &di, sizeof (di)))
210 case DIGI_GET_NI_INFO:
212 struct channel_t *ch;
218 if (copy_from_user(&ni, uarg, sizeof(struct ni_info))) {
222 DPR_MGMT(("DIGI_GETBD asking about board: %d channel: %d\n",
223 ni.board, ni.channel));
226 channel = ni.channel;
228 /* Verify boundaries on board */
229 if ((board < 0) || (board > dgnc_NumBoards) || (dgnc_NumBoards == 0))
232 /* Verify boundaries on channel */
233 if ((channel < 0) || (channel > dgnc_Board[board]->nasync))
236 ch = dgnc_Board[board]->channels[channel];
238 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
241 memset(&ni, 0, sizeof(ni));
243 ni.channel = channel;
245 DGNC_LOCK(ch->ch_lock, lock_flags);
247 mstat = (ch->ch_mostat | ch->ch_mistat);
249 if (mstat & UART_MCR_DTR) {
250 ni.mstat |= TIOCM_DTR;
253 if (mstat & UART_MCR_RTS) {
254 ni.mstat |= TIOCM_RTS;
257 if (mstat & UART_MSR_CTS) {
258 ni.mstat |= TIOCM_CTS;
261 if (mstat & UART_MSR_RI) {
262 ni.mstat |= TIOCM_RI;
265 if (mstat & UART_MSR_DCD) {
266 ni.mstat |= TIOCM_CD;
269 if (mstat & UART_MSR_DSR)
270 ni.mstat |= TIOCM_DSR;
272 ni.iflag = ch->ch_c_iflag;
273 ni.oflag = ch->ch_c_oflag;
274 ni.cflag = ch->ch_c_cflag;
275 ni.lflag = ch->ch_c_lflag;
277 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS)
282 if ((ch->ch_flags & CH_STOPI) || (ch->ch_flags & CH_FORCED_STOPI))
287 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
292 ni.curtx = ch->ch_txcount;
293 ni.currx = ch->ch_rxcount;
295 ni.baud = ch->ch_old_baud;
297 DGNC_UNLOCK(ch->ch_lock, lock_flags);
299 if (copy_to_user(uarg, &ni, sizeof(ni)))
308 DPR_MGMT(("dgnc_mgmt_ioctl finish.\n"));