blob: 88fc24fc43928674ef24647a394a2348cd18c082 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2
3
4 Copyright (C) 1996 Digi International.
5
6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456
8
Alan Coxf2cf8e22005-09-06 15:16:44 -07009 ** This driver is no longer supported by Digi **
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 Much of this design and code came from epca.c which was
12 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
13 modified by David Nugent, Christoph Lameter, Mike McLagan.
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
29--------------------------------------------------------------------------- */
30/* See README.epca for change history --DAT*/
31
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/types.h>
36#include <linux/init.h>
37#include <linux/serial.h>
38#include <linux/delay.h>
39#include <linux/ctype.h>
40#include <linux/tty.h>
41#include <linux/tty_flip.h>
42#include <linux/slab.h>
43#include <linux/ioport.h>
44#include <linux/interrupt.h>
45#include <asm/uaccess.h>
46#include <asm/io.h>
Alan Coxf2cf8e22005-09-06 15:16:44 -070047#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/pci.h>
49#include "digiPCI.h"
Alan Coxf2cf8e22005-09-06 15:16:44 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include "digi1.h"
53#include "digiFep1.h"
54#include "epca.h"
55#include "epcaconfig.h"
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* ---------------------- Begin defines ------------------------ */
58
Alan Coxf2cf8e22005-09-06 15:16:44 -070059#define VERSION "1.3.0.1-LK2.6"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61/* This major needs to be submitted to Linux to join the majors list */
62
63#define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
64
65
66#define MAXCARDS 7
67#define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
68
69#define PFX "epca: "
70
71/* ----------------- Begin global definitions ------------------- */
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static int nbdevs, num_cards, liloconfig;
74static int digi_poller_inhibited = 1 ;
75
76static int setup_error_code;
77static int invalid_lilo_config;
78
Alan Coxf2cf8e22005-09-06 15:16:44 -070079/* The ISA boards do window flipping into the same spaces so its only sane
80 with a single lock. It's still pretty efficient */
81
Ingo Molnar34af9462006-06-27 02:53:55 -070082static DEFINE_SPINLOCK(epca_lock);
Alan Coxf2cf8e22005-09-06 15:16:44 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/* -----------------------------------------------------------------------
85 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
86 7 below.
87--------------------------------------------------------------------------*/
88static struct board_info boards[MAXBOARDS];
89
90
91/* ------------- Begin structures used for driver registeration ---------- */
92
93static struct tty_driver *pc_driver;
94static struct tty_driver *pc_info;
95
96/* ------------------ Begin Digi specific structures -------------------- */
97
98/* ------------------------------------------------------------------------
99 digi_channels represents an array of structures that keep track of
100 each channel of the Digi product. Information such as transmit and
101 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
102 are stored here. This structure is NOT used to overlay the cards
103 physical channel structure.
104-------------------------------------------------------------------------- */
105
106static struct channel digi_channels[MAX_ALLOC];
107
108/* ------------------------------------------------------------------------
109 card_ptr is an array used to hold the address of the
110 first channel structure of each card. This array will hold
111 the addresses of various channels located in digi_channels.
112-------------------------------------------------------------------------- */
113static struct channel *card_ptr[MAXCARDS];
114
115static struct timer_list epca_timer;
116
117/* ---------------------- Begin function prototypes --------------------- */
118
119/* ----------------------------------------------------------------------
120 Begin generic memory functions. These functions will be alias
121 (point at) more specific functions dependent on the board being
122 configured.
123----------------------------------------------------------------------- */
124
Alan Coxf2cf8e22005-09-06 15:16:44 -0700125static void memwinon(struct board_info *b, unsigned int win);
126static void memwinoff(struct board_info *b, unsigned int win);
127static void globalwinon(struct channel *ch);
128static void rxwinon(struct channel *ch);
129static void txwinon(struct channel *ch);
130static void memoff(struct channel *ch);
131static void assertgwinon(struct channel *ch);
132static void assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/* ---- Begin more 'specific' memory functions for cx_like products --- */
135
Alan Coxf2cf8e22005-09-06 15:16:44 -0700136static void pcxem_memwinon(struct board_info *b, unsigned int win);
137static void pcxem_memwinoff(struct board_info *b, unsigned int win);
138static void pcxem_globalwinon(struct channel *ch);
139static void pcxem_rxwinon(struct channel *ch);
140static void pcxem_txwinon(struct channel *ch);
141static void pcxem_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/* ------ Begin more 'specific' memory functions for the pcxe ------- */
144
Alan Coxf2cf8e22005-09-06 15:16:44 -0700145static void pcxe_memwinon(struct board_info *b, unsigned int win);
146static void pcxe_memwinoff(struct board_info *b, unsigned int win);
147static void pcxe_globalwinon(struct channel *ch);
148static void pcxe_rxwinon(struct channel *ch);
149static void pcxe_txwinon(struct channel *ch);
150static void pcxe_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
153/* Note : pc64xe and pcxi share the same windowing routines */
154
Alan Coxf2cf8e22005-09-06 15:16:44 -0700155static void pcxi_memwinon(struct board_info *b, unsigned int win);
156static void pcxi_memwinoff(struct board_info *b, unsigned int win);
157static void pcxi_globalwinon(struct channel *ch);
158static void pcxi_rxwinon(struct channel *ch);
159static void pcxi_txwinon(struct channel *ch);
160static void pcxi_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162/* - Begin 'specific' do nothing memory functions needed for some cards - */
163
Alan Coxf2cf8e22005-09-06 15:16:44 -0700164static void dummy_memwinon(struct board_info *b, unsigned int win);
165static void dummy_memwinoff(struct board_info *b, unsigned int win);
166static void dummy_globalwinon(struct channel *ch);
167static void dummy_rxwinon(struct channel *ch);
168static void dummy_txwinon(struct channel *ch);
169static void dummy_memoff(struct channel *ch);
170static void dummy_assertgwinon(struct channel *ch);
171static void dummy_assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173/* ------------------- Begin declare functions ----------------------- */
174
Alan Coxf2cf8e22005-09-06 15:16:44 -0700175static struct channel *verifyChannel(struct tty_struct *);
176static void pc_sched_event(struct channel *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static void epca_error(int, char *);
178static void pc_close(struct tty_struct *, struct file *);
179static void shutdown(struct channel *);
180static void pc_hangup(struct tty_struct *);
181static void pc_put_char(struct tty_struct *, unsigned char);
182static int pc_write_room(struct tty_struct *);
183static int pc_chars_in_buffer(struct tty_struct *);
184static void pc_flush_buffer(struct tty_struct *);
185static void pc_flush_chars(struct tty_struct *);
186static int block_til_ready(struct tty_struct *, struct file *,
187 struct channel *);
188static int pc_open(struct tty_struct *, struct file *);
189static void post_fep_init(unsigned int crd);
190static void epcapoll(unsigned long);
191static void doevent(int);
192static void fepcmd(struct channel *, int, int, int, int, int);
193static unsigned termios2digi_h(struct channel *ch, unsigned);
194static unsigned termios2digi_i(struct channel *ch, unsigned);
195static unsigned termios2digi_c(struct channel *ch, unsigned);
196static void epcaparam(struct tty_struct *, struct channel *);
197static void receive_data(struct channel *);
198static int pc_ioctl(struct tty_struct *, struct file *,
199 unsigned int, unsigned long);
200static int info_ioctl(struct tty_struct *, struct file *,
201 unsigned int, unsigned long);
Alan Cox606d0992006-12-08 02:38:45 -0800202static void pc_set_termios(struct tty_struct *, struct ktermios *);
David Howellsc4028952006-11-22 14:57:56 +0000203static void do_softint(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static void pc_stop(struct tty_struct *);
205static void pc_start(struct tty_struct *);
206static void pc_throttle(struct tty_struct * tty);
207static void pc_unthrottle(struct tty_struct *tty);
208static void digi_send_break(struct channel *ch, int msec);
209static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
210void epca_setup(char *, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212static int get_termio(struct tty_struct *, struct termio __user *);
213static int pc_write(struct tty_struct *, const unsigned char *, int);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700214static int pc_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215static int init_PCI(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217
218/* ------------------------------------------------------------------
219 Table of functions for each board to handle memory. Mantaining
220 parallelism is a *very* good idea here. The idea is for the
221 runtime code to blindly call these functions, not knowing/caring
222 about the underlying hardware. This stuff should contain no
223 conditionals; if more functionality is needed a different entry
224 should be established. These calls are the interface calls and
225 are the only functions that should be accessed. Anyone caught
226 making direct calls deserves what they get.
227-------------------------------------------------------------------- */
228
Alan Coxf2cf8e22005-09-06 15:16:44 -0700229static void memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 (b->memwinon)(b, win);
232}
233
Alan Coxf2cf8e22005-09-06 15:16:44 -0700234static void memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 (b->memwinoff)(b, win);
237}
238
Alan Coxf2cf8e22005-09-06 15:16:44 -0700239static void globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 (ch->board->globalwinon)(ch);
242}
243
Alan Coxf2cf8e22005-09-06 15:16:44 -0700244static void rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 (ch->board->rxwinon)(ch);
247}
248
Alan Coxf2cf8e22005-09-06 15:16:44 -0700249static void txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
251 (ch->board->txwinon)(ch);
252}
253
Alan Coxf2cf8e22005-09-06 15:16:44 -0700254static void memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 (ch->board->memoff)(ch);
257}
Alan Coxf2cf8e22005-09-06 15:16:44 -0700258static void assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 (ch->board->assertgwinon)(ch);
261}
262
Alan Coxf2cf8e22005-09-06 15:16:44 -0700263static void assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 (ch->board->assertmemoff)(ch);
266}
267
268/* ---------------------------------------------------------
269 PCXEM windowing is the same as that used in the PCXR
270 and CX series cards.
271------------------------------------------------------------ */
272
Alan Coxf2cf8e22005-09-06 15:16:44 -0700273static void pcxem_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700275 outb_p(FEPWIN|win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
Alan Coxf2cf8e22005-09-06 15:16:44 -0700278static void pcxem_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700280 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
Alan Coxf2cf8e22005-09-06 15:16:44 -0700283static void pcxem_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
285 outb_p( FEPWIN, (int)ch->board->port + 1);
286}
287
Alan Coxf2cf8e22005-09-06 15:16:44 -0700288static void pcxem_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 outb_p(ch->rxwin, (int)ch->board->port + 1);
291}
292
Alan Coxf2cf8e22005-09-06 15:16:44 -0700293static void pcxem_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 outb_p(ch->txwin, (int)ch->board->port + 1);
296}
297
Alan Coxf2cf8e22005-09-06 15:16:44 -0700298static void pcxem_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 outb_p(0, (int)ch->board->port + 1);
301}
302
303/* ----------------- Begin pcxe memory window stuff ------------------ */
304
Alan Coxf2cf8e22005-09-06 15:16:44 -0700305static void pcxe_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700307 outb_p(FEPWIN | win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309
Alan Coxf2cf8e22005-09-06 15:16:44 -0700310static void pcxe_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700312 outb_p(inb(b->port) & ~FEPMEM,
313 b->port + 1);
314 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
Alan Coxf2cf8e22005-09-06 15:16:44 -0700317static void pcxe_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
319 outb_p( FEPWIN, (int)ch->board->port + 1);
320}
321
Alan Coxf2cf8e22005-09-06 15:16:44 -0700322static void pcxe_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
324 outb_p(ch->rxwin, (int)ch->board->port + 1);
325}
326
Alan Coxf2cf8e22005-09-06 15:16:44 -0700327static void pcxe_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
329 outb_p(ch->txwin, (int)ch->board->port + 1);
330}
331
Alan Coxf2cf8e22005-09-06 15:16:44 -0700332static void pcxe_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
334 outb_p(0, (int)ch->board->port);
335 outb_p(0, (int)ch->board->port + 1);
336}
337
338/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
339
Alan Coxf2cf8e22005-09-06 15:16:44 -0700340static void pcxi_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700342 outb_p(inb(b->port) | FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
Alan Coxf2cf8e22005-09-06 15:16:44 -0700345static void pcxi_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700347 outb_p(inb(b->port) & ~FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
Alan Coxf2cf8e22005-09-06 15:16:44 -0700350static void pcxi_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700352 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
Alan Coxf2cf8e22005-09-06 15:16:44 -0700355static void pcxi_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700357 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Alan Coxf2cf8e22005-09-06 15:16:44 -0700360static void pcxi_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700362 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
Alan Coxf2cf8e22005-09-06 15:16:44 -0700365static void pcxi_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700367 outb_p(0, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
Alan Coxf2cf8e22005-09-06 15:16:44 -0700370static void pcxi_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700372 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
Alan Coxf2cf8e22005-09-06 15:16:44 -0700375static void pcxi_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700377 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380
381/* ----------------------------------------------------------------------
382 Not all of the cards need specific memory windowing routines. Some
383 cards (Such as PCI) needs no windowing routines at all. We provide
384 these do nothing routines so that the same code base can be used.
385 The driver will ALWAYS call a windowing routine if it thinks it needs
386 to; regardless of the card. However, dependent on the card the routine
387 may or may not do anything.
388---------------------------------------------------------------------------*/
389
Alan Coxf2cf8e22005-09-06 15:16:44 -0700390static void dummy_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
392}
393
Alan Coxf2cf8e22005-09-06 15:16:44 -0700394static void dummy_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396}
397
Alan Coxf2cf8e22005-09-06 15:16:44 -0700398static void dummy_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400}
401
Alan Coxf2cf8e22005-09-06 15:16:44 -0700402static void dummy_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
404}
405
Alan Coxf2cf8e22005-09-06 15:16:44 -0700406static void dummy_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
408}
409
Alan Coxf2cf8e22005-09-06 15:16:44 -0700410static void dummy_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
412}
413
Alan Coxf2cf8e22005-09-06 15:16:44 -0700414static void dummy_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416}
417
Alan Coxf2cf8e22005-09-06 15:16:44 -0700418static void dummy_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420}
421
422/* ----------------- Begin verifyChannel function ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700423static struct channel *verifyChannel(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{ /* Begin verifyChannel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 /* --------------------------------------------------------------------
426 This routine basically provides a sanity check. It insures that
427 the channel returned is within the proper range of addresses as
428 well as properly initialized. If some bogus info gets passed in
429 through tty->driver_data this should catch it.
Alan Coxf2cf8e22005-09-06 15:16:44 -0700430 --------------------------------------------------------------------- */
431 if (tty) {
432 struct channel *ch = (struct channel *)tty->driver_data;
433 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 if (ch->magic == EPCA_MAGIC)
435 return ch;
436 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 return NULL;
439
440} /* End verifyChannel */
441
442/* ------------------ Begin pc_sched_event ------------------------- */
443
Alan Coxf2cf8e22005-09-06 15:16:44 -0700444static void pc_sched_event(struct channel *ch, int event)
445{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /* ----------------------------------------------------------------------
447 We call this to schedule interrupt processing on some event. The
448 kernel sees our request and calls the related routine in OUR driver.
449 -------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 ch->event |= 1 << event;
451 schedule_work(&ch->tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452} /* End pc_sched_event */
453
454/* ------------------ Begin epca_error ------------------------- */
455
456static void epca_error(int line, char *msg)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700457{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700459}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461/* ------------------ Begin pc_close ------------------------- */
462static void pc_close(struct tty_struct * tty, struct file * filp)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700463{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 struct channel *ch;
465 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 /* ---------------------------------------------------------
467 verifyChannel returns the channel from the tty struct
468 if it is valid. This serves as a sanity check.
469 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700470 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
471 spin_lock_irqsave(&epca_lock, flags);
472 if (tty_hung_up_p(filp)) {
473 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return;
475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 /* Check to see if the channel is open more than once */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700477 if (ch->count-- > 1) {
478 /* Begin channel is open more than once */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 /* -------------------------------------------------------------
480 Return without doing anything. Someone might still be using
481 the channel.
482 ---------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700483 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 return;
485 } /* End channel is open more than once */
486
487 /* Port open only once go ahead with shutdown & reset */
Eric Sesterhenn56ee4822006-03-26 18:17:21 +0200488 BUG_ON(ch->count < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 /* ---------------------------------------------------------------
491 Let the rest of the driver know the channel is being closed.
492 This becomes important if an open is attempted before close
493 is finished.
494 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 ch->asyncflags |= ASYNC_CLOSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 tty->closing = 1;
497
Alan Coxf2cf8e22005-09-06 15:16:44 -0700498 spin_unlock_irqrestore(&epca_lock, flags);
499
500 if (ch->asyncflags & ASYNC_INITIALIZED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /* Setup an event to indicate when the transmit buffer empties */
502 setup_empty_event(tty, ch);
503 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (tty->driver->flush_buffer)
506 tty->driver->flush_buffer(tty);
507
508 tty_ldisc_flush(tty);
509 shutdown(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700510
511 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 tty->closing = 0;
513 ch->event = 0;
514 ch->tty = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700515 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Alan Coxf2cf8e22005-09-06 15:16:44 -0700517 if (ch->blocked_open) { /* Begin if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (ch->close_delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 } /* End if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
523 ASYNC_CLOSING);
524 wake_up_interruptible(&ch->close_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 } /* End if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526} /* End pc_close */
527
528/* ------------------ Begin shutdown ------------------------- */
529
530static void shutdown(struct channel *ch)
531{ /* Begin shutdown */
532
533 unsigned long flags;
534 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +0100535 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 if (!(ch->asyncflags & ASYNC_INITIALIZED))
538 return;
539
Alan Coxf2cf8e22005-09-06 15:16:44 -0700540 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Alan Coxf2cf8e22005-09-06 15:16:44 -0700542 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 bc = ch->brdchan;
544
545 /* ------------------------------------------------------------------
546 In order for an event to be generated on the receipt of data the
547 idata flag must be set. Since we are shutting down, this is not
548 necessary clear this flag.
549 --------------------------------------------------------------------- */
550
551 if (bc)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700552 writeb(0, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 tty = ch->tty;
554
555 /* ----------------------------------------------------------------
556 If we're a modem control device and HUPCL is on, drop RTS & DTR.
557 ------------------------------------------------------------------ */
558
Alan Coxf2cf8e22005-09-06 15:16:44 -0700559 if (tty->termios->c_cflag & HUPCL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
561 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 memoff(ch);
564
565 /* ------------------------------------------------------------------
566 The channel has officialy been closed. The next time it is opened
567 it will have to reinitialized. Set a flag to indicate this.
568 ---------------------------------------------------------------------- */
569
570 /* Prevent future Digi programmed interrupts from coming active */
571
572 ch->asyncflags &= ~ASYNC_INITIALIZED;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700573 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
575} /* End shutdown */
576
577/* ------------------ Begin pc_hangup ------------------------- */
578
579static void pc_hangup(struct tty_struct *tty)
580{ /* Begin pc_hangup */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 struct channel *ch;
582
583 /* ---------------------------------------------------------
584 verifyChannel returns the channel from the tty struct
585 if it is valid. This serves as a sanity check.
586 ------------------------------------------------------------- */
587
Alan Coxf2cf8e22005-09-06 15:16:44 -0700588 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 unsigned long flags;
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 if (tty->driver->flush_buffer)
592 tty->driver->flush_buffer(tty);
593 tty_ldisc_flush(tty);
594 shutdown(ch);
595
Alan Coxf2cf8e22005-09-06 15:16:44 -0700596 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 ch->tty = NULL;
598 ch->event = 0;
599 ch->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700601 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 } /* End if ch != NULL */
604
605} /* End pc_hangup */
606
607/* ------------------ Begin pc_write ------------------------- */
608
609static int pc_write(struct tty_struct * tty,
610 const unsigned char *buf, int bytesAvailable)
611{ /* Begin pc_write */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700612 unsigned int head, tail;
613 int dataLen;
614 int size;
615 int amountCopied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 struct channel *ch;
617 unsigned long flags;
618 int remain;
Al Virobc9a5152005-09-15 22:53:28 +0100619 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 /* ----------------------------------------------------------------
622 pc_write is primarily called directly by the kernel routine
623 tty_write (Though it can also be called by put_char) found in
624 tty_io.c. pc_write is passed a line discipline buffer where
625 the data to be written out is stored. The line discipline
626 implementation itself is done at the kernel level and is not
627 brought into the driver.
628 ------------------------------------------------------------------- */
629
630 /* ---------------------------------------------------------
631 verifyChannel returns the channel from the tty struct
632 if it is valid. This serves as a sanity check.
633 ------------------------------------------------------------- */
634
635 if ((ch = verifyChannel(tty)) == NULL)
636 return 0;
637
638 /* Make a pointer to the channel data structure found on the board. */
639
640 bc = ch->brdchan;
641 size = ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 amountCopied = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Alan Coxf2cf8e22005-09-06 15:16:44 -0700644 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 globalwinon(ch);
646
Alan Coxf2cf8e22005-09-06 15:16:44 -0700647 head = readw(&bc->tin) & (size - 1);
648 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Alan Coxf2cf8e22005-09-06 15:16:44 -0700650 if (tail != readw(&bc->tout))
651 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 tail &= (size - 1);
653
654 /* If head >= tail, head has not wrapped around. */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700655 if (head >= tail) { /* Begin head has not wrapped */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /* ---------------------------------------------------------------
657 remain (much like dataLen above) represents the total amount of
658 space available on the card for data. Here dataLen represents
659 the space existing between the head pointer and the end of
660 buffer. This is important because a memcpy cannot be told to
661 automatically wrap around when it hits the buffer end.
662 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 dataLen = size - head;
664 remain = size - (head - tail) - 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700665 } else { /* Begin head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
667 remain = tail - head - 1;
668 dataLen = remain;
669
670 } /* End head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 /* -------------------------------------------------------------------
672 Check the space on the card. If we have more data than
673 space; reduce the amount of data to fit the space.
674 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 bytesAvailable = min(remain, bytesAvailable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 txwinon(ch);
677 while (bytesAvailable > 0)
678 { /* Begin while there is data to copy onto card */
679
680 /* -----------------------------------------------------------------
681 If head is not wrapped, the below will make sure the first
682 data copy fills to the end of card buffer.
683 ------------------------------------------------------------------- */
684
685 dataLen = min(bytesAvailable, dataLen);
Al Virobc9a5152005-09-15 22:53:28 +0100686 memcpy_toio(ch->txptr + head, buf, dataLen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 buf += dataLen;
688 head += dataLen;
689 amountCopied += dataLen;
690 bytesAvailable -= dataLen;
691
Alan Coxf2cf8e22005-09-06 15:16:44 -0700692 if (head >= size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 head = 0;
694 dataLen = tail;
695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 } /* End while there is data to copy onto card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 ch->statusflags |= TXBUSY;
698 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700699 writew(head, &bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Alan Coxf2cf8e22005-09-06 15:16:44 -0700701 if ((ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700703 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 }
705 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700706 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 return(amountCopied);
708
709} /* End pc_write */
710
711/* ------------------ Begin pc_put_char ------------------------- */
712
713static void pc_put_char(struct tty_struct *tty, unsigned char c)
714{ /* Begin pc_put_char */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 pc_write(tty, &c, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716} /* End pc_put_char */
717
718/* ------------------ Begin pc_write_room ------------------------- */
719
720static int pc_write_room(struct tty_struct *tty)
721{ /* Begin pc_write_room */
722
723 int remain;
724 struct channel *ch;
725 unsigned long flags;
726 unsigned int head, tail;
Al Virobc9a5152005-09-15 22:53:28 +0100727 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729 remain = 0;
730
731 /* ---------------------------------------------------------
732 verifyChannel returns the channel from the tty struct
733 if it is valid. This serves as a sanity check.
734 ------------------------------------------------------------- */
735
Alan Coxf2cf8e22005-09-06 15:16:44 -0700736 if ((ch = verifyChannel(tty)) != NULL) {
737 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 globalwinon(ch);
739
740 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700741 head = readw(&bc->tin) & (ch->txbufsize - 1);
742 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Alan Coxf2cf8e22005-09-06 15:16:44 -0700744 if (tail != readw(&bc->tout))
745 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 /* Wrap tail if necessary */
747 tail &= (ch->txbufsize - 1);
748
749 if ((remain = tail - head - 1) < 0 )
750 remain += ch->txbufsize;
751
Alan Coxf2cf8e22005-09-06 15:16:44 -0700752 if (remain && (ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700754 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700757 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 /* Return how much room is left on card */
760 return remain;
761
762} /* End pc_write_room */
763
764/* ------------------ Begin pc_chars_in_buffer ---------------------- */
765
766static int pc_chars_in_buffer(struct tty_struct *tty)
767{ /* Begin pc_chars_in_buffer */
768
769 int chars;
770 unsigned int ctail, head, tail;
771 int remain;
772 unsigned long flags;
773 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100774 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 /* ---------------------------------------------------------
777 verifyChannel returns the channel from the tty struct
778 if it is valid. This serves as a sanity check.
779 ------------------------------------------------------------- */
780
781 if ((ch = verifyChannel(tty)) == NULL)
782 return(0);
783
Alan Coxf2cf8e22005-09-06 15:16:44 -0700784 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 globalwinon(ch);
786
787 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700788 tail = readw(&bc->tout);
789 head = readw(&bc->tin);
790 ctail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Alan Coxf2cf8e22005-09-06 15:16:44 -0700792 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 chars = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700794 else { /* Begin if some space on the card has been used */
795 head = readw(&bc->tin) & (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 tail &= (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 /* --------------------------------------------------------------
798 The logic here is basically opposite of the above pc_write_room
799 here we are finding the amount of bytes in the buffer filled.
800 Not the amount of bytes empty.
801 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 if ((remain = tail - head - 1) < 0 )
803 remain += ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 chars = (int)(ch->txbufsize - remain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 /* -------------------------------------------------------------
806 Make it possible to wakeup anything waiting for output
807 in tty_ioctl.c, etc.
808
809 If not already set. Setup an event to indicate when the
810 transmit buffer empties
811 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 if (!(ch->statusflags & EMPTYWAIT))
813 setup_empty_event(tty,ch);
814
815 } /* End if some space on the card has been used */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700817 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 /* Return number of characters residing on card. */
819 return(chars);
820
821} /* End pc_chars_in_buffer */
822
823/* ------------------ Begin pc_flush_buffer ---------------------- */
824
825static void pc_flush_buffer(struct tty_struct *tty)
826{ /* Begin pc_flush_buffer */
827
828 unsigned int tail;
829 unsigned long flags;
830 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100831 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 /* ---------------------------------------------------------
833 verifyChannel returns the channel from the tty struct
834 if it is valid. This serves as a sanity check.
835 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 if ((ch = verifyChannel(tty)) == NULL)
837 return;
838
Alan Coxf2cf8e22005-09-06 15:16:44 -0700839 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700842 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 /* Have FEP move tout pointer; effectively flushing transmit buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700846 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848} /* End pc_flush_buffer */
849
850/* ------------------ Begin pc_flush_chars ---------------------- */
851
852static void pc_flush_chars(struct tty_struct *tty)
853{ /* Begin pc_flush_chars */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 struct channel * ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 /* ---------------------------------------------------------
856 verifyChannel returns the channel from the tty struct
857 if it is valid. This serves as a sanity check.
858 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700859 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700861 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 /* ----------------------------------------------------------------
863 If not already set and the transmitter is busy setup an event
864 to indicate when the transmit empties.
865 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
867 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700868 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870} /* End pc_flush_chars */
871
872/* ------------------ Begin block_til_ready ---------------------- */
873
874static int block_til_ready(struct tty_struct *tty,
875 struct file *filp, struct channel *ch)
876{ /* Begin block_til_ready */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 DECLARE_WAITQUEUE(wait,current);
878 int retval, do_clocal = 0;
879 unsigned long flags;
880
Alan Coxf2cf8e22005-09-06 15:16:44 -0700881 if (tty_hung_up_p(filp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
883 retval = -EAGAIN;
884 else
885 retval = -ERESTARTSYS;
886 return(retval);
887 }
888
889 /* -----------------------------------------------------------------
890 If the device is in the middle of being closed, then block
891 until it's done, and then try again.
892 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700893 if (ch->asyncflags & ASYNC_CLOSING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 interruptible_sleep_on(&ch->close_wait);
895
896 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
897 return -EAGAIN;
898 else
899 return -ERESTARTSYS;
900 }
901
Alan Coxf2cf8e22005-09-06 15:16:44 -0700902 if (filp->f_flags & O_NONBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 /* -----------------------------------------------------------------
904 If non-blocking mode is set, then make the check up front
905 and then exit.
906 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 return 0;
909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if (tty->termios->c_cflag & CLOCAL)
911 do_clocal = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700912 /* Block waiting for the carrier detect and the line to become free */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 retval = 0;
915 add_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Alan Coxf2cf8e22005-09-06 15:16:44 -0700917 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 /* We dec count so that pc_close will know when to free things */
919 if (!tty_hung_up_p(filp))
920 ch->count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 ch->blocked_open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 while(1)
923 { /* Begin forever while */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 if (tty_hung_up_p(filp) ||
926 !(ch->asyncflags & ASYNC_INITIALIZED))
927 {
928 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
929 retval = -EAGAIN;
930 else
931 retval = -ERESTARTSYS;
932 break;
933 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 if (!(ch->asyncflags & ASYNC_CLOSING) &&
935 (do_clocal || (ch->imodem & ch->dcd)))
936 break;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700937 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 retval = -ERESTARTSYS;
939 break;
940 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700941 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 /* ---------------------------------------------------------------
943 Allow someone else to be scheduled. We will occasionally go
944 through this loop until one of the above conditions change.
945 The below schedule call will allow other processes to enter and
946 prevent this loop from hogging the cpu.
947 ------------------------------------------------------------------ */
948 schedule();
Alan Coxf2cf8e22005-09-06 15:16:44 -0700949 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 } /* End forever while */
952
953 current->state = TASK_RUNNING;
954 remove_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 if (!tty_hung_up_p(filp))
956 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 ch->blocked_open--;
958
Alan Coxf2cf8e22005-09-06 15:16:44 -0700959 spin_unlock_irqrestore(&epca_lock, flags);
960
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (retval)
962 return retval;
963
964 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966} /* End block_til_ready */
967
968/* ------------------ Begin pc_open ---------------------- */
969
970static int pc_open(struct tty_struct *tty, struct file * filp)
971{ /* Begin pc_open */
972
973 struct channel *ch;
974 unsigned long flags;
975 int line, retval, boardnum;
Al Virobc9a5152005-09-15 22:53:28 +0100976 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700977 unsigned int head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 line = tty->index;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700980 if (line < 0 || line >= nbdevs)
981 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 ch = &digi_channels[line];
984 boardnum = ch->boardnum;
985
986 /* Check status of board configured in system. */
987
988 /* -----------------------------------------------------------------
989 I check to see if the epca_setup routine detected an user error.
990 It might be better to put this in pc_init, but for the moment it
991 goes here.
992 ---------------------------------------------------------------------- */
993
Alan Coxf2cf8e22005-09-06 15:16:44 -0700994 if (invalid_lilo_config) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (setup_error_code & INVALID_BOARD_TYPE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700996 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 if (setup_error_code & INVALID_NUM_PORTS)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700998 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (setup_error_code & INVALID_MEM_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001000 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 if (setup_error_code & INVALID_PORT_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001002 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (setup_error_code & INVALID_BOARD_STATUS)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001004 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (setup_error_code & INVALID_ALTPIN)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001006 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 tty->driver_data = NULL; /* Mark this device as 'down' */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001008 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001010 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 tty->driver_data = NULL; /* Mark this device as 'down' */
1012 return(-ENODEV);
1013 }
1014
Alan Coxf2cf8e22005-09-06 15:16:44 -07001015 if ((bc = ch->brdchan) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 tty->driver_data = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001017 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019
Alan Coxf2cf8e22005-09-06 15:16:44 -07001020 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 /* ------------------------------------------------------------------
1022 Every time a channel is opened, increment a counter. This is
1023 necessary because we do not wish to flush and shutdown the channel
1024 until the last app holding the channel open, closes it.
1025 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 /* ----------------------------------------------------------------
1028 Set a kernel structures pointer to our local channel
1029 structure. This way we can get to it when passed only
1030 a tty struct.
1031 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 tty->driver_data = ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 /* ----------------------------------------------------------------
1034 If this is the first time the channel has been opened, initialize
1035 the tty->termios struct otherwise let pc_close handle it.
1036 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 globalwinon(ch);
1038 ch->statusflags = 0;
1039
1040 /* Save boards current modem status */
Al Virobc9a5152005-09-15 22:53:28 +01001041 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 /* ----------------------------------------------------------------
1044 Set receive head and tail ptrs to each other. This indicates
1045 no data available to read.
1046 ----------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001047 head = readw(&bc->rin);
1048 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 /* Set the channels associated tty structure */
1051 ch->tty = tty;
1052
1053 /* -----------------------------------------------------------------
1054 The below routine generally sets up parity, baud, flow control
1055 issues, etc.... It effect both control flags and input flags.
1056 -------------------------------------------------------------------- */
1057 epcaparam(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 ch->asyncflags |= ASYNC_INITIALIZED;
1059 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001060 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 retval = block_til_ready(tty, filp, ch);
1063 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 /* -------------------------------------------------------------
1066 Set this again in case a hangup set it to zero while this
1067 open() was waiting for the line...
1068 --------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001069 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 ch->tty = tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 /* Enable Digi Data events */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001073 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001075 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077} /* End pc_open */
1078
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079static int __init epca_module_init(void)
1080{ /* Begin init_module */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001081 return pc_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
1084module_init(epca_module_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086static struct pci_driver epca_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
1088static void __exit epca_module_exit(void)
1089{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 int count, crd;
1091 struct board_info *bd;
1092 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 del_timer_sync(&epca_timer);
1095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 if ((tty_unregister_driver(pc_driver)) ||
1097 (tty_unregister_driver(pc_info)))
1098 {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001099 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 return;
1101 }
1102 put_tty_driver(pc_driver);
1103 put_tty_driver(pc_info);
1104
Alan Coxf2cf8e22005-09-06 15:16:44 -07001105 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 bd = &boards[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (!bd)
1108 { /* Begin sanity check */
1109 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1110 return;
1111 } /* End sanity check */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001112 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 for (count = 0; count < bd->numports; count++, ch++)
1114 { /* Begin for each port */
Jiri Slabyb3218a72006-10-04 02:15:27 -07001115 if (ch && ch->tty)
1116 tty_hangup(ch->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 } /* End for each port */
1118 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 pci_unregister_driver (&epca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
Alan Coxf2cf8e22005-09-06 15:16:44 -07001121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122module_exit(epca_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001124static const struct tty_operations pc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .open = pc_open,
1126 .close = pc_close,
1127 .write = pc_write,
1128 .write_room = pc_write_room,
1129 .flush_buffer = pc_flush_buffer,
1130 .chars_in_buffer = pc_chars_in_buffer,
1131 .flush_chars = pc_flush_chars,
1132 .put_char = pc_put_char,
1133 .ioctl = pc_ioctl,
1134 .set_termios = pc_set_termios,
1135 .stop = pc_stop,
1136 .start = pc_start,
1137 .throttle = pc_throttle,
1138 .unthrottle = pc_unthrottle,
1139 .hangup = pc_hangup,
1140};
1141
1142static int info_open(struct tty_struct *tty, struct file * filp)
1143{
1144 return 0;
1145}
1146
1147static struct tty_operations info_ops = {
1148 .open = info_open,
1149 .ioctl = info_ioctl,
1150};
1151
1152/* ------------------ Begin pc_init ---------------------- */
1153
Alan Coxf2cf8e22005-09-06 15:16:44 -07001154static int __init pc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{ /* Begin pc_init */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 int crd;
1157 struct board_info *bd;
1158 unsigned char board_id = 0;
Akinobu Mitadabad052006-10-17 00:10:28 -07001159 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 int pci_boards_found, pci_count;
1162
1163 pci_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 pc_driver = alloc_tty_driver(MAX_ALLOC);
1166 if (!pc_driver)
Akinobu Mitadabad052006-10-17 00:10:28 -07001167 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 pc_info = alloc_tty_driver(MAX_ALLOC);
Akinobu Mitadabad052006-10-17 00:10:28 -07001170 if (!pc_info)
1171 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173 /* -----------------------------------------------------------------------
1174 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1175 board structure defined by digiConfig into drivers board structure.
1176 Note : If LILO has ran epca_setup then epca_setup will handle defining
1177 num_cards as well as copying the data into the board structure.
1178 -------------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001179 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 nbdevs = NBDEVS;
1182 num_cards = NUMCARDS;
1183 memcpy((void *)&boards, (void *)&static_boards,
1184 (sizeof(struct board_info) * NUMCARDS));
1185 } /* End driver has been configured via. epcaconfig */
1186
1187 /* -----------------------------------------------------------------
1188 Note : If lilo was used to configure the driver and the
1189 ignore epcaconfig option was choosen (digiepca=2) then
1190 nbdevs and num_cards will equal 0 at this point. This is
1191 okay; PCI cards will still be picked up if detected.
1192 --------------------------------------------------------------------- */
1193
1194 /* -----------------------------------------------------------
1195 Set up interrupt, we will worry about memory allocation in
1196 post_fep_init.
1197 --------------------------------------------------------------- */
1198
1199
1200 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 /* ------------------------------------------------------------------
1203 NOTE : This code assumes that the number of ports found in
1204 the boards array is correct. This could be wrong if
1205 the card in question is PCI (And therefore has no ports
1206 entry in the boards structure.) The rest of the
1207 information will be valid for PCI because the beginning
1208 of pc_init scans for PCI and determines i/o and base
1209 memory addresses. I am not sure if it is possible to
1210 read the number of ports supported by the card prior to
1211 it being booted (Since that is the state it is in when
1212 pc_init is run). Because it is not possible to query the
1213 number of supported ports until after the card has booted;
1214 we are required to calculate the card_ptrs as the card is
1215 is initialized (Inside post_fep_init). The negative thing
1216 about this approach is that digiDload's call to GET_INFO
1217 will have a bad port value. (Since this is called prior
1218 to post_fep_init.)
1219
1220 --------------------------------------------------------------------- */
1221
1222 pci_boards_found = 0;
1223 if(num_cards < MAXBOARDS)
1224 pci_boards_found += init_PCI();
1225 num_cards += pci_boards_found;
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 pc_driver->owner = THIS_MODULE;
1228 pc_driver->name = "ttyD";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 pc_driver->major = DIGI_MAJOR;
1230 pc_driver->minor_start = 0;
1231 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1232 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1233 pc_driver->init_termios = tty_std_termios;
1234 pc_driver->init_termios.c_iflag = 0;
1235 pc_driver->init_termios.c_oflag = 0;
1236 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1237 pc_driver->init_termios.c_lflag = 0;
Alan Cox606d0992006-12-08 02:38:45 -08001238 pc_driver->init_termios.c_ispeed = 9600;
1239 pc_driver->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1241 tty_set_operations(pc_driver, &pc_ops);
1242
1243 pc_info->owner = THIS_MODULE;
1244 pc_info->name = "digi_ctl";
1245 pc_info->major = DIGIINFOMAJOR;
1246 pc_info->minor_start = 0;
1247 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1248 pc_info->subtype = SERIAL_TYPE_INFO;
1249 pc_info->init_termios = tty_std_termios;
1250 pc_info->init_termios.c_iflag = 0;
1251 pc_info->init_termios.c_oflag = 0;
1252 pc_info->init_termios.c_lflag = 0;
1253 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
Alan Cox606d0992006-12-08 02:38:45 -08001254 pc_info->init_termios.c_ispeed = 9600;
1255 pc_info->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 pc_info->flags = TTY_DRIVER_REAL_RAW;
1257 tty_set_operations(pc_info, &info_ops);
1258
1259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 for (crd = 0; crd < num_cards; crd++)
1261 { /* Begin for each card */
1262
1263 /* ------------------------------------------------------------------
1264 This is where the appropriate memory handlers for the hardware is
1265 set. Everything at runtime blindly jumps through these vectors.
1266 ---------------------------------------------------------------------- */
1267
1268 /* defined in epcaconfig.h */
1269 bd = &boards[crd];
1270
1271 switch (bd->type)
1272 { /* Begin switch on bd->type {board type} */
1273 case PCXEM:
1274 case EISAXEM:
1275 bd->memwinon = pcxem_memwinon ;
1276 bd->memwinoff = pcxem_memwinoff ;
1277 bd->globalwinon = pcxem_globalwinon ;
1278 bd->txwinon = pcxem_txwinon ;
1279 bd->rxwinon = pcxem_rxwinon ;
1280 bd->memoff = pcxem_memoff ;
1281 bd->assertgwinon = dummy_assertgwinon;
1282 bd->assertmemoff = dummy_assertmemoff;
1283 break;
1284
1285 case PCIXEM:
1286 case PCIXRJ:
1287 case PCIXR:
1288 bd->memwinon = dummy_memwinon;
1289 bd->memwinoff = dummy_memwinoff;
1290 bd->globalwinon = dummy_globalwinon;
1291 bd->txwinon = dummy_txwinon;
1292 bd->rxwinon = dummy_rxwinon;
1293 bd->memoff = dummy_memoff;
1294 bd->assertgwinon = dummy_assertgwinon;
1295 bd->assertmemoff = dummy_assertmemoff;
1296 break;
1297
1298 case PCXE:
1299 case PCXEVE:
1300
1301 bd->memwinon = pcxe_memwinon;
1302 bd->memwinoff = pcxe_memwinoff;
1303 bd->globalwinon = pcxe_globalwinon;
1304 bd->txwinon = pcxe_txwinon;
1305 bd->rxwinon = pcxe_rxwinon;
1306 bd->memoff = pcxe_memoff;
1307 bd->assertgwinon = dummy_assertgwinon;
1308 bd->assertmemoff = dummy_assertmemoff;
1309 break;
1310
1311 case PCXI:
1312 case PC64XE:
1313
1314 bd->memwinon = pcxi_memwinon;
1315 bd->memwinoff = pcxi_memwinoff;
1316 bd->globalwinon = pcxi_globalwinon;
1317 bd->txwinon = pcxi_txwinon;
1318 bd->rxwinon = pcxi_rxwinon;
1319 bd->memoff = pcxi_memoff;
1320 bd->assertgwinon = pcxi_assertgwinon;
1321 bd->assertmemoff = pcxi_assertmemoff;
1322 break;
1323
1324 default:
1325 break;
1326
1327 } /* End switch on bd->type */
1328
1329 /* ---------------------------------------------------------------
1330 Some cards need a memory segment to be defined for use in
1331 transmit and receive windowing operations. These boards
1332 are listed in the below switch. In the case of the XI the
1333 amount of memory on the board is variable so the memory_seg
1334 is also variable. This code determines what they segment
1335 should be.
1336 ----------------------------------------------------------------- */
1337
1338 switch (bd->type)
1339 { /* Begin switch on bd->type {board type} */
1340
1341 case PCXE:
1342 case PCXEVE:
1343 case PC64XE:
1344 bd->memory_seg = 0xf000;
1345 break;
1346
1347 case PCXI:
1348 board_id = inb((int)bd->port);
1349 if ((board_id & 0x1) == 0x1)
1350 { /* Begin it's an XI card */
1351
1352 /* Is it a 64K board */
1353 if ((board_id & 0x30) == 0)
1354 bd->memory_seg = 0xf000;
1355
1356 /* Is it a 128K board */
1357 if ((board_id & 0x30) == 0x10)
1358 bd->memory_seg = 0xe000;
1359
1360 /* Is is a 256K board */
1361 if ((board_id & 0x30) == 0x20)
1362 bd->memory_seg = 0xc000;
1363
1364 /* Is it a 512K board */
1365 if ((board_id & 0x30) == 0x30)
1366 bd->memory_seg = 0x8000;
1367
Alan Coxf2cf8e22005-09-06 15:16:44 -07001368 } else printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 break;
1370
1371 } /* End switch on bd->type */
1372
1373 } /* End for each card */
1374
Akinobu Mitadabad052006-10-17 00:10:28 -07001375 err = tty_register_driver(pc_driver);
1376 if (err) {
1377 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1378 goto out3;
1379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Akinobu Mitadabad052006-10-17 00:10:28 -07001381 err = tty_register_driver(pc_info);
1382 if (err) {
1383 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1384 goto out4;
1385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 /* -------------------------------------------------------------------
1388 Start up the poller to check for events on all enabled boards
1389 ---------------------------------------------------------------------- */
1390
1391 init_timer(&epca_timer);
1392 epca_timer.function = epcapoll;
1393 mod_timer(&epca_timer, jiffies + HZ/25);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 return 0;
1395
Akinobu Mitadabad052006-10-17 00:10:28 -07001396out4:
1397 tty_unregister_driver(pc_driver);
1398out3:
1399 put_tty_driver(pc_info);
1400out2:
1401 put_tty_driver(pc_driver);
1402out1:
1403 return err;
1404
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405} /* End pc_init */
1406
1407/* ------------------ Begin post_fep_init ---------------------- */
1408
1409static void post_fep_init(unsigned int crd)
1410{ /* Begin post_fep_init */
1411
1412 int i;
Al Virobc9a5152005-09-15 22:53:28 +01001413 void __iomem *memaddr;
1414 struct global_data __iomem *gd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001416 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 struct channel *ch;
1418 int shrinkmem = 0, lowwater ;
1419
1420 /* -------------------------------------------------------------
1421 This call is made by the user via. the ioctl call DIGI_INIT.
1422 It is responsible for setting up all the card specific stuff.
1423 ---------------------------------------------------------------- */
1424 bd = &boards[crd];
1425
1426 /* -----------------------------------------------------------------
1427 If this is a PCI board, get the port info. Remember PCI cards
1428 do not have entries into the epcaconfig.h file, so we can't get
1429 the number of ports from it. Unfortunetly, this means that anyone
1430 doing a DIGI_GETINFO before the board has booted will get an invalid
1431 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1432 after DIGI_INIT has been called will return the proper values.
1433 ------------------------------------------------------------------- */
1434
Alan Coxf2cf8e22005-09-06 15:16:44 -07001435 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 /* --------------------------------------------------------------------
1437 Below we use XEMPORTS as a memory offset regardless of which PCI
1438 card it is. This is because all of the supported PCI cards have
1439 the same memory offset for the channel data. This will have to be
1440 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1441 states that the port offset is 0xC22 as opposed to 0xC02. This is
1442 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1443 On the PCI cards the number of ports is determined by reading a
1444 ID PROM located in the box attached to the card. The card can then
1445 determine the index the id to determine the number of ports available.
1446 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1447 if the box in question is a XEM or CX)).
1448 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001449 /* PCI cards are already remapped at this point ISA are not */
1450 bd->numports = readw(bd->re_map_membase + XEMPORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1452 nbdevs += (bd->numports);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001453 } else {
1454 /* Fix up the mappings for ISA/EISA etc */
1455 /* FIXME: 64K - can we be smarter ? */
1456 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
1459 if (crd != 0)
1460 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1461 else
1462 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1463
1464 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1466
Alan Coxf2cf8e22005-09-06 15:16:44 -07001467 memaddr = bd->re_map_membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
1469 /* -----------------------------------------------------------------
1470 The below assignment will set bc to point at the BEGINING of
1471 the cards channel structures. For 1 card there will be between
1472 8 and 64 of these structures.
1473 -------------------------------------------------------------------- */
1474
Al Virobc9a5152005-09-15 22:53:28 +01001475 bc = memaddr + CHANSTRUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 /* -------------------------------------------------------------------
1478 The below assignment will set gd to point at the BEGINING of
1479 global memory address 0xc00. The first data in that global
1480 memory actually starts at address 0xc1a. The command in
1481 pointer begins at 0xd10.
1482 ---------------------------------------------------------------------- */
1483
Al Virobc9a5152005-09-15 22:53:28 +01001484 gd = memaddr + GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 /* --------------------------------------------------------------------
1487 XEPORTS (address 0xc22) points at the number of channels the
1488 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1489 ----------------------------------------------------------------------- */
1490
Alan Coxf2cf8e22005-09-06 15:16:44 -07001491 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 shrinkmem = 1;
1493 if (bd->type < PCIXEM)
1494 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1495 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 memwinon(bd, 0);
1497
1498 /* --------------------------------------------------------------------
1499 Remember ch is the main drivers channels structure, while bc is
1500 the cards channel structure.
1501 ------------------------------------------------------------------------ */
1502
1503 /* For every port on the card do ..... */
1504
Alan Coxf2cf8e22005-09-06 15:16:44 -07001505 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1506 unsigned long flags;
Al Virobc9a5152005-09-15 22:53:28 +01001507 u16 tseg, rseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 ch->brdchan = bc;
1510 ch->mailbox = gd;
David Howellsc4028952006-11-22 14:57:56 +00001511 INIT_WORK(&ch->tqueue, do_softint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 ch->board = &boards[crd];
1513
Alan Coxf2cf8e22005-09-06 15:16:44 -07001514 spin_lock_irqsave(&epca_lock, flags);
1515 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 /* ----------------------------------------------------------------
1517 Since some of the boards use different bitmaps for their
1518 control signals we cannot hard code these values and retain
1519 portability. We virtualize this data here.
1520 ------------------------------------------------------------------- */
1521 case EISAXEM:
1522 case PCXEM:
1523 case PCIXEM:
1524 case PCIXRJ:
1525 case PCIXR:
1526 ch->m_rts = 0x02 ;
1527 ch->m_dcd = 0x80 ;
1528 ch->m_dsr = 0x20 ;
1529 ch->m_cts = 0x10 ;
1530 ch->m_ri = 0x40 ;
1531 ch->m_dtr = 0x01 ;
1532 break;
1533
1534 case PCXE:
1535 case PCXEVE:
1536 case PCXI:
1537 case PC64XE:
1538 ch->m_rts = 0x02 ;
1539 ch->m_dcd = 0x08 ;
1540 ch->m_dsr = 0x10 ;
1541 ch->m_cts = 0x20 ;
1542 ch->m_ri = 0x40 ;
1543 ch->m_dtr = 0x80 ;
1544 break;
1545
1546 } /* End switch bd->type */
1547
Alan Coxf2cf8e22005-09-06 15:16:44 -07001548 if (boards[crd].altpin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 ch->dsr = ch->m_dcd;
1550 ch->dcd = ch->m_dsr;
1551 ch->digiext.digi_flags |= DIGI_ALTPIN;
1552 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001553 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 ch->dcd = ch->m_dcd;
1555 ch->dsr = ch->m_dsr;
1556 }
1557
1558 ch->boardnum = crd;
1559 ch->channelnum = i;
1560 ch->magic = EPCA_MAGIC;
1561 ch->tty = NULL;
1562
Alan Coxf2cf8e22005-09-06 15:16:44 -07001563 if (shrinkmem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1565 shrinkmem = 0;
1566 }
1567
Al Virobc9a5152005-09-15 22:53:28 +01001568 tseg = readw(&bc->tseg);
1569 rseg = readw(&bc->rseg);
1570
Alan Coxf2cf8e22005-09-06 15:16:44 -07001571 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 case PCIXEM:
1574 case PCIXRJ:
1575 case PCIXR:
1576 /* Cover all the 2MEG cards */
Al Virobc9a5152005-09-15 22:53:28 +01001577 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1578 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1579 ch->txwin = FEPWIN | (tseg >> 11);
1580 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 break;
1582
1583 case PCXEM:
1584 case EISAXEM:
1585 /* Cover all the 32K windowed cards */
1586 /* Mask equal to window size - 1 */
Al Virobc9a5152005-09-15 22:53:28 +01001587 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1588 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1589 ch->txwin = FEPWIN | (tseg >> 11);
1590 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 break;
1592
1593 case PCXEVE:
1594 case PCXE:
Al Virobc9a5152005-09-15 22:53:28 +01001595 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1596 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1597 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1598 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 break;
1600
1601 case PCXI:
1602 case PC64XE:
Al Virobc9a5152005-09-15 22:53:28 +01001603 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1604 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 ch->txwin = ch->rxwin = 0;
1606 break;
1607
1608 } /* End switch bd->type */
1609
1610 ch->txbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001611 ch->txbufsize = readw(&bc->tmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
1613 ch->rxbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001614 ch->rxbufsize = readw(&bc->rmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
1616 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1617
1618 /* Set transmitter low water mark */
1619 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1620
1621 /* Set receiver low water mark */
1622
1623 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1624
1625 /* Set receiver high water mark */
1626
1627 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1628
Alan Coxf2cf8e22005-09-06 15:16:44 -07001629 writew(100, &bc->edelay);
1630 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Alan Coxf2cf8e22005-09-06 15:16:44 -07001632 ch->startc = readb(&bc->startc);
1633 ch->stopc = readb(&bc->stopc);
1634 ch->startca = readb(&bc->startca);
1635 ch->stopca = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 ch->fepcflag = 0;
1638 ch->fepiflag = 0;
1639 ch->fepoflag = 0;
1640 ch->fepstartc = 0;
1641 ch->fepstopc = 0;
1642 ch->fepstartca = 0;
1643 ch->fepstopca = 0;
1644
1645 ch->close_delay = 50;
1646 ch->count = 0;
1647 ch->blocked_open = 0;
1648 init_waitqueue_head(&ch->open_wait);
1649 init_waitqueue_head(&ch->close_wait);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001650
1651 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 } /* End for each port */
1653
1654 printk(KERN_INFO
1655 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1656 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 memwinoff(bd, 0);
1658
1659} /* End post_fep_init */
1660
1661/* --------------------- Begin epcapoll ------------------------ */
1662
1663static void epcapoll(unsigned long ignored)
1664{ /* Begin epcapoll */
1665
1666 unsigned long flags;
1667 int crd;
1668 volatile unsigned int head, tail;
1669 struct channel *ch;
1670 struct board_info *bd;
1671
1672 /* -------------------------------------------------------------------
1673 This routine is called upon every timer interrupt. Even though
1674 the Digi series cards are capable of generating interrupts this
1675 method of non-looping polling is more efficient. This routine
1676 checks for card generated events (Such as receive data, are transmit
1677 buffer empty) and acts on those events.
1678 ----------------------------------------------------------------------- */
1679
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 for (crd = 0; crd < num_cards; crd++)
1681 { /* Begin for each card */
1682
1683 bd = &boards[crd];
1684 ch = card_ptr[crd];
1685
1686 if ((bd->status == DISABLED) || digi_poller_inhibited)
1687 continue; /* Begin loop next interation */
1688
1689 /* -----------------------------------------------------------
1690 assertmemoff is not needed here; indeed it is an empty subroutine.
1691 It is being kept because future boards may need this as well as
1692 some legacy boards.
1693 ---------------------------------------------------------------- */
1694
Alan Coxf2cf8e22005-09-06 15:16:44 -07001695 spin_lock_irqsave(&epca_lock, flags);
1696
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 assertmemoff(ch);
1698
1699 globalwinon(ch);
1700
1701 /* ---------------------------------------------------------------
1702 In this case head and tail actually refer to the event queue not
1703 the transmit or receive queue.
1704 ------------------------------------------------------------------- */
1705
Alan Coxf2cf8e22005-09-06 15:16:44 -07001706 head = readw(&ch->mailbox->ein);
1707 tail = readw(&ch->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 /* If head isn't equal to tail we have an event */
1710
1711 if (head != tail)
1712 doevent(crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 memoff(ch);
1714
Alan Coxf2cf8e22005-09-06 15:16:44 -07001715 spin_unlock_irqrestore(&epca_lock, flags);
1716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 mod_timer(&epca_timer, jiffies + (HZ / 25));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719} /* End epcapoll */
1720
1721/* --------------------- Begin doevent ------------------------ */
1722
1723static void doevent(int crd)
1724{ /* Begin doevent */
1725
Al Virobc9a5152005-09-15 22:53:28 +01001726 void __iomem *eventbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 struct channel *ch, *chan0;
1728 static struct tty_struct *tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001729 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001730 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001731 unsigned int tail, head;
1732 int event, channel;
1733 int mstat, lstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 /* -------------------------------------------------------------------
1736 This subroutine is called by epcapoll when an event is detected
1737 in the event queue. This routine responds to those events.
1738 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 bd = &boards[crd];
1740
1741 chan0 = card_ptr[crd];
1742 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001744 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 { /* Begin while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001747 eventbuf = bd->re_map_membase + tail + ISTART;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 /* Get the channel the event occurred on */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001749 channel = readb(eventbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 /* Get the actual event code that occurred */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001751 event = readb(eventbuf + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 /* ----------------------------------------------------------------
1753 The two assignments below get the current modem status (mstat)
1754 and the previous modem status (lstat). These are useful becuase
1755 an event could signal a change in modem signals itself.
1756 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001757 mstat = readb(eventbuf + 2);
1758 lstat = readb(eventbuf + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
1760 ch = chan0 + channel;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001761 if ((unsigned)channel >= bd->numports || !ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 if (channel >= bd->numports)
1763 ch = chan0;
1764 bc = ch->brdchan;
1765 goto next;
1766 }
1767
1768 if ((bc = ch->brdchan) == NULL)
1769 goto next;
1770
Alan Coxf2cf8e22005-09-06 15:16:44 -07001771 if (event & DATA_IND) { /* Begin DATA_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 receive_data(ch);
1773 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 } /* End DATA_IND */
1775 /* else *//* Fix for DCD transition missed bug */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001776 if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 /* A modem signal change has been indicated */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 ch->imodem = mstat;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001779 if (ch->asyncflags & ASYNC_CHECK_CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 if (mstat & ch->dcd) /* We are now receiving dcd */
1781 wake_up_interruptible(&ch->open_wait);
1782 else
1783 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 } /* End MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 tty = ch->tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001787 if (tty) { /* Begin if valid tty */
1788 if (event & BREAK_IND) { /* Begin if BREAK_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 /* A break has been indicated */
Alan Cox33f0f882006-01-09 20:54:13 -08001790 tty_insert_flip_char(tty, 0, TTY_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 tty_schedule_flip(tty);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001792 } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 if (ch->statusflags & LOWWAIT)
1794 { /* Begin if LOWWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 ch->statusflags &= ~LOWWAIT;
1796 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 } /* End if LOWWAIT */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001798 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 /* This event is generated by setup_empty_event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ch->statusflags &= ~TXBUSY;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001801 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 ch->statusflags &= ~EMPTYWAIT;
1803 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 } /* End if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 } /* End EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 } /* End if valid tty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 next:
1808 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001809 BUG_ON(!bc);
1810 writew(1, &bc->idata);
1811 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 globalwinon(chan0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 } /* End while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814} /* End doevent */
1815
1816/* --------------------- Begin fepcmd ------------------------ */
1817
1818static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1819 int byte2, int ncmds, int bytecmd)
1820{ /* Begin fepcmd */
Al Virobc9a5152005-09-15 22:53:28 +01001821 unchar __iomem *memaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 unsigned int head, cmdTail, cmdStart, cmdMax;
1823 long count;
1824 int n;
1825
1826 /* This is the routine in which commands may be passed to the card. */
1827
1828 if (ch->board->status == DISABLED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 /* Remember head (As well as max) is just an offset not a base addr */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001832 head = readw(&ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 /* cmdStart is a base address */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001834 cmdStart = readw(&ch->mailbox->cstart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 /* ------------------------------------------------------------------
1836 We do the addition below because we do not want a max pointer
1837 relative to cmdStart. We want a max pointer that points at the
1838 physical end of the command queue.
1839 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001840 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 memaddr = ch->board->re_map_membase;
1842
Alan Coxf2cf8e22005-09-06 15:16:44 -07001843 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1844 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1845 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 return;
1847 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001848 if (bytecmd) {
1849 writeb(cmd, memaddr + head + cmdStart + 0);
1850 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 /* Below word_or_byte is bits to set */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001852 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 /* Below byte2 is bits to reset */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001854 writeb(byte2, memaddr + head + cmdStart + 3);
1855 } else {
1856 writeb(cmd, memaddr + head + cmdStart + 0);
1857 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1858 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 head = (head + 4) & (cmdMax - cmdStart - 4);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001861 writew(head, &ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 count = FEPTIMEOUT;
1863
Alan Coxf2cf8e22005-09-06 15:16:44 -07001864 for (;;) { /* Begin forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 count--;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001866 if (count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1868 return;
1869 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001870 head = readw(&ch->mailbox->cin);
1871 cmdTail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 /* ----------------------------------------------------------
1874 Basically this will break when the FEP acknowledges the
1875 command by incrementing cmdTail (Making it equal to head).
1876 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 if (n <= ncmds * (sizeof(short) * 4))
1878 break; /* Well nearly forever :-) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 } /* End forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880} /* End fepcmd */
1881
1882/* ---------------------------------------------------------------------
1883 Digi products use fields in their channels structures that are very
1884 similar to the c_cflag and c_iflag fields typically found in UNIX
1885 termios structures. The below three routines allow mappings
1886 between these hardware "flags" and their respective Linux flags.
1887------------------------------------------------------------------------- */
1888
1889/* --------------------- Begin termios2digi_h -------------------- */
1890
1891static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1892{ /* Begin termios2digi_h */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 unsigned res = 0;
1894
Alan Coxf2cf8e22005-09-06 15:16:44 -07001895 if (cflag & CRTSCTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1897 res |= ((ch->m_cts) | (ch->m_rts));
1898 }
1899
1900 if (ch->digiext.digi_flags & RTSPACE)
1901 res |= ch->m_rts;
1902
1903 if (ch->digiext.digi_flags & DTRPACE)
1904 res |= ch->m_dtr;
1905
1906 if (ch->digiext.digi_flags & CTSPACE)
1907 res |= ch->m_cts;
1908
1909 if (ch->digiext.digi_flags & DSRPACE)
1910 res |= ch->dsr;
1911
1912 if (ch->digiext.digi_flags & DCDPACE)
1913 res |= ch->dcd;
1914
1915 if (res & (ch->m_rts))
1916 ch->digiext.digi_flags |= RTSPACE;
1917
1918 if (res & (ch->m_cts))
1919 ch->digiext.digi_flags |= CTSPACE;
1920
1921 return res;
1922
1923} /* End termios2digi_h */
1924
1925/* --------------------- Begin termios2digi_i -------------------- */
1926static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1927{ /* Begin termios2digi_i */
1928
1929 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1930 INPCK | ISTRIP|IXON|IXANY|IXOFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 if (ch->digiext.digi_flags & DIGI_AIXON)
1932 res |= IAIXON;
1933 return res;
1934
1935} /* End termios2digi_i */
1936
1937/* --------------------- Begin termios2digi_c -------------------- */
1938
1939static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1940{ /* Begin termios2digi_c */
1941
1942 unsigned res = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001943 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 ch->digiext.digi_flags |= DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 /* -------------------------------------------------------------
1946 HUPCL bit is used by FEP to indicate fast baud
1947 table is to be used.
1948 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 res |= FEP_HUPCL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 } /* End detected CBAUDEX */
1951 else ch->digiext.digi_flags &= ~DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 /* -------------------------------------------------------------------
1953 CBAUD has bit position 0x1000 set these days to indicate Linux
1954 baud rate remap. Digi hardware can't handle the bit assignment.
1955 (We use a different bit assignment for high speed.). Clear this
1956 bit out.
1957 ---------------------------------------------------------------------- */
1958 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 /* -------------------------------------------------------------
1960 This gets a little confusing. The Digi cards have their own
1961 representation of c_cflags controling baud rate. For the most
1962 part this is identical to the Linux implementation. However;
1963 Digi supports one rate (76800) that Linux doesn't. This means
1964 that the c_cflag entry that would normally mean 76800 for Digi
1965 actually means 115200 under Linux. Without the below mapping,
1966 a stty 115200 would only drive the board at 76800. Since
1967 the rate 230400 is also found after 76800, the same problem afflicts
1968 us when we choose a rate of 230400. Without the below modificiation
1969 stty 230400 would actually give us 115200.
1970
1971 There are two additional differences. The Linux value for CLOCAL
1972 (0x800; 0004000) has no meaning to the Digi hardware. Also in
1973 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
1974 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
1975 should be checked for a screened out prior to termios2digi_c
1976 returning. Since CLOCAL isn't used by the board this can be
1977 ignored as long as the returned value is used only by Digi hardware.
Alan Coxf2cf8e22005-09-06 15:16:44 -07001978 ----------------------------------------------------------------- */
1979 if (cflag & CBAUDEX) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 /* -------------------------------------------------------------
1981 The below code is trying to guarantee that only baud rates
1982 115200 and 230400 are remapped. We use exclusive or because
1983 the various baud rates share common bit positions and therefore
1984 can't be tested for easily.
1985 ----------------------------------------------------------------- */
1986
1987
1988 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1989 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 res += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 return res;
1993
1994} /* End termios2digi_c */
1995
1996/* --------------------- Begin epcaparam ----------------------- */
1997
Alan Coxf2cf8e22005-09-06 15:16:44 -07001998/* Caller must hold the locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999static void epcaparam(struct tty_struct *tty, struct channel *ch)
2000{ /* Begin epcaparam */
2001
2002 unsigned int cmdHead;
Alan Cox606d0992006-12-08 02:38:45 -08002003 struct ktermios *ts;
Al Virobc9a5152005-09-15 22:53:28 +01002004 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 unsigned mval, hflow, cflag, iflag;
2006
2007 bc = ch->brdchan;
2008 epcaassert(bc !=0, "bc out of range");
2009
2010 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 ts = tty->termios;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002012 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2013 cmdHead = readw(&bc->rin);
Al Virobc9a5152005-09-15 22:53:28 +01002014 writew(cmdHead, &bc->rout);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002015 cmdHead = readw(&bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 /* Changing baud in mid-stream transmission can be wonderful */
2017 /* ---------------------------------------------------------------
2018 Flush current transmit buffer by setting cmdTail pointer (tout)
2019 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2020 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2022 mval = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002023 } else { /* Begin CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 /* -------------------------------------------------------------------
2025 c_cflags have changed but that change had nothing to do with BAUD.
2026 Propagate the change to the card.
2027 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 cflag = termios2digi_c(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002029 if (cflag != ch->fepcflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 ch->fepcflag = cflag;
2031 /* Set baud rate, char size, stop bits, parity */
2032 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 /* ----------------------------------------------------------------
2035 If the user has not forced CLOCAL and if the device is not a
2036 CALLOUT device (Which is always CLOCAL) we set flags such that
2037 the driver will wait on carrier detect.
2038 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 if (ts->c_cflag & CLOCAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 ch->asyncflags &= ~ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 ch->asyncflags |= ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 mval = ch->m_dtr | ch->m_rts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 } /* End CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 iflag = termios2digi_i(ch, ts->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 /* Check input mode flags */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002047 if (iflag != ch->fepiflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 ch->fepiflag = iflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 /* ---------------------------------------------------------------
2050 Command sets channels iflag structure on the board. Such things
2051 as input soft flow control, handling of parity errors, and
2052 break handling are all set here.
2053 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 /* break handling, parity handling, input stripping, flow control chars */
2055 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 /* ---------------------------------------------------------------
2058 Set the board mint value for this channel. This will cause hardware
2059 events to be generated each time the DCD signal (Described in mint)
2060 changes.
2061 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002062 writeb(ch->dcd, &bc->mint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2064 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002065 writeb(0, &bc->mint);
2066 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 hflow = termios2digi_h(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002068 if (hflow != ch->hflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 ch->hflow = hflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 /* --------------------------------------------------------------
2071 Hard flow control has been selected but the board is not
2072 using it. Activate hard flow control now.
2073 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 mval ^= ch->modemfake & (mval ^ ch->modem);
2077
Alan Coxf2cf8e22005-09-06 15:16:44 -07002078 if (ch->omodem ^ mval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 ch->omodem = mval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 /* --------------------------------------------------------------
2081 The below command sets the DTR and RTS mstat structure. If
2082 hard flow control is NOT active these changes will drive the
2083 output of the actual DTR and RTS lines. If hard flow control
2084 is active, the changes will be saved in the mstat structure and
2085 only asserted when hard flow control is turned off.
2086 ----------------------------------------------------------------- */
2087
2088 /* First reset DTR & RTS; then set them */
2089 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2090 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002092 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 ch->fepstartc = ch->startc;
2094 ch->fepstopc = ch->stopc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 /* ------------------------------------------------------------
2096 The XON / XOFF characters have changed; propagate these
2097 changes to the card.
2098 --------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2100 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002101 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 ch->fepstartca = ch->startca;
2103 ch->fepstopca = ch->stopca;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 /* ---------------------------------------------------------------
2105 Similar to the above, this time the auxilarly XON / XOFF
2106 characters have changed; propagate these changes to the card.
2107 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110} /* End epcaparam */
2111
2112/* --------------------- Begin receive_data ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002113/* Caller holds lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114static void receive_data(struct channel *ch)
2115{ /* Begin receive_data */
2116
2117 unchar *rptr;
Alan Cox606d0992006-12-08 02:38:45 -08002118 struct ktermios *ts = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +01002120 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002121 int dataToRead, wrapgap, bytesAvailable;
2122 unsigned int tail, head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 unsigned int wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 /* ---------------------------------------------------------------
2126 This routine is called by doint when a receive data event
2127 has taken place.
2128 ------------------------------------------------------------------- */
2129
2130 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 if (ch->statusflags & RXSTOPPED)
2132 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 tty = ch->tty;
2134 if (tty)
2135 ts = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002137 BUG_ON(!bc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 wrapmask = ch->rxbufsize - 1;
2139
2140 /* ---------------------------------------------------------------------
2141 Get the head and tail pointers to the receiver queue. Wrap the
2142 head pointer if it has reached the end of the buffer.
2143 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002144 head = readw(&bc->rin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 head &= wrapmask;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002146 tail = readw(&bc->rout) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
2148 bytesAvailable = (head - tail) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 if (bytesAvailable == 0)
2150 return;
2151
2152 /* ------------------------------------------------------------------
2153 If CREAD bit is off or device not open, set TX tail to head
2154 --------------------------------------------------------------------- */
2155
Alan Coxf2cf8e22005-09-06 15:16:44 -07002156 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
Al Virobc9a5152005-09-15 22:53:28 +01002157 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 return;
2159 }
2160
Alan Cox33f0f882006-01-09 20:54:13 -08002161 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 return;
2163
Alan Coxf2cf8e22005-09-06 15:16:44 -07002164 if (readb(&bc->orun)) {
2165 writeb(0, &bc->orun);
2166 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
Alan Cox33f0f882006-01-09 20:54:13 -08002167 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 rxwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002170 while (bytesAvailable > 0) { /* Begin while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 /* ---------------------------------------------------------------
2173 Even if head has wrapped around only report the amount of
2174 data to be equal to the size - tail. Remember memcpy can't
2175 automaticly wrap around the receive buffer.
2176 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 /* --------------------------------------------------------------
2179 Make sure we don't overflow the buffer
2180 ----------------------------------------------------------------- */
Alan Cox33f0f882006-01-09 20:54:13 -08002181 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 if (dataToRead == 0)
2183 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 /* ---------------------------------------------------------------
2185 Move data read from our card into the line disciplines buffer
2186 for translation if necessary.
2187 ------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002188 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 tail = (tail + dataToRead) & wrapmask;
2190 bytesAvailable -= dataToRead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 } /* End while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002193 writew(tail, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 /* Must be called with global data */
2195 tty_schedule_flip(ch->tty);
2196 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197} /* End receive_data */
2198
2199static int info_ioctl(struct tty_struct *tty, struct file * file,
2200 unsigned int cmd, unsigned long arg)
2201{
2202 switch (cmd)
2203 { /* Begin switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 case DIGI_GETINFO:
2205 { /* Begin case DIGI_GETINFO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 struct digi_info di ;
2207 int brd;
2208
Alan Coxf2cf8e22005-09-06 15:16:44 -07002209 if(get_user(brd, (unsigned int __user *)arg))
2210 return -EFAULT;
2211 if (brd < 0 || brd >= num_cards || num_cards == 0)
2212 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
2214 memset(&di, 0, sizeof(di));
2215
2216 di.board = brd ;
2217 di.status = boards[brd].status;
2218 di.type = boards[brd].type ;
2219 di.numports = boards[brd].numports ;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002220 /* Legacy fixups - just move along nothing to see */
2221 di.port = (unsigned char *)boards[brd].port ;
2222 di.membase = (unsigned char *)boards[brd].membase ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
2224 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2225 return -EFAULT;
2226 break;
2227
2228 } /* End case DIGI_GETINFO */
2229
2230 case DIGI_POLLER:
2231 { /* Begin case DIGI_POLLER */
2232
2233 int brd = arg & 0xff000000 >> 16 ;
2234 unsigned char state = arg & 0xff ;
2235
Alan Coxf2cf8e22005-09-06 15:16:44 -07002236 if (brd < 0 || brd >= num_cards) {
2237 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 return (-ENODEV);
2239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 digi_poller_inhibited = state ;
2241 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 } /* End case DIGI_POLLER */
2243
2244 case DIGI_INIT:
2245 { /* Begin case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 /* ------------------------------------------------------------
2247 This call is made by the apps to complete the initilization
2248 of the board(s). This routine is responsible for setting
2249 the card to its initial state and setting the drivers control
2250 fields to the sutianle settings for the card in question.
2251 ---------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 int crd ;
2253 for (crd = 0; crd < num_cards; crd++)
2254 post_fep_init (crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 } /* End case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002258 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 } /* End switch cmd */
2260 return (0) ;
2261}
2262/* --------------------- Begin pc_ioctl ----------------------- */
2263
2264static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2265{
2266 struct channel *ch = (struct channel *) tty->driver_data;
Al Virobc9a5152005-09-15 22:53:28 +01002267 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 unsigned int mstat, mflag = 0;
2269 unsigned long flags;
2270
2271 if (ch)
2272 bc = ch->brdchan;
2273 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002274 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Alan Coxf2cf8e22005-09-06 15:16:44 -07002276 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002278 mstat = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002280 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
2282 if (mstat & ch->m_dtr)
2283 mflag |= TIOCM_DTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 if (mstat & ch->m_rts)
2285 mflag |= TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 if (mstat & ch->m_cts)
2287 mflag |= TIOCM_CTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 if (mstat & ch->dsr)
2289 mflag |= TIOCM_DSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 if (mstat & ch->m_ri)
2291 mflag |= TIOCM_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 if (mstat & ch->dcd)
2293 mflag |= TIOCM_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 return mflag;
2295}
2296
2297static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2298 unsigned int set, unsigned int clear)
2299{
2300 struct channel *ch = (struct channel *) tty->driver_data;
2301 unsigned long flags;
2302
Alan Coxf2cf8e22005-09-06 15:16:44 -07002303 if (!ch)
2304 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Alan Coxf2cf8e22005-09-06 15:16:44 -07002306 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 /*
2308 * I think this modemfake stuff is broken. It doesn't
2309 * correctly reflect the behaviour desired by the TIOCM*
2310 * ioctls. Therefore this is probably broken.
2311 */
2312 if (set & TIOCM_RTS) {
2313 ch->modemfake |= ch->m_rts;
2314 ch->modem |= ch->m_rts;
2315 }
2316 if (set & TIOCM_DTR) {
2317 ch->modemfake |= ch->m_dtr;
2318 ch->modem |= ch->m_dtr;
2319 }
2320 if (clear & TIOCM_RTS) {
2321 ch->modemfake |= ch->m_rts;
2322 ch->modem &= ~ch->m_rts;
2323 }
2324 if (clear & TIOCM_DTR) {
2325 ch->modemfake |= ch->m_dtr;
2326 ch->modem &= ~ch->m_dtr;
2327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 /* --------------------------------------------------------------
2330 The below routine generally sets up parity, baud, flow control
2331 issues, etc.... It effect both control flags and input flags.
2332 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 epcaparam(tty,ch);
2334 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002335 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 return 0;
2337}
2338
2339static int pc_ioctl(struct tty_struct *tty, struct file * file,
2340 unsigned int cmd, unsigned long arg)
2341{ /* Begin pc_ioctl */
2342
2343 digiflow_t dflow;
2344 int retval;
2345 unsigned long flags;
2346 unsigned int mflag, mstat;
2347 unsigned char startc, stopc;
Al Virobc9a5152005-09-15 22:53:28 +01002348 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 struct channel *ch = (struct channel *) tty->driver_data;
2350 void __user *argp = (void __user *)arg;
2351
2352 if (ch)
2353 bc = ch->brdchan;
2354 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002355 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
2357 /* -------------------------------------------------------------------
2358 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2359 in /usr/src/linux/drivers/char for a good example. In particular
2360 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2361 ---------------------------------------------------------------------- */
2362
2363 switch (cmd)
2364 { /* Begin switch cmd */
2365
Alan Cox606d0992006-12-08 02:38:45 -08002366#if 0 /* Handled by calling layer properly */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 case TCGETS:
Alan Cox606d0992006-12-08 02:38:45 -08002368 if (copy_to_user(argp, tty->termios, sizeof(struct ktermios)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 return -EFAULT;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002370 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 case TCGETA:
2372 return get_termio(tty, argp);
Alan Cox606d0992006-12-08 02:38:45 -08002373#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 case TCSBRK: /* SVID version: non-zero arg --> no break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 retval = tty_check_change(tty);
2376 if (retval)
2377 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002379 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002381 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 tty_wait_until_sent(tty, 0);
2383 if (!arg)
2384 digi_send_break(ch, HZ/4); /* 1/4 second */
2385 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 case TCSBRKP: /* support for POSIX tcsendbreak() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 retval = tty_check_change(tty);
2388 if (retval)
2389 return retval;
2390
2391 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002392 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002394 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 tty_wait_until_sent(tty, 0);
2396 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2397 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 case TIOCGSOFTCAR:
2399 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2400 return -EFAULT;
2401 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 case TIOCSSOFTCAR:
2403 {
2404 unsigned int value;
2405
2406 if (get_user(value, (unsigned __user *)argp))
2407 return -EFAULT;
2408 tty->termios->c_cflag =
2409 ((tty->termios->c_cflag & ~CLOCAL) |
2410 (value ? CLOCAL : 0));
2411 return 0;
2412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 case TIOCMODG:
2414 mflag = pc_tiocmget(tty, file);
2415 if (put_user(mflag, (unsigned long __user *)argp))
2416 return -EFAULT;
2417 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 case TIOCMODS:
2419 if (get_user(mstat, (unsigned __user *)argp))
2420 return -EFAULT;
2421 return pc_tiocmset(tty, file, mstat, ~mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 case TIOCSDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002423 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 ch->omodem |= ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 globalwinon(ch);
2426 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2427 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002428 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 break;
2430
2431 case TIOCCDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002432 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 ch->omodem &= ~ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 globalwinon(ch);
2435 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2436 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002437 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 case DIGI_GETA:
2440 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2441 return -EFAULT;
2442 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 case DIGI_SETAW:
2444 case DIGI_SETAF:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002445 if (cmd == DIGI_SETAW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002447 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002449 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 tty_wait_until_sent(tty, 0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002451 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 /* ldisc lock already held in ioctl */
2453 if (tty->ldisc.flush_buffer)
2454 tty->ldisc.flush_buffer(tty);
2455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 /* Fall Thru */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 case DIGI_SETA:
2458 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2459 return -EFAULT;
2460
Alan Coxf2cf8e22005-09-06 15:16:44 -07002461 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 ch->dcd = ch->m_dsr;
2463 ch->dsr = ch->m_dcd;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002464 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 ch->dcd = ch->m_dcd;
2466 ch->dsr = ch->m_dsr;
2467 }
2468
Alan Coxf2cf8e22005-09-06 15:16:44 -07002469 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 globalwinon(ch);
2471
2472 /* -----------------------------------------------------------------
2473 The below routine generally sets up parity, baud, flow control
2474 issues, etc.... It effect both control flags and input flags.
2475 ------------------------------------------------------------------- */
2476
2477 epcaparam(tty,ch);
2478 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002479 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 break;
2481
2482 case DIGI_GETFLOW:
2483 case DIGI_GETAFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002484 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002486 if (cmd == DIGI_GETFLOW) {
2487 dflow.startc = readb(&bc->startc);
2488 dflow.stopc = readb(&bc->stopc);
2489 } else {
2490 dflow.startc = readb(&bc->startca);
2491 dflow.stopc = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 }
2493 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002494 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
2496 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2497 return -EFAULT;
2498 break;
2499
2500 case DIGI_SETAFLOW:
2501 case DIGI_SETFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002502 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 startc = ch->startc;
2504 stopc = ch->stopc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002505 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 startc = ch->startca;
2507 stopc = ch->stopca;
2508 }
2509
2510 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2511 return -EFAULT;
2512
Alan Coxf2cf8e22005-09-06 15:16:44 -07002513 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2514 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 globalwinon(ch);
2516
Alan Coxf2cf8e22005-09-06 15:16:44 -07002517 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 ch->fepstartc = ch->startc = dflow.startc;
2519 ch->fepstopc = ch->stopc = dflow.stopc;
2520 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002521 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 ch->fepstartca = ch->startca = dflow.startc;
2523 ch->fepstopca = ch->stopca = dflow.stopc;
2524 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2525 }
2526
Alan Coxf2cf8e22005-09-06 15:16:44 -07002527 if (ch->statusflags & TXSTOPPED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 pc_start(tty);
2529
2530 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002531 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 } /* End if setflow toggled */
2533 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 default:
2535 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 } /* End switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538} /* End pc_ioctl */
2539
2540/* --------------------- Begin pc_set_termios ----------------------- */
2541
Alan Cox606d0992006-12-08 02:38:45 -08002542static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543{ /* Begin pc_set_termios */
2544
2545 struct channel *ch;
2546 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 /* ---------------------------------------------------------
2548 verifyChannel returns the channel from the tty struct
2549 if it is valid. This serves as a sanity check.
2550 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002551 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2552 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 globalwinon(ch);
2554 epcaparam(tty, ch);
2555 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002556 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
2558 if ((old_termios->c_cflag & CRTSCTS) &&
2559 ((tty->termios->c_cflag & CRTSCTS) == 0))
2560 tty->hw_stopped = 0;
2561
2562 if (!(old_termios->c_cflag & CLOCAL) &&
2563 (tty->termios->c_cflag & CLOCAL))
2564 wake_up_interruptible(&ch->open_wait);
2565
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 } /* End if channel valid */
2567
2568} /* End pc_set_termios */
2569
2570/* --------------------- Begin do_softint ----------------------- */
2571
David Howellsc4028952006-11-22 14:57:56 +00002572static void do_softint(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{ /* Begin do_softint */
David Howellsc4028952006-11-22 14:57:56 +00002574 struct channel *ch = container_of(work, struct channel, tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 /* Called in response to a modem change event */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002576 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 struct tty_struct *tty = ch->tty;
2578
Alan Coxf2cf8e22005-09-06 15:16:44 -07002579 if (tty && tty->driver_data) {
2580 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2582 wake_up_interruptible(&ch->open_wait);
2583 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 } /* End if clear_bit */
2585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 } /* End EPCA_MAGIC */
2587} /* End do_softint */
2588
2589/* ------------------------------------------------------------
2590 pc_stop and pc_start provide software flow control to the
2591 routine and the pc_ioctl routine.
2592---------------------------------------------------------------- */
2593
2594/* --------------------- Begin pc_stop ----------------------- */
2595
2596static void pc_stop(struct tty_struct *tty)
2597{ /* Begin pc_stop */
2598
2599 struct channel *ch;
2600 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 /* ---------------------------------------------------------
2602 verifyChannel returns the channel from the tty struct
2603 if it is valid. This serves as a sanity check.
2604 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002605 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
2606 spin_lock_irqsave(&epca_lock, flags);
2607 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 /* STOP transmitting now !! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 ch->statusflags |= TXSTOPPED;
2612 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 } /* End if transmit stop requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002614 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 } /* End if valid channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616} /* End pc_stop */
2617
2618/* --------------------- Begin pc_start ----------------------- */
2619
2620static void pc_start(struct tty_struct *tty)
2621{ /* Begin pc_start */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 /* ---------------------------------------------------------
2624 verifyChannel returns the channel from the tty struct
2625 if it is valid. This serves as a sanity check.
2626 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002627 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002629 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002631 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
Al Virobc9a5152005-09-15 22:53:28 +01002632 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 globalwinon(ch);
2634 bc = ch->brdchan;
2635 if (ch->statusflags & LOWWAIT)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002636 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 /* Okay, you can start transmitting again... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 ch->statusflags &= ~TXSTOPPED;
2640 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 } /* End transmit resume requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002642 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644} /* End pc_start */
2645
2646/* ------------------------------------------------------------------
2647 The below routines pc_throttle and pc_unthrottle are used
2648 to slow (And resume) the receipt of data into the kernels
2649 receive buffers. The exact occurrence of this depends on the
2650 size of the kernels receive buffer and what the 'watermarks'
2651 are set to for that buffer. See the n_ttys.c file for more
2652 details.
2653______________________________________________________________________ */
2654/* --------------------- Begin throttle ----------------------- */
2655
2656static void pc_throttle(struct tty_struct * tty)
2657{ /* Begin pc_throttle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 struct channel *ch;
2659 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 /* ---------------------------------------------------------
2661 verifyChannel returns the channel from the tty struct
2662 if it is valid. This serves as a sanity check.
2663 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002664 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2665 spin_lock_irqsave(&epca_lock, flags);
2666 if ((ch->statusflags & RXSTOPPED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 globalwinon(ch);
2668 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 ch->statusflags |= RXSTOPPED;
2670 memoff(ch);
2671 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002672 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674} /* End pc_throttle */
2675
2676/* --------------------- Begin unthrottle ----------------------- */
2677
2678static void pc_unthrottle(struct tty_struct *tty)
2679{ /* Begin pc_unthrottle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 struct channel *ch;
2681 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 /* ---------------------------------------------------------
2683 verifyChannel returns the channel from the tty struct
2684 if it is valid. This serves as a sanity check.
2685 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002686 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002688 spin_lock_irqsave(&epca_lock, flags);
2689 if (ch->statusflags & RXSTOPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 ch->statusflags &= ~RXSTOPPED;
2693 memoff(ch);
2694 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002695 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697} /* End pc_unthrottle */
2698
2699/* --------------------- Begin digi_send_break ----------------------- */
2700
2701void digi_send_break(struct channel *ch, int msec)
2702{ /* Begin digi_send_break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 unsigned long flags;
2704
Alan Coxf2cf8e22005-09-06 15:16:44 -07002705 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 /* --------------------------------------------------------------------
2708 Maybe I should send an infinite break here, schedule() for
2709 msec amount of time, and then stop the break. This way,
2710 the user can't screw up the FEP by causing digi_send_break()
2711 to be called (i.e. via an ioctl()) more than once in msec amount
2712 of time. Try this for now...
2713 ------------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2715 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002716 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717} /* End digi_send_break */
2718
2719/* --------------------- Begin setup_empty_event ----------------------- */
2720
Alan Coxf2cf8e22005-09-06 15:16:44 -07002721/* Caller MUST hold the lock */
2722
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2724{ /* Begin setup_empty_event */
2725
Al Virobc9a5152005-09-15 22:53:28 +01002726 struct board_chan __iomem *bc = ch->brdchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 globalwinon(ch);
2729 ch->statusflags |= EMPTYWAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 /* ------------------------------------------------------------------
2731 When set the iempty flag request a event to be generated when the
2732 transmit buffer is empty (If there is no BREAK in progress).
2733 --------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002734 writeb(1, &bc->iempty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736} /* End setup_empty_event */
2737
2738/* --------------------- Begin get_termio ----------------------- */
2739
2740static int get_termio(struct tty_struct * tty, struct termio __user * termio)
2741{ /* Begin get_termio */
2742 return kernel_termios_to_user_termio(termio, tty->termios);
2743} /* End get_termio */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002744
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745/* ---------------------- Begin epca_setup -------------------------- */
2746void epca_setup(char *str, int *ints)
2747{ /* Begin epca_setup */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 struct board_info board;
2749 int index, loop, last;
2750 char *temp, *t2;
2751 unsigned len;
2752
2753 /* ----------------------------------------------------------------------
2754 If this routine looks a little strange it is because it is only called
2755 if a LILO append command is given to boot the kernel with parameters.
2756 In this way, we can provide the user a method of changing his board
2757 configuration without rebuilding the kernel.
2758 ----------------------------------------------------------------------- */
2759 if (!liloconfig)
2760 liloconfig = 1;
2761
2762 memset(&board, 0, sizeof(board));
2763
2764 /* Assume the data is int first, later we can change it */
2765 /* I think that array position 0 of ints holds the number of args */
2766 for (last = 0, index = 1; index <= ints[0]; index++)
2767 switch(index)
2768 { /* Begin parse switch */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 case 1:
2770 board.status = ints[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 /* ---------------------------------------------------------
2772 We check for 2 (As opposed to 1; because 2 is a flag
2773 instructing the driver to ignore epcaconfig.) For this
2774 reason we check for 2.
2775 ------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002776 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 nbdevs = 0;
2778 num_cards = 0;
2779 return;
2780 } /* End ignore epcaconfig as well as lilo cmd line */
2781
Alan Coxf2cf8e22005-09-06 15:16:44 -07002782 if (board.status > 2) {
2783 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 invalid_lilo_config = 1;
2785 setup_error_code |= INVALID_BOARD_STATUS;
2786 return;
2787 }
2788 last = index;
2789 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 case 2:
2791 board.type = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002792 if (board.type >= PCIXEM) {
2793 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 invalid_lilo_config = 1;
2795 setup_error_code |= INVALID_BOARD_TYPE;
2796 return;
2797 }
2798 last = index;
2799 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 case 3:
2801 board.altpin = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002802 if (board.altpin > 1) {
2803 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 invalid_lilo_config = 1;
2805 setup_error_code |= INVALID_ALTPIN;
2806 return;
2807 }
2808 last = index;
2809 break;
2810
2811 case 4:
2812 board.numports = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002813 if (board.numports < 2 || board.numports > 256) {
2814 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 invalid_lilo_config = 1;
2816 setup_error_code |= INVALID_NUM_PORTS;
2817 return;
2818 }
2819 nbdevs += board.numports;
2820 last = index;
2821 break;
2822
2823 case 5:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002824 board.port = ints[index];
2825 if (ints[index] <= 0) {
2826 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 invalid_lilo_config = 1;
2828 setup_error_code |= INVALID_PORT_BASE;
2829 return;
2830 }
2831 last = index;
2832 break;
2833
2834 case 6:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002835 board.membase = ints[index];
2836 if (ints[index] <= 0) {
2837 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 invalid_lilo_config = 1;
2839 setup_error_code |= INVALID_MEM_BASE;
2840 return;
2841 }
2842 last = index;
2843 break;
2844
2845 default:
2846 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2847 return;
2848
2849 } /* End parse switch */
2850
Alan Coxf2cf8e22005-09-06 15:16:44 -07002851 while (str && *str) { /* Begin while there is a string arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 /* find the next comma or terminator */
2853 temp = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 /* While string is not null, and a comma hasn't been found */
2855 while (*temp && (*temp != ','))
2856 temp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 if (!*temp)
2858 temp = NULL;
2859 else
2860 *temp++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 /* Set index to the number of args + 1 */
2862 index = last + 1;
2863
2864 switch(index)
2865 {
2866 case 1:
2867 len = strlen(str);
2868 if (strncmp("Disable", str, len) == 0)
2869 board.status = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002870 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 board.status = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002872 else {
2873 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 invalid_lilo_config = 1;
2875 setup_error_code |= INVALID_BOARD_STATUS;
2876 return;
2877 }
2878 last = index;
2879 break;
2880
2881 case 2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
2883 if (strcmp(board_desc[loop], str) == 0)
2884 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 /* ---------------------------------------------------------------
2886 If the index incremented above refers to a legitamate board
2887 type set it here.
2888 ------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 if (index < EPCA_NUM_TYPES)
2890 board.type = loop;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002891 else {
2892 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 invalid_lilo_config = 1;
2894 setup_error_code |= INVALID_BOARD_TYPE;
2895 return;
2896 }
2897 last = index;
2898 break;
2899
2900 case 3:
2901 len = strlen(str);
2902 if (strncmp("Disable", str, len) == 0)
2903 board.altpin = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002904 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 board.altpin = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002906 else {
2907 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 invalid_lilo_config = 1;
2909 setup_error_code |= INVALID_ALTPIN;
2910 return;
2911 }
2912 last = index;
2913 break;
2914
2915 case 4:
2916 t2 = str;
2917 while (isdigit(*t2))
2918 t2++;
2919
Alan Coxf2cf8e22005-09-06 15:16:44 -07002920 if (*t2) {
2921 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 invalid_lilo_config = 1;
2923 setup_error_code |= INVALID_NUM_PORTS;
2924 return;
2925 }
2926
2927 /* ------------------------------------------------------------
2928 There is not a man page for simple_strtoul but the code can be
2929 found in vsprintf.c. The first argument is the string to
2930 translate (To an unsigned long obviously), the second argument
2931 can be the address of any character variable or a NULL. If a
2932 variable is given, the end pointer of the string will be stored
2933 in that variable; if a NULL is given the end pointer will
2934 not be returned. The last argument is the base to use. If
2935 a 0 is indicated, the routine will attempt to determine the
2936 proper base by looking at the values prefix (A '0' for octal,
2937 a 'x' for hex, etc ... If a value is given it will use that
2938 value as the base.
2939 ---------------------------------------------------------------- */
2940 board.numports = simple_strtoul(str, NULL, 0);
2941 nbdevs += board.numports;
2942 last = index;
2943 break;
2944
2945 case 5:
2946 t2 = str;
2947 while (isxdigit(*t2))
2948 t2++;
2949
Alan Coxf2cf8e22005-09-06 15:16:44 -07002950 if (*t2) {
2951 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 invalid_lilo_config = 1;
2953 setup_error_code |= INVALID_PORT_BASE;
2954 return;
2955 }
2956
Alan Coxf2cf8e22005-09-06 15:16:44 -07002957 board.port = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 last = index;
2959 break;
2960
2961 case 6:
2962 t2 = str;
2963 while (isxdigit(*t2))
2964 t2++;
2965
Alan Coxf2cf8e22005-09-06 15:16:44 -07002966 if (*t2) {
2967 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 invalid_lilo_config = 1;
2969 setup_error_code |= INVALID_MEM_BASE;
2970 return;
2971 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002972 board.membase = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 last = index;
2974 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002976 printk(KERN_ERR "epca: Too many string parms\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return;
2978 }
2979 str = temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 } /* End while there is a string arg */
2981
Alan Coxf2cf8e22005-09-06 15:16:44 -07002982 if (last < 6) {
2983 printk(KERN_ERR "epca: Insufficient parms specified\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 return;
2985 }
2986
2987 /* I should REALLY validate the stuff here */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 /* Copies our local copy of board into boards */
2989 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 /* Does this get called once per lilo arg are what ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2992 num_cards, board_desc[board.type],
2993 board.numports, (int)board.port, (unsigned int) board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 num_cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995} /* End epca_setup */
2996
2997
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998/* ------------------------ Begin init_PCI --------------------------- */
2999
3000enum epic_board_types {
3001 brd_xr = 0,
3002 brd_xem,
3003 brd_cx,
3004 brd_xrj,
3005};
3006
3007
3008/* indexed directly by epic_board_types enum */
3009static struct {
3010 unsigned char board_type;
3011 unsigned bar_idx; /* PCI base address region */
3012} epca_info_tbl[] = {
3013 { PCIXR, 0, },
3014 { PCIXEM, 0, },
3015 { PCICX, 0, },
3016 { PCIXRJ, 2, },
3017};
3018
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019static int __devinit epca_init_one (struct pci_dev *pdev,
3020 const struct pci_device_id *ent)
3021{
3022 static int board_num = -1;
3023 int board_idx, info_idx = ent->driver_data;
3024 unsigned long addr;
3025
3026 if (pci_enable_device(pdev))
3027 return -EIO;
3028
3029 board_num++;
3030 board_idx = board_num + num_cards;
3031 if (board_idx >= MAXBOARDS)
3032 goto err_out;
3033
3034 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3035 if (!addr) {
3036 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3037 epca_info_tbl[info_idx].bar_idx);
3038 goto err_out;
3039 }
3040
3041 boards[board_idx].status = ENABLED;
3042 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3043 boards[board_idx].numports = 0x0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07003044 boards[board_idx].port = addr + PCI_IO_OFFSET;
3045 boards[board_idx].membase = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
3047 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3048 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3049 0x200000, addr + PCI_IO_OFFSET);
3050 goto err_out;
3051 }
3052
3053 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3054 if (!boards[board_idx].re_map_port) {
3055 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3056 0x200000, addr + PCI_IO_OFFSET);
3057 goto err_out_free_pciio;
3058 }
3059
3060 if (!request_mem_region (addr, 0x200000, "epca")) {
3061 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3062 0x200000, addr);
3063 goto err_out_free_iounmap;
3064 }
3065
3066 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3067 if (!boards[board_idx].re_map_membase) {
3068 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3069 0x200000, addr + PCI_IO_OFFSET);
3070 goto err_out_free_memregion;
3071 }
3072
3073 /* --------------------------------------------------------------
3074 I don't know what the below does, but the hardware guys say
3075 its required on everything except PLX (In this case XRJ).
3076 ---------------------------------------------------------------- */
3077 if (info_idx != brd_xrj) {
3078 pci_write_config_byte(pdev, 0x40, 0);
3079 pci_write_config_byte(pdev, 0x46, 0);
3080 }
3081
3082 return 0;
3083
3084err_out_free_memregion:
3085 release_mem_region (addr, 0x200000);
3086err_out_free_iounmap:
3087 iounmap (boards[board_idx].re_map_port);
3088err_out_free_pciio:
3089 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3090err_out:
3091 return -ENODEV;
3092}
3093
3094
3095static struct pci_device_id epca_pci_tbl[] = {
3096 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3097 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3098 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3099 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3100 { 0, }
3101};
3102
3103MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3104
3105int __init init_PCI (void)
Alan Coxf2cf8e22005-09-06 15:16:44 -07003106{ /* Begin init_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 memset (&epca_driver, 0, sizeof (epca_driver));
3108 epca_driver.name = "epca";
3109 epca_driver.id_table = epca_pci_tbl;
3110 epca_driver.probe = epca_init_one;
3111
3112 return pci_register_driver(&epca_driver);
Alan Coxf2cf8e22005-09-06 15:16:44 -07003113}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115MODULE_LICENSE("GPL");