[PATCH] tty: switch to ktermios
[deliverable/linux.git] / drivers / char / epca.c
CommitLineData
1da177e4
LT
1/*
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
f2cf8e25
AC
9 ** This driver is no longer supported by Digi **
10
1da177e4
LT
11 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
1da177e4
LT
33#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>
f2cf8e25 47#include <linux/spinlock.h>
1da177e4
LT
48#include <linux/pci.h>
49#include "digiPCI.h"
f2cf8e25 50
1da177e4
LT
51
52#include "digi1.h"
53#include "digiFep1.h"
54#include "epca.h"
55#include "epcaconfig.h"
56
1da177e4
LT
57/* ---------------------- Begin defines ------------------------ */
58
f2cf8e25 59#define VERSION "1.3.0.1-LK2.6"
1da177e4
LT
60
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
1da177e4
LT
73static int nbdevs, num_cards, liloconfig;
74static int digi_poller_inhibited = 1 ;
75
76static int setup_error_code;
77static int invalid_lilo_config;
78
f2cf8e25
AC
79/* 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
34af946a 82static DEFINE_SPINLOCK(epca_lock);
f2cf8e25 83
1da177e4
LT
84/* -----------------------------------------------------------------------
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
f2cf8e25
AC
125static 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);
1da177e4
LT
133
134/* ---- Begin more 'specific' memory functions for cx_like products --- */
135
f2cf8e25
AC
136static 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);
1da177e4
LT
142
143/* ------ Begin more 'specific' memory functions for the pcxe ------- */
144
f2cf8e25
AC
145static 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);
1da177e4
LT
151
152/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
153/* Note : pc64xe and pcxi share the same windowing routines */
154
f2cf8e25
AC
155static 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);
1da177e4
LT
161
162/* - Begin 'specific' do nothing memory functions needed for some cards - */
163
f2cf8e25
AC
164static 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);
1da177e4
LT
172
173/* ------------------- Begin declare functions ----------------------- */
174
f2cf8e25
AC
175static struct channel *verifyChannel(struct tty_struct *);
176static void pc_sched_event(struct channel *, int);
1da177e4
LT
177static 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);
606d099c 202static void pc_set_termios(struct tty_struct *, struct ktermios *);
c4028958 203static void do_softint(struct work_struct *work);
1da177e4
LT
204static 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 *);
1da177e4
LT
211
212static int get_termio(struct tty_struct *, struct termio __user *);
213static int pc_write(struct tty_struct *, const unsigned char *, int);
f2cf8e25 214static int pc_init(void);
1da177e4 215static int init_PCI(void);
1da177e4
LT
216
217
218/* ------------------------------------------------------------------
219 Table of functions for each board to handle memory. Mantaining
220 parallelism is a *very* good idea here. The idea is for the
221 runtime code to blindly call these functions, not knowing/caring
222 about the underlying hardware. This stuff should contain no
223 conditionals; if more functionality is needed a different entry
224 should be established. These calls are the interface calls and
225 are the only functions that should be accessed. Anyone caught
226 making direct calls deserves what they get.
227-------------------------------------------------------------------- */
228
f2cf8e25 229static void memwinon(struct board_info *b, unsigned int win)
1da177e4
LT
230{
231 (b->memwinon)(b, win);
232}
233
f2cf8e25 234static void memwinoff(struct board_info *b, unsigned int win)
1da177e4
LT
235{
236 (b->memwinoff)(b, win);
237}
238
f2cf8e25 239static void globalwinon(struct channel *ch)
1da177e4
LT
240{
241 (ch->board->globalwinon)(ch);
242}
243
f2cf8e25 244static void rxwinon(struct channel *ch)
1da177e4
LT
245{
246 (ch->board->rxwinon)(ch);
247}
248
f2cf8e25 249static void txwinon(struct channel *ch)
1da177e4
LT
250{
251 (ch->board->txwinon)(ch);
252}
253
f2cf8e25 254static void memoff(struct channel *ch)
1da177e4
LT
255{
256 (ch->board->memoff)(ch);
257}
f2cf8e25 258static void assertgwinon(struct channel *ch)
1da177e4
LT
259{
260 (ch->board->assertgwinon)(ch);
261}
262
f2cf8e25 263static void assertmemoff(struct channel *ch)
1da177e4
LT
264{
265 (ch->board->assertmemoff)(ch);
266}
267
268/* ---------------------------------------------------------
269 PCXEM windowing is the same as that used in the PCXR
270 and CX series cards.
271------------------------------------------------------------ */
272
f2cf8e25 273static void pcxem_memwinon(struct board_info *b, unsigned int win)
1da177e4 274{
f2cf8e25 275 outb_p(FEPWIN|win, b->port + 1);
1da177e4
LT
276}
277
f2cf8e25 278static void pcxem_memwinoff(struct board_info *b, unsigned int win)
1da177e4 279{
f2cf8e25 280 outb_p(0, b->port + 1);
1da177e4
LT
281}
282
f2cf8e25 283static void pcxem_globalwinon(struct channel *ch)
1da177e4
LT
284{
285 outb_p( FEPWIN, (int)ch->board->port + 1);
286}
287
f2cf8e25 288static void pcxem_rxwinon(struct channel *ch)
1da177e4
LT
289{
290 outb_p(ch->rxwin, (int)ch->board->port + 1);
291}
292
f2cf8e25 293static void pcxem_txwinon(struct channel *ch)
1da177e4
LT
294{
295 outb_p(ch->txwin, (int)ch->board->port + 1);
296}
297
f2cf8e25 298static void pcxem_memoff(struct channel *ch)
1da177e4
LT
299{
300 outb_p(0, (int)ch->board->port + 1);
301}
302
303/* ----------------- Begin pcxe memory window stuff ------------------ */
304
f2cf8e25 305static void pcxe_memwinon(struct board_info *b, unsigned int win)
1da177e4 306{
f2cf8e25 307 outb_p(FEPWIN | win, b->port + 1);
1da177e4
LT
308}
309
f2cf8e25 310static void pcxe_memwinoff(struct board_info *b, unsigned int win)
1da177e4 311{
f2cf8e25
AC
312 outb_p(inb(b->port) & ~FEPMEM,
313 b->port + 1);
314 outb_p(0, b->port + 1);
1da177e4
LT
315}
316
f2cf8e25 317static void pcxe_globalwinon(struct channel *ch)
1da177e4
LT
318{
319 outb_p( FEPWIN, (int)ch->board->port + 1);
320}
321
f2cf8e25 322static void pcxe_rxwinon(struct channel *ch)
1da177e4
LT
323{
324 outb_p(ch->rxwin, (int)ch->board->port + 1);
325}
326
f2cf8e25 327static void pcxe_txwinon(struct channel *ch)
1da177e4
LT
328{
329 outb_p(ch->txwin, (int)ch->board->port + 1);
330}
331
f2cf8e25 332static void pcxe_memoff(struct channel *ch)
1da177e4
LT
333{
334 outb_p(0, (int)ch->board->port);
335 outb_p(0, (int)ch->board->port + 1);
336}
337
338/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
339
f2cf8e25 340static void pcxi_memwinon(struct board_info *b, unsigned int win)
1da177e4 341{
f2cf8e25 342 outb_p(inb(b->port) | FEPMEM, b->port);
1da177e4
LT
343}
344
f2cf8e25 345static void pcxi_memwinoff(struct board_info *b, unsigned int win)
1da177e4 346{
f2cf8e25 347 outb_p(inb(b->port) & ~FEPMEM, b->port);
1da177e4
LT
348}
349
f2cf8e25 350static void pcxi_globalwinon(struct channel *ch)
1da177e4 351{
f2cf8e25 352 outb_p(FEPMEM, ch->board->port);
1da177e4
LT
353}
354
f2cf8e25 355static void pcxi_rxwinon(struct channel *ch)
1da177e4 356{
f2cf8e25 357 outb_p(FEPMEM, ch->board->port);
1da177e4
LT
358}
359
f2cf8e25 360static void pcxi_txwinon(struct channel *ch)
1da177e4 361{
f2cf8e25 362 outb_p(FEPMEM, ch->board->port);
1da177e4
LT
363}
364
f2cf8e25 365static void pcxi_memoff(struct channel *ch)
1da177e4 366{
f2cf8e25 367 outb_p(0, ch->board->port);
1da177e4
LT
368}
369
f2cf8e25 370static void pcxi_assertgwinon(struct channel *ch)
1da177e4 371{
f2cf8e25 372 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
1da177e4
LT
373}
374
f2cf8e25 375static void pcxi_assertmemoff(struct channel *ch)
1da177e4 376{
f2cf8e25 377 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
1da177e4
LT
378}
379
380
381/* ----------------------------------------------------------------------
382 Not all of the cards need specific memory windowing routines. Some
383 cards (Such as PCI) needs no windowing routines at all. We provide
384 these do nothing routines so that the same code base can be used.
385 The driver will ALWAYS call a windowing routine if it thinks it needs
386 to; regardless of the card. However, dependent on the card the routine
387 may or may not do anything.
388---------------------------------------------------------------------------*/
389
f2cf8e25 390static void dummy_memwinon(struct board_info *b, unsigned int win)
1da177e4
LT
391{
392}
393
f2cf8e25 394static void dummy_memwinoff(struct board_info *b, unsigned int win)
1da177e4
LT
395{
396}
397
f2cf8e25 398static void dummy_globalwinon(struct channel *ch)
1da177e4
LT
399{
400}
401
f2cf8e25 402static void dummy_rxwinon(struct channel *ch)
1da177e4
LT
403{
404}
405
f2cf8e25 406static void dummy_txwinon(struct channel *ch)
1da177e4
LT
407{
408}
409
f2cf8e25 410static void dummy_memoff(struct channel *ch)
1da177e4
LT
411{
412}
413
f2cf8e25 414static void dummy_assertgwinon(struct channel *ch)
1da177e4
LT
415{
416}
417
f2cf8e25 418static void dummy_assertmemoff(struct channel *ch)
1da177e4
LT
419{
420}
421
422/* ----------------- Begin verifyChannel function ----------------------- */
f2cf8e25 423static struct channel *verifyChannel(struct tty_struct *tty)
1da177e4 424{ /* Begin verifyChannel */
1da177e4
LT
425 /* --------------------------------------------------------------------
426 This routine basically provides a sanity check. It insures that
427 the channel returned is within the proper range of addresses as
428 well as properly initialized. If some bogus info gets passed in
429 through tty->driver_data this should catch it.
f2cf8e25
AC
430 --------------------------------------------------------------------- */
431 if (tty) {
432 struct channel *ch = (struct channel *)tty->driver_data;
433 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
1da177e4
LT
434 if (ch->magic == EPCA_MAGIC)
435 return ch;
436 }
f2cf8e25 437 }
1da177e4
LT
438 return NULL;
439
440} /* End verifyChannel */
441
442/* ------------------ Begin pc_sched_event ------------------------- */
443
f2cf8e25
AC
444static void pc_sched_event(struct channel *ch, int event)
445{
1da177e4
LT
446 /* ----------------------------------------------------------------------
447 We call this to schedule interrupt processing on some event. The
448 kernel sees our request and calls the related routine in OUR driver.
449 -------------------------------------------------------------------------*/
1da177e4
LT
450 ch->event |= 1 << event;
451 schedule_work(&ch->tqueue);
1da177e4
LT
452} /* End pc_sched_event */
453
454/* ------------------ Begin epca_error ------------------------- */
455
456static void epca_error(int line, char *msg)
f2cf8e25 457{
1da177e4 458 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
f2cf8e25 459}
1da177e4
LT
460
461/* ------------------ Begin pc_close ------------------------- */
462static void pc_close(struct tty_struct * tty, struct file * filp)
f2cf8e25 463{
1da177e4
LT
464 struct channel *ch;
465 unsigned long flags;
1da177e4
LT
466 /* ---------------------------------------------------------
467 verifyChannel returns the channel from the tty struct
468 if it is valid. This serves as a sanity check.
469 ------------------------------------------------------------- */
f2cf8e25
AC
470 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
471 spin_lock_irqsave(&epca_lock, flags);
472 if (tty_hung_up_p(filp)) {
473 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
474 return;
475 }
1da177e4 476 /* Check to see if the channel is open more than once */
f2cf8e25
AC
477 if (ch->count-- > 1) {
478 /* Begin channel is open more than once */
1da177e4
LT
479 /* -------------------------------------------------------------
480 Return without doing anything. Someone might still be using
481 the channel.
482 ---------------------------------------------------------------- */
f2cf8e25 483 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
484 return;
485 } /* End channel is open more than once */
486
487 /* Port open only once go ahead with shutdown & reset */
56ee4827 488 BUG_ON(ch->count < 0);
1da177e4
LT
489
490 /* ---------------------------------------------------------------
491 Let the rest of the driver know the channel is being closed.
492 This becomes important if an open is attempted before close
493 is finished.
494 ------------------------------------------------------------------ */
1da177e4 495 ch->asyncflags |= ASYNC_CLOSING;
1da177e4
LT
496 tty->closing = 1;
497
f2cf8e25
AC
498 spin_unlock_irqrestore(&epca_lock, flags);
499
500 if (ch->asyncflags & ASYNC_INITIALIZED) {
1da177e4
LT
501 /* Setup an event to indicate when the transmit buffer empties */
502 setup_empty_event(tty, ch);
503 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
504 }
1da177e4
LT
505 if (tty->driver->flush_buffer)
506 tty->driver->flush_buffer(tty);
507
508 tty_ldisc_flush(tty);
509 shutdown(ch);
f2cf8e25
AC
510
511 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
512 tty->closing = 0;
513 ch->event = 0;
514 ch->tty = NULL;
f2cf8e25 515 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 516
f2cf8e25 517 if (ch->blocked_open) { /* Begin if blocked_open */
1da177e4 518 if (ch->close_delay)
1da177e4 519 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
1da177e4 520 wake_up_interruptible(&ch->open_wait);
1da177e4 521 } /* End if blocked_open */
1da177e4
LT
522 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
523 ASYNC_CLOSING);
524 wake_up_interruptible(&ch->close_wait);
1da177e4 525 } /* End if ch != NULL */
1da177e4
LT
526} /* End pc_close */
527
528/* ------------------ Begin shutdown ------------------------- */
529
530static void shutdown(struct channel *ch)
531{ /* Begin shutdown */
532
533 unsigned long flags;
534 struct tty_struct *tty;
bc9a5154 535 struct board_chan __iomem *bc;
1da177e4
LT
536
537 if (!(ch->asyncflags & ASYNC_INITIALIZED))
538 return;
539
f2cf8e25 540 spin_lock_irqsave(&epca_lock, flags);
1da177e4 541
f2cf8e25 542 globalwinon(ch);
1da177e4
LT
543 bc = ch->brdchan;
544
545 /* ------------------------------------------------------------------
546 In order for an event to be generated on the receipt of data the
547 idata flag must be set. Since we are shutting down, this is not
548 necessary clear this flag.
549 --------------------------------------------------------------------- */
550
551 if (bc)
f2cf8e25 552 writeb(0, &bc->idata);
1da177e4
LT
553 tty = ch->tty;
554
555 /* ----------------------------------------------------------------
556 If we're a modem control device and HUPCL is on, drop RTS & DTR.
557 ------------------------------------------------------------------ */
558
f2cf8e25 559 if (tty->termios->c_cflag & HUPCL) {
1da177e4
LT
560 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
561 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
562 }
1da177e4
LT
563 memoff(ch);
564
565 /* ------------------------------------------------------------------
566 The channel has officialy been closed. The next time it is opened
567 it will have to reinitialized. Set a flag to indicate this.
568 ---------------------------------------------------------------------- */
569
570 /* Prevent future Digi programmed interrupts from coming active */
571
572 ch->asyncflags &= ~ASYNC_INITIALIZED;
f2cf8e25 573 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
574
575} /* End shutdown */
576
577/* ------------------ Begin pc_hangup ------------------------- */
578
579static void pc_hangup(struct tty_struct *tty)
580{ /* Begin pc_hangup */
1da177e4
LT
581 struct channel *ch;
582
583 /* ---------------------------------------------------------
584 verifyChannel returns the channel from the tty struct
585 if it is valid. This serves as a sanity check.
586 ------------------------------------------------------------- */
587
f2cf8e25 588 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
1da177e4
LT
589 unsigned long flags;
590
1da177e4
LT
591 if (tty->driver->flush_buffer)
592 tty->driver->flush_buffer(tty);
593 tty_ldisc_flush(tty);
594 shutdown(ch);
595
f2cf8e25 596 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
597 ch->tty = NULL;
598 ch->event = 0;
599 ch->count = 0;
1da177e4 600 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
f2cf8e25 601 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 602 wake_up_interruptible(&ch->open_wait);
1da177e4
LT
603 } /* End if ch != NULL */
604
605} /* End pc_hangup */
606
607/* ------------------ Begin pc_write ------------------------- */
608
609static int pc_write(struct tty_struct * tty,
610 const unsigned char *buf, int bytesAvailable)
611{ /* Begin pc_write */
f2cf8e25
AC
612 unsigned int head, tail;
613 int dataLen;
614 int size;
615 int amountCopied;
1da177e4
LT
616 struct channel *ch;
617 unsigned long flags;
618 int remain;
bc9a5154 619 struct board_chan __iomem *bc;
1da177e4
LT
620
621 /* ----------------------------------------------------------------
622 pc_write is primarily called directly by the kernel routine
623 tty_write (Though it can also be called by put_char) found in
624 tty_io.c. pc_write is passed a line discipline buffer where
625 the data to be written out is stored. The line discipline
626 implementation itself is done at the kernel level and is not
627 brought into the driver.
628 ------------------------------------------------------------------- */
629
630 /* ---------------------------------------------------------
631 verifyChannel returns the channel from the tty struct
632 if it is valid. This serves as a sanity check.
633 ------------------------------------------------------------- */
634
635 if ((ch = verifyChannel(tty)) == NULL)
636 return 0;
637
638 /* Make a pointer to the channel data structure found on the board. */
639
640 bc = ch->brdchan;
641 size = ch->txbufsize;
1da177e4 642 amountCopied = 0;
1da177e4 643
f2cf8e25 644 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
645 globalwinon(ch);
646
f2cf8e25
AC
647 head = readw(&bc->tin) & (size - 1);
648 tail = readw(&bc->tout);
1da177e4 649
f2cf8e25
AC
650 if (tail != readw(&bc->tout))
651 tail = readw(&bc->tout);
1da177e4
LT
652 tail &= (size - 1);
653
654 /* If head >= tail, head has not wrapped around. */
f2cf8e25 655 if (head >= tail) { /* Begin head has not wrapped */
1da177e4
LT
656 /* ---------------------------------------------------------------
657 remain (much like dataLen above) represents the total amount of
658 space available on the card for data. Here dataLen represents
659 the space existing between the head pointer and the end of
660 buffer. This is important because a memcpy cannot be told to
661 automatically wrap around when it hits the buffer end.
662 ------------------------------------------------------------------ */
1da177e4
LT
663 dataLen = size - head;
664 remain = size - (head - tail) - 1;
f2cf8e25 665 } else { /* Begin head has wrapped around */
1da177e4
LT
666
667 remain = tail - head - 1;
668 dataLen = remain;
669
670 } /* End head has wrapped around */
1da177e4
LT
671 /* -------------------------------------------------------------------
672 Check the space on the card. If we have more data than
673 space; reduce the amount of data to fit the space.
674 ---------------------------------------------------------------------- */
1da177e4 675 bytesAvailable = min(remain, bytesAvailable);
1da177e4
LT
676 txwinon(ch);
677 while (bytesAvailable > 0)
678 { /* Begin while there is data to copy onto card */
679
680 /* -----------------------------------------------------------------
681 If head is not wrapped, the below will make sure the first
682 data copy fills to the end of card buffer.
683 ------------------------------------------------------------------- */
684
685 dataLen = min(bytesAvailable, dataLen);
bc9a5154 686 memcpy_toio(ch->txptr + head, buf, dataLen);
1da177e4
LT
687 buf += dataLen;
688 head += dataLen;
689 amountCopied += dataLen;
690 bytesAvailable -= dataLen;
691
f2cf8e25 692 if (head >= size) {
1da177e4
LT
693 head = 0;
694 dataLen = tail;
695 }
1da177e4 696 } /* End while there is data to copy onto card */
1da177e4
LT
697 ch->statusflags |= TXBUSY;
698 globalwinon(ch);
f2cf8e25 699 writew(head, &bc->tin);
1da177e4 700
f2cf8e25 701 if ((ch->statusflags & LOWWAIT) == 0) {
1da177e4 702 ch->statusflags |= LOWWAIT;
f2cf8e25 703 writeb(1, &bc->ilow);
1da177e4
LT
704 }
705 memoff(ch);
f2cf8e25 706 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
707 return(amountCopied);
708
709} /* End pc_write */
710
711/* ------------------ Begin pc_put_char ------------------------- */
712
713static void pc_put_char(struct tty_struct *tty, unsigned char c)
714{ /* Begin pc_put_char */
1da177e4 715 pc_write(tty, &c, 1);
1da177e4
LT
716} /* End pc_put_char */
717
718/* ------------------ Begin pc_write_room ------------------------- */
719
720static int pc_write_room(struct tty_struct *tty)
721{ /* Begin pc_write_room */
722
723 int remain;
724 struct channel *ch;
725 unsigned long flags;
726 unsigned int head, tail;
bc9a5154 727 struct board_chan __iomem *bc;
1da177e4
LT
728
729 remain = 0;
730
731 /* ---------------------------------------------------------
732 verifyChannel returns the channel from the tty struct
733 if it is valid. This serves as a sanity check.
734 ------------------------------------------------------------- */
735
f2cf8e25
AC
736 if ((ch = verifyChannel(tty)) != NULL) {
737 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
738 globalwinon(ch);
739
740 bc = ch->brdchan;
f2cf8e25
AC
741 head = readw(&bc->tin) & (ch->txbufsize - 1);
742 tail = readw(&bc->tout);
1da177e4 743
f2cf8e25
AC
744 if (tail != readw(&bc->tout))
745 tail = readw(&bc->tout);
1da177e4
LT
746 /* Wrap tail if necessary */
747 tail &= (ch->txbufsize - 1);
748
749 if ((remain = tail - head - 1) < 0 )
750 remain += ch->txbufsize;
751
f2cf8e25 752 if (remain && (ch->statusflags & LOWWAIT) == 0) {
1da177e4 753 ch->statusflags |= LOWWAIT;
f2cf8e25 754 writeb(1, &bc->ilow);
1da177e4
LT
755 }
756 memoff(ch);
f2cf8e25 757 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 758 }
1da177e4
LT
759 /* Return how much room is left on card */
760 return remain;
761
762} /* End pc_write_room */
763
764/* ------------------ Begin pc_chars_in_buffer ---------------------- */
765
766static int pc_chars_in_buffer(struct tty_struct *tty)
767{ /* Begin pc_chars_in_buffer */
768
769 int chars;
770 unsigned int ctail, head, tail;
771 int remain;
772 unsigned long flags;
773 struct channel *ch;
bc9a5154 774 struct board_chan __iomem *bc;
1da177e4
LT
775
776 /* ---------------------------------------------------------
777 verifyChannel returns the channel from the tty struct
778 if it is valid. This serves as a sanity check.
779 ------------------------------------------------------------- */
780
781 if ((ch = verifyChannel(tty)) == NULL)
782 return(0);
783
f2cf8e25 784 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
785 globalwinon(ch);
786
787 bc = ch->brdchan;
f2cf8e25
AC
788 tail = readw(&bc->tout);
789 head = readw(&bc->tin);
790 ctail = readw(&ch->mailbox->cout);
1da177e4 791
f2cf8e25 792 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
1da177e4 793 chars = 0;
f2cf8e25
AC
794 else { /* Begin if some space on the card has been used */
795 head = readw(&bc->tin) & (ch->txbufsize - 1);
1da177e4 796 tail &= (ch->txbufsize - 1);
1da177e4
LT
797 /* --------------------------------------------------------------
798 The logic here is basically opposite of the above pc_write_room
799 here we are finding the amount of bytes in the buffer filled.
800 Not the amount of bytes empty.
801 ------------------------------------------------------------------- */
1da177e4
LT
802 if ((remain = tail - head - 1) < 0 )
803 remain += ch->txbufsize;
1da177e4 804 chars = (int)(ch->txbufsize - remain);
1da177e4
LT
805 /* -------------------------------------------------------------
806 Make it possible to wakeup anything waiting for output
807 in tty_ioctl.c, etc.
808
809 If not already set. Setup an event to indicate when the
810 transmit buffer empties
811 ----------------------------------------------------------------- */
1da177e4
LT
812 if (!(ch->statusflags & EMPTYWAIT))
813 setup_empty_event(tty,ch);
814
815 } /* End if some space on the card has been used */
1da177e4 816 memoff(ch);
f2cf8e25 817 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
818 /* Return number of characters residing on card. */
819 return(chars);
820
821} /* End pc_chars_in_buffer */
822
823/* ------------------ Begin pc_flush_buffer ---------------------- */
824
825static void pc_flush_buffer(struct tty_struct *tty)
826{ /* Begin pc_flush_buffer */
827
828 unsigned int tail;
829 unsigned long flags;
830 struct channel *ch;
bc9a5154 831 struct board_chan __iomem *bc;
1da177e4
LT
832 /* ---------------------------------------------------------
833 verifyChannel returns the channel from the tty struct
834 if it is valid. This serves as a sanity check.
835 ------------------------------------------------------------- */
1da177e4
LT
836 if ((ch = verifyChannel(tty)) == NULL)
837 return;
838
f2cf8e25 839 spin_lock_irqsave(&epca_lock, flags);
1da177e4 840 globalwinon(ch);
1da177e4 841 bc = ch->brdchan;
f2cf8e25 842 tail = readw(&bc->tout);
1da177e4 843 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1da177e4 844 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1da177e4 845 memoff(ch);
f2cf8e25 846 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
847 wake_up_interruptible(&tty->write_wait);
848 tty_wakeup(tty);
1da177e4
LT
849} /* End pc_flush_buffer */
850
851/* ------------------ Begin pc_flush_chars ---------------------- */
852
853static void pc_flush_chars(struct tty_struct *tty)
854{ /* Begin pc_flush_chars */
1da177e4 855 struct channel * ch;
1da177e4
LT
856 /* ---------------------------------------------------------
857 verifyChannel returns the channel from the tty struct
858 if it is valid. This serves as a sanity check.
859 ------------------------------------------------------------- */
f2cf8e25 860 if ((ch = verifyChannel(tty)) != NULL) {
1da177e4 861 unsigned long flags;
f2cf8e25 862 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
863 /* ----------------------------------------------------------------
864 If not already set and the transmitter is busy setup an event
865 to indicate when the transmit empties.
866 ------------------------------------------------------------------- */
1da177e4
LT
867 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
868 setup_empty_event(tty,ch);
f2cf8e25 869 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 870 }
1da177e4
LT
871} /* End pc_flush_chars */
872
873/* ------------------ Begin block_til_ready ---------------------- */
874
875static int block_til_ready(struct tty_struct *tty,
876 struct file *filp, struct channel *ch)
877{ /* Begin block_til_ready */
1da177e4
LT
878 DECLARE_WAITQUEUE(wait,current);
879 int retval, do_clocal = 0;
880 unsigned long flags;
881
f2cf8e25 882 if (tty_hung_up_p(filp)) {
1da177e4
LT
883 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
884 retval = -EAGAIN;
885 else
886 retval = -ERESTARTSYS;
887 return(retval);
888 }
889
890 /* -----------------------------------------------------------------
891 If the device is in the middle of being closed, then block
892 until it's done, and then try again.
893 -------------------------------------------------------------------- */
f2cf8e25 894 if (ch->asyncflags & ASYNC_CLOSING) {
1da177e4
LT
895 interruptible_sleep_on(&ch->close_wait);
896
897 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
898 return -EAGAIN;
899 else
900 return -ERESTARTSYS;
901 }
902
f2cf8e25 903 if (filp->f_flags & O_NONBLOCK) {
1da177e4
LT
904 /* -----------------------------------------------------------------
905 If non-blocking mode is set, then make the check up front
906 and then exit.
907 -------------------------------------------------------------------- */
1da177e4 908 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1da177e4
LT
909 return 0;
910 }
1da177e4
LT
911 if (tty->termios->c_cflag & CLOCAL)
912 do_clocal = 1;
f2cf8e25 913 /* Block waiting for the carrier detect and the line to become free */
1da177e4
LT
914
915 retval = 0;
916 add_wait_queue(&ch->open_wait, &wait);
1da177e4 917
f2cf8e25 918 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
919 /* We dec count so that pc_close will know when to free things */
920 if (!tty_hung_up_p(filp))
921 ch->count--;
1da177e4 922 ch->blocked_open++;
1da177e4
LT
923 while(1)
924 { /* Begin forever while */
1da177e4 925 set_current_state(TASK_INTERRUPTIBLE);
1da177e4
LT
926 if (tty_hung_up_p(filp) ||
927 !(ch->asyncflags & ASYNC_INITIALIZED))
928 {
929 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
930 retval = -EAGAIN;
931 else
932 retval = -ERESTARTSYS;
933 break;
934 }
1da177e4
LT
935 if (!(ch->asyncflags & ASYNC_CLOSING) &&
936 (do_clocal || (ch->imodem & ch->dcd)))
937 break;
f2cf8e25 938 if (signal_pending(current)) {
1da177e4
LT
939 retval = -ERESTARTSYS;
940 break;
941 }
f2cf8e25 942 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
943 /* ---------------------------------------------------------------
944 Allow someone else to be scheduled. We will occasionally go
945 through this loop until one of the above conditions change.
946 The below schedule call will allow other processes to enter and
947 prevent this loop from hogging the cpu.
948 ------------------------------------------------------------------ */
949 schedule();
f2cf8e25 950 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
951
952 } /* End forever while */
953
954 current->state = TASK_RUNNING;
955 remove_wait_queue(&ch->open_wait, &wait);
1da177e4
LT
956 if (!tty_hung_up_p(filp))
957 ch->count++;
1da177e4
LT
958 ch->blocked_open--;
959
f2cf8e25
AC
960 spin_unlock_irqrestore(&epca_lock, flags);
961
1da177e4
LT
962 if (retval)
963 return retval;
964
965 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1da177e4 966 return 0;
1da177e4
LT
967} /* End block_til_ready */
968
969/* ------------------ Begin pc_open ---------------------- */
970
971static int pc_open(struct tty_struct *tty, struct file * filp)
972{ /* Begin pc_open */
973
974 struct channel *ch;
975 unsigned long flags;
976 int line, retval, boardnum;
bc9a5154 977 struct board_chan __iomem *bc;
f2cf8e25 978 unsigned int head;
1da177e4
LT
979
980 line = tty->index;
f2cf8e25
AC
981 if (line < 0 || line >= nbdevs)
982 return -ENODEV;
1da177e4
LT
983
984 ch = &digi_channels[line];
985 boardnum = ch->boardnum;
986
987 /* Check status of board configured in system. */
988
989 /* -----------------------------------------------------------------
990 I check to see if the epca_setup routine detected an user error.
991 It might be better to put this in pc_init, but for the moment it
992 goes here.
993 ---------------------------------------------------------------------- */
994
f2cf8e25 995 if (invalid_lilo_config) {
1da177e4 996 if (setup_error_code & INVALID_BOARD_TYPE)
f2cf8e25 997 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
1da177e4 998 if (setup_error_code & INVALID_NUM_PORTS)
f2cf8e25 999 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
1da177e4 1000 if (setup_error_code & INVALID_MEM_BASE)
f2cf8e25 1001 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
1da177e4 1002 if (setup_error_code & INVALID_PORT_BASE)
f2cf8e25 1003 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
1da177e4 1004 if (setup_error_code & INVALID_BOARD_STATUS)
f2cf8e25 1005 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
1da177e4 1006 if (setup_error_code & INVALID_ALTPIN)
f2cf8e25 1007 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
1da177e4 1008 tty->driver_data = NULL; /* Mark this device as 'down' */
f2cf8e25 1009 return -ENODEV;
1da177e4 1010 }
f2cf8e25 1011 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
1da177e4
LT
1012 tty->driver_data = NULL; /* Mark this device as 'down' */
1013 return(-ENODEV);
1014 }
1015
f2cf8e25 1016 if ((bc = ch->brdchan) == 0) {
1da177e4 1017 tty->driver_data = NULL;
f2cf8e25 1018 return -ENODEV;
1da177e4
LT
1019 }
1020
f2cf8e25 1021 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
1022 /* ------------------------------------------------------------------
1023 Every time a channel is opened, increment a counter. This is
1024 necessary because we do not wish to flush and shutdown the channel
1025 until the last app holding the channel open, closes it.
1026 --------------------------------------------------------------------- */
1da177e4 1027 ch->count++;
1da177e4
LT
1028 /* ----------------------------------------------------------------
1029 Set a kernel structures pointer to our local channel
1030 structure. This way we can get to it when passed only
1031 a tty struct.
1032 ------------------------------------------------------------------ */
1da177e4 1033 tty->driver_data = ch;
1da177e4
LT
1034 /* ----------------------------------------------------------------
1035 If this is the first time the channel has been opened, initialize
1036 the tty->termios struct otherwise let pc_close handle it.
1037 -------------------------------------------------------------------- */
1da177e4
LT
1038 globalwinon(ch);
1039 ch->statusflags = 0;
1040
1041 /* Save boards current modem status */
bc9a5154 1042 ch->imodem = readb(&bc->mstat);
1da177e4
LT
1043
1044 /* ----------------------------------------------------------------
1045 Set receive head and tail ptrs to each other. This indicates
1046 no data available to read.
1047 ----------------------------------------------------------------- */
f2cf8e25
AC
1048 head = readw(&bc->rin);
1049 writew(head, &bc->rout);
1da177e4
LT
1050
1051 /* Set the channels associated tty structure */
1052 ch->tty = tty;
1053
1054 /* -----------------------------------------------------------------
1055 The below routine generally sets up parity, baud, flow control
1056 issues, etc.... It effect both control flags and input flags.
1057 -------------------------------------------------------------------- */
1058 epcaparam(tty,ch);
1da177e4
LT
1059 ch->asyncflags |= ASYNC_INITIALIZED;
1060 memoff(ch);
f2cf8e25 1061 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
1062
1063 retval = block_til_ready(tty, filp, ch);
1064 if (retval)
1da177e4 1065 return retval;
1da177e4
LT
1066 /* -------------------------------------------------------------
1067 Set this again in case a hangup set it to zero while this
1068 open() was waiting for the line...
1069 --------------------------------------------------------------- */
f2cf8e25 1070 spin_lock_irqsave(&epca_lock, flags);
1da177e4 1071 ch->tty = tty;
1da177e4 1072 globalwinon(ch);
1da177e4 1073 /* Enable Digi Data events */
f2cf8e25 1074 writeb(1, &bc->idata);
1da177e4 1075 memoff(ch);
f2cf8e25 1076 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 1077 return 0;
1da177e4
LT
1078} /* End pc_open */
1079
1da177e4
LT
1080static int __init epca_module_init(void)
1081{ /* Begin init_module */
f2cf8e25 1082 return pc_init();
1da177e4
LT
1083}
1084
1085module_init(epca_module_init);
1da177e4 1086
1da177e4 1087static struct pci_driver epca_driver;
1da177e4
LT
1088
1089static void __exit epca_module_exit(void)
1090{
1da177e4
LT
1091 int count, crd;
1092 struct board_info *bd;
1093 struct channel *ch;
1da177e4
LT
1094
1095 del_timer_sync(&epca_timer);
1096
1da177e4
LT
1097 if ((tty_unregister_driver(pc_driver)) ||
1098 (tty_unregister_driver(pc_info)))
1099 {
f2cf8e25 1100 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1da177e4
LT
1101 return;
1102 }
1103 put_tty_driver(pc_driver);
1104 put_tty_driver(pc_info);
1105
f2cf8e25 1106 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
1da177e4 1107 bd = &boards[crd];
1da177e4
LT
1108 if (!bd)
1109 { /* Begin sanity check */
1110 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1111 return;
1112 } /* End sanity check */
f2cf8e25 1113 ch = card_ptr[crd];
1da177e4
LT
1114 for (count = 0; count < bd->numports; count++, ch++)
1115 { /* Begin for each port */
b3218a79
JS
1116 if (ch && ch->tty)
1117 tty_hangup(ch->tty);
1da177e4
LT
1118 } /* End for each port */
1119 } /* End for each card */
1da177e4 1120 pci_unregister_driver (&epca_driver);
1da177e4 1121}
f2cf8e25 1122
1da177e4 1123module_exit(epca_module_exit);
1da177e4 1124
b68e31d0 1125static const struct tty_operations pc_ops = {
1da177e4
LT
1126 .open = pc_open,
1127 .close = pc_close,
1128 .write = pc_write,
1129 .write_room = pc_write_room,
1130 .flush_buffer = pc_flush_buffer,
1131 .chars_in_buffer = pc_chars_in_buffer,
1132 .flush_chars = pc_flush_chars,
1133 .put_char = pc_put_char,
1134 .ioctl = pc_ioctl,
1135 .set_termios = pc_set_termios,
1136 .stop = pc_stop,
1137 .start = pc_start,
1138 .throttle = pc_throttle,
1139 .unthrottle = pc_unthrottle,
1140 .hangup = pc_hangup,
1141};
1142
1143static int info_open(struct tty_struct *tty, struct file * filp)
1144{
1145 return 0;
1146}
1147
1148static struct tty_operations info_ops = {
1149 .open = info_open,
1150 .ioctl = info_ioctl,
1151};
1152
1153/* ------------------ Begin pc_init ---------------------- */
1154
f2cf8e25 1155static int __init pc_init(void)
1da177e4 1156{ /* Begin pc_init */
1da177e4
LT
1157 int crd;
1158 struct board_info *bd;
1159 unsigned char board_id = 0;
dabad056 1160 int err = -ENOMEM;
1da177e4 1161
1da177e4
LT
1162 int pci_boards_found, pci_count;
1163
1164 pci_count = 0;
1da177e4
LT
1165
1166 pc_driver = alloc_tty_driver(MAX_ALLOC);
1167 if (!pc_driver)
dabad056 1168 goto out1;
1da177e4
LT
1169
1170 pc_info = alloc_tty_driver(MAX_ALLOC);
dabad056
AM
1171 if (!pc_info)
1172 goto out2;
1da177e4
LT
1173
1174 /* -----------------------------------------------------------------------
1175 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1176 board structure defined by digiConfig into drivers board structure.
1177 Note : If LILO has ran epca_setup then epca_setup will handle defining
1178 num_cards as well as copying the data into the board structure.
1179 -------------------------------------------------------------------------- */
f2cf8e25 1180 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
1da177e4
LT
1181
1182 nbdevs = NBDEVS;
1183 num_cards = NUMCARDS;
1184 memcpy((void *)&boards, (void *)&static_boards,
1185 (sizeof(struct board_info) * NUMCARDS));
1186 } /* End driver has been configured via. epcaconfig */
1187
1188 /* -----------------------------------------------------------------
1189 Note : If lilo was used to configure the driver and the
1190 ignore epcaconfig option was choosen (digiepca=2) then
1191 nbdevs and num_cards will equal 0 at this point. This is
1192 okay; PCI cards will still be picked up if detected.
1193 --------------------------------------------------------------------- */
1194
1195 /* -----------------------------------------------------------
1196 Set up interrupt, we will worry about memory allocation in
1197 post_fep_init.
1198 --------------------------------------------------------------- */
1199
1200
1201 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1202
1da177e4
LT
1203 /* ------------------------------------------------------------------
1204 NOTE : This code assumes that the number of ports found in
1205 the boards array is correct. This could be wrong if
1206 the card in question is PCI (And therefore has no ports
1207 entry in the boards structure.) The rest of the
1208 information will be valid for PCI because the beginning
1209 of pc_init scans for PCI and determines i/o and base
1210 memory addresses. I am not sure if it is possible to
1211 read the number of ports supported by the card prior to
1212 it being booted (Since that is the state it is in when
1213 pc_init is run). Because it is not possible to query the
1214 number of supported ports until after the card has booted;
1215 we are required to calculate the card_ptrs as the card is
1216 is initialized (Inside post_fep_init). The negative thing
1217 about this approach is that digiDload's call to GET_INFO
1218 will have a bad port value. (Since this is called prior
1219 to post_fep_init.)
1220
1221 --------------------------------------------------------------------- */
1222
1223 pci_boards_found = 0;
1224 if(num_cards < MAXBOARDS)
1225 pci_boards_found += init_PCI();
1226 num_cards += pci_boards_found;
1227
1da177e4
LT
1228 pc_driver->owner = THIS_MODULE;
1229 pc_driver->name = "ttyD";
1da177e4
LT
1230 pc_driver->major = DIGI_MAJOR;
1231 pc_driver->minor_start = 0;
1232 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1233 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1234 pc_driver->init_termios = tty_std_termios;
1235 pc_driver->init_termios.c_iflag = 0;
1236 pc_driver->init_termios.c_oflag = 0;
1237 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1238 pc_driver->init_termios.c_lflag = 0;
606d099c
AC
1239 pc_driver->init_termios.c_ispeed = 9600;
1240 pc_driver->init_termios.c_ospeed = 9600;
1da177e4
LT
1241 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1242 tty_set_operations(pc_driver, &pc_ops);
1243
1244 pc_info->owner = THIS_MODULE;
1245 pc_info->name = "digi_ctl";
1246 pc_info->major = DIGIINFOMAJOR;
1247 pc_info->minor_start = 0;
1248 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1249 pc_info->subtype = SERIAL_TYPE_INFO;
1250 pc_info->init_termios = tty_std_termios;
1251 pc_info->init_termios.c_iflag = 0;
1252 pc_info->init_termios.c_oflag = 0;
1253 pc_info->init_termios.c_lflag = 0;
1254 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
606d099c
AC
1255 pc_info->init_termios.c_ispeed = 9600;
1256 pc_info->init_termios.c_ospeed = 9600;
1da177e4
LT
1257 pc_info->flags = TTY_DRIVER_REAL_RAW;
1258 tty_set_operations(pc_info, &info_ops);
1259
1260
1da177e4
LT
1261 for (crd = 0; crd < num_cards; crd++)
1262 { /* Begin for each card */
1263
1264 /* ------------------------------------------------------------------
1265 This is where the appropriate memory handlers for the hardware is
1266 set. Everything at runtime blindly jumps through these vectors.
1267 ---------------------------------------------------------------------- */
1268
1269 /* defined in epcaconfig.h */
1270 bd = &boards[crd];
1271
1272 switch (bd->type)
1273 { /* Begin switch on bd->type {board type} */
1274 case PCXEM:
1275 case EISAXEM:
1276 bd->memwinon = pcxem_memwinon ;
1277 bd->memwinoff = pcxem_memwinoff ;
1278 bd->globalwinon = pcxem_globalwinon ;
1279 bd->txwinon = pcxem_txwinon ;
1280 bd->rxwinon = pcxem_rxwinon ;
1281 bd->memoff = pcxem_memoff ;
1282 bd->assertgwinon = dummy_assertgwinon;
1283 bd->assertmemoff = dummy_assertmemoff;
1284 break;
1285
1286 case PCIXEM:
1287 case PCIXRJ:
1288 case PCIXR:
1289 bd->memwinon = dummy_memwinon;
1290 bd->memwinoff = dummy_memwinoff;
1291 bd->globalwinon = dummy_globalwinon;
1292 bd->txwinon = dummy_txwinon;
1293 bd->rxwinon = dummy_rxwinon;
1294 bd->memoff = dummy_memoff;
1295 bd->assertgwinon = dummy_assertgwinon;
1296 bd->assertmemoff = dummy_assertmemoff;
1297 break;
1298
1299 case PCXE:
1300 case PCXEVE:
1301
1302 bd->memwinon = pcxe_memwinon;
1303 bd->memwinoff = pcxe_memwinoff;
1304 bd->globalwinon = pcxe_globalwinon;
1305 bd->txwinon = pcxe_txwinon;
1306 bd->rxwinon = pcxe_rxwinon;
1307 bd->memoff = pcxe_memoff;
1308 bd->assertgwinon = dummy_assertgwinon;
1309 bd->assertmemoff = dummy_assertmemoff;
1310 break;
1311
1312 case PCXI:
1313 case PC64XE:
1314
1315 bd->memwinon = pcxi_memwinon;
1316 bd->memwinoff = pcxi_memwinoff;
1317 bd->globalwinon = pcxi_globalwinon;
1318 bd->txwinon = pcxi_txwinon;
1319 bd->rxwinon = pcxi_rxwinon;
1320 bd->memoff = pcxi_memoff;
1321 bd->assertgwinon = pcxi_assertgwinon;
1322 bd->assertmemoff = pcxi_assertmemoff;
1323 break;
1324
1325 default:
1326 break;
1327
1328 } /* End switch on bd->type */
1329
1330 /* ---------------------------------------------------------------
1331 Some cards need a memory segment to be defined for use in
1332 transmit and receive windowing operations. These boards
1333 are listed in the below switch. In the case of the XI the
1334 amount of memory on the board is variable so the memory_seg
1335 is also variable. This code determines what they segment
1336 should be.
1337 ----------------------------------------------------------------- */
1338
1339 switch (bd->type)
1340 { /* Begin switch on bd->type {board type} */
1341
1342 case PCXE:
1343 case PCXEVE:
1344 case PC64XE:
1345 bd->memory_seg = 0xf000;
1346 break;
1347
1348 case PCXI:
1349 board_id = inb((int)bd->port);
1350 if ((board_id & 0x1) == 0x1)
1351 { /* Begin it's an XI card */
1352
1353 /* Is it a 64K board */
1354 if ((board_id & 0x30) == 0)
1355 bd->memory_seg = 0xf000;
1356
1357 /* Is it a 128K board */
1358 if ((board_id & 0x30) == 0x10)
1359 bd->memory_seg = 0xe000;
1360
1361 /* Is is a 256K board */
1362 if ((board_id & 0x30) == 0x20)
1363 bd->memory_seg = 0xc000;
1364
1365 /* Is it a 512K board */
1366 if ((board_id & 0x30) == 0x30)
1367 bd->memory_seg = 0x8000;
1368
f2cf8e25 1369 } else printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1da177e4
LT
1370 break;
1371
1372 } /* End switch on bd->type */
1373
1374 } /* End for each card */
1375
dabad056
AM
1376 err = tty_register_driver(pc_driver);
1377 if (err) {
1378 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1379 goto out3;
1380 }
1da177e4 1381
dabad056
AM
1382 err = tty_register_driver(pc_info);
1383 if (err) {
1384 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1385 goto out4;
1386 }
1da177e4
LT
1387
1388 /* -------------------------------------------------------------------
1389 Start up the poller to check for events on all enabled boards
1390 ---------------------------------------------------------------------- */
1391
1392 init_timer(&epca_timer);
1393 epca_timer.function = epcapoll;
1394 mod_timer(&epca_timer, jiffies + HZ/25);
1da177e4
LT
1395 return 0;
1396
dabad056
AM
1397out4:
1398 tty_unregister_driver(pc_driver);
1399out3:
1400 put_tty_driver(pc_info);
1401out2:
1402 put_tty_driver(pc_driver);
1403out1:
1404 return err;
1405
1da177e4
LT
1406} /* End pc_init */
1407
1408/* ------------------ Begin post_fep_init ---------------------- */
1409
1410static void post_fep_init(unsigned int crd)
1411{ /* Begin post_fep_init */
1412
1413 int i;
bc9a5154
AV
1414 void __iomem *memaddr;
1415 struct global_data __iomem *gd;
1da177e4 1416 struct board_info *bd;
bc9a5154 1417 struct board_chan __iomem *bc;
1da177e4
LT
1418 struct channel *ch;
1419 int shrinkmem = 0, lowwater ;
1420
1421 /* -------------------------------------------------------------
1422 This call is made by the user via. the ioctl call DIGI_INIT.
1423 It is responsible for setting up all the card specific stuff.
1424 ---------------------------------------------------------------- */
1425 bd = &boards[crd];
1426
1427 /* -----------------------------------------------------------------
1428 If this is a PCI board, get the port info. Remember PCI cards
1429 do not have entries into the epcaconfig.h file, so we can't get
1430 the number of ports from it. Unfortunetly, this means that anyone
1431 doing a DIGI_GETINFO before the board has booted will get an invalid
1432 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1433 after DIGI_INIT has been called will return the proper values.
1434 ------------------------------------------------------------------- */
1435
f2cf8e25 1436 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1da177e4
LT
1437 /* --------------------------------------------------------------------
1438 Below we use XEMPORTS as a memory offset regardless of which PCI
1439 card it is. This is because all of the supported PCI cards have
1440 the same memory offset for the channel data. This will have to be
1441 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1442 states that the port offset is 0xC22 as opposed to 0xC02. This is
1443 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1444 On the PCI cards the number of ports is determined by reading a
1445 ID PROM located in the box attached to the card. The card can then
1446 determine the index the id to determine the number of ports available.
1447 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1448 if the box in question is a XEM or CX)).
1449 ------------------------------------------------------------------------ */
f2cf8e25
AC
1450 /* PCI cards are already remapped at this point ISA are not */
1451 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1da177e4
LT
1452 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1453 nbdevs += (bd->numports);
f2cf8e25
AC
1454 } else {
1455 /* Fix up the mappings for ISA/EISA etc */
1456 /* FIXME: 64K - can we be smarter ? */
1457 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1458 }
1da177e4
LT
1459
1460 if (crd != 0)
1461 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1462 else
1463 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1464
1465 ch = card_ptr[crd];
1da177e4
LT
1466 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1467
f2cf8e25 1468 memaddr = bd->re_map_membase;
1da177e4
LT
1469
1470 /* -----------------------------------------------------------------
1471 The below assignment will set bc to point at the BEGINING of
1472 the cards channel structures. For 1 card there will be between
1473 8 and 64 of these structures.
1474 -------------------------------------------------------------------- */
1475
bc9a5154 1476 bc = memaddr + CHANSTRUCT;
1da177e4
LT
1477
1478 /* -------------------------------------------------------------------
1479 The below assignment will set gd to point at the BEGINING of
1480 global memory address 0xc00. The first data in that global
1481 memory actually starts at address 0xc1a. The command in
1482 pointer begins at 0xd10.
1483 ---------------------------------------------------------------------- */
1484
bc9a5154 1485 gd = memaddr + GLOBAL;
1da177e4
LT
1486
1487 /* --------------------------------------------------------------------
1488 XEPORTS (address 0xc22) points at the number of channels the
1489 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1490 ----------------------------------------------------------------------- */
1491
f2cf8e25 1492 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
1da177e4
LT
1493 shrinkmem = 1;
1494 if (bd->type < PCIXEM)
1495 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1496 return;
1da177e4
LT
1497 memwinon(bd, 0);
1498
1499 /* --------------------------------------------------------------------
1500 Remember ch is the main drivers channels structure, while bc is
1501 the cards channel structure.
1502 ------------------------------------------------------------------------ */
1503
1504 /* For every port on the card do ..... */
1505
f2cf8e25
AC
1506 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1507 unsigned long flags;
bc9a5154 1508 u16 tseg, rseg;
1da177e4
LT
1509
1510 ch->brdchan = bc;
1511 ch->mailbox = gd;
c4028958 1512 INIT_WORK(&ch->tqueue, do_softint);
1da177e4
LT
1513 ch->board = &boards[crd];
1514
f2cf8e25
AC
1515 spin_lock_irqsave(&epca_lock, flags);
1516 switch (bd->type) {
1da177e4
LT
1517 /* ----------------------------------------------------------------
1518 Since some of the boards use different bitmaps for their
1519 control signals we cannot hard code these values and retain
1520 portability. We virtualize this data here.
1521 ------------------------------------------------------------------- */
1522 case EISAXEM:
1523 case PCXEM:
1524 case PCIXEM:
1525 case PCIXRJ:
1526 case PCIXR:
1527 ch->m_rts = 0x02 ;
1528 ch->m_dcd = 0x80 ;
1529 ch->m_dsr = 0x20 ;
1530 ch->m_cts = 0x10 ;
1531 ch->m_ri = 0x40 ;
1532 ch->m_dtr = 0x01 ;
1533 break;
1534
1535 case PCXE:
1536 case PCXEVE:
1537 case PCXI:
1538 case PC64XE:
1539 ch->m_rts = 0x02 ;
1540 ch->m_dcd = 0x08 ;
1541 ch->m_dsr = 0x10 ;
1542 ch->m_cts = 0x20 ;
1543 ch->m_ri = 0x40 ;
1544 ch->m_dtr = 0x80 ;
1545 break;
1546
1547 } /* End switch bd->type */
1548
f2cf8e25 1549 if (boards[crd].altpin) {
1da177e4
LT
1550 ch->dsr = ch->m_dcd;
1551 ch->dcd = ch->m_dsr;
1552 ch->digiext.digi_flags |= DIGI_ALTPIN;
1553 }
f2cf8e25 1554 else {
1da177e4
LT
1555 ch->dcd = ch->m_dcd;
1556 ch->dsr = ch->m_dsr;
1557 }
1558
1559 ch->boardnum = crd;
1560 ch->channelnum = i;
1561 ch->magic = EPCA_MAGIC;
1562 ch->tty = NULL;
1563
f2cf8e25 1564 if (shrinkmem) {
1da177e4
LT
1565 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1566 shrinkmem = 0;
1567 }
1568
bc9a5154
AV
1569 tseg = readw(&bc->tseg);
1570 rseg = readw(&bc->rseg);
1571
f2cf8e25 1572 switch (bd->type) {
1da177e4
LT
1573
1574 case PCIXEM:
1575 case PCIXRJ:
1576 case PCIXR:
1577 /* Cover all the 2MEG cards */
bc9a5154
AV
1578 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1579 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1580 ch->txwin = FEPWIN | (tseg >> 11);
1581 ch->rxwin = FEPWIN | (rseg >> 11);
1da177e4
LT
1582 break;
1583
1584 case PCXEM:
1585 case EISAXEM:
1586 /* Cover all the 32K windowed cards */
1587 /* Mask equal to window size - 1 */
bc9a5154
AV
1588 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1589 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1590 ch->txwin = FEPWIN | (tseg >> 11);
1591 ch->rxwin = FEPWIN | (rseg >> 11);
1da177e4
LT
1592 break;
1593
1594 case PCXEVE:
1595 case PCXE:
bc9a5154
AV
1596 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1597 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1598 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1599 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
1da177e4
LT
1600 break;
1601
1602 case PCXI:
1603 case PC64XE:
bc9a5154
AV
1604 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1605 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1da177e4
LT
1606 ch->txwin = ch->rxwin = 0;
1607 break;
1608
1609 } /* End switch bd->type */
1610
1611 ch->txbufhead = 0;
bc9a5154 1612 ch->txbufsize = readw(&bc->tmax) + 1;
1da177e4
LT
1613
1614 ch->rxbufhead = 0;
bc9a5154 1615 ch->rxbufsize = readw(&bc->rmax) + 1;
1da177e4
LT
1616
1617 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1618
1619 /* Set transmitter low water mark */
1620 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1621
1622 /* Set receiver low water mark */
1623
1624 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1625
1626 /* Set receiver high water mark */
1627
1628 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1629
f2cf8e25
AC
1630 writew(100, &bc->edelay);
1631 writeb(1, &bc->idata);
1da177e4 1632
f2cf8e25
AC
1633 ch->startc = readb(&bc->startc);
1634 ch->stopc = readb(&bc->stopc);
1635 ch->startca = readb(&bc->startca);
1636 ch->stopca = readb(&bc->stopca);
1da177e4
LT
1637
1638 ch->fepcflag = 0;
1639 ch->fepiflag = 0;
1640 ch->fepoflag = 0;
1641 ch->fepstartc = 0;
1642 ch->fepstopc = 0;
1643 ch->fepstartca = 0;
1644 ch->fepstopca = 0;
1645
1646 ch->close_delay = 50;
1647 ch->count = 0;
1648 ch->blocked_open = 0;
1649 init_waitqueue_head(&ch->open_wait);
1650 init_waitqueue_head(&ch->close_wait);
f2cf8e25
AC
1651
1652 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
1653 } /* End for each port */
1654
1655 printk(KERN_INFO
1656 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1657 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
1da177e4
LT
1658 memwinoff(bd, 0);
1659
1660} /* End post_fep_init */
1661
1662/* --------------------- Begin epcapoll ------------------------ */
1663
1664static void epcapoll(unsigned long ignored)
1665{ /* Begin epcapoll */
1666
1667 unsigned long flags;
1668 int crd;
1669 volatile unsigned int head, tail;
1670 struct channel *ch;
1671 struct board_info *bd;
1672
1673 /* -------------------------------------------------------------------
1674 This routine is called upon every timer interrupt. Even though
1675 the Digi series cards are capable of generating interrupts this
1676 method of non-looping polling is more efficient. This routine
1677 checks for card generated events (Such as receive data, are transmit
1678 buffer empty) and acts on those events.
1679 ----------------------------------------------------------------------- */
1680
1da177e4
LT
1681 for (crd = 0; crd < num_cards; crd++)
1682 { /* Begin for each card */
1683
1684 bd = &boards[crd];
1685 ch = card_ptr[crd];
1686
1687 if ((bd->status == DISABLED) || digi_poller_inhibited)
1688 continue; /* Begin loop next interation */
1689
1690 /* -----------------------------------------------------------
1691 assertmemoff is not needed here; indeed it is an empty subroutine.
1692 It is being kept because future boards may need this as well as
1693 some legacy boards.
1694 ---------------------------------------------------------------- */
1695
f2cf8e25
AC
1696 spin_lock_irqsave(&epca_lock, flags);
1697
1da177e4
LT
1698 assertmemoff(ch);
1699
1700 globalwinon(ch);
1701
1702 /* ---------------------------------------------------------------
1703 In this case head and tail actually refer to the event queue not
1704 the transmit or receive queue.
1705 ------------------------------------------------------------------- */
1706
f2cf8e25
AC
1707 head = readw(&ch->mailbox->ein);
1708 tail = readw(&ch->mailbox->eout);
1da177e4
LT
1709
1710 /* If head isn't equal to tail we have an event */
1711
1712 if (head != tail)
1713 doevent(crd);
1da177e4
LT
1714 memoff(ch);
1715
f2cf8e25 1716 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 1717
f2cf8e25 1718 } /* End for each card */
1da177e4 1719 mod_timer(&epca_timer, jiffies + (HZ / 25));
1da177e4
LT
1720} /* End epcapoll */
1721
1722/* --------------------- Begin doevent ------------------------ */
1723
1724static void doevent(int crd)
1725{ /* Begin doevent */
1726
bc9a5154 1727 void __iomem *eventbuf;
1da177e4
LT
1728 struct channel *ch, *chan0;
1729 static struct tty_struct *tty;
f2cf8e25 1730 struct board_info *bd;
bc9a5154 1731 struct board_chan __iomem *bc;
f2cf8e25
AC
1732 unsigned int tail, head;
1733 int event, channel;
1734 int mstat, lstat;
1da177e4
LT
1735
1736 /* -------------------------------------------------------------------
1737 This subroutine is called by epcapoll when an event is detected
1738 in the event queue. This routine responds to those events.
1739 --------------------------------------------------------------------- */
1da177e4
LT
1740 bd = &boards[crd];
1741
1742 chan0 = card_ptr[crd];
1743 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1da177e4 1744 assertgwinon(chan0);
f2cf8e25 1745 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
1da177e4 1746 { /* Begin while something in event queue */
1da177e4 1747 assertgwinon(chan0);
f2cf8e25 1748 eventbuf = bd->re_map_membase + tail + ISTART;
1da177e4 1749 /* Get the channel the event occurred on */
f2cf8e25 1750 channel = readb(eventbuf);
1da177e4 1751 /* Get the actual event code that occurred */
f2cf8e25 1752 event = readb(eventbuf + 1);
1da177e4
LT
1753 /* ----------------------------------------------------------------
1754 The two assignments below get the current modem status (mstat)
1755 and the previous modem status (lstat). These are useful becuase
1756 an event could signal a change in modem signals itself.
1757 ------------------------------------------------------------------- */
f2cf8e25
AC
1758 mstat = readb(eventbuf + 2);
1759 lstat = readb(eventbuf + 3);
1da177e4
LT
1760
1761 ch = chan0 + channel;
f2cf8e25 1762 if ((unsigned)channel >= bd->numports || !ch) {
1da177e4
LT
1763 if (channel >= bd->numports)
1764 ch = chan0;
1765 bc = ch->brdchan;
1766 goto next;
1767 }
1768
1769 if ((bc = ch->brdchan) == NULL)
1770 goto next;
1771
f2cf8e25 1772 if (event & DATA_IND) { /* Begin DATA_IND */
1da177e4
LT
1773 receive_data(ch);
1774 assertgwinon(ch);
1da177e4
LT
1775 } /* End DATA_IND */
1776 /* else *//* Fix for DCD transition missed bug */
f2cf8e25 1777 if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
1da177e4 1778 /* A modem signal change has been indicated */
1da177e4 1779 ch->imodem = mstat;
f2cf8e25 1780 if (ch->asyncflags & ASYNC_CHECK_CD) {
1da177e4
LT
1781 if (mstat & ch->dcd) /* We are now receiving dcd */
1782 wake_up_interruptible(&ch->open_wait);
1783 else
1784 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
1785 }
1da177e4 1786 } /* End MODEMCHG_IND */
1da177e4 1787 tty = ch->tty;
f2cf8e25
AC
1788 if (tty) { /* Begin if valid tty */
1789 if (event & BREAK_IND) { /* Begin if BREAK_IND */
1da177e4 1790 /* A break has been indicated */
33f0f88f 1791 tty_insert_flip_char(tty, 0, TTY_BREAK);
1da177e4 1792 tty_schedule_flip(tty);
f2cf8e25 1793 } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
1da177e4
LT
1794 if (ch->statusflags & LOWWAIT)
1795 { /* Begin if LOWWAIT */
1da177e4
LT
1796 ch->statusflags &= ~LOWWAIT;
1797 tty_wakeup(tty);
1798 wake_up_interruptible(&tty->write_wait);
1da177e4 1799 } /* End if LOWWAIT */
f2cf8e25 1800 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
1da177e4 1801 /* This event is generated by setup_empty_event */
1da177e4 1802 ch->statusflags &= ~TXBUSY;
f2cf8e25 1803 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
1da177e4
LT
1804 ch->statusflags &= ~EMPTYWAIT;
1805 tty_wakeup(tty);
1da177e4 1806 wake_up_interruptible(&tty->write_wait);
1da177e4 1807 } /* End if EMPTYWAIT */
1da177e4 1808 } /* End EMPTYTX_IND */
1da177e4 1809 } /* End if valid tty */
1da177e4
LT
1810 next:
1811 globalwinon(ch);
f2cf8e25
AC
1812 BUG_ON(!bc);
1813 writew(1, &bc->idata);
1814 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1da177e4 1815 globalwinon(chan0);
1da177e4 1816 } /* End while something in event queue */
1da177e4
LT
1817} /* End doevent */
1818
1819/* --------------------- Begin fepcmd ------------------------ */
1820
1821static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1822 int byte2, int ncmds, int bytecmd)
1823{ /* Begin fepcmd */
bc9a5154 1824 unchar __iomem *memaddr;
1da177e4
LT
1825 unsigned int head, cmdTail, cmdStart, cmdMax;
1826 long count;
1827 int n;
1828
1829 /* This is the routine in which commands may be passed to the card. */
1830
1831 if (ch->board->status == DISABLED)
1da177e4 1832 return;
1da177e4 1833 assertgwinon(ch);
1da177e4 1834 /* Remember head (As well as max) is just an offset not a base addr */
f2cf8e25 1835 head = readw(&ch->mailbox->cin);
1da177e4 1836 /* cmdStart is a base address */
f2cf8e25 1837 cmdStart = readw(&ch->mailbox->cstart);
1da177e4
LT
1838 /* ------------------------------------------------------------------
1839 We do the addition below because we do not want a max pointer
1840 relative to cmdStart. We want a max pointer that points at the
1841 physical end of the command queue.
1842 -------------------------------------------------------------------- */
f2cf8e25 1843 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1da177e4
LT
1844 memaddr = ch->board->re_map_membase;
1845
f2cf8e25
AC
1846 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1847 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
1848 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
1da177e4
LT
1849 return;
1850 }
f2cf8e25
AC
1851 if (bytecmd) {
1852 writeb(cmd, memaddr + head + cmdStart + 0);
1853 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1da177e4 1854 /* Below word_or_byte is bits to set */
f2cf8e25 1855 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1da177e4 1856 /* Below byte2 is bits to reset */
f2cf8e25
AC
1857 writeb(byte2, memaddr + head + cmdStart + 3);
1858 } else {
1859 writeb(cmd, memaddr + head + cmdStart + 0);
1860 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1861 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1da177e4 1862 }
1da177e4 1863 head = (head + 4) & (cmdMax - cmdStart - 4);
f2cf8e25 1864 writew(head, &ch->mailbox->cin);
1da177e4
LT
1865 count = FEPTIMEOUT;
1866
f2cf8e25 1867 for (;;) { /* Begin forever loop */
1da177e4 1868 count--;
f2cf8e25 1869 if (count == 0) {
1da177e4
LT
1870 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1871 return;
1872 }
f2cf8e25
AC
1873 head = readw(&ch->mailbox->cin);
1874 cmdTail = readw(&ch->mailbox->cout);
1da177e4 1875 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1da177e4
LT
1876 /* ----------------------------------------------------------
1877 Basically this will break when the FEP acknowledges the
1878 command by incrementing cmdTail (Making it equal to head).
1879 ------------------------------------------------------------- */
1da177e4
LT
1880 if (n <= ncmds * (sizeof(short) * 4))
1881 break; /* Well nearly forever :-) */
1da177e4 1882 } /* End forever loop */
1da177e4
LT
1883} /* End fepcmd */
1884
1885/* ---------------------------------------------------------------------
1886 Digi products use fields in their channels structures that are very
1887 similar to the c_cflag and c_iflag fields typically found in UNIX
1888 termios structures. The below three routines allow mappings
1889 between these hardware "flags" and their respective Linux flags.
1890------------------------------------------------------------------------- */
1891
1892/* --------------------- Begin termios2digi_h -------------------- */
1893
1894static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1895{ /* Begin termios2digi_h */
1da177e4
LT
1896 unsigned res = 0;
1897
f2cf8e25 1898 if (cflag & CRTSCTS) {
1da177e4
LT
1899 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1900 res |= ((ch->m_cts) | (ch->m_rts));
1901 }
1902
1903 if (ch->digiext.digi_flags & RTSPACE)
1904 res |= ch->m_rts;
1905
1906 if (ch->digiext.digi_flags & DTRPACE)
1907 res |= ch->m_dtr;
1908
1909 if (ch->digiext.digi_flags & CTSPACE)
1910 res |= ch->m_cts;
1911
1912 if (ch->digiext.digi_flags & DSRPACE)
1913 res |= ch->dsr;
1914
1915 if (ch->digiext.digi_flags & DCDPACE)
1916 res |= ch->dcd;
1917
1918 if (res & (ch->m_rts))
1919 ch->digiext.digi_flags |= RTSPACE;
1920
1921 if (res & (ch->m_cts))
1922 ch->digiext.digi_flags |= CTSPACE;
1923
1924 return res;
1925
1926} /* End termios2digi_h */
1927
1928/* --------------------- Begin termios2digi_i -------------------- */
1929static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1930{ /* Begin termios2digi_i */
1931
1932 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1933 INPCK | ISTRIP|IXON|IXANY|IXOFF);
1da177e4
LT
1934 if (ch->digiext.digi_flags & DIGI_AIXON)
1935 res |= IAIXON;
1936 return res;
1937
1938} /* End termios2digi_i */
1939
1940/* --------------------- Begin termios2digi_c -------------------- */
1941
1942static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1943{ /* Begin termios2digi_c */
1944
1945 unsigned res = 0;
f2cf8e25 1946 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
1da177e4 1947 ch->digiext.digi_flags |= DIGI_FAST;
1da177e4
LT
1948 /* -------------------------------------------------------------
1949 HUPCL bit is used by FEP to indicate fast baud
1950 table is to be used.
1951 ----------------------------------------------------------------- */
1da177e4 1952 res |= FEP_HUPCL;
1da177e4
LT
1953 } /* End detected CBAUDEX */
1954 else ch->digiext.digi_flags &= ~DIGI_FAST;
1da177e4
LT
1955 /* -------------------------------------------------------------------
1956 CBAUD has bit position 0x1000 set these days to indicate Linux
1957 baud rate remap. Digi hardware can't handle the bit assignment.
1958 (We use a different bit assignment for high speed.). Clear this
1959 bit out.
1960 ---------------------------------------------------------------------- */
1961 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1da177e4
LT
1962 /* -------------------------------------------------------------
1963 This gets a little confusing. The Digi cards have their own
1964 representation of c_cflags controling baud rate. For the most
1965 part this is identical to the Linux implementation. However;
1966 Digi supports one rate (76800) that Linux doesn't. This means
1967 that the c_cflag entry that would normally mean 76800 for Digi
1968 actually means 115200 under Linux. Without the below mapping,
1969 a stty 115200 would only drive the board at 76800. Since
1970 the rate 230400 is also found after 76800, the same problem afflicts
1971 us when we choose a rate of 230400. Without the below modificiation
1972 stty 230400 would actually give us 115200.
1973
1974 There are two additional differences. The Linux value for CLOCAL
1975 (0x800; 0004000) has no meaning to the Digi hardware. Also in
1976 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
1977 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
1978 should be checked for a screened out prior to termios2digi_c
1979 returning. Since CLOCAL isn't used by the board this can be
1980 ignored as long as the returned value is used only by Digi hardware.
f2cf8e25
AC
1981 ----------------------------------------------------------------- */
1982 if (cflag & CBAUDEX) {
1da177e4
LT
1983 /* -------------------------------------------------------------
1984 The below code is trying to guarantee that only baud rates
1985 115200 and 230400 are remapped. We use exclusive or because
1986 the various baud rates share common bit positions and therefore
1987 can't be tested for easily.
1988 ----------------------------------------------------------------- */
1989
1990
1991 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1992 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1da177e4 1993 res += 1;
1da177e4 1994 }
1da177e4
LT
1995 return res;
1996
1997} /* End termios2digi_c */
1998
1999/* --------------------- Begin epcaparam ----------------------- */
2000
f2cf8e25 2001/* Caller must hold the locks */
1da177e4
LT
2002static void epcaparam(struct tty_struct *tty, struct channel *ch)
2003{ /* Begin epcaparam */
2004
2005 unsigned int cmdHead;
606d099c 2006 struct ktermios *ts;
bc9a5154 2007 struct board_chan __iomem *bc;
1da177e4
LT
2008 unsigned mval, hflow, cflag, iflag;
2009
2010 bc = ch->brdchan;
2011 epcaassert(bc !=0, "bc out of range");
2012
2013 assertgwinon(ch);
1da177e4 2014 ts = tty->termios;
f2cf8e25
AC
2015 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2016 cmdHead = readw(&bc->rin);
bc9a5154 2017 writew(cmdHead, &bc->rout);
f2cf8e25 2018 cmdHead = readw(&bc->tin);
1da177e4
LT
2019 /* Changing baud in mid-stream transmission can be wonderful */
2020 /* ---------------------------------------------------------------
2021 Flush current transmit buffer by setting cmdTail pointer (tout)
2022 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2023 ----------------------------------------------------------------- */
1da177e4
LT
2024 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2025 mval = 0;
f2cf8e25 2026 } else { /* Begin CBAUD not detected */
1da177e4
LT
2027 /* -------------------------------------------------------------------
2028 c_cflags have changed but that change had nothing to do with BAUD.
2029 Propagate the change to the card.
2030 ---------------------------------------------------------------------- */
1da177e4 2031 cflag = termios2digi_c(ch, ts->c_cflag);
f2cf8e25 2032 if (cflag != ch->fepcflag) {
1da177e4
LT
2033 ch->fepcflag = cflag;
2034 /* Set baud rate, char size, stop bits, parity */
2035 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2036 }
1da177e4
LT
2037 /* ----------------------------------------------------------------
2038 If the user has not forced CLOCAL and if the device is not a
2039 CALLOUT device (Which is always CLOCAL) we set flags such that
2040 the driver will wait on carrier detect.
2041 ------------------------------------------------------------------- */
1da177e4 2042 if (ts->c_cflag & CLOCAL)
1da177e4 2043 ch->asyncflags &= ~ASYNC_CHECK_CD;
1da177e4 2044 else
1da177e4 2045 ch->asyncflags |= ASYNC_CHECK_CD;
1da177e4 2046 mval = ch->m_dtr | ch->m_rts;
1da177e4 2047 } /* End CBAUD not detected */
1da177e4 2048 iflag = termios2digi_i(ch, ts->c_iflag);
1da177e4 2049 /* Check input mode flags */
f2cf8e25 2050 if (iflag != ch->fepiflag) {
1da177e4 2051 ch->fepiflag = iflag;
1da177e4
LT
2052 /* ---------------------------------------------------------------
2053 Command sets channels iflag structure on the board. Such things
2054 as input soft flow control, handling of parity errors, and
2055 break handling are all set here.
2056 ------------------------------------------------------------------- */
1da177e4
LT
2057 /* break handling, parity handling, input stripping, flow control chars */
2058 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2059 }
1da177e4
LT
2060 /* ---------------------------------------------------------------
2061 Set the board mint value for this channel. This will cause hardware
2062 events to be generated each time the DCD signal (Described in mint)
2063 changes.
2064 ------------------------------------------------------------------- */
f2cf8e25 2065 writeb(ch->dcd, &bc->mint);
1da177e4
LT
2066 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2067 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
f2cf8e25
AC
2068 writeb(0, &bc->mint);
2069 ch->imodem = readb(&bc->mstat);
1da177e4 2070 hflow = termios2digi_h(ch, ts->c_cflag);
f2cf8e25 2071 if (hflow != ch->hflow) {
1da177e4 2072 ch->hflow = hflow;
1da177e4
LT
2073 /* --------------------------------------------------------------
2074 Hard flow control has been selected but the board is not
2075 using it. Activate hard flow control now.
2076 ----------------------------------------------------------------- */
1da177e4
LT
2077 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2078 }
1da177e4
LT
2079 mval ^= ch->modemfake & (mval ^ ch->modem);
2080
f2cf8e25 2081 if (ch->omodem ^ mval) {
1da177e4 2082 ch->omodem = mval;
1da177e4
LT
2083 /* --------------------------------------------------------------
2084 The below command sets the DTR and RTS mstat structure. If
2085 hard flow control is NOT active these changes will drive the
2086 output of the actual DTR and RTS lines. If hard flow control
2087 is active, the changes will be saved in the mstat structure and
2088 only asserted when hard flow control is turned off.
2089 ----------------------------------------------------------------- */
2090
2091 /* First reset DTR & RTS; then set them */
2092 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2093 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1da177e4 2094 }
f2cf8e25 2095 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1da177e4
LT
2096 ch->fepstartc = ch->startc;
2097 ch->fepstopc = ch->stopc;
1da177e4
LT
2098 /* ------------------------------------------------------------
2099 The XON / XOFF characters have changed; propagate these
2100 changes to the card.
2101 --------------------------------------------------------------- */
1da177e4
LT
2102 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2103 }
f2cf8e25 2104 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1da177e4
LT
2105 ch->fepstartca = ch->startca;
2106 ch->fepstopca = ch->stopca;
1da177e4
LT
2107 /* ---------------------------------------------------------------
2108 Similar to the above, this time the auxilarly XON / XOFF
2109 characters have changed; propagate these changes to the card.
2110 ------------------------------------------------------------------ */
1da177e4
LT
2111 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2112 }
1da177e4
LT
2113} /* End epcaparam */
2114
2115/* --------------------- Begin receive_data ----------------------- */
f2cf8e25 2116/* Caller holds lock */
1da177e4
LT
2117static void receive_data(struct channel *ch)
2118{ /* Begin receive_data */
2119
2120 unchar *rptr;
606d099c 2121 struct ktermios *ts = NULL;
1da177e4 2122 struct tty_struct *tty;
bc9a5154 2123 struct board_chan __iomem *bc;
f2cf8e25
AC
2124 int dataToRead, wrapgap, bytesAvailable;
2125 unsigned int tail, head;
1da177e4 2126 unsigned int wrapmask;
1da177e4 2127
1da177e4
LT
2128 /* ---------------------------------------------------------------
2129 This routine is called by doint when a receive data event
2130 has taken place.
2131 ------------------------------------------------------------------- */
2132
2133 globalwinon(ch);
1da177e4
LT
2134 if (ch->statusflags & RXSTOPPED)
2135 return;
1da177e4
LT
2136 tty = ch->tty;
2137 if (tty)
2138 ts = tty->termios;
1da177e4 2139 bc = ch->brdchan;
f2cf8e25 2140 BUG_ON(!bc);
1da177e4
LT
2141 wrapmask = ch->rxbufsize - 1;
2142
2143 /* ---------------------------------------------------------------------
2144 Get the head and tail pointers to the receiver queue. Wrap the
2145 head pointer if it has reached the end of the buffer.
2146 ------------------------------------------------------------------------ */
f2cf8e25 2147 head = readw(&bc->rin);
1da177e4 2148 head &= wrapmask;
f2cf8e25 2149 tail = readw(&bc->rout) & wrapmask;
1da177e4
LT
2150
2151 bytesAvailable = (head - tail) & wrapmask;
1da177e4
LT
2152 if (bytesAvailable == 0)
2153 return;
2154
2155 /* ------------------------------------------------------------------
2156 If CREAD bit is off or device not open, set TX tail to head
2157 --------------------------------------------------------------------- */
2158
f2cf8e25 2159 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
bc9a5154 2160 writew(head, &bc->rout);
1da177e4
LT
2161 return;
2162 }
2163
33f0f88f 2164 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
1da177e4
LT
2165 return;
2166
f2cf8e25
AC
2167 if (readb(&bc->orun)) {
2168 writeb(0, &bc->orun);
2169 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
33f0f88f 2170 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1da177e4 2171 }
1da177e4 2172 rxwinon(ch);
f2cf8e25 2173 while (bytesAvailable > 0) { /* Begin while there is data on the card */
1da177e4 2174 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
1da177e4
LT
2175 /* ---------------------------------------------------------------
2176 Even if head has wrapped around only report the amount of
2177 data to be equal to the size - tail. Remember memcpy can't
2178 automaticly wrap around the receive buffer.
2179 ----------------------------------------------------------------- */
1da177e4 2180 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
1da177e4
LT
2181 /* --------------------------------------------------------------
2182 Make sure we don't overflow the buffer
2183 ----------------------------------------------------------------- */
33f0f88f 2184 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
1da177e4
LT
2185 if (dataToRead == 0)
2186 break;
1da177e4
LT
2187 /* ---------------------------------------------------------------
2188 Move data read from our card into the line disciplines buffer
2189 for translation if necessary.
2190 ------------------------------------------------------------------ */
f2cf8e25 2191 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
1da177e4
LT
2192 tail = (tail + dataToRead) & wrapmask;
2193 bytesAvailable -= dataToRead;
1da177e4 2194 } /* End while there is data on the card */
1da177e4 2195 globalwinon(ch);
f2cf8e25 2196 writew(tail, &bc->rout);
1da177e4
LT
2197 /* Must be called with global data */
2198 tty_schedule_flip(ch->tty);
2199 return;
1da177e4
LT
2200} /* End receive_data */
2201
2202static int info_ioctl(struct tty_struct *tty, struct file * file,
2203 unsigned int cmd, unsigned long arg)
2204{
2205 switch (cmd)
2206 { /* Begin switch cmd */
1da177e4
LT
2207 case DIGI_GETINFO:
2208 { /* Begin case DIGI_GETINFO */
1da177e4
LT
2209 struct digi_info di ;
2210 int brd;
2211
f2cf8e25
AC
2212 if(get_user(brd, (unsigned int __user *)arg))
2213 return -EFAULT;
2214 if (brd < 0 || brd >= num_cards || num_cards == 0)
2215 return -ENODEV;
1da177e4
LT
2216
2217 memset(&di, 0, sizeof(di));
2218
2219 di.board = brd ;
2220 di.status = boards[brd].status;
2221 di.type = boards[brd].type ;
2222 di.numports = boards[brd].numports ;
f2cf8e25
AC
2223 /* Legacy fixups - just move along nothing to see */
2224 di.port = (unsigned char *)boards[brd].port ;
2225 di.membase = (unsigned char *)boards[brd].membase ;
1da177e4
LT
2226
2227 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2228 return -EFAULT;
2229 break;
2230
2231 } /* End case DIGI_GETINFO */
2232
2233 case DIGI_POLLER:
2234 { /* Begin case DIGI_POLLER */
2235
2236 int brd = arg & 0xff000000 >> 16 ;
2237 unsigned char state = arg & 0xff ;
2238
f2cf8e25
AC
2239 if (brd < 0 || brd >= num_cards) {
2240 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
1da177e4
LT
2241 return (-ENODEV);
2242 }
1da177e4
LT
2243 digi_poller_inhibited = state ;
2244 break ;
1da177e4
LT
2245 } /* End case DIGI_POLLER */
2246
2247 case DIGI_INIT:
2248 { /* Begin case DIGI_INIT */
1da177e4
LT
2249 /* ------------------------------------------------------------
2250 This call is made by the apps to complete the initilization
2251 of the board(s). This routine is responsible for setting
2252 the card to its initial state and setting the drivers control
2253 fields to the sutianle settings for the card in question.
2254 ---------------------------------------------------------------- */
1da177e4
LT
2255 int crd ;
2256 for (crd = 0; crd < num_cards; crd++)
2257 post_fep_init (crd);
1da177e4 2258 break ;
1da177e4 2259 } /* End case DIGI_INIT */
1da177e4 2260 default:
f2cf8e25 2261 return -ENOTTY;
1da177e4
LT
2262 } /* End switch cmd */
2263 return (0) ;
2264}
2265/* --------------------- Begin pc_ioctl ----------------------- */
2266
2267static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2268{
2269 struct channel *ch = (struct channel *) tty->driver_data;
bc9a5154 2270 struct board_chan __iomem *bc;
1da177e4
LT
2271 unsigned int mstat, mflag = 0;
2272 unsigned long flags;
2273
2274 if (ch)
2275 bc = ch->brdchan;
2276 else
f2cf8e25 2277 return -EINVAL;
1da177e4 2278
f2cf8e25 2279 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2280 globalwinon(ch);
f2cf8e25 2281 mstat = readb(&bc->mstat);
1da177e4 2282 memoff(ch);
f2cf8e25 2283 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2284
2285 if (mstat & ch->m_dtr)
2286 mflag |= TIOCM_DTR;
1da177e4
LT
2287 if (mstat & ch->m_rts)
2288 mflag |= TIOCM_RTS;
1da177e4
LT
2289 if (mstat & ch->m_cts)
2290 mflag |= TIOCM_CTS;
1da177e4
LT
2291 if (mstat & ch->dsr)
2292 mflag |= TIOCM_DSR;
1da177e4
LT
2293 if (mstat & ch->m_ri)
2294 mflag |= TIOCM_RI;
1da177e4
LT
2295 if (mstat & ch->dcd)
2296 mflag |= TIOCM_CD;
1da177e4
LT
2297 return mflag;
2298}
2299
2300static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2301 unsigned int set, unsigned int clear)
2302{
2303 struct channel *ch = (struct channel *) tty->driver_data;
2304 unsigned long flags;
2305
f2cf8e25
AC
2306 if (!ch)
2307 return -EINVAL;
1da177e4 2308
f2cf8e25 2309 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
2310 /*
2311 * I think this modemfake stuff is broken. It doesn't
2312 * correctly reflect the behaviour desired by the TIOCM*
2313 * ioctls. Therefore this is probably broken.
2314 */
2315 if (set & TIOCM_RTS) {
2316 ch->modemfake |= ch->m_rts;
2317 ch->modem |= ch->m_rts;
2318 }
2319 if (set & TIOCM_DTR) {
2320 ch->modemfake |= ch->m_dtr;
2321 ch->modem |= ch->m_dtr;
2322 }
2323 if (clear & TIOCM_RTS) {
2324 ch->modemfake |= ch->m_rts;
2325 ch->modem &= ~ch->m_rts;
2326 }
2327 if (clear & TIOCM_DTR) {
2328 ch->modemfake |= ch->m_dtr;
2329 ch->modem &= ~ch->m_dtr;
2330 }
1da177e4 2331 globalwinon(ch);
1da177e4
LT
2332 /* --------------------------------------------------------------
2333 The below routine generally sets up parity, baud, flow control
2334 issues, etc.... It effect both control flags and input flags.
2335 ------------------------------------------------------------------ */
1da177e4
LT
2336 epcaparam(tty,ch);
2337 memoff(ch);
f2cf8e25 2338 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2339 return 0;
2340}
2341
2342static int pc_ioctl(struct tty_struct *tty, struct file * file,
2343 unsigned int cmd, unsigned long arg)
2344{ /* Begin pc_ioctl */
2345
2346 digiflow_t dflow;
2347 int retval;
2348 unsigned long flags;
2349 unsigned int mflag, mstat;
2350 unsigned char startc, stopc;
bc9a5154 2351 struct board_chan __iomem *bc;
1da177e4
LT
2352 struct channel *ch = (struct channel *) tty->driver_data;
2353 void __user *argp = (void __user *)arg;
2354
2355 if (ch)
2356 bc = ch->brdchan;
2357 else
f2cf8e25 2358 return -EINVAL;
1da177e4
LT
2359
2360 /* -------------------------------------------------------------------
2361 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2362 in /usr/src/linux/drivers/char for a good example. In particular
2363 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2364 ---------------------------------------------------------------------- */
2365
2366 switch (cmd)
2367 { /* Begin switch cmd */
2368
606d099c 2369#if 0 /* Handled by calling layer properly */
1da177e4 2370 case TCGETS:
606d099c 2371 if (copy_to_user(argp, tty->termios, sizeof(struct ktermios)))
1da177e4 2372 return -EFAULT;
f2cf8e25 2373 return 0;
1da177e4
LT
2374 case TCGETA:
2375 return get_termio(tty, argp);
606d099c 2376#endif
1da177e4 2377 case TCSBRK: /* SVID version: non-zero arg --> no break */
1da177e4
LT
2378 retval = tty_check_change(tty);
2379 if (retval)
2380 return retval;
1da177e4 2381 /* Setup an event to indicate when the transmit buffer empties */
f2cf8e25 2382 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2383 setup_empty_event(tty,ch);
f2cf8e25 2384 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2385 tty_wait_until_sent(tty, 0);
2386 if (!arg)
2387 digi_send_break(ch, HZ/4); /* 1/4 second */
2388 return 0;
1da177e4 2389 case TCSBRKP: /* support for POSIX tcsendbreak() */
1da177e4
LT
2390 retval = tty_check_change(tty);
2391 if (retval)
2392 return retval;
2393
2394 /* Setup an event to indicate when the transmit buffer empties */
f2cf8e25 2395 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2396 setup_empty_event(tty,ch);
f2cf8e25 2397 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2398 tty_wait_until_sent(tty, 0);
2399 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2400 return 0;
1da177e4
LT
2401 case TIOCGSOFTCAR:
2402 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2403 return -EFAULT;
2404 return 0;
1da177e4
LT
2405 case TIOCSSOFTCAR:
2406 {
2407 unsigned int value;
2408
2409 if (get_user(value, (unsigned __user *)argp))
2410 return -EFAULT;
2411 tty->termios->c_cflag =
2412 ((tty->termios->c_cflag & ~CLOCAL) |
2413 (value ? CLOCAL : 0));
2414 return 0;
2415 }
1da177e4
LT
2416 case TIOCMODG:
2417 mflag = pc_tiocmget(tty, file);
2418 if (put_user(mflag, (unsigned long __user *)argp))
2419 return -EFAULT;
2420 break;
1da177e4
LT
2421 case TIOCMODS:
2422 if (get_user(mstat, (unsigned __user *)argp))
2423 return -EFAULT;
2424 return pc_tiocmset(tty, file, mstat, ~mstat);
1da177e4 2425 case TIOCSDTR:
f2cf8e25 2426 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2427 ch->omodem |= ch->m_dtr;
1da177e4
LT
2428 globalwinon(ch);
2429 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2430 memoff(ch);
f2cf8e25 2431 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2432 break;
2433
2434 case TIOCCDTR:
f2cf8e25 2435 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2436 ch->omodem &= ~ch->m_dtr;
1da177e4
LT
2437 globalwinon(ch);
2438 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2439 memoff(ch);
f2cf8e25 2440 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 2441 break;
1da177e4
LT
2442 case DIGI_GETA:
2443 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2444 return -EFAULT;
2445 break;
1da177e4
LT
2446 case DIGI_SETAW:
2447 case DIGI_SETAF:
f2cf8e25 2448 if (cmd == DIGI_SETAW) {
1da177e4 2449 /* Setup an event to indicate when the transmit buffer empties */
f2cf8e25 2450 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2451 setup_empty_event(tty,ch);
f2cf8e25 2452 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 2453 tty_wait_until_sent(tty, 0);
f2cf8e25 2454 } else {
1da177e4
LT
2455 /* ldisc lock already held in ioctl */
2456 if (tty->ldisc.flush_buffer)
2457 tty->ldisc.flush_buffer(tty);
2458 }
1da177e4 2459 /* Fall Thru */
1da177e4
LT
2460 case DIGI_SETA:
2461 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2462 return -EFAULT;
2463
f2cf8e25 2464 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
1da177e4
LT
2465 ch->dcd = ch->m_dsr;
2466 ch->dsr = ch->m_dcd;
f2cf8e25 2467 } else {
1da177e4
LT
2468 ch->dcd = ch->m_dcd;
2469 ch->dsr = ch->m_dsr;
2470 }
2471
f2cf8e25 2472 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
2473 globalwinon(ch);
2474
2475 /* -----------------------------------------------------------------
2476 The below routine generally sets up parity, baud, flow control
2477 issues, etc.... It effect both control flags and input flags.
2478 ------------------------------------------------------------------- */
2479
2480 epcaparam(tty,ch);
2481 memoff(ch);
f2cf8e25 2482 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2483 break;
2484
2485 case DIGI_GETFLOW:
2486 case DIGI_GETAFLOW:
f2cf8e25 2487 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2488 globalwinon(ch);
f2cf8e25
AC
2489 if (cmd == DIGI_GETFLOW) {
2490 dflow.startc = readb(&bc->startc);
2491 dflow.stopc = readb(&bc->stopc);
2492 } else {
2493 dflow.startc = readb(&bc->startca);
2494 dflow.stopc = readb(&bc->stopca);
1da177e4
LT
2495 }
2496 memoff(ch);
f2cf8e25 2497 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2498
2499 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2500 return -EFAULT;
2501 break;
2502
2503 case DIGI_SETAFLOW:
2504 case DIGI_SETFLOW:
f2cf8e25 2505 if (cmd == DIGI_SETFLOW) {
1da177e4
LT
2506 startc = ch->startc;
2507 stopc = ch->stopc;
f2cf8e25 2508 } else {
1da177e4
LT
2509 startc = ch->startca;
2510 stopc = ch->stopca;
2511 }
2512
2513 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2514 return -EFAULT;
2515
f2cf8e25
AC
2516 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
2517 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
2518 globalwinon(ch);
2519
f2cf8e25 2520 if (cmd == DIGI_SETFLOW) {
1da177e4
LT
2521 ch->fepstartc = ch->startc = dflow.startc;
2522 ch->fepstopc = ch->stopc = dflow.stopc;
2523 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
f2cf8e25 2524 } else {
1da177e4
LT
2525 ch->fepstartca = ch->startca = dflow.startc;
2526 ch->fepstopca = ch->stopca = dflow.stopc;
2527 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2528 }
2529
f2cf8e25 2530 if (ch->statusflags & TXSTOPPED)
1da177e4
LT
2531 pc_start(tty);
2532
2533 memoff(ch);
f2cf8e25 2534 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2535 } /* End if setflow toggled */
2536 break;
1da177e4
LT
2537 default:
2538 return -ENOIOCTLCMD;
1da177e4 2539 } /* End switch cmd */
1da177e4 2540 return 0;
1da177e4
LT
2541} /* End pc_ioctl */
2542
2543/* --------------------- Begin pc_set_termios ----------------------- */
2544
606d099c 2545static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1da177e4
LT
2546{ /* Begin pc_set_termios */
2547
2548 struct channel *ch;
2549 unsigned long flags;
1da177e4
LT
2550 /* ---------------------------------------------------------
2551 verifyChannel returns the channel from the tty struct
2552 if it is valid. This serves as a sanity check.
2553 ------------------------------------------------------------- */
f2cf8e25
AC
2554 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2555 spin_lock_irqsave(&epca_lock, flags);
1da177e4
LT
2556 globalwinon(ch);
2557 epcaparam(tty, ch);
2558 memoff(ch);
f2cf8e25 2559 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2560
2561 if ((old_termios->c_cflag & CRTSCTS) &&
2562 ((tty->termios->c_cflag & CRTSCTS) == 0))
2563 tty->hw_stopped = 0;
2564
2565 if (!(old_termios->c_cflag & CLOCAL) &&
2566 (tty->termios->c_cflag & CLOCAL))
2567 wake_up_interruptible(&ch->open_wait);
2568
1da177e4
LT
2569 } /* End if channel valid */
2570
2571} /* End pc_set_termios */
2572
2573/* --------------------- Begin do_softint ----------------------- */
2574
c4028958 2575static void do_softint(struct work_struct *work)
1da177e4 2576{ /* Begin do_softint */
c4028958 2577 struct channel *ch = container_of(work, struct channel, tqueue);
1da177e4 2578 /* Called in response to a modem change event */
f2cf8e25 2579 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
1da177e4
LT
2580 struct tty_struct *tty = ch->tty;
2581
f2cf8e25
AC
2582 if (tty && tty->driver_data) {
2583 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
1da177e4
LT
2584 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2585 wake_up_interruptible(&ch->open_wait);
2586 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
1da177e4
LT
2587 } /* End if clear_bit */
2588 }
1da177e4
LT
2589 } /* End EPCA_MAGIC */
2590} /* End do_softint */
2591
2592/* ------------------------------------------------------------
2593 pc_stop and pc_start provide software flow control to the
2594 routine and the pc_ioctl routine.
2595---------------------------------------------------------------- */
2596
2597/* --------------------- Begin pc_stop ----------------------- */
2598
2599static void pc_stop(struct tty_struct *tty)
2600{ /* Begin pc_stop */
2601
2602 struct channel *ch;
2603 unsigned long flags;
1da177e4
LT
2604 /* ---------------------------------------------------------
2605 verifyChannel returns the channel from the tty struct
2606 if it is valid. This serves as a sanity check.
2607 ------------------------------------------------------------- */
f2cf8e25
AC
2608 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
2609 spin_lock_irqsave(&epca_lock, flags);
2610 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
1da177e4 2611 globalwinon(ch);
1da177e4 2612 /* STOP transmitting now !! */
1da177e4 2613 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
1da177e4
LT
2614 ch->statusflags |= TXSTOPPED;
2615 memoff(ch);
1da177e4 2616 } /* End if transmit stop requested */
f2cf8e25 2617 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 2618 } /* End if valid channel */
1da177e4
LT
2619} /* End pc_stop */
2620
2621/* --------------------- Begin pc_start ----------------------- */
2622
2623static void pc_start(struct tty_struct *tty)
2624{ /* Begin pc_start */
1da177e4 2625 struct channel *ch;
1da177e4
LT
2626 /* ---------------------------------------------------------
2627 verifyChannel returns the channel from the tty struct
2628 if it is valid. This serves as a sanity check.
2629 ------------------------------------------------------------- */
f2cf8e25 2630 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
1da177e4 2631 unsigned long flags;
f2cf8e25 2632 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2633 /* Just in case output was resumed because of a change in Digi-flow */
f2cf8e25 2634 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
bc9a5154 2635 struct board_chan __iomem *bc;
1da177e4
LT
2636 globalwinon(ch);
2637 bc = ch->brdchan;
2638 if (ch->statusflags & LOWWAIT)
f2cf8e25 2639 writeb(1, &bc->ilow);
1da177e4 2640 /* Okay, you can start transmitting again... */
1da177e4 2641 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
1da177e4
LT
2642 ch->statusflags &= ~TXSTOPPED;
2643 memoff(ch);
1da177e4 2644 } /* End transmit resume requested */
f2cf8e25 2645 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 2646 } /* End if channel valid */
1da177e4
LT
2647} /* End pc_start */
2648
2649/* ------------------------------------------------------------------
2650 The below routines pc_throttle and pc_unthrottle are used
2651 to slow (And resume) the receipt of data into the kernels
2652 receive buffers. The exact occurrence of this depends on the
2653 size of the kernels receive buffer and what the 'watermarks'
2654 are set to for that buffer. See the n_ttys.c file for more
2655 details.
2656______________________________________________________________________ */
2657/* --------------------- Begin throttle ----------------------- */
2658
2659static void pc_throttle(struct tty_struct * tty)
2660{ /* Begin pc_throttle */
1da177e4
LT
2661 struct channel *ch;
2662 unsigned long flags;
1da177e4
LT
2663 /* ---------------------------------------------------------
2664 verifyChannel returns the channel from the tty struct
2665 if it is valid. This serves as a sanity check.
2666 ------------------------------------------------------------- */
f2cf8e25
AC
2667 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
2668 spin_lock_irqsave(&epca_lock, flags);
2669 if ((ch->statusflags & RXSTOPPED) == 0) {
1da177e4
LT
2670 globalwinon(ch);
2671 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
1da177e4
LT
2672 ch->statusflags |= RXSTOPPED;
2673 memoff(ch);
2674 }
f2cf8e25 2675 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 2676 } /* End if channel valid */
1da177e4
LT
2677} /* End pc_throttle */
2678
2679/* --------------------- Begin unthrottle ----------------------- */
2680
2681static void pc_unthrottle(struct tty_struct *tty)
2682{ /* Begin pc_unthrottle */
1da177e4
LT
2683 struct channel *ch;
2684 unsigned long flags;
1da177e4
LT
2685 /* ---------------------------------------------------------
2686 verifyChannel returns the channel from the tty struct
2687 if it is valid. This serves as a sanity check.
2688 ------------------------------------------------------------- */
f2cf8e25 2689 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
1da177e4 2690 /* Just in case output was resumed because of a change in Digi-flow */
f2cf8e25
AC
2691 spin_lock_irqsave(&epca_lock, flags);
2692 if (ch->statusflags & RXSTOPPED) {
1da177e4 2693 globalwinon(ch);
1da177e4 2694 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
1da177e4
LT
2695 ch->statusflags &= ~RXSTOPPED;
2696 memoff(ch);
2697 }
f2cf8e25 2698 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4 2699 } /* End if channel valid */
1da177e4
LT
2700} /* End pc_unthrottle */
2701
2702/* --------------------- Begin digi_send_break ----------------------- */
2703
2704void digi_send_break(struct channel *ch, int msec)
2705{ /* Begin digi_send_break */
1da177e4
LT
2706 unsigned long flags;
2707
f2cf8e25 2708 spin_lock_irqsave(&epca_lock, flags);
1da177e4 2709 globalwinon(ch);
1da177e4
LT
2710 /* --------------------------------------------------------------------
2711 Maybe I should send an infinite break here, schedule() for
2712 msec amount of time, and then stop the break. This way,
2713 the user can't screw up the FEP by causing digi_send_break()
2714 to be called (i.e. via an ioctl()) more than once in msec amount
2715 of time. Try this for now...
2716 ------------------------------------------------------------------------ */
1da177e4
LT
2717 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2718 memoff(ch);
f2cf8e25 2719 spin_unlock_irqrestore(&epca_lock, flags);
1da177e4
LT
2720} /* End digi_send_break */
2721
2722/* --------------------- Begin setup_empty_event ----------------------- */
2723
f2cf8e25
AC
2724/* Caller MUST hold the lock */
2725
1da177e4
LT
2726static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2727{ /* Begin setup_empty_event */
2728
bc9a5154 2729 struct board_chan __iomem *bc = ch->brdchan;
1da177e4 2730
1da177e4
LT
2731 globalwinon(ch);
2732 ch->statusflags |= EMPTYWAIT;
1da177e4
LT
2733 /* ------------------------------------------------------------------
2734 When set the iempty flag request a event to be generated when the
2735 transmit buffer is empty (If there is no BREAK in progress).
2736 --------------------------------------------------------------------- */
f2cf8e25 2737 writeb(1, &bc->iempty);
1da177e4 2738 memoff(ch);
1da177e4
LT
2739} /* End setup_empty_event */
2740
2741/* --------------------- Begin get_termio ----------------------- */
2742
2743static int get_termio(struct tty_struct * tty, struct termio __user * termio)
2744{ /* Begin get_termio */
2745 return kernel_termios_to_user_termio(termio, tty->termios);
2746} /* End get_termio */
f2cf8e25 2747
1da177e4
LT
2748/* ---------------------- Begin epca_setup -------------------------- */
2749void epca_setup(char *str, int *ints)
2750{ /* Begin epca_setup */
1da177e4
LT
2751 struct board_info board;
2752 int index, loop, last;
2753 char *temp, *t2;
2754 unsigned len;
2755
2756 /* ----------------------------------------------------------------------
2757 If this routine looks a little strange it is because it is only called
2758 if a LILO append command is given to boot the kernel with parameters.
2759 In this way, we can provide the user a method of changing his board
2760 configuration without rebuilding the kernel.
2761 ----------------------------------------------------------------------- */
2762 if (!liloconfig)
2763 liloconfig = 1;
2764
2765 memset(&board, 0, sizeof(board));
2766
2767 /* Assume the data is int first, later we can change it */
2768 /* I think that array position 0 of ints holds the number of args */
2769 for (last = 0, index = 1; index <= ints[0]; index++)
2770 switch(index)
2771 { /* Begin parse switch */
1da177e4
LT
2772 case 1:
2773 board.status = ints[index];
1da177e4
LT
2774 /* ---------------------------------------------------------
2775 We check for 2 (As opposed to 1; because 2 is a flag
2776 instructing the driver to ignore epcaconfig.) For this
2777 reason we check for 2.
2778 ------------------------------------------------------------ */
f2cf8e25 2779 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
1da177e4
LT
2780 nbdevs = 0;
2781 num_cards = 0;
2782 return;
2783 } /* End ignore epcaconfig as well as lilo cmd line */
2784
f2cf8e25
AC
2785 if (board.status > 2) {
2786 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
1da177e4
LT
2787 invalid_lilo_config = 1;
2788 setup_error_code |= INVALID_BOARD_STATUS;
2789 return;
2790 }
2791 last = index;
2792 break;
1da177e4
LT
2793 case 2:
2794 board.type = ints[index];
f2cf8e25
AC
2795 if (board.type >= PCIXEM) {
2796 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
1da177e4
LT
2797 invalid_lilo_config = 1;
2798 setup_error_code |= INVALID_BOARD_TYPE;
2799 return;
2800 }
2801 last = index;
2802 break;
1da177e4
LT
2803 case 3:
2804 board.altpin = ints[index];
f2cf8e25
AC
2805 if (board.altpin > 1) {
2806 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
1da177e4
LT
2807 invalid_lilo_config = 1;
2808 setup_error_code |= INVALID_ALTPIN;
2809 return;
2810 }
2811 last = index;
2812 break;
2813
2814 case 4:
2815 board.numports = ints[index];
f2cf8e25
AC
2816 if (board.numports < 2 || board.numports > 256) {
2817 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
1da177e4
LT
2818 invalid_lilo_config = 1;
2819 setup_error_code |= INVALID_NUM_PORTS;
2820 return;
2821 }
2822 nbdevs += board.numports;
2823 last = index;
2824 break;
2825
2826 case 5:
f2cf8e25
AC
2827 board.port = ints[index];
2828 if (ints[index] <= 0) {
2829 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
1da177e4
LT
2830 invalid_lilo_config = 1;
2831 setup_error_code |= INVALID_PORT_BASE;
2832 return;
2833 }
2834 last = index;
2835 break;
2836
2837 case 6:
f2cf8e25
AC
2838 board.membase = ints[index];
2839 if (ints[index] <= 0) {
2840 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
1da177e4
LT
2841 invalid_lilo_config = 1;
2842 setup_error_code |= INVALID_MEM_BASE;
2843 return;
2844 }
2845 last = index;
2846 break;
2847
2848 default:
2849 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2850 return;
2851
2852 } /* End parse switch */
2853
f2cf8e25 2854 while (str && *str) { /* Begin while there is a string arg */
1da177e4
LT
2855 /* find the next comma or terminator */
2856 temp = str;
1da177e4
LT
2857 /* While string is not null, and a comma hasn't been found */
2858 while (*temp && (*temp != ','))
2859 temp++;
1da177e4
LT
2860 if (!*temp)
2861 temp = NULL;
2862 else
2863 *temp++ = 0;
1da177e4
LT
2864 /* Set index to the number of args + 1 */
2865 index = last + 1;
2866
2867 switch(index)
2868 {
2869 case 1:
2870 len = strlen(str);
2871 if (strncmp("Disable", str, len) == 0)
2872 board.status = 0;
f2cf8e25 2873 else if (strncmp("Enable", str, len) == 0)
1da177e4 2874 board.status = 1;
f2cf8e25
AC
2875 else {
2876 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
1da177e4
LT
2877 invalid_lilo_config = 1;
2878 setup_error_code |= INVALID_BOARD_STATUS;
2879 return;
2880 }
2881 last = index;
2882 break;
2883
2884 case 2:
1da177e4
LT
2885 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
2886 if (strcmp(board_desc[loop], str) == 0)
2887 break;
1da177e4
LT
2888 /* ---------------------------------------------------------------
2889 If the index incremented above refers to a legitamate board
2890 type set it here.
2891 ------------------------------------------------------------------*/
1da177e4
LT
2892 if (index < EPCA_NUM_TYPES)
2893 board.type = loop;
f2cf8e25
AC
2894 else {
2895 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
1da177e4
LT
2896 invalid_lilo_config = 1;
2897 setup_error_code |= INVALID_BOARD_TYPE;
2898 return;
2899 }
2900 last = index;
2901 break;
2902
2903 case 3:
2904 len = strlen(str);
2905 if (strncmp("Disable", str, len) == 0)
2906 board.altpin = 0;
f2cf8e25 2907 else if (strncmp("Enable", str, len) == 0)
1da177e4 2908 board.altpin = 1;
f2cf8e25
AC
2909 else {
2910 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
1da177e4
LT
2911 invalid_lilo_config = 1;
2912 setup_error_code |= INVALID_ALTPIN;
2913 return;
2914 }
2915 last = index;
2916 break;
2917
2918 case 4:
2919 t2 = str;
2920 while (isdigit(*t2))
2921 t2++;
2922
f2cf8e25
AC
2923 if (*t2) {
2924 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
1da177e4
LT
2925 invalid_lilo_config = 1;
2926 setup_error_code |= INVALID_NUM_PORTS;
2927 return;
2928 }
2929
2930 /* ------------------------------------------------------------
2931 There is not a man page for simple_strtoul but the code can be
2932 found in vsprintf.c. The first argument is the string to
2933 translate (To an unsigned long obviously), the second argument
2934 can be the address of any character variable or a NULL. If a
2935 variable is given, the end pointer of the string will be stored
2936 in that variable; if a NULL is given the end pointer will
2937 not be returned. The last argument is the base to use. If
2938 a 0 is indicated, the routine will attempt to determine the
2939 proper base by looking at the values prefix (A '0' for octal,
2940 a 'x' for hex, etc ... If a value is given it will use that
2941 value as the base.
2942 ---------------------------------------------------------------- */
2943 board.numports = simple_strtoul(str, NULL, 0);
2944 nbdevs += board.numports;
2945 last = index;
2946 break;
2947
2948 case 5:
2949 t2 = str;
2950 while (isxdigit(*t2))
2951 t2++;
2952
f2cf8e25
AC
2953 if (*t2) {
2954 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
1da177e4
LT
2955 invalid_lilo_config = 1;
2956 setup_error_code |= INVALID_PORT_BASE;
2957 return;
2958 }
2959
f2cf8e25 2960 board.port = simple_strtoul(str, NULL, 16);
1da177e4
LT
2961 last = index;
2962 break;
2963
2964 case 6:
2965 t2 = str;
2966 while (isxdigit(*t2))
2967 t2++;
2968
f2cf8e25
AC
2969 if (*t2) {
2970 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
1da177e4
LT
2971 invalid_lilo_config = 1;
2972 setup_error_code |= INVALID_MEM_BASE;
2973 return;
2974 }
f2cf8e25 2975 board.membase = simple_strtoul(str, NULL, 16);
1da177e4
LT
2976 last = index;
2977 break;
1da177e4 2978 default:
f2cf8e25 2979 printk(KERN_ERR "epca: Too many string parms\n");
1da177e4
LT
2980 return;
2981 }
2982 str = temp;
1da177e4
LT
2983 } /* End while there is a string arg */
2984
f2cf8e25
AC
2985 if (last < 6) {
2986 printk(KERN_ERR "epca: Insufficient parms specified\n");
1da177e4
LT
2987 return;
2988 }
2989
2990 /* I should REALLY validate the stuff here */
1da177e4
LT
2991 /* Copies our local copy of board into boards */
2992 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
1da177e4 2993 /* Does this get called once per lilo arg are what ? */
1da177e4
LT
2994 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2995 num_cards, board_desc[board.type],
2996 board.numports, (int)board.port, (unsigned int) board.membase);
1da177e4 2997 num_cards++;
1da177e4
LT
2998} /* End epca_setup */
2999
3000
1da177e4
LT
3001/* ------------------------ Begin init_PCI --------------------------- */
3002
3003enum epic_board_types {
3004 brd_xr = 0,
3005 brd_xem,
3006 brd_cx,
3007 brd_xrj,
3008};
3009
3010
3011/* indexed directly by epic_board_types enum */
3012static struct {
3013 unsigned char board_type;
3014 unsigned bar_idx; /* PCI base address region */
3015} epca_info_tbl[] = {
3016 { PCIXR, 0, },
3017 { PCIXEM, 0, },
3018 { PCICX, 0, },
3019 { PCIXRJ, 2, },
3020};
3021
1da177e4
LT
3022static int __devinit epca_init_one (struct pci_dev *pdev,
3023 const struct pci_device_id *ent)
3024{
3025 static int board_num = -1;
3026 int board_idx, info_idx = ent->driver_data;
3027 unsigned long addr;
3028
3029 if (pci_enable_device(pdev))
3030 return -EIO;
3031
3032 board_num++;
3033 board_idx = board_num + num_cards;
3034 if (board_idx >= MAXBOARDS)
3035 goto err_out;
3036
3037 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3038 if (!addr) {
3039 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3040 epca_info_tbl[info_idx].bar_idx);
3041 goto err_out;
3042 }
3043
3044 boards[board_idx].status = ENABLED;
3045 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3046 boards[board_idx].numports = 0x0;
f2cf8e25
AC
3047 boards[board_idx].port = addr + PCI_IO_OFFSET;
3048 boards[board_idx].membase = addr;
1da177e4
LT
3049
3050 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3051 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3052 0x200000, addr + PCI_IO_OFFSET);
3053 goto err_out;
3054 }
3055
3056 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3057 if (!boards[board_idx].re_map_port) {
3058 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3059 0x200000, addr + PCI_IO_OFFSET);
3060 goto err_out_free_pciio;
3061 }
3062
3063 if (!request_mem_region (addr, 0x200000, "epca")) {
3064 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3065 0x200000, addr);
3066 goto err_out_free_iounmap;
3067 }
3068
3069 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3070 if (!boards[board_idx].re_map_membase) {
3071 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3072 0x200000, addr + PCI_IO_OFFSET);
3073 goto err_out_free_memregion;
3074 }
3075
3076 /* --------------------------------------------------------------
3077 I don't know what the below does, but the hardware guys say
3078 its required on everything except PLX (In this case XRJ).
3079 ---------------------------------------------------------------- */
3080 if (info_idx != brd_xrj) {
3081 pci_write_config_byte(pdev, 0x40, 0);
3082 pci_write_config_byte(pdev, 0x46, 0);
3083 }
3084
3085 return 0;
3086
3087err_out_free_memregion:
3088 release_mem_region (addr, 0x200000);
3089err_out_free_iounmap:
3090 iounmap (boards[board_idx].re_map_port);
3091err_out_free_pciio:
3092 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3093err_out:
3094 return -ENODEV;
3095}
3096
3097
3098static struct pci_device_id epca_pci_tbl[] = {
3099 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3100 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3101 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3102 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3103 { 0, }
3104};
3105
3106MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3107
3108int __init init_PCI (void)
f2cf8e25 3109{ /* Begin init_PCI */
1da177e4
LT
3110 memset (&epca_driver, 0, sizeof (epca_driver));
3111 epca_driver.name = "epca";
3112 epca_driver.id_table = epca_pci_tbl;
3113 epca_driver.probe = epca_init_one;
3114
3115 return pci_register_driver(&epca_driver);
f2cf8e25 3116}
1da177e4
LT
3117
3118MODULE_LICENSE("GPL");
This page took 0.373079 seconds and 5 git commands to generate.