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 <linux/interrupt.h>
44 #include <asm/uaccess.h>
49 #endif /* CONFIG_PCI */
51 #define putUser(arg1, arg2) put_user(arg1, (unsigned long *)arg2)
52 #define getUser(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
55 #include <linux/pci.h>
57 #endif /* ENABLE_PCI */
62 #include "epcaconfig.h"
64 #if BITS_PER_LONG != 32
65 # error FIXME: this driver only works on 32-bit platforms
68 /* ---------------------- Begin defines ------------------------ */
70 #define VERSION "1.3.0.1-LK"
72 /* This major needs to be submitted to Linux to join the majors list */
74 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
77 #define MIN(a,b) ((a) < (b) ? (a) : (b))
79 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
83 /* ----------------- Begin global definitions ------------------- */
85 static char mesg[100];
86 static int nbdevs, num_cards, liloconfig;
87 static int digi_poller_inhibited = 1 ;
89 static int setup_error_code;
90 static int invalid_lilo_config;
92 /* -----------------------------------------------------------------------
93 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
95 --------------------------------------------------------------------------*/
96 static struct board_info boards[MAXBOARDS];
99 /* ------------- Begin structures used for driver registeration ---------- */
101 static struct tty_driver *pc_driver;
102 static struct tty_driver *pc_info;
104 /* ------------------ Begin Digi specific structures -------------------- */
106 /* ------------------------------------------------------------------------
107 digi_channels represents an array of structures that keep track of
108 each channel of the Digi product. Information such as transmit and
109 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
110 are stored here. This structure is NOT used to overlay the cards
111 physical channel structure.
112 -------------------------------------------------------------------------- */
114 static struct channel digi_channels[MAX_ALLOC];
116 /* ------------------------------------------------------------------------
117 card_ptr is an array used to hold the address of the
118 first channel structure of each card. This array will hold
119 the addresses of various channels located in digi_channels.
120 -------------------------------------------------------------------------- */
121 static struct channel *card_ptr[MAXCARDS];
123 static struct timer_list epca_timer;
125 /* ---------------------- Begin function prototypes --------------------- */
127 /* ----------------------------------------------------------------------
128 Begin generic memory functions. These functions will be alias
129 (point at) more specific functions dependent on the board being
131 ----------------------------------------------------------------------- */
133 static inline void memwinon(struct board_info *b, unsigned int win);
134 static inline void memwinoff(struct board_info *b, unsigned int win);
135 static inline void globalwinon(struct channel *ch);
136 static inline void rxwinon(struct channel *ch);
137 static inline void txwinon(struct channel *ch);
138 static inline void memoff(struct channel *ch);
139 static inline void assertgwinon(struct channel *ch);
140 static inline void assertmemoff(struct channel *ch);
142 /* ---- Begin more 'specific' memory functions for cx_like products --- */
144 static inline void pcxem_memwinon(struct board_info *b, unsigned int win);
145 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win);
146 static inline void pcxem_globalwinon(struct channel *ch);
147 static inline void pcxem_rxwinon(struct channel *ch);
148 static inline void pcxem_txwinon(struct channel *ch);
149 static inline void pcxem_memoff(struct channel *ch);
151 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
153 static inline void pcxe_memwinon(struct board_info *b, unsigned int win);
154 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win);
155 static inline void pcxe_globalwinon(struct channel *ch);
156 static inline void pcxe_rxwinon(struct channel *ch);
157 static inline void pcxe_txwinon(struct channel *ch);
158 static inline void pcxe_memoff(struct channel *ch);
160 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
161 /* Note : pc64xe and pcxi share the same windowing routines */
163 static inline void pcxi_memwinon(struct board_info *b, unsigned int win);
164 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win);
165 static inline void pcxi_globalwinon(struct channel *ch);
166 static inline void pcxi_rxwinon(struct channel *ch);
167 static inline void pcxi_txwinon(struct channel *ch);
168 static inline void pcxi_memoff(struct channel *ch);
170 /* - Begin 'specific' do nothing memory functions needed for some cards - */
172 static inline void dummy_memwinon(struct board_info *b, unsigned int win);
173 static inline void dummy_memwinoff(struct board_info *b, unsigned int win);
174 static inline void dummy_globalwinon(struct channel *ch);
175 static inline void dummy_rxwinon(struct channel *ch);
176 static inline void dummy_txwinon(struct channel *ch);
177 static inline void dummy_memoff(struct channel *ch);
178 static inline void dummy_assertgwinon(struct channel *ch);
179 static inline void dummy_assertmemoff(struct channel *ch);
181 /* ------------------- Begin declare functions ----------------------- */
183 static inline struct channel *verifyChannel(register struct tty_struct *);
184 static inline void pc_sched_event(struct channel *, int);
185 static void epca_error(int, char *);
186 static void pc_close(struct tty_struct *, struct file *);
187 static void shutdown(struct channel *);
188 static void pc_hangup(struct tty_struct *);
189 static void pc_put_char(struct tty_struct *, unsigned char);
190 static int pc_write_room(struct tty_struct *);
191 static int pc_chars_in_buffer(struct tty_struct *);
192 static void pc_flush_buffer(struct tty_struct *);
193 static void pc_flush_chars(struct tty_struct *);
194 static int block_til_ready(struct tty_struct *, struct file *,
196 static int pc_open(struct tty_struct *, struct file *);
197 static void post_fep_init(unsigned int crd);
198 static void epcapoll(unsigned long);
199 static void doevent(int);
200 static void fepcmd(struct channel *, int, int, int, int, int);
201 static unsigned termios2digi_h(struct channel *ch, unsigned);
202 static unsigned termios2digi_i(struct channel *ch, unsigned);
203 static unsigned termios2digi_c(struct channel *ch, unsigned);
204 static void epcaparam(struct tty_struct *, struct channel *);
205 static void receive_data(struct channel *);
206 static int pc_ioctl(struct tty_struct *, struct file *,
207 unsigned int, unsigned long);
208 static int info_ioctl(struct tty_struct *, struct file *,
209 unsigned int, unsigned long);
210 static void pc_set_termios(struct tty_struct *, struct termios *);
211 static void do_softint(void *);
212 static void pc_stop(struct tty_struct *);
213 static void pc_start(struct tty_struct *);
214 static void pc_throttle(struct tty_struct * tty);
215 static void pc_unthrottle(struct tty_struct *tty);
216 static void digi_send_break(struct channel *ch, int msec);
217 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
218 void epca_setup(char *, int *);
219 void console_print(const char *);
221 static int get_termio(struct tty_struct *, struct termio *);
222 static int pc_write(struct tty_struct *, int, const unsigned char *, int);
226 static int init_PCI(void);
227 #endif /* ENABLE_PCI */
230 /* ------------------------------------------------------------------
231 Table of functions for each board to handle memory. Mantaining
232 parallelism is a *very* good idea here. The idea is for the
233 runtime code to blindly call these functions, not knowing/caring
234 about the underlying hardware. This stuff should contain no
235 conditionals; if more functionality is needed a different entry
236 should be established. These calls are the interface calls and
237 are the only functions that should be accessed. Anyone caught
238 making direct calls deserves what they get.
239 -------------------------------------------------------------------- */
241 static inline void memwinon(struct board_info *b, unsigned int win)
243 (b->memwinon)(b, win);
246 static inline void memwinoff(struct board_info *b, unsigned int win)
248 (b->memwinoff)(b, win);
251 static inline void globalwinon(struct channel *ch)
253 (ch->board->globalwinon)(ch);
256 static inline void rxwinon(struct channel *ch)
258 (ch->board->rxwinon)(ch);
261 static inline void txwinon(struct channel *ch)
263 (ch->board->txwinon)(ch);
266 static inline void memoff(struct channel *ch)
268 (ch->board->memoff)(ch);
270 static inline void assertgwinon(struct channel *ch)
272 (ch->board->assertgwinon)(ch);
275 static inline void assertmemoff(struct channel *ch)
277 (ch->board->assertmemoff)(ch);
280 /* ---------------------------------------------------------
281 PCXEM windowing is the same as that used in the PCXR
283 ------------------------------------------------------------ */
285 static inline void pcxem_memwinon(struct board_info *b, unsigned int win)
287 outb_p(FEPWIN|win, (int)b->port + 1);
290 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win)
292 outb_p(0, (int)b->port + 1);
295 static inline void pcxem_globalwinon(struct channel *ch)
297 outb_p( FEPWIN, (int)ch->board->port + 1);
300 static inline void pcxem_rxwinon(struct channel *ch)
302 outb_p(ch->rxwin, (int)ch->board->port + 1);
305 static inline void pcxem_txwinon(struct channel *ch)
307 outb_p(ch->txwin, (int)ch->board->port + 1);
310 static inline void pcxem_memoff(struct channel *ch)
312 outb_p(0, (int)ch->board->port + 1);
315 /* ----------------- Begin pcxe memory window stuff ------------------ */
317 static inline void pcxe_memwinon(struct board_info *b, unsigned int win)
319 outb_p(FEPWIN | win, (int)b->port + 1);
322 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win)
324 outb_p(inb((int)b->port) & ~FEPMEM,
326 outb_p(0, (int)b->port + 1);
329 static inline void pcxe_globalwinon(struct channel *ch)
331 outb_p( FEPWIN, (int)ch->board->port + 1);
334 static inline void pcxe_rxwinon(struct channel *ch)
336 outb_p(ch->rxwin, (int)ch->board->port + 1);
339 static inline void pcxe_txwinon(struct channel *ch)
341 outb_p(ch->txwin, (int)ch->board->port + 1);
344 static inline void pcxe_memoff(struct channel *ch)
346 outb_p(0, (int)ch->board->port);
347 outb_p(0, (int)ch->board->port + 1);
350 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
352 static inline void pcxi_memwinon(struct board_info *b, unsigned int win)
354 outb_p(inb((int)b->port) | FEPMEM, (int)b->port);
357 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win)
359 outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port);
362 static inline void pcxi_globalwinon(struct channel *ch)
364 outb_p(FEPMEM, (int)ch->board->port);
367 static inline void pcxi_rxwinon(struct channel *ch)
369 outb_p(FEPMEM, (int)ch->board->port);
372 static inline void pcxi_txwinon(struct channel *ch)
374 outb_p(FEPMEM, (int)ch->board->port);
377 static inline void pcxi_memoff(struct channel *ch)
379 outb_p(0, (int)ch->board->port);
382 static inline void pcxi_assertgwinon(struct channel *ch)
384 epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off");
387 static inline void pcxi_assertmemoff(struct channel *ch)
389 epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on");
393 /* ----------------------------------------------------------------------
394 Not all of the cards need specific memory windowing routines. Some
395 cards (Such as PCI) needs no windowing routines at all. We provide
396 these do nothing routines so that the same code base can be used.
397 The driver will ALWAYS call a windowing routine if it thinks it needs
398 to; regardless of the card. However, dependent on the card the routine
399 may or may not do anything.
400 ---------------------------------------------------------------------------*/
402 static inline void dummy_memwinon(struct board_info *b, unsigned int win)
406 static inline void dummy_memwinoff(struct board_info *b, unsigned int win)
410 static inline void dummy_globalwinon(struct channel *ch)
414 static inline void dummy_rxwinon(struct channel *ch)
418 static inline void dummy_txwinon(struct channel *ch)
422 static inline void dummy_memoff(struct channel *ch)
426 static inline void dummy_assertgwinon(struct channel *ch)
430 static inline void dummy_assertmemoff(struct channel *ch)
434 /* ----------------- Begin verifyChannel function ----------------------- */
435 static inline struct channel *verifyChannel(register struct tty_struct *tty)
436 { /* Begin verifyChannel */
438 /* --------------------------------------------------------------------
439 This routine basically provides a sanity check. It insures that
440 the channel returned is within the proper range of addresses as
441 well as properly initialized. If some bogus info gets passed in
442 through tty->driver_data this should catch it.
443 --------------------------------------------------------------------- */
448 register struct channel *ch = (struct channel *)tty->driver_data;
450 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs]))
452 if (ch->magic == EPCA_MAGIC)
458 /* Else return a NULL for invalid */
461 } /* End verifyChannel */
463 /* ------------------ Begin pc_sched_event ------------------------- */
465 static inline void pc_sched_event(struct channel *ch, int event)
466 { /* Begin pc_sched_event */
469 /* ----------------------------------------------------------------------
470 We call this to schedule interrupt processing on some event. The
471 kernel sees our request and calls the related routine in OUR driver.
472 -------------------------------------------------------------------------*/
474 ch->event |= 1 << event;
475 schedule_work(&ch->tqueue);
478 } /* End pc_sched_event */
480 /* ------------------ Begin epca_error ------------------------- */
482 static void epca_error(int line, char *msg)
483 { /* Begin epca_error */
485 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
488 } /* End epca_error */
490 /* ------------------ Begin pc_close ------------------------- */
491 static void pc_close(struct tty_struct * tty, struct file * filp)
492 { /* Begin pc_close */
497 /* ---------------------------------------------------------
498 verifyChannel returns the channel from the tty struct
499 if it is valid. This serves as a sanity check.
500 ------------------------------------------------------------- */
502 if ((ch = verifyChannel(tty)) != NULL)
503 { /* Begin if ch != NULL */
508 if (tty_hung_up_p(filp))
510 restore_flags(flags);
514 /* Check to see if the channel is open more than once */
516 { /* Begin channel is open more than once */
518 /* -------------------------------------------------------------
519 Return without doing anything. Someone might still be using
521 ---------------------------------------------------------------- */
523 restore_flags(flags);
525 } /* End channel is open more than once */
527 /* Port open only once go ahead with shutdown & reset */
534 /* ---------------------------------------------------------------
535 Let the rest of the driver know the channel is being closed.
536 This becomes important if an open is attempted before close
538 ------------------------------------------------------------------ */
540 ch->asyncflags |= ASYNC_CLOSING;
544 if (ch->asyncflags & ASYNC_INITIALIZED)
546 /* Setup an event to indicate when the transmit buffer empties */
547 setup_empty_event(tty, ch);
548 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
551 if (tty->driver->flush_buffer)
552 tty->driver->flush_buffer(tty);
554 if (tty->ldisc.flush_buffer)
555 tty->ldisc.flush_buffer(tty);
562 if (ch->blocked_open)
563 { /* Begin if blocked_open */
567 current->state = TASK_INTERRUPTIBLE;
568 schedule_timeout(ch->close_delay);
571 wake_up_interruptible(&ch->open_wait);
573 } /* End if blocked_open */
575 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
577 wake_up_interruptible(&ch->close_wait);
580 restore_flags(flags);
582 } /* End if ch != NULL */
586 /* ------------------ Begin shutdown ------------------------- */
588 static void shutdown(struct channel *ch)
589 { /* Begin shutdown */
592 struct tty_struct *tty;
593 volatile struct board_chan *bc;
595 if (!(ch->asyncflags & ASYNC_INITIALIZED))
604 /* ------------------------------------------------------------------
605 In order for an event to be generated on the receipt of data the
606 idata flag must be set. Since we are shutting down, this is not
607 necessary clear this flag.
608 --------------------------------------------------------------------- */
615 /* ----------------------------------------------------------------
616 If we're a modem control device and HUPCL is on, drop RTS & DTR.
617 ------------------------------------------------------------------ */
619 if (tty->termios->c_cflag & HUPCL)
621 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
622 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
627 /* ------------------------------------------------------------------
628 The channel has officialy been closed. The next time it is opened
629 it will have to reinitialized. Set a flag to indicate this.
630 ---------------------------------------------------------------------- */
632 /* Prevent future Digi programmed interrupts from coming active */
634 ch->asyncflags &= ~ASYNC_INITIALIZED;
635 restore_flags(flags);
639 /* ------------------ Begin pc_hangup ------------------------- */
641 static void pc_hangup(struct tty_struct *tty)
642 { /* Begin pc_hangup */
646 /* ---------------------------------------------------------
647 verifyChannel returns the channel from the tty struct
648 if it is valid. This serves as a sanity check.
649 ------------------------------------------------------------- */
651 if ((ch = verifyChannel(tty)) != NULL)
652 { /* Begin if ch != NULL */
658 if (tty->driver->flush_buffer)
659 tty->driver->flush_buffer(tty);
661 if (tty->ldisc.flush_buffer)
662 tty->ldisc.flush_buffer(tty);
669 restore_flags(flags);
670 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
671 wake_up_interruptible(&ch->open_wait);
673 } /* End if ch != NULL */
675 } /* End pc_hangup */
677 /* ------------------ Begin pc_write ------------------------- */
679 static int pc_write(struct tty_struct * tty, int from_user,
680 const unsigned char *buf, int bytesAvailable)
681 { /* Begin pc_write */
683 register unsigned int head, tail;
684 register int dataLen;
686 register int amountCopied;
692 volatile struct board_chan *bc;
695 /* ----------------------------------------------------------------
696 pc_write is primarily called directly by the kernel routine
697 tty_write (Though it can also be called by put_char) found in
698 tty_io.c. pc_write is passed a line discipline buffer where
699 the data to be written out is stored. The line discipline
700 implementation itself is done at the kernel level and is not
701 brought into the driver.
702 ------------------------------------------------------------------- */
704 /* ---------------------------------------------------------
705 verifyChannel returns the channel from the tty struct
706 if it is valid. This serves as a sanity check.
707 ------------------------------------------------------------- */
709 if ((ch = verifyChannel(tty)) == NULL)
712 /* Make a pointer to the channel data structure found on the board. */
715 size = ch->txbufsize;
718 { /* Begin from_user */
725 /* -----------------------------------------------------------------
726 Anding against size will wrap the pointer back to its beginning
727 position if it is necessary. This will only work if size is
728 a power of 2 which should always be the case. Size is determined
729 by the cards on board FEP/OS.
730 -------------------------------------------------------------------- */
732 /* head refers to the next empty location in which data may be stored */
734 head = bc->tin & (size - 1);
736 /* tail refers to the next data byte to be transmitted */
740 /* Consider changing this to a do statement to make sure */
742 if (tail != bc->tout)
745 /* ------------------------------------------------------------------
746 Anding against size will wrap the pointer back to its beginning
747 position if it is necessary. This will only work if size is
748 a power of 2 which should always be the case. Size is determined
749 by the cards on board FEP/OS.
750 --------------------------------------------------------------------- */
754 /* -----------------------------------------------------------------
755 Two situations can affect how space in the transmit buffer
756 is calculated. You can have a situation where the transmit
757 in pointer (tin) head has wrapped around and actually has a
758 lower address than the transmit out pointer (tout) tail; or
759 the transmit in pointer (tin) head will not be wrapped around
760 yet, and have a higher address than the transmit out pointer
761 (tout) tail. Obviously space available in the transmit buffer
762 is calculated differently for each case.
766 Consider a 10 byte buffer where head is a pointer to the next
767 empty location in the buffer and tail is a pointer to the next
768 byte to transmit. In this example head will not have wrapped
769 around and therefore head > tail.
774 The above diagram shows that buffer locations 2,3,4,5 and 6 have
775 data to be transmitted, while head points at the next empty
776 location. To calculate how much space is available first we have
777 to determine if the head pointer (tin) has wrapped. To do this
778 compare the head pointer to the tail pointer, If head is equal
779 or greater than tail; then it has not wrapped; and the space may
780 be calculated by subtracting tail from head and then subtracting
781 that value from the buffers size. A one is subtracted from the
782 new value to indicate how much space is available between the
783 head pointer and end of buffer; as well as the space between the
784 beginning of the buffer and the tail. If the head is not greater
785 or equal to the tail this indicates that the head has wrapped
786 around to the beginning of the buffer. To calculate the space
787 available in this case simply subtract head from tail. This new
788 value minus one represents the space available betwwen the head
789 and tail pointers. In this example head (7) is greater than tail (2)
790 and therefore has not wrapped around. We find the space by first
791 subtracting tail from head (7-2=5). We then subtract this value
792 from the buffer size of ten and subtract one (10-5-1=4). The space
793 remaining is 4 bytes.
797 Consider a 10 byte buffer where head is a pointer to the next
798 empty location in the buffer and tail is a pointer to the next
799 byte to transmit. In this example head will wrapped around and
800 therefore head < tail.
805 The above diagram shows that buffer locations 7,8,9,0 and 1 have
806 data to be transmitted, while head points at the next empty
807 location. To find the space available we compare head to tail. If
808 head is not equal to, or greater than tail this indicates that head
809 has wrapped around. In this case head (2) is not equal to, or
810 greater than tail (7) and therefore has already wrapped around. To
811 calculate the available space between the two pointers we subtract
812 head from tail (7-2=5). We then subtract one from this new value
813 (5-1=4). We have 5 bytes empty remaining in the buffer. Unlike the
814 previous example these five bytes are located between the head and
817 ----------------------------------------------------------------------- */
819 dataLen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1);
821 /* ----------------------------------------------------------------------
822 In this case bytesAvailable has been passed into pc_write and
823 represents the amount of data that needs to be written. dataLen
824 represents the amount of space available on the card. Whichever
825 value is smaller will be the amount actually written.
826 bytesAvailable will then take on this newly calculated value.
827 ---------------------------------------------------------------------- */
829 bytesAvailable = MIN(dataLen, bytesAvailable);
831 /* First we read the data in from the file system into a temp buffer */
834 restore_flags(flags);
837 { /* Begin bytesAvailable */
839 /* Can the user buffer be accessed at the moment ? */
840 if (verify_area(VERIFY_READ, (char*)buf, bytesAvailable))
841 bytesAvailable = 0; /* Can't do; try again later */
842 else /* Evidently it can, began transmission */
843 { /* Begin if area verified */
844 /* ---------------------------------------------------------------
845 The below function reads data from user memory. This routine
846 can not be used in an interrupt routine. (Because it may
847 generate a page fault) It can only be called while we can the
848 user context is accessible.
851 inline void copy_from_user(void * to, const void * from,
852 unsigned long count);
854 I also think (Check hackers guide) that optimization must
855 be turned ON. (Which sounds strange to me...)
857 Remember copy_from_user WILL generate a page fault if the
858 user memory being accessed has been swapped out. This can
859 cause this routine to temporarily sleep while this page
862 ----------------------------------------------------------------- */
864 if (copy_from_user(ch->tmp_buf, buf,
868 } /* End if area verified */
870 } /* End bytesAvailable */
872 /* ------------------------------------------------------------------
873 Set buf to this address for the moment. tmp_buf was allocated in
875 --------------------------------------------------------------------- */
878 } /* End from_user */
880 /* All data is now local */
888 head = bc->tin & (size - 1);
891 if (tail != bc->tout)
895 /* If head >= tail, head has not wrapped around. */
897 { /* Begin head has not wrapped */
899 /* ---------------------------------------------------------------
900 remain (much like dataLen above) represents the total amount of
901 space available on the card for data. Here dataLen represents
902 the space existing between the head pointer and the end of
903 buffer. This is important because a memcpy cannot be told to
904 automatically wrap around when it hits the buffer end.
905 ------------------------------------------------------------------ */
907 dataLen = size - head;
908 remain = size - (head - tail) - 1;
910 } /* End head has not wrapped */
912 { /* Begin head has wrapped around */
914 remain = tail - head - 1;
917 } /* End head has wrapped around */
919 /* -------------------------------------------------------------------
920 Check the space on the card. If we have more data than
921 space; reduce the amount of data to fit the space.
922 ---------------------------------------------------------------------- */
924 bytesAvailable = MIN(remain, bytesAvailable);
927 while (bytesAvailable > 0)
928 { /* Begin while there is data to copy onto card */
930 /* -----------------------------------------------------------------
931 If head is not wrapped, the below will make sure the first
932 data copy fills to the end of card buffer.
933 ------------------------------------------------------------------- */
935 dataLen = MIN(bytesAvailable, dataLen);
936 memcpy(ch->txptr + head, buf, dataLen);
939 amountCopied += dataLen;
940 bytesAvailable -= dataLen;
948 } /* End while there is data to copy onto card */
950 ch->statusflags |= TXBUSY;
954 if ((ch->statusflags & LOWWAIT) == 0)
956 ch->statusflags |= LOWWAIT;
960 restore_flags(flags);
962 return(amountCopied);
966 /* ------------------ Begin pc_put_char ------------------------- */
968 static void pc_put_char(struct tty_struct *tty, unsigned char c)
969 { /* Begin pc_put_char */
972 pc_write(tty, 0, &c, 1);
975 } /* End pc_put_char */
977 /* ------------------ Begin pc_write_room ------------------------- */
979 static int pc_write_room(struct tty_struct *tty)
980 { /* Begin pc_write_room */
985 unsigned int head, tail;
986 volatile struct board_chan *bc;
990 /* ---------------------------------------------------------
991 verifyChannel returns the channel from the tty struct
992 if it is valid. This serves as a sanity check.
993 ------------------------------------------------------------- */
995 if ((ch = verifyChannel(tty)) != NULL)
1002 head = bc->tin & (ch->txbufsize - 1);
1005 if (tail != bc->tout)
1007 /* Wrap tail if necessary */
1008 tail &= (ch->txbufsize - 1);
1010 if ((remain = tail - head - 1) < 0 )
1011 remain += ch->txbufsize;
1013 if (remain && (ch->statusflags & LOWWAIT) == 0)
1015 ch->statusflags |= LOWWAIT;
1019 restore_flags(flags);
1022 /* Return how much room is left on card */
1025 } /* End pc_write_room */
1027 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
1029 static int pc_chars_in_buffer(struct tty_struct *tty)
1030 { /* Begin pc_chars_in_buffer */
1033 unsigned int ctail, head, tail;
1035 unsigned long flags;
1037 volatile struct board_chan *bc;
1040 /* ---------------------------------------------------------
1041 verifyChannel returns the channel from the tty struct
1042 if it is valid. This serves as a sanity check.
1043 ------------------------------------------------------------- */
1045 if ((ch = verifyChannel(tty)) == NULL)
1055 ctail = ch->mailbox->cout;
1057 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
1060 { /* Begin if some space on the card has been used */
1062 head = bc->tin & (ch->txbufsize - 1);
1063 tail &= (ch->txbufsize - 1);
1065 /* --------------------------------------------------------------
1066 The logic here is basically opposite of the above pc_write_room
1067 here we are finding the amount of bytes in the buffer filled.
1068 Not the amount of bytes empty.
1069 ------------------------------------------------------------------- */
1071 if ((remain = tail - head - 1) < 0 )
1072 remain += ch->txbufsize;
1074 chars = (int)(ch->txbufsize - remain);
1076 /* -------------------------------------------------------------
1077 Make it possible to wakeup anything waiting for output
1078 in tty_ioctl.c, etc.
1080 If not already set. Setup an event to indicate when the
1081 transmit buffer empties
1082 ----------------------------------------------------------------- */
1084 if (!(ch->statusflags & EMPTYWAIT))
1085 setup_empty_event(tty,ch);
1087 } /* End if some space on the card has been used */
1090 restore_flags(flags);
1092 /* Return number of characters residing on card. */
1095 } /* End pc_chars_in_buffer */
1097 /* ------------------ Begin pc_flush_buffer ---------------------- */
1099 static void pc_flush_buffer(struct tty_struct *tty)
1100 { /* Begin pc_flush_buffer */
1103 unsigned long flags;
1105 volatile struct board_chan *bc;
1108 /* ---------------------------------------------------------
1109 verifyChannel returns the channel from the tty struct
1110 if it is valid. This serves as a sanity check.
1111 ------------------------------------------------------------- */
1113 if ((ch = verifyChannel(tty)) == NULL)
1124 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1126 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1129 restore_flags(flags);
1131 wake_up_interruptible(&tty->write_wait);
1132 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1133 (tty->ldisc.write_wakeup)(tty);
1135 } /* End pc_flush_buffer */
1137 /* ------------------ Begin pc_flush_chars ---------------------- */
1139 static void pc_flush_chars(struct tty_struct *tty)
1140 { /* Begin pc_flush_chars */
1142 struct channel * ch;
1144 /* ---------------------------------------------------------
1145 verifyChannel returns the channel from the tty struct
1146 if it is valid. This serves as a sanity check.
1147 ------------------------------------------------------------- */
1149 if ((ch = verifyChannel(tty)) != NULL)
1151 unsigned long flags;
1156 /* ----------------------------------------------------------------
1157 If not already set and the transmitter is busy setup an event
1158 to indicate when the transmit empties.
1159 ------------------------------------------------------------------- */
1161 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
1162 setup_empty_event(tty,ch);
1164 restore_flags(flags);
1167 } /* End pc_flush_chars */
1169 /* ------------------ Begin block_til_ready ---------------------- */
1171 static int block_til_ready(struct tty_struct *tty,
1172 struct file *filp, struct channel *ch)
1173 { /* Begin block_til_ready */
1175 DECLARE_WAITQUEUE(wait,current);
1176 int retval, do_clocal = 0;
1177 unsigned long flags;
1180 if (tty_hung_up_p(filp))
1182 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1185 retval = -ERESTARTSYS;
1189 /* -----------------------------------------------------------------
1190 If the device is in the middle of being closed, then block
1191 until it's done, and then try again.
1192 -------------------------------------------------------------------- */
1193 if (ch->asyncflags & ASYNC_CLOSING)
1195 interruptible_sleep_on(&ch->close_wait);
1197 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1200 return -ERESTARTSYS;
1203 if (filp->f_flags & O_NONBLOCK)
1205 /* -----------------------------------------------------------------
1206 If non-blocking mode is set, then make the check up front
1208 -------------------------------------------------------------------- */
1210 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1216 if (tty->termios->c_cflag & CLOCAL)
1219 /* Block waiting for the carrier detect and the line to become free */
1222 add_wait_queue(&ch->open_wait, &wait);
1227 /* We dec count so that pc_close will know when to free things */
1228 if (!tty_hung_up_p(filp))
1231 restore_flags(flags);
1236 { /* Begin forever while */
1238 set_current_state(TASK_INTERRUPTIBLE);
1240 if (tty_hung_up_p(filp) ||
1241 !(ch->asyncflags & ASYNC_INITIALIZED))
1243 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1246 retval = -ERESTARTSYS;
1250 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1251 (do_clocal || (ch->imodem & ch->dcd)))
1254 if (signal_pending(current))
1256 retval = -ERESTARTSYS;
1260 /* ---------------------------------------------------------------
1261 Allow someone else to be scheduled. We will occasionally go
1262 through this loop until one of the above conditions change.
1263 The below schedule call will allow other processes to enter and
1264 prevent this loop from hogging the cpu.
1265 ------------------------------------------------------------------ */
1268 } /* End forever while */
1270 current->state = TASK_RUNNING;
1271 remove_wait_queue(&ch->open_wait, &wait);
1273 if (!tty_hung_up_p(filp))
1275 restore_flags(flags);
1282 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1286 } /* End block_til_ready */
1288 /* ------------------ Begin pc_open ---------------------- */
1290 static int pc_open(struct tty_struct *tty, struct file * filp)
1291 { /* Begin pc_open */
1294 unsigned long flags;
1295 int line, retval, boardnum;
1296 volatile struct board_chan *bc;
1297 volatile unsigned int head;
1300 if (line < 0 || line >= nbdevs)
1302 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1303 tty->driver_data = NULL;
1308 ch = &digi_channels[line];
1309 boardnum = ch->boardnum;
1311 /* Check status of board configured in system. */
1313 /* -----------------------------------------------------------------
1314 I check to see if the epca_setup routine detected an user error.
1315 It might be better to put this in pc_init, but for the moment it
1317 ---------------------------------------------------------------------- */
1319 if (invalid_lilo_config)
1321 if (setup_error_code & INVALID_BOARD_TYPE)
1322 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n");
1324 if (setup_error_code & INVALID_NUM_PORTS)
1325 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1327 if (setup_error_code & INVALID_MEM_BASE)
1328 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1330 if (setup_error_code & INVALID_PORT_BASE)
1331 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n");
1333 if (setup_error_code & INVALID_BOARD_STATUS)
1334 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n");
1336 if (setup_error_code & INVALID_ALTPIN)
1337 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1339 tty->driver_data = NULL; /* Mark this device as 'down' */
1343 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1345 tty->driver_data = NULL; /* Mark this device as 'down' */
1349 if (( bc = ch->brdchan) == 0)
1351 tty->driver_data = NULL;
1355 /* ------------------------------------------------------------------
1356 Every time a channel is opened, increment a counter. This is
1357 necessary because we do not wish to flush and shutdown the channel
1358 until the last app holding the channel open, closes it.
1359 --------------------------------------------------------------------- */
1363 /* ----------------------------------------------------------------
1364 Set a kernel structures pointer to our local channel
1365 structure. This way we can get to it when passed only
1367 ------------------------------------------------------------------ */
1369 tty->driver_data = ch;
1371 /* ----------------------------------------------------------------
1372 If this is the first time the channel has been opened, initialize
1373 the tty->termios struct otherwise let pc_close handle it.
1374 -------------------------------------------------------------------- */
1380 ch->statusflags = 0;
1382 /* Save boards current modem status */
1383 ch->imodem = bc->mstat;
1385 /* ----------------------------------------------------------------
1386 Set receive head and tail ptrs to each other. This indicates
1387 no data available to read.
1388 ----------------------------------------------------------------- */
1392 /* Set the channels associated tty structure */
1395 /* -----------------------------------------------------------------
1396 The below routine generally sets up parity, baud, flow control
1397 issues, etc.... It effect both control flags and input flags.
1398 -------------------------------------------------------------------- */
1401 ch->asyncflags |= ASYNC_INITIALIZED;
1404 restore_flags(flags);
1406 retval = block_til_ready(tty, filp, ch);
1412 /* -------------------------------------------------------------
1413 Set this again in case a hangup set it to zero while this
1414 open() was waiting for the line...
1415 --------------------------------------------------------------- */
1422 /* Enable Digi Data events */
1426 restore_flags(flags);
1433 static int __init epca_module_init(void)
1434 { /* Begin init_module */
1436 unsigned long flags;
1443 restore_flags(flags);
1448 module_init(epca_module_init);
1452 static struct pci_driver epca_driver;
1456 /* -------------------- Begin cleanup_module ---------------------- */
1458 static void __exit epca_module_exit(void)
1462 struct board_info *bd;
1464 unsigned long flags;
1466 del_timer_sync(&epca_timer);
1471 if ((tty_unregister_driver(pc_driver)) ||
1472 (tty_unregister_driver(pc_info)))
1474 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1475 restore_flags(flags);
1478 put_tty_driver(pc_driver);
1479 put_tty_driver(pc_info);
1481 for (crd = 0; crd < num_cards; crd++)
1482 { /* Begin for each card */
1487 { /* Begin sanity check */
1488 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1490 } /* End sanity check */
1494 for (count = 0; count < bd->numports; count++, ch++)
1495 { /* Begin for each port */
1500 tty_hangup(ch->tty);
1504 } /* End for each port */
1505 } /* End for each card */
1508 pci_unregister_driver (&epca_driver);
1511 restore_flags(flags);
1514 module_exit(epca_module_exit);
1517 static struct tty_operations pc_ops = {
1521 .write_room = pc_write_room,
1522 .flush_buffer = pc_flush_buffer,
1523 .chars_in_buffer = pc_chars_in_buffer,
1524 .flush_chars = pc_flush_chars,
1525 .put_char = pc_put_char,
1527 .set_termios = pc_set_termios,
1530 .throttle = pc_throttle,
1531 .unthrottle = pc_unthrottle,
1532 .hangup = pc_hangup,
1535 static int info_open(struct tty_struct *tty, struct file * filp)
1540 static struct tty_operations info_ops = {
1542 .ioctl = info_ioctl,
1545 /* ------------------ Begin pc_init ---------------------- */
1547 int __init pc_init(void)
1548 { /* Begin pc_init */
1550 /* ----------------------------------------------------------------
1551 pc_init is called by the operating system during boot up prior to
1552 any open calls being made. In the older versions of Linux (Prior
1553 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1554 memory location (from kernel space) used (kmem_start) is passed
1555 to pc_init. It is pc_inits responsibility to modify this value
1556 for any memory that the Digi driver might need and then return
1557 this value to the operating system. For example if the driver
1558 wishes to allocate 1K of kernel memory, pc_init would return
1559 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1560 + 1024) would then be available for use exclusively by the driver.
1561 In this case our driver does not allocate any of this kernel
1563 ------------------------------------------------------------------*/
1567 struct board_info *bd;
1568 unsigned char board_id = 0;
1571 int pci_boards_found, pci_count;
1574 #endif /* ENABLE_PCI */
1576 pc_driver = alloc_tty_driver(MAX_ALLOC);
1580 pc_info = alloc_tty_driver(MAX_ALLOC);
1582 put_tty_driver(pc_driver);
1586 /* -----------------------------------------------------------------------
1587 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1588 board structure defined by digiConfig into drivers board structure.
1589 Note : If LILO has ran epca_setup then epca_setup will handle defining
1590 num_cards as well as copying the data into the board structure.
1591 -------------------------------------------------------------------------- */
1593 { /* Begin driver has been configured via. epcaconfig */
1596 num_cards = NUMCARDS;
1597 memcpy((void *)&boards, (void *)&static_boards,
1598 (sizeof(struct board_info) * NUMCARDS));
1599 } /* End driver has been configured via. epcaconfig */
1601 /* -----------------------------------------------------------------
1602 Note : If lilo was used to configure the driver and the
1603 ignore epcaconfig option was choosen (digiepca=2) then
1604 nbdevs and num_cards will equal 0 at this point. This is
1605 okay; PCI cards will still be picked up if detected.
1606 --------------------------------------------------------------------- */
1608 /* -----------------------------------------------------------
1609 Set up interrupt, we will worry about memory allocation in
1611 --------------------------------------------------------------- */
1614 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1618 /* ------------------------------------------------------------------
1619 NOTE : This code assumes that the number of ports found in
1620 the boards array is correct. This could be wrong if
1621 the card in question is PCI (And therefore has no ports
1622 entry in the boards structure.) The rest of the
1623 information will be valid for PCI because the beginning
1624 of pc_init scans for PCI and determines i/o and base
1625 memory addresses. I am not sure if it is possible to
1626 read the number of ports supported by the card prior to
1627 it being booted (Since that is the state it is in when
1628 pc_init is run). Because it is not possible to query the
1629 number of supported ports until after the card has booted;
1630 we are required to calculate the card_ptrs as the card is
1631 is initialized (Inside post_fep_init). The negative thing
1632 about this approach is that digiDload's call to GET_INFO
1633 will have a bad port value. (Since this is called prior
1636 --------------------------------------------------------------------- */
1638 pci_boards_found = 0;
1639 if(num_cards < MAXBOARDS)
1640 pci_boards_found += init_PCI();
1641 num_cards += pci_boards_found;
1643 #endif /* ENABLE_PCI */
1645 pc_driver->owner = THIS_MODULE;
1646 pc_driver->name = "ttyD";
1647 pc_driver->devfs_name = "tts/D";
1648 pc_driver->major = DIGI_MAJOR;
1649 pc_driver->minor_start = 0;
1650 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1651 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1652 pc_driver->init_termios = tty_std_termios;
1653 pc_driver->init_termios.c_iflag = 0;
1654 pc_driver->init_termios.c_oflag = 0;
1655 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1656 pc_driver->init_termios.c_lflag = 0;
1657 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1658 tty_set_operations(pc_driver, &pc_ops);
1660 pc_info->owner = THIS_MODULE;
1661 pc_info->name = "digi_ctl";
1662 pc_info->major = DIGIINFOMAJOR;
1663 pc_info->minor_start = 0;
1664 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1665 pc_info->subtype = SERIAL_TYPE_INFO;
1666 pc_info->init_termios = tty_std_termios;
1667 pc_info->init_termios.c_iflag = 0;
1668 pc_info->init_termios.c_oflag = 0;
1669 pc_info->init_termios.c_lflag = 0;
1670 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1671 pc_info->flags = TTY_DRIVER_REAL_RAW;
1672 tty_set_operations(pc_info, &info_ops);
1678 for (crd = 0; crd < num_cards; crd++)
1679 { /* Begin for each card */
1681 /* ------------------------------------------------------------------
1682 This is where the appropriate memory handlers for the hardware is
1683 set. Everything at runtime blindly jumps through these vectors.
1684 ---------------------------------------------------------------------- */
1686 /* defined in epcaconfig.h */
1690 { /* Begin switch on bd->type {board type} */
1693 bd->memwinon = pcxem_memwinon ;
1694 bd->memwinoff = pcxem_memwinoff ;
1695 bd->globalwinon = pcxem_globalwinon ;
1696 bd->txwinon = pcxem_txwinon ;
1697 bd->rxwinon = pcxem_rxwinon ;
1698 bd->memoff = pcxem_memoff ;
1699 bd->assertgwinon = dummy_assertgwinon;
1700 bd->assertmemoff = dummy_assertmemoff;
1706 bd->memwinon = dummy_memwinon;
1707 bd->memwinoff = dummy_memwinoff;
1708 bd->globalwinon = dummy_globalwinon;
1709 bd->txwinon = dummy_txwinon;
1710 bd->rxwinon = dummy_rxwinon;
1711 bd->memoff = dummy_memoff;
1712 bd->assertgwinon = dummy_assertgwinon;
1713 bd->assertmemoff = dummy_assertmemoff;
1719 bd->memwinon = pcxe_memwinon;
1720 bd->memwinoff = pcxe_memwinoff;
1721 bd->globalwinon = pcxe_globalwinon;
1722 bd->txwinon = pcxe_txwinon;
1723 bd->rxwinon = pcxe_rxwinon;
1724 bd->memoff = pcxe_memoff;
1725 bd->assertgwinon = dummy_assertgwinon;
1726 bd->assertmemoff = dummy_assertmemoff;
1732 bd->memwinon = pcxi_memwinon;
1733 bd->memwinoff = pcxi_memwinoff;
1734 bd->globalwinon = pcxi_globalwinon;
1735 bd->txwinon = pcxi_txwinon;
1736 bd->rxwinon = pcxi_rxwinon;
1737 bd->memoff = pcxi_memoff;
1738 bd->assertgwinon = pcxi_assertgwinon;
1739 bd->assertmemoff = pcxi_assertmemoff;
1745 } /* End switch on bd->type */
1747 /* ---------------------------------------------------------------
1748 Some cards need a memory segment to be defined for use in
1749 transmit and receive windowing operations. These boards
1750 are listed in the below switch. In the case of the XI the
1751 amount of memory on the board is variable so the memory_seg
1752 is also variable. This code determines what they segment
1754 ----------------------------------------------------------------- */
1757 { /* Begin switch on bd->type {board type} */
1762 bd->memory_seg = 0xf000;
1766 board_id = inb((int)bd->port);
1767 if ((board_id & 0x1) == 0x1)
1768 { /* Begin it's an XI card */
1770 /* Is it a 64K board */
1771 if ((board_id & 0x30) == 0)
1772 bd->memory_seg = 0xf000;
1774 /* Is it a 128K board */
1775 if ((board_id & 0x30) == 0x10)
1776 bd->memory_seg = 0xe000;
1778 /* Is is a 256K board */
1779 if ((board_id & 0x30) == 0x20)
1780 bd->memory_seg = 0xc000;
1782 /* Is it a 512K board */
1783 if ((board_id & 0x30) == 0x30)
1784 bd->memory_seg = 0x8000;
1786 } /* End it is an XI card */
1789 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1793 } /* End switch on bd->type */
1795 } /* End for each card */
1797 if (tty_register_driver(pc_driver))
1798 panic("Couldn't register Digi PC/ driver");
1800 if (tty_register_driver(pc_info))
1801 panic("Couldn't register Digi PC/ info ");
1803 /* -------------------------------------------------------------------
1804 Start up the poller to check for events on all enabled boards
1805 ---------------------------------------------------------------------- */
1807 init_timer(&epca_timer);
1808 epca_timer.function = epcapoll;
1809 mod_timer(&epca_timer, jiffies + HZ/25);
1811 restore_flags(flags);
1817 /* ------------------ Begin post_fep_init ---------------------- */
1819 static void post_fep_init(unsigned int crd)
1820 { /* Begin post_fep_init */
1824 volatile struct global_data *gd;
1825 struct board_info *bd;
1826 volatile struct board_chan *bc;
1828 int shrinkmem = 0, lowwater ;
1830 /* -------------------------------------------------------------
1831 This call is made by the user via. the ioctl call DIGI_INIT.
1832 It is responsible for setting up all the card specific stuff.
1833 ---------------------------------------------------------------- */
1836 /* -----------------------------------------------------------------
1837 If this is a PCI board, get the port info. Remember PCI cards
1838 do not have entries into the epcaconfig.h file, so we can't get
1839 the number of ports from it. Unfortunetly, this means that anyone
1840 doing a DIGI_GETINFO before the board has booted will get an invalid
1841 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1842 after DIGI_INIT has been called will return the proper values.
1843 ------------------------------------------------------------------- */
1845 if (bd->type >= PCIXEM) /* If the board in question is PCI */
1846 { /* Begin get PCI number of ports */
1848 /* --------------------------------------------------------------------
1849 Below we use XEMPORTS as a memory offset regardless of which PCI
1850 card it is. This is because all of the supported PCI cards have
1851 the same memory offset for the channel data. This will have to be
1852 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1853 states that the port offset is 0xC22 as opposed to 0xC02. This is
1854 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1855 On the PCI cards the number of ports is determined by reading a
1856 ID PROM located in the box attached to the card. The card can then
1857 determine the index the id to determine the number of ports available.
1858 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1859 if the box in question is a XEM or CX)).
1860 ------------------------------------------------------------------------ */
1862 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1863 (bd->re_map_membase + XEMPORTS));
1866 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1867 nbdevs += (bd->numports);
1869 } /* End get PCI number of ports */
1872 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1874 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1879 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1881 memaddr = (unchar *)bd->re_map_membase;
1884 The below command is necessary because newer kernels (2.1.x and
1885 up) do not have a 1:1 virtual to physical mapping. The below
1886 call adjust for that.
1889 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
1891 /* -----------------------------------------------------------------
1892 The below assignment will set bc to point at the BEGINING of
1893 the cards channel structures. For 1 card there will be between
1894 8 and 64 of these structures.
1895 -------------------------------------------------------------------- */
1897 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
1899 /* -------------------------------------------------------------------
1900 The below assignment will set gd to point at the BEGINING of
1901 global memory address 0xc00. The first data in that global
1902 memory actually starts at address 0xc1a. The command in
1903 pointer begins at 0xd10.
1904 ---------------------------------------------------------------------- */
1906 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
1908 /* --------------------------------------------------------------------
1909 XEPORTS (address 0xc22) points at the number of channels the
1910 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1911 ----------------------------------------------------------------------- */
1913 if (((bd->type == PCXEVE) | (bd->type == PCXE)) &&
1914 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
1916 if (bd->type < PCIXEM)
1917 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1922 /* --------------------------------------------------------------------
1923 Remember ch is the main drivers channels structure, while bc is
1924 the cards channel structure.
1925 ------------------------------------------------------------------------ */
1927 /* For every port on the card do ..... */
1929 for (i = 0; i < bd->numports; i++, ch++, bc++)
1930 { /* Begin for each port */
1934 INIT_WORK(&ch->tqueue, do_softint, ch);
1935 ch->board = &boards[crd];
1938 { /* Begin switch bd->type */
1940 /* ----------------------------------------------------------------
1941 Since some of the boards use different bitmaps for their
1942 control signals we cannot hard code these values and retain
1943 portability. We virtualize this data here.
1944 ------------------------------------------------------------------- */
1970 } /* End switch bd->type */
1972 if (boards[crd].altpin)
1974 ch->dsr = ch->m_dcd;
1975 ch->dcd = ch->m_dsr;
1976 ch->digiext.digi_flags |= DIGI_ALTPIN;
1980 ch->dcd = ch->m_dcd;
1981 ch->dsr = ch->m_dsr;
1986 ch->magic = EPCA_MAGIC;
1991 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1996 { /* Begin switch bd->type */
2001 /* Cover all the 2MEG cards */
2002 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff);
2003 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff);
2004 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2005 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2010 /* Cover all the 32K windowed cards */
2011 /* Mask equal to window size - 1 */
2012 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff);
2013 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff);
2014 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2015 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2020 ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff);
2021 ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9);
2022 ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff);
2023 ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 );
2028 ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4);
2029 ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4);
2030 ch->txwin = ch->rxwin = 0;
2033 } /* End switch bd->type */
2036 ch->txbufsize = bc->tmax + 1;
2039 ch->rxbufsize = bc->rmax + 1;
2041 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
2043 /* Set transmitter low water mark */
2044 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
2046 /* Set receiver low water mark */
2048 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
2050 /* Set receiver high water mark */
2052 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
2057 ch->startc = bc->startc;
2058 ch->stopc = bc->stopc;
2059 ch->startca = bc->startca;
2060 ch->stopca = bc->stopca;
2070 ch->close_delay = 50;
2072 ch->blocked_open = 0;
2073 init_waitqueue_head(&ch->open_wait);
2074 init_waitqueue_head(&ch->close_wait);
2075 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
2078 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
2079 release_region((int)bd->port, 4);
2081 kfree((ch--)->tmp_buf);
2085 memset((void *)ch->tmp_buf,0,ch->txbufsize);
2086 } /* End for each port */
2089 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2090 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2092 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2093 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2094 console_print(mesg);
2098 } /* End post_fep_init */
2100 /* --------------------- Begin epcapoll ------------------------ */
2102 static void epcapoll(unsigned long ignored)
2103 { /* Begin epcapoll */
2105 unsigned long flags;
2107 volatile unsigned int head, tail;
2109 struct board_info *bd;
2111 /* -------------------------------------------------------------------
2112 This routine is called upon every timer interrupt. Even though
2113 the Digi series cards are capable of generating interrupts this
2114 method of non-looping polling is more efficient. This routine
2115 checks for card generated events (Such as receive data, are transmit
2116 buffer empty) and acts on those events.
2117 ----------------------------------------------------------------------- */
2122 for (crd = 0; crd < num_cards; crd++)
2123 { /* Begin for each card */
2128 if ((bd->status == DISABLED) || digi_poller_inhibited)
2129 continue; /* Begin loop next interation */
2131 /* -----------------------------------------------------------
2132 assertmemoff is not needed here; indeed it is an empty subroutine.
2133 It is being kept because future boards may need this as well as
2135 ---------------------------------------------------------------- */
2141 /* ---------------------------------------------------------------
2142 In this case head and tail actually refer to the event queue not
2143 the transmit or receive queue.
2144 ------------------------------------------------------------------- */
2146 head = ch->mailbox->ein;
2147 tail = ch->mailbox->eout;
2149 /* If head isn't equal to tail we have an event */
2156 } /* End for each card */
2158 mod_timer(&epca_timer, jiffies + (HZ / 25));
2160 restore_flags(flags);
2161 } /* End epcapoll */
2163 /* --------------------- Begin doevent ------------------------ */
2165 static void doevent(int crd)
2166 { /* Begin doevent */
2168 volatile unchar *eventbuf;
2169 struct channel *ch, *chan0;
2170 static struct tty_struct *tty;
2171 volatile struct board_info *bd;
2172 volatile struct board_chan *bc;
2173 register volatile unsigned int tail, head;
2174 register int event, channel;
2175 register int mstat, lstat;
2177 /* -------------------------------------------------------------------
2178 This subroutine is called by epcapoll when an event is detected
2179 in the event queue. This routine responds to those events.
2180 --------------------------------------------------------------------- */
2184 chan0 = card_ptr[crd];
2185 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2187 assertgwinon(chan0);
2189 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2190 { /* Begin while something in event queue */
2192 assertgwinon(chan0);
2194 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2196 /* Get the channel the event occurred on */
2197 channel = eventbuf[0];
2199 /* Get the actual event code that occurred */
2200 event = eventbuf[1];
2202 /* ----------------------------------------------------------------
2203 The two assignments below get the current modem status (mstat)
2204 and the previous modem status (lstat). These are useful becuase
2205 an event could signal a change in modem signals itself.
2206 ------------------------------------------------------------------- */
2208 mstat = eventbuf[2];
2209 lstat = eventbuf[3];
2211 ch = chan0 + channel;
2213 if ((unsigned)channel >= bd->numports || !ch)
2215 if (channel >= bd->numports)
2221 if ((bc = ch->brdchan) == NULL)
2224 if (event & DATA_IND)
2225 { /* Begin DATA_IND */
2230 } /* End DATA_IND */
2231 /* else *//* Fix for DCD transition missed bug */
2232 if (event & MODEMCHG_IND)
2233 { /* Begin MODEMCHG_IND */
2235 /* A modem signal change has been indicated */
2239 if (ch->asyncflags & ASYNC_CHECK_CD)
2241 if (mstat & ch->dcd) /* We are now receiving dcd */
2242 wake_up_interruptible(&ch->open_wait);
2244 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2247 } /* End MODEMCHG_IND */
2251 { /* Begin if valid tty */
2253 if (event & BREAK_IND)
2254 { /* Begin if BREAK_IND */
2256 /* A break has been indicated */
2259 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2261 *tty->flip.char_buf_ptr++ = 0;
2263 tty_schedule_flip(tty);
2265 } /* End if BREAK_IND */
2267 if (event & LOWTX_IND)
2268 { /* Begin LOWTX_IND */
2270 if (ch->statusflags & LOWWAIT)
2271 { /* Begin if LOWWAIT */
2273 ch->statusflags &= ~LOWWAIT;
2274 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2275 tty->ldisc.write_wakeup)
2276 (tty->ldisc.write_wakeup)(tty);
2277 wake_up_interruptible(&tty->write_wait);
2279 } /* End if LOWWAIT */
2281 } /* End LOWTX_IND */
2283 if (event & EMPTYTX_IND)
2284 { /* Begin EMPTYTX_IND */
2286 /* This event is generated by setup_empty_event */
2288 ch->statusflags &= ~TXBUSY;
2289 if (ch->statusflags & EMPTYWAIT)
2290 { /* Begin if EMPTYWAIT */
2292 ch->statusflags &= ~EMPTYWAIT;
2293 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2294 tty->ldisc.write_wakeup)
2295 (tty->ldisc.write_wakeup)(tty);
2297 wake_up_interruptible(&tty->write_wait);
2299 } /* End if EMPTYWAIT */
2301 } /* End EMPTYTX_IND */
2303 } /* End if valid tty */
2310 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n");
2314 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2317 } /* End while something in event queue */
2321 /* --------------------- Begin fepcmd ------------------------ */
2323 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2324 int byte2, int ncmds, int bytecmd)
2325 { /* Begin fepcmd */
2328 unsigned int head, cmdTail, cmdStart, cmdMax;
2332 /* This is the routine in which commands may be passed to the card. */
2334 if (ch->board->status == DISABLED)
2341 /* Remember head (As well as max) is just an offset not a base addr */
2342 head = ch->mailbox->cin;
2344 /* cmdStart is a base address */
2345 cmdStart = ch->mailbox->cstart;
2347 /* ------------------------------------------------------------------
2348 We do the addition below because we do not want a max pointer
2349 relative to cmdStart. We want a max pointer that points at the
2350 physical end of the command queue.
2351 -------------------------------------------------------------------- */
2353 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2355 memaddr = ch->board->re_map_membase;
2358 The below command is necessary because newer kernels (2.1.x and
2359 up) do not have a 1:1 virtual to physical mapping. The below
2360 call adjust for that.
2363 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2365 if (head >= (cmdMax - cmdStart) || (head & 03))
2367 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2369 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2376 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2378 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2379 /* Below word_or_byte is bits to set */
2380 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte;
2381 /* Below byte2 is bits to reset */
2382 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2;
2387 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2388 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2389 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2392 head = (head + 4) & (cmdMax - cmdStart - 4);
2393 ch->mailbox->cin = head;
2398 { /* Begin forever loop */
2403 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2407 head = ch->mailbox->cin;
2408 cmdTail = ch->mailbox->cout;
2410 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2412 /* ----------------------------------------------------------
2413 Basically this will break when the FEP acknowledges the
2414 command by incrementing cmdTail (Making it equal to head).
2415 ------------------------------------------------------------- */
2417 if (n <= ncmds * (sizeof(short) * 4))
2418 break; /* Well nearly forever :-) */
2420 } /* End forever loop */
2424 /* ---------------------------------------------------------------------
2425 Digi products use fields in their channels structures that are very
2426 similar to the c_cflag and c_iflag fields typically found in UNIX
2427 termios structures. The below three routines allow mappings
2428 between these hardware "flags" and their respective Linux flags.
2429 ------------------------------------------------------------------------- */
2431 /* --------------------- Begin termios2digi_h -------------------- */
2433 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2434 { /* Begin termios2digi_h */
2438 if (cflag & CRTSCTS)
2440 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2441 res |= ((ch->m_cts) | (ch->m_rts));
2444 if (ch->digiext.digi_flags & RTSPACE)
2447 if (ch->digiext.digi_flags & DTRPACE)
2450 if (ch->digiext.digi_flags & CTSPACE)
2453 if (ch->digiext.digi_flags & DSRPACE)
2456 if (ch->digiext.digi_flags & DCDPACE)
2459 if (res & (ch->m_rts))
2460 ch->digiext.digi_flags |= RTSPACE;
2462 if (res & (ch->m_cts))
2463 ch->digiext.digi_flags |= CTSPACE;
2467 } /* End termios2digi_h */
2469 /* --------------------- Begin termios2digi_i -------------------- */
2470 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2471 { /* Begin termios2digi_i */
2473 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2474 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2476 if (ch->digiext.digi_flags & DIGI_AIXON)
2480 } /* End termios2digi_i */
2482 /* --------------------- Begin termios2digi_c -------------------- */
2484 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2485 { /* Begin termios2digi_c */
2490 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2491 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2492 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2493 #endif /* SPEED_HACK */
2495 if (cflag & CBAUDEX)
2496 { /* Begin detected CBAUDEX */
2498 ch->digiext.digi_flags |= DIGI_FAST;
2500 /* -------------------------------------------------------------
2501 HUPCL bit is used by FEP to indicate fast baud
2502 table is to be used.
2503 ----------------------------------------------------------------- */
2507 } /* End detected CBAUDEX */
2508 else ch->digiext.digi_flags &= ~DIGI_FAST;
2510 /* -------------------------------------------------------------------
2511 CBAUD has bit position 0x1000 set these days to indicate Linux
2512 baud rate remap. Digi hardware can't handle the bit assignment.
2513 (We use a different bit assignment for high speed.). Clear this
2515 ---------------------------------------------------------------------- */
2516 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2518 /* -------------------------------------------------------------
2519 This gets a little confusing. The Digi cards have their own
2520 representation of c_cflags controling baud rate. For the most
2521 part this is identical to the Linux implementation. However;
2522 Digi supports one rate (76800) that Linux doesn't. This means
2523 that the c_cflag entry that would normally mean 76800 for Digi
2524 actually means 115200 under Linux. Without the below mapping,
2525 a stty 115200 would only drive the board at 76800. Since
2526 the rate 230400 is also found after 76800, the same problem afflicts
2527 us when we choose a rate of 230400. Without the below modificiation
2528 stty 230400 would actually give us 115200.
2530 There are two additional differences. The Linux value for CLOCAL
2531 (0x800; 0004000) has no meaning to the Digi hardware. Also in
2532 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
2533 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
2534 should be checked for a screened out prior to termios2digi_c
2535 returning. Since CLOCAL isn't used by the board this can be
2536 ignored as long as the returned value is used only by Digi hardware.
2537 ----------------------------------------------------------------- */
2539 if (cflag & CBAUDEX)
2541 /* -------------------------------------------------------------
2542 The below code is trying to guarantee that only baud rates
2543 115200 and 230400 are remapped. We use exclusive or because
2544 the various baud rates share common bit positions and therefore
2545 can't be tested for easily.
2546 ----------------------------------------------------------------- */
2549 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2550 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2558 } /* End termios2digi_c */
2560 /* --------------------- Begin epcaparam ----------------------- */
2562 static void epcaparam(struct tty_struct *tty, struct channel *ch)
2563 { /* Begin epcaparam */
2565 unsigned int cmdHead;
2567 volatile struct board_chan *bc;
2568 unsigned mval, hflow, cflag, iflag;
2571 epcaassert(bc !=0, "bc out of range");
2577 if ((ts->c_cflag & CBAUD) == 0)
2578 { /* Begin CBAUD detected */
2584 /* Changing baud in mid-stream transmission can be wonderful */
2585 /* ---------------------------------------------------------------
2586 Flush current transmit buffer by setting cmdTail pointer (tout)
2587 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2588 ----------------------------------------------------------------- */
2590 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2593 } /* End CBAUD detected */
2595 { /* Begin CBAUD not detected */
2597 /* -------------------------------------------------------------------
2598 c_cflags have changed but that change had nothing to do with BAUD.
2599 Propagate the change to the card.
2600 ---------------------------------------------------------------------- */
2602 cflag = termios2digi_c(ch, ts->c_cflag);
2604 if (cflag != ch->fepcflag)
2606 ch->fepcflag = cflag;
2607 /* Set baud rate, char size, stop bits, parity */
2608 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2612 /* ----------------------------------------------------------------
2613 If the user has not forced CLOCAL and if the device is not a
2614 CALLOUT device (Which is always CLOCAL) we set flags such that
2615 the driver will wait on carrier detect.
2616 ------------------------------------------------------------------- */
2618 if (ts->c_cflag & CLOCAL)
2619 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2620 ch->asyncflags &= ~ASYNC_CHECK_CD;
2621 } /* End it is a cud device or a ttyD device with CLOCAL on */
2623 { /* Begin it is a ttyD device */
2624 ch->asyncflags |= ASYNC_CHECK_CD;
2625 } /* End it is a ttyD device */
2627 mval = ch->m_dtr | ch->m_rts;
2629 } /* End CBAUD not detected */
2631 iflag = termios2digi_i(ch, ts->c_iflag);
2633 /* Check input mode flags */
2635 if (iflag != ch->fepiflag)
2637 ch->fepiflag = iflag;
2639 /* ---------------------------------------------------------------
2640 Command sets channels iflag structure on the board. Such things
2641 as input soft flow control, handling of parity errors, and
2642 break handling are all set here.
2643 ------------------------------------------------------------------- */
2645 /* break handling, parity handling, input stripping, flow control chars */
2646 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2649 /* ---------------------------------------------------------------
2650 Set the board mint value for this channel. This will cause hardware
2651 events to be generated each time the DCD signal (Described in mint)
2653 ------------------------------------------------------------------- */
2656 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2657 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2660 ch->imodem = bc->mstat;
2662 hflow = termios2digi_h(ch, ts->c_cflag);
2664 if (hflow != ch->hflow)
2668 /* --------------------------------------------------------------
2669 Hard flow control has been selected but the board is not
2670 using it. Activate hard flow control now.
2671 ----------------------------------------------------------------- */
2673 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2677 mval ^= ch->modemfake & (mval ^ ch->modem);
2679 if (ch->omodem ^ mval)
2683 /* --------------------------------------------------------------
2684 The below command sets the DTR and RTS mstat structure. If
2685 hard flow control is NOT active these changes will drive the
2686 output of the actual DTR and RTS lines. If hard flow control
2687 is active, the changes will be saved in the mstat structure and
2688 only asserted when hard flow control is turned off.
2689 ----------------------------------------------------------------- */
2691 /* First reset DTR & RTS; then set them */
2692 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2693 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2697 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2699 ch->fepstartc = ch->startc;
2700 ch->fepstopc = ch->stopc;
2702 /* ------------------------------------------------------------
2703 The XON / XOFF characters have changed; propagate these
2704 changes to the card.
2705 --------------------------------------------------------------- */
2707 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2710 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2712 ch->fepstartca = ch->startca;
2713 ch->fepstopca = ch->stopca;
2715 /* ---------------------------------------------------------------
2716 Similar to the above, this time the auxilarly XON / XOFF
2717 characters have changed; propagate these changes to the card.
2718 ------------------------------------------------------------------ */
2720 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2723 } /* End epcaparam */
2725 /* --------------------- Begin receive_data ----------------------- */
2727 static void receive_data(struct channel *ch)
2728 { /* Begin receive_data */
2731 struct termios *ts = 0;
2732 struct tty_struct *tty;
2733 volatile struct board_chan *bc;
2734 register int dataToRead, wrapgap, bytesAvailable;
2735 register unsigned int tail, head;
2736 unsigned int wrapmask;
2740 /* ---------------------------------------------------------------
2741 This routine is called by doint when a receive data event
2743 ------------------------------------------------------------------- */
2747 if (ch->statusflags & RXSTOPPED)
2758 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2762 wrapmask = ch->rxbufsize - 1;
2764 /* ---------------------------------------------------------------------
2765 Get the head and tail pointers to the receiver queue. Wrap the
2766 head pointer if it has reached the end of the buffer.
2767 ------------------------------------------------------------------------ */
2771 tail = bc->rout & wrapmask;
2773 bytesAvailable = (head - tail) & wrapmask;
2775 if (bytesAvailable == 0)
2778 /* ------------------------------------------------------------------
2779 If CREAD bit is off or device not open, set TX tail to head
2780 --------------------------------------------------------------------- */
2782 if (!tty || !ts || !(ts->c_cflag & CREAD))
2788 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2794 printk(KERN_WARNING "overrun! DigiBoard device %s\n",tty->name);
2798 rptr = tty->flip.char_buf_ptr;
2799 rc = tty->flip.count;
2801 while (bytesAvailable > 0)
2802 { /* Begin while there is data on the card */
2804 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2806 /* ---------------------------------------------------------------
2807 Even if head has wrapped around only report the amount of
2808 data to be equal to the size - tail. Remember memcpy can't
2809 automaticly wrap around the receive buffer.
2810 ----------------------------------------------------------------- */
2812 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2814 /* --------------------------------------------------------------
2815 Make sure we don't overflow the buffer
2816 ----------------------------------------------------------------- */
2818 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2819 dataToRead = TTY_FLIPBUF_SIZE - rc;
2821 if (dataToRead == 0)
2824 /* ---------------------------------------------------------------
2825 Move data read from our card into the line disciplines buffer
2826 for translation if necessary.
2827 ------------------------------------------------------------------ */
2829 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2830 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2834 tail = (tail + dataToRead) & wrapmask;
2835 bytesAvailable -= dataToRead;
2837 } /* End while there is data on the card */
2840 tty->flip.count = rc;
2841 tty->flip.char_buf_ptr = rptr;
2845 /* Must be called with global data */
2846 tty_schedule_flip(ch->tty);
2849 } /* End receive_data */
2851 static int info_ioctl(struct tty_struct *tty, struct file * file,
2852 unsigned int cmd, unsigned long arg)
2857 { /* Begin switch cmd */
2860 { /* Begin case DIGI_GETINFO */
2862 struct digi_info di ;
2865 getUser(brd, (unsigned int *)arg);
2867 if ((error = verify_area(VERIFY_WRITE, (char*)arg, sizeof(di))))
2869 printk(KERN_ERR "DIGI_GETINFO : verify area size 0x%x failed\n",sizeof(di));
2873 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
2876 memset(&di, 0, sizeof(di));
2879 di.status = boards[brd].status;
2880 di.type = boards[brd].type ;
2881 di.numports = boards[brd].numports ;
2882 di.port = boards[brd].port ;
2883 di.membase = boards[brd].membase ;
2885 if (copy_to_user((char *)arg, &di, sizeof (di)))
2889 } /* End case DIGI_GETINFO */
2892 { /* Begin case DIGI_POLLER */
2894 int brd = arg & 0xff000000 >> 16 ;
2895 unsigned char state = arg & 0xff ;
2897 if ((brd < 0) || (brd >= num_cards))
2899 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
2903 digi_poller_inhibited = state ;
2906 } /* End case DIGI_POLLER */
2909 { /* Begin case DIGI_INIT */
2911 /* ------------------------------------------------------------
2912 This call is made by the apps to complete the initilization
2913 of the board(s). This routine is responsible for setting
2914 the card to its initial state and setting the drivers control
2915 fields to the sutianle settings for the card in question.
2916 ---------------------------------------------------------------- */
2919 for (crd = 0; crd < num_cards; crd++)
2920 post_fep_init (crd);
2924 } /* End case DIGI_INIT */
2928 return -ENOIOCTLCMD;
2930 } /* End switch cmd */
2933 /* --------------------- Begin pc_ioctl ----------------------- */
2935 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2937 struct channel *ch = (struct channel *) tty->driver_data;
2938 volatile struct board_chan *bc;
2939 unsigned int mstat, mflag = 0;
2940 unsigned long flags;
2946 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmget!\n");
2955 restore_flags(flags);
2957 if (mstat & ch->m_dtr)
2960 if (mstat & ch->m_rts)
2963 if (mstat & ch->m_cts)
2966 if (mstat & ch->dsr)
2969 if (mstat & ch->m_ri)
2972 if (mstat & ch->dcd)
2978 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2979 unsigned int set, unsigned int clear)
2981 struct channel *ch = (struct channel *) tty->driver_data;
2982 unsigned long flags;
2985 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmset!\n");
2992 * I think this modemfake stuff is broken. It doesn't
2993 * correctly reflect the behaviour desired by the TIOCM*
2994 * ioctls. Therefore this is probably broken.
2996 if (set & TIOCM_RTS) {
2997 ch->modemfake |= ch->m_rts;
2998 ch->modem |= ch->m_rts;
3000 if (set & TIOCM_DTR) {
3001 ch->modemfake |= ch->m_dtr;
3002 ch->modem |= ch->m_dtr;
3004 if (clear & TIOCM_RTS) {
3005 ch->modemfake |= ch->m_rts;
3006 ch->modem &= ~ch->m_rts;
3008 if (clear & TIOCM_DTR) {
3009 ch->modemfake |= ch->m_dtr;
3010 ch->modem &= ~ch->m_dtr;
3015 /* --------------------------------------------------------------
3016 The below routine generally sets up parity, baud, flow control
3017 issues, etc.... It effect both control flags and input flags.
3018 ------------------------------------------------------------------ */
3022 restore_flags(flags);
3025 static int pc_ioctl(struct tty_struct *tty, struct file * file,
3026 unsigned int cmd, unsigned long arg)
3027 { /* Begin pc_ioctl */
3031 unsigned long flags;
3032 unsigned int mflag, mstat;
3033 unsigned char startc, stopc;
3034 volatile struct board_chan *bc;
3035 struct channel *ch = (struct channel *) tty->driver_data;
3041 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
3047 /* -------------------------------------------------------------------
3048 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
3049 in /usr/src/linux/drivers/char for a good example. In particular
3050 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
3051 ---------------------------------------------------------------------- */
3054 { /* Begin switch cmd */
3057 if (copy_to_user((struct termios *)arg,
3058 tty->termios, sizeof(struct termios)))
3063 return get_termio(tty, (struct termio *)arg);
3065 case TCSBRK: /* SVID version: non-zero arg --> no break */
3067 retval = tty_check_change(tty);
3071 /* Setup an event to indicate when the transmit buffer empties */
3073 setup_empty_event(tty,ch);
3074 tty_wait_until_sent(tty, 0);
3076 digi_send_break(ch, HZ/4); /* 1/4 second */
3079 case TCSBRKP: /* support for POSIX tcsendbreak() */
3081 retval = tty_check_change(tty);
3085 /* Setup an event to indicate when the transmit buffer empties */
3087 setup_empty_event(tty,ch);
3088 tty_wait_until_sent(tty, 0);
3089 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
3094 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
3098 putUser(C_CLOCAL(tty) ? 1 : 0,
3099 (unsigned long *) arg);
3103 /*RONNIE PUT VERIFY_READ (See above) check here */
3107 getUser(value, (unsigned int *)arg);
3108 tty->termios->c_cflag =
3109 ((tty->termios->c_cflag & ~CLOCAL) |
3110 (value ? CLOCAL : 0));
3115 mflag = pc_tiocmget(tty, file);
3116 if (putUser(mflag, (unsigned int *) arg))
3121 if (getUser(mstat, (unsigned int *)arg))
3123 return pc_tiocmset(tty, file, mstat, ~mstat);
3126 ch->omodem |= ch->m_dtr;
3129 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
3131 restore_flags(flags);
3135 ch->omodem &= ~ch->m_dtr;
3138 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
3140 restore_flags(flags);
3144 if (copy_to_user((char*)arg, &ch->digiext,
3151 if ((cmd) == (DIGI_SETAW))
3153 /* Setup an event to indicate when the transmit buffer empties */
3155 setup_empty_event(tty,ch);
3156 tty_wait_until_sent(tty, 0);
3160 if (tty->ldisc.flush_buffer)
3161 tty->ldisc.flush_buffer(tty);
3167 if (copy_from_user(&ch->digiext, (char*)arg,
3171 if (ch->digiext.digi_flags & DIGI_ALTPIN)
3173 ch->dcd = ch->m_dsr;
3174 ch->dsr = ch->m_dcd;
3178 ch->dcd = ch->m_dcd;
3179 ch->dsr = ch->m_dsr;
3185 /* -----------------------------------------------------------------
3186 The below routine generally sets up parity, baud, flow control
3187 issues, etc.... It effect both control flags and input flags.
3188 ------------------------------------------------------------------- */
3192 restore_flags(flags);
3199 if ((cmd) == (DIGI_GETFLOW))
3201 dflow.startc = bc->startc;
3202 dflow.stopc = bc->stopc;
3206 dflow.startc = bc->startca;
3207 dflow.stopc = bc->stopca;
3210 restore_flags(flags);
3212 if (copy_to_user((char*)arg, &dflow, sizeof(dflow)))
3218 if ((cmd) == (DIGI_SETFLOW))
3220 startc = ch->startc;
3225 startc = ch->startca;
3229 if (copy_from_user(&dflow, (char*)arg, sizeof(dflow)))
3232 if (dflow.startc != startc || dflow.stopc != stopc)
3233 { /* Begin if setflow toggled */
3237 if ((cmd) == (DIGI_SETFLOW))
3239 ch->fepstartc = ch->startc = dflow.startc;
3240 ch->fepstopc = ch->stopc = dflow.stopc;
3241 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3245 ch->fepstartca = ch->startca = dflow.startc;
3246 ch->fepstopca = ch->stopca = dflow.stopc;
3247 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3250 if (ch->statusflags & TXSTOPPED)
3254 restore_flags(flags);
3256 } /* End if setflow toggled */
3260 return -ENOIOCTLCMD;
3262 } /* End switch cmd */
3266 } /* End pc_ioctl */
3268 /* --------------------- Begin pc_set_termios ----------------------- */
3270 static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3271 { /* Begin pc_set_termios */
3274 unsigned long flags;
3276 /* ---------------------------------------------------------
3277 verifyChannel returns the channel from the tty struct
3278 if it is valid. This serves as a sanity check.
3279 ------------------------------------------------------------- */
3281 if ((ch = verifyChannel(tty)) != NULL)
3282 { /* Begin if channel valid */
3290 if ((old_termios->c_cflag & CRTSCTS) &&
3291 ((tty->termios->c_cflag & CRTSCTS) == 0))
3292 tty->hw_stopped = 0;
3294 if (!(old_termios->c_cflag & CLOCAL) &&
3295 (tty->termios->c_cflag & CLOCAL))
3296 wake_up_interruptible(&ch->open_wait);
3298 restore_flags(flags);
3300 } /* End if channel valid */
3302 } /* End pc_set_termios */
3304 /* --------------------- Begin do_softint ----------------------- */
3306 static void do_softint(void *private_)
3307 { /* Begin do_softint */
3309 struct channel *ch = (struct channel *) private_;
3312 /* Called in response to a modem change event */
3314 if (ch && ch->magic == EPCA_MAGIC)
3315 { /* Begin EPCA_MAGIC */
3317 struct tty_struct *tty = ch->tty;
3319 if (tty && tty->driver_data)
3321 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3322 { /* Begin if clear_bit */
3324 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
3325 wake_up_interruptible(&ch->open_wait);
3326 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
3328 } /* End if clear_bit */
3331 } /* End EPCA_MAGIC */
3333 } /* End do_softint */
3335 /* ------------------------------------------------------------
3336 pc_stop and pc_start provide software flow control to the
3337 routine and the pc_ioctl routine.
3338 ---------------------------------------------------------------- */
3340 /* --------------------- Begin pc_stop ----------------------- */
3342 static void pc_stop(struct tty_struct *tty)
3343 { /* Begin pc_stop */
3346 unsigned long flags;
3348 /* ---------------------------------------------------------
3349 verifyChannel returns the channel from the tty struct
3350 if it is valid. This serves as a sanity check.
3351 ------------------------------------------------------------- */
3353 if ((ch = verifyChannel(tty)) != NULL)
3354 { /* Begin if valid channel */
3359 if ((ch->statusflags & TXSTOPPED) == 0)
3360 { /* Begin if transmit stop requested */
3364 /* STOP transmitting now !! */
3366 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3368 ch->statusflags |= TXSTOPPED;
3371 } /* End if transmit stop requested */
3373 restore_flags(flags);
3375 } /* End if valid channel */
3379 /* --------------------- Begin pc_start ----------------------- */
3381 static void pc_start(struct tty_struct *tty)
3382 { /* Begin pc_start */
3386 /* ---------------------------------------------------------
3387 verifyChannel returns the channel from the tty struct
3388 if it is valid. This serves as a sanity check.
3389 ------------------------------------------------------------- */
3391 if ((ch = verifyChannel(tty)) != NULL)
3392 { /* Begin if channel valid */
3394 unsigned long flags;
3399 /* Just in case output was resumed because of a change in Digi-flow */
3400 if (ch->statusflags & TXSTOPPED)
3401 { /* Begin transmit resume requested */
3403 volatile struct board_chan *bc;
3407 if (ch->statusflags & LOWWAIT)
3410 /* Okay, you can start transmitting again... */
3412 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3414 ch->statusflags &= ~TXSTOPPED;
3417 } /* End transmit resume requested */
3419 restore_flags(flags);
3421 } /* End if channel valid */
3423 } /* End pc_start */
3425 /* ------------------------------------------------------------------
3426 The below routines pc_throttle and pc_unthrottle are used
3427 to slow (And resume) the receipt of data into the kernels
3428 receive buffers. The exact occurrence of this depends on the
3429 size of the kernels receive buffer and what the 'watermarks'
3430 are set to for that buffer. See the n_ttys.c file for more
3432 ______________________________________________________________________ */
3433 /* --------------------- Begin throttle ----------------------- */
3435 static void pc_throttle(struct tty_struct * tty)
3436 { /* Begin pc_throttle */
3439 unsigned long flags;
3441 /* ---------------------------------------------------------
3442 verifyChannel returns the channel from the tty struct
3443 if it is valid. This serves as a sanity check.
3444 ------------------------------------------------------------- */
3446 if ((ch = verifyChannel(tty)) != NULL)
3447 { /* Begin if channel valid */
3453 if ((ch->statusflags & RXSTOPPED) == 0)
3456 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3458 ch->statusflags |= RXSTOPPED;
3461 restore_flags(flags);
3463 } /* End if channel valid */
3465 } /* End pc_throttle */
3467 /* --------------------- Begin unthrottle ----------------------- */
3469 static void pc_unthrottle(struct tty_struct *tty)
3470 { /* Begin pc_unthrottle */
3473 unsigned long flags;
3474 volatile struct board_chan *bc;
3477 /* ---------------------------------------------------------
3478 verifyChannel returns the channel from the tty struct
3479 if it is valid. This serves as a sanity check.
3480 ------------------------------------------------------------- */
3482 if ((ch = verifyChannel(tty)) != NULL)
3483 { /* Begin if channel valid */
3486 /* Just in case output was resumed because of a change in Digi-flow */
3490 if (ch->statusflags & RXSTOPPED)
3495 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3497 ch->statusflags &= ~RXSTOPPED;
3500 restore_flags(flags);
3502 } /* End if channel valid */
3504 } /* End pc_unthrottle */
3506 /* --------------------- Begin digi_send_break ----------------------- */
3508 void digi_send_break(struct channel *ch, int msec)
3509 { /* Begin digi_send_break */
3511 unsigned long flags;
3517 /* --------------------------------------------------------------------
3518 Maybe I should send an infinite break here, schedule() for
3519 msec amount of time, and then stop the break. This way,
3520 the user can't screw up the FEP by causing digi_send_break()
3521 to be called (i.e. via an ioctl()) more than once in msec amount
3522 of time. Try this for now...
3523 ------------------------------------------------------------------------ */
3525 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3528 restore_flags(flags);
3530 } /* End digi_send_break */
3532 /* --------------------- Begin setup_empty_event ----------------------- */
3534 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3535 { /* Begin setup_empty_event */
3537 volatile struct board_chan *bc = ch->brdchan;
3538 unsigned long int flags;
3543 ch->statusflags |= EMPTYWAIT;
3545 /* ------------------------------------------------------------------
3546 When set the iempty flag request a event to be generated when the
3547 transmit buffer is empty (If there is no BREAK in progress).
3548 --------------------------------------------------------------------- */
3552 restore_flags(flags);
3554 } /* End setup_empty_event */
3556 /* --------------------- Begin get_termio ----------------------- */
3558 static int get_termio(struct tty_struct * tty, struct termio * termio)
3559 { /* Begin get_termio */
3562 error = verify_area(VERIFY_WRITE, termio, sizeof (struct termio));
3566 kernel_termios_to_user_termio(termio, tty->termios);
3569 } /* End get_termio */
3570 /* ---------------------- Begin epca_setup -------------------------- */
3571 void epca_setup(char *str, int *ints)
3572 { /* Begin epca_setup */
3574 struct board_info board;
3575 int index, loop, last;
3579 /* ----------------------------------------------------------------------
3580 If this routine looks a little strange it is because it is only called
3581 if a LILO append command is given to boot the kernel with parameters.
3582 In this way, we can provide the user a method of changing his board
3583 configuration without rebuilding the kernel.
3584 ----------------------------------------------------------------------- */
3588 memset(&board, 0, sizeof(board));
3590 /* Assume the data is int first, later we can change it */
3591 /* I think that array position 0 of ints holds the number of args */
3592 for (last = 0, index = 1; index <= ints[0]; index++)
3594 { /* Begin parse switch */
3597 board.status = ints[index];
3599 /* ---------------------------------------------------------
3600 We check for 2 (As opposed to 1; because 2 is a flag
3601 instructing the driver to ignore epcaconfig.) For this
3602 reason we check for 2.
3603 ------------------------------------------------------------ */
3604 if (board.status == 2)
3605 { /* Begin ignore epcaconfig as well as lilo cmd line */
3609 } /* End ignore epcaconfig as well as lilo cmd line */
3611 if (board.status > 2)
3613 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3614 invalid_lilo_config = 1;
3615 setup_error_code |= INVALID_BOARD_STATUS;
3622 board.type = ints[index];
3623 if (board.type >= PCIXEM)
3625 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3626 invalid_lilo_config = 1;
3627 setup_error_code |= INVALID_BOARD_TYPE;
3634 board.altpin = ints[index];
3635 if (board.altpin > 1)
3637 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3638 invalid_lilo_config = 1;
3639 setup_error_code |= INVALID_ALTPIN;
3646 board.numports = ints[index];
3647 if ((board.numports < 2) || (board.numports > 256))
3649 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3650 invalid_lilo_config = 1;
3651 setup_error_code |= INVALID_NUM_PORTS;
3654 nbdevs += board.numports;
3659 board.port = (unsigned char *)ints[index];
3660 if (ints[index] <= 0)
3662 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3663 invalid_lilo_config = 1;
3664 setup_error_code |= INVALID_PORT_BASE;
3671 board.membase = (unsigned char *)ints[index];
3672 if (ints[index] <= 0)
3674 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3675 invalid_lilo_config = 1;
3676 setup_error_code |= INVALID_MEM_BASE;
3683 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
3686 } /* End parse switch */
3689 { /* Begin while there is a string arg */
3691 /* find the next comma or terminator */
3694 /* While string is not null, and a comma hasn't been found */
3695 while (*temp && (*temp != ','))
3703 /* Set index to the number of args + 1 */
3710 if (strncmp("Disable", str, len) == 0)
3713 if (strncmp("Enable", str, len) == 0)
3717 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3718 invalid_lilo_config = 1;
3719 setup_error_code |= INVALID_BOARD_STATUS;
3727 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3728 if (strcmp(board_desc[loop], str) == 0)
3732 /* ---------------------------------------------------------------
3733 If the index incremented above refers to a legitamate board
3735 ------------------------------------------------------------------*/
3737 if (index < EPCA_NUM_TYPES)
3741 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3742 invalid_lilo_config = 1;
3743 setup_error_code |= INVALID_BOARD_TYPE;
3751 if (strncmp("Disable", str, len) == 0)
3754 if (strncmp("Enable", str, len) == 0)
3758 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3759 invalid_lilo_config = 1;
3760 setup_error_code |= INVALID_ALTPIN;
3768 while (isdigit(*t2))
3773 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3774 invalid_lilo_config = 1;
3775 setup_error_code |= INVALID_NUM_PORTS;
3779 /* ------------------------------------------------------------
3780 There is not a man page for simple_strtoul but the code can be
3781 found in vsprintf.c. The first argument is the string to
3782 translate (To an unsigned long obviously), the second argument
3783 can be the address of any character variable or a NULL. If a
3784 variable is given, the end pointer of the string will be stored
3785 in that variable; if a NULL is given the end pointer will
3786 not be returned. The last argument is the base to use. If
3787 a 0 is indicated, the routine will attempt to determine the
3788 proper base by looking at the values prefix (A '0' for octal,
3789 a 'x' for hex, etc ... If a value is given it will use that
3791 ---------------------------------------------------------------- */
3792 board.numports = simple_strtoul(str, NULL, 0);
3793 nbdevs += board.numports;
3799 while (isxdigit(*t2))
3804 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3805 invalid_lilo_config = 1;
3806 setup_error_code |= INVALID_PORT_BASE;
3810 board.port = (unsigned char *)simple_strtoul(str, NULL, 16);
3816 while (isxdigit(*t2))
3821 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3822 invalid_lilo_config = 1;
3823 setup_error_code |= INVALID_MEM_BASE;
3827 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3832 printk(KERN_ERR "PC/Xx: Too many string parms\n");
3837 } /* End while there is a string arg */
3842 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3846 /* I should REALLY validate the stuff here */
3848 /* Copies our local copy of board into boards */
3849 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3852 /* Does this get called once per lilo arg are what ? */
3854 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3855 num_cards, board_desc[board.type],
3856 board.numports, (int)board.port, (unsigned int) board.membase);
3860 } /* End epca_setup */
3865 /* ------------------------ Begin init_PCI --------------------------- */
3867 enum epic_board_types {
3875 /* indexed directly by epic_board_types enum */
3877 unsigned char board_type;
3878 unsigned bar_idx; /* PCI base address region */
3879 } epca_info_tbl[] = {
3887 static int __devinit epca_init_one (struct pci_dev *pdev,
3888 const struct pci_device_id *ent)
3890 static int board_num = -1;
3891 int board_idx, info_idx = ent->driver_data;
3894 if (pci_enable_device(pdev))
3898 board_idx = board_num + num_cards;
3899 if (board_idx >= MAXBOARDS)
3902 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3904 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3905 epca_info_tbl[info_idx].bar_idx);
3909 boards[board_idx].status = ENABLED;
3910 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3911 boards[board_idx].numports = 0x0;
3912 boards[board_idx].port =
3913 (unsigned char *)((char *) addr + PCI_IO_OFFSET);
3914 boards[board_idx].membase =
3915 (unsigned char *)((char *) addr);
3917 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3918 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3919 0x200000, addr + PCI_IO_OFFSET);
3923 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3924 if (!boards[board_idx].re_map_port) {
3925 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3926 0x200000, addr + PCI_IO_OFFSET);
3927 goto err_out_free_pciio;
3930 if (!request_mem_region (addr, 0x200000, "epca")) {
3931 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3933 goto err_out_free_iounmap;
3936 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3937 if (!boards[board_idx].re_map_membase) {
3938 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3939 0x200000, addr + PCI_IO_OFFSET);
3940 goto err_out_free_memregion;
3943 /* --------------------------------------------------------------
3944 I don't know what the below does, but the hardware guys say
3945 its required on everything except PLX (In this case XRJ).
3946 ---------------------------------------------------------------- */
3947 if (info_idx != brd_xrj) {
3948 pci_write_config_byte(pdev, 0x40, 0);
3949 pci_write_config_byte(pdev, 0x46, 0);
3954 err_out_free_memregion:
3955 release_mem_region (addr, 0x200000);
3956 err_out_free_iounmap:
3957 iounmap (boards[board_idx].re_map_port);
3959 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3965 static struct pci_device_id epca_pci_tbl[] = {
3966 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3967 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3968 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3969 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3973 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3975 int __init init_PCI (void)
3976 { /* Begin init_PCI */
3980 memset (&epca_driver, 0, sizeof (epca_driver));
3981 epca_driver.name = "epca";
3982 epca_driver.id_table = epca_pci_tbl;
3983 epca_driver.probe = epca_init_one;
3985 pci_count = pci_register_driver (&epca_driver);
3987 if (pci_count <= 0) {
3988 pci_unregister_driver (&epca_driver);
3994 } /* End init_PCI */
3996 #endif /* ENABLE_PCI */
3998 MODULE_LICENSE("GPL");