3 * (c) 1999 by Computone Corporation
5 ********************************************************************************
7 * PACKAGE: Linux tty Device Driver for IntelliPort family of multiport
8 * serial I/O controllers.
10 * DESCRIPTION: Mainline code for the device driver
12 *******************************************************************************/
15 // Fix the immediate DSS_NOW problem.
16 // Work over the channel stats return logic in ip2_ipl_ioctl so they
17 // make sense for all 256 possible channels and so the user space
18 // utilities will compile and work properly.
22 // 1.2.14 /\/\|=mhw=|\/\/
23 // Added bounds checking to ip2_ipl_ioctl to avoid potential terroristic acts.
24 // Changed the definition of ip2trace to be more consistent with kernel style
25 // Thanks to Andreas Dilger <adilger@turbolabs.com> for these updates
27 // 1.2.13 /\/\|=mhw=|\/\/
28 // DEVFS: Renamed ttf/{n} to tts/F{n} and cuf/{n} to cua/F{n} to conform
29 // to agreed devfs serial device naming convention.
31 // 1.2.12 /\/\|=mhw=|\/\/
32 // Cleaned up some remove queue cut and paste errors
34 // 1.2.11 /\/\|=mhw=|\/\/
35 // Clean up potential NULL pointer dereferences
36 // Clean up devfs registration
37 // Add kernel command line parsing for io and irq
38 // Compile defaults for io and irq are now set in ip2.c not ip2/ip2.h!
39 // Reworked poll_only hack for explicit parameter setting
40 // You must now EXPLICITLY set poll_only = 1 or set all irqs to 0
41 // Merged ip2_loadmain and old_ip2_init
42 // Converted all instances of interruptible_sleep_on into queue calls
43 // Most of these had no race conditions but better to clean up now
45 // 1.2.10 /\/\|=mhw=|\/\/
46 // Fixed the bottom half interrupt handler and enabled USE_IQI
47 // to split the interrupt handler into a formal top-half / bottom-half
48 // Fixed timing window on high speed processors that queued messages to
49 // the outbound mail fifo faster than the board could handle.
52 // Four box EX was barfing on >128k kmalloc, made structure smaller by
53 // reducing output buffer size
56 // Device file system support (MHW)
60 // Reload of ip2 without unloading ip2main hangs system on cat of /proc/modules
64 // DCD was not reported when CLOCAL was set on call to TIOCMGET
67 // TIOCMGET requests and waits for status return
68 // No DSS interrupts enabled except for DCD when needed
70 // For internal use only
72 //#define IP2DEBUG_INIT
73 //#define IP2DEBUG_OPEN
74 //#define IP2DEBUG_WRITE
75 //#define IP2DEBUG_READ
76 //#define IP2DEBUG_IOCTL
77 //#define IP2DEBUG_IPL
79 //#define IP2DEBUG_TRACE
85 #include <linux/config.h>
87 #include <linux/ctype.h>
88 #include <linux/string.h>
89 #include <linux/fcntl.h>
90 #include <linux/errno.h>
91 #include <linux/module.h>
92 #include <linux/signal.h>
93 #include <linux/sched.h>
94 #include <linux/devfs_fs_kernel.h>
95 #include <linux/timer.h>
96 #include <linux/interrupt.h>
97 #include <linux/pci.h>
99 #include <linux/slab.h>
100 #include <linux/major.h>
101 #include <linux/wait.h>
103 #include <linux/tty.h>
104 #include <linux/tty_flip.h>
105 #include <linux/termios.h>
106 #include <linux/tty_driver.h>
107 #include <linux/serial.h>
108 #include <linux/ptrace.h>
109 #include <linux/ioport.h>
111 #include <linux/cdk.h>
112 #include <linux/comstats.h>
113 #include <linux/delay.h>
115 #include <asm/system.h>
118 #include <asm/bitops.h>
120 #include <linux/vmalloc.h>
121 #include <linux/init.h>
122 #include <asm/serial.h>
124 #include <asm/uaccess.h>
126 #include "./ip2/ip2types.h"
127 #include "./ip2/ip2trace.h"
128 #include "./ip2/ip2ioctl.h"
129 #include "./ip2/ip2.h"
130 #include "./ip2/i2ellis.h"
131 #include "./ip2/i2lib.h"
137 #include <linux/proc_fs.h>
139 static int ip2_read_procmem(char *, char **, off_t, int);
140 int ip2_read_proc(char *, char **, off_t, int, int *, void * );
142 /********************/
143 /* Type Definitions */
144 /********************/
150 /* String constants to identify ourselves */
151 static char *pcName = "Computone IntelliPort Plus multiport driver";
152 static char *pcVersion = "1.2.14";
154 /* String constants for port names */
155 static char *pcDriver_name = "ip2";
156 static char *pcIpl = "ip2ipl";
158 /* Serial subtype definitions */
159 #define SERIAL_TYPE_NORMAL 1
161 // cheezy kludge or genius - you decide?
162 int ip2_loadmain(int *, int *, unsigned char *, int);
163 static unsigned char *Fip_firmware;
164 static int Fip_firmware_size;
166 /***********************/
167 /* Function Prototypes */
168 /***********************/
170 /* Global module entry functions */
172 /* Private (static) functions */
173 static int ip2_open(PTTY, struct file *);
174 static void ip2_close(PTTY, struct file *);
175 static int ip2_write(PTTY, int, const unsigned char *, int);
176 static void ip2_putchar(PTTY, unsigned char);
177 static void ip2_flush_chars(PTTY);
178 static int ip2_write_room(PTTY);
179 static int ip2_chars_in_buf(PTTY);
180 static void ip2_flush_buffer(PTTY);
181 static int ip2_ioctl(PTTY, struct file *, UINT, ULONG);
182 static void ip2_set_termios(PTTY, struct termios *);
183 static void ip2_set_line_discipline(PTTY);
184 static void ip2_throttle(PTTY);
185 static void ip2_unthrottle(PTTY);
186 static void ip2_stop(PTTY);
187 static void ip2_start(PTTY);
188 static void ip2_hangup(PTTY);
189 static int ip2_tiocmget(struct tty_struct *tty, struct file *file);
190 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
191 unsigned int set, unsigned int clear);
193 static void set_irq(int, int);
194 static void ip2_interrupt_bh(i2eBordStrPtr pB);
195 static irqreturn_t ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs);
196 static void ip2_poll(unsigned long arg);
197 static inline void service_all_boards(void);
198 static void do_input(void *p);
199 static void do_status(void *p);
201 static void ip2_wait_until_sent(PTTY,int);
203 static void set_params (i2ChanStrPtr, struct termios *);
204 static int set_modem_info(i2ChanStrPtr, unsigned int, unsigned int *);
205 static int get_serial_info(i2ChanStrPtr, struct serial_struct *);
206 static int set_serial_info(i2ChanStrPtr, struct serial_struct *);
208 static ssize_t ip2_ipl_read(struct file *, char *, size_t, loff_t *);
209 static ssize_t ip2_ipl_write(struct file *, const char *, size_t, loff_t *);
210 static int ip2_ipl_ioctl(struct inode *, struct file *, UINT, ULONG);
211 static int ip2_ipl_open(struct inode *, struct file *);
213 static int DumpTraceBuffer(char *, int);
214 static int DumpFifoBuffer( char *, int);
216 static void ip2_init_board(int);
217 static unsigned short find_eisa_board(int);
223 static struct tty_driver *ip2_tty_driver;
225 /* Here, then is a table of board pointers which the interrupt routine should
226 * scan through to determine who it must service.
228 static unsigned short i2nBoards; // Number of boards here
230 static i2eBordStrPtr i2BoardPtrTable[IP2_MAX_BOARDS];
232 static i2ChanStrPtr DevTable[IP2_MAX_PORTS];
233 //DevTableMem just used to save addresses for kfree
234 static void *DevTableMem[IP2_MAX_BOARDS];
236 /* This is the driver descriptor for the ip2ipl device, which is used to
237 * download the loadware to the boards.
239 static struct file_operations ip2_ipl = {
240 .owner = THIS_MODULE,
241 .read = ip2_ipl_read,
242 .write = ip2_ipl_write,
243 .ioctl = ip2_ipl_ioctl,
244 .open = ip2_ipl_open,
247 static unsigned long irq_counter = 0;
248 static unsigned long bh_counter = 0;
250 // Use immediate queue to service interrupts
252 //#define USE_IQ // PCI&2.2 needs work
254 /* The timer_list entry for our poll routine. If interrupt operation is not
255 * selected, the board is serviced periodically to see if anything needs doing.
257 #define POLL_TIMEOUT (jiffies + 1)
258 static struct timer_list PollTimer = TIMER_INITIALIZER(ip2_poll, 0, 0);
261 #ifdef IP2DEBUG_TRACE
262 /* Trace (debug) buffer data */
263 #define TRACEMAX 1000
264 static unsigned long tracebuf[TRACEMAX];
265 static int tracestuff;
266 static int tracestrip;
267 static int tracewrap;
274 #if defined(MODULE) && defined(IP2DEBUG_OPEN)
275 #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, ttyc=%d, modc=%x -> %s\n", \
276 tty->name,(pCh->flags),ip2_tty_driver->refcount, \
277 tty->count,/*GET_USE_COUNT(module)*/0,s)
286 #include "./ip2/i2ellis.c" /* Extremely low-level interface services */
287 #include "./ip2/i2cmd.c" /* Standard loadware command definitions */
288 #include "./ip2/i2lib.c" /* High level interface services */
290 /* Configuration area for modprobe */
292 MODULE_AUTHOR("Doug McNash");
293 MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
295 static int poll_only = 0;
298 static int Eisa_slot;
301 static char rirqs[IP2_MAX_BOARDS];
302 static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};
304 // Some functions to keep track of what irq's we have
307 is_valid_irq(int irq)
311 while ((*i != 0) && (*i != irq)) {
318 mark_requested_irq( char irq )
320 rirqs[iindx++] = irq;
325 clear_requested_irq( char irq )
328 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
329 if (rirqs[i] == irq) {
339 have_requested_irq( char irq )
341 // array init to zeros so 0 irq will not be requested as a side effect
343 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
350 /******************************************************************************/
351 /* Function: init_module() */
352 /* Parameters: None */
353 /* Returns: Success (0) */
356 /* This is a required entry point for an installable module. It simply calls */
357 /* the driver initialisation function and returns what it returns. */
358 /******************************************************************************/
364 printk (KERN_DEBUG "Loading module ...\n" );
370 /******************************************************************************/
371 /* Function: cleanup_module() */
372 /* Parameters: None */
373 /* Returns: Nothing */
376 /* This is a required entry point for an installable module. It has to return */
377 /* the device and the driver to a passive state. It should not be necessary */
378 /* to reset the board fully, especially as the loadware is downloaded */
379 /* externally rather than in the driver. We just want to disable the board */
380 /* and clear the loadware to a reset state. To allow this there has to be a */
381 /* way to detect whether the board has the loadware running at init time to */
382 /* handle subsequent installations of the driver. All memory allocated by the */
383 /* driver should be returned since it may be unloaded from memory. */
384 /******************************************************************************/
393 printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );
395 /* Stop poll timer if we had one. */
397 del_timer ( &PollTimer );
401 /* Reset the boards we have. */
402 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
403 if ( i2BoardPtrTable[i] ) {
404 iiReset( i2BoardPtrTable[i] );
408 /* The following is done at most once, if any boards were installed. */
409 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
410 if ( i2BoardPtrTable[i] ) {
411 iiResetDelay( i2BoardPtrTable[i] );
412 /* free io addresses and Tibet */
413 release_region( ip2config.addr[i], 8 );
414 devfs_remove("ip2/ipl%d", i);
415 devfs_remove("ip2/stat%d", i);
417 /* Disable and remove interrupt handler. */
418 if ( (ip2config.irq[i] > 0) && have_requested_irq(ip2config.irq[i]) ) {
419 free_irq ( ip2config.irq[i], (void *)&pcName);
420 clear_requested_irq( ip2config.irq[i]);
424 if ( ( err = tty_unregister_driver ( ip2_tty_driver ) ) ) {
425 printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n", err);
427 put_tty_driver(ip2_tty_driver);
428 if ( ( err = unregister_chrdev ( IP2_IPL_MAJOR, pcIpl ) ) ) {
429 printk(KERN_ERR "IP2: failed to unregister IPL driver (%d)\n", err);
431 remove_proc_entry("ip2mem", &proc_root);
434 for (i = 0; i < IP2_MAX_BOARDS; i++) {
436 if ((pB = i2BoardPtrTable[i]) != 0 ) {
438 i2BoardPtrTable[i] = NULL;
440 if ((DevTableMem[i]) != NULL ) {
441 kfree ( DevTableMem[i] );
442 DevTableMem[i] = NULL;
446 /* Cleanup the iiEllis subsystem. */
449 printk (KERN_DEBUG "IP2 Unloaded\n" );
454 static struct tty_operations ip2_ops = {
458 .put_char = ip2_putchar,
459 .flush_chars = ip2_flush_chars,
460 .write_room = ip2_write_room,
461 .chars_in_buffer = ip2_chars_in_buf,
462 .flush_buffer = ip2_flush_buffer,
464 .throttle = ip2_throttle,
465 .unthrottle = ip2_unthrottle,
466 .set_termios = ip2_set_termios,
467 .set_ldisc = ip2_set_line_discipline,
470 .hangup = ip2_hangup,
471 .read_proc = ip2_read_proc,
472 .tiocmget = ip2_tiocmget,
473 .tiocmset = ip2_tiocmset,
476 /******************************************************************************/
477 /* Function: ip2_loadmain() */
478 /* Parameters: irq, io from command line of insmod et. al. */
479 /* pointer to fip firmware and firmware size for boards */
480 /* Returns: Success (0) */
483 /* This was the required entry point for all drivers (now in ip2.c) */
484 /* It performs all */
485 /* initialisation of the devices and driver structures, and registers itself */
486 /* with the relevant kernel modules. */
487 /******************************************************************************/
488 /* SA_INTERRUPT- if set blocks all interrupts else only this line */
489 /* SA_SHIRQ - for shared irq PCI or maybe EISA only */
490 /* SA_RANDOM - can be source for cert. random number generators */
491 #define IP2_SA_FLAGS 0
494 ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
500 i2eBordStrPtr pB = NULL;
503 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );
505 /* process command line arguments to modprobe or
506 insmod i.e. iop & irqp */
507 /* irqp and iop should ALWAYS be specified now... But we check
508 them individually just to be sure, anyways... */
509 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
511 ip2config.addr[i] = iop[i];
514 ip2config.irq[i] = irqp[i];
516 ip2config.irq[i] = 0;
518 // This is a little bit of a hack. If poll_only=1 on command
519 // line back in ip2.c OR all IRQs on all specified boards are
520 // explicitly set to 0, then drop to poll only mode and override
521 // PCI or EISA interrupts. This superceeds the old hack of
522 // triggering if all interrupts were zero (like da default).
523 // Still a hack but less prone to random acts of terrorism.
525 // What we really should do, now that the IRQ default is set
526 // to -1, is to use 0 as a hard coded, do not probe.
529 poll_only |= irqp[i];
533 poll_only = !poll_only;
535 Fip_firmware = firmware;
536 Fip_firmware_size = firmsize;
538 /* Announce our presence */
539 printk( KERN_INFO "%s version %s\n", pcName, pcVersion );
541 // ip2 can be unloaded and reloaded for no good reason
542 // we can't let that happen here or bad things happen
543 // second load hoses board but not system - fixme later
545 printk( KERN_INFO "Still loaded\n" );
550 ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
554 /* Initialise the iiEllis subsystem. */
557 /* Initialize arrays. */
558 memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );
559 memset( DevTable, 0, sizeof DevTable );
561 /* Initialise all the boards we can find (up to the maximum). */
562 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
563 switch ( ip2config.addr[i] ) {
564 case 0: /* skip this slot even if card is present */
567 /* ISA address must be specified */
568 if ( (ip2config.addr[i] < 0x100) || (ip2config.addr[i] > 0x3f8) ) {
569 printk ( KERN_ERR "IP2: Bad ISA board %d address %x\n",
570 i, ip2config.addr[i] );
571 ip2config.addr[i] = 0;
573 ip2config.type[i] = ISA;
575 /* Check for valid irq argument, set for polling if invalid */
576 if (ip2config.irq[i] && !is_valid_irq(ip2config.irq[i])) {
577 printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",ip2config.irq[i]);
578 ip2config.irq[i] = 0;// 0 is polling and is valid in that sense
585 struct pci_dev *pci_dev_i = NULL;
586 pci_dev_i = pci_find_device(PCI_VENDOR_ID_COMPUTONE,
587 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);
588 if (pci_dev_i != NULL) {
590 unsigned char pci_irq;
592 ip2config.type[i] = PCI;
594 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
596 ip2config.addr[i]=(USHORT)(addr&0xfffe);
598 printk( KERN_ERR "IP2: PCI I/O address error\n");
601 pci_read_config_byte(pci_dev_i, PCI_INTERRUPT_LINE, &pci_irq);
603 // If the PCI BIOS assigned it, lets try and use it. If we
604 // can't acquire it or it screws up, deal with it then.
606 // if (!is_valid_irq(pci_irq)) {
607 // printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);
610 ip2config.irq[i] = pci_irq;
611 } else { // ann error
612 ip2config.addr[i] = 0;
613 if (status == PCIBIOS_DEVICE_NOT_FOUND) {
614 printk( KERN_ERR "IP2: PCI board %d not found\n", i );
616 printk( KERN_ERR "IP2: PCI error 0x%x \n", status );
621 printk( KERN_ERR "IP2: PCI card specified but PCI support not\n");
622 printk( KERN_ERR "IP2: configured in this kernel.\n");
623 printk( KERN_ERR "IP2: Recompile kernel with CONFIG_PCI defined!\n");
624 #endif /* CONFIG_PCI */
627 if ( (ip2config.addr[i] = find_eisa_board( Eisa_slot + 1 )) != 0) {
628 /* Eisa_irq set as side effect, boo */
629 ip2config.type[i] = EISA;
631 ip2config.irq[i] = Eisa_irq;
635 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
636 if ( ip2config.addr[i] ) {
637 pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL);
639 i2BoardPtrTable[i] = pB;
640 memset( pB, 0, sizeof(i2eBordStr) );
641 iiSetAddress( pB, ip2config.addr[i], ii2DelayTimer );
644 printk(KERN_ERR "IP2: board memory allocation error\n");
648 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
649 if ( ( pB = i2BoardPtrTable[i] ) != NULL ) {
654 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
655 if ( i2BoardPtrTable[i] != NULL ) {
660 ip2trace (ITRC_NO_PORT, ITRC_INIT, 2, 0 );
662 ip2_tty_driver->owner = THIS_MODULE;
663 ip2_tty_driver->name = "ttyF";
664 ip2_tty_driver->devfs_name = "tts/F";
665 ip2_tty_driver->driver_name = pcDriver_name;
666 ip2_tty_driver->major = IP2_TTY_MAJOR;
667 ip2_tty_driver->minor_start = 0;
668 ip2_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
669 ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
670 ip2_tty_driver->init_termios = tty_std_termios;
671 ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
672 ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
673 tty_set_operations(ip2_tty_driver, &ip2_ops);
675 ip2trace (ITRC_NO_PORT, ITRC_INIT, 3, 0 );
677 /* Register the tty devices. */
678 if ( ( err = tty_register_driver ( ip2_tty_driver ) ) ) {
679 printk(KERN_ERR "IP2: failed to register tty driver (%d)\n", err);
680 put_tty_driver(ip2_tty_driver);
683 /* Register the IPL driver. */
684 if ( ( err = register_chrdev ( IP2_IPL_MAJOR, pcIpl, &ip2_ipl ) ) ) {
685 printk(KERN_ERR "IP2: failed to register IPL device (%d)\n", err );
687 /* Register the read_procmem thing */
688 if (!create_proc_info_entry("ip2mem",0,&proc_root,ip2_read_procmem)) {
689 printk(KERN_ERR "IP2: failed to register read_procmem\n");
692 ip2trace (ITRC_NO_PORT, ITRC_INIT, 4, 0 );
693 /* Register the interrupt handler or poll handler, depending upon the
694 * specified interrupt.
697 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
698 if ( 0 == ip2config.addr[i] ) {
702 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
703 devfs_mk_cdev(MKDEV(IP2_IPL_MAJOR, 4 * i),
704 S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR,
707 devfs_mk_cdev(MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
708 S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR,
711 for ( box = 0; box < ABS_MAX_BOXES; ++box )
713 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
715 if ( pB->i2eChannelMap[box] & (1 << j) )
717 tty_register_device(ip2_tty_driver,
718 j + ABS_BIGGEST_BOX *
719 (box+i*ABS_MAX_BOXES), NULL);
726 // Poll only forces driver to only use polling and
727 // to ignore the probed PCI or EISA interrupts.
728 ip2config.irq[i] = CIR_POLL;
730 if ( ip2config.irq[i] == CIR_POLL ) {
733 PollTimer.expires = POLL_TIMEOUT;
734 add_timer ( &PollTimer );
736 printk( KERN_INFO "IP2: polling\n");
739 if (have_requested_irq(ip2config.irq[i]))
741 rc = request_irq( ip2config.irq[i], ip2_interrupt,
742 IP2_SA_FLAGS | (ip2config.type[i] == PCI ? SA_SHIRQ : 0),
743 pcName, (void *)&pcName);
745 printk(KERN_ERR "IP2: an request_irq failed: error %d\n",rc);
746 ip2config.irq[i] = CIR_POLL;
747 printk( KERN_INFO "IP2: Polling %ld/sec.\n",
748 (POLL_TIMEOUT - jiffies));
751 mark_requested_irq(ip2config.irq[i]);
752 /* Initialise the interrupt handler bottom half (aka slih). */
755 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
756 if ( i2BoardPtrTable[i] ) {
757 set_irq( i, ip2config.irq[i] ); /* set and enable board interrupt */
761 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );
766 EXPORT_SYMBOL(ip2_loadmain);
768 /******************************************************************************/
769 /* Function: ip2_init_board() */
770 /* Parameters: Index of board in configuration structure */
771 /* Returns: Success (0) */
774 /* This function initializes the specified board. The loadware is copied to */
775 /* the board, the channel structures are initialized, and the board details */
776 /* are reported on the console. */
777 /******************************************************************************/
779 ip2_init_board( int boardnum )
782 int nports = 0, nboxes = 0;
784 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
786 if ( !iiInitialize ( pB ) ) {
787 printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",
788 pB->i2eBase, pB->i2eError );
791 printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,
792 ip2config.addr[boardnum], ip2config.irq[boardnum] );
794 if (!request_region( ip2config.addr[boardnum], 8, pcName )) {
795 printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);
799 if ( iiDownloadAll ( pB, (loadHdrStrPtr)Fip_firmware, 1, Fip_firmware_size )
801 printk ( KERN_ERR "IP2: failed to download loadware\n" );
802 goto err_release_region;
804 printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
805 pB->i2ePom.e.porVersion,
806 pB->i2ePom.e.porRevision,
807 pB->i2ePom.e.porSubRev, pB->i2eLVersion,
808 pB->i2eLRevision, pB->i2eLSub );
811 switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {
814 printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",
815 pB->i2ePom.e.porID );
817 goto err_release_region;
820 case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */
821 printk ( KERN_INFO "IP2: ISA-4\n" );
825 case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */
826 printk ( KERN_INFO "IP2: ISA-8 std\n" );
830 case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
831 printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );
835 case POR_ID_FIIEX: /* IntelliPort IIEX */
837 int portnum = IP2_PORTS_PER_BOARD * boardnum;
840 for( box = 0; box < ABS_MAX_BOXES; ++box ) {
841 if ( pB->i2eChannelMap[box] != 0 ) {
844 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
845 if ( pB->i2eChannelMap[box] & 1<< i ) {
850 DevTableMem[boardnum] = pCh =
851 kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );
853 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
854 goto err_release_region;
856 if ( !i2InitChannels( pB, nports, pCh ) ) {
857 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
859 goto err_release_region;
861 pB->i2eChannelPtr = &DevTable[portnum];
862 pB->i2eChannelCnt = ABS_MOST_PORTS;
864 for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {
865 for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
866 if ( pB->i2eChannelMap[box] & (1 << i) ) {
867 DevTable[portnum + i] = pCh;
868 pCh->port_index = portnum + i;
873 printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",
874 nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );
878 DevTableMem[boardnum] = pCh =
879 kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );
881 printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
882 goto err_release_region;
884 pB->i2eChannelPtr = pCh;
885 pB->i2eChannelCnt = nports;
886 if ( !i2InitChannels( pB, nports, pCh ) ) {
887 printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
889 goto err_release_region;
891 pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];
893 for( i = 0; i < pB->i2eChannelCnt; ++i ) {
894 DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;
895 pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;
899 INIT_WORK(&pB->tqueue_interrupt, (void(*)(void*)) ip2_interrupt_bh, pB);
903 release_region(ip2config.addr[boardnum], 8);
906 i2BoardPtrTable[boardnum] = NULL;
910 /******************************************************************************/
911 /* Function: find_eisa_board ( int start_slot ) */
912 /* Parameters: First slot to check */
913 /* Returns: Address of EISA IntelliPort II controller */
916 /* This function searches for an EISA IntelliPort controller, starting */
917 /* from the specified slot number. If the motherboard is not identified as an */
918 /* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
919 /* it returns the base address of the controller. */
920 /******************************************************************************/
921 static unsigned short __init
922 find_eisa_board( int start_slot )
925 unsigned int idm = 0;
926 unsigned int idp = 0;
927 unsigned int base = 0;
934 * First a check for an EISA motherboard, which we do by comparing the
935 * EISA ID registers for the system board and the first couple of slots.
936 * No slot ID should match the system board ID, but on an ISA or PCI
937 * machine the odds are that an empty bus will return similar values for
941 value = (inb(i) << 24) + (inb(i+1) << 16) + (inb(i+2) << 8) + inb(i+3);
942 for( i = 0x1c80; i <= 0x4c80; i += 0x1000 ) {
943 j = (inb(i)<<24)+(inb(i+1)<<16)+(inb(i+2)<<8)+inb(i+3);
949 * OK, so we are inclined to believe that this is an EISA machine. Find
950 * an IntelliPort controller.
952 for( i = start_slot; i < 16; i++ ) {
954 idm = (inb(base + 0xc80) << 8) | (inb(base + 0xc81) & 0xff);
955 idp = (inb(base + 0xc82) << 8) | (inb(base + 0xc83) & 0xff);
957 if ( idm == 0x0e8e ) {
958 if ( idp == 0x0281 || idp == 0x0218 ) {
960 } else if ( idp == 0x0282 || idp == 0x0283 ) {
961 ismine = 3; /* Can do edge-trigger */
972 /* It's some sort of EISA card, but at what address is it configured? */
974 setup_address = base + 0xc88;
975 value = inb(base + 0xc86);
976 setup_irq = (value & 8) ? Valid_Irqs[value & 7] : 0;
978 if ( (ismine & 2) && !(value & 0x10) ) {
979 ismine = 1; /* Could be edging, but not */
982 if ( Eisa_irq == 0 ) {
983 Eisa_irq = setup_irq;
984 } else if ( Eisa_irq != setup_irq ) {
985 printk ( KERN_ERR "IP2: EISA irq mismatch between EISA controllers\n" );
989 printk(KERN_DEBUG "Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",
990 base >> 12, idm, idp, setup_address);
992 printk(KERN_DEBUG ", Interrupt %d %s\n",
993 setup_irq, (ismine & 2) ? "(edge)" : "(level)");
995 printk(KERN_DEBUG ", (polled)\n");
998 return setup_address;
1001 /******************************************************************************/
1002 /* Function: set_irq() */
1003 /* Parameters: index to board in board table */
1005 /* Returns: Success (0) */
1008 /******************************************************************************/
1010 set_irq( int boardnum, int boardIrq )
1012 unsigned char tempCommand[16];
1013 i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
1014 unsigned long flags;
1017 * Notify the boards they may generate interrupts. This is done by
1018 * sending an in-line command to channel 0 on each board. This is why
1019 * the channels have to be defined already. For each board, if the
1020 * interrupt has never been defined, we must do so NOW, directly, since
1021 * board will not send flow control or even give an interrupt until this
1022 * is done. If polling we must send 0 as the interrupt parameter.
1025 // We will get an interrupt here at the end of this function
1027 iiDisableMailIrq(pB);
1029 /* We build up the entire packet header. */
1030 CHANNEL_OF(tempCommand) = 0;
1031 PTYPE_OF(tempCommand) = PTYPE_INLINE;
1032 CMD_COUNT_OF(tempCommand) = 2;
1033 (CMD_OF(tempCommand))[0] = CMDVALUE_IRQ;
1034 (CMD_OF(tempCommand))[1] = boardIrq;
1036 * Write to FIFO; don't bother to adjust fifo capacity for this, since
1037 * board will respond almost immediately after SendMail hit.
1039 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1040 iiWriteBuf(pB, tempCommand, 4);
1041 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1042 pB->i2eUsingIrq = boardIrq;
1043 pB->i2eOutMailWaiting |= MB_OUT_STUFFED;
1045 /* Need to update number of boards before you enable mailbox int */
1048 CHANNEL_OF(tempCommand) = 0;
1049 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1050 CMD_COUNT_OF(tempCommand) = 6;
1051 (CMD_OF(tempCommand))[0] = 88; // SILO
1052 (CMD_OF(tempCommand))[1] = 64; // chars
1053 (CMD_OF(tempCommand))[2] = 32; // ms
1055 (CMD_OF(tempCommand))[3] = 28; // MAX_BLOCK
1056 (CMD_OF(tempCommand))[4] = 64; // chars
1058 (CMD_OF(tempCommand))[5] = 87; // HW_TEST
1059 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1060 iiWriteBuf(pB, tempCommand, 8);
1061 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1063 CHANNEL_OF(tempCommand) = 0;
1064 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1065 CMD_COUNT_OF(tempCommand) = 1;
1066 (CMD_OF(tempCommand))[0] = 84; /* get BOX_IDS */
1067 iiWriteBuf(pB, tempCommand, 3);
1070 // enable heartbeat for test porpoises
1071 CHANNEL_OF(tempCommand) = 0;
1072 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
1073 CMD_COUNT_OF(tempCommand) = 2;
1074 (CMD_OF(tempCommand))[0] = 44; /* get ping */
1075 (CMD_OF(tempCommand))[1] = 200; /* 200 ms */
1076 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
1077 iiWriteBuf(pB, tempCommand, 4);
1078 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
1081 iiEnableMailIrq(pB);
1082 iiSendPendingMail(pB);
1085 /******************************************************************************/
1086 /* Interrupt Handler Section */
1087 /******************************************************************************/
1090 service_all_boards()
1095 /* Service every board on the list */
1096 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
1097 pB = i2BoardPtrTable[i];
1099 i2ServiceBoard( pB );
1105 /******************************************************************************/
1106 /* Function: ip2_interrupt_bh(pB) */
1107 /* Parameters: pB - pointer to the board structure */
1108 /* Returns: Nothing */
1111 /* Service the board in a bottom half interrupt handler and then */
1112 /* reenable the board's interrupts if it has an IRQ number */
1114 /******************************************************************************/
1116 ip2_interrupt_bh(i2eBordStrPtr pB)
1118 // pB better well be set or we have a problem! We can only get
1119 // here from the IMMEDIATE queue. Here, we process the boards.
1120 // Checking pB doesn't cost much and it saves us from the sanity checkers.
1125 i2ServiceBoard( pB );
1126 if( pB->i2eUsingIrq ) {
1127 // Re-enable his interrupts
1128 iiEnableMailIrq(pB);
1134 /******************************************************************************/
1135 /* Function: ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs) */
1136 /* Parameters: irq - interrupt number */
1137 /* pointer to optional device ID structure */
1138 /* pointer to register structure */
1139 /* Returns: Nothing */
1143 /* Our task here is simply to identify each board which needs servicing. */
1144 /* If we are queuing then, queue it to be serviced, and disable its irq */
1145 /* mask otherwise process the board directly. */
1147 /* We could queue by IRQ but that just complicates things on both ends */
1148 /* with very little gain in performance (how many instructions does */
1149 /* it take to iterate on the immediate queue). */
1152 /******************************************************************************/
1154 ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1160 ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq );
1162 /* Service just the boards on the list using this irq */
1163 for( i = 0; i < i2nBoards; ++i ) {
1164 pB = i2BoardPtrTable[i];
1166 // Only process those boards which match our IRQ.
1167 // IRQ = 0 for polled boards, we won't poll "IRQ" boards
1169 if ( pB && (pB->i2eUsingIrq == irq) ) {
1173 if (NO_MAIL_HERE != ( pB->i2eStartMail = iiGetMail(pB))) {
1174 // Disable his interrupt (will be enabled when serviced)
1175 // This is mostly to protect from reentrancy.
1176 iiDisableMailIrq(pB);
1178 // Park the board on the immediate queue for processing.
1179 schedule_work(&pB->tqueue_interrupt);
1181 // Make sure the immediate queue is flagged to fire.
1184 // We are using immediate servicing here. This sucks and can
1185 // cause all sorts of havoc with ppp and others. The failsafe
1186 // check on iiSendPendingMail could also throw a hairball.
1187 i2ServiceBoard( pB );
1188 #endif /* USE_IQI */
1194 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1195 return IRQ_RETVAL(handled);
1198 /******************************************************************************/
1199 /* Function: ip2_poll(unsigned long arg) */
1201 /* Returns: Nothing */
1204 /* This function calls the library routine i2ServiceBoard for each board in */
1205 /* the board table. This is used instead of the interrupt routine when polled */
1206 /* mode is specified. */
1207 /******************************************************************************/
1209 ip2_poll(unsigned long arg)
1211 ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
1213 TimerOn = 0; // it's the truth but not checked in service
1215 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1216 // It will NOT poll boards handled by hard interrupts.
1217 // The issue of queued BH interrups is handled in ip2_interrupt().
1218 ip2_interrupt(0, NULL, NULL);
1220 PollTimer.expires = POLL_TIMEOUT;
1221 add_timer( &PollTimer );
1224 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1227 static void do_input(void *p)
1229 i2ChanStrPtr pCh = p;
1230 unsigned long flags;
1232 ip2trace(CHANN, ITRC_INPUT, 21, 0 );
1235 if ( pCh->pTTY != NULL ) {
1236 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1237 if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) {
1238 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1241 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1243 ip2trace(CHANN, ITRC_INPUT, 22, 0 );
1245 i2InputFlush( pCh );
1249 // code duplicated from n_tty (ldisc)
1250 static inline void isig(int sig, struct tty_struct *tty, int flush)
1253 kill_pg(tty->pgrp, sig, 1);
1254 if (flush || !L_NOFLSH(tty)) {
1255 if ( tty->ldisc.flush_buffer )
1256 tty->ldisc.flush_buffer(tty);
1257 i2InputFlush( tty->driver_data );
1261 static void do_status(void *p)
1263 i2ChanStrPtr pCh = p;
1266 status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) );
1268 ip2trace (CHANN, ITRC_STATUS, 21, 1, status );
1270 if (pCh->pTTY && (status & (I2_BRK|I2_PAR|I2_FRA|I2_OVR)) ) {
1271 if ( (status & I2_BRK) ) {
1272 // code duplicated from n_tty (ldisc)
1273 if (I_IGNBRK(pCh->pTTY))
1275 if (I_BRKINT(pCh->pTTY)) {
1276 isig(SIGINT, pCh->pTTY, 1);
1279 wake_up_interruptible(&pCh->pTTY->read_wait);
1281 #ifdef NEVER_HAPPENS_AS_SETUP_XXX
1282 // and can't work because we don't know the_char
1283 // as the_char is reported on a separate path
1284 // The intelligent board does this stuff as setup
1286 char brkf = TTY_NORMAL;
1287 unsigned char brkc = '\0';
1289 if ( (status & I2_BRK) ) {
1293 else if (status & I2_PAR) {
1296 } else if (status & I2_FRA) {
1299 } else if (status & I2_OVR) {
1303 tmp = pCh->pTTY->real_raw;
1304 pCh->pTTY->real_raw = 0;
1305 pCh->pTTY->ldisc.receive_buf( pCh->pTTY, &brkc, &brkf, 1 );
1306 pCh->pTTY->real_raw = tmp;
1308 #endif /* NEVER_HAPPENS_AS_SETUP_XXX */
1312 if ( status & (I2_DDCD | I2_DDSR | I2_DCTS | I2_DRI) ) {
1313 wake_up_interruptible(&pCh->delta_msr_wait);
1315 if ( (pCh->flags & ASYNC_CHECK_CD) && (status & I2_DDCD) ) {
1316 if ( status & I2_DCD ) {
1318 wake_up_interruptible ( &pCh->open_wait );
1321 if (pCh->pTTY && (!(pCh->pTTY->termios->c_cflag & CLOCAL)) ) {
1322 tty_hangup( pCh->pTTY );
1328 ip2trace (CHANN, ITRC_STATUS, 26, 0 );
1331 /******************************************************************************/
1332 /* Device Open/Close/Ioctl Entry Point Section */
1333 /******************************************************************************/
1335 /******************************************************************************/
1336 /* Function: open_sanity_check() */
1337 /* Parameters: Pointer to tty structure */
1338 /* Pointer to file structure */
1339 /* Returns: Success or failure */
1342 /* Verifies the structure magic numbers and cross links. */
1343 /******************************************************************************/
1344 #ifdef IP2DEBUG_OPEN
1346 open_sanity_check( i2ChanStrPtr pCh, i2eBordStrPtr pBrd )
1348 if ( pBrd->i2eValid != I2E_MAGIC ) {
1349 printk(KERN_ERR "IP2: invalid board structure\n" );
1350 } else if ( pBrd != pCh->pMyBord ) {
1351 printk(KERN_ERR "IP2: board structure pointer mismatch (%p)\n",
1353 } else if ( pBrd->i2eChannelCnt < pCh->port_index ) {
1354 printk(KERN_ERR "IP2: bad device index (%d)\n", pCh->port_index );
1355 } else if (&((i2ChanStrPtr)pBrd->i2eChannelPtr)[pCh->port_index] != pCh) {
1357 printk(KERN_INFO "IP2: all pointers check out!\n" );
1363 /******************************************************************************/
1364 /* Function: ip2_open() */
1365 /* Parameters: Pointer to tty structure */
1366 /* Pointer to file structure */
1367 /* Returns: Success or failure */
1369 /* Description: (MANDATORY) */
1370 /* A successful device open has to run a gauntlet of checks before it */
1371 /* completes. After some sanity checking and pointer setup, the function */
1372 /* blocks until all conditions are satisfied. It then initialises the port to */
1373 /* the default characteristics and returns. */
1374 /******************************************************************************/
1376 ip2_open( PTTY tty, struct file *pFile )
1381 i2ChanStrPtr pCh = DevTable[tty->index];
1383 ip2trace (tty->index, ITRC_OPEN, ITRC_ENTER, 0 );
1385 if ( pCh == NULL ) {
1388 /* Setup pointer links in device and tty structures */
1390 tty->driver_data = pCh;
1392 #ifdef IP2DEBUG_OPEN
1394 "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n",
1395 tty, pFile, tty->name, pCh->infl.hd.i2sChannel, pCh->port_index);
1396 open_sanity_check ( pCh, pCh->pMyBord );
1399 i2QueueCommands(PTYPE_INLINE, pCh, 100, 3, CMD_DTRUP,CMD_RTSUP,CMD_DCD_REP);
1400 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1401 serviceOutgoingFifo( pCh->pMyBord );
1403 /* Block here until the port is ready (per serial and istallion) */
1405 * 1. If the port is in the middle of closing wait for the completion
1406 * and then return the appropriate error.
1408 init_waitqueue_entry(&wait, current);
1409 add_wait_queue(&pCh->close_wait, &wait);
1410 set_current_state( TASK_INTERRUPTIBLE );
1412 if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) {
1413 if ( pCh->flags & ASYNC_CLOSING ) {
1416 if ( tty_hung_up_p(pFile) ) {
1417 set_current_state( TASK_RUNNING );
1418 remove_wait_queue(&pCh->close_wait, &wait);
1419 return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS;
1422 set_current_state( TASK_RUNNING );
1423 remove_wait_queue(&pCh->close_wait, &wait);
1426 * 3. Handle a non-blocking open of a normal port.
1428 if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) {
1429 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1433 * 4. Now loop waiting for the port to be free and carrier present
1436 if ( tty->termios->c_cflag & CLOCAL )
1439 #ifdef IP2DEBUG_OPEN
1440 printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);
1445 init_waitqueue_entry(&wait, current);
1446 add_wait_queue(&pCh->open_wait, &wait);
1449 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
1450 pCh->dataSetOut |= (I2_DTR | I2_RTS);
1451 set_current_state( TASK_INTERRUPTIBLE );
1452 serviceOutgoingFifo( pCh->pMyBord );
1453 if ( tty_hung_up_p(pFile) ) {
1454 set_current_state( TASK_RUNNING );
1455 remove_wait_queue(&pCh->open_wait, &wait);
1456 return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS;
1458 if (!(pCh->flags & ASYNC_CLOSING) &&
1459 (do_clocal || (pCh->dataSetIn & I2_DCD) )) {
1464 #ifdef IP2DEBUG_OPEN
1465 printk(KERN_DEBUG "ASYNC_CLOSING = %s\n",
1466 (pCh->flags & ASYNC_CLOSING)?"True":"False");
1467 printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");
1469 ip2trace (CHANN, ITRC_OPEN, 3, 2, 0,
1470 (pCh->flags & ASYNC_CLOSING) );
1471 /* check for signal */
1472 if (signal_pending(current)) {
1473 rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
1478 set_current_state( TASK_RUNNING );
1479 remove_wait_queue(&pCh->open_wait, &wait);
1481 --pCh->wopen; //why count?
1483 ip2trace (CHANN, ITRC_OPEN, 4, 0 );
1488 pCh->flags |= ASYNC_NORMAL_ACTIVE;
1492 /* first open - Assign termios structure to port */
1493 if ( tty->count == 1 ) {
1494 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1495 /* Now we must send the termios settings to the loadware */
1496 set_params( pCh, NULL );
1500 * Now set any i2lib options. These may go away if the i2lib code ends
1501 * up rolled into the mainline.
1503 pCh->channelOptions |= CO_NBLOCK_WRITE;
1505 #ifdef IP2DEBUG_OPEN
1506 printk (KERN_DEBUG "IP2: open completed\n" );
1508 serviceOutgoingFifo( pCh->pMyBord );
1510 ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 );
1515 /******************************************************************************/
1516 /* Function: ip2_close() */
1517 /* Parameters: Pointer to tty structure */
1518 /* Pointer to file structure */
1519 /* Returns: Nothing */
1524 /******************************************************************************/
1526 ip2_close( PTTY tty, struct file *pFile )
1528 i2ChanStrPtr pCh = tty->driver_data;
1534 ip2trace (CHANN, ITRC_CLOSE, ITRC_ENTER, 0 );
1536 #ifdef IP2DEBUG_OPEN
1537 printk(KERN_DEBUG "IP2:close %s:\n",tty->name);
1540 if ( tty_hung_up_p ( pFile ) ) {
1542 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 2 );
1546 if ( tty->count > 1 ) { /* not the last close */
1548 ip2trace (CHANN, ITRC_CLOSE, 2, 1, 3 );
1552 pCh->flags |= ASYNC_CLOSING; // last close actually
1556 if (pCh->ClosingWaitTime != ASYNC_CLOSING_WAIT_NONE) {
1558 * Before we drop DTR, make sure the transmitter has completely drained.
1559 * This uses an timeout, after which the close
1562 ip2_wait_until_sent(tty, pCh->ClosingWaitTime );
1565 * At this point we stop accepting input. Here we flush the channel
1566 * input buffer which will allow the board to send up more data. Any
1567 * additional input is tossed at interrupt/poll time.
1569 i2InputFlush( pCh );
1571 /* disable DSS reporting */
1572 i2QueueCommands(PTYPE_INLINE, pCh, 100, 4,
1573 CMD_DCD_NREP, CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1574 if ( !tty || (tty->termios->c_cflag & HUPCL) ) {
1575 i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
1576 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1577 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1580 serviceOutgoingFifo ( pCh->pMyBord );
1582 if ( tty->driver->flush_buffer )
1583 tty->driver->flush_buffer(tty);
1584 if ( tty->ldisc.flush_buffer )
1585 tty->ldisc.flush_buffer(tty);
1591 if (pCh->ClosingDelay) {
1592 current->state = TASK_INTERRUPTIBLE;
1593 schedule_timeout(pCh->ClosingDelay);
1595 wake_up_interruptible(&pCh->open_wait);
1598 pCh->flags &=~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1599 wake_up_interruptible(&pCh->close_wait);
1601 #ifdef IP2DEBUG_OPEN
1602 DBG_CNT("ip2_close: after wakeups--");
1606 ip2trace (CHANN, ITRC_CLOSE, ITRC_RETURN, 1, 1 );
1611 /******************************************************************************/
1612 /* Function: ip2_hangup() */
1613 /* Parameters: Pointer to tty structure */
1614 /* Returns: Nothing */
1619 /******************************************************************************/
1621 ip2_hangup ( PTTY tty )
1623 i2ChanStrPtr pCh = tty->driver_data;
1629 ip2trace (CHANN, ITRC_HANGUP, ITRC_ENTER, 0 );
1631 ip2_flush_buffer(tty);
1633 /* disable DSS reporting */
1635 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_DCD_NREP);
1636 i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
1637 if ( (tty->termios->c_cflag & HUPCL) ) {
1638 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 2, CMD_RTSDN, CMD_DTRDN);
1639 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
1640 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
1642 i2QueueCommands(PTYPE_INLINE, pCh, 1, 3,
1643 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
1644 serviceOutgoingFifo ( pCh->pMyBord );
1646 wake_up_interruptible ( &pCh->delta_msr_wait );
1648 pCh->flags &= ~ASYNC_NORMAL_ACTIVE;
1650 wake_up_interruptible ( &pCh->open_wait );
1652 ip2trace (CHANN, ITRC_HANGUP, ITRC_RETURN, 0 );
1655 /******************************************************************************/
1656 /******************************************************************************/
1657 /* Device Output Section */
1658 /******************************************************************************/
1659 /******************************************************************************/
1661 /******************************************************************************/
1662 /* Function: ip2_write() */
1663 /* Parameters: Pointer to tty structure */
1664 /* Flag denoting data is in user (1) or kernel (0) space */
1665 /* Pointer to data */
1666 /* Number of bytes to write */
1667 /* Returns: Number of bytes actually written */
1669 /* Description: (MANDATORY) */
1672 /******************************************************************************/
1674 ip2_write( PTTY tty, int user, const unsigned char *pData, int count)
1676 i2ChanStrPtr pCh = tty->driver_data;
1678 unsigned long flags;
1680 ip2trace (CHANN, ITRC_WRITE, ITRC_ENTER, 2, count, -1 );
1682 /* Flush out any buffered data left over from ip2_putchar() calls. */
1683 ip2_flush_chars( tty );
1685 /* This is the actual move bit. Make sure it does what we need!!!!! */
1686 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1687 bytesSent = i2Output( pCh, pData, count, user );
1688 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1690 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
1692 return bytesSent > 0 ? bytesSent : 0;
1695 /******************************************************************************/
1696 /* Function: ip2_putchar() */
1697 /* Parameters: Pointer to tty structure */
1698 /* Character to write */
1699 /* Returns: Nothing */
1704 /******************************************************************************/
1706 ip2_putchar( PTTY tty, unsigned char ch )
1708 i2ChanStrPtr pCh = tty->driver_data;
1709 unsigned long flags;
1711 // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
1713 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1714 pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
1715 if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
1716 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1717 ip2_flush_chars( tty );
1719 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1721 // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
1724 /******************************************************************************/
1725 /* Function: ip2_flush_chars() */
1726 /* Parameters: Pointer to tty structure */
1727 /* Returns: Nothing */
1731 /******************************************************************************/
1733 ip2_flush_chars( PTTY tty )
1736 i2ChanStrPtr pCh = tty->driver_data;
1737 unsigned long flags;
1739 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1740 if ( pCh->Pbuf_stuff ) {
1742 // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
1745 // We may need to restart i2Output if it does not fullfill this request
1747 strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff, 0 );
1748 if ( strip != pCh->Pbuf_stuff ) {
1749 memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
1751 pCh->Pbuf_stuff -= strip;
1753 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1756 /******************************************************************************/
1757 /* Function: ip2_write_room() */
1758 /* Parameters: Pointer to tty structure */
1759 /* Returns: Number of bytes that the driver can accept */
1763 /******************************************************************************/
1765 ip2_write_room ( PTTY tty )
1768 i2ChanStrPtr pCh = tty->driver_data;
1769 unsigned long flags;
1771 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1772 bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
1773 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1775 ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
1777 return ((bytesFree > 0) ? bytesFree : 0);
1780 /******************************************************************************/
1781 /* Function: ip2_chars_in_buf() */
1782 /* Parameters: Pointer to tty structure */
1783 /* Returns: Number of bytes queued for transmission */
1788 /******************************************************************************/
1790 ip2_chars_in_buf ( PTTY tty )
1792 i2ChanStrPtr pCh = tty->driver_data;
1794 unsigned long flags;
1796 ip2trace (CHANN, ITRC_WRITE, 12, 1, pCh->Obuf_char_count + pCh->Pbuf_stuff );
1798 #ifdef IP2DEBUG_WRITE
1799 printk (KERN_DEBUG "IP2: chars in buffer = %d (%d,%d)\n",
1800 pCh->Obuf_char_count + pCh->Pbuf_stuff,
1801 pCh->Obuf_char_count, pCh->Pbuf_stuff );
1803 READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags);
1804 rc = pCh->Obuf_char_count;
1805 READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags);
1806 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1807 rc += pCh->Pbuf_stuff;
1808 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1812 /******************************************************************************/
1813 /* Function: ip2_flush_buffer() */
1814 /* Parameters: Pointer to tty structure */
1815 /* Returns: Nothing */
1820 /******************************************************************************/
1822 ip2_flush_buffer( PTTY tty )
1824 i2ChanStrPtr pCh = tty->driver_data;
1825 unsigned long flags;
1827 ip2trace (CHANN, ITRC_FLUSH, ITRC_ENTER, 0 );
1829 #ifdef IP2DEBUG_WRITE
1830 printk (KERN_DEBUG "IP2: flush buffer\n" );
1832 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
1833 pCh->Pbuf_stuff = 0;
1834 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
1835 i2FlushOutput( pCh );
1838 ip2trace (CHANN, ITRC_FLUSH, ITRC_RETURN, 0 );
1842 /******************************************************************************/
1843 /* Function: ip2_wait_until_sent() */
1844 /* Parameters: Pointer to tty structure */
1845 /* Timeout for wait. */
1846 /* Returns: Nothing */
1849 /* This function is used in place of the normal tty_wait_until_sent, which */
1850 /* only waits for the driver buffers to be empty (or rather, those buffers */
1851 /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
1852 /* indeterminate number of bytes buffered on the board. */
1853 /******************************************************************************/
1855 ip2_wait_until_sent ( PTTY tty, int timeout )
1858 i2ChanStrPtr pCh = tty->driver_data;
1860 tty_wait_until_sent(tty, timeout );
1861 if ( (i = timeout - (jiffies -i)) > 0)
1862 i2DrainOutput( pCh, i );
1865 /******************************************************************************/
1866 /******************************************************************************/
1867 /* Device Input Section */
1868 /******************************************************************************/
1869 /******************************************************************************/
1871 /******************************************************************************/
1872 /* Function: ip2_throttle() */
1873 /* Parameters: Pointer to tty structure */
1874 /* Returns: Nothing */
1879 /******************************************************************************/
1881 ip2_throttle ( PTTY tty )
1883 i2ChanStrPtr pCh = tty->driver_data;
1885 #ifdef IP2DEBUG_READ
1886 printk (KERN_DEBUG "IP2: throttle\n" );
1889 * Signal the poll/interrupt handlers not to forward incoming data to
1890 * the line discipline. This will cause the buffers to fill up in the
1891 * library and thus cause the library routines to send the flow control
1897 /******************************************************************************/
1898 /* Function: ip2_unthrottle() */
1899 /* Parameters: Pointer to tty structure */
1900 /* Returns: Nothing */
1905 /******************************************************************************/
1907 ip2_unthrottle ( PTTY tty )
1909 i2ChanStrPtr pCh = tty->driver_data;
1910 unsigned long flags;
1912 #ifdef IP2DEBUG_READ
1913 printk (KERN_DEBUG "IP2: unthrottle\n" );
1916 /* Pass incoming data up to the line discipline again. */
1918 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1919 serviceOutgoingFifo( pCh->pMyBord );
1920 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
1921 if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
1922 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1923 #ifdef IP2DEBUG_READ
1924 printk (KERN_DEBUG "i2Input called from unthrottle\n" );
1928 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
1932 ip2_start ( PTTY tty )
1934 i2ChanStrPtr pCh = DevTable[tty->index];
1936 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1937 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_UNSUSPEND);
1938 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_RESUME);
1939 #ifdef IP2DEBUG_WRITE
1940 printk (KERN_DEBUG "IP2: start tx\n" );
1945 ip2_stop ( PTTY tty )
1947 i2ChanStrPtr pCh = DevTable[tty->index];
1949 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_SUSPEND);
1950 #ifdef IP2DEBUG_WRITE
1951 printk (KERN_DEBUG "IP2: stop tx\n" );
1955 /******************************************************************************/
1956 /* Device Ioctl Section */
1957 /******************************************************************************/
1959 static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
1961 i2ChanStrPtr pCh = DevTable[tty->index];
1968 FIXME - the following code is causing a NULL pointer dereference in
1969 2.3.51 in an interrupt handler. It's suppose to prompt the board
1970 to return the DSS signal status immediately. Why doesn't it do
1971 the same thing in 2.2.14?
1974 /* This thing is still busted in the 1.2.12 driver on 2.4.x
1975 and even hoses the serial console so the oops can be trapped.
1978 #ifdef ENABLE_DSSNOW
1979 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DSS_NOW);
1981 init_waitqueue_entry(&wait, current);
1982 add_wait_queue(&pCh->dss_now_wait, &wait);
1983 set_current_state( TASK_INTERRUPTIBLE );
1985 serviceOutgoingFifo( pCh->pMyBord );
1989 set_current_state( TASK_RUNNING );
1990 remove_wait_queue(&pCh->dss_now_wait, &wait);
1992 if (signal_pending(current)) {
1996 return ((pCh->dataSetOut & I2_RTS) ? TIOCM_RTS : 0)
1997 | ((pCh->dataSetOut & I2_DTR) ? TIOCM_DTR : 0)
1998 | ((pCh->dataSetIn & I2_DCD) ? TIOCM_CAR : 0)
1999 | ((pCh->dataSetIn & I2_RI) ? TIOCM_RNG : 0)
2000 | ((pCh->dataSetIn & I2_DSR) ? TIOCM_DSR : 0)
2001 | ((pCh->dataSetIn & I2_CTS) ? TIOCM_CTS : 0);
2004 static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
2005 unsigned int set, unsigned int clear)
2007 i2ChanStrPtr pCh = DevTable[tty->index];
2012 if (set & TIOCM_RTS) {
2013 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSUP);
2014 pCh->dataSetOut |= I2_RTS;
2016 if (set & TIOCM_DTR) {
2017 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRUP);
2018 pCh->dataSetOut |= I2_DTR;
2021 if (clear & TIOCM_RTS) {
2022 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSDN);
2023 pCh->dataSetOut &= ~I2_RTS;
2025 if (clear & TIOCM_DTR) {
2026 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRDN);
2027 pCh->dataSetOut &= ~I2_DTR;
2029 serviceOutgoingFifo( pCh->pMyBord );
2033 /******************************************************************************/
2034 /* Function: ip2_ioctl() */
2035 /* Parameters: Pointer to tty structure */
2036 /* Pointer to file structure */
2039 /* Returns: Success or failure */
2044 /******************************************************************************/
2046 ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2049 i2ChanStrPtr pCh = DevTable[tty->index];
2050 struct async_icount cprev, cnow; /* kernel counter temps */
2051 struct serial_icounter_struct *p_cuser; /* user space */
2053 unsigned long flags;
2055 if ( pCh == NULL ) {
2059 ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
2061 #ifdef IP2DEBUG_IOCTL
2062 printk(KERN_DEBUG "IP2: ioctl cmd (%x), arg (%lx)\n", cmd, arg );
2068 ip2trace (CHANN, ITRC_IOCTL, 2, 1, rc );
2070 rc = get_serial_info(pCh, (struct serial_struct *) arg);
2077 ip2trace (CHANN, ITRC_IOCTL, 3, 1, rc );
2079 rc = set_serial_info(pCh, (struct serial_struct *) arg);
2085 rc = tty_check_change(tty);
2090 //return -ENOIOCTLCMD;
2093 //return -ENOIOCTLCMD;
2096 if (STOP_CHAR(tty) != __DISABLED_CHAR) {
2097 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2098 CMD_XMIT_NOW(STOP_CHAR(tty)));
2102 if (START_CHAR(tty) != __DISABLED_CHAR) {
2103 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
2104 CMD_XMIT_NOW(START_CHAR(tty)));
2112 case TCSBRK: /* SVID version: non-zero arg --> no break */
2113 rc = tty_check_change(tty);
2115 ip2trace (CHANN, ITRC_IOCTL, 4, 1, rc );
2118 ip2_wait_until_sent(tty,0);
2120 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SEND_BRK(250));
2121 serviceOutgoingFifo( pCh->pMyBord );
2126 case TCSBRKP: /* support for POSIX tcsendbreak() */
2127 rc = tty_check_change(tty);
2129 ip2trace (CHANN, ITRC_IOCTL, 5, 1, rc );
2132 ip2_wait_until_sent(tty,0);
2133 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2134 CMD_SEND_BRK(arg ? arg*100 : 250));
2135 serviceOutgoingFifo ( pCh->pMyBord );
2141 ip2trace (CHANN, ITRC_IOCTL, 6, 1, rc );
2143 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
2150 ip2trace (CHANN, ITRC_IOCTL, 7, 1, rc );
2152 rc = get_user(arg,(unsigned long *) arg);
2155 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL)
2156 | (arg ? CLOCAL : 0));
2161 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
2162 * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
2163 * for masking). Caller should use TIOCGICOUNT to see which one it was
2166 save_flags(flags);cli();
2167 cprev = pCh->icount; /* note the counters on entry */
2168 restore_flags(flags);
2169 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
2170 CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
2171 init_waitqueue_entry(&wait, current);
2172 add_wait_queue(&pCh->delta_msr_wait, &wait);
2173 set_current_state( TASK_INTERRUPTIBLE );
2175 serviceOutgoingFifo( pCh->pMyBord );
2177 ip2trace (CHANN, ITRC_IOCTL, 10, 0 );
2181 ip2trace (CHANN, ITRC_IOCTL, 11, 0 );
2183 /* see if a signal did it */
2184 if (signal_pending(current)) {
2188 save_flags(flags);cli();
2189 cnow = pCh->icount; /* atomic copy */
2190 restore_flags(flags);
2191 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2192 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2193 rc = -EIO; /* no change => rc */
2196 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2197 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2198 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2199 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2205 set_current_state( TASK_RUNNING );
2206 remove_wait_queue(&pCh->delta_msr_wait, &wait);
2208 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 3,
2209 CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
2210 if ( ! (pCh->flags & ASYNC_CHECK_CD)) {
2211 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DCD_NREP);
2213 serviceOutgoingFifo( pCh->pMyBord );
2218 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2219 * Return: write counters to the user passed counter struct
2220 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2221 * only 0->1 is counted. The controller is quite capable of counting
2222 * both, but this done to preserve compatibility with the standard
2226 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
2228 save_flags(flags);cli();
2230 restore_flags(flags);
2231 p_cuser = (struct serial_icounter_struct *) arg;
2232 rc = put_user(cnow.cts, &p_cuser->cts);
2233 rc = put_user(cnow.dsr, &p_cuser->dsr);
2234 rc = put_user(cnow.rng, &p_cuser->rng);
2235 rc = put_user(cnow.dcd, &p_cuser->dcd);
2236 rc = put_user(cnow.rx, &p_cuser->rx);
2237 rc = put_user(cnow.tx, &p_cuser->tx);
2238 rc = put_user(cnow.frame, &p_cuser->frame);
2239 rc = put_user(cnow.overrun, &p_cuser->overrun);
2240 rc = put_user(cnow.parity, &p_cuser->parity);
2241 rc = put_user(cnow.brk, &p_cuser->brk);
2242 rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
2246 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
2247 * will be passed to the line discipline for it to handle.
2253 case TIOCSERGSTRUCT:
2254 case TIOCSERGETMULTI:
2255 case TIOCSERSETMULTI:
2258 ip2trace (CHANN, ITRC_IOCTL, 12, 0 );
2264 ip2trace (CHANN, ITRC_IOCTL, ITRC_RETURN, 0 );
2269 /******************************************************************************/
2270 /* Function: GetSerialInfo() */
2271 /* Parameters: Pointer to channel structure */
2272 /* Pointer to old termios structure */
2273 /* Returns: Nothing */
2276 /* This is to support the setserial command, and requires processing of the */
2277 /* standard Linux serial structure. */
2278 /******************************************************************************/
2280 get_serial_info ( i2ChanStrPtr pCh, struct serial_struct *retinfo )
2282 struct serial_struct tmp;
2289 memset ( &tmp, 0, sizeof(tmp) );
2290 tmp.type = pCh->pMyBord->channelBtypes.bid_value[(pCh->port_index & (IP2_PORTS_PER_BOARD-1))/16];
2291 if (BID_HAS_654(tmp.type)) {
2292 tmp.type = PORT_16650;
2294 tmp.type = PORT_CIRRUS;
2296 tmp.line = pCh->port_index;
2297 tmp.port = pCh->pMyBord->i2eBase;
2298 tmp.irq = ip2config.irq[pCh->port_index/64];
2299 tmp.flags = pCh->flags;
2300 tmp.baud_base = pCh->BaudBase;
2301 tmp.close_delay = pCh->ClosingDelay;
2302 tmp.closing_wait = pCh->ClosingWaitTime;
2303 tmp.custom_divisor = pCh->BaudDivisor;
2304 rc = copy_to_user(retinfo,&tmp,sizeof(*retinfo));
2308 /******************************************************************************/
2309 /* Function: SetSerialInfo() */
2310 /* Parameters: Pointer to channel structure */
2311 /* Pointer to old termios structure */
2312 /* Returns: Nothing */
2315 /* This function provides support for setserial, which uses the TIOCSSERIAL */
2316 /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
2317 /* change the IRQ, address or type of the port the ioctl fails. */
2318 /******************************************************************************/
2320 set_serial_info( i2ChanStrPtr pCh, struct serial_struct *new_info )
2322 struct serial_struct ns;
2323 int old_flags, old_baud_divisor;
2329 if (copy_from_user(&ns, new_info, sizeof (ns))) {
2334 * We don't allow setserial to change IRQ, board address, type or baud
2335 * base. Also line nunber as such is meaningless but we use it for our
2336 * array index so it is fixed also.
2338 if ( (ns.irq != ip2config.irq[pCh->port_index])
2339 || ((int) ns.port != ((int) (pCh->pMyBord->i2eBase)))
2340 || (ns.baud_base != pCh->BaudBase)
2341 || (ns.line != pCh->port_index) ) {
2345 old_flags = pCh->flags;
2346 old_baud_divisor = pCh->BaudDivisor;
2348 if ( !capable(CAP_SYS_ADMIN) ) {
2349 if ( ( ns.close_delay != pCh->ClosingDelay ) ||
2350 ( (ns.flags & ~ASYNC_USR_MASK) !=
2351 (pCh->flags & ~ASYNC_USR_MASK) ) ) {
2355 pCh->flags = (pCh->flags & ~ASYNC_USR_MASK) |
2356 (ns.flags & ASYNC_USR_MASK);
2357 pCh->BaudDivisor = ns.custom_divisor;
2359 pCh->flags = (pCh->flags & ~ASYNC_FLAGS) |
2360 (ns.flags & ASYNC_FLAGS);
2361 pCh->BaudDivisor = ns.custom_divisor;
2362 pCh->ClosingDelay = ns.close_delay * HZ/100;
2363 pCh->ClosingWaitTime = ns.closing_wait * HZ/100;
2366 if ( ( (old_flags & ASYNC_SPD_MASK) != (pCh->flags & ASYNC_SPD_MASK) )
2367 || (old_baud_divisor != pCh->BaudDivisor) ) {
2368 // Invalidate speed and reset parameters
2369 set_params( pCh, NULL );
2375 /******************************************************************************/
2376 /* Function: ip2_set_termios() */
2377 /* Parameters: Pointer to tty structure */
2378 /* Pointer to old termios structure */
2379 /* Returns: Nothing */
2384 /******************************************************************************/
2386 ip2_set_termios( PTTY tty, struct termios *old_termios )
2388 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
2390 #ifdef IP2DEBUG_IOCTL
2391 printk (KERN_DEBUG "IP2: set termios %p\n", old_termios );
2394 set_params( pCh, old_termios );
2397 /******************************************************************************/
2398 /* Function: ip2_set_line_discipline() */
2399 /* Parameters: Pointer to tty structure */
2400 /* Returns: Nothing */
2402 /* Description: Does nothing */
2405 /******************************************************************************/
2407 ip2_set_line_discipline ( PTTY tty )
2409 #ifdef IP2DEBUG_IOCTL
2410 printk (KERN_DEBUG "IP2: set line discipline\n" );
2413 ip2trace (((i2ChanStrPtr)tty->driver_data)->port_index, ITRC_IOCTL, 16, 0 );
2417 /******************************************************************************/
2418 /* Function: SetLine Characteristics() */
2419 /* Parameters: Pointer to channel structure */
2420 /* Returns: Nothing */
2423 /* This routine is called to update the channel structure with the new line */
2424 /* characteristics, and send the appropriate commands to the board when they */
2426 /******************************************************************************/
2428 set_params( i2ChanStrPtr pCh, struct termios *o_tios )
2430 tcflag_t cflag, iflag, lflag;
2431 char stop_char, start_char;
2432 struct termios dummy;
2434 lflag = pCh->pTTY->termios->c_lflag;
2435 cflag = pCh->pTTY->termios->c_cflag;
2436 iflag = pCh->pTTY->termios->c_iflag;
2438 if (o_tios == NULL) {
2439 dummy.c_lflag = ~lflag;
2440 dummy.c_cflag = ~cflag;
2441 dummy.c_iflag = ~iflag;
2446 switch ( cflag & CBAUD ) {
2448 i2QueueCommands( PTYPE_BYPASS, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
2449 pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
2450 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
2451 pCh->pTTY->termios->c_cflag |= (CBAUD & o_tios->c_cflag);
2456 * This is the speed that is overloaded with all the other high
2457 * speeds, depending upon the flag settings.
2459 if ( ( pCh->flags & ASYNC_SPD_MASK ) == ASYNC_SPD_HI ) {
2460 pCh->speed = CBR_57600;
2461 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI ) {
2462 pCh->speed = CBR_115200;
2463 } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST ) {
2464 pCh->speed = CBR_C1;
2466 pCh->speed = CBR_38400;
2469 case B50: pCh->speed = CBR_50; break;
2470 case B75: pCh->speed = CBR_75; break;
2471 case B110: pCh->speed = CBR_110; break;
2472 case B134: pCh->speed = CBR_134; break;
2473 case B150: pCh->speed = CBR_150; break;
2474 case B200: pCh->speed = CBR_200; break;
2475 case B300: pCh->speed = CBR_300; break;
2476 case B600: pCh->speed = CBR_600; break;
2477 case B1200: pCh->speed = CBR_1200; break;
2478 case B1800: pCh->speed = CBR_1800; break;
2479 case B2400: pCh->speed = CBR_2400; break;
2480 case B4800: pCh->speed = CBR_4800; break;
2481 case B9600: pCh->speed = CBR_9600; break;
2482 case B19200: pCh->speed = CBR_19200; break;
2483 case B57600: pCh->speed = CBR_57600; break;
2484 case B115200: pCh->speed = CBR_115200; break;
2485 case B153600: pCh->speed = CBR_153600; break;
2486 case B230400: pCh->speed = CBR_230400; break;
2487 case B307200: pCh->speed = CBR_307200; break;
2488 case B460800: pCh->speed = CBR_460800; break;
2489 case B921600: pCh->speed = CBR_921600; break;
2490 default: pCh->speed = CBR_9600; break;
2492 if ( pCh->speed == CBR_C1 ) {
2493 // Process the custom speed parameters.
2494 int bps = pCh->BaudBase / pCh->BaudDivisor;
2495 if ( bps == 921600 ) {
2496 pCh->speed = CBR_921600;
2499 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_BAUD_DEF1(bps) );
2502 i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_SETBAUD(pCh->speed));
2504 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
2505 pCh->dataSetOut |= (I2_DTR | I2_RTS);
2507 if ( (CSTOPB & cflag) ^ (CSTOPB & o_tios->c_cflag))
2509 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2510 CMD_SETSTOP( ( cflag & CSTOPB ) ? CST_2 : CST_1));
2512 if (((PARENB|PARODD) & cflag) ^ ((PARENB|PARODD) & o_tios->c_cflag))
2514 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
2516 (cflag & PARENB ? (cflag & PARODD ? CSP_OD : CSP_EV) : CSP_NP)
2520 /* byte size and parity */
2521 if ( (CSIZE & cflag)^(CSIZE & o_tios->c_cflag))
2524 switch ( cflag & CSIZE ) {
2525 case CS5: datasize = CSZ_5; break;
2526 case CS6: datasize = CSZ_6; break;
2527 case CS7: datasize = CSZ_7; break;
2528 case CS8: datasize = CSZ_8; break;
2529 default: datasize = CSZ_5; break; /* as per serial.c */
2531 i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1, CMD_SETBITS(datasize) );
2533 /* Process CTS flow control flag setting */
2534 if ( (cflag & CRTSCTS) ) {
2535 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2536 2, CMD_CTSFL_ENAB, CMD_RTSFL_ENAB);
2538 i2QueueCommands(PTYPE_INLINE, pCh, 100,
2539 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
2542 // Process XON/XOFF flow control flags settings
2544 stop_char = STOP_CHAR(pCh->pTTY);
2545 start_char = START_CHAR(pCh->pTTY);
2547 //////////// can't be \000
2548 if (stop_char == __DISABLED_CHAR )
2550 stop_char = ~__DISABLED_CHAR;
2552 if (start_char == __DISABLED_CHAR )
2554 start_char = ~__DISABLED_CHAR;
2556 /////////////////////////////////
2558 if ( o_tios->c_cc[VSTART] != start_char )
2560 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXON(start_char));
2561 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXON(start_char));
2563 if ( o_tios->c_cc[VSTOP] != stop_char )
2565 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXOFF(stop_char));
2566 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXOFF(stop_char));
2568 if (stop_char == __DISABLED_CHAR )
2570 stop_char = ~__DISABLED_CHAR; //TEST123
2573 if ((iflag & (IXOFF))^(o_tios->c_iflag & (IXOFF)))
2575 if ( iflag & IXOFF ) { // Enable XOFF output flow control
2576 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_XON));
2577 } else { // Disable XOFF output flow control
2579 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_NONE));
2582 if (start_char == __DISABLED_CHAR )
2586 if ((iflag & (IXON|IXANY)) ^ (o_tios->c_iflag & (IXON|IXANY)))
2588 if ( iflag & IXON ) {
2589 if ( iflag & IXANY ) { // Enable XON/XANY output flow control
2590 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XANY));
2591 } else { // Enable XON output flow control
2592 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XON));
2594 } else { // Disable XON output flow control
2596 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_NONE));
2599 if ( (iflag & ISTRIP) ^ ( o_tios->c_iflag & (ISTRIP)) )
2601 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2602 CMD_ISTRIP_OPT((iflag & ISTRIP ? 1 : 0)));
2604 if ( (iflag & INPCK) ^ ( o_tios->c_iflag & (INPCK)) )
2606 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
2607 CMD_PARCHK((iflag & INPCK) ? CPK_ENAB : CPK_DSAB));
2610 if ( (iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR))
2611 ^ ( o_tios->c_iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR)) )
2616 if ( iflag & IGNBRK ) { /* Ignore breaks altogether */
2617 /* Ignore breaks altogether */
2618 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_NREP);
2620 if ( iflag & BRKINT ) {
2621 if ( iflag & PARMRK ) {
2622 brkrpt = 0x0a; // exception an inline triple
2624 brkrpt = 0x1a; // exception and NULL
2626 brkrpt |= 0x04; // flush input
2628 if ( iflag & PARMRK ) {
2629 brkrpt = 0x0b; //POSIX triple \0377 \0 \0
2631 brkrpt = 0x01; // Null only
2634 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_REP(brkrpt));
2637 if (iflag & IGNPAR) {
2639 /* would be 2 for not cirrus bug */
2640 /* would be 0x20 cept for cirrus bug */
2642 if ( iflag & PARMRK ) {
2644 * Replace error characters with 3-byte sequence (\0377,\0,char)
2647 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_ISTRIP_OPT((char)0));
2652 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SET_ERROR(parrpt));
2654 if (cflag & CLOCAL) {
2655 // Status reporting fails for DCD if this is off
2656 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_NREP);
2657 pCh->flags &= ~ASYNC_CHECK_CD;
2659 i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_REP);
2660 pCh->flags |= ASYNC_CHECK_CD;
2664 do_flags_thing: // This is a test, we don't do the flags thing
2666 if ( (cflag & CRTSCTS) ) {
2667 cflag |= 014000000000;
2669 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1,
2670 CMD_UNIX_FLAGS(iflag,cflag,lflag));
2674 i2DrainOutput( pCh, 100 );
2677 /******************************************************************************/
2678 /* IPL Device Section */
2679 /******************************************************************************/
2681 /******************************************************************************/
2682 /* Function: ip2_ipl_read() */
2683 /* Parameters: Pointer to device inode */
2684 /* Pointer to file structure */
2685 /* Pointer to data */
2686 /* Number of bytes to read */
2687 /* Returns: Success or failure */
2689 /* Description: Ugly */
2692 /******************************************************************************/
2696 ip2_ipl_read(struct file *pFile, char *pData, size_t count, loff_t *off )
2698 unsigned int minor = iminor(pFile->f_dentry->d_inode);
2702 printk (KERN_DEBUG "IP2IPL: read %p, %d bytes\n", pData, count );
2706 case 0: // IPL device
2709 case 1: // Status dump
2712 case 2: // Ping device
2715 case 3: // Trace device
2716 rc = DumpTraceBuffer ( pData, count );
2718 case 4: // Trace device
2719 rc = DumpFifoBuffer ( pData, count );
2729 DumpFifoBuffer ( char *pData, int count )
2733 rc = copy_to_user(pData, DBGBuf, count);
2735 printk(KERN_DEBUG "Last index %d\n", I );
2738 #endif /* DEBUG_FIFO */
2743 DumpTraceBuffer ( char *pData, int count )
2745 #ifdef IP2DEBUG_TRACE
2749 int *pIndex = (int*)pData;
2751 if ( count < (sizeof(int) * 6) ) {
2754 rc = put_user(tracewrap, pIndex );
2755 rc = put_user(TRACEMAX, ++pIndex );
2756 rc = put_user(tracestrip, ++pIndex );
2757 rc = put_user(tracestuff, ++pIndex );
2758 pData += sizeof(int) * 6;
2759 count -= sizeof(int) * 6;
2761 dumpcount = tracestuff - tracestrip;
2762 if ( dumpcount < 0 ) {
2763 dumpcount += TRACEMAX;
2765 if ( dumpcount > count ) {
2768 chunk = TRACEMAX - tracestrip;
2769 if ( dumpcount > chunk ) {
2770 rc = copy_to_user(pData, &tracebuf[tracestrip],
2771 chunk * sizeof(tracebuf[0]) );
2772 pData += chunk * sizeof(tracebuf[0]);
2774 chunk = dumpcount - chunk;
2778 rc = copy_to_user(pData, &tracebuf[tracestrip],
2779 chunk * sizeof(tracebuf[0]) );
2780 tracestrip += chunk;
2783 rc = put_user(tracestrip, ++pIndex );
2784 rc = put_user(tracestuff, ++pIndex );
2792 /******************************************************************************/
2793 /* Function: ip2_ipl_write() */
2795 /* Pointer to file structure */
2796 /* Pointer to data */
2797 /* Number of bytes to write */
2798 /* Returns: Success or failure */
2803 /******************************************************************************/
2805 ip2_ipl_write(struct file *pFile, const char *pData, size_t count, loff_t *off)
2808 printk (KERN_DEBUG "IP2IPL: write %p, %d bytes\n", pData, count );
2813 /******************************************************************************/
2814 /* Function: ip2_ipl_ioctl() */
2815 /* Parameters: Pointer to device inode */
2816 /* Pointer to file structure */
2819 /* Returns: Success or failure */
2824 /******************************************************************************/
2826 ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
2828 unsigned int iplminor = iminor(pInode);
2830 ULONG *pIndex = (ULONG*)arg;
2831 i2eBordStrPtr pB = i2BoardPtrTable[iplminor / 4];
2835 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2838 switch ( iplminor ) {
2839 case 0: // IPL device
2842 case 1: // Status dump
2847 case 64: /* Driver - ip2stat */
2848 rc = put_user(ip2_tty_driver->refcount, pIndex++ );
2849 rc = put_user(irq_counter, pIndex++ );
2850 rc = put_user(bh_counter, pIndex++ );
2853 case 65: /* Board - ip2stat */
2855 rc = copy_to_user((char*)arg, (char*)pB, sizeof(i2eBordStr) );
2856 rc = put_user(INB(pB->i2eStatus),
2857 (ULONG*)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
2864 if (cmd < IP2_MAX_PORTS) {
2865 pCh = DevTable[cmd];
2868 rc = copy_to_user((char*)arg, (char*)pCh, sizeof(i2ChanStr) );
2878 case 2: // Ping device
2881 case 3: // Trace device
2883 rc = put_user(iiSendPendingMail, pIndex++ );
2884 rc = put_user(i2InitChannels, pIndex++ );
2885 rc = put_user(i2QueueNeeds, pIndex++ );
2886 rc = put_user(i2QueueCommands, pIndex++ );
2887 rc = put_user(i2GetStatus, pIndex++ );
2888 rc = put_user(i2Input, pIndex++ );
2889 rc = put_user(i2InputFlush, pIndex++ );
2890 rc = put_user(i2Output, pIndex++ );
2891 rc = put_user(i2FlushOutput, pIndex++ );
2892 rc = put_user(i2DrainWakeup, pIndex++ );
2893 rc = put_user(i2DrainOutput, pIndex++ );
2894 rc = put_user(i2OutputFree, pIndex++ );
2895 rc = put_user(i2StripFifo, pIndex++ );
2896 rc = put_user(i2StuffFifoBypass, pIndex++ );
2897 rc = put_user(i2StuffFifoFlow, pIndex++ );
2898 rc = put_user(i2StuffFifoInline, pIndex++ );
2899 rc = put_user(i2ServiceBoard, pIndex++ );
2900 rc = put_user(serviceOutgoingFifo, pIndex++ );
2901 // rc = put_user(ip2_init, pIndex++ );
2902 rc = put_user(ip2_init_board, pIndex++ );
2903 rc = put_user(find_eisa_board, pIndex++ );
2904 rc = put_user(set_irq, pIndex++ );
2905 rc = put_user(ip2_interrupt, pIndex++ );
2906 rc = put_user(ip2_poll, pIndex++ );
2907 rc = put_user(service_all_boards, pIndex++ );
2908 rc = put_user(do_input, pIndex++ );
2909 rc = put_user(do_status, pIndex++ );
2910 #ifndef IP2DEBUG_OPEN
2911 rc = put_user(0, pIndex++ );
2913 rc = put_user(open_sanity_check, pIndex++ );
2915 rc = put_user(ip2_open, pIndex++ );
2916 rc = put_user(ip2_close, pIndex++ );
2917 rc = put_user(ip2_hangup, pIndex++ );
2918 rc = put_user(ip2_write, pIndex++ );
2919 rc = put_user(ip2_putchar, pIndex++ );
2920 rc = put_user(ip2_flush_chars, pIndex++ );
2921 rc = put_user(ip2_write_room, pIndex++ );
2922 rc = put_user(ip2_chars_in_buf, pIndex++ );
2923 rc = put_user(ip2_flush_buffer, pIndex++ );
2925 //rc = put_user(ip2_wait_until_sent, pIndex++ );
2926 rc = put_user(0, pIndex++ );
2928 rc = put_user(ip2_throttle, pIndex++ );
2929 rc = put_user(ip2_unthrottle, pIndex++ );
2930 rc = put_user(ip2_ioctl, pIndex++ );
2931 rc = put_user(0, pIndex++ );
2932 rc = put_user(get_serial_info, pIndex++ );
2933 rc = put_user(set_serial_info, pIndex++ );
2934 rc = put_user(ip2_set_termios, pIndex++ );
2935 rc = put_user(ip2_set_line_discipline, pIndex++ );
2936 rc = put_user(set_params, pIndex++ );
2950 /******************************************************************************/
2951 /* Function: ip2_ipl_open() */
2952 /* Parameters: Pointer to device inode */
2953 /* Pointer to file structure */
2954 /* Returns: Success or failure */
2959 /******************************************************************************/
2961 ip2_ipl_open( struct inode *pInode, struct file *pFile )
2963 unsigned int iplminor = iminor(pInode);
2968 printk (KERN_DEBUG "IP2IPL: open\n" );
2972 // These are the IPL devices
2979 // These are the status devices
2986 // These are the debug devices
2991 pB = i2BoardPtrTable[iplminor / 4];
2992 pCh = (i2ChanStrPtr) pB->i2eChannelPtr;
2995 // This is the trace device
3001 /******************************************************************************/
3002 /* Function: ip2_read_procmem */
3005 /* Returns: Length of output */
3008 /* Supplies some driver operating parameters */
3009 /* Not real useful unless your debugging the fifo */
3011 /******************************************************************************/
3013 #define LIMIT (PAGE_SIZE - 120)
3016 ip2_read_procmem(char *buf, char **start, off_t offset, int len)
3025 #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
3026 #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
3027 #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
3029 len += sprintf(buf+len,"\n");
3031 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
3032 pB = i2BoardPtrTable[i];
3034 len += sprintf(buf+len,"board %d:\n",i);
3035 len += sprintf(buf+len,"\tFifo rem: %d mty: %x outM %x\n",
3036 pB->i2eFifoRemains,pB->i2eWaitingForEmptyFifo,pB->i2eOutMailWaiting);
3040 len += sprintf(buf+len,"#: tty flags, port flags, cflags, iflags\n");
3041 for (i=0; i < IP2_MAX_PORTS; i++) {
3047 if (tty && tty->count) {
3048 len += sprintf(buf+len,FMTLINE,i,(int)tty->flags,pCh->flags,
3049 tty->termios->c_cflag,tty->termios->c_iflag);
3051 len += sprintf(buf+len,FMTLIN2,
3052 pCh->outfl.asof,pCh->outfl.room,pCh->channelNeeds);
3053 len += sprintf(buf+len,FMTLIN3,pCh->infl.asof,pCh->infl.room);
3061 * This is the handler for /proc/tty/driver/ip2
3063 * This stretch of code has been largely plagerized from at least three
3064 * different sources including ip2mkdev.c and a couple of other drivers.
3065 * The bugs are all mine. :-) =mhw=
3067 int ip2_read_proc(char *page, char **start, off_t off,
3068 int count, int *eof, void *data)
3078 len += sprintf(page, "ip2info: 1.0 driver: %s\n", pcVersion );
3079 len += sprintf(page+len, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
3080 IP2_TTY_MAJOR, IP2_CALLOUT_MAJOR, IP2_IPL_MAJOR,
3081 IP2_MAX_BOARDS, ABS_MAX_BOXES, ABS_BIGGEST_BOX);
3083 for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
3084 /* This need to be reset for a board by board count... */
3086 pB = i2BoardPtrTable[i];
3088 switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
3091 len += sprintf( page+len, "Board %d: EX ports=", i );
3092 for( box = 0; box < ABS_MAX_BOXES; ++box )
3096 if( pB->i2eChannelMap[box] != 0 ) ++boxes;
3097 for( j = 0; j < ABS_BIGGEST_BOX; ++j )
3099 if( pB->i2eChannelMap[box] & 1<< j ) {
3103 len += sprintf( page+len, "%d,", ports );
3107 --len; /* Backup over that last comma */
3109 len += sprintf( page+len, " boxes=%d width=%d", boxes, pB->i2eDataWidth16 ? 16 : 8 );
3113 len += sprintf(page+len, "Board %d: ISA-4 ports=4 boxes=1", i );
3118 len += sprintf(page+len, "Board %d: ISA-8-std ports=8 boxes=1", i );
3123 len += sprintf(page+len, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i );
3128 len += sprintf(page+len, "Board %d: unknown", i );
3129 /* Don't try and probe for minor numbers */
3134 /* Don't try and probe for minor numbers */
3135 len += sprintf(page+len, "Board %d: vacant", i );
3140 len += sprintf(page+len, " minors=" );
3142 for ( box = 0; box < ABS_MAX_BOXES; ++box )
3144 for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
3146 if ( pB->i2eChannelMap[box] & (1 << j) )
3148 len += sprintf (page+len,"%d,",
3149 j + ABS_BIGGEST_BOX *
3150 (box+i*ABS_MAX_BOXES));
3155 page[ len - 1 ] = '\n'; /* Overwrite that last comma */
3157 len += sprintf (page+len,"\n" );
3160 if (len+begin > off+count)
3162 if (len+begin < off) {
3168 if (i >= IP2_MAX_BOARDS)
3170 if (off >= len+begin)
3173 *start = page + (off-begin);
3174 return ((count < begin+len-off) ? count : begin+len-off);
3177 /******************************************************************************/
3178 /* Function: ip2trace() */
3179 /* Parameters: Value to add to trace buffer */
3180 /* Returns: Nothing */
3185 /******************************************************************************/
3186 #ifdef IP2DEBUG_TRACE
3188 ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned long codes, ...)
3191 unsigned long *pCode = &codes;
3192 union ip2breadcrumb bc;
3196 tracebuf[tracestuff++] = jiffies;
3197 if ( tracestuff == TRACEMAX ) {
3200 if ( tracestuff == tracestrip ) {
3201 if ( ++tracestrip == TRACEMAX ) {
3207 bc.hdr.port = 0xff & pn;
3209 bc.hdr.codes = (unsigned char)( codes & 0xff );
3210 bc.hdr.label = label;
3211 tracebuf[tracestuff++] = bc.value;
3214 if ( tracestuff == TRACEMAX ) {
3217 if ( tracestuff == tracestrip ) {
3218 if ( ++tracestrip == TRACEMAX ) {
3227 tracebuf[tracestuff++] = *++pCode;
3233 MODULE_LICENSE("GPL");