File: /usr/src/linux/drivers/char/epca.c
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
9 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan.
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 --------------------------------------------------------------------------- */
28 /* See README.epca for change history --DAT*/
29
30
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/init.h>
36 #include <linux/serial.h>
37 #include <linux/delay.h>
38 #include <linux/ctype.h>
39 #include <linux/tty.h>
40 #include <linux/tty_flip.h>
41 #include <linux/slab.h>
42 #include <linux/ioport.h>
43 #include <asm/uaccess.h>
44 #include <asm/io.h>
45
46 #ifdef CONFIG_PCI
47 #define ENABLE_PCI
48 #endif /* CONFIG_PCI */
49
50 #define putUser(arg1, arg2) put_user(arg1, (unsigned long *)arg2)
51 #define getUser(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
52
53 #ifdef ENABLE_PCI
54 #include <linux/pci.h>
55 #include "digiPCI.h"
56 #endif /* ENABLE_PCI */
57
58 #include "digi1.h"
59 #include "digiFep1.h"
60 #include "epca.h"
61 #include "epcaconfig.h"
62
63 #if BITS_PER_LONG != 32
64 # error FIXME: this driver only works on 32-bit platforms
65 #endif
66
67 /* ---------------------- Begin defines ------------------------ */
68
69 #define VERSION "1.3.0.1-LK"
70
71 /* This major needs to be submitted to Linux to join the majors list */
72
73 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
74
75
76 #define MIN(a,b) ((a) < (b) ? (a) : (b))
77 #define MAXCARDS 7
78 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
79
80 #define PFX "epca: "
81
82 /* ----------------- Begin global definitions ------------------- */
83
84 static char mesg[100];
85 static int pc_refcount, nbdevs, num_cards, liloconfig;
86 static int digi_poller_inhibited = 1 ;
87
88 static int setup_error_code;
89 static int invalid_lilo_config;
90
91 /* -----------------------------------------------------------------------
92 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
93 7 below.
94 --------------------------------------------------------------------------*/
95 static struct board_info boards[MAXBOARDS];
96
97
98 /* ------------- Begin structures used for driver registeration ---------- */
99
100 struct tty_driver pc_driver;
101 struct tty_driver pc_callout;
102 struct tty_driver pc_info;
103
104 /* The below structures are used to initialize the tty_driver structures. */
105
106 /* -------------------------------------------------------------------------
107 Note : MAX_ALLOC is currently limited to 0x100. This restriction is
108 placed on us by Linux not Digi.
109 ----------------------------------------------------------------------------*/
110 static struct tty_struct *pc_table[MAX_ALLOC];
111 static struct termios *pc_termios[MAX_ALLOC];
112 static struct termios *pc_termios_locked[MAX_ALLOC];
113
114
115 /* ------------------ Begin Digi specific structures -------------------- */
116
117 /* ------------------------------------------------------------------------
118 digi_channels represents an array of structures that keep track of
119 each channel of the Digi product. Information such as transmit and
120 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
121 are stored here. This structure is NOT used to overlay the cards
122 physical channel structure.
123 -------------------------------------------------------------------------- */
124
125 static struct channel digi_channels[MAX_ALLOC];
126
127 /* ------------------------------------------------------------------------
128 card_ptr is an array used to hold the address of the
129 first channel structure of each card. This array will hold
130 the addresses of various channels located in digi_channels.
131 -------------------------------------------------------------------------- */
132 static struct channel *card_ptr[MAXCARDS];
133
134 static struct timer_list epca_timer;
135
136 /* ---------------------- Begin function prototypes --------------------- */
137
138 /* ----------------------------------------------------------------------
139 Begin generic memory functions. These functions will be alias
140 (point at) more specific functions dependent on the board being
141 configured.
142 ----------------------------------------------------------------------- */
143
144
145 #ifdef MODULE
146 int init_module(void);
147 void cleanup_module(void);
148 #endif /* MODULE */
149
150 static inline void memwinon(struct board_info *b, unsigned int win);
151 static inline void memwinoff(struct board_info *b, unsigned int win);
152 static inline void globalwinon(struct channel *ch);
153 static inline void rxwinon(struct channel *ch);
154 static inline void txwinon(struct channel *ch);
155 static inline void memoff(struct channel *ch);
156 static inline void assertgwinon(struct channel *ch);
157 static inline void assertmemoff(struct channel *ch);
158
159 /* ---- Begin more 'specific' memory functions for cx_like products --- */
160
161 static inline void pcxem_memwinon(struct board_info *b, unsigned int win);
162 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win);
163 static inline void pcxem_globalwinon(struct channel *ch);
164 static inline void pcxem_rxwinon(struct channel *ch);
165 static inline void pcxem_txwinon(struct channel *ch);
166 static inline void pcxem_memoff(struct channel *ch);
167
168 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
169
170 static inline void pcxe_memwinon(struct board_info *b, unsigned int win);
171 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win);
172 static inline void pcxe_globalwinon(struct channel *ch);
173 static inline void pcxe_rxwinon(struct channel *ch);
174 static inline void pcxe_txwinon(struct channel *ch);
175 static inline void pcxe_memoff(struct channel *ch);
176
177 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
178 /* Note : pc64xe and pcxi share the same windowing routines */
179
180 static inline void pcxi_memwinon(struct board_info *b, unsigned int win);
181 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win);
182 static inline void pcxi_globalwinon(struct channel *ch);
183 static inline void pcxi_rxwinon(struct channel *ch);
184 static inline void pcxi_txwinon(struct channel *ch);
185 static inline void pcxi_memoff(struct channel *ch);
186
187 /* - Begin 'specific' do nothing memory functions needed for some cards - */
188
189 static inline void dummy_memwinon(struct board_info *b, unsigned int win);
190 static inline void dummy_memwinoff(struct board_info *b, unsigned int win);
191 static inline void dummy_globalwinon(struct channel *ch);
192 static inline void dummy_rxwinon(struct channel *ch);
193 static inline void dummy_txwinon(struct channel *ch);
194 static inline void dummy_memoff(struct channel *ch);
195 static inline void dummy_assertgwinon(struct channel *ch);
196 static inline void dummy_assertmemoff(struct channel *ch);
197
198 /* ------------------- Begin declare functions ----------------------- */
199
200 static inline struct channel *verifyChannel(register struct tty_struct *);
201 static inline void pc_sched_event(struct channel *, int);
202 static void epca_error(int, char *);
203 static void pc_close(struct tty_struct *, struct file *);
204 static void shutdown(struct channel *);
205 static void pc_hangup(struct tty_struct *);
206 static void pc_put_char(struct tty_struct *, unsigned char);
207 static int pc_write_room(struct tty_struct *);
208 static int pc_chars_in_buffer(struct tty_struct *);
209 static void pc_flush_buffer(struct tty_struct *);
210 static void pc_flush_chars(struct tty_struct *);
211 static int block_til_ready(struct tty_struct *, struct file *,
212 struct channel *);
213 static int pc_open(struct tty_struct *, struct file *);
214 static void post_fep_init(unsigned int crd);
215 static void epcapoll(unsigned long);
216 static void doevent(int);
217 static void fepcmd(struct channel *, int, int, int, int, int);
218 static unsigned termios2digi_h(struct channel *ch, unsigned);
219 static unsigned termios2digi_i(struct channel *ch, unsigned);
220 static unsigned termios2digi_c(struct channel *ch, unsigned);
221 static void epcaparam(struct tty_struct *, struct channel *);
222 static void receive_data(struct channel *);
223 static int pc_ioctl(struct tty_struct *, struct file *,
224 unsigned int, unsigned long);
225 static void pc_set_termios(struct tty_struct *, struct termios *);
226 static void do_softint(void *);
227 static void pc_stop(struct tty_struct *);
228 static void pc_start(struct tty_struct *);
229 static void pc_throttle(struct tty_struct * tty);
230 static void pc_unthrottle(struct tty_struct *tty);
231 static void digi_send_break(struct channel *ch, int msec);
232 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
233 void epca_setup(char *, int *);
234 void console_print(const char *);
235
236 static int get_termio(struct tty_struct *, struct termio *);
237 static int pc_write(struct tty_struct *, int, const unsigned char *, int);
238 int pc_init(void);
239
240 #ifdef ENABLE_PCI
241 static int init_PCI(void);
242 #endif /* ENABLE_PCI */
243
244
245 /* ------------------------------------------------------------------
246 Table of functions for each board to handle memory. Mantaining
247 parallelism is a *very* good idea here. The idea is for the
248 runtime code to blindly call these functions, not knowing/caring
249 about the underlying hardware. This stuff should contain no
250 conditionals; if more functionality is needed a different entry
251 should be established. These calls are the interface calls and
252 are the only functions that should be accessed. Anyone caught
253 making direct calls deserves what they get.
254 -------------------------------------------------------------------- */
255
256 static inline void memwinon(struct board_info *b, unsigned int win)
257 {
258 (b->memwinon)(b, win);
259 }
260
261 static inline void memwinoff(struct board_info *b, unsigned int win)
262 {
263 (b->memwinoff)(b, win);
264 }
265
266 static inline void globalwinon(struct channel *ch)
267 {
268 (ch->board->globalwinon)(ch);
269 }
270
271 static inline void rxwinon(struct channel *ch)
272 {
273 (ch->board->rxwinon)(ch);
274 }
275
276 static inline void txwinon(struct channel *ch)
277 {
278 (ch->board->txwinon)(ch);
279 }
280
281 static inline void memoff(struct channel *ch)
282 {
283 (ch->board->memoff)(ch);
284 }
285 static inline void assertgwinon(struct channel *ch)
286 {
287 (ch->board->assertgwinon)(ch);
288 }
289
290 static inline void assertmemoff(struct channel *ch)
291 {
292 (ch->board->assertmemoff)(ch);
293 }
294
295 /* ---------------------------------------------------------
296 PCXEM windowing is the same as that used in the PCXR
297 and CX series cards.
298 ------------------------------------------------------------ */
299
300 static inline void pcxem_memwinon(struct board_info *b, unsigned int win)
301 {
302 outb_p(FEPWIN|win, (int)b->port + 1);
303 }
304
305 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win)
306 {
307 outb_p(0, (int)b->port + 1);
308 }
309
310 static inline void pcxem_globalwinon(struct channel *ch)
311 {
312 outb_p( FEPWIN, (int)ch->board->port + 1);
313 }
314
315 static inline void pcxem_rxwinon(struct channel *ch)
316 {
317 outb_p(ch->rxwin, (int)ch->board->port + 1);
318 }
319
320 static inline void pcxem_txwinon(struct channel *ch)
321 {
322 outb_p(ch->txwin, (int)ch->board->port + 1);
323 }
324
325 static inline void pcxem_memoff(struct channel *ch)
326 {
327 outb_p(0, (int)ch->board->port + 1);
328 }
329
330 /* ----------------- Begin pcxe memory window stuff ------------------ */
331
332 static inline void pcxe_memwinon(struct board_info *b, unsigned int win)
333 {
334 outb_p(FEPWIN | win, (int)b->port + 1);
335 }
336
337 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win)
338 {
339 outb_p(inb((int)b->port) & ~FEPMEM,
340 (int)b->port + 1);
341 outb_p(0, (int)b->port + 1);
342 }
343
344 static inline void pcxe_globalwinon(struct channel *ch)
345 {
346 outb_p( FEPWIN, (int)ch->board->port + 1);
347 }
348
349 static inline void pcxe_rxwinon(struct channel *ch)
350 {
351 outb_p(ch->rxwin, (int)ch->board->port + 1);
352 }
353
354 static inline void pcxe_txwinon(struct channel *ch)
355 {
356 outb_p(ch->txwin, (int)ch->board->port + 1);
357 }
358
359 static inline void pcxe_memoff(struct channel *ch)
360 {
361 outb_p(0, (int)ch->board->port);
362 outb_p(0, (int)ch->board->port + 1);
363 }
364
365 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
366
367 static inline void pcxi_memwinon(struct board_info *b, unsigned int win)
368 {
369 outb_p(inb((int)b->port) | FEPMEM, (int)b->port);
370 }
371
372 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win)
373 {
374 outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port);
375 }
376
377 static inline void pcxi_globalwinon(struct channel *ch)
378 {
379 outb_p(FEPMEM, (int)ch->board->port);
380 }
381
382 static inline void pcxi_rxwinon(struct channel *ch)
383 {
384 outb_p(FEPMEM, (int)ch->board->port);
385 }
386
387 static inline void pcxi_txwinon(struct channel *ch)
388 {
389 outb_p(FEPMEM, (int)ch->board->port);
390 }
391
392 static inline void pcxi_memoff(struct channel *ch)
393 {
394 outb_p(0, (int)ch->board->port);
395 }
396
397 static inline void pcxi_assertgwinon(struct channel *ch)
398 {
399 epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off");
400 }
401
402 static inline void pcxi_assertmemoff(struct channel *ch)
403 {
404 epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on");
405 }
406
407
408 /* ----------------------------------------------------------------------
409 Not all of the cards need specific memory windowing routines. Some
410 cards (Such as PCI) needs no windowing routines at all. We provide
411 these do nothing routines so that the same code base can be used.
412 The driver will ALWAYS call a windowing routine if it thinks it needs
413 to; regardless of the card. However, dependent on the card the routine
414 may or may not do anything.
415 ---------------------------------------------------------------------------*/
416
417 static inline void dummy_memwinon(struct board_info *b, unsigned int win)
418 {
419 }
420
421 static inline void dummy_memwinoff(struct board_info *b, unsigned int win)
422 {
423 }
424
425 static inline void dummy_globalwinon(struct channel *ch)
426 {
427 }
428
429 static inline void dummy_rxwinon(struct channel *ch)
430 {
431 }
432
433 static inline void dummy_txwinon(struct channel *ch)
434 {
435 }
436
437 static inline void dummy_memoff(struct channel *ch)
438 {
439 }
440
441 static inline void dummy_assertgwinon(struct channel *ch)
442 {
443 }
444
445 static inline void dummy_assertmemoff(struct channel *ch)
446 {
447 }
448
449 /* ----------------- Begin verifyChannel function ----------------------- */
450 static inline struct channel *verifyChannel(register struct tty_struct *tty)
451 { /* Begin verifyChannel */
452
453 /* --------------------------------------------------------------------
454 This routine basically provides a sanity check. It insures that
455 the channel returned is within the proper range of addresses as
456 well as properly initialized. If some bogus info gets passed in
457 through tty->driver_data this should catch it.
458 --------------------------------------------------------------------- */
459
460 if (tty)
461 { /* Begin if tty */
462
463 register struct channel *ch = (struct channel *)tty->driver_data;
464
465 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs]))
466 {
467 if (ch->magic == EPCA_MAGIC)
468 return ch;
469 }
470
471 } /* End if tty */
472
473 /* Else return a NULL for invalid */
474 return NULL;
475
476 } /* End verifyChannel */
477
478 /* ------------------ Begin pc_sched_event ------------------------- */
479
480 static inline void pc_sched_event(struct channel *ch, int event)
481 { /* Begin pc_sched_event */
482
483
484 /* ----------------------------------------------------------------------
485 We call this to schedule interrupt processing on some event. The
486 kernel sees our request and calls the related routine in OUR driver.
487 -------------------------------------------------------------------------*/
488
489 ch->event |= 1 << event;
490 MOD_INC_USE_COUNT;
491 if (schedule_task(&ch->tqueue) == 0)
492 MOD_DEC_USE_COUNT;
493
494
495 } /* End pc_sched_event */
496
497 /* ------------------ Begin epca_error ------------------------- */
498
499 static void epca_error(int line, char *msg)
500 { /* Begin epca_error */
501
502 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
503 return;
504
505 } /* End epca_error */
506
507 /* ------------------ Begin pc_close ------------------------- */
508 static void pc_close(struct tty_struct * tty, struct file * filp)
509 { /* Begin pc_close */
510
511 struct channel *ch;
512 unsigned long flags;
513
514 if (tty->driver.subtype == SERIAL_TYPE_INFO)
515 {
516 return;
517 }
518
519
520 /* ---------------------------------------------------------
521 verifyChannel returns the channel from the tty struct
522 if it is valid. This serves as a sanity check.
523 ------------------------------------------------------------- */
524
525 if ((ch = verifyChannel(tty)) != NULL)
526 { /* Begin if ch != NULL */
527
528 save_flags(flags);
529 cli();
530
531 if (tty_hung_up_p(filp))
532 {
533 restore_flags(flags);
534 return;
535 }
536
537 /* Check to see if the channel is open more than once */
538 if (ch->count-- > 1)
539 { /* Begin channel is open more than once */
540
541 /* -------------------------------------------------------------
542 Return without doing anything. Someone might still be using
543 the channel.
544 ---------------------------------------------------------------- */
545
546 restore_flags(flags);
547 return;
548 } /* End channel is open more than once */
549
550 /* Port open only once go ahead with shutdown & reset */
551
552 if (ch->count < 0)
553 {
554 ch->count = 0;
555 }
556
557 /* ---------------------------------------------------------------
558 Let the rest of the driver know the channel is being closed.
559 This becomes important if an open is attempted before close
560 is finished.
561 ------------------------------------------------------------------ */
562
563 ch->asyncflags |= ASYNC_CLOSING;
564
565 /* -------------------------------------------------------------
566 Save the termios structure, since this port may have
567 separate termios for callout and dialin.
568 --------------------------------------------------------------- */
569
570 if (ch->asyncflags & ASYNC_NORMAL_ACTIVE)
571 ch->normal_termios = *tty->termios;
572
573 if (ch->asyncflags & ASYNC_CALLOUT_ACTIVE)
574 ch->callout_termios = *tty->termios;
575
576 tty->closing = 1;
577
578 if (ch->asyncflags & ASYNC_INITIALIZED)
579 {
580 /* Setup an event to indicate when the transmit buffer empties */
581 setup_empty_event(tty, ch);
582 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
583 }
584
585 if (tty->driver.flush_buffer)
586 tty->driver.flush_buffer(tty);
587
588 if (tty->ldisc.flush_buffer)
589 tty->ldisc.flush_buffer(tty);
590
591 shutdown(ch);
592 tty->closing = 0;
593 ch->event = 0;
594 ch->tty = NULL;
595
596 if (ch->blocked_open)
597 { /* Begin if blocked_open */
598
599 if (ch->close_delay)
600 {
601 current->state = TASK_INTERRUPTIBLE;
602 schedule_timeout(ch->close_delay);
603 }
604
605 wake_up_interruptible(&ch->open_wait);
606
607 } /* End if blocked_open */
608
609 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
610 ASYNC_CALLOUT_ACTIVE | ASYNC_CLOSING);
611 wake_up_interruptible(&ch->close_wait);
612
613 MOD_DEC_USE_COUNT;
614
615 restore_flags(flags);
616
617 } /* End if ch != NULL */
618
619 } /* End pc_close */
620
621 /* ------------------ Begin shutdown ------------------------- */
622
623 static void shutdown(struct channel *ch)
624 { /* Begin shutdown */
625
626 unsigned long flags;
627 struct tty_struct *tty;
628 volatile struct board_chan *bc;
629
630 if (!(ch->asyncflags & ASYNC_INITIALIZED))
631 return;
632
633 save_flags(flags);
634 cli();
635 globalwinon(ch);
636
637 bc = ch->brdchan;
638
639 /* ------------------------------------------------------------------
640 In order for an event to be generated on the receipt of data the
641 idata flag must be set. Since we are shutting down, this is not
642 necessary clear this flag.
643 --------------------------------------------------------------------- */
644
645 if (bc)
646 bc->idata = 0;
647
648 tty = ch->tty;
649
650 /* ----------------------------------------------------------------
651 If we're a modem control device and HUPCL is on, drop RTS & DTR.
652 ------------------------------------------------------------------ */
653
654 if (tty->termios->c_cflag & HUPCL)
655 {
656 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
657 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
658 }
659
660 memoff(ch);
661
662 /* ------------------------------------------------------------------
663 The channel has officialy been closed. The next time it is opened
664 it will have to reinitialized. Set a flag to indicate this.
665 ---------------------------------------------------------------------- */
666
667 /* Prevent future Digi programmed interrupts from coming active */
668
669 ch->asyncflags &= ~ASYNC_INITIALIZED;
670 restore_flags(flags);
671
672 } /* End shutdown */
673
674 /* ------------------ Begin pc_hangup ------------------------- */
675
676 static void pc_hangup(struct tty_struct *tty)
677 { /* Begin pc_hangup */
678
679 struct channel *ch;
680
681 /* ---------------------------------------------------------
682 verifyChannel returns the channel from the tty struct
683 if it is valid. This serves as a sanity check.
684 ------------------------------------------------------------- */
685
686 if ((ch = verifyChannel(tty)) != NULL)
687 { /* Begin if ch != NULL */
688
689 unsigned long flags;
690
691 save_flags(flags);
692 cli();
693 if (tty->driver.flush_buffer)
694 tty->driver.flush_buffer(tty);
695
696 if (tty->ldisc.flush_buffer)
697 tty->ldisc.flush_buffer(tty);
698
699 shutdown(ch);
700
701 if (ch->count)
702 MOD_DEC_USE_COUNT;
703
704
705 ch->tty = NULL;
706 ch->event = 0;
707 ch->count = 0;
708 restore_flags(flags);
709 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | ASYNC_CALLOUT_ACTIVE);
710 wake_up_interruptible(&ch->open_wait);
711
712 } /* End if ch != NULL */
713
714 } /* End pc_hangup */
715
716 /* ------------------ Begin pc_write ------------------------- */
717
718 static int pc_write(struct tty_struct * tty, int from_user,
719 const unsigned char *buf, int bytesAvailable)
720 { /* Begin pc_write */
721
722 register unsigned int head, tail;
723 register int dataLen;
724 register int size;
725 register int amountCopied;
726
727
728 struct channel *ch;
729 unsigned long flags;
730 int remain;
731 volatile struct board_chan *bc;
732
733
734 /* ----------------------------------------------------------------
735 pc_write is primarily called directly by the kernel routine
736 tty_write (Though it can also be called by put_char) found in
737 tty_io.c. pc_write is passed a line discipline buffer where
738 the data to be written out is stored. The line discipline
739 implementation itself is done at the kernel level and is not
740 brought into the driver.
741 ------------------------------------------------------------------- */
742
743 /* Stop users from hurting themselves on control minor */
744
745 if (tty->driver.subtype == SERIAL_TYPE_INFO)
746 {
747 return (0) ;
748 }
749
750 /* ---------------------------------------------------------
751 verifyChannel returns the channel from the tty struct
752 if it is valid. This serves as a sanity check.
753 ------------------------------------------------------------- */
754
755 if ((ch = verifyChannel(tty)) == NULL)
756 return 0;
757
758 /* Make a pointer to the channel data structure found on the board. */
759
760 bc = ch->brdchan;
761 size = ch->txbufsize;
762
763 if (from_user)
764 { /* Begin from_user */
765
766 save_flags(flags);
767 cli();
768
769 globalwinon(ch);
770
771 /* -----------------------------------------------------------------
772 Anding against size will wrap the pointer back to its beginning
773 position if it is necessary. This will only work if size is
774 a power of 2 which should always be the case. Size is determined
775 by the cards on board FEP/OS.
776 -------------------------------------------------------------------- */
777
778 /* head refers to the next empty location in which data may be stored */
779
780 head = bc->tin & (size - 1);
781
782 /* tail refers to the next data byte to be transmitted */
783
784 tail = bc->tout;
785
786 /* Consider changing this to a do statement to make sure */
787
788 if (tail != bc->tout)
789 tail = bc->tout;
790
791 /* ------------------------------------------------------------------
792 Anding against size will wrap the pointer back to its beginning
793 position if it is necessary. This will only work if size is
794 a power of 2 which should always be the case. Size is determined
795 by the cards on board FEP/OS.
796 --------------------------------------------------------------------- */
797
798 tail &= (size - 1);
799
800 /* -----------------------------------------------------------------
801 Two situations can affect how space in the transmit buffer
802 is calculated. You can have a situation where the transmit
803 in pointer (tin) head has wrapped around and actually has a
804 lower address than the transmit out pointer (tout) tail; or
805 the transmit in pointer (tin) head will not be wrapped around
806 yet, and have a higher address than the transmit out pointer
807 (tout) tail. Obviously space available in the transmit buffer
808 is calculated differently for each case.
809
810 Example 1:
811
812 Consider a 10 byte buffer where head is a pointer to the next
813 empty location in the buffer and tail is a pointer to the next
814 byte to transmit. In this example head will not have wrapped
815 around and therefore head > tail.
816
817 0 1 2 3 4 5 6 7 8 9
818 tail head
819
820 The above diagram shows that buffer locations 2,3,4,5 and 6 have
821 data to be transmitted, while head points at the next empty
822 location. To calculate how much space is available first we have
823 to determine if the head pointer (tin) has wrapped. To do this
824 compare the head pointer to the tail pointer, If head is equal
825 or greater than tail; then it has not wrapped; and the space may
826 be calculated by subtracting tail from head and then subtracting
827 that value from the buffers size. A one is subtracted from the
828 new value to indicate how much space is available between the
829 head pointer and end of buffer; as well as the space between the
830 beginning of the buffer and the tail. If the head is not greater
831 or equal to the tail this indicates that the head has wrapped
832 around to the beginning of the buffer. To calculate the space
833 available in this case simply subtract head from tail. This new
834 value minus one represents the space available betwwen the head
835 and tail pointers. In this example head (7) is greater than tail (2)
836 and therefore has not wrapped around. We find the space by first
837 subtracting tail from head (7-2=5). We then subtract this value
838 from the buffer size of ten and subtract one (10-5-1=4). The space
839 remaining is 4 bytes.
840
841 Example 2:
842
843 Consider a 10 byte buffer where head is a pointer to the next
844 empty location in the buffer and tail is a pointer to the next
845 byte to transmit. In this example head will wrapped around and
846 therefore head < tail.
847
848 0 1 2 3 4 5 6 7 8 9
849 head tail
850
851 The above diagram shows that buffer locations 7,8,9,0 and 1 have
852 data to be transmitted, while head points at the next empty
853 location. To find the space available we compare head to tail. If
854 head is not equal to, or greater than tail this indicates that head
855 has wrapped around. In this case head (2) is not equal to, or
856 greater than tail (7) and therefore has already wrapped around. To
857 calculate the available space between the two pointers we subtract
858 head from tail (7-2=5). We then subtract one from this new value
859 (5-1=4). We have 5 bytes empty remaining in the buffer. Unlike the
860 previous example these five bytes are located between the head and
861 tail pointers.
862
863 ----------------------------------------------------------------------- */
864
865 dataLen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1);
866
867 /* ----------------------------------------------------------------------
868 In this case bytesAvailable has been passed into pc_write and
869 represents the amount of data that needs to be written. dataLen
870 represents the amount of space available on the card. Whichever
871 value is smaller will be the amount actually written.
872 bytesAvailable will then take on this newly calculated value.
873 ---------------------------------------------------------------------- */
874
875 bytesAvailable = MIN(dataLen, bytesAvailable);
876
877 /* First we read the data in from the file system into a temp buffer */
878
879 memoff(ch);
880 restore_flags(flags);
881
882 if (bytesAvailable)
883 { /* Begin bytesAvailable */
884
885 /* Can the user buffer be accessed at the moment ? */
886 if (verify_area(VERIFY_READ, (char*)buf, bytesAvailable))
887 bytesAvailable = 0; /* Can't do; try again later */
888 else /* Evidently it can, began transmission */
889 { /* Begin if area verified */
890 /* ---------------------------------------------------------------
891 The below function reads data from user memory. This routine
892 can not be used in an interrupt routine. (Because it may
893 generate a page fault) It can only be called while we can the
894 user context is accessible.
895
896 The prototype is :
897 inline void copy_from_user(void * to, const void * from,
898 unsigned long count);
899
900 You must include <asm/segment.h>
901 I also think (Check hackers guide) that optimization must
902 be turned ON. (Which sounds strange to me...)
903
904 Remember copy_from_user WILL generate a page fault if the
905 user memory being accessed has been swapped out. This can
906 cause this routine to temporarily sleep while this page
907 fault is occuring.
908
909 ----------------------------------------------------------------- */
910
911 copy_from_user(ch->tmp_buf, buf, bytesAvailable);
912
913 } /* End if area verified */
914
915 } /* End bytesAvailable */
916
917 /* ------------------------------------------------------------------
918 Set buf to this address for the moment. tmp_buf was allocated in
919 post_fep_init.
920 --------------------------------------------------------------------- */
921 buf = ch->tmp_buf;
922
923 } /* End from_user */
924
925 /* All data is now local */
926
927 amountCopied = 0;
928 save_flags(flags);
929 cli();
930
931 globalwinon(ch);
932
933 head = bc->tin & (size - 1);
934 tail = bc->tout;
935
936 if (tail != bc->tout)
937 tail = bc->tout;
938 tail &= (size - 1);
939
940 /* If head >= tail, head has not wrapped around. */
941 if (head >= tail)
942 { /* Begin head has not wrapped */
943
944 /* ---------------------------------------------------------------
945 remain (much like dataLen above) represents the total amount of
946 space available on the card for data. Here dataLen represents
947 the space existing between the head pointer and the end of
948 buffer. This is important because a memcpy cannot be told to
949 automatically wrap around when it hits the buffer end.
950 ------------------------------------------------------------------ */
951
952 dataLen = size - head;
953 remain = size - (head - tail) - 1;
954
955 } /* End head has not wrapped */
956 else
957 { /* Begin head has wrapped around */
958
959 remain = tail - head - 1;
960 dataLen = remain;
961
962 } /* End head has wrapped around */
963
964 /* -------------------------------------------------------------------
965 Check the space on the card. If we have more data than
966 space; reduce the amount of data to fit the space.
967 ---------------------------------------------------------------------- */
968
969 bytesAvailable = MIN(remain, bytesAvailable);
970
971 txwinon(ch);
972 while (bytesAvailable > 0)
973 { /* Begin while there is data to copy onto card */
974
975 /* -----------------------------------------------------------------
976 If head is not wrapped, the below will make sure the first
977 data copy fills to the end of card buffer.
978 ------------------------------------------------------------------- */
979
980 dataLen = MIN(bytesAvailable, dataLen);
981 memcpy(ch->txptr + head, buf, dataLen);
982 buf += dataLen;
983 head += dataLen;
984 amountCopied += dataLen;
985 bytesAvailable -= dataLen;
986
987 if (head >= size)
988 {
989 head = 0;
990 dataLen = tail;
991 }
992
993 } /* End while there is data to copy onto card */
994
995 ch->statusflags |= TXBUSY;
996 globalwinon(ch);
997 bc->tin = head;
998
999 if ((ch->statusflags & LOWWAIT) == 0)
1000 {
1001 ch->statusflags |= LOWWAIT;
1002 bc->ilow = 1;
1003 }
1004 memoff(ch);
1005 restore_flags(flags);
1006
1007 return(amountCopied);
1008
1009 } /* End pc_write */
1010
1011 /* ------------------ Begin pc_put_char ------------------------- */
1012
1013 static void pc_put_char(struct tty_struct *tty, unsigned char c)
1014 { /* Begin pc_put_char */
1015
1016
1017 pc_write(tty, 0, &c, 1);
1018 return;
1019
1020 } /* End pc_put_char */
1021
1022 /* ------------------ Begin pc_write_room ------------------------- */
1023
1024 static int pc_write_room(struct tty_struct *tty)
1025 { /* Begin pc_write_room */
1026
1027 int remain;
1028 struct channel *ch;
1029 unsigned long flags;
1030 unsigned int head, tail;
1031 volatile struct board_chan *bc;
1032
1033 remain = 0;
1034
1035 /* ---------------------------------------------------------
1036 verifyChannel returns the channel from the tty struct
1037 if it is valid. This serves as a sanity check.
1038 ------------------------------------------------------------- */
1039
1040 if ((ch = verifyChannel(tty)) != NULL)
1041 {
1042 save_flags(flags);
1043 cli();
1044 globalwinon(ch);
1045
1046 bc = ch->brdchan;
1047 head = bc->tin & (ch->txbufsize - 1);
1048 tail = bc->tout;
1049
1050 if (tail != bc->tout)
1051 tail = bc->tout;
1052 /* Wrap tail if necessary */
1053 tail &= (ch->txbufsize - 1);
1054
1055 if ((remain = tail - head - 1) < 0 )
1056 remain += ch->txbufsize;
1057
1058 if (remain && (ch->statusflags & LOWWAIT) == 0)
1059 {
1060 ch->statusflags |= LOWWAIT;
1061 bc->ilow = 1;
1062 }
1063 memoff(ch);
1064 restore_flags(flags);
1065 }
1066
1067 /* Return how much room is left on card */
1068 return remain;
1069
1070 } /* End pc_write_room */
1071
1072 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
1073
1074 static int pc_chars_in_buffer(struct tty_struct *tty)
1075 { /* Begin pc_chars_in_buffer */
1076
1077 int chars;
1078 unsigned int ctail, head, tail;
1079 int remain;
1080 unsigned long flags;
1081 struct channel *ch;
1082 volatile struct board_chan *bc;
1083
1084
1085 /* ---------------------------------------------------------
1086 verifyChannel returns the channel from the tty struct
1087 if it is valid. This serves as a sanity check.
1088 ------------------------------------------------------------- */
1089
1090 if ((ch = verifyChannel(tty)) == NULL)
1091 return(0);
1092
1093 save_flags(flags);
1094 cli();
1095 globalwinon(ch);
1096
1097 bc = ch->brdchan;
1098 tail = bc->tout;
1099 head = bc->tin;
1100 ctail = ch->mailbox->cout;
1101
1102 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
1103 chars = 0;
1104 else
1105 { /* Begin if some space on the card has been used */
1106
1107 head = bc->tin & (ch->txbufsize - 1);
1108 tail &= (ch->txbufsize - 1);
1109
1110 /* --------------------------------------------------------------
1111 The logic here is basically opposite of the above pc_write_room
1112 here we are finding the amount of bytes in the buffer filled.
1113 Not the amount of bytes empty.
1114 ------------------------------------------------------------------- */
1115
1116 if ((remain = tail - head - 1) < 0 )
1117 remain += ch->txbufsize;
1118
1119 chars = (int)(ch->txbufsize - remain);
1120
1121 /* -------------------------------------------------------------
1122 Make it possible to wakeup anything waiting for output
1123 in tty_ioctl.c, etc.
1124
1125 If not already set. Setup an event to indicate when the
1126 transmit buffer empties
1127 ----------------------------------------------------------------- */
1128
1129 if (!(ch->statusflags & EMPTYWAIT))
1130 setup_empty_event(tty,ch);
1131
1132 } /* End if some space on the card has been used */
1133
1134 memoff(ch);
1135 restore_flags(flags);
1136
1137 /* Return number of characters residing on card. */
1138 return(chars);
1139
1140 } /* End pc_chars_in_buffer */
1141
1142 /* ------------------ Begin pc_flush_buffer ---------------------- */
1143
1144 static void pc_flush_buffer(struct tty_struct *tty)
1145 { /* Begin pc_flush_buffer */
1146
1147 unsigned int tail;
1148 unsigned long flags;
1149 struct channel *ch;
1150 volatile struct board_chan *bc;
1151
1152
1153 /* ---------------------------------------------------------
1154 verifyChannel returns the channel from the tty struct
1155 if it is valid. This serves as a sanity check.
1156 ------------------------------------------------------------- */
1157
1158 if ((ch = verifyChannel(tty)) == NULL)
1159 return;
1160
1161 save_flags(flags);
1162 cli();
1163
1164 globalwinon(ch);
1165
1166 bc = ch->brdchan;
1167 tail = bc->tout;
1168
1169 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1170
1171 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1172
1173 memoff(ch);
1174 restore_flags(flags);
1175
1176 wake_up_interruptible(&tty->write_wait);
1177 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1178 (tty->ldisc.write_wakeup)(tty);
1179
1180 } /* End pc_flush_buffer */
1181
1182 /* ------------------ Begin pc_flush_chars ---------------------- */
1183
1184 static void pc_flush_chars(struct tty_struct *tty)
1185 { /* Begin pc_flush_chars */
1186
1187 struct channel * ch;
1188
1189 /* ---------------------------------------------------------
1190 verifyChannel returns the channel from the tty struct
1191 if it is valid. This serves as a sanity check.
1192 ------------------------------------------------------------- */
1193
1194 if ((ch = verifyChannel(tty)) != NULL)
1195 {
1196 unsigned long flags;
1197
1198 save_flags(flags);
1199 cli();
1200
1201 /* ----------------------------------------------------------------
1202 If not already set and the transmitter is busy setup an event
1203 to indicate when the transmit empties.
1204 ------------------------------------------------------------------- */
1205
1206 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
1207 setup_empty_event(tty,ch);
1208
1209 restore_flags(flags);
1210 }
1211
1212 } /* End pc_flush_chars */
1213
1214 /* ------------------ Begin block_til_ready ---------------------- */
1215
1216 static int block_til_ready(struct tty_struct *tty,
1217 struct file *filp, struct channel *ch)
1218 { /* Begin block_til_ready */
1219
1220 DECLARE_WAITQUEUE(wait,current);
1221 int retval, do_clocal = 0;
1222 unsigned long flags;
1223
1224
1225 if (tty_hung_up_p(filp))
1226 {
1227 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1228 retval = -EAGAIN;
1229 else
1230 retval = -ERESTARTSYS;
1231 return(retval);
1232 }
1233
1234 /* -----------------------------------------------------------------
1235 If the device is in the middle of being closed, then block
1236 until it's done, and then try again.
1237 -------------------------------------------------------------------- */
1238 if (ch->asyncflags & ASYNC_CLOSING)
1239 {
1240 interruptible_sleep_on(&ch->close_wait);
1241
1242 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1243 return -EAGAIN;
1244 else
1245 return -ERESTARTSYS;
1246 }
1247
1248 /* -----------------------------------------------------------------
1249 If this is a callout device, then just make sure the normal
1250 device isn't being used.
1251 -------------------------------------------------------------------- */
1252
1253 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT)
1254 { /* A cud device has been opened */
1255 if (ch->asyncflags & ASYNC_NORMAL_ACTIVE)
1256 return -EBUSY;
1257
1258 if ((ch->asyncflags & ASYNC_CALLOUT_ACTIVE) &&
1259 (ch->asyncflags & ASYNC_SESSION_LOCKOUT) &&
1260 (ch->session != current->session))
1261 return -EBUSY;
1262
1263 if ((ch->asyncflags & ASYNC_CALLOUT_ACTIVE) &&
1264 (ch->asyncflags & ASYNC_PGRP_LOCKOUT) &&
1265 (ch->pgrp != current->pgrp))
1266 return -EBUSY;
1267
1268 ch->asyncflags |= ASYNC_CALLOUT_ACTIVE;
1269
1270 return 0;
1271 } /* End a cud device has been opened */
1272
1273 if (filp->f_flags & O_NONBLOCK)
1274 {
1275 /* -----------------------------------------------------------------
1276 If non-blocking mode is set, then make the check up front
1277 and then exit.
1278 -------------------------------------------------------------------- */
1279
1280 if (ch->asyncflags & ASYNC_CALLOUT_ACTIVE)
1281 return -EBUSY;
1282
1283 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1284
1285 return 0;
1286 }
1287
1288
1289 if (ch->asyncflags & ASYNC_CALLOUT_ACTIVE)
1290 {
1291 if (ch->normal_termios.c_cflag & CLOCAL)
1292 do_clocal = 1;
1293 }
1294 else
1295 {
1296 if (tty->termios->c_cflag & CLOCAL)
1297 do_clocal = 1;
1298 }
1299
1300 /* Block waiting for the carrier detect and the line to become free */
1301
1302 retval = 0;
1303 add_wait_queue(&ch->open_wait, &wait);
1304 save_flags(flags);
1305 cli();
1306
1307
1308 /* We dec count so that pc_close will know when to free things */
1309 if (!tty_hung_up_p(filp))
1310 ch->count--;
1311
1312 restore_flags(flags);
1313
1314 ch->blocked_open++;
1315
1316 while(1)
1317 { /* Begin forever while */
1318
1319 set_current_state(TASK_INTERRUPTIBLE);
1320
1321 if (tty_hung_up_p(filp) ||
1322 !(ch->asyncflags & ASYNC_INITIALIZED))
1323 {
1324 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1325 retval = -EAGAIN;
1326 else
1327 retval = -ERESTARTSYS;
1328 break;
1329 }
1330
1331 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1332 !(ch->asyncflags & ASYNC_CALLOUT_ACTIVE) &&
1333 (do_clocal || (ch->imodem & ch->dcd)))
1334 break;
1335
1336 if (signal_pending(current))
1337 {
1338 retval = -ERESTARTSYS;
1339 break;
1340 }
1341
1342 /* ---------------------------------------------------------------
1343 Allow someone else to be scheduled. We will occasionally go
1344 through this loop until one of the above conditions change.
1345 The below schedule call will allow other processes to enter and
1346 prevent this loop from hogging the cpu.
1347 ------------------------------------------------------------------ */
1348 schedule();
1349
1350 } /* End forever while */
1351
1352 current->state = TASK_RUNNING;
1353 remove_wait_queue(&ch->open_wait, &wait);
1354 cli();
1355 if (!tty_hung_up_p(filp))
1356 ch->count++;
1357 restore_flags(flags);
1358
1359 ch->blocked_open--;
1360
1361 if (retval)
1362 return retval;
1363
1364 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1365
1366 return 0;
1367
1368 } /* End block_til_ready */
1369
1370 /* ------------------ Begin pc_open ---------------------- */
1371
1372 static int pc_open(struct tty_struct *tty, struct file * filp)
1373 { /* Begin pc_open */
1374
1375 struct channel *ch;
1376 unsigned long flags;
1377 int line, retval, boardnum;
1378 volatile struct board_chan *bc;
1379 volatile unsigned int head;
1380
1381 /* Nothing "real" happens in open of control device */
1382
1383 if (tty->driver.subtype == SERIAL_TYPE_INFO)
1384 {
1385 return (0) ;
1386 }
1387
1388 line = MINOR(tty->device) - tty->driver.minor_start;
1389 if (line < 0 || line >= nbdevs)
1390 {
1391 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1392 tty->driver_data = NULL;
1393 return(-ENODEV);
1394 }
1395
1396
1397 MOD_INC_USE_COUNT;
1398
1399 ch = &digi_channels[line];
1400 boardnum = ch->boardnum;
1401
1402 /* Check status of board configured in system. */
1403
1404 /* -----------------------------------------------------------------
1405 I check to see if the epca_setup routine detected an user error.
1406 It might be better to put this in pc_init, but for the moment it
1407 goes here.
1408 ---------------------------------------------------------------------- */
1409
1410 if (invalid_lilo_config)
1411 {
1412 if (setup_error_code & INVALID_BOARD_TYPE)
1413 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n");
1414
1415 if (setup_error_code & INVALID_NUM_PORTS)
1416 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1417
1418 if (setup_error_code & INVALID_MEM_BASE)
1419 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1420
1421 if (setup_error_code & INVALID_PORT_BASE)
1422 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n");
1423
1424 if (setup_error_code & INVALID_BOARD_STATUS)
1425 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n");
1426
1427 if (setup_error_code & INVALID_ALTPIN)
1428 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1429
1430 tty->driver_data = NULL; /* Mark this device as 'down' */
1431 return(-ENODEV);
1432 }
1433
1434 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1435 {
1436 tty->driver_data = NULL; /* Mark this device as 'down' */
1437 return(-ENODEV);
1438 }
1439
1440 if (( bc = ch->brdchan) == 0)
1441 {
1442 tty->driver_data = NULL;
1443 return(-ENODEV);
1444 }
1445
1446 /* ------------------------------------------------------------------
1447 Every time a channel is opened, increment a counter. This is
1448 necessary because we do not wish to flush and shutdown the channel
1449 until the last app holding the channel open, closes it.
1450 --------------------------------------------------------------------- */
1451
1452 ch->count++;
1453
1454 /* ----------------------------------------------------------------
1455 Set a kernel structures pointer to our local channel
1456 structure. This way we can get to it when passed only
1457 a tty struct.
1458 ------------------------------------------------------------------ */
1459
1460 tty->driver_data = ch;
1461
1462 /* ----------------------------------------------------------------
1463 If this is the first time the channel has been opened, initialize
1464 the tty->termios struct otherwise let pc_close handle it.
1465 -------------------------------------------------------------------- */
1466
1467 /* Should this be here except for SPLIT termios ? */
1468 if (ch->count == 1)
1469 {
1470 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
1471 *tty->termios = ch->normal_termios;
1472 else
1473 *tty->termios = ch->callout_termios;
1474 }
1475
1476 ch->session = current->session;
1477 ch->pgrp = current->pgrp;
1478
1479 save_flags(flags);
1480 cli();
1481
1482 globalwinon(ch);
1483 ch->statusflags = 0;
1484
1485 /* Save boards current modem status */
1486 ch->imodem = bc->mstat;
1487
1488 /* ----------------------------------------------------------------
1489 Set receive head and tail ptrs to each other. This indicates
1490 no data available to read.
1491 ----------------------------------------------------------------- */
1492 head = bc->rin;
1493 bc->rout = head;
1494
1495 /* Set the channels associated tty structure */
1496 ch->tty = tty;
1497
1498 /* -----------------------------------------------------------------
1499 The below routine generally sets up parity, baud, flow control
1500 issues, etc.... It effect both control flags and input flags.
1501 -------------------------------------------------------------------- */
1502 epcaparam(tty,ch);
1503
1504 ch->asyncflags |= ASYNC_INITIALIZED;
1505 memoff(ch);
1506
1507 restore_flags(flags);
1508
1509 retval = block_til_ready(tty, filp, ch);
1510 if (retval)
1511 {
1512 return retval;
1513 }
1514
1515 /* -------------------------------------------------------------
1516 Set this again in case a hangup set it to zero while this
1517 open() was waiting for the line...
1518 --------------------------------------------------------------- */
1519 ch->tty = tty;
1520
1521 save_flags(flags);
1522 cli();
1523 globalwinon(ch);
1524
1525 /* Enable Digi Data events */
1526 bc->idata = 1;
1527
1528 memoff(ch);
1529 restore_flags(flags);
1530
1531 return 0;
1532
1533 } /* End pc_open */
1534
1535 #ifdef MODULE
1536 /* -------------------- Begin init_module ---------------------- */
1537 int __init init_module()
1538 { /* Begin init_module */
1539
1540 unsigned long flags;
1541
1542 save_flags(flags);
1543 cli();
1544
1545 pc_init();
1546
1547 restore_flags(flags);
1548
1549 return(0);
1550 } /* End init_module */
1551
1552 #endif
1553
1554 #ifdef ENABLE_PCI
1555 static struct pci_driver epca_driver;
1556 #endif
1557
1558 #ifdef MODULE
1559 /* -------------------- Begin cleanup_module ---------------------- */
1560
1561 void cleanup_module()
1562 { /* Begin cleanup_module */
1563
1564 int count, crd;
1565 struct board_info *bd;
1566 struct channel *ch;
1567 unsigned long flags;
1568
1569 del_timer_sync(&epca_timer);
1570
1571 save_flags(flags);
1572 cli();
1573
1574 if ((tty_unregister_driver(&pc_driver)) ||
1575 (tty_unregister_driver(&pc_callout)))
1576 {
1577 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1578 restore_flags(flags);
1579 return;
1580 }
1581
1582 for (crd = 0; crd < num_cards; crd++)
1583 { /* Begin for each card */
1584
1585 bd = &boards[crd];
1586
1587 if (!bd)
1588 { /* Begin sanity check */
1589 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1590 return;
1591 } /* End sanity check */
1592
1593 ch = card_ptr[crd];
1594
1595 for (count = 0; count < bd->numports; count++, ch++)
1596 { /* Begin for each port */
1597
1598 if (ch)
1599 {
1600 if (ch->tty)
1601 tty_hangup(ch->tty);
1602 kfree(ch->tmp_buf);
1603 }
1604
1605 } /* End for each port */
1606 } /* End for each card */
1607
1608 #ifdef ENABLE_PCI
1609 pci_unregister_driver (&epca_driver);
1610 #endif
1611
1612 restore_flags(flags);
1613
1614 } /* End cleanup_module */
1615 #endif /* MODULE */
1616
1617 /* ------------------ Begin pc_init ---------------------- */
1618
1619 int __init pc_init(void)
1620 { /* Begin pc_init */
1621
1622 /* ----------------------------------------------------------------
1623 pc_init is called by the operating system during boot up prior to
1624 any open calls being made. In the older versions of Linux (Prior
1625 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1626 memory location (from kernel space) used (kmem_start) is passed
1627 to pc_init. It is pc_inits responsibility to modify this value
1628 for any memory that the Digi driver might need and then return
1629 this value to the operating system. For example if the driver
1630 wishes to allocate 1K of kernel memory, pc_init would return
1631 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1632 + 1024) would then be available for use exclusively by the driver.
1633 In this case our driver does not allocate any of this kernel
1634 memory.
1635 ------------------------------------------------------------------*/
1636
1637 ulong flags;
1638 int crd;
1639 struct board_info *bd;
1640 unsigned char board_id = 0;
1641
1642
1643 #ifdef ENABLE_PCI
1644 int pci_boards_found, pci_count;
1645
1646 pci_count = 0;
1647 #endif /* ENABLE_PCI */
1648
1649 /* -----------------------------------------------------------------------
1650 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1651 board structure defined by digiConfig into drivers board structure.
1652 Note : If LILO has ran epca_setup then epca_setup will handle defining
1653 num_cards as well as copying the data into the board structure.
1654 -------------------------------------------------------------------------- */
1655 if (!liloconfig)
1656 { /* Begin driver has been configured via. epcaconfig */
1657
1658 nbdevs = NBDEVS;
1659 num_cards = NUMCARDS;
1660 memcpy((void *)&boards, (void *)&static_boards,
1661 (sizeof(struct board_info) * NUMCARDS));
1662 } /* End driver has been configured via. epcaconfig */
1663
1664 /* -----------------------------------------------------------------
1665 Note : If lilo was used to configure the driver and the
1666 ignore epcaconfig option was choosen (digiepca=2) then
1667 nbdevs and num_cards will equal 0 at this point. This is
1668 okay; PCI cards will still be picked up if detected.
1669 --------------------------------------------------------------------- */
1670
1671 /* -----------------------------------------------------------
1672 Set up interrupt, we will worry about memory allocation in
1673 post_fep_init.
1674 --------------------------------------------------------------- */
1675
1676
1677 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1678
1679 #ifdef ENABLE_PCI
1680
1681 /* ------------------------------------------------------------------
1682 NOTE : This code assumes that the number of ports found in
1683 the boards array is correct. This could be wrong if
1684 the card in question is PCI (And therefore has no ports
1685 entry in the boards structure.) The rest of the
1686 information will be valid for PCI because the beginning
1687 of pc_init scans for PCI and determines i/o and base
1688 memory addresses. I am not sure if it is possible to
1689 read the number of ports supported by the card prior to
1690 it being booted (Since that is the state it is in when
1691 pc_init is run). Because it is not possible to query the
1692 number of supported ports until after the card has booted;
1693 we are required to calculate the card_ptrs as the card is
1694 is initialized (Inside post_fep_init). The negative thing
1695 about this approach is that digiDload's call to GET_INFO
1696 will have a bad port value. (Since this is called prior
1697 to post_fep_init.)
1698
1699 --------------------------------------------------------------------- */
1700
1701 pci_boards_found = 0;
1702 if (pci_present())
1703 {
1704 if(num_cards < MAXBOARDS)
1705 pci_boards_found += init_PCI();
1706 num_cards += pci_boards_found;
1707 }
1708 else
1709 {
1710 printk(KERN_ERR "<Error> - No PCI BIOS found\n");
1711 }
1712
1713 #endif /* ENABLE_PCI */
1714
1715 memset(&pc_driver, 0, sizeof(struct tty_driver));
1716 memset(&pc_callout, 0, sizeof(struct tty_driver));
1717 memset(&pc_info, 0, sizeof(struct tty_driver));
1718
1719 pc_driver.magic = TTY_DRIVER_MAGIC;
1720 pc_driver.name = "ttyD";
1721 pc_driver.major = DIGI_MAJOR;
1722 pc_driver.minor_start = 0;
1723 pc_driver.num = MAX_ALLOC;
1724 pc_driver.type = TTY_DRIVER_TYPE_SERIAL;
1725 pc_driver.subtype = SERIAL_TYPE_NORMAL;
1726 pc_driver.init_termios = tty_std_termios;
1727 pc_driver.init_termios.c_iflag = 0;
1728 pc_driver.init_termios.c_oflag = 0;
1729
1730 pc_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1731 pc_driver.init_termios.c_lflag = 0;
1732 pc_driver.flags = TTY_DRIVER_REAL_RAW;
1733 pc_driver.refcount = &pc_refcount;
1734 pc_driver.table = pc_table;
1735
1736 /* pc_termios is an array of pointers pointing at termios structs */
1737 /* The below should get the first pointer */
1738 pc_driver.termios = pc_termios;
1739 pc_driver.termios_locked = pc_termios_locked;
1740
1741 /* ------------------------------------------------------------------
1742 Setup entry points for the driver. These are primarily called by
1743 the kernel in tty_io.c and n_tty.c
1744 --------------------------------------------------------------------- */
1745
1746 pc_driver.open = pc_open;
1747 pc_driver.close = pc_close;
1748 pc_driver.write = pc_write;
1749 pc_driver.write_room = pc_write_room;
1750 pc_driver.flush_buffer = pc_flush_buffer;
1751 pc_driver.chars_in_buffer = pc_chars_in_buffer;
1752 pc_driver.flush_chars = pc_flush_chars;
1753 pc_driver.put_char = pc_put_char;
1754 pc_driver.ioctl = pc_ioctl;
1755 pc_driver.set_termios = pc_set_termios;
1756 pc_driver.stop = pc_stop;
1757 pc_driver.start = pc_start;
1758 pc_driver.throttle = pc_throttle;
1759 pc_driver.unthrottle = pc_unthrottle;
1760 pc_driver.hangup = pc_hangup;
1761 pc_callout = pc_driver;
1762
1763 pc_callout.name = "cud";
1764 pc_callout.major = DIGICU_MAJOR;
1765 pc_callout.minor_start = 0;
1766 pc_callout.init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1767 pc_callout.subtype = SERIAL_TYPE_CALLOUT;
1768
1769 pc_info = pc_driver;
1770 pc_info.name = "digi_ctl";
1771 pc_info.major = DIGIINFOMAJOR;
1772 pc_info.minor_start = 0;
1773 pc_info.num = 1;
1774 pc_info.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1775 pc_info.subtype = SERIAL_TYPE_INFO;
1776
1777
1778 save_flags(flags);
1779 cli();
1780
1781 for (crd = 0; crd < num_cards; crd++)
1782 { /* Begin for each card */
1783
1784 /* ------------------------------------------------------------------
1785 This is where the appropriate memory handlers for the hardware is
1786 set. Everything at runtime blindly jumps through these vectors.
1787 ---------------------------------------------------------------------- */
1788
1789 /* defined in epcaconfig.h */
1790 bd = &boards[crd];
1791
1792 switch (bd->type)
1793 { /* Begin switch on bd->type {board type} */
1794 case PCXEM:
1795 case EISAXEM:
1796 bd->memwinon = pcxem_memwinon ;
1797 bd->memwinoff = pcxem_memwinoff ;
1798 bd->globalwinon = pcxem_globalwinon ;
1799 bd->txwinon = pcxem_txwinon ;
1800 bd->rxwinon = pcxem_rxwinon ;
1801 bd->memoff = pcxem_memoff ;
1802 bd->assertgwinon = dummy_assertgwinon;
1803 bd->assertmemoff = dummy_assertmemoff;
1804 break;
1805
1806 case PCIXEM:
1807 case PCIXRJ:
1808 case PCIXR:
1809 bd->memwinon = dummy_memwinon;
1810 bd->memwinoff = dummy_memwinoff;
1811 bd->globalwinon = dummy_globalwinon;
1812 bd->txwinon = dummy_txwinon;
1813 bd->rxwinon = dummy_rxwinon;
1814 bd->memoff = dummy_memoff;
1815 bd->assertgwinon = dummy_assertgwinon;
1816 bd->assertmemoff = dummy_assertmemoff;
1817 break;
1818
1819 case PCXE:
1820 case PCXEVE:
1821
1822 bd->memwinon = pcxe_memwinon;
1823 bd->memwinoff = pcxe_memwinoff;
1824 bd->globalwinon = pcxe_globalwinon;
1825 bd->txwinon = pcxe_txwinon;
1826 bd->rxwinon = pcxe_rxwinon;
1827 bd->memoff = pcxe_memoff;
1828 bd->assertgwinon = dummy_assertgwinon;
1829 bd->assertmemoff = dummy_assertmemoff;
1830 break;
1831
1832 case PCXI:
1833 case PC64XE:
1834
1835 bd->memwinon = pcxi_memwinon;
1836 bd->memwinoff = pcxi_memwinoff;
1837 bd->globalwinon = pcxi_globalwinon;
1838 bd->txwinon = pcxi_txwinon;
1839 bd->rxwinon = pcxi_rxwinon;
1840 bd->memoff = pcxi_memoff;
1841 bd->assertgwinon = pcxi_assertgwinon;
1842 bd->assertmemoff = pcxi_assertmemoff;
1843 break;
1844
1845 default:
1846 break;
1847
1848 } /* End switch on bd->type */
1849
1850 /* ---------------------------------------------------------------
1851 Some cards need a memory segment to be defined for use in
1852 transmit and receive windowing operations. These boards
1853 are listed in the below switch. In the case of the XI the
1854 amount of memory on the board is variable so the memory_seg
1855 is also variable. This code determines what they segment
1856 should be.
1857 ----------------------------------------------------------------- */
1858
1859 switch (bd->type)
1860 { /* Begin switch on bd->type {board type} */
1861
1862 case PCXE:
1863 case PCXEVE:
1864 case PC64XE:
1865 bd->memory_seg = 0xf000;
1866 break;
1867
1868 case PCXI:
1869 board_id = inb((int)bd->port);
1870 if ((board_id & 0x1) == 0x1)
1871 { /* Begin its an XI card */
1872
1873 /* Is it a 64K board */
1874 if ((board_id & 0x30) == 0)
1875 bd->memory_seg = 0xf000;
1876
1877 /* Is it a 128K board */
1878 if ((board_id & 0x30) == 0x10)
1879 bd->memory_seg = 0xe000;
1880
1881 /* Is is a 256K board */
1882 if ((board_id & 0x30) == 0x20)
1883 bd->memory_seg = 0xc000;
1884
1885 /* Is it a 512K board */
1886 if ((board_id & 0x30) == 0x30)
1887 bd->memory_seg = 0x8000;
1888
1889 } /* End it is an XI card */
1890 else
1891 {
1892 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1893 }
1894 break;
1895
1896 } /* End switch on bd->type */
1897
1898 } /* End for each card */
1899
1900 if (tty_register_driver(&pc_driver))
1901 panic("Couldn't register Digi PC/ driver");
1902
1903 if (tty_register_driver(&pc_callout))
1904 panic("Couldn't register Digi PC/ callout");
1905
1906 if (tty_register_driver(&pc_info))
1907 panic("Couldn't register Digi PC/ info ");
1908
1909 /* -------------------------------------------------------------------
1910 Start up the poller to check for events on all enabled boards
1911 ---------------------------------------------------------------------- */
1912
1913 init_timer(&epca_timer);
1914 epca_timer.function = epcapoll;
1915 mod_timer(&epca_timer, jiffies + HZ/25);
1916
1917 restore_flags(flags);
1918
1919 return 0;
1920
1921 } /* End pc_init */
1922
1923 /* ------------------ Begin post_fep_init ---------------------- */
1924
1925 static void post_fep_init(unsigned int crd)
1926 { /* Begin post_fep_init */
1927
1928 int i;
1929 unchar *memaddr;
1930 volatile struct global_data *gd;
1931 struct board_info *bd;
1932 volatile struct board_chan *bc;
1933 struct channel *ch;
1934 int shrinkmem = 0, lowwater ;
1935
1936 /* -------------------------------------------------------------
1937 This call is made by the user via. the ioctl call DIGI_INIT.
1938 It is responsible for setting up all the card specific stuff.
1939 ---------------------------------------------------------------- */
1940 bd = &boards[crd];
1941
1942 /* -----------------------------------------------------------------
1943 If this is a PCI board, get the port info. Remember PCI cards
1944 do not have entries into the epcaconfig.h file, so we can't get
1945 the number of ports from it. Unfortunetly, this means that anyone
1946 doing a DIGI_GETINFO before the board has booted will get an invalid
1947 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1948 after DIGI_INIT has been called will return the proper values.
1949 ------------------------------------------------------------------- */
1950
1951 if (bd->type >= PCIXEM) /* If the board in question is PCI */
1952 { /* Begin get PCI number of ports */
1953
1954 /* --------------------------------------------------------------------
1955 Below we use XEMPORTS as a memory offset regardless of which PCI
1956 card it is. This is because all of the supported PCI cards have
1957 the same memory offset for the channel data. This will have to be
1958 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1959 states that the port offset is 0xC22 as opposed to 0xC02. This is
1960 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1961 On the PCI cards the number of ports is determined by reading a
1962 ID PROM located in the box attached to the card. The card can then
1963 determine the index the id to determine the number of ports available.
1964 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1965 if the box in question is a XEM or CX)).
1966 ------------------------------------------------------------------------ */
1967
1968 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1969 (bd->re_map_membase + XEMPORTS));
1970
1971
1972 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1973 nbdevs += (bd->numports);
1974
1975 } /* End get PCI number of ports */
1976
1977 if (crd != 0)
1978 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1979 else
1980 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1981
1982 ch = card_ptr[crd];
1983
1984
1985 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1986
1987 memaddr = (unchar *)bd->re_map_membase;
1988
1989 /*
1990 The below command is necessary because newer kernels (2.1.x and
1991 up) do not have a 1:1 virtual to physical mapping. The below
1992 call adjust for that.
1993 */
1994
1995 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
1996
1997 /* -----------------------------------------------------------------
1998 The below assignment will set bc to point at the BEGINING of
1999 the cards channel structures. For 1 card there will be between
2000 8 and 64 of these structures.
2001 -------------------------------------------------------------------- */
2002
2003 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
2004
2005 /* -------------------------------------------------------------------
2006 The below assignment will set gd to point at the BEGINING of
2007 global memory address 0xc00. The first data in that global
2008 memory actually starts at address 0xc1a. The command in
2009 pointer begins at 0xd10.
2010 ---------------------------------------------------------------------- */
2011
2012 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
2013
2014 /* --------------------------------------------------------------------
2015 XEPORTS (address 0xc22) points at the number of channels the
2016 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
2017 ----------------------------------------------------------------------- */
2018
2019 if (((bd->type == PCXEVE) | (bd->type == PCXE)) &&
2020 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
2021 shrinkmem = 1;
2022 if (bd->type < PCIXEM)
2023 request_region((int)bd->port, 4, board_desc[bd->type]);
2024
2025 memwinon(bd, 0);
2026
2027 /* --------------------------------------------------------------------
2028 Remember ch is the main drivers channels structure, while bc is
2029 the cards channel structure.
2030 ------------------------------------------------------------------------ */
2031
2032 /* For every port on the card do ..... */
2033
2034 for (i = 0; i < bd->numports; i++, ch++, bc++)
2035 { /* Begin for each port */
2036
2037 ch->brdchan = bc;
2038 ch->mailbox = gd;
2039 ch->tqueue.routine = do_softint;
2040 ch->tqueue.data = ch;
2041 ch->board = &boards[crd];
2042
2043 switch (bd->type)
2044 { /* Begin switch bd->type */
2045
2046 /* ----------------------------------------------------------------
2047 Since some of the boards use different bitmaps for their
2048 control signals we cannot hard code these values and retain
2049 portability. We virtualize this data here.
2050 ------------------------------------------------------------------- */
2051 case EISAXEM:
2052 case PCXEM:
2053 case PCIXEM:
2054 case PCIXRJ:
2055 case PCIXR:
2056 ch->m_rts = 0x02 ;
2057 ch->m_dcd = 0x80 ;
2058 ch->m_dsr = 0x20 ;
2059 ch->m_cts = 0x10 ;
2060 ch->m_ri = 0x40 ;
2061 ch->m_dtr = 0x01 ;
2062 break;
2063
2064 case PCXE:
2065 case PCXEVE:
2066 case PCXI:
2067 case PC64XE:
2068 ch->m_rts = 0x02 ;
2069 ch->m_dcd = 0x08 ;
2070 ch->m_dsr = 0x10 ;
2071 ch->m_cts = 0x20 ;
2072 ch->m_ri = 0x40 ;
2073 ch->m_dtr = 0x80 ;
2074 break;
2075
2076 } /* End switch bd->type */
2077
2078 if (boards[crd].altpin)
2079 {
2080 ch->dsr = ch->m_dcd;
2081 ch->dcd = ch->m_dsr;
2082 ch->digiext.digi_flags |= DIGI_ALTPIN;
2083 }
2084 else
2085 {
2086 ch->dcd = ch->m_dcd;
2087 ch->dsr = ch->m_dsr;
2088 }
2089
2090 ch->boardnum = crd;
2091 ch->channelnum = i;
2092 ch->magic = EPCA_MAGIC;
2093 ch->tty = 0;
2094
2095 if (shrinkmem)
2096 {
2097 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
2098 shrinkmem = 0;
2099 }
2100
2101 switch (bd->type)
2102 { /* Begin switch bd->type */
2103
2104 case PCIXEM:
2105 case PCIXRJ:
2106 case PCIXR:
2107 /* Cover all the 2MEG cards */
2108 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff);
2109 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff);
2110 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2111 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2112 break;
2113
2114 case PCXEM:
2115 case EISAXEM:
2116 /* Cover all the 32K windowed cards */
2117 /* Mask equal to window size - 1 */
2118 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff);
2119 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff);
2120 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2121 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2122 break;
2123
2124 case PCXEVE:
2125 case PCXE:
2126 ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff);
2127 ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9);
2128 ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff);
2129 ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 );
2130 break;
2131
2132 case PCXI:
2133 case PC64XE:
2134 ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4);
2135 ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4);
2136 ch->txwin = ch->rxwin = 0;
2137 break;
2138
2139 } /* End switch bd->type */
2140
2141 ch->txbufhead = 0;
2142 ch->txbufsize = bc->tmax + 1;
2143
2144 ch->rxbufhead = 0;
2145 ch->rxbufsize = bc->rmax + 1;
2146
2147 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
2148
2149 /* Set transmitter low water mark */
2150 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
2151
2152 /* Set receiver low water mark */
2153
2154 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
2155
2156 /* Set receiver high water mark */
2157
2158 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
2159
2160 bc->edelay = 100;
2161 bc->idata = 1;
2162
2163 ch->startc = bc->startc;
2164 ch->stopc = bc->stopc;
2165 ch->startca = bc->startca;
2166 ch->stopca = bc->stopca;
2167
2168 ch->fepcflag = 0;
2169 ch->fepiflag = 0;
2170 ch->fepoflag = 0;
2171 ch->fepstartc = 0;
2172 ch->fepstopc = 0;
2173 ch->fepstartca = 0;
2174 ch->fepstopca = 0;
2175
2176 ch->close_delay = 50;
2177 ch->count = 0;
2178 ch->blocked_open = 0;
2179 ch->callout_termios = pc_callout.init_termios;
2180 ch->normal_termios = pc_driver.init_termios;
2181 init_waitqueue_head(&ch->open_wait);
2182 init_waitqueue_head(&ch->close_wait);
2183 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
2184 if (!(ch->tmp_buf))
2185 {
2186 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
2187
2188 }
2189 memset((void *)ch->tmp_buf,0,ch->txbufsize);
2190 } /* End for each port */
2191
2192 printk(KERN_INFO
2193 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2194 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2195 sprintf(mesg,
2196 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2197 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2198 console_print(mesg);
2199
2200 memwinoff(bd, 0);
2201
2202 } /* End post_fep_init */
2203
2204 /* --------------------- Begin epcapoll ------------------------ */
2205
2206 static void epcapoll(unsigned long ignored)
2207 { /* Begin epcapoll */
2208
2209 unsigned long flags;
2210 int crd;
2211 volatile unsigned int head, tail;
2212 struct channel *ch;
2213 struct board_info *bd;
2214
2215 /* -------------------------------------------------------------------
2216 This routine is called upon every timer interrupt. Even though
2217 the Digi series cards are capable of generating interrupts this
2218 method of non-looping polling is more efficient. This routine
2219 checks for card generated events (Such as receive data, are transmit
2220 buffer empty) and acts on those events.
2221 ----------------------------------------------------------------------- */
2222
2223 save_flags(flags);
2224 cli();
2225
2226 for (crd = 0; crd < num_cards; crd++)
2227 { /* Begin for each card */
2228
2229 bd = &boards[crd];
2230 ch = card_ptr[crd];
2231
2232 if ((bd->status == DISABLED) || digi_poller_inhibited)
2233 continue; /* Begin loop next interation */
2234
2235 /* -----------------------------------------------------------
2236 assertmemoff is not needed here; indeed it is an empty subroutine.
2237 It is being kept because future boards may need this as well as
2238 some legacy boards.
2239 ---------------------------------------------------------------- */
2240
2241 assertmemoff(ch);
2242
2243 globalwinon(ch);
2244
2245 /* ---------------------------------------------------------------
2246 In this case head and tail actually refer to the event queue not
2247 the transmit or receive queue.
2248 ------------------------------------------------------------------- */
2249
2250 head = ch->mailbox->ein;
2251 tail = ch->mailbox->eout;
2252
2253 /* If head isn't equal to tail we have an event */
2254
2255 if (head != tail)
2256 doevent(crd);
2257
2258 memoff(ch);
2259
2260 } /* End for each card */
2261
2262 mod_timer(&epca_timer, jiffies + (HZ / 25));
2263
2264 restore_flags(flags);
2265 } /* End epcapoll */
2266
2267 /* --------------------- Begin doevent ------------------------ */
2268
2269 static void doevent(int crd)
2270 { /* Begin doevent */
2271
2272 volatile unchar *eventbuf;
2273 struct channel *ch, *chan0;
2274 static struct tty_struct *tty;
2275 volatile struct board_info *bd;
2276 volatile struct board_chan *bc;
2277 register volatile unsigned int tail, head;
2278 register int event, channel;
2279 register int mstat, lstat;
2280
2281 /* -------------------------------------------------------------------
2282 This subroutine is called by epcapoll when an event is detected
2283 in the event queue. This routine responds to those events.
2284 --------------------------------------------------------------------- */
2285
2286 bd = &boards[crd];
2287
2288 chan0 = card_ptr[crd];
2289 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2290
2291 assertgwinon(chan0);
2292
2293 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2294 { /* Begin while something in event queue */
2295
2296 assertgwinon(chan0);
2297
2298 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2299
2300 /* Get the channel the event occurred on */
2301 channel = eventbuf[0];
2302
2303 /* Get the actual event code that occurred */
2304 event = eventbuf[1];
2305
2306 /* ----------------------------------------------------------------
2307 The two assignments below get the current modem status (mstat)
2308 and the previous modem status (lstat). These are useful becuase
2309 an event could signal a change in modem signals itself.
2310 ------------------------------------------------------------------- */
2311
2312 mstat = eventbuf[2];
2313 lstat = eventbuf[3];
2314
2315 ch = chan0 + channel;
2316
2317 if ((unsigned)channel >= bd->numports || !ch)
2318 {
2319 if (channel >= bd->numports)
2320 ch = chan0;
2321 bc = ch->brdchan;
2322 goto next;
2323 }
2324
2325 if ((bc = ch->brdchan) == NULL)
2326 goto next;
2327
2328 if (event & DATA_IND)
2329 { /* Begin DATA_IND */
2330
2331 receive_data(ch);
2332 assertgwinon(ch);
2333
2334 } /* End DATA_IND */
2335 /* else *//* Fix for DCD transition missed bug */
2336 if (event & MODEMCHG_IND)
2337 { /* Begin MODEMCHG_IND */
2338
2339 /* A modem signal change has been indicated */
2340
2341 ch->imodem = mstat;
2342
2343 if (ch->asyncflags & ASYNC_CHECK_CD)
2344 {
2345 if (mstat & ch->dcd) /* We are now receiving dcd */
2346 wake_up_interruptible(&ch->open_wait);
2347 else
2348 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2349 }
2350
2351 } /* End MODEMCHG_IND */
2352
2353 tty = ch->tty;
2354 if (tty)
2355 { /* Begin if valid tty */
2356
2357 if (event & BREAK_IND)
2358 { /* Begin if BREAK_IND */
2359
2360 /* A break has been indicated */
2361
2362 tty->flip.count++;
2363 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2364
2365 *tty->flip.char_buf_ptr++ = 0;
2366
2367 tty_schedule_flip(tty);
2368
2369 } /* End if BREAK_IND */
2370 else
2371 if (event & LOWTX_IND)
2372 { /* Begin LOWTX_IND */
2373
2374 if (ch->statusflags & LOWWAIT)
2375 { /* Begin if LOWWAIT */
2376
2377 ch->statusflags &= ~LOWWAIT;
2378 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2379 tty->ldisc.write_wakeup)
2380 (tty->ldisc.write_wakeup)(tty);
2381 wake_up_interruptible(&tty->write_wait);
2382
2383 } /* End if LOWWAIT */
2384
2385 } /* End LOWTX_IND */
2386 else
2387 if (event & EMPTYTX_IND)
2388 { /* Begin EMPTYTX_IND */
2389
2390 /* This event is generated by setup_empty_event */
2391
2392 ch->statusflags &= ~TXBUSY;
2393 if (ch->statusflags & EMPTYWAIT)
2394 { /* Begin if EMPTYWAIT */
2395
2396 ch->statusflags &= ~EMPTYWAIT;
2397 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2398 tty->ldisc.write_wakeup)
2399 (tty->ldisc.write_wakeup)(tty);
2400
2401 wake_up_interruptible(&tty->write_wait);
2402
2403 } /* End if EMPTYWAIT */
2404
2405 } /* End EMPTYTX_IND */
2406
2407 } /* End if valid tty */
2408
2409
2410 next:
2411 globalwinon(ch);
2412
2413 if (!bc)
2414 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n");
2415 else
2416 bc->idata = 1;
2417
2418 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2419 globalwinon(chan0);
2420
2421 } /* End while something in event queue */
2422
2423 } /* End doevent */
2424
2425 /* --------------------- Begin fepcmd ------------------------ */
2426
2427 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2428 int byte2, int ncmds, int bytecmd)
2429 { /* Begin fepcmd */
2430
2431 unchar *memaddr;
2432 unsigned int head, cmdTail, cmdStart, cmdMax;
2433 long count;
2434 int n;
2435
2436 /* This is the routine in which commands may be passed to the card. */
2437
2438 if (ch->board->status == DISABLED)
2439 {
2440 return;
2441 }
2442
2443 assertgwinon(ch);
2444
2445 /* Remember head (As well as max) is just an offset not a base addr */
2446 head = ch->mailbox->cin;
2447
2448 /* cmdStart is a base address */
2449 cmdStart = ch->mailbox->cstart;
2450
2451 /* ------------------------------------------------------------------
2452 We do the addition below because we do not want a max pointer
2453 relative to cmdStart. We want a max pointer that points at the
2454 physical end of the command queue.
2455 -------------------------------------------------------------------- */
2456
2457 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2458
2459 memaddr = ch->board->re_map_membase;
2460
2461 /*
2462 The below command is necessary because newer kernels (2.1.x and
2463 up) do not have a 1:1 virtual to physical mapping. The below
2464 call adjust for that.
2465 */
2466
2467 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2468
2469 if (head >= (cmdMax - cmdStart) || (head & 03))
2470 {
2471 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2472 cmd, head);
2473 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2474 cmdMax, cmdStart);
2475 return;
2476 }
2477
2478 if (bytecmd)
2479 {
2480 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2481
2482 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2483 /* Below word_or_byte is bits to set */
2484 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte;
2485 /* Below byte2 is bits to reset */
2486 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2;
2487
2488 }
2489 else
2490 {
2491 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2492 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2493 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2494 }
2495
2496 head = (head + 4) & (cmdMax - cmdStart - 4);
2497 ch->mailbox->cin = head;
2498
2499 count = FEPTIMEOUT;
2500
2501 for (;;)
2502 { /* Begin forever loop */
2503
2504 count--;
2505 if (count == 0)
2506 {
2507 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2508 return;
2509 }
2510
2511 head = ch->mailbox->cin;
2512 cmdTail = ch->mailbox->cout;
2513
2514 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2515
2516 /* ----------------------------------------------------------
2517 Basically this will break when the FEP acknowledges the
2518 command by incrementing cmdTail (Making it equal to head).
2519 ------------------------------------------------------------- */
2520
2521 if (n <= ncmds * (sizeof(short) * 4))
2522 break; /* Well nearly forever :-) */
2523
2524 } /* End forever loop */
2525
2526 } /* End fepcmd */
2527
2528 /* ---------------------------------------------------------------------
2529 Digi products use fields in their channels structures that are very
2530 similar to the c_cflag and c_iflag fields typically found in UNIX
2531 termios structures. The below three routines allow mappings
2532 between these hardware "flags" and their respective Linux flags.
2533 ------------------------------------------------------------------------- */
2534
2535 /* --------------------- Begin termios2digi_h -------------------- */
2536
2537 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2538 { /* Begin termios2digi_h */
2539
2540 unsigned res = 0;
2541
2542 if (cflag & CRTSCTS)
2543 {
2544 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2545 res |= ((ch->m_cts) | (ch->m_rts));
2546 }
2547
2548 if (ch->digiext.digi_flags & RTSPACE)
2549 res |= ch->m_rts;
2550
2551 if (ch->digiext.digi_flags & DTRPACE)
2552 res |= ch->m_dtr;
2553
2554 if (ch->digiext.digi_flags & CTSPACE)
2555 res |= ch->m_cts;
2556
2557 if (ch->digiext.digi_flags & DSRPACE)
2558 res |= ch->dsr;
2559
2560 if (ch->digiext.digi_flags & DCDPACE)
2561 res |= ch->dcd;
2562
2563 if (res & (ch->m_rts))
2564 ch->digiext.digi_flags |= RTSPACE;
2565
2566 if (res & (ch->m_cts))
2567 ch->digiext.digi_flags |= CTSPACE;
2568
2569 return res;
2570
2571 } /* End termios2digi_h */
2572
2573 /* --------------------- Begin termios2digi_i -------------------- */
2574 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2575 { /* Begin termios2digi_i */
2576
2577 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2578 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2579
2580 if (ch->digiext.digi_flags & DIGI_AIXON)
2581 res |= IAIXON;
2582 return res;
2583
2584 } /* End termios2digi_i */
2585
2586 /* --------------------- Begin termios2digi_c -------------------- */
2587
2588 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2589 { /* Begin termios2digi_c */
2590
2591 unsigned res = 0;
2592
2593 #ifdef SPEED_HACK
2594 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2595 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2596 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2597 #endif /* SPEED_HACK */
2598
2599 if (cflag & CBAUDEX)
2600 { /* Begin detected CBAUDEX */
2601
2602 ch->digiext.digi_flags |= DIGI_FAST;
2603
2604 /* -------------------------------------------------------------
2605 HUPCL bit is used by FEP to indicate fast baud
2606 table is to be used.
2607 ----------------------------------------------------------------- */
2608
2609 res |= FEP_HUPCL;
2610
2611 } /* End detected CBAUDEX */
2612 else ch->digiext.digi_flags &= ~DIGI_FAST;
2613
2614 /* -------------------------------------------------------------------
2615 CBAUD has bit position 0x1000 set these days to indicate Linux
2616 baud rate remap. Digi hardware can't handle the bit assignment.
2617 (We use a different bit assignment for high speed.). Clear this
2618 bit out.
2619 ---------------------------------------------------------------------- */
2620 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2621
2622 /* -------------------------------------------------------------
2623 This gets a little confusing. The Digi cards have their own
2624 representation of c_cflags controling baud rate. For the most
2625 part this is identical to the Linux implementation. However;
2626 Digi supports one rate (76800) that Linux doesn't. This means
2627 that the c_cflag entry that would normally mean 76800 for Digi
2628 actually means 115200 under Linux. Without the below mapping,
2629 a stty 115200 would only drive the board at 76800. Since
2630 the rate 230400 is also found after 76800, the same problem afflicts
2631 us when we choose a rate of 230400. Without the below modificiation
2632 stty 230400 would actually give us 115200.
2633
2634 There are two additional differences. The Linux value for CLOCAL
2635 (0x800; 0004000) has no meaning to the Digi hardware. Also in
2636 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
2637 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
2638 should be checked for a screened out prior to termios2digi_c
2639 returning. Since CLOCAL isn't used by the board this can be
2640 ignored as long as the returned value is used only by Digi hardware.
2641 ----------------------------------------------------------------- */
2642
2643 if (cflag & CBAUDEX)
2644 {
2645 /* -------------------------------------------------------------
2646 The below code is trying to guarantee that only baud rates
2647 115200 and 230400 are remapped. We use exclusive or because
2648 the various baud rates share common bit positions and therefore
2649 can't be tested for easily.
2650 ----------------------------------------------------------------- */
2651
2652
2653 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2654 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2655 {
2656 res += 1;
2657 }
2658 }
2659
2660 return res;
2661
2662 } /* End termios2digi_c */
2663
2664 /* --------------------- Begin epcaparam ----------------------- */
2665
2666 static void epcaparam(struct tty_struct *tty, struct channel *ch)
2667 { /* Begin epcaparam */
2668
2669 unsigned int cmdHead;
2670 struct termios *ts;
2671 volatile struct board_chan *bc;
2672 unsigned mval, hflow, cflag, iflag;
2673
2674 bc = ch->brdchan;
2675 epcaassert(bc !=0, "bc out of range");
2676
2677 assertgwinon(ch);
2678
2679 ts = tty->termios;
2680
2681 if ((ts->c_cflag & CBAUD) == 0)
2682 { /* Begin CBAUD detected */
2683
2684 cmdHead = bc->rin;
2685 bc->rout = cmdHead;
2686 cmdHead = bc->tin;
2687
2688 /* Changing baud in mid-stream transmission can be wonderful */
2689 /* ---------------------------------------------------------------
2690 Flush current transmit buffer by setting cmdTail pointer (tout)
2691 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2692 ----------------------------------------------------------------- */
2693
2694 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2695 mval = 0;
2696
2697 } /* End CBAUD detected */
2698 else
2699 { /* Begin CBAUD not detected */
2700
2701 /* -------------------------------------------------------------------
2702 c_cflags have changed but that change had nothing to do with BAUD.
2703 Propagate the change to the card.
2704 ---------------------------------------------------------------------- */
2705
2706 cflag = termios2digi_c(ch, ts->c_cflag);
2707
2708 if (cflag != ch->fepcflag)
2709 {
2710 ch->fepcflag = cflag;
2711 /* Set baud rate, char size, stop bits, parity */
2712 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2713 }
2714
2715
2716 /* ----------------------------------------------------------------
2717 If the user has not forced CLOCAL and if the device is not a
2718 CALLOUT device (Which is always CLOCAL) we set flags such that
2719 the driver will wait on carrier detect.
2720 ------------------------------------------------------------------- */
2721
2722 if ((ts->c_cflag & CLOCAL) || (tty->driver.subtype == SERIAL_TYPE_CALLOUT))
2723 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2724 ch->asyncflags &= ~ASYNC_CHECK_CD;
2725 } /* End it is a cud device or a ttyD device with CLOCAL on */
2726 else
2727 { /* Begin it is a ttyD device */
2728 ch->asyncflags |= ASYNC_CHECK_CD;
2729 } /* End it is a ttyD device */
2730
2731 mval = ch->m_dtr | ch->m_rts;
2732
2733 } /* End CBAUD not detected */
2734
2735 iflag = termios2digi_i(ch, ts->c_iflag);
2736
2737 /* Check input mode flags */
2738
2739 if (iflag != ch->fepiflag)
2740 {
2741 ch->fepiflag = iflag;
2742
2743 /* ---------------------------------------------------------------
2744 Command sets channels iflag structure on the board. Such things
2745 as input soft flow control, handeling of parity errors, and
2746 break handeling are all set here.
2747 ------------------------------------------------------------------- */
2748
2749 /* break handeling, parity handeling, input stripping, flow control chars */
2750 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2751 }
2752
2753 /* ---------------------------------------------------------------
2754 Set the board mint value for this channel. This will cause hardware
2755 events to be generated each time the DCD signal (Described in mint)
2756 changes.
2757 ------------------------------------------------------------------- */
2758 bc->mint = ch->dcd;
2759
2760 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2761 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2762 bc->mint = 0;
2763
2764 ch->imodem = bc->mstat;
2765
2766 hflow = termios2digi_h(ch, ts->c_cflag);
2767
2768 if (hflow != ch->hflow)
2769 {
2770 ch->hflow = hflow;
2771
2772 /* --------------------------------------------------------------
2773 Hard flow control has been selected but the board is not
2774 using it. Activate hard flow control now.
2775 ----------------------------------------------------------------- */
2776
2777 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2778 }
2779
2780
2781 mval ^= ch->modemfake & (mval ^ ch->modem);
2782
2783 if (ch->omodem ^ mval)
2784 {
2785 ch->omodem = mval;
2786
2787 /* --------------------------------------------------------------
2788 The below command sets the DTR and RTS mstat structure. If
2789 hard flow control is NOT active these changes will drive the
2790 output of the actual DTR and RTS lines. If hard flow control
2791 is active, the changes will be saved in the mstat structure and
2792 only asserted when hard flow control is turned off.
2793 ----------------------------------------------------------------- */
2794
2795 /* First reset DTR & RTS; then set them */
2796 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2797 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2798
2799 }
2800
2801 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2802 {
2803 ch->fepstartc = ch->startc;
2804 ch->fepstopc = ch->stopc;
2805
2806 /* ------------------------------------------------------------
2807 The XON / XOFF characters have changed; propogate these
2808 changes to the card.
2809 --------------------------------------------------------------- */
2810
2811 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2812 }
2813
2814 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2815 {
2816 ch->fepstartca = ch->startca;
2817 ch->fepstopca = ch->stopca;
2818
2819 /* ---------------------------------------------------------------
2820 Similar to the above, this time the auxilarly XON / XOFF
2821 characters have changed; propogate these changes to the card.
2822 ------------------------------------------------------------------ */
2823
2824 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2825 }
2826
2827 } /* End epcaparam */
2828
2829 /* --------------------- Begin receive_data ----------------------- */
2830
2831 static void receive_data(struct channel *ch)
2832 { /* Begin receive_data */
2833
2834 unchar *rptr;
2835 struct termios *ts = 0;
2836 struct tty_struct *tty;
2837 volatile struct board_chan *bc;
2838 register int dataToRead, wrapgap, bytesAvailable;
2839 register unsigned int tail, head;
2840 unsigned int wrapmask;
2841 int rc;
2842
2843
2844 /* ---------------------------------------------------------------
2845 This routine is called by doint when a receive data event
2846 has taken place.
2847 ------------------------------------------------------------------- */
2848
2849 globalwinon(ch);
2850
2851 if (ch->statusflags & RXSTOPPED)
2852 return;
2853
2854 tty = ch->tty;
2855 if (tty)
2856 ts = tty->termios;
2857
2858 bc = ch->brdchan;
2859
2860 if (!bc)
2861 {
2862 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2863 return;
2864 }
2865
2866 wrapmask = ch->rxbufsize - 1;
2867
2868 /* ---------------------------------------------------------------------
2869 Get the head and tail pointers to the receiver queue. Wrap the
2870 head pointer if it has reached the end of the buffer.
2871 ------------------------------------------------------------------------ */
2872
2873 head = bc->rin;
2874 head &= wrapmask;
2875 tail = bc->rout & wrapmask;
2876
2877 bytesAvailable = (head - tail) & wrapmask;
2878
2879 if (bytesAvailable == 0)
2880 return;
2881
2882 /* ------------------------------------------------------------------
2883 If CREAD bit is off or device not open, set TX tail to head
2884 --------------------------------------------------------------------- */
2885
2886 if (!tty || !ts || !(ts->c_cflag & CREAD))
2887 {
2888 bc->rout = head;
2889 return;
2890 }
2891
2892 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2893 return;
2894
2895 if (bc->orun)
2896 {
2897 bc->orun = 0;
2898 printk(KERN_WARNING "overrun! DigiBoard device minor = %d\n",MINOR(tty->device));
2899 }
2900
2901 rxwinon(ch);
2902 rptr = tty->flip.char_buf_ptr;
2903 rc = tty->flip.count;
2904
2905 while (bytesAvailable > 0)
2906 { /* Begin while there is data on the card */
2907
2908 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2909
2910 /* ---------------------------------------------------------------
2911 Even if head has wrapped around only report the amount of
2912 data to be equal to the size - tail. Remember memcpy can't
2913 automaticly wrap around the receive buffer.
2914 ----------------------------------------------------------------- */
2915
2916 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2917
2918 /* --------------------------------------------------------------
2919 Make sure we don't overflow the buffer
2920 ----------------------------------------------------------------- */
2921
2922 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2923 dataToRead = TTY_FLIPBUF_SIZE - rc;
2924
2925 if (dataToRead == 0)
2926 break;
2927
2928 /* ---------------------------------------------------------------
2929 Move data read from our card into the line disciplines buffer
2930 for translation if necessary.
2931 ------------------------------------------------------------------ */
2932
2933 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2934 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2935
2936 rc += dataToRead;
2937 rptr += dataToRead;
2938 tail = (tail + dataToRead) & wrapmask;
2939 bytesAvailable -= dataToRead;
2940
2941 } /* End while there is data on the card */
2942
2943
2944 tty->flip.count = rc;
2945 tty->flip.char_buf_ptr = rptr;
2946 globalwinon(ch);
2947 bc->rout = tail;
2948
2949 /* Must be called with global data */
2950 tty_schedule_flip(ch->tty);
2951 return;
2952
2953 } /* End receive_data */
2954
2955 /* --------------------- Begin pc_ioctl ----------------------- */
2956
2957 static int pc_ioctl(struct tty_struct *tty, struct file * file,
2958 unsigned int cmd, unsigned long arg)
2959 { /* Begin pc_ioctl */
2960
2961 digiflow_t dflow;
2962 int retval, error;
2963 unsigned long flags;
2964 unsigned int mflag, mstat;
2965 unsigned char startc, stopc;
2966 volatile struct board_chan *bc;
2967 struct channel *ch = (struct channel *) tty->driver_data;
2968
2969 /* The control device has it's own set of commands */
2970 if (tty->driver.subtype == SERIAL_TYPE_INFO)
2971 { /* Begin if subtype is the control device */
2972
2973 switch (cmd)
2974 { /* Begin switch cmd */
2975
2976 case DIGI_GETINFO:
2977 { /* Begin case DIGI_GETINFO */
2978
2979 struct digi_info di ;
2980 int brd;
2981
2982 getUser(brd, (unsigned int *)arg);
2983
2984 if ((error = verify_area(VERIFY_WRITE, (char*)arg, sizeof(di))))
2985 {
2986 printk(KERN_ERR "DIGI_GETINFO : verify area size 0x%x failed\n",sizeof(di));
2987 return(error);
2988 }
2989
2990 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
2991 return (-ENODEV);
2992
2993 memset(&di, 0, sizeof(di));
2994
2995 di.board = brd ;
2996 di.status = boards[brd].status;
2997 di.type = boards[brd].type ;
2998 di.numports = boards[brd].numports ;
2999 di.port = boards[brd].port ;
3000 di.membase = boards[brd].membase ;
3001
3002 copy_to_user((char *)arg, &di, sizeof (di));
3003 break;
3004
3005 } /* End case DIGI_GETINFO */
3006
3007 case DIGI_POLLER:
3008 { /* Begin case DIGI_POLLER */
3009
3010 int brd = arg & 0xff000000 >> 16 ;
3011 unsigned char state = arg & 0xff ;
3012
3013 if ((brd < 0) || (brd >= num_cards))
3014 {
3015 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
3016 return (-ENODEV);
3017 }
3018
3019 digi_poller_inhibited = state ;
3020 break ;
3021
3022 } /* End case DIGI_POLLER */
3023
3024 case DIGI_INIT:
3025 { /* Begin case DIGI_INIT */
3026
3027 /* ------------------------------------------------------------
3028 This call is made by the apps to complete the initilization
3029 of the board(s). This routine is responsible for setting
3030 the card to its initial state and setting the drivers control
3031 fields to the sutianle settings for the card in question.
3032 ---------------------------------------------------------------- */
3033
3034 int crd ;
3035 for (crd = 0; crd < num_cards; crd++)
3036 post_fep_init (crd);
3037
3038 break ;
3039
3040 } /* End case DIGI_INIT */
3041
3042
3043 default:
3044 return -ENOIOCTLCMD;
3045
3046 } /* End switch cmd */
3047 return (0) ;
3048
3049 } /* End if subtype is the control device */
3050
3051 if (ch)
3052 bc = ch->brdchan;
3053 else
3054 {
3055 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
3056 return(-EINVAL);
3057 }
3058
3059 save_flags(flags);
3060
3061 /* -------------------------------------------------------------------
3062 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
3063 in /usr/src/linux/drivers/char for a good example. In particular
3064 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
3065 ---------------------------------------------------------------------- */
3066
3067 switch (cmd)
3068 { /* Begin switch cmd */
3069
3070 case TCGETS:
3071 retval = verify_area(VERIFY_WRITE, (void *)arg,
3072 sizeof(struct termios));
3073
3074 if (retval)
3075 return(retval);
3076
3077 copy_to_user((struct termios *)arg,
3078 tty->termios, sizeof(struct termios));
3079 return(0);
3080
3081 case TCGETA:
3082 return get_termio(tty, (struct termio *)arg);
3083
3084 case TCSBRK: /* SVID version: non-zero arg --> no break */
3085
3086 retval = tty_check_change(tty);
3087 if (retval)
3088 return retval;
3089
3090 /* Setup an event to indicate when the transmit buffer empties */
3091
3092 setup_empty_event(tty,ch);
3093 tty_wait_until_sent(tty, 0);
3094 if (!arg)
3095 digi_send_break(ch, HZ/4); /* 1/4 second */
3096 return 0;
3097
3098 case TCSBRKP: /* support for POSIX tcsendbreak() */
3099
3100 retval = tty_check_change(tty);
3101 if (retval)
3102 return retval;
3103
3104 /* Setup an event to indicate when the transmit buffer empties */
3105
3106 setup_empty_event(tty,ch);
3107 tty_wait_until_sent(tty, 0);
3108 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
3109 return 0;
3110
3111 case TIOCGSOFTCAR:
3112
3113 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
3114 if (error)
3115 return error;
3116
3117 putUser(C_CLOCAL(tty) ? 1 : 0,
3118 (unsigned long *) arg);
3119 return 0;
3120
3121 case TIOCSSOFTCAR:
3122 /*RONNIE PUT VERIFY_READ (See above) check here */
3123 {
3124 unsigned int value;
3125
3126 getUser(value, (unsigned int *)arg);
3127 tty->termios->c_cflag =
3128 ((tty->termios->c_cflag & ~CLOCAL) |
3129 (value ? CLOCAL : 0));
3130 return 0;
3131 }
3132
3133 case TIOCMODG:
3134 case TIOCMGET:
3135
3136 mflag = 0;
3137
3138 cli();
3139 globalwinon(ch);
3140 mstat = bc->mstat;
3141 memoff(ch);
3142 restore_flags(flags);
3143
3144 if (mstat & ch->m_dtr)
3145 mflag |= TIOCM_DTR;
3146
3147 if (mstat & ch->m_rts)
3148 mflag |= TIOCM_RTS;
3149
3150 if (mstat & ch->m_cts)
3151 mflag |= TIOCM_CTS;
3152
3153 if (mstat & ch->dsr)
3154 mflag |= TIOCM_DSR;
3155
3156 if (mstat & ch->m_ri)
3157 mflag |= TIOCM_RI;
3158
3159 if (mstat & ch->dcd)
3160 mflag |= TIOCM_CD;
3161
3162 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
3163
3164 if (error)
3165 return error;
3166
3167 putUser(mflag, (unsigned int *) arg);
3168
3169 break;
3170
3171 case TIOCMBIS:
3172 case TIOCMBIC:
3173 case TIOCMODS:
3174 case TIOCMSET:
3175
3176 getUser(mstat, (unsigned int *)arg);
3177
3178 mflag = 0;
3179 if (mstat & TIOCM_DTR)
3180 mflag |= ch->m_dtr;
3181
3182 if (mstat & TIOCM_RTS)
3183 mflag |= ch->m_rts;
3184
3185 switch (cmd)
3186 { /* Begin switch cmd */
3187
3188 case TIOCMODS:
3189 case TIOCMSET:
3190 ch->modemfake = ch->m_dtr|ch->m_rts;
3191 ch->modem = mflag;
3192 break;
3193
3194 case TIOCMBIS:
3195 ch->modemfake |= mflag;
3196 ch->modem |= mflag;
3197 break;
3198
3199 case TIOCMBIC:
3200 ch->modemfake |= mflag;
3201 ch->modem &= ~mflag;
3202 break;
3203
3204 } /* End switch cmd */
3205
3206 cli();
3207 globalwinon(ch);
3208
3209 /* --------------------------------------------------------------
3210 The below routine generally sets up parity, baud, flow control
3211 issues, etc.... It effect both control flags and input flags.
3212 ------------------------------------------------------------------ */
3213
3214 epcaparam(tty,ch);
3215 memoff(ch);
3216 restore_flags(flags);
3217 break;
3218
3219 case TIOCSDTR:
3220 ch->omodem |= ch->m_dtr;
3221 cli();
3222 globalwinon(ch);
3223 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
3224 memoff(ch);
3225 restore_flags(flags);
3226 break;
3227
3228 case TIOCCDTR:
3229 ch->omodem &= ~ch->m_dtr;
3230 cli();
3231 globalwinon(ch);
3232 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
3233 memoff(ch);
3234 restore_flags(flags);
3235 break;
3236
3237 case DIGI_GETA:
3238 if ((error=
3239 verify_area(VERIFY_WRITE, (char*)arg, sizeof(digi_t))))
3240 {
3241 printk(KERN_ERR "<Error> - Digi GETA failed\n");
3242 return(error);
3243 }
3244
3245 copy_to_user((char*)arg, &ch->digiext, sizeof(digi_t));
3246 break;
3247
3248 case DIGI_SETAW:
3249 case DIGI_SETAF:
3250 if ((cmd) == (DIGI_SETAW))
3251 {
3252 /* Setup an event to indicate when the transmit buffer empties */
3253
3254 setup_empty_event(tty,ch);
3255 tty_wait_until_sent(tty, 0);
3256 }
3257 else
3258 {
3259 if (tty->ldisc.flush_buffer)
3260 tty->ldisc.flush_buffer(tty);
3261 }
3262
3263 /* Fall Thru */
3264
3265 case DIGI_SETA:
3266 if ((error =
3267 verify_area(VERIFY_READ, (char*)arg,sizeof(digi_t))))
3268 return(error);
3269
3270 copy_from_user(&ch->digiext, (char*)arg, sizeof(digi_t));
3271
3272 if (ch->digiext.digi_flags & DIGI_ALTPIN)
3273 {
3274 ch->dcd = ch->m_dsr;
3275 ch->dsr = ch->m_dcd;
3276 }
3277 else
3278 {
3279 ch->dcd = ch->m_dcd;
3280 ch->dsr = ch->m_dsr;
3281 }
3282
3283 cli();
3284 globalwinon(ch);
3285
3286 /* -----------------------------------------------------------------
3287 The below routine generally sets up parity, baud, flow control
3288 issues, etc.... It effect both control flags and input flags.
3289 ------------------------------------------------------------------- */
3290
3291 epcaparam(tty,ch);
3292 memoff(ch);
3293 restore_flags(flags);
3294 break;
3295
3296 case DIGI_GETFLOW:
3297 case DIGI_GETAFLOW:
3298 cli();
3299 globalwinon(ch);
3300 if ((cmd) == (DIGI_GETFLOW))
3301 {
3302 dflow.startc = bc->startc;
3303 dflow.stopc = bc->stopc;
3304 }
3305 else
3306 {
3307 dflow.startc = bc->startca;
3308 dflow.stopc = bc->stopca;
3309 }
3310 memoff(ch);
3311 restore_flags(flags);
3312
3313 if ((error = verify_area(VERIFY_WRITE, (char*)arg,sizeof(dflow))))
3314 return(error);
3315
3316 copy_to_user((char*)arg, &dflow, sizeof(dflow));
3317 break;
3318
3319 case DIGI_SETAFLOW:
3320 case DIGI_SETFLOW:
3321 if ((cmd) == (DIGI_SETFLOW))
3322 {
3323 startc = ch->startc;
3324 stopc = ch->stopc;
3325 }
3326 else
3327 {
3328 startc = ch->startca;
3329 stopc = ch->stopca;
3330 }
3331
3332 if ((error = verify_area(VERIFY_READ, (char*)arg,sizeof(dflow))))
3333 return(error);
3334
3335 copy_from_user(&dflow, (char*)arg, sizeof(dflow));
3336
3337 if (dflow.startc != startc || dflow.stopc != stopc)
3338 { /* Begin if setflow toggled */
3339 cli();
3340 globalwinon(ch);
3341
3342 if ((cmd) == (DIGI_SETFLOW))
3343 {
3344 ch->fepstartc = ch->startc = dflow.startc;
3345 ch->fepstopc = ch->stopc = dflow.stopc;
3346 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3347 }
3348 else
3349 {
3350 ch->fepstartca = ch->startca = dflow.startc;
3351 ch->fepstopca = ch->stopca = dflow.stopc;
3352 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3353 }
3354
3355 if (ch->statusflags & TXSTOPPED)
3356 pc_start(tty);
3357
3358 memoff(ch);
3359 restore_flags(flags);
3360
3361 } /* End if setflow toggled */
3362 break;
3363
3364 default:
3365 return -ENOIOCTLCMD;
3366
3367 } /* End switch cmd */
3368
3369 return 0;
3370
3371 } /* End pc_ioctl */
3372
3373 /* --------------------- Begin pc_set_termios ----------------------- */
3374
3375 static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3376 { /* Begin pc_set_termios */
3377
3378 struct channel *ch;
3379 unsigned long flags;
3380
3381 /* ---------------------------------------------------------
3382 verifyChannel returns the channel from the tty struct
3383 if it is valid. This serves as a sanity check.
3384 ------------------------------------------------------------- */
3385
3386 if ((ch = verifyChannel(tty)) != NULL)
3387 { /* Begin if channel valid */
3388
3389 save_flags(flags);
3390 cli();
3391 globalwinon(ch);
3392 epcaparam(tty, ch);
3393 memoff(ch);
3394
3395 if ((old_termios->c_cflag & CRTSCTS) &&
3396 ((tty->termios->c_cflag & CRTSCTS) == 0))
3397 tty->hw_stopped = 0;
3398
3399 if (!(old_termios->c_cflag & CLOCAL) &&
3400 (tty->termios->c_cflag & CLOCAL))
3401 wake_up_interruptible(&ch->open_wait);
3402
3403 restore_flags(flags);
3404
3405 } /* End if channel valid */
3406
3407 } /* End pc_set_termios */
3408
3409 /* --------------------- Begin do_softint ----------------------- */
3410
3411 static void do_softint(void *private_)
3412 { /* Begin do_softint */
3413
3414 struct channel *ch = (struct channel *) private_;
3415
3416
3417 /* Called in response to a modem change event */
3418
3419 if (ch && ch->magic == EPCA_MAGIC)
3420 { /* Begin EPCA_MAGIC */
3421
3422 struct tty_struct *tty = ch->tty;
3423
3424 if (tty && tty->driver_data)
3425 {
3426 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3427 { /* Begin if clear_bit */
3428
3429 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
3430 wake_up_interruptible(&ch->open_wait);
3431 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
3432
3433 } /* End if clear_bit */
3434 }
3435
3436 } /* End EPCA_MAGIC */
3437 MOD_DEC_USE_COUNT;
3438 } /* End do_softint */
3439
3440 /* ------------------------------------------------------------
3441 pc_stop and pc_start provide software flow control to the
3442 routine and the pc_ioctl routine.
3443 ---------------------------------------------------------------- */
3444
3445 /* --------------------- Begin pc_stop ----------------------- */
3446
3447 static void pc_stop(struct tty_struct *tty)
3448 { /* Begin pc_stop */
3449
3450 struct channel *ch;
3451 unsigned long flags;
3452
3453 /* ---------------------------------------------------------
3454 verifyChannel returns the channel from the tty struct
3455 if it is valid. This serves as a sanity check.
3456 ------------------------------------------------------------- */
3457
3458 if ((ch = verifyChannel(tty)) != NULL)
3459 { /* Begin if valid channel */
3460
3461 save_flags(flags);
3462 cli();
3463
3464 if ((ch->statusflags & TXSTOPPED) == 0)
3465 { /* Begin if transmit stop requested */
3466
3467 globalwinon(ch);
3468
3469 /* STOP transmitting now !! */
3470
3471 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3472
3473 ch->statusflags |= TXSTOPPED;
3474 memoff(ch);
3475
3476 } /* End if transmit stop requested */
3477
3478 restore_flags(flags);
3479
3480 } /* End if valid channel */
3481
3482 } /* End pc_stop */
3483
3484 /* --------------------- Begin pc_start ----------------------- */
3485
3486 static void pc_start(struct tty_struct *tty)
3487 { /* Begin pc_start */
3488
3489 struct channel *ch;
3490
3491 /* ---------------------------------------------------------
3492 verifyChannel returns the channel from the tty struct
3493 if it is valid. This serves as a sanity check.
3494 ------------------------------------------------------------- */
3495
3496 if ((ch = verifyChannel(tty)) != NULL)
3497 { /* Begin if channel valid */
3498
3499 unsigned long flags;
3500
3501 save_flags(flags);
3502 cli();
3503
3504 /* Just in case output was resumed because of a change in Digi-flow */
3505 if (ch->statusflags & TXSTOPPED)
3506 { /* Begin transmit resume requested */
3507
3508 volatile struct board_chan *bc;
3509
3510 globalwinon(ch);
3511 bc = ch->brdchan;
3512 if (ch->statusflags & LOWWAIT)
3513 bc->ilow = 1;
3514
3515 /* Okay, you can start transmitting again... */
3516
3517 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3518
3519 ch->statusflags &= ~TXSTOPPED;
3520 memoff(ch);
3521
3522 } /* End transmit resume requested */
3523
3524 restore_flags(flags);
3525
3526 } /* End if channel valid */
3527
3528 } /* End pc_start */
3529
3530 /* ------------------------------------------------------------------
3531 The below routines pc_throttle and pc_unthrottle are used
3532 to slow (And resume) the receipt of data into the kernels
3533 receive buffers. The exact occurence of this depends on the
3534 size of the kernels receive buffer and what the 'watermarks'
3535 are set to for that buffer. See the n_ttys.c file for more
3536 details.
3537 ______________________________________________________________________ */
3538 /* --------------------- Begin throttle ----------------------- */
3539
3540 static void pc_throttle(struct tty_struct * tty)
3541 { /* Begin pc_throttle */
3542
3543 struct channel *ch;
3544 unsigned long flags;
3545
3546 /* ---------------------------------------------------------
3547 verifyChannel returns the channel from the tty struct
3548 if it is valid. This serves as a sanity check.
3549 ------------------------------------------------------------- */
3550
3551 if ((ch = verifyChannel(tty)) != NULL)
3552 { /* Begin if channel valid */
3553
3554
3555 save_flags(flags);
3556 cli();
3557
3558 if ((ch->statusflags & RXSTOPPED) == 0)
3559 {
3560 globalwinon(ch);
3561 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3562
3563 ch->statusflags |= RXSTOPPED;
3564 memoff(ch);
3565 }
3566 restore_flags(flags);
3567
3568 } /* End if channel valid */
3569
3570 } /* End pc_throttle */
3571
3572 /* --------------------- Begin unthrottle ----------------------- */
3573
3574 static void pc_unthrottle(struct tty_struct *tty)
3575 { /* Begin pc_unthrottle */
3576
3577 struct channel *ch;
3578 unsigned long flags;
3579 volatile struct board_chan *bc;
3580
3581
3582 /* ---------------------------------------------------------
3583 verifyChannel returns the channel from the tty struct
3584 if it is valid. This serves as a sanity check.
3585 ------------------------------------------------------------- */
3586
3587 if ((ch = verifyChannel(tty)) != NULL)
3588 { /* Begin if channel valid */
3589
3590
3591 /* Just in case output was resumed because of a change in Digi-flow */
3592 save_flags(flags);
3593 cli();
3594
3595 if (ch->statusflags & RXSTOPPED)
3596 {
3597
3598 globalwinon(ch);
3599 bc = ch->brdchan;
3600 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3601
3602 ch->statusflags &= ~RXSTOPPED;
3603 memoff(ch);
3604 }
3605 restore_flags(flags);
3606
3607 } /* End if channel valid */
3608
3609 } /* End pc_unthrottle */
3610
3611 /* --------------------- Begin digi_send_break ----------------------- */
3612
3613 void digi_send_break(struct channel *ch, int msec)
3614 { /* Begin digi_send_break */
3615
3616 unsigned long flags;
3617
3618 save_flags(flags);
3619 cli();
3620 globalwinon(ch);
3621
3622 /* --------------------------------------------------------------------
3623 Maybe I should send an infinite break here, schedule() for
3624 msec amount of time, and then stop the break. This way,
3625 the user can't screw up the FEP by causing digi_send_break()
3626 to be called (i.e. via an ioctl()) more than once in msec amount
3627 of time. Try this for now...
3628 ------------------------------------------------------------------------ */
3629
3630 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3631 memoff(ch);
3632
3633 restore_flags(flags);
3634
3635 } /* End digi_send_break */
3636
3637 /* --------------------- Begin setup_empty_event ----------------------- */
3638
3639 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3640 { /* Begin setup_empty_event */
3641
3642 volatile struct board_chan *bc = ch->brdchan;
3643 unsigned long int flags;
3644
3645 save_flags(flags);
3646 cli();
3647 globalwinon(ch);
3648 ch->statusflags |= EMPTYWAIT;
3649
3650 /* ------------------------------------------------------------------
3651 When set the iempty flag request a event to be generated when the
3652 transmit buffer is empty (If there is no BREAK in progress).
3653 --------------------------------------------------------------------- */
3654
3655 bc->iempty = 1;
3656 memoff(ch);
3657 restore_flags(flags);
3658
3659 } /* End setup_empty_event */
3660
3661 /* --------------------- Begin get_termio ----------------------- */
3662
3663 static int get_termio(struct tty_struct * tty, struct termio * termio)
3664 { /* Begin get_termio */
3665 int error;
3666
3667 error = verify_area(VERIFY_WRITE, termio, sizeof (struct termio));
3668 if (error)
3669 return error;
3670
3671 kernel_termios_to_user_termio(termio, tty->termios);
3672
3673 return 0;
3674 } /* End get_termio */
3675 /* ---------------------- Begin epca_setup -------------------------- */
3676 void epca_setup(char *str, int *ints)
3677 { /* Begin epca_setup */
3678
3679 struct board_info board;
3680 int index, loop, last;
3681 char *temp, *t2;
3682 unsigned len;
3683
3684 /* ----------------------------------------------------------------------
3685 If this routine looks a little strange it is because it is only called
3686 if a LILO append command is given to boot the kernel with parameters.
3687 In this way, we can provide the user a method of changing his board
3688 configuration without rebuilding the kernel.
3689 ----------------------------------------------------------------------- */
3690 if (!liloconfig)
3691 liloconfig = 1;
3692
3693 memset(&board, 0, sizeof(board));
3694
3695 /* Assume the data is int first, later we can change it */
3696 /* I think that array position 0 of ints holds the number of args */
3697 for (last = 0, index = 1; index <= ints[0]; index++)
3698 switch(index)
3699 { /* Begin parse switch */
3700
3701 case 1:
3702 board.status = ints[index];
3703
3704 /* ---------------------------------------------------------
3705 We check for 2 (As opposed to 1; because 2 is a flag
3706 instructing the driver to ignore epcaconfig.) For this
3707 reason we check for 2.
3708 ------------------------------------------------------------ */
3709 if (board.status == 2)
3710 { /* Begin ignore epcaconfig as well as lilo cmd line */
3711 nbdevs = 0;
3712 num_cards = 0;
3713 return;
3714 } /* End ignore epcaconfig as well as lilo cmd line */
3715
3716 if (board.status > 2)
3717 {
3718 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3719 invalid_lilo_config = 1;
3720 setup_error_code |= INVALID_BOARD_STATUS;
3721 return;
3722 }
3723 last = index;
3724 break;
3725
3726 case 2:
3727 board.type = ints[index];
3728 if (board.type >= PCIXEM)
3729 {
3730 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3731 invalid_lilo_config = 1;
3732 setup_error_code |= INVALID_BOARD_TYPE;
3733 return;
3734 }
3735 last = index;
3736 break;
3737
3738 case 3:
3739 board.altpin = ints[index];
3740 if (board.altpin > 1)
3741 {
3742 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3743 invalid_lilo_config = 1;
3744 setup_error_code |= INVALID_ALTPIN;
3745 return;
3746 }
3747 last = index;
3748 break;
3749
3750 case 4:
3751 board.numports = ints[index];
3752 if ((board.numports < 2) || (board.numports > 256))
3753 {
3754 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3755 invalid_lilo_config = 1;
3756 setup_error_code |= INVALID_NUM_PORTS;
3757 return;
3758 }
3759 nbdevs += board.numports;
3760 last = index;
3761 break;
3762
3763 case 5:
3764 board.port = (unsigned char *)ints[index];
3765 if (board.port <= 0)
3766 {
3767 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3768 invalid_lilo_config = 1;
3769 setup_error_code |= INVALID_PORT_BASE;
3770 return;
3771 }
3772 last = index;
3773 break;
3774
3775 case 6:
3776 board.membase = (unsigned char *)ints[index];
3777 if (board.membase <= 0)
3778 {
3779 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3780 invalid_lilo_config = 1;
3781 setup_error_code |= INVALID_MEM_BASE;
3782 return;
3783 }
3784 last = index;
3785 break;
3786
3787 default:
3788 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
3789 return;
3790
3791 } /* End parse switch */
3792
3793 while (str && *str)
3794 { /* Begin while there is a string arg */
3795
3796 /* find the next comma or terminator */
3797 temp = str;
3798
3799 /* While string is not null, and a comma hasn't been found */
3800 while (*temp && (*temp != ','))
3801 temp++;
3802
3803 if (!*temp)
3804 temp = NULL;
3805 else
3806 *temp++ = 0;
3807
3808 /* Set index to the number of args + 1 */
3809 index = last + 1;
3810
3811 switch(index)
3812 {
3813 case 1:
3814 len = strlen(str);
3815 if (strncmp("Disable", str, len) == 0)
3816 board.status = 0;
3817 else
3818 if (strncmp("Enable", str, len) == 0)
3819 board.status = 1;
3820 else
3821 {
3822 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3823 invalid_lilo_config = 1;
3824 setup_error_code |= INVALID_BOARD_STATUS;
3825 return;
3826 }
3827 last = index;
3828 break;
3829
3830 case 2:
3831
3832 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3833 if (strcmp(board_desc[loop], str) == 0)
3834 break;
3835
3836
3837 /* ---------------------------------------------------------------
3838 If the index incremented above refers to a legitamate board
3839 type set it here.
3840 ------------------------------------------------------------------*/
3841
3842 if (index < EPCA_NUM_TYPES)
3843 board.type = loop;
3844 else
3845 {
3846 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3847 invalid_lilo_config = 1;
3848 setup_error_code |= INVALID_BOARD_TYPE;
3849 return;
3850 }
3851 last = index;
3852 break;
3853
3854 case 3:
3855 len = strlen(str);
3856 if (strncmp("Disable", str, len) == 0)
3857 board.altpin = 0;
3858 else
3859 if (strncmp("Enable", str, len) == 0)
3860 board.altpin = 1;
3861 else
3862 {
3863 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3864 invalid_lilo_config = 1;
3865 setup_error_code |= INVALID_ALTPIN;
3866 return;
3867 }
3868 last = index;
3869 break;
3870
3871 case 4:
3872 t2 = str;
3873 while (isdigit(*t2))
3874 t2++;
3875
3876 if (*t2)
3877 {
3878 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3879 invalid_lilo_config = 1;
3880 setup_error_code |= INVALID_NUM_PORTS;
3881 return;
3882 }
3883
3884 /* ------------------------------------------------------------
3885 There is not a man page for simple_strtoul but the code can be
3886 found in vsprintf.c. The first argument is the string to
3887 translate (To an unsigned long obviously), the second argument
3888 can be the address of any character variable or a NULL. If a
3889 variable is given, the end pointer of the string will be stored
3890 in that variable; if a NULL is given the end pointer will
3891 not be returned. The last argument is the base to use. If
3892 a 0 is indicated, the routine will attempt to determine the
3893 proper base by looking at the values prefix (A '0' for octal,
3894 a 'x' for hex, etc ... If a value is given it will use that
3895 value as the base.
3896 ---------------------------------------------------------------- */
3897 board.numports = simple_strtoul(str, NULL, 0);
3898 nbdevs += board.numports;
3899 last = index;
3900 break;
3901
3902 case 5:
3903 t2 = str;
3904 while (isxdigit(*t2))
3905 t2++;
3906
3907 if (*t2)
3908 {
3909 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3910 invalid_lilo_config = 1;
3911 setup_error_code |= INVALID_PORT_BASE;
3912 return;
3913 }
3914
3915 board.port = (unsigned char *)simple_strtoul(str, NULL, 16);
3916 last = index;
3917 break;
3918
3919 case 6:
3920 t2 = str;
3921 while (isxdigit(*t2))
3922 t2++;
3923
3924 if (*t2)
3925 {
3926 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3927 invalid_lilo_config = 1;
3928 setup_error_code |= INVALID_MEM_BASE;
3929 return;
3930 }
3931
3932 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3933 last = index;
3934 break;
3935
3936 default:
3937 printk(KERN_ERR "PC/Xx: Too many string parms\n");
3938 return;
3939 }
3940 str = temp;
3941
3942 } /* End while there is a string arg */
3943
3944
3945 if (last < 6)
3946 {
3947 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3948 return;
3949 }
3950
3951 /* I should REALLY validate the stuff here */
3952
3953 /* Copies our local copy of board into boards */
3954 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3955
3956
3957 /* Does this get called once per lilo arg are what ? */
3958
3959 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3960 num_cards, board_desc[board.type],
3961 board.numports, (int)board.port, (unsigned int) board.membase);
3962
3963 num_cards++;
3964
3965 } /* End epca_setup */
3966
3967
3968
3969 #ifdef ENABLE_PCI
3970 /* ------------------------ Begin init_PCI --------------------------- */
3971
3972 enum epic_board_types {
3973 brd_xr = 0,
3974 brd_xem,
3975 brd_cx,
3976 brd_xrj,
3977 };
3978
3979
3980 /* indexed directly by epic_board_types enum */
3981 static struct {
3982 unsigned char board_type;
3983 unsigned bar_idx; /* PCI base address region */
3984 } epca_info_tbl[] = {
3985 { PCIXR, 0, },
3986 { PCIXEM, 0, },
3987 { PCICX, 0, },
3988 { PCIXRJ, 2, },
3989 };
3990
3991
3992 static int __init epca_init_one (struct pci_dev *pdev,
3993 const struct pci_device_id *ent)
3994 {
3995 static int board_num = -1;
3996 int board_idx, info_idx = ent->driver_data;
3997 unsigned long addr;
3998
3999 if (pci_enable_device(pdev))
4000 return -EIO;
4001
4002 board_num++;
4003 board_idx = board_num + num_cards;
4004 if (board_idx >= MAXBOARDS)
4005 goto err_out;
4006
4007 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
4008 if (!addr) {
4009 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
4010 epca_info_tbl[info_idx].bar_idx);
4011 goto err_out;
4012 }
4013
4014 boards[board_idx].status = ENABLED;
4015 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
4016 boards[board_idx].numports = 0x0;
4017 boards[board_idx].port =
4018 (unsigned char *)((char *) addr + PCI_IO_OFFSET);
4019 boards[board_idx].membase =
4020 (unsigned char *)((char *) addr);
4021
4022 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
4023 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
4024 0x200000, addr + PCI_IO_OFFSET);
4025 goto err_out;
4026 }
4027
4028 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
4029 if (!boards[board_idx].re_map_port) {
4030 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
4031 0x200000, addr + PCI_IO_OFFSET);
4032 goto err_out_free_pciio;
4033 }
4034
4035 if (!request_mem_region (addr, 0x200000, "epca")) {
4036 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
4037 0x200000, addr);
4038 goto err_out_free_iounmap;
4039 }
4040
4041 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
4042 if (!boards[board_idx].re_map_membase) {
4043 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
4044 0x200000, addr + PCI_IO_OFFSET);
4045 goto err_out_free_memregion;
4046 }
4047
4048 /* --------------------------------------------------------------
4049 I don't know what the below does, but the hardware guys say
4050 its required on everything except PLX (In this case XRJ).
4051 ---------------------------------------------------------------- */
4052 if (info_idx != brd_xrj) {
4053 pci_write_config_byte(pdev, 0x40, 0);
4054 pci_write_config_byte(pdev, 0x46, 0);
4055 }
4056
4057 return 0;
4058
4059 err_out_free_memregion:
4060 release_mem_region (addr, 0x200000);
4061 err_out_free_iounmap:
4062 iounmap (boards[board_idx].re_map_port);
4063 err_out_free_pciio:
4064 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
4065 err_out:
4066 return -ENODEV;
4067 }
4068
4069
4070 static struct pci_device_id epca_pci_tbl[] __initdata = {
4071 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
4072 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
4073 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
4074 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
4075 { 0, }
4076 };
4077
4078 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
4079
4080 int __init init_PCI (void)
4081 { /* Begin init_PCI */
4082
4083 int pci_count;
4084
4085 memset (&epca_driver, 0, sizeof (epca_driver));
4086 epca_driver.name = "epca";
4087 epca_driver.id_table = epca_pci_tbl;
4088 epca_driver.probe = epca_init_one;
4089
4090 pci_count = pci_register_driver (&epca_driver);
4091
4092 if (pci_count <= 0) {
4093 pci_unregister_driver (&epca_driver);
4094 pci_count = 0;
4095 }
4096
4097 return(pci_count);
4098
4099 } /* End init_PCI */
4100
4101 #endif /* ENABLE_PCI */
4102
4103 MODULE_LICENSE("GPL");
4104