4 Copyright (C) 1996 Digi International.
6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456
9 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 --------------------------------------------------------------------------- */
28 /* See README.epca for change history --DAT*/
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/init.h>
36 #include <linux/serial.h>
37 #include <linux/delay.h>
38 #include <linux/ctype.h>
39 #include <linux/tty.h>
40 #include <linux/tty_flip.h>
41 #include <linux/slab.h>
42 #include <linux/ioport.h>
43 #include <asm/uaccess.h>
48 #endif /* CONFIG_PCI */
50 #define putUser(arg1, arg2) put_user(arg1, (unsigned long *)arg2)
51 #define getUser(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
54 #include <linux/pci.h>
56 #endif /* ENABLE_PCI */
61 #include "epcaconfig.h"
63 #if BITS_PER_LONG != 32
64 # error FIXME: this driver only works on 32-bit platforms
67 /* ---------------------- Begin defines ------------------------ */
69 #define VERSION "1.3.0.1-LK"
71 /* This major needs to be submitted to Linux to join the majors list */
73 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
76 #define MIN(a,b) ((a) < (b) ? (a) : (b))
78 #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
82 /* ----------------- Begin global definitions ------------------- */
84 static char mesg[100];
85 static int nbdevs, num_cards, liloconfig;
86 static int digi_poller_inhibited = 1 ;
88 static int setup_error_code;
89 static int invalid_lilo_config;
91 /* -----------------------------------------------------------------------
92 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
94 --------------------------------------------------------------------------*/
95 static struct board_info boards[MAXBOARDS];
98 /* ------------- Begin structures used for driver registeration ---------- */
100 static struct tty_driver *pc_driver;
101 static struct tty_driver *pc_info;
103 /* ------------------ Begin Digi specific structures -------------------- */
105 /* ------------------------------------------------------------------------
106 digi_channels represents an array of structures that keep track of
107 each channel of the Digi product. Information such as transmit and
108 receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
109 are stored here. This structure is NOT used to overlay the cards
110 physical channel structure.
111 -------------------------------------------------------------------------- */
113 static struct channel digi_channels[MAX_ALLOC];
115 /* ------------------------------------------------------------------------
116 card_ptr is an array used to hold the address of the
117 first channel structure of each card. This array will hold
118 the addresses of various channels located in digi_channels.
119 -------------------------------------------------------------------------- */
120 static struct channel *card_ptr[MAXCARDS];
122 static struct timer_list epca_timer;
124 /* ---------------------- Begin function prototypes --------------------- */
126 /* ----------------------------------------------------------------------
127 Begin generic memory functions. These functions will be alias
128 (point at) more specific functions dependent on the board being
130 ----------------------------------------------------------------------- */
132 static inline void memwinon(struct board_info *b, unsigned int win);
133 static inline void memwinoff(struct board_info *b, unsigned int win);
134 static inline void globalwinon(struct channel *ch);
135 static inline void rxwinon(struct channel *ch);
136 static inline void txwinon(struct channel *ch);
137 static inline void memoff(struct channel *ch);
138 static inline void assertgwinon(struct channel *ch);
139 static inline void assertmemoff(struct channel *ch);
141 /* ---- Begin more 'specific' memory functions for cx_like products --- */
143 static inline void pcxem_memwinon(struct board_info *b, unsigned int win);
144 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win);
145 static inline void pcxem_globalwinon(struct channel *ch);
146 static inline void pcxem_rxwinon(struct channel *ch);
147 static inline void pcxem_txwinon(struct channel *ch);
148 static inline void pcxem_memoff(struct channel *ch);
150 /* ------ Begin more 'specific' memory functions for the pcxe ------- */
152 static inline void pcxe_memwinon(struct board_info *b, unsigned int win);
153 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win);
154 static inline void pcxe_globalwinon(struct channel *ch);
155 static inline void pcxe_rxwinon(struct channel *ch);
156 static inline void pcxe_txwinon(struct channel *ch);
157 static inline void pcxe_memoff(struct channel *ch);
159 /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
160 /* Note : pc64xe and pcxi share the same windowing routines */
162 static inline void pcxi_memwinon(struct board_info *b, unsigned int win);
163 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win);
164 static inline void pcxi_globalwinon(struct channel *ch);
165 static inline void pcxi_rxwinon(struct channel *ch);
166 static inline void pcxi_txwinon(struct channel *ch);
167 static inline void pcxi_memoff(struct channel *ch);
169 /* - Begin 'specific' do nothing memory functions needed for some cards - */
171 static inline void dummy_memwinon(struct board_info *b, unsigned int win);
172 static inline void dummy_memwinoff(struct board_info *b, unsigned int win);
173 static inline void dummy_globalwinon(struct channel *ch);
174 static inline void dummy_rxwinon(struct channel *ch);
175 static inline void dummy_txwinon(struct channel *ch);
176 static inline void dummy_memoff(struct channel *ch);
177 static inline void dummy_assertgwinon(struct channel *ch);
178 static inline void dummy_assertmemoff(struct channel *ch);
180 /* ------------------- Begin declare functions ----------------------- */
182 static inline struct channel *verifyChannel(register struct tty_struct *);
183 static inline void pc_sched_event(struct channel *, int);
184 static void epca_error(int, char *);
185 static void pc_close(struct tty_struct *, struct file *);
186 static void shutdown(struct channel *);
187 static void pc_hangup(struct tty_struct *);
188 static void pc_put_char(struct tty_struct *, unsigned char);
189 static int pc_write_room(struct tty_struct *);
190 static int pc_chars_in_buffer(struct tty_struct *);
191 static void pc_flush_buffer(struct tty_struct *);
192 static void pc_flush_chars(struct tty_struct *);
193 static int block_til_ready(struct tty_struct *, struct file *,
195 static int pc_open(struct tty_struct *, struct file *);
196 static void post_fep_init(unsigned int crd);
197 static void epcapoll(unsigned long);
198 static void doevent(int);
199 static void fepcmd(struct channel *, int, int, int, int, int);
200 static unsigned termios2digi_h(struct channel *ch, unsigned);
201 static unsigned termios2digi_i(struct channel *ch, unsigned);
202 static unsigned termios2digi_c(struct channel *ch, unsigned);
203 static void epcaparam(struct tty_struct *, struct channel *);
204 static void receive_data(struct channel *);
205 static int pc_ioctl(struct tty_struct *, struct file *,
206 unsigned int, unsigned long);
207 static int info_ioctl(struct tty_struct *, struct file *,
208 unsigned int, unsigned long);
209 static void pc_set_termios(struct tty_struct *, struct termios *);
210 static void do_softint(void *);
211 static void pc_stop(struct tty_struct *);
212 static void pc_start(struct tty_struct *);
213 static void pc_throttle(struct tty_struct * tty);
214 static void pc_unthrottle(struct tty_struct *tty);
215 static void digi_send_break(struct channel *ch, int msec);
216 static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
217 void epca_setup(char *, int *);
218 void console_print(const char *);
220 static int get_termio(struct tty_struct *, struct termio *);
221 static int pc_write(struct tty_struct *, int, const unsigned char *, int);
225 static int init_PCI(void);
226 #endif /* ENABLE_PCI */
229 /* ------------------------------------------------------------------
230 Table of functions for each board to handle memory. Mantaining
231 parallelism is a *very* good idea here. The idea is for the
232 runtime code to blindly call these functions, not knowing/caring
233 about the underlying hardware. This stuff should contain no
234 conditionals; if more functionality is needed a different entry
235 should be established. These calls are the interface calls and
236 are the only functions that should be accessed. Anyone caught
237 making direct calls deserves what they get.
238 -------------------------------------------------------------------- */
240 static inline void memwinon(struct board_info *b, unsigned int win)
242 (b->memwinon)(b, win);
245 static inline void memwinoff(struct board_info *b, unsigned int win)
247 (b->memwinoff)(b, win);
250 static inline void globalwinon(struct channel *ch)
252 (ch->board->globalwinon)(ch);
255 static inline void rxwinon(struct channel *ch)
257 (ch->board->rxwinon)(ch);
260 static inline void txwinon(struct channel *ch)
262 (ch->board->txwinon)(ch);
265 static inline void memoff(struct channel *ch)
267 (ch->board->memoff)(ch);
269 static inline void assertgwinon(struct channel *ch)
271 (ch->board->assertgwinon)(ch);
274 static inline void assertmemoff(struct channel *ch)
276 (ch->board->assertmemoff)(ch);
279 /* ---------------------------------------------------------
280 PCXEM windowing is the same as that used in the PCXR
282 ------------------------------------------------------------ */
284 static inline void pcxem_memwinon(struct board_info *b, unsigned int win)
286 outb_p(FEPWIN|win, (int)b->port + 1);
289 static inline void pcxem_memwinoff(struct board_info *b, unsigned int win)
291 outb_p(0, (int)b->port + 1);
294 static inline void pcxem_globalwinon(struct channel *ch)
296 outb_p( FEPWIN, (int)ch->board->port + 1);
299 static inline void pcxem_rxwinon(struct channel *ch)
301 outb_p(ch->rxwin, (int)ch->board->port + 1);
304 static inline void pcxem_txwinon(struct channel *ch)
306 outb_p(ch->txwin, (int)ch->board->port + 1);
309 static inline void pcxem_memoff(struct channel *ch)
311 outb_p(0, (int)ch->board->port + 1);
314 /* ----------------- Begin pcxe memory window stuff ------------------ */
316 static inline void pcxe_memwinon(struct board_info *b, unsigned int win)
318 outb_p(FEPWIN | win, (int)b->port + 1);
321 static inline void pcxe_memwinoff(struct board_info *b, unsigned int win)
323 outb_p(inb((int)b->port) & ~FEPMEM,
325 outb_p(0, (int)b->port + 1);
328 static inline void pcxe_globalwinon(struct channel *ch)
330 outb_p( FEPWIN, (int)ch->board->port + 1);
333 static inline void pcxe_rxwinon(struct channel *ch)
335 outb_p(ch->rxwin, (int)ch->board->port + 1);
338 static inline void pcxe_txwinon(struct channel *ch)
340 outb_p(ch->txwin, (int)ch->board->port + 1);
343 static inline void pcxe_memoff(struct channel *ch)
345 outb_p(0, (int)ch->board->port);
346 outb_p(0, (int)ch->board->port + 1);
349 /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
351 static inline void pcxi_memwinon(struct board_info *b, unsigned int win)
353 outb_p(inb((int)b->port) | FEPMEM, (int)b->port);
356 static inline void pcxi_memwinoff(struct board_info *b, unsigned int win)
358 outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port);
361 static inline void pcxi_globalwinon(struct channel *ch)
363 outb_p(FEPMEM, (int)ch->board->port);
366 static inline void pcxi_rxwinon(struct channel *ch)
368 outb_p(FEPMEM, (int)ch->board->port);
371 static inline void pcxi_txwinon(struct channel *ch)
373 outb_p(FEPMEM, (int)ch->board->port);
376 static inline void pcxi_memoff(struct channel *ch)
378 outb_p(0, (int)ch->board->port);
381 static inline void pcxi_assertgwinon(struct channel *ch)
383 epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off");
386 static inline void pcxi_assertmemoff(struct channel *ch)
388 epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on");
392 /* ----------------------------------------------------------------------
393 Not all of the cards need specific memory windowing routines. Some
394 cards (Such as PCI) needs no windowing routines at all. We provide
395 these do nothing routines so that the same code base can be used.
396 The driver will ALWAYS call a windowing routine if it thinks it needs
397 to; regardless of the card. However, dependent on the card the routine
398 may or may not do anything.
399 ---------------------------------------------------------------------------*/
401 static inline void dummy_memwinon(struct board_info *b, unsigned int win)
405 static inline void dummy_memwinoff(struct board_info *b, unsigned int win)
409 static inline void dummy_globalwinon(struct channel *ch)
413 static inline void dummy_rxwinon(struct channel *ch)
417 static inline void dummy_txwinon(struct channel *ch)
421 static inline void dummy_memoff(struct channel *ch)
425 static inline void dummy_assertgwinon(struct channel *ch)
429 static inline void dummy_assertmemoff(struct channel *ch)
433 /* ----------------- Begin verifyChannel function ----------------------- */
434 static inline struct channel *verifyChannel(register struct tty_struct *tty)
435 { /* Begin verifyChannel */
437 /* --------------------------------------------------------------------
438 This routine basically provides a sanity check. It insures that
439 the channel returned is within the proper range of addresses as
440 well as properly initialized. If some bogus info gets passed in
441 through tty->driver_data this should catch it.
442 --------------------------------------------------------------------- */
447 register struct channel *ch = (struct channel *)tty->driver_data;
449 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs]))
451 if (ch->magic == EPCA_MAGIC)
457 /* Else return a NULL for invalid */
460 } /* End verifyChannel */
462 /* ------------------ Begin pc_sched_event ------------------------- */
464 static inline void pc_sched_event(struct channel *ch, int event)
465 { /* Begin pc_sched_event */
468 /* ----------------------------------------------------------------------
469 We call this to schedule interrupt processing on some event. The
470 kernel sees our request and calls the related routine in OUR driver.
471 -------------------------------------------------------------------------*/
473 ch->event |= 1 << event;
474 schedule_work(&ch->tqueue);
477 } /* End pc_sched_event */
479 /* ------------------ Begin epca_error ------------------------- */
481 static void epca_error(int line, char *msg)
482 { /* Begin epca_error */
484 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
487 } /* End epca_error */
489 /* ------------------ Begin pc_close ------------------------- */
490 static void pc_close(struct tty_struct * tty, struct file * filp)
491 { /* Begin pc_close */
496 /* ---------------------------------------------------------
497 verifyChannel returns the channel from the tty struct
498 if it is valid. This serves as a sanity check.
499 ------------------------------------------------------------- */
501 if ((ch = verifyChannel(tty)) != NULL)
502 { /* Begin if ch != NULL */
507 if (tty_hung_up_p(filp))
509 restore_flags(flags);
513 /* Check to see if the channel is open more than once */
515 { /* Begin channel is open more than once */
517 /* -------------------------------------------------------------
518 Return without doing anything. Someone might still be using
520 ---------------------------------------------------------------- */
522 restore_flags(flags);
524 } /* End channel is open more than once */
526 /* Port open only once go ahead with shutdown & reset */
533 /* ---------------------------------------------------------------
534 Let the rest of the driver know the channel is being closed.
535 This becomes important if an open is attempted before close
537 ------------------------------------------------------------------ */
539 ch->asyncflags |= ASYNC_CLOSING;
543 if (ch->asyncflags & ASYNC_INITIALIZED)
545 /* Setup an event to indicate when the transmit buffer empties */
546 setup_empty_event(tty, ch);
547 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
550 if (tty->driver->flush_buffer)
551 tty->driver->flush_buffer(tty);
553 if (tty->ldisc.flush_buffer)
554 tty->ldisc.flush_buffer(tty);
561 if (ch->blocked_open)
562 { /* Begin if blocked_open */
566 current->state = TASK_INTERRUPTIBLE;
567 schedule_timeout(ch->close_delay);
570 wake_up_interruptible(&ch->open_wait);
572 } /* End if blocked_open */
574 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
576 wake_up_interruptible(&ch->close_wait);
579 restore_flags(flags);
581 } /* End if ch != NULL */
585 /* ------------------ Begin shutdown ------------------------- */
587 static void shutdown(struct channel *ch)
588 { /* Begin shutdown */
591 struct tty_struct *tty;
592 volatile struct board_chan *bc;
594 if (!(ch->asyncflags & ASYNC_INITIALIZED))
603 /* ------------------------------------------------------------------
604 In order for an event to be generated on the receipt of data the
605 idata flag must be set. Since we are shutting down, this is not
606 necessary clear this flag.
607 --------------------------------------------------------------------- */
614 /* ----------------------------------------------------------------
615 If we're a modem control device and HUPCL is on, drop RTS & DTR.
616 ------------------------------------------------------------------ */
618 if (tty->termios->c_cflag & HUPCL)
620 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
621 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
626 /* ------------------------------------------------------------------
627 The channel has officialy been closed. The next time it is opened
628 it will have to reinitialized. Set a flag to indicate this.
629 ---------------------------------------------------------------------- */
631 /* Prevent future Digi programmed interrupts from coming active */
633 ch->asyncflags &= ~ASYNC_INITIALIZED;
634 restore_flags(flags);
638 /* ------------------ Begin pc_hangup ------------------------- */
640 static void pc_hangup(struct tty_struct *tty)
641 { /* Begin pc_hangup */
645 /* ---------------------------------------------------------
646 verifyChannel returns the channel from the tty struct
647 if it is valid. This serves as a sanity check.
648 ------------------------------------------------------------- */
650 if ((ch = verifyChannel(tty)) != NULL)
651 { /* Begin if ch != NULL */
657 if (tty->driver->flush_buffer)
658 tty->driver->flush_buffer(tty);
660 if (tty->ldisc.flush_buffer)
661 tty->ldisc.flush_buffer(tty);
668 restore_flags(flags);
669 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
670 wake_up_interruptible(&ch->open_wait);
672 } /* End if ch != NULL */
674 } /* End pc_hangup */
676 /* ------------------ Begin pc_write ------------------------- */
678 static int pc_write(struct tty_struct * tty, int from_user,
679 const unsigned char *buf, int bytesAvailable)
680 { /* Begin pc_write */
682 register unsigned int head, tail;
683 register int dataLen;
685 register int amountCopied;
691 volatile struct board_chan *bc;
694 /* ----------------------------------------------------------------
695 pc_write is primarily called directly by the kernel routine
696 tty_write (Though it can also be called by put_char) found in
697 tty_io.c. pc_write is passed a line discipline buffer where
698 the data to be written out is stored. The line discipline
699 implementation itself is done at the kernel level and is not
700 brought into the driver.
701 ------------------------------------------------------------------- */
703 /* ---------------------------------------------------------
704 verifyChannel returns the channel from the tty struct
705 if it is valid. This serves as a sanity check.
706 ------------------------------------------------------------- */
708 if ((ch = verifyChannel(tty)) == NULL)
711 /* Make a pointer to the channel data structure found on the board. */
714 size = ch->txbufsize;
717 { /* Begin from_user */
724 /* -----------------------------------------------------------------
725 Anding against size will wrap the pointer back to its beginning
726 position if it is necessary. This will only work if size is
727 a power of 2 which should always be the case. Size is determined
728 by the cards on board FEP/OS.
729 -------------------------------------------------------------------- */
731 /* head refers to the next empty location in which data may be stored */
733 head = bc->tin & (size - 1);
735 /* tail refers to the next data byte to be transmitted */
739 /* Consider changing this to a do statement to make sure */
741 if (tail != bc->tout)
744 /* ------------------------------------------------------------------
745 Anding against size will wrap the pointer back to its beginning
746 position if it is necessary. This will only work if size is
747 a power of 2 which should always be the case. Size is determined
748 by the cards on board FEP/OS.
749 --------------------------------------------------------------------- */
753 /* -----------------------------------------------------------------
754 Two situations can affect how space in the transmit buffer
755 is calculated. You can have a situation where the transmit
756 in pointer (tin) head has wrapped around and actually has a
757 lower address than the transmit out pointer (tout) tail; or
758 the transmit in pointer (tin) head will not be wrapped around
759 yet, and have a higher address than the transmit out pointer
760 (tout) tail. Obviously space available in the transmit buffer
761 is calculated differently for each case.
765 Consider a 10 byte buffer where head is a pointer to the next
766 empty location in the buffer and tail is a pointer to the next
767 byte to transmit. In this example head will not have wrapped
768 around and therefore head > tail.
773 The above diagram shows that buffer locations 2,3,4,5 and 6 have
774 data to be transmitted, while head points at the next empty
775 location. To calculate how much space is available first we have
776 to determine if the head pointer (tin) has wrapped. To do this
777 compare the head pointer to the tail pointer, If head is equal
778 or greater than tail; then it has not wrapped; and the space may
779 be calculated by subtracting tail from head and then subtracting
780 that value from the buffers size. A one is subtracted from the
781 new value to indicate how much space is available between the
782 head pointer and end of buffer; as well as the space between the
783 beginning of the buffer and the tail. If the head is not greater
784 or equal to the tail this indicates that the head has wrapped
785 around to the beginning of the buffer. To calculate the space
786 available in this case simply subtract head from tail. This new
787 value minus one represents the space available betwwen the head
788 and tail pointers. In this example head (7) is greater than tail (2)
789 and therefore has not wrapped around. We find the space by first
790 subtracting tail from head (7-2=5). We then subtract this value
791 from the buffer size of ten and subtract one (10-5-1=4). The space
792 remaining is 4 bytes.
796 Consider a 10 byte buffer where head is a pointer to the next
797 empty location in the buffer and tail is a pointer to the next
798 byte to transmit. In this example head will wrapped around and
799 therefore head < tail.
804 The above diagram shows that buffer locations 7,8,9,0 and 1 have
805 data to be transmitted, while head points at the next empty
806 location. To find the space available we compare head to tail. If
807 head is not equal to, or greater than tail this indicates that head
808 has wrapped around. In this case head (2) is not equal to, or
809 greater than tail (7) and therefore has already wrapped around. To
810 calculate the available space between the two pointers we subtract
811 head from tail (7-2=5). We then subtract one from this new value
812 (5-1=4). We have 5 bytes empty remaining in the buffer. Unlike the
813 previous example these five bytes are located between the head and
816 ----------------------------------------------------------------------- */
818 dataLen = (head >= tail) ? (size - (head - tail) - 1) : (tail - head - 1);
820 /* ----------------------------------------------------------------------
821 In this case bytesAvailable has been passed into pc_write and
822 represents the amount of data that needs to be written. dataLen
823 represents the amount of space available on the card. Whichever
824 value is smaller will be the amount actually written.
825 bytesAvailable will then take on this newly calculated value.
826 ---------------------------------------------------------------------- */
828 bytesAvailable = MIN(dataLen, bytesAvailable);
830 /* First we read the data in from the file system into a temp buffer */
833 restore_flags(flags);
836 { /* Begin bytesAvailable */
838 /* Can the user buffer be accessed at the moment ? */
839 if (verify_area(VERIFY_READ, (char*)buf, bytesAvailable))
840 bytesAvailable = 0; /* Can't do; try again later */
841 else /* Evidently it can, began transmission */
842 { /* Begin if area verified */
843 /* ---------------------------------------------------------------
844 The below function reads data from user memory. This routine
845 can not be used in an interrupt routine. (Because it may
846 generate a page fault) It can only be called while we can the
847 user context is accessible.
850 inline void copy_from_user(void * to, const void * from,
851 unsigned long count);
853 I also think (Check hackers guide) that optimization must
854 be turned ON. (Which sounds strange to me...)
856 Remember copy_from_user WILL generate a page fault if the
857 user memory being accessed has been swapped out. This can
858 cause this routine to temporarily sleep while this page
861 ----------------------------------------------------------------- */
863 if (copy_from_user(ch->tmp_buf, buf,
867 } /* End if area verified */
869 } /* End bytesAvailable */
871 /* ------------------------------------------------------------------
872 Set buf to this address for the moment. tmp_buf was allocated in
874 --------------------------------------------------------------------- */
877 } /* End from_user */
879 /* All data is now local */
887 head = bc->tin & (size - 1);
890 if (tail != bc->tout)
894 /* If head >= tail, head has not wrapped around. */
896 { /* Begin head has not wrapped */
898 /* ---------------------------------------------------------------
899 remain (much like dataLen above) represents the total amount of
900 space available on the card for data. Here dataLen represents
901 the space existing between the head pointer and the end of
902 buffer. This is important because a memcpy cannot be told to
903 automatically wrap around when it hits the buffer end.
904 ------------------------------------------------------------------ */
906 dataLen = size - head;
907 remain = size - (head - tail) - 1;
909 } /* End head has not wrapped */
911 { /* Begin head has wrapped around */
913 remain = tail - head - 1;
916 } /* End head has wrapped around */
918 /* -------------------------------------------------------------------
919 Check the space on the card. If we have more data than
920 space; reduce the amount of data to fit the space.
921 ---------------------------------------------------------------------- */
923 bytesAvailable = MIN(remain, bytesAvailable);
926 while (bytesAvailable > 0)
927 { /* Begin while there is data to copy onto card */
929 /* -----------------------------------------------------------------
930 If head is not wrapped, the below will make sure the first
931 data copy fills to the end of card buffer.
932 ------------------------------------------------------------------- */
934 dataLen = MIN(bytesAvailable, dataLen);
935 memcpy(ch->txptr + head, buf, dataLen);
938 amountCopied += dataLen;
939 bytesAvailable -= dataLen;
947 } /* End while there is data to copy onto card */
949 ch->statusflags |= TXBUSY;
953 if ((ch->statusflags & LOWWAIT) == 0)
955 ch->statusflags |= LOWWAIT;
959 restore_flags(flags);
961 return(amountCopied);
965 /* ------------------ Begin pc_put_char ------------------------- */
967 static void pc_put_char(struct tty_struct *tty, unsigned char c)
968 { /* Begin pc_put_char */
971 pc_write(tty, 0, &c, 1);
974 } /* End pc_put_char */
976 /* ------------------ Begin pc_write_room ------------------------- */
978 static int pc_write_room(struct tty_struct *tty)
979 { /* Begin pc_write_room */
984 unsigned int head, tail;
985 volatile struct board_chan *bc;
989 /* ---------------------------------------------------------
990 verifyChannel returns the channel from the tty struct
991 if it is valid. This serves as a sanity check.
992 ------------------------------------------------------------- */
994 if ((ch = verifyChannel(tty)) != NULL)
1001 head = bc->tin & (ch->txbufsize - 1);
1004 if (tail != bc->tout)
1006 /* Wrap tail if necessary */
1007 tail &= (ch->txbufsize - 1);
1009 if ((remain = tail - head - 1) < 0 )
1010 remain += ch->txbufsize;
1012 if (remain && (ch->statusflags & LOWWAIT) == 0)
1014 ch->statusflags |= LOWWAIT;
1018 restore_flags(flags);
1021 /* Return how much room is left on card */
1024 } /* End pc_write_room */
1026 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
1028 static int pc_chars_in_buffer(struct tty_struct *tty)
1029 { /* Begin pc_chars_in_buffer */
1032 unsigned int ctail, head, tail;
1034 unsigned long flags;
1036 volatile struct board_chan *bc;
1039 /* ---------------------------------------------------------
1040 verifyChannel returns the channel from the tty struct
1041 if it is valid. This serves as a sanity check.
1042 ------------------------------------------------------------- */
1044 if ((ch = verifyChannel(tty)) == NULL)
1054 ctail = ch->mailbox->cout;
1056 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
1059 { /* Begin if some space on the card has been used */
1061 head = bc->tin & (ch->txbufsize - 1);
1062 tail &= (ch->txbufsize - 1);
1064 /* --------------------------------------------------------------
1065 The logic here is basically opposite of the above pc_write_room
1066 here we are finding the amount of bytes in the buffer filled.
1067 Not the amount of bytes empty.
1068 ------------------------------------------------------------------- */
1070 if ((remain = tail - head - 1) < 0 )
1071 remain += ch->txbufsize;
1073 chars = (int)(ch->txbufsize - remain);
1075 /* -------------------------------------------------------------
1076 Make it possible to wakeup anything waiting for output
1077 in tty_ioctl.c, etc.
1079 If not already set. Setup an event to indicate when the
1080 transmit buffer empties
1081 ----------------------------------------------------------------- */
1083 if (!(ch->statusflags & EMPTYWAIT))
1084 setup_empty_event(tty,ch);
1086 } /* End if some space on the card has been used */
1089 restore_flags(flags);
1091 /* Return number of characters residing on card. */
1094 } /* End pc_chars_in_buffer */
1096 /* ------------------ Begin pc_flush_buffer ---------------------- */
1098 static void pc_flush_buffer(struct tty_struct *tty)
1099 { /* Begin pc_flush_buffer */
1102 unsigned long flags;
1104 volatile struct board_chan *bc;
1107 /* ---------------------------------------------------------
1108 verifyChannel returns the channel from the tty struct
1109 if it is valid. This serves as a sanity check.
1110 ------------------------------------------------------------- */
1112 if ((ch = verifyChannel(tty)) == NULL)
1123 /* Have FEP move tout pointer; effectively flushing transmit buffer */
1125 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
1128 restore_flags(flags);
1130 wake_up_interruptible(&tty->write_wait);
1131 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1132 (tty->ldisc.write_wakeup)(tty);
1134 } /* End pc_flush_buffer */
1136 /* ------------------ Begin pc_flush_chars ---------------------- */
1138 static void pc_flush_chars(struct tty_struct *tty)
1139 { /* Begin pc_flush_chars */
1141 struct channel * ch;
1143 /* ---------------------------------------------------------
1144 verifyChannel returns the channel from the tty struct
1145 if it is valid. This serves as a sanity check.
1146 ------------------------------------------------------------- */
1148 if ((ch = verifyChannel(tty)) != NULL)
1150 unsigned long flags;
1155 /* ----------------------------------------------------------------
1156 If not already set and the transmitter is busy setup an event
1157 to indicate when the transmit empties.
1158 ------------------------------------------------------------------- */
1160 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
1161 setup_empty_event(tty,ch);
1163 restore_flags(flags);
1166 } /* End pc_flush_chars */
1168 /* ------------------ Begin block_til_ready ---------------------- */
1170 static int block_til_ready(struct tty_struct *tty,
1171 struct file *filp, struct channel *ch)
1172 { /* Begin block_til_ready */
1174 DECLARE_WAITQUEUE(wait,current);
1175 int retval, do_clocal = 0;
1176 unsigned long flags;
1179 if (tty_hung_up_p(filp))
1181 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1184 retval = -ERESTARTSYS;
1188 /* -----------------------------------------------------------------
1189 If the device is in the middle of being closed, then block
1190 until it's done, and then try again.
1191 -------------------------------------------------------------------- */
1192 if (ch->asyncflags & ASYNC_CLOSING)
1194 interruptible_sleep_on(&ch->close_wait);
1196 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1199 return -ERESTARTSYS;
1202 if (filp->f_flags & O_NONBLOCK)
1204 /* -----------------------------------------------------------------
1205 If non-blocking mode is set, then make the check up front
1207 -------------------------------------------------------------------- */
1209 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1215 if (tty->termios->c_cflag & CLOCAL)
1218 /* Block waiting for the carrier detect and the line to become free */
1221 add_wait_queue(&ch->open_wait, &wait);
1226 /* We dec count so that pc_close will know when to free things */
1227 if (!tty_hung_up_p(filp))
1230 restore_flags(flags);
1235 { /* Begin forever while */
1237 set_current_state(TASK_INTERRUPTIBLE);
1239 if (tty_hung_up_p(filp) ||
1240 !(ch->asyncflags & ASYNC_INITIALIZED))
1242 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1245 retval = -ERESTARTSYS;
1249 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1250 (do_clocal || (ch->imodem & ch->dcd)))
1253 if (signal_pending(current))
1255 retval = -ERESTARTSYS;
1259 /* ---------------------------------------------------------------
1260 Allow someone else to be scheduled. We will occasionally go
1261 through this loop until one of the above conditions change.
1262 The below schedule call will allow other processes to enter and
1263 prevent this loop from hogging the cpu.
1264 ------------------------------------------------------------------ */
1267 } /* End forever while */
1269 current->state = TASK_RUNNING;
1270 remove_wait_queue(&ch->open_wait, &wait);
1272 if (!tty_hung_up_p(filp))
1274 restore_flags(flags);
1281 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1285 } /* End block_til_ready */
1287 /* ------------------ Begin pc_open ---------------------- */
1289 static int pc_open(struct tty_struct *tty, struct file * filp)
1290 { /* Begin pc_open */
1293 unsigned long flags;
1294 int line, retval, boardnum;
1295 volatile struct board_chan *bc;
1296 volatile unsigned int head;
1299 if (line < 0 || line >= nbdevs)
1301 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1302 tty->driver_data = NULL;
1307 ch = &digi_channels[line];
1308 boardnum = ch->boardnum;
1310 /* Check status of board configured in system. */
1312 /* -----------------------------------------------------------------
1313 I check to see if the epca_setup routine detected an user error.
1314 It might be better to put this in pc_init, but for the moment it
1316 ---------------------------------------------------------------------- */
1318 if (invalid_lilo_config)
1320 if (setup_error_code & INVALID_BOARD_TYPE)
1321 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n");
1323 if (setup_error_code & INVALID_NUM_PORTS)
1324 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1326 if (setup_error_code & INVALID_MEM_BASE)
1327 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1329 if (setup_error_code & INVALID_PORT_BASE)
1330 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n");
1332 if (setup_error_code & INVALID_BOARD_STATUS)
1333 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n");
1335 if (setup_error_code & INVALID_ALTPIN)
1336 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1338 tty->driver_data = NULL; /* Mark this device as 'down' */
1342 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1344 tty->driver_data = NULL; /* Mark this device as 'down' */
1348 if (( bc = ch->brdchan) == 0)
1350 tty->driver_data = NULL;
1354 /* ------------------------------------------------------------------
1355 Every time a channel is opened, increment a counter. This is
1356 necessary because we do not wish to flush and shutdown the channel
1357 until the last app holding the channel open, closes it.
1358 --------------------------------------------------------------------- */
1362 /* ----------------------------------------------------------------
1363 Set a kernel structures pointer to our local channel
1364 structure. This way we can get to it when passed only
1366 ------------------------------------------------------------------ */
1368 tty->driver_data = ch;
1370 /* ----------------------------------------------------------------
1371 If this is the first time the channel has been opened, initialize
1372 the tty->termios struct otherwise let pc_close handle it.
1373 -------------------------------------------------------------------- */
1379 ch->statusflags = 0;
1381 /* Save boards current modem status */
1382 ch->imodem = bc->mstat;
1384 /* ----------------------------------------------------------------
1385 Set receive head and tail ptrs to each other. This indicates
1386 no data available to read.
1387 ----------------------------------------------------------------- */
1391 /* Set the channels associated tty structure */
1394 /* -----------------------------------------------------------------
1395 The below routine generally sets up parity, baud, flow control
1396 issues, etc.... It effect both control flags and input flags.
1397 -------------------------------------------------------------------- */
1400 ch->asyncflags |= ASYNC_INITIALIZED;
1403 restore_flags(flags);
1405 retval = block_til_ready(tty, filp, ch);
1411 /* -------------------------------------------------------------
1412 Set this again in case a hangup set it to zero while this
1413 open() was waiting for the line...
1414 --------------------------------------------------------------- */
1421 /* Enable Digi Data events */
1425 restore_flags(flags);
1432 static int __init epca_module_init(void)
1433 { /* Begin init_module */
1435 unsigned long flags;
1442 restore_flags(flags);
1447 module_init(epca_module_init);
1451 static struct pci_driver epca_driver;
1455 /* -------------------- Begin cleanup_module ---------------------- */
1457 static void __exit epca_module_exit(void)
1461 struct board_info *bd;
1463 unsigned long flags;
1465 del_timer_sync(&epca_timer);
1470 if ((tty_unregister_driver(pc_driver)) ||
1471 (tty_unregister_driver(pc_info)))
1473 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1474 restore_flags(flags);
1477 put_tty_driver(pc_driver);
1478 put_tty_driver(pc_info);
1480 for (crd = 0; crd < num_cards; crd++)
1481 { /* Begin for each card */
1486 { /* Begin sanity check */
1487 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1489 } /* End sanity check */
1493 for (count = 0; count < bd->numports; count++, ch++)
1494 { /* Begin for each port */
1499 tty_hangup(ch->tty);
1503 } /* End for each port */
1504 } /* End for each card */
1507 pci_unregister_driver (&epca_driver);
1510 restore_flags(flags);
1513 module_exit(epca_module_exit);
1516 static struct tty_operations pc_ops = {
1520 .write_room = pc_write_room,
1521 .flush_buffer = pc_flush_buffer,
1522 .chars_in_buffer = pc_chars_in_buffer,
1523 .flush_chars = pc_flush_chars,
1524 .put_char = pc_put_char,
1526 .set_termios = pc_set_termios,
1529 .throttle = pc_throttle,
1530 .unthrottle = pc_unthrottle,
1531 .hangup = pc_hangup,
1534 static int info_open(struct tty_struct *tty, struct file * filp)
1539 static struct tty_operations info_ops = {
1541 .ioctl = info_ioctl,
1544 /* ------------------ Begin pc_init ---------------------- */
1546 int __init pc_init(void)
1547 { /* Begin pc_init */
1549 /* ----------------------------------------------------------------
1550 pc_init is called by the operating system during boot up prior to
1551 any open calls being made. In the older versions of Linux (Prior
1552 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1553 memory location (from kernel space) used (kmem_start) is passed
1554 to pc_init. It is pc_inits responsibility to modify this value
1555 for any memory that the Digi driver might need and then return
1556 this value to the operating system. For example if the driver
1557 wishes to allocate 1K of kernel memory, pc_init would return
1558 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1559 + 1024) would then be available for use exclusively by the driver.
1560 In this case our driver does not allocate any of this kernel
1562 ------------------------------------------------------------------*/
1566 struct board_info *bd;
1567 unsigned char board_id = 0;
1570 int pci_boards_found, pci_count;
1573 #endif /* ENABLE_PCI */
1575 pc_driver = alloc_tty_driver(MAX_ALLOC);
1579 pc_info = alloc_tty_driver(MAX_ALLOC);
1581 put_tty_driver(pc_driver);
1585 /* -----------------------------------------------------------------------
1586 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1587 board structure defined by digiConfig into drivers board structure.
1588 Note : If LILO has ran epca_setup then epca_setup will handle defining
1589 num_cards as well as copying the data into the board structure.
1590 -------------------------------------------------------------------------- */
1592 { /* Begin driver has been configured via. epcaconfig */
1595 num_cards = NUMCARDS;
1596 memcpy((void *)&boards, (void *)&static_boards,
1597 (sizeof(struct board_info) * NUMCARDS));
1598 } /* End driver has been configured via. epcaconfig */
1600 /* -----------------------------------------------------------------
1601 Note : If lilo was used to configure the driver and the
1602 ignore epcaconfig option was choosen (digiepca=2) then
1603 nbdevs and num_cards will equal 0 at this point. This is
1604 okay; PCI cards will still be picked up if detected.
1605 --------------------------------------------------------------------- */
1607 /* -----------------------------------------------------------
1608 Set up interrupt, we will worry about memory allocation in
1610 --------------------------------------------------------------- */
1613 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1617 /* ------------------------------------------------------------------
1618 NOTE : This code assumes that the number of ports found in
1619 the boards array is correct. This could be wrong if
1620 the card in question is PCI (And therefore has no ports
1621 entry in the boards structure.) The rest of the
1622 information will be valid for PCI because the beginning
1623 of pc_init scans for PCI and determines i/o and base
1624 memory addresses. I am not sure if it is possible to
1625 read the number of ports supported by the card prior to
1626 it being booted (Since that is the state it is in when
1627 pc_init is run). Because it is not possible to query the
1628 number of supported ports until after the card has booted;
1629 we are required to calculate the card_ptrs as the card is
1630 is initialized (Inside post_fep_init). The negative thing
1631 about this approach is that digiDload's call to GET_INFO
1632 will have a bad port value. (Since this is called prior
1635 --------------------------------------------------------------------- */
1637 pci_boards_found = 0;
1638 if(num_cards < MAXBOARDS)
1639 pci_boards_found += init_PCI();
1640 num_cards += pci_boards_found;
1642 #endif /* ENABLE_PCI */
1644 pc_driver->owner = THIS_MODULE;
1645 pc_driver->name = "ttyD";
1646 pc_driver->major = DIGI_MAJOR;
1647 pc_driver->minor_start = 0;
1648 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1649 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1650 pc_driver->init_termios = tty_std_termios;
1651 pc_driver->init_termios.c_iflag = 0;
1652 pc_driver->init_termios.c_oflag = 0;
1653 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1654 pc_driver->init_termios.c_lflag = 0;
1655 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1656 tty_set_operations(pc_driver, &pc_ops);
1658 pc_info->owner = THIS_MODULE;
1659 pc_info->name = "digi_ctl";
1660 pc_info->major = DIGIINFOMAJOR;
1661 pc_info->minor_start = 0;
1662 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1663 pc_info->subtype = SERIAL_TYPE_INFO;
1664 pc_info->init_termios = tty_std_termios;
1665 pc_info->init_termios.c_iflag = 0;
1666 pc_info->init_termios.c_oflag = 0;
1667 pc_info->init_termios.c_lflag = 0;
1668 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1669 pc_info->flags = TTY_DRIVER_REAL_RAW;
1670 tty_set_operations(pc_info, &info_ops);
1676 for (crd = 0; crd < num_cards; crd++)
1677 { /* Begin for each card */
1679 /* ------------------------------------------------------------------
1680 This is where the appropriate memory handlers for the hardware is
1681 set. Everything at runtime blindly jumps through these vectors.
1682 ---------------------------------------------------------------------- */
1684 /* defined in epcaconfig.h */
1688 { /* Begin switch on bd->type {board type} */
1691 bd->memwinon = pcxem_memwinon ;
1692 bd->memwinoff = pcxem_memwinoff ;
1693 bd->globalwinon = pcxem_globalwinon ;
1694 bd->txwinon = pcxem_txwinon ;
1695 bd->rxwinon = pcxem_rxwinon ;
1696 bd->memoff = pcxem_memoff ;
1697 bd->assertgwinon = dummy_assertgwinon;
1698 bd->assertmemoff = dummy_assertmemoff;
1704 bd->memwinon = dummy_memwinon;
1705 bd->memwinoff = dummy_memwinoff;
1706 bd->globalwinon = dummy_globalwinon;
1707 bd->txwinon = dummy_txwinon;
1708 bd->rxwinon = dummy_rxwinon;
1709 bd->memoff = dummy_memoff;
1710 bd->assertgwinon = dummy_assertgwinon;
1711 bd->assertmemoff = dummy_assertmemoff;
1717 bd->memwinon = pcxe_memwinon;
1718 bd->memwinoff = pcxe_memwinoff;
1719 bd->globalwinon = pcxe_globalwinon;
1720 bd->txwinon = pcxe_txwinon;
1721 bd->rxwinon = pcxe_rxwinon;
1722 bd->memoff = pcxe_memoff;
1723 bd->assertgwinon = dummy_assertgwinon;
1724 bd->assertmemoff = dummy_assertmemoff;
1730 bd->memwinon = pcxi_memwinon;
1731 bd->memwinoff = pcxi_memwinoff;
1732 bd->globalwinon = pcxi_globalwinon;
1733 bd->txwinon = pcxi_txwinon;
1734 bd->rxwinon = pcxi_rxwinon;
1735 bd->memoff = pcxi_memoff;
1736 bd->assertgwinon = pcxi_assertgwinon;
1737 bd->assertmemoff = pcxi_assertmemoff;
1743 } /* End switch on bd->type */
1745 /* ---------------------------------------------------------------
1746 Some cards need a memory segment to be defined for use in
1747 transmit and receive windowing operations. These boards
1748 are listed in the below switch. In the case of the XI the
1749 amount of memory on the board is variable so the memory_seg
1750 is also variable. This code determines what they segment
1752 ----------------------------------------------------------------- */
1755 { /* Begin switch on bd->type {board type} */
1760 bd->memory_seg = 0xf000;
1764 board_id = inb((int)bd->port);
1765 if ((board_id & 0x1) == 0x1)
1766 { /* Begin it's an XI card */
1768 /* Is it a 64K board */
1769 if ((board_id & 0x30) == 0)
1770 bd->memory_seg = 0xf000;
1772 /* Is it a 128K board */
1773 if ((board_id & 0x30) == 0x10)
1774 bd->memory_seg = 0xe000;
1776 /* Is is a 256K board */
1777 if ((board_id & 0x30) == 0x20)
1778 bd->memory_seg = 0xc000;
1780 /* Is it a 512K board */
1781 if ((board_id & 0x30) == 0x30)
1782 bd->memory_seg = 0x8000;
1784 } /* End it is an XI card */
1787 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1791 } /* End switch on bd->type */
1793 } /* End for each card */
1795 if (tty_register_driver(pc_driver))
1796 panic("Couldn't register Digi PC/ driver");
1798 if (tty_register_driver(pc_info))
1799 panic("Couldn't register Digi PC/ info ");
1801 /* -------------------------------------------------------------------
1802 Start up the poller to check for events on all enabled boards
1803 ---------------------------------------------------------------------- */
1805 init_timer(&epca_timer);
1806 epca_timer.function = epcapoll;
1807 mod_timer(&epca_timer, jiffies + HZ/25);
1809 restore_flags(flags);
1815 /* ------------------ Begin post_fep_init ---------------------- */
1817 static void post_fep_init(unsigned int crd)
1818 { /* Begin post_fep_init */
1822 volatile struct global_data *gd;
1823 struct board_info *bd;
1824 volatile struct board_chan *bc;
1826 int shrinkmem = 0, lowwater ;
1828 /* -------------------------------------------------------------
1829 This call is made by the user via. the ioctl call DIGI_INIT.
1830 It is responsible for setting up all the card specific stuff.
1831 ---------------------------------------------------------------- */
1834 /* -----------------------------------------------------------------
1835 If this is a PCI board, get the port info. Remember PCI cards
1836 do not have entries into the epcaconfig.h file, so we can't get
1837 the number of ports from it. Unfortunetly, this means that anyone
1838 doing a DIGI_GETINFO before the board has booted will get an invalid
1839 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1840 after DIGI_INIT has been called will return the proper values.
1841 ------------------------------------------------------------------- */
1843 if (bd->type >= PCIXEM) /* If the board in question is PCI */
1844 { /* Begin get PCI number of ports */
1846 /* --------------------------------------------------------------------
1847 Below we use XEMPORTS as a memory offset regardless of which PCI
1848 card it is. This is because all of the supported PCI cards have
1849 the same memory offset for the channel data. This will have to be
1850 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1851 states that the port offset is 0xC22 as opposed to 0xC02. This is
1852 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1853 On the PCI cards the number of ports is determined by reading a
1854 ID PROM located in the box attached to the card. The card can then
1855 determine the index the id to determine the number of ports available.
1856 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1857 if the box in question is a XEM or CX)).
1858 ------------------------------------------------------------------------ */
1860 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1861 (bd->re_map_membase + XEMPORTS));
1864 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1865 nbdevs += (bd->numports);
1867 } /* End get PCI number of ports */
1870 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1872 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1877 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1879 memaddr = (unchar *)bd->re_map_membase;
1882 The below command is necessary because newer kernels (2.1.x and
1883 up) do not have a 1:1 virtual to physical mapping. The below
1884 call adjust for that.
1887 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
1889 /* -----------------------------------------------------------------
1890 The below assignment will set bc to point at the BEGINING of
1891 the cards channel structures. For 1 card there will be between
1892 8 and 64 of these structures.
1893 -------------------------------------------------------------------- */
1895 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
1897 /* -------------------------------------------------------------------
1898 The below assignment will set gd to point at the BEGINING of
1899 global memory address 0xc00. The first data in that global
1900 memory actually starts at address 0xc1a. The command in
1901 pointer begins at 0xd10.
1902 ---------------------------------------------------------------------- */
1904 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
1906 /* --------------------------------------------------------------------
1907 XEPORTS (address 0xc22) points at the number of channels the
1908 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1909 ----------------------------------------------------------------------- */
1911 if (((bd->type == PCXEVE) | (bd->type == PCXE)) &&
1912 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
1914 if (bd->type < PCIXEM)
1915 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1920 /* --------------------------------------------------------------------
1921 Remember ch is the main drivers channels structure, while bc is
1922 the cards channel structure.
1923 ------------------------------------------------------------------------ */
1925 /* For every port on the card do ..... */
1927 for (i = 0; i < bd->numports; i++, ch++, bc++)
1928 { /* Begin for each port */
1932 INIT_WORK(&ch->tqueue, do_softint, ch);
1933 ch->board = &boards[crd];
1936 { /* Begin switch bd->type */
1938 /* ----------------------------------------------------------------
1939 Since some of the boards use different bitmaps for their
1940 control signals we cannot hard code these values and retain
1941 portability. We virtualize this data here.
1942 ------------------------------------------------------------------- */
1968 } /* End switch bd->type */
1970 if (boards[crd].altpin)
1972 ch->dsr = ch->m_dcd;
1973 ch->dcd = ch->m_dsr;
1974 ch->digiext.digi_flags |= DIGI_ALTPIN;
1978 ch->dcd = ch->m_dcd;
1979 ch->dsr = ch->m_dsr;
1984 ch->magic = EPCA_MAGIC;
1989 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1994 { /* Begin switch bd->type */
1999 /* Cover all the 2MEG cards */
2000 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff);
2001 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff);
2002 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2003 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2008 /* Cover all the 32K windowed cards */
2009 /* Mask equal to window size - 1 */
2010 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff);
2011 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff);
2012 ch->txwin = FEPWIN | ((bc->tseg) >> 11);
2013 ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
2018 ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff);
2019 ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9);
2020 ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff);
2021 ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 );
2026 ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4);
2027 ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4);
2028 ch->txwin = ch->rxwin = 0;
2031 } /* End switch bd->type */
2034 ch->txbufsize = bc->tmax + 1;
2037 ch->rxbufsize = bc->rmax + 1;
2039 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
2041 /* Set transmitter low water mark */
2042 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
2044 /* Set receiver low water mark */
2046 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
2048 /* Set receiver high water mark */
2050 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
2055 ch->startc = bc->startc;
2056 ch->stopc = bc->stopc;
2057 ch->startca = bc->startca;
2058 ch->stopca = bc->stopca;
2068 ch->close_delay = 50;
2070 ch->blocked_open = 0;
2071 init_waitqueue_head(&ch->open_wait);
2072 init_waitqueue_head(&ch->close_wait);
2073 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
2076 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
2077 release_region((int)bd->port, 4);
2079 kfree((ch--)->tmp_buf);
2083 memset((void *)ch->tmp_buf,0,ch->txbufsize);
2084 } /* End for each port */
2087 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2088 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2090 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
2091 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
2092 console_print(mesg);
2096 } /* End post_fep_init */
2098 /* --------------------- Begin epcapoll ------------------------ */
2100 static void epcapoll(unsigned long ignored)
2101 { /* Begin epcapoll */
2103 unsigned long flags;
2105 volatile unsigned int head, tail;
2107 struct board_info *bd;
2109 /* -------------------------------------------------------------------
2110 This routine is called upon every timer interrupt. Even though
2111 the Digi series cards are capable of generating interrupts this
2112 method of non-looping polling is more efficient. This routine
2113 checks for card generated events (Such as receive data, are transmit
2114 buffer empty) and acts on those events.
2115 ----------------------------------------------------------------------- */
2120 for (crd = 0; crd < num_cards; crd++)
2121 { /* Begin for each card */
2126 if ((bd->status == DISABLED) || digi_poller_inhibited)
2127 continue; /* Begin loop next interation */
2129 /* -----------------------------------------------------------
2130 assertmemoff is not needed here; indeed it is an empty subroutine.
2131 It is being kept because future boards may need this as well as
2133 ---------------------------------------------------------------- */
2139 /* ---------------------------------------------------------------
2140 In this case head and tail actually refer to the event queue not
2141 the transmit or receive queue.
2142 ------------------------------------------------------------------- */
2144 head = ch->mailbox->ein;
2145 tail = ch->mailbox->eout;
2147 /* If head isn't equal to tail we have an event */
2154 } /* End for each card */
2156 mod_timer(&epca_timer, jiffies + (HZ / 25));
2158 restore_flags(flags);
2159 } /* End epcapoll */
2161 /* --------------------- Begin doevent ------------------------ */
2163 static void doevent(int crd)
2164 { /* Begin doevent */
2166 volatile unchar *eventbuf;
2167 struct channel *ch, *chan0;
2168 static struct tty_struct *tty;
2169 volatile struct board_info *bd;
2170 volatile struct board_chan *bc;
2171 register volatile unsigned int tail, head;
2172 register int event, channel;
2173 register int mstat, lstat;
2175 /* -------------------------------------------------------------------
2176 This subroutine is called by epcapoll when an event is detected
2177 in the event queue. This routine responds to those events.
2178 --------------------------------------------------------------------- */
2182 chan0 = card_ptr[crd];
2183 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2185 assertgwinon(chan0);
2187 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2188 { /* Begin while something in event queue */
2190 assertgwinon(chan0);
2192 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2194 /* Get the channel the event occurred on */
2195 channel = eventbuf[0];
2197 /* Get the actual event code that occurred */
2198 event = eventbuf[1];
2200 /* ----------------------------------------------------------------
2201 The two assignments below get the current modem status (mstat)
2202 and the previous modem status (lstat). These are useful becuase
2203 an event could signal a change in modem signals itself.
2204 ------------------------------------------------------------------- */
2206 mstat = eventbuf[2];
2207 lstat = eventbuf[3];
2209 ch = chan0 + channel;
2211 if ((unsigned)channel >= bd->numports || !ch)
2213 if (channel >= bd->numports)
2219 if ((bc = ch->brdchan) == NULL)
2222 if (event & DATA_IND)
2223 { /* Begin DATA_IND */
2228 } /* End DATA_IND */
2229 /* else *//* Fix for DCD transition missed bug */
2230 if (event & MODEMCHG_IND)
2231 { /* Begin MODEMCHG_IND */
2233 /* A modem signal change has been indicated */
2237 if (ch->asyncflags & ASYNC_CHECK_CD)
2239 if (mstat & ch->dcd) /* We are now receiving dcd */
2240 wake_up_interruptible(&ch->open_wait);
2242 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2245 } /* End MODEMCHG_IND */
2249 { /* Begin if valid tty */
2251 if (event & BREAK_IND)
2252 { /* Begin if BREAK_IND */
2254 /* A break has been indicated */
2257 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2259 *tty->flip.char_buf_ptr++ = 0;
2261 tty_schedule_flip(tty);
2263 } /* End if BREAK_IND */
2265 if (event & LOWTX_IND)
2266 { /* Begin LOWTX_IND */
2268 if (ch->statusflags & LOWWAIT)
2269 { /* Begin if LOWWAIT */
2271 ch->statusflags &= ~LOWWAIT;
2272 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2273 tty->ldisc.write_wakeup)
2274 (tty->ldisc.write_wakeup)(tty);
2275 wake_up_interruptible(&tty->write_wait);
2277 } /* End if LOWWAIT */
2279 } /* End LOWTX_IND */
2281 if (event & EMPTYTX_IND)
2282 { /* Begin EMPTYTX_IND */
2284 /* This event is generated by setup_empty_event */
2286 ch->statusflags &= ~TXBUSY;
2287 if (ch->statusflags & EMPTYWAIT)
2288 { /* Begin if EMPTYWAIT */
2290 ch->statusflags &= ~EMPTYWAIT;
2291 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2292 tty->ldisc.write_wakeup)
2293 (tty->ldisc.write_wakeup)(tty);
2295 wake_up_interruptible(&tty->write_wait);
2297 } /* End if EMPTYWAIT */
2299 } /* End EMPTYTX_IND */
2301 } /* End if valid tty */
2308 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n");
2312 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2315 } /* End while something in event queue */
2319 /* --------------------- Begin fepcmd ------------------------ */
2321 static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2322 int byte2, int ncmds, int bytecmd)
2323 { /* Begin fepcmd */
2326 unsigned int head, cmdTail, cmdStart, cmdMax;
2330 /* This is the routine in which commands may be passed to the card. */
2332 if (ch->board->status == DISABLED)
2339 /* Remember head (As well as max) is just an offset not a base addr */
2340 head = ch->mailbox->cin;
2342 /* cmdStart is a base address */
2343 cmdStart = ch->mailbox->cstart;
2345 /* ------------------------------------------------------------------
2346 We do the addition below because we do not want a max pointer
2347 relative to cmdStart. We want a max pointer that points at the
2348 physical end of the command queue.
2349 -------------------------------------------------------------------- */
2351 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2353 memaddr = ch->board->re_map_membase;
2356 The below command is necessary because newer kernels (2.1.x and
2357 up) do not have a 1:1 virtual to physical mapping. The below
2358 call adjust for that.
2361 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2363 if (head >= (cmdMax - cmdStart) || (head & 03))
2365 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2367 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2374 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2376 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2377 /* Below word_or_byte is bits to set */
2378 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte;
2379 /* Below byte2 is bits to reset */
2380 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2;
2385 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2386 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2387 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2390 head = (head + 4) & (cmdMax - cmdStart - 4);
2391 ch->mailbox->cin = head;
2396 { /* Begin forever loop */
2401 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2405 head = ch->mailbox->cin;
2406 cmdTail = ch->mailbox->cout;
2408 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2410 /* ----------------------------------------------------------
2411 Basically this will break when the FEP acknowledges the
2412 command by incrementing cmdTail (Making it equal to head).
2413 ------------------------------------------------------------- */
2415 if (n <= ncmds * (sizeof(short) * 4))
2416 break; /* Well nearly forever :-) */
2418 } /* End forever loop */
2422 /* ---------------------------------------------------------------------
2423 Digi products use fields in their channels structures that are very
2424 similar to the c_cflag and c_iflag fields typically found in UNIX
2425 termios structures. The below three routines allow mappings
2426 between these hardware "flags" and their respective Linux flags.
2427 ------------------------------------------------------------------------- */
2429 /* --------------------- Begin termios2digi_h -------------------- */
2431 static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2432 { /* Begin termios2digi_h */
2436 if (cflag & CRTSCTS)
2438 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2439 res |= ((ch->m_cts) | (ch->m_rts));
2442 if (ch->digiext.digi_flags & RTSPACE)
2445 if (ch->digiext.digi_flags & DTRPACE)
2448 if (ch->digiext.digi_flags & CTSPACE)
2451 if (ch->digiext.digi_flags & DSRPACE)
2454 if (ch->digiext.digi_flags & DCDPACE)
2457 if (res & (ch->m_rts))
2458 ch->digiext.digi_flags |= RTSPACE;
2460 if (res & (ch->m_cts))
2461 ch->digiext.digi_flags |= CTSPACE;
2465 } /* End termios2digi_h */
2467 /* --------------------- Begin termios2digi_i -------------------- */
2468 static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2469 { /* Begin termios2digi_i */
2471 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2472 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2474 if (ch->digiext.digi_flags & DIGI_AIXON)
2478 } /* End termios2digi_i */
2480 /* --------------------- Begin termios2digi_c -------------------- */
2482 static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2483 { /* Begin termios2digi_c */
2488 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2489 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2490 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2491 #endif /* SPEED_HACK */
2493 if (cflag & CBAUDEX)
2494 { /* Begin detected CBAUDEX */
2496 ch->digiext.digi_flags |= DIGI_FAST;
2498 /* -------------------------------------------------------------
2499 HUPCL bit is used by FEP to indicate fast baud
2500 table is to be used.
2501 ----------------------------------------------------------------- */
2505 } /* End detected CBAUDEX */
2506 else ch->digiext.digi_flags &= ~DIGI_FAST;
2508 /* -------------------------------------------------------------------
2509 CBAUD has bit position 0x1000 set these days to indicate Linux
2510 baud rate remap. Digi hardware can't handle the bit assignment.
2511 (We use a different bit assignment for high speed.). Clear this
2513 ---------------------------------------------------------------------- */
2514 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2516 /* -------------------------------------------------------------
2517 This gets a little confusing. The Digi cards have their own
2518 representation of c_cflags controling baud rate. For the most
2519 part this is identical to the Linux implementation. However;
2520 Digi supports one rate (76800) that Linux doesn't. This means
2521 that the c_cflag entry that would normally mean 76800 for Digi
2522 actually means 115200 under Linux. Without the below mapping,
2523 a stty 115200 would only drive the board at 76800. Since
2524 the rate 230400 is also found after 76800, the same problem afflicts
2525 us when we choose a rate of 230400. Without the below modificiation
2526 stty 230400 would actually give us 115200.
2528 There are two additional differences. The Linux value for CLOCAL
2529 (0x800; 0004000) has no meaning to the Digi hardware. Also in
2530 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
2531 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
2532 should be checked for a screened out prior to termios2digi_c
2533 returning. Since CLOCAL isn't used by the board this can be
2534 ignored as long as the returned value is used only by Digi hardware.
2535 ----------------------------------------------------------------- */
2537 if (cflag & CBAUDEX)
2539 /* -------------------------------------------------------------
2540 The below code is trying to guarantee that only baud rates
2541 115200 and 230400 are remapped. We use exclusive or because
2542 the various baud rates share common bit positions and therefore
2543 can't be tested for easily.
2544 ----------------------------------------------------------------- */
2547 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2548 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2556 } /* End termios2digi_c */
2558 /* --------------------- Begin epcaparam ----------------------- */
2560 static void epcaparam(struct tty_struct *tty, struct channel *ch)
2561 { /* Begin epcaparam */
2563 unsigned int cmdHead;
2565 volatile struct board_chan *bc;
2566 unsigned mval, hflow, cflag, iflag;
2569 epcaassert(bc !=0, "bc out of range");
2575 if ((ts->c_cflag & CBAUD) == 0)
2576 { /* Begin CBAUD detected */
2582 /* Changing baud in mid-stream transmission can be wonderful */
2583 /* ---------------------------------------------------------------
2584 Flush current transmit buffer by setting cmdTail pointer (tout)
2585 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2586 ----------------------------------------------------------------- */
2588 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2591 } /* End CBAUD detected */
2593 { /* Begin CBAUD not detected */
2595 /* -------------------------------------------------------------------
2596 c_cflags have changed but that change had nothing to do with BAUD.
2597 Propagate the change to the card.
2598 ---------------------------------------------------------------------- */
2600 cflag = termios2digi_c(ch, ts->c_cflag);
2602 if (cflag != ch->fepcflag)
2604 ch->fepcflag = cflag;
2605 /* Set baud rate, char size, stop bits, parity */
2606 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2610 /* ----------------------------------------------------------------
2611 If the user has not forced CLOCAL and if the device is not a
2612 CALLOUT device (Which is always CLOCAL) we set flags such that
2613 the driver will wait on carrier detect.
2614 ------------------------------------------------------------------- */
2616 if (ts->c_cflag & CLOCAL)
2617 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2618 ch->asyncflags &= ~ASYNC_CHECK_CD;
2619 } /* End it is a cud device or a ttyD device with CLOCAL on */
2621 { /* Begin it is a ttyD device */
2622 ch->asyncflags |= ASYNC_CHECK_CD;
2623 } /* End it is a ttyD device */
2625 mval = ch->m_dtr | ch->m_rts;
2627 } /* End CBAUD not detected */
2629 iflag = termios2digi_i(ch, ts->c_iflag);
2631 /* Check input mode flags */
2633 if (iflag != ch->fepiflag)
2635 ch->fepiflag = iflag;
2637 /* ---------------------------------------------------------------
2638 Command sets channels iflag structure on the board. Such things
2639 as input soft flow control, handling of parity errors, and
2640 break handling are all set here.
2641 ------------------------------------------------------------------- */
2643 /* break handling, parity handling, input stripping, flow control chars */
2644 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2647 /* ---------------------------------------------------------------
2648 Set the board mint value for this channel. This will cause hardware
2649 events to be generated each time the DCD signal (Described in mint)
2651 ------------------------------------------------------------------- */
2654 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2655 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2658 ch->imodem = bc->mstat;
2660 hflow = termios2digi_h(ch, ts->c_cflag);
2662 if (hflow != ch->hflow)
2666 /* --------------------------------------------------------------
2667 Hard flow control has been selected but the board is not
2668 using it. Activate hard flow control now.
2669 ----------------------------------------------------------------- */
2671 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2675 mval ^= ch->modemfake & (mval ^ ch->modem);
2677 if (ch->omodem ^ mval)
2681 /* --------------------------------------------------------------
2682 The below command sets the DTR and RTS mstat structure. If
2683 hard flow control is NOT active these changes will drive the
2684 output of the actual DTR and RTS lines. If hard flow control
2685 is active, the changes will be saved in the mstat structure and
2686 only asserted when hard flow control is turned off.
2687 ----------------------------------------------------------------- */
2689 /* First reset DTR & RTS; then set them */
2690 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2691 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2695 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2697 ch->fepstartc = ch->startc;
2698 ch->fepstopc = ch->stopc;
2700 /* ------------------------------------------------------------
2701 The XON / XOFF characters have changed; propagate these
2702 changes to the card.
2703 --------------------------------------------------------------- */
2705 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2708 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2710 ch->fepstartca = ch->startca;
2711 ch->fepstopca = ch->stopca;
2713 /* ---------------------------------------------------------------
2714 Similar to the above, this time the auxilarly XON / XOFF
2715 characters have changed; propagate these changes to the card.
2716 ------------------------------------------------------------------ */
2718 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2721 } /* End epcaparam */
2723 /* --------------------- Begin receive_data ----------------------- */
2725 static void receive_data(struct channel *ch)
2726 { /* Begin receive_data */
2729 struct termios *ts = 0;
2730 struct tty_struct *tty;
2731 volatile struct board_chan *bc;
2732 register int dataToRead, wrapgap, bytesAvailable;
2733 register unsigned int tail, head;
2734 unsigned int wrapmask;
2738 /* ---------------------------------------------------------------
2739 This routine is called by doint when a receive data event
2741 ------------------------------------------------------------------- */
2745 if (ch->statusflags & RXSTOPPED)
2756 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2760 wrapmask = ch->rxbufsize - 1;
2762 /* ---------------------------------------------------------------------
2763 Get the head and tail pointers to the receiver queue. Wrap the
2764 head pointer if it has reached the end of the buffer.
2765 ------------------------------------------------------------------------ */
2769 tail = bc->rout & wrapmask;
2771 bytesAvailable = (head - tail) & wrapmask;
2773 if (bytesAvailable == 0)
2776 /* ------------------------------------------------------------------
2777 If CREAD bit is off or device not open, set TX tail to head
2778 --------------------------------------------------------------------- */
2780 if (!tty || !ts || !(ts->c_cflag & CREAD))
2786 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2792 printk(KERN_WARNING "overrun! DigiBoard device %s\n",tty->name);
2796 rptr = tty->flip.char_buf_ptr;
2797 rc = tty->flip.count;
2799 while (bytesAvailable > 0)
2800 { /* Begin while there is data on the card */
2802 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2804 /* ---------------------------------------------------------------
2805 Even if head has wrapped around only report the amount of
2806 data to be equal to the size - tail. Remember memcpy can't
2807 automaticly wrap around the receive buffer.
2808 ----------------------------------------------------------------- */
2810 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2812 /* --------------------------------------------------------------
2813 Make sure we don't overflow the buffer
2814 ----------------------------------------------------------------- */
2816 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2817 dataToRead = TTY_FLIPBUF_SIZE - rc;
2819 if (dataToRead == 0)
2822 /* ---------------------------------------------------------------
2823 Move data read from our card into the line disciplines buffer
2824 for translation if necessary.
2825 ------------------------------------------------------------------ */
2827 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2828 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2832 tail = (tail + dataToRead) & wrapmask;
2833 bytesAvailable -= dataToRead;
2835 } /* End while there is data on the card */
2838 tty->flip.count = rc;
2839 tty->flip.char_buf_ptr = rptr;
2843 /* Must be called with global data */
2844 tty_schedule_flip(ch->tty);
2847 } /* End receive_data */
2849 static int info_ioctl(struct tty_struct *tty, struct file * file,
2850 unsigned int cmd, unsigned long arg)
2855 { /* Begin switch cmd */
2858 { /* Begin case DIGI_GETINFO */
2860 struct digi_info di ;
2863 getUser(brd, (unsigned int *)arg);
2865 if ((error = verify_area(VERIFY_WRITE, (char*)arg, sizeof(di))))
2867 printk(KERN_ERR "DIGI_GETINFO : verify area size 0x%x failed\n",sizeof(di));
2871 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
2874 memset(&di, 0, sizeof(di));
2877 di.status = boards[brd].status;
2878 di.type = boards[brd].type ;
2879 di.numports = boards[brd].numports ;
2880 di.port = boards[brd].port ;
2881 di.membase = boards[brd].membase ;
2883 if (copy_to_user((char *)arg, &di, sizeof (di)))
2887 } /* End case DIGI_GETINFO */
2890 { /* Begin case DIGI_POLLER */
2892 int brd = arg & 0xff000000 >> 16 ;
2893 unsigned char state = arg & 0xff ;
2895 if ((brd < 0) || (brd >= num_cards))
2897 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
2901 digi_poller_inhibited = state ;
2904 } /* End case DIGI_POLLER */
2907 { /* Begin case DIGI_INIT */
2909 /* ------------------------------------------------------------
2910 This call is made by the apps to complete the initilization
2911 of the board(s). This routine is responsible for setting
2912 the card to its initial state and setting the drivers control
2913 fields to the sutianle settings for the card in question.
2914 ---------------------------------------------------------------- */
2917 for (crd = 0; crd < num_cards; crd++)
2918 post_fep_init (crd);
2922 } /* End case DIGI_INIT */
2926 return -ENOIOCTLCMD;
2928 } /* End switch cmd */
2931 /* --------------------- Begin pc_ioctl ----------------------- */
2933 static int pc_ioctl(struct tty_struct *tty, struct file * file,
2934 unsigned int cmd, unsigned long arg)
2935 { /* Begin pc_ioctl */
2939 unsigned long flags;
2940 unsigned int mflag, mstat;
2941 unsigned char startc, stopc;
2942 volatile struct board_chan *bc;
2943 struct channel *ch = (struct channel *) tty->driver_data;
2949 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
2955 /* -------------------------------------------------------------------
2956 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2957 in /usr/src/linux/drivers/char for a good example. In particular
2958 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2959 ---------------------------------------------------------------------- */
2962 { /* Begin switch cmd */
2965 if (copy_to_user((struct termios *)arg,
2966 tty->termios, sizeof(struct termios)))
2971 return get_termio(tty, (struct termio *)arg);
2973 case TCSBRK: /* SVID version: non-zero arg --> no break */
2975 retval = tty_check_change(tty);
2979 /* Setup an event to indicate when the transmit buffer empties */
2981 setup_empty_event(tty,ch);
2982 tty_wait_until_sent(tty, 0);
2984 digi_send_break(ch, HZ/4); /* 1/4 second */
2987 case TCSBRKP: /* support for POSIX tcsendbreak() */
2989 retval = tty_check_change(tty);
2993 /* Setup an event to indicate when the transmit buffer empties */
2995 setup_empty_event(tty,ch);
2996 tty_wait_until_sent(tty, 0);
2997 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
3002 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
3006 putUser(C_CLOCAL(tty) ? 1 : 0,
3007 (unsigned long *) arg);
3011 /*RONNIE PUT VERIFY_READ (See above) check here */
3015 getUser(value, (unsigned int *)arg);
3016 tty->termios->c_cflag =
3017 ((tty->termios->c_cflag & ~CLOCAL) |
3018 (value ? CLOCAL : 0));
3031 restore_flags(flags);
3033 if (mstat & ch->m_dtr)
3036 if (mstat & ch->m_rts)
3039 if (mstat & ch->m_cts)
3042 if (mstat & ch->dsr)
3045 if (mstat & ch->m_ri)
3048 if (mstat & ch->dcd)
3051 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
3056 putUser(mflag, (unsigned int *) arg);
3065 getUser(mstat, (unsigned int *)arg);
3068 if (mstat & TIOCM_DTR)
3071 if (mstat & TIOCM_RTS)
3075 { /* Begin switch cmd */
3079 ch->modemfake = ch->m_dtr|ch->m_rts;
3084 ch->modemfake |= mflag;
3089 ch->modemfake |= mflag;
3090 ch->modem &= ~mflag;
3093 } /* End switch cmd */
3098 /* --------------------------------------------------------------
3099 The below routine generally sets up parity, baud, flow control
3100 issues, etc.... It effect both control flags and input flags.
3101 ------------------------------------------------------------------ */
3105 restore_flags(flags);
3109 ch->omodem |= ch->m_dtr;
3112 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
3114 restore_flags(flags);
3118 ch->omodem &= ~ch->m_dtr;
3121 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
3123 restore_flags(flags);
3127 if (copy_to_user((char*)arg, &ch->digiext,
3134 if ((cmd) == (DIGI_SETAW))
3136 /* Setup an event to indicate when the transmit buffer empties */
3138 setup_empty_event(tty,ch);
3139 tty_wait_until_sent(tty, 0);
3143 if (tty->ldisc.flush_buffer)
3144 tty->ldisc.flush_buffer(tty);
3150 if (copy_from_user(&ch->digiext, (char*)arg,
3154 if (ch->digiext.digi_flags & DIGI_ALTPIN)
3156 ch->dcd = ch->m_dsr;
3157 ch->dsr = ch->m_dcd;
3161 ch->dcd = ch->m_dcd;
3162 ch->dsr = ch->m_dsr;
3168 /* -----------------------------------------------------------------
3169 The below routine generally sets up parity, baud, flow control
3170 issues, etc.... It effect both control flags and input flags.
3171 ------------------------------------------------------------------- */
3175 restore_flags(flags);
3182 if ((cmd) == (DIGI_GETFLOW))
3184 dflow.startc = bc->startc;
3185 dflow.stopc = bc->stopc;
3189 dflow.startc = bc->startca;
3190 dflow.stopc = bc->stopca;
3193 restore_flags(flags);
3195 if (copy_to_user((char*)arg, &dflow, sizeof(dflow)))
3201 if ((cmd) == (DIGI_SETFLOW))
3203 startc = ch->startc;
3208 startc = ch->startca;
3212 if (copy_from_user(&dflow, (char*)arg, sizeof(dflow)))
3215 if (dflow.startc != startc || dflow.stopc != stopc)
3216 { /* Begin if setflow toggled */
3220 if ((cmd) == (DIGI_SETFLOW))
3222 ch->fepstartc = ch->startc = dflow.startc;
3223 ch->fepstopc = ch->stopc = dflow.stopc;
3224 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3228 ch->fepstartca = ch->startca = dflow.startc;
3229 ch->fepstopca = ch->stopca = dflow.stopc;
3230 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3233 if (ch->statusflags & TXSTOPPED)
3237 restore_flags(flags);
3239 } /* End if setflow toggled */
3243 return -ENOIOCTLCMD;
3245 } /* End switch cmd */
3249 } /* End pc_ioctl */
3251 /* --------------------- Begin pc_set_termios ----------------------- */
3253 static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3254 { /* Begin pc_set_termios */
3257 unsigned long flags;
3259 /* ---------------------------------------------------------
3260 verifyChannel returns the channel from the tty struct
3261 if it is valid. This serves as a sanity check.
3262 ------------------------------------------------------------- */
3264 if ((ch = verifyChannel(tty)) != NULL)
3265 { /* Begin if channel valid */
3273 if ((old_termios->c_cflag & CRTSCTS) &&
3274 ((tty->termios->c_cflag & CRTSCTS) == 0))
3275 tty->hw_stopped = 0;
3277 if (!(old_termios->c_cflag & CLOCAL) &&
3278 (tty->termios->c_cflag & CLOCAL))
3279 wake_up_interruptible(&ch->open_wait);
3281 restore_flags(flags);
3283 } /* End if channel valid */
3285 } /* End pc_set_termios */
3287 /* --------------------- Begin do_softint ----------------------- */
3289 static void do_softint(void *private_)
3290 { /* Begin do_softint */
3292 struct channel *ch = (struct channel *) private_;
3295 /* Called in response to a modem change event */
3297 if (ch && ch->magic == EPCA_MAGIC)
3298 { /* Begin EPCA_MAGIC */
3300 struct tty_struct *tty = ch->tty;
3302 if (tty && tty->driver_data)
3304 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3305 { /* Begin if clear_bit */
3307 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
3308 wake_up_interruptible(&ch->open_wait);
3309 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
3311 } /* End if clear_bit */
3314 } /* End EPCA_MAGIC */
3316 } /* End do_softint */
3318 /* ------------------------------------------------------------
3319 pc_stop and pc_start provide software flow control to the
3320 routine and the pc_ioctl routine.
3321 ---------------------------------------------------------------- */
3323 /* --------------------- Begin pc_stop ----------------------- */
3325 static void pc_stop(struct tty_struct *tty)
3326 { /* Begin pc_stop */
3329 unsigned long flags;
3331 /* ---------------------------------------------------------
3332 verifyChannel returns the channel from the tty struct
3333 if it is valid. This serves as a sanity check.
3334 ------------------------------------------------------------- */
3336 if ((ch = verifyChannel(tty)) != NULL)
3337 { /* Begin if valid channel */
3342 if ((ch->statusflags & TXSTOPPED) == 0)
3343 { /* Begin if transmit stop requested */
3347 /* STOP transmitting now !! */
3349 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3351 ch->statusflags |= TXSTOPPED;
3354 } /* End if transmit stop requested */
3356 restore_flags(flags);
3358 } /* End if valid channel */
3362 /* --------------------- Begin pc_start ----------------------- */
3364 static void pc_start(struct tty_struct *tty)
3365 { /* Begin pc_start */
3369 /* ---------------------------------------------------------
3370 verifyChannel returns the channel from the tty struct
3371 if it is valid. This serves as a sanity check.
3372 ------------------------------------------------------------- */
3374 if ((ch = verifyChannel(tty)) != NULL)
3375 { /* Begin if channel valid */
3377 unsigned long flags;
3382 /* Just in case output was resumed because of a change in Digi-flow */
3383 if (ch->statusflags & TXSTOPPED)
3384 { /* Begin transmit resume requested */
3386 volatile struct board_chan *bc;
3390 if (ch->statusflags & LOWWAIT)
3393 /* Okay, you can start transmitting again... */
3395 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3397 ch->statusflags &= ~TXSTOPPED;
3400 } /* End transmit resume requested */
3402 restore_flags(flags);
3404 } /* End if channel valid */
3406 } /* End pc_start */
3408 /* ------------------------------------------------------------------
3409 The below routines pc_throttle and pc_unthrottle are used
3410 to slow (And resume) the receipt of data into the kernels
3411 receive buffers. The exact occurrence of this depends on the
3412 size of the kernels receive buffer and what the 'watermarks'
3413 are set to for that buffer. See the n_ttys.c file for more
3415 ______________________________________________________________________ */
3416 /* --------------------- Begin throttle ----------------------- */
3418 static void pc_throttle(struct tty_struct * tty)
3419 { /* Begin pc_throttle */
3422 unsigned long flags;
3424 /* ---------------------------------------------------------
3425 verifyChannel returns the channel from the tty struct
3426 if it is valid. This serves as a sanity check.
3427 ------------------------------------------------------------- */
3429 if ((ch = verifyChannel(tty)) != NULL)
3430 { /* Begin if channel valid */
3436 if ((ch->statusflags & RXSTOPPED) == 0)
3439 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3441 ch->statusflags |= RXSTOPPED;
3444 restore_flags(flags);
3446 } /* End if channel valid */
3448 } /* End pc_throttle */
3450 /* --------------------- Begin unthrottle ----------------------- */
3452 static void pc_unthrottle(struct tty_struct *tty)
3453 { /* Begin pc_unthrottle */
3456 unsigned long flags;
3457 volatile struct board_chan *bc;
3460 /* ---------------------------------------------------------
3461 verifyChannel returns the channel from the tty struct
3462 if it is valid. This serves as a sanity check.
3463 ------------------------------------------------------------- */
3465 if ((ch = verifyChannel(tty)) != NULL)
3466 { /* Begin if channel valid */
3469 /* Just in case output was resumed because of a change in Digi-flow */
3473 if (ch->statusflags & RXSTOPPED)
3478 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3480 ch->statusflags &= ~RXSTOPPED;
3483 restore_flags(flags);
3485 } /* End if channel valid */
3487 } /* End pc_unthrottle */
3489 /* --------------------- Begin digi_send_break ----------------------- */
3491 void digi_send_break(struct channel *ch, int msec)
3492 { /* Begin digi_send_break */
3494 unsigned long flags;
3500 /* --------------------------------------------------------------------
3501 Maybe I should send an infinite break here, schedule() for
3502 msec amount of time, and then stop the break. This way,
3503 the user can't screw up the FEP by causing digi_send_break()
3504 to be called (i.e. via an ioctl()) more than once in msec amount
3505 of time. Try this for now...
3506 ------------------------------------------------------------------------ */
3508 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3511 restore_flags(flags);
3513 } /* End digi_send_break */
3515 /* --------------------- Begin setup_empty_event ----------------------- */
3517 static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3518 { /* Begin setup_empty_event */
3520 volatile struct board_chan *bc = ch->brdchan;
3521 unsigned long int flags;
3526 ch->statusflags |= EMPTYWAIT;
3528 /* ------------------------------------------------------------------
3529 When set the iempty flag request a event to be generated when the
3530 transmit buffer is empty (If there is no BREAK in progress).
3531 --------------------------------------------------------------------- */
3535 restore_flags(flags);
3537 } /* End setup_empty_event */
3539 /* --------------------- Begin get_termio ----------------------- */
3541 static int get_termio(struct tty_struct * tty, struct termio * termio)
3542 { /* Begin get_termio */
3545 error = verify_area(VERIFY_WRITE, termio, sizeof (struct termio));
3549 kernel_termios_to_user_termio(termio, tty->termios);
3552 } /* End get_termio */
3553 /* ---------------------- Begin epca_setup -------------------------- */
3554 void epca_setup(char *str, int *ints)
3555 { /* Begin epca_setup */
3557 struct board_info board;
3558 int index, loop, last;
3562 /* ----------------------------------------------------------------------
3563 If this routine looks a little strange it is because it is only called
3564 if a LILO append command is given to boot the kernel with parameters.
3565 In this way, we can provide the user a method of changing his board
3566 configuration without rebuilding the kernel.
3567 ----------------------------------------------------------------------- */
3571 memset(&board, 0, sizeof(board));
3573 /* Assume the data is int first, later we can change it */
3574 /* I think that array position 0 of ints holds the number of args */
3575 for (last = 0, index = 1; index <= ints[0]; index++)
3577 { /* Begin parse switch */
3580 board.status = ints[index];
3582 /* ---------------------------------------------------------
3583 We check for 2 (As opposed to 1; because 2 is a flag
3584 instructing the driver to ignore epcaconfig.) For this
3585 reason we check for 2.
3586 ------------------------------------------------------------ */
3587 if (board.status == 2)
3588 { /* Begin ignore epcaconfig as well as lilo cmd line */
3592 } /* End ignore epcaconfig as well as lilo cmd line */
3594 if (board.status > 2)
3596 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3597 invalid_lilo_config = 1;
3598 setup_error_code |= INVALID_BOARD_STATUS;
3605 board.type = ints[index];
3606 if (board.type >= PCIXEM)
3608 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3609 invalid_lilo_config = 1;
3610 setup_error_code |= INVALID_BOARD_TYPE;
3617 board.altpin = ints[index];
3618 if (board.altpin > 1)
3620 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3621 invalid_lilo_config = 1;
3622 setup_error_code |= INVALID_ALTPIN;
3629 board.numports = ints[index];
3630 if ((board.numports < 2) || (board.numports > 256))
3632 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3633 invalid_lilo_config = 1;
3634 setup_error_code |= INVALID_NUM_PORTS;
3637 nbdevs += board.numports;
3642 board.port = (unsigned char *)ints[index];
3643 if (ints[index] <= 0)
3645 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3646 invalid_lilo_config = 1;
3647 setup_error_code |= INVALID_PORT_BASE;
3654 board.membase = (unsigned char *)ints[index];
3655 if (ints[index] <= 0)
3657 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3658 invalid_lilo_config = 1;
3659 setup_error_code |= INVALID_MEM_BASE;
3666 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
3669 } /* End parse switch */
3672 { /* Begin while there is a string arg */
3674 /* find the next comma or terminator */
3677 /* While string is not null, and a comma hasn't been found */
3678 while (*temp && (*temp != ','))
3686 /* Set index to the number of args + 1 */
3693 if (strncmp("Disable", str, len) == 0)
3696 if (strncmp("Enable", str, len) == 0)
3700 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3701 invalid_lilo_config = 1;
3702 setup_error_code |= INVALID_BOARD_STATUS;
3710 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3711 if (strcmp(board_desc[loop], str) == 0)
3715 /* ---------------------------------------------------------------
3716 If the index incremented above refers to a legitamate board
3718 ------------------------------------------------------------------*/
3720 if (index < EPCA_NUM_TYPES)
3724 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3725 invalid_lilo_config = 1;
3726 setup_error_code |= INVALID_BOARD_TYPE;
3734 if (strncmp("Disable", str, len) == 0)
3737 if (strncmp("Enable", str, len) == 0)
3741 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3742 invalid_lilo_config = 1;
3743 setup_error_code |= INVALID_ALTPIN;
3751 while (isdigit(*t2))
3756 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3757 invalid_lilo_config = 1;
3758 setup_error_code |= INVALID_NUM_PORTS;
3762 /* ------------------------------------------------------------
3763 There is not a man page for simple_strtoul but the code can be
3764 found in vsprintf.c. The first argument is the string to
3765 translate (To an unsigned long obviously), the second argument
3766 can be the address of any character variable or a NULL. If a
3767 variable is given, the end pointer of the string will be stored
3768 in that variable; if a NULL is given the end pointer will
3769 not be returned. The last argument is the base to use. If
3770 a 0 is indicated, the routine will attempt to determine the
3771 proper base by looking at the values prefix (A '0' for octal,
3772 a 'x' for hex, etc ... If a value is given it will use that
3774 ---------------------------------------------------------------- */
3775 board.numports = simple_strtoul(str, NULL, 0);
3776 nbdevs += board.numports;
3782 while (isxdigit(*t2))
3787 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3788 invalid_lilo_config = 1;
3789 setup_error_code |= INVALID_PORT_BASE;
3793 board.port = (unsigned char *)simple_strtoul(str, NULL, 16);
3799 while (isxdigit(*t2))
3804 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3805 invalid_lilo_config = 1;
3806 setup_error_code |= INVALID_MEM_BASE;
3810 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3815 printk(KERN_ERR "PC/Xx: Too many string parms\n");
3820 } /* End while there is a string arg */
3825 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3829 /* I should REALLY validate the stuff here */
3831 /* Copies our local copy of board into boards */
3832 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3835 /* Does this get called once per lilo arg are what ? */
3837 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3838 num_cards, board_desc[board.type],
3839 board.numports, (int)board.port, (unsigned int) board.membase);
3843 } /* End epca_setup */
3848 /* ------------------------ Begin init_PCI --------------------------- */
3850 enum epic_board_types {
3858 /* indexed directly by epic_board_types enum */
3860 unsigned char board_type;
3861 unsigned bar_idx; /* PCI base address region */
3862 } epca_info_tbl[] = {
3870 static int __init epca_init_one (struct pci_dev *pdev,
3871 const struct pci_device_id *ent)
3873 static int board_num = -1;
3874 int board_idx, info_idx = ent->driver_data;
3877 if (pci_enable_device(pdev))
3881 board_idx = board_num + num_cards;
3882 if (board_idx >= MAXBOARDS)
3885 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
3887 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
3888 epca_info_tbl[info_idx].bar_idx);
3892 boards[board_idx].status = ENABLED;
3893 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3894 boards[board_idx].numports = 0x0;
3895 boards[board_idx].port =
3896 (unsigned char *)((char *) addr + PCI_IO_OFFSET);
3897 boards[board_idx].membase =
3898 (unsigned char *)((char *) addr);
3900 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3901 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3902 0x200000, addr + PCI_IO_OFFSET);
3906 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
3907 if (!boards[board_idx].re_map_port) {
3908 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3909 0x200000, addr + PCI_IO_OFFSET);
3910 goto err_out_free_pciio;
3913 if (!request_mem_region (addr, 0x200000, "epca")) {
3914 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
3916 goto err_out_free_iounmap;
3919 boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
3920 if (!boards[board_idx].re_map_membase) {
3921 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
3922 0x200000, addr + PCI_IO_OFFSET);
3923 goto err_out_free_memregion;
3926 /* --------------------------------------------------------------
3927 I don't know what the below does, but the hardware guys say
3928 its required on everything except PLX (In this case XRJ).
3929 ---------------------------------------------------------------- */
3930 if (info_idx != brd_xrj) {
3931 pci_write_config_byte(pdev, 0x40, 0);
3932 pci_write_config_byte(pdev, 0x46, 0);
3937 err_out_free_memregion:
3938 release_mem_region (addr, 0x200000);
3939 err_out_free_iounmap:
3940 iounmap (boards[board_idx].re_map_port);
3942 release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
3948 static struct pci_device_id epca_pci_tbl[] __initdata = {
3949 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
3950 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
3951 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
3952 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
3956 MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3958 int __init init_PCI (void)
3959 { /* Begin init_PCI */
3963 memset (&epca_driver, 0, sizeof (epca_driver));
3964 epca_driver.name = "epca";
3965 epca_driver.id_table = epca_pci_tbl;
3966 epca_driver.probe = epca_init_one;
3968 pci_count = pci_register_driver (&epca_driver);
3970 if (pci_count <= 0) {
3971 pci_unregister_driver (&epca_driver);
3977 } /* End init_PCI */
3979 #endif /* ENABLE_PCI */
3981 MODULE_LICENSE("GPL");