4 Copyright (C) 1996 Digi International.
6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456
9 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 --------------------------------------------------------------------------- */
28 /* See README.epca for change history --DAT*/
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/init.h>
36 #include <linux/serial.h>
37 #include <linux/delay.h>
38 #include <linux/ctype.h>
39 #include <linux/tty.h>
40 #include <linux/tty_flip.h>
41 #include <linux/slab.h>
42 #include <linux/ioport.h>
43 #include <linux/interrupt.h>
44 #include <asm/uaccess.h>
49 #endif /* CONFIG_PCI */
51 #define putUser(arg1, arg2) put_user(arg1, (unsigned long __user *)arg2)
52 #define getUser(arg1, arg2) get_user(arg1, (unsigned __user *)arg2)
55 #include <linux/pci.h>
57 #endif /* ENABLE_PCI */
62 #include "epcaconfig.h"
64 #if BITS_PER_LONG != 32
65 # error FIXME: this driver only works on 32-bit platforms
68 /* ---------------------- Begin defines ------------------------ */
70 #define VERSION "1.3.0.1-LK"
72 /* This major needs to be submitted to Linux to join the majors list */
74 #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
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 __user
*);
221 static int pc_write(struct tty_struct
*, 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 tty_ldisc_flush(tty
);
559 if (ch
->blocked_open
)
560 { /* Begin if blocked_open */
564 msleep_interruptible(jiffies_to_msecs(ch
->close_delay
));
567 wake_up_interruptible(&ch
->open_wait
);
569 } /* End if blocked_open */
571 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_INITIALIZED
|
573 wake_up_interruptible(&ch
->close_wait
);
576 restore_flags(flags
);
578 } /* End if ch != NULL */
582 /* ------------------ Begin shutdown ------------------------- */
584 static void shutdown(struct channel
*ch
)
585 { /* Begin shutdown */
588 struct tty_struct
*tty
;
589 volatile struct board_chan
*bc
;
591 if (!(ch
->asyncflags
& ASYNC_INITIALIZED
))
600 /* ------------------------------------------------------------------
601 In order for an event to be generated on the receipt of data the
602 idata flag must be set. Since we are shutting down, this is not
603 necessary clear this flag.
604 --------------------------------------------------------------------- */
611 /* ----------------------------------------------------------------
612 If we're a modem control device and HUPCL is on, drop RTS & DTR.
613 ------------------------------------------------------------------ */
615 if (tty
->termios
->c_cflag
& HUPCL
)
617 ch
->omodem
&= ~(ch
->m_rts
| ch
->m_dtr
);
618 fepcmd(ch
, SETMODEM
, 0, ch
->m_dtr
| ch
->m_rts
, 10, 1);
623 /* ------------------------------------------------------------------
624 The channel has officialy been closed. The next time it is opened
625 it will have to reinitialized. Set a flag to indicate this.
626 ---------------------------------------------------------------------- */
628 /* Prevent future Digi programmed interrupts from coming active */
630 ch
->asyncflags
&= ~ASYNC_INITIALIZED
;
631 restore_flags(flags
);
635 /* ------------------ Begin pc_hangup ------------------------- */
637 static void pc_hangup(struct tty_struct
*tty
)
638 { /* Begin pc_hangup */
642 /* ---------------------------------------------------------
643 verifyChannel returns the channel from the tty struct
644 if it is valid. This serves as a sanity check.
645 ------------------------------------------------------------- */
647 if ((ch
= verifyChannel(tty
)) != NULL
)
648 { /* Begin if ch != NULL */
654 if (tty
->driver
->flush_buffer
)
655 tty
->driver
->flush_buffer(tty
);
656 tty_ldisc_flush(tty
);
662 restore_flags(flags
);
663 ch
->asyncflags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_INITIALIZED
);
664 wake_up_interruptible(&ch
->open_wait
);
666 } /* End if ch != NULL */
668 } /* End pc_hangup */
670 /* ------------------ Begin pc_write ------------------------- */
672 static int pc_write(struct tty_struct
* tty
,
673 const unsigned char *buf
, int bytesAvailable
)
674 { /* Begin pc_write */
676 register unsigned int head
, tail
;
677 register int dataLen
;
679 register int amountCopied
;
685 volatile struct board_chan
*bc
;
688 /* ----------------------------------------------------------------
689 pc_write is primarily called directly by the kernel routine
690 tty_write (Though it can also be called by put_char) found in
691 tty_io.c. pc_write is passed a line discipline buffer where
692 the data to be written out is stored. The line discipline
693 implementation itself is done at the kernel level and is not
694 brought into the driver.
695 ------------------------------------------------------------------- */
697 /* ---------------------------------------------------------
698 verifyChannel returns the channel from the tty struct
699 if it is valid. This serves as a sanity check.
700 ------------------------------------------------------------- */
702 if ((ch
= verifyChannel(tty
)) == NULL
)
705 /* Make a pointer to the channel data structure found on the board. */
708 size
= ch
->txbufsize
;
716 head
= bc
->tin
& (size
- 1);
719 if (tail
!= bc
->tout
)
723 /* If head >= tail, head has not wrapped around. */
725 { /* Begin head has not wrapped */
727 /* ---------------------------------------------------------------
728 remain (much like dataLen above) represents the total amount of
729 space available on the card for data. Here dataLen represents
730 the space existing between the head pointer and the end of
731 buffer. This is important because a memcpy cannot be told to
732 automatically wrap around when it hits the buffer end.
733 ------------------------------------------------------------------ */
735 dataLen
= size
- head
;
736 remain
= size
- (head
- tail
) - 1;
738 } /* End head has not wrapped */
740 { /* Begin head has wrapped around */
742 remain
= tail
- head
- 1;
745 } /* End head has wrapped around */
747 /* -------------------------------------------------------------------
748 Check the space on the card. If we have more data than
749 space; reduce the amount of data to fit the space.
750 ---------------------------------------------------------------------- */
752 bytesAvailable
= min(remain
, bytesAvailable
);
755 while (bytesAvailable
> 0)
756 { /* Begin while there is data to copy onto card */
758 /* -----------------------------------------------------------------
759 If head is not wrapped, the below will make sure the first
760 data copy fills to the end of card buffer.
761 ------------------------------------------------------------------- */
763 dataLen
= min(bytesAvailable
, dataLen
);
764 memcpy(ch
->txptr
+ head
, buf
, dataLen
);
767 amountCopied
+= dataLen
;
768 bytesAvailable
-= dataLen
;
776 } /* End while there is data to copy onto card */
778 ch
->statusflags
|= TXBUSY
;
782 if ((ch
->statusflags
& LOWWAIT
) == 0)
784 ch
->statusflags
|= LOWWAIT
;
788 restore_flags(flags
);
790 return(amountCopied
);
794 /* ------------------ Begin pc_put_char ------------------------- */
796 static void pc_put_char(struct tty_struct
*tty
, unsigned char c
)
797 { /* Begin pc_put_char */
800 pc_write(tty
, &c
, 1);
803 } /* End pc_put_char */
805 /* ------------------ Begin pc_write_room ------------------------- */
807 static int pc_write_room(struct tty_struct
*tty
)
808 { /* Begin pc_write_room */
813 unsigned int head
, tail
;
814 volatile struct board_chan
*bc
;
818 /* ---------------------------------------------------------
819 verifyChannel returns the channel from the tty struct
820 if it is valid. This serves as a sanity check.
821 ------------------------------------------------------------- */
823 if ((ch
= verifyChannel(tty
)) != NULL
)
830 head
= bc
->tin
& (ch
->txbufsize
- 1);
833 if (tail
!= bc
->tout
)
835 /* Wrap tail if necessary */
836 tail
&= (ch
->txbufsize
- 1);
838 if ((remain
= tail
- head
- 1) < 0 )
839 remain
+= ch
->txbufsize
;
841 if (remain
&& (ch
->statusflags
& LOWWAIT
) == 0)
843 ch
->statusflags
|= LOWWAIT
;
847 restore_flags(flags
);
850 /* Return how much room is left on card */
853 } /* End pc_write_room */
855 /* ------------------ Begin pc_chars_in_buffer ---------------------- */
857 static int pc_chars_in_buffer(struct tty_struct
*tty
)
858 { /* Begin pc_chars_in_buffer */
861 unsigned int ctail
, head
, tail
;
865 volatile struct board_chan
*bc
;
868 /* ---------------------------------------------------------
869 verifyChannel returns the channel from the tty struct
870 if it is valid. This serves as a sanity check.
871 ------------------------------------------------------------- */
873 if ((ch
= verifyChannel(tty
)) == NULL
)
883 ctail
= ch
->mailbox
->cout
;
885 if (tail
== head
&& ch
->mailbox
->cin
== ctail
&& bc
->tbusy
== 0)
888 { /* Begin if some space on the card has been used */
890 head
= bc
->tin
& (ch
->txbufsize
- 1);
891 tail
&= (ch
->txbufsize
- 1);
893 /* --------------------------------------------------------------
894 The logic here is basically opposite of the above pc_write_room
895 here we are finding the amount of bytes in the buffer filled.
896 Not the amount of bytes empty.
897 ------------------------------------------------------------------- */
899 if ((remain
= tail
- head
- 1) < 0 )
900 remain
+= ch
->txbufsize
;
902 chars
= (int)(ch
->txbufsize
- remain
);
904 /* -------------------------------------------------------------
905 Make it possible to wakeup anything waiting for output
908 If not already set. Setup an event to indicate when the
909 transmit buffer empties
910 ----------------------------------------------------------------- */
912 if (!(ch
->statusflags
& EMPTYWAIT
))
913 setup_empty_event(tty
,ch
);
915 } /* End if some space on the card has been used */
918 restore_flags(flags
);
920 /* Return number of characters residing on card. */
923 } /* End pc_chars_in_buffer */
925 /* ------------------ Begin pc_flush_buffer ---------------------- */
927 static void pc_flush_buffer(struct tty_struct
*tty
)
928 { /* Begin pc_flush_buffer */
933 volatile struct board_chan
*bc
;
936 /* ---------------------------------------------------------
937 verifyChannel returns the channel from the tty struct
938 if it is valid. This serves as a sanity check.
939 ------------------------------------------------------------- */
941 if ((ch
= verifyChannel(tty
)) == NULL
)
952 /* Have FEP move tout pointer; effectively flushing transmit buffer */
954 fepcmd(ch
, STOUT
, (unsigned) tail
, 0, 0, 0);
957 restore_flags(flags
);
959 wake_up_interruptible(&tty
->write_wait
);
962 } /* End pc_flush_buffer */
964 /* ------------------ Begin pc_flush_chars ---------------------- */
966 static void pc_flush_chars(struct tty_struct
*tty
)
967 { /* Begin pc_flush_chars */
971 /* ---------------------------------------------------------
972 verifyChannel returns the channel from the tty struct
973 if it is valid. This serves as a sanity check.
974 ------------------------------------------------------------- */
976 if ((ch
= verifyChannel(tty
)) != NULL
)
983 /* ----------------------------------------------------------------
984 If not already set and the transmitter is busy setup an event
985 to indicate when the transmit empties.
986 ------------------------------------------------------------------- */
988 if ((ch
->statusflags
& TXBUSY
) && !(ch
->statusflags
& EMPTYWAIT
))
989 setup_empty_event(tty
,ch
);
991 restore_flags(flags
);
994 } /* End pc_flush_chars */
996 /* ------------------ Begin block_til_ready ---------------------- */
998 static int block_til_ready(struct tty_struct
*tty
,
999 struct file
*filp
, struct channel
*ch
)
1000 { /* Begin block_til_ready */
1002 DECLARE_WAITQUEUE(wait
,current
);
1003 int retval
, do_clocal
= 0;
1004 unsigned long flags
;
1007 if (tty_hung_up_p(filp
))
1009 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
1012 retval
= -ERESTARTSYS
;
1016 /* -----------------------------------------------------------------
1017 If the device is in the middle of being closed, then block
1018 until it's done, and then try again.
1019 -------------------------------------------------------------------- */
1020 if (ch
->asyncflags
& ASYNC_CLOSING
)
1022 interruptible_sleep_on(&ch
->close_wait
);
1024 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
1027 return -ERESTARTSYS
;
1030 if (filp
->f_flags
& O_NONBLOCK
)
1032 /* -----------------------------------------------------------------
1033 If non-blocking mode is set, then make the check up front
1035 -------------------------------------------------------------------- */
1037 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
1043 if (tty
->termios
->c_cflag
& CLOCAL
)
1046 /* Block waiting for the carrier detect and the line to become free */
1049 add_wait_queue(&ch
->open_wait
, &wait
);
1054 /* We dec count so that pc_close will know when to free things */
1055 if (!tty_hung_up_p(filp
))
1058 restore_flags(flags
);
1063 { /* Begin forever while */
1065 set_current_state(TASK_INTERRUPTIBLE
);
1067 if (tty_hung_up_p(filp
) ||
1068 !(ch
->asyncflags
& ASYNC_INITIALIZED
))
1070 if (ch
->asyncflags
& ASYNC_HUP_NOTIFY
)
1073 retval
= -ERESTARTSYS
;
1077 if (!(ch
->asyncflags
& ASYNC_CLOSING
) &&
1078 (do_clocal
|| (ch
->imodem
& ch
->dcd
)))
1081 if (signal_pending(current
))
1083 retval
= -ERESTARTSYS
;
1087 /* ---------------------------------------------------------------
1088 Allow someone else to be scheduled. We will occasionally go
1089 through this loop until one of the above conditions change.
1090 The below schedule call will allow other processes to enter and
1091 prevent this loop from hogging the cpu.
1092 ------------------------------------------------------------------ */
1095 } /* End forever while */
1097 current
->state
= TASK_RUNNING
;
1098 remove_wait_queue(&ch
->open_wait
, &wait
);
1100 if (!tty_hung_up_p(filp
))
1102 restore_flags(flags
);
1109 ch
->asyncflags
|= ASYNC_NORMAL_ACTIVE
;
1113 } /* End block_til_ready */
1115 /* ------------------ Begin pc_open ---------------------- */
1117 static int pc_open(struct tty_struct
*tty
, struct file
* filp
)
1118 { /* Begin pc_open */
1121 unsigned long flags
;
1122 int line
, retval
, boardnum
;
1123 volatile struct board_chan
*bc
;
1124 volatile unsigned int head
;
1127 if (line
< 0 || line
>= nbdevs
)
1129 printk(KERN_ERR
"<Error> - pc_open : line out of range in pc_open\n");
1130 tty
->driver_data
= NULL
;
1135 ch
= &digi_channels
[line
];
1136 boardnum
= ch
->boardnum
;
1138 /* Check status of board configured in system. */
1140 /* -----------------------------------------------------------------
1141 I check to see if the epca_setup routine detected an user error.
1142 It might be better to put this in pc_init, but for the moment it
1144 ---------------------------------------------------------------------- */
1146 if (invalid_lilo_config
)
1148 if (setup_error_code
& INVALID_BOARD_TYPE
)
1149 printk(KERN_ERR
"<Error> - pc_open: Invalid board type specified in LILO command\n");
1151 if (setup_error_code
& INVALID_NUM_PORTS
)
1152 printk(KERN_ERR
"<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1154 if (setup_error_code
& INVALID_MEM_BASE
)
1155 printk(KERN_ERR
"<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1157 if (setup_error_code
& INVALID_PORT_BASE
)
1158 printk(KERN_ERR
"<Error> - pc_open: Invalid board port address specified in LILO command\n");
1160 if (setup_error_code
& INVALID_BOARD_STATUS
)
1161 printk(KERN_ERR
"<Error> - pc_open: Invalid board status specified in LILO command\n");
1163 if (setup_error_code
& INVALID_ALTPIN
)
1164 printk(KERN_ERR
"<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1166 tty
->driver_data
= NULL
; /* Mark this device as 'down' */
1170 if ((boardnum
>= num_cards
) || (boards
[boardnum
].status
== DISABLED
))
1172 tty
->driver_data
= NULL
; /* Mark this device as 'down' */
1176 if (( bc
= ch
->brdchan
) == 0)
1178 tty
->driver_data
= NULL
;
1182 /* ------------------------------------------------------------------
1183 Every time a channel is opened, increment a counter. This is
1184 necessary because we do not wish to flush and shutdown the channel
1185 until the last app holding the channel open, closes it.
1186 --------------------------------------------------------------------- */
1190 /* ----------------------------------------------------------------
1191 Set a kernel structures pointer to our local channel
1192 structure. This way we can get to it when passed only
1194 ------------------------------------------------------------------ */
1196 tty
->driver_data
= ch
;
1198 /* ----------------------------------------------------------------
1199 If this is the first time the channel has been opened, initialize
1200 the tty->termios struct otherwise let pc_close handle it.
1201 -------------------------------------------------------------------- */
1207 ch
->statusflags
= 0;
1209 /* Save boards current modem status */
1210 ch
->imodem
= bc
->mstat
;
1212 /* ----------------------------------------------------------------
1213 Set receive head and tail ptrs to each other. This indicates
1214 no data available to read.
1215 ----------------------------------------------------------------- */
1219 /* Set the channels associated tty structure */
1222 /* -----------------------------------------------------------------
1223 The below routine generally sets up parity, baud, flow control
1224 issues, etc.... It effect both control flags and input flags.
1225 -------------------------------------------------------------------- */
1228 ch
->asyncflags
|= ASYNC_INITIALIZED
;
1231 restore_flags(flags
);
1233 retval
= block_til_ready(tty
, filp
, ch
);
1239 /* -------------------------------------------------------------
1240 Set this again in case a hangup set it to zero while this
1241 open() was waiting for the line...
1242 --------------------------------------------------------------- */
1249 /* Enable Digi Data events */
1253 restore_flags(flags
);
1260 static int __init
epca_module_init(void)
1261 { /* Begin init_module */
1263 unsigned long flags
;
1270 restore_flags(flags
);
1275 module_init(epca_module_init
);
1279 static struct pci_driver epca_driver
;
1283 /* -------------------- Begin cleanup_module ---------------------- */
1285 static void __exit
epca_module_exit(void)
1289 struct board_info
*bd
;
1291 unsigned long flags
;
1293 del_timer_sync(&epca_timer
);
1298 if ((tty_unregister_driver(pc_driver
)) ||
1299 (tty_unregister_driver(pc_info
)))
1301 printk(KERN_WARNING
"<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1302 restore_flags(flags
);
1305 put_tty_driver(pc_driver
);
1306 put_tty_driver(pc_info
);
1308 for (crd
= 0; crd
< num_cards
; crd
++)
1309 { /* Begin for each card */
1314 { /* Begin sanity check */
1315 printk(KERN_ERR
"<Error> - Digi : cleanup_module failed\n");
1317 } /* End sanity check */
1321 for (count
= 0; count
< bd
->numports
; count
++, ch
++)
1322 { /* Begin for each port */
1327 tty_hangup(ch
->tty
);
1331 } /* End for each port */
1332 } /* End for each card */
1335 pci_unregister_driver (&epca_driver
);
1338 restore_flags(flags
);
1341 module_exit(epca_module_exit
);
1344 static struct tty_operations pc_ops
= {
1348 .write_room
= pc_write_room
,
1349 .flush_buffer
= pc_flush_buffer
,
1350 .chars_in_buffer
= pc_chars_in_buffer
,
1351 .flush_chars
= pc_flush_chars
,
1352 .put_char
= pc_put_char
,
1354 .set_termios
= pc_set_termios
,
1357 .throttle
= pc_throttle
,
1358 .unthrottle
= pc_unthrottle
,
1359 .hangup
= pc_hangup
,
1362 static int info_open(struct tty_struct
*tty
, struct file
* filp
)
1367 static struct tty_operations info_ops
= {
1369 .ioctl
= info_ioctl
,
1372 /* ------------------ Begin pc_init ---------------------- */
1374 int __init
pc_init(void)
1375 { /* Begin pc_init */
1377 /* ----------------------------------------------------------------
1378 pc_init is called by the operating system during boot up prior to
1379 any open calls being made. In the older versions of Linux (Prior
1380 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1381 memory location (from kernel space) used (kmem_start) is passed
1382 to pc_init. It is pc_inits responsibility to modify this value
1383 for any memory that the Digi driver might need and then return
1384 this value to the operating system. For example if the driver
1385 wishes to allocate 1K of kernel memory, pc_init would return
1386 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1387 + 1024) would then be available for use exclusively by the driver.
1388 In this case our driver does not allocate any of this kernel
1390 ------------------------------------------------------------------*/
1394 struct board_info
*bd
;
1395 unsigned char board_id
= 0;
1398 int pci_boards_found
, pci_count
;
1401 #endif /* ENABLE_PCI */
1403 pc_driver
= alloc_tty_driver(MAX_ALLOC
);
1407 pc_info
= alloc_tty_driver(MAX_ALLOC
);
1409 put_tty_driver(pc_driver
);
1413 /* -----------------------------------------------------------------------
1414 If epca_setup has not been ran by LILO set num_cards to defaults; copy
1415 board structure defined by digiConfig into drivers board structure.
1416 Note : If LILO has ran epca_setup then epca_setup will handle defining
1417 num_cards as well as copying the data into the board structure.
1418 -------------------------------------------------------------------------- */
1420 { /* Begin driver has been configured via. epcaconfig */
1423 num_cards
= NUMCARDS
;
1424 memcpy((void *)&boards
, (void *)&static_boards
,
1425 (sizeof(struct board_info
) * NUMCARDS
));
1426 } /* End driver has been configured via. epcaconfig */
1428 /* -----------------------------------------------------------------
1429 Note : If lilo was used to configure the driver and the
1430 ignore epcaconfig option was choosen (digiepca=2) then
1431 nbdevs and num_cards will equal 0 at this point. This is
1432 okay; PCI cards will still be picked up if detected.
1433 --------------------------------------------------------------------- */
1435 /* -----------------------------------------------------------
1436 Set up interrupt, we will worry about memory allocation in
1438 --------------------------------------------------------------- */
1441 printk(KERN_INFO
"DIGI epca driver version %s loaded.\n",VERSION
);
1445 /* ------------------------------------------------------------------
1446 NOTE : This code assumes that the number of ports found in
1447 the boards array is correct. This could be wrong if
1448 the card in question is PCI (And therefore has no ports
1449 entry in the boards structure.) The rest of the
1450 information will be valid for PCI because the beginning
1451 of pc_init scans for PCI and determines i/o and base
1452 memory addresses. I am not sure if it is possible to
1453 read the number of ports supported by the card prior to
1454 it being booted (Since that is the state it is in when
1455 pc_init is run). Because it is not possible to query the
1456 number of supported ports until after the card has booted;
1457 we are required to calculate the card_ptrs as the card is
1458 is initialized (Inside post_fep_init). The negative thing
1459 about this approach is that digiDload's call to GET_INFO
1460 will have a bad port value. (Since this is called prior
1463 --------------------------------------------------------------------- */
1465 pci_boards_found
= 0;
1466 if(num_cards
< MAXBOARDS
)
1467 pci_boards_found
+= init_PCI();
1468 num_cards
+= pci_boards_found
;
1470 #endif /* ENABLE_PCI */
1472 pc_driver
->owner
= THIS_MODULE
;
1473 pc_driver
->name
= "ttyD";
1474 pc_driver
->devfs_name
= "tts/D";
1475 pc_driver
->major
= DIGI_MAJOR
;
1476 pc_driver
->minor_start
= 0;
1477 pc_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
1478 pc_driver
->subtype
= SERIAL_TYPE_NORMAL
;
1479 pc_driver
->init_termios
= tty_std_termios
;
1480 pc_driver
->init_termios
.c_iflag
= 0;
1481 pc_driver
->init_termios
.c_oflag
= 0;
1482 pc_driver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| CLOCAL
| HUPCL
;
1483 pc_driver
->init_termios
.c_lflag
= 0;
1484 pc_driver
->flags
= TTY_DRIVER_REAL_RAW
;
1485 tty_set_operations(pc_driver
, &pc_ops
);
1487 pc_info
->owner
= THIS_MODULE
;
1488 pc_info
->name
= "digi_ctl";
1489 pc_info
->major
= DIGIINFOMAJOR
;
1490 pc_info
->minor_start
= 0;
1491 pc_info
->type
= TTY_DRIVER_TYPE_SERIAL
;
1492 pc_info
->subtype
= SERIAL_TYPE_INFO
;
1493 pc_info
->init_termios
= tty_std_termios
;
1494 pc_info
->init_termios
.c_iflag
= 0;
1495 pc_info
->init_termios
.c_oflag
= 0;
1496 pc_info
->init_termios
.c_lflag
= 0;
1497 pc_info
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
;
1498 pc_info
->flags
= TTY_DRIVER_REAL_RAW
;
1499 tty_set_operations(pc_info
, &info_ops
);
1505 for (crd
= 0; crd
< num_cards
; crd
++)
1506 { /* Begin for each card */
1508 /* ------------------------------------------------------------------
1509 This is where the appropriate memory handlers for the hardware is
1510 set. Everything at runtime blindly jumps through these vectors.
1511 ---------------------------------------------------------------------- */
1513 /* defined in epcaconfig.h */
1517 { /* Begin switch on bd->type {board type} */
1520 bd
->memwinon
= pcxem_memwinon
;
1521 bd
->memwinoff
= pcxem_memwinoff
;
1522 bd
->globalwinon
= pcxem_globalwinon
;
1523 bd
->txwinon
= pcxem_txwinon
;
1524 bd
->rxwinon
= pcxem_rxwinon
;
1525 bd
->memoff
= pcxem_memoff
;
1526 bd
->assertgwinon
= dummy_assertgwinon
;
1527 bd
->assertmemoff
= dummy_assertmemoff
;
1533 bd
->memwinon
= dummy_memwinon
;
1534 bd
->memwinoff
= dummy_memwinoff
;
1535 bd
->globalwinon
= dummy_globalwinon
;
1536 bd
->txwinon
= dummy_txwinon
;
1537 bd
->rxwinon
= dummy_rxwinon
;
1538 bd
->memoff
= dummy_memoff
;
1539 bd
->assertgwinon
= dummy_assertgwinon
;
1540 bd
->assertmemoff
= dummy_assertmemoff
;
1546 bd
->memwinon
= pcxe_memwinon
;
1547 bd
->memwinoff
= pcxe_memwinoff
;
1548 bd
->globalwinon
= pcxe_globalwinon
;
1549 bd
->txwinon
= pcxe_txwinon
;
1550 bd
->rxwinon
= pcxe_rxwinon
;
1551 bd
->memoff
= pcxe_memoff
;
1552 bd
->assertgwinon
= dummy_assertgwinon
;
1553 bd
->assertmemoff
= dummy_assertmemoff
;
1559 bd
->memwinon
= pcxi_memwinon
;
1560 bd
->memwinoff
= pcxi_memwinoff
;
1561 bd
->globalwinon
= pcxi_globalwinon
;
1562 bd
->txwinon
= pcxi_txwinon
;
1563 bd
->rxwinon
= pcxi_rxwinon
;
1564 bd
->memoff
= pcxi_memoff
;
1565 bd
->assertgwinon
= pcxi_assertgwinon
;
1566 bd
->assertmemoff
= pcxi_assertmemoff
;
1572 } /* End switch on bd->type */
1574 /* ---------------------------------------------------------------
1575 Some cards need a memory segment to be defined for use in
1576 transmit and receive windowing operations. These boards
1577 are listed in the below switch. In the case of the XI the
1578 amount of memory on the board is variable so the memory_seg
1579 is also variable. This code determines what they segment
1581 ----------------------------------------------------------------- */
1584 { /* Begin switch on bd->type {board type} */
1589 bd
->memory_seg
= 0xf000;
1593 board_id
= inb((int)bd
->port
);
1594 if ((board_id
& 0x1) == 0x1)
1595 { /* Begin it's an XI card */
1597 /* Is it a 64K board */
1598 if ((board_id
& 0x30) == 0)
1599 bd
->memory_seg
= 0xf000;
1601 /* Is it a 128K board */
1602 if ((board_id
& 0x30) == 0x10)
1603 bd
->memory_seg
= 0xe000;
1605 /* Is is a 256K board */
1606 if ((board_id
& 0x30) == 0x20)
1607 bd
->memory_seg
= 0xc000;
1609 /* Is it a 512K board */
1610 if ((board_id
& 0x30) == 0x30)
1611 bd
->memory_seg
= 0x8000;
1613 } /* End it is an XI card */
1616 printk(KERN_ERR
"<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd
->port
);
1620 } /* End switch on bd->type */
1622 } /* End for each card */
1624 if (tty_register_driver(pc_driver
))
1625 panic("Couldn't register Digi PC/ driver");
1627 if (tty_register_driver(pc_info
))
1628 panic("Couldn't register Digi PC/ info ");
1630 /* -------------------------------------------------------------------
1631 Start up the poller to check for events on all enabled boards
1632 ---------------------------------------------------------------------- */
1634 init_timer(&epca_timer
);
1635 epca_timer
.function
= epcapoll
;
1636 mod_timer(&epca_timer
, jiffies
+ HZ
/25);
1638 restore_flags(flags
);
1644 /* ------------------ Begin post_fep_init ---------------------- */
1646 static void post_fep_init(unsigned int crd
)
1647 { /* Begin post_fep_init */
1651 volatile struct global_data
*gd
;
1652 struct board_info
*bd
;
1653 volatile struct board_chan
*bc
;
1655 int shrinkmem
= 0, lowwater
;
1657 /* -------------------------------------------------------------
1658 This call is made by the user via. the ioctl call DIGI_INIT.
1659 It is responsible for setting up all the card specific stuff.
1660 ---------------------------------------------------------------- */
1663 /* -----------------------------------------------------------------
1664 If this is a PCI board, get the port info. Remember PCI cards
1665 do not have entries into the epcaconfig.h file, so we can't get
1666 the number of ports from it. Unfortunetly, this means that anyone
1667 doing a DIGI_GETINFO before the board has booted will get an invalid
1668 number of ports returned (It should return 0). Calls to DIGI_GETINFO
1669 after DIGI_INIT has been called will return the proper values.
1670 ------------------------------------------------------------------- */
1672 if (bd
->type
>= PCIXEM
) /* If the board in question is PCI */
1673 { /* Begin get PCI number of ports */
1675 /* --------------------------------------------------------------------
1676 Below we use XEMPORTS as a memory offset regardless of which PCI
1677 card it is. This is because all of the supported PCI cards have
1678 the same memory offset for the channel data. This will have to be
1679 changed if we ever develop a PCI/XE card. NOTE : The FEP manual
1680 states that the port offset is 0xC22 as opposed to 0xC02. This is
1681 only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1682 On the PCI cards the number of ports is determined by reading a
1683 ID PROM located in the box attached to the card. The card can then
1684 determine the index the id to determine the number of ports available.
1685 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1686 if the box in question is a XEM or CX)).
1687 ------------------------------------------------------------------------ */
1689 bd
->numports
= (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1690 (bd
->re_map_membase
+ XEMPORTS
));
1693 epcaassert(bd
->numports
<= 64,"PCI returned a invalid number of ports");
1694 nbdevs
+= (bd
->numports
);
1696 } /* End get PCI number of ports */
1699 card_ptr
[crd
] = card_ptr
[crd
-1] + boards
[crd
-1].numports
;
1701 card_ptr
[crd
] = &digi_channels
[crd
]; /* <- For card 0 only */
1706 epcaassert(ch
<= &digi_channels
[nbdevs
- 1], "ch out of range");
1708 memaddr
= (unchar
*)bd
->re_map_membase
;
1711 The below command is necessary because newer kernels (2.1.x and
1712 up) do not have a 1:1 virtual to physical mapping. The below
1713 call adjust for that.
1716 memaddr
= (unsigned char *)bus_to_virt((unsigned long)memaddr
);
1718 /* -----------------------------------------------------------------
1719 The below assignment will set bc to point at the BEGINING of
1720 the cards channel structures. For 1 card there will be between
1721 8 and 64 of these structures.
1722 -------------------------------------------------------------------- */
1724 bc
= (volatile struct board_chan
*)((ulong
)memaddr
+ CHANSTRUCT
);
1726 /* -------------------------------------------------------------------
1727 The below assignment will set gd to point at the BEGINING of
1728 global memory address 0xc00. The first data in that global
1729 memory actually starts at address 0xc1a. The command in
1730 pointer begins at 0xd10.
1731 ---------------------------------------------------------------------- */
1733 gd
= (volatile struct global_data
*)((ulong
)memaddr
+ GLOBAL
);
1735 /* --------------------------------------------------------------------
1736 XEPORTS (address 0xc22) points at the number of channels the
1737 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1738 ----------------------------------------------------------------------- */
1740 if (((bd
->type
== PCXEVE
) | (bd
->type
== PCXE
)) &&
1741 (*(ushort
*)((ulong
)memaddr
+ XEPORTS
) < 3))
1743 if (bd
->type
< PCIXEM
)
1744 if (!request_region((int)bd
->port
, 4, board_desc
[bd
->type
]))
1749 /* --------------------------------------------------------------------
1750 Remember ch is the main drivers channels structure, while bc is
1751 the cards channel structure.
1752 ------------------------------------------------------------------------ */
1754 /* For every port on the card do ..... */
1756 for (i
= 0; i
< bd
->numports
; i
++, ch
++, bc
++)
1757 { /* Begin for each port */
1761 INIT_WORK(&ch
->tqueue
, do_softint
, ch
);
1762 ch
->board
= &boards
[crd
];
1765 { /* Begin switch bd->type */
1767 /* ----------------------------------------------------------------
1768 Since some of the boards use different bitmaps for their
1769 control signals we cannot hard code these values and retain
1770 portability. We virtualize this data here.
1771 ------------------------------------------------------------------- */
1797 } /* End switch bd->type */
1799 if (boards
[crd
].altpin
)
1801 ch
->dsr
= ch
->m_dcd
;
1802 ch
->dcd
= ch
->m_dsr
;
1803 ch
->digiext
.digi_flags
|= DIGI_ALTPIN
;
1807 ch
->dcd
= ch
->m_dcd
;
1808 ch
->dsr
= ch
->m_dsr
;
1813 ch
->magic
= EPCA_MAGIC
;
1818 fepcmd(ch
, SETBUFFER
, 32, 0, 0, 0);
1823 { /* Begin switch bd->type */
1828 /* Cover all the 2MEG cards */
1829 ch
->txptr
= memaddr
+ (((bc
->tseg
) << 4) & 0x1fffff);
1830 ch
->rxptr
= memaddr
+ (((bc
->rseg
) << 4) & 0x1fffff);
1831 ch
->txwin
= FEPWIN
| ((bc
->tseg
) >> 11);
1832 ch
->rxwin
= FEPWIN
| ((bc
->rseg
) >> 11);
1837 /* Cover all the 32K windowed cards */
1838 /* Mask equal to window size - 1 */
1839 ch
->txptr
= memaddr
+ (((bc
->tseg
) << 4) & 0x7fff);
1840 ch
->rxptr
= memaddr
+ (((bc
->rseg
) << 4) & 0x7fff);
1841 ch
->txwin
= FEPWIN
| ((bc
->tseg
) >> 11);
1842 ch
->rxwin
= FEPWIN
| ((bc
->rseg
) >> 11);
1847 ch
->txptr
= memaddr
+ (((bc
->tseg
- bd
->memory_seg
) << 4) & 0x1fff);
1848 ch
->txwin
= FEPWIN
| ((bc
->tseg
- bd
->memory_seg
) >> 9);
1849 ch
->rxptr
= memaddr
+ (((bc
->rseg
- bd
->memory_seg
) << 4) & 0x1fff);
1850 ch
->rxwin
= FEPWIN
| ((bc
->rseg
- bd
->memory_seg
) >>9 );
1855 ch
->txptr
= memaddr
+ ((bc
->tseg
- bd
->memory_seg
) << 4);
1856 ch
->rxptr
= memaddr
+ ((bc
->rseg
- bd
->memory_seg
) << 4);
1857 ch
->txwin
= ch
->rxwin
= 0;
1860 } /* End switch bd->type */
1863 ch
->txbufsize
= bc
->tmax
+ 1;
1866 ch
->rxbufsize
= bc
->rmax
+ 1;
1868 lowwater
= ch
->txbufsize
>= 2000 ? 1024 : (ch
->txbufsize
/ 2);
1870 /* Set transmitter low water mark */
1871 fepcmd(ch
, STXLWATER
, lowwater
, 0, 10, 0);
1873 /* Set receiver low water mark */
1875 fepcmd(ch
, SRXLWATER
, (ch
->rxbufsize
/ 4), 0, 10, 0);
1877 /* Set receiver high water mark */
1879 fepcmd(ch
, SRXHWATER
, (3 * ch
->rxbufsize
/ 4), 0, 10, 0);
1884 ch
->startc
= bc
->startc
;
1885 ch
->stopc
= bc
->stopc
;
1886 ch
->startca
= bc
->startca
;
1887 ch
->stopca
= bc
->stopca
;
1897 ch
->close_delay
= 50;
1899 ch
->blocked_open
= 0;
1900 init_waitqueue_head(&ch
->open_wait
);
1901 init_waitqueue_head(&ch
->close_wait
);
1902 ch
->tmp_buf
= kmalloc(ch
->txbufsize
,GFP_KERNEL
);
1905 printk(KERN_ERR
"POST FEP INIT : kmalloc failed for port 0x%x\n",i
);
1906 release_region((int)bd
->port
, 4);
1908 kfree((ch
--)->tmp_buf
);
1912 memset((void *)ch
->tmp_buf
,0,ch
->txbufsize
);
1913 } /* End for each port */
1916 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1917 VERSION
, board_desc
[bd
->type
], (long)bd
->port
, (long)bd
->membase
, bd
->numports
);
1919 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1920 VERSION
, board_desc
[bd
->type
], (long)bd
->port
, (long)bd
->membase
, bd
->numports
);
1921 console_print(mesg
);
1925 } /* End post_fep_init */
1927 /* --------------------- Begin epcapoll ------------------------ */
1929 static void epcapoll(unsigned long ignored
)
1930 { /* Begin epcapoll */
1932 unsigned long flags
;
1934 volatile unsigned int head
, tail
;
1936 struct board_info
*bd
;
1938 /* -------------------------------------------------------------------
1939 This routine is called upon every timer interrupt. Even though
1940 the Digi series cards are capable of generating interrupts this
1941 method of non-looping polling is more efficient. This routine
1942 checks for card generated events (Such as receive data, are transmit
1943 buffer empty) and acts on those events.
1944 ----------------------------------------------------------------------- */
1949 for (crd
= 0; crd
< num_cards
; crd
++)
1950 { /* Begin for each card */
1955 if ((bd
->status
== DISABLED
) || digi_poller_inhibited
)
1956 continue; /* Begin loop next interation */
1958 /* -----------------------------------------------------------
1959 assertmemoff is not needed here; indeed it is an empty subroutine.
1960 It is being kept because future boards may need this as well as
1962 ---------------------------------------------------------------- */
1968 /* ---------------------------------------------------------------
1969 In this case head and tail actually refer to the event queue not
1970 the transmit or receive queue.
1971 ------------------------------------------------------------------- */
1973 head
= ch
->mailbox
->ein
;
1974 tail
= ch
->mailbox
->eout
;
1976 /* If head isn't equal to tail we have an event */
1983 } /* End for each card */
1985 mod_timer(&epca_timer
, jiffies
+ (HZ
/ 25));
1987 restore_flags(flags
);
1988 } /* End epcapoll */
1990 /* --------------------- Begin doevent ------------------------ */
1992 static void doevent(int crd
)
1993 { /* Begin doevent */
1995 volatile unchar
*eventbuf
;
1996 struct channel
*ch
, *chan0
;
1997 static struct tty_struct
*tty
;
1998 volatile struct board_info
*bd
;
1999 volatile struct board_chan
*bc
;
2000 register volatile unsigned int tail
, head
;
2001 register int event
, channel
;
2002 register int mstat
, lstat
;
2004 /* -------------------------------------------------------------------
2005 This subroutine is called by epcapoll when an event is detected
2006 in the event queue. This routine responds to those events.
2007 --------------------------------------------------------------------- */
2011 chan0
= card_ptr
[crd
];
2012 epcaassert(chan0
<= &digi_channels
[nbdevs
- 1], "ch out of range");
2014 assertgwinon(chan0
);
2016 while ((tail
= chan0
->mailbox
->eout
) != (head
= chan0
->mailbox
->ein
))
2017 { /* Begin while something in event queue */
2019 assertgwinon(chan0
);
2021 eventbuf
= (volatile unchar
*)bus_to_virt((ulong
)(bd
->re_map_membase
+ tail
+ ISTART
));
2023 /* Get the channel the event occurred on */
2024 channel
= eventbuf
[0];
2026 /* Get the actual event code that occurred */
2027 event
= eventbuf
[1];
2029 /* ----------------------------------------------------------------
2030 The two assignments below get the current modem status (mstat)
2031 and the previous modem status (lstat). These are useful becuase
2032 an event could signal a change in modem signals itself.
2033 ------------------------------------------------------------------- */
2035 mstat
= eventbuf
[2];
2036 lstat
= eventbuf
[3];
2038 ch
= chan0
+ channel
;
2040 if ((unsigned)channel
>= bd
->numports
|| !ch
)
2042 if (channel
>= bd
->numports
)
2048 if ((bc
= ch
->brdchan
) == NULL
)
2051 if (event
& DATA_IND
)
2052 { /* Begin DATA_IND */
2057 } /* End DATA_IND */
2058 /* else *//* Fix for DCD transition missed bug */
2059 if (event
& MODEMCHG_IND
)
2060 { /* Begin MODEMCHG_IND */
2062 /* A modem signal change has been indicated */
2066 if (ch
->asyncflags
& ASYNC_CHECK_CD
)
2068 if (mstat
& ch
->dcd
) /* We are now receiving dcd */
2069 wake_up_interruptible(&ch
->open_wait
);
2071 pc_sched_event(ch
, EPCA_EVENT_HANGUP
); /* No dcd; hangup */
2074 } /* End MODEMCHG_IND */
2078 { /* Begin if valid tty */
2080 if (event
& BREAK_IND
)
2081 { /* Begin if BREAK_IND */
2083 /* A break has been indicated */
2086 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
2088 *tty
->flip
.char_buf_ptr
++ = 0;
2090 tty_schedule_flip(tty
);
2092 } /* End if BREAK_IND */
2094 if (event
& LOWTX_IND
)
2095 { /* Begin LOWTX_IND */
2097 if (ch
->statusflags
& LOWWAIT
)
2098 { /* Begin if LOWWAIT */
2100 ch
->statusflags
&= ~LOWWAIT
;
2102 wake_up_interruptible(&tty
->write_wait
);
2104 } /* End if LOWWAIT */
2106 } /* End LOWTX_IND */
2108 if (event
& EMPTYTX_IND
)
2109 { /* Begin EMPTYTX_IND */
2111 /* This event is generated by setup_empty_event */
2113 ch
->statusflags
&= ~TXBUSY
;
2114 if (ch
->statusflags
& EMPTYWAIT
)
2115 { /* Begin if EMPTYWAIT */
2117 ch
->statusflags
&= ~EMPTYWAIT
;
2120 wake_up_interruptible(&tty
->write_wait
);
2122 } /* End if EMPTYWAIT */
2124 } /* End EMPTYTX_IND */
2126 } /* End if valid tty */
2133 printk(KERN_ERR
"<Error> - bc == NULL in doevent!\n");
2137 chan0
->mailbox
->eout
= (tail
+ 4) & (IMAX
- ISTART
- 4);
2140 } /* End while something in event queue */
2144 /* --------------------- Begin fepcmd ------------------------ */
2146 static void fepcmd(struct channel
*ch
, int cmd
, int word_or_byte
,
2147 int byte2
, int ncmds
, int bytecmd
)
2148 { /* Begin fepcmd */
2151 unsigned int head
, cmdTail
, cmdStart
, cmdMax
;
2155 /* This is the routine in which commands may be passed to the card. */
2157 if (ch
->board
->status
== DISABLED
)
2164 /* Remember head (As well as max) is just an offset not a base addr */
2165 head
= ch
->mailbox
->cin
;
2167 /* cmdStart is a base address */
2168 cmdStart
= ch
->mailbox
->cstart
;
2170 /* ------------------------------------------------------------------
2171 We do the addition below because we do not want a max pointer
2172 relative to cmdStart. We want a max pointer that points at the
2173 physical end of the command queue.
2174 -------------------------------------------------------------------- */
2176 cmdMax
= (cmdStart
+ 4 + (ch
->mailbox
->cmax
));
2178 memaddr
= ch
->board
->re_map_membase
;
2181 The below command is necessary because newer kernels (2.1.x and
2182 up) do not have a 1:1 virtual to physical mapping. The below
2183 call adjust for that.
2186 memaddr
= (unsigned char *)bus_to_virt((unsigned long)memaddr
);
2188 if (head
>= (cmdMax
- cmdStart
) || (head
& 03))
2190 printk(KERN_ERR
"line %d: Out of range, cmd = %x, head = %x\n", __LINE__
,
2192 printk(KERN_ERR
"line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__
,
2199 *(volatile unchar
*)(memaddr
+ head
+ cmdStart
+ 0) = (unchar
)cmd
;
2201 *(volatile unchar
*)(memaddr
+ head
+ cmdStart
+ 1) = (unchar
)ch
->channelnum
;
2202 /* Below word_or_byte is bits to set */
2203 *(volatile unchar
*)(memaddr
+ head
+ cmdStart
+ 2) = (unchar
)word_or_byte
;
2204 /* Below byte2 is bits to reset */
2205 *(volatile unchar
*)(memaddr
+ head
+ cmdStart
+ 3) = (unchar
)byte2
;
2210 *(volatile unchar
*)(memaddr
+ head
+ cmdStart
+ 0) = (unchar
)cmd
;
2211 *(volatile unchar
*)(memaddr
+ head
+ cmdStart
+ 1) = (unchar
)ch
->channelnum
;
2212 *(volatile ushort
*)(memaddr
+ head
+ cmdStart
+ 2) = (ushort
)word_or_byte
;
2215 head
= (head
+ 4) & (cmdMax
- cmdStart
- 4);
2216 ch
->mailbox
->cin
= head
;
2221 { /* Begin forever loop */
2226 printk(KERN_ERR
"<Error> - Fep not responding in fepcmd()\n");
2230 head
= ch
->mailbox
->cin
;
2231 cmdTail
= ch
->mailbox
->cout
;
2233 n
= (head
- cmdTail
) & (cmdMax
- cmdStart
- 4);
2235 /* ----------------------------------------------------------
2236 Basically this will break when the FEP acknowledges the
2237 command by incrementing cmdTail (Making it equal to head).
2238 ------------------------------------------------------------- */
2240 if (n
<= ncmds
* (sizeof(short) * 4))
2241 break; /* Well nearly forever :-) */
2243 } /* End forever loop */
2247 /* ---------------------------------------------------------------------
2248 Digi products use fields in their channels structures that are very
2249 similar to the c_cflag and c_iflag fields typically found in UNIX
2250 termios structures. The below three routines allow mappings
2251 between these hardware "flags" and their respective Linux flags.
2252 ------------------------------------------------------------------------- */
2254 /* --------------------- Begin termios2digi_h -------------------- */
2256 static unsigned termios2digi_h(struct channel
*ch
, unsigned cflag
)
2257 { /* Begin termios2digi_h */
2261 if (cflag
& CRTSCTS
)
2263 ch
->digiext
.digi_flags
|= (RTSPACE
| CTSPACE
);
2264 res
|= ((ch
->m_cts
) | (ch
->m_rts
));
2267 if (ch
->digiext
.digi_flags
& RTSPACE
)
2270 if (ch
->digiext
.digi_flags
& DTRPACE
)
2273 if (ch
->digiext
.digi_flags
& CTSPACE
)
2276 if (ch
->digiext
.digi_flags
& DSRPACE
)
2279 if (ch
->digiext
.digi_flags
& DCDPACE
)
2282 if (res
& (ch
->m_rts
))
2283 ch
->digiext
.digi_flags
|= RTSPACE
;
2285 if (res
& (ch
->m_cts
))
2286 ch
->digiext
.digi_flags
|= CTSPACE
;
2290 } /* End termios2digi_h */
2292 /* --------------------- Begin termios2digi_i -------------------- */
2293 static unsigned termios2digi_i(struct channel
*ch
, unsigned iflag
)
2294 { /* Begin termios2digi_i */
2296 unsigned res
= iflag
& (IGNBRK
| BRKINT
| IGNPAR
| PARMRK
|
2297 INPCK
| ISTRIP
|IXON
|IXANY
|IXOFF
);
2299 if (ch
->digiext
.digi_flags
& DIGI_AIXON
)
2303 } /* End termios2digi_i */
2305 /* --------------------- Begin termios2digi_c -------------------- */
2307 static unsigned termios2digi_c(struct channel
*ch
, unsigned cflag
)
2308 { /* Begin termios2digi_c */
2313 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2314 if ((cflag
& CBAUD
)== B38400
) cflag
=cflag
- B38400
+ B115200
;
2315 if ((cflag
& CBAUD
)== B19200
) cflag
=cflag
- B19200
+ B57600
;
2316 #endif /* SPEED_HACK */
2318 if (cflag
& CBAUDEX
)
2319 { /* Begin detected CBAUDEX */
2321 ch
->digiext
.digi_flags
|= DIGI_FAST
;
2323 /* -------------------------------------------------------------
2324 HUPCL bit is used by FEP to indicate fast baud
2325 table is to be used.
2326 ----------------------------------------------------------------- */
2330 } /* End detected CBAUDEX */
2331 else ch
->digiext
.digi_flags
&= ~DIGI_FAST
;
2333 /* -------------------------------------------------------------------
2334 CBAUD has bit position 0x1000 set these days to indicate Linux
2335 baud rate remap. Digi hardware can't handle the bit assignment.
2336 (We use a different bit assignment for high speed.). Clear this
2338 ---------------------------------------------------------------------- */
2339 res
|= cflag
& ((CBAUD
^ CBAUDEX
) | PARODD
| PARENB
| CSTOPB
| CSIZE
);
2341 /* -------------------------------------------------------------
2342 This gets a little confusing. The Digi cards have their own
2343 representation of c_cflags controling baud rate. For the most
2344 part this is identical to the Linux implementation. However;
2345 Digi supports one rate (76800) that Linux doesn't. This means
2346 that the c_cflag entry that would normally mean 76800 for Digi
2347 actually means 115200 under Linux. Without the below mapping,
2348 a stty 115200 would only drive the board at 76800. Since
2349 the rate 230400 is also found after 76800, the same problem afflicts
2350 us when we choose a rate of 230400. Without the below modificiation
2351 stty 230400 would actually give us 115200.
2353 There are two additional differences. The Linux value for CLOCAL
2354 (0x800; 0004000) has no meaning to the Digi hardware. Also in
2355 later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
2356 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
2357 should be checked for a screened out prior to termios2digi_c
2358 returning. Since CLOCAL isn't used by the board this can be
2359 ignored as long as the returned value is used only by Digi hardware.
2360 ----------------------------------------------------------------- */
2362 if (cflag
& CBAUDEX
)
2364 /* -------------------------------------------------------------
2365 The below code is trying to guarantee that only baud rates
2366 115200 and 230400 are remapped. We use exclusive or because
2367 the various baud rates share common bit positions and therefore
2368 can't be tested for easily.
2369 ----------------------------------------------------------------- */
2372 if ((!((cflag
& 0x7) ^ (B115200
& ~CBAUDEX
))) ||
2373 (!((cflag
& 0x7) ^ (B230400
& ~CBAUDEX
))))
2381 } /* End termios2digi_c */
2383 /* --------------------- Begin epcaparam ----------------------- */
2385 static void epcaparam(struct tty_struct
*tty
, struct channel
*ch
)
2386 { /* Begin epcaparam */
2388 unsigned int cmdHead
;
2390 volatile struct board_chan
*bc
;
2391 unsigned mval
, hflow
, cflag
, iflag
;
2394 epcaassert(bc
!=0, "bc out of range");
2400 if ((ts
->c_cflag
& CBAUD
) == 0)
2401 { /* Begin CBAUD detected */
2407 /* Changing baud in mid-stream transmission can be wonderful */
2408 /* ---------------------------------------------------------------
2409 Flush current transmit buffer by setting cmdTail pointer (tout)
2410 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2411 ----------------------------------------------------------------- */
2413 fepcmd(ch
, STOUT
, (unsigned) cmdHead
, 0, 0, 0);
2416 } /* End CBAUD detected */
2418 { /* Begin CBAUD not detected */
2420 /* -------------------------------------------------------------------
2421 c_cflags have changed but that change had nothing to do with BAUD.
2422 Propagate the change to the card.
2423 ---------------------------------------------------------------------- */
2425 cflag
= termios2digi_c(ch
, ts
->c_cflag
);
2427 if (cflag
!= ch
->fepcflag
)
2429 ch
->fepcflag
= cflag
;
2430 /* Set baud rate, char size, stop bits, parity */
2431 fepcmd(ch
, SETCTRLFLAGS
, (unsigned) cflag
, 0, 0, 0);
2435 /* ----------------------------------------------------------------
2436 If the user has not forced CLOCAL and if the device is not a
2437 CALLOUT device (Which is always CLOCAL) we set flags such that
2438 the driver will wait on carrier detect.
2439 ------------------------------------------------------------------- */
2441 if (ts
->c_cflag
& CLOCAL
)
2442 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2443 ch
->asyncflags
&= ~ASYNC_CHECK_CD
;
2444 } /* End it is a cud device or a ttyD device with CLOCAL on */
2446 { /* Begin it is a ttyD device */
2447 ch
->asyncflags
|= ASYNC_CHECK_CD
;
2448 } /* End it is a ttyD device */
2450 mval
= ch
->m_dtr
| ch
->m_rts
;
2452 } /* End CBAUD not detected */
2454 iflag
= termios2digi_i(ch
, ts
->c_iflag
);
2456 /* Check input mode flags */
2458 if (iflag
!= ch
->fepiflag
)
2460 ch
->fepiflag
= iflag
;
2462 /* ---------------------------------------------------------------
2463 Command sets channels iflag structure on the board. Such things
2464 as input soft flow control, handling of parity errors, and
2465 break handling are all set here.
2466 ------------------------------------------------------------------- */
2468 /* break handling, parity handling, input stripping, flow control chars */
2469 fepcmd(ch
, SETIFLAGS
, (unsigned int) ch
->fepiflag
, 0, 0, 0);
2472 /* ---------------------------------------------------------------
2473 Set the board mint value for this channel. This will cause hardware
2474 events to be generated each time the DCD signal (Described in mint)
2476 ------------------------------------------------------------------- */
2479 if ((ts
->c_cflag
& CLOCAL
) || (ch
->digiext
.digi_flags
& DIGI_FORCEDCD
))
2480 if (ch
->digiext
.digi_flags
& DIGI_FORCEDCD
)
2483 ch
->imodem
= bc
->mstat
;
2485 hflow
= termios2digi_h(ch
, ts
->c_cflag
);
2487 if (hflow
!= ch
->hflow
)
2491 /* --------------------------------------------------------------
2492 Hard flow control has been selected but the board is not
2493 using it. Activate hard flow control now.
2494 ----------------------------------------------------------------- */
2496 fepcmd(ch
, SETHFLOW
, hflow
, 0xff, 0, 1);
2500 mval
^= ch
->modemfake
& (mval
^ ch
->modem
);
2502 if (ch
->omodem
^ mval
)
2506 /* --------------------------------------------------------------
2507 The below command sets the DTR and RTS mstat structure. If
2508 hard flow control is NOT active these changes will drive the
2509 output of the actual DTR and RTS lines. If hard flow control
2510 is active, the changes will be saved in the mstat structure and
2511 only asserted when hard flow control is turned off.
2512 ----------------------------------------------------------------- */
2514 /* First reset DTR & RTS; then set them */
2515 fepcmd(ch
, SETMODEM
, 0, ((ch
->m_dtr
)|(ch
->m_rts
)), 0, 1);
2516 fepcmd(ch
, SETMODEM
, mval
, 0, 0, 1);
2520 if (ch
->startc
!= ch
->fepstartc
|| ch
->stopc
!= ch
->fepstopc
)
2522 ch
->fepstartc
= ch
->startc
;
2523 ch
->fepstopc
= ch
->stopc
;
2525 /* ------------------------------------------------------------
2526 The XON / XOFF characters have changed; propagate these
2527 changes to the card.
2528 --------------------------------------------------------------- */
2530 fepcmd(ch
, SONOFFC
, ch
->fepstartc
, ch
->fepstopc
, 0, 1);
2533 if (ch
->startca
!= ch
->fepstartca
|| ch
->stopca
!= ch
->fepstopca
)
2535 ch
->fepstartca
= ch
->startca
;
2536 ch
->fepstopca
= ch
->stopca
;
2538 /* ---------------------------------------------------------------
2539 Similar to the above, this time the auxilarly XON / XOFF
2540 characters have changed; propagate these changes to the card.
2541 ------------------------------------------------------------------ */
2543 fepcmd(ch
, SAUXONOFFC
, ch
->fepstartca
, ch
->fepstopca
, 0, 1);
2546 } /* End epcaparam */
2548 /* --------------------- Begin receive_data ----------------------- */
2550 static void receive_data(struct channel
*ch
)
2551 { /* Begin receive_data */
2554 struct termios
*ts
= NULL
;
2555 struct tty_struct
*tty
;
2556 volatile struct board_chan
*bc
;
2557 register int dataToRead
, wrapgap
, bytesAvailable
;
2558 register unsigned int tail
, head
;
2559 unsigned int wrapmask
;
2563 /* ---------------------------------------------------------------
2564 This routine is called by doint when a receive data event
2566 ------------------------------------------------------------------- */
2570 if (ch
->statusflags
& RXSTOPPED
)
2581 printk(KERN_ERR
"<Error> - bc is NULL in receive_data!\n");
2585 wrapmask
= ch
->rxbufsize
- 1;
2587 /* ---------------------------------------------------------------------
2588 Get the head and tail pointers to the receiver queue. Wrap the
2589 head pointer if it has reached the end of the buffer.
2590 ------------------------------------------------------------------------ */
2594 tail
= bc
->rout
& wrapmask
;
2596 bytesAvailable
= (head
- tail
) & wrapmask
;
2598 if (bytesAvailable
== 0)
2601 /* ------------------------------------------------------------------
2602 If CREAD bit is off or device not open, set TX tail to head
2603 --------------------------------------------------------------------- */
2605 if (!tty
|| !ts
|| !(ts
->c_cflag
& CREAD
))
2611 if (tty
->flip
.count
== TTY_FLIPBUF_SIZE
)
2617 printk(KERN_WARNING
"overrun! DigiBoard device %s\n",tty
->name
);
2621 rptr
= tty
->flip
.char_buf_ptr
;
2622 rc
= tty
->flip
.count
;
2624 while (bytesAvailable
> 0)
2625 { /* Begin while there is data on the card */
2627 wrapgap
= (head
>= tail
) ? head
- tail
: ch
->rxbufsize
- tail
;
2629 /* ---------------------------------------------------------------
2630 Even if head has wrapped around only report the amount of
2631 data to be equal to the size - tail. Remember memcpy can't
2632 automaticly wrap around the receive buffer.
2633 ----------------------------------------------------------------- */
2635 dataToRead
= (wrapgap
< bytesAvailable
) ? wrapgap
: bytesAvailable
;
2637 /* --------------------------------------------------------------
2638 Make sure we don't overflow the buffer
2639 ----------------------------------------------------------------- */
2641 if ((rc
+ dataToRead
) > TTY_FLIPBUF_SIZE
)
2642 dataToRead
= TTY_FLIPBUF_SIZE
- rc
;
2644 if (dataToRead
== 0)
2647 /* ---------------------------------------------------------------
2648 Move data read from our card into the line disciplines buffer
2649 for translation if necessary.
2650 ------------------------------------------------------------------ */
2652 if ((memcpy(rptr
, ch
->rxptr
+ tail
, dataToRead
)) != rptr
)
2653 printk(KERN_ERR
"<Error> - receive_data : memcpy failed\n");
2657 tail
= (tail
+ dataToRead
) & wrapmask
;
2658 bytesAvailable
-= dataToRead
;
2660 } /* End while there is data on the card */
2663 tty
->flip
.count
= rc
;
2664 tty
->flip
.char_buf_ptr
= rptr
;
2668 /* Must be called with global data */
2669 tty_schedule_flip(ch
->tty
);
2672 } /* End receive_data */
2674 static int info_ioctl(struct tty_struct
*tty
, struct file
* file
,
2675 unsigned int cmd
, unsigned long arg
)
2678 { /* Begin switch cmd */
2681 { /* Begin case DIGI_GETINFO */
2683 struct digi_info di
;
2686 getUser(brd
, (unsigned int __user
*)arg
);
2688 if ((brd
< 0) || (brd
>= num_cards
) || (num_cards
== 0))
2691 memset(&di
, 0, sizeof(di
));
2694 di
.status
= boards
[brd
].status
;
2695 di
.type
= boards
[brd
].type
;
2696 di
.numports
= boards
[brd
].numports
;
2697 di
.port
= boards
[brd
].port
;
2698 di
.membase
= boards
[brd
].membase
;
2700 if (copy_to_user((void __user
*)arg
, &di
, sizeof (di
)))
2704 } /* End case DIGI_GETINFO */
2707 { /* Begin case DIGI_POLLER */
2709 int brd
= arg
& 0xff000000 >> 16 ;
2710 unsigned char state
= arg
& 0xff ;
2712 if ((brd
< 0) || (brd
>= num_cards
))
2714 printk(KERN_ERR
"<Error> - DIGI POLLER : brd not valid!\n");
2718 digi_poller_inhibited
= state
;
2721 } /* End case DIGI_POLLER */
2724 { /* Begin case DIGI_INIT */
2726 /* ------------------------------------------------------------
2727 This call is made by the apps to complete the initilization
2728 of the board(s). This routine is responsible for setting
2729 the card to its initial state and setting the drivers control
2730 fields to the sutianle settings for the card in question.
2731 ---------------------------------------------------------------- */
2734 for (crd
= 0; crd
< num_cards
; crd
++)
2735 post_fep_init (crd
);
2739 } /* End case DIGI_INIT */
2743 return -ENOIOCTLCMD
;
2745 } /* End switch cmd */
2748 /* --------------------- Begin pc_ioctl ----------------------- */
2750 static int pc_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2752 struct channel
*ch
= (struct channel
*) tty
->driver_data
;
2753 volatile struct board_chan
*bc
;
2754 unsigned int mstat
, mflag
= 0;
2755 unsigned long flags
;
2761 printk(KERN_ERR
"<Error> - ch is NULL in pc_tiocmget!\n");
2770 restore_flags(flags
);
2772 if (mstat
& ch
->m_dtr
)
2775 if (mstat
& ch
->m_rts
)
2778 if (mstat
& ch
->m_cts
)
2781 if (mstat
& ch
->dsr
)
2784 if (mstat
& ch
->m_ri
)
2787 if (mstat
& ch
->dcd
)
2793 static int pc_tiocmset(struct tty_struct
*tty
, struct file
*file
,
2794 unsigned int set
, unsigned int clear
)
2796 struct channel
*ch
= (struct channel
*) tty
->driver_data
;
2797 unsigned long flags
;
2800 printk(KERN_ERR
"<Error> - ch is NULL in pc_tiocmset!\n");
2807 * I think this modemfake stuff is broken. It doesn't
2808 * correctly reflect the behaviour desired by the TIOCM*
2809 * ioctls. Therefore this is probably broken.
2811 if (set
& TIOCM_RTS
) {
2812 ch
->modemfake
|= ch
->m_rts
;
2813 ch
->modem
|= ch
->m_rts
;
2815 if (set
& TIOCM_DTR
) {
2816 ch
->modemfake
|= ch
->m_dtr
;
2817 ch
->modem
|= ch
->m_dtr
;
2819 if (clear
& TIOCM_RTS
) {
2820 ch
->modemfake
|= ch
->m_rts
;
2821 ch
->modem
&= ~ch
->m_rts
;
2823 if (clear
& TIOCM_DTR
) {
2824 ch
->modemfake
|= ch
->m_dtr
;
2825 ch
->modem
&= ~ch
->m_dtr
;
2830 /* --------------------------------------------------------------
2831 The below routine generally sets up parity, baud, flow control
2832 issues, etc.... It effect both control flags and input flags.
2833 ------------------------------------------------------------------ */
2837 restore_flags(flags
);
2841 static int pc_ioctl(struct tty_struct
*tty
, struct file
* file
,
2842 unsigned int cmd
, unsigned long arg
)
2843 { /* Begin pc_ioctl */
2847 unsigned long flags
;
2848 unsigned int mflag
, mstat
;
2849 unsigned char startc
, stopc
;
2850 volatile struct board_chan
*bc
;
2851 struct channel
*ch
= (struct channel
*) tty
->driver_data
;
2852 void __user
*argp
= (void __user
*)arg
;
2858 printk(KERN_ERR
"<Error> - ch is NULL in pc_ioctl!\n");
2864 /* -------------------------------------------------------------------
2865 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
2866 in /usr/src/linux/drivers/char for a good example. In particular
2867 think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
2868 ---------------------------------------------------------------------- */
2871 { /* Begin switch cmd */
2874 if (copy_to_user(argp
,
2875 tty
->termios
, sizeof(struct termios
)))
2880 return get_termio(tty
, argp
);
2882 case TCSBRK
: /* SVID version: non-zero arg --> no break */
2884 retval
= tty_check_change(tty
);
2888 /* Setup an event to indicate when the transmit buffer empties */
2890 setup_empty_event(tty
,ch
);
2891 tty_wait_until_sent(tty
, 0);
2893 digi_send_break(ch
, HZ
/4); /* 1/4 second */
2896 case TCSBRKP
: /* support for POSIX tcsendbreak() */
2898 retval
= tty_check_change(tty
);
2902 /* Setup an event to indicate when the transmit buffer empties */
2904 setup_empty_event(tty
,ch
);
2905 tty_wait_until_sent(tty
, 0);
2906 digi_send_break(ch
, arg
? arg
*(HZ
/10) : HZ
/4);
2910 if (put_user(C_CLOCAL(tty
)?1:0, (unsigned long __user
*)arg
))
2918 if (get_user(value
, (unsigned __user
*)argp
))
2920 tty
->termios
->c_cflag
=
2921 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
2922 (value
? CLOCAL
: 0));
2927 mflag
= pc_tiocmget(tty
, file
);
2928 if (put_user(mflag
, (unsigned long __user
*)argp
))
2933 if (get_user(mstat
, (unsigned __user
*)argp
))
2935 return pc_tiocmset(tty
, file
, mstat
, ~mstat
);
2938 ch
->omodem
|= ch
->m_dtr
;
2941 fepcmd(ch
, SETMODEM
, ch
->m_dtr
, 0, 10, 1);
2943 restore_flags(flags
);
2947 ch
->omodem
&= ~ch
->m_dtr
;
2950 fepcmd(ch
, SETMODEM
, 0, ch
->m_dtr
, 10, 1);
2952 restore_flags(flags
);
2956 if (copy_to_user(argp
, &ch
->digiext
, sizeof(digi_t
)))
2962 if ((cmd
) == (DIGI_SETAW
))
2964 /* Setup an event to indicate when the transmit buffer empties */
2966 setup_empty_event(tty
,ch
);
2967 tty_wait_until_sent(tty
, 0);
2971 /* ldisc lock already held in ioctl */
2972 if (tty
->ldisc
.flush_buffer
)
2973 tty
->ldisc
.flush_buffer(tty
);
2979 if (copy_from_user(&ch
->digiext
, argp
, sizeof(digi_t
)))
2982 if (ch
->digiext
.digi_flags
& DIGI_ALTPIN
)
2984 ch
->dcd
= ch
->m_dsr
;
2985 ch
->dsr
= ch
->m_dcd
;
2989 ch
->dcd
= ch
->m_dcd
;
2990 ch
->dsr
= ch
->m_dsr
;
2996 /* -----------------------------------------------------------------
2997 The below routine generally sets up parity, baud, flow control
2998 issues, etc.... It effect both control flags and input flags.
2999 ------------------------------------------------------------------- */
3003 restore_flags(flags
);
3010 if ((cmd
) == (DIGI_GETFLOW
))
3012 dflow
.startc
= bc
->startc
;
3013 dflow
.stopc
= bc
->stopc
;
3017 dflow
.startc
= bc
->startca
;
3018 dflow
.stopc
= bc
->stopca
;
3021 restore_flags(flags
);
3023 if (copy_to_user(argp
, &dflow
, sizeof(dflow
)))
3029 if ((cmd
) == (DIGI_SETFLOW
))
3031 startc
= ch
->startc
;
3036 startc
= ch
->startca
;
3040 if (copy_from_user(&dflow
, argp
, sizeof(dflow
)))
3043 if (dflow
.startc
!= startc
|| dflow
.stopc
!= stopc
)
3044 { /* Begin if setflow toggled */
3048 if ((cmd
) == (DIGI_SETFLOW
))
3050 ch
->fepstartc
= ch
->startc
= dflow
.startc
;
3051 ch
->fepstopc
= ch
->stopc
= dflow
.stopc
;
3052 fepcmd(ch
, SONOFFC
, ch
->fepstartc
, ch
->fepstopc
, 0, 1);
3056 ch
->fepstartca
= ch
->startca
= dflow
.startc
;
3057 ch
->fepstopca
= ch
->stopca
= dflow
.stopc
;
3058 fepcmd(ch
, SAUXONOFFC
, ch
->fepstartca
, ch
->fepstopca
, 0, 1);
3061 if (ch
->statusflags
& TXSTOPPED
)
3065 restore_flags(flags
);
3067 } /* End if setflow toggled */
3071 return -ENOIOCTLCMD
;
3073 } /* End switch cmd */
3077 } /* End pc_ioctl */
3079 /* --------------------- Begin pc_set_termios ----------------------- */
3081 static void pc_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
3082 { /* Begin pc_set_termios */
3085 unsigned long flags
;
3087 /* ---------------------------------------------------------
3088 verifyChannel returns the channel from the tty struct
3089 if it is valid. This serves as a sanity check.
3090 ------------------------------------------------------------- */
3092 if ((ch
= verifyChannel(tty
)) != NULL
)
3093 { /* Begin if channel valid */
3101 if ((old_termios
->c_cflag
& CRTSCTS
) &&
3102 ((tty
->termios
->c_cflag
& CRTSCTS
) == 0))
3103 tty
->hw_stopped
= 0;
3105 if (!(old_termios
->c_cflag
& CLOCAL
) &&
3106 (tty
->termios
->c_cflag
& CLOCAL
))
3107 wake_up_interruptible(&ch
->open_wait
);
3109 restore_flags(flags
);
3111 } /* End if channel valid */
3113 } /* End pc_set_termios */
3115 /* --------------------- Begin do_softint ----------------------- */
3117 static void do_softint(void *private_
)
3118 { /* Begin do_softint */
3120 struct channel
*ch
= (struct channel
*) private_
;
3123 /* Called in response to a modem change event */
3125 if (ch
&& ch
->magic
== EPCA_MAGIC
)
3126 { /* Begin EPCA_MAGIC */
3128 struct tty_struct
*tty
= ch
->tty
;
3130 if (tty
&& tty
->driver_data
)
3132 if (test_and_clear_bit(EPCA_EVENT_HANGUP
, &ch
->event
))
3133 { /* Begin if clear_bit */
3135 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
3136 wake_up_interruptible(&ch
->open_wait
);
3137 ch
->asyncflags
&= ~ASYNC_NORMAL_ACTIVE
;
3139 } /* End if clear_bit */
3142 } /* End EPCA_MAGIC */
3143 } /* End do_softint */
3145 /* ------------------------------------------------------------
3146 pc_stop and pc_start provide software flow control to the
3147 routine and the pc_ioctl routine.
3148 ---------------------------------------------------------------- */
3150 /* --------------------- Begin pc_stop ----------------------- */
3152 static void pc_stop(struct tty_struct
*tty
)
3153 { /* Begin pc_stop */
3156 unsigned long flags
;
3158 /* ---------------------------------------------------------
3159 verifyChannel returns the channel from the tty struct
3160 if it is valid. This serves as a sanity check.
3161 ------------------------------------------------------------- */
3163 if ((ch
= verifyChannel(tty
)) != NULL
)
3164 { /* Begin if valid channel */
3169 if ((ch
->statusflags
& TXSTOPPED
) == 0)
3170 { /* Begin if transmit stop requested */
3174 /* STOP transmitting now !! */
3176 fepcmd(ch
, PAUSETX
, 0, 0, 0, 0);
3178 ch
->statusflags
|= TXSTOPPED
;
3181 } /* End if transmit stop requested */
3183 restore_flags(flags
);
3185 } /* End if valid channel */
3189 /* --------------------- Begin pc_start ----------------------- */
3191 static void pc_start(struct tty_struct
*tty
)
3192 { /* Begin pc_start */
3196 /* ---------------------------------------------------------
3197 verifyChannel returns the channel from the tty struct
3198 if it is valid. This serves as a sanity check.
3199 ------------------------------------------------------------- */
3201 if ((ch
= verifyChannel(tty
)) != NULL
)
3202 { /* Begin if channel valid */
3204 unsigned long flags
;
3209 /* Just in case output was resumed because of a change in Digi-flow */
3210 if (ch
->statusflags
& TXSTOPPED
)
3211 { /* Begin transmit resume requested */
3213 volatile struct board_chan
*bc
;
3217 if (ch
->statusflags
& LOWWAIT
)
3220 /* Okay, you can start transmitting again... */
3222 fepcmd(ch
, RESUMETX
, 0, 0, 0, 0);
3224 ch
->statusflags
&= ~TXSTOPPED
;
3227 } /* End transmit resume requested */
3229 restore_flags(flags
);
3231 } /* End if channel valid */
3233 } /* End pc_start */
3235 /* ------------------------------------------------------------------
3236 The below routines pc_throttle and pc_unthrottle are used
3237 to slow (And resume) the receipt of data into the kernels
3238 receive buffers. The exact occurrence of this depends on the
3239 size of the kernels receive buffer and what the 'watermarks'
3240 are set to for that buffer. See the n_ttys.c file for more
3242 ______________________________________________________________________ */
3243 /* --------------------- Begin throttle ----------------------- */
3245 static void pc_throttle(struct tty_struct
* tty
)
3246 { /* Begin pc_throttle */
3249 unsigned long flags
;
3251 /* ---------------------------------------------------------
3252 verifyChannel returns the channel from the tty struct
3253 if it is valid. This serves as a sanity check.
3254 ------------------------------------------------------------- */
3256 if ((ch
= verifyChannel(tty
)) != NULL
)
3257 { /* Begin if channel valid */
3263 if ((ch
->statusflags
& RXSTOPPED
) == 0)
3266 fepcmd(ch
, PAUSERX
, 0, 0, 0, 0);
3268 ch
->statusflags
|= RXSTOPPED
;
3271 restore_flags(flags
);
3273 } /* End if channel valid */
3275 } /* End pc_throttle */
3277 /* --------------------- Begin unthrottle ----------------------- */
3279 static void pc_unthrottle(struct tty_struct
*tty
)
3280 { /* Begin pc_unthrottle */
3283 unsigned long flags
;
3284 volatile struct board_chan
*bc
;
3287 /* ---------------------------------------------------------
3288 verifyChannel returns the channel from the tty struct
3289 if it is valid. This serves as a sanity check.
3290 ------------------------------------------------------------- */
3292 if ((ch
= verifyChannel(tty
)) != NULL
)
3293 { /* Begin if channel valid */
3296 /* Just in case output was resumed because of a change in Digi-flow */
3300 if (ch
->statusflags
& RXSTOPPED
)
3305 fepcmd(ch
, RESUMERX
, 0, 0, 0, 0);
3307 ch
->statusflags
&= ~RXSTOPPED
;
3310 restore_flags(flags
);
3312 } /* End if channel valid */
3314 } /* End pc_unthrottle */
3316 /* --------------------- Begin digi_send_break ----------------------- */
3318 void digi_send_break(struct channel
*ch
, int msec
)
3319 { /* Begin digi_send_break */
3321 unsigned long flags
;
3327 /* --------------------------------------------------------------------
3328 Maybe I should send an infinite break here, schedule() for
3329 msec amount of time, and then stop the break. This way,
3330 the user can't screw up the FEP by causing digi_send_break()
3331 to be called (i.e. via an ioctl()) more than once in msec amount
3332 of time. Try this for now...
3333 ------------------------------------------------------------------------ */
3335 fepcmd(ch
, SENDBREAK
, msec
, 0, 10, 0);
3338 restore_flags(flags
);
3340 } /* End digi_send_break */
3342 /* --------------------- Begin setup_empty_event ----------------------- */
3344 static void setup_empty_event(struct tty_struct
*tty
, struct channel
*ch
)
3345 { /* Begin setup_empty_event */
3347 volatile struct board_chan
*bc
= ch
->brdchan
;
3348 unsigned long int flags
;
3353 ch
->statusflags
|= EMPTYWAIT
;
3355 /* ------------------------------------------------------------------
3356 When set the iempty flag request a event to be generated when the
3357 transmit buffer is empty (If there is no BREAK in progress).
3358 --------------------------------------------------------------------- */
3362 restore_flags(flags
);
3364 } /* End setup_empty_event */
3366 /* --------------------- Begin get_termio ----------------------- */
3368 static int get_termio(struct tty_struct
* tty
, struct termio __user
* termio
)
3369 { /* Begin get_termio */
3370 return kernel_termios_to_user_termio(termio
, tty
->termios
);
3371 } /* End get_termio */
3372 /* ---------------------- Begin epca_setup -------------------------- */
3373 void epca_setup(char *str
, int *ints
)
3374 { /* Begin epca_setup */
3376 struct board_info board
;
3377 int index
, loop
, last
;
3381 /* ----------------------------------------------------------------------
3382 If this routine looks a little strange it is because it is only called
3383 if a LILO append command is given to boot the kernel with parameters.
3384 In this way, we can provide the user a method of changing his board
3385 configuration without rebuilding the kernel.
3386 ----------------------------------------------------------------------- */
3390 memset(&board
, 0, sizeof(board
));
3392 /* Assume the data is int first, later we can change it */
3393 /* I think that array position 0 of ints holds the number of args */
3394 for (last
= 0, index
= 1; index
<= ints
[0]; index
++)
3396 { /* Begin parse switch */
3399 board
.status
= ints
[index
];
3401 /* ---------------------------------------------------------
3402 We check for 2 (As opposed to 1; because 2 is a flag
3403 instructing the driver to ignore epcaconfig.) For this
3404 reason we check for 2.
3405 ------------------------------------------------------------ */
3406 if (board
.status
== 2)
3407 { /* Begin ignore epcaconfig as well as lilo cmd line */
3411 } /* End ignore epcaconfig as well as lilo cmd line */
3413 if (board
.status
> 2)
3415 printk(KERN_ERR
"<Error> - epca_setup: Invalid board status 0x%x\n", board
.status
);
3416 invalid_lilo_config
= 1;
3417 setup_error_code
|= INVALID_BOARD_STATUS
;
3424 board
.type
= ints
[index
];
3425 if (board
.type
>= PCIXEM
)
3427 printk(KERN_ERR
"<Error> - epca_setup: Invalid board type 0x%x\n", board
.type
);
3428 invalid_lilo_config
= 1;
3429 setup_error_code
|= INVALID_BOARD_TYPE
;
3436 board
.altpin
= ints
[index
];
3437 if (board
.altpin
> 1)
3439 printk(KERN_ERR
"<Error> - epca_setup: Invalid board altpin 0x%x\n", board
.altpin
);
3440 invalid_lilo_config
= 1;
3441 setup_error_code
|= INVALID_ALTPIN
;
3448 board
.numports
= ints
[index
];
3449 if ((board
.numports
< 2) || (board
.numports
> 256))
3451 printk(KERN_ERR
"<Error> - epca_setup: Invalid board numports 0x%x\n", board
.numports
);
3452 invalid_lilo_config
= 1;
3453 setup_error_code
|= INVALID_NUM_PORTS
;
3456 nbdevs
+= board
.numports
;
3461 board
.port
= (unsigned char *)ints
[index
];
3462 if (ints
[index
] <= 0)
3464 printk(KERN_ERR
"<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board
.port
);
3465 invalid_lilo_config
= 1;
3466 setup_error_code
|= INVALID_PORT_BASE
;
3473 board
.membase
= (unsigned char *)ints
[index
];
3474 if (ints
[index
] <= 0)
3476 printk(KERN_ERR
"<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board
.membase
);
3477 invalid_lilo_config
= 1;
3478 setup_error_code
|= INVALID_MEM_BASE
;
3485 printk(KERN_ERR
"<Error> - epca_setup: Too many integer parms\n");
3488 } /* End parse switch */
3491 { /* Begin while there is a string arg */
3493 /* find the next comma or terminator */
3496 /* While string is not null, and a comma hasn't been found */
3497 while (*temp
&& (*temp
!= ','))
3505 /* Set index to the number of args + 1 */
3512 if (strncmp("Disable", str
, len
) == 0)
3515 if (strncmp("Enable", str
, len
) == 0)
3519 printk(KERN_ERR
"<Error> - epca_setup: Invalid status %s\n", str
);
3520 invalid_lilo_config
= 1;
3521 setup_error_code
|= INVALID_BOARD_STATUS
;
3529 for(loop
= 0; loop
< EPCA_NUM_TYPES
; loop
++)
3530 if (strcmp(board_desc
[loop
], str
) == 0)
3534 /* ---------------------------------------------------------------
3535 If the index incremented above refers to a legitamate board
3537 ------------------------------------------------------------------*/
3539 if (index
< EPCA_NUM_TYPES
)
3543 printk(KERN_ERR
"<Error> - epca_setup: Invalid board type: %s\n", str
);
3544 invalid_lilo_config
= 1;
3545 setup_error_code
|= INVALID_BOARD_TYPE
;
3553 if (strncmp("Disable", str
, len
) == 0)
3556 if (strncmp("Enable", str
, len
) == 0)
3560 printk(KERN_ERR
"<Error> - epca_setup: Invalid altpin %s\n", str
);
3561 invalid_lilo_config
= 1;
3562 setup_error_code
|= INVALID_ALTPIN
;
3570 while (isdigit(*t2
))
3575 printk(KERN_ERR
"<Error> - epca_setup: Invalid port count %s\n", str
);
3576 invalid_lilo_config
= 1;
3577 setup_error_code
|= INVALID_NUM_PORTS
;
3581 /* ------------------------------------------------------------
3582 There is not a man page for simple_strtoul but the code can be
3583 found in vsprintf.c. The first argument is the string to
3584 translate (To an unsigned long obviously), the second argument
3585 can be the address of any character variable or a NULL. If a
3586 variable is given, the end pointer of the string will be stored
3587 in that variable; if a NULL is given the end pointer will
3588 not be returned. The last argument is the base to use. If
3589 a 0 is indicated, the routine will attempt to determine the
3590 proper base by looking at the values prefix (A '0' for octal,
3591 a 'x' for hex, etc ... If a value is given it will use that
3593 ---------------------------------------------------------------- */
3594 board
.numports
= simple_strtoul(str
, NULL
, 0);
3595 nbdevs
+= board
.numports
;
3601 while (isxdigit(*t2
))
3606 printk(KERN_ERR
"<Error> - epca_setup: Invalid i/o address %s\n", str
);
3607 invalid_lilo_config
= 1;
3608 setup_error_code
|= INVALID_PORT_BASE
;
3612 board
.port
= (unsigned char *)simple_strtoul(str
, NULL
, 16);
3618 while (isxdigit(*t2
))
3623 printk(KERN_ERR
"<Error> - epca_setup: Invalid memory base %s\n",str
);
3624 invalid_lilo_config
= 1;
3625 setup_error_code
|= INVALID_MEM_BASE
;
3629 board
.membase
= (unsigned char *)simple_strtoul(str
, NULL
, 16);
3634 printk(KERN_ERR
"PC/Xx: Too many string parms\n");
3639 } /* End while there is a string arg */
3644 printk(KERN_ERR
"PC/Xx: Insufficient parms specified\n");
3648 /* I should REALLY validate the stuff here */
3650 /* Copies our local copy of board into boards */
3651 memcpy((void *)&boards
[num_cards
],(void *)&board
, sizeof(board
));
3654 /* Does this get called once per lilo arg are what ? */
3656 printk(KERN_INFO
"PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3657 num_cards
, board_desc
[board
.type
],
3658 board
.numports
, (int)board
.port
, (unsigned int) board
.membase
);
3662 } /* End epca_setup */
3667 /* ------------------------ Begin init_PCI --------------------------- */
3669 enum epic_board_types
{
3677 /* indexed directly by epic_board_types enum */
3679 unsigned char board_type
;
3680 unsigned bar_idx
; /* PCI base address region */
3681 } epca_info_tbl
[] = {
3689 static int __devinit
epca_init_one (struct pci_dev
*pdev
,
3690 const struct pci_device_id
*ent
)
3692 static int board_num
= -1;
3693 int board_idx
, info_idx
= ent
->driver_data
;
3696 if (pci_enable_device(pdev
))
3700 board_idx
= board_num
+ num_cards
;
3701 if (board_idx
>= MAXBOARDS
)
3704 addr
= pci_resource_start (pdev
, epca_info_tbl
[info_idx
].bar_idx
);
3706 printk (KERN_ERR PFX
"PCI region #%d not available (size 0)\n",
3707 epca_info_tbl
[info_idx
].bar_idx
);
3711 boards
[board_idx
].status
= ENABLED
;
3712 boards
[board_idx
].type
= epca_info_tbl
[info_idx
].board_type
;
3713 boards
[board_idx
].numports
= 0x0;
3714 boards
[board_idx
].port
=
3715 (unsigned char *)((char *) addr
+ PCI_IO_OFFSET
);
3716 boards
[board_idx
].membase
=
3717 (unsigned char *)((char *) addr
);
3719 if (!request_mem_region (addr
+ PCI_IO_OFFSET
, 0x200000, "epca")) {
3720 printk (KERN_ERR PFX
"resource 0x%x @ 0x%lx unavailable\n",
3721 0x200000, addr
+ PCI_IO_OFFSET
);
3725 boards
[board_idx
].re_map_port
= ioremap(addr
+ PCI_IO_OFFSET
, 0x200000);
3726 if (!boards
[board_idx
].re_map_port
) {
3727 printk (KERN_ERR PFX
"cannot map 0x%x @ 0x%lx\n",
3728 0x200000, addr
+ PCI_IO_OFFSET
);
3729 goto err_out_free_pciio
;
3732 if (!request_mem_region (addr
, 0x200000, "epca")) {
3733 printk (KERN_ERR PFX
"resource 0x%x @ 0x%lx unavailable\n",
3735 goto err_out_free_iounmap
;
3738 boards
[board_idx
].re_map_membase
= ioremap(addr
, 0x200000);
3739 if (!boards
[board_idx
].re_map_membase
) {
3740 printk (KERN_ERR PFX
"cannot map 0x%x @ 0x%lx\n",
3741 0x200000, addr
+ PCI_IO_OFFSET
);
3742 goto err_out_free_memregion
;
3745 /* --------------------------------------------------------------
3746 I don't know what the below does, but the hardware guys say
3747 its required on everything except PLX (In this case XRJ).
3748 ---------------------------------------------------------------- */
3749 if (info_idx
!= brd_xrj
) {
3750 pci_write_config_byte(pdev
, 0x40, 0);
3751 pci_write_config_byte(pdev
, 0x46, 0);
3756 err_out_free_memregion
:
3757 release_mem_region (addr
, 0x200000);
3758 err_out_free_iounmap
:
3759 iounmap (boards
[board_idx
].re_map_port
);
3761 release_mem_region (addr
+ PCI_IO_OFFSET
, 0x200000);
3767 static struct pci_device_id epca_pci_tbl
[] = {
3768 { PCI_VENDOR_DIGI
, PCI_DEVICE_XR
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xr
},
3769 { PCI_VENDOR_DIGI
, PCI_DEVICE_XEM
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xem
},
3770 { PCI_VENDOR_DIGI
, PCI_DEVICE_CX
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_cx
},
3771 { PCI_VENDOR_DIGI
, PCI_DEVICE_XRJ
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, brd_xrj
},
3775 MODULE_DEVICE_TABLE(pci
, epca_pci_tbl
);
3777 int __init
init_PCI (void)
3778 { /* Begin init_PCI */
3779 memset (&epca_driver
, 0, sizeof (epca_driver
));
3780 epca_driver
.name
= "epca";
3781 epca_driver
.id_table
= epca_pci_tbl
;
3782 epca_driver
.probe
= epca_init_one
;
3784 return pci_register_driver(&epca_driver
);
3785 } /* End init_PCI */
3787 #endif /* ENABLE_PCI */
3789 MODULE_LICENSE("GPL");