blob: 765c5c108bf4f532619724eab156d3bbf3694bda [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 */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700489 if (ch->count < 0)
490 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 /* ---------------------------------------------------------------
493 Let the rest of the driver know the channel is being closed.
494 This becomes important if an open is attempted before close
495 is finished.
496 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 ch->asyncflags |= ASYNC_CLOSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 tty->closing = 1;
499
Alan Coxf2cf8e22005-09-06 15:16:44 -0700500 spin_unlock_irqrestore(&epca_lock, flags);
501
502 if (ch->asyncflags & ASYNC_INITIALIZED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /* Setup an event to indicate when the transmit buffer empties */
504 setup_empty_event(tty, ch);
505 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (tty->driver->flush_buffer)
508 tty->driver->flush_buffer(tty);
509
510 tty_ldisc_flush(tty);
511 shutdown(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700512
513 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 tty->closing = 0;
515 ch->event = 0;
516 ch->tty = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700517 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Alan Coxf2cf8e22005-09-06 15:16:44 -0700519 if (ch->blocked_open) { /* Begin if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (ch->close_delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 } /* End if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
525 ASYNC_CLOSING);
526 wake_up_interruptible(&ch->close_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 } /* End if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528} /* End pc_close */
529
530/* ------------------ Begin shutdown ------------------------- */
531
532static void shutdown(struct channel *ch)
533{ /* Begin shutdown */
534
535 unsigned long flags;
536 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +0100537 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 if (!(ch->asyncflags & ASYNC_INITIALIZED))
540 return;
541
Alan Coxf2cf8e22005-09-06 15:16:44 -0700542 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Alan Coxf2cf8e22005-09-06 15:16:44 -0700544 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 bc = ch->brdchan;
546
547 /* ------------------------------------------------------------------
548 In order for an event to be generated on the receipt of data the
549 idata flag must be set. Since we are shutting down, this is not
550 necessary clear this flag.
551 --------------------------------------------------------------------- */
552
553 if (bc)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700554 writeb(0, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 tty = ch->tty;
556
557 /* ----------------------------------------------------------------
558 If we're a modem control device and HUPCL is on, drop RTS & DTR.
559 ------------------------------------------------------------------ */
560
Alan Coxf2cf8e22005-09-06 15:16:44 -0700561 if (tty->termios->c_cflag & HUPCL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
563 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 memoff(ch);
566
567 /* ------------------------------------------------------------------
568 The channel has officialy been closed. The next time it is opened
569 it will have to reinitialized. Set a flag to indicate this.
570 ---------------------------------------------------------------------- */
571
572 /* Prevent future Digi programmed interrupts from coming active */
573
574 ch->asyncflags &= ~ASYNC_INITIALIZED;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700575 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577} /* End shutdown */
578
579/* ------------------ Begin pc_hangup ------------------------- */
580
581static void pc_hangup(struct tty_struct *tty)
582{ /* Begin pc_hangup */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 struct channel *ch;
584
585 /* ---------------------------------------------------------
586 verifyChannel returns the channel from the tty struct
587 if it is valid. This serves as a sanity check.
588 ------------------------------------------------------------- */
589
Alan Coxf2cf8e22005-09-06 15:16:44 -0700590 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 unsigned long flags;
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (tty->driver->flush_buffer)
594 tty->driver->flush_buffer(tty);
595 tty_ldisc_flush(tty);
596 shutdown(ch);
597
Alan Coxf2cf8e22005-09-06 15:16:44 -0700598 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 ch->tty = NULL;
600 ch->event = 0;
601 ch->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700603 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 } /* End if ch != NULL */
606
607} /* End pc_hangup */
608
609/* ------------------ Begin pc_write ------------------------- */
610
611static int pc_write(struct tty_struct * tty,
612 const unsigned char *buf, int bytesAvailable)
613{ /* Begin pc_write */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700614 unsigned int head, tail;
615 int dataLen;
616 int size;
617 int amountCopied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 struct channel *ch;
619 unsigned long flags;
620 int remain;
Al Virobc9a5152005-09-15 22:53:28 +0100621 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /* ----------------------------------------------------------------
624 pc_write is primarily called directly by the kernel routine
625 tty_write (Though it can also be called by put_char) found in
626 tty_io.c. pc_write is passed a line discipline buffer where
627 the data to be written out is stored. The line discipline
628 implementation itself is done at the kernel level and is not
629 brought into the driver.
630 ------------------------------------------------------------------- */
631
632 /* ---------------------------------------------------------
633 verifyChannel returns the channel from the tty struct
634 if it is valid. This serves as a sanity check.
635 ------------------------------------------------------------- */
636
637 if ((ch = verifyChannel(tty)) == NULL)
638 return 0;
639
640 /* Make a pointer to the channel data structure found on the board. */
641
642 bc = ch->brdchan;
643 size = ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 amountCopied = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Alan Coxf2cf8e22005-09-06 15:16:44 -0700646 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 globalwinon(ch);
648
Alan Coxf2cf8e22005-09-06 15:16:44 -0700649 head = readw(&bc->tin) & (size - 1);
650 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Alan Coxf2cf8e22005-09-06 15:16:44 -0700652 if (tail != readw(&bc->tout))
653 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 tail &= (size - 1);
655
656 /* If head >= tail, head has not wrapped around. */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700657 if (head >= tail) { /* Begin head has not wrapped */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 /* ---------------------------------------------------------------
659 remain (much like dataLen above) represents the total amount of
660 space available on the card for data. Here dataLen represents
661 the space existing between the head pointer and the end of
662 buffer. This is important because a memcpy cannot be told to
663 automatically wrap around when it hits the buffer end.
664 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 dataLen = size - head;
666 remain = size - (head - tail) - 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700667 } else { /* Begin head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 remain = tail - head - 1;
670 dataLen = remain;
671
672 } /* End head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 /* -------------------------------------------------------------------
674 Check the space on the card. If we have more data than
675 space; reduce the amount of data to fit the space.
676 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 bytesAvailable = min(remain, bytesAvailable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 txwinon(ch);
679 while (bytesAvailable > 0)
680 { /* Begin while there is data to copy onto card */
681
682 /* -----------------------------------------------------------------
683 If head is not wrapped, the below will make sure the first
684 data copy fills to the end of card buffer.
685 ------------------------------------------------------------------- */
686
687 dataLen = min(bytesAvailable, dataLen);
Al Virobc9a5152005-09-15 22:53:28 +0100688 memcpy_toio(ch->txptr + head, buf, dataLen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 buf += dataLen;
690 head += dataLen;
691 amountCopied += dataLen;
692 bytesAvailable -= dataLen;
693
Alan Coxf2cf8e22005-09-06 15:16:44 -0700694 if (head >= size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 head = 0;
696 dataLen = tail;
697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 } /* End while there is data to copy onto card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 ch->statusflags |= TXBUSY;
700 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700701 writew(head, &bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Alan Coxf2cf8e22005-09-06 15:16:44 -0700703 if ((ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700705 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 }
707 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700708 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 return(amountCopied);
710
711} /* End pc_write */
712
713/* ------------------ Begin pc_put_char ------------------------- */
714
715static void pc_put_char(struct tty_struct *tty, unsigned char c)
716{ /* Begin pc_put_char */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 pc_write(tty, &c, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718} /* End pc_put_char */
719
720/* ------------------ Begin pc_write_room ------------------------- */
721
722static int pc_write_room(struct tty_struct *tty)
723{ /* Begin pc_write_room */
724
725 int remain;
726 struct channel *ch;
727 unsigned long flags;
728 unsigned int head, tail;
Al Virobc9a5152005-09-15 22:53:28 +0100729 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 remain = 0;
732
733 /* ---------------------------------------------------------
734 verifyChannel returns the channel from the tty struct
735 if it is valid. This serves as a sanity check.
736 ------------------------------------------------------------- */
737
Alan Coxf2cf8e22005-09-06 15:16:44 -0700738 if ((ch = verifyChannel(tty)) != NULL) {
739 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 globalwinon(ch);
741
742 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700743 head = readw(&bc->tin) & (ch->txbufsize - 1);
744 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Alan Coxf2cf8e22005-09-06 15:16:44 -0700746 if (tail != readw(&bc->tout))
747 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 /* Wrap tail if necessary */
749 tail &= (ch->txbufsize - 1);
750
751 if ((remain = tail - head - 1) < 0 )
752 remain += ch->txbufsize;
753
Alan Coxf2cf8e22005-09-06 15:16:44 -0700754 if (remain && (ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700756 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700759 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 /* Return how much room is left on card */
762 return remain;
763
764} /* End pc_write_room */
765
766/* ------------------ Begin pc_chars_in_buffer ---------------------- */
767
768static int pc_chars_in_buffer(struct tty_struct *tty)
769{ /* Begin pc_chars_in_buffer */
770
771 int chars;
772 unsigned int ctail, head, tail;
773 int remain;
774 unsigned long flags;
775 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100776 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /* ---------------------------------------------------------
779 verifyChannel returns the channel from the tty struct
780 if it is valid. This serves as a sanity check.
781 ------------------------------------------------------------- */
782
783 if ((ch = verifyChannel(tty)) == NULL)
784 return(0);
785
Alan Coxf2cf8e22005-09-06 15:16:44 -0700786 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 globalwinon(ch);
788
789 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700790 tail = readw(&bc->tout);
791 head = readw(&bc->tin);
792 ctail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Alan Coxf2cf8e22005-09-06 15:16:44 -0700794 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 chars = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700796 else { /* Begin if some space on the card has been used */
797 head = readw(&bc->tin) & (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 tail &= (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 /* --------------------------------------------------------------
800 The logic here is basically opposite of the above pc_write_room
801 here we are finding the amount of bytes in the buffer filled.
802 Not the amount of bytes empty.
803 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 if ((remain = tail - head - 1) < 0 )
805 remain += ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 chars = (int)(ch->txbufsize - remain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 /* -------------------------------------------------------------
808 Make it possible to wakeup anything waiting for output
809 in tty_ioctl.c, etc.
810
811 If not already set. Setup an event to indicate when the
812 transmit buffer empties
813 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 if (!(ch->statusflags & EMPTYWAIT))
815 setup_empty_event(tty,ch);
816
817 } /* End if some space on the card has been used */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700819 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 /* Return number of characters residing on card. */
821 return(chars);
822
823} /* End pc_chars_in_buffer */
824
825/* ------------------ Begin pc_flush_buffer ---------------------- */
826
827static void pc_flush_buffer(struct tty_struct *tty)
828{ /* Begin pc_flush_buffer */
829
830 unsigned int tail;
831 unsigned long flags;
832 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100833 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 /* ---------------------------------------------------------
835 verifyChannel returns the channel from the tty struct
836 if it is valid. This serves as a sanity check.
837 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 if ((ch = verifyChannel(tty)) == NULL)
839 return;
840
Alan Coxf2cf8e22005-09-06 15:16:44 -0700841 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700844 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 /* Have FEP move tout pointer; effectively flushing transmit buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700848 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 wake_up_interruptible(&tty->write_wait);
850 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851} /* End pc_flush_buffer */
852
853/* ------------------ Begin pc_flush_chars ---------------------- */
854
855static void pc_flush_chars(struct tty_struct *tty)
856{ /* Begin pc_flush_chars */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 struct channel * ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 /* ---------------------------------------------------------
859 verifyChannel returns the channel from the tty struct
860 if it is valid. This serves as a sanity check.
861 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700862 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700864 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 /* ----------------------------------------------------------------
866 If not already set and the transmitter is busy setup an event
867 to indicate when the transmit empties.
868 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
870 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700871 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873} /* End pc_flush_chars */
874
875/* ------------------ Begin block_til_ready ---------------------- */
876
877static int block_til_ready(struct tty_struct *tty,
878 struct file *filp, struct channel *ch)
879{ /* Begin block_til_ready */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 DECLARE_WAITQUEUE(wait,current);
881 int retval, do_clocal = 0;
882 unsigned long flags;
883
Alan Coxf2cf8e22005-09-06 15:16:44 -0700884 if (tty_hung_up_p(filp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
886 retval = -EAGAIN;
887 else
888 retval = -ERESTARTSYS;
889 return(retval);
890 }
891
892 /* -----------------------------------------------------------------
893 If the device is in the middle of being closed, then block
894 until it's done, and then try again.
895 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700896 if (ch->asyncflags & ASYNC_CLOSING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 interruptible_sleep_on(&ch->close_wait);
898
899 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
900 return -EAGAIN;
901 else
902 return -ERESTARTSYS;
903 }
904
Alan Coxf2cf8e22005-09-06 15:16:44 -0700905 if (filp->f_flags & O_NONBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 /* -----------------------------------------------------------------
907 If non-blocking mode is set, then make the check up front
908 and then exit.
909 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 return 0;
912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 if (tty->termios->c_cflag & CLOCAL)
914 do_clocal = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700915 /* Block waiting for the carrier detect and the line to become free */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917 retval = 0;
918 add_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Alan Coxf2cf8e22005-09-06 15:16:44 -0700920 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 /* We dec count so that pc_close will know when to free things */
922 if (!tty_hung_up_p(filp))
923 ch->count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 ch->blocked_open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 while(1)
926 { /* Begin forever while */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 if (tty_hung_up_p(filp) ||
929 !(ch->asyncflags & ASYNC_INITIALIZED))
930 {
931 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
932 retval = -EAGAIN;
933 else
934 retval = -ERESTARTSYS;
935 break;
936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 if (!(ch->asyncflags & ASYNC_CLOSING) &&
938 (do_clocal || (ch->imodem & ch->dcd)))
939 break;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700940 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 retval = -ERESTARTSYS;
942 break;
943 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700944 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 /* ---------------------------------------------------------------
946 Allow someone else to be scheduled. We will occasionally go
947 through this loop until one of the above conditions change.
948 The below schedule call will allow other processes to enter and
949 prevent this loop from hogging the cpu.
950 ------------------------------------------------------------------ */
951 schedule();
Alan Coxf2cf8e22005-09-06 15:16:44 -0700952 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 } /* End forever while */
955
956 current->state = TASK_RUNNING;
957 remove_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 if (!tty_hung_up_p(filp))
959 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 ch->blocked_open--;
961
Alan Coxf2cf8e22005-09-06 15:16:44 -0700962 spin_unlock_irqrestore(&epca_lock, flags);
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 if (retval)
965 return retval;
966
967 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969} /* End block_til_ready */
970
971/* ------------------ Begin pc_open ---------------------- */
972
973static int pc_open(struct tty_struct *tty, struct file * filp)
974{ /* Begin pc_open */
975
976 struct channel *ch;
977 unsigned long flags;
978 int line, retval, boardnum;
Al Virobc9a5152005-09-15 22:53:28 +0100979 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700980 unsigned int head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 line = tty->index;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700983 if (line < 0 || line >= nbdevs)
984 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 ch = &digi_channels[line];
987 boardnum = ch->boardnum;
988
989 /* Check status of board configured in system. */
990
991 /* -----------------------------------------------------------------
992 I check to see if the epca_setup routine detected an user error.
993 It might be better to put this in pc_init, but for the moment it
994 goes here.
995 ---------------------------------------------------------------------- */
996
Alan Coxf2cf8e22005-09-06 15:16:44 -0700997 if (invalid_lilo_config) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 if (setup_error_code & INVALID_BOARD_TYPE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700999 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (setup_error_code & INVALID_NUM_PORTS)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001001 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (setup_error_code & INVALID_MEM_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001003 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (setup_error_code & INVALID_PORT_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001005 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 if (setup_error_code & INVALID_BOARD_STATUS)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001007 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (setup_error_code & INVALID_ALTPIN)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001009 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 tty->driver_data = NULL; /* Mark this device as 'down' */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001011 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001013 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 tty->driver_data = NULL; /* Mark this device as 'down' */
1015 return(-ENODEV);
1016 }
1017
Alan Coxf2cf8e22005-09-06 15:16:44 -07001018 if ((bc = ch->brdchan) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 tty->driver_data = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001020 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 }
1022
Alan Coxf2cf8e22005-09-06 15:16:44 -07001023 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 /* ------------------------------------------------------------------
1025 Every time a channel is opened, increment a counter. This is
1026 necessary because we do not wish to flush and shutdown the channel
1027 until the last app holding the channel open, closes it.
1028 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 /* ----------------------------------------------------------------
1031 Set a kernel structures pointer to our local channel
1032 structure. This way we can get to it when passed only
1033 a tty struct.
1034 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 tty->driver_data = ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 /* ----------------------------------------------------------------
1037 If this is the first time the channel has been opened, initialize
1038 the tty->termios struct otherwise let pc_close handle it.
1039 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 globalwinon(ch);
1041 ch->statusflags = 0;
1042
1043 /* Save boards current modem status */
Al Virobc9a5152005-09-15 22:53:28 +01001044 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046 /* ----------------------------------------------------------------
1047 Set receive head and tail ptrs to each other. This indicates
1048 no data available to read.
1049 ----------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001050 head = readw(&bc->rin);
1051 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
1053 /* Set the channels associated tty structure */
1054 ch->tty = tty;
1055
1056 /* -----------------------------------------------------------------
1057 The below routine generally sets up parity, baud, flow control
1058 issues, etc.... It effect both control flags and input flags.
1059 -------------------------------------------------------------------- */
1060 epcaparam(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 ch->asyncflags |= ASYNC_INITIALIZED;
1062 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001063 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 retval = block_til_ready(tty, filp, ch);
1066 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 /* -------------------------------------------------------------
1069 Set this again in case a hangup set it to zero while this
1070 open() was waiting for the line...
1071 --------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001072 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 ch->tty = tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 /* Enable Digi Data events */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001076 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001078 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080} /* End pc_open */
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082static int __init epca_module_init(void)
1083{ /* Begin init_module */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001084 return pc_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
1087module_init(epca_module_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089static struct pci_driver epca_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
1091static void __exit epca_module_exit(void)
1092{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 int count, crd;
1094 struct board_info *bd;
1095 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 del_timer_sync(&epca_timer);
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 if ((tty_unregister_driver(pc_driver)) ||
1100 (tty_unregister_driver(pc_info)))
1101 {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001102 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 return;
1104 }
1105 put_tty_driver(pc_driver);
1106 put_tty_driver(pc_info);
1107
Alan Coxf2cf8e22005-09-06 15:16:44 -07001108 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 bd = &boards[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 if (!bd)
1111 { /* Begin sanity check */
1112 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1113 return;
1114 } /* End sanity check */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001115 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 for (count = 0; count < bd->numports; count++, ch++)
1117 { /* Begin for each port */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001118 if (ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 if (ch->tty)
1120 tty_hangup(ch->tty);
1121 kfree(ch->tmp_buf);
1122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 } /* End for each port */
1124 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 pci_unregister_driver (&epca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
Alan Coxf2cf8e22005-09-06 15:16:44 -07001127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128module_exit(epca_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130static struct tty_operations pc_ops = {
1131 .open = pc_open,
1132 .close = pc_close,
1133 .write = pc_write,
1134 .write_room = pc_write_room,
1135 .flush_buffer = pc_flush_buffer,
1136 .chars_in_buffer = pc_chars_in_buffer,
1137 .flush_chars = pc_flush_chars,
1138 .put_char = pc_put_char,
1139 .ioctl = pc_ioctl,
1140 .set_termios = pc_set_termios,
1141 .stop = pc_stop,
1142 .start = pc_start,
1143 .throttle = pc_throttle,
1144 .unthrottle = pc_unthrottle,
1145 .hangup = pc_hangup,
1146};
1147
1148static int info_open(struct tty_struct *tty, struct file * filp)
1149{
1150 return 0;
1151}
1152
1153static struct tty_operations info_ops = {
1154 .open = info_open,
1155 .ioctl = info_ioctl,
1156};
1157
1158/* ------------------ Begin pc_init ---------------------- */
1159
Alan Coxf2cf8e22005-09-06 15:16:44 -07001160static int __init pc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161{ /* Begin pc_init */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 int crd;
1163 struct board_info *bd;
1164 unsigned char board_id = 0;
1165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 int pci_boards_found, pci_count;
1167
1168 pci_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 pc_driver = alloc_tty_driver(MAX_ALLOC);
1171 if (!pc_driver)
1172 return -ENOMEM;
1173
1174 pc_info = alloc_tty_driver(MAX_ALLOC);
1175 if (!pc_info) {
1176 put_tty_driver(pc_driver);
1177 return -ENOMEM;
1178 }
1179
1180 /* -----------------------------------------------------------------------
1181 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1182 board structure defined by digiConfig into drivers board structure.
1183 Note : If LILO has ran epca_setup then epca_setup will handle defining
1184 num_cards as well as copying the data into the board structure.
1185 -------------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001186 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 nbdevs = NBDEVS;
1189 num_cards = NUMCARDS;
1190 memcpy((void *)&boards, (void *)&static_boards,
1191 (sizeof(struct board_info) * NUMCARDS));
1192 } /* End driver has been configured via. epcaconfig */
1193
1194 /* -----------------------------------------------------------------
1195 Note : If lilo was used to configure the driver and the
1196 ignore epcaconfig option was choosen (digiepca=2) then
1197 nbdevs and num_cards will equal 0 at this point. This is
1198 okay; PCI cards will still be picked up if detected.
1199 --------------------------------------------------------------------- */
1200
1201 /* -----------------------------------------------------------
1202 Set up interrupt, we will worry about memory allocation in
1203 post_fep_init.
1204 --------------------------------------------------------------- */
1205
1206
1207 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1208
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 /* ------------------------------------------------------------------
1210 NOTE : This code assumes that the number of ports found in
1211 the boards array is correct. This could be wrong if
1212 the card in question is PCI (And therefore has no ports
1213 entry in the boards structure.) The rest of the
1214 information will be valid for PCI because the beginning
1215 of pc_init scans for PCI and determines i/o and base
1216 memory addresses. I am not sure if it is possible to
1217 read the number of ports supported by the card prior to
1218 it being booted (Since that is the state it is in when
1219 pc_init is run). Because it is not possible to query the
1220 number of supported ports until after the card has booted;
1221 we are required to calculate the card_ptrs as the card is
1222 is initialized (Inside post_fep_init). The negative thing
1223 about this approach is that digiDload's call to GET_INFO
1224 will have a bad port value. (Since this is called prior
1225 to post_fep_init.)
1226
1227 --------------------------------------------------------------------- */
1228
1229 pci_boards_found = 0;
1230 if(num_cards < MAXBOARDS)
1231 pci_boards_found += init_PCI();
1232 num_cards += pci_boards_found;
1233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 pc_driver->owner = THIS_MODULE;
1235 pc_driver->name = "ttyD";
1236 pc_driver->devfs_name = "tts/D";
1237 pc_driver->major = DIGI_MAJOR;
1238 pc_driver->minor_start = 0;
1239 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1240 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1241 pc_driver->init_termios = tty_std_termios;
1242 pc_driver->init_termios.c_iflag = 0;
1243 pc_driver->init_termios.c_oflag = 0;
1244 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1245 pc_driver->init_termios.c_lflag = 0;
1246 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1247 tty_set_operations(pc_driver, &pc_ops);
1248
1249 pc_info->owner = THIS_MODULE;
1250 pc_info->name = "digi_ctl";
1251 pc_info->major = DIGIINFOMAJOR;
1252 pc_info->minor_start = 0;
1253 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1254 pc_info->subtype = SERIAL_TYPE_INFO;
1255 pc_info->init_termios = tty_std_termios;
1256 pc_info->init_termios.c_iflag = 0;
1257 pc_info->init_termios.c_oflag = 0;
1258 pc_info->init_termios.c_lflag = 0;
1259 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1260 pc_info->flags = TTY_DRIVER_REAL_RAW;
1261 tty_set_operations(pc_info, &info_ops);
1262
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 for (crd = 0; crd < num_cards; crd++)
1265 { /* Begin for each card */
1266
1267 /* ------------------------------------------------------------------
1268 This is where the appropriate memory handlers for the hardware is
1269 set. Everything at runtime blindly jumps through these vectors.
1270 ---------------------------------------------------------------------- */
1271
1272 /* defined in epcaconfig.h */
1273 bd = &boards[crd];
1274
1275 switch (bd->type)
1276 { /* Begin switch on bd->type {board type} */
1277 case PCXEM:
1278 case EISAXEM:
1279 bd->memwinon = pcxem_memwinon ;
1280 bd->memwinoff = pcxem_memwinoff ;
1281 bd->globalwinon = pcxem_globalwinon ;
1282 bd->txwinon = pcxem_txwinon ;
1283 bd->rxwinon = pcxem_rxwinon ;
1284 bd->memoff = pcxem_memoff ;
1285 bd->assertgwinon = dummy_assertgwinon;
1286 bd->assertmemoff = dummy_assertmemoff;
1287 break;
1288
1289 case PCIXEM:
1290 case PCIXRJ:
1291 case PCIXR:
1292 bd->memwinon = dummy_memwinon;
1293 bd->memwinoff = dummy_memwinoff;
1294 bd->globalwinon = dummy_globalwinon;
1295 bd->txwinon = dummy_txwinon;
1296 bd->rxwinon = dummy_rxwinon;
1297 bd->memoff = dummy_memoff;
1298 bd->assertgwinon = dummy_assertgwinon;
1299 bd->assertmemoff = dummy_assertmemoff;
1300 break;
1301
1302 case PCXE:
1303 case PCXEVE:
1304
1305 bd->memwinon = pcxe_memwinon;
1306 bd->memwinoff = pcxe_memwinoff;
1307 bd->globalwinon = pcxe_globalwinon;
1308 bd->txwinon = pcxe_txwinon;
1309 bd->rxwinon = pcxe_rxwinon;
1310 bd->memoff = pcxe_memoff;
1311 bd->assertgwinon = dummy_assertgwinon;
1312 bd->assertmemoff = dummy_assertmemoff;
1313 break;
1314
1315 case PCXI:
1316 case PC64XE:
1317
1318 bd->memwinon = pcxi_memwinon;
1319 bd->memwinoff = pcxi_memwinoff;
1320 bd->globalwinon = pcxi_globalwinon;
1321 bd->txwinon = pcxi_txwinon;
1322 bd->rxwinon = pcxi_rxwinon;
1323 bd->memoff = pcxi_memoff;
1324 bd->assertgwinon = pcxi_assertgwinon;
1325 bd->assertmemoff = pcxi_assertmemoff;
1326 break;
1327
1328 default:
1329 break;
1330
1331 } /* End switch on bd->type */
1332
1333 /* ---------------------------------------------------------------
1334 Some cards need a memory segment to be defined for use in
1335 transmit and receive windowing operations. These boards
1336 are listed in the below switch. In the case of the XI the
1337 amount of memory on the board is variable so the memory_seg
1338 is also variable. This code determines what they segment
1339 should be.
1340 ----------------------------------------------------------------- */
1341
1342 switch (bd->type)
1343 { /* Begin switch on bd->type {board type} */
1344
1345 case PCXE:
1346 case PCXEVE:
1347 case PC64XE:
1348 bd->memory_seg = 0xf000;
1349 break;
1350
1351 case PCXI:
1352 board_id = inb((int)bd->port);
1353 if ((board_id & 0x1) == 0x1)
1354 { /* Begin it's an XI card */
1355
1356 /* Is it a 64K board */
1357 if ((board_id & 0x30) == 0)
1358 bd->memory_seg = 0xf000;
1359
1360 /* Is it a 128K board */
1361 if ((board_id & 0x30) == 0x10)
1362 bd->memory_seg = 0xe000;
1363
1364 /* Is is a 256K board */
1365 if ((board_id & 0x30) == 0x20)
1366 bd->memory_seg = 0xc000;
1367
1368 /* Is it a 512K board */
1369 if ((board_id & 0x30) == 0x30)
1370 bd->memory_seg = 0x8000;
1371
Alan Coxf2cf8e22005-09-06 15:16:44 -07001372 } 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 -07001373 break;
1374
1375 } /* End switch on bd->type */
1376
1377 } /* End for each card */
1378
1379 if (tty_register_driver(pc_driver))
1380 panic("Couldn't register Digi PC/ driver");
1381
1382 if (tty_register_driver(pc_info))
1383 panic("Couldn't register Digi PC/ info ");
1384
1385 /* -------------------------------------------------------------------
1386 Start up the poller to check for events on all enabled boards
1387 ---------------------------------------------------------------------- */
1388
1389 init_timer(&epca_timer);
1390 epca_timer.function = epcapoll;
1391 mod_timer(&epca_timer, jiffies + HZ/25);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 return 0;
1393
1394} /* End pc_init */
1395
1396/* ------------------ Begin post_fep_init ---------------------- */
1397
1398static void post_fep_init(unsigned int crd)
1399{ /* Begin post_fep_init */
1400
1401 int i;
Al Virobc9a5152005-09-15 22:53:28 +01001402 void __iomem *memaddr;
1403 struct global_data __iomem *gd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001405 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 struct channel *ch;
1407 int shrinkmem = 0, lowwater ;
1408
1409 /* -------------------------------------------------------------
1410 This call is made by the user via. the ioctl call DIGI_INIT.
1411 It is responsible for setting up all the card specific stuff.
1412 ---------------------------------------------------------------- */
1413 bd = &boards[crd];
1414
1415 /* -----------------------------------------------------------------
1416 If this is a PCI board, get the port info. Remember PCI cards
1417 do not have entries into the epcaconfig.h file, so we can't get
1418 the number of ports from it. Unfortunetly, this means that anyone
1419 doing a DIGI_GETINFO before the board has booted will get an invalid
1420 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1421 after DIGI_INIT has been called will return the proper values.
1422 ------------------------------------------------------------------- */
1423
Alan Coxf2cf8e22005-09-06 15:16:44 -07001424 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 /* --------------------------------------------------------------------
1426 Below we use XEMPORTS as a memory offset regardless of which PCI
1427 card it is. This is because all of the supported PCI cards have
1428 the same memory offset for the channel data. This will have to be
1429 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1430 states that the port offset is 0xC22 as opposed to 0xC02. This is
1431 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1432 On the PCI cards the number of ports is determined by reading a
1433 ID PROM located in the box attached to the card. The card can then
1434 determine the index the id to determine the number of ports available.
1435 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1436 if the box in question is a XEM or CX)).
1437 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001438 /* PCI cards are already remapped at this point ISA are not */
1439 bd->numports = readw(bd->re_map_membase + XEMPORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1441 nbdevs += (bd->numports);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001442 } else {
1443 /* Fix up the mappings for ISA/EISA etc */
1444 /* FIXME: 64K - can we be smarter ? */
1445 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
1448 if (crd != 0)
1449 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1450 else
1451 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1452
1453 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1455
Alan Coxf2cf8e22005-09-06 15:16:44 -07001456 memaddr = bd->re_map_membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 /* -----------------------------------------------------------------
1459 The below assignment will set bc to point at the BEGINING of
1460 the cards channel structures. For 1 card there will be between
1461 8 and 64 of these structures.
1462 -------------------------------------------------------------------- */
1463
Al Virobc9a5152005-09-15 22:53:28 +01001464 bc = memaddr + CHANSTRUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
1466 /* -------------------------------------------------------------------
1467 The below assignment will set gd to point at the BEGINING of
1468 global memory address 0xc00. The first data in that global
1469 memory actually starts at address 0xc1a. The command in
1470 pointer begins at 0xd10.
1471 ---------------------------------------------------------------------- */
1472
Al Virobc9a5152005-09-15 22:53:28 +01001473 gd = memaddr + GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 /* --------------------------------------------------------------------
1476 XEPORTS (address 0xc22) points at the number of channels the
1477 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1478 ----------------------------------------------------------------------- */
1479
Alan Coxf2cf8e22005-09-06 15:16:44 -07001480 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 shrinkmem = 1;
1482 if (bd->type < PCIXEM)
1483 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1484 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 memwinon(bd, 0);
1486
1487 /* --------------------------------------------------------------------
1488 Remember ch is the main drivers channels structure, while bc is
1489 the cards channel structure.
1490 ------------------------------------------------------------------------ */
1491
1492 /* For every port on the card do ..... */
1493
Alan Coxf2cf8e22005-09-06 15:16:44 -07001494 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1495 unsigned long flags;
Al Virobc9a5152005-09-15 22:53:28 +01001496 u16 tseg, rseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 ch->brdchan = bc;
1499 ch->mailbox = gd;
1500 INIT_WORK(&ch->tqueue, do_softint, ch);
1501 ch->board = &boards[crd];
1502
Alan Coxf2cf8e22005-09-06 15:16:44 -07001503 spin_lock_irqsave(&epca_lock, flags);
1504 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 /* ----------------------------------------------------------------
1506 Since some of the boards use different bitmaps for their
1507 control signals we cannot hard code these values and retain
1508 portability. We virtualize this data here.
1509 ------------------------------------------------------------------- */
1510 case EISAXEM:
1511 case PCXEM:
1512 case PCIXEM:
1513 case PCIXRJ:
1514 case PCIXR:
1515 ch->m_rts = 0x02 ;
1516 ch->m_dcd = 0x80 ;
1517 ch->m_dsr = 0x20 ;
1518 ch->m_cts = 0x10 ;
1519 ch->m_ri = 0x40 ;
1520 ch->m_dtr = 0x01 ;
1521 break;
1522
1523 case PCXE:
1524 case PCXEVE:
1525 case PCXI:
1526 case PC64XE:
1527 ch->m_rts = 0x02 ;
1528 ch->m_dcd = 0x08 ;
1529 ch->m_dsr = 0x10 ;
1530 ch->m_cts = 0x20 ;
1531 ch->m_ri = 0x40 ;
1532 ch->m_dtr = 0x80 ;
1533 break;
1534
1535 } /* End switch bd->type */
1536
Alan Coxf2cf8e22005-09-06 15:16:44 -07001537 if (boards[crd].altpin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 ch->dsr = ch->m_dcd;
1539 ch->dcd = ch->m_dsr;
1540 ch->digiext.digi_flags |= DIGI_ALTPIN;
1541 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001542 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 ch->dcd = ch->m_dcd;
1544 ch->dsr = ch->m_dsr;
1545 }
1546
1547 ch->boardnum = crd;
1548 ch->channelnum = i;
1549 ch->magic = EPCA_MAGIC;
1550 ch->tty = NULL;
1551
Alan Coxf2cf8e22005-09-06 15:16:44 -07001552 if (shrinkmem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1554 shrinkmem = 0;
1555 }
1556
Al Virobc9a5152005-09-15 22:53:28 +01001557 tseg = readw(&bc->tseg);
1558 rseg = readw(&bc->rseg);
1559
Alan Coxf2cf8e22005-09-06 15:16:44 -07001560 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 case PCIXEM:
1563 case PCIXRJ:
1564 case PCIXR:
1565 /* Cover all the 2MEG cards */
Al Virobc9a5152005-09-15 22:53:28 +01001566 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1567 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1568 ch->txwin = FEPWIN | (tseg >> 11);
1569 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 break;
1571
1572 case PCXEM:
1573 case EISAXEM:
1574 /* Cover all the 32K windowed cards */
1575 /* Mask equal to window size - 1 */
Al Virobc9a5152005-09-15 22:53:28 +01001576 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1577 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1578 ch->txwin = FEPWIN | (tseg >> 11);
1579 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 break;
1581
1582 case PCXEVE:
1583 case PCXE:
Al Virobc9a5152005-09-15 22:53:28 +01001584 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1585 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1586 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1587 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 break;
1589
1590 case PCXI:
1591 case PC64XE:
Al Virobc9a5152005-09-15 22:53:28 +01001592 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1593 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 ch->txwin = ch->rxwin = 0;
1595 break;
1596
1597 } /* End switch bd->type */
1598
1599 ch->txbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001600 ch->txbufsize = readw(&bc->tmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 ch->rxbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001603 ch->rxbufsize = readw(&bc->rmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1606
1607 /* Set transmitter low water mark */
1608 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1609
1610 /* Set receiver low water mark */
1611
1612 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1613
1614 /* Set receiver high water mark */
1615
1616 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1617
Alan Coxf2cf8e22005-09-06 15:16:44 -07001618 writew(100, &bc->edelay);
1619 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Alan Coxf2cf8e22005-09-06 15:16:44 -07001621 ch->startc = readb(&bc->startc);
1622 ch->stopc = readb(&bc->stopc);
1623 ch->startca = readb(&bc->startca);
1624 ch->stopca = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
1626 ch->fepcflag = 0;
1627 ch->fepiflag = 0;
1628 ch->fepoflag = 0;
1629 ch->fepstartc = 0;
1630 ch->fepstopc = 0;
1631 ch->fepstartca = 0;
1632 ch->fepstopca = 0;
1633
1634 ch->close_delay = 50;
1635 ch->count = 0;
1636 ch->blocked_open = 0;
1637 init_waitqueue_head(&ch->open_wait);
1638 init_waitqueue_head(&ch->close_wait);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001639
1640 spin_unlock_irqrestore(&epca_lock, flags);
1641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001643 if (!ch->tmp_buf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
1645 release_region((int)bd->port, 4);
1646 while(i-- > 0)
1647 kfree((ch--)->tmp_buf);
1648 return;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001649 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 memset((void *)ch->tmp_buf,0,ch->txbufsize);
1651 } /* End for each port */
1652
1653 printk(KERN_INFO
1654 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1655 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 memwinoff(bd, 0);
1657
1658} /* End post_fep_init */
1659
1660/* --------------------- Begin epcapoll ------------------------ */
1661
1662static void epcapoll(unsigned long ignored)
1663{ /* Begin epcapoll */
1664
1665 unsigned long flags;
1666 int crd;
1667 volatile unsigned int head, tail;
1668 struct channel *ch;
1669 struct board_info *bd;
1670
1671 /* -------------------------------------------------------------------
1672 This routine is called upon every timer interrupt. Even though
1673 the Digi series cards are capable of generating interrupts this
1674 method of non-looping polling is more efficient. This routine
1675 checks for card generated events (Such as receive data, are transmit
1676 buffer empty) and acts on those events.
1677 ----------------------------------------------------------------------- */
1678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 for (crd = 0; crd < num_cards; crd++)
1680 { /* Begin for each card */
1681
1682 bd = &boards[crd];
1683 ch = card_ptr[crd];
1684
1685 if ((bd->status == DISABLED) || digi_poller_inhibited)
1686 continue; /* Begin loop next interation */
1687
1688 /* -----------------------------------------------------------
1689 assertmemoff is not needed here; indeed it is an empty subroutine.
1690 It is being kept because future boards may need this as well as
1691 some legacy boards.
1692 ---------------------------------------------------------------- */
1693
Alan Coxf2cf8e22005-09-06 15:16:44 -07001694 spin_lock_irqsave(&epca_lock, flags);
1695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 assertmemoff(ch);
1697
1698 globalwinon(ch);
1699
1700 /* ---------------------------------------------------------------
1701 In this case head and tail actually refer to the event queue not
1702 the transmit or receive queue.
1703 ------------------------------------------------------------------- */
1704
Alan Coxf2cf8e22005-09-06 15:16:44 -07001705 head = readw(&ch->mailbox->ein);
1706 tail = readw(&ch->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 /* If head isn't equal to tail we have an event */
1709
1710 if (head != tail)
1711 doevent(crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 memoff(ch);
1713
Alan Coxf2cf8e22005-09-06 15:16:44 -07001714 spin_unlock_irqrestore(&epca_lock, flags);
1715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 mod_timer(&epca_timer, jiffies + (HZ / 25));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718} /* End epcapoll */
1719
1720/* --------------------- Begin doevent ------------------------ */
1721
1722static void doevent(int crd)
1723{ /* Begin doevent */
1724
Al Virobc9a5152005-09-15 22:53:28 +01001725 void __iomem *eventbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 struct channel *ch, *chan0;
1727 static struct tty_struct *tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001728 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001729 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001730 unsigned int tail, head;
1731 int event, channel;
1732 int mstat, lstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 /* -------------------------------------------------------------------
1735 This subroutine is called by epcapoll when an event is detected
1736 in the event queue. This routine responds to those events.
1737 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 bd = &boards[crd];
1739
1740 chan0 = card_ptr[crd];
1741 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001743 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 { /* Begin while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 assertgwinon(chan0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001746 eventbuf = bd->re_map_membase + tail + ISTART;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 /* Get the channel the event occurred on */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001748 channel = readb(eventbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 /* Get the actual event code that occurred */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001750 event = readb(eventbuf + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 /* ----------------------------------------------------------------
1752 The two assignments below get the current modem status (mstat)
1753 and the previous modem status (lstat). These are useful becuase
1754 an event could signal a change in modem signals itself.
1755 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001756 mstat = readb(eventbuf + 2);
1757 lstat = readb(eventbuf + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
1759 ch = chan0 + channel;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001760 if ((unsigned)channel >= bd->numports || !ch) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 if (channel >= bd->numports)
1762 ch = chan0;
1763 bc = ch->brdchan;
1764 goto next;
1765 }
1766
1767 if ((bc = ch->brdchan) == NULL)
1768 goto next;
1769
Alan Coxf2cf8e22005-09-06 15:16:44 -07001770 if (event & DATA_IND) { /* Begin DATA_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 receive_data(ch);
1772 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 } /* End DATA_IND */
1774 /* else *//* Fix for DCD transition missed bug */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001775 if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 /* A modem signal change has been indicated */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 ch->imodem = mstat;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001778 if (ch->asyncflags & ASYNC_CHECK_CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 if (mstat & ch->dcd) /* We are now receiving dcd */
1780 wake_up_interruptible(&ch->open_wait);
1781 else
1782 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 } /* End MODEMCHG_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 tty = ch->tty;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001786 if (tty) { /* Begin if valid tty */
1787 if (event & BREAK_IND) { /* Begin if BREAK_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 /* A break has been indicated */
Alan Cox33f0f882006-01-09 20:54:13 -08001789 tty_insert_flip_char(tty, 0, TTY_BREAK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 tty_schedule_flip(tty);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001791 } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 if (ch->statusflags & LOWWAIT)
1793 { /* Begin if LOWWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 ch->statusflags &= ~LOWWAIT;
1795 tty_wakeup(tty);
1796 wake_up_interruptible(&tty->write_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 } /* End if LOWWAIT */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001798 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 /* This event is generated by setup_empty_event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ch->statusflags &= ~TXBUSY;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001801 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 ch->statusflags &= ~EMPTYWAIT;
1803 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 wake_up_interruptible(&tty->write_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 } /* End if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 } /* End EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 } /* End if valid tty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 next:
1809 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001810 BUG_ON(!bc);
1811 writew(1, &bc->idata);
1812 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 globalwinon(chan0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 } /* End while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815} /* End doevent */
1816
1817/* --------------------- Begin fepcmd ------------------------ */
1818
1819static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1820 int byte2, int ncmds, int bytecmd)
1821{ /* Begin fepcmd */
Al Virobc9a5152005-09-15 22:53:28 +01001822 unchar __iomem *memaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 unsigned int head, cmdTail, cmdStart, cmdMax;
1824 long count;
1825 int n;
1826
1827 /* This is the routine in which commands may be passed to the card. */
1828
1829 if (ch->board->status == DISABLED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 /* Remember head (As well as max) is just an offset not a base addr */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001833 head = readw(&ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 /* cmdStart is a base address */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001835 cmdStart = readw(&ch->mailbox->cstart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 /* ------------------------------------------------------------------
1837 We do the addition below because we do not want a max pointer
1838 relative to cmdStart. We want a max pointer that points at the
1839 physical end of the command queue.
1840 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001841 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 memaddr = ch->board->re_map_membase;
1843
Alan Coxf2cf8e22005-09-06 15:16:44 -07001844 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1845 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1846 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 return;
1848 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001849 if (bytecmd) {
1850 writeb(cmd, memaddr + head + cmdStart + 0);
1851 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 /* Below word_or_byte is bits to set */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001853 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 /* Below byte2 is bits to reset */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001855 writeb(byte2, memaddr + head + cmdStart + 3);
1856 } else {
1857 writeb(cmd, memaddr + head + cmdStart + 0);
1858 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1859 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 head = (head + 4) & (cmdMax - cmdStart - 4);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001862 writew(head, &ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 count = FEPTIMEOUT;
1864
Alan Coxf2cf8e22005-09-06 15:16:44 -07001865 for (;;) { /* Begin forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 count--;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001867 if (count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1869 return;
1870 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001871 head = readw(&ch->mailbox->cin);
1872 cmdTail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 /* ----------------------------------------------------------
1875 Basically this will break when the FEP acknowledges the
1876 command by incrementing cmdTail (Making it equal to head).
1877 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 if (n <= ncmds * (sizeof(short) * 4))
1879 break; /* Well nearly forever :-) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 } /* End forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881} /* End fepcmd */
1882
1883/* ---------------------------------------------------------------------
1884 Digi products use fields in their channels structures that are very
1885 similar to the c_cflag and c_iflag fields typically found in UNIX
1886 termios structures. The below three routines allow mappings
1887 between these hardware "flags" and their respective Linux flags.
1888------------------------------------------------------------------------- */
1889
1890/* --------------------- Begin termios2digi_h -------------------- */
1891
1892static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1893{ /* Begin termios2digi_h */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 unsigned res = 0;
1895
Alan Coxf2cf8e22005-09-06 15:16:44 -07001896 if (cflag & CRTSCTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1898 res |= ((ch->m_cts) | (ch->m_rts));
1899 }
1900
1901 if (ch->digiext.digi_flags & RTSPACE)
1902 res |= ch->m_rts;
1903
1904 if (ch->digiext.digi_flags & DTRPACE)
1905 res |= ch->m_dtr;
1906
1907 if (ch->digiext.digi_flags & CTSPACE)
1908 res |= ch->m_cts;
1909
1910 if (ch->digiext.digi_flags & DSRPACE)
1911 res |= ch->dsr;
1912
1913 if (ch->digiext.digi_flags & DCDPACE)
1914 res |= ch->dcd;
1915
1916 if (res & (ch->m_rts))
1917 ch->digiext.digi_flags |= RTSPACE;
1918
1919 if (res & (ch->m_cts))
1920 ch->digiext.digi_flags |= CTSPACE;
1921
1922 return res;
1923
1924} /* End termios2digi_h */
1925
1926/* --------------------- Begin termios2digi_i -------------------- */
1927static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1928{ /* Begin termios2digi_i */
1929
1930 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1931 INPCK | ISTRIP|IXON|IXANY|IXOFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 if (ch->digiext.digi_flags & DIGI_AIXON)
1933 res |= IAIXON;
1934 return res;
1935
1936} /* End termios2digi_i */
1937
1938/* --------------------- Begin termios2digi_c -------------------- */
1939
1940static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1941{ /* Begin termios2digi_c */
1942
1943 unsigned res = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001944 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 ch->digiext.digi_flags |= DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 /* -------------------------------------------------------------
1947 HUPCL bit is used by FEP to indicate fast baud
1948 table is to be used.
1949 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 res |= FEP_HUPCL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 } /* End detected CBAUDEX */
1952 else ch->digiext.digi_flags &= ~DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 /* -------------------------------------------------------------------
1954 CBAUD has bit position 0x1000 set these days to indicate Linux
1955 baud rate remap. Digi hardware can't handle the bit assignment.
1956 (We use a different bit assignment for high speed.). Clear this
1957 bit out.
1958 ---------------------------------------------------------------------- */
1959 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 /* -------------------------------------------------------------
1961 This gets a little confusing. The Digi cards have their own
1962 representation of c_cflags controling baud rate. For the most
1963 part this is identical to the Linux implementation. However;
1964 Digi supports one rate (76800) that Linux doesn't. This means
1965 that the c_cflag entry that would normally mean 76800 for Digi
1966 actually means 115200 under Linux. Without the below mapping,
1967 a stty 115200 would only drive the board at 76800. Since
1968 the rate 230400 is also found after 76800, the same problem afflicts
1969 us when we choose a rate of 230400. Without the below modificiation
1970 stty 230400 would actually give us 115200.
1971
1972 There are two additional differences. The Linux value for CLOCAL
1973 (0x800; 0004000) has no meaning to the Digi hardware. Also in
1974 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
1975 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
1976 should be checked for a screened out prior to termios2digi_c
1977 returning. Since CLOCAL isn't used by the board this can be
1978 ignored as long as the returned value is used only by Digi hardware.
Alan Coxf2cf8e22005-09-06 15:16:44 -07001979 ----------------------------------------------------------------- */
1980 if (cflag & CBAUDEX) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 /* -------------------------------------------------------------
1982 The below code is trying to guarantee that only baud rates
1983 115200 and 230400 are remapped. We use exclusive or because
1984 the various baud rates share common bit positions and therefore
1985 can't be tested for easily.
1986 ----------------------------------------------------------------- */
1987
1988
1989 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1990 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 res += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 return res;
1994
1995} /* End termios2digi_c */
1996
1997/* --------------------- Begin epcaparam ----------------------- */
1998
Alan Coxf2cf8e22005-09-06 15:16:44 -07001999/* Caller must hold the locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000static void epcaparam(struct tty_struct *tty, struct channel *ch)
2001{ /* Begin epcaparam */
2002
2003 unsigned int cmdHead;
2004 struct termios *ts;
Al Virobc9a5152005-09-15 22:53:28 +01002005 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 unsigned mval, hflow, cflag, iflag;
2007
2008 bc = ch->brdchan;
2009 epcaassert(bc !=0, "bc out of range");
2010
2011 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 ts = tty->termios;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002013 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2014 cmdHead = readw(&bc->rin);
Al Virobc9a5152005-09-15 22:53:28 +01002015 writew(cmdHead, &bc->rout);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002016 cmdHead = readw(&bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 /* Changing baud in mid-stream transmission can be wonderful */
2018 /* ---------------------------------------------------------------
2019 Flush current transmit buffer by setting cmdTail pointer (tout)
2020 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2021 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2023 mval = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002024 } else { /* Begin CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 /* -------------------------------------------------------------------
2026 c_cflags have changed but that change had nothing to do with BAUD.
2027 Propagate the change to the card.
2028 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 cflag = termios2digi_c(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002030 if (cflag != ch->fepcflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 ch->fepcflag = cflag;
2032 /* Set baud rate, char size, stop bits, parity */
2033 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 /* ----------------------------------------------------------------
2036 If the user has not forced CLOCAL and if the device is not a
2037 CALLOUT device (Which is always CLOCAL) we set flags such that
2038 the driver will wait on carrier detect.
2039 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 if (ts->c_cflag & CLOCAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 ch->asyncflags &= ~ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 ch->asyncflags |= ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 mval = ch->m_dtr | ch->m_rts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 } /* End CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 iflag = termios2digi_i(ch, ts->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 /* Check input mode flags */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002048 if (iflag != ch->fepiflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 ch->fepiflag = iflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 /* ---------------------------------------------------------------
2051 Command sets channels iflag structure on the board. Such things
2052 as input soft flow control, handling of parity errors, and
2053 break handling are all set here.
2054 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 /* break handling, parity handling, input stripping, flow control chars */
2056 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2057 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 /* ---------------------------------------------------------------
2059 Set the board mint value for this channel. This will cause hardware
2060 events to be generated each time the DCD signal (Described in mint)
2061 changes.
2062 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002063 writeb(ch->dcd, &bc->mint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2065 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002066 writeb(0, &bc->mint);
2067 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 hflow = termios2digi_h(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002069 if (hflow != ch->hflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 ch->hflow = hflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 /* --------------------------------------------------------------
2072 Hard flow control has been selected but the board is not
2073 using it. Activate hard flow control now.
2074 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2076 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 mval ^= ch->modemfake & (mval ^ ch->modem);
2078
Alan Coxf2cf8e22005-09-06 15:16:44 -07002079 if (ch->omodem ^ mval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 ch->omodem = mval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 /* --------------------------------------------------------------
2082 The below command sets the DTR and RTS mstat structure. If
2083 hard flow control is NOT active these changes will drive the
2084 output of the actual DTR and RTS lines. If hard flow control
2085 is active, the changes will be saved in the mstat structure and
2086 only asserted when hard flow control is turned off.
2087 ----------------------------------------------------------------- */
2088
2089 /* First reset DTR & RTS; then set them */
2090 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2091 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002093 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 ch->fepstartc = ch->startc;
2095 ch->fepstopc = ch->stopc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 /* ------------------------------------------------------------
2097 The XON / XOFF characters have changed; propagate these
2098 changes to the card.
2099 --------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2101 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002102 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 ch->fepstartca = ch->startca;
2104 ch->fepstopca = ch->stopca;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 /* ---------------------------------------------------------------
2106 Similar to the above, this time the auxilarly XON / XOFF
2107 characters have changed; propagate these changes to the card.
2108 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111} /* End epcaparam */
2112
2113/* --------------------- Begin receive_data ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002114/* Caller holds lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115static void receive_data(struct channel *ch)
2116{ /* Begin receive_data */
2117
2118 unchar *rptr;
2119 struct termios *ts = NULL;
2120 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +01002121 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002122 int dataToRead, wrapgap, bytesAvailable;
2123 unsigned int tail, head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 unsigned int wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 /* ---------------------------------------------------------------
2127 This routine is called by doint when a receive data event
2128 has taken place.
2129 ------------------------------------------------------------------- */
2130
2131 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 if (ch->statusflags & RXSTOPPED)
2133 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 tty = ch->tty;
2135 if (tty)
2136 ts = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002138 BUG_ON(!bc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 wrapmask = ch->rxbufsize - 1;
2140
2141 /* ---------------------------------------------------------------------
2142 Get the head and tail pointers to the receiver queue. Wrap the
2143 head pointer if it has reached the end of the buffer.
2144 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002145 head = readw(&bc->rin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 head &= wrapmask;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002147 tail = readw(&bc->rout) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
2149 bytesAvailable = (head - tail) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 if (bytesAvailable == 0)
2151 return;
2152
2153 /* ------------------------------------------------------------------
2154 If CREAD bit is off or device not open, set TX tail to head
2155 --------------------------------------------------------------------- */
2156
Alan Coxf2cf8e22005-09-06 15:16:44 -07002157 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
Al Virobc9a5152005-09-15 22:53:28 +01002158 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 return;
2160 }
2161
Alan Cox33f0f882006-01-09 20:54:13 -08002162 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 return;
2164
Alan Coxf2cf8e22005-09-06 15:16:44 -07002165 if (readb(&bc->orun)) {
2166 writeb(0, &bc->orun);
2167 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
Alan Cox33f0f882006-01-09 20:54:13 -08002168 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 rxwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002171 while (bytesAvailable > 0) { /* Begin while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 /* ---------------------------------------------------------------
2174 Even if head has wrapped around only report the amount of
2175 data to be equal to the size - tail. Remember memcpy can't
2176 automaticly wrap around the receive buffer.
2177 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 /* --------------------------------------------------------------
2180 Make sure we don't overflow the buffer
2181 ----------------------------------------------------------------- */
Alan Cox33f0f882006-01-09 20:54:13 -08002182 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 if (dataToRead == 0)
2184 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 /* ---------------------------------------------------------------
2186 Move data read from our card into the line disciplines buffer
2187 for translation if necessary.
2188 ------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002189 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 tail = (tail + dataToRead) & wrapmask;
2191 bytesAvailable -= dataToRead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 } /* End while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002194 writew(tail, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 /* Must be called with global data */
2196 tty_schedule_flip(ch->tty);
2197 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198} /* End receive_data */
2199
2200static int info_ioctl(struct tty_struct *tty, struct file * file,
2201 unsigned int cmd, unsigned long arg)
2202{
2203 switch (cmd)
2204 { /* Begin switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 case DIGI_GETINFO:
2206 { /* Begin case DIGI_GETINFO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 struct digi_info di ;
2208 int brd;
2209
Alan Coxf2cf8e22005-09-06 15:16:44 -07002210 if(get_user(brd, (unsigned int __user *)arg))
2211 return -EFAULT;
2212 if (brd < 0 || brd >= num_cards || num_cards == 0)
2213 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
2215 memset(&di, 0, sizeof(di));
2216
2217 di.board = brd ;
2218 di.status = boards[brd].status;
2219 di.type = boards[brd].type ;
2220 di.numports = boards[brd].numports ;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002221 /* Legacy fixups - just move along nothing to see */
2222 di.port = (unsigned char *)boards[brd].port ;
2223 di.membase = (unsigned char *)boards[brd].membase ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2226 return -EFAULT;
2227 break;
2228
2229 } /* End case DIGI_GETINFO */
2230
2231 case DIGI_POLLER:
2232 { /* Begin case DIGI_POLLER */
2233
2234 int brd = arg & 0xff000000 >> 16 ;
2235 unsigned char state = arg & 0xff ;
2236
Alan Coxf2cf8e22005-09-06 15:16:44 -07002237 if (brd < 0 || brd >= num_cards) {
2238 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 return (-ENODEV);
2240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 digi_poller_inhibited = state ;
2242 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 } /* End case DIGI_POLLER */
2244
2245 case DIGI_INIT:
2246 { /* Begin case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 /* ------------------------------------------------------------
2248 This call is made by the apps to complete the initilization
2249 of the board(s). This routine is responsible for setting
2250 the card to its initial state and setting the drivers control
2251 fields to the sutianle settings for the card in question.
2252 ---------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 int crd ;
2254 for (crd = 0; crd < num_cards; crd++)
2255 post_fep_init (crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 } /* End case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002259 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 } /* End switch cmd */
2261 return (0) ;
2262}
2263/* --------------------- Begin pc_ioctl ----------------------- */
2264
2265static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2266{
2267 struct channel *ch = (struct channel *) tty->driver_data;
Al Virobc9a5152005-09-15 22:53:28 +01002268 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 unsigned int mstat, mflag = 0;
2270 unsigned long flags;
2271
2272 if (ch)
2273 bc = ch->brdchan;
2274 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002275 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Alan Coxf2cf8e22005-09-06 15:16:44 -07002277 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002279 mstat = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002281 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
2283 if (mstat & ch->m_dtr)
2284 mflag |= TIOCM_DTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 if (mstat & ch->m_rts)
2286 mflag |= TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 if (mstat & ch->m_cts)
2288 mflag |= TIOCM_CTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 if (mstat & ch->dsr)
2290 mflag |= TIOCM_DSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 if (mstat & ch->m_ri)
2292 mflag |= TIOCM_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 if (mstat & ch->dcd)
2294 mflag |= TIOCM_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 return mflag;
2296}
2297
2298static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2299 unsigned int set, unsigned int clear)
2300{
2301 struct channel *ch = (struct channel *) tty->driver_data;
2302 unsigned long flags;
2303
Alan Coxf2cf8e22005-09-06 15:16:44 -07002304 if (!ch)
2305 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
Alan Coxf2cf8e22005-09-06 15:16:44 -07002307 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 /*
2309 * I think this modemfake stuff is broken. It doesn't
2310 * correctly reflect the behaviour desired by the TIOCM*
2311 * ioctls. Therefore this is probably broken.
2312 */
2313 if (set & TIOCM_RTS) {
2314 ch->modemfake |= ch->m_rts;
2315 ch->modem |= ch->m_rts;
2316 }
2317 if (set & TIOCM_DTR) {
2318 ch->modemfake |= ch->m_dtr;
2319 ch->modem |= ch->m_dtr;
2320 }
2321 if (clear & TIOCM_RTS) {
2322 ch->modemfake |= ch->m_rts;
2323 ch->modem &= ~ch->m_rts;
2324 }
2325 if (clear & TIOCM_DTR) {
2326 ch->modemfake |= ch->m_dtr;
2327 ch->modem &= ~ch->m_dtr;
2328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 /* --------------------------------------------------------------
2331 The below routine generally sets up parity, baud, flow control
2332 issues, etc.... It effect both control flags and input flags.
2333 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 epcaparam(tty,ch);
2335 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002336 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 return 0;
2338}
2339
2340static int pc_ioctl(struct tty_struct *tty, struct file * file,
2341 unsigned int cmd, unsigned long arg)
2342{ /* Begin pc_ioctl */
2343
2344 digiflow_t dflow;
2345 int retval;
2346 unsigned long flags;
2347 unsigned int mflag, mstat;
2348 unsigned char startc, stopc;
Al Virobc9a5152005-09-15 22:53:28 +01002349 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 struct channel *ch = (struct channel *) tty->driver_data;
2351 void __user *argp = (void __user *)arg;
2352
2353 if (ch)
2354 bc = ch->brdchan;
2355 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002356 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
2358 /* -------------------------------------------------------------------
2359 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2360 in /usr/src/linux/drivers/char for a good example. In particular
2361 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2362 ---------------------------------------------------------------------- */
2363
2364 switch (cmd)
2365 { /* Begin switch cmd */
2366
2367 case TCGETS:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002368 if (copy_to_user(argp, tty->termios, sizeof(struct termios)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 return -EFAULT;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002370 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 case TCGETA:
2372 return get_termio(tty, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 case TCSBRK: /* SVID version: non-zero arg --> no break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 retval = tty_check_change(tty);
2375 if (retval)
2376 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002378 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002380 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 tty_wait_until_sent(tty, 0);
2382 if (!arg)
2383 digi_send_break(ch, HZ/4); /* 1/4 second */
2384 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 case TCSBRKP: /* support for POSIX tcsendbreak() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 retval = tty_check_change(tty);
2387 if (retval)
2388 return retval;
2389
2390 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002391 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002393 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 tty_wait_until_sent(tty, 0);
2395 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2396 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 case TIOCGSOFTCAR:
2398 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2399 return -EFAULT;
2400 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 case TIOCSSOFTCAR:
2402 {
2403 unsigned int value;
2404
2405 if (get_user(value, (unsigned __user *)argp))
2406 return -EFAULT;
2407 tty->termios->c_cflag =
2408 ((tty->termios->c_cflag & ~CLOCAL) |
2409 (value ? CLOCAL : 0));
2410 return 0;
2411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 case TIOCMODG:
2413 mflag = pc_tiocmget(tty, file);
2414 if (put_user(mflag, (unsigned long __user *)argp))
2415 return -EFAULT;
2416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 case TIOCMODS:
2418 if (get_user(mstat, (unsigned __user *)argp))
2419 return -EFAULT;
2420 return pc_tiocmset(tty, file, mstat, ~mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 case TIOCSDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002422 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 ch->omodem |= ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 globalwinon(ch);
2425 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2426 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002427 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 break;
2429
2430 case TIOCCDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002431 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 ch->omodem &= ~ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 globalwinon(ch);
2434 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2435 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002436 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 case DIGI_GETA:
2439 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2440 return -EFAULT;
2441 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 case DIGI_SETAW:
2443 case DIGI_SETAF:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002444 if (cmd == DIGI_SETAW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002446 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002448 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 tty_wait_until_sent(tty, 0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002450 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 /* ldisc lock already held in ioctl */
2452 if (tty->ldisc.flush_buffer)
2453 tty->ldisc.flush_buffer(tty);
2454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 /* Fall Thru */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 case DIGI_SETA:
2457 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2458 return -EFAULT;
2459
Alan Coxf2cf8e22005-09-06 15:16:44 -07002460 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 ch->dcd = ch->m_dsr;
2462 ch->dsr = ch->m_dcd;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002463 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 ch->dcd = ch->m_dcd;
2465 ch->dsr = ch->m_dsr;
2466 }
2467
Alan Coxf2cf8e22005-09-06 15:16:44 -07002468 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 globalwinon(ch);
2470
2471 /* -----------------------------------------------------------------
2472 The below routine generally sets up parity, baud, flow control
2473 issues, etc.... It effect both control flags and input flags.
2474 ------------------------------------------------------------------- */
2475
2476 epcaparam(tty,ch);
2477 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002478 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 break;
2480
2481 case DIGI_GETFLOW:
2482 case DIGI_GETAFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002483 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002485 if (cmd == DIGI_GETFLOW) {
2486 dflow.startc = readb(&bc->startc);
2487 dflow.stopc = readb(&bc->stopc);
2488 } else {
2489 dflow.startc = readb(&bc->startca);
2490 dflow.stopc = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 }
2492 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002493 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
2495 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2496 return -EFAULT;
2497 break;
2498
2499 case DIGI_SETAFLOW:
2500 case DIGI_SETFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002501 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 startc = ch->startc;
2503 stopc = ch->stopc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002504 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 startc = ch->startca;
2506 stopc = ch->stopca;
2507 }
2508
2509 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2510 return -EFAULT;
2511
Alan Coxf2cf8e22005-09-06 15:16:44 -07002512 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2513 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 globalwinon(ch);
2515
Alan Coxf2cf8e22005-09-06 15:16:44 -07002516 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 ch->fepstartc = ch->startc = dflow.startc;
2518 ch->fepstopc = ch->stopc = dflow.stopc;
2519 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002520 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 ch->fepstartca = ch->startca = dflow.startc;
2522 ch->fepstopca = ch->stopca = dflow.stopc;
2523 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2524 }
2525
Alan Coxf2cf8e22005-09-06 15:16:44 -07002526 if (ch->statusflags & TXSTOPPED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 pc_start(tty);
2528
2529 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002530 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 } /* End if setflow toggled */
2532 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 default:
2534 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 } /* End switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537} /* End pc_ioctl */
2538
2539/* --------------------- Begin pc_set_termios ----------------------- */
2540
2541static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
2542{ /* Begin pc_set_termios */
2543
2544 struct channel *ch;
2545 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 /* ---------------------------------------------------------
2547 verifyChannel returns the channel from the tty struct
2548 if it is valid. This serves as a sanity check.
2549 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002550 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2551 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 globalwinon(ch);
2553 epcaparam(tty, ch);
2554 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002555 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
2557 if ((old_termios->c_cflag & CRTSCTS) &&
2558 ((tty->termios->c_cflag & CRTSCTS) == 0))
2559 tty->hw_stopped = 0;
2560
2561 if (!(old_termios->c_cflag & CLOCAL) &&
2562 (tty->termios->c_cflag & CLOCAL))
2563 wake_up_interruptible(&ch->open_wait);
2564
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 } /* End if channel valid */
2566
2567} /* End pc_set_termios */
2568
2569/* --------------------- Begin do_softint ----------------------- */
2570
2571static void do_softint(void *private_)
2572{ /* Begin do_softint */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct channel *ch = (struct channel *) private_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 /* Called in response to a modem change event */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002575 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct tty_struct *tty = ch->tty;
2577
Alan Coxf2cf8e22005-09-06 15:16:44 -07002578 if (tty && tty->driver_data) {
2579 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2581 wake_up_interruptible(&ch->open_wait);
2582 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 } /* End if clear_bit */
2584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 } /* End EPCA_MAGIC */
2586} /* End do_softint */
2587
2588/* ------------------------------------------------------------
2589 pc_stop and pc_start provide software flow control to the
2590 routine and the pc_ioctl routine.
2591---------------------------------------------------------------- */
2592
2593/* --------------------- Begin pc_stop ----------------------- */
2594
2595static void pc_stop(struct tty_struct *tty)
2596{ /* Begin pc_stop */
2597
2598 struct channel *ch;
2599 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 /* ---------------------------------------------------------
2601 verifyChannel returns the channel from the tty struct
2602 if it is valid. This serves as a sanity check.
2603 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002604 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
2605 spin_lock_irqsave(&epca_lock, flags);
2606 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 /* STOP transmitting now !! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 ch->statusflags |= TXSTOPPED;
2611 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 } /* End if transmit stop requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002613 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 } /* End if valid channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615} /* End pc_stop */
2616
2617/* --------------------- Begin pc_start ----------------------- */
2618
2619static void pc_start(struct tty_struct *tty)
2620{ /* Begin pc_start */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 /* ---------------------------------------------------------
2623 verifyChannel returns the channel from the tty struct
2624 if it is valid. This serves as a sanity check.
2625 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002626 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002628 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002630 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
Al Virobc9a5152005-09-15 22:53:28 +01002631 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 globalwinon(ch);
2633 bc = ch->brdchan;
2634 if (ch->statusflags & LOWWAIT)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002635 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 /* Okay, you can start transmitting again... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 ch->statusflags &= ~TXSTOPPED;
2639 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 } /* End transmit resume requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002641 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643} /* End pc_start */
2644
2645/* ------------------------------------------------------------------
2646 The below routines pc_throttle and pc_unthrottle are used
2647 to slow (And resume) the receipt of data into the kernels
2648 receive buffers. The exact occurrence of this depends on the
2649 size of the kernels receive buffer and what the 'watermarks'
2650 are set to for that buffer. See the n_ttys.c file for more
2651 details.
2652______________________________________________________________________ */
2653/* --------------------- Begin throttle ----------------------- */
2654
2655static void pc_throttle(struct tty_struct * tty)
2656{ /* Begin pc_throttle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 struct channel *ch;
2658 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 /* ---------------------------------------------------------
2660 verifyChannel returns the channel from the tty struct
2661 if it is valid. This serves as a sanity check.
2662 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002663 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2664 spin_lock_irqsave(&epca_lock, flags);
2665 if ((ch->statusflags & RXSTOPPED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 globalwinon(ch);
2667 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 ch->statusflags |= RXSTOPPED;
2669 memoff(ch);
2670 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002671 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673} /* End pc_throttle */
2674
2675/* --------------------- Begin unthrottle ----------------------- */
2676
2677static void pc_unthrottle(struct tty_struct *tty)
2678{ /* Begin pc_unthrottle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 struct channel *ch;
2680 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 /* ---------------------------------------------------------
2682 verifyChannel returns the channel from the tty struct
2683 if it is valid. This serves as a sanity check.
2684 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002685 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002687 spin_lock_irqsave(&epca_lock, flags);
2688 if (ch->statusflags & RXSTOPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 ch->statusflags &= ~RXSTOPPED;
2692 memoff(ch);
2693 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002694 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696} /* End pc_unthrottle */
2697
2698/* --------------------- Begin digi_send_break ----------------------- */
2699
2700void digi_send_break(struct channel *ch, int msec)
2701{ /* Begin digi_send_break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 unsigned long flags;
2703
Alan Coxf2cf8e22005-09-06 15:16:44 -07002704 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 /* --------------------------------------------------------------------
2707 Maybe I should send an infinite break here, schedule() for
2708 msec amount of time, and then stop the break. This way,
2709 the user can't screw up the FEP by causing digi_send_break()
2710 to be called (i.e. via an ioctl()) more than once in msec amount
2711 of time. Try this for now...
2712 ------------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2714 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002715 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716} /* End digi_send_break */
2717
2718/* --------------------- Begin setup_empty_event ----------------------- */
2719
Alan Coxf2cf8e22005-09-06 15:16:44 -07002720/* Caller MUST hold the lock */
2721
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2723{ /* Begin setup_empty_event */
2724
Al Virobc9a5152005-09-15 22:53:28 +01002725 struct board_chan __iomem *bc = ch->brdchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 globalwinon(ch);
2728 ch->statusflags |= EMPTYWAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 /* ------------------------------------------------------------------
2730 When set the iempty flag request a event to be generated when the
2731 transmit buffer is empty (If there is no BREAK in progress).
2732 --------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002733 writeb(1, &bc->iempty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735} /* End setup_empty_event */
2736
2737/* --------------------- Begin get_termio ----------------------- */
2738
2739static int get_termio(struct tty_struct * tty, struct termio __user * termio)
2740{ /* Begin get_termio */
2741 return kernel_termios_to_user_termio(termio, tty->termios);
2742} /* End get_termio */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002743
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744/* ---------------------- Begin epca_setup -------------------------- */
2745void epca_setup(char *str, int *ints)
2746{ /* Begin epca_setup */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 struct board_info board;
2748 int index, loop, last;
2749 char *temp, *t2;
2750 unsigned len;
2751
2752 /* ----------------------------------------------------------------------
2753 If this routine looks a little strange it is because it is only called
2754 if a LILO append command is given to boot the kernel with parameters.
2755 In this way, we can provide the user a method of changing his board
2756 configuration without rebuilding the kernel.
2757 ----------------------------------------------------------------------- */
2758 if (!liloconfig)
2759 liloconfig = 1;
2760
2761 memset(&board, 0, sizeof(board));
2762
2763 /* Assume the data is int first, later we can change it */
2764 /* I think that array position 0 of ints holds the number of args */
2765 for (last = 0, index = 1; index <= ints[0]; index++)
2766 switch(index)
2767 { /* Begin parse switch */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 case 1:
2769 board.status = ints[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 /* ---------------------------------------------------------
2771 We check for 2 (As opposed to 1; because 2 is a flag
2772 instructing the driver to ignore epcaconfig.) For this
2773 reason we check for 2.
2774 ------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002775 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 nbdevs = 0;
2777 num_cards = 0;
2778 return;
2779 } /* End ignore epcaconfig as well as lilo cmd line */
2780
Alan Coxf2cf8e22005-09-06 15:16:44 -07002781 if (board.status > 2) {
2782 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 invalid_lilo_config = 1;
2784 setup_error_code |= INVALID_BOARD_STATUS;
2785 return;
2786 }
2787 last = index;
2788 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 case 2:
2790 board.type = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002791 if (board.type >= PCIXEM) {
2792 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 invalid_lilo_config = 1;
2794 setup_error_code |= INVALID_BOARD_TYPE;
2795 return;
2796 }
2797 last = index;
2798 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 case 3:
2800 board.altpin = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002801 if (board.altpin > 1) {
2802 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 invalid_lilo_config = 1;
2804 setup_error_code |= INVALID_ALTPIN;
2805 return;
2806 }
2807 last = index;
2808 break;
2809
2810 case 4:
2811 board.numports = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002812 if (board.numports < 2 || board.numports > 256) {
2813 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 invalid_lilo_config = 1;
2815 setup_error_code |= INVALID_NUM_PORTS;
2816 return;
2817 }
2818 nbdevs += board.numports;
2819 last = index;
2820 break;
2821
2822 case 5:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002823 board.port = ints[index];
2824 if (ints[index] <= 0) {
2825 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 invalid_lilo_config = 1;
2827 setup_error_code |= INVALID_PORT_BASE;
2828 return;
2829 }
2830 last = index;
2831 break;
2832
2833 case 6:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002834 board.membase = ints[index];
2835 if (ints[index] <= 0) {
2836 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 invalid_lilo_config = 1;
2838 setup_error_code |= INVALID_MEM_BASE;
2839 return;
2840 }
2841 last = index;
2842 break;
2843
2844 default:
2845 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2846 return;
2847
2848 } /* End parse switch */
2849
Alan Coxf2cf8e22005-09-06 15:16:44 -07002850 while (str && *str) { /* Begin while there is a string arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 /* find the next comma or terminator */
2852 temp = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 /* While string is not null, and a comma hasn't been found */
2854 while (*temp && (*temp != ','))
2855 temp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 if (!*temp)
2857 temp = NULL;
2858 else
2859 *temp++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 /* Set index to the number of args + 1 */
2861 index = last + 1;
2862
2863 switch(index)
2864 {
2865 case 1:
2866 len = strlen(str);
2867 if (strncmp("Disable", str, len) == 0)
2868 board.status = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002869 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 board.status = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002871 else {
2872 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 invalid_lilo_config = 1;
2874 setup_error_code |= INVALID_BOARD_STATUS;
2875 return;
2876 }
2877 last = index;
2878 break;
2879
2880 case 2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
2882 if (strcmp(board_desc[loop], str) == 0)
2883 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 /* ---------------------------------------------------------------
2885 If the index incremented above refers to a legitamate board
2886 type set it here.
2887 ------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 if (index < EPCA_NUM_TYPES)
2889 board.type = loop;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002890 else {
2891 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 invalid_lilo_config = 1;
2893 setup_error_code |= INVALID_BOARD_TYPE;
2894 return;
2895 }
2896 last = index;
2897 break;
2898
2899 case 3:
2900 len = strlen(str);
2901 if (strncmp("Disable", str, len) == 0)
2902 board.altpin = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002903 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 board.altpin = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002905 else {
2906 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 invalid_lilo_config = 1;
2908 setup_error_code |= INVALID_ALTPIN;
2909 return;
2910 }
2911 last = index;
2912 break;
2913
2914 case 4:
2915 t2 = str;
2916 while (isdigit(*t2))
2917 t2++;
2918
Alan Coxf2cf8e22005-09-06 15:16:44 -07002919 if (*t2) {
2920 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 invalid_lilo_config = 1;
2922 setup_error_code |= INVALID_NUM_PORTS;
2923 return;
2924 }
2925
2926 /* ------------------------------------------------------------
2927 There is not a man page for simple_strtoul but the code can be
2928 found in vsprintf.c. The first argument is the string to
2929 translate (To an unsigned long obviously), the second argument
2930 can be the address of any character variable or a NULL. If a
2931 variable is given, the end pointer of the string will be stored
2932 in that variable; if a NULL is given the end pointer will
2933 not be returned. The last argument is the base to use. If
2934 a 0 is indicated, the routine will attempt to determine the
2935 proper base by looking at the values prefix (A '0' for octal,
2936 a 'x' for hex, etc ... If a value is given it will use that
2937 value as the base.
2938 ---------------------------------------------------------------- */
2939 board.numports = simple_strtoul(str, NULL, 0);
2940 nbdevs += board.numports;
2941 last = index;
2942 break;
2943
2944 case 5:
2945 t2 = str;
2946 while (isxdigit(*t2))
2947 t2++;
2948
Alan Coxf2cf8e22005-09-06 15:16:44 -07002949 if (*t2) {
2950 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 invalid_lilo_config = 1;
2952 setup_error_code |= INVALID_PORT_BASE;
2953 return;
2954 }
2955
Alan Coxf2cf8e22005-09-06 15:16:44 -07002956 board.port = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 last = index;
2958 break;
2959
2960 case 6:
2961 t2 = str;
2962 while (isxdigit(*t2))
2963 t2++;
2964
Alan Coxf2cf8e22005-09-06 15:16:44 -07002965 if (*t2) {
2966 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 invalid_lilo_config = 1;
2968 setup_error_code |= INVALID_MEM_BASE;
2969 return;
2970 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002971 board.membase = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 last = index;
2973 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002975 printk(KERN_ERR "epca: Too many string parms\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 return;
2977 }
2978 str = temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 } /* End while there is a string arg */
2980
Alan Coxf2cf8e22005-09-06 15:16:44 -07002981 if (last < 6) {
2982 printk(KERN_ERR "epca: Insufficient parms specified\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 return;
2984 }
2985
2986 /* I should REALLY validate the stuff here */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 /* Copies our local copy of board into boards */
2988 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 /* Does this get called once per lilo arg are what ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2991 num_cards, board_desc[board.type],
2992 board.numports, (int)board.port, (unsigned int) board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 num_cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994} /* End epca_setup */
2995
2996
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997/* ------------------------ Begin init_PCI --------------------------- */
2998
2999enum epic_board_types {
3000 brd_xr = 0,
3001 brd_xem,
3002 brd_cx,
3003 brd_xrj,
3004};
3005
3006
3007/* indexed directly by epic_board_types enum */
3008static struct {
3009 unsigned char board_type;
3010 unsigned bar_idx; /* PCI base address region */
3011} epca_info_tbl[] = {
3012 { PCIXR, 0, },
3013 { PCIXEM, 0, },
3014 { PCICX, 0, },
3015 { PCIXRJ, 2, },
3016};
3017
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018static int __devinit epca_init_one (struct pci_dev *pdev,
3019 const struct pci_device_id *ent)
3020{
3021 static int board_num = -1;
3022 int board_idx, info_idx = ent->driver_data;
3023 unsigned long addr;
3024
3025 if (pci_enable_device(pdev))
3026 return -EIO;
3027
3028 board_num++;
3029 board_idx = board_num + num_cards;
3030 if (board_idx >= MAXBOARDS)
3031 goto err_out;
3032
3033 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3034 if (!addr) {
3035 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3036 epca_info_tbl[info_idx].bar_idx);
3037 goto err_out;
3038 }
3039
3040 boards[board_idx].status = ENABLED;
3041 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3042 boards[board_idx].numports = 0x0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07003043 boards[board_idx].port = addr + PCI_IO_OFFSET;
3044 boards[board_idx].membase = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
3046 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3047 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3048 0x200000, addr + PCI_IO_OFFSET);
3049 goto err_out;
3050 }
3051
3052 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3053 if (!boards[board_idx].re_map_port) {
3054 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3055 0x200000, addr + PCI_IO_OFFSET);
3056 goto err_out_free_pciio;
3057 }
3058
3059 if (!request_mem_region (addr, 0x200000, "epca")) {
3060 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3061 0x200000, addr);
3062 goto err_out_free_iounmap;
3063 }
3064
3065 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3066 if (!boards[board_idx].re_map_membase) {
3067 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3068 0x200000, addr + PCI_IO_OFFSET);
3069 goto err_out_free_memregion;
3070 }
3071
3072 /* --------------------------------------------------------------
3073 I don't know what the below does, but the hardware guys say
3074 its required on everything except PLX (In this case XRJ).
3075 ---------------------------------------------------------------- */
3076 if (info_idx != brd_xrj) {
3077 pci_write_config_byte(pdev, 0x40, 0);
3078 pci_write_config_byte(pdev, 0x46, 0);
3079 }
3080
3081 return 0;
3082
3083err_out_free_memregion:
3084 release_mem_region (addr, 0x200000);
3085err_out_free_iounmap:
3086 iounmap (boards[board_idx].re_map_port);
3087err_out_free_pciio:
3088 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3089err_out:
3090 return -ENODEV;
3091}
3092
3093
3094static struct pci_device_id epca_pci_tbl[] = {
3095 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3096 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3097 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3098 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3099 { 0, }
3100};
3101
3102MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3103
3104int __init init_PCI (void)
Alan Coxf2cf8e22005-09-06 15:16:44 -07003105{ /* Begin init_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 memset (&epca_driver, 0, sizeof (epca_driver));
3107 epca_driver.name = "epca";
3108 epca_driver.id_table = epca_pci_tbl;
3109 epca_driver.probe = epca_init_one;
3110
3111 return pci_register_driver(&epca_driver);
Alan Coxf2cf8e22005-09-06 15:16:44 -07003112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
3114MODULE_LICENSE("GPL");