blob: c6c56fb8ba5098f341692d16c698e39a383abda1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2
3
4 Copyright (C) 1996 Digi International.
5
6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456
8
Alan Coxf2cf8e22005-09-06 15:16:44 -07009 ** This driver is no longer supported by Digi **
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 Much of this design and code came from epca.c which was
12 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
13 modified by David Nugent, Christoph Lameter, Mike McLagan.
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
29--------------------------------------------------------------------------- */
30/* See README.epca for change history --DAT*/
31
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/types.h>
36#include <linux/init.h>
37#include <linux/serial.h>
38#include <linux/delay.h>
39#include <linux/ctype.h>
40#include <linux/tty.h>
41#include <linux/tty_flip.h>
42#include <linux/slab.h>
43#include <linux/ioport.h>
44#include <linux/interrupt.h>
45#include <asm/uaccess.h>
46#include <asm/io.h>
Alan Coxf2cf8e22005-09-06 15:16:44 -070047#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/pci.h>
49#include "digiPCI.h"
Alan Coxf2cf8e22005-09-06 15:16:44 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include "digi1.h"
53#include "digiFep1.h"
54#include "epca.h"
55#include "epcaconfig.h"
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/* ---------------------- Begin defines ------------------------ */
58
Alan Coxf2cf8e22005-09-06 15:16:44 -070059#define VERSION "1.3.0.1-LK2.6"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61/* This major needs to be submitted to Linux to join the majors list */
62
63#define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
64
65
66#define MAXCARDS 7
67#define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
68
69#define PFX "epca: "
70
71/* ----------------- Begin global definitions ------------------- */
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static int nbdevs, num_cards, liloconfig;
74static int digi_poller_inhibited = 1 ;
75
76static int setup_error_code;
77static int invalid_lilo_config;
78
Alan Coxf2cf8e22005-09-06 15:16:44 -070079/* The ISA boards do window flipping into the same spaces so its only sane
80 with a single lock. It's still pretty efficient */
81
Ingo Molnar34af9462006-06-27 02:53:55 -070082static DEFINE_SPINLOCK(epca_lock);
Alan Coxf2cf8e22005-09-06 15:16:44 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/* -----------------------------------------------------------------------
85 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
86 7 below.
87--------------------------------------------------------------------------*/
88static struct board_info boards[MAXBOARDS];
89
90
91/* ------------- Begin structures used for driver registeration ---------- */
92
93static struct tty_driver *pc_driver;
94static struct tty_driver *pc_info;
95
96/* ------------------ Begin Digi specific structures -------------------- */
97
98/* ------------------------------------------------------------------------
99 digi_channels represents an array of structures that keep track of
100 each channel of the Digi product. Information such as transmit and
101 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
102 are stored here. This structure is NOT used to overlay the cards
103 physical channel structure.
104-------------------------------------------------------------------------- */
105
106static struct channel digi_channels[MAX_ALLOC];
107
108/* ------------------------------------------------------------------------
109 card_ptr is an array used to hold the address of the
110 first channel structure of each card. This array will hold
111 the addresses of various channels located in digi_channels.
112-------------------------------------------------------------------------- */
113static struct channel *card_ptr[MAXCARDS];
114
115static struct timer_list epca_timer;
116
117/* ---------------------- Begin function prototypes --------------------- */
118
119/* ----------------------------------------------------------------------
120 Begin generic memory functions. These functions will be alias
121 (point at) more specific functions dependent on the board being
122 configured.
123----------------------------------------------------------------------- */
124
Alan Coxf2cf8e22005-09-06 15:16:44 -0700125static void memwinon(struct board_info *b, unsigned int win);
126static void memwinoff(struct board_info *b, unsigned int win);
127static void globalwinon(struct channel *ch);
128static void rxwinon(struct channel *ch);
129static void txwinon(struct channel *ch);
130static void memoff(struct channel *ch);
131static void assertgwinon(struct channel *ch);
132static void assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/* ---- Begin more 'specific' memory functions for cx_like products --- */
135
Alan Coxf2cf8e22005-09-06 15:16:44 -0700136static void pcxem_memwinon(struct board_info *b, unsigned int win);
137static void pcxem_memwinoff(struct board_info *b, unsigned int win);
138static void pcxem_globalwinon(struct channel *ch);
139static void pcxem_rxwinon(struct channel *ch);
140static void pcxem_txwinon(struct channel *ch);
141static void pcxem_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/* ------ Begin more 'specific' memory functions for the pcxe ------- */
144
Alan Coxf2cf8e22005-09-06 15:16:44 -0700145static void pcxe_memwinon(struct board_info *b, unsigned int win);
146static void pcxe_memwinoff(struct board_info *b, unsigned int win);
147static void pcxe_globalwinon(struct channel *ch);
148static void pcxe_rxwinon(struct channel *ch);
149static void pcxe_txwinon(struct channel *ch);
150static void pcxe_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
153/* Note : pc64xe and pcxi share the same windowing routines */
154
Alan Coxf2cf8e22005-09-06 15:16:44 -0700155static void pcxi_memwinon(struct board_info *b, unsigned int win);
156static void pcxi_memwinoff(struct board_info *b, unsigned int win);
157static void pcxi_globalwinon(struct channel *ch);
158static void pcxi_rxwinon(struct channel *ch);
159static void pcxi_txwinon(struct channel *ch);
160static void pcxi_memoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162/* - Begin 'specific' do nothing memory functions needed for some cards - */
163
Alan Coxf2cf8e22005-09-06 15:16:44 -0700164static void dummy_memwinon(struct board_info *b, unsigned int win);
165static void dummy_memwinoff(struct board_info *b, unsigned int win);
166static void dummy_globalwinon(struct channel *ch);
167static void dummy_rxwinon(struct channel *ch);
168static void dummy_txwinon(struct channel *ch);
169static void dummy_memoff(struct channel *ch);
170static void dummy_assertgwinon(struct channel *ch);
171static void dummy_assertmemoff(struct channel *ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173/* ------------------- Begin declare functions ----------------------- */
174
Alan Coxf2cf8e22005-09-06 15:16:44 -0700175static struct channel *verifyChannel(struct tty_struct *);
176static void pc_sched_event(struct channel *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static void epca_error(int, char *);
178static void pc_close(struct tty_struct *, struct file *);
179static void shutdown(struct channel *);
180static void pc_hangup(struct tty_struct *);
181static void pc_put_char(struct tty_struct *, unsigned char);
182static int pc_write_room(struct tty_struct *);
183static int pc_chars_in_buffer(struct tty_struct *);
184static void pc_flush_buffer(struct tty_struct *);
185static void pc_flush_chars(struct tty_struct *);
186static int block_til_ready(struct tty_struct *, struct file *,
187 struct channel *);
188static int pc_open(struct tty_struct *, struct file *);
189static void post_fep_init(unsigned int crd);
190static void epcapoll(unsigned long);
191static void doevent(int);
192static void fepcmd(struct channel *, int, int, int, int, int);
193static unsigned termios2digi_h(struct channel *ch, unsigned);
194static unsigned termios2digi_i(struct channel *ch, unsigned);
195static unsigned termios2digi_c(struct channel *ch, unsigned);
196static void epcaparam(struct tty_struct *, struct channel *);
197static void receive_data(struct channel *);
198static int pc_ioctl(struct tty_struct *, struct file *,
199 unsigned int, unsigned long);
200static int info_ioctl(struct tty_struct *, struct file *,
201 unsigned int, unsigned long);
Alan Cox606d0992006-12-08 02:38:45 -0800202static void pc_set_termios(struct tty_struct *, struct ktermios *);
David Howellsc4028952006-11-22 14:57:56 +0000203static void do_softint(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static void pc_stop(struct tty_struct *);
205static void pc_start(struct tty_struct *);
206static void pc_throttle(struct tty_struct * tty);
207static void pc_unthrottle(struct tty_struct *tty);
208static void digi_send_break(struct channel *ch, int msec);
209static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
210void epca_setup(char *, int *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212static int pc_write(struct tty_struct *, const unsigned char *, int);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700213static int pc_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214static int init_PCI(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216
217/* ------------------------------------------------------------------
218 Table of functions for each board to handle memory. Mantaining
219 parallelism is a *very* good idea here. The idea is for the
220 runtime code to blindly call these functions, not knowing/caring
221 about the underlying hardware. This stuff should contain no
222 conditionals; if more functionality is needed a different entry
223 should be established. These calls are the interface calls and
224 are the only functions that should be accessed. Anyone caught
225 making direct calls deserves what they get.
226-------------------------------------------------------------------- */
227
Alan Coxf2cf8e22005-09-06 15:16:44 -0700228static void memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 (b->memwinon)(b, win);
231}
232
Alan Coxf2cf8e22005-09-06 15:16:44 -0700233static void memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
235 (b->memwinoff)(b, win);
236}
237
Alan Coxf2cf8e22005-09-06 15:16:44 -0700238static void globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 (ch->board->globalwinon)(ch);
241}
242
Alan Coxf2cf8e22005-09-06 15:16:44 -0700243static void rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 (ch->board->rxwinon)(ch);
246}
247
Alan Coxf2cf8e22005-09-06 15:16:44 -0700248static void txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250 (ch->board->txwinon)(ch);
251}
252
Alan Coxf2cf8e22005-09-06 15:16:44 -0700253static void memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 (ch->board->memoff)(ch);
256}
Alan Coxf2cf8e22005-09-06 15:16:44 -0700257static void assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 (ch->board->assertgwinon)(ch);
260}
261
Alan Coxf2cf8e22005-09-06 15:16:44 -0700262static void assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
264 (ch->board->assertmemoff)(ch);
265}
266
267/* ---------------------------------------------------------
268 PCXEM windowing is the same as that used in the PCXR
269 and CX series cards.
270------------------------------------------------------------ */
271
Alan Coxf2cf8e22005-09-06 15:16:44 -0700272static void pcxem_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700274 outb_p(FEPWIN|win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Alan Coxf2cf8e22005-09-06 15:16:44 -0700277static void pcxem_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700279 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Alan Coxf2cf8e22005-09-06 15:16:44 -0700282static void pcxem_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
284 outb_p( FEPWIN, (int)ch->board->port + 1);
285}
286
Alan Coxf2cf8e22005-09-06 15:16:44 -0700287static void pcxem_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 outb_p(ch->rxwin, (int)ch->board->port + 1);
290}
291
Alan Coxf2cf8e22005-09-06 15:16:44 -0700292static void pcxem_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
294 outb_p(ch->txwin, (int)ch->board->port + 1);
295}
296
Alan Coxf2cf8e22005-09-06 15:16:44 -0700297static void pcxem_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
299 outb_p(0, (int)ch->board->port + 1);
300}
301
302/* ----------------- Begin pcxe memory window stuff ------------------ */
303
Alan Coxf2cf8e22005-09-06 15:16:44 -0700304static void pcxe_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700306 outb_p(FEPWIN | win, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Alan Coxf2cf8e22005-09-06 15:16:44 -0700309static void pcxe_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700311 outb_p(inb(b->port) & ~FEPMEM,
312 b->port + 1);
313 outb_p(0, b->port + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
Alan Coxf2cf8e22005-09-06 15:16:44 -0700316static void pcxe_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 outb_p( FEPWIN, (int)ch->board->port + 1);
319}
320
Alan Coxf2cf8e22005-09-06 15:16:44 -0700321static void pcxe_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 outb_p(ch->rxwin, (int)ch->board->port + 1);
324}
325
Alan Coxf2cf8e22005-09-06 15:16:44 -0700326static void pcxe_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
328 outb_p(ch->txwin, (int)ch->board->port + 1);
329}
330
Alan Coxf2cf8e22005-09-06 15:16:44 -0700331static void pcxe_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 outb_p(0, (int)ch->board->port);
334 outb_p(0, (int)ch->board->port + 1);
335}
336
337/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
338
Alan Coxf2cf8e22005-09-06 15:16:44 -0700339static void pcxi_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700341 outb_p(inb(b->port) | FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
Alan Coxf2cf8e22005-09-06 15:16:44 -0700344static void pcxi_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700346 outb_p(inb(b->port) & ~FEPMEM, b->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Alan Coxf2cf8e22005-09-06 15:16:44 -0700349static void pcxi_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700351 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Alan Coxf2cf8e22005-09-06 15:16:44 -0700354static void pcxi_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700356 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Alan Coxf2cf8e22005-09-06 15:16:44 -0700359static void pcxi_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700361 outb_p(FEPMEM, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Alan Coxf2cf8e22005-09-06 15:16:44 -0700364static void pcxi_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700366 outb_p(0, ch->board->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
368
Alan Coxf2cf8e22005-09-06 15:16:44 -0700369static void pcxi_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700371 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
Alan Coxf2cf8e22005-09-06 15:16:44 -0700374static void pcxi_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Alan Coxf2cf8e22005-09-06 15:16:44 -0700376 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
379
380/* ----------------------------------------------------------------------
381 Not all of the cards need specific memory windowing routines. Some
382 cards (Such as PCI) needs no windowing routines at all. We provide
383 these do nothing routines so that the same code base can be used.
384 The driver will ALWAYS call a windowing routine if it thinks it needs
385 to; regardless of the card. However, dependent on the card the routine
386 may or may not do anything.
387---------------------------------------------------------------------------*/
388
Alan Coxf2cf8e22005-09-06 15:16:44 -0700389static void dummy_memwinon(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
391}
392
Alan Coxf2cf8e22005-09-06 15:16:44 -0700393static void dummy_memwinoff(struct board_info *b, unsigned int win)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
395}
396
Alan Coxf2cf8e22005-09-06 15:16:44 -0700397static void dummy_globalwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399}
400
Alan Coxf2cf8e22005-09-06 15:16:44 -0700401static void dummy_rxwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403}
404
Alan Coxf2cf8e22005-09-06 15:16:44 -0700405static void dummy_txwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
407}
408
Alan Coxf2cf8e22005-09-06 15:16:44 -0700409static void dummy_memoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
411}
412
Alan Coxf2cf8e22005-09-06 15:16:44 -0700413static void dummy_assertgwinon(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
415}
416
Alan Coxf2cf8e22005-09-06 15:16:44 -0700417static void dummy_assertmemoff(struct channel *ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
419}
420
421/* ----------------- Begin verifyChannel function ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700422static struct channel *verifyChannel(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{ /* Begin verifyChannel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 /* --------------------------------------------------------------------
425 This routine basically provides a sanity check. It insures that
426 the channel returned is within the proper range of addresses as
427 well as properly initialized. If some bogus info gets passed in
428 through tty->driver_data this should catch it.
Alan Coxf2cf8e22005-09-06 15:16:44 -0700429 --------------------------------------------------------------------- */
430 if (tty) {
431 struct channel *ch = (struct channel *)tty->driver_data;
432 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 if (ch->magic == EPCA_MAGIC)
434 return ch;
435 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return NULL;
438
439} /* End verifyChannel */
440
441/* ------------------ Begin pc_sched_event ------------------------- */
442
Alan Coxf2cf8e22005-09-06 15:16:44 -0700443static void pc_sched_event(struct channel *ch, int event)
444{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 /* ----------------------------------------------------------------------
446 We call this to schedule interrupt processing on some event. The
447 kernel sees our request and calls the related routine in OUR driver.
448 -------------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 ch->event |= 1 << event;
450 schedule_work(&ch->tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451} /* End pc_sched_event */
452
453/* ------------------ Begin epca_error ------------------------- */
454
455static void epca_error(int line, char *msg)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700456{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700458}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460/* ------------------ Begin pc_close ------------------------- */
461static void pc_close(struct tty_struct * tty, struct file * filp)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700462{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 struct channel *ch;
464 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /* ---------------------------------------------------------
466 verifyChannel returns the channel from the tty struct
467 if it is valid. This serves as a sanity check.
468 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700469 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
470 spin_lock_irqsave(&epca_lock, flags);
471 if (tty_hung_up_p(filp)) {
472 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return;
474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 /* Check to see if the channel is open more than once */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700476 if (ch->count-- > 1) {
477 /* Begin channel is open more than once */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 /* -------------------------------------------------------------
479 Return without doing anything. Someone might still be using
480 the channel.
481 ---------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700482 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return;
484 } /* End channel is open more than once */
485
486 /* Port open only once go ahead with shutdown & reset */
Eric Sesterhenn56ee4822006-03-26 18:17:21 +0200487 BUG_ON(ch->count < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 /* ---------------------------------------------------------------
490 Let the rest of the driver know the channel is being closed.
491 This becomes important if an open is attempted before close
492 is finished.
493 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 ch->asyncflags |= ASYNC_CLOSING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 tty->closing = 1;
496
Alan Coxf2cf8e22005-09-06 15:16:44 -0700497 spin_unlock_irqrestore(&epca_lock, flags);
498
499 if (ch->asyncflags & ASYNC_INITIALIZED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* Setup an event to indicate when the transmit buffer empties */
501 setup_empty_event(tty, ch);
502 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (tty->driver->flush_buffer)
505 tty->driver->flush_buffer(tty);
506
507 tty_ldisc_flush(tty);
508 shutdown(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700509
510 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 tty->closing = 0;
512 ch->event = 0;
513 ch->tty = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700514 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Alan Coxf2cf8e22005-09-06 15:16:44 -0700516 if (ch->blocked_open) { /* Begin if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (ch->close_delay)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 } /* End if blocked_open */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
522 ASYNC_CLOSING);
523 wake_up_interruptible(&ch->close_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 } /* End if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525} /* End pc_close */
526
527/* ------------------ Begin shutdown ------------------------- */
528
529static void shutdown(struct channel *ch)
530{ /* Begin shutdown */
531
532 unsigned long flags;
533 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +0100534 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 if (!(ch->asyncflags & ASYNC_INITIALIZED))
537 return;
538
Alan Coxf2cf8e22005-09-06 15:16:44 -0700539 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Alan Coxf2cf8e22005-09-06 15:16:44 -0700541 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 bc = ch->brdchan;
543
544 /* ------------------------------------------------------------------
545 In order for an event to be generated on the receipt of data the
546 idata flag must be set. Since we are shutting down, this is not
547 necessary clear this flag.
548 --------------------------------------------------------------------- */
549
550 if (bc)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700551 writeb(0, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 tty = ch->tty;
553
554 /* ----------------------------------------------------------------
555 If we're a modem control device and HUPCL is on, drop RTS & DTR.
556 ------------------------------------------------------------------ */
557
Alan Coxf2cf8e22005-09-06 15:16:44 -0700558 if (tty->termios->c_cflag & HUPCL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
560 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 memoff(ch);
563
564 /* ------------------------------------------------------------------
565 The channel has officialy been closed. The next time it is opened
566 it will have to reinitialized. Set a flag to indicate this.
567 ---------------------------------------------------------------------- */
568
569 /* Prevent future Digi programmed interrupts from coming active */
570
571 ch->asyncflags &= ~ASYNC_INITIALIZED;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700572 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574} /* End shutdown */
575
576/* ------------------ Begin pc_hangup ------------------------- */
577
578static void pc_hangup(struct tty_struct *tty)
579{ /* Begin pc_hangup */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 struct channel *ch;
581
582 /* ---------------------------------------------------------
583 verifyChannel returns the channel from the tty struct
584 if it is valid. This serves as a sanity check.
585 ------------------------------------------------------------- */
586
Alan Coxf2cf8e22005-09-06 15:16:44 -0700587 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 unsigned long flags;
589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (tty->driver->flush_buffer)
591 tty->driver->flush_buffer(tty);
592 tty_ldisc_flush(tty);
593 shutdown(ch);
594
Alan Coxf2cf8e22005-09-06 15:16:44 -0700595 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 ch->tty = NULL;
597 ch->event = 0;
598 ch->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700600 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 wake_up_interruptible(&ch->open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 } /* End if ch != NULL */
603
604} /* End pc_hangup */
605
606/* ------------------ Begin pc_write ------------------------- */
607
608static int pc_write(struct tty_struct * tty,
609 const unsigned char *buf, int bytesAvailable)
610{ /* Begin pc_write */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700611 unsigned int head, tail;
612 int dataLen;
613 int size;
614 int amountCopied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 struct channel *ch;
616 unsigned long flags;
617 int remain;
Al Virobc9a5152005-09-15 22:53:28 +0100618 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 /* ----------------------------------------------------------------
621 pc_write is primarily called directly by the kernel routine
622 tty_write (Though it can also be called by put_char) found in
623 tty_io.c. pc_write is passed a line discipline buffer where
624 the data to be written out is stored. The line discipline
625 implementation itself is done at the kernel level and is not
626 brought into the driver.
627 ------------------------------------------------------------------- */
628
629 /* ---------------------------------------------------------
630 verifyChannel returns the channel from the tty struct
631 if it is valid. This serves as a sanity check.
632 ------------------------------------------------------------- */
633
634 if ((ch = verifyChannel(tty)) == NULL)
635 return 0;
636
637 /* Make a pointer to the channel data structure found on the board. */
638
639 bc = ch->brdchan;
640 size = ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 amountCopied = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Alan Coxf2cf8e22005-09-06 15:16:44 -0700643 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 globalwinon(ch);
645
Alan Coxf2cf8e22005-09-06 15:16:44 -0700646 head = readw(&bc->tin) & (size - 1);
647 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Alan Coxf2cf8e22005-09-06 15:16:44 -0700649 if (tail != readw(&bc->tout))
650 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 tail &= (size - 1);
652
653 /* If head >= tail, head has not wrapped around. */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700654 if (head >= tail) { /* Begin head has not wrapped */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 /* ---------------------------------------------------------------
656 remain (much like dataLen above) represents the total amount of
657 space available on the card for data. Here dataLen represents
658 the space existing between the head pointer and the end of
659 buffer. This is important because a memcpy cannot be told to
660 automatically wrap around when it hits the buffer end.
661 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 dataLen = size - head;
663 remain = size - (head - tail) - 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700664 } else { /* Begin head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 remain = tail - head - 1;
667 dataLen = remain;
668
669 } /* End head has wrapped around */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 /* -------------------------------------------------------------------
671 Check the space on the card. If we have more data than
672 space; reduce the amount of data to fit the space.
673 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 bytesAvailable = min(remain, bytesAvailable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 txwinon(ch);
676 while (bytesAvailable > 0)
677 { /* Begin while there is data to copy onto card */
678
679 /* -----------------------------------------------------------------
680 If head is not wrapped, the below will make sure the first
681 data copy fills to the end of card buffer.
682 ------------------------------------------------------------------- */
683
684 dataLen = min(bytesAvailable, dataLen);
Al Virobc9a5152005-09-15 22:53:28 +0100685 memcpy_toio(ch->txptr + head, buf, dataLen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 buf += dataLen;
687 head += dataLen;
688 amountCopied += dataLen;
689 bytesAvailable -= dataLen;
690
Alan Coxf2cf8e22005-09-06 15:16:44 -0700691 if (head >= size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 head = 0;
693 dataLen = tail;
694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 } /* End while there is data to copy onto card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 ch->statusflags |= TXBUSY;
697 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700698 writew(head, &bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Alan Coxf2cf8e22005-09-06 15:16:44 -0700700 if ((ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700702 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700705 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 return(amountCopied);
707
708} /* End pc_write */
709
710/* ------------------ Begin pc_put_char ------------------------- */
711
712static void pc_put_char(struct tty_struct *tty, unsigned char c)
713{ /* Begin pc_put_char */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 pc_write(tty, &c, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715} /* End pc_put_char */
716
717/* ------------------ Begin pc_write_room ------------------------- */
718
719static int pc_write_room(struct tty_struct *tty)
720{ /* Begin pc_write_room */
721
722 int remain;
723 struct channel *ch;
724 unsigned long flags;
725 unsigned int head, tail;
Al Virobc9a5152005-09-15 22:53:28 +0100726 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 remain = 0;
729
730 /* ---------------------------------------------------------
731 verifyChannel returns the channel from the tty struct
732 if it is valid. This serves as a sanity check.
733 ------------------------------------------------------------- */
734
Alan Coxf2cf8e22005-09-06 15:16:44 -0700735 if ((ch = verifyChannel(tty)) != NULL) {
736 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 globalwinon(ch);
738
739 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700740 head = readw(&bc->tin) & (ch->txbufsize - 1);
741 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Alan Coxf2cf8e22005-09-06 15:16:44 -0700743 if (tail != readw(&bc->tout))
744 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 /* Wrap tail if necessary */
746 tail &= (ch->txbufsize - 1);
747
748 if ((remain = tail - head - 1) < 0 )
749 remain += ch->txbufsize;
750
Alan Coxf2cf8e22005-09-06 15:16:44 -0700751 if (remain && (ch->statusflags & LOWWAIT) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 ch->statusflags |= LOWWAIT;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700753 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
755 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700756 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 /* Return how much room is left on card */
759 return remain;
760
761} /* End pc_write_room */
762
763/* ------------------ Begin pc_chars_in_buffer ---------------------- */
764
765static int pc_chars_in_buffer(struct tty_struct *tty)
766{ /* Begin pc_chars_in_buffer */
767
768 int chars;
769 unsigned int ctail, head, tail;
770 int remain;
771 unsigned long flags;
772 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100773 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 /* ---------------------------------------------------------
776 verifyChannel returns the channel from the tty struct
777 if it is valid. This serves as a sanity check.
778 ------------------------------------------------------------- */
779
780 if ((ch = verifyChannel(tty)) == NULL)
781 return(0);
782
Alan Coxf2cf8e22005-09-06 15:16:44 -0700783 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 globalwinon(ch);
785
786 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700787 tail = readw(&bc->tout);
788 head = readw(&bc->tin);
789 ctail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Alan Coxf2cf8e22005-09-06 15:16:44 -0700791 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 chars = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700793 else { /* Begin if some space on the card has been used */
794 head = readw(&bc->tin) & (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 tail &= (ch->txbufsize - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 /* --------------------------------------------------------------
797 The logic here is basically opposite of the above pc_write_room
798 here we are finding the amount of bytes in the buffer filled.
799 Not the amount of bytes empty.
800 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if ((remain = tail - head - 1) < 0 )
802 remain += ch->txbufsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 chars = (int)(ch->txbufsize - remain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 /* -------------------------------------------------------------
805 Make it possible to wakeup anything waiting for output
806 in tty_ioctl.c, etc.
807
808 If not already set. Setup an event to indicate when the
809 transmit buffer empties
810 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 if (!(ch->statusflags & EMPTYWAIT))
812 setup_empty_event(tty,ch);
813
814 } /* End if some space on the card has been used */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700816 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /* Return number of characters residing on card. */
818 return(chars);
819
820} /* End pc_chars_in_buffer */
821
822/* ------------------ Begin pc_flush_buffer ---------------------- */
823
824static void pc_flush_buffer(struct tty_struct *tty)
825{ /* Begin pc_flush_buffer */
826
827 unsigned int tail;
828 unsigned long flags;
829 struct channel *ch;
Al Virobc9a5152005-09-15 22:53:28 +0100830 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /* ---------------------------------------------------------
832 verifyChannel returns the channel from the tty struct
833 if it is valid. This serves as a sanity check.
834 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 if ((ch = verifyChannel(tty)) == NULL)
836 return;
837
Alan Coxf2cf8e22005-09-06 15:16:44 -0700838 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700841 tail = readw(&bc->tout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 /* Have FEP move tout pointer; effectively flushing transmit buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700845 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847} /* End pc_flush_buffer */
848
849/* ------------------ Begin pc_flush_chars ---------------------- */
850
851static void pc_flush_chars(struct tty_struct *tty)
852{ /* Begin pc_flush_chars */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 struct channel * ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 /* ---------------------------------------------------------
855 verifyChannel returns the channel from the tty struct
856 if it is valid. This serves as a sanity check.
857 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700858 if ((ch = verifyChannel(tty)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700860 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 /* ----------------------------------------------------------------
862 If not already set and the transmitter is busy setup an event
863 to indicate when the transmit empties.
864 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
866 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -0700867 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869} /* End pc_flush_chars */
870
871/* ------------------ Begin block_til_ready ---------------------- */
872
873static int block_til_ready(struct tty_struct *tty,
874 struct file *filp, struct channel *ch)
875{ /* Begin block_til_ready */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 DECLARE_WAITQUEUE(wait,current);
877 int retval, do_clocal = 0;
878 unsigned long flags;
879
Alan Coxf2cf8e22005-09-06 15:16:44 -0700880 if (tty_hung_up_p(filp)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
882 retval = -EAGAIN;
883 else
884 retval = -ERESTARTSYS;
885 return(retval);
886 }
887
888 /* -----------------------------------------------------------------
889 If the device is in the middle of being closed, then block
890 until it's done, and then try again.
891 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -0700892 if (ch->asyncflags & ASYNC_CLOSING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 interruptible_sleep_on(&ch->close_wait);
894
895 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
896 return -EAGAIN;
897 else
898 return -ERESTARTSYS;
899 }
900
Alan Coxf2cf8e22005-09-06 15:16:44 -0700901 if (filp->f_flags & O_NONBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 /* -----------------------------------------------------------------
903 If non-blocking mode is set, then make the check up front
904 and then exit.
905 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 return 0;
908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 if (tty->termios->c_cflag & CLOCAL)
910 do_clocal = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700911 /* Block waiting for the carrier detect and the line to become free */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 retval = 0;
914 add_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Alan Coxf2cf8e22005-09-06 15:16:44 -0700916 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 /* We dec count so that pc_close will know when to free things */
918 if (!tty_hung_up_p(filp))
919 ch->count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 ch->blocked_open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 while(1)
922 { /* Begin forever while */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 if (tty_hung_up_p(filp) ||
925 !(ch->asyncflags & ASYNC_INITIALIZED))
926 {
927 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
928 retval = -EAGAIN;
929 else
930 retval = -ERESTARTSYS;
931 break;
932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 if (!(ch->asyncflags & ASYNC_CLOSING) &&
934 (do_clocal || (ch->imodem & ch->dcd)))
935 break;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700936 if (signal_pending(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 retval = -ERESTARTSYS;
938 break;
939 }
Alan Coxf2cf8e22005-09-06 15:16:44 -0700940 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 /* ---------------------------------------------------------------
942 Allow someone else to be scheduled. We will occasionally go
943 through this loop until one of the above conditions change.
944 The below schedule call will allow other processes to enter and
945 prevent this loop from hogging the cpu.
946 ------------------------------------------------------------------ */
947 schedule();
Alan Coxf2cf8e22005-09-06 15:16:44 -0700948 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 } /* End forever while */
951
Milind Arun Choudharycc0a8fb2007-05-08 00:30:52 -0700952 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 remove_wait_queue(&ch->open_wait, &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (!tty_hung_up_p(filp))
955 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 ch->blocked_open--;
957
Alan Coxf2cf8e22005-09-06 15:16:44 -0700958 spin_unlock_irqrestore(&epca_lock, flags);
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (retval)
961 return retval;
962
963 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965} /* End block_til_ready */
966
967/* ------------------ Begin pc_open ---------------------- */
968
969static int pc_open(struct tty_struct *tty, struct file * filp)
970{ /* Begin pc_open */
971
972 struct channel *ch;
973 unsigned long flags;
974 int line, retval, boardnum;
Al Virobc9a5152005-09-15 22:53:28 +0100975 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700976 unsigned int head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 line = tty->index;
Alan Coxf2cf8e22005-09-06 15:16:44 -0700979 if (line < 0 || line >= nbdevs)
980 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
982 ch = &digi_channels[line];
983 boardnum = ch->boardnum;
984
985 /* Check status of board configured in system. */
986
987 /* -----------------------------------------------------------------
988 I check to see if the epca_setup routine detected an user error.
989 It might be better to put this in pc_init, but for the moment it
990 goes here.
991 ---------------------------------------------------------------------- */
992
Alan Coxf2cf8e22005-09-06 15:16:44 -0700993 if (invalid_lilo_config) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 if (setup_error_code & INVALID_BOARD_TYPE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700995 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (setup_error_code & INVALID_NUM_PORTS)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700997 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 if (setup_error_code & INVALID_MEM_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -0700999 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (setup_error_code & INVALID_PORT_BASE)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001001 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (setup_error_code & INVALID_BOARD_STATUS)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001003 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 if (setup_error_code & INVALID_ALTPIN)
Alan Coxf2cf8e22005-09-06 15:16:44 -07001005 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 tty->driver_data = NULL; /* Mark this device as 'down' */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001007 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001009 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 tty->driver_data = NULL; /* Mark this device as 'down' */
1011 return(-ENODEV);
1012 }
1013
Alan Coxf2cf8e22005-09-06 15:16:44 -07001014 if ((bc = ch->brdchan) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 tty->driver_data = NULL;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001016 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018
Alan Coxf2cf8e22005-09-06 15:16:44 -07001019 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 /* ------------------------------------------------------------------
1021 Every time a channel is opened, increment a counter. This is
1022 necessary because we do not wish to flush and shutdown the channel
1023 until the last app holding the channel open, closes it.
1024 --------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 ch->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 /* ----------------------------------------------------------------
1027 Set a kernel structures pointer to our local channel
1028 structure. This way we can get to it when passed only
1029 a tty struct.
1030 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 tty->driver_data = ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 /* ----------------------------------------------------------------
1033 If this is the first time the channel has been opened, initialize
1034 the tty->termios struct otherwise let pc_close handle it.
1035 -------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 globalwinon(ch);
1037 ch->statusflags = 0;
1038
1039 /* Save boards current modem status */
Al Virobc9a5152005-09-15 22:53:28 +01001040 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
1042 /* ----------------------------------------------------------------
1043 Set receive head and tail ptrs to each other. This indicates
1044 no data available to read.
1045 ----------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001046 head = readw(&bc->rin);
1047 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
1049 /* Set the channels associated tty structure */
1050 ch->tty = tty;
1051
1052 /* -----------------------------------------------------------------
1053 The below routine generally sets up parity, baud, flow control
1054 issues, etc.... It effect both control flags and input flags.
1055 -------------------------------------------------------------------- */
1056 epcaparam(tty,ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 ch->asyncflags |= ASYNC_INITIALIZED;
1058 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001059 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061 retval = block_til_ready(tty, filp, ch);
1062 if (retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 /* -------------------------------------------------------------
1065 Set this again in case a hangup set it to zero while this
1066 open() was waiting for the line...
1067 --------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001068 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 ch->tty = tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 /* Enable Digi Data events */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001072 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001074 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076} /* End pc_open */
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078static int __init epca_module_init(void)
1079{ /* Begin init_module */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001080 return pc_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
1083module_init(epca_module_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085static struct pci_driver epca_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087static void __exit epca_module_exit(void)
1088{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 int count, crd;
1090 struct board_info *bd;
1091 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 del_timer_sync(&epca_timer);
1094
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 if ((tty_unregister_driver(pc_driver)) ||
1096 (tty_unregister_driver(pc_info)))
1097 {
Alan Coxf2cf8e22005-09-06 15:16:44 -07001098 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 return;
1100 }
1101 put_tty_driver(pc_driver);
1102 put_tty_driver(pc_info);
1103
Alan Coxf2cf8e22005-09-06 15:16:44 -07001104 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 bd = &boards[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 if (!bd)
1107 { /* Begin sanity check */
1108 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1109 return;
1110 } /* End sanity check */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001111 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 for (count = 0; count < bd->numports; count++, ch++)
1113 { /* Begin for each port */
Jiri Slabyb3218a72006-10-04 02:15:27 -07001114 if (ch && ch->tty)
1115 tty_hangup(ch->tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 } /* End for each port */
1117 } /* End for each card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 pci_unregister_driver (&epca_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119}
Alan Coxf2cf8e22005-09-06 15:16:44 -07001120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121module_exit(epca_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Jeff Dikeb68e31d2006-10-02 02:17:18 -07001123static const struct tty_operations pc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 .open = pc_open,
1125 .close = pc_close,
1126 .write = pc_write,
1127 .write_room = pc_write_room,
1128 .flush_buffer = pc_flush_buffer,
1129 .chars_in_buffer = pc_chars_in_buffer,
1130 .flush_chars = pc_flush_chars,
1131 .put_char = pc_put_char,
1132 .ioctl = pc_ioctl,
1133 .set_termios = pc_set_termios,
1134 .stop = pc_stop,
1135 .start = pc_start,
1136 .throttle = pc_throttle,
1137 .unthrottle = pc_unthrottle,
1138 .hangup = pc_hangup,
1139};
1140
1141static int info_open(struct tty_struct *tty, struct file * filp)
1142{
1143 return 0;
1144}
1145
1146static struct tty_operations info_ops = {
1147 .open = info_open,
1148 .ioctl = info_ioctl,
1149};
1150
1151/* ------------------ Begin pc_init ---------------------- */
1152
Alan Coxf2cf8e22005-09-06 15:16:44 -07001153static int __init pc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{ /* Begin pc_init */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 int crd;
1156 struct board_info *bd;
1157 unsigned char board_id = 0;
Akinobu Mitadabad052006-10-17 00:10:28 -07001158 int err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 int pci_boards_found, pci_count;
1161
1162 pci_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 pc_driver = alloc_tty_driver(MAX_ALLOC);
1165 if (!pc_driver)
Akinobu Mitadabad052006-10-17 00:10:28 -07001166 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 pc_info = alloc_tty_driver(MAX_ALLOC);
Akinobu Mitadabad052006-10-17 00:10:28 -07001169 if (!pc_info)
1170 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 /* -----------------------------------------------------------------------
1173 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1174 board structure defined by digiConfig into drivers board structure.
1175 Note : If LILO has ran epca_setup then epca_setup will handle defining
1176 num_cards as well as copying the data into the board structure.
1177 -------------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001178 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180 nbdevs = NBDEVS;
1181 num_cards = NUMCARDS;
1182 memcpy((void *)&boards, (void *)&static_boards,
1183 (sizeof(struct board_info) * NUMCARDS));
1184 } /* End driver has been configured via. epcaconfig */
1185
1186 /* -----------------------------------------------------------------
1187 Note : If lilo was used to configure the driver and the
1188 ignore epcaconfig option was choosen (digiepca=2) then
1189 nbdevs and num_cards will equal 0 at this point. This is
1190 okay; PCI cards will still be picked up if detected.
1191 --------------------------------------------------------------------- */
1192
1193 /* -----------------------------------------------------------
1194 Set up interrupt, we will worry about memory allocation in
1195 post_fep_init.
1196 --------------------------------------------------------------- */
1197
1198
1199 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 /* ------------------------------------------------------------------
1202 NOTE : This code assumes that the number of ports found in
1203 the boards array is correct. This could be wrong if
1204 the card in question is PCI (And therefore has no ports
1205 entry in the boards structure.) The rest of the
1206 information will be valid for PCI because the beginning
1207 of pc_init scans for PCI and determines i/o and base
1208 memory addresses. I am not sure if it is possible to
1209 read the number of ports supported by the card prior to
1210 it being booted (Since that is the state it is in when
1211 pc_init is run). Because it is not possible to query the
1212 number of supported ports until after the card has booted;
1213 we are required to calculate the card_ptrs as the card is
1214 is initialized (Inside post_fep_init). The negative thing
1215 about this approach is that digiDload's call to GET_INFO
1216 will have a bad port value. (Since this is called prior
1217 to post_fep_init.)
1218
1219 --------------------------------------------------------------------- */
1220
1221 pci_boards_found = 0;
1222 if(num_cards < MAXBOARDS)
1223 pci_boards_found += init_PCI();
1224 num_cards += pci_boards_found;
1225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 pc_driver->owner = THIS_MODULE;
1227 pc_driver->name = "ttyD";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 pc_driver->major = DIGI_MAJOR;
1229 pc_driver->minor_start = 0;
1230 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1231 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1232 pc_driver->init_termios = tty_std_termios;
1233 pc_driver->init_termios.c_iflag = 0;
1234 pc_driver->init_termios.c_oflag = 0;
1235 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1236 pc_driver->init_termios.c_lflag = 0;
Alan Cox606d0992006-12-08 02:38:45 -08001237 pc_driver->init_termios.c_ispeed = 9600;
1238 pc_driver->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1240 tty_set_operations(pc_driver, &pc_ops);
1241
1242 pc_info->owner = THIS_MODULE;
1243 pc_info->name = "digi_ctl";
1244 pc_info->major = DIGIINFOMAJOR;
1245 pc_info->minor_start = 0;
1246 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1247 pc_info->subtype = SERIAL_TYPE_INFO;
1248 pc_info->init_termios = tty_std_termios;
1249 pc_info->init_termios.c_iflag = 0;
1250 pc_info->init_termios.c_oflag = 0;
1251 pc_info->init_termios.c_lflag = 0;
1252 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
Alan Cox606d0992006-12-08 02:38:45 -08001253 pc_info->init_termios.c_ispeed = 9600;
1254 pc_info->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 pc_info->flags = TTY_DRIVER_REAL_RAW;
1256 tty_set_operations(pc_info, &info_ops);
1257
1258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 for (crd = 0; crd < num_cards; crd++)
1260 { /* Begin for each card */
1261
1262 /* ------------------------------------------------------------------
1263 This is where the appropriate memory handlers for the hardware is
1264 set. Everything at runtime blindly jumps through these vectors.
1265 ---------------------------------------------------------------------- */
1266
1267 /* defined in epcaconfig.h */
1268 bd = &boards[crd];
1269
1270 switch (bd->type)
1271 { /* Begin switch on bd->type {board type} */
1272 case PCXEM:
1273 case EISAXEM:
1274 bd->memwinon = pcxem_memwinon ;
1275 bd->memwinoff = pcxem_memwinoff ;
1276 bd->globalwinon = pcxem_globalwinon ;
1277 bd->txwinon = pcxem_txwinon ;
1278 bd->rxwinon = pcxem_rxwinon ;
1279 bd->memoff = pcxem_memoff ;
1280 bd->assertgwinon = dummy_assertgwinon;
1281 bd->assertmemoff = dummy_assertmemoff;
1282 break;
1283
1284 case PCIXEM:
1285 case PCIXRJ:
1286 case PCIXR:
1287 bd->memwinon = dummy_memwinon;
1288 bd->memwinoff = dummy_memwinoff;
1289 bd->globalwinon = dummy_globalwinon;
1290 bd->txwinon = dummy_txwinon;
1291 bd->rxwinon = dummy_rxwinon;
1292 bd->memoff = dummy_memoff;
1293 bd->assertgwinon = dummy_assertgwinon;
1294 bd->assertmemoff = dummy_assertmemoff;
1295 break;
1296
1297 case PCXE:
1298 case PCXEVE:
1299
1300 bd->memwinon = pcxe_memwinon;
1301 bd->memwinoff = pcxe_memwinoff;
1302 bd->globalwinon = pcxe_globalwinon;
1303 bd->txwinon = pcxe_txwinon;
1304 bd->rxwinon = pcxe_rxwinon;
1305 bd->memoff = pcxe_memoff;
1306 bd->assertgwinon = dummy_assertgwinon;
1307 bd->assertmemoff = dummy_assertmemoff;
1308 break;
1309
1310 case PCXI:
1311 case PC64XE:
1312
1313 bd->memwinon = pcxi_memwinon;
1314 bd->memwinoff = pcxi_memwinoff;
1315 bd->globalwinon = pcxi_globalwinon;
1316 bd->txwinon = pcxi_txwinon;
1317 bd->rxwinon = pcxi_rxwinon;
1318 bd->memoff = pcxi_memoff;
1319 bd->assertgwinon = pcxi_assertgwinon;
1320 bd->assertmemoff = pcxi_assertmemoff;
1321 break;
1322
1323 default:
1324 break;
1325
1326 } /* End switch on bd->type */
1327
1328 /* ---------------------------------------------------------------
1329 Some cards need a memory segment to be defined for use in
1330 transmit and receive windowing operations. These boards
1331 are listed in the below switch. In the case of the XI the
1332 amount of memory on the board is variable so the memory_seg
1333 is also variable. This code determines what they segment
1334 should be.
1335 ----------------------------------------------------------------- */
1336
1337 switch (bd->type)
1338 { /* Begin switch on bd->type {board type} */
1339
1340 case PCXE:
1341 case PCXEVE:
1342 case PC64XE:
1343 bd->memory_seg = 0xf000;
1344 break;
1345
1346 case PCXI:
1347 board_id = inb((int)bd->port);
1348 if ((board_id & 0x1) == 0x1)
1349 { /* Begin it's an XI card */
1350
1351 /* Is it a 64K board */
1352 if ((board_id & 0x30) == 0)
1353 bd->memory_seg = 0xf000;
1354
1355 /* Is it a 128K board */
1356 if ((board_id & 0x30) == 0x10)
1357 bd->memory_seg = 0xe000;
1358
1359 /* Is is a 256K board */
1360 if ((board_id & 0x30) == 0x20)
1361 bd->memory_seg = 0xc000;
1362
1363 /* Is it a 512K board */
1364 if ((board_id & 0x30) == 0x30)
1365 bd->memory_seg = 0x8000;
1366
Alan Coxf2cf8e22005-09-06 15:16:44 -07001367 } 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 -07001368 break;
1369
1370 } /* End switch on bd->type */
1371
1372 } /* End for each card */
1373
Akinobu Mitadabad052006-10-17 00:10:28 -07001374 err = tty_register_driver(pc_driver);
1375 if (err) {
1376 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1377 goto out3;
1378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Akinobu Mitadabad052006-10-17 00:10:28 -07001380 err = tty_register_driver(pc_info);
1381 if (err) {
1382 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1383 goto out4;
1384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 /* -------------------------------------------------------------------
1387 Start up the poller to check for events on all enabled boards
1388 ---------------------------------------------------------------------- */
1389
1390 init_timer(&epca_timer);
1391 epca_timer.function = epcapoll;
1392 mod_timer(&epca_timer, jiffies + HZ/25);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 return 0;
1394
Akinobu Mitadabad052006-10-17 00:10:28 -07001395out4:
1396 tty_unregister_driver(pc_driver);
1397out3:
1398 put_tty_driver(pc_info);
1399out2:
1400 put_tty_driver(pc_driver);
1401out1:
1402 return err;
1403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404} /* End pc_init */
1405
1406/* ------------------ Begin post_fep_init ---------------------- */
1407
1408static void post_fep_init(unsigned int crd)
1409{ /* Begin post_fep_init */
1410
1411 int i;
Al Virobc9a5152005-09-15 22:53:28 +01001412 void __iomem *memaddr;
1413 struct global_data __iomem *gd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 struct board_info *bd;
Al Virobc9a5152005-09-15 22:53:28 +01001415 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 struct channel *ch;
1417 int shrinkmem = 0, lowwater ;
1418
1419 /* -------------------------------------------------------------
1420 This call is made by the user via. the ioctl call DIGI_INIT.
1421 It is responsible for setting up all the card specific stuff.
1422 ---------------------------------------------------------------- */
1423 bd = &boards[crd];
1424
1425 /* -----------------------------------------------------------------
1426 If this is a PCI board, get the port info. Remember PCI cards
1427 do not have entries into the epcaconfig.h file, so we can't get
1428 the number of ports from it. Unfortunetly, this means that anyone
1429 doing a DIGI_GETINFO before the board has booted will get an invalid
1430 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1431 after DIGI_INIT has been called will return the proper values.
1432 ------------------------------------------------------------------- */
1433
Alan Coxf2cf8e22005-09-06 15:16:44 -07001434 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 /* --------------------------------------------------------------------
1436 Below we use XEMPORTS as a memory offset regardless of which PCI
1437 card it is. This is because all of the supported PCI cards have
1438 the same memory offset for the channel data. This will have to be
1439 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1440 states that the port offset is 0xC22 as opposed to 0xC02. This is
1441 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1442 On the PCI cards the number of ports is determined by reading a
1443 ID PROM located in the box attached to the card. The card can then
1444 determine the index the id to determine the number of ports available.
1445 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1446 if the box in question is a XEM or CX)).
1447 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001448 /* PCI cards are already remapped at this point ISA are not */
1449 bd->numports = readw(bd->re_map_membase + XEMPORTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1451 nbdevs += (bd->numports);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001452 } else {
1453 /* Fix up the mappings for ISA/EISA etc */
1454 /* FIXME: 64K - can we be smarter ? */
1455 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 if (crd != 0)
1459 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1460 else
1461 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1462
1463 ch = card_ptr[crd];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1465
Alan Coxf2cf8e22005-09-06 15:16:44 -07001466 memaddr = bd->re_map_membase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 /* -----------------------------------------------------------------
1469 The below assignment will set bc to point at the BEGINING of
1470 the cards channel structures. For 1 card there will be between
1471 8 and 64 of these structures.
1472 -------------------------------------------------------------------- */
1473
Al Virobc9a5152005-09-15 22:53:28 +01001474 bc = memaddr + CHANSTRUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 /* -------------------------------------------------------------------
1477 The below assignment will set gd to point at the BEGINING of
1478 global memory address 0xc00. The first data in that global
1479 memory actually starts at address 0xc1a. The command in
1480 pointer begins at 0xd10.
1481 ---------------------------------------------------------------------- */
1482
Al Virobc9a5152005-09-15 22:53:28 +01001483 gd = memaddr + GLOBAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 /* --------------------------------------------------------------------
1486 XEPORTS (address 0xc22) points at the number of channels the
1487 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1488 ----------------------------------------------------------------------- */
1489
Alan Coxf2cf8e22005-09-06 15:16:44 -07001490 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 shrinkmem = 1;
1492 if (bd->type < PCIXEM)
1493 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1494 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 memwinon(bd, 0);
1496
1497 /* --------------------------------------------------------------------
1498 Remember ch is the main drivers channels structure, while bc is
1499 the cards channel structure.
1500 ------------------------------------------------------------------------ */
1501
1502 /* For every port on the card do ..... */
1503
Alan Coxf2cf8e22005-09-06 15:16:44 -07001504 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1505 unsigned long flags;
Al Virobc9a5152005-09-15 22:53:28 +01001506 u16 tseg, rseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 ch->brdchan = bc;
1509 ch->mailbox = gd;
David Howellsc4028952006-11-22 14:57:56 +00001510 INIT_WORK(&ch->tqueue, do_softint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 ch->board = &boards[crd];
1512
Alan Coxf2cf8e22005-09-06 15:16:44 -07001513 spin_lock_irqsave(&epca_lock, flags);
1514 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 /* ----------------------------------------------------------------
1516 Since some of the boards use different bitmaps for their
1517 control signals we cannot hard code these values and retain
1518 portability. We virtualize this data here.
1519 ------------------------------------------------------------------- */
1520 case EISAXEM:
1521 case PCXEM:
1522 case PCIXEM:
1523 case PCIXRJ:
1524 case PCIXR:
1525 ch->m_rts = 0x02 ;
1526 ch->m_dcd = 0x80 ;
1527 ch->m_dsr = 0x20 ;
1528 ch->m_cts = 0x10 ;
1529 ch->m_ri = 0x40 ;
1530 ch->m_dtr = 0x01 ;
1531 break;
1532
1533 case PCXE:
1534 case PCXEVE:
1535 case PCXI:
1536 case PC64XE:
1537 ch->m_rts = 0x02 ;
1538 ch->m_dcd = 0x08 ;
1539 ch->m_dsr = 0x10 ;
1540 ch->m_cts = 0x20 ;
1541 ch->m_ri = 0x40 ;
1542 ch->m_dtr = 0x80 ;
1543 break;
1544
1545 } /* End switch bd->type */
1546
Alan Coxf2cf8e22005-09-06 15:16:44 -07001547 if (boards[crd].altpin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 ch->dsr = ch->m_dcd;
1549 ch->dcd = ch->m_dsr;
1550 ch->digiext.digi_flags |= DIGI_ALTPIN;
1551 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001552 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 ch->dcd = ch->m_dcd;
1554 ch->dsr = ch->m_dsr;
1555 }
1556
1557 ch->boardnum = crd;
1558 ch->channelnum = i;
1559 ch->magic = EPCA_MAGIC;
1560 ch->tty = NULL;
1561
Alan Coxf2cf8e22005-09-06 15:16:44 -07001562 if (shrinkmem) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1564 shrinkmem = 0;
1565 }
1566
Al Virobc9a5152005-09-15 22:53:28 +01001567 tseg = readw(&bc->tseg);
1568 rseg = readw(&bc->rseg);
1569
Alan Coxf2cf8e22005-09-06 15:16:44 -07001570 switch (bd->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572 case PCIXEM:
1573 case PCIXRJ:
1574 case PCIXR:
1575 /* Cover all the 2MEG cards */
Al Virobc9a5152005-09-15 22:53:28 +01001576 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1577 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1578 ch->txwin = FEPWIN | (tseg >> 11);
1579 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 break;
1581
1582 case PCXEM:
1583 case EISAXEM:
1584 /* Cover all the 32K windowed cards */
1585 /* Mask equal to window size - 1 */
Al Virobc9a5152005-09-15 22:53:28 +01001586 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1587 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1588 ch->txwin = FEPWIN | (tseg >> 11);
1589 ch->rxwin = FEPWIN | (rseg >> 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 break;
1591
1592 case PCXEVE:
1593 case PCXE:
Al Virobc9a5152005-09-15 22:53:28 +01001594 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1595 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1596 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1597 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 break;
1599
1600 case PCXI:
1601 case PC64XE:
Al Virobc9a5152005-09-15 22:53:28 +01001602 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1603 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 ch->txwin = ch->rxwin = 0;
1605 break;
1606
1607 } /* End switch bd->type */
1608
1609 ch->txbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001610 ch->txbufsize = readw(&bc->tmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 ch->rxbufhead = 0;
Al Virobc9a5152005-09-15 22:53:28 +01001613 ch->rxbufsize = readw(&bc->rmax) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1616
1617 /* Set transmitter low water mark */
1618 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1619
1620 /* Set receiver low water mark */
1621
1622 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1623
1624 /* Set receiver high water mark */
1625
1626 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1627
Alan Coxf2cf8e22005-09-06 15:16:44 -07001628 writew(100, &bc->edelay);
1629 writeb(1, &bc->idata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Alan Coxf2cf8e22005-09-06 15:16:44 -07001631 ch->startc = readb(&bc->startc);
1632 ch->stopc = readb(&bc->stopc);
1633 ch->startca = readb(&bc->startca);
1634 ch->stopca = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635
1636 ch->fepcflag = 0;
1637 ch->fepiflag = 0;
1638 ch->fepoflag = 0;
1639 ch->fepstartc = 0;
1640 ch->fepstopc = 0;
1641 ch->fepstartca = 0;
1642 ch->fepstopca = 0;
1643
1644 ch->close_delay = 50;
1645 ch->count = 0;
1646 ch->blocked_open = 0;
1647 init_waitqueue_head(&ch->open_wait);
1648 init_waitqueue_head(&ch->close_wait);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001649
1650 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 } /* 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 } /* End if LOWWAIT */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001797 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 /* This event is generated by setup_empty_event */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 ch->statusflags &= ~TXBUSY;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001800 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 ch->statusflags &= ~EMPTYWAIT;
1802 tty_wakeup(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 } /* End if EMPTYWAIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 } /* End EMPTYTX_IND */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 } /* End if valid tty */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 next:
1807 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001808 BUG_ON(!bc);
1809 writew(1, &bc->idata);
1810 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 globalwinon(chan0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 } /* End while something in event queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813} /* End doevent */
1814
1815/* --------------------- Begin fepcmd ------------------------ */
1816
1817static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1818 int byte2, int ncmds, int bytecmd)
1819{ /* Begin fepcmd */
Al Virobc9a5152005-09-15 22:53:28 +01001820 unchar __iomem *memaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 unsigned int head, cmdTail, cmdStart, cmdMax;
1822 long count;
1823 int n;
1824
1825 /* This is the routine in which commands may be passed to the card. */
1826
1827 if (ch->board->status == DISABLED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 /* Remember head (As well as max) is just an offset not a base addr */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001831 head = readw(&ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 /* cmdStart is a base address */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001833 cmdStart = readw(&ch->mailbox->cstart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 /* ------------------------------------------------------------------
1835 We do the addition below because we do not want a max pointer
1836 relative to cmdStart. We want a max pointer that points at the
1837 physical end of the command queue.
1838 -------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001839 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 memaddr = ch->board->re_map_membase;
1841
Alan Coxf2cf8e22005-09-06 15:16:44 -07001842 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1843 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1844 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 return;
1846 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001847 if (bytecmd) {
1848 writeb(cmd, memaddr + head + cmdStart + 0);
1849 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 /* Below word_or_byte is bits to set */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001851 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 /* Below byte2 is bits to reset */
Alan Coxf2cf8e22005-09-06 15:16:44 -07001853 writeb(byte2, memaddr + head + cmdStart + 3);
1854 } else {
1855 writeb(cmd, memaddr + head + cmdStart + 0);
1856 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1857 writeb(word_or_byte, memaddr + head + cmdStart + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 head = (head + 4) & (cmdMax - cmdStart - 4);
Alan Coxf2cf8e22005-09-06 15:16:44 -07001860 writew(head, &ch->mailbox->cin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 count = FEPTIMEOUT;
1862
Alan Coxf2cf8e22005-09-06 15:16:44 -07001863 for (;;) { /* Begin forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 count--;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001865 if (count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1867 return;
1868 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07001869 head = readw(&ch->mailbox->cin);
1870 cmdTail = readw(&ch->mailbox->cout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 /* ----------------------------------------------------------
1873 Basically this will break when the FEP acknowledges the
1874 command by incrementing cmdTail (Making it equal to head).
1875 ------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 if (n <= ncmds * (sizeof(short) * 4))
1877 break; /* Well nearly forever :-) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 } /* End forever loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879} /* End fepcmd */
1880
1881/* ---------------------------------------------------------------------
1882 Digi products use fields in their channels structures that are very
1883 similar to the c_cflag and c_iflag fields typically found in UNIX
1884 termios structures. The below three routines allow mappings
1885 between these hardware "flags" and their respective Linux flags.
1886------------------------------------------------------------------------- */
1887
1888/* --------------------- Begin termios2digi_h -------------------- */
1889
1890static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1891{ /* Begin termios2digi_h */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 unsigned res = 0;
1893
Alan Coxf2cf8e22005-09-06 15:16:44 -07001894 if (cflag & CRTSCTS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1896 res |= ((ch->m_cts) | (ch->m_rts));
1897 }
1898
1899 if (ch->digiext.digi_flags & RTSPACE)
1900 res |= ch->m_rts;
1901
1902 if (ch->digiext.digi_flags & DTRPACE)
1903 res |= ch->m_dtr;
1904
1905 if (ch->digiext.digi_flags & CTSPACE)
1906 res |= ch->m_cts;
1907
1908 if (ch->digiext.digi_flags & DSRPACE)
1909 res |= ch->dsr;
1910
1911 if (ch->digiext.digi_flags & DCDPACE)
1912 res |= ch->dcd;
1913
1914 if (res & (ch->m_rts))
1915 ch->digiext.digi_flags |= RTSPACE;
1916
1917 if (res & (ch->m_cts))
1918 ch->digiext.digi_flags |= CTSPACE;
1919
1920 return res;
1921
1922} /* End termios2digi_h */
1923
1924/* --------------------- Begin termios2digi_i -------------------- */
1925static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1926{ /* Begin termios2digi_i */
1927
1928 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1929 INPCK | ISTRIP|IXON|IXANY|IXOFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (ch->digiext.digi_flags & DIGI_AIXON)
1931 res |= IAIXON;
1932 return res;
1933
1934} /* End termios2digi_i */
1935
1936/* --------------------- Begin termios2digi_c -------------------- */
1937
1938static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1939{ /* Begin termios2digi_c */
1940
1941 unsigned res = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07001942 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 ch->digiext.digi_flags |= DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 /* -------------------------------------------------------------
1945 HUPCL bit is used by FEP to indicate fast baud
1946 table is to be used.
1947 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 res |= FEP_HUPCL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 } /* End detected CBAUDEX */
1950 else ch->digiext.digi_flags &= ~DIGI_FAST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 /* -------------------------------------------------------------------
1952 CBAUD has bit position 0x1000 set these days to indicate Linux
1953 baud rate remap. Digi hardware can't handle the bit assignment.
1954 (We use a different bit assignment for high speed.). Clear this
1955 bit out.
1956 ---------------------------------------------------------------------- */
1957 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 /* -------------------------------------------------------------
1959 This gets a little confusing. The Digi cards have their own
1960 representation of c_cflags controling baud rate. For the most
1961 part this is identical to the Linux implementation. However;
1962 Digi supports one rate (76800) that Linux doesn't. This means
1963 that the c_cflag entry that would normally mean 76800 for Digi
1964 actually means 115200 under Linux. Without the below mapping,
1965 a stty 115200 would only drive the board at 76800. Since
1966 the rate 230400 is also found after 76800, the same problem afflicts
1967 us when we choose a rate of 230400. Without the below modificiation
1968 stty 230400 would actually give us 115200.
1969
1970 There are two additional differences. The Linux value for CLOCAL
1971 (0x800; 0004000) has no meaning to the Digi hardware. Also in
1972 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
1973 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
1974 should be checked for a screened out prior to termios2digi_c
1975 returning. Since CLOCAL isn't used by the board this can be
1976 ignored as long as the returned value is used only by Digi hardware.
Alan Coxf2cf8e22005-09-06 15:16:44 -07001977 ----------------------------------------------------------------- */
1978 if (cflag & CBAUDEX) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 /* -------------------------------------------------------------
1980 The below code is trying to guarantee that only baud rates
1981 115200 and 230400 are remapped. We use exclusive or because
1982 the various baud rates share common bit positions and therefore
1983 can't be tested for easily.
1984 ----------------------------------------------------------------- */
1985
1986
1987 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1988 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 res += 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return res;
1992
1993} /* End termios2digi_c */
1994
1995/* --------------------- Begin epcaparam ----------------------- */
1996
Alan Coxf2cf8e22005-09-06 15:16:44 -07001997/* Caller must hold the locks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998static void epcaparam(struct tty_struct *tty, struct channel *ch)
1999{ /* Begin epcaparam */
2000
2001 unsigned int cmdHead;
Alan Cox606d0992006-12-08 02:38:45 -08002002 struct ktermios *ts;
Al Virobc9a5152005-09-15 22:53:28 +01002003 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 unsigned mval, hflow, cflag, iflag;
2005
2006 bc = ch->brdchan;
2007 epcaassert(bc !=0, "bc out of range");
2008
2009 assertgwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 ts = tty->termios;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002011 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2012 cmdHead = readw(&bc->rin);
Al Virobc9a5152005-09-15 22:53:28 +01002013 writew(cmdHead, &bc->rout);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002014 cmdHead = readw(&bc->tin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 /* Changing baud in mid-stream transmission can be wonderful */
2016 /* ---------------------------------------------------------------
2017 Flush current transmit buffer by setting cmdTail pointer (tout)
2018 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2019 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2021 mval = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002022 } else { /* Begin CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 /* -------------------------------------------------------------------
2024 c_cflags have changed but that change had nothing to do with BAUD.
2025 Propagate the change to the card.
2026 ---------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 cflag = termios2digi_c(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002028 if (cflag != ch->fepcflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 ch->fepcflag = cflag;
2030 /* Set baud rate, char size, stop bits, parity */
2031 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 /* ----------------------------------------------------------------
2034 If the user has not forced CLOCAL and if the device is not a
2035 CALLOUT device (Which is always CLOCAL) we set flags such that
2036 the driver will wait on carrier detect.
2037 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 if (ts->c_cflag & CLOCAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 ch->asyncflags &= ~ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 ch->asyncflags |= ASYNC_CHECK_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 mval = ch->m_dtr | ch->m_rts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 } /* End CBAUD not detected */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 iflag = termios2digi_i(ch, ts->c_iflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 /* Check input mode flags */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002046 if (iflag != ch->fepiflag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 ch->fepiflag = iflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 /* ---------------------------------------------------------------
2049 Command sets channels iflag structure on the board. Such things
2050 as input soft flow control, handling of parity errors, and
2051 break handling are all set here.
2052 ------------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 /* break handling, parity handling, input stripping, flow control chars */
2054 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 /* ---------------------------------------------------------------
2057 Set the board mint value for this channel. This will cause hardware
2058 events to be generated each time the DCD signal (Described in mint)
2059 changes.
2060 ------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002061 writeb(ch->dcd, &bc->mint);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2063 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002064 writeb(0, &bc->mint);
2065 ch->imodem = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 hflow = termios2digi_h(ch, ts->c_cflag);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002067 if (hflow != ch->hflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 ch->hflow = hflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 /* --------------------------------------------------------------
2070 Hard flow control has been selected but the board is not
2071 using it. Activate hard flow control now.
2072 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 mval ^= ch->modemfake & (mval ^ ch->modem);
2076
Alan Coxf2cf8e22005-09-06 15:16:44 -07002077 if (ch->omodem ^ mval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 ch->omodem = mval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 /* --------------------------------------------------------------
2080 The below command sets the DTR and RTS mstat structure. If
2081 hard flow control is NOT active these changes will drive the
2082 output of the actual DTR and RTS lines. If hard flow control
2083 is active, the changes will be saved in the mstat structure and
2084 only asserted when hard flow control is turned off.
2085 ----------------------------------------------------------------- */
2086
2087 /* First reset DTR & RTS; then set them */
2088 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2089 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002091 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 ch->fepstartc = ch->startc;
2093 ch->fepstopc = ch->stopc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 /* ------------------------------------------------------------
2095 The XON / XOFF characters have changed; propagate these
2096 changes to the card.
2097 --------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2099 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002100 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 ch->fepstartca = ch->startca;
2102 ch->fepstopca = ch->stopca;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 /* ---------------------------------------------------------------
2104 Similar to the above, this time the auxilarly XON / XOFF
2105 characters have changed; propagate these changes to the card.
2106 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2108 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109} /* End epcaparam */
2110
2111/* --------------------- Begin receive_data ----------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002112/* Caller holds lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113static void receive_data(struct channel *ch)
2114{ /* Begin receive_data */
2115
2116 unchar *rptr;
Alan Cox606d0992006-12-08 02:38:45 -08002117 struct ktermios *ts = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 struct tty_struct *tty;
Al Virobc9a5152005-09-15 22:53:28 +01002119 struct board_chan __iomem *bc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002120 int dataToRead, wrapgap, bytesAvailable;
2121 unsigned int tail, head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 unsigned int wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 /* ---------------------------------------------------------------
2125 This routine is called by doint when a receive data event
2126 has taken place.
2127 ------------------------------------------------------------------- */
2128
2129 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 if (ch->statusflags & RXSTOPPED)
2131 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 tty = ch->tty;
2133 if (tty)
2134 ts = tty->termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 bc = ch->brdchan;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002136 BUG_ON(!bc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 wrapmask = ch->rxbufsize - 1;
2138
2139 /* ---------------------------------------------------------------------
2140 Get the head and tail pointers to the receiver queue. Wrap the
2141 head pointer if it has reached the end of the buffer.
2142 ------------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002143 head = readw(&bc->rin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 head &= wrapmask;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002145 tail = readw(&bc->rout) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
2147 bytesAvailable = (head - tail) & wrapmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 if (bytesAvailable == 0)
2149 return;
2150
2151 /* ------------------------------------------------------------------
2152 If CREAD bit is off or device not open, set TX tail to head
2153 --------------------------------------------------------------------- */
2154
Alan Coxf2cf8e22005-09-06 15:16:44 -07002155 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
Al Virobc9a5152005-09-15 22:53:28 +01002156 writew(head, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 return;
2158 }
2159
Alan Cox33f0f882006-01-09 20:54:13 -08002160 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 return;
2162
Alan Coxf2cf8e22005-09-06 15:16:44 -07002163 if (readb(&bc->orun)) {
2164 writeb(0, &bc->orun);
2165 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
Alan Cox33f0f882006-01-09 20:54:13 -08002166 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 rxwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002169 while (bytesAvailable > 0) { /* Begin while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 /* ---------------------------------------------------------------
2172 Even if head has wrapped around only report the amount of
2173 data to be equal to the size - tail. Remember memcpy can't
2174 automaticly wrap around the receive buffer.
2175 ----------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 /* --------------------------------------------------------------
2178 Make sure we don't overflow the buffer
2179 ----------------------------------------------------------------- */
Alan Cox33f0f882006-01-09 20:54:13 -08002180 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 if (dataToRead == 0)
2182 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 /* ---------------------------------------------------------------
2184 Move data read from our card into the line disciplines buffer
2185 for translation if necessary.
2186 ------------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002187 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 tail = (tail + dataToRead) & wrapmask;
2189 bytesAvailable -= dataToRead;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 } /* End while there is data on the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002192 writew(tail, &bc->rout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 /* Must be called with global data */
2194 tty_schedule_flip(ch->tty);
2195 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196} /* End receive_data */
2197
2198static int info_ioctl(struct tty_struct *tty, struct file * file,
2199 unsigned int cmd, unsigned long arg)
2200{
2201 switch (cmd)
2202 { /* Begin switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 case DIGI_GETINFO:
2204 { /* Begin case DIGI_GETINFO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 struct digi_info di ;
2206 int brd;
2207
Alan Coxf2cf8e22005-09-06 15:16:44 -07002208 if(get_user(brd, (unsigned int __user *)arg))
2209 return -EFAULT;
2210 if (brd < 0 || brd >= num_cards || num_cards == 0)
2211 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
2213 memset(&di, 0, sizeof(di));
2214
2215 di.board = brd ;
2216 di.status = boards[brd].status;
2217 di.type = boards[brd].type ;
2218 di.numports = boards[brd].numports ;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002219 /* Legacy fixups - just move along nothing to see */
2220 di.port = (unsigned char *)boards[brd].port ;
2221 di.membase = (unsigned char *)boards[brd].membase ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
2223 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2224 return -EFAULT;
2225 break;
2226
2227 } /* End case DIGI_GETINFO */
2228
2229 case DIGI_POLLER:
2230 { /* Begin case DIGI_POLLER */
2231
2232 int brd = arg & 0xff000000 >> 16 ;
2233 unsigned char state = arg & 0xff ;
2234
Alan Coxf2cf8e22005-09-06 15:16:44 -07002235 if (brd < 0 || brd >= num_cards) {
2236 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 return (-ENODEV);
2238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 digi_poller_inhibited = state ;
2240 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 } /* End case DIGI_POLLER */
2242
2243 case DIGI_INIT:
2244 { /* Begin case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 /* ------------------------------------------------------------
2246 This call is made by the apps to complete the initilization
2247 of the board(s). This routine is responsible for setting
2248 the card to its initial state and setting the drivers control
2249 fields to the sutianle settings for the card in question.
2250 ---------------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 int crd ;
2252 for (crd = 0; crd < num_cards; crd++)
2253 post_fep_init (crd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 break ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 } /* End case DIGI_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002257 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 } /* End switch cmd */
2259 return (0) ;
2260}
2261/* --------------------- Begin pc_ioctl ----------------------- */
2262
2263static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2264{
2265 struct channel *ch = (struct channel *) tty->driver_data;
Al Virobc9a5152005-09-15 22:53:28 +01002266 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 unsigned int mstat, mflag = 0;
2268 unsigned long flags;
2269
2270 if (ch)
2271 bc = ch->brdchan;
2272 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002273 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Alan Coxf2cf8e22005-09-06 15:16:44 -07002275 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002277 mstat = readb(&bc->mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002279 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 if (mstat & ch->m_dtr)
2282 mflag |= TIOCM_DTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 if (mstat & ch->m_rts)
2284 mflag |= TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 if (mstat & ch->m_cts)
2286 mflag |= TIOCM_CTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 if (mstat & ch->dsr)
2288 mflag |= TIOCM_DSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 if (mstat & ch->m_ri)
2290 mflag |= TIOCM_RI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 if (mstat & ch->dcd)
2292 mflag |= TIOCM_CD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 return mflag;
2294}
2295
2296static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2297 unsigned int set, unsigned int clear)
2298{
2299 struct channel *ch = (struct channel *) tty->driver_data;
2300 unsigned long flags;
2301
Alan Coxf2cf8e22005-09-06 15:16:44 -07002302 if (!ch)
2303 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
Alan Coxf2cf8e22005-09-06 15:16:44 -07002305 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 /*
2307 * I think this modemfake stuff is broken. It doesn't
2308 * correctly reflect the behaviour desired by the TIOCM*
2309 * ioctls. Therefore this is probably broken.
2310 */
2311 if (set & TIOCM_RTS) {
2312 ch->modemfake |= ch->m_rts;
2313 ch->modem |= ch->m_rts;
2314 }
2315 if (set & TIOCM_DTR) {
2316 ch->modemfake |= ch->m_dtr;
2317 ch->modem |= ch->m_dtr;
2318 }
2319 if (clear & TIOCM_RTS) {
2320 ch->modemfake |= ch->m_rts;
2321 ch->modem &= ~ch->m_rts;
2322 }
2323 if (clear & TIOCM_DTR) {
2324 ch->modemfake |= ch->m_dtr;
2325 ch->modem &= ~ch->m_dtr;
2326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 /* --------------------------------------------------------------
2329 The below routine generally sets up parity, baud, flow control
2330 issues, etc.... It effect both control flags and input flags.
2331 ------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 epcaparam(tty,ch);
2333 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002334 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 return 0;
2336}
2337
2338static int pc_ioctl(struct tty_struct *tty, struct file * file,
2339 unsigned int cmd, unsigned long arg)
2340{ /* Begin pc_ioctl */
2341
2342 digiflow_t dflow;
2343 int retval;
2344 unsigned long flags;
2345 unsigned int mflag, mstat;
2346 unsigned char startc, stopc;
Al Virobc9a5152005-09-15 22:53:28 +01002347 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 struct channel *ch = (struct channel *) tty->driver_data;
2349 void __user *argp = (void __user *)arg;
2350
2351 if (ch)
2352 bc = ch->brdchan;
2353 else
Alan Coxf2cf8e22005-09-06 15:16:44 -07002354 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 /* -------------------------------------------------------------------
2357 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2358 in /usr/src/linux/drivers/char for a good example. In particular
2359 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2360 ---------------------------------------------------------------------- */
2361
2362 switch (cmd)
2363 { /* Begin switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 case TCSBRK: /* SVID version: non-zero arg --> no break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 retval = tty_check_change(tty);
2366 if (retval)
2367 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002369 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002371 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 tty_wait_until_sent(tty, 0);
2373 if (!arg)
2374 digi_send_break(ch, HZ/4); /* 1/4 second */
2375 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 case TCSBRKP: /* support for POSIX tcsendbreak() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 retval = tty_check_change(tty);
2378 if (retval)
2379 return retval;
2380
2381 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002382 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002384 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 tty_wait_until_sent(tty, 0);
2386 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2387 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 case TIOCGSOFTCAR:
2389 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2390 return -EFAULT;
2391 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 case TIOCSSOFTCAR:
2393 {
2394 unsigned int value;
2395
2396 if (get_user(value, (unsigned __user *)argp))
2397 return -EFAULT;
2398 tty->termios->c_cflag =
2399 ((tty->termios->c_cflag & ~CLOCAL) |
2400 (value ? CLOCAL : 0));
2401 return 0;
2402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 case TIOCMODG:
2404 mflag = pc_tiocmget(tty, file);
2405 if (put_user(mflag, (unsigned long __user *)argp))
2406 return -EFAULT;
2407 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 case TIOCMODS:
2409 if (get_user(mstat, (unsigned __user *)argp))
2410 return -EFAULT;
2411 return pc_tiocmset(tty, file, mstat, ~mstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 case TIOCSDTR:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002413 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 ch->omodem |= ch->m_dtr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 globalwinon(ch);
2416 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2417 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002418 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 break;
2420
2421 case TIOCCDTR:
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, 0, ch->m_dtr, 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 case DIGI_GETA:
2430 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2431 return -EFAULT;
2432 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 case DIGI_SETAW:
2434 case DIGI_SETAF:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002435 if (cmd == DIGI_SETAW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 /* Setup an event to indicate when the transmit buffer empties */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002437 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 setup_empty_event(tty,ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002439 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 tty_wait_until_sent(tty, 0);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002441 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 /* ldisc lock already held in ioctl */
2443 if (tty->ldisc.flush_buffer)
2444 tty->ldisc.flush_buffer(tty);
2445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 /* Fall Thru */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 case DIGI_SETA:
2448 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2449 return -EFAULT;
2450
Alan Coxf2cf8e22005-09-06 15:16:44 -07002451 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 ch->dcd = ch->m_dsr;
2453 ch->dsr = ch->m_dcd;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002454 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 ch->dcd = ch->m_dcd;
2456 ch->dsr = ch->m_dsr;
2457 }
2458
Alan Coxf2cf8e22005-09-06 15:16:44 -07002459 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 globalwinon(ch);
2461
2462 /* -----------------------------------------------------------------
2463 The below routine generally sets up parity, baud, flow control
2464 issues, etc.... It effect both control flags and input flags.
2465 ------------------------------------------------------------------- */
2466
2467 epcaparam(tty,ch);
2468 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002469 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 break;
2471
2472 case DIGI_GETFLOW:
2473 case DIGI_GETAFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002474 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 globalwinon(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002476 if (cmd == DIGI_GETFLOW) {
2477 dflow.startc = readb(&bc->startc);
2478 dflow.stopc = readb(&bc->stopc);
2479 } else {
2480 dflow.startc = readb(&bc->startca);
2481 dflow.stopc = readb(&bc->stopca);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 }
2483 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002484 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
2486 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2487 return -EFAULT;
2488 break;
2489
2490 case DIGI_SETAFLOW:
2491 case DIGI_SETFLOW:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002492 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 startc = ch->startc;
2494 stopc = ch->stopc;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002495 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 startc = ch->startca;
2497 stopc = ch->stopca;
2498 }
2499
2500 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2501 return -EFAULT;
2502
Alan Coxf2cf8e22005-09-06 15:16:44 -07002503 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2504 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 globalwinon(ch);
2506
Alan Coxf2cf8e22005-09-06 15:16:44 -07002507 if (cmd == DIGI_SETFLOW) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 ch->fepstartc = ch->startc = dflow.startc;
2509 ch->fepstopc = ch->stopc = dflow.stopc;
2510 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002511 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 ch->fepstartca = ch->startca = dflow.startc;
2513 ch->fepstopca = ch->stopca = dflow.stopc;
2514 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2515 }
2516
Alan Coxf2cf8e22005-09-06 15:16:44 -07002517 if (ch->statusflags & TXSTOPPED)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 pc_start(tty);
2519
2520 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002521 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 } /* End if setflow toggled */
2523 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 default:
2525 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 } /* End switch cmd */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528} /* End pc_ioctl */
2529
2530/* --------------------- Begin pc_set_termios ----------------------- */
2531
Alan Cox606d0992006-12-08 02:38:45 -08002532static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533{ /* Begin pc_set_termios */
2534
2535 struct channel *ch;
2536 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 /* ---------------------------------------------------------
2538 verifyChannel returns the channel from the tty struct
2539 if it is valid. This serves as a sanity check.
2540 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002541 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2542 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 globalwinon(ch);
2544 epcaparam(tty, ch);
2545 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002546 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548 if ((old_termios->c_cflag & CRTSCTS) &&
2549 ((tty->termios->c_cflag & CRTSCTS) == 0))
2550 tty->hw_stopped = 0;
2551
2552 if (!(old_termios->c_cflag & CLOCAL) &&
2553 (tty->termios->c_cflag & CLOCAL))
2554 wake_up_interruptible(&ch->open_wait);
2555
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 } /* End if channel valid */
2557
2558} /* End pc_set_termios */
2559
2560/* --------------------- Begin do_softint ----------------------- */
2561
David Howellsc4028952006-11-22 14:57:56 +00002562static void do_softint(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563{ /* Begin do_softint */
David Howellsc4028952006-11-22 14:57:56 +00002564 struct channel *ch = container_of(work, struct channel, tqueue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 /* Called in response to a modem change event */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002566 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 struct tty_struct *tty = ch->tty;
2568
Alan Coxf2cf8e22005-09-06 15:16:44 -07002569 if (tty && tty->driver_data) {
2570 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2572 wake_up_interruptible(&ch->open_wait);
2573 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 } /* End if clear_bit */
2575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 } /* End EPCA_MAGIC */
2577} /* End do_softint */
2578
2579/* ------------------------------------------------------------
2580 pc_stop and pc_start provide software flow control to the
2581 routine and the pc_ioctl routine.
2582---------------------------------------------------------------- */
2583
2584/* --------------------- Begin pc_stop ----------------------- */
2585
2586static void pc_stop(struct tty_struct *tty)
2587{ /* Begin pc_stop */
2588
2589 struct channel *ch;
2590 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 /* ---------------------------------------------------------
2592 verifyChannel returns the channel from the tty struct
2593 if it is valid. This serves as a sanity check.
2594 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002595 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
2596 spin_lock_irqsave(&epca_lock, flags);
2597 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 /* STOP transmitting now !! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 ch->statusflags |= TXSTOPPED;
2602 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 } /* End if transmit stop requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002604 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 } /* End if valid channel */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606} /* End pc_stop */
2607
2608/* --------------------- Begin pc_start ----------------------- */
2609
2610static void pc_start(struct tty_struct *tty)
2611{ /* Begin pc_start */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 struct channel *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 /* ---------------------------------------------------------
2614 verifyChannel returns the channel from the tty struct
2615 if it is valid. This serves as a sanity check.
2616 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002617 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 unsigned long flags;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002619 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002621 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
Al Virobc9a5152005-09-15 22:53:28 +01002622 struct board_chan __iomem *bc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 globalwinon(ch);
2624 bc = ch->brdchan;
2625 if (ch->statusflags & LOWWAIT)
Alan Coxf2cf8e22005-09-06 15:16:44 -07002626 writeb(1, &bc->ilow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 /* Okay, you can start transmitting again... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 ch->statusflags &= ~TXSTOPPED;
2630 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 } /* End transmit resume requested */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002632 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634} /* End pc_start */
2635
2636/* ------------------------------------------------------------------
2637 The below routines pc_throttle and pc_unthrottle are used
2638 to slow (And resume) the receipt of data into the kernels
2639 receive buffers. The exact occurrence of this depends on the
2640 size of the kernels receive buffer and what the 'watermarks'
2641 are set to for that buffer. See the n_ttys.c file for more
2642 details.
2643______________________________________________________________________ */
2644/* --------------------- Begin throttle ----------------------- */
2645
2646static void pc_throttle(struct tty_struct * tty)
2647{ /* Begin pc_throttle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 struct channel *ch;
2649 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 /* ---------------------------------------------------------
2651 verifyChannel returns the channel from the tty struct
2652 if it is valid. This serves as a sanity check.
2653 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002654 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2655 spin_lock_irqsave(&epca_lock, flags);
2656 if ((ch->statusflags & RXSTOPPED) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 globalwinon(ch);
2658 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 ch->statusflags |= RXSTOPPED;
2660 memoff(ch);
2661 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002662 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664} /* End pc_throttle */
2665
2666/* --------------------- Begin unthrottle ----------------------- */
2667
2668static void pc_unthrottle(struct tty_struct *tty)
2669{ /* Begin pc_unthrottle */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 struct channel *ch;
2671 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 /* ---------------------------------------------------------
2673 verifyChannel returns the channel from the tty struct
2674 if it is valid. This serves as a sanity check.
2675 ------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002676 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 /* Just in case output was resumed because of a change in Digi-flow */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002678 spin_lock_irqsave(&epca_lock, flags);
2679 if (ch->statusflags & RXSTOPPED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 ch->statusflags &= ~RXSTOPPED;
2683 memoff(ch);
2684 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002685 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 } /* End if channel valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687} /* End pc_unthrottle */
2688
2689/* --------------------- Begin digi_send_break ----------------------- */
2690
2691void digi_send_break(struct channel *ch, int msec)
2692{ /* Begin digi_send_break */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 unsigned long flags;
2694
Alan Coxf2cf8e22005-09-06 15:16:44 -07002695 spin_lock_irqsave(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 globalwinon(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 /* --------------------------------------------------------------------
2698 Maybe I should send an infinite break here, schedule() for
2699 msec amount of time, and then stop the break. This way,
2700 the user can't screw up the FEP by causing digi_send_break()
2701 to be called (i.e. via an ioctl()) more than once in msec amount
2702 of time. Try this for now...
2703 ------------------------------------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2705 memoff(ch);
Alan Coxf2cf8e22005-09-06 15:16:44 -07002706 spin_unlock_irqrestore(&epca_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707} /* End digi_send_break */
2708
2709/* --------------------- Begin setup_empty_event ----------------------- */
2710
Alan Coxf2cf8e22005-09-06 15:16:44 -07002711/* Caller MUST hold the lock */
2712
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2714{ /* Begin setup_empty_event */
2715
Al Virobc9a5152005-09-15 22:53:28 +01002716 struct board_chan __iomem *bc = ch->brdchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 globalwinon(ch);
2719 ch->statusflags |= EMPTYWAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 /* ------------------------------------------------------------------
2721 When set the iempty flag request a event to be generated when the
2722 transmit buffer is empty (If there is no BREAK in progress).
2723 --------------------------------------------------------------------- */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002724 writeb(1, &bc->iempty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 memoff(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726} /* End setup_empty_event */
2727
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728/* ---------------------- Begin epca_setup -------------------------- */
2729void epca_setup(char *str, int *ints)
2730{ /* Begin epca_setup */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 struct board_info board;
2732 int index, loop, last;
2733 char *temp, *t2;
2734 unsigned len;
2735
2736 /* ----------------------------------------------------------------------
2737 If this routine looks a little strange it is because it is only called
2738 if a LILO append command is given to boot the kernel with parameters.
2739 In this way, we can provide the user a method of changing his board
2740 configuration without rebuilding the kernel.
2741 ----------------------------------------------------------------------- */
2742 if (!liloconfig)
2743 liloconfig = 1;
2744
2745 memset(&board, 0, sizeof(board));
2746
2747 /* Assume the data is int first, later we can change it */
2748 /* I think that array position 0 of ints holds the number of args */
2749 for (last = 0, index = 1; index <= ints[0]; index++)
2750 switch(index)
2751 { /* Begin parse switch */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 case 1:
2753 board.status = ints[index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 /* ---------------------------------------------------------
2755 We check for 2 (As opposed to 1; because 2 is a flag
2756 instructing the driver to ignore epcaconfig.) For this
2757 reason we check for 2.
2758 ------------------------------------------------------------ */
Alan Coxf2cf8e22005-09-06 15:16:44 -07002759 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 nbdevs = 0;
2761 num_cards = 0;
2762 return;
2763 } /* End ignore epcaconfig as well as lilo cmd line */
2764
Alan Coxf2cf8e22005-09-06 15:16:44 -07002765 if (board.status > 2) {
2766 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 invalid_lilo_config = 1;
2768 setup_error_code |= INVALID_BOARD_STATUS;
2769 return;
2770 }
2771 last = index;
2772 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 case 2:
2774 board.type = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002775 if (board.type >= PCIXEM) {
2776 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 invalid_lilo_config = 1;
2778 setup_error_code |= INVALID_BOARD_TYPE;
2779 return;
2780 }
2781 last = index;
2782 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 case 3:
2784 board.altpin = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002785 if (board.altpin > 1) {
2786 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 invalid_lilo_config = 1;
2788 setup_error_code |= INVALID_ALTPIN;
2789 return;
2790 }
2791 last = index;
2792 break;
2793
2794 case 4:
2795 board.numports = ints[index];
Alan Coxf2cf8e22005-09-06 15:16:44 -07002796 if (board.numports < 2 || board.numports > 256) {
2797 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 invalid_lilo_config = 1;
2799 setup_error_code |= INVALID_NUM_PORTS;
2800 return;
2801 }
2802 nbdevs += board.numports;
2803 last = index;
2804 break;
2805
2806 case 5:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002807 board.port = ints[index];
2808 if (ints[index] <= 0) {
2809 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 invalid_lilo_config = 1;
2811 setup_error_code |= INVALID_PORT_BASE;
2812 return;
2813 }
2814 last = index;
2815 break;
2816
2817 case 6:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002818 board.membase = ints[index];
2819 if (ints[index] <= 0) {
2820 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 invalid_lilo_config = 1;
2822 setup_error_code |= INVALID_MEM_BASE;
2823 return;
2824 }
2825 last = index;
2826 break;
2827
2828 default:
2829 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2830 return;
2831
2832 } /* End parse switch */
2833
Alan Coxf2cf8e22005-09-06 15:16:44 -07002834 while (str && *str) { /* Begin while there is a string arg */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 /* find the next comma or terminator */
2836 temp = str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 /* While string is not null, and a comma hasn't been found */
2838 while (*temp && (*temp != ','))
2839 temp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 if (!*temp)
2841 temp = NULL;
2842 else
2843 *temp++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 /* Set index to the number of args + 1 */
2845 index = last + 1;
2846
2847 switch(index)
2848 {
2849 case 1:
2850 len = strlen(str);
2851 if (strncmp("Disable", str, len) == 0)
2852 board.status = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002853 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 board.status = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002855 else {
2856 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 invalid_lilo_config = 1;
2858 setup_error_code |= INVALID_BOARD_STATUS;
2859 return;
2860 }
2861 last = index;
2862 break;
2863
2864 case 2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
2866 if (strcmp(board_desc[loop], str) == 0)
2867 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 /* ---------------------------------------------------------------
2869 If the index incremented above refers to a legitamate board
2870 type set it here.
2871 ------------------------------------------------------------------*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 if (index < EPCA_NUM_TYPES)
2873 board.type = loop;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002874 else {
2875 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 invalid_lilo_config = 1;
2877 setup_error_code |= INVALID_BOARD_TYPE;
2878 return;
2879 }
2880 last = index;
2881 break;
2882
2883 case 3:
2884 len = strlen(str);
2885 if (strncmp("Disable", str, len) == 0)
2886 board.altpin = 0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002887 else if (strncmp("Enable", str, len) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 board.altpin = 1;
Alan Coxf2cf8e22005-09-06 15:16:44 -07002889 else {
2890 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 invalid_lilo_config = 1;
2892 setup_error_code |= INVALID_ALTPIN;
2893 return;
2894 }
2895 last = index;
2896 break;
2897
2898 case 4:
2899 t2 = str;
2900 while (isdigit(*t2))
2901 t2++;
2902
Alan Coxf2cf8e22005-09-06 15:16:44 -07002903 if (*t2) {
2904 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 invalid_lilo_config = 1;
2906 setup_error_code |= INVALID_NUM_PORTS;
2907 return;
2908 }
2909
2910 /* ------------------------------------------------------------
2911 There is not a man page for simple_strtoul but the code can be
2912 found in vsprintf.c. The first argument is the string to
2913 translate (To an unsigned long obviously), the second argument
2914 can be the address of any character variable or a NULL. If a
2915 variable is given, the end pointer of the string will be stored
2916 in that variable; if a NULL is given the end pointer will
2917 not be returned. The last argument is the base to use. If
2918 a 0 is indicated, the routine will attempt to determine the
2919 proper base by looking at the values prefix (A '0' for octal,
2920 a 'x' for hex, etc ... If a value is given it will use that
2921 value as the base.
2922 ---------------------------------------------------------------- */
2923 board.numports = simple_strtoul(str, NULL, 0);
2924 nbdevs += board.numports;
2925 last = index;
2926 break;
2927
2928 case 5:
2929 t2 = str;
2930 while (isxdigit(*t2))
2931 t2++;
2932
Alan Coxf2cf8e22005-09-06 15:16:44 -07002933 if (*t2) {
2934 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 invalid_lilo_config = 1;
2936 setup_error_code |= INVALID_PORT_BASE;
2937 return;
2938 }
2939
Alan Coxf2cf8e22005-09-06 15:16:44 -07002940 board.port = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 last = index;
2942 break;
2943
2944 case 6:
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 memory base %s\n",str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 invalid_lilo_config = 1;
2952 setup_error_code |= INVALID_MEM_BASE;
2953 return;
2954 }
Alan Coxf2cf8e22005-09-06 15:16:44 -07002955 board.membase = simple_strtoul(str, NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 last = index;
2957 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 default:
Alan Coxf2cf8e22005-09-06 15:16:44 -07002959 printk(KERN_ERR "epca: Too many string parms\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 return;
2961 }
2962 str = temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 } /* End while there is a string arg */
2964
Alan Coxf2cf8e22005-09-06 15:16:44 -07002965 if (last < 6) {
2966 printk(KERN_ERR "epca: Insufficient parms specified\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 return;
2968 }
2969
2970 /* I should REALLY validate the stuff here */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 /* Copies our local copy of board into boards */
2972 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 /* Does this get called once per lilo arg are what ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2975 num_cards, board_desc[board.type],
2976 board.numports, (int)board.port, (unsigned int) board.membase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 num_cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978} /* End epca_setup */
2979
2980
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981/* ------------------------ Begin init_PCI --------------------------- */
2982
2983enum epic_board_types {
2984 brd_xr = 0,
2985 brd_xem,
2986 brd_cx,
2987 brd_xrj,
2988};
2989
2990
2991/* indexed directly by epic_board_types enum */
2992static struct {
2993 unsigned char board_type;
2994 unsigned bar_idx; /* PCI base address region */
2995} epca_info_tbl[] = {
2996 { PCIXR, 0, },
2997 { PCIXEM, 0, },
2998 { PCICX, 0, },
2999 { PCIXRJ, 2, },
3000};
3001
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002static int __devinit epca_init_one (struct pci_dev *pdev,
3003 const struct pci_device_id *ent)
3004{
3005 static int board_num = -1;
3006 int board_idx, info_idx = ent->driver_data;
3007 unsigned long addr;
3008
3009 if (pci_enable_device(pdev))
3010 return -EIO;
3011
3012 board_num++;
3013 board_idx = board_num + num_cards;
3014 if (board_idx >= MAXBOARDS)
3015 goto err_out;
3016
3017 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3018 if (!addr) {
3019 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3020 epca_info_tbl[info_idx].bar_idx);
3021 goto err_out;
3022 }
3023
3024 boards[board_idx].status = ENABLED;
3025 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3026 boards[board_idx].numports = 0x0;
Alan Coxf2cf8e22005-09-06 15:16:44 -07003027 boards[board_idx].port = addr + PCI_IO_OFFSET;
3028 boards[board_idx].membase = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
3030 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3031 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3032 0x200000, addr + PCI_IO_OFFSET);
3033 goto err_out;
3034 }
3035
3036 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3037 if (!boards[board_idx].re_map_port) {
3038 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3039 0x200000, addr + PCI_IO_OFFSET);
3040 goto err_out_free_pciio;
3041 }
3042
3043 if (!request_mem_region (addr, 0x200000, "epca")) {
3044 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3045 0x200000, addr);
3046 goto err_out_free_iounmap;
3047 }
3048
3049 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3050 if (!boards[board_idx].re_map_membase) {
3051 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3052 0x200000, addr + PCI_IO_OFFSET);
3053 goto err_out_free_memregion;
3054 }
3055
3056 /* --------------------------------------------------------------
3057 I don't know what the below does, but the hardware guys say
3058 its required on everything except PLX (In this case XRJ).
3059 ---------------------------------------------------------------- */
3060 if (info_idx != brd_xrj) {
3061 pci_write_config_byte(pdev, 0x40, 0);
3062 pci_write_config_byte(pdev, 0x46, 0);
3063 }
3064
3065 return 0;
3066
3067err_out_free_memregion:
3068 release_mem_region (addr, 0x200000);
3069err_out_free_iounmap:
3070 iounmap (boards[board_idx].re_map_port);
3071err_out_free_pciio:
3072 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3073err_out:
3074 return -ENODEV;
3075}
3076
3077
3078static struct pci_device_id epca_pci_tbl[] = {
3079 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3080 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3081 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3082 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3083 { 0, }
3084};
3085
3086MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3087
3088int __init init_PCI (void)
Alan Coxf2cf8e22005-09-06 15:16:44 -07003089{ /* Begin init_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 memset (&epca_driver, 0, sizeof (epca_driver));
3091 epca_driver.name = "epca";
3092 epca_driver.id_table = epca_pci_tbl;
3093 epca_driver.probe = epca_init_one;
3094
3095 return pci_register_driver(&epca_driver);
Alan Coxf2cf8e22005-09-06 15:16:44 -07003096}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
3098MODULE_LICENSE("GPL");