blob: 7c71eb779802a9f9ed1a8dde50b3943b86c25b96 [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);
202static void pc_set_termios(struct tty_struct *, struct termios *);
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 wake_up_interruptible(&tty->write_wait);
848 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849} /* End pc_flush_buffer */
850
851/* ------------------ Begin pc_flush_chars ---------------------- */
852
853static void pc_flush_chars(struct tty_struct *tty)
854{ /* Begin pc_flush_chars */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 struct channel * ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 /* ---------------------------------------------------------
857 verifyChannel returns the channel from the tty struct
858 if it is valid. This serves as a sanity check.
859 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700860 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700862 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 /* ----------------------------------------------------------------
864 If not already set and the transmitter is busy setup an event
865 to indicate when the transmit empties.
866 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
868 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700869 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871} /* End pc_flush_chars */
872
873/* ------------------ Begin block_til_ready ---------------------- */
874
875static int block_til_ready(struct tty_struct *tty,
876 struct file *filp, struct channel *ch)
877{ /* Begin block_til_ready */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 DECLARE_WAITQUEUE(wait,current);
879 int retval, do_clocal = 0;
880 unsigned long flags;
881
Alan Coxf2cf8e22005-09-06 15:16:44 -0700882 if (tty_hung_up_p(filp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
884 retval = -EAGAIN;
885 else
886 retval = -ERESTARTSYS;
887 return(retval);
888 }
889
890 /* -----------------------------------------------------------------
891 If the device is in the middle of being closed, then block
892 until it's done, and then try again.
893 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700894 if (ch->asyncflags & ASYNC_CLOSING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 interruptible_sleep_on(&ch->close_wait);
896
897 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
898 return -EAGAIN;
899 else
900 return -ERESTARTSYS;
901 }
902
Alan Coxf2cf8e22005-09-06 15:16:44 -0700903 if (filp->f_flags & O_NONBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 /* -----------------------------------------------------------------
905 If non-blocking mode is set, then make the check up front
906 and then exit.
907 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 return 0;
910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (tty->termios->c_cflag & CLOCAL)
912 do_clocal = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700913 /* Block waiting for the carrier detect and the line to become free */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 retval = 0;
916 add_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Alan Coxf2cf8e22005-09-06 15:16:44 -0700918 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 /* We dec count so that pc_close will know when to free things */
920 if (!tty_hung_up_p(filp))
921 ch->count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 ch->blocked_open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 while(1)
924 { /* Begin forever while */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 if (tty_hung_up_p(filp) ||
927 !(ch->asyncflags & ASYNC_INITIALIZED))
928 {
929 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
930 retval = -EAGAIN;
931 else
932 retval = -ERESTARTSYS;
933 break;
934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 if (!(ch->asyncflags & ASYNC_CLOSING) &&
936 (do_clocal || (ch->imodem & ch->dcd)))
937 break;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700938 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 retval = -ERESTARTSYS;
940 break;
941 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700942 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 /* ---------------------------------------------------------------
944 Allow someone else to be scheduled. We will occasionally go
945 through this loop until one of the above conditions change.
946 The below schedule call will allow other processes to enter and
947 prevent this loop from hogging the cpu.
948 ------------------------------------------------------------------ */
949 schedule();
Alan Coxf2cf8e22005-09-06 15:16:44 -0700950 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 } /* End forever while */
953
954 current->state = TASK_RUNNING;
955 remove_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 if (!tty_hung_up_p(filp))
957 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 ch->blocked_open--;
959
Alan Coxf2cf8e22005-09-06 15:16:44 -0700960 spin_unlock_irqrestore(&epca_lock, flags);
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 if (retval)
963 return retval;
964
965 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967} /* End block_til_ready */
968
969/* ------------------ Begin pc_open ---------------------- */
970
971static int pc_open(struct tty_struct *tty, struct file * filp)
972{ /* Begin pc_open */
973
974 struct channel *ch;
975 unsigned long flags;
976 int line, retval, boardnum;
Al Virobc9a5152005-09-15 22:53:28 +0100977 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700978 unsigned int head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 line = tty->index;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700981 if (line < 0 || line >= nbdevs)
982 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 ch = &digi_channels[line];
985 boardnum = ch->boardnum;
986
987 /* Check status of board configured in system. */
988
989 /* -----------------------------------------------------------------
990 I check to see if the epca_setup routine detected an user error.
991 It might be better to put this in pc_init, but for the moment it
992 goes here.
993 ---------------------------------------------------------------------- */
994
Alan Coxf2cf8e22005-09-06 15:16:44 -0700995 if (invalid_lilo_config) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (setup_error_code & INVALID_BOARD_TYPE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700997 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 if (setup_error_code & INVALID_NUM_PORTS)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700999 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (setup_error_code & INVALID_MEM_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001001 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (setup_error_code & INVALID_PORT_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001003 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (setup_error_code & INVALID_BOARD_STATUS)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001005 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 if (setup_error_code & INVALID_ALTPIN)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001007 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 tty->driver_data = NULL; /* Mark this device as 'down' */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001009 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001011 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 tty->driver_data = NULL; /* Mark this device as 'down' */
1013 return(-ENODEV);
1014 }
1015
Alan Coxf2cf8e22005-09-06 15:16:44 -07001016 if ((bc = ch->brdchan) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 tty->driver_data = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001018 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020
Alan Coxf2cf8e22005-09-06 15:16:44 -07001021 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 /* ------------------------------------------------------------------
1023 Every time a channel is opened, increment a counter. This is
1024 necessary because we do not wish to flush and shutdown the channel
1025 until the last app holding the channel open, closes it.
1026 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 /* ----------------------------------------------------------------
1029 Set a kernel structures pointer to our local channel
1030 structure. This way we can get to it when passed only
1031 a tty struct.
1032 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 tty->driver_data = ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 /* ----------------------------------------------------------------
1035 If this is the first time the channel has been opened, initialize
1036 the tty->termios struct otherwise let pc_close handle it.
1037 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 globalwinon(ch);
1039 ch->statusflags = 0;
1040
1041 /* Save boards current modem status */
Al Virobc9a5152005-09-15 22:53:28 +01001042 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 /* ----------------------------------------------------------------
1045 Set receive head and tail ptrs to each other. This indicates
1046 no data available to read.
1047 ----------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001048 head = readw(&bc->rin);
1049 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 /* Set the channels associated tty structure */
1052 ch->tty = tty;
1053
1054 /* -----------------------------------------------------------------
1055 The below routine generally sets up parity, baud, flow control
1056 issues, etc.... It effect both control flags and input flags.
1057 -------------------------------------------------------------------- */
1058 epcaparam(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 ch->asyncflags |= ASYNC_INITIALIZED;
1060 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001061 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 retval = block_til_ready(tty, filp, ch);
1064 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 /* -------------------------------------------------------------
1067 Set this again in case a hangup set it to zero while this
1068 open() was waiting for the line...
1069 --------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001070 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 ch->tty = tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 /* Enable Digi Data events */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001074 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001076 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078} /* End pc_open */
1079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080static int __init epca_module_init(void)
1081{ /* Begin init_module */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001082 return pc_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
1085module_init(epca_module_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087static struct pci_driver epca_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089static void __exit epca_module_exit(void)
1090{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 int count, crd;
1092 struct board_info *bd;
1093 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 del_timer_sync(&epca_timer);
1096
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 if ((tty_unregister_driver(pc_driver)) ||
1098 (tty_unregister_driver(pc_info)))
1099 {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001100 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 return;
1102 }
1103 put_tty_driver(pc_driver);
1104 put_tty_driver(pc_info);
1105
Alan Coxf2cf8e22005-09-06 15:16:44 -07001106 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 bd = &boards[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 if (!bd)
1109 { /* Begin sanity check */
1110 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1111 return;
1112 } /* End sanity check */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001113 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 for (count = 0; count < bd->numports; count++, ch++)
1115 { /* Begin for each port */
Jiri Slabyb3218a72006-10-04 02:15:27 -07001116 if (ch && ch->tty)
1117 tty_hangup(ch->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 } /* End for each port */
1119 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 pci_unregister_driver (&epca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
Alan Coxf2cf8e22005-09-06 15:16:44 -07001122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123module_exit(epca_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001125static const struct tty_operations pc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 .open = pc_open,
1127 .close = pc_close,
1128 .write = pc_write,
1129 .write_room = pc_write_room,
1130 .flush_buffer = pc_flush_buffer,
1131 .chars_in_buffer = pc_chars_in_buffer,
1132 .flush_chars = pc_flush_chars,
1133 .put_char = pc_put_char,
1134 .ioctl = pc_ioctl,
1135 .set_termios = pc_set_termios,
1136 .stop = pc_stop,
1137 .start = pc_start,
1138 .throttle = pc_throttle,
1139 .unthrottle = pc_unthrottle,
1140 .hangup = pc_hangup,
1141};
1142
1143static int info_open(struct tty_struct *tty, struct file * filp)
1144{
1145 return 0;
1146}
1147
1148static struct tty_operations info_ops = {
1149 .open = info_open,
1150 .ioctl = info_ioctl,
1151};
1152
1153/* ------------------ Begin pc_init ---------------------- */
1154
Alan Coxf2cf8e22005-09-06 15:16:44 -07001155static int __init pc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{ /* Begin pc_init */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 int crd;
1158 struct board_info *bd;
1159 unsigned char board_id = 0;
Akinobu Mitadabad052006-10-17 00:10:28 -07001160 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 int pci_boards_found, pci_count;
1163
1164 pci_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 pc_driver = alloc_tty_driver(MAX_ALLOC);
1167 if (!pc_driver)
Akinobu Mitadabad052006-10-17 00:10:28 -07001168 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 pc_info = alloc_tty_driver(MAX_ALLOC);
Akinobu Mitadabad052006-10-17 00:10:28 -07001171 if (!pc_info)
1172 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174 /* -----------------------------------------------------------------------
1175 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1176 board structure defined by digiConfig into drivers board structure.
1177 Note : If LILO has ran epca_setup then epca_setup will handle defining
1178 num_cards as well as copying the data into the board structure.
1179 -------------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001180 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
1182 nbdevs = NBDEVS;
1183 num_cards = NUMCARDS;
1184 memcpy((void *)&boards, (void *)&static_boards,
1185 (sizeof(struct board_info) * NUMCARDS));
1186 } /* End driver has been configured via. epcaconfig */
1187
1188 /* -----------------------------------------------------------------
1189 Note : If lilo was used to configure the driver and the
1190 ignore epcaconfig option was choosen (digiepca=2) then
1191 nbdevs and num_cards will equal 0 at this point. This is
1192 okay; PCI cards will still be picked up if detected.
1193 --------------------------------------------------------------------- */
1194
1195 /* -----------------------------------------------------------
1196 Set up interrupt, we will worry about memory allocation in
1197 post_fep_init.
1198 --------------------------------------------------------------- */
1199
1200
1201 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 /* ------------------------------------------------------------------
1204 NOTE : This code assumes that the number of ports found in
1205 the boards array is correct. This could be wrong if
1206 the card in question is PCI (And therefore has no ports
1207 entry in the boards structure.) The rest of the
1208 information will be valid for PCI because the beginning
1209 of pc_init scans for PCI and determines i/o and base
1210 memory addresses. I am not sure if it is possible to
1211 read the number of ports supported by the card prior to
1212 it being booted (Since that is the state it is in when
1213 pc_init is run). Because it is not possible to query the
1214 number of supported ports until after the card has booted;
1215 we are required to calculate the card_ptrs as the card is
1216 is initialized (Inside post_fep_init). The negative thing
1217 about this approach is that digiDload's call to GET_INFO
1218 will have a bad port value. (Since this is called prior
1219 to post_fep_init.)
1220
1221 --------------------------------------------------------------------- */
1222
1223 pci_boards_found = 0;
1224 if(num_cards < MAXBOARDS)
1225 pci_boards_found += init_PCI();
1226 num_cards += pci_boards_found;
1227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 pc_driver->owner = THIS_MODULE;
1229 pc_driver->name = "ttyD";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 pc_driver->major = DIGI_MAJOR;
1231 pc_driver->minor_start = 0;
1232 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1233 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1234 pc_driver->init_termios = tty_std_termios;
1235 pc_driver->init_termios.c_iflag = 0;
1236 pc_driver->init_termios.c_oflag = 0;
1237 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1238 pc_driver->init_termios.c_lflag = 0;
1239 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1240 tty_set_operations(pc_driver, &pc_ops);
1241
1242 pc_info->owner = THIS_MODULE;
1243 pc_info->name = "digi_ctl";
1244 pc_info->major = DIGIINFOMAJOR;
1245 pc_info->minor_start = 0;
1246 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1247 pc_info->subtype = SERIAL_TYPE_INFO;
1248 pc_info->init_termios = tty_std_termios;
1249 pc_info->init_termios.c_iflag = 0;
1250 pc_info->init_termios.c_oflag = 0;
1251 pc_info->init_termios.c_lflag = 0;
1252 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1253 pc_info->flags = TTY_DRIVER_REAL_RAW;
1254 tty_set_operations(pc_info, &info_ops);
1255
1256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 for (crd = 0; crd < num_cards; crd++)
1258 { /* Begin for each card */
1259
1260 /* ------------------------------------------------------------------
1261 This is where the appropriate memory handlers for the hardware is
1262 set. Everything at runtime blindly jumps through these vectors.
1263 ---------------------------------------------------------------------- */
1264
1265 /* defined in epcaconfig.h */
1266 bd = &boards[crd];
1267
1268 switch (bd->type)
1269 { /* Begin switch on bd->type {board type} */
1270 case PCXEM:
1271 case EISAXEM:
1272 bd->memwinon = pcxem_memwinon ;
1273 bd->memwinoff = pcxem_memwinoff ;
1274 bd->globalwinon = pcxem_globalwinon ;
1275 bd->txwinon = pcxem_txwinon ;
1276 bd->rxwinon = pcxem_rxwinon ;
1277 bd->memoff = pcxem_memoff ;
1278 bd->assertgwinon = dummy_assertgwinon;
1279 bd->assertmemoff = dummy_assertmemoff;
1280 break;
1281
1282 case PCIXEM:
1283 case PCIXRJ:
1284 case PCIXR:
1285 bd->memwinon = dummy_memwinon;
1286 bd->memwinoff = dummy_memwinoff;
1287 bd->globalwinon = dummy_globalwinon;
1288 bd->txwinon = dummy_txwinon;
1289 bd->rxwinon = dummy_rxwinon;
1290 bd->memoff = dummy_memoff;
1291 bd->assertgwinon = dummy_assertgwinon;
1292 bd->assertmemoff = dummy_assertmemoff;
1293 break;
1294
1295 case PCXE:
1296 case PCXEVE:
1297
1298 bd->memwinon = pcxe_memwinon;
1299 bd->memwinoff = pcxe_memwinoff;
1300 bd->globalwinon = pcxe_globalwinon;
1301 bd->txwinon = pcxe_txwinon;
1302 bd->rxwinon = pcxe_rxwinon;
1303 bd->memoff = pcxe_memoff;
1304 bd->assertgwinon = dummy_assertgwinon;
1305 bd->assertmemoff = dummy_assertmemoff;
1306 break;
1307
1308 case PCXI:
1309 case PC64XE:
1310
1311 bd->memwinon = pcxi_memwinon;
1312 bd->memwinoff = pcxi_memwinoff;
1313 bd->globalwinon = pcxi_globalwinon;
1314 bd->txwinon = pcxi_txwinon;
1315 bd->rxwinon = pcxi_rxwinon;
1316 bd->memoff = pcxi_memoff;
1317 bd->assertgwinon = pcxi_assertgwinon;
1318 bd->assertmemoff = pcxi_assertmemoff;
1319 break;
1320
1321 default:
1322 break;
1323
1324 } /* End switch on bd->type */
1325
1326 /* ---------------------------------------------------------------
1327 Some cards need a memory segment to be defined for use in
1328 transmit and receive windowing operations. These boards
1329 are listed in the below switch. In the case of the XI the
1330 amount of memory on the board is variable so the memory_seg
1331 is also variable. This code determines what they segment
1332 should be.
1333 ----------------------------------------------------------------- */
1334
1335 switch (bd->type)
1336 { /* Begin switch on bd->type {board type} */
1337
1338 case PCXE:
1339 case PCXEVE:
1340 case PC64XE:
1341 bd->memory_seg = 0xf000;
1342 break;
1343
1344 case PCXI:
1345 board_id = inb((int)bd->port);
1346 if ((board_id & 0x1) == 0x1)
1347 { /* Begin it's an XI card */
1348
1349 /* Is it a 64K board */
1350 if ((board_id & 0x30) == 0)
1351 bd->memory_seg = 0xf000;
1352
1353 /* Is it a 128K board */
1354 if ((board_id & 0x30) == 0x10)
1355 bd->memory_seg = 0xe000;
1356
1357 /* Is is a 256K board */
1358 if ((board_id & 0x30) == 0x20)
1359 bd->memory_seg = 0xc000;
1360
1361 /* Is it a 512K board */
1362 if ((board_id & 0x30) == 0x30)
1363 bd->memory_seg = 0x8000;
1364
Alan Coxf2cf8e22005-09-06 15:16:44 -07001365 } 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 -07001366 break;
1367
1368 } /* End switch on bd->type */
1369
1370 } /* End for each card */
1371
Akinobu Mitadabad052006-10-17 00:10:28 -07001372 err = tty_register_driver(pc_driver);
1373 if (err) {
1374 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1375 goto out3;
1376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Akinobu Mitadabad052006-10-17 00:10:28 -07001378 err = tty_register_driver(pc_info);
1379 if (err) {
1380 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1381 goto out4;
1382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
1384 /* -------------------------------------------------------------------
1385 Start up the poller to check for events on all enabled boards
1386 ---------------------------------------------------------------------- */
1387
1388 init_timer(&epca_timer);
1389 epca_timer.function = epcapoll;
1390 mod_timer(&epca_timer, jiffies + HZ/25);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 return 0;
1392
Akinobu Mitadabad052006-10-17 00:10:28 -07001393out4:
1394 tty_unregister_driver(pc_driver);
1395out3:
1396 put_tty_driver(pc_info);
1397out2:
1398 put_tty_driver(pc_driver);
1399out1:
1400 return err;
1401
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402} /* End pc_init */
1403
1404/* ------------------ Begin post_fep_init ---------------------- */
1405
1406static void post_fep_init(unsigned int crd)
1407{ /* Begin post_fep_init */
1408
1409 int i;
Al Virobc9a5152005-09-15 22:53:28 +01001410 void __iomem *memaddr;
1411 struct global_data __iomem *gd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001413 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 struct channel *ch;
1415 int shrinkmem = 0, lowwater ;
1416
1417 /* -------------------------------------------------------------
1418 This call is made by the user via. the ioctl call DIGI_INIT.
1419 It is responsible for setting up all the card specific stuff.
1420 ---------------------------------------------------------------- */
1421 bd = &boards[crd];
1422
1423 /* -----------------------------------------------------------------
1424 If this is a PCI board, get the port info. Remember PCI cards
1425 do not have entries into the epcaconfig.h file, so we can't get
1426 the number of ports from it. Unfortunetly, this means that anyone
1427 doing a DIGI_GETINFO before the board has booted will get an invalid
1428 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1429 after DIGI_INIT has been called will return the proper values.
1430 ------------------------------------------------------------------- */
1431
Alan Coxf2cf8e22005-09-06 15:16:44 -07001432 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 /* --------------------------------------------------------------------
1434 Below we use XEMPORTS as a memory offset regardless of which PCI
1435 card it is. This is because all of the supported PCI cards have
1436 the same memory offset for the channel data. This will have to be
1437 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1438 states that the port offset is 0xC22 as opposed to 0xC02. This is
1439 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1440 On the PCI cards the number of ports is determined by reading a
1441 ID PROM located in the box attached to the card. The card can then
1442 determine the index the id to determine the number of ports available.
1443 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1444 if the box in question is a XEM or CX)).
1445 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001446 /* PCI cards are already remapped at this point ISA are not */
1447 bd->numports = readw(bd->re_map_membase + XEMPORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1449 nbdevs += (bd->numports);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001450 } else {
1451 /* Fix up the mappings for ISA/EISA etc */
1452 /* FIXME: 64K - can we be smarter ? */
1453 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
1456 if (crd != 0)
1457 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1458 else
1459 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1460
1461 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1463
Alan Coxf2cf8e22005-09-06 15:16:44 -07001464 memaddr = bd->re_map_membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
1466 /* -----------------------------------------------------------------
1467 The below assignment will set bc to point at the BEGINING of
1468 the cards channel structures. For 1 card there will be between
1469 8 and 64 of these structures.
1470 -------------------------------------------------------------------- */
1471
Al Virobc9a5152005-09-15 22:53:28 +01001472 bc = memaddr + CHANSTRUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 /* -------------------------------------------------------------------
1475 The below assignment will set gd to point at the BEGINING of
1476 global memory address 0xc00. The first data in that global
1477 memory actually starts at address 0xc1a. The command in
1478 pointer begins at 0xd10.
1479 ---------------------------------------------------------------------- */
1480
Al Virobc9a5152005-09-15 22:53:28 +01001481 gd = memaddr + GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 /* --------------------------------------------------------------------
1484 XEPORTS (address 0xc22) points at the number of channels the
1485 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1486 ----------------------------------------------------------------------- */
1487
Alan Coxf2cf8e22005-09-06 15:16:44 -07001488 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 shrinkmem = 1;
1490 if (bd->type < PCIXEM)
1491 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1492 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 memwinon(bd, 0);
1494
1495 /* --------------------------------------------------------------------
1496 Remember ch is the main drivers channels structure, while bc is
1497 the cards channel structure.
1498 ------------------------------------------------------------------------ */
1499
1500 /* For every port on the card do ..... */
1501
Alan Coxf2cf8e22005-09-06 15:16:44 -07001502 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1503 unsigned long flags;
Al Virobc9a5152005-09-15 22:53:28 +01001504 u16 tseg, rseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 ch->brdchan = bc;
1507 ch->mailbox = gd;
David Howellsc4028952006-11-22 14:57:56 +00001508 INIT_WORK(&ch->tqueue, do_softint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 ch->board = &boards[crd];
1510
Alan Coxf2cf8e22005-09-06 15:16:44 -07001511 spin_lock_irqsave(&epca_lock, flags);
1512 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 /* ----------------------------------------------------------------
1514 Since some of the boards use different bitmaps for their
1515 control signals we cannot hard code these values and retain
1516 portability. We virtualize this data here.
1517 ------------------------------------------------------------------- */
1518 case EISAXEM:
1519 case PCXEM:
1520 case PCIXEM:
1521 case PCIXRJ:
1522 case PCIXR:
1523 ch->m_rts = 0x02 ;
1524 ch->m_dcd = 0x80 ;
1525 ch->m_dsr = 0x20 ;
1526 ch->m_cts = 0x10 ;
1527 ch->m_ri = 0x40 ;
1528 ch->m_dtr = 0x01 ;
1529 break;
1530
1531 case PCXE:
1532 case PCXEVE:
1533 case PCXI:
1534 case PC64XE:
1535 ch->m_rts = 0x02 ;
1536 ch->m_dcd = 0x08 ;
1537 ch->m_dsr = 0x10 ;
1538 ch->m_cts = 0x20 ;
1539 ch->m_ri = 0x40 ;
1540 ch->m_dtr = 0x80 ;
1541 break;
1542
1543 } /* End switch bd->type */
1544
Alan Coxf2cf8e22005-09-06 15:16:44 -07001545 if (boards[crd].altpin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 ch->dsr = ch->m_dcd;
1547 ch->dcd = ch->m_dsr;
1548 ch->digiext.digi_flags |= DIGI_ALTPIN;
1549 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001550 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 ch->dcd = ch->m_dcd;
1552 ch->dsr = ch->m_dsr;
1553 }
1554
1555 ch->boardnum = crd;
1556 ch->channelnum = i;
1557 ch->magic = EPCA_MAGIC;
1558 ch->tty = NULL;
1559
Alan Coxf2cf8e22005-09-06 15:16:44 -07001560 if (shrinkmem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1562 shrinkmem = 0;
1563 }
1564
Al Virobc9a5152005-09-15 22:53:28 +01001565 tseg = readw(&bc->tseg);
1566 rseg = readw(&bc->rseg);
1567
Alan Coxf2cf8e22005-09-06 15:16:44 -07001568 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
1570 case PCIXEM:
1571 case PCIXRJ:
1572 case PCIXR:
1573 /* Cover all the 2MEG cards */
Al Virobc9a5152005-09-15 22:53:28 +01001574 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1575 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1576 ch->txwin = FEPWIN | (tseg >> 11);
1577 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 break;
1579
1580 case PCXEM:
1581 case EISAXEM:
1582 /* Cover all the 32K windowed cards */
1583 /* Mask equal to window size - 1 */
Al Virobc9a5152005-09-15 22:53:28 +01001584 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1585 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1586 ch->txwin = FEPWIN | (tseg >> 11);
1587 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 break;
1589
1590 case PCXEVE:
1591 case PCXE:
Al Virobc9a5152005-09-15 22:53:28 +01001592 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1593 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1594 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1595 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 break;
1597
1598 case PCXI:
1599 case PC64XE:
Al Virobc9a5152005-09-15 22:53:28 +01001600 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1601 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 ch->txwin = ch->rxwin = 0;
1603 break;
1604
1605 } /* End switch bd->type */
1606
1607 ch->txbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001608 ch->txbufsize = readw(&bc->tmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 ch->rxbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001611 ch->rxbufsize = readw(&bc->rmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
1613 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1614
1615 /* Set transmitter low water mark */
1616 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1617
1618 /* Set receiver low water mark */
1619
1620 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1621
1622 /* Set receiver high water mark */
1623
1624 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1625
Alan Coxf2cf8e22005-09-06 15:16:44 -07001626 writew(100, &bc->edelay);
1627 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Alan Coxf2cf8e22005-09-06 15:16:44 -07001629 ch->startc = readb(&bc->startc);
1630 ch->stopc = readb(&bc->stopc);
1631 ch->startca = readb(&bc->startca);
1632 ch->stopca = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
1634 ch->fepcflag = 0;
1635 ch->fepiflag = 0;
1636 ch->fepoflag = 0;
1637 ch->fepstartc = 0;
1638 ch->fepstopc = 0;
1639 ch->fepstartca = 0;
1640 ch->fepstopca = 0;
1641
1642 ch->close_delay = 50;
1643 ch->count = 0;
1644 ch->blocked_open = 0;
1645 init_waitqueue_head(&ch->open_wait);
1646 init_waitqueue_head(&ch->close_wait);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001647
1648 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 } /* End for each port */
1650
1651 printk(KERN_INFO
1652 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1653 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 memwinoff(bd, 0);
1655
1656} /* End post_fep_init */
1657
1658/* --------------------- Begin epcapoll ------------------------ */
1659
1660static void epcapoll(unsigned long ignored)
1661{ /* Begin epcapoll */
1662
1663 unsigned long flags;
1664 int crd;
1665 volatile unsigned int head, tail;
1666 struct channel *ch;
1667 struct board_info *bd;
1668
1669 /* -------------------------------------------------------------------
1670 This routine is called upon every timer interrupt. Even though
1671 the Digi series cards are capable of generating interrupts this
1672 method of non-looping polling is more efficient. This routine
1673 checks for card generated events (Such as receive data, are transmit
1674 buffer empty) and acts on those events.
1675 ----------------------------------------------------------------------- */
1676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 for (crd = 0; crd < num_cards; crd++)
1678 { /* Begin for each card */
1679
1680 bd = &boards[crd];
1681 ch = card_ptr[crd];
1682
1683 if ((bd->status == DISABLED) || digi_poller_inhibited)
1684 continue; /* Begin loop next interation */
1685
1686 /* -----------------------------------------------------------
1687 assertmemoff is not needed here; indeed it is an empty subroutine.
1688 It is being kept because future boards may need this as well as
1689 some legacy boards.
1690 ---------------------------------------------------------------- */
1691
Alan Coxf2cf8e22005-09-06 15:16:44 -07001692 spin_lock_irqsave(&epca_lock, flags);
1693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 assertmemoff(ch);
1695
1696 globalwinon(ch);
1697
1698 /* ---------------------------------------------------------------
1699 In this case head and tail actually refer to the event queue not
1700 the transmit or receive queue.
1701 ------------------------------------------------------------------- */
1702
Alan Coxf2cf8e22005-09-06 15:16:44 -07001703 head = readw(&ch->mailbox->ein);
1704 tail = readw(&ch->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
1706 /* If head isn't equal to tail we have an event */
1707
1708 if (head != tail)
1709 doevent(crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 memoff(ch);
1711
Alan Coxf2cf8e22005-09-06 15:16:44 -07001712 spin_unlock_irqrestore(&epca_lock, flags);
1713
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 mod_timer(&epca_timer, jiffies + (HZ / 25));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716} /* End epcapoll */
1717
1718/* --------------------- Begin doevent ------------------------ */
1719
1720static void doevent(int crd)
1721{ /* Begin doevent */
1722
Al Virobc9a5152005-09-15 22:53:28 +01001723 void __iomem *eventbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 struct channel *ch, *chan0;
1725 static struct tty_struct *tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001726 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001727 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001728 unsigned int tail, head;
1729 int event, channel;
1730 int mstat, lstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732 /* -------------------------------------------------------------------
1733 This subroutine is called by epcapoll when an event is detected
1734 in the event queue. This routine responds to those events.
1735 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 bd = &boards[crd];
1737
1738 chan0 = card_ptr[crd];
1739 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001741 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 { /* Begin while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001744 eventbuf = bd->re_map_membase + tail + ISTART;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 /* Get the channel the event occurred on */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001746 channel = readb(eventbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 /* Get the actual event code that occurred */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001748 event = readb(eventbuf + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 /* ----------------------------------------------------------------
1750 The two assignments below get the current modem status (mstat)
1751 and the previous modem status (lstat). These are useful becuase
1752 an event could signal a change in modem signals itself.
1753 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001754 mstat = readb(eventbuf + 2);
1755 lstat = readb(eventbuf + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
1757 ch = chan0 + channel;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001758 if ((unsigned)channel >= bd->numports || !ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 if (channel >= bd->numports)
1760 ch = chan0;
1761 bc = ch->brdchan;
1762 goto next;
1763 }
1764
1765 if ((bc = ch->brdchan) == NULL)
1766 goto next;
1767
Alan Coxf2cf8e22005-09-06 15:16:44 -07001768 if (event & DATA_IND) { /* Begin DATA_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 receive_data(ch);
1770 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 } /* End DATA_IND */
1772 /* else *//* Fix for DCD transition missed bug */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001773 if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 /* A modem signal change has been indicated */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 ch->imodem = mstat;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001776 if (ch->asyncflags & ASYNC_CHECK_CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 if (mstat & ch->dcd) /* We are now receiving dcd */
1778 wake_up_interruptible(&ch->open_wait);
1779 else
1780 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 } /* End MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 tty = ch->tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001784 if (tty) { /* Begin if valid tty */
1785 if (event & BREAK_IND) { /* Begin if BREAK_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 /* A break has been indicated */
Alan Cox33f0f882006-01-09 20:54:13 -08001787 tty_insert_flip_char(tty, 0, TTY_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 tty_schedule_flip(tty);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001789 } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 if (ch->statusflags & LOWWAIT)
1791 { /* Begin if LOWWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 ch->statusflags &= ~LOWWAIT;
1793 tty_wakeup(tty);
1794 wake_up_interruptible(&tty->write_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 } /* End if LOWWAIT */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001796 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 /* This event is generated by setup_empty_event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 ch->statusflags &= ~TXBUSY;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001799 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ch->statusflags &= ~EMPTYWAIT;
1801 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 wake_up_interruptible(&tty->write_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 } /* End if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 } /* End EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 } /* End if valid tty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 next:
1807 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001808 BUG_ON(!bc);
1809 writew(1, &bc->idata);
1810 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 globalwinon(chan0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 } /* End while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813} /* End doevent */
1814
1815/* --------------------- Begin fepcmd ------------------------ */
1816
1817static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1818 int byte2, int ncmds, int bytecmd)
1819{ /* Begin fepcmd */
Al Virobc9a5152005-09-15 22:53:28 +01001820 unchar __iomem *memaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 unsigned int head, cmdTail, cmdStart, cmdMax;
1822 long count;
1823 int n;
1824
1825 /* This is the routine in which commands may be passed to the card. */
1826
1827 if (ch->board->status == DISABLED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 /* Remember head (As well as max) is just an offset not a base addr */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001831 head = readw(&ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 /* cmdStart is a base address */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001833 cmdStart = readw(&ch->mailbox->cstart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 /* ------------------------------------------------------------------
1835 We do the addition below because we do not want a max pointer
1836 relative to cmdStart. We want a max pointer that points at the
1837 physical end of the command queue.
1838 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001839 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 memaddr = ch->board->re_map_membase;
1841
Alan Coxf2cf8e22005-09-06 15:16:44 -07001842 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1843 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1844 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 return;
1846 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001847 if (bytecmd) {
1848 writeb(cmd, memaddr + head + cmdStart + 0);
1849 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 /* Below word_or_byte is bits to set */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001851 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 /* Below byte2 is bits to reset */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001853 writeb(byte2, memaddr + head + cmdStart + 3);
1854 } else {
1855 writeb(cmd, memaddr + head + cmdStart + 0);
1856 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1857 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 head = (head + 4) & (cmdMax - cmdStart - 4);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001860 writew(head, &ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 count = FEPTIMEOUT;
1862
Alan Coxf2cf8e22005-09-06 15:16:44 -07001863 for (;;) { /* Begin forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 count--;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001865 if (count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1867 return;
1868 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001869 head = readw(&ch->mailbox->cin);
1870 cmdTail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 /* ----------------------------------------------------------
1873 Basically this will break when the FEP acknowledges the
1874 command by incrementing cmdTail (Making it equal to head).
1875 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 if (n <= ncmds * (sizeof(short) * 4))
1877 break; /* Well nearly forever :-) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 } /* End forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879} /* End fepcmd */
1880
1881/* ---------------------------------------------------------------------
1882 Digi products use fields in their channels structures that are very
1883 similar to the c_cflag and c_iflag fields typically found in UNIX
1884 termios structures. The below three routines allow mappings
1885 between these hardware "flags" and their respective Linux flags.
1886------------------------------------------------------------------------- */
1887
1888/* --------------------- Begin termios2digi_h -------------------- */
1889
1890static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1891{ /* Begin termios2digi_h */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 unsigned res = 0;
1893
Alan Coxf2cf8e22005-09-06 15:16:44 -07001894 if (cflag & CRTSCTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1896 res |= ((ch->m_cts) | (ch->m_rts));
1897 }
1898
1899 if (ch->digiext.digi_flags & RTSPACE)
1900 res |= ch->m_rts;
1901
1902 if (ch->digiext.digi_flags & DTRPACE)
1903 res |= ch->m_dtr;
1904
1905 if (ch->digiext.digi_flags & CTSPACE)
1906 res |= ch->m_cts;
1907
1908 if (ch->digiext.digi_flags & DSRPACE)
1909 res |= ch->dsr;
1910
1911 if (ch->digiext.digi_flags & DCDPACE)
1912 res |= ch->dcd;
1913
1914 if (res & (ch->m_rts))
1915 ch->digiext.digi_flags |= RTSPACE;
1916
1917 if (res & (ch->m_cts))
1918 ch->digiext.digi_flags |= CTSPACE;
1919
1920 return res;
1921
1922} /* End termios2digi_h */
1923
1924/* --------------------- Begin termios2digi_i -------------------- */
1925static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1926{ /* Begin termios2digi_i */
1927
1928 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1929 INPCK | ISTRIP|IXON|IXANY|IXOFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (ch->digiext.digi_flags & DIGI_AIXON)
1931 res |= IAIXON;
1932 return res;
1933
1934} /* End termios2digi_i */
1935
1936/* --------------------- Begin termios2digi_c -------------------- */
1937
1938static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1939{ /* Begin termios2digi_c */
1940
1941 unsigned res = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001942 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 ch->digiext.digi_flags |= DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 /* -------------------------------------------------------------
1945 HUPCL bit is used by FEP to indicate fast baud
1946 table is to be used.
1947 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 res |= FEP_HUPCL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 } /* End detected CBAUDEX */
1950 else ch->digiext.digi_flags &= ~DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 /* -------------------------------------------------------------------
1952 CBAUD has bit position 0x1000 set these days to indicate Linux
1953 baud rate remap. Digi hardware can't handle the bit assignment.
1954 (We use a different bit assignment for high speed.). Clear this
1955 bit out.
1956 ---------------------------------------------------------------------- */
1957 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 /* -------------------------------------------------------------
1959 This gets a little confusing. The Digi cards have their own
1960 representation of c_cflags controling baud rate. For the most
1961 part this is identical to the Linux implementation. However;
1962 Digi supports one rate (76800) that Linux doesn't. This means
1963 that the c_cflag entry that would normally mean 76800 for Digi
1964 actually means 115200 under Linux. Without the below mapping,
1965 a stty 115200 would only drive the board at 76800. Since
1966 the rate 230400 is also found after 76800, the same problem afflicts
1967 us when we choose a rate of 230400. Without the below modificiation
1968 stty 230400 would actually give us 115200.
1969
1970 There are two additional differences. The Linux value for CLOCAL
1971 (0x800; 0004000) has no meaning to the Digi hardware. Also in
1972 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
1973 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
1974 should be checked for a screened out prior to termios2digi_c
1975 returning. Since CLOCAL isn't used by the board this can be
1976 ignored as long as the returned value is used only by Digi hardware.
Alan Coxf2cf8e22005-09-06 15:16:44 -07001977 ----------------------------------------------------------------- */
1978 if (cflag & CBAUDEX) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 /* -------------------------------------------------------------
1980 The below code is trying to guarantee that only baud rates
1981 115200 and 230400 are remapped. We use exclusive or because
1982 the various baud rates share common bit positions and therefore
1983 can't be tested for easily.
1984 ----------------------------------------------------------------- */
1985
1986
1987 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1988 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 res += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return res;
1992
1993} /* End termios2digi_c */
1994
1995/* --------------------- Begin epcaparam ----------------------- */
1996
Alan Coxf2cf8e22005-09-06 15:16:44 -07001997/* Caller must hold the locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998static void epcaparam(struct tty_struct *tty, struct channel *ch)
1999{ /* Begin epcaparam */
2000
2001 unsigned int cmdHead;
2002 struct termios *ts;
Al Virobc9a5152005-09-15 22:53:28 +01002003 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 unsigned mval, hflow, cflag, iflag;
2005
2006 bc = ch->brdchan;
2007 epcaassert(bc !=0, "bc out of range");
2008
2009 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 ts = tty->termios;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002011 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2012 cmdHead = readw(&bc->rin);
Al Virobc9a5152005-09-15 22:53:28 +01002013 writew(cmdHead, &bc->rout);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002014 cmdHead = readw(&bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 /* Changing baud in mid-stream transmission can be wonderful */
2016 /* ---------------------------------------------------------------
2017 Flush current transmit buffer by setting cmdTail pointer (tout)
2018 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2019 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2021 mval = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002022 } else { /* Begin CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 /* -------------------------------------------------------------------
2024 c_cflags have changed but that change had nothing to do with BAUD.
2025 Propagate the change to the card.
2026 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 cflag = termios2digi_c(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002028 if (cflag != ch->fepcflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 ch->fepcflag = cflag;
2030 /* Set baud rate, char size, stop bits, parity */
2031 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 /* ----------------------------------------------------------------
2034 If the user has not forced CLOCAL and if the device is not a
2035 CALLOUT device (Which is always CLOCAL) we set flags such that
2036 the driver will wait on carrier detect.
2037 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 if (ts->c_cflag & CLOCAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 ch->asyncflags &= ~ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 ch->asyncflags |= ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 mval = ch->m_dtr | ch->m_rts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 } /* End CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 iflag = termios2digi_i(ch, ts->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 /* Check input mode flags */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002046 if (iflag != ch->fepiflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 ch->fepiflag = iflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 /* ---------------------------------------------------------------
2049 Command sets channels iflag structure on the board. Such things
2050 as input soft flow control, handling of parity errors, and
2051 break handling are all set here.
2052 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 /* break handling, parity handling, input stripping, flow control chars */
2054 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 /* ---------------------------------------------------------------
2057 Set the board mint value for this channel. This will cause hardware
2058 events to be generated each time the DCD signal (Described in mint)
2059 changes.
2060 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002061 writeb(ch->dcd, &bc->mint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2063 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002064 writeb(0, &bc->mint);
2065 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 hflow = termios2digi_h(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002067 if (hflow != ch->hflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 ch->hflow = hflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 /* --------------------------------------------------------------
2070 Hard flow control has been selected but the board is not
2071 using it. Activate hard flow control now.
2072 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 mval ^= ch->modemfake & (mval ^ ch->modem);
2076
Alan Coxf2cf8e22005-09-06 15:16:44 -07002077 if (ch->omodem ^ mval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 ch->omodem = mval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 /* --------------------------------------------------------------
2080 The below command sets the DTR and RTS mstat structure. If
2081 hard flow control is NOT active these changes will drive the
2082 output of the actual DTR and RTS lines. If hard flow control
2083 is active, the changes will be saved in the mstat structure and
2084 only asserted when hard flow control is turned off.
2085 ----------------------------------------------------------------- */
2086
2087 /* First reset DTR & RTS; then set them */
2088 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2089 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002091 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 ch->fepstartc = ch->startc;
2093 ch->fepstopc = ch->stopc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 /* ------------------------------------------------------------
2095 The XON / XOFF characters have changed; propagate these
2096 changes to the card.
2097 --------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2099 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002100 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 ch->fepstartca = ch->startca;
2102 ch->fepstopca = ch->stopca;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 /* ---------------------------------------------------------------
2104 Similar to the above, this time the auxilarly XON / XOFF
2105 characters have changed; propagate these changes to the card.
2106 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2108 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109} /* End epcaparam */
2110
2111/* --------------------- Begin receive_data ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002112/* Caller holds lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113static void receive_data(struct channel *ch)
2114{ /* Begin receive_data */
2115
2116 unchar *rptr;
2117 struct termios *ts = NULL;
2118 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +01002119 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002120 int dataToRead, wrapgap, bytesAvailable;
2121 unsigned int tail, head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 unsigned int wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 /* ---------------------------------------------------------------
2125 This routine is called by doint when a receive data event
2126 has taken place.
2127 ------------------------------------------------------------------- */
2128
2129 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 if (ch->statusflags & RXSTOPPED)
2131 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 tty = ch->tty;
2133 if (tty)
2134 ts = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002136 BUG_ON(!bc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 wrapmask = ch->rxbufsize - 1;
2138
2139 /* ---------------------------------------------------------------------
2140 Get the head and tail pointers to the receiver queue. Wrap the
2141 head pointer if it has reached the end of the buffer.
2142 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002143 head = readw(&bc->rin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 head &= wrapmask;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002145 tail = readw(&bc->rout) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
2147 bytesAvailable = (head - tail) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 if (bytesAvailable == 0)
2149 return;
2150
2151 /* ------------------------------------------------------------------
2152 If CREAD bit is off or device not open, set TX tail to head
2153 --------------------------------------------------------------------- */
2154
Alan Coxf2cf8e22005-09-06 15:16:44 -07002155 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
Al Virobc9a5152005-09-15 22:53:28 +01002156 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 return;
2158 }
2159
Alan Cox33f0f882006-01-09 20:54:13 -08002160 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 return;
2162
Alan Coxf2cf8e22005-09-06 15:16:44 -07002163 if (readb(&bc->orun)) {
2164 writeb(0, &bc->orun);
2165 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
Alan Cox33f0f882006-01-09 20:54:13 -08002166 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 rxwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002169 while (bytesAvailable > 0) { /* Begin while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 /* ---------------------------------------------------------------
2172 Even if head has wrapped around only report the amount of
2173 data to be equal to the size - tail. Remember memcpy can't
2174 automaticly wrap around the receive buffer.
2175 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 /* --------------------------------------------------------------
2178 Make sure we don't overflow the buffer
2179 ----------------------------------------------------------------- */
Alan Cox33f0f882006-01-09 20:54:13 -08002180 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 if (dataToRead == 0)
2182 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 /* ---------------------------------------------------------------
2184 Move data read from our card into the line disciplines buffer
2185 for translation if necessary.
2186 ------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002187 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 tail = (tail + dataToRead) & wrapmask;
2189 bytesAvailable -= dataToRead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 } /* End while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002192 writew(tail, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 /* Must be called with global data */
2194 tty_schedule_flip(ch->tty);
2195 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196} /* End receive_data */
2197
2198static int info_ioctl(struct tty_struct *tty, struct file * file,
2199 unsigned int cmd, unsigned long arg)
2200{
2201 switch (cmd)
2202 { /* Begin switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 case DIGI_GETINFO:
2204 { /* Begin case DIGI_GETINFO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 struct digi_info di ;
2206 int brd;
2207
Alan Coxf2cf8e22005-09-06 15:16:44 -07002208 if(get_user(brd, (unsigned int __user *)arg))
2209 return -EFAULT;
2210 if (brd < 0 || brd >= num_cards || num_cards == 0)
2211 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
2213 memset(&di, 0, sizeof(di));
2214
2215 di.board = brd ;
2216 di.status = boards[brd].status;
2217 di.type = boards[brd].type ;
2218 di.numports = boards[brd].numports ;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002219 /* Legacy fixups - just move along nothing to see */
2220 di.port = (unsigned char *)boards[brd].port ;
2221 di.membase = (unsigned char *)boards[brd].membase ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
2223 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2224 return -EFAULT;
2225 break;
2226
2227 } /* End case DIGI_GETINFO */
2228
2229 case DIGI_POLLER:
2230 { /* Begin case DIGI_POLLER */
2231
2232 int brd = arg & 0xff000000 >> 16 ;
2233 unsigned char state = arg & 0xff ;
2234
Alan Coxf2cf8e22005-09-06 15:16:44 -07002235 if (brd < 0 || brd >= num_cards) {
2236 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 return (-ENODEV);
2238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 digi_poller_inhibited = state ;
2240 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 } /* End case DIGI_POLLER */
2242
2243 case DIGI_INIT:
2244 { /* Begin case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 /* ------------------------------------------------------------
2246 This call is made by the apps to complete the initilization
2247 of the board(s). This routine is responsible for setting
2248 the card to its initial state and setting the drivers control
2249 fields to the sutianle settings for the card in question.
2250 ---------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 int crd ;
2252 for (crd = 0; crd < num_cards; crd++)
2253 post_fep_init (crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 } /* End case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002257 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 } /* End switch cmd */
2259 return (0) ;
2260}
2261/* --------------------- Begin pc_ioctl ----------------------- */
2262
2263static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2264{
2265 struct channel *ch = (struct channel *) tty->driver_data;
Al Virobc9a5152005-09-15 22:53:28 +01002266 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 unsigned int mstat, mflag = 0;
2268 unsigned long flags;
2269
2270 if (ch)
2271 bc = ch->brdchan;
2272 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002273 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Alan Coxf2cf8e22005-09-06 15:16:44 -07002275 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002277 mstat = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002279 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 if (mstat & ch->m_dtr)
2282 mflag |= TIOCM_DTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 if (mstat & ch->m_rts)
2284 mflag |= TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 if (mstat & ch->m_cts)
2286 mflag |= TIOCM_CTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 if (mstat & ch->dsr)
2288 mflag |= TIOCM_DSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 if (mstat & ch->m_ri)
2290 mflag |= TIOCM_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 if (mstat & ch->dcd)
2292 mflag |= TIOCM_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 return mflag;
2294}
2295
2296static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2297 unsigned int set, unsigned int clear)
2298{
2299 struct channel *ch = (struct channel *) tty->driver_data;
2300 unsigned long flags;
2301
Alan Coxf2cf8e22005-09-06 15:16:44 -07002302 if (!ch)
2303 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
Alan Coxf2cf8e22005-09-06 15:16:44 -07002305 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 /*
2307 * I think this modemfake stuff is broken. It doesn't
2308 * correctly reflect the behaviour desired by the TIOCM*
2309 * ioctls. Therefore this is probably broken.
2310 */
2311 if (set & TIOCM_RTS) {
2312 ch->modemfake |= ch->m_rts;
2313 ch->modem |= ch->m_rts;
2314 }
2315 if (set & TIOCM_DTR) {
2316 ch->modemfake |= ch->m_dtr;
2317 ch->modem |= ch->m_dtr;
2318 }
2319 if (clear & TIOCM_RTS) {
2320 ch->modemfake |= ch->m_rts;
2321 ch->modem &= ~ch->m_rts;
2322 }
2323 if (clear & TIOCM_DTR) {
2324 ch->modemfake |= ch->m_dtr;
2325 ch->modem &= ~ch->m_dtr;
2326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 /* --------------------------------------------------------------
2329 The below routine generally sets up parity, baud, flow control
2330 issues, etc.... It effect both control flags and input flags.
2331 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 epcaparam(tty,ch);
2333 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002334 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 return 0;
2336}
2337
2338static int pc_ioctl(struct tty_struct *tty, struct file * file,
2339 unsigned int cmd, unsigned long arg)
2340{ /* Begin pc_ioctl */
2341
2342 digiflow_t dflow;
2343 int retval;
2344 unsigned long flags;
2345 unsigned int mflag, mstat;
2346 unsigned char startc, stopc;
Al Virobc9a5152005-09-15 22:53:28 +01002347 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 struct channel *ch = (struct channel *) tty->driver_data;
2349 void __user *argp = (void __user *)arg;
2350
2351 if (ch)
2352 bc = ch->brdchan;
2353 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002354 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 /* -------------------------------------------------------------------
2357 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2358 in /usr/src/linux/drivers/char for a good example. In particular
2359 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2360 ---------------------------------------------------------------------- */
2361
2362 switch (cmd)
2363 { /* Begin switch cmd */
2364
2365 case TCGETS:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002366 if (copy_to_user(argp, tty->termios, sizeof(struct termios)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 return -EFAULT;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002368 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 case TCGETA:
2370 return get_termio(tty, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 case TCSBRK: /* SVID version: non-zero arg --> no break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 retval = tty_check_change(tty);
2373 if (retval)
2374 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002376 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002378 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 tty_wait_until_sent(tty, 0);
2380 if (!arg)
2381 digi_send_break(ch, HZ/4); /* 1/4 second */
2382 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 case TCSBRKP: /* support for POSIX tcsendbreak() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 retval = tty_check_change(tty);
2385 if (retval)
2386 return retval;
2387
2388 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002389 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002391 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 tty_wait_until_sent(tty, 0);
2393 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2394 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 case TIOCGSOFTCAR:
2396 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2397 return -EFAULT;
2398 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 case TIOCSSOFTCAR:
2400 {
2401 unsigned int value;
2402
2403 if (get_user(value, (unsigned __user *)argp))
2404 return -EFAULT;
2405 tty->termios->c_cflag =
2406 ((tty->termios->c_cflag & ~CLOCAL) |
2407 (value ? CLOCAL : 0));
2408 return 0;
2409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 case TIOCMODG:
2411 mflag = pc_tiocmget(tty, file);
2412 if (put_user(mflag, (unsigned long __user *)argp))
2413 return -EFAULT;
2414 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 case TIOCMODS:
2416 if (get_user(mstat, (unsigned __user *)argp))
2417 return -EFAULT;
2418 return pc_tiocmset(tty, file, mstat, ~mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 case TIOCSDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002420 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 ch->omodem |= ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 globalwinon(ch);
2423 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2424 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002425 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 break;
2427
2428 case TIOCCDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002429 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 ch->omodem &= ~ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 globalwinon(ch);
2432 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2433 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002434 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 case DIGI_GETA:
2437 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2438 return -EFAULT;
2439 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 case DIGI_SETAW:
2441 case DIGI_SETAF:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002442 if (cmd == DIGI_SETAW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002444 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002446 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 tty_wait_until_sent(tty, 0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002448 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 /* ldisc lock already held in ioctl */
2450 if (tty->ldisc.flush_buffer)
2451 tty->ldisc.flush_buffer(tty);
2452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 /* Fall Thru */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 case DIGI_SETA:
2455 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2456 return -EFAULT;
2457
Alan Coxf2cf8e22005-09-06 15:16:44 -07002458 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 ch->dcd = ch->m_dsr;
2460 ch->dsr = ch->m_dcd;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002461 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 ch->dcd = ch->m_dcd;
2463 ch->dsr = ch->m_dsr;
2464 }
2465
Alan Coxf2cf8e22005-09-06 15:16:44 -07002466 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 globalwinon(ch);
2468
2469 /* -----------------------------------------------------------------
2470 The below routine generally sets up parity, baud, flow control
2471 issues, etc.... It effect both control flags and input flags.
2472 ------------------------------------------------------------------- */
2473
2474 epcaparam(tty,ch);
2475 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002476 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 break;
2478
2479 case DIGI_GETFLOW:
2480 case DIGI_GETAFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002481 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002483 if (cmd == DIGI_GETFLOW) {
2484 dflow.startc = readb(&bc->startc);
2485 dflow.stopc = readb(&bc->stopc);
2486 } else {
2487 dflow.startc = readb(&bc->startca);
2488 dflow.stopc = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 }
2490 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002491 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
2493 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2494 return -EFAULT;
2495 break;
2496
2497 case DIGI_SETAFLOW:
2498 case DIGI_SETFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002499 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 startc = ch->startc;
2501 stopc = ch->stopc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002502 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 startc = ch->startca;
2504 stopc = ch->stopca;
2505 }
2506
2507 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2508 return -EFAULT;
2509
Alan Coxf2cf8e22005-09-06 15:16:44 -07002510 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2511 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 globalwinon(ch);
2513
Alan Coxf2cf8e22005-09-06 15:16:44 -07002514 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 ch->fepstartc = ch->startc = dflow.startc;
2516 ch->fepstopc = ch->stopc = dflow.stopc;
2517 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002518 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 ch->fepstartca = ch->startca = dflow.startc;
2520 ch->fepstopca = ch->stopca = dflow.stopc;
2521 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2522 }
2523
Alan Coxf2cf8e22005-09-06 15:16:44 -07002524 if (ch->statusflags & TXSTOPPED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 pc_start(tty);
2526
2527 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002528 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 } /* End if setflow toggled */
2530 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 default:
2532 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 } /* End switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535} /* End pc_ioctl */
2536
2537/* --------------------- Begin pc_set_termios ----------------------- */
2538
2539static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
2540{ /* Begin pc_set_termios */
2541
2542 struct channel *ch;
2543 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 /* ---------------------------------------------------------
2545 verifyChannel returns the channel from the tty struct
2546 if it is valid. This serves as a sanity check.
2547 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002548 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2549 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 globalwinon(ch);
2551 epcaparam(tty, ch);
2552 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002553 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
2555 if ((old_termios->c_cflag & CRTSCTS) &&
2556 ((tty->termios->c_cflag & CRTSCTS) == 0))
2557 tty->hw_stopped = 0;
2558
2559 if (!(old_termios->c_cflag & CLOCAL) &&
2560 (tty->termios->c_cflag & CLOCAL))
2561 wake_up_interruptible(&ch->open_wait);
2562
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 } /* End if channel valid */
2564
2565} /* End pc_set_termios */
2566
2567/* --------------------- Begin do_softint ----------------------- */
2568
David Howellsc4028952006-11-22 14:57:56 +00002569static void do_softint(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570{ /* Begin do_softint */
David Howellsc4028952006-11-22 14:57:56 +00002571 struct channel *ch = container_of(work, struct channel, tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 /* Called in response to a modem change event */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002573 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 struct tty_struct *tty = ch->tty;
2575
Alan Coxf2cf8e22005-09-06 15:16:44 -07002576 if (tty && tty->driver_data) {
2577 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2579 wake_up_interruptible(&ch->open_wait);
2580 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 } /* End if clear_bit */
2582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 } /* End EPCA_MAGIC */
2584} /* End do_softint */
2585
2586/* ------------------------------------------------------------
2587 pc_stop and pc_start provide software flow control to the
2588 routine and the pc_ioctl routine.
2589---------------------------------------------------------------- */
2590
2591/* --------------------- Begin pc_stop ----------------------- */
2592
2593static void pc_stop(struct tty_struct *tty)
2594{ /* Begin pc_stop */
2595
2596 struct channel *ch;
2597 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 /* ---------------------------------------------------------
2599 verifyChannel returns the channel from the tty struct
2600 if it is valid. This serves as a sanity check.
2601 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002602 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
2603 spin_lock_irqsave(&epca_lock, flags);
2604 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 /* STOP transmitting now !! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 ch->statusflags |= TXSTOPPED;
2609 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 } /* End if transmit stop requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002611 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 } /* End if valid channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613} /* End pc_stop */
2614
2615/* --------------------- Begin pc_start ----------------------- */
2616
2617static void pc_start(struct tty_struct *tty)
2618{ /* Begin pc_start */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 /* ---------------------------------------------------------
2621 verifyChannel returns the channel from the tty struct
2622 if it is valid. This serves as a sanity check.
2623 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002624 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002626 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002628 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
Al Virobc9a5152005-09-15 22:53:28 +01002629 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 globalwinon(ch);
2631 bc = ch->brdchan;
2632 if (ch->statusflags & LOWWAIT)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002633 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 /* Okay, you can start transmitting again... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 ch->statusflags &= ~TXSTOPPED;
2637 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 } /* End transmit resume requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002639 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641} /* End pc_start */
2642
2643/* ------------------------------------------------------------------
2644 The below routines pc_throttle and pc_unthrottle are used
2645 to slow (And resume) the receipt of data into the kernels
2646 receive buffers. The exact occurrence of this depends on the
2647 size of the kernels receive buffer and what the 'watermarks'
2648 are set to for that buffer. See the n_ttys.c file for more
2649 details.
2650______________________________________________________________________ */
2651/* --------------------- Begin throttle ----------------------- */
2652
2653static void pc_throttle(struct tty_struct * tty)
2654{ /* Begin pc_throttle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 struct channel *ch;
2656 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 /* ---------------------------------------------------------
2658 verifyChannel returns the channel from the tty struct
2659 if it is valid. This serves as a sanity check.
2660 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002661 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2662 spin_lock_irqsave(&epca_lock, flags);
2663 if ((ch->statusflags & RXSTOPPED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 globalwinon(ch);
2665 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 ch->statusflags |= RXSTOPPED;
2667 memoff(ch);
2668 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002669 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671} /* End pc_throttle */
2672
2673/* --------------------- Begin unthrottle ----------------------- */
2674
2675static void pc_unthrottle(struct tty_struct *tty)
2676{ /* Begin pc_unthrottle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 struct channel *ch;
2678 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 /* ---------------------------------------------------------
2680 verifyChannel returns the channel from the tty struct
2681 if it is valid. This serves as a sanity check.
2682 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002683 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002685 spin_lock_irqsave(&epca_lock, flags);
2686 if (ch->statusflags & RXSTOPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 ch->statusflags &= ~RXSTOPPED;
2690 memoff(ch);
2691 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002692 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694} /* End pc_unthrottle */
2695
2696/* --------------------- Begin digi_send_break ----------------------- */
2697
2698void digi_send_break(struct channel *ch, int msec)
2699{ /* Begin digi_send_break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 unsigned long flags;
2701
Alan Coxf2cf8e22005-09-06 15:16:44 -07002702 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 /* --------------------------------------------------------------------
2705 Maybe I should send an infinite break here, schedule() for
2706 msec amount of time, and then stop the break. This way,
2707 the user can't screw up the FEP by causing digi_send_break()
2708 to be called (i.e. via an ioctl()) more than once in msec amount
2709 of time. Try this for now...
2710 ------------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2712 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002713 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714} /* End digi_send_break */
2715
2716/* --------------------- Begin setup_empty_event ----------------------- */
2717
Alan Coxf2cf8e22005-09-06 15:16:44 -07002718/* Caller MUST hold the lock */
2719
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2721{ /* Begin setup_empty_event */
2722
Al Virobc9a5152005-09-15 22:53:28 +01002723 struct board_chan __iomem *bc = ch->brdchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 globalwinon(ch);
2726 ch->statusflags |= EMPTYWAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 /* ------------------------------------------------------------------
2728 When set the iempty flag request a event to be generated when the
2729 transmit buffer is empty (If there is no BREAK in progress).
2730 --------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002731 writeb(1, &bc->iempty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733} /* End setup_empty_event */
2734
2735/* --------------------- Begin get_termio ----------------------- */
2736
2737static int get_termio(struct tty_struct * tty, struct termio __user * termio)
2738{ /* Begin get_termio */
2739 return kernel_termios_to_user_termio(termio, tty->termios);
2740} /* End get_termio */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002741
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742/* ---------------------- Begin epca_setup -------------------------- */
2743void epca_setup(char *str, int *ints)
2744{ /* Begin epca_setup */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 struct board_info board;
2746 int index, loop, last;
2747 char *temp, *t2;
2748 unsigned len;
2749
2750 /* ----------------------------------------------------------------------
2751 If this routine looks a little strange it is because it is only called
2752 if a LILO append command is given to boot the kernel with parameters.
2753 In this way, we can provide the user a method of changing his board
2754 configuration without rebuilding the kernel.
2755 ----------------------------------------------------------------------- */
2756 if (!liloconfig)
2757 liloconfig = 1;
2758
2759 memset(&board, 0, sizeof(board));
2760
2761 /* Assume the data is int first, later we can change it */
2762 /* I think that array position 0 of ints holds the number of args */
2763 for (last = 0, index = 1; index <= ints[0]; index++)
2764 switch(index)
2765 { /* Begin parse switch */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 case 1:
2767 board.status = ints[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 /* ---------------------------------------------------------
2769 We check for 2 (As opposed to 1; because 2 is a flag
2770 instructing the driver to ignore epcaconfig.) For this
2771 reason we check for 2.
2772 ------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002773 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 nbdevs = 0;
2775 num_cards = 0;
2776 return;
2777 } /* End ignore epcaconfig as well as lilo cmd line */
2778
Alan Coxf2cf8e22005-09-06 15:16:44 -07002779 if (board.status > 2) {
2780 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 invalid_lilo_config = 1;
2782 setup_error_code |= INVALID_BOARD_STATUS;
2783 return;
2784 }
2785 last = index;
2786 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 case 2:
2788 board.type = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002789 if (board.type >= PCIXEM) {
2790 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 invalid_lilo_config = 1;
2792 setup_error_code |= INVALID_BOARD_TYPE;
2793 return;
2794 }
2795 last = index;
2796 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 case 3:
2798 board.altpin = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002799 if (board.altpin > 1) {
2800 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 invalid_lilo_config = 1;
2802 setup_error_code |= INVALID_ALTPIN;
2803 return;
2804 }
2805 last = index;
2806 break;
2807
2808 case 4:
2809 board.numports = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002810 if (board.numports < 2 || board.numports > 256) {
2811 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 invalid_lilo_config = 1;
2813 setup_error_code |= INVALID_NUM_PORTS;
2814 return;
2815 }
2816 nbdevs += board.numports;
2817 last = index;
2818 break;
2819
2820 case 5:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002821 board.port = ints[index];
2822 if (ints[index] <= 0) {
2823 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 invalid_lilo_config = 1;
2825 setup_error_code |= INVALID_PORT_BASE;
2826 return;
2827 }
2828 last = index;
2829 break;
2830
2831 case 6:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002832 board.membase = ints[index];
2833 if (ints[index] <= 0) {
2834 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 invalid_lilo_config = 1;
2836 setup_error_code |= INVALID_MEM_BASE;
2837 return;
2838 }
2839 last = index;
2840 break;
2841
2842 default:
2843 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2844 return;
2845
2846 } /* End parse switch */
2847
Alan Coxf2cf8e22005-09-06 15:16:44 -07002848 while (str && *str) { /* Begin while there is a string arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 /* find the next comma or terminator */
2850 temp = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 /* While string is not null, and a comma hasn't been found */
2852 while (*temp && (*temp != ','))
2853 temp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 if (!*temp)
2855 temp = NULL;
2856 else
2857 *temp++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 /* Set index to the number of args + 1 */
2859 index = last + 1;
2860
2861 switch(index)
2862 {
2863 case 1:
2864 len = strlen(str);
2865 if (strncmp("Disable", str, len) == 0)
2866 board.status = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002867 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 board.status = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002869 else {
2870 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 invalid_lilo_config = 1;
2872 setup_error_code |= INVALID_BOARD_STATUS;
2873 return;
2874 }
2875 last = index;
2876 break;
2877
2878 case 2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
2880 if (strcmp(board_desc[loop], str) == 0)
2881 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 /* ---------------------------------------------------------------
2883 If the index incremented above refers to a legitamate board
2884 type set it here.
2885 ------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 if (index < EPCA_NUM_TYPES)
2887 board.type = loop;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002888 else {
2889 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 invalid_lilo_config = 1;
2891 setup_error_code |= INVALID_BOARD_TYPE;
2892 return;
2893 }
2894 last = index;
2895 break;
2896
2897 case 3:
2898 len = strlen(str);
2899 if (strncmp("Disable", str, len) == 0)
2900 board.altpin = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002901 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 board.altpin = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002903 else {
2904 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 invalid_lilo_config = 1;
2906 setup_error_code |= INVALID_ALTPIN;
2907 return;
2908 }
2909 last = index;
2910 break;
2911
2912 case 4:
2913 t2 = str;
2914 while (isdigit(*t2))
2915 t2++;
2916
Alan Coxf2cf8e22005-09-06 15:16:44 -07002917 if (*t2) {
2918 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 invalid_lilo_config = 1;
2920 setup_error_code |= INVALID_NUM_PORTS;
2921 return;
2922 }
2923
2924 /* ------------------------------------------------------------
2925 There is not a man page for simple_strtoul but the code can be
2926 found in vsprintf.c. The first argument is the string to
2927 translate (To an unsigned long obviously), the second argument
2928 can be the address of any character variable or a NULL. If a
2929 variable is given, the end pointer of the string will be stored
2930 in that variable; if a NULL is given the end pointer will
2931 not be returned. The last argument is the base to use. If
2932 a 0 is indicated, the routine will attempt to determine the
2933 proper base by looking at the values prefix (A '0' for octal,
2934 a 'x' for hex, etc ... If a value is given it will use that
2935 value as the base.
2936 ---------------------------------------------------------------- */
2937 board.numports = simple_strtoul(str, NULL, 0);
2938 nbdevs += board.numports;
2939 last = index;
2940 break;
2941
2942 case 5:
2943 t2 = str;
2944 while (isxdigit(*t2))
2945 t2++;
2946
Alan Coxf2cf8e22005-09-06 15:16:44 -07002947 if (*t2) {
2948 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 invalid_lilo_config = 1;
2950 setup_error_code |= INVALID_PORT_BASE;
2951 return;
2952 }
2953
Alan Coxf2cf8e22005-09-06 15:16:44 -07002954 board.port = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 last = index;
2956 break;
2957
2958 case 6:
2959 t2 = str;
2960 while (isxdigit(*t2))
2961 t2++;
2962
Alan Coxf2cf8e22005-09-06 15:16:44 -07002963 if (*t2) {
2964 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 invalid_lilo_config = 1;
2966 setup_error_code |= INVALID_MEM_BASE;
2967 return;
2968 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002969 board.membase = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 last = index;
2971 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002973 printk(KERN_ERR "epca: Too many string parms\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 return;
2975 }
2976 str = temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 } /* End while there is a string arg */
2978
Alan Coxf2cf8e22005-09-06 15:16:44 -07002979 if (last < 6) {
2980 printk(KERN_ERR "epca: Insufficient parms specified\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 return;
2982 }
2983
2984 /* I should REALLY validate the stuff here */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 /* Copies our local copy of board into boards */
2986 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 /* Does this get called once per lilo arg are what ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2989 num_cards, board_desc[board.type],
2990 board.numports, (int)board.port, (unsigned int) board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 num_cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992} /* End epca_setup */
2993
2994
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995/* ------------------------ Begin init_PCI --------------------------- */
2996
2997enum epic_board_types {
2998 brd_xr = 0,
2999 brd_xem,
3000 brd_cx,
3001 brd_xrj,
3002};
3003
3004
3005/* indexed directly by epic_board_types enum */
3006static struct {
3007 unsigned char board_type;
3008 unsigned bar_idx; /* PCI base address region */
3009} epca_info_tbl[] = {
3010 { PCIXR, 0, },
3011 { PCIXEM, 0, },
3012 { PCICX, 0, },
3013 { PCIXRJ, 2, },
3014};
3015
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016static int __devinit epca_init_one (struct pci_dev *pdev,
3017 const struct pci_device_id *ent)
3018{
3019 static int board_num = -1;
3020 int board_idx, info_idx = ent->driver_data;
3021 unsigned long addr;
3022
3023 if (pci_enable_device(pdev))
3024 return -EIO;
3025
3026 board_num++;
3027 board_idx = board_num + num_cards;
3028 if (board_idx >= MAXBOARDS)
3029 goto err_out;
3030
3031 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3032 if (!addr) {
3033 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3034 epca_info_tbl[info_idx].bar_idx);
3035 goto err_out;
3036 }
3037
3038 boards[board_idx].status = ENABLED;
3039 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3040 boards[board_idx].numports = 0x0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07003041 boards[board_idx].port = addr + PCI_IO_OFFSET;
3042 boards[board_idx].membase = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
3044 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3045 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3046 0x200000, addr + PCI_IO_OFFSET);
3047 goto err_out;
3048 }
3049
3050 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3051 if (!boards[board_idx].re_map_port) {
3052 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3053 0x200000, addr + PCI_IO_OFFSET);
3054 goto err_out_free_pciio;
3055 }
3056
3057 if (!request_mem_region (addr, 0x200000, "epca")) {
3058 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3059 0x200000, addr);
3060 goto err_out_free_iounmap;
3061 }
3062
3063 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3064 if (!boards[board_idx].re_map_membase) {
3065 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3066 0x200000, addr + PCI_IO_OFFSET);
3067 goto err_out_free_memregion;
3068 }
3069
3070 /* --------------------------------------------------------------
3071 I don't know what the below does, but the hardware guys say
3072 its required on everything except PLX (In this case XRJ).
3073 ---------------------------------------------------------------- */
3074 if (info_idx != brd_xrj) {
3075 pci_write_config_byte(pdev, 0x40, 0);
3076 pci_write_config_byte(pdev, 0x46, 0);
3077 }
3078
3079 return 0;
3080
3081err_out_free_memregion:
3082 release_mem_region (addr, 0x200000);
3083err_out_free_iounmap:
3084 iounmap (boards[board_idx].re_map_port);
3085err_out_free_pciio:
3086 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3087err_out:
3088 return -ENODEV;
3089}
3090
3091
3092static struct pci_device_id epca_pci_tbl[] = {
3093 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3094 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3095 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3096 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3097 { 0, }
3098};
3099
3100MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3101
3102int __init init_PCI (void)
Alan Coxf2cf8e22005-09-06 15:16:44 -07003103{ /* Begin init_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 memset (&epca_driver, 0, sizeof (epca_driver));
3105 epca_driver.name = "epca";
3106 epca_driver.id_table = epca_pci_tbl;
3107 epca_driver.probe = epca_init_one;
3108
3109 return pci_register_driver(&epca_driver);
Alan Coxf2cf8e22005-09-06 15:16:44 -07003110}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111
3112MODULE_LICENSE("GPL");