Portability cleanup as required by Linus.
[linux-2.6/linux-mips.git] / drivers / char / epca.c
blob2ba24a26beb029f865459a46262619dca5e58fc4
1 /*
4 Copyright (C) 1996 Digi International.
6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456
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.
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.
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.
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.
27 --------------------------------------------------------------------------- */
28 /* See README.epca for change history --DAT*/
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>
46 #ifdef CONFIG_PCI
47 #define ENABLE_PCI
48 #endif /* CONFIG_PCI */
50 #define putUser(arg1, arg2) put_user(arg1, (unsigned long *)arg2)
51 #define getUser(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
53 #ifdef ENABLE_PCI
54 #include <linux/pci.h>
55 #include "digiPCI.h"
56 #endif /* ENABLE_PCI */
58 #include "digi1.h"
59 #include "digiFep1.h"
60 #include "epca.h"
61 #include "epcaconfig.h"
63 /* ---------------------- Begin defines ------------------------ */
65 #define VERSION "1.3.0.1-LK"
67 /* This major needs to be submitted to Linux to join the majors list */
69 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
72 #define MIN(a,b) ((a) < (b) ? (a) : (b))
73 #define MAXCARDS 7
74 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
76 #define PFX "epca: "
78 /* ----------------- Begin global definitions ------------------- */
80 static char mesg[100];
81 static int pc_refcount, nbdevs = 0, num_cards = 0, liloconfig = 0;
82 static int digi_poller_inhibited = 1 ;
84 static int setup_error_code = 0;
85 static int invalid_lilo_config = 0;
87 /* -----------------------------------------------------------------------
88 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
89 7 below.
90 --------------------------------------------------------------------------*/
91 static struct board_info boards[MAXBOARDS];
94 /* ------------- Begin structures used for driver registeration ---------- */
96 struct tty_driver pc_driver;
97 struct tty_driver pc_callout;
98 struct tty_driver pc_info;
100 /* The below structures are used to initialize the tty_driver structures. */
102 /* -------------------------------------------------------------------------
103 Note : MAX_ALLOC is currently limited to 0x100. This restriction is
104 placed on us by Linux not Digi.
105 ----------------------------------------------------------------------------*/
106 static struct tty_struct *pc_table[MAX_ALLOC];
107 static struct termios *pc_termios[MAX_ALLOC];
108 static struct termios *pc_termios_locked[MAX_ALLOC];
111 /* ------------------ Begin Digi specific structures -------------------- */
113 /* ------------------------------------------------------------------------
114 digi_channels represents an array of structures that keep track of
115 each channel of the Digi product. Information such as transmit and
116 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
117 are stored here. This structure is NOT used to overlay the cards
118 physical channel structure.
119 -------------------------------------------------------------------------- */
121 static struct channel digi_channels[MAX_ALLOC];
123 /* ------------------------------------------------------------------------
124 card_ptr is an array used to hold the address of the
125 first channel structure of each card. This array will hold
126 the addresses of various channels located in digi_channels.
127 -------------------------------------------------------------------------- */
128 static struct channel *card_ptr[MAXCARDS];
130 static struct timer_list epca_timer;
132 /* ---------------------- Begin function prototypes --------------------- */
134 /* ----------------------------------------------------------------------
135 Begin generic memory functions. These functions will be alias
136 (point at) more specific functions dependent on the board being
137 configured.
138 ----------------------------------------------------------------------- */
141 #ifdef MODULE
142 int init_module(void);
143 void cleanup_module(void);
144 #endif /* MODULE */
146 static inline void memwinon(struct board_info *b, unsigned int win);
147 static inline void memwinoff(struct board_info *b, unsigned int win);
148 static inline void globalwinon(struct channel *ch);
149 static inline void rxwinon(struct channel *ch);
150 static inline void txwinon(struct channel *ch);
151 static inline void memoff(struct channel *ch);
152 static inline void assertgwinon(struct channel *ch);
153 static inline void assertmemoff(struct channel *ch);
155 /* ---- Begin more 'specific' memory functions for cx_like products --- */
157 static inline void pcxem_memwinon(struct board_info *b, unsigned int win);
158 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win);
159 static inline void pcxem_globalwinon(struct channel *ch);
160 static inline void pcxem_rxwinon(struct channel *ch);
161 static inline void pcxem_txwinon(struct channel *ch);
162 static inline void pcxem_memoff(struct channel *ch);
164 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
166 static inline void pcxe_memwinon(struct board_info *b, unsigned int win);
167 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win);
168 static inline void pcxe_globalwinon(struct channel *ch);
169 static inline void pcxe_rxwinon(struct channel *ch);
170 static inline void pcxe_txwinon(struct channel *ch);
171 static inline void pcxe_memoff(struct channel *ch);
173 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
174 /* Note : pc64xe and pcxi share the same windowing routines */
176 static inline void pcxi_memwinon(struct board_info *b, unsigned int win);
177 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win);
178 static inline void pcxi_globalwinon(struct channel *ch);
179 static inline void pcxi_rxwinon(struct channel *ch);
180 static inline void pcxi_txwinon(struct channel *ch);
181 static inline void pcxi_memoff(struct channel *ch);
183 /* - Begin 'specific' do nothing memory functions needed for some cards - */
185 static inline void dummy_memwinon(struct board_info *b, unsigned int win);
186 static inline void dummy_memwinoff(struct board_info *b, unsigned int win);
187 static inline void dummy_globalwinon(struct channel *ch);
188 static inline void dummy_rxwinon(struct channel *ch);
189 static inline void dummy_txwinon(struct channel *ch);
190 static inline void dummy_memoff(struct channel *ch);
191 static inline void dummy_assertgwinon(struct channel *ch);
192 static inline void dummy_assertmemoff(struct channel *ch);
194 /* ------------------- Begin declare functions ----------------------- */
196 static inline struct channel *verifyChannel(register struct tty_struct *);
197 static inline void pc_sched_event(struct channel *, int);
198 static void epca_error(int, char *);
199 static void pc_close(struct tty_struct *, struct file *);
200 static void shutdown(struct channel *);
201 static void pc_hangup(struct tty_struct *);
202 static void pc_put_char(struct tty_struct *, unsigned char);
203 static int pc_write_room(struct tty_struct *);
204 static int pc_chars_in_buffer(struct tty_struct *);
205 static void pc_flush_buffer(struct tty_struct *);
206 static void pc_flush_chars(struct tty_struct *);
207 static int block_til_ready(struct tty_struct *, struct file *,
208 struct channel *);
209 static int pc_open(struct tty_struct *, struct file *);
210 static void post_fep_init(unsigned int crd);
211 static void epcapoll(unsigned long);
212 static void doevent(int);
213 static void fepcmd(struct channel *, int, int, int, int, int);
214 static unsigned termios2digi_h(struct channel *ch, unsigned);
215 static unsigned termios2digi_i(struct channel *ch, unsigned);
216 static unsigned termios2digi_c(struct channel *ch, unsigned);
217 static void epcaparam(struct tty_struct *, struct channel *);
218 static void receive_data(struct channel *);
219 static int pc_ioctl(struct tty_struct *, struct file *,
220 unsigned int, unsigned long);
221 static void pc_set_termios(struct tty_struct *, struct termios *);
222 static void do_softint(void *);
223 static void pc_stop(struct tty_struct *);
224 static void pc_start(struct tty_struct *);
225 static void pc_throttle(struct tty_struct * tty);
226 static void pc_unthrottle(struct tty_struct *tty);
227 static void digi_send_break(struct channel *ch, int msec);
228 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
229 void epca_setup(char *, int *);
230 void console_print(const char *);
232 static int get_termio(struct tty_struct *, struct termio *);
233 static int pc_write(struct tty_struct *, int, const unsigned char *, int);
234 int pc_init(void);
236 #ifdef ENABLE_PCI
237 static int init_PCI(void);
238 #endif /* ENABLE_PCI */
241 /* ------------------------------------------------------------------
242 Table of functions for each board to handle memory. Mantaining
243 parallelism is a *very* good idea here. The idea is for the
244 runtime code to blindly call these functions, not knowing/caring
245 about the underlying hardware. This stuff should contain no
246 conditionals; if more functionality is needed a different entry
247 should be established. These calls are the interface calls and
248 are the only functions that should be accessed. Anyone caught
249 making direct calls deserves what they get.
250 -------------------------------------------------------------------- */
252 static inline void memwinon(struct board_info *b, unsigned int win)
254 (b->memwinon)(b, win);
257 static inline void memwinoff(struct board_info *b, unsigned int win)
259 (b->memwinoff)(b, win);
262 static inline void globalwinon(struct channel *ch)
264 (ch->board->globalwinon)(ch);
267 static inline void rxwinon(struct channel *ch)
269 (ch->board->rxwinon)(ch);
272 static inline void txwinon(struct channel *ch)
274 (ch->board->txwinon)(ch);
277 static inline void memoff(struct channel *ch)
279 (ch->board->memoff)(ch);
281 static inline void assertgwinon(struct channel *ch)
283 (ch->board->assertgwinon)(ch);
286 static inline void assertmemoff(struct channel *ch)
288 (ch->board->assertmemoff)(ch);
291 /* ---------------------------------------------------------
292 PCXEM windowing is the same as that used in the PCXR
293 and CX series cards.
294 ------------------------------------------------------------ */
296 static inline void pcxem_memwinon(struct board_info *b, unsigned int win)
298 outb_p(FEPWIN|win, (int)b->port + 1);
301 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win)
303 outb_p(0, (int)b->port + 1);
306 static inline void pcxem_globalwinon(struct channel *ch)
308 outb_p( FEPWIN, (int)ch->board->port + 1);
311 static inline void pcxem_rxwinon(struct channel *ch)
313 outb_p(ch->rxwin, (int)ch->board->port + 1);
316 static inline void pcxem_txwinon(struct channel *ch)
318 outb_p(ch->txwin, (int)ch->board->port + 1);
321 static inline void pcxem_memoff(struct channel *ch)
323 outb_p(0, (int)ch->board->port + 1);
326 /* ----------------- Begin pcxe memory window stuff ------------------ */
328 static inline void pcxe_memwinon(struct board_info *b, unsigned int win)
330 outb_p(FEPWIN | win, (int)b->port + 1);
333 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win)
335 outb_p(inb((int)b->port) & ~FEPMEM,
336 (int)b->port + 1);
337 outb_p(0, (int)b->port + 1);
340 static inline void pcxe_globalwinon(struct channel *ch)
342 outb_p( FEPWIN, (int)ch->board->port + 1);
345 static inline void pcxe_rxwinon(struct channel *ch)
347 outb_p(ch->rxwin, (int)ch->board->port + 1);
350 static inline void pcxe_txwinon(struct channel *ch)
352 outb_p(ch->txwin, (int)ch->board->port + 1);
355 static inline void pcxe_memoff(struct channel *ch)
357 outb_p(0, (int)ch->board->port);
358 outb_p(0, (int)ch->board->port + 1);
361 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
363 static inline void pcxi_memwinon(struct board_info *b, unsigned int win)
365 outb_p(inb((int)b->port) | FEPMEM, (int)b->port);
368 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win)
370 outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port);
373 static inline void pcxi_globalwinon(struct channel *ch)
375 outb_p(FEPMEM, (int)ch->board->port);
378 static inline void pcxi_rxwinon(struct channel *ch)
380 outb_p(FEPMEM, (int)ch->board->port);
383 static inline void pcxi_txwinon(struct channel *ch)
385 outb_p(FEPMEM, (int)ch->board->port);
388 static inline void pcxi_memoff(struct channel *ch)
390 outb_p(0, (int)ch->board->port);
393 static inline void pcxi_assertgwinon(struct channel *ch)
395 epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off");
398 static inline void pcxi_assertmemoff(struct channel *ch)
400 epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on");
404 /* ----------------------------------------------------------------------
405 Not all of the cards need specific memory windowing routines. Some
406 cards (Such as PCI) needs no windowing routines at all. We provide
407 these do nothing routines so that the same code base can be used.
408 The driver will ALWAYS call a windowing routine if it thinks it needs
409 to; regardless of the card. However, dependent on the card the routine
410 may or may not do anything.
411 ---------------------------------------------------------------------------*/
413 static inline void dummy_memwinon(struct board_info *b, unsigned int win)
417 static inline void dummy_memwinoff(struct board_info *b, unsigned int win)
421 static inline void dummy_globalwinon(struct channel *ch)
425 static inline void dummy_rxwinon(struct channel *ch)
429 static inline void dummy_txwinon(struct channel *ch)
433 static inline void dummy_memoff(struct channel *ch)
437 static inline void dummy_assertgwinon(struct channel *ch)
441 static inline void dummy_assertmemoff(struct channel *ch)
445 /* ----------------- Begin verifyChannel function ----------------------- */
446 static inline struct channel *verifyChannel(register struct tty_struct *tty)
447 { /* Begin verifyChannel */
449 /* --------------------------------------------------------------------
450 This routine basically provides a sanity check. It insures that
451 the channel returned is within the proper range of addresses as
452 well as properly initialized. If some bogus info gets passed in
453 through tty->driver_data this should catch it.
454 --------------------------------------------------------------------- */
456 if (tty)
457 { /* Begin if tty */
459 register struct channel *ch = (struct channel *)tty->driver_data;
461 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs]))
463 if (ch->magic == EPCA_MAGIC)
464 return ch;
467 } /* End if tty */
469 /* Else return a NULL for invalid */
470 return NULL;
472 } /* End verifyChannel */
474 /* ------------------ Begin pc_sched_event ------------------------- */
476 static inline void pc_sched_event(struct channel *ch, int event)
477 { /* Begin pc_sched_event */
480 /* ----------------------------------------------------------------------
481 We call this to schedule interrupt processing on some event. The
482 kernel sees our request and calls the related routine in OUR driver.
483 -------------------------------------------------------------------------*/
485 ch->event |= 1 << event;
486 queue_task(&ch->tqueue, &tq_scheduler);
489 } /* End pc_sched_event */
491 /* ------------------ Begin epca_error ------------------------- */
493 static void epca_error(int line, char *msg)
494 { /* Begin epca_error */
496 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
497 return;
499 } /* End epca_error */
501 /* ------------------ Begin pc_close ------------------------- */
502 static void pc_close(struct tty_struct * tty, struct file * filp)
503 { /* Begin pc_close */
505 struct channel *ch;
506 unsigned long flags;
508 if (tty->driver.subtype == SERIAL_TYPE_INFO)
510 return;
514 /* ---------------------------------------------------------
515 verifyChannel returns the channel from the tty struct
516 if it is valid. This serves as a sanity check.
517 ------------------------------------------------------------- */
519 if ((ch = verifyChannel(tty)) != NULL)
520 { /* Begin if ch != NULL */
522 save_flags(flags);
523 cli();
525 if (tty_hung_up_p(filp))
527 restore_flags(flags);
528 return;
531 /* Check to see if the channel is open more than once */
532 if (ch->count-- > 1)
533 { /* Begin channel is open more than once */
535 /* -------------------------------------------------------------
536 Return without doing anything. Someone might still be using
537 the channel.
538 ---------------------------------------------------------------- */
540 restore_flags(flags);
541 return;
542 } /* End channel is open more than once */
544 /* Port open only once go ahead with shutdown & reset */
546 if (ch->count < 0)
548 ch->count = 0;
551 /* ---------------------------------------------------------------
552 Let the rest of the driver know the channel is being closed.
553 This becomes important if an open is attempted before close
554 is finished.
555 ------------------------------------------------------------------ */
557 ch->asyncflags |= ASYNC_CLOSING;
559 /* -------------------------------------------------------------
560 Save the termios structure, since this port may have
561 separate termios for callout and dialin.
562 --------------------------------------------------------------- */
564 if (ch->asyncflags & ASYNC_NORMAL_ACTIVE)
565 ch->normal_termios = *tty->termios;
567 if (ch->asyncflags & ASYNC_CALLOUT_ACTIVE)
568 ch->callout_termios = *tty->termios;
570 tty->closing = 1;
572 if (ch->asyncflags & ASYNC_INITIALIZED)
574 /* Setup an event to indicate when the transmit buffer empties */
575 setup_empty_event(tty, ch);
576 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
579 if (tty->driver.flush_buffer)
580 tty->driver.flush_buffer(tty);
582 if (tty->ldisc.flush_buffer)
583 tty->ldisc.flush_buffer(tty);
585 shutdown(ch);
586 tty->closing = 0;
587 ch->event = 0;
588 ch->tty = NULL;
590 if (ch->blocked_open)
591 { /* Begin if blocked_open */
593 if (ch->close_delay)
595 current->state = TASK_INTERRUPTIBLE;
596 schedule_timeout(ch->close_delay);
599 wake_up_interruptible(&ch->open_wait);
601 } /* End if blocked_open */
603 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
604 ASYNC_CALLOUT_ACTIVE | ASYNC_CLOSING);
605 wake_up_interruptible(&ch->close_wait);
607 #ifdef MODULE
608 MOD_DEC_USE_COUNT;
609 #endif
611 restore_flags(flags);
613 } /* End if ch != NULL */
615 } /* End pc_close */
617 /* ------------------ Begin shutdown ------------------------- */
619 static void shutdown(struct channel *ch)
620 { /* Begin shutdown */
622 unsigned long flags;
623 struct tty_struct *tty;
624 volatile struct board_chan *bc;
626 if (!(ch->asyncflags & ASYNC_INITIALIZED))
627 return;
629 save_flags(flags);
630 cli();
631 globalwinon(ch);
633 bc = ch->brdchan;
635 /* ------------------------------------------------------------------
636 In order for an event to be generated on the receipt of data the
637 idata flag must be set. Since we are shutting down, this is not
638 necessary clear this flag.
639 --------------------------------------------------------------------- */
641 if (bc)
642 bc->idata = 0;
644 tty = ch->tty;
646 /* ----------------------------------------------------------------
647 If we're a modem control device and HUPCL is on, drop RTS & DTR.
648 ------------------------------------------------------------------ */
650 if (tty->termios->c_cflag & HUPCL)
652 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
653 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
656 memoff(ch);
658 /* ------------------------------------------------------------------
659 The channel has officialy been closed. The next time it is opened
660 it will have to reinitialized. Set a flag to indicate this.
661 ---------------------------------------------------------------------- */
663 /* Prevent future Digi programmed interrupts from coming active */
665 ch->asyncflags &= ~ASYNC_INITIALIZED;
666 restore_flags(flags);
668 } /* End shutdown */
670 /* ------------------ Begin pc_hangup ------------------------- */
672 static void pc_hangup(struct tty_struct *tty)
673 { /* Begin pc_hangup */
675 struct channel *ch;
677 /* ---------------------------------------------------------
678 verifyChannel returns the channel from the tty struct
679 if it is valid. This serves as a sanity check.
680 ------------------------------------------------------------- */
682 if ((ch = verifyChannel(tty)) != NULL)
683 { /* Begin if ch != NULL */
685 unsigned long flags;
687 save_flags(flags);
688 cli();
689 if (tty->driver.flush_buffer)
690 tty->driver.flush_buffer(tty);
692 if (tty->ldisc.flush_buffer)
693 tty->ldisc.flush_buffer(tty);
695 shutdown(ch);
697 #ifdef MODULE
698 if (ch->count)
699 MOD_DEC_USE_COUNT;
700 #endif /* MODULE */
703 ch->tty = NULL;
704 ch->event = 0;
705 ch->count = 0;
706 restore_flags(flags);
707 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | ASYNC_CALLOUT_ACTIVE);
708 wake_up_interruptible(&ch->open_wait);
710 } /* End if ch != NULL */
712 } /* End pc_hangup */
714 /* ------------------ Begin pc_write ------------------------- */
716 static int pc_write(struct tty_struct * tty, int from_user,
717 const unsigned char *buf, int bytesAvailable)
718 { /* Begin pc_write */
720 register unsigned int head, tail;
721 register int dataLen;
722 register int size;
723 register int amountCopied;
726 struct channel *ch;
727 unsigned long flags;
728 int remain;
729 volatile struct board_chan *bc;
732 /* ----------------------------------------------------------------
733 pc_write is primarily called directly by the kernel routine
734 tty_write (Though it can also be called by put_char) found in
735 tty_io.c. pc_write is passed a line discipline buffer where
736 the data to be written out is stored. The line discipline
737 implementation itself is done at the kernel level and is not
738 brought into the driver.
739 ------------------------------------------------------------------- */
741 /* Stop users from hurting themselves on control minor */
743 if (tty->driver.subtype == SERIAL_TYPE_INFO)
745 return (0) ;
748 /* ---------------------------------------------------------
749 verifyChannel returns the channel from the tty struct
750 if it is valid. This serves as a sanity check.
751 ------------------------------------------------------------- */
753 if ((ch = verifyChannel(tty)) == NULL)
754 return 0;
756 /* Make a pointer to the channel data structure found on the board. */
758 bc = ch->brdchan;
759 size = ch->txbufsize;
761 if (from_user)
762 { /* Begin from_user */
764 save_flags(flags);
765 cli();
767 globalwinon(ch);
769 /* -----------------------------------------------------------------
770 Anding against size will wrap the pointer back to its begining
771 position if it is necessary. This will only work if size is
772 a power of 2 which should always be the case. Size is determined
773 by the cards on board FEP/OS.
774 -------------------------------------------------------------------- */
776 /* head refers to the next empty location in which data may be stored */
778 head = bc->tin & (size - 1);
780 /* tail refers to the next data byte to be transmitted */
782 tail = bc->tout;
784 /* Consider changing this to a do statement to make sure */
786 if (tail != bc->tout)
787 tail = bc->tout;
789 /* ------------------------------------------------------------------
790 Anding against size will wrap the pointer back to its begining
791 position if it is necessary. This will only work if size is
792 a power of 2 which should always be the case. Size is determined
793 by the cards on board FEP/OS.
794 --------------------------------------------------------------------- */
796 tail &= (size - 1);
798 /* -----------------------------------------------------------------
799 Two situations can affect how space in the transmit buffer
800 is calculated. You can have a situation where the transmit
801 in pointer (tin) head has wrapped around and actually has a
802 lower address than the transmit out pointer (tout) tail; or
803 the transmit in pointer (tin) head will not be wrapped around
804 yet, and have a higher address than the transmit out pointer
805 (tout) tail. Obviously space available in the transmit buffer
806 is calculated differently for each case.
808 Example 1:
810 Consider a 10 byte buffer where head is a pointer to the next
811 empty location in the buffer and tail is a pointer to the next
812 byte to transmit. In this example head will not have wrapped
813 around and therefore head > tail.
815 0 1 2 3 4 5 6 7 8 9
816 tail head
818 The above diagram shows that buffer locations 2,3,4,5 and 6 have
819 data to be transmited, while head points at the next empty
820 location. To calculate how much space is available first we have
821 to determine if the head pointer (tin) has wrapped. To do this
822 compare the head pointer to the tail pointer, If head is equal
823 or greater than tail; then it has not wrapped; and the space may
824 be calculated by subtracting tail from head and then subtracting
825 that value from the buffers size. A one is subtracted from the
826 new value to indicate how much space is available between the
827 head pointer and end of buffer; as well as the space between the
828 begining of the buffer and the tail. If the head is not greater
829 or equal to the tail this indicates that the head has wrapped
830 around to the begining of the buffer. To calculate the space
831 available in this case simply subtract head from tail. This new
832 value minus one represents the space available betwwen the head
833 and tail pointers. In this example head (7) is greater than tail (2)
834 and therefore has not wrapped around. We find the space by first
835 subtracting tail from head (7-2=5). We then subtract this value
836 from the buffer size of ten and subtract one (10-5-1=4). The space
837 remaining is 4 bytes.
839 Example 2:
841 Consider a 10 byte buffer where head is a pointer to the next
842 empty location in the buffer and tail is a pointer to the next
843 byte to transmit. In this example head will wrapped around and
844 therefore head < tail.
846 0 1 2 3 4 5 6 7 8 9
847 head tail
849 The above diagram shows that buffer locations 7,8,9,0 and 1 have
850 data to be transmited, while head points at the next empty
851 location. To find the space available we compare head to tail. If
852 head is not equal to, or greater than tail this indicates that head
853 has wrapped around. In this case head (2) is not equal to, or
854 greater than tail (7) and therefore has already wrapped around. To
855 calculate the available space between the two pointers we subtract
856 head from tail (7-2=5). We then subtract one from this new value
857 (5-1=4). We have 5 bytes empty remaining in the buffer. Unlike the
858 previous example these five bytes are located between the head and
859 tail pointers.
861 ----------------------------------------------------------------------- */
863 dataLen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1);
865 /* ----------------------------------------------------------------------
866 In this case bytesAvailable has been passed into pc_write and
867 represents the amount of data that needs to be written. dataLen
868 represents the amount of space available on the card. Whichever
869 value is smaller will be the amount actually written.
870 bytesAvailable will then take on this newly calculated value.
871 ---------------------------------------------------------------------- */
873 bytesAvailable = MIN(dataLen, bytesAvailable);
875 /* First we read the data in from the file system into a temp buffer */
877 if (bytesAvailable)
878 { /* Begin bytesAvailable */
880 /* Can the user buffer be accessed at the moment ? */
881 if (verify_area(VERIFY_READ, (char*)buf, bytesAvailable))
882 bytesAvailable = 0; /* Can't do; try again later */
883 else /* Evidently it can, began transmission */
884 { /* Begin if area verified */
885 /* ---------------------------------------------------------------
886 The below function reads data from user memory. This routine
887 can not be used in an interrupt routine. (Because it may
888 generate a page fault) It can only be called while we can the
889 user context is accessible.
891 The prototype is :
892 inline void copy_from_user(void * to, const void * from,
893 unsigned long count);
895 You must include <asm/segment.h>
896 I also think (Check hackers guide) that optimization must
897 be turned ON. (Which sounds strange to me...)
899 Remember copy_from_user WILL generate a page fault if the
900 user memory being accessed has been swapped out. This can
901 cause this routine to temporarily sleep while this page
902 fault is occuring.
904 ----------------------------------------------------------------- */
906 copy_from_user(ch->tmp_buf, buf, bytesAvailable);
908 } /* End if area verified */
910 } /* End bytesAvailable */
912 /* ------------------------------------------------------------------
913 Set buf to this address for the moment. tmp_buf was allocated in
914 post_fep_init.
915 --------------------------------------------------------------------- */
916 buf = ch->tmp_buf;
917 memoff(ch);
918 restore_flags(flags);
920 } /* End from_user */
922 /* All data is now local */
924 amountCopied = 0;
925 save_flags(flags);
926 cli();
928 globalwinon(ch);
930 head = bc->tin & (size - 1);
931 tail = bc->tout;
933 if (tail != bc->tout)
934 tail = bc->tout;
935 tail &= (size - 1);
937 /* If head >= tail, head has not wrapped around. */
938 if (head >= tail)
939 { /* Begin head has not wrapped */
941 /* ---------------------------------------------------------------
942 remain (much like dataLen above) represents the total amount of
943 space available on the card for data. Here dataLen represents
944 the space existing between the head pointer and the end of
945 buffer. This is important because a memcpy cannot be told to
946 automatically wrap around when it hits the buffer end.
947 ------------------------------------------------------------------ */
949 dataLen = size - head;
950 remain = size - (head - tail) - 1;
952 } /* End head has not wrapped */
953 else
954 { /* Begin head has wrapped around */
956 remain = tail - head - 1;
957 dataLen = remain;
959 } /* End head has wrapped around */
961 /* -------------------------------------------------------------------
962 Check the space on the card. If we have more data than
963 space; reduce the amount of data to fit the space.
964 ---------------------------------------------------------------------- */
966 bytesAvailable = MIN(remain, bytesAvailable);
968 txwinon(ch);
969 while (bytesAvailable > 0)
970 { /* Begin while there is data to copy onto card */
972 /* -----------------------------------------------------------------
973 If head is not wrapped, the below will make sure the first
974 data copy fills to the end of card buffer.
975 ------------------------------------------------------------------- */
977 dataLen = MIN(bytesAvailable, dataLen);
978 memcpy(ch->txptr + head, buf, dataLen);
979 buf += dataLen;
980 head += dataLen;
981 amountCopied += dataLen;
982 bytesAvailable -= dataLen;
984 if (head >= size)
986 head = 0;
987 dataLen = tail;
990 } /* End while there is data to copy onto card */
992 ch->statusflags |= TXBUSY;
993 globalwinon(ch);
994 bc->tin = head;
996 if ((ch->statusflags & LOWWAIT) == 0)
998 ch->statusflags |= LOWWAIT;
999 bc->ilow = 1;
1001 memoff(ch);
1002 restore_flags(flags);
1004 return(amountCopied);
1006 } /* End pc_write */
1008 /* ------------------ Begin pc_put_char ------------------------- */
1010 static void pc_put_char(struct tty_struct *tty, unsigned char c)
1011 { /* Begin pc_put_char */
1014 pc_write(tty, 0, &c, 1);
1015 return;
1017 } /* End pc_put_char */
1019 /* ------------------ Begin pc_write_room ------------------------- */
1021 static int pc_write_room(struct tty_struct *tty)
1022 { /* Begin pc_write_room */
1024 int remain;
1025 struct channel *ch;
1026 unsigned long flags;
1027 unsigned int head, tail;
1028 volatile struct board_chan *bc;
1030 remain = 0;
1032 /* ---------------------------------------------------------
1033 verifyChannel returns the channel from the tty struct
1034 if it is valid. This serves as a sanity check.
1035 ------------------------------------------------------------- */
1037 if ((ch = verifyChannel(tty)) != NULL)
1039 save_flags(flags);
1040 cli();
1041 globalwinon(ch);
1043 bc = ch->brdchan;
1044 head = bc->tin & (ch->txbufsize - 1);
1045 tail = bc->tout;
1047 if (tail != bc->tout)
1048 tail = bc->tout;
1049 /* Wrap tail if necessary */
1050 tail &= (ch->txbufsize - 1);
1052 if ((remain = tail - head - 1) < 0 )
1053 remain += ch->txbufsize;
1055 if (remain && (ch->statusflags & LOWWAIT) == 0)
1057 ch->statusflags |= LOWWAIT;
1058 bc->ilow = 1;
1060 memoff(ch);
1061 restore_flags(flags);
1064 /* Return how much room is left on card */
1065 return remain;
1067 } /* End pc_write_room */
1069 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
1071 static int pc_chars_in_buffer(struct tty_struct *tty)
1072 { /* Begin pc_chars_in_buffer */
1074 int chars;
1075 unsigned int ctail, head, tail;
1076 int remain;
1077 unsigned long flags;
1078 struct channel *ch;
1079 volatile struct board_chan *bc;
1082 /* ---------------------------------------------------------
1083 verifyChannel returns the channel from the tty struct
1084 if it is valid. This serves as a sanity check.
1085 ------------------------------------------------------------- */
1087 if ((ch = verifyChannel(tty)) == NULL)
1088 return(0);
1090 save_flags(flags);
1091 cli();
1092 globalwinon(ch);
1094 bc = ch->brdchan;
1095 tail = bc->tout;
1096 head = bc->tin;
1097 ctail = ch->mailbox->cout;
1099 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
1100 chars = 0;
1101 else
1102 { /* Begin if some space on the card has been used */
1104 head = bc->tin & (ch->txbufsize - 1);
1105 tail &= (ch->txbufsize - 1);
1107 /* --------------------------------------------------------------
1108 The logic here is basically opposite of the above pc_write_room
1109 here we are finding the amount of bytes in the buffer filled.
1110 Not the amount of bytes empty.
1111 ------------------------------------------------------------------- */
1113 if ((remain = tail - head - 1) < 0 )
1114 remain += ch->txbufsize;
1116 chars = (int)(ch->txbufsize - remain);
1118 /* -------------------------------------------------------------
1119 Make it possible to wakeup anything waiting for output
1120 in tty_ioctl.c, etc.
1122 If not already set. Setup an event to indicate when the
1123 transmit buffer empties
1124 ----------------------------------------------------------------- */
1126 if (!(ch->statusflags & EMPTYWAIT))
1127 setup_empty_event(tty,ch);
1129 } /* End if some space on the card has been used */
1131 memoff(ch);
1132 restore_flags(flags);
1134 /* Return number of characters residing on card. */
1135 return(chars);
1137 } /* End pc_chars_in_buffer */
1139 /* ------------------ Begin pc_flush_buffer ---------------------- */
1141 static void pc_flush_buffer(struct tty_struct *tty)
1142 { /* Begin pc_flush_buffer */
1144 unsigned int tail;
1145 unsigned long flags;
1146 struct channel *ch;
1147 volatile struct board_chan *bc;
1150 /* ---------------------------------------------------------
1151 verifyChannel returns the channel from the tty struct
1152 if it is valid. This serves as a sanity check.
1153 ------------------------------------------------------------- */
1155 if ((ch = verifyChannel(tty)) == NULL)
1156 return;
1158 save_flags(flags);
1159 cli();
1161 globalwinon(ch);
1163 bc = ch->brdchan;
1164 tail = bc->tout;
1166 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1168 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1170 memoff(ch);
1171 restore_flags(flags);
1173 wake_up_interruptible(&tty->write_wait);
1174 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1175 (tty->ldisc.write_wakeup)(tty);
1177 } /* End pc_flush_buffer */
1179 /* ------------------ Begin pc_flush_chars ---------------------- */
1181 static void pc_flush_chars(struct tty_struct *tty)
1182 { /* Begin pc_flush_chars */
1184 struct channel * ch;
1186 /* ---------------------------------------------------------
1187 verifyChannel returns the channel from the tty struct
1188 if it is valid. This serves as a sanity check.
1189 ------------------------------------------------------------- */
1191 if ((ch = verifyChannel(tty)) != NULL)
1193 unsigned long flags;
1195 save_flags(flags);
1196 cli();
1198 /* ----------------------------------------------------------------
1199 If not already set and the transmitter is busy setup an event
1200 to indicate when the transmit empties.
1201 ------------------------------------------------------------------- */
1203 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
1204 setup_empty_event(tty,ch);
1206 restore_flags(flags);
1209 } /* End pc_flush_chars */
1211 /* ------------------ Begin block_til_ready ---------------------- */
1213 static int block_til_ready(struct tty_struct *tty,
1214 struct file *filp, struct channel *ch)
1215 { /* Begin block_til_ready */
1217 DECLARE_WAITQUEUE(wait,current);
1218 int retval, do_clocal = 0;
1219 unsigned long flags;
1222 if (tty_hung_up_p(filp))
1224 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1225 retval = -EAGAIN;
1226 else
1227 retval = -ERESTARTSYS;
1228 return(retval);
1231 /* -----------------------------------------------------------------
1232 If the device is in the middle of being closed, then block
1233 until it's done, and then try again.
1234 -------------------------------------------------------------------- */
1235 if (ch->asyncflags & ASYNC_CLOSING)
1237 interruptible_sleep_on(&ch->close_wait);
1239 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1240 return -EAGAIN;
1241 else
1242 return -ERESTARTSYS;
1245 /* -----------------------------------------------------------------
1246 If this is a callout device, then just make sure the normal
1247 device isn't being used.
1248 -------------------------------------------------------------------- */
1250 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT)
1251 { /* A cud device has been opened */
1252 if (ch->asyncflags & ASYNC_NORMAL_ACTIVE)
1253 return -EBUSY;
1255 if ((ch->asyncflags & ASYNC_CALLOUT_ACTIVE) &&
1256 (ch->asyncflags & ASYNC_SESSION_LOCKOUT) &&
1257 (ch->session != current->session))
1258 return -EBUSY;
1260 if ((ch->asyncflags & ASYNC_CALLOUT_ACTIVE) &&
1261 (ch->asyncflags & ASYNC_PGRP_LOCKOUT) &&
1262 (ch->pgrp != current->pgrp))
1263 return -EBUSY;
1265 ch->asyncflags |= ASYNC_CALLOUT_ACTIVE;
1267 return 0;
1268 } /* End a cud device has been opened */
1270 if (filp->f_flags & O_NONBLOCK)
1272 /* -----------------------------------------------------------------
1273 If non-blocking mode is set, then make the check up front
1274 and then exit.
1275 -------------------------------------------------------------------- */
1277 if (ch->asyncflags & ASYNC_CALLOUT_ACTIVE)
1278 return -EBUSY;
1280 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1282 return 0;
1286 if (ch->asyncflags & ASYNC_CALLOUT_ACTIVE)
1288 if (ch->normal_termios.c_cflag & CLOCAL)
1289 do_clocal = 1;
1291 else
1293 if (tty->termios->c_cflag & CLOCAL)
1294 do_clocal = 1;
1297 /* Block waiting for the carrier detect and the line to become free */
1299 retval = 0;
1300 add_wait_queue(&ch->open_wait, &wait);
1301 save_flags(flags);
1302 cli();
1305 /* We dec count so that pc_close will know when to free things */
1306 if (!tty_hung_up_p(filp))
1307 ch->count--;
1309 restore_flags(flags);
1311 ch->blocked_open++;
1313 while(1)
1314 { /* Begin forever while */
1316 set_current_state(TASK_INTERRUPTIBLE);
1318 if (tty_hung_up_p(filp) ||
1319 !(ch->asyncflags & ASYNC_INITIALIZED))
1321 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1322 retval = -EAGAIN;
1323 else
1324 retval = -ERESTARTSYS;
1325 break;
1328 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1329 !(ch->asyncflags & ASYNC_CALLOUT_ACTIVE) &&
1330 (do_clocal || (ch->imodem & ch->dcd)))
1331 break;
1333 if (signal_pending(current))
1335 retval = -ERESTARTSYS;
1336 break;
1339 /* ---------------------------------------------------------------
1340 Allow someone else to be scheduled. We will occasionaly go
1341 through this loop until one of the above conditions change.
1342 The below schedule call will allow other processes to enter and
1343 prevent this loop from hogging the cpu.
1344 ------------------------------------------------------------------ */
1345 schedule();
1347 } /* End forever while */
1349 current->state = TASK_RUNNING;
1350 remove_wait_queue(&ch->open_wait, &wait);
1351 cli();
1352 if (!tty_hung_up_p(filp))
1353 ch->count++;
1354 restore_flags(flags);
1356 ch->blocked_open--;
1358 if (retval)
1359 return retval;
1361 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1363 return 0;
1365 } /* End block_til_ready */
1367 /* ------------------ Begin pc_open ---------------------- */
1369 static int pc_open(struct tty_struct *tty, struct file * filp)
1370 { /* Begin pc_open */
1372 struct channel *ch;
1373 unsigned long flags;
1374 int line, retval, boardnum;
1375 volatile struct board_chan *bc;
1376 volatile unsigned int head;
1378 /* Nothing "real" happens in open of control device */
1380 if (tty->driver.subtype == SERIAL_TYPE_INFO)
1382 return (0) ;
1385 line = MINOR(tty->device) - tty->driver.minor_start;
1386 if (line < 0 || line >= nbdevs)
1388 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1389 tty->driver_data = NULL;
1390 return(-ENODEV);
1393 #ifdef MODULE
1395 MOD_INC_USE_COUNT;
1397 #endif
1399 ch = &digi_channels[line];
1400 boardnum = ch->boardnum;
1402 /* Check status of board configured in system. */
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 ---------------------------------------------------------------------- */
1410 if (invalid_lilo_config)
1412 if (setup_error_code & INVALID_BOARD_TYPE)
1413 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n");
1415 if (setup_error_code & INVALID_NUM_PORTS)
1416 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1418 if (setup_error_code & INVALID_MEM_BASE)
1419 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1421 if (setup_error_code & INVALID_PORT_BASE)
1422 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n");
1424 if (setup_error_code & INVALID_BOARD_STATUS)
1425 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n");
1427 if (setup_error_code & INVALID_ALTPIN)
1428 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1430 tty->driver_data = NULL; /* Mark this device as 'down' */
1431 return(-ENODEV);
1434 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1436 tty->driver_data = NULL; /* Mark this device as 'down' */
1437 return(-ENODEV);
1440 if (( bc = ch->brdchan) == 0)
1442 tty->driver_data = NULL;
1443 return(-ENODEV);
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 --------------------------------------------------------------------- */
1452 ch->count++;
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 ------------------------------------------------------------------ */
1460 tty->driver_data = ch;
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 -------------------------------------------------------------------- */
1467 /* Should this be here except for SPLIT termios ? */
1468 if (ch->count == 1)
1470 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
1471 *tty->termios = ch->normal_termios;
1472 else
1473 *tty->termios = ch->callout_termios;
1476 ch->session = current->session;
1477 ch->pgrp = current->pgrp;
1479 save_flags(flags);
1480 cli();
1482 globalwinon(ch);
1483 ch->statusflags = 0;
1485 /* Save boards current modem status */
1486 ch->imodem = bc->mstat;
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;
1495 /* Set the channels associated tty structure */
1496 ch->tty = tty;
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);
1504 ch->asyncflags |= ASYNC_INITIALIZED;
1505 memoff(ch);
1507 restore_flags(flags);
1509 retval = block_til_ready(tty, filp, ch);
1510 if (retval)
1512 return retval;
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;
1521 save_flags(flags);
1522 cli();
1523 globalwinon(ch);
1525 /* Enable Digi Data events */
1526 bc->idata = 1;
1528 memoff(ch);
1529 restore_flags(flags);
1531 return 0;
1533 } /* End pc_open */
1535 #ifdef MODULE
1536 /* -------------------- Begin init_module ---------------------- */
1537 int __init init_module()
1538 { /* Begin init_module */
1540 unsigned long flags;
1542 save_flags(flags);
1543 cli();
1545 pc_init();
1547 restore_flags(flags);
1549 return(0);
1550 } /* End init_module */
1552 #endif
1554 #ifdef ENABLE_PCI
1555 static struct pci_driver epca_driver;
1556 #endif
1558 #ifdef MODULE
1559 /* -------------------- Begin cleanup_module ---------------------- */
1561 void cleanup_module()
1562 { /* Begin cleanup_module */
1564 int count, crd;
1565 struct board_info *bd;
1566 struct channel *ch;
1567 unsigned long flags;
1569 del_timer_sync(&epca_timer);
1571 save_flags(flags);
1572 cli();
1574 if ((tty_unregister_driver(&pc_driver)) ||
1575 (tty_unregister_driver(&pc_callout)))
1577 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1578 restore_flags(flags);
1579 return;
1582 for (crd = 0; crd < num_cards; crd++)
1583 { /* Begin for each card */
1585 bd = &boards[crd];
1587 if (!bd)
1588 { /* Begin sanity check */
1589 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1590 return;
1591 } /* End sanity check */
1593 ch = card_ptr[crd];
1595 for (count = 0; count < bd->numports; count++, ch++)
1596 { /* Begin for each port */
1598 if (ch)
1600 if (ch->tty)
1601 tty_hangup(ch->tty);
1602 kfree_s(ch->tmp_buf, ch->txbufsize);
1605 } /* End for each port */
1606 } /* End for each card */
1608 #ifdef ENABLE_PCI
1609 pci_unregister_driver (&epca_driver);
1610 #endif
1612 restore_flags(flags);
1614 } /* End cleanup_module */
1615 #endif /* MODULE */
1617 /* ------------------ Begin pc_init ---------------------- */
1619 int __init pc_init(void)
1620 { /* Begin pc_init */
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 ------------------------------------------------------------------*/
1637 ulong flags, save_loops_per_sec;
1638 int crd;
1639 struct board_info *bd;
1640 unsigned char board_id = 0;
1643 #ifdef ENABLE_PCI
1644 int pci_boards_found, pci_count;
1646 pci_count = 0;
1647 #endif /* ENABLE_PCI */
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 */
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 */
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 --------------------------------------------------------------------- */
1671 /* -----------------------------------------------------------
1672 Set up interrupt, we will worry about memory allocation in
1673 post_fep_init.
1674 --------------------------------------------------------------- */
1677 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1679 #ifdef ENABLE_PCI
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 begining
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.)
1699 --------------------------------------------------------------------- */
1701 pci_boards_found = 0;
1702 if (pci_present())
1704 if(num_cards < MAXBOARDS)
1705 pci_boards_found += init_PCI();
1706 num_cards += pci_boards_found;
1708 else
1710 printk(KERN_ERR "<Error> - No PCI BIOS found\n");
1713 #endif /* ENABLE_PCI */
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));
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;
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;
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;
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 --------------------------------------------------------------------- */
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;
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;
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;
1778 /* ---------------------------------------------------------------------
1779 loops_per_sec hasn't been set at this point :-(, so fake it out...
1780 I set it, so that I can use the __delay() function.
1781 ------------------------------------------------------------------------ */
1782 save_loops_per_sec = loops_per_sec;
1783 loops_per_sec = 13L * 500000L;
1785 save_flags(flags);
1786 cli();
1788 for (crd = 0; crd < num_cards; crd++)
1789 { /* Begin for each card */
1791 /* ------------------------------------------------------------------
1792 This is where the appropriate memory handlers for the hardware is
1793 set. Everything at runtime blindly jumps through these vectors.
1794 ---------------------------------------------------------------------- */
1796 /* defined in epcaconfig.h */
1797 bd = &boards[crd];
1799 switch (bd->type)
1800 { /* Begin switch on bd->type {board type} */
1801 case PCXEM:
1802 case EISAXEM:
1803 bd->memwinon = pcxem_memwinon ;
1804 bd->memwinoff = pcxem_memwinoff ;
1805 bd->globalwinon = pcxem_globalwinon ;
1806 bd->txwinon = pcxem_txwinon ;
1807 bd->rxwinon = pcxem_rxwinon ;
1808 bd->memoff = pcxem_memoff ;
1809 bd->assertgwinon = dummy_assertgwinon;
1810 bd->assertmemoff = dummy_assertmemoff;
1811 break;
1813 case PCIXEM:
1814 case PCIXRJ:
1815 case PCIXR:
1816 bd->memwinon = dummy_memwinon;
1817 bd->memwinoff = dummy_memwinoff;
1818 bd->globalwinon = dummy_globalwinon;
1819 bd->txwinon = dummy_txwinon;
1820 bd->rxwinon = dummy_rxwinon;
1821 bd->memoff = dummy_memoff;
1822 bd->assertgwinon = dummy_assertgwinon;
1823 bd->assertmemoff = dummy_assertmemoff;
1824 break;
1826 case PCXE:
1827 case PCXEVE:
1829 bd->memwinon = pcxe_memwinon;
1830 bd->memwinoff = pcxe_memwinoff;
1831 bd->globalwinon = pcxe_globalwinon;
1832 bd->txwinon = pcxe_txwinon;
1833 bd->rxwinon = pcxe_rxwinon;
1834 bd->memoff = pcxe_memoff;
1835 bd->assertgwinon = dummy_assertgwinon;
1836 bd->assertmemoff = dummy_assertmemoff;
1837 break;
1839 case PCXI:
1840 case PC64XE:
1842 bd->memwinon = pcxi_memwinon;
1843 bd->memwinoff = pcxi_memwinoff;
1844 bd->globalwinon = pcxi_globalwinon;
1845 bd->txwinon = pcxi_txwinon;
1846 bd->rxwinon = pcxi_rxwinon;
1847 bd->memoff = pcxi_memoff;
1848 bd->assertgwinon = pcxi_assertgwinon;
1849 bd->assertmemoff = pcxi_assertmemoff;
1850 break;
1852 default:
1853 break;
1855 } /* End switch on bd->type */
1857 /* ---------------------------------------------------------------
1858 Some cards need a memory segment to be defined for use in
1859 transmit and receive windowing operations. These boards
1860 are listed in the below switch. In the case of the XI the
1861 amount of memory on the board is variable so the memory_seg
1862 is also variable. This code determines what they segment
1863 should be.
1864 ----------------------------------------------------------------- */
1866 switch (bd->type)
1867 { /* Begin switch on bd->type {board type} */
1869 case PCXE:
1870 case PCXEVE:
1871 case PC64XE:
1872 bd->memory_seg = 0xf000;
1873 break;
1875 case PCXI:
1876 board_id = inb((int)bd->port);
1877 if ((board_id & 0x1) == 0x1)
1878 { /* Begin its an XI card */
1880 /* Is it a 64K board */
1881 if ((board_id & 0x30) == 0)
1882 bd->memory_seg = 0xf000;
1884 /* Is it a 128K board */
1885 if ((board_id & 0x30) == 0x10)
1886 bd->memory_seg = 0xe000;
1888 /* Is is a 256K board */
1889 if ((board_id & 0x30) == 0x20)
1890 bd->memory_seg = 0xc000;
1892 /* Is it a 512K board */
1893 if ((board_id & 0x30) == 0x30)
1894 bd->memory_seg = 0x8000;
1896 } /* End it is an XI card */
1897 else
1899 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1901 break;
1903 } /* End switch on bd->type */
1905 } /* End for each card */
1907 if (tty_register_driver(&pc_driver))
1908 panic("Couldn't register Digi PC/ driver");
1910 if (tty_register_driver(&pc_callout))
1911 panic("Couldn't register Digi PC/ callout");
1913 if (tty_register_driver(&pc_info))
1914 panic("Couldn't register Digi PC/ info ");
1916 loops_per_sec = save_loops_per_sec; /* reset it to what it should be */
1918 /* -------------------------------------------------------------------
1919 Start up the poller to check for events on all enabled boards
1920 ---------------------------------------------------------------------- */
1922 init_timer(&epca_timer);
1923 epca_timer.function = epcapoll;
1924 mod_timer(&epca_timer, jiffies + HZ/25);
1926 restore_flags(flags);
1928 return 0;
1930 } /* End pc_init */
1932 /* ------------------ Begin post_fep_init ---------------------- */
1934 static void post_fep_init(unsigned int crd)
1935 { /* Begin post_fep_init */
1937 int i;
1938 unchar *memaddr;
1939 volatile struct global_data *gd;
1940 struct board_info *bd;
1941 volatile struct board_chan *bc;
1942 struct channel *ch;
1943 int shrinkmem = 0, lowwater ;
1945 /* -------------------------------------------------------------
1946 This call is made by the user via. the ioctl call DIGI_INIT.
1947 It is resposible for setting up all the card specific stuff.
1948 ---------------------------------------------------------------- */
1949 bd = &boards[crd];
1951 /* -----------------------------------------------------------------
1952 If this is a PCI board, get the port info. Remember PCI cards
1953 do not have entries into the epcaconfig.h file, so we can't get
1954 the number of ports from it. Unfortunetly, this means that anyone
1955 doing a DIGI_GETINFO before the board has booted will get an invalid
1956 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1957 after DIGI_INIT has been called will return the proper values.
1958 ------------------------------------------------------------------- */
1960 if (bd->type >= PCIXEM) /* If the board in question is PCI */
1961 { /* Begin get PCI number of ports */
1963 /* --------------------------------------------------------------------
1964 Below we use XEMPORTS as a memory offset regardless of which PCI
1965 card it is. This is because all of the supported PCI cards have
1966 the same memory offset for the channel data. This will have to be
1967 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1968 states that the port offset is 0xC22 as opposed to 0xC02. This is
1969 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1970 On the PCI cards the number of ports is determined by reading a
1971 ID PROM located in the box attached to the card. The card can then
1972 determine the index the id to determine the number of ports available.
1973 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1974 if the box in question is a XEM or CX)).
1975 ------------------------------------------------------------------------ */
1977 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1978 (bd->re_map_membase + XEMPORTS));
1981 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1982 nbdevs += (bd->numports);
1984 } /* End get PCI number of ports */
1986 if (crd != 0)
1987 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1988 else
1989 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1991 ch = card_ptr[crd];
1994 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1996 memaddr = (unchar *)bd->re_map_membase;
1999 The below command is necessary because newer kernels (2.1.x and
2000 up) do not have a 1:1 virtual to physical mapping. The below
2001 call adjust for that.
2004 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2006 /* -----------------------------------------------------------------
2007 The below assignment will set bc to point at the BEGINING of
2008 the cards channel structures. For 1 card there will be between
2009 8 and 64 of these structures.
2010 -------------------------------------------------------------------- */
2012 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
2014 /* -------------------------------------------------------------------
2015 The below assignment will set gd to point at the BEGINING of
2016 global memory address 0xc00. The first data in that global
2017 memory actually starts at address 0xc1a. The command in
2018 pointer begins at 0xd10.
2019 ---------------------------------------------------------------------- */
2021 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
2023 /* --------------------------------------------------------------------
2024 XEPORTS (address 0xc22) points at the number of channels the
2025 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
2026 ----------------------------------------------------------------------- */
2028 if (((bd->type == PCXEVE) | (bd->type == PCXE)) &&
2029 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
2030 shrinkmem = 1;
2031 if (bd->type < PCIXEM)
2032 request_region((int)bd->port, 4, board_desc[bd->type]);
2034 memwinon(bd, 0);
2036 /* --------------------------------------------------------------------
2037 Remember ch is the main drivers channels structure, while bc is
2038 the cards channel structure.
2039 ------------------------------------------------------------------------ */
2041 /* For every port on the card do ..... */
2043 for (i = 0; i < bd->numports; i++, ch++, bc++)
2044 { /* Begin for each port */
2046 ch->brdchan = bc;
2047 ch->mailbox = gd;
2048 ch->tqueue.routine = do_softint;
2049 ch->tqueue.data = ch;
2050 ch->board = &boards[crd];
2052 switch (bd->type)
2053 { /* Begin switch bd->type */
2055 /* ----------------------------------------------------------------
2056 Since some of the boards use different bitmaps for their
2057 control signals we cannot hard code these values and retain
2058 portability. We virtualize this data here.
2059 ------------------------------------------------------------------- */
2060 case EISAXEM:
2061 case PCXEM:
2062 case PCIXEM:
2063 case PCIXRJ:
2064 case PCIXR:
2065 ch->m_rts = 0x02 ;
2066 ch->m_dcd = 0x80 ;
2067 ch->m_dsr = 0x20 ;
2068 ch->m_cts = 0x10 ;
2069 ch->m_ri = 0x40 ;
2070 ch->m_dtr = 0x01 ;
2071 break;
2073 case PCXE:
2074 case PCXEVE:
2075 case PCXI:
2076 case PC64XE:
2077 ch->m_rts = 0x02 ;
2078 ch->m_dcd = 0x08 ;
2079 ch->m_dsr = 0x10 ;
2080 ch->m_cts = 0x20 ;
2081 ch->m_ri = 0x40 ;
2082 ch->m_dtr = 0x80 ;
2083 break;
2085 } /* End switch bd->type */
2087 if (boards[crd].altpin)
2089 ch->dsr = ch->m_dcd;
2090 ch->dcd = ch->m_dsr;
2091 ch->digiext.digi_flags |= DIGI_ALTPIN;
2093 else
2095 ch->dcd = ch->m_dcd;
2096 ch->dsr = ch->m_dsr;
2099 ch->boardnum = crd;
2100 ch->channelnum = i;
2101 ch->magic = EPCA_MAGIC;
2102 ch->tty = 0;
2104 if (shrinkmem)
2106 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
2107 shrinkmem = 0;
2110 switch (bd->type)
2111 { /* Begin switch bd->type */
2113 case PCIXEM:
2114 case PCIXRJ:
2115 case PCIXR:
2116 /* Cover all the 2MEG cards */
2117 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff);
2118 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff);
2119 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2120 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2121 break;
2123 case PCXEM:
2124 case EISAXEM:
2125 /* Cover all the 32K windowed cards */
2126 /* Mask equal to window size - 1 */
2127 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff);
2128 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff);
2129 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2130 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2131 break;
2133 case PCXEVE:
2134 case PCXE:
2135 ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff);
2136 ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9);
2137 ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff);
2138 ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 );
2139 break;
2141 case PCXI:
2142 case PC64XE:
2143 ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4);
2144 ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4);
2145 ch->txwin = ch->rxwin = 0;
2146 break;
2148 } /* End switch bd->type */
2150 ch->txbufhead = 0;
2151 ch->txbufsize = bc->tmax + 1;
2153 ch->rxbufhead = 0;
2154 ch->rxbufsize = bc->rmax + 1;
2156 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
2158 /* Set transmitter low water mark */
2159 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
2161 /* Set receiver low water mark */
2163 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
2165 /* Set receiver high water mark */
2167 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
2169 bc->edelay = 100;
2170 bc->idata = 1;
2172 ch->startc = bc->startc;
2173 ch->stopc = bc->stopc;
2174 ch->startca = bc->startca;
2175 ch->stopca = bc->stopca;
2177 ch->fepcflag = 0;
2178 ch->fepiflag = 0;
2179 ch->fepoflag = 0;
2180 ch->fepstartc = 0;
2181 ch->fepstopc = 0;
2182 ch->fepstartca = 0;
2183 ch->fepstopca = 0;
2185 ch->close_delay = 50;
2186 ch->count = 0;
2187 ch->blocked_open = 0;
2188 ch->callout_termios = pc_callout.init_termios;
2189 ch->normal_termios = pc_driver.init_termios;
2190 init_waitqueue_head(&ch->open_wait);
2191 init_waitqueue_head(&ch->close_wait);
2192 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
2193 if (!(ch->tmp_buf))
2195 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
2198 memset((void *)ch->tmp_buf,0,ch->txbufsize);
2199 } /* End for each port */
2201 printk(KERN_INFO
2202 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2203 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2204 sprintf(mesg,
2205 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2206 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2207 console_print(mesg);
2209 memwinoff(bd, 0);
2211 } /* End post_fep_init */
2213 /* --------------------- Begin epcapoll ------------------------ */
2215 static void epcapoll(unsigned long ignored)
2216 { /* Begin epcapoll */
2218 unsigned long flags;
2219 int crd;
2220 volatile unsigned int head, tail;
2221 struct channel *ch;
2222 struct board_info *bd;
2224 /* -------------------------------------------------------------------
2225 This routine is called upon every timer interrupt. Even though
2226 the Digi series cards are capable of generating interupts this
2227 method of non-looping polling is more efficient. This routine
2228 checks for card generated events (Such as receive data, are transmit
2229 buffer empty) and acts on those events.
2230 ----------------------------------------------------------------------- */
2232 save_flags(flags);
2233 cli();
2235 for (crd = 0; crd < num_cards; crd++)
2236 { /* Begin for each card */
2238 bd = &boards[crd];
2239 ch = card_ptr[crd];
2241 if ((bd->status == DISABLED) || digi_poller_inhibited)
2242 continue; /* Begin loop next interation */
2244 /* -----------------------------------------------------------
2245 assertmemoff is not needed here; indeed it is an empty subroutine.
2246 It is being kept because future boards may need this as well as
2247 some legacy boards.
2248 ---------------------------------------------------------------- */
2250 assertmemoff(ch);
2252 globalwinon(ch);
2254 /* ---------------------------------------------------------------
2255 In this case head and tail actually refer to the event queue not
2256 the transmit or receive queue.
2257 ------------------------------------------------------------------- */
2259 head = ch->mailbox->ein;
2260 tail = ch->mailbox->eout;
2262 /* If head isn't equal to tail we have an event */
2264 if (head != tail)
2265 doevent(crd);
2267 memoff(ch);
2269 } /* End for each card */
2271 mod_timer(&epca_timer, jiffies + (HZ / 25));
2273 restore_flags(flags);
2274 } /* End epcapoll */
2276 /* --------------------- Begin doevent ------------------------ */
2278 static void doevent(int crd)
2279 { /* Begin doevent */
2281 volatile unchar *eventbuf;
2282 struct channel *ch, *chan0;
2283 static struct tty_struct *tty;
2284 volatile struct board_info *bd;
2285 volatile struct board_chan *bc;
2286 register volatile unsigned int tail, head;
2287 register int event, channel;
2288 register int mstat, lstat;
2290 /* -------------------------------------------------------------------
2291 This subroutine is called by epcapoll when an event is detected
2292 in the event queue. This routine responds to those events.
2293 --------------------------------------------------------------------- */
2295 bd = &boards[crd];
2297 chan0 = card_ptr[crd];
2298 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2300 assertgwinon(chan0);
2302 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2303 { /* Begin while something in event queue */
2305 assertgwinon(chan0);
2307 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2309 /* Get the channel the event occurred on */
2310 channel = eventbuf[0];
2312 /* Get the actual event code that occurred */
2313 event = eventbuf[1];
2315 /* ----------------------------------------------------------------
2316 The two assignments below get the current modem status (mstat)
2317 and the previous modem status (lstat). These are useful becuase
2318 an event could signal a change in modem signals itself.
2319 ------------------------------------------------------------------- */
2321 mstat = eventbuf[2];
2322 lstat = eventbuf[3];
2324 ch = chan0 + channel;
2326 if ((unsigned)channel >= bd->numports || !ch)
2328 if (channel >= bd->numports)
2329 ch = chan0;
2330 bc = ch->brdchan;
2331 goto next;
2334 if ((bc = ch->brdchan) == NULL)
2335 goto next;
2337 if (event & DATA_IND)
2338 { /* Begin DATA_IND */
2340 receive_data(ch);
2341 assertgwinon(ch);
2343 } /* End DATA_IND */
2344 /* else *//* Fix for DCD transition missed bug */
2345 if (event & MODEMCHG_IND)
2346 { /* Begin MODEMCHG_IND */
2348 /* A modem signal change has been indicated */
2350 ch->imodem = mstat;
2352 if (ch->asyncflags & ASYNC_CHECK_CD)
2354 if (mstat & ch->dcd) /* We are now receiving dcd */
2355 wake_up_interruptible(&ch->open_wait);
2356 else
2357 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2360 } /* End MODEMCHG_IND */
2362 tty = ch->tty;
2363 if (tty)
2364 { /* Begin if valid tty */
2366 if (event & BREAK_IND)
2367 { /* Begin if BREAK_IND */
2369 /* A break has been indicated */
2371 tty->flip.count++;
2372 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2374 *tty->flip.char_buf_ptr++ = 0;
2376 tty_schedule_flip(tty);
2378 } /* End if BREAK_IND */
2379 else
2380 if (event & LOWTX_IND)
2381 { /* Begin LOWTX_IND */
2383 if (ch->statusflags & LOWWAIT)
2384 { /* Begin if LOWWAIT */
2386 ch->statusflags &= ~LOWWAIT;
2387 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2388 tty->ldisc.write_wakeup)
2389 (tty->ldisc.write_wakeup)(tty);
2390 wake_up_interruptible(&tty->write_wait);
2392 } /* End if LOWWAIT */
2394 } /* End LOWTX_IND */
2395 else
2396 if (event & EMPTYTX_IND)
2397 { /* Begin EMPTYTX_IND */
2399 /* This event is generated by setup_empty_event */
2401 ch->statusflags &= ~TXBUSY;
2402 if (ch->statusflags & EMPTYWAIT)
2403 { /* Begin if EMPTYWAIT */
2405 ch->statusflags &= ~EMPTYWAIT;
2406 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2407 tty->ldisc.write_wakeup)
2408 (tty->ldisc.write_wakeup)(tty);
2410 wake_up_interruptible(&tty->write_wait);
2412 } /* End if EMPTYWAIT */
2414 } /* End EMPTYTX_IND */
2416 } /* End if valid tty */
2419 next:
2420 globalwinon(ch);
2422 if (!bc)
2423 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n");
2424 else
2425 bc->idata = 1;
2427 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2428 globalwinon(chan0);
2430 } /* End while something in event queue */
2432 } /* End doevent */
2434 /* --------------------- Begin fepcmd ------------------------ */
2436 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2437 int byte2, int ncmds, int bytecmd)
2438 { /* Begin fepcmd */
2440 unchar *memaddr;
2441 unsigned int head, cmdTail, cmdStart, cmdMax;
2442 long count;
2443 int n;
2445 /* This is the routine in which commands may be passed to the card. */
2447 if (ch->board->status == DISABLED)
2449 return;
2452 assertgwinon(ch);
2454 /* Remember head (As well as max) is just an offset not a base addr */
2455 head = ch->mailbox->cin;
2457 /* cmdStart is a base address */
2458 cmdStart = ch->mailbox->cstart;
2460 /* ------------------------------------------------------------------
2461 We do the addition below because we do not want a max pointer
2462 relative to cmdStart. We want a max pointer that points at the
2463 physical end of the command queue.
2464 -------------------------------------------------------------------- */
2466 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2468 memaddr = ch->board->re_map_membase;
2471 The below command is necessary because newer kernels (2.1.x and
2472 up) do not have a 1:1 virtual to physical mapping. The below
2473 call adjust for that.
2476 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2478 if (head >= (cmdMax - cmdStart) || (head & 03))
2480 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2481 cmd, head);
2482 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2483 cmdMax, cmdStart);
2484 return;
2487 if (bytecmd)
2489 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2491 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2492 /* Below word_or_byte is bits to set */
2493 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte;
2494 /* Below byte2 is bits to reset */
2495 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2;
2498 else
2500 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2501 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2502 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2505 head = (head + 4) & (cmdMax - cmdStart - 4);
2506 ch->mailbox->cin = head;
2508 count = FEPTIMEOUT;
2510 for (;;)
2511 { /* Begin forever loop */
2513 count--;
2514 if (count == 0)
2516 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2517 return;
2520 head = ch->mailbox->cin;
2521 cmdTail = ch->mailbox->cout;
2523 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2525 /* ----------------------------------------------------------
2526 Basically this will break when the FEP acknowledges the
2527 command by incrementing cmdTail (Making it equal to head).
2528 ------------------------------------------------------------- */
2530 if (n <= ncmds * (sizeof(short) * 4))
2531 break; /* Well nearly forever :-) */
2533 } /* End forever loop */
2535 } /* End fepcmd */
2537 /* ---------------------------------------------------------------------
2538 Digi products use fields in their channels structures that are very
2539 similar to the c_cflag and c_iflag fields typically found in UNIX
2540 termios structures. The below three routines allow mappings
2541 between these hardware "flags" and their respective Linux flags.
2542 ------------------------------------------------------------------------- */
2544 /* --------------------- Begin termios2digi_h -------------------- */
2546 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2547 { /* Begin termios2digi_h */
2549 unsigned res = 0;
2551 if (cflag & CRTSCTS)
2553 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2554 res |= ((ch->m_cts) | (ch->m_rts));
2557 if (ch->digiext.digi_flags & RTSPACE)
2558 res |= ch->m_rts;
2560 if (ch->digiext.digi_flags & DTRPACE)
2561 res |= ch->m_dtr;
2563 if (ch->digiext.digi_flags & CTSPACE)
2564 res |= ch->m_cts;
2566 if (ch->digiext.digi_flags & DSRPACE)
2567 res |= ch->dsr;
2569 if (ch->digiext.digi_flags & DCDPACE)
2570 res |= ch->dcd;
2572 if (res & (ch->m_rts))
2573 ch->digiext.digi_flags |= RTSPACE;
2575 if (res & (ch->m_cts))
2576 ch->digiext.digi_flags |= CTSPACE;
2578 return res;
2580 } /* End termios2digi_h */
2582 /* --------------------- Begin termios2digi_i -------------------- */
2583 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2584 { /* Begin termios2digi_i */
2586 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2587 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2589 if (ch->digiext.digi_flags & DIGI_AIXON)
2590 res |= IAIXON;
2591 return res;
2593 } /* End termios2digi_i */
2595 /* --------------------- Begin termios2digi_c -------------------- */
2597 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2598 { /* Begin termios2digi_c */
2600 unsigned res = 0;
2602 #ifdef SPEED_HACK
2603 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2604 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2605 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2606 #endif /* SPEED_HACK */
2608 if (cflag & CBAUDEX)
2609 { /* Begin detected CBAUDEX */
2611 ch->digiext.digi_flags |= DIGI_FAST;
2613 /* -------------------------------------------------------------
2614 HUPCL bit is used by FEP to indicate fast baud
2615 table is to be used.
2616 ----------------------------------------------------------------- */
2618 res |= FEP_HUPCL;
2620 } /* End detected CBAUDEX */
2621 else ch->digiext.digi_flags &= ~DIGI_FAST;
2623 /* -------------------------------------------------------------------
2624 CBAUD has bit position 0x1000 set these days to indicate Linux
2625 baud rate remap. Digi hardware can't handle the bit assignment.
2626 (We use a different bit assignment for high speed.). Clear this
2627 bit out.
2628 ---------------------------------------------------------------------- */
2629 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2631 /* -------------------------------------------------------------
2632 This gets a little confusing. The Digi cards have their own
2633 representation of c_cflags controling baud rate. For the most
2634 part this is identical to the Linux implementation. However;
2635 Digi supports one rate (76800) that Linux doesn't. This means
2636 that the c_cflag entry that would normally mean 76800 for Digi
2637 actually means 115200 under Linux. Without the below mapping,
2638 a stty 115200 would only drive the board at 76800. Since
2639 the rate 230400 is also found after 76800, the same problem afflicts
2640 us when we choose a rate of 230400. Without the below modificiation
2641 stty 230400 would actually give us 115200.
2643 There are two additional differences. The Linux value for CLOCAL
2644 (0x800; 0004000) has no meaning to the Digi hardware. Also in
2645 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
2646 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
2647 should be checked for a screened out prior to termios2digi_c
2648 returning. Since CLOCAL isn't used by the board this can be
2649 ignored as long as the returned value is used only by Digi hardware.
2650 ----------------------------------------------------------------- */
2652 if (cflag & CBAUDEX)
2654 /* -------------------------------------------------------------
2655 The below code is trying to guarantee that only baud rates
2656 115200 and 230400 are remapped. We use exclusive or because
2657 the various baud rates share common bit positions and therefore
2658 can't be tested for easily.
2659 ----------------------------------------------------------------- */
2662 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2663 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2665 res += 1;
2669 return res;
2671 } /* End termios2digi_c */
2673 /* --------------------- Begin epcaparam ----------------------- */
2675 static void epcaparam(struct tty_struct *tty, struct channel *ch)
2676 { /* Begin epcaparam */
2678 unsigned int cmdHead;
2679 struct termios *ts;
2680 volatile struct board_chan *bc;
2681 unsigned mval, hflow, cflag, iflag;
2683 bc = ch->brdchan;
2684 epcaassert(bc !=0, "bc out of range");
2686 assertgwinon(ch);
2688 ts = tty->termios;
2690 if ((ts->c_cflag & CBAUD) == 0)
2691 { /* Begin CBAUD detected */
2693 cmdHead = bc->rin;
2694 bc->rout = cmdHead;
2695 cmdHead = bc->tin;
2697 /* Changing baud in mid-stream transmission can be wonderful */
2698 /* ---------------------------------------------------------------
2699 Flush current transmit buffer by setting cmdTail pointer (tout)
2700 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2701 ----------------------------------------------------------------- */
2703 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2704 mval = 0;
2706 } /* End CBAUD detected */
2707 else
2708 { /* Begin CBAUD not detected */
2710 /* -------------------------------------------------------------------
2711 c_cflags have changed but that change had nothing to do with BAUD.
2712 Propagate the change to the card.
2713 ---------------------------------------------------------------------- */
2715 cflag = termios2digi_c(ch, ts->c_cflag);
2717 if (cflag != ch->fepcflag)
2719 ch->fepcflag = cflag;
2720 /* Set baud rate, char size, stop bits, parity */
2721 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2725 /* ----------------------------------------------------------------
2726 If the user has not forced CLOCAL and if the device is not a
2727 CALLOUT device (Which is always CLOCAL) we set flags such that
2728 the driver will wait on carrier detect.
2729 ------------------------------------------------------------------- */
2731 if ((ts->c_cflag & CLOCAL) || (tty->driver.subtype == SERIAL_TYPE_CALLOUT))
2732 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2733 ch->asyncflags &= ~ASYNC_CHECK_CD;
2734 } /* End it is a cud device or a ttyD device with CLOCAL on */
2735 else
2736 { /* Begin it is a ttyD device */
2737 ch->asyncflags |= ASYNC_CHECK_CD;
2738 } /* End it is a ttyD device */
2740 mval = ch->m_dtr | ch->m_rts;
2742 } /* End CBAUD not detected */
2744 iflag = termios2digi_i(ch, ts->c_iflag);
2746 /* Check input mode flags */
2748 if (iflag != ch->fepiflag)
2750 ch->fepiflag = iflag;
2752 /* ---------------------------------------------------------------
2753 Command sets channels iflag structure on the board. Such things
2754 as input soft flow control, handeling of parity errors, and
2755 break handeling are all set here.
2756 ------------------------------------------------------------------- */
2758 /* break handeling, parity handeling, input stripping, flow control chars */
2759 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2762 /* ---------------------------------------------------------------
2763 Set the board mint value for this channel. This will cause hardware
2764 events to be generated each time the DCD signal (Described in mint)
2765 changes.
2766 ------------------------------------------------------------------- */
2767 bc->mint = ch->dcd;
2769 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2770 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2771 bc->mint = 0;
2773 ch->imodem = bc->mstat;
2775 hflow = termios2digi_h(ch, ts->c_cflag);
2777 if (hflow != ch->hflow)
2779 ch->hflow = hflow;
2781 /* --------------------------------------------------------------
2782 Hard flow control has been selected but the board is not
2783 using it. Activate hard flow control now.
2784 ----------------------------------------------------------------- */
2786 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2790 mval ^= ch->modemfake & (mval ^ ch->modem);
2792 if (ch->omodem ^ mval)
2794 ch->omodem = mval;
2796 /* --------------------------------------------------------------
2797 The below command sets the DTR and RTS mstat structure. If
2798 hard flow control is NOT active these changes will drive the
2799 output of the actual DTR and RTS lines. If hard flow control
2800 is active, the changes will be saved in the mstat structure and
2801 only asserted when hard flow control is turned off.
2802 ----------------------------------------------------------------- */
2804 /* First reset DTR & RTS; then set them */
2805 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2806 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2810 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2812 ch->fepstartc = ch->startc;
2813 ch->fepstopc = ch->stopc;
2815 /* ------------------------------------------------------------
2816 The XON / XOFF characters have changed; propogate these
2817 changes to the card.
2818 --------------------------------------------------------------- */
2820 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2823 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2825 ch->fepstartca = ch->startca;
2826 ch->fepstopca = ch->stopca;
2828 /* ---------------------------------------------------------------
2829 Similar to the above, this time the auxilarly XON / XOFF
2830 characters have changed; propogate these changes to the card.
2831 ------------------------------------------------------------------ */
2833 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2836 } /* End epcaparam */
2838 /* --------------------- Begin receive_data ----------------------- */
2840 static void receive_data(struct channel *ch)
2841 { /* Begin receive_data */
2843 unchar *rptr;
2844 struct termios *ts = 0;
2845 struct tty_struct *tty;
2846 volatile struct board_chan *bc;
2847 register int dataToRead, wrapgap, bytesAvailable;
2848 register unsigned int tail, head;
2849 unsigned int wrapmask;
2850 int rc;
2853 /* ---------------------------------------------------------------
2854 This routine is called by doint when a receive data event
2855 has taken place.
2856 ------------------------------------------------------------------- */
2858 globalwinon(ch);
2860 if (ch->statusflags & RXSTOPPED)
2861 return;
2863 tty = ch->tty;
2864 if (tty)
2865 ts = tty->termios;
2867 bc = ch->brdchan;
2869 if (!bc)
2871 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2872 return;
2875 wrapmask = ch->rxbufsize - 1;
2877 /* ---------------------------------------------------------------------
2878 Get the head and tail pointers to the receiver queue. Wrap the
2879 head pointer if it has reached the end of the buffer.
2880 ------------------------------------------------------------------------ */
2882 head = bc->rin;
2883 head &= wrapmask;
2884 tail = bc->rout & wrapmask;
2886 bytesAvailable = (head - tail) & wrapmask;
2888 if (bytesAvailable == 0)
2889 return;
2891 /* ------------------------------------------------------------------
2892 If CREAD bit is off or device not open, set TX tail to head
2893 --------------------------------------------------------------------- */
2895 if (!tty || !ts || !(ts->c_cflag & CREAD))
2897 bc->rout = head;
2898 return;
2901 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2902 return;
2904 if (bc->orun)
2906 bc->orun = 0;
2907 printk(KERN_WARNING "overrun! DigiBoard device minor = %d\n",MINOR(tty->device));
2910 rxwinon(ch);
2911 rptr = tty->flip.char_buf_ptr;
2912 rc = tty->flip.count;
2914 while (bytesAvailable > 0)
2915 { /* Begin while there is data on the card */
2917 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2919 /* ---------------------------------------------------------------
2920 Even if head has wrapped around only report the amount of
2921 data to be equal to the size - tail. Remember memcpy can't
2922 automaticly wrap around the receive buffer.
2923 ----------------------------------------------------------------- */
2925 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2927 /* --------------------------------------------------------------
2928 Make sure we don't overflow the buffer
2929 ----------------------------------------------------------------- */
2931 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2932 dataToRead = TTY_FLIPBUF_SIZE - rc;
2934 if (dataToRead == 0)
2935 break;
2937 /* ---------------------------------------------------------------
2938 Move data read from our card into the line disciplines buffer
2939 for translation if necessary.
2940 ------------------------------------------------------------------ */
2942 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2943 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2945 rc += dataToRead;
2946 rptr += dataToRead;
2947 tail = (tail + dataToRead) & wrapmask;
2948 bytesAvailable -= dataToRead;
2950 } /* End while there is data on the card */
2953 tty->flip.count = rc;
2954 tty->flip.char_buf_ptr = rptr;
2955 globalwinon(ch);
2956 bc->rout = tail;
2958 /* Must be called with global data */
2959 tty_schedule_flip(ch->tty);
2960 return;
2962 } /* End receive_data */
2964 /* --------------------- Begin pc_ioctl ----------------------- */
2966 static int pc_ioctl(struct tty_struct *tty, struct file * file,
2967 unsigned int cmd, unsigned long arg)
2968 { /* Begin pc_ioctl */
2970 digiflow_t dflow;
2971 int retval, error;
2972 unsigned long flags;
2973 unsigned int mflag, mstat;
2974 unsigned char startc, stopc;
2975 volatile struct board_chan *bc;
2976 struct channel *ch = (struct channel *) tty->driver_data;
2978 /* The control device has it's own set of commands */
2979 if (tty->driver.subtype == SERIAL_TYPE_INFO)
2980 { /* Begin if subtype is the control device */
2982 switch (cmd)
2983 { /* Begin switch cmd */
2985 case DIGI_GETINFO:
2986 { /* Begin case DIGI_GETINFO */
2988 struct digi_info di ;
2989 int brd;
2991 getUser(brd, (unsigned int *)arg);
2993 if ((error = verify_area(VERIFY_WRITE, (char*)arg, sizeof(di))))
2995 printk(KERN_ERR "DIGI_GETINFO : verify area size 0x%x failed\n",sizeof(di));
2996 return(error);
2999 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
3000 return (-ENODEV);
3002 memset(&di, 0, sizeof(di));
3004 di.board = brd ;
3005 di.status = boards[brd].status;
3006 di.type = boards[brd].type ;
3007 di.numports = boards[brd].numports ;
3008 di.port = boards[brd].port ;
3009 di.membase = boards[brd].membase ;
3011 copy_to_user((char *)arg, &di, sizeof (di));
3012 break;
3014 } /* End case DIGI_GETINFO */
3016 case DIGI_POLLER:
3017 { /* Begin case DIGI_POLLER */
3019 int brd = arg & 0xff000000 >> 16 ;
3020 unsigned char state = arg & 0xff ;
3022 if ((brd < 0) || (brd >= num_cards))
3024 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
3025 return (-ENODEV);
3028 digi_poller_inhibited = state ;
3029 break ;
3031 } /* End case DIGI_POLLER */
3033 case DIGI_INIT:
3034 { /* Begin case DIGI_INIT */
3036 /* ------------------------------------------------------------
3037 This call is made by the apps to complete the initilization
3038 of the board(s). This routine is responsible for setting
3039 the card to its initial state and setting the drivers control
3040 fields to the sutianle settings for the card in question.
3041 ---------------------------------------------------------------- */
3043 int crd ;
3044 for (crd = 0; crd < num_cards; crd++)
3045 post_fep_init (crd);
3047 break ;
3049 } /* End case DIGI_INIT */
3052 default:
3053 return -ENOIOCTLCMD;
3055 } /* End switch cmd */
3056 return (0) ;
3058 } /* End if subtype is the control device */
3060 if (ch)
3061 bc = ch->brdchan;
3062 else
3064 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
3065 return(-EINVAL);
3068 save_flags(flags);
3070 /* -------------------------------------------------------------------
3071 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
3072 in /usr/src/linux/drivers/char for a good example. In particular
3073 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
3074 ---------------------------------------------------------------------- */
3076 switch (cmd)
3077 { /* Begin switch cmd */
3079 case TCGETS:
3080 retval = verify_area(VERIFY_WRITE, (void *)arg,
3081 sizeof(struct termios));
3083 if (retval)
3084 return(retval);
3086 copy_to_user((struct termios *)arg,
3087 tty->termios, sizeof(struct termios));
3088 return(0);
3090 case TCGETA:
3091 return get_termio(tty, (struct termio *)arg);
3093 case TCSBRK: /* SVID version: non-zero arg --> no break */
3095 retval = tty_check_change(tty);
3096 if (retval)
3097 return retval;
3099 /* Setup an event to indicate when the transmit buffer empties */
3101 setup_empty_event(tty,ch);
3102 tty_wait_until_sent(tty, 0);
3103 if (!arg)
3104 digi_send_break(ch, HZ/4); /* 1/4 second */
3105 return 0;
3107 case TCSBRKP: /* support for POSIX tcsendbreak() */
3109 retval = tty_check_change(tty);
3110 if (retval)
3111 return retval;
3113 /* Setup an event to indicate when the transmit buffer empties */
3115 setup_empty_event(tty,ch);
3116 tty_wait_until_sent(tty, 0);
3117 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
3118 return 0;
3120 case TIOCGSOFTCAR:
3122 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
3123 if (error)
3124 return error;
3126 putUser(C_CLOCAL(tty) ? 1 : 0,
3127 (unsigned long *) arg);
3128 return 0;
3130 case TIOCSSOFTCAR:
3131 /*RONNIE PUT VERIFY_READ (See above) check here */
3133 unsigned int value;
3135 getUser(value, (unsigned int *)arg);
3136 tty->termios->c_cflag =
3137 ((tty->termios->c_cflag & ~CLOCAL) |
3138 (value ? CLOCAL : 0));
3139 return 0;
3142 case TIOCMODG:
3143 case TIOCMGET:
3145 mflag = 0;
3147 cli();
3148 globalwinon(ch);
3149 mstat = bc->mstat;
3150 memoff(ch);
3151 restore_flags(flags);
3153 if (mstat & ch->m_dtr)
3154 mflag |= TIOCM_DTR;
3156 if (mstat & ch->m_rts)
3157 mflag |= TIOCM_RTS;
3159 if (mstat & ch->m_cts)
3160 mflag |= TIOCM_CTS;
3162 if (mstat & ch->dsr)
3163 mflag |= TIOCM_DSR;
3165 if (mstat & ch->m_ri)
3166 mflag |= TIOCM_RI;
3168 if (mstat & ch->dcd)
3169 mflag |= TIOCM_CD;
3171 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
3173 if (error)
3174 return error;
3176 putUser(mflag, (unsigned int *) arg);
3178 break;
3180 case TIOCMBIS:
3181 case TIOCMBIC:
3182 case TIOCMODS:
3183 case TIOCMSET:
3185 getUser(mstat, (unsigned int *)arg);
3187 mflag = 0;
3188 if (mstat & TIOCM_DTR)
3189 mflag |= ch->m_dtr;
3191 if (mstat & TIOCM_RTS)
3192 mflag |= ch->m_rts;
3194 switch (cmd)
3195 { /* Begin switch cmd */
3197 case TIOCMODS:
3198 case TIOCMSET:
3199 ch->modemfake = ch->m_dtr|ch->m_rts;
3200 ch->modem = mflag;
3201 break;
3203 case TIOCMBIS:
3204 ch->modemfake |= mflag;
3205 ch->modem |= mflag;
3206 break;
3208 case TIOCMBIC:
3209 ch->modemfake |= mflag;
3210 ch->modem &= ~mflag;
3211 break;
3213 } /* End switch cmd */
3215 cli();
3216 globalwinon(ch);
3218 /* --------------------------------------------------------------
3219 The below routine generally sets up parity, baud, flow control
3220 issues, etc.... It effect both control flags and input flags.
3221 ------------------------------------------------------------------ */
3223 epcaparam(tty,ch);
3224 memoff(ch);
3225 restore_flags(flags);
3226 break;
3228 case TIOCSDTR:
3229 ch->omodem |= ch->m_dtr;
3230 cli();
3231 globalwinon(ch);
3232 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
3233 memoff(ch);
3234 restore_flags(flags);
3235 break;
3237 case TIOCCDTR:
3238 ch->omodem &= ~ch->m_dtr;
3239 cli();
3240 globalwinon(ch);
3241 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
3242 memoff(ch);
3243 restore_flags(flags);
3244 break;
3246 case DIGI_GETA:
3247 if ((error=
3248 verify_area(VERIFY_WRITE, (char*)arg, sizeof(digi_t))))
3250 printk(KERN_ERR "<Error> - Digi GETA failed\n");
3251 return(error);
3254 copy_to_user((char*)arg, &ch->digiext, sizeof(digi_t));
3255 break;
3257 case DIGI_SETAW:
3258 case DIGI_SETAF:
3259 if ((cmd) == (DIGI_SETAW))
3261 /* Setup an event to indicate when the transmit buffer empties */
3263 setup_empty_event(tty,ch);
3264 tty_wait_until_sent(tty, 0);
3266 else
3268 if (tty->ldisc.flush_buffer)
3269 tty->ldisc.flush_buffer(tty);
3272 /* Fall Thru */
3274 case DIGI_SETA:
3275 if ((error =
3276 verify_area(VERIFY_READ, (char*)arg,sizeof(digi_t))))
3277 return(error);
3279 copy_from_user(&ch->digiext, (char*)arg, sizeof(digi_t));
3281 if (ch->digiext.digi_flags & DIGI_ALTPIN)
3283 ch->dcd = ch->m_dsr;
3284 ch->dsr = ch->m_dcd;
3286 else
3288 ch->dcd = ch->m_dcd;
3289 ch->dsr = ch->m_dsr;
3292 cli();
3293 globalwinon(ch);
3295 /* -----------------------------------------------------------------
3296 The below routine generally sets up parity, baud, flow control
3297 issues, etc.... It effect both control flags and input flags.
3298 ------------------------------------------------------------------- */
3300 epcaparam(tty,ch);
3301 memoff(ch);
3302 restore_flags(flags);
3303 break;
3305 case DIGI_GETFLOW:
3306 case DIGI_GETAFLOW:
3307 cli();
3308 globalwinon(ch);
3309 if ((cmd) == (DIGI_GETFLOW))
3311 dflow.startc = bc->startc;
3312 dflow.stopc = bc->stopc;
3314 else
3316 dflow.startc = bc->startca;
3317 dflow.stopc = bc->stopca;
3319 memoff(ch);
3320 restore_flags(flags);
3322 if ((error = verify_area(VERIFY_WRITE, (char*)arg,sizeof(dflow))))
3323 return(error);
3325 copy_to_user((char*)arg, &dflow, sizeof(dflow));
3326 break;
3328 case DIGI_SETAFLOW:
3329 case DIGI_SETFLOW:
3330 if ((cmd) == (DIGI_SETFLOW))
3332 startc = ch->startc;
3333 stopc = ch->stopc;
3335 else
3337 startc = ch->startca;
3338 stopc = ch->stopca;
3341 if ((error = verify_area(VERIFY_READ, (char*)arg,sizeof(dflow))))
3342 return(error);
3344 copy_from_user(&dflow, (char*)arg, sizeof(dflow));
3346 if (dflow.startc != startc || dflow.stopc != stopc)
3347 { /* Begin if setflow toggled */
3348 cli();
3349 globalwinon(ch);
3351 if ((cmd) == (DIGI_SETFLOW))
3353 ch->fepstartc = ch->startc = dflow.startc;
3354 ch->fepstopc = ch->stopc = dflow.stopc;
3355 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3357 else
3359 ch->fepstartca = ch->startca = dflow.startc;
3360 ch->fepstopca = ch->stopca = dflow.stopc;
3361 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3364 if (ch->statusflags & TXSTOPPED)
3365 pc_start(tty);
3367 memoff(ch);
3368 restore_flags(flags);
3370 } /* End if setflow toggled */
3371 break;
3373 default:
3374 return -ENOIOCTLCMD;
3376 } /* End switch cmd */
3378 return 0;
3380 } /* End pc_ioctl */
3382 /* --------------------- Begin pc_set_termios ----------------------- */
3384 static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3385 { /* Begin pc_set_termios */
3387 struct channel *ch;
3388 unsigned long flags;
3390 /* ---------------------------------------------------------
3391 verifyChannel returns the channel from the tty struct
3392 if it is valid. This serves as a sanity check.
3393 ------------------------------------------------------------- */
3395 if ((ch = verifyChannel(tty)) != NULL)
3396 { /* Begin if channel valid */
3398 save_flags(flags);
3399 cli();
3400 globalwinon(ch);
3401 epcaparam(tty, ch);
3402 memoff(ch);
3404 if ((old_termios->c_cflag & CRTSCTS) &&
3405 ((tty->termios->c_cflag & CRTSCTS) == 0))
3406 tty->hw_stopped = 0;
3408 if (!(old_termios->c_cflag & CLOCAL) &&
3409 (tty->termios->c_cflag & CLOCAL))
3410 wake_up_interruptible(&ch->open_wait);
3412 restore_flags(flags);
3414 } /* End if channel valid */
3416 } /* End pc_set_termios */
3418 /* --------------------- Begin do_softint ----------------------- */
3420 static void do_softint(void *private_)
3421 { /* Begin do_softint */
3423 struct channel *ch = (struct channel *) private_;
3426 /* Called in response to a modem change event */
3428 if (ch && ch->magic == EPCA_MAGIC)
3429 { /* Begin EPCA_MAGIC */
3431 struct tty_struct *tty = ch->tty;
3433 if (tty && tty->driver_data)
3435 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3436 { /* Begin if clear_bit */
3438 tty_hangup(tty);
3439 wake_up_interruptible(&ch->open_wait);
3440 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
3442 } /* End if clear_bit */
3445 } /* End EPCA_MAGIC */
3447 } /* End do_softint */
3449 /* ------------------------------------------------------------
3450 pc_stop and pc_start provide software flow control to the
3451 routine and the pc_ioctl routine.
3452 ---------------------------------------------------------------- */
3454 /* --------------------- Begin pc_stop ----------------------- */
3456 static void pc_stop(struct tty_struct *tty)
3457 { /* Begin pc_stop */
3459 struct channel *ch;
3460 unsigned long flags;
3462 /* ---------------------------------------------------------
3463 verifyChannel returns the channel from the tty struct
3464 if it is valid. This serves as a sanity check.
3465 ------------------------------------------------------------- */
3467 if ((ch = verifyChannel(tty)) != NULL)
3468 { /* Begin if valid channel */
3470 save_flags(flags);
3471 cli();
3473 if ((ch->statusflags & TXSTOPPED) == 0)
3474 { /* Begin if transmit stop requested */
3476 globalwinon(ch);
3478 /* STOP transmitting now !! */
3480 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3482 ch->statusflags |= TXSTOPPED;
3483 memoff(ch);
3485 } /* End if transmit stop requested */
3487 restore_flags(flags);
3489 } /* End if valid channel */
3491 } /* End pc_stop */
3493 /* --------------------- Begin pc_start ----------------------- */
3495 static void pc_start(struct tty_struct *tty)
3496 { /* Begin pc_start */
3498 struct channel *ch;
3500 /* ---------------------------------------------------------
3501 verifyChannel returns the channel from the tty struct
3502 if it is valid. This serves as a sanity check.
3503 ------------------------------------------------------------- */
3505 if ((ch = verifyChannel(tty)) != NULL)
3506 { /* Begin if channel valid */
3508 unsigned long flags;
3510 save_flags(flags);
3511 cli();
3513 /* Just in case output was resumed because of a change in Digi-flow */
3514 if (ch->statusflags & TXSTOPPED)
3515 { /* Begin transmit resume requested */
3517 volatile struct board_chan *bc;
3519 globalwinon(ch);
3520 bc = ch->brdchan;
3521 if (ch->statusflags & LOWWAIT)
3522 bc->ilow = 1;
3524 /* Okay, you can start transmitting again... */
3526 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3528 ch->statusflags &= ~TXSTOPPED;
3529 memoff(ch);
3531 } /* End transmit resume requested */
3533 restore_flags(flags);
3535 } /* End if channel valid */
3537 } /* End pc_start */
3539 /* ------------------------------------------------------------------
3540 The below routines pc_throttle and pc_unthrottle are used
3541 to slow (And resume) the receipt of data into the kernels
3542 receive buffers. The exact occurence of this depends on the
3543 size of the kernels receive buffer and what the 'watermarks'
3544 are set to for that buffer. See the n_ttys.c file for more
3545 details.
3546 ______________________________________________________________________ */
3547 /* --------------------- Begin throttle ----------------------- */
3549 static void pc_throttle(struct tty_struct * tty)
3550 { /* Begin pc_throttle */
3552 struct channel *ch;
3553 unsigned long flags;
3555 /* ---------------------------------------------------------
3556 verifyChannel returns the channel from the tty struct
3557 if it is valid. This serves as a sanity check.
3558 ------------------------------------------------------------- */
3560 if ((ch = verifyChannel(tty)) != NULL)
3561 { /* Begin if channel valid */
3564 save_flags(flags);
3565 cli();
3567 if ((ch->statusflags & RXSTOPPED) == 0)
3569 globalwinon(ch);
3570 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3572 ch->statusflags |= RXSTOPPED;
3573 memoff(ch);
3575 restore_flags(flags);
3577 } /* End if channel valid */
3579 } /* End pc_throttle */
3581 /* --------------------- Begin unthrottle ----------------------- */
3583 static void pc_unthrottle(struct tty_struct *tty)
3584 { /* Begin pc_unthrottle */
3586 struct channel *ch;
3587 unsigned long flags;
3588 volatile struct board_chan *bc;
3591 /* ---------------------------------------------------------
3592 verifyChannel returns the channel from the tty struct
3593 if it is valid. This serves as a sanity check.
3594 ------------------------------------------------------------- */
3596 if ((ch = verifyChannel(tty)) != NULL)
3597 { /* Begin if channel valid */
3600 /* Just in case output was resumed because of a change in Digi-flow */
3601 save_flags(flags);
3602 cli();
3604 if (ch->statusflags & RXSTOPPED)
3607 globalwinon(ch);
3608 bc = ch->brdchan;
3609 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3611 ch->statusflags &= ~RXSTOPPED;
3612 memoff(ch);
3614 restore_flags(flags);
3616 } /* End if channel valid */
3618 } /* End pc_unthrottle */
3620 /* --------------------- Begin digi_send_break ----------------------- */
3622 void digi_send_break(struct channel *ch, int msec)
3623 { /* Begin digi_send_break */
3625 unsigned long flags;
3627 save_flags(flags);
3628 cli();
3629 globalwinon(ch);
3631 /* --------------------------------------------------------------------
3632 Maybe I should send an infinite break here, schedule() for
3633 msec amount of time, and then stop the break. This way,
3634 the user can't screw up the FEP by causing digi_send_break()
3635 to be called (i.e. via an ioctl()) more than once in msec amount
3636 of time. Try this for now...
3637 ------------------------------------------------------------------------ */
3639 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3640 memoff(ch);
3642 restore_flags(flags);
3644 } /* End digi_send_break */
3646 /* --------------------- Begin setup_empty_event ----------------------- */
3648 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3649 { /* Begin setup_empty_event */
3651 volatile struct board_chan *bc = ch->brdchan;
3652 unsigned long int flags;
3654 save_flags(flags);
3655 cli();
3656 globalwinon(ch);
3657 ch->statusflags |= EMPTYWAIT;
3659 /* ------------------------------------------------------------------
3660 When set the iempty flag request a event to be generated when the
3661 transmit buffer is empty (If there is no BREAK in progress).
3662 --------------------------------------------------------------------- */
3664 bc->iempty = 1;
3665 memoff(ch);
3666 restore_flags(flags);
3668 } /* End setup_empty_event */
3670 /* --------------------- Begin get_termio ----------------------- */
3672 static int get_termio(struct tty_struct * tty, struct termio * termio)
3673 { /* Begin get_termio */
3674 int error;
3676 error = verify_area(VERIFY_WRITE, termio, sizeof (struct termio));
3677 if (error)
3678 return error;
3680 kernel_termios_to_user_termio(termio, tty->termios);
3682 return 0;
3683 } /* End get_termio */
3684 /* ---------------------- Begin epca_setup -------------------------- */
3685 void epca_setup(char *str, int *ints)
3686 { /* Begin epca_setup */
3688 struct board_info board;
3689 int index, loop, last;
3690 char *temp, *t2;
3691 unsigned len;
3693 /* ----------------------------------------------------------------------
3694 If this routine looks a little strange it is because it is only called
3695 if a LILO append command is given to boot the kernel with parameters.
3696 In this way, we can provide the user a method of changing his board
3697 configuration without rebuilding the kernel.
3698 ----------------------------------------------------------------------- */
3699 if (!liloconfig)
3700 liloconfig = 1;
3702 memset(&board, 0, sizeof(board));
3704 /* Assume the data is int first, later we can change it */
3705 /* I think that array position 0 of ints holds the number of args */
3706 for (last = 0, index = 1; index <= ints[0]; index++)
3707 switch(index)
3708 { /* Begin parse switch */
3710 case 1:
3711 board.status = ints[index];
3713 /* ---------------------------------------------------------
3714 We check for 2 (As opposed to 1; because 2 is a flag
3715 instructing the driver to ignore epcaconfig.) For this
3716 reason we check for 2.
3717 ------------------------------------------------------------ */
3718 if (board.status == 2)
3719 { /* Begin ignore epcaconfig as well as lilo cmd line */
3720 nbdevs = 0;
3721 num_cards = 0;
3722 return;
3723 } /* End ignore epcaconfig as well as lilo cmd line */
3725 if (board.status > 2)
3727 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3728 invalid_lilo_config = 1;
3729 setup_error_code |= INVALID_BOARD_STATUS;
3730 return;
3732 last = index;
3733 break;
3735 case 2:
3736 board.type = ints[index];
3737 if (board.type >= PCIXEM)
3739 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3740 invalid_lilo_config = 1;
3741 setup_error_code |= INVALID_BOARD_TYPE;
3742 return;
3744 last = index;
3745 break;
3747 case 3:
3748 board.altpin = ints[index];
3749 if (board.altpin > 1)
3751 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3752 invalid_lilo_config = 1;
3753 setup_error_code |= INVALID_ALTPIN;
3754 return;
3756 last = index;
3757 break;
3759 case 4:
3760 board.numports = ints[index];
3761 if ((board.numports < 2) || (board.numports > 256))
3763 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3764 invalid_lilo_config = 1;
3765 setup_error_code |= INVALID_NUM_PORTS;
3766 return;
3768 nbdevs += board.numports;
3769 last = index;
3770 break;
3772 case 5:
3773 board.port = (unsigned char *)ints[index];
3774 if (board.port <= 0)
3776 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3777 invalid_lilo_config = 1;
3778 setup_error_code |= INVALID_PORT_BASE;
3779 return;
3781 last = index;
3782 break;
3784 case 6:
3785 board.membase = (unsigned char *)ints[index];
3786 if (board.membase <= 0)
3788 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3789 invalid_lilo_config = 1;
3790 setup_error_code |= INVALID_MEM_BASE;
3791 return;
3793 last = index;
3794 break;
3796 default:
3797 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
3798 return;
3800 } /* End parse switch */
3802 while (str && *str)
3803 { /* Begin while there is a string arg */
3805 /* find the next comma or terminator */
3806 temp = str;
3808 /* While string is not null, and a comma hasn't been found */
3809 while (*temp && (*temp != ','))
3810 temp++;
3812 if (!*temp)
3813 temp = NULL;
3814 else
3815 *temp++ = 0;
3817 /* Set index to the number of args + 1 */
3818 index = last + 1;
3820 switch(index)
3822 case 1:
3823 len = strlen(str);
3824 if (strncmp("Disable", str, len) == 0)
3825 board.status = 0;
3826 else
3827 if (strncmp("Enable", str, len) == 0)
3828 board.status = 1;
3829 else
3831 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3832 invalid_lilo_config = 1;
3833 setup_error_code |= INVALID_BOARD_STATUS;
3834 return;
3836 last = index;
3837 break;
3839 case 2:
3841 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3842 if (strcmp(board_desc[loop], str) == 0)
3843 break;
3846 /* ---------------------------------------------------------------
3847 If the index incremented above refers to a legitamate board
3848 type set it here.
3849 ------------------------------------------------------------------*/
3851 if (index < EPCA_NUM_TYPES)
3852 board.type = loop;
3853 else
3855 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3856 invalid_lilo_config = 1;
3857 setup_error_code |= INVALID_BOARD_TYPE;
3858 return;
3860 last = index;
3861 break;
3863 case 3:
3864 len = strlen(str);
3865 if (strncmp("Disable", str, len) == 0)
3866 board.altpin = 0;
3867 else
3868 if (strncmp("Enable", str, len) == 0)
3869 board.altpin = 1;
3870 else
3872 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3873 invalid_lilo_config = 1;
3874 setup_error_code |= INVALID_ALTPIN;
3875 return;
3877 last = index;
3878 break;
3880 case 4:
3881 t2 = str;
3882 while (isdigit(*t2))
3883 t2++;
3885 if (*t2)
3887 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3888 invalid_lilo_config = 1;
3889 setup_error_code |= INVALID_NUM_PORTS;
3890 return;
3893 /* ------------------------------------------------------------
3894 There is not a man page for simple_strtoul but the code can be
3895 found in vsprintf.c. The first argument is the string to
3896 translate (To an unsigned long obviously), the second argument
3897 can be the address of any character variable or a NULL. If a
3898 variable is given, the end pointer of the string will be stored
3899 in that variable; if a NULL is given the end pointer will
3900 not be returned. The last argument is the base to use. If
3901 a 0 is indicated, the routine will attempt to determine the
3902 proper base by looking at the values prefix (A '0' for octal,
3903 a 'x' for hex, etc ... If a value is given it will use that
3904 value as the base.
3905 ---------------------------------------------------------------- */
3906 board.numports = simple_strtoul(str, NULL, 0);
3907 nbdevs += board.numports;
3908 last = index;
3909 break;
3911 case 5:
3912 t2 = str;
3913 while (isxdigit(*t2))
3914 t2++;
3916 if (*t2)
3918 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3919 invalid_lilo_config = 1;
3920 setup_error_code |= INVALID_PORT_BASE;
3921 return;
3924 board.port = (unsigned char *)simple_strtoul(str, NULL, 16);
3925 last = index;
3926 break;
3928 case 6:
3929 t2 = str;
3930 while (isxdigit(*t2))
3931 t2++;
3933 if (*t2)
3935 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3936 invalid_lilo_config = 1;
3937 setup_error_code |= INVALID_MEM_BASE;
3938 return;
3941 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3942 last = index;
3943 break;
3945 default:
3946 printk(KERN_ERR "PC/Xx: Too many string parms\n");
3947 return;
3949 str = temp;
3951 } /* End while there is a string arg */
3954 if (last < 6)
3956 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3957 return;
3960 /* I should REALLY validate the stuff here */
3962 /* Copies our local copy of board into boards */
3963 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3966 /* Does this get called once per lilo arg are what ? */
3968 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3969 num_cards, board_desc[board.type],
3970 board.numports, (int)board.port, (unsigned int) board.membase);
3972 num_cards++;
3974 } /* End epca_setup */
3978 #ifdef ENABLE_PCI
3979 /* ------------------------ Begin init_PCI --------------------------- */
3981 enum epic_board_types {
3982 brd_xr = 0,
3983 brd_xem,
3984 brd_cx,
3985 brd_xrj,
3989 /* indexed directly by epic_board_types enum */
3990 static struct {
3991 unsigned char board_type;
3992 unsigned bar_idx; /* PCI base address region */
3993 } epca_info_tbl[] = {
3994 { PCIXR, 0, },
3995 { PCIXEM, 0, },
3996 { PCICX, 0, },
3997 { PCIXRJ, 2, },
4001 static int __init epca_init_one (struct pci_dev *pdev,
4002 const struct pci_device_id *ent)
4004 static int board_num = -1;
4005 int board_idx, info_idx = ent->driver_data;
4006 unsigned long addr;
4008 if (pci_enable_device(pdev))
4009 return -EIO;
4011 board_num++;
4012 board_idx = board_num + num_cards;
4013 if (board_idx >= MAXBOARDS)
4014 goto err_out;
4016 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
4017 if (!addr) {
4018 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
4019 epca_info_tbl[info_idx].bar_idx);
4020 goto err_out;
4023 boards[board_idx].status = ENABLED;
4024 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
4025 boards[board_idx].numports = 0x0;
4026 boards[board_idx].port =
4027 (unsigned char *)((char *) addr + PCI_IO_OFFSET);
4028 boards[board_idx].membase =
4029 (unsigned char *)((char *) addr);
4031 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
4032 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
4033 0x200000, addr + PCI_IO_OFFSET);
4034 goto err_out;
4037 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
4038 if (!boards[board_idx].re_map_port) {
4039 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
4040 0x200000, addr + PCI_IO_OFFSET);
4041 goto err_out_free_pciio;
4044 if (!request_mem_region (addr, 0x200000, "epca")) {
4045 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
4046 0x200000, addr);
4047 goto err_out_free_iounmap;
4050 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
4051 if (!boards[board_idx].re_map_membase) {
4052 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
4053 0x200000, addr + PCI_IO_OFFSET);
4054 goto err_out_free_memregion;
4057 /* --------------------------------------------------------------
4058 I don't know what the below does, but the hardware guys say
4059 its required on everything except PLX (In this case XRJ).
4060 ---------------------------------------------------------------- */
4061 if (info_idx != brd_xrj) {
4062 pci_write_config_byte(pdev, 0x40, 0);
4063 pci_write_config_byte(pdev, 0x46, 0);
4066 return 0;
4068 err_out_free_memregion:
4069 release_mem_region (addr, 0x200000);
4070 err_out_free_iounmap:
4071 iounmap (boards[board_idx].re_map_port);
4072 err_out_free_pciio:
4073 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
4074 err_out:
4075 return -ENODEV;
4079 static struct pci_device_id epca_pci_tbl[] __initdata = {
4080 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
4081 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
4082 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
4083 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
4084 { 0, }
4087 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
4089 int __init init_PCI (void)
4090 { /* Begin init_PCI */
4092 int pci_count;
4094 memset (&epca_driver, 0, sizeof (epca_driver));
4095 epca_driver.name = "epca";
4096 epca_driver.id_table = epca_pci_tbl;
4097 epca_driver.probe = epca_init_one;
4099 pci_count = pci_register_driver (&epca_driver);
4101 if (pci_count <= 0) {
4102 pci_unregister_driver (&epca_driver);
4103 pci_count = 0;
4106 return(pci_count);
4108 } /* End init_PCI */
4110 #endif /* ENABLE_PCI */