blob: 9cad8501d62c9fca6a93656c204bb1dea1e09a15 [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
33#include <linux/config.h>
34#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/types.h>
37#include <linux/init.h>
38#include <linux/serial.h>
39#include <linux/delay.h>
40#include <linux/ctype.h>
41#include <linux/tty.h>
42#include <linux/tty_flip.h>
43#include <linux/slab.h>
44#include <linux/ioport.h>
45#include <linux/interrupt.h>
46#include <asm/uaccess.h>
47#include <asm/io.h>
Alan Coxf2cf8e22005-09-06 15:16:44 -070048#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/pci.h>
50#include "digiPCI.h"
Alan Coxf2cf8e22005-09-06 15:16:44 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include "digi1.h"
54#include "digiFep1.h"
55#include "epca.h"
56#include "epcaconfig.h"
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/* ---------------------- Begin defines ------------------------ */
59
Alan Coxf2cf8e22005-09-06 15:16:44 -070060#define VERSION "1.3.0.1-LK2.6"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/* This major needs to be submitted to Linux to join the majors list */
63
64#define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
65
66
67#define MAXCARDS 7
68#define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
69
70#define PFX "epca: "
71
72/* ----------------- Begin global definitions ------------------- */
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static int nbdevs, num_cards, liloconfig;
75static int digi_poller_inhibited = 1 ;
76
77static int setup_error_code;
78static int invalid_lilo_config;
79
Alan Coxf2cf8e22005-09-06 15:16:44 -070080/* The ISA boards do window flipping into the same spaces so its only sane
81 with a single lock. It's still pretty efficient */
82
83static spinlock_t epca_lock = SPIN_LOCK_UNLOCKED;
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* -----------------------------------------------------------------------
86 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
87 7 below.
88--------------------------------------------------------------------------*/
89static struct board_info boards[MAXBOARDS];
90
91
92/* ------------- Begin structures used for driver registeration ---------- */
93
94static struct tty_driver *pc_driver;
95static struct tty_driver *pc_info;
96
97/* ------------------ Begin Digi specific structures -------------------- */
98
99/* ------------------------------------------------------------------------
100 digi_channels represents an array of structures that keep track of
101 each channel of the Digi product. Information such as transmit and
102 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
103 are stored here. This structure is NOT used to overlay the cards
104 physical channel structure.
105-------------------------------------------------------------------------- */
106
107static struct channel digi_channels[MAX_ALLOC];
108
109/* ------------------------------------------------------------------------
110 card_ptr is an array used to hold the address of the
111 first channel structure of each card. This array will hold
112 the addresses of various channels located in digi_channels.
113-------------------------------------------------------------------------- */
114static struct channel *card_ptr[MAXCARDS];
115
116static struct timer_list epca_timer;
117
118/* ---------------------- Begin function prototypes --------------------- */
119
120/* ----------------------------------------------------------------------
121 Begin generic memory functions. These functions will be alias
122 (point at) more specific functions dependent on the board being
123 configured.
124----------------------------------------------------------------------- */
125
Alan Coxf2cf8e22005-09-06 15:16:44 -0700126static void memwinon(struct board_info *b, unsigned int win);
127static void memwinoff(struct board_info *b, unsigned int win);
128static void globalwinon(struct channel *ch);
129static void rxwinon(struct channel *ch);
130static void txwinon(struct channel *ch);
131static void memoff(struct channel *ch);
132static void assertgwinon(struct channel *ch);
133static void assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/* ---- Begin more 'specific' memory functions for cx_like products --- */
136
Alan Coxf2cf8e22005-09-06 15:16:44 -0700137static void pcxem_memwinon(struct board_info *b, unsigned int win);
138static void pcxem_memwinoff(struct board_info *b, unsigned int win);
139static void pcxem_globalwinon(struct channel *ch);
140static void pcxem_rxwinon(struct channel *ch);
141static void pcxem_txwinon(struct channel *ch);
142static void pcxem_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144/* ------ Begin more 'specific' memory functions for the pcxe ------- */
145
Alan Coxf2cf8e22005-09-06 15:16:44 -0700146static void pcxe_memwinon(struct board_info *b, unsigned int win);
147static void pcxe_memwinoff(struct board_info *b, unsigned int win);
148static void pcxe_globalwinon(struct channel *ch);
149static void pcxe_rxwinon(struct channel *ch);
150static void pcxe_txwinon(struct channel *ch);
151static void pcxe_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
154/* Note : pc64xe and pcxi share the same windowing routines */
155
Alan Coxf2cf8e22005-09-06 15:16:44 -0700156static void pcxi_memwinon(struct board_info *b, unsigned int win);
157static void pcxi_memwinoff(struct board_info *b, unsigned int win);
158static void pcxi_globalwinon(struct channel *ch);
159static void pcxi_rxwinon(struct channel *ch);
160static void pcxi_txwinon(struct channel *ch);
161static void pcxi_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163/* - Begin 'specific' do nothing memory functions needed for some cards - */
164
Alan Coxf2cf8e22005-09-06 15:16:44 -0700165static void dummy_memwinon(struct board_info *b, unsigned int win);
166static void dummy_memwinoff(struct board_info *b, unsigned int win);
167static void dummy_globalwinon(struct channel *ch);
168static void dummy_rxwinon(struct channel *ch);
169static void dummy_txwinon(struct channel *ch);
170static void dummy_memoff(struct channel *ch);
171static void dummy_assertgwinon(struct channel *ch);
172static void dummy_assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174/* ------------------- Begin declare functions ----------------------- */
175
Alan Coxf2cf8e22005-09-06 15:16:44 -0700176static struct channel *verifyChannel(struct tty_struct *);
177static void pc_sched_event(struct channel *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178static void epca_error(int, char *);
179static void pc_close(struct tty_struct *, struct file *);
180static void shutdown(struct channel *);
181static void pc_hangup(struct tty_struct *);
182static void pc_put_char(struct tty_struct *, unsigned char);
183static int pc_write_room(struct tty_struct *);
184static int pc_chars_in_buffer(struct tty_struct *);
185static void pc_flush_buffer(struct tty_struct *);
186static void pc_flush_chars(struct tty_struct *);
187static int block_til_ready(struct tty_struct *, struct file *,
188 struct channel *);
189static int pc_open(struct tty_struct *, struct file *);
190static void post_fep_init(unsigned int crd);
191static void epcapoll(unsigned long);
192static void doevent(int);
193static void fepcmd(struct channel *, int, int, int, int, int);
194static unsigned termios2digi_h(struct channel *ch, unsigned);
195static unsigned termios2digi_i(struct channel *ch, unsigned);
196static unsigned termios2digi_c(struct channel *ch, unsigned);
197static void epcaparam(struct tty_struct *, struct channel *);
198static void receive_data(struct channel *);
199static int pc_ioctl(struct tty_struct *, struct file *,
200 unsigned int, unsigned long);
201static int info_ioctl(struct tty_struct *, struct file *,
202 unsigned int, unsigned long);
203static void pc_set_termios(struct tty_struct *, struct termios *);
204static void do_softint(void *);
205static void pc_stop(struct tty_struct *);
206static void pc_start(struct tty_struct *);
207static void pc_throttle(struct tty_struct * tty);
208static void pc_unthrottle(struct tty_struct *tty);
209static void digi_send_break(struct channel *ch, int msec);
210static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
211void epca_setup(char *, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213static int get_termio(struct tty_struct *, struct termio __user *);
214static int pc_write(struct tty_struct *, const unsigned char *, int);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700215static int pc_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216static int init_PCI(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218
219/* ------------------------------------------------------------------
220 Table of functions for each board to handle memory. Mantaining
221 parallelism is a *very* good idea here. The idea is for the
222 runtime code to blindly call these functions, not knowing/caring
223 about the underlying hardware. This stuff should contain no
224 conditionals; if more functionality is needed a different entry
225 should be established. These calls are the interface calls and
226 are the only functions that should be accessed. Anyone caught
227 making direct calls deserves what they get.
228-------------------------------------------------------------------- */
229
Alan Coxf2cf8e22005-09-06 15:16:44 -0700230static void memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 (b->memwinon)(b, win);
233}
234
Alan Coxf2cf8e22005-09-06 15:16:44 -0700235static void memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 (b->memwinoff)(b, win);
238}
239
Alan Coxf2cf8e22005-09-06 15:16:44 -0700240static void globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 (ch->board->globalwinon)(ch);
243}
244
Alan Coxf2cf8e22005-09-06 15:16:44 -0700245static void rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 (ch->board->rxwinon)(ch);
248}
249
Alan Coxf2cf8e22005-09-06 15:16:44 -0700250static void txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 (ch->board->txwinon)(ch);
253}
254
Alan Coxf2cf8e22005-09-06 15:16:44 -0700255static void memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 (ch->board->memoff)(ch);
258}
Alan Coxf2cf8e22005-09-06 15:16:44 -0700259static void assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261 (ch->board->assertgwinon)(ch);
262}
263
Alan Coxf2cf8e22005-09-06 15:16:44 -0700264static void assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 (ch->board->assertmemoff)(ch);
267}
268
269/* ---------------------------------------------------------
270 PCXEM windowing is the same as that used in the PCXR
271 and CX series cards.
272------------------------------------------------------------ */
273
Alan Coxf2cf8e22005-09-06 15:16:44 -0700274static void pcxem_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700276 outb_p(FEPWIN|win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Alan Coxf2cf8e22005-09-06 15:16:44 -0700279static void pcxem_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700281 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Alan Coxf2cf8e22005-09-06 15:16:44 -0700284static void pcxem_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 outb_p( FEPWIN, (int)ch->board->port + 1);
287}
288
Alan Coxf2cf8e22005-09-06 15:16:44 -0700289static void pcxem_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 outb_p(ch->rxwin, (int)ch->board->port + 1);
292}
293
Alan Coxf2cf8e22005-09-06 15:16:44 -0700294static void pcxem_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 outb_p(ch->txwin, (int)ch->board->port + 1);
297}
298
Alan Coxf2cf8e22005-09-06 15:16:44 -0700299static void pcxem_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 outb_p(0, (int)ch->board->port + 1);
302}
303
304/* ----------------- Begin pcxe memory window stuff ------------------ */
305
Alan Coxf2cf8e22005-09-06 15:16:44 -0700306static void pcxe_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700308 outb_p(FEPWIN | win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Alan Coxf2cf8e22005-09-06 15:16:44 -0700311static void pcxe_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700313 outb_p(inb(b->port) & ~FEPMEM,
314 b->port + 1);
315 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
Alan Coxf2cf8e22005-09-06 15:16:44 -0700318static void pcxe_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
320 outb_p( FEPWIN, (int)ch->board->port + 1);
321}
322
Alan Coxf2cf8e22005-09-06 15:16:44 -0700323static void pcxe_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 outb_p(ch->rxwin, (int)ch->board->port + 1);
326}
327
Alan Coxf2cf8e22005-09-06 15:16:44 -0700328static void pcxe_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 outb_p(ch->txwin, (int)ch->board->port + 1);
331}
332
Alan Coxf2cf8e22005-09-06 15:16:44 -0700333static void pcxe_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 outb_p(0, (int)ch->board->port);
336 outb_p(0, (int)ch->board->port + 1);
337}
338
339/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
340
Alan Coxf2cf8e22005-09-06 15:16:44 -0700341static void pcxi_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700343 outb_p(inb(b->port) | FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
Alan Coxf2cf8e22005-09-06 15:16:44 -0700346static void pcxi_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700348 outb_p(inb(b->port) & ~FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Alan Coxf2cf8e22005-09-06 15:16:44 -0700351static void pcxi_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700353 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
Alan Coxf2cf8e22005-09-06 15:16:44 -0700356static void pcxi_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700358 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Alan Coxf2cf8e22005-09-06 15:16:44 -0700361static void pcxi_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700363 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
Alan Coxf2cf8e22005-09-06 15:16:44 -0700366static void pcxi_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700368 outb_p(0, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369}
370
Alan Coxf2cf8e22005-09-06 15:16:44 -0700371static void pcxi_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700373 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
Alan Coxf2cf8e22005-09-06 15:16:44 -0700376static void pcxi_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700378 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
381
382/* ----------------------------------------------------------------------
383 Not all of the cards need specific memory windowing routines. Some
384 cards (Such as PCI) needs no windowing routines at all. We provide
385 these do nothing routines so that the same code base can be used.
386 The driver will ALWAYS call a windowing routine if it thinks it needs
387 to; regardless of the card. However, dependent on the card the routine
388 may or may not do anything.
389---------------------------------------------------------------------------*/
390
Alan Coxf2cf8e22005-09-06 15:16:44 -0700391static void dummy_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393}
394
Alan Coxf2cf8e22005-09-06 15:16:44 -0700395static void dummy_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
397}
398
Alan Coxf2cf8e22005-09-06 15:16:44 -0700399static void dummy_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
401}
402
Alan Coxf2cf8e22005-09-06 15:16:44 -0700403static void dummy_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
405}
406
Alan Coxf2cf8e22005-09-06 15:16:44 -0700407static void dummy_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
409}
410
Alan Coxf2cf8e22005-09-06 15:16:44 -0700411static void dummy_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
413}
414
Alan Coxf2cf8e22005-09-06 15:16:44 -0700415static void dummy_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
417}
418
Alan Coxf2cf8e22005-09-06 15:16:44 -0700419static void dummy_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
421}
422
423/* ----------------- Begin verifyChannel function ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700424static struct channel *verifyChannel(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{ /* Begin verifyChannel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* --------------------------------------------------------------------
427 This routine basically provides a sanity check. It insures that
428 the channel returned is within the proper range of addresses as
429 well as properly initialized. If some bogus info gets passed in
430 through tty->driver_data this should catch it.
Alan Coxf2cf8e22005-09-06 15:16:44 -0700431 --------------------------------------------------------------------- */
432 if (tty) {
433 struct channel *ch = (struct channel *)tty->driver_data;
434 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 if (ch->magic == EPCA_MAGIC)
436 return ch;
437 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 return NULL;
440
441} /* End verifyChannel */
442
443/* ------------------ Begin pc_sched_event ------------------------- */
444
Alan Coxf2cf8e22005-09-06 15:16:44 -0700445static void pc_sched_event(struct channel *ch, int event)
446{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 /* ----------------------------------------------------------------------
448 We call this to schedule interrupt processing on some event. The
449 kernel sees our request and calls the related routine in OUR driver.
450 -------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 ch->event |= 1 << event;
452 schedule_work(&ch->tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453} /* End pc_sched_event */
454
455/* ------------------ Begin epca_error ------------------------- */
456
457static void epca_error(int line, char *msg)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700458{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700460}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462/* ------------------ Begin pc_close ------------------------- */
463static void pc_close(struct tty_struct * tty, struct file * filp)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700464{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 struct channel *ch;
466 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /* ---------------------------------------------------------
468 verifyChannel returns the channel from the tty struct
469 if it is valid. This serves as a sanity check.
470 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700471 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
472 spin_lock_irqsave(&epca_lock, flags);
473 if (tty_hung_up_p(filp)) {
474 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return;
476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 /* Check to see if the channel is open more than once */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700478 if (ch->count-- > 1) {
479 /* Begin channel is open more than once */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 /* -------------------------------------------------------------
481 Return without doing anything. Someone might still be using
482 the channel.
483 ---------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700484 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 return;
486 } /* End channel is open more than once */
487
488 /* Port open only once go ahead with shutdown & reset */
Eric Sesterhenn56ee4822006-03-26 18:17:21 +0200489 BUG_ON(ch->count < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 /* ---------------------------------------------------------------
492 Let the rest of the driver know the channel is being closed.
493 This becomes important if an open is attempted before close
494 is finished.
495 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 ch->asyncflags |= ASYNC_CLOSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 tty->closing = 1;
498
Alan Coxf2cf8e22005-09-06 15:16:44 -0700499 spin_unlock_irqrestore(&epca_lock, flags);
500
501 if (ch->asyncflags & ASYNC_INITIALIZED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 /* Setup an event to indicate when the transmit buffer empties */
503 setup_empty_event(tty, ch);
504 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (tty->driver->flush_buffer)
507 tty->driver->flush_buffer(tty);
508
509 tty_ldisc_flush(tty);
510 shutdown(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700511
512 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 tty->closing = 0;
514 ch->event = 0;
515 ch->tty = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700516 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Alan Coxf2cf8e22005-09-06 15:16:44 -0700518 if (ch->blocked_open) { /* Begin if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (ch->close_delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 } /* End if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
524 ASYNC_CLOSING);
525 wake_up_interruptible(&ch->close_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 } /* End if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527} /* End pc_close */
528
529/* ------------------ Begin shutdown ------------------------- */
530
531static void shutdown(struct channel *ch)
532{ /* Begin shutdown */
533
534 unsigned long flags;
535 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +0100536 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 if (!(ch->asyncflags & ASYNC_INITIALIZED))
539 return;
540
Alan Coxf2cf8e22005-09-06 15:16:44 -0700541 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Alan Coxf2cf8e22005-09-06 15:16:44 -0700543 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 bc = ch->brdchan;
545
546 /* ------------------------------------------------------------------
547 In order for an event to be generated on the receipt of data the
548 idata flag must be set. Since we are shutting down, this is not
549 necessary clear this flag.
550 --------------------------------------------------------------------- */
551
552 if (bc)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700553 writeb(0, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 tty = ch->tty;
555
556 /* ----------------------------------------------------------------
557 If we're a modem control device and HUPCL is on, drop RTS & DTR.
558 ------------------------------------------------------------------ */
559
Alan Coxf2cf8e22005-09-06 15:16:44 -0700560 if (tty->termios->c_cflag & HUPCL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
562 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 memoff(ch);
565
566 /* ------------------------------------------------------------------
567 The channel has officialy been closed. The next time it is opened
568 it will have to reinitialized. Set a flag to indicate this.
569 ---------------------------------------------------------------------- */
570
571 /* Prevent future Digi programmed interrupts from coming active */
572
573 ch->asyncflags &= ~ASYNC_INITIALIZED;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700574 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576} /* End shutdown */
577
578/* ------------------ Begin pc_hangup ------------------------- */
579
580static void pc_hangup(struct tty_struct *tty)
581{ /* Begin pc_hangup */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 struct channel *ch;
583
584 /* ---------------------------------------------------------
585 verifyChannel returns the channel from the tty struct
586 if it is valid. This serves as a sanity check.
587 ------------------------------------------------------------- */
588
Alan Coxf2cf8e22005-09-06 15:16:44 -0700589 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 unsigned long flags;
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (tty->driver->flush_buffer)
593 tty->driver->flush_buffer(tty);
594 tty_ldisc_flush(tty);
595 shutdown(ch);
596
Alan Coxf2cf8e22005-09-06 15:16:44 -0700597 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 ch->tty = NULL;
599 ch->event = 0;
600 ch->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700602 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 } /* End if ch != NULL */
605
606} /* End pc_hangup */
607
608/* ------------------ Begin pc_write ------------------------- */
609
610static int pc_write(struct tty_struct * tty,
611 const unsigned char *buf, int bytesAvailable)
612{ /* Begin pc_write */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700613 unsigned int head, tail;
614 int dataLen;
615 int size;
616 int amountCopied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 struct channel *ch;
618 unsigned long flags;
619 int remain;
Al Virobc9a5152005-09-15 22:53:28 +0100620 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 /* ----------------------------------------------------------------
623 pc_write is primarily called directly by the kernel routine
624 tty_write (Though it can also be called by put_char) found in
625 tty_io.c. pc_write is passed a line discipline buffer where
626 the data to be written out is stored. The line discipline
627 implementation itself is done at the kernel level and is not
628 brought into the driver.
629 ------------------------------------------------------------------- */
630
631 /* ---------------------------------------------------------
632 verifyChannel returns the channel from the tty struct
633 if it is valid. This serves as a sanity check.
634 ------------------------------------------------------------- */
635
636 if ((ch = verifyChannel(tty)) == NULL)
637 return 0;
638
639 /* Make a pointer to the channel data structure found on the board. */
640
641 bc = ch->brdchan;
642 size = ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 amountCopied = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Alan Coxf2cf8e22005-09-06 15:16:44 -0700645 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 globalwinon(ch);
647
Alan Coxf2cf8e22005-09-06 15:16:44 -0700648 head = readw(&bc->tin) & (size - 1);
649 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Alan Coxf2cf8e22005-09-06 15:16:44 -0700651 if (tail != readw(&bc->tout))
652 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 tail &= (size - 1);
654
655 /* If head >= tail, head has not wrapped around. */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700656 if (head >= tail) { /* Begin head has not wrapped */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /* ---------------------------------------------------------------
658 remain (much like dataLen above) represents the total amount of
659 space available on the card for data. Here dataLen represents
660 the space existing between the head pointer and the end of
661 buffer. This is important because a memcpy cannot be told to
662 automatically wrap around when it hits the buffer end.
663 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 dataLen = size - head;
665 remain = size - (head - tail) - 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700666 } else { /* Begin head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 remain = tail - head - 1;
669 dataLen = remain;
670
671 } /* End head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 /* -------------------------------------------------------------------
673 Check the space on the card. If we have more data than
674 space; reduce the amount of data to fit the space.
675 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 bytesAvailable = min(remain, bytesAvailable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 txwinon(ch);
678 while (bytesAvailable > 0)
679 { /* Begin while there is data to copy onto card */
680
681 /* -----------------------------------------------------------------
682 If head is not wrapped, the below will make sure the first
683 data copy fills to the end of card buffer.
684 ------------------------------------------------------------------- */
685
686 dataLen = min(bytesAvailable, dataLen);
Al Virobc9a5152005-09-15 22:53:28 +0100687 memcpy_toio(ch->txptr + head, buf, dataLen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 buf += dataLen;
689 head += dataLen;
690 amountCopied += dataLen;
691 bytesAvailable -= dataLen;
692
Alan Coxf2cf8e22005-09-06 15:16:44 -0700693 if (head >= size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 head = 0;
695 dataLen = tail;
696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 } /* End while there is data to copy onto card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 ch->statusflags |= TXBUSY;
699 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700700 writew(head, &bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Alan Coxf2cf8e22005-09-06 15:16:44 -0700702 if ((ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700704 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700707 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 return(amountCopied);
709
710} /* End pc_write */
711
712/* ------------------ Begin pc_put_char ------------------------- */
713
714static void pc_put_char(struct tty_struct *tty, unsigned char c)
715{ /* Begin pc_put_char */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 pc_write(tty, &c, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717} /* End pc_put_char */
718
719/* ------------------ Begin pc_write_room ------------------------- */
720
721static int pc_write_room(struct tty_struct *tty)
722{ /* Begin pc_write_room */
723
724 int remain;
725 struct channel *ch;
726 unsigned long flags;
727 unsigned int head, tail;
Al Virobc9a5152005-09-15 22:53:28 +0100728 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 remain = 0;
731
732 /* ---------------------------------------------------------
733 verifyChannel returns the channel from the tty struct
734 if it is valid. This serves as a sanity check.
735 ------------------------------------------------------------- */
736
Alan Coxf2cf8e22005-09-06 15:16:44 -0700737 if ((ch = verifyChannel(tty)) != NULL) {
738 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 globalwinon(ch);
740
741 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700742 head = readw(&bc->tin) & (ch->txbufsize - 1);
743 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Alan Coxf2cf8e22005-09-06 15:16:44 -0700745 if (tail != readw(&bc->tout))
746 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 /* Wrap tail if necessary */
748 tail &= (ch->txbufsize - 1);
749
750 if ((remain = tail - head - 1) < 0 )
751 remain += ch->txbufsize;
752
Alan Coxf2cf8e22005-09-06 15:16:44 -0700753 if (remain && (ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700755 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700758 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 /* Return how much room is left on card */
761 return remain;
762
763} /* End pc_write_room */
764
765/* ------------------ Begin pc_chars_in_buffer ---------------------- */
766
767static int pc_chars_in_buffer(struct tty_struct *tty)
768{ /* Begin pc_chars_in_buffer */
769
770 int chars;
771 unsigned int ctail, head, tail;
772 int remain;
773 unsigned long flags;
774 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100775 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 /* ---------------------------------------------------------
778 verifyChannel returns the channel from the tty struct
779 if it is valid. This serves as a sanity check.
780 ------------------------------------------------------------- */
781
782 if ((ch = verifyChannel(tty)) == NULL)
783 return(0);
784
Alan Coxf2cf8e22005-09-06 15:16:44 -0700785 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 globalwinon(ch);
787
788 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700789 tail = readw(&bc->tout);
790 head = readw(&bc->tin);
791 ctail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Alan Coxf2cf8e22005-09-06 15:16:44 -0700793 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 chars = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700795 else { /* Begin if some space on the card has been used */
796 head = readw(&bc->tin) & (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 tail &= (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /* --------------------------------------------------------------
799 The logic here is basically opposite of the above pc_write_room
800 here we are finding the amount of bytes in the buffer filled.
801 Not the amount of bytes empty.
802 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 if ((remain = tail - head - 1) < 0 )
804 remain += ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 chars = (int)(ch->txbufsize - remain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 /* -------------------------------------------------------------
807 Make it possible to wakeup anything waiting for output
808 in tty_ioctl.c, etc.
809
810 If not already set. Setup an event to indicate when the
811 transmit buffer empties
812 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 if (!(ch->statusflags & EMPTYWAIT))
814 setup_empty_event(tty,ch);
815
816 } /* End if some space on the card has been used */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700818 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 /* Return number of characters residing on card. */
820 return(chars);
821
822} /* End pc_chars_in_buffer */
823
824/* ------------------ Begin pc_flush_buffer ---------------------- */
825
826static void pc_flush_buffer(struct tty_struct *tty)
827{ /* Begin pc_flush_buffer */
828
829 unsigned int tail;
830 unsigned long flags;
831 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100832 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 /* ---------------------------------------------------------
834 verifyChannel returns the channel from the tty struct
835 if it is valid. This serves as a sanity check.
836 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 if ((ch = verifyChannel(tty)) == NULL)
838 return;
839
Alan Coxf2cf8e22005-09-06 15:16:44 -0700840 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700843 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /* Have FEP move tout pointer; effectively flushing transmit buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700847 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 wake_up_interruptible(&tty->write_wait);
849 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850} /* End pc_flush_buffer */
851
852/* ------------------ Begin pc_flush_chars ---------------------- */
853
854static void pc_flush_chars(struct tty_struct *tty)
855{ /* Begin pc_flush_chars */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 struct channel * ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 /* ---------------------------------------------------------
858 verifyChannel returns the channel from the tty struct
859 if it is valid. This serves as a sanity check.
860 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700861 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700863 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 /* ----------------------------------------------------------------
865 If not already set and the transmitter is busy setup an event
866 to indicate when the transmit empties.
867 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
869 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700870 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872} /* End pc_flush_chars */
873
874/* ------------------ Begin block_til_ready ---------------------- */
875
876static int block_til_ready(struct tty_struct *tty,
877 struct file *filp, struct channel *ch)
878{ /* Begin block_til_ready */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 DECLARE_WAITQUEUE(wait,current);
880 int retval, do_clocal = 0;
881 unsigned long flags;
882
Alan Coxf2cf8e22005-09-06 15:16:44 -0700883 if (tty_hung_up_p(filp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
885 retval = -EAGAIN;
886 else
887 retval = -ERESTARTSYS;
888 return(retval);
889 }
890
891 /* -----------------------------------------------------------------
892 If the device is in the middle of being closed, then block
893 until it's done, and then try again.
894 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700895 if (ch->asyncflags & ASYNC_CLOSING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 interruptible_sleep_on(&ch->close_wait);
897
898 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
899 return -EAGAIN;
900 else
901 return -ERESTARTSYS;
902 }
903
Alan Coxf2cf8e22005-09-06 15:16:44 -0700904 if (filp->f_flags & O_NONBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 /* -----------------------------------------------------------------
906 If non-blocking mode is set, then make the check up front
907 and then exit.
908 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 return 0;
911 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 if (tty->termios->c_cflag & CLOCAL)
913 do_clocal = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700914 /* Block waiting for the carrier detect and the line to become free */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 retval = 0;
917 add_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Alan Coxf2cf8e22005-09-06 15:16:44 -0700919 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 /* We dec count so that pc_close will know when to free things */
921 if (!tty_hung_up_p(filp))
922 ch->count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 ch->blocked_open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 while(1)
925 { /* Begin forever while */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 if (tty_hung_up_p(filp) ||
928 !(ch->asyncflags & ASYNC_INITIALIZED))
929 {
930 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
931 retval = -EAGAIN;
932 else
933 retval = -ERESTARTSYS;
934 break;
935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (!(ch->asyncflags & ASYNC_CLOSING) &&
937 (do_clocal || (ch->imodem & ch->dcd)))
938 break;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700939 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 retval = -ERESTARTSYS;
941 break;
942 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700943 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 /* ---------------------------------------------------------------
945 Allow someone else to be scheduled. We will occasionally go
946 through this loop until one of the above conditions change.
947 The below schedule call will allow other processes to enter and
948 prevent this loop from hogging the cpu.
949 ------------------------------------------------------------------ */
950 schedule();
Alan Coxf2cf8e22005-09-06 15:16:44 -0700951 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 } /* End forever while */
954
955 current->state = TASK_RUNNING;
956 remove_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 if (!tty_hung_up_p(filp))
958 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 ch->blocked_open--;
960
Alan Coxf2cf8e22005-09-06 15:16:44 -0700961 spin_unlock_irqrestore(&epca_lock, flags);
962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 if (retval)
964 return retval;
965
966 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968} /* End block_til_ready */
969
970/* ------------------ Begin pc_open ---------------------- */
971
972static int pc_open(struct tty_struct *tty, struct file * filp)
973{ /* Begin pc_open */
974
975 struct channel *ch;
976 unsigned long flags;
977 int line, retval, boardnum;
Al Virobc9a5152005-09-15 22:53:28 +0100978 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700979 unsigned int head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981 line = tty->index;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700982 if (line < 0 || line >= nbdevs)
983 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 ch = &digi_channels[line];
986 boardnum = ch->boardnum;
987
988 /* Check status of board configured in system. */
989
990 /* -----------------------------------------------------------------
991 I check to see if the epca_setup routine detected an user error.
992 It might be better to put this in pc_init, but for the moment it
993 goes here.
994 ---------------------------------------------------------------------- */
995
Alan Coxf2cf8e22005-09-06 15:16:44 -0700996 if (invalid_lilo_config) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 if (setup_error_code & INVALID_BOARD_TYPE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700998 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (setup_error_code & INVALID_NUM_PORTS)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001000 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 if (setup_error_code & INVALID_MEM_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001002 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (setup_error_code & INVALID_PORT_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001004 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (setup_error_code & INVALID_BOARD_STATUS)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001006 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if (setup_error_code & INVALID_ALTPIN)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001008 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 tty->driver_data = NULL; /* Mark this device as 'down' */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001010 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001012 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 tty->driver_data = NULL; /* Mark this device as 'down' */
1014 return(-ENODEV);
1015 }
1016
Alan Coxf2cf8e22005-09-06 15:16:44 -07001017 if ((bc = ch->brdchan) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 tty->driver_data = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001019 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 }
1021
Alan Coxf2cf8e22005-09-06 15:16:44 -07001022 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 /* ------------------------------------------------------------------
1024 Every time a channel is opened, increment a counter. This is
1025 necessary because we do not wish to flush and shutdown the channel
1026 until the last app holding the channel open, closes it.
1027 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 /* ----------------------------------------------------------------
1030 Set a kernel structures pointer to our local channel
1031 structure. This way we can get to it when passed only
1032 a tty struct.
1033 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 tty->driver_data = ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 /* ----------------------------------------------------------------
1036 If this is the first time the channel has been opened, initialize
1037 the tty->termios struct otherwise let pc_close handle it.
1038 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 globalwinon(ch);
1040 ch->statusflags = 0;
1041
1042 /* Save boards current modem status */
Al Virobc9a5152005-09-15 22:53:28 +01001043 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 /* ----------------------------------------------------------------
1046 Set receive head and tail ptrs to each other. This indicates
1047 no data available to read.
1048 ----------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001049 head = readw(&bc->rin);
1050 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 /* Set the channels associated tty structure */
1053 ch->tty = tty;
1054
1055 /* -----------------------------------------------------------------
1056 The below routine generally sets up parity, baud, flow control
1057 issues, etc.... It effect both control flags and input flags.
1058 -------------------------------------------------------------------- */
1059 epcaparam(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 ch->asyncflags |= ASYNC_INITIALIZED;
1061 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001062 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
1064 retval = block_til_ready(tty, filp, ch);
1065 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 /* -------------------------------------------------------------
1068 Set this again in case a hangup set it to zero while this
1069 open() was waiting for the line...
1070 --------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001071 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 ch->tty = tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 /* Enable Digi Data events */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001075 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001077 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079} /* End pc_open */
1080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081static int __init epca_module_init(void)
1082{ /* Begin init_module */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001083 return pc_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
1085
1086module_init(epca_module_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088static struct pci_driver epca_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090static void __exit epca_module_exit(void)
1091{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 int count, crd;
1093 struct board_info *bd;
1094 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 del_timer_sync(&epca_timer);
1097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 if ((tty_unregister_driver(pc_driver)) ||
1099 (tty_unregister_driver(pc_info)))
1100 {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001101 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 return;
1103 }
1104 put_tty_driver(pc_driver);
1105 put_tty_driver(pc_info);
1106
Alan Coxf2cf8e22005-09-06 15:16:44 -07001107 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 bd = &boards[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 if (!bd)
1110 { /* Begin sanity check */
1111 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1112 return;
1113 } /* End sanity check */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001114 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 for (count = 0; count < bd->numports; count++, ch++)
1116 { /* Begin for each port */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001117 if (ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 if (ch->tty)
1119 tty_hangup(ch->tty);
1120 kfree(ch->tmp_buf);
1121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 } /* End for each port */
1123 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 pci_unregister_driver (&epca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
Alan Coxf2cf8e22005-09-06 15:16:44 -07001126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127module_exit(epca_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129static struct tty_operations pc_ops = {
1130 .open = pc_open,
1131 .close = pc_close,
1132 .write = pc_write,
1133 .write_room = pc_write_room,
1134 .flush_buffer = pc_flush_buffer,
1135 .chars_in_buffer = pc_chars_in_buffer,
1136 .flush_chars = pc_flush_chars,
1137 .put_char = pc_put_char,
1138 .ioctl = pc_ioctl,
1139 .set_termios = pc_set_termios,
1140 .stop = pc_stop,
1141 .start = pc_start,
1142 .throttle = pc_throttle,
1143 .unthrottle = pc_unthrottle,
1144 .hangup = pc_hangup,
1145};
1146
1147static int info_open(struct tty_struct *tty, struct file * filp)
1148{
1149 return 0;
1150}
1151
1152static struct tty_operations info_ops = {
1153 .open = info_open,
1154 .ioctl = info_ioctl,
1155};
1156
1157/* ------------------ Begin pc_init ---------------------- */
1158
Alan Coxf2cf8e22005-09-06 15:16:44 -07001159static int __init pc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160{ /* Begin pc_init */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 int crd;
1162 struct board_info *bd;
1163 unsigned char board_id = 0;
1164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 int pci_boards_found, pci_count;
1166
1167 pci_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 pc_driver = alloc_tty_driver(MAX_ALLOC);
1170 if (!pc_driver)
1171 return -ENOMEM;
1172
1173 pc_info = alloc_tty_driver(MAX_ALLOC);
1174 if (!pc_info) {
1175 put_tty_driver(pc_driver);
1176 return -ENOMEM;
1177 }
1178
1179 /* -----------------------------------------------------------------------
1180 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1181 board structure defined by digiConfig into drivers board structure.
1182 Note : If LILO has ran epca_setup then epca_setup will handle defining
1183 num_cards as well as copying the data into the board structure.
1184 -------------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001185 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 nbdevs = NBDEVS;
1188 num_cards = NUMCARDS;
1189 memcpy((void *)&boards, (void *)&static_boards,
1190 (sizeof(struct board_info) * NUMCARDS));
1191 } /* End driver has been configured via. epcaconfig */
1192
1193 /* -----------------------------------------------------------------
1194 Note : If lilo was used to configure the driver and the
1195 ignore epcaconfig option was choosen (digiepca=2) then
1196 nbdevs and num_cards will equal 0 at this point. This is
1197 okay; PCI cards will still be picked up if detected.
1198 --------------------------------------------------------------------- */
1199
1200 /* -----------------------------------------------------------
1201 Set up interrupt, we will worry about memory allocation in
1202 post_fep_init.
1203 --------------------------------------------------------------- */
1204
1205
1206 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 /* ------------------------------------------------------------------
1209 NOTE : This code assumes that the number of ports found in
1210 the boards array is correct. This could be wrong if
1211 the card in question is PCI (And therefore has no ports
1212 entry in the boards structure.) The rest of the
1213 information will be valid for PCI because the beginning
1214 of pc_init scans for PCI and determines i/o and base
1215 memory addresses. I am not sure if it is possible to
1216 read the number of ports supported by the card prior to
1217 it being booted (Since that is the state it is in when
1218 pc_init is run). Because it is not possible to query the
1219 number of supported ports until after the card has booted;
1220 we are required to calculate the card_ptrs as the card is
1221 is initialized (Inside post_fep_init). The negative thing
1222 about this approach is that digiDload's call to GET_INFO
1223 will have a bad port value. (Since this is called prior
1224 to post_fep_init.)
1225
1226 --------------------------------------------------------------------- */
1227
1228 pci_boards_found = 0;
1229 if(num_cards < MAXBOARDS)
1230 pci_boards_found += init_PCI();
1231 num_cards += pci_boards_found;
1232
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 pc_driver->owner = THIS_MODULE;
1234 pc_driver->name = "ttyD";
1235 pc_driver->devfs_name = "tts/D";
1236 pc_driver->major = DIGI_MAJOR;
1237 pc_driver->minor_start = 0;
1238 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1239 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1240 pc_driver->init_termios = tty_std_termios;
1241 pc_driver->init_termios.c_iflag = 0;
1242 pc_driver->init_termios.c_oflag = 0;
1243 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1244 pc_driver->init_termios.c_lflag = 0;
1245 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1246 tty_set_operations(pc_driver, &pc_ops);
1247
1248 pc_info->owner = THIS_MODULE;
1249 pc_info->name = "digi_ctl";
1250 pc_info->major = DIGIINFOMAJOR;
1251 pc_info->minor_start = 0;
1252 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1253 pc_info->subtype = SERIAL_TYPE_INFO;
1254 pc_info->init_termios = tty_std_termios;
1255 pc_info->init_termios.c_iflag = 0;
1256 pc_info->init_termios.c_oflag = 0;
1257 pc_info->init_termios.c_lflag = 0;
1258 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1259 pc_info->flags = TTY_DRIVER_REAL_RAW;
1260 tty_set_operations(pc_info, &info_ops);
1261
1262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 for (crd = 0; crd < num_cards; crd++)
1264 { /* Begin for each card */
1265
1266 /* ------------------------------------------------------------------
1267 This is where the appropriate memory handlers for the hardware is
1268 set. Everything at runtime blindly jumps through these vectors.
1269 ---------------------------------------------------------------------- */
1270
1271 /* defined in epcaconfig.h */
1272 bd = &boards[crd];
1273
1274 switch (bd->type)
1275 { /* Begin switch on bd->type {board type} */
1276 case PCXEM:
1277 case EISAXEM:
1278 bd->memwinon = pcxem_memwinon ;
1279 bd->memwinoff = pcxem_memwinoff ;
1280 bd->globalwinon = pcxem_globalwinon ;
1281 bd->txwinon = pcxem_txwinon ;
1282 bd->rxwinon = pcxem_rxwinon ;
1283 bd->memoff = pcxem_memoff ;
1284 bd->assertgwinon = dummy_assertgwinon;
1285 bd->assertmemoff = dummy_assertmemoff;
1286 break;
1287
1288 case PCIXEM:
1289 case PCIXRJ:
1290 case PCIXR:
1291 bd->memwinon = dummy_memwinon;
1292 bd->memwinoff = dummy_memwinoff;
1293 bd->globalwinon = dummy_globalwinon;
1294 bd->txwinon = dummy_txwinon;
1295 bd->rxwinon = dummy_rxwinon;
1296 bd->memoff = dummy_memoff;
1297 bd->assertgwinon = dummy_assertgwinon;
1298 bd->assertmemoff = dummy_assertmemoff;
1299 break;
1300
1301 case PCXE:
1302 case PCXEVE:
1303
1304 bd->memwinon = pcxe_memwinon;
1305 bd->memwinoff = pcxe_memwinoff;
1306 bd->globalwinon = pcxe_globalwinon;
1307 bd->txwinon = pcxe_txwinon;
1308 bd->rxwinon = pcxe_rxwinon;
1309 bd->memoff = pcxe_memoff;
1310 bd->assertgwinon = dummy_assertgwinon;
1311 bd->assertmemoff = dummy_assertmemoff;
1312 break;
1313
1314 case PCXI:
1315 case PC64XE:
1316
1317 bd->memwinon = pcxi_memwinon;
1318 bd->memwinoff = pcxi_memwinoff;
1319 bd->globalwinon = pcxi_globalwinon;
1320 bd->txwinon = pcxi_txwinon;
1321 bd->rxwinon = pcxi_rxwinon;
1322 bd->memoff = pcxi_memoff;
1323 bd->assertgwinon = pcxi_assertgwinon;
1324 bd->assertmemoff = pcxi_assertmemoff;
1325 break;
1326
1327 default:
1328 break;
1329
1330 } /* End switch on bd->type */
1331
1332 /* ---------------------------------------------------------------
1333 Some cards need a memory segment to be defined for use in
1334 transmit and receive windowing operations. These boards
1335 are listed in the below switch. In the case of the XI the
1336 amount of memory on the board is variable so the memory_seg
1337 is also variable. This code determines what they segment
1338 should be.
1339 ----------------------------------------------------------------- */
1340
1341 switch (bd->type)
1342 { /* Begin switch on bd->type {board type} */
1343
1344 case PCXE:
1345 case PCXEVE:
1346 case PC64XE:
1347 bd->memory_seg = 0xf000;
1348 break;
1349
1350 case PCXI:
1351 board_id = inb((int)bd->port);
1352 if ((board_id & 0x1) == 0x1)
1353 { /* Begin it's an XI card */
1354
1355 /* Is it a 64K board */
1356 if ((board_id & 0x30) == 0)
1357 bd->memory_seg = 0xf000;
1358
1359 /* Is it a 128K board */
1360 if ((board_id & 0x30) == 0x10)
1361 bd->memory_seg = 0xe000;
1362
1363 /* Is is a 256K board */
1364 if ((board_id & 0x30) == 0x20)
1365 bd->memory_seg = 0xc000;
1366
1367 /* Is it a 512K board */
1368 if ((board_id & 0x30) == 0x30)
1369 bd->memory_seg = 0x8000;
1370
Alan Coxf2cf8e22005-09-06 15:16:44 -07001371 } 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 -07001372 break;
1373
1374 } /* End switch on bd->type */
1375
1376 } /* End for each card */
1377
1378 if (tty_register_driver(pc_driver))
1379 panic("Couldn't register Digi PC/ driver");
1380
1381 if (tty_register_driver(pc_info))
1382 panic("Couldn't register Digi PC/ info ");
1383
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
1393} /* End pc_init */
1394
1395/* ------------------ Begin post_fep_init ---------------------- */
1396
1397static void post_fep_init(unsigned int crd)
1398{ /* Begin post_fep_init */
1399
1400 int i;
Al Virobc9a5152005-09-15 22:53:28 +01001401 void __iomem *memaddr;
1402 struct global_data __iomem *gd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001404 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 struct channel *ch;
1406 int shrinkmem = 0, lowwater ;
1407
1408 /* -------------------------------------------------------------
1409 This call is made by the user via. the ioctl call DIGI_INIT.
1410 It is responsible for setting up all the card specific stuff.
1411 ---------------------------------------------------------------- */
1412 bd = &boards[crd];
1413
1414 /* -----------------------------------------------------------------
1415 If this is a PCI board, get the port info. Remember PCI cards
1416 do not have entries into the epcaconfig.h file, so we can't get
1417 the number of ports from it. Unfortunetly, this means that anyone
1418 doing a DIGI_GETINFO before the board has booted will get an invalid
1419 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1420 after DIGI_INIT has been called will return the proper values.
1421 ------------------------------------------------------------------- */
1422
Alan Coxf2cf8e22005-09-06 15:16:44 -07001423 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 /* --------------------------------------------------------------------
1425 Below we use XEMPORTS as a memory offset regardless of which PCI
1426 card it is. This is because all of the supported PCI cards have
1427 the same memory offset for the channel data. This will have to be
1428 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1429 states that the port offset is 0xC22 as opposed to 0xC02. This is
1430 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1431 On the PCI cards the number of ports is determined by reading a
1432 ID PROM located in the box attached to the card. The card can then
1433 determine the index the id to determine the number of ports available.
1434 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1435 if the box in question is a XEM or CX)).
1436 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001437 /* PCI cards are already remapped at this point ISA are not */
1438 bd->numports = readw(bd->re_map_membase + XEMPORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1440 nbdevs += (bd->numports);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001441 } else {
1442 /* Fix up the mappings for ISA/EISA etc */
1443 /* FIXME: 64K - can we be smarter ? */
1444 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 if (crd != 0)
1448 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1449 else
1450 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1451
1452 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1454
Alan Coxf2cf8e22005-09-06 15:16:44 -07001455 memaddr = bd->re_map_membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
1457 /* -----------------------------------------------------------------
1458 The below assignment will set bc to point at the BEGINING of
1459 the cards channel structures. For 1 card there will be between
1460 8 and 64 of these structures.
1461 -------------------------------------------------------------------- */
1462
Al Virobc9a5152005-09-15 22:53:28 +01001463 bc = memaddr + CHANSTRUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
1465 /* -------------------------------------------------------------------
1466 The below assignment will set gd to point at the BEGINING of
1467 global memory address 0xc00. The first data in that global
1468 memory actually starts at address 0xc1a. The command in
1469 pointer begins at 0xd10.
1470 ---------------------------------------------------------------------- */
1471
Al Virobc9a5152005-09-15 22:53:28 +01001472 gd = memaddr + GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 /* --------------------------------------------------------------------
1475 XEPORTS (address 0xc22) points at the number of channels the
1476 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1477 ----------------------------------------------------------------------- */
1478
Alan Coxf2cf8e22005-09-06 15:16:44 -07001479 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 shrinkmem = 1;
1481 if (bd->type < PCIXEM)
1482 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1483 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 memwinon(bd, 0);
1485
1486 /* --------------------------------------------------------------------
1487 Remember ch is the main drivers channels structure, while bc is
1488 the cards channel structure.
1489 ------------------------------------------------------------------------ */
1490
1491 /* For every port on the card do ..... */
1492
Alan Coxf2cf8e22005-09-06 15:16:44 -07001493 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1494 unsigned long flags;
Al Virobc9a5152005-09-15 22:53:28 +01001495 u16 tseg, rseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497 ch->brdchan = bc;
1498 ch->mailbox = gd;
1499 INIT_WORK(&ch->tqueue, do_softint, ch);
1500 ch->board = &boards[crd];
1501
Alan Coxf2cf8e22005-09-06 15:16:44 -07001502 spin_lock_irqsave(&epca_lock, flags);
1503 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 /* ----------------------------------------------------------------
1505 Since some of the boards use different bitmaps for their
1506 control signals we cannot hard code these values and retain
1507 portability. We virtualize this data here.
1508 ------------------------------------------------------------------- */
1509 case EISAXEM:
1510 case PCXEM:
1511 case PCIXEM:
1512 case PCIXRJ:
1513 case PCIXR:
1514 ch->m_rts = 0x02 ;
1515 ch->m_dcd = 0x80 ;
1516 ch->m_dsr = 0x20 ;
1517 ch->m_cts = 0x10 ;
1518 ch->m_ri = 0x40 ;
1519 ch->m_dtr = 0x01 ;
1520 break;
1521
1522 case PCXE:
1523 case PCXEVE:
1524 case PCXI:
1525 case PC64XE:
1526 ch->m_rts = 0x02 ;
1527 ch->m_dcd = 0x08 ;
1528 ch->m_dsr = 0x10 ;
1529 ch->m_cts = 0x20 ;
1530 ch->m_ri = 0x40 ;
1531 ch->m_dtr = 0x80 ;
1532 break;
1533
1534 } /* End switch bd->type */
1535
Alan Coxf2cf8e22005-09-06 15:16:44 -07001536 if (boards[crd].altpin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 ch->dsr = ch->m_dcd;
1538 ch->dcd = ch->m_dsr;
1539 ch->digiext.digi_flags |= DIGI_ALTPIN;
1540 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001541 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 ch->dcd = ch->m_dcd;
1543 ch->dsr = ch->m_dsr;
1544 }
1545
1546 ch->boardnum = crd;
1547 ch->channelnum = i;
1548 ch->magic = EPCA_MAGIC;
1549 ch->tty = NULL;
1550
Alan Coxf2cf8e22005-09-06 15:16:44 -07001551 if (shrinkmem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1553 shrinkmem = 0;
1554 }
1555
Al Virobc9a5152005-09-15 22:53:28 +01001556 tseg = readw(&bc->tseg);
1557 rseg = readw(&bc->rseg);
1558
Alan Coxf2cf8e22005-09-06 15:16:44 -07001559 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 case PCIXEM:
1562 case PCIXRJ:
1563 case PCIXR:
1564 /* Cover all the 2MEG cards */
Al Virobc9a5152005-09-15 22:53:28 +01001565 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1566 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1567 ch->txwin = FEPWIN | (tseg >> 11);
1568 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 break;
1570
1571 case PCXEM:
1572 case EISAXEM:
1573 /* Cover all the 32K windowed cards */
1574 /* Mask equal to window size - 1 */
Al Virobc9a5152005-09-15 22:53:28 +01001575 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1576 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1577 ch->txwin = FEPWIN | (tseg >> 11);
1578 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 break;
1580
1581 case PCXEVE:
1582 case PCXE:
Al Virobc9a5152005-09-15 22:53:28 +01001583 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1584 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1585 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1586 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 break;
1588
1589 case PCXI:
1590 case PC64XE:
Al Virobc9a5152005-09-15 22:53:28 +01001591 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1592 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 ch->txwin = ch->rxwin = 0;
1594 break;
1595
1596 } /* End switch bd->type */
1597
1598 ch->txbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001599 ch->txbufsize = readw(&bc->tmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601 ch->rxbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001602 ch->rxbufsize = readw(&bc->rmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
1604 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1605
1606 /* Set transmitter low water mark */
1607 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1608
1609 /* Set receiver low water mark */
1610
1611 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1612
1613 /* Set receiver high water mark */
1614
1615 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1616
Alan Coxf2cf8e22005-09-06 15:16:44 -07001617 writew(100, &bc->edelay);
1618 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
Alan Coxf2cf8e22005-09-06 15:16:44 -07001620 ch->startc = readb(&bc->startc);
1621 ch->stopc = readb(&bc->stopc);
1622 ch->startca = readb(&bc->startca);
1623 ch->stopca = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 ch->fepcflag = 0;
1626 ch->fepiflag = 0;
1627 ch->fepoflag = 0;
1628 ch->fepstartc = 0;
1629 ch->fepstopc = 0;
1630 ch->fepstartca = 0;
1631 ch->fepstopca = 0;
1632
1633 ch->close_delay = 50;
1634 ch->count = 0;
1635 ch->blocked_open = 0;
1636 init_waitqueue_head(&ch->open_wait);
1637 init_waitqueue_head(&ch->close_wait);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001638
1639 spin_unlock_irqrestore(&epca_lock, flags);
1640
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001642 if (!ch->tmp_buf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
1644 release_region((int)bd->port, 4);
1645 while(i-- > 0)
1646 kfree((ch--)->tmp_buf);
1647 return;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001648 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 memset((void *)ch->tmp_buf,0,ch->txbufsize);
1650 } /* End for each port */
1651
1652 printk(KERN_INFO
1653 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1654 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 memwinoff(bd, 0);
1656
1657} /* End post_fep_init */
1658
1659/* --------------------- Begin epcapoll ------------------------ */
1660
1661static void epcapoll(unsigned long ignored)
1662{ /* Begin epcapoll */
1663
1664 unsigned long flags;
1665 int crd;
1666 volatile unsigned int head, tail;
1667 struct channel *ch;
1668 struct board_info *bd;
1669
1670 /* -------------------------------------------------------------------
1671 This routine is called upon every timer interrupt. Even though
1672 the Digi series cards are capable of generating interrupts this
1673 method of non-looping polling is more efficient. This routine
1674 checks for card generated events (Such as receive data, are transmit
1675 buffer empty) and acts on those events.
1676 ----------------------------------------------------------------------- */
1677
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 for (crd = 0; crd < num_cards; crd++)
1679 { /* Begin for each card */
1680
1681 bd = &boards[crd];
1682 ch = card_ptr[crd];
1683
1684 if ((bd->status == DISABLED) || digi_poller_inhibited)
1685 continue; /* Begin loop next interation */
1686
1687 /* -----------------------------------------------------------
1688 assertmemoff is not needed here; indeed it is an empty subroutine.
1689 It is being kept because future boards may need this as well as
1690 some legacy boards.
1691 ---------------------------------------------------------------- */
1692
Alan Coxf2cf8e22005-09-06 15:16:44 -07001693 spin_lock_irqsave(&epca_lock, flags);
1694
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 assertmemoff(ch);
1696
1697 globalwinon(ch);
1698
1699 /* ---------------------------------------------------------------
1700 In this case head and tail actually refer to the event queue not
1701 the transmit or receive queue.
1702 ------------------------------------------------------------------- */
1703
Alan Coxf2cf8e22005-09-06 15:16:44 -07001704 head = readw(&ch->mailbox->ein);
1705 tail = readw(&ch->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 /* If head isn't equal to tail we have an event */
1708
1709 if (head != tail)
1710 doevent(crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 memoff(ch);
1712
Alan Coxf2cf8e22005-09-06 15:16:44 -07001713 spin_unlock_irqrestore(&epca_lock, flags);
1714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 mod_timer(&epca_timer, jiffies + (HZ / 25));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717} /* End epcapoll */
1718
1719/* --------------------- Begin doevent ------------------------ */
1720
1721static void doevent(int crd)
1722{ /* Begin doevent */
1723
Al Virobc9a5152005-09-15 22:53:28 +01001724 void __iomem *eventbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 struct channel *ch, *chan0;
1726 static struct tty_struct *tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001727 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001728 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001729 unsigned int tail, head;
1730 int event, channel;
1731 int mstat, lstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 /* -------------------------------------------------------------------
1734 This subroutine is called by epcapoll when an event is detected
1735 in the event queue. This routine responds to those events.
1736 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 bd = &boards[crd];
1738
1739 chan0 = card_ptr[crd];
1740 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001742 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 { /* Begin while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001745 eventbuf = bd->re_map_membase + tail + ISTART;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 /* Get the channel the event occurred on */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001747 channel = readb(eventbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 /* Get the actual event code that occurred */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001749 event = readb(eventbuf + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 /* ----------------------------------------------------------------
1751 The two assignments below get the current modem status (mstat)
1752 and the previous modem status (lstat). These are useful becuase
1753 an event could signal a change in modem signals itself.
1754 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001755 mstat = readb(eventbuf + 2);
1756 lstat = readb(eventbuf + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
1758 ch = chan0 + channel;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001759 if ((unsigned)channel >= bd->numports || !ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 if (channel >= bd->numports)
1761 ch = chan0;
1762 bc = ch->brdchan;
1763 goto next;
1764 }
1765
1766 if ((bc = ch->brdchan) == NULL)
1767 goto next;
1768
Alan Coxf2cf8e22005-09-06 15:16:44 -07001769 if (event & DATA_IND) { /* Begin DATA_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 receive_data(ch);
1771 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 } /* End DATA_IND */
1773 /* else *//* Fix for DCD transition missed bug */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001774 if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 /* A modem signal change has been indicated */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 ch->imodem = mstat;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001777 if (ch->asyncflags & ASYNC_CHECK_CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 if (mstat & ch->dcd) /* We are now receiving dcd */
1779 wake_up_interruptible(&ch->open_wait);
1780 else
1781 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 } /* End MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 tty = ch->tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001785 if (tty) { /* Begin if valid tty */
1786 if (event & BREAK_IND) { /* Begin if BREAK_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 /* A break has been indicated */
Alan Cox33f0f882006-01-09 20:54:13 -08001788 tty_insert_flip_char(tty, 0, TTY_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 tty_schedule_flip(tty);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001790 } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 if (ch->statusflags & LOWWAIT)
1792 { /* Begin if LOWWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 ch->statusflags &= ~LOWWAIT;
1794 tty_wakeup(tty);
1795 wake_up_interruptible(&tty->write_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 } /* End if LOWWAIT */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001797 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 /* This event is generated by setup_empty_event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 ch->statusflags &= ~TXBUSY;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001800 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 ch->statusflags &= ~EMPTYWAIT;
1802 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 wake_up_interruptible(&tty->write_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 } /* End if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 } /* End EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 } /* End if valid tty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 next:
1808 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001809 BUG_ON(!bc);
1810 writew(1, &bc->idata);
1811 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 globalwinon(chan0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 } /* End while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814} /* End doevent */
1815
1816/* --------------------- Begin fepcmd ------------------------ */
1817
1818static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1819 int byte2, int ncmds, int bytecmd)
1820{ /* Begin fepcmd */
Al Virobc9a5152005-09-15 22:53:28 +01001821 unchar __iomem *memaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 unsigned int head, cmdTail, cmdStart, cmdMax;
1823 long count;
1824 int n;
1825
1826 /* This is the routine in which commands may be passed to the card. */
1827
1828 if (ch->board->status == DISABLED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 /* Remember head (As well as max) is just an offset not a base addr */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001832 head = readw(&ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 /* cmdStart is a base address */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001834 cmdStart = readw(&ch->mailbox->cstart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 /* ------------------------------------------------------------------
1836 We do the addition below because we do not want a max pointer
1837 relative to cmdStart. We want a max pointer that points at the
1838 physical end of the command queue.
1839 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001840 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 memaddr = ch->board->re_map_membase;
1842
Alan Coxf2cf8e22005-09-06 15:16:44 -07001843 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1844 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1845 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 return;
1847 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001848 if (bytecmd) {
1849 writeb(cmd, memaddr + head + cmdStart + 0);
1850 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 /* Below word_or_byte is bits to set */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001852 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 /* Below byte2 is bits to reset */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001854 writeb(byte2, memaddr + head + cmdStart + 3);
1855 } else {
1856 writeb(cmd, memaddr + head + cmdStart + 0);
1857 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1858 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 head = (head + 4) & (cmdMax - cmdStart - 4);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001861 writew(head, &ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 count = FEPTIMEOUT;
1863
Alan Coxf2cf8e22005-09-06 15:16:44 -07001864 for (;;) { /* Begin forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 count--;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001866 if (count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1868 return;
1869 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001870 head = readw(&ch->mailbox->cin);
1871 cmdTail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 /* ----------------------------------------------------------
1874 Basically this will break when the FEP acknowledges the
1875 command by incrementing cmdTail (Making it equal to head).
1876 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 if (n <= ncmds * (sizeof(short) * 4))
1878 break; /* Well nearly forever :-) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 } /* End forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880} /* End fepcmd */
1881
1882/* ---------------------------------------------------------------------
1883 Digi products use fields in their channels structures that are very
1884 similar to the c_cflag and c_iflag fields typically found in UNIX
1885 termios structures. The below three routines allow mappings
1886 between these hardware "flags" and their respective Linux flags.
1887------------------------------------------------------------------------- */
1888
1889/* --------------------- Begin termios2digi_h -------------------- */
1890
1891static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1892{ /* Begin termios2digi_h */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 unsigned res = 0;
1894
Alan Coxf2cf8e22005-09-06 15:16:44 -07001895 if (cflag & CRTSCTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1897 res |= ((ch->m_cts) | (ch->m_rts));
1898 }
1899
1900 if (ch->digiext.digi_flags & RTSPACE)
1901 res |= ch->m_rts;
1902
1903 if (ch->digiext.digi_flags & DTRPACE)
1904 res |= ch->m_dtr;
1905
1906 if (ch->digiext.digi_flags & CTSPACE)
1907 res |= ch->m_cts;
1908
1909 if (ch->digiext.digi_flags & DSRPACE)
1910 res |= ch->dsr;
1911
1912 if (ch->digiext.digi_flags & DCDPACE)
1913 res |= ch->dcd;
1914
1915 if (res & (ch->m_rts))
1916 ch->digiext.digi_flags |= RTSPACE;
1917
1918 if (res & (ch->m_cts))
1919 ch->digiext.digi_flags |= CTSPACE;
1920
1921 return res;
1922
1923} /* End termios2digi_h */
1924
1925/* --------------------- Begin termios2digi_i -------------------- */
1926static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1927{ /* Begin termios2digi_i */
1928
1929 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1930 INPCK | ISTRIP|IXON|IXANY|IXOFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 if (ch->digiext.digi_flags & DIGI_AIXON)
1932 res |= IAIXON;
1933 return res;
1934
1935} /* End termios2digi_i */
1936
1937/* --------------------- Begin termios2digi_c -------------------- */
1938
1939static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1940{ /* Begin termios2digi_c */
1941
1942 unsigned res = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001943 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 ch->digiext.digi_flags |= DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 /* -------------------------------------------------------------
1946 HUPCL bit is used by FEP to indicate fast baud
1947 table is to be used.
1948 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 res |= FEP_HUPCL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 } /* End detected CBAUDEX */
1951 else ch->digiext.digi_flags &= ~DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 /* -------------------------------------------------------------------
1953 CBAUD has bit position 0x1000 set these days to indicate Linux
1954 baud rate remap. Digi hardware can't handle the bit assignment.
1955 (We use a different bit assignment for high speed.). Clear this
1956 bit out.
1957 ---------------------------------------------------------------------- */
1958 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 /* -------------------------------------------------------------
1960 This gets a little confusing. The Digi cards have their own
1961 representation of c_cflags controling baud rate. For the most
1962 part this is identical to the Linux implementation. However;
1963 Digi supports one rate (76800) that Linux doesn't. This means
1964 that the c_cflag entry that would normally mean 76800 for Digi
1965 actually means 115200 under Linux. Without the below mapping,
1966 a stty 115200 would only drive the board at 76800. Since
1967 the rate 230400 is also found after 76800, the same problem afflicts
1968 us when we choose a rate of 230400. Without the below modificiation
1969 stty 230400 would actually give us 115200.
1970
1971 There are two additional differences. The Linux value for CLOCAL
1972 (0x800; 0004000) has no meaning to the Digi hardware. Also in
1973 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
1974 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
1975 should be checked for a screened out prior to termios2digi_c
1976 returning. Since CLOCAL isn't used by the board this can be
1977 ignored as long as the returned value is used only by Digi hardware.
Alan Coxf2cf8e22005-09-06 15:16:44 -07001978 ----------------------------------------------------------------- */
1979 if (cflag & CBAUDEX) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 /* -------------------------------------------------------------
1981 The below code is trying to guarantee that only baud rates
1982 115200 and 230400 are remapped. We use exclusive or because
1983 the various baud rates share common bit positions and therefore
1984 can't be tested for easily.
1985 ----------------------------------------------------------------- */
1986
1987
1988 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1989 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 res += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 return res;
1993
1994} /* End termios2digi_c */
1995
1996/* --------------------- Begin epcaparam ----------------------- */
1997
Alan Coxf2cf8e22005-09-06 15:16:44 -07001998/* Caller must hold the locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999static void epcaparam(struct tty_struct *tty, struct channel *ch)
2000{ /* Begin epcaparam */
2001
2002 unsigned int cmdHead;
2003 struct termios *ts;
Al Virobc9a5152005-09-15 22:53:28 +01002004 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 unsigned mval, hflow, cflag, iflag;
2006
2007 bc = ch->brdchan;
2008 epcaassert(bc !=0, "bc out of range");
2009
2010 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 ts = tty->termios;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002012 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2013 cmdHead = readw(&bc->rin);
Al Virobc9a5152005-09-15 22:53:28 +01002014 writew(cmdHead, &bc->rout);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002015 cmdHead = readw(&bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 /* Changing baud in mid-stream transmission can be wonderful */
2017 /* ---------------------------------------------------------------
2018 Flush current transmit buffer by setting cmdTail pointer (tout)
2019 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2020 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2022 mval = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002023 } else { /* Begin CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 /* -------------------------------------------------------------------
2025 c_cflags have changed but that change had nothing to do with BAUD.
2026 Propagate the change to the card.
2027 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 cflag = termios2digi_c(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002029 if (cflag != ch->fepcflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 ch->fepcflag = cflag;
2031 /* Set baud rate, char size, stop bits, parity */
2032 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 /* ----------------------------------------------------------------
2035 If the user has not forced CLOCAL and if the device is not a
2036 CALLOUT device (Which is always CLOCAL) we set flags such that
2037 the driver will wait on carrier detect.
2038 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 if (ts->c_cflag & CLOCAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 ch->asyncflags &= ~ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 ch->asyncflags |= ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 mval = ch->m_dtr | ch->m_rts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 } /* End CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 iflag = termios2digi_i(ch, ts->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 /* Check input mode flags */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002047 if (iflag != ch->fepiflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 ch->fepiflag = iflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 /* ---------------------------------------------------------------
2050 Command sets channels iflag structure on the board. Such things
2051 as input soft flow control, handling of parity errors, and
2052 break handling are all set here.
2053 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 /* break handling, parity handling, input stripping, flow control chars */
2055 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 /* ---------------------------------------------------------------
2058 Set the board mint value for this channel. This will cause hardware
2059 events to be generated each time the DCD signal (Described in mint)
2060 changes.
2061 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002062 writeb(ch->dcd, &bc->mint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2064 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002065 writeb(0, &bc->mint);
2066 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 hflow = termios2digi_h(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002068 if (hflow != ch->hflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 ch->hflow = hflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 /* --------------------------------------------------------------
2071 Hard flow control has been selected but the board is not
2072 using it. Activate hard flow control now.
2073 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 mval ^= ch->modemfake & (mval ^ ch->modem);
2077
Alan Coxf2cf8e22005-09-06 15:16:44 -07002078 if (ch->omodem ^ mval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 ch->omodem = mval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 /* --------------------------------------------------------------
2081 The below command sets the DTR and RTS mstat structure. If
2082 hard flow control is NOT active these changes will drive the
2083 output of the actual DTR and RTS lines. If hard flow control
2084 is active, the changes will be saved in the mstat structure and
2085 only asserted when hard flow control is turned off.
2086 ----------------------------------------------------------------- */
2087
2088 /* First reset DTR & RTS; then set them */
2089 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2090 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002092 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 ch->fepstartc = ch->startc;
2094 ch->fepstopc = ch->stopc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 /* ------------------------------------------------------------
2096 The XON / XOFF characters have changed; propagate these
2097 changes to the card.
2098 --------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2100 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002101 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 ch->fepstartca = ch->startca;
2103 ch->fepstopca = ch->stopca;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 /* ---------------------------------------------------------------
2105 Similar to the above, this time the auxilarly XON / XOFF
2106 characters have changed; propagate these changes to the card.
2107 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110} /* End epcaparam */
2111
2112/* --------------------- Begin receive_data ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002113/* Caller holds lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114static void receive_data(struct channel *ch)
2115{ /* Begin receive_data */
2116
2117 unchar *rptr;
2118 struct termios *ts = NULL;
2119 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +01002120 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002121 int dataToRead, wrapgap, bytesAvailable;
2122 unsigned int tail, head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 unsigned int wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 /* ---------------------------------------------------------------
2126 This routine is called by doint when a receive data event
2127 has taken place.
2128 ------------------------------------------------------------------- */
2129
2130 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 if (ch->statusflags & RXSTOPPED)
2132 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 tty = ch->tty;
2134 if (tty)
2135 ts = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002137 BUG_ON(!bc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 wrapmask = ch->rxbufsize - 1;
2139
2140 /* ---------------------------------------------------------------------
2141 Get the head and tail pointers to the receiver queue. Wrap the
2142 head pointer if it has reached the end of the buffer.
2143 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002144 head = readw(&bc->rin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 head &= wrapmask;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002146 tail = readw(&bc->rout) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
2148 bytesAvailable = (head - tail) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 if (bytesAvailable == 0)
2150 return;
2151
2152 /* ------------------------------------------------------------------
2153 If CREAD bit is off or device not open, set TX tail to head
2154 --------------------------------------------------------------------- */
2155
Alan Coxf2cf8e22005-09-06 15:16:44 -07002156 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
Al Virobc9a5152005-09-15 22:53:28 +01002157 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 return;
2159 }
2160
Alan Cox33f0f882006-01-09 20:54:13 -08002161 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 return;
2163
Alan Coxf2cf8e22005-09-06 15:16:44 -07002164 if (readb(&bc->orun)) {
2165 writeb(0, &bc->orun);
2166 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
Alan Cox33f0f882006-01-09 20:54:13 -08002167 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 rxwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002170 while (bytesAvailable > 0) { /* Begin while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 /* ---------------------------------------------------------------
2173 Even if head has wrapped around only report the amount of
2174 data to be equal to the size - tail. Remember memcpy can't
2175 automaticly wrap around the receive buffer.
2176 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 /* --------------------------------------------------------------
2179 Make sure we don't overflow the buffer
2180 ----------------------------------------------------------------- */
Alan Cox33f0f882006-01-09 20:54:13 -08002181 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 if (dataToRead == 0)
2183 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 /* ---------------------------------------------------------------
2185 Move data read from our card into the line disciplines buffer
2186 for translation if necessary.
2187 ------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002188 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 tail = (tail + dataToRead) & wrapmask;
2190 bytesAvailable -= dataToRead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 } /* End while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002193 writew(tail, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 /* Must be called with global data */
2195 tty_schedule_flip(ch->tty);
2196 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197} /* End receive_data */
2198
2199static int info_ioctl(struct tty_struct *tty, struct file * file,
2200 unsigned int cmd, unsigned long arg)
2201{
2202 switch (cmd)
2203 { /* Begin switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 case DIGI_GETINFO:
2205 { /* Begin case DIGI_GETINFO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 struct digi_info di ;
2207 int brd;
2208
Alan Coxf2cf8e22005-09-06 15:16:44 -07002209 if(get_user(brd, (unsigned int __user *)arg))
2210 return -EFAULT;
2211 if (brd < 0 || brd >= num_cards || num_cards == 0)
2212 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
2214 memset(&di, 0, sizeof(di));
2215
2216 di.board = brd ;
2217 di.status = boards[brd].status;
2218 di.type = boards[brd].type ;
2219 di.numports = boards[brd].numports ;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002220 /* Legacy fixups - just move along nothing to see */
2221 di.port = (unsigned char *)boards[brd].port ;
2222 di.membase = (unsigned char *)boards[brd].membase ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
2224 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2225 return -EFAULT;
2226 break;
2227
2228 } /* End case DIGI_GETINFO */
2229
2230 case DIGI_POLLER:
2231 { /* Begin case DIGI_POLLER */
2232
2233 int brd = arg & 0xff000000 >> 16 ;
2234 unsigned char state = arg & 0xff ;
2235
Alan Coxf2cf8e22005-09-06 15:16:44 -07002236 if (brd < 0 || brd >= num_cards) {
2237 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 return (-ENODEV);
2239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 digi_poller_inhibited = state ;
2241 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 } /* End case DIGI_POLLER */
2243
2244 case DIGI_INIT:
2245 { /* Begin case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 /* ------------------------------------------------------------
2247 This call is made by the apps to complete the initilization
2248 of the board(s). This routine is responsible for setting
2249 the card to its initial state and setting the drivers control
2250 fields to the sutianle settings for the card in question.
2251 ---------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 int crd ;
2253 for (crd = 0; crd < num_cards; crd++)
2254 post_fep_init (crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 } /* End case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002258 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 } /* End switch cmd */
2260 return (0) ;
2261}
2262/* --------------------- Begin pc_ioctl ----------------------- */
2263
2264static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2265{
2266 struct channel *ch = (struct channel *) tty->driver_data;
Al Virobc9a5152005-09-15 22:53:28 +01002267 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 unsigned int mstat, mflag = 0;
2269 unsigned long flags;
2270
2271 if (ch)
2272 bc = ch->brdchan;
2273 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002274 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Alan Coxf2cf8e22005-09-06 15:16:44 -07002276 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002278 mstat = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002280 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
2282 if (mstat & ch->m_dtr)
2283 mflag |= TIOCM_DTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 if (mstat & ch->m_rts)
2285 mflag |= TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 if (mstat & ch->m_cts)
2287 mflag |= TIOCM_CTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 if (mstat & ch->dsr)
2289 mflag |= TIOCM_DSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 if (mstat & ch->m_ri)
2291 mflag |= TIOCM_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 if (mstat & ch->dcd)
2293 mflag |= TIOCM_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 return mflag;
2295}
2296
2297static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2298 unsigned int set, unsigned int clear)
2299{
2300 struct channel *ch = (struct channel *) tty->driver_data;
2301 unsigned long flags;
2302
Alan Coxf2cf8e22005-09-06 15:16:44 -07002303 if (!ch)
2304 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Alan Coxf2cf8e22005-09-06 15:16:44 -07002306 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 /*
2308 * I think this modemfake stuff is broken. It doesn't
2309 * correctly reflect the behaviour desired by the TIOCM*
2310 * ioctls. Therefore this is probably broken.
2311 */
2312 if (set & TIOCM_RTS) {
2313 ch->modemfake |= ch->m_rts;
2314 ch->modem |= ch->m_rts;
2315 }
2316 if (set & TIOCM_DTR) {
2317 ch->modemfake |= ch->m_dtr;
2318 ch->modem |= ch->m_dtr;
2319 }
2320 if (clear & TIOCM_RTS) {
2321 ch->modemfake |= ch->m_rts;
2322 ch->modem &= ~ch->m_rts;
2323 }
2324 if (clear & TIOCM_DTR) {
2325 ch->modemfake |= ch->m_dtr;
2326 ch->modem &= ~ch->m_dtr;
2327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 /* --------------------------------------------------------------
2330 The below routine generally sets up parity, baud, flow control
2331 issues, etc.... It effect both control flags and input flags.
2332 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 epcaparam(tty,ch);
2334 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002335 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 return 0;
2337}
2338
2339static int pc_ioctl(struct tty_struct *tty, struct file * file,
2340 unsigned int cmd, unsigned long arg)
2341{ /* Begin pc_ioctl */
2342
2343 digiflow_t dflow;
2344 int retval;
2345 unsigned long flags;
2346 unsigned int mflag, mstat;
2347 unsigned char startc, stopc;
Al Virobc9a5152005-09-15 22:53:28 +01002348 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 struct channel *ch = (struct channel *) tty->driver_data;
2350 void __user *argp = (void __user *)arg;
2351
2352 if (ch)
2353 bc = ch->brdchan;
2354 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002355 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
2357 /* -------------------------------------------------------------------
2358 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2359 in /usr/src/linux/drivers/char for a good example. In particular
2360 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2361 ---------------------------------------------------------------------- */
2362
2363 switch (cmd)
2364 { /* Begin switch cmd */
2365
2366 case TCGETS:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002367 if (copy_to_user(argp, tty->termios, sizeof(struct termios)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 return -EFAULT;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002369 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 case TCGETA:
2371 return get_termio(tty, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 case TCSBRK: /* SVID version: non-zero arg --> no break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 retval = tty_check_change(tty);
2374 if (retval)
2375 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002377 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002379 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 tty_wait_until_sent(tty, 0);
2381 if (!arg)
2382 digi_send_break(ch, HZ/4); /* 1/4 second */
2383 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 case TCSBRKP: /* support for POSIX tcsendbreak() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 retval = tty_check_change(tty);
2386 if (retval)
2387 return retval;
2388
2389 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002390 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002392 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 tty_wait_until_sent(tty, 0);
2394 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2395 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 case TIOCGSOFTCAR:
2397 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2398 return -EFAULT;
2399 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 case TIOCSSOFTCAR:
2401 {
2402 unsigned int value;
2403
2404 if (get_user(value, (unsigned __user *)argp))
2405 return -EFAULT;
2406 tty->termios->c_cflag =
2407 ((tty->termios->c_cflag & ~CLOCAL) |
2408 (value ? CLOCAL : 0));
2409 return 0;
2410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 case TIOCMODG:
2412 mflag = pc_tiocmget(tty, file);
2413 if (put_user(mflag, (unsigned long __user *)argp))
2414 return -EFAULT;
2415 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 case TIOCMODS:
2417 if (get_user(mstat, (unsigned __user *)argp))
2418 return -EFAULT;
2419 return pc_tiocmset(tty, file, mstat, ~mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 case TIOCSDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002421 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 ch->omodem |= ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 globalwinon(ch);
2424 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2425 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002426 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 break;
2428
2429 case TIOCCDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002430 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 ch->omodem &= ~ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 globalwinon(ch);
2433 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2434 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002435 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 case DIGI_GETA:
2438 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2439 return -EFAULT;
2440 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 case DIGI_SETAW:
2442 case DIGI_SETAF:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002443 if (cmd == DIGI_SETAW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002445 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002447 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 tty_wait_until_sent(tty, 0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002449 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 /* ldisc lock already held in ioctl */
2451 if (tty->ldisc.flush_buffer)
2452 tty->ldisc.flush_buffer(tty);
2453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 /* Fall Thru */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 case DIGI_SETA:
2456 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2457 return -EFAULT;
2458
Alan Coxf2cf8e22005-09-06 15:16:44 -07002459 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 ch->dcd = ch->m_dsr;
2461 ch->dsr = ch->m_dcd;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002462 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 ch->dcd = ch->m_dcd;
2464 ch->dsr = ch->m_dsr;
2465 }
2466
Alan Coxf2cf8e22005-09-06 15:16:44 -07002467 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 globalwinon(ch);
2469
2470 /* -----------------------------------------------------------------
2471 The below routine generally sets up parity, baud, flow control
2472 issues, etc.... It effect both control flags and input flags.
2473 ------------------------------------------------------------------- */
2474
2475 epcaparam(tty,ch);
2476 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002477 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 break;
2479
2480 case DIGI_GETFLOW:
2481 case DIGI_GETAFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002482 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002484 if (cmd == DIGI_GETFLOW) {
2485 dflow.startc = readb(&bc->startc);
2486 dflow.stopc = readb(&bc->stopc);
2487 } else {
2488 dflow.startc = readb(&bc->startca);
2489 dflow.stopc = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 }
2491 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002492 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
2494 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2495 return -EFAULT;
2496 break;
2497
2498 case DIGI_SETAFLOW:
2499 case DIGI_SETFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002500 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 startc = ch->startc;
2502 stopc = ch->stopc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002503 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 startc = ch->startca;
2505 stopc = ch->stopca;
2506 }
2507
2508 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2509 return -EFAULT;
2510
Alan Coxf2cf8e22005-09-06 15:16:44 -07002511 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2512 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 globalwinon(ch);
2514
Alan Coxf2cf8e22005-09-06 15:16:44 -07002515 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 ch->fepstartc = ch->startc = dflow.startc;
2517 ch->fepstopc = ch->stopc = dflow.stopc;
2518 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002519 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 ch->fepstartca = ch->startca = dflow.startc;
2521 ch->fepstopca = ch->stopca = dflow.stopc;
2522 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2523 }
2524
Alan Coxf2cf8e22005-09-06 15:16:44 -07002525 if (ch->statusflags & TXSTOPPED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 pc_start(tty);
2527
2528 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002529 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 } /* End if setflow toggled */
2531 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 default:
2533 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 } /* End switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536} /* End pc_ioctl */
2537
2538/* --------------------- Begin pc_set_termios ----------------------- */
2539
2540static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
2541{ /* Begin pc_set_termios */
2542
2543 struct channel *ch;
2544 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 /* ---------------------------------------------------------
2546 verifyChannel returns the channel from the tty struct
2547 if it is valid. This serves as a sanity check.
2548 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002549 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2550 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 globalwinon(ch);
2552 epcaparam(tty, ch);
2553 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002554 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
2556 if ((old_termios->c_cflag & CRTSCTS) &&
2557 ((tty->termios->c_cflag & CRTSCTS) == 0))
2558 tty->hw_stopped = 0;
2559
2560 if (!(old_termios->c_cflag & CLOCAL) &&
2561 (tty->termios->c_cflag & CLOCAL))
2562 wake_up_interruptible(&ch->open_wait);
2563
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 } /* End if channel valid */
2565
2566} /* End pc_set_termios */
2567
2568/* --------------------- Begin do_softint ----------------------- */
2569
2570static void do_softint(void *private_)
2571{ /* Begin do_softint */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 struct channel *ch = (struct channel *) private_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 /* Called in response to a modem change event */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002574 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 struct tty_struct *tty = ch->tty;
2576
Alan Coxf2cf8e22005-09-06 15:16:44 -07002577 if (tty && tty->driver_data) {
2578 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2580 wake_up_interruptible(&ch->open_wait);
2581 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 } /* End if clear_bit */
2583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 } /* End EPCA_MAGIC */
2585} /* End do_softint */
2586
2587/* ------------------------------------------------------------
2588 pc_stop and pc_start provide software flow control to the
2589 routine and the pc_ioctl routine.
2590---------------------------------------------------------------- */
2591
2592/* --------------------- Begin pc_stop ----------------------- */
2593
2594static void pc_stop(struct tty_struct *tty)
2595{ /* Begin pc_stop */
2596
2597 struct channel *ch;
2598 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 /* ---------------------------------------------------------
2600 verifyChannel returns the channel from the tty struct
2601 if it is valid. This serves as a sanity check.
2602 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002603 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
2604 spin_lock_irqsave(&epca_lock, flags);
2605 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 /* STOP transmitting now !! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 ch->statusflags |= TXSTOPPED;
2610 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 } /* End if transmit stop requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002612 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 } /* End if valid channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614} /* End pc_stop */
2615
2616/* --------------------- Begin pc_start ----------------------- */
2617
2618static void pc_start(struct tty_struct *tty)
2619{ /* Begin pc_start */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 /* ---------------------------------------------------------
2622 verifyChannel returns the channel from the tty struct
2623 if it is valid. This serves as a sanity check.
2624 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002625 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002627 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002629 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
Al Virobc9a5152005-09-15 22:53:28 +01002630 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 globalwinon(ch);
2632 bc = ch->brdchan;
2633 if (ch->statusflags & LOWWAIT)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002634 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 /* Okay, you can start transmitting again... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 ch->statusflags &= ~TXSTOPPED;
2638 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 } /* End transmit resume requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002640 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642} /* End pc_start */
2643
2644/* ------------------------------------------------------------------
2645 The below routines pc_throttle and pc_unthrottle are used
2646 to slow (And resume) the receipt of data into the kernels
2647 receive buffers. The exact occurrence of this depends on the
2648 size of the kernels receive buffer and what the 'watermarks'
2649 are set to for that buffer. See the n_ttys.c file for more
2650 details.
2651______________________________________________________________________ */
2652/* --------------------- Begin throttle ----------------------- */
2653
2654static void pc_throttle(struct tty_struct * tty)
2655{ /* Begin pc_throttle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 struct channel *ch;
2657 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 /* ---------------------------------------------------------
2659 verifyChannel returns the channel from the tty struct
2660 if it is valid. This serves as a sanity check.
2661 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002662 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2663 spin_lock_irqsave(&epca_lock, flags);
2664 if ((ch->statusflags & RXSTOPPED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 globalwinon(ch);
2666 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 ch->statusflags |= RXSTOPPED;
2668 memoff(ch);
2669 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002670 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672} /* End pc_throttle */
2673
2674/* --------------------- Begin unthrottle ----------------------- */
2675
2676static void pc_unthrottle(struct tty_struct *tty)
2677{ /* Begin pc_unthrottle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 struct channel *ch;
2679 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 /* ---------------------------------------------------------
2681 verifyChannel returns the channel from the tty struct
2682 if it is valid. This serves as a sanity check.
2683 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002684 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002686 spin_lock_irqsave(&epca_lock, flags);
2687 if (ch->statusflags & RXSTOPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 ch->statusflags &= ~RXSTOPPED;
2691 memoff(ch);
2692 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002693 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695} /* End pc_unthrottle */
2696
2697/* --------------------- Begin digi_send_break ----------------------- */
2698
2699void digi_send_break(struct channel *ch, int msec)
2700{ /* Begin digi_send_break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 unsigned long flags;
2702
Alan Coxf2cf8e22005-09-06 15:16:44 -07002703 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 /* --------------------------------------------------------------------
2706 Maybe I should send an infinite break here, schedule() for
2707 msec amount of time, and then stop the break. This way,
2708 the user can't screw up the FEP by causing digi_send_break()
2709 to be called (i.e. via an ioctl()) more than once in msec amount
2710 of time. Try this for now...
2711 ------------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2713 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002714 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715} /* End digi_send_break */
2716
2717/* --------------------- Begin setup_empty_event ----------------------- */
2718
Alan Coxf2cf8e22005-09-06 15:16:44 -07002719/* Caller MUST hold the lock */
2720
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2722{ /* Begin setup_empty_event */
2723
Al Virobc9a5152005-09-15 22:53:28 +01002724 struct board_chan __iomem *bc = ch->brdchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 globalwinon(ch);
2727 ch->statusflags |= EMPTYWAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 /* ------------------------------------------------------------------
2729 When set the iempty flag request a event to be generated when the
2730 transmit buffer is empty (If there is no BREAK in progress).
2731 --------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002732 writeb(1, &bc->iempty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734} /* End setup_empty_event */
2735
2736/* --------------------- Begin get_termio ----------------------- */
2737
2738static int get_termio(struct tty_struct * tty, struct termio __user * termio)
2739{ /* Begin get_termio */
2740 return kernel_termios_to_user_termio(termio, tty->termios);
2741} /* End get_termio */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743/* ---------------------- Begin epca_setup -------------------------- */
2744void epca_setup(char *str, int *ints)
2745{ /* Begin epca_setup */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 struct board_info board;
2747 int index, loop, last;
2748 char *temp, *t2;
2749 unsigned len;
2750
2751 /* ----------------------------------------------------------------------
2752 If this routine looks a little strange it is because it is only called
2753 if a LILO append command is given to boot the kernel with parameters.
2754 In this way, we can provide the user a method of changing his board
2755 configuration without rebuilding the kernel.
2756 ----------------------------------------------------------------------- */
2757 if (!liloconfig)
2758 liloconfig = 1;
2759
2760 memset(&board, 0, sizeof(board));
2761
2762 /* Assume the data is int first, later we can change it */
2763 /* I think that array position 0 of ints holds the number of args */
2764 for (last = 0, index = 1; index <= ints[0]; index++)
2765 switch(index)
2766 { /* Begin parse switch */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 case 1:
2768 board.status = ints[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 /* ---------------------------------------------------------
2770 We check for 2 (As opposed to 1; because 2 is a flag
2771 instructing the driver to ignore epcaconfig.) For this
2772 reason we check for 2.
2773 ------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002774 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 nbdevs = 0;
2776 num_cards = 0;
2777 return;
2778 } /* End ignore epcaconfig as well as lilo cmd line */
2779
Alan Coxf2cf8e22005-09-06 15:16:44 -07002780 if (board.status > 2) {
2781 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 invalid_lilo_config = 1;
2783 setup_error_code |= INVALID_BOARD_STATUS;
2784 return;
2785 }
2786 last = index;
2787 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 case 2:
2789 board.type = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002790 if (board.type >= PCIXEM) {
2791 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 invalid_lilo_config = 1;
2793 setup_error_code |= INVALID_BOARD_TYPE;
2794 return;
2795 }
2796 last = index;
2797 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 case 3:
2799 board.altpin = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002800 if (board.altpin > 1) {
2801 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 invalid_lilo_config = 1;
2803 setup_error_code |= INVALID_ALTPIN;
2804 return;
2805 }
2806 last = index;
2807 break;
2808
2809 case 4:
2810 board.numports = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002811 if (board.numports < 2 || board.numports > 256) {
2812 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 invalid_lilo_config = 1;
2814 setup_error_code |= INVALID_NUM_PORTS;
2815 return;
2816 }
2817 nbdevs += board.numports;
2818 last = index;
2819 break;
2820
2821 case 5:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002822 board.port = ints[index];
2823 if (ints[index] <= 0) {
2824 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 invalid_lilo_config = 1;
2826 setup_error_code |= INVALID_PORT_BASE;
2827 return;
2828 }
2829 last = index;
2830 break;
2831
2832 case 6:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002833 board.membase = ints[index];
2834 if (ints[index] <= 0) {
2835 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 invalid_lilo_config = 1;
2837 setup_error_code |= INVALID_MEM_BASE;
2838 return;
2839 }
2840 last = index;
2841 break;
2842
2843 default:
2844 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2845 return;
2846
2847 } /* End parse switch */
2848
Alan Coxf2cf8e22005-09-06 15:16:44 -07002849 while (str && *str) { /* Begin while there is a string arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 /* find the next comma or terminator */
2851 temp = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 /* While string is not null, and a comma hasn't been found */
2853 while (*temp && (*temp != ','))
2854 temp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 if (!*temp)
2856 temp = NULL;
2857 else
2858 *temp++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 /* Set index to the number of args + 1 */
2860 index = last + 1;
2861
2862 switch(index)
2863 {
2864 case 1:
2865 len = strlen(str);
2866 if (strncmp("Disable", str, len) == 0)
2867 board.status = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002868 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 board.status = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002870 else {
2871 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 invalid_lilo_config = 1;
2873 setup_error_code |= INVALID_BOARD_STATUS;
2874 return;
2875 }
2876 last = index;
2877 break;
2878
2879 case 2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
2881 if (strcmp(board_desc[loop], str) == 0)
2882 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 /* ---------------------------------------------------------------
2884 If the index incremented above refers to a legitamate board
2885 type set it here.
2886 ------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 if (index < EPCA_NUM_TYPES)
2888 board.type = loop;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002889 else {
2890 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 invalid_lilo_config = 1;
2892 setup_error_code |= INVALID_BOARD_TYPE;
2893 return;
2894 }
2895 last = index;
2896 break;
2897
2898 case 3:
2899 len = strlen(str);
2900 if (strncmp("Disable", str, len) == 0)
2901 board.altpin = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002902 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 board.altpin = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002904 else {
2905 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 invalid_lilo_config = 1;
2907 setup_error_code |= INVALID_ALTPIN;
2908 return;
2909 }
2910 last = index;
2911 break;
2912
2913 case 4:
2914 t2 = str;
2915 while (isdigit(*t2))
2916 t2++;
2917
Alan Coxf2cf8e22005-09-06 15:16:44 -07002918 if (*t2) {
2919 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 invalid_lilo_config = 1;
2921 setup_error_code |= INVALID_NUM_PORTS;
2922 return;
2923 }
2924
2925 /* ------------------------------------------------------------
2926 There is not a man page for simple_strtoul but the code can be
2927 found in vsprintf.c. The first argument is the string to
2928 translate (To an unsigned long obviously), the second argument
2929 can be the address of any character variable or a NULL. If a
2930 variable is given, the end pointer of the string will be stored
2931 in that variable; if a NULL is given the end pointer will
2932 not be returned. The last argument is the base to use. If
2933 a 0 is indicated, the routine will attempt to determine the
2934 proper base by looking at the values prefix (A '0' for octal,
2935 a 'x' for hex, etc ... If a value is given it will use that
2936 value as the base.
2937 ---------------------------------------------------------------- */
2938 board.numports = simple_strtoul(str, NULL, 0);
2939 nbdevs += board.numports;
2940 last = index;
2941 break;
2942
2943 case 5:
2944 t2 = str;
2945 while (isxdigit(*t2))
2946 t2++;
2947
Alan Coxf2cf8e22005-09-06 15:16:44 -07002948 if (*t2) {
2949 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 invalid_lilo_config = 1;
2951 setup_error_code |= INVALID_PORT_BASE;
2952 return;
2953 }
2954
Alan Coxf2cf8e22005-09-06 15:16:44 -07002955 board.port = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 last = index;
2957 break;
2958
2959 case 6:
2960 t2 = str;
2961 while (isxdigit(*t2))
2962 t2++;
2963
Alan Coxf2cf8e22005-09-06 15:16:44 -07002964 if (*t2) {
2965 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 invalid_lilo_config = 1;
2967 setup_error_code |= INVALID_MEM_BASE;
2968 return;
2969 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002970 board.membase = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 last = index;
2972 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002974 printk(KERN_ERR "epca: Too many string parms\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 return;
2976 }
2977 str = temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 } /* End while there is a string arg */
2979
Alan Coxf2cf8e22005-09-06 15:16:44 -07002980 if (last < 6) {
2981 printk(KERN_ERR "epca: Insufficient parms specified\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 return;
2983 }
2984
2985 /* I should REALLY validate the stuff here */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 /* Copies our local copy of board into boards */
2987 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 /* Does this get called once per lilo arg are what ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2990 num_cards, board_desc[board.type],
2991 board.numports, (int)board.port, (unsigned int) board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 num_cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993} /* End epca_setup */
2994
2995
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996/* ------------------------ Begin init_PCI --------------------------- */
2997
2998enum epic_board_types {
2999 brd_xr = 0,
3000 brd_xem,
3001 brd_cx,
3002 brd_xrj,
3003};
3004
3005
3006/* indexed directly by epic_board_types enum */
3007static struct {
3008 unsigned char board_type;
3009 unsigned bar_idx; /* PCI base address region */
3010} epca_info_tbl[] = {
3011 { PCIXR, 0, },
3012 { PCIXEM, 0, },
3013 { PCICX, 0, },
3014 { PCIXRJ, 2, },
3015};
3016
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017static int __devinit epca_init_one (struct pci_dev *pdev,
3018 const struct pci_device_id *ent)
3019{
3020 static int board_num = -1;
3021 int board_idx, info_idx = ent->driver_data;
3022 unsigned long addr;
3023
3024 if (pci_enable_device(pdev))
3025 return -EIO;
3026
3027 board_num++;
3028 board_idx = board_num + num_cards;
3029 if (board_idx >= MAXBOARDS)
3030 goto err_out;
3031
3032 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3033 if (!addr) {
3034 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3035 epca_info_tbl[info_idx].bar_idx);
3036 goto err_out;
3037 }
3038
3039 boards[board_idx].status = ENABLED;
3040 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3041 boards[board_idx].numports = 0x0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07003042 boards[board_idx].port = addr + PCI_IO_OFFSET;
3043 boards[board_idx].membase = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
3045 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3046 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3047 0x200000, addr + PCI_IO_OFFSET);
3048 goto err_out;
3049 }
3050
3051 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3052 if (!boards[board_idx].re_map_port) {
3053 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3054 0x200000, addr + PCI_IO_OFFSET);
3055 goto err_out_free_pciio;
3056 }
3057
3058 if (!request_mem_region (addr, 0x200000, "epca")) {
3059 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3060 0x200000, addr);
3061 goto err_out_free_iounmap;
3062 }
3063
3064 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3065 if (!boards[board_idx].re_map_membase) {
3066 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3067 0x200000, addr + PCI_IO_OFFSET);
3068 goto err_out_free_memregion;
3069 }
3070
3071 /* --------------------------------------------------------------
3072 I don't know what the below does, but the hardware guys say
3073 its required on everything except PLX (In this case XRJ).
3074 ---------------------------------------------------------------- */
3075 if (info_idx != brd_xrj) {
3076 pci_write_config_byte(pdev, 0x40, 0);
3077 pci_write_config_byte(pdev, 0x46, 0);
3078 }
3079
3080 return 0;
3081
3082err_out_free_memregion:
3083 release_mem_region (addr, 0x200000);
3084err_out_free_iounmap:
3085 iounmap (boards[board_idx].re_map_port);
3086err_out_free_pciio:
3087 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3088err_out:
3089 return -ENODEV;
3090}
3091
3092
3093static struct pci_device_id epca_pci_tbl[] = {
3094 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3095 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3096 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3097 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3098 { 0, }
3099};
3100
3101MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3102
3103int __init init_PCI (void)
Alan Coxf2cf8e22005-09-06 15:16:44 -07003104{ /* Begin init_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 memset (&epca_driver, 0, sizeof (epca_driver));
3106 epca_driver.name = "epca";
3107 epca_driver.id_table = epca_pci_tbl;
3108 epca_driver.probe = epca_init_one;
3109
3110 return pci_register_driver(&epca_driver);
Alan Coxf2cf8e22005-09-06 15:16:44 -07003111}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
3113MODULE_LICENSE("GPL");