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 __user *)arg2)
52 #define getUser(arg1, arg2) get_user(arg1, (unsigned __user *)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 __user *);
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 */
838 /* ---------------------------------------------------------------
839 The below function reads data from user memory. This routine
840 can not be used in an interrupt routine. (Because it may
841 generate a page fault) It can only be called while we can the
842 user context is accessible.
845 inline void copy_from_user(void * to, const void * from,
846 unsigned long count);
848 I also think (Check hackers guide) that optimization must
849 be turned ON. (Which sounds strange to me...)
851 Remember copy_from_user WILL generate a page fault if the
852 user memory being accessed has been swapped out. This can
853 cause this routine to temporarily sleep while this page
856 ----------------------------------------------------------------- */
858 if (copy_from_user(ch->tmp_buf, buf,
861 } /* End bytesAvailable */
863 /* ------------------------------------------------------------------
864 Set buf to this address for the moment. tmp_buf was allocated in
866 --------------------------------------------------------------------- */
869 } /* End from_user */
871 /* All data is now local */
879 head = bc->tin & (size - 1);
882 if (tail != bc->tout)
886 /* If head >= tail, head has not wrapped around. */
888 { /* Begin head has not wrapped */
890 /* ---------------------------------------------------------------
891 remain (much like dataLen above) represents the total amount of
892 space available on the card for data. Here dataLen represents
893 the space existing between the head pointer and the end of
894 buffer. This is important because a memcpy cannot be told to
895 automatically wrap around when it hits the buffer end.
896 ------------------------------------------------------------------ */
898 dataLen = size - head;
899 remain = size - (head - tail) - 1;
901 } /* End head has not wrapped */
903 { /* Begin head has wrapped around */
905 remain = tail - head - 1;
908 } /* End head has wrapped around */
910 /* -------------------------------------------------------------------
911 Check the space on the card. If we have more data than
912 space; reduce the amount of data to fit the space.
913 ---------------------------------------------------------------------- */
915 bytesAvailable = MIN(remain, bytesAvailable);
918 while (bytesAvailable > 0)
919 { /* Begin while there is data to copy onto card */
921 /* -----------------------------------------------------------------
922 If head is not wrapped, the below will make sure the first
923 data copy fills to the end of card buffer.
924 ------------------------------------------------------------------- */
926 dataLen = MIN(bytesAvailable, dataLen);
927 memcpy(ch->txptr + head, buf, dataLen);
930 amountCopied += dataLen;
931 bytesAvailable -= dataLen;
939 } /* End while there is data to copy onto card */
941 ch->statusflags |= TXBUSY;
945 if ((ch->statusflags & LOWWAIT) == 0)
947 ch->statusflags |= LOWWAIT;
951 restore_flags(flags);
953 return(amountCopied);
957 /* ------------------ Begin pc_put_char ------------------------- */
959 static void pc_put_char(struct tty_struct *tty, unsigned char c)
960 { /* Begin pc_put_char */
963 pc_write(tty, 0, &c, 1);
966 } /* End pc_put_char */
968 /* ------------------ Begin pc_write_room ------------------------- */
970 static int pc_write_room(struct tty_struct *tty)
971 { /* Begin pc_write_room */
976 unsigned int head, tail;
977 volatile struct board_chan *bc;
981 /* ---------------------------------------------------------
982 verifyChannel returns the channel from the tty struct
983 if it is valid. This serves as a sanity check.
984 ------------------------------------------------------------- */
986 if ((ch = verifyChannel(tty)) != NULL)
993 head = bc->tin & (ch->txbufsize - 1);
996 if (tail != bc->tout)
998 /* Wrap tail if necessary */
999 tail &= (ch->txbufsize - 1);
1001 if ((remain = tail - head - 1) < 0 )
1002 remain += ch->txbufsize;
1004 if (remain && (ch->statusflags & LOWWAIT) == 0)
1006 ch->statusflags |= LOWWAIT;
1010 restore_flags(flags);
1013 /* Return how much room is left on card */
1016 } /* End pc_write_room */
1018 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
1020 static int pc_chars_in_buffer(struct tty_struct *tty)
1021 { /* Begin pc_chars_in_buffer */
1024 unsigned int ctail, head, tail;
1026 unsigned long flags;
1028 volatile struct board_chan *bc;
1031 /* ---------------------------------------------------------
1032 verifyChannel returns the channel from the tty struct
1033 if it is valid. This serves as a sanity check.
1034 ------------------------------------------------------------- */
1036 if ((ch = verifyChannel(tty)) == NULL)
1046 ctail = ch->mailbox->cout;
1048 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
1051 { /* Begin if some space on the card has been used */
1053 head = bc->tin & (ch->txbufsize - 1);
1054 tail &= (ch->txbufsize - 1);
1056 /* --------------------------------------------------------------
1057 The logic here is basically opposite of the above pc_write_room
1058 here we are finding the amount of bytes in the buffer filled.
1059 Not the amount of bytes empty.
1060 ------------------------------------------------------------------- */
1062 if ((remain = tail - head - 1) < 0 )
1063 remain += ch->txbufsize;
1065 chars = (int)(ch->txbufsize - remain);
1067 /* -------------------------------------------------------------
1068 Make it possible to wakeup anything waiting for output
1069 in tty_ioctl.c, etc.
1071 If not already set. Setup an event to indicate when the
1072 transmit buffer empties
1073 ----------------------------------------------------------------- */
1075 if (!(ch->statusflags & EMPTYWAIT))
1076 setup_empty_event(tty,ch);
1078 } /* End if some space on the card has been used */
1081 restore_flags(flags);
1083 /* Return number of characters residing on card. */
1086 } /* End pc_chars_in_buffer */
1088 /* ------------------ Begin pc_flush_buffer ---------------------- */
1090 static void pc_flush_buffer(struct tty_struct *tty)
1091 { /* Begin pc_flush_buffer */
1094 unsigned long flags;
1096 volatile struct board_chan *bc;
1099 /* ---------------------------------------------------------
1100 verifyChannel returns the channel from the tty struct
1101 if it is valid. This serves as a sanity check.
1102 ------------------------------------------------------------- */
1104 if ((ch = verifyChannel(tty)) == NULL)
1115 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1117 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1120 restore_flags(flags);
1122 wake_up_interruptible(&tty->write_wait);
1123 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1124 (tty->ldisc.write_wakeup)(tty);
1126 } /* End pc_flush_buffer */
1128 /* ------------------ Begin pc_flush_chars ---------------------- */
1130 static void pc_flush_chars(struct tty_struct *tty)
1131 { /* Begin pc_flush_chars */
1133 struct channel * ch;
1135 /* ---------------------------------------------------------
1136 verifyChannel returns the channel from the tty struct
1137 if it is valid. This serves as a sanity check.
1138 ------------------------------------------------------------- */
1140 if ((ch = verifyChannel(tty)) != NULL)
1142 unsigned long flags;
1147 /* ----------------------------------------------------------------
1148 If not already set and the transmitter is busy setup an event
1149 to indicate when the transmit empties.
1150 ------------------------------------------------------------------- */
1152 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
1153 setup_empty_event(tty,ch);
1155 restore_flags(flags);
1158 } /* End pc_flush_chars */
1160 /* ------------------ Begin block_til_ready ---------------------- */
1162 static int block_til_ready(struct tty_struct *tty,
1163 struct file *filp, struct channel *ch)
1164 { /* Begin block_til_ready */
1166 DECLARE_WAITQUEUE(wait,current);
1167 int retval, do_clocal = 0;
1168 unsigned long flags;
1171 if (tty_hung_up_p(filp))
1173 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1176 retval = -ERESTARTSYS;
1180 /* -----------------------------------------------------------------
1181 If the device is in the middle of being closed, then block
1182 until it's done, and then try again.
1183 -------------------------------------------------------------------- */
1184 if (ch->asyncflags & ASYNC_CLOSING)
1186 interruptible_sleep_on(&ch->close_wait);
1188 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1191 return -ERESTARTSYS;
1194 if (filp->f_flags & O_NONBLOCK)
1196 /* -----------------------------------------------------------------
1197 If non-blocking mode is set, then make the check up front
1199 -------------------------------------------------------------------- */
1201 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1207 if (tty->termios->c_cflag & CLOCAL)
1210 /* Block waiting for the carrier detect and the line to become free */
1213 add_wait_queue(&ch->open_wait, &wait);
1218 /* We dec count so that pc_close will know when to free things */
1219 if (!tty_hung_up_p(filp))
1222 restore_flags(flags);
1227 { /* Begin forever while */
1229 set_current_state(TASK_INTERRUPTIBLE);
1231 if (tty_hung_up_p(filp) ||
1232 !(ch->asyncflags & ASYNC_INITIALIZED))
1234 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1237 retval = -ERESTARTSYS;
1241 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1242 (do_clocal || (ch->imodem & ch->dcd)))
1245 if (signal_pending(current))
1247 retval = -ERESTARTSYS;
1251 /* ---------------------------------------------------------------
1252 Allow someone else to be scheduled. We will occasionally go
1253 through this loop until one of the above conditions change.
1254 The below schedule call will allow other processes to enter and
1255 prevent this loop from hogging the cpu.
1256 ------------------------------------------------------------------ */
1259 } /* End forever while */
1261 current->state = TASK_RUNNING;
1262 remove_wait_queue(&ch->open_wait, &wait);
1264 if (!tty_hung_up_p(filp))
1266 restore_flags(flags);
1273 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1277 } /* End block_til_ready */
1279 /* ------------------ Begin pc_open ---------------------- */
1281 static int pc_open(struct tty_struct *tty, struct file * filp)
1282 { /* Begin pc_open */
1285 unsigned long flags;
1286 int line, retval, boardnum;
1287 volatile struct board_chan *bc;
1288 volatile unsigned int head;
1291 if (line < 0 || line >= nbdevs)
1293 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1294 tty->driver_data = NULL;
1299 ch = &digi_channels[line];
1300 boardnum = ch->boardnum;
1302 /* Check status of board configured in system. */
1304 /* -----------------------------------------------------------------
1305 I check to see if the epca_setup routine detected an user error.
1306 It might be better to put this in pc_init, but for the moment it
1308 ---------------------------------------------------------------------- */
1310 if (invalid_lilo_config)
1312 if (setup_error_code & INVALID_BOARD_TYPE)
1313 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n");
1315 if (setup_error_code & INVALID_NUM_PORTS)
1316 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1318 if (setup_error_code & INVALID_MEM_BASE)
1319 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1321 if (setup_error_code & INVALID_PORT_BASE)
1322 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n");
1324 if (setup_error_code & INVALID_BOARD_STATUS)
1325 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n");
1327 if (setup_error_code & INVALID_ALTPIN)
1328 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1330 tty->driver_data = NULL; /* Mark this device as 'down' */
1334 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1336 tty->driver_data = NULL; /* Mark this device as 'down' */
1340 if (( bc = ch->brdchan) == 0)
1342 tty->driver_data = NULL;
1346 /* ------------------------------------------------------------------
1347 Every time a channel is opened, increment a counter. This is
1348 necessary because we do not wish to flush and shutdown the channel
1349 until the last app holding the channel open, closes it.
1350 --------------------------------------------------------------------- */
1354 /* ----------------------------------------------------------------
1355 Set a kernel structures pointer to our local channel
1356 structure. This way we can get to it when passed only
1358 ------------------------------------------------------------------ */
1360 tty->driver_data = ch;
1362 /* ----------------------------------------------------------------
1363 If this is the first time the channel has been opened, initialize
1364 the tty->termios struct otherwise let pc_close handle it.
1365 -------------------------------------------------------------------- */
1371 ch->statusflags = 0;
1373 /* Save boards current modem status */
1374 ch->imodem = bc->mstat;
1376 /* ----------------------------------------------------------------
1377 Set receive head and tail ptrs to each other. This indicates
1378 no data available to read.
1379 ----------------------------------------------------------------- */
1383 /* Set the channels associated tty structure */
1386 /* -----------------------------------------------------------------
1387 The below routine generally sets up parity, baud, flow control
1388 issues, etc.... It effect both control flags and input flags.
1389 -------------------------------------------------------------------- */
1392 ch->asyncflags |= ASYNC_INITIALIZED;
1395 restore_flags(flags);
1397 retval = block_til_ready(tty, filp, ch);
1403 /* -------------------------------------------------------------
1404 Set this again in case a hangup set it to zero while this
1405 open() was waiting for the line...
1406 --------------------------------------------------------------- */
1413 /* Enable Digi Data events */
1417 restore_flags(flags);
1424 static int __init epca_module_init(void)
1425 { /* Begin init_module */
1427 unsigned long flags;
1434 restore_flags(flags);
1439 module_init(epca_module_init);
1443 static struct pci_driver epca_driver;
1447 /* -------------------- Begin cleanup_module ---------------------- */
1449 static void __exit epca_module_exit(void)
1453 struct board_info *bd;
1455 unsigned long flags;
1457 del_timer_sync(&epca_timer);
1462 if ((tty_unregister_driver(pc_driver)) ||
1463 (tty_unregister_driver(pc_info)))
1465 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1466 restore_flags(flags);
1469 put_tty_driver(pc_driver);
1470 put_tty_driver(pc_info);
1472 for (crd = 0; crd < num_cards; crd++)
1473 { /* Begin for each card */
1478 { /* Begin sanity check */
1479 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1481 } /* End sanity check */
1485 for (count = 0; count < bd->numports; count++, ch++)
1486 { /* Begin for each port */
1491 tty_hangup(ch->tty);
1495 } /* End for each port */
1496 } /* End for each card */
1499 pci_unregister_driver (&epca_driver);
1502 restore_flags(flags);
1505 module_exit(epca_module_exit);
1508 static struct tty_operations pc_ops = {
1512 .write_room = pc_write_room,
1513 .flush_buffer = pc_flush_buffer,
1514 .chars_in_buffer = pc_chars_in_buffer,
1515 .flush_chars = pc_flush_chars,
1516 .put_char = pc_put_char,
1518 .set_termios = pc_set_termios,
1521 .throttle = pc_throttle,
1522 .unthrottle = pc_unthrottle,
1523 .hangup = pc_hangup,
1526 static int info_open(struct tty_struct *tty, struct file * filp)
1531 static struct tty_operations info_ops = {
1533 .ioctl = info_ioctl,
1536 /* ------------------ Begin pc_init ---------------------- */
1538 int __init pc_init(void)
1539 { /* Begin pc_init */
1541 /* ----------------------------------------------------------------
1542 pc_init is called by the operating system during boot up prior to
1543 any open calls being made. In the older versions of Linux (Prior
1544 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1545 memory location (from kernel space) used (kmem_start) is passed
1546 to pc_init. It is pc_inits responsibility to modify this value
1547 for any memory that the Digi driver might need and then return
1548 this value to the operating system. For example if the driver
1549 wishes to allocate 1K of kernel memory, pc_init would return
1550 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1551 + 1024) would then be available for use exclusively by the driver.
1552 In this case our driver does not allocate any of this kernel
1554 ------------------------------------------------------------------*/
1558 struct board_info *bd;
1559 unsigned char board_id = 0;
1562 int pci_boards_found, pci_count;
1565 #endif /* ENABLE_PCI */
1567 pc_driver = alloc_tty_driver(MAX_ALLOC);
1571 pc_info = alloc_tty_driver(MAX_ALLOC);
1573 put_tty_driver(pc_driver);
1577 /* -----------------------------------------------------------------------
1578 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1579 board structure defined by digiConfig into drivers board structure.
1580 Note : If LILO has ran epca_setup then epca_setup will handle defining
1581 num_cards as well as copying the data into the board structure.
1582 -------------------------------------------------------------------------- */
1584 { /* Begin driver has been configured via. epcaconfig */
1587 num_cards = NUMCARDS;
1588 memcpy((void *)&boards, (void *)&static_boards,
1589 (sizeof(struct board_info) * NUMCARDS));
1590 } /* End driver has been configured via. epcaconfig */
1592 /* -----------------------------------------------------------------
1593 Note : If lilo was used to configure the driver and the
1594 ignore epcaconfig option was choosen (digiepca=2) then
1595 nbdevs and num_cards will equal 0 at this point. This is
1596 okay; PCI cards will still be picked up if detected.
1597 --------------------------------------------------------------------- */
1599 /* -----------------------------------------------------------
1600 Set up interrupt, we will worry about memory allocation in
1602 --------------------------------------------------------------- */
1605 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1609 /* ------------------------------------------------------------------
1610 NOTE : This code assumes that the number of ports found in
1611 the boards array is correct. This could be wrong if
1612 the card in question is PCI (And therefore has no ports
1613 entry in the boards structure.) The rest of the
1614 information will be valid for PCI because the beginning
1615 of pc_init scans for PCI and determines i/o and base
1616 memory addresses. I am not sure if it is possible to
1617 read the number of ports supported by the card prior to
1618 it being booted (Since that is the state it is in when
1619 pc_init is run). Because it is not possible to query the
1620 number of supported ports until after the card has booted;
1621 we are required to calculate the card_ptrs as the card is
1622 is initialized (Inside post_fep_init). The negative thing
1623 about this approach is that digiDload's call to GET_INFO
1624 will have a bad port value. (Since this is called prior
1627 --------------------------------------------------------------------- */
1629 pci_boards_found = 0;
1630 if(num_cards < MAXBOARDS)
1631 pci_boards_found += init_PCI();
1632 num_cards += pci_boards_found;
1634 #endif /* ENABLE_PCI */
1636 pc_driver->owner = THIS_MODULE;
1637 pc_driver->name = "ttyD";
1638 pc_driver->devfs_name = "tts/D";
1639 pc_driver->major = DIGI_MAJOR;
1640 pc_driver->minor_start = 0;
1641 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1642 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1643 pc_driver->init_termios = tty_std_termios;
1644 pc_driver->init_termios.c_iflag = 0;
1645 pc_driver->init_termios.c_oflag = 0;
1646 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1647 pc_driver->init_termios.c_lflag = 0;
1648 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1649 tty_set_operations(pc_driver, &pc_ops);
1651 pc_info->owner = THIS_MODULE;
1652 pc_info->name = "digi_ctl";
1653 pc_info->major = DIGIINFOMAJOR;
1654 pc_info->minor_start = 0;
1655 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1656 pc_info->subtype = SERIAL_TYPE_INFO;
1657 pc_info->init_termios = tty_std_termios;
1658 pc_info->init_termios.c_iflag = 0;
1659 pc_info->init_termios.c_oflag = 0;
1660 pc_info->init_termios.c_lflag = 0;
1661 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1662 pc_info->flags = TTY_DRIVER_REAL_RAW;
1663 tty_set_operations(pc_info, &info_ops);
1669 for (crd = 0; crd < num_cards; crd++)
1670 { /* Begin for each card */
1672 /* ------------------------------------------------------------------
1673 This is where the appropriate memory handlers for the hardware is
1674 set. Everything at runtime blindly jumps through these vectors.
1675 ---------------------------------------------------------------------- */
1677 /* defined in epcaconfig.h */
1681 { /* Begin switch on bd->type {board type} */
1684 bd->memwinon = pcxem_memwinon ;
1685 bd->memwinoff = pcxem_memwinoff ;
1686 bd->globalwinon = pcxem_globalwinon ;
1687 bd->txwinon = pcxem_txwinon ;
1688 bd->rxwinon = pcxem_rxwinon ;
1689 bd->memoff = pcxem_memoff ;
1690 bd->assertgwinon = dummy_assertgwinon;
1691 bd->assertmemoff = dummy_assertmemoff;
1697 bd->memwinon = dummy_memwinon;
1698 bd->memwinoff = dummy_memwinoff;
1699 bd->globalwinon = dummy_globalwinon;
1700 bd->txwinon = dummy_txwinon;
1701 bd->rxwinon = dummy_rxwinon;
1702 bd->memoff = dummy_memoff;
1703 bd->assertgwinon = dummy_assertgwinon;
1704 bd->assertmemoff = dummy_assertmemoff;
1710 bd->memwinon = pcxe_memwinon;
1711 bd->memwinoff = pcxe_memwinoff;
1712 bd->globalwinon = pcxe_globalwinon;
1713 bd->txwinon = pcxe_txwinon;
1714 bd->rxwinon = pcxe_rxwinon;
1715 bd->memoff = pcxe_memoff;
1716 bd->assertgwinon = dummy_assertgwinon;
1717 bd->assertmemoff = dummy_assertmemoff;
1723 bd->memwinon = pcxi_memwinon;
1724 bd->memwinoff = pcxi_memwinoff;
1725 bd->globalwinon = pcxi_globalwinon;
1726 bd->txwinon = pcxi_txwinon;
1727 bd->rxwinon = pcxi_rxwinon;
1728 bd->memoff = pcxi_memoff;
1729 bd->assertgwinon = pcxi_assertgwinon;
1730 bd->assertmemoff = pcxi_assertmemoff;
1736 } /* End switch on bd->type */
1738 /* ---------------------------------------------------------------
1739 Some cards need a memory segment to be defined for use in
1740 transmit and receive windowing operations. These boards
1741 are listed in the below switch. In the case of the XI the
1742 amount of memory on the board is variable so the memory_seg
1743 is also variable. This code determines what they segment
1745 ----------------------------------------------------------------- */
1748 { /* Begin switch on bd->type {board type} */
1753 bd->memory_seg = 0xf000;
1757 board_id = inb((int)bd->port);
1758 if ((board_id & 0x1) == 0x1)
1759 { /* Begin it's an XI card */
1761 /* Is it a 64K board */
1762 if ((board_id & 0x30) == 0)
1763 bd->memory_seg = 0xf000;
1765 /* Is it a 128K board */
1766 if ((board_id & 0x30) == 0x10)
1767 bd->memory_seg = 0xe000;
1769 /* Is is a 256K board */
1770 if ((board_id & 0x30) == 0x20)
1771 bd->memory_seg = 0xc000;
1773 /* Is it a 512K board */
1774 if ((board_id & 0x30) == 0x30)
1775 bd->memory_seg = 0x8000;
1777 } /* End it is an XI card */
1780 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1784 } /* End switch on bd->type */
1786 } /* End for each card */
1788 if (tty_register_driver(pc_driver))
1789 panic("Couldn't register Digi PC/ driver");
1791 if (tty_register_driver(pc_info))
1792 panic("Couldn't register Digi PC/ info ");
1794 /* -------------------------------------------------------------------
1795 Start up the poller to check for events on all enabled boards
1796 ---------------------------------------------------------------------- */
1798 init_timer(&epca_timer);
1799 epca_timer.function = epcapoll;
1800 mod_timer(&epca_timer, jiffies + HZ/25);
1802 restore_flags(flags);
1808 /* ------------------ Begin post_fep_init ---------------------- */
1810 static void post_fep_init(unsigned int crd)
1811 { /* Begin post_fep_init */
1815 volatile struct global_data *gd;
1816 struct board_info *bd;
1817 volatile struct board_chan *bc;
1819 int shrinkmem = 0, lowwater ;
1821 /* -------------------------------------------------------------
1822 This call is made by the user via. the ioctl call DIGI_INIT.
1823 It is responsible for setting up all the card specific stuff.
1824 ---------------------------------------------------------------- */
1827 /* -----------------------------------------------------------------
1828 If this is a PCI board, get the port info. Remember PCI cards
1829 do not have entries into the epcaconfig.h file, so we can't get
1830 the number of ports from it. Unfortunetly, this means that anyone
1831 doing a DIGI_GETINFO before the board has booted will get an invalid
1832 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1833 after DIGI_INIT has been called will return the proper values.
1834 ------------------------------------------------------------------- */
1836 if (bd->type >= PCIXEM) /* If the board in question is PCI */
1837 { /* Begin get PCI number of ports */
1839 /* --------------------------------------------------------------------
1840 Below we use XEMPORTS as a memory offset regardless of which PCI
1841 card it is. This is because all of the supported PCI cards have
1842 the same memory offset for the channel data. This will have to be
1843 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1844 states that the port offset is 0xC22 as opposed to 0xC02. This is
1845 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1846 On the PCI cards the number of ports is determined by reading a
1847 ID PROM located in the box attached to the card. The card can then
1848 determine the index the id to determine the number of ports available.
1849 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1850 if the box in question is a XEM or CX)).
1851 ------------------------------------------------------------------------ */
1853 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1854 (bd->re_map_membase + XEMPORTS));
1857 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1858 nbdevs += (bd->numports);
1860 } /* End get PCI number of ports */
1863 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1865 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1870 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1872 memaddr = (unchar *)bd->re_map_membase;
1875 The below command is necessary because newer kernels (2.1.x and
1876 up) do not have a 1:1 virtual to physical mapping. The below
1877 call adjust for that.
1880 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
1882 /* -----------------------------------------------------------------
1883 The below assignment will set bc to point at the BEGINING of
1884 the cards channel structures. For 1 card there will be between
1885 8 and 64 of these structures.
1886 -------------------------------------------------------------------- */
1888 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
1890 /* -------------------------------------------------------------------
1891 The below assignment will set gd to point at the BEGINING of
1892 global memory address 0xc00. The first data in that global
1893 memory actually starts at address 0xc1a. The command in
1894 pointer begins at 0xd10.
1895 ---------------------------------------------------------------------- */
1897 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
1899 /* --------------------------------------------------------------------
1900 XEPORTS (address 0xc22) points at the number of channels the
1901 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1902 ----------------------------------------------------------------------- */
1904 if (((bd->type == PCXEVE) | (bd->type == PCXE)) &&
1905 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
1907 if (bd->type < PCIXEM)
1908 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1913 /* --------------------------------------------------------------------
1914 Remember ch is the main drivers channels structure, while bc is
1915 the cards channel structure.
1916 ------------------------------------------------------------------------ */
1918 /* For every port on the card do ..... */
1920 for (i = 0; i < bd->numports; i++, ch++, bc++)
1921 { /* Begin for each port */
1925 INIT_WORK(&ch->tqueue, do_softint, ch);
1926 ch->board = &boards[crd];
1929 { /* Begin switch bd->type */
1931 /* ----------------------------------------------------------------
1932 Since some of the boards use different bitmaps for their
1933 control signals we cannot hard code these values and retain
1934 portability. We virtualize this data here.
1935 ------------------------------------------------------------------- */
1961 } /* End switch bd->type */
1963 if (boards[crd].altpin)
1965 ch->dsr = ch->m_dcd;
1966 ch->dcd = ch->m_dsr;
1967 ch->digiext.digi_flags |= DIGI_ALTPIN;
1971 ch->dcd = ch->m_dcd;
1972 ch->dsr = ch->m_dsr;
1977 ch->magic = EPCA_MAGIC;
1982 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1987 { /* Begin switch bd->type */
1992 /* Cover all the 2MEG cards */
1993 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff);
1994 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff);
1995 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
1996 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2001 /* Cover all the 32K windowed cards */
2002 /* Mask equal to window size - 1 */
2003 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff);
2004 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff);
2005 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2006 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2011 ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff);
2012 ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9);
2013 ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff);
2014 ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 );
2019 ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4);
2020 ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4);
2021 ch->txwin = ch->rxwin = 0;
2024 } /* End switch bd->type */
2027 ch->txbufsize = bc->tmax + 1;
2030 ch->rxbufsize = bc->rmax + 1;
2032 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
2034 /* Set transmitter low water mark */
2035 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
2037 /* Set receiver low water mark */
2039 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
2041 /* Set receiver high water mark */
2043 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
2048 ch->startc = bc->startc;
2049 ch->stopc = bc->stopc;
2050 ch->startca = bc->startca;
2051 ch->stopca = bc->stopca;
2061 ch->close_delay = 50;
2063 ch->blocked_open = 0;
2064 init_waitqueue_head(&ch->open_wait);
2065 init_waitqueue_head(&ch->close_wait);
2066 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
2069 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
2070 release_region((int)bd->port, 4);
2072 kfree((ch--)->tmp_buf);
2076 memset((void *)ch->tmp_buf,0,ch->txbufsize);
2077 } /* End for each port */
2080 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2081 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2083 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2084 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2085 console_print(mesg);
2089 } /* End post_fep_init */
2091 /* --------------------- Begin epcapoll ------------------------ */
2093 static void epcapoll(unsigned long ignored)
2094 { /* Begin epcapoll */
2096 unsigned long flags;
2098 volatile unsigned int head, tail;
2100 struct board_info *bd;
2102 /* -------------------------------------------------------------------
2103 This routine is called upon every timer interrupt. Even though
2104 the Digi series cards are capable of generating interrupts this
2105 method of non-looping polling is more efficient. This routine
2106 checks for card generated events (Such as receive data, are transmit
2107 buffer empty) and acts on those events.
2108 ----------------------------------------------------------------------- */
2113 for (crd = 0; crd < num_cards; crd++)
2114 { /* Begin for each card */
2119 if ((bd->status == DISABLED) || digi_poller_inhibited)
2120 continue; /* Begin loop next interation */
2122 /* -----------------------------------------------------------
2123 assertmemoff is not needed here; indeed it is an empty subroutine.
2124 It is being kept because future boards may need this as well as
2126 ---------------------------------------------------------------- */
2132 /* ---------------------------------------------------------------
2133 In this case head and tail actually refer to the event queue not
2134 the transmit or receive queue.
2135 ------------------------------------------------------------------- */
2137 head = ch->mailbox->ein;
2138 tail = ch->mailbox->eout;
2140 /* If head isn't equal to tail we have an event */
2147 } /* End for each card */
2149 mod_timer(&epca_timer, jiffies + (HZ / 25));
2151 restore_flags(flags);
2152 } /* End epcapoll */
2154 /* --------------------- Begin doevent ------------------------ */
2156 static void doevent(int crd)
2157 { /* Begin doevent */
2159 volatile unchar *eventbuf;
2160 struct channel *ch, *chan0;
2161 static struct tty_struct *tty;
2162 volatile struct board_info *bd;
2163 volatile struct board_chan *bc;
2164 register volatile unsigned int tail, head;
2165 register int event, channel;
2166 register int mstat, lstat;
2168 /* -------------------------------------------------------------------
2169 This subroutine is called by epcapoll when an event is detected
2170 in the event queue. This routine responds to those events.
2171 --------------------------------------------------------------------- */
2175 chan0 = card_ptr[crd];
2176 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2178 assertgwinon(chan0);
2180 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2181 { /* Begin while something in event queue */
2183 assertgwinon(chan0);
2185 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2187 /* Get the channel the event occurred on */
2188 channel = eventbuf[0];
2190 /* Get the actual event code that occurred */
2191 event = eventbuf[1];
2193 /* ----------------------------------------------------------------
2194 The two assignments below get the current modem status (mstat)
2195 and the previous modem status (lstat). These are useful becuase
2196 an event could signal a change in modem signals itself.
2197 ------------------------------------------------------------------- */
2199 mstat = eventbuf[2];
2200 lstat = eventbuf[3];
2202 ch = chan0 + channel;
2204 if ((unsigned)channel >= bd->numports || !ch)
2206 if (channel >= bd->numports)
2212 if ((bc = ch->brdchan) == NULL)
2215 if (event & DATA_IND)
2216 { /* Begin DATA_IND */
2221 } /* End DATA_IND */
2222 /* else *//* Fix for DCD transition missed bug */
2223 if (event & MODEMCHG_IND)
2224 { /* Begin MODEMCHG_IND */
2226 /* A modem signal change has been indicated */
2230 if (ch->asyncflags & ASYNC_CHECK_CD)
2232 if (mstat & ch->dcd) /* We are now receiving dcd */
2233 wake_up_interruptible(&ch->open_wait);
2235 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2238 } /* End MODEMCHG_IND */
2242 { /* Begin if valid tty */
2244 if (event & BREAK_IND)
2245 { /* Begin if BREAK_IND */
2247 /* A break has been indicated */
2250 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2252 *tty->flip.char_buf_ptr++ = 0;
2254 tty_schedule_flip(tty);
2256 } /* End if BREAK_IND */
2258 if (event & LOWTX_IND)
2259 { /* Begin LOWTX_IND */
2261 if (ch->statusflags & LOWWAIT)
2262 { /* Begin if LOWWAIT */
2264 ch->statusflags &= ~LOWWAIT;
2265 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2266 tty->ldisc.write_wakeup)
2267 (tty->ldisc.write_wakeup)(tty);
2268 wake_up_interruptible(&tty->write_wait);
2270 } /* End if LOWWAIT */
2272 } /* End LOWTX_IND */
2274 if (event & EMPTYTX_IND)
2275 { /* Begin EMPTYTX_IND */
2277 /* This event is generated by setup_empty_event */
2279 ch->statusflags &= ~TXBUSY;
2280 if (ch->statusflags & EMPTYWAIT)
2281 { /* Begin if EMPTYWAIT */
2283 ch->statusflags &= ~EMPTYWAIT;
2284 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2285 tty->ldisc.write_wakeup)
2286 (tty->ldisc.write_wakeup)(tty);
2288 wake_up_interruptible(&tty->write_wait);
2290 } /* End if EMPTYWAIT */
2292 } /* End EMPTYTX_IND */
2294 } /* End if valid tty */
2301 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n");
2305 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2308 } /* End while something in event queue */
2312 /* --------------------- Begin fepcmd ------------------------ */
2314 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2315 int byte2, int ncmds, int bytecmd)
2316 { /* Begin fepcmd */
2319 unsigned int head, cmdTail, cmdStart, cmdMax;
2323 /* This is the routine in which commands may be passed to the card. */
2325 if (ch->board->status == DISABLED)
2332 /* Remember head (As well as max) is just an offset not a base addr */
2333 head = ch->mailbox->cin;
2335 /* cmdStart is a base address */
2336 cmdStart = ch->mailbox->cstart;
2338 /* ------------------------------------------------------------------
2339 We do the addition below because we do not want a max pointer
2340 relative to cmdStart. We want a max pointer that points at the
2341 physical end of the command queue.
2342 -------------------------------------------------------------------- */
2344 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2346 memaddr = ch->board->re_map_membase;
2349 The below command is necessary because newer kernels (2.1.x and
2350 up) do not have a 1:1 virtual to physical mapping. The below
2351 call adjust for that.
2354 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2356 if (head >= (cmdMax - cmdStart) || (head & 03))
2358 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2360 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2367 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2369 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2370 /* Below word_or_byte is bits to set */
2371 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte;
2372 /* Below byte2 is bits to reset */
2373 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2;
2378 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2379 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2380 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2383 head = (head + 4) & (cmdMax - cmdStart - 4);
2384 ch->mailbox->cin = head;
2389 { /* Begin forever loop */
2394 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2398 head = ch->mailbox->cin;
2399 cmdTail = ch->mailbox->cout;
2401 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2403 /* ----------------------------------------------------------
2404 Basically this will break when the FEP acknowledges the
2405 command by incrementing cmdTail (Making it equal to head).
2406 ------------------------------------------------------------- */
2408 if (n <= ncmds * (sizeof(short) * 4))
2409 break; /* Well nearly forever :-) */
2411 } /* End forever loop */
2415 /* ---------------------------------------------------------------------
2416 Digi products use fields in their channels structures that are very
2417 similar to the c_cflag and c_iflag fields typically found in UNIX
2418 termios structures. The below three routines allow mappings
2419 between these hardware "flags" and their respective Linux flags.
2420 ------------------------------------------------------------------------- */
2422 /* --------------------- Begin termios2digi_h -------------------- */
2424 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2425 { /* Begin termios2digi_h */
2429 if (cflag & CRTSCTS)
2431 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2432 res |= ((ch->m_cts) | (ch->m_rts));
2435 if (ch->digiext.digi_flags & RTSPACE)
2438 if (ch->digiext.digi_flags & DTRPACE)
2441 if (ch->digiext.digi_flags & CTSPACE)
2444 if (ch->digiext.digi_flags & DSRPACE)
2447 if (ch->digiext.digi_flags & DCDPACE)
2450 if (res & (ch->m_rts))
2451 ch->digiext.digi_flags |= RTSPACE;
2453 if (res & (ch->m_cts))
2454 ch->digiext.digi_flags |= CTSPACE;
2458 } /* End termios2digi_h */
2460 /* --------------------- Begin termios2digi_i -------------------- */
2461 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2462 { /* Begin termios2digi_i */
2464 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2465 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2467 if (ch->digiext.digi_flags & DIGI_AIXON)
2471 } /* End termios2digi_i */
2473 /* --------------------- Begin termios2digi_c -------------------- */
2475 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2476 { /* Begin termios2digi_c */
2481 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2482 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2483 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2484 #endif /* SPEED_HACK */
2486 if (cflag & CBAUDEX)
2487 { /* Begin detected CBAUDEX */
2489 ch->digiext.digi_flags |= DIGI_FAST;
2491 /* -------------------------------------------------------------
2492 HUPCL bit is used by FEP to indicate fast baud
2493 table is to be used.
2494 ----------------------------------------------------------------- */
2498 } /* End detected CBAUDEX */
2499 else ch->digiext.digi_flags &= ~DIGI_FAST;
2501 /* -------------------------------------------------------------------
2502 CBAUD has bit position 0x1000 set these days to indicate Linux
2503 baud rate remap. Digi hardware can't handle the bit assignment.
2504 (We use a different bit assignment for high speed.). Clear this
2506 ---------------------------------------------------------------------- */
2507 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2509 /* -------------------------------------------------------------
2510 This gets a little confusing. The Digi cards have their own
2511 representation of c_cflags controling baud rate. For the most
2512 part this is identical to the Linux implementation. However;
2513 Digi supports one rate (76800) that Linux doesn't. This means
2514 that the c_cflag entry that would normally mean 76800 for Digi
2515 actually means 115200 under Linux. Without the below mapping,
2516 a stty 115200 would only drive the board at 76800. Since
2517 the rate 230400 is also found after 76800, the same problem afflicts
2518 us when we choose a rate of 230400. Without the below modificiation
2519 stty 230400 would actually give us 115200.
2521 There are two additional differences. The Linux value for CLOCAL
2522 (0x800; 0004000) has no meaning to the Digi hardware. Also in
2523 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
2524 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
2525 should be checked for a screened out prior to termios2digi_c
2526 returning. Since CLOCAL isn't used by the board this can be
2527 ignored as long as the returned value is used only by Digi hardware.
2528 ----------------------------------------------------------------- */
2530 if (cflag & CBAUDEX)
2532 /* -------------------------------------------------------------
2533 The below code is trying to guarantee that only baud rates
2534 115200 and 230400 are remapped. We use exclusive or because
2535 the various baud rates share common bit positions and therefore
2536 can't be tested for easily.
2537 ----------------------------------------------------------------- */
2540 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2541 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2549 } /* End termios2digi_c */
2551 /* --------------------- Begin epcaparam ----------------------- */
2553 static void epcaparam(struct tty_struct *tty, struct channel *ch)
2554 { /* Begin epcaparam */
2556 unsigned int cmdHead;
2558 volatile struct board_chan *bc;
2559 unsigned mval, hflow, cflag, iflag;
2562 epcaassert(bc !=0, "bc out of range");
2568 if ((ts->c_cflag & CBAUD) == 0)
2569 { /* Begin CBAUD detected */
2575 /* Changing baud in mid-stream transmission can be wonderful */
2576 /* ---------------------------------------------------------------
2577 Flush current transmit buffer by setting cmdTail pointer (tout)
2578 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2579 ----------------------------------------------------------------- */
2581 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2584 } /* End CBAUD detected */
2586 { /* Begin CBAUD not detected */
2588 /* -------------------------------------------------------------------
2589 c_cflags have changed but that change had nothing to do with BAUD.
2590 Propagate the change to the card.
2591 ---------------------------------------------------------------------- */
2593 cflag = termios2digi_c(ch, ts->c_cflag);
2595 if (cflag != ch->fepcflag)
2597 ch->fepcflag = cflag;
2598 /* Set baud rate, char size, stop bits, parity */
2599 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2603 /* ----------------------------------------------------------------
2604 If the user has not forced CLOCAL and if the device is not a
2605 CALLOUT device (Which is always CLOCAL) we set flags such that
2606 the driver will wait on carrier detect.
2607 ------------------------------------------------------------------- */
2609 if (ts->c_cflag & CLOCAL)
2610 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2611 ch->asyncflags &= ~ASYNC_CHECK_CD;
2612 } /* End it is a cud device or a ttyD device with CLOCAL on */
2614 { /* Begin it is a ttyD device */
2615 ch->asyncflags |= ASYNC_CHECK_CD;
2616 } /* End it is a ttyD device */
2618 mval = ch->m_dtr | ch->m_rts;
2620 } /* End CBAUD not detected */
2622 iflag = termios2digi_i(ch, ts->c_iflag);
2624 /* Check input mode flags */
2626 if (iflag != ch->fepiflag)
2628 ch->fepiflag = iflag;
2630 /* ---------------------------------------------------------------
2631 Command sets channels iflag structure on the board. Such things
2632 as input soft flow control, handling of parity errors, and
2633 break handling are all set here.
2634 ------------------------------------------------------------------- */
2636 /* break handling, parity handling, input stripping, flow control chars */
2637 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2640 /* ---------------------------------------------------------------
2641 Set the board mint value for this channel. This will cause hardware
2642 events to be generated each time the DCD signal (Described in mint)
2644 ------------------------------------------------------------------- */
2647 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2648 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2651 ch->imodem = bc->mstat;
2653 hflow = termios2digi_h(ch, ts->c_cflag);
2655 if (hflow != ch->hflow)
2659 /* --------------------------------------------------------------
2660 Hard flow control has been selected but the board is not
2661 using it. Activate hard flow control now.
2662 ----------------------------------------------------------------- */
2664 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2668 mval ^= ch->modemfake & (mval ^ ch->modem);
2670 if (ch->omodem ^ mval)
2674 /* --------------------------------------------------------------
2675 The below command sets the DTR and RTS mstat structure. If
2676 hard flow control is NOT active these changes will drive the
2677 output of the actual DTR and RTS lines. If hard flow control
2678 is active, the changes will be saved in the mstat structure and
2679 only asserted when hard flow control is turned off.
2680 ----------------------------------------------------------------- */
2682 /* First reset DTR & RTS; then set them */
2683 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2684 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2688 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2690 ch->fepstartc = ch->startc;
2691 ch->fepstopc = ch->stopc;
2693 /* ------------------------------------------------------------
2694 The XON / XOFF characters have changed; propagate these
2695 changes to the card.
2696 --------------------------------------------------------------- */
2698 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2701 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2703 ch->fepstartca = ch->startca;
2704 ch->fepstopca = ch->stopca;
2706 /* ---------------------------------------------------------------
2707 Similar to the above, this time the auxilarly XON / XOFF
2708 characters have changed; propagate these changes to the card.
2709 ------------------------------------------------------------------ */
2711 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2714 } /* End epcaparam */
2716 /* --------------------- Begin receive_data ----------------------- */
2718 static void receive_data(struct channel *ch)
2719 { /* Begin receive_data */
2722 struct termios *ts = NULL;
2723 struct tty_struct *tty;
2724 volatile struct board_chan *bc;
2725 register int dataToRead, wrapgap, bytesAvailable;
2726 register unsigned int tail, head;
2727 unsigned int wrapmask;
2731 /* ---------------------------------------------------------------
2732 This routine is called by doint when a receive data event
2734 ------------------------------------------------------------------- */
2738 if (ch->statusflags & RXSTOPPED)
2749 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2753 wrapmask = ch->rxbufsize - 1;
2755 /* ---------------------------------------------------------------------
2756 Get the head and tail pointers to the receiver queue. Wrap the
2757 head pointer if it has reached the end of the buffer.
2758 ------------------------------------------------------------------------ */
2762 tail = bc->rout & wrapmask;
2764 bytesAvailable = (head - tail) & wrapmask;
2766 if (bytesAvailable == 0)
2769 /* ------------------------------------------------------------------
2770 If CREAD bit is off or device not open, set TX tail to head
2771 --------------------------------------------------------------------- */
2773 if (!tty || !ts || !(ts->c_cflag & CREAD))
2779 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2785 printk(KERN_WARNING "overrun! DigiBoard device %s\n",tty->name);
2789 rptr = tty->flip.char_buf_ptr;
2790 rc = tty->flip.count;
2792 while (bytesAvailable > 0)
2793 { /* Begin while there is data on the card */
2795 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2797 /* ---------------------------------------------------------------
2798 Even if head has wrapped around only report the amount of
2799 data to be equal to the size - tail. Remember memcpy can't
2800 automaticly wrap around the receive buffer.
2801 ----------------------------------------------------------------- */
2803 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2805 /* --------------------------------------------------------------
2806 Make sure we don't overflow the buffer
2807 ----------------------------------------------------------------- */
2809 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2810 dataToRead = TTY_FLIPBUF_SIZE - rc;
2812 if (dataToRead == 0)
2815 /* ---------------------------------------------------------------
2816 Move data read from our card into the line disciplines buffer
2817 for translation if necessary.
2818 ------------------------------------------------------------------ */
2820 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2821 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2825 tail = (tail + dataToRead) & wrapmask;
2826 bytesAvailable -= dataToRead;
2828 } /* End while there is data on the card */
2831 tty->flip.count = rc;
2832 tty->flip.char_buf_ptr = rptr;
2836 /* Must be called with global data */
2837 tty_schedule_flip(ch->tty);
2840 } /* End receive_data */
2842 static int info_ioctl(struct tty_struct *tty, struct file * file,
2843 unsigned int cmd, unsigned long arg)
2846 { /* Begin switch cmd */
2849 { /* Begin case DIGI_GETINFO */
2851 struct digi_info di ;
2854 getUser(brd, (unsigned int __user *)arg);
2856 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
2859 memset(&di, 0, sizeof(di));
2862 di.status = boards[brd].status;
2863 di.type = boards[brd].type ;
2864 di.numports = boards[brd].numports ;
2865 di.port = boards[brd].port ;
2866 di.membase = boards[brd].membase ;
2868 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2872 } /* End case DIGI_GETINFO */
2875 { /* Begin case DIGI_POLLER */
2877 int brd = arg & 0xff000000 >> 16 ;
2878 unsigned char state = arg & 0xff ;
2880 if ((brd < 0) || (brd >= num_cards))
2882 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
2886 digi_poller_inhibited = state ;
2889 } /* End case DIGI_POLLER */
2892 { /* Begin case DIGI_INIT */
2894 /* ------------------------------------------------------------
2895 This call is made by the apps to complete the initilization
2896 of the board(s). This routine is responsible for setting
2897 the card to its initial state and setting the drivers control
2898 fields to the sutianle settings for the card in question.
2899 ---------------------------------------------------------------- */
2902 for (crd = 0; crd < num_cards; crd++)
2903 post_fep_init (crd);
2907 } /* End case DIGI_INIT */
2911 return -ENOIOCTLCMD;
2913 } /* End switch cmd */
2916 /* --------------------- Begin pc_ioctl ----------------------- */
2918 static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2920 struct channel *ch = (struct channel *) tty->driver_data;
2921 volatile struct board_chan *bc;
2922 unsigned int mstat, mflag = 0;
2923 unsigned long flags;
2929 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmget!\n");
2938 restore_flags(flags);
2940 if (mstat & ch->m_dtr)
2943 if (mstat & ch->m_rts)
2946 if (mstat & ch->m_cts)
2949 if (mstat & ch->dsr)
2952 if (mstat & ch->m_ri)
2955 if (mstat & ch->dcd)
2961 static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2962 unsigned int set, unsigned int clear)
2964 struct channel *ch = (struct channel *) tty->driver_data;
2965 unsigned long flags;
2968 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmset!\n");
2975 * I think this modemfake stuff is broken. It doesn't
2976 * correctly reflect the behaviour desired by the TIOCM*
2977 * ioctls. Therefore this is probably broken.
2979 if (set & TIOCM_RTS) {
2980 ch->modemfake |= ch->m_rts;
2981 ch->modem |= ch->m_rts;
2983 if (set & TIOCM_DTR) {
2984 ch->modemfake |= ch->m_dtr;
2985 ch->modem |= ch->m_dtr;
2987 if (clear & TIOCM_RTS) {
2988 ch->modemfake |= ch->m_rts;
2989 ch->modem &= ~ch->m_rts;
2991 if (clear & TIOCM_DTR) {
2992 ch->modemfake |= ch->m_dtr;
2993 ch->modem &= ~ch->m_dtr;
2998 /* --------------------------------------------------------------
2999 The below routine generally sets up parity, baud, flow control
3000 issues, etc.... It effect both control flags and input flags.
3001 ------------------------------------------------------------------ */
3005 restore_flags(flags);
3009 static int pc_ioctl(struct tty_struct *tty, struct file * file,
3010 unsigned int cmd, unsigned long arg)
3011 { /* Begin pc_ioctl */
3015 unsigned long flags;
3016 unsigned int mflag, mstat;
3017 unsigned char startc, stopc;
3018 volatile struct board_chan *bc;
3019 struct channel *ch = (struct channel *) tty->driver_data;
3020 void __user *argp = (void __user *)arg;
3026 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
3032 /* -------------------------------------------------------------------
3033 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
3034 in /usr/src/linux/drivers/char for a good example. In particular
3035 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
3036 ---------------------------------------------------------------------- */
3039 { /* Begin switch cmd */
3042 if (copy_to_user(argp,
3043 tty->termios, sizeof(struct termios)))
3048 return get_termio(tty, argp);
3050 case TCSBRK: /* SVID version: non-zero arg --> no break */
3052 retval = tty_check_change(tty);
3056 /* Setup an event to indicate when the transmit buffer empties */
3058 setup_empty_event(tty,ch);
3059 tty_wait_until_sent(tty, 0);
3061 digi_send_break(ch, HZ/4); /* 1/4 second */
3064 case TCSBRKP: /* support for POSIX tcsendbreak() */
3066 retval = tty_check_change(tty);
3070 /* Setup an event to indicate when the transmit buffer empties */
3072 setup_empty_event(tty,ch);
3073 tty_wait_until_sent(tty, 0);
3074 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
3078 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
3086 if (get_user(value, (unsigned __user *)argp))
3088 tty->termios->c_cflag =
3089 ((tty->termios->c_cflag & ~CLOCAL) |
3090 (value ? CLOCAL : 0));
3095 mflag = pc_tiocmget(tty, file);
3096 if (put_user(mflag, (unsigned long __user *)argp))
3101 if (get_user(mstat, (unsigned __user *)argp))
3103 return pc_tiocmset(tty, file, mstat, ~mstat);
3106 ch->omodem |= ch->m_dtr;
3109 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
3111 restore_flags(flags);
3115 ch->omodem &= ~ch->m_dtr;
3118 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
3120 restore_flags(flags);
3124 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
3130 if ((cmd) == (DIGI_SETAW))
3132 /* Setup an event to indicate when the transmit buffer empties */
3134 setup_empty_event(tty,ch);
3135 tty_wait_until_sent(tty, 0);
3139 if (tty->ldisc.flush_buffer)
3140 tty->ldisc.flush_buffer(tty);
3146 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
3149 if (ch->digiext.digi_flags & DIGI_ALTPIN)
3151 ch->dcd = ch->m_dsr;
3152 ch->dsr = ch->m_dcd;
3156 ch->dcd = ch->m_dcd;
3157 ch->dsr = ch->m_dsr;
3163 /* -----------------------------------------------------------------
3164 The below routine generally sets up parity, baud, flow control
3165 issues, etc.... It effect both control flags and input flags.
3166 ------------------------------------------------------------------- */
3170 restore_flags(flags);
3177 if ((cmd) == (DIGI_GETFLOW))
3179 dflow.startc = bc->startc;
3180 dflow.stopc = bc->stopc;
3184 dflow.startc = bc->startca;
3185 dflow.stopc = bc->stopca;
3188 restore_flags(flags);
3190 if (copy_to_user(argp, &dflow, sizeof(dflow)))
3196 if ((cmd) == (DIGI_SETFLOW))
3198 startc = ch->startc;
3203 startc = ch->startca;
3207 if (copy_from_user(&dflow, argp, sizeof(dflow)))
3210 if (dflow.startc != startc || dflow.stopc != stopc)
3211 { /* Begin if setflow toggled */
3215 if ((cmd) == (DIGI_SETFLOW))
3217 ch->fepstartc = ch->startc = dflow.startc;
3218 ch->fepstopc = ch->stopc = dflow.stopc;
3219 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3223 ch->fepstartca = ch->startca = dflow.startc;
3224 ch->fepstopca = ch->stopca = dflow.stopc;
3225 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3228 if (ch->statusflags & TXSTOPPED)
3232 restore_flags(flags);
3234 } /* End if setflow toggled */
3238 return -ENOIOCTLCMD;
3240 } /* End switch cmd */
3244 } /* End pc_ioctl */
3246 /* --------------------- Begin pc_set_termios ----------------------- */
3248 static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3249 { /* Begin pc_set_termios */
3252 unsigned long flags;
3254 /* ---------------------------------------------------------
3255 verifyChannel returns the channel from the tty struct
3256 if it is valid. This serves as a sanity check.
3257 ------------------------------------------------------------- */
3259 if ((ch = verifyChannel(tty)) != NULL)
3260 { /* Begin if channel valid */
3268 if ((old_termios->c_cflag & CRTSCTS) &&
3269 ((tty->termios->c_cflag & CRTSCTS) == 0))
3270 tty->hw_stopped = 0;
3272 if (!(old_termios->c_cflag & CLOCAL) &&
3273 (tty->termios->c_cflag & CLOCAL))
3274 wake_up_interruptible(&ch->open_wait);
3276 restore_flags(flags);
3278 } /* End if channel valid */
3280 } /* End pc_set_termios */
3282 /* --------------------- Begin do_softint ----------------------- */
3284 static void do_softint(void *private_)
3285 { /* Begin do_softint */
3287 struct channel *ch = (struct channel *) private_;
3290 /* Called in response to a modem change event */
3292 if (ch && ch->magic == EPCA_MAGIC)
3293 { /* Begin EPCA_MAGIC */
3295 struct tty_struct *tty = ch->tty;
3297 if (tty && tty->driver_data)
3299 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3300 { /* Begin if clear_bit */
3302 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
3303 wake_up_interruptible(&ch->open_wait);
3304 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
3306 } /* End if clear_bit */
3309 } /* End EPCA_MAGIC */
3311 } /* End do_softint */
3313 /* ------------------------------------------------------------
3314 pc_stop and pc_start provide software flow control to the
3315 routine and the pc_ioctl routine.
3316 ---------------------------------------------------------------- */
3318 /* --------------------- Begin pc_stop ----------------------- */
3320 static void pc_stop(struct tty_struct *tty)
3321 { /* Begin pc_stop */
3324 unsigned long flags;
3326 /* ---------------------------------------------------------
3327 verifyChannel returns the channel from the tty struct
3328 if it is valid. This serves as a sanity check.
3329 ------------------------------------------------------------- */
3331 if ((ch = verifyChannel(tty)) != NULL)
3332 { /* Begin if valid channel */
3337 if ((ch->statusflags & TXSTOPPED) == 0)
3338 { /* Begin if transmit stop requested */
3342 /* STOP transmitting now !! */
3344 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3346 ch->statusflags |= TXSTOPPED;
3349 } /* End if transmit stop requested */
3351 restore_flags(flags);
3353 } /* End if valid channel */
3357 /* --------------------- Begin pc_start ----------------------- */
3359 static void pc_start(struct tty_struct *tty)
3360 { /* Begin pc_start */
3364 /* ---------------------------------------------------------
3365 verifyChannel returns the channel from the tty struct
3366 if it is valid. This serves as a sanity check.
3367 ------------------------------------------------------------- */
3369 if ((ch = verifyChannel(tty)) != NULL)
3370 { /* Begin if channel valid */
3372 unsigned long flags;
3377 /* Just in case output was resumed because of a change in Digi-flow */
3378 if (ch->statusflags & TXSTOPPED)
3379 { /* Begin transmit resume requested */
3381 volatile struct board_chan *bc;
3385 if (ch->statusflags & LOWWAIT)
3388 /* Okay, you can start transmitting again... */
3390 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3392 ch->statusflags &= ~TXSTOPPED;
3395 } /* End transmit resume requested */
3397 restore_flags(flags);
3399 } /* End if channel valid */
3401 } /* End pc_start */
3403 /* ------------------------------------------------------------------
3404 The below routines pc_throttle and pc_unthrottle are used
3405 to slow (And resume) the receipt of data into the kernels
3406 receive buffers. The exact occurrence of this depends on the
3407 size of the kernels receive buffer and what the 'watermarks'
3408 are set to for that buffer. See the n_ttys.c file for more
3410 ______________________________________________________________________ */
3411 /* --------------------- Begin throttle ----------------------- */
3413 static void pc_throttle(struct tty_struct * tty)
3414 { /* Begin pc_throttle */
3417 unsigned long flags;
3419 /* ---------------------------------------------------------
3420 verifyChannel returns the channel from the tty struct
3421 if it is valid. This serves as a sanity check.
3422 ------------------------------------------------------------- */
3424 if ((ch = verifyChannel(tty)) != NULL)
3425 { /* Begin if channel valid */
3431 if ((ch->statusflags & RXSTOPPED) == 0)
3434 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3436 ch->statusflags |= RXSTOPPED;
3439 restore_flags(flags);
3441 } /* End if channel valid */
3443 } /* End pc_throttle */
3445 /* --------------------- Begin unthrottle ----------------------- */
3447 static void pc_unthrottle(struct tty_struct *tty)
3448 { /* Begin pc_unthrottle */
3451 unsigned long flags;
3452 volatile struct board_chan *bc;
3455 /* ---------------------------------------------------------
3456 verifyChannel returns the channel from the tty struct
3457 if it is valid. This serves as a sanity check.
3458 ------------------------------------------------------------- */
3460 if ((ch = verifyChannel(tty)) != NULL)
3461 { /* Begin if channel valid */
3464 /* Just in case output was resumed because of a change in Digi-flow */
3468 if (ch->statusflags & RXSTOPPED)
3473 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3475 ch->statusflags &= ~RXSTOPPED;
3478 restore_flags(flags);
3480 } /* End if channel valid */
3482 } /* End pc_unthrottle */
3484 /* --------------------- Begin digi_send_break ----------------------- */
3486 void digi_send_break(struct channel *ch, int msec)
3487 { /* Begin digi_send_break */
3489 unsigned long flags;
3495 /* --------------------------------------------------------------------
3496 Maybe I should send an infinite break here, schedule() for
3497 msec amount of time, and then stop the break. This way,
3498 the user can't screw up the FEP by causing digi_send_break()
3499 to be called (i.e. via an ioctl()) more than once in msec amount
3500 of time. Try this for now...
3501 ------------------------------------------------------------------------ */
3503 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3506 restore_flags(flags);
3508 } /* End digi_send_break */
3510 /* --------------------- Begin setup_empty_event ----------------------- */
3512 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3513 { /* Begin setup_empty_event */
3515 volatile struct board_chan *bc = ch->brdchan;
3516 unsigned long int flags;
3521 ch->statusflags |= EMPTYWAIT;
3523 /* ------------------------------------------------------------------
3524 When set the iempty flag request a event to be generated when the
3525 transmit buffer is empty (If there is no BREAK in progress).
3526 --------------------------------------------------------------------- */
3530 restore_flags(flags);
3532 } /* End setup_empty_event */
3534 /* --------------------- Begin get_termio ----------------------- */
3536 static int get_termio(struct tty_struct * tty, struct termio __user * termio)
3537 { /* Begin get_termio */
3538 return kernel_termios_to_user_termio(termio, tty->termios);
3539 } /* End get_termio */
3540 /* ---------------------- Begin epca_setup -------------------------- */
3541 void epca_setup(char *str, int *ints)
3542 { /* Begin epca_setup */
3544 struct board_info board;
3545 int index, loop, last;
3549 /* ----------------------------------------------------------------------
3550 If this routine looks a little strange it is because it is only called
3551 if a LILO append command is given to boot the kernel with parameters.
3552 In this way, we can provide the user a method of changing his board
3553 configuration without rebuilding the kernel.
3554 ----------------------------------------------------------------------- */
3558 memset(&board, 0, sizeof(board));
3560 /* Assume the data is int first, later we can change it */
3561 /* I think that array position 0 of ints holds the number of args */
3562 for (last = 0, index = 1; index <= ints[0]; index++)
3564 { /* Begin parse switch */
3567 board.status = ints[index];
3569 /* ---------------------------------------------------------
3570 We check for 2 (As opposed to 1; because 2 is a flag
3571 instructing the driver to ignore epcaconfig.) For this
3572 reason we check for 2.
3573 ------------------------------------------------------------ */
3574 if (board.status == 2)
3575 { /* Begin ignore epcaconfig as well as lilo cmd line */
3579 } /* End ignore epcaconfig as well as lilo cmd line */
3581 if (board.status > 2)
3583 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3584 invalid_lilo_config = 1;
3585 setup_error_code |= INVALID_BOARD_STATUS;
3592 board.type = ints[index];
3593 if (board.type >= PCIXEM)
3595 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3596 invalid_lilo_config = 1;
3597 setup_error_code |= INVALID_BOARD_TYPE;
3604 board.altpin = ints[index];
3605 if (board.altpin > 1)
3607 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3608 invalid_lilo_config = 1;
3609 setup_error_code |= INVALID_ALTPIN;
3616 board.numports = ints[index];
3617 if ((board.numports < 2) || (board.numports > 256))
3619 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3620 invalid_lilo_config = 1;
3621 setup_error_code |= INVALID_NUM_PORTS;
3624 nbdevs += board.numports;
3629 board.port = (unsigned char *)ints[index];
3630 if (ints[index] <= 0)
3632 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3633 invalid_lilo_config = 1;
3634 setup_error_code |= INVALID_PORT_BASE;
3641 board.membase = (unsigned char *)ints[index];
3642 if (ints[index] <= 0)
3644 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3645 invalid_lilo_config = 1;
3646 setup_error_code |= INVALID_MEM_BASE;
3653 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
3656 } /* End parse switch */
3659 { /* Begin while there is a string arg */
3661 /* find the next comma or terminator */
3664 /* While string is not null, and a comma hasn't been found */
3665 while (*temp && (*temp != ','))
3673 /* Set index to the number of args + 1 */
3680 if (strncmp("Disable", str, len) == 0)
3683 if (strncmp("Enable", str, len) == 0)
3687 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3688 invalid_lilo_config = 1;
3689 setup_error_code |= INVALID_BOARD_STATUS;
3697 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3698 if (strcmp(board_desc[loop], str) == 0)
3702 /* ---------------------------------------------------------------
3703 If the index incremented above refers to a legitamate board
3705 ------------------------------------------------------------------*/
3707 if (index < EPCA_NUM_TYPES)
3711 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3712 invalid_lilo_config = 1;
3713 setup_error_code |= INVALID_BOARD_TYPE;
3721 if (strncmp("Disable", str, len) == 0)
3724 if (strncmp("Enable", str, len) == 0)
3728 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3729 invalid_lilo_config = 1;
3730 setup_error_code |= INVALID_ALTPIN;
3738 while (isdigit(*t2))
3743 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3744 invalid_lilo_config = 1;
3745 setup_error_code |= INVALID_NUM_PORTS;
3749 /* ------------------------------------------------------------
3750 There is not a man page for simple_strtoul but the code can be
3751 found in vsprintf.c. The first argument is the string to
3752 translate (To an unsigned long obviously), the second argument
3753 can be the address of any character variable or a NULL. If a
3754 variable is given, the end pointer of the string will be stored
3755 in that variable; if a NULL is given the end pointer will
3756 not be returned. The last argument is the base to use. If
3757 a 0 is indicated, the routine will attempt to determine the
3758 proper base by looking at the values prefix (A '0' for octal,
3759 a 'x' for hex, etc ... If a value is given it will use that
3761 ---------------------------------------------------------------- */
3762 board.numports = simple_strtoul(str, NULL, 0);
3763 nbdevs += board.numports;
3769 while (isxdigit(*t2))
3774 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3775 invalid_lilo_config = 1;
3776 setup_error_code |= INVALID_PORT_BASE;
3780 board.port = (unsigned char *)simple_strtoul(str, NULL, 16);
3786 while (isxdigit(*t2))
3791 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3792 invalid_lilo_config = 1;
3793 setup_error_code |= INVALID_MEM_BASE;
3797 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3802 printk(KERN_ERR "PC/Xx: Too many string parms\n");
3807 } /* End while there is a string arg */
3812 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3816 /* I should REALLY validate the stuff here */
3818 /* Copies our local copy of board into boards */
3819 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3822 /* Does this get called once per lilo arg are what ? */
3824 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3825 num_cards, board_desc[board.type],
3826 board.numports, (int)board.port, (unsigned int) board.membase);
3830 } /* End epca_setup */
3835 /* ------------------------ Begin init_PCI --------------------------- */
3837 enum epic_board_types {
3845 /* indexed directly by epic_board_types enum */
3847 unsigned char board_type;
3848 unsigned bar_idx; /* PCI base address region */
3849 } epca_info_tbl[] = {
3857 static int __devinit epca_init_one (struct pci_dev *pdev,
3858 const struct pci_device_id *ent)
3860 static int board_num = -1;
3861 int board_idx, info_idx = ent->driver_data;
3864 if (pci_enable_device(pdev))
3868 board_idx = board_num + num_cards;
3869 if (board_idx >= MAXBOARDS)
3872 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3874 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3875 epca_info_tbl[info_idx].bar_idx);
3879 boards[board_idx].status = ENABLED;
3880 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3881 boards[board_idx].numports = 0x0;
3882 boards[board_idx].port =
3883 (unsigned char *)((char *) addr + PCI_IO_OFFSET);
3884 boards[board_idx].membase =
3885 (unsigned char *)((char *) addr);
3887 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3888 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3889 0x200000, addr + PCI_IO_OFFSET);
3893 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3894 if (!boards[board_idx].re_map_port) {
3895 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3896 0x200000, addr + PCI_IO_OFFSET);
3897 goto err_out_free_pciio;
3900 if (!request_mem_region (addr, 0x200000, "epca")) {
3901 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3903 goto err_out_free_iounmap;
3906 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3907 if (!boards[board_idx].re_map_membase) {
3908 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3909 0x200000, addr + PCI_IO_OFFSET);
3910 goto err_out_free_memregion;
3913 /* --------------------------------------------------------------
3914 I don't know what the below does, but the hardware guys say
3915 its required on everything except PLX (In this case XRJ).
3916 ---------------------------------------------------------------- */
3917 if (info_idx != brd_xrj) {
3918 pci_write_config_byte(pdev, 0x40, 0);
3919 pci_write_config_byte(pdev, 0x46, 0);
3924 err_out_free_memregion:
3925 release_mem_region (addr, 0x200000);
3926 err_out_free_iounmap:
3927 iounmap (boards[board_idx].re_map_port);
3929 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3935 static struct pci_device_id epca_pci_tbl[] = {
3936 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3937 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3938 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3939 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3943 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3945 int __init init_PCI (void)
3946 { /* Begin init_PCI */
3950 memset (&epca_driver, 0, sizeof (epca_driver));
3951 epca_driver.name = "epca";
3952 epca_driver.id_table = epca_pci_tbl;
3953 epca_driver.probe = epca_init_one;
3955 pci_count = pci_register_driver (&epca_driver);
3957 if (pci_count <= 0) {
3958 pci_unregister_driver (&epca_driver);
3964 } /* End init_PCI */
3966 #endif /* ENABLE_PCI */
3968 MODULE_LICENSE("GPL");